1/*
2 * linux/arch/arm/mach-sa1100/collie.c
3 *
4 * May be copied or modified under the terms of the GNU General Public
5 * License.  See linux/COPYING for more information.
6 *
7 * This file contains all Collie-specific tweaks.
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License version 2 as
11 * published by the Free Software Foundation.
12 *
13 * ChangeLog:
14 *  2006 Pavel Machek <pavel@ucw.cz>
15 *  03-06-2004 John Lenz <lenz@cs.wisc.edu>
16 *  06-04-2002 Chris Larson <kergoth@digitalnemesis.net>
17 *  04-16-2001 Lineo Japan,Inc. ...
18 */
19
20#include <linux/init.h>
21#include <linux/kernel.h>
22#include <linux/tty.h>
23#include <linux/delay.h>
24#include <linux/platform_data/sa11x0-serial.h>
25#include <linux/platform_device.h>
26#include <linux/mfd/ucb1x00.h>
27#include <linux/mtd/mtd.h>
28#include <linux/mtd/partitions.h>
29#include <linux/timer.h>
30#include <linux/gpio_keys.h>
31#include <linux/input.h>
32#include <linux/gpio.h>
33#include <linux/gpio/machine.h>
34#include <linux/power/gpio-charger.h>
35
36#include <video/sa1100fb.h>
37
38#include <mach/hardware.h>
39#include <asm/mach-types.h>
40#include <asm/page.h>
41#include <asm/setup.h>
42#include <mach/collie.h>
43
44#include <asm/mach/arch.h>
45#include <asm/mach/flash.h>
46#include <asm/mach/map.h>
47#include <linux/platform_data/irda-sa11x0.h>
48
49#include <asm/hardware/scoop.h>
50#include <asm/mach/sharpsl_param.h>
51#include <asm/hardware/locomo.h>
52#include <linux/platform_data/mfd-mcp-sa11x0.h>
53#include <mach/irqs.h>
54
55#include "generic.h"
56
57static struct resource collie_scoop_resources[] = {
58	[0] = DEFINE_RES_MEM(0x40800000, SZ_4K),
59};
60
61static struct scoop_config collie_scoop_setup = {
62	.io_dir 	= COLLIE_SCOOP_IO_DIR,
63	.io_out		= COLLIE_SCOOP_IO_OUT,
64	.gpio_base	= COLLIE_SCOOP_GPIO_BASE,
65};
66
67struct platform_device colliescoop_device = {
68	.name		= "sharp-scoop",
69	.id		= -1,
70	.dev		= {
71 		.platform_data	= &collie_scoop_setup,
72	},
73	.num_resources	= ARRAY_SIZE(collie_scoop_resources),
74	.resource	= collie_scoop_resources,
75};
76
77static struct scoop_pcmcia_dev collie_pcmcia_scoop[] = {
78	{
79	.dev		= &colliescoop_device.dev,
80	.irq		= COLLIE_IRQ_GPIO_CF_IRQ,
81	.cd_irq		= COLLIE_IRQ_GPIO_CF_CD,
82	.cd_irq_str	= "PCMCIA0 CD",
83	},
84};
85
86static struct scoop_pcmcia_config collie_pcmcia_config = {
87	.devs		= &collie_pcmcia_scoop[0],
88	.num_devs	= 1,
89};
90
91static struct ucb1x00_plat_data collie_ucb1x00_data = {
92	.gpio_base	= COLLIE_TC35143_GPIO_BASE,
93};
94
95static struct mcp_plat_data collie_mcp_data = {
96	.mccr0		= MCCR0_ADM | MCCR0_ExtClk,
97	.sclk_rate	= 9216000,
98	.codec_pdata	= &collie_ucb1x00_data,
99};
100
101static int collie_ir_startup(struct device *dev)
102{
103	int rc = gpio_request(COLLIE_GPIO_IR_ON, "IrDA");
104	if (rc)
105		return rc;
106	rc = gpio_direction_output(COLLIE_GPIO_IR_ON, 1);
107
108	if (!rc)
109		return 0;
110
111	gpio_free(COLLIE_GPIO_IR_ON);
112	return rc;
113}
114
115static void collie_ir_shutdown(struct device *dev)
116{
117	gpio_free(COLLIE_GPIO_IR_ON);
118}
119
120static int collie_ir_set_power(struct device *dev, unsigned int state)
121{
122	gpio_set_value(COLLIE_GPIO_IR_ON, !state);
123	return 0;
124}
125
126static struct irda_platform_data collie_ir_data = {
127	.startup = collie_ir_startup,
128	.shutdown = collie_ir_shutdown,
129	.set_power = collie_ir_set_power,
130};
131
132/*
133 * Collie AC IN
134 */
135static struct gpiod_lookup_table collie_power_gpiod_table = {
136	.dev_id = "gpio-charger",
137	.table = {
138		GPIO_LOOKUP("gpio", COLLIE_GPIO_AC_IN,
139			    NULL, GPIO_ACTIVE_HIGH),
140		{ },
141	},
142};
143
144static char *collie_ac_supplied_to[] = {
145	"main-battery",
146	"backup-battery",
147};
148
149static struct gpio_charger_platform_data collie_power_data = {
150	.name			= "charger",
151	.type			= POWER_SUPPLY_TYPE_MAINS,
152	.supplied_to		= collie_ac_supplied_to,
153	.num_supplicants	= ARRAY_SIZE(collie_ac_supplied_to),
154};
155
156static struct platform_device collie_power_device = {
157	.name			= "gpio-charger",
158	.id			= -1,
159	.dev.platform_data	= &collie_power_data,
160};
161
162#ifdef CONFIG_SHARP_LOCOMO
163/*
164 * low-level UART features.
165 */
166struct platform_device collie_locomo_device;
167
168static void collie_uart_set_mctrl(struct uart_port *port, u_int mctrl)
169{
170	if (mctrl & TIOCM_RTS)
171		locomo_gpio_write(&collie_locomo_device.dev, LOCOMO_GPIO_RTS, 0);
172	else
173		locomo_gpio_write(&collie_locomo_device.dev, LOCOMO_GPIO_RTS, 1);
174
175	if (mctrl & TIOCM_DTR)
176		locomo_gpio_write(&collie_locomo_device.dev, LOCOMO_GPIO_DTR, 0);
177	else
178		locomo_gpio_write(&collie_locomo_device.dev, LOCOMO_GPIO_DTR, 1);
179}
180
181static u_int collie_uart_get_mctrl(struct uart_port *port)
182{
183	int ret = TIOCM_CD;
184	unsigned int r;
185
186	r = locomo_gpio_read_output(&collie_locomo_device.dev, LOCOMO_GPIO_CTS & LOCOMO_GPIO_DSR);
187	if (r == -ENODEV)
188		return ret;
189	if (r & LOCOMO_GPIO_CTS)
190		ret |= TIOCM_CTS;
191	if (r & LOCOMO_GPIO_DSR)
192		ret |= TIOCM_DSR;
193
194	return ret;
195}
196
197static struct sa1100_port_fns collie_port_fns __initdata = {
198	.set_mctrl	= collie_uart_set_mctrl,
199	.get_mctrl	= collie_uart_get_mctrl,
200};
201
202static int collie_uart_probe(struct locomo_dev *dev)
203{
204	return 0;
205}
206
207static int collie_uart_remove(struct locomo_dev *dev)
208{
209	return 0;
210}
211
212static struct locomo_driver collie_uart_driver = {
213	.drv = {
214		.name = "collie_uart",
215	},
216	.devid	= LOCOMO_DEVID_UART,
217	.probe	= collie_uart_probe,
218	.remove	= collie_uart_remove,
219};
220
221static int __init collie_uart_init(void)
222{
223	return locomo_driver_register(&collie_uart_driver);
224}
225device_initcall(collie_uart_init);
226
227#endif
228
229
230static struct resource locomo_resources[] = {
231	[0] = DEFINE_RES_MEM(0x40000000, SZ_8K),
232	[1] = DEFINE_RES_IRQ(IRQ_GPIO25),
233};
234
235static struct locomo_platform_data locomo_info = {
236	.irq_base	= IRQ_BOARD_START,
237};
238
239struct platform_device collie_locomo_device = {
240	.name		= "locomo",
241	.id		= 0,
242	.dev		= {
243		.platform_data	= &locomo_info,
244	},
245	.num_resources	= ARRAY_SIZE(locomo_resources),
246	.resource	= locomo_resources,
247};
248
249static struct gpio_keys_button collie_gpio_keys[] = {
250	{
251		.type	= EV_PWR,
252		.code	= KEY_RESERVED,
253		.gpio	= COLLIE_GPIO_ON_KEY,
254		.desc	= "On key",
255		.wakeup	= 1,
256		.active_low = 1,
257	},
258	{
259		.type	= EV_PWR,
260		.code	= KEY_WAKEUP,
261		.gpio	= COLLIE_GPIO_WAKEUP,
262		.desc	= "Sync",
263		.wakeup = 1,
264		.active_low = 1,
265	},
266};
267
268static struct gpio_keys_platform_data collie_gpio_keys_data = {
269	.buttons	= collie_gpio_keys,
270	.nbuttons	= ARRAY_SIZE(collie_gpio_keys),
271};
272
273static struct platform_device collie_gpio_keys_device = {
274	.name	= "gpio-keys",
275	.id	= -1,
276	.dev	= {
277		.platform_data = &collie_gpio_keys_data,
278	},
279};
280
281static struct platform_device *devices[] __initdata = {
282	&collie_locomo_device,
283	&colliescoop_device,
284	&collie_power_device,
285	&collie_gpio_keys_device,
286};
287
288static struct mtd_partition collie_partitions[] = {
289	{
290		.name		= "bootloader",
291		.offset 	= 0,
292		.size		= 0x000C0000,
293		.mask_flags	= MTD_WRITEABLE
294	}, {
295		.name		= "kernel",
296		.offset 	= MTDPART_OFS_APPEND,
297		.size		= 0x00100000,
298	}, {
299		.name		= "rootfs",
300		.offset 	= MTDPART_OFS_APPEND,
301		.size		= 0x00e20000,
302	}, {
303		.name		= "bootblock",
304		.offset		= MTDPART_OFS_APPEND,
305		.size		= 0x00020000,
306		.mask_flags	= MTD_WRITEABLE
307	}
308};
309
310static int collie_flash_init(void)
311{
312	int rc = gpio_request(COLLIE_GPIO_VPEN, "flash Vpp enable");
313	if (rc)
314		return rc;
315
316	rc = gpio_direction_output(COLLIE_GPIO_VPEN, 1);
317	if (rc)
318		gpio_free(COLLIE_GPIO_VPEN);
319
320	return rc;
321}
322
323static void collie_set_vpp(int vpp)
324{
325	gpio_set_value(COLLIE_GPIO_VPEN, vpp);
326}
327
328static void collie_flash_exit(void)
329{
330	gpio_free(COLLIE_GPIO_VPEN);
331}
332
333static struct flash_platform_data collie_flash_data = {
334	.map_name	= "cfi_probe",
335	.init		= collie_flash_init,
336	.set_vpp	= collie_set_vpp,
337	.exit		= collie_flash_exit,
338	.parts		= collie_partitions,
339	.nr_parts	= ARRAY_SIZE(collie_partitions),
340};
341
342static struct resource collie_flash_resources[] = {
343	DEFINE_RES_MEM(SA1100_CS0_PHYS, SZ_32M),
344};
345
346static struct sa1100fb_mach_info collie_lcd_info = {
347	.pixclock	= 171521,	.bpp		= 16,
348	.xres		= 320,		.yres		= 240,
349
350	.hsync_len	= 5,		.vsync_len	= 1,
351	.left_margin	= 11,		.upper_margin	= 2,
352	.right_margin	= 30,		.lower_margin	= 0,
353
354	.sync		= FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
355
356	.lccr0		= LCCR0_Color | LCCR0_Sngl | LCCR0_Act,
357	.lccr3		= LCCR3_OutEnH | LCCR3_PixRsEdg | LCCR3_ACBsDiv(2),
358
359#ifdef CONFIG_BACKLIGHT_LOCOMO
360	.lcd_power	= locomolcd_power
361#endif
362};
363
364static void __init collie_init(void)
365{
366	int ret = 0;
367
368	/* cpu initialize */
369	GAFR = GPIO_SSP_TXD | GPIO_SSP_SCLK | GPIO_SSP_SFRM | GPIO_SSP_CLK |
370		GPIO_MCP_CLK | GPIO_32_768kHz;
371
372	GPDR = GPIO_LDD8 | GPIO_LDD9 | GPIO_LDD10 | GPIO_LDD11 | GPIO_LDD12 |
373		GPIO_LDD13 | GPIO_LDD14 | GPIO_LDD15 | GPIO_SSP_TXD |
374		GPIO_SSP_SCLK | GPIO_SSP_SFRM | GPIO_SDLC_SCLK |
375		_COLLIE_GPIO_UCB1x00_RESET | _COLLIE_GPIO_nMIC_ON |
376		_COLLIE_GPIO_nREMOCON_ON | GPIO_32_768kHz;
377
378	PPDR = PPC_LDD0 | PPC_LDD1 | PPC_LDD2 | PPC_LDD3 | PPC_LDD4 | PPC_LDD5 |
379		PPC_LDD6 | PPC_LDD7 | PPC_L_PCLK | PPC_L_LCLK | PPC_L_FCLK | PPC_L_BIAS |
380		PPC_TXD1 | PPC_TXD2 | PPC_TXD3 | PPC_TXD4 | PPC_SCLK | PPC_SFRM;
381
382	PWER = 0;
383
384	PGSR = _COLLIE_GPIO_nREMOCON_ON;
385
386	PSDR = PPC_RXD1 | PPC_RXD2 | PPC_RXD3 | PPC_RXD4;
387
388	PCFR = PCFR_OPDE;
389
390	GPSR |= _COLLIE_GPIO_UCB1x00_RESET;
391
392	sa11x0_ppc_configure_mcp();
393
394
395	platform_scoop_config = &collie_pcmcia_config;
396
397	gpiod_add_lookup_table(&collie_power_gpiod_table);
398
399	ret = platform_add_devices(devices, ARRAY_SIZE(devices));
400	if (ret) {
401		printk(KERN_WARNING "collie: Unable to register LoCoMo device\n");
402	}
403
404	sa11x0_register_lcd(&collie_lcd_info);
405	sa11x0_register_mtd(&collie_flash_data, collie_flash_resources,
406			    ARRAY_SIZE(collie_flash_resources));
407	sa11x0_register_mcp(&collie_mcp_data);
408	sa11x0_register_irda(&collie_ir_data);
409
410	sharpsl_save_param();
411}
412
413static struct map_desc collie_io_desc[] __initdata = {
414	{	/* 32M main flash (cs0) */
415		.virtual	= 0xe8000000,
416		.pfn		= __phys_to_pfn(0x00000000),
417		.length		= 0x02000000,
418		.type		= MT_DEVICE
419	}, {	/* 32M boot flash (cs1) */
420		.virtual	= 0xea000000,
421		.pfn		= __phys_to_pfn(0x08000000),
422		.length		= 0x02000000,
423		.type		= MT_DEVICE
424	}
425};
426
427static void __init collie_map_io(void)
428{
429	sa1100_map_io();
430	iotable_init(collie_io_desc, ARRAY_SIZE(collie_io_desc));
431
432#ifdef CONFIG_SHARP_LOCOMO
433	sa1100_register_uart_fns(&collie_port_fns);
434#endif
435	sa1100_register_uart(0, 3);
436	sa1100_register_uart(1, 1);
437}
438
439MACHINE_START(COLLIE, "Sharp-Collie")
440	.map_io		= collie_map_io,
441	.nr_irqs	= SA1100_NR_IRQS,
442	.init_irq	= sa1100_init_irq,
443	.init_time	= sa1100_timer_init,
444	.init_machine	= collie_init,
445	.init_late	= sa11x0_init_late,
446	.restart	= sa11x0_restart,
447MACHINE_END
448