GNU Linux-libre 5.19-rc6-gnu
[releases.git] / arch / arm / mach-omap1 / board-palmtt.c
1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3  * linux/arch/arm/mach-omap1/board-palmtt.c
4  *
5  * Modified from board-palmtt2.c
6  *
7  * Modified and amended for Palm Tungsten|T
8  * by Marek Vasut <marek.vasut@gmail.com>
9  */
10
11 #include <linux/delay.h>
12 #include <linux/gpio.h>
13 #include <linux/kernel.h>
14 #include <linux/init.h>
15 #include <linux/platform_device.h>
16 #include <linux/notifier.h>
17 #include <linux/clk.h>
18 #include <linux/input.h>
19 #include <linux/interrupt.h>
20 #include <linux/mtd/mtd.h>
21 #include <linux/mtd/partitions.h>
22 #include <linux/mtd/physmap.h>
23 #include <linux/leds.h>
24 #include <linux/omapfb.h>
25 #include <linux/spi/spi.h>
26 #include <linux/spi/ads7846.h>
27 #include <linux/omap-dma.h>
28 #include <linux/platform_data/omap1_bl.h>
29 #include <linux/platform_data/leds-omap.h>
30 #include <linux/platform_data/keypad-omap.h>
31
32 #include <asm/mach-types.h>
33 #include <asm/mach/arch.h>
34 #include <asm/mach/map.h>
35
36 #include "tc.h"
37 #include "flash.h"
38 #include "mux.h"
39 #include "hardware.h"
40 #include "usb.h"
41 #include "common.h"
42
43 #define PALMTT_USBDETECT_GPIO   0
44 #define PALMTT_CABLE_GPIO       1
45 #define PALMTT_LED_GPIO         3
46 #define PALMTT_PENIRQ_GPIO      6
47 #define PALMTT_MMC_WP_GPIO      8
48 #define PALMTT_HDQ_GPIO         11
49
50 static const unsigned int palmtt_keymap[] = {
51         KEY(0, 0, KEY_ESC),
52         KEY(1, 0, KEY_SPACE),
53         KEY(2, 0, KEY_LEFTCTRL),
54         KEY(3, 0, KEY_TAB),
55         KEY(4, 0, KEY_ENTER),
56         KEY(0, 1, KEY_LEFT),
57         KEY(1, 1, KEY_DOWN),
58         KEY(2, 1, KEY_UP),
59         KEY(3, 1, KEY_RIGHT),
60         KEY(0, 2, KEY_SLEEP),
61         KEY(4, 2, KEY_Y),
62 };
63
64 static struct mtd_partition palmtt_partitions[] = {
65         {
66                 .name           = "write8k",
67                 .offset         = 0,
68                 .size           = SZ_8K,
69                 .mask_flags     = 0,
70         },
71         {
72                 .name           = "PalmOS-BootLoader(ro)",
73                 .offset         = SZ_8K,
74                 .size           = 7 * SZ_8K,
75                 .mask_flags     = MTD_WRITEABLE,
76         },
77         {
78                 .name           = "u-boot",
79                 .offset         = MTDPART_OFS_APPEND,
80                 .size           = 8 * SZ_8K,
81                 .mask_flags     = 0,
82         },
83         {
84                 .name           = "PalmOS-FS(ro)",
85                 .offset         = MTDPART_OFS_APPEND,
86                 .size           = 7 * SZ_1M + 4 * SZ_64K - 16 * SZ_8K,
87                 .mask_flags     = MTD_WRITEABLE,
88         },
89         {
90                 .name           = "u-boot(rez)",
91                 .offset         = MTDPART_OFS_APPEND,
92                 .size           = SZ_128K,
93                 .mask_flags     = 0
94         },
95         {
96                 .name           = "empty",
97                 .offset         = MTDPART_OFS_APPEND,
98                 .size           = MTDPART_SIZ_FULL,
99                 .mask_flags     = 0
100         }
101 };
102
103 static struct physmap_flash_data palmtt_flash_data = {
104         .width          = 2,
105         .set_vpp        = omap1_set_vpp,
106         .parts          = palmtt_partitions,
107         .nr_parts       = ARRAY_SIZE(palmtt_partitions),
108 };
109
110 static struct resource palmtt_flash_resource = {
111         .start          = OMAP_CS0_PHYS,
112         .end            = OMAP_CS0_PHYS + SZ_8M - 1,
113         .flags          = IORESOURCE_MEM,
114 };
115
116 static struct platform_device palmtt_flash_device = {
117         .name           = "physmap-flash",
118         .id             = 0,
119         .dev            = {
120                 .platform_data  = &palmtt_flash_data,
121         },
122         .num_resources  = 1,
123         .resource       = &palmtt_flash_resource,
124 };
125
126 static struct resource palmtt_kp_resources[] = {
127         [0] = {
128                 .start  = INT_KEYBOARD,
129                 .end    = INT_KEYBOARD,
130                 .flags  = IORESOURCE_IRQ,
131         },
132 };
133
134 static const struct matrix_keymap_data palmtt_keymap_data = {
135         .keymap         = palmtt_keymap,
136         .keymap_size    = ARRAY_SIZE(palmtt_keymap),
137 };
138
139 static struct omap_kp_platform_data palmtt_kp_data = {
140         .rows   = 6,
141         .cols   = 3,
142         .keymap_data = &palmtt_keymap_data,
143 };
144
145 static struct platform_device palmtt_kp_device = {
146         .name           = "omap-keypad",
147         .id             = -1,
148         .dev            = {
149                 .platform_data = &palmtt_kp_data,
150         },
151         .num_resources  = ARRAY_SIZE(palmtt_kp_resources),
152         .resource       = palmtt_kp_resources,
153 };
154
155 static struct platform_device palmtt_lcd_device = {
156         .name           = "lcd_palmtt",
157         .id             = -1,
158 };
159
160 static struct platform_device palmtt_spi_device = {
161         .name           = "spi_palmtt",
162         .id             = -1,
163 };
164
165 static struct omap_backlight_config palmtt_backlight_config = {
166         .default_intensity      = 0xa0,
167 };
168
169 static struct platform_device palmtt_backlight_device = {
170         .name           = "omap-bl",
171         .id             = -1,
172         .dev            = {
173                 .platform_data= &palmtt_backlight_config,
174         },
175 };
176
177 static struct omap_led_config palmtt_led_config[] = {
178         {
179                 .cdev   = {
180                         .name   = "palmtt:led0",
181                 },
182                 .gpio   = PALMTT_LED_GPIO,
183         },
184 };
185
186 static struct omap_led_platform_data palmtt_led_data = {
187         .nr_leds        = ARRAY_SIZE(palmtt_led_config),
188         .leds           = palmtt_led_config,
189 };
190
191 static struct platform_device palmtt_led_device = {
192         .name   = "omap-led",
193         .id     = -1,
194         .dev    = {
195                 .platform_data  = &palmtt_led_data,
196         },
197 };
198
199 static struct platform_device *palmtt_devices[] __initdata = {
200         &palmtt_flash_device,
201         &palmtt_kp_device,
202         &palmtt_lcd_device,
203         &palmtt_spi_device,
204         &palmtt_backlight_device,
205         &palmtt_led_device,
206 };
207
208 static int palmtt_get_pendown_state(void)
209 {
210         return !gpio_get_value(6);
211 }
212
213 static const struct ads7846_platform_data palmtt_ts_info = {
214         .model                  = 7846,
215         .vref_delay_usecs       = 100,  /* internal, no capacitor */
216         .x_plate_ohms           = 419,
217         .y_plate_ohms           = 486,
218         .get_pendown_state      = palmtt_get_pendown_state,
219 };
220
221 static struct spi_board_info __initdata palmtt_boardinfo[] = {
222         {
223                 /* MicroWire (bus 2) CS0 has an ads7846e */
224                 .modalias       = "ads7846",
225                 .platform_data  = &palmtt_ts_info,
226                 .max_speed_hz   = 120000        /* max sample rate at 3V */
227                                         * 26    /* command + data + overhead */,
228                 .bus_num        = 2,
229                 .chip_select    = 0,
230         }
231 };
232
233 static struct omap_usb_config palmtt_usb_config __initdata = {
234         .register_dev   = 1,
235         .hmc_mode       = 0,
236         .pins[0]        = 2,
237 };
238
239 static const struct omap_lcd_config palmtt_lcd_config __initconst = {
240         .ctrl_name      = "internal",
241 };
242
243 static void __init omap_mpu_wdt_mode(int mode) {
244         if (mode)
245                 omap_writew(0x8000, OMAP_WDT_TIMER_MODE);
246         else {
247                 omap_writew(0x00f5, OMAP_WDT_TIMER_MODE);
248                 omap_writew(0x00a0, OMAP_WDT_TIMER_MODE);
249         }
250 }
251
252 static void __init omap_palmtt_init(void)
253 {
254         /* mux pins for uarts */
255         omap_cfg_reg(UART1_TX);
256         omap_cfg_reg(UART1_RTS);
257         omap_cfg_reg(UART2_TX);
258         omap_cfg_reg(UART2_RTS);
259         omap_cfg_reg(UART3_TX);
260         omap_cfg_reg(UART3_RX);
261
262         omap_mpu_wdt_mode(0);
263
264         platform_add_devices(palmtt_devices, ARRAY_SIZE(palmtt_devices));
265
266         palmtt_boardinfo[0].irq = gpio_to_irq(6);
267         spi_register_board_info(palmtt_boardinfo,ARRAY_SIZE(palmtt_boardinfo));
268         omap_serial_init();
269         omap1_usb_init(&palmtt_usb_config);
270         omap_register_i2c_bus(1, 100, NULL, 0);
271
272         omapfb_set_lcd_config(&palmtt_lcd_config);
273 }
274
275 MACHINE_START(OMAP_PALMTT, "OMAP1510 based Palm Tungsten|T")
276         .atag_offset    = 0x100,
277         .map_io         = omap15xx_map_io,
278         .init_early     = omap1_init_early,
279         .init_irq       = omap1_init_irq,
280         .handle_irq     = omap1_handle_irq,
281         .init_machine   = omap_palmtt_init,
282         .init_late      = omap1_init_late,
283         .init_time      = omap1_timer_init,
284         .restart        = omap1_restart,
285 MACHINE_END