ixp4xx: patch cleanup
[openwrt.git] / target / linux / ixp4xx / patches-3.3 / 300-avila_support.patch
1 --- a/arch/arm/mach-ixp4xx/avila-setup.c
2 +++ b/arch/arm/mach-ixp4xx/avila-setup.c
3 @@ -14,9 +14,15 @@
4  #include <linux/kernel.h>
5  #include <linux/init.h>
6  #include <linux/device.h>
7 +#include <linux/if_ether.h>
8 +#include <linux/socket.h>
9 +#include <linux/netdevice.h>
10  #include <linux/serial.h>
11  #include <linux/tty.h>
12  #include <linux/serial_8250.h>
13 +#include <linux/i2c.h>
14 +#include <linux/i2c/at24.h>
15 +#include <linux/leds.h>
16  #include <linux/i2c-gpio.h>
17  #include <asm/types.h>
18  #include <asm/setup.h>
19 @@ -30,6 +36,20 @@
20  #define AVILA_SDA_PIN  7
21  #define AVILA_SCL_PIN  6
22  
23 +/* User LEDs */
24 +#define AVILA_GW23XX_LED_USER_GPIO     3
25 +#define AVILA_GW23X7_LED_USER_GPIO     4
26 +
27 +/* gpio mask used by platform device */
28 +#define AVILA_GPIO_MASK        (1 << 1) | (1 << 3) | (1 << 5) | (1 << 7) | (1 << 9)
29 +
30 +struct avila_board_info {
31 +       unsigned char   *model;
32 +       void            (*setup)(void);
33 +};
34 +
35 +static struct avila_board_info *avila_info __initdata;
36 +
37  static struct flash_platform_data avila_flash_data = {
38         .map_name       = "cfi_probe",
39         .width          = 2,
40 @@ -133,16 +153,277 @@ static struct platform_device avila_pata
41         .resource               = avila_pata_resources,
42  };
43  
44 +/* Built-in 10/100 Ethernet MAC interfaces */
45 +static struct eth_plat_info avila_npeb_data = {
46 +       .phy            = 0,
47 +       .rxq            = 3,
48 +       .txreadyq       = 20,
49 +};
50 +
51 +static struct eth_plat_info avila_npec_data = {
52 +       .phy            = 1,
53 +       .rxq            = 4,
54 +       .txreadyq       = 21,
55 +};
56 +
57 +static struct platform_device avila_npeb_device = {
58 +       .name                   = "ixp4xx_eth",
59 +       .id                     = IXP4XX_ETH_NPEB,
60 +       .dev.platform_data      = &avila_npeb_data,
61 +};
62 +
63 +static struct platform_device avila_npec_device = {
64 +       .name                   = "ixp4xx_eth",
65 +       .id                     = IXP4XX_ETH_NPEC,
66 +       .dev.platform_data      = &avila_npec_data,
67 +};
68 +
69 +static struct gpio_led avila_gpio_leds[] = {
70 +       {
71 +               .name           = "user",  /* green led */
72 +               .gpio           = AVILA_GW23XX_LED_USER_GPIO,
73 +               .active_low     = 1,
74 +       }
75 +};
76 +
77 +static struct gpio_led_platform_data avila_gpio_leds_data = {
78 +       .num_leds               = 1,
79 +       .leds                   = avila_gpio_leds,
80 +};
81 +
82 +static struct platform_device avila_gpio_leds_device = {
83 +       .name                   = "leds-gpio",
84 +       .id                     = -1,
85 +       .dev.platform_data      = &avila_gpio_leds_data,
86 +};
87 +
88 +static struct latch_led avila_latch_leds[] = {
89 +       {
90 +               .name   = "led0",  /* green led */
91 +               .bit    = 0,
92 +       },
93 +       {
94 +               .name   = "led1",  /* green led */
95 +               .bit    = 1,
96 +       },
97 +       {
98 +               .name   = "led2",  /* green led */
99 +               .bit    = 2,
100 +       },
101 +       {
102 +               .name   = "led3",  /* green led */
103 +               .bit    = 3,
104 +       },
105 +       {
106 +               .name   = "led4",  /* green led */
107 +               .bit    = 4,
108 +       },
109 +       {
110 +               .name   = "led5",  /* green led */
111 +               .bit    = 5,
112 +       },
113 +       {
114 +               .name   = "led6",  /* green led */
115 +               .bit    = 6,
116 +       },
117 +       {
118 +               .name   = "led7",  /* green led */
119 +               .bit    = 7,
120 +       }
121 +};
122 +
123 +static struct latch_led_platform_data avila_latch_leds_data = {
124 +       .num_leds       = 8,
125 +       .leds           = avila_latch_leds,
126 +       .mem            = 0x51000000,
127 +};
128 +
129 +static struct platform_device avila_latch_leds_device = {
130 +       .name                   = "leds-latch",
131 +       .id                     = -1,
132 +       .dev.platform_data      = &avila_latch_leds_data,
133 +};
134 +
135  static struct platform_device *avila_devices[] __initdata = {
136         &avila_i2c_gpio,
137         &avila_flash,
138         &avila_uart
139  };
140  
141 +static void __init avila_gw23xx_setup(void)
142 +{
143 +       platform_device_register(&avila_npeb_device);
144 +       platform_device_register(&avila_npec_device);
145 +
146 +       platform_device_register(&avila_gpio_leds_device);
147 +}
148 +
149 +static void __init avila_gw2342_setup(void)
150 +{
151 +       platform_device_register(&avila_npeb_device);
152 +       platform_device_register(&avila_npec_device);
153 +
154 +       platform_device_register(&avila_gpio_leds_device);
155 +}
156 +
157 +static void __init avila_gw2345_setup(void)
158 +{
159 +       avila_npeb_data.phy = IXP4XX_ETH_PHY_MAX_ADDR;
160 +       avila_npeb_data.phy_mask = 0x1e; /* ports 1-4 of the KS8995 switch */
161 +       platform_device_register(&avila_npeb_device);
162 +
163 +       avila_npec_data.phy = 5; /* port 5 of the KS8995 switch */
164 +       platform_device_register(&avila_npec_device);
165 +
166 +       platform_device_register(&avila_gpio_leds_device);
167 +}
168 +
169 +static void __init avila_gw2347_setup(void)
170 +{
171 +       platform_device_register(&avila_npeb_device);
172 +
173 +       avila_gpio_leds[0].gpio = AVILA_GW23X7_LED_USER_GPIO;
174 +       platform_device_register(&avila_gpio_leds_device);
175 +}
176 +
177 +static void __init avila_gw2348_setup(void)
178 +{
179 +       platform_device_register(&avila_npeb_device);
180 +       platform_device_register(&avila_npec_device);
181 +
182 +       platform_device_register(&avila_gpio_leds_device);
183 +}
184 +
185 +static void __init avila_gw2353_setup(void)
186 +{
187 +       platform_device_register(&avila_npeb_device);
188 +       platform_device_register(&avila_gpio_leds_device);
189 +}
190 +
191 +static void __init avila_gw2355_setup(void)
192 +{
193 +       avila_npeb_data.phy = IXP4XX_ETH_PHY_MAX_ADDR;
194 +       avila_npeb_data.phy_mask = 0x1e; /* ports 1-4 of the KS8995 switch */
195 +       platform_device_register(&avila_npeb_device);
196 +
197 +       avila_npec_data.phy = 16;
198 +       platform_device_register(&avila_npec_device);
199 +
200 +       platform_device_register(&avila_gpio_leds_device);
201 +
202 +       *IXP4XX_EXP_CS4 |= 0xbfff3c03;
203 +       avila_latch_leds[0].name = "RXD";
204 +       avila_latch_leds[1].name = "TXD";
205 +       avila_latch_leds[2].name = "POL";
206 +       avila_latch_leds[3].name = "LNK";
207 +       avila_latch_leds[4].name = "ERR";
208 +       avila_latch_leds_data.num_leds = 5;
209 +       avila_latch_leds_data.mem = 0x54000000;
210 +       platform_device_register(&avila_latch_leds_device);
211 +}
212 +
213 +static void __init avila_gw2357_setup(void)
214 +{
215 +       platform_device_register(&avila_npeb_device);
216 +
217 +       avila_gpio_leds[0].gpio = AVILA_GW23X7_LED_USER_GPIO;
218 +       platform_device_register(&avila_gpio_leds_device);
219 +
220 +       *IXP4XX_EXP_CS1 |= 0xbfff3c03;
221 +       platform_device_register(&avila_latch_leds_device);
222 +}
223 +
224 +static struct avila_board_info avila_boards[] __initdata = {
225 +       {
226 +               .model          = "GW2342",
227 +               .setup          = avila_gw2342_setup,
228 +       }, {
229 +               .model          = "GW2345",
230 +               .setup          = avila_gw2345_setup,
231 +       }, {
232 +               .model          = "GW2347",
233 +               .setup          = avila_gw2347_setup,
234 +       }, {
235 +               .model          = "GW2348",
236 +               .setup          = avila_gw2348_setup,
237 +       }, {
238 +               .model          = "GW2353",
239 +               .setup          = avila_gw2353_setup,
240 +       }, {
241 +               .model          = "GW2355",
242 +               .setup          = avila_gw2355_setup,
243 +       }, {
244 +               .model          = "GW2357",
245 +               .setup          = avila_gw2357_setup,
246 +       }
247 +};
248 +
249 +static struct avila_board_info * __init avila_find_board_info(char *model)
250 +{
251 +       int i;
252 +       model[6] = '\0';
253 +
254 +       for (i = 0; i < ARRAY_SIZE(avila_boards); i++) {
255 +               struct avila_board_info *info = &avila_boards[i];
256 +               if (strcmp(info->model, model) == 0)
257 +                       return info;
258 +       }
259 +
260 +       return NULL;
261 +}
262 +
263 +static struct memory_accessor *at24_mem_acc;
264 +
265 +static void at24_setup(struct memory_accessor *mem_acc, void *context)
266 +{
267 +       char mac_addr[ETH_ALEN];
268 +       char model[7];
269 +
270 +       at24_mem_acc = mem_acc;
271 +
272 +       /* Read MAC addresses */
273 +       if (at24_mem_acc->read(at24_mem_acc, mac_addr, 0x0, 6) == 6) {
274 +               memcpy(&avila_npeb_data.hwaddr, mac_addr, ETH_ALEN);
275 +       }
276 +       if (at24_mem_acc->read(at24_mem_acc, mac_addr, 0x6, 6) == 6) {
277 +               memcpy(&avila_npec_data.hwaddr, mac_addr, ETH_ALEN);
278 +       }
279 +
280 +       /* Read the first 6 bytes of the model number */
281 +       if (at24_mem_acc->read(at24_mem_acc, model, 0x20, 6) == 6) {
282 +               avila_info = avila_find_board_info(model);
283 +       }
284 +
285 +}
286 +
287 +static struct at24_platform_data avila_eeprom_info = {
288 +       .byte_len       = 1024,
289 +       .page_size      = 16,
290 +       .flags          = AT24_FLAG_READONLY,
291 +       .setup          = at24_setup,
292 +};
293 +
294 +static struct i2c_board_info __initdata avila_i2c_board_info[] = {
295 +       {
296 +               I2C_BOARD_INFO("ds1672", 0x68),
297 +       },
298 +       {
299 +               I2C_BOARD_INFO("ad7418", 0x28),
300 +       },
301 +       {
302 +               I2C_BOARD_INFO("24c08", 0x51),
303 +               .platform_data  = &avila_eeprom_info
304 +       },
305 +};
306 +
307  static void __init avila_init(void)
308  {
309         ixp4xx_sys_init();
310  
311 +       /*
312 +        * These devices are present on all Avila models and don't need any
313 +        * model specific setup.
314 +        */
315         avila_flash_resource.start = IXP4XX_EXP_BUS_BASE(0);
316         avila_flash_resource.end =
317                 IXP4XX_EXP_BUS_BASE(0) + ixp4xx_exp_bus_size - 1;
318 @@ -160,7 +441,28 @@ static void __init avila_init(void)
319  
320         platform_device_register(&avila_pata);
321  
322 +               i2c_register_board_info(0, avila_i2c_board_info,
323 +                               ARRAY_SIZE(avila_i2c_board_info));
324 +}
325 +
326 +static int __init avila_model_setup(void)
327 +{
328 +       if (!machine_is_avila())
329 +               return 0;
330 +
331 +       if (avila_info) {
332 +               printk(KERN_DEBUG "Running on Gateworks Avila %s\n",
333 +                                                       avila_info->model);
334 +               avila_info->setup();
335 +       } else {
336 +               printk(KERN_INFO "Unknown/missing Avila model number"
337 +                                               " -- defaults will be used\n");
338 +               avila_gw23xx_setup();
339 +       }
340 +
341 +       return 0;
342  }
343 +late_initcall(avila_model_setup);
344  
345  MACHINE_START(AVILA, "Gateworks Avila Network Platform")
346         /* Maintainer: Deepak Saxena <dsaxena@plexity.net> */