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
,
60 .name
= "board_config",
66 static struct gpio_led
67 gigasx76x_gpio_leds
[] __initdata
= {
69 { .name
= "soc:green:usb", .gpio
= 202, },
70 { .name
= "soc:green:wifi", .gpio
= 203, },
71 { .name
= "soc:green:phone2", .gpio
= 204, },
72 { .name
= "soc:green:phone1", .gpio
= 205, },
73 { .name
= "soc:green:line", .gpio
= 206, },
74 { .name
= "soc:green:online", .gpio
= 207, },
75 { .name
= "soc:green:voip", .gpio
= 208, },
78 static struct gpio_keys_button
79 gigasx76x_gpio_keys
[] __initdata
= {
84 .debounce_interval
= LTQ_KEYS_DEBOUNCE_INTERVAL
,
92 .debounce_interval = LTQ_KEYS_DEBOUNCE_INTERVAL,
98 static struct physmap_flash_data gigasx76x_flash_data
= {
99 .nr_parts
= ARRAY_SIZE(gigasx76x_partitions
),
100 .parts
= gigasx76x_partitions
,
103 static struct ltq_pci_data ltq_pci_data
= {
104 .clock
= PCI_CLOCK_INT
,
105 .gpio
= PCI_GNT1
| PCI_REQ1
,
106 .irq
= { [14] = INT_NUM_IM0_IRL0
+ 22, },
109 static struct ltq_eth_data ltq_eth_data
= {
110 .mii_mode
= PHY_INTERFACE_MODE_MII
,
113 static char __init
*get_uboot_env_var(char *haystack
, int haystack_len
, char *needle
, int needle_len
) {
115 for (i
= 0; i
<= haystack_len
- needle_len
; i
++) {
116 if (memcmp(haystack
+ i
, needle
, needle_len
) == 0) {
117 return haystack
+ i
+ needle_len
;
124 * gigasx76x_parse_hex_* are not uniq. in arm/orion there are also duplicates:
126 * TODO: one day write a patch for this :)
128 static int __init
gigasx76x_parse_hex_nibble(char n
) {
129 if (n
>= '0' && n
<= '9')
132 if (n
>= 'A' && n
<= 'F')
135 if (n
>= 'a' && n
<= 'f')
141 static int __init
gigasx76x_parse_hex_byte(const char *b
) {
145 hi
= gigasx76x_parse_hex_nibble(b
[0]);
146 lo
= gigasx76x_parse_hex_nibble(b
[1]);
148 if (hi
< 0 || lo
< 0)
151 return (hi
<< 4) | lo
;
154 static u16 gigasx76x_ath5k_eeprom_data
[ATH5K_PLAT_EEP_MAX_WORDS
];
155 static u8 gigasx76x_ath5k_eeprom_mac
[6];
157 static int __init
gigasx76x_register_ethernet(void) {
160 char *uboot_env_page
;
164 uboot_env_page
= ioremap(LTQ_FLASH_START
+ UBOOT_ENV_OFFSET
, UBOOT_ENV_SIZE
);
168 mac
= get_uboot_env_var(uboot_env_page
, UBOOT_ENV_SIZE
, "\0ethaddr=", 9);
169 boardid
= get_uboot_env_var(uboot_env_page
, UBOOT_ENV_SIZE
, "\0boardid=", 9);
179 /* Sanity check the string we're looking at */
180 for (i
= 0; i
< 5; i
++) {
181 if (*(mac
+ (i
* 3) + 2) != ':') {
186 for (i
= 0; i
< 6; i
++) {
188 byte
= gigasx76x_parse_hex_byte(mac
+ (i
* 3));
195 iounmap(uboot_env_page
);
196 printk("GIGASX76X: Found ethernet MAC address: ");
197 for (i
= 0; i
< 6; i
++)
198 printk("%.2x%s", addr
[i
], (i
< 5) ? ":" : ".\n");
200 memcpy(<q_eth_data
.mac
.sa_data
, addr
, 6);
201 ltq_register_etop(<q_eth_data
);
203 memcpy(&gigasx76x_ath5k_eeprom_mac
, addr
, 6);
204 gigasx76x_ath5k_eeprom_mac
[5]++;
206 if (strncmp(boardid
, "sx763", 5) == 0) {
207 printk("GIGASX76X: Board id is sx763.");
208 memcpy(&gigasx76x_ath5k_eeprom_data
, sx763_eeprom_data
, ATH5K_PLAT_EEP_MAX_WORDS
);
209 } else if (strncmp(boardid
, "sx762", 5) == 0) {
210 printk("GIGASX76X: Board id is sx762.");
211 memcpy(&gigasx76x_ath5k_eeprom_data
, sx762_eeprom_data
, ATH5K_PLAT_EEP_MAX_WORDS
);
213 printk("GIGASX76X: Board id is unknown, fix uboot_env data.");
219 iounmap(uboot_env_page
);
223 static void __init
gigasx76x_init(void) {
224 #define GIGASX76X_USB 29
225 #define GIGASX76X_MADWIFI_ADDR 0xb07f0000
227 ltq_register_gpio_stp();
228 ltq_register_nor(&gigasx76x_flash_data
);
229 ltq_register_pci(<q_pci_data
);
231 ltq_register_madwifi_eep(GIGASX76X_MADWIFI_ADDR
);
232 ltq_add_device_gpio_leds(-1, ARRAY_SIZE(gigasx76x_gpio_leds
), gigasx76x_gpio_leds
);
233 ltq_register_gpio_keys_polled(-1, LTQ_KEYS_POLL_INTERVAL
, ARRAY_SIZE(gigasx76x_gpio_keys
), gigasx76x_gpio_keys
);
234 ltq_register_ath5k(gigasx76x_ath5k_eeprom_data
, gigasx76x_ath5k_eeprom_mac
);
235 xway_register_dwc(GIGASX76X_USB
);
236 gigasx76x_register_ethernet();
239 MIPS_MACHINE(LANTIQ_MACH_GIGASX76X
, "GIGASX76X", "GIGASX76X - Gigaset SX761,SX762,SX763", gigasx76x_init
);