1 // SPDX-License-Identifier: GPL-2.0
5 * Copyright (C) 2008 Rod Whitby <rod@whitby.id.au>
6 * Copyright (C) 2006 Tower Technologies
8 * based on ixdp425-setup.c:
9 * Copyright (C) 2003-2004 MontaVista Software, Inc.
10 * based on nslu2-power.c:
11 * Copyright (C) 2005 Tower Technologies
12 * based on nslu2-io.c:
13 * Copyright (C) 2004 Karen Spearel
15 * Author: Alessandro Zummo <a.zummo@towertech.it>
16 * Author: Michael Westerhof <mwester@dls.net>
17 * Author: Rod Whitby <rod@whitby.id.au>
18 * Maintainers: http://www.nslu2-linux.org/
20 #include <linux/gpio.h>
21 #include <linux/irq.h>
22 #include <linux/jiffies.h>
23 #include <linux/timer.h>
24 #include <linux/serial.h>
25 #include <linux/serial_8250.h>
26 #include <linux/leds.h>
27 #include <linux/reboot.h>
28 #include <linux/i2c.h>
29 #include <linux/gpio/machine.h>
31 #include <mach/hardware.h>
33 #include <asm/mach-types.h>
34 #include <asm/mach/arch.h>
35 #include <asm/mach/flash.h>
36 #include <asm/mach/time.h>
38 #define DSMG600_SDA_PIN 5
39 #define DSMG600_SCL_PIN 4
41 /* DSM-G600 Timer Setting */
42 #define DSMG600_FREQ 66000000
45 #define DSMG600_PB_GPIO 15 /* power button */
46 #define DSMG600_RB_GPIO 3 /* reset button */
49 #define DSMG600_PO_GPIO 2 /* power off */
52 #define DSMG600_LED_PWR_GPIO 0
53 #define DSMG600_LED_WLAN_GPIO 14
55 static struct flash_platform_data dsmg600_flash_data
= {
56 .map_name
= "cfi_probe",
60 static struct resource dsmg600_flash_resource
= {
61 .flags
= IORESOURCE_MEM
,
64 static struct platform_device dsmg600_flash
= {
65 .name
= "IXP4XX-Flash",
67 .dev
.platform_data
= &dsmg600_flash_data
,
69 .resource
= &dsmg600_flash_resource
,
72 static struct gpiod_lookup_table dsmg600_i2c_gpiod_table
= {
75 GPIO_LOOKUP_IDX("IXP4XX_GPIO_CHIP", DSMG600_SDA_PIN
,
76 NULL
, 0, GPIO_ACTIVE_HIGH
| GPIO_OPEN_DRAIN
),
77 GPIO_LOOKUP_IDX("IXP4XX_GPIO_CHIP", DSMG600_SCL_PIN
,
78 NULL
, 1, GPIO_ACTIVE_HIGH
| GPIO_OPEN_DRAIN
),
82 static struct platform_device dsmg600_i2c_gpio
= {
86 .platform_data
= NULL
,
90 static struct i2c_board_info __initdata dsmg600_i2c_board_info
[] = {
92 I2C_BOARD_INFO("pcf8563", 0x51),
96 static struct gpio_led dsmg600_led_pins
[] = {
98 .name
= "dsmg600:green:power",
99 .gpio
= DSMG600_LED_PWR_GPIO
,
102 .name
= "dsmg600:green:wlan",
103 .gpio
= DSMG600_LED_WLAN_GPIO
,
108 static struct gpio_led_platform_data dsmg600_led_data
= {
109 .num_leds
= ARRAY_SIZE(dsmg600_led_pins
),
110 .leds
= dsmg600_led_pins
,
113 static struct platform_device dsmg600_leds
= {
116 .dev
.platform_data
= &dsmg600_led_data
,
119 static struct resource dsmg600_uart_resources
[] = {
121 .start
= IXP4XX_UART1_BASE_PHYS
,
122 .end
= IXP4XX_UART1_BASE_PHYS
+ 0x0fff,
123 .flags
= IORESOURCE_MEM
,
126 .start
= IXP4XX_UART2_BASE_PHYS
,
127 .end
= IXP4XX_UART2_BASE_PHYS
+ 0x0fff,
128 .flags
= IORESOURCE_MEM
,
132 static struct plat_serial8250_port dsmg600_uart_data
[] = {
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
,
140 .uartclk
= IXP4XX_UART_XTAL
,
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
,
149 .uartclk
= IXP4XX_UART_XTAL
,
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
,
162 static struct platform_device
*dsmg600_devices
[] __initdata
= {
168 static void dsmg600_power_off(void)
170 /* enable the pwr cntl and drive it high */
171 gpio_direction_output(DSMG600_PO_GPIO
, 1);
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.
177 static int power_button_countdown
;
179 /* Must hold the button down for at least this many counts to be processed */
180 #define PBUTTON_HOLDDOWN_COUNT 4 /* 2 secs */
182 static void dsmg600_power_handler(struct timer_list
*unused
);
183 static DEFINE_TIMER(dsmg600_power_timer
, dsmg600_power_handler
);
185 static void dsmg600_power_handler(struct timer_list
*unused
)
187 /* This routine is called twice per second to check the
188 * state of the power button.
191 if (gpio_get_value(DSMG600_PB_GPIO
)) {
193 /* IO Pin is 1 (button pushed) */
194 if (power_button_countdown
> 0)
195 power_button_countdown
--;
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.
207 /* Change the state of the power LED to "blink" */
208 gpio_set_value(DSMG600_LED_PWR_GPIO
, 0);
210 power_button_countdown
= PBUTTON_HOLDDOWN_COUNT
;
214 mod_timer(&dsmg600_power_timer
, jiffies
+ msecs_to_jiffies(500));
217 static irqreturn_t
dsmg600_reset_handler(int irq
, void *dev_id
)
219 /* This is the paper-clip reset, it shuts the machine down directly. */
225 static void __init
dsmg600_timer_init(void)
227 /* The xtal on this machine is non-standard. */
228 ixp4xx_timer_freq
= DSMG600_FREQ
;
230 /* Call standard timer_init function. */
234 static int __init
dsmg600_gpio_init(void)
236 if (!machine_is_dsmg600())
239 gpio_request(DSMG600_RB_GPIO
, "reset button");
240 if (request_irq(gpio_to_irq(DSMG600_RB_GPIO
), &dsmg600_reset_handler
,
241 IRQF_TRIGGER_LOW
, "DSM-G600 reset button", NULL
) < 0) {
243 printk(KERN_DEBUG
"Reset Button IRQ %d not available\n",
244 gpio_to_irq(DSMG600_RB_GPIO
));
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.
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");
259 /* Set the initial value for the power button IRQ handler */
260 power_button_countdown
= PBUTTON_HOLDDOWN_COUNT
;
262 mod_timer(&dsmg600_power_timer
, jiffies
+ msecs_to_jiffies(500));
265 device_initcall(dsmg600_gpio_init
);
267 static void __init
dsmg600_init(void)
271 /* Make sure that GPIO14 and GPIO15 are not used as clocks */
272 *IXP4XX_GPIO_GPCLKR
= 0;
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;
278 gpiod_add_lookup_table(&dsmg600_i2c_gpiod_table
);
279 i2c_register_board_info(0, dsmg600_i2c_board_info
,
280 ARRAY_SIZE(dsmg600_i2c_board_info
));
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!
286 (void)platform_device_register(&dsmg600_uart
);
288 platform_add_devices(dsmg600_devices
, ARRAY_SIZE(dsmg600_devices
));
290 pm_power_off
= dsmg600_power_off
;
293 MACHINE_START(DSMG600
, "D-Link DSM-G600 RevA")
294 /* Maintainer: www.nslu2-linux.org */
295 .atag_offset
= 0x100,
296 .map_io
= ixp4xx_map_io
,
297 .init_early
= ixp4xx_init_early
,
298 .init_irq
= ixp4xx_init_irq
,
299 .init_time
= dsmg600_timer_init
,
300 .init_machine
= dsmg600_init
,
301 #if defined(CONFIG_PCI)
302 .dma_zone_size
= SZ_64M
,
304 .restart
= ixp4xx_restart
,