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) 2011 Andrej Vlašić
7 * Copyright (C) 2011 Luka Perkov
11 #include <linux/kernel.h>
12 #include <linux/init.h>
13 #include <linux/platform_device.h>
14 #include <linux/leds.h>
15 #include <linux/gpio.h>
16 #include <linux/mtd/mtd.h>
17 #include <linux/mtd/partitions.h>
18 #include <linux/mtd/physmap.h>
19 #include <linux/input.h>
20 #include <linux/ath5k_platform.h>
21 #include <linux/pci.h>
22 #include <linux/phy.h>
24 #include <linux/string.h>
27 #include <lantiq_soc.h>
28 #include <lantiq_platform.h>
29 #include <dev-gpio-leds.h>
30 #include <dev-gpio-buttons.h>
32 #include "../machtypes.h"
33 #include "dev-wifi-ath5k.h"
35 #include "dev-dwc_otg.h"
37 #include "mach-gigasx76x.h"
39 #define UBOOT_ENV_OFFSET 0x010000
40 #define UBOOT_ENV_SIZE 0x010000
42 static struct mtd_partition gigasx76x_partitions
[] =
51 .offset
= UBOOT_ENV_OFFSET
,
52 .size
= UBOOT_ENV_SIZE
,
61 static struct gpio_led
62 gigasx76x_gpio_leds
[] __initdata
= {
63 { .name
= "soc:green:voip", .gpio
= 216, },
64 { .name
= "soc:green:adsl", .gpio
= 217, },
65 { .name
= "soc:green:usb", .gpio
= 218, },
66 { .name
= "soc:green:wifi", .gpio
= 219, },
67 { .name
= "soc:green:phone2", .gpio
= 220, },
68 { .name
= "soc:green:phone1", .gpio
= 221, },
69 { .name
= "soc:green:line", .gpio
= 222, },
70 { .name
= "soc:green:online", .gpio
= 223, },
73 static struct gpio_keys_button
74 gigasx76x_gpio_keys
[] __initdata
= {
78 .code
= KEY_WPS_BUTTON
,
79 .debounce_interval
= LTQ_KEYS_DEBOUNCE_INTERVAL
,
87 .debounce_interval
= LTQ_KEYS_DEBOUNCE_INTERVAL
,
93 static struct physmap_flash_data gigasx76x_flash_data
= {
94 .nr_parts
= ARRAY_SIZE(gigasx76x_partitions
),
95 .parts
= gigasx76x_partitions
,
98 static struct ltq_pci_data ltq_pci_data
= {
99 .clock
= PCI_CLOCK_INT
,
100 .gpio
= PCI_GNT1
| PCI_REQ1
,
101 .irq
= { [14] = INT_NUM_IM0_IRL0
+ 22, },
104 static struct ltq_eth_data ltq_eth_data
= {
105 .mii_mode
= PHY_INTERFACE_MODE_MII
,
108 static char __init
*get_uboot_env_var(char *haystack
, int haystack_len
, char *needle
, int needle_len
) {
110 for (i
= 0; i
<= haystack_len
- needle_len
; i
++) {
111 if (memcmp(haystack
+ i
, needle
, needle_len
) == 0) {
112 return haystack
+ i
+ needle_len
;
119 * gigasx76x_parse_hex_* are not uniq. in arm/orion there are also duplicates:
121 * TODO: one day write a patch for this :)
123 static int __init
gigasx76x_parse_hex_nibble(char n
) {
124 if (n
>= '0' && n
<= '9')
127 if (n
>= 'A' && n
<= 'F')
130 if (n
>= 'a' && n
<= 'f')
136 static int __init
gigasx76x_parse_hex_byte(const char *b
) {
140 hi
= gigasx76x_parse_hex_nibble(b
[0]);
141 lo
= gigasx76x_parse_hex_nibble(b
[1]);
143 if (hi
< 0 || lo
< 0)
146 return (hi
<< 4) | lo
;
149 static u16 gigasx76x_ath5k_eeprom_data
[ATH5K_PLAT_EEP_MAX_WORDS
];
150 static u8 gigasx76x_ath5k_eeprom_mac
[6];
152 static int __init
gigasx76x_register_ethernet(void) {
155 char *uboot_env_page
;
159 uboot_env_page
= ioremap(LTQ_FLASH_START
+ UBOOT_ENV_OFFSET
, UBOOT_ENV_SIZE
);
163 mac
= get_uboot_env_var(uboot_env_page
, UBOOT_ENV_SIZE
, "\0ethaddr=", 9);
164 boardid
= get_uboot_env_var(uboot_env_page
, UBOOT_ENV_SIZE
, "\0boardid=", 9);
174 /* Sanity check the string we're looking at */
175 for (i
= 0; i
< 5; i
++) {
176 if (*(mac
+ (i
* 3) + 2) != ':') {
181 for (i
= 0; i
< 6; i
++) {
183 byte
= gigasx76x_parse_hex_byte(mac
+ (i
* 3));
190 iounmap(uboot_env_page
);
191 printk("GIGASX76X: Found ethernet MAC address: ");
192 for (i
= 0; i
< 6; i
++)
193 printk("%.2x%s", addr
[i
], (i
< 5) ? ":" : ".\n");
195 memcpy(<q_eth_data
.mac
.sa_data
, addr
, 6);
196 ltq_register_etop(<q_eth_data
);
198 memcpy(&gigasx76x_ath5k_eeprom_mac
, addr
, 6);
199 gigasx76x_ath5k_eeprom_mac
[5]++;
201 if (strncmp(boardid
, "sx763", 5) == 0) {
202 printk("GIGASX76X: Board id is sx763.");
203 memcpy(&gigasx76x_ath5k_eeprom_data
, sx763_eeprom_data
, ATH5K_PLAT_EEP_MAX_WORDS
);
204 } else if (strncmp(boardid
, "sx762", 5) == 0) {
205 printk("GIGASX76X: Board id is sx762.");
206 memcpy(&gigasx76x_ath5k_eeprom_data
, sx762_eeprom_data
, ATH5K_PLAT_EEP_MAX_WORDS
);
208 printk("GIGASX76X: Board id is unknown, fix uboot_env data.");
214 iounmap(uboot_env_page
);
218 static void __init
gigasx76x_init(void) {
219 #define GIGASX76X_USB 29
220 #define GIGASX76X_MADWIFI_ADDR 0xb07f0000
222 ltq_register_gpio_stp();
223 ltq_register_nor(&gigasx76x_flash_data
);
224 ltq_register_pci(<q_pci_data
);
226 ltq_add_device_gpio_leds(-1, ARRAY_SIZE(gigasx76x_gpio_leds
), gigasx76x_gpio_leds
);
227 ltq_register_gpio_keys_polled(-1, LTQ_KEYS_POLL_INTERVAL
, ARRAY_SIZE(gigasx76x_gpio_keys
), gigasx76x_gpio_keys
);
228 ltq_register_ath5k(gigasx76x_ath5k_eeprom_data
, gigasx76x_ath5k_eeprom_mac
);
229 xway_register_dwc(GIGASX76X_USB
);
230 gigasx76x_register_ethernet();
233 MIPS_MACHINE(LANTIQ_MACH_GIGASX76X
, "GIGASX76X", "GIGASX76X - Gigaset SX761,SX762,SX763", gigasx76x_init
);