xref: /openbmc/linux/arch/arm/mach-pxa/spitz.c (revision 90848a25)
1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3  * Support for Sharp SL-Cxx00 Series of PDAs
4  * Models: SL-C3000 (Spitz), SL-C1000 (Akita) and SL-C3100 (Borzoi)
5  *
6  * Copyright (c) 2005 Richard Purdie
7  *
8  * Based on Sharp's 2.4 kernel patches/lubbock.c
9  */
10 
11 #include <linux/kernel.h>
12 #include <linux/module.h>	/* symbol_get ; symbol_put */
13 #include <linux/platform_device.h>
14 #include <linux/delay.h>
15 #include <linux/gpio_keys.h>
16 #include <linux/gpio.h>
17 #include <linux/gpio/machine.h>
18 #include <linux/leds.h>
19 #include <linux/i2c.h>
20 #include <linux/platform_data/i2c-pxa.h>
21 #include <linux/platform_data/pca953x.h>
22 #include <linux/spi/spi.h>
23 #include <linux/spi/ads7846.h>
24 #include <linux/spi/corgi_lcd.h>
25 #include <linux/spi/pxa2xx_spi.h>
26 #include <linux/mtd/sharpsl.h>
27 #include <linux/mtd/physmap.h>
28 #include <linux/input-event-codes.h>
29 #include <linux/input/matrix_keypad.h>
30 #include <linux/regulator/machine.h>
31 #include <linux/io.h>
32 #include <linux/reboot.h>
33 #include <linux/memblock.h>
34 
35 #include <asm/setup.h>
36 #include <asm/mach-types.h>
37 #include <asm/mach/arch.h>
38 #include <asm/mach/sharpsl_param.h>
39 #include <asm/hardware/scoop.h>
40 
41 #include "pxa27x.h"
42 #include "pxa27x-udc.h"
43 #include "reset.h"
44 #include <linux/platform_data/mmc-pxamci.h>
45 #include <linux/platform_data/usb-ohci-pxa27x.h>
46 #include <linux/platform_data/video-pxafb.h>
47 #include "spitz.h"
48 #include "sharpsl_pm.h"
49 #include "smemc.h"
50 
51 #include "generic.h"
52 #include "devices.h"
53 
54 /******************************************************************************
55  * Pin configuration
56  ******************************************************************************/
57 static unsigned long spitz_pin_config[] __initdata = {
58 	/* Chip Selects */
59 	GPIO78_nCS_2,	/* SCOOP #2 */
60 	GPIO79_nCS_3,	/* NAND */
61 	GPIO80_nCS_4,	/* SCOOP #1 */
62 
63 	/* LCD - 16bpp Active TFT */
64 	GPIOxx_LCD_TFT_16BPP,
65 
66 	/* PC Card */
67 	GPIO48_nPOE,
68 	GPIO49_nPWE,
69 	GPIO50_nPIOR,
70 	GPIO51_nPIOW,
71 	GPIO85_nPCE_1,
72 	GPIO54_nPCE_2,
73 	GPIO55_nPREG,
74 	GPIO56_nPWAIT,
75 	GPIO57_nIOIS16,
76 	GPIO104_PSKTSEL,
77 
78 	/* I2S */
79 	GPIO28_I2S_BITCLK_OUT,
80 	GPIO29_I2S_SDATA_IN,
81 	GPIO30_I2S_SDATA_OUT,
82 	GPIO31_I2S_SYNC,
83 
84 	/* MMC */
85 	GPIO32_MMC_CLK,
86 	GPIO112_MMC_CMD,
87 	GPIO92_MMC_DAT_0,
88 	GPIO109_MMC_DAT_1,
89 	GPIO110_MMC_DAT_2,
90 	GPIO111_MMC_DAT_3,
91 
92 	/* GPIOs */
93 	GPIO9_GPIO,	/* SPITZ_GPIO_nSD_DETECT */
94 	GPIO16_GPIO,	/* SPITZ_GPIO_SYNC */
95 	GPIO81_GPIO,	/* SPITZ_GPIO_nSD_WP */
96 	GPIO41_GPIO,	/* SPITZ_GPIO_USB_CONNECT */
97 	GPIO37_GPIO,	/* SPITZ_GPIO_USB_HOST */
98 	GPIO35_GPIO,	/* SPITZ_GPIO_USB_DEVICE */
99 	GPIO22_GPIO,	/* SPITZ_GPIO_HSYNC */
100 	GPIO94_GPIO,	/* SPITZ_GPIO_CF_CD */
101 	GPIO105_GPIO,	/* SPITZ_GPIO_CF_IRQ */
102 	GPIO106_GPIO,	/* SPITZ_GPIO_CF2_IRQ */
103 
104 	/* GPIO matrix keypad */
105 	GPIO88_GPIO,	/* column 0 */
106 	GPIO23_GPIO,	/* column 1 */
107 	GPIO24_GPIO,	/* column 2 */
108 	GPIO25_GPIO,	/* column 3 */
109 	GPIO26_GPIO,	/* column 4 */
110 	GPIO27_GPIO,	/* column 5 */
111 	GPIO52_GPIO,	/* column 6 */
112 	GPIO103_GPIO,	/* column 7 */
113 	GPIO107_GPIO,	/* column 8 */
114 	GPIO108_GPIO,	/* column 9 */
115 	GPIO114_GPIO,	/* column 10 */
116 	GPIO12_GPIO,	/* row 0 */
117 	GPIO17_GPIO,	/* row 1 */
118 	GPIO91_GPIO,	/* row 2 */
119 	GPIO34_GPIO,	/* row 3 */
120 	GPIO36_GPIO,	/* row 4 */
121 	GPIO38_GPIO,	/* row 5 */
122 	GPIO39_GPIO,	/* row 6 */
123 
124 	/* I2C */
125 	GPIO117_I2C_SCL,
126 	GPIO118_I2C_SDA,
127 
128 	GPIO0_GPIO | WAKEUP_ON_EDGE_RISE,	/* SPITZ_GPIO_KEY_INT */
129 	GPIO1_GPIO | WAKEUP_ON_EDGE_FALL,	/* SPITZ_GPIO_RESET */
130 };
131 
132 
133 /******************************************************************************
134  * Scoop GPIO expander
135  ******************************************************************************/
136 #if defined(CONFIG_SHARP_SCOOP) || defined(CONFIG_SHARP_SCOOP_MODULE)
137 /* SCOOP Device #1 */
138 static struct resource spitz_scoop_1_resources[] = {
139 	[0] = {
140 		.start		= 0x10800000,
141 		.end		= 0x10800fff,
142 		.flags		= IORESOURCE_MEM,
143 	},
144 };
145 
146 static struct scoop_config spitz_scoop_1_setup = {
147 	.io_dir		= SPITZ_SCP_IO_DIR,
148 	.io_out		= SPITZ_SCP_IO_OUT,
149 	.suspend_clr	= SPITZ_SCP_SUS_CLR,
150 	.suspend_set	= SPITZ_SCP_SUS_SET,
151 	.gpio_base	= SPITZ_SCP_GPIO_BASE,
152 };
153 
154 struct platform_device spitz_scoop_1_device = {
155 	.name		= "sharp-scoop",
156 	.id		= 0,
157 	.dev		= {
158 		.platform_data	= &spitz_scoop_1_setup,
159 	},
160 	.num_resources	= ARRAY_SIZE(spitz_scoop_1_resources),
161 	.resource	= spitz_scoop_1_resources,
162 };
163 
164 /* SCOOP Device #2 */
165 static struct resource spitz_scoop_2_resources[] = {
166 	[0] = {
167 		.start		= 0x08800040,
168 		.end		= 0x08800fff,
169 		.flags		= IORESOURCE_MEM,
170 	},
171 };
172 
173 static struct scoop_config spitz_scoop_2_setup = {
174 	.io_dir		= SPITZ_SCP2_IO_DIR,
175 	.io_out		= SPITZ_SCP2_IO_OUT,
176 	.suspend_clr	= SPITZ_SCP2_SUS_CLR,
177 	.suspend_set	= SPITZ_SCP2_SUS_SET,
178 	.gpio_base	= SPITZ_SCP2_GPIO_BASE,
179 };
180 
181 struct platform_device spitz_scoop_2_device = {
182 	.name		= "sharp-scoop",
183 	.id		= 1,
184 	.dev		= {
185 		.platform_data	= &spitz_scoop_2_setup,
186 	},
187 	.num_resources	= ARRAY_SIZE(spitz_scoop_2_resources),
188 	.resource	= spitz_scoop_2_resources,
189 };
190 
191 static void __init spitz_scoop_init(void)
192 {
193 	platform_device_register(&spitz_scoop_1_device);
194 
195 	/* Akita doesn't have the second SCOOP chip */
196 	if (!machine_is_akita())
197 		platform_device_register(&spitz_scoop_2_device);
198 }
199 
200 /* Power control is shared with between one of the CF slots and SD */
201 static void __maybe_unused spitz_card_pwr_ctrl(uint8_t enable, uint8_t new_cpr)
202 {
203 	unsigned short cpr;
204 	unsigned long flags;
205 
206 	if (new_cpr & 0x7) {
207 		gpio_set_value(SPITZ_GPIO_CF_POWER, 1);
208 		mdelay(5);
209 	}
210 
211 	local_irq_save(flags);
212 
213 	cpr = read_scoop_reg(&spitz_scoop_1_device.dev, SCOOP_CPR);
214 
215 	if (enable & new_cpr)
216 		cpr |= new_cpr;
217 	else
218 		cpr &= ~enable;
219 
220 	write_scoop_reg(&spitz_scoop_1_device.dev, SCOOP_CPR, cpr);
221 
222 	local_irq_restore(flags);
223 
224 	if (!(cpr & 0x7)) {
225 		mdelay(1);
226 		gpio_set_value(SPITZ_GPIO_CF_POWER, 0);
227 	}
228 }
229 
230 #else
231 static inline void spitz_scoop_init(void) {}
232 static inline void spitz_card_pwr_ctrl(uint8_t enable, uint8_t new_cpr) {}
233 #endif
234 
235 /******************************************************************************
236  * PCMCIA
237  ******************************************************************************/
238 #if defined(CONFIG_PCMCIA_PXA2XX) || defined(CONFIG_PCMCIA_PXA2XX_MODULE)
239 static void spitz_pcmcia_pwr(struct device *scoop, uint16_t cpr, int nr)
240 {
241 	/* Only need to override behaviour for slot 0 */
242 	if (nr == 0)
243 		spitz_card_pwr_ctrl(
244 			cpr & (SCOOP_CPR_CF_3V | SCOOP_CPR_CF_XV), cpr);
245 	else
246 		write_scoop_reg(scoop, SCOOP_CPR, cpr);
247 }
248 
249 static struct scoop_pcmcia_dev spitz_pcmcia_scoop[] = {
250 	{
251 		.dev		= &spitz_scoop_1_device.dev,
252 		.irq		= SPITZ_IRQ_GPIO_CF_IRQ,
253 		.cd_irq		= SPITZ_IRQ_GPIO_CF_CD,
254 		.cd_irq_str	= "PCMCIA0 CD",
255 	}, {
256 		.dev		= &spitz_scoop_2_device.dev,
257 		.irq		= SPITZ_IRQ_GPIO_CF2_IRQ,
258 		.cd_irq		= -1,
259 	},
260 };
261 
262 static struct scoop_pcmcia_config spitz_pcmcia_config = {
263 	.devs		= &spitz_pcmcia_scoop[0],
264 	.num_devs	= 2,
265 	.power_ctrl	= spitz_pcmcia_pwr,
266 };
267 
268 static void __init spitz_pcmcia_init(void)
269 {
270 	/* Akita has only one PCMCIA slot used */
271 	if (machine_is_akita())
272 		spitz_pcmcia_config.num_devs = 1;
273 
274 	platform_scoop_config = &spitz_pcmcia_config;
275 }
276 #else
277 static inline void spitz_pcmcia_init(void) {}
278 #endif
279 
280 /******************************************************************************
281  * GPIO keyboard
282  ******************************************************************************/
283 #if defined(CONFIG_KEYBOARD_MATRIX) || defined(CONFIG_KEYBOARD_MATRIX_MODULE)
284 
285 #define SPITZ_KEY_CALENDAR	KEY_F1
286 #define SPITZ_KEY_ADDRESS	KEY_F2
287 #define SPITZ_KEY_FN		KEY_F3
288 #define SPITZ_KEY_CANCEL	KEY_F4
289 #define SPITZ_KEY_EXOK		KEY_F5
290 #define SPITZ_KEY_EXCANCEL	KEY_F6
291 #define SPITZ_KEY_EXJOGDOWN	KEY_F7
292 #define SPITZ_KEY_EXJOGUP	KEY_F8
293 #define SPITZ_KEY_JAP1		KEY_LEFTALT
294 #define SPITZ_KEY_JAP2		KEY_RIGHTCTRL
295 #define SPITZ_KEY_SYNC		KEY_F9
296 #define SPITZ_KEY_MAIL		KEY_F10
297 #define SPITZ_KEY_OK		KEY_F11
298 #define SPITZ_KEY_MENU		KEY_F12
299 
300 static const uint32_t spitz_keymap[] = {
301 	KEY(0, 0, KEY_LEFTCTRL),
302 	KEY(0, 1, KEY_1),
303 	KEY(0, 2, KEY_3),
304 	KEY(0, 3, KEY_5),
305 	KEY(0, 4, KEY_6),
306 	KEY(0, 5, KEY_7),
307 	KEY(0, 6, KEY_9),
308 	KEY(0, 7, KEY_0),
309 	KEY(0, 8, KEY_BACKSPACE),
310 	KEY(0, 9, SPITZ_KEY_EXOK),	/* EXOK */
311 	KEY(0, 10, SPITZ_KEY_EXCANCEL),	/* EXCANCEL */
312 	KEY(1, 1, KEY_2),
313 	KEY(1, 2, KEY_4),
314 	KEY(1, 3, KEY_R),
315 	KEY(1, 4, KEY_Y),
316 	KEY(1, 5, KEY_8),
317 	KEY(1, 6, KEY_I),
318 	KEY(1, 7, KEY_O),
319 	KEY(1, 8, KEY_P),
320 	KEY(1, 9, SPITZ_KEY_EXJOGDOWN),	/* EXJOGDOWN */
321 	KEY(1, 10, SPITZ_KEY_EXJOGUP),	/* EXJOGUP */
322 	KEY(2, 0, KEY_TAB),
323 	KEY(2, 1, KEY_Q),
324 	KEY(2, 2, KEY_E),
325 	KEY(2, 3, KEY_T),
326 	KEY(2, 4, KEY_G),
327 	KEY(2, 5, KEY_U),
328 	KEY(2, 6, KEY_J),
329 	KEY(2, 7, KEY_K),
330 	KEY(3, 0, SPITZ_KEY_ADDRESS),	/* ADDRESS */
331 	KEY(3, 1, KEY_W),
332 	KEY(3, 2, KEY_S),
333 	KEY(3, 3, KEY_F),
334 	KEY(3, 4, KEY_V),
335 	KEY(3, 5, KEY_H),
336 	KEY(3, 6, KEY_M),
337 	KEY(3, 7, KEY_L),
338 	KEY(3, 9, KEY_RIGHTSHIFT),
339 	KEY(4, 0, SPITZ_KEY_CALENDAR),	/* CALENDAR */
340 	KEY(4, 1, KEY_A),
341 	KEY(4, 2, KEY_D),
342 	KEY(4, 3, KEY_C),
343 	KEY(4, 4, KEY_B),
344 	KEY(4, 5, KEY_N),
345 	KEY(4, 6, KEY_DOT),
346 	KEY(4, 8, KEY_ENTER),
347 	KEY(4, 9, KEY_LEFTSHIFT),
348 	KEY(5, 0, SPITZ_KEY_MAIL),	/* MAIL */
349 	KEY(5, 1, KEY_Z),
350 	KEY(5, 2, KEY_X),
351 	KEY(5, 3, KEY_MINUS),
352 	KEY(5, 4, KEY_SPACE),
353 	KEY(5, 5, KEY_COMMA),
354 	KEY(5, 7, KEY_UP),
355 	KEY(5, 10, SPITZ_KEY_FN),	/* FN */
356 	KEY(6, 0, KEY_SYSRQ),
357 	KEY(6, 1, SPITZ_KEY_JAP1),	/* JAP1 */
358 	KEY(6, 2, SPITZ_KEY_JAP2),	/* JAP2 */
359 	KEY(6, 3, SPITZ_KEY_CANCEL),	/* CANCEL */
360 	KEY(6, 4, SPITZ_KEY_OK),	/* OK */
361 	KEY(6, 5, SPITZ_KEY_MENU),	/* MENU */
362 	KEY(6, 6, KEY_LEFT),
363 	KEY(6, 7, KEY_DOWN),
364 	KEY(6, 8, KEY_RIGHT),
365 };
366 
367 static const struct matrix_keymap_data spitz_keymap_data = {
368 	.keymap		= spitz_keymap,
369 	.keymap_size	= ARRAY_SIZE(spitz_keymap),
370 };
371 
372 static const uint32_t spitz_row_gpios[] =
373 		{ 12, 17, 91, 34, 36, 38, 39 };
374 static const uint32_t spitz_col_gpios[] =
375 		{ 88, 23, 24, 25, 26, 27, 52, 103, 107, 108, 114 };
376 
377 static struct matrix_keypad_platform_data spitz_mkp_pdata = {
378 	.keymap_data		= &spitz_keymap_data,
379 	.row_gpios		= spitz_row_gpios,
380 	.col_gpios		= spitz_col_gpios,
381 	.num_row_gpios		= ARRAY_SIZE(spitz_row_gpios),
382 	.num_col_gpios		= ARRAY_SIZE(spitz_col_gpios),
383 	.col_scan_delay_us	= 10,
384 	.debounce_ms		= 10,
385 	.wakeup			= 1,
386 };
387 
388 static struct platform_device spitz_mkp_device = {
389 	.name		= "matrix-keypad",
390 	.id		= -1,
391 	.dev		= {
392 		.platform_data	= &spitz_mkp_pdata,
393 	},
394 };
395 
396 static void __init spitz_mkp_init(void)
397 {
398 	platform_device_register(&spitz_mkp_device);
399 }
400 #else
401 static inline void spitz_mkp_init(void) {}
402 #endif
403 
404 /******************************************************************************
405  * GPIO keys
406  ******************************************************************************/
407 #if defined(CONFIG_KEYBOARD_GPIO) || defined(CONFIG_KEYBOARD_GPIO_MODULE)
408 static struct gpio_keys_button spitz_gpio_keys[] = {
409 	{
410 		.type	= EV_PWR,
411 		.code	= KEY_SUSPEND,
412 		.gpio	= SPITZ_GPIO_ON_KEY,
413 		.desc	= "On Off",
414 		.wakeup	= 1,
415 	},
416 	/* Two buttons detecting the lid state */
417 	{
418 		.type	= EV_SW,
419 		.code	= 0,
420 		.gpio	= SPITZ_GPIO_SWA,
421 		.desc	= "Display Down",
422 	},
423 	{
424 		.type	= EV_SW,
425 		.code	= 1,
426 		.gpio	= SPITZ_GPIO_SWB,
427 		.desc	= "Lid Closed",
428 	},
429 };
430 
431 static struct gpio_keys_platform_data spitz_gpio_keys_platform_data = {
432 	.buttons	= spitz_gpio_keys,
433 	.nbuttons	= ARRAY_SIZE(spitz_gpio_keys),
434 };
435 
436 static struct platform_device spitz_gpio_keys_device = {
437 	.name	= "gpio-keys",
438 	.id	= -1,
439 	.dev	= {
440 		.platform_data	= &spitz_gpio_keys_platform_data,
441 	},
442 };
443 
444 static void __init spitz_keys_init(void)
445 {
446 	platform_device_register(&spitz_gpio_keys_device);
447 }
448 #else
449 static inline void spitz_keys_init(void) {}
450 #endif
451 
452 /******************************************************************************
453  * LEDs
454  ******************************************************************************/
455 #if defined(CONFIG_LEDS_GPIO) || defined(CONFIG_LEDS_GPIO_MODULE)
456 static struct gpio_led spitz_gpio_leds[] = {
457 	{
458 		.name			= "spitz:amber:charge",
459 		.default_trigger	= "sharpsl-charge",
460 		.gpio			= SPITZ_GPIO_LED_ORANGE,
461 	},
462 	{
463 		.name			= "spitz:green:hddactivity",
464 		.default_trigger	= "disk-activity",
465 		.gpio			= SPITZ_GPIO_LED_GREEN,
466 	},
467 };
468 
469 static struct gpio_led_platform_data spitz_gpio_leds_info = {
470 	.leds		= spitz_gpio_leds,
471 	.num_leds	= ARRAY_SIZE(spitz_gpio_leds),
472 };
473 
474 static struct platform_device spitz_led_device = {
475 	.name		= "leds-gpio",
476 	.id		= -1,
477 	.dev		= {
478 		.platform_data	= &spitz_gpio_leds_info,
479 	},
480 };
481 
482 static void __init spitz_leds_init(void)
483 {
484 	platform_device_register(&spitz_led_device);
485 }
486 #else
487 static inline void spitz_leds_init(void) {}
488 #endif
489 
490 /******************************************************************************
491  * SSP Devices
492  ******************************************************************************/
493 #if defined(CONFIG_SPI_PXA2XX) || defined(CONFIG_SPI_PXA2XX_MODULE)
494 static void spitz_ads7846_wait_for_hsync(void)
495 {
496 	while (gpio_get_value(SPITZ_GPIO_HSYNC))
497 		cpu_relax();
498 
499 	while (!gpio_get_value(SPITZ_GPIO_HSYNC))
500 		cpu_relax();
501 }
502 
503 static struct ads7846_platform_data spitz_ads7846_info = {
504 	.model			= 7846,
505 	.vref_delay_usecs	= 100,
506 	.x_plate_ohms		= 419,
507 	.y_plate_ohms		= 486,
508 	.pressure_max		= 1024,
509 	.gpio_pendown		= SPITZ_GPIO_TP_INT,
510 	.wait_for_sync		= spitz_ads7846_wait_for_hsync,
511 };
512 
513 static void spitz_bl_kick_battery(void)
514 {
515 	void (*kick_batt)(void);
516 
517 	kick_batt = symbol_get(sharpsl_battery_kick);
518 	if (kick_batt) {
519 		kick_batt();
520 		symbol_put(sharpsl_battery_kick);
521 	}
522 }
523 
524 static struct gpiod_lookup_table spitz_lcdcon_gpio_table = {
525 	.dev_id = "spi2.1",
526 	.table = {
527 		GPIO_LOOKUP("gpio-pxa", SPITZ_GPIO_BACKLIGHT_CONT,
528 			    "BL_CONT", GPIO_ACTIVE_LOW),
529 		GPIO_LOOKUP("gpio-pxa", SPITZ_GPIO_BACKLIGHT_ON,
530 			    "BL_ON", GPIO_ACTIVE_HIGH),
531 		{ },
532 	},
533 };
534 
535 static struct gpiod_lookup_table akita_lcdcon_gpio_table = {
536 	.dev_id = "spi2.1",
537 	.table = {
538 		GPIO_LOOKUP("gpio-pxa", AKITA_GPIO_BACKLIGHT_CONT,
539 			    "BL_CONT", GPIO_ACTIVE_LOW),
540 		GPIO_LOOKUP("gpio-pxa", AKITA_GPIO_BACKLIGHT_ON,
541 			    "BL_ON", GPIO_ACTIVE_HIGH),
542 		{ },
543 	},
544 };
545 
546 static struct corgi_lcd_platform_data spitz_lcdcon_info = {
547 	.init_mode		= CORGI_LCD_MODE_VGA,
548 	.max_intensity		= 0x2f,
549 	.default_intensity	= 0x1f,
550 	.limit_mask		= 0x0b,
551 	.kick_battery		= spitz_bl_kick_battery,
552 };
553 
554 static struct spi_board_info spitz_spi_devices[] = {
555 	{
556 		.modalias		= "ads7846",
557 		.max_speed_hz		= 1200000,
558 		.bus_num		= 2,
559 		.chip_select		= 0,
560 		.platform_data		= &spitz_ads7846_info,
561 		.irq			= PXA_GPIO_TO_IRQ(SPITZ_GPIO_TP_INT),
562 	}, {
563 		.modalias		= "corgi-lcd",
564 		.max_speed_hz		= 50000,
565 		.bus_num		= 2,
566 		.chip_select		= 1,
567 		.platform_data		= &spitz_lcdcon_info,
568 	}, {
569 		.modalias		= "max1111",
570 		.max_speed_hz		= 450000,
571 		.bus_num		= 2,
572 		.chip_select		= 2,
573 	},
574 };
575 
576 static struct pxa2xx_spi_controller spitz_spi_info = {
577 	.num_chipselect	= 3,
578 };
579 
580 static struct gpiod_lookup_table spitz_spi_gpio_table = {
581 	.dev_id = "spi2",
582 	.table = {
583 		GPIO_LOOKUP_IDX("gpio-pxa", SPITZ_GPIO_ADS7846_CS, "cs", 0, GPIO_ACTIVE_LOW),
584 		GPIO_LOOKUP_IDX("gpio-pxa", SPITZ_GPIO_LCDCON_CS, "cs", 1, GPIO_ACTIVE_LOW),
585 		GPIO_LOOKUP_IDX("gpio-pxa", SPITZ_GPIO_MAX1111_CS, "cs", 2, GPIO_ACTIVE_LOW),
586 		{ },
587 	},
588 };
589 
590 static void __init spitz_spi_init(void)
591 {
592 	if (machine_is_akita())
593 		gpiod_add_lookup_table(&akita_lcdcon_gpio_table);
594 	else
595 		gpiod_add_lookup_table(&spitz_lcdcon_gpio_table);
596 
597 	gpiod_add_lookup_table(&spitz_spi_gpio_table);
598 	pxa2xx_set_spi_info(2, &spitz_spi_info);
599 	spi_register_board_info(ARRAY_AND_SIZE(spitz_spi_devices));
600 }
601 #else
602 static inline void spitz_spi_init(void) {}
603 #endif
604 
605 /******************************************************************************
606  * SD/MMC card controller
607  ******************************************************************************/
608 #if defined(CONFIG_MMC_PXA) || defined(CONFIG_MMC_PXA_MODULE)
609 /*
610  * NOTE: The card detect interrupt isn't debounced so we delay it by 250ms to
611  * give the card a chance to fully insert/eject.
612  */
613 static int spitz_mci_setpower(struct device *dev, unsigned int vdd)
614 {
615 	struct pxamci_platform_data* p_d = dev->platform_data;
616 
617 	if ((1 << vdd) & p_d->ocr_mask)
618 		spitz_card_pwr_ctrl(SCOOP_CPR_SD_3V, SCOOP_CPR_SD_3V);
619 	else
620 		spitz_card_pwr_ctrl(SCOOP_CPR_SD_3V, 0x0);
621 
622 	return 0;
623 }
624 
625 static struct pxamci_platform_data spitz_mci_platform_data = {
626 	.detect_delay_ms	= 250,
627 	.ocr_mask		= MMC_VDD_32_33|MMC_VDD_33_34,
628 	.setpower		= spitz_mci_setpower,
629 };
630 
631 static struct gpiod_lookup_table spitz_mci_gpio_table = {
632 	.dev_id = "pxa2xx-mci.0",
633 	.table = {
634 		GPIO_LOOKUP("gpio-pxa", SPITZ_GPIO_nSD_DETECT,
635 			    "cd", GPIO_ACTIVE_LOW),
636 		GPIO_LOOKUP("gpio-pxa", SPITZ_GPIO_nSD_WP,
637 			    "wp", GPIO_ACTIVE_LOW),
638 		{ },
639 	},
640 };
641 
642 static void __init spitz_mmc_init(void)
643 {
644 	gpiod_add_lookup_table(&spitz_mci_gpio_table);
645 	pxa_set_mci_info(&spitz_mci_platform_data);
646 }
647 #else
648 static inline void spitz_mmc_init(void) {}
649 #endif
650 
651 /******************************************************************************
652  * USB Host
653  ******************************************************************************/
654 #if defined(CONFIG_USB_OHCI_HCD) || defined(CONFIG_USB_OHCI_HCD_MODULE)
655 static int spitz_ohci_init(struct device *dev)
656 {
657 	int err;
658 
659 	err = gpio_request(SPITZ_GPIO_USB_HOST, "USB_HOST");
660 	if (err)
661 		return err;
662 
663 	/* Only Port 2 is connected, setup USB Port 2 Output Control Register */
664 	UP2OCR = UP2OCR_HXS | UP2OCR_HXOE | UP2OCR_DPPDE | UP2OCR_DMPDE;
665 
666 	return gpio_direction_output(SPITZ_GPIO_USB_HOST, 1);
667 }
668 
669 static void spitz_ohci_exit(struct device *dev)
670 {
671 	gpio_free(SPITZ_GPIO_USB_HOST);
672 }
673 
674 static struct pxaohci_platform_data spitz_ohci_platform_data = {
675 	.port_mode	= PMM_NPS_MODE,
676 	.init		= spitz_ohci_init,
677 	.exit		= spitz_ohci_exit,
678 	.flags		= ENABLE_PORT_ALL | NO_OC_PROTECTION,
679 	.power_budget	= 150,
680 };
681 
682 static void __init spitz_uhc_init(void)
683 {
684 	pxa_set_ohci_info(&spitz_ohci_platform_data);
685 }
686 #else
687 static inline void spitz_uhc_init(void) {}
688 #endif
689 
690 /******************************************************************************
691  * Framebuffer
692  ******************************************************************************/
693 #if defined(CONFIG_FB_PXA) || defined(CONFIG_FB_PXA_MODULE)
694 static struct pxafb_mode_info spitz_pxafb_modes[] = {
695 	{
696 		.pixclock       = 19231,
697 		.xres           = 480,
698 		.yres           = 640,
699 		.bpp            = 16,
700 		.hsync_len      = 40,
701 		.left_margin    = 46,
702 		.right_margin   = 125,
703 		.vsync_len      = 3,
704 		.upper_margin   = 1,
705 		.lower_margin   = 0,
706 		.sync           = 0,
707 	}, {
708 		.pixclock       = 134617,
709 		.xres           = 240,
710 		.yres           = 320,
711 		.bpp            = 16,
712 		.hsync_len      = 20,
713 		.left_margin    = 20,
714 		.right_margin   = 46,
715 		.vsync_len      = 2,
716 		.upper_margin   = 1,
717 		.lower_margin   = 0,
718 		.sync           = 0,
719 	},
720 };
721 
722 static struct pxafb_mach_info spitz_pxafb_info = {
723 	.modes          = spitz_pxafb_modes,
724 	.num_modes      = ARRAY_SIZE(spitz_pxafb_modes),
725 	.fixed_modes    = 1,
726 	.lcd_conn	= LCD_COLOR_TFT_16BPP | LCD_ALTERNATE_MAPPING,
727 };
728 
729 static void __init spitz_lcd_init(void)
730 {
731 	pxa_set_fb_info(NULL, &spitz_pxafb_info);
732 }
733 #else
734 static inline void spitz_lcd_init(void) {}
735 #endif
736 
737 /******************************************************************************
738  * NAND Flash
739  ******************************************************************************/
740 #if defined(CONFIG_MTD_NAND_SHARPSL) || defined(CONFIG_MTD_NAND_SHARPSL_MODULE)
741 static uint8_t scan_ff_pattern[] = { 0xff, 0xff };
742 
743 static struct nand_bbt_descr spitz_nand_bbt = {
744 	.options	= 0,
745 	.offs		= 4,
746 	.len		= 2,
747 	.pattern	= scan_ff_pattern
748 };
749 
750 static int akita_ooblayout_ecc(struct mtd_info *mtd, int section,
751 			       struct mtd_oob_region *oobregion)
752 {
753 	if (section > 12)
754 		return -ERANGE;
755 
756 	switch (section % 3) {
757 	case 0:
758 		oobregion->offset = 5;
759 		oobregion->length = 1;
760 		break;
761 
762 	case 1:
763 		oobregion->offset = 1;
764 		oobregion->length = 3;
765 		break;
766 
767 	case 2:
768 		oobregion->offset = 6;
769 		oobregion->length = 2;
770 		break;
771 	}
772 
773 	oobregion->offset += (section / 3) * 0x10;
774 
775 	return 0;
776 }
777 
778 static int akita_ooblayout_free(struct mtd_info *mtd, int section,
779 				struct mtd_oob_region *oobregion)
780 {
781 	if (section)
782 		return -ERANGE;
783 
784 	oobregion->offset = 8;
785 	oobregion->length = 9;
786 
787 	return 0;
788 }
789 
790 static const struct mtd_ooblayout_ops akita_ooblayout_ops = {
791 	.ecc = akita_ooblayout_ecc,
792 	.free = akita_ooblayout_free,
793 };
794 
795 static const char * const probes[] = {
796 	"cmdlinepart",
797 	"ofpart",
798 	"sharpslpart",
799 	NULL,
800 };
801 
802 static struct sharpsl_nand_platform_data spitz_nand_pdata = {
803 	.badblock_pattern	= &spitz_nand_bbt,
804 	.part_parsers		= probes,
805 };
806 
807 static struct resource spitz_nand_resources[] = {
808 	{
809 		.start	= PXA_CS3_PHYS,
810 		.end	= PXA_CS3_PHYS + SZ_4K - 1,
811 		.flags	= IORESOURCE_MEM,
812 	},
813 };
814 
815 static struct platform_device spitz_nand_device = {
816 	.name		= "sharpsl-nand",
817 	.id		= -1,
818 	.resource	= spitz_nand_resources,
819 	.num_resources	= ARRAY_SIZE(spitz_nand_resources),
820 	.dev		= {
821 		.platform_data	= &spitz_nand_pdata,
822 	}
823 };
824 
825 static void __init spitz_nand_init(void)
826 {
827 	if (machine_is_akita() || machine_is_borzoi()) {
828 		spitz_nand_bbt.len = 1;
829 		spitz_nand_pdata.ecc_layout = &akita_ooblayout_ops;
830 	}
831 
832 	platform_device_register(&spitz_nand_device);
833 }
834 #else
835 static inline void spitz_nand_init(void) {}
836 #endif
837 
838 /******************************************************************************
839  * NOR Flash
840  ******************************************************************************/
841 #if defined(CONFIG_MTD_PHYSMAP) || defined(CONFIG_MTD_PHYSMAP_MODULE)
842 static struct mtd_partition spitz_rom_parts[] = {
843 	{
844 		.name	="Boot PROM Filesystem",
845 		.offset	= 0x00140000,
846 		.size	= MTDPART_SIZ_FULL,
847 	},
848 };
849 
850 static struct physmap_flash_data spitz_rom_data = {
851 	.width		= 2,
852 	.nr_parts	= ARRAY_SIZE(spitz_rom_parts),
853 	.parts		= spitz_rom_parts,
854 };
855 
856 static struct resource spitz_rom_resources[] = {
857 	{
858 		.start	= PXA_CS0_PHYS,
859 		.end	= PXA_CS0_PHYS + SZ_8M - 1,
860 		.flags	= IORESOURCE_MEM,
861 	},
862 };
863 
864 static struct platform_device spitz_rom_device = {
865 	.name		= "physmap-flash",
866 	.id		= -1,
867 	.resource	= spitz_rom_resources,
868 	.num_resources	= ARRAY_SIZE(spitz_rom_resources),
869 	.dev		= {
870 		.platform_data	= &spitz_rom_data,
871 	},
872 };
873 
874 static void __init spitz_nor_init(void)
875 {
876 	platform_device_register(&spitz_rom_device);
877 }
878 #else
879 static inline void spitz_nor_init(void) {}
880 #endif
881 
882 /******************************************************************************
883  * I2C devices
884  ******************************************************************************/
885 #if defined(CONFIG_I2C_PXA) || defined(CONFIG_I2C_PXA_MODULE)
886 static struct pca953x_platform_data akita_pca953x_pdata = {
887 	.gpio_base		= AKITA_IOEXP_GPIO_BASE,
888 };
889 
890 static struct i2c_board_info spitz_i2c_devs[] = {
891 	{
892 		.type		= "wm8750",
893 		.addr		= 0x1b,
894 	}, {
895 		.type		= "max7310",
896 		.addr		= 0x18,
897 		.platform_data	= &akita_pca953x_pdata,
898 	},
899 };
900 
901 static struct regulator_consumer_supply isl6271a_consumers[] = {
902 	REGULATOR_SUPPLY("vcc_core", NULL),
903 };
904 
905 static struct regulator_init_data isl6271a_info[] = {
906 	{
907 		.constraints = {
908 			.name		= "vcc_core range",
909 			.min_uV		= 850000,
910 			.max_uV		= 1600000,
911 			.always_on	= 1,
912 			.valid_ops_mask	= REGULATOR_CHANGE_VOLTAGE,
913 		},
914 	.consumer_supplies	= isl6271a_consumers,
915 	.num_consumer_supplies	= ARRAY_SIZE(isl6271a_consumers),
916 	}
917 };
918 
919 static struct i2c_board_info spitz_pi2c_devs[] = {
920 	{
921 		.type		= "isl6271a",
922 		.addr		= 0x0c,
923 		.platform_data	= &isl6271a_info,
924 	},
925 };
926 
927 static void __init spitz_i2c_init(void)
928 {
929 	int size = ARRAY_SIZE(spitz_i2c_devs);
930 
931 	/* Only Akita has the max7310 chip */
932 	if (!machine_is_akita())
933 		size--;
934 
935 	pxa_set_i2c_info(NULL);
936 	pxa27x_set_i2c_power_info(NULL);
937 	i2c_register_board_info(0, spitz_i2c_devs, size);
938 	i2c_register_board_info(1, ARRAY_AND_SIZE(spitz_pi2c_devs));
939 }
940 #else
941 static inline void spitz_i2c_init(void) {}
942 #endif
943 
944 static struct gpiod_lookup_table spitz_audio_gpio_table = {
945 	.dev_id = "spitz-audio",
946 	.table = {
947 		GPIO_LOOKUP("sharp-scoop.0", SPITZ_GPIO_MUTE_L - SPITZ_SCP_GPIO_BASE,
948 			    "mute-l", GPIO_ACTIVE_HIGH),
949 		GPIO_LOOKUP("sharp-scoop.0", SPITZ_GPIO_MUTE_R - SPITZ_SCP_GPIO_BASE,
950 			    "mute-r", GPIO_ACTIVE_HIGH),
951 		GPIO_LOOKUP("sharp-scoop.1", SPITZ_GPIO_MIC_BIAS - SPITZ_SCP2_GPIO_BASE,
952 			    "mic", GPIO_ACTIVE_HIGH),
953 		{ },
954 	},
955 };
956 
957 static struct gpiod_lookup_table akita_audio_gpio_table = {
958 	.dev_id = "spitz-audio",
959 	.table = {
960 		GPIO_LOOKUP("sharp-scoop.0", SPITZ_GPIO_MUTE_L - SPITZ_SCP_GPIO_BASE,
961 			    "mute-l", GPIO_ACTIVE_HIGH),
962 		GPIO_LOOKUP("sharp-scoop.0", SPITZ_GPIO_MUTE_R - SPITZ_SCP_GPIO_BASE,
963 			    "mute-r", GPIO_ACTIVE_HIGH),
964 		GPIO_LOOKUP("i2c-max7310", AKITA_GPIO_MIC_BIAS - AKITA_IOEXP_GPIO_BASE,
965 			    "mic", GPIO_ACTIVE_HIGH),
966 		{ },
967 	},
968 };
969 
970 /******************************************************************************
971  * Audio devices
972  ******************************************************************************/
973 static inline void spitz_audio_init(void)
974 {
975 	if (machine_is_akita())
976 		gpiod_add_lookup_table(&akita_audio_gpio_table);
977 	else
978 		gpiod_add_lookup_table(&spitz_audio_gpio_table);
979 
980 	platform_device_register_simple("spitz-audio", -1, NULL, 0);
981 }
982 
983 /******************************************************************************
984  * Machine init
985  ******************************************************************************/
986 static void spitz_poweroff(void)
987 {
988 	pxa_restart(REBOOT_GPIO, NULL);
989 }
990 
991 static void spitz_restart(enum reboot_mode mode, const char *cmd)
992 {
993 	uint32_t msc0 = __raw_readl(MSC0);
994 	/* Bootloader magic for a reboot */
995 	if ((msc0 & 0xffff0000) == 0x7ff00000)
996 		__raw_writel((msc0 & 0xffff) | 0x7ee00000, MSC0);
997 
998 	spitz_poweroff();
999 }
1000 
1001 static void __init spitz_init(void)
1002 {
1003 	init_gpio_reset(SPITZ_GPIO_ON_RESET, 1, 0);
1004 	pm_power_off = spitz_poweroff;
1005 
1006 	PMCR = 0x00;
1007 
1008 	/* Stop 3.6MHz and drive HIGH to PCMCIA and CS */
1009 	PCFR |= PCFR_OPDE;
1010 
1011 	pxa2xx_mfp_config(ARRAY_AND_SIZE(spitz_pin_config));
1012 
1013 	pxa_set_ffuart_info(NULL);
1014 	pxa_set_btuart_info(NULL);
1015 	pxa_set_stuart_info(NULL);
1016 
1017 	spitz_spi_init();
1018 	spitz_scoop_init();
1019 	spitz_mkp_init();
1020 	spitz_keys_init();
1021 	spitz_leds_init();
1022 	spitz_mmc_init();
1023 	spitz_pcmcia_init();
1024 	spitz_uhc_init();
1025 	spitz_lcd_init();
1026 	spitz_nor_init();
1027 	spitz_nand_init();
1028 	spitz_i2c_init();
1029 	spitz_audio_init();
1030 
1031 	regulator_has_full_constraints();
1032 }
1033 
1034 static void __init spitz_fixup(struct tag *tags, char **cmdline)
1035 {
1036 	sharpsl_save_param();
1037 	memblock_add(0xa0000000, SZ_64M);
1038 }
1039 
1040 #ifdef CONFIG_MACH_SPITZ
1041 MACHINE_START(SPITZ, "SHARP Spitz")
1042 	.fixup		= spitz_fixup,
1043 	.map_io		= pxa27x_map_io,
1044 	.nr_irqs	= PXA_NR_IRQS,
1045 	.init_irq	= pxa27x_init_irq,
1046 	.handle_irq	= pxa27x_handle_irq,
1047 	.init_machine	= spitz_init,
1048 	.init_time	= pxa_timer_init,
1049 	.restart	= spitz_restart,
1050 MACHINE_END
1051 #endif
1052 
1053 #ifdef CONFIG_MACH_BORZOI
1054 MACHINE_START(BORZOI, "SHARP Borzoi")
1055 	.fixup		= spitz_fixup,
1056 	.map_io		= pxa27x_map_io,
1057 	.nr_irqs	= PXA_NR_IRQS,
1058 	.init_irq	= pxa27x_init_irq,
1059 	.handle_irq	= pxa27x_handle_irq,
1060 	.init_machine	= spitz_init,
1061 	.init_time	= pxa_timer_init,
1062 	.restart	= spitz_restart,
1063 MACHINE_END
1064 #endif
1065 
1066 #ifdef CONFIG_MACH_AKITA
1067 MACHINE_START(AKITA, "SHARP Akita")
1068 	.fixup		= spitz_fixup,
1069 	.map_io		= pxa27x_map_io,
1070 	.nr_irqs	= PXA_NR_IRQS,
1071 	.init_irq	= pxa27x_init_irq,
1072 	.handle_irq	= pxa27x_handle_irq,
1073 	.init_machine	= spitz_init,
1074 	.init_time	= pxa_timer_init,
1075 	.restart	= spitz_restart,
1076 MACHINE_END
1077 #endif
1078