2 * This program is free software; you can redistribute it and/or modify it
3 * under the terms of the GNU General Public License version 2 as published
4 * by the Free Software Foundation.
6 * Copyright (C) 2010 John Crispin <blogic@openwrt.org>
7 * Copyright (C) 2012 Pieter Voorthuijsen <p.voorthuijsen@gmail.com>
10 #include <linux/init.h>
11 #include <linux/platform_device.h>
12 #include <linux/mtd/mtd.h>
13 #include <linux/mtd/partitions.h>
14 #include <linux/mtd/physmap.h>
15 #include <linux/input.h>
16 #include <linux/phy.h>
17 #include <linux/spi/spi.h>
18 #include <linux/spi/flash.h>
19 #include <linux/spi/spi_gpio.h>
20 #include <linux/ath9k_platform.h>
21 #include <linux/if_ether.h>
22 #include <linux/etherdevice.h>
23 #include <linux/kobject.h>
24 #include <linux/sysfs.h>
25 #include <linux/rtl8366.h>
27 #include <lantiq_soc.h>
29 #include <dev-gpio-leds.h>
30 #include <dev-gpio-buttons.h>
31 #include "dev-wifi-athxk.h"
33 #include "../machtypes.h"
35 #include "dev-dwc_otg.h"
36 #include "pci-ath-fixup.h"
37 #include <mtd/mtd-abi.h>
38 #include <asm-generic/sizes.h>
40 static struct mtd_partition dgn3500_partitions
[] = {
45 .mask_flags
= MTD_WRITEABLE
,
48 .name
= "environment",
51 .mask_flags
= MTD_WRITEABLE
,
54 .name
= "calibration",
57 .mask_flags
= MTD_WRITEABLE
,
66 static struct ltq_pci_data ltq_pci_data
= {
67 .clock
= PCI_CLOCK_INT
,
68 .gpio
= PCI_GNT1
| PCI_REQ1
,
70 [14] = INT_NUM_IM0_IRL0
+ 22,
74 static struct ltq_eth_data ltq_eth_data
= {
75 .mii_mode
= PHY_INTERFACE_MODE_MII
,
78 static struct gpio_led
79 dgn3500_gpio_leds
[] __initdata
= {
80 { .name
= "soc:green:power", .gpio
= 34, .active_low
= 1, },
81 { .name
= "soc:red:power", .gpio
= 39, .active_low
= 1, },
82 { .name
= "soc:orange:wlan", .gpio
= 51, .active_low
= 1, },
83 { .name
= "soc:green:wps", .gpio
= 52, .active_low
= 1, },
84 { .name
= "soc:green:usb", .gpio
= 22, .active_low
= 1, },
85 { .name
= "soc:green:dsl", .gpio
= 4, .active_low
= 1, },
86 { .name
= "soc:green:internet", .gpio
= 2, .active_low
= 1, },
89 static struct gpio_keys_button
90 dgn3500_gpio_keys
[] __initdata
= {
95 .debounce_interval
= LTQ_KEYS_DEBOUNCE_INTERVAL
,
103 .debounce_interval
= LTQ_KEYS_DEBOUNCE_INTERVAL
,
109 #define SPI_GPIO_MRST 16
110 #define SPI_GPIO_MTSR 17
111 #define SPI_GPIO_CLK 18
112 #define SPI_GPIO_CS0 10
114 static struct spi_gpio_platform_data spi_gpio_data
= {
116 .mosi
= SPI_GPIO_MTSR
,
117 .miso
= SPI_GPIO_MRST
,
121 static struct platform_device spi_gpio_device
= {
123 .dev
.platform_data
= &spi_gpio_data
,
126 static struct flash_platform_data spi_flash_data
= {
128 .parts
= dgn3500_partitions
,
129 .nr_parts
= ARRAY_SIZE(dgn3500_partitions
),
132 static struct spi_board_info spi_flash __initdata
= {
133 .modalias
= "m25p80",
136 .max_speed_hz
= 10 * 1000 * 1000,
139 .controller_data
= (void *) SPI_GPIO_CS0
,
140 .platform_data
= &spi_flash_data
143 static u8 ltq_ethaddr
[6] = { 0 };
145 static int __init
setup_ethaddr(char *str
)
147 if (!mac_pton(str
, ltq_ethaddr
))
148 memset(ltq_ethaddr
, 0, 6);
151 __setup("ethaddr=", setup_ethaddr
);
156 static struct rtl8366_platform_data rtl8366rb_data
= {
161 static struct platform_device rtl8366rb_device
= {
162 .name
= RTL8366RB_DRIVER_NAME
,
165 .platform_data
= &rtl8366rb_data
,
169 static u16 dgn3500_eeprom_data
[ATH9K_PLAT_EEP_MAX_WORDS
] = {0};
171 static ssize_t
ath_eeprom_read(struct file
*filp
, struct kobject
*kobj
,
172 struct bin_attribute
*attr
, char *buf
,
173 loff_t offset
, size_t count
)
175 if (unlikely(offset
>= sizeof(dgn3500_eeprom_data
)))
177 if ((offset
+ count
) > sizeof(dgn3500_eeprom_data
))
178 count
= sizeof(dgn3500_eeprom_data
) - offset
;
179 if (unlikely(!count
))
182 memcpy(buf
, (char *)(dgn3500_eeprom_data
) + offset
, count
);
187 extern struct ath9k_platform_data ath9k_pdata
;
189 static ssize_t
ath_eeprom_write(struct file
*filp
, struct kobject
*kobj
,
190 struct bin_attribute
*attr
, char *buf
,
191 loff_t offset
, size_t count
)
194 char *eeprom_bytes
= (char *)dgn3500_eeprom_data
;
196 if (unlikely(offset
>= sizeof(dgn3500_eeprom_data
)))
198 if ((offset
+ count
) > sizeof(dgn3500_eeprom_data
))
199 count
= sizeof(dgn3500_eeprom_data
) - offset
;
200 if (unlikely(!count
))
205 /* The PCI fixup routine requires an endian swap of the calibartion data
207 for (i
= 0; i
< count
; i
+= 2) {
208 eeprom_bytes
[offset
+ i
+ 1] = buf
[i
];
209 eeprom_bytes
[offset
+ i
] = buf
[i
+1];
212 /* The original data does not contain a checksum. Set the country and
213 * calculate new checksum when all data is received */
214 if ((count
+ offset
) == sizeof(dgn3500_eeprom_data
))
215 memcpy(ath9k_pdata
.eeprom_data
, dgn3500_eeprom_data
,
216 sizeof(ath9k_pdata
.eeprom_data
));
221 static struct bin_attribute dev_attr_ath_eeprom
= {
223 .name
= "ath_eeprom",
224 .mode
= S_IRUGO
|S_IWUSR
,
226 .read
= ath_eeprom_read
,
227 .write
= ath_eeprom_write
,
230 static void __init
dgn3500_init(void)
232 if (sysfs_create_bin_file(firmware_kobj
, &dev_attr_ath_eeprom
))
233 printk(KERN_INFO
"Failed to create ath eeprom sysfs entry\n");
234 ltq_add_device_gpio_leds(-1, ARRAY_SIZE(dgn3500_gpio_leds
),
236 ltq_register_gpio_keys_polled(-1, LTQ_KEYS_POLL_INTERVAL
,
237 ARRAY_SIZE(dgn3500_gpio_keys
), dgn3500_gpio_keys
);
238 platform_device_register(&spi_gpio_device
);
239 ltq_register_pci(<q_pci_data
);
240 spi_register_board_info(&spi_flash
, 1);
241 if (!is_valid_ether_addr(ltq_ethaddr
)) {
242 printk(KERN_INFO
"MAC invalid using random\n");
243 random_ether_addr(ltq_ethaddr
);
245 memcpy(<q_eth_data
.mac
.sa_data
, ltq_ethaddr
, 6);
246 ltq_register_etop(<q_eth_data
);
247 ltq_register_ath9k(dgn3500_eeprom_data
, ltq_ethaddr
);
248 ltq_pci_ath_fixup(14, dgn3500_eeprom_data
);
249 /* The usb power is always enabled, protected by a fuse */
250 xway_register_dwc(-1);
251 platform_device_register(&rtl8366rb_device
);
254 MIPS_MACHINE(LANTIQ_MACH_DGN3500B
,