Loading...
1/*
2 * linux/arch/arm/mach-omap1/board-nokia770.c
3 *
4 * Modified from board-generic.c
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
9 */
10#include <linux/irq.h>
11#include <linux/gpio.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/input.h>
17#include <linux/clk.h>
18#include <linux/omapfb.h>
19
20#include <linux/spi/spi.h>
21#include <linux/spi/ads7846.h>
22#include <linux/workqueue.h>
23#include <linux/delay.h>
24
25#include <linux/platform_data/keypad-omap.h>
26#include <linux/platform_data/lcd-mipid.h>
27#include <linux/platform_data/gpio-omap.h>
28#include <linux/platform_data/i2c-cbus-gpio.h>
29
30#include <asm/mach-types.h>
31#include <asm/mach/arch.h>
32#include <asm/mach/map.h>
33
34#include <mach/mux.h>
35
36#include <mach/hardware.h>
37#include <mach/usb.h>
38
39#include "common.h"
40#include "clock.h"
41#include "mmc.h"
42
43#define ADS7846_PENDOWN_GPIO 15
44
45static const unsigned int nokia770_keymap[] = {
46 KEY(1, 0, GROUP_0 | KEY_UP),
47 KEY(2, 0, GROUP_1 | KEY_F5),
48 KEY(0, 1, GROUP_0 | KEY_LEFT),
49 KEY(1, 1, GROUP_0 | KEY_ENTER),
50 KEY(2, 1, GROUP_0 | KEY_RIGHT),
51 KEY(0, 2, GROUP_1 | KEY_ESC),
52 KEY(1, 2, GROUP_0 | KEY_DOWN),
53 KEY(2, 2, GROUP_1 | KEY_F4),
54 KEY(0, 3, GROUP_2 | KEY_F7),
55 KEY(1, 3, GROUP_2 | KEY_F8),
56 KEY(2, 3, GROUP_2 | KEY_F6),
57};
58
59static struct resource nokia770_kp_resources[] = {
60 [0] = {
61 .start = INT_KEYBOARD,
62 .end = INT_KEYBOARD,
63 .flags = IORESOURCE_IRQ,
64 },
65};
66
67static const struct matrix_keymap_data nokia770_keymap_data = {
68 .keymap = nokia770_keymap,
69 .keymap_size = ARRAY_SIZE(nokia770_keymap),
70};
71
72static struct omap_kp_platform_data nokia770_kp_data = {
73 .rows = 8,
74 .cols = 8,
75 .keymap_data = &nokia770_keymap_data,
76 .delay = 4,
77};
78
79static struct platform_device nokia770_kp_device = {
80 .name = "omap-keypad",
81 .id = -1,
82 .dev = {
83 .platform_data = &nokia770_kp_data,
84 },
85 .num_resources = ARRAY_SIZE(nokia770_kp_resources),
86 .resource = nokia770_kp_resources,
87};
88
89static struct platform_device *nokia770_devices[] __initdata = {
90 &nokia770_kp_device,
91};
92
93static void mipid_shutdown(struct mipid_platform_data *pdata)
94{
95 if (pdata->nreset_gpio != -1) {
96 printk(KERN_INFO "shutdown LCD\n");
97 gpio_set_value(pdata->nreset_gpio, 0);
98 msleep(120);
99 }
100}
101
102static struct mipid_platform_data nokia770_mipid_platform_data = {
103 .shutdown = mipid_shutdown,
104};
105
106static struct omap_lcd_config nokia770_lcd_config __initdata = {
107 .ctrl_name = "hwa742",
108};
109
110static void __init mipid_dev_init(void)
111{
112 nokia770_mipid_platform_data.nreset_gpio = 13;
113 nokia770_mipid_platform_data.data_lines = 16;
114
115 omapfb_set_lcd_config(&nokia770_lcd_config);
116}
117
118static struct ads7846_platform_data nokia770_ads7846_platform_data __initdata = {
119 .x_max = 0x0fff,
120 .y_max = 0x0fff,
121 .x_plate_ohms = 180,
122 .pressure_max = 255,
123 .debounce_max = 10,
124 .debounce_tol = 3,
125 .debounce_rep = 1,
126 .gpio_pendown = ADS7846_PENDOWN_GPIO,
127};
128
129static struct spi_board_info nokia770_spi_board_info[] __initdata = {
130 [0] = {
131 .modalias = "lcd_mipid",
132 .bus_num = 2,
133 .chip_select = 3,
134 .max_speed_hz = 12000000,
135 .platform_data = &nokia770_mipid_platform_data,
136 },
137 [1] = {
138 .modalias = "ads7846",
139 .bus_num = 2,
140 .chip_select = 0,
141 .max_speed_hz = 2500000,
142 .platform_data = &nokia770_ads7846_platform_data,
143 },
144};
145
146static void __init hwa742_dev_init(void)
147{
148 clk_add_alias("hwa_sys_ck", NULL, "bclk", NULL);
149}
150
151/* assume no Mini-AB port */
152
153static struct omap_usb_config nokia770_usb_config __initdata = {
154 .otg = 1,
155 .register_host = 1,
156 .register_dev = 1,
157 .hmc_mode = 16,
158 .pins[0] = 6,
159 .extcon = "tahvo-usb",
160};
161
162#if defined(CONFIG_MMC_OMAP) || defined(CONFIG_MMC_OMAP_MODULE)
163
164#define NOKIA770_GPIO_MMC_POWER 41
165#define NOKIA770_GPIO_MMC_SWITCH 23
166
167static int nokia770_mmc_set_power(struct device *dev, int slot, int power_on,
168 int vdd)
169{
170 gpio_set_value(NOKIA770_GPIO_MMC_POWER, power_on);
171 return 0;
172}
173
174static int nokia770_mmc_get_cover_state(struct device *dev, int slot)
175{
176 return gpio_get_value(NOKIA770_GPIO_MMC_SWITCH);
177}
178
179static struct omap_mmc_platform_data nokia770_mmc2_data = {
180 .nr_slots = 1,
181 .max_freq = 12000000,
182 .slots[0] = {
183 .set_power = nokia770_mmc_set_power,
184 .get_cover_state = nokia770_mmc_get_cover_state,
185 .ocr_mask = MMC_VDD_32_33|MMC_VDD_33_34,
186 .name = "mmcblk",
187 },
188};
189
190static struct omap_mmc_platform_data *nokia770_mmc_data[OMAP16XX_NR_MMC];
191
192static void __init nokia770_mmc_init(void)
193{
194 int ret;
195
196 ret = gpio_request(NOKIA770_GPIO_MMC_POWER, "MMC power");
197 if (ret < 0)
198 return;
199 gpio_direction_output(NOKIA770_GPIO_MMC_POWER, 0);
200
201 ret = gpio_request(NOKIA770_GPIO_MMC_SWITCH, "MMC cover");
202 if (ret < 0) {
203 gpio_free(NOKIA770_GPIO_MMC_POWER);
204 return;
205 }
206 gpio_direction_input(NOKIA770_GPIO_MMC_SWITCH);
207
208 /* Only the second MMC controller is used */
209 nokia770_mmc_data[1] = &nokia770_mmc2_data;
210 omap1_init_mmc(nokia770_mmc_data, OMAP16XX_NR_MMC);
211}
212
213#else
214static inline void nokia770_mmc_init(void)
215{
216}
217#endif
218
219#if defined(CONFIG_I2C_CBUS_GPIO) || defined(CONFIG_I2C_CBUS_GPIO_MODULE)
220static struct i2c_cbus_platform_data nokia770_cbus_data = {
221 .clk_gpio = OMAP_MPUIO(9),
222 .dat_gpio = OMAP_MPUIO(10),
223 .sel_gpio = OMAP_MPUIO(11),
224};
225
226static struct platform_device nokia770_cbus_device = {
227 .name = "i2c-cbus-gpio",
228 .id = 2,
229 .dev = {
230 .platform_data = &nokia770_cbus_data,
231 },
232};
233
234static struct i2c_board_info nokia770_i2c_board_info_2[] __initdata = {
235 {
236 I2C_BOARD_INFO("retu-mfd", 0x01),
237 },
238 {
239 I2C_BOARD_INFO("tahvo-mfd", 0x02),
240 },
241};
242
243static void __init nokia770_cbus_init(void)
244{
245 const int retu_irq_gpio = 62;
246 const int tahvo_irq_gpio = 40;
247
248 if (gpio_request_one(retu_irq_gpio, GPIOF_IN, "Retu IRQ"))
249 return;
250 if (gpio_request_one(tahvo_irq_gpio, GPIOF_IN, "Tahvo IRQ")) {
251 gpio_free(retu_irq_gpio);
252 return;
253 }
254 irq_set_irq_type(gpio_to_irq(retu_irq_gpio), IRQ_TYPE_EDGE_RISING);
255 irq_set_irq_type(gpio_to_irq(tahvo_irq_gpio), IRQ_TYPE_EDGE_RISING);
256 nokia770_i2c_board_info_2[0].irq = gpio_to_irq(retu_irq_gpio);
257 nokia770_i2c_board_info_2[1].irq = gpio_to_irq(tahvo_irq_gpio);
258 i2c_register_board_info(2, nokia770_i2c_board_info_2,
259 ARRAY_SIZE(nokia770_i2c_board_info_2));
260 platform_device_register(&nokia770_cbus_device);
261}
262#else /* CONFIG_I2C_CBUS_GPIO */
263static void __init nokia770_cbus_init(void)
264{
265}
266#endif /* CONFIG_I2C_CBUS_GPIO */
267
268static void __init omap_nokia770_init(void)
269{
270 /* On Nokia 770, the SleepX signal is masked with an
271 * MPUIO line by default. It has to be unmasked for it
272 * to become functional */
273
274 /* SleepX mask direction */
275 omap_writew((omap_readw(0xfffb5008) & ~2), 0xfffb5008);
276 /* Unmask SleepX signal */
277 omap_writew((omap_readw(0xfffb5004) & ~2), 0xfffb5004);
278
279 platform_add_devices(nokia770_devices, ARRAY_SIZE(nokia770_devices));
280 nokia770_spi_board_info[1].irq = gpio_to_irq(15);
281 spi_register_board_info(nokia770_spi_board_info,
282 ARRAY_SIZE(nokia770_spi_board_info));
283 omap_serial_init();
284 omap_register_i2c_bus(1, 100, NULL, 0);
285 hwa742_dev_init();
286 mipid_dev_init();
287 omap1_usb_init(&nokia770_usb_config);
288 nokia770_mmc_init();
289 nokia770_cbus_init();
290}
291
292MACHINE_START(NOKIA770, "Nokia 770")
293 .atag_offset = 0x100,
294 .map_io = omap16xx_map_io,
295 .init_early = omap1_init_early,
296 .init_irq = omap1_init_irq,
297 .init_machine = omap_nokia770_init,
298 .init_late = omap1_init_late,
299 .init_time = omap1_timer_init,
300 .restart = omap1_restart,
301MACHINE_END
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
39static const struct software_node nokia770_mpuio_gpiochip_node = {
40 .name = "mpuio",
41};
42
43static const struct software_node nokia770_gpiochip1_node = {
44 .name = "gpio-0-15",
45};
46
47static const struct software_node nokia770_gpiochip2_node = {
48 .name = "gpio-16-31",
49};
50
51static 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
60static 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
74static struct resource nokia770_kp_resources[] = {
75 [0] = {
76 .start = INT_KEYBOARD,
77 .end = INT_KEYBOARD,
78 .flags = IORESOURCE_IRQ,
79 },
80};
81
82static const struct matrix_keymap_data nokia770_keymap_data = {
83 .keymap = nokia770_keymap,
84 .keymap_size = ARRAY_SIZE(nokia770_keymap),
85};
86
87static 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
94static 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
104static struct platform_device *nokia770_devices[] __initdata = {
105 &nokia770_kp_device,
106};
107
108static struct mipid_platform_data nokia770_mipid_platform_data = { };
109
110static const struct omap_lcd_config nokia770_lcd_config __initconst = {
111 .ctrl_name = "hwa742",
112};
113
114static const struct property_entry nokia770_mipid_props[] = {
115 PROPERTY_ENTRY_GPIO("reset-gpios", &nokia770_gpiochip1_node,
116 13, GPIO_ACTIVE_LOW),
117 { }
118};
119
120static const struct software_node nokia770_mipid_swnode = {
121 .name = "lcd_mipid",
122 .properties = nokia770_mipid_props,
123};
124
125static 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
132static 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
146static const struct software_node nokia770_ads7846_swnode = {
147 .name = "ads7846",
148 .properties = nokia770_ads7846_props,
149};
150
151static 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
169static 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
176static 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
187static 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
200static 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
209static struct omap_mmc_platform_data *nokia770_mmc_data[OMAP16XX_NR_MMC];
210
211static 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
220static inline void nokia770_mmc_init(void)
221{
222}
223#endif
224
225#if IS_ENABLED(CONFIG_I2C_CBUS_GPIO)
226
227static 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
233static const struct property_entry nokia770_cbus_props[] = {
234 PROPERTY_ENTRY_REF_ARRAY("gpios", nokia770_cbus_gpio_refs),
235 { }
236};
237
238static struct platform_device nokia770_cbus_device = {
239 .name = "i2c-cbus-gpio",
240 .id = 2,
241};
242
243static 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
252static 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 */
280static void __init nokia770_cbus_init(void)
281{
282}
283#endif /* CONFIG_I2C_CBUS_GPIO */
284
285static 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
308static 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
342MACHINE_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,
351MACHINE_END