1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3  * linux/arch/arm/mach-omap1/board-palmz71.c
4  *
5  * Modified from board-generic.c
6  *
7  * Support for the Palm Zire71 PDA.
8  *
9  * Original version : Laurent Gonzalez
10  *
11  * Modified for zire71 : Marek Vasut
12  */
13 
14 #include <linux/delay.h>
15 #include <linux/gpio.h>
16 #include <linux/kernel.h>
17 #include <linux/init.h>
18 #include <linux/platform_device.h>
19 #include <linux/notifier.h>
20 #include <linux/clk.h>
21 #include <linux/irq.h>
22 #include <linux/input.h>
23 #include <linux/interrupt.h>
24 #include <linux/mtd/mtd.h>
25 #include <linux/mtd/partitions.h>
26 #include <linux/mtd/physmap.h>
27 #include <linux/omapfb.h>
28 #include <linux/spi/spi.h>
29 #include <linux/spi/ads7846.h>
30 #include <linux/platform_data/omap1_bl.h>
31 #include <linux/platform_data/keypad-omap.h>
32 #include <linux/omap-dma.h>
33 
34 #include <asm/mach-types.h>
35 #include <asm/mach/arch.h>
36 #include <asm/mach/map.h>
37 
38 #include "tc.h"
39 #include "flash.h"
40 #include "mux.h"
41 #include "hardware.h"
42 #include "usb.h"
43 #include "common.h"
44 
45 #define PALMZ71_USBDETECT_GPIO	0
46 #define PALMZ71_PENIRQ_GPIO	6
47 #define PALMZ71_MMC_WP_GPIO	8
48 #define PALMZ71_HDQ_GPIO 	11
49 
50 #define PALMZ71_HOTSYNC_GPIO	OMAP_MPUIO(1)
51 #define PALMZ71_CABLE_GPIO	OMAP_MPUIO(2)
52 #define PALMZ71_SLIDER_GPIO	OMAP_MPUIO(3)
53 #define PALMZ71_MMC_IN_GPIO	OMAP_MPUIO(4)
54 
55 static const unsigned int palmz71_keymap[] = {
56 	KEY(0, 0, KEY_F1),
57 	KEY(1, 0, KEY_F2),
58 	KEY(2, 0, KEY_F3),
59 	KEY(3, 0, KEY_F4),
60 	KEY(4, 0, KEY_POWER),
61 	KEY(0, 1, KEY_LEFT),
62 	KEY(1, 1, KEY_DOWN),
63 	KEY(2, 1, KEY_UP),
64 	KEY(3, 1, KEY_RIGHT),
65 	KEY(4, 1, KEY_ENTER),
66 	KEY(0, 2, KEY_CAMERA),
67 };
68 
69 static const struct matrix_keymap_data palmz71_keymap_data = {
70 	.keymap		= palmz71_keymap,
71 	.keymap_size	= ARRAY_SIZE(palmz71_keymap),
72 };
73 
74 static struct omap_kp_platform_data palmz71_kp_data = {
75 	.rows	= 8,
76 	.cols	= 8,
77 	.keymap_data	= &palmz71_keymap_data,
78 	.rep	= true,
79 	.delay	= 80,
80 };
81 
82 static struct resource palmz71_kp_resources[] = {
83 	[0] = {
84 		.start	= INT_KEYBOARD,
85 		.end	= INT_KEYBOARD,
86 		.flags	= IORESOURCE_IRQ,
87 	},
88 };
89 
90 static struct platform_device palmz71_kp_device = {
91 	.name	= "omap-keypad",
92 	.id	= -1,
93 	.dev	= {
94 		.platform_data = &palmz71_kp_data,
95 	},
96 	.num_resources	= ARRAY_SIZE(palmz71_kp_resources),
97 	.resource	= palmz71_kp_resources,
98 };
99 
100 static struct mtd_partition palmz71_rom_partitions[] = {
101 	/* PalmOS "Small ROM", contains the bootloader and the debugger */
102 	{
103 		.name		= "smallrom",
104 		.offset		= 0,
105 		.size		= 0xa000,
106 		.mask_flags	= MTD_WRITEABLE,
107 	},
108 	/* PalmOS "Big ROM", a filesystem with all the OS code and data */
109 	{
110 		.name	= "bigrom",
111 		.offset	= SZ_128K,
112 		/*
113 		 * 0x5f0000 bytes big in the multi-language ("EFIGS") version,
114 		 * 0x7b0000 bytes in the English-only ("enUS") version.
115 		 */
116 		.size		= 0x7b0000,
117 		.mask_flags	= MTD_WRITEABLE,
118 	},
119 };
120 
121 static struct physmap_flash_data palmz71_rom_data = {
122 	.width		= 2,
123 	.set_vpp	= omap1_set_vpp,
124 	.parts		= palmz71_rom_partitions,
125 	.nr_parts	= ARRAY_SIZE(palmz71_rom_partitions),
126 };
127 
128 static struct resource palmz71_rom_resource = {
129 	.start	= OMAP_CS0_PHYS,
130 	.end	= OMAP_CS0_PHYS + SZ_8M - 1,
131 	.flags	= IORESOURCE_MEM,
132 };
133 
134 static struct platform_device palmz71_rom_device = {
135 	.name	= "physmap-flash",
136 	.id	= -1,
137 	.dev = {
138 		.platform_data = &palmz71_rom_data,
139 	},
140 	.num_resources	= 1,
141 	.resource	= &palmz71_rom_resource,
142 };
143 
144 static struct platform_device palmz71_lcd_device = {
145 	.name	= "lcd_palmz71",
146 	.id	= -1,
147 };
148 
149 static struct platform_device palmz71_spi_device = {
150 	.name	= "spi_palmz71",
151 	.id	= -1,
152 };
153 
154 static struct omap_backlight_config palmz71_backlight_config = {
155 	.default_intensity	= 0xa0,
156 };
157 
158 static struct platform_device palmz71_backlight_device = {
159 	.name	= "omap-bl",
160 	.id	= -1,
161 	.dev	= {
162 		.platform_data = &palmz71_backlight_config,
163 	},
164 };
165 
166 static struct platform_device *devices[] __initdata = {
167 	&palmz71_rom_device,
168 	&palmz71_kp_device,
169 	&palmz71_lcd_device,
170 	&palmz71_spi_device,
171 	&palmz71_backlight_device,
172 };
173 
174 static int
palmz71_get_pendown_state(void)175 palmz71_get_pendown_state(void)
176 {
177 	return !gpio_get_value(PALMZ71_PENIRQ_GPIO);
178 }
179 
180 static const struct ads7846_platform_data palmz71_ts_info = {
181 	.model			= 7846,
182 	.vref_delay_usecs	= 100,	/* internal, no capacitor */
183 	.x_plate_ohms		= 419,
184 	.y_plate_ohms		= 486,
185 	.get_pendown_state	= palmz71_get_pendown_state,
186 };
187 
188 static struct spi_board_info __initdata palmz71_boardinfo[] = { {
189 	/* MicroWire (bus 2) CS0 has an ads7846e */
190 	.modalias	= "ads7846",
191 	.platform_data	= &palmz71_ts_info,
192 	.max_speed_hz	= 120000	/* max sample rate at 3V */
193 				* 26	/* command + data + overhead */,
194 	.bus_num	= 2,
195 	.chip_select	= 0,
196 } };
197 
198 static struct omap_usb_config palmz71_usb_config __initdata = {
199 	.register_dev	= 1,	/* Mini-B only receptacle */
200 	.hmc_mode	= 0,
201 	.pins[0]	= 2,
202 };
203 
204 static const struct omap_lcd_config palmz71_lcd_config __initconst = {
205 	.ctrl_name = "internal",
206 };
207 
208 static irqreturn_t
palmz71_powercable(int irq,void * dev_id)209 palmz71_powercable(int irq, void *dev_id)
210 {
211 	if (gpio_get_value(PALMZ71_USBDETECT_GPIO)) {
212 		printk(KERN_INFO "PM: Power cable connected\n");
213 		irq_set_irq_type(gpio_to_irq(PALMZ71_USBDETECT_GPIO),
214 				 IRQ_TYPE_EDGE_FALLING);
215 	} else {
216 		printk(KERN_INFO "PM: Power cable disconnected\n");
217 		irq_set_irq_type(gpio_to_irq(PALMZ71_USBDETECT_GPIO),
218 				 IRQ_TYPE_EDGE_RISING);
219 	}
220 	return IRQ_HANDLED;
221 }
222 
223 static void __init
omap_mpu_wdt_mode(int mode)224 omap_mpu_wdt_mode(int mode)
225 {
226 	if (mode)
227 		omap_writew(0x8000, OMAP_WDT_TIMER_MODE);
228 	else {
229 		omap_writew(0x00f5, OMAP_WDT_TIMER_MODE);
230 		omap_writew(0x00a0, OMAP_WDT_TIMER_MODE);
231 	}
232 }
233 
234 static void __init
palmz71_gpio_setup(int early)235 palmz71_gpio_setup(int early)
236 {
237 	if (early) {
238 		/* Only set GPIO1 so we have a working serial */
239 		gpio_direction_output(1, 1);
240 	} else {
241 		/* Set MMC/SD host WP pin as input */
242 		if (gpio_request(PALMZ71_MMC_WP_GPIO, "MMC WP") < 0) {
243 			printk(KERN_ERR "Could not reserve WP GPIO!\n");
244 			return;
245 		}
246 		gpio_direction_input(PALMZ71_MMC_WP_GPIO);
247 
248 		/* Monitor the Power-cable-connected signal */
249 		if (gpio_request(PALMZ71_USBDETECT_GPIO, "USB detect") < 0) {
250 			printk(KERN_ERR
251 				"Could not reserve cable signal GPIO!\n");
252 			return;
253 		}
254 		gpio_direction_input(PALMZ71_USBDETECT_GPIO);
255 		if (request_irq(gpio_to_irq(PALMZ71_USBDETECT_GPIO),
256 				palmz71_powercable, 0, "palmz71-cable", NULL))
257 			printk(KERN_ERR
258 					"IRQ request for power cable failed!\n");
259 		palmz71_powercable(gpio_to_irq(PALMZ71_USBDETECT_GPIO), NULL);
260 	}
261 }
262 
263 static void __init
omap_palmz71_init(void)264 omap_palmz71_init(void)
265 {
266 	/* mux pins for uarts */
267 	omap_cfg_reg(UART1_TX);
268 	omap_cfg_reg(UART1_RTS);
269 	omap_cfg_reg(UART2_TX);
270 	omap_cfg_reg(UART2_RTS);
271 	omap_cfg_reg(UART3_TX);
272 	omap_cfg_reg(UART3_RX);
273 
274 	palmz71_gpio_setup(1);
275 	omap_mpu_wdt_mode(0);
276 
277 	platform_add_devices(devices, ARRAY_SIZE(devices));
278 
279 	palmz71_boardinfo[0].irq = gpio_to_irq(PALMZ71_PENIRQ_GPIO);
280 	spi_register_board_info(palmz71_boardinfo,
281 				ARRAY_SIZE(palmz71_boardinfo));
282 	omap1_usb_init(&palmz71_usb_config);
283 	omap_serial_init();
284 	omap_register_i2c_bus(1, 100, NULL, 0);
285 	palmz71_gpio_setup(0);
286 
287 	omapfb_set_lcd_config(&palmz71_lcd_config);
288 }
289 
290 MACHINE_START(OMAP_PALMZ71, "OMAP310 based Palm Zire71")
291 	.atag_offset	= 0x100,
292 	.map_io		= omap15xx_map_io,
293 	.init_early     = omap1_init_early,
294 	.init_irq	= omap1_init_irq,
295 	.handle_irq	= omap1_handle_irq,
296 	.init_machine	= omap_palmz71_init,
297 	.init_late	= omap1_init_late,
298 	.init_time	= omap1_timer_init,
299 	.restart	= omap1_restart,
300 MACHINE_END
301