ramips: properly setup the FEATURES variable
[openwrt.git] / target / linux / ramips / files-3.7 / arch / mips / ralink / rt3883 / mach-omni-emb-hpm.c
1 /*
2  *  Omnima EMB HPM board support
3  *
4  *  Copyright (C) 2012 Gabor Juhos <juhosg@openwrt.org>
5  *
6  *  This program is free software; you can redistribute it and/or modify it
7  *  under the terms of the GNU General Public License version 2 as published
8  *  by the Free Software Foundation.
9  */
10
11 #include <linux/init.h>
12 #include <linux/platform_device.h>
13 #include <linux/ethtool.h>
14 #include <linux/gpio.h>
15 #include <linux/rt2x00_platform.h>
16 #include <linux/spi/spi.h>
17
18 #include <asm/mach-ralink/machine.h>
19 #include <asm/mach-ralink/dev-gpio-buttons.h>
20 #include <asm/mach-ralink/dev-gpio-leds.h>
21 #include <asm/mach-ralink/rt3883.h>
22 #include <asm/mach-ralink/rt3883_regs.h>
23 #include <asm/mach-ralink/ramips_eth_platform.h>
24
25 #include "devices.h"
26
27 #define OMNI_EMB_HPM_GPIO_LED_POWER             7
28 #define OMNI_EMB_HPM_GPIO_LED_ETH_GREEN         20
29 #define OMNI_EMB_HPM_GPIO_LED_ETH_RED           18
30 #define OMNI_EMB_HPM_GPIO_LED_STATUS            21
31 #define OMNI_EMB_HPM_GPIO_LED_WIFI_GREEN        17
32 #define OMNI_EMB_HPM_GPIO_LED_WIFI_RED          19
33
34 #define OMNI_EMB_HPM_GPIO_BUTTON_RESET          14
35
36 #define OMNI_EMB_HPM_GPIO_USB0_ENABLE           2
37 #define OMNI_EMB_HPM_GPIO_USB1_ENABLE           1
38 #define OMNI_EMB_HPM_GPIO_USB0_OC               12
39 #define OMNI_EMB_HPM_GPIO_USB1_OC               13
40
41 #define OMNI_EMB_HPM_KEYS_POLL_INTERVAL 20
42 #define OMNI_EMB_HPM_KEYS_DEBOUNCE_INTERVAL (3 * OMNI_EMB_HPM_KEYS_POLL_INTERVAL)
43
44 static struct gpio_led omni_emb_hpm_leds_gpio[] __initdata = {
45         {
46                 .name           = "emb:orange:power",
47                 .gpio           = OMNI_EMB_HPM_GPIO_LED_POWER,
48                 .active_low     = 1,
49         },
50         {
51                 .name           = "emb:green:status",
52                 .gpio           = OMNI_EMB_HPM_GPIO_LED_STATUS,
53         },
54         {
55                 .name           = "emb:green:eth",
56                 .gpio           = OMNI_EMB_HPM_GPIO_LED_ETH_GREEN,
57                 .active_low     = 1,
58         },
59         {
60                 .name           = "emb:red:eth",
61                 .gpio           = OMNI_EMB_HPM_GPIO_LED_ETH_RED,
62                 .active_low     = 1,
63         },
64         {
65                 .name           = "emb:green:wifi",
66                 .gpio           = OMNI_EMB_HPM_GPIO_LED_WIFI_GREEN,
67                 .active_low     = 1,
68         },
69         {
70                 .name           = "emb:red:wifi",
71                 .gpio           = OMNI_EMB_HPM_GPIO_LED_WIFI_RED,
72                 .active_low     = 1,
73         },
74 };
75
76 static struct gpio_keys_button omni_emb_hpm_gpio_buttons[] __initdata = {
77         {
78                 .desc           = "reset",
79                 .type           = EV_KEY,
80                 .code           = KEY_RESTART,
81                 .debounce_interval = OMNI_EMB_HPM_KEYS_DEBOUNCE_INTERVAL,
82                 .gpio           = OMNI_EMB_HPM_GPIO_BUTTON_RESET,
83                 .active_low     = 1,
84         },
85 };
86
87 static struct spi_board_info omni_emb_hpm_spi_info[] = {
88         {
89                 .bus_num        = 0,
90                 .chip_select    = 0,
91                 .max_speed_hz   = 25000000,
92                 .modalias       = "m25p80",
93         }
94 };
95
96
97 static void __init omni_emb_hpm_gpio_request(unsigned int gpio,
98                                              unsigned long flags,
99                                              const char *label,
100                                              bool free)
101 {
102         int err;
103
104         err = gpio_request_one(gpio, flags, label);
105         if (err) {
106                 pr_err("EMB_HPM: can't setup GPIO%u (%s), err=%d\n",
107                         gpio, label, err);
108                 return;
109         }
110
111         if (free)
112                 gpio_free(gpio);
113 }
114
115 static void __init omni_emb_hpm_gpio_init(void)
116 {
117         rt3883_gpio_init(RT3883_GPIO_MODE_I2C |
118                          RT3883_GPIO_MODE_UART0(RT3883_GPIO_MODE_GPIO) |
119                          RT3883_GPIO_MODE_JTAG);
120
121         omni_emb_hpm_gpio_request(OMNI_EMB_HPM_GPIO_USB0_ENABLE,
122                                   GPIOF_OUT_INIT_HIGH,
123                                   "USB0 power", true);
124         omni_emb_hpm_gpio_request(OMNI_EMB_HPM_GPIO_USB1_ENABLE,
125                                   GPIOF_OUT_INIT_HIGH,
126                                   "USB1 power", true);
127         omni_emb_hpm_gpio_request(OMNI_EMB_HPM_GPIO_USB0_OC,
128                                   GPIOF_IN, "USB0 OC", false);
129         omni_emb_hpm_gpio_request(OMNI_EMB_HPM_GPIO_USB1_OC,
130                                   GPIOF_IN, "USB1 OC", false);
131 }
132
133 static void __init omni_emb_hpm_init(void)
134 {
135         omni_emb_hpm_gpio_init();
136
137         ramips_register_gpio_leds(-1, ARRAY_SIZE(omni_emb_hpm_leds_gpio),
138                                   omni_emb_hpm_leds_gpio);
139
140         ramips_register_gpio_buttons(-1, OMNI_EMB_HPM_KEYS_POLL_INTERVAL,
141                                      ARRAY_SIZE(omni_emb_hpm_gpio_buttons),
142                                      omni_emb_hpm_gpio_buttons);
143
144         rt3883_register_spi(omni_emb_hpm_spi_info,
145                             ARRAY_SIZE(omni_emb_hpm_spi_info));
146
147         rt3883_register_wlan();
148
149         rt3883_eth_data.phy_mask = BIT(4);
150         rt3883_register_ethernet();
151
152         rt3883_register_wdt(false);
153         rt3883_register_usbhost();
154 }
155
156 MIPS_MACHINE(RAMIPS_MACH_OMNI_EMB_HPM, "OMNI-EMB-HPM", "Omnima EMB HPM",
157              omni_emb_hpm_init);