1 // SPDX-License-Identifier: GPL-2.0-only
3 * linux/arch/arm/mach-omap1/board-nokia770.c
5 * Modified from board-generic.c
7 #include <linux/clkdev.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>
20 #include <linux/spi/spi.h>
21 #include <linux/workqueue.h>
22 #include <linux/delay.h>
24 #include <linux/platform_data/keypad-omap.h>
25 #include <linux/platform_data/lcd-mipid.h>
26 #include <linux/platform_data/gpio-omap.h>
28 #include <asm/mach-types.h>
29 #include <asm/mach/arch.h>
30 #include <asm/mach/map.h>
39 static const struct software_node nokia770_mpuio_gpiochip_node
= {
43 static const struct software_node nokia770_gpiochip1_node
= {
47 static const struct software_node nokia770_gpiochip2_node
= {
51 static const struct software_node
*nokia770_gpiochip_nodes
[] = {
52 &nokia770_mpuio_gpiochip_node
,
53 &nokia770_gpiochip1_node
,
54 &nokia770_gpiochip2_node
,
58 #define ADS7846_PENDOWN_GPIO 15
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
),
74 static struct resource nokia770_kp_resources
[] = {
76 .start
= INT_KEYBOARD
,
78 .flags
= IORESOURCE_IRQ
,
82 static const struct matrix_keymap_data nokia770_keymap_data
= {
83 .keymap
= nokia770_keymap
,
84 .keymap_size
= ARRAY_SIZE(nokia770_keymap
),
87 static struct omap_kp_platform_data nokia770_kp_data
= {
90 .keymap_data
= &nokia770_keymap_data
,
94 static struct platform_device nokia770_kp_device
= {
95 .name
= "omap-keypad",
98 .platform_data
= &nokia770_kp_data
,
100 .num_resources
= ARRAY_SIZE(nokia770_kp_resources
),
101 .resource
= nokia770_kp_resources
,
104 static struct platform_device
*nokia770_devices
[] __initdata
= {
108 static struct mipid_platform_data nokia770_mipid_platform_data
= { };
110 static const struct omap_lcd_config nokia770_lcd_config __initconst
= {
111 .ctrl_name
= "hwa742",
114 static const struct property_entry nokia770_mipid_props
[] = {
115 PROPERTY_ENTRY_GPIO("reset-gpios", &nokia770_gpiochip1_node
,
116 13, GPIO_ACTIVE_LOW
),
120 static const struct software_node nokia770_mipid_swnode
= {
122 .properties
= nokia770_mipid_props
,
125 static void __init
mipid_dev_init(void)
127 nokia770_mipid_platform_data
.data_lines
= 16;
129 omapfb_set_lcd_config(&nokia770_lcd_config
);
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
),
146 static const struct software_node nokia770_ads7846_swnode
= {
148 .properties
= nokia770_ads7846_props
,
151 static struct spi_board_info nokia770_spi_board_info
[] __initdata
= {
153 .modalias
= "lcd_mipid",
156 .max_speed_hz
= 12000000,
157 .platform_data
= &nokia770_mipid_platform_data
,
158 .swnode
= &nokia770_mipid_swnode
,
161 .modalias
= "ads7846",
164 .max_speed_hz
= 2500000,
165 .swnode
= &nokia770_ads7846_swnode
,
169 static void __init
hwa742_dev_init(void)
171 clk_add_alias("hwa_sys_ck", NULL
, "bclk", NULL
);
174 /* assume no Mini-AB port */
176 static struct omap_usb_config nokia770_usb_config __initdata
= {
182 .extcon
= "tahvo-usb",
185 #if IS_ENABLED(CONFIG_MMC_OMAP)
187 static struct gpiod_lookup_table nokia770_mmc_gpio_table
= {
188 .dev_id
= "mmci-omap.1",
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
),
200 static struct omap_mmc_platform_data nokia770_mmc2_data
= {
202 .max_freq
= 12000000,
204 .ocr_mask
= MMC_VDD_32_33
|MMC_VDD_33_34
,
209 static struct omap_mmc_platform_data
*nokia770_mmc_data
[OMAP16XX_NR_MMC
];
211 static void __init
nokia770_mmc_init(void)
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
);
220 static inline void nokia770_mmc_init(void)
225 #if IS_ENABLED(CONFIG_I2C_CBUS_GPIO)
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),
233 static const struct property_entry nokia770_cbus_props
[] = {
234 PROPERTY_ENTRY_REF_ARRAY("gpios", nokia770_cbus_gpio_refs
),
238 static struct platform_device nokia770_cbus_device
= {
239 .name
= "i2c-cbus-gpio",
243 static struct i2c_board_info nokia770_i2c_board_info_2
[] __initdata
= {
245 I2C_BOARD_INFO("retu", 0x01),
248 I2C_BOARD_INFO("tahvo", 0x02),
252 static void __init
nokia770_cbus_init(void)
257 d
= gpiod_get(NULL
, "retu_irq", GPIOD_IN
);
259 pr_err("Unable to get CBUS Retu IRQ GPIO descriptor\n");
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
;
265 d
= gpiod_get(NULL
, "tahvo_irq", GPIOD_IN
);
267 pr_err("Unable to get CBUS Tahvo IRQ GPIO descriptor\n");
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
;
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
);
279 #else /* CONFIG_I2C_CBUS_GPIO */
280 static void __init
nokia770_cbus_init(void)
283 #endif /* CONFIG_I2C_CBUS_GPIO */
285 static struct gpiod_lookup_table nokia770_irq_gpio_table
= {
288 /* GPIO used by SPI device 1 */
289 GPIO_LOOKUP("gpio-0-15", 15, "ads7846_irq",
291 /* GPIO used for retu IRQ */
292 GPIO_LOOKUP("gpio-48-63", 15, "retu_irq",
294 /* GPIO used for tahvo IRQ */
295 GPIO_LOOKUP("gpio-32-47", 8, "tahvo_irq",
297 /* GPIOs used by serial wakeup IRQs */
298 GPIO_LOOKUP_IDX("gpio-32-47", 5, "wakeup", 0,
300 GPIO_LOOKUP_IDX("gpio-16-31", 2, "wakeup", 1,
302 GPIO_LOOKUP_IDX("gpio-48-63", 1, "wakeup", 2,
308 static void __init
omap_nokia770_init(void)
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 */
316 /* SleepX mask direction */
317 omap_writew((omap_readw(0xfffb5008) & ~2), 0xfffb5008);
318 /* Unmask SleepX signal */
319 omap_writew((omap_readw(0xfffb5004) & ~2), 0xfffb5004);
321 software_node_register_node_group(nokia770_gpiochip_nodes
);
322 platform_add_devices(nokia770_devices
, ARRAY_SIZE(nokia770_devices
));
324 gpiod_add_lookup_table(&nokia770_irq_gpio_table
);
325 d
= gpiod_get(NULL
, "ads7846_irq", GPIOD_IN
);
327 pr_err("Unable to get ADS7846 IRQ GPIO descriptor\n");
329 nokia770_spi_board_info
[1].irq
= gpiod_to_irq(d
);
331 spi_register_board_info(nokia770_spi_board_info
,
332 ARRAY_SIZE(nokia770_spi_board_info
));
334 omap_register_i2c_bus(1, 100, NULL
, 0);
337 omap1_usb_init(&nokia770_usb_config
);
339 nokia770_cbus_init();
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
,