OpenWrt – Diff between revs 2 and 3
?pathlinks?
Rev 2 | Rev 3 | |||
---|---|---|---|---|
1 | /* |
1 | /* |
|
2 | * Arduino Yun support |
2 | * Arduino Yun support |
|
3 | * |
3 | * |
|
4 | * Copyright (C) 2011-2012 Gabor Juhos <juhosg@openwrt.org> |
4 | * Copyright (C) 2011-2012 Gabor Juhos <juhosg@openwrt.org> |
|
5 | * Copyright (C) 2015 Hauke Mehrtens <hauke@hauke-m.de> |
5 | * Copyright (C) 2015 Hauke Mehrtens <hauke@hauke-m.de> |
|
6 | * |
6 | * |
|
7 | * This program is free software; you can redistribute it and/or modify it |
7 | * This program is free software; you can redistribute it and/or modify it |
|
8 | * under the terms of the GNU General Public License version 2 as published |
8 | * under the terms of the GNU General Public License version 2 as published |
|
9 | * by the Free Software Foundation. |
9 | * by the Free Software Foundation. |
|
10 | */ |
10 | */ |
|
11 | |
11 | |
|
12 | #include "dev-eth.h" |
12 | #include "dev-eth.h" |
|
13 | #include "dev-gpio-buttons.h" |
13 | #include "dev-gpio-buttons.h" |
|
14 | #include "dev-leds-gpio.h" |
14 | #include "dev-leds-gpio.h" |
|
15 | #include "dev-m25p80.h" |
15 | #include "dev-m25p80.h" |
|
16 | #include "dev-spi.h" |
16 | #include "dev-spi.h" |
|
17 | #include "dev-usb.h" |
17 | #include "dev-usb.h" |
|
18 | #include "dev-wmac.h" |
18 | #include "dev-wmac.h" |
|
19 | #include "machtypes.h" |
19 | #include "machtypes.h" |
|
20 | #include <asm/mach-ath79/ar71xx_regs.h> |
20 | #include <asm/mach-ath79/ar71xx_regs.h> |
|
21 | #include <asm/mach-ath79/ath79.h> |
21 | #include <asm/mach-ath79/ath79.h> |
|
22 | #include <linux/gpio.h> |
22 | #include <linux/gpio.h> |
|
23 | #include "common.h" |
23 | #include "common.h" |
|
24 | |
24 | |
|
25 | // Uncomment to have reset on gpio18 instead of gipo7 |
25 | // Uncomment to have reset on gpio18 instead of gipo7 |
|
26 | #define DS2_B |
26 | #define DS2_B |
|
27 | |
27 | |
|
28 | #define DS_GPIO_LED_WLAN 0 |
28 | #define DS_GPIO_LED_WLAN 0 |
|
29 | #define DS_GPIO_LED_USB 1 |
29 | #define DS_GPIO_LED_USB 1 |
|
30 | |
30 | |
|
31 | #define DS_GPIO_OE 21 |
31 | #define DS_GPIO_OE 21 |
|
32 | #define DS_GPIO_AVR_RESET 18 |
32 | #define DS_GPIO_AVR_RESET 18 |
|
33 | |
33 | |
|
34 | // Maintained to have the console in the previous version of DS2 working |
34 | // Maintained to have the console in the previous version of DS2 working |
|
35 | #define DS_GPIO_AVR_RESET_DS2 7 |
35 | #define DS_GPIO_AVR_RESET_DS2 7 |
|
36 | |
36 | |
|
37 | #define DS_GPIO_OE2 22 |
37 | #define DS_GPIO_OE2 22 |
|
38 | #define DS_GPIO_UART_ENA 23 |
38 | #define DS_GPIO_UART_ENA 23 |
|
39 | #define DS_GPIO_CONF_BTN 20 |
39 | #define DS_GPIO_CONF_BTN 20 |
|
40 | |
40 | |
|
41 | #define DS_KEYS_POLL_INTERVAL 20 /* msecs */ |
41 | #define DS_KEYS_POLL_INTERVAL 20 /* msecs */ |
|
42 | #define DS_KEYS_DEBOUNCE_INTERVAL (3 * DS_KEYS_POLL_INTERVAL) |
42 | #define DS_KEYS_DEBOUNCE_INTERVAL (3 * DS_KEYS_POLL_INTERVAL) |
|
43 | |
43 | |
|
44 | #define DS_MAC0_OFFSET 0x0000 |
44 | #define DS_MAC0_OFFSET 0x0000 |
|
45 | #define DS_MAC1_OFFSET 0x0006 |
45 | #define DS_MAC1_OFFSET 0x0006 |
|
46 | #define DS_CALDATA_OFFSET 0x1000 |
46 | #define DS_CALDATA_OFFSET 0x1000 |
|
47 | #define DS_WMAC_MAC_OFFSET 0x1002 |
47 | #define DS_WMAC_MAC_OFFSET 0x1002 |
|
48 | |
48 | |
|
49 | |
49 | |
|
50 | static struct gpio_led ds_leds_gpio[] __initdata = { |
50 | static struct gpio_led ds_leds_gpio[] __initdata = { |
|
51 | { |
51 | { |
|
52 | .name = "arduino:white:usb", |
52 | .name = "arduino:white:usb", |
|
53 | .gpio = DS_GPIO_LED_USB, |
53 | .gpio = DS_GPIO_LED_USB, |
|
54 | .active_low = 0, |
54 | .active_low = 0, |
|
55 | }, |
55 | }, |
|
56 | { |
56 | { |
|
57 | .name = "arduino:blue:wlan", |
57 | .name = "arduino:blue:wlan", |
|
58 | .gpio = DS_GPIO_LED_WLAN, |
58 | .gpio = DS_GPIO_LED_WLAN, |
|
59 | .active_low = 0, |
59 | .active_low = 0, |
|
60 | }, |
60 | }, |
|
61 | }; |
61 | }; |
|
62 | |
62 | |
|
63 | static struct gpio_keys_button ds_gpio_keys[] __initdata = { |
63 | static struct gpio_keys_button ds_gpio_keys[] __initdata = { |
|
64 | { |
64 | { |
|
65 | .desc = "configuration button", |
65 | .desc = "configuration button", |
|
66 | .type = EV_KEY, |
66 | .type = EV_KEY, |
|
67 | .code = KEY_WPS_BUTTON, |
67 | .code = KEY_WPS_BUTTON, |
|
68 | .debounce_interval = DS_KEYS_DEBOUNCE_INTERVAL, |
68 | .debounce_interval = DS_KEYS_DEBOUNCE_INTERVAL, |
|
69 | .gpio = DS_GPIO_CONF_BTN, |
69 | .gpio = DS_GPIO_CONF_BTN, |
|
70 | .active_low = 1, |
70 | .active_low = 1, |
|
71 | }, |
71 | }, |
|
72 | }; |
72 | }; |
|
73 | |
73 | |
|
74 | static void __init ds_common_setup(void) |
74 | static void __init ds_common_setup(void) |
|
75 | { |
75 | { |
|
76 | static u8 mac[6]; |
76 | static u8 mac[6]; |
|
77 | |
77 | |
|
78 | u8 *art = (u8 *) KSEG1ADDR(0x1fff0000); |
78 | u8 *art = (u8 *) KSEG1ADDR(0x1fff0000); |
|
79 | ath79_register_m25p80(NULL); |
79 | ath79_register_m25p80(NULL); |
|
80 | |
80 | |
|
81 | if (ar93xx_wmac_read_mac_address(mac)) { |
81 | if (ar93xx_wmac_read_mac_address(mac)) { |
|
82 | ath79_register_wmac(NULL, NULL); |
82 | ath79_register_wmac(NULL, NULL); |
|
83 | } else { |
83 | } else { |
|
84 | ath79_register_wmac(art + DS_CALDATA_OFFSET, |
84 | ath79_register_wmac(art + DS_CALDATA_OFFSET, |
|
85 | art + DS_WMAC_MAC_OFFSET); |
85 | art + DS_WMAC_MAC_OFFSET); |
|
86 | memcpy(mac, art + DS_WMAC_MAC_OFFSET, sizeof(mac)); |
86 | memcpy(mac, art + DS_WMAC_MAC_OFFSET, sizeof(mac)); |
|
87 | } |
87 | } |
|
88 | |
88 | |
|
89 | mac[3] |= 0x08; |
89 | mac[3] |= 0x08; |
|
90 | ath79_init_mac(ath79_eth0_data.mac_addr, mac, 0); |
90 | ath79_init_mac(ath79_eth0_data.mac_addr, mac, 0); |
|
91 | |
91 | |
|
92 | mac[3] &= 0xF7; |
92 | mac[3] &= 0xF7; |
|
93 | ath79_init_mac(ath79_eth1_data.mac_addr, mac, 0); |
93 | ath79_init_mac(ath79_eth1_data.mac_addr, mac, 0); |
|
94 | ath79_register_mdio(0, 0x0); |
94 | ath79_register_mdio(0, 0x0); |
|
95 | |
95 | |
|
96 | /* LAN ports */ |
96 | /* LAN ports */ |
|
97 | ath79_register_eth(1); |
97 | ath79_register_eth(1); |
|
98 | |
98 | |
|
99 | /* WAN port */ |
99 | /* WAN port */ |
|
100 | ath79_register_eth(0); |
100 | ath79_register_eth(0); |
|
101 | } |
101 | } |
|
102 | |
102 | |
|
103 | static void __init ds_setup(void) |
103 | static void __init ds_setup(void) |
|
104 | { |
104 | { |
|
105 | u32 t; |
105 | u32 t; |
|
106 | |
106 | |
|
107 | ds_common_setup(); |
107 | ds_common_setup(); |
|
108 | |
108 | |
|
109 | ath79_register_leds_gpio(-1, ARRAY_SIZE(ds_leds_gpio), |
109 | ath79_register_leds_gpio(-1, ARRAY_SIZE(ds_leds_gpio), |
|
110 | ds_leds_gpio); |
110 | ds_leds_gpio); |
|
111 | ath79_register_gpio_keys_polled(-1, DS_KEYS_POLL_INTERVAL, |
111 | ath79_register_gpio_keys_polled(-1, DS_KEYS_POLL_INTERVAL, |
|
112 | ARRAY_SIZE(ds_gpio_keys), |
112 | ARRAY_SIZE(ds_gpio_keys), |
|
113 | ds_gpio_keys); |
113 | ds_gpio_keys); |
|
114 | ath79_register_usb(); |
114 | ath79_register_usb(); |
|
115 | |
115 | |
|
116 | /* use the swtich_led directly form sysfs */ |
116 | /* use the swtich_led directly form sysfs */ |
|
117 | ath79_gpio_function_disable(AR933X_GPIO_FUNC_ETH_SWITCH_LED0_EN | |
117 | ath79_gpio_function_disable(AR933X_GPIO_FUNC_ETH_SWITCH_LED0_EN | |
|
118 | AR933X_GPIO_FUNC_ETH_SWITCH_LED1_EN | |
118 | AR933X_GPIO_FUNC_ETH_SWITCH_LED1_EN | |
|
119 | AR933X_GPIO_FUNC_ETH_SWITCH_LED2_EN | |
119 | AR933X_GPIO_FUNC_ETH_SWITCH_LED2_EN | |
|
120 | AR933X_GPIO_FUNC_ETH_SWITCH_LED3_EN | |
120 | AR933X_GPIO_FUNC_ETH_SWITCH_LED3_EN | |
|
121 | AR933X_GPIO_FUNC_ETH_SWITCH_LED4_EN); |
121 | AR933X_GPIO_FUNC_ETH_SWITCH_LED4_EN); |
|
122 | |
122 | |
|
123 | //Disable the Function for some pins to have GPIO functionality active |
123 | //Disable the Function for some pins to have GPIO functionality active |
|
124 | // GPIO6-7-8 and GPIO11 |
124 | // GPIO6-7-8 and GPIO11 |
|
125 | ath79_gpio_function_setup(AR933X_GPIO_FUNC_JTAG_DISABLE | AR933X_GPIO_FUNC_I2S_MCK_EN, 0); |
125 | ath79_gpio_function_setup(AR933X_GPIO_FUNC_JTAG_DISABLE | AR933X_GPIO_FUNC_I2S_MCK_EN, 0); |
|
126 | |
126 | |
|
127 | ath79_gpio_function2_setup(AR933X_GPIO_FUNC2_JUMPSTART_DISABLE, 0); |
127 | ath79_gpio_function2_setup(AR933X_GPIO_FUNC2_JUMPSTART_DISABLE, 0); |
|
128 | |
128 | |
|
129 | printk("Setting DogStick2 GPIO\n"); |
129 | printk("Setting DogStick2 GPIO\n"); |
|
130 | |
130 | |
|
131 | t = ath79_reset_rr(AR933X_RESET_REG_BOOTSTRAP); |
131 | t = ath79_reset_rr(AR933X_RESET_REG_BOOTSTRAP); |
|
132 | t |= AR933X_BOOTSTRAP_MDIO_GPIO_EN; |
132 | t |= AR933X_BOOTSTRAP_MDIO_GPIO_EN; |
|
133 | ath79_reset_wr(AR933X_RESET_REG_BOOTSTRAP, t); |
133 | ath79_reset_wr(AR933X_RESET_REG_BOOTSTRAP, t); |
|
134 | |
134 | |
|
135 | // Put the avr reset to high |
135 | // Put the avr reset to high |
|
136 | if (gpio_request_one(DS_GPIO_AVR_RESET_DS2, |
136 | if (gpio_request_one(DS_GPIO_AVR_RESET_DS2, |
|
137 | GPIOF_OUT_INIT_LOW | GPIOF_EXPORT_DIR_FIXED, "OE-1") != 0) |
137 | GPIOF_OUT_INIT_LOW | GPIOF_EXPORT_DIR_FIXED, "OE-1") != 0) |
|
138 | printk("Error setting GPIO OE\n"); |
138 | printk("Error setting GPIO OE\n"); |
|
139 | gpio_unexport(DS_GPIO_AVR_RESET_DS2); |
139 | gpio_unexport(DS_GPIO_AVR_RESET_DS2); |
|
140 | gpio_free(DS_GPIO_AVR_RESET_DS2); |
140 | gpio_free(DS_GPIO_AVR_RESET_DS2); |
|
141 | |
141 | |
|
142 | // enable OE of level shifter |
142 | // enable OE of level shifter |
|
143 | if (gpio_request_one(DS_GPIO_OE, |
143 | if (gpio_request_one(DS_GPIO_OE, |
|
144 | GPIOF_OUT_INIT_HIGH | GPIOF_EXPORT_DIR_FIXED, "OE-1") != 0) |
144 | GPIOF_OUT_INIT_LOW | GPIOF_EXPORT_DIR_FIXED, "OE-1") != 0) |
|
145 | printk("Error setting GPIO OE\n"); |
145 | printk("Error setting GPIO OE\n"); |
|
146 | |
146 | |
|
147 | if (gpio_request_one(DS_GPIO_UART_ENA, |
147 | if (gpio_request_one(DS_GPIO_UART_ENA, |
|
148 | GPIOF_OUT_INIT_LOW | GPIOF_EXPORT_DIR_FIXED, "UART-ENA") != 0) |
148 | GPIOF_OUT_INIT_LOW | GPIOF_EXPORT_DIR_FIXED, "UART-ENA") != 0) |
|
149 | printk("Error setting GPIO Uart Enable\n"); |
149 | printk("Error setting GPIO Uart Enable\n"); |
|
150 | |
150 | |
|
151 | // enable OE of level shifter |
151 | // enable OE of level shifter |
|
152 | if (gpio_request_one(DS_GPIO_OE2, |
152 | if (gpio_request_one(DS_GPIO_OE2, |
|
153 | GPIOF_OUT_INIT_HIGH | GPIOF_EXPORT_DIR_FIXED, "OE-2") != 0) |
153 | GPIOF_OUT_INIT_LOW | GPIOF_EXPORT_DIR_FIXED, "OE-2") != 0) |
|
154 | printk("Error setting GPIO OE2\n"); |
154 | printk("Error setting GPIO OE2\n"); |
|
155 | } |
155 | } |
|
156 | |
156 | |
|
157 | MIPS_MACHINE(ATH79_MACH_ARDUINO_YUN, "Yun", "Arduino Yun", ds_setup); |
157 | MIPS_MACHINE(ATH79_MACH_ARDUINO_YUN, "Yun", "Arduino Yun", ds_setup); |
|
158 | |
158 | |