| Michael-Luke Jones | 28bd3a0 | 2007-04-28 08:31:40 +0100 | [diff] [blame] | 1 | /* | 
 | 2 |  * DSM-G600 board-setup | 
 | 3 |  * | 
| Rod Whitby | 43816bc | 2008-02-03 12:05:55 +0100 | [diff] [blame] | 4 |  * Copyright (C) 2008 Rod Whitby <rod@whitby.id.au> | 
| Michael-Luke Jones | 28bd3a0 | 2007-04-28 08:31:40 +0100 | [diff] [blame] | 5 |  * Copyright (C) 2006 Tower Technologies | 
| Michael-Luke Jones | 28bd3a0 | 2007-04-28 08:31:40 +0100 | [diff] [blame] | 6 |  * | 
| Rod Whitby | 43816bc | 2008-02-03 12:05:55 +0100 | [diff] [blame] | 7 |  * based on ixdp425-setup.c: | 
| Michael-Luke Jones | 28bd3a0 | 2007-04-28 08:31:40 +0100 | [diff] [blame] | 8 |  *      Copyright (C) 2003-2004 MontaVista Software, Inc. | 
| Rod Whitby | 43816bc | 2008-02-03 12:05:55 +0100 | [diff] [blame] | 9 |  * based on nslu2-power.c: | 
 | 10 |  *	Copyright (C) 2005 Tower Technologies | 
 | 11 |  * based on nslu2-io.c: | 
 | 12 |  *	Copyright (C) 2004 Karen Spearel | 
| Michael-Luke Jones | 28bd3a0 | 2007-04-28 08:31:40 +0100 | [diff] [blame] | 13 |  * | 
 | 14 |  * Author: Alessandro Zummo <a.zummo@towertech.it> | 
| Rod Whitby | 43816bc | 2008-02-03 12:05:55 +0100 | [diff] [blame] | 15 |  * Author: Michael Westerhof <mwester@dls.net> | 
 | 16 |  * Author: Rod Whitby <rod@whitby.id.au> | 
| Michael-Luke Jones | 28bd3a0 | 2007-04-28 08:31:40 +0100 | [diff] [blame] | 17 |  * Maintainers: http://www.nslu2-linux.org/ | 
 | 18 |  */ | 
| Russell King | 2f8163b | 2011-07-26 10:53:52 +0100 | [diff] [blame] | 19 | #include <linux/gpio.h> | 
| Rod Whitby | 43816bc | 2008-02-03 12:05:55 +0100 | [diff] [blame] | 20 | #include <linux/irq.h> | 
 | 21 | #include <linux/jiffies.h> | 
 | 22 | #include <linux/timer.h> | 
| Michael-Luke Jones | 28bd3a0 | 2007-04-28 08:31:40 +0100 | [diff] [blame] | 23 | #include <linux/serial.h> | 
 | 24 | #include <linux/serial_8250.h> | 
| Rod Whitby | 1208ebf | 2008-02-02 00:03:56 +0100 | [diff] [blame] | 25 | #include <linux/leds.h> | 
| Rod Whitby | 43816bc | 2008-02-03 12:05:55 +0100 | [diff] [blame] | 26 | #include <linux/reboot.h> | 
| Rod Whitby | a9a424c | 2008-01-29 00:40:02 +0100 | [diff] [blame] | 27 | #include <linux/i2c.h> | 
| Michael-Luke Jones | 5a4a238 | 2008-01-27 18:14:46 +0100 | [diff] [blame] | 28 | #include <linux/i2c-gpio.h> | 
| Michael-Luke Jones | 28bd3a0 | 2007-04-28 08:31:40 +0100 | [diff] [blame] | 29 |  | 
 | 30 | #include <asm/mach-types.h> | 
 | 31 | #include <asm/mach/arch.h> | 
 | 32 | #include <asm/mach/flash.h> | 
