update lantiq/falcon patches
[openwrt/openwrt.git] / target / linux / lantiq / patches-2.6.32 / 110-falcon_board.patch
1 --- /dev/null
2 +++ b/arch/mips/lantiq/falcon/Kconfig
3 @@ -0,0 +1,11 @@
4 +if SOC_FALCON
5 +
6 +menu "Mips Machine"
7 +
8 +config LANTIQ_MACH_EASY98000
9 + bool "Easy98000"
10 + default y
11 +
12 +endmenu
13 +
14 +endif
15 --- /dev/null
16 +++ b/arch/mips/lantiq/falcon/Makefile
17 @@ -0,0 +1,4 @@
18 +obj-y := clk-falcon.o devices.o gpio.o prom.o sysctrl.o reset.o
19 +obj-y += softdog_vpe.o
20 +obj-$(CONFIG_LANTIQ_MACH_EASY98000) += addon-easy98000.o
21 +obj-$(CONFIG_LANTIQ_MACH_EASY98000) += mach-easy98000.o
22 --- /dev/null
23 +++ b/arch/mips/lantiq/falcon/clk-falcon.c
24 @@ -0,0 +1,48 @@
25 +/*
26 + * This program is free software; you can redistribute it and/or modify
27 + * it under the terms of the GNU General Public License as published by
28 + * the Free Software Foundation; either version 2 of the License, or
29 + * (at your option) any later version.
30 + *
31 + * Copyright (C) 2010 John Crispin <blogic@openwrt.org>
32 + */
33 +
34 +#include <linux/io.h>
35 +#include <linux/module.h>
36 +#include <linux/init.h>
37 +
38 +#include <asm/time.h>
39 +#include <asm/irq.h>
40 +#include <asm/div64.h>
41 +
42 +#include <lantiq_soc.h>
43 +
44 +#include <falcon.h>
45 +#include <gpon_reg_base.h>
46 +#include <sys1_reg.h>
47 +
48 +static struct gpon_reg_sys1 * const pSYS1 = (struct gpon_reg_sys1 *)GPON_SYS1_BASE;
49 +
50 +unsigned int
51 +ltq_get_io_region_clock(void)
52 +{
53 + return 200000000; /* 200 MHz */
54 +}
55 +EXPORT_SYMBOL(ltq_get_io_region_clock);
56 +
57 +unsigned int
58 +ltq_get_cpu_hz(void)
59 +{
60 + if ((ltq_r32(&pSYS1->cpu0cc) & CPU0CC_CPUDIV) == CPU0CC_CPUDIV_SELFHALF)
61 + return 200000000; /* 200 MHz */
62 + else
63 + return 400000000; /* 400 MHz */
64 +}
65 +EXPORT_SYMBOL(ltq_get_cpu_hz);
66 +
67 +unsigned int
68 +ltq_get_fpi_hz(void)
69 +{
70 + return 100000000;
71 +}
72 +EXPORT_SYMBOL(ltq_get_fpi_hz);
73 --- /dev/null
74 +++ b/arch/mips/lantiq/falcon/devices.c
75 @@ -0,0 +1,254 @@
76 +#include <linux/init.h>
77 +#include <linux/module.h>
78 +#include <linux/types.h>
79 +#include <linux/string.h>
80 +#include <linux/mtd/physmap.h>
81 +#include <linux/kernel.h>
82 +#include <linux/reboot.h>
83 +#include <linux/platform_device.h>
84 +#include <linux/leds.h>
85 +#include <linux/etherdevice.h>
86 +#include <linux/reboot.h>
87 +#include <linux/time.h>
88 +#include <linux/io.h>
89 +#include <linux/gpio.h>
90 +#include <linux/leds.h>
91 +#include <linux/spi/spi.h>
92 +#include <linux/mtd/nand.h>
93 +
94 +#include <asm/bootinfo.h>
95 +#include <asm/irq.h>
96 +
97 +#include <lantiq.h>
98 +
99 +#include <falcon/falcon_irq.h>
100 +#include <falcon/gpon_reg_base.h>
101 +#include <falcon/ebu_reg.h>
102 +#include <falcon/sys1_reg.h>
103 +#include <falcon/sys_eth_reg.h>
104 +
105 +#include <falcon/sysctrl.h>
106 +
107 +#include "devices.h"
108 +
109 +unsigned char ltq_ethaddr[6] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
110 +EXPORT_SYMBOL(ltq_ethaddr);
111 +
112 +static int __init
113 +falcon_set_ethaddr(char *str)
114 +{
115 + sscanf(str, "%02hhx:%02hhx:%02hhx:%02hhx:%02hhx:%02hhx",
116 + &ltq_ethaddr[0], &ltq_ethaddr[1], &ltq_ethaddr[2],
117 + &ltq_ethaddr[3], &ltq_ethaddr[4], &ltq_ethaddr[5]);
118 + return 0;
119 +}
120 +__setup("ethaddr=", falcon_set_ethaddr);
121 +
122 +/* asc ports */
123 +static struct resource falcon_asc0_resources[] =
124 +{
125 + MEM_RES("asc0",GPON_ASC0_BASE,GPON_ASC0_END),
126 + IRQ_RES("tx",INT_NUM_IM3_IRL0),
127 + IRQ_RES("rx",INT_NUM_IM3_IRL0+1),
128 + IRQ_RES("err",INT_NUM_IM3_IRL0+2),
129 +};
130 +
131 +static struct resource falcon_asc1_resources[] =
132 +{
133 + MEM_RES("asc1",GPON_ASC1_BASE,GPON_ASC1_END),
134 + IRQ_RES("tx",INT_NUM_IM3_IRL0+8),
135 + IRQ_RES("rx",INT_NUM_IM3_IRL0+9),
136 + IRQ_RES("err",INT_NUM_IM3_IRL0+10),
137 +};
138 +
139 +void __init falcon_register_asc(int port)
140 +{
141 + switch (port) {
142 + case 0:
143 + platform_device_register_simple("ltq_asc", 0,
144 + falcon_asc0_resources, ARRAY_SIZE(falcon_asc0_resources));
145 + break;
146 + case 1:
147 + platform_device_register_simple("ltq_asc", 1,
148 + falcon_asc1_resources, ARRAY_SIZE(falcon_asc1_resources));
149 + break;
150 + default:
151 + break;
152 + }
153 +}
154 +
155 +/* nor flash */
156 +static struct resource ltq_nor_resource =
157 + MEM_RES("nor",LTQ_FLASH_START,LTQ_FLASH_START + LTQ_FLASH_MAX - 1);
158 +
159 +static struct platform_device ltq_nor = {
160 + .name = "ltq_nor",
161 + .resource = &ltq_nor_resource,
162 + .num_resources = 1,
163 +};
164 +
165 +void __init falcon_register_nor(struct physmap_flash_data *data)
166 +{
167 + ltq_nor.dev.platform_data = data;
168 + platform_device_register(&ltq_nor);
169 +}
170 +
171 +/* spi flash */
172 +static struct resource ltq_spi_resources[] = {
173 + MEM_RES("ebu", GPON_EBU_BASE, GPON_EBU_END),
174 + MEM_RES("sys1", GPON_SYS1_BASE, GPON_SYS1_END)
175 +};
176 +
177 +static struct platform_device ltq_spi = {
178 + .name = "falcon_spi",
179 + .resource = ltq_spi_resources,
180 + .num_resources = ARRAY_SIZE(ltq_spi_resources)
181 +};
182 +
183 +void __init falcon_register_spi_flash(struct spi_board_info *data)
184 +{
185 + spi_register_board_info(data, 1);
186 + platform_device_register(&ltq_spi);
187 +}
188 +
189 +/* nand flash */
190 +static struct gpon_reg_ebu __iomem *membase_ebu;
191 +static const char *part_probes[] = { "cmdlinepart", NULL };
192 +
193 +static int falcon_nand_ready(struct mtd_info *mtd)
194 +{
195 + u32 modcon = __raw_readl(&membase_ebu->modcon);
196 +
197 + return (((modcon & (MODCON_STS|MODCON_STSEDGE)) ==
198 + (MODCON_STS|MODCON_STSEDGE)));
199 +}
200 +
201 +/* address lines used for NAND control signals */
202 +#define NAND_ADDR_ALE (1<<16)
203 +#define NAND_ADDR_CLE (1<<17)
204 +
205 +static void falcon_hwcontrol(struct mtd_info *mtd, int cmd, unsigned int ctrl)
206 +{
207 + struct nand_chip *this = mtd->priv;
208 + unsigned long nandaddr = (unsigned long) this->IO_ADDR_W;
209 +
210 + if (ctrl & NAND_CTRL_CHANGE) {
211 + nandaddr &= ~(NAND_ADDR_ALE | NAND_ADDR_CLE);
212 +
213 + if (ctrl & NAND_CLE)
214 + nandaddr |= NAND_ADDR_CLE;
215 + if (ctrl & NAND_ALE)
216 + nandaddr |= NAND_ADDR_ALE;
217 +
218 + this->IO_ADDR_W = (void __iomem *) nandaddr;
219 + }
220 +
221 + if (cmd != NAND_CMD_NONE)
222 + writeb(cmd, this->IO_ADDR_W);
223 +}
224 +
225 +static struct platform_nand_data falcon_flash_nand_data = {
226 + .chip = {
227 + .nr_chips = 1,
228 + .chip_delay = 25,
229 + .part_probe_types = part_probes,
230 + },
231 + .ctrl = {
232 + .cmd_ctrl = falcon_hwcontrol,
233 + .dev_ready = falcon_nand_ready,
234 + }
235 +};
236 +
237 +static struct resource ltq_nand_resources[] = {
238 + MEM_RES("nand", LTQ_FLASH_START, LTQ_FLASH_START + LTQ_FLASH_MAX - 1),
239 + MEM_RES("ebu", GPON_EBU_BASE, GPON_EBU_END),
240 +};
241 +
242 +static struct platform_device ltq_flash_nand = {
243 + .name = "gen_nand",
244 + .id = -1,
245 + .num_resources = ARRAY_SIZE(ltq_nand_resources),
246 + .resource = ltq_nand_resources,
247 + .dev = {
248 + .platform_data = &falcon_flash_nand_data,
249 + },
250 +};
251 +
252 +void __init falcon_register_nand(void)
253 +{
254 + membase_ebu = ioremap_nocache(ltq_nand_resources[1].start,
255 + resource_size(&ltq_nand_resources[1]));
256 +
257 + if (membase_ebu)
258 + platform_device_register(&ltq_flash_nand);
259 +}
260 +
261 +/* watchdog */
262 +static struct resource falcon_wdt_resource =
263 + MEM_RES("watchdog",GPON_WDT_BASE,GPON_WDT_END);
264 +
265 +void __init falcon_register_wdt(void)
266 +{
267 + platform_device_register_simple("ltq_wdt", 0, &falcon_wdt_resource, 1);
268 +}
269 +
270 +/* gpio */
271 +#define DECLARE_GPIO_RES(port) \
272 +static struct resource falcon_gpio ## port ## _resources[] = { \
273 + MEM_RES("gpio"#port,GPON_GPIO ## port ## _BASE,GPON_GPIO ## port ## _END), \
274 + MEM_RES("padctrl"#port,GPON_PADCTRL ## port ## _BASE,GPON_PADCTRL ## port ## _END), \
275 + IRQ_RES("gpio_mux"#port,FALCON_IRQ_GPIO_P ## port ) \
276 +}
277 +DECLARE_GPIO_RES(0);
278 +DECLARE_GPIO_RES(1);
279 +DECLARE_GPIO_RES(2);
280 +#ifdef REGISTER_ALL_GPIO_PORTS
281 +#if NR_IRQS < 328
282 +#error NR_IRQS to low for all gpio irqs
283 +#endif
284 +DECLARE_GPIO_RES(3);
285 +DECLARE_GPIO_RES(4);
286 +#endif
287 +
288 +void __init falcon_register_gpio(void)
289 +{
290 + platform_device_register_simple("falcon_gpio", 0,
291 + falcon_gpio0_resources, ARRAY_SIZE(falcon_gpio0_resources));
292 + platform_device_register_simple("falcon_gpio", 1,
293 + falcon_gpio1_resources, ARRAY_SIZE(falcon_gpio1_resources));
294 + platform_device_register_simple("falcon_gpio", 2,
295 + falcon_gpio2_resources, ARRAY_SIZE(falcon_gpio2_resources));
296 + sys1_hw_activate(ACTS_PADCTRL1 | ACTS_P1);
297 + sys_eth_hw_activate(SYS_ETH_ACTS_PADCTRL0 | SYS_ETH_ACTS_PADCTRL2 |
298 + SYS_ETH_ACTS_P0 | SYS_ETH_ACTS_P2);
299 +
300 +#ifdef REGISTER_ALL_GPIO_PORTS
301 + /* optional gpio ports: not registered,
302 + as the pins are EBU specific and always used by linux */
303 + platform_device_register_simple("falcon_gpio", 3,
304 + falcon_gpio3_resources, ARRAY_SIZE(falcon_gpio3_resources));
305 + platform_device_register_simple("falcon_gpio", 4,
306 + falcon_gpio4_resources, ARRAY_SIZE(falcon_gpio4_resources));
307 + sys1_hw_activate(ACTS_PADCTRL3 | ACTS_PADCTRL4 | ACTS_P3 | ACTS_P4);
308 +#endif
309 +}
310 +
311 +static struct resource falcon_i2c_resources[] = {
312 + MEM_RES("i2c", GPON_I2C_BASE,GPON_I2C_END),
313 + IRQ_RES("i2c_lb", FALCON_IRQ_I2C_LBREQ),
314 + IRQ_RES("i2c_b", FALCON_IRQ_I2C_BREQ),
315 + IRQ_RES("i2c_err", FALCON_IRQ_I2C_I2C_ERR),
316 + IRQ_RES("i2c_p", FALCON_IRQ_I2C_I2C_P),
317 +};
318 +
319 +void __init falcon_register_i2c(void)
320 +{
321 + platform_device_register_simple("i2c-falcon", 0,
322 + falcon_i2c_resources, ARRAY_SIZE(falcon_i2c_resources));
323 + sys1_hw_activate(ACTS_I2C_ACT);
324 +}
325 +
326 +void __init falcon_register_crypto(void)
327 +{
328 + platform_device_register_simple("ltq_falcon_deu", 0, NULL, 0);
329 +}
330 --- /dev/null
331 +++ b/arch/mips/lantiq/falcon/devices.h
332 @@ -0,0 +1,22 @@
333 +#ifndef _FALCON_DEVICES_H__
334 +#define _FALCON_DEVICES_H__
335 +
336 +#include <linux/mtd/physmap.h>
337 +#include <linux/spi/spi.h>
338 +#include <linux/spi/flash.h>
339 +
340 +extern void __init falcon_register_asc(int port);
341 +extern void __init falcon_register_i2c(void);
342 +extern void __init falcon_register_spi_flash(struct spi_board_info *data);
343 +extern void __init falcon_register_gpio(void);
344 +extern void __init falcon_register_nor(struct physmap_flash_data *data);
345 +extern void __init falcon_register_nand(void);
346 +extern void __init falcon_register_wdt(void);
347 +extern void __init falcon_register_crypto(void);
348 +
349 +#define IRQ_RES(resname,irq) {.name=resname,.start=(irq),.flags=IORESOURCE_IRQ}
350 +#define MEM_RES(resname,adr_start,adr_end) \
351 + { .name=resname, .flags=IORESOURCE_MEM, \
352 + .start=((adr_start)&~KSEG1),.end=((adr_end)&~KSEG1) }
353 +
354 +#endif
355 --- /dev/null
356 +++ b/arch/mips/lantiq/falcon/prom.c
357 @@ -0,0 +1,52 @@
358 +/*
359 + * This program is free software; you can redistribute it and/or modify
360 + * it under the terms of the GNU General Public License as published by
361 + * the Free Software Foundation; either version 2 of the License, or
362 + * (at your option) any later version.
363 + *
364 + * Copyright (C) 2010 John Crispin <blogic@openwrt.org>
365 + */
366 +
367 +#include <linux/module.h>
368 +#include <linux/clk.h>
369 +#include <asm/bootinfo.h>
370 +#include <asm/time.h>
371 +
372 +#include <lantiq_soc.h>
373 +
374 +#include <falcon.h>
375 +
376 +#include <falcon/gpon_reg_base.h>
377 +#include <falcon/status_reg.h>
378 +#include <falcon/sys1_reg.h>
379 +
380 +#include "../prom.h"
381 +
382 +static struct gpon_reg_status * const pSTATUS = (struct gpon_reg_status *)GPON_STATUS_BASE;
383 +
384 +#define SOC_FALCON "Falcon"
385 +
386 +void __init
387 +ltq_soc_setup(void)
388 +{
389 + /* not used */
390 +}
391 +
392 +void __init
393 +ltq_soc_detect(struct ltq_soc_info *i)
394 +{
395 + i->partnum = (ltq_r32(&pSTATUS->chipid) & STATUS_CHIPID_PARTNR_MASK) >> STATUS_CHIPID_PARTNR_OFFSET;
396 + i->rev = (ltq_r32(&pSTATUS->chipid) & STATUS_CHIPID_VERSION_MASK) >> STATUS_CHIPID_VERSION_OFFSET;
397 + switch (i->partnum)
398 + {
399 + case SOC_ID_FALCON:
400 + i->name = SOC_FALCON;
401 + i->type = SOC_TYPE_FALCON;
402 + break;
403 +
404 + default:
405 + printk(KERN_ERR "unknown partnum : 0x%08X\n", i->partnum);
406 + while(1) { };
407 + break;
408 + }
409 +}
410 --- /dev/null
411 +++ b/arch/mips/lantiq/falcon/sysctrl.c
412 @@ -0,0 +1,380 @@
413 +/*
414 + * This program is free software; you can redistribute it and/or
415 + * modify it under the terms of the GNU General Public License as
416 + * published by the Free Software Foundation; either version 2 of
417 + * the License, or (at your option) any later version.
418 + *
419 + * This program is distributed in the hope that it will be useful,
420 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
421 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
422 + * GNU General Public License for more details.
423 + *
424 + * You should have received a copy of the GNU General Public License
425 + * along with this program; if not, write to the Free Software
426 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
427 + * MA 02111-1307 USA
428 + *
429 + * Copyright (C) 2010 Thomas Langer, Lantiq Deutschland
430 + */
431 +
432 +#include <linux/cpu.h>
433 +#include <linux/init.h>
434 +#include <linux/kernel.h>
435 +#include <linux/pm.h>
436 +#include <linux/io.h>
437 +#include <linux/ioport.h>
438 +#include <linux/clk.h>
439 +#include <asm/reboot.h>
440 +
441 +#include <falcon/gpon_reg_base.h>
442 +#include <falcon/status_reg.h>
443 +#include <falcon/sys1_reg.h>
444 +#include <falcon/sys_eth_reg.h>
445 +#include <falcon/sys_gpe_reg.h>
446 +
447 +#include <falcon/sysctrl.h>
448 +
449 +/* mapping to linux hw-accessor routines */
450 +#define reg_r32(reg) __raw_readl(reg)
451 +#define reg_w32(val, reg) __raw_writel(val, reg)
452 +#define reg_w32_mask(clear, set, reg) reg_w32((reg_r32(reg) & ~(clear)) | (set), reg)
453 +
454 +static struct gpon_reg_sys1 * const sys1 = (struct gpon_reg_sys1 *)GPON_SYS1_BASE;
455 +static struct gpon_reg_sys_eth * const sys_eth = (struct gpon_reg_sys_eth *)GPON_SYS_ETH_BASE;
456 +static struct gpon_reg_sys_gpe * const sys_gpe = (struct gpon_reg_sys_gpe *)GPON_SYS_GPE_BASE;
457 +static struct gpon_reg_status * const status = (struct gpon_reg_status *)GPON_STATUS_BASE;
458 +
459 +/**
460 + * Activate the selected module(s)
461 + * Enables the clock of the module and activates the module itself.
462 + *
463 + * \param[in] mask bitmask of module(s), as for registers SYS1.ACT
464 + * \return void
465 + */
466 +void sys1_hw_activate(u32 mask)
467 +{
468 + sys1_w32(mask, clken);
469 + sys1_w32(mask, act);
470 +
471 + while ( (sys1_r32(acts) & mask) != mask) {
472 + /*NOP;*/
473 + };
474 +}
475 +EXPORT_SYMBOL(sys1_hw_activate);
476 +
477 +/**
478 + * Deactivate the selected module(s)
479 + * Disables the clock of the module and deactivates the module itself.
480 + *
481 + * \param[in] mask bitmask of module(s), as for registers SYS1.DEACT
482 + * \return void
483 + */
484 +void sys1_hw_deactivate(u32 mask)
485 +{
486 + sys1_w32(mask, clkclr);
487 + sys1_w32(mask, deact);
488 +
489 + while ( (sys1_r32(acts) & mask) != 0) {
490 + /*NOP;*/
491 + };
492 +}
493 +EXPORT_SYMBOL(sys1_hw_deactivate);
494 +
495 +/**
496 + * Clock enable for the selected module(s)
497 + * Enables the clock of the module.
498 + *
499 + * \param[in] mask bitmask of module(s), as for registers SYS1.CLKEN
500 + * \return void
501 + */
502 +void sys1_hw_clk_enable(u32 mask)
503 +{
504 + sys1_w32(mask, clken);
505 +
506 + while ( (sys1_r32(clks) & mask) != mask) {
507 + /*NOP;*/
508 + };
509 +}
510 +EXPORT_SYMBOL(sys1_hw_clk_enable);
511 +
512 +/**
513 + * Clock disable for the selected module(s)
514 + * disables the clock of the module.
515 + *
516 + * \param[in] mask bitmask of module(s), as for registers SYS1.CLKCLR
517 + * \return void
518 + */
519 +void sys1_hw_clk_disable(u32 mask)
520 +{
521 + sys1_w32(mask, clkclr);
522 +
523 + while ( (sys1_r32(clks) & mask) != 0) {
524 + /*NOP;*/
525 + };
526 +}
527 +EXPORT_SYMBOL(sys1_hw_clk_disable);
528 +
529 +/**
530 + * Reboots the selected module(s)
531 + * Triggers the reboot of the module.
532 + *
533 + * \param[in] mask bitmask of module(s), as for registers SYS1.RBT
534 + * \return void
535 + */
536 +void sys1_hw_activate_or_reboot(u32 mask)
537 +{
538 + u32 acts = sys1_r32(acts);
539 + /* is not already active? */
540 + if ((~acts & mask) != 0)
541 + sys1_hw_activate(~acts & mask);
542 + sys1_w32(acts & mask, rbt);
543 + while ( (sys1_r32(acts) & mask) != mask) {
544 + /*NOP;*/
545 + };
546 +}
547 +EXPORT_SYMBOL(sys1_hw_activate_or_reboot);
548 +
549 +/**
550 + * Activate the selected module(s)
551 + * Enables the clock of the module and activates the module itself.
552 + *
553 + * \param[in] mask bitmask of module(s), as for registers SYS_ETH.ACT
554 + * \return void
555 + */
556 +void sys_eth_hw_activate(u32 mask)
557 +{
558 + sys_eth_w32(mask, clken);
559 + sys_eth_w32(mask, act);
560 +
561 + while ( (sys_eth_r32(acts) & mask) != mask) {
562 + /*NOP;*/
563 + };
564 +}
565 +EXPORT_SYMBOL(sys_eth_hw_activate);
566 +
567 +/**
568 + * Deactivate the selected module(s)
569 + * Disables the clock of the module and deactivates the module itself.
570 + *
571 + * \param[in] mask bitmask of module(s), as for registers SYS_ETH.DEACT
572 + * \return void
573 + */
574 +void sys_eth_hw_deactivate(u32 mask)
575 +{
576 + sys_eth_w32(mask, clkclr);
577 + sys_eth_w32(mask, deact);
578 +
579 + while ( (sys_eth_r32(acts) & mask) != 0) {
580 + /*NOP;*/
581 + };
582 +}
583 +EXPORT_SYMBOL(sys_eth_hw_deactivate);
584 +
585 +/**
586 + * Clock enable for the selected module(s)
587 + * Enables the clock of the module.
588 + *
589 + * \param[in] mask bitmask of module(s), as for registers SYS_ETH.CLKEN
590 + * \return void
591 + */
592 +void sys_eth_hw_clk_enable(u32 mask)
593 +{
594 + sys_eth_w32(mask, clken);
595 +
596 + while ( (sys_eth_r32(clks) & mask) != mask) {
597 + /*NOP;*/
598 + };
599 +}
600 +EXPORT_SYMBOL(sys_eth_hw_clk_enable);
601 +
602 +/**
603 + * Clock disable for the selected module(s)
604 + * disables the clock of the module.
605 + *
606 + * \param[in] mask bitmask of module(s), as for registers SYS_ETH.CLKCLR
607 + * \return void
608 + */
609 +void sys_eth_hw_clk_disable(u32 mask)
610 +{
611 + sys_eth_w32(mask, clkclr);
612 +
613 + while ( (sys_eth_r32(clks) & mask) != 0) {
614 + /*NOP;*/
615 + };
616 +}
617 +EXPORT_SYMBOL(sys_eth_hw_clk_disable);
618 +
619 +/**
620 + * Reboots the selected module(s)
621 + * Triggers the reboot of the module.
622 + *
623 + * \param[in] mask bitmask of module(s), as for registers SYS_ETH.RBT
624 + * \return void
625 + */
626 +void sys_eth_hw_activate_or_reboot(u32 mask)
627 +{
628 + u32 acts = sys_eth_r32(acts);
629 + /* is not already active? */
630 + if ((~acts & mask) != 0)
631 + sys_eth_hw_activate(~acts & mask);
632 + sys_eth_w32(acts & mask, rbt);
633 + while ( (sys_eth_r32(acts) & mask) != mask) {
634 + /*NOP;*/
635 + };
636 +}
637 +EXPORT_SYMBOL(sys_eth_hw_activate_or_reboot);
638 +
639 +static int gpe_clk_is_enabled(void)
640 +{
641 + u32 rd_data;
642 +
643 + rd_data = sys1_r32(infrac);
644 + if (rd_data & (1<<(INFRAC_GP_OFFSET+1)))
645 + return 1;
646 + return 0;
647 +}
648 +
649 +static void enable_gpe_clk(void)
650 +{
651 + u32 aeFreq;
652 + u32 rd_data;
653 + u32 rd_data_to_keep;
654 + int i;
655 +
656 + if (gpe_clk_is_enabled())
657 + /* clock already active, no need to change here */
658 + return;
659 +
660 + aeFreq = (status_r32(config) & STATUS_CONFIG_GPEFREQ_MASK) >> STATUS_CONFIG_GPEFREQ_OFFSET;
661 + if (aeFreq == 0)
662 + aeFreq = 1; /* use 625MHz on invalid value 0 */
663 + rd_data = sys1_r32(infrac);
664 + /* clear gpe-fsel and enable bits */
665 + rd_data_to_keep = rd_data & ~(7<<(INFRAC_GP_OFFSET+1));
666 +
667 + /* set new fsel */
668 + sys1_w32(rd_data_to_keep | (aeFreq<<(INFRAC_GP_OFFSET+2)), infrac);
669 +
670 + for (i = 0; i <10; i++) /* wait 10 cycles */
671 + {}
672 +
673 + /* keep new fsel and enable */
674 + sys1_w32(rd_data_to_keep | (aeFreq<<(INFRAC_GP_OFFSET+2)) |
675 + (1<<(INFRAC_GP_OFFSET+1)), infrac);
676 + for (i = 0; i <100; i++) /* wait 100 cycles */
677 + {}
678 +}
679 +
680 +/**
681 + * Activate the selected module(s)
682 + * Enables the clock of the module and activates the module itself.
683 + *
684 + * \param[in] mask bitmask of module(s), as for registers SYS_GPE.ACT
685 + * \return void
686 + */
687 +void sys_gpe_hw_activate(u32 mask)
688 +{
689 + enable_gpe_clk();
690 + sys_gpe_w32(mask, clken);
691 + sys_gpe_w32(mask, act);
692 +
693 + while ( (sys_gpe_r32(acts) & mask) != mask) {
694 + /*NOP;*/
695 + };
696 +}
697 +EXPORT_SYMBOL(sys_gpe_hw_activate);
698 +
699 +/**
700 + * Deactivate the selected module(s)
701 + * Disables the clock of the module and deactivates the module itself.
702 + *
703 + * \param[in] mask bitmask of module(s), as for registers SYS_GPE.DEACT
704 + * \return void
705 + */
706 +void sys_gpe_hw_deactivate(u32 mask)
707 +{
708 + enable_gpe_clk();
709 + sys_gpe_w32(mask, clkclr);
710 + sys_gpe_w32(mask, deact);
711 +
712 + while ( (sys_gpe_r32(acts) & mask) != 0) {
713 + /*NOP;*/
714 + };
715 +}
716 +EXPORT_SYMBOL(sys_gpe_hw_deactivate);
717 +
718 +/**
719 + * Clock enable for the selected module(s)
720 + * Enables the clock of the module.
721 + *
722 + * \param[in] mask bitmask of module(s), as for registers SYS_GPE.CLKEN
723 + * \return void
724 + */
725 +void sys_gpe_hw_clk_enable(u32 mask)
726 +{
727 + enable_gpe_clk();
728 + sys_gpe_w32(mask, clken);
729 +
730 + while ( (sys_gpe_r32(clks) & mask) != mask) {
731 + /*NOP;*/
732 + };
733 +}
734 +EXPORT_SYMBOL(sys_gpe_hw_clk_enable);
735 +
736 +/**
737 + * Clock disable for the selected module(s)
738 + * disables the clock of the module.
739 + *
740 + * \param[in] mask bitmask of module(s), as for registers SYS_GPE.CLKCLR
741 + * \return void
742 + */
743 +void sys_gpe_hw_clk_disable(u32 mask)
744 +{
745 + enable_gpe_clk();
746 + sys_gpe_w32(mask, clkclr);
747 +
748 + while ( (sys_gpe_r32(clks) & mask) != 0) {
749 + /*NOP;*/
750 + };
751 +}
752 +EXPORT_SYMBOL(sys_gpe_hw_clk_disable);
753 +
754 +/**
755 + * Reboots the selected module(s)
756 + * Triggers the reboot of the module.
757 + *
758 + * \param[in] mask bitmask of module(s), as for registers SYS_GPE.RBT
759 + * \return void
760 + */
761 +void sys_gpe_hw_activate_or_reboot(u32 mask)
762 +{
763 + u32 acts;
764 + enable_gpe_clk();
765 + acts = sys_gpe_r32(acts);
766 + /* is not already active? */
767 + if ((~acts & mask) != 0)
768 + sys_gpe_hw_activate(~acts & mask);
769 + sys_gpe_w32(acts & mask, rbt);
770 + while ( (sys_gpe_r32(acts) & mask) != mask) {
771 + /*NOP;*/
772 + };
773 +}
774 +EXPORT_SYMBOL(sys_gpe_hw_activate_or_reboot);
775 +
776 +/**
777 + * Retrieve activation status of the selected hardware module(s)
778 + *
779 + * \param[in] mask bitmask of module(s), as for registers SYS_GPE.RBT
780 + * \return int 1 - if hardware module(s) is activated (including clock)
781 + */
782 + int sys_gpe_hw_is_activated(u32 mask)
783 +{
784 + if (gpe_clk_is_enabled() == 0)
785 + return 0;
786 +
787 + if ((sys_gpe_r32(clks) & mask) != mask)
788 + return 0;
789 +
790 + return ((sys_gpe_r32(acts) & mask) == mask);
791 +}
792 +EXPORT_SYMBOL(sys_gpe_hw_is_activated);
793 --- /dev/null
794 +++ b/arch/mips/lantiq/falcon/gpio.c
795 @@ -0,0 +1,463 @@
796 +/*
797 + * This program is free software; you can redistribute it and/or modify
798 + * it under the terms of the GNU General Public License as published by
799 + * the Free Software Foundation; either version 2 of the License, or
800 + * (at your option) any later version.
801 + *
802 + * This program is distributed in the hope that it will be useful,
803 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
804 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
805 + * GNU General Public License for more details.
806 + *
807 + * You should have received a copy of the GNU General Public License
808 + * along with this program; if not, write to the Free Software
809 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
810 + *
811 + * Copyright (C) 2010 Thomas Langer, Lantiq Deutschland
812 + */
813 +
814 +/**
815 + TODO:
816 + - add locking?
817 + - provide mask of available pins per platform_data
818 +*/
819 +
820 +#include <linux/module.h>
821 +#include <linux/types.h>
822 +#include <linux/errno.h>
823 +#include <linux/init.h>
824 +#include <linux/seq_file.h>
825 +#include <linux/platform_device.h>
826 +#include <linux/uaccess.h>
827 +#include <linux/gpio.h>
828 +#include <linux/irq.h>
829 +#include <linux/interrupt.h>
830 +#include <linux/slab.h>
831 +
832 +#include <falcon.h>
833 +#include <falcon/falcon_irq.h>
834 +
835 +#include <linux/version.h>
836 +#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,35))
837 +#define for_each_set_bit for_each_bit
838 +#endif
839 +
840 +#define gpio_r32(reg) __raw_readl(reg)
841 +#define gpio_w32(val, reg) __raw_writel(val, reg)
842 +#define gpio_w32_mask(clear, set, reg) gpio_w32((gpio_r32(reg) & ~(clear)) | (set), reg)
843 +
844 +
845 +/** register structure for padctrl
846 + (mainly needed for mux control) */
847 +typedef struct gpon_padctrl_s
848 +{
849 + /** Multiplexer Control Register
850 + The value 0 (the reset-value) is always the default function corresponding to the pad's name. The value 1 selects always the GPIO functionality (if available). */
851 + unsigned int muxc[32];
852 + /** Pull Up Enable Register */
853 + unsigned int puen; /* 0x00000080 */
854 + /** Pull Down Enable Register */
855 + unsigned int pden; /* 0x00000084 */
856 + /** Slew Rate Control Register */
857 + unsigned int src; /* 0x00000088 */
858 + /** Drive Current Control Register */
859 + unsigned int dcc; /* 0x0000008C */
860 + /** Reserved */
861 + unsigned int res_0[24]; /* 0x00000090 */
862 + /** Pad Control Availability Register */
863 + unsigned int avail; /* 0x000000F0 */
864 +} gpon_padctrl0_t;
865 +
866 +/** register structure for gpio port */
867 +typedef struct gpon_gpio_s
868 +{
869 + /** Data Output Register
870 + Via this register the output values of the different bits can be set if they are switched as outputs. */
871 + unsigned int out; /* 0x00000000 */
872 + /** Data Input Register
873 + Via this register the input values of the different bits can be observed. */
874 + unsigned int in; /* 0x00000004 */
875 + /** Direction Register
876 + Via this register the input direction of the different bits can be determined. */
877 + unsigned int dir; /* 0x00000008 */
878 + /** Reserved */
879 + unsigned int res_0[3]; /* 0x0000000C */
880 + /** External Interrupt Control Register 0 */
881 + unsigned int exintcr0; /* 0x00000018 */
882 + /** External Interrupt Control Register 1 */
883 + unsigned int exintcr1; /* 0x0000001C */
884 + /** IRN Capture Register
885 + This register shows the currently active interrupt events masked with the corresponding enable bits of the IRNEN register. The interrupts can be acknowledged by a write operation. */
886 + unsigned int irncr; /* 0x00000020 */
887 + /** IRN Interrupt Control Register
888 + A write operation directly effects the interrupts. This can be used to trigger events under software control for testing purposes. A read operation returns the unmasked interrupt events. */
889 + unsigned int irnicr; /* 0x00000024 */
890 + /** IRN Interrupt Enable Register
891 + This register contains the enable (or mask) bits for the interrupts. Disabled interrupts are not visible in the IRNCR register and are not signalled via the interrupt line towards the controller. */
892 + unsigned int irnen; /* 0x00000028 */
893 + /** IRN Interrupt Configuration Register
894 + Configures the interrupts bitwise to be edge-senstivie or level-sensitive. */
895 + unsigned int irncfg; /* 0x0000002C */
896 + /** IRN Interrupt Enable Set Register
897 + The corresponding bit in the IRNEN register can be set with an atomic access. */
898 + unsigned int irnenset; /* 0x00000030 */
899 + /** IRN Interrupt Enable Clear Register
900 + The corresponding bit in the IRNEN register can be cleared with an atomic access. */
901 + unsigned int irnenclr; /* 0x00000034 */
902 + /** Reserved */
903 + unsigned int res_1[2]; /* 0x00000038 */
904 + /** Output Set Register
905 + This register can be used to set certain bits within the OUT register without touching the other bits. */
906 + unsigned int outset; /* 0x00000040 */
907 + /** Output Clear Register
908 + This register can be used to clear certain bits within the OUT register without touching the other bits. */
909 + unsigned int outclr; /* 0x00000044 */
910 + /** Direction Set Register
911 + This register can be used to set certain bits within the DIR register without touching the other bits. */
912 + unsigned int dirset; /* 0x00000048 */
913 + /** Direction Clear Register
914 + This register can be used to clear certain bits within the DIR register without touching the other bits. */
915 + unsigned int dirclr; /* 0x0000004C */
916 +} gpon_gpio_t;
917 +
918 +struct falcon_gpio_port {
919 + struct gpio_chip gpio_chip;
920 + gpon_padctrl0_t __iomem *pad;
921 + gpon_gpio_t __iomem *port;
922 + struct resource *pad_req; /* resources requested */
923 + struct resource *port_req;
924 + unsigned int irq_base;
925 + unsigned int chained_irq;
926 +};
927 +
928 +static int gpio_exported = 0;
929 +static int __init gpio_export_setup(char *str)
930 +{
931 + get_option(&str, &gpio_exported);
932 + return 1;
933 +}
934 +__setup("gpio_exported=", gpio_export_setup);
935 +
936 +static inline struct falcon_gpio_port *to_falcon_gpio_port(struct gpio_chip *chip)
937 +{
938 + return container_of(chip, struct falcon_gpio_port, gpio_chip);
939 +}
940 +
941 +static int falcon_gpio_direction_input(struct gpio_chip *chip, unsigned int offset)
942 +{
943 + struct falcon_gpio_port *gpio_port = to_falcon_gpio_port(chip);
944 + gpio_w32(1<<offset, &gpio_port->port->dirclr);
945 + return 0;
946 +}
947 +
948 +static int falcon_gpio_direction_output(struct gpio_chip *chip, unsigned int offset, int value)
949 +{
950 + struct falcon_gpio_port *gpio_port = to_falcon_gpio_port(chip);
951 + gpio_w32(1<<offset, &gpio_port->port->dirset);
952 + return 0;
953 +}
954 +
955 +static void falcon_gpio_set(struct gpio_chip *chip, unsigned int offset, int value)
956 +{
957 + struct falcon_gpio_port *gpio_port = to_falcon_gpio_port(chip);
958 + if (value)
959 + gpio_w32(1<<offset, &gpio_port->port->outset);
960 + else
961 + gpio_w32(1<<offset, &gpio_port->port->outclr);
962 +}
963 +
964 +static int falcon_gpio_get(struct gpio_chip *chip, unsigned int offset)
965 +{
966 + struct falcon_gpio_port *gpio_port = to_falcon_gpio_port(chip);
967 + if ((gpio_r32(&gpio_port->port->dir) >> offset) & 1)
968 + return (gpio_r32(&gpio_port->port->out) >> offset) & 1;
969 + else
970 + return (gpio_r32(&gpio_port->port->in) >> offset) & 1;
971 +}
972 +
973 +static int falcon_gpio_request(struct gpio_chip *chip, unsigned offset)
974 +{
975 + struct falcon_gpio_port *gpio_port = to_falcon_gpio_port(chip);
976 + if ( (gpio_r32(&gpio_port->pad->avail) >> offset) & 1) {
977 + if (gpio_r32(&gpio_port->pad->muxc[offset]) > 1)
978 + return -EBUSY;
979 + /* switch on gpio function */
980 + gpio_w32(1, &gpio_port->pad->muxc[offset]);
981 + return 0;
982 + }
983 +
984 + return -ENODEV;
985 +}
986 +
987 +static void falcon_gpio_free(struct gpio_chip *chip, unsigned offset)
988 +{
989 + struct falcon_gpio_port *gpio_port = to_falcon_gpio_port(chip);
990 + if ( (gpio_r32(&gpio_port->pad->avail) >> offset) & 1) {
991 + if (gpio_r32(&gpio_port->pad->muxc[offset]) > 1)
992 + return;
993 + /* switch off gpio function */
994 + gpio_w32(0, &gpio_port->pad->muxc[offset]);
995 + }
996 +}
997 +
998 +static int falcon_gpio_to_irq(struct gpio_chip *chip, unsigned offset)
999 +{
1000 + struct falcon_gpio_port *gpio_port = to_falcon_gpio_port(chip);
1001 + /* no checks: this functions is only registered with valid irq_base */
1002 + return gpio_port->irq_base + offset;
1003 +}
1004 +
1005 +static void falcon_gpio_disable_irq(unsigned int irq)
1006 +{
1007 + struct falcon_gpio_port *gpio_port = get_irq_chip_data(irq);
1008 + unsigned int offset = irq-gpio_port->irq_base;
1009 + gpio_w32(1<<offset, &gpio_port->port->irnenclr);
1010 +}
1011 +
1012 +static void falcon_gpio_enable_irq(unsigned int irq)
1013 +{
1014 + struct falcon_gpio_port *gpio_port = get_irq_chip_data(irq);
1015 + unsigned int offset = irq-gpio_port->irq_base;
1016 +
1017 + if (gpio_r32(&gpio_port->pad->muxc[offset]) < 1) {
1018 + /* switch on gpio function */
1019 + gpio_w32(1, &gpio_port->pad->muxc[offset]);
1020 + }
1021 +
1022 + gpio_w32(1<<offset, &gpio_port->port->irnenset);
1023 +}
1024 +
1025 +static void falcon_gpio_ack_irq(unsigned int irq)
1026 +{
1027 + struct falcon_gpio_port *gpio_port = get_irq_chip_data(irq);
1028 + unsigned int offset = irq-gpio_port->irq_base;
1029 + gpio_w32(1<<offset, &gpio_port->port->irncr);
1030 +}
1031 +
1032 +static void falcon_gpio_mask_and_ack_irq(unsigned int irq)
1033 +{
1034 + struct falcon_gpio_port *gpio_port = get_irq_chip_data(irq);
1035 + unsigned int offset = irq-gpio_port->irq_base;
1036 + gpio_w32(1<<offset, &gpio_port->port->irnenclr);
1037 + gpio_w32(1<<offset, &gpio_port->port->irncr);
1038 +}
1039 +
1040 +static struct irq_chip falcon_gpio_irq_chip;
1041 +static int falcon_gpio_irq_type(unsigned irq, unsigned int type)
1042 +{
1043 + struct falcon_gpio_port *gpio_port = get_irq_chip_data(irq);
1044 + unsigned int offset = irq-gpio_port->irq_base;
1045 + unsigned int mask = 1 << offset;
1046 +
1047 + if ((type & IRQ_TYPE_SENSE_MASK) == IRQ_TYPE_NONE)
1048 + return 0;
1049 +
1050 + if ((type & (IRQ_TYPE_LEVEL_HIGH | IRQ_TYPE_LEVEL_LOW)) != 0) {
1051 + /* level triggered */
1052 + gpio_w32_mask(0, mask, &gpio_port->port->irncfg);
1053 + set_irq_chip_and_handler_name(irq,
1054 + &falcon_gpio_irq_chip, handle_level_irq, "mux");
1055 + } else {
1056 + /* edge triggered */
1057 + gpio_w32_mask(mask, 0, &gpio_port->port->irncfg);
1058 + set_irq_chip_and_handler_name(irq,
1059 + &falcon_gpio_irq_chip, handle_simple_irq, "mux");
1060 + }
1061 +
1062 + if ((type & IRQ_TYPE_EDGE_BOTH) == IRQ_TYPE_EDGE_BOTH) {
1063 + gpio_w32_mask(mask, 0, &gpio_port->port->exintcr0);
1064 + gpio_w32_mask(0, mask, &gpio_port->port->exintcr1);
1065 + } else {
1066 + if ((type & (IRQ_TYPE_EDGE_RISING |IRQ_TYPE_LEVEL_HIGH)) != 0) {
1067 + /* positive logic: rising edge, high level */
1068 + gpio_w32_mask(mask, 0, &gpio_port->port->exintcr0);
1069 + } else {
1070 + /* negative logic: falling edge, low level */
1071 + gpio_w32_mask(0, mask, &gpio_port->port->exintcr0);
1072 + }
1073 + gpio_w32_mask(mask, 0, &gpio_port->port->exintcr1);
1074 + }
1075 +
1076 + return gpio_direction_input(gpio_port->gpio_chip.base + offset);
1077 +}
1078 +
1079 +static void falcon_gpio_irq_handler(unsigned int irq, struct irq_desc *desc)
1080 +{
1081 + struct falcon_gpio_port *gpio_port = get_irq_desc_data(desc);
1082 + unsigned long irncr;
1083 + int offset;
1084 +
1085 + irncr = gpio_r32(&gpio_port->port->irncr);
1086 + /* acknowledge interrupt */
1087 + gpio_w32(irncr, &gpio_port->port->irncr);
1088 +
1089 + desc->chip->ack(irq);
1090 +
1091 + for_each_set_bit(offset, &irncr, gpio_port->gpio_chip.ngpio)
1092 + generic_handle_irq(gpio_port->irq_base + offset);
1093 +}
1094 +
1095 +static struct irq_chip falcon_gpio_irq_chip = {
1096 + .name = "gpio_irq_mux",
1097 + .mask = falcon_gpio_disable_irq,
1098 + .unmask = falcon_gpio_enable_irq,
1099 + .ack = falcon_gpio_ack_irq,
1100 + .mask_ack = falcon_gpio_mask_and_ack_irq,
1101 + .set_type = falcon_gpio_irq_type,
1102 +};
1103 +
1104 +static struct irqaction gpio_cascade = {
1105 + .handler = no_action,
1106 + .flags = IRQF_DISABLED,
1107 + .name = "gpio_cascade",
1108 +};
1109 +
1110 +static int falcon_gpio_probe(struct platform_device *pdev)
1111 +{
1112 + struct falcon_gpio_port *gpio_port;
1113 + int ret, i;
1114 + struct resource *gpiores, *padres;
1115 + int irq;
1116 +
1117 + gpiores = platform_get_resource(pdev, IORESOURCE_MEM, 0);
1118 + padres = platform_get_resource(pdev, IORESOURCE_MEM, 1);
1119 + irq = platform_get_irq(pdev, 0);
1120 + if (!gpiores || !padres)
1121 + return -ENODEV;
1122 +
1123 + gpio_port = kzalloc(sizeof(*gpio_port), GFP_KERNEL);
1124 + if (gpio_port == NULL)
1125 + return -ENOMEM;
1126 +
1127 + gpio_port->gpio_chip.label = "falcon-gpio";
1128 + gpio_port->gpio_chip.direction_input = falcon_gpio_direction_input;
1129 + gpio_port->gpio_chip.direction_output = falcon_gpio_direction_output;
1130 + gpio_port->gpio_chip.get = falcon_gpio_get;
1131 + gpio_port->gpio_chip.set = falcon_gpio_set;
1132 + gpio_port->gpio_chip.request = falcon_gpio_request;
1133 + gpio_port->gpio_chip.free = falcon_gpio_free;
1134 + gpio_port->gpio_chip.base = 100 * pdev->id;
1135 + gpio_port->gpio_chip.ngpio = 32;
1136 + gpio_port->gpio_chip.dev = &pdev->dev;
1137 + gpio_port->gpio_chip.exported = gpio_exported;
1138 +
1139 + gpio_port->port_req = request_mem_region(gpiores->start,
1140 + resource_size(gpiores), pdev->name);
1141 + gpio_port->pad_req = request_mem_region(padres->start,
1142 + resource_size(padres), pdev->name);
1143 + if (!gpio_port->port_req || !gpio_port->pad_req) {
1144 + dev_err(&pdev->dev, "cannot claim register area\n");
1145 + ret = -EIO;
1146 + goto err;
1147 + }
1148 +
1149 + gpio_port->port = ioremap_nocache(gpiores->start,
1150 + resource_size(gpiores));
1151 + gpio_port->pad = ioremap_nocache(padres->start,
1152 + resource_size(padres));
1153 + if (!gpio_port->port || !gpio_port->pad) {
1154 + dev_err(&pdev->dev, "Could not map io ranges\n");
1155 + ret = -ENOMEM;
1156 + goto err;
1157 + }
1158 +
1159 + if (irq>0) {
1160 + /*
1161 + * irq_chip support
1162 + */
1163 + gpio_port->gpio_chip.to_irq = falcon_gpio_to_irq;
1164 + gpio_port->irq_base = INT_NUM_EXTRA_START + 32 * pdev->id;
1165 +
1166 + for (i = 0; i < 32; i++) {
1167 + set_irq_chip_and_handler_name(gpio_port->irq_base + i,
1168 + &falcon_gpio_irq_chip, handle_simple_irq, "mux");
1169 + set_irq_chip_data(gpio_port->irq_base + i, gpio_port);
1170 + /* FIXME: set default cfg to level triggered */
1171 + //gpio_w32_mask(0, 1<<i, &gpio_port->port->irncfg);
1172 + /* set to negative logic (falling edge, low level) */
1173 + gpio_w32_mask(0, 1<<i, &gpio_port->port->exintcr0);
1174 + }
1175 +
1176 + gpio_port->chained_irq = irq;
1177 + setup_irq(irq, &gpio_cascade);
1178 + set_irq_data(irq, gpio_port);
1179 + set_irq_chained_handler(irq, falcon_gpio_irq_handler);
1180 + }
1181 +
1182 + ret = gpiochip_add(&gpio_port->gpio_chip);
1183 + if (ret < 0) {
1184 + dev_err(&pdev->dev, "Could not register gpiochip %d, %d\n",
1185 + pdev->id, ret);
1186 + goto err;
1187 + }
1188 + platform_set_drvdata(pdev, gpio_port);
1189 + return ret;
1190 +
1191 +err:
1192 + dev_err(&pdev->dev, "Error in gpio_probe %d, %d\n", pdev->id, ret);
1193 + if (gpio_port->port_req)
1194 + release_resource(gpio_port->port_req);
1195 + if (gpio_port->pad_req)
1196 + release_resource(gpio_port->pad_req);
1197 +
1198 + if (gpio_port->port)
1199 + iounmap(gpio_port->port);
1200 + if (gpio_port->pad)
1201 + iounmap(gpio_port->pad);
1202 + kfree(gpio_port);
1203 + return ret;
1204 +}
1205 +
1206 +static int falcon_gpio_remove(struct platform_device *pdev)
1207 +{
1208 + struct falcon_gpio_port *gpio_port = platform_get_drvdata(pdev);
1209 + int ret;
1210 +
1211 + ret = gpiochip_remove(&gpio_port->gpio_chip);
1212 + if (gpio_port->port_req)
1213 + release_resource(gpio_port->port_req);
1214 + if (gpio_port->pad_req)
1215 + release_resource(gpio_port->pad_req);
1216 + if (gpio_port->port)
1217 + iounmap(gpio_port->port);
1218 + if (gpio_port->pad)
1219 + iounmap(gpio_port->pad);
1220 + if (ret == 0)
1221 + kfree(gpio_port);
1222 +
1223 + return ret;
1224 +}
1225 +
1226 +static struct platform_driver falcon_gpio_driver = {
1227 + .probe = falcon_gpio_probe,
1228 + .remove = __devexit_p(falcon_gpio_remove),
1229 + .driver = {
1230 + .name = "falcon_gpio",
1231 + .owner = THIS_MODULE,
1232 + },
1233 +};
1234 +
1235 +int __init falcon_gpio_init(void)
1236 +{
1237 + int ret;
1238 +
1239 + printk(KERN_INFO "FALC(tm) ON GPIO Driver, (C) 2011 Lantiq Deutschland Gmbh\n");
1240 + ret = platform_driver_register(&falcon_gpio_driver);
1241 + if (ret)
1242 + pr_err( "falcon_gpio: Error registering platform driver!");
1243 + return ret;
1244 +}
1245 +
1246 +void __exit falcon_gpio_exit(void)
1247 +{
1248 + platform_driver_unregister(&falcon_gpio_driver);
1249 +}
1250 +
1251 +int gpio_to_irq(unsigned int gpio)
1252 +{
1253 + return __gpio_to_irq(gpio);
1254 +}
1255 +EXPORT_SYMBOL(gpio_to_irq);
1256 +
1257 +module_init(falcon_gpio_init);
1258 +module_exit(falcon_gpio_exit);
1259 --- /dev/null
1260 +++ b/arch/mips/include/asm/mach-lantiq/falcon/falcon.h
1261 @@ -0,0 +1,16 @@
1262 +/*
1263 + * This program is free software; you can redistribute it and/or modify
1264 + * it under the terms of the GNU General Public License as published by
1265 + * the Free Software Foundation; either version 2 of the License, or
1266 + * (at your option) any later version.
1267 + *
1268 + * Copyright (C) 2005 infineon
1269 + * Copyright (C) 2010 John Crispin <blogic@openwrt.org>
1270 + */
1271 +
1272 +#ifdef CONFIG_SOC_FALCON
1273 +
1274 +#include <lantiq_soc.h>
1275 +#include <falcon/gpon_reg_base.h>
1276 +
1277 +#endif
1278 --- /dev/null
1279 +++ b/arch/mips/lantiq/falcon/reset.c
1280 @@ -0,0 +1,65 @@
1281 +/*
1282 + * This program is free software; you can redistribute it and/or modify
1283 + * it under the terms of the GNU General Public License as published by
1284 + * the Free Software Foundation; either version 2 of the License, or
1285 + * (at your option) any later version.
1286 + *
1287 + * Copyright (C) 2010 John Crispin <blogic@openwrt.org>
1288 + */
1289 +
1290 +#include <linux/init.h>
1291 +#include <linux/io.h>
1292 +#include <linux/pm.h>
1293 +#include <asm/reboot.h>
1294 +#include <linux/module.h>
1295 +
1296 +#include <falcon.h>
1297 +#include <falcon/gpon_reg_base.h>
1298 +#include <falcon/status_reg.h>
1299 +#include <falcon/sys1_reg.h>
1300 +
1301 +static struct gpon_reg_sys1 * const pSYS1 = (struct gpon_reg_sys1 *)GPON_SYS1_BASE;
1302 +
1303 +/* This function is used by the watchdog driver */
1304 +int ltq_reset_cause(void)
1305 +{
1306 + return 0;
1307 +}
1308 +EXPORT_SYMBOL_GPL(ltq_reset_cause);
1309 +
1310 +static void
1311 +ltq_machine_restart(char *command)
1312 +{
1313 + printk(KERN_NOTICE "System restart\n");
1314 + local_irq_disable();
1315 + ltq_w32(0, (void*)0xBF200000); /* reset Bootreg RVEC */
1316 + ltq_w32(RBT_CPU_TRIG, &pSYS1->rbt);
1317 + for(;;);
1318 +}
1319 +
1320 +static void
1321 +ltq_machine_halt(void)
1322 +{
1323 + printk(KERN_NOTICE "System halted.\n");
1324 + local_irq_disable();
1325 + for(;;);
1326 +}
1327 +
1328 +static void
1329 +ltq_machine_power_off(void)
1330 +{
1331 + printk(KERN_NOTICE "Please turn off the power now.\n");
1332 + local_irq_disable();
1333 + for(;;);
1334 +}
1335 +
1336 +static int __init
1337 +mips_reboot_setup(void)
1338 +{
1339 + _machine_restart = ltq_machine_restart;
1340 + _machine_halt = ltq_machine_halt;
1341 + pm_power_off = ltq_machine_power_off;
1342 + return 0;
1343 +}
1344 +
1345 +arch_initcall(mips_reboot_setup);
1346 --- /dev/null
1347 +++ b/arch/mips/lantiq/falcon/mach-easy98000.c
1348 @@ -0,0 +1,263 @@
1349 +#include <linux/init.h>
1350 +#include <linux/platform_device.h>
1351 +#include <linux/leds.h>
1352 +#include <linux/gpio.h>
1353 +#include <linux/gpio_buttons.h>
1354 +#include <linux/etherdevice.h>
1355 +#include <linux/mtd/mtd.h>
1356 +#include <linux/mtd/partitions.h>
1357 +#include <linux/mtd/physmap.h>
1358 +#include <linux/input.h>
1359 +#include <linux/interrupt.h>
1360 +#include <linux/dm9000.h>
1361 +#include <linux/i2c.h>
1362 +#include <linux/i2c-gpio.h>
1363 +#include <linux/spi/spi.h>
1364 +#include <linux/spi/spi_gpio.h>
1365 +#include <linux/spi/eeprom.h>
1366 +
1367 +#include "../machtypes.h"
1368 +
1369 +#include "devices.h"
1370 +#include "dev-leds-gpio.h"
1371 +
1372 +#define EASY98000_GPIO_LED_0 9
1373 +#define EASY98000_GPIO_LED_1 10
1374 +#define EASY98000_GPIO_LED_2 11
1375 +#define EASY98000_GPIO_LED_3 12
1376 +#define EASY98000_GPIO_LED_4 13
1377 +#define EASY98000_GPIO_LED_5 14
1378 +
1379 +extern unsigned char ltq_ethaddr[6];
1380 +
1381 +#ifdef CONFIG_MTD_PARTITIONS
1382 +static struct mtd_partition easy98000_nor_partitions[] =
1383 +{
1384 + {
1385 + .name = "uboot",
1386 + .offset = 0x0,
1387 + .size = 0x40000,
1388 + },
1389 + {
1390 + .name = "uboot_env",
1391 + .offset = 0x40000,
1392 + .size = 0x40000, /* 2 sectors for redundant env. */
1393 + },
1394 + {
1395 + .name = "linux",
1396 + .offset = 0x80000,
1397 + .size = 0xF80000, /* map only 16 MiB */
1398 + },
1399 +};
1400 +#endif
1401 +
1402 +static struct physmap_flash_data easy98000_nor_flash_data = {
1403 +#ifdef CONFIG_MTD_PARTITIONS
1404 + .nr_parts = ARRAY_SIZE(easy98000_nor_partitions),
1405 + .parts = easy98000_nor_partitions,
1406 +#endif
1407 +};
1408 +
1409 +#ifdef CONFIG_MTD_PARTITIONS
1410 +static struct flash_platform_data easy98000_spi_flash_platform_data = {
1411 + .name = "sflash",
1412 + .parts = easy98000_nor_partitions,
1413 + .nr_parts = ARRAY_SIZE(easy98000_nor_partitions)
1414 +};
1415 +#endif
1416 +
1417 +static struct spi_board_info easy98000_spi_flash_data __initdata = {
1418 + .modalias = "m25p80",
1419 + .bus_num = 0,
1420 + .chip_select = 0,
1421 + .max_speed_hz = 10 * 1000 * 1000,
1422 + .mode = SPI_MODE_3,
1423 +#ifdef CONFIG_MTD_PARTITIONS
1424 + .platform_data = &easy98000_spi_flash_platform_data
1425 +#endif
1426 +};
1427 +
1428 +static struct gpio_led easy98000_leds_gpio[] __initdata = {
1429 + {
1430 + .name = "easy98000:green:0",
1431 + .gpio = EASY98000_GPIO_LED_0,
1432 + .active_low = 0,
1433 + }, {
1434 + .name = "easy98000:green:1",
1435 + .gpio = EASY98000_GPIO_LED_1,
1436 + .active_low = 0,
1437 + }, {
1438 + .name = "easy98000:green:2",
1439 + .gpio = EASY98000_GPIO_LED_2,
1440 + .active_low = 0,
1441 + }, {
1442 + .name = "easy98000:green:3",
1443 + .gpio = EASY98000_GPIO_LED_3,
1444 + .active_low = 0,
1445 + }, {
1446 + .name = "easy98000:green:4",
1447 + .gpio = EASY98000_GPIO_LED_4,
1448 + .active_low = 0,
1449 + }, {
1450 + .name = "easy98000:green:5",
1451 + .gpio = EASY98000_GPIO_LED_5,
1452 + .active_low = 0,
1453 + }
1454 +};
1455 +
1456 +#define CONFIG_DM9000_BASE 0x14000000
1457 +#define DM9000_IO (CONFIG_DM9000_BASE + 3)
1458 +#define DM9000_DATA (CONFIG_DM9000_BASE + 1)
1459 +
1460 +static struct dm9000_plat_data dm9000_plat_data = {
1461 + .flags = DM9000_PLATF_8BITONLY,
1462 + //.dev_addr = { }, /* possibility to provide an ethernet address for the chip */
1463 +};
1464 +
1465 +static struct resource dm9000_resources[] = {
1466 + MEM_RES("dm9000_io", DM9000_IO, DM9000_IO),
1467 + MEM_RES("dm9000_data", DM9000_DATA, DM9000_DATA),
1468 + [2] = {
1469 + /* with irq (210 -> gpio 110) the driver is very unreliable */
1470 + .start = -1, /* use polling */
1471 + .end = -1,
1472 + .flags = IORESOURCE_IRQ | IRQF_TRIGGER_LOW,
1473 + },
1474 +};
1475 +
1476 +static struct platform_device dm9000_platform = {
1477 + .name = "dm9000",
1478 + .id = 0,
1479 + .num_resources = ARRAY_SIZE(dm9000_resources),
1480 + .resource = dm9000_resources,
1481 + .dev = {
1482 + .platform_data = (void *) &dm9000_plat_data,
1483 + }
1484 +};
1485 +
1486 +extern int easy98000_addon_has_dm9000(void);
1487 +static void __init register_davicom(void)
1488 +{
1489 + if (!easy98000_addon_has_dm9000())
1490 + return;
1491 +
1492 + if (!is_valid_ether_addr(ltq_ethaddr))
1493 + random_ether_addr(dm9000_plat_data.dev_addr);
1494 + else {
1495 + memcpy(dm9000_plat_data.dev_addr, ltq_ethaddr, 6);
1496 + /* change to "Locally Administered Address" */
1497 + dm9000_plat_data.dev_addr[0] |= 0x2;
1498 + }
1499 + platform_device_register(&dm9000_platform);
1500 +}
1501 +
1502 +static struct i2c_gpio_platform_data easy98000_i2c_gpio_data = {
1503 + .sda_pin = 107,
1504 + .scl_pin = 108,
1505 +};
1506 +
1507 +static struct platform_device easy98000_i2c_gpio_device = {
1508 + .name = "i2c-gpio",
1509 + .id = 0,
1510 + .dev = {
1511 + .platform_data = &easy98000_i2c_gpio_data,
1512 + }
1513 +};
1514 +
1515 +void __init register_easy98000_cpld(void)
1516 +{
1517 + platform_device_register_simple("easy98000_cpld_led", 0, NULL, 0);
1518 + platform_device_register_simple("easy98000_addon", 0, NULL, 0);
1519 +}
1520 +
1521 +/* setup gpio based spi bus/device for access to the eeprom on the board */
1522 +#define SPI_GPIO_MRST 102
1523 +#define SPI_GPIO_MTSR 103
1524 +#define SPI_GPIO_CLK 104
1525 +#define SPI_GPIO_CS0 105
1526 +#define SPI_GPIO_CS1 106
1527 +#define SPI_GPIO_BUS_NUM 1
1528 +
1529 +static struct spi_gpio_platform_data easy98000_spi_gpio_data = {
1530 + .sck = SPI_GPIO_CLK,
1531 + .mosi = SPI_GPIO_MTSR,
1532 + .miso = SPI_GPIO_MRST,
1533 + .num_chipselect = 2,
1534 +};
1535 +
1536 +static struct platform_device easy98000_spi_gpio_device = {
1537 + .name = "spi_gpio",
1538 + .id = SPI_GPIO_BUS_NUM,
1539 + .dev.platform_data = &easy98000_spi_gpio_data,
1540 +};
1541 +
1542 +static struct spi_eeprom at25160n = {
1543 + .byte_len = 16 * 1024 / 8,
1544 + .name = "at25160n",
1545 + .page_size = 32,
1546 + .flags = EE_ADDR2,
1547 +};
1548 +
1549 +static struct spi_board_info easy98000_spi_gpio_devices __initdata = {
1550 + .modalias = "at25",
1551 + .bus_num = SPI_GPIO_BUS_NUM,
1552 + .max_speed_hz = 1000 * 1000,
1553 + .mode = SPI_MODE_3,
1554 + .chip_select = 1,
1555 + .controller_data = (void *) SPI_GPIO_CS1,
1556 + .platform_data = &at25160n,
1557 +};
1558 +
1559 +static void __init easy98000_spi_gpio_init(void)
1560 +{
1561 + spi_register_board_info(&easy98000_spi_gpio_devices, 1);
1562 + platform_device_register(&easy98000_spi_gpio_device);
1563 +}
1564 +
1565 +static void __init easy98000_init_common(void)
1566 +{
1567 + falcon_register_asc(0);
1568 + falcon_register_gpio();
1569 + falcon_register_wdt();
1570 + falcon_register_i2c();
1571 + platform_device_register(&easy98000_i2c_gpio_device);
1572 + register_davicom();
1573 + ltq_add_device_leds_gpio(-1, ARRAY_SIZE(easy98000_leds_gpio),
1574 + easy98000_leds_gpio);
1575 + register_easy98000_cpld();
1576 + falcon_register_crypto();
1577 + easy98000_spi_gpio_init();
1578 +}
1579 +
1580 +static void __init easy98000_init(void)
1581 +{
1582 + easy98000_init_common();
1583 + falcon_register_nor(&easy98000_nor_flash_data);
1584 +}
1585 +
1586 +static void __init easy98000sf_init(void)
1587 +{
1588 + easy98000_init_common();
1589 + falcon_register_spi_flash(&easy98000_spi_flash_data);
1590 +}
1591 +
1592 +static void __init easy98000nand_init(void)
1593 +{
1594 + easy98000_init_common();
1595 + falcon_register_nand();
1596 +}
1597 +
1598 +MIPS_MACHINE(LANTIQ_MACH_EASY98000,
1599 + "EASY98000",
1600 + "EASY98000 Eval Board",
1601 + easy98000_init);
1602 +
1603 +MIPS_MACHINE(LANTIQ_MACH_EASY98000SF,
1604 + "EASY98000SF",
1605 + "EASY98000 Eval Board (Serial Flash)",
1606 + easy98000sf_init);
1607 +
1608 +MIPS_MACHINE(LANTIQ_MACH_EASY98000NAND,
1609 + "EASY98000NAND",
1610 + "EASY98000 Eval Board (NAND Flash)",
1611 + easy98000nand_init);
1612 --- /dev/null
1613 +++ b/arch/mips/lantiq/falcon/softdog_vpe.c
1614 @@ -0,0 +1,109 @@
1615 +/*
1616 +** =============================================================================
1617 +** FILE NAME : softdog_vpe.c
1618 +** MODULES : LXDB
1619 +** DATE : 24-03-2008
1620 +** AUTHOR : LXDB Team
1621 +** DESCRIPTION : This header file contains the code for the watchdog
1622 +** implentation on vpe1 side.
1623 +** REFERENCES :
1624 +** COPYRIGHT : Copyright (c) 2008
1625 +** Am Campeon 1-12, 85579 Neubiberg, Germany
1626 +** Any use of this software is subject to the conclusion of a respective
1627 +** License agreement. Without such a License agreement no rights to the
1628 +** software are granted
1629 +**
1630 +** HISTORY :
1631 +** $Date $Author $Comment
1632 +** 24-03-2008 LXDB Initial version
1633 +** ============================================================================
1634 +*/
1635 +
1636 +#include <linux/module.h>
1637 +#include <linux/moduleparam.h>
1638 +#include <linux/types.h>
1639 +#include <linux/timer.h>
1640 +#include <linux/reboot.h>
1641 +#include <linux/init.h>
1642 +#include <linux/jiffies.h>
1643 +
1644 +#include <falcon/vpe.h>
1645 +
1646 +static unsigned long last_wdog_value;
1647 +static unsigned long vpe1_wdog_cleared;
1648 +
1649 +static unsigned long vpe1_wdog_dead;
1650 +static void watchdog_vpe0_fire(unsigned long); /* Called when vpe0 timer expires */
1651 +static void keep_alive_vpe0(unsigned long);
1652 +VPE_SW_WDOG_RESET reset_local_fn;
1653 +
1654 +
1655 +static struct timer_list watchdog_vpe0_ticktock =
1656 + TIMER_INITIALIZER(watchdog_vpe0_fire, 0, 0);
1657 +
1658 +static void watchdog_vpe0_fire (unsigned long flags)
1659 +{
1660 + volatile unsigned long *wdog_ctr_value;
1661 + wdog_ctr_value = (void*)vpe1_wdog_ctr;
1662 + if (*wdog_ctr_value == last_wdog_value) { /* VPE1 watchdog expiry handling */
1663 + vpe1_sw_wdog_stop(flags);
1664 + vpe1_wdog_dead++;
1665 + printk(KERN_DEBUG "VPE1 watchdog reset handler called\n");
1666 + /* Call the reset handler function */
1667 + reset_local_fn(flags);
1668 + } else { /* Everything is OK on vpe1 side. Continue. */
1669 + last_wdog_value = *wdog_ctr_value;
1670 + vpe1_wdog_cleared++;
1671 + keep_alive_vpe0(flags);
1672 + }
1673 +}
1674 +
1675 +int32_t vpe1_sw_wdog_register_reset_handler (VPE_SW_WDOG_RESET reset_fn)
1676 +{
1677 + reset_local_fn = (VPE_SW_WDOG_RESET)reset_fn;
1678 + return 0;
1679 +}
1680 +
1681 +static void keep_alive_vpe0(unsigned long flags)
1682 +{
1683 + mod_timer(&watchdog_vpe0_ticktock, jiffies+ vpe1_wdog_timeout );
1684 +}
1685 +
1686 +unsigned long vpe1_sw_wdog_start(unsigned long flags)
1687 +{
1688 + volatile unsigned long *wdog_ctr_value;
1689 + wdog_ctr_value = (void*)vpe1_wdog_ctr;
1690 + *wdog_ctr_value = 0;
1691 + last_wdog_value = 0;
1692 + keep_alive_vpe0(flags);
1693 + return 0;
1694 +}
1695 +
1696 +unsigned long vpe1_sw_wdog_stop(unsigned long flags)
1697 +{
1698 + del_timer(&watchdog_vpe0_ticktock);
1699 + return 0;
1700 +}
1701 +
1702 +static int __init watchdog_vpe1_init(void)
1703 +{
1704 + /* Nothing to be done here */
1705 + return 0;
1706 +}
1707 +
1708 +static void __exit watchdog_vpe1_exit(void)
1709 +{
1710 + unsigned long flags=0;
1711 + vpe1_sw_wdog_stop(flags);
1712 +}
1713 +
1714 +module_init(watchdog_vpe1_init);
1715 +module_exit(watchdog_vpe1_exit);
1716 +
1717 +EXPORT_SYMBOL(vpe1_sw_wdog_register_reset_handler);
1718 +EXPORT_SYMBOL(vpe1_sw_wdog_start);
1719 +EXPORT_SYMBOL(vpe1_sw_wdog_stop);
1720 +
1721 +MODULE_AUTHOR("LXDB");
1722 +MODULE_DESCRIPTION("Software Watchdog For VPE1");
1723 +MODULE_LICENSE("GPL");
1724 --- /dev/null
1725 +++ b/arch/mips/include/asm/mach-lantiq/falcon/vpe.h
1726 @@ -0,0 +1,44 @@
1727 +/*
1728 + * This program is free software; you can redistribute it and/or modify
1729 + * it under the terms of the GNU General Public License as published by
1730 + * the Free Software Foundation; either version 2 of the License, or
1731 + * (at your option) any later version.
1732 + *
1733 + * This program is distributed in the hope that it will be useful,
1734 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
1735 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1736 + * GNU General Public License for more details.
1737 + *
1738 + * You should have received a copy of the GNU General Public License
1739 + * along with this program; if not, write to the Free Software
1740 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
1741 + *
1742 + * Copyright (C) 2005 infineon
1743 + * Copyright (C) 2007 John Crispin <blogic@openwrt.org>
1744 + *
1745 + */
1746 +#ifndef _IFXMIPS_VPE_H__
1747 +#define _IFXMIPS_VPE_H__
1748 +
1749 +/* For the explanation of the APIs please refer the section "MT APRP Kernel
1750 + * Programming" in AR9 SW Architecture Specification
1751 + */
1752 +int32_t vpe1_sw_start(void* sw_start_addr, uint32_t tcmask, uint32_t flags);
1753 +int32_t vpe1_sw_stop(uint32_t flags);
1754 +uint32_t vpe1_get_load_addr (uint32_t flags);
1755 +uint32_t vpe1_get_max_mem (uint32_t flags);
1756 +
1757 +int32_t vpe1_set_boot_param(char *field, char *value, char flags);
1758 +int32_t vpe1_get_boot_param(char *field, char **value, char flags);
1759 +
1760 +/* Watchdog APIs */
1761 +extern unsigned long vpe1_wdog_ctr;
1762 +extern unsigned long vpe1_wdog_timeout;
1763 +
1764 +unsigned long vpe1_sw_wdog_start(unsigned long);
1765 +unsigned long vpe1_sw_wdog_stop(unsigned long);
1766 +
1767 +typedef int (*VPE_SW_WDOG_RESET)(unsigned long wdog_cleared_ok_count);
1768 +int32_t vpe1_sw_wdog_register_reset_handler(VPE_SW_WDOG_RESET reset_fn);
1769 +
1770 +#endif
1771 --- a/arch/mips/lantiq/Kconfig
1772 +++ b/arch/mips/lantiq/Kconfig
1773 @@ -16,8 +16,12 @@ config SOC_XWAY
1774 bool "XWAY"
1775 select SOC_TYPE_XWAY
1776 select HW_HAS_PCI
1777 +
1778 +config SOC_FALCON
1779 + bool "FALCON"
1780 endchoice
1781
1782 source "arch/mips/lantiq/xway/Kconfig"
1783 +source "arch/mips/lantiq/falcon/Kconfig"
1784
1785 endif
1786 --- a/arch/mips/lantiq/Makefile
1787 +++ b/arch/mips/lantiq/Makefile
1788 @@ -9,3 +9,4 @@ obj-y := irq.o setup.o clk.o prom.o devi
1789 obj-$(CONFIG_EARLY_PRINTK) += early_printk.o
1790
1791 obj-$(CONFIG_SOC_TYPE_XWAY) += xway/
1792 +obj-$(CONFIG_SOC_FALCON) += falcon/
1793 --- a/arch/mips/lantiq/Platform
1794 +++ b/arch/mips/lantiq/Platform
1795 @@ -6,3 +6,4 @@ platform-$(CONFIG_LANTIQ) += lantiq/
1796 cflags-$(CONFIG_LANTIQ) += -I$(srctree)/arch/mips/include/asm/mach-lantiq
1797 load-$(CONFIG_LANTIQ) = 0xffffffff80002000
1798 cflags-$(CONFIG_SOC_TYPE_XWAY) += -I$(srctree)/arch/mips/include/asm/mach-lantiq/xway
1799 +cflags-$(CONFIG_SOC_FALCON) += -I$(srctree)/arch/mips/include/asm/mach-lantiq/falcon
1800 --- a/arch/mips/lantiq/machtypes.h
1801 +++ b/arch/mips/lantiq/machtypes.h
1802 @@ -15,6 +15,12 @@ enum lantiq_mach_type {
1803 LTQ_MACH_GENERIC = 0,
1804 LTQ_MACH_EASY50712, /* Danube evaluation board */
1805 LTQ_MACH_EASY50601, /* Amazon SE evaluation board */
1806 +
1807 + /* FALCON */
1808 + LANTIQ_MACH_EASY98000, /* Falcon Eval Board, NOR Flash */
1809 + LANTIQ_MACH_EASY98000SF, /* Falcon Eval Board, Serial Flash */
1810 + LANTIQ_MACH_EASY98000NAND, /* Falcon Eval Board, NAND Flash */
1811 + LANTIQ_MACH_EASY98020, /* Falcon Reference Board */
1812 };
1813
1814 #endif
1815 --- /dev/null
1816 +++ b/arch/mips/lantiq/falcon/addon-easy98000.c
1817 @@ -0,0 +1,212 @@
1818 +/*
1819 + * EASY98000 CPLD Addon driver
1820 + *
1821 + * Copyright (C) 2011 Thomas Langer <thomas.langer@lantiq.com>
1822 + *
1823 + * This program is free software; you can redistribute it and/or modify it
1824 + * under the terms of the GNU General Public License version 2 as published
1825 + * by the Free Software Foundation.
1826 + *
1827 + */
1828 +
1829 +#include <linux/kernel.h>
1830 +#include <linux/version.h>
1831 +#include <linux/types.h>
1832 +#include <linux/init.h>
1833 +#include <linux/platform_device.h>
1834 +#include <linux/errno.h>
1835 +#include <linux/slab.h>
1836 +#include <linux/proc_fs.h>
1837 +#include <linux/seq_file.h>
1838 +
1839 +struct easy98000_reg_cpld {
1840 + u16 cmdreg1; /* 0x1 */
1841 + u16 cmdreg0; /* 0x0 */
1842 + u16 idreg0; /* 0x3 */
1843 + u16 resreg; /* 0x2 */
1844 + u16 intreg; /* 0x5 */
1845 + u16 idreg1; /* 0x4 */
1846 + u16 ledreg; /* 0x7 */
1847 + u16 pcmconconfig; /* 0x6 */
1848 + u16 res0; /* 0x9 */
1849 + u16 ethledreg; /* 0x8 */
1850 + u16 res1[4]; /* 0xa-0xd */
1851 + u16 cpld1v; /* 0xf */
1852 + u16 cpld2v; /* 0xe */
1853 +};
1854 +static struct easy98000_reg_cpld * const cpld =
1855 + (struct easy98000_reg_cpld *)(KSEG1 | 0x17c00000);
1856 +#define cpld_r8(reg) (__raw_readw(&cpld->reg) & 0xFF)
1857 +#define cpld_w8(val, reg) __raw_writew((val) & 0xFF, &cpld->reg)
1858 +
1859 +int easy98000_addon_has_dm9000(void)
1860 +{
1861 + if ((cpld_r8(idreg0) & 0xF) == 1)
1862 + return 1;
1863 + return 0;
1864 +}
1865 +
1866 +#if defined(CONFIG_PROC_FS)
1867 +typedef void (*cpld_dump) (struct seq_file *s);
1868 +struct proc_entry {
1869 + char *name;
1870 + void *callback;
1871 +};
1872 +
1873 +static int cpld_proc_show ( struct seq_file *s, void *p )
1874 +{
1875 + cpld_dump dump = s->private;
1876 +
1877 + if ( dump != NULL )
1878 + dump(s);
1879 +
1880 + return 0;
1881 +}
1882 +
1883 +static int cpld_proc_open ( struct inode *inode, struct file *file )
1884 +{
1885 + return single_open ( file, cpld_proc_show, PDE(inode)->data );
1886 +}
1887 +
1888 +static void cpld_versions_get ( struct seq_file *s )
1889 +{
1890 + seq_printf(s, "CPLD1: V%d\n", cpld_r8(cpld1v));
1891 + seq_printf(s, "CPLD2: V%d\n", cpld_r8(cpld2v));
1892 +}
1893 +
1894 +static void cpld_ebu_module_get ( struct seq_file *s )
1895 +{
1896 + u8 addon_id;
1897 +
1898 + addon_id = cpld_r8(idreg0) & 0xF;
1899 + switch (addon_id) {
1900 + case 0xF: /* nothing connected */
1901 + break;
1902 + case 1:
1903 + seq_printf(s, "Ethernet Controller module (dm9000)\n");
1904 + break;
1905 + default:
1906 + seq_printf(s, "Unknown EBU module (EBU_ID=0x%02X)\n", addon_id);
1907 + break;
1908 + }
1909 +}
1910 +
1911 +static void cpld_xmii_module_get ( struct seq_file *s )
1912 +{
1913 + u8 addon_id;
1914 + char *mod = NULL;
1915 +
1916 + addon_id = cpld_r8(idreg1) & 0xF;
1917 + switch (addon_id) {
1918 + case 0xF:
1919 + mod = "no module";
1920 + break;
1921 + case 0x1:
1922 + mod = "RGMII module";
1923 + break;
1924 + case 0x4:
1925 + mod = "GMII MAC Mode (XWAY TANTOS-3G)";
1926 + break;
1927 + case 0x6:
1928 + mod = "TMII MAC Mode (XWAY TANTOS-3G)";
1929 + break;
1930 + case 0x8:
1931 + mod = "GMII PHY module";
1932 + break;
1933 + case 0x9:
1934 + mod = "MII PHY module";
1935 + break;
1936 + case 0xA:
1937 + mod = "RMII PHY module";
1938 + break;
1939 + default:
1940 + break;
1941 + }
1942 + if (mod)
1943 + seq_printf(s, "%s\n", mod);
1944 + else
1945 + seq_printf(s, "unknown xMII module (xMII_ID=0x%02X)\n", addon_id);
1946 +}
1947 +
1948 +static struct proc_entry proc_entries[] = {
1949 + {"versions", cpld_versions_get},
1950 + {"ebu", cpld_ebu_module_get},
1951 + {"xmii", cpld_xmii_module_get},
1952 +};
1953 +
1954 +static struct file_operations ops = {
1955 + .owner = THIS_MODULE,
1956 + .open = cpld_proc_open,
1957 + .read = seq_read,
1958 + .llseek = seq_lseek,
1959 + .release = single_release,
1960 +};
1961 +
1962 +static void cpld_proc_entry_create(struct proc_dir_entry *parent_node,
1963 + struct proc_entry *proc_entry)
1964 +{
1965 + proc_create_data ( proc_entry->name, (S_IFREG | S_IRUGO), parent_node,
1966 + &ops, proc_entry->callback);
1967 +}
1968 +
1969 +static int cpld_proc_install(void)
1970 +{
1971 + struct proc_dir_entry *driver_proc_node;
1972 +
1973 + driver_proc_node = proc_mkdir("cpld", NULL);
1974 + if (driver_proc_node != NULL) {
1975 + int i;
1976 + for (i = 0; i < ARRAY_SIZE(proc_entries); i++)
1977 + cpld_proc_entry_create(driver_proc_node,
1978 + &proc_entries[i]);
1979 + } else {
1980 + printk("cannot create proc entry");
1981 + return -1;
1982 + }
1983 + return 0;
1984 +}
1985 +#else
1986 +static inline int cpld_proc_install(void) {}
1987 +#endif
1988 +
1989 +static int easy98000_addon_probe(struct platform_device *pdev)
1990 +{
1991 + return cpld_proc_install();
1992 +}
1993 +
1994 +static int easy98000_addon_remove(struct platform_device *pdev)
1995 +{
1996 +#if defined(CONFIG_PROC_FS)
1997 + char buf[64];
1998 + int i;
1999 +
2000 + for (i = 0; i < sizeof(proc_entries) / sizeof(proc_entries[0]); i++) {
2001 + sprintf(buf, "cpld/%s", proc_entries[i].name);
2002 + remove_proc_entry(buf, 0);
2003 + }
2004 + remove_proc_entry("cpld", 0);
2005 +#endif
2006 + return 0;
2007 +}
2008 +
2009 +static struct platform_driver easy98000_addon_driver = {
2010 + .probe = easy98000_addon_probe,
2011 + .remove = __devexit_p(easy98000_addon_remove),
2012 + .driver = {
2013 + .name = "easy98000_addon",
2014 + .owner = THIS_MODULE,
2015 + },
2016 +};
2017 +
2018 +int __init easy98000_addon_init(void)
2019 +{
2020 + return platform_driver_register(&easy98000_addon_driver);
2021 +}
2022 +
2023 +void __exit easy98000_addon_exit(void)
2024 +{
2025 + platform_driver_unregister(&easy98000_addon_driver);
2026 +}
2027 +
2028 +module_init(easy98000_addon_init);
2029 +module_exit(easy98000_addon_exit);