1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19#include <linux/gpio.h>
20#include <linux/irq.h>
21#include <linux/jiffies.h>
22#include <linux/timer.h>
23#include <linux/serial.h>
24#include <linux/serial_8250.h>
25#include <linux/leds.h>
26#include <linux/reboot.h>
27#include <linux/i2c.h>
28#include <linux/i2c-gpio.h>
29
30#include <mach/hardware.h>
31
32#include <asm/mach-types.h>
33#include <asm/mach/arch.h>
34#include <asm/mach/flash.h>
35#include <asm/mach/time.h>
36
37#define DSMG600_SDA_PIN 5
38#define DSMG600_SCL_PIN 4
39
40
41#define DSMG600_FREQ 66000000
42
43
44#define DSMG600_PB_GPIO 15
45#define DSMG600_RB_GPIO 3
46
47
48#define DSMG600_PO_GPIO 2
49
50
51#define DSMG600_LED_PWR_GPIO 0
52#define DSMG600_LED_WLAN_GPIO 14
53
54static struct flash_platform_data dsmg600_flash_data = {
55 .map_name = "cfi_probe",
56 .width = 2,
57};
58
59static struct resource dsmg600_flash_resource = {
60 .flags = IORESOURCE_MEM,
61};
62
63static struct platform_device dsmg600_flash = {
64 .name = "IXP4XX-Flash",
65 .id = 0,
66 .dev.platform_data = &dsmg600_flash_data,
67 .num_resources = 1,
68 .resource = &dsmg600_flash_resource,
69};
70
71static struct i2c_gpio_platform_data dsmg600_i2c_gpio_data = {
72 .sda_pin = DSMG600_SDA_PIN,
73 .scl_pin = DSMG600_SCL_PIN,
74};
75
76static struct platform_device dsmg600_i2c_gpio = {
77 .name = "i2c-gpio",
78 .id = 0,
79 .dev = {
80 .platform_data = &dsmg600_i2c_gpio_data,
81 },
82};
83
84static struct i2c_board_info __initdata dsmg600_i2c_board_info [] = {
85 {
86 I2C_BOARD_INFO("pcf8563", 0x51),
87 },
88};
89
90static struct gpio_led dsmg600_led_pins[] = {
91 {
92 .name = "dsmg600:green:power",
93 .gpio = DSMG600_LED_PWR_GPIO,
94 },
95 {
96 .name = "dsmg600:green:wlan",
97 .gpio = DSMG600_LED_WLAN_GPIO,
98 .active_low = true,
99 },
100};
101
102static struct gpio_led_platform_data dsmg600_led_data = {
103 .num_leds = ARRAY_SIZE(dsmg600_led_pins),
104 .leds = dsmg600_led_pins,
105};
106
107static struct platform_device dsmg600_leds = {
108 .name = "leds-gpio",
109 .id = -1,
110 .dev.platform_data = &dsmg600_led_data,
111};
112
113static struct resource dsmg600_uart_resources[] = {
114 {
115 .start = IXP4XX_UART1_BASE_PHYS,
116 .end = IXP4XX_UART1_BASE_PHYS + 0x0fff,
117 .flags = IORESOURCE_MEM,
118 },
119 {
120 .start = IXP4XX_UART2_BASE_PHYS,
121 .end = IXP4XX_UART2_BASE_PHYS + 0x0fff,
122 .flags = IORESOURCE_MEM,
123 }
124};
125
126static struct plat_serial8250_port dsmg600_uart_data[] = {
127 {
128 .mapbase = IXP4XX_UART1_BASE_PHYS,
129 .membase = (char *)IXP4XX_UART1_BASE_VIRT + REG_OFFSET,
130 .irq = IRQ_IXP4XX_UART1,
131 .flags = UPF_BOOT_AUTOCONF,
132 .iotype = UPIO_MEM,
133 .regshift = 2,
134 .uartclk = IXP4XX_UART_XTAL,
135 },
136 {
137 .mapbase = IXP4XX_UART2_BASE_PHYS,
138 .membase = (char *)IXP4XX_UART2_BASE_VIRT + REG_OFFSET,
139 .irq = IRQ_IXP4XX_UART2,
140 .flags = UPF_BOOT_AUTOCONF,
141 .iotype = UPIO_MEM,
142 .regshift = 2,
143 .uartclk = IXP4XX_UART_XTAL,
144 },
145 { }
146};
147
148static struct platform_device dsmg600_uart = {
149 .name = "serial8250",
150 .id = PLAT8250_DEV_PLATFORM,
151 .dev.platform_data = dsmg600_uart_data,
152 .num_resources = ARRAY_SIZE(dsmg600_uart_resources),
153 .resource = dsmg600_uart_resources,
154};
155
156static struct platform_device *dsmg600_devices[] __initdata = {
157 &dsmg600_i2c_gpio,
158 &dsmg600_flash,
159 &dsmg600_leds,
160};
161
162static void dsmg600_power_off(void)
163{
164
165 gpio_line_config(DSMG600_PO_GPIO, IXP4XX_GPIO_OUT);
166
167
168 gpio_line_set(DSMG600_PO_GPIO, IXP4XX_GPIO_HIGH);
169}
170
171
172
173
174static int power_button_countdown;
175
176
177#define PBUTTON_HOLDDOWN_COUNT 4
178
179static void dsmg600_power_handler(unsigned long data);
180static DEFINE_TIMER(dsmg600_power_timer, dsmg600_power_handler, 0, 0);
181
182static void dsmg600_power_handler(unsigned long data)
183{
184
185
186
187
188 if (gpio_get_value(DSMG600_PB_GPIO)) {
189
190
191 if (power_button_countdown > 0)
192 power_button_countdown--;
193
194 } else {
195
196
197 if (power_button_countdown == 0) {
198
199
200
201
202 ctrl_alt_del();
203
204
205 gpio_line_set(DSMG600_LED_PWR_GPIO, IXP4XX_GPIO_LOW);
206 } else {
207 power_button_countdown = PBUTTON_HOLDDOWN_COUNT;
208 }
209 }
210
211 mod_timer(&dsmg600_power_timer, jiffies + msecs_to_jiffies(500));
212}
213
214static irqreturn_t dsmg600_reset_handler(int irq, void *dev_id)
215{
216
217 machine_power_off();
218
219 return IRQ_HANDLED;
220}
221
222static void __init dsmg600_timer_init(void)
223{
224
225 ixp4xx_timer_freq = DSMG600_FREQ;
226
227
228 ixp4xx_timer_init();
229}
230
231static void __init dsmg600_init(void)
232{
233 ixp4xx_sys_init();
234
235
236 *IXP4XX_GPIO_GPCLKR = 0;
237
238 dsmg600_flash_resource.start = IXP4XX_EXP_BUS_BASE(0);
239 dsmg600_flash_resource.end =
240 IXP4XX_EXP_BUS_BASE(0) + ixp4xx_exp_bus_size - 1;
241
242 i2c_register_board_info(0, dsmg600_i2c_board_info,
243 ARRAY_SIZE(dsmg600_i2c_board_info));
244
245
246
247
248
249 (void)platform_device_register(&dsmg600_uart);
250
251 platform_add_devices(dsmg600_devices, ARRAY_SIZE(dsmg600_devices));
252
253 pm_power_off = dsmg600_power_off;
254
255 if (request_irq(gpio_to_irq(DSMG600_RB_GPIO), &dsmg600_reset_handler,
256 IRQF_DISABLED | IRQF_TRIGGER_LOW,
257 "DSM-G600 reset button", NULL) < 0) {
258
259 printk(KERN_DEBUG "Reset Button IRQ %d not available\n",
260 gpio_to_irq(DSMG600_RB_GPIO));
261 }
262
263
264
265
266
267
268
269 gpio_line_config(DSMG600_PB_GPIO, IXP4XX_GPIO_IN);
270
271
272 power_button_countdown = PBUTTON_HOLDDOWN_COUNT;
273
274 mod_timer(&dsmg600_power_timer, jiffies + msecs_to_jiffies(500));
275}
276
277MACHINE_START(DSMG600, "D-Link DSM-G600 RevA")
278
279 .atag_offset = 0x100,
280 .map_io = ixp4xx_map_io,
281 .init_early = ixp4xx_init_early,
282 .init_irq = ixp4xx_init_irq,
283 .init_time = dsmg600_timer_init,
284 .init_machine = dsmg600_init,
285#if defined(CONFIG_PCI)
286 .dma_zone_size = SZ_64M,
287#endif
288 .restart = ixp4xx_restart,
289MACHINE_END
290