9da7547b3600f4dc89cbc91978e518fa14e36b02
[buildroot.git] /
1 diff --git a/MAINTAINERS b/MAINTAINERS
2 index df40a4e..3c5cfef 100644
3 --- a/MAINTAINERS
4 +++ b/MAINTAINERS
5 @@ -674,6 +674,13 @@ P: Haavard Skinnemoen
6 M: hskinnemoen@atmel.com
7 S: Supported
8
9 +ATMEL USBA UDC DRIVER
10 +P: Haavard Skinnemoen
11 +M: hskinnemoen@atmel.com
12 +L: kernel@avr32linux.org
13 +W: http://avr32linux.org/twiki/bin/view/Main/AtmelUsbDeviceDriver
14 +S: Supported
15 +
16 ATMEL WIRELESS DRIVER
17 P: Simon Kelley
18 M: simon@thekelleys.org.uk
19 diff --git a/arch/avr32/Kconfig b/arch/avr32/Kconfig
20 index 3ec7658..ec6c7c5 100644
21 --- a/arch/avr32/Kconfig
22 +++ b/arch/avr32/Kconfig
23 @@ -113,6 +113,13 @@ config BOARD_ATNGW100
24 bool "ATNGW100 Network Gateway"
25 endchoice
26
27 +if BOARD_ATSTK1000
28 +source "arch/avr32/boards/atstk1000/Kconfig"
29 +endif
30 +if BOARD_ATNGW100
31 +source "arch/avr32/boards/atngw100/Kconfig"
32 +endif
33 +
34 choice
35 prompt "Boot loader type"
36 default LOADER_U_BOOT
37 @@ -171,6 +178,10 @@ config OWNERSHIP_TRACE
38 enabling Nexus-compliant debuggers to keep track of the PID of the
39 currently executing task.
40
41 +config DW_DMAC
42 + tristate "Synopsys DesignWare DMA Controller support"
43 + default y if CPU_AT32AP7000
44 +
45 # FPU emulation goes here
46
47 source "kernel/Kconfig.hz"
48 @@ -185,6 +196,27 @@ config CMDLINE
49
50 endmenu
51
52 +menu "Power managment options"
53 +
54 +menu "CPU Frequency scaling"
55 +
56 +source "drivers/cpufreq/Kconfig"
57 +
58 +config CPU_FREQ_AT32AP
59 + bool "CPU frequency driver for AT32AP"
60 + depends on CPU_FREQ && PLATFORM_AT32AP
61 + default n
62 + help
63 + This enables the CPU frequency driver for AT32AP processors.
64 +
65 + For details, take a look in <file:Documentation/cpu-freq>.
66 +
67 + If in doubt, say N.
68 +
69 +endmenu
70 +
71 +endmenu
72 +
73 menu "Bus options"
74
75 config PCI
76 diff --git a/arch/avr32/Makefile b/arch/avr32/Makefile
77 index dc6bc01..eb72198 100644
78 --- a/arch/avr32/Makefile
79 +++ b/arch/avr32/Makefile
80 @@ -31,6 +31,7 @@ core-$(CONFIG_BOARD_ATNGW100) += arch/avr32/boards/atngw100/
81 core-$(CONFIG_LOADER_U_BOOT) += arch/avr32/boot/u-boot/
82 core-y += arch/avr32/kernel/
83 core-y += arch/avr32/mm/
84 +drivers-y += arch/avr32/drivers/
85 libs-y += arch/avr32/lib/
86
87 archincdir-$(CONFIG_PLATFORM_AT32AP) := arch-at32ap
88 diff --git a/arch/avr32/boards/atngw100/Kconfig b/arch/avr32/boards/atngw100/Kconfig
89 new file mode 100644
90 index 0000000..5d922df
91 --- /dev/null
92 +++ b/arch/avr32/boards/atngw100/Kconfig
93 @@ -0,0 +1,12 @@
94 +# NGW100 customization
95 +
96 +config BOARD_ATNGW100_I2C_GPIO
97 + bool "Use GPIO for i2c instead of built-in TWI module"
98 + help
99 + The driver for the built-in TWI module has been plagued by
100 + various problems, while the i2c-gpio driver is based on the
101 + trusty old i2c-algo-bit bitbanging engine, making it work
102 + on pretty much any setup.
103 +
104 + Choose 'Y' here if you're having i2c-related problems and
105 + want to rule out the i2c bus driver.
106 diff --git a/arch/avr32/boards/atngw100/setup.c b/arch/avr32/boards/atngw100/setup.c
107 index 6c4dc0a..d649974 100644
108 --- a/arch/avr32/boards/atngw100/setup.c
109 +++ b/arch/avr32/boards/atngw100/setup.c
110 @@ -9,10 +9,12 @@
111 */
112 #include <linux/clk.h>
113 #include <linux/etherdevice.h>
114 +#include <linux/i2c-gpio.h>
115 #include <linux/init.h>
116 #include <linux/linkage.h>
117 #include <linux/platform_device.h>
118 #include <linux/types.h>
119 +#include <linux/leds.h>
120 #include <linux/spi/spi.h>
121
122 #include <asm/io.h>
123 @@ -21,6 +23,7 @@
124 #include <asm/arch/at32ap7000.h>
125 #include <asm/arch/board.h>
126 #include <asm/arch/init.h>
127 +#include <asm/arch/portmux.h>
128
129 /* Initialized by bootloader-specific startup code. */
130 struct tag *bootloader_tags __initdata;
131 @@ -39,6 +42,11 @@ static struct spi_board_info spi0_board_info[] __initdata = {
132 },
133 };
134
135 +static struct mci_platform_data __initdata mci0_data = {
136 + .detect_pin = GPIO_PIN_PC(25),
137 + .wp_pin = GPIO_PIN_PE(0),
138 +};
139 +
140 /*
141 * The next two functions should go away as the boot loader is
142 * supposed to initialize the macb address registers with a valid
143 @@ -100,8 +108,46 @@ void __init setup_board(void)
144 at32_setup_serial_console(0);
145 }
146
147 +static const struct gpio_led ngw_leds[] = {
148 + { .name = "sys", .gpio = GPIO_PIN_PA(16), .active_low = 1,
149 + .default_trigger = "heartbeat",
150 + },
151 + { .name = "a", .gpio = GPIO_PIN_PA(19), .active_low = 1, },
152 + { .name = "b", .gpio = GPIO_PIN_PE(19), .active_low = 1, },
153 +};
154 +
155 +static const struct gpio_led_platform_data ngw_led_data = {
156 + .num_leds = ARRAY_SIZE(ngw_leds),
157 + .leds = (void *) ngw_leds,
158 +};
159 +
160 +static struct platform_device ngw_gpio_leds = {
161 + .name = "leds-gpio",
162 + .id = -1,
163 + .dev = {
164 + .platform_data = (void *) &ngw_led_data,
165 + }
166 +};
167 +
168 +#ifdef CONFIG_BOARD_ATNGW100_I2C_GPIO
169 +static struct i2c_gpio_platform_data i2c_gpio_data = {
170 + .sda_pin = GPIO_PIN_PA(6),
171 + .scl_pin = GPIO_PIN_PA(7),
172 +};
173 +
174 +static struct platform_device i2c_gpio_device = {
175 + .name = "i2c-gpio",
176 + .id = 0,
177 + .dev = {
178 + .platform_data = &i2c_gpio_data,
179 + },
180 +};
181 +#endif
182 +
183 static int __init atngw100_init(void)
184 {
185 + unsigned i;
186 +
187 /*
188 * ATNGW100 uses 16-bit SDRAM interface, so we don't need to
189 * reserve any pins for it.
190 @@ -115,6 +161,22 @@ static int __init atngw100_init(void)
191 set_hw_addr(at32_add_device_eth(1, &eth_data[1]));
192
193 at32_add_device_spi(0, spi0_board_info, ARRAY_SIZE(spi0_board_info));
194 + at32_add_device_mci(0, &mci0_data);
195 + at32_add_device_usba(0, NULL);
196 +
197 + for (i = 0; i < ARRAY_SIZE(ngw_leds); i++) {
198 + at32_select_gpio(ngw_leds[i].gpio,
199 + AT32_GPIOF_OUTPUT | AT32_GPIOF_HIGH);
200 + }
201 + platform_device_register(&ngw_gpio_leds);
202 +
203 +#ifdef CONFIG_BOARD_ATNGW100_I2C_GPIO
204 + at32_select_gpio(i2c_gpio_data.sda_pin, 0);
205 + at32_select_gpio(i2c_gpio_data.scl_pin, 0);
206 + platform_device_register(&i2c_gpio_device);
207 +#else
208 + at32_add_device_twi(0);
209 +#endif
210
211 return 0;
212 }
213 diff --git a/arch/avr32/boards/atstk1000/Kconfig b/arch/avr32/boards/atstk1000/Kconfig
214 new file mode 100644
215 index 0000000..718578f
216 --- /dev/null
217 +++ b/arch/avr32/boards/atstk1000/Kconfig
218 @@ -0,0 +1,79 @@
219 +# STK1000 customization
220 +
221 +if BOARD_ATSTK1002
222 +
223 +config BOARD_ATSTK1002_CUSTOM
224 + bool "Non-default STK-1002 jumper settings"
225 + help
226 + You will normally leave the jumpers on the CPU card at their
227 + default settings. If you need to use certain peripherals,
228 + you will need to change some of those jumpers.
229 +
230 +if BOARD_ATSTK1002_CUSTOM
231 +
232 +config BOARD_ATSTK1002_SW1_CUSTOM
233 + bool "SW1: use SSC1 (not SPI0)"
234 + help
235 + This also prevents using the external DAC as an audio interface,
236 + and means you can't initialize the on-board QVGA display.
237 +
238 +config BOARD_ATSTK1002_SW2_CUSTOM
239 + bool "SW2: use IRDA or TIMER0 (not UART-A, MMC/SD, and PS2-A)"
240 + help
241 + If you change this you'll want an updated boot loader putting
242 + the console on UART-C not UART-A.
243 +
244 +config BOARD_ATSTK1002_SW3_CUSTOM
245 + bool "SW3: use TIMER1 (not SSC0 and GCLK)"
246 + help
247 + This also prevents using the external DAC as an audio interface.
248 +
249 +config BOARD_ATSTK1002_SW4_CUSTOM
250 + bool "SW4: use ISI/Camera (not GPIOs, SPI1, and PS2-B)"
251 + help
252 + To use the camera interface you'll need a custom card (on the
253 + PCI-format connector) connect a video sensor.
254 +
255 +config BOARD_ATSTK1002_SW5_CUSTOM
256 + bool "SW5: use MACB1 (not LCDC)"
257 +
258 +config BOARD_ATSTK1002_SW6_CUSTOM
259 + bool "SW6: more GPIOs (not MACB0)"
260 +
261 +endif # custom
262 +
263 +config BOARD_ATSTK1002_SPI1
264 + bool "Configure SPI1 controller"
265 + depends on !BOARD_ATSTK1002_SW4_CUSTOM
266 + help
267 + All the signals for the second SPI controller are available on
268 + GPIO lines and accessed through the J1 jumper block. Say "y"
269 + here to configure that SPI controller.
270 +
271 +config BOARD_ATSTK1002_J2_LED
272 + bool
273 + default BOARD_ATSTK1002_J2_LED8 || BOARD_ATSTK1002_J2_RGB
274 +
275 +choice
276 + prompt "LEDs connected to J2:"
277 + depends on LEDS_GPIO && !BOARD_ATSTK1002_SW4_CUSTOM
278 + optional
279 + help
280 + Select this if you have jumpered the J2 jumper block to the
281 + LED0..LED7 amber leds, or to the RGB leds, using a ten-pin
282 + IDC cable. A default "heartbeat" trigger is provided, but
283 + you can of course override this.
284 +
285 +config BOARD_ATSTK1002_J2_LED8
286 + bool "LED0..LED7"
287 + help
288 + Select this if J2 is jumpered to LED0..LED7 amber leds.
289 +
290 +config BOARD_ATSTK1002_J2_RGB
291 + bool "RGB leds"
292 + help
293 + Select this if J2 is jumpered to the RGB leds.
294 +
295 +endchoice
296 +
297 +endif # stk 1002
298 diff --git a/arch/avr32/boards/atstk1000/atstk1002.c b/arch/avr32/boards/atstk1000/atstk1002.c
299 index e253e86..c958fd4 100644
300 --- a/arch/avr32/boards/atstk1000/atstk1002.c
301 +++ b/arch/avr32/boards/atstk1000/atstk1002.c
302 @@ -11,10 +11,12 @@
303 #include <linux/etherdevice.h>
304 #include <linux/init.h>
305 #include <linux/kernel.h>
306 +#include <linux/leds.h>
307 #include <linux/platform_device.h>
308 #include <linux/string.h>
309 #include <linux/types.h>
310 #include <linux/spi/spi.h>
311 +#include <linux/spi/at73c213.h>
312
313 #include <video/atmel_lcdc.h>
314
315 @@ -27,16 +29,47 @@
316
317 #include "atstk1000.h"
318
319 -#define SW2_DEFAULT /* MMCI and UART_A available */
320
321 struct eth_addr {
322 u8 addr[6];
323 };
324
325 static struct eth_addr __initdata hw_addr[2];
326 -static struct eth_platform_data __initdata eth_data[2];
327 +static struct eth_platform_data __initdata eth_data[2] = {
328 + {
329 + /*
330 + * The MDIO pullups on STK1000 are a bit too weak for
331 + * the autodetection to work properly, so we have to
332 + * mask out everything but the correct address.
333 + */
334 + .phy_mask = ~(1U << 16),
335 + },
336 + {
337 + .phy_mask = ~(1U << 17),
338 + },
339 +};
340 +
341 +#ifndef CONFIG_BOARD_ATSTK1002_SW1_CUSTOM
342 +#ifndef CONFIG_BOARD_ATSTK1002_SW3_CUSTOM
343 +static struct at73c213_board_info at73c213_data = {
344 + .ssc_id = 0,
345 + .shortname = "AVR32 STK1000 external DAC",
346 +};
347 +#endif
348 +#endif
349
350 +#ifndef CONFIG_BOARD_ATSTK1002_SW1_CUSTOM
351 static struct spi_board_info spi0_board_info[] __initdata = {
352 +#ifndef CONFIG_BOARD_ATSTK1002_SW3_CUSTOM
353 + {
354 + /* AT73C213 */
355 + .modalias = "at73c213",
356 + .max_speed_hz = 200000,
357 + .chip_select = 0,
358 + .mode = SPI_MODE_1,
359 + .platform_data = &at73c213_data,
360 + },
361 +#endif
362 {
363 /* QVGA display */
364 .modalias = "ltv350qv",
365 @@ -45,6 +78,18 @@ static struct spi_board_info spi0_board_info[] __initdata = {
366 .mode = SPI_MODE_3,
367 },
368 };
369 +#endif
370 +
371 +#ifdef CONFIG_BOARD_ATSTK1002_SPI1
372 +static struct spi_board_info spi1_board_info[] __initdata = { {
373 + /* patch in custom entries here */
374 +} };
375 +#endif
376 +
377 +static struct mci_platform_data __initdata mci0_data = {
378 + .detect_pin = GPIO_PIN_NONE,
379 + .wp_pin = GPIO_PIN_NONE,
380 +};
381
382 /*
383 * The next two functions should go away as the boot loader is
384 @@ -101,12 +146,103 @@ static void __init set_hw_addr(struct platform_device *pdev)
385 clk_put(pclk);
386 }
387
388 -void __init setup_board(void)
389 +#ifdef CONFIG_BOARD_ATSTK1002_J2_LED
390 +
391 +static struct gpio_led stk_j2_led[] = {
392 +#ifdef CONFIG_BOARD_ATSTK1002_J2_LED8
393 +#define LEDSTRING "J2 jumpered to LED8"
394 + { .name = "led0:amber", .gpio = GPIO_PIN_PB( 8), },
395 + { .name = "led1:amber", .gpio = GPIO_PIN_PB( 9), },
396 + { .name = "led2:amber", .gpio = GPIO_PIN_PB(10), },
397 + { .name = "led3:amber", .gpio = GPIO_PIN_PB(13), },
398 + { .name = "led4:amber", .gpio = GPIO_PIN_PB(14), },
399 + { .name = "led5:amber", .gpio = GPIO_PIN_PB(15), },
400 + { .name = "led6:amber", .gpio = GPIO_PIN_PB(16), },
401 + { .name = "led7:amber", .gpio = GPIO_PIN_PB(30),
402 + .default_trigger = "heartbeat", },
403 +#else /* RGB */
404 +#define LEDSTRING "J2 jumpered to RGB LEDs"
405 + { .name = "r1:red", .gpio = GPIO_PIN_PB( 8), },
406 + { .name = "g1:green", .gpio = GPIO_PIN_PB(10), },
407 + { .name = "b1:blue", .gpio = GPIO_PIN_PB(14), },
408 +
409 + { .name = "r2:red", .gpio = GPIO_PIN_PB( 9),
410 + .default_trigger = "heartbeat", },
411 + { .name = "g2:green", .gpio = GPIO_PIN_PB(13), },
412 + { .name = "b2:blue", .gpio = GPIO_PIN_PB(15),
413 + .default_trigger = "heartbeat", },
414 + /* PB16, PB30 unused */
415 +#endif
416 +};
417 +
418 +static struct gpio_led_platform_data stk_j2_led_data = {
419 + .num_leds = ARRAY_SIZE(stk_j2_led),
420 + .leds = stk_j2_led,
421 +};
422 +
423 +static struct platform_device stk_j2_led_dev = {
424 + .name = "leds-gpio",
425 + .id = 2, /* gpio block J2 */
426 + .dev = {
427 + .platform_data = &stk_j2_led_data,
428 + },
429 +};
430 +
431 +static void setup_j2_leds(void)
432 {
433 -#ifdef SW2_DEFAULT
434 - at32_map_usart(1, 0); /* USART 1/A: /dev/ttyS0, DB9 */
435 + unsigned i;
436 +
437 + for (i = 0; i < ARRAY_SIZE(stk_j2_led); i++)
438 + at32_select_gpio(stk_j2_led[i].gpio, AT32_GPIOF_OUTPUT);
439 +
440 + printk("STK1002: " LEDSTRING "\n");
441 + platform_device_register(&stk_j2_led_dev);
442 +}
443 +
444 #else
445 +static void setup_j2_leds(void)
446 +{
447 +}
448 +#endif
449 +
450 +#ifndef CONFIG_BOARD_ATSTK1002_SW1_CUSTOM
451 +#ifndef CONFIG_BOARD_ATSTK1002_SW3_CUSTOM
452 +static void __init at73c213_set_clk(struct at73c213_board_info *info)
453 +{
454 + struct clk *gclk;
455 + struct clk *pll;
456 +
457 + gclk = clk_get(NULL, "gclk0");
458 + if (IS_ERR(gclk))
459 + goto err_gclk;
460 + pll = clk_get(NULL, "pll0");
461 + if (IS_ERR(pll))
462 + goto err_pll;
463 +
464 + if (clk_set_parent(gclk, pll)) {
465 + pr_debug("STK1000: failed to set pll0 as parent for DAC clock\n");
466 + goto err_set_clk;
467 + }
468 +
469 + at32_select_periph(GPIO_PIN_PA(30), GPIO_PERIPH_A, 0);
470 + info->dac_clk = gclk;
471 +
472 +err_set_clk:
473 + clk_put(pll);
474 +err_pll:
475 + clk_put(gclk);
476 +err_gclk:
477 + return;
478 +}
479 +#endif
480 +#endif
481 +
482 +void __init setup_board(void)
483 +{
484 +#ifdef CONFIG_BOARD_ATSTK1002_SW2_CUSTOM
485 at32_map_usart(0, 1); /* USART 0/B: /dev/ttyS1, IRDA */
486 +#else
487 + at32_map_usart(1, 0); /* USART 1/A: /dev/ttyS0, DB9 */
488 #endif
489 /* USART 2/unused: expansion connector */
490 at32_map_usart(3, 2); /* USART 3/C: /dev/ttyS2, DB9 */
491 @@ -140,18 +276,46 @@ static int __init atstk1002_init(void)
492
493 at32_add_system_devices();
494
495 -#ifdef SW2_DEFAULT
496 - at32_add_device_usart(0);
497 -#else
498 +#ifdef CONFIG_BOARD_ATSTK1002_SW2_CUSTOM
499 at32_add_device_usart(1);
500 +#else
501 + at32_add_device_usart(0);
502 #endif
503 at32_add_device_usart(2);
504
505 +#ifndef CONFIG_BOARD_ATSTK1002_SW6_CUSTOM
506 set_hw_addr(at32_add_device_eth(0, &eth_data[0]));
507 -
508 - at32_add_device_spi(0, spi0_board_info, ARRAY_SIZE(spi0_board_info));
509 +#endif
510 +#ifdef CONFIG_BOARD_ATSTK1002_SW5_CUSTOM
511 + set_hw_addr(at32_add_device_eth(1, &eth_data[1]));
512 +#else
513 at32_add_device_lcdc(0, &atstk1000_lcdc_data,
514 fbmem_start, fbmem_size);
515 +#endif
516 +
517 +#ifndef CONFIG_BOARD_ATSTK1002_SW1_CUSTOM
518 + at32_add_device_spi(0, spi0_board_info, ARRAY_SIZE(spi0_board_info));
519 +#endif
520 +#ifdef CONFIG_BOARD_ATSTK1002_SPI1
521 + at32_add_device_spi(1, spi1_board_info, ARRAY_SIZE(spi1_board_info));
522 +#endif
523 + at32_add_device_twi(0);
524 +#ifndef CONFIG_BOARD_ATSTK1002_SW2_CUSTOM
525 + at32_add_device_mci(0, &mci0_data);
526 +#endif
527 + at32_add_device_usba(0, NULL);
528 + at32_add_device_abdac(0);
529 +#ifndef CONFIG_BOARD_ATSTK1002_SW3_CUSTOM
530 + at32_add_device_ssc(0, ATMEL_SSC_TX);
531 +#endif
532 +
533 + setup_j2_leds();
534 +
535 +#ifndef CONFIG_BOARD_ATSTK1002_SW3_CUSTOM
536 +#ifndef CONFIG_BOARD_ATSTK1002_SW1_CUSTOM
537 + at73c213_set_clk(&at73c213_data);
538 +#endif
539 +#endif
540
541 return 0;
542 }
543 diff --git a/arch/avr32/configs/atngw100_defconfig b/arch/avr32/configs/atngw100_defconfig
544 index 49493ad..adce168 100644
545 --- a/arch/avr32/configs/atngw100_defconfig
546 +++ b/arch/avr32/configs/atngw100_defconfig
547 @@ -1,7 +1,7 @@
548 #
549 # Automatically generated make config: don't edit
550 -# Linux kernel version: 2.6.22-rc5
551 -# Sat Jun 23 15:40:05 2007
552 +# Linux kernel version: 2.6.22.atmel.1
553 +# Thu Jul 12 17:49:20 2007
554 #
555 CONFIG_AVR32=y
556 CONFIG_GENERIC_GPIO=y
557 @@ -114,6 +114,7 @@ CONFIG_PLATFORM_AT32AP=y
558 CONFIG_CPU_AT32AP7000=y
559 # CONFIG_BOARD_ATSTK1000 is not set
560 CONFIG_BOARD_ATNGW100=y
561 +# CONFIG_BOARD_ATNGW100_I2C_GPIO is not set
562 CONFIG_LOADER_U_BOOT=y
563
564 #
565 @@ -122,6 +123,7 @@ CONFIG_LOADER_U_BOOT=y
566 # CONFIG_AP7000_32_BIT_SMC is not set
567 CONFIG_AP7000_16_BIT_SMC=y
568 # CONFIG_AP7000_8_BIT_SMC is not set
569 +CONFIG_GPIO_DEV=y
570 CONFIG_LOAD_ADDRESS=0x10000000
571 CONFIG_ENTRY_ADDRESS=0x90000000
572 CONFIG_PHYS_OFFSET=0x10000000
573 @@ -145,6 +147,7 @@ CONFIG_SPLIT_PTLOCK_CPUS=4
574 # CONFIG_RESOURCES_64BIT is not set
575 CONFIG_ZONE_DMA_FLAG=0
576 # CONFIG_OWNERSHIP_TRACE is not set
577 +CONFIG_DW_DMAC=y
578 # CONFIG_HZ_100 is not set
579 CONFIG_HZ_250=y
580 # CONFIG_HZ_300 is not set
581 @@ -153,6 +156,27 @@ CONFIG_HZ=250
582 CONFIG_CMDLINE=""
583
584 #
585 +# Power managment options
586 +#
587 +
588 +#
589 +# CPU Frequency scaling
590 +#
591 +CONFIG_CPU_FREQ=y
592 +CONFIG_CPU_FREQ_TABLE=y
593 +# CONFIG_CPU_FREQ_DEBUG is not set
594 +CONFIG_CPU_FREQ_STAT=m
595 +# CONFIG_CPU_FREQ_STAT_DETAILS is not set
596 +CONFIG_CPU_FREQ_DEFAULT_GOV_PERFORMANCE=y
597 +# CONFIG_CPU_FREQ_DEFAULT_GOV_USERSPACE is not set
598 +CONFIG_CPU_FREQ_GOV_PERFORMANCE=y
599 +CONFIG_CPU_FREQ_GOV_POWERSAVE=y
600 +CONFIG_CPU_FREQ_GOV_USERSPACE=y
601 +CONFIG_CPU_FREQ_GOV_ONDEMAND=y
602 +# CONFIG_CPU_FREQ_GOV_CONSERVATIVE is not set
603 +CONFIG_CPU_FREQ_AT32AP=y
604 +
605 +#
606 # Bus options
607 #
608 # CONFIG_ARCH_SUPPORTS_MSI is not set
609 @@ -187,13 +211,8 @@ CONFIG_NET_KEY=y
610 # CONFIG_NET_KEY_MIGRATE is not set
611 CONFIG_INET=y
612 CONFIG_IP_MULTICAST=y
613 -CONFIG_IP_ADVANCED_ROUTER=y
614 -CONFIG_ASK_IP_FIB_HASH=y
615 -# CONFIG_IP_FIB_TRIE is not set
616 +# CONFIG_IP_ADVANCED_ROUTER is not set
617 CONFIG_IP_FIB_HASH=y
618 -# CONFIG_IP_MULTIPLE_TABLES is not set
619 -# CONFIG_IP_ROUTE_MULTIPATH is not set
620 -# CONFIG_IP_ROUTE_VERBOSE is not set
621 CONFIG_IP_PNP=y
622 CONFIG_IP_PNP_DHCP=y
623 # CONFIG_IP_PNP_BOOTP is not set
624 @@ -240,6 +259,7 @@ CONFIG_IPV6_SIT=y
625 # CONFIG_NETWORK_SECMARK is not set
626 CONFIG_NETFILTER=y
627 # CONFIG_NETFILTER_DEBUG is not set
628 +CONFIG_BRIDGE_NETFILTER=y
629
630 #
631 # Core Netfilter Configuration
632 @@ -284,6 +304,7 @@ CONFIG_NETFILTER_XT_MATCH_MAC=m
633 CONFIG_NETFILTER_XT_MATCH_MARK=m
634 CONFIG_NETFILTER_XT_MATCH_POLICY=m
635 CONFIG_NETFILTER_XT_MATCH_MULTIPORT=m
636 +# CONFIG_NETFILTER_XT_MATCH_PHYSDEV is not set
637 CONFIG_NETFILTER_XT_MATCH_PKTTYPE=m
638 CONFIG_NETFILTER_XT_MATCH_QUOTA=m
639 CONFIG_NETFILTER_XT_MATCH_REALM=m
640 @@ -359,13 +380,19 @@ CONFIG_IP6_NF_TARGET_REJECT=m
641 CONFIG_IP6_NF_MANGLE=m
642 CONFIG_IP6_NF_TARGET_HL=m
643 CONFIG_IP6_NF_RAW=m
644 +
645 +#
646 +# Bridge: Netfilter Configuration
647 +#
648 +# CONFIG_BRIDGE_NF_EBTABLES is not set
649 # CONFIG_IP_DCCP is not set
650 # CONFIG_IP_SCTP is not set
651 # CONFIG_TIPC is not set
652 # CONFIG_ATM is not set
653 -# CONFIG_BRIDGE is not set
654 +CONFIG_BRIDGE=m
655 CONFIG_VLAN_8021Q=m
656 # CONFIG_DECNET is not set
657 +CONFIG_LLC=m
658 # CONFIG_LLC2 is not set
659 # CONFIG_IPX is not set
660 # CONFIG_ATALK is not set
661 @@ -521,7 +548,6 @@ CONFIG_BLK_DEV_RAM_BLOCKSIZE=1024
662 #
663 # Misc devices
664 #
665 -# CONFIG_BLINK is not set
666 # CONFIG_IDE is not set
667
668 #
669 @@ -545,13 +571,26 @@ CONFIG_NETDEVICES=y
670 # CONFIG_BONDING is not set
671 # CONFIG_EQUALIZER is not set
672 CONFIG_TUN=m
673 -# CONFIG_PHYLIB is not set
674 +CONFIG_PHYLIB=y
675 +
676 +#
677 +# MII PHY device drivers
678 +#
679 +# CONFIG_MARVELL_PHY is not set
680 +# CONFIG_DAVICOM_PHY is not set
681 +# CONFIG_QSEMI_PHY is not set
682 +# CONFIG_LXT_PHY is not set
683 +# CONFIG_CICADA_PHY is not set
684 +# CONFIG_VITESSE_PHY is not set
685 +# CONFIG_SMSC_PHY is not set
686 +# CONFIG_BROADCOM_PHY is not set
687 +# CONFIG_FIXED_PHY is not set
688
689 #
690 # Ethernet (10 or 100Mbit)
691 #
692 CONFIG_NET_ETHERNET=y
693 -CONFIG_MII=y
694 +# CONFIG_MII is not set
695 CONFIG_MACB=y
696 # CONFIG_NETDEV_1000 is not set
697 # CONFIG_NETDEV_10000 is not set
698 @@ -625,7 +664,15 @@ CONFIG_UNIX98_PTYS=y
699 # IPMI
700 #
701 # CONFIG_IPMI_HANDLER is not set
702 -# CONFIG_WATCHDOG is not set
703 +CONFIG_WATCHDOG=y
704 +# CONFIG_WATCHDOG_NOWAYOUT is not set
705 +
706 +#
707 +# Watchdog Device Drivers
708 +#
709 +# CONFIG_SOFT_WATCHDOG is not set
710 +CONFIG_AT32AP700X_WDT=y
711 +CONFIG_AT32AP700X_WDT_TIMEOUT=2
712 # CONFIG_HW_RANDOM is not set
713 # CONFIG_RTC is not set
714 # CONFIG_GEN_RTC is not set
715 @@ -636,7 +683,42 @@ CONFIG_UNIX98_PTYS=y
716 # TPM devices
717 #
718 # CONFIG_TCG_TPM is not set
719 -# CONFIG_I2C is not set
720 +CONFIG_I2C=m
721 +CONFIG_I2C_BOARDINFO=y
722 +CONFIG_I2C_CHARDEV=m
723 +
724 +#
725 +# I2C Algorithms
726 +#
727 +CONFIG_I2C_ALGOBIT=m
728 +# CONFIG_I2C_ALGOPCF is not set
729 +# CONFIG_I2C_ALGOPCA is not set
730 +
731 +#
732 +# I2C Hardware Bus support
733 +#
734 +CONFIG_I2C_ATMELTWI=m
735 +CONFIG_I2C_ATMELTWI_BAUDRATE=100000
736 +CONFIG_I2C_GPIO=m
737 +# CONFIG_I2C_OCORES is not set
738 +# CONFIG_I2C_PARPORT_LIGHT is not set
739 +# CONFIG_I2C_SIMTEC is not set
740 +# CONFIG_I2C_STUB is not set
741 +
742 +#
743 +# Miscellaneous I2C Chip support
744 +#
745 +# CONFIG_SENSORS_DS1337 is not set
746 +# CONFIG_SENSORS_DS1374 is not set
747 +# CONFIG_SENSORS_EEPROM is not set
748 +# CONFIG_SENSORS_PCF8574 is not set
749 +# CONFIG_SENSORS_PCA9539 is not set
750 +# CONFIG_SENSORS_PCF8591 is not set
751 +# CONFIG_SENSORS_MAX6875 is not set
752 +# CONFIG_I2C_DEBUG_CORE is not set
753 +# CONFIG_I2C_DEBUG_ALGO is not set
754 +# CONFIG_I2C_DEBUG_BUS is not set
755 +# CONFIG_I2C_DEBUG_CHIP is not set
756
757 #
758 # SPI support
759 @@ -655,7 +737,7 @@ CONFIG_SPI_ATMEL=y
760 # SPI Protocol Masters
761 #
762 # CONFIG_SPI_AT25 is not set
763 -# CONFIG_SPI_SPIDEV is not set
764 +CONFIG_SPI_SPIDEV=m
765
766 #
767 # Dallas's 1-wire bus
768 @@ -706,21 +788,59 @@ CONFIG_SPI_ATMEL=y
769 #
770 # USB Gadget Support
771 #
772 -# CONFIG_USB_GADGET is not set
773 -# CONFIG_MMC is not set
774 +CONFIG_USB_GADGET=y
775 +# CONFIG_USB_GADGET_DEBUG_FILES is not set
776 +CONFIG_USB_GADGET_SELECTED=y
777 +# CONFIG_USB_GADGET_FSL_USB2 is not set
778 +# CONFIG_USB_GADGET_NET2280 is not set
779 +# CONFIG_USB_GADGET_PXA2XX is not set
780 +# CONFIG_USB_GADGET_GOKU is not set
781 +# CONFIG_USB_GADGET_LH7A40X is not set
782 +CONFIG_USB_GADGET_ATMEL_USBA=y
783 +CONFIG_USB_ATMEL_USBA=y
784 +# CONFIG_USB_GADGET_OMAP is not set
785 +# CONFIG_USB_GADGET_AT91 is not set
786 +# CONFIG_USB_GADGET_DUMMY_HCD is not set
787 +CONFIG_USB_GADGET_DUALSPEED=y
788 +CONFIG_USB_ZERO=m
789 +CONFIG_USB_ETH=m
790 +CONFIG_USB_ETH_RNDIS=y
791 +CONFIG_USB_GADGETFS=m
792 +CONFIG_USB_FILE_STORAGE=m
793 +# CONFIG_USB_FILE_STORAGE_TEST is not set
794 +CONFIG_USB_G_SERIAL=m
795 +# CONFIG_USB_MIDI_GADGET is not set
796 +CONFIG_MMC=y
797 +# CONFIG_MMC_DEBUG is not set
798 +# CONFIG_MMC_UNSAFE_RESUME is not set
799 +
800 +#
801 +# MMC/SD Card Drivers
802 +#
803 +CONFIG_MMC_BLOCK=y
804 +
805 +#
806 +# MMC/SD Host Controller Drivers
807 +#
808 +CONFIG_MMC_ATMELMCI=y
809
810 #
811 # LED devices
812 #
813 -# CONFIG_NEW_LEDS is not set
814 +CONFIG_NEW_LEDS=y
815 +CONFIG_LEDS_CLASS=y
816
817 #
818 # LED drivers
819 #
820 +CONFIG_LEDS_GPIO=y
821
822 #
823 # LED Triggers
824 #
825 +CONFIG_LEDS_TRIGGERS=y
826 +CONFIG_LEDS_TRIGGER_TIMER=y
827 +CONFIG_LEDS_TRIGGER_HEARTBEAT=y
828
829 #
830 # InfiniBand support
831 @@ -733,7 +853,51 @@ CONFIG_SPI_ATMEL=y
832 #
833 # Real Time Clock
834 #
835 -# CONFIG_RTC_CLASS is not set
836 +CONFIG_RTC_LIB=y
837 +CONFIG_RTC_CLASS=y
838 +CONFIG_RTC_HCTOSYS=y
839 +CONFIG_RTC_HCTOSYS_DEVICE="rtc0"
840 +# CONFIG_RTC_DEBUG is not set
841 +
842 +#
843 +# RTC interfaces
844 +#
845 +CONFIG_RTC_INTF_SYSFS=y
846 +CONFIG_RTC_INTF_PROC=y
847 +CONFIG_RTC_INTF_DEV=y
848 +# CONFIG_RTC_INTF_DEV_UIE_EMUL is not set
849 +# CONFIG_RTC_DRV_TEST is not set
850 +
851 +#
852 +# I2C RTC drivers
853 +#
854 +# CONFIG_RTC_DRV_DS1307 is not set
855 +# CONFIG_RTC_DRV_DS1672 is not set
856 +# CONFIG_RTC_DRV_MAX6900 is not set
857 +# CONFIG_RTC_DRV_RS5C372 is not set
858 +# CONFIG_RTC_DRV_ISL1208 is not set
859 +# CONFIG_RTC_DRV_X1205 is not set
860 +# CONFIG_RTC_DRV_PCF8563 is not set
861 +# CONFIG_RTC_DRV_PCF8583 is not set
862 +
863 +#
864 +# SPI RTC drivers
865 +#
866 +# CONFIG_RTC_DRV_RS5C348 is not set
867 +# CONFIG_RTC_DRV_MAX6902 is not set
868 +
869 +#
870 +# Platform RTC drivers
871 +#
872 +# CONFIG_RTC_DRV_DS1553 is not set
873 +# CONFIG_RTC_DRV_DS1742 is not set
874 +# CONFIG_RTC_DRV_M48T86 is not set
875 +# CONFIG_RTC_DRV_V3020 is not set
876 +
877 +#
878 +# on-CPU RTC drivers
879 +#
880 +CONFIG_RTC_DRV_AT32AP700X=y
881
882 #
883 # DMA Engine support
884 @@ -767,7 +931,8 @@ CONFIG_JBD=y
885 # CONFIG_OCFS2_FS is not set
886 # CONFIG_MINIX_FS is not set
887 # CONFIG_ROMFS_FS is not set
888 -# CONFIG_INOTIFY is not set
889 +CONFIG_INOTIFY=y
890 +CONFIG_INOTIFY_USER=y
891 # CONFIG_QUOTA is not set
892 # CONFIG_DNOTIFY is not set
893 # CONFIG_AUTOFS_FS is not set
894 @@ -922,7 +1087,7 @@ CONFIG_TRACE_IRQFLAGS_SUPPORT=y
895 CONFIG_ENABLE_MUST_CHECK=y
896 CONFIG_MAGIC_SYSRQ=y
897 # CONFIG_UNUSED_SYMBOLS is not set
898 -# CONFIG_DEBUG_FS is not set
899 +CONFIG_DEBUG_FS=y
900 # CONFIG_HEADERS_CHECK is not set
901 CONFIG_DEBUG_KERNEL=y
902 # CONFIG_DEBUG_SHIRQ is not set
903 diff --git a/arch/avr32/configs/atstk1002_defconfig b/arch/avr32/configs/atstk1002_defconfig
904 index 3b977fd..3708066 100644
905 --- a/arch/avr32/configs/atstk1002_defconfig
906 +++ b/arch/avr32/configs/atstk1002_defconfig
907 @@ -1,7 +1,7 @@
908 #
909 # Automatically generated make config: don't edit
910 -# Linux kernel version: 2.6.22-rc5
911 -# Sat Jun 23 15:32:08 2007
912 +# Linux kernel version: 2.6.22.atmel.2
913 +# Thu Jul 19 13:46:47 2007
914 #
915 CONFIG_AVR32=y
916 CONFIG_GENERIC_GPIO=y
917 @@ -80,10 +80,10 @@ CONFIG_BASE_SMALL=1
918 #
919 CONFIG_MODULES=y
920 CONFIG_MODULE_UNLOAD=y
921 -# CONFIG_MODULE_FORCE_UNLOAD is not set
922 +CONFIG_MODULE_FORCE_UNLOAD=y
923 # CONFIG_MODVERSIONS is not set
924 # CONFIG_MODULE_SRCVERSION_ALL is not set
925 -# CONFIG_KMOD is not set
926 +CONFIG_KMOD=y
927
928 #
929 # Block layer
930 @@ -99,12 +99,12 @@ CONFIG_BLOCK=y
931 CONFIG_IOSCHED_NOOP=y
932 # CONFIG_IOSCHED_AS is not set
933 # CONFIG_IOSCHED_DEADLINE is not set
934 -# CONFIG_IOSCHED_CFQ is not set
935 +CONFIG_IOSCHED_CFQ=y
936 # CONFIG_DEFAULT_AS is not set
937 # CONFIG_DEFAULT_DEADLINE is not set
938 -# CONFIG_DEFAULT_CFQ is not set
939 -CONFIG_DEFAULT_NOOP=y
940 -CONFIG_DEFAULT_IOSCHED="noop"
941 +CONFIG_DEFAULT_CFQ=y
942 +# CONFIG_DEFAULT_NOOP is not set
943 +CONFIG_DEFAULT_IOSCHED="cfq"
944
945 #
946 # System Type and features
947 @@ -117,6 +117,11 @@ CONFIG_CPU_AT32AP7000=y
948 CONFIG_BOARD_ATSTK1002=y
949 CONFIG_BOARD_ATSTK1000=y
950 # CONFIG_BOARD_ATNGW100 is not set
951 +# CONFIG_BOARD_ATSTK1002_CUSTOM is not set
952 +# CONFIG_BOARD_ATSTK1002_SPI1 is not set
953 +# CONFIG_BOARD_ATSTK1002_J2_LED is not set
954 +# CONFIG_BOARD_ATSTK1002_J2_LED8 is not set
955 +# CONFIG_BOARD_ATSTK1002_J2_RGB is not set
956 CONFIG_LOADER_U_BOOT=y
957
958 #
959 @@ -125,6 +130,7 @@ CONFIG_LOADER_U_BOOT=y
960 # CONFIG_AP7000_32_BIT_SMC is not set
961 CONFIG_AP7000_16_BIT_SMC=y
962 # CONFIG_AP7000_8_BIT_SMC is not set
963 +CONFIG_GPIO_DEV=y
964 CONFIG_LOAD_ADDRESS=0x10000000
965 CONFIG_ENTRY_ADDRESS=0x90000000
966 CONFIG_PHYS_OFFSET=0x10000000
967 @@ -148,6 +154,7 @@ CONFIG_SPLIT_PTLOCK_CPUS=4
968 # CONFIG_RESOURCES_64BIT is not set
969 CONFIG_ZONE_DMA_FLAG=0
970 # CONFIG_OWNERSHIP_TRACE is not set
971 +CONFIG_DW_DMAC=y
972 # CONFIG_HZ_100 is not set
973 CONFIG_HZ_250=y
974 # CONFIG_HZ_300 is not set
975 @@ -156,6 +163,27 @@ CONFIG_HZ=250
976 CONFIG_CMDLINE=""
977
978 #
979 +# Power managment options
980 +#
981 +
982 +#
983 +# CPU Frequency scaling
984 +#
985 +CONFIG_CPU_FREQ=y
986 +CONFIG_CPU_FREQ_TABLE=y
987 +# CONFIG_CPU_FREQ_DEBUG is not set
988 +CONFIG_CPU_FREQ_STAT=m
989 +# CONFIG_CPU_FREQ_STAT_DETAILS is not set
990 +CONFIG_CPU_FREQ_DEFAULT_GOV_PERFORMANCE=y
991 +# CONFIG_CPU_FREQ_DEFAULT_GOV_USERSPACE is not set
992 +CONFIG_CPU_FREQ_GOV_PERFORMANCE=y
993 +CONFIG_CPU_FREQ_GOV_POWERSAVE=y
994 +CONFIG_CPU_FREQ_GOV_USERSPACE=y
995 +CONFIG_CPU_FREQ_GOV_ONDEMAND=y
996 +# CONFIG_CPU_FREQ_GOV_CONSERVATIVE is not set
997 +CONFIG_CPU_FREQ_AT32AP=y
998 +
999 +#
1000 # Bus options
1001 #
1002 # CONFIG_ARCH_SUPPORTS_MSI is not set
1003 @@ -327,6 +355,8 @@ CONFIG_MTD_PHYSMAP_BANKWIDTH=2
1004 #
1005 # Self-contained MTD device drivers
1006 #
1007 +CONFIG_MTD_DATAFLASH=m
1008 +# CONFIG_MTD_M25P80 is not set
1009 # CONFIG_MTD_SLRAM is not set
1010 # CONFIG_MTD_PHRAM is not set
1011 # CONFIG_MTD_MTDRAM is not set
1012 @@ -373,7 +403,7 @@ CONFIG_BLK_DEV_RAM_BLOCKSIZE=1024
1013 #
1014 # Misc devices
1015 #
1016 -# CONFIG_BLINK is not set
1017 +CONFIG_ATMEL_SSC=m
1018 # CONFIG_IDE is not set
1019
1020 #
1021 @@ -397,13 +427,26 @@ CONFIG_DUMMY=y
1022 # CONFIG_BONDING is not set
1023 # CONFIG_EQUALIZER is not set
1024 CONFIG_TUN=m
1025 -# CONFIG_PHYLIB is not set
1026 +CONFIG_PHYLIB=y
1027 +
1028 +#
1029 +# MII PHY device drivers
1030 +#
1031 +# CONFIG_MARVELL_PHY is not set
1032 +# CONFIG_DAVICOM_PHY is not set
1033 +# CONFIG_QSEMI_PHY is not set
1034 +CONFIG_LXT_PHY=y
1035 +# CONFIG_CICADA_PHY is not set
1036 +# CONFIG_VITESSE_PHY is not set
1037 +# CONFIG_SMSC_PHY is not set
1038 +# CONFIG_BROADCOM_PHY is not set
1039 +# CONFIG_FIXED_PHY is not set
1040
1041 #
1042 # Ethernet (10 or 100Mbit)
1043 #
1044 CONFIG_NET_ETHERNET=y
1045 -CONFIG_MII=y
1046 +# CONFIG_MII is not set
1047 CONFIG_MACB=y
1048 # CONFIG_NETDEV_1000 is not set
1049 # CONFIG_NETDEV_10000 is not set
1050 @@ -443,7 +486,42 @@ CONFIG_SLHC=m
1051 #
1052 # Input device support
1053 #
1054 -# CONFIG_INPUT is not set
1055 +CONFIG_INPUT=m
1056 +# CONFIG_INPUT_FF_MEMLESS is not set
1057 +CONFIG_INPUT_POLLDEV=m
1058 +
1059 +#
1060 +# Userland interfaces
1061 +#
1062 +CONFIG_INPUT_MOUSEDEV=m
1063 +CONFIG_INPUT_MOUSEDEV_PSAUX=y
1064 +CONFIG_INPUT_MOUSEDEV_SCREEN_X=1024
1065 +CONFIG_INPUT_MOUSEDEV_SCREEN_Y=768
1066 +# CONFIG_INPUT_JOYDEV is not set
1067 +# CONFIG_INPUT_TSDEV is not set
1068 +# CONFIG_INPUT_EVDEV is not set
1069 +# CONFIG_INPUT_EVBUG is not set
1070 +
1071 +#
1072 +# Input Device Drivers
1073 +#
1074 +CONFIG_INPUT_KEYBOARD=y
1075 +# CONFIG_KEYBOARD_ATKBD is not set
1076 +# CONFIG_KEYBOARD_SUNKBD is not set
1077 +# CONFIG_KEYBOARD_LKKBD is not set
1078 +# CONFIG_KEYBOARD_XTKBD is not set
1079 +# CONFIG_KEYBOARD_NEWTON is not set
1080 +# CONFIG_KEYBOARD_STOWAWAY is not set
1081 +CONFIG_KEYBOARD_GPIO=m
1082 +CONFIG_INPUT_MOUSE=y
1083 +# CONFIG_MOUSE_PS2 is not set
1084 +# CONFIG_MOUSE_SERIAL is not set
1085 +# CONFIG_MOUSE_VSXXXAA is not set
1086 +CONFIG_MOUSE_GPIO=m
1087 +# CONFIG_INPUT_JOYSTICK is not set
1088 +# CONFIG_INPUT_TABLET is not set
1089 +# CONFIG_INPUT_TOUCHSCREEN is not set
1090 +# CONFIG_INPUT_MISC is not set
1091
1092 #
1093 # Hardware I/O ports
1094 @@ -477,7 +555,15 @@ CONFIG_UNIX98_PTYS=y
1095 # IPMI
1096 #
1097 # CONFIG_IPMI_HANDLER is not set
1098 -# CONFIG_WATCHDOG is not set
1099 +CONFIG_WATCHDOG=y
1100 +# CONFIG_WATCHDOG_NOWAYOUT is not set
1101 +
1102 +#
1103 +# Watchdog Device Drivers
1104 +#
1105 +# CONFIG_SOFT_WATCHDOG is not set
1106 +CONFIG_AT32AP700X_WDT=y
1107 +CONFIG_AT32AP700X_WDT_TIMEOUT=2
1108 # CONFIG_HW_RANDOM is not set
1109 # CONFIG_RTC is not set
1110 # CONFIG_GEN_RTC is not set
1111 @@ -488,13 +574,61 @@ CONFIG_UNIX98_PTYS=y
1112 # TPM devices
1113 #
1114 # CONFIG_TCG_TPM is not set
1115 -# CONFIG_I2C is not set
1116 +CONFIG_I2C=m
1117 +CONFIG_I2C_BOARDINFO=y
1118 +CONFIG_I2C_CHARDEV=m
1119 +
1120 +#
1121 +# I2C Algorithms
1122 +#
1123 +CONFIG_I2C_ALGOBIT=m
1124 +# CONFIG_I2C_ALGOPCF is not set
1125 +# CONFIG_I2C_ALGOPCA is not set
1126 +
1127 +#
1128 +# I2C Hardware Bus support
1129 +#
1130 +CONFIG_I2C_ATMELTWI=m
1131 +CONFIG_I2C_ATMELTWI_BAUDRATE=100000
1132 +CONFIG_I2C_GPIO=m
1133 +# CONFIG_I2C_OCORES is not set
1134 +# CONFIG_I2C_PARPORT_LIGHT is not set
1135 +# CONFIG_I2C_SIMTEC is not set
1136 +# CONFIG_I2C_STUB is not set
1137 +
1138 +#
1139 +# Miscellaneous I2C Chip support
1140 +#
1141 +# CONFIG_SENSORS_DS1337 is not set
1142 +# CONFIG_SENSORS_DS1374 is not set
1143 +# CONFIG_SENSORS_EEPROM is not set
1144 +# CONFIG_SENSORS_PCF8574 is not set
1145 +# CONFIG_SENSORS_PCA9539 is not set
1146 +# CONFIG_SENSORS_PCF8591 is not set
1147 +# CONFIG_SENSORS_MAX6875 is not set
1148 +# CONFIG_I2C_DEBUG_CORE is not set
1149 +# CONFIG_I2C_DEBUG_ALGO is not set
1150 +# CONFIG_I2C_DEBUG_BUS is not set
1151 +# CONFIG_I2C_DEBUG_CHIP is not set
1152
1153 #
1154 # SPI support
1155 #
1156 -# CONFIG_SPI is not set
1157 -# CONFIG_SPI_MASTER is not set
1158 +CONFIG_SPI=y
1159 +# CONFIG_SPI_DEBUG is not set
1160 +CONFIG_SPI_MASTER=y
1161 +
1162 +#
1163 +# SPI Master Controller Drivers
1164 +#
1165 +CONFIG_SPI_ATMEL=y
1166 +# CONFIG_SPI_BITBANG is not set
1167 +
1168 +#
1169 +# SPI Protocol Masters
1170 +#
1171 +# CONFIG_SPI_AT25 is not set
1172 +CONFIG_SPI_SPIDEV=m
1173
1174 #
1175 # Dallas's 1-wire bus
1176 @@ -517,19 +651,91 @@ CONFIG_UNIX98_PTYS=y
1177 #
1178 # Graphics support
1179 #
1180 -# CONFIG_BACKLIGHT_LCD_SUPPORT is not set
1181 +CONFIG_BACKLIGHT_LCD_SUPPORT=y
1182 +CONFIG_LCD_CLASS_DEVICE=y
1183 +CONFIG_LCD_LTV350QV=y
1184 +# CONFIG_BACKLIGHT_CLASS_DEVICE is not set
1185
1186 #
1187 # Display device support
1188 #
1189 # CONFIG_DISPLAY_SUPPORT is not set
1190 # CONFIG_VGASTATE is not set
1191 -# CONFIG_FB is not set
1192 +CONFIG_FB=y
1193 +# CONFIG_FIRMWARE_EDID is not set
1194 +# CONFIG_FB_DDC is not set
1195 +CONFIG_FB_CFB_FILLRECT=y
1196 +CONFIG_FB_CFB_COPYAREA=y
1197 +CONFIG_FB_CFB_IMAGEBLIT=y
1198 +# CONFIG_FB_SYS_FILLRECT is not set
1199 +# CONFIG_FB_SYS_COPYAREA is not set
1200 +# CONFIG_FB_SYS_IMAGEBLIT is not set
1201 +# CONFIG_FB_SYS_FOPS is not set
1202 +CONFIG_FB_DEFERRED_IO=y
1203 +# CONFIG_FB_SVGALIB is not set
1204 +# CONFIG_FB_MACMODES is not set
1205 +# CONFIG_FB_BACKLIGHT is not set
1206 +# CONFIG_FB_MODE_HELPERS is not set
1207 +# CONFIG_FB_TILEBLITTING is not set
1208 +
1209 +#
1210 +# Frame buffer hardware drivers
1211 +#
1212 +# CONFIG_FB_S1D13XXX is not set
1213 +CONFIG_FB_ATMEL=y
1214 +# CONFIG_FB_VIRTUAL is not set
1215 +# CONFIG_LOGO is not set
1216
1217 #
1218 # Sound
1219 #
1220 -# CONFIG_SOUND is not set
1221 +CONFIG_SOUND=m
1222 +
1223 +#
1224 +# Advanced Linux Sound Architecture
1225 +#
1226 +CONFIG_SND=m
1227 +CONFIG_SND_TIMER=m
1228 +CONFIG_SND_PCM=m
1229 +# CONFIG_SND_SEQUENCER is not set
1230 +CONFIG_SND_OSSEMUL=y
1231 +CONFIG_SND_MIXER_OSS=m
1232 +CONFIG_SND_PCM_OSS=m
1233 +CONFIG_SND_PCM_OSS_PLUGINS=y
1234 +# CONFIG_SND_DYNAMIC_MINORS is not set
1235 +# CONFIG_SND_SUPPORT_OLD_API is not set
1236 +CONFIG_SND_VERBOSE_PROCFS=y
1237 +# CONFIG_SND_VERBOSE_PRINTK is not set
1238 +# CONFIG_SND_DEBUG is not set
1239 +
1240 +#
1241 +# Generic devices
1242 +#
1243 +# CONFIG_SND_DUMMY is not set
1244 +# CONFIG_SND_MTPAV is not set
1245 +# CONFIG_SND_SERIAL_U16550 is not set
1246 +# CONFIG_SND_MPU401 is not set
1247 +
1248 +#
1249 +# SPI devices
1250 +#
1251 +CONFIG_SND_AT73C213=m
1252 +CONFIG_SND_AT73C213_TARGET_BITRATE=48000
1253 +
1254 +#
1255 +# System on Chip audio support
1256 +#
1257 +# CONFIG_SND_SOC is not set
1258 +
1259 +#
1260 +# Open Sound System
1261 +#
1262 +# CONFIG_SOUND_PRIME is not set
1263 +
1264 +#
1265 +# HID Devices
1266 +#
1267 +# CONFIG_HID is not set
1268
1269 #
1270 # USB support
1271 @@ -545,21 +751,59 @@ CONFIG_UNIX98_PTYS=y
1272 #
1273 # USB Gadget Support
1274 #
1275 -# CONFIG_USB_GADGET is not set
1276 -# CONFIG_MMC is not set
1277 +CONFIG_USB_GADGET=y
1278 +# CONFIG_USB_GADGET_DEBUG_FILES is not set
1279 +CONFIG_USB_GADGET_SELECTED=y
1280 +# CONFIG_USB_GADGET_FSL_USB2 is not set
1281 +# CONFIG_USB_GADGET_NET2280 is not set
1282 +# CONFIG_USB_GADGET_PXA2XX is not set
1283 +# CONFIG_USB_GADGET_GOKU is not set
1284 +# CONFIG_USB_GADGET_LH7A40X is not set
1285 +CONFIG_USB_GADGET_ATMEL_USBA=y
1286 +CONFIG_USB_ATMEL_USBA=y
1287 +# CONFIG_USB_GADGET_OMAP is not set
1288 +# CONFIG_USB_GADGET_AT91 is not set
1289 +# CONFIG_USB_GADGET_DUMMY_HCD is not set
1290 +CONFIG_USB_GADGET_DUALSPEED=y
1291 +CONFIG_USB_ZERO=m
1292 +CONFIG_USB_ETH=m
1293 +CONFIG_USB_ETH_RNDIS=y
1294 +CONFIG_USB_GADGETFS=m
1295 +CONFIG_USB_FILE_STORAGE=m
1296 +# CONFIG_USB_FILE_STORAGE_TEST is not set
1297 +CONFIG_USB_G_SERIAL=m
1298 +# CONFIG_USB_MIDI_GADGET is not set
1299 +CONFIG_MMC=y
1300 +# CONFIG_MMC_DEBUG is not set
1301 +# CONFIG_MMC_UNSAFE_RESUME is not set
1302 +
1303 +#
1304 +# MMC/SD Card Drivers
1305 +#
1306 +CONFIG_MMC_BLOCK=y
1307 +
1308 +#
1309 +# MMC/SD Host Controller Drivers
1310 +#
1311 +CONFIG_MMC_ATMELMCI=y
1312
1313 #
1314 # LED devices
1315 #
1316 -# CONFIG_NEW_LEDS is not set
1317 +CONFIG_NEW_LEDS=y
1318 +CONFIG_LEDS_CLASS=m
1319
1320 #
1321 # LED drivers
1322 #
1323 +CONFIG_LEDS_GPIO=m
1324
1325 #
1326 # LED Triggers
1327 #
1328 +CONFIG_LEDS_TRIGGERS=y
1329 +CONFIG_LEDS_TRIGGER_TIMER=m
1330 +CONFIG_LEDS_TRIGGER_HEARTBEAT=m
1331
1332 #
1333 # InfiniBand support
1334 @@ -572,7 +816,50 @@ CONFIG_UNIX98_PTYS=y
1335 #
1336 # Real Time Clock
1337 #
1338 -# CONFIG_RTC_CLASS is not set
1339 +CONFIG_RTC_LIB=y
1340 +CONFIG_RTC_CLASS=y
1341 +# CONFIG_RTC_HCTOSYS is not set
1342 +# CONFIG_RTC_DEBUG is not set
1343 +
1344 +#
1345 +# RTC interfaces
1346 +#
1347 +CONFIG_RTC_INTF_SYSFS=y
1348 +CONFIG_RTC_INTF_PROC=y
1349 +CONFIG_RTC_INTF_DEV=y
1350 +# CONFIG_RTC_INTF_DEV_UIE_EMUL is not set
1351 +# CONFIG_RTC_DRV_TEST is not set
1352 +
1353 +#
1354 +# I2C RTC drivers
1355 +#
1356 +# CONFIG_RTC_DRV_DS1307 is not set
1357 +# CONFIG_RTC_DRV_DS1672 is not set
1358 +# CONFIG_RTC_DRV_MAX6900 is not set
1359 +# CONFIG_RTC_DRV_RS5C372 is not set
1360 +# CONFIG_RTC_DRV_ISL1208 is not set
1361 +# CONFIG_RTC_DRV_X1205 is not set
1362 +# CONFIG_RTC_DRV_PCF8563 is not set
1363 +# CONFIG_RTC_DRV_PCF8583 is not set
1364 +
1365 +#
1366 +# SPI RTC drivers
1367 +#
1368 +# CONFIG_RTC_DRV_RS5C348 is not set
1369 +# CONFIG_RTC_DRV_MAX6902 is not set
1370 +
1371 +#
1372 +# Platform RTC drivers
1373 +#
1374 +# CONFIG_RTC_DRV_DS1553 is not set
1375 +# CONFIG_RTC_DRV_DS1742 is not set
1376 +# CONFIG_RTC_DRV_M48T86 is not set
1377 +# CONFIG_RTC_DRV_V3020 is not set
1378 +
1379 +#
1380 +# on-CPU RTC drivers
1381 +#
1382 +CONFIG_RTC_DRV_AT32AP700X=y
1383
1384 #
1385 # DMA Engine support
1386 @@ -590,11 +877,14 @@ CONFIG_UNIX98_PTYS=y
1387 #
1388 # File systems
1389 #
1390 -CONFIG_EXT2_FS=m
1391 +CONFIG_EXT2_FS=y
1392 # CONFIG_EXT2_FS_XATTR is not set
1393 # CONFIG_EXT2_FS_XIP is not set
1394 -# CONFIG_EXT3_FS is not set
1395 +CONFIG_EXT3_FS=y
1396 +# CONFIG_EXT3_FS_XATTR is not set
1397 # CONFIG_EXT4DEV_FS is not set
1398 +CONFIG_JBD=y
1399 +# CONFIG_JBD_DEBUG is not set
1400 # CONFIG_REISERFS_FS is not set
1401 # CONFIG_JFS_FS is not set
1402 # CONFIG_FS_POSIX_ACL is not set
1403 @@ -609,7 +899,7 @@ CONFIG_INOTIFY_USER=y
1404 # CONFIG_DNOTIFY is not set
1405 # CONFIG_AUTOFS_FS is not set
1406 # CONFIG_AUTOFS4_FS is not set
1407 -# CONFIG_FUSE_FS is not set
1408 +CONFIG_FUSE_FS=m
1409
1410 #
1411 # CD-ROM/DVD Filesystems
1412 @@ -638,7 +928,7 @@ CONFIG_TMPFS=y
1413 # CONFIG_TMPFS_POSIX_ACL is not set
1414 # CONFIG_HUGETLB_PAGE is not set
1415 CONFIG_RAMFS=y
1416 -CONFIG_CONFIGFS_FS=m
1417 +CONFIG_CONFIGFS_FS=y
1418
1419 #
1420 # Miscellaneous filesystems
1421 @@ -683,8 +973,14 @@ CONFIG_SUNRPC=y
1422 # CONFIG_SUNRPC_BIND34 is not set
1423 # CONFIG_RPCSEC_GSS_KRB5 is not set
1424 # CONFIG_RPCSEC_GSS_SPKM3 is not set
1425 -# CONFIG_SMB_FS is not set
1426 -# CONFIG_CIFS is not set
1427 +CONFIG_SMB_FS=m
1428 +# CONFIG_SMB_NLS_DEFAULT is not set
1429 +CONFIG_CIFS=m
1430 +# CONFIG_CIFS_STATS is not set
1431 +# CONFIG_CIFS_WEAK_PW_HASH is not set
1432 +# CONFIG_CIFS_XATTR is not set
1433 +# CONFIG_CIFS_DEBUG2 is not set
1434 +# CONFIG_CIFS_EXPERIMENTAL is not set
1435 # CONFIG_NCP_FS is not set
1436 # CONFIG_CODA_FS is not set
1437 # CONFIG_AFS_FS is not set
1438 diff --git a/arch/avr32/drivers/Makefile b/arch/avr32/drivers/Makefile
1439 new file mode 100644
1440 index 0000000..b429b75
1441 --- /dev/null
1442 +++ b/arch/avr32/drivers/Makefile
1443 @@ -0,0 +1 @@
1444 +obj-$(CONFIG_DW_DMAC) += dw-dmac.o
1445 diff --git a/arch/avr32/drivers/dw-dmac.c b/arch/avr32/drivers/dw-dmac.c
1446 new file mode 100644
1447 index 0000000..224eb30
1448 --- /dev/null
1449 +++ b/arch/avr32/drivers/dw-dmac.c
1450 @@ -0,0 +1,761 @@
1451 +/*
1452 + * Driver for the Synopsys DesignWare DMA Controller
1453 + *
1454 + * Copyright (C) 2005-2006 Atmel Corporation
1455 + *
1456 + * This program is free software; you can redistribute it and/or modify
1457 + * it under the terms of the GNU General Public License version 2 as
1458 + * published by the Free Software Foundation.
1459 + */
1460 +#include <linux/clk.h>
1461 +#include <linux/device.h>
1462 +#include <linux/dma-mapping.h>
1463 +#include <linux/dmapool.h>
1464 +#include <linux/init.h>
1465 +#include <linux/interrupt.h>
1466 +#include <linux/module.h>
1467 +#include <linux/platform_device.h>
1468 +
1469 +#include <asm/dma-controller.h>
1470 +#include <asm/io.h>
1471 +
1472 +#include "dw-dmac.h"
1473 +
1474 +#define DMAC_NR_CHANNELS 3
1475 +#define DMAC_MAX_BLOCKSIZE 4095
1476 +
1477 +enum {
1478 + CH_STATE_FREE = 0,
1479 + CH_STATE_ALLOCATED,
1480 + CH_STATE_BUSY,
1481 +};
1482 +
1483 +struct dw_dma_lli {
1484 + dma_addr_t sar;
1485 + dma_addr_t dar;
1486 + dma_addr_t llp;
1487 + u32 ctllo;
1488 + u32 ctlhi;
1489 + u32 sstat;
1490 + u32 dstat;
1491 +};
1492 +
1493 +struct dw_dma_block {
1494 + struct dw_dma_lli *lli_vaddr;
1495 + dma_addr_t lli_dma_addr;
1496 +};
1497 +
1498 +struct dw_dma_channel {
1499 + unsigned int state;
1500 + int is_cyclic;
1501 + struct dma_request_sg *req_sg;
1502 + struct dma_request_cyclic *req_cyclic;
1503 + unsigned int nr_blocks;
1504 + int direction;
1505 + struct dw_dma_block *block;
1506 +};
1507 +
1508 +struct dw_dma_controller {
1509 + spinlock_t lock;
1510 + void * __iomem regs;
1511 + struct dma_pool *lli_pool;
1512 + struct clk *hclk;
1513 + struct dma_controller dma;
1514 + struct dw_dma_channel channel[DMAC_NR_CHANNELS];
1515 +};
1516 +#define to_dw_dmac(dmac) container_of(dmac, struct dw_dma_controller, dma)
1517 +
1518 +#define dmac_writel_hi(dmac, reg, value) \
1519 + __raw_writel((value), (dmac)->regs + DW_DMAC_##reg + 4)
1520 +#define dmac_readl_hi(dmac, reg) \
1521 + __raw_readl((dmac)->regs + DW_DMAC_##reg + 4)
1522 +#define dmac_writel_lo(dmac, reg, value) \
1523 + __raw_writel((value), (dmac)->regs + DW_DMAC_##reg)
1524 +#define dmac_readl_lo(dmac, reg) \
1525 + __raw_readl((dmac)->regs + DW_DMAC_##reg)
1526 +#define dmac_chan_writel_hi(dmac, chan, reg, value) \
1527 + __raw_writel((value), ((dmac)->regs + 0x58 * (chan) \
1528 + + DW_DMAC_CHAN_##reg + 4))
1529 +#define dmac_chan_readl_hi(dmac, chan, reg) \
1530 + __raw_readl((dmac)->regs + 0x58 * (chan) + DW_DMAC_CHAN_##reg + 4)
1531 +#define dmac_chan_writel_lo(dmac, chan, reg, value) \
1532 + __raw_writel((value), (dmac)->regs + 0x58 * (chan) + DW_DMAC_CHAN_##reg)
1533 +#define dmac_chan_readl_lo(dmac, chan, reg) \
1534 + __raw_readl((dmac)->regs + 0x58 * (chan) + DW_DMAC_CHAN_##reg)
1535 +#define set_channel_bit(dmac, reg, chan) \
1536 + dmac_writel_lo(dmac, reg, (1 << (chan)) | (1 << ((chan) + 8)))
1537 +#define clear_channel_bit(dmac, reg, chan) \
1538 + dmac_writel_lo(dmac, reg, (0 << (chan)) | (1 << ((chan) + 8)))
1539 +
1540 +static int dmac_alloc_channel(struct dma_controller *_dmac)
1541 +{
1542 + struct dw_dma_controller *dmac = to_dw_dmac(_dmac);
1543 + struct dw_dma_channel *chan;
1544 + unsigned long flags;
1545 + int i;
1546 +
1547 + spin_lock_irqsave(&dmac->lock, flags);
1548 + for (i = 0; i < DMAC_NR_CHANNELS; i++)
1549 + if (dmac->channel[i].state == CH_STATE_FREE)
1550 + break;
1551 +
1552 + if (i < DMAC_NR_CHANNELS) {
1553 + chan = &dmac->channel[i];
1554 + chan->state = CH_STATE_ALLOCATED;
1555 + } else {
1556 + i = -EBUSY;
1557 + }
1558 +
1559 + spin_unlock_irqrestore(&dmac->lock, flags);
1560 +
1561 + return i;
1562 +}
1563 +
1564 +static void dmac_release_channel(struct dma_controller *_dmac, int channel)
1565 +{
1566 + struct dw_dma_controller *dmac = to_dw_dmac(_dmac);
1567 +
1568 + BUG_ON(channel >= DMAC_NR_CHANNELS
1569 + || dmac->channel[channel].state != CH_STATE_ALLOCATED);
1570 +
1571 + dmac->channel[channel].state = CH_STATE_FREE;
1572 +}
1573 +
1574 +static struct dw_dma_block *allocate_blocks(struct dw_dma_controller *dmac,
1575 + unsigned int nr_blocks)
1576 +{
1577 + struct dw_dma_block *block;
1578 + void *p;
1579 + unsigned int i;
1580 +
1581 + block = kmalloc(nr_blocks * sizeof(*block),
1582 + GFP_KERNEL);
1583 + if (unlikely(!block))
1584 + return NULL;
1585 +
1586 + for (i = 0; i < nr_blocks; i++) {
1587 + p = dma_pool_alloc(dmac->lli_pool, GFP_KERNEL,
1588 + &block[i].lli_dma_addr);
1589 + block[i].lli_vaddr = p;
1590 + if (unlikely(!p))
1591 + goto fail;
1592 + }
1593 +
1594 + return block;
1595 +
1596 +fail:
1597 + for (i = 0; i < nr_blocks; i++) {
1598 + if (!block[i].lli_vaddr)
1599 + break;
1600 + dma_pool_free(dmac->lli_pool, block[i].lli_vaddr,
1601 + block[i].lli_dma_addr);
1602 + }
1603 + kfree(block);
1604 + return NULL;
1605 +}
1606 +
1607 +static void cleanup_channel(struct dw_dma_controller *dmac,
1608 + struct dw_dma_channel *chan)
1609 +{
1610 + unsigned int i;
1611 +
1612 + if (chan->nr_blocks > 1) {
1613 + for (i = 0; i < chan->nr_blocks; i++)
1614 + dma_pool_free(dmac->lli_pool, chan->block[i].lli_vaddr,
1615 + chan->block[i].lli_dma_addr);
1616 + kfree(chan->block);
1617 + }
1618 +
1619 + chan->state = CH_STATE_ALLOCATED;
1620 +}
1621 +
1622 +static int dmac_prepare_request_sg(struct dma_controller *_dmac,
1623 + struct dma_request_sg *req)
1624 +{
1625 + struct dw_dma_controller *dmac = to_dw_dmac(_dmac);
1626 + struct dw_dma_channel *chan;
1627 + unsigned long ctlhi, ctllo, cfghi, cfglo;
1628 + unsigned long block_size;
1629 + unsigned int nr_blocks;
1630 + int ret, i, direction;
1631 + unsigned long flags;
1632 +
1633 + spin_lock_irqsave(&dmac->lock, flags);
1634 +
1635 + ret = -EINVAL;
1636 + if (req->req.channel >= DMAC_NR_CHANNELS
1637 + || dmac->channel[req->req.channel].state != CH_STATE_ALLOCATED
1638 + || req->block_size > DMAC_MAX_BLOCKSIZE) {
1639 + spin_unlock_irqrestore(&dmac->lock, flags);
1640 + return -EINVAL;
1641 + }
1642 +
1643 + chan = &dmac->channel[req->req.channel];
1644 + chan->state = CH_STATE_BUSY;
1645 + chan->req_sg = req;
1646 + chan->is_cyclic = 0;
1647 +
1648 + /*
1649 + * We have marked the channel as busy, so no need to keep the
1650 + * lock as long as we only touch the channel-specific
1651 + * registers
1652 + */
1653 + spin_unlock_irqrestore(&dmac->lock, flags);
1654 +
1655 + /*
1656 + * There may be limitations in the driver and/or the DMA
1657 + * controller that prevents us from sending a whole
1658 + * scatterlist item in one go. Taking this into account,
1659 + * calculate the number of block transfers we need to set up.
1660 + *
1661 + * FIXME: Let the peripheral driver know about the maximum
1662 + * block size we support. We really don't want to use a
1663 + * different block size than what was suggested by the
1664 + * peripheral.
1665 + *
1666 + * Each block will get its own Linked List Item (LLI) below.
1667 + */
1668 + block_size = req->block_size;
1669 + nr_blocks = req->nr_blocks;
1670 + pr_debug("block_size %lu, nr_blocks %u nr_sg = %u\n",
1671 + block_size, nr_blocks, req->nr_sg);
1672 +
1673 + BUG_ON(nr_blocks == 0);
1674 + chan->nr_blocks = nr_blocks;
1675 +
1676 + ret = -EINVAL;
1677 + cfglo = cfghi = 0;
1678 + switch (req->direction) {
1679 + case DMA_DIR_MEM_TO_PERIPH:
1680 + direction = DMA_TO_DEVICE;
1681 + cfghi = req->periph_id << (43 - 32);
1682 + break;
1683 +
1684 + case DMA_DIR_PERIPH_TO_MEM:
1685 + direction = DMA_FROM_DEVICE;
1686 + cfghi = req->periph_id << (39 - 32);
1687 + break;
1688 + default:
1689 + goto out_unclaim_channel;
1690 + }
1691 +
1692 + chan->direction = direction;
1693 +
1694 + dmac_chan_writel_hi(dmac, req->req.channel, CFG, cfghi);
1695 + dmac_chan_writel_lo(dmac, req->req.channel, CFG, cfglo);
1696 +
1697 + ctlhi = block_size >> req->width;
1698 + ctllo = ((req->direction << 20)
1699 + // | (1 << 14) | (1 << 11) // source/dest burst trans len
1700 + | (req->width << 4) | (req->width << 1)
1701 + | (1 << 0)); // interrupt enable
1702 +
1703 + if (nr_blocks == 1) {
1704 + /* Only one block: No need to use block chaining */
1705 + if (direction == DMA_TO_DEVICE) {
1706 + dmac_chan_writel_lo(dmac, req->req.channel, SAR,
1707 + req->sg->dma_address);
1708 + dmac_chan_writel_lo(dmac, req->req.channel, DAR,
1709 + req->data_reg);
1710 + ctllo |= 2 << 7; // no dst increment
1711 + } else {
1712 + dmac_chan_writel_lo(dmac, req->req.channel, SAR,
1713 + req->data_reg);
1714 + dmac_chan_writel_lo(dmac, req->req.channel, DAR,
1715 + req->sg->dma_address);
1716 + ctllo |= 2 << 9; // no src increment
1717 + }
1718 + dmac_chan_writel_lo(dmac, req->req.channel, CTL, ctllo);
1719 + dmac_chan_writel_hi(dmac, req->req.channel, CTL, ctlhi);
1720 + pr_debug("ctl hi:lo 0x%lx:%lx\n", ctlhi, ctllo);
1721 + } else {
1722 + struct dw_dma_lli *lli, *lli_prev = NULL;
1723 + int j = 0, offset = 0;
1724 +
1725 + ret = -ENOMEM;
1726 + chan->block = allocate_blocks(dmac, nr_blocks);
1727 + if (!chan->block)
1728 + goto out_unclaim_channel;
1729 +
1730 + if (direction == DMA_TO_DEVICE)
1731 + ctllo |= 1 << 28 | 1 << 27 | 2 << 7;
1732 + else
1733 + ctllo |= 1 << 28 | 1 << 27 | 2 << 9;
1734 +
1735 + /*
1736 + * Map scatterlist items to blocks. One scatterlist
1737 + * item may need more than one block for the reasons
1738 + * mentioned above.
1739 + */
1740 + for (i = 0; i < nr_blocks; i++) {
1741 + lli = chan->block[i].lli_vaddr;
1742 + if (lli_prev) {
1743 + lli_prev->llp = chan->block[i].lli_dma_addr;
1744 + pr_debug("lli[%d] (0x%p/0x%x): 0x%x 0x%x 0x%x 0x%x 0x%x\n",
1745 + i - 1, chan->block[i - 1].lli_vaddr,
1746 + chan->block[i - 1].lli_dma_addr,
1747 + lli_prev->sar, lli_prev->dar, lli_prev->llp,
1748 + lli_prev->ctllo, lli_prev->ctlhi);
1749 + }
1750 + lli->llp = 0;
1751 + lli->ctllo = ctllo;
1752 + lli->ctlhi = ctlhi;
1753 + if (direction == DMA_TO_DEVICE) {
1754 + lli->sar = req->sg[j].dma_address + offset;
1755 + lli->dar = req->data_reg;
1756 + } else {
1757 + lli->sar = req->data_reg;
1758 + lli->dar = req->sg[j].dma_address + offset;
1759 + }
1760 + lli_prev = lli;
1761 +
1762 + offset += block_size;
1763 + if (offset > req->sg[j].length) {
1764 + j++;
1765 + offset = 0;
1766 + }
1767 + }
1768 +
1769 + pr_debug("lli[%d] (0x%p/0x%x): 0x%x 0x%x 0x%x 0x%x 0x%x\n",
1770 + i - 1, chan->block[i - 1].lli_vaddr,
1771 + chan->block[i - 1].lli_dma_addr, lli_prev->sar,
1772 + lli_prev->dar, lli_prev->llp,
1773 + lli_prev->ctllo, lli_prev->ctlhi);
1774 +
1775 + /*
1776 + * SAR, DAR and CTL are initialized from the LLI. We
1777 + * only have to enable the LLI bits in CTL.
1778 + */
1779 + dmac_chan_writel_hi(dmac, req->req.channel, CTL, 0);
1780 + dmac_chan_writel_lo(dmac, req->req.channel, LLP,
1781 + chan->block[0].lli_dma_addr);
1782 + dmac_chan_writel_lo(dmac, req->req.channel, CTL, 1 << 28 | 1 << 27);
1783 + }
1784 +
1785 + set_channel_bit(dmac, MASK_XFER, req->req.channel);
1786 + set_channel_bit(dmac, MASK_ERROR, req->req.channel);
1787 + if (req->req.block_complete)
1788 + set_channel_bit(dmac, MASK_BLOCK, req->req.channel);
1789 + else
1790 + clear_channel_bit(dmac, MASK_BLOCK, req->req.channel);
1791 +
1792 + return 0;
1793 +
1794 +out_unclaim_channel:
1795 + chan->state = CH_STATE_ALLOCATED;
1796 + return ret;
1797 +}
1798 +
1799 +static int dmac_prepare_request_cyclic(struct dma_controller *_dmac,
1800 + struct dma_request_cyclic *req)
1801 +{
1802 + struct dw_dma_controller *dmac = to_dw_dmac(_dmac);
1803 + struct dw_dma_channel *chan;
1804 + unsigned long ctlhi, ctllo, cfghi, cfglo;
1805 + unsigned long block_size;
1806 + int ret, i, direction;
1807 + unsigned long flags;
1808 +
1809 + spin_lock_irqsave(&dmac->lock, flags);
1810 +
1811 + block_size = (req->buffer_size/req->periods) >> req->width;
1812 +
1813 + ret = -EINVAL;
1814 + if (req->req.channel >= DMAC_NR_CHANNELS
1815 + || dmac->channel[req->req.channel].state != CH_STATE_ALLOCATED
1816 + || (req->periods == 0)
1817 + || block_size > DMAC_MAX_BLOCKSIZE) {
1818 + spin_unlock_irqrestore(&dmac->lock, flags);
1819 + return -EINVAL;
1820 + }
1821 +
1822 + chan = &dmac->channel[req->req.channel];
1823 + chan->state = CH_STATE_BUSY;
1824 + chan->is_cyclic = 1;
1825 + chan->req_cyclic = req;
1826 +
1827 + /*
1828 + * We have marked the channel as busy, so no need to keep the
1829 + * lock as long as we only touch the channel-specific
1830 + * registers
1831 + */
1832 + spin_unlock_irqrestore(&dmac->lock, flags);
1833 +
1834 + /*
1835 + Setup
1836 + */
1837 + BUG_ON(req->buffer_size % req->periods);
1838 + /* printk(KERN_INFO "block_size = %lu, periods = %u\n", block_size, req->periods); */
1839 +
1840 + chan->nr_blocks = req->periods;
1841 +
1842 + ret = -EINVAL;
1843 + cfglo = cfghi = 0;
1844 + switch (req->direction) {
1845 + case DMA_DIR_MEM_TO_PERIPH:
1846 + direction = DMA_TO_DEVICE;
1847 + cfghi = req->periph_id << (43 - 32);
1848 + break;
1849 +
1850 + case DMA_DIR_PERIPH_TO_MEM:
1851 + direction = DMA_FROM_DEVICE;
1852 + cfghi = req->periph_id << (39 - 32);
1853 + break;
1854 + default:
1855 + goto out_unclaim_channel;
1856 + }
1857 +
1858 + chan->direction = direction;
1859 +
1860 + dmac_chan_writel_hi(dmac, req->req.channel, CFG, cfghi);
1861 + dmac_chan_writel_lo(dmac, req->req.channel, CFG, cfglo);
1862 +
1863 + ctlhi = block_size;
1864 + ctllo = ((req->direction << 20)
1865 + | (req->width << 4) | (req->width << 1)
1866 + | (1 << 0)); // interrupt enable
1867 +
1868 + {
1869 + struct dw_dma_lli *lli = NULL, *lli_prev = NULL;
1870 +
1871 + ret = -ENOMEM;
1872 + chan->block = allocate_blocks(dmac, req->periods);
1873 + if (!chan->block)
1874 + goto out_unclaim_channel;
1875 +
1876 + if (direction == DMA_TO_DEVICE)
1877 + ctllo |= 1 << 28 | 1 << 27 | 2 << 7;
1878 + else
1879 + ctllo |= 1 << 28 | 1 << 27 | 2 << 9;
1880 +
1881 + /*
1882 + * Set up a linked list items where each period gets
1883 + * an item. The linked list item for the last period
1884 + * points back to the star of the buffer making a
1885 + * cyclic buffer.
1886 + */
1887 + for (i = 0; i < req->periods; i++) {
1888 + lli = chan->block[i].lli_vaddr;
1889 + if (lli_prev) {
1890 + lli_prev->llp = chan->block[i].lli_dma_addr;
1891 + /* printk(KERN_INFO "lli[%d] (0x%p/0x%x): 0x%x 0x%x 0x%x 0x%x 0x%x\n",
1892 + i - 1, chan->block[i - 1].lli_vaddr,
1893 + chan->block[i - 1].lli_dma_addr,
1894 + lli_prev->sar, lli_prev->dar, lli_prev->llp,
1895 + lli_prev->ctllo, lli_prev->ctlhi);*/
1896 + }
1897 + lli->llp = 0;
1898 + lli->ctllo = ctllo;
1899 + lli->ctlhi = ctlhi;
1900 + if (direction == DMA_TO_DEVICE) {
1901 + lli->sar = req->buffer_start + i*(block_size << req->width);
1902 + lli->dar = req->data_reg;
1903 + } else {
1904 + lli->sar = req->data_reg;
1905 + lli->dar = req->buffer_start + i*(block_size << req->width);
1906 + }
1907 + lli_prev = lli;
1908 + }
1909 + lli->llp = chan->block[0].lli_dma_addr;
1910 +
1911 + /*printk(KERN_INFO "lli[%d] (0x%p/0x%x): 0x%x 0x%x 0x%x 0x%x 0x%x\n",
1912 + i - 1, chan->block[i - 1].lli_vaddr,
1913 + chan->block[i - 1].lli_dma_addr, lli_prev->sar,
1914 + lli_prev->dar, lli_prev->llp,
1915 + lli_prev->ctllo, lli_prev->ctlhi); */
1916 +
1917 + /*
1918 + * SAR, DAR and CTL are initialized from the LLI. We
1919 + * only have to enable the LLI bits in CTL.
1920 + */
1921 + dmac_chan_writel_lo(dmac, req->req.channel, LLP,
1922 + chan->block[0].lli_dma_addr);
1923 + dmac_chan_writel_lo(dmac, req->req.channel, CTL, 1 << 28 | 1 << 27);
1924 + }
1925 +
1926 + clear_channel_bit(dmac, MASK_XFER, req->req.channel);
1927 + set_channel_bit(dmac, MASK_ERROR, req->req.channel);
1928 + if (req->req.block_complete)
1929 + set_channel_bit(dmac, MASK_BLOCK, req->req.channel);
1930 + else
1931 + clear_channel_bit(dmac, MASK_BLOCK, req->req.channel);
1932 +
1933 + return 0;
1934 +
1935 +out_unclaim_channel:
1936 + chan->state = CH_STATE_ALLOCATED;
1937 + return ret;
1938 +}
1939 +
1940 +static int dmac_start_request(struct dma_controller *_dmac,
1941 + unsigned int channel)
1942 +{
1943 + struct dw_dma_controller *dmac = to_dw_dmac(_dmac);
1944 +
1945 + BUG_ON(channel >= DMAC_NR_CHANNELS);
1946 +
1947 + set_channel_bit(dmac, CH_EN, channel);
1948 +
1949 + return 0;
1950 +}
1951 +
1952 +static dma_addr_t dmac_get_current_pos(struct dma_controller *_dmac,
1953 + unsigned int channel)
1954 +{
1955 + struct dw_dma_controller *dmac = to_dw_dmac(_dmac);
1956 + struct dw_dma_channel *chan;
1957 + dma_addr_t current_pos;
1958 +
1959 + BUG_ON(channel >= DMAC_NR_CHANNELS);
1960 +
1961 + chan = &dmac->channel[channel];
1962 +
1963 + switch (chan->direction) {
1964 + case DMA_TO_DEVICE:
1965 + current_pos = dmac_chan_readl_lo(dmac, channel, SAR);
1966 + break;
1967 + case DMA_FROM_DEVICE:
1968 + current_pos = dmac_chan_readl_lo(dmac, channel, DAR);
1969 + break;
1970 + default:
1971 + return 0;
1972 + }
1973 +
1974 +
1975 + if (!current_pos) {
1976 + if (chan->is_cyclic) {
1977 + current_pos = chan->req_cyclic->buffer_start;
1978 + } else {
1979 + current_pos = chan->req_sg->sg->dma_address;
1980 + }
1981 + }
1982 +
1983 + return current_pos;
1984 +}
1985 +
1986 +
1987 +static int dmac_stop_request(struct dma_controller *_dmac,
1988 + unsigned int channel)
1989 +{
1990 + struct dw_dma_controller *dmac = to_dw_dmac(_dmac);
1991 + struct dw_dma_channel *chan;
1992 +
1993 + BUG_ON(channel >= DMAC_NR_CHANNELS);
1994 +
1995 + chan = &dmac->channel[channel];
1996 + pr_debug("stop: st%u s%08x d%08x l%08x ctl0x%08x:0x%08x\n",
1997 + chan->state, dmac_chan_readl_lo(dmac, channel, SAR),
1998 + dmac_chan_readl_lo(dmac, channel, DAR),
1999 + dmac_chan_readl_lo(dmac, channel, LLP),
2000 + dmac_chan_readl_hi(dmac, channel, CTL),
2001 + dmac_chan_readl_lo(dmac, channel, CTL));
2002 +
2003 + if (chan->state == CH_STATE_BUSY) {
2004 + clear_channel_bit(dmac, CH_EN, channel);
2005 + cleanup_channel(dmac, &dmac->channel[channel]);
2006 + }
2007 +
2008 + return 0;
2009 +}
2010 +
2011 +
2012 +static void dmac_block_complete(struct dw_dma_controller *dmac)
2013 +{
2014 + struct dw_dma_channel *chan;
2015 + unsigned long status, chanid;
2016 +
2017 + status = dmac_readl_lo(dmac, STATUS_BLOCK);
2018 +
2019 + while (status) {
2020 + struct dma_request *req;
2021 + chanid = __ffs(status);
2022 + chan = &dmac->channel[chanid];
2023 +
2024 + if (chan->is_cyclic) {
2025 + BUG_ON(!chan->req_cyclic
2026 + || !chan->req_cyclic->req.block_complete);
2027 + req = &chan->req_cyclic->req;
2028 + } else {
2029 + BUG_ON(!chan->req_sg || !chan->req_sg->req.block_complete);
2030 + req = &chan->req_sg->req;
2031 + }
2032 + dmac_writel_lo(dmac, CLEAR_BLOCK, 1 << chanid);
2033 + req->block_complete(req);
2034 + status = dmac_readl_lo(dmac, STATUS_BLOCK);
2035 + }
2036 +}
2037 +
2038 +static void dmac_xfer_complete(struct dw_dma_controller *dmac)
2039 +{
2040 + struct dw_dma_channel *chan;
2041 + struct dma_request *req;
2042 + unsigned long status, chanid;
2043 +
2044 + status = dmac_readl_lo(dmac, STATUS_XFER);
2045 +
2046 + while (status) {
2047 + chanid = __ffs(status);
2048 + chan = &dmac->channel[chanid];
2049 +
2050 + dmac_writel_lo(dmac, CLEAR_XFER, 1 << chanid);
2051 +
2052 + req = &chan->req_sg->req;
2053 + BUG_ON(!req);
2054 + cleanup_channel(dmac, chan);
2055 + if (req->xfer_complete)
2056 + req->xfer_complete(req);
2057 +
2058 + status = dmac_readl_lo(dmac, STATUS_XFER);
2059 + }
2060 +}
2061 +
2062 +static void dmac_error(struct dw_dma_controller *dmac)
2063 +{
2064 + struct dw_dma_channel *chan;
2065 + unsigned long status, chanid;
2066 +
2067 + status = dmac_readl_lo(dmac, STATUS_ERROR);
2068 +
2069 + while (status) {
2070 + struct dma_request *req;
2071 +
2072 + chanid = __ffs(status);
2073 + chan = &dmac->channel[chanid];
2074 +
2075 + dmac_writel_lo(dmac, CLEAR_ERROR, 1 << chanid);
2076 + clear_channel_bit(dmac, CH_EN, chanid);
2077 +
2078 + if (chan->is_cyclic) {
2079 + BUG_ON(!chan->req_cyclic);
2080 + req = &chan->req_cyclic->req;
2081 + } else {
2082 + BUG_ON(!chan->req_sg);
2083 + req = &chan->req_sg->req;
2084 + }
2085 +
2086 + cleanup_channel(dmac, chan);
2087 + if (req->error)
2088 + req->error(req);
2089 +
2090 + status = dmac_readl_lo(dmac, STATUS_XFER);
2091 + }
2092 +}
2093 +
2094 +static irqreturn_t dmac_interrupt(int irq, void *dev_id)
2095 +{
2096 + struct dw_dma_controller *dmac = dev_id;
2097 + unsigned long status;
2098 + int ret = IRQ_NONE;
2099 +
2100 + spin_lock(&dmac->lock);
2101 +
2102 + status = dmac_readl_lo(dmac, STATUS_INT);
2103 +
2104 + while (status) {
2105 + ret = IRQ_HANDLED;
2106 + if (status & 0x10)
2107 + dmac_error(dmac);
2108 + if (status & 0x02)
2109 + dmac_block_complete(dmac);
2110 + if (status & 0x01)
2111 + dmac_xfer_complete(dmac);
2112 +
2113 + status = dmac_readl_lo(dmac, STATUS_INT);
2114 + }
2115 +
2116 + spin_unlock(&dmac->lock);
2117 + return ret;
2118 +}
2119 +
2120 +static int __devinit dmac_probe(struct platform_device *pdev)
2121 +{
2122 + struct dw_dma_controller *dmac;
2123 + struct resource *regs;
2124 + int ret;
2125 +
2126 + regs = platform_get_resource(pdev, IORESOURCE_MEM, 0);
2127 + if (!regs)
2128 + return -ENXIO;
2129 +
2130 + dmac = kmalloc(sizeof(*dmac), GFP_KERNEL);
2131 + if (!dmac)
2132 + return -ENOMEM;
2133 + memset(dmac, 0, sizeof(*dmac));
2134 +
2135 + dmac->hclk = clk_get(&pdev->dev, "hclk");
2136 + if (IS_ERR(dmac->hclk)) {
2137 + ret = PTR_ERR(dmac->hclk);
2138 + goto out_free_dmac;
2139 + }
2140 + clk_enable(dmac->hclk);
2141 +
2142 + ret = -ENOMEM;
2143 + dmac->lli_pool = dma_pool_create("dmac", &pdev->dev,
2144 + sizeof(struct dw_dma_lli), 4, 0);
2145 + if (!dmac->lli_pool)
2146 + goto out_disable_clk;
2147 +
2148 + spin_lock_init(&dmac->lock);
2149 + dmac->dma.dev = &pdev->dev;
2150 + dmac->dma.alloc_channel = dmac_alloc_channel;
2151 + dmac->dma.release_channel = dmac_release_channel;
2152 + dmac->dma.prepare_request_sg = dmac_prepare_request_sg;
2153 + dmac->dma.prepare_request_cyclic = dmac_prepare_request_cyclic;
2154 + dmac->dma.start_request = dmac_start_request;
2155 + dmac->dma.stop_request = dmac_stop_request;
2156 + dmac->dma.get_current_pos = dmac_get_current_pos;
2157 +
2158 + dmac->regs = ioremap(regs->start, regs->end - regs->start + 1);
2159 + if (!dmac->regs)
2160 + goto out_free_pool;
2161 +
2162 + ret = request_irq(platform_get_irq(pdev, 0), dmac_interrupt,
2163 + IRQF_SAMPLE_RANDOM, pdev->name, dmac);
2164 + if (ret)
2165 + goto out_unmap_regs;
2166 +
2167 + /* Enable the DMA controller */
2168 + dmac_writel_lo(dmac, CFG, 1);
2169 +
2170 + register_dma_controller(&dmac->dma);
2171 +
2172 + printk(KERN_INFO
2173 + "dmac%d: DesignWare DMA controller at 0x%p irq %d\n",
2174 + dmac->dma.id, dmac->regs, platform_get_irq(pdev, 0));
2175 +
2176 + return 0;
2177 +
2178 +out_unmap_regs:
2179 + iounmap(dmac->regs);
2180 +out_free_pool:
2181 + dma_pool_destroy(dmac->lli_pool);
2182 +out_disable_clk:
2183 + clk_disable(dmac->hclk);
2184 + clk_put(dmac->hclk);
2185 +out_free_dmac:
2186 + kfree(dmac);
2187 + return ret;
2188 +}
2189 +
2190 +static struct platform_driver dmac_driver = {
2191 + .probe = dmac_probe,
2192 + .driver = {
2193 + .name = "dmaca",
2194 + },
2195 +};
2196 +
2197 +static int __init dmac_init(void)
2198 +{
2199 + return platform_driver_register(&dmac_driver);
2200 +}
2201 +subsys_initcall(dmac_init);
2202 +
2203 +static void __exit dmac_exit(void)
2204 +{
2205 + platform_driver_unregister(&dmac_driver);
2206 +}
2207 +module_exit(dmac_exit);
2208 +
2209 +MODULE_DESCRIPTION("Synopsys DesignWare DMA Controller driver");
2210 +MODULE_AUTHOR("Haavard Skinnemoen <hskinnemoen@atmel.com>");
2211 +MODULE_LICENSE("GPL");
2212 diff --git a/arch/avr32/drivers/dw-dmac.h b/arch/avr32/drivers/dw-dmac.h
2213 new file mode 100644
2214 index 0000000..1f67921
2215 --- /dev/null
2216 +++ b/arch/avr32/drivers/dw-dmac.h
2217 @@ -0,0 +1,42 @@
2218 +/*
2219 + * Driver for the Synopsys DesignWare DMA Controller
2220 + *
2221 + * Copyright (C) 2005-2006 Atmel Corporation
2222 + *
2223 + * This program is free software; you can redistribute it and/or modify
2224 + * it under the terms of the GNU General Public License version 2 as
2225 + * published by the Free Software Foundation.
2226 + */
2227 +#ifndef __AVR32_DW_DMAC_H__
2228 +#define __AVR32_DW_DMAC_H__
2229 +
2230 +#define DW_DMAC_CFG 0x398
2231 +#define DW_DMAC_CH_EN 0x3a0
2232 +
2233 +#define DW_DMAC_STATUS_XFER 0x2e8
2234 +#define DW_DMAC_STATUS_BLOCK 0x2f0
2235 +#define DW_DMAC_STATUS_ERROR 0x308
2236 +
2237 +#define DW_DMAC_MASK_XFER 0x310
2238 +#define DW_DMAC_MASK_BLOCK 0x318
2239 +#define DW_DMAC_MASK_ERROR 0x330
2240 +
2241 +#define DW_DMAC_CLEAR_XFER 0x338
2242 +#define DW_DMAC_CLEAR_BLOCK 0x340
2243 +#define DW_DMAC_CLEAR_ERROR 0x358
2244 +
2245 +#define DW_DMAC_STATUS_INT 0x360
2246 +
2247 +#define DW_DMAC_CHAN_SAR 0x000
2248 +#define DW_DMAC_CHAN_DAR 0x008
2249 +#define DW_DMAC_CHAN_LLP 0x010
2250 +#define DW_DMAC_CHAN_CTL 0x018
2251 +#define DW_DMAC_CHAN_SSTAT 0x020
2252 +#define DW_DMAC_CHAN_DSTAT 0x028
2253 +#define DW_DMAC_CHAN_SSTATAR 0x030
2254 +#define DW_DMAC_CHAN_DSTATAR 0x038
2255 +#define DW_DMAC_CHAN_CFG 0x040
2256 +#define DW_DMAC_CHAN_SGR 0x048
2257 +#define DW_DMAC_CHAN_DSR 0x050
2258 +
2259 +#endif /* __AVR32_DW_DMAC_H__ */
2260 diff --git a/arch/avr32/kernel/Makefile b/arch/avr32/kernel/Makefile
2261 index 90e5aff..b6afc0c 100644
2262 --- a/arch/avr32/kernel/Makefile
2263 +++ b/arch/avr32/kernel/Makefile
2264 @@ -9,6 +9,7 @@ obj-y += syscall_table.o syscall-stubs.o irq.o
2265 obj-y += setup.o traps.o semaphore.o ptrace.o
2266 obj-y += signal.o sys_avr32.o process.o time.o
2267 obj-y += init_task.o switch_to.o cpu.o
2268 +obj-y += dma-controller.o
2269 obj-$(CONFIG_MODULES) += module.o avr32_ksyms.o
2270 obj-$(CONFIG_KPROBES) += kprobes.o
2271
2272 diff --git a/arch/avr32/kernel/dma-controller.c b/arch/avr32/kernel/dma-controller.c
2273 new file mode 100644
2274 index 0000000..fb654b3
2275 --- /dev/null
2276 +++ b/arch/avr32/kernel/dma-controller.c
2277 @@ -0,0 +1,34 @@
2278 +/*
2279 + * Preliminary DMA controller framework for AVR32
2280 + *
2281 + * Copyright (C) 2005-2006 Atmel Corporation
2282 + *
2283 + * This program is free software; you can redistribute it and/or modify
2284 + * it under the terms of the GNU General Public License version 2 as
2285 + * published by the Free Software Foundation.
2286 + */
2287 +#include <asm/dma-controller.h>
2288 +
2289 +static LIST_HEAD(controllers);
2290 +
2291 +int register_dma_controller(struct dma_controller *dmac)
2292 +{
2293 + static int next_id;
2294 +
2295 + dmac->id = next_id++;
2296 + list_add_tail(&dmac->list, &controllers);
2297 +
2298 + return 0;
2299 +}
2300 +EXPORT_SYMBOL(register_dma_controller);
2301 +
2302 +struct dma_controller *find_dma_controller(int id)
2303 +{
2304 + struct dma_controller *dmac;
2305 +
2306 + list_for_each_entry(dmac, &controllers, list)
2307 + if (dmac->id == id)
2308 + return dmac;
2309 + return NULL;
2310 +}
2311 +EXPORT_SYMBOL(find_dma_controller);
2312 diff --git a/arch/avr32/kernel/setup.c b/arch/avr32/kernel/setup.c
2313 index b279d66..d08b0bc 100644
2314 --- a/arch/avr32/kernel/setup.c
2315 +++ b/arch/avr32/kernel/setup.c
2316 @@ -313,7 +313,7 @@ __tagtable(ATAG_MEM, parse_tag_mem);
2317
2318 static int __init parse_tag_rdimg(struct tag *tag)
2319 {
2320 -#ifdef CONFIG_INITRD
2321 +#ifdef CONFIG_BLK_DEV_INITRD
2322 struct tag_mem_range *mem = &tag->u.mem_range;
2323 int ret;
2324
2325 @@ -323,7 +323,7 @@ static int __init parse_tag_rdimg(struct tag *tag)
2326 return 0;
2327 }
2328
2329 - ret = add_reserved_region(mem->start, mem->start + mem->size - 1,
2330 + ret = add_reserved_region(mem->addr, mem->addr + mem->size - 1,
2331 "initrd");
2332 if (ret) {
2333 printk(KERN_WARNING
2334 diff --git a/arch/avr32/mach-at32ap/Kconfig b/arch/avr32/mach-at32ap/Kconfig
2335 index eb30783..43c5b9f 100644
2336 --- a/arch/avr32/mach-at32ap/Kconfig
2337 +++ b/arch/avr32/mach-at32ap/Kconfig
2338 @@ -26,6 +26,13 @@ config AP7000_8_BIT_SMC
2339
2340 endchoice
2341
2342 +config GPIO_DEV
2343 + bool "GPIO /dev interface"
2344 + select CONFIGFS_FS
2345 + default n
2346 + help
2347 + Say `Y' to enable a /dev interface to the GPIO pins.
2348 +
2349 endmenu
2350
2351 endif # PLATFORM_AT32AP
2352 diff --git a/arch/avr32/mach-at32ap/Makefile b/arch/avr32/mach-at32ap/Makefile
2353 index f1d3957..250372a 100644
2354 --- a/arch/avr32/mach-at32ap/Makefile
2355 +++ b/arch/avr32/mach-at32ap/Makefile
2356 @@ -1,3 +1,5 @@
2357 obj-y += at32ap.o clock.o intc.o extint.o pio.o hsmc.o
2358 obj-$(CONFIG_CPU_AT32AP7000) += at32ap7000.o
2359 obj-$(CONFIG_CPU_AT32AP7000) += time-tc.o
2360 +obj-$(CONFIG_CPU_FREQ_AT32AP) += cpufreq.o
2361 +obj-$(CONFIG_GPIO_DEV) += gpio-dev.o
2362 diff --git a/arch/avr32/mach-at32ap/at32ap.c b/arch/avr32/mach-at32ap/at32ap.c
2363 index 90f207e..7c4987f 100644
2364 --- a/arch/avr32/mach-at32ap/at32ap.c
2365 +++ b/arch/avr32/mach-at32ap/at32ap.c
2366 @@ -11,41 +11,10 @@
2367 #include <linux/init.h>
2368 #include <linux/platform_device.h>
2369
2370 -#include <asm/io.h>
2371 -
2372 #include <asm/arch/init.h>
2373 -#include <asm/arch/sm.h>
2374 -
2375 -struct at32_sm system_manager;
2376 -
2377 -static int __init at32_sm_init(void)
2378 -{
2379 - struct resource *regs;
2380 - struct at32_sm *sm = &system_manager;
2381 - int ret = -ENXIO;
2382 -
2383 - regs = platform_get_resource(&at32_sm_device, IORESOURCE_MEM, 0);
2384 - if (!regs)
2385 - goto fail;
2386 -
2387 - spin_lock_init(&sm->lock);
2388 - sm->pdev = &at32_sm_device;
2389 -
2390 - ret = -ENOMEM;
2391 - sm->regs = ioremap(regs->start, regs->end - regs->start + 1);
2392 - if (!sm->regs)
2393 - goto fail;
2394 -
2395 - return 0;
2396 -
2397 -fail:
2398 - printk(KERN_ERR "Failed to initialize System Manager: %d\n", ret);
2399 - return ret;
2400 -}
2401
2402 void __init setup_platform(void)
2403 {
2404 - at32_sm_init();
2405 at32_clock_init();
2406 at32_portmux_init();
2407 }
2408 diff --git a/arch/avr32/mach-at32ap/at32ap7000.c b/arch/avr32/mach-at32ap/at32ap7000.c
2409 index 4dda42d..1130c8a 100644
2410 --- a/arch/avr32/mach-at32ap/at32ap7000.c
2411 +++ b/arch/avr32/mach-at32ap/at32ap7000.c
2412 @@ -17,14 +17,20 @@
2413 #include <asm/arch/at32ap7000.h>
2414 #include <asm/arch/board.h>
2415 #include <asm/arch/portmux.h>
2416 -#include <asm/arch/sm.h>
2417
2418 #include <video/atmel_lcdc.h>
2419
2420 #include "clock.h"
2421 #include "hmatrix.h"
2422 #include "pio.h"
2423 -#include "sm.h"
2424 +#include "pm.h"
2425 +
2426 +/*
2427 + * We can reduce the code size a bit by using a constant here. Since
2428 + * this file is completely chip-specific, it's safe to not use
2429 + * ioremap. Generic drivers should of course never do this.
2430 + */
2431 +#define AT32_PM_BASE 0xfff00000
2432
2433 #define PBMEM(base) \
2434 { \
2435 @@ -88,6 +94,8 @@ static struct clk devname##_##_name = { \
2436 .index = _index, \
2437 }
2438
2439 +static DEFINE_SPINLOCK(pm_lock);
2440 +
2441 unsigned long at32ap7000_osc_rates[3] = {
2442 [0] = 32768,
2443 /* FIXME: these are ATSTK1002-specific */
2444 @@ -104,11 +112,11 @@ static unsigned long pll_get_rate(struct clk *clk, unsigned long control)
2445 {
2446 unsigned long div, mul, rate;
2447
2448 - if (!(control & SM_BIT(PLLEN)))
2449 + if (!(control & PM_BIT(PLLEN)))
2450 return 0;
2451
2452 - div = SM_BFEXT(PLLDIV, control) + 1;
2453 - mul = SM_BFEXT(PLLMUL, control) + 1;
2454 + div = PM_BFEXT(PLLDIV, control) + 1;
2455 + mul = PM_BFEXT(PLLMUL, control) + 1;
2456
2457 rate = clk->parent->get_rate(clk->parent);
2458 rate = (rate + div / 2) / div;
2459 @@ -121,7 +129,7 @@ static unsigned long pll0_get_rate(struct clk *clk)
2460 {
2461 u32 control;
2462
2463 - control = sm_readl(&system_manager, PM_PLL0);
2464 + control = pm_readl(PLL0);
2465
2466 return pll_get_rate(clk, control);
2467 }
2468 @@ -130,7 +138,7 @@ static unsigned long pll1_get_rate(struct clk *clk)
2469 {
2470 u32 control;
2471
2472 - control = sm_readl(&system_manager, PM_PLL1);
2473 + control = pm_readl(PLL1);
2474
2475 return pll_get_rate(clk, control);
2476 }
2477 @@ -187,108 +195,139 @@ static unsigned long bus_clk_get_rate(struct clk *clk, unsigned int shift)
2478
2479 static void cpu_clk_mode(struct clk *clk, int enabled)
2480 {
2481 - struct at32_sm *sm = &system_manager;
2482 unsigned long flags;
2483 u32 mask;
2484
2485 - spin_lock_irqsave(&sm->lock, flags);
2486 - mask = sm_readl(sm, PM_CPU_MASK);
2487 + spin_lock_irqsave(&pm_lock, flags);
2488 + mask = pm_readl(CPU_MASK);
2489 if (enabled)
2490 mask |= 1 << clk->index;
2491 else
2492 mask &= ~(1 << clk->index);
2493 - sm_writel(sm, PM_CPU_MASK, mask);
2494 - spin_unlock_irqrestore(&sm->lock, flags);
2495 + pm_writel(CPU_MASK, mask);
2496 + spin_unlock_irqrestore(&pm_lock, flags);
2497 }
2498
2499 static unsigned long cpu_clk_get_rate(struct clk *clk)
2500 {
2501 unsigned long cksel, shift = 0;
2502
2503 - cksel = sm_readl(&system_manager, PM_CKSEL);
2504 - if (cksel & SM_BIT(CPUDIV))
2505 - shift = SM_BFEXT(CPUSEL, cksel) + 1;
2506 + cksel = pm_readl(CKSEL);
2507 + if (cksel & PM_BIT(CPUDIV))
2508 + shift = PM_BFEXT(CPUSEL, cksel) + 1;
2509
2510 return bus_clk_get_rate(clk, shift);
2511 }
2512
2513 +static long cpu_clk_set_rate(struct clk *clk, unsigned long rate, int apply)
2514 +{
2515 + u32 control;
2516 + unsigned long parent_rate, child_div, actual_rate, div;
2517 +
2518 + parent_rate = clk->parent->get_rate(clk->parent);
2519 + control = pm_readl(CKSEL);
2520 +
2521 + if (control & PM_BIT(HSBDIV))
2522 + child_div = 1 << (PM_BFEXT(HSBSEL, control) + 1);
2523 + else
2524 + child_div = 1;
2525 +
2526 + if (rate > 3 * (parent_rate / 4) || child_div == 1) {
2527 + actual_rate = parent_rate;
2528 + control &= ~PM_BIT(CPUDIV);
2529 + } else {
2530 + unsigned int cpusel;
2531 + div = (parent_rate + rate / 2) / rate;
2532 + if (div > child_div)
2533 + div = child_div;
2534 + cpusel = (div > 1) ? (fls(div) - 2) : 0;
2535 + control = PM_BIT(CPUDIV) | PM_BFINS(CPUSEL, cpusel, control);
2536 + actual_rate = parent_rate / (1 << (cpusel + 1));
2537 + }
2538 +
2539 + pr_debug("clk %s: new rate %lu (actual rate %lu)\n",
2540 + clk->name, rate, actual_rate);
2541 +
2542 + if (apply)
2543 + pm_writel(CKSEL, control);
2544 +
2545 + return actual_rate;
2546 +}
2547 +
2548 static void hsb_clk_mode(struct clk *clk, int enabled)
2549 {
2550 - struct at32_sm *sm = &system_manager;
2551 unsigned long flags;
2552 u32 mask;
2553
2554 - spin_lock_irqsave(&sm->lock, flags);
2555 - mask = sm_readl(sm, PM_HSB_MASK);
2556 + spin_lock_irqsave(&pm_lock, flags);
2557 + mask = pm_readl(HSB_MASK);
2558 if (enabled)
2559 mask |= 1 << clk->index;
2560 else
2561 mask &= ~(1 << clk->index);
2562 - sm_writel(sm, PM_HSB_MASK, mask);
2563 - spin_unlock_irqrestore(&sm->lock, flags);
2564 + pm_writel(HSB_MASK, mask);
2565 + spin_unlock_irqrestore(&pm_lock, flags);
2566 }
2567
2568 static unsigned long hsb_clk_get_rate(struct clk *clk)
2569 {
2570 unsigned long cksel, shift = 0;
2571
2572 - cksel = sm_readl(&system_manager, PM_CKSEL);
2573 - if (cksel & SM_BIT(HSBDIV))
2574 - shift = SM_BFEXT(HSBSEL, cksel) + 1;
2575 + cksel = pm_readl(CKSEL);
2576 + if (cksel & PM_BIT(HSBDIV))
2577 + shift = PM_BFEXT(HSBSEL, cksel) + 1;
2578
2579 return bus_clk_get_rate(clk, shift);
2580 }
2581
2582 static void pba_clk_mode(struct clk *clk, int enabled)
2583 {
2584 - struct at32_sm *sm = &system_manager;
2585 unsigned long flags;
2586 u32 mask;
2587
2588 - spin_lock_irqsave(&sm->lock, flags);
2589 - mask = sm_readl(sm, PM_PBA_MASK);
2590 + spin_lock_irqsave(&pm_lock, flags);
2591 + mask = pm_readl(PBA_MASK);
2592 if (enabled)
2593 mask |= 1 << clk->index;
2594 else
2595 mask &= ~(1 << clk->index);
2596 - sm_writel(sm, PM_PBA_MASK, mask);
2597 - spin_unlock_irqrestore(&sm->lock, flags);
2598 + pm_writel(PBA_MASK, mask);
2599 + spin_unlock_irqrestore(&pm_lock, flags);
2600 }
2601
2602 static unsigned long pba_clk_get_rate(struct clk *clk)
2603 {
2604 unsigned long cksel, shift = 0;
2605
2606 - cksel = sm_readl(&system_manager, PM_CKSEL);
2607 - if (cksel & SM_BIT(PBADIV))
2608 - shift = SM_BFEXT(PBASEL, cksel) + 1;
2609 + cksel = pm_readl(CKSEL);
2610 + if (cksel & PM_BIT(PBADIV))
2611 + shift = PM_BFEXT(PBASEL, cksel) + 1;
2612
2613 return bus_clk_get_rate(clk, shift);
2614 }
2615
2616 static void pbb_clk_mode(struct clk *clk, int enabled)
2617 {
2618 - struct at32_sm *sm = &system_manager;
2619 unsigned long flags;
2620 u32 mask;
2621
2622 - spin_lock_irqsave(&sm->lock, flags);
2623 - mask = sm_readl(sm, PM_PBB_MASK);
2624 + spin_lock_irqsave(&pm_lock, flags);
2625 + mask = pm_readl(PBB_MASK);
2626 if (enabled)
2627 mask |= 1 << clk->index;
2628 else
2629 mask &= ~(1 << clk->index);
2630 - sm_writel(sm, PM_PBB_MASK, mask);
2631 - spin_unlock_irqrestore(&sm->lock, flags);
2632 + pm_writel(PBB_MASK, mask);
2633 + spin_unlock_irqrestore(&pm_lock, flags);
2634 }
2635
2636 static unsigned long pbb_clk_get_rate(struct clk *clk)
2637 {
2638 unsigned long cksel, shift = 0;
2639
2640 - cksel = sm_readl(&system_manager, PM_CKSEL);
2641 - if (cksel & SM_BIT(PBBDIV))
2642 - shift = SM_BFEXT(PBBSEL, cksel) + 1;
2643 + cksel = pm_readl(CKSEL);
2644 + if (cksel & PM_BIT(PBBDIV))
2645 + shift = PM_BFEXT(PBBSEL, cksel) + 1;
2646
2647 return bus_clk_get_rate(clk, shift);
2648 }
2649 @@ -296,6 +335,7 @@ static unsigned long pbb_clk_get_rate(struct clk *clk)
2650 static struct clk cpu_clk = {
2651 .name = "cpu",
2652 .get_rate = cpu_clk_get_rate,
2653 + .set_rate = cpu_clk_set_rate,
2654 .users = 1,
2655 };
2656 static struct clk hsb_clk = {
2657 @@ -327,12 +367,12 @@ static void genclk_mode(struct clk *clk, int enabled)
2658 {
2659 u32 control;
2660
2661 - control = sm_readl(&system_manager, PM_GCCTRL + 4 * clk->index);
2662 + control = pm_readl(GCCTRL(clk->index));
2663 if (enabled)
2664 - control |= SM_BIT(CEN);
2665 + control |= PM_BIT(CEN);
2666 else
2667 - control &= ~SM_BIT(CEN);
2668 - sm_writel(&system_manager, PM_GCCTRL + 4 * clk->index, control);
2669 + control &= ~PM_BIT(CEN);
2670 + pm_writel(GCCTRL(clk->index), control);
2671 }
2672
2673 static unsigned long genclk_get_rate(struct clk *clk)
2674 @@ -340,9 +380,9 @@ static unsigned long genclk_get_rate(struct clk *clk)
2675 u32 control;
2676 unsigned long div = 1;
2677
2678 - control = sm_readl(&system_manager, PM_GCCTRL + 4 * clk->index);
2679 - if (control & SM_BIT(DIVEN))
2680 - div = 2 * (SM_BFEXT(DIV, control) + 1);
2681 + control = pm_readl(GCCTRL(clk->index));
2682 + if (control & PM_BIT(DIVEN))
2683 + div = 2 * (PM_BFEXT(DIV, control) + 1);
2684
2685 return clk->parent->get_rate(clk->parent) / div;
2686 }
2687 @@ -353,23 +393,22 @@ static long genclk_set_rate(struct clk *clk, unsigned long rate, int apply)
2688 unsigned long parent_rate, actual_rate, div;
2689
2690 parent_rate = clk->parent->get_rate(clk->parent);
2691 - control = sm_readl(&system_manager, PM_GCCTRL + 4 * clk->index);
2692 + control = pm_readl(GCCTRL(clk->index));
2693
2694 if (rate > 3 * parent_rate / 4) {
2695 actual_rate = parent_rate;
2696 - control &= ~SM_BIT(DIVEN);
2697 + control &= ~PM_BIT(DIVEN);
2698 } else {
2699 div = (parent_rate + rate) / (2 * rate) - 1;
2700 - control = SM_BFINS(DIV, div, control) | SM_BIT(DIVEN);
2701 + control = PM_BFINS(DIV, div, control) | PM_BIT(DIVEN);
2702 actual_rate = parent_rate / (2 * (div + 1));
2703 }
2704
2705 - printk("clk %s: new rate %lu (actual rate %lu)\n",
2706 - clk->name, rate, actual_rate);
2707 + dev_dbg(clk->dev, "clk %s: new rate %lu (actual rate %lu)\n",
2708 + clk->name, rate, actual_rate);
2709
2710 if (apply)
2711 - sm_writel(&system_manager, PM_GCCTRL + 4 * clk->index,
2712 - control);
2713 + pm_writel(GCCTRL(clk->index), control);
2714
2715 return actual_rate;
2716 }
2717 @@ -378,24 +417,24 @@ int genclk_set_parent(struct clk *clk, struct clk *parent)
2718 {
2719 u32 control;
2720
2721 - printk("clk %s: new parent %s (was %s)\n",
2722 - clk->name, parent->name, clk->parent->name);
2723 + dev_dbg(clk->dev, "clk %s: new parent %s (was %s)\n",
2724 + clk->name, parent->name, clk->parent->name);
2725
2726 - control = sm_readl(&system_manager, PM_GCCTRL + 4 * clk->index);
2727 + control = pm_readl(GCCTRL(clk->index));
2728
2729 if (parent == &osc1 || parent == &pll1)
2730 - control |= SM_BIT(OSCSEL);
2731 + control |= PM_BIT(OSCSEL);
2732 else if (parent == &osc0 || parent == &pll0)
2733 - control &= ~SM_BIT(OSCSEL);
2734 + control &= ~PM_BIT(OSCSEL);
2735 else
2736 return -EINVAL;
2737
2738 if (parent == &pll0 || parent == &pll1)
2739 - control |= SM_BIT(PLLSEL);
2740 + control |= PM_BIT(PLLSEL);
2741 else
2742 - control &= ~SM_BIT(PLLSEL);
2743 + control &= ~PM_BIT(PLLSEL);
2744
2745 - sm_writel(&system_manager, PM_GCCTRL + 4 * clk->index, control);
2746 + pm_writel(GCCTRL(clk->index), control);
2747 clk->parent = parent;
2748
2749 return 0;
2750 @@ -408,11 +447,11 @@ static void __init genclk_init_parent(struct clk *clk)
2751
2752 BUG_ON(clk->index > 7);
2753
2754 - control = sm_readl(&system_manager, PM_GCCTRL + 4 * clk->index);
2755 - if (control & SM_BIT(OSCSEL))
2756 - parent = (control & SM_BIT(PLLSEL)) ? &pll1 : &osc1;
2757 + control = pm_readl(GCCTRL(clk->index));
2758 + if (control & PM_BIT(OSCSEL))
2759 + parent = (control & PM_BIT(PLLSEL)) ? &pll1 : &osc1;
2760 else
2761 - parent = (control & SM_BIT(PLLSEL)) ? &pll0 : &osc0;
2762 + parent = (control & PM_BIT(PLLSEL)) ? &pll0 : &osc0;
2763
2764 clk->parent = parent;
2765 }
2766 @@ -420,21 +459,53 @@ static void __init genclk_init_parent(struct clk *clk)
2767 /* --------------------------------------------------------------------
2768 * System peripherals
2769 * -------------------------------------------------------------------- */
2770 -static struct resource sm_resource[] = {
2771 - PBMEM(0xfff00000),
2772 - NAMED_IRQ(19, "eim"),
2773 - NAMED_IRQ(20, "pm"),
2774 - NAMED_IRQ(21, "rtc"),
2775 -};
2776 -struct platform_device at32_sm_device = {
2777 - .name = "sm",
2778 - .id = 0,
2779 - .resource = sm_resource,
2780 - .num_resources = ARRAY_SIZE(sm_resource),
2781 +static struct resource at32_pm0_resource[] = {
2782 + {
2783 + .start = 0xfff00000,
2784 + .end = 0xfff0007f,
2785 + .flags = IORESOURCE_MEM,
2786 + },
2787 + IRQ(20),
2788 };
2789 -static struct clk at32_sm_pclk = {
2790 +
2791 +static struct resource at32ap700x_rtc0_resource[] = {
2792 + {
2793 + .start = 0xfff00080,
2794 + .end = 0xfff000af,
2795 + .flags = IORESOURCE_MEM,
2796 + },
2797 + IRQ(21),
2798 +};
2799 +
2800 +static struct resource at32_wdt0_resource[] = {
2801 + {
2802 + .start = 0xfff000b0,
2803 + .end = 0xfff000bf,
2804 + .flags = IORESOURCE_MEM,
2805 + },
2806 +};
2807 +
2808 +static struct resource at32_eic0_resource[] = {
2809 + {
2810 + .start = 0xfff00100,
2811 + .end = 0xfff0013f,
2812 + .flags = IORESOURCE_MEM,
2813 + },
2814 + IRQ(19),
2815 +};
2816 +
2817 +DEFINE_DEV(at32_pm, 0);
2818 +DEFINE_DEV(at32ap700x_rtc, 0);
2819 +DEFINE_DEV(at32_wdt, 0);
2820 +DEFINE_DEV(at32_eic, 0);
2821 +
2822 +/*
2823 + * Peripheral clock for PM, RTC, WDT and EIC. PM will ensure that this
2824 + * is always running.
2825 + */
2826 +static struct clk at32_pm_pclk = {
2827 .name = "pclk",
2828 - .dev = &at32_sm_device.dev,
2829 + .dev = &at32_pm0_device.dev,
2830 .parent = &pbb_clk,
2831 .mode = pbb_clk_mode,
2832 .get_rate = pbb_clk_get_rate,
2833 @@ -491,6 +562,17 @@ static struct clk pico_clk = {
2834 .users = 1,
2835 };
2836
2837 +static struct resource dmaca0_resource[] = {
2838 + {
2839 + .start = 0xff200000,
2840 + .end = 0xff20ffff,
2841 + .flags = IORESOURCE_MEM,
2842 + },
2843 + IRQ(2),
2844 +};
2845 +DEFINE_DEV(dmaca, 0);
2846 +DEV_CLK(hclk, dmaca0, hsb, 10);
2847 +
2848 /* --------------------------------------------------------------------
2849 * HMATRIX
2850 * -------------------------------------------------------------------- */
2851 @@ -583,12 +665,14 @@ DEV_CLK(mck, pio4, pba, 14);
2852
2853 void __init at32_add_system_devices(void)
2854 {
2855 - system_manager.eim_first_irq = EIM_IRQ_BASE;
2856 -
2857 - platform_device_register(&at32_sm_device);
2858 + platform_device_register(&at32_pm0_device);
2859 platform_device_register(&at32_intc0_device);
2860 + platform_device_register(&at32ap700x_rtc0_device);
2861 + platform_device_register(&at32_wdt0_device);
2862 + platform_device_register(&at32_eic0_device);
2863 platform_device_register(&smc0_device);
2864 platform_device_register(&pdc_device);
2865 + platform_device_register(&dmaca0_device);
2866
2867 platform_device_register(&at32_systc0_device);
2868
2869 @@ -894,6 +978,83 @@ at32_add_device_spi(unsigned int id, struct spi_board_info *b, unsigned int n)
2870 }
2871
2872 /* --------------------------------------------------------------------
2873 + * TWI
2874 + * -------------------------------------------------------------------- */
2875 +
2876 +static struct resource atmel_twi0_resource[] = {
2877 + PBMEM(0xffe00800),
2878 + IRQ(5),
2879 +};
2880 +DEFINE_DEV(atmel_twi, 0);
2881 +DEV_CLK(pclk,atmel_twi0,pba,2);
2882 +
2883 +struct platform_device *__init
2884 +at32_add_device_twi(unsigned int id)
2885 +{
2886 + struct platform_device *pdev;
2887 +
2888 + switch (id) {
2889 + case 0:
2890 + pdev = &atmel_twi0_device;
2891 + select_peripheral(PA(6), PERIPH_A, 0); /* SDA */
2892 + select_peripheral(PA(7), PERIPH_A, 0); /* SCL */
2893 + break;
2894 +
2895 + default:
2896 + return NULL;
2897 + }
2898 +
2899 + platform_device_register(pdev);
2900 + return pdev;
2901 +}
2902 +
2903 +/* --------------------------------------------------------------------
2904 + * MMC
2905 + * -------------------------------------------------------------------- */
2906 +static struct mci_platform_data atmel_mci0_data = {
2907 + .detect_pin = GPIO_PIN_NONE,
2908 + .wp_pin = GPIO_PIN_NONE,
2909 +};
2910 +static struct resource atmel_mci0_resource[] = {
2911 + PBMEM(0xfff02400),
2912 + IRQ(28),
2913 +};
2914 +DEFINE_DEV_DATA(atmel_mci, 0);
2915 +DEV_CLK(mci_clk, atmel_mci0, pbb, 9);
2916 +
2917 +struct platform_device *__init
2918 +at32_add_device_mci(unsigned int id, struct mci_platform_data *data)
2919 +{
2920 + struct platform_device *pdev;
2921 +
2922 + switch (id) {
2923 + case 0:
2924 + pdev = &atmel_mci0_device;
2925 + select_peripheral(PA(10), PERIPH_A, 0); /* CLK */
2926 + select_peripheral(PA(11), PERIPH_A, 0); /* CMD */
2927 + select_peripheral(PA(12), PERIPH_A, 0); /* DATA0 */
2928 + select_peripheral(PA(13), PERIPH_A, 0); /* DATA1 */
2929 + select_peripheral(PA(14), PERIPH_A, 0); /* DATA2 */
2930 + select_peripheral(PA(15), PERIPH_A, 0); /* DATA3 */
2931 + break;
2932 + default:
2933 + return NULL;
2934 + }
2935 +
2936 + if (data) {
2937 + if (data->detect_pin != GPIO_PIN_NONE)
2938 + at32_select_gpio(data->detect_pin, 0);
2939 + if (data->wp_pin != GPIO_PIN_NONE)
2940 + at32_select_gpio(data->wp_pin, 0);
2941 + memcpy(pdev->dev.platform_data, data,
2942 + sizeof(struct mci_platform_data));
2943 + }
2944 +
2945 + platform_device_register(pdev);
2946 + return pdev;
2947 +}
2948 +
2949 +/* --------------------------------------------------------------------
2950 * LCDC
2951 * -------------------------------------------------------------------- */
2952 static struct atmel_lcdfb_info atmel_lcdfb0_data;
2953 @@ -1013,6 +1174,228 @@ err_dup_modedb:
2954 }
2955
2956 /* --------------------------------------------------------------------
2957 + * USB Device Controller
2958 + * -------------------------------------------------------------------- */
2959 +static struct resource usba0_resource[] __initdata = {
2960 + {
2961 + .name = "fifo",
2962 + .start = 0xff300000,
2963 + .end = 0xff3fffff,
2964 + .flags = IORESOURCE_MEM,
2965 + }, {
2966 + .name = "regs",
2967 + .start = 0xfff03000,
2968 + .end = 0xfff033ff,
2969 + .flags = IORESOURCE_MEM,
2970 + },
2971 + IRQ(31),
2972 +};
2973 +static struct clk usba0_pclk = {
2974 + .name = "pclk",
2975 + .parent = &pbb_clk,
2976 + .mode = pbb_clk_mode,
2977 + .get_rate = pbb_clk_get_rate,
2978 + .index = 12,
2979 +};
2980 +static struct clk usba0_hclk = {
2981 + .name = "hclk",
2982 + .parent = &hsb_clk,
2983 + .mode = hsb_clk_mode,
2984 + .get_rate = hsb_clk_get_rate,
2985 + .index = 6,
2986 +};
2987 +
2988 +struct platform_device *__init
2989 +at32_add_device_usba(unsigned int id, struct usba_platform_data *data)
2990 +{
2991 + struct platform_device *pdev;
2992 +
2993 + if (id != 0)
2994 + return NULL;
2995 +
2996 + pdev = platform_device_alloc("atmel_usba_udc", 0);
2997 + if (!pdev)
2998 + return NULL;
2999 +
3000 + if (platform_device_add_resources(pdev, usba0_resource,
3001 + ARRAY_SIZE(usba0_resource)))
3002 + goto out_free_pdev;
3003 +
3004 + if (data) {
3005 + if (platform_device_add_data(pdev, data, sizeof(*data)))
3006 + goto out_free_pdev;
3007 +
3008 + if (data->vbus_pin != GPIO_PIN_NONE)
3009 + at32_select_gpio(data->vbus_pin, 0);
3010 + }
3011 +
3012 + usba0_pclk.dev = &pdev->dev;
3013 + usba0_hclk.dev = &pdev->dev;
3014 +
3015 + platform_device_add(pdev);
3016 +
3017 + return pdev;
3018 +
3019 +out_free_pdev:
3020 + platform_device_put(pdev);
3021 + return NULL;
3022 +}
3023 +
3024 +/* --------------------------------------------------------------------
3025 + * SSC
3026 + * -------------------------------------------------------------------- */
3027 +static struct resource ssc0_resource[] = {
3028 + PBMEM(0xffe01c00),
3029 + IRQ(10),
3030 +};
3031 +DEFINE_DEV(ssc, 0);
3032 +DEV_CLK(pclk, ssc0, pba, 7);
3033 +
3034 +static struct resource ssc1_resource[] = {
3035 + PBMEM(0xffe02000),
3036 + IRQ(11),
3037 +};
3038 +DEFINE_DEV(ssc, 1);
3039 +DEV_CLK(pclk, ssc1, pba, 8);
3040 +
3041 +static struct resource ssc2_resource[] = {
3042 + PBMEM(0xffe02400),
3043 + IRQ(12),
3044 +};
3045 +DEFINE_DEV(ssc, 2);
3046 +DEV_CLK(pclk, ssc2, pba, 9);
3047 +
3048 +struct platform_device *__init
3049 +at32_add_device_ssc(unsigned int id, unsigned int flags)
3050 +{
3051 + struct platform_device *pdev;
3052 +
3053 + switch (id) {
3054 + case 0:
3055 + pdev = &ssc0_device;
3056 + if (flags & ATMEL_SSC_RF)
3057 + select_peripheral(PA(21), PERIPH_A, 0); /* RF */
3058 + if (flags & ATMEL_SSC_RK)
3059 + select_peripheral(PA(22), PERIPH_A, 0); /* RK */
3060 + if (flags & ATMEL_SSC_TK)
3061 + select_peripheral(PA(23), PERIPH_A, 0); /* TK */
3062 + if (flags & ATMEL_SSC_TF)
3063 + select_peripheral(PA(24), PERIPH_A, 0); /* TF */
3064 + if (flags & ATMEL_SSC_TD)
3065 + select_peripheral(PA(25), PERIPH_A, 0); /* TD */
3066 + if (flags & ATMEL_SSC_RD)
3067 + select_peripheral(PA(26), PERIPH_A, 0); /* RD */
3068 + break;
3069 + case 1:
3070 + pdev = &ssc1_device;
3071 + if (flags & ATMEL_SSC_RF)
3072 + select_peripheral(PA(0), PERIPH_B, 0); /* RF */
3073 + if (flags & ATMEL_SSC_RK)
3074 + select_peripheral(PA(1), PERIPH_B, 0); /* RK */
3075 + if (flags & ATMEL_SSC_TK)
3076 + select_peripheral(PA(2), PERIPH_B, 0); /* TK */
3077 + if (flags & ATMEL_SSC_TF)
3078 + select_peripheral(PA(3), PERIPH_B, 0); /* TF */
3079 + if (flags & ATMEL_SSC_TD)
3080 + select_peripheral(PA(4), PERIPH_B, 0); /* TD */
3081 + if (flags & ATMEL_SSC_RD)
3082 + select_peripheral(PA(5), PERIPH_B, 0); /* RD */
3083 + break;
3084 + case 2:
3085 + pdev = &ssc2_device;
3086 + if (flags & ATMEL_SSC_TD)
3087 + select_peripheral(PB(13), PERIPH_A, 0); /* TD */
3088 + if (flags & ATMEL_SSC_RD)
3089 + select_peripheral(PB(14), PERIPH_A, 0); /* RD */
3090 + if (flags & ATMEL_SSC_TK)
3091 + select_peripheral(PB(15), PERIPH_A, 0); /* TK */
3092 + if (flags & ATMEL_SSC_TF)
3093 + select_peripheral(PB(16), PERIPH_A, 0); /* TF */
3094 + if (flags & ATMEL_SSC_RF)
3095 + select_peripheral(PB(17), PERIPH_A, 0); /* RF */
3096 + if (flags & ATMEL_SSC_RK)
3097 + select_peripheral(PB(18), PERIPH_A, 0); /* RK */
3098 + break;
3099 + default:
3100 + return NULL;
3101 + }
3102 +
3103 + platform_device_register(pdev);
3104 + return pdev;
3105 +}
3106 +
3107 +/* --------------------------------------------------------------------
3108 + * AC97C
3109 + * -------------------------------------------------------------------- */
3110 +static struct resource atmel_ac97c0_resource[] = {
3111 + PBMEM(0xfff02800),
3112 + IRQ(29),
3113 +};
3114 +DEFINE_DEV(atmel_ac97c, 0);
3115 +DEV_CLK(pclk, atmel_ac97c0, pbb, 10);
3116 +
3117 +struct platform_device *__init
3118 +at32_add_device_ac97c(unsigned int id)
3119 +{
3120 + struct platform_device *pdev;
3121 +
3122 + switch (id) {
3123 + case 0:
3124 + pdev = &atmel_ac97c0_device;
3125 + select_peripheral(PB(20), PERIPH_B, 0); /* SYNC */
3126 + select_peripheral(PB(21), PERIPH_B, 0); /* SDO */
3127 + select_peripheral(PB(22), PERIPH_B, 0); /* SDI */
3128 + select_peripheral(PB(23), PERIPH_B, 0); /* SCLK */
3129 + break;
3130 + default:
3131 + return NULL;
3132 + }
3133 +
3134 + platform_device_register(pdev);
3135 + return pdev;
3136 +}
3137 +
3138 +/* --------------------------------------------------------------------
3139 + * DAC
3140 + * -------------------------------------------------------------------- */
3141 +static struct resource abdac0_resource[] = {
3142 + PBMEM(0xfff02000),
3143 + IRQ(27),
3144 +};
3145 +DEFINE_DEV(abdac, 0);
3146 +DEV_CLK(pclk, abdac0, pbb, 8);
3147 +static struct clk abdac0_sample_clk = {
3148 + .name = "sample_clk",
3149 + .dev = &abdac0_device.dev,
3150 + .mode = genclk_mode,
3151 + .get_rate = genclk_get_rate,
3152 + .set_rate = genclk_set_rate,
3153 + .set_parent = genclk_set_parent,
3154 + .index = 6,
3155 +};
3156 +
3157 +struct platform_device *__init
3158 +at32_add_device_abdac(unsigned int id)
3159 +{
3160 + struct platform_device *pdev;
3161 +
3162 + switch (id) {
3163 + case 0:
3164 + pdev = &abdac0_device;
3165 + select_peripheral(PB(20), PERIPH_A, 0); /* DATA1 */
3166 + select_peripheral(PB(21), PERIPH_A, 0); /* DATA0 */
3167 + select_peripheral(PB(22), PERIPH_A, 0); /* DATAN1 */
3168 + select_peripheral(PB(23), PERIPH_A, 0); /* DATAN0 */
3169 + break;
3170 + default:
3171 + return NULL;
3172 + }
3173 +
3174 + platform_device_register(pdev);
3175 + return pdev;
3176 +}
3177 +
3178 +/* --------------------------------------------------------------------
3179 * GCLK
3180 * -------------------------------------------------------------------- */
3181 static struct clk gclk0 = {
3182 @@ -1066,7 +1449,7 @@ struct clk *at32_clock_list[] = {
3183 &hsb_clk,
3184 &pba_clk,
3185 &pbb_clk,
3186 - &at32_sm_pclk,
3187 + &at32_pm_pclk,
3188 &at32_intc0_pclk,
3189 &hmatrix_clk,
3190 &ebi_clk,
3191 @@ -1075,6 +1458,7 @@ struct clk *at32_clock_list[] = {
3192 &smc0_mck,
3193 &pdc_hclk,
3194 &pdc_pclk,
3195 + &dmaca0_hclk,
3196 &pico_clk,
3197 &pio0_mck,
3198 &pio1_mck,
3199 @@ -1092,8 +1476,18 @@ struct clk *at32_clock_list[] = {
3200 &macb1_pclk,
3201 &atmel_spi0_spi_clk,
3202 &atmel_spi1_spi_clk,
3203 + &atmel_twi0_pclk,
3204 + &atmel_mci0_mci_clk,
3205 &atmel_lcdfb0_hck1,
3206 &atmel_lcdfb0_pixclk,
3207 + &usba0_pclk,
3208 + &usba0_hclk,
3209 + &ssc0_pclk,
3210 + &ssc1_pclk,
3211 + &ssc2_pclk,
3212 + &atmel_ac97c0_pclk,
3213 + &abdac0_pclk,
3214 + &abdac0_sample_clk,
3215 &gclk0,
3216 &gclk1,
3217 &gclk2,
3218 @@ -1113,18 +1507,20 @@ void __init at32_portmux_init(void)
3219
3220 void __init at32_clock_init(void)
3221 {
3222 - struct at32_sm *sm = &system_manager;
3223 u32 cpu_mask = 0, hsb_mask = 0, pba_mask = 0, pbb_mask = 0;
3224 int i;
3225
3226 - if (sm_readl(sm, PM_MCCTRL) & SM_BIT(PLLSEL))
3227 + if (pm_readl(MCCTRL) & PM_BIT(PLLSEL)) {
3228 main_clock = &pll0;
3229 - else
3230 + cpu_clk.parent = &pll0;
3231 + } else {
3232 main_clock = &osc0;
3233 + cpu_clk.parent = &osc0;
3234 + }
3235
3236 - if (sm_readl(sm, PM_PLL0) & SM_BIT(PLLOSC))
3237 + if (pm_readl(PLL0) & PM_BIT(PLLOSC))
3238 pll0.parent = &osc1;
3239 - if (sm_readl(sm, PM_PLL1) & SM_BIT(PLLOSC))
3240 + if (pm_readl(PLL1) & PM_BIT(PLLOSC))
3241 pll1.parent = &osc1;
3242
3243 genclk_init_parent(&gclk0);
3244 @@ -1133,6 +1529,7 @@ void __init at32_clock_init(void)
3245 genclk_init_parent(&gclk3);
3246 genclk_init_parent(&gclk4);
3247 genclk_init_parent(&atmel_lcdfb0_pixclk);
3248 + genclk_init_parent(&abdac0_sample_clk);
3249
3250 /*
3251 * Turn on all clocks that have at least one user already, and
3252 @@ -1157,8 +1554,8 @@ void __init at32_clock_init(void)
3253 pbb_mask |= 1 << clk->index;
3254 }
3255
3256 - sm_writel(sm, PM_CPU_MASK, cpu_mask);
3257 - sm_writel(sm, PM_HSB_MASK, hsb_mask);
3258 - sm_writel(sm, PM_PBA_MASK, pba_mask);
3259 - sm_writel(sm, PM_PBB_MASK, pbb_mask);
3260 + pm_writel(CPU_MASK, cpu_mask);
3261 + pm_writel(HSB_MASK, hsb_mask);
3262 + pm_writel(PBA_MASK, pba_mask);
3263 + pm_writel(PBB_MASK, pbb_mask);
3264 }
3265 diff --git a/arch/avr32/mach-at32ap/cpufreq.c b/arch/avr32/mach-at32ap/cpufreq.c
3266 new file mode 100644
3267 index 0000000..235524b
3268 --- /dev/null
3269 +++ b/arch/avr32/mach-at32ap/cpufreq.c
3270 @@ -0,0 +1,112 @@
3271 +/*
3272 + * Copyright (C) 2004-2007 Atmel Corporation
3273 + *
3274 + * Based on MIPS implementation arch/mips/kernel/time.c
3275 + * Copyright 2001 MontaVista Software Inc.
3276 + *
3277 + * This program is free software; you can redistribute it and/or modify
3278 + * it under the terms of the GNU General Public License version 2 as
3279 + * published by the Free Software Foundation.
3280 + */
3281 +
3282 +/*#define DEBUG*/
3283 +
3284 +#include <linux/kernel.h>
3285 +#include <linux/types.h>
3286 +#include <linux/init.h>
3287 +#include <linux/cpufreq.h>
3288 +#include <linux/io.h>
3289 +#include <linux/clk.h>
3290 +#include <linux/err.h>
3291 +#include <asm/system.h>
3292 +
3293 +static struct clk *cpuclk;
3294 +
3295 +static int at32_verify_speed(struct cpufreq_policy *policy)
3296 +{
3297 + if (policy->cpu != 0)
3298 + return -EINVAL;
3299 +
3300 + cpufreq_verify_within_limits(policy, policy->cpuinfo.min_freq,
3301 + policy->cpuinfo.max_freq);
3302 + return 0;
3303 +}
3304 +
3305 +static unsigned int at32_get_speed(unsigned int cpu)
3306 +{
3307 + /* No SMP support */
3308 + if (cpu)
3309 + return 0;
3310 + return (unsigned int)((clk_get_rate(cpuclk) + 500) / 1000);
3311 +}
3312 +
3313 +static int at32_set_target(struct cpufreq_policy *policy,
3314 + unsigned int target_freq,
3315 + unsigned int relation)
3316 +{
3317 + struct cpufreq_freqs freqs;
3318 + long freq;
3319 +
3320 + /* Convert target_freq from kHz to Hz */
3321 + freq = clk_round_rate(cpuclk, target_freq * 1000);
3322 +
3323 + /* Check if policy->min <= new_freq <= policy->max */
3324 + if(freq < (policy->min * 1000) || freq > (policy->max * 1000))
3325 + return -EINVAL;
3326 +
3327 + pr_debug("cpufreq: requested frequency %u Hz\n", target_freq * 1000);
3328 +
3329 + freqs.old = at32_get_speed(0);
3330 + freqs.new = (freq + 500) / 1000;
3331 + freqs.cpu = 0;
3332 + freqs.flags = 0;
3333 +
3334 + cpufreq_notify_transition(&freqs, CPUFREQ_PRECHANGE);
3335 + clk_set_rate(cpuclk, freq);
3336 + cpufreq_notify_transition(&freqs, CPUFREQ_POSTCHANGE);
3337 +
3338 + pr_debug("cpufreq: set frequency %lu Hz\n", freq);
3339 +
3340 + return 0;
3341 +}
3342 +
3343 +static int __init at32_cpufreq_driver_init(struct cpufreq_policy *policy)
3344 +{
3345 + if (policy->cpu != 0)
3346 + return -EINVAL;
3347 +
3348 + cpuclk = clk_get(NULL, "cpu");
3349 + if (IS_ERR(cpuclk)) {
3350 + pr_debug("cpufreq: could not get CPU clk\n");
3351 + return PTR_ERR(cpuclk);
3352 + }
3353 +
3354 + policy->cpuinfo.min_freq = (clk_round_rate(cpuclk, 1) + 500) / 1000;
3355 + policy->cpuinfo.max_freq = (clk_round_rate(cpuclk, ~0UL) + 500) / 1000;
3356 + policy->cpuinfo.transition_latency = 0;
3357 + policy->cur = at32_get_speed(0);
3358 + policy->min = policy->cpuinfo.min_freq;
3359 + policy->max = policy->cpuinfo.max_freq;
3360 + policy->governor = CPUFREQ_DEFAULT_GOVERNOR;
3361 +
3362 + printk("cpufreq: AT32AP CPU frequency driver\n");
3363 +
3364 + return 0;
3365 +}
3366 +
3367 +static struct cpufreq_driver at32_driver = {
3368 + .name = "at32ap",
3369 + .owner = THIS_MODULE,
3370 + .init = at32_cpufreq_driver_init,
3371 + .verify = at32_verify_speed,
3372 + .target = at32_set_target,
3373 + .get = at32_get_speed,
3374 + .flags = CPUFREQ_STICKY,
3375 +};
3376 +
3377 +static int __init at32_cpufreq_init(void)
3378 +{
3379 + return cpufreq_register_driver(&at32_driver);
3380 +}
3381 +
3382 +arch_initcall(at32_cpufreq_init);
3383 diff --git a/arch/avr32/mach-at32ap/extint.c b/arch/avr32/mach-at32ap/extint.c
3384 index 4a60ecc..8acd010 100644
3385 --- a/arch/avr32/mach-at32ap/extint.c
3386 +++ b/arch/avr32/mach-at32ap/extint.c
3387 @@ -17,42 +17,83 @@
3388
3389 #include <asm/io.h>
3390
3391 -#include <asm/arch/sm.h>
3392 -
3393 -#include "sm.h"
3394 +/* EIC register offsets */
3395 +#define EIC_IER 0x0000
3396 +#define EIC_IDR 0x0004
3397 +#define EIC_IMR 0x0008
3398 +#define EIC_ISR 0x000c
3399 +#define EIC_ICR 0x0010
3400 +#define EIC_MODE 0x0014
3401 +#define EIC_EDGE 0x0018
3402 +#define EIC_LEVEL 0x001c
3403 +#define EIC_TEST 0x0020
3404 +#define EIC_NMIC 0x0024
3405 +
3406 +/* Bitfields in TEST */
3407 +#define EIC_TESTEN_OFFSET 31
3408 +#define EIC_TESTEN_SIZE 1
3409 +
3410 +/* Bitfields in NMIC */
3411 +#define EIC_EN_OFFSET 0
3412 +#define EIC_EN_SIZE 1
3413 +
3414 +/* Bit manipulation macros */
3415 +#define EIC_BIT(name) \
3416 + (1 << EIC_##name##_OFFSET)
3417 +#define EIC_BF(name,value) \
3418 + (((value) & ((1 << EIC_##name##_SIZE) - 1)) \
3419 + << EIC_##name##_OFFSET)
3420 +#define EIC_BFEXT(name,value) \
3421 + (((value) >> EIC_##name##_OFFSET) \
3422 + & ((1 << EIC_##name##_SIZE) - 1))
3423 +#define EIC_BFINS(name,value,old) \
3424 + (((old) & ~(((1 << EIC_##name##_SIZE) - 1) \
3425 + << EIC_##name##_OFFSET)) \
3426 + | EIC_BF(name,value))
3427 +
3428 +/* Register access macros */
3429 +#define eic_readl(port,reg) \
3430 + __raw_readl((port)->regs + EIC_##reg)
3431 +#define eic_writel(port,reg,value) \
3432 + __raw_writel((value), (port)->regs + EIC_##reg)
3433 +
3434 +struct eic {
3435 + void __iomem *regs;
3436 + struct irq_chip *chip;
3437 + unsigned int first_irq;
3438 +};
3439
3440 -static void eim_ack_irq(unsigned int irq)
3441 +static void eic_ack_irq(unsigned int irq)
3442 {
3443 - struct at32_sm *sm = get_irq_chip_data(irq);
3444 - sm_writel(sm, EIM_ICR, 1 << (irq - sm->eim_first_irq));
3445 + struct eic *eic = get_irq_chip_data(irq);
3446 + eic_writel(eic, ICR, 1 << (irq - eic->first_irq));
3447 }
3448
3449 -static void eim_mask_irq(unsigned int irq)
3450 +static void eic_mask_irq(unsigned int irq)
3451 {
3452 - struct at32_sm *sm = get_irq_chip_data(irq);
3453 - sm_writel(sm, EIM_IDR, 1 << (irq - sm->eim_first_irq));
3454 + struct eic *eic = get_irq_chip_data(irq);
3455 + eic_writel(eic, IDR, 1 << (irq - eic->first_irq));
3456 }
3457
3458 -static void eim_mask_ack_irq(unsigned int irq)
3459 +static void eic_mask_ack_irq(unsigned int irq)
3460 {
3461 - struct at32_sm *sm = get_irq_chip_data(irq);
3462 - sm_writel(sm, EIM_ICR, 1 << (irq - sm->eim_first_irq));
3463 - sm_writel(sm, EIM_IDR, 1 << (irq - sm->eim_first_irq));
3464 + struct eic *eic = get_irq_chip_data(irq);
3465 + eic_writel(eic, ICR, 1 << (irq - eic->first_irq));
3466 + eic_writel(eic, IDR, 1 << (irq - eic->first_irq));
3467 }
3468
3469 -static void eim_unmask_irq(unsigned int irq)
3470 +static void eic_unmask_irq(unsigned int irq)
3471 {
3472 - struct at32_sm *sm = get_irq_chip_data(irq);
3473 - sm_writel(sm, EIM_IER, 1 << (irq - sm->eim_first_irq));
3474 + struct eic *eic = get_irq_chip_data(irq);
3475 + eic_writel(eic, IER, 1 << (irq - eic->first_irq));
3476 }
3477
3478 -static int eim_set_irq_type(unsigned int irq, unsigned int flow_type)
3479 +static int eic_set_irq_type(unsigned int irq, unsigned int flow_type)
3480 {
3481 - struct at32_sm *sm = get_irq_chip_data(irq);
3482 + struct eic *eic = get_irq_chip_data(irq);
3483 struct irq_desc *desc;
3484 - unsigned int i = irq - sm->eim_first_irq;
3485 + unsigned int i = irq - eic->first_irq;
3486 u32 mode, edge, level;
3487 - unsigned long flags;
3488 int ret = 0;
3489
3490 flow_type &= IRQ_TYPE_SENSE_MASK;
3491 @@ -60,11 +101,10 @@ static int eim_set_irq_type(unsigned int irq, unsigned int flow_type)
3492 flow_type = IRQ_TYPE_LEVEL_LOW;
3493
3494 desc = &irq_desc[irq];
3495 - spin_lock_irqsave(&sm->lock, flags);
3496
3497 - mode = sm_readl(sm, EIM_MODE);
3498 - edge = sm_readl(sm, EIM_EDGE);
3499 - level = sm_readl(sm, EIM_LEVEL);
3500 + mode = eic_readl(eic, MODE);
3501 + edge = eic_readl(eic, EDGE);
3502 + level = eic_readl(eic, LEVEL);
3503
3504 switch (flow_type) {
3505 case IRQ_TYPE_LEVEL_LOW:
3506 @@ -89,9 +129,9 @@ static int eim_set_irq_type(unsigned int irq, unsigned int flow_type)
3507 }
3508
3509 if (ret == 0) {
3510 - sm_writel(sm, EIM_MODE, mode);
3511 - sm_writel(sm, EIM_EDGE, edge);
3512 - sm_writel(sm, EIM_LEVEL, level);
3513 + eic_writel(eic, MODE, mode);
3514 + eic_writel(eic, EDGE, edge);
3515 + eic_writel(eic, LEVEL, level);
3516
3517 if (flow_type & (IRQ_TYPE_LEVEL_LOW | IRQ_TYPE_LEVEL_HIGH))
3518 flow_type |= IRQ_LEVEL;
3519 @@ -99,35 +139,33 @@ static int eim_set_irq_type(unsigned int irq, unsigned int flow_type)
3520 desc->status |= flow_type;
3521 }
3522
3523 - spin_unlock_irqrestore(&sm->lock, flags);
3524 -
3525 return ret;
3526 }
3527
3528 -struct irq_chip eim_chip = {
3529 - .name = "eim",
3530 - .ack = eim_ack_irq,
3531 - .mask = eim_mask_irq,
3532 - .mask_ack = eim_mask_ack_irq,
3533 - .unmask = eim_unmask_irq,
3534 - .set_type = eim_set_irq_type,
3535 +struct irq_chip eic_chip = {
3536 + .name = "eic",
3537 + .ack = eic_ack_irq,
3538 + .mask = eic_mask_irq,
3539 + .mask_ack = eic_mask_ack_irq,
3540 + .unmask = eic_unmask_irq,
3541 + .set_type = eic_set_irq_type,
3542 };
3543
3544 -static void demux_eim_irq(unsigned int irq, struct irq_desc *desc)
3545 +static void demux_eic_irq(unsigned int irq, struct irq_desc *desc)
3546 {
3547 - struct at32_sm *sm = desc->handler_data;
3548 + struct eic *eic = desc->handler_data;
3549 struct irq_desc *ext_desc;
3550 unsigned long status, pending;
3551 unsigned int i, ext_irq;
3552
3553 - status = sm_readl(sm, EIM_ISR);
3554 - pending = status & sm_readl(sm, EIM_IMR);
3555 + status = eic_readl(eic, ISR);
3556 + pending = status & eic_readl(eic, IMR);
3557
3558 while (pending) {
3559 i = fls(pending) - 1;
3560 pending &= ~(1 << i);
3561
3562 - ext_irq = i + sm->eim_first_irq;
3563 + ext_irq = i + eic->first_irq;
3564 ext_desc = irq_desc + ext_irq;
3565 if (ext_desc->status & IRQ_LEVEL)
3566 handle_level_irq(ext_irq, ext_desc);
3567 @@ -136,51 +174,85 @@ static void demux_eim_irq(unsigned int irq, struct irq_desc *desc)
3568 }
3569 }
3570
3571 -static int __init eim_init(void)
3572 +static int __init eic_probe(struct platform_device *pdev)
3573 {
3574 - struct at32_sm *sm = &system_manager;
3575 + struct eic *eic;
3576 + struct resource *regs;
3577 unsigned int i;
3578 unsigned int nr_irqs;
3579 unsigned int int_irq;
3580 + int ret;
3581 u32 pattern;
3582
3583 - /*
3584 - * The EIM is really the same module as SM, so register
3585 - * mapping, etc. has been taken care of already.
3586 - */
3587 + regs = platform_get_resource(pdev, IORESOURCE_MEM, 0);
3588 + int_irq = platform_get_irq(pdev, 0);
3589 + if (!regs || !int_irq) {
3590 + dev_dbg(&pdev->dev, "missing regs and/or irq resource\n");
3591 + return -ENXIO;
3592 + }
3593 +
3594 + ret = -ENOMEM;
3595 + eic = kzalloc(sizeof(struct eic), GFP_KERNEL);
3596 + if (!eic) {
3597 + dev_dbg(&pdev->dev, "no memory for eic structure\n");
3598 + goto err_kzalloc;
3599 + }
3600 +
3601 + eic->first_irq = EIM_IRQ_BASE + 32 * pdev->id;
3602 + eic->regs = ioremap(regs->start, regs->end - regs->start + 1);
3603 + if (!eic->regs) {
3604 + dev_dbg(&pdev->dev, "failed to map regs\n");
3605 + goto err_ioremap;
3606 + }
3607
3608 /*
3609 * Find out how many interrupt lines that are actually
3610 * implemented in hardware.
3611 */
3612 - sm_writel(sm, EIM_IDR, ~0UL);
3613 - sm_writel(sm, EIM_MODE, ~0UL);
3614 - pattern = sm_readl(sm, EIM_MODE);
3615 + eic_writel(eic, IDR, ~0UL);
3616 + eic_writel(eic, MODE, ~0UL);
3617 + pattern = eic_readl(eic, MODE);
3618 nr_irqs = fls(pattern);
3619
3620 /* Trigger on falling edge unless overridden by driver */
3621 - sm_writel(sm, EIM_MODE, 0UL);
3622 - sm_writel(sm, EIM_EDGE, 0UL);
3623 + eic_writel(eic, MODE, 0UL);
3624 + eic_writel(eic, EDGE, 0UL);
3625
3626 - sm->eim_chip = &eim_chip;
3627 + eic->chip = &eic_chip;
3628
3629 for (i = 0; i < nr_irqs; i++) {
3630 /* NOTE the handler we set here is ignored by the demux */
3631 - set_irq_chip_and_handler(sm->eim_first_irq + i, &eim_chip,
3632 + set_irq_chip_and_handler(eic->first_irq + i, &eic_chip,
3633 handle_level_irq);
3634 - set_irq_chip_data(sm->eim_first_irq + i, sm);
3635 + set_irq_chip_data(eic->first_irq + i, eic);
3636 }
3637
3638 - int_irq = platform_get_irq_byname(sm->pdev, "eim");
3639 -
3640 - set_irq_chained_handler(int_irq, demux_eim_irq);
3641 - set_irq_data(int_irq, sm);
3642 + set_irq_chained_handler(int_irq, demux_eic_irq);
3643 + set_irq_data(int_irq, eic);
3644
3645 - printk("EIM: External Interrupt Module at 0x%p, IRQ %u\n",
3646 - sm->regs, int_irq);
3647 - printk("EIM: Handling %u external IRQs, starting with IRQ %u\n",
3648 - nr_irqs, sm->eim_first_irq);
3649 + dev_info(&pdev->dev,
3650 + "External Interrupt Controller at 0x%p, IRQ %u\n",
3651 + eic->regs, int_irq);
3652 + dev_info(&pdev->dev,
3653 + "Handling %u external IRQs, starting with IRQ %u\n",
3654 + nr_irqs, eic->first_irq);
3655
3656 return 0;
3657 +
3658 +err_ioremap:
3659 + kfree(eic);
3660 +err_kzalloc:
3661 + return ret;
3662 +}
3663 +
3664 +static struct platform_driver eic_driver = {
3665 + .driver = {
3666 + .name = "at32_eic",
3667 + },
3668 +};
3669 +
3670 +static int __init eic_init(void)
3671 +{
3672 + return platform_driver_probe(&eic_driver, eic_probe);
3673 }
3674 -arch_initcall(eim_init);
3675 +arch_initcall(eic_init);
3676 diff --git a/arch/avr32/mach-at32ap/gpio-dev.c b/arch/avr32/mach-at32ap/gpio-dev.c
3677 new file mode 100644
3678 index 0000000..3d4810d
3679 --- /dev/null
3680 +++ b/arch/avr32/mach-at32ap/gpio-dev.c
3681 @@ -0,0 +1,570 @@
3682 +/*
3683 + * GPIO /dev and configfs interface
3684 + *
3685 + * Copyright (C) 2006-2007 Atmel Corporation
3686 + *
3687 + * This program is free software; you can redistribute it and/or modify
3688 + * it under the terms of the GNU General Public License version 2 as
3689 + * published by the Free Software Foundation.
3690 + */
3691 +#include <linux/configfs.h>
3692 +#include <linux/cdev.h>
3693 +#include <linux/fs.h>
3694 +#include <linux/interrupt.h>
3695 +#include <linux/poll.h>
3696 +#include <linux/uaccess.h>
3697 +#include <linux/wait.h>
3698 +
3699 +#include <asm/gpio.h>
3700 +#include <asm/arch/portmux.h>
3701 +
3702 +#define GPIO_DEV_MAX 8
3703 +
3704 +static struct class *gpio_dev_class;
3705 +static dev_t gpio_devt;
3706 +
3707 +struct gpio_item {
3708 + spinlock_t lock;
3709 +
3710 + int enabled;
3711 + int initialized;
3712 + int port;
3713 + u32 pin_mask;
3714 + u32 oe_mask;
3715 +
3716 + /* Pin state last time we read it (for blocking reads) */
3717 + u32 pin_state;
3718 + int changed;
3719 +
3720 + wait_queue_head_t change_wq;
3721 + struct fasync_struct *async_queue;
3722 +
3723 + int id;
3724 + struct class_device *gpio_dev;
3725 + struct cdev char_dev;
3726 + struct config_item item;
3727 +};
3728 +
3729 +struct gpio_attribute {
3730 + struct configfs_attribute attr;
3731 + ssize_t (*show)(struct gpio_item *, char *);
3732 + ssize_t (*store)(struct gpio_item *, const char *, size_t);
3733 +};
3734 +
3735 +static irqreturn_t gpio_dev_interrupt(int irq, void *dev_id)
3736 +{
3737 + struct gpio_item *gpio = dev_id;
3738 + u32 old_state, new_state;
3739 +
3740 + old_state = gpio->pin_state;
3741 + new_state = at32_gpio_get_value_multiple(gpio->port, gpio->pin_mask);
3742 + gpio->pin_state = new_state;
3743 +
3744 + if (new_state != old_state) {
3745 + gpio->changed = 1;
3746 + wake_up_interruptible(&gpio->change_wq);
3747 +
3748 + if (gpio->async_queue)
3749 + kill_fasync(&gpio->async_queue, SIGIO, POLL_IN);
3750 + }
3751 +
3752 + return IRQ_HANDLED;
3753 +}
3754 +
3755 +static int gpio_dev_open(struct inode *inode, struct file *file)
3756 +{
3757 + struct gpio_item *gpio = container_of(inode->i_cdev,
3758 + struct gpio_item,
3759 + char_dev);
3760 + unsigned int irq;
3761 + unsigned int i;
3762 + int ret;
3763 +
3764 + nonseekable_open(inode, file);
3765 + config_item_get(&gpio->item);
3766 + file->private_data = gpio;
3767 +
3768 + gpio->pin_state = at32_gpio_get_value_multiple(gpio->port,
3769 + gpio->pin_mask);
3770 + gpio->changed = 1;
3771 +
3772 + for (i = 0; i < 32; i++) {
3773 + if (gpio->pin_mask & (1 << i)) {
3774 + irq = gpio_to_irq(32 * gpio->port + i);
3775 + ret = request_irq(irq, gpio_dev_interrupt, 0,
3776 + "gpio-dev", gpio);
3777 + if (ret)
3778 + goto err_irq;
3779 + }
3780 + }
3781 +
3782 + return 0;
3783 +
3784 +err_irq:
3785 + while (i--) {
3786 + if (gpio->pin_mask & (1 << i)) {
3787 + irq = gpio_to_irq(32 * gpio->port + i);
3788 + free_irq(irq, gpio);
3789 + }
3790 + }
3791 +
3792 + config_item_put(&gpio->item);
3793 +
3794 + return ret;
3795 +}
3796 +
3797 +static int gpio_dev_fasync(int fd, struct file *file, int mode)
3798 +{
3799 + struct gpio_item *gpio = file->private_data;
3800 +
3801 + return fasync_helper(fd, file, mode, &gpio->async_queue);
3802 +}
3803 +
3804 +static int gpio_dev_release(struct inode *inode, struct file *file)
3805 +{
3806 + struct gpio_item *gpio = file->private_data;
3807 + unsigned int irq;
3808 + unsigned int i;
3809 +
3810 + gpio_dev_fasync(-1, file, 0);
3811 +
3812 + for (i = 0; i < 32; i++) {
3813 + if (gpio->pin_mask & (1 << i)) {
3814 + irq = gpio_to_irq(32 * gpio->port + i);
3815 + free_irq(irq, gpio);
3816 + }
3817 + }
3818 +
3819 + config_item_put(&gpio->item);
3820 +
3821 + return 0;
3822 +}
3823 +
3824 +static unsigned int gpio_dev_poll(struct file *file, poll_table *wait)
3825 +{
3826 + struct gpio_item *gpio = file->private_data;
3827 + unsigned int mask = 0;
3828 +
3829 + poll_wait(file, &gpio->change_wq, wait);
3830 + if (gpio->changed)
3831 + mask |= POLLIN | POLLRDNORM;
3832 +
3833 + return mask;
3834 +}
3835 +
3836 +static ssize_t gpio_dev_read(struct file *file, char __user *buf,
3837 + size_t count, loff_t *offset)
3838 +{
3839 + struct gpio_item *gpio = file->private_data;
3840 + u32 value;
3841 +
3842 + spin_lock_irq(&gpio->lock);
3843 + while (!gpio->changed) {
3844 + spin_unlock_irq(&gpio->lock);
3845 +
3846 + if (file->f_flags & O_NONBLOCK)
3847 + return -EAGAIN;
3848 +
3849 + if (wait_event_interruptible(gpio->change_wq, gpio->changed))
3850 + return -ERESTARTSYS;
3851 +
3852 + spin_lock_irq(&gpio->lock);
3853 + }
3854 +
3855 + gpio->changed = 0;
3856 + value = at32_gpio_get_value_multiple(gpio->port, gpio->pin_mask);
3857 +
3858 + spin_unlock_irq(&gpio->lock);
3859 +
3860 + count = min(count, (size_t)4);
3861 + if (copy_to_user(buf, &value, count))
3862 + return -EFAULT;
3863 +
3864 + return count;
3865 +}
3866 +
3867 +static ssize_t gpio_dev_write(struct file *file, const char __user *buf,
3868 + size_t count, loff_t *offset)
3869 +{
3870 + struct gpio_item *gpio = file->private_data;
3871 + u32 value = 0;
3872 + u32 mask = ~0UL;
3873 +
3874 + count = min(count, (size_t)4);
3875 + if (copy_from_user(&value, buf, count))
3876 + return -EFAULT;
3877 +
3878 + /* Assuming big endian */
3879 + mask <<= (4 - count) * 8;
3880 + mask &= gpio->pin_mask;
3881 +
3882 + at32_gpio_set_value_multiple(gpio->port, value, mask);
3883 +
3884 + return count;
3885 +}
3886 +
3887 +static struct file_operations gpio_dev_fops = {
3888 + .owner = THIS_MODULE,
3889 + .llseek = no_llseek,
3890 + .open = gpio_dev_open,
3891 + .release = gpio_dev_release,
3892 + .fasync = gpio_dev_fasync,
3893 + .poll = gpio_dev_poll,
3894 + .read = gpio_dev_read,
3895 + .write = gpio_dev_write,
3896 +};
3897 +
3898 +static struct gpio_item *to_gpio_item(struct config_item *item)
3899 +{
3900 + return item ? container_of(item, struct gpio_item, item) : NULL;
3901 +}
3902 +
3903 +static ssize_t gpio_show_gpio_id(struct gpio_item *gpio, char *page)
3904 +{
3905 + return sprintf(page, "%d\n", gpio->port);
3906 +}
3907 +
3908 +static ssize_t gpio_store_gpio_id(struct gpio_item *gpio,
3909 + const char *page, size_t count)
3910 +{
3911 + unsigned long id;
3912 + char *p = (char *)page;
3913 + ssize_t ret = -EINVAL;
3914 +
3915 + id = simple_strtoul(p, &p, 0);
3916 + if (!p || (*p && (*p != '\n')))
3917 + return -EINVAL;
3918 +
3919 + /* Switching PIO is not allowed when live... */
3920 + spin_lock(&gpio->lock);
3921 + if (!gpio->enabled) {
3922 + ret = -ENXIO;
3923 + if (at32_gpio_port_is_valid(id)) {
3924 + gpio->port = id;
3925 + ret = count;
3926 + }
3927 + }
3928 + spin_unlock(&gpio->lock);
3929 +
3930 + return ret;
3931 +}
3932 +
3933 +static ssize_t gpio_show_pin_mask(struct gpio_item *gpio, char *page)
3934 +{
3935 + return sprintf(page, "0x%08x\n", gpio->pin_mask);
3936 +}
3937 +
3938 +static ssize_t gpio_store_pin_mask(struct gpio_item *gpio,
3939 + const char *page, size_t count)
3940 +{
3941 + u32 new_mask;
3942 + char *p = (char *)page;
3943 + ssize_t ret = -EINVAL;
3944 +
3945 + new_mask = simple_strtoul(p, &p, 0);
3946 + if (!p || (*p && (*p != '\n')))
3947 + return -EINVAL;
3948 +
3949 + /* Can't update the pin mask while live. */
3950 + spin_lock(&gpio->lock);
3951 + if (!gpio->enabled) {
3952 + gpio->oe_mask &= new_mask;
3953 + gpio->pin_mask = new_mask;
3954 + ret = count;
3955 + }
3956 + spin_unlock(&gpio->lock);
3957 +
3958 + return ret;
3959 +}
3960 +
3961 +static ssize_t gpio_show_oe_mask(struct gpio_item *gpio, char *page)
3962 +{
3963 + return sprintf(page, "0x%08x\n", gpio->oe_mask);
3964 +}
3965 +
3966 +static ssize_t gpio_store_oe_mask(struct gpio_item *gpio,
3967 + const char *page, size_t count)
3968 +{
3969 + u32 mask;
3970 + char *p = (char *)page;
3971 + ssize_t ret = -EINVAL;
3972 +
3973 + mask = simple_strtoul(p, &p, 0);
3974 + if (!p || (*p && (*p != '\n')))
3975 + return -EINVAL;
3976 +
3977 + spin_lock(&gpio->lock);
3978 + if (!gpio->enabled) {
3979 + gpio->oe_mask = mask & gpio->pin_mask;
3980 + ret = count;
3981 + }
3982 + spin_unlock(&gpio->lock);
3983 +
3984 + return ret;
3985 +}
3986 +
3987 +static ssize_t gpio_show_enabled(struct gpio_item *gpio, char *page)
3988 +{
3989 + return sprintf(page, "%d\n", gpio->enabled);
3990 +}
3991 +
3992 +static ssize_t gpio_store_enabled(struct gpio_item *gpio,
3993 + const char *page, size_t count)
3994 +{
3995 + char *p = (char *)page;
3996 + int enabled;
3997 + int ret;
3998 +
3999 + enabled = simple_strtoul(p, &p, 0);
4000 + if (!p || (*p && (*p != '\n')))
4001 + return -EINVAL;
4002 +
4003 + /* make it a boolean value */
4004 + enabled = !!enabled;
4005 +
4006 + if (gpio->enabled == enabled)
4007 + /* No change; do nothing. */
4008 + return count;
4009 +
4010 + BUG_ON(gpio->id >= GPIO_DEV_MAX);
4011 +
4012 + if (!enabled) {
4013 + class_device_unregister(gpio->gpio_dev);
4014 + cdev_del(&gpio->char_dev);
4015 + at32_deselect_pins(gpio->port, gpio->pin_mask);
4016 + gpio->initialized = 0;
4017 + } else {
4018 + if (gpio->port < 0 || !gpio->pin_mask)
4019 + return -ENODEV;
4020 + }
4021 +
4022 + /* Disallow any updates to gpio_id or pin_mask */
4023 + spin_lock(&gpio->lock);
4024 + gpio->enabled = enabled;
4025 + spin_unlock(&gpio->lock);
4026 +
4027 + if (!enabled)
4028 + return count;
4029 +
4030 + /* Now, try to allocate the pins */
4031 + ret = at32_select_gpio_pins(gpio->port, gpio->pin_mask, gpio->oe_mask);
4032 + if (ret)
4033 + goto err_alloc_pins;
4034 +
4035 + gpio->initialized = 1;
4036 +
4037 + cdev_init(&gpio->char_dev, &gpio_dev_fops);
4038 + gpio->char_dev.owner = THIS_MODULE;
4039 + ret = cdev_add(&gpio->char_dev, MKDEV(MAJOR(gpio_devt), gpio->id), 1);
4040 + if (ret < 0)
4041 + goto err_cdev_add;
4042 + gpio->gpio_dev = class_device_create(gpio_dev_class, NULL,
4043 + MKDEV(MAJOR(gpio_devt), gpio->id),
4044 + NULL,
4045 + "gpio%d", gpio->id);
4046 + if (IS_ERR(gpio->gpio_dev)) {
4047 + printk(KERN_ERR "failed to create gpio%d\n", gpio->id);
4048 + ret = PTR_ERR(gpio->gpio_dev);
4049 + goto err_class_dev;
4050 + }
4051 +
4052 + printk(KERN_INFO "created gpio%d (port%d/0x%08x) as (%d:%d)\n",
4053 + gpio->id, gpio->port, gpio->pin_mask,
4054 + MAJOR(gpio->gpio_dev->devt), MINOR(gpio->gpio_dev->devt));
4055 +
4056 + return 0;
4057 +
4058 +err_class_dev:
4059 + cdev_del(&gpio->char_dev);
4060 +err_cdev_add:
4061 + at32_deselect_pins(gpio->port, gpio->pin_mask);
4062 + gpio->initialized = 0;
4063 +err_alloc_pins:
4064 + spin_lock(&gpio->lock);
4065 + gpio->enabled = 0;
4066 + spin_unlock(&gpio->lock);
4067 +
4068 + return ret;
4069 +}
4070 +
4071 +static struct gpio_attribute gpio_item_attr_gpio_id = {
4072 + .attr = {
4073 + .ca_owner = THIS_MODULE,
4074 + .ca_name = "gpio_id",
4075 + .ca_mode = S_IRUGO | S_IWUSR,
4076 + },
4077 + .show = gpio_show_gpio_id,
4078 + .store = gpio_store_gpio_id,
4079 +};
4080 +static struct gpio_attribute gpio_item_attr_pin_mask = {
4081 + .attr = {
4082 + .ca_owner = THIS_MODULE,
4083 + .ca_name = "pin_mask",
4084 + .ca_mode = S_IRUGO | S_IWUSR,
4085 + },
4086 + .show = gpio_show_pin_mask,
4087 + .store = gpio_store_pin_mask,
4088 +};
4089 +static struct gpio_attribute gpio_item_attr_oe_mask = {
4090 + .attr = {
4091 + .ca_owner = THIS_MODULE,
4092 + .ca_name = "oe_mask",
4093 + .ca_mode = S_IRUGO | S_IWUSR,
4094 + },
4095 + .show = gpio_show_oe_mask,
4096 + .store = gpio_store_oe_mask,
4097 +};
4098 +static struct gpio_attribute gpio_item_attr_enabled = {
4099 + .attr = {
4100 + .ca_owner = THIS_MODULE,
4101 + .ca_name = "enabled",
4102 + .ca_mode = S_IRUGO | S_IWUSR,
4103 + },
4104 + .show = gpio_show_enabled,
4105 + .store = gpio_store_enabled,
4106 +};
4107 +
4108 +static struct configfs_attribute *gpio_item_attrs[] = {
4109 + &gpio_item_attr_gpio_id.attr,
4110 + &gpio_item_attr_pin_mask.attr,
4111 + &gpio_item_attr_oe_mask.attr,
4112 + &gpio_item_attr_enabled.attr,
4113 + NULL,
4114 +};
4115 +
4116 +static ssize_t gpio_show_attr(struct config_item *item,
4117 + struct configfs_attribute *attr,
4118 + char *page)
4119 +{
4120 + struct gpio_item *gpio_item = to_gpio_item(item);
4121 + struct gpio_attribute *gpio_attr
4122 + = container_of(attr, struct gpio_attribute, attr);
4123 + ssize_t ret = 0;
4124 +
4125 + if (gpio_attr->show)
4126 + ret = gpio_attr->show(gpio_item, page);
4127 + return ret;
4128 +}
4129 +
4130 +static ssize_t gpio_store_attr(struct config_item *item,
4131 + struct configfs_attribute *attr,
4132 + const char *page, size_t count)
4133 +{
4134 + struct gpio_item *gpio_item = to_gpio_item(item);
4135 + struct gpio_attribute *gpio_attr
4136 + = container_of(attr, struct gpio_attribute, attr);
4137 + ssize_t ret = -EINVAL;
4138 +
4139 + if (gpio_attr->store)
4140 + ret = gpio_attr->store(gpio_item, page, count);
4141 + return ret;
4142 +}
4143 +
4144 +static void gpio_release(struct config_item *item)
4145 +{
4146 + kfree(to_gpio_item(item));
4147 +}
4148 +
4149 +static struct configfs_item_operations gpio_item_ops = {
4150 + .release = gpio_release,
4151 + .show_attribute = gpio_show_attr,
4152 + .store_attribute = gpio_store_attr,
4153 +};
4154 +
4155 +static struct config_item_type gpio_item_type = {
4156 + .ct_item_ops = &gpio_item_ops,
4157 + .ct_attrs = gpio_item_attrs,
4158 + .ct_owner = THIS_MODULE,
4159 +};
4160 +
4161 +static struct config_item *gpio_make_item(struct config_group *group,
4162 + const char *name)
4163 +{
4164 + static int next_id;
4165 + struct gpio_item *gpio;
4166 +
4167 + if (next_id >= GPIO_DEV_MAX)
4168 + return NULL;
4169 +
4170 + gpio = kzalloc(sizeof(struct gpio_item), GFP_KERNEL);
4171 + if (!gpio)
4172 + return NULL;
4173 +
4174 + gpio->id = next_id++;
4175 + config_item_init_type_name(&gpio->item, name, &gpio_item_type);
4176 + spin_lock_init(&gpio->lock);
4177 + init_waitqueue_head(&gpio->change_wq);
4178 +
4179 + return &gpio->item;
4180 +}
4181 +
4182 +static void gpio_drop_item(struct config_group *group,
4183 + struct config_item *item)
4184 +{
4185 + struct gpio_item *gpio = to_gpio_item(item);
4186 +
4187 + spin_lock(&gpio->lock);
4188 + if (gpio->enabled) {
4189 + class_device_unregister(gpio->gpio_dev);
4190 + cdev_del(&gpio->char_dev);
4191 + }
4192 +
4193 + if (gpio->initialized) {
4194 + at32_deselect_pins(gpio->port, gpio->pin_mask);
4195 + gpio->initialized = 0;
4196 + gpio->enabled = 0;
4197 + }
4198 + spin_unlock(&gpio->lock);
4199 +}
4200 +
4201 +static struct configfs_group_operations gpio_group_ops = {
4202 + .make_item = gpio_make_item,
4203 + .drop_item = gpio_drop_item,
4204 +};
4205 +
4206 +static struct config_item_type gpio_group_type = {
4207 + .ct_group_ops = &gpio_group_ops,
4208 + .ct_owner = THIS_MODULE,
4209 +};
4210 +
4211 +static struct configfs_subsystem gpio_subsys = {
4212 + .su_group = {
4213 + .cg_item = {
4214 + .ci_namebuf = "gpio",
4215 + .ci_type = &gpio_group_type,
4216 + },
4217 + },
4218 +};
4219 +
4220 +static int __init gpio_dev_init(void)
4221 +{
4222 + int err;
4223 +
4224 + gpio_dev_class = class_create(THIS_MODULE, "gpio-dev");
4225 + if (IS_ERR(gpio_dev_class)) {
4226 + err = PTR_ERR(gpio_dev_class);
4227 + goto err_class_create;
4228 + }
4229 +
4230 + err = alloc_chrdev_region(&gpio_devt, 0, GPIO_DEV_MAX, "gpio");
4231 + if (err < 0)
4232 + goto err_alloc_chrdev;
4233 +
4234 + /* Configfs initialization */
4235 + config_group_init(&gpio_subsys.su_group);
4236 + init_MUTEX(&gpio_subsys.su_sem);
4237 + err = configfs_register_subsystem(&gpio_subsys);
4238 + if (err)
4239 + goto err_register_subsys;
4240 +
4241 + return 0;
4242 +
4243 +err_register_subsys:
4244 + unregister_chrdev_region(gpio_devt, GPIO_DEV_MAX);
4245 +err_alloc_chrdev:
4246 + class_destroy(gpio_dev_class);
4247 +err_class_create:
4248 + printk(KERN_WARNING "Failed to initialize gpio /dev interface\n");
4249 + return err;
4250 +}
4251 +late_initcall(gpio_dev_init);
4252 diff --git a/arch/avr32/mach-at32ap/pio.c b/arch/avr32/mach-at32ap/pio.c
4253 index 1eb99b8..153bb9a 100644
4254 --- a/arch/avr32/mach-at32ap/pio.c
4255 +++ b/arch/avr32/mach-at32ap/pio.c
4256 @@ -158,6 +158,82 @@ fail:
4257 dump_stack();
4258 }
4259
4260 +#ifdef CONFIG_GPIO_DEV
4261 +
4262 +/* Gang allocators and accessors; used by the GPIO /dev driver */
4263 +int at32_gpio_port_is_valid(unsigned int port)
4264 +{
4265 + return port < MAX_NR_PIO_DEVICES && pio_dev[port].regs != NULL;
4266 +}
4267 +
4268 +int at32_select_gpio_pins(unsigned int port, u32 pins, u32 oe_mask)
4269 +{
4270 + struct pio_device *pio;
4271 + u32 old, new;
4272 +
4273 + pio = &pio_dev[port];
4274 + BUG_ON(port > ARRAY_SIZE(pio_dev) || !pio->regs || (oe_mask & ~pins));
4275 +
4276 + /* Try to allocate the pins */
4277 + do {
4278 + old = pio->pinmux_mask;
4279 + if (old & pins)
4280 + return -EBUSY;
4281 +
4282 + new = old | pins;
4283 + } while (cmpxchg(&pio->pinmux_mask, old, new) != old);
4284 +
4285 + /* That went well, now configure the port */
4286 + pio_writel(pio, OER, oe_mask);
4287 + pio_writel(pio, PER, pins);
4288 +
4289 + return 0;
4290 +}
4291 +
4292 +void at32_deselect_pins(unsigned int port, u32 pins)
4293 +{
4294 + struct pio_device *pio;
4295 + u32 old, new;
4296 +
4297 + pio = &pio_dev[port];
4298 + BUG_ON(port > ARRAY_SIZE(pio_dev) || !pio->regs);
4299 +
4300 + /* Return to a "safe" mux configuration */
4301 + pio_writel(pio, PUER, pins);
4302 + pio_writel(pio, ODR, pins);
4303 +
4304 + /* Deallocate the pins */
4305 + do {
4306 + old = pio->pinmux_mask;
4307 + new = old & ~pins;
4308 + } while (cmpxchg(&pio->pinmux_mask, old, new) != old);
4309 +}
4310 +
4311 +u32 at32_gpio_get_value_multiple(unsigned int port, u32 pins)
4312 +{
4313 + struct pio_device *pio;
4314 +
4315 + pio = &pio_dev[port];
4316 + BUG_ON(port > ARRAY_SIZE(pio_dev) || !pio->regs);
4317 +
4318 + return pio_readl(pio, PDSR) & pins;
4319 +}
4320 +
4321 +void at32_gpio_set_value_multiple(unsigned int port, u32 value, u32 mask)
4322 +{
4323 + struct pio_device *pio;
4324 +
4325 + pio = &pio_dev[port];
4326 + BUG_ON(port > ARRAY_SIZE(pio_dev) || !pio->regs);
4327 +
4328 + /* No atomic updates for now... */
4329 + pio_writel(pio, CODR, ~value & mask);
4330 + pio_writel(pio, SODR, value & mask);
4331 +}
4332 +
4333 +#endif /* CONFIG_GPIO_DEV */
4334 +
4335 +
4336 /*--------------------------------------------------------------------------*/
4337
4338 /* GPIO API */
4339 diff --git a/arch/avr32/mach-at32ap/pm.h b/arch/avr32/mach-at32ap/pm.h
4340 new file mode 100644
4341 index 0000000..a1f8ace
4342 --- /dev/null
4343 +++ b/arch/avr32/mach-at32ap/pm.h
4344 @@ -0,0 +1,112 @@
4345 +/*
4346 + * Register definitions for the Power Manager (PM)
4347 + */
4348 +#ifndef __ARCH_AVR32_MACH_AT32AP_PM_H__
4349 +#define __ARCH_AVR32_MACH_AT32AP_PM_H__
4350 +
4351 +/* PM register offsets */
4352 +#define PM_MCCTRL 0x0000
4353 +#define PM_CKSEL 0x0004
4354 +#define PM_CPU_MASK 0x0008
4355 +#define PM_HSB_MASK 0x000c
4356 +#define PM_PBA_MASK 0x0010
4357 +#define PM_PBB_MASK 0x0014
4358 +#define PM_PLL0 0x0020
4359 +#define PM_PLL1 0x0024
4360 +#define PM_IER 0x0040
4361 +#define PM_IDR 0x0044
4362 +#define PM_IMR 0x0048
4363 +#define PM_ISR 0x004c
4364 +#define PM_ICR 0x0050
4365 +#define PM_GCCTRL(x) (0x0060 + 4 * (x))
4366 +#define PM_RCAUSE 0x00c0
4367 +
4368 +/* Bitfields in CKSEL */
4369 +#define PM_CPUSEL_OFFSET 0
4370 +#define PM_CPUSEL_SIZE 3
4371 +#define PM_CPUDIV_OFFSET 7
4372 +#define PM_CPUDIV_SIZE 1
4373 +#define PM_HSBSEL_OFFSET 8
4374 +#define PM_HSBSEL_SIZE 3
4375 +#define PM_HSBDIV_OFFSET 15
4376 +#define PM_HSBDIV_SIZE 1
4377 +#define PM_PBASEL_OFFSET 16
4378 +#define PM_PBASEL_SIZE 3
4379 +#define PM_PBADIV_OFFSET 23
4380 +#define PM_PBADIV_SIZE 1
4381 +#define PM_PBBSEL_OFFSET 24
4382 +#define PM_PBBSEL_SIZE 3
4383 +#define PM_PBBDIV_OFFSET 31
4384 +#define PM_PBBDIV_SIZE 1
4385 +
4386 +/* Bitfields in PLL0 */
4387 +#define PM_PLLEN_OFFSET 0
4388 +#define PM_PLLEN_SIZE 1
4389 +#define PM_PLLOSC_OFFSET 1
4390 +#define PM_PLLOSC_SIZE 1
4391 +#define PM_PLLOPT_OFFSET 2
4392 +#define PM_PLLOPT_SIZE 3
4393 +#define PM_PLLDIV_OFFSET 8
4394 +#define PM_PLLDIV_SIZE 8
4395 +#define PM_PLLMUL_OFFSET 16
4396 +#define PM_PLLMUL_SIZE 8
4397 +#define PM_PLLCOUNT_OFFSET 24
4398 +#define PM_PLLCOUNT_SIZE 6
4399 +#define PM_PLLTEST_OFFSET 31
4400 +#define PM_PLLTEST_SIZE 1
4401 +
4402 +/* Bitfields in ICR */
4403 +#define PM_LOCK0_OFFSET 0
4404 +#define PM_LOCK0_SIZE 1
4405 +#define PM_LOCK1_OFFSET 1
4406 +#define PM_LOCK1_SIZE 1
4407 +#define PM_WAKE_OFFSET 2
4408 +#define PM_WAKE_SIZE 1
4409 +#define PM_CKRDY_OFFSET 5
4410 +#define PM_CKRDY_SIZE 1
4411 +#define PM_MSKRDY_OFFSET 6
4412 +#define PM_MSKRDY_SIZE 1
4413 +
4414 +/* Bitfields in GCCTRL0 */
4415 +#define PM_OSCSEL_OFFSET 0
4416 +#define PM_OSCSEL_SIZE 1
4417 +#define PM_PLLSEL_OFFSET 1
4418 +#define PM_PLLSEL_SIZE 1
4419 +#define PM_CEN_OFFSET 2
4420 +#define PM_CEN_SIZE 1
4421 +#define PM_DIVEN_OFFSET 4
4422 +#define PM_DIVEN_SIZE 1
4423 +#define PM_DIV_OFFSET 8
4424 +#define PM_DIV_SIZE 8
4425 +
4426 +/* Bitfields in RCAUSE */
4427 +#define PM_POR_OFFSET 0
4428 +#define PM_POR_SIZE 1
4429 +#define PM_EXT_OFFSET 2
4430 +#define PM_EXT_SIZE 1
4431 +#define PM_WDT_OFFSET 3
4432 +#define PM_WDT_SIZE 1
4433 +#define PM_NTAE_OFFSET 4
4434 +#define PM_NTAE_SIZE 1
4435 +
4436 +/* Bit manipulation macros */
4437 +#define PM_BIT(name) \
4438 + (1 << PM_##name##_OFFSET)
4439 +#define PM_BF(name,value) \
4440 + (((value) & ((1 << PM_##name##_SIZE) - 1)) \
4441 + << PM_##name##_OFFSET)
4442 +#define PM_BFEXT(name,value) \
4443 + (((value) >> PM_##name##_OFFSET) \
4444 + & ((1 << PM_##name##_SIZE) - 1))
4445 +#define PM_BFINS(name,value,old)\
4446 + (((old) & ~(((1 << PM_##name##_SIZE) - 1) \
4447 + << PM_##name##_OFFSET)) \
4448 + | PM_BF(name,value))
4449 +
4450 +/* Register access macros */
4451 +#define pm_readl(reg) \
4452 + __raw_readl((void __iomem *)AT32_PM_BASE + PM_##reg)
4453 +#define pm_writel(reg,value) \
4454 + __raw_writel((value), (void __iomem *)AT32_PM_BASE + PM_##reg)
4455 +
4456 +#endif /* __ARCH_AVR32_MACH_AT32AP_PM_H__ */
4457 diff --git a/arch/avr32/mach-at32ap/sm.h b/arch/avr32/mach-at32ap/sm.h
4458 deleted file mode 100644
4459 index cad02b5..0000000
4460 --- a/arch/avr32/mach-at32ap/sm.h
4461 +++ /dev/null
4462 @@ -1,242 +0,0 @@
4463 -/*
4464 - * Register definitions for SM
4465 - *
4466 - * System Manager
4467 - */
4468 -#ifndef __ASM_AVR32_SM_H__
4469 -#define __ASM_AVR32_SM_H__
4470 -
4471 -/* SM register offsets */
4472 -#define SM_PM_MCCTRL 0x0000
4473 -#define SM_PM_CKSEL 0x0004
4474 -#define SM_PM_CPU_MASK 0x0008
4475 -#define SM_PM_HSB_MASK 0x000c
4476 -#define SM_PM_PBA_MASK 0x0010
4477 -#define SM_PM_PBB_MASK 0x0014
4478 -#define SM_PM_PLL0 0x0020
4479 -#define SM_PM_PLL1 0x0024
4480 -#define SM_PM_VCTRL 0x0030
4481 -#define SM_PM_VMREF 0x0034
4482 -#define SM_PM_VMV 0x0038
4483 -#define SM_PM_IER 0x0040
4484 -#define SM_PM_IDR 0x0044
4485 -#define SM_PM_IMR 0x0048
4486 -#define SM_PM_ISR 0x004c
4487 -#define SM_PM_ICR 0x0050
4488 -#define SM_PM_GCCTRL 0x0060
4489 -#define SM_RTC_CTRL 0x0080
4490 -#define SM_RTC_VAL 0x0084
4491 -#define SM_RTC_TOP 0x0088
4492 -#define SM_RTC_IER 0x0090
4493 -#define SM_RTC_IDR 0x0094
4494 -#define SM_RTC_IMR 0x0098
4495 -#define SM_RTC_ISR 0x009c
4496 -#define SM_RTC_ICR 0x00a0
4497 -#define SM_WDT_CTRL 0x00b0
4498 -#define SM_WDT_CLR 0x00b4
4499 -#define SM_WDT_EXT 0x00b8
4500 -#define SM_RC_RCAUSE 0x00c0
4501 -#define SM_EIM_IER 0x0100
4502 -#define SM_EIM_IDR 0x0104
4503 -#define SM_EIM_IMR 0x0108
4504 -#define SM_EIM_ISR 0x010c
4505 -#define SM_EIM_ICR 0x0110
4506 -#define SM_EIM_MODE 0x0114
4507 -#define SM_EIM_EDGE 0x0118
4508 -#define SM_EIM_LEVEL 0x011c
4509 -#define SM_EIM_TEST 0x0120
4510 -#define SM_EIM_NMIC 0x0124
4511 -
4512 -/* Bitfields in PM_MCCTRL */
4513 -
4514 -/* Bitfields in PM_CKSEL */
4515 -#define SM_CPUSEL_OFFSET 0
4516 -#define SM_CPUSEL_SIZE 3
4517 -#define SM_CPUDIV_OFFSET 7
4518 -#define SM_CPUDIV_SIZE 1
4519 -#define SM_HSBSEL_OFFSET 8
4520 -#define SM_HSBSEL_SIZE 3
4521 -#define SM_HSBDIV_OFFSET 15
4522 -#define SM_HSBDIV_SIZE 1
4523 -#define SM_PBASEL_OFFSET 16
4524 -#define SM_PBASEL_SIZE 3
4525 -#define SM_PBADIV_OFFSET 23
4526 -#define SM_PBADIV_SIZE 1
4527 -#define SM_PBBSEL_OFFSET 24
4528 -#define SM_PBBSEL_SIZE 3
4529 -#define SM_PBBDIV_OFFSET 31
4530 -#define SM_PBBDIV_SIZE 1
4531 -
4532 -/* Bitfields in PM_CPU_MASK */
4533 -
4534 -/* Bitfields in PM_HSB_MASK */
4535 -
4536 -/* Bitfields in PM_PBA_MASK */
4537 -
4538 -/* Bitfields in PM_PBB_MASK */
4539 -
4540 -/* Bitfields in PM_PLL0 */
4541 -#define SM_PLLEN_OFFSET 0
4542 -#define SM_PLLEN_SIZE 1
4543 -#define SM_PLLOSC_OFFSET 1
4544 -#define SM_PLLOSC_SIZE 1
4545 -#define SM_PLLOPT_OFFSET 2
4546 -#define SM_PLLOPT_SIZE 3
4547 -#define SM_PLLDIV_OFFSET 8
4548 -#define SM_PLLDIV_SIZE 8
4549 -#define SM_PLLMUL_OFFSET 16
4550 -#define SM_PLLMUL_SIZE 8
4551 -#define SM_PLLCOUNT_OFFSET 24
4552 -#define SM_PLLCOUNT_SIZE 6
4553 -#define SM_PLLTEST_OFFSET 31
4554 -#define SM_PLLTEST_SIZE 1
4555 -
4556 -/* Bitfields in PM_PLL1 */
4557 -
4558 -/* Bitfields in PM_VCTRL */
4559 -#define SM_VAUTO_OFFSET 0
4560 -#define SM_VAUTO_SIZE 1
4561 -#define SM_PM_VCTRL_VAL_OFFSET 8
4562 -#define SM_PM_VCTRL_VAL_SIZE 7
4563 -
4564 -/* Bitfields in PM_VMREF */
4565 -#define SM_REFSEL_OFFSET 0
4566 -#define SM_REFSEL_SIZE 4
4567 -
4568 -/* Bitfields in PM_VMV */
4569 -#define SM_PM_VMV_VAL_OFFSET 0
4570 -#define SM_PM_VMV_VAL_SIZE 8
4571 -
4572 -/* Bitfields in PM_IER */
4573 -
4574 -/* Bitfields in PM_IDR */
4575 -
4576 -/* Bitfields in PM_IMR */
4577 -
4578 -/* Bitfields in PM_ISR */
4579 -
4580 -/* Bitfields in PM_ICR */
4581 -#define SM_LOCK0_OFFSET 0
4582 -#define SM_LOCK0_SIZE 1
4583 -#define SM_LOCK1_OFFSET 1
4584 -#define SM_LOCK1_SIZE 1
4585 -#define SM_WAKE_OFFSET 2
4586 -#define SM_WAKE_SIZE 1
4587 -#define SM_VOK_OFFSET 3
4588 -#define SM_VOK_SIZE 1
4589 -#define SM_VMRDY_OFFSET 4
4590 -#define SM_VMRDY_SIZE 1
4591 -#define SM_CKRDY_OFFSET 5
4592 -#define SM_CKRDY_SIZE 1
4593 -
4594 -/* Bitfields in PM_GCCTRL */
4595 -#define SM_OSCSEL_OFFSET 0
4596 -#define SM_OSCSEL_SIZE 1
4597 -#define SM_PLLSEL_OFFSET 1
4598 -#define SM_PLLSEL_SIZE 1
4599 -#define SM_CEN_OFFSET 2
4600 -#define SM_CEN_SIZE 1
4601 -#define SM_CPC_OFFSET 3
4602 -#define SM_CPC_SIZE 1
4603 -#define SM_DIVEN_OFFSET 4
4604 -#define SM_DIVEN_SIZE 1
4605 -#define SM_DIV_OFFSET 8
4606 -#define SM_DIV_SIZE 8
4607 -
4608 -/* Bitfields in RTC_CTRL */
4609 -#define SM_PCLR_OFFSET 1
4610 -#define SM_PCLR_SIZE 1
4611 -#define SM_TOPEN_OFFSET 2
4612 -#define SM_TOPEN_SIZE 1
4613 -#define SM_CLKEN_OFFSET 3
4614 -#define SM_CLKEN_SIZE 1
4615 -#define SM_PSEL_OFFSET 8
4616 -#define SM_PSEL_SIZE 16
4617 -
4618 -/* Bitfields in RTC_VAL */
4619 -#define SM_RTC_VAL_VAL_OFFSET 0
4620 -#define SM_RTC_VAL_VAL_SIZE 31
4621 -
4622 -/* Bitfields in RTC_TOP */
4623 -#define SM_RTC_TOP_VAL_OFFSET 0
4624 -#define SM_RTC_TOP_VAL_SIZE 32
4625 -
4626 -/* Bitfields in RTC_IER */
4627 -
4628 -/* Bitfields in RTC_IDR */
4629 -
4630 -/* Bitfields in RTC_IMR */
4631 -
4632 -/* Bitfields in RTC_ISR */
4633 -
4634 -/* Bitfields in RTC_ICR */
4635 -#define SM_TOPI_OFFSET 0
4636 -#define SM_TOPI_SIZE 1
4637 -
4638 -/* Bitfields in WDT_CTRL */
4639 -#define SM_KEY_OFFSET 24
4640 -#define SM_KEY_SIZE 8
4641 -
4642 -/* Bitfields in WDT_CLR */
4643 -
4644 -/* Bitfields in WDT_EXT */
4645 -
4646 -/* Bitfields in RC_RCAUSE */
4647 -#define SM_POR_OFFSET 0
4648 -#define SM_POR_SIZE 1
4649 -#define SM_BOD_OFFSET 1
4650 -#define SM_BOD_SIZE 1
4651 -#define SM_EXT_OFFSET 2
4652 -#define SM_EXT_SIZE 1
4653 -#define SM_WDT_OFFSET 3
4654 -#define SM_WDT_SIZE 1
4655 -#define SM_NTAE_OFFSET 4
4656 -#define SM_NTAE_SIZE 1
4657 -#define SM_SERP_OFFSET 5
4658 -#define SM_SERP_SIZE 1
4659 -
4660 -/* Bitfields in EIM_IER */
4661 -
4662 -/* Bitfields in EIM_IDR */
4663 -
4664 -/* Bitfields in EIM_IMR */
4665 -
4666 -/* Bitfields in EIM_ISR */
4667 -
4668 -/* Bitfields in EIM_ICR */
4669 -
4670 -/* Bitfields in EIM_MODE */
4671 -
4672 -/* Bitfields in EIM_EDGE */
4673 -#define SM_INT0_OFFSET 0
4674 -#define SM_INT0_SIZE 1
4675 -#define SM_INT1_OFFSET 1
4676 -#define SM_INT1_SIZE 1
4677 -#define SM_INT2_OFFSET 2
4678 -#define SM_INT2_SIZE 1
4679 -#define SM_INT3_OFFSET 3
4680 -#define SM_INT3_SIZE 1
4681 -
4682 -/* Bitfields in EIM_LEVEL */
4683 -
4684 -/* Bitfields in EIM_TEST */
4685 -#define SM_TESTEN_OFFSET 31
4686 -#define SM_TESTEN_SIZE 1
4687 -
4688 -/* Bitfields in EIM_NMIC */
4689 -#define SM_EN_OFFSET 0
4690 -#define SM_EN_SIZE 1
4691 -
4692 -/* Bit manipulation macros */
4693 -#define SM_BIT(name) (1 << SM_##name##_OFFSET)
4694 -#define SM_BF(name,value) (((value) & ((1 << SM_##name##_SIZE) - 1)) << SM_##name##_OFFSET)
4695 -#define SM_BFEXT(name,value) (((value) >> SM_##name##_OFFSET) & ((1 << SM_##name##_SIZE) - 1))
4696 -#define SM_BFINS(name,value,old) (((old) & ~(((1 << SM_##name##_SIZE) - 1) << SM_##name##_OFFSET)) | SM_BF(name,value))
4697 -
4698 -/* Register access macros */
4699 -#define sm_readl(port,reg) \
4700 - __raw_readl((port)->regs + SM_##reg)
4701 -#define sm_writel(port,reg,value) \
4702 - __raw_writel((value), (port)->regs + SM_##reg)
4703 -
4704 -#endif /* __ASM_AVR32_SM_H__ */
4705 diff --git a/arch/avr32/mm/dma-coherent.c b/arch/avr32/mm/dma-coherent.c
4706 index 099212d..26f29c6 100644
4707 --- a/arch/avr32/mm/dma-coherent.c
4708 +++ b/arch/avr32/mm/dma-coherent.c
4709 @@ -41,6 +41,13 @@ static struct page *__dma_alloc(struct device *dev, size_t size,
4710 struct page *page, *free, *end;
4711 int order;
4712
4713 + /* Following is a work-around (a.k.a. hack) to prevent pages
4714 + * with __GFP_COMP being passed to split_page() which cannot
4715 + * handle them. The real problem is that this flag probably
4716 + * should be 0 on AVR32 as it is not supported on this
4717 + * platform--see CONFIG_HUGETLB_PAGE. */
4718 + gfp &= ~(__GFP_COMP);
4719 +
4720 size = PAGE_ALIGN(size);
4721 order = get_order(size);
4722
4723 diff --git a/drivers/char/watchdog/Kconfig b/drivers/char/watchdog/Kconfig
4724 index 53f5538..520afb8 100644
4725 --- a/drivers/char/watchdog/Kconfig
4726 +++ b/drivers/char/watchdog/Kconfig
4727 @@ -187,6 +187,26 @@ config PNX4008_WATCHDOG
4728
4729 Say N if you are unsure.
4730
4731 +# AVR32 Architecture
4732 +
4733 +config AT32AP700X_WDT
4734 + tristate "AT32AP700x watchdog"
4735 + depends on WATCHDOG && CPU_AT32AP7000
4736 + help
4737 + Watchdog timer embedded into AT32AP700x devices. This will reboot
4738 + your system when the timeout is reached.
4739 +
4740 +config AT32AP700X_WDT_TIMEOUT
4741 + int "Timeout value for AT32AP700x watchdog"
4742 + depends on AT32AP700X_WDT
4743 + default "2"
4744 + range 1 2
4745 + help
4746 + Sets the timeout value for the watchdog in AT32AP700x devices.
4747 + Limited by hardware to be 1 or 2 seconds.
4748 +
4749 + Set to 2 seconds by default.
4750 +
4751 # X86 (i386 + ia64 + x86_64) Architecture
4752
4753 config ACQUIRE_WDT
4754 diff --git a/drivers/char/watchdog/Makefile b/drivers/char/watchdog/Makefile
4755 index d90f649..3907ec0 100644
4756 --- a/drivers/char/watchdog/Makefile
4757 +++ b/drivers/char/watchdog/Makefile
4758 @@ -36,6 +36,9 @@ obj-$(CONFIG_MPCORE_WATCHDOG) += mpcore_wdt.o
4759 obj-$(CONFIG_EP93XX_WATCHDOG) += ep93xx_wdt.o
4760 obj-$(CONFIG_PNX4008_WATCHDOG) += pnx4008_wdt.o
4761
4762 +# AVR32 Architecture
4763 +obj-$(CONFIG_AT32AP700X_WDT) += at32ap700x_wdt.o
4764 +
4765 # X86 (i386 + ia64 + x86_64) Architecture
4766 obj-$(CONFIG_ACQUIRE_WDT) += acquirewdt.o
4767 obj-$(CONFIG_ADVANTECH_WDT) += advantechwdt.o
4768 diff --git a/drivers/char/watchdog/at32ap700x_wdt.c b/drivers/char/watchdog/at32ap700x_wdt.c
4769 new file mode 100644
4770 index 0000000..9b598d9
4771 --- /dev/null
4772 +++ b/drivers/char/watchdog/at32ap700x_wdt.c
4773 @@ -0,0 +1,325 @@
4774 +/*
4775 + * Watchdog driver for Atmel AT32AP700X devices
4776 + *
4777 + * Copyright (C) 2005-2006 Atmel Corporation
4778 + *
4779 + * This program is free software; you can redistribute it and/or modify
4780 + * it under the terms of the GNU General Public License version 2 as
4781 + * published by the Free Software Foundation.
4782 + */
4783 +
4784 +#include <linux/init.h>
4785 +#include <linux/kernel.h>
4786 +#include <linux/module.h>
4787 +#include <linux/moduleparam.h>
4788 +#include <linux/miscdevice.h>
4789 +#include <linux/fs.h>
4790 +#include <linux/platform_device.h>
4791 +#include <linux/watchdog.h>
4792 +#include <linux/uaccess.h>
4793 +#include <linux/io.h>
4794 +
4795 +#define TIMEOUT_MIN 1
4796 +#define TIMEOUT_DEFAULT CONFIG_AT32AP700X_WDT_TIMEOUT
4797 +#define TIMEOUT_MAX 2
4798 +
4799 +/* Watchdog registers and write/read macro */
4800 +#define WDT_CTRL 0x00
4801 +#define WDT_CTRL_EN 0
4802 +#define WDT_CTRL_PSEL 8
4803 +#define WDT_CTRL_KEY 24
4804 +
4805 +#define WDT_CLR 0x04
4806 +
4807 +#define WDT_BIT(name) (1 << WDT_##name)
4808 +#define WDT_BF(name,value) ((value) << WDT_##name)
4809 +
4810 +#define wdt_readl(dev,reg) \
4811 + __raw_readl((dev)->regs + WDT_##reg)
4812 +#define wdt_writel(dev,reg,value) \
4813 + __raw_writel((value), (dev)->regs + WDT_##reg)
4814 +
4815 +struct wdt_at32ap700x {
4816 + void __iomem *regs;
4817 + int timeout;
4818 + int users;
4819 + struct miscdevice miscdev;
4820 +};
4821 +
4822 +static struct wdt_at32ap700x *wdt;
4823 +
4824 +/*
4825 + * Disable the watchdog.
4826 + */
4827 +static void inline at32_wdt_stop(void)
4828 +{
4829 + unsigned long psel = wdt_readl(wdt, CTRL) & WDT_BF(CTRL_PSEL, 0x0f);
4830 + wdt_writel(wdt, CTRL, psel | WDT_BF(CTRL_KEY, 0x55));
4831 + wdt_writel(wdt, CTRL, psel | WDT_BF(CTRL_KEY, 0xaa));
4832 +}
4833 +
4834 +/*
4835 + * Enable and reset the watchdog.
4836 + */
4837 +static void inline at32_wdt_start(void)
4838 +{
4839 + /* 0xf is 2^16 divider = 2 sec, 0xe is 2^15 divider = 1 sec */
4840 + unsigned long psel = (wdt->timeout > 1) ? 0xf : 0xe;
4841 +
4842 + wdt_writel(wdt, CTRL, WDT_BIT(CTRL_EN)
4843 + | WDT_BF(CTRL_PSEL, psel)
4844 + | WDT_BF(CTRL_KEY, 0x55));
4845 + wdt_writel(wdt, CTRL, WDT_BIT(CTRL_EN)
4846 + | WDT_BF(CTRL_PSEL, psel)
4847 + | WDT_BF(CTRL_KEY, 0xaa));
4848 +}
4849 +
4850 +/*
4851 + * Pat the watchdog timer.
4852 + */
4853 +static void inline at32_wdt_pat(void)
4854 +{
4855 + wdt_writel(wdt, CLR, 0x42);
4856 +}
4857 +
4858 +/*
4859 + * Watchdog device is opened, and watchdog starts running.
4860 + */
4861 +static int at32_wdt_open(struct inode *inode, struct file *file)
4862 +{
4863 + if (test_and_set_bit(1, &wdt->users))
4864 + return -EBUSY;
4865 +
4866 + at32_wdt_start();
4867 + return nonseekable_open(inode, file);
4868 +}
4869 +
4870 +/*
4871 + * Close the watchdog device. If CONFIG_WATCHDOG_NOWAYOUT is _not_ defined then
4872 + * the watchdog is also disabled.
4873 + */
4874 +static int at32_wdt_close(struct inode *inode, struct file *file)
4875 +{
4876 +#ifndef CONFIG_WATCHDOG_NOWAYOUT
4877 + at32_wdt_stop();
4878 +#endif
4879 + clear_bit(1, &wdt->users);
4880 + return 0;
4881 +}
4882 +
4883 +/*
4884 + * Change the watchdog time interval.
4885 + */
4886 +static int at32_wdt_settimeout(int time)
4887 +{
4888 + /*
4889 + * All counting occurs at 1 / SLOW_CLOCK (32 kHz) and max prescaler is
4890 + * 2 ^ 16 allowing up to 2 seconds timeout.
4891 + */
4892 + if ((time < TIMEOUT_MIN) || (time > TIMEOUT_MAX))
4893 + return -EINVAL;
4894 +
4895 + /*
4896 + * Set new watchdog time. It will be used when at32_wdt_start() is
4897 + * called.
4898 + */
4899 + wdt->timeout = time;
4900 + return 0;
4901 +}
4902 +
4903 +static struct watchdog_info at32_wdt_info = {
4904 + .identity = "at32ap700x watchdog",
4905 + .options = WDIOF_SETTIMEOUT | WDIOF_KEEPALIVEPING,
4906 +};
4907 +
4908 +/*
4909 + * Handle commands from user-space.
4910 + */
4911 +static int at32_wdt_ioctl(struct inode *inode, struct file *file,
4912 + unsigned int cmd, unsigned long arg)
4913 +{
4914 + int ret = -ENOTTY;
4915 + int time;
4916 + void __user *argp = (void __user *)arg;
4917 + int __user *p = argp;
4918 +
4919 + switch (cmd) {
4920 + case WDIOC_KEEPALIVE:
4921 + at32_wdt_pat();
4922 + ret = 0;
4923 + break;
4924 + case WDIOC_GETSUPPORT:
4925 + ret = copy_to_user(argp, &at32_wdt_info,
4926 + sizeof(at32_wdt_info)) ? -EFAULT : 0;
4927 + break;
4928 + case WDIOC_SETTIMEOUT:
4929 + ret = get_user(time, p);
4930 + if (ret)
4931 + break;
4932 + ret = at32_wdt_settimeout(time);
4933 + if (ret)
4934 + break;
4935 + /* Enable new time value */
4936 + at32_wdt_start();
4937 + /* fall through */
4938 + case WDIOC_GETTIMEOUT:
4939 + ret = put_user(wdt->timeout, p);
4940 + break;
4941 + case WDIOC_GETSTATUS: /* fall through */
4942 + case WDIOC_GETBOOTSTATUS:
4943 + ret = put_user(0, p);
4944 + break;
4945 + case WDIOC_SETOPTIONS:
4946 + ret = get_user(time, p);
4947 + if (ret)
4948 + break;
4949 + if (time & WDIOS_DISABLECARD)
4950 + at32_wdt_stop();
4951 + if (time & WDIOS_ENABLECARD)
4952 + at32_wdt_start();
4953 + ret = 0;
4954 + break;
4955 + }
4956 +
4957 + return ret;
4958 +}
4959 +
4960 +static ssize_t at32_wdt_write(struct file *file, const char *data, size_t len,
4961 + loff_t *ppos)
4962 +{
4963 + at32_wdt_pat();
4964 + return len;
4965 +}
4966 +
4967 +static const struct file_operations at32_wdt_fops = {
4968 + .owner = THIS_MODULE,
4969 + .llseek = no_llseek,
4970 + .ioctl = at32_wdt_ioctl,
4971 + .open = at32_wdt_open,
4972 + .release = at32_wdt_close,
4973 + .write = at32_wdt_write,
4974 +};
4975 +
4976 +static int __init at32_wdt_probe(struct platform_device *pdev)
4977 +{
4978 + struct resource *regs;
4979 + int ret;
4980 +
4981 + if (wdt) {
4982 + dev_dbg(&pdev->dev, "only 1 wdt instance supported.\n");
4983 + return -EBUSY;
4984 + }
4985 +
4986 + regs = platform_get_resource(pdev, IORESOURCE_MEM, 0);
4987 + if (!regs) {
4988 + dev_dbg(&pdev->dev, "missing mmio resource\n");
4989 + return -ENXIO;
4990 + }
4991 +
4992 + wdt = kzalloc(sizeof(struct wdt_at32ap700x), GFP_KERNEL);
4993 + if (!wdt) {
4994 + dev_dbg(&pdev->dev, "no memory for wdt structure\n");
4995 + return -ENOMEM;
4996 + }
4997 +
4998 + wdt->regs = ioremap(regs->start, regs->end - regs->start + 1);
4999 + if (!wdt->regs) {
5000 + ret = -ENOMEM;
5001 + dev_dbg(&pdev->dev, "could not map I/O memory\n");
5002 + goto err_free;
5003 + }
5004 + wdt->users = 0;
5005 + wdt->miscdev.minor = WATCHDOG_MINOR;
5006 + wdt->miscdev.name = "watchdog";
5007 + wdt->miscdev.fops = &at32_wdt_fops;
5008 +
5009 + if (at32_wdt_settimeout(TIMEOUT_DEFAULT)) {
5010 + at32_wdt_settimeout(TIMEOUT_MAX);
5011 + dev_dbg(&pdev->dev,
5012 + "default timeout invalid, set to %d sec.\n",
5013 + TIMEOUT_MAX);
5014 + }
5015 +
5016 + ret = misc_register(&wdt->miscdev);
5017 + if (ret) {
5018 + dev_dbg(&pdev->dev, "failed to register wdt miscdev\n");
5019 + goto err_iounmap;
5020 + }
5021 +
5022 + platform_set_drvdata(pdev, wdt);
5023 + wdt->miscdev.parent = &pdev->dev;
5024 + dev_info(&pdev->dev, "AT32AP700X WDT at 0x%p\n", wdt->regs);
5025 +
5026 + return 0;
5027 +
5028 +err_iounmap:
5029 + iounmap(wdt->regs);
5030 +err_free:
5031 + kfree(wdt);
5032 + wdt = NULL;
5033 + return ret;
5034 +}
5035 +
5036 +static int __exit at32_wdt_remove(struct platform_device *pdev)
5037 +{
5038 + if (wdt && platform_get_drvdata(pdev) == wdt) {
5039 + misc_deregister(&wdt->miscdev);
5040 + iounmap(wdt->regs);
5041 + kfree(wdt);
5042 + wdt = NULL;
5043 + platform_set_drvdata(pdev, NULL);
5044 + }
5045 +
5046 + return 0;
5047 +}
5048 +
5049 +static void at32_wdt_shutdown(struct platform_device *pdev)
5050 +{
5051 + at32_wdt_stop();
5052 +}
5053 +
5054 +#ifdef CONFIG_PM
5055 +static int at32_wdt_suspend(struct platform_device *pdev, pm_message_t message)
5056 +{
5057 + at32_wdt_stop();
5058 + return 0;
5059 +}
5060 +
5061 +static int at32_wdt_resume(struct platform_device *pdev)
5062 +{
5063 + if (wdt->users)
5064 + at32_wdt_start();
5065 + return 0;
5066 +}
5067 +#else
5068 +#define at32_wdt_suspend NULL
5069 +#define at32_wdt_resume NULL
5070 +#endif
5071 +
5072 +static struct platform_driver at32_wdt_driver = {
5073 + .remove = __exit_p(at32_wdt_remove),
5074 + .suspend = at32_wdt_suspend,
5075 + .resume = at32_wdt_resume,
5076 + .driver = {
5077 + .name = "at32_wdt",
5078 + .owner = THIS_MODULE,
5079 + },
5080 + .shutdown = at32_wdt_shutdown,
5081 +};
5082 +
5083 +static int __init at32_wdt_init(void)
5084 +{
5085 + return platform_driver_probe(&at32_wdt_driver, at32_wdt_probe);
5086 +}
5087 +module_init(at32_wdt_init);
5088 +
5089 +static void __exit at32_wdt_exit(void)
5090 +{
5091 + platform_driver_unregister(&at32_wdt_driver);
5092 +}
5093 +module_exit(at32_wdt_exit);
5094 +
5095 +MODULE_AUTHOR("Hans-Christian Egtvedt <hcegtvedt@atmel.com>");
5096 +MODULE_DESCRIPTION("Watchdog driver for Atmel AT32AP700X");
5097 +MODULE_LICENSE("GPL");
5098 +MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR);
5099 diff --git a/drivers/i2c/busses/Kconfig b/drivers/i2c/busses/Kconfig
5100 index 838dc1c..80da12d 100644
5101 --- a/drivers/i2c/busses/Kconfig
5102 +++ b/drivers/i2c/busses/Kconfig
5103 @@ -4,6 +4,26 @@
5104
5105 menu "I2C Hardware Bus support"
5106
5107 +config I2C_ATMELTWI
5108 + tristate "Atmel TWI/I2C"
5109 + depends on I2C
5110 + help
5111 + Atmel on-chip TWI controller. Say Y if you have an AT32 or
5112 + AT91-based device and want to use its built-in TWI
5113 + functionality. Atmel's TWI is compatible with Philips' I2C
5114 + protocol. If in doubt, say NO
5115 +
5116 +config I2C_ATMELTWI_BAUDRATE
5117 + prompt "Atmel TWI baudrate"
5118 + depends on I2C_ATMELTWI
5119 + int
5120 + default 100000
5121 + help
5122 + Set the TWI/I2C baudrate. This will alter the default value. A
5123 + different baudrate can be set by using a module parameter as well. If
5124 + no parameter is provided when loading, this is the value that will be
5125 + used.
5126 +
5127 config I2C_ALI1535
5128 tristate "ALI 1535"
5129 depends on PCI
5130 diff --git a/drivers/i2c/busses/Makefile b/drivers/i2c/busses/Makefile
5131 index 14d1432..fd7c3b3 100644
5132 --- a/drivers/i2c/busses/Makefile
5133 +++ b/drivers/i2c/busses/Makefile
5134 @@ -52,6 +52,7 @@ obj-$(CONFIG_I2C_VIAPRO) += i2c-viapro.o
5135 obj-$(CONFIG_I2C_VOODOO3) += i2c-voodoo3.o
5136 obj-$(CONFIG_SCx200_ACB) += scx200_acb.o
5137 obj-$(CONFIG_SCx200_I2C) += scx200_i2c.o
5138 +obj-$(CONFIG_I2C_ATMELTWI) += i2c-atmeltwi.o
5139
5140 ifeq ($(CONFIG_I2C_DEBUG_BUS),y)
5141 EXTRA_CFLAGS += -DDEBUG
5142 diff --git a/drivers/i2c/busses/atmeltwi.h b/drivers/i2c/busses/atmeltwi.h
5143 new file mode 100644
5144 index 0000000..8502ea6
5145 --- /dev/null
5146 +++ b/drivers/i2c/busses/atmeltwi.h
5147 @@ -0,0 +1,117 @@
5148 +/*
5149 + * Register definitions for the Atmel Two-Wire Interface
5150 + */
5151 +
5152 +#ifndef __ASM_AVR32_TWI_H__
5153 +#define __ASM_AVR32_TWI_H__
5154 +
5155 +/* TWI register offsets */
5156 +#define TWI_CR 0x0000
5157 +#define TWI_MMR 0x0004
5158 +#define TWI_SMR 0x0008
5159 +#define TWI_IADR 0x000c
5160 +#define TWI_CWGR 0x0010
5161 +#define TWI_SR 0x0020
5162 +#define TWI_IER 0x0024
5163 +#define TWI_IDR 0x0028
5164 +#define TWI_IMR 0x002c
5165 +#define TWI_RHR 0x0030
5166 +#define TWI_THR 0x0034
5167 +
5168 +/* Bitfields in CR */
5169 +#define TWI_START_OFFSET 0
5170 +#define TWI_START_SIZE 1
5171 +#define TWI_STOP_OFFSET 1
5172 +#define TWI_STOP_SIZE 1
5173 +#define TWI_MSEN_OFFSET 2
5174 +#define TWI_MSEN_SIZE 1
5175 +#define TWI_MSDIS_OFFSET 3
5176 +#define TWI_MSDIS_SIZE 1
5177 +#define TWI_SVEN_OFFSET 4
5178 +#define TWI_SVEN_SIZE 1
5179 +#define TWI_SVDIS_OFFSET 5
5180 +#define TWI_SVDIS_SIZE 1
5181 +#define TWI_SWRST_OFFSET 7
5182 +#define TWI_SWRST_SIZE 1
5183 +
5184 +/* Bitfields in MMR */
5185 +#define TWI_IADRSZ_OFFSET 8
5186 +#define TWI_IADRSZ_SIZE 2
5187 +#define TWI_MREAD_OFFSET 12
5188 +#define TWI_MREAD_SIZE 1
5189 +#define TWI_DADR_OFFSET 16
5190 +#define TWI_DADR_SIZE 7
5191 +
5192 +/* Bitfields in SMR */
5193 +#define TWI_SADR_OFFSET 16
5194 +#define TWI_SADR_SIZE 7
5195 +
5196 +/* Bitfields in IADR */
5197 +#define TWI_IADR_OFFSET 0
5198 +#define TWI_IADR_SIZE 24
5199 +
5200 +/* Bitfields in CWGR */
5201 +#define TWI_CLDIV_OFFSET 0
5202 +#define TWI_CLDIV_SIZE 8
5203 +#define TWI_CHDIV_OFFSET 8
5204 +#define TWI_CHDIV_SIZE 8
5205 +#define TWI_CKDIV_OFFSET 16
5206 +#define TWI_CKDIV_SIZE 3
5207 +
5208 +/* Bitfields in SR */
5209 +#define TWI_TXCOMP_OFFSET 0
5210 +#define TWI_TXCOMP_SIZE 1
5211 +#define TWI_RXRDY_OFFSET 1
5212 +#define TWI_RXRDY_SIZE 1
5213 +#define TWI_TXRDY_OFFSET 2
5214 +#define TWI_TXRDY_SIZE 1
5215 +#define TWI_SVDIR_OFFSET 3
5216 +#define TWI_SVDIR_SIZE 1
5217 +#define TWI_SVACC_OFFSET 4
5218 +#define TWI_SVACC_SIZE 1
5219 +#define TWI_GCACC_OFFSET 5
5220 +#define TWI_GCACC_SIZE 1
5221 +#define TWI_OVRE_OFFSET 6
5222 +#define TWI_OVRE_SIZE 1
5223 +#define TWI_UNRE_OFFSET 7
5224 +#define TWI_UNRE_SIZE 1
5225 +#define TWI_NACK_OFFSET 8
5226 +#define TWI_NACK_SIZE 1
5227 +#define TWI_ARBLST_OFFSET 9
5228 +#define TWI_ARBLST_SIZE 1
5229 +
5230 +/* Bitfields in RHR */
5231 +#define TWI_RXDATA_OFFSET 0
5232 +#define TWI_RXDATA_SIZE 8
5233 +
5234 +/* Bitfields in THR */
5235 +#define TWI_TXDATA_OFFSET 0
5236 +#define TWI_TXDATA_SIZE 8
5237 +
5238 +/* Constants for IADRSZ */
5239 +#define TWI_IADRSZ_NO_ADDR 0
5240 +#define TWI_IADRSZ_ONE_BYTE 1
5241 +#define TWI_IADRSZ_TWO_BYTES 2
5242 +#define TWI_IADRSZ_THREE_BYTES 3
5243 +
5244 +/* Bit manipulation macros */
5245 +#define TWI_BIT(name) \
5246 + (1 << TWI_##name##_OFFSET)
5247 +#define TWI_BF(name,value) \
5248 + (((value) & ((1 << TWI_##name##_SIZE) - 1)) \
5249 + << TWI_##name##_OFFSET)
5250 +#define TWI_BFEXT(name,value) \
5251 + (((value) >> TWI_##name##_OFFSET) \
5252 + & ((1 << TWI_##name##_SIZE) - 1))
5253 +#define TWI_BFINS(name,value,old) \
5254 + (((old) & ~(((1 << TWI_##name##_SIZE) - 1) \
5255 + << TWI_##name##_OFFSET)) \
5256 + | TWI_BF(name,value))
5257 +
5258 +/* Register access macros */
5259 +#define twi_readl(port,reg) \
5260 + __raw_readl((port)->regs + TWI_##reg)
5261 +#define twi_writel(port,reg,value) \
5262 + __raw_writel((value), (port)->regs + TWI_##reg)
5263 +
5264 +#endif /* __ASM_AVR32_TWI_H__ */
5265 diff --git a/drivers/i2c/busses/i2c-atmeltwi.c b/drivers/i2c/busses/i2c-atmeltwi.c
5266 new file mode 100644
5267 index 0000000..9a3f223
5268 --- /dev/null
5269 +++ b/drivers/i2c/busses/i2c-atmeltwi.c
5270 @@ -0,0 +1,383 @@
5271 +/*
5272 + * i2c Support for Atmel's Two-Wire Interface (TWI)
5273 + *
5274 + * Based on the work of Copyright (C) 2004 Rick Bronson
5275 + * Converted to 2.6 by Andrew Victor <andrew at sanpeople.com>
5276 + * Ported to AVR32 and heavily modified by Espen Krangnes
5277 + * <ekrangnes at atmel.com>
5278 + *
5279 + * Copyright (C) 2006 Atmel Corporation
5280 + *
5281 + * Borrowed heavily from the original work by:
5282 + * Copyright (C) 2000 Philip Edelbrock <phil at stimpy.netroedge.com>
5283 + *
5284 + * Partialy rewriten by Karel Hojdar <cmkaho at seznam.cz>
5285 + * bugs removed, interrupt routine markedly rewritten
5286 + *
5287 + * This program is free software; you can redistribute it and/or modify
5288 + * it under the terms of the GNU General Public License as published by
5289 + * the Free Software Foundation; either version 2 of the License, or
5290 + * (at your option) any later version.
5291 + */
5292 +
5293 +
5294 +#include <linux/err.h>
5295 +#include <linux/module.h>
5296 +#include <linux/kernel.h>
5297 +#include <linux/slab.h>
5298 +#include <linux/types.h>
5299 +#include <linux/delay.h>
5300 +#include <linux/i2c.h>
5301 +#include <linux/init.h>
5302 +#include <linux/clk.h>
5303 +#include <linux/interrupt.h>
5304 +#include <linux/irq.h>
5305 +#include <linux/platform_device.h>
5306 +#include <linux/completion.h>
5307 +#include <asm/io.h>
5308 +#include <linux/time.h>
5309 +#include "atmeltwi.h"
5310 +
5311 +static unsigned int baudrate = CONFIG_I2C_ATMELTWI_BAUDRATE;
5312 +module_param(baudrate, uint, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP);
5313 +MODULE_PARM_DESC(baudrate, "The TWI baudrate");
5314 +
5315 +
5316 +struct atmel_twi {
5317 + void __iomem *regs;
5318 + struct i2c_adapter adapter;
5319 + struct clk *pclk;
5320 + spinlock_t lock;
5321 + struct completion comp;
5322 + u32 intmask;
5323 + u8 *buf;
5324 + u8 len;
5325 + u8 acks_left;
5326 + u8 nack;
5327 + unsigned int irq;
5328 +
5329 +};
5330 +#define to_atmel_twi(adap) container_of(adap, struct atmel_twi, adapter)
5331 +
5332 +/*
5333 + * Initialize the TWI hardware registers.
5334 + */
5335 +static int __devinit twi_hwinit(struct atmel_twi *twi)
5336 +{
5337 + unsigned long cdiv, ckdiv=0;
5338 +
5339 + twi_writel(twi, IDR, ~0UL);
5340 + twi_writel(twi, CR, TWI_BIT(SWRST)); /*Reset peripheral*/
5341 + twi_readl(twi, SR);
5342 +
5343 + cdiv = (clk_get_rate(twi->pclk) / (2 * baudrate)) - 4;
5344 +
5345 + while (cdiv > 255) {
5346 + ckdiv++;
5347 + cdiv = cdiv >> 1;
5348 + }
5349 +
5350 + if (ckdiv > 7)
5351 + return -EINVAL;
5352 + else
5353 + twi_writel(twi, CWGR, (TWI_BF(CKDIV, ckdiv)
5354 + | TWI_BF(CHDIV, cdiv)
5355 + | TWI_BF(CLDIV, cdiv)));
5356 + return 0;
5357 +}
5358 +
5359 +/*
5360 + * Waits for the i2c status register to set the specified bitmask
5361 + * Returns 0 if timed out (~100ms).
5362 + */
5363 +static short twi_complete(struct atmel_twi *twi, u32 mask)
5364 +{
5365 + int timeout = msecs_to_jiffies(100);
5366 +
5367 + twi->intmask = mask;
5368 + init_completion(&twi->comp);
5369 +
5370 + twi_writel(twi, IER, mask);
5371 +
5372 + if (!wait_for_completion_timeout(&twi->comp, timeout)) {
5373 + /* RESET TWI interface */
5374 + twi_writel(twi, CR, TWI_BIT(SWRST));
5375 +
5376 + /* Reinitialize TWI */
5377 + twi_hwinit(twi);
5378 +
5379 + return -ETIMEDOUT;
5380 + }
5381 + return 0;
5382 +}
5383 +
5384 +/*
5385 + * Generic i2c master transfer entrypoint.
5386 + */
5387 +static int twi_xfer(struct i2c_adapter *adap, struct i2c_msg msgs[], int num)
5388 +{
5389 + struct atmel_twi *twi = to_atmel_twi(adap);
5390 + struct i2c_msg *pmsg;
5391 + int i;
5392 +
5393 + /* get first message */
5394 + pmsg = msgs;
5395 +
5396 + dev_dbg(&adap->dev, "twi_xfer: processing %d messages:\n", num);
5397 +
5398 + twi->nack = 0;
5399 + for (i = 0; i < num; i++, pmsg++) {
5400 + twi->len = pmsg->len;
5401 + twi->buf = pmsg->buf;
5402 + twi->acks_left = pmsg->len;
5403 + twi_writel(twi, MMR, TWI_BF(DADR, pmsg->addr) |
5404 + (pmsg->flags & I2C_M_RD ? TWI_BIT(MREAD) : 0));
5405 + twi_writel(twi, IADR, TWI_BF(IADR, pmsg->addr));
5406 +
5407 + dev_dbg(&adap->dev,"#%d: internal addr %d %s byte%s %s 0x%02x\n",
5408 + i,pmsg->len, pmsg->flags & I2C_M_RD ? "reading" : "writing",
5409 + pmsg->len > 1 ? "s" : "",
5410 + pmsg->flags & I2C_M_RD ? "from" : "to", pmsg->addr);
5411 +
5412 + /* enable */
5413 + twi_writel(twi, CR, TWI_BIT(MSEN));
5414 +
5415 + if (pmsg->flags & I2C_M_RD) {
5416 + if (twi->len == 1)
5417 + twi_writel(twi, CR,
5418 + TWI_BIT(START) | TWI_BIT(STOP));
5419 + else
5420 + twi_writel(twi, CR, TWI_BIT(START));
5421 +
5422 + if (twi_complete(twi, TWI_BIT(RXRDY)) == -ETIMEDOUT) {
5423 + dev_dbg(&adap->dev, "RXRDY timeout. Stopped with %d bytes left\n",
5424 + twi->acks_left);
5425 + return -ETIMEDOUT;
5426 + }
5427 + } else {
5428 + twi_writel(twi, THR, twi->buf[0]);
5429 + if (twi_complete(twi, TWI_BIT(TXRDY)) == -ETIMEDOUT) {
5430 + dev_dbg(&adap->dev, "TXRDY timeout. Stopped with %d bytes left\n",
5431 + twi->acks_left);
5432 + return -ETIMEDOUT;
5433 + }
5434 +
5435 + if (twi->nack)
5436 + return -ENODEV;
5437 + }
5438 +
5439 + /* Disable TWI interface */
5440 + twi_writel(twi, CR, TWI_BIT(MSDIS));
5441 +
5442 + } /* end cur msg */
5443 +
5444 + return i;
5445 +}
5446 +
5447 +
5448 +static irqreturn_t twi_interrupt(int irq, void *dev_id)
5449 +{
5450 + struct atmel_twi *twi = dev_id;
5451 + int status = twi_readl(twi, SR);
5452 +
5453 + /* Save state for later debug prints */
5454 + int old_mask = twi->intmask;
5455 + int old_status = status;
5456 +
5457 + if (twi->intmask & status) {
5458 + if (status & TWI_BIT(NACK))
5459 + goto nack;
5460 +
5461 + status &= twi->intmask;
5462 +
5463 + if (status & TWI_BIT(TXCOMP))
5464 + goto complete;
5465 +
5466 + else if (status & TWI_BIT(RXRDY)) {
5467 + if ( twi->acks_left > 0 ) {
5468 + twi->buf[twi->len - twi->acks_left] =
5469 + twi_readl(twi, RHR);
5470 + twi->acks_left--;
5471 + }
5472 + if ( twi->acks_left == 1 )
5473 + twi_writel(twi, CR, TWI_BIT(STOP));
5474 +
5475 + if (twi->acks_left == 0 ) {
5476 + twi->intmask = TWI_BIT(TXCOMP);
5477 + twi_writel(twi, IER, TWI_BIT(TXCOMP));
5478 + }
5479 + } else if (status & TWI_BIT(TXRDY)) {
5480 + twi->acks_left--;
5481 + if ( twi->acks_left == 0 ) {
5482 + twi->intmask = TWI_BIT(TXCOMP);
5483 + twi_writel(twi, IER, TWI_BIT(TXCOMP));
5484 + } else if (twi->acks_left > 0)
5485 + twi_writel(twi, THR, twi->buf[twi->len - twi->acks_left]);
5486 + }
5487 + }
5488 +
5489 + dev_dbg(&twi->adapter.dev,
5490 + "TWI ISR, SR 0x%08X, intmask 0x%08X, acks_left %i.\n",
5491 + old_status, old_mask, twi->acks_left);
5492 +
5493 + return IRQ_HANDLED;
5494 +
5495 +nack:
5496 + dev_dbg(&twi->adapter.dev, "NACK received!\n");
5497 + twi->nack = 1;
5498 +
5499 +complete:
5500 + twi_writel(twi, IDR, ~0UL);
5501 + complete(&twi->comp);
5502 +
5503 + dev_dbg(&twi->adapter.dev,
5504 + "TWI ISR, SR 0x%08X, intmask 0x%08X, \
5505 + acks_left %i - completed.\n",
5506 + old_status, old_mask, twi->acks_left);
5507 +
5508 + return IRQ_HANDLED;
5509 +}
5510 +
5511 +
5512 +/*
5513 + * Return list of supported functionality.
5514 + */
5515 +static u32 twi_func(struct i2c_adapter *adapter)
5516 +{
5517 + return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL;
5518 +}
5519 +
5520 +/* For now, we only handle combined mode (smbus) */
5521 +static struct i2c_algorithm twi_algorithm = {
5522 + .master_xfer = twi_xfer,
5523 + .functionality = twi_func,
5524 +};
5525 +
5526 +/*
5527 + * Main initialization routine.
5528 + */
5529 +static int __devinit twi_probe(struct platform_device *pdev)
5530 +{
5531 + struct atmel_twi *twi;
5532 + struct resource *regs;
5533 + struct clk *pclk;
5534 + struct i2c_adapter *adapter;
5535 + int rc, irq;
5536 +
5537 + regs = platform_get_resource(pdev, IORESOURCE_MEM, 0);
5538 + if (!regs)
5539 + return -ENXIO;
5540 +
5541 + pclk = clk_get(&pdev->dev, "pclk");
5542 + if (IS_ERR(pclk))
5543 + return PTR_ERR(pclk);
5544 + clk_enable(pclk);
5545 +
5546 + rc = -ENOMEM;
5547 + twi = kzalloc(sizeof(struct atmel_twi), GFP_KERNEL);
5548 + if (!twi) {
5549 + dev_err(&pdev->dev, "can't allocate interface!\n");
5550 + goto err_alloc_twi;
5551 + }
5552 +
5553 + twi->pclk = pclk;
5554 + twi->regs = ioremap(regs->start, regs->end - regs->start + 1);
5555 + if (!twi->regs)
5556 + goto err_ioremap;
5557 +
5558 + irq = platform_get_irq(pdev,0);
5559 + rc = request_irq(irq, twi_interrupt, 0, "twi", twi);
5560 + if (rc) {
5561 + dev_err(&pdev->dev, "can't bind irq!\n");
5562 + goto err_irq;
5563 + }
5564 + twi->irq = irq;
5565 +
5566 + rc = twi_hwinit(twi);
5567 + if (rc) {
5568 + dev_err(&pdev->dev, "Unable to set baudrate\n");
5569 + goto err_hw_init;
5570 + }
5571 +
5572 + adapter = &twi->adapter;
5573 + sprintf(adapter->name, "TWI");
5574 + adapter->algo = &twi_algorithm;
5575 + adapter->class = I2C_CLASS_HWMON;
5576 + adapter->dev.parent = &pdev->dev;
5577 +
5578 + platform_set_drvdata(pdev, twi);
5579 +
5580 + rc = i2c_add_adapter(adapter);
5581 + if (rc) {
5582 + dev_err(&pdev->dev, "Adapter %s registration failed\n",
5583 + adapter->name);
5584 + goto err_register;
5585 + }
5586 +
5587 + dev_info(&pdev->dev, "Atmel TWI i2c bus device (baudrate %dk) at 0x%08lx.\n",
5588 + baudrate/1000, (unsigned long)regs->start);
5589 +
5590 + return 0;
5591 +
5592 +
5593 +err_register:
5594 + platform_set_drvdata(pdev, NULL);
5595 +
5596 +err_hw_init:
5597 + free_irq(irq, twi);
5598 +
5599 +err_irq:
5600 + iounmap(twi->regs);
5601 +
5602 +err_ioremap:
5603 + kfree(twi);
5604 +
5605 +err_alloc_twi:
5606 + clk_disable(pclk);
5607 + clk_put(pclk);
5608 +
5609 + return rc;
5610 +}
5611 +
5612 +static int __devexit twi_remove(struct platform_device *pdev)
5613 +{
5614 + struct atmel_twi *twi = platform_get_drvdata(pdev);
5615 + int res;
5616 +
5617 + platform_set_drvdata(pdev, NULL);
5618 + res = i2c_del_adapter(&twi->adapter);
5619 + twi_writel(twi, CR, TWI_BIT(MSDIS));
5620 + iounmap(twi->regs);
5621 + clk_disable(twi->pclk);
5622 + clk_put(twi->pclk);
5623 + free_irq(twi->irq, twi);
5624 + kfree(twi);
5625 +
5626 + return res;
5627 +}
5628 +
5629 +static struct platform_driver twi_driver = {
5630 + .probe = twi_probe,
5631 + .remove = __devexit_p(twi_remove),
5632 + .driver = {
5633 + .name = "atmel_twi",
5634 + .owner = THIS_MODULE,
5635 + },
5636 +};
5637 +
5638 +static int __init atmel_twi_init(void)
5639 +{
5640 + return platform_driver_register(&twi_driver);
5641 +}
5642 +
5643 +static void __exit atmel_twi_exit(void)
5644 +{
5645 + platform_driver_unregister(&twi_driver);
5646 +}
5647 +
5648 +module_init(atmel_twi_init);
5649 +module_exit(atmel_twi_exit);
5650 +
5651 +MODULE_AUTHOR("Espen Krangnes");
5652 +MODULE_DESCRIPTION("I2C driver for Atmel TWI");
5653 +MODULE_LICENSE("GPL");
5654 diff --git a/drivers/input/mouse/Kconfig b/drivers/input/mouse/Kconfig
5655 index 50e06e8..7bbea09 100644
5656 --- a/drivers/input/mouse/Kconfig
5657 +++ b/drivers/input/mouse/Kconfig
5658 @@ -216,4 +216,20 @@ config MOUSE_HIL
5659 help
5660 Say Y here to support HIL pointers.
5661
5662 +config MOUSE_GPIO
5663 + tristate "GPIO mouse"
5664 + depends on GENERIC_GPIO
5665 + select INPUT_POLLDEV
5666 + help
5667 + This driver simulates a mouse on GPIO lines of various CPUs (and some
5668 + other chips).
5669 +
5670 + Say Y here if your device has buttons or a simple joystick connected
5671 + directly to GPIO lines. Your board-specific setup logic must also
5672 + provide a platform device and platform data saying which GPIOs are
5673 + used.
5674 +
5675 + To compile this driver as a module, choose M here: the
5676 + module will be called gpio_mouse.
5677 +
5678 endif
5679 diff --git a/drivers/input/mouse/Makefile b/drivers/input/mouse/Makefile
5680 index aa4ba87..9e6e363 100644
5681 --- a/drivers/input/mouse/Makefile
5682 +++ b/drivers/input/mouse/Makefile
5683 @@ -15,6 +15,7 @@ obj-$(CONFIG_MOUSE_PS2) += psmouse.o
5684 obj-$(CONFIG_MOUSE_SERIAL) += sermouse.o
5685 obj-$(CONFIG_MOUSE_HIL) += hil_ptr.o
5686 obj-$(CONFIG_MOUSE_VSXXXAA) += vsxxxaa.o
5687 +obj-$(CONFIG_MOUSE_GPIO) += gpio_mouse.o
5688
5689 psmouse-objs := psmouse-base.o synaptics.o
5690
5691 diff --git a/drivers/input/mouse/gpio_mouse.c b/drivers/input/mouse/gpio_mouse.c
5692 new file mode 100644
5693 index 0000000..0936d6b
5694 --- /dev/null
5695 +++ b/drivers/input/mouse/gpio_mouse.c
5696 @@ -0,0 +1,196 @@
5697 +/*
5698 + * Driver for simulating a mouse on GPIO lines.
5699 + *
5700 + * Copyright (C) 2007 Atmel Corporation
5701 + *
5702 + * This program is free software; you can redistribute it and/or modify
5703 + * it under the terms of the GNU General Public License version 2 as
5704 + * published by the Free Software Foundation.
5705 + */
5706 +
5707 +#include <linux/init.h>
5708 +#include <linux/version.h>
5709 +#include <linux/module.h>
5710 +#include <linux/platform_device.h>
5711 +#include <linux/input-polldev.h>
5712 +#include <linux/gpio_mouse.h>
5713 +
5714 +#include <asm/gpio.h>
5715 +
5716 +/*
5717 + * Timer function which is run every scan_ms ms when the device is opened.
5718 + * The dev input varaible is set to the the input_dev pointer.
5719 + */
5720 +static void gpio_mouse_scan(struct input_polled_dev *dev)
5721 +{
5722 + struct gpio_mouse_platform_data *gpio = dev->private;
5723 + struct input_dev *input = dev->input;
5724 + int x, y;
5725 +
5726 + if (gpio->bleft >= 0)
5727 + input_report_key(input, BTN_LEFT,
5728 + gpio_get_value(gpio->bleft) ^ gpio->polarity);
5729 + if (gpio->bmiddle >= 0)
5730 + input_report_key(input, BTN_MIDDLE,
5731 + gpio_get_value(gpio->bmiddle) ^ gpio->polarity);
5732 + if (gpio->bright >= 0)
5733 + input_report_key(input, BTN_RIGHT,
5734 + gpio_get_value(gpio->bright) ^ gpio->polarity);
5735 +
5736 + x = (gpio_get_value(gpio->right) ^ gpio->polarity)
5737 + - (gpio_get_value(gpio->left) ^ gpio->polarity);
5738 + y = (gpio_get_value(gpio->down) ^ gpio->polarity)
5739 + - (gpio_get_value(gpio->up) ^ gpio->polarity);
5740 +
5741 + input_report_rel(input, REL_X, x);
5742 + input_report_rel(input, REL_Y, y);
5743 + input_sync(input);
5744 +}
5745 +
5746 +static int __init gpio_mouse_probe(struct platform_device *pdev)
5747 +{
5748 + struct gpio_mouse_platform_data *pdata = pdev->dev.platform_data;
5749 + struct input_polled_dev *input_poll;
5750 + struct input_dev *input;
5751 + int pin, i;
5752 + int error;
5753 +
5754 + if (!pdata) {
5755 + dev_err(&pdev->dev, "no platform data\n");
5756 + error = -ENXIO;
5757 + goto out;
5758 + }
5759 +
5760 + if (pdata->scan_ms < 0) {
5761 + dev_err(&pdev->dev, "invalid scan time\n");
5762 + error = -EINVAL;
5763 + goto out;
5764 + }
5765 +
5766 + for (i = 0; i < GPIO_MOUSE_PIN_MAX; i++) {
5767 + pin = pdata->pins[i];
5768 +
5769 + if (pin < 0) {
5770 +
5771 + if (i <= GPIO_MOUSE_PIN_RIGHT) {
5772 + /* Mouse direction is required. */
5773 + dev_err(&pdev->dev,
5774 + "missing GPIO for directions\n");
5775 + error = -EINVAL;
5776 + goto out_free_gpios;
5777 + }
5778 +
5779 + if (i == GPIO_MOUSE_PIN_BLEFT)
5780 + dev_dbg(&pdev->dev, "no left button defined\n");
5781 +
5782 + } else {
5783 + error = gpio_request(pin, "gpio_mouse");
5784 + if (error) {
5785 + dev_err(&pdev->dev, "fail %d pin (%d idx)\n",
5786 + pin, i);
5787 + goto out_free_gpios;
5788 + }
5789 +
5790 + gpio_direction_input(pin);
5791 + }
5792 + }
5793 +
5794 + input_poll = input_allocate_polled_device();
5795 + if (!input_poll) {
5796 + dev_err(&pdev->dev, "not enough memory for input device\n");
5797 + error = -ENOMEM;
5798 + goto out_free_gpios;
5799 + }
5800 +
5801 + platform_set_drvdata(pdev, input_poll);
5802 +
5803 + /* set input-polldev handlers */
5804 + input_poll->private = pdata;
5805 + input_poll->poll = gpio_mouse_scan;
5806 + input_poll->poll_interval = pdata->scan_ms;
5807 +
5808 + input = input_poll->input;
5809 + input->name = pdev->name;
5810 + input->id.bustype = BUS_HOST;
5811 + input->dev.parent = &pdev->dev;
5812 +
5813 + input_set_capability(input, EV_REL, REL_X);
5814 + input_set_capability(input, EV_REL, REL_Y);
5815 + if (pdata->bleft >= 0)
5816 + input_set_capability(input, EV_KEY, BTN_LEFT);
5817 + if (pdata->bmiddle >= 0)
5818 + input_set_capability(input, EV_KEY, BTN_MIDDLE);
5819 + if (pdata->bright >= 0)
5820 + input_set_capability(input, EV_KEY, BTN_RIGHT);
5821 +
5822 + error = input_register_polled_device(input_poll);
5823 + if (error) {
5824 + dev_err(&pdev->dev, "could not register input device\n");
5825 + goto out_free_polldev;
5826 + }
5827 +
5828 + dev_dbg(&pdev->dev, "%d ms scan time, buttons: %s%s%s\n",
5829 + pdata->scan_ms,
5830 + pdata->bleft < 0 ? "" : "left ",
5831 + pdata->bmiddle < 0 ? "" : "middle ",
5832 + pdata->bright < 0 ? "" : "right");
5833 +
5834 + return 0;
5835 +
5836 + out_free_polldev:
5837 + input_free_polled_device(input_poll);
5838 + platform_set_drvdata(pdev, NULL);
5839 +
5840 + out_free_gpios:
5841 + while (--i >= 0) {
5842 + pin = pdata->pins[i];
5843 + if (pin)
5844 + gpio_free(pin);
5845 + }
5846 + out:
5847 + return error;
5848 +}
5849 +
5850 +static int __devexit gpio_mouse_remove(struct platform_device *pdev)
5851 +{
5852 + struct input_polled_dev *input = platform_get_drvdata(pdev);
5853 + struct gpio_mouse_platform_data *pdata = input->private;
5854 + int pin, i;
5855 +
5856 + input_unregister_polled_device(input);
5857 + input_free_polled_device(input);
5858 +
5859 + for (i = 0; i < GPIO_MOUSE_PIN_MAX; i++) {
5860 + pin = pdata->pins[i];
5861 + if (pin >= 0)
5862 + gpio_free(pin);
5863 + }
5864 +
5865 + platform_set_drvdata(pdev, NULL);
5866 +
5867 + return 0;
5868 +}
5869 +
5870 +struct platform_driver gpio_mouse_device_driver = {
5871 + .remove = __devexit_p(gpio_mouse_remove),
5872 + .driver = {
5873 + .name = "gpio_mouse",
5874 + }
5875 +};
5876 +
5877 +static int __init gpio_mouse_init(void)
5878 +{
5879 + return platform_driver_probe(&gpio_mouse_device_driver,
5880 + gpio_mouse_probe);
5881 +}
5882 +module_init(gpio_mouse_init);
5883 +
5884 +static void __exit gpio_mouse_exit(void)
5885 +{
5886 + platform_driver_unregister(&gpio_mouse_device_driver);
5887 +}
5888 +module_exit(gpio_mouse_exit);
5889 +
5890 +MODULE_AUTHOR("Hans-Christian Egtvedt <hcegtvedt@atmel.com>");
5891 +MODULE_DESCRIPTION("GPIO mouse driver");
5892 +MODULE_LICENSE("GPL");
5893 diff --git a/drivers/leds/Kconfig b/drivers/leds/Kconfig
5894 index 87d2046..9ce3ca1 100644
5895 --- a/drivers/leds/Kconfig
5896 +++ b/drivers/leds/Kconfig
5897 @@ -95,6 +95,14 @@ config LEDS_COBALT
5898 help
5899 This option enables support for the front LED on Cobalt Server
5900
5901 +config LEDS_GPIO
5902 + tristate "LED Support for GPIO connected LEDs"
5903 + depends on LEDS_CLASS && GENERIC_GPIO
5904 + help
5905 + This option enables support for the LEDs connected to GPIO
5906 + outputs. To be useful the particular board must have LEDs
5907 + and they must be connected to the GPIO lines.
5908 +
5909 comment "LED Triggers"
5910
5911 config LEDS_TRIGGERS
5912 diff --git a/drivers/leds/Makefile b/drivers/leds/Makefile
5913 index aa2c18e..f8995c9 100644
5914 --- a/drivers/leds/Makefile
5915 +++ b/drivers/leds/Makefile
5916 @@ -16,6 +16,7 @@ obj-$(CONFIG_LEDS_NET48XX) += leds-net48xx.o
5917 obj-$(CONFIG_LEDS_WRAP) += leds-wrap.o
5918 obj-$(CONFIG_LEDS_H1940) += leds-h1940.o
5919 obj-$(CONFIG_LEDS_COBALT) += leds-cobalt.o
5920 +obj-$(CONFIG_LEDS_GPIO) += leds-gpio.o
5921
5922 # LED Triggers
5923 obj-$(CONFIG_LEDS_TRIGGER_TIMER) += ledtrig-timer.o
5924 diff --git a/drivers/leds/leds-gpio.c b/drivers/leds/leds-gpio.c
5925 new file mode 100644
5926 index 0000000..47d90db
5927 --- /dev/null
5928 +++ b/drivers/leds/leds-gpio.c
5929 @@ -0,0 +1,199 @@
5930 +/*
5931 + * LEDs driver for GPIOs
5932 + *
5933 + * Copyright (C) 2007 8D Technologies inc.
5934 + * Raphael Assenat <raph@8d.com>
5935 + *
5936 + * This program is free software; you can redistribute it and/or modify
5937 + * it under the terms of the GNU General Public License version 2 as
5938 + * published by the Free Software Foundation.
5939 + *
5940 + */
5941 +#include <linux/kernel.h>
5942 +#include <linux/init.h>
5943 +#include <linux/platform_device.h>
5944 +#include <linux/leds.h>
5945 +#include <linux/workqueue.h>
5946 +
5947 +#include <asm/gpio.h>
5948 +
5949 +struct gpio_led_data {
5950 + struct led_classdev cdev;
5951 + unsigned gpio;
5952 + struct work_struct work;
5953 + u8 new_level;
5954 + u8 can_sleep;
5955 + u8 active_low;
5956 +};
5957 +
5958 +static void gpio_led_work(struct work_struct *work)
5959 +{
5960 + struct gpio_led_data *led_dat =
5961 + container_of(work, struct gpio_led_data, work);
5962 +
5963 + gpio_set_value_cansleep(led_dat->gpio, led_dat->new_level);
5964 +}
5965 +
5966 +static void gpio_led_set(struct led_classdev *led_cdev,
5967 + enum led_brightness value)
5968 +{
5969 + struct gpio_led_data *led_dat =
5970 + container_of(led_cdev, struct gpio_led_data, cdev);
5971 + int level;
5972 +
5973 + if (value == LED_OFF)
5974 + level = 0;
5975 + else
5976 + level = 1;
5977 +
5978 + if (led_dat->active_low)
5979 + level = !level;
5980 +
5981 + /* setting GPIOs with I2C/etc requires a preemptible task context */
5982 + if (led_dat->can_sleep) {
5983 + if (preempt_count()) {
5984 + led_dat->new_level = level;
5985 + schedule_work(&led_dat->work);
5986 + } else
5987 + gpio_set_value_cansleep(led_dat->gpio, level);
5988 + } else
5989 + gpio_set_value(led_dat->gpio, level);
5990 +}
5991 +
5992 +static int __init gpio_led_probe(struct platform_device *pdev)
5993 +{
5994 + struct gpio_led_platform_data *pdata = pdev->dev.platform_data;
5995 + struct gpio_led *cur_led;
5996 + struct gpio_led_data *leds_data, *led_dat;
5997 + int i, ret = 0;
5998 +
5999 + if (!pdata)
6000 + return -EBUSY;
6001 +
6002 + leds_data = kzalloc(sizeof(struct gpio_led_data) * pdata->num_leds,
6003 + GFP_KERNEL);
6004 + if (!leds_data)
6005 + return -ENOMEM;
6006 +
6007 + for (i = 0; i < pdata->num_leds; i++) {
6008 + cur_led = &pdata->leds[i];
6009 + led_dat = &leds_data[i];
6010 +
6011 + led_dat->cdev.name = cur_led->name;
6012 + led_dat->cdev.default_trigger = cur_led->default_trigger;
6013 + led_dat->gpio = cur_led->gpio;
6014 + led_dat->can_sleep = gpio_cansleep(cur_led->gpio);
6015 + led_dat->active_low = cur_led->active_low;
6016 + led_dat->cdev.brightness_set = gpio_led_set;
6017 + led_dat->cdev.brightness = cur_led->active_low ? LED_FULL : LED_OFF;
6018 +
6019 + ret = gpio_request(led_dat->gpio, led_dat->cdev.name);
6020 + if (ret < 0)
6021 + goto err;
6022 +
6023 + gpio_direction_output(led_dat->gpio, led_dat->active_low);
6024 +
6025 + ret = led_classdev_register(&pdev->dev, &led_dat->cdev);
6026 + if (ret < 0) {
6027 + gpio_free(led_dat->gpio);
6028 + goto err;
6029 + }
6030 +
6031 + INIT_WORK(&led_dat->work, gpio_led_work);
6032 + }
6033 +
6034 + platform_set_drvdata(pdev, leds_data);
6035 +
6036 + return 0;
6037 +
6038 +err:
6039 + if (i > 0) {
6040 + for (i = i - 1; i >= 0; i--) {
6041 + led_classdev_unregister(&leds_data[i].cdev);
6042 + gpio_free(leds_data[i].gpio);
6043 + }
6044 + }
6045 +
6046 + flush_scheduled_work();
6047 + kfree(leds_data);
6048 +
6049 + return ret;
6050 +}
6051 +
6052 +static int __exit gpio_led_remove(struct platform_device *pdev)
6053 +{
6054 + int i;
6055 + struct gpio_led_platform_data *pdata = pdev->dev.platform_data;
6056 + struct gpio_led_data *leds_data;
6057 +
6058 + leds_data = platform_get_drvdata(pdev);
6059 +
6060 + for (i = 0; i < pdata->num_leds; i++) {
6061 + led_classdev_unregister(&leds_data[i].cdev);
6062 + gpio_free(leds_data[i].gpio);
6063 + }
6064 +
6065 + kfree(leds_data);
6066 +
6067 + return 0;
6068 +}
6069 +
6070 +#ifdef CONFIG_PM
6071 +static int gpio_led_suspend(struct platform_device *pdev, pm_message_t state)
6072 +{
6073 + struct gpio_led_platform_data *pdata = pdev->dev.platform_data;
6074 + struct gpio_led_data *leds_data;
6075 + int i;
6076 +
6077 + leds_data = platform_get_drvdata(pdev);
6078 +
6079 + for (i = 0; i < pdata->num_leds; i++)
6080 + led_classdev_suspend(&leds_data[i].cdev);
6081 +
6082 + return 0;
6083 +}
6084 +
6085 +static int gpio_led_resume(struct platform_device *pdev)
6086 +{
6087 + struct gpio_led_platform_data *pdata = pdev->dev.platform_data;
6088 + struct gpio_led_data *leds_data;
6089 + int i;
6090 +
6091 + leds_data = platform_get_drvdata(pdev);
6092 +
6093 + for (i = 0; i < pdata->num_leds; i++)
6094 + led_classdev_resume(&leds_data[i].cdev);
6095 +
6096 + return 0;
6097 +}
6098 +#else
6099 +#define gpio_led_suspend NULL
6100 +#define gpio_led_resume NULL
6101 +#endif
6102 +
6103 +static struct platform_driver gpio_led_driver = {
6104 + .remove = __exit_p(gpio_led_remove),
6105 + .suspend = gpio_led_suspend,
6106 + .resume = gpio_led_resume,
6107 + .driver = {
6108 + .name = "leds-gpio",
6109 + .owner = THIS_MODULE,
6110 + },
6111 +};
6112 +
6113 +static int __init gpio_led_init(void)
6114 +{
6115 + return platform_driver_probe(&gpio_led_driver, gpio_led_probe);
6116 +}
6117 +
6118 +static void __exit gpio_led_exit(void)
6119 +{
6120 + platform_driver_unregister(&gpio_led_driver);
6121 +}
6122 +
6123 +module_init(gpio_led_init);
6124 +module_exit(gpio_led_exit);
6125 +
6126 +MODULE_AUTHOR("Raphael Assenat <raph@8d.com>");
6127 +MODULE_DESCRIPTION("GPIO LED driver");
6128 +MODULE_LICENSE("GPL");
6129 diff --git a/drivers/misc/Kconfig b/drivers/misc/Kconfig
6130 index 616eee9..0810d83 100644
6131 --- a/drivers/misc/Kconfig
6132 +++ b/drivers/misc/Kconfig
6133 @@ -187,5 +187,15 @@ config THINKPAD_ACPI_BAY
6134
6135 If you are not sure, say Y here.
6136
6137 +config ATMEL_SSC
6138 + tristate "Device driver for Atmel SSC peripheral"
6139 + depends on AVR32 || ARCH_AT91
6140 + ---help---
6141 + This option enables device driver support for Atmel Syncronized
6142 + Serial Communication peripheral (SSC).
6143 +
6144 + The SSC peripheral supports a wide variety of serial frame based
6145 + communications, i.e. I2S, SPI, etc.
6146
6147 + If unsure, say N.
6148 endmenu
6149 diff --git a/drivers/misc/Makefile b/drivers/misc/Makefile
6150 index 8abbf2f..2d52cc6 100644
6151 --- a/drivers/misc/Makefile
6152 +++ b/drivers/misc/Makefile
6153 @@ -14,3 +14,4 @@ obj-$(CONFIG_PHANTOM) += phantom.o
6154 obj-$(CONFIG_SGI_IOC4) += ioc4.o
6155 obj-$(CONFIG_SONY_LAPTOP) += sony-laptop.o
6156 obj-$(CONFIG_THINKPAD_ACPI) += thinkpad_acpi.o
6157 +obj-$(CONFIG_ATMEL_SSC) += atmel-ssc.o
6158 diff --git a/drivers/misc/atmel-ssc.c b/drivers/misc/atmel-ssc.c
6159 new file mode 100644
6160 index 0000000..058ccac
6161 --- /dev/null
6162 +++ b/drivers/misc/atmel-ssc.c
6163 @@ -0,0 +1,174 @@
6164 +/*
6165 + * Atmel SSC driver
6166 + *
6167 + * Copyright (C) 2007 Atmel Corporation
6168 + *
6169 + * This program is free software; you can redistribute it and/or modify
6170 + * it under the terms of the GNU General Public License version 2 as
6171 + * published by the Free Software Foundation.
6172 + */
6173 +
6174 +#include <linux/platform_device.h>
6175 +#include <linux/list.h>
6176 +#include <linux/clk.h>
6177 +#include <linux/err.h>
6178 +#include <linux/io.h>
6179 +#include <linux/list.h>
6180 +#include <linux/spinlock.h>
6181 +#include <linux/atmel-ssc.h>
6182 +
6183 +/* Serialize access to ssc_list and user count */
6184 +static DEFINE_SPINLOCK(user_lock);
6185 +static LIST_HEAD(ssc_list);
6186 +
6187 +struct ssc_device *ssc_request(unsigned int ssc_num)
6188 +{
6189 + int ssc_valid = 0;
6190 + struct ssc_device *ssc;
6191 +
6192 + spin_lock(&user_lock);
6193 + list_for_each_entry(ssc, &ssc_list, list) {
6194 + if (ssc->pdev->id == ssc_num) {
6195 + ssc_valid = 1;
6196 + break;
6197 + }
6198 + }
6199 +
6200 + if (!ssc_valid) {
6201 + spin_unlock(&user_lock);
6202 + dev_dbg(&ssc->pdev->dev, "could not find requested device\n");
6203 + return ERR_PTR(-ENODEV);
6204 + }
6205 +
6206 + if (ssc->user) {
6207 + spin_unlock(&user_lock);
6208 + dev_dbg(&ssc->pdev->dev, "module busy\n");
6209 + return ERR_PTR(-EBUSY);
6210 + }
6211 + ssc->user++;
6212 + spin_unlock(&user_lock);
6213 +
6214 + clk_enable(ssc->clk);
6215 +
6216 + return ssc;
6217 +}
6218 +EXPORT_SYMBOL(ssc_request);
6219 +
6220 +void ssc_free(struct ssc_device *ssc)
6221 +{
6222 + spin_lock(&user_lock);
6223 + if (ssc->user) {
6224 + ssc->user--;
6225 + clk_disable(ssc->clk);
6226 + } else {
6227 + dev_dbg(&ssc->pdev->dev, "device already free\n");
6228 + }
6229 + spin_unlock(&user_lock);
6230 +}
6231 +EXPORT_SYMBOL(ssc_free);
6232 +
6233 +static int __init ssc_probe(struct platform_device *pdev)
6234 +{
6235 + int retval = 0;
6236 + struct resource *regs;
6237 + struct ssc_device *ssc;
6238 +
6239 + ssc = kzalloc(sizeof(struct ssc_device), GFP_KERNEL);
6240 + if (!ssc) {
6241 + dev_dbg(&pdev->dev, "out of memory\n");
6242 + retval = -ENOMEM;
6243 + goto out;
6244 + }
6245 +
6246 + regs = platform_get_resource(pdev, IORESOURCE_MEM, 0);
6247 + if (!regs) {
6248 + dev_dbg(&pdev->dev, "no mmio resource defined\n");
6249 + retval = -ENXIO;
6250 + goto out_free;
6251 + }
6252 +
6253 + ssc->clk = clk_get(&pdev->dev, "pclk");
6254 + if (IS_ERR(ssc->clk)) {
6255 + dev_dbg(&pdev->dev, "no pclk clock defined\n");
6256 + retval = -ENXIO;
6257 + goto out_free;
6258 + }
6259 +
6260 + ssc->pdev = pdev;
6261 + ssc->regs = ioremap(regs->start, regs->end - regs->start + 1);
6262 + if (!ssc->regs) {
6263 + dev_dbg(&pdev->dev, "ioremap failed\n");
6264 + retval = -EINVAL;
6265 + goto out_clk;
6266 + }
6267 +
6268 + /* disable all interrupts */
6269 + clk_enable(ssc->clk);
6270 + ssc_writel(ssc->regs, IDR, ~0UL);
6271 + ssc_readl(ssc->regs, SR);
6272 + clk_disable(ssc->clk);
6273 +
6274 + ssc->irq = platform_get_irq(pdev, 0);
6275 + if (!ssc->irq) {
6276 + dev_dbg(&pdev->dev, "could not get irq\n");
6277 + retval = -ENXIO;
6278 + goto out_unmap;
6279 + }
6280 +
6281 + spin_lock(&user_lock);
6282 + list_add_tail(&ssc->list, &ssc_list);
6283 + spin_unlock(&user_lock);
6284 +
6285 + platform_set_drvdata(pdev, ssc);
6286 +
6287 + dev_info(&pdev->dev, "Atmel SSC device at 0x%p (irq %d)\n",
6288 + ssc->regs, ssc->irq);
6289 +
6290 + goto out;
6291 +
6292 +out_unmap:
6293 + iounmap(ssc->regs);
6294 +out_clk:
6295 + clk_put(ssc->clk);
6296 +out_free:
6297 + kfree(ssc);
6298 +out:
6299 + return retval;
6300 +}
6301 +
6302 +static int __devexit ssc_remove(struct platform_device *pdev)
6303 +{
6304 + struct ssc_device *ssc = platform_get_drvdata(pdev);
6305 +
6306 + spin_lock(&user_lock);
6307 + iounmap(ssc->regs);
6308 + clk_put(ssc->clk);
6309 + list_del(&ssc->list);
6310 + kfree(ssc);
6311 + spin_unlock(&user_lock);
6312 +
6313 + return 0;
6314 +}
6315 +
6316 +static struct platform_driver ssc_driver = {
6317 + .remove = __devexit_p(ssc_remove),
6318 + .driver = {
6319 + .name = "ssc",
6320 + },
6321 +};
6322 +
6323 +static int __init ssc_init(void)
6324 +{
6325 + return platform_driver_probe(&ssc_driver, ssc_probe);
6326 +}
6327 +module_init(ssc_init);
6328 +
6329 +static void __exit ssc_exit(void)
6330 +{
6331 + platform_driver_unregister(&ssc_driver);
6332 +}
6333 +module_exit(ssc_exit);
6334 +
6335 +MODULE_AUTHOR("Hans-Christian Egtvedt <hcegtvedt@atmel.com>");
6336 +MODULE_DESCRIPTION("SSC driver for Atmel AVR32 and AT91");
6337 +MODULE_LICENSE("GPL");
6338 diff --git a/drivers/mmc/host/Kconfig b/drivers/mmc/host/Kconfig
6339 index e23082f..1de1716 100644
6340 --- a/drivers/mmc/host/Kconfig
6341 +++ b/drivers/mmc/host/Kconfig
6342 @@ -74,6 +74,16 @@ config MMC_AT91
6343
6344 If unsure, say N.
6345
6346 +config MMC_ATMELMCI
6347 + tristate "Atmel Multimedia Card Interface support"
6348 + depends on AVR32 && MMC
6349 + help
6350 + This selects the Atmel Multimedia Card Interface. If you have
6351 + a AT91 (ARM) or AT32 (AVR32) platform with a Multimedia Card
6352 + slot, say Y or M here.
6353 +
6354 + If unsure, say N.
6355 +
6356 config MMC_IMX
6357 tristate "Motorola i.MX Multimedia Card Interface support"
6358 depends on ARCH_IMX
6359 diff --git a/drivers/mmc/host/Makefile b/drivers/mmc/host/Makefile
6360 index 6685f64..4b8e6e2 100644
6361 --- a/drivers/mmc/host/Makefile
6362 +++ b/drivers/mmc/host/Makefile
6363 @@ -14,5 +14,6 @@ obj-$(CONFIG_MMC_WBSD) += wbsd.o
6364 obj-$(CONFIG_MMC_AU1X) += au1xmmc.o
6365 obj-$(CONFIG_MMC_OMAP) += omap.o
6366 obj-$(CONFIG_MMC_AT91) += at91_mci.o
6367 +obj-$(CONFIG_MMC_ATMELMCI) += atmel-mci.o
6368 obj-$(CONFIG_MMC_TIFM_SD) += tifm_sd.o
6369
6370 diff --git a/drivers/mmc/host/atmel-mci.c b/drivers/mmc/host/atmel-mci.c
6371 new file mode 100644
6372 index 0000000..74d343f
6373 --- /dev/null
6374 +++ b/drivers/mmc/host/atmel-mci.c
6375 @@ -0,0 +1,1217 @@
6376 +/*
6377 + * Atmel MultiMedia Card Interface driver
6378 + *
6379 + * Copyright (C) 2004-2006 Atmel Corporation
6380 + *
6381 + * This program is free software; you can redistribute it and/or modify
6382 + * it under the terms of the GNU General Public License version 2 as
6383 + * published by the Free Software Foundation.
6384 + */
6385 +#include <linux/blkdev.h>
6386 +#include <linux/clk.h>
6387 +#include <linux/device.h>
6388 +#include <linux/dma-mapping.h>
6389 +#include <linux/init.h>
6390 +#include <linux/interrupt.h>
6391 +#include <linux/ioport.h>
6392 +#include <linux/module.h>
6393 +#include <linux/platform_device.h>
6394 +
6395 +#include <linux/mmc/host.h>
6396 +
6397 +#include <asm/dma-controller.h>
6398 +#include <asm/io.h>
6399 +#include <asm/arch/board.h>
6400 +#include <asm/arch/gpio.h>
6401 +
6402 +#include "atmel-mci.h"
6403 +
6404 +#define DRIVER_NAME "atmel_mci"
6405 +
6406 +#define MCI_CMD_ERROR_FLAGS (MCI_BIT(RINDE) | MCI_BIT(RDIRE) | \
6407 + MCI_BIT(RCRCE) | MCI_BIT(RENDE) | \
6408 + MCI_BIT(RTOE))
6409 +#define MCI_DATA_ERROR_FLAGS (MCI_BIT(DCRCE) | MCI_BIT(DTOE) | \
6410 + MCI_BIT(OVRE) | MCI_BIT(UNRE))
6411 +
6412 +enum {
6413 + EVENT_CMD_COMPLETE = 0,
6414 + EVENT_CMD_ERROR,
6415 + EVENT_DATA_COMPLETE,
6416 + EVENT_DATA_ERROR,
6417 + EVENT_STOP_SENT,
6418 + EVENT_STOP_COMPLETE,
6419 + EVENT_STOP_ERROR,
6420 + EVENT_DMA_ERROR,
6421 + EVENT_CARD_DETECT,
6422 +};
6423 +
6424 +struct atmel_mci_dma {
6425 + struct dma_request_sg req;
6426 + unsigned short rx_periph_id;
6427 + unsigned short tx_periph_id;
6428 +};
6429 +
6430 +struct atmel_mci {
6431 + struct mmc_host *mmc;
6432 + void __iomem *regs;
6433 + struct atmel_mci_dma dma;
6434 +
6435 + struct mmc_request *mrq;
6436 + struct mmc_command *cmd;
6437 + struct mmc_data *data;
6438 +
6439 + u32 stop_cmdr;
6440 + u32 stop_iflags;
6441 +
6442 + struct tasklet_struct tasklet;
6443 + unsigned long pending_events;
6444 + unsigned long completed_events;
6445 + u32 error_status;
6446 +
6447 + int present;
6448 + int detect_pin;
6449 + int wp_pin;
6450 +
6451 + unsigned long bus_hz;
6452 + unsigned long mapbase;
6453 + struct clk *mck;
6454 + struct platform_device *pdev;
6455 +
6456 +#ifdef CONFIG_DEBUG_FS
6457 + struct dentry *debugfs_root;
6458 + struct dentry *debugfs_regs;
6459 + struct dentry *debugfs_req;
6460 + struct dentry *debugfs_pending_events;
6461 + struct dentry *debugfs_completed_events;
6462 +#endif
6463 +};
6464 +
6465 +/* Those printks take an awful lot of time... */
6466 +#ifndef DEBUG
6467 +static unsigned int fmax = 15000000U;
6468 +#else
6469 +static unsigned int fmax = 1000000U;
6470 +#endif
6471 +module_param(fmax, uint, 0444);
6472 +MODULE_PARM_DESC(fmax, "Max frequency in Hz of the MMC bus clock");
6473 +
6474 +/* Test bit macros for completed events */
6475 +#define mci_cmd_is_complete(host) \
6476 + test_bit(EVENT_CMD_COMPLETE, &host->completed_events)
6477 +#define mci_cmd_error_is_complete(host) \
6478 + test_bit(EVENT_CMD_ERROR, &host->completed_events)
6479 +#define mci_data_is_complete(host) \
6480 + test_bit(EVENT_DATA_COMPLETE, &host->completed_events)
6481 +#define mci_data_error_is_complete(host) \
6482 + test_bit(EVENT_DATA_ERROR, &host->completed_events)
6483 +#define mci_stop_sent_is_complete(host) \
6484 + test_bit(EVENT_STOP_SENT, &host->completed_events)
6485 +#define mci_stop_is_complete(host) \
6486 + test_bit(EVENT_STOP_COMPLETE, &host->completed_events)
6487 +#define mci_stop_error_is_complete(host) \
6488 + test_bit(EVENT_STOP_ERROR, &host->completed_events)
6489 +#define mci_dma_error_is_complete(host) \
6490 + test_bit(EVENT_DMA_ERROR, &host->completed_events)
6491 +#define mci_card_detect_is_complete(host) \
6492 + test_bit(EVENT_CARD_DETECT, &host->completed_events)
6493 +
6494 +/* Test and clear bit macros for pending events */
6495 +#define mci_clear_cmd_is_pending(host) \
6496 + test_and_clear_bit(EVENT_CMD_COMPLETE, &host->pending_events)
6497 +#define mci_clear_cmd_error_is_pending(host) \
6498 + test_and_clear_bit(EVENT_CMD_ERROR, &host->pending_events)
6499 +#define mci_clear_data_is_pending(host) \
6500 + test_and_clear_bit(EVENT_DATA_COMPLETE, &host->pending_events)
6501 +#define mci_clear_data_error_is_pending(host) \
6502 + test_and_clear_bit(EVENT_DATA_ERROR, &host->pending_events)
6503 +#define mci_clear_stop_sent_is_pending(host) \
6504 + test_and_clear_bit(EVENT_STOP_SENT, &host->pending_events)
6505 +#define mci_clear_stop_is_pending(host) \
6506 + test_and_clear_bit(EVENT_STOP_COMPLETE, &host->pending_events)
6507 +#define mci_clear_stop_error_is_pending(host) \
6508 + test_and_clear_bit(EVENT_STOP_ERROR, &host->pending_events)
6509 +#define mci_clear_dma_error_is_pending(host) \
6510 + test_and_clear_bit(EVENT_DMA_ERROR, &host->pending_events)
6511 +#define mci_clear_card_detect_is_pending(host) \
6512 + test_and_clear_bit(EVENT_CARD_DETECT, &host->pending_events)
6513 +
6514 +/* Test and set bit macros for completed events */
6515 +#define mci_set_cmd_is_completed(host) \
6516 + test_and_set_bit(EVENT_CMD_COMPLETE, &host->completed_events)
6517 +#define mci_set_cmd_error_is_completed(host) \
6518 + test_and_set_bit(EVENT_CMD_ERROR, &host->completed_events)
6519 +#define mci_set_data_is_completed(host) \
6520 + test_and_set_bit(EVENT_DATA_COMPLETE, &host->completed_events)
6521 +#define mci_set_data_error_is_completed(host) \
6522 + test_and_set_bit(EVENT_DATA_ERROR, &host->completed_events)
6523 +#define mci_set_stop_sent_is_completed(host) \
6524 + test_and_set_bit(EVENT_STOP_SENT, &host->completed_events)
6525 +#define mci_set_stop_is_completed(host) \
6526 + test_and_set_bit(EVENT_STOP_COMPLETE, &host->completed_events)
6527 +#define mci_set_stop_error_is_completed(host) \
6528 + test_and_set_bit(EVENT_STOP_ERROR, &host->completed_events)
6529 +#define mci_set_dma_error_is_completed(host) \
6530 + test_and_set_bit(EVENT_DMA_ERROR, &host->completed_events)
6531 +#define mci_set_card_detect_is_completed(host) \
6532 + test_and_set_bit(EVENT_CARD_DETECT, &host->completed_events)
6533 +
6534 +/* Set bit macros for completed events */
6535 +#define mci_set_cmd_complete(host) \
6536 + set_bit(EVENT_CMD_COMPLETE, &host->completed_events)
6537 +#define mci_set_cmd_error_complete(host) \
6538 + set_bit(EVENT_CMD_ERROR, &host->completed_events)
6539 +#define mci_set_data_complete(host) \
6540 + set_bit(EVENT_DATA_COMPLETE, &host->completed_events)
6541 +#define mci_set_data_error_complete(host) \
6542 + set_bit(EVENT_DATA_ERROR, &host->completed_events)
6543 +#define mci_set_stop_sent_complete(host) \
6544 + set_bit(EVENT_STOP_SENT, &host->completed_events)
6545 +#define mci_set_stop_complete(host) \
6546 + set_bit(EVENT_STOP_COMPLETE, &host->completed_events)
6547 +#define mci_set_stop_error_complete(host) \
6548 + set_bit(EVENT_STOP_ERROR, &host->completed_events)
6549 +#define mci_set_dma_error_complete(host) \
6550 + set_bit(EVENT_DMA_ERROR, &host->completed_events)
6551 +#define mci_set_card_detect_complete(host) \
6552 + set_bit(EVENT_CARD_DETECT, &host->completed_events)
6553 +
6554 +/* Set bit macros for pending events */
6555 +#define mci_set_cmd_pending(host) \
6556 + set_bit(EVENT_CMD_COMPLETE, &host->pending_events)
6557 +#define mci_set_cmd_error_pending(host) \
6558 + set_bit(EVENT_CMD_ERROR, &host->pending_events)
6559 +#define mci_set_data_pending(host) \
6560 + set_bit(EVENT_DATA_COMPLETE, &host->pending_events)
6561 +#define mci_set_data_error_pending(host) \
6562 + set_bit(EVENT_DATA_ERROR, &host->pending_events)
6563 +#define mci_set_stop_sent_pending(host) \
6564 + set_bit(EVENT_STOP_SENT, &host->pending_events)
6565 +#define mci_set_stop_pending(host) \
6566 + set_bit(EVENT_STOP_COMPLETE, &host->pending_events)
6567 +#define mci_set_stop_error_pending(host) \
6568 + set_bit(EVENT_STOP_ERROR, &host->pending_events)
6569 +#define mci_set_dma_error_pending(host) \
6570 + set_bit(EVENT_DMA_ERROR, &host->pending_events)
6571 +#define mci_set_card_detect_pending(host) \
6572 + set_bit(EVENT_CARD_DETECT, &host->pending_events)
6573 +
6574 +/* Clear bit macros for pending events */
6575 +#define mci_clear_cmd_pending(host) \
6576 + clear_bit(EVENT_CMD_COMPLETE, &host->pending_events)
6577 +#define mci_clear_cmd_error_pending(host) \
6578 + clear_bit(EVENT_CMD_ERROR, &host->pending_events)
6579 +#define mci_clear_data_pending(host) \
6580 + clear_bit(EVENT_DATA_COMPLETE, &host->pending_events)
6581 +#define mci_clear_data_error_pending(host) \
6582 + clear_bit(EVENT_DATA_ERROR, &host->pending_events)
6583 +#define mci_clear_stop_sent_pending(host) \
6584 + clear_bit(EVENT_STOP_SENT, &host->pending_events)
6585 +#define mci_clear_stop_pending(host) \
6586 + clear_bit(EVENT_STOP_COMPLETE, &host->pending_events)
6587 +#define mci_clear_stop_error_pending(host) \
6588 + clear_bit(EVENT_STOP_ERROR, &host->pending_events)
6589 +#define mci_clear_dma_error_pending(host) \
6590 + clear_bit(EVENT_DMA_ERROR, &host->pending_events)
6591 +#define mci_clear_card_detect_pending(host) \
6592 + clear_bit(EVENT_CARD_DETECT, &host->pending_events)
6593 +
6594 +
6595 +#ifdef CONFIG_DEBUG_FS
6596 +#include <linux/debugfs.h>
6597 +
6598 +#define DBG_REQ_BUF_SIZE (4096 - sizeof(unsigned int))
6599 +
6600 +struct req_dbg_data {
6601 + unsigned int nbytes;
6602 + char str[DBG_REQ_BUF_SIZE];
6603 +};
6604 +
6605 +static int req_dbg_open(struct inode *inode, struct file *file)
6606 +{
6607 + struct atmel_mci *host;
6608 + struct mmc_request *mrq;
6609 + struct mmc_command *cmd, *stop;
6610 + struct mmc_data *data;
6611 + struct req_dbg_data *priv;
6612 + char *str;
6613 + unsigned long n = 0;
6614 +
6615 + priv = kzalloc(DBG_REQ_BUF_SIZE, GFP_KERNEL);
6616 + if (!priv)
6617 + return -ENOMEM;
6618 + str = priv->str;
6619 +
6620 + mutex_lock(&inode->i_mutex);
6621 + host = inode->i_private;
6622 +
6623 + spin_lock_irq(&host->mmc->lock);
6624 + mrq = host->mrq;
6625 + if (mrq) {
6626 + cmd = mrq->cmd;
6627 + data = mrq->data;
6628 + stop = mrq->stop;
6629 + n = snprintf(str, DBG_REQ_BUF_SIZE,
6630 + "CMD%u(0x%x) %x %x %x %x %x (err %u)\n",
6631 + cmd->opcode, cmd->arg, cmd->flags,
6632 + cmd->resp[0], cmd->resp[1], cmd->resp[2],
6633 + cmd->resp[3], cmd->error);
6634 + if (n < DBG_REQ_BUF_SIZE && data)
6635 + n += snprintf(str + n, DBG_REQ_BUF_SIZE - n,
6636 + "DATA %u * %u (%u) %x (err %u)\n",
6637 + data->blocks, data->blksz,
6638 + data->bytes_xfered, data->flags,
6639 + data->error);
6640 + if (n < DBG_REQ_BUF_SIZE && stop)
6641 + n += snprintf(str + n, DBG_REQ_BUF_SIZE - n,
6642 + "CMD%u(0x%x) %x %x %x %x %x (err %u)\n",
6643 + stop->opcode, stop->arg, stop->flags,
6644 + stop->resp[0], stop->resp[1],
6645 + stop->resp[2], stop->resp[3],
6646 + stop->error);
6647 + }
6648 + spin_unlock_irq(&host->mmc->lock);
6649 + mutex_unlock(&inode->i_mutex);
6650 +
6651 + priv->nbytes = min(n, DBG_REQ_BUF_SIZE);
6652 + file->private_data = priv;
6653 +
6654 + return 0;
6655 +}
6656 +
6657 +static ssize_t req_dbg_read(struct file *file, char __user *buf,
6658 + size_t nbytes, loff_t *ppos)
6659 +{
6660 + struct req_dbg_data *priv = file->private_data;
6661 +
6662 + return simple_read_from_buffer(buf, nbytes, ppos,
6663 + priv->str, priv->nbytes);
6664 +}
6665 +
6666 +static int req_dbg_release(struct inode *inode, struct file *file)
6667 +{
6668 + kfree(file->private_data);
6669 + return 0;
6670 +}
6671 +
6672 +static const struct file_operations req_dbg_fops = {
6673 + .owner = THIS_MODULE,
6674 + .open = req_dbg_open,
6675 + .llseek = no_llseek,
6676 + .read = req_dbg_read,
6677 + .release = req_dbg_release,
6678 +};
6679 +
6680 +static int regs_dbg_open(struct inode *inode, struct file *file)
6681 +{
6682 + struct atmel_mci *host;
6683 + unsigned int i;
6684 + u32 *data;
6685 + int ret = -ENOMEM;
6686 +
6687 + mutex_lock(&inode->i_mutex);
6688 + host = inode->i_private;
6689 + data = kmalloc(inode->i_size, GFP_KERNEL);
6690 + if (!data)
6691 + goto out;
6692 +
6693 + spin_lock_irq(&host->mmc->lock);
6694 + for (i = 0; i < inode->i_size / 4; i++)
6695 + data[i] = __raw_readl(host->regs + i * 4);
6696 + spin_unlock_irq(&host->mmc->lock);
6697 +
6698 + file->private_data = data;
6699 + ret = 0;
6700 +
6701 +out:
6702 + mutex_unlock(&inode->i_mutex);
6703 +
6704 + return ret;
6705 +}
6706 +
6707 +static ssize_t regs_dbg_read(struct file *file, char __user *buf,
6708 + size_t nbytes, loff_t *ppos)
6709 +{
6710 + struct inode *inode = file->f_dentry->d_inode;
6711 + int ret;
6712 +
6713 + mutex_lock(&inode->i_mutex);
6714 + ret = simple_read_from_buffer(buf, nbytes, ppos,
6715 + file->private_data,
6716 + file->f_dentry->d_inode->i_size);
6717 + mutex_unlock(&inode->i_mutex);
6718 +
6719 + return ret;
6720 +}
6721 +
6722 +static int regs_dbg_release(struct inode *inode, struct file *file)
6723 +{
6724 + kfree(file->private_data);
6725 + return 0;
6726 +}
6727 +
6728 +static const struct file_operations regs_dbg_fops = {
6729 + .owner = THIS_MODULE,
6730 + .open = regs_dbg_open,
6731 + .llseek = generic_file_llseek,
6732 + .read = regs_dbg_read,
6733 + .release = regs_dbg_release,
6734 +};
6735 +
6736 +static void atmci_init_debugfs(struct atmel_mci *host)
6737 +{
6738 + struct mmc_host *mmc;
6739 + struct dentry *root, *regs;
6740 + struct resource *res;
6741 +
6742 + mmc = host->mmc;
6743 + root = debugfs_create_dir(mmc_hostname(mmc), NULL);
6744 + if (IS_ERR(root) || !root)
6745 + goto err_root;
6746 + host->debugfs_root = root;
6747 +
6748 + regs = debugfs_create_file("regs", 0400, root, host, &regs_dbg_fops);
6749 + if (!regs)
6750 + goto err_regs;
6751 +
6752 + res = platform_get_resource(host->pdev, IORESOURCE_MEM, 0);
6753 + regs->d_inode->i_size = res->end - res->start + 1;
6754 + host->debugfs_regs = regs;
6755 +
6756 + host->debugfs_req = debugfs_create_file("req", 0400, root,
6757 + host, &req_dbg_fops);
6758 + if (!host->debugfs_req)
6759 + goto err_req;
6760 +
6761 + host->debugfs_pending_events
6762 + = debugfs_create_u32("pending_events", 0400, root,
6763 + (u32 *)&host->pending_events);
6764 + if (!host->debugfs_pending_events)
6765 + goto err_pending_events;
6766 +
6767 + host->debugfs_completed_events
6768 + = debugfs_create_u32("completed_events", 0400, root,
6769 + (u32 *)&host->completed_events);
6770 + if (!host->debugfs_completed_events)
6771 + goto err_completed_events;
6772 +
6773 + return;
6774 +
6775 +err_completed_events:
6776 + debugfs_remove(host->debugfs_pending_events);
6777 +err_pending_events:
6778 + debugfs_remove(host->debugfs_req);
6779 +err_req:
6780 + debugfs_remove(host->debugfs_regs);
6781 +err_regs:
6782 + debugfs_remove(host->debugfs_root);
6783 +err_root:
6784 + host->debugfs_root = NULL;
6785 + dev_err(&host->pdev->dev,
6786 + "failed to initialize debugfs for %s\n",
6787 + mmc_hostname(mmc));
6788 +}
6789 +
6790 +static void atmci_cleanup_debugfs(struct atmel_mci *host)
6791 +{
6792 + if (host->debugfs_root) {
6793 + debugfs_remove(host->debugfs_completed_events);
6794 + debugfs_remove(host->debugfs_pending_events);
6795 + debugfs_remove(host->debugfs_req);
6796 + debugfs_remove(host->debugfs_regs);
6797 + debugfs_remove(host->debugfs_root);
6798 + host->debugfs_root = NULL;
6799 + }
6800 +}
6801 +#else
6802 +static inline void atmci_init_debugfs(struct atmel_mci *host)
6803 +{
6804 +
6805 +}
6806 +
6807 +static inline void atmci_cleanup_debugfs(struct atmel_mci *host)
6808 +{
6809 +
6810 +}
6811 +#endif /* CONFIG_DEBUG_FS */
6812 +
6813 +static inline unsigned int ns_to_clocks(struct atmel_mci *host,
6814 + unsigned int ns)
6815 +{
6816 + return (ns * (host->bus_hz / 1000000) + 999) / 1000;
6817 +}
6818 +
6819 +static void atmci_set_timeout(struct atmel_mci *host,
6820 + struct mmc_data *data)
6821 +{
6822 + static unsigned dtomul_to_shift[] = {
6823 + 0, 4, 7, 8, 10, 12, 16, 20
6824 + };
6825 + unsigned timeout;
6826 + unsigned dtocyc, dtomul;
6827 +
6828 + timeout = ns_to_clocks(host, data->timeout_ns) + data->timeout_clks;
6829 +
6830 + for (dtomul = 0; dtomul < 8; dtomul++) {
6831 + unsigned shift = dtomul_to_shift[dtomul];
6832 + dtocyc = (timeout + (1 << shift) - 1) >> shift;
6833 + if (dtocyc < 15)
6834 + break;
6835 + }
6836 +
6837 + if (dtomul >= 8) {
6838 + dtomul = 7;
6839 + dtocyc = 15;
6840 + }
6841 +
6842 + pr_debug("%s: setting timeout to %u cycles\n",
6843 + mmc_hostname(host->mmc),
6844 + dtocyc << dtomul_to_shift[dtomul]);
6845 + mci_writel(host, DTOR, (MCI_BF(DTOMUL, dtomul)
6846 + | MCI_BF(DTOCYC, dtocyc)));
6847 +}
6848 +
6849 +/*
6850 + * Return mask with interrupt flags to be handled for this command.
6851 + */
6852 +static u32 atmci_prepare_command(struct mmc_host *mmc,
6853 + struct mmc_command *cmd,
6854 + u32 *cmd_flags)
6855 +{
6856 + u32 cmdr;
6857 + u32 iflags;
6858 +
6859 + cmd->error = MMC_ERR_NONE;
6860 +
6861 + cmdr = 0;
6862 + BUG_ON(MCI_BFEXT(CMDNB, cmdr) != 0);
6863 + cmdr = MCI_BFINS(CMDNB, cmd->opcode, cmdr);
6864 +
6865 + if (cmd->flags & MMC_RSP_PRESENT) {
6866 + if (cmd->flags & MMC_RSP_136)
6867 + cmdr |= MCI_BF(RSPTYP, MCI_RSPTYP_136_BIT);
6868 + else
6869 + cmdr |= MCI_BF(RSPTYP, MCI_RSPTYP_48_BIT);
6870 + }
6871 +
6872 + /*
6873 + * This should really be MAXLAT_5 for CMD2 and ACMD41, but
6874 + * it's too difficult to determine whether this is an ACMD or
6875 + * not. Better make it 64.
6876 + */
6877 + cmdr |= MCI_BIT(MAXLAT);
6878 +
6879 + if (mmc->ios.bus_mode == MMC_BUSMODE_OPENDRAIN)
6880 + cmdr |= MCI_BIT(OPDCMD);
6881 +
6882 + iflags = MCI_BIT(CMDRDY) | MCI_CMD_ERROR_FLAGS;
6883 + if (!(cmd->flags & MMC_RSP_CRC))
6884 + iflags &= ~MCI_BIT(RCRCE);
6885 +
6886 + pr_debug("%s: cmd: op %02x arg %08x flags %08x, cmdflags %08lx\n",
6887 + mmc_hostname(mmc), cmd->opcode, cmd->arg, cmd->flags,
6888 + (unsigned long)cmdr);
6889 +
6890 + *cmd_flags = cmdr;
6891 + return iflags;
6892 +}
6893 +
6894 +static void atmci_start_command(struct atmel_mci *host,
6895 + struct mmc_command *cmd,
6896 + u32 cmd_flags)
6897 +{
6898 + WARN_ON(host->cmd);
6899 + host->cmd = cmd;
6900 +
6901 + mci_writel(host, ARGR, cmd->arg);
6902 + mci_writel(host, CMDR, cmd_flags);
6903 +
6904 + if (cmd->data)
6905 + dma_start_request(host->dma.req.req.dmac,
6906 + host->dma.req.req.channel);
6907 +}
6908 +
6909 +/*
6910 + * Returns a mask of flags to be set in the command register when the
6911 + * command to start the transfer is to be sent.
6912 + */
6913 +static u32 atmci_prepare_data(struct mmc_host *mmc, struct mmc_data *data)
6914 +{
6915 + struct atmel_mci *host = mmc_priv(mmc);
6916 + u32 cmd_flags;
6917 +
6918 + WARN_ON(host->data);
6919 + host->data = data;
6920 +
6921 + atmci_set_timeout(host, data);
6922 + mci_writel(host, BLKR, (MCI_BF(BCNT, data->blocks)
6923 + | MCI_BF(BLKLEN, data->blksz)));
6924 + host->dma.req.block_size = data->blksz;
6925 + host->dma.req.nr_blocks = data->blocks;
6926 +
6927 + cmd_flags = MCI_BF(TRCMD, MCI_TRCMD_START_TRANS);
6928 + if (data->flags & MMC_DATA_STREAM)
6929 + cmd_flags |= MCI_BF(TRTYP, MCI_TRTYP_STREAM);
6930 + else if (data->blocks > 1)
6931 + cmd_flags |= MCI_BF(TRTYP, MCI_TRTYP_MULTI_BLOCK);
6932 + else
6933 + cmd_flags |= MCI_BF(TRTYP, MCI_TRTYP_BLOCK);
6934 +
6935 + if (data->flags & MMC_DATA_READ) {
6936 + cmd_flags |= MCI_BIT(TRDIR);
6937 + host->dma.req.nr_sg
6938 + = dma_map_sg(&host->pdev->dev, data->sg,
6939 + data->sg_len, DMA_FROM_DEVICE);
6940 + host->dma.req.periph_id = host->dma.rx_periph_id;
6941 + host->dma.req.direction = DMA_DIR_PERIPH_TO_MEM;
6942 + host->dma.req.data_reg = host->mapbase + MCI_RDR;
6943 + } else {
6944 + host->dma.req.nr_sg
6945 + = dma_map_sg(&host->pdev->dev, data->sg,
6946 + data->sg_len, DMA_TO_DEVICE);
6947 + host->dma.req.periph_id = host->dma.tx_periph_id;
6948 + host->dma.req.direction = DMA_DIR_MEM_TO_PERIPH;
6949 + host->dma.req.data_reg = host->mapbase + MCI_TDR;
6950 + }
6951 + host->dma.req.sg = data->sg;
6952 +
6953 + dma_prepare_request_sg(host->dma.req.req.dmac, &host->dma.req);
6954 +
6955 + return cmd_flags;
6956 +}
6957 +
6958 +static void atmci_request(struct mmc_host *mmc, struct mmc_request *mrq)
6959 +{
6960 + struct atmel_mci *host = mmc_priv(mmc);
6961 + struct mmc_data *data = mrq->data;
6962 + u32 iflags;
6963 + u32 cmdflags = 0;
6964 +
6965 + iflags = mci_readl(host, IMR);
6966 + if (iflags)
6967 + printk("WARNING: IMR=0x%08x\n", mci_readl(host, IMR));
6968 +
6969 + WARN_ON(host->mrq != NULL);
6970 + host->mrq = mrq;
6971 + host->pending_events = 0;
6972 + host->completed_events = 0;
6973 +
6974 + iflags = atmci_prepare_command(mmc, mrq->cmd, &cmdflags);
6975 +
6976 + if (mrq->stop) {
6977 + BUG_ON(!data);
6978 +
6979 + host->stop_iflags = atmci_prepare_command(mmc, mrq->stop,
6980 + &host->stop_cmdr);
6981 + host->stop_cmdr |= MCI_BF(TRCMD, MCI_TRCMD_STOP_TRANS);
6982 + if (!(data->flags & MMC_DATA_WRITE))
6983 + host->stop_cmdr |= MCI_BIT(TRDIR);
6984 + if (data->flags & MMC_DATA_STREAM)
6985 + host->stop_cmdr |= MCI_BF(TRTYP, MCI_TRTYP_STREAM);
6986 + else
6987 + host->stop_cmdr |= MCI_BF(TRTYP, MCI_TRTYP_MULTI_BLOCK);
6988 + }
6989 + if (data) {
6990 + cmdflags |= atmci_prepare_data(mmc, data);
6991 + iflags |= MCI_DATA_ERROR_FLAGS;
6992 + }
6993 +
6994 + atmci_start_command(host, mrq->cmd, cmdflags);
6995 + mci_writel(host, IER, iflags);
6996 +}
6997 +
6998 +static void atmci_set_ios(struct mmc_host *mmc, struct mmc_ios *ios)
6999 +{
7000 + struct atmel_mci *host = mmc_priv(mmc);
7001 +
7002 + if (ios->clock) {
7003 + u32 clkdiv;
7004 +
7005 + clkdiv = host->bus_hz / (2 * ios->clock) - 1;
7006 + if (clkdiv > 255)
7007 + clkdiv = 255;
7008 + mci_writel(host, MR, (clkdiv
7009 + | MCI_BIT(WRPROOF)
7010 + | MCI_BIT(RDPROOF)));
7011 + }
7012 +
7013 + switch (ios->bus_width) {
7014 + case MMC_BUS_WIDTH_1:
7015 + mci_writel(host, SDCR, 0);
7016 + break;
7017 + case MMC_BUS_WIDTH_4:
7018 + mci_writel(host, SDCR, MCI_BIT(SDCBUS));
7019 + break;
7020 + }
7021 +
7022 + switch (ios->power_mode) {
7023 + case MMC_POWER_OFF:
7024 + mci_writel(host, CR, MCI_BIT(MCIDIS));
7025 + break;
7026 + case MMC_POWER_UP:
7027 + mci_writel(host, CR, MCI_BIT(SWRST));
7028 + break;
7029 + case MMC_POWER_ON:
7030 + mci_writel(host, CR, MCI_BIT(MCIEN));
7031 + break;
7032 + }
7033 +}
7034 +
7035 +static int atmci_get_ro(struct mmc_host *mmc)
7036 +{
7037 + int read_only = 0;
7038 + struct atmel_mci *host = mmc_priv(mmc);
7039 +
7040 + if (host->wp_pin >= 0) {
7041 + read_only = gpio_get_value(host->wp_pin);
7042 + pr_debug("%s: card is %s\n", mmc_hostname(mmc),
7043 + read_only ? "read-only" : "read-write");
7044 + } else {
7045 + pr_debug("%s: no pin for checking read-only switch."
7046 + " Assuming write-enable.\n", mmc_hostname(mmc));
7047 + }
7048 +
7049 + return read_only;
7050 +}
7051 +
7052 +static struct mmc_host_ops atmci_ops = {
7053 + .request = atmci_request,
7054 + .set_ios = atmci_set_ios,
7055 + .get_ro = atmci_get_ro,
7056 +};
7057 +
7058 +static void atmci_request_end(struct mmc_host *mmc, struct mmc_request *mrq)
7059 +{
7060 + struct atmel_mci *host = mmc_priv(mmc);
7061 +
7062 + WARN_ON(host->cmd || host->data);
7063 + host->mrq = NULL;
7064 +
7065 + mmc_request_done(mmc, mrq);
7066 +}
7067 +
7068 +static void send_stop_cmd(struct mmc_host *mmc, struct mmc_data *data,
7069 + u32 flags)
7070 +{
7071 + struct atmel_mci *host = mmc_priv(mmc);
7072 +
7073 + atmci_start_command(host, data->stop, host->stop_cmdr | flags);
7074 + mci_writel(host, IER, host->stop_iflags);
7075 +}
7076 +
7077 +static void atmci_data_complete(struct atmel_mci *host, struct mmc_data *data)
7078 +{
7079 + host->data = NULL;
7080 + dma_unmap_sg(&host->pdev->dev, data->sg, host->dma.req.nr_sg,
7081 + ((data->flags & MMC_DATA_WRITE)
7082 + ? DMA_TO_DEVICE : DMA_FROM_DEVICE));
7083 +
7084 + /*
7085 + * Data might complete before command for very short transfers
7086 + * (like READ_SCR)
7087 + */
7088 + if (mci_cmd_is_complete(host)
7089 + && (!data->stop || mci_stop_is_complete(host)))
7090 + atmci_request_end(host->mmc, data->mrq);
7091 +}
7092 +
7093 +static void atmci_command_error(struct mmc_host *mmc,
7094 + struct mmc_command *cmd,
7095 + u32 status)
7096 +{
7097 + pr_debug("%s: command error: status=0x%08x\n",
7098 + mmc_hostname(mmc), status);
7099 +
7100 + if (status & MCI_BIT(RTOE))
7101 + cmd->error = MMC_ERR_TIMEOUT;
7102 + else if (status & MCI_BIT(RCRCE))
7103 + cmd->error = MMC_ERR_BADCRC;
7104 + else
7105 + cmd->error = MMC_ERR_FAILED;
7106 +}
7107 +
7108 +static void atmci_tasklet_func(unsigned long priv)
7109 +{
7110 + struct mmc_host *mmc = (struct mmc_host *)priv;
7111 + struct atmel_mci *host = mmc_priv(mmc);
7112 + struct mmc_request *mrq = host->mrq;
7113 + struct mmc_data *data = host->data;
7114 +
7115 + pr_debug("atmci_tasklet: pending/completed/mask %lx/%lx/%x\n",
7116 + host->pending_events, host->completed_events,
7117 + mci_readl(host, IMR));
7118 +
7119 + if (mci_clear_cmd_error_is_pending(host)) {
7120 + struct mmc_command *cmd;
7121 +
7122 + mci_set_cmd_error_complete(host);
7123 + mci_clear_cmd_pending(host);
7124 + cmd = host->mrq->cmd;
7125 +
7126 + if (cmd->data) {
7127 + dma_stop_request(host->dma.req.req.dmac,
7128 + host->dma.req.req.channel);
7129 + host->data = NULL;
7130 + }
7131 +
7132 + atmci_command_error(mmc, cmd, host->error_status);
7133 + atmci_request_end(mmc, cmd->mrq);
7134 + }
7135 + if (mci_clear_stop_error_is_pending(host)) {
7136 + mci_set_stop_error_complete(host);
7137 + mci_clear_stop_pending(host);
7138 + atmci_command_error(mmc, host->mrq->stop,
7139 + host->error_status);
7140 + if (!host->data)
7141 + atmci_request_end(mmc, host->mrq);
7142 + }
7143 + if (mci_clear_cmd_is_pending(host)) {
7144 + mci_set_cmd_complete(host);
7145 + if (!mrq->data || mci_data_is_complete(host)
7146 + || mci_data_error_is_complete(host))
7147 + atmci_request_end(mmc, mrq);
7148 + }
7149 + if (mci_clear_stop_is_pending(host)) {
7150 + mci_set_stop_complete(host);
7151 + if (mci_data_is_complete(host)
7152 + || mci_data_error_is_complete(host))
7153 + atmci_request_end(mmc, mrq);
7154 + }
7155 + if (mci_clear_dma_error_is_pending(host)) {
7156 + mci_set_dma_error_complete(host);
7157 + mci_clear_data_pending(host);
7158 +
7159 + /* DMA controller got bus error => invalid address */
7160 + data->error = MMC_ERR_INVALID;
7161 +
7162 + printk(KERN_DEBUG "%s: dma error after %u bytes xfered\n",
7163 + mmc_hostname(mmc), host->data->bytes_xfered);
7164 +
7165 + if (data->stop
7166 + && !mci_set_stop_sent_is_completed(host))
7167 + /* TODO: Check if card is still present */
7168 + send_stop_cmd(host->mmc, data, 0);
7169 +
7170 + atmci_data_complete(host, data);
7171 + }
7172 + if (mci_clear_data_error_is_pending(host)) {
7173 + u32 status = host->error_status;
7174 +
7175 + mci_set_data_error_complete(host);
7176 + mci_clear_data_pending(host);
7177 +
7178 + dma_stop_request(host->dma.req.req.dmac,
7179 + host->dma.req.req.channel);
7180 +
7181 + printk(KERN_DEBUG "%s: data error: status=0x%08x\n",
7182 + mmc_hostname(host->mmc), status);
7183 +
7184 + if (status & MCI_BIT(DCRCE)) {
7185 + printk(KERN_DEBUG "%s: Data CRC error\n",
7186 + mmc_hostname(host->mmc));
7187 + data->error = MMC_ERR_BADCRC;
7188 + } else if (status & MCI_BIT(DTOE)) {
7189 + printk(KERN_DEBUG "%s: Data Timeout error\n",
7190 + mmc_hostname(host->mmc));
7191 + data->error = MMC_ERR_TIMEOUT;
7192 + } else {
7193 + printk(KERN_DEBUG "%s: Data FIFO error\n",
7194 + mmc_hostname(host->mmc));
7195 + data->error = MMC_ERR_FIFO;
7196 + }
7197 + printk(KERN_DEBUG "%s: Bytes xfered: %u\n",
7198 + mmc_hostname(host->mmc), data->bytes_xfered);
7199 +
7200 + if (data->stop
7201 + && !mci_set_stop_sent_is_completed(host))
7202 + /* TODO: Check if card is still present */
7203 + send_stop_cmd(host->mmc, data, 0);
7204 +
7205 + atmci_data_complete(host, data);
7206 + }
7207 + if (mci_clear_data_is_pending(host)) {
7208 + mci_set_data_complete(host);
7209 + data->bytes_xfered = data->blocks * data->blksz;
7210 + atmci_data_complete(host, data);
7211 + }
7212 + if (mci_clear_card_detect_is_pending(host)) {
7213 + /* Reset controller if card is gone */
7214 + if (!host->present) {
7215 + mci_writel(host, CR, MCI_BIT(SWRST));
7216 + mci_writel(host, IDR, ~0UL);
7217 + mci_writel(host, CR, MCI_BIT(MCIEN));
7218 + }
7219 +
7220 + /* Clean up queue if present */
7221 + if (mrq) {
7222 + if (!mci_cmd_is_complete(host)
7223 + && !mci_cmd_error_is_complete(host)) {
7224 + mrq->cmd->error = MMC_ERR_TIMEOUT;
7225 + }
7226 + if (mrq->data && !mci_data_is_complete(host)
7227 + && !mci_data_error_is_complete(host)) {
7228 + dma_stop_request(host->dma.req.req.dmac,
7229 + host->dma.req.req.channel);
7230 + host->data->error = MMC_ERR_TIMEOUT;
7231 + atmci_data_complete(host, data);
7232 + }
7233 + if (mrq->stop && !mci_stop_is_complete(host)
7234 + && !mci_stop_error_is_complete(host)) {
7235 + mrq->stop->error = MMC_ERR_TIMEOUT;
7236 + }
7237 +
7238 + host->cmd = NULL;
7239 + atmci_request_end(mmc, mrq);
7240 + }
7241 + mmc_detect_change(host->mmc, msecs_to_jiffies(100));
7242 + }
7243 +}
7244 +
7245 +static void atmci_cmd_interrupt(struct mmc_host *mmc, u32 status)
7246 +{
7247 + struct atmel_mci *host = mmc_priv(mmc);
7248 + struct mmc_command *cmd = host->cmd;
7249 +
7250 + /*
7251 + * Read the response now so that we're free to send a new
7252 + * command immediately.
7253 + */
7254 + cmd->resp[0] = mci_readl(host, RSPR);
7255 + cmd->resp[1] = mci_readl(host, RSPR);
7256 + cmd->resp[2] = mci_readl(host, RSPR);
7257 + cmd->resp[3] = mci_readl(host, RSPR);
7258 +
7259 + mci_writel(host, IDR, MCI_BIT(CMDRDY) | MCI_CMD_ERROR_FLAGS);
7260 + host->cmd = NULL;
7261 +
7262 + if (mci_stop_sent_is_complete(host))
7263 + mci_set_stop_pending(host);
7264 + else
7265 + mci_set_cmd_pending(host);
7266 +
7267 + tasklet_schedule(&host->tasklet);
7268 +}
7269 +
7270 +static void atmci_xfer_complete(struct dma_request *_req)
7271 +{
7272 + struct dma_request_sg *req = to_dma_request_sg(_req);
7273 + struct atmel_mci_dma *dma;
7274 + struct atmel_mci *host;
7275 + struct mmc_data *data;
7276 +
7277 + dma = container_of(req, struct atmel_mci_dma, req);
7278 + host = container_of(dma, struct atmel_mci, dma);
7279 + data = host->data;
7280 +
7281 + if (data->stop && !mci_set_stop_sent_is_completed(host))
7282 + send_stop_cmd(host->mmc, data, 0);
7283 +
7284 + if (data->flags & MMC_DATA_READ) {
7285 + mci_writel(host, IDR, MCI_DATA_ERROR_FLAGS);
7286 + mci_set_data_pending(host);
7287 + tasklet_schedule(&host->tasklet);
7288 + } else {
7289 + /*
7290 + * For the WRITE case, wait for NOTBUSY. This function
7291 + * is called when everything has been written to the
7292 + * controller, not when the card is done programming.
7293 + */
7294 + mci_writel(host, IER, MCI_BIT(NOTBUSY));
7295 + }
7296 +}
7297 +
7298 +static void atmci_dma_error(struct dma_request *_req)
7299 +{
7300 + struct dma_request_sg *req = to_dma_request_sg(_req);
7301 + struct atmel_mci_dma *dma;
7302 + struct atmel_mci *host;
7303 +
7304 + dma = container_of(req, struct atmel_mci_dma, req);
7305 + host = container_of(dma, struct atmel_mci, dma);
7306 +
7307 + mci_writel(host, IDR, (MCI_BIT(NOTBUSY)
7308 + | MCI_DATA_ERROR_FLAGS));
7309 +
7310 + mci_set_dma_error_pending(host);
7311 + tasklet_schedule(&host->tasklet);
7312 +}
7313 +
7314 +static irqreturn_t atmci_interrupt(int irq, void *dev_id)
7315 +{
7316 + struct mmc_host *mmc = dev_id;
7317 + struct atmel_mci *host = mmc_priv(mmc);
7318 + u32 status, mask, pending;
7319 +
7320 + spin_lock(&mmc->lock);
7321 +
7322 + status = mci_readl(host, SR);
7323 + mask = mci_readl(host, IMR);
7324 + pending = status & mask;
7325 +
7326 + do {
7327 + if (pending & MCI_CMD_ERROR_FLAGS) {
7328 + mci_writel(host, IDR, (MCI_BIT(CMDRDY)
7329 + | MCI_BIT(NOTBUSY)
7330 + | MCI_CMD_ERROR_FLAGS
7331 + | MCI_DATA_ERROR_FLAGS));
7332 + host->error_status = status;
7333 + host->cmd = NULL;
7334 + if (mci_stop_sent_is_complete(host))
7335 + mci_set_stop_error_pending(host);
7336 + else
7337 + mci_set_cmd_error_pending(host);
7338 + tasklet_schedule(&host->tasklet);
7339 + break;
7340 + }
7341 + if (pending & MCI_DATA_ERROR_FLAGS) {
7342 + mci_writel(host, IDR, (MCI_BIT(NOTBUSY)
7343 + | MCI_DATA_ERROR_FLAGS));
7344 + host->error_status = status;
7345 + mci_set_data_error_pending(host);
7346 + tasklet_schedule(&host->tasklet);
7347 + break;
7348 + }
7349 + if (pending & MCI_BIT(CMDRDY))
7350 + atmci_cmd_interrupt(mmc, status);
7351 + if (pending & MCI_BIT(NOTBUSY)) {
7352 + mci_writel(host, IDR, (MCI_BIT(NOTBUSY)
7353 + | MCI_DATA_ERROR_FLAGS));
7354 + mci_set_data_pending(host);
7355 + tasklet_schedule(&host->tasklet);
7356 + }
7357 +
7358 + status = mci_readl(host, SR);
7359 + mask = mci_readl(host, IMR);
7360 + pending = status & mask;
7361 + } while (pending);
7362 +
7363 + spin_unlock(&mmc->lock);
7364 +
7365 + return IRQ_HANDLED;
7366 +}
7367 +
7368 +static irqreturn_t atmci_detect_change(int irq, void *dev_id)
7369 +{
7370 + struct mmc_host *mmc = dev_id;
7371 + struct atmel_mci *host = mmc_priv(mmc);
7372 +
7373 + int present = !gpio_get_value(irq_to_gpio(irq));
7374 +
7375 + if (present != host->present) {
7376 + pr_debug("%s: card %s\n", mmc_hostname(host->mmc),
7377 + present ? "inserted" : "removed");
7378 + host->present = present;
7379 + mci_set_card_detect_pending(host);
7380 + tasklet_schedule(&host->tasklet);
7381 + }
7382 + return IRQ_HANDLED;
7383 +}
7384 +
7385 +static int __devinit atmci_probe(struct platform_device *pdev)
7386 +{
7387 + struct mci_platform_data *board;
7388 + struct atmel_mci *host;
7389 + struct mmc_host *mmc;
7390 + struct resource *regs;
7391 + int irq;
7392 + int ret;
7393 +
7394 + regs = platform_get_resource(pdev, IORESOURCE_MEM, 0);
7395 + if (!regs)
7396 + return -ENXIO;
7397 + irq = platform_get_irq(pdev, 0);
7398 + if (irq < 0)
7399 + return irq;
7400 +
7401 + board = pdev->dev.platform_data;
7402 +
7403 + mmc = mmc_alloc_host(sizeof(struct atmel_mci), &pdev->dev);
7404 + if (!mmc)
7405 + return -ENOMEM;
7406 +
7407 + host = mmc_priv(mmc);
7408 + host->pdev = pdev;
7409 + host->mmc = mmc;
7410 + if (board) {
7411 + host->detect_pin = board->detect_pin;
7412 + host->wp_pin = board->wp_pin;
7413 + } else {
7414 + host->detect_pin = -1;
7415 + host->detect_pin = -1;
7416 + }
7417 +
7418 + host->mck = clk_get(&pdev->dev, "mci_clk");
7419 + if (IS_ERR(host->mck)) {
7420 + ret = PTR_ERR(host->mck);
7421 + goto out_free_host;
7422 + }
7423 + clk_enable(host->mck);
7424 +
7425 + ret = -ENOMEM;
7426 + host->regs = ioremap(regs->start, regs->end - regs->start + 1);
7427 + if (!host->regs)
7428 + goto out_disable_clk;
7429 +
7430 + host->bus_hz = clk_get_rate(host->mck);
7431 + host->mapbase = regs->start;
7432 +
7433 + mmc->ops = &atmci_ops;
7434 + mmc->f_min = (host->bus_hz + 511) / 512;
7435 + mmc->f_max = min((unsigned int)(host->bus_hz / 2), fmax);
7436 + mmc->ocr_avail = 0x00100000;
7437 + mmc->caps |= MMC_CAP_4_BIT_DATA;
7438 +
7439 + tasklet_init(&host->tasklet, atmci_tasklet_func, (unsigned long)mmc);
7440 +
7441 + ret = request_irq(irq, atmci_interrupt, 0, "mmci", mmc);
7442 + if (ret)
7443 + goto out_unmap;
7444 +
7445 + /* Assume card is present if we don't have a detect pin */
7446 + host->present = 1;
7447 + if (host->detect_pin >= 0) {
7448 + if (gpio_request(host->detect_pin, "mmc_detect")) {
7449 + printk(KERN_WARNING "%s: no detect pin available\n",
7450 + mmc_hostname(host->mmc));
7451 + host->detect_pin = -1;
7452 + } else {
7453 + host->present = !gpio_get_value(host->detect_pin);
7454 + }
7455 + }
7456 + if (host->wp_pin >= 0) {
7457 + if (gpio_request(host->wp_pin, "mmc_wp")) {
7458 + printk(KERN_WARNING "%s: no WP pin available\n",
7459 + mmc_hostname(host->mmc));
7460 + host->wp_pin = -1;
7461 + }
7462 + }
7463 +
7464 + /* TODO: Get this information from platform data */
7465 + ret = -ENOMEM;
7466 + host->dma.req.req.dmac = find_dma_controller(0);
7467 + if (!host->dma.req.req.dmac) {
7468 + printk(KERN_ERR
7469 + "mmci: No DMA controller available, aborting\n");
7470 + goto out_free_irq;
7471 + }
7472 + ret = dma_alloc_channel(host->dma.req.req.dmac);
7473 + if (ret < 0) {
7474 + printk(KERN_ERR
7475 + "mmci: Unable to allocate DMA channel, aborting\n");
7476 + goto out_free_irq;
7477 + }
7478 + host->dma.req.req.channel = ret;
7479 + host->dma.req.width = DMA_WIDTH_32BIT;
7480 + host->dma.req.req.xfer_complete = atmci_xfer_complete;
7481 + host->dma.req.req.block_complete = NULL; // atmci_block_complete;
7482 + host->dma.req.req.error = atmci_dma_error;
7483 + host->dma.rx_periph_id = 0;
7484 + host->dma.tx_periph_id = 1;
7485 +
7486 + mci_writel(host, CR, MCI_BIT(SWRST));
7487 + mci_writel(host, IDR, ~0UL);
7488 + mci_writel(host, CR, MCI_BIT(MCIEN));
7489 +
7490 + platform_set_drvdata(pdev, host);
7491 +
7492 + mmc_add_host(mmc);
7493 +
7494 + if (host->detect_pin >= 0) {
7495 + ret = request_irq(gpio_to_irq(host->detect_pin),
7496 + atmci_detect_change,
7497 + IRQF_TRIGGER_FALLING | IRQF_TRIGGER_RISING,
7498 + DRIVER_NAME, mmc);
7499 + if (ret) {
7500 + printk(KERN_ERR
7501 + "%s: could not request IRQ %d for detect pin\n",
7502 + mmc_hostname(mmc),
7503 + gpio_to_irq(host->detect_pin));
7504 + gpio_free(host->detect_pin);
7505 + host->detect_pin = -1;
7506 + }
7507 + }
7508 +
7509 + printk(KERN_INFO "%s: Atmel MCI controller at 0x%08lx irq %d\n",
7510 + mmc_hostname(mmc), host->mapbase, irq);
7511 +
7512 + atmci_init_debugfs(host);
7513 +
7514 + return 0;
7515 +
7516 +out_free_irq:
7517 + if (host->detect_pin >= 0)
7518 + gpio_free(host->detect_pin);
7519 + if (host->wp_pin >= 0)
7520 + gpio_free(host->wp_pin);
7521 + free_irq(irq, mmc);
7522 +out_unmap:
7523 + iounmap(host->regs);
7524 +out_disable_clk:
7525 + clk_disable(host->mck);
7526 + clk_put(host->mck);
7527 +out_free_host:
7528 + mmc_free_host(mmc);
7529 + return ret;
7530 +}
7531 +
7532 +static int __devexit atmci_remove(struct platform_device *pdev)
7533 +{
7534 + struct atmel_mci *host = platform_get_drvdata(pdev);
7535 +
7536 + platform_set_drvdata(pdev, NULL);
7537 +
7538 + if (host) {
7539 + atmci_cleanup_debugfs(host);
7540 +
7541 + if (host->detect_pin >= 0) {
7542 + free_irq(gpio_to_irq(host->detect_pin), host->mmc);
7543 + cancel_delayed_work(&host->mmc->detect);
7544 + gpio_free(host->detect_pin);
7545 + }
7546 +
7547 + mmc_remove_host(host->mmc);
7548 +
7549 + mci_writel(host, IDR, ~0UL);
7550 + mci_writel(host, CR, MCI_BIT(MCIDIS));
7551 + mci_readl(host, SR);
7552 +
7553 + dma_release_channel(host->dma.req.req.dmac,
7554 + host->dma.req.req.channel);
7555 +
7556 + if (host->wp_pin >= 0)
7557 + gpio_free(host->wp_pin);
7558 +
7559 + free_irq(platform_get_irq(pdev, 0), host->mmc);
7560 + iounmap(host->regs);
7561 +
7562 + clk_disable(host->mck);
7563 + clk_put(host->mck);
7564 +
7565 + mmc_free_host(host->mmc);
7566 + }
7567 + return 0;
7568 +}
7569 +
7570 +static struct platform_driver atmci_driver = {
7571 + .probe = atmci_probe,
7572 + .remove = __devexit_p(atmci_remove),
7573 + .driver = {
7574 + .name = DRIVER_NAME,
7575 + },
7576 +};
7577 +
7578 +static int __init atmci_init(void)
7579 +{
7580 + return platform_driver_register(&atmci_driver);
7581 +}
7582 +
7583 +static void __exit atmci_exit(void)
7584 +{
7585 + platform_driver_unregister(&atmci_driver);
7586 +}
7587 +
7588 +module_init(atmci_init);
7589 +module_exit(atmci_exit);
7590 +
7591 +MODULE_DESCRIPTION("Atmel Multimedia Card Interface driver");
7592 +MODULE_LICENSE("GPL");
7593 diff --git a/drivers/mmc/host/atmel-mci.h b/drivers/mmc/host/atmel-mci.h
7594 new file mode 100644
7595 index 0000000..60d15c4
7596 --- /dev/null
7597 +++ b/drivers/mmc/host/atmel-mci.h
7598 @@ -0,0 +1,192 @@
7599 +/*
7600 + * Atmel MultiMedia Card Interface driver
7601 + *
7602 + * Copyright (C) 2004-2006 Atmel Corporation
7603 + *
7604 + * This program is free software; you can redistribute it and/or modify
7605 + * it under the terms of the GNU General Public License version 2 as
7606 + * published by the Free Software Foundation.
7607 + */
7608 +#ifndef __DRIVERS_MMC_ATMEL_MCI_H__
7609 +#define __DRIVERS_MMC_ATMEL_MCI_H__
7610 +
7611 +/* MCI register offsets */
7612 +#define MCI_CR 0x0000
7613 +#define MCI_MR 0x0004
7614 +#define MCI_DTOR 0x0008
7615 +#define MCI_SDCR 0x000c
7616 +#define MCI_ARGR 0x0010
7617 +#define MCI_CMDR 0x0014
7618 +#define MCI_BLKR 0x0018
7619 +#define MCI_RSPR 0x0020
7620 +#define MCI_RSPR1 0x0024
7621 +#define MCI_RSPR2 0x0028
7622 +#define MCI_RSPR3 0x002c
7623 +#define MCI_RDR 0x0030
7624 +#define MCI_TDR 0x0034
7625 +#define MCI_SR 0x0040
7626 +#define MCI_IER 0x0044
7627 +#define MCI_IDR 0x0048
7628 +#define MCI_IMR 0x004c
7629 +
7630 +/* Bitfields in CR */
7631 +#define MCI_MCIEN_OFFSET 0
7632 +#define MCI_MCIEN_SIZE 1
7633 +#define MCI_MCIDIS_OFFSET 1
7634 +#define MCI_MCIDIS_SIZE 1
7635 +#define MCI_PWSEN_OFFSET 2
7636 +#define MCI_PWSEN_SIZE 1
7637 +#define MCI_PWSDIS_OFFSET 3
7638 +#define MCI_PWSDIS_SIZE 1
7639 +#define MCI_SWRST_OFFSET 7
7640 +#define MCI_SWRST_SIZE 1
7641 +
7642 +/* Bitfields in MR */
7643 +#define MCI_CLKDIV_OFFSET 0
7644 +#define MCI_CLKDIV_SIZE 8
7645 +#define MCI_PWSDIV_OFFSET 8
7646 +#define MCI_PWSDIV_SIZE 3
7647 +#define MCI_RDPROOF_OFFSET 11
7648 +#define MCI_RDPROOF_SIZE 1
7649 +#define MCI_WRPROOF_OFFSET 12
7650 +#define MCI_WRPROOF_SIZE 1
7651 +#define MCI_DMAPADV_OFFSET 14
7652 +#define MCI_DMAPADV_SIZE 1
7653 +#define MCI_BLKLEN_OFFSET 16
7654 +#define MCI_BLKLEN_SIZE 16
7655 +
7656 +/* Bitfields in DTOR */
7657 +#define MCI_DTOCYC_OFFSET 0
7658 +#define MCI_DTOCYC_SIZE 4
7659 +#define MCI_DTOMUL_OFFSET 4
7660 +#define MCI_DTOMUL_SIZE 3
7661 +
7662 +/* Bitfields in SDCR */
7663 +#define MCI_SDCSEL_OFFSET 0
7664 +#define MCI_SDCSEL_SIZE 4
7665 +#define MCI_SDCBUS_OFFSET 7
7666 +#define MCI_SDCBUS_SIZE 1
7667 +
7668 +/* Bitfields in ARGR */
7669 +#define MCI_ARG_OFFSET 0
7670 +#define MCI_ARG_SIZE 32
7671 +
7672 +/* Bitfields in CMDR */
7673 +#define MCI_CMDNB_OFFSET 0
7674 +#define MCI_CMDNB_SIZE 6
7675 +#define MCI_RSPTYP_OFFSET 6
7676 +#define MCI_RSPTYP_SIZE 2
7677 +#define MCI_SPCMD_OFFSET 8
7678 +#define MCI_SPCMD_SIZE 3
7679 +#define MCI_OPDCMD_OFFSET 11
7680 +#define MCI_OPDCMD_SIZE 1
7681 +#define MCI_MAXLAT_OFFSET 12
7682 +#define MCI_MAXLAT_SIZE 1
7683 +#define MCI_TRCMD_OFFSET 16
7684 +#define MCI_TRCMD_SIZE 2
7685 +#define MCI_TRDIR_OFFSET 18
7686 +#define MCI_TRDIR_SIZE 1
7687 +#define MCI_TRTYP_OFFSET 19
7688 +#define MCI_TRTYP_SIZE 2
7689 +
7690 +/* Bitfields in BLKR */
7691 +#define MCI_BCNT_OFFSET 0
7692 +#define MCI_BCNT_SIZE 16
7693 +
7694 +/* Bitfields in RSPRn */
7695 +#define MCI_RSP_OFFSET 0
7696 +#define MCI_RSP_SIZE 32
7697 +
7698 +/* Bitfields in SR/IER/IDR/IMR */
7699 +#define MCI_CMDRDY_OFFSET 0
7700 +#define MCI_CMDRDY_SIZE 1
7701 +#define MCI_RXRDY_OFFSET 1
7702 +#define MCI_RXRDY_SIZE 1
7703 +#define MCI_TXRDY_OFFSET 2
7704 +#define MCI_TXRDY_SIZE 1
7705 +#define MCI_BLKE_OFFSET 3
7706 +#define MCI_BLKE_SIZE 1
7707 +#define MCI_DTIP_OFFSET 4
7708 +#define MCI_DTIP_SIZE 1
7709 +#define MCI_NOTBUSY_OFFSET 5
7710 +#define MCI_NOTBUSY_SIZE 1
7711 +#define MCI_ENDRX_OFFSET 6
7712 +#define MCI_ENDRX_SIZE 1
7713 +#define MCI_ENDTX_OFFSET 7
7714 +#define MCI_ENDTX_SIZE 1
7715 +#define MCI_RXBUFF_OFFSET 14
7716 +#define MCI_RXBUFF_SIZE 1
7717 +#define MCI_TXBUFE_OFFSET 15
7718 +#define MCI_TXBUFE_SIZE 1
7719 +#define MCI_RINDE_OFFSET 16
7720 +#define MCI_RINDE_SIZE 1
7721 +#define MCI_RDIRE_OFFSET 17
7722 +#define MCI_RDIRE_SIZE 1
7723 +#define MCI_RCRCE_OFFSET 18
7724 +#define MCI_RCRCE_SIZE 1
7725 +#define MCI_RENDE_OFFSET 19
7726 +#define MCI_RENDE_SIZE 1
7727 +#define MCI_RTOE_OFFSET 20
7728 +#define MCI_RTOE_SIZE 1
7729 +#define MCI_DCRCE_OFFSET 21
7730 +#define MCI_DCRCE_SIZE 1
7731 +#define MCI_DTOE_OFFSET 22
7732 +#define MCI_DTOE_SIZE 1
7733 +#define MCI_OVRE_OFFSET 30
7734 +#define MCI_OVRE_SIZE 1
7735 +#define MCI_UNRE_OFFSET 31
7736 +#define MCI_UNRE_SIZE 1
7737 +
7738 +/* Constants for DTOMUL */
7739 +#define MCI_DTOMUL_1_CYCLE 0
7740 +#define MCI_DTOMUL_16_CYCLES 1
7741 +#define MCI_DTOMUL_128_CYCLES 2
7742 +#define MCI_DTOMUL_256_CYCLES 3
7743 +#define MCI_DTOMUL_1024_CYCLES 4
7744 +#define MCI_DTOMUL_4096_CYCLES 5
7745 +#define MCI_DTOMUL_65536_CYCLES 6
7746 +#define MCI_DTOMUL_1048576_CYCLES 7
7747 +
7748 +/* Constants for RSPTYP */
7749 +#define MCI_RSPTYP_NO_RESP 0
7750 +#define MCI_RSPTYP_48_BIT 1
7751 +#define MCI_RSPTYP_136_BIT 2
7752 +
7753 +/* Constants for SPCMD */
7754 +#define MCI_SPCMD_NO_SPEC_CMD 0
7755 +#define MCI_SPCMD_INIT_CMD 1
7756 +#define MCI_SPCMD_SYNC_CMD 2
7757 +#define MCI_SPCMD_INT_CMD 4
7758 +#define MCI_SPCMD_INT_RESP 5
7759 +
7760 +/* Constants for TRCMD */
7761 +#define MCI_TRCMD_NO_TRANS 0
7762 +#define MCI_TRCMD_START_TRANS 1
7763 +#define MCI_TRCMD_STOP_TRANS 2
7764 +
7765 +/* Constants for TRTYP */
7766 +#define MCI_TRTYP_BLOCK 0
7767 +#define MCI_TRTYP_MULTI_BLOCK 1
7768 +#define MCI_TRTYP_STREAM 2
7769 +
7770 +/* Bit manipulation macros */
7771 +#define MCI_BIT(name) \
7772 + (1 << MCI_##name##_OFFSET)
7773 +#define MCI_BF(name,value) \
7774 + (((value) & ((1 << MCI_##name##_SIZE) - 1)) \
7775 + << MCI_##name##_OFFSET)
7776 +#define MCI_BFEXT(name,value) \
7777 + (((value) >> MCI_##name##_OFFSET) \
7778 + & ((1 << MCI_##name##_SIZE) - 1))
7779 +#define MCI_BFINS(name,value,old) \
7780 + (((old) & ~(((1 << MCI_##name##_SIZE) - 1) \
7781 + << MCI_##name##_OFFSET)) \
7782 + | MCI_BF(name,value))
7783 +
7784 +/* Register access macros */
7785 +#define mci_readl(port,reg) \
7786 + __raw_readl((port)->regs + MCI_##reg)
7787 +#define mci_writel(port,reg,value) \
7788 + __raw_writel((value), (port)->regs + MCI_##reg)
7789 +
7790 +#endif /* __DRIVERS_MMC_ATMEL_MCI_H__ */
7791 diff --git a/drivers/mtd/chips/cfi_cmdset_0001.c b/drivers/mtd/chips/cfi_cmdset_0001.c
7792 index 2f19fa7..94304ca 100644
7793 --- a/drivers/mtd/chips/cfi_cmdset_0001.c
7794 +++ b/drivers/mtd/chips/cfi_cmdset_0001.c
7795 @@ -50,6 +50,7 @@
7796 #define I82802AC 0x00ac
7797 #define MANUFACTURER_ST 0x0020
7798 #define M50LPW080 0x002F
7799 +#define AT49BV640D 0x02de
7800
7801 static int cfi_intelext_read (struct mtd_info *, loff_t, size_t, size_t *, u_char *);
7802 static int cfi_intelext_write_words(struct mtd_info *, loff_t, size_t, size_t *, const u_char *);
7803 @@ -156,6 +157,47 @@ static void cfi_tell_features(struct cfi_pri_intelext *extp)
7804 }
7805 #endif
7806
7807 +/* Atmel chips don't use the same PRI format as Intel chips */
7808 +static void fixup_convert_atmel_pri(struct mtd_info *mtd, void *param)
7809 +{
7810 + struct map_info *map = mtd->priv;
7811 + struct cfi_private *cfi = map->fldrv_priv;
7812 + struct cfi_pri_intelext *extp = cfi->cmdset_priv;
7813 + struct cfi_pri_atmel atmel_pri;
7814 + uint32_t features = 0;
7815 +
7816 + /* Reverse byteswapping */
7817 + extp->FeatureSupport = cpu_to_le32(extp->FeatureSupport);
7818 + extp->BlkStatusRegMask = cpu_to_le16(extp->BlkStatusRegMask);
7819 + extp->ProtRegAddr = cpu_to_le16(extp->ProtRegAddr);
7820 +
7821 + memcpy(&atmel_pri, extp, sizeof(atmel_pri));
7822 + memset((char *)extp + 5, 0, sizeof(*extp) - 5);
7823 +
7824 + printk(KERN_ERR "atmel Features: %02x\n", atmel_pri.Features);
7825 +
7826 + if (atmel_pri.Features & 0x01) /* chip erase supported */
7827 + features |= (1<<0);
7828 + if (atmel_pri.Features & 0x02) /* erase suspend supported */
7829 + features |= (1<<1);
7830 + if (atmel_pri.Features & 0x04) /* program suspend supported */
7831 + features |= (1<<2);
7832 + if (atmel_pri.Features & 0x08) /* simultaneous operations supported */
7833 + features |= (1<<9);
7834 + if (atmel_pri.Features & 0x20) /* page mode read supported */
7835 + features |= (1<<7);
7836 + if (atmel_pri.Features & 0x40) /* queued erase supported */
7837 + features |= (1<<4);
7838 + if (atmel_pri.Features & 0x80) /* Protection bits supported */
7839 + features |= (1<<6);
7840 +
7841 + extp->FeatureSupport = features;
7842 +
7843 + /* burst write mode not supported */
7844 + cfi->cfiq->BufWriteTimeoutTyp = 0;
7845 + cfi->cfiq->BufWriteTimeoutMax = 0;
7846 +}
7847 +
7848 #ifdef CMDSET0001_DISABLE_ERASE_SUSPEND_ON_WRITE
7849 /* Some Intel Strata Flash prior to FPO revision C has bugs in this area */
7850 static void fixup_intel_strataflash(struct mtd_info *mtd, void* param)
7851 @@ -233,6 +275,7 @@ static void fixup_use_powerup_lock(struct mtd_info *mtd, void *param)
7852 }
7853
7854 static struct cfi_fixup cfi_fixup_table[] = {
7855 + { CFI_MFR_ATMEL, CFI_ID_ANY, fixup_convert_atmel_pri, NULL },
7856 #ifdef CMDSET0001_DISABLE_ERASE_SUSPEND_ON_WRITE
7857 { CFI_MFR_ANY, CFI_ID_ANY, fixup_intel_strataflash, NULL },
7858 #endif
7859 diff --git a/drivers/mtd/chips/cfi_cmdset_0002.c b/drivers/mtd/chips/cfi_cmdset_0002.c
7860 index 1f64458..205977b 100644
7861 --- a/drivers/mtd/chips/cfi_cmdset_0002.c
7862 +++ b/drivers/mtd/chips/cfi_cmdset_0002.c
7863 @@ -185,6 +185,10 @@ static void fixup_convert_atmel_pri(struct mtd_info *mtd, void *param)
7864 extp->TopBottom = 2;
7865 else
7866 extp->TopBottom = 3;
7867 +
7868 + /* burst write mode not supported */
7869 + cfi->cfiq->BufWriteTimeoutTyp = 0;
7870 + cfi->cfiq->BufWriteTimeoutMax = 0;
7871 }
7872
7873 static void fixup_use_secsi(struct mtd_info *mtd, void *param)
7874 @@ -217,6 +221,7 @@ static void fixup_use_atmel_lock(struct mtd_info *mtd, void *param)
7875 }
7876
7877 static struct cfi_fixup cfi_fixup_table[] = {
7878 + { CFI_MFR_ATMEL, CFI_ID_ANY, fixup_convert_atmel_pri, NULL },
7879 #ifdef AMD_BOOTLOC_BUG
7880 { CFI_MFR_AMD, CFI_ID_ANY, fixup_amd_bootblock, NULL },
7881 #endif
7882 @@ -229,7 +234,6 @@ static struct cfi_fixup cfi_fixup_table[] = {
7883 #if !FORCE_WORD_WRITE
7884 { CFI_MFR_ANY, CFI_ID_ANY, fixup_use_write_buffers, NULL, },
7885 #endif
7886 - { CFI_MFR_ATMEL, CFI_ID_ANY, fixup_convert_atmel_pri, NULL },
7887 { 0, 0, NULL, NULL }
7888 };
7889 static struct cfi_fixup jedec_fixup_table[] = {
7890 diff --git a/drivers/net/Kconfig b/drivers/net/Kconfig
7891 index b49375a..b9cb56a 100644
7892 --- a/drivers/net/Kconfig
7893 +++ b/drivers/net/Kconfig
7894 @@ -191,7 +191,7 @@ config MII
7895 config MACB
7896 tristate "Atmel MACB support"
7897 depends on NET_ETHERNET && (AVR32 || ARCH_AT91SAM9260 || ARCH_AT91SAM9263)
7898 - select MII
7899 + select PHYLIB
7900 help
7901 The Atmel MACB ethernet interface is found on many AT32 and AT91
7902 parts. Say Y to include support for the MACB chip.
7903 diff --git a/drivers/net/macb.c b/drivers/net/macb.c
7904 index 0e04f7a..c20a585 100644
7905 --- a/drivers/net/macb.c
7906 +++ b/drivers/net/macb.c
7907 @@ -17,13 +17,14 @@
7908 #include <linux/init.h>
7909 #include <linux/netdevice.h>
7910 #include <linux/etherdevice.h>
7911 -#include <linux/mii.h>
7912 -#include <linux/mutex.h>
7913 #include <linux/dma-mapping.h>
7914 -#include <linux/ethtool.h>
7915 #include <linux/platform_device.h>
7916 +#include <linux/phy.h>
7917
7918 #include <asm/arch/board.h>
7919 +#if defined(CONFIG_ARCH_AT91)
7920 +#include <asm/arch/cpu.h>
7921 +#endif
7922
7923 #include "macb.h"
7924
7925 @@ -85,172 +86,202 @@ static void __init macb_get_hwaddr(struct macb *bp)
7926 memcpy(bp->dev->dev_addr, addr, sizeof(addr));
7927 }
7928
7929 -static void macb_enable_mdio(struct macb *bp)
7930 +static int macb_mdio_read(struct mii_bus *bus, int mii_id, int regnum)
7931 {
7932 - unsigned long flags;
7933 - u32 reg;
7934 -
7935 - spin_lock_irqsave(&bp->lock, flags);
7936 - reg = macb_readl(bp, NCR);
7937 - reg |= MACB_BIT(MPE);
7938 - macb_writel(bp, NCR, reg);
7939 - macb_writel(bp, IER, MACB_BIT(MFD));
7940 - spin_unlock_irqrestore(&bp->lock, flags);
7941 -}
7942 -
7943 -static void macb_disable_mdio(struct macb *bp)
7944 -{
7945 - unsigned long flags;
7946 - u32 reg;
7947 -
7948 - spin_lock_irqsave(&bp->lock, flags);
7949 - reg = macb_readl(bp, NCR);
7950 - reg &= ~MACB_BIT(MPE);
7951 - macb_writel(bp, NCR, reg);
7952 - macb_writel(bp, IDR, MACB_BIT(MFD));
7953 - spin_unlock_irqrestore(&bp->lock, flags);
7954 -}
7955 -
7956 -static int macb_mdio_read(struct net_device *dev, int phy_id, int location)
7957 -{
7958 - struct macb *bp = netdev_priv(dev);
7959 + struct macb *bp = bus->priv;
7960 int value;
7961
7962 - mutex_lock(&bp->mdio_mutex);
7963 -
7964 - macb_enable_mdio(bp);
7965 macb_writel(bp, MAN, (MACB_BF(SOF, MACB_MAN_SOF)
7966 | MACB_BF(RW, MACB_MAN_READ)
7967 - | MACB_BF(PHYA, phy_id)
7968 - | MACB_BF(REGA, location)
7969 + | MACB_BF(PHYA, mii_id)
7970 + | MACB_BF(REGA, regnum)
7971 | MACB_BF(CODE, MACB_MAN_CODE)));
7972
7973 - wait_for_completion(&bp->mdio_complete);
7974 + /* wait for end of transfer */
7975 + while (!MACB_BFEXT(IDLE, macb_readl(bp, NSR)))
7976 + cpu_relax();
7977
7978 value = MACB_BFEXT(DATA, macb_readl(bp, MAN));
7979 - macb_disable_mdio(bp);
7980 - mutex_unlock(&bp->mdio_mutex);
7981
7982 return value;
7983 }
7984
7985 -static void macb_mdio_write(struct net_device *dev, int phy_id,
7986 - int location, int val)
7987 +static int macb_mdio_write(struct mii_bus *bus, int mii_id, int regnum,
7988 + u16 value)
7989 {
7990 - struct macb *bp = netdev_priv(dev);
7991 -
7992 - dev_dbg(&bp->pdev->dev, "mdio_write %02x:%02x <- %04x\n",
7993 - phy_id, location, val);
7994 -
7995 - mutex_lock(&bp->mdio_mutex);
7996 - macb_enable_mdio(bp);
7997 + struct macb *bp = bus->priv;
7998
7999 macb_writel(bp, MAN, (MACB_BF(SOF, MACB_MAN_SOF)
8000 | MACB_BF(RW, MACB_MAN_WRITE)
8001 - | MACB_BF(PHYA, phy_id)
8002 - | MACB_BF(REGA, location)
8003 + | MACB_BF(PHYA, mii_id)
8004 + | MACB_BF(REGA, regnum)
8005 | MACB_BF(CODE, MACB_MAN_CODE)
8006 - | MACB_BF(DATA, val)));
8007 + | MACB_BF(DATA, value)));
8008
8009 - wait_for_completion(&bp->mdio_complete);
8010 + /* wait for end of transfer */
8011 + while (!MACB_BFEXT(IDLE, macb_readl(bp, NSR)))
8012 + cpu_relax();
8013
8014 - macb_disable_mdio(bp);
8015 - mutex_unlock(&bp->mdio_mutex);
8016 + return 0;
8017 }
8018
8019 -static int macb_phy_probe(struct macb *bp)
8020 +static int macb_mdio_reset(struct mii_bus *bus)
8021 {
8022 - int phy_address;
8023 - u16 phyid1, phyid2;
8024 + return 0;
8025 +}
8026
8027 - for (phy_address = 0; phy_address < 32; phy_address++) {
8028 - phyid1 = macb_mdio_read(bp->dev, phy_address, MII_PHYSID1);
8029 - phyid2 = macb_mdio_read(bp->dev, phy_address, MII_PHYSID2);
8030 +static void macb_handle_link_change(struct net_device *dev)
8031 +{
8032 + struct macb *bp = netdev_priv(dev);
8033 + struct phy_device *phydev = bp->phy_dev;
8034 + unsigned long flags;
8035
8036 - if (phyid1 != 0xffff && phyid1 != 0x0000
8037 - && phyid2 != 0xffff && phyid2 != 0x0000)
8038 - break;
8039 + int status_change = 0;
8040 +
8041 + spin_lock_irqsave(&bp->lock, flags);
8042 +
8043 + if (phydev->link) {
8044 + if ((bp->speed != phydev->speed) ||
8045 + (bp->duplex != phydev->duplex)) {
8046 + u32 reg;
8047 +
8048 + reg = macb_readl(bp, NCFGR);
8049 + reg &= ~(MACB_BIT(SPD) | MACB_BIT(FD));
8050 +
8051 + if (phydev->duplex)
8052 + reg |= MACB_BIT(FD);
8053 + if (phydev->speed)
8054 + reg |= MACB_BIT(SPD);
8055 +
8056 + macb_writel(bp, NCFGR, reg);
8057 +
8058 + bp->speed = phydev->speed;
8059 + bp->duplex = phydev->duplex;
8060 + status_change = 1;
8061 + }
8062 }
8063
8064 - if (phy_address == 32)
8065 - return -ENODEV;
8066 + if (phydev->link != bp->link) {
8067 + if (phydev->link)
8068 + netif_schedule(dev);
8069 + else {
8070 + bp->speed = 0;
8071 + bp->duplex = -1;
8072 + }
8073 + bp->link = phydev->link;
8074
8075 - dev_info(&bp->pdev->dev,
8076 - "detected PHY at address %d (ID %04x:%04x)\n",
8077 - phy_address, phyid1, phyid2);
8078 + status_change = 1;
8079 + }
8080
8081 - bp->mii.phy_id = phy_address;
8082 - return 0;
8083 + spin_unlock_irqrestore(&bp->lock, flags);
8084 +
8085 + if (status_change) {
8086 + if (phydev->link)
8087 + printk(KERN_INFO "%s: link up (%d/%s)\n",
8088 + dev->name, phydev->speed,
8089 + DUPLEX_FULL == phydev->duplex ? "Full":"Half");
8090 + else
8091 + printk(KERN_INFO "%s: link down\n", dev->name);
8092 + }
8093 }
8094
8095 -static void macb_set_media(struct macb *bp, int media)
8096 +/* based on au1000_eth. c*/
8097 +static int macb_mii_probe(struct net_device *dev)
8098 {
8099 - u32 reg;
8100 + struct macb *bp = netdev_priv(dev);
8101 + struct phy_device *phydev = NULL;
8102 + struct eth_platform_data *pdata;
8103 + int phy_addr;
8104
8105 - spin_lock_irq(&bp->lock);
8106 - reg = macb_readl(bp, NCFGR);
8107 - reg &= ~(MACB_BIT(SPD) | MACB_BIT(FD));
8108 - if (media & (ADVERTISE_100HALF | ADVERTISE_100FULL))
8109 - reg |= MACB_BIT(SPD);
8110 - if (media & ADVERTISE_FULL)
8111 - reg |= MACB_BIT(FD);
8112 - macb_writel(bp, NCFGR, reg);
8113 - spin_unlock_irq(&bp->lock);
8114 + /* find the first phy */
8115 + for (phy_addr = 0; phy_addr < PHY_MAX_ADDR; phy_addr++) {
8116 + if (bp->mii_bus.phy_map[phy_addr]) {
8117 + phydev = bp->mii_bus.phy_map[phy_addr];
8118 + break;
8119 + }
8120 + }
8121 +
8122 + if (!phydev) {
8123 + printk (KERN_ERR "%s: no PHY found\n", dev->name);
8124 + return -1;
8125 + }
8126 +
8127 + pdata = bp->pdev->dev.platform_data;
8128 + /* TODO : add pin_irq */
8129 +
8130 + /* attach the mac to the phy */
8131 + if (pdata && pdata->is_rmii) {
8132 + phydev = phy_connect(dev, phydev->dev.bus_id,
8133 + &macb_handle_link_change, 0, PHY_INTERFACE_MODE_RMII);
8134 + } else {
8135 + phydev = phy_connect(dev, phydev->dev.bus_id,
8136 + &macb_handle_link_change, 0, PHY_INTERFACE_MODE_MII);
8137 + }
8138 +
8139 + if (IS_ERR(phydev)) {
8140 + printk(KERN_ERR "%s: Could not attach to PHY\n", dev->name);
8141 + return PTR_ERR(phydev);
8142 + }
8143 +
8144 + /* mask with MAC supported features */
8145 + phydev->supported &= PHY_BASIC_FEATURES;
8146 +
8147 + phydev->advertising = phydev->supported;
8148 +
8149 + bp->link = 0;
8150 + bp->speed = 0;
8151 + bp->duplex = -1;
8152 + bp->phy_dev = phydev;
8153 +
8154 + return 0;
8155 }
8156
8157 -static void macb_check_media(struct macb *bp, int ok_to_print, int init_media)
8158 +static int macb_mii_init(struct macb *bp)
8159 {
8160 - struct mii_if_info *mii = &bp->mii;
8161 - unsigned int old_carrier, new_carrier;
8162 - int advertise, lpa, media, duplex;
8163 + struct eth_platform_data *pdata;
8164 + int err = -ENXIO, i;
8165
8166 - /* if forced media, go no further */
8167 - if (mii->force_media)
8168 - return;
8169 + /* Enable managment port */
8170 + macb_writel(bp, NCR, MACB_BIT(MPE));
8171
8172 - /* check current and old link status */
8173 - old_carrier = netif_carrier_ok(mii->dev) ? 1 : 0;
8174 - new_carrier = (unsigned int) mii_link_ok(mii);
8175 + bp->mii_bus.name = "MACB_mii_bus",
8176 + bp->mii_bus.read = &macb_mdio_read,
8177 + bp->mii_bus.write = &macb_mdio_write,
8178 + bp->mii_bus.reset = &macb_mdio_reset,
8179 + bp->mii_bus.id = bp->pdev->id,
8180 + bp->mii_bus.priv = bp,
8181 + bp->mii_bus.dev = &bp->dev->dev;
8182 + pdata = bp->pdev->dev.platform_data;
8183
8184 - /* if carrier state did not change, assume nothing else did */
8185 - if (!init_media && old_carrier == new_carrier)
8186 - return;
8187 + if (pdata)
8188 + bp->mii_bus.phy_mask = pdata->phy_mask;
8189
8190 - /* no carrier, nothing much to do */
8191 - if (!new_carrier) {
8192 - netif_carrier_off(mii->dev);
8193 - printk(KERN_INFO "%s: link down\n", mii->dev->name);
8194 - return;
8195 + bp->mii_bus.irq = kmalloc(sizeof(int)*PHY_MAX_ADDR, GFP_KERNEL);
8196 + if (!bp->mii_bus.irq) {
8197 + err = -ENOMEM;
8198 + goto err_out;
8199 }
8200
8201 - /*
8202 - * we have carrier, see who's on the other end
8203 - */
8204 - netif_carrier_on(mii->dev);
8205 + for (i = 0; i < PHY_MAX_ADDR; i++)
8206 + bp->mii_bus.irq[i] = PHY_POLL;
8207
8208 - /* get MII advertise and LPA values */
8209 - if (!init_media && mii->advertising) {
8210 - advertise = mii->advertising;
8211 - } else {
8212 - advertise = mii->mdio_read(mii->dev, mii->phy_id, MII_ADVERTISE);
8213 - mii->advertising = advertise;
8214 - }
8215 - lpa = mii->mdio_read(mii->dev, mii->phy_id, MII_LPA);
8216 + platform_set_drvdata(bp->dev, &bp->mii_bus);
8217
8218 - /* figure out media and duplex from advertise and LPA values */
8219 - media = mii_nway_result(lpa & advertise);
8220 - duplex = (media & ADVERTISE_FULL) ? 1 : 0;
8221 + if (mdiobus_register(&bp->mii_bus))
8222 + goto err_out_free_mdio_irq;
8223
8224 - if (ok_to_print)
8225 - printk(KERN_INFO "%s: link up, %sMbps, %s-duplex, lpa 0x%04X\n",
8226 - mii->dev->name,
8227 - media & (ADVERTISE_100FULL | ADVERTISE_100HALF) ? "100" : "10",
8228 - duplex ? "full" : "half", lpa);
8229 + if (macb_mii_probe(bp->dev) != 0) {
8230 + goto err_out_unregister_bus;
8231 + }
8232
8233 - mii->full_duplex = duplex;
8234 + return 0;
8235
8236 - /* Let the MAC know about the new link state */
8237 - macb_set_media(bp, media);
8238 +err_out_unregister_bus:
8239 + mdiobus_unregister(&bp->mii_bus);
8240 +err_out_free_mdio_irq:
8241 + kfree(bp->mii_bus.irq);
8242 +err_out:
8243 + return err;
8244 }
8245
8246 static void macb_update_stats(struct macb *bp)
8247 @@ -265,16 +296,6 @@ static void macb_update_stats(struct macb *bp)
8248 *p += __raw_readl(reg);
8249 }
8250
8251 -static void macb_periodic_task(struct work_struct *work)
8252 -{
8253 - struct macb *bp = container_of(work, struct macb, periodic_task.work);
8254 -
8255 - macb_update_stats(bp);
8256 - macb_check_media(bp, 1, 0);
8257 -
8258 - schedule_delayed_work(&bp->periodic_task, HZ);
8259 -}
8260 -
8261 static void macb_tx(struct macb *bp)
8262 {
8263 unsigned int tail;
8264 @@ -519,9 +540,6 @@ static irqreturn_t macb_interrupt(int irq, void *dev_id)
8265 spin_lock(&bp->lock);
8266
8267 while (status) {
8268 - if (status & MACB_BIT(MFD))
8269 - complete(&bp->mdio_complete);
8270 -
8271 /* close possible race with dev_close */
8272 if (unlikely(!netif_running(dev))) {
8273 macb_writel(bp, IDR, ~0UL);
8274 @@ -535,7 +553,8 @@ static irqreturn_t macb_interrupt(int irq, void *dev_id)
8275 * until we have processed the buffers
8276 */
8277 macb_writel(bp, IDR, MACB_RX_INT_FLAGS);
8278 - dev_dbg(&bp->pdev->dev, "scheduling RX softirq\n");
8279 + dev_dbg(&bp->pdev->dev,
8280 + "scheduling RX softirq\n");
8281 __netif_rx_schedule(dev);
8282 }
8283 }
8284 @@ -765,7 +784,7 @@ static void macb_init_hw(struct macb *bp)
8285 macb_writel(bp, TBQP, bp->tx_ring_dma);
8286
8287 /* Enable TX and RX */
8288 - macb_writel(bp, NCR, MACB_BIT(RE) | MACB_BIT(TE));
8289 + macb_writel(bp, NCR, MACB_BIT(RE) | MACB_BIT(TE) | MACB_BIT(MPE));
8290
8291 /* Enable interrupts */
8292 macb_writel(bp, IER, (MACB_BIT(RCOMP)
8293 @@ -776,18 +795,126 @@ static void macb_init_hw(struct macb *bp)
8294 | MACB_BIT(TCOMP)
8295 | MACB_BIT(ISR_ROVR)
8296 | MACB_BIT(HRESP)));
8297 +
8298 }
8299
8300 -static void macb_init_phy(struct net_device *dev)
8301 +/*
8302 + * The hash address register is 64 bits long and takes up two
8303 + * locations in the memory map. The least significant bits are stored
8304 + * in EMAC_HSL and the most significant bits in EMAC_HSH.
8305 + *
8306 + * The unicast hash enable and the multicast hash enable bits in the
8307 + * network configuration register enable the reception of hash matched
8308 + * frames. The destination address is reduced to a 6 bit index into
8309 + * the 64 bit hash register using the following hash function. The
8310 + * hash function is an exclusive or of every sixth bit of the
8311 + * destination address.
8312 + *
8313 + * hi[5] = da[5] ^ da[11] ^ da[17] ^ da[23] ^ da[29] ^ da[35] ^ da[41] ^ da[47]
8314 + * hi[4] = da[4] ^ da[10] ^ da[16] ^ da[22] ^ da[28] ^ da[34] ^ da[40] ^ da[46]
8315 + * hi[3] = da[3] ^ da[09] ^ da[15] ^ da[21] ^ da[27] ^ da[33] ^ da[39] ^ da[45]
8316 + * hi[2] = da[2] ^ da[08] ^ da[14] ^ da[20] ^ da[26] ^ da[32] ^ da[38] ^ da[44]
8317 + * hi[1] = da[1] ^ da[07] ^ da[13] ^ da[19] ^ da[25] ^ da[31] ^ da[37] ^ da[43]
8318 + * hi[0] = da[0] ^ da[06] ^ da[12] ^ da[18] ^ da[24] ^ da[30] ^ da[36] ^ da[42]
8319 + *
8320 + * da[0] represents the least significant bit of the first byte
8321 + * received, that is, the multicast/unicast indicator, and da[47]
8322 + * represents the most significant bit of the last byte received. If
8323 + * the hash index, hi[n], points to a bit that is set in the hash
8324 + * register then the frame will be matched according to whether the
8325 + * frame is multicast or unicast. A multicast match will be signalled
8326 + * if the multicast hash enable bit is set, da[0] is 1 and the hash
8327 + * index points to a bit set in the hash register. A unicast match
8328 + * will be signalled if the unicast hash enable bit is set, da[0] is 0
8329 + * and the hash index points to a bit set in the hash register. To
8330 + * receive all multicast frames, the hash register should be set with
8331 + * all ones and the multicast hash enable bit should be set in the
8332 + * network configuration register.
8333 + */
8334 +
8335 +static inline int hash_bit_value(int bitnr, __u8 *addr)
8336 {
8337 + if (addr[bitnr / 8] & (1 << (bitnr % 8)))
8338 + return 1;
8339 + return 0;
8340 +}
8341 +
8342 +/*
8343 + * Return the hash index value for the specified address.
8344 + */
8345 +static int hash_get_index(__u8 *addr)
8346 +{
8347 + int i, j, bitval;
8348 + int hash_index = 0;
8349 +
8350 + for (j = 0; j < 6; j++) {
8351 + for (i = 0, bitval = 0; i < 8; i++)
8352 + bitval ^= hash_bit_value(i*6 + j, addr);
8353 +
8354 + hash_index |= (bitval << j);
8355 + }
8356 +
8357 + return hash_index;
8358 +}
8359 +
8360 +/*
8361 + * Add multicast addresses to the internal multicast-hash table.
8362 + */
8363 +static void macb_sethashtable(struct net_device *dev)
8364 +{
8365 + struct dev_mc_list *curr;
8366 + unsigned long mc_filter[2];
8367 + unsigned int i, bitnr;
8368 + struct macb *bp = netdev_priv(dev);
8369 +
8370 + mc_filter[0] = mc_filter[1] = 0;
8371 +
8372 + curr = dev->mc_list;
8373 + for (i = 0; i < dev->mc_count; i++, curr = curr->next) {
8374 + if (!curr) break; /* unexpected end of list */
8375 +
8376 + bitnr = hash_get_index(curr->dmi_addr);
8377 + mc_filter[bitnr >> 5] |= 1 << (bitnr & 31);
8378 + }
8379 +
8380 + macb_writel(bp, HRB, mc_filter[0]);
8381 + macb_writel(bp, HRT, mc_filter[1]);
8382 +}
8383 +
8384 +/*
8385 + * Enable/Disable promiscuous and multicast modes.
8386 + */
8387 +static void macb_set_rx_mode(struct net_device *dev)
8388 +{
8389 + unsigned long cfg;
8390 struct macb *bp = netdev_priv(dev);
8391
8392 - /* Set some reasonable default settings */
8393 - macb_mdio_write(dev, bp->mii.phy_id, MII_ADVERTISE,
8394 - ADVERTISE_CSMA | ADVERTISE_ALL);
8395 - macb_mdio_write(dev, bp->mii.phy_id, MII_BMCR,
8396 - (BMCR_SPEED100 | BMCR_ANENABLE
8397 - | BMCR_ANRESTART | BMCR_FULLDPLX));
8398 + cfg = macb_readl(bp, NCFGR);
8399 +
8400 + if (dev->flags & IFF_PROMISC)
8401 + /* Enable promiscuous mode */
8402 + cfg |= MACB_BIT(CAF);
8403 + else if (dev->flags & (~IFF_PROMISC))
8404 + /* Disable promiscuous mode */
8405 + cfg &= ~MACB_BIT(CAF);
8406 +
8407 + if (dev->flags & IFF_ALLMULTI) {
8408 + /* Enable all multicast mode */
8409 + macb_writel(bp, HRB, -1);
8410 + macb_writel(bp, HRT, -1);
8411 + cfg |= MACB_BIT(NCFGR_MTI);
8412 + } else if (dev->mc_count > 0) {
8413 + /* Enable specific multicasts */
8414 + macb_sethashtable(dev);
8415 + cfg |= MACB_BIT(NCFGR_MTI);
8416 + } else if (dev->flags & (~IFF_ALLMULTI)) {
8417 + /* Disable all multicast mode */
8418 + macb_writel(bp, HRB, 0);
8419 + macb_writel(bp, HRT, 0);
8420 + cfg &= ~MACB_BIT(NCFGR_MTI);
8421 + }
8422 +
8423 + macb_writel(bp, NCFGR, cfg);
8424 }
8425
8426 static int macb_open(struct net_device *dev)
8427 @@ -797,6 +924,10 @@ static int macb_open(struct net_device *dev)
8428
8429 dev_dbg(&bp->pdev->dev, "open\n");
8430
8431 + /* if the phy is not yet register, retry later*/
8432 + if (!bp->phy_dev)
8433 + return -EAGAIN;
8434 +
8435 if (!is_valid_ether_addr(dev->dev_addr))
8436 return -EADDRNOTAVAIL;
8437
8438 @@ -810,12 +941,11 @@ static int macb_open(struct net_device *dev)
8439
8440 macb_init_rings(bp);
8441 macb_init_hw(bp);
8442 - macb_init_phy(dev);
8443
8444 - macb_check_media(bp, 1, 1);
8445 - netif_start_queue(dev);
8446 + /* schedule a link state check */
8447 + phy_start(bp->phy_dev);
8448
8449 - schedule_delayed_work(&bp->periodic_task, HZ);
8450 + netif_start_queue(dev);
8451
8452 return 0;
8453 }
8454 @@ -825,10 +955,11 @@ static int macb_close(struct net_device *dev)
8455 struct macb *bp = netdev_priv(dev);
8456 unsigned long flags;
8457
8458 - cancel_rearming_delayed_work(&bp->periodic_task);
8459 -
8460 netif_stop_queue(dev);
8461
8462 + if (bp->phy_dev)
8463 + phy_stop(bp->phy_dev);
8464 +
8465 spin_lock_irqsave(&bp->lock, flags);
8466 macb_reset_hw(bp);
8467 netif_carrier_off(dev);
8468 @@ -845,6 +976,9 @@ static struct net_device_stats *macb_get_stats(struct net_device *dev)
8469 struct net_device_stats *nstat = &bp->stats;
8470 struct macb_stats *hwstat = &bp->hw_stats;
8471
8472 + /* read stats from hardware */
8473 + macb_update_stats(bp);
8474 +
8475 /* Convert HW stats into netdevice stats */
8476 nstat->rx_errors = (hwstat->rx_fcs_errors +
8477 hwstat->rx_align_errors +
8478 @@ -882,18 +1016,27 @@ static struct net_device_stats *macb_get_stats(struct net_device *dev)
8479 static int macb_get_settings(struct net_device *dev, struct ethtool_cmd *cmd)
8480 {
8481 struct macb *bp = netdev_priv(dev);
8482 + struct phy_device *phydev = bp->phy_dev;
8483
8484 - return mii_ethtool_gset(&bp->mii, cmd);
8485 + if (!phydev)
8486 + return -ENODEV;
8487 +
8488 + return phy_ethtool_gset(phydev, cmd);
8489 }
8490
8491 static int macb_set_settings(struct net_device *dev, struct ethtool_cmd *cmd)
8492 {
8493 struct macb *bp = netdev_priv(dev);
8494 + struct phy_device *phydev = bp->phy_dev;
8495
8496 - return mii_ethtool_sset(&bp->mii, cmd);
8497 + if (!phydev)
8498 + return -ENODEV;
8499 +
8500 + return phy_ethtool_sset(phydev, cmd);
8501 }
8502
8503 -static void macb_get_drvinfo(struct net_device *dev, struct ethtool_drvinfo *info)
8504 +static void macb_get_drvinfo(struct net_device *dev,
8505 + struct ethtool_drvinfo *info)
8506 {
8507 struct macb *bp = netdev_priv(dev);
8508
8509 @@ -902,104 +1045,34 @@ static void macb_get_drvinfo(struct net_device *dev, struct ethtool_drvinfo *inf
8510 strcpy(info->bus_info, bp->pdev->dev.bus_id);
8511 }
8512
8513 -static int macb_nway_reset(struct net_device *dev)
8514 -{
8515 - struct macb *bp = netdev_priv(dev);
8516 - return mii_nway_restart(&bp->mii);
8517 -}
8518 -
8519 static struct ethtool_ops macb_ethtool_ops = {
8520 .get_settings = macb_get_settings,
8521 .set_settings = macb_set_settings,
8522 .get_drvinfo = macb_get_drvinfo,
8523 - .nway_reset = macb_nway_reset,
8524 .get_link = ethtool_op_get_link,
8525 };
8526
8527 static int macb_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
8528 {
8529 struct macb *bp = netdev_priv(dev);
8530 + struct phy_device *phydev = bp->phy_dev;
8531
8532 if (!netif_running(dev))
8533 return -EINVAL;
8534
8535 - return generic_mii_ioctl(&bp->mii, if_mii(rq), cmd, NULL);
8536 -}
8537 -
8538 -static ssize_t macb_mii_show(const struct device *_dev, char *buf,
8539 - unsigned long addr)
8540 -{
8541 - struct net_device *dev = to_net_dev(_dev);
8542 - struct macb *bp = netdev_priv(dev);
8543 - ssize_t ret = -EINVAL;
8544 -
8545 - if (netif_running(dev)) {
8546 - int value;
8547 - value = macb_mdio_read(dev, bp->mii.phy_id, addr);
8548 - ret = sprintf(buf, "0x%04x\n", (uint16_t)value);
8549 - }
8550 -
8551 - return ret;
8552 -}
8553 -
8554 -#define MII_ENTRY(name, addr) \
8555 -static ssize_t show_##name(struct device *_dev, \
8556 - struct device_attribute *attr, \
8557 - char *buf) \
8558 -{ \
8559 - return macb_mii_show(_dev, buf, addr); \
8560 -} \
8561 -static DEVICE_ATTR(name, S_IRUGO, show_##name, NULL)
8562 -
8563 -MII_ENTRY(bmcr, MII_BMCR);
8564 -MII_ENTRY(bmsr, MII_BMSR);
8565 -MII_ENTRY(physid1, MII_PHYSID1);
8566 -MII_ENTRY(physid2, MII_PHYSID2);
8567 -MII_ENTRY(advertise, MII_ADVERTISE);
8568 -MII_ENTRY(lpa, MII_LPA);
8569 -MII_ENTRY(expansion, MII_EXPANSION);
8570 -
8571 -static struct attribute *macb_mii_attrs[] = {
8572 - &dev_attr_bmcr.attr,
8573 - &dev_attr_bmsr.attr,
8574 - &dev_attr_physid1.attr,
8575 - &dev_attr_physid2.attr,
8576 - &dev_attr_advertise.attr,
8577 - &dev_attr_lpa.attr,
8578 - &dev_attr_expansion.attr,
8579 - NULL,
8580 -};
8581 -
8582 -static struct attribute_group macb_mii_group = {
8583 - .name = "mii",
8584 - .attrs = macb_mii_attrs,
8585 -};
8586 -
8587 -static void macb_unregister_sysfs(struct net_device *net)
8588 -{
8589 - struct device *_dev = &net->dev;
8590 + if (!phydev)
8591 + return -ENODEV;
8592
8593 - sysfs_remove_group(&_dev->kobj, &macb_mii_group);
8594 + return phy_mii_ioctl(phydev, if_mii(rq), cmd);
8595 }
8596
8597 -static int macb_register_sysfs(struct net_device *net)
8598 -{
8599 - struct device *_dev = &net->dev;
8600 - int ret;
8601 -
8602 - ret = sysfs_create_group(&_dev->kobj, &macb_mii_group);
8603 - if (ret)
8604 - printk(KERN_WARNING
8605 - "%s: sysfs mii attribute registration failed: %d\n",
8606 - net->name, ret);
8607 - return ret;
8608 -}
8609 static int __devinit macb_probe(struct platform_device *pdev)
8610 {
8611 struct eth_platform_data *pdata;
8612 struct resource *regs;
8613 struct net_device *dev;
8614 struct macb *bp;
8615 + struct phy_device *phydev;
8616 unsigned long pclk_hz;
8617 u32 config;
8618 int err = -ENXIO;
8619 @@ -1073,6 +1146,7 @@ static int __devinit macb_probe(struct platform_device *pdev)
8620 dev->stop = macb_close;
8621 dev->hard_start_xmit = macb_start_xmit;
8622 dev->get_stats = macb_get_stats;
8623 + dev->set_multicast_list = macb_set_rx_mode;
8624 dev->do_ioctl = macb_ioctl;
8625 dev->poll = macb_poll;
8626 dev->weight = 64;
8627 @@ -1080,10 +1154,6 @@ static int __devinit macb_probe(struct platform_device *pdev)
8628
8629 dev->base_addr = regs->start;
8630
8631 - INIT_DELAYED_WORK(&bp->periodic_task, macb_periodic_task);
8632 - mutex_init(&bp->mdio_mutex);
8633 - init_completion(&bp->mdio_complete);
8634 -
8635 /* Set MII management clock divider */
8636 pclk_hz = clk_get_rate(bp->pclk);
8637 if (pclk_hz <= 20000000)
8638 @@ -1096,20 +1166,9 @@ static int __devinit macb_probe(struct platform_device *pdev)
8639 config = MACB_BF(CLK, MACB_CLK_DIV64);
8640 macb_writel(bp, NCFGR, config);
8641
8642 - bp->mii.dev = dev;
8643 - bp->mii.mdio_read = macb_mdio_read;
8644 - bp->mii.mdio_write = macb_mdio_write;
8645 - bp->mii.phy_id_mask = 0x1f;
8646 - bp->mii.reg_num_mask = 0x1f;
8647 -
8648 macb_get_hwaddr(bp);
8649 - err = macb_phy_probe(bp);
8650 - if (err) {
8651 - dev_err(&pdev->dev, "Failed to detect PHY, aborting.\n");
8652 - goto err_out_free_irq;
8653 - }
8654 -
8655 pdata = pdev->dev.platform_data;
8656 +
8657 if (pdata && pdata->is_rmii)
8658 #if defined(CONFIG_ARCH_AT91)
8659 macb_writel(bp, USRIO, (MACB_BIT(RMII) | MACB_BIT(CLKEN)) );
8660 @@ -1131,9 +1190,11 @@ static int __devinit macb_probe(struct platform_device *pdev)
8661 goto err_out_free_irq;
8662 }
8663
8664 - platform_set_drvdata(pdev, dev);
8665 + if (macb_mii_init(bp) != 0) {
8666 + goto err_out_unregister_netdev;
8667 + }
8668
8669 - macb_register_sysfs(dev);
8670 + platform_set_drvdata(pdev, dev);
8671
8672 printk(KERN_INFO "%s: Atmel MACB at 0x%08lx irq %d "
8673 "(%02x:%02x:%02x:%02x:%02x:%02x)\n",
8674 @@ -1141,8 +1202,15 @@ static int __devinit macb_probe(struct platform_device *pdev)
8675 dev->dev_addr[0], dev->dev_addr[1], dev->dev_addr[2],
8676 dev->dev_addr[3], dev->dev_addr[4], dev->dev_addr[5]);
8677
8678 + phydev = bp->phy_dev;
8679 + printk(KERN_INFO "%s: attached PHY driver [%s] "
8680 + "(mii_bus:phy_addr=%s, irq=%d)\n",
8681 + dev->name, phydev->drv->name, phydev->dev.bus_id, phydev->irq);
8682 +
8683 return 0;
8684
8685 +err_out_unregister_netdev:
8686 + unregister_netdev(dev);
8687 err_out_free_irq:
8688 free_irq(dev->irq, dev);
8689 err_out_iounmap:
8690 @@ -1153,7 +1221,9 @@ err_out_disable_clocks:
8691 clk_put(bp->hclk);
8692 #endif
8693 clk_disable(bp->pclk);
8694 +#ifndef CONFIG_ARCH_AT91
8695 err_out_put_pclk:
8696 +#endif
8697 clk_put(bp->pclk);
8698 err_out_free_dev:
8699 free_netdev(dev);
8700 @@ -1171,7 +1241,8 @@ static int __devexit macb_remove(struct platform_device *pdev)
8701
8702 if (dev) {
8703 bp = netdev_priv(dev);
8704 - macb_unregister_sysfs(dev);
8705 + mdiobus_unregister(&bp->mii_bus);
8706 + kfree(bp->mii_bus.irq);
8707 unregister_netdev(dev);
8708 free_irq(dev->irq, dev);
8709 iounmap(bp->regs);
8710 diff --git a/drivers/net/macb.h b/drivers/net/macb.h
8711 index b3bb218..4e3283e 100644
8712 --- a/drivers/net/macb.h
8713 +++ b/drivers/net/macb.h
8714 @@ -383,11 +383,11 @@ struct macb {
8715
8716 unsigned int rx_pending, tx_pending;
8717
8718 - struct delayed_work periodic_task;
8719 -
8720 - struct mutex mdio_mutex;
8721 - struct completion mdio_complete;
8722 - struct mii_if_info mii;
8723 + struct mii_bus mii_bus;
8724 + struct phy_device *phy_dev;
8725 + unsigned int link;
8726 + unsigned int speed;
8727 + unsigned int duplex;
8728 };
8729
8730 #endif /* _MACB_H */
8731 diff --git a/drivers/rtc/Kconfig b/drivers/rtc/Kconfig
8732 index 4e4c10a..6d014fb 100644
8733 --- a/drivers/rtc/Kconfig
8734 +++ b/drivers/rtc/Kconfig
8735 @@ -379,6 +379,13 @@ config RTC_DRV_PL031
8736 To compile this driver as a module, choose M here: the
8737 module will be called rtc-pl031.
8738
8739 +config RTC_DRV_AT32AP700X
8740 + tristate "AT32AP700X series RTC"
8741 + depends on RTC_CLASS && PLATFORM_AT32AP
8742 + help
8743 + Driver for the internal RTC (Realtime Clock) on Atmel AVR32
8744 + AT32AP700x family processors.
8745 +
8746 config RTC_DRV_AT91RM9200
8747 tristate "AT91RM9200"
8748 depends on RTC_CLASS && ARCH_AT91RM9200
8749 diff --git a/drivers/rtc/Makefile b/drivers/rtc/Makefile
8750 index a1afbc2..5fb1c10 100644
8751 --- a/drivers/rtc/Makefile
8752 +++ b/drivers/rtc/Makefile
8753 @@ -19,6 +19,7 @@ obj-$(CONFIG_RTC_DRV_CMOS) += rtc-cmos.o
8754 obj-$(CONFIG_RTC_DRV_X1205) += rtc-x1205.o
8755 obj-$(CONFIG_RTC_DRV_ISL1208) += rtc-isl1208.o
8756 obj-$(CONFIG_RTC_DRV_TEST) += rtc-test.o
8757 +obj-$(CONFIG_RTC_DRV_AT32AP700X) += rtc-at32ap700x.o
8758 obj-$(CONFIG_RTC_DRV_DS1307) += rtc-ds1307.o
8759 obj-$(CONFIG_RTC_DRV_DS1672) += rtc-ds1672.o
8760 obj-$(CONFIG_RTC_DRV_DS1742) += rtc-ds1742.o
8761 diff --git a/drivers/rtc/rtc-at32ap700x.c b/drivers/rtc/rtc-at32ap700x.c
8762 new file mode 100644
8763 index 0000000..2999214
8764 --- /dev/null
8765 +++ b/drivers/rtc/rtc-at32ap700x.c
8766 @@ -0,0 +1,317 @@
8767 +/*
8768 + * An RTC driver for the AVR32 AT32AP700x processor series.
8769 + *
8770 + * Copyright (C) 2007 Atmel Corporation
8771 + *
8772 + * This program is free software; you can redistribute it and/or modify it
8773 + * under the terms of the GNU General Public License version 2 as published
8774 + * by the Free Software Foundation.
8775 + */
8776 +
8777 +#include <linux/module.h>
8778 +#include <linux/kernel.h>
8779 +#include <linux/platform_device.h>
8780 +#include <linux/rtc.h>
8781 +#include <linux/io.h>
8782 +
8783 +/*
8784 + * This is a bare-bones RTC. It runs during most system sleep states, but has
8785 + * no battery backup and gets reset during system restart. It must be
8786 + * initialized from an external clock (network, I2C, etc) before it can be of
8787 + * much use.
8788 + *
8789 + * The alarm functionality is limited by the hardware, not supporting
8790 + * periodic interrupts.
8791 + */
8792 +
8793 +#define RTC_CTRL 0x00
8794 +#define RTC_CTRL_EN 0
8795 +#define RTC_CTRL_PCLR 1
8796 +#define RTC_CTRL_TOPEN 2
8797 +#define RTC_CTRL_PSEL 8
8798 +
8799 +#define RTC_VAL 0x04
8800 +
8801 +#define RTC_TOP 0x08
8802 +
8803 +#define RTC_IER 0x10
8804 +#define RTC_IER_TOPI 0
8805 +
8806 +#define RTC_IDR 0x14
8807 +#define RTC_IDR_TOPI 0
8808 +
8809 +#define RTC_IMR 0x18
8810 +#define RTC_IMR_TOPI 0
8811 +
8812 +#define RTC_ISR 0x1c
8813 +#define RTC_ISR_TOPI 0
8814 +
8815 +#define RTC_ICR 0x20
8816 +#define RTC_ICR_TOPI 0
8817 +
8818 +#define RTC_BIT(name) (1 << RTC_##name)
8819 +#define RTC_BF(name, value) ((value) << RTC_##name)
8820 +
8821 +#define rtc_readl(dev, reg) \
8822 + __raw_readl((dev)->regs + RTC_##reg)
8823 +#define rtc_writel(dev, reg, value) \
8824 + __raw_writel((value), (dev)->regs + RTC_##reg)
8825 +
8826 +struct rtc_at32ap700x {
8827 + struct rtc_device *rtc;
8828 + void __iomem *regs;
8829 + unsigned long alarm_time;
8830 + unsigned long irq;
8831 + /* Protect against concurrent register access. */
8832 + spinlock_t lock;
8833 +};
8834 +
8835 +static int at32_rtc_readtime(struct device *dev, struct rtc_time *tm)
8836 +{
8837 + struct rtc_at32ap700x *rtc = dev_get_drvdata(dev);
8838 + unsigned long now;
8839 +
8840 + now = rtc_readl(rtc, VAL);
8841 + rtc_time_to_tm(now, tm);
8842 +
8843 + return 0;
8844 +}
8845 +
8846 +static int at32_rtc_settime(struct device *dev, struct rtc_time *tm)
8847 +{
8848 + struct rtc_at32ap700x *rtc = dev_get_drvdata(dev);
8849 + unsigned long now;
8850 + int ret;
8851 +
8852 + ret = rtc_tm_to_time(tm, &now);
8853 + if (ret == 0)
8854 + rtc_writel(rtc, VAL, now);
8855 +
8856 + return ret;
8857 +}
8858 +
8859 +static int at32_rtc_readalarm(struct device *dev, struct rtc_wkalrm *alrm)
8860 +{
8861 + struct rtc_at32ap700x *rtc = dev_get_drvdata(dev);
8862 +
8863 + rtc_time_to_tm(rtc->alarm_time, &alrm->time);
8864 + alrm->pending = rtc_readl(rtc, IMR) & RTC_BIT(IMR_TOPI) ? 1 : 0;
8865 +
8866 + return 0;
8867 +}
8868 +
8869 +static int at32_rtc_setalarm(struct device *dev, struct rtc_wkalrm *alrm)
8870 +{
8871 + struct rtc_at32ap700x *rtc = dev_get_drvdata(dev);
8872 + unsigned long rtc_unix_time;
8873 + unsigned long alarm_unix_time;
8874 + int ret;
8875 +
8876 + rtc_unix_time = rtc_readl(rtc, VAL);
8877 +
8878 + ret = rtc_tm_to_time(&alrm->time, &alarm_unix_time);
8879 + if (ret)
8880 + return ret;
8881 +
8882 + if (alarm_unix_time < rtc_unix_time)
8883 + return -EINVAL;
8884 +
8885 + spin_lock_irq(&rtc->lock);
8886 + rtc->alarm_time = alarm_unix_time;
8887 + rtc_writel(rtc, TOP, rtc->alarm_time);
8888 + if (alrm->pending)
8889 + rtc_writel(rtc, CTRL, rtc_readl(rtc, CTRL)
8890 + | RTC_BIT(CTRL_TOPEN));
8891 + else
8892 + rtc_writel(rtc, CTRL, rtc_readl(rtc, CTRL)
8893 + & ~RTC_BIT(CTRL_TOPEN));
8894 + spin_unlock_irq(&rtc->lock);
8895 +
8896 + return ret;
8897 +}
8898 +
8899 +static int at32_rtc_ioctl(struct device *dev, unsigned int cmd,
8900 + unsigned long arg)
8901 +{
8902 + struct rtc_at32ap700x *rtc = dev_get_drvdata(dev);
8903 + int ret = 0;
8904 +
8905 + spin_lock_irq(&rtc->lock);
8906 +
8907 + switch (cmd) {
8908 + case RTC_AIE_ON:
8909 + if (rtc_readl(rtc, VAL) > rtc->alarm_time) {
8910 + ret = -EINVAL;
8911 + break;
8912 + }
8913 + rtc_writel(rtc, CTRL, rtc_readl(rtc, CTRL)
8914 + | RTC_BIT(CTRL_TOPEN));
8915 + rtc_writel(rtc, ICR, RTC_BIT(ICR_TOPI));
8916 + rtc_writel(rtc, IER, RTC_BIT(IER_TOPI));
8917 + break;
8918 + case RTC_AIE_OFF:
8919 + rtc_writel(rtc, CTRL, rtc_readl(rtc, CTRL)
8920 + & ~RTC_BIT(CTRL_TOPEN));
8921 + rtc_writel(rtc, IDR, RTC_BIT(IDR_TOPI));
8922 + rtc_writel(rtc, ICR, RTC_BIT(ICR_TOPI));
8923 + break;
8924 + default:
8925 + ret = -ENOIOCTLCMD;
8926 + break;
8927 + }
8928 +
8929 + spin_unlock_irq(&rtc->lock);
8930 +
8931 + return ret;
8932 +}
8933 +
8934 +static irqreturn_t at32_rtc_interrupt(int irq, void *dev_id)
8935 +{
8936 + struct rtc_at32ap700x *rtc = (struct rtc_at32ap700x *)dev_id;
8937 + unsigned long isr = rtc_readl(rtc, ISR);
8938 + unsigned long events = 0;
8939 + int ret = IRQ_NONE;
8940 +
8941 + spin_lock(&rtc->lock);
8942 +
8943 + if (isr & RTC_BIT(ISR_TOPI)) {
8944 + rtc_writel(rtc, ICR, RTC_BIT(ICR_TOPI));
8945 + rtc_writel(rtc, IDR, RTC_BIT(IDR_TOPI));
8946 + rtc_writel(rtc, CTRL, rtc_readl(rtc, CTRL)
8947 + & ~RTC_BIT(CTRL_TOPEN));
8948 + rtc_writel(rtc, VAL, rtc->alarm_time);
8949 + events = RTC_AF | RTC_IRQF;
8950 + rtc_update_irq(rtc->rtc, 1, events);
8951 + ret = IRQ_HANDLED;
8952 + }
8953 +
8954 + spin_unlock(&rtc->lock);
8955 +
8956 + return ret;
8957 +}
8958 +
8959 +static struct rtc_class_ops at32_rtc_ops = {
8960 + .ioctl = at32_rtc_ioctl,
8961 + .read_time = at32_rtc_readtime,
8962 + .set_time = at32_rtc_settime,
8963 + .read_alarm = at32_rtc_readalarm,
8964 + .set_alarm = at32_rtc_setalarm,
8965 +};
8966 +
8967 +static int __init at32_rtc_probe(struct platform_device *pdev)
8968 +{
8969 + struct resource *regs;
8970 + struct rtc_at32ap700x *rtc;
8971 + int irq = -1;
8972 + int ret;
8973 +
8974 + rtc = kzalloc(sizeof(struct rtc_at32ap700x), GFP_KERNEL);
8975 + if (!rtc) {
8976 + dev_dbg(&pdev->dev, "out of memory\n");
8977 + return -ENOMEM;
8978 + }
8979 +
8980 + regs = platform_get_resource(pdev, IORESOURCE_MEM, 0);
8981 + if (!regs) {
8982 + dev_dbg(&pdev->dev, "no mmio resource defined\n");
8983 + ret = -ENXIO;
8984 + goto out;
8985 + }
8986 +
8987 + irq = platform_get_irq(pdev, 0);
8988 + if (irq < 0) {
8989 + dev_dbg(&pdev->dev, "could not get irq\n");
8990 + ret = -ENXIO;
8991 + goto out;
8992 + }
8993 +
8994 + ret = request_irq(irq, at32_rtc_interrupt, IRQF_SHARED, "rtc", rtc);
8995 + if (ret) {
8996 + dev_dbg(&pdev->dev, "could not request irq %d\n", irq);
8997 + goto out;
8998 + }
8999 +
9000 + rtc->irq = irq;
9001 + rtc->regs = ioremap(regs->start, regs->end - regs->start + 1);
9002 + if (!rtc->regs) {
9003 + ret = -ENOMEM;
9004 + dev_dbg(&pdev->dev, "could not map I/O memory\n");
9005 + goto out_free_irq;
9006 + }
9007 + spin_lock_init(&rtc->lock);
9008 +
9009 + /*
9010 + * Maybe init RTC: count from zero at 1 Hz, disable wrap irq.
9011 + *
9012 + * Do not reset VAL register, as it can hold an old time
9013 + * from last JTAG reset.
9014 + */
9015 + if (!(rtc_readl(rtc, CTRL) & RTC_BIT(CTRL_EN))) {
9016 + rtc_writel(rtc, CTRL, RTC_BIT(CTRL_PCLR));
9017 + rtc_writel(rtc, IDR, RTC_BIT(IDR_TOPI));
9018 + rtc_writel(rtc, CTRL, RTC_BF(CTRL_PSEL, 0xe)
9019 + | RTC_BIT(CTRL_EN));
9020 + }
9021 +
9022 + rtc->rtc = rtc_device_register(pdev->name, &pdev->dev,
9023 + &at32_rtc_ops, THIS_MODULE);
9024 + if (IS_ERR(rtc->rtc)) {
9025 + dev_dbg(&pdev->dev, "could not register rtc device\n");
9026 + ret = PTR_ERR(rtc->rtc);
9027 + goto out_iounmap;
9028 + }
9029 +
9030 + platform_set_drvdata(pdev, rtc);
9031 +
9032 + dev_info(&pdev->dev, "Atmel RTC for AT32AP700x at %08lx irq %ld\n",
9033 + (unsigned long)rtc->regs, rtc->irq);
9034 +
9035 + return 0;
9036 +
9037 +out_iounmap:
9038 + iounmap(rtc->regs);
9039 +out_free_irq:
9040 + free_irq(irq, rtc);
9041 +out:
9042 + kfree(rtc);
9043 + return ret;
9044 +}
9045 +
9046 +static int __exit at32_rtc_remove(struct platform_device *pdev)
9047 +{
9048 + struct rtc_at32ap700x *rtc = platform_get_drvdata(pdev);
9049 +
9050 + free_irq(rtc->irq, rtc);
9051 + iounmap(rtc->regs);
9052 + rtc_device_unregister(rtc->rtc);
9053 + kfree(rtc);
9054 + platform_set_drvdata(pdev, NULL);
9055 +
9056 + return 0;
9057 +}
9058 +
9059 +MODULE_ALIAS("at32ap700x_rtc");
9060 +
9061 +static struct platform_driver at32_rtc_driver = {
9062 + .remove = __exit_p(at32_rtc_remove),
9063 + .driver = {
9064 + .name = "at32ap700x_rtc",
9065 + .owner = THIS_MODULE,
9066 + },
9067 +};
9068 +
9069 +static int __init at32_rtc_init(void)
9070 +{
9071 + return platform_driver_probe(&at32_rtc_driver, at32_rtc_probe);
9072 +}
9073 +module_init(at32_rtc_init);
9074 +
9075 +static void __exit at32_rtc_exit(void)
9076 +{
9077 + platform_driver_unregister(&at32_rtc_driver);
9078 +}
9079 +module_exit(at32_rtc_exit);
9080 +
9081 +MODULE_AUTHOR("Hans-Christian Egtvedt <hcegtvedt@atmel.com>");
9082 +MODULE_DESCRIPTION("Real time clock for AVR32 AT32AP700x");
9083 +MODULE_LICENSE("GPL");
9084 diff --git a/drivers/serial/atmel_serial.c b/drivers/serial/atmel_serial.c
9085 index 3320bcd..4d6b3c5 100644
9086 --- a/drivers/serial/atmel_serial.c
9087 +++ b/drivers/serial/atmel_serial.c
9088 @@ -114,6 +114,7 @@ struct atmel_uart_port {
9089 struct uart_port uart; /* uart */
9090 struct clk *clk; /* uart clock */
9091 unsigned short suspended; /* is port suspended? */
9092 + int break_active; /* break being received */
9093 };
9094
9095 static struct atmel_uart_port atmel_ports[ATMEL_MAX_UART];
9096 @@ -252,6 +253,7 @@ static void atmel_break_ctl(struct uart_port *port, int break_state)
9097 */
9098 static void atmel_rx_chars(struct uart_port *port)
9099 {
9100 + struct atmel_uart_port *atmel_port = (struct atmel_uart_port *) port;
9101 struct tty_struct *tty = port->info->tty;
9102 unsigned int status, ch, flg;
9103
9104 @@ -267,13 +269,29 @@ static void atmel_rx_chars(struct uart_port *port)
9105 * note that the error handling code is
9106 * out of the main execution path
9107 */
9108 - if (unlikely(status & (ATMEL_US_PARE | ATMEL_US_FRAME | ATMEL_US_OVRE | ATMEL_US_RXBRK))) {
9109 + if (unlikely(status & (ATMEL_US_PARE | ATMEL_US_FRAME
9110 + | ATMEL_US_OVRE | ATMEL_US_RXBRK)
9111 + || atmel_port->break_active)) {
9112 UART_PUT_CR(port, ATMEL_US_RSTSTA); /* clear error */
9113 - if (status & ATMEL_US_RXBRK) {
9114 + if (status & ATMEL_US_RXBRK
9115 + && !atmel_port->break_active) {
9116 status &= ~(ATMEL_US_PARE | ATMEL_US_FRAME); /* ignore side-effect */
9117 port->icount.brk++;
9118 + atmel_port->break_active = 1;
9119 + UART_PUT_IER(port, ATMEL_US_RXBRK);
9120 if (uart_handle_break(port))
9121 goto ignore_char;
9122 + } else {
9123 + /*
9124 + * This is either the end-of-break
9125 + * condition or we've received at
9126 + * least one character without RXBRK
9127 + * being set. In both cases, the next
9128 + * RXBRK will indicate start-of-break.
9129 + */
9130 + UART_PUT_IDR(port, ATMEL_US_RXBRK);
9131 + status &= ~ATMEL_US_RXBRK;
9132 + atmel_port->break_active = 0;
9133 }
9134 if (status & ATMEL_US_PARE)
9135 port->icount.parity++;
9136 @@ -352,6 +370,16 @@ static irqreturn_t atmel_interrupt(int irq, void *dev_id)
9137 /* Interrupt receive */
9138 if (pending & ATMEL_US_RXRDY)
9139 atmel_rx_chars(port);
9140 + else if (pending & ATMEL_US_RXBRK) {
9141 + /*
9142 + * End of break detected. If it came along
9143 + * with a character, atmel_rx_chars will
9144 + * handle it.
9145 + */
9146 + UART_PUT_CR(port, ATMEL_US_RSTSTA);
9147 + UART_PUT_IDR(port, ATMEL_US_RXBRK);
9148 + atmel_port->break_active = 0;
9149 + }
9150
9151 // TODO: All reads to CSR will clear these interrupts!
9152 if (pending & ATMEL_US_RIIC) port->icount.rng++;
9153 diff --git a/drivers/spi/atmel_spi.c b/drivers/spi/atmel_spi.c
9154 index 8b2601d..8f5453f 100644
9155 --- a/drivers/spi/atmel_spi.c
9156 +++ b/drivers/spi/atmel_spi.c
9157 @@ -412,8 +412,8 @@ static int atmel_spi_setup(struct spi_device *spi)
9158 csr |= SPI_BIT(NCPHA);
9159
9160 /* TODO: DLYBS and DLYBCT */
9161 - csr |= SPI_BF(DLYBS, 10);
9162 - csr |= SPI_BF(DLYBCT, 10);
9163 + csr |= SPI_BF(DLYBS, 0);
9164 + csr |= SPI_BF(DLYBCT, 0);
9165
9166 /* chipselect must have been muxed as GPIO (e.g. in board setup) */
9167 npcs_pin = (unsigned int)spi->controller_data;
9168 diff --git a/drivers/usb/gadget/Kconfig b/drivers/usb/gadget/Kconfig
9169 index f771a7c..0c3d55b 100644
9170 --- a/drivers/usb/gadget/Kconfig
9171 +++ b/drivers/usb/gadget/Kconfig
9172 @@ -175,6 +175,19 @@ config USB_LH7A40X
9173 default USB_GADGET
9174 select USB_GADGET_SELECTED
9175
9176 +config USB_GADGET_ATMEL_USBA
9177 + boolean "Atmel USBA"
9178 + select USB_GADGET_DUALSPEED
9179 + depends on AVR32
9180 + help
9181 + USBA is the integrated high-speed USB Device controller on
9182 + the AT32AP700x processors from Atmel.
9183 +
9184 +config USB_ATMEL_USBA
9185 + tristate
9186 + depends on USB_GADGET_ATMEL_USBA
9187 + default USB_GADGET
9188 + select USB_GADGET_SELECTED
9189
9190 config USB_GADGET_OMAP
9191 boolean "OMAP USB Device Controller"
9192 diff --git a/drivers/usb/gadget/Makefile b/drivers/usb/gadget/Makefile
9193 index 5db1939..c28da01 100644
9194 --- a/drivers/usb/gadget/Makefile
9195 +++ b/drivers/usb/gadget/Makefile
9196 @@ -8,6 +8,7 @@ obj-$(CONFIG_USB_GOKU) += goku_udc.o
9197 obj-$(CONFIG_USB_OMAP) += omap_udc.o
9198 obj-$(CONFIG_USB_LH7A40X) += lh7a40x_udc.o
9199 obj-$(CONFIG_USB_AT91) += at91_udc.o
9200 +obj-$(CONFIG_USB_ATMEL_USBA) += atmel_usba_udc.o
9201 obj-$(CONFIG_USB_FSL_USB2) += fsl_usb2_udc.o
9202
9203 #
9204 diff --git a/drivers/usb/gadget/atmel_usba_udc.c b/drivers/usb/gadget/atmel_usba_udc.c
9205 new file mode 100644
9206 index 0000000..34dbae3
9207 --- /dev/null
9208 +++ b/drivers/usb/gadget/atmel_usba_udc.c
9209 @@ -0,0 +1,2072 @@
9210 +/*
9211 + * Driver for the Atmel USBA high speed USB device controller
9212 + *
9213 + * Copyright (C) 2005-2007 Atmel Corporation
9214 + *
9215 + * This program is free software; you can redistribute it and/or modify
9216 + * it under the terms of the GNU General Public License version 2 as
9217 + * published by the Free Software Foundation.
9218 + */
9219 +/* #define DEBUG */
9220 +
9221 +#include <linux/clk.h>
9222 +#include <linux/module.h>
9223 +#include <linux/init.h>
9224 +#include <linux/interrupt.h>
9225 +#include <linux/io.h>
9226 +#include <linux/device.h>
9227 +#include <linux/dma-mapping.h>
9228 +#include <linux/list.h>
9229 +#include <linux/platform_device.h>
9230 +#include <linux/usb/ch9.h>
9231 +#include <linux/usb_gadget.h>
9232 +#include <linux/delay.h>
9233 +
9234 +#include <asm/gpio.h>
9235 +#include <asm/arch/board.h>
9236 +
9237 +#include "atmel_usba_udc.h"
9238 +
9239 +#define DMA_ADDR_INVALID (~(dma_addr_t)0)
9240 +
9241 +#define FIFO_IOMEM_ID 0
9242 +#define CTRL_IOMEM_ID 1
9243 +
9244 +#ifdef DEBUG
9245 +#define DBG_ERR 0x0001 /* report all error returns */
9246 +#define DBG_HW 0x0002 /* debug hardware initialization */
9247 +#define DBG_GADGET 0x0004 /* calls to/from gadget driver */
9248 +#define DBG_INT 0x0008 /* interrupts */
9249 +#define DBG_BUS 0x0010 /* report changes in bus state */
9250 +#define DBG_QUEUE 0x0020 /* debug request queue processing */
9251 +#define DBG_FIFO 0x0040 /* debug FIFO contents */
9252 +#define DBG_DMA 0x0080 /* debug DMA handling */
9253 +#define DBG_REQ 0x0100 /* print out queued request length */
9254 +#define DBG_ALL 0xffff
9255 +#define DBG_NONE 0x0000
9256 +
9257 +#define DEBUG_LEVEL (DBG_ERR)
9258 +#define DBG(level, fmt, ...) \
9259 + do { \
9260 + if ((level) & DEBUG_LEVEL) \
9261 + printk(KERN_DEBUG "udc: " fmt, ## __VA_ARGS__); \
9262 + } while (0)
9263 +#else
9264 +#define DBG(level, fmt...)
9265 +#endif
9266 +
9267 +static struct usba_udc the_udc;
9268 +
9269 +#ifdef CONFIG_DEBUG_FS
9270 +#include <linux/debugfs.h>
9271 +#include <linux/uaccess.h>
9272 +
9273 +static int queue_dbg_open(struct inode *inode, struct file *file)
9274 +{
9275 + struct usba_ep *ep = inode->i_private;
9276 + struct usba_request *req, *req_copy;
9277 + struct list_head *queue_data;
9278 +
9279 + queue_data = kmalloc(sizeof(*queue_data), GFP_KERNEL);
9280 + if (!queue_data)
9281 + return -ENOMEM;
9282 + INIT_LIST_HEAD(queue_data);
9283 +
9284 + spin_lock_irq(&ep->udc->lock);
9285 + list_for_each_entry(req, &ep->queue, queue) {
9286 + req_copy = kmalloc(sizeof(*req_copy), GFP_ATOMIC);
9287 + if (!req_copy)
9288 + goto fail;
9289 + memcpy(req_copy, req, sizeof(*req_copy));
9290 + list_add_tail(&req_copy->queue, queue_data);
9291 + }
9292 + spin_unlock_irq(&ep->udc->lock);
9293 +
9294 + file->private_data = queue_data;
9295 + return 0;
9296 +
9297 +fail:
9298 + spin_unlock_irq(&ep->udc->lock);
9299 + list_for_each_entry_safe(req, req_copy, queue_data, queue) {
9300 + list_del(&req->queue);
9301 + kfree(req);
9302 + }
9303 + kfree(queue_data);
9304 + return -ENOMEM;
9305 +}
9306 +
9307 +/*
9308 + * bbbbbbbb llllllll IZS sssss nnnn FDL\n\0
9309 + *
9310 + * b: buffer address
9311 + * l: buffer length
9312 + * I/i: interrupt/no interrupt
9313 + * Z/z: zero/no zero
9314 + * S/s: short ok/short not ok
9315 + * s: status
9316 + * n: nr_packets
9317 + * F/f: submitted/not submitted to FIFO
9318 + * D/d: using/not using DMA
9319 + * L/l: last transaction/not last transaction
9320 + */
9321 +static ssize_t queue_dbg_read(struct file *file, char __user *buf,
9322 + size_t nbytes, loff_t *ppos)
9323 +{
9324 + struct list_head *queue = file->private_data;
9325 + struct usba_request *req, *tmp_req;
9326 + size_t len, remaining, actual = 0;
9327 + char tmpbuf[38];
9328 +
9329 + if (!access_ok(VERIFY_WRITE, buf, nbytes))
9330 + return -EFAULT;
9331 +
9332 + mutex_lock(&file->f_dentry->d_inode->i_mutex);
9333 + list_for_each_entry_safe(req, tmp_req, queue, queue) {
9334 + len = snprintf(tmpbuf, sizeof(tmpbuf),
9335 + "%8p %08x %c%c%c %5d %c%c%c\n",
9336 + req->req.buf, req->req.length,
9337 + req->req.no_interrupt ? 'i' : 'I',
9338 + req->req.zero ? 'Z' : 'z',
9339 + req->req.short_not_ok ? 's' : 'S',
9340 + req->req.status,
9341 + req->submitted ? 'F' : 'f',
9342 + req->using_dma ? 'D' : 'd',
9343 + req->last_transaction ? 'L' : 'l');
9344 + len = min(len, sizeof(tmpbuf));
9345 + if (len > nbytes)
9346 + break;
9347 +
9348 + list_del(&req->queue);
9349 + kfree(req);
9350 +
9351 + remaining = __copy_to_user(buf, tmpbuf, len);
9352 + actual += len - remaining;
9353 + if (remaining)
9354 + break;
9355 +
9356 + nbytes -= len;
9357 + buf += len;
9358 + }
9359 + mutex_unlock(&file->f_dentry->d_inode->i_mutex);
9360 +
9361 + return actual;
9362 +}
9363 +
9364 +static int queue_dbg_release(struct inode *inode, struct file *file)
9365 +{
9366 + struct list_head *queue_data = file->private_data;
9367 + struct usba_request *req, *tmp_req;
9368 +
9369 + list_for_each_entry_safe(req, tmp_req, queue_data, queue) {
9370 + list_del(&req->queue);
9371 + kfree(req);
9372 + }
9373 + kfree(queue_data);
9374 + return 0;
9375 +}
9376 +
9377 +static int regs_dbg_open(struct inode *inode, struct file *file)
9378 +{
9379 + struct usba_udc *udc;
9380 + unsigned int i;
9381 + u32 *data;
9382 + int ret = -ENOMEM;
9383 +
9384 + mutex_lock(&inode->i_mutex);
9385 + udc = inode->i_private;
9386 + data = kmalloc(inode->i_size, GFP_KERNEL);
9387 + if (!data)
9388 + goto out;
9389 +
9390 + spin_lock_irq(&udc->lock);
9391 + for (i = 0; i < inode->i_size / 4; i++)
9392 + data[i] = __raw_readl(udc->regs + i * 4);
9393 + spin_unlock_irq(&udc->lock);
9394 +
9395 + file->private_data = data;
9396 + ret = 0;
9397 +
9398 +out:
9399 + mutex_unlock(&inode->i_mutex);
9400 +
9401 + return ret;
9402 +}
9403 +
9404 +static ssize_t regs_dbg_read(struct file *file, char __user *buf,
9405 + size_t nbytes, loff_t *ppos)
9406 +{
9407 + struct inode *inode = file->f_dentry->d_inode;
9408 + int ret;
9409 +
9410 + mutex_lock(&inode->i_mutex);
9411 + ret = simple_read_from_buffer(buf, nbytes, ppos,
9412 + file->private_data,
9413 + file->f_dentry->d_inode->i_size);
9414 + mutex_unlock(&inode->i_mutex);
9415 +
9416 + return ret;
9417 +}
9418 +
9419 +static int regs_dbg_release(struct inode *inode, struct file *file)
9420 +{
9421 + kfree(file->private_data);
9422 + return 0;
9423 +}
9424 +
9425 +const struct file_operations queue_dbg_fops = {
9426 + .owner = THIS_MODULE,
9427 + .open = queue_dbg_open,
9428 + .llseek = no_llseek,
9429 + .read = queue_dbg_read,
9430 + .release = queue_dbg_release,
9431 +};
9432 +
9433 +const struct file_operations regs_dbg_fops = {
9434 + .owner = THIS_MODULE,
9435 + .open = regs_dbg_open,
9436 + .llseek = generic_file_llseek,
9437 + .read = regs_dbg_read,
9438 + .release = regs_dbg_release,
9439 +};
9440 +
9441 +static void usba_ep_init_debugfs(struct usba_udc *udc,
9442 + struct usba_ep *ep)
9443 +{
9444 + struct dentry *ep_root;
9445 +
9446 + ep_root = debugfs_create_dir(ep_name(ep), udc->debugfs_root);
9447 + if (!ep_root)
9448 + goto err_root;
9449 + ep->debugfs_dir = ep_root;
9450 +
9451 + ep->debugfs_queue = debugfs_create_file("queue", 0400, ep_root,
9452 + ep, &queue_dbg_fops);
9453 + if (!ep->debugfs_queue)
9454 + goto err_queue;
9455 +
9456 + if (ep_can_dma(ep)) {
9457 + ep->debugfs_dma_status
9458 + = debugfs_create_u32("dma_status", 0400, ep_root,
9459 + &ep->last_dma_status);
9460 + if (!ep->debugfs_dma_status)
9461 + goto err_dma_status;
9462 + }
9463 + if (ep_is_control(ep)) {
9464 + ep->debugfs_state
9465 + = debugfs_create_u32("state", 0400, ep_root,
9466 + &ep->state);
9467 + if (!ep->debugfs_state)
9468 + goto err_state;
9469 + }
9470 +
9471 + return;
9472 +
9473 +err_state:
9474 + if (ep_can_dma(ep))
9475 + debugfs_remove(ep->debugfs_dma_status);
9476 +err_dma_status:
9477 + debugfs_remove(ep->debugfs_queue);
9478 +err_queue:
9479 + debugfs_remove(ep_root);
9480 +err_root:
9481 + dev_err(&ep->udc->pdev->dev,
9482 + "failed to create debugfs directory for %s\n", ep_name(ep));
9483 +}
9484 +
9485 +static void usba_ep_cleanup_debugfs(struct usba_ep *ep)
9486 +{
9487 + debugfs_remove(ep->debugfs_queue);
9488 + debugfs_remove(ep->debugfs_dma_status);
9489 + debugfs_remove(ep->debugfs_state);
9490 + debugfs_remove(ep->debugfs_dir);
9491 + ep->debugfs_dma_status = NULL;
9492 + ep->debugfs_dir = NULL;
9493 +}
9494 +
9495 +static void usba_init_debugfs(struct usba_udc *udc)
9496 +{
9497 + struct dentry *root, *regs;
9498 + struct resource *regs_resource;
9499 +
9500 + root = debugfs_create_dir(udc->gadget.name, NULL);
9501 + if (IS_ERR(root) || !root)
9502 + goto err_root;
9503 + udc->debugfs_root = root;
9504 +
9505 + regs = debugfs_create_file("regs", 0400, root, udc, &regs_dbg_fops);
9506 + if (!regs)
9507 + goto err_regs;
9508 +
9509 + regs_resource = platform_get_resource(udc->pdev, IORESOURCE_MEM,
9510 + CTRL_IOMEM_ID);
9511 + regs->d_inode->i_size = regs_resource->end - regs_resource->start + 1;
9512 + udc->debugfs_regs = regs;
9513 +
9514 + usba_ep_init_debugfs(udc, to_usba_ep(udc->gadget.ep0));
9515 +
9516 + return;
9517 +
9518 +err_regs:
9519 + debugfs_remove(root);
9520 +err_root:
9521 + udc->debugfs_root = NULL;
9522 + dev_err(&udc->pdev->dev, "debugfs is not available\n");
9523 +}
9524 +
9525 +static void usba_cleanup_debugfs(struct usba_udc *udc)
9526 +{
9527 + usba_ep_cleanup_debugfs(to_usba_ep(udc->gadget.ep0));
9528 + debugfs_remove(udc->debugfs_regs);
9529 + debugfs_remove(udc->debugfs_root);
9530 + udc->debugfs_regs = NULL;
9531 + udc->debugfs_root = NULL;
9532 +}
9533 +#else
9534 +static inline void usba_ep_init_debugfs(struct usba_udc *udc,
9535 + struct usba_ep *ep)
9536 +{
9537 +
9538 +}
9539 +
9540 +static inline void usba_ep_cleanup_debugfs(struct usba_ep *ep)
9541 +{
9542 +
9543 +}
9544 +
9545 +static inline void usba_init_debugfs(struct usba_udc *udc)
9546 +{
9547 +
9548 +}
9549 +
9550 +static inline void usba_cleanup_debugfs(struct usba_udc *udc)
9551 +{
9552 +
9553 +}
9554 +#endif
9555 +
9556 +static int vbus_is_present(struct usba_udc *udc)
9557 +{
9558 + if (udc->vbus_pin != -1)
9559 + return gpio_get_value(udc->vbus_pin);
9560 +
9561 + /* No Vbus detection: Assume always present */
9562 + return 1;
9563 +}
9564 +
9565 +static void copy_to_fifo(void __iomem *fifo, const void *buf, int len)
9566 +{
9567 + unsigned long tmp;
9568 +
9569 + DBG(DBG_FIFO, "copy to FIFO (len %d):\n", len);
9570 + for (; len > 0; len -= 4, buf += 4, fifo += 4) {
9571 + tmp = *(unsigned long *)buf;
9572 + if (len >= 4) {
9573 + DBG(DBG_FIFO, " -> %08lx\n", tmp);
9574 + __raw_writel(tmp, fifo);
9575 + } else {
9576 + do {
9577 + DBG(DBG_FIFO, " -> %02lx\n", tmp >> 24);
9578 + __raw_writeb(tmp >> 24, fifo);
9579 + fifo++;
9580 + tmp <<= 8;
9581 + } while (--len);
9582 + break;
9583 + }
9584 + }
9585 +}
9586 +
9587 +static void copy_from_fifo(void *buf, void __iomem *fifo, int len)
9588 +{
9589 + union {
9590 + unsigned long *w;
9591 + unsigned char *b;
9592 + } p;
9593 + unsigned long tmp;
9594 +
9595 + DBG(DBG_FIFO, "copy from FIFO (len %d):\n", len);
9596 + for (p.w = buf; len > 0; len -= 4, p.w++, fifo += 4) {
9597 + if (len >= 4) {
9598 + tmp = __raw_readl(fifo);
9599 + *p.w = tmp;
9600 + DBG(DBG_FIFO, " -> %08lx\n", tmp);
9601 + } else {
9602 + do {
9603 + tmp = __raw_readb(fifo);
9604 + *p.b = tmp;
9605 + DBG(DBG_FIFO, " -> %02lx\n", tmp);
9606 + fifo++, p.b++;
9607 + } while (--len);
9608 + }
9609 + }
9610 +}
9611 +
9612 +static void next_fifo_transaction(struct usba_ep *ep,
9613 + struct usba_request *req)
9614 +{
9615 + unsigned int transaction_len;
9616 +
9617 + transaction_len = req->req.length - req->req.actual;
9618 + req->last_transaction = 1;
9619 + if (transaction_len > ep->ep.maxpacket) {
9620 + transaction_len = ep->ep.maxpacket;
9621 + req->last_transaction = 0;
9622 + } else if (transaction_len == ep->ep.maxpacket
9623 + && req->req.zero) {
9624 + req->last_transaction = 0;
9625 + }
9626 + DBG(DBG_QUEUE, "%s: submit_transaction, req %p (length %d)%s\n",
9627 + ep_name(ep), req, transaction_len,
9628 + req->last_transaction ? ", done" : "");
9629 +
9630 + copy_to_fifo(ep->fifo, req->req.buf + req->req.actual, transaction_len);
9631 + usba_ep_writel(ep, SET_STA, USBA_BIT(TX_PK_RDY));
9632 + req->req.actual += transaction_len;
9633 +}
9634 +
9635 +static void submit_request(struct usba_ep *ep, struct usba_request *req)
9636 +{
9637 + DBG(DBG_QUEUE, "%s: submit_request: req %p (length %d)\n",
9638 + ep_name(ep), req, req->req.length);
9639 +
9640 + req->req.actual = 0;
9641 + req->submitted = 1;
9642 +
9643 + if (req->using_dma) {
9644 + if (req->req.length == 0) {
9645 + usba_ep_writel(ep, CTL_ENB, USBA_BIT(TX_PK_RDY));
9646 + return;
9647 + }
9648 +
9649 + if (req->req.zero)
9650 + usba_ep_writel(ep, CTL_ENB, USBA_BIT(SHORT_PACKET));
9651 + else
9652 + usba_ep_writel(ep, CTL_DIS, USBA_BIT(SHORT_PACKET));
9653 +
9654 + usba_dma_writel(ep, ADDRESS, req->req.dma);
9655 + usba_dma_writel(ep, CONTROL, req->ctrl);
9656 + } else {
9657 + next_fifo_transaction(ep, req);
9658 + if (req->last_transaction) {
9659 + usba_ep_writel(ep, CTL_DIS, USBA_BIT(TX_PK_RDY));
9660 + usba_ep_writel(ep, CTL_ENB, USBA_BIT(TX_COMPLETE));
9661 + } else {
9662 + usba_ep_writel(ep, CTL_DIS, USBA_BIT(TX_COMPLETE));
9663 + usba_ep_writel(ep, CTL_ENB, USBA_BIT(TX_PK_RDY));
9664 + }
9665 + }
9666 +}
9667 +
9668 +static void submit_next_request(struct usba_ep *ep)
9669 +{
9670 + struct usba_request *req;
9671 +
9672 + if (list_empty(&ep->queue)) {
9673 + usba_ep_writel(ep, CTL_DIS, (USBA_BIT(TX_PK_RDY)
9674 + | USBA_BIT(RX_BK_RDY)));
9675 + return;
9676 + }
9677 +
9678 + req = list_entry(ep->queue.next, struct usba_request, queue);
9679 + if (!req->submitted)
9680 + submit_request(ep, req);
9681 +}
9682 +
9683 +static void send_status(struct usba_udc *udc, struct usba_ep *ep)
9684 +{
9685 + ep->state = STATUS_STAGE_IN;
9686 + usba_ep_writel(ep, SET_STA, USBA_BIT(TX_PK_RDY));
9687 + usba_ep_writel(ep, CTL_ENB, USBA_BIT(TX_COMPLETE));
9688 +}
9689 +
9690 +static void receive_data(struct usba_ep *ep)
9691 +{
9692 + struct usba_udc *udc = ep->udc;
9693 + struct usba_request *req;
9694 + unsigned long status;
9695 + unsigned int bytecount, nr_busy;
9696 + int is_complete = 0;
9697 +
9698 + status = usba_ep_readl(ep, STA);
9699 + nr_busy = USBA_BFEXT(BUSY_BANKS, status);
9700 +
9701 + DBG(DBG_QUEUE, "receive data: nr_busy=%u\n", nr_busy);
9702 +
9703 + while (nr_busy > 0) {
9704 + if (list_empty(&ep->queue)) {
9705 + usba_ep_writel(ep, CTL_DIS, USBA_BIT(RX_BK_RDY));
9706 + break;
9707 + }
9708 + req = list_entry(ep->queue.next,
9709 + struct usba_request, queue);
9710 +
9711 + bytecount = USBA_BFEXT(BYTE_COUNT, status);
9712 +
9713 + if (status & (1 << 31))
9714 + is_complete = 1;
9715 + if (req->req.actual + bytecount >= req->req.length) {
9716 + is_complete = 1;
9717 + bytecount = req->req.length - req->req.actual;
9718 + }
9719 +
9720 + copy_from_fifo(req->req.buf + req->req.actual,
9721 + ep->fifo, bytecount);
9722 + req->req.actual += bytecount;
9723 +
9724 + usba_ep_writel(ep, CLR_STA, USBA_BIT(RX_BK_RDY));
9725 +
9726 + if (is_complete) {
9727 + DBG(DBG_QUEUE, "%s: request done\n", ep_name(ep));
9728 + req->req.status = 0;
9729 + list_del_init(&req->queue);
9730 + usba_ep_writel(ep, CTL_DIS, USBA_BIT(RX_BK_RDY));
9731 + req->req.complete(&ep->ep, &req->req);
9732 + }
9733 +
9734 + status = usba_ep_readl(ep, STA);
9735 + nr_busy = USBA_BFEXT(BUSY_BANKS, status);
9736 +
9737 + if (is_complete && ep_is_control(ep)) {
9738 + send_status(udc, ep);
9739 + break;
9740 + }
9741 + }
9742 +}
9743 +
9744 +static void request_complete(struct usba_ep *ep,
9745 + struct usba_request *req,
9746 + int status)
9747 +{
9748 + struct usba_udc *udc = ep->udc;
9749 +
9750 + WARN_ON(!list_empty(&req->queue));
9751 +
9752 + if (req->req.status == -EINPROGRESS)
9753 + req->req.status = status;
9754 +
9755 + if (req->mapped) {
9756 + dma_unmap_single(
9757 + &udc->pdev->dev, req->req.dma, req->req.length,
9758 + ep_is_in(ep) ? DMA_TO_DEVICE : DMA_FROM_DEVICE);
9759 + req->req.dma = DMA_ADDR_INVALID;
9760 + req->mapped = 0;
9761 + }
9762 +
9763 + DBG(DBG_GADGET | DBG_REQ,
9764 + "%s: req %p complete: status %d, actual %u\n",
9765 + ep_name(ep), req, req->req.status, req->req.actual);
9766 + req->req.complete(&ep->ep, &req->req);
9767 +}
9768 +
9769 +static void request_complete_list(struct usba_ep *ep,
9770 + struct list_head *list,
9771 + int status)
9772 +{
9773 + struct usba_request *req, *tmp_req;
9774 +
9775 + list_for_each_entry_safe(req, tmp_req, list, queue) {
9776 + list_del_init(&req->queue);
9777 + request_complete(ep, req, status);
9778 + }
9779 +}
9780 +
9781 +static int usba_ep_enable(struct usb_ep *_ep,
9782 + const struct usb_endpoint_descriptor *desc)
9783 +{
9784 + struct usba_ep *ep = to_usba_ep(_ep);
9785 + struct usba_udc *udc = ep->udc;
9786 + unsigned long flags, ept_cfg, maxpacket;
9787 +
9788 + DBG(DBG_GADGET, "%s: ep_enable: desc=%p\n", ep_name(ep), desc);
9789 +
9790 + maxpacket = le16_to_cpu(desc->wMaxPacketSize);
9791 +
9792 + if (ep->index == 0
9793 + || desc->bDescriptorType != USB_DT_ENDPOINT
9794 + || ((desc->bEndpointAddress & USB_ENDPOINT_NUMBER_MASK)
9795 + != ep->index)
9796 + || maxpacket == 0
9797 + || maxpacket > ep->fifo_size) {
9798 + DBG(DBG_ERR, "ep_enable: Invalid argument");
9799 + return -EINVAL;
9800 + }
9801 +
9802 + ep->is_isoc = 0;
9803 + ep->is_in = 0;
9804 +
9805 + if ((desc->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK)
9806 + == USB_ENDPOINT_XFER_ISOC) {
9807 + if (!ep->can_isoc) {
9808 + DBG(DBG_ERR, "ep_enable: %s is not isoc capable\n",
9809 + ep_name(ep));
9810 + return -EINVAL;
9811 + }
9812 + ep->is_isoc = 1;
9813 + }
9814 +
9815 + if (maxpacket <= 8)
9816 + ept_cfg = USBA_BF(EPT_SIZE, USBA_EPT_SIZE_8);
9817 + else
9818 + /* LSB is bit 1, not 0 */
9819 + ept_cfg = USBA_BF(EPT_SIZE, fls(maxpacket - 1) - 3);
9820 + DBG(DBG_HW, "%s: EPT_SIZE = %lu (maxpacket = %lu)\n",
9821 + ep_name(ep), ept_cfg, maxpacket);
9822 +
9823 + if ((desc->bEndpointAddress & USB_ENDPOINT_DIR_MASK) == USB_DIR_IN) {
9824 + ep->is_in = 1;
9825 + ept_cfg |= USBA_BIT(EPT_DIR);
9826 + }
9827 +
9828 + switch (desc->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) {
9829 + case USB_ENDPOINT_XFER_CONTROL:
9830 + ept_cfg |= USBA_BF(EPT_TYPE, USBA_EPT_TYPE_CONTROL);
9831 + break;
9832 + case USB_ENDPOINT_XFER_ISOC:
9833 + ept_cfg |= USBA_BF(EPT_TYPE, USBA_EPT_TYPE_ISO);
9834 + break;
9835 + case USB_ENDPOINT_XFER_BULK:
9836 + ept_cfg |= USBA_BF(EPT_TYPE, USBA_EPT_TYPE_BULK);
9837 + break;
9838 + case USB_ENDPOINT_XFER_INT:
9839 + ept_cfg |= USBA_BF(EPT_TYPE, USBA_EPT_TYPE_INT);
9840 + break;
9841 + }
9842 + ept_cfg |= USBA_BF(BK_NUMBER, ep->nr_banks);
9843 +
9844 + spin_lock_irqsave(&ep->udc->lock, flags);
9845 +
9846 + if (ep->desc) {
9847 + spin_unlock_irqrestore(&ep->udc->lock, flags);
9848 + DBG(DBG_ERR, "ep%d already enabled\n", ep->index);
9849 + return -EBUSY;
9850 + }
9851 +
9852 + ep->desc = desc;
9853 + ep->ep.maxpacket = maxpacket;
9854 +
9855 + usba_ep_writel(ep, CFG, ept_cfg);
9856 + usba_ep_writel(ep, CTL_ENB, USBA_BIT(EPT_ENABLE));
9857 +
9858 + if (ep_can_dma(ep)) {
9859 + u32 ctrl;
9860 +
9861 + usba_writel(udc, INT_ENB,
9862 + (usba_readl(udc, INT_ENB)
9863 + | USBA_BF(EPT_INT, 1 << ep->index)
9864 + | USBA_BF(DMA_INT, 1 << ep->index)));
9865 + ctrl = USBA_BIT(AUTO_VALID) | USBA_BIT(INTDIS_DMA);
9866 + usba_ep_writel(ep, CTL_ENB, ctrl);
9867 + } else {
9868 + usba_writel(udc, INT_ENB,
9869 + (usba_readl(udc, INT_ENB)
9870 + | USBA_BF(EPT_INT, 1 << ep->index)));
9871 + }
9872 +
9873 + spin_unlock_irqrestore(&udc->lock, flags);
9874 +
9875 + DBG(DBG_HW, "EPT_CFG%d after init: %#08lx\n", ep->index,
9876 + (unsigned long)usba_ep_readl(ep, CFG));
9877 + DBG(DBG_HW, "INT_ENB after init: %#08lx\n",
9878 + (unsigned long)usba_readl(udc, INT_ENB));
9879 +
9880 + return 0;
9881 +}
9882 +
9883 +static int usba_ep_disable(struct usb_ep *_ep)
9884 +{
9885 + struct usba_ep *ep = to_usba_ep(_ep);
9886 + struct usba_udc *udc = ep->udc;
9887 + LIST_HEAD(req_list);
9888 + unsigned long flags;
9889 +
9890 + DBG(DBG_GADGET, "ep_disable: %s\n", ep_name(ep));
9891 +
9892 + spin_lock_irqsave(&udc->lock, flags);
9893 +
9894 + if (!ep->desc) {
9895 + spin_unlock_irqrestore(&udc->lock, flags);
9896 + DBG(DBG_ERR, "ep_disable: %s not enabled\n",
9897 + ep_name(ep));
9898 + return -EINVAL;
9899 + }
9900 + ep->desc = NULL;
9901 +
9902 + list_splice_init(&ep->queue, &req_list);
9903 + if (ep_can_dma(ep)) {
9904 + usba_dma_writel(ep, CONTROL, 0);
9905 + usba_dma_writel(ep, ADDRESS, 0);
9906 + usba_dma_readl(ep, STATUS);
9907 + }
9908 + usba_ep_writel(ep, CTL_DIS, USBA_BIT(EPT_ENABLE));
9909 + usba_writel(udc, INT_ENB, (usba_readl(udc, INT_ENB)
9910 + & ~USBA_BF(EPT_INT, 1 << ep->index)));
9911 +
9912 + spin_unlock_irqrestore(&udc->lock, flags);
9913 +
9914 + request_complete_list(ep, &req_list, -ESHUTDOWN);
9915 +
9916 + return 0;
9917 +}
9918 +
9919 +static struct usb_request *
9920 +usba_ep_alloc_request(struct usb_ep *_ep, unsigned gfp_flags)
9921 +{
9922 + struct usba_request *req;
9923 +
9924 + DBG(DBG_GADGET, "ep_alloc_request: %p, 0x%x\n", _ep, gfp_flags);
9925 +
9926 + req = kzalloc(sizeof(*req), gfp_flags);
9927 + if (!req)
9928 + return NULL;
9929 +
9930 + INIT_LIST_HEAD(&req->queue);
9931 + req->req.dma = DMA_ADDR_INVALID;
9932 +
9933 + return &req->req;
9934 +}
9935 +
9936 +static void
9937 +usba_ep_free_request(struct usb_ep *_ep, struct usb_request *_req)
9938 +{
9939 + struct usba_request *req = to_usba_req(_req);
9940 +
9941 + DBG(DBG_GADGET, "ep_free_request: %p, %p\n", _ep, _req);
9942 +
9943 + kfree(req);
9944 +}
9945 +
9946 +static void *usba_ep_alloc_buffer(struct usb_ep *_ep, unsigned bytes,
9947 + dma_addr_t *dma, unsigned gfp_flags)
9948 +{
9949 + void *buf;
9950 +
9951 + if (bytes < L1_CACHE_BYTES)
9952 + bytes = L1_CACHE_BYTES;
9953 +
9954 + buf = kmalloc(bytes, gfp_flags);
9955 +
9956 + /*
9957 + * Seems like we have to map the buffer any chance we get.
9958 + * ether.c wants us to initialize the dma member of a
9959 + * different request than the one receiving the buffer, so one
9960 + * never knows...
9961 + *
9962 + * Ah, screw it. The ether driver is probably wrong, and this
9963 + * is not the right place to do the mapping. The driver
9964 + * shouldn't mess with our DMA mappings anyway.
9965 + */
9966 + *dma = DMA_ADDR_INVALID;
9967 +
9968 + return buf;
9969 +}
9970 +
9971 +static void usba_ep_free_buffer(struct usb_ep *_ep, void *buf,
9972 + dma_addr_t dma, unsigned bytes)
9973 +{
9974 + DBG(DBG_GADGET, "ep_free_buffer: %s, buf %p (size %u)\n",
9975 + _ep->name, buf, bytes);
9976 + kfree(buf);
9977 +}
9978 +
9979 +static int queue_dma(struct usba_udc *udc, struct usba_ep *ep,
9980 + struct usba_request *req, gfp_t gfp_flags)
9981 +{
9982 + unsigned long flags;
9983 + int ret;
9984 +
9985 + DBG(DBG_DMA, "%s: req l/%u d/%08x %c%c%c\n",
9986 + ep_name(ep), req->req.length, req->req.dma,
9987 + req->req.zero ? 'Z' : 'z',
9988 + req->req.short_not_ok ? 'S' : 's',
9989 + req->req.no_interrupt ? 'I' : 'i');
9990 +
9991 + if (req->req.length > 0x10000) {
9992 + /* Lengths from 0 to 65536 (inclusive) are supported */
9993 + DBG(DBG_ERR, "invalid request length %u\n", req->req.length);
9994 + return -EINVAL;
9995 + }
9996 +
9997 + req->using_dma = 1;
9998 +
9999 + if (req->req.dma == DMA_ADDR_INVALID) {
10000 + req->req.dma = dma_map_single(
10001 + &udc->pdev->dev, req->req.buf, req->req.length,
10002 + ep_is_in(ep) ? DMA_TO_DEVICE : DMA_FROM_DEVICE);
10003 + req->mapped = 1;
10004 + } else {
10005 + dma_sync_single_for_device(
10006 + &udc->pdev->dev, req->req.dma, req->req.length,
10007 + ep_is_in(ep) ? DMA_TO_DEVICE : DMA_FROM_DEVICE);
10008 + req->mapped = 0;
10009 + }
10010 +
10011 + req->ctrl = (USBA_BF(DMA_BUF_LEN, req->req.length)
10012 + | USBA_BIT(DMA_CH_EN) | USBA_BIT(DMA_END_BUF_IE)
10013 + | USBA_BIT(DMA_END_TR_EN) | USBA_BIT(DMA_END_TR_IE));
10014 +
10015 + if (ep_is_in(ep))
10016 + req->ctrl |= USBA_BIT(DMA_END_BUF_EN);
10017 +
10018 + /*
10019 + * Add this request to the queue and submit for DMA if
10020 + * possible. Check if we're still alive first -- we may have
10021 + * received a reset since last time we checked.
10022 + */
10023 + ret = -ESHUTDOWN;
10024 + spin_lock_irqsave(&udc->lock, flags);
10025 + if (ep->desc) {
10026 + if (list_empty(&ep->queue))
10027 + submit_request(ep, req);
10028 +
10029 + list_add_tail(&req->queue, &ep->queue);
10030 + ret = 0;
10031 + }
10032 + spin_unlock_irqrestore(&udc->lock, flags);
10033 +
10034 + return ret;
10035 +}
10036 +
10037 +static int usba_ep_queue(struct usb_ep *_ep, struct usb_request *_req,
10038 + gfp_t gfp_flags)
10039 +{
10040 + struct usba_request *req = to_usba_req(_req);
10041 + struct usba_ep *ep = to_usba_ep(_ep);
10042 + struct usba_udc *udc = ep->udc;
10043 + unsigned long flags;
10044 + int ret;
10045 +
10046 + DBG(DBG_GADGET | DBG_QUEUE | DBG_REQ,
10047 + "%s: queue req %p, len %u\n", ep_name(ep), req, _req->length);
10048 +
10049 + if (!udc->driver || udc->gadget.speed == USB_SPEED_UNKNOWN
10050 + || !ep->desc)
10051 + return -ESHUTDOWN;
10052 +
10053 + req->submitted = 0;
10054 + req->using_dma = 0;
10055 + req->last_transaction = 0;
10056 +
10057 + _req->status = -EINPROGRESS;
10058 + _req->actual = 0;
10059 +
10060 + if (ep_can_dma(ep))
10061 + return queue_dma(udc, ep, req, gfp_flags);
10062 +
10063 + /* May have received a reset since last time we checked */
10064 + ret = -ESHUTDOWN;
10065 + spin_lock_irqsave(&udc->lock, flags);
10066 + if (ep->desc) {
10067 + list_add_tail(&req->queue, &ep->queue);
10068 +
10069 + if (ep_is_in(ep)
10070 + || (ep_is_control(ep)
10071 + && (ep->state == DATA_STAGE_IN
10072 + || ep->state == STATUS_STAGE_IN)))
10073 + usba_ep_writel(ep, CTL_ENB, USBA_BIT(TX_PK_RDY));
10074 + else
10075 + usba_ep_writel(ep, CTL_ENB, USBA_BIT(RX_BK_RDY));
10076 + ret = 0;
10077 + }
10078 + spin_unlock_irqrestore(&udc->lock, flags);
10079 +
10080 + return ret;
10081 +}
10082 +
10083 +static void usba_update_req(struct usba_ep *ep, struct usba_request *req,
10084 + u32 status)
10085 +{
10086 + req->req.actual = req->req.length - USBA_BFEXT(DMA_BUF_LEN, status);
10087 +}
10088 +
10089 +static int stop_dma(struct usba_ep *ep, u32 *pstatus)
10090 +{
10091 + unsigned int timeout;
10092 + u32 status;
10093 +
10094 + /*
10095 + * Stop the DMA controller. When writing both CH_EN
10096 + * and LINK to 0, the other bits are not affected.
10097 + */
10098 + usba_dma_writel(ep, CONTROL, 0);
10099 +
10100 + /* Wait for the FIFO to empty */
10101 + for (timeout = 40; timeout; --timeout) {
10102 + status = usba_dma_readl(ep, STATUS);
10103 + if (!(status & USBA_BIT(DMA_CH_EN)))
10104 + break;
10105 + udelay(1);
10106 + }
10107 +
10108 + if (pstatus)
10109 + *pstatus = status;
10110 +
10111 + if (timeout == 0) {
10112 + dev_err(&ep->udc->pdev->dev,
10113 + "%s: timed out waiting for DMA FIFO to empty\n",
10114 + ep_name(ep));
10115 + return -ETIMEDOUT;
10116 + }
10117 +
10118 + return 0;
10119 +}
10120 +
10121 +static int usba_ep_dequeue(struct usb_ep *_ep, struct usb_request *_req)
10122 +{
10123 + struct usba_ep *ep = to_usba_ep(_ep);
10124 + struct usba_udc *udc = ep->udc;
10125 + struct usba_request *req = to_usba_req(_req);
10126 + unsigned long flags;
10127 + u32 status;
10128 +
10129 + DBG(DBG_GADGET | DBG_QUEUE, "ep_dequeue: %s, req %p\n",
10130 + ep_name(ep), req);
10131 +
10132 + spin_lock_irqsave(&udc->lock, flags);
10133 +
10134 + if (req->using_dma) {
10135 + /*
10136 + * If this request is currently being transferred,
10137 + * stop the DMA controller and reset the FIFO.
10138 + */
10139 + if (ep->queue.next == &req->queue) {
10140 + status = usba_dma_readl(ep, STATUS);
10141 + if (status & USBA_BIT(DMA_CH_EN))
10142 + stop_dma(ep, &status);
10143 +
10144 +#ifdef CONFIG_DEBUG_FS
10145 + ep->last_dma_status = status;
10146 +#endif
10147 +
10148 + usba_writel(udc, EPT_RST,
10149 + 1 << ep_index(ep));
10150 +
10151 + usba_update_req(ep, req, status);
10152 + }
10153 + }
10154 +
10155 + /*
10156 + * Errors should stop the queue from advancing until the
10157 + * completion function returns.
10158 + */
10159 + list_del_init(&req->queue);
10160 + spin_unlock_irqrestore(&udc->lock, flags);
10161 +
10162 + request_complete(ep, req, -ECONNRESET);
10163 +
10164 + /* Process the next request if any */
10165 + spin_lock_irqsave(&udc->lock, flags);
10166 + submit_next_request(ep);
10167 + spin_unlock_irqrestore(&udc->lock, flags);
10168 +
10169 + return 0;
10170 +}
10171 +
10172 +static int usba_ep_set_halt(struct usb_ep *_ep, int value)
10173 +{
10174 + struct usba_ep *ep = to_usba_ep(_ep);
10175 + struct usba_udc *udc = ep->udc;
10176 + unsigned long flags;
10177 + int ret = 0;
10178 +
10179 + DBG(DBG_GADGET, "endpoint %s: %s HALT\n", ep_name(ep),
10180 + value ? "set" : "clear");
10181 +
10182 + if (!ep->desc) {
10183 + DBG(DBG_ERR, "Attempted to halt uninitialized ep %s\n",
10184 + ep_name(ep));
10185 + return -ENODEV;
10186 + }
10187 + if (ep_is_isochronous(ep)) {
10188 + DBG(DBG_ERR, "Attempted to halt isochronous ep %s\n",
10189 + ep_name(ep));
10190 + return -ENOTTY;
10191 + }
10192 +
10193 + spin_lock_irqsave(&udc->lock, flags);
10194 +
10195 + /*
10196 + * We can't halt IN endpoints while there are still data to be
10197 + * transferred
10198 + */
10199 + if (!list_empty(&ep->queue)
10200 + || ((value && ep_is_in(ep)
10201 + && (usba_ep_readl(ep, STA)
10202 + & USBA_BF(BUSY_BANKS, -1L))))) {
10203 + ret = -EAGAIN;
10204 + } else {
10205 + if (value)
10206 + usba_ep_writel(ep, SET_STA, USBA_BIT(FORCE_STALL));
10207 + else
10208 + usba_ep_writel(ep, CLR_STA, (USBA_BIT(FORCE_STALL)
10209 + | USBA_BIT(TOGGLE_SEQ)));
10210 + usba_ep_readl(ep, STA);
10211 + }
10212 +
10213 + spin_unlock_irqrestore(&udc->lock, flags);
10214 +
10215 + return ret;
10216 +}
10217 +
10218 +static int usba_ep_fifo_status(struct usb_ep *_ep)
10219 +{
10220 + struct usba_ep *ep = to_usba_ep(_ep);
10221 +
10222 + return USBA_BFEXT(BYTE_COUNT, usba_ep_readl(ep, STA));
10223 +}
10224 +
10225 +static void usba_ep_fifo_flush(struct usb_ep *_ep)
10226 +{
10227 + struct usba_ep *ep = to_usba_ep(_ep);
10228 + struct usba_udc *udc = ep->udc;
10229 +
10230 + usba_writel(udc, EPT_RST, 1 << ep->index);
10231 +}
10232 +
10233 +struct usb_ep_ops usba_ep_ops = {
10234 + .enable = usba_ep_enable,
10235 + .disable = usba_ep_disable,
10236 + .alloc_request = usba_ep_alloc_request,
10237 + .free_request = usba_ep_free_request,
10238 + .alloc_buffer = usba_ep_alloc_buffer,
10239 + .free_buffer = usba_ep_free_buffer,
10240 + .queue = usba_ep_queue,
10241 + .dequeue = usba_ep_dequeue,
10242 + .set_halt = usba_ep_set_halt,
10243 + .fifo_status = usba_ep_fifo_status,
10244 + .fifo_flush = usba_ep_fifo_flush,
10245 +};
10246 +
10247 +static int usba_udc_get_frame(struct usb_gadget *gadget)
10248 +{
10249 + struct usba_udc *udc = to_usba_udc(gadget);
10250 +
10251 + return USBA_BFEXT(FRAME_NUMBER, usba_readl(udc, FNUM));
10252 +}
10253 +
10254 +struct usb_gadget_ops usba_udc_ops = {
10255 + .get_frame = usba_udc_get_frame,
10256 +};
10257 +
10258 +#define EP(nam, type, idx, dma, isoc) \
10259 +{ \
10260 + .ep = { \
10261 + .ops = &usba_ep_ops, \
10262 + .name = nam, \
10263 + .maxpacket = type##_FIFO_SIZE, \
10264 + }, \
10265 + .udc = &the_udc, \
10266 + .queue = LIST_HEAD_INIT(usba_ep[idx].queue), \
10267 + .fifo_size = type##_FIFO_SIZE, \
10268 + .nr_banks = type##_NR_BANKS, \
10269 + .index = idx, \
10270 + .can_dma = dma, \
10271 + .can_isoc = isoc, \
10272 +}
10273 +
10274 +static struct usba_ep usba_ep[] = {
10275 + EP("ep0", EP0, 0, 0, 0),
10276 + EP("ep1in-bulk", BULK, 1, 1, 0),
10277 + EP("ep2out-bulk", BULK, 2, 1, 0),
10278 + EP("ep3in-iso", ISO, 3, 1, 1),
10279 + EP("ep4out-iso", ISO, 4, 1, 1),
10280 + EP("ep5in-int", INT, 5, 1, 0),
10281 + EP("ep6out-int", INT, 6, 1, 0),
10282 +};
10283 +#undef EP
10284 +
10285 +static struct usb_endpoint_descriptor usba_ep0_desc = {
10286 + .bLength = USB_DT_ENDPOINT_SIZE,
10287 + .bDescriptorType = USB_DT_ENDPOINT,
10288 + .bEndpointAddress = 0,
10289 + .bmAttributes = USB_ENDPOINT_XFER_CONTROL,
10290 + .wMaxPacketSize = __constant_cpu_to_le16(64),
10291 + /* FIXME: I have no idea what to put here */
10292 + .bInterval = 1,
10293 +};
10294 +
10295 +static void nop_release(struct device *dev)
10296 +{
10297 +
10298 +}
10299 +
10300 +static struct usba_udc the_udc = {
10301 + .gadget = {
10302 + .ops = &usba_udc_ops,
10303 + .ep0 = &usba_ep[0].ep,
10304 + .ep_list = LIST_HEAD_INIT(the_udc.gadget.ep_list),
10305 + .is_dualspeed = 1,
10306 + .name = "atmel_usba_udc",
10307 + .dev = {
10308 + .bus_id = "gadget",
10309 + .release = nop_release,
10310 + },
10311 + },
10312 +
10313 + .lock = SPIN_LOCK_UNLOCKED,
10314 +};
10315 +
10316 +/*
10317 + * Called with interrupts disabled and udc->lock held.
10318 + */
10319 +static void reset_all_endpoints(struct usba_udc *udc)
10320 +{
10321 + struct usba_ep *ep;
10322 + struct usba_request *req, *tmp_req;
10323 +
10324 + usba_writel(udc, EPT_RST, ~0UL);
10325 +
10326 + ep = to_usba_ep(udc->gadget.ep0);
10327 + list_for_each_entry_safe(req, tmp_req, &ep->queue, queue) {
10328 + list_del_init(&req->queue);
10329 + request_complete(ep, req, -ECONNRESET);
10330 + }
10331 +
10332 + list_for_each_entry(ep, &udc->gadget.ep_list, ep.ep_list) {
10333 + if (ep->desc)
10334 + usba_ep_disable(&ep->ep);
10335 + }
10336 +}
10337 +
10338 +static struct usba_ep *get_ep_by_addr(struct usba_udc *udc, u16 wIndex)
10339 +{
10340 + struct usba_ep *ep;
10341 +
10342 + if ((wIndex & USB_ENDPOINT_NUMBER_MASK) == 0)
10343 + return to_usba_ep(udc->gadget.ep0);
10344 +
10345 + list_for_each_entry (ep, &udc->gadget.ep_list, ep.ep_list) {
10346 + u8 bEndpointAddress;
10347 +
10348 + if (!ep->desc)
10349 + continue;
10350 + bEndpointAddress = ep->desc->bEndpointAddress;
10351 + if ((wIndex ^ bEndpointAddress) & USB_DIR_IN)
10352 + continue;
10353 + if ((wIndex & USB_ENDPOINT_NUMBER_MASK)
10354 + == (bEndpointAddress & USB_ENDPOINT_NUMBER_MASK))
10355 + return ep;
10356 + }
10357 +
10358 + return NULL;
10359 +}
10360 +
10361 +/* Called with interrupts disabled and udc->lock held */
10362 +static inline void set_protocol_stall(struct usba_udc *udc,
10363 + struct usba_ep *ep)
10364 +{
10365 + usba_ep_writel(ep, SET_STA, USBA_BIT(FORCE_STALL));
10366 + ep->state = WAIT_FOR_SETUP;
10367 +}
10368 +
10369 +static inline int is_stalled(struct usba_udc *udc, struct usba_ep *ep)
10370 +{
10371 + if (usba_ep_readl(ep, STA) & USBA_BIT(FORCE_STALL))
10372 + return 1;
10373 + return 0;
10374 +}
10375 +
10376 +static inline void set_address(struct usba_udc *udc, unsigned int addr)
10377 +{
10378 + u32 regval;
10379 +
10380 + DBG(DBG_BUS, "setting address %u...\n", addr);
10381 + regval = usba_readl(udc, CTRL);
10382 + regval = USBA_BFINS(DEV_ADDR, addr, regval);
10383 + usba_writel(udc, CTRL, regval);
10384 +}
10385 +
10386 +static int do_test_mode(struct usba_udc *udc)
10387 +{
10388 + static const char test_packet_buffer[] = {
10389 + /* JKJKJKJK * 9 */
10390 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
10391 + /* JJKKJJKK * 8 */
10392 + 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA,
10393 + /* JJKKJJKK * 8 */
10394 + 0xEE, 0xEE, 0xEE, 0xEE, 0xEE, 0xEE, 0xEE, 0xEE,
10395 + /* JJJJJJJKKKKKKK * 8 */
10396 + 0xFE, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
10397 + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
10398 + /* JJJJJJJK * 8 */
10399 + 0x7F, 0xBF, 0xDF, 0xEF, 0xF7, 0xFB, 0xFD,
10400 + /* {JKKKKKKK * 10}, JK */
10401 + 0xFC, 0x7E, 0xBF, 0xDF, 0xEF, 0xF7, 0xFB, 0xFD, 0x7E
10402 + };
10403 + struct device *dev = &udc->pdev->dev;
10404 + struct usba_ep *ep;
10405 + int test_mode;
10406 +
10407 + test_mode = udc->test_mode;
10408 +
10409 + /* Start from a clean slate */
10410 + reset_all_endpoints(udc);
10411 +
10412 + switch (test_mode) {
10413 + case 0x0100:
10414 + /* Test_J */
10415 + usba_writel(udc, TST, USBA_BIT(TST_J_MODE));
10416 + dev_info(dev, "Entering Test_J mode...\n");
10417 + break;
10418 + case 0x0200:
10419 + /* Test_K */
10420 + usba_writel(udc, TST, USBA_BIT(TST_K_MODE));
10421 + dev_info(dev, "Entering Test_K mode...\n");
10422 + break;
10423 + case 0x0300:
10424 + /*
10425 + * Test_SE0_NAK: Force high-speed mode and set up ep0
10426 + * for Bulk IN transfers
10427 + */
10428 + ep = &usba_ep[0];
10429 + usba_writel(udc, TST,
10430 + USBA_BF(SPEED_CFG, USBA_SPEED_CFG_FORCE_HIGH));
10431 + usba_ep_writel(ep, CFG,
10432 + USBA_BF(EPT_SIZE, USBA_EPT_SIZE_64)
10433 + | USBA_BIT(EPT_DIR)
10434 + | USBA_BF(EPT_TYPE, USBA_EPT_TYPE_BULK)
10435 + | USBA_BF(BK_NUMBER, 1));
10436 + if (!(usba_ep_readl(ep, CFG) & USBA_BIT(EPT_MAPPED))) {
10437 + set_protocol_stall(udc, ep);
10438 + dev_err(dev, "Test_SE0_NAK: ep0 not mapped\n");
10439 + } else {
10440 + usba_ep_writel(ep, CTL_ENB, USBA_BIT(EPT_ENABLE));
10441 + dev_info(dev, "Entering Test_SE0_NAK mode...\n");
10442 + }
10443 + break;
10444 + case 0x0400:
10445 + /* Test_Packet */
10446 + ep = &usba_ep[0];
10447 + usba_ep_writel(ep, CFG,
10448 + USBA_BF(EPT_SIZE, USBA_EPT_SIZE_64)
10449 + | USBA_BIT(EPT_DIR)
10450 + | USBA_BF(EPT_TYPE, USBA_EPT_TYPE_BULK)
10451 + | USBA_BF(BK_NUMBER, 1));
10452 + if (!(usba_ep_readl(ep, CFG) & USBA_BIT(EPT_MAPPED))) {
10453 + set_protocol_stall(udc, ep);
10454 + dev_err(dev, "Test_Packet: ep0 not mapped\n");
10455 + } else {
10456 + usba_ep_writel(ep, CTL_ENB, USBA_BIT(EPT_ENABLE));
10457 + usba_writel(udc, TST, USBA_BIT(TST_PKT_MODE));
10458 + copy_to_fifo(ep->fifo, test_packet_buffer,
10459 + sizeof(test_packet_buffer));
10460 + usba_ep_writel(ep, SET_STA, USBA_BIT(TX_PK_RDY));
10461 + dev_info(dev, "Entering Test_Packet mode...\n");
10462 + }
10463 + break;
10464 + default:
10465 + dev_err(dev, "Invalid test mode: 0x%04x\n", test_mode);
10466 + return -EINVAL;
10467 + }
10468 +
10469 + return 0;
10470 +}
10471 +
10472 +/* Avoid overly long expressions */
10473 +static inline bool feature_is_dev_remote_wakeup(struct usb_ctrlrequest *crq)
10474 +{
10475 + if (crq->wValue == __constant_cpu_to_le16(USB_DEVICE_REMOTE_WAKEUP))
10476 + return true;
10477 + return false;
10478 +}
10479 +
10480 +static inline bool feature_is_dev_test_mode(struct usb_ctrlrequest *crq)
10481 +{
10482 + if (crq->wValue == __constant_cpu_to_le16(USB_DEVICE_TEST_MODE))
10483 + return true;
10484 + return false;
10485 +}
10486 +
10487 +static inline bool feature_is_ep_halt(struct usb_ctrlrequest *crq)
10488 +{
10489 + if (crq->wValue == __constant_cpu_to_le16(USB_ENDPOINT_HALT))
10490 + return true;
10491 + return false;
10492 +}
10493 +
10494 +static int handle_ep0_setup(struct usba_udc *udc, struct usba_ep *ep,
10495 + struct usb_ctrlrequest *crq)
10496 +{
10497 + switch (crq->bRequest) {
10498 + case USB_REQ_GET_STATUS: {
10499 + u16 status;
10500 +
10501 + if (crq->bRequestType == (USB_DIR_IN | USB_RECIP_DEVICE)) {
10502 + /* Self-powered, no remote wakeup */
10503 + status = __constant_cpu_to_le16(1 << 0);
10504 + } else if (crq->bRequestType
10505 + == (USB_DIR_IN | USB_RECIP_INTERFACE)) {
10506 + status = __constant_cpu_to_le16(0);
10507 + } else if (crq->bRequestType
10508 + == (USB_DIR_IN | USB_RECIP_ENDPOINT)) {
10509 + struct usba_ep *target;
10510 +
10511 + target = get_ep_by_addr(udc, le16_to_cpu(crq->wIndex));
10512 + if (!target)
10513 + goto stall;
10514 +
10515 + status = 0;
10516 + if (is_stalled(udc, target))
10517 + status |= __constant_cpu_to_le16(1);
10518 + } else {
10519 + goto delegate;
10520 + }
10521 +
10522 + /* Write directly to the FIFO. No queueing is done. */
10523 + if (crq->wLength != __constant_cpu_to_le16(sizeof(status)))
10524 + goto stall;
10525 + ep->state = DATA_STAGE_IN;
10526 + __raw_writew(status, ep->fifo);
10527 + usba_ep_writel(ep, SET_STA, USBA_BIT(TX_PK_RDY));
10528 + break;
10529 + }
10530 +
10531 + case USB_REQ_CLEAR_FEATURE: {
10532 + if (crq->bRequestType == USB_RECIP_DEVICE) {
10533 + if (feature_is_dev_remote_wakeup(crq)) {
10534 + /* TODO: Handle REMOTE_WAKEUP */
10535 + } else {
10536 + /* Can't CLEAR_FEATURE TEST_MODE */
10537 + goto stall;
10538 + }
10539 + } else if (crq->bRequestType == USB_RECIP_ENDPOINT) {
10540 + struct usba_ep *target;
10541 +
10542 + if (!feature_is_ep_halt(crq)
10543 + || crq->wLength != __constant_cpu_to_le16(0))
10544 + goto stall;
10545 + target = get_ep_by_addr(udc, le16_to_cpu(crq->wIndex));
10546 + if (!target)
10547 + goto stall;
10548 +
10549 + usba_ep_writel(target, CLR_STA,
10550 + (USBA_BIT(FORCE_STALL)
10551 + | USBA_BIT(TOGGLE_SEQ)));
10552 + } else {
10553 + goto delegate;
10554 + }
10555 +
10556 + send_status(udc, ep);
10557 + break;
10558 + }
10559 +
10560 + case USB_REQ_SET_FEATURE: {
10561 + if (crq->bRequestType == USB_RECIP_DEVICE) {
10562 + if (feature_is_dev_test_mode(crq)) {
10563 + send_status(udc, ep);
10564 + ep->state = STATUS_STAGE_TEST;
10565 + udc->test_mode = le16_to_cpu(crq->wIndex);
10566 + return 0;
10567 + } else if (feature_is_dev_remote_wakeup(crq)) {
10568 + /* TODO: Handle REMOTE_WAKEUP */
10569 + } else {
10570 + goto stall;
10571 + }
10572 + } else if (crq->bRequestType == USB_RECIP_ENDPOINT) {
10573 + struct usba_ep *target;
10574 +
10575 + if (!feature_is_ep_halt(crq)
10576 + || crq->wLength != __constant_cpu_to_le16(0))
10577 + goto stall;
10578 +
10579 + target = get_ep_by_addr(udc, le16_to_cpu(crq->wIndex));
10580 + if (!target)
10581 + goto stall;
10582 +
10583 + usba_ep_writel(target, SET_STA, USBA_BIT(FORCE_STALL));
10584 + } else
10585 + goto delegate;
10586 +
10587 + send_status(udc, ep);
10588 + break;
10589 + }
10590 +
10591 + case USB_REQ_SET_ADDRESS:
10592 + if (crq->bRequestType != (USB_DIR_OUT | USB_RECIP_DEVICE))
10593 + goto delegate;
10594 +
10595 + set_address(udc, le16_to_cpu(crq->wValue));
10596 + send_status(udc, ep);
10597 + ep->state = STATUS_STAGE_ADDR;
10598 + break;
10599 +
10600 + default:
10601 +delegate:
10602 + return udc->driver->setup(&udc->gadget, crq);
10603 + }
10604 +
10605 + return 0;
10606 +
10607 +stall:
10608 + printk(KERN_ERR
10609 + "udc: %s: Invalid setup request: %02x.%02x v%04x i%04x l%d, "
10610 + "halting endpoint...\n",
10611 + ep_name(ep), crq->bRequestType, crq->bRequest,
10612 + le16_to_cpu(crq->wValue), le16_to_cpu(crq->wIndex),
10613 + le16_to_cpu(crq->wLength));
10614 + set_protocol_stall(udc, ep);
10615 + return -1;
10616 +}
10617 +
10618 +static void usba_control_irq(struct usba_udc *udc, struct usba_ep *ep)
10619 +{
10620 + struct usba_request *req;
10621 + u32 epstatus;
10622 + u32 epctrl;
10623 +
10624 +restart:
10625 + epstatus = usba_ep_readl(ep, STA);
10626 + epctrl = usba_ep_readl(ep, CTL);
10627 +
10628 + DBG(DBG_INT, "%s [%d]: s/%08x c/%08x\n",
10629 + ep_name(ep), ep->state, epstatus, epctrl);
10630 +
10631 + req = NULL;
10632 + if (!list_empty(&ep->queue))
10633 + req = list_entry(ep->queue.next,
10634 + struct usba_request, queue);
10635 +
10636 + if ((epctrl & USBA_BIT(TX_PK_RDY))
10637 + && !(epstatus & USBA_BIT(TX_PK_RDY))) {
10638 + if (req->submitted)
10639 + next_fifo_transaction(ep, req);
10640 + else
10641 + submit_request(ep, req);
10642 +
10643 + if (req->last_transaction) {
10644 + usba_ep_writel(ep, CTL_DIS, USBA_BIT(TX_PK_RDY));
10645 + usba_ep_writel(ep, CTL_ENB, USBA_BIT(TX_COMPLETE));
10646 + }
10647 + goto restart;
10648 + }
10649 + if ((epstatus & epctrl) & USBA_BIT(TX_COMPLETE)) {
10650 + usba_ep_writel(ep, CLR_STA, USBA_BIT(TX_COMPLETE));
10651 +
10652 + switch (ep->state) {
10653 + case DATA_STAGE_IN:
10654 + usba_ep_writel(ep, CTL_ENB, USBA_BIT(RX_BK_RDY));
10655 + usba_ep_writel(ep, CTL_DIS, USBA_BIT(TX_COMPLETE));
10656 + ep->state = STATUS_STAGE_OUT;
10657 + break;
10658 + case STATUS_STAGE_ADDR:
10659 + /* Activate our new address */
10660 + usba_writel(udc, CTRL, (usba_readl(udc, CTRL)
10661 + | USBA_BIT(FADDR_EN)));
10662 + usba_ep_writel(ep, CTL_DIS, USBA_BIT(TX_COMPLETE));
10663 + ep->state = WAIT_FOR_SETUP;
10664 + break;
10665 + case STATUS_STAGE_IN:
10666 + if (req) {
10667 + list_del_init(&req->queue);
10668 + request_complete(ep, req, 0);
10669 + submit_next_request(ep);
10670 + }
10671 + usba_ep_writel(ep, CTL_DIS, USBA_BIT(TX_COMPLETE));
10672 + ep->state = WAIT_FOR_SETUP;
10673 + break;
10674 + case STATUS_STAGE_TEST:
10675 + usba_ep_writel(ep, CTL_DIS, USBA_BIT(TX_COMPLETE));
10676 + ep->state = WAIT_FOR_SETUP;
10677 + if (do_test_mode(udc))
10678 + set_protocol_stall(udc, ep);
10679 + break;
10680 + default:
10681 + printk(KERN_ERR
10682 + "udc: %s: TXCOMP: Invalid endpoint state %d, "
10683 + "halting endpoint...\n",
10684 + ep_name(ep), ep->state);
10685 + set_protocol_stall(udc, ep);
10686 + break;
10687 + }
10688 +
10689 + goto restart;
10690 + }
10691 + if ((epstatus & epctrl) & USBA_BIT(RX_BK_RDY)) {
10692 + switch (ep->state) {
10693 + case STATUS_STAGE_OUT:
10694 + usba_ep_writel(ep, CLR_STA, USBA_BIT(RX_BK_RDY));
10695 + usba_ep_writel(ep, CTL_DIS, USBA_BIT(RX_BK_RDY));
10696 +
10697 + if (req) {
10698 + list_del_init(&req->queue);
10699 + request_complete(ep, req, 0);
10700 + }
10701 + ep->state = WAIT_FOR_SETUP;
10702 + break;
10703 +
10704 + case DATA_STAGE_OUT:
10705 + receive_data(ep);
10706 + break;
10707 +
10708 + default:
10709 + usba_ep_writel(ep, CLR_STA, USBA_BIT(RX_BK_RDY));
10710 + usba_ep_writel(ep, CTL_DIS, USBA_BIT(RX_BK_RDY));
10711 + printk(KERN_ERR
10712 + "udc: %s: RXRDY: Invalid endpoint state %d, "
10713 + "halting endpoint...\n",
10714 + ep_name(ep), ep->state);
10715 + set_protocol_stall(udc, ep);
10716 + break;
10717 + }
10718 +
10719 + goto restart;
10720 + }
10721 + if (epstatus & USBA_BIT(RX_SETUP)) {
10722 + union {
10723 + struct usb_ctrlrequest crq;
10724 + unsigned long data[2];
10725 + } crq;
10726 + unsigned int pkt_len;
10727 + int ret;
10728 +
10729 + if (ep->state != WAIT_FOR_SETUP) {
10730 + /*
10731 + * Didn't expect a SETUP packet at this
10732 + * point. Clean up any pending requests (which
10733 + * may be successful).
10734 + */
10735 + int status = -EPROTO;
10736 +
10737 + /*
10738 + * RXRDY and TXCOMP are dropped when SETUP
10739 + * packets arrive. Just pretend we received
10740 + * the status packet.
10741 + */
10742 + if (ep->state == STATUS_STAGE_OUT
10743 + || ep->state == STATUS_STAGE_IN) {
10744 + usba_ep_writel(ep, CTL_DIS,
10745 + USBA_BIT(RX_BK_RDY));
10746 + status = 0;
10747 + }
10748 +
10749 + if (req) {
10750 + list_del_init(&req->queue);
10751 + request_complete(ep, req, status);
10752 + }
10753 + }
10754 +
10755 + pkt_len = USBA_BFEXT(BYTE_COUNT, usba_ep_readl(ep, STA));
10756 + DBG(DBG_HW, "Packet length: %u\n", pkt_len);
10757 + if (pkt_len != sizeof(crq)) {
10758 + printk(KERN_WARNING
10759 + "udc: Invalid packet length %u (expected %lu)\n",
10760 + pkt_len, sizeof(crq));
10761 + set_protocol_stall(udc, ep);
10762 + return;
10763 + }
10764 +
10765 + DBG(DBG_FIFO, "Copying ctrl request from 0x%p:\n", ep->fifo);
10766 + copy_from_fifo(crq.data, ep->fifo, sizeof(crq));
10767 +
10768 + /* Free up one bank in the FIFO so that we can
10769 + * generate or receive a reply right away. */
10770 + usba_ep_writel(ep, CLR_STA, USBA_BIT(RX_SETUP));
10771 +
10772 + /* printk(KERN_DEBUG "setup: %d: %02x.%02x\n",
10773 + ep->state, crq.crq.bRequestType,
10774 + crq.crq.bRequest); */
10775 +
10776 + if (crq.crq.bRequestType & USB_DIR_IN) {
10777 + /*
10778 + * The USB 2.0 spec states that "if wLength is
10779 + * zero, there is no data transfer phase."
10780 + * However, testusb #14 seems to actually
10781 + * expect a data phase even if wLength = 0...
10782 + */
10783 + ep->state = DATA_STAGE_IN;
10784 + } else {
10785 + if (crq.crq.wLength != __constant_cpu_to_le16(0))
10786 + ep->state = DATA_STAGE_OUT;
10787 + else
10788 + ep->state = STATUS_STAGE_IN;
10789 + }
10790 +
10791 + ret = -1;
10792 + if (ep->index == 0)
10793 + ret = handle_ep0_setup(udc, ep, &crq.crq);
10794 + else
10795 + ret = udc->driver->setup(&udc->gadget, &crq.crq);
10796 +
10797 + DBG(DBG_BUS, "req %02x.%02x, length %d, state %d, ret %d\n",
10798 + crq.crq.bRequestType, crq.crq.bRequest,
10799 + le16_to_cpu(crq.crq.wLength), ep->state, ret);
10800 +
10801 + if (ret < 0) {
10802 + /* Let the host know that we failed */
10803 + set_protocol_stall(udc, ep);
10804 + }
10805 + }
10806 +}
10807 +
10808 +static void usba_ep_irq(struct usba_udc *udc, struct usba_ep *ep)
10809 +{
10810 + struct usba_request *req;
10811 + u32 epstatus;
10812 + u32 epctrl;
10813 +
10814 + epstatus = usba_ep_readl(ep, STA);
10815 + epctrl = usba_ep_readl(ep, CTL);
10816 +
10817 + DBG(DBG_INT, "%s: interrupt, status: 0x%08x\n",
10818 + ep_name(ep), epstatus);
10819 +
10820 + while ((epctrl & USBA_BIT(TX_PK_RDY))
10821 + && !(epstatus & USBA_BIT(TX_PK_RDY))) {
10822 + DBG(DBG_BUS, "%s: TX PK ready\n", ep_name(ep));
10823 +
10824 + if (list_empty(&ep->queue)) {
10825 + dev_warn(&udc->pdev->dev, "ep_irq: queue empty\n");
10826 + usba_ep_writel(ep, CTL_DIS, USBA_BIT(TX_PK_RDY));
10827 + return;
10828 + }
10829 +
10830 + req = list_entry(ep->queue.next, struct usba_request, queue);
10831 +
10832 + if (req->using_dma) {
10833 + /* Send a zero-length packet */
10834 + usba_ep_writel(ep, SET_STA,
10835 + USBA_BIT(TX_PK_RDY));
10836 + usba_ep_writel(ep, CTL_DIS,
10837 + USBA_BIT(TX_PK_RDY));
10838 + list_del_init(&req->queue);
10839 + submit_next_request(ep);
10840 + request_complete(ep, req, 0);
10841 + } else {
10842 + if (req->submitted)
10843 + next_fifo_transaction(ep, req);
10844 + else
10845 + submit_request(ep, req);
10846 +
10847 + if (req->last_transaction) {
10848 + list_del_init(&req->queue);
10849 + submit_next_request(ep);
10850 + request_complete(ep, req, 0);
10851 + }
10852 + }
10853 +
10854 + epstatus = usba_ep_readl(ep, STA);
10855 + epctrl = usba_ep_readl(ep, CTL);
10856 + }
10857 + if ((epstatus & epctrl) & USBA_BIT(RX_BK_RDY)) {
10858 + DBG(DBG_BUS, "%s: RX data ready\n", ep_name(ep));
10859 + receive_data(ep);
10860 + usba_ep_writel(ep, CLR_STA, USBA_BIT(RX_BK_RDY));
10861 + }
10862 +}
10863 +
10864 +static void usba_dma_irq(struct usba_udc *udc, struct usba_ep *ep)
10865 +{
10866 + struct usba_request *req;
10867 + u32 status, control, pending;
10868 +
10869 + status = usba_dma_readl(ep, STATUS);
10870 + control = usba_dma_readl(ep, CONTROL);
10871 +#ifdef CONFIG_DEBUG_FS
10872 + ep->last_dma_status = status;
10873 +#endif
10874 + pending = status & control;
10875 + DBG(DBG_INT | DBG_DMA, "dma irq, s/%#08x, c/%#08x\n",
10876 + status, control);
10877 +
10878 + if (status & USBA_BIT(DMA_CH_EN)) {
10879 + dev_err(&udc->pdev->dev,
10880 + "DMA_CH_EN is set after transfer is finished!\n");
10881 + dev_err(&udc->pdev->dev,
10882 + "status=%#08x, pending=%#08x, control=%#08x\n",
10883 + status, pending, control);
10884 +
10885 + /*
10886 + * try to pretend nothing happened. We might have to
10887 + * do something here...
10888 + */
10889 + }
10890 +
10891 + if (list_empty(&ep->queue))
10892 + /* Might happen if a reset comes along at the right moment */
10893 + return;
10894 +
10895 + if (pending & (USBA_BIT(DMA_END_TR_ST) | USBA_BIT(DMA_END_BUF_ST))) {
10896 + req = list_entry(ep->queue.next, struct usba_request, queue);
10897 + usba_update_req(ep, req, status);
10898 +
10899 + list_del_init(&req->queue);
10900 + submit_next_request(ep);
10901 + request_complete(ep, req, 0);
10902 + }
10903 +}
10904 +
10905 +static irqreturn_t usba_udc_irq(int irq, void *devid)
10906 +{
10907 + struct usba_udc *udc = devid;
10908 + u32 status;
10909 + u32 dma_status;
10910 + u32 ep_status;
10911 +
10912 + spin_lock(&udc->lock);
10913 +
10914 + status = usba_readl(udc, INT_STA);
10915 + DBG(DBG_INT, "irq, status=%#08x\n", status);
10916 +
10917 + if (status & USBA_BIT(DET_SUSPEND)) {
10918 + usba_writel(udc, INT_CLR, USBA_BIT(DET_SUSPEND));
10919 + DBG(DBG_BUS, "Suspend detected\n");
10920 + if (udc->gadget.speed != USB_SPEED_UNKNOWN
10921 + && udc->driver && udc->driver->suspend)
10922 + udc->driver->suspend(&udc->gadget);
10923 + }
10924 +
10925 + if (status & USBA_BIT(WAKE_UP)) {
10926 + usba_writel(udc, INT_CLR, USBA_BIT(WAKE_UP));
10927 + DBG(DBG_BUS, "Wake Up CPU detected\n");
10928 + }
10929 +
10930 + if (status & USBA_BIT(END_OF_RESUME)) {
10931 + usba_writel(udc, INT_CLR, USBA_BIT(END_OF_RESUME));
10932 + DBG(DBG_BUS, "Resume detected\n");
10933 + if (udc->gadget.speed != USB_SPEED_UNKNOWN
10934 + && udc->driver && udc->driver->resume)
10935 + udc->driver->resume(&udc->gadget);
10936 + }
10937 +
10938 + dma_status = USBA_BFEXT(DMA_INT, status);
10939 + if (dma_status) {
10940 + int i;
10941 +
10942 + for (i = 1; i < USBA_NR_ENDPOINTS; i++)
10943 + if (dma_status & (1 << i))
10944 + usba_dma_irq(udc, &usba_ep[i]);
10945 + }
10946 +
10947 + ep_status = USBA_BFEXT(EPT_INT, status);
10948 + if (ep_status) {
10949 + int i;
10950 +
10951 + for (i = 0; i < USBA_NR_ENDPOINTS; i++)
10952 + if (ep_status & (1 << i)) {
10953 + if (ep_is_control(&usba_ep[i]))
10954 + usba_control_irq(udc, &usba_ep[i]);
10955 + else
10956 + usba_ep_irq(udc, &usba_ep[i]);
10957 + }
10958 + }
10959 +
10960 + if (status & USBA_BIT(END_OF_RESET)) {
10961 + struct usba_ep *ep0;
10962 +
10963 + usba_writel(udc, INT_CLR, USBA_BIT(END_OF_RESET));
10964 + reset_all_endpoints(udc);
10965 +
10966 + if (status & USBA_BIT(HIGH_SPEED)) {
10967 + DBG(DBG_BUS, "High-speed bus reset detected\n");
10968 + udc->gadget.speed = USB_SPEED_HIGH;
10969 + } else {
10970 + DBG(DBG_BUS, "Full-speed bus reset detected\n");
10971 + udc->gadget.speed = USB_SPEED_FULL;
10972 + }
10973 +
10974 + ep0 = &usba_ep[0];
10975 + ep0->desc = &usba_ep0_desc;
10976 + ep0->state = WAIT_FOR_SETUP;
10977 + usba_ep_writel(ep0, CFG,
10978 + (USBA_BF(EPT_SIZE, EP0_EPT_SIZE)
10979 + | USBA_BF(EPT_TYPE, USBA_EPT_TYPE_CONTROL)
10980 + | USBA_BF(BK_NUMBER, USBA_BK_NUMBER_ONE)));
10981 + usba_ep_writel(ep0, CTL_ENB,
10982 + USBA_BIT(EPT_ENABLE) | USBA_BIT(RX_SETUP));
10983 + usba_writel(udc, INT_ENB, (usba_readl(udc, INT_ENB)
10984 + | USBA_BF(EPT_INT, 1)
10985 + | USBA_BIT(DET_SUSPEND)
10986 + | USBA_BIT(END_OF_RESUME)));
10987 +
10988 + if (!(usba_ep_readl(ep0, CFG) & USBA_BIT(EPT_MAPPED)))
10989 + dev_warn(&udc->pdev->dev,
10990 + "WARNING: EP0 configuration is invalid!\n");
10991 + }
10992 +
10993 + spin_unlock(&udc->lock);
10994 +
10995 + return IRQ_HANDLED;
10996 +}
10997 +
10998 +static irqreturn_t usba_vbus_irq(int irq, void *devid)
10999 +{
11000 + struct usba_udc *udc = devid;
11001 + int vbus;
11002 +
11003 + /* debounce */
11004 + udelay(10);
11005 +
11006 + spin_lock(&udc->lock);
11007 + vbus = gpio_get_value(udc->vbus_pin);
11008 + if (vbus != udc->vbus_prev) {
11009 + if (vbus) {
11010 + usba_writel(udc, CTRL, USBA_BIT(EN_USBA));
11011 + usba_writel(udc, INT_ENB, USBA_BIT(END_OF_RESET));
11012 + } else {
11013 + udc->gadget.speed = USB_SPEED_UNKNOWN;
11014 + reset_all_endpoints(udc);
11015 + usba_writel(udc, CTRL, 0);
11016 + if (udc->driver)
11017 + udc->driver->disconnect(&udc->gadget);
11018 + }
11019 + udc->vbus_prev = vbus;
11020 + }
11021 + spin_unlock(&udc->lock);
11022 +
11023 + return IRQ_HANDLED;
11024 +}
11025 +
11026 +int usb_gadget_register_driver(struct usb_gadget_driver *driver)
11027 +{
11028 + struct usba_udc *udc = &the_udc;
11029 + unsigned long flags;
11030 + int ret;
11031 +
11032 + if (!udc->pdev)
11033 + return -ENODEV;
11034 +
11035 + spin_lock_irqsave(&udc->lock, flags);
11036 + if (udc->driver) {
11037 + spin_unlock_irqrestore(&udc->lock, flags);
11038 + return -EBUSY;
11039 + }
11040 +
11041 + udc->driver = driver;
11042 + udc->gadget.dev.driver = &driver->driver;
11043 + spin_unlock_irqrestore(&udc->lock, flags);
11044 +
11045 + clk_enable(udc->pclk);
11046 + clk_enable(udc->hclk);
11047 +
11048 + ret = driver->bind(&udc->gadget);
11049 + if (ret) {
11050 + DBG(DBG_ERR, "Could not bind to driver %s: error %d\n",
11051 + driver->driver.name, ret);
11052 + goto err_driver_bind;
11053 + }
11054 +
11055 + DBG(DBG_GADGET, "registered driver `%s'\n", driver->driver.name);
11056 +
11057 + udc->vbus_prev = 0;
11058 + if (udc->vbus_pin != -1) {
11059 + ret = request_irq(gpio_to_irq(udc->vbus_pin),
11060 + usba_vbus_irq, 0, "atmel_usba_udc", udc);
11061 + if (ret) {
11062 + gpio_free(udc->vbus_pin);
11063 + udc->vbus_pin = -1;
11064 + dev_warn(&udc->pdev->dev,
11065 + "failed to request vbus irq; "
11066 + "assuming always on\n");
11067 + }
11068 + }
11069 +
11070 + /* If Vbus is present, enable the controller and wait for reset */
11071 + spin_lock_irqsave(&udc->lock, flags);
11072 + if (vbus_is_present(udc) && udc->vbus_prev == 0) {
11073 + usba_writel(udc, CTRL, USBA_BIT(EN_USBA));
11074 + usba_writel(udc, INT_ENB, USBA_BIT(END_OF_RESET));
11075 + }
11076 + spin_unlock_irqrestore(&udc->lock, flags);
11077 +
11078 + return 0;
11079 +
11080 +err_driver_bind:
11081 + udc->driver = NULL;
11082 + udc->gadget.dev.driver = NULL;
11083 + return ret;
11084 +}
11085 +EXPORT_SYMBOL(usb_gadget_register_driver);
11086 +
11087 +int usb_gadget_unregister_driver(struct usb_gadget_driver *driver)
11088 +{
11089 + struct usba_udc *udc = &the_udc;
11090 + unsigned long flags;
11091 +
11092 + if (!udc->pdev)
11093 + return -ENODEV;
11094 + if (driver != udc->driver)
11095 + return -EINVAL;
11096 +
11097 + if (udc->vbus_pin != -1)
11098 + free_irq(gpio_to_irq(udc->vbus_pin), udc);
11099 +
11100 + spin_lock_irqsave(&udc->lock, flags);
11101 + udc->gadget.speed = USB_SPEED_UNKNOWN;
11102 + reset_all_endpoints(udc);
11103 + spin_unlock_irqrestore(&udc->lock, flags);
11104 +
11105 + /* This will also disable the DP pullup */
11106 + usba_writel(udc, CTRL, 0);
11107 +
11108 + driver->unbind(&udc->gadget);
11109 + udc->gadget.dev.driver = NULL;
11110 + udc->driver = NULL;
11111 +
11112 + clk_disable(udc->hclk);
11113 + clk_disable(udc->pclk);
11114 +
11115 + DBG(DBG_GADGET, "unregistered driver `%s'\n", driver->driver.name);
11116 +
11117 + return 0;
11118 +}
11119 +EXPORT_SYMBOL(usb_gadget_unregister_driver);
11120 +
11121 +static int __devinit usba_udc_probe(struct platform_device *pdev)
11122 +{
11123 + struct usba_platform_data *pdata = pdev->dev.platform_data;
11124 + struct resource *regs, *fifo;
11125 + struct clk *pclk, *hclk;
11126 + struct usba_udc *udc = &the_udc;
11127 + int irq, ret, i;
11128 +
11129 + regs = platform_get_resource(pdev, IORESOURCE_MEM, CTRL_IOMEM_ID);
11130 + fifo = platform_get_resource(pdev, IORESOURCE_MEM, FIFO_IOMEM_ID);
11131 + if (!regs || !fifo)
11132 + return -ENXIO;
11133 +
11134 + irq = platform_get_irq(pdev, 0);
11135 + if (irq < 0)
11136 + return irq;
11137 +
11138 + pclk = clk_get(&pdev->dev, "pclk");
11139 + if (IS_ERR(pclk))
11140 + return PTR_ERR(pclk);
11141 + hclk = clk_get(&pdev->dev, "hclk");
11142 + if (IS_ERR(hclk)) {
11143 + ret = PTR_ERR(hclk);
11144 + goto err_get_hclk;
11145 + }
11146 +
11147 + udc->pdev = pdev;
11148 + udc->pclk = pclk;
11149 + udc->hclk = hclk;
11150 + udc->vbus_pin = -1;
11151 +
11152 + ret = -ENOMEM;
11153 + udc->regs = ioremap(regs->start, regs->end - regs->start + 1);
11154 + if (!udc->regs) {
11155 + dev_err(&pdev->dev, "Unable to map I/O memory, aborting.\n");
11156 + goto err_map_regs;
11157 + }
11158 + dev_info(&pdev->dev, "MMIO registers at 0x%08lx mapped at %p\n",
11159 + (unsigned long)regs->start, udc->regs);
11160 + udc->fifo = ioremap(fifo->start, fifo->end - fifo->start + 1);
11161 + if (!udc->fifo) {
11162 + dev_err(&pdev->dev, "Unable to map FIFO, aborting.\n");
11163 + goto err_map_fifo;
11164 + }
11165 + dev_info(&pdev->dev, "FIFO at 0x%08lx mapped at %p\n",
11166 + (unsigned long)fifo->start, udc->fifo);
11167 +
11168 + device_initialize(&udc->gadget.dev);
11169 + udc->gadget.dev.parent = &pdev->dev;
11170 + udc->gadget.dev.dma_mask = pdev->dev.dma_mask;
11171 +
11172 + platform_set_drvdata(pdev, udc);
11173 +
11174 + /* Make sure we start from a clean slate */
11175 + clk_enable(pclk);
11176 + usba_writel(udc, CTRL, 0);
11177 + clk_disable(pclk);
11178 +
11179 + INIT_LIST_HEAD(&usba_ep[0].ep.ep_list);
11180 + usba_ep[0].ep_regs = udc->regs + USBA_EPT_BASE(0);
11181 + usba_ep[0].dma_regs = udc->regs + USBA_DMA_BASE(0);
11182 + usba_ep[0].fifo = udc->fifo + USBA_FIFO_BASE(0);
11183 + for (i = 1; i < ARRAY_SIZE(usba_ep); i++) {
11184 + struct usba_ep *ep = &usba_ep[i];
11185 +
11186 + ep->ep_regs = udc->regs + USBA_EPT_BASE(i);
11187 + ep->dma_regs = udc->regs + USBA_DMA_BASE(i);
11188 + ep->fifo = udc->fifo + USBA_FIFO_BASE(i);
11189 +
11190 + list_add_tail(&ep->ep.ep_list, &udc->gadget.ep_list);
11191 + }
11192 +
11193 + ret = request_irq(irq, usba_udc_irq, IRQF_SAMPLE_RANDOM,
11194 + "atmel_usba_udc", udc);
11195 + if (ret) {
11196 + dev_err(&pdev->dev, "Cannot request irq %d (error %d)\n",
11197 + irq, ret);
11198 + goto err_request_irq;
11199 + }
11200 + udc->irq = irq;
11201 +
11202 + ret = device_add(&udc->gadget.dev);
11203 + if (ret) {
11204 + dev_dbg(&pdev->dev, "Could not add gadget: %d\n", ret);
11205 + goto err_device_add;
11206 + }
11207 +
11208 + if (pdata && pdata->vbus_pin != GPIO_PIN_NONE)
11209 + if (!gpio_request(pdata->vbus_pin, "atmel_usba_udc"))
11210 + udc->vbus_pin = pdata->vbus_pin;
11211 +
11212 + usba_init_debugfs(udc);
11213 + for (i = 1; i < ARRAY_SIZE(usba_ep); i++)
11214 + usba_ep_init_debugfs(udc, &usba_ep[i]);
11215 +
11216 + return 0;
11217 +
11218 +err_device_add:
11219 + free_irq(irq, udc);
11220 +err_request_irq:
11221 + iounmap(udc->fifo);
11222 +err_map_fifo:
11223 + iounmap(udc->regs);
11224 +err_map_regs:
11225 + clk_put(hclk);
11226 +err_get_hclk:
11227 + clk_put(pclk);
11228 +
11229 + platform_set_drvdata(pdev, NULL);
11230 +
11231 + return ret;
11232 +}
11233 +
11234 +static int __devexit usba_udc_remove(struct platform_device *pdev)
11235 +{
11236 + struct usba_udc *udc;
11237 + int i;
11238 +
11239 + udc = platform_get_drvdata(pdev);
11240 +
11241 + for (i = 1; i < ARRAY_SIZE(usba_ep); i++)
11242 + usba_ep_cleanup_debugfs(&usba_ep[i]);
11243 + usba_cleanup_debugfs(udc);
11244 +
11245 + if (udc->vbus_pin != -1)
11246 + gpio_free(udc->vbus_pin);
11247 +
11248 + free_irq(udc->irq, udc);
11249 + iounmap(udc->fifo);
11250 + iounmap(udc->regs);
11251 + clk_put(udc->hclk);
11252 + clk_put(udc->pclk);
11253 +
11254 + device_unregister(&udc->gadget.dev);
11255 +
11256 + return 0;
11257 +}
11258 +
11259 +static struct platform_driver udc_driver = {
11260 + .probe = usba_udc_probe,
11261 + .remove = __devexit_p(usba_udc_remove),
11262 + .driver = {
11263 + .name = "atmel_usba_udc",
11264 + },
11265 +};
11266 +
11267 +static int __init udc_init(void)
11268 +{
11269 + return platform_driver_register(&udc_driver);
11270 +}
11271 +module_init(udc_init);
11272 +
11273 +static void __exit udc_exit(void)
11274 +{
11275 + platform_driver_unregister(&udc_driver);
11276 +}
11277 +module_exit(udc_exit);
11278 +
11279 +MODULE_DESCRIPTION("Atmel USBA UDC driver");
11280 +MODULE_AUTHOR("Haavard Skinnemoen <hskinnemoen@atmel.com>");
11281 +MODULE_LICENSE("GPL");
11282 diff --git a/drivers/usb/gadget/atmel_usba_udc.h b/drivers/usb/gadget/atmel_usba_udc.h
11283 new file mode 100644
11284 index 0000000..408d2ce
11285 --- /dev/null
11286 +++ b/drivers/usb/gadget/atmel_usba_udc.h
11287 @@ -0,0 +1,402 @@
11288 +/*
11289 + * Driver for the Atmel USBA high speed USB device controller
11290 + *
11291 + * Copyright (C) 2005-2007 Atmel Corporation
11292 + *
11293 + * This program is free software; you can redistribute it and/or modify
11294 + * it under the terms of the GNU General Public License version 2 as
11295 + * published by the Free Software Foundation.
11296 + */
11297 +#ifndef __LINUX_USB_GADGET_USBA_UDC_H__
11298 +#define __LINUX_USB_GADGET_USBA_UDC_H__
11299 +
11300 +/* USB register offsets */
11301 +#define USBA_CTRL 0x0000
11302 +#define USBA_FNUM 0x0004
11303 +#define USBA_INT_ENB 0x0010
11304 +#define USBA_INT_STA 0x0014
11305 +#define USBA_INT_CLR 0x0018
11306 +#define USBA_EPT_RST 0x001c
11307 +#define USBA_TST_SOF_CNT 0x00d0
11308 +#define USBA_TST_CNT_A 0x00d4
11309 +#define USBA_TST_CNT_B 0x00d8
11310 +#define USBA_TST_MODE_REG 0x00dc
11311 +#define USBA_TST 0x00e0
11312 +
11313 +/* USB endpoint register offsets */
11314 +#define USBA_EPT_CFG 0x0000
11315 +#define USBA_EPT_CTL_ENB 0x0004
11316 +#define USBA_EPT_CTL_DIS 0x0008
11317 +#define USBA_EPT_CTL 0x000c
11318 +#define USBA_EPT_SET_STA 0x0014
11319 +#define USBA_EPT_CLR_STA 0x0018
11320 +#define USBA_EPT_STA 0x001c
11321 +
11322 +/* USB DMA register offsets */
11323 +#define USBA_DMA_NXT_DSC 0x0000
11324 +#define USBA_DMA_ADDRESS 0x0004
11325 +#define USBA_DMA_CONTROL 0x0008
11326 +#define USBA_DMA_STATUS 0x000c
11327 +
11328 +/* Bitfields in CTRL */
11329 +#define USBA_DEV_ADDR_OFFSET 0
11330 +#define USBA_DEV_ADDR_SIZE 7
11331 +#define USBA_FADDR_EN_OFFSET 7
11332 +#define USBA_FADDR_EN_SIZE 1
11333 +#define USBA_EN_USBA_OFFSET 8
11334 +#define USBA_EN_USBA_SIZE 1
11335 +#define USBA_DETACH_OFFSET 9
11336 +#define USBA_DETACH_SIZE 1
11337 +#define USBA_REMOTE_WAKE_UP_OFFSET 10
11338 +#define USBA_REMOTE_WAKE_UP_SIZE 1
11339 +
11340 +/* Bitfields in FNUM */
11341 +#define USBA_MICRO_FRAME_NUM_OFFSET 0
11342 +#define USBA_MICRO_FRAME_NUM_SIZE 3
11343 +#define USBA_FRAME_NUMBER_OFFSET 3
11344 +#define USBA_FRAME_NUMBER_SIZE 11
11345 +#define USBA_FRAME_NUM_ERROR_OFFSET 31
11346 +#define USBA_FRAME_NUM_ERROR_SIZE 1
11347 +
11348 +/* Bitfields in INT_ENB/INT_STA/INT_CLR */
11349 +#define USBA_HIGH_SPEED_OFFSET 0
11350 +#define USBA_HIGH_SPEED_SIZE 1
11351 +#define USBA_DET_SUSPEND_OFFSET 1
11352 +#define USBA_DET_SUSPEND_SIZE 1
11353 +#define USBA_MICRO_SOF_OFFSET 2
11354 +#define USBA_MICRO_SOF_SIZE 1
11355 +#define USBA_SOF_OFFSET 3
11356 +#define USBA_SOF_SIZE 1
11357 +#define USBA_END_OF_RESET_OFFSET 4
11358 +#define USBA_END_OF_RESET_SIZE 1
11359 +#define USBA_WAKE_UP_OFFSET 5
11360 +#define USBA_WAKE_UP_SIZE 1
11361 +#define USBA_END_OF_RESUME_OFFSET 6
11362 +#define USBA_END_OF_RESUME_SIZE 1
11363 +#define USBA_UPSTREAM_RESUME_OFFSET 7
11364 +#define USBA_UPSTREAM_RESUME_SIZE 1
11365 +#define USBA_EPT_INT_OFFSET 8
11366 +#define USBA_EPT_INT_SIZE 16
11367 +#define USBA_DMA_INT_OFFSET 24
11368 +#define USBA_DMA_INT_SIZE 8
11369 +
11370 +/* Bitfields in EPT_RST */
11371 +#define USBA_RST_OFFSET 0
11372 +#define USBA_RST_SIZE 16
11373 +
11374 +/* Bitfields in TST_SOF_CNT */
11375 +#define USBA_SOF_CNT_MAX_OFFSET 0
11376 +#define USBA_SOF_CNT_MAX_SIZE 7
11377 +#define USBA_SOF_CNT_LOAD_OFFSET 7
11378 +#define USBA_SOF_CNT_LOAD_SIZE 1
11379 +
11380 +/* Bitfields in TST_CNT_A */
11381 +#define USBA_CNT_A_MAX_OFFSET 0
11382 +#define USBA_CNT_A_MAX_SIZE 7
11383 +#define USBA_CNT_A_LOAD_OFFSET 7
11384 +#define USBA_CNT_A_LOAD_SIZE 1
11385 +
11386 +/* Bitfields in TST_CNT_B */
11387 +#define USBA_CNT_B_MAX_OFFSET 0
11388 +#define USBA_CNT_B_MAX_SIZE 7
11389 +#define USBA_CNT_B_LOAD_OFFSET 7
11390 +#define USBA_CNT_B_LOAD_SIZE 1
11391 +
11392 +/* Bitfields in TST_MODE_REG */
11393 +#define USBA_TST_MODE_OFFSET 0
11394 +#define USBA_TST_MODE_SIZE 6
11395 +
11396 +/* Bitfields in USBA_TST */
11397 +#define USBA_SPEED_CFG_OFFSET 0
11398 +#define USBA_SPEED_CFG_SIZE 2
11399 +#define USBA_TST_J_MODE_OFFSET 2
11400 +#define USBA_TST_J_MODE_SIZE 1
11401 +#define USBA_TST_K_MODE_OFFSET 3
11402 +#define USBA_TST_K_MODE_SIZE 1
11403 +#define USBA_TST_PKT_MODE_OFFSET 4
11404 +#define USBA_TST_PKT_MODE_SIZE 1
11405 +#define USBA_OPMODE2_OFFSET 5
11406 +#define USBA_OPMODE2_SIZE 1
11407 +
11408 +/* Bitfields in EPT_CFG */
11409 +#define USBA_EPT_SIZE_OFFSET 0
11410 +#define USBA_EPT_SIZE_SIZE 3
11411 +#define USBA_EPT_DIR_OFFSET 3
11412 +#define USBA_EPT_DIR_SIZE 1
11413 +#define USBA_EPT_TYPE_OFFSET 4
11414 +#define USBA_EPT_TYPE_SIZE 2
11415 +#define USBA_BK_NUMBER_OFFSET 6
11416 +#define USBA_BK_NUMBER_SIZE 2
11417 +#define USBA_NB_TRANS_OFFSET 8
11418 +#define USBA_NB_TRANS_SIZE 2
11419 +#define USBA_EPT_MAPPED_OFFSET 31
11420 +#define USBA_EPT_MAPPED_SIZE 1
11421 +
11422 +/* Bitfields in EPT_CTL/EPT_CTL_ENB/EPT_CTL_DIS */
11423 +#define USBA_EPT_ENABLE_OFFSET 0
11424 +#define USBA_EPT_ENABLE_SIZE 1
11425 +#define USBA_AUTO_VALID_OFFSET 1
11426 +#define USBA_AUTO_VALID_SIZE 1
11427 +#define USBA_INTDIS_DMA_OFFSET 3
11428 +#define USBA_INTDIS_DMA_SIZE 1
11429 +#define USBA_NYET_DIS_OFFSET 4
11430 +#define USBA_NYET_DIS_SIZE 1
11431 +#define USBA_DATAX_RX_OFFSET 6
11432 +#define USBA_DATAX_RX_SIZE 1
11433 +#define USBA_MDATA_RX_OFFSET 7
11434 +#define USBA_MDATA_RX_SIZE 1
11435 +/* Bits 8-15 and 31 enable interrupts for respective bits in EPT_STA */
11436 +#define USBA_BUSY_BANK_IE_OFFSET 18
11437 +#define USBA_BUSY_BANK_IE_SIZE 1
11438 +
11439 +/* Bitfields in EPT_SET_STA/EPT_CLR_STA/EPT_STA */
11440 +#define USBA_FORCE_STALL_OFFSET 5
11441 +#define USBA_FORCE_STALL_SIZE 1
11442 +#define USBA_TOGGLE_SEQ_OFFSET 6
11443 +#define USBA_TOGGLE_SEQ_SIZE 2
11444 +#define USBA_ERR_OVFLW_OFFSET 8
11445 +#define USBA_ERR_OVFLW_SIZE 1
11446 +#define USBA_RX_BK_RDY_OFFSET 9
11447 +#define USBA_RX_BK_RDY_SIZE 1
11448 +#define USBA_KILL_BANK_OFFSET 9
11449 +#define USBA_KILL_BANK_SIZE 1
11450 +#define USBA_TX_COMPLETE_OFFSET 10
11451 +#define USBA_TX_COMPLETE_SIZE 1
11452 +#define USBA_TX_PK_RDY_OFFSET 11
11453 +#define USBA_TX_PK_RDY_SIZE 1
11454 +#define USBA_ISO_ERR_TRANS_OFFSET 11
11455 +#define USBA_ISO_ERR_TRANS_SIZE 1
11456 +#define USBA_RX_SETUP_OFFSET 12
11457 +#define USBA_RX_SETUP_SIZE 1
11458 +#define USBA_ISO_ERR_FLOW_OFFSET 12
11459 +#define USBA_ISO_ERR_FLOW_SIZE 1
11460 +#define USBA_STALL_SENT_OFFSET 13
11461 +#define USBA_STALL_SENT_SIZE 1
11462 +#define USBA_ISO_ERR_CRC_OFFSET 13
11463 +#define USBA_ISO_ERR_CRC_SIZE 1
11464 +#define USBA_ISO_ERR_NBTRANS_OFFSET 13
11465 +#define USBA_ISO_ERR_NBTRANS_SIZE 1
11466 +#define USBA_NAK_IN_OFFSET 14
11467 +#define USBA_NAK_IN_SIZE 1
11468 +#define USBA_ISO_ERR_FLUSH_OFFSET 14
11469 +#define USBA_ISO_ERR_FLUSH_SIZE 1
11470 +#define USBA_NAK_OUT_OFFSET 15
11471 +#define USBA_NAK_OUT_SIZE 1
11472 +#define USBA_CURRENT_BANK_OFFSET 16
11473 +#define USBA_CURRENT_BANK_SIZE 2
11474 +#define USBA_BUSY_BANKS_OFFSET 18
11475 +#define USBA_BUSY_BANKS_SIZE 2
11476 +#define USBA_BYTE_COUNT_OFFSET 20
11477 +#define USBA_BYTE_COUNT_SIZE 11
11478 +#define USBA_SHORT_PACKET_OFFSET 31
11479 +#define USBA_SHORT_PACKET_SIZE 1
11480 +
11481 +/* Bitfields in DMA_CONTROL */
11482 +#define USBA_DMA_CH_EN_OFFSET 0
11483 +#define USBA_DMA_CH_EN_SIZE 1
11484 +#define USBA_DMA_LINK_OFFSET 1
11485 +#define USBA_DMA_LINK_SIZE 1
11486 +#define USBA_DMA_END_TR_EN_OFFSET 2
11487 +#define USBA_DMA_END_TR_EN_SIZE 1
11488 +#define USBA_DMA_END_BUF_EN_OFFSET 3
11489 +#define USBA_DMA_END_BUF_EN_SIZE 1
11490 +#define USBA_DMA_END_TR_IE_OFFSET 4
11491 +#define USBA_DMA_END_TR_IE_SIZE 1
11492 +#define USBA_DMA_END_BUF_IE_OFFSET 5
11493 +#define USBA_DMA_END_BUF_IE_SIZE 1
11494 +#define USBA_DMA_DESC_LOAD_IE_OFFSET 6
11495 +#define USBA_DMA_DESC_LOAD_IE_SIZE 1
11496 +#define USBA_DMA_BURST_LOCK_OFFSET 7
11497 +#define USBA_DMA_BURST_LOCK_SIZE 1
11498 +#define USBA_DMA_BUF_LEN_OFFSET 16
11499 +#define USBA_DMA_BUF_LEN_SIZE 16
11500 +
11501 +/* Bitfields in DMA_STATUS */
11502 +#define USBA_DMA_CH_ACTIVE_OFFSET 1
11503 +#define USBA_DMA_CH_ACTIVE_SIZE 1
11504 +#define USBA_DMA_END_TR_ST_OFFSET 4
11505 +#define USBA_DMA_END_TR_ST_SIZE 1
11506 +#define USBA_DMA_END_BUF_ST_OFFSET 5
11507 +#define USBA_DMA_END_BUF_ST_SIZE 1
11508 +#define USBA_DMA_DESC_LOAD_ST_OFFSET 6
11509 +#define USBA_DMA_DESC_LOAD_ST_SIZE 1
11510 +
11511 +/* Constants for SPEED_CFG */
11512 +#define USBA_SPEED_CFG_NORMAL 0
11513 +#define USBA_SPEED_CFG_FORCE_HIGH 2
11514 +#define USBA_SPEED_CFG_FORCE_FULL 3
11515 +
11516 +/* Constants for EPT_SIZE */
11517 +#define USBA_EPT_SIZE_8 0
11518 +#define USBA_EPT_SIZE_16 1
11519 +#define USBA_EPT_SIZE_32 2
11520 +#define USBA_EPT_SIZE_64 3
11521 +#define USBA_EPT_SIZE_128 4
11522 +#define USBA_EPT_SIZE_256 5
11523 +#define USBA_EPT_SIZE_512 6
11524 +#define USBA_EPT_SIZE_1024 7
11525 +
11526 +/* Constants for EPT_TYPE */
11527 +#define USBA_EPT_TYPE_CONTROL 0
11528 +#define USBA_EPT_TYPE_ISO 1
11529 +#define USBA_EPT_TYPE_BULK 2
11530 +#define USBA_EPT_TYPE_INT 3
11531 +
11532 +/* Constants for BK_NUMBER */
11533 +#define USBA_BK_NUMBER_ZERO 0
11534 +#define USBA_BK_NUMBER_ONE 1
11535 +#define USBA_BK_NUMBER_DOUBLE 2
11536 +#define USBA_BK_NUMBER_TRIPLE 3
11537 +
11538 +/* Bit manipulation macros */
11539 +#define USBA_BIT(name) \
11540 + (1 << USBA_##name##_OFFSET)
11541 +#define USBA_BF(name, value) \
11542 + (((value) & ((1 << USBA_##name##_SIZE) - 1)) \
11543 + << USBA_##name##_OFFSET)
11544 +#define USBA_BFEXT(name, value) \
11545 + (((value) >> USBA_##name##_OFFSET) \
11546 + & ((1 << USBA_##name##_SIZE) - 1))
11547 +#define USBA_BFINS(name, value, old) \
11548 + (((old) & ~(((1 << USBA_##name##_SIZE) - 1) \
11549 + << USBA_##name##_OFFSET)) \
11550 + | USBA_BF(name, value))
11551 +
11552 +/* Register access macros */
11553 +#define usba_readl(udc, reg) \
11554 + __raw_readl((udc)->regs + USBA_##reg)
11555 +#define usba_writel(udc, reg, value) \
11556 + __raw_writel((value), (udc)->regs + USBA_##reg)
11557 +#define usba_ep_readl(ep, reg) \
11558 + __raw_readl((ep)->ep_regs + USBA_EPT_##reg)
11559 +#define usba_ep_writel(ep, reg, value) \
11560 + __raw_writel((value), (ep)->ep_regs + USBA_EPT_##reg)
11561 +#define usba_dma_readl(ep, reg) \
11562 + __raw_readl((ep)->dma_regs + USBA_DMA_##reg)
11563 +#define usba_dma_writel(ep, reg, value) \
11564 + __raw_writel((value), (ep)->dma_regs + USBA_DMA_##reg)
11565 +
11566 +/* Calculate base address for a given endpoint or DMA controller */
11567 +#define USBA_EPT_BASE(x) (0x100 + (x) * 0x20)
11568 +#define USBA_DMA_BASE(x) (0x300 + (x) * 0x10)
11569 +#define USBA_FIFO_BASE(x) ((x) << 16)
11570 +
11571 +/* Synth parameters */
11572 +#define USBA_NR_ENDPOINTS 7
11573 +
11574 +#define EP0_FIFO_SIZE 64
11575 +#define EP0_EPT_SIZE USBA_EPT_SIZE_64
11576 +#define EP0_NR_BANKS 1
11577 +#define BULK_FIFO_SIZE 512
11578 +#define BULK_EPT_SIZE USBA_EPT_SIZE_512
11579 +#define BULK_NR_BANKS 2
11580 +#define ISO_FIFO_SIZE 1024
11581 +#define ISO_EPT_SIZE USBA_EPT_SIZE_1024
11582 +#define ISO_NR_BANKS 3
11583 +#define INT_FIFO_SIZE 64
11584 +#define INT_EPT_SIZE USBA_EPT_SIZE_64
11585 +#define INT_NR_BANKS 3
11586 +
11587 +enum usba_ctrl_state {
11588 + WAIT_FOR_SETUP,
11589 + DATA_STAGE_IN,
11590 + DATA_STAGE_OUT,
11591 + STATUS_STAGE_IN,
11592 + STATUS_STAGE_OUT,
11593 + STATUS_STAGE_ADDR,
11594 + STATUS_STAGE_TEST,
11595 +};
11596 +/*
11597 + EP_STATE_IDLE,
11598 + EP_STATE_SETUP,
11599 + EP_STATE_IN_DATA,
11600 + EP_STATE_OUT_DATA,
11601 + EP_STATE_SET_ADDR_STATUS,
11602 + EP_STATE_RX_STATUS,
11603 + EP_STATE_TX_STATUS,
11604 + EP_STATE_HALT,
11605 +*/
11606 +
11607 +struct usba_dma_desc {
11608 + dma_addr_t next;
11609 + dma_addr_t addr;
11610 + u32 ctrl;
11611 +};
11612 +
11613 +struct usba_ep {
11614 + int state;
11615 + void __iomem *ep_regs;
11616 + void __iomem *dma_regs;
11617 + void __iomem *fifo;
11618 + struct usb_ep ep;
11619 + struct usba_udc *udc;
11620 +
11621 + struct list_head queue;
11622 + const struct usb_endpoint_descriptor *desc;
11623 +
11624 + u16 fifo_size;
11625 + u8 nr_banks;
11626 + u8 index;
11627 + unsigned int can_dma:1;
11628 + unsigned int can_isoc:1;
11629 + unsigned int is_isoc:1;
11630 + unsigned int is_in:1;
11631 +
11632 +#ifdef CONFIG_DEBUG_FS
11633 + u32 last_dma_status;
11634 + struct dentry *debugfs_dir;
11635 + struct dentry *debugfs_queue;
11636 + struct dentry *debugfs_dma_status;
11637 + struct dentry *debugfs_state;
11638 +#endif
11639 +};
11640 +
11641 +struct usba_request {
11642 + struct usb_request req;
11643 + struct list_head queue;
11644 +
11645 + u32 ctrl;
11646 +
11647 + unsigned int submitted:1;
11648 + unsigned int last_transaction:1;
11649 + unsigned int using_dma:1;
11650 + unsigned int mapped:1;
11651 +};
11652 +
11653 +struct usba_udc {
11654 + /* Protect hw registers from concurrent modifications */
11655 + spinlock_t lock;
11656 +
11657 + void __iomem *regs;
11658 + void __iomem *fifo;
11659 +
11660 + struct usb_gadget gadget;
11661 + struct usb_gadget_driver *driver;
11662 + struct platform_device *pdev;
11663 + int irq;
11664 + int vbus_pin;
11665 + struct clk *pclk;
11666 + struct clk *hclk;
11667 +
11668 + int test_mode;
11669 + int vbus_prev;
11670 +
11671 +#ifdef CONFIG_DEBUG_FS
11672 + struct dentry *debugfs_root;
11673 + struct dentry *debugfs_regs;
11674 +#endif
11675 +};
11676 +
11677 +#define to_usba_ep(x) container_of((x), struct usba_ep, ep)
11678 +#define to_usba_req(x) container_of((x), struct usba_request, req)
11679 +#define to_usba_udc(x) container_of((x), struct usba_udc, gadget)
11680 +
11681 +#define ep_index(ep) ((ep)->index)
11682 +#define ep_can_dma(ep) ((ep)->can_dma)
11683 +#define ep_is_in(ep) ((ep)->is_in)
11684 +#define ep_is_isochronous(ep) ((ep)->is_isoc)
11685 +#define ep_is_control(ep) (ep_index(ep) == 0)
11686 +#define ep_name(ep) ((ep)->ep.name)
11687 +#define ep_is_idle(ep) ((ep)->state == EP_STATE_IDLE)
11688 +
11689 +#endif /* __LINUX_USB_GADGET_USBA_UDC_H */
11690 diff --git a/drivers/usb/gadget/ether.c b/drivers/usb/gadget/ether.c
11691 index 325bf7c..23e874b 100644
11692 --- a/drivers/usb/gadget/ether.c
11693 +++ b/drivers/usb/gadget/ether.c
11694 @@ -277,7 +277,7 @@ MODULE_PARM_DESC(host_addr, "Host Ethernet Address");
11695 #define DEV_CONFIG_CDC
11696 #endif
11697
11698 -#ifdef CONFIG_USB_GADGET_HUSB2DEV
11699 +#ifdef CONFIG_USB_GADGET_ATMEL_USBA
11700 #define DEV_CONFIG_CDC
11701 #endif
11702
11703 diff --git a/drivers/usb/gadget/gadget_chips.h b/drivers/usb/gadget/gadget_chips.h
11704 index d041b91..96e4dbc 100644
11705 --- a/drivers/usb/gadget/gadget_chips.h
11706 +++ b/drivers/usb/gadget/gadget_chips.h
11707 @@ -75,10 +75,10 @@
11708 #define gadget_is_pxa27x(g) 0
11709 #endif
11710
11711 -#ifdef CONFIG_USB_GADGET_HUSB2DEV
11712 -#define gadget_is_husb2dev(g) !strcmp("husb2_udc", (g)->name)
11713 +#ifdef CONFIG_USB_GADGET_ATMEL_USBA
11714 +#define gadget_is_atmel_usba(g) !strcmp("atmel_usba_udc", (g)->name)
11715 #else
11716 -#define gadget_is_husb2dev(g) 0
11717 +#define gadget_is_atmel_usba(g) 0
11718 #endif
11719
11720 #ifdef CONFIG_USB_GADGET_S3C2410
11721 @@ -181,7 +181,7 @@ static inline int usb_gadget_controller_number(struct usb_gadget *gadget)
11722 return 0x16;
11723 else if (gadget_is_mpc8272(gadget))
11724 return 0x17;
11725 - else if (gadget_is_husb2dev(gadget))
11726 + else if (gadget_is_atmel_usba(gadget))
11727 return 0x18;
11728 else if (gadget_is_fsl_usb2(gadget))
11729 return 0x19;
11730 diff --git a/drivers/usb/gadget/inode.c b/drivers/usb/gadget/inode.c
11731 index 46d0e52..855f8cc 100644
11732 --- a/drivers/usb/gadget/inode.c
11733 +++ b/drivers/usb/gadget/inode.c
11734 @@ -37,7 +37,7 @@
11735 #include <linux/device.h>
11736 #include <linux/moduleparam.h>
11737
11738 -#include <linux/usb_gadgetfs.h>
11739 +#include <linux/usb/gadgetfs.h>
11740 #include <linux/usb_gadget.h>
11741
11742
11743 diff --git a/drivers/video/Kconfig b/drivers/video/Kconfig
11744 index 403dac7..f3e2897 100644
11745 --- a/drivers/video/Kconfig
11746 +++ b/drivers/video/Kconfig
11747 @@ -849,6 +849,16 @@ config FB_INTSRAM
11748 Say Y if you want to map Frame Buffer in internal SRAM. Say N if you want
11749 to let frame buffer in external SDRAM.
11750
11751 +config FB_ATMEL_STN
11752 + bool "Use a STN display with AT91/AT32 LCD Controller"
11753 + depends on FB_ATMEL && ARCH_AT91SAM9261
11754 + default n
11755 + help
11756 + Say Y if you want to connect a STN LCD display to the AT91/AT32 LCD
11757 + Controller. Say N if you want to connect a TFT.
11758 +
11759 + If unsure, say N.
11760 +
11761 config FB_NVIDIA
11762 tristate "nVidia Framebuffer Support"
11763 depends on FB && PCI
11764 diff --git a/drivers/video/atmel_lcdfb.c b/drivers/video/atmel_lcdfb.c
11765 index e1d5bd0..bb361ab 100644
11766 --- a/drivers/video/atmel_lcdfb.c
11767 +++ b/drivers/video/atmel_lcdfb.c
11768 @@ -37,7 +37,9 @@
11769 #endif
11770
11771 #if defined(CONFIG_ARCH_AT91)
11772 -#define ATMEL_LCDFB_FBINFO_DEFAULT FBINFO_DEFAULT
11773 +#define ATMEL_LCDFB_FBINFO_DEFAULT (FBINFO_DEFAULT \
11774 + | FBINFO_PARTIAL_PAN_OK \
11775 + | FBINFO_HWACCEL_YPAN)
11776
11777 static inline void atmel_lcdfb_update_dma2d(struct atmel_lcdfb_info *sinfo,
11778 struct fb_var_screeninfo *var)
11779 @@ -74,11 +76,34 @@ static struct fb_fix_screeninfo atmel_lcdfb_fix __initdata = {
11780 .type = FB_TYPE_PACKED_PIXELS,
11781 .visual = FB_VISUAL_TRUECOLOR,
11782 .xpanstep = 0,
11783 - .ypanstep = 0,
11784 + .ypanstep = 1,
11785 .ywrapstep = 0,
11786 .accel = FB_ACCEL_NONE,
11787 };
11788
11789 +static unsigned long compute_hozval(unsigned long xres, unsigned long lcdcon2)
11790 +{
11791 + unsigned long value;
11792 +
11793 + if (!(cpu_is_at91sam9261() || cpu_is_at32ap7000()))
11794 + return xres;
11795 +
11796 + value = xres;
11797 + if ((lcdcon2 & ATMEL_LCDC_DISTYPE) != ATMEL_LCDC_DISTYPE_TFT) {
11798 + /* STN display */
11799 + if ((lcdcon2 & ATMEL_LCDC_DISTYPE) == ATMEL_LCDC_DISTYPE_STNCOLOR) {
11800 + value *= 3;
11801 + }
11802 + if ( (lcdcon2 & ATMEL_LCDC_IFWIDTH) == ATMEL_LCDC_IFWIDTH_4
11803 + || ( (lcdcon2 & ATMEL_LCDC_IFWIDTH) == ATMEL_LCDC_IFWIDTH_8
11804 + && (lcdcon2 & ATMEL_LCDC_SCANMOD) == ATMEL_LCDC_SCANMOD_DUAL ))
11805 + value = DIV_ROUND_UP(value, 4);
11806 + else
11807 + value = DIV_ROUND_UP(value, 8);
11808 + }
11809 +
11810 + return value;
11811 +}
11812
11813 static void atmel_lcdfb_update_dma(struct fb_info *info,
11814 struct fb_var_screeninfo *var)
11815 @@ -181,6 +206,7 @@ static int atmel_lcdfb_check_var(struct fb_var_screeninfo *var,
11816 var->xoffset = var->yoffset = 0;
11817
11818 switch (var->bits_per_pixel) {
11819 + case 1:
11820 case 2:
11821 case 4:
11822 case 8:
11823 @@ -195,8 +221,11 @@ static int atmel_lcdfb_check_var(struct fb_var_screeninfo *var,
11824 var->blue.offset = 10;
11825 var->red.length = var->green.length = var->blue.length = 5;
11826 break;
11827 - case 24:
11828 case 32:
11829 + var->transp.offset = 24;
11830 + var->transp.length = 8;
11831 + /* fall through */
11832 + case 24:
11833 var->red.offset = 0;
11834 var->green.offset = 8;
11835 var->blue.offset = 16;
11836 @@ -228,8 +257,10 @@ static int atmel_lcdfb_check_var(struct fb_var_screeninfo *var,
11837 static int atmel_lcdfb_set_par(struct fb_info *info)
11838 {
11839 struct atmel_lcdfb_info *sinfo = info->par;
11840 + unsigned long hozval_linesz;
11841 unsigned long value;
11842 unsigned long clk_value_khz;
11843 + unsigned long bits_per_line;
11844
11845 dev_dbg(info->device, "%s:\n", __func__);
11846 dev_dbg(info->device, " * resolution: %ux%u (%ux%u virtual)\n",
11847 @@ -241,12 +272,15 @@ static int atmel_lcdfb_set_par(struct fb_info *info)
11848
11849 lcdc_writel(sinfo, ATMEL_LCDC_DMACON, 0);
11850
11851 - if (info->var.bits_per_pixel <= 8)
11852 + if (info->var.bits_per_pixel == 1)
11853 + info->fix.visual = FB_VISUAL_MONO01;
11854 + else if (info->var.bits_per_pixel <= 8)
11855 info->fix.visual = FB_VISUAL_PSEUDOCOLOR;
11856 else
11857 info->fix.visual = FB_VISUAL_TRUECOLOR;
11858
11859 - info->fix.line_length = info->var.xres_virtual * (info->var.bits_per_pixel / 8);
11860 + bits_per_line = info->var.xres_virtual * info->var.bits_per_pixel;
11861 + info->fix.line_length = DIV_ROUND_UP(bits_per_line, 8);
11862
11863 /* Re-initialize the DMA engine... */
11864 dev_dbg(info->device, " * update DMA engine\n");
11865 @@ -262,18 +296,21 @@ static int atmel_lcdfb_set_par(struct fb_info *info)
11866 /* Set pixel clock */
11867 clk_value_khz = clk_get_rate(sinfo->lcdc_clk) / 1000;
11868
11869 - value = clk_value_khz / PICOS2KHZ(info->var.pixclock);
11870 -
11871 - if (clk_value_khz % PICOS2KHZ(info->var.pixclock))
11872 - value++;
11873 + value = DIV_ROUND_UP(clk_value_khz, PICOS2KHZ(info->var.pixclock));
11874
11875 value = (value / 2) - 1;
11876 + dev_dbg(info->device, " * programming CLKVAL = 0x%08lx\n", value);
11877
11878 if (value <= 0) {
11879 dev_notice(info->device, "Bypassing pixel clock divider\n");
11880 lcdc_writel(sinfo, ATMEL_LCDC_LCDCON1, ATMEL_LCDC_BYPASS);
11881 - } else
11882 + } else {
11883 lcdc_writel(sinfo, ATMEL_LCDC_LCDCON1, value << ATMEL_LCDC_CLKVAL_OFFSET);
11884 + info->var.pixclock = KHZ2PICOS(clk_value_khz / (2 * (value + 1)));
11885 + dev_dbg(info->device, " updated pixclk: %lu KHz\n",
11886 + PICOS2KHZ(info->var.pixclock));
11887 + }
11888 +
11889
11890 /* Initialize control register 2 */
11891 value = sinfo->default_lcdcon2;
11892 @@ -311,9 +348,14 @@ static int atmel_lcdfb_set_par(struct fb_info *info)
11893 dev_dbg(info->device, " * LCDTIM2 = %08lx\n", value);
11894 lcdc_writel(sinfo, ATMEL_LCDC_TIM2, value);
11895
11896 + /* Horizontal value (aka line size) */
11897 + hozval_linesz = compute_hozval(info->var.xres,
11898 + lcdc_readl(sinfo, ATMEL_LCDC_LCDCON2));
11899 +
11900 /* Display size */
11901 - value = (info->var.xres - 1) << ATMEL_LCDC_HOZVAL_OFFSET;
11902 + value = (hozval_linesz - 1) << ATMEL_LCDC_HOZVAL_OFFSET;
11903 value |= info->var.yres - 1;
11904 + dev_dbg(info->device, " * LCDFRMCFG = %08lx\n", value);
11905 lcdc_writel(sinfo, ATMEL_LCDC_LCDFRMCFG, value);
11906
11907 /* FIFO Threshold: Use formula from data sheet */
11908 @@ -421,6 +463,15 @@ static int atmel_lcdfb_setcolreg(unsigned int regno, unsigned int red,
11909 ret = 0;
11910 }
11911 break;
11912 +
11913 + case FB_VISUAL_MONO01:
11914 + if (regno < 2) {
11915 + val = (regno == 0) ? 0x00 : 0x1F;
11916 + lcdc_writel(sinfo, ATMEL_LCDC_LUT(regno), val);
11917 + ret = 0;
11918 + }
11919 + break;
11920 +
11921 }
11922
11923 return ret;
11924 diff --git a/drivers/video/backlight/Kconfig b/drivers/video/backlight/Kconfig
11925 index fbef663..b6f936a 100644
11926 --- a/drivers/video/backlight/Kconfig
11927 +++ b/drivers/video/backlight/Kconfig
11928 @@ -8,26 +8,44 @@ menuconfig BACKLIGHT_LCD_SUPPORT
11929 Enable this to be able to choose the drivers for controlling the
11930 backlight and the LCD panel on some platforms, for example on PDAs.
11931
11932 -config BACKLIGHT_CLASS_DEVICE
11933 - tristate "Lowlevel Backlight controls"
11934 +#
11935 +# LCD
11936 +#
11937 +config LCD_CLASS_DEVICE
11938 + tristate "Lowlevel LCD controls"
11939 depends on BACKLIGHT_LCD_SUPPORT
11940 default m
11941 help
11942 - This framework adds support for low-level control of the LCD
11943 - backlight. This includes support for brightness and power.
11944 + This framework adds support for low-level control of LCD.
11945 + Some framebuffer devices connect to platform-specific LCD modules
11946 + in order to have a platform-specific way to control the flat panel
11947 + (contrast and applying power to the LCD (not to the backlight!)).
11948
11949 To have support for your specific LCD panel you will have to
11950 select the proper drivers which depend on this option.
11951
11952 -config LCD_CLASS_DEVICE
11953 - tristate "Lowlevel LCD controls"
11954 +config LCD_LTV350QV
11955 + tristate "Samsung LTV350QV LCD Panel"
11956 + depends on LCD_CLASS_DEVICE && SPI_MASTER
11957 + default n
11958 + help
11959 + If you have a Samsung LTV350QV LCD panel, say y to include a
11960 + power control driver for it. The panel starts up in power
11961 + off state, so you need this driver in order to see any
11962 + output.
11963 +
11964 + The LTV350QV panel is present on all ATSTK1000 boards.
11965 +
11966 +#
11967 +# Backlight
11968 +#
11969 +config BACKLIGHT_CLASS_DEVICE
11970 + tristate "Lowlevel Backlight controls"
11971 depends on BACKLIGHT_LCD_SUPPORT
11972 default m
11973 help
11974 - This framework adds support for low-level control of LCD.
11975 - Some framebuffer devices connect to platform-specific LCD modules
11976 - in order to have a platform-specific way to control the flat panel
11977 - (contrast and applying power to the LCD (not to the backlight!)).
11978 + This framework adds support for low-level control of the LCD
11979 + backlight. This includes support for brightness and power.
11980
11981 To have support for your specific LCD panel you will have to
11982 select the proper drivers which depend on this option.
11983 diff --git a/drivers/video/backlight/Makefile b/drivers/video/backlight/Makefile
11984 index c6e2266..965a78b 100644
11985 --- a/drivers/video/backlight/Makefile
11986 +++ b/drivers/video/backlight/Makefile
11987 @@ -1,6 +1,8 @@
11988 # Backlight & LCD drivers
11989
11990 obj-$(CONFIG_LCD_CLASS_DEVICE) += lcd.o
11991 +obj-$(CONFIG_LCD_LTV350QV) += ltv350qv.o
11992 +
11993 obj-$(CONFIG_BACKLIGHT_CLASS_DEVICE) += backlight.o
11994 obj-$(CONFIG_BACKLIGHT_CORGI) += corgi_bl.o
11995 obj-$(CONFIG_BACKLIGHT_HP680) += hp680_bl.o
11996 diff --git a/drivers/video/backlight/ltv350qv.c b/drivers/video/backlight/ltv350qv.c
11997 new file mode 100644
11998 index 0000000..342b97a
11999 --- /dev/null
12000 +++ b/drivers/video/backlight/ltv350qv.c
12001 @@ -0,0 +1,340 @@
12002 +/*
12003 + * Power control for Samsung LTV350QV Quarter VGA LCD Panel
12004 + *
12005 + * Copyright (C) 2006, 2007 Atmel Corporation
12006 + *
12007 + * This program is free software; you can redistribute it and/or modify
12008 + * it under the terms of the GNU General Public License version 2 as
12009 + * published by the Free Software Foundation.
12010 + */
12011 +#include <linux/delay.h>
12012 +#include <linux/err.h>
12013 +#include <linux/fb.h>
12014 +#include <linux/init.h>
12015 +#include <linux/lcd.h>
12016 +#include <linux/module.h>
12017 +#include <linux/spi/spi.h>
12018 +
12019 +#include "ltv350qv.h"
12020 +
12021 +#define POWER_IS_ON(pwr) ((pwr) <= FB_BLANK_NORMAL)
12022 +
12023 +struct ltv350qv {
12024 + struct spi_device *spi;
12025 + u8 *buffer;
12026 + int power;
12027 + struct lcd_device *ld;
12028 +};
12029 +
12030 +/*
12031 + * The power-on and power-off sequences are taken from the
12032 + * LTV350QV-F04 data sheet from Samsung. The register definitions are
12033 + * taken from the S6F2002 command list also from Samsung. Both
12034 + * documents are distributed with the AVR32 Linux BSP CD from Atmel.
12035 + *
12036 + * There's still some voodoo going on here, but it's a lot better than
12037 + * in the first incarnation of the driver where all we had was the raw
12038 + * numbers from the initialization sequence.
12039 + */
12040 +static int ltv350qv_write_reg(struct ltv350qv *lcd, u8 reg, u16 val)
12041 +{
12042 + struct spi_message msg;
12043 + struct spi_transfer index_xfer = {
12044 + .len = 3,
12045 + .cs_change = 1,
12046 + };
12047 + struct spi_transfer value_xfer = {
12048 + .len = 3,
12049 + .cs_change = 1,
12050 + };
12051 +
12052 + spi_message_init(&msg);
12053 +
12054 + /* register index */
12055 + lcd->buffer[0] = LTV_OPC_INDEX;
12056 + lcd->buffer[1] = 0x00;
12057 + lcd->buffer[2] = reg & 0x7f;
12058 + index_xfer.tx_buf = lcd->buffer;
12059 + spi_message_add_tail(&index_xfer, &msg);
12060 +
12061 + /* register value */
12062 + lcd->buffer[4] = LTV_OPC_DATA;
12063 + lcd->buffer[5] = val >> 8;
12064 + lcd->buffer[6] = val;
12065 + value_xfer.tx_buf = lcd->buffer + 4;
12066 + spi_message_add_tail(&value_xfer, &msg);
12067 +
12068 + return spi_sync(lcd->spi, &msg);
12069 +}
12070 +
12071 +/* The comments are taken straight from the data sheet */
12072 +static int ltv350qv_power_on(struct ltv350qv *lcd)
12073 +{
12074 + int ret;
12075 +
12076 + /* Power On Reset Display off State */
12077 + if (ltv350qv_write_reg(lcd, LTV_PWRCTL1, 0x0000))
12078 + goto err;
12079 + msleep(15);
12080 +
12081 + /* Power Setting Function 1 */
12082 + if (ltv350qv_write_reg(lcd, LTV_PWRCTL1, LTV_VCOM_DISABLE))
12083 + goto err;
12084 + if (ltv350qv_write_reg(lcd, LTV_PWRCTL2, LTV_VCOML_ENABLE))
12085 + goto err_power1;
12086 +
12087 + /* Power Setting Function 2 */
12088 + if (ltv350qv_write_reg(lcd, LTV_PWRCTL1,
12089 + LTV_VCOM_DISABLE | LTV_DRIVE_CURRENT(5)
12090 + | LTV_SUPPLY_CURRENT(5)))
12091 + goto err_power2;
12092 +
12093 + msleep(55);
12094 +
12095 + /* Instruction Setting */
12096 + ret = ltv350qv_write_reg(lcd, LTV_IFCTL,
12097 + LTV_NMD | LTV_REV | LTV_NL(0x1d));
12098 + ret |= ltv350qv_write_reg(lcd, LTV_DATACTL,
12099 + LTV_DS_SAME | LTV_CHS_480
12100 + | LTV_DF_RGB | LTV_RGB_BGR);
12101 + ret |= ltv350qv_write_reg(lcd, LTV_ENTRY_MODE,
12102 + LTV_VSPL_ACTIVE_LOW
12103 + | LTV_HSPL_ACTIVE_LOW
12104 + | LTV_DPL_SAMPLE_RISING
12105 + | LTV_EPL_ACTIVE_LOW
12106 + | LTV_SS_RIGHT_TO_LEFT);
12107 + ret |= ltv350qv_write_reg(lcd, LTV_GATECTL1, LTV_CLW(3));
12108 + ret |= ltv350qv_write_reg(lcd, LTV_GATECTL2,
12109 + LTV_NW_INV_1LINE | LTV_FWI(3));
12110 + ret |= ltv350qv_write_reg(lcd, LTV_VBP, 0x000a);
12111 + ret |= ltv350qv_write_reg(lcd, LTV_HBP, 0x0021);
12112 + ret |= ltv350qv_write_reg(lcd, LTV_SOTCTL, LTV_SDT(3) | LTV_EQ(0));
12113 + ret |= ltv350qv_write_reg(lcd, LTV_GAMMA(0), 0x0103);
12114 + ret |= ltv350qv_write_reg(lcd, LTV_GAMMA(1), 0x0301);
12115 + ret |= ltv350qv_write_reg(lcd, LTV_GAMMA(2), 0x1f0f);
12116 + ret |= ltv350qv_write_reg(lcd, LTV_GAMMA(3), 0x1f0f);
12117 + ret |= ltv350qv_write_reg(lcd, LTV_GAMMA(4), 0x0707);
12118 + ret |= ltv350qv_write_reg(lcd, LTV_GAMMA(5), 0x0307);
12119 + ret |= ltv350qv_write_reg(lcd, LTV_GAMMA(6), 0x0707);
12120 + ret |= ltv350qv_write_reg(lcd, LTV_GAMMA(7), 0x0000);
12121 + ret |= ltv350qv_write_reg(lcd, LTV_GAMMA(8), 0x0004);
12122 + ret |= ltv350qv_write_reg(lcd, LTV_GAMMA(9), 0x0000);
12123 + if (ret)
12124 + goto err_settings;
12125 +
12126 + /* Wait more than 2 frames */
12127 + msleep(20);
12128 +
12129 + /* Display On Sequence */
12130 + ret = ltv350qv_write_reg(lcd, LTV_PWRCTL1,
12131 + LTV_VCOM_DISABLE | LTV_VCOMOUT_ENABLE
12132 + | LTV_POWER_ON | LTV_DRIVE_CURRENT(5)
12133 + | LTV_SUPPLY_CURRENT(5));
12134 + ret |= ltv350qv_write_reg(lcd, LTV_GATECTL2,
12135 + LTV_NW_INV_1LINE | LTV_DSC | LTV_FWI(3));
12136 + if (ret)
12137 + goto err_disp_on;
12138 +
12139 + /* Display should now be ON. Phew. */
12140 + return 0;
12141 +
12142 +err_disp_on:
12143 + /*
12144 + * Try to recover. Error handling probably isn't very useful
12145 + * at this point, just make a best effort to switch the panel
12146 + * off.
12147 + */
12148 + ltv350qv_write_reg(lcd, LTV_PWRCTL1,
12149 + LTV_VCOM_DISABLE | LTV_DRIVE_CURRENT(5)
12150 + | LTV_SUPPLY_CURRENT(5));
12151 + ltv350qv_write_reg(lcd, LTV_GATECTL2,
12152 + LTV_NW_INV_1LINE | LTV_FWI(3));
12153 +err_settings:
12154 +err_power2:
12155 +err_power1:
12156 + ltv350qv_write_reg(lcd, LTV_PWRCTL2, 0x0000);
12157 + msleep(1);
12158 +err:
12159 + ltv350qv_write_reg(lcd, LTV_PWRCTL1, LTV_VCOM_DISABLE);
12160 + return -EIO;
12161 +}
12162 +
12163 +static int ltv350qv_power_off(struct ltv350qv *lcd)
12164 +{
12165 + int ret;
12166 +
12167 + /* Display Off Sequence */
12168 + ret = ltv350qv_write_reg(lcd, LTV_PWRCTL1,
12169 + LTV_VCOM_DISABLE
12170 + | LTV_DRIVE_CURRENT(5)
12171 + | LTV_SUPPLY_CURRENT(5));
12172 + ret |= ltv350qv_write_reg(lcd, LTV_GATECTL2,
12173 + LTV_NW_INV_1LINE | LTV_FWI(3));
12174 +
12175 + /* Power down setting 1 */
12176 + ret |= ltv350qv_write_reg(lcd, LTV_PWRCTL2, 0x0000);
12177 +
12178 + /* Wait at least 1 ms */
12179 + msleep(1);
12180 +
12181 + /* Power down setting 2 */
12182 + ret |= ltv350qv_write_reg(lcd, LTV_PWRCTL1, LTV_VCOM_DISABLE);
12183 +
12184 + /*
12185 + * No point in trying to recover here. If we can't switch the
12186 + * panel off, what are we supposed to do other than inform the
12187 + * user about the failure?
12188 + */
12189 + if (ret)
12190 + return -EIO;
12191 +
12192 + /* Display power should now be OFF */
12193 + return 0;
12194 +}
12195 +
12196 +static int ltv350qv_power(struct ltv350qv *lcd, int power)
12197 +{
12198 + int ret = 0;
12199 +
12200 + if (POWER_IS_ON(power) && !POWER_IS_ON(lcd->power))
12201 + ret = ltv350qv_power_on(lcd);
12202 + else if (!POWER_IS_ON(power) && POWER_IS_ON(lcd->power))
12203 + ret = ltv350qv_power_off(lcd);
12204 +
12205 + if (!ret)
12206 + lcd->power = power;
12207 +
12208 + return ret;
12209 +}
12210 +
12211 +static int ltv350qv_set_power(struct lcd_device *ld, int power)
12212 +{
12213 + struct ltv350qv *lcd;
12214 +
12215 + lcd = class_get_devdata(&ld->class_dev);
12216 + return ltv350qv_power(lcd, power);
12217 +}
12218 +
12219 +static int ltv350qv_get_power(struct lcd_device *ld)
12220 +{
12221 + struct ltv350qv *lcd;
12222 +
12223 + lcd = class_get_devdata(&ld->class_dev);
12224 + return lcd->power;
12225 +}
12226 +
12227 +static struct lcd_ops ltv_ops = {
12228 + .get_power = ltv350qv_get_power,
12229 + .set_power = ltv350qv_set_power,
12230 +};
12231 +
12232 +static int __devinit ltv350qv_probe(struct spi_device *spi)
12233 +{
12234 + struct ltv350qv *lcd;
12235 + struct lcd_device *ld;
12236 + int ret;
12237 +
12238 + lcd = kzalloc(sizeof(struct ltv350qv), GFP_KERNEL);
12239 + if (!lcd)
12240 + return -ENOMEM;
12241 +
12242 + lcd->spi = spi;
12243 + lcd->power = FB_BLANK_POWERDOWN;
12244 + lcd->buffer = kzalloc(8, GFP_KERNEL);
12245 +
12246 + ld = lcd_device_register("ltv350qv", lcd, &ltv_ops);
12247 + if (IS_ERR(ld)) {
12248 + ret = PTR_ERR(ld);
12249 + goto out_free_lcd;
12250 + }
12251 + lcd->ld = ld;
12252 +
12253 + ret = ltv350qv_power(lcd, FB_BLANK_UNBLANK);
12254 + if (ret)
12255 + goto out_unregister;
12256 +
12257 + dev_set_drvdata(&spi->dev, lcd);
12258 +
12259 + return 0;
12260 +
12261 +out_unregister:
12262 + lcd_device_unregister(ld);
12263 +out_free_lcd:
12264 + kfree(lcd);
12265 + return ret;
12266 +}
12267 +
12268 +static int __devexit ltv350qv_remove(struct spi_device *spi)
12269 +{
12270 + struct ltv350qv *lcd = dev_get_drvdata(&spi->dev);
12271 +
12272 + ltv350qv_power(lcd, FB_BLANK_POWERDOWN);
12273 + lcd_device_unregister(lcd->ld);
12274 + kfree(lcd);
12275 +
12276 + return 0;
12277 +}
12278 +
12279 +#ifdef CONFIG_PM
12280 +static int ltv350qv_suspend(struct spi_device *spi,
12281 + pm_message_t state, u32 level)
12282 +{
12283 + struct ltv350qv *lcd = dev_get_drvdata(&spi->dev);
12284 +
12285 + if (level == SUSPEND_POWER_DOWN)
12286 + return ltv350qv_power(lcd, FB_BLANK_POWERDOWN);
12287 +
12288 + return 0;
12289 +}
12290 +
12291 +static int ltv350qv_resume(struct spi_device *spi, u32 level)
12292 +{
12293 + struct ltv350qv *lcd = dev_get_drvdata(&spi->dev);
12294 +
12295 + if (level == RESUME_POWER_ON)
12296 + return ltv350qv_power(lcd, FB_BLANK_UNBLANK);
12297 +
12298 + return 0;
12299 +}
12300 +#else
12301 +#define ltv350qv_suspend NULL
12302 +#define ltv350qv_resume NULL
12303 +#endif
12304 +
12305 +/* Power down all displays on reboot, poweroff or halt */
12306 +static void ltv350qv_shutdown(struct spi_device *spi)
12307 +{
12308 + struct ltv350qv *lcd = dev_get_drvdata(&spi->dev);
12309 +
12310 + ltv350qv_power(lcd, FB_BLANK_POWERDOWN);
12311 +}
12312 +
12313 +static struct spi_driver ltv350qv_driver = {
12314 + .driver = {
12315 + .name = "ltv350qv",
12316 + .bus = &spi_bus_type,
12317 + .owner = THIS_MODULE,
12318 + },
12319 +
12320 + .probe = ltv350qv_probe,
12321 + .remove = __devexit_p(ltv350qv_remove),
12322 + .shutdown = ltv350qv_shutdown,
12323 + .suspend = ltv350qv_suspend,
12324 + .resume = ltv350qv_resume,
12325 +};
12326 +
12327 +static int __init ltv350qv_init(void)
12328 +{
12329 + return spi_register_driver(&ltv350qv_driver);
12330 +}
12331 +
12332 +static void __exit ltv350qv_exit(void)
12333 +{
12334 + spi_unregister_driver(&ltv350qv_driver);
12335 +}
12336 +module_init(ltv350qv_init);
12337 +module_exit(ltv350qv_exit);
12338 +
12339 +MODULE_AUTHOR("Haavard Skinnemoen <hskinnemoen@atmel.com>");
12340 +MODULE_DESCRIPTION("Samsung LTV350QV LCD Driver");
12341 +MODULE_LICENSE("GPL");
12342 diff --git a/drivers/video/backlight/ltv350qv.h b/drivers/video/backlight/ltv350qv.h
12343 new file mode 100644
12344 index 0000000..189112e
12345 --- /dev/null
12346 +++ b/drivers/video/backlight/ltv350qv.h
12347 @@ -0,0 +1,95 @@
12348 +/*
12349 + * Register definitions for Samsung LTV350QV Quarter VGA LCD Panel
12350 + *
12351 + * Copyright (C) 2006, 2007 Atmel Corporation
12352 + *
12353 + * This program is free software; you can redistribute it and/or modify
12354 + * it under the terms of the GNU General Public License version 2 as
12355 + * published by the Free Software Foundation.
12356 + */
12357 +#ifndef __LTV350QV_H
12358 +#define __LTV350QV_H
12359 +
12360 +#define LTV_OPC_INDEX 0x74
12361 +#define LTV_OPC_DATA 0x76
12362 +
12363 +#define LTV_ID 0x00 /* ID Read */
12364 +#define LTV_IFCTL 0x01 /* Display Interface Control */
12365 +#define LTV_DATACTL 0x02 /* Display Data Control */
12366 +#define LTV_ENTRY_MODE 0x03 /* Entry Mode */
12367 +#define LTV_GATECTL1 0x04 /* Gate Control 1 */
12368 +#define LTV_GATECTL2 0x05 /* Gate Control 2 */
12369 +#define LTV_VBP 0x06 /* Vertical Back Porch */
12370 +#define LTV_HBP 0x07 /* Horizontal Back Porch */
12371 +#define LTV_SOTCTL 0x08 /* Source Output Timing Control */
12372 +#define LTV_PWRCTL1 0x09 /* Power Control 1 */
12373 +#define LTV_PWRCTL2 0x0a /* Power Control 2 */
12374 +#define LTV_GAMMA(x) (0x10 + (x)) /* Gamma control */
12375 +
12376 +/* Bit definitions for LTV_IFCTL */
12377 +#define LTV_IM (1 << 15)
12378 +#define LTV_NMD (1 << 14)
12379 +#define LTV_SSMD (1 << 13)
12380 +#define LTV_REV (1 << 7)
12381 +#define LTV_NL(x) (((x) & 0x001f) << 0)
12382 +
12383 +/* Bit definitions for LTV_DATACTL */
12384 +#define LTV_DS_SAME (0 << 12)
12385 +#define LTV_DS_D_TO_S (1 << 12)
12386 +#define LTV_DS_S_TO_D (2 << 12)
12387 +#define LTV_CHS_384 (0 << 9)
12388 +#define LTV_CHS_480 (1 << 9)
12389 +#define LTV_CHS_492 (2 << 9)
12390 +#define LTV_DF_RGB (0 << 6)
12391 +#define LTV_DF_RGBX (1 << 6)
12392 +#define LTV_DF_XRGB (2 << 6)
12393 +#define LTV_RGB_RGB (0 << 2)
12394 +#define LTV_RGB_BGR (1 << 2)
12395 +#define LTV_RGB_GRB (2 << 2)
12396 +#define LTV_RGB_RBG (3 << 2)
12397 +
12398 +/* Bit definitions for LTV_ENTRY_MODE */
12399 +#define LTV_VSPL_ACTIVE_LOW (0 << 15)
12400 +#define LTV_VSPL_ACTIVE_HIGH (1 << 15)
12401 +#define LTV_HSPL_ACTIVE_LOW (0 << 14)
12402 +#define LTV_HSPL_ACTIVE_HIGH (1 << 14)
12403 +#define LTV_DPL_SAMPLE_RISING (0 << 13)
12404 +#define LTV_DPL_SAMPLE_FALLING (1 << 13)
12405 +#define LTV_EPL_ACTIVE_LOW (0 << 12)
12406 +#define LTV_EPL_ACTIVE_HIGH (1 << 12)
12407 +#define LTV_SS_LEFT_TO_RIGHT (0 << 8)
12408 +#define LTV_SS_RIGHT_TO_LEFT (1 << 8)
12409 +#define LTV_STB (1 << 1)
12410 +
12411 +/* Bit definitions for LTV_GATECTL1 */
12412 +#define LTV_CLW(x) (((x) & 0x0007) << 12)
12413 +#define LTV_GAON (1 << 5)
12414 +#define LTV_SDR (1 << 3)
12415 +
12416 +/* Bit definitions for LTV_GATECTL2 */
12417 +#define LTV_NW_INV_FRAME (0 << 14)
12418 +#define LTV_NW_INV_1LINE (1 << 14)
12419 +#define LTV_NW_INV_2LINE (2 << 14)
12420 +#define LTV_DSC (1 << 12)
12421 +#define LTV_GIF (1 << 8)
12422 +#define LTV_FHN (1 << 7)
12423 +#define LTV_FTI(x) (((x) & 0x0003) << 4)
12424 +#define LTV_FWI(x) (((x) & 0x0003) << 0)
12425 +
12426 +/* Bit definitions for LTV_SOTCTL */
12427 +#define LTV_SDT(x) (((x) & 0x0007) << 10)
12428 +#define LTV_EQ(x) (((x) & 0x0007) << 2)
12429 +
12430 +/* Bit definitions for LTV_PWRCTL1 */
12431 +#define LTV_VCOM_DISABLE (1 << 14)
12432 +#define LTV_VCOMOUT_ENABLE (1 << 11)
12433 +#define LTV_POWER_ON (1 << 9)
12434 +#define LTV_DRIVE_CURRENT(x) (((x) & 0x0007) << 4) /* 0=off, 5=max */
12435 +#define LTV_SUPPLY_CURRENT(x) (((x) & 0x0007) << 0) /* 0=off, 5=max */
12436 +
12437 +/* Bit definitions for LTV_PWRCTL2 */
12438 +#define LTV_VCOML_ENABLE (1 << 13)
12439 +#define LTV_VCOML_VOLTAGE(x) (((x) & 0x001f) << 8) /* 0=1V, 31=-1V */
12440 +#define LTV_VCOMH_VOLTAGE(x) (((x) & 0x001f) << 0) /* 0=3V, 31=4.5V */
12441 +
12442 +#endif /* __LTV350QV_H */
12443 diff --git a/include/asm-arm/arch-at91/board.h b/include/asm-arm/arch-at91/board.h
12444 index 0ce6ee9..d96b10f 100644
12445 --- a/include/asm-arm/arch-at91/board.h
12446 +++ b/include/asm-arm/arch-at91/board.h
12447 @@ -64,6 +64,7 @@ extern void __init at91_add_device_mmc(short mmc_id, struct at91_mmc_data *data)
12448
12449 /* Ethernet (EMAC & MACB) */
12450 struct at91_eth_data {
12451 + u32 phy_mask;
12452 u8 phy_irq_pin; /* PHY IRQ */
12453 u8 is_rmii; /* using RMII interface? */
12454 };
12455 diff --git a/include/asm-avr32/arch-at32ap/board.h b/include/asm-avr32/arch-at32ap/board.h
12456 index 9fd2e32..9b36eb8 100644
12457 --- a/include/asm-avr32/arch-at32ap/board.h
12458 +++ b/include/asm-avr32/arch-at32ap/board.h
12459 @@ -6,6 +6,8 @@
12460
12461 #include <linux/types.h>
12462
12463 +#define GPIO_PIN_NONE (-1)
12464 +
12465 /* Add basic devices: system manager, interrupt controller, portmuxes, etc. */
12466 void at32_add_system_devices(void);
12467
12468 @@ -21,6 +23,7 @@ void at32_map_usart(unsigned int hw_id, unsigned int line);
12469 struct platform_device *at32_add_device_usart(unsigned int id);
12470
12471 struct eth_platform_data {
12472 + u32 phy_mask;
12473 u8 is_rmii;
12474 };
12475 struct platform_device *
12476 @@ -30,9 +33,41 @@ struct spi_board_info;
12477 struct platform_device *
12478 at32_add_device_spi(unsigned int id, struct spi_board_info *b, unsigned int n);
12479
12480 +struct platform_device *at32_add_device_twi(unsigned int id);
12481 +
12482 +struct mci_platform_data {
12483 + int detect_pin;
12484 + int wp_pin;
12485 +};
12486 +struct platform_device *
12487 +at32_add_device_mci(unsigned int id, struct mci_platform_data *data);
12488 +
12489 +struct usba_platform_data {
12490 + int vbus_pin;
12491 +};
12492 +struct platform_device *
12493 +at32_add_device_usba(unsigned int id, struct usba_platform_data *data);
12494 +
12495 struct atmel_lcdfb_info;
12496 struct platform_device *
12497 at32_add_device_lcdc(unsigned int id, struct atmel_lcdfb_info *data,
12498 unsigned long fbmem_start, unsigned long fbmem_len);
12499
12500 +struct platform_device *at32_add_device_ac97c(unsigned int id);
12501 +struct platform_device *at32_add_device_abdac(unsigned int id);
12502 +
12503 +/* depending on what's hooked up, not all SSC pins will be used */
12504 +#define ATMEL_SSC_TK 0x01
12505 +#define ATMEL_SSC_TF 0x02
12506 +#define ATMEL_SSC_TD 0x04
12507 +#define ATMEL_SSC_TX (ATMEL_SSC_TK | ATMEL_SSC_TF | ATMEL_SSC_TD)
12508 +
12509 +#define ATMEL_SSC_RK 0x10
12510 +#define ATMEL_SSC_RF 0x20
12511 +#define ATMEL_SSC_RD 0x40
12512 +#define ATMEL_SSC_RX (ATMEL_SSC_RK | ATMEL_SSC_RF | ATMEL_SSC_RD)
12513 +
12514 +struct platform_device *
12515 +at32_add_device_ssc(unsigned int id, unsigned int flags);
12516 +
12517 #endif /* __ASM_ARCH_BOARD_H */
12518 diff --git a/include/asm-avr32/arch-at32ap/portmux.h b/include/asm-avr32/arch-at32ap/portmux.h
12519 index 9930871..0f95567 100644
12520 --- a/include/asm-avr32/arch-at32ap/portmux.h
12521 +++ b/include/asm-avr32/arch-at32ap/portmux.h
12522 @@ -25,4 +25,16 @@ void at32_select_periph(unsigned int pin, unsigned int periph,
12523 void at32_select_gpio(unsigned int pin, unsigned long flags);
12524 void at32_reserve_pin(unsigned int pin);
12525
12526 +#ifdef CONFIG_GPIO_DEV
12527 +
12528 +/* Gang allocators and accessors; used by the GPIO /dev driver */
12529 +int at32_gpio_port_is_valid(unsigned int port);
12530 +int at32_select_gpio_pins(unsigned int port, u32 pins, u32 oe_mask);
12531 +void at32_deselect_pins(unsigned int port, u32 pins);
12532 +
12533 +u32 at32_gpio_get_value_multiple(unsigned int port, u32 pins);
12534 +void at32_gpio_set_value_multiple(unsigned int port, u32 value, u32 mask);
12535 +
12536 +#endif /* CONFIG_GPIO_DEV */
12537 +
12538 #endif /* __ASM_ARCH_PORTMUX_H__ */
12539 diff --git a/include/asm-avr32/arch-at32ap/sm.h b/include/asm-avr32/arch-at32ap/sm.h
12540 deleted file mode 100644
12541 index 265a9ea..0000000
12542 --- a/include/asm-avr32/arch-at32ap/sm.h
12543 +++ /dev/null
12544 @@ -1,27 +0,0 @@
12545 -/*
12546 - * AT32 System Manager interface.
12547 - *
12548 - * Copyright (C) 2006 Atmel Corporation
12549 - *
12550 - * This program is free software; you can redistribute it and/or modify
12551 - * it under the terms of the GNU General Public License version 2 as
12552 - * published by the Free Software Foundation.
12553 - */
12554 -#ifndef __ASM_AVR32_AT32_SM_H__
12555 -#define __ASM_AVR32_AT32_SM_H__
12556 -
12557 -struct irq_chip;
12558 -struct platform_device;
12559 -
12560 -struct at32_sm {
12561 - spinlock_t lock;
12562 - void __iomem *regs;
12563 - struct irq_chip *eim_chip;
12564 - unsigned int eim_first_irq;
12565 - struct platform_device *pdev;
12566 -};
12567 -
12568 -extern struct platform_device at32_sm_device;
12569 -extern struct at32_sm system_manager;
12570 -
12571 -#endif /* __ASM_AVR32_AT32_SM_H__ */
12572 diff --git a/include/asm-avr32/atomic.h b/include/asm-avr32/atomic.h
12573 index b9c2548..7ef3862 100644
12574 --- a/include/asm-avr32/atomic.h
12575 +++ b/include/asm-avr32/atomic.h
12576 @@ -101,7 +101,7 @@ static inline int atomic_sub_unless(atomic_t *v, int a, int u)
12577 " mov %1, 1\n"
12578 "1:"
12579 : "=&r"(tmp), "=&r"(result), "=o"(v->counter)
12580 - : "m"(v->counter), "rKs21"(a), "rKs21"(u)
12581 + : "m"(v->counter), "rKs21"(a), "rKs21"(u), "1"(result)
12582 : "cc", "memory");
12583
12584 return result;
12585 @@ -137,7 +137,7 @@ static inline int atomic_add_unless(atomic_t *v, int a, int u)
12586 " mov %1, 1\n"
12587 "1:"
12588 : "=&r"(tmp), "=&r"(result), "=o"(v->counter)
12589 - : "m"(v->counter), "r"(a), "ir"(u)
12590 + : "m"(v->counter), "r"(a), "ir"(u), "1"(result)
12591 : "cc", "memory");
12592 }
12593
12594 diff --git a/include/asm-avr32/dma-controller.h b/include/asm-avr32/dma-controller.h
12595 new file mode 100644
12596 index 0000000..56a4965
12597 --- /dev/null
12598 +++ b/include/asm-avr32/dma-controller.h
12599 @@ -0,0 +1,166 @@
12600 +/*
12601 + * Copyright (C) 2005-2006 Atmel Corporation
12602 + *
12603 + * This program is free software; you can redistribute it and/or modify
12604 + * it under the terms of the GNU General Public License version 2 as
12605 + * published by the Free Software Foundation.
12606 + */
12607 +#ifndef __ASM_AVR32_DMA_CONTROLLER_H
12608 +#define __ASM_AVR32_DMA_CONTROLLER_H
12609 +
12610 +#include <linux/device.h>
12611 +
12612 +#define DMA_DIR_MEM_TO_MEM 0x0000
12613 +#define DMA_DIR_MEM_TO_PERIPH 0x0001
12614 +#define DMA_DIR_PERIPH_TO_MEM 0x0002
12615 +#define DMA_DIR_PERIPH_TO_PERIPH 0x0003
12616 +
12617 +#define DMA_WIDTH_8BIT 0
12618 +#define DMA_WIDTH_16BIT 1
12619 +#define DMA_WIDTH_32BIT 2
12620 +
12621 +struct dma_request {
12622 + struct dma_controller *dmac;
12623 + struct list_head list;
12624 +
12625 + unsigned short channel;
12626 +
12627 + void (*xfer_complete)(struct dma_request *req);
12628 + void (*block_complete)(struct dma_request *req);
12629 + void (*error)(struct dma_request *req);
12630 +};
12631 +
12632 +struct dma_request_sg {
12633 + struct dma_request req;
12634 +
12635 + int nr_sg;
12636 + struct scatterlist *sg;
12637 + unsigned long block_size;
12638 + unsigned int nr_blocks;
12639 +
12640 + dma_addr_t data_reg;
12641 + unsigned short periph_id;
12642 +
12643 + unsigned char direction;
12644 + unsigned char width;
12645 +};
12646 +#define to_dma_request_sg(_req) \
12647 + container_of(_req, struct dma_request_sg, req)
12648 +
12649 +struct dma_request_cyclic {
12650 + struct dma_request req;
12651 +
12652 + int periods;
12653 + unsigned long buffer_size;
12654 +
12655 + dma_addr_t buffer_start;
12656 + dma_addr_t data_reg;
12657 +
12658 + unsigned short periph_id;
12659 + unsigned char direction;
12660 + unsigned char width;
12661 +
12662 + void *dev_id;
12663 +};
12664 +#define to_dma_request_cyclic(_req) \
12665 + container_of(_req, struct dma_request_cyclic, req)
12666 +
12667 +struct dma_request_memcpy {
12668 + struct dma_request req;
12669 +
12670 + dma_addr_t src_addr;
12671 + unsigned int src_width;
12672 + unsigned int src_stride;
12673 +
12674 + dma_addr_t dst_addr;
12675 + unsigned int dst_width;
12676 + unsigned int dst_stride;
12677 +
12678 + size_t length;
12679 +
12680 + unsigned short src_reverse:1;
12681 + unsigned short dst_reverse:1;
12682 +};
12683 +#define to_dma_request_memcpy(_req) \
12684 + container_of(_req, struct dma_request_memcpy, req)
12685 +
12686 +struct dma_controller {
12687 + struct list_head list;
12688 + int id;
12689 + struct device *dev;
12690 +
12691 + int (*alloc_channel)(struct dma_controller *dmac);
12692 + void (*release_channel)(struct dma_controller *dmac,
12693 + int channel);
12694 + int (*prepare_request_sg)(struct dma_controller *dmac,
12695 + struct dma_request_sg *req);
12696 + int (*prepare_request_cyclic)(struct dma_controller *dmac,
12697 + struct dma_request_cyclic *req);
12698 + int (*prepare_request_memcpy)(struct dma_controller *dmac,
12699 + struct dma_request_memcpy *req);
12700 + int (*start_request)(struct dma_controller *dmac,
12701 + unsigned int channel);
12702 + int (*stop_request)(struct dma_controller *dmac,
12703 + unsigned int channel);
12704 + dma_addr_t (*get_current_pos)(struct dma_controller *dmac,
12705 + unsigned int channel);
12706 +};
12707 +
12708 +static inline int
12709 +dma_alloc_channel(struct dma_controller *dmac)
12710 +{
12711 + return dmac->alloc_channel(dmac);
12712 +}
12713 +
12714 +static inline void
12715 +dma_release_channel(struct dma_controller *dmac, int chan)
12716 +{
12717 + dmac->release_channel(dmac, chan);
12718 +}
12719 +
12720 +static inline int
12721 +dma_prepare_request_sg(struct dma_controller *dmac,
12722 + struct dma_request_sg *req)
12723 +{
12724 + return dmac->prepare_request_sg(dmac, req);
12725 +}
12726 +
12727 +static inline int
12728 +dma_prepare_request_cyclic(struct dma_controller *dmac,
12729 + struct dma_request_cyclic *req)
12730 +{
12731 + return dmac->prepare_request_cyclic(dmac, req);
12732 +}
12733 +
12734 +static inline int
12735 +dma_prepare_request_memcpy(struct dma_controller *dmac,
12736 + struct dma_request_memcpy *req)
12737 +{
12738 + return dmac->prepare_request_memcpy(dmac, req);
12739 +}
12740 +
12741 +static inline int
12742 +dma_start_request(struct dma_controller *dmac,
12743 + unsigned int channel)
12744 +{
12745 + return dmac->start_request(dmac, channel);
12746 +}
12747 +
12748 +static inline int
12749 +dma_stop_request(struct dma_controller *dmac,
12750 + unsigned int channel)
12751 +{
12752 + return dmac->stop_request(dmac, channel);
12753 +}
12754 +
12755 +static inline dma_addr_t
12756 +dma_get_current_pos(struct dma_controller *dmac,
12757 + unsigned int channel)
12758 +{
12759 + return dmac->get_current_pos(dmac, channel);
12760 +}
12761 +
12762 +extern int register_dma_controller(struct dma_controller *dmac);
12763 +extern struct dma_controller *find_dma_controller(int id);
12764 +
12765 +#endif /* __ASM_AVR32_DMA_CONTROLLER_H */
12766 diff --git a/include/asm-avr32/unaligned.h b/include/asm-avr32/unaligned.h
12767 index 3042723..36f5fd4 100644
12768 --- a/include/asm-avr32/unaligned.h
12769 +++ b/include/asm-avr32/unaligned.h
12770 @@ -7,19 +7,10 @@
12771 * words, but halfwords must be halfword-aligned, and doublewords must
12772 * be word-aligned.
12773 *
12774 - * TODO: Make all this CPU-specific and optimize.
12775 + * However, swapped word loads must be word-aligned so we can't
12776 + * optimize word loads in general.
12777 */
12778
12779 -#include <linux/string.h>
12780 -
12781 -/* Use memmove here, so gcc does not insert a __builtin_memcpy. */
12782 -
12783 -#define get_unaligned(ptr) \
12784 - ({ __typeof__(*(ptr)) __tmp; memmove(&__tmp, (ptr), sizeof(*(ptr))); __tmp; })
12785 -
12786 -#define put_unaligned(val, ptr) \
12787 - ({ __typeof__(*(ptr)) __tmp = (val); \
12788 - memmove((ptr), &__tmp, sizeof(*(ptr))); \
12789 - (void)0; })
12790 +#include <asm-generic/unaligned.h>
12791
12792 #endif /* __ASM_AVR32_UNALIGNED_H */
12793 diff --git a/include/linux/atmel-ssc.h b/include/linux/atmel-ssc.h
12794 new file mode 100644
12795 index 0000000..0602339
12796 --- /dev/null
12797 +++ b/include/linux/atmel-ssc.h
12798 @@ -0,0 +1,312 @@
12799 +#ifndef __INCLUDE_ATMEL_SSC_H
12800 +#define __INCLUDE_ATMEL_SSC_H
12801 +
12802 +#include <linux/platform_device.h>
12803 +#include <linux/list.h>
12804 +
12805 +struct ssc_device {
12806 + struct list_head list;
12807 + void __iomem *regs;
12808 + struct platform_device *pdev;
12809 + struct clk *clk;
12810 + int user;
12811 + int irq;
12812 +};
12813 +
12814 +struct ssc_device * __must_check ssc_request(unsigned int ssc_num);
12815 +void ssc_free(struct ssc_device *ssc);
12816 +
12817 +/* SSC register offsets */
12818 +
12819 +/* SSC Control Register */
12820 +#define SSC_CR 0x00000000
12821 +#define SSC_CR_RXDIS_SIZE 1
12822 +#define SSC_CR_RXDIS_OFFSET 1
12823 +#define SSC_CR_RXEN_SIZE 1
12824 +#define SSC_CR_RXEN_OFFSET 0
12825 +#define SSC_CR_SWRST_SIZE 1
12826 +#define SSC_CR_SWRST_OFFSET 15
12827 +#define SSC_CR_TXDIS_SIZE 1
12828 +#define SSC_CR_TXDIS_OFFSET 9
12829 +#define SSC_CR_TXEN_SIZE 1
12830 +#define SSC_CR_TXEN_OFFSET 8
12831 +
12832 +/* SSC Clock Mode Register */
12833 +#define SSC_CMR 0x00000004
12834 +#define SSC_CMR_DIV_SIZE 12
12835 +#define SSC_CMR_DIV_OFFSET 0
12836 +
12837 +/* SSC Receive Clock Mode Register */
12838 +#define SSC_RCMR 0x00000010
12839 +#define SSC_RCMR_CKG_SIZE 2
12840 +#define SSC_RCMR_CKG_OFFSET 6
12841 +#define SSC_RCMR_CKI_SIZE 1
12842 +#define SSC_RCMR_CKI_OFFSET 5
12843 +#define SSC_RCMR_CKO_SIZE 3
12844 +#define SSC_RCMR_CKO_OFFSET 2
12845 +#define SSC_RCMR_CKS_SIZE 2
12846 +#define SSC_RCMR_CKS_OFFSET 0
12847 +#define SSC_RCMR_PERIOD_SIZE 8
12848 +#define SSC_RCMR_PERIOD_OFFSET 24
12849 +#define SSC_RCMR_START_SIZE 4
12850 +#define SSC_RCMR_START_OFFSET 8
12851 +#define SSC_RCMR_STOP_SIZE 1
12852 +#define SSC_RCMR_STOP_OFFSET 12
12853 +#define SSC_RCMR_STTDLY_SIZE 8
12854 +#define SSC_RCMR_STTDLY_OFFSET 16
12855 +
12856 +/* SSC Receive Frame Mode Register */
12857 +#define SSC_RFMR 0x00000014
12858 +#define SSC_RFMR_DATLEN_SIZE 5
12859 +#define SSC_RFMR_DATLEN_OFFSET 0
12860 +#define SSC_RFMR_DATNB_SIZE 4
12861 +#define SSC_RFMR_DATNB_OFFSET 8
12862 +#define SSC_RFMR_FSEDGE_SIZE 1
12863 +#define SSC_RFMR_FSEDGE_OFFSET 24
12864 +#define SSC_RFMR_FSLEN_SIZE 4
12865 +#define SSC_RFMR_FSLEN_OFFSET 16
12866 +#define SSC_RFMR_FSOS_SIZE 4
12867 +#define SSC_RFMR_FSOS_OFFSET 20
12868 +#define SSC_RFMR_LOOP_SIZE 1
12869 +#define SSC_RFMR_LOOP_OFFSET 5
12870 +#define SSC_RFMR_MSBF_SIZE 1
12871 +#define SSC_RFMR_MSBF_OFFSET 7
12872 +
12873 +/* SSC Transmit Clock Mode Register */
12874 +#define SSC_TCMR 0x00000018
12875 +#define SSC_TCMR_CKG_SIZE 2
12876 +#define SSC_TCMR_CKG_OFFSET 6
12877 +#define SSC_TCMR_CKI_SIZE 1
12878 +#define SSC_TCMR_CKI_OFFSET 5
12879 +#define SSC_TCMR_CKO_SIZE 3
12880 +#define SSC_TCMR_CKO_OFFSET 2
12881 +#define SSC_TCMR_CKS_SIZE 2
12882 +#define SSC_TCMR_CKS_OFFSET 0
12883 +#define SSC_TCMR_PERIOD_SIZE 8
12884 +#define SSC_TCMR_PERIOD_OFFSET 24
12885 +#define SSC_TCMR_START_SIZE 4
12886 +#define SSC_TCMR_START_OFFSET 8
12887 +#define SSC_TCMR_STTDLY_SIZE 8
12888 +#define SSC_TCMR_STTDLY_OFFSET 16
12889 +
12890 +/* SSC Transmit Frame Mode Register */
12891 +#define SSC_TFMR 0x0000001c
12892 +#define SSC_TFMR_DATDEF_SIZE 1
12893 +#define SSC_TFMR_DATDEF_OFFSET 5
12894 +#define SSC_TFMR_DATLEN_SIZE 5
12895 +#define SSC_TFMR_DATLEN_OFFSET 0
12896 +#define SSC_TFMR_DATNB_SIZE 4
12897 +#define SSC_TFMR_DATNB_OFFSET 8
12898 +#define SSC_TFMR_FSDEN_SIZE 1
12899 +#define SSC_TFMR_FSDEN_OFFSET 23
12900 +#define SSC_TFMR_FSEDGE_SIZE 1
12901 +#define SSC_TFMR_FSEDGE_OFFSET 24
12902 +#define SSC_TFMR_FSLEN_SIZE 4
12903 +#define SSC_TFMR_FSLEN_OFFSET 16
12904 +#define SSC_TFMR_FSOS_SIZE 3
12905 +#define SSC_TFMR_FSOS_OFFSET 20
12906 +#define SSC_TFMR_MSBF_SIZE 1
12907 +#define SSC_TFMR_MSBF_OFFSET 7
12908 +
12909 +/* SSC Receive Hold Register */
12910 +#define SSC_RHR 0x00000020
12911 +#define SSC_RHR_RDAT_SIZE 32
12912 +#define SSC_RHR_RDAT_OFFSET 0
12913 +
12914 +/* SSC Transmit Hold Register */
12915 +#define SSC_THR 0x00000024
12916 +#define SSC_THR_TDAT_SIZE 32
12917 +#define SSC_THR_TDAT_OFFSET 0
12918 +
12919 +/* SSC Receive Sync. Holding Register */
12920 +#define SSC_RSHR 0x00000030
12921 +#define SSC_RSHR_RSDAT_SIZE 16
12922 +#define SSC_RSHR_RSDAT_OFFSET 0
12923 +
12924 +/* SSC Transmit Sync. Holding Register */
12925 +#define SSC_TSHR 0x00000034
12926 +#define SSC_TSHR_TSDAT_SIZE 16
12927 +#define SSC_TSHR_RSDAT_OFFSET 0
12928 +
12929 +/* SSC Receive Compare 0 Register */
12930 +#define SSC_RC0R 0x00000038
12931 +#define SSC_RC0R_CP0_SIZE 16
12932 +#define SSC_RC0R_CP0_OFFSET 0
12933 +
12934 +/* SSC Receive Compare 1 Register */
12935 +#define SSC_RC1R 0x0000003c
12936 +#define SSC_RC1R_CP1_SIZE 16
12937 +#define SSC_RC1R_CP1_OFFSET 0
12938 +
12939 +/* SSC Status Register */
12940 +#define SSC_SR 0x00000040
12941 +#define SSC_SR_CP0_SIZE 1
12942 +#define SSC_SR_CP0_OFFSET 8
12943 +#define SSC_SR_CP1_SIZE 1
12944 +#define SSC_SR_CP1_OFFSET 9
12945 +#define SSC_SR_ENDRX_SIZE 1
12946 +#define SSC_SR_ENDRX_OFFSET 6
12947 +#define SSC_SR_ENDTX_SIZE 1
12948 +#define SSC_SR_ENDTX_OFFSET 2
12949 +#define SSC_SR_OVRUN_SIZE 1
12950 +#define SSC_SR_OVRUN_OFFSET 5
12951 +#define SSC_SR_RXBUFF_SIZE 1
12952 +#define SSC_SR_RXBUFF_OFFSET 7
12953 +#define SSC_SR_RXEN_SIZE 1
12954 +#define SSC_SR_RXEN_OFFSET 17
12955 +#define SSC_SR_RXRDY_SIZE 1
12956 +#define SSC_SR_RXRDY_OFFSET 4
12957 +#define SSC_SR_RXSYN_SIZE 1
12958 +#define SSC_SR_RXSYN_OFFSET 11
12959 +#define SSC_SR_TXBUFE_SIZE 1
12960 +#define SSC_SR_TXBUFE_OFFSET 3
12961 +#define SSC_SR_TXEMPTY_SIZE 1
12962 +#define SSC_SR_TXEMPTY_OFFSET 1
12963 +#define SSC_SR_TXEN_SIZE 1
12964 +#define SSC_SR_TXEN_OFFSET 16
12965 +#define SSC_SR_TXRDY_SIZE 1
12966 +#define SSC_SR_TXRDY_OFFSET 0
12967 +#define SSC_SR_TXSYN_SIZE 1
12968 +#define SSC_SR_TXSYN_OFFSET 10
12969 +
12970 +/* SSC Interrupt Enable Register */
12971 +#define SSC_IER 0x00000044
12972 +#define SSC_IER_CP0_SIZE 1
12973 +#define SSC_IER_CP0_OFFSET 8
12974 +#define SSC_IER_CP1_SIZE 1
12975 +#define SSC_IER_CP1_OFFSET 9
12976 +#define SSC_IER_ENDRX_SIZE 1
12977 +#define SSC_IER_ENDRX_OFFSET 6
12978 +#define SSC_IER_ENDTX_SIZE 1
12979 +#define SSC_IER_ENDTX_OFFSET 2
12980 +#define SSC_IER_OVRUN_SIZE 1
12981 +#define SSC_IER_OVRUN_OFFSET 5
12982 +#define SSC_IER_RXBUFF_SIZE 1
12983 +#define SSC_IER_RXBUFF_OFFSET 7
12984 +#define SSC_IER_RXRDY_SIZE 1
12985 +#define SSC_IER_RXRDY_OFFSET 4
12986 +#define SSC_IER_RXSYN_SIZE 1
12987 +#define SSC_IER_RXSYN_OFFSET 11
12988 +#define SSC_IER_TXBUFE_SIZE 1
12989 +#define SSC_IER_TXBUFE_OFFSET 3
12990 +#define SSC_IER_TXEMPTY_SIZE 1
12991 +#define SSC_IER_TXEMPTY_OFFSET 1
12992 +#define SSC_IER_TXRDY_SIZE 1
12993 +#define SSC_IER_TXRDY_OFFSET 0
12994 +#define SSC_IER_TXSYN_SIZE 1
12995 +#define SSC_IER_TXSYN_OFFSET 10
12996 +
12997 +/* SSC Interrupt Disable Register */
12998 +#define SSC_IDR 0x00000048
12999 +#define SSC_IDR_CP0_SIZE 1
13000 +#define SSC_IDR_CP0_OFFSET 8
13001 +#define SSC_IDR_CP1_SIZE 1
13002 +#define SSC_IDR_CP1_OFFSET 9
13003 +#define SSC_IDR_ENDRX_SIZE 1
13004 +#define SSC_IDR_ENDRX_OFFSET 6
13005 +#define SSC_IDR_ENDTX_SIZE 1
13006 +#define SSC_IDR_ENDTX_OFFSET 2
13007 +#define SSC_IDR_OVRUN_SIZE 1
13008 +#define SSC_IDR_OVRUN_OFFSET 5
13009 +#define SSC_IDR_RXBUFF_SIZE 1
13010 +#define SSC_IDR_RXBUFF_OFFSET 7
13011 +#define SSC_IDR_RXRDY_SIZE 1
13012 +#define SSC_IDR_RXRDY_OFFSET 4
13013 +#define SSC_IDR_RXSYN_SIZE 1
13014 +#define SSC_IDR_RXSYN_OFFSET 11
13015 +#define SSC_IDR_TXBUFE_SIZE 1
13016 +#define SSC_IDR_TXBUFE_OFFSET 3
13017 +#define SSC_IDR_TXEMPTY_SIZE 1
13018 +#define SSC_IDR_TXEMPTY_OFFSET 1
13019 +#define SSC_IDR_TXRDY_SIZE 1
13020 +#define SSC_IDR_TXRDY_OFFSET 0
13021 +#define SSC_IDR_TXSYN_SIZE 1
13022 +#define SSC_IDR_TXSYN_OFFSET 10
13023 +
13024 +/* SSC Interrupt Mask Register */
13025 +#define SSC_IMR 0x0000004c
13026 +#define SSC_IMR_CP0_SIZE 1
13027 +#define SSC_IMR_CP0_OFFSET 8
13028 +#define SSC_IMR_CP1_SIZE 1
13029 +#define SSC_IMR_CP1_OFFSET 9
13030 +#define SSC_IMR_ENDRX_SIZE 1
13031 +#define SSC_IMR_ENDRX_OFFSET 6
13032 +#define SSC_IMR_ENDTX_SIZE 1
13033 +#define SSC_IMR_ENDTX_OFFSET 2
13034 +#define SSC_IMR_OVRUN_SIZE 1
13035 +#define SSC_IMR_OVRUN_OFFSET 5
13036 +#define SSC_IMR_RXBUFF_SIZE 1
13037 +#define SSC_IMR_RXBUFF_OFFSET 7
13038 +#define SSC_IMR_RXRDY_SIZE 1
13039 +#define SSC_IMR_RXRDY_OFFSET 4
13040 +#define SSC_IMR_RXSYN_SIZE 1
13041 +#define SSC_IMR_RXSYN_OFFSET 11
13042 +#define SSC_IMR_TXBUFE_SIZE 1
13043 +#define SSC_IMR_TXBUFE_OFFSET 3
13044 +#define SSC_IMR_TXEMPTY_SIZE 1
13045 +#define SSC_IMR_TXEMPTY_OFFSET 1
13046 +#define SSC_IMR_TXRDY_SIZE 1
13047 +#define SSC_IMR_TXRDY_OFFSET 0
13048 +#define SSC_IMR_TXSYN_SIZE 1
13049 +#define SSC_IMR_TXSYN_OFFSET 10
13050 +
13051 +/* SSC PDC Receive Pointer Register */
13052 +#define SSC_PDC_RPR 0x00000100
13053 +
13054 +/* SSC PDC Receive Counter Register */
13055 +#define SSC_PDC_RCR 0x00000104
13056 +
13057 +/* SSC PDC Transmit Pointer Register */
13058 +#define SSC_PDC_TPR 0x00000108
13059 +
13060 +/* SSC PDC Receive Next Pointer Register */
13061 +#define SSC_PDC_RNPR 0x00000110
13062 +
13063 +/* SSC PDC Receive Next Counter Register */
13064 +#define SSC_PDC_RNCR 0x00000114
13065 +
13066 +/* SSC PDC Transmit Counter Register */
13067 +#define SSC_PDC_TCR 0x0000010c
13068 +
13069 +/* SSC PDC Transmit Next Pointer Register */
13070 +#define SSC_PDC_TNPR 0x00000118
13071 +
13072 +/* SSC PDC Transmit Next Counter Register */
13073 +#define SSC_PDC_TNCR 0x0000011c
13074 +
13075 +/* SSC PDC Transfer Control Register */
13076 +#define SSC_PDC_PTCR 0x00000120
13077 +#define SSC_PDC_PTCR_RXTDIS_SIZE 1
13078 +#define SSC_PDC_PTCR_RXTDIS_OFFSET 1
13079 +#define SSC_PDC_PTCR_RXTEN_SIZE 1
13080 +#define SSC_PDC_PTCR_RXTEN_OFFSET 0
13081 +#define SSC_PDC_PTCR_TXTDIS_SIZE 1
13082 +#define SSC_PDC_PTCR_TXTDIS_OFFSET 9
13083 +#define SSC_PDC_PTCR_TXTEN_SIZE 1
13084 +#define SSC_PDC_PTCR_TXTEN_OFFSET 8
13085 +
13086 +/* SSC PDC Transfer Status Register */
13087 +#define SSC_PDC_PTSR 0x00000124
13088 +#define SSC_PDC_PTSR_RXTEN_SIZE 1
13089 +#define SSC_PDC_PTSR_RXTEN_OFFSET 0
13090 +#define SSC_PDC_PTSR_TXTEN_SIZE 1
13091 +#define SSC_PDC_PTSR_TXTEN_OFFSET 8
13092 +
13093 +/* Bit manipulation macros */
13094 +#define SSC_BIT(name) \
13095 + (1 << SSC_##name##_OFFSET)
13096 +#define SSC_BF(name, value) \
13097 + (((value) & ((1 << SSC_##name##_SIZE) - 1)) \
13098 + << SSC_##name##_OFFSET)
13099 +#define SSC_BFEXT(name, value) \
13100 + (((value) >> SSC_##name##_OFFSET) \
13101 + & ((1 << SSC_##name##_SIZE) - 1))
13102 +#define SSC_BFINS(name, value, old) \
13103 + (((old) & ~(((1 << SSC_##name##_SIZE) - 1) \
13104 + << SSC_##name##_OFFSET)) | SSC_BF(name, value))
13105 +
13106 +/* Register access macros */
13107 +#define ssc_readl(base, reg) __raw_readl(base + SSC_##reg)
13108 +#define ssc_writel(base, reg, value) __raw_writel((value), base + SSC_##reg)
13109 +
13110 +#endif /* __INCLUDE_ATMEL_SSC_H */
13111 diff --git a/include/linux/gpio_mouse.h b/include/linux/gpio_mouse.h
13112 new file mode 100644
13113 index 0000000..44ed7aa
13114 --- /dev/null
13115 +++ b/include/linux/gpio_mouse.h
13116 @@ -0,0 +1,61 @@
13117 +/*
13118 + * Driver for simulating a mouse on GPIO lines.
13119 + *
13120 + * Copyright (C) 2007 Atmel Corporation
13121 + *
13122 + * This program is free software; you can redistribute it and/or modify
13123 + * it under the terms of the GNU General Public License version 2 as
13124 + * published by the Free Software Foundation.
13125 + */
13126 +
13127 +#ifndef _GPIO_MOUSE_H
13128 +#define _GPIO_MOUSE_H
13129 +
13130 +#define GPIO_MOUSE_POLARITY_ACT_HIGH 0x00
13131 +#define GPIO_MOUSE_POLARITY_ACT_LOW 0x01
13132 +
13133 +#define GPIO_MOUSE_PIN_UP 0
13134 +#define GPIO_MOUSE_PIN_DOWN 1
13135 +#define GPIO_MOUSE_PIN_LEFT 2
13136 +#define GPIO_MOUSE_PIN_RIGHT 3
13137 +#define GPIO_MOUSE_PIN_BLEFT 4
13138 +#define GPIO_MOUSE_PIN_BMIDDLE 5
13139 +#define GPIO_MOUSE_PIN_BRIGHT 6
13140 +#define GPIO_MOUSE_PIN_MAX 7
13141 +
13142 +/**
13143 + * struct gpio_mouse_platform_data
13144 + * @scan_ms: integer in ms specifying the scan periode.
13145 + * @polarity: Pin polarity, active high or low.
13146 + * @up: GPIO line for up value.
13147 + * @down: GPIO line for down value.
13148 + * @left: GPIO line for left value.
13149 + * @right: GPIO line for right value.
13150 + * @bleft: GPIO line for left button.
13151 + * @bmiddle: GPIO line for middle button.
13152 + * @bright: GPIO line for right button.
13153 + *
13154 + * This struct must be added to the platform_device in the board code.
13155 + * It is used by the gpio_mouse driver to setup GPIO lines and to
13156 + * calculate mouse movement.
13157 + */
13158 +struct gpio_mouse_platform_data {
13159 + int scan_ms;
13160 + int polarity;
13161 +
13162 + union {
13163 + struct {
13164 + int up;
13165 + int down;
13166 + int left;
13167 + int right;
13168 +
13169 + int bleft;
13170 + int bmiddle;
13171 + int bright;
13172 + };
13173 + int pins[GPIO_MOUSE_PIN_MAX];
13174 + };
13175 +};
13176 +
13177 +#endif /* _GPIO_MOUSE_H */
13178 diff --git a/include/linux/leds.h b/include/linux/leds.h
13179 index 88afcef..059abfe 100644
13180 --- a/include/linux/leds.h
13181 +++ b/include/linux/leds.h
13182 @@ -110,4 +110,18 @@ extern void ledtrig_ide_activity(void);
13183 #define ledtrig_ide_activity() do {} while(0)
13184 #endif
13185
13186 +/* For the leds-gpio driver */
13187 +struct gpio_led {
13188 + const char *name;
13189 + char *default_trigger;
13190 + unsigned gpio;
13191 + u8 active_low;
13192 +};
13193 +
13194 +struct gpio_led_platform_data {
13195 + int num_leds;
13196 + struct gpio_led *leds;
13197 +};
13198 +
13199 +
13200 #endif /* __LINUX_LEDS_H_INCLUDED */
13201 diff --git a/include/linux/spi/at73c213.h b/include/linux/spi/at73c213.h
13202 new file mode 100644
13203 index 0000000..0f20a70
13204 --- /dev/null
13205 +++ b/include/linux/spi/at73c213.h
13206 @@ -0,0 +1,25 @@
13207 +/*
13208 + * Board-specific data used to set up AT73c213 audio DAC driver.
13209 + */
13210 +
13211 +#ifndef __LINUX_SPI_AT73C213_H
13212 +#define __LINUX_SPI_AT73C213_H
13213 +
13214 +/**
13215 + * at73c213_board_info - how the external DAC is wired to the device.
13216 + *
13217 + * @ssc_id: SSC platform_driver id the DAC shall use to stream the audio.
13218 + * @dac_clk: the external clock used to provide master clock to the DAC.
13219 + * @shortname: a short discription for the DAC, seen by userspace tools.
13220 + *
13221 + * This struct contains the configuration of the hardware connection to the
13222 + * external DAC. The DAC needs a master clock and a I2S audio stream. It also
13223 + * provides a name which is used to identify it in userspace tools.
13224 + */
13225 +struct at73c213_board_info {
13226 + int ssc_id;
13227 + struct clk *dac_clk;
13228 + char shortname[32];
13229 +};
13230 +
13231 +#endif /* __LINUX_SPI_AT73C213_H */
13232 diff --git a/include/linux/usb/Kbuild b/include/linux/usb/Kbuild
13233 index 43f160c..6ce42bf 100644
13234 --- a/include/linux/usb/Kbuild
13235 +++ b/include/linux/usb/Kbuild
13236 @@ -1,5 +1,6 @@
13237 unifdef-y += audio.h
13238 unifdef-y += cdc.h
13239 unifdef-y += ch9.h
13240 +unifdef-y += gadgetfs.h
13241 unifdef-y += midi.h
13242
13243 diff --git a/include/linux/usb/gadgetfs.h b/include/linux/usb/gadgetfs.h
13244 new file mode 100644
13245 index 0000000..e8654c3
13246 --- /dev/null
13247 +++ b/include/linux/usb/gadgetfs.h
13248 @@ -0,0 +1,81 @@
13249 +#ifndef __LINUX_USB_GADGETFS_H
13250 +#define __LINUX_USB_GADGETFS_H
13251 +
13252 +#include <asm/types.h>
13253 +#include <asm/ioctl.h>
13254 +
13255 +#include <linux/usb/ch9.h>
13256 +
13257 +/*
13258 + * Filesystem based user-mode API to USB Gadget controller hardware
13259 + *
13260 + * Other than ep0 operations, most things are done by read() and write()
13261 + * on endpoint files found in one directory. They are configured by
13262 + * writing descriptors, and then may be used for normal stream style
13263 + * i/o requests. When ep0 is configured, the device can enumerate;
13264 + * when it's closed, the device disconnects from usb. Operations on
13265 + * ep0 require ioctl() operations.
13266 + *
13267 + * Configuration and device descriptors get written to /dev/gadget/$CHIP,
13268 + * which may then be used to read usb_gadgetfs_event structs. The driver
13269 + * may activate endpoints as it handles SET_CONFIGURATION setup events,
13270 + * or earlier; writing endpoint descriptors to /dev/gadget/$ENDPOINT
13271 + * then performing data transfers by reading or writing.
13272 + */
13273 +
13274 +/*
13275 + * Events are delivered on the ep0 file descriptor, when the user mode driver
13276 + * reads from this file descriptor after writing the descriptors. Don't
13277 + * stop polling this descriptor.
13278 + */
13279 +
13280 +enum usb_gadgetfs_event_type {
13281 + GADGETFS_NOP = 0,
13282 +
13283 + GADGETFS_CONNECT,
13284 + GADGETFS_DISCONNECT,
13285 + GADGETFS_SETUP,
13286 + GADGETFS_SUSPEND,
13287 + // and likely more !
13288 +};
13289 +
13290 +/* NOTE: this structure must stay the same size and layout on
13291 + * both 32-bit and 64-bit kernels.
13292 + */
13293 +struct usb_gadgetfs_event {
13294 + union {
13295 + // NOP, DISCONNECT, SUSPEND: nothing
13296 + // ... some hardware can't report disconnection
13297 +
13298 + // CONNECT: just the speed
13299 + enum usb_device_speed speed;
13300 +
13301 + // SETUP: packet; DATA phase i/o precedes next event
13302 + // (setup.bmRequestType & USB_DIR_IN) flags direction
13303 + // ... includes SET_CONFIGURATION, SET_INTERFACE
13304 + struct usb_ctrlrequest setup;
13305 + } u;
13306 + enum usb_gadgetfs_event_type type;
13307 +};
13308 +
13309 +
13310 +/* endpoint ioctls */
13311 +
13312 +/* IN transfers may be reported to the gadget driver as complete
13313 + * when the fifo is loaded, before the host reads the data;
13314 + * OUT transfers may be reported to the host's "client" driver as
13315 + * complete when they're sitting in the FIFO unread.
13316 + * THIS returns how many bytes are "unclaimed" in the endpoint fifo
13317 + * (needed for precise fault handling, when the hardware allows it)
13318 + */
13319 +#define GADGETFS_FIFO_STATUS _IO('g',1)
13320 +
13321 +/* discards any unclaimed data in the fifo. */
13322 +#define GADGETFS_FIFO_FLUSH _IO('g',2)
13323 +
13324 +/* resets endpoint halt+toggle; used to implement set_interface.
13325 + * some hardware (like pxa2xx) can't support this.
13326 + */
13327 +#define GADGETFS_CLEAR_HALT _IO('g',3)
13328 +
13329 +#endif /* __LINUX_USB_GADGETFS_H */
13330 diff --git a/include/linux/usb_gadgetfs.h b/include/linux/usb_gadgetfs.h
13331 deleted file mode 100644
13332 index 8086d5a..0000000
13333 --- a/include/linux/usb_gadgetfs.h
13334 +++ /dev/null
13335 @@ -1,75 +0,0 @@
13336 -
13337 -#include <asm/types.h>
13338 -#include <asm/ioctl.h>
13339 -
13340 -#include <linux/usb/ch9.h>
13341 -
13342 -/*
13343 - * Filesystem based user-mode API to USB Gadget controller hardware
13344 - *
13345 - * Almost everything can be done with only read and write operations,
13346 - * on endpoint files found in one directory. They are configured by
13347 - * writing descriptors, and then may be used for normal stream style
13348 - * i/o requests. When ep0 is configured, the device can enumerate;
13349 - * when it's closed, the device disconnects from usb.
13350 - *
13351 - * Configuration and device descriptors get written to /dev/gadget/$CHIP,
13352 - * which may then be used to read usb_gadgetfs_event structs. The driver
13353 - * may activate endpoints as it handles SET_CONFIGURATION setup events,
13354 - * or earlier; writing endpoint descriptors to /dev/gadget/$ENDPOINT
13355 - * then performing data transfers by reading or writing.
13356 - */
13357 -
13358 -/*
13359 - * Events are delivered on the ep0 file descriptor, if the user mode driver
13360 - * reads from this file descriptor after writing the descriptors. Don't
13361 - * stop polling this descriptor, if you write that kind of driver.
13362 - */
13363 -
13364 -enum usb_gadgetfs_event_type {
13365 - GADGETFS_NOP = 0,
13366 -
13367 - GADGETFS_CONNECT,
13368 - GADGETFS_DISCONNECT,
13369 - GADGETFS_SETUP,
13370 - GADGETFS_SUSPEND,
13371 - // and likely more !
13372 -};
13373 -
13374 -struct usb_gadgetfs_event {
13375 - enum usb_gadgetfs_event_type type;
13376 - union {
13377 - // NOP, DISCONNECT, SUSPEND: nothing
13378 - // ... some hardware can't report disconnection
13379 -
13380 - // CONNECT: just the speed
13381 - enum usb_device_speed speed;
13382 -
13383 - // SETUP: packet; DATA phase i/o precedes next event
13384 - // (setup.bmRequestType & USB_DIR_IN) flags direction
13385 - // ... includes SET_CONFIGURATION, SET_INTERFACE
13386 - struct usb_ctrlrequest setup;
13387 - } u;
13388 -};
13389 -
13390 -
13391 -/* endpoint ioctls */
13392 -
13393 -/* IN transfers may be reported to the gadget driver as complete
13394 - * when the fifo is loaded, before the host reads the data;
13395 - * OUT transfers may be reported to the host's "client" driver as
13396 - * complete when they're sitting in the FIFO unread.
13397 - * THIS returns how many bytes are "unclaimed" in the endpoint fifo
13398 - * (needed for precise fault handling, when the hardware allows it)
13399 - */
13400 -#define GADGETFS_FIFO_STATUS _IO('g',1)
13401 -
13402 -/* discards any unclaimed data in the fifo. */
13403 -#define GADGETFS_FIFO_FLUSH _IO('g',2)
13404 -
13405 -/* resets endpoint halt+toggle; used to implement set_interface.
13406 - * some hardware (like pxa2xx) can't support this.
13407 - */
13408 -#define GADGETFS_CLEAR_HALT _IO('g',3)
13409 -
13410 -
13411 diff --git a/init/do_mounts.c b/init/do_mounts.c
13412 index 46fe407..efc134c 100644
13413 --- a/init/do_mounts.c
13414 +++ b/init/do_mounts.c
13415 @@ -25,6 +25,7 @@ int __initdata rd_doload; /* 1 = load RAM disk, 0 = don't load */
13416 int root_mountflags = MS_RDONLY | MS_SILENT;
13417 char * __initdata root_device_name;
13418 static char __initdata saved_root_name[64];
13419 +int __initdata root_wait;
13420
13421 dev_t ROOT_DEV;
13422
13423 @@ -216,6 +217,14 @@ static int __init root_dev_setup(char *line)
13424
13425 __setup("root=", root_dev_setup);
13426
13427 +static int __init rootwait_setup(char *line)
13428 +{
13429 + root_wait = simple_strtol(line,NULL,0);
13430 + return 1;
13431 +}
13432 +
13433 +__setup("rootwait=", rootwait_setup);
13434 +
13435 static char * __initdata root_mount_data;
13436 static int __init root_data_setup(char *str)
13437 {
13438 @@ -438,11 +447,24 @@ void __init prepare_namespace(void)
13439 root_device_name += 5;
13440 }
13441
13442 - is_floppy = MAJOR(ROOT_DEV) == FLOPPY_MAJOR;
13443 -
13444 if (initrd_load())
13445 goto out;
13446
13447 + /* wait for any asynchronous scanning to complete */
13448 + if ((ROOT_DEV == 0) && root_wait) {
13449 + printk(KERN_INFO "Waiting for root device %s...\n",
13450 + saved_root_name);
13451 + do {
13452 + while (driver_probe_done() != 0)
13453 + msleep(100);
13454 + ROOT_DEV = name_to_dev_t(saved_root_name);
13455 + if (ROOT_DEV == 0)
13456 + msleep(100);
13457 + } while (ROOT_DEV == 0);
13458 + }
13459 +
13460 + is_floppy = MAJOR(ROOT_DEV) == FLOPPY_MAJOR;
13461 +
13462 if (is_floppy && rd_doload && rd_load_disk(0))
13463 ROOT_DEV = Root_RAM0;
13464
13465 diff --git a/scripts/checkstack.pl b/scripts/checkstack.pl
13466 index f7844f6..6631586 100755
13467 --- a/scripts/checkstack.pl
13468 +++ b/scripts/checkstack.pl
13469 @@ -12,6 +12,7 @@
13470 # sh64 port by Paul Mundt
13471 # Random bits by Matt Mackall <mpm@selenic.com>
13472 # M68k port by Geert Uytterhoeven and Andreas Schwab
13473 +# AVR32 port by Haavard Skinnemoen <hskinnemoen@atmel.com>
13474 #
13475 # Usage:
13476 # objdump -d vmlinux | stackcheck.pl [arch]
13477 @@ -37,6 +38,10 @@ my (@stack, $re, $x, $xs);
13478 if ($arch eq 'arm') {
13479 #c0008ffc: e24dd064 sub sp, sp, #100 ; 0x64
13480 $re = qr/.*sub.*sp, sp, #(([0-9]{2}|[3-9])[0-9]{2})/o;
13481 + } elsif ($arch eq 'avr32') {
13482 + #8000008a: 20 1d sub sp,4
13483 + #80000ca8: fa cd 05 b0 sub sp,sp,1456
13484 + $re = qr/^.*sub.*sp.*,([0-9]{1,8})/o;
13485 } elsif ($arch =~ /^i[3456]86$/) {
13486 #c0105234: 81 ec ac 05 00 00 sub $0x5ac,%esp
13487 $re = qr/^.*[as][du][db] \$(0x$x{1,8}),\%esp$/o;
13488 diff --git a/sound/Kconfig b/sound/Kconfig
13489 index 9ea4738..9217739 100644
13490 --- a/sound/Kconfig
13491 +++ b/sound/Kconfig
13492 @@ -63,9 +63,13 @@ source "sound/aoa/Kconfig"
13493
13494 source "sound/arm/Kconfig"
13495
13496 +if SPI
13497 +source "sound/spi/Kconfig"
13498 +endif
13499 +
13500 source "sound/mips/Kconfig"
13501
13502 -# the following will depend on the order of config.
13503 +# tee following will depend on the order of config.
13504 # here assuming USB is defined before ALSA
13505 source "sound/usb/Kconfig"
13506
13507 diff --git a/sound/Makefile b/sound/Makefile
13508 index b7c7fb7..581ea5e 100644
13509 --- a/sound/Makefile
13510 +++ b/sound/Makefile
13511 @@ -5,7 +5,8 @@ obj-$(CONFIG_SOUND) += soundcore.o
13512 obj-$(CONFIG_SOUND_PRIME) += sound_firmware.o
13513 obj-$(CONFIG_SOUND_PRIME) += oss/
13514 obj-$(CONFIG_DMASOUND) += oss/
13515 -obj-$(CONFIG_SND) += core/ i2c/ drivers/ isa/ pci/ ppc/ arm/ synth/ usb/ sparc/ parisc/ pcmcia/ mips/ soc/
13516 +obj-$(CONFIG_SND) += core/ i2c/ drivers/ isa/ pci/ ppc/ arm/ synth/ usb/ \
13517 + sparc/ spi/ parisc/ pcmcia/ mips/ soc/
13518 obj-$(CONFIG_SND_AOA) += aoa/
13519
13520 # This one must be compilable even if sound is configured out
13521 diff --git a/sound/spi/Kconfig b/sound/spi/Kconfig
13522 new file mode 100644
13523 index 0000000..0d08c29
13524 --- /dev/null
13525 +++ b/sound/spi/Kconfig
13526 @@ -0,0 +1,31 @@
13527 +#SPI drivers
13528 +
13529 +menu "SPI devices"
13530 + depends on SND != n
13531 +
13532 +config SND_AT73C213
13533 + tristate "Atmel AT73C213 DAC driver"
13534 + depends on ATMEL_SSC
13535 + select SND_PCM
13536 + help
13537 + Say Y here if you want to use the Atmel AT73C213 external DAC. This
13538 + DAC can be found on Atmel development boards.
13539 +
13540 + This driver requires the Atmel SSC driver for sound sink, a
13541 + peripheral found on most AT91 and AVR32 microprocessors.
13542 +
13543 + To compile this driver as a module, choose M here: the module will be
13544 + called snd-at73c213.
13545 +
13546 +config SND_AT73C213_TARGET_BITRATE
13547 + int "Target bitrate for AT73C213"
13548 + depends on SND_AT73C213
13549 + default "48000"
13550 + range 8000 50000
13551 + help
13552 + Sets the target bitrate for the bitrate calculator in the driver.
13553 + Limited by hardware to be between 8000 Hz and 50000 Hz.
13554 +
13555 + Set to 48000 Hz by default.
13556 +
13557 +endmenu
13558 diff --git a/sound/spi/Makefile b/sound/spi/Makefile
13559 new file mode 100644
13560 index 0000000..026fb73
13561 --- /dev/null
13562 +++ b/sound/spi/Makefile
13563 @@ -0,0 +1,5 @@
13564 +# Makefile for SPI drivers
13565 +
13566 +snd-at73c213-objs := at73c213.o
13567 +
13568 +obj-$(CONFIG_SND_AT73C213) += snd-at73c213.o
13569 diff --git a/sound/spi/at73c213.c b/sound/spi/at73c213.c
13570 new file mode 100644
13571 index 0000000..f514f47
13572 --- /dev/null
13573 +++ b/sound/spi/at73c213.c
13574 @@ -0,0 +1,1121 @@
13575 +/*
13576 + * Driver for AT73C213 16-bit stereo DAC connected to Atmel SSC
13577 + *
13578 + * Copyright (C) 2006-2007 Atmel Norway
13579 + *
13580 + * This program is free software; you can redistribute it and/or modify it
13581 + * under the terms of the GNU General Public License version 2 as published by
13582 + * the Free Software Foundation.
13583 + */
13584 +
13585 +/*#define DEBUG*/
13586 +
13587 +#include <linux/clk.h>
13588 +#include <linux/err.h>
13589 +#include <linux/delay.h>
13590 +#include <linux/device.h>
13591 +#include <linux/dma-mapping.h>
13592 +#include <linux/init.h>
13593 +#include <linux/interrupt.h>
13594 +#include <linux/module.h>
13595 +#include <linux/platform_device.h>
13596 +#include <linux/io.h>
13597 +
13598 +#include <sound/driver.h>
13599 +#include <sound/initval.h>
13600 +#include <sound/control.h>
13601 +#include <sound/core.h>
13602 +#include <sound/pcm.h>
13603 +
13604 +#include <linux/atmel-ssc.h>
13605 +
13606 +#include <linux/spi/spi.h>
13607 +#include <linux/spi/at73c213.h>
13608 +
13609 +#include "at73c213.h"
13610 +
13611 +#define BITRATE_MIN 8000 /* Hardware limit? */
13612 +#define BITRATE_TARGET CONFIG_SND_AT73C213_TARGET_BITRATE
13613 +#define BITRATE_MAX 50000 /* Hardware limit. */
13614 +
13615 +/* Initial (hardware reset) AT73C213 register values. */
13616 +static u8 snd_at73c213_original_image[18] =
13617 +{
13618 + 0x00, /* 00 - CTRL */
13619 + 0x05, /* 01 - LLIG */
13620 + 0x05, /* 02 - RLIG */
13621 + 0x08, /* 03 - LPMG */
13622 + 0x08, /* 04 - RPMG */
13623 + 0x00, /* 05 - LLOG */
13624 + 0x00, /* 06 - RLOG */
13625 + 0x22, /* 07 - OLC */
13626 + 0x09, /* 08 - MC */
13627 + 0x00, /* 09 - CSFC */
13628 + 0x00, /* 0A - MISC */
13629 + 0x00, /* 0B - */
13630 + 0x00, /* 0C - PRECH */
13631 + 0x05, /* 0D - AUXG */
13632 + 0x00, /* 0E - */
13633 + 0x00, /* 0F - */
13634 + 0x00, /* 10 - RST */
13635 + 0x00, /* 11 - PA_CTRL */
13636 +};
13637 +
13638 +struct snd_at73c213 {
13639 + struct snd_card *card;
13640 + struct snd_pcm *pcm;
13641 + struct snd_pcm_substream *substream;
13642 + struct at73c213_board_info *board;
13643 + int irq;
13644 + int period;
13645 + unsigned long bitrate;
13646 + struct clk *bitclk;
13647 + struct ssc_device *ssc;
13648 + struct spi_device *spi;
13649 + u8 spi_wbuffer[2];
13650 + u8 spi_rbuffer[2];
13651 + /* Image of the SPI registers in AT73C213. */
13652 + u8 reg_image[18];
13653 + /* Protect registers against concurrent access. */
13654 + spinlock_t lock;
13655 +};
13656 +
13657 +#define get_chip(card) ((struct snd_at73c213 *)card->private_data)
13658 +
13659 +static int
13660 +snd_at73c213_write_reg(struct snd_at73c213 *chip, u8 reg, u8 val)
13661 +{
13662 + struct spi_message msg;
13663 + struct spi_transfer msg_xfer = {
13664 + .len = 2,
13665 + .cs_change = 0,
13666 + };
13667 + int retval;
13668 +
13669 + spi_message_init(&msg);
13670 +
13671 + chip->spi_wbuffer[0] = reg;
13672 + chip->spi_wbuffer[1] = val;
13673 +
13674 + msg_xfer.tx_buf = chip->spi_wbuffer;
13675 + msg_xfer.rx_buf = chip->spi_rbuffer;
13676 + spi_message_add_tail(&msg_xfer, &msg);
13677 +
13678 + retval = spi_sync(chip->spi, &msg);
13679 +
13680 + if (!retval)
13681 + chip->reg_image[reg] = val;
13682 +
13683 + return retval;
13684 +}
13685 +
13686 +static struct snd_pcm_hardware snd_at73c213_playback_hw = {
13687 + .info = SNDRV_PCM_INFO_INTERLEAVED |
13688 + SNDRV_PCM_INFO_BLOCK_TRANSFER,
13689 + .formats = SNDRV_PCM_FMTBIT_S16_BE,
13690 + .rates = SNDRV_PCM_RATE_CONTINUOUS,
13691 + .rate_min = 8000, /* Replaced by chip->bitrate later. */
13692 + .rate_max = 50000, /* Replaced by chip->bitrate later. */
13693 + .channels_min = 2,
13694 + .channels_max = 2,
13695 + .buffer_bytes_max = 64 * 1024 - 1,
13696 + .period_bytes_min = 512,
13697 + .period_bytes_max = 64 * 1024 - 1,
13698 + .periods_min = 4,
13699 + .periods_max = 1024,
13700 +};
13701 +
13702 +/*
13703 + * Calculate and set bitrate and divisions.
13704 + */
13705 +static int snd_at73c213_set_bitrate(struct snd_at73c213 *chip)
13706 +{
13707 + unsigned long ssc_rate = clk_get_rate(chip->ssc->clk);
13708 + unsigned long dac_rate_new, ssc_div, status;
13709 + unsigned long ssc_div_max, ssc_div_min;
13710 + int max_tries;
13711 +
13712 + /*
13713 + * We connect two clocks here, picking divisors so the I2S clocks
13714 + * out data at the same rate the DAC clocks it in ... and as close
13715 + * as practical to the desired target rate.
13716 + *
13717 + * The DAC master clock (MCLK) is programmable, and is either 256
13718 + * or (not here) 384 times the I2S output clock (BCLK).
13719 + */
13720 +
13721 + /* SSC clock / (bitrate * stereo * 16-bit). */
13722 + ssc_div = ssc_rate / (BITRATE_TARGET * 2 * 16);
13723 + ssc_div_min = ssc_rate / (BITRATE_MAX * 2 * 16);
13724 + ssc_div_max = ssc_rate / (BITRATE_MIN * 2 * 16);
13725 + max_tries = (ssc_div_max - ssc_div_min) / 2;
13726 +
13727 + if (max_tries < 1)
13728 + max_tries = 1;
13729 +
13730 + /* ssc_div must be a power of 2. */
13731 + ssc_div = (ssc_div + 1) & ~1UL;
13732 +
13733 + if ((ssc_rate / (ssc_div * 2 * 16)) < BITRATE_MIN) {
13734 + ssc_div -= 2;
13735 + if ((ssc_rate / (ssc_div * 2 * 16)) > BITRATE_MAX)
13736 + return -ENXIO;
13737 + }
13738 +
13739 + /* Search for a possible bitrate. */
13740 + do {
13741 + /* SSC clock / (ssc divider * 16-bit * stereo). */
13742 + if ((ssc_rate / (ssc_div * 2 * 16)) < BITRATE_MIN)
13743 + return -ENXIO;
13744 +
13745 + /* 256 / (2 * 16) = 8 */
13746 + dac_rate_new = 8 * (ssc_rate / ssc_div);
13747 +
13748 + status = clk_round_rate(chip->board->dac_clk, dac_rate_new);
13749 + if (status < 0)
13750 + return status;
13751 +
13752 + /* Ignore difference smaller than 256 Hz. */
13753 + if ((status/256) == (dac_rate_new/256))
13754 + goto set_rate;
13755 +
13756 + ssc_div += 2;
13757 + } while (--max_tries);
13758 +
13759 + /* Not able to find a valid bitrate. */
13760 + return -ENXIO;
13761 +
13762 +set_rate:
13763 + status = clk_set_rate(chip->board->dac_clk, status);
13764 + if (status < 0)
13765 + return status;
13766 +
13767 + /* Set divider in SSC device. */
13768 + ssc_writel(chip->ssc->regs, CMR, ssc_div/2);
13769 +
13770 + /* SSC clock / (ssc divider * 16-bit * stereo). */
13771 + chip->bitrate = ssc_rate / (ssc_div * 16 * 2);
13772 +
13773 + dev_info(&chip->spi->dev,
13774 + "at73c213: supported bitrate is %lu (%lu divider)\n",
13775 + chip->bitrate, ssc_div);
13776 +
13777 + return 0;
13778 +}
13779 +
13780 +static int snd_at73c213_pcm_open(struct snd_pcm_substream *substream)
13781 +{
13782 + struct snd_at73c213 *chip = snd_pcm_substream_chip(substream);
13783 + struct snd_pcm_runtime *runtime = substream->runtime;
13784 +
13785 + snd_at73c213_playback_hw.rate_min = chip->bitrate;
13786 + snd_at73c213_playback_hw.rate_max = chip->bitrate;
13787 + runtime->hw = snd_at73c213_playback_hw;
13788 + chip->substream = substream;
13789 +
13790 + return 0;
13791 +}
13792 +
13793 +static int snd_at73c213_pcm_close(struct snd_pcm_substream *substream)
13794 +{
13795 + struct snd_at73c213 *chip = snd_pcm_substream_chip(substream);
13796 + chip->substream = NULL;
13797 + return 0;
13798 +}
13799 +
13800 +static int snd_at73c213_pcm_hw_params(struct snd_pcm_substream *substream,
13801 + struct snd_pcm_hw_params *hw_params)
13802 +{
13803 + return snd_pcm_lib_malloc_pages(substream,
13804 + params_buffer_bytes(hw_params));
13805 +}
13806 +
13807 +static int snd_at73c213_pcm_hw_free(struct snd_pcm_substream *substream)
13808 +{
13809 + return snd_pcm_lib_free_pages(substream);
13810 +}
13811 +
13812 +static int snd_at73c213_pcm_prepare(struct snd_pcm_substream *substream)
13813 +{
13814 + struct snd_at73c213 *chip = snd_pcm_substream_chip(substream);
13815 + struct snd_pcm_runtime *runtime = substream->runtime;
13816 + int block_size;
13817 +
13818 + block_size = frames_to_bytes(runtime, runtime->period_size);
13819 +
13820 + chip->period = 0;
13821 +
13822 + ssc_writel(chip->ssc->regs, PDC_TPR,
13823 + (long)runtime->dma_addr);
13824 + ssc_writel(chip->ssc->regs, PDC_TCR, runtime->period_size * 2);
13825 + ssc_writel(chip->ssc->regs, PDC_TNPR,
13826 + (long)runtime->dma_addr + block_size);
13827 + ssc_writel(chip->ssc->regs, PDC_TNCR, runtime->period_size * 2);
13828 +
13829 + return 0;
13830 +}
13831 +
13832 +static int snd_at73c213_pcm_trigger(struct snd_pcm_substream *substream,
13833 + int cmd)
13834 +{
13835 + struct snd_at73c213 *chip = snd_pcm_substream_chip(substream);
13836 + int retval = 0;
13837 +
13838 + spin_lock(&chip->lock);
13839 +
13840 + switch (cmd) {
13841 + case SNDRV_PCM_TRIGGER_START:
13842 + ssc_writel(chip->ssc->regs, IER, SSC_BIT(IER_ENDTX));
13843 + ssc_writel(chip->ssc->regs, PDC_PTCR, SSC_BIT(PDC_PTCR_TXTEN));
13844 + break;
13845 + case SNDRV_PCM_TRIGGER_STOP:
13846 + ssc_writel(chip->ssc->regs, PDC_PTCR, SSC_BIT(PDC_PTCR_TXTDIS));
13847 + ssc_writel(chip->ssc->regs, IDR, SSC_BIT(IDR_ENDTX));
13848 + break;
13849 + default:
13850 + dev_dbg(&chip->spi->dev, "spurious command %x\n", cmd);
13851 + retval = -EINVAL;
13852 + break;
13853 + }
13854 +
13855 + spin_unlock(&chip->lock);
13856 +
13857 + return retval;
13858 +}
13859 +
13860 +static snd_pcm_uframes_t
13861 +snd_at73c213_pcm_pointer(struct snd_pcm_substream *substream)
13862 +{
13863 + struct snd_at73c213 *chip = snd_pcm_substream_chip(substream);
13864 + struct snd_pcm_runtime *runtime = substream->runtime;
13865 + snd_pcm_uframes_t pos;
13866 + unsigned long bytes;
13867 +
13868 + bytes = ssc_readl(chip->ssc->regs, PDC_TPR)
13869 + - (unsigned long)runtime->dma_addr;
13870 +
13871 + pos = bytes_to_frames(runtime, bytes);
13872 + if (pos >= runtime->buffer_size)
13873 + pos -= runtime->buffer_size;
13874 +
13875 + return pos;
13876 +}
13877 +
13878 +static struct snd_pcm_ops at73c213_playback_ops = {
13879 + .open = snd_at73c213_pcm_open,
13880 + .close = snd_at73c213_pcm_close,
13881 + .ioctl = snd_pcm_lib_ioctl,
13882 + .hw_params = snd_at73c213_pcm_hw_params,
13883 + .hw_free = snd_at73c213_pcm_hw_free,
13884 + .prepare = snd_at73c213_pcm_prepare,
13885 + .trigger = snd_at73c213_pcm_trigger,
13886 + .pointer = snd_at73c213_pcm_pointer,
13887 +};
13888 +
13889 +static void snd_at73c213_pcm_free(struct snd_pcm *pcm)
13890 +{
13891 + struct snd_at73c213 *chip = snd_pcm_chip(pcm);
13892 + if (chip->pcm) {
13893 + snd_pcm_lib_preallocate_free_for_all(chip->pcm);
13894 + chip->pcm = NULL;
13895 + }
13896 +}
13897 +
13898 +static int __devinit snd_at73c213_pcm_new(struct snd_at73c213 *chip, int device)
13899 +{
13900 + struct snd_pcm *pcm;
13901 + int retval;
13902 +
13903 + retval = snd_pcm_new(chip->card, chip->card->shortname,
13904 + device, 1, 0, &pcm);
13905 + if (retval < 0)
13906 + goto out;
13907 +
13908 + pcm->private_data = chip;
13909 + pcm->private_free = snd_at73c213_pcm_free;
13910 + pcm->info_flags = SNDRV_PCM_INFO_BLOCK_TRANSFER;
13911 + strcpy(pcm->name, "at73c213");
13912 + chip->pcm = pcm;
13913 +
13914 + snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &at73c213_playback_ops);
13915 +
13916 + retval = snd_pcm_lib_preallocate_pages_for_all(chip->pcm,
13917 + SNDRV_DMA_TYPE_DEV, &chip->ssc->pdev->dev,
13918 + 64 * 1024, 64 * 1024);
13919 +out:
13920 + return retval;
13921 +}
13922 +
13923 +static irqreturn_t snd_at73c213_interrupt(int irq, void *dev_id)
13924 +{
13925 + struct snd_at73c213 *chip = dev_id;
13926 + struct snd_pcm_runtime *runtime = chip->substream->runtime;
13927 + u32 status;
13928 + int offset;
13929 + int block_size;
13930 + int next_period;
13931 + int retval = IRQ_NONE;
13932 +
13933 + spin_lock(&chip->lock);
13934 +
13935 + block_size = frames_to_bytes(runtime, runtime->period_size);
13936 + status = ssc_readl(chip->ssc->regs, IMR);
13937 +
13938 + if (status & SSC_BIT(IMR_ENDTX)) {
13939 + chip->period++;
13940 + if (chip->period == runtime->periods)
13941 + chip->period = 0;
13942 + next_period = chip->period + 1;
13943 + if (next_period == runtime->periods)
13944 + next_period = 0;
13945 +
13946 + offset = block_size * next_period;
13947 +
13948 + ssc_writel(chip->ssc->regs, PDC_TNPR,
13949 + (long)runtime->dma_addr + offset);
13950 + ssc_writel(chip->ssc->regs, PDC_TNCR, runtime->period_size * 2);
13951 + retval = IRQ_HANDLED;
13952 + }
13953 +
13954 + ssc_readl(chip->ssc->regs, IMR);
13955 + spin_unlock(&chip->lock);
13956 +
13957 + if (status & SSC_BIT(IMR_ENDTX))
13958 + snd_pcm_period_elapsed(chip->substream);
13959 +
13960 + return retval;
13961 +}
13962 +
13963 +/*
13964 + * Mixer functions.
13965 + */
13966 +static int snd_at73c213_mono_get(struct snd_kcontrol *kcontrol,
13967 + struct snd_ctl_elem_value *ucontrol)
13968 +{
13969 + struct snd_at73c213 *chip = snd_kcontrol_chip(kcontrol);
13970 + int reg = kcontrol->private_value & 0xff;
13971 + int shift = (kcontrol->private_value >> 8) & 0xff;
13972 + int mask = (kcontrol->private_value >> 16) & 0xff;
13973 + int invert = (kcontrol->private_value >> 24) & 0xff;
13974 +
13975 + spin_lock_irq(&chip->lock);
13976 +
13977 + ucontrol->value.integer.value[0] = (chip->reg_image[reg] >> shift) & mask;
13978 +
13979 + if (invert)
13980 + ucontrol->value.integer.value[0] =
13981 + (mask - ucontrol->value.integer.value[0]);
13982 +
13983 + spin_unlock_irq(&chip->lock);
13984 +
13985 + return 0;
13986 +}
13987 +
13988 +static int snd_at73c213_mono_put(struct snd_kcontrol *kcontrol,
13989 + struct snd_ctl_elem_value *ucontrol)
13990 +{
13991 + struct snd_at73c213 *chip = snd_kcontrol_chip(kcontrol);
13992 + int reg = kcontrol->private_value & 0xff;
13993 + int shift = (kcontrol->private_value >> 8) & 0xff;
13994 + int mask = (kcontrol->private_value >> 16) & 0xff;
13995 + int invert = (kcontrol->private_value >> 24) & 0xff;
13996 + int change, retval;
13997 + unsigned short val;
13998 +
13999 + val = (ucontrol->value.integer.value[0] & mask);
14000 + if (invert)
14001 + val = mask - val;
14002 + val <<= shift;
14003 +
14004 + spin_lock_irq(&chip->lock);
14005 +
14006 + val = (chip->reg_image[reg] & ~(mask << shift)) | val;
14007 + change = val != chip->reg_image[reg];
14008 + retval = snd_at73c213_write_reg(chip, reg, val);
14009 +
14010 + spin_unlock_irq(&chip->lock);
14011 +
14012 + if (retval)
14013 + return retval;
14014 +
14015 + return change;
14016 +}
14017 +
14018 +static int snd_at73c213_stereo_info(struct snd_kcontrol *kcontrol,
14019 + struct snd_ctl_elem_info *uinfo)
14020 +{
14021 + int mask = (kcontrol->private_value >> 24) & 0xff;
14022 +
14023 + if (mask == 1)
14024 + uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
14025 + else
14026 + uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
14027 +
14028 + uinfo->count = 2;
14029 + uinfo->value.integer.min = 0;
14030 + uinfo->value.integer.max = mask;
14031 +
14032 + return 0;
14033 +}
14034 +
14035 +static int snd_at73c213_stereo_get(struct snd_kcontrol *kcontrol,
14036 + struct snd_ctl_elem_value *ucontrol)
14037 +{
14038 + struct snd_at73c213 *chip = snd_kcontrol_chip(kcontrol);
14039 + int left_reg = kcontrol->private_value & 0xff;
14040 + int right_reg = (kcontrol->private_value >> 8) & 0xff;
14041 + int shift_left = (kcontrol->private_value >> 16) & 0x07;
14042 + int shift_right = (kcontrol->private_value >> 19) & 0x07;
14043 + int mask = (kcontrol->private_value >> 24) & 0xff;
14044 + int invert = (kcontrol->private_value >> 22) & 1;
14045 +
14046 + spin_lock_irq(&chip->lock);
14047 +
14048 + ucontrol->value.integer.value[0] =
14049 + (chip->reg_image[left_reg] >> shift_left) & mask;
14050 + ucontrol->value.integer.value[1] =
14051 + (chip->reg_image[right_reg] >> shift_right) & mask;
14052 +
14053 + if (invert) {
14054 + ucontrol->value.integer.value[0] =
14055 + (mask - ucontrol->value.integer.value[0]);
14056 + ucontrol->value.integer.value[1] =
14057 + (mask - ucontrol->value.integer.value[1]);
14058 + }
14059 +
14060 + spin_unlock_irq(&chip->lock);
14061 +
14062 + return 0;
14063 +}
14064 +
14065 +static int snd_at73c213_stereo_put(struct snd_kcontrol *kcontrol,
14066 + struct snd_ctl_elem_value *ucontrol)
14067 +{
14068 + struct snd_at73c213 *chip = snd_kcontrol_chip(kcontrol);
14069 + int left_reg = kcontrol->private_value & 0xff;
14070 + int right_reg = (kcontrol->private_value >> 8) & 0xff;
14071 + int shift_left = (kcontrol->private_value >> 16) & 0x07;
14072 + int shift_right = (kcontrol->private_value >> 19) & 0x07;
14073 + int mask = (kcontrol->private_value >> 24) & 0xff;
14074 + int invert = (kcontrol->private_value >> 22) & 1;
14075 + int change, retval;
14076 + unsigned short val1, val2;
14077 +
14078 + val1 = ucontrol->value.integer.value[0] & mask;
14079 + val2 = ucontrol->value.integer.value[1] & mask;
14080 + if (invert) {
14081 + val1 = mask - val1;
14082 + val2 = mask - val2;
14083 + }
14084 + val1 <<= shift_left;
14085 + val2 <<= shift_right;
14086 +
14087 + spin_lock_irq(&chip->lock);
14088 +
14089 + val1 = (chip->reg_image[left_reg] & ~(mask << shift_left)) | val1;
14090 + val2 = (chip->reg_image[right_reg] & ~(mask << shift_right)) | val2;
14091 + change = val1 != chip->reg_image[left_reg]
14092 + || val2 != chip->reg_image[right_reg];
14093 + retval = snd_at73c213_write_reg(chip, left_reg, val1);
14094 + if (retval) {
14095 + spin_unlock_irq(&chip->lock);
14096 + goto out;
14097 + }
14098 + retval = snd_at73c213_write_reg(chip, right_reg, val2);
14099 + if (retval) {
14100 + spin_unlock_irq(&chip->lock);
14101 + goto out;
14102 + }
14103 +
14104 + spin_unlock_irq(&chip->lock);
14105 +
14106 + return change;
14107 +
14108 +out:
14109 + return retval;
14110 +}
14111 +
14112 +static int snd_at73c213_mono_switch_info(struct snd_kcontrol *kcontrol,
14113 + struct snd_ctl_elem_info *uinfo)
14114 +{
14115 + uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
14116 + uinfo->count = 1;
14117 + uinfo->value.integer.min = 0;
14118 + uinfo->value.integer.max = 1;
14119 +
14120 + return 0;
14121 +}
14122 +
14123 +static int snd_at73c213_mono_switch_get(struct snd_kcontrol *kcontrol,
14124 + struct snd_ctl_elem_value *ucontrol)
14125 +{
14126 + struct snd_at73c213 *chip = snd_kcontrol_chip(kcontrol);
14127 + int reg = kcontrol->private_value & 0xff;
14128 + int shift = (kcontrol->private_value >> 8) & 0xff;
14129 + int invert = (kcontrol->private_value >> 24) & 0xff;
14130 +
14131 + spin_lock_irq(&chip->lock);
14132 +
14133 + ucontrol->value.integer.value[0] = (chip->reg_image[reg] >> shift) & 0x01;
14134 +
14135 + if (invert)
14136 + ucontrol->value.integer.value[0] =
14137 + (0x01 - ucontrol->value.integer.value[0]);
14138 +
14139 + spin_unlock_irq(&chip->lock);
14140 +
14141 + return 0;
14142 +}
14143 +
14144 +static int snd_at73c213_mono_switch_put(struct snd_kcontrol *kcontrol,
14145 + struct snd_ctl_elem_value *ucontrol)
14146 +{
14147 + struct snd_at73c213 *chip = snd_kcontrol_chip(kcontrol);
14148 + int reg = kcontrol->private_value & 0xff;
14149 + int shift = (kcontrol->private_value >> 8) & 0xff;
14150 + int mask = (kcontrol->private_value >> 16) & 0xff;
14151 + int invert = (kcontrol->private_value >> 24) & 0xff;
14152 + int change, retval;
14153 + unsigned short val;
14154 +
14155 + if (ucontrol->value.integer.value[0])
14156 + val = mask;
14157 + else
14158 + val = 0;
14159 +
14160 + if (invert)
14161 + val = mask - val;
14162 + val <<= shift;
14163 +
14164 + spin_lock_irq(&chip->lock);
14165 +
14166 + val |= (chip->reg_image[reg] & ~(mask << shift));
14167 + change = val != chip->reg_image[reg];
14168 +
14169 + retval = snd_at73c213_write_reg(chip, reg, val);
14170 +
14171 + spin_unlock_irq(&chip->lock);
14172 +
14173 + if (retval)
14174 + return retval;
14175 +
14176 + return change;
14177 +}
14178 +
14179 +static int snd_at73c213_pa_volume_info(struct snd_kcontrol *kcontrol,
14180 + struct snd_ctl_elem_info *uinfo)
14181 +{
14182 + uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
14183 + uinfo->count = 1;
14184 + uinfo->value.integer.min = 0;
14185 + uinfo->value.integer.max = ((kcontrol->private_value >> 16) & 0xff) - 1;
14186 +
14187 + return 0;
14188 +}
14189 +
14190 +static int snd_at73c213_line_capture_volume_info(
14191 + struct snd_kcontrol *kcontrol,
14192 + struct snd_ctl_elem_info *uinfo)
14193 +{
14194 + uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
14195 + uinfo->count = 2;
14196 + /* When inverted will give values 0x10001 => 0. */
14197 + uinfo->value.integer.min = 14;
14198 + uinfo->value.integer.max = 31;
14199 +
14200 + return 0;
14201 +}
14202 +
14203 +static int snd_at73c213_aux_capture_volume_info(
14204 + struct snd_kcontrol *kcontrol,
14205 + struct snd_ctl_elem_info *uinfo)
14206 +{
14207 + uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
14208 + uinfo->count = 1;
14209 + /* When inverted will give values 0x10001 => 0. */
14210 + uinfo->value.integer.min = 14;
14211 + uinfo->value.integer.max = 31;
14212 +
14213 + return 0;
14214 +}
14215 +
14216 +#define AT73C213_MONO_SWITCH(xname, xindex, reg, shift, mask, invert) \
14217 +{ \
14218 + .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
14219 + .name = xname, \
14220 + .index = xindex, \
14221 + .info = snd_at73c213_mono_switch_info, \
14222 + .get = snd_at73c213_mono_switch_get, \
14223 + .put = snd_at73c213_mono_switch_put, \
14224 + .private_value = (reg | (shift << 8) | (mask << 16) | (invert << 24)) \
14225 +}
14226 +
14227 +#define AT73C213_STEREO(xname, xindex, left_reg, right_reg, shift_left, shift_right, mask, invert) \
14228 +{ \
14229 + .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
14230 + .name = xname, \
14231 + .index = xindex, \
14232 + .info = snd_at73c213_stereo_info, \
14233 + .get = snd_at73c213_stereo_get, \
14234 + .put = snd_at73c213_stereo_put, \
14235 + .private_value = (left_reg | (right_reg << 8) \
14236 + | (shift_left << 16) | (shift_right << 19) \
14237 + | (mask << 24) | (invert << 22)) \
14238 +}
14239 +
14240 +static struct snd_kcontrol_new snd_at73c213_controls[] __devinitdata = {
14241 +AT73C213_STEREO("Master Playback Volume", 0, DAC_LMPG, DAC_RMPG, 0, 0, 0x1f, 1),
14242 +AT73C213_STEREO("Master Playback Switch", 0, DAC_LMPG, DAC_RMPG, 5, 5, 1, 1),
14243 +AT73C213_STEREO("PCM Playback Volume", 0, DAC_LLOG, DAC_RLOG, 0, 0, 0x1f, 1),
14244 +AT73C213_STEREO("PCM Playback Switch", 0, DAC_LLOG, DAC_RLOG, 5, 5, 1, 1),
14245 +AT73C213_MONO_SWITCH("Mono PA Playback Switch", 0, DAC_CTRL, DAC_CTRL_ONPADRV, 0x01, 0),
14246 +{
14247 + .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
14248 + .name = "PA Playback Volume",
14249 + .index = 0,
14250 + .info = snd_at73c213_pa_volume_info,
14251 + .get = snd_at73c213_mono_get,
14252 + .put = snd_at73c213_mono_put,
14253 + .private_value = PA_CTRL | (PA_CTRL_APAGAIN << 8) | (0x0f << 16) | (1 << 24),
14254 +},
14255 +AT73C213_MONO_SWITCH("PA High Gain Playback Switch", 0, PA_CTRL, PA_CTRL_APALP, 0x01, 1),
14256 +AT73C213_MONO_SWITCH("PA Playback Switch", 0, PA_CTRL, PA_CTRL_APAON, 0x01, 0),
14257 +{
14258 + .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
14259 + .name = "Aux Capture Volume",
14260 + .index = 0,
14261 + .info = snd_at73c213_aux_capture_volume_info,
14262 + .get = snd_at73c213_mono_get,
14263 + .put = snd_at73c213_mono_put,
14264 + .private_value = DAC_AUXG | (0 << 8) | (0x1f << 16) | (1 << 24),
14265 +},
14266 +AT73C213_MONO_SWITCH("Aux Capture Switch", 0, DAC_CTRL, DAC_CTRL_ONAUXIN, 0x01, 0),
14267 +{
14268 + .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
14269 + .name = "Line Capture Volume",
14270 + .index = 0,
14271 + .info = snd_at73c213_line_capture_volume_info,
14272 + .get = snd_at73c213_stereo_get,
14273 + .put = snd_at73c213_stereo_put,
14274 + .private_value = DAC_LLIG | (DAC_RLIG << 8) | (0 << 16) | (0 << 19)
14275 + | (0x1f << 24) | (1 << 22),
14276 +},
14277 +AT73C213_MONO_SWITCH("Line Capture Switch", 0, DAC_CTRL, 0, 0x03, 0),
14278 +};
14279 +
14280 +static int __devinit snd_at73c213_mixer(struct snd_at73c213 *chip)
14281 +{
14282 + struct snd_card *card;
14283 + int errval, idx;
14284 +
14285 + if (chip == NULL || chip->pcm == NULL)
14286 + return -EINVAL;
14287 +
14288 + card = chip->card;
14289 +
14290 + strcpy(card->mixername, chip->pcm->name);
14291 +
14292 + for (idx = 0; idx < ARRAY_SIZE(snd_at73c213_controls); idx++) {
14293 + errval = snd_ctl_add(card,
14294 + snd_ctl_new1(&snd_at73c213_controls[idx],
14295 + chip));
14296 + if (errval < 0)
14297 + goto cleanup;
14298 + }
14299 +
14300 + return 0;
14301 +
14302 +cleanup:
14303 + for (idx = 1; idx < ARRAY_SIZE(snd_at73c213_controls) + 1; idx++) {
14304 + struct snd_kcontrol *kctl;
14305 + kctl = snd_ctl_find_numid(card, idx);
14306 + if (kctl)
14307 + snd_ctl_remove(card, kctl);
14308 + }
14309 + return errval;
14310 +}
14311 +
14312 +/*
14313 + * Device functions
14314 + */
14315 +static int snd_at73c213_ssc_init(struct snd_at73c213 *chip)
14316 +{
14317 + /*
14318 + * Continuous clock output.
14319 + * Starts on falling TF.
14320 + * Delay 1 cycle (1 bit).
14321 + * Periode is 16 bit (16 - 1).
14322 + */
14323 + ssc_writel(chip->ssc->regs, TCMR,
14324 + SSC_BF(TCMR_CKO, 1)
14325 + | SSC_BF(TCMR_START, 4)
14326 + | SSC_BF(TCMR_STTDLY, 1)
14327 + | SSC_BF(TCMR_PERIOD, 16 - 1));
14328 + /*
14329 + * Data length is 16 bit (16 - 1).
14330 + * Transmit MSB first.
14331 + * Transmit 2 words each transfer.
14332 + * Frame sync length is 16 bit (16 - 1).
14333 + * Frame starts on negative pulse.
14334 + */
14335 + ssc_writel(chip->ssc->regs, TFMR,
14336 + SSC_BF(TFMR_DATLEN, 16 - 1)
14337 + | SSC_BIT(TFMR_MSBF)
14338 + | SSC_BF(TFMR_DATNB, 1)
14339 + | SSC_BF(TFMR_FSLEN, 16 - 1)
14340 + | SSC_BF(TFMR_FSOS, 1));
14341 +
14342 + return 0;
14343 +}
14344 +
14345 +static int snd_at73c213_chip_init(struct snd_at73c213 *chip)
14346 +{
14347 + int retval;
14348 + unsigned char dac_ctrl = 0;
14349 +
14350 + retval = snd_at73c213_set_bitrate(chip);
14351 + if (retval)
14352 + goto out;
14353 +
14354 + /* Enable DAC master clock. */
14355 + clk_enable(chip->board->dac_clk);
14356 +
14357 + /* Initialize at73c213 on SPI bus. */
14358 + retval = snd_at73c213_write_reg(chip, DAC_RST, 0x04);
14359 + if (retval)
14360 + goto out_clk;
14361 + msleep(1);
14362 + retval = snd_at73c213_write_reg(chip, DAC_RST, 0x03);
14363 + if (retval)
14364 + goto out_clk;
14365 +
14366 + /* Precharge everything. */
14367 + retval = snd_at73c213_write_reg(chip, DAC_PRECH, 0xff);
14368 + if (retval)
14369 + goto out_clk;
14370 + retval = snd_at73c213_write_reg(chip, PA_CTRL, (1<<PA_CTRL_APAPRECH));
14371 + if (retval)
14372 + goto out_clk;
14373 + retval = snd_at73c213_write_reg(chip, DAC_CTRL,
14374 + (1<<DAC_CTRL_ONLNOL) | (1<<DAC_CTRL_ONLNOR));
14375 + if (retval)
14376 + goto out_clk;
14377 +
14378 + msleep(50);
14379 +
14380 + /* Stop precharging PA. */
14381 + retval = snd_at73c213_write_reg(chip, PA_CTRL,
14382 + (1<<PA_CTRL_APALP) | 0x0f);
14383 + if (retval)
14384 + goto out_clk;
14385 +
14386 + msleep(450);
14387 +
14388 + /* Stop precharging DAC, turn on master power. */
14389 + retval = snd_at73c213_write_reg(chip, DAC_PRECH, (1<<DAC_PRECH_ONMSTR));
14390 + if (retval)
14391 + goto out_clk;
14392 +
14393 + msleep(1);
14394 +
14395 + /* Turn on DAC. */
14396 + dac_ctrl = (1<<DAC_CTRL_ONDACL) | (1<<DAC_CTRL_ONDACR)
14397 + | (1<<DAC_CTRL_ONLNOL) | (1<<DAC_CTRL_ONLNOR);
14398 +
14399 + retval = snd_at73c213_write_reg(chip, DAC_CTRL, dac_ctrl);
14400 + if (retval)
14401 + goto out_clk;
14402 +
14403 + /* Mute sound. */
14404 + retval = snd_at73c213_write_reg(chip, DAC_LMPG, 0x3f);
14405 + if (retval)
14406 + goto out_clk;
14407 + retval = snd_at73c213_write_reg(chip, DAC_RMPG, 0x3f);
14408 + if (retval)
14409 + goto out_clk;
14410 + retval = snd_at73c213_write_reg(chip, DAC_LLOG, 0x3f);
14411 + if (retval)
14412 + goto out_clk;
14413 + retval = snd_at73c213_write_reg(chip, DAC_RLOG, 0x3f);
14414 + if (retval)
14415 + goto out_clk;
14416 + retval = snd_at73c213_write_reg(chip, DAC_LLIG, 0x11);
14417 + if (retval)
14418 + goto out_clk;
14419 + retval = snd_at73c213_write_reg(chip, DAC_RLIG, 0x11);
14420 + if (retval)
14421 + goto out_clk;
14422 + retval = snd_at73c213_write_reg(chip, DAC_AUXG, 0x11);
14423 + if (retval)
14424 + goto out_clk;
14425 +
14426 + /* Enable I2S device, i.e. clock output. */
14427 + ssc_writel(chip->ssc->regs, CR, SSC_BIT(CR_TXEN));
14428 +
14429 + goto out;
14430 +
14431 +out_clk:
14432 + clk_disable(chip->board->dac_clk);
14433 +out:
14434 + return retval;
14435 +}
14436 +
14437 +static int snd_at73c213_dev_free(struct snd_device *device)
14438 +{
14439 + struct snd_at73c213 *chip = device->device_data;
14440 +
14441 + ssc_writel(chip->ssc->regs, CR, SSC_BIT(CR_TXDIS));
14442 + if (chip->irq >= 0) {
14443 + free_irq(chip->irq, chip);
14444 + chip->irq = -1;
14445 + }
14446 +
14447 + return 0;
14448 +}
14449 +
14450 +static int __devinit snd_at73c213_dev_init(struct snd_card *card,
14451 + struct spi_device *spi)
14452 +{
14453 + static struct snd_device_ops ops = {
14454 + .dev_free = snd_at73c213_dev_free,
14455 + };
14456 + struct snd_at73c213 *chip = get_chip(card);
14457 + int irq, retval;
14458 +
14459 + irq = chip->ssc->irq;
14460 + if (irq < 0)
14461 + return irq;
14462 +
14463 + spin_lock_init(&chip->lock);
14464 + chip->card = card;
14465 + chip->irq = -1;
14466 +
14467 + retval = request_irq(irq, snd_at73c213_interrupt, 0, "at73c213", chip);
14468 + if (retval) {
14469 + dev_dbg(&chip->spi->dev, "unable to request irq %d\n", irq);
14470 + goto out;
14471 + }
14472 + chip->irq = irq;
14473 +
14474 + memcpy(&chip->reg_image, &snd_at73c213_original_image,
14475 + sizeof(snd_at73c213_original_image));
14476 +
14477 + retval = snd_at73c213_ssc_init(chip);
14478 + if (retval)
14479 + goto out_irq;
14480 +
14481 + retval = snd_at73c213_chip_init(chip);
14482 + if (retval)
14483 + goto out_irq;
14484 +
14485 + retval = snd_at73c213_pcm_new(chip, 0);
14486 + if (retval)
14487 + goto out_irq;
14488 +
14489 + retval = snd_device_new(card, SNDRV_DEV_LOWLEVEL, chip, &ops);
14490 + if (retval)
14491 + goto out_irq;
14492 +
14493 + retval = snd_at73c213_mixer(chip);
14494 + if (retval)
14495 + goto out_snd_dev;
14496 +
14497 + snd_card_set_dev(card, &spi->dev);
14498 +
14499 + goto out;
14500 +
14501 +out_snd_dev:
14502 + snd_device_free(card, chip);
14503 +out_irq:
14504 + free_irq(chip->irq, chip);
14505 + chip->irq = -1;
14506 +out:
14507 + return retval;
14508 +}
14509 +
14510 +static int snd_at73c213_probe(struct spi_device *spi)
14511 +{
14512 + struct snd_card *card;
14513 + struct snd_at73c213 *chip;
14514 + struct at73c213_board_info *board;
14515 + int retval;
14516 + char id[16];
14517 +
14518 + board = spi->dev.platform_data;
14519 + if (!board) {
14520 + dev_dbg(&spi->dev, "no platform_data\n");
14521 + return -ENXIO;
14522 + }
14523 +
14524 + if (!board->dac_clk) {
14525 + dev_dbg(&spi->dev, "no DAC clk\n");
14526 + return -ENXIO;
14527 + }
14528 +
14529 + if (IS_ERR(board->dac_clk)) {
14530 + dev_dbg(&spi->dev, "no DAC clk\n");
14531 + return PTR_ERR(board->dac_clk);
14532 + }
14533 +
14534 + retval = -ENOMEM;
14535 +
14536 + /* Allocate "card" using some unused identifiers. */
14537 + snprintf(id, sizeof id, "at73c213_%d", board->ssc_id);
14538 + card = snd_card_new(-1, id, THIS_MODULE, sizeof(struct snd_at73c213));
14539 + if (!card)
14540 + goto out;
14541 +
14542 + chip = card->private_data;
14543 + chip->spi = spi;
14544 + chip->board = board;
14545 +
14546 + chip->ssc = ssc_request(board->ssc_id);
14547 + if (IS_ERR(chip->ssc)) {
14548 + dev_dbg(&spi->dev, "could not get ssc%d device\n",
14549 + board->ssc_id);
14550 + retval = PTR_ERR(chip->ssc);
14551 + goto out_card;
14552 + }
14553 +
14554 + retval = snd_at73c213_dev_init(card, spi);
14555 + if (retval)
14556 + goto out_ssc;
14557 +
14558 + strcpy(card->driver, "at73c213");
14559 + strcpy(card->shortname, board->shortname);
14560 + sprintf(card->longname, "%s on irq %d", card->shortname, chip->irq);
14561 +
14562 + retval = snd_card_register(card);
14563 + if (retval)
14564 + goto out_ssc;
14565 +
14566 + dev_set_drvdata(&spi->dev, card);
14567 +
14568 + goto out;
14569 +
14570 +out_ssc:
14571 + ssc_free(chip->ssc);
14572 +out_card:
14573 + snd_card_free(card);
14574 +out:
14575 + return retval;
14576 +}
14577 +
14578 +static int __devexit snd_at73c213_remove(struct spi_device *spi)
14579 +{
14580 + struct snd_card *card = dev_get_drvdata(&spi->dev);
14581 + struct snd_at73c213 *chip = card->private_data;
14582 + int retval;
14583 +
14584 + /* Stop playback. */
14585 + ssc_writel(chip->ssc->regs, CR, SSC_BIT(CR_TXDIS));
14586 +
14587 + /* Mute sound. */
14588 + retval = snd_at73c213_write_reg(chip, DAC_LMPG, 0x3f);
14589 + if (retval)
14590 + goto out;
14591 + retval = snd_at73c213_write_reg(chip, DAC_RMPG, 0x3f);
14592 + if (retval)
14593 + goto out;
14594 + retval = snd_at73c213_write_reg(chip, DAC_LLOG, 0x3f);
14595 + if (retval)
14596 + goto out;
14597 + retval = snd_at73c213_write_reg(chip, DAC_RLOG, 0x3f);
14598 + if (retval)
14599 + goto out;
14600 + retval = snd_at73c213_write_reg(chip, DAC_LLIG, 0x11);
14601 + if (retval)
14602 + goto out;
14603 + retval = snd_at73c213_write_reg(chip, DAC_RLIG, 0x11);
14604 + if (retval)
14605 + goto out;
14606 + retval = snd_at73c213_write_reg(chip, DAC_AUXG, 0x11);
14607 + if (retval)
14608 + goto out;
14609 +
14610 + /* Turn off PA. */
14611 + retval = snd_at73c213_write_reg(chip, PA_CTRL, (chip->reg_image[PA_CTRL]|0x0f));
14612 + if (retval)
14613 + goto out;
14614 + msleep(10);
14615 + retval = snd_at73c213_write_reg(chip, PA_CTRL, (1<<PA_CTRL_APALP)|0x0f);
14616 + if (retval)
14617 + goto out;
14618 +
14619 + /* Turn off external DAC. */
14620 + retval = snd_at73c213_write_reg(chip, DAC_CTRL, 0x0c);
14621 + if (retval)
14622 + goto out;
14623 + msleep(2);
14624 + retval = snd_at73c213_write_reg(chip, DAC_CTRL, 0x00);
14625 + if (retval)
14626 + goto out;
14627 +
14628 + /* Turn off master power. */
14629 + retval = snd_at73c213_write_reg(chip, DAC_PRECH, 0x00);
14630 + if (retval)
14631 + goto out;
14632 +
14633 +out:
14634 + /* Stop DAC master clock. */
14635 + clk_disable(chip->board->dac_clk);
14636 +
14637 + ssc_free(chip->ssc);
14638 + snd_card_free(card);
14639 + dev_set_drvdata(&spi->dev, NULL);
14640 +
14641 + return 0;
14642 +}
14643 +
14644 +#ifdef CONFIG_PM
14645 +static int snd_at73c213_suspend(struct spi_device *spi, pm_message_t msg)
14646 +{
14647 + struct snd_card *card = dev_get_drvdata(&spi->dev);
14648 + struct snd_at73c213 *chip = card->private_data;
14649 +
14650 + ssc_writel(chip->ssc->regs, CR, SSC_BIT(CR_TXDIS));
14651 + clk_disable(chip->board->dac_clk);
14652 +
14653 + return 0;
14654 +}
14655 +
14656 +static int snd_at73c213_resume(struct spi_device *spi)
14657 +{
14658 + struct snd_card *card = dev_get_drvdata(&spi->dev);
14659 + struct snd_at73c213 *chip = card->private_data;
14660 +
14661 + clk_enable(chip->board->dac_clk);
14662 + ssc_writel(chip->ssc->regs, CR, SSC_BIT(CR_TXEN));
14663 +
14664 + return 0;
14665 +}
14666 +#else
14667 +#define snd_at73c213_suspend NULL
14668 +#define snd_at73c213_resume NULL
14669 +#endif
14670 +
14671 +static struct spi_driver at73c213_driver = {
14672 + .driver = {
14673 + .name = "at73c213",
14674 + },
14675 + .probe = snd_at73c213_probe,
14676 + .suspend = snd_at73c213_suspend,
14677 + .resume = snd_at73c213_resume,
14678 + .remove = __devexit_p(snd_at73c213_remove),
14679 +};
14680 +
14681 +static int __init at73c213_init(void)
14682 +{
14683 + return spi_register_driver(&at73c213_driver);
14684 +}
14685 +module_init(at73c213_init);
14686 +
14687 +static void __exit at73c213_exit(void)
14688 +{
14689 + spi_unregister_driver(&at73c213_driver);
14690 +}
14691 +module_exit(at73c213_exit);
14692 +
14693 +MODULE_AUTHOR("Hans-Christian Egtvedt <hcegtvedt@atmel.com>");
14694 +MODULE_DESCRIPTION("Sound driver for AT73C213 with Atmel SSC");
14695 +MODULE_LICENSE("GPL");
14696 diff --git a/sound/spi/at73c213.h b/sound/spi/at73c213.h
14697 new file mode 100644
14698 index 0000000..fd8b372
14699 --- /dev/null
14700 +++ b/sound/spi/at73c213.h
14701 @@ -0,0 +1,119 @@
14702 +/*
14703 + * Driver for the AT73C213 16-bit stereo DAC on Atmel ATSTK1000
14704 + *
14705 + * Copyright (C) 2006 - 2007 Atmel Corporation
14706 + *
14707 + * This program is free software; you can redistribute it and/or
14708 + * modify it under the terms of the GNU General Public License as
14709 + * published by the Free Software Foundation; either version 2 of the
14710 + * License, or (at your option) any later version.
14711 + *
14712 + * This program is distributed in the hope that it will be useful, but
14713 + * WITHOUT ANY WARRANTY; without even the implied warranty of
14714 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14715 + * General Public License for more details.
14716 + *
14717 + * You should have received a copy of the GNU General Public License
14718 + * along with this program; if not, write to the Free Software
14719 + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
14720 + * 02111-1307, USA.
14721 + *
14722 + * The full GNU General Public License is included in this
14723 + * distribution in the file called COPYING.
14724 + */
14725 +
14726 +#ifndef _SND_AT73C213_H
14727 +#define _SND_AT73C213_H
14728 +
14729 +/* DAC control register */
14730 +#define DAC_CTRL 0x00
14731 +#define DAC_CTRL_ONPADRV 7
14732 +#define DAC_CTRL_ONAUXIN 6
14733 +#define DAC_CTRL_ONDACR 5
14734 +#define DAC_CTRL_ONDACL 4
14735 +#define DAC_CTRL_ONLNOR 3
14736 +#define DAC_CTRL_ONLNOL 2
14737 +#define DAC_CTRL_ONLNIR 1
14738 +#define DAC_CTRL_ONLNIL 0
14739 +
14740 +/* DAC left line in gain register */
14741 +#define DAC_LLIG 0x01
14742 +#define DAC_LLIG_LLIG 0
14743 +
14744 +/* DAC right line in gain register */
14745 +#define DAC_RLIG 0x02
14746 +#define DAC_RLIG_RLIG 0
14747 +
14748 +/* DAC Left Master Playback Gain Register */
14749 +#define DAC_LMPG 0x03
14750 +#define DAC_LMPG_LMPG 0
14751 +
14752 +/* DAC Right Master Playback Gain Register */
14753 +#define DAC_RMPG 0x04
14754 +#define DAC_RMPG_RMPG 0
14755 +
14756 +/* DAC Left Line Out Gain Register */
14757 +#define DAC_LLOG 0x05
14758 +#define DAC_LLOG_LLOG 0
14759 +
14760 +/* DAC Right Line Out Gain Register */
14761 +#define DAC_RLOG 0x06
14762 +#define DAC_RLOG_RLOG 0
14763 +
14764 +/* DAC Output Level Control Register */
14765 +#define DAC_OLC 0x07
14766 +#define DAC_OLC_RSHORT 7
14767 +#define DAC_OLC_ROLC 4
14768 +#define DAC_OLC_LSHORT 3
14769 +#define DAC_OLC_LOLC 0
14770 +
14771 +/* DAC Mixer Control Register */
14772 +#define DAC_MC 0x08
14773 +#define DAC_MC_INVR 5
14774 +#define DAC_MC_INVL 4
14775 +#define DAC_MC_RMSMIN2 3
14776 +#define DAC_MC_RMSMIN1 2
14777 +#define DAC_MC_LMSMIN2 1
14778 +#define DAC_MC_LMSMIN1 0
14779 +
14780 +/* DAC Clock and Sampling Frequency Control Register */
14781 +#define DAC_CSFC 0x09
14782 +#define DAC_CSFC_OVRSEL 4
14783 +
14784 +/* DAC Miscellaneous Register */
14785 +#define DAC_MISC 0x0A
14786 +#define DAC_MISC_VCMCAPSEL 7
14787 +#define DAC_MISC_DINTSEL 4
14788 +#define DAC_MISC_DITHEN 3
14789 +#define DAC_MISC_DEEMPEN 2
14790 +#define DAC_MISC_NBITS 0
14791 +
14792 +/* DAC Precharge Control Register */
14793 +#define DAC_PRECH 0x0C
14794 +#define DAC_PRECH_PRCHGPDRV 7
14795 +#define DAC_PRECH_PRCHGAUX1 6
14796 +#define DAC_PRECH_PRCHGLNOR 5
14797 +#define DAC_PRECH_PRCHGLNOL 4
14798 +#define DAC_PRECH_PRCHGLNIR 3
14799 +#define DAC_PRECH_PRCHGLNIL 2
14800 +#define DAC_PRECH_PRCHG 1
14801 +#define DAC_PRECH_ONMSTR 0
14802 +
14803 +/* DAC Auxiliary Input Gain Control Register */
14804 +#define DAC_AUXG 0x0D
14805 +#define DAC_AUXG_AUXG 0
14806 +
14807 +/* DAC Reset Register */
14808 +#define DAC_RST 0x10
14809 +#define DAC_RST_RESMASK 2
14810 +#define DAC_RST_RESFILZ 1
14811 +#define DAC_RST_RSTZ 0
14812 +
14813 +/* Power Amplifier Control Register */
14814 +#define PA_CTRL 0x11
14815 +#define PA_CTRL_APAON 6
14816 +#define PA_CTRL_APAPRECH 5
14817 +#define PA_CTRL_APALP 4
14818 +#define PA_CTRL_APAGAIN 0
14819 +
14820 +#endif /* _SND_AT73C213_H */