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