| Michael-Luke Jones | 435c5da | 2007-05-23 22:38:45 +0100 | [diff] [blame] | 33 | #include <asm/mach/time.h> | 
| Michael-Luke Jones | 28bd3a0 | 2007-04-28 08:31:40 +0100 | [diff] [blame] | 34 |  | 
| Krzysztof HaĆasa | 395e712 | 2009-11-16 21:56:56 +0100 | [diff] [blame] | 35 | #define DSMG600_SDA_PIN		5 | 
 | 36 | #define DSMG600_SCL_PIN		4 | 
 | 37 |  | 
 | 38 | /* DSM-G600 Timer Setting */ | 
 | 39 | #define DSMG600_FREQ		66000000 | 
 | 40 |  | 
 | 41 | /* Buttons */ | 
 | 42 | #define DSMG600_PB_GPIO		15	/* power button */ | 
 | 43 | #define DSMG600_RB_GPIO		3	/* reset button */ | 
 | 44 |  | 
 | 45 | /* Power control */ | 
 | 46 | #define DSMG600_PO_GPIO		2	/* power off */ | 
 | 47 |  | 
 | 48 | /* LEDs */ | 
 | 49 | #define DSMG600_LED_PWR_GPIO	0 | 
 | 50 | #define DSMG600_LED_WLAN_GPIO	14 | 
 | 51 |  | 
| Michael-Luke Jones | 28bd3a0 | 2007-04-28 08:31:40 +0100 | [diff] [blame] | 52 | static struct flash_platform_data dsmg600_flash_data = { | 
 | 53 | 	.map_name		= "cfi_probe", | 
 | 54 | 	.width			= 2, | 
 | 55 | }; | 
 | 56 |  | 
 | 57 | static struct resource dsmg600_flash_resource = { | 
 | 58 | 	.flags			= IORESOURCE_MEM, | 
 | 59 | }; | 
 | 60 |  | 
 | 61 | static struct platform_device dsmg600_flash = { | 
 | 62 | 	.name			= "IXP4XX-Flash", | 
 | 63 | 	.id			= 0, | 
 | 64 | 	.dev.platform_data	= &dsmg600_flash_data, | 
 | 65 | 	.num_resources		= 1, | 
 | 66 | 	.resource		= &dsmg600_flash_resource, | 
 | 67 | }; | 
 | 68 |  | 
| Michael-Luke Jones | 5a4a238 | 2008-01-27 18:14:46 +0100 | [diff] [blame] | 69 | static struct i2c_gpio_platform_data dsmg600_i2c_gpio_data = { | 
| Michael-Luke Jones | 28bd3a0 | 2007-04-28 08:31:40 +0100 | [diff] [blame] | 70 | 	.sda_pin		= DSMG600_SDA_PIN, | 
 | 71 | 	.scl_pin		= DSMG600_SCL_PIN, | 
 | 72 | }; | 
 | 73 |  | 
| Michael-Luke Jones | 5a4a238 | 2008-01-27 18:14:46 +0100 | [diff] [blame] | 74 | static struct platform_device dsmg600_i2c_gpio = { | 
 | 75 | 	.name			= "i2c-gpio", | 
| Michael-Luke Jones | 28bd3a0 | 2007-04-28 08:31:40 +0100 | [diff] [blame] | 76 | 	.id			= 0, | 
| Michael-Luke Jones | 5a4a238 | 2008-01-27 18:14:46 +0100 | [diff] [blame] | 77 | 	.dev	 = { | 
 | 78 | 		.platform_data	= &dsmg600_i2c_gpio_data, | 
 | 79 | 	}, | 
| Michael-Luke Jones | 28bd3a0 | 2007-04-28 08:31:40 +0100 | [diff] [blame] | 80 | }; | 
 | 81 |  | 
| Rod Whitby | a9a424c | 2008-01-29 00:40:02 +0100 | [diff] [blame] | 82 | static struct i2c_board_info __initdata dsmg600_i2c_board_info [] = { | 
 | 83 | 	{ | 
| Jean Delvare | 3760f73 | 2008-04-29 23:11:40 +0200 | [diff] [blame] | 84 | 		I2C_BOARD_INFO("pcf8563", 0x51), | 
| Rod Whitby | a9a424c | 2008-01-29 00:40:02 +0100 | [diff] [blame] | 85 | 	}, | 
 | 86 | }; | 
 | 87 |  | 
