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>
26 #include <lantiq_soc.h>
28 #include <dev-gpio-leds.h>
29 #include <dev-gpio-buttons.h>
30 #include "dev-wifi-athxk.h"
32 #include "../machtypes.h"
34 #include "dev-dwc_otg.h"
35 #include "pci-ath-fixup.h"
36 #include <mtd/mtd-abi.h>
37 #include <asm-generic/sizes.h>
39 static struct mtd_partition dgn3500_partitions[] = {
44 .mask_flags = MTD_WRITEABLE,
47 .name = "environment",
50 .mask_flags = MTD_WRITEABLE,
53 .name = "calibration",
56 .mask_flags = MTD_WRITEABLE,
65 static struct ltq_pci_data ltq_pci_data = {
66 .clock = PCI_CLOCK_INT,
67 .gpio = PCI_GNT1 | PCI_REQ1,
69 [14] = INT_NUM_IM0_IRL0 + 22,
73 static struct ltq_eth_data ltq_eth_data = {
74 .mii_mode = PHY_INTERFACE_MODE_MII,
77 static struct gpio_led
78 dgn3500_gpio_leds[] __initdata = {
79 { .name = "soc:green:power", .gpio = 34, .active_low = 1, },
80 { .name = "soc:red:power", .gpio = 39, .active_low = 1, },
81 { .name = "soc:orange:wlan", .gpio = 51, .active_low = 1, },
82 { .name = "soc:green:wps", .gpio = 52, .active_low = 1, },
83 { .name = "soc:green:usb", .gpio = 22, .active_low = 1, },
84 { .name = "soc:green:dsl", .gpio = 4, .active_low = 1, },
85 { .name = "soc:green:internet", .gpio = 2, .active_low = 1, },
88 static struct gpio_keys_button
89 dgn3500_gpio_keys[] __initdata = {
94 .debounce_interval = LTQ_KEYS_DEBOUNCE_INTERVAL,
102 .debounce_interval = LTQ_KEYS_DEBOUNCE_INTERVAL,
108 #define SPI_GPIO_MRST 16
109 #define SPI_GPIO_MTSR 17
110 #define SPI_GPIO_CLK 18
111 #define SPI_GPIO_CS0 10
113 static struct spi_gpio_platform_data spi_gpio_data = {
115 .mosi = SPI_GPIO_MTSR,
116 .miso = SPI_GPIO_MRST,
120 static struct platform_device spi_gpio_device = {
122 .dev.platform_data = &spi_gpio_data,
125 static struct flash_platform_data spi_flash_data = {
127 .parts = dgn3500_partitions,
128 .nr_parts = ARRAY_SIZE(dgn3500_partitions),
131 static struct spi_board_info spi_flash __initdata = {
132 .modalias = "m25p80",
135 .max_speed_hz = 10 * 1000 * 1000,
138 .controller_data = (void *) SPI_GPIO_CS0,
139 .platform_data = &spi_flash_data
142 static u8 ltq_ethaddr[6] = { 0 };
144 static int __init setup_ethaddr(char *str)
146 if (!mac_pton(str, ltq_ethaddr))
147 memset(ltq_ethaddr, 0, 6);
150 __setup("ethaddr=", setup_ethaddr);
152 static u16 dgn3500_eeprom_data[ATH9K_PLAT_EEP_MAX_WORDS] = {0};
154 static ssize_t ath_eeprom_read(struct file *filp, struct kobject *kobj,
155 struct bin_attribute *attr, char *buf,
156 loff_t offset, size_t count)
158 if (unlikely(offset >= sizeof(dgn3500_eeprom_data)))
160 if ((offset + count) > sizeof(dgn3500_eeprom_data))
161 count = sizeof(dgn3500_eeprom_data) - offset;
162 if (unlikely(!count))
165 memcpy(buf, (char *)(dgn3500_eeprom_data) + offset, count);
170 extern struct ath9k_platform_data ath9k_pdata;
172 static ssize_t ath_eeprom_write(struct file *filp, struct kobject *kobj,
173 struct bin_attribute *attr, char *buf,
174 loff_t offset, size_t count)
177 char *eeprom_bytes = (char *)dgn3500_eeprom_data;
179 if (unlikely(offset >= sizeof(dgn3500_eeprom_data)))
181 if ((offset + count) > sizeof(dgn3500_eeprom_data))
182 count = sizeof(dgn3500_eeprom_data) - offset;
183 if (unlikely(!count))
188 /* The PCI fixup routine requires an endian swap of the calibartion data
190 for (i = 0; i < count; i += 2) {
191 eeprom_bytes[offset + i + 1] = buf[i];
192 eeprom_bytes[offset + i] = buf[i+1];
195 /* The original data does not contain a checksum. Set the country and
196 * calculate new checksum when all data is received */
197 if ((count + offset) == sizeof(dgn3500_eeprom_data))
198 memcpy(ath9k_pdata.eeprom_data, dgn3500_eeprom_data,
199 sizeof(ath9k_pdata.eeprom_data));
204 static struct bin_attribute dev_attr_ath_eeprom = {
206 .name = "ath_eeprom",
207 .mode = S_IRUGO|S_IWUSR,
209 .read = ath_eeprom_read,
210 .write = ath_eeprom_write,
213 static void __init dgn3500_init(void)
215 if (sysfs_create_bin_file(firmware_kobj, &dev_attr_ath_eeprom))
216 printk(KERN_INFO "Failed to create ath eeprom sysfs entry\n");
217 ltq_add_device_gpio_leds(-1, ARRAY_SIZE(dgn3500_gpio_leds),
219 ltq_register_gpio_keys_polled(-1, LTQ_KEYS_POLL_INTERVAL,
220 ARRAY_SIZE(dgn3500_gpio_keys), dgn3500_gpio_keys);
221 platform_device_register(&spi_gpio_device);
222 ltq_register_pci(<q_pci_data);
223 spi_register_board_info(&spi_flash, 1);
224 if (!is_valid_ether_addr(ltq_ethaddr)) {
225 printk(KERN_INFO "MAC invalid using random\n");
226 random_ether_addr(ltq_ethaddr);
228 memcpy(<q_eth_data.mac.sa_data, ltq_ethaddr, 6);
229 ltq_register_etop(<q_eth_data);
230 ltq_register_ath9k(dgn3500_eeprom_data, ltq_ethaddr);
231 ltq_pci_ath_fixup(14, dgn3500_eeprom_data);
232 /* The usb power is always enabled, protected by a fuse */
233 xway_register_dwc(-1);
236 MIPS_MACHINE(LANTIQ_MACH_DGN3500B,