]> Git Repo - J-linux.git/blob - arch/arm/mach-omap1/board-nokia770.c
mei: Add transport driver for IVSC device
[J-linux.git] / arch / arm / mach-omap1 / board-nokia770.c
1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3  * linux/arch/arm/mach-omap1/board-nokia770.c
4  *
5  * Modified from board-generic.c
6  */
7 #include <linux/clkdev.h>
8 #include <linux/irq.h>
9 #include <linux/gpio/consumer.h>
10 #include <linux/gpio/machine.h>
11 #include <linux/gpio/property.h>
12 #include <linux/kernel.h>
13 #include <linux/init.h>
14 #include <linux/mutex.h>
15 #include <linux/platform_device.h>
16 #include <linux/property.h>
17 #include <linux/input.h>
18 #include <linux/omapfb.h>
19
20 #include <linux/spi/spi.h>
21 #include <linux/workqueue.h>
22 #include <linux/delay.h>
23
24 #include <linux/platform_data/keypad-omap.h>
25 #include <linux/platform_data/lcd-mipid.h>
26 #include <linux/platform_data/gpio-omap.h>
27
28 #include <asm/mach-types.h>
29 #include <asm/mach/arch.h>
30 #include <asm/mach/map.h>
31
32 #include "mux.h"
33 #include "hardware.h"
34 #include "usb.h"
35 #include "common.h"
36 #include "clock.h"
37 #include "mmc.h"
38
39 static const struct software_node nokia770_mpuio_gpiochip_node = {
40         .name = "mpuio",
41 };
42
43 static const struct software_node nokia770_gpiochip1_node = {
44         .name = "gpio-0-15",
45 };
46
47 static const struct software_node nokia770_gpiochip2_node = {
48         .name = "gpio-16-31",
49 };
50
51 static const struct software_node *nokia770_gpiochip_nodes[] = {
52         &nokia770_mpuio_gpiochip_node,
53         &nokia770_gpiochip1_node,
54         &nokia770_gpiochip2_node,
55         NULL
56 };
57
58 #define ADS7846_PENDOWN_GPIO    15
59
60 static const unsigned int nokia770_keymap[] = {
61         KEY(1, 0, GROUP_0 | KEY_UP),
62         KEY(2, 0, GROUP_1 | KEY_F5),
63         KEY(0, 1, GROUP_0 | KEY_LEFT),
64         KEY(1, 1, GROUP_0 | KEY_ENTER),
65         KEY(2, 1, GROUP_0 | KEY_RIGHT),
66         KEY(0, 2, GROUP_1 | KEY_ESC),
67         KEY(1, 2, GROUP_0 | KEY_DOWN),
68         KEY(2, 2, GROUP_1 | KEY_F4),
69         KEY(0, 3, GROUP_2 | KEY_F7),
70         KEY(1, 3, GROUP_2 | KEY_F8),
71         KEY(2, 3, GROUP_2 | KEY_F6),
72 };
73
74 static struct resource nokia770_kp_resources[] = {
75         [0] = {
76                 .start  = INT_KEYBOARD,
77                 .end    = INT_KEYBOARD,
78                 .flags  = IORESOURCE_IRQ,
79         },
80 };
81
82 static const struct matrix_keymap_data nokia770_keymap_data = {
83         .keymap         = nokia770_keymap,
84         .keymap_size    = ARRAY_SIZE(nokia770_keymap),
85 };
86
87 static struct omap_kp_platform_data nokia770_kp_data = {
88         .rows           = 8,
89         .cols           = 8,
90         .keymap_data    = &nokia770_keymap_data,
91         .delay          = 4,
92 };
93
94 static struct platform_device nokia770_kp_device = {
95         .name           = "omap-keypad",
96         .id             = -1,
97         .dev            = {
98                 .platform_data = &nokia770_kp_data,
99         },
100         .num_resources  = ARRAY_SIZE(nokia770_kp_resources),
101         .resource       = nokia770_kp_resources,
102 };
103
104 static struct platform_device *nokia770_devices[] __initdata = {
105         &nokia770_kp_device,
106 };
107
108 static struct mipid_platform_data nokia770_mipid_platform_data = { };
109
110 static const struct omap_lcd_config nokia770_lcd_config __initconst = {
111         .ctrl_name      = "hwa742",
112 };
113
114 static const struct property_entry nokia770_mipid_props[] = {
115         PROPERTY_ENTRY_GPIO("reset-gpios", &nokia770_gpiochip1_node,
116                             13, GPIO_ACTIVE_LOW),
117         { }
118 };
119
120 static const struct software_node nokia770_mipid_swnode = {
121         .name = "lcd_mipid",
122         .properties = nokia770_mipid_props,
123 };
124
125 static void __init mipid_dev_init(void)
126 {
127         nokia770_mipid_platform_data.data_lines = 16;
128
129         omapfb_set_lcd_config(&nokia770_lcd_config);
130 }
131
132 static const struct property_entry nokia770_ads7846_props[] = {
133         PROPERTY_ENTRY_STRING("compatible", "ti,ads7846"),
134         PROPERTY_ENTRY_U32("touchscreen-size-x", 4096),
135         PROPERTY_ENTRY_U32("touchscreen-size-y", 4096),
136         PROPERTY_ENTRY_U32("touchscreen-max-pressure", 256),
137         PROPERTY_ENTRY_U32("touchscreen-average-samples", 10),
138         PROPERTY_ENTRY_U16("ti,x-plate-ohms", 180),
139         PROPERTY_ENTRY_U16("ti,debounce-tol", 3),
140         PROPERTY_ENTRY_U16("ti,debounce-rep", 1),
141         PROPERTY_ENTRY_GPIO("pendown-gpios", &nokia770_gpiochip1_node,
142                             ADS7846_PENDOWN_GPIO, GPIO_ACTIVE_LOW),
143         { }
144 };
145
146 static const struct software_node nokia770_ads7846_swnode = {
147         .name = "ads7846",
148         .properties = nokia770_ads7846_props,
149 };
150
151 static struct spi_board_info nokia770_spi_board_info[] __initdata = {
152         [0] = {
153                 .modalias       = "lcd_mipid",
154                 .bus_num        = 2,
155                 .chip_select    = 3,
156                 .max_speed_hz   = 12000000,
157                 .platform_data  = &nokia770_mipid_platform_data,
158                 .swnode         = &nokia770_mipid_swnode,
159         },
160         [1] = {
161                 .modalias       = "ads7846",
162                 .bus_num        = 2,
163                 .chip_select    = 0,
164                 .max_speed_hz   = 2500000,
165                 .swnode         = &nokia770_ads7846_swnode,
166         },
167 };
168
169 static void __init hwa742_dev_init(void)
170 {
171         clk_add_alias("hwa_sys_ck", NULL, "bclk", NULL);
172 }
173
174 /* assume no Mini-AB port */
175
176 static struct omap_usb_config nokia770_usb_config __initdata = {
177         .otg            = 1,
178         .register_host  = 1,
179         .register_dev   = 1,
180         .hmc_mode       = 16,
181         .pins[0]        = 6,
182         .extcon         = "tahvo-usb",
183 };
184
185 #if IS_ENABLED(CONFIG_MMC_OMAP)
186
187 static struct gpiod_lookup_table nokia770_mmc_gpio_table = {
188         .dev_id = "mmci-omap.1",
189         .table = {
190                 /* Slot index 0, VSD power, GPIO 41 */
191                 GPIO_LOOKUP_IDX("gpio-32-47", 9,
192                                 "vsd", 0, GPIO_ACTIVE_HIGH),
193                 /* Slot index 0, switch, GPIO 23 */
194                 GPIO_LOOKUP_IDX("gpio-16-31", 7,
195                                 "cover", 0, GPIO_ACTIVE_HIGH),
196                 { }
197         },
198 };
199
200 static struct omap_mmc_platform_data nokia770_mmc2_data = {
201         .nr_slots                       = 1,
202         .max_freq                       = 12000000,
203         .slots[0]       = {
204                 .ocr_mask               = MMC_VDD_32_33|MMC_VDD_33_34,
205                 .name                   = "mmcblk",
206         },
207 };
208
209 static struct omap_mmc_platform_data *nokia770_mmc_data[OMAP16XX_NR_MMC];
210
211 static void __init nokia770_mmc_init(void)
212 {
213         gpiod_add_lookup_table(&nokia770_mmc_gpio_table);
214         /* Only the second MMC controller is used */
215         nokia770_mmc_data[1] = &nokia770_mmc2_data;
216         omap1_init_mmc(nokia770_mmc_data, OMAP16XX_NR_MMC);
217 }
218
219 #else
220 static inline void nokia770_mmc_init(void)
221 {
222 }
223 #endif
224
225 #if IS_ENABLED(CONFIG_I2C_CBUS_GPIO)
226
227 static const struct software_node_ref_args nokia770_cbus_gpio_refs[] = {
228         SOFTWARE_NODE_REFERENCE(&nokia770_mpuio_gpiochip_node, 9, 0),
229         SOFTWARE_NODE_REFERENCE(&nokia770_mpuio_gpiochip_node, 10, 0),
230         SOFTWARE_NODE_REFERENCE(&nokia770_mpuio_gpiochip_node, 11, 0),
231 };
232
233 static const struct property_entry nokia770_cbus_props[] = {
234         PROPERTY_ENTRY_REF_ARRAY("gpios", nokia770_cbus_gpio_refs),
235         { }
236 };
237
238 static struct platform_device nokia770_cbus_device = {
239         .name   = "i2c-cbus-gpio",
240         .id     = 2,
241 };
242
243 static struct i2c_board_info nokia770_i2c_board_info_2[] __initdata = {
244         {
245                 I2C_BOARD_INFO("retu", 0x01),
246         },
247         {
248                 I2C_BOARD_INFO("tahvo", 0x02),
249         },
250 };
251
252 static void __init nokia770_cbus_init(void)
253 {
254         struct gpio_desc *d;
255         int irq;
256
257         d = gpiod_get(NULL, "retu_irq", GPIOD_IN);
258         if (IS_ERR(d)) {
259                 pr_err("Unable to get CBUS Retu IRQ GPIO descriptor\n");
260         } else {
261                 irq = gpiod_to_irq(d);
262                 irq_set_irq_type(irq, IRQ_TYPE_EDGE_RISING);
263                 nokia770_i2c_board_info_2[0].irq = irq;
264         }
265         d = gpiod_get(NULL, "tahvo_irq", GPIOD_IN);
266         if (IS_ERR(d)) {
267                 pr_err("Unable to get CBUS Tahvo IRQ GPIO descriptor\n");
268         } else {
269                 irq = gpiod_to_irq(d);
270                 irq_set_irq_type(irq, IRQ_TYPE_EDGE_RISING);
271                 nokia770_i2c_board_info_2[1].irq = irq;
272         }
273         i2c_register_board_info(2, nokia770_i2c_board_info_2,
274                                 ARRAY_SIZE(nokia770_i2c_board_info_2));
275         device_create_managed_software_node(&nokia770_cbus_device.dev,
276                                             nokia770_cbus_props, NULL);
277         platform_device_register(&nokia770_cbus_device);
278 }
279 #else /* CONFIG_I2C_CBUS_GPIO */
280 static void __init nokia770_cbus_init(void)
281 {
282 }
283 #endif /* CONFIG_I2C_CBUS_GPIO */
284
285 static struct gpiod_lookup_table nokia770_irq_gpio_table = {
286         .dev_id = NULL,
287         .table = {
288                 /* GPIO used by SPI device 1 */
289                 GPIO_LOOKUP("gpio-0-15", 15, "ads7846_irq",
290                             GPIO_ACTIVE_HIGH),
291                 /* GPIO used for retu IRQ */
292                 GPIO_LOOKUP("gpio-48-63", 15, "retu_irq",
293                             GPIO_ACTIVE_HIGH),
294                 /* GPIO used for tahvo IRQ */
295                 GPIO_LOOKUP("gpio-32-47", 8, "tahvo_irq",
296                             GPIO_ACTIVE_HIGH),
297                 /* GPIOs used by serial wakeup IRQs */
298                 GPIO_LOOKUP_IDX("gpio-32-47", 5, "wakeup", 0,
299                             GPIO_ACTIVE_HIGH),
300                 GPIO_LOOKUP_IDX("gpio-16-31", 2, "wakeup", 1,
301                             GPIO_ACTIVE_HIGH),
302                 GPIO_LOOKUP_IDX("gpio-48-63", 1, "wakeup", 2,
303                             GPIO_ACTIVE_HIGH),
304                 { }
305         },
306 };
307
308 static void __init omap_nokia770_init(void)
309 {
310         struct gpio_desc *d;
311
312         /* On Nokia 770, the SleepX signal is masked with an
313          * MPUIO line by default.  It has to be unmasked for it
314          * to become functional */
315
316         /* SleepX mask direction */
317         omap_writew((omap_readw(0xfffb5008) & ~2), 0xfffb5008);
318         /* Unmask SleepX signal */
319         omap_writew((omap_readw(0xfffb5004) & ~2), 0xfffb5004);
320
321         software_node_register_node_group(nokia770_gpiochip_nodes);
322         platform_add_devices(nokia770_devices, ARRAY_SIZE(nokia770_devices));
323
324         gpiod_add_lookup_table(&nokia770_irq_gpio_table);
325         d = gpiod_get(NULL, "ads7846_irq", GPIOD_IN);
326         if (IS_ERR(d))
327                 pr_err("Unable to get ADS7846 IRQ GPIO descriptor\n");
328         else
329                 nokia770_spi_board_info[1].irq = gpiod_to_irq(d);
330
331         spi_register_board_info(nokia770_spi_board_info,
332                                 ARRAY_SIZE(nokia770_spi_board_info));
333         omap_serial_init();
334         omap_register_i2c_bus(1, 100, NULL, 0);
335         hwa742_dev_init();
336         mipid_dev_init();
337         omap1_usb_init(&nokia770_usb_config);
338         nokia770_mmc_init();
339         nokia770_cbus_init();
340 }
341
342 MACHINE_START(NOKIA770, "Nokia 770")
343         .atag_offset    = 0x100,
344         .map_io         = omap1_map_io,
345         .init_early     = omap1_init_early,
346         .init_irq       = omap1_init_irq,
347         .init_machine   = omap_nokia770_init,
348         .init_late      = omap1_init_late,
349         .init_time      = omap1_timer_init,
350         .restart        = omap1_restart,
351 MACHINE_END
This page took 0.0446 seconds and 4 git commands to generate.