1 diff --git a/MAINTAINERS b/MAINTAINERS
2 index df40a4e..3c5cfef 100644
5 @@ -674,6 +674,13 @@ P: Haavard Skinnemoen
6 M: hskinnemoen@atmel.com
10 +P: Haavard Skinnemoen
11 +M: hskinnemoen@atmel.com
12 +L: kernel@avr32linux.org
13 +W: http://avr32linux.org/twiki/bin/view/Main/AtmelUsbDeviceDriver
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"
28 +source "arch/avr32/boards/atstk1000/Kconfig"
31 +source "arch/avr32/boards/atngw100/Kconfig"
35 prompt "Boot loader type"
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.
42 + tristate "Synopsys DesignWare DMA Controller support"
43 + default y if CPU_AT32AP7000
45 # FPU emulation goes here
47 source "kernel/Kconfig.hz"
48 @@ -185,6 +196,27 @@ config CMDLINE
52 +menu "Power managment options"
54 +menu "CPU Frequency scaling"
56 +source "drivers/cpufreq/Kconfig"
58 +config CPU_FREQ_AT32AP
59 + bool "CPU frequency driver for AT32AP"
60 + depends on CPU_FREQ && PLATFORM_AT32AP
63 + This enables the CPU frequency driver for AT32AP processors.
65 + For details, take a look in <file:Documentation/cpu-freq>.
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/
87 archincdir-$(CONFIG_PLATFORM_AT32AP) := arch-at32ap
88 diff --git a/arch/avr32/boards/atngw100/Kconfig b/arch/avr32/boards/atngw100/Kconfig
90 index 0000000..5d922df
92 +++ b/arch/avr32/boards/atngw100/Kconfig
94 +# NGW100 customization
96 +config BOARD_ATNGW100_I2C_GPIO
97 + bool "Use GPIO for i2c instead of built-in TWI module"
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.
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
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>
124 #include <asm/arch/at32ap7000.h>
125 #include <asm/arch/board.h>
126 #include <asm/arch/init.h>
127 +#include <asm/arch/portmux.h>
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 = {
135 +static struct mci_platform_data __initdata mci0_data = {
136 + .detect_pin = GPIO_PIN_PC(25),
137 + .wp_pin = GPIO_PIN_PE(0),
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);
147 +static const struct gpio_led ngw_leds[] = {
148 + { .name = "sys", .gpio = GPIO_PIN_PA(16), .active_low = 1,
149 + .default_trigger = "heartbeat",
151 + { .name = "a", .gpio = GPIO_PIN_PA(19), .active_low = 1, },
152 + { .name = "b", .gpio = GPIO_PIN_PE(19), .active_low = 1, },
155 +static const struct gpio_led_platform_data ngw_led_data = {
156 + .num_leds = ARRAY_SIZE(ngw_leds),
157 + .leds = (void *) ngw_leds,
160 +static struct platform_device ngw_gpio_leds = {
161 + .name = "leds-gpio",
164 + .platform_data = (void *) &ngw_led_data,
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),
174 +static struct platform_device i2c_gpio_device = {
175 + .name = "i2c-gpio",
178 + .platform_data = &i2c_gpio_data,
183 static int __init atngw100_init(void)
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, ð_data[1]));
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);
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);
201 + platform_device_register(&ngw_gpio_leds);
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);
208 + at32_add_device_twi(0);
213 diff --git a/arch/avr32/boards/atstk1000/Kconfig b/arch/avr32/boards/atstk1000/Kconfig
215 index 0000000..718578f
217 +++ b/arch/avr32/boards/atstk1000/Kconfig
219 +# STK1000 customization
223 +config BOARD_ATSTK1002_CUSTOM
224 + bool "Non-default STK-1002 jumper settings"
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.
230 +if BOARD_ATSTK1002_CUSTOM
232 +config BOARD_ATSTK1002_SW1_CUSTOM
233 + bool "SW1: use SSC1 (not SPI0)"
235 + This also prevents using the external DAC as an audio interface,
236 + and means you can't initialize the on-board QVGA display.
238 +config BOARD_ATSTK1002_SW2_CUSTOM
239 + bool "SW2: use IRDA or TIMER0 (not UART-A, MMC/SD, and PS2-A)"
241 + If you change this you'll want an updated boot loader putting
242 + the console on UART-C not UART-A.
244 +config BOARD_ATSTK1002_SW3_CUSTOM
245 + bool "SW3: use TIMER1 (not SSC0 and GCLK)"
247 + This also prevents using the external DAC as an audio interface.
249 +config BOARD_ATSTK1002_SW4_CUSTOM
250 + bool "SW4: use ISI/Camera (not GPIOs, SPI1, and PS2-B)"
252 + To use the camera interface you'll need a custom card (on the
253 + PCI-format connector) connect a video sensor.
255 +config BOARD_ATSTK1002_SW5_CUSTOM
256 + bool "SW5: use MACB1 (not LCDC)"
258 +config BOARD_ATSTK1002_SW6_CUSTOM
259 + bool "SW6: more GPIOs (not MACB0)"
263 +config BOARD_ATSTK1002_SPI1
264 + bool "Configure SPI1 controller"
265 + depends on !BOARD_ATSTK1002_SW4_CUSTOM
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.
271 +config BOARD_ATSTK1002_J2_LED
273 + default BOARD_ATSTK1002_J2_LED8 || BOARD_ATSTK1002_J2_RGB
276 + prompt "LEDs connected to J2:"
277 + depends on LEDS_GPIO && !BOARD_ATSTK1002_SW4_CUSTOM
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.
285 +config BOARD_ATSTK1002_J2_LED8
288 + Select this if J2 is jumpered to LED0..LED7 amber leds.
290 +config BOARD_ATSTK1002_J2_RGB
293 + Select this if J2 is jumpered to the RGB leds.
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
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>
313 #include <video/atmel_lcdc.h>
317 #include "atstk1000.h"
319 -#define SW2_DEFAULT /* MMCI and UART_A available */
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] = {
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.
334 + .phy_mask = ~(1U << 16),
337 + .phy_mask = ~(1U << 17),
341 +#ifndef CONFIG_BOARD_ATSTK1002_SW1_CUSTOM
342 +#ifndef CONFIG_BOARD_ATSTK1002_SW3_CUSTOM
343 +static struct at73c213_board_info at73c213_data = {
345 + .shortname = "AVR32 STK1000 external DAC",
350 +#ifndef CONFIG_BOARD_ATSTK1002_SW1_CUSTOM
351 static struct spi_board_info spi0_board_info[] __initdata = {
352 +#ifndef CONFIG_BOARD_ATSTK1002_SW3_CUSTOM
355 + .modalias = "at73c213",
356 + .max_speed_hz = 200000,
358 + .mode = SPI_MODE_1,
359 + .platform_data = &at73c213_data,
364 .modalias = "ltv350qv",
365 @@ -45,6 +78,18 @@ static struct spi_board_info spi0_board_info[] __initdata = {
371 +#ifdef CONFIG_BOARD_ATSTK1002_SPI1
372 +static struct spi_board_info spi1_board_info[] __initdata = { {
373 + /* patch in custom entries here */
377 +static struct mci_platform_data __initdata mci0_data = {
378 + .detect_pin = GPIO_PIN_NONE,
379 + .wp_pin = GPIO_PIN_NONE,
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)
388 -void __init setup_board(void)
389 +#ifdef CONFIG_BOARD_ATSTK1002_J2_LED
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", },
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), },
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 */
418 +static struct gpio_led_platform_data stk_j2_led_data = {
419 + .num_leds = ARRAY_SIZE(stk_j2_led),
420 + .leds = stk_j2_led,
423 +static struct platform_device stk_j2_led_dev = {
424 + .name = "leds-gpio",
425 + .id = 2, /* gpio block J2 */
427 + .platform_data = &stk_j2_led_data,
431 +static void setup_j2_leds(void)
434 - at32_map_usart(1, 0); /* USART 1/A: /dev/ttyS0, DB9 */
437 + for (i = 0; i < ARRAY_SIZE(stk_j2_led); i++)
438 + at32_select_gpio(stk_j2_led[i].gpio, AT32_GPIOF_OUTPUT);
440 + printk("STK1002: " LEDSTRING "\n");
441 + platform_device_register(&stk_j2_led_dev);
445 +static void setup_j2_leds(void)
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)
457 + gclk = clk_get(NULL, "gclk0");
460 + pll = clk_get(NULL, "pll0");
464 + if (clk_set_parent(gclk, pll)) {
465 + pr_debug("STK1000: failed to set pll0 as parent for DAC clock\n");
469 + at32_select_periph(GPIO_PIN_PA(30), GPIO_PERIPH_A, 0);
470 + info->dac_clk = gclk;
482 +void __init setup_board(void)
484 +#ifdef CONFIG_BOARD_ATSTK1002_SW2_CUSTOM
485 at32_map_usart(0, 1); /* USART 0/B: /dev/ttyS1, IRDA */
487 + at32_map_usart(1, 0); /* USART 1/A: /dev/ttyS0, DB9 */
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)
493 at32_add_system_devices();
496 - at32_add_device_usart(0);
498 +#ifdef CONFIG_BOARD_ATSTK1002_SW2_CUSTOM
499 at32_add_device_usart(1);
501 + at32_add_device_usart(0);
503 at32_add_device_usart(2);
505 +#ifndef CONFIG_BOARD_ATSTK1002_SW6_CUSTOM
506 set_hw_addr(at32_add_device_eth(0, ð_data[0]));
508 - at32_add_device_spi(0, spi0_board_info, ARRAY_SIZE(spi0_board_info));
510 +#ifdef CONFIG_BOARD_ATSTK1002_SW5_CUSTOM
511 + set_hw_addr(at32_add_device_eth(1, ð_data[1]));
513 at32_add_device_lcdc(0, &atstk1000_lcdc_data,
514 fbmem_start, fbmem_size);
517 +#ifndef CONFIG_BOARD_ATSTK1002_SW1_CUSTOM
518 + at32_add_device_spi(0, spi0_board_info, ARRAY_SIZE(spi0_board_info));
520 +#ifdef CONFIG_BOARD_ATSTK1002_SPI1
521 + at32_add_device_spi(1, spi1_board_info, ARRAY_SIZE(spi1_board_info));
523 + at32_add_device_twi(0);
524 +#ifndef CONFIG_BOARD_ATSTK1002_SW2_CUSTOM
525 + at32_add_device_mci(0, &mci0_data);
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);
535 +#ifndef CONFIG_BOARD_ATSTK1002_SW3_CUSTOM
536 +#ifndef CONFIG_BOARD_ATSTK1002_SW1_CUSTOM
537 + at73c213_set_clk(&at73c213_data);
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
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
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
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
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
578 # CONFIG_HZ_100 is not set
580 # CONFIG_HZ_300 is not set
581 @@ -153,6 +156,27 @@ CONFIG_HZ=250
585 +# Power managment options
589 +# CPU Frequency scaling
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
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
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
618 -# CONFIG_IP_MULTIPLE_TABLES is not set
619 -# CONFIG_IP_ROUTE_MULTIPATH is not set
620 -# CONFIG_IP_ROUTE_VERBOSE is not set
623 # CONFIG_IP_PNP_BOOTP is not set
624 @@ -240,6 +259,7 @@ CONFIG_IPV6_SIT=y
625 # CONFIG_NETWORK_SECMARK is not set
627 # CONFIG_NETFILTER_DEBUG is not set
628 +CONFIG_BRIDGE_NETFILTER=y
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
646 +# Bridge: Netfilter Configuration
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
656 # CONFIG_DECNET is not set
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
665 -# CONFIG_BLINK is not set
666 # CONFIG_IDE is not set
669 @@ -545,13 +571,26 @@ CONFIG_NETDEVICES=y
670 # CONFIG_BONDING is not set
671 # CONFIG_EQUALIZER is not set
673 -# CONFIG_PHYLIB is not set
677 +# MII PHY device drivers
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
690 # Ethernet (10 or 100Mbit)
692 CONFIG_NET_ETHERNET=y
694 +# CONFIG_MII is not set
696 # CONFIG_NETDEV_1000 is not set
697 # CONFIG_NETDEV_10000 is not set
698 @@ -625,7 +664,15 @@ CONFIG_UNIX98_PTYS=y
701 # CONFIG_IPMI_HANDLER is not set
702 -# CONFIG_WATCHDOG is not set
704 +# CONFIG_WATCHDOG_NOWAYOUT is not set
707 +# Watchdog Device Drivers
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
718 # CONFIG_TCG_TPM is not set
719 -# CONFIG_I2C is not set
721 +CONFIG_I2C_BOARDINFO=y
722 +CONFIG_I2C_CHARDEV=m
727 +CONFIG_I2C_ALGOBIT=m
728 +# CONFIG_I2C_ALGOPCF is not set
729 +# CONFIG_I2C_ALGOPCA is not set
732 +# I2C Hardware Bus support
734 +CONFIG_I2C_ATMELTWI=m
735 +CONFIG_I2C_ATMELTWI_BAUDRATE=100000
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
743 +# Miscellaneous I2C Chip support
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
759 @@ -655,7 +737,7 @@ CONFIG_SPI_ATMEL=y
760 # SPI Protocol Masters
762 # CONFIG_SPI_AT25 is not set
763 -# CONFIG_SPI_SPIDEV is not set
767 # Dallas's 1-wire bus
768 @@ -706,21 +788,59 @@ CONFIG_SPI_ATMEL=y
772 -# CONFIG_USB_GADGET is not set
773 -# CONFIG_MMC is not set
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
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
797 +# CONFIG_MMC_DEBUG is not set
798 +# CONFIG_MMC_UNSAFE_RESUME is not set
801 +# MMC/SD Card Drivers
806 +# MMC/SD Host Controller Drivers
808 +CONFIG_MMC_ATMELMCI=y
813 -# CONFIG_NEW_LEDS is not set
825 +CONFIG_LEDS_TRIGGERS=y
826 +CONFIG_LEDS_TRIGGER_TIMER=y
827 +CONFIG_LEDS_TRIGGER_HEARTBEAT=y
831 @@ -733,7 +853,51 @@ CONFIG_SPI_ATMEL=y
835 -# CONFIG_RTC_CLASS is not set
838 +CONFIG_RTC_HCTOSYS=y
839 +CONFIG_RTC_HCTOSYS_DEVICE="rtc0"
840 +# CONFIG_RTC_DEBUG is not set
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
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
866 +# CONFIG_RTC_DRV_RS5C348 is not set
867 +# CONFIG_RTC_DRV_MAX6902 is not set
870 +# Platform RTC drivers
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
878 +# on-CPU RTC drivers
880 +CONFIG_RTC_DRV_AT32AP700X=y
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
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
897 # CONFIG_UNUSED_SYMBOLS is not set
898 -# CONFIG_DEBUG_FS is not set
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
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
916 CONFIG_GENERIC_GPIO=y
917 @@ -80,10 +80,10 @@ CONFIG_BASE_SMALL=1
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
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"
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
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
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
972 # CONFIG_HZ_100 is not set
974 # CONFIG_HZ_300 is not set
975 @@ -156,6 +163,27 @@ CONFIG_HZ=250
979 +# Power managment options
983 +# CPU Frequency scaling
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
1002 # CONFIG_ARCH_SUPPORTS_MSI is not set
1003 @@ -327,6 +355,8 @@ CONFIG_MTD_PHYSMAP_BANKWIDTH=2
1005 # Self-contained MTD device drivers
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
1016 -# CONFIG_BLINK is not set
1018 # CONFIG_IDE is not set
1021 @@ -397,13 +427,26 @@ CONFIG_DUMMY=y
1022 # CONFIG_BONDING is not set
1023 # CONFIG_EQUALIZER is not set
1025 -# CONFIG_PHYLIB is not set
1029 +# MII PHY device drivers
1031 +# CONFIG_MARVELL_PHY is not set
1032 +# CONFIG_DAVICOM_PHY is not set
1033 +# CONFIG_QSEMI_PHY is not set
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
1042 # Ethernet (10 or 100Mbit)
1044 CONFIG_NET_ETHERNET=y
1046 +# CONFIG_MII is not set
1048 # CONFIG_NETDEV_1000 is not set
1049 # CONFIG_NETDEV_10000 is not set
1050 @@ -443,7 +486,42 @@ CONFIG_SLHC=m
1052 # Input device support
1054 -# CONFIG_INPUT is not set
1056 +# CONFIG_INPUT_FF_MEMLESS is not set
1057 +CONFIG_INPUT_POLLDEV=m
1060 +# Userland interfaces
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
1072 +# Input Device Drivers
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
1093 # Hardware I/O ports
1094 @@ -477,7 +555,15 @@ CONFIG_UNIX98_PTYS=y
1097 # CONFIG_IPMI_HANDLER is not set
1098 -# CONFIG_WATCHDOG is not set
1100 +# CONFIG_WATCHDOG_NOWAYOUT is not set
1103 +# Watchdog Device Drivers
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
1114 # CONFIG_TCG_TPM is not set
1115 -# CONFIG_I2C is not set
1117 +CONFIG_I2C_BOARDINFO=y
1118 +CONFIG_I2C_CHARDEV=m
1123 +CONFIG_I2C_ALGOBIT=m
1124 +# CONFIG_I2C_ALGOPCF is not set
1125 +# CONFIG_I2C_ALGOPCA is not set
1128 +# I2C Hardware Bus support
1130 +CONFIG_I2C_ATMELTWI=m
1131 +CONFIG_I2C_ATMELTWI_BAUDRATE=100000
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
1139 +# Miscellaneous I2C Chip support
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
1156 -# CONFIG_SPI is not set
1157 -# CONFIG_SPI_MASTER is not set
1159 +# CONFIG_SPI_DEBUG is not set
1160 +CONFIG_SPI_MASTER=y
1163 +# SPI Master Controller Drivers
1166 +# CONFIG_SPI_BITBANG is not set
1169 +# SPI Protocol Masters
1171 +# CONFIG_SPI_AT25 is not set
1172 +CONFIG_SPI_SPIDEV=m
1175 # Dallas's 1-wire bus
1176 @@ -517,19 +651,91 @@ CONFIG_UNIX98_PTYS=y
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
1187 # Display device support
1189 # CONFIG_DISPLAY_SUPPORT is not set
1190 # CONFIG_VGASTATE is not set
1191 -# CONFIG_FB is not set
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
1210 +# Frame buffer hardware drivers
1212 +# CONFIG_FB_S1D13XXX is not set
1214 +# CONFIG_FB_VIRTUAL is not set
1215 +# CONFIG_LOGO is not set
1220 -# CONFIG_SOUND is not set
1224 +# Advanced Linux Sound Architecture
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
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
1251 +CONFIG_SND_AT73C213=m
1252 +CONFIG_SND_AT73C213_TARGET_BITRATE=48000
1255 +# System on Chip audio support
1257 +# CONFIG_SND_SOC is not set
1260 +# Open Sound System
1262 +# CONFIG_SOUND_PRIME is not set
1267 +# CONFIG_HID is not set
1271 @@ -545,21 +751,59 @@ CONFIG_UNIX98_PTYS=y
1273 # USB Gadget Support
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
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
1300 +# CONFIG_MMC_DEBUG is not set
1301 +# CONFIG_MMC_UNSAFE_RESUME is not set
1304 +# MMC/SD Card Drivers
1309 +# MMC/SD Host Controller Drivers
1311 +CONFIG_MMC_ATMELMCI=y
1316 -# CONFIG_NEW_LEDS is not set
1318 +CONFIG_LEDS_CLASS=m
1328 +CONFIG_LEDS_TRIGGERS=y
1329 +CONFIG_LEDS_TRIGGER_TIMER=m
1330 +CONFIG_LEDS_TRIGGER_HEARTBEAT=m
1333 # InfiniBand support
1334 @@ -572,7 +816,50 @@ CONFIG_UNIX98_PTYS=y
1338 -# CONFIG_RTC_CLASS is not set
1341 +# CONFIG_RTC_HCTOSYS is not set
1342 +# CONFIG_RTC_DEBUG is not set
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
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
1368 +# CONFIG_RTC_DRV_RS5C348 is not set
1369 +# CONFIG_RTC_DRV_MAX6902 is not set
1372 +# Platform RTC drivers
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
1380 +# on-CPU RTC drivers
1382 +CONFIG_RTC_DRV_AT32AP700X=y
1385 # DMA Engine support
1386 @@ -590,11 +877,14 @@ CONFIG_UNIX98_PTYS=y
1392 # CONFIG_EXT2_FS_XATTR is not set
1393 # CONFIG_EXT2_FS_XIP is not set
1394 -# CONFIG_EXT3_FS is not set
1396 +# CONFIG_EXT3_FS_XATTR is not set
1397 # CONFIG_EXT4DEV_FS is not set
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
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
1416 -CONFIG_CONFIGFS_FS=m
1417 +CONFIG_CONFIGFS_FS=y
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
1428 +# CONFIG_SMB_NLS_DEFAULT is not set
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
1442 +++ b/arch/avr32/drivers/Makefile
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
1449 +++ b/arch/avr32/drivers/dw-dmac.c
1452 + * Driver for the Synopsys DesignWare DMA Controller
1454 + * Copyright (C) 2005-2006 Atmel Corporation
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.
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>
1469 +#include <asm/dma-controller.h>
1470 +#include <asm/io.h>
1472 +#include "dw-dmac.h"
1474 +#define DMAC_NR_CHANNELS 3
1475 +#define DMAC_MAX_BLOCKSIZE 4095
1478 + CH_STATE_FREE = 0,
1479 + CH_STATE_ALLOCATED,
1483 +struct dw_dma_lli {
1493 +struct dw_dma_block {
1494 + struct dw_dma_lli *lli_vaddr;
1495 + dma_addr_t lli_dma_addr;
1498 +struct dw_dma_channel {
1499 + unsigned int state;
1501 + struct dma_request_sg *req_sg;
1502 + struct dma_request_cyclic *req_cyclic;
1503 + unsigned int nr_blocks;
1505 + struct dw_dma_block *block;
1508 +struct dw_dma_controller {
1510 + void * __iomem regs;
1511 + struct dma_pool *lli_pool;
1513 + struct dma_controller dma;
1514 + struct dw_dma_channel channel[DMAC_NR_CHANNELS];
1516 +#define to_dw_dmac(dmac) container_of(dmac, struct dw_dma_controller, dma)
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)))
1540 +static int dmac_alloc_channel(struct dma_controller *_dmac)
1542 + struct dw_dma_controller *dmac = to_dw_dmac(_dmac);
1543 + struct dw_dma_channel *chan;
1544 + unsigned long flags;
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)
1552 + if (i < DMAC_NR_CHANNELS) {
1553 + chan = &dmac->channel[i];
1554 + chan->state = CH_STATE_ALLOCATED;
1559 + spin_unlock_irqrestore(&dmac->lock, flags);
1564 +static void dmac_release_channel(struct dma_controller *_dmac, int channel)
1566 + struct dw_dma_controller *dmac = to_dw_dmac(_dmac);
1568 + BUG_ON(channel >= DMAC_NR_CHANNELS
1569 + || dmac->channel[channel].state != CH_STATE_ALLOCATED);
1571 + dmac->channel[channel].state = CH_STATE_FREE;
1574 +static struct dw_dma_block *allocate_blocks(struct dw_dma_controller *dmac,
1575 + unsigned int nr_blocks)
1577 + struct dw_dma_block *block;
1581 + block = kmalloc(nr_blocks * sizeof(*block),
1583 + if (unlikely(!block))
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;
1597 + for (i = 0; i < nr_blocks; i++) {
1598 + if (!block[i].lli_vaddr)
1600 + dma_pool_free(dmac->lli_pool, block[i].lli_vaddr,
1601 + block[i].lli_dma_addr);
1607 +static void cleanup_channel(struct dw_dma_controller *dmac,
1608 + struct dw_dma_channel *chan)
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);
1619 + chan->state = CH_STATE_ALLOCATED;
1622 +static int dmac_prepare_request_sg(struct dma_controller *_dmac,
1623 + struct dma_request_sg *req)
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;
1633 + spin_lock_irqsave(&dmac->lock, flags);
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);
1643 + chan = &dmac->channel[req->req.channel];
1644 + chan->state = CH_STATE_BUSY;
1645 + chan->req_sg = req;
1646 + chan->is_cyclic = 0;
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
1653 + spin_unlock_irqrestore(&dmac->lock, flags);
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.
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
1666 + * Each block will get its own Linked List Item (LLI) below.
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);
1673 + BUG_ON(nr_blocks == 0);
1674 + chan->nr_blocks = nr_blocks;
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);
1684 + case DMA_DIR_PERIPH_TO_MEM:
1685 + direction = DMA_FROM_DEVICE;
1686 + cfghi = req->periph_id << (39 - 32);
1689 + goto out_unclaim_channel;
1692 + chan->direction = direction;
1694 + dmac_chan_writel_hi(dmac, req->req.channel, CFG, cfghi);
1695 + dmac_chan_writel_lo(dmac, req->req.channel, CFG, cfglo);
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
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,
1710 + ctllo |= 2 << 7; // no dst increment
1712 + dmac_chan_writel_lo(dmac, req->req.channel, SAR,
1714 + dmac_chan_writel_lo(dmac, req->req.channel, DAR,
1715 + req->sg->dma_address);
1716 + ctllo |= 2 << 9; // no src increment
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);
1722 + struct dw_dma_lli *lli, *lli_prev = NULL;
1723 + int j = 0, offset = 0;
1726 + chan->block = allocate_blocks(dmac, nr_blocks);
1728 + goto out_unclaim_channel;
1730 + if (direction == DMA_TO_DEVICE)
1731 + ctllo |= 1 << 28 | 1 << 27 | 2 << 7;
1733 + ctllo |= 1 << 28 | 1 << 27 | 2 << 9;
1736 + * Map scatterlist items to blocks. One scatterlist
1737 + * item may need more than one block for the reasons
1738 + * mentioned above.
1740 + for (i = 0; i < nr_blocks; i++) {
1741 + lli = chan->block[i].lli_vaddr;
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);
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;
1757 + lli->sar = req->data_reg;
1758 + lli->dar = req->sg[j].dma_address + offset;
1762 + offset += block_size;
1763 + if (offset > req->sg[j].length) {
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);
1776 + * SAR, DAR and CTL are initialized from the LLI. We
1777 + * only have to enable the LLI bits in CTL.
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);
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);
1790 + clear_channel_bit(dmac, MASK_BLOCK, req->req.channel);
1794 +out_unclaim_channel:
1795 + chan->state = CH_STATE_ALLOCATED;
1799 +static int dmac_prepare_request_cyclic(struct dma_controller *_dmac,
1800 + struct dma_request_cyclic *req)
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;
1809 + spin_lock_irqsave(&dmac->lock, flags);
1811 + block_size = (req->buffer_size/req->periods) >> req->width;
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);
1822 + chan = &dmac->channel[req->req.channel];
1823 + chan->state = CH_STATE_BUSY;
1824 + chan->is_cyclic = 1;
1825 + chan->req_cyclic = req;
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
1832 + spin_unlock_irqrestore(&dmac->lock, flags);
1837 + BUG_ON(req->buffer_size % req->periods);
1838 + /* printk(KERN_INFO "block_size = %lu, periods = %u\n", block_size, req->periods); */
1840 + chan->nr_blocks = req->periods;
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);
1850 + case DMA_DIR_PERIPH_TO_MEM:
1851 + direction = DMA_FROM_DEVICE;
1852 + cfghi = req->periph_id << (39 - 32);
1855 + goto out_unclaim_channel;
1858 + chan->direction = direction;
1860 + dmac_chan_writel_hi(dmac, req->req.channel, CFG, cfghi);
1861 + dmac_chan_writel_lo(dmac, req->req.channel, CFG, cfglo);
1863 + ctlhi = block_size;
1864 + ctllo = ((req->direction << 20)
1865 + | (req->width << 4) | (req->width << 1)
1866 + | (1 << 0)); // interrupt enable
1869 + struct dw_dma_lli *lli = NULL, *lli_prev = NULL;
1872 + chan->block = allocate_blocks(dmac, req->periods);
1874 + goto out_unclaim_channel;
1876 + if (direction == DMA_TO_DEVICE)
1877 + ctllo |= 1 << 28 | 1 << 27 | 2 << 7;
1879 + ctllo |= 1 << 28 | 1 << 27 | 2 << 9;
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
1887 + for (i = 0; i < req->periods; i++) {
1888 + lli = chan->block[i].lli_vaddr;
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);*/
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;
1904 + lli->sar = req->data_reg;
1905 + lli->dar = req->buffer_start + i*(block_size << req->width);
1909 + lli->llp = chan->block[0].lli_dma_addr;
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); */
1918 + * SAR, DAR and CTL are initialized from the LLI. We
1919 + * only have to enable the LLI bits in CTL.
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);
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);
1931 + clear_channel_bit(dmac, MASK_BLOCK, req->req.channel);
1935 +out_unclaim_channel:
1936 + chan->state = CH_STATE_ALLOCATED;
1940 +static int dmac_start_request(struct dma_controller *_dmac,
1941 + unsigned int channel)
1943 + struct dw_dma_controller *dmac = to_dw_dmac(_dmac);
1945 + BUG_ON(channel >= DMAC_NR_CHANNELS);
1947 + set_channel_bit(dmac, CH_EN, channel);
1952 +static dma_addr_t dmac_get_current_pos(struct dma_controller *_dmac,
1953 + unsigned int channel)
1955 + struct dw_dma_controller *dmac = to_dw_dmac(_dmac);
1956 + struct dw_dma_channel *chan;
1957 + dma_addr_t current_pos;
1959 + BUG_ON(channel >= DMAC_NR_CHANNELS);
1961 + chan = &dmac->channel[channel];
1963 + switch (chan->direction) {
1964 + case DMA_TO_DEVICE:
1965 + current_pos = dmac_chan_readl_lo(dmac, channel, SAR);
1967 + case DMA_FROM_DEVICE:
1968 + current_pos = dmac_chan_readl_lo(dmac, channel, DAR);
1975 + if (!current_pos) {
1976 + if (chan->is_cyclic) {
1977 + current_pos = chan->req_cyclic->buffer_start;
1979 + current_pos = chan->req_sg->sg->dma_address;
1983 + return current_pos;
1987 +static int dmac_stop_request(struct dma_controller *_dmac,
1988 + unsigned int channel)
1990 + struct dw_dma_controller *dmac = to_dw_dmac(_dmac);
1991 + struct dw_dma_channel *chan;
1993 + BUG_ON(channel >= DMAC_NR_CHANNELS);
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));
2003 + if (chan->state == CH_STATE_BUSY) {
2004 + clear_channel_bit(dmac, CH_EN, channel);
2005 + cleanup_channel(dmac, &dmac->channel[channel]);
2012 +static void dmac_block_complete(struct dw_dma_controller *dmac)
2014 + struct dw_dma_channel *chan;
2015 + unsigned long status, chanid;
2017 + status = dmac_readl_lo(dmac, STATUS_BLOCK);
2020 + struct dma_request *req;
2021 + chanid = __ffs(status);
2022 + chan = &dmac->channel[chanid];
2024 + if (chan->is_cyclic) {
2025 + BUG_ON(!chan->req_cyclic
2026 + || !chan->req_cyclic->req.block_complete);
2027 + req = &chan->req_cyclic->req;
2029 + BUG_ON(!chan->req_sg || !chan->req_sg->req.block_complete);
2030 + req = &chan->req_sg->req;
2032 + dmac_writel_lo(dmac, CLEAR_BLOCK, 1 << chanid);
2033 + req->block_complete(req);
2034 + status = dmac_readl_lo(dmac, STATUS_BLOCK);
2038 +static void dmac_xfer_complete(struct dw_dma_controller *dmac)
2040 + struct dw_dma_channel *chan;
2041 + struct dma_request *req;
2042 + unsigned long status, chanid;
2044 + status = dmac_readl_lo(dmac, STATUS_XFER);
2047 + chanid = __ffs(status);
2048 + chan = &dmac->channel[chanid];
2050 + dmac_writel_lo(dmac, CLEAR_XFER, 1 << chanid);
2052 + req = &chan->req_sg->req;
2054 + cleanup_channel(dmac, chan);
2055 + if (req->xfer_complete)
2056 + req->xfer_complete(req);
2058 + status = dmac_readl_lo(dmac, STATUS_XFER);
2062 +static void dmac_error(struct dw_dma_controller *dmac)
2064 + struct dw_dma_channel *chan;
2065 + unsigned long status, chanid;
2067 + status = dmac_readl_lo(dmac, STATUS_ERROR);
2070 + struct dma_request *req;
2072 + chanid = __ffs(status);
2073 + chan = &dmac->channel[chanid];
2075 + dmac_writel_lo(dmac, CLEAR_ERROR, 1 << chanid);
2076 + clear_channel_bit(dmac, CH_EN, chanid);
2078 + if (chan->is_cyclic) {
2079 + BUG_ON(!chan->req_cyclic);
2080 + req = &chan->req_cyclic->req;
2082 + BUG_ON(!chan->req_sg);
2083 + req = &chan->req_sg->req;
2086 + cleanup_channel(dmac, chan);
2090 + status = dmac_readl_lo(dmac, STATUS_XFER);
2094 +static irqreturn_t dmac_interrupt(int irq, void *dev_id)
2096 + struct dw_dma_controller *dmac = dev_id;
2097 + unsigned long status;
2098 + int ret = IRQ_NONE;
2100 + spin_lock(&dmac->lock);
2102 + status = dmac_readl_lo(dmac, STATUS_INT);
2105 + ret = IRQ_HANDLED;
2106 + if (status & 0x10)
2108 + if (status & 0x02)
2109 + dmac_block_complete(dmac);
2110 + if (status & 0x01)
2111 + dmac_xfer_complete(dmac);
2113 + status = dmac_readl_lo(dmac, STATUS_INT);
2116 + spin_unlock(&dmac->lock);
2120 +static int __devinit dmac_probe(struct platform_device *pdev)
2122 + struct dw_dma_controller *dmac;
2123 + struct resource *regs;
2126 + regs = platform_get_resource(pdev, IORESOURCE_MEM, 0);
2130 + dmac = kmalloc(sizeof(*dmac), GFP_KERNEL);
2133 + memset(dmac, 0, sizeof(*dmac));
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;
2140 + clk_enable(dmac->hclk);
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;
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;
2158 + dmac->regs = ioremap(regs->start, regs->end - regs->start + 1);
2160 + goto out_free_pool;
2162 + ret = request_irq(platform_get_irq(pdev, 0), dmac_interrupt,
2163 + IRQF_SAMPLE_RANDOM, pdev->name, dmac);
2165 + goto out_unmap_regs;
2167 + /* Enable the DMA controller */
2168 + dmac_writel_lo(dmac, CFG, 1);
2170 + register_dma_controller(&dmac->dma);
2173 + "dmac%d: DesignWare DMA controller at 0x%p irq %d\n",
2174 + dmac->dma.id, dmac->regs, platform_get_irq(pdev, 0));
2179 + iounmap(dmac->regs);
2181 + dma_pool_destroy(dmac->lli_pool);
2183 + clk_disable(dmac->hclk);
2184 + clk_put(dmac->hclk);
2190 +static struct platform_driver dmac_driver = {
2191 + .probe = dmac_probe,
2197 +static int __init dmac_init(void)
2199 + return platform_driver_register(&dmac_driver);
2201 +subsys_initcall(dmac_init);
2203 +static void __exit dmac_exit(void)
2205 + platform_driver_unregister(&dmac_driver);
2207 +module_exit(dmac_exit);
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
2216 +++ b/arch/avr32/drivers/dw-dmac.h
2219 + * Driver for the Synopsys DesignWare DMA Controller
2221 + * Copyright (C) 2005-2006 Atmel Corporation
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.
2227 +#ifndef __AVR32_DW_DMAC_H__
2228 +#define __AVR32_DW_DMAC_H__
2230 +#define DW_DMAC_CFG 0x398
2231 +#define DW_DMAC_CH_EN 0x3a0
2233 +#define DW_DMAC_STATUS_XFER 0x2e8
2234 +#define DW_DMAC_STATUS_BLOCK 0x2f0
2235 +#define DW_DMAC_STATUS_ERROR 0x308
2237 +#define DW_DMAC_MASK_XFER 0x310
2238 +#define DW_DMAC_MASK_BLOCK 0x318
2239 +#define DW_DMAC_MASK_ERROR 0x330
2241 +#define DW_DMAC_CLEAR_XFER 0x338
2242 +#define DW_DMAC_CLEAR_BLOCK 0x340
2243 +#define DW_DMAC_CLEAR_ERROR 0x358
2245 +#define DW_DMAC_STATUS_INT 0x360
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
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
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
2276 +++ b/arch/avr32/kernel/dma-controller.c
2279 + * Preliminary DMA controller framework for AVR32
2281 + * Copyright (C) 2005-2006 Atmel Corporation
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.
2287 +#include <asm/dma-controller.h>
2289 +static LIST_HEAD(controllers);
2291 +int register_dma_controller(struct dma_controller *dmac)
2293 + static int next_id;
2295 + dmac->id = next_id++;
2296 + list_add_tail(&dmac->list, &controllers);
2300 +EXPORT_SYMBOL(register_dma_controller);
2302 +struct dma_controller *find_dma_controller(int id)
2304 + struct dma_controller *dmac;
2306 + list_for_each_entry(dmac, &controllers, list)
2307 + if (dmac->id == id)
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);
2318 static int __init parse_tag_rdimg(struct tag *tag)
2320 -#ifdef CONFIG_INITRD
2321 +#ifdef CONFIG_BLK_DEV_INITRD
2322 struct tag_mem_range *mem = &tag->u.mem_range;
2325 @@ -323,7 +323,7 @@ static int __init parse_tag_rdimg(struct tag *tag)
2329 - ret = add_reserved_region(mem->start, mem->start + mem->size - 1,
2330 + ret = add_reserved_region(mem->addr, mem->addr + mem->size - 1,
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
2343 + bool "GPIO /dev interface"
2344 + select CONFIGFS_FS
2347 + Say `Y' to enable a /dev interface to the GPIO pins.
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
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
2367 #include <linux/init.h>
2368 #include <linux/platform_device.h>
2370 -#include <asm/io.h>
2372 #include <asm/arch/init.h>
2373 -#include <asm/arch/sm.h>
2375 -struct at32_sm system_manager;
2377 -static int __init at32_sm_init(void)
2379 - struct resource *regs;
2380 - struct at32_sm *sm = &system_manager;
2383 - regs = platform_get_resource(&at32_sm_device, IORESOURCE_MEM, 0);
2387 - spin_lock_init(&sm->lock);
2388 - sm->pdev = &at32_sm_device;
2391 - sm->regs = ioremap(regs->start, regs->end - regs->start + 1);
2398 - printk(KERN_ERR "Failed to initialize System Manager: %d\n", ret);
2402 void __init setup_platform(void)
2406 at32_portmux_init();
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
2413 #include <asm/arch/at32ap7000.h>
2414 #include <asm/arch/board.h>
2415 #include <asm/arch/portmux.h>
2416 -#include <asm/arch/sm.h>
2418 #include <video/atmel_lcdc.h>
2421 #include "hmatrix.h"
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.
2431 +#define AT32_PM_BASE 0xfff00000
2433 #define PBMEM(base) \
2435 @@ -88,6 +94,8 @@ static struct clk devname##_##_name = { \
2439 +static DEFINE_SPINLOCK(pm_lock);
2441 unsigned long at32ap7000_osc_rates[3] = {
2443 /* FIXME: these are ATSTK1002-specific */
2444 @@ -104,11 +112,11 @@ static unsigned long pll_get_rate(struct clk *clk, unsigned long control)
2446 unsigned long div, mul, rate;
2448 - if (!(control & SM_BIT(PLLEN)))
2449 + if (!(control & PM_BIT(PLLEN)))
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;
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)
2463 - control = sm_readl(&system_manager, PM_PLL0);
2464 + control = pm_readl(PLL0);
2466 return pll_get_rate(clk, control);
2468 @@ -130,7 +138,7 @@ static unsigned long pll1_get_rate(struct clk *clk)
2472 - control = sm_readl(&system_manager, PM_PLL1);
2473 + control = pm_readl(PLL1);
2475 return pll_get_rate(clk, control);
2477 @@ -187,108 +195,139 @@ static unsigned long bus_clk_get_rate(struct clk *clk, unsigned int shift)
2479 static void cpu_clk_mode(struct clk *clk, int enabled)
2481 - struct at32_sm *sm = &system_manager;
2482 unsigned long flags;
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);
2490 mask |= 1 << clk->index;
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);
2499 static unsigned long cpu_clk_get_rate(struct clk *clk)
2501 unsigned long cksel, shift = 0;
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;
2510 return bus_clk_get_rate(clk, shift);
2513 +static long cpu_clk_set_rate(struct clk *clk, unsigned long rate, int apply)
2516 + unsigned long parent_rate, child_div, actual_rate, div;
2518 + parent_rate = clk->parent->get_rate(clk->parent);
2519 + control = pm_readl(CKSEL);
2521 + if (control & PM_BIT(HSBDIV))
2522 + child_div = 1 << (PM_BFEXT(HSBSEL, control) + 1);
2526 + if (rate > 3 * (parent_rate / 4) || child_div == 1) {
2527 + actual_rate = parent_rate;
2528 + control &= ~PM_BIT(CPUDIV);
2530 + unsigned int cpusel;
2531 + div = (parent_rate + rate / 2) / rate;
2532 + if (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));
2539 + pr_debug("clk %s: new rate %lu (actual rate %lu)\n",
2540 + clk->name, rate, actual_rate);
2543 + pm_writel(CKSEL, control);
2545 + return actual_rate;
2548 static void hsb_clk_mode(struct clk *clk, int enabled)
2550 - struct at32_sm *sm = &system_manager;
2551 unsigned long flags;
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);
2559 mask |= 1 << clk->index;
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);
2568 static unsigned long hsb_clk_get_rate(struct clk *clk)
2570 unsigned long cksel, shift = 0;
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;
2579 return bus_clk_get_rate(clk, shift);
2582 static void pba_clk_mode(struct clk *clk, int enabled)
2584 - struct at32_sm *sm = &system_manager;
2585 unsigned long flags;
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);
2593 mask |= 1 << clk->index;
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);
2602 static unsigned long pba_clk_get_rate(struct clk *clk)
2604 unsigned long cksel, shift = 0;
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;
2613 return bus_clk_get_rate(clk, shift);
2616 static void pbb_clk_mode(struct clk *clk, int enabled)
2618 - struct at32_sm *sm = &system_manager;
2619 unsigned long flags;
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);
2627 mask |= 1 << clk->index;
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);
2636 static unsigned long pbb_clk_get_rate(struct clk *clk)
2638 unsigned long cksel, shift = 0;
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;
2647 return bus_clk_get_rate(clk, shift);
2649 @@ -296,6 +335,7 @@ static unsigned long pbb_clk_get_rate(struct clk *clk)
2650 static struct clk cpu_clk = {
2652 .get_rate = cpu_clk_get_rate,
2653 + .set_rate = cpu_clk_set_rate,
2656 static struct clk hsb_clk = {
2657 @@ -327,12 +367,12 @@ static void genclk_mode(struct clk *clk, int enabled)
2661 - control = sm_readl(&system_manager, PM_GCCTRL + 4 * clk->index);
2662 + control = pm_readl(GCCTRL(clk->index));
2664 - control |= SM_BIT(CEN);
2665 + control |= PM_BIT(CEN);
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);
2673 static unsigned long genclk_get_rate(struct clk *clk)
2674 @@ -340,9 +380,9 @@ static unsigned long genclk_get_rate(struct clk *clk)
2676 unsigned long div = 1;
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);
2685 return clk->parent->get_rate(clk->parent) / div;
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;
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));
2694 if (rate > 3 * parent_rate / 4) {
2695 actual_rate = parent_rate;
2696 - control &= ~SM_BIT(DIVEN);
2697 + control &= ~PM_BIT(DIVEN);
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));
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);
2711 - sm_writel(&system_manager, PM_GCCTRL + 4 * clk->index,
2713 + pm_writel(GCCTRL(clk->index), control);
2717 @@ -378,24 +417,24 @@ int genclk_set_parent(struct clk *clk, struct clk *parent)
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);
2726 - control = sm_readl(&system_manager, PM_GCCTRL + 4 * clk->index);
2727 + control = pm_readl(GCCTRL(clk->index));
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);
2738 if (parent == &pll0 || parent == &pll1)
2739 - control |= SM_BIT(PLLSEL);
2740 + control |= PM_BIT(PLLSEL);
2742 - control &= ~SM_BIT(PLLSEL);
2743 + control &= ~PM_BIT(PLLSEL);
2745 - sm_writel(&system_manager, PM_GCCTRL + 4 * clk->index, control);
2746 + pm_writel(GCCTRL(clk->index), control);
2747 clk->parent = parent;
2750 @@ -408,11 +447,11 @@ static void __init genclk_init_parent(struct clk *clk)
2752 BUG_ON(clk->index > 7);
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;
2761 - parent = (control & SM_BIT(PLLSEL)) ? &pll0 : &osc0;
2762 + parent = (control & PM_BIT(PLLSEL)) ? &pll0 : &osc0;
2764 clk->parent = parent;
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"),
2776 -struct platform_device at32_sm_device = {
2779 - .resource = sm_resource,
2780 - .num_resources = ARRAY_SIZE(sm_resource),
2781 +static struct resource at32_pm0_resource[] = {
2783 + .start = 0xfff00000,
2784 + .end = 0xfff0007f,
2785 + .flags = IORESOURCE_MEM,
2789 -static struct clk at32_sm_pclk = {
2791 +static struct resource at32ap700x_rtc0_resource[] = {
2793 + .start = 0xfff00080,
2794 + .end = 0xfff000af,
2795 + .flags = IORESOURCE_MEM,
2800 +static struct resource at32_wdt0_resource[] = {
2802 + .start = 0xfff000b0,
2803 + .end = 0xfff000bf,
2804 + .flags = IORESOURCE_MEM,
2808 +static struct resource at32_eic0_resource[] = {
2810 + .start = 0xfff00100,
2811 + .end = 0xfff0013f,
2812 + .flags = IORESOURCE_MEM,
2817 +DEFINE_DEV(at32_pm, 0);
2818 +DEFINE_DEV(at32ap700x_rtc, 0);
2819 +DEFINE_DEV(at32_wdt, 0);
2820 +DEFINE_DEV(at32_eic, 0);
2823 + * Peripheral clock for PM, RTC, WDT and EIC. PM will ensure that this
2824 + * is always running.
2826 +static struct clk at32_pm_pclk = {
2828 - .dev = &at32_sm_device.dev,
2829 + .dev = &at32_pm0_device.dev,
2831 .mode = pbb_clk_mode,
2832 .get_rate = pbb_clk_get_rate,
2833 @@ -491,6 +562,17 @@ static struct clk pico_clk = {
2837 +static struct resource dmaca0_resource[] = {
2839 + .start = 0xff200000,
2840 + .end = 0xff20ffff,
2841 + .flags = IORESOURCE_MEM,
2845 +DEFINE_DEV(dmaca, 0);
2846 +DEV_CLK(hclk, dmaca0, hsb, 10);
2848 /* --------------------------------------------------------------------
2850 * -------------------------------------------------------------------- */
2851 @@ -583,12 +665,14 @@ DEV_CLK(mck, pio4, pba, 14);
2853 void __init at32_add_system_devices(void)
2855 - system_manager.eim_first_irq = EIM_IRQ_BASE;
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);
2867 platform_device_register(&at32_systc0_device);
2869 @@ -894,6 +978,83 @@ at32_add_device_spi(unsigned int id, struct spi_board_info *b, unsigned int n)
2872 /* --------------------------------------------------------------------
2874 + * -------------------------------------------------------------------- */
2876 +static struct resource atmel_twi0_resource[] = {
2877 + PBMEM(0xffe00800),
2880 +DEFINE_DEV(atmel_twi, 0);
2881 +DEV_CLK(pclk,atmel_twi0,pba,2);
2883 +struct platform_device *__init
2884 +at32_add_device_twi(unsigned int id)
2886 + struct platform_device *pdev;
2890 + pdev = &atmel_twi0_device;
2891 + select_peripheral(PA(6), PERIPH_A, 0); /* SDA */
2892 + select_peripheral(PA(7), PERIPH_A, 0); /* SCL */
2899 + platform_device_register(pdev);
2903 +/* --------------------------------------------------------------------
2905 + * -------------------------------------------------------------------- */
2906 +static struct mci_platform_data atmel_mci0_data = {
2907 + .detect_pin = GPIO_PIN_NONE,
2908 + .wp_pin = GPIO_PIN_NONE,
2910 +static struct resource atmel_mci0_resource[] = {
2911 + PBMEM(0xfff02400),
2914 +DEFINE_DEV_DATA(atmel_mci, 0);
2915 +DEV_CLK(mci_clk, atmel_mci0, pbb, 9);
2917 +struct platform_device *__init
2918 +at32_add_device_mci(unsigned int id, struct mci_platform_data *data)
2920 + struct platform_device *pdev;
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 */
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));
2945 + platform_device_register(pdev);
2949 +/* --------------------------------------------------------------------
2951 * -------------------------------------------------------------------- */
2952 static struct atmel_lcdfb_info atmel_lcdfb0_data;
2953 @@ -1013,6 +1174,228 @@ err_dup_modedb:
2956 /* --------------------------------------------------------------------
2957 + * USB Device Controller
2958 + * -------------------------------------------------------------------- */
2959 +static struct resource usba0_resource[] __initdata = {
2962 + .start = 0xff300000,
2963 + .end = 0xff3fffff,
2964 + .flags = IORESOURCE_MEM,
2967 + .start = 0xfff03000,
2968 + .end = 0xfff033ff,
2969 + .flags = IORESOURCE_MEM,
2973 +static struct clk usba0_pclk = {
2975 + .parent = &pbb_clk,
2976 + .mode = pbb_clk_mode,
2977 + .get_rate = pbb_clk_get_rate,
2980 +static struct clk usba0_hclk = {
2982 + .parent = &hsb_clk,
2983 + .mode = hsb_clk_mode,
2984 + .get_rate = hsb_clk_get_rate,
2988 +struct platform_device *__init
2989 +at32_add_device_usba(unsigned int id, struct usba_platform_data *data)
2991 + struct platform_device *pdev;
2996 + pdev = platform_device_alloc("atmel_usba_udc", 0);
3000 + if (platform_device_add_resources(pdev, usba0_resource,
3001 + ARRAY_SIZE(usba0_resource)))
3002 + goto out_free_pdev;
3005 + if (platform_device_add_data(pdev, data, sizeof(*data)))
3006 + goto out_free_pdev;
3008 + if (data->vbus_pin != GPIO_PIN_NONE)
3009 + at32_select_gpio(data->vbus_pin, 0);
3012 + usba0_pclk.dev = &pdev->dev;
3013 + usba0_hclk.dev = &pdev->dev;
3015 + platform_device_add(pdev);
3020 + platform_device_put(pdev);
3024 +/* --------------------------------------------------------------------
3026 + * -------------------------------------------------------------------- */
3027 +static struct resource ssc0_resource[] = {
3028 + PBMEM(0xffe01c00),
3031 +DEFINE_DEV(ssc, 0);
3032 +DEV_CLK(pclk, ssc0, pba, 7);
3034 +static struct resource ssc1_resource[] = {
3035 + PBMEM(0xffe02000),
3038 +DEFINE_DEV(ssc, 1);
3039 +DEV_CLK(pclk, ssc1, pba, 8);
3041 +static struct resource ssc2_resource[] = {
3042 + PBMEM(0xffe02400),
3045 +DEFINE_DEV(ssc, 2);
3046 +DEV_CLK(pclk, ssc2, pba, 9);
3048 +struct platform_device *__init
3049 +at32_add_device_ssc(unsigned int id, unsigned int flags)
3051 + struct platform_device *pdev;
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 */
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 */
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 */
3103 + platform_device_register(pdev);
3107 +/* --------------------------------------------------------------------
3109 + * -------------------------------------------------------------------- */
3110 +static struct resource atmel_ac97c0_resource[] = {
3111 + PBMEM(0xfff02800),
3114 +DEFINE_DEV(atmel_ac97c, 0);
3115 +DEV_CLK(pclk, atmel_ac97c0, pbb, 10);
3117 +struct platform_device *__init
3118 +at32_add_device_ac97c(unsigned int id)
3120 + struct platform_device *pdev;
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 */
3134 + platform_device_register(pdev);
3138 +/* --------------------------------------------------------------------
3140 + * -------------------------------------------------------------------- */
3141 +static struct resource abdac0_resource[] = {
3142 + PBMEM(0xfff02000),
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,
3157 +struct platform_device *__init
3158 +at32_add_device_abdac(unsigned int id)
3160 + struct platform_device *pdev;
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 */
3174 + platform_device_register(pdev);
3178 +/* --------------------------------------------------------------------
3180 * -------------------------------------------------------------------- */
3181 static struct clk gclk0 = {
3182 @@ -1066,7 +1449,7 @@ struct clk *at32_clock_list[] = {
3191 @@ -1075,6 +1458,7 @@ struct clk *at32_clock_list[] = {
3199 @@ -1092,8 +1476,18 @@ struct clk *at32_clock_list[] = {
3201 &atmel_spi0_spi_clk,
3202 &atmel_spi1_spi_clk,
3204 + &atmel_mci0_mci_clk,
3206 &atmel_lcdfb0_pixclk,
3212 + &atmel_ac97c0_pclk,
3214 + &abdac0_sample_clk,
3218 @@ -1113,18 +1507,20 @@ void __init at32_portmux_init(void)
3220 void __init at32_clock_init(void)
3222 - struct at32_sm *sm = &system_manager;
3223 u32 cpu_mask = 0, hsb_mask = 0, pba_mask = 0, pbb_mask = 0;
3226 - if (sm_readl(sm, PM_MCCTRL) & SM_BIT(PLLSEL))
3227 + if (pm_readl(MCCTRL) & PM_BIT(PLLSEL)) {
3230 + cpu_clk.parent = &pll0;
3233 + cpu_clk.parent = &osc0;
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;
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);
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;
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);
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
3269 +++ b/arch/avr32/mach-at32ap/cpufreq.c
3272 + * Copyright (C) 2004-2007 Atmel Corporation
3274 + * Based on MIPS implementation arch/mips/kernel/time.c
3275 + * Copyright 2001 MontaVista Software Inc.
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.
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>
3293 +static struct clk *cpuclk;
3295 +static int at32_verify_speed(struct cpufreq_policy *policy)
3297 + if (policy->cpu != 0)
3300 + cpufreq_verify_within_limits(policy, policy->cpuinfo.min_freq,
3301 + policy->cpuinfo.max_freq);
3305 +static unsigned int at32_get_speed(unsigned int cpu)
3307 + /* No SMP support */
3310 + return (unsigned int)((clk_get_rate(cpuclk) + 500) / 1000);
3313 +static int at32_set_target(struct cpufreq_policy *policy,
3314 + unsigned int target_freq,
3315 + unsigned int relation)
3317 + struct cpufreq_freqs freqs;
3320 + /* Convert target_freq from kHz to Hz */
3321 + freq = clk_round_rate(cpuclk, target_freq * 1000);
3323 + /* Check if policy->min <= new_freq <= policy->max */
3324 + if(freq < (policy->min * 1000) || freq > (policy->max * 1000))
3327 + pr_debug("cpufreq: requested frequency %u Hz\n", target_freq * 1000);
3329 + freqs.old = at32_get_speed(0);
3330 + freqs.new = (freq + 500) / 1000;
3334 + cpufreq_notify_transition(&freqs, CPUFREQ_PRECHANGE);
3335 + clk_set_rate(cpuclk, freq);
3336 + cpufreq_notify_transition(&freqs, CPUFREQ_POSTCHANGE);
3338 + pr_debug("cpufreq: set frequency %lu Hz\n", freq);
3343 +static int __init at32_cpufreq_driver_init(struct cpufreq_policy *policy)
3345 + if (policy->cpu != 0)
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);
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;
3362 + printk("cpufreq: AT32AP CPU frequency driver\n");
3367 +static struct cpufreq_driver at32_driver = {
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,
3377 +static int __init at32_cpufreq_init(void)
3379 + return cpufreq_register_driver(&at32_driver);
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
3391 -#include <asm/arch/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
3406 +/* Bitfields in TEST */
3407 +#define EIC_TESTEN_OFFSET 31
3408 +#define EIC_TESTEN_SIZE 1
3410 +/* Bitfields in NMIC */
3411 +#define EIC_EN_OFFSET 0
3412 +#define EIC_EN_SIZE 1
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))
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)
3435 + void __iomem *regs;
3436 + struct irq_chip *chip;
3437 + unsigned int first_irq;
3440 -static void eim_ack_irq(unsigned int irq)
3441 +static void eic_ack_irq(unsigned int irq)
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));
3449 -static void eim_mask_irq(unsigned int irq)
3450 +static void eic_mask_irq(unsigned int irq)
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));
3458 -static void eim_mask_ack_irq(unsigned int irq)
3459 +static void eic_mask_ack_irq(unsigned int irq)
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));
3469 -static void eim_unmask_irq(unsigned int irq)
3470 +static void eic_unmask_irq(unsigned int irq)
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));
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)
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;
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;
3494 desc = &irq_desc[irq];
3495 - spin_lock_irqsave(&sm->lock, flags);
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);
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)
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);
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;
3523 - spin_unlock_irqrestore(&sm->lock, flags);
3528 -struct irq_chip eim_chip = {
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 = {
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,
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)
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;
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);
3559 i = fls(pending) - 1;
3560 pending &= ~(1 << i);
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)
3571 -static int __init eim_init(void)
3572 +static int __init eic_probe(struct platform_device *pdev)
3574 - struct at32_sm *sm = &system_manager;
3576 + struct resource *regs;
3578 unsigned int nr_irqs;
3579 unsigned int int_irq;
3584 - * The EIM is really the same module as SM, so register
3585 - * mapping, etc. has been taken care of already.
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");
3595 + eic = kzalloc(sizeof(struct eic), GFP_KERNEL);
3597 + dev_dbg(&pdev->dev, "no memory for eic structure\n");
3601 + eic->first_irq = EIM_IRQ_BASE + 32 * pdev->id;
3602 + eic->regs = ioremap(regs->start, regs->end - regs->start + 1);
3604 + dev_dbg(&pdev->dev, "failed to map regs\n");
3609 * Find out how many interrupt lines that are actually
3610 * implemented in hardware.
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);
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);
3626 - sm->eim_chip = &eim_chip;
3627 + eic->chip = &eic_chip;
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,
3634 - set_irq_chip_data(sm->eim_first_irq + i, sm);
3635 + set_irq_chip_data(eic->first_irq + i, eic);
3638 - int_irq = platform_get_irq_byname(sm->pdev, "eim");
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);
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);
3664 +static struct platform_driver eic_driver = {
3666 + .name = "at32_eic",
3670 +static int __init eic_init(void)
3672 + return platform_driver_probe(&eic_driver, eic_probe);
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
3680 +++ b/arch/avr32/mach-at32ap/gpio-dev.c
3683 + * GPIO /dev and configfs interface
3685 + * Copyright (C) 2006-2007 Atmel Corporation
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.
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>
3699 +#include <asm/gpio.h>
3700 +#include <asm/arch/portmux.h>
3702 +#define GPIO_DEV_MAX 8
3704 +static struct class *gpio_dev_class;
3705 +static dev_t gpio_devt;
3716 + /* Pin state last time we read it (for blocking reads) */
3720 + wait_queue_head_t change_wq;
3721 + struct fasync_struct *async_queue;
3724 + struct class_device *gpio_dev;
3725 + struct cdev char_dev;
3726 + struct config_item item;
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);
3735 +static irqreturn_t gpio_dev_interrupt(int irq, void *dev_id)
3737 + struct gpio_item *gpio = dev_id;
3738 + u32 old_state, new_state;
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;
3744 + if (new_state != old_state) {
3745 + gpio->changed = 1;
3746 + wake_up_interruptible(&gpio->change_wq);
3748 + if (gpio->async_queue)
3749 + kill_fasync(&gpio->async_queue, SIGIO, POLL_IN);
3752 + return IRQ_HANDLED;
3755 +static int gpio_dev_open(struct inode *inode, struct file *file)
3757 + struct gpio_item *gpio = container_of(inode->i_cdev,
3764 + nonseekable_open(inode, file);
3765 + config_item_get(&gpio->item);
3766 + file->private_data = gpio;
3768 + gpio->pin_state = at32_gpio_get_value_multiple(gpio->port,
3770 + gpio->changed = 1;
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);
3786 + if (gpio->pin_mask & (1 << i)) {
3787 + irq = gpio_to_irq(32 * gpio->port + i);
3788 + free_irq(irq, gpio);
3792 + config_item_put(&gpio->item);
3797 +static int gpio_dev_fasync(int fd, struct file *file, int mode)
3799 + struct gpio_item *gpio = file->private_data;
3801 + return fasync_helper(fd, file, mode, &gpio->async_queue);
3804 +static int gpio_dev_release(struct inode *inode, struct file *file)
3806 + struct gpio_item *gpio = file->private_data;
3810 + gpio_dev_fasync(-1, file, 0);
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);
3819 + config_item_put(&gpio->item);
3824 +static unsigned int gpio_dev_poll(struct file *file, poll_table *wait)
3826 + struct gpio_item *gpio = file->private_data;
3827 + unsigned int mask = 0;
3829 + poll_wait(file, &gpio->change_wq, wait);
3830 + if (gpio->changed)
3831 + mask |= POLLIN | POLLRDNORM;
3836 +static ssize_t gpio_dev_read(struct file *file, char __user *buf,
3837 + size_t count, loff_t *offset)
3839 + struct gpio_item *gpio = file->private_data;
3842 + spin_lock_irq(&gpio->lock);
3843 + while (!gpio->changed) {
3844 + spin_unlock_irq(&gpio->lock);
3846 + if (file->f_flags & O_NONBLOCK)
3849 + if (wait_event_interruptible(gpio->change_wq, gpio->changed))
3850 + return -ERESTARTSYS;
3852 + spin_lock_irq(&gpio->lock);
3855 + gpio->changed = 0;
3856 + value = at32_gpio_get_value_multiple(gpio->port, gpio->pin_mask);
3858 + spin_unlock_irq(&gpio->lock);
3860 + count = min(count, (size_t)4);
3861 + if (copy_to_user(buf, &value, count))
3867 +static ssize_t gpio_dev_write(struct file *file, const char __user *buf,
3868 + size_t count, loff_t *offset)
3870 + struct gpio_item *gpio = file->private_data;
3874 + count = min(count, (size_t)4);
3875 + if (copy_from_user(&value, buf, count))
3878 + /* Assuming big endian */
3879 + mask <<= (4 - count) * 8;
3880 + mask &= gpio->pin_mask;
3882 + at32_gpio_set_value_multiple(gpio->port, value, mask);
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,
3898 +static struct gpio_item *to_gpio_item(struct config_item *item)
3900 + return item ? container_of(item, struct gpio_item, item) : NULL;
3903 +static ssize_t gpio_show_gpio_id(struct gpio_item *gpio, char *page)
3905 + return sprintf(page, "%d\n", gpio->port);
3908 +static ssize_t gpio_store_gpio_id(struct gpio_item *gpio,
3909 + const char *page, size_t count)
3912 + char *p = (char *)page;
3913 + ssize_t ret = -EINVAL;
3915 + id = simple_strtoul(p, &p, 0);
3916 + if (!p || (*p && (*p != '\n')))
3919 + /* Switching PIO is not allowed when live... */
3920 + spin_lock(&gpio->lock);
3921 + if (!gpio->enabled) {
3923 + if (at32_gpio_port_is_valid(id)) {
3928 + spin_unlock(&gpio->lock);
3933 +static ssize_t gpio_show_pin_mask(struct gpio_item *gpio, char *page)
3935 + return sprintf(page, "0x%08x\n", gpio->pin_mask);
3938 +static ssize_t gpio_store_pin_mask(struct gpio_item *gpio,
3939 + const char *page, size_t count)
3942 + char *p = (char *)page;
3943 + ssize_t ret = -EINVAL;
3945 + new_mask = simple_strtoul(p, &p, 0);
3946 + if (!p || (*p && (*p != '\n')))
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;
3956 + spin_unlock(&gpio->lock);
3961 +static ssize_t gpio_show_oe_mask(struct gpio_item *gpio, char *page)
3963 + return sprintf(page, "0x%08x\n", gpio->oe_mask);
3966 +static ssize_t gpio_store_oe_mask(struct gpio_item *gpio,
3967 + const char *page, size_t count)
3970 + char *p = (char *)page;
3971 + ssize_t ret = -EINVAL;
3973 + mask = simple_strtoul(p, &p, 0);
3974 + if (!p || (*p && (*p != '\n')))
3977 + spin_lock(&gpio->lock);
3978 + if (!gpio->enabled) {
3979 + gpio->oe_mask = mask & gpio->pin_mask;
3982 + spin_unlock(&gpio->lock);
3987 +static ssize_t gpio_show_enabled(struct gpio_item *gpio, char *page)
3989 + return sprintf(page, "%d\n", gpio->enabled);
3992 +static ssize_t gpio_store_enabled(struct gpio_item *gpio,
3993 + const char *page, size_t count)
3995 + char *p = (char *)page;
3999 + enabled = simple_strtoul(p, &p, 0);
4000 + if (!p || (*p && (*p != '\n')))
4003 + /* make it a boolean value */
4004 + enabled = !!enabled;
4006 + if (gpio->enabled == enabled)
4007 + /* No change; do nothing. */
4010 + BUG_ON(gpio->id >= GPIO_DEV_MAX);
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;
4018 + if (gpio->port < 0 || !gpio->pin_mask)
4022 + /* Disallow any updates to gpio_id or pin_mask */
4023 + spin_lock(&gpio->lock);
4024 + gpio->enabled = enabled;
4025 + spin_unlock(&gpio->lock);
4030 + /* Now, try to allocate the pins */
4031 + ret = at32_select_gpio_pins(gpio->port, gpio->pin_mask, gpio->oe_mask);
4033 + goto err_alloc_pins;
4035 + gpio->initialized = 1;
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);
4041 + goto err_cdev_add;
4042 + gpio->gpio_dev = class_device_create(gpio_dev_class, NULL,
4043 + MKDEV(MAJOR(gpio_devt), gpio->id),
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;
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));
4059 + cdev_del(&gpio->char_dev);
4061 + at32_deselect_pins(gpio->port, gpio->pin_mask);
4062 + gpio->initialized = 0;
4064 + spin_lock(&gpio->lock);
4065 + gpio->enabled = 0;
4066 + spin_unlock(&gpio->lock);
4071 +static struct gpio_attribute gpio_item_attr_gpio_id = {
4073 + .ca_owner = THIS_MODULE,
4074 + .ca_name = "gpio_id",
4075 + .ca_mode = S_IRUGO | S_IWUSR,
4077 + .show = gpio_show_gpio_id,
4078 + .store = gpio_store_gpio_id,
4080 +static struct gpio_attribute gpio_item_attr_pin_mask = {
4082 + .ca_owner = THIS_MODULE,
4083 + .ca_name = "pin_mask",
4084 + .ca_mode = S_IRUGO | S_IWUSR,
4086 + .show = gpio_show_pin_mask,
4087 + .store = gpio_store_pin_mask,
4089 +static struct gpio_attribute gpio_item_attr_oe_mask = {
4091 + .ca_owner = THIS_MODULE,
4092 + .ca_name = "oe_mask",
4093 + .ca_mode = S_IRUGO | S_IWUSR,
4095 + .show = gpio_show_oe_mask,
4096 + .store = gpio_store_oe_mask,
4098 +static struct gpio_attribute gpio_item_attr_enabled = {
4100 + .ca_owner = THIS_MODULE,
4101 + .ca_name = "enabled",
4102 + .ca_mode = S_IRUGO | S_IWUSR,
4104 + .show = gpio_show_enabled,
4105 + .store = gpio_store_enabled,
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,
4116 +static ssize_t gpio_show_attr(struct config_item *item,
4117 + struct configfs_attribute *attr,
4120 + struct gpio_item *gpio_item = to_gpio_item(item);
4121 + struct gpio_attribute *gpio_attr
4122 + = container_of(attr, struct gpio_attribute, attr);
4125 + if (gpio_attr->show)
4126 + ret = gpio_attr->show(gpio_item, page);
4130 +static ssize_t gpio_store_attr(struct config_item *item,
4131 + struct configfs_attribute *attr,
4132 + const char *page, size_t count)
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;
4139 + if (gpio_attr->store)
4140 + ret = gpio_attr->store(gpio_item, page, count);
4144 +static void gpio_release(struct config_item *item)
4146 + kfree(to_gpio_item(item));
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,
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,
4161 +static struct config_item *gpio_make_item(struct config_group *group,
4164 + static int next_id;
4165 + struct gpio_item *gpio;
4167 + if (next_id >= GPIO_DEV_MAX)
4170 + gpio = kzalloc(sizeof(struct gpio_item), GFP_KERNEL);
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);
4179 + return &gpio->item;
4182 +static void gpio_drop_item(struct config_group *group,
4183 + struct config_item *item)
4185 + struct gpio_item *gpio = to_gpio_item(item);
4187 + spin_lock(&gpio->lock);
4188 + if (gpio->enabled) {
4189 + class_device_unregister(gpio->gpio_dev);
4190 + cdev_del(&gpio->char_dev);
4193 + if (gpio->initialized) {
4194 + at32_deselect_pins(gpio->port, gpio->pin_mask);
4195 + gpio->initialized = 0;
4196 + gpio->enabled = 0;
4198 + spin_unlock(&gpio->lock);
4201 +static struct configfs_group_operations gpio_group_ops = {
4202 + .make_item = gpio_make_item,
4203 + .drop_item = gpio_drop_item,
4206 +static struct config_item_type gpio_group_type = {
4207 + .ct_group_ops = &gpio_group_ops,
4208 + .ct_owner = THIS_MODULE,
4211 +static struct configfs_subsystem gpio_subsys = {
4214 + .ci_namebuf = "gpio",
4215 + .ci_type = &gpio_group_type,
4220 +static int __init gpio_dev_init(void)
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;
4230 + err = alloc_chrdev_region(&gpio_devt, 0, GPIO_DEV_MAX, "gpio");
4232 + goto err_alloc_chrdev;
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);
4239 + goto err_register_subsys;
4243 +err_register_subsys:
4244 + unregister_chrdev_region(gpio_devt, GPIO_DEV_MAX);
4246 + class_destroy(gpio_dev_class);
4248 + printk(KERN_WARNING "Failed to initialize gpio /dev interface\n");
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:
4260 +#ifdef CONFIG_GPIO_DEV
4262 +/* Gang allocators and accessors; used by the GPIO /dev driver */
4263 +int at32_gpio_port_is_valid(unsigned int port)
4265 + return port < MAX_NR_PIO_DEVICES && pio_dev[port].regs != NULL;
4268 +int at32_select_gpio_pins(unsigned int port, u32 pins, u32 oe_mask)
4270 + struct pio_device *pio;
4273 + pio = &pio_dev[port];
4274 + BUG_ON(port > ARRAY_SIZE(pio_dev) || !pio->regs || (oe_mask & ~pins));
4276 + /* Try to allocate the pins */
4278 + old = pio->pinmux_mask;
4283 + } while (cmpxchg(&pio->pinmux_mask, old, new) != old);
4285 + /* That went well, now configure the port */
4286 + pio_writel(pio, OER, oe_mask);
4287 + pio_writel(pio, PER, pins);
4292 +void at32_deselect_pins(unsigned int port, u32 pins)
4294 + struct pio_device *pio;
4297 + pio = &pio_dev[port];
4298 + BUG_ON(port > ARRAY_SIZE(pio_dev) || !pio->regs);
4300 + /* Return to a "safe" mux configuration */
4301 + pio_writel(pio, PUER, pins);
4302 + pio_writel(pio, ODR, pins);
4304 + /* Deallocate the pins */
4306 + old = pio->pinmux_mask;
4307 + new = old & ~pins;
4308 + } while (cmpxchg(&pio->pinmux_mask, old, new) != old);
4311 +u32 at32_gpio_get_value_multiple(unsigned int port, u32 pins)
4313 + struct pio_device *pio;
4315 + pio = &pio_dev[port];
4316 + BUG_ON(port > ARRAY_SIZE(pio_dev) || !pio->regs);
4318 + return pio_readl(pio, PDSR) & pins;
4321 +void at32_gpio_set_value_multiple(unsigned int port, u32 value, u32 mask)
4323 + struct pio_device *pio;
4325 + pio = &pio_dev[port];
4326 + BUG_ON(port > ARRAY_SIZE(pio_dev) || !pio->regs);
4328 + /* No atomic updates for now... */
4329 + pio_writel(pio, CODR, ~value & mask);
4330 + pio_writel(pio, SODR, value & mask);
4333 +#endif /* CONFIG_GPIO_DEV */
4336 /*--------------------------------------------------------------------------*/
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
4343 +++ b/arch/avr32/mach-at32ap/pm.h
4346 + * Register definitions for the Power Manager (PM)
4348 +#ifndef __ARCH_AVR32_MACH_AT32AP_PM_H__
4349 +#define __ARCH_AVR32_MACH_AT32AP_PM_H__
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
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
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
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
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
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
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))
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)
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
4464 - * Register definitions for SM
4468 -#ifndef __ASM_AVR32_SM_H__
4469 -#define __ASM_AVR32_SM_H__
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
4512 -/* Bitfields in PM_MCCTRL */
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
4532 -/* Bitfields in PM_CPU_MASK */
4534 -/* Bitfields in PM_HSB_MASK */
4536 -/* Bitfields in PM_PBA_MASK */
4538 -/* Bitfields in PM_PBB_MASK */
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
4556 -/* Bitfields in PM_PLL1 */
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
4564 -/* Bitfields in PM_VMREF */
4565 -#define SM_REFSEL_OFFSET 0
4566 -#define SM_REFSEL_SIZE 4
4568 -/* Bitfields in PM_VMV */
4569 -#define SM_PM_VMV_VAL_OFFSET 0
4570 -#define SM_PM_VMV_VAL_SIZE 8
4572 -/* Bitfields in PM_IER */
4574 -/* Bitfields in PM_IDR */
4576 -/* Bitfields in PM_IMR */
4578 -/* Bitfields in PM_ISR */
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
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
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
4618 -/* Bitfields in RTC_VAL */
4619 -#define SM_RTC_VAL_VAL_OFFSET 0
4620 -#define SM_RTC_VAL_VAL_SIZE 31
4622 -/* Bitfields in RTC_TOP */
4623 -#define SM_RTC_TOP_VAL_OFFSET 0
4624 -#define SM_RTC_TOP_VAL_SIZE 32
4626 -/* Bitfields in RTC_IER */
4628 -/* Bitfields in RTC_IDR */
4630 -/* Bitfields in RTC_IMR */
4632 -/* Bitfields in RTC_ISR */
4634 -/* Bitfields in RTC_ICR */
4635 -#define SM_TOPI_OFFSET 0
4636 -#define SM_TOPI_SIZE 1
4638 -/* Bitfields in WDT_CTRL */
4639 -#define SM_KEY_OFFSET 24
4640 -#define SM_KEY_SIZE 8
4642 -/* Bitfields in WDT_CLR */
4644 -/* Bitfields in WDT_EXT */
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
4660 -/* Bitfields in EIM_IER */
4662 -/* Bitfields in EIM_IDR */
4664 -/* Bitfields in EIM_IMR */
4666 -/* Bitfields in EIM_ISR */
4668 -/* Bitfields in EIM_ICR */
4670 -/* Bitfields in EIM_MODE */
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
4682 -/* Bitfields in EIM_LEVEL */
4684 -/* Bitfields in EIM_TEST */
4685 -#define SM_TESTEN_OFFSET 31
4686 -#define SM_TESTEN_SIZE 1
4688 -/* Bitfields in EIM_NMIC */
4689 -#define SM_EN_OFFSET 0
4690 -#define SM_EN_SIZE 1
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))
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)
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;
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);
4720 size = PAGE_ALIGN(size);
4721 order = get_order(size);
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
4729 Say N if you are unsure.
4731 +# AVR32 Architecture
4733 +config AT32AP700X_WDT
4734 + tristate "AT32AP700x watchdog"
4735 + depends on WATCHDOG && CPU_AT32AP7000
4737 + Watchdog timer embedded into AT32AP700x devices. This will reboot
4738 + your system when the timeout is reached.
4740 +config AT32AP700X_WDT_TIMEOUT
4741 + int "Timeout value for AT32AP700x watchdog"
4742 + depends on AT32AP700X_WDT
4746 + Sets the timeout value for the watchdog in AT32AP700x devices.
4747 + Limited by hardware to be 1 or 2 seconds.
4749 + Set to 2 seconds by default.
4751 # X86 (i386 + ia64 + x86_64) Architecture
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
4762 +# AVR32 Architecture
4763 +obj-$(CONFIG_AT32AP700X_WDT) += at32ap700x_wdt.o
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
4772 +++ b/drivers/char/watchdog/at32ap700x_wdt.c
4775 + * Watchdog driver for Atmel AT32AP700X devices
4777 + * Copyright (C) 2005-2006 Atmel Corporation
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.
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>
4795 +#define TIMEOUT_MIN 1
4796 +#define TIMEOUT_DEFAULT CONFIG_AT32AP700X_WDT_TIMEOUT
4797 +#define TIMEOUT_MAX 2
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
4805 +#define WDT_CLR 0x04
4807 +#define WDT_BIT(name) (1 << WDT_##name)
4808 +#define WDT_BF(name,value) ((value) << WDT_##name)
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)
4815 +struct wdt_at32ap700x {
4816 + void __iomem *regs;
4819 + struct miscdevice miscdev;
4822 +static struct wdt_at32ap700x *wdt;
4825 + * Disable the watchdog.
4827 +static void inline at32_wdt_stop(void)
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));
4835 + * Enable and reset the watchdog.
4837 +static void inline at32_wdt_start(void)
4839 + /* 0xf is 2^16 divider = 2 sec, 0xe is 2^15 divider = 1 sec */
4840 + unsigned long psel = (wdt->timeout > 1) ? 0xf : 0xe;
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));
4851 + * Pat the watchdog timer.
4853 +static void inline at32_wdt_pat(void)
4855 + wdt_writel(wdt, CLR, 0x42);
4859 + * Watchdog device is opened, and watchdog starts running.
4861 +static int at32_wdt_open(struct inode *inode, struct file *file)
4863 + if (test_and_set_bit(1, &wdt->users))
4867 + return nonseekable_open(inode, file);
4871 + * Close the watchdog device. If CONFIG_WATCHDOG_NOWAYOUT is _not_ defined then
4872 + * the watchdog is also disabled.
4874 +static int at32_wdt_close(struct inode *inode, struct file *file)
4876 +#ifndef CONFIG_WATCHDOG_NOWAYOUT
4879 + clear_bit(1, &wdt->users);
4884 + * Change the watchdog time interval.
4886 +static int at32_wdt_settimeout(int time)
4889 + * All counting occurs at 1 / SLOW_CLOCK (32 kHz) and max prescaler is
4890 + * 2 ^ 16 allowing up to 2 seconds timeout.
4892 + if ((time < TIMEOUT_MIN) || (time > TIMEOUT_MAX))
4896 + * Set new watchdog time. It will be used when at32_wdt_start() is
4899 + wdt->timeout = time;
4903 +static struct watchdog_info at32_wdt_info = {
4904 + .identity = "at32ap700x watchdog",
4905 + .options = WDIOF_SETTIMEOUT | WDIOF_KEEPALIVEPING,
4909 + * Handle commands from user-space.
4911 +static int at32_wdt_ioctl(struct inode *inode, struct file *file,
4912 + unsigned int cmd, unsigned long arg)
4914 + int ret = -ENOTTY;
4916 + void __user *argp = (void __user *)arg;
4917 + int __user *p = argp;
4920 + case WDIOC_KEEPALIVE:
4924 + case WDIOC_GETSUPPORT:
4925 + ret = copy_to_user(argp, &at32_wdt_info,
4926 + sizeof(at32_wdt_info)) ? -EFAULT : 0;
4928 + case WDIOC_SETTIMEOUT:
4929 + ret = get_user(time, p);
4932 + ret = at32_wdt_settimeout(time);
4935 + /* Enable new time value */
4937 + /* fall through */
4938 + case WDIOC_GETTIMEOUT:
4939 + ret = put_user(wdt->timeout, p);
4941 + case WDIOC_GETSTATUS: /* fall through */
4942 + case WDIOC_GETBOOTSTATUS:
4943 + ret = put_user(0, p);
4945 + case WDIOC_SETOPTIONS:
4946 + ret = get_user(time, p);
4949 + if (time & WDIOS_DISABLECARD)
4951 + if (time & WDIOS_ENABLECARD)
4960 +static ssize_t at32_wdt_write(struct file *file, const char *data, size_t len,
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,
4976 +static int __init at32_wdt_probe(struct platform_device *pdev)
4978 + struct resource *regs;
4982 + dev_dbg(&pdev->dev, "only 1 wdt instance supported.\n");
4986 + regs = platform_get_resource(pdev, IORESOURCE_MEM, 0);
4988 + dev_dbg(&pdev->dev, "missing mmio resource\n");
4992 + wdt = kzalloc(sizeof(struct wdt_at32ap700x), GFP_KERNEL);
4994 + dev_dbg(&pdev->dev, "no memory for wdt structure\n");
4998 + wdt->regs = ioremap(regs->start, regs->end - regs->start + 1);
5001 + dev_dbg(&pdev->dev, "could not map I/O memory\n");
5005 + wdt->miscdev.minor = WATCHDOG_MINOR;
5006 + wdt->miscdev.name = "watchdog";
5007 + wdt->miscdev.fops = &at32_wdt_fops;
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",
5016 + ret = misc_register(&wdt->miscdev);
5018 + dev_dbg(&pdev->dev, "failed to register wdt miscdev\n");
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);
5029 + iounmap(wdt->regs);
5036 +static int __exit at32_wdt_remove(struct platform_device *pdev)
5038 + if (wdt && platform_get_drvdata(pdev) == wdt) {
5039 + misc_deregister(&wdt->miscdev);
5040 + iounmap(wdt->regs);
5043 + platform_set_drvdata(pdev, NULL);
5049 +static void at32_wdt_shutdown(struct platform_device *pdev)
5055 +static int at32_wdt_suspend(struct platform_device *pdev, pm_message_t message)
5061 +static int at32_wdt_resume(struct platform_device *pdev)
5068 +#define at32_wdt_suspend NULL
5069 +#define at32_wdt_resume NULL
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,
5077 + .name = "at32_wdt",
5078 + .owner = THIS_MODULE,
5080 + .shutdown = at32_wdt_shutdown,
5083 +static int __init at32_wdt_init(void)
5085 + return platform_driver_probe(&at32_wdt_driver, at32_wdt_probe);
5087 +module_init(at32_wdt_init);
5089 +static void __exit at32_wdt_exit(void)
5091 + platform_driver_unregister(&at32_wdt_driver);
5093 +module_exit(at32_wdt_exit);
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
5105 menu "I2C Hardware Bus support"
5107 +config I2C_ATMELTWI
5108 + tristate "Atmel TWI/I2C"
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
5116 +config I2C_ATMELTWI_BAUDRATE
5117 + prompt "Atmel TWI baudrate"
5118 + depends on I2C_ATMELTWI
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
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
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
5146 +++ b/drivers/i2c/busses/atmeltwi.h
5149 + * Register definitions for the Atmel Two-Wire Interface
5152 +#ifndef __ASM_AVR32_TWI_H__
5153 +#define __ASM_AVR32_TWI_H__
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
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
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
5192 +/* Bitfields in SMR */
5193 +#define TWI_SADR_OFFSET 16
5194 +#define TWI_SADR_SIZE 7
5196 +/* Bitfields in IADR */
5197 +#define TWI_IADR_OFFSET 0
5198 +#define TWI_IADR_SIZE 24
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
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
5230 +/* Bitfields in RHR */
5231 +#define TWI_RXDATA_OFFSET 0
5232 +#define TWI_RXDATA_SIZE 8
5234 +/* Bitfields in THR */
5235 +#define TWI_TXDATA_OFFSET 0
5236 +#define TWI_TXDATA_SIZE 8
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
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))
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)
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
5269 +++ b/drivers/i2c/busses/i2c-atmeltwi.c
5272 + * i2c Support for Atmel's Two-Wire Interface (TWI)
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>
5279 + * Copyright (C) 2006 Atmel Corporation
5281 + * Borrowed heavily from the original work by:
5282 + * Copyright (C) 2000 Philip Edelbrock <phil at stimpy.netroedge.com>
5284 + * Partialy rewriten by Karel Hojdar <cmkaho at seznam.cz>
5285 + * bugs removed, interrupt routine markedly rewritten
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.
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"
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");
5317 + void __iomem *regs;
5318 + struct i2c_adapter adapter;
5321 + struct completion comp;
5330 +#define to_atmel_twi(adap) container_of(adap, struct atmel_twi, adapter)
5333 + * Initialize the TWI hardware registers.
5335 +static int __devinit twi_hwinit(struct atmel_twi *twi)
5337 + unsigned long cdiv, ckdiv=0;
5339 + twi_writel(twi, IDR, ~0UL);
5340 + twi_writel(twi, CR, TWI_BIT(SWRST)); /*Reset peripheral*/
5341 + twi_readl(twi, SR);
5343 + cdiv = (clk_get_rate(twi->pclk) / (2 * baudrate)) - 4;
5345 + while (cdiv > 255) {
5353 + twi_writel(twi, CWGR, (TWI_BF(CKDIV, ckdiv)
5354 + | TWI_BF(CHDIV, cdiv)
5355 + | TWI_BF(CLDIV, cdiv)));
5360 + * Waits for the i2c status register to set the specified bitmask
5361 + * Returns 0 if timed out (~100ms).
5363 +static short twi_complete(struct atmel_twi *twi, u32 mask)
5365 + int timeout = msecs_to_jiffies(100);
5367 + twi->intmask = mask;
5368 + init_completion(&twi->comp);
5370 + twi_writel(twi, IER, mask);
5372 + if (!wait_for_completion_timeout(&twi->comp, timeout)) {
5373 + /* RESET TWI interface */
5374 + twi_writel(twi, CR, TWI_BIT(SWRST));
5376 + /* Reinitialize TWI */
5379 + return -ETIMEDOUT;
5385 + * Generic i2c master transfer entrypoint.
5387 +static int twi_xfer(struct i2c_adapter *adap, struct i2c_msg msgs[], int num)
5389 + struct atmel_twi *twi = to_atmel_twi(adap);
5390 + struct i2c_msg *pmsg;
5393 + /* get first message */
5396 + dev_dbg(&adap->dev, "twi_xfer: processing %d messages:\n", num);
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));
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);
5413 + twi_writel(twi, CR, TWI_BIT(MSEN));
5415 + if (pmsg->flags & I2C_M_RD) {
5416 + if (twi->len == 1)
5417 + twi_writel(twi, CR,
5418 + TWI_BIT(START) | TWI_BIT(STOP));
5420 + twi_writel(twi, CR, TWI_BIT(START));
5422 + if (twi_complete(twi, TWI_BIT(RXRDY)) == -ETIMEDOUT) {
5423 + dev_dbg(&adap->dev, "RXRDY timeout. Stopped with %d bytes left\n",
5425 + return -ETIMEDOUT;
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",
5432 + return -ETIMEDOUT;
5439 + /* Disable TWI interface */
5440 + twi_writel(twi, CR, TWI_BIT(MSDIS));
5442 + } /* end cur msg */
5448 +static irqreturn_t twi_interrupt(int irq, void *dev_id)
5450 + struct atmel_twi *twi = dev_id;
5451 + int status = twi_readl(twi, SR);
5453 + /* Save state for later debug prints */
5454 + int old_mask = twi->intmask;
5455 + int old_status = status;
5457 + if (twi->intmask & status) {
5458 + if (status & TWI_BIT(NACK))
5461 + status &= twi->intmask;
5463 + if (status & TWI_BIT(TXCOMP))
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);
5472 + if ( twi->acks_left == 1 )
5473 + twi_writel(twi, CR, TWI_BIT(STOP));
5475 + if (twi->acks_left == 0 ) {
5476 + twi->intmask = TWI_BIT(TXCOMP);
5477 + twi_writel(twi, IER, TWI_BIT(TXCOMP));
5479 + } else if (status & TWI_BIT(TXRDY)) {
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]);
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);
5493 + return IRQ_HANDLED;
5496 + dev_dbg(&twi->adapter.dev, "NACK received!\n");
5500 + twi_writel(twi, IDR, ~0UL);
5501 + complete(&twi->comp);
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);
5508 + return IRQ_HANDLED;
5513 + * Return list of supported functionality.
5515 +static u32 twi_func(struct i2c_adapter *adapter)
5517 + return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL;
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,
5527 + * Main initialization routine.
5529 +static int __devinit twi_probe(struct platform_device *pdev)
5531 + struct atmel_twi *twi;
5532 + struct resource *regs;
5534 + struct i2c_adapter *adapter;
5537 + regs = platform_get_resource(pdev, IORESOURCE_MEM, 0);
5541 + pclk = clk_get(&pdev->dev, "pclk");
5543 + return PTR_ERR(pclk);
5547 + twi = kzalloc(sizeof(struct atmel_twi), GFP_KERNEL);
5549 + dev_err(&pdev->dev, "can't allocate interface!\n");
5550 + goto err_alloc_twi;
5554 + twi->regs = ioremap(regs->start, regs->end - regs->start + 1);
5558 + irq = platform_get_irq(pdev,0);
5559 + rc = request_irq(irq, twi_interrupt, 0, "twi", twi);
5561 + dev_err(&pdev->dev, "can't bind irq!\n");
5566 + rc = twi_hwinit(twi);
5568 + dev_err(&pdev->dev, "Unable to set baudrate\n");
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;
5578 + platform_set_drvdata(pdev, twi);
5580 + rc = i2c_add_adapter(adapter);
5582 + dev_err(&pdev->dev, "Adapter %s registration failed\n",
5584 + goto err_register;
5587 + dev_info(&pdev->dev, "Atmel TWI i2c bus device (baudrate %dk) at 0x%08lx.\n",
5588 + baudrate/1000, (unsigned long)regs->start);
5594 + platform_set_drvdata(pdev, NULL);
5597 + free_irq(irq, twi);
5600 + iounmap(twi->regs);
5606 + clk_disable(pclk);
5612 +static int __devexit twi_remove(struct platform_device *pdev)
5614 + struct atmel_twi *twi = platform_get_drvdata(pdev);
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);
5629 +static struct platform_driver twi_driver = {
5630 + .probe = twi_probe,
5631 + .remove = __devexit_p(twi_remove),
5633 + .name = "atmel_twi",
5634 + .owner = THIS_MODULE,
5638 +static int __init atmel_twi_init(void)
5640 + return platform_driver_register(&twi_driver);
5643 +static void __exit atmel_twi_exit(void)
5645 + platform_driver_unregister(&twi_driver);
5648 +module_init(atmel_twi_init);
5649 +module_exit(atmel_twi_exit);
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
5660 Say Y here to support HIL pointers.
5663 + tristate "GPIO mouse"
5664 + depends on GENERIC_GPIO
5665 + select INPUT_POLLDEV
5667 + This driver simulates a mouse on GPIO lines of various CPUs (and some
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
5675 + To compile this driver as a module, choose M here: the
5676 + module will be called gpio_mouse.
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
5689 psmouse-objs := psmouse-base.o synaptics.o
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
5695 +++ b/drivers/input/mouse/gpio_mouse.c
5698 + * Driver for simulating a mouse on GPIO lines.
5700 + * Copyright (C) 2007 Atmel Corporation
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.
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>
5714 +#include <asm/gpio.h>
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.
5720 +static void gpio_mouse_scan(struct input_polled_dev *dev)
5722 + struct gpio_mouse_platform_data *gpio = dev->private;
5723 + struct input_dev *input = dev->input;
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);
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);
5741 + input_report_rel(input, REL_X, x);
5742 + input_report_rel(input, REL_Y, y);
5743 + input_sync(input);
5746 +static int __init gpio_mouse_probe(struct platform_device *pdev)
5748 + struct gpio_mouse_platform_data *pdata = pdev->dev.platform_data;
5749 + struct input_polled_dev *input_poll;
5750 + struct input_dev *input;
5755 + dev_err(&pdev->dev, "no platform data\n");
5760 + if (pdata->scan_ms < 0) {
5761 + dev_err(&pdev->dev, "invalid scan time\n");
5766 + for (i = 0; i < GPIO_MOUSE_PIN_MAX; i++) {
5767 + pin = pdata->pins[i];
5771 + if (i <= GPIO_MOUSE_PIN_RIGHT) {
5772 + /* Mouse direction is required. */
5773 + dev_err(&pdev->dev,
5774 + "missing GPIO for directions\n");
5776 + goto out_free_gpios;
5779 + if (i == GPIO_MOUSE_PIN_BLEFT)
5780 + dev_dbg(&pdev->dev, "no left button defined\n");
5783 + error = gpio_request(pin, "gpio_mouse");
5785 + dev_err(&pdev->dev, "fail %d pin (%d idx)\n",
5787 + goto out_free_gpios;
5790 + gpio_direction_input(pin);
5794 + input_poll = input_allocate_polled_device();
5795 + if (!input_poll) {
5796 + dev_err(&pdev->dev, "not enough memory for input device\n");
5798 + goto out_free_gpios;
5801 + platform_set_drvdata(pdev, input_poll);
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;
5808 + input = input_poll->input;
5809 + input->name = pdev->name;
5810 + input->id.bustype = BUS_HOST;
5811 + input->dev.parent = &pdev->dev;
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);
5822 + error = input_register_polled_device(input_poll);
5824 + dev_err(&pdev->dev, "could not register input device\n");
5825 + goto out_free_polldev;
5828 + dev_dbg(&pdev->dev, "%d ms scan time, buttons: %s%s%s\n",
5830 + pdata->bleft < 0 ? "" : "left ",
5831 + pdata->bmiddle < 0 ? "" : "middle ",
5832 + pdata->bright < 0 ? "" : "right");
5837 + input_free_polled_device(input_poll);
5838 + platform_set_drvdata(pdev, NULL);
5841 + while (--i >= 0) {
5842 + pin = pdata->pins[i];
5850 +static int __devexit gpio_mouse_remove(struct platform_device *pdev)
5852 + struct input_polled_dev *input = platform_get_drvdata(pdev);
5853 + struct gpio_mouse_platform_data *pdata = input->private;
5856 + input_unregister_polled_device(input);
5857 + input_free_polled_device(input);
5859 + for (i = 0; i < GPIO_MOUSE_PIN_MAX; i++) {
5860 + pin = pdata->pins[i];
5865 + platform_set_drvdata(pdev, NULL);
5870 +struct platform_driver gpio_mouse_device_driver = {
5871 + .remove = __devexit_p(gpio_mouse_remove),
5873 + .name = "gpio_mouse",
5877 +static int __init gpio_mouse_init(void)
5879 + return platform_driver_probe(&gpio_mouse_device_driver,
5880 + gpio_mouse_probe);
5882 +module_init(gpio_mouse_init);
5884 +static void __exit gpio_mouse_exit(void)
5886 + platform_driver_unregister(&gpio_mouse_device_driver);
5888 +module_exit(gpio_mouse_exit);
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
5899 This option enables support for the front LED on Cobalt Server
5902 + tristate "LED Support for GPIO connected LEDs"
5903 + depends on LEDS_CLASS && GENERIC_GPIO
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.
5909 comment "LED Triggers"
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
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
5928 +++ b/drivers/leds/leds-gpio.c
5931 + * LEDs driver for GPIOs
5933 + * Copyright (C) 2007 8D Technologies inc.
5934 + * Raphael Assenat <raph@8d.com>
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.
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>
5947 +#include <asm/gpio.h>
5949 +struct gpio_led_data {
5950 + struct led_classdev cdev;
5952 + struct work_struct work;
5958 +static void gpio_led_work(struct work_struct *work)
5960 + struct gpio_led_data *led_dat =
5961 + container_of(work, struct gpio_led_data, work);
5963 + gpio_set_value_cansleep(led_dat->gpio, led_dat->new_level);
5966 +static void gpio_led_set(struct led_classdev *led_cdev,
5967 + enum led_brightness value)
5969 + struct gpio_led_data *led_dat =
5970 + container_of(led_cdev, struct gpio_led_data, cdev);
5973 + if (value == LED_OFF)
5978 + if (led_dat->active_low)
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);
5987 + gpio_set_value_cansleep(led_dat->gpio, level);
5989 + gpio_set_value(led_dat->gpio, level);
5992 +static int __init gpio_led_probe(struct platform_device *pdev)
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;
6002 + leds_data = kzalloc(sizeof(struct gpio_led_data) * pdata->num_leds,
6007 + for (i = 0; i < pdata->num_leds; i++) {
6008 + cur_led = &pdata->leds[i];
6009 + led_dat = &leds_data[i];
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;
6019 + ret = gpio_request(led_dat->gpio, led_dat->cdev.name);
6023 + gpio_direction_output(led_dat->gpio, led_dat->active_low);
6025 + ret = led_classdev_register(&pdev->dev, &led_dat->cdev);
6027 + gpio_free(led_dat->gpio);
6031 + INIT_WORK(&led_dat->work, gpio_led_work);
6034 + platform_set_drvdata(pdev, leds_data);
6040 + for (i = i - 1; i >= 0; i--) {
6041 + led_classdev_unregister(&leds_data[i].cdev);
6042 + gpio_free(leds_data[i].gpio);
6046 + flush_scheduled_work();
6052 +static int __exit gpio_led_remove(struct platform_device *pdev)
6055 + struct gpio_led_platform_data *pdata = pdev->dev.platform_data;
6056 + struct gpio_led_data *leds_data;
6058 + leds_data = platform_get_drvdata(pdev);
6060 + for (i = 0; i < pdata->num_leds; i++) {
6061 + led_classdev_unregister(&leds_data[i].cdev);
6062 + gpio_free(leds_data[i].gpio);
6071 +static int gpio_led_suspend(struct platform_device *pdev, pm_message_t state)
6073 + struct gpio_led_platform_data *pdata = pdev->dev.platform_data;
6074 + struct gpio_led_data *leds_data;
6077 + leds_data = platform_get_drvdata(pdev);
6079 + for (i = 0; i < pdata->num_leds; i++)
6080 + led_classdev_suspend(&leds_data[i].cdev);
6085 +static int gpio_led_resume(struct platform_device *pdev)
6087 + struct gpio_led_platform_data *pdata = pdev->dev.platform_data;
6088 + struct gpio_led_data *leds_data;
6091 + leds_data = platform_get_drvdata(pdev);
6093 + for (i = 0; i < pdata->num_leds; i++)
6094 + led_classdev_resume(&leds_data[i].cdev);
6099 +#define gpio_led_suspend NULL
6100 +#define gpio_led_resume NULL
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,
6108 + .name = "leds-gpio",
6109 + .owner = THIS_MODULE,
6113 +static int __init gpio_led_init(void)
6115 + return platform_driver_probe(&gpio_led_driver, gpio_led_probe);
6118 +static void __exit gpio_led_exit(void)
6120 + platform_driver_unregister(&gpio_led_driver);
6123 +module_init(gpio_led_init);
6124 +module_exit(gpio_led_exit);
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
6135 If you are not sure, say Y here.
6138 + tristate "Device driver for Atmel SSC peripheral"
6139 + depends on AVR32 || ARCH_AT91
6141 + This option enables device driver support for Atmel Syncronized
6142 + Serial Communication peripheral (SSC).
6144 + The SSC peripheral supports a wide variety of serial frame based
6145 + communications, i.e. I2S, SPI, etc.
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
6162 +++ b/drivers/misc/atmel-ssc.c
6165 + * Atmel SSC driver
6167 + * Copyright (C) 2007 Atmel Corporation
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.
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>
6183 +/* Serialize access to ssc_list and user count */
6184 +static DEFINE_SPINLOCK(user_lock);
6185 +static LIST_HEAD(ssc_list);
6187 +struct ssc_device *ssc_request(unsigned int ssc_num)
6189 + int ssc_valid = 0;
6190 + struct ssc_device *ssc;
6192 + spin_lock(&user_lock);
6193 + list_for_each_entry(ssc, &ssc_list, list) {
6194 + if (ssc->pdev->id == ssc_num) {
6201 + spin_unlock(&user_lock);
6202 + dev_dbg(&ssc->pdev->dev, "could not find requested device\n");
6203 + return ERR_PTR(-ENODEV);
6207 + spin_unlock(&user_lock);
6208 + dev_dbg(&ssc->pdev->dev, "module busy\n");
6209 + return ERR_PTR(-EBUSY);
6212 + spin_unlock(&user_lock);
6214 + clk_enable(ssc->clk);
6218 +EXPORT_SYMBOL(ssc_request);
6220 +void ssc_free(struct ssc_device *ssc)
6222 + spin_lock(&user_lock);
6225 + clk_disable(ssc->clk);
6227 + dev_dbg(&ssc->pdev->dev, "device already free\n");
6229 + spin_unlock(&user_lock);
6231 +EXPORT_SYMBOL(ssc_free);
6233 +static int __init ssc_probe(struct platform_device *pdev)
6236 + struct resource *regs;
6237 + struct ssc_device *ssc;
6239 + ssc = kzalloc(sizeof(struct ssc_device), GFP_KERNEL);
6241 + dev_dbg(&pdev->dev, "out of memory\n");
6246 + regs = platform_get_resource(pdev, IORESOURCE_MEM, 0);
6248 + dev_dbg(&pdev->dev, "no mmio resource defined\n");
6253 + ssc->clk = clk_get(&pdev->dev, "pclk");
6254 + if (IS_ERR(ssc->clk)) {
6255 + dev_dbg(&pdev->dev, "no pclk clock defined\n");
6261 + ssc->regs = ioremap(regs->start, regs->end - regs->start + 1);
6263 + dev_dbg(&pdev->dev, "ioremap failed\n");
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);
6274 + ssc->irq = platform_get_irq(pdev, 0);
6276 + dev_dbg(&pdev->dev, "could not get irq\n");
6281 + spin_lock(&user_lock);
6282 + list_add_tail(&ssc->list, &ssc_list);
6283 + spin_unlock(&user_lock);
6285 + platform_set_drvdata(pdev, ssc);
6287 + dev_info(&pdev->dev, "Atmel SSC device at 0x%p (irq %d)\n",
6288 + ssc->regs, ssc->irq);
6293 + iounmap(ssc->regs);
6295 + clk_put(ssc->clk);
6302 +static int __devexit ssc_remove(struct platform_device *pdev)
6304 + struct ssc_device *ssc = platform_get_drvdata(pdev);
6306 + spin_lock(&user_lock);
6307 + iounmap(ssc->regs);
6308 + clk_put(ssc->clk);
6309 + list_del(&ssc->list);
6311 + spin_unlock(&user_lock);
6316 +static struct platform_driver ssc_driver = {
6317 + .remove = __devexit_p(ssc_remove),
6323 +static int __init ssc_init(void)
6325 + return platform_driver_probe(&ssc_driver, ssc_probe);
6327 +module_init(ssc_init);
6329 +static void __exit ssc_exit(void)
6331 + platform_driver_unregister(&ssc_driver);
6333 +module_exit(ssc_exit);
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
6346 +config MMC_ATMELMCI
6347 + tristate "Atmel Multimedia Card Interface support"
6348 + depends on AVR32 && MMC
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.
6357 tristate "Motorola i.MX Multimedia Card Interface support"
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
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
6374 +++ b/drivers/mmc/host/atmel-mci.c
6377 + * Atmel MultiMedia Card Interface driver
6379 + * Copyright (C) 2004-2006 Atmel Corporation
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.
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>
6395 +#include <linux/mmc/host.h>
6397 +#include <asm/dma-controller.h>
6398 +#include <asm/io.h>
6399 +#include <asm/arch/board.h>
6400 +#include <asm/arch/gpio.h>
6402 +#include "atmel-mci.h"
6404 +#define DRIVER_NAME "atmel_mci"
6406 +#define MCI_CMD_ERROR_FLAGS (MCI_BIT(RINDE) | MCI_BIT(RDIRE) | \
6407 + MCI_BIT(RCRCE) | MCI_BIT(RENDE) | \
6409 +#define MCI_DATA_ERROR_FLAGS (MCI_BIT(DCRCE) | MCI_BIT(DTOE) | \
6410 + MCI_BIT(OVRE) | MCI_BIT(UNRE))
6413 + EVENT_CMD_COMPLETE = 0,
6415 + EVENT_DATA_COMPLETE,
6418 + EVENT_STOP_COMPLETE,
6421 + EVENT_CARD_DETECT,
6424 +struct atmel_mci_dma {
6425 + struct dma_request_sg req;
6426 + unsigned short rx_periph_id;
6427 + unsigned short tx_periph_id;
6431 + struct mmc_host *mmc;
6432 + void __iomem *regs;
6433 + struct atmel_mci_dma dma;
6435 + struct mmc_request *mrq;
6436 + struct mmc_command *cmd;
6437 + struct mmc_data *data;
6442 + struct tasklet_struct tasklet;
6443 + unsigned long pending_events;
6444 + unsigned long completed_events;
6451 + unsigned long bus_hz;
6452 + unsigned long mapbase;
6454 + struct platform_device *pdev;
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;
6465 +/* Those printks take an awful lot of time... */
6467 +static unsigned int fmax = 15000000U;
6469 +static unsigned int fmax = 1000000U;
6471 +module_param(fmax, uint, 0444);
6472 +MODULE_PARM_DESC(fmax, "Max frequency in Hz of the MMC bus clock");
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)
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)
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)
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)
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)
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)
6595 +#ifdef CONFIG_DEBUG_FS
6596 +#include <linux/debugfs.h>
6598 +#define DBG_REQ_BUF_SIZE (4096 - sizeof(unsigned int))
6600 +struct req_dbg_data {
6601 + unsigned int nbytes;
6602 + char str[DBG_REQ_BUF_SIZE];
6605 +static int req_dbg_open(struct inode *inode, struct file *file)
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;
6613 + unsigned long n = 0;
6615 + priv = kzalloc(DBG_REQ_BUF_SIZE, GFP_KERNEL);
6620 + mutex_lock(&inode->i_mutex);
6621 + host = inode->i_private;
6623 + spin_lock_irq(&host->mmc->lock);
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,
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],
6648 + spin_unlock_irq(&host->mmc->lock);
6649 + mutex_unlock(&inode->i_mutex);
6651 + priv->nbytes = min(n, DBG_REQ_BUF_SIZE);
6652 + file->private_data = priv;
6657 +static ssize_t req_dbg_read(struct file *file, char __user *buf,
6658 + size_t nbytes, loff_t *ppos)
6660 + struct req_dbg_data *priv = file->private_data;
6662 + return simple_read_from_buffer(buf, nbytes, ppos,
6663 + priv->str, priv->nbytes);
6666 +static int req_dbg_release(struct inode *inode, struct file *file)
6668 + kfree(file->private_data);
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,
6680 +static int regs_dbg_open(struct inode *inode, struct file *file)
6682 + struct atmel_mci *host;
6685 + int ret = -ENOMEM;
6687 + mutex_lock(&inode->i_mutex);
6688 + host = inode->i_private;
6689 + data = kmalloc(inode->i_size, GFP_KERNEL);
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);
6698 + file->private_data = data;
6702 + mutex_unlock(&inode->i_mutex);
6707 +static ssize_t regs_dbg_read(struct file *file, char __user *buf,
6708 + size_t nbytes, loff_t *ppos)
6710 + struct inode *inode = file->f_dentry->d_inode;
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);
6722 +static int regs_dbg_release(struct inode *inode, struct file *file)
6724 + kfree(file->private_data);
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,
6736 +static void atmci_init_debugfs(struct atmel_mci *host)
6738 + struct mmc_host *mmc;
6739 + struct dentry *root, *regs;
6740 + struct resource *res;
6743 + root = debugfs_create_dir(mmc_hostname(mmc), NULL);
6744 + if (IS_ERR(root) || !root)
6746 + host->debugfs_root = root;
6748 + regs = debugfs_create_file("regs", 0400, root, host, ®s_dbg_fops);
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;
6756 + host->debugfs_req = debugfs_create_file("req", 0400, root,
6757 + host, &req_dbg_fops);
6758 + if (!host->debugfs_req)
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;
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;
6775 +err_completed_events:
6776 + debugfs_remove(host->debugfs_pending_events);
6777 +err_pending_events:
6778 + debugfs_remove(host->debugfs_req);
6780 + debugfs_remove(host->debugfs_regs);
6782 + debugfs_remove(host->debugfs_root);
6784 + host->debugfs_root = NULL;
6785 + dev_err(&host->pdev->dev,
6786 + "failed to initialize debugfs for %s\n",
6787 + mmc_hostname(mmc));
6790 +static void atmci_cleanup_debugfs(struct atmel_mci *host)
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;
6802 +static inline void atmci_init_debugfs(struct atmel_mci *host)
6807 +static inline void atmci_cleanup_debugfs(struct atmel_mci *host)
6811 +#endif /* CONFIG_DEBUG_FS */
6813 +static inline unsigned int ns_to_clocks(struct atmel_mci *host,
6816 + return (ns * (host->bus_hz / 1000000) + 999) / 1000;
6819 +static void atmci_set_timeout(struct atmel_mci *host,
6820 + struct mmc_data *data)
6822 + static unsigned dtomul_to_shift[] = {
6823 + 0, 4, 7, 8, 10, 12, 16, 20
6826 + unsigned dtocyc, dtomul;
6828 + timeout = ns_to_clocks(host, data->timeout_ns) + data->timeout_clks;
6830 + for (dtomul = 0; dtomul < 8; dtomul++) {
6831 + unsigned shift = dtomul_to_shift[dtomul];
6832 + dtocyc = (timeout + (1 << shift) - 1) >> shift;
6837 + if (dtomul >= 8) {
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)));
6850 + * Return mask with interrupt flags to be handled for this command.
6852 +static u32 atmci_prepare_command(struct mmc_host *mmc,
6853 + struct mmc_command *cmd,
6859 + cmd->error = MMC_ERR_NONE;
6862 + BUG_ON(MCI_BFEXT(CMDNB, cmdr) != 0);
6863 + cmdr = MCI_BFINS(CMDNB, cmd->opcode, cmdr);
6865 + if (cmd->flags & MMC_RSP_PRESENT) {
6866 + if (cmd->flags & MMC_RSP_136)
6867 + cmdr |= MCI_BF(RSPTYP, MCI_RSPTYP_136_BIT);
6869 + cmdr |= MCI_BF(RSPTYP, MCI_RSPTYP_48_BIT);
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.
6877 + cmdr |= MCI_BIT(MAXLAT);
6879 + if (mmc->ios.bus_mode == MMC_BUSMODE_OPENDRAIN)
6880 + cmdr |= MCI_BIT(OPDCMD);
6882 + iflags = MCI_BIT(CMDRDY) | MCI_CMD_ERROR_FLAGS;
6883 + if (!(cmd->flags & MMC_RSP_CRC))
6884 + iflags &= ~MCI_BIT(RCRCE);
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);
6890 + *cmd_flags = cmdr;
6894 +static void atmci_start_command(struct atmel_mci *host,
6895 + struct mmc_command *cmd,
6898 + WARN_ON(host->cmd);
6901 + mci_writel(host, ARGR, cmd->arg);
6902 + mci_writel(host, CMDR, cmd_flags);
6905 + dma_start_request(host->dma.req.req.dmac,
6906 + host->dma.req.req.channel);
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.
6913 +static u32 atmci_prepare_data(struct mmc_host *mmc, struct mmc_data *data)
6915 + struct atmel_mci *host = mmc_priv(mmc);
6918 + WARN_ON(host->data);
6919 + host->data = data;
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;
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);
6933 + cmd_flags |= MCI_BF(TRTYP, MCI_TRTYP_BLOCK);
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;
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;
6951 + host->dma.req.sg = data->sg;
6953 + dma_prepare_request_sg(host->dma.req.req.dmac, &host->dma.req);
6958 +static void atmci_request(struct mmc_host *mmc, struct mmc_request *mrq)
6960 + struct atmel_mci *host = mmc_priv(mmc);
6961 + struct mmc_data *data = mrq->data;
6965 + iflags = mci_readl(host, IMR);
6967 + printk("WARNING: IMR=0x%08x\n", mci_readl(host, IMR));
6969 + WARN_ON(host->mrq != NULL);
6971 + host->pending_events = 0;
6972 + host->completed_events = 0;
6974 + iflags = atmci_prepare_command(mmc, mrq->cmd, &cmdflags);
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);
6987 + host->stop_cmdr |= MCI_BF(TRTYP, MCI_TRTYP_MULTI_BLOCK);
6990 + cmdflags |= atmci_prepare_data(mmc, data);
6991 + iflags |= MCI_DATA_ERROR_FLAGS;
6994 + atmci_start_command(host, mrq->cmd, cmdflags);
6995 + mci_writel(host, IER, iflags);
6998 +static void atmci_set_ios(struct mmc_host *mmc, struct mmc_ios *ios)
7000 + struct atmel_mci *host = mmc_priv(mmc);
7005 + clkdiv = host->bus_hz / (2 * ios->clock) - 1;
7008 + mci_writel(host, MR, (clkdiv
7009 + | MCI_BIT(WRPROOF)
7010 + | MCI_BIT(RDPROOF)));
7013 + switch (ios->bus_width) {
7014 + case MMC_BUS_WIDTH_1:
7015 + mci_writel(host, SDCR, 0);
7017 + case MMC_BUS_WIDTH_4:
7018 + mci_writel(host, SDCR, MCI_BIT(SDCBUS));
7022 + switch (ios->power_mode) {
7023 + case MMC_POWER_OFF:
7024 + mci_writel(host, CR, MCI_BIT(MCIDIS));
7026 + case MMC_POWER_UP:
7027 + mci_writel(host, CR, MCI_BIT(SWRST));
7029 + case MMC_POWER_ON:
7030 + mci_writel(host, CR, MCI_BIT(MCIEN));
7035 +static int atmci_get_ro(struct mmc_host *mmc)
7037 + int read_only = 0;
7038 + struct atmel_mci *host = mmc_priv(mmc);
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");
7045 + pr_debug("%s: no pin for checking read-only switch."
7046 + " Assuming write-enable.\n", mmc_hostname(mmc));
7052 +static struct mmc_host_ops atmci_ops = {
7053 + .request = atmci_request,
7054 + .set_ios = atmci_set_ios,
7055 + .get_ro = atmci_get_ro,
7058 +static void atmci_request_end(struct mmc_host *mmc, struct mmc_request *mrq)
7060 + struct atmel_mci *host = mmc_priv(mmc);
7062 + WARN_ON(host->cmd || host->data);
7065 + mmc_request_done(mmc, mrq);
7068 +static void send_stop_cmd(struct mmc_host *mmc, struct mmc_data *data,
7071 + struct atmel_mci *host = mmc_priv(mmc);
7073 + atmci_start_command(host, data->stop, host->stop_cmdr | flags);
7074 + mci_writel(host, IER, host->stop_iflags);
7077 +static void atmci_data_complete(struct atmel_mci *host, struct mmc_data *data)
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));
7085 + * Data might complete before command for very short transfers
7088 + if (mci_cmd_is_complete(host)
7089 + && (!data->stop || mci_stop_is_complete(host)))
7090 + atmci_request_end(host->mmc, data->mrq);
7093 +static void atmci_command_error(struct mmc_host *mmc,
7094 + struct mmc_command *cmd,
7097 + pr_debug("%s: command error: status=0x%08x\n",
7098 + mmc_hostname(mmc), status);
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;
7105 + cmd->error = MMC_ERR_FAILED;
7108 +static void atmci_tasklet_func(unsigned long priv)
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;
7115 + pr_debug("atmci_tasklet: pending/completed/mask %lx/%lx/%x\n",
7116 + host->pending_events, host->completed_events,
7117 + mci_readl(host, IMR));
7119 + if (mci_clear_cmd_error_is_pending(host)) {
7120 + struct mmc_command *cmd;
7122 + mci_set_cmd_error_complete(host);
7123 + mci_clear_cmd_pending(host);
7124 + cmd = host->mrq->cmd;
7127 + dma_stop_request(host->dma.req.req.dmac,
7128 + host->dma.req.req.channel);
7129 + host->data = NULL;
7132 + atmci_command_error(mmc, cmd, host->error_status);
7133 + atmci_request_end(mmc, cmd->mrq);
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);
7141 + atmci_request_end(mmc, host->mrq);
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);
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);
7155 + if (mci_clear_dma_error_is_pending(host)) {
7156 + mci_set_dma_error_complete(host);
7157 + mci_clear_data_pending(host);
7159 + /* DMA controller got bus error => invalid address */
7160 + data->error = MMC_ERR_INVALID;
7162 + printk(KERN_DEBUG "%s: dma error after %u bytes xfered\n",
7163 + mmc_hostname(mmc), host->data->bytes_xfered);
7166 + && !mci_set_stop_sent_is_completed(host))
7167 + /* TODO: Check if card is still present */
7168 + send_stop_cmd(host->mmc, data, 0);
7170 + atmci_data_complete(host, data);
7172 + if (mci_clear_data_error_is_pending(host)) {
7173 + u32 status = host->error_status;
7175 + mci_set_data_error_complete(host);
7176 + mci_clear_data_pending(host);
7178 + dma_stop_request(host->dma.req.req.dmac,
7179 + host->dma.req.req.channel);
7181 + printk(KERN_DEBUG "%s: data error: status=0x%08x\n",
7182 + mmc_hostname(host->mmc), status);
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;
7193 + printk(KERN_DEBUG "%s: Data FIFO error\n",
7194 + mmc_hostname(host->mmc));
7195 + data->error = MMC_ERR_FIFO;
7197 + printk(KERN_DEBUG "%s: Bytes xfered: %u\n",
7198 + mmc_hostname(host->mmc), data->bytes_xfered);
7201 + && !mci_set_stop_sent_is_completed(host))
7202 + /* TODO: Check if card is still present */
7203 + send_stop_cmd(host->mmc, data, 0);
7205 + atmci_data_complete(host, data);
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);
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));
7220 + /* Clean up queue if present */
7222 + if (!mci_cmd_is_complete(host)
7223 + && !mci_cmd_error_is_complete(host)) {
7224 + mrq->cmd->error = MMC_ERR_TIMEOUT;
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);
7233 + if (mrq->stop && !mci_stop_is_complete(host)
7234 + && !mci_stop_error_is_complete(host)) {
7235 + mrq->stop->error = MMC_ERR_TIMEOUT;
7239 + atmci_request_end(mmc, mrq);
7241 + mmc_detect_change(host->mmc, msecs_to_jiffies(100));
7245 +static void atmci_cmd_interrupt(struct mmc_host *mmc, u32 status)
7247 + struct atmel_mci *host = mmc_priv(mmc);
7248 + struct mmc_command *cmd = host->cmd;
7251 + * Read the response now so that we're free to send a new
7252 + * command immediately.
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);
7259 + mci_writel(host, IDR, MCI_BIT(CMDRDY) | MCI_CMD_ERROR_FLAGS);
7262 + if (mci_stop_sent_is_complete(host))
7263 + mci_set_stop_pending(host);
7265 + mci_set_cmd_pending(host);
7267 + tasklet_schedule(&host->tasklet);
7270 +static void atmci_xfer_complete(struct dma_request *_req)
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;
7277 + dma = container_of(req, struct atmel_mci_dma, req);
7278 + host = container_of(dma, struct atmel_mci, dma);
7279 + data = host->data;
7281 + if (data->stop && !mci_set_stop_sent_is_completed(host))
7282 + send_stop_cmd(host->mmc, data, 0);
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);
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.
7294 + mci_writel(host, IER, MCI_BIT(NOTBUSY));
7298 +static void atmci_dma_error(struct dma_request *_req)
7300 + struct dma_request_sg *req = to_dma_request_sg(_req);
7301 + struct atmel_mci_dma *dma;
7302 + struct atmel_mci *host;
7304 + dma = container_of(req, struct atmel_mci_dma, req);
7305 + host = container_of(dma, struct atmel_mci, dma);
7307 + mci_writel(host, IDR, (MCI_BIT(NOTBUSY)
7308 + | MCI_DATA_ERROR_FLAGS));
7310 + mci_set_dma_error_pending(host);
7311 + tasklet_schedule(&host->tasklet);
7314 +static irqreturn_t atmci_interrupt(int irq, void *dev_id)
7316 + struct mmc_host *mmc = dev_id;
7317 + struct atmel_mci *host = mmc_priv(mmc);
7318 + u32 status, mask, pending;
7320 + spin_lock(&mmc->lock);
7322 + status = mci_readl(host, SR);
7323 + mask = mci_readl(host, IMR);
7324 + pending = status & mask;
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;
7334 + if (mci_stop_sent_is_complete(host))
7335 + mci_set_stop_error_pending(host);
7337 + mci_set_cmd_error_pending(host);
7338 + tasklet_schedule(&host->tasklet);
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);
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);
7358 + status = mci_readl(host, SR);
7359 + mask = mci_readl(host, IMR);
7360 + pending = status & mask;
7361 + } while (pending);
7363 + spin_unlock(&mmc->lock);
7365 + return IRQ_HANDLED;
7368 +static irqreturn_t atmci_detect_change(int irq, void *dev_id)
7370 + struct mmc_host *mmc = dev_id;
7371 + struct atmel_mci *host = mmc_priv(mmc);
7373 + int present = !gpio_get_value(irq_to_gpio(irq));
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);
7382 + return IRQ_HANDLED;
7385 +static int __devinit atmci_probe(struct platform_device *pdev)
7387 + struct mci_platform_data *board;
7388 + struct atmel_mci *host;
7389 + struct mmc_host *mmc;
7390 + struct resource *regs;
7394 + regs = platform_get_resource(pdev, IORESOURCE_MEM, 0);
7397 + irq = platform_get_irq(pdev, 0);
7401 + board = pdev->dev.platform_data;
7403 + mmc = mmc_alloc_host(sizeof(struct atmel_mci), &pdev->dev);
7407 + host = mmc_priv(mmc);
7408 + host->pdev = pdev;
7411 + host->detect_pin = board->detect_pin;
7412 + host->wp_pin = board->wp_pin;
7414 + host->detect_pin = -1;
7415 + host->detect_pin = -1;
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;
7423 + clk_enable(host->mck);
7426 + host->regs = ioremap(regs->start, regs->end - regs->start + 1);
7428 + goto out_disable_clk;
7430 + host->bus_hz = clk_get_rate(host->mck);
7431 + host->mapbase = regs->start;
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;
7439 + tasklet_init(&host->tasklet, atmci_tasklet_func, (unsigned long)mmc);
7441 + ret = request_irq(irq, atmci_interrupt, 0, "mmci", mmc);
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;
7453 + host->present = !gpio_get_value(host->detect_pin);
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;
7464 + /* TODO: Get this information from platform data */
7466 + host->dma.req.req.dmac = find_dma_controller(0);
7467 + if (!host->dma.req.req.dmac) {
7469 + "mmci: No DMA controller available, aborting\n");
7470 + goto out_free_irq;
7472 + ret = dma_alloc_channel(host->dma.req.req.dmac);
7475 + "mmci: Unable to allocate DMA channel, aborting\n");
7476 + goto out_free_irq;
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;
7486 + mci_writel(host, CR, MCI_BIT(SWRST));
7487 + mci_writel(host, IDR, ~0UL);
7488 + mci_writel(host, CR, MCI_BIT(MCIEN));
7490 + platform_set_drvdata(pdev, host);
7492 + mmc_add_host(mmc);
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);
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;
7509 + printk(KERN_INFO "%s: Atmel MCI controller at 0x%08lx irq %d\n",
7510 + mmc_hostname(mmc), host->mapbase, irq);
7512 + atmci_init_debugfs(host);
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);
7523 + iounmap(host->regs);
7525 + clk_disable(host->mck);
7526 + clk_put(host->mck);
7528 + mmc_free_host(mmc);
7532 +static int __devexit atmci_remove(struct platform_device *pdev)
7534 + struct atmel_mci *host = platform_get_drvdata(pdev);
7536 + platform_set_drvdata(pdev, NULL);
7539 + atmci_cleanup_debugfs(host);
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);
7547 + mmc_remove_host(host->mmc);
7549 + mci_writel(host, IDR, ~0UL);
7550 + mci_writel(host, CR, MCI_BIT(MCIDIS));
7551 + mci_readl(host, SR);
7553 + dma_release_channel(host->dma.req.req.dmac,
7554 + host->dma.req.req.channel);
7556 + if (host->wp_pin >= 0)
7557 + gpio_free(host->wp_pin);
7559 + free_irq(platform_get_irq(pdev, 0), host->mmc);
7560 + iounmap(host->regs);
7562 + clk_disable(host->mck);
7563 + clk_put(host->mck);
7565 + mmc_free_host(host->mmc);
7570 +static struct platform_driver atmci_driver = {
7571 + .probe = atmci_probe,
7572 + .remove = __devexit_p(atmci_remove),
7574 + .name = DRIVER_NAME,
7578 +static int __init atmci_init(void)
7580 + return platform_driver_register(&atmci_driver);
7583 +static void __exit atmci_exit(void)
7585 + platform_driver_unregister(&atmci_driver);
7588 +module_init(atmci_init);
7589 +module_exit(atmci_exit);
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
7597 +++ b/drivers/mmc/host/atmel-mci.h
7600 + * Atmel MultiMedia Card Interface driver
7602 + * Copyright (C) 2004-2006 Atmel Corporation
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.
7608 +#ifndef __DRIVERS_MMC_ATMEL_MCI_H__
7609 +#define __DRIVERS_MMC_ATMEL_MCI_H__
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
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
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
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
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
7668 +/* Bitfields in ARGR */
7669 +#define MCI_ARG_OFFSET 0
7670 +#define MCI_ARG_SIZE 32
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
7690 +/* Bitfields in BLKR */
7691 +#define MCI_BCNT_OFFSET 0
7692 +#define MCI_BCNT_SIZE 16
7694 +/* Bitfields in RSPRn */
7695 +#define MCI_RSP_OFFSET 0
7696 +#define MCI_RSP_SIZE 32
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
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
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
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
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
7765 +/* Constants for TRTYP */
7766 +#define MCI_TRTYP_BLOCK 0
7767 +#define MCI_TRTYP_MULTI_BLOCK 1
7768 +#define MCI_TRTYP_STREAM 2
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))
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)
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
7796 #define I82802AC 0x00ac
7797 #define MANUFACTURER_ST 0x0020
7798 #define M50LPW080 0x002F
7799 +#define AT49BV640D 0x02de
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)
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)
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;
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);
7821 + memcpy(&atmel_pri, extp, sizeof(atmel_pri));
7822 + memset((char *)extp + 5, 0, sizeof(*extp) - 5);
7824 + printk(KERN_ERR "atmel Features: %02x\n", atmel_pri.Features);
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);
7841 + extp->FeatureSupport = features;
7843 + /* burst write mode not supported */
7844 + cfi->cfiq->BufWriteTimeoutTyp = 0;
7845 + cfi->cfiq->BufWriteTimeoutMax = 0;
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)
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 },
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;
7866 extp->TopBottom = 3;
7868 + /* burst write mode not supported */
7869 + cfi->cfiq->BufWriteTimeoutTyp = 0;
7870 + cfi->cfiq->BufWriteTimeoutMax = 0;
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)
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 },
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, },
7886 - { CFI_MFR_ATMEL, CFI_ID_ANY, fixup_convert_atmel_pri, NULL },
7887 { 0, 0, NULL, NULL }
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
7896 tristate "Atmel MACB support"
7897 depends on NET_ETHERNET && (AVR32 || ARCH_AT91SAM9260 || ARCH_AT91SAM9263)
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
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>
7918 #include <asm/arch/board.h>
7919 +#if defined(CONFIG_ARCH_AT91)
7920 +#include <asm/arch/cpu.h>
7925 @@ -85,172 +86,202 @@ static void __init macb_get_hwaddr(struct macb *bp)
7926 memcpy(bp->dev->dev_addr, addr, sizeof(addr));
7929 -static void macb_enable_mdio(struct macb *bp)
7930 +static int macb_mdio_read(struct mii_bus *bus, int mii_id, int regnum)
7932 - unsigned long flags;
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);
7943 -static void macb_disable_mdio(struct macb *bp)
7945 - unsigned long flags;
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);
7956 -static int macb_mdio_read(struct net_device *dev, int phy_id, int location)
7958 - struct macb *bp = netdev_priv(dev);
7959 + struct macb *bp = bus->priv;
7962 - mutex_lock(&bp->mdio_mutex);
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)));
7973 - wait_for_completion(&bp->mdio_complete);
7974 + /* wait for end of transfer */
7975 + while (!MACB_BFEXT(IDLE, macb_readl(bp, NSR)))
7978 value = MACB_BFEXT(DATA, macb_readl(bp, MAN));
7979 - macb_disable_mdio(bp);
7980 - mutex_unlock(&bp->mdio_mutex);
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,
7990 - struct macb *bp = netdev_priv(dev);
7992 - dev_dbg(&bp->pdev->dev, "mdio_write %02x:%02x <- %04x\n",
7993 - phy_id, location, val);
7995 - mutex_lock(&bp->mdio_mutex);
7996 - macb_enable_mdio(bp);
7997 + struct macb *bp = bus->priv;
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)));
8009 - wait_for_completion(&bp->mdio_complete);
8010 + /* wait for end of transfer */
8011 + while (!MACB_BFEXT(IDLE, macb_readl(bp, NSR)))
8014 - macb_disable_mdio(bp);
8015 - mutex_unlock(&bp->mdio_mutex);
8019 -static int macb_phy_probe(struct macb *bp)
8020 +static int macb_mdio_reset(struct mii_bus *bus)
8023 - u16 phyid1, phyid2;
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)
8032 + struct macb *bp = netdev_priv(dev);
8033 + struct phy_device *phydev = bp->phy_dev;
8034 + unsigned long flags;
8036 - if (phyid1 != 0xffff && phyid1 != 0x0000
8037 - && phyid2 != 0xffff && phyid2 != 0x0000)
8039 + int status_change = 0;
8041 + spin_lock_irqsave(&bp->lock, flags);
8043 + if (phydev->link) {
8044 + if ((bp->speed != phydev->speed) ||
8045 + (bp->duplex != phydev->duplex)) {
8048 + reg = macb_readl(bp, NCFGR);
8049 + reg &= ~(MACB_BIT(SPD) | MACB_BIT(FD));
8051 + if (phydev->duplex)
8052 + reg |= MACB_BIT(FD);
8053 + if (phydev->speed)
8054 + reg |= MACB_BIT(SPD);
8056 + macb_writel(bp, NCFGR, reg);
8058 + bp->speed = phydev->speed;
8059 + bp->duplex = phydev->duplex;
8060 + status_change = 1;
8064 - if (phy_address == 32)
8066 + if (phydev->link != bp->link) {
8068 + netif_schedule(dev);
8073 + bp->link = phydev->link;
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;
8081 - bp->mii.phy_id = phy_address;
8083 + spin_unlock_irqrestore(&bp->lock, flags);
8085 + if (status_change) {
8087 + printk(KERN_INFO "%s: link up (%d/%s)\n",
8088 + dev->name, phydev->speed,
8089 + DUPLEX_FULL == phydev->duplex ? "Full":"Half");
8091 + printk(KERN_INFO "%s: link down\n", dev->name);
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)
8100 + struct macb *bp = netdev_priv(dev);
8101 + struct phy_device *phydev = NULL;
8102 + struct eth_platform_data *pdata;
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];
8123 + printk (KERN_ERR "%s: no PHY found\n", dev->name);
8127 + pdata = bp->pdev->dev.platform_data;
8128 + /* TODO : add pin_irq */
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);
8135 + phydev = phy_connect(dev, phydev->dev.bus_id,
8136 + &macb_handle_link_change, 0, PHY_INTERFACE_MODE_MII);
8139 + if (IS_ERR(phydev)) {
8140 + printk(KERN_ERR "%s: Could not attach to PHY\n", dev->name);
8141 + return PTR_ERR(phydev);
8144 + /* mask with MAC supported features */
8145 + phydev->supported &= PHY_BASIC_FEATURES;
8147 + phydev->advertising = phydev->supported;
8152 + bp->phy_dev = phydev;
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)
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;
8166 - /* if forced media, go no further */
8167 - if (mii->force_media)
8169 + /* Enable managment port */
8170 + macb_writel(bp, NCR, MACB_BIT(MPE));
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;
8184 - /* if carrier state did not change, assume nothing else did */
8185 - if (!init_media && old_carrier == new_carrier)
8188 + bp->mii_bus.phy_mask = pdata->phy_mask;
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);
8195 + bp->mii_bus.irq = kmalloc(sizeof(int)*PHY_MAX_ADDR, GFP_KERNEL);
8196 + if (!bp->mii_bus.irq) {
8202 - * we have carrier, see who's on the other end
8204 - netif_carrier_on(mii->dev);
8205 + for (i = 0; i < PHY_MAX_ADDR; i++)
8206 + bp->mii_bus.irq[i] = PHY_POLL;
8208 - /* get MII advertise and LPA values */
8209 - if (!init_media && mii->advertising) {
8210 - advertise = mii->advertising;
8212 - advertise = mii->mdio_read(mii->dev, mii->phy_id, MII_ADVERTISE);
8213 - mii->advertising = advertise;
8215 - lpa = mii->mdio_read(mii->dev, mii->phy_id, MII_LPA);
8216 + platform_set_drvdata(bp->dev, &bp->mii_bus);
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;
8225 - printk(KERN_INFO "%s: link up, %sMbps, %s-duplex, lpa 0x%04X\n",
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;
8233 - mii->full_duplex = duplex;
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);
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);
8251 -static void macb_periodic_task(struct work_struct *work)
8253 - struct macb *bp = container_of(work, struct macb, periodic_task.work);
8255 - macb_update_stats(bp);
8256 - macb_check_media(bp, 1, 0);
8258 - schedule_delayed_work(&bp->periodic_task, HZ);
8261 static void macb_tx(struct macb *bp)
8264 @@ -519,9 +540,6 @@ static irqreturn_t macb_interrupt(int irq, void *dev_id)
8265 spin_lock(&bp->lock);
8268 - if (status & MACB_BIT(MFD))
8269 - complete(&bp->mdio_complete);
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
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);
8284 @@ -765,7 +784,7 @@ static void macb_init_hw(struct macb *bp)
8285 macb_writel(bp, TBQP, bp->tx_ring_dma);
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));
8291 /* Enable interrupts */
8292 macb_writel(bp, IER, (MACB_BIT(RCOMP)
8293 @@ -776,18 +795,126 @@ static void macb_init_hw(struct macb *bp)
8295 | MACB_BIT(ISR_ROVR)
8296 | MACB_BIT(HRESP)));
8300 -static void macb_init_phy(struct net_device *dev)
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.
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.
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]
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.
8335 +static inline int hash_bit_value(int bitnr, __u8 *addr)
8337 + if (addr[bitnr / 8] & (1 << (bitnr % 8)))
8343 + * Return the hash index value for the specified address.
8345 +static int hash_get_index(__u8 *addr)
8348 + int hash_index = 0;
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);
8354 + hash_index |= (bitval << j);
8357 + return hash_index;
8361 + * Add multicast addresses to the internal multicast-hash table.
8363 +static void macb_sethashtable(struct net_device *dev)
8365 + struct dev_mc_list *curr;
8366 + unsigned long mc_filter[2];
8367 + unsigned int i, bitnr;
8368 + struct macb *bp = netdev_priv(dev);
8370 + mc_filter[0] = mc_filter[1] = 0;
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 */
8376 + bitnr = hash_get_index(curr->dmi_addr);
8377 + mc_filter[bitnr >> 5] |= 1 << (bitnr & 31);
8380 + macb_writel(bp, HRB, mc_filter[0]);
8381 + macb_writel(bp, HRT, mc_filter[1]);
8385 + * Enable/Disable promiscuous and multicast modes.
8387 +static void macb_set_rx_mode(struct net_device *dev)
8389 + unsigned long cfg;
8390 struct macb *bp = netdev_priv(dev);
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);
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);
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);
8423 + macb_writel(bp, NCFGR, cfg);
8426 static int macb_open(struct net_device *dev)
8427 @@ -797,6 +924,10 @@ static int macb_open(struct net_device *dev)
8429 dev_dbg(&bp->pdev->dev, "open\n");
8431 + /* if the phy is not yet register, retry later*/
8435 if (!is_valid_ether_addr(dev->dev_addr))
8436 return -EADDRNOTAVAIL;
8438 @@ -810,12 +941,11 @@ static int macb_open(struct net_device *dev)
8440 macb_init_rings(bp);
8442 - macb_init_phy(dev);
8444 - macb_check_media(bp, 1, 1);
8445 - netif_start_queue(dev);
8446 + /* schedule a link state check */
8447 + phy_start(bp->phy_dev);
8449 - schedule_delayed_work(&bp->periodic_task, HZ);
8450 + netif_start_queue(dev);
8454 @@ -825,10 +955,11 @@ static int macb_close(struct net_device *dev)
8455 struct macb *bp = netdev_priv(dev);
8456 unsigned long flags;
8458 - cancel_rearming_delayed_work(&bp->periodic_task);
8460 netif_stop_queue(dev);
8463 + phy_stop(bp->phy_dev);
8465 spin_lock_irqsave(&bp->lock, flags);
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;
8472 + /* read stats from hardware */
8473 + macb_update_stats(bp);
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)
8481 struct macb *bp = netdev_priv(dev);
8482 + struct phy_device *phydev = bp->phy_dev;
8484 - return mii_ethtool_gset(&bp->mii, cmd);
8488 + return phy_ethtool_gset(phydev, cmd);
8491 static int macb_set_settings(struct net_device *dev, struct ethtool_cmd *cmd)
8493 struct macb *bp = netdev_priv(dev);
8494 + struct phy_device *phydev = bp->phy_dev;
8496 - return mii_ethtool_sset(&bp->mii, cmd);
8500 + return phy_ethtool_sset(phydev, cmd);
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)
8507 struct macb *bp = netdev_priv(dev);
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);
8513 -static int macb_nway_reset(struct net_device *dev)
8515 - struct macb *bp = netdev_priv(dev);
8516 - return mii_nway_restart(&bp->mii);
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,
8527 static int macb_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
8529 struct macb *bp = netdev_priv(dev);
8530 + struct phy_device *phydev = bp->phy_dev;
8532 if (!netif_running(dev))
8535 - return generic_mii_ioctl(&bp->mii, if_mii(rq), cmd, NULL);
8538 -static ssize_t macb_mii_show(const struct device *_dev, char *buf,
8539 - unsigned long addr)
8541 - struct net_device *dev = to_net_dev(_dev);
8542 - struct macb *bp = netdev_priv(dev);
8543 - ssize_t ret = -EINVAL;
8545 - if (netif_running(dev)) {
8547 - value = macb_mdio_read(dev, bp->mii.phy_id, addr);
8548 - ret = sprintf(buf, "0x%04x\n", (uint16_t)value);
8554 -#define MII_ENTRY(name, addr) \
8555 -static ssize_t show_##name(struct device *_dev, \
8556 - struct device_attribute *attr, \
8559 - return macb_mii_show(_dev, buf, addr); \
8561 -static DEVICE_ATTR(name, S_IRUGO, show_##name, NULL)
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);
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,
8582 -static struct attribute_group macb_mii_group = {
8584 - .attrs = macb_mii_attrs,
8587 -static void macb_unregister_sysfs(struct net_device *net)
8589 - struct device *_dev = &net->dev;
8593 - sysfs_remove_group(&_dev->kobj, &macb_mii_group);
8594 + return phy_mii_ioctl(phydev, if_mii(rq), cmd);
8597 -static int macb_register_sysfs(struct net_device *net)
8599 - struct device *_dev = &net->dev;
8602 - ret = sysfs_create_group(&_dev->kobj, &macb_mii_group);
8604 - printk(KERN_WARNING
8605 - "%s: sysfs mii attribute registration failed: %d\n",
8609 static int __devinit macb_probe(struct platform_device *pdev)
8611 struct eth_platform_data *pdata;
8612 struct resource *regs;
8613 struct net_device *dev;
8615 + struct phy_device *phydev;
8616 unsigned long pclk_hz;
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;
8627 @@ -1080,10 +1154,6 @@ static int __devinit macb_probe(struct platform_device *pdev)
8629 dev->base_addr = regs->start;
8631 - INIT_DELAYED_WORK(&bp->periodic_task, macb_periodic_task);
8632 - mutex_init(&bp->mdio_mutex);
8633 - init_completion(&bp->mdio_complete);
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);
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;
8648 macb_get_hwaddr(bp);
8649 - err = macb_phy_probe(bp);
8651 - dev_err(&pdev->dev, "Failed to detect PHY, aborting.\n");
8652 - goto err_out_free_irq;
8655 pdata = pdev->dev.platform_data;
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;
8664 - platform_set_drvdata(pdev, dev);
8665 + if (macb_mii_init(bp) != 0) {
8666 + goto err_out_unregister_netdev;
8669 - macb_register_sysfs(dev);
8670 + platform_set_drvdata(pdev, dev);
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]);
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);
8685 +err_out_unregister_netdev:
8686 + unregister_netdev(dev);
8688 free_irq(dev->irq, dev);
8690 @@ -1153,7 +1221,9 @@ err_out_disable_clocks:
8693 clk_disable(bp->pclk);
8694 +#ifndef CONFIG_ARCH_AT91
8700 @@ -1171,7 +1241,8 @@ static int __devexit macb_remove(struct platform_device *pdev)
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);
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 {
8716 unsigned int rx_pending, tx_pending;
8718 - struct delayed_work periodic_task;
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;
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.
8739 +config RTC_DRV_AT32AP700X
8740 + tristate "AT32AP700X series RTC"
8741 + depends on RTC_CLASS && PLATFORM_AT32AP
8743 + Driver for the internal RTC (Realtime Clock) on Atmel AVR32
8744 + AT32AP700x family processors.
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
8765 +++ b/drivers/rtc/rtc-at32ap700x.c
8768 + * An RTC driver for the AVR32 AT32AP700x processor series.
8770 + * Copyright (C) 2007 Atmel Corporation
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.
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>
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
8789 + * The alarm functionality is limited by the hardware, not supporting
8790 + * periodic interrupts.
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
8799 +#define RTC_VAL 0x04
8801 +#define RTC_TOP 0x08
8803 +#define RTC_IER 0x10
8804 +#define RTC_IER_TOPI 0
8806 +#define RTC_IDR 0x14
8807 +#define RTC_IDR_TOPI 0
8809 +#define RTC_IMR 0x18
8810 +#define RTC_IMR_TOPI 0
8812 +#define RTC_ISR 0x1c
8813 +#define RTC_ISR_TOPI 0
8815 +#define RTC_ICR 0x20
8816 +#define RTC_ICR_TOPI 0
8818 +#define RTC_BIT(name) (1 << RTC_##name)
8819 +#define RTC_BF(name, value) ((value) << RTC_##name)
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)
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. */
8835 +static int at32_rtc_readtime(struct device *dev, struct rtc_time *tm)
8837 + struct rtc_at32ap700x *rtc = dev_get_drvdata(dev);
8838 + unsigned long now;
8840 + now = rtc_readl(rtc, VAL);
8841 + rtc_time_to_tm(now, tm);
8846 +static int at32_rtc_settime(struct device *dev, struct rtc_time *tm)
8848 + struct rtc_at32ap700x *rtc = dev_get_drvdata(dev);
8849 + unsigned long now;
8852 + ret = rtc_tm_to_time(tm, &now);
8854 + rtc_writel(rtc, VAL, now);
8859 +static int at32_rtc_readalarm(struct device *dev, struct rtc_wkalrm *alrm)
8861 + struct rtc_at32ap700x *rtc = dev_get_drvdata(dev);
8863 + rtc_time_to_tm(rtc->alarm_time, &alrm->time);
8864 + alrm->pending = rtc_readl(rtc, IMR) & RTC_BIT(IMR_TOPI) ? 1 : 0;
8869 +static int at32_rtc_setalarm(struct device *dev, struct rtc_wkalrm *alrm)
8871 + struct rtc_at32ap700x *rtc = dev_get_drvdata(dev);
8872 + unsigned long rtc_unix_time;
8873 + unsigned long alarm_unix_time;
8876 + rtc_unix_time = rtc_readl(rtc, VAL);
8878 + ret = rtc_tm_to_time(&alrm->time, &alarm_unix_time);
8882 + if (alarm_unix_time < rtc_unix_time)
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));
8892 + rtc_writel(rtc, CTRL, rtc_readl(rtc, CTRL)
8893 + & ~RTC_BIT(CTRL_TOPEN));
8894 + spin_unlock_irq(&rtc->lock);
8899 +static int at32_rtc_ioctl(struct device *dev, unsigned int cmd,
8900 + unsigned long arg)
8902 + struct rtc_at32ap700x *rtc = dev_get_drvdata(dev);
8905 + spin_lock_irq(&rtc->lock);
8909 + if (rtc_readl(rtc, VAL) > rtc->alarm_time) {
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));
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));
8925 + ret = -ENOIOCTLCMD;
8929 + spin_unlock_irq(&rtc->lock);
8934 +static irqreturn_t at32_rtc_interrupt(int irq, void *dev_id)
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;
8941 + spin_lock(&rtc->lock);
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;
8954 + spin_unlock(&rtc->lock);
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,
8967 +static int __init at32_rtc_probe(struct platform_device *pdev)
8969 + struct resource *regs;
8970 + struct rtc_at32ap700x *rtc;
8974 + rtc = kzalloc(sizeof(struct rtc_at32ap700x), GFP_KERNEL);
8976 + dev_dbg(&pdev->dev, "out of memory\n");
8980 + regs = platform_get_resource(pdev, IORESOURCE_MEM, 0);
8982 + dev_dbg(&pdev->dev, "no mmio resource defined\n");
8987 + irq = platform_get_irq(pdev, 0);
8989 + dev_dbg(&pdev->dev, "could not get irq\n");
8994 + ret = request_irq(irq, at32_rtc_interrupt, IRQF_SHARED, "rtc", rtc);
8996 + dev_dbg(&pdev->dev, "could not request irq %d\n", irq);
9001 + rtc->regs = ioremap(regs->start, regs->end - regs->start + 1);
9004 + dev_dbg(&pdev->dev, "could not map I/O memory\n");
9005 + goto out_free_irq;
9007 + spin_lock_init(&rtc->lock);
9010 + * Maybe init RTC: count from zero at 1 Hz, disable wrap irq.
9012 + * Do not reset VAL register, as it can hold an old time
9013 + * from last JTAG reset.
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));
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);
9030 + platform_set_drvdata(pdev, rtc);
9032 + dev_info(&pdev->dev, "Atmel RTC for AT32AP700x at %08lx irq %ld\n",
9033 + (unsigned long)rtc->regs, rtc->irq);
9038 + iounmap(rtc->regs);
9040 + free_irq(irq, rtc);
9046 +static int __exit at32_rtc_remove(struct platform_device *pdev)
9048 + struct rtc_at32ap700x *rtc = platform_get_drvdata(pdev);
9050 + free_irq(rtc->irq, rtc);
9051 + iounmap(rtc->regs);
9052 + rtc_device_unregister(rtc->rtc);
9054 + platform_set_drvdata(pdev, NULL);
9059 +MODULE_ALIAS("at32ap700x_rtc");
9061 +static struct platform_driver at32_rtc_driver = {
9062 + .remove = __exit_p(at32_rtc_remove),
9064 + .name = "at32ap700x_rtc",
9065 + .owner = THIS_MODULE,
9069 +static int __init at32_rtc_init(void)
9071 + return platform_driver_probe(&at32_rtc_driver, at32_rtc_probe);
9073 +module_init(at32_rtc_init);
9075 +static void __exit at32_rtc_exit(void)
9077 + platform_driver_unregister(&at32_rtc_driver);
9079 +module_exit(at32_rtc_exit);
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 */
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)
9098 static void atmel_rx_chars(struct uart_port *port)
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;
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
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 */
9118 + atmel_port->break_active = 1;
9119 + UART_PUT_IER(port, ATMEL_US_RXBRK);
9120 if (uart_handle_break(port))
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.
9130 + UART_PUT_IDR(port, ATMEL_US_RXBRK);
9131 + status &= ~ATMEL_US_RXBRK;
9132 + atmel_port->break_active = 0;
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) {
9142 + * End of break detected. If it came along
9143 + * with a character, atmel_rx_chars will
9146 + UART_PUT_CR(port, ATMEL_US_RSTSTA);
9147 + UART_PUT_IDR(port, ATMEL_US_RXBRK);
9148 + atmel_port->break_active = 0;
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);
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);
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
9174 select USB_GADGET_SELECTED
9176 +config USB_GADGET_ATMEL_USBA
9177 + boolean "Atmel USBA"
9178 + select USB_GADGET_DUALSPEED
9181 + USBA is the integrated high-speed USB Device controller on
9182 + the AT32AP700x processors from Atmel.
9184 +config USB_ATMEL_USBA
9186 + depends on USB_GADGET_ATMEL_USBA
9187 + default USB_GADGET
9188 + select USB_GADGET_SELECTED
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
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
9208 +++ b/drivers/usb/gadget/atmel_usba_udc.c
9211 + * Driver for the Atmel USBA high speed USB device controller
9213 + * Copyright (C) 2005-2007 Atmel Corporation
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.
9219 +/* #define DEBUG */
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>
9234 +#include <asm/gpio.h>
9235 +#include <asm/arch/board.h>
9237 +#include "atmel_usba_udc.h"
9239 +#define DMA_ADDR_INVALID (~(dma_addr_t)0)
9241 +#define FIFO_IOMEM_ID 0
9242 +#define CTRL_IOMEM_ID 1
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
9257 +#define DEBUG_LEVEL (DBG_ERR)
9258 +#define DBG(level, fmt, ...) \
9260 + if ((level) & DEBUG_LEVEL) \
9261 + printk(KERN_DEBUG "udc: " fmt, ## __VA_ARGS__); \
9264 +#define DBG(level, fmt...)
9267 +static struct usba_udc the_udc;
9269 +#ifdef CONFIG_DEBUG_FS
9270 +#include <linux/debugfs.h>
9271 +#include <linux/uaccess.h>
9273 +static int queue_dbg_open(struct inode *inode, struct file *file)
9275 + struct usba_ep *ep = inode->i_private;
9276 + struct usba_request *req, *req_copy;
9277 + struct list_head *queue_data;
9279 + queue_data = kmalloc(sizeof(*queue_data), GFP_KERNEL);
9282 + INIT_LIST_HEAD(queue_data);
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);
9289 + memcpy(req_copy, req, sizeof(*req_copy));
9290 + list_add_tail(&req_copy->queue, queue_data);
9292 + spin_unlock_irq(&ep->udc->lock);
9294 + file->private_data = queue_data;
9298 + spin_unlock_irq(&ep->udc->lock);
9299 + list_for_each_entry_safe(req, req_copy, queue_data, queue) {
9300 + list_del(&req->queue);
9303 + kfree(queue_data);
9308 + * bbbbbbbb llllllll IZS sssss nnnn FDL\n\0
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
9317 + * F/f: submitted/not submitted to FIFO
9318 + * D/d: using/not using DMA
9319 + * L/l: last transaction/not last transaction
9321 +static ssize_t queue_dbg_read(struct file *file, char __user *buf,
9322 + size_t nbytes, loff_t *ppos)
9324 + struct list_head *queue = file->private_data;
9325 + struct usba_request *req, *tmp_req;
9326 + size_t len, remaining, actual = 0;
9329 + if (!access_ok(VERIFY_WRITE, buf, nbytes))
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',
9341 + req->submitted ? 'F' : 'f',
9342 + req->using_dma ? 'D' : 'd',
9343 + req->last_transaction ? 'L' : 'l');
9344 + len = min(len, sizeof(tmpbuf));
9348 + list_del(&req->queue);
9351 + remaining = __copy_to_user(buf, tmpbuf, len);
9352 + actual += len - remaining;
9359 + mutex_unlock(&file->f_dentry->d_inode->i_mutex);
9364 +static int queue_dbg_release(struct inode *inode, struct file *file)
9366 + struct list_head *queue_data = file->private_data;
9367 + struct usba_request *req, *tmp_req;
9369 + list_for_each_entry_safe(req, tmp_req, queue_data, queue) {
9370 + list_del(&req->queue);
9373 + kfree(queue_data);
9377 +static int regs_dbg_open(struct inode *inode, struct file *file)
9379 + struct usba_udc *udc;
9382 + int ret = -ENOMEM;
9384 + mutex_lock(&inode->i_mutex);
9385 + udc = inode->i_private;
9386 + data = kmalloc(inode->i_size, GFP_KERNEL);
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);
9395 + file->private_data = data;
9399 + mutex_unlock(&inode->i_mutex);
9404 +static ssize_t regs_dbg_read(struct file *file, char __user *buf,
9405 + size_t nbytes, loff_t *ppos)
9407 + struct inode *inode = file->f_dentry->d_inode;
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);
9419 +static int regs_dbg_release(struct inode *inode, struct file *file)
9421 + kfree(file->private_data);
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,
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,
9441 +static void usba_ep_init_debugfs(struct usba_udc *udc,
9442 + struct usba_ep *ep)
9444 + struct dentry *ep_root;
9446 + ep_root = debugfs_create_dir(ep_name(ep), udc->debugfs_root);
9449 + ep->debugfs_dir = ep_root;
9451 + ep->debugfs_queue = debugfs_create_file("queue", 0400, ep_root,
9452 + ep, &queue_dbg_fops);
9453 + if (!ep->debugfs_queue)
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;
9463 + if (ep_is_control(ep)) {
9465 + = debugfs_create_u32("state", 0400, ep_root,
9467 + if (!ep->debugfs_state)
9474 + if (ep_can_dma(ep))
9475 + debugfs_remove(ep->debugfs_dma_status);
9477 + debugfs_remove(ep->debugfs_queue);
9479 + debugfs_remove(ep_root);
9481 + dev_err(&ep->udc->pdev->dev,
9482 + "failed to create debugfs directory for %s\n", ep_name(ep));
9485 +static void usba_ep_cleanup_debugfs(struct usba_ep *ep)
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;
9495 +static void usba_init_debugfs(struct usba_udc *udc)
9497 + struct dentry *root, *regs;
9498 + struct resource *regs_resource;
9500 + root = debugfs_create_dir(udc->gadget.name, NULL);
9501 + if (IS_ERR(root) || !root)
9503 + udc->debugfs_root = root;
9505 + regs = debugfs_create_file("regs", 0400, root, udc, ®s_dbg_fops);
9509 + regs_resource = platform_get_resource(udc->pdev, IORESOURCE_MEM,
9511 + regs->d_inode->i_size = regs_resource->end - regs_resource->start + 1;
9512 + udc->debugfs_regs = regs;
9514 + usba_ep_init_debugfs(udc, to_usba_ep(udc->gadget.ep0));
9519 + debugfs_remove(root);
9521 + udc->debugfs_root = NULL;
9522 + dev_err(&udc->pdev->dev, "debugfs is not available\n");
9525 +static void usba_cleanup_debugfs(struct usba_udc *udc)
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;
9534 +static inline void usba_ep_init_debugfs(struct usba_udc *udc,
9535 + struct usba_ep *ep)
9540 +static inline void usba_ep_cleanup_debugfs(struct usba_ep *ep)
9545 +static inline void usba_init_debugfs(struct usba_udc *udc)
9550 +static inline void usba_cleanup_debugfs(struct usba_udc *udc)
9556 +static int vbus_is_present(struct usba_udc *udc)
9558 + if (udc->vbus_pin != -1)
9559 + return gpio_get_value(udc->vbus_pin);
9561 + /* No Vbus detection: Assume always present */
9565 +static void copy_to_fifo(void __iomem *fifo, const void *buf, int len)
9567 + unsigned long tmp;
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;
9573 + DBG(DBG_FIFO, " -> %08lx\n", tmp);
9574 + __raw_writel(tmp, fifo);
9577 + DBG(DBG_FIFO, " -> %02lx\n", tmp >> 24);
9578 + __raw_writeb(tmp >> 24, fifo);
9587 +static void copy_from_fifo(void *buf, void __iomem *fifo, int len)
9593 + unsigned long tmp;
9595 + DBG(DBG_FIFO, "copy from FIFO (len %d):\n", len);
9596 + for (p.w = buf; len > 0; len -= 4, p.w++, fifo += 4) {
9598 + tmp = __raw_readl(fifo);
9600 + DBG(DBG_FIFO, " -> %08lx\n", tmp);
9603 + tmp = __raw_readb(fifo);
9605 + DBG(DBG_FIFO, " -> %02lx\n", tmp);
9612 +static void next_fifo_transaction(struct usba_ep *ep,
9613 + struct usba_request *req)
9615 + unsigned int transaction_len;
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;
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" : "");
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;
9635 +static void submit_request(struct usba_ep *ep, struct usba_request *req)
9637 + DBG(DBG_QUEUE, "%s: submit_request: req %p (length %d)\n",
9638 + ep_name(ep), req, req->req.length);
9640 + req->req.actual = 0;
9641 + req->submitted = 1;
9643 + if (req->using_dma) {
9644 + if (req->req.length == 0) {
9645 + usba_ep_writel(ep, CTL_ENB, USBA_BIT(TX_PK_RDY));
9649 + if (req->req.zero)
9650 + usba_ep_writel(ep, CTL_ENB, USBA_BIT(SHORT_PACKET));
9652 + usba_ep_writel(ep, CTL_DIS, USBA_BIT(SHORT_PACKET));
9654 + usba_dma_writel(ep, ADDRESS, req->req.dma);
9655 + usba_dma_writel(ep, CONTROL, req->ctrl);
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));
9662 + usba_ep_writel(ep, CTL_DIS, USBA_BIT(TX_COMPLETE));
9663 + usba_ep_writel(ep, CTL_ENB, USBA_BIT(TX_PK_RDY));
9668 +static void submit_next_request(struct usba_ep *ep)
9670 + struct usba_request *req;
9672 + if (list_empty(&ep->queue)) {
9673 + usba_ep_writel(ep, CTL_DIS, (USBA_BIT(TX_PK_RDY)
9674 + | USBA_BIT(RX_BK_RDY)));
9678 + req = list_entry(ep->queue.next, struct usba_request, queue);
9679 + if (!req->submitted)
9680 + submit_request(ep, req);
9683 +static void send_status(struct usba_udc *udc, struct usba_ep *ep)
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));
9690 +static void receive_data(struct usba_ep *ep)
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;
9698 + status = usba_ep_readl(ep, STA);
9699 + nr_busy = USBA_BFEXT(BUSY_BANKS, status);
9701 + DBG(DBG_QUEUE, "receive data: nr_busy=%u\n", nr_busy);
9703 + while (nr_busy > 0) {
9704 + if (list_empty(&ep->queue)) {
9705 + usba_ep_writel(ep, CTL_DIS, USBA_BIT(RX_BK_RDY));
9708 + req = list_entry(ep->queue.next,
9709 + struct usba_request, queue);
9711 + bytecount = USBA_BFEXT(BYTE_COUNT, status);
9713 + if (status & (1 << 31))
9715 + if (req->req.actual + bytecount >= req->req.length) {
9717 + bytecount = req->req.length - req->req.actual;
9720 + copy_from_fifo(req->req.buf + req->req.actual,
9721 + ep->fifo, bytecount);
9722 + req->req.actual += bytecount;
9724 + usba_ep_writel(ep, CLR_STA, USBA_BIT(RX_BK_RDY));
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);
9734 + status = usba_ep_readl(ep, STA);
9735 + nr_busy = USBA_BFEXT(BUSY_BANKS, status);
9737 + if (is_complete && ep_is_control(ep)) {
9738 + send_status(udc, ep);
9744 +static void request_complete(struct usba_ep *ep,
9745 + struct usba_request *req,
9748 + struct usba_udc *udc = ep->udc;
9750 + WARN_ON(!list_empty(&req->queue));
9752 + if (req->req.status == -EINPROGRESS)
9753 + req->req.status = status;
9755 + if (req->mapped) {
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;
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);
9769 +static void request_complete_list(struct usba_ep *ep,
9770 + struct list_head *list,
9773 + struct usba_request *req, *tmp_req;
9775 + list_for_each_entry_safe(req, tmp_req, list, queue) {
9776 + list_del_init(&req->queue);
9777 + request_complete(ep, req, status);
9781 +static int usba_ep_enable(struct usb_ep *_ep,
9782 + const struct usb_endpoint_descriptor *desc)
9784 + struct usba_ep *ep = to_usba_ep(_ep);
9785 + struct usba_udc *udc = ep->udc;
9786 + unsigned long flags, ept_cfg, maxpacket;
9788 + DBG(DBG_GADGET, "%s: ep_enable: desc=%p\n", ep_name(ep), desc);
9790 + maxpacket = le16_to_cpu(desc->wMaxPacketSize);
9792 + if (ep->index == 0
9793 + || desc->bDescriptorType != USB_DT_ENDPOINT
9794 + || ((desc->bEndpointAddress & USB_ENDPOINT_NUMBER_MASK)
9797 + || maxpacket > ep->fifo_size) {
9798 + DBG(DBG_ERR, "ep_enable: Invalid argument");
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",
9815 + if (maxpacket <= 8)
9816 + ept_cfg = USBA_BF(EPT_SIZE, USBA_EPT_SIZE_8);
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);
9823 + if ((desc->bEndpointAddress & USB_ENDPOINT_DIR_MASK) == USB_DIR_IN) {
9825 + ept_cfg |= USBA_BIT(EPT_DIR);
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);
9832 + case USB_ENDPOINT_XFER_ISOC:
9833 + ept_cfg |= USBA_BF(EPT_TYPE, USBA_EPT_TYPE_ISO);
9835 + case USB_ENDPOINT_XFER_BULK:
9836 + ept_cfg |= USBA_BF(EPT_TYPE, USBA_EPT_TYPE_BULK);
9838 + case USB_ENDPOINT_XFER_INT:
9839 + ept_cfg |= USBA_BF(EPT_TYPE, USBA_EPT_TYPE_INT);
9842 + ept_cfg |= USBA_BF(BK_NUMBER, ep->nr_banks);
9844 + spin_lock_irqsave(&ep->udc->lock, flags);
9847 + spin_unlock_irqrestore(&ep->udc->lock, flags);
9848 + DBG(DBG_ERR, "ep%d already enabled\n", ep->index);
9853 + ep->ep.maxpacket = maxpacket;
9855 + usba_ep_writel(ep, CFG, ept_cfg);
9856 + usba_ep_writel(ep, CTL_ENB, USBA_BIT(EPT_ENABLE));
9858 + if (ep_can_dma(ep)) {
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);
9868 + usba_writel(udc, INT_ENB,
9869 + (usba_readl(udc, INT_ENB)
9870 + | USBA_BF(EPT_INT, 1 << ep->index)));
9873 + spin_unlock_irqrestore(&udc->lock, flags);
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));
9883 +static int usba_ep_disable(struct usb_ep *_ep)
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;
9890 + DBG(DBG_GADGET, "ep_disable: %s\n", ep_name(ep));
9892 + spin_lock_irqsave(&udc->lock, flags);
9895 + spin_unlock_irqrestore(&udc->lock, flags);
9896 + DBG(DBG_ERR, "ep_disable: %s not enabled\n",
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);
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)));
9912 + spin_unlock_irqrestore(&udc->lock, flags);
9914 + request_complete_list(ep, &req_list, -ESHUTDOWN);
9919 +static struct usb_request *
9920 +usba_ep_alloc_request(struct usb_ep *_ep, unsigned gfp_flags)
9922 + struct usba_request *req;
9924 + DBG(DBG_GADGET, "ep_alloc_request: %p, 0x%x\n", _ep, gfp_flags);
9926 + req = kzalloc(sizeof(*req), gfp_flags);
9930 + INIT_LIST_HEAD(&req->queue);
9931 + req->req.dma = DMA_ADDR_INVALID;
9937 +usba_ep_free_request(struct usb_ep *_ep, struct usb_request *_req)
9939 + struct usba_request *req = to_usba_req(_req);
9941 + DBG(DBG_GADGET, "ep_free_request: %p, %p\n", _ep, _req);
9946 +static void *usba_ep_alloc_buffer(struct usb_ep *_ep, unsigned bytes,
9947 + dma_addr_t *dma, unsigned gfp_flags)
9951 + if (bytes < L1_CACHE_BYTES)
9952 + bytes = L1_CACHE_BYTES;
9954 + buf = kmalloc(bytes, gfp_flags);
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
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.
9966 + *dma = DMA_ADDR_INVALID;
9971 +static void usba_ep_free_buffer(struct usb_ep *_ep, void *buf,
9972 + dma_addr_t dma, unsigned bytes)
9974 + DBG(DBG_GADGET, "ep_free_buffer: %s, buf %p (size %u)\n",
9975 + _ep->name, buf, bytes);
9979 +static int queue_dma(struct usba_udc *udc, struct usba_ep *ep,
9980 + struct usba_request *req, gfp_t gfp_flags)
9982 + unsigned long flags;
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');
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);
9997 + req->using_dma = 1;
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);
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);
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));
10015 + if (ep_is_in(ep))
10016 + req->ctrl |= USBA_BIT(DMA_END_BUF_EN);
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.
10023 + ret = -ESHUTDOWN;
10024 + spin_lock_irqsave(&udc->lock, flags);
10026 + if (list_empty(&ep->queue))
10027 + submit_request(ep, req);
10029 + list_add_tail(&req->queue, &ep->queue);
10032 + spin_unlock_irqrestore(&udc->lock, flags);
10037 +static int usba_ep_queue(struct usb_ep *_ep, struct usb_request *_req,
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;
10046 + DBG(DBG_GADGET | DBG_QUEUE | DBG_REQ,
10047 + "%s: queue req %p, len %u\n", ep_name(ep), req, _req->length);
10049 + if (!udc->driver || udc->gadget.speed == USB_SPEED_UNKNOWN
10051 + return -ESHUTDOWN;
10053 + req->submitted = 0;
10054 + req->using_dma = 0;
10055 + req->last_transaction = 0;
10057 + _req->status = -EINPROGRESS;
10058 + _req->actual = 0;
10060 + if (ep_can_dma(ep))
10061 + return queue_dma(udc, ep, req, gfp_flags);
10063 + /* May have received a reset since last time we checked */
10064 + ret = -ESHUTDOWN;
10065 + spin_lock_irqsave(&udc->lock, flags);
10067 + list_add_tail(&req->queue, &ep->queue);
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));
10075 + usba_ep_writel(ep, CTL_ENB, USBA_BIT(RX_BK_RDY));
10078 + spin_unlock_irqrestore(&udc->lock, flags);
10083 +static void usba_update_req(struct usba_ep *ep, struct usba_request *req,
10086 + req->req.actual = req->req.length - USBA_BFEXT(DMA_BUF_LEN, status);
10089 +static int stop_dma(struct usba_ep *ep, u32 *pstatus)
10091 + unsigned int timeout;
10095 + * Stop the DMA controller. When writing both CH_EN
10096 + * and LINK to 0, the other bits are not affected.
10098 + usba_dma_writel(ep, CONTROL, 0);
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)))
10109 + *pstatus = status;
10111 + if (timeout == 0) {
10112 + dev_err(&ep->udc->pdev->dev,
10113 + "%s: timed out waiting for DMA FIFO to empty\n",
10115 + return -ETIMEDOUT;
10121 +static int usba_ep_dequeue(struct usb_ep *_ep, struct usb_request *_req)
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;
10129 + DBG(DBG_GADGET | DBG_QUEUE, "ep_dequeue: %s, req %p\n",
10130 + ep_name(ep), req);
10132 + spin_lock_irqsave(&udc->lock, flags);
10134 + if (req->using_dma) {
10136 + * If this request is currently being transferred,
10137 + * stop the DMA controller and reset the FIFO.
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);
10144 +#ifdef CONFIG_DEBUG_FS
10145 + ep->last_dma_status = status;
10148 + usba_writel(udc, EPT_RST,
10149 + 1 << ep_index(ep));
10151 + usba_update_req(ep, req, status);
10156 + * Errors should stop the queue from advancing until the
10157 + * completion function returns.
10159 + list_del_init(&req->queue);
10160 + spin_unlock_irqrestore(&udc->lock, flags);
10162 + request_complete(ep, req, -ECONNRESET);
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);
10172 +static int usba_ep_set_halt(struct usb_ep *_ep, int value)
10174 + struct usba_ep *ep = to_usba_ep(_ep);
10175 + struct usba_udc *udc = ep->udc;
10176 + unsigned long flags;
10179 + DBG(DBG_GADGET, "endpoint %s: %s HALT\n", ep_name(ep),
10180 + value ? "set" : "clear");
10183 + DBG(DBG_ERR, "Attempted to halt uninitialized ep %s\n",
10187 + if (ep_is_isochronous(ep)) {
10188 + DBG(DBG_ERR, "Attempted to halt isochronous ep %s\n",
10193 + spin_lock_irqsave(&udc->lock, flags);
10196 + * We can't halt IN endpoints while there are still data to be
10199 + if (!list_empty(&ep->queue)
10200 + || ((value && ep_is_in(ep)
10201 + && (usba_ep_readl(ep, STA)
10202 + & USBA_BF(BUSY_BANKS, -1L))))) {
10206 + usba_ep_writel(ep, SET_STA, USBA_BIT(FORCE_STALL));
10208 + usba_ep_writel(ep, CLR_STA, (USBA_BIT(FORCE_STALL)
10209 + | USBA_BIT(TOGGLE_SEQ)));
10210 + usba_ep_readl(ep, STA);
10213 + spin_unlock_irqrestore(&udc->lock, flags);
10218 +static int usba_ep_fifo_status(struct usb_ep *_ep)
10220 + struct usba_ep *ep = to_usba_ep(_ep);
10222 + return USBA_BFEXT(BYTE_COUNT, usba_ep_readl(ep, STA));
10225 +static void usba_ep_fifo_flush(struct usb_ep *_ep)
10227 + struct usba_ep *ep = to_usba_ep(_ep);
10228 + struct usba_udc *udc = ep->udc;
10230 + usba_writel(udc, EPT_RST, 1 << ep->index);
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,
10247 +static int usba_udc_get_frame(struct usb_gadget *gadget)
10249 + struct usba_udc *udc = to_usba_udc(gadget);
10251 + return USBA_BFEXT(FRAME_NUMBER, usba_readl(udc, FNUM));
10254 +struct usb_gadget_ops usba_udc_ops = {
10255 + .get_frame = usba_udc_get_frame,
10258 +#define EP(nam, type, idx, dma, isoc) \
10261 + .ops = &usba_ep_ops, \
10263 + .maxpacket = type##_FIFO_SIZE, \
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, \
10270 + .can_dma = dma, \
10271 + .can_isoc = isoc, \
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),
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 */
10295 +static void nop_release(struct device *dev)
10300 +static struct usba_udc the_udc = {
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",
10308 + .bus_id = "gadget",
10309 + .release = nop_release,
10313 + .lock = SPIN_LOCK_UNLOCKED,
10317 + * Called with interrupts disabled and udc->lock held.
10319 +static void reset_all_endpoints(struct usba_udc *udc)
10321 + struct usba_ep *ep;
10322 + struct usba_request *req, *tmp_req;
10324 + usba_writel(udc, EPT_RST, ~0UL);
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);
10332 + list_for_each_entry(ep, &udc->gadget.ep_list, ep.ep_list) {
10334 + usba_ep_disable(&ep->ep);
10338 +static struct usba_ep *get_ep_by_addr(struct usba_udc *udc, u16 wIndex)
10340 + struct usba_ep *ep;
10342 + if ((wIndex & USB_ENDPOINT_NUMBER_MASK) == 0)
10343 + return to_usba_ep(udc->gadget.ep0);
10345 + list_for_each_entry (ep, &udc->gadget.ep_list, ep.ep_list) {
10346 + u8 bEndpointAddress;
10350 + bEndpointAddress = ep->desc->bEndpointAddress;
10351 + if ((wIndex ^ bEndpointAddress) & USB_DIR_IN)
10353 + if ((wIndex & USB_ENDPOINT_NUMBER_MASK)
10354 + == (bEndpointAddress & USB_ENDPOINT_NUMBER_MASK))
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)
10365 + usba_ep_writel(ep, SET_STA, USBA_BIT(FORCE_STALL));
10366 + ep->state = WAIT_FOR_SETUP;
10369 +static inline int is_stalled(struct usba_udc *udc, struct usba_ep *ep)
10371 + if (usba_ep_readl(ep, STA) & USBA_BIT(FORCE_STALL))
10376 +static inline void set_address(struct usba_udc *udc, unsigned int addr)
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);
10386 +static int do_test_mode(struct usba_udc *udc)
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
10403 + struct device *dev = &udc->pdev->dev;
10404 + struct usba_ep *ep;
10407 + test_mode = udc->test_mode;
10409 + /* Start from a clean slate */
10410 + reset_all_endpoints(udc);
10412 + switch (test_mode) {
10415 + usba_writel(udc, TST, USBA_BIT(TST_J_MODE));
10416 + dev_info(dev, "Entering Test_J mode...\n");
10420 + usba_writel(udc, TST, USBA_BIT(TST_K_MODE));
10421 + dev_info(dev, "Entering Test_K mode...\n");
10425 + * Test_SE0_NAK: Force high-speed mode and set up ep0
10426 + * for Bulk IN transfers
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");
10440 + usba_ep_writel(ep, CTL_ENB, USBA_BIT(EPT_ENABLE));
10441 + dev_info(dev, "Entering Test_SE0_NAK mode...\n");
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");
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");
10465 + dev_err(dev, "Invalid test mode: 0x%04x\n", test_mode);
10472 +/* Avoid overly long expressions */
10473 +static inline bool feature_is_dev_remote_wakeup(struct usb_ctrlrequest *crq)
10475 + if (crq->wValue == __constant_cpu_to_le16(USB_DEVICE_REMOTE_WAKEUP))
10480 +static inline bool feature_is_dev_test_mode(struct usb_ctrlrequest *crq)
10482 + if (crq->wValue == __constant_cpu_to_le16(USB_DEVICE_TEST_MODE))
10487 +static inline bool feature_is_ep_halt(struct usb_ctrlrequest *crq)
10489 + if (crq->wValue == __constant_cpu_to_le16(USB_ENDPOINT_HALT))
10494 +static int handle_ep0_setup(struct usba_udc *udc, struct usba_ep *ep,
10495 + struct usb_ctrlrequest *crq)
10497 + switch (crq->bRequest) {
10498 + case USB_REQ_GET_STATUS: {
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;
10511 + target = get_ep_by_addr(udc, le16_to_cpu(crq->wIndex));
10516 + if (is_stalled(udc, target))
10517 + status |= __constant_cpu_to_le16(1);
10522 + /* Write directly to the FIFO. No queueing is done. */
10523 + if (crq->wLength != __constant_cpu_to_le16(sizeof(status)))
10525 + ep->state = DATA_STAGE_IN;
10526 + __raw_writew(status, ep->fifo);
10527 + usba_ep_writel(ep, SET_STA, USBA_BIT(TX_PK_RDY));
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 */
10536 + /* Can't CLEAR_FEATURE TEST_MODE */
10539 + } else if (crq->bRequestType == USB_RECIP_ENDPOINT) {
10540 + struct usba_ep *target;
10542 + if (!feature_is_ep_halt(crq)
10543 + || crq->wLength != __constant_cpu_to_le16(0))
10545 + target = get_ep_by_addr(udc, le16_to_cpu(crq->wIndex));
10549 + usba_ep_writel(target, CLR_STA,
10550 + (USBA_BIT(FORCE_STALL)
10551 + | USBA_BIT(TOGGLE_SEQ)));
10556 + send_status(udc, ep);
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);
10567 + } else if (feature_is_dev_remote_wakeup(crq)) {
10568 + /* TODO: Handle REMOTE_WAKEUP */
10572 + } else if (crq->bRequestType == USB_RECIP_ENDPOINT) {
10573 + struct usba_ep *target;
10575 + if (!feature_is_ep_halt(crq)
10576 + || crq->wLength != __constant_cpu_to_le16(0))
10579 + target = get_ep_by_addr(udc, le16_to_cpu(crq->wIndex));
10583 + usba_ep_writel(target, SET_STA, USBA_BIT(FORCE_STALL));
10587 + send_status(udc, ep);
10591 + case USB_REQ_SET_ADDRESS:
10592 + if (crq->bRequestType != (USB_DIR_OUT | USB_RECIP_DEVICE))
10595 + set_address(udc, le16_to_cpu(crq->wValue));
10596 + send_status(udc, ep);
10597 + ep->state = STATUS_STAGE_ADDR;
10602 + return udc->driver->setup(&udc->gadget, crq);
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);
10618 +static void usba_control_irq(struct usba_udc *udc, struct usba_ep *ep)
10620 + struct usba_request *req;
10625 + epstatus = usba_ep_readl(ep, STA);
10626 + epctrl = usba_ep_readl(ep, CTL);
10628 + DBG(DBG_INT, "%s [%d]: s/%08x c/%08x\n",
10629 + ep_name(ep), ep->state, epstatus, epctrl);
10632 + if (!list_empty(&ep->queue))
10633 + req = list_entry(ep->queue.next,
10634 + struct usba_request, queue);
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);
10641 + submit_request(ep, req);
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));
10649 + if ((epstatus & epctrl) & USBA_BIT(TX_COMPLETE)) {
10650 + usba_ep_writel(ep, CLR_STA, USBA_BIT(TX_COMPLETE));
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;
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;
10665 + case STATUS_STAGE_IN:
10667 + list_del_init(&req->queue);
10668 + request_complete(ep, req, 0);
10669 + submit_next_request(ep);
10671 + usba_ep_writel(ep, CTL_DIS, USBA_BIT(TX_COMPLETE));
10672 + ep->state = WAIT_FOR_SETUP;
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);
10682 + "udc: %s: TXCOMP: Invalid endpoint state %d, "
10683 + "halting endpoint...\n",
10684 + ep_name(ep), ep->state);
10685 + set_protocol_stall(udc, ep);
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));
10698 + list_del_init(&req->queue);
10699 + request_complete(ep, req, 0);
10701 + ep->state = WAIT_FOR_SETUP;
10704 + case DATA_STAGE_OUT:
10705 + receive_data(ep);
10709 + usba_ep_writel(ep, CLR_STA, USBA_BIT(RX_BK_RDY));
10710 + usba_ep_writel(ep, CTL_DIS, USBA_BIT(RX_BK_RDY));
10712 + "udc: %s: RXRDY: Invalid endpoint state %d, "
10713 + "halting endpoint...\n",
10714 + ep_name(ep), ep->state);
10715 + set_protocol_stall(udc, ep);
10721 + if (epstatus & USBA_BIT(RX_SETUP)) {
10723 + struct usb_ctrlrequest crq;
10724 + unsigned long data[2];
10726 + unsigned int pkt_len;
10729 + if (ep->state != WAIT_FOR_SETUP) {
10731 + * Didn't expect a SETUP packet at this
10732 + * point. Clean up any pending requests (which
10733 + * may be successful).
10735 + int status = -EPROTO;
10738 + * RXRDY and TXCOMP are dropped when SETUP
10739 + * packets arrive. Just pretend we received
10740 + * the status packet.
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));
10750 + list_del_init(&req->queue);
10751 + request_complete(ep, req, status);
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);
10765 + DBG(DBG_FIFO, "Copying ctrl request from 0x%p:\n", ep->fifo);
10766 + copy_from_fifo(crq.data, ep->fifo, sizeof(crq));
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));
10772 + /* printk(KERN_DEBUG "setup: %d: %02x.%02x\n",
10773 + ep->state, crq.crq.bRequestType,
10774 + crq.crq.bRequest); */
10776 + if (crq.crq.bRequestType & USB_DIR_IN) {
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...
10783 + ep->state = DATA_STAGE_IN;
10785 + if (crq.crq.wLength != __constant_cpu_to_le16(0))
10786 + ep->state = DATA_STAGE_OUT;
10788 + ep->state = STATUS_STAGE_IN;
10792 + if (ep->index == 0)
10793 + ret = handle_ep0_setup(udc, ep, &crq.crq);
10795 + ret = udc->driver->setup(&udc->gadget, &crq.crq);
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);
10802 + /* Let the host know that we failed */
10803 + set_protocol_stall(udc, ep);
10808 +static void usba_ep_irq(struct usba_udc *udc, struct usba_ep *ep)
10810 + struct usba_request *req;
10814 + epstatus = usba_ep_readl(ep, STA);
10815 + epctrl = usba_ep_readl(ep, CTL);
10817 + DBG(DBG_INT, "%s: interrupt, status: 0x%08x\n",
10818 + ep_name(ep), epstatus);
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));
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));
10830 + req = list_entry(ep->queue.next, struct usba_request, queue);
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);
10842 + if (req->submitted)
10843 + next_fifo_transaction(ep, req);
10845 + submit_request(ep, req);
10847 + if (req->last_transaction) {
10848 + list_del_init(&req->queue);
10849 + submit_next_request(ep);
10850 + request_complete(ep, req, 0);
10854 + epstatus = usba_ep_readl(ep, STA);
10855 + epctrl = usba_ep_readl(ep, CTL);
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));
10864 +static void usba_dma_irq(struct usba_udc *udc, struct usba_ep *ep)
10866 + struct usba_request *req;
10867 + u32 status, control, pending;
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;
10874 + pending = status & control;
10875 + DBG(DBG_INT | DBG_DMA, "dma irq, s/%#08x, c/%#08x\n",
10876 + status, control);
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);
10886 + * try to pretend nothing happened. We might have to
10887 + * do something here...
10891 + if (list_empty(&ep->queue))
10892 + /* Might happen if a reset comes along at the right moment */
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);
10899 + list_del_init(&req->queue);
10900 + submit_next_request(ep);
10901 + request_complete(ep, req, 0);
10905 +static irqreturn_t usba_udc_irq(int irq, void *devid)
10907 + struct usba_udc *udc = devid;
10912 + spin_lock(&udc->lock);
10914 + status = usba_readl(udc, INT_STA);
10915 + DBG(DBG_INT, "irq, status=%#08x\n", status);
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);
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");
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);
10938 + dma_status = USBA_BFEXT(DMA_INT, status);
10939 + if (dma_status) {
10942 + for (i = 1; i < USBA_NR_ENDPOINTS; i++)
10943 + if (dma_status & (1 << i))
10944 + usba_dma_irq(udc, &usba_ep[i]);
10947 + ep_status = USBA_BFEXT(EPT_INT, status);
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]);
10956 + usba_ep_irq(udc, &usba_ep[i]);
10960 + if (status & USBA_BIT(END_OF_RESET)) {
10961 + struct usba_ep *ep0;
10963 + usba_writel(udc, INT_CLR, USBA_BIT(END_OF_RESET));
10964 + reset_all_endpoints(udc);
10966 + if (status & USBA_BIT(HIGH_SPEED)) {
10967 + DBG(DBG_BUS, "High-speed bus reset detected\n");
10968 + udc->gadget.speed = USB_SPEED_HIGH;
10970 + DBG(DBG_BUS, "Full-speed bus reset detected\n");
10971 + udc->gadget.speed = USB_SPEED_FULL;
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)));
10988 + if (!(usba_ep_readl(ep0, CFG) & USBA_BIT(EPT_MAPPED)))
10989 + dev_warn(&udc->pdev->dev,
10990 + "WARNING: EP0 configuration is invalid!\n");
10993 + spin_unlock(&udc->lock);
10995 + return IRQ_HANDLED;
10998 +static irqreturn_t usba_vbus_irq(int irq, void *devid)
11000 + struct usba_udc *udc = devid;
11006 + spin_lock(&udc->lock);
11007 + vbus = gpio_get_value(udc->vbus_pin);
11008 + if (vbus != udc->vbus_prev) {
11010 + usba_writel(udc, CTRL, USBA_BIT(EN_USBA));
11011 + usba_writel(udc, INT_ENB, USBA_BIT(END_OF_RESET));
11013 + udc->gadget.speed = USB_SPEED_UNKNOWN;
11014 + reset_all_endpoints(udc);
11015 + usba_writel(udc, CTRL, 0);
11017 + udc->driver->disconnect(&udc->gadget);
11019 + udc->vbus_prev = vbus;
11021 + spin_unlock(&udc->lock);
11023 + return IRQ_HANDLED;
11026 +int usb_gadget_register_driver(struct usb_gadget_driver *driver)
11028 + struct usba_udc *udc = &the_udc;
11029 + unsigned long flags;
11035 + spin_lock_irqsave(&udc->lock, flags);
11036 + if (udc->driver) {
11037 + spin_unlock_irqrestore(&udc->lock, flags);
11041 + udc->driver = driver;
11042 + udc->gadget.dev.driver = &driver->driver;
11043 + spin_unlock_irqrestore(&udc->lock, flags);
11045 + clk_enable(udc->pclk);
11046 + clk_enable(udc->hclk);
11048 + ret = driver->bind(&udc->gadget);
11050 + DBG(DBG_ERR, "Could not bind to driver %s: error %d\n",
11051 + driver->driver.name, ret);
11052 + goto err_driver_bind;
11055 + DBG(DBG_GADGET, "registered driver `%s'\n", driver->driver.name);
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);
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");
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));
11076 + spin_unlock_irqrestore(&udc->lock, flags);
11081 + udc->driver = NULL;
11082 + udc->gadget.dev.driver = NULL;
11085 +EXPORT_SYMBOL(usb_gadget_register_driver);
11087 +int usb_gadget_unregister_driver(struct usb_gadget_driver *driver)
11089 + struct usba_udc *udc = &the_udc;
11090 + unsigned long flags;
11094 + if (driver != udc->driver)
11097 + if (udc->vbus_pin != -1)
11098 + free_irq(gpio_to_irq(udc->vbus_pin), udc);
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);
11105 + /* This will also disable the DP pullup */
11106 + usba_writel(udc, CTRL, 0);
11108 + driver->unbind(&udc->gadget);
11109 + udc->gadget.dev.driver = NULL;
11110 + udc->driver = NULL;
11112 + clk_disable(udc->hclk);
11113 + clk_disable(udc->pclk);
11115 + DBG(DBG_GADGET, "unregistered driver `%s'\n", driver->driver.name);
11119 +EXPORT_SYMBOL(usb_gadget_unregister_driver);
11121 +static int __devinit usba_udc_probe(struct platform_device *pdev)
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;
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)
11134 + irq = platform_get_irq(pdev, 0);
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;
11147 + udc->pdev = pdev;
11148 + udc->pclk = pclk;
11149 + udc->hclk = hclk;
11150 + udc->vbus_pin = -1;
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;
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;
11165 + dev_info(&pdev->dev, "FIFO at 0x%08lx mapped at %p\n",
11166 + (unsigned long)fifo->start, udc->fifo);
11168 + device_initialize(&udc->gadget.dev);
11169 + udc->gadget.dev.parent = &pdev->dev;
11170 + udc->gadget.dev.dma_mask = pdev->dev.dma_mask;
11172 + platform_set_drvdata(pdev, udc);
11174 + /* Make sure we start from a clean slate */
11175 + clk_enable(pclk);
11176 + usba_writel(udc, CTRL, 0);
11177 + clk_disable(pclk);
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];
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);
11190 + list_add_tail(&ep->ep.ep_list, &udc->gadget.ep_list);
11193 + ret = request_irq(irq, usba_udc_irq, IRQF_SAMPLE_RANDOM,
11194 + "atmel_usba_udc", udc);
11196 + dev_err(&pdev->dev, "Cannot request irq %d (error %d)\n",
11198 + goto err_request_irq;
11202 + ret = device_add(&udc->gadget.dev);
11204 + dev_dbg(&pdev->dev, "Could not add gadget: %d\n", ret);
11205 + goto err_device_add;
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;
11212 + usba_init_debugfs(udc);
11213 + for (i = 1; i < ARRAY_SIZE(usba_ep); i++)
11214 + usba_ep_init_debugfs(udc, &usba_ep[i]);
11219 + free_irq(irq, udc);
11221 + iounmap(udc->fifo);
11223 + iounmap(udc->regs);
11229 + platform_set_drvdata(pdev, NULL);
11234 +static int __devexit usba_udc_remove(struct platform_device *pdev)
11236 + struct usba_udc *udc;
11239 + udc = platform_get_drvdata(pdev);
11241 + for (i = 1; i < ARRAY_SIZE(usba_ep); i++)
11242 + usba_ep_cleanup_debugfs(&usba_ep[i]);
11243 + usba_cleanup_debugfs(udc);
11245 + if (udc->vbus_pin != -1)
11246 + gpio_free(udc->vbus_pin);
11248 + free_irq(udc->irq, udc);
11249 + iounmap(udc->fifo);
11250 + iounmap(udc->regs);
11251 + clk_put(udc->hclk);
11252 + clk_put(udc->pclk);
11254 + device_unregister(&udc->gadget.dev);
11259 +static struct platform_driver udc_driver = {
11260 + .probe = usba_udc_probe,
11261 + .remove = __devexit_p(usba_udc_remove),
11263 + .name = "atmel_usba_udc",
11267 +static int __init udc_init(void)
11269 + return platform_driver_register(&udc_driver);
11271 +module_init(udc_init);
11273 +static void __exit udc_exit(void)
11275 + platform_driver_unregister(&udc_driver);
11277 +module_exit(udc_exit);
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
11286 +++ b/drivers/usb/gadget/atmel_usba_udc.h
11289 + * Driver for the Atmel USBA high speed USB device controller
11291 + * Copyright (C) 2005-2007 Atmel Corporation
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.
11297 +#ifndef __LINUX_USB_GADGET_USBA_UDC_H__
11298 +#define __LINUX_USB_GADGET_USBA_UDC_H__
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
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
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
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
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
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
11370 +/* Bitfields in EPT_RST */
11371 +#define USBA_RST_OFFSET 0
11372 +#define USBA_RST_SIZE 16
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
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
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
11392 +/* Bitfields in TST_MODE_REG */
11393 +#define USBA_TST_MODE_OFFSET 0
11394 +#define USBA_TST_MODE_SIZE 6
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
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
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
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
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
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
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
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
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
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
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))
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)
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)
11571 +/* Synth parameters */
11572 +#define USBA_NR_ENDPOINTS 7
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
11587 +enum usba_ctrl_state {
11592 + STATUS_STAGE_OUT,
11593 + STATUS_STAGE_ADDR,
11594 + STATUS_STAGE_TEST,
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,
11607 +struct usba_dma_desc {
11615 + void __iomem *ep_regs;
11616 + void __iomem *dma_regs;
11617 + void __iomem *fifo;
11618 + struct usb_ep ep;
11619 + struct usba_udc *udc;
11621 + struct list_head queue;
11622 + const struct usb_endpoint_descriptor *desc;
11627 + unsigned int can_dma:1;
11628 + unsigned int can_isoc:1;
11629 + unsigned int is_isoc:1;
11630 + unsigned int is_in:1;
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;
11641 +struct usba_request {
11642 + struct usb_request req;
11643 + struct list_head queue;
11647 + unsigned int submitted:1;
11648 + unsigned int last_transaction:1;
11649 + unsigned int using_dma:1;
11650 + unsigned int mapped:1;
11654 + /* Protect hw registers from concurrent modifications */
11657 + void __iomem *regs;
11658 + void __iomem *fifo;
11660 + struct usb_gadget gadget;
11661 + struct usb_gadget_driver *driver;
11662 + struct platform_device *pdev;
11665 + struct clk *pclk;
11666 + struct clk *hclk;
11671 +#ifdef CONFIG_DEBUG_FS
11672 + struct dentry *debugfs_root;
11673 + struct dentry *debugfs_regs;
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)
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)
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
11698 -#ifdef CONFIG_USB_GADGET_HUSB2DEV
11699 +#ifdef CONFIG_USB_GADGET_ATMEL_USBA
11700 #define DEV_CONFIG_CDC
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
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)
11716 -#define gadget_is_husb2dev(g) 0
11717 +#define gadget_is_atmel_usba(g) 0
11720 #ifdef CONFIG_USB_GADGET_S3C2410
11721 @@ -181,7 +181,7 @@ static inline int usb_gadget_controller_number(struct usb_gadget *gadget)
11723 else if (gadget_is_mpc8272(gadget))
11725 - else if (gadget_is_husb2dev(gadget))
11726 + else if (gadget_is_atmel_usba(gadget))
11728 else if (gadget_is_fsl_usb2(gadget))
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
11735 #include <linux/device.h>
11736 #include <linux/moduleparam.h>
11738 -#include <linux/usb_gadgetfs.h>
11739 +#include <linux/usb/gadgetfs.h>
11740 #include <linux/usb_gadget.h>
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.
11751 +config FB_ATMEL_STN
11752 + bool "Use a STN display with AT91/AT32 LCD Controller"
11753 + depends on FB_ATMEL && ARCH_AT91SAM9261
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.
11759 + If unsure, say N.
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
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)
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,
11786 .accel = FB_ACCEL_NONE,
11789 +static unsigned long compute_hozval(unsigned long xres, unsigned long lcdcon2)
11791 + unsigned long value;
11793 + if (!(cpu_is_at91sam9261() || cpu_is_at32ap7000()))
11797 + if ((lcdcon2 & ATMEL_LCDC_DISTYPE) != ATMEL_LCDC_DISTYPE_TFT) {
11798 + /* STN display */
11799 + if ((lcdcon2 & ATMEL_LCDC_DISTYPE) == ATMEL_LCDC_DISTYPE_STNCOLOR) {
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);
11807 + value = DIV_ROUND_UP(value, 8);
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;
11818 switch (var->bits_per_pixel) {
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;
11829 + var->transp.offset = 24;
11830 + var->transp.length = 8;
11831 + /* fall through */
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)
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;
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)
11849 lcdc_writel(sinfo, ATMEL_LCDC_DMACON, 0);
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;
11857 info->fix.visual = FB_VISUAL_TRUECOLOR;
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);
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;
11869 - value = clk_value_khz / PICOS2KHZ(info->var.pixclock);
11871 - if (clk_value_khz % PICOS2KHZ(info->var.pixclock))
11873 + value = DIV_ROUND_UP(clk_value_khz, PICOS2KHZ(info->var.pixclock));
11875 value = (value / 2) - 1;
11876 + dev_dbg(info->device, " * programming CLKVAL = 0x%08lx\n", value);
11879 dev_notice(info->device, "Bypassing pixel clock divider\n");
11880 lcdc_writel(sinfo, ATMEL_LCDC_LCDCON1, ATMEL_LCDC_BYPASS);
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));
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);
11896 + /* Horizontal value (aka line size) */
11897 + hozval_linesz = compute_hozval(info->var.xres,
11898 + lcdc_readl(sinfo, ATMEL_LCDC_LCDCON2));
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);
11907 /* FIFO Threshold: Use formula from data sheet */
11908 @@ -421,6 +463,15 @@ static int atmel_lcdfb_setcolreg(unsigned int regno, unsigned int red,
11913 + case FB_VISUAL_MONO01:
11915 + val = (regno == 0) ? 0x00 : 0x1F;
11916 + lcdc_writel(sinfo, ATMEL_LCDC_LUT(regno), val);
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.
11932 -config BACKLIGHT_CLASS_DEVICE
11933 - tristate "Lowlevel Backlight controls"
11937 +config LCD_CLASS_DEVICE
11938 + tristate "Lowlevel LCD controls"
11939 depends on BACKLIGHT_LCD_SUPPORT
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!)).
11949 To have support for your specific LCD panel you will have to
11950 select the proper drivers which depend on this option.
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
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
11964 + The LTV350QV panel is present on all ATSTK1000 boards.
11969 +config BACKLIGHT_CLASS_DEVICE
11970 + tristate "Lowlevel Backlight controls"
11971 depends on BACKLIGHT_LCD_SUPPORT
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.
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
11988 # Backlight & LCD drivers
11990 obj-$(CONFIG_LCD_CLASS_DEVICE) += lcd.o
11991 +obj-$(CONFIG_LCD_LTV350QV) += ltv350qv.o
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
12000 +++ b/drivers/video/backlight/ltv350qv.c
12003 + * Power control for Samsung LTV350QV Quarter VGA LCD Panel
12005 + * Copyright (C) 2006, 2007 Atmel Corporation
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.
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>
12019 +#include "ltv350qv.h"
12021 +#define POWER_IS_ON(pwr) ((pwr) <= FB_BLANK_NORMAL)
12024 + struct spi_device *spi;
12027 + struct lcd_device *ld;
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.
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.
12040 +static int ltv350qv_write_reg(struct ltv350qv *lcd, u8 reg, u16 val)
12042 + struct spi_message msg;
12043 + struct spi_transfer index_xfer = {
12047 + struct spi_transfer value_xfer = {
12052 + spi_message_init(&msg);
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);
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);
12068 + return spi_sync(lcd->spi, &msg);
12071 +/* The comments are taken straight from the data sheet */
12072 +static int ltv350qv_power_on(struct ltv350qv *lcd)
12076 + /* Power On Reset Display off State */
12077 + if (ltv350qv_write_reg(lcd, LTV_PWRCTL1, 0x0000))
12081 + /* Power Setting Function 1 */
12082 + if (ltv350qv_write_reg(lcd, LTV_PWRCTL1, LTV_VCOM_DISABLE))
12084 + if (ltv350qv_write_reg(lcd, LTV_PWRCTL2, LTV_VCOML_ENABLE))
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)))
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);
12124 + goto err_settings;
12126 + /* Wait more than 2 frames */
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));
12137 + goto err_disp_on;
12139 + /* Display should now be ON. Phew. */
12144 + * Try to recover. Error handling probably isn't very useful
12145 + * at this point, just make a best effort to switch the panel
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));
12156 + ltv350qv_write_reg(lcd, LTV_PWRCTL2, 0x0000);
12159 + ltv350qv_write_reg(lcd, LTV_PWRCTL1, LTV_VCOM_DISABLE);
12163 +static int ltv350qv_power_off(struct ltv350qv *lcd)
12167 + /* Display Off Sequence */
12168 + ret = ltv350qv_write_reg(lcd, LTV_PWRCTL1,
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));
12175 + /* Power down setting 1 */
12176 + ret |= ltv350qv_write_reg(lcd, LTV_PWRCTL2, 0x0000);
12178 + /* Wait at least 1 ms */
12181 + /* Power down setting 2 */
12182 + ret |= ltv350qv_write_reg(lcd, LTV_PWRCTL1, LTV_VCOM_DISABLE);
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?
12192 + /* Display power should now be OFF */
12196 +static int ltv350qv_power(struct ltv350qv *lcd, int power)
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);
12206 + lcd->power = power;
12211 +static int ltv350qv_set_power(struct lcd_device *ld, int power)
12213 + struct ltv350qv *lcd;
12215 + lcd = class_get_devdata(&ld->class_dev);
12216 + return ltv350qv_power(lcd, power);
12219 +static int ltv350qv_get_power(struct lcd_device *ld)
12221 + struct ltv350qv *lcd;
12223 + lcd = class_get_devdata(&ld->class_dev);
12224 + return lcd->power;
12227 +static struct lcd_ops ltv_ops = {
12228 + .get_power = ltv350qv_get_power,
12229 + .set_power = ltv350qv_set_power,
12232 +static int __devinit ltv350qv_probe(struct spi_device *spi)
12234 + struct ltv350qv *lcd;
12235 + struct lcd_device *ld;
12238 + lcd = kzalloc(sizeof(struct ltv350qv), GFP_KERNEL);
12243 + lcd->power = FB_BLANK_POWERDOWN;
12244 + lcd->buffer = kzalloc(8, GFP_KERNEL);
12246 + ld = lcd_device_register("ltv350qv", lcd, <v_ops);
12247 + if (IS_ERR(ld)) {
12248 + ret = PTR_ERR(ld);
12249 + goto out_free_lcd;
12253 + ret = ltv350qv_power(lcd, FB_BLANK_UNBLANK);
12255 + goto out_unregister;
12257 + dev_set_drvdata(&spi->dev, lcd);
12262 + lcd_device_unregister(ld);
12268 +static int __devexit ltv350qv_remove(struct spi_device *spi)
12270 + struct ltv350qv *lcd = dev_get_drvdata(&spi->dev);
12272 + ltv350qv_power(lcd, FB_BLANK_POWERDOWN);
12273 + lcd_device_unregister(lcd->ld);
12280 +static int ltv350qv_suspend(struct spi_device *spi,
12281 + pm_message_t state, u32 level)
12283 + struct ltv350qv *lcd = dev_get_drvdata(&spi->dev);
12285 + if (level == SUSPEND_POWER_DOWN)
12286 + return ltv350qv_power(lcd, FB_BLANK_POWERDOWN);
12291 +static int ltv350qv_resume(struct spi_device *spi, u32 level)
12293 + struct ltv350qv *lcd = dev_get_drvdata(&spi->dev);
12295 + if (level == RESUME_POWER_ON)
12296 + return ltv350qv_power(lcd, FB_BLANK_UNBLANK);
12301 +#define ltv350qv_suspend NULL
12302 +#define ltv350qv_resume NULL
12305 +/* Power down all displays on reboot, poweroff or halt */
12306 +static void ltv350qv_shutdown(struct spi_device *spi)
12308 + struct ltv350qv *lcd = dev_get_drvdata(&spi->dev);
12310 + ltv350qv_power(lcd, FB_BLANK_POWERDOWN);
12313 +static struct spi_driver ltv350qv_driver = {
12315 + .name = "ltv350qv",
12316 + .bus = &spi_bus_type,
12317 + .owner = THIS_MODULE,
12320 + .probe = ltv350qv_probe,
12321 + .remove = __devexit_p(ltv350qv_remove),
12322 + .shutdown = ltv350qv_shutdown,
12323 + .suspend = ltv350qv_suspend,
12324 + .resume = ltv350qv_resume,
12327 +static int __init ltv350qv_init(void)
12329 + return spi_register_driver(<v350qv_driver);
12332 +static void __exit ltv350qv_exit(void)
12334 + spi_unregister_driver(<v350qv_driver);
12336 +module_init(ltv350qv_init);
12337 +module_exit(ltv350qv_exit);
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
12346 +++ b/drivers/video/backlight/ltv350qv.h
12349 + * Register definitions for Samsung LTV350QV Quarter VGA LCD Panel
12351 + * Copyright (C) 2006, 2007 Atmel Corporation
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.
12357 +#ifndef __LTV350QV_H
12358 +#define __LTV350QV_H
12360 +#define LTV_OPC_INDEX 0x74
12361 +#define LTV_OPC_DATA 0x76
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 */
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)
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)
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)
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)
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)
12426 +/* Bit definitions for LTV_SOTCTL */
12427 +#define LTV_SDT(x) (((x) & 0x0007) << 10)
12428 +#define LTV_EQ(x) (((x) & 0x0007) << 2)
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 */
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 */
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)
12449 /* Ethernet (EMAC & MACB) */
12450 struct at91_eth_data {
12452 u8 phy_irq_pin; /* PHY IRQ */
12453 u8 is_rmii; /* using RMII interface? */
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
12461 #include <linux/types.h>
12463 +#define GPIO_PIN_NONE (-1)
12465 /* Add basic devices: system manager, interrupt controller, portmuxes, etc. */
12466 void at32_add_system_devices(void);
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);
12471 struct eth_platform_data {
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);
12480 +struct platform_device *at32_add_device_twi(unsigned int id);
12482 +struct mci_platform_data {
12486 +struct platform_device *
12487 +at32_add_device_mci(unsigned int id, struct mci_platform_data *data);
12489 +struct usba_platform_data {
12492 +struct platform_device *
12493 +at32_add_device_usba(unsigned int id, struct usba_platform_data *data);
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);
12500 +struct platform_device *at32_add_device_ac97c(unsigned int id);
12501 +struct platform_device *at32_add_device_abdac(unsigned int id);
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)
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)
12514 +struct platform_device *
12515 +at32_add_device_ssc(unsigned int id, unsigned int flags);
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);
12526 +#ifdef CONFIG_GPIO_DEV
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);
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);
12536 +#endif /* CONFIG_GPIO_DEV */
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
12546 - * AT32 System Manager interface.
12548 - * Copyright (C) 2006 Atmel Corporation
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.
12554 -#ifndef __ASM_AVR32_AT32_SM_H__
12555 -#define __ASM_AVR32_AT32_SM_H__
12558 -struct platform_device;
12562 - void __iomem *regs;
12563 - struct irq_chip *eim_chip;
12564 - unsigned int eim_first_irq;
12565 - struct platform_device *pdev;
12568 -extern struct platform_device at32_sm_device;
12569 -extern struct at32_sm system_manager;
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)
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)
12585 @@ -137,7 +137,7 @@ static inline int atomic_add_unless(atomic_t *v, int a, int u)
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)
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
12598 +++ b/include/asm-avr32/dma-controller.h
12601 + * Copyright (C) 2005-2006 Atmel Corporation
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.
12607 +#ifndef __ASM_AVR32_DMA_CONTROLLER_H
12608 +#define __ASM_AVR32_DMA_CONTROLLER_H
12610 +#include <linux/device.h>
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
12617 +#define DMA_WIDTH_8BIT 0
12618 +#define DMA_WIDTH_16BIT 1
12619 +#define DMA_WIDTH_32BIT 2
12621 +struct dma_request {
12622 + struct dma_controller *dmac;
12623 + struct list_head list;
12625 + unsigned short channel;
12627 + void (*xfer_complete)(struct dma_request *req);
12628 + void (*block_complete)(struct dma_request *req);
12629 + void (*error)(struct dma_request *req);
12632 +struct dma_request_sg {
12633 + struct dma_request req;
12636 + struct scatterlist *sg;
12637 + unsigned long block_size;
12638 + unsigned int nr_blocks;
12640 + dma_addr_t data_reg;
12641 + unsigned short periph_id;
12643 + unsigned char direction;
12644 + unsigned char width;
12646 +#define to_dma_request_sg(_req) \
12647 + container_of(_req, struct dma_request_sg, req)
12649 +struct dma_request_cyclic {
12650 + struct dma_request req;
12653 + unsigned long buffer_size;
12655 + dma_addr_t buffer_start;
12656 + dma_addr_t data_reg;
12658 + unsigned short periph_id;
12659 + unsigned char direction;
12660 + unsigned char width;
12664 +#define to_dma_request_cyclic(_req) \
12665 + container_of(_req, struct dma_request_cyclic, req)
12667 +struct dma_request_memcpy {
12668 + struct dma_request req;
12670 + dma_addr_t src_addr;
12671 + unsigned int src_width;
12672 + unsigned int src_stride;
12674 + dma_addr_t dst_addr;
12675 + unsigned int dst_width;
12676 + unsigned int dst_stride;
12680 + unsigned short src_reverse:1;
12681 + unsigned short dst_reverse:1;
12683 +#define to_dma_request_memcpy(_req) \
12684 + container_of(_req, struct dma_request_memcpy, req)
12686 +struct dma_controller {
12687 + struct list_head list;
12689 + struct device *dev;
12691 + int (*alloc_channel)(struct dma_controller *dmac);
12692 + void (*release_channel)(struct dma_controller *dmac,
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);
12709 +dma_alloc_channel(struct dma_controller *dmac)
12711 + return dmac->alloc_channel(dmac);
12714 +static inline void
12715 +dma_release_channel(struct dma_controller *dmac, int chan)
12717 + dmac->release_channel(dmac, chan);
12721 +dma_prepare_request_sg(struct dma_controller *dmac,
12722 + struct dma_request_sg *req)
12724 + return dmac->prepare_request_sg(dmac, req);
12728 +dma_prepare_request_cyclic(struct dma_controller *dmac,
12729 + struct dma_request_cyclic *req)
12731 + return dmac->prepare_request_cyclic(dmac, req);
12735 +dma_prepare_request_memcpy(struct dma_controller *dmac,
12736 + struct dma_request_memcpy *req)
12738 + return dmac->prepare_request_memcpy(dmac, req);
12742 +dma_start_request(struct dma_controller *dmac,
12743 + unsigned int channel)
12745 + return dmac->start_request(dmac, channel);
12749 +dma_stop_request(struct dma_controller *dmac,
12750 + unsigned int channel)
12752 + return dmac->stop_request(dmac, channel);
12755 +static inline dma_addr_t
12756 +dma_get_current_pos(struct dma_controller *dmac,
12757 + unsigned int channel)
12759 + return dmac->get_current_pos(dmac, channel);
12762 +extern int register_dma_controller(struct dma_controller *dmac);
12763 +extern struct dma_controller *find_dma_controller(int id);
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
12771 * words, but halfwords must be halfword-aligned, and doublewords must
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.
12779 -#include <linux/string.h>
12781 -/* Use memmove here, so gcc does not insert a __builtin_memcpy. */
12783 -#define get_unaligned(ptr) \
12784 - ({ __typeof__(*(ptr)) __tmp; memmove(&__tmp, (ptr), sizeof(*(ptr))); __tmp; })
12786 -#define put_unaligned(val, ptr) \
12787 - ({ __typeof__(*(ptr)) __tmp = (val); \
12788 - memmove((ptr), &__tmp, sizeof(*(ptr))); \
12790 +#include <asm-generic/unaligned.h>
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
12797 +++ b/include/linux/atmel-ssc.h
12799 +#ifndef __INCLUDE_ATMEL_SSC_H
12800 +#define __INCLUDE_ATMEL_SSC_H
12802 +#include <linux/platform_device.h>
12803 +#include <linux/list.h>
12805 +struct ssc_device {
12806 + struct list_head list;
12807 + void __iomem *regs;
12808 + struct platform_device *pdev;
12814 +struct ssc_device * __must_check ssc_request(unsigned int ssc_num);
12815 +void ssc_free(struct ssc_device *ssc);
12817 +/* SSC register offsets */
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
12832 +/* SSC Clock Mode Register */
12833 +#define SSC_CMR 0x00000004
12834 +#define SSC_CMR_DIV_SIZE 12
12835 +#define SSC_CMR_DIV_OFFSET 0
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
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
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
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
12909 +/* SSC Receive Hold Register */
12910 +#define SSC_RHR 0x00000020
12911 +#define SSC_RHR_RDAT_SIZE 32
12912 +#define SSC_RHR_RDAT_OFFSET 0
12914 +/* SSC Transmit Hold Register */
12915 +#define SSC_THR 0x00000024
12916 +#define SSC_THR_TDAT_SIZE 32
12917 +#define SSC_THR_TDAT_OFFSET 0
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
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
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
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
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
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
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
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
13051 +/* SSC PDC Receive Pointer Register */
13052 +#define SSC_PDC_RPR 0x00000100
13054 +/* SSC PDC Receive Counter Register */
13055 +#define SSC_PDC_RCR 0x00000104
13057 +/* SSC PDC Transmit Pointer Register */
13058 +#define SSC_PDC_TPR 0x00000108
13060 +/* SSC PDC Receive Next Pointer Register */
13061 +#define SSC_PDC_RNPR 0x00000110
13063 +/* SSC PDC Receive Next Counter Register */
13064 +#define SSC_PDC_RNCR 0x00000114
13066 +/* SSC PDC Transmit Counter Register */
13067 +#define SSC_PDC_TCR 0x0000010c
13069 +/* SSC PDC Transmit Next Pointer Register */
13070 +#define SSC_PDC_TNPR 0x00000118
13072 +/* SSC PDC Transmit Next Counter Register */
13073 +#define SSC_PDC_TNCR 0x0000011c
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
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
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))
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)
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
13115 +++ b/include/linux/gpio_mouse.h
13118 + * Driver for simulating a mouse on GPIO lines.
13120 + * Copyright (C) 2007 Atmel Corporation
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.
13127 +#ifndef _GPIO_MOUSE_H
13128 +#define _GPIO_MOUSE_H
13130 +#define GPIO_MOUSE_POLARITY_ACT_HIGH 0x00
13131 +#define GPIO_MOUSE_POLARITY_ACT_LOW 0x01
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
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.
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.
13158 +struct gpio_mouse_platform_data {
13173 + int pins[GPIO_MOUSE_PIN_MAX];
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)
13186 +/* For the leds-gpio driver */
13188 + const char *name;
13189 + char *default_trigger;
13194 +struct gpio_led_platform_data {
13196 + struct gpio_led *leds;
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
13205 +++ b/include/linux/spi/at73c213.h
13208 + * Board-specific data used to set up AT73c213 audio DAC driver.
13211 +#ifndef __LINUX_SPI_AT73C213_H
13212 +#define __LINUX_SPI_AT73C213_H
13215 + * at73c213_board_info - how the external DAC is wired to the device.
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.
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.
13225 +struct at73c213_board_info {
13227 + struct clk *dac_clk;
13228 + char shortname[32];
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
13237 unifdef-y += audio.h
13240 +unifdef-y += gadgetfs.h
13241 unifdef-y += midi.h
13243 diff --git a/include/linux/usb/gadgetfs.h b/include/linux/usb/gadgetfs.h
13244 new file mode 100644
13245 index 0000000..e8654c3
13247 +++ b/include/linux/usb/gadgetfs.h
13249 +#ifndef __LINUX_USB_GADGETFS_H
13250 +#define __LINUX_USB_GADGETFS_H
13252 +#include <asm/types.h>
13253 +#include <asm/ioctl.h>
13255 +#include <linux/usb/ch9.h>
13258 + * Filesystem based user-mode API to USB Gadget controller hardware
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.
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.
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.
13280 +enum usb_gadgetfs_event_type {
13281 + GADGETFS_NOP = 0,
13283 + GADGETFS_CONNECT,
13284 + GADGETFS_DISCONNECT,
13286 + GADGETFS_SUSPEND,
13287 + // and likely more !
13290 +/* NOTE: this structure must stay the same size and layout on
13291 + * both 32-bit and 64-bit kernels.
13293 +struct usb_gadgetfs_event {
13295 + // NOP, DISCONNECT, SUSPEND: nothing
13296 + // ... some hardware can't report disconnection
13298 + // CONNECT: just the speed
13299 + enum usb_device_speed speed;
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;
13306 + enum usb_gadgetfs_event_type type;
13310 +/* endpoint ioctls */
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)
13319 +#define GADGETFS_FIFO_STATUS _IO('g',1)
13321 +/* discards any unclaimed data in the fifo. */
13322 +#define GADGETFS_FIFO_FLUSH _IO('g',2)
13324 +/* resets endpoint halt+toggle; used to implement set_interface.
13325 + * some hardware (like pxa2xx) can't support this.
13327 +#define GADGETFS_CLEAR_HALT _IO('g',3)
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
13337 -#include <asm/types.h>
13338 -#include <asm/ioctl.h>
13340 -#include <linux/usb/ch9.h>
13343 - * Filesystem based user-mode API to USB Gadget controller hardware
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.
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.
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.
13364 -enum usb_gadgetfs_event_type {
13365 - GADGETFS_NOP = 0,
13367 - GADGETFS_CONNECT,
13368 - GADGETFS_DISCONNECT,
13370 - GADGETFS_SUSPEND,
13371 - // and likely more !
13374 -struct usb_gadgetfs_event {
13375 - enum usb_gadgetfs_event_type type;
13377 - // NOP, DISCONNECT, SUSPEND: nothing
13378 - // ... some hardware can't report disconnection
13380 - // CONNECT: just the speed
13381 - enum usb_device_speed speed;
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;
13391 -/* endpoint ioctls */
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)
13400 -#define GADGETFS_FIFO_STATUS _IO('g',1)
13402 -/* discards any unclaimed data in the fifo. */
13403 -#define GADGETFS_FIFO_FLUSH _IO('g',2)
13405 -/* resets endpoint halt+toggle; used to implement set_interface.
13406 - * some hardware (like pxa2xx) can't support this.
13408 -#define GADGETFS_CLEAR_HALT _IO('g',3)
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;
13423 @@ -216,6 +217,14 @@ static int __init root_dev_setup(char *line)
13425 __setup("root=", root_dev_setup);
13427 +static int __init rootwait_setup(char *line)
13429 + root_wait = simple_strtol(line,NULL,0);
13433 +__setup("rootwait=", rootwait_setup);
13435 static char * __initdata root_mount_data;
13436 static int __init root_data_setup(char *str)
13438 @@ -438,11 +447,24 @@ void __init prepare_namespace(void)
13439 root_device_name += 5;
13442 - is_floppy = MAJOR(ROOT_DEV) == FLOPPY_MAJOR;
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);
13452 + while (driver_probe_done() != 0)
13454 + ROOT_DEV = name_to_dev_t(saved_root_name);
13455 + if (ROOT_DEV == 0)
13457 + } while (ROOT_DEV == 0);
13460 + is_floppy = MAJOR(ROOT_DEV) == FLOPPY_MAJOR;
13462 if (is_floppy && rd_doload && rd_load_disk(0))
13463 ROOT_DEV = Root_RAM0;
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
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>
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"
13494 source "sound/arm/Kconfig"
13497 +source "sound/spi/Kconfig"
13500 source "sound/mips/Kconfig"
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"
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/
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
13525 +++ b/sound/spi/Kconfig
13529 +menu "SPI devices"
13530 + depends on SND != n
13532 +config SND_AT73C213
13533 + tristate "Atmel AT73C213 DAC driver"
13534 + depends on ATMEL_SSC
13537 + Say Y here if you want to use the Atmel AT73C213 external DAC. This
13538 + DAC can be found on Atmel development boards.
13540 + This driver requires the Atmel SSC driver for sound sink, a
13541 + peripheral found on most AT91 and AVR32 microprocessors.
13543 + To compile this driver as a module, choose M here: the module will be
13544 + called snd-at73c213.
13546 +config SND_AT73C213_TARGET_BITRATE
13547 + int "Target bitrate for AT73C213"
13548 + depends on SND_AT73C213
13552 + Sets the target bitrate for the bitrate calculator in the driver.
13553 + Limited by hardware to be between 8000 Hz and 50000 Hz.
13555 + Set to 48000 Hz by default.
13558 diff --git a/sound/spi/Makefile b/sound/spi/Makefile
13559 new file mode 100644
13560 index 0000000..026fb73
13562 +++ b/sound/spi/Makefile
13564 +# Makefile for SPI drivers
13566 +snd-at73c213-objs := at73c213.o
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
13573 +++ b/sound/spi/at73c213.c
13576 + * Driver for AT73C213 16-bit stereo DAC connected to Atmel SSC
13578 + * Copyright (C) 2006-2007 Atmel Norway
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.
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>
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>
13604 +#include <linux/atmel-ssc.h>
13606 +#include <linux/spi/spi.h>
13607 +#include <linux/spi/at73c213.h>
13609 +#include "at73c213.h"
13611 +#define BITRATE_MIN 8000 /* Hardware limit? */
13612 +#define BITRATE_TARGET CONFIG_SND_AT73C213_TARGET_BITRATE
13613 +#define BITRATE_MAX 50000 /* Hardware limit. */
13615 +/* Initial (hardware reset) AT73C213 register values. */
13616 +static u8 snd_at73c213_original_image[18] =
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 */
13630 + 0x00, /* 0C - PRECH */
13631 + 0x05, /* 0D - AUXG */
13634 + 0x00, /* 10 - RST */
13635 + 0x00, /* 11 - PA_CTRL */
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;
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. */
13657 +#define get_chip(card) ((struct snd_at73c213 *)card->private_data)
13660 +snd_at73c213_write_reg(struct snd_at73c213 *chip, u8 reg, u8 val)
13662 + struct spi_message msg;
13663 + struct spi_transfer msg_xfer = {
13669 + spi_message_init(&msg);
13671 + chip->spi_wbuffer[0] = reg;
13672 + chip->spi_wbuffer[1] = val;
13674 + msg_xfer.tx_buf = chip->spi_wbuffer;
13675 + msg_xfer.rx_buf = chip->spi_rbuffer;
13676 + spi_message_add_tail(&msg_xfer, &msg);
13678 + retval = spi_sync(chip->spi, &msg);
13681 + chip->reg_image[reg] = val;
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,
13703 + * Calculate and set bitrate and divisions.
13705 +static int snd_at73c213_set_bitrate(struct snd_at73c213 *chip)
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;
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.
13717 + * The DAC master clock (MCLK) is programmable, and is either 256
13718 + * or (not here) 384 times the I2S output clock (BCLK).
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;
13727 + if (max_tries < 1)
13730 + /* ssc_div must be a power of 2. */
13731 + ssc_div = (ssc_div + 1) & ~1UL;
13733 + if ((ssc_rate / (ssc_div * 2 * 16)) < BITRATE_MIN) {
13735 + if ((ssc_rate / (ssc_div * 2 * 16)) > BITRATE_MAX)
13739 + /* Search for a possible bitrate. */
13741 + /* SSC clock / (ssc divider * 16-bit * stereo). */
13742 + if ((ssc_rate / (ssc_div * 2 * 16)) < BITRATE_MIN)
13745 + /* 256 / (2 * 16) = 8 */
13746 + dac_rate_new = 8 * (ssc_rate / ssc_div);
13748 + status = clk_round_rate(chip->board->dac_clk, dac_rate_new);
13752 + /* Ignore difference smaller than 256 Hz. */
13753 + if ((status/256) == (dac_rate_new/256))
13757 + } while (--max_tries);
13759 + /* Not able to find a valid bitrate. */
13763 + status = clk_set_rate(chip->board->dac_clk, status);
13767 + /* Set divider in SSC device. */
13768 + ssc_writel(chip->ssc->regs, CMR, ssc_div/2);
13770 + /* SSC clock / (ssc divider * 16-bit * stereo). */
13771 + chip->bitrate = ssc_rate / (ssc_div * 16 * 2);
13773 + dev_info(&chip->spi->dev,
13774 + "at73c213: supported bitrate is %lu (%lu divider)\n",
13775 + chip->bitrate, ssc_div);
13780 +static int snd_at73c213_pcm_open(struct snd_pcm_substream *substream)
13782 + struct snd_at73c213 *chip = snd_pcm_substream_chip(substream);
13783 + struct snd_pcm_runtime *runtime = substream->runtime;
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;
13793 +static int snd_at73c213_pcm_close(struct snd_pcm_substream *substream)
13795 + struct snd_at73c213 *chip = snd_pcm_substream_chip(substream);
13796 + chip->substream = NULL;
13800 +static int snd_at73c213_pcm_hw_params(struct snd_pcm_substream *substream,
13801 + struct snd_pcm_hw_params *hw_params)
13803 + return snd_pcm_lib_malloc_pages(substream,
13804 + params_buffer_bytes(hw_params));
13807 +static int snd_at73c213_pcm_hw_free(struct snd_pcm_substream *substream)
13809 + return snd_pcm_lib_free_pages(substream);
13812 +static int snd_at73c213_pcm_prepare(struct snd_pcm_substream *substream)
13814 + struct snd_at73c213 *chip = snd_pcm_substream_chip(substream);
13815 + struct snd_pcm_runtime *runtime = substream->runtime;
13818 + block_size = frames_to_bytes(runtime, runtime->period_size);
13820 + chip->period = 0;
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);
13832 +static int snd_at73c213_pcm_trigger(struct snd_pcm_substream *substream,
13835 + struct snd_at73c213 *chip = snd_pcm_substream_chip(substream);
13838 + spin_lock(&chip->lock);
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));
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));
13850 + dev_dbg(&chip->spi->dev, "spurious command %x\n", cmd);
13851 + retval = -EINVAL;
13855 + spin_unlock(&chip->lock);
13860 +static snd_pcm_uframes_t
13861 +snd_at73c213_pcm_pointer(struct snd_pcm_substream *substream)
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;
13868 + bytes = ssc_readl(chip->ssc->regs, PDC_TPR)
13869 + - (unsigned long)runtime->dma_addr;
13871 + pos = bytes_to_frames(runtime, bytes);
13872 + if (pos >= runtime->buffer_size)
13873 + pos -= runtime->buffer_size;
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,
13889 +static void snd_at73c213_pcm_free(struct snd_pcm *pcm)
13891 + struct snd_at73c213 *chip = snd_pcm_chip(pcm);
13893 + snd_pcm_lib_preallocate_free_for_all(chip->pcm);
13894 + chip->pcm = NULL;
13898 +static int __devinit snd_at73c213_pcm_new(struct snd_at73c213 *chip, int device)
13900 + struct snd_pcm *pcm;
13903 + retval = snd_pcm_new(chip->card, chip->card->shortname,
13904 + device, 1, 0, &pcm);
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");
13914 + snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &at73c213_playback_ops);
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);
13923 +static irqreturn_t snd_at73c213_interrupt(int irq, void *dev_id)
13925 + struct snd_at73c213 *chip = dev_id;
13926 + struct snd_pcm_runtime *runtime = chip->substream->runtime;
13931 + int retval = IRQ_NONE;
13933 + spin_lock(&chip->lock);
13935 + block_size = frames_to_bytes(runtime, runtime->period_size);
13936 + status = ssc_readl(chip->ssc->regs, IMR);
13938 + if (status & SSC_BIT(IMR_ENDTX)) {
13940 + if (chip->period == runtime->periods)
13941 + chip->period = 0;
13942 + next_period = chip->period + 1;
13943 + if (next_period == runtime->periods)
13946 + offset = block_size * next_period;
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;
13954 + ssc_readl(chip->ssc->regs, IMR);
13955 + spin_unlock(&chip->lock);
13957 + if (status & SSC_BIT(IMR_ENDTX))
13958 + snd_pcm_period_elapsed(chip->substream);
13964 + * Mixer functions.
13966 +static int snd_at73c213_mono_get(struct snd_kcontrol *kcontrol,
13967 + struct snd_ctl_elem_value *ucontrol)
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;
13975 + spin_lock_irq(&chip->lock);
13977 + ucontrol->value.integer.value[0] = (chip->reg_image[reg] >> shift) & mask;
13980 + ucontrol->value.integer.value[0] =
13981 + (mask - ucontrol->value.integer.value[0]);
13983 + spin_unlock_irq(&chip->lock);
13988 +static int snd_at73c213_mono_put(struct snd_kcontrol *kcontrol,
13989 + struct snd_ctl_elem_value *ucontrol)
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;
13999 + val = (ucontrol->value.integer.value[0] & mask);
14001 + val = mask - val;
14004 + spin_lock_irq(&chip->lock);
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);
14010 + spin_unlock_irq(&chip->lock);
14018 +static int snd_at73c213_stereo_info(struct snd_kcontrol *kcontrol,
14019 + struct snd_ctl_elem_info *uinfo)
14021 + int mask = (kcontrol->private_value >> 24) & 0xff;
14024 + uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
14026 + uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
14028 + uinfo->count = 2;
14029 + uinfo->value.integer.min = 0;
14030 + uinfo->value.integer.max = mask;
14035 +static int snd_at73c213_stereo_get(struct snd_kcontrol *kcontrol,
14036 + struct snd_ctl_elem_value *ucontrol)
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;
14046 + spin_lock_irq(&chip->lock);
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;
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]);
14060 + spin_unlock_irq(&chip->lock);
14065 +static int snd_at73c213_stereo_put(struct snd_kcontrol *kcontrol,
14066 + struct snd_ctl_elem_value *ucontrol)
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;
14078 + val1 = ucontrol->value.integer.value[0] & mask;
14079 + val2 = ucontrol->value.integer.value[1] & mask;
14081 + val1 = mask - val1;
14082 + val2 = mask - val2;
14084 + val1 <<= shift_left;
14085 + val2 <<= shift_right;
14087 + spin_lock_irq(&chip->lock);
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);
14095 + spin_unlock_irq(&chip->lock);
14098 + retval = snd_at73c213_write_reg(chip, right_reg, val2);
14100 + spin_unlock_irq(&chip->lock);
14104 + spin_unlock_irq(&chip->lock);
14112 +static int snd_at73c213_mono_switch_info(struct snd_kcontrol *kcontrol,
14113 + struct snd_ctl_elem_info *uinfo)
14115 + uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
14116 + uinfo->count = 1;
14117 + uinfo->value.integer.min = 0;
14118 + uinfo->value.integer.max = 1;
14123 +static int snd_at73c213_mono_switch_get(struct snd_kcontrol *kcontrol,
14124 + struct snd_ctl_elem_value *ucontrol)
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;
14131 + spin_lock_irq(&chip->lock);
14133 + ucontrol->value.integer.value[0] = (chip->reg_image[reg] >> shift) & 0x01;
14136 + ucontrol->value.integer.value[0] =
14137 + (0x01 - ucontrol->value.integer.value[0]);
14139 + spin_unlock_irq(&chip->lock);
14144 +static int snd_at73c213_mono_switch_put(struct snd_kcontrol *kcontrol,
14145 + struct snd_ctl_elem_value *ucontrol)
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;
14155 + if (ucontrol->value.integer.value[0])
14161 + val = mask - val;
14164 + spin_lock_irq(&chip->lock);
14166 + val |= (chip->reg_image[reg] & ~(mask << shift));
14167 + change = val != chip->reg_image[reg];
14169 + retval = snd_at73c213_write_reg(chip, reg, val);
14171 + spin_unlock_irq(&chip->lock);
14179 +static int snd_at73c213_pa_volume_info(struct snd_kcontrol *kcontrol,
14180 + struct snd_ctl_elem_info *uinfo)
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;
14190 +static int snd_at73c213_line_capture_volume_info(
14191 + struct snd_kcontrol *kcontrol,
14192 + struct snd_ctl_elem_info *uinfo)
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;
14203 +static int snd_at73c213_aux_capture_volume_info(
14204 + struct snd_kcontrol *kcontrol,
14205 + struct snd_ctl_elem_info *uinfo)
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;
14216 +#define AT73C213_MONO_SWITCH(xname, xindex, reg, shift, mask, invert) \
14218 + .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
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)) \
14227 +#define AT73C213_STEREO(xname, xindex, left_reg, right_reg, shift_left, shift_right, mask, invert) \
14229 + .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
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)) \
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),
14247 + .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
14248 + .name = "PA Playback Volume",
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),
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),
14258 + .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
14259 + .name = "Aux Capture Volume",
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),
14266 +AT73C213_MONO_SWITCH("Aux Capture Switch", 0, DAC_CTRL, DAC_CTRL_ONAUXIN, 0x01, 0),
14268 + .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
14269 + .name = "Line Capture Volume",
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),
14277 +AT73C213_MONO_SWITCH("Line Capture Switch", 0, DAC_CTRL, 0, 0x03, 0),
14280 +static int __devinit snd_at73c213_mixer(struct snd_at73c213 *chip)
14282 + struct snd_card *card;
14285 + if (chip == NULL || chip->pcm == NULL)
14288 + card = chip->card;
14290 + strcpy(card->mixername, chip->pcm->name);
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],
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);
14307 + snd_ctl_remove(card, kctl);
14313 + * Device functions
14315 +static int snd_at73c213_ssc_init(struct snd_at73c213 *chip)
14318 + * Continuous clock output.
14319 + * Starts on falling TF.
14320 + * Delay 1 cycle (1 bit).
14321 + * Periode is 16 bit (16 - 1).
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));
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.
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));
14345 +static int snd_at73c213_chip_init(struct snd_at73c213 *chip)
14348 + unsigned char dac_ctrl = 0;
14350 + retval = snd_at73c213_set_bitrate(chip);
14354 + /* Enable DAC master clock. */
14355 + clk_enable(chip->board->dac_clk);
14357 + /* Initialize at73c213 on SPI bus. */
14358 + retval = snd_at73c213_write_reg(chip, DAC_RST, 0x04);
14362 + retval = snd_at73c213_write_reg(chip, DAC_RST, 0x03);
14366 + /* Precharge everything. */
14367 + retval = snd_at73c213_write_reg(chip, DAC_PRECH, 0xff);
14370 + retval = snd_at73c213_write_reg(chip, PA_CTRL, (1<<PA_CTRL_APAPRECH));
14373 + retval = snd_at73c213_write_reg(chip, DAC_CTRL,
14374 + (1<<DAC_CTRL_ONLNOL) | (1<<DAC_CTRL_ONLNOR));
14380 + /* Stop precharging PA. */
14381 + retval = snd_at73c213_write_reg(chip, PA_CTRL,
14382 + (1<<PA_CTRL_APALP) | 0x0f);
14388 + /* Stop precharging DAC, turn on master power. */
14389 + retval = snd_at73c213_write_reg(chip, DAC_PRECH, (1<<DAC_PRECH_ONMSTR));
14395 + /* Turn on DAC. */
14396 + dac_ctrl = (1<<DAC_CTRL_ONDACL) | (1<<DAC_CTRL_ONDACR)
14397 + | (1<<DAC_CTRL_ONLNOL) | (1<<DAC_CTRL_ONLNOR);
14399 + retval = snd_at73c213_write_reg(chip, DAC_CTRL, dac_ctrl);
14403 + /* Mute sound. */
14404 + retval = snd_at73c213_write_reg(chip, DAC_LMPG, 0x3f);
14407 + retval = snd_at73c213_write_reg(chip, DAC_RMPG, 0x3f);
14410 + retval = snd_at73c213_write_reg(chip, DAC_LLOG, 0x3f);
14413 + retval = snd_at73c213_write_reg(chip, DAC_RLOG, 0x3f);
14416 + retval = snd_at73c213_write_reg(chip, DAC_LLIG, 0x11);
14419 + retval = snd_at73c213_write_reg(chip, DAC_RLIG, 0x11);
14422 + retval = snd_at73c213_write_reg(chip, DAC_AUXG, 0x11);
14426 + /* Enable I2S device, i.e. clock output. */
14427 + ssc_writel(chip->ssc->regs, CR, SSC_BIT(CR_TXEN));
14432 + clk_disable(chip->board->dac_clk);
14437 +static int snd_at73c213_dev_free(struct snd_device *device)
14439 + struct snd_at73c213 *chip = device->device_data;
14441 + ssc_writel(chip->ssc->regs, CR, SSC_BIT(CR_TXDIS));
14442 + if (chip->irq >= 0) {
14443 + free_irq(chip->irq, chip);
14450 +static int __devinit snd_at73c213_dev_init(struct snd_card *card,
14451 + struct spi_device *spi)
14453 + static struct snd_device_ops ops = {
14454 + .dev_free = snd_at73c213_dev_free,
14456 + struct snd_at73c213 *chip = get_chip(card);
14459 + irq = chip->ssc->irq;
14463 + spin_lock_init(&chip->lock);
14464 + chip->card = card;
14467 + retval = request_irq(irq, snd_at73c213_interrupt, 0, "at73c213", chip);
14469 + dev_dbg(&chip->spi->dev, "unable to request irq %d\n", irq);
14474 + memcpy(&chip->reg_image, &snd_at73c213_original_image,
14475 + sizeof(snd_at73c213_original_image));
14477 + retval = snd_at73c213_ssc_init(chip);
14481 + retval = snd_at73c213_chip_init(chip);
14485 + retval = snd_at73c213_pcm_new(chip, 0);
14489 + retval = snd_device_new(card, SNDRV_DEV_LOWLEVEL, chip, &ops);
14493 + retval = snd_at73c213_mixer(chip);
14495 + goto out_snd_dev;
14497 + snd_card_set_dev(card, &spi->dev);
14502 + snd_device_free(card, chip);
14504 + free_irq(chip->irq, chip);
14510 +static int snd_at73c213_probe(struct spi_device *spi)
14512 + struct snd_card *card;
14513 + struct snd_at73c213 *chip;
14514 + struct at73c213_board_info *board;
14518 + board = spi->dev.platform_data;
14520 + dev_dbg(&spi->dev, "no platform_data\n");
14524 + if (!board->dac_clk) {
14525 + dev_dbg(&spi->dev, "no DAC clk\n");
14529 + if (IS_ERR(board->dac_clk)) {
14530 + dev_dbg(&spi->dev, "no DAC clk\n");
14531 + return PTR_ERR(board->dac_clk);
14534 + retval = -ENOMEM;
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));
14542 + chip = card->private_data;
14544 + chip->board = board;
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",
14550 + retval = PTR_ERR(chip->ssc);
14554 + retval = snd_at73c213_dev_init(card, spi);
14558 + strcpy(card->driver, "at73c213");
14559 + strcpy(card->shortname, board->shortname);
14560 + sprintf(card->longname, "%s on irq %d", card->shortname, chip->irq);
14562 + retval = snd_card_register(card);
14566 + dev_set_drvdata(&spi->dev, card);
14571 + ssc_free(chip->ssc);
14573 + snd_card_free(card);
14578 +static int __devexit snd_at73c213_remove(struct spi_device *spi)
14580 + struct snd_card *card = dev_get_drvdata(&spi->dev);
14581 + struct snd_at73c213 *chip = card->private_data;
14584 + /* Stop playback. */
14585 + ssc_writel(chip->ssc->regs, CR, SSC_BIT(CR_TXDIS));
14587 + /* Mute sound. */
14588 + retval = snd_at73c213_write_reg(chip, DAC_LMPG, 0x3f);
14591 + retval = snd_at73c213_write_reg(chip, DAC_RMPG, 0x3f);
14594 + retval = snd_at73c213_write_reg(chip, DAC_LLOG, 0x3f);
14597 + retval = snd_at73c213_write_reg(chip, DAC_RLOG, 0x3f);
14600 + retval = snd_at73c213_write_reg(chip, DAC_LLIG, 0x11);
14603 + retval = snd_at73c213_write_reg(chip, DAC_RLIG, 0x11);
14606 + retval = snd_at73c213_write_reg(chip, DAC_AUXG, 0x11);
14610 + /* Turn off PA. */
14611 + retval = snd_at73c213_write_reg(chip, PA_CTRL, (chip->reg_image[PA_CTRL]|0x0f));
14615 + retval = snd_at73c213_write_reg(chip, PA_CTRL, (1<<PA_CTRL_APALP)|0x0f);
14619 + /* Turn off external DAC. */
14620 + retval = snd_at73c213_write_reg(chip, DAC_CTRL, 0x0c);
14624 + retval = snd_at73c213_write_reg(chip, DAC_CTRL, 0x00);
14628 + /* Turn off master power. */
14629 + retval = snd_at73c213_write_reg(chip, DAC_PRECH, 0x00);
14634 + /* Stop DAC master clock. */
14635 + clk_disable(chip->board->dac_clk);
14637 + ssc_free(chip->ssc);
14638 + snd_card_free(card);
14639 + dev_set_drvdata(&spi->dev, NULL);
14645 +static int snd_at73c213_suspend(struct spi_device *spi, pm_message_t msg)
14647 + struct snd_card *card = dev_get_drvdata(&spi->dev);
14648 + struct snd_at73c213 *chip = card->private_data;
14650 + ssc_writel(chip->ssc->regs, CR, SSC_BIT(CR_TXDIS));
14651 + clk_disable(chip->board->dac_clk);
14656 +static int snd_at73c213_resume(struct spi_device *spi)
14658 + struct snd_card *card = dev_get_drvdata(&spi->dev);
14659 + struct snd_at73c213 *chip = card->private_data;
14661 + clk_enable(chip->board->dac_clk);
14662 + ssc_writel(chip->ssc->regs, CR, SSC_BIT(CR_TXEN));
14667 +#define snd_at73c213_suspend NULL
14668 +#define snd_at73c213_resume NULL
14671 +static struct spi_driver at73c213_driver = {
14673 + .name = "at73c213",
14675 + .probe = snd_at73c213_probe,
14676 + .suspend = snd_at73c213_suspend,
14677 + .resume = snd_at73c213_resume,
14678 + .remove = __devexit_p(snd_at73c213_remove),
14681 +static int __init at73c213_init(void)
14683 + return spi_register_driver(&at73c213_driver);
14685 +module_init(at73c213_init);
14687 +static void __exit at73c213_exit(void)
14689 + spi_unregister_driver(&at73c213_driver);
14691 +module_exit(at73c213_exit);
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
14700 +++ b/sound/spi/at73c213.h
14703 + * Driver for the AT73C213 16-bit stereo DAC on Atmel ATSTK1000
14705 + * Copyright (C) 2006 - 2007 Atmel Corporation
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.
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.
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.
14722 + * The full GNU General Public License is included in this
14723 + * distribution in the file called COPYING.
14726 +#ifndef _SND_AT73C213_H
14727 +#define _SND_AT73C213_H
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
14740 +/* DAC left line in gain register */
14741 +#define DAC_LLIG 0x01
14742 +#define DAC_LLIG_LLIG 0
14744 +/* DAC right line in gain register */
14745 +#define DAC_RLIG 0x02
14746 +#define DAC_RLIG_RLIG 0
14748 +/* DAC Left Master Playback Gain Register */
14749 +#define DAC_LMPG 0x03
14750 +#define DAC_LMPG_LMPG 0
14752 +/* DAC Right Master Playback Gain Register */
14753 +#define DAC_RMPG 0x04
14754 +#define DAC_RMPG_RMPG 0
14756 +/* DAC Left Line Out Gain Register */
14757 +#define DAC_LLOG 0x05
14758 +#define DAC_LLOG_LLOG 0
14760 +/* DAC Right Line Out Gain Register */
14761 +#define DAC_RLOG 0x06
14762 +#define DAC_RLOG_RLOG 0
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
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
14780 +/* DAC Clock and Sampling Frequency Control Register */
14781 +#define DAC_CSFC 0x09
14782 +#define DAC_CSFC_OVRSEL 4
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
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
14803 +/* DAC Auxiliary Input Gain Control Register */
14804 +#define DAC_AUXG 0x0D
14805 +#define DAC_AUXG_AUXG 0
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
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
14820 +#endif /* _SND_AT73C213_H */