| Rod Whitby | 1208ebf | 2008-02-02 00:03:56 +0100 | [diff] [blame] | 88 | static struct gpio_led dsmg600_led_pins[] = { | 
| Michael-Luke Jones | 28bd3a0 | 2007-04-28 08:31:40 +0100 | [diff] [blame] | 89 | 	{ | 
| Richard Purdie | 6c152be | 2007-10-31 15:00:07 +0100 | [diff] [blame] | 90 | 		.name		= "dsmg600:green:power", | 
| Rod Whitby | 1208ebf | 2008-02-02 00:03:56 +0100 | [diff] [blame] | 91 | 		.gpio		= DSMG600_LED_PWR_GPIO, | 
| Michael-Luke Jones | 28bd3a0 | 2007-04-28 08:31:40 +0100 | [diff] [blame] | 92 | 	}, | 
 | 93 | 	{ | 
| Richard Purdie | 6c152be | 2007-10-31 15:00:07 +0100 | [diff] [blame] | 94 | 		.name		= "dsmg600:green:wlan", | 
| Rod Whitby | 1208ebf | 2008-02-02 00:03:56 +0100 | [diff] [blame] | 95 | 		.gpio		= DSMG600_LED_WLAN_GPIO, | 
 | 96 | 		.active_low	= true, | 
| Michael-Luke Jones | 28bd3a0 | 2007-04-28 08:31:40 +0100 | [diff] [blame] | 97 | 	}, | 
 | 98 | }; | 
 | 99 |  | 
| Rod Whitby | 1208ebf | 2008-02-02 00:03:56 +0100 | [diff] [blame] | 100 | static struct gpio_led_platform_data dsmg600_led_data = { | 
 | 101 | 	.num_leds		= ARRAY_SIZE(dsmg600_led_pins), | 
 | 102 | 	.leds			= dsmg600_led_pins, | 
| Michael-Luke Jones | 28bd3a0 | 2007-04-28 08:31:40 +0100 | [diff] [blame] | 103 | }; | 
| Rod Whitby | 1208ebf | 2008-02-02 00:03:56 +0100 | [diff] [blame] | 104 |  | 
 | 105 | static struct platform_device dsmg600_leds = { | 
 | 106 | 	.name			= "leds-gpio", | 
 | 107 | 	.id			= -1, | 
 | 108 | 	.dev.platform_data	= &dsmg600_led_data, | 
 | 109 | }; | 
| Michael-Luke Jones | 28bd3a0 | 2007-04-28 08:31:40 +0100 | [diff] [blame] | 110 |  | 
 | 111 | static struct resource dsmg600_uart_resources[] = { | 
 | 112 | 	{ | 
 | 113 | 		.start		= IXP4XX_UART1_BASE_PHYS, | 
 | 114 | 		.end		= IXP4XX_UART1_BASE_PHYS + 0x0fff, | 
 | 115 | 		.flags		= IORESOURCE_MEM, | 
 | 116 | 	}, | 
 | 117 | 	{ | 
 | 118 | 		.start		= IXP4XX_UART2_BASE_PHYS, | 
 | 119 | 		.end		= IXP4XX_UART2_BASE_PHYS + 0x0fff, | 
 | 120 | 		.flags		= IORESOURCE_MEM, | 
 | 121 | 	} | 
 | 122 | }; | 
 | 123 |  | 
 | 124 | static struct plat_serial8250_port dsmg600_uart_data[] = { | 
 | 125 | 	{ | 
 | 126 | 		.mapbase	= IXP4XX_UART1_BASE_PHYS, | 
 | 127 | 		.membase	= (char *)IXP4XX_UART1_BASE_VIRT + REG_OFFSET, | 
 | 128 | 		.irq		= IRQ_IXP4XX_UART1, | 
 | 129 | 		.flags		= UPF_BOOT_AUTOCONF, | 
 | 130 | 		.iotype		= UPIO_MEM, | 
 | 131 | 		.regshift	= 2, | 
 | 132 | 		.uartclk	= IXP4XX_UART_XTAL, | 
 | 133 | 	}, | 
 | 134 | 	{ | 
 | 135 | 		.mapbase	= IXP4XX_UART2_BASE_PHYS, | 
 | 136 | 		.membase	= (char *)IXP4XX_UART2_BASE_VIRT + REG_OFFSET, | 
 | 137 | 		.irq		= IRQ_IXP4XX_UART2, | 
 | 138 | 		.flags		= UPF_BOOT_AUTOCONF, | 
 | 139 | 		.iotype		= UPIO_MEM, | 
 | 140 | 		.regshift	= 2, | 
 | 141 | 		.uartclk	= IXP4XX_UART_XTAL, | 
 | 142 | 	}, | 
 | 143 | 	{ } | 
 | 144 | }; | 
 | 145 |  | 
 | 146 | static struct platform_device dsmg600_uart = { | 
 | 147 | 	.name			= "serial8250", | 
 | 148 | 	.id			= PLAT8250_DEV_PLATFORM, | 
 | 149 | 	.dev.platform_data	= dsmg600_uart_data, | 
 | 150 | 	.num_resources		= ARRAY_SIZE(dsmg600_uart_resources), | 
 | 151 | 	.resource		= dsmg600_uart_resources, | 
 | 152 | }; | 
 | 153 |  | 
 | 154 | static struct platform_device *dsmg600_devices[] __initdata = { | 
| Michael-Luke Jones | 5a4a238 | 2008-01-27 18:14:46 +0100 | [diff] [blame] | 155 | 	&dsmg600_i2c_gpio, | 
| Michael-Luke Jones | 28bd3a0 | 2007-04-28 08:31:40 +0100 | [diff] [blame] | 156 | 	&dsmg600_flash, | 
| Rod Whitby | 1208ebf | 2008-02-02 00:03:56 +0100 | [diff] [blame] | 157 | 	&dsmg600_leds, | 
| Michael-Luke Jones | 28bd3a0 | 2007-04-28 08:31:40 +0100 | [diff] [blame] | 158 | }; | 
 | 159 |  | 
 | 160 | static void dsmg600_power_off(void) | 
 | 161 | { | 
 | 162 | 	/* enable the pwr cntl gpio */ | 
 | 163 | 	gpio_line_config(DSMG600_PO_GPIO, IXP4XX_GPIO_OUT); | 
 | 164 |  | 
 | 165 | 	/* poweroff */ | 
 | 166 | 	gpio_line_set(DSMG600_PO_GPIO, IXP4XX_GPIO_HIGH); | 
 | 167 | } | 
 | 168 |  | 
| Rod Whitby | 43816bc | 2008-02-03 12:05:55 +0100 | [diff] [blame] | 169 | /* This is used to make sure the power-button pusher is serious.  The button | 
 | 170 |  * must be held until the value of this counter reaches zero. | 
 | 171 |  */ | 
 | 172 | static int power_button_countdown; | 
 | 173 |  | 
 | 174 | /* Must hold the button down for at least this many counts to be processed */ | 
 | 175 | #define PBUTTON_HOLDDOWN_COUNT 4 /* 2 secs */ | 
 | 176 |  | 
 | 177 | static void dsmg600_power_handler(unsigned long data); | 
 | 178 | static DEFINE_TIMER(dsmg600_power_timer, dsmg600_power_handler, 0, 0); | 
 | 179 |  | 
 | 180 | static void dsmg600_power_handler(unsigned long data) | 
 | 181 | { | 
 | 182 | 	/* This routine is called twice per second to check the | 
 | 183 | 	 * state of the power button. | 
 | 184 | 	 */ | 
 | 185 |  | 
 | 186 | 	if (gpio_get_value(DSMG600_PB_GPIO)) { | 
 | 187 |  | 
 | 188 | 		/* IO Pin is 1 (button pushed) */ | 
 | 189 | 		if (power_button_countdown > 0) | 
 | 190 | 			power_button_countdown--; | 
 | 191 |  | 
 | 192 | 	} else { | 
 | 193 |  | 
 | 194 | 		/* Done on button release, to allow for auto-power-on mods. */ | 
 | 195 | 		if (power_button_countdown == 0) { | 
 | 196 | 			/* Signal init to do the ctrlaltdel action, | 
 | 197 | 			 * this will bypass init if it hasn't started | 
 | 198 | 			 * and do a kernel_restart. | 
 | 199 | 			 */ | 
 | 200 | 			ctrl_alt_del(); | 
 | 201 |  | 
 | 202 | 			/* Change the state of the power LED to "blink" */ | 
 | 203 | 			gpio_line_set(DSMG600_LED_PWR_GPIO, IXP4XX_GPIO_LOW); | 
 | 204 | 		} else { | 
 | 205 | 			power_button_countdown = PBUTTON_HOLDDOWN_COUNT; | 
 | 206 | 		} | 
 | 207 | 	} | 
 | 208 |  | 
 | 209 | 	mod_timer(&dsmg600_power_timer, jiffies + msecs_to_jiffies(500)); | 
 | 210 | } | 
 | 211 |  | 
 | 212 | static irqreturn_t dsmg600_reset_handler(int irq, void *dev_id) | 
 | 213 | { | 
 | 214 | 	/* This is the paper-clip reset, it shuts the machine down directly. */ | 
 | 215 | 	machine_power_off(); | 
 | 216 |  | 
 | 217 | 	return IRQ_HANDLED; | 
 | 218 | } | 
 | 219 |  | 
| Michael-Luke Jones | 435c5da | 2007-05-23 22:38:45 +0100 | [diff] [blame] | 220 | static void __init dsmg600_timer_init(void) | 
 | 221 | { | 
 | 222 |     /* The xtal on this machine is non-standard. */ | 
 | 223 |     ixp4xx_timer_freq = DSMG600_FREQ; | 
 | 224 |  | 
 | 225 |     /* Call standard timer_init function. */ | 
 | 226 |     ixp4xx_timer_init(); | 
 | 227 | } | 
 | 228 |  | 
 | 229 | static struct sys_timer dsmg600_timer = { | 
 | 230 |     .init   = dsmg600_timer_init, | 
 | 231 | }; | 
 | 232 |  | 
| Michael-Luke Jones | 28bd3a0 | 2007-04-28 08:31:40 +0100 | [diff] [blame] | 233 | static void __init dsmg600_init(void) | 
 | 234 | { | 
 | 235 | 	ixp4xx_sys_init(); | 
 | 236 |  | 
 | 237 | 	/* Make sure that GPIO14 and GPIO15 are not used as clocks */ | 
 | 238 | 	*IXP4XX_GPIO_GPCLKR = 0; | 
 | 239 |  | 
 | 240 | 	dsmg600_flash_resource.start = IXP4XX_EXP_BUS_BASE(0); | 
 | 241 | 	dsmg600_flash_resource.end = | 
 | 242 | 		IXP4XX_EXP_BUS_BASE(0) + ixp4xx_exp_bus_size - 1; | 
 | 243 |  | 
| Rod Whitby | a9a424c | 2008-01-29 00:40:02 +0100 | [diff] [blame] | 244 | 	i2c_register_board_info(0, dsmg600_i2c_board_info, | 
 | 245 | 				ARRAY_SIZE(dsmg600_i2c_board_info)); | 
 | 246 |  | 
| Michael-Luke Jones | 28bd3a0 | 2007-04-28 08:31:40 +0100 | [diff] [blame] | 247 | 	/* The UART is required on the DSM-G600 (Redboot cannot use the | 
 | 248 | 	 * NIC) -- do it here so that it does *not* get removed if | 
 | 249 | 	 * platform_add_devices fails! | 
 | 250 |          */ | 
 | 251 |         (void)platform_device_register(&dsmg600_uart); | 
 | 252 |  | 
 | 253 | 	platform_add_devices(dsmg600_devices, ARRAY_SIZE(dsmg600_devices)); | 
| Rod Whitby | 43816bc | 2008-02-03 12:05:55 +0100 | [diff] [blame] | 254 |  | 
 | 255 | 	pm_power_off = dsmg600_power_off; | 
 | 256 |  | 
 | 257 | 	if (request_irq(gpio_to_irq(DSMG600_RB_GPIO), &dsmg600_reset_handler, | 
 | 258 | 		IRQF_DISABLED | IRQF_TRIGGER_LOW, | 
 | 259 | 		"DSM-G600 reset button", NULL) < 0) { | 
 | 260 |  | 
 | 261 | 		printk(KERN_DEBUG "Reset Button IRQ %d not available\n", | 
 | 262 | 			gpio_to_irq(DSMG600_RB_GPIO)); | 
 | 263 | 	} | 
 | 264 |  | 
 | 265 | 	/* The power button on the D-Link DSM-G600 is on GPIO 15, but | 
 | 266 | 	 * it cannot handle interrupts on that GPIO line.  So we'll | 
 | 267 | 	 * have to poll it with a kernel timer. | 
 | 268 | 	 */ | 
 | 269 |  | 
 | 270 | 	/* Make sure that the power button GPIO is set up as an input */ | 
 | 271 | 	gpio_line_config(DSMG600_PB_GPIO, IXP4XX_GPIO_IN); | 
 | 272 |  | 
 | 273 | 	/* Set the initial value for the power button IRQ handler */ | 
 | 274 | 	power_button_countdown = PBUTTON_HOLDDOWN_COUNT; | 
 | 275 |  | 
 | 276 | 	mod_timer(&dsmg600_power_timer, jiffies + msecs_to_jiffies(500)); | 
| Michael-Luke Jones | 28bd3a0 | 2007-04-28 08:31:40 +0100 | [diff] [blame] | 277 | } | 
 | 278 |  | 
| Michael-Luke Jones | 28bd3a0 | 2007-04-28 08:31:40 +0100 | [diff] [blame] | 279 | MACHINE_START(DSMG600, "D-Link DSM-G600 RevA") | 
 | 280 | 	/* Maintainer: www.nslu2-linux.org */ | 
| Nicolas Pitre | e022c72 | 2011-07-05 22:38:13 -0400 | [diff] [blame] | 281 | 	.atag_offset	= 0x100, | 
| Michael-Luke Jones | 28bd3a0 | 2007-04-28 08:31:40 +0100 | [diff] [blame] | 282 | 	.map_io		= ixp4xx_map_io, | 
| Rob Herring | f449588 | 2012-03-06 15:01:53 -0600 | [diff] [blame] | 283 | 	.init_early	= ixp4xx_init_early, | 
| Michael-Luke Jones | 28bd3a0 | 2007-04-28 08:31:40 +0100 | [diff] [blame] | 284 | 	.init_irq	= ixp4xx_init_irq, | 
| Michael-Luke Jones | 435c5da | 2007-05-23 22:38:45 +0100 | [diff] [blame] | 285 | 	.timer          = &dsmg600_timer, | 
| Michael-Luke Jones | 28bd3a0 | 2007-04-28 08:31:40 +0100 | [diff] [blame] | 286 | 	.init_machine	= dsmg600_init, | 
| Nicolas Pitre | 7553ee7 | 2011-07-05 22:28:09 -0400 | [diff] [blame] | 287 | #if defined(CONFIG_PCI) | 
 | 288 | 	.dma_zone_size	= SZ_64M, | 
 | 289 | #endif | 
| Russell King | d1b860f | 2011-11-05 12:10:55 +0000 | [diff] [blame] | 290 | 	.restart	= ixp4xx_restart, | 
| Michael-Luke Jones | 28bd3a0 | 2007-04-28 08:31:40 +0100 | [diff] [blame] | 291 | MACHINE_END |