3 arch/avr32/Kconfig | 7 +
4 arch/avr32/Makefile | 1 +
5 arch/avr32/boards/atngw100/Kconfig | 12 +
6 arch/avr32/boards/atngw100/flash.c | 5 +-
7 arch/avr32/boards/atngw100/setup.c | 26 +-
8 arch/avr32/boards/atstk1000/Kconfig | 12 +
9 arch/avr32/boards/atstk1000/atstk1002.c | 72 ++
10 arch/avr32/boards/atstk1000/flash.c | 5 +-
11 arch/avr32/configs/atngw100_defconfig | 201 +++-
12 arch/avr32/configs/atstk1002_defconfig | 354 +++++-
13 arch/avr32/drivers/Makefile | 1 +
14 arch/avr32/drivers/dw-dmac.c | 761 ++++++++++++
15 arch/avr32/drivers/dw-dmac.h | 42 +
16 arch/avr32/kernel/Makefile | 6 +-
17 arch/avr32/kernel/dma-controller.c | 34 +
18 arch/avr32/kernel/entry-avr32b.S | 26 +-
19 arch/avr32/kernel/setup.c | 2 +-
20 arch/avr32/kernel/vmlinux.lds.S | 143 +++
21 arch/avr32/kernel/vmlinux.lds.c | 142 ---
22 arch/avr32/mach-at32ap/Kconfig | 7 +
23 arch/avr32/mach-at32ap/Makefile | 1 +
24 arch/avr32/mach-at32ap/at32ap7000.c | 241 ++++-
25 arch/avr32/mach-at32ap/clock.c | 116 ++
26 arch/avr32/mach-at32ap/gpio-dev.c | 573 +++++++++
27 arch/avr32/mach-at32ap/hsmc.c | 129 ++-
28 arch/avr32/mach-at32ap/pio.c | 80 ++
29 arch/avr32/mach-at32ap/pm.h | 8 +
30 arch/avr32/mm/dma-coherent.c | 7 +
31 arch/avr32/mm/init.c | 12 +-
32 drivers/i2c/busses/Kconfig | 8 +
33 drivers/i2c/busses/Makefile | 1 +
34 drivers/i2c/busses/i2c-atmeltwi.c | 436 +++++++
35 drivers/i2c/busses/i2c-atmeltwi.h | 117 ++
36 drivers/misc/Kconfig | 9 +
37 drivers/misc/Makefile | 1 +
38 drivers/misc/atmel-ssc.c | 174 +++
39 drivers/mmc/host/Kconfig | 10 +
40 drivers/mmc/host/Makefile | 1 +
41 drivers/mmc/host/atmel-mci.c | 1161 ++++++++++++++++++
42 drivers/mmc/host/atmel-mci.h | 192 +++
43 drivers/mtd/chips/cfi_cmdset_0001.c | 43 +
44 drivers/mtd/chips/cfi_cmdset_0002.c | 6 +-
45 drivers/spi/atmel_spi.c | 4 +-
46 drivers/usb/gadget/Kconfig | 26 +-
47 drivers/usb/gadget/Makefile | 1 +
48 drivers/usb/gadget/atmel_usba_udc.c | 2038 +++++++++++++++++++++++++++++++
49 drivers/usb/gadget/atmel_usba_udc.h | 350 ++++++
50 drivers/video/atmel_lcdfb.c | 6 +-
51 drivers/video/backlight/Kconfig | 12 +
52 drivers/video/backlight/Makefile | 2 +
53 drivers/video/backlight/ltv350qv.c | 339 +++++
54 drivers/video/backlight/ltv350qv.h | 95 ++
55 include/asm-avr32/arch-at32ap/board.h | 20 +
56 include/asm-avr32/arch-at32ap/portmux.h | 13 +
57 include/asm-avr32/arch-at32ap/smc.h | 51 +-
58 include/asm-avr32/dma-controller.h | 166 +++
59 include/asm-avr32/dma-mapping.h | 17 +-
60 include/asm-avr32/system.h | 13 +-
61 include/asm-avr32/unistd.h | 13 +
62 include/linux/atmel-ssc.h | 312 +++++
63 include/linux/spi/at73c213.h | 25 +
64 scripts/checkstack.pl | 5 +
67 sound/avr32/Kconfig | 11 +
68 sound/avr32/Makefile | 3 +
69 sound/avr32/ac97c.c | 914 ++++++++++++++
70 sound/avr32/ac97c.h | 71 ++
71 sound/oss/Kconfig | 4 +
72 sound/oss/Makefile | 1 +
73 sound/oss/at32_abdac.c | 722 +++++++++++
74 sound/oss/at32_abdac.h | 59 +
75 sound/spi/Kconfig | 31 +
76 sound/spi/Makefile | 5 +
77 sound/spi/at73c213.c | 1121 +++++++++++++++++
78 sound/spi/at73c213.h | 119 ++
79 78 files changed, 11500 insertions(+), 272 deletions(-)
80 create mode 100644 arch/avr32/boards/atngw100/Kconfig
81 create mode 100644 arch/avr32/drivers/Makefile
82 create mode 100644 arch/avr32/drivers/dw-dmac.c
83 create mode 100644 arch/avr32/drivers/dw-dmac.h
84 create mode 100644 arch/avr32/kernel/dma-controller.c
85 create mode 100644 arch/avr32/kernel/vmlinux.lds.S
86 delete mode 100644 arch/avr32/kernel/vmlinux.lds.c
87 create mode 100644 arch/avr32/mach-at32ap/gpio-dev.c
88 create mode 100644 drivers/i2c/busses/i2c-atmeltwi.c
89 create mode 100644 drivers/i2c/busses/i2c-atmeltwi.h
90 create mode 100644 drivers/misc/atmel-ssc.c
91 create mode 100644 drivers/mmc/host/atmel-mci.c
92 create mode 100644 drivers/mmc/host/atmel-mci.h
93 create mode 100644 drivers/usb/gadget/atmel_usba_udc.c
94 create mode 100644 drivers/usb/gadget/atmel_usba_udc.h
95 create mode 100644 drivers/video/backlight/ltv350qv.c
96 create mode 100644 drivers/video/backlight/ltv350qv.h
97 create mode 100644 include/asm-avr32/dma-controller.h
98 create mode 100644 include/linux/atmel-ssc.h
99 create mode 100644 include/linux/spi/at73c213.h
100 create mode 100644 sound/avr32/Kconfig
101 create mode 100644 sound/avr32/Makefile
102 create mode 100644 sound/avr32/ac97c.c
103 create mode 100644 sound/avr32/ac97c.h
104 create mode 100644 sound/oss/at32_abdac.c
105 create mode 100644 sound/oss/at32_abdac.h
106 create mode 100644 sound/spi/Kconfig
107 create mode 100644 sound/spi/Makefile
108 create mode 100644 sound/spi/at73c213.c
109 create mode 100644 sound/spi/at73c213.h
111 diff --git a/MAINTAINERS b/MAINTAINERS
112 index 9a91d9e..587afe3 100644
115 @@ -669,6 +669,13 @@ P: Haavard Skinnemoen
116 M: hskinnemoen@atmel.com
119 +ATMEL USBA UDC DRIVER
120 +P: Haavard Skinnemoen
121 +M: hskinnemoen@atmel.com
122 +L: kernel@avr32linux.org
123 +W: http://avr32linux.org/twiki/bin/view/Main/AtmelUsbDeviceDriver
126 ATMEL WIRELESS DRIVER
128 M: simon@thekelleys.org.uk
129 diff --git a/arch/avr32/Kconfig b/arch/avr32/Kconfig
130 index d12346a..ec6c7c5 100644
131 --- a/arch/avr32/Kconfig
132 +++ b/arch/avr32/Kconfig
133 @@ -116,6 +116,9 @@ endchoice
135 source "arch/avr32/boards/atstk1000/Kconfig"
138 +source "arch/avr32/boards/atngw100/Kconfig"
142 prompt "Boot loader type"
143 @@ -175,6 +178,10 @@ config OWNERSHIP_TRACE
144 enabling Nexus-compliant debuggers to keep track of the PID of the
145 currently executing task.
148 + tristate "Synopsys DesignWare DMA Controller support"
149 + default y if CPU_AT32AP7000
151 # FPU emulation goes here
153 source "kernel/Kconfig.hz"
154 diff --git a/arch/avr32/Makefile b/arch/avr32/Makefile
155 index dc6bc01..eb72198 100644
156 --- a/arch/avr32/Makefile
157 +++ b/arch/avr32/Makefile
158 @@ -31,6 +31,7 @@ core-$(CONFIG_BOARD_ATNGW100) += arch/avr32/boards/atngw100/
159 core-$(CONFIG_LOADER_U_BOOT) += arch/avr32/boot/u-boot/
160 core-y += arch/avr32/kernel/
161 core-y += arch/avr32/mm/
162 +drivers-y += arch/avr32/drivers/
163 libs-y += arch/avr32/lib/
165 archincdir-$(CONFIG_PLATFORM_AT32AP) := arch-at32ap
166 diff --git a/arch/avr32/boards/atngw100/Kconfig b/arch/avr32/boards/atngw100/Kconfig
168 index 0000000..5d922df
170 +++ b/arch/avr32/boards/atngw100/Kconfig
172 +# NGW100 customization
174 +config BOARD_ATNGW100_I2C_GPIO
175 + bool "Use GPIO for i2c instead of built-in TWI module"
177 + The driver for the built-in TWI module has been plagued by
178 + various problems, while the i2c-gpio driver is based on the
179 + trusty old i2c-algo-bit bitbanging engine, making it work
180 + on pretty much any setup.
182 + Choose 'Y' here if you're having i2c-related problems and
183 + want to rule out the i2c bus driver.
184 diff --git a/arch/avr32/boards/atngw100/flash.c b/arch/avr32/boards/atngw100/flash.c
185 index f9b32a8..b07ae63 100644
186 --- a/arch/avr32/boards/atngw100/flash.c
187 +++ b/arch/avr32/boards/atngw100/flash.c
190 #include <asm/arch/smc.h>
192 -static struct smc_config flash_config __initdata = {
193 +static struct smc_timing flash_timing __initdata = {
196 .ncs_write_setup = 0,
197 @@ -28,7 +28,9 @@ static struct smc_config flash_config __initdata = {
203 +static struct smc_config flash_config __initdata = {
207 @@ -82,6 +84,7 @@ static int __init atngw100_flash_init(void)
211 + smc_set_timing(&flash_config, &flash_timing);
212 ret = smc_set_configuration(0, &flash_config);
214 printk(KERN_ERR "atngw100: failed to set NOR flash timing\n");
215 diff --git a/arch/avr32/boards/atngw100/setup.c b/arch/avr32/boards/atngw100/setup.c
216 index ef80156..2a5f587 100644
217 --- a/arch/avr32/boards/atngw100/setup.c
218 +++ b/arch/avr32/boards/atngw100/setup.c
219 @@ -42,6 +42,11 @@ static struct spi_board_info spi0_board_info[] __initdata = {
223 +static struct mci_platform_data __initdata mci0_data = {
224 + .detect_pin = GPIO_PIN_PC(25),
225 + .wp_pin = GPIO_PIN_PE(0),
229 * The next two functions should go away as the boot loader is
230 * supposed to initialize the macb address registers with a valid
231 @@ -124,9 +129,13 @@ static struct platform_device ngw_gpio_leds = {
235 +#ifdef CONFIG_BOARD_ATNGW100_I2C_GPIO
236 static struct i2c_gpio_platform_data i2c_gpio_data = {
237 - .sda_pin = GPIO_PIN_PA(6),
238 - .scl_pin = GPIO_PIN_PA(7),
239 + .sda_pin = GPIO_PIN_PA(6),
240 + .scl_pin = GPIO_PIN_PA(7),
241 + .sda_is_open_drain = 1,
242 + .scl_is_open_drain = 1,
243 + .udelay = 2, /* close to 100 kHz */
246 static struct platform_device i2c_gpio_device = {
247 @@ -136,6 +145,7 @@ static struct platform_device i2c_gpio_device = {
248 .platform_data = &i2c_gpio_data,
253 static int __init atngw100_init(void)
255 @@ -154,6 +164,8 @@ static int __init atngw100_init(void)
256 set_hw_addr(at32_add_device_eth(1, ð_data[1]));
258 at32_add_device_spi(0, spi0_board_info, ARRAY_SIZE(spi0_board_info));
259 + at32_add_device_mci(0, &mci0_data);
260 + at32_add_device_usba(0, NULL);
262 for (i = 0; i < ARRAY_SIZE(ngw_leds); i++) {
263 at32_select_gpio(ngw_leds[i].gpio,
264 @@ -161,9 +173,15 @@ static int __init atngw100_init(void)
266 platform_device_register(&ngw_gpio_leds);
268 - at32_select_gpio(i2c_gpio_data.sda_pin, 0);
269 - at32_select_gpio(i2c_gpio_data.scl_pin, 0);
270 +#ifdef CONFIG_BOARD_ATNGW100_I2C_GPIO
271 + at32_select_gpio(i2c_gpio_data.sda_pin,
272 + AT32_GPIOF_MULTIDRV | AT32_GPIOF_OUTPUT | AT32_GPIOF_HIGH);
273 + at32_select_gpio(i2c_gpio_data.scl_pin,
274 + AT32_GPIOF_MULTIDRV | AT32_GPIOF_OUTPUT | AT32_GPIOF_HIGH);
275 platform_device_register(&i2c_gpio_device);
277 + at32_add_device_twi(0);
282 diff --git a/arch/avr32/boards/atstk1000/Kconfig b/arch/avr32/boards/atstk1000/Kconfig
283 index 718578f..b1f5a62 100644
284 --- a/arch/avr32/boards/atstk1000/Kconfig
285 +++ b/arch/avr32/boards/atstk1000/Kconfig
286 @@ -76,4 +76,16 @@ config BOARD_ATSTK1002_J2_RGB
290 +config BOARD_ATSTK1002_ENABLE_AC97
291 + bool "Use AC97C instead of ABDAC"
293 + Select this if you want to use the built-in AC97 controller
294 + instead of the built-in Audio Bitstream DAC. These share
295 + the same I/O pins on the AP7000, so both can't be enabled
298 + Note that the STK1000/STK1002 kit doesn't ship with an AC97
299 + codec on board, so say N unless you've got an expansion
300 + board with an AC97 codec on it that you want to use.
303 diff --git a/arch/avr32/boards/atstk1000/atstk1002.c b/arch/avr32/boards/atstk1000/atstk1002.c
304 index c9981b7..f7fb509 100644
305 --- a/arch/avr32/boards/atstk1000/atstk1002.c
306 +++ b/arch/avr32/boards/atstk1000/atstk1002.c
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>
315 @@ -49,7 +50,25 @@ static struct eth_platform_data __initdata eth_data[2] = {
318 #ifndef CONFIG_BOARD_ATSTK1002_SW1_CUSTOM
319 +#ifndef CONFIG_BOARD_ATSTK1002_SW3_CUSTOM
320 +static struct at73c213_board_info at73c213_data = {
322 + .shortname = "AVR32 STK1000 external DAC",
326 +#ifndef CONFIG_BOARD_ATSTK1002_SW1_CUSTOM
327 static struct spi_board_info spi0_board_info[] __initdata = {
328 +#ifndef CONFIG_BOARD_ATSTK1002_SW3_CUSTOM
331 + .modalias = "at73c213",
332 + .max_speed_hz = 200000,
334 + .mode = SPI_MODE_1,
335 + .platform_data = &at73c213_data,
340 .modalias = "ltv350qv",
341 @@ -66,6 +85,11 @@ static struct spi_board_info spi1_board_info[] __initdata = { {
345 +static struct mci_platform_data __initdata mci0_data = {
346 + .detect_pin = GPIO_PIN_NONE,
347 + .wp_pin = GPIO_PIN_NONE,
351 * The next two functions should go away as the boot loader is
352 * supposed to initialize the macb address registers with a valid
353 @@ -180,6 +204,38 @@ static void setup_j2_leds(void)
357 +#ifndef CONFIG_BOARD_ATSTK1002_SW1_CUSTOM
358 +#ifndef CONFIG_BOARD_ATSTK1002_SW3_CUSTOM
359 +static void __init at73c213_set_clk(struct at73c213_board_info *info)
364 + gclk = clk_get(NULL, "gclk0");
367 + pll = clk_get(NULL, "pll0");
371 + if (clk_set_parent(gclk, pll)) {
372 + pr_debug("STK1000: failed to set pll0 as parent for DAC clock\n");
376 + at32_select_periph(GPIO_PIN_PA(30), GPIO_PERIPH_A, 0);
377 + info->dac_clk = gclk;
389 void __init setup_board(void)
391 #ifdef CONFIG_BOARD_ATSTK1002_SW2_CUSTOM
392 @@ -235,18 +291,34 @@ static int __init atstk1002_init(void)
393 #ifdef CONFIG_BOARD_ATSTK1002_SPI1
394 at32_add_device_spi(1, spi1_board_info, ARRAY_SIZE(spi1_board_info));
396 + at32_add_device_twi(0);
397 +#ifndef CONFIG_BOARD_ATSTK1002_SW2_CUSTOM
398 + at32_add_device_mci(0, &mci0_data);
400 #ifdef CONFIG_BOARD_ATSTK1002_SW5_CUSTOM
401 set_hw_addr(at32_add_device_eth(1, ð_data[1]));
403 at32_add_device_lcdc(0, &atstk1000_lcdc_data,
404 fbmem_start, fbmem_size);
406 + at32_add_device_usba(0, NULL);
407 +#ifdef CONFIG_BOARD_ATSTK1002_ENABLE_AC97
408 + at32_add_device_ac97c(0);
410 + at32_add_device_abdac(0);
412 #ifndef CONFIG_BOARD_ATSTK1002_SW3_CUSTOM
413 at32_add_device_ssc(0, ATMEL_SSC_TX);
418 +#ifndef CONFIG_BOARD_ATSTK1002_SW3_CUSTOM
419 +#ifndef CONFIG_BOARD_ATSTK1002_SW1_CUSTOM
420 + at73c213_set_clk(&at73c213_data);
426 postcore_initcall(atstk1002_init);
427 diff --git a/arch/avr32/boards/atstk1000/flash.c b/arch/avr32/boards/atstk1000/flash.c
428 index aac4300..3d0a102 100644
429 --- a/arch/avr32/boards/atstk1000/flash.c
430 +++ b/arch/avr32/boards/atstk1000/flash.c
433 #include <asm/arch/smc.h>
435 -static struct smc_config flash_config __initdata = {
436 +static struct smc_timing flash_timing __initdata = {
439 .ncs_write_setup = 0,
440 @@ -28,7 +28,9 @@ static struct smc_config flash_config __initdata = {
446 +static struct smc_config flash_config __initdata = {
450 @@ -82,6 +84,7 @@ static int __init atstk1000_flash_init(void)
454 + smc_set_timing(&flash_config, &flash_timing);
455 ret = smc_set_configuration(0, &flash_config);
457 printk(KERN_ERR "atstk1000: failed to set NOR flash timing\n");
458 diff --git a/arch/avr32/configs/atngw100_defconfig b/arch/avr32/configs/atngw100_defconfig
459 index b799a68..adce168 100644
460 --- a/arch/avr32/configs/atngw100_defconfig
461 +++ b/arch/avr32/configs/atngw100_defconfig
464 # Automatically generated make config: don't edit
465 -# Linux kernel version: 2.6.22-rc5
466 -# Sat Jun 23 15:40:05 2007
467 +# Linux kernel version: 2.6.22.atmel.1
468 +# Thu Jul 12 17:49:20 2007
471 CONFIG_GENERIC_GPIO=y
472 @@ -114,6 +114,7 @@ CONFIG_PLATFORM_AT32AP=y
473 CONFIG_CPU_AT32AP7000=y
474 # CONFIG_BOARD_ATSTK1000 is not set
475 CONFIG_BOARD_ATNGW100=y
476 +# CONFIG_BOARD_ATNGW100_I2C_GPIO is not set
477 CONFIG_LOADER_U_BOOT=y
480 @@ -122,6 +123,7 @@ CONFIG_LOADER_U_BOOT=y
481 # CONFIG_AP7000_32_BIT_SMC is not set
482 CONFIG_AP7000_16_BIT_SMC=y
483 # CONFIG_AP7000_8_BIT_SMC is not set
485 CONFIG_LOAD_ADDRESS=0x10000000
486 CONFIG_ENTRY_ADDRESS=0x90000000
487 CONFIG_PHYS_OFFSET=0x10000000
488 @@ -145,6 +147,7 @@ CONFIG_SPLIT_PTLOCK_CPUS=4
489 # CONFIG_RESOURCES_64BIT is not set
490 CONFIG_ZONE_DMA_FLAG=0
491 # CONFIG_OWNERSHIP_TRACE is not set
493 # CONFIG_HZ_100 is not set
495 # CONFIG_HZ_300 is not set
496 @@ -153,6 +156,27 @@ CONFIG_HZ=250
500 +# Power managment options
504 +# CPU Frequency scaling
507 +CONFIG_CPU_FREQ_TABLE=y
508 +# CONFIG_CPU_FREQ_DEBUG is not set
509 +CONFIG_CPU_FREQ_STAT=m
510 +# CONFIG_CPU_FREQ_STAT_DETAILS is not set
511 +CONFIG_CPU_FREQ_DEFAULT_GOV_PERFORMANCE=y
512 +# CONFIG_CPU_FREQ_DEFAULT_GOV_USERSPACE is not set
513 +CONFIG_CPU_FREQ_GOV_PERFORMANCE=y
514 +CONFIG_CPU_FREQ_GOV_POWERSAVE=y
515 +CONFIG_CPU_FREQ_GOV_USERSPACE=y
516 +CONFIG_CPU_FREQ_GOV_ONDEMAND=y
517 +# CONFIG_CPU_FREQ_GOV_CONSERVATIVE is not set
518 +CONFIG_CPU_FREQ_AT32AP=y
523 # CONFIG_ARCH_SUPPORTS_MSI is not set
524 @@ -187,13 +211,8 @@ CONFIG_NET_KEY=y
525 # CONFIG_NET_KEY_MIGRATE is not set
527 CONFIG_IP_MULTICAST=y
528 -CONFIG_IP_ADVANCED_ROUTER=y
529 -CONFIG_ASK_IP_FIB_HASH=y
530 -# CONFIG_IP_FIB_TRIE is not set
531 +# CONFIG_IP_ADVANCED_ROUTER is not set
533 -# CONFIG_IP_MULTIPLE_TABLES is not set
534 -# CONFIG_IP_ROUTE_MULTIPATH is not set
535 -# CONFIG_IP_ROUTE_VERBOSE is not set
538 # CONFIG_IP_PNP_BOOTP is not set
539 @@ -240,6 +259,7 @@ CONFIG_IPV6_SIT=y
540 # CONFIG_NETWORK_SECMARK is not set
542 # CONFIG_NETFILTER_DEBUG is not set
543 +CONFIG_BRIDGE_NETFILTER=y
546 # Core Netfilter Configuration
547 @@ -284,6 +304,7 @@ CONFIG_NETFILTER_XT_MATCH_MAC=m
548 CONFIG_NETFILTER_XT_MATCH_MARK=m
549 CONFIG_NETFILTER_XT_MATCH_POLICY=m
550 CONFIG_NETFILTER_XT_MATCH_MULTIPORT=m
551 +# CONFIG_NETFILTER_XT_MATCH_PHYSDEV is not set
552 CONFIG_NETFILTER_XT_MATCH_PKTTYPE=m
553 CONFIG_NETFILTER_XT_MATCH_QUOTA=m
554 CONFIG_NETFILTER_XT_MATCH_REALM=m
555 @@ -359,13 +380,19 @@ CONFIG_IP6_NF_TARGET_REJECT=m
556 CONFIG_IP6_NF_MANGLE=m
557 CONFIG_IP6_NF_TARGET_HL=m
561 +# Bridge: Netfilter Configuration
563 +# CONFIG_BRIDGE_NF_EBTABLES is not set
564 # CONFIG_IP_DCCP is not set
565 # CONFIG_IP_SCTP is not set
566 # CONFIG_TIPC is not set
567 # CONFIG_ATM is not set
568 -# CONFIG_BRIDGE is not set
571 # CONFIG_DECNET is not set
573 # CONFIG_LLC2 is not set
574 # CONFIG_IPX is not set
575 # CONFIG_ATALK is not set
576 @@ -521,7 +548,6 @@ CONFIG_BLK_DEV_RAM_BLOCKSIZE=1024
580 -# CONFIG_BLINK is not set
581 # CONFIG_IDE is not set
584 @@ -545,13 +571,26 @@ CONFIG_NETDEVICES=y
585 # CONFIG_BONDING is not set
586 # CONFIG_EQUALIZER is not set
588 -# CONFIG_PHYLIB is not set
592 +# MII PHY device drivers
594 +# CONFIG_MARVELL_PHY is not set
595 +# CONFIG_DAVICOM_PHY is not set
596 +# CONFIG_QSEMI_PHY is not set
597 +# CONFIG_LXT_PHY is not set
598 +# CONFIG_CICADA_PHY is not set
599 +# CONFIG_VITESSE_PHY is not set
600 +# CONFIG_SMSC_PHY is not set
601 +# CONFIG_BROADCOM_PHY is not set
602 +# CONFIG_FIXED_PHY is not set
605 # Ethernet (10 or 100Mbit)
607 CONFIG_NET_ETHERNET=y
609 +# CONFIG_MII is not set
611 # CONFIG_NETDEV_1000 is not set
612 # CONFIG_NETDEV_10000 is not set
613 @@ -625,7 +664,15 @@ CONFIG_UNIX98_PTYS=y
616 # CONFIG_IPMI_HANDLER is not set
617 -# CONFIG_WATCHDOG is not set
619 +# CONFIG_WATCHDOG_NOWAYOUT is not set
622 +# Watchdog Device Drivers
624 +# CONFIG_SOFT_WATCHDOG is not set
625 +CONFIG_AT32AP700X_WDT=y
626 +CONFIG_AT32AP700X_WDT_TIMEOUT=2
627 # CONFIG_HW_RANDOM is not set
628 # CONFIG_RTC is not set
629 # CONFIG_GEN_RTC is not set
630 @@ -636,7 +683,42 @@ CONFIG_UNIX98_PTYS=y
633 # CONFIG_TCG_TPM is not set
634 -# CONFIG_I2C is not set
636 +CONFIG_I2C_BOARDINFO=y
637 +CONFIG_I2C_CHARDEV=m
642 +CONFIG_I2C_ALGOBIT=m
643 +# CONFIG_I2C_ALGOPCF is not set
644 +# CONFIG_I2C_ALGOPCA is not set
647 +# I2C Hardware Bus support
649 +CONFIG_I2C_ATMELTWI=m
650 +CONFIG_I2C_ATMELTWI_BAUDRATE=100000
652 +# CONFIG_I2C_OCORES is not set
653 +# CONFIG_I2C_PARPORT_LIGHT is not set
654 +# CONFIG_I2C_SIMTEC is not set
655 +# CONFIG_I2C_STUB is not set
658 +# Miscellaneous I2C Chip support
660 +# CONFIG_SENSORS_DS1337 is not set
661 +# CONFIG_SENSORS_DS1374 is not set
662 +# CONFIG_SENSORS_EEPROM is not set
663 +# CONFIG_SENSORS_PCF8574 is not set
664 +# CONFIG_SENSORS_PCA9539 is not set
665 +# CONFIG_SENSORS_PCF8591 is not set
666 +# CONFIG_SENSORS_MAX6875 is not set
667 +# CONFIG_I2C_DEBUG_CORE is not set
668 +# CONFIG_I2C_DEBUG_ALGO is not set
669 +# CONFIG_I2C_DEBUG_BUS is not set
670 +# CONFIG_I2C_DEBUG_CHIP is not set
674 @@ -655,7 +737,7 @@ CONFIG_SPI_ATMEL=y
675 # SPI Protocol Masters
677 # CONFIG_SPI_AT25 is not set
678 -# CONFIG_SPI_SPIDEV is not set
682 # Dallas's 1-wire bus
683 @@ -706,8 +788,41 @@ CONFIG_SPI_ATMEL=y
687 -# CONFIG_USB_GADGET is not set
688 -# CONFIG_MMC is not set
690 +# CONFIG_USB_GADGET_DEBUG_FILES is not set
691 +CONFIG_USB_GADGET_SELECTED=y
692 +# CONFIG_USB_GADGET_FSL_USB2 is not set
693 +# CONFIG_USB_GADGET_NET2280 is not set
694 +# CONFIG_USB_GADGET_PXA2XX is not set
695 +# CONFIG_USB_GADGET_GOKU is not set
696 +# CONFIG_USB_GADGET_LH7A40X is not set
697 +CONFIG_USB_GADGET_ATMEL_USBA=y
698 +CONFIG_USB_ATMEL_USBA=y
699 +# CONFIG_USB_GADGET_OMAP is not set
700 +# CONFIG_USB_GADGET_AT91 is not set
701 +# CONFIG_USB_GADGET_DUMMY_HCD is not set
702 +CONFIG_USB_GADGET_DUALSPEED=y
705 +CONFIG_USB_ETH_RNDIS=y
706 +CONFIG_USB_GADGETFS=m
707 +CONFIG_USB_FILE_STORAGE=m
708 +# CONFIG_USB_FILE_STORAGE_TEST is not set
709 +CONFIG_USB_G_SERIAL=m
710 +# CONFIG_USB_MIDI_GADGET is not set
712 +# CONFIG_MMC_DEBUG is not set
713 +# CONFIG_MMC_UNSAFE_RESUME is not set
716 +# MMC/SD Card Drivers
721 +# MMC/SD Host Controller Drivers
723 +CONFIG_MMC_ATMELMCI=y
727 @@ -727,27 +842,62 @@ CONFIG_LEDS_TRIGGERS=y
728 CONFIG_LEDS_TRIGGER_TIMER=y
729 CONFIG_LEDS_TRIGGER_HEARTBEAT=y
732 +# InfiniBand support
737 +# EDAC - error detection and reporting (RAS) (EXPERIMENTAL)
746 +CONFIG_RTC_HCTOSYS=y
747 +CONFIG_RTC_HCTOSYS_DEVICE="rtc0"
748 +# CONFIG_RTC_DEBUG is not set
751 -# InfiniBand support
754 +CONFIG_RTC_INTF_SYSFS=y
755 +CONFIG_RTC_INTF_PROC=y
756 +CONFIG_RTC_INTF_DEV=y
757 +# CONFIG_RTC_INTF_DEV_UIE_EMUL is not set
758 +# CONFIG_RTC_DRV_TEST is not set
761 -# EDAC - error detection and reporting (RAS) (EXPERIMENTAL)
764 +# CONFIG_RTC_DRV_DS1307 is not set
765 +# CONFIG_RTC_DRV_DS1672 is not set
766 +# CONFIG_RTC_DRV_MAX6900 is not set
767 +# CONFIG_RTC_DRV_RS5C372 is not set
768 +# CONFIG_RTC_DRV_ISL1208 is not set
769 +# CONFIG_RTC_DRV_X1205 is not set
770 +# CONFIG_RTC_DRV_PCF8563 is not set
771 +# CONFIG_RTC_DRV_PCF8583 is not set
777 +# CONFIG_RTC_DRV_RS5C348 is not set
778 +# CONFIG_RTC_DRV_MAX6902 is not set
781 +# Platform RTC drivers
783 +# CONFIG_RTC_DRV_DS1553 is not set
784 +# CONFIG_RTC_DRV_DS1742 is not set
785 +# CONFIG_RTC_DRV_M48T86 is not set
786 +# CONFIG_RTC_DRV_V3020 is not set
789 +# on-CPU RTC drivers
791 -# CONFIG_RTC_CLASS is not set
792 +CONFIG_RTC_DRV_AT32AP700X=y
796 @@ -781,7 +931,8 @@ CONFIG_JBD=y
797 # CONFIG_OCFS2_FS is not set
798 # CONFIG_MINIX_FS is not set
799 # CONFIG_ROMFS_FS is not set
800 -# CONFIG_INOTIFY is not set
802 +CONFIG_INOTIFY_USER=y
803 # CONFIG_QUOTA is not set
804 # CONFIG_DNOTIFY is not set
805 # CONFIG_AUTOFS_FS is not set
806 @@ -936,7 +1087,7 @@ CONFIG_TRACE_IRQFLAGS_SUPPORT=y
807 CONFIG_ENABLE_MUST_CHECK=y
809 # CONFIG_UNUSED_SYMBOLS is not set
810 -# CONFIG_DEBUG_FS is not set
812 # CONFIG_HEADERS_CHECK is not set
813 CONFIG_DEBUG_KERNEL=y
814 # CONFIG_DEBUG_SHIRQ is not set
815 diff --git a/arch/avr32/configs/atstk1002_defconfig b/arch/avr32/configs/atstk1002_defconfig
816 index 3b977fd..3708066 100644
817 --- a/arch/avr32/configs/atstk1002_defconfig
818 +++ b/arch/avr32/configs/atstk1002_defconfig
821 # Automatically generated make config: don't edit
822 -# Linux kernel version: 2.6.22-rc5
823 -# Sat Jun 23 15:32:08 2007
824 +# Linux kernel version: 2.6.22.atmel.2
825 +# Thu Jul 19 13:46:47 2007
828 CONFIG_GENERIC_GPIO=y
829 @@ -80,10 +80,10 @@ CONFIG_BASE_SMALL=1
832 CONFIG_MODULE_UNLOAD=y
833 -# CONFIG_MODULE_FORCE_UNLOAD is not set
834 +CONFIG_MODULE_FORCE_UNLOAD=y
835 # CONFIG_MODVERSIONS is not set
836 # CONFIG_MODULE_SRCVERSION_ALL is not set
837 -# CONFIG_KMOD is not set
842 @@ -99,12 +99,12 @@ CONFIG_BLOCK=y
843 CONFIG_IOSCHED_NOOP=y
844 # CONFIG_IOSCHED_AS is not set
845 # CONFIG_IOSCHED_DEADLINE is not set
846 -# CONFIG_IOSCHED_CFQ is not set
847 +CONFIG_IOSCHED_CFQ=y
848 # CONFIG_DEFAULT_AS is not set
849 # CONFIG_DEFAULT_DEADLINE is not set
850 -# CONFIG_DEFAULT_CFQ is not set
851 -CONFIG_DEFAULT_NOOP=y
852 -CONFIG_DEFAULT_IOSCHED="noop"
853 +CONFIG_DEFAULT_CFQ=y
854 +# CONFIG_DEFAULT_NOOP is not set
855 +CONFIG_DEFAULT_IOSCHED="cfq"
858 # System Type and features
859 @@ -117,6 +117,11 @@ CONFIG_CPU_AT32AP7000=y
860 CONFIG_BOARD_ATSTK1002=y
861 CONFIG_BOARD_ATSTK1000=y
862 # CONFIG_BOARD_ATNGW100 is not set
863 +# CONFIG_BOARD_ATSTK1002_CUSTOM is not set
864 +# CONFIG_BOARD_ATSTK1002_SPI1 is not set
865 +# CONFIG_BOARD_ATSTK1002_J2_LED is not set
866 +# CONFIG_BOARD_ATSTK1002_J2_LED8 is not set
867 +# CONFIG_BOARD_ATSTK1002_J2_RGB is not set
868 CONFIG_LOADER_U_BOOT=y
871 @@ -125,6 +130,7 @@ CONFIG_LOADER_U_BOOT=y
872 # CONFIG_AP7000_32_BIT_SMC is not set
873 CONFIG_AP7000_16_BIT_SMC=y
874 # CONFIG_AP7000_8_BIT_SMC is not set
876 CONFIG_LOAD_ADDRESS=0x10000000
877 CONFIG_ENTRY_ADDRESS=0x90000000
878 CONFIG_PHYS_OFFSET=0x10000000
879 @@ -148,6 +154,7 @@ CONFIG_SPLIT_PTLOCK_CPUS=4
880 # CONFIG_RESOURCES_64BIT is not set
881 CONFIG_ZONE_DMA_FLAG=0
882 # CONFIG_OWNERSHIP_TRACE is not set
884 # CONFIG_HZ_100 is not set
886 # CONFIG_HZ_300 is not set
887 @@ -156,6 +163,27 @@ CONFIG_HZ=250
891 +# Power managment options
895 +# CPU Frequency scaling
898 +CONFIG_CPU_FREQ_TABLE=y
899 +# CONFIG_CPU_FREQ_DEBUG is not set
900 +CONFIG_CPU_FREQ_STAT=m
901 +# CONFIG_CPU_FREQ_STAT_DETAILS is not set
902 +CONFIG_CPU_FREQ_DEFAULT_GOV_PERFORMANCE=y
903 +# CONFIG_CPU_FREQ_DEFAULT_GOV_USERSPACE is not set
904 +CONFIG_CPU_FREQ_GOV_PERFORMANCE=y
905 +CONFIG_CPU_FREQ_GOV_POWERSAVE=y
906 +CONFIG_CPU_FREQ_GOV_USERSPACE=y
907 +CONFIG_CPU_FREQ_GOV_ONDEMAND=y
908 +# CONFIG_CPU_FREQ_GOV_CONSERVATIVE is not set
909 +CONFIG_CPU_FREQ_AT32AP=y
914 # CONFIG_ARCH_SUPPORTS_MSI is not set
915 @@ -327,6 +355,8 @@ CONFIG_MTD_PHYSMAP_BANKWIDTH=2
917 # Self-contained MTD device drivers
919 +CONFIG_MTD_DATAFLASH=m
920 +# CONFIG_MTD_M25P80 is not set
921 # CONFIG_MTD_SLRAM is not set
922 # CONFIG_MTD_PHRAM is not set
923 # CONFIG_MTD_MTDRAM is not set
924 @@ -373,7 +403,7 @@ CONFIG_BLK_DEV_RAM_BLOCKSIZE=1024
928 -# CONFIG_BLINK is not set
930 # CONFIG_IDE is not set
933 @@ -397,13 +427,26 @@ CONFIG_DUMMY=y
934 # CONFIG_BONDING is not set
935 # CONFIG_EQUALIZER is not set
937 -# CONFIG_PHYLIB is not set
941 +# MII PHY device drivers
943 +# CONFIG_MARVELL_PHY is not set
944 +# CONFIG_DAVICOM_PHY is not set
945 +# CONFIG_QSEMI_PHY is not set
947 +# CONFIG_CICADA_PHY is not set
948 +# CONFIG_VITESSE_PHY is not set
949 +# CONFIG_SMSC_PHY is not set
950 +# CONFIG_BROADCOM_PHY is not set
951 +# CONFIG_FIXED_PHY is not set
954 # Ethernet (10 or 100Mbit)
956 CONFIG_NET_ETHERNET=y
958 +# CONFIG_MII is not set
960 # CONFIG_NETDEV_1000 is not set
961 # CONFIG_NETDEV_10000 is not set
962 @@ -443,7 +486,42 @@ CONFIG_SLHC=m
964 # Input device support
966 -# CONFIG_INPUT is not set
968 +# CONFIG_INPUT_FF_MEMLESS is not set
969 +CONFIG_INPUT_POLLDEV=m
972 +# Userland interfaces
974 +CONFIG_INPUT_MOUSEDEV=m
975 +CONFIG_INPUT_MOUSEDEV_PSAUX=y
976 +CONFIG_INPUT_MOUSEDEV_SCREEN_X=1024
977 +CONFIG_INPUT_MOUSEDEV_SCREEN_Y=768
978 +# CONFIG_INPUT_JOYDEV is not set
979 +# CONFIG_INPUT_TSDEV is not set
980 +# CONFIG_INPUT_EVDEV is not set
981 +# CONFIG_INPUT_EVBUG is not set
984 +# Input Device Drivers
986 +CONFIG_INPUT_KEYBOARD=y
987 +# CONFIG_KEYBOARD_ATKBD is not set
988 +# CONFIG_KEYBOARD_SUNKBD is not set
989 +# CONFIG_KEYBOARD_LKKBD is not set
990 +# CONFIG_KEYBOARD_XTKBD is not set
991 +# CONFIG_KEYBOARD_NEWTON is not set
992 +# CONFIG_KEYBOARD_STOWAWAY is not set
993 +CONFIG_KEYBOARD_GPIO=m
994 +CONFIG_INPUT_MOUSE=y
995 +# CONFIG_MOUSE_PS2 is not set
996 +# CONFIG_MOUSE_SERIAL is not set
997 +# CONFIG_MOUSE_VSXXXAA is not set
999 +# CONFIG_INPUT_JOYSTICK is not set
1000 +# CONFIG_INPUT_TABLET is not set
1001 +# CONFIG_INPUT_TOUCHSCREEN is not set
1002 +# CONFIG_INPUT_MISC is not set
1005 # Hardware I/O ports
1006 @@ -477,7 +555,15 @@ CONFIG_UNIX98_PTYS=y
1009 # CONFIG_IPMI_HANDLER is not set
1010 -# CONFIG_WATCHDOG is not set
1012 +# CONFIG_WATCHDOG_NOWAYOUT is not set
1015 +# Watchdog Device Drivers
1017 +# CONFIG_SOFT_WATCHDOG is not set
1018 +CONFIG_AT32AP700X_WDT=y
1019 +CONFIG_AT32AP700X_WDT_TIMEOUT=2
1020 # CONFIG_HW_RANDOM is not set
1021 # CONFIG_RTC is not set
1022 # CONFIG_GEN_RTC is not set
1023 @@ -488,13 +574,61 @@ CONFIG_UNIX98_PTYS=y
1026 # CONFIG_TCG_TPM is not set
1027 -# CONFIG_I2C is not set
1029 +CONFIG_I2C_BOARDINFO=y
1030 +CONFIG_I2C_CHARDEV=m
1035 +CONFIG_I2C_ALGOBIT=m
1036 +# CONFIG_I2C_ALGOPCF is not set
1037 +# CONFIG_I2C_ALGOPCA is not set
1040 +# I2C Hardware Bus support
1042 +CONFIG_I2C_ATMELTWI=m
1043 +CONFIG_I2C_ATMELTWI_BAUDRATE=100000
1045 +# CONFIG_I2C_OCORES is not set
1046 +# CONFIG_I2C_PARPORT_LIGHT is not set
1047 +# CONFIG_I2C_SIMTEC is not set
1048 +# CONFIG_I2C_STUB is not set
1051 +# Miscellaneous I2C Chip support
1053 +# CONFIG_SENSORS_DS1337 is not set
1054 +# CONFIG_SENSORS_DS1374 is not set
1055 +# CONFIG_SENSORS_EEPROM is not set
1056 +# CONFIG_SENSORS_PCF8574 is not set
1057 +# CONFIG_SENSORS_PCA9539 is not set
1058 +# CONFIG_SENSORS_PCF8591 is not set
1059 +# CONFIG_SENSORS_MAX6875 is not set
1060 +# CONFIG_I2C_DEBUG_CORE is not set
1061 +# CONFIG_I2C_DEBUG_ALGO is not set
1062 +# CONFIG_I2C_DEBUG_BUS is not set
1063 +# CONFIG_I2C_DEBUG_CHIP is not set
1068 -# CONFIG_SPI is not set
1069 -# CONFIG_SPI_MASTER is not set
1071 +# CONFIG_SPI_DEBUG is not set
1072 +CONFIG_SPI_MASTER=y
1075 +# SPI Master Controller Drivers
1078 +# CONFIG_SPI_BITBANG is not set
1081 +# SPI Protocol Masters
1083 +# CONFIG_SPI_AT25 is not set
1084 +CONFIG_SPI_SPIDEV=m
1087 # Dallas's 1-wire bus
1088 @@ -517,19 +651,91 @@ CONFIG_UNIX98_PTYS=y
1092 -# CONFIG_BACKLIGHT_LCD_SUPPORT is not set
1093 +CONFIG_BACKLIGHT_LCD_SUPPORT=y
1094 +CONFIG_LCD_CLASS_DEVICE=y
1095 +CONFIG_LCD_LTV350QV=y
1096 +# CONFIG_BACKLIGHT_CLASS_DEVICE is not set
1099 # Display device support
1101 # CONFIG_DISPLAY_SUPPORT is not set
1102 # CONFIG_VGASTATE is not set
1103 -# CONFIG_FB is not set
1105 +# CONFIG_FIRMWARE_EDID is not set
1106 +# CONFIG_FB_DDC is not set
1107 +CONFIG_FB_CFB_FILLRECT=y
1108 +CONFIG_FB_CFB_COPYAREA=y
1109 +CONFIG_FB_CFB_IMAGEBLIT=y
1110 +# CONFIG_FB_SYS_FILLRECT is not set
1111 +# CONFIG_FB_SYS_COPYAREA is not set
1112 +# CONFIG_FB_SYS_IMAGEBLIT is not set
1113 +# CONFIG_FB_SYS_FOPS is not set
1114 +CONFIG_FB_DEFERRED_IO=y
1115 +# CONFIG_FB_SVGALIB is not set
1116 +# CONFIG_FB_MACMODES is not set
1117 +# CONFIG_FB_BACKLIGHT is not set
1118 +# CONFIG_FB_MODE_HELPERS is not set
1119 +# CONFIG_FB_TILEBLITTING is not set
1122 +# Frame buffer hardware drivers
1124 +# CONFIG_FB_S1D13XXX is not set
1126 +# CONFIG_FB_VIRTUAL is not set
1127 +# CONFIG_LOGO is not set
1132 -# CONFIG_SOUND is not set
1136 +# Advanced Linux Sound Architecture
1141 +# CONFIG_SND_SEQUENCER is not set
1142 +CONFIG_SND_OSSEMUL=y
1143 +CONFIG_SND_MIXER_OSS=m
1144 +CONFIG_SND_PCM_OSS=m
1145 +CONFIG_SND_PCM_OSS_PLUGINS=y
1146 +# CONFIG_SND_DYNAMIC_MINORS is not set
1147 +# CONFIG_SND_SUPPORT_OLD_API is not set
1148 +CONFIG_SND_VERBOSE_PROCFS=y
1149 +# CONFIG_SND_VERBOSE_PRINTK is not set
1150 +# CONFIG_SND_DEBUG is not set
1155 +# CONFIG_SND_DUMMY is not set
1156 +# CONFIG_SND_MTPAV is not set
1157 +# CONFIG_SND_SERIAL_U16550 is not set
1158 +# CONFIG_SND_MPU401 is not set
1163 +CONFIG_SND_AT73C213=m
1164 +CONFIG_SND_AT73C213_TARGET_BITRATE=48000
1167 +# System on Chip audio support
1169 +# CONFIG_SND_SOC is not set
1172 +# Open Sound System
1174 +# CONFIG_SOUND_PRIME is not set
1179 +# CONFIG_HID is not set
1183 @@ -545,21 +751,59 @@ CONFIG_UNIX98_PTYS=y
1185 # USB Gadget Support
1187 -# CONFIG_USB_GADGET is not set
1188 -# CONFIG_MMC is not set
1189 +CONFIG_USB_GADGET=y
1190 +# CONFIG_USB_GADGET_DEBUG_FILES is not set
1191 +CONFIG_USB_GADGET_SELECTED=y
1192 +# CONFIG_USB_GADGET_FSL_USB2 is not set
1193 +# CONFIG_USB_GADGET_NET2280 is not set
1194 +# CONFIG_USB_GADGET_PXA2XX is not set
1195 +# CONFIG_USB_GADGET_GOKU is not set
1196 +# CONFIG_USB_GADGET_LH7A40X is not set
1197 +CONFIG_USB_GADGET_ATMEL_USBA=y
1198 +CONFIG_USB_ATMEL_USBA=y
1199 +# CONFIG_USB_GADGET_OMAP is not set
1200 +# CONFIG_USB_GADGET_AT91 is not set
1201 +# CONFIG_USB_GADGET_DUMMY_HCD is not set
1202 +CONFIG_USB_GADGET_DUALSPEED=y
1205 +CONFIG_USB_ETH_RNDIS=y
1206 +CONFIG_USB_GADGETFS=m
1207 +CONFIG_USB_FILE_STORAGE=m
1208 +# CONFIG_USB_FILE_STORAGE_TEST is not set
1209 +CONFIG_USB_G_SERIAL=m
1210 +# CONFIG_USB_MIDI_GADGET is not set
1212 +# CONFIG_MMC_DEBUG is not set
1213 +# CONFIG_MMC_UNSAFE_RESUME is not set
1216 +# MMC/SD Card Drivers
1221 +# MMC/SD Host Controller Drivers
1223 +CONFIG_MMC_ATMELMCI=y
1228 -# CONFIG_NEW_LEDS is not set
1230 +CONFIG_LEDS_CLASS=m
1240 +CONFIG_LEDS_TRIGGERS=y
1241 +CONFIG_LEDS_TRIGGER_TIMER=m
1242 +CONFIG_LEDS_TRIGGER_HEARTBEAT=m
1245 # InfiniBand support
1246 @@ -572,7 +816,50 @@ CONFIG_UNIX98_PTYS=y
1250 -# CONFIG_RTC_CLASS is not set
1253 +# CONFIG_RTC_HCTOSYS is not set
1254 +# CONFIG_RTC_DEBUG is not set
1259 +CONFIG_RTC_INTF_SYSFS=y
1260 +CONFIG_RTC_INTF_PROC=y
1261 +CONFIG_RTC_INTF_DEV=y
1262 +# CONFIG_RTC_INTF_DEV_UIE_EMUL is not set
1263 +# CONFIG_RTC_DRV_TEST is not set
1268 +# CONFIG_RTC_DRV_DS1307 is not set
1269 +# CONFIG_RTC_DRV_DS1672 is not set
1270 +# CONFIG_RTC_DRV_MAX6900 is not set
1271 +# CONFIG_RTC_DRV_RS5C372 is not set
1272 +# CONFIG_RTC_DRV_ISL1208 is not set
1273 +# CONFIG_RTC_DRV_X1205 is not set
1274 +# CONFIG_RTC_DRV_PCF8563 is not set
1275 +# CONFIG_RTC_DRV_PCF8583 is not set
1280 +# CONFIG_RTC_DRV_RS5C348 is not set
1281 +# CONFIG_RTC_DRV_MAX6902 is not set
1284 +# Platform RTC drivers
1286 +# CONFIG_RTC_DRV_DS1553 is not set
1287 +# CONFIG_RTC_DRV_DS1742 is not set
1288 +# CONFIG_RTC_DRV_M48T86 is not set
1289 +# CONFIG_RTC_DRV_V3020 is not set
1292 +# on-CPU RTC drivers
1294 +CONFIG_RTC_DRV_AT32AP700X=y
1297 # DMA Engine support
1298 @@ -590,11 +877,14 @@ CONFIG_UNIX98_PTYS=y
1304 # CONFIG_EXT2_FS_XATTR is not set
1305 # CONFIG_EXT2_FS_XIP is not set
1306 -# CONFIG_EXT3_FS is not set
1308 +# CONFIG_EXT3_FS_XATTR is not set
1309 # CONFIG_EXT4DEV_FS is not set
1311 +# CONFIG_JBD_DEBUG is not set
1312 # CONFIG_REISERFS_FS is not set
1313 # CONFIG_JFS_FS is not set
1314 # CONFIG_FS_POSIX_ACL is not set
1315 @@ -609,7 +899,7 @@ CONFIG_INOTIFY_USER=y
1316 # CONFIG_DNOTIFY is not set
1317 # CONFIG_AUTOFS_FS is not set
1318 # CONFIG_AUTOFS4_FS is not set
1319 -# CONFIG_FUSE_FS is not set
1323 # CD-ROM/DVD Filesystems
1324 @@ -638,7 +928,7 @@ CONFIG_TMPFS=y
1325 # CONFIG_TMPFS_POSIX_ACL is not set
1326 # CONFIG_HUGETLB_PAGE is not set
1328 -CONFIG_CONFIGFS_FS=m
1329 +CONFIG_CONFIGFS_FS=y
1332 # Miscellaneous filesystems
1333 @@ -683,8 +973,14 @@ CONFIG_SUNRPC=y
1334 # CONFIG_SUNRPC_BIND34 is not set
1335 # CONFIG_RPCSEC_GSS_KRB5 is not set
1336 # CONFIG_RPCSEC_GSS_SPKM3 is not set
1337 -# CONFIG_SMB_FS is not set
1338 -# CONFIG_CIFS is not set
1340 +# CONFIG_SMB_NLS_DEFAULT is not set
1342 +# CONFIG_CIFS_STATS is not set
1343 +# CONFIG_CIFS_WEAK_PW_HASH is not set
1344 +# CONFIG_CIFS_XATTR is not set
1345 +# CONFIG_CIFS_DEBUG2 is not set
1346 +# CONFIG_CIFS_EXPERIMENTAL is not set
1347 # CONFIG_NCP_FS is not set
1348 # CONFIG_CODA_FS is not set
1349 # CONFIG_AFS_FS is not set
1350 diff --git a/arch/avr32/drivers/Makefile b/arch/avr32/drivers/Makefile
1351 new file mode 100644
1352 index 0000000..b429b75
1354 +++ b/arch/avr32/drivers/Makefile
1356 +obj-$(CONFIG_DW_DMAC) += dw-dmac.o
1357 diff --git a/arch/avr32/drivers/dw-dmac.c b/arch/avr32/drivers/dw-dmac.c
1358 new file mode 100644
1359 index 0000000..224eb30
1361 +++ b/arch/avr32/drivers/dw-dmac.c
1364 + * Driver for the Synopsys DesignWare DMA Controller
1366 + * Copyright (C) 2005-2006 Atmel Corporation
1368 + * This program is free software; you can redistribute it and/or modify
1369 + * it under the terms of the GNU General Public License version 2 as
1370 + * published by the Free Software Foundation.
1372 +#include <linux/clk.h>
1373 +#include <linux/device.h>
1374 +#include <linux/dma-mapping.h>
1375 +#include <linux/dmapool.h>
1376 +#include <linux/init.h>
1377 +#include <linux/interrupt.h>
1378 +#include <linux/module.h>
1379 +#include <linux/platform_device.h>
1381 +#include <asm/dma-controller.h>
1382 +#include <asm/io.h>
1384 +#include "dw-dmac.h"
1386 +#define DMAC_NR_CHANNELS 3
1387 +#define DMAC_MAX_BLOCKSIZE 4095
1390 + CH_STATE_FREE = 0,
1391 + CH_STATE_ALLOCATED,
1395 +struct dw_dma_lli {
1405 +struct dw_dma_block {
1406 + struct dw_dma_lli *lli_vaddr;
1407 + dma_addr_t lli_dma_addr;
1410 +struct dw_dma_channel {
1411 + unsigned int state;
1413 + struct dma_request_sg *req_sg;
1414 + struct dma_request_cyclic *req_cyclic;
1415 + unsigned int nr_blocks;
1417 + struct dw_dma_block *block;
1420 +struct dw_dma_controller {
1422 + void * __iomem regs;
1423 + struct dma_pool *lli_pool;
1425 + struct dma_controller dma;
1426 + struct dw_dma_channel channel[DMAC_NR_CHANNELS];
1428 +#define to_dw_dmac(dmac) container_of(dmac, struct dw_dma_controller, dma)
1430 +#define dmac_writel_hi(dmac, reg, value) \
1431 + __raw_writel((value), (dmac)->regs + DW_DMAC_##reg + 4)
1432 +#define dmac_readl_hi(dmac, reg) \
1433 + __raw_readl((dmac)->regs + DW_DMAC_##reg + 4)
1434 +#define dmac_writel_lo(dmac, reg, value) \
1435 + __raw_writel((value), (dmac)->regs + DW_DMAC_##reg)
1436 +#define dmac_readl_lo(dmac, reg) \
1437 + __raw_readl((dmac)->regs + DW_DMAC_##reg)
1438 +#define dmac_chan_writel_hi(dmac, chan, reg, value) \
1439 + __raw_writel((value), ((dmac)->regs + 0x58 * (chan) \
1440 + + DW_DMAC_CHAN_##reg + 4))
1441 +#define dmac_chan_readl_hi(dmac, chan, reg) \
1442 + __raw_readl((dmac)->regs + 0x58 * (chan) + DW_DMAC_CHAN_##reg + 4)
1443 +#define dmac_chan_writel_lo(dmac, chan, reg, value) \
1444 + __raw_writel((value), (dmac)->regs + 0x58 * (chan) + DW_DMAC_CHAN_##reg)
1445 +#define dmac_chan_readl_lo(dmac, chan, reg) \
1446 + __raw_readl((dmac)->regs + 0x58 * (chan) + DW_DMAC_CHAN_##reg)
1447 +#define set_channel_bit(dmac, reg, chan) \
1448 + dmac_writel_lo(dmac, reg, (1 << (chan)) | (1 << ((chan) + 8)))
1449 +#define clear_channel_bit(dmac, reg, chan) \
1450 + dmac_writel_lo(dmac, reg, (0 << (chan)) | (1 << ((chan) + 8)))
1452 +static int dmac_alloc_channel(struct dma_controller *_dmac)
1454 + struct dw_dma_controller *dmac = to_dw_dmac(_dmac);
1455 + struct dw_dma_channel *chan;
1456 + unsigned long flags;
1459 + spin_lock_irqsave(&dmac->lock, flags);
1460 + for (i = 0; i < DMAC_NR_CHANNELS; i++)
1461 + if (dmac->channel[i].state == CH_STATE_FREE)
1464 + if (i < DMAC_NR_CHANNELS) {
1465 + chan = &dmac->channel[i];
1466 + chan->state = CH_STATE_ALLOCATED;
1471 + spin_unlock_irqrestore(&dmac->lock, flags);
1476 +static void dmac_release_channel(struct dma_controller *_dmac, int channel)
1478 + struct dw_dma_controller *dmac = to_dw_dmac(_dmac);
1480 + BUG_ON(channel >= DMAC_NR_CHANNELS
1481 + || dmac->channel[channel].state != CH_STATE_ALLOCATED);
1483 + dmac->channel[channel].state = CH_STATE_FREE;
1486 +static struct dw_dma_block *allocate_blocks(struct dw_dma_controller *dmac,
1487 + unsigned int nr_blocks)
1489 + struct dw_dma_block *block;
1493 + block = kmalloc(nr_blocks * sizeof(*block),
1495 + if (unlikely(!block))
1498 + for (i = 0; i < nr_blocks; i++) {
1499 + p = dma_pool_alloc(dmac->lli_pool, GFP_KERNEL,
1500 + &block[i].lli_dma_addr);
1501 + block[i].lli_vaddr = p;
1509 + for (i = 0; i < nr_blocks; i++) {
1510 + if (!block[i].lli_vaddr)
1512 + dma_pool_free(dmac->lli_pool, block[i].lli_vaddr,
1513 + block[i].lli_dma_addr);
1519 +static void cleanup_channel(struct dw_dma_controller *dmac,
1520 + struct dw_dma_channel *chan)
1524 + if (chan->nr_blocks > 1) {
1525 + for (i = 0; i < chan->nr_blocks; i++)
1526 + dma_pool_free(dmac->lli_pool, chan->block[i].lli_vaddr,
1527 + chan->block[i].lli_dma_addr);
1528 + kfree(chan->block);
1531 + chan->state = CH_STATE_ALLOCATED;
1534 +static int dmac_prepare_request_sg(struct dma_controller *_dmac,
1535 + struct dma_request_sg *req)
1537 + struct dw_dma_controller *dmac = to_dw_dmac(_dmac);
1538 + struct dw_dma_channel *chan;
1539 + unsigned long ctlhi, ctllo, cfghi, cfglo;
1540 + unsigned long block_size;
1541 + unsigned int nr_blocks;
1542 + int ret, i, direction;
1543 + unsigned long flags;
1545 + spin_lock_irqsave(&dmac->lock, flags);
1548 + if (req->req.channel >= DMAC_NR_CHANNELS
1549 + || dmac->channel[req->req.channel].state != CH_STATE_ALLOCATED
1550 + || req->block_size > DMAC_MAX_BLOCKSIZE) {
1551 + spin_unlock_irqrestore(&dmac->lock, flags);
1555 + chan = &dmac->channel[req->req.channel];
1556 + chan->state = CH_STATE_BUSY;
1557 + chan->req_sg = req;
1558 + chan->is_cyclic = 0;
1561 + * We have marked the channel as busy, so no need to keep the
1562 + * lock as long as we only touch the channel-specific
1565 + spin_unlock_irqrestore(&dmac->lock, flags);
1568 + * There may be limitations in the driver and/or the DMA
1569 + * controller that prevents us from sending a whole
1570 + * scatterlist item in one go. Taking this into account,
1571 + * calculate the number of block transfers we need to set up.
1573 + * FIXME: Let the peripheral driver know about the maximum
1574 + * block size we support. We really don't want to use a
1575 + * different block size than what was suggested by the
1578 + * Each block will get its own Linked List Item (LLI) below.
1580 + block_size = req->block_size;
1581 + nr_blocks = req->nr_blocks;
1582 + pr_debug("block_size %lu, nr_blocks %u nr_sg = %u\n",
1583 + block_size, nr_blocks, req->nr_sg);
1585 + BUG_ON(nr_blocks == 0);
1586 + chan->nr_blocks = nr_blocks;
1589 + cfglo = cfghi = 0;
1590 + switch (req->direction) {
1591 + case DMA_DIR_MEM_TO_PERIPH:
1592 + direction = DMA_TO_DEVICE;
1593 + cfghi = req->periph_id << (43 - 32);
1596 + case DMA_DIR_PERIPH_TO_MEM:
1597 + direction = DMA_FROM_DEVICE;
1598 + cfghi = req->periph_id << (39 - 32);
1601 + goto out_unclaim_channel;
1604 + chan->direction = direction;
1606 + dmac_chan_writel_hi(dmac, req->req.channel, CFG, cfghi);
1607 + dmac_chan_writel_lo(dmac, req->req.channel, CFG, cfglo);
1609 + ctlhi = block_size >> req->width;
1610 + ctllo = ((req->direction << 20)
1611 + // | (1 << 14) | (1 << 11) // source/dest burst trans len
1612 + | (req->width << 4) | (req->width << 1)
1613 + | (1 << 0)); // interrupt enable
1615 + if (nr_blocks == 1) {
1616 + /* Only one block: No need to use block chaining */
1617 + if (direction == DMA_TO_DEVICE) {
1618 + dmac_chan_writel_lo(dmac, req->req.channel, SAR,
1619 + req->sg->dma_address);
1620 + dmac_chan_writel_lo(dmac, req->req.channel, DAR,
1622 + ctllo |= 2 << 7; // no dst increment
1624 + dmac_chan_writel_lo(dmac, req->req.channel, SAR,
1626 + dmac_chan_writel_lo(dmac, req->req.channel, DAR,
1627 + req->sg->dma_address);
1628 + ctllo |= 2 << 9; // no src increment
1630 + dmac_chan_writel_lo(dmac, req->req.channel, CTL, ctllo);
1631 + dmac_chan_writel_hi(dmac, req->req.channel, CTL, ctlhi);
1632 + pr_debug("ctl hi:lo 0x%lx:%lx\n", ctlhi, ctllo);
1634 + struct dw_dma_lli *lli, *lli_prev = NULL;
1635 + int j = 0, offset = 0;
1638 + chan->block = allocate_blocks(dmac, nr_blocks);
1640 + goto out_unclaim_channel;
1642 + if (direction == DMA_TO_DEVICE)
1643 + ctllo |= 1 << 28 | 1 << 27 | 2 << 7;
1645 + ctllo |= 1 << 28 | 1 << 27 | 2 << 9;
1648 + * Map scatterlist items to blocks. One scatterlist
1649 + * item may need more than one block for the reasons
1650 + * mentioned above.
1652 + for (i = 0; i < nr_blocks; i++) {
1653 + lli = chan->block[i].lli_vaddr;
1655 + lli_prev->llp = chan->block[i].lli_dma_addr;
1656 + pr_debug("lli[%d] (0x%p/0x%x): 0x%x 0x%x 0x%x 0x%x 0x%x\n",
1657 + i - 1, chan->block[i - 1].lli_vaddr,
1658 + chan->block[i - 1].lli_dma_addr,
1659 + lli_prev->sar, lli_prev->dar, lli_prev->llp,
1660 + lli_prev->ctllo, lli_prev->ctlhi);
1663 + lli->ctllo = ctllo;
1664 + lli->ctlhi = ctlhi;
1665 + if (direction == DMA_TO_DEVICE) {
1666 + lli->sar = req->sg[j].dma_address + offset;
1667 + lli->dar = req->data_reg;
1669 + lli->sar = req->data_reg;
1670 + lli->dar = req->sg[j].dma_address + offset;
1674 + offset += block_size;
1675 + if (offset > req->sg[j].length) {
1681 + pr_debug("lli[%d] (0x%p/0x%x): 0x%x 0x%x 0x%x 0x%x 0x%x\n",
1682 + i - 1, chan->block[i - 1].lli_vaddr,
1683 + chan->block[i - 1].lli_dma_addr, lli_prev->sar,
1684 + lli_prev->dar, lli_prev->llp,
1685 + lli_prev->ctllo, lli_prev->ctlhi);
1688 + * SAR, DAR and CTL are initialized from the LLI. We
1689 + * only have to enable the LLI bits in CTL.
1691 + dmac_chan_writel_hi(dmac, req->req.channel, CTL, 0);
1692 + dmac_chan_writel_lo(dmac, req->req.channel, LLP,
1693 + chan->block[0].lli_dma_addr);
1694 + dmac_chan_writel_lo(dmac, req->req.channel, CTL, 1 << 28 | 1 << 27);
1697 + set_channel_bit(dmac, MASK_XFER, req->req.channel);
1698 + set_channel_bit(dmac, MASK_ERROR, req->req.channel);
1699 + if (req->req.block_complete)
1700 + set_channel_bit(dmac, MASK_BLOCK, req->req.channel);
1702 + clear_channel_bit(dmac, MASK_BLOCK, req->req.channel);
1706 +out_unclaim_channel:
1707 + chan->state = CH_STATE_ALLOCATED;
1711 +static int dmac_prepare_request_cyclic(struct dma_controller *_dmac,
1712 + struct dma_request_cyclic *req)
1714 + struct dw_dma_controller *dmac = to_dw_dmac(_dmac);
1715 + struct dw_dma_channel *chan;
1716 + unsigned long ctlhi, ctllo, cfghi, cfglo;
1717 + unsigned long block_size;
1718 + int ret, i, direction;
1719 + unsigned long flags;
1721 + spin_lock_irqsave(&dmac->lock, flags);
1723 + block_size = (req->buffer_size/req->periods) >> req->width;
1726 + if (req->req.channel >= DMAC_NR_CHANNELS
1727 + || dmac->channel[req->req.channel].state != CH_STATE_ALLOCATED
1728 + || (req->periods == 0)
1729 + || block_size > DMAC_MAX_BLOCKSIZE) {
1730 + spin_unlock_irqrestore(&dmac->lock, flags);
1734 + chan = &dmac->channel[req->req.channel];
1735 + chan->state = CH_STATE_BUSY;
1736 + chan->is_cyclic = 1;
1737 + chan->req_cyclic = req;
1740 + * We have marked the channel as busy, so no need to keep the
1741 + * lock as long as we only touch the channel-specific
1744 + spin_unlock_irqrestore(&dmac->lock, flags);
1749 + BUG_ON(req->buffer_size % req->periods);
1750 + /* printk(KERN_INFO "block_size = %lu, periods = %u\n", block_size, req->periods); */
1752 + chan->nr_blocks = req->periods;
1755 + cfglo = cfghi = 0;
1756 + switch (req->direction) {
1757 + case DMA_DIR_MEM_TO_PERIPH:
1758 + direction = DMA_TO_DEVICE;
1759 + cfghi = req->periph_id << (43 - 32);
1762 + case DMA_DIR_PERIPH_TO_MEM:
1763 + direction = DMA_FROM_DEVICE;
1764 + cfghi = req->periph_id << (39 - 32);
1767 + goto out_unclaim_channel;
1770 + chan->direction = direction;
1772 + dmac_chan_writel_hi(dmac, req->req.channel, CFG, cfghi);
1773 + dmac_chan_writel_lo(dmac, req->req.channel, CFG, cfglo);
1775 + ctlhi = block_size;
1776 + ctllo = ((req->direction << 20)
1777 + | (req->width << 4) | (req->width << 1)
1778 + | (1 << 0)); // interrupt enable
1781 + struct dw_dma_lli *lli = NULL, *lli_prev = NULL;
1784 + chan->block = allocate_blocks(dmac, req->periods);
1786 + goto out_unclaim_channel;
1788 + if (direction == DMA_TO_DEVICE)
1789 + ctllo |= 1 << 28 | 1 << 27 | 2 << 7;
1791 + ctllo |= 1 << 28 | 1 << 27 | 2 << 9;
1794 + * Set up a linked list items where each period gets
1795 + * an item. The linked list item for the last period
1796 + * points back to the star of the buffer making a
1799 + for (i = 0; i < req->periods; i++) {
1800 + lli = chan->block[i].lli_vaddr;
1802 + lli_prev->llp = chan->block[i].lli_dma_addr;
1803 + /* printk(KERN_INFO "lli[%d] (0x%p/0x%x): 0x%x 0x%x 0x%x 0x%x 0x%x\n",
1804 + i - 1, chan->block[i - 1].lli_vaddr,
1805 + chan->block[i - 1].lli_dma_addr,
1806 + lli_prev->sar, lli_prev->dar, lli_prev->llp,
1807 + lli_prev->ctllo, lli_prev->ctlhi);*/
1810 + lli->ctllo = ctllo;
1811 + lli->ctlhi = ctlhi;
1812 + if (direction == DMA_TO_DEVICE) {
1813 + lli->sar = req->buffer_start + i*(block_size << req->width);
1814 + lli->dar = req->data_reg;
1816 + lli->sar = req->data_reg;
1817 + lli->dar = req->buffer_start + i*(block_size << req->width);
1821 + lli->llp = chan->block[0].lli_dma_addr;
1823 + /*printk(KERN_INFO "lli[%d] (0x%p/0x%x): 0x%x 0x%x 0x%x 0x%x 0x%x\n",
1824 + i - 1, chan->block[i - 1].lli_vaddr,
1825 + chan->block[i - 1].lli_dma_addr, lli_prev->sar,
1826 + lli_prev->dar, lli_prev->llp,
1827 + lli_prev->ctllo, lli_prev->ctlhi); */
1830 + * SAR, DAR and CTL are initialized from the LLI. We
1831 + * only have to enable the LLI bits in CTL.
1833 + dmac_chan_writel_lo(dmac, req->req.channel, LLP,
1834 + chan->block[0].lli_dma_addr);
1835 + dmac_chan_writel_lo(dmac, req->req.channel, CTL, 1 << 28 | 1 << 27);
1838 + clear_channel_bit(dmac, MASK_XFER, req->req.channel);
1839 + set_channel_bit(dmac, MASK_ERROR, req->req.channel);
1840 + if (req->req.block_complete)
1841 + set_channel_bit(dmac, MASK_BLOCK, req->req.channel);
1843 + clear_channel_bit(dmac, MASK_BLOCK, req->req.channel);
1847 +out_unclaim_channel:
1848 + chan->state = CH_STATE_ALLOCATED;
1852 +static int dmac_start_request(struct dma_controller *_dmac,
1853 + unsigned int channel)
1855 + struct dw_dma_controller *dmac = to_dw_dmac(_dmac);
1857 + BUG_ON(channel >= DMAC_NR_CHANNELS);
1859 + set_channel_bit(dmac, CH_EN, channel);
1864 +static dma_addr_t dmac_get_current_pos(struct dma_controller *_dmac,
1865 + unsigned int channel)
1867 + struct dw_dma_controller *dmac = to_dw_dmac(_dmac);
1868 + struct dw_dma_channel *chan;
1869 + dma_addr_t current_pos;
1871 + BUG_ON(channel >= DMAC_NR_CHANNELS);
1873 + chan = &dmac->channel[channel];
1875 + switch (chan->direction) {
1876 + case DMA_TO_DEVICE:
1877 + current_pos = dmac_chan_readl_lo(dmac, channel, SAR);
1879 + case DMA_FROM_DEVICE:
1880 + current_pos = dmac_chan_readl_lo(dmac, channel, DAR);
1887 + if (!current_pos) {
1888 + if (chan->is_cyclic) {
1889 + current_pos = chan->req_cyclic->buffer_start;
1891 + current_pos = chan->req_sg->sg->dma_address;
1895 + return current_pos;
1899 +static int dmac_stop_request(struct dma_controller *_dmac,
1900 + unsigned int channel)
1902 + struct dw_dma_controller *dmac = to_dw_dmac(_dmac);
1903 + struct dw_dma_channel *chan;
1905 + BUG_ON(channel >= DMAC_NR_CHANNELS);
1907 + chan = &dmac->channel[channel];
1908 + pr_debug("stop: st%u s%08x d%08x l%08x ctl0x%08x:0x%08x\n",
1909 + chan->state, dmac_chan_readl_lo(dmac, channel, SAR),
1910 + dmac_chan_readl_lo(dmac, channel, DAR),
1911 + dmac_chan_readl_lo(dmac, channel, LLP),
1912 + dmac_chan_readl_hi(dmac, channel, CTL),
1913 + dmac_chan_readl_lo(dmac, channel, CTL));
1915 + if (chan->state == CH_STATE_BUSY) {
1916 + clear_channel_bit(dmac, CH_EN, channel);
1917 + cleanup_channel(dmac, &dmac->channel[channel]);
1924 +static void dmac_block_complete(struct dw_dma_controller *dmac)
1926 + struct dw_dma_channel *chan;
1927 + unsigned long status, chanid;
1929 + status = dmac_readl_lo(dmac, STATUS_BLOCK);
1932 + struct dma_request *req;
1933 + chanid = __ffs(status);
1934 + chan = &dmac->channel[chanid];
1936 + if (chan->is_cyclic) {
1937 + BUG_ON(!chan->req_cyclic
1938 + || !chan->req_cyclic->req.block_complete);
1939 + req = &chan->req_cyclic->req;
1941 + BUG_ON(!chan->req_sg || !chan->req_sg->req.block_complete);
1942 + req = &chan->req_sg->req;
1944 + dmac_writel_lo(dmac, CLEAR_BLOCK, 1 << chanid);
1945 + req->block_complete(req);
1946 + status = dmac_readl_lo(dmac, STATUS_BLOCK);
1950 +static void dmac_xfer_complete(struct dw_dma_controller *dmac)
1952 + struct dw_dma_channel *chan;
1953 + struct dma_request *req;
1954 + unsigned long status, chanid;
1956 + status = dmac_readl_lo(dmac, STATUS_XFER);
1959 + chanid = __ffs(status);
1960 + chan = &dmac->channel[chanid];
1962 + dmac_writel_lo(dmac, CLEAR_XFER, 1 << chanid);
1964 + req = &chan->req_sg->req;
1966 + cleanup_channel(dmac, chan);
1967 + if (req->xfer_complete)
1968 + req->xfer_complete(req);
1970 + status = dmac_readl_lo(dmac, STATUS_XFER);
1974 +static void dmac_error(struct dw_dma_controller *dmac)
1976 + struct dw_dma_channel *chan;
1977 + unsigned long status, chanid;
1979 + status = dmac_readl_lo(dmac, STATUS_ERROR);
1982 + struct dma_request *req;
1984 + chanid = __ffs(status);
1985 + chan = &dmac->channel[chanid];
1987 + dmac_writel_lo(dmac, CLEAR_ERROR, 1 << chanid);
1988 + clear_channel_bit(dmac, CH_EN, chanid);
1990 + if (chan->is_cyclic) {
1991 + BUG_ON(!chan->req_cyclic);
1992 + req = &chan->req_cyclic->req;
1994 + BUG_ON(!chan->req_sg);
1995 + req = &chan->req_sg->req;
1998 + cleanup_channel(dmac, chan);
2002 + status = dmac_readl_lo(dmac, STATUS_XFER);
2006 +static irqreturn_t dmac_interrupt(int irq, void *dev_id)
2008 + struct dw_dma_controller *dmac = dev_id;
2009 + unsigned long status;
2010 + int ret = IRQ_NONE;
2012 + spin_lock(&dmac->lock);
2014 + status = dmac_readl_lo(dmac, STATUS_INT);
2017 + ret = IRQ_HANDLED;
2018 + if (status & 0x10)
2020 + if (status & 0x02)
2021 + dmac_block_complete(dmac);
2022 + if (status & 0x01)
2023 + dmac_xfer_complete(dmac);
2025 + status = dmac_readl_lo(dmac, STATUS_INT);
2028 + spin_unlock(&dmac->lock);
2032 +static int __devinit dmac_probe(struct platform_device *pdev)
2034 + struct dw_dma_controller *dmac;
2035 + struct resource *regs;
2038 + regs = platform_get_resource(pdev, IORESOURCE_MEM, 0);
2042 + dmac = kmalloc(sizeof(*dmac), GFP_KERNEL);
2045 + memset(dmac, 0, sizeof(*dmac));
2047 + dmac->hclk = clk_get(&pdev->dev, "hclk");
2048 + if (IS_ERR(dmac->hclk)) {
2049 + ret = PTR_ERR(dmac->hclk);
2050 + goto out_free_dmac;
2052 + clk_enable(dmac->hclk);
2055 + dmac->lli_pool = dma_pool_create("dmac", &pdev->dev,
2056 + sizeof(struct dw_dma_lli), 4, 0);
2057 + if (!dmac->lli_pool)
2058 + goto out_disable_clk;
2060 + spin_lock_init(&dmac->lock);
2061 + dmac->dma.dev = &pdev->dev;
2062 + dmac->dma.alloc_channel = dmac_alloc_channel;
2063 + dmac->dma.release_channel = dmac_release_channel;
2064 + dmac->dma.prepare_request_sg = dmac_prepare_request_sg;
2065 + dmac->dma.prepare_request_cyclic = dmac_prepare_request_cyclic;
2066 + dmac->dma.start_request = dmac_start_request;
2067 + dmac->dma.stop_request = dmac_stop_request;
2068 + dmac->dma.get_current_pos = dmac_get_current_pos;
2070 + dmac->regs = ioremap(regs->start, regs->end - regs->start + 1);
2072 + goto out_free_pool;
2074 + ret = request_irq(platform_get_irq(pdev, 0), dmac_interrupt,
2075 + IRQF_SAMPLE_RANDOM, pdev->name, dmac);
2077 + goto out_unmap_regs;
2079 + /* Enable the DMA controller */
2080 + dmac_writel_lo(dmac, CFG, 1);
2082 + register_dma_controller(&dmac->dma);
2085 + "dmac%d: DesignWare DMA controller at 0x%p irq %d\n",
2086 + dmac->dma.id, dmac->regs, platform_get_irq(pdev, 0));
2091 + iounmap(dmac->regs);
2093 + dma_pool_destroy(dmac->lli_pool);
2095 + clk_disable(dmac->hclk);
2096 + clk_put(dmac->hclk);
2102 +static struct platform_driver dmac_driver = {
2103 + .probe = dmac_probe,
2109 +static int __init dmac_init(void)
2111 + return platform_driver_register(&dmac_driver);
2113 +subsys_initcall(dmac_init);
2115 +static void __exit dmac_exit(void)
2117 + platform_driver_unregister(&dmac_driver);
2119 +module_exit(dmac_exit);
2121 +MODULE_DESCRIPTION("Synopsys DesignWare DMA Controller driver");
2122 +MODULE_AUTHOR("Haavard Skinnemoen <hskinnemoen@atmel.com>");
2123 +MODULE_LICENSE("GPL");
2124 diff --git a/arch/avr32/drivers/dw-dmac.h b/arch/avr32/drivers/dw-dmac.h
2125 new file mode 100644
2126 index 0000000..1f67921
2128 +++ b/arch/avr32/drivers/dw-dmac.h
2131 + * Driver for the Synopsys DesignWare DMA Controller
2133 + * Copyright (C) 2005-2006 Atmel Corporation
2135 + * This program is free software; you can redistribute it and/or modify
2136 + * it under the terms of the GNU General Public License version 2 as
2137 + * published by the Free Software Foundation.
2139 +#ifndef __AVR32_DW_DMAC_H__
2140 +#define __AVR32_DW_DMAC_H__
2142 +#define DW_DMAC_CFG 0x398
2143 +#define DW_DMAC_CH_EN 0x3a0
2145 +#define DW_DMAC_STATUS_XFER 0x2e8
2146 +#define DW_DMAC_STATUS_BLOCK 0x2f0
2147 +#define DW_DMAC_STATUS_ERROR 0x308
2149 +#define DW_DMAC_MASK_XFER 0x310
2150 +#define DW_DMAC_MASK_BLOCK 0x318
2151 +#define DW_DMAC_MASK_ERROR 0x330
2153 +#define DW_DMAC_CLEAR_XFER 0x338
2154 +#define DW_DMAC_CLEAR_BLOCK 0x340
2155 +#define DW_DMAC_CLEAR_ERROR 0x358
2157 +#define DW_DMAC_STATUS_INT 0x360
2159 +#define DW_DMAC_CHAN_SAR 0x000
2160 +#define DW_DMAC_CHAN_DAR 0x008
2161 +#define DW_DMAC_CHAN_LLP 0x010
2162 +#define DW_DMAC_CHAN_CTL 0x018
2163 +#define DW_DMAC_CHAN_SSTAT 0x020
2164 +#define DW_DMAC_CHAN_DSTAT 0x028
2165 +#define DW_DMAC_CHAN_SSTATAR 0x030
2166 +#define DW_DMAC_CHAN_DSTATAR 0x038
2167 +#define DW_DMAC_CHAN_CFG 0x040
2168 +#define DW_DMAC_CHAN_SGR 0x048
2169 +#define DW_DMAC_CHAN_DSR 0x050
2171 +#endif /* __AVR32_DW_DMAC_H__ */
2172 diff --git a/arch/avr32/kernel/Makefile b/arch/avr32/kernel/Makefile
2173 index 90e5aff..1aedaeb 100644
2174 --- a/arch/avr32/kernel/Makefile
2175 +++ b/arch/avr32/kernel/Makefile
2176 @@ -9,10 +9,6 @@ obj-y += syscall_table.o syscall-stubs.o irq.o
2177 obj-y += setup.o traps.o semaphore.o ptrace.o
2178 obj-y += signal.o sys_avr32.o process.o time.o
2179 obj-y += init_task.o switch_to.o cpu.o
2180 +obj-y += dma-controller.o
2181 obj-$(CONFIG_MODULES) += module.o avr32_ksyms.o
2182 obj-$(CONFIG_KPROBES) += kprobes.o
2184 -USE_STANDARD_AS_RULE := true
2186 -%.lds: %.lds.c FORCE
2187 - $(call if_changed_dep,cpp_lds_S)
2188 diff --git a/arch/avr32/kernel/dma-controller.c b/arch/avr32/kernel/dma-controller.c
2189 new file mode 100644
2190 index 0000000..fb654b3
2192 +++ b/arch/avr32/kernel/dma-controller.c
2195 + * Preliminary DMA controller framework for AVR32
2197 + * Copyright (C) 2005-2006 Atmel Corporation
2199 + * This program is free software; you can redistribute it and/or modify
2200 + * it under the terms of the GNU General Public License version 2 as
2201 + * published by the Free Software Foundation.
2203 +#include <asm/dma-controller.h>
2205 +static LIST_HEAD(controllers);
2207 +int register_dma_controller(struct dma_controller *dmac)
2209 + static int next_id;
2211 + dmac->id = next_id++;
2212 + list_add_tail(&dmac->list, &controllers);
2216 +EXPORT_SYMBOL(register_dma_controller);
2218 +struct dma_controller *find_dma_controller(int id)
2220 + struct dma_controller *dmac;
2222 + list_for_each_entry(dmac, &controllers, list)
2223 + if (dmac->id == id)
2227 +EXPORT_SYMBOL(find_dma_controller);
2228 diff --git a/arch/avr32/kernel/entry-avr32b.S b/arch/avr32/kernel/entry-avr32b.S
2229 index 42657f1..ccadfd9 100644
2230 --- a/arch/avr32/kernel/entry-avr32b.S
2231 +++ b/arch/avr32/kernel/entry-avr32b.S
2232 @@ -159,11 +159,18 @@ handle_vmalloc_miss:
2234 .section .scall.text,"ax",@progbits
2236 +#ifdef CONFIG_PREEMPT
2239 pushm r12 /* r12_orig */
2243 mfsr r0, SYSREG_RAR_SUP
2244 mfsr r1, SYSREG_RSR_SUP
2245 +#ifdef CONFIG_PREEMPT
2251 /* check for syscall tracing */
2252 @@ -638,6 +645,13 @@ irq_level\level:
2254 mfsr r8, rar_int\level
2255 mfsr r9, rsr_int\level
2257 +#ifdef CONFIG_PREEMPT
2258 + sub r11, pc, (. - system_call)
2266 @@ -668,6 +682,16 @@ irq_level\level:
2267 sub sp, -4 /* ignore r12_orig */
2270 +#ifdef CONFIG_PREEMPT
2272 + mfsr r8, rsr_int\level
2274 + mtsr rsr_int\level, r8
2276 + sub sp, -4 /* ignore r12_orig */
2280 2: get_thread_info r0
2281 ld.w r1, r0[TI_flags]
2282 bld r1, TIF_CPU_GOING_TO_SLEEP
2283 diff --git a/arch/avr32/kernel/setup.c b/arch/avr32/kernel/setup.c
2284 index d08b0bc..4b4c188 100644
2285 --- a/arch/avr32/kernel/setup.c
2286 +++ b/arch/avr32/kernel/setup.c
2287 @@ -248,7 +248,7 @@ static int __init early_parse_fbmem(char *p)
2289 fbmem_size = memparse(p, &p);
2291 - fbmem_start = memparse(p, &p);
2292 + fbmem_start = memparse(p + 1, &p);
2293 ret = add_reserved_region(fbmem_start,
2294 fbmem_start + fbmem_size - 1,
2296 diff --git a/arch/avr32/kernel/vmlinux.lds.S b/arch/avr32/kernel/vmlinux.lds.S
2297 new file mode 100644
2298 index 0000000..ce9ac96
2300 +++ b/arch/avr32/kernel/vmlinux.lds.S
2303 + * AVR32 linker script for the Linux kernel
2305 + * Copyright (C) 2004-2006 Atmel Corporation
2307 + * This program is free software; you can redistribute it and/or modify
2308 + * it under the terms of the GNU General Public License version 2 as
2309 + * published by the Free Software Foundation.
2311 +#define LOAD_OFFSET 0x00000000
2312 +#include <asm-generic/vmlinux.lds.h>
2313 +#include <asm/cache.h>
2314 +#include <asm/thread_info.h>
2316 +OUTPUT_FORMAT("elf32-avr32", "elf32-avr32", "elf32-avr32")
2321 +jiffies = jiffies_64 + 4;
2325 + . = CONFIG_ENTRY_ADDRESS;
2326 + .init : AT(ADDR(.init) - LOAD_OFFSET) {
2333 + * .exit.text is discarded at runtime, not
2334 + * link time, to deal with references from
2340 + __tagtable_begin = .;
2342 + __tagtable_end = .;
2345 + __setup_start = .;
2349 + __initcall_start = .;
2351 + __initcall_end = .;
2352 + __con_initcall_start = .;
2353 + *(.con_initcall.init)
2354 + __con_initcall_end = .;
2355 + __security_initcall_start = .;
2356 + *(.security_initcall.init)
2357 + __security_initcall_end = .;
2358 +#ifdef CONFIG_BLK_DEV_INITRD
2360 + __initramfs_start = .;
2362 + __initramfs_end = .;
2364 + . = ALIGN(PAGE_SIZE);
2368 + .text : AT(ADDR(.text) - LOAD_OFFSET) {
2391 + __ex_table : AT(ADDR(__ex_table) - LOAD_OFFSET) {
2392 + __start___ex_table = .;
2394 + __stop___ex_table = .;
2401 + . = ALIGN(THREAD_SIZE);
2403 + .data : AT(ADDR(.data) - LOAD_OFFSET) {
2407 + * First, the init task union, aligned to an 8K boundary.
2409 + *(.data.init_task)
2411 + /* Then, the cacheline aligned data */
2412 + . = ALIGN(L1_CACHE_BYTES);
2413 + *(.data.cacheline_aligned)
2415 + /* And the rest... */
2425 + .bss : AT(ADDR(.bss) - LOAD_OFFSET) {
2434 + /* When something in the kernel is NOT compiled as a module, the module
2435 + * cleanup code and data are put into these segments. Both can then be
2436 + * thrown away, as cleanup code is never called unless it's a module.
2445 diff --git a/arch/avr32/kernel/vmlinux.lds.c b/arch/avr32/kernel/vmlinux.lds.c
2446 deleted file mode 100644
2447 index db0438f..0000000
2448 --- a/arch/avr32/kernel/vmlinux.lds.c
2452 - * AVR32 linker script for the Linux kernel
2454 - * Copyright (C) 2004-2006 Atmel Corporation
2456 - * This program is free software; you can redistribute it and/or modify
2457 - * it under the terms of the GNU General Public License version 2 as
2458 - * published by the Free Software Foundation.
2460 -#define LOAD_OFFSET 0x00000000
2461 -#include <asm-generic/vmlinux.lds.h>
2463 -OUTPUT_FORMAT("elf32-avr32", "elf32-avr32", "elf32-avr32")
2468 -jiffies = jiffies_64 + 4;
2472 - . = CONFIG_ENTRY_ADDRESS;
2473 - .init : AT(ADDR(.init) - LOAD_OFFSET) {
2480 - * .exit.text is discarded at runtime, not
2481 - * link time, to deal with references from
2487 - __tagtable_begin = .;
2489 - __tagtable_end = .;
2492 - __setup_start = .;
2496 - __initcall_start = .;
2498 - __initcall_end = .;
2499 - __con_initcall_start = .;
2500 - *(.con_initcall.init)
2501 - __con_initcall_end = .;
2502 - __security_initcall_start = .;
2503 - *(.security_initcall.init)
2504 - __security_initcall_end = .;
2505 -#ifdef CONFIG_BLK_DEV_INITRD
2507 - __initramfs_start = .;
2509 - __initramfs_end = .;
2516 - .text : AT(ADDR(.text) - LOAD_OFFSET) {
2539 - __ex_table : AT(ADDR(__ex_table) - LOAD_OFFSET) {
2540 - __start___ex_table = .;
2542 - __stop___ex_table = .;
2551 - .data : AT(ADDR(.data) - LOAD_OFFSET) {
2555 - * First, the init task union, aligned to an 8K boundary.
2557 - *(.data.init_task)
2559 - /* Then, the cacheline aligned data */
2561 - *(.data.cacheline_aligned)
2563 - /* And the rest... */
2573 - .bss : AT(ADDR(.bss) - LOAD_OFFSET) {
2582 - /* When something in the kernel is NOT compiled as a module, the module
2583 - * cleanup code and data are put into these segments. Both can then be
2584 - * thrown away, as cleanup code is never called unless it's a module.
2593 diff --git a/arch/avr32/mach-at32ap/Kconfig b/arch/avr32/mach-at32ap/Kconfig
2594 index eb30783..43c5b9f 100644
2595 --- a/arch/avr32/mach-at32ap/Kconfig
2596 +++ b/arch/avr32/mach-at32ap/Kconfig
2597 @@ -26,6 +26,13 @@ config AP7000_8_BIT_SMC
2602 + bool "GPIO /dev interface"
2603 + select CONFIGFS_FS
2606 + Say `Y' to enable a /dev interface to the GPIO pins.
2610 endif # PLATFORM_AT32AP
2611 diff --git a/arch/avr32/mach-at32ap/Makefile b/arch/avr32/mach-at32ap/Makefile
2612 index a8b4450..250372a 100644
2613 --- a/arch/avr32/mach-at32ap/Makefile
2614 +++ b/arch/avr32/mach-at32ap/Makefile
2615 @@ -2,3 +2,4 @@ obj-y += at32ap.o clock.o intc.o extint.o pio.o hsmc.o
2616 obj-$(CONFIG_CPU_AT32AP7000) += at32ap7000.o
2617 obj-$(CONFIG_CPU_AT32AP7000) += time-tc.o
2618 obj-$(CONFIG_CPU_FREQ_AT32AP) += cpufreq.o
2619 +obj-$(CONFIG_GPIO_DEV) += gpio-dev.o
2620 diff --git a/arch/avr32/mach-at32ap/at32ap7000.c b/arch/avr32/mach-at32ap/at32ap7000.c
2621 index 64cc558..8375f89 100644
2622 --- a/arch/avr32/mach-at32ap/at32ap7000.c
2623 +++ b/arch/avr32/mach-at32ap/at32ap7000.c
2629 - * We can reduce the code size a bit by using a constant here. Since
2630 - * this file is completely chip-specific, it's safe to not use
2631 - * ioremap. Generic drivers should of course never do this.
2633 -#define AT32_PM_BASE 0xfff00000
2635 #define PBMEM(base) \
2637 @@ -562,6 +556,17 @@ static struct clk pico_clk = {
2641 +static struct resource dmaca0_resource[] = {
2643 + .start = 0xff200000,
2644 + .end = 0xff20ffff,
2645 + .flags = IORESOURCE_MEM,
2649 +DEFINE_DEV(dmaca, 0);
2650 +DEV_CLK(hclk, dmaca0, hsb, 10);
2652 /* --------------------------------------------------------------------
2654 * -------------------------------------------------------------------- */
2655 @@ -661,6 +666,7 @@ void __init at32_add_system_devices(void)
2656 platform_device_register(&at32_eic0_device);
2657 platform_device_register(&smc0_device);
2658 platform_device_register(&pdc_device);
2659 + platform_device_register(&dmaca0_device);
2661 platform_device_register(&at32_systc0_device);
2663 @@ -966,6 +972,83 @@ at32_add_device_spi(unsigned int id, struct spi_board_info *b, unsigned int n)
2666 /* --------------------------------------------------------------------
2668 + * -------------------------------------------------------------------- */
2670 +static struct resource atmel_twi0_resource[] = {
2671 + PBMEM(0xffe00800),
2674 +DEFINE_DEV(atmel_twi, 0);
2675 +DEV_CLK(pclk,atmel_twi0,pba,2);
2677 +struct platform_device *__init
2678 +at32_add_device_twi(unsigned int id)
2680 + struct platform_device *pdev;
2684 + pdev = &atmel_twi0_device;
2685 + select_peripheral(PA(6), PERIPH_A, 0); /* SDA */
2686 + select_peripheral(PA(7), PERIPH_A, 0); /* SCL */
2693 + platform_device_register(pdev);
2697 +/* --------------------------------------------------------------------
2699 + * -------------------------------------------------------------------- */
2700 +static struct mci_platform_data atmel_mci0_data = {
2701 + .detect_pin = GPIO_PIN_NONE,
2702 + .wp_pin = GPIO_PIN_NONE,
2704 +static struct resource atmel_mci0_resource[] = {
2705 + PBMEM(0xfff02400),
2708 +DEFINE_DEV_DATA(atmel_mci, 0);
2709 +DEV_CLK(mci_clk, atmel_mci0, pbb, 9);
2711 +struct platform_device *__init
2712 +at32_add_device_mci(unsigned int id, struct mci_platform_data *data)
2714 + struct platform_device *pdev;
2718 + pdev = &atmel_mci0_device;
2719 + select_peripheral(PA(10), PERIPH_A, 0); /* CLK */
2720 + select_peripheral(PA(11), PERIPH_A, 0); /* CMD */
2721 + select_peripheral(PA(12), PERIPH_A, 0); /* DATA0 */
2722 + select_peripheral(PA(13), PERIPH_A, 0); /* DATA1 */
2723 + select_peripheral(PA(14), PERIPH_A, 0); /* DATA2 */
2724 + select_peripheral(PA(15), PERIPH_A, 0); /* DATA3 */
2731 + if (data->detect_pin != GPIO_PIN_NONE)
2732 + at32_select_gpio(data->detect_pin, 0);
2733 + if (data->wp_pin != GPIO_PIN_NONE)
2734 + at32_select_gpio(data->wp_pin, 0);
2735 + memcpy(pdev->dev.platform_data, data,
2736 + sizeof(struct mci_platform_data));
2739 + platform_device_register(pdev);
2743 +/* --------------------------------------------------------------------
2745 * -------------------------------------------------------------------- */
2746 static struct atmel_lcdfb_info atmel_lcdfb0_data;
2747 @@ -1168,6 +1251,143 @@ at32_add_device_ssc(unsigned int id, unsigned int flags)
2750 /* --------------------------------------------------------------------
2751 + * USB Device Controller
2752 + * -------------------------------------------------------------------- */
2753 +static struct resource usba0_resource[] __initdata = {
2755 + .start = 0xff300000,
2756 + .end = 0xff3fffff,
2757 + .flags = IORESOURCE_MEM,
2759 + .start = 0xfff03000,
2760 + .end = 0xfff033ff,
2761 + .flags = IORESOURCE_MEM,
2765 +static struct clk usba0_pclk = {
2767 + .parent = &pbb_clk,
2768 + .mode = pbb_clk_mode,
2769 + .get_rate = pbb_clk_get_rate,
2772 +static struct clk usba0_hclk = {
2774 + .parent = &hsb_clk,
2775 + .mode = hsb_clk_mode,
2776 + .get_rate = hsb_clk_get_rate,
2780 +struct platform_device *__init
2781 +at32_add_device_usba(unsigned int id, struct usba_platform_data *data)
2783 + struct platform_device *pdev;
2788 + pdev = platform_device_alloc("atmel_usba_udc", 0);
2792 + if (platform_device_add_resources(pdev, usba0_resource,
2793 + ARRAY_SIZE(usba0_resource)))
2794 + goto out_free_pdev;
2797 + if (platform_device_add_data(pdev, data, sizeof(*data)))
2798 + goto out_free_pdev;
2800 + if (data->vbus_pin != GPIO_PIN_NONE)
2801 + at32_select_gpio(data->vbus_pin, 0);
2804 + usba0_pclk.dev = &pdev->dev;
2805 + usba0_hclk.dev = &pdev->dev;
2807 + platform_device_add(pdev);
2812 + platform_device_put(pdev);
2816 +/* --------------------------------------------------------------------
2818 + * -------------------------------------------------------------------- */
2819 +static struct resource atmel_ac97c0_resource[] = {
2820 + PBMEM(0xfff02800),
2823 +DEFINE_DEV(atmel_ac97c, 0);
2824 +DEV_CLK(pclk, atmel_ac97c0, pbb, 10);
2826 +struct platform_device *__init
2827 +at32_add_device_ac97c(unsigned int id)
2829 + struct platform_device *pdev;
2833 + pdev = &atmel_ac97c0_device;
2834 + select_peripheral(PB(20), PERIPH_B, 0); /* SYNC */
2835 + select_peripheral(PB(21), PERIPH_B, 0); /* SDO */
2836 + select_peripheral(PB(22), PERIPH_B, 0); /* SDI */
2837 + select_peripheral(PB(23), PERIPH_B, 0); /* SCLK */
2843 + platform_device_register(pdev);
2847 +/* --------------------------------------------------------------------
2849 + * -------------------------------------------------------------------- */
2850 +static struct resource abdac0_resource[] = {
2851 + PBMEM(0xfff02000),
2854 +DEFINE_DEV(abdac, 0);
2855 +DEV_CLK(pclk, abdac0, pbb, 8);
2856 +static struct clk abdac0_sample_clk = {
2857 + .name = "sample_clk",
2858 + .dev = &abdac0_device.dev,
2859 + .mode = genclk_mode,
2860 + .get_rate = genclk_get_rate,
2861 + .set_rate = genclk_set_rate,
2862 + .set_parent = genclk_set_parent,
2866 +struct platform_device *__init
2867 +at32_add_device_abdac(unsigned int id)
2869 + struct platform_device *pdev;
2873 + pdev = &abdac0_device;
2874 + select_peripheral(PB(20), PERIPH_A, 0); /* DATA1 */
2875 + select_peripheral(PB(21), PERIPH_A, 0); /* DATA0 */
2876 + select_peripheral(PB(22), PERIPH_A, 0); /* DATAN1 */
2877 + select_peripheral(PB(23), PERIPH_A, 0); /* DATAN0 */
2883 + platform_device_register(pdev);
2887 +/* --------------------------------------------------------------------
2889 * -------------------------------------------------------------------- */
2890 static struct clk gclk0 = {
2891 @@ -1230,6 +1450,7 @@ struct clk *at32_clock_list[] = {
2899 @@ -1247,11 +1468,18 @@ struct clk *at32_clock_list[] = {
2901 &atmel_spi0_spi_clk,
2902 &atmel_spi1_spi_clk,
2904 + &atmel_mci0_mci_clk,
2906 &atmel_lcdfb0_pixclk,
2912 + &atmel_ac97c0_pclk,
2914 + &abdac0_sample_clk,
2918 @@ -1293,6 +1521,7 @@ void __init at32_clock_init(void)
2919 genclk_init_parent(&gclk3);
2920 genclk_init_parent(&gclk4);
2921 genclk_init_parent(&atmel_lcdfb0_pixclk);
2922 + genclk_init_parent(&abdac0_sample_clk);
2925 * Turn on all clocks that have at least one user already, and
2926 diff --git a/arch/avr32/mach-at32ap/clock.c b/arch/avr32/mach-at32ap/clock.c
2927 index 0f8c89c..4642117 100644
2928 --- a/arch/avr32/mach-at32ap/clock.c
2929 +++ b/arch/avr32/mach-at32ap/clock.c
2930 @@ -150,3 +150,119 @@ struct clk *clk_get_parent(struct clk *clk)
2933 EXPORT_SYMBOL(clk_get_parent);
2937 +#ifdef CONFIG_DEBUG_FS
2939 +/* /sys/kernel/debug/at32ap_clk */
2941 +#include <linux/io.h>
2942 +#include <linux/debugfs.h>
2943 +#include <linux/seq_file.h>
2947 +#define NEST_DELTA 2
2951 + struct seq_file *s;
2956 +dump_clock(struct clk *parent, struct clkinf *r)
2958 + unsigned nest = r->nest;
2959 + char buf[16 + NEST_MAX];
2963 + /* skip clocks coupled to devices that aren't registered */
2964 + if (parent->dev && !parent->dev->bus_id[0] && !parent->users)
2967 + /* <nest spaces> name <pad to end> */
2968 + memset(buf, ' ', sizeof(buf) - 1);
2969 + buf[sizeof(buf) - 1] = 0;
2970 + i = strlen(parent->name);
2971 + memcpy(buf + nest, parent->name,
2972 + min(i, (unsigned)(sizeof(buf) - 1 - nest)));
2974 + seq_printf(r->s, "%s%c users=%2d %-3s %9ld Hz",
2975 + buf, parent->set_parent ? '*' : ' ',
2977 + parent->users ? "on" : "off", /* NOTE: not-paranoid!! */
2978 + clk_get_rate(parent));
2980 + seq_printf(r->s, ", for %s", parent->dev->bus_id);
2981 + seq_printf(r->s, "\n");
2983 + /* cost of this scan is small, but not linear... */
2984 + r->nest = nest + NEST_DELTA;
2985 + for (i = 3; i < at32_nr_clocks; i++) {
2986 + clk = at32_clock_list[i];
2987 + if (clk->parent == parent)
2988 + dump_clock(clk, r);
2993 +static int clk_show(struct seq_file *s, void *unused)
2998 + /* show all the power manager registers */
2999 + seq_printf(s, "MCCTRL = %8x\n", pm_readl(MCCTRL));
3000 + seq_printf(s, "CKSEL = %8x\n", pm_readl(CKSEL));
3001 + seq_printf(s, "CPUMASK = %8x\n", pm_readl(CPU_MASK));
3002 + seq_printf(s, "HSBMASK = %8x\n", pm_readl(HSB_MASK));
3003 + seq_printf(s, "PBAMASK = %8x\n", pm_readl(PBA_MASK));
3004 + seq_printf(s, "PBBMASK = %8x\n", pm_readl(PBB_MASK));
3005 + seq_printf(s, "PLL0 = %8x\n", pm_readl(PLL0));
3006 + seq_printf(s, "PLL1 = %8x\n", pm_readl(PLL1));
3007 + seq_printf(s, "IMR = %8x\n", pm_readl(IMR));
3008 + for (i = 0; i < 8; i++) {
3011 + seq_printf(s, "GCCTRL%d = %8x\n", i, pm_readl(GCCTRL(i)));
3014 + seq_printf(s, "\n");
3016 + /* show clock tree as derived from the three oscillators
3017 + * we "know" are at the head of the list
3021 + dump_clock(at32_clock_list[0], &r);
3022 + dump_clock(at32_clock_list[1], &r);
3023 + dump_clock(at32_clock_list[2], &r);
3028 +static int clk_open(struct inode *inode, struct file *file)
3030 + return single_open(file, clk_show, NULL);
3033 +static const struct file_operations clk_operations = {
3036 + .llseek = seq_lseek,
3037 + .release = single_release,
3040 +static int __init clk_debugfs_init(void)
3042 + (void) debugfs_create_file("at32ap_clk", S_IFREG | S_IRUGO,
3043 + NULL, NULL, &clk_operations);
3047 +postcore_initcall(clk_debugfs_init);
3050 diff --git a/arch/avr32/mach-at32ap/gpio-dev.c b/arch/avr32/mach-at32ap/gpio-dev.c
3051 new file mode 100644
3052 index 0000000..8cf6d11
3054 +++ b/arch/avr32/mach-at32ap/gpio-dev.c
3057 + * GPIO /dev and configfs interface
3059 + * Copyright (C) 2006-2007 Atmel Corporation
3061 + * This program is free software; you can redistribute it and/or modify
3062 + * it under the terms of the GNU General Public License version 2 as
3063 + * published by the Free Software Foundation.
3065 +#include <linux/kernel.h>
3066 +#include <linux/configfs.h>
3067 +#include <linux/cdev.h>
3068 +#include <linux/device.h>
3069 +#include <linux/fs.h>
3070 +#include <linux/interrupt.h>
3071 +#include <linux/module.h>
3072 +#include <linux/poll.h>
3073 +#include <linux/uaccess.h>
3074 +#include <linux/wait.h>
3076 +#include <asm/gpio.h>
3077 +#include <asm/arch/portmux.h>
3079 +#define GPIO_DEV_MAX 8
3081 +static struct class *gpio_dev_class;
3082 +static dev_t gpio_devt;
3093 + /* Pin state last time we read it (for blocking reads) */
3097 + wait_queue_head_t change_wq;
3098 + struct fasync_struct *async_queue;
3101 + struct class_device *gpio_dev;
3102 + struct cdev char_dev;
3103 + struct config_item item;
3106 +struct gpio_attribute {
3107 + struct configfs_attribute attr;
3108 + ssize_t (*show)(struct gpio_item *, char *);
3109 + ssize_t (*store)(struct gpio_item *, const char *, size_t);
3112 +static irqreturn_t gpio_dev_interrupt(int irq, void *dev_id)
3114 + struct gpio_item *gpio = dev_id;
3115 + u32 old_state, new_state;
3117 + old_state = gpio->pin_state;
3118 + new_state = at32_gpio_get_value_multiple(gpio->port, gpio->pin_mask);
3119 + gpio->pin_state = new_state;
3121 + if (new_state != old_state) {
3122 + gpio->changed = 1;
3123 + wake_up_interruptible(&gpio->change_wq);
3125 + if (gpio->async_queue)
3126 + kill_fasync(&gpio->async_queue, SIGIO, POLL_IN);
3129 + return IRQ_HANDLED;
3132 +static int gpio_dev_open(struct inode *inode, struct file *file)
3134 + struct gpio_item *gpio = container_of(inode->i_cdev,
3141 + nonseekable_open(inode, file);
3142 + config_item_get(&gpio->item);
3143 + file->private_data = gpio;
3145 + gpio->pin_state = at32_gpio_get_value_multiple(gpio->port,
3147 + gpio->changed = 1;
3149 + for (i = 0; i < 32; i++) {
3150 + if (gpio->pin_mask & (1 << i)) {
3151 + irq = gpio_to_irq(32 * gpio->port + i);
3152 + ret = request_irq(irq, gpio_dev_interrupt, 0,
3153 + "gpio-dev", gpio);
3163 + if (gpio->pin_mask & (1 << i)) {
3164 + irq = gpio_to_irq(32 * gpio->port + i);
3165 + free_irq(irq, gpio);
3169 + config_item_put(&gpio->item);
3174 +static int gpio_dev_fasync(int fd, struct file *file, int mode)
3176 + struct gpio_item *gpio = file->private_data;
3178 + return fasync_helper(fd, file, mode, &gpio->async_queue);
3181 +static int gpio_dev_release(struct inode *inode, struct file *file)
3183 + struct gpio_item *gpio = file->private_data;
3187 + gpio_dev_fasync(-1, file, 0);
3189 + for (i = 0; i < 32; i++) {
3190 + if (gpio->pin_mask & (1 << i)) {
3191 + irq = gpio_to_irq(32 * gpio->port + i);
3192 + free_irq(irq, gpio);
3196 + config_item_put(&gpio->item);
3201 +static unsigned int gpio_dev_poll(struct file *file, poll_table *wait)
3203 + struct gpio_item *gpio = file->private_data;
3204 + unsigned int mask = 0;
3206 + poll_wait(file, &gpio->change_wq, wait);
3207 + if (gpio->changed)
3208 + mask |= POLLIN | POLLRDNORM;
3213 +static ssize_t gpio_dev_read(struct file *file, char __user *buf,
3214 + size_t count, loff_t *offset)
3216 + struct gpio_item *gpio = file->private_data;
3219 + spin_lock_irq(&gpio->lock);
3220 + while (!gpio->changed) {
3221 + spin_unlock_irq(&gpio->lock);
3223 + if (file->f_flags & O_NONBLOCK)
3226 + if (wait_event_interruptible(gpio->change_wq, gpio->changed))
3227 + return -ERESTARTSYS;
3229 + spin_lock_irq(&gpio->lock);
3232 + gpio->changed = 0;
3233 + value = at32_gpio_get_value_multiple(gpio->port, gpio->pin_mask);
3235 + spin_unlock_irq(&gpio->lock);
3237 + count = min(count, (size_t)4);
3238 + if (copy_to_user(buf, &value, count))
3244 +static ssize_t gpio_dev_write(struct file *file, const char __user *buf,
3245 + size_t count, loff_t *offset)
3247 + struct gpio_item *gpio = file->private_data;
3251 + count = min(count, (size_t)4);
3252 + if (copy_from_user(&value, buf, count))
3255 + /* Assuming big endian */
3256 + mask <<= (4 - count) * 8;
3257 + mask &= gpio->pin_mask;
3259 + at32_gpio_set_value_multiple(gpio->port, value, mask);
3264 +static struct file_operations gpio_dev_fops = {
3265 + .owner = THIS_MODULE,
3266 + .llseek = no_llseek,
3267 + .open = gpio_dev_open,
3268 + .release = gpio_dev_release,
3269 + .fasync = gpio_dev_fasync,
3270 + .poll = gpio_dev_poll,
3271 + .read = gpio_dev_read,
3272 + .write = gpio_dev_write,
3275 +static struct gpio_item *to_gpio_item(struct config_item *item)
3277 + return item ? container_of(item, struct gpio_item, item) : NULL;
3280 +static ssize_t gpio_show_gpio_id(struct gpio_item *gpio, char *page)
3282 + return sprintf(page, "%d\n", gpio->port);
3285 +static ssize_t gpio_store_gpio_id(struct gpio_item *gpio,
3286 + const char *page, size_t count)
3289 + char *p = (char *)page;
3290 + ssize_t ret = -EINVAL;
3292 + id = simple_strtoul(p, &p, 0);
3293 + if (!p || (*p && (*p != '\n')))
3296 + /* Switching PIO is not allowed when live... */
3297 + spin_lock(&gpio->lock);
3298 + if (!gpio->enabled) {
3300 + if (at32_gpio_port_is_valid(id)) {
3305 + spin_unlock(&gpio->lock);
3310 +static ssize_t gpio_show_pin_mask(struct gpio_item *gpio, char *page)
3312 + return sprintf(page, "0x%08x\n", gpio->pin_mask);
3315 +static ssize_t gpio_store_pin_mask(struct gpio_item *gpio,
3316 + const char *page, size_t count)
3319 + char *p = (char *)page;
3320 + ssize_t ret = -EINVAL;
3322 + new_mask = simple_strtoul(p, &p, 0);
3323 + if (!p || (*p && (*p != '\n')))
3326 + /* Can't update the pin mask while live. */
3327 + spin_lock(&gpio->lock);
3328 + if (!gpio->enabled) {
3329 + gpio->oe_mask &= new_mask;
3330 + gpio->pin_mask = new_mask;
3333 + spin_unlock(&gpio->lock);
3338 +static ssize_t gpio_show_oe_mask(struct gpio_item *gpio, char *page)
3340 + return sprintf(page, "0x%08x\n", gpio->oe_mask);
3343 +static ssize_t gpio_store_oe_mask(struct gpio_item *gpio,
3344 + const char *page, size_t count)
3347 + char *p = (char *)page;
3348 + ssize_t ret = -EINVAL;
3350 + mask = simple_strtoul(p, &p, 0);
3351 + if (!p || (*p && (*p != '\n')))
3354 + spin_lock(&gpio->lock);
3355 + if (!gpio->enabled) {
3356 + gpio->oe_mask = mask & gpio->pin_mask;
3359 + spin_unlock(&gpio->lock);
3364 +static ssize_t gpio_show_enabled(struct gpio_item *gpio, char *page)
3366 + return sprintf(page, "%d\n", gpio->enabled);
3369 +static ssize_t gpio_store_enabled(struct gpio_item *gpio,
3370 + const char *page, size_t count)
3372 + char *p = (char *)page;
3376 + enabled = simple_strtoul(p, &p, 0);
3377 + if (!p || (*p && (*p != '\n')))
3380 + /* make it a boolean value */
3381 + enabled = !!enabled;
3383 + if (gpio->enabled == enabled)
3384 + /* No change; do nothing. */
3387 + BUG_ON(gpio->id >= GPIO_DEV_MAX);
3390 + class_device_unregister(gpio->gpio_dev);
3391 + cdev_del(&gpio->char_dev);
3392 + at32_deselect_pins(gpio->port, gpio->pin_mask);
3393 + gpio->initialized = 0;
3395 + if (gpio->port < 0 || !gpio->pin_mask)
3399 + /* Disallow any updates to gpio_id or pin_mask */
3400 + spin_lock(&gpio->lock);
3401 + gpio->enabled = enabled;
3402 + spin_unlock(&gpio->lock);
3407 + /* Now, try to allocate the pins */
3408 + ret = at32_select_gpio_pins(gpio->port, gpio->pin_mask, gpio->oe_mask);
3410 + goto err_alloc_pins;
3412 + gpio->initialized = 1;
3414 + cdev_init(&gpio->char_dev, &gpio_dev_fops);
3415 + gpio->char_dev.owner = THIS_MODULE;
3416 + ret = cdev_add(&gpio->char_dev, MKDEV(MAJOR(gpio_devt), gpio->id), 1);
3418 + goto err_cdev_add;
3419 + gpio->gpio_dev = class_device_create(gpio_dev_class, NULL,
3420 + MKDEV(MAJOR(gpio_devt), gpio->id),
3422 + "gpio%d", gpio->id);
3423 + if (IS_ERR(gpio->gpio_dev)) {
3424 + printk(KERN_ERR "failed to create gpio%d\n", gpio->id);
3425 + ret = PTR_ERR(gpio->gpio_dev);
3426 + goto err_class_dev;
3429 + printk(KERN_INFO "created gpio%d (port%d/0x%08x) as (%d:%d)\n",
3430 + gpio->id, gpio->port, gpio->pin_mask,
3431 + MAJOR(gpio->gpio_dev->devt), MINOR(gpio->gpio_dev->devt));
3436 + cdev_del(&gpio->char_dev);
3438 + at32_deselect_pins(gpio->port, gpio->pin_mask);
3439 + gpio->initialized = 0;
3441 + spin_lock(&gpio->lock);
3442 + gpio->enabled = 0;
3443 + spin_unlock(&gpio->lock);
3448 +static struct gpio_attribute gpio_item_attr_gpio_id = {
3450 + .ca_owner = THIS_MODULE,
3451 + .ca_name = "gpio_id",
3452 + .ca_mode = S_IRUGO | S_IWUSR,
3454 + .show = gpio_show_gpio_id,
3455 + .store = gpio_store_gpio_id,
3457 +static struct gpio_attribute gpio_item_attr_pin_mask = {
3459 + .ca_owner = THIS_MODULE,
3460 + .ca_name = "pin_mask",
3461 + .ca_mode = S_IRUGO | S_IWUSR,
3463 + .show = gpio_show_pin_mask,
3464 + .store = gpio_store_pin_mask,
3466 +static struct gpio_attribute gpio_item_attr_oe_mask = {
3468 + .ca_owner = THIS_MODULE,
3469 + .ca_name = "oe_mask",
3470 + .ca_mode = S_IRUGO | S_IWUSR,
3472 + .show = gpio_show_oe_mask,
3473 + .store = gpio_store_oe_mask,
3475 +static struct gpio_attribute gpio_item_attr_enabled = {
3477 + .ca_owner = THIS_MODULE,
3478 + .ca_name = "enabled",
3479 + .ca_mode = S_IRUGO | S_IWUSR,
3481 + .show = gpio_show_enabled,
3482 + .store = gpio_store_enabled,
3485 +static struct configfs_attribute *gpio_item_attrs[] = {
3486 + &gpio_item_attr_gpio_id.attr,
3487 + &gpio_item_attr_pin_mask.attr,
3488 + &gpio_item_attr_oe_mask.attr,
3489 + &gpio_item_attr_enabled.attr,
3493 +static ssize_t gpio_show_attr(struct config_item *item,
3494 + struct configfs_attribute *attr,
3497 + struct gpio_item *gpio_item = to_gpio_item(item);
3498 + struct gpio_attribute *gpio_attr
3499 + = container_of(attr, struct gpio_attribute, attr);
3502 + if (gpio_attr->show)
3503 + ret = gpio_attr->show(gpio_item, page);
3507 +static ssize_t gpio_store_attr(struct config_item *item,
3508 + struct configfs_attribute *attr,
3509 + const char *page, size_t count)
3511 + struct gpio_item *gpio_item = to_gpio_item(item);
3512 + struct gpio_attribute *gpio_attr
3513 + = container_of(attr, struct gpio_attribute, attr);
3514 + ssize_t ret = -EINVAL;
3516 + if (gpio_attr->store)
3517 + ret = gpio_attr->store(gpio_item, page, count);
3521 +static void gpio_release(struct config_item *item)
3523 + kfree(to_gpio_item(item));
3526 +static struct configfs_item_operations gpio_item_ops = {
3527 + .release = gpio_release,
3528 + .show_attribute = gpio_show_attr,
3529 + .store_attribute = gpio_store_attr,
3532 +static struct config_item_type gpio_item_type = {
3533 + .ct_item_ops = &gpio_item_ops,
3534 + .ct_attrs = gpio_item_attrs,
3535 + .ct_owner = THIS_MODULE,
3538 +static struct config_item *gpio_make_item(struct config_group *group,
3541 + static int next_id;
3542 + struct gpio_item *gpio;
3544 + if (next_id >= GPIO_DEV_MAX)
3547 + gpio = kzalloc(sizeof(struct gpio_item), GFP_KERNEL);
3551 + gpio->id = next_id++;
3552 + config_item_init_type_name(&gpio->item, name, &gpio_item_type);
3553 + spin_lock_init(&gpio->lock);
3554 + init_waitqueue_head(&gpio->change_wq);
3556 + return &gpio->item;
3559 +static void gpio_drop_item(struct config_group *group,
3560 + struct config_item *item)
3562 + struct gpio_item *gpio = to_gpio_item(item);
3564 + spin_lock(&gpio->lock);
3565 + if (gpio->enabled) {
3566 + class_device_unregister(gpio->gpio_dev);
3567 + cdev_del(&gpio->char_dev);
3570 + if (gpio->initialized) {
3571 + at32_deselect_pins(gpio->port, gpio->pin_mask);
3572 + gpio->initialized = 0;
3573 + gpio->enabled = 0;
3575 + spin_unlock(&gpio->lock);
3578 +static struct configfs_group_operations gpio_group_ops = {
3579 + .make_item = gpio_make_item,
3580 + .drop_item = gpio_drop_item,
3583 +static struct config_item_type gpio_group_type = {
3584 + .ct_group_ops = &gpio_group_ops,
3585 + .ct_owner = THIS_MODULE,
3588 +static struct configfs_subsystem gpio_subsys = {
3591 + .ci_namebuf = "gpio",
3592 + .ci_type = &gpio_group_type,
3597 +static int __init gpio_dev_init(void)
3601 + gpio_dev_class = class_create(THIS_MODULE, "gpio-dev");
3602 + if (IS_ERR(gpio_dev_class)) {
3603 + err = PTR_ERR(gpio_dev_class);
3604 + goto err_class_create;
3607 + err = alloc_chrdev_region(&gpio_devt, 0, GPIO_DEV_MAX, "gpio");
3609 + goto err_alloc_chrdev;
3611 + /* Configfs initialization */
3612 + config_group_init(&gpio_subsys.su_group);
3613 + mutex_init(&gpio_subsys.su_mutex);
3614 + err = configfs_register_subsystem(&gpio_subsys);
3616 + goto err_register_subsys;
3620 +err_register_subsys:
3621 + unregister_chrdev_region(gpio_devt, GPIO_DEV_MAX);
3623 + class_destroy(gpio_dev_class);
3625 + printk(KERN_WARNING "Failed to initialize gpio /dev interface\n");
3628 +late_initcall(gpio_dev_init);
3629 diff --git a/arch/avr32/mach-at32ap/hsmc.c b/arch/avr32/mach-at32ap/hsmc.c
3630 index 5e22a75..704607f 100644
3631 --- a/arch/avr32/mach-at32ap/hsmc.c
3632 +++ b/arch/avr32/mach-at32ap/hsmc.c
3633 @@ -29,16 +29,25 @@ struct hsmc {
3635 static struct hsmc *hsmc;
3637 -int smc_set_configuration(int cs, const struct smc_config *config)
3638 +void smc_set_timing(struct smc_config *config,
3639 + const struct smc_timing *timing)
3645 - unsigned long offset;
3646 - u32 setup, pulse, cycle, mode;
3650 - if (cs >= NR_CHIP_SELECTS)
3652 + /* Reset all SMC timings */
3653 + config->ncs_read_setup = 0;
3654 + config->nrd_setup = 0;
3655 + config->ncs_write_setup = 0;
3656 + config->nwe_setup = 0;
3657 + config->ncs_read_pulse = 0;
3658 + config->nrd_pulse = 0;
3659 + config->ncs_write_pulse = 0;
3660 + config->nwe_pulse = 0;
3661 + config->read_cycle = 0;
3662 + config->write_cycle = 0;
3665 * cycles = x / T = x * f
3666 @@ -50,16 +59,102 @@ int smc_set_configuration(int cs, const struct smc_config *config)
3668 #define ns2cyc(x) ((((x) * mul) + 65535) >> 16)
3670 - setup = (HSMC_BF(NWE_SETUP, ns2cyc(config->nwe_setup))
3671 - | HSMC_BF(NCS_WR_SETUP, ns2cyc(config->ncs_write_setup))
3672 - | HSMC_BF(NRD_SETUP, ns2cyc(config->nrd_setup))
3673 - | HSMC_BF(NCS_RD_SETUP, ns2cyc(config->ncs_read_setup)));
3674 - pulse = (HSMC_BF(NWE_PULSE, ns2cyc(config->nwe_pulse))
3675 - | HSMC_BF(NCS_WR_PULSE, ns2cyc(config->ncs_write_pulse))
3676 - | HSMC_BF(NRD_PULSE, ns2cyc(config->nrd_pulse))
3677 - | HSMC_BF(NCS_RD_PULSE, ns2cyc(config->ncs_read_pulse)));
3678 - cycle = (HSMC_BF(NWE_CYCLE, ns2cyc(config->write_cycle))
3679 - | HSMC_BF(NRD_CYCLE, ns2cyc(config->read_cycle)));
3680 + if (timing->ncs_read_setup > 0)
3681 + config->ncs_read_setup = ns2cyc(timing->ncs_read_setup);
3683 + if (timing->nrd_setup > 0)
3684 + config->nrd_setup = ns2cyc(timing->nrd_setup);
3686 + if (timing->ncs_write_setup > 0)
3687 + config->ncs_write_setup = ns2cyc(timing->ncs_write_setup);
3689 + if (timing->nwe_setup > 0)
3690 + config->nwe_setup = ns2cyc(timing->nwe_setup);
3692 + if (timing->ncs_read_pulse > 0)
3693 + config->ncs_read_pulse = ns2cyc(timing->ncs_read_pulse);
3695 + if (timing->nrd_pulse > 0)
3696 + config->nrd_pulse = ns2cyc(timing->nrd_pulse);
3698 + if (timing->ncs_write_pulse > 0)
3699 + config->ncs_write_pulse = ns2cyc(timing->ncs_write_pulse);
3701 + if (timing->nwe_pulse > 0)
3702 + config->nwe_pulse = ns2cyc(timing->nwe_pulse);
3704 + if (timing->read_cycle > 0)
3705 + config->read_cycle = ns2cyc(timing->read_cycle);
3707 + if (timing->write_cycle > 0)
3708 + config->write_cycle = ns2cyc(timing->write_cycle);
3710 + /* Extend read cycle in needed */
3711 + if (timing->ncs_read_recover > 0)
3712 + recover = ns2cyc(timing->ncs_read_recover);
3716 + cycle = config->ncs_read_setup + config->ncs_read_pulse + recover;
3718 + if (config->read_cycle < cycle)
3719 + config->read_cycle = cycle;
3721 + /* Extend read cycle in needed */
3722 + if (timing->nrd_recover > 0)
3723 + recover = ns2cyc(timing->nrd_recover);
3727 + cycle = config->nrd_setup + config->nrd_pulse + recover;
3729 + if (config->read_cycle < cycle)
3730 + config->read_cycle = cycle;
3732 + /* Extend write cycle in needed */
3733 + if (timing->ncs_write_recover > 0)
3734 + recover = ns2cyc(timing->ncs_write_recover);
3738 + cycle = config->ncs_write_setup + config->ncs_write_pulse + recover;
3740 + if (config->write_cycle < cycle)
3741 + config->write_cycle = cycle;
3743 + /* Extend write cycle in needed */
3744 + if (timing->nwe_recover > 0)
3745 + recover = ns2cyc(timing->nwe_recover);
3749 + cycle = config->nwe_setup + config->nwe_pulse + recover;
3751 + if (config->write_cycle < cycle)
3752 + config->write_cycle = cycle;
3754 +EXPORT_SYMBOL(smc_set_timing);
3756 +int smc_set_configuration(int cs, const struct smc_config *config)
3758 + unsigned long offset;
3759 + u32 setup, pulse, cycle, mode;
3763 + if (cs >= NR_CHIP_SELECTS)
3766 + setup = (HSMC_BF(NWE_SETUP, config->nwe_setup)
3767 + | HSMC_BF(NCS_WR_SETUP, config->ncs_write_setup)
3768 + | HSMC_BF(NRD_SETUP, config->nrd_setup)
3769 + | HSMC_BF(NCS_RD_SETUP, config->ncs_read_setup));
3770 + pulse = (HSMC_BF(NWE_PULSE, config->nwe_pulse)
3771 + | HSMC_BF(NCS_WR_PULSE, config->ncs_write_pulse)
3772 + | HSMC_BF(NRD_PULSE, config->nrd_pulse)
3773 + | HSMC_BF(NCS_RD_PULSE, config->ncs_read_pulse));
3774 + cycle = (HSMC_BF(NWE_CYCLE, config->write_cycle)
3775 + | HSMC_BF(NRD_CYCLE, config->read_cycle));
3777 switch (config->bus_width) {
3779 diff --git a/arch/avr32/mach-at32ap/pio.c b/arch/avr32/mach-at32ap/pio.c
3780 index 1eb99b8..c978c36 100644
3781 --- a/arch/avr32/mach-at32ap/pio.c
3782 +++ b/arch/avr32/mach-at32ap/pio.c
3783 @@ -110,6 +110,10 @@ void __init at32_select_gpio(unsigned int pin, unsigned long flags)
3784 pio_writel(pio, SODR, mask);
3786 pio_writel(pio, CODR, mask);
3787 + if (flags & AT32_GPIOF_MULTIDRV)
3788 + pio_writel(pio, MDER, mask);
3790 + pio_writel(pio, MDDR, mask);
3791 pio_writel(pio, PUDR, mask);
3792 pio_writel(pio, OER, mask);
3794 @@ -158,6 +162,82 @@ fail:
3798 +#ifdef CONFIG_GPIO_DEV
3800 +/* Gang allocators and accessors; used by the GPIO /dev driver */
3801 +int at32_gpio_port_is_valid(unsigned int port)
3803 + return port < MAX_NR_PIO_DEVICES && pio_dev[port].regs != NULL;
3806 +int at32_select_gpio_pins(unsigned int port, u32 pins, u32 oe_mask)
3808 + struct pio_device *pio;
3811 + pio = &pio_dev[port];
3812 + BUG_ON(port > ARRAY_SIZE(pio_dev) || !pio->regs || (oe_mask & ~pins));
3814 + /* Try to allocate the pins */
3816 + old = pio->pinmux_mask;
3821 + } while (cmpxchg(&pio->pinmux_mask, old, new) != old);
3823 + /* That went well, now configure the port */
3824 + pio_writel(pio, OER, oe_mask);
3825 + pio_writel(pio, PER, pins);
3830 +void at32_deselect_pins(unsigned int port, u32 pins)
3832 + struct pio_device *pio;
3835 + pio = &pio_dev[port];
3836 + BUG_ON(port > ARRAY_SIZE(pio_dev) || !pio->regs);
3838 + /* Return to a "safe" mux configuration */
3839 + pio_writel(pio, PUER, pins);
3840 + pio_writel(pio, ODR, pins);
3842 + /* Deallocate the pins */
3844 + old = pio->pinmux_mask;
3845 + new = old & ~pins;
3846 + } while (cmpxchg(&pio->pinmux_mask, old, new) != old);
3849 +u32 at32_gpio_get_value_multiple(unsigned int port, u32 pins)
3851 + struct pio_device *pio;
3853 + pio = &pio_dev[port];
3854 + BUG_ON(port > ARRAY_SIZE(pio_dev) || !pio->regs);
3856 + return pio_readl(pio, PDSR) & pins;
3859 +void at32_gpio_set_value_multiple(unsigned int port, u32 value, u32 mask)
3861 + struct pio_device *pio;
3863 + pio = &pio_dev[port];
3864 + BUG_ON(port > ARRAY_SIZE(pio_dev) || !pio->regs);
3866 + /* No atomic updates for now... */
3867 + pio_writel(pio, CODR, ~value & mask);
3868 + pio_writel(pio, SODR, value & mask);
3871 +#endif /* CONFIG_GPIO_DEV */
3874 /*--------------------------------------------------------------------------*/
3877 diff --git a/arch/avr32/mach-at32ap/pm.h b/arch/avr32/mach-at32ap/pm.h
3878 index a1f8ace..47efd0d 100644
3879 --- a/arch/avr32/mach-at32ap/pm.h
3880 +++ b/arch/avr32/mach-at32ap/pm.h
3882 #ifndef __ARCH_AVR32_MACH_AT32AP_PM_H__
3883 #define __ARCH_AVR32_MACH_AT32AP_PM_H__
3886 + * We can reduce the code size a bit by using a constant here. Since
3887 + * this file is only used on AVR32 AP CPUs with segmentation enabled,
3888 + * it's safe to not use ioremap. Generic drivers should of course
3891 +#define AT32_PM_BASE 0xfff00000
3893 /* PM register offsets */
3894 #define PM_MCCTRL 0x0000
3895 #define PM_CKSEL 0x0004
3896 diff --git a/arch/avr32/mm/dma-coherent.c b/arch/avr32/mm/dma-coherent.c
3897 index 099212d..26f29c6 100644
3898 --- a/arch/avr32/mm/dma-coherent.c
3899 +++ b/arch/avr32/mm/dma-coherent.c
3900 @@ -41,6 +41,13 @@ static struct page *__dma_alloc(struct device *dev, size_t size,
3901 struct page *page, *free, *end;
3904 + /* Following is a work-around (a.k.a. hack) to prevent pages
3905 + * with __GFP_COMP being passed to split_page() which cannot
3906 + * handle them. The real problem is that this flag probably
3907 + * should be 0 on AVR32 as it is not supported on this
3908 + * platform--see CONFIG_HUGETLB_PAGE. */
3909 + gfp &= ~(__GFP_COMP);
3911 size = PAGE_ALIGN(size);
3912 order = get_order(size);
3914 diff --git a/arch/avr32/mm/init.c b/arch/avr32/mm/init.c
3915 index 82cf708..480760b 100644
3916 --- a/arch/avr32/mm/init.c
3917 +++ b/arch/avr32/mm/init.c
3918 @@ -224,19 +224,9 @@ void free_initmem(void)
3920 #ifdef CONFIG_BLK_DEV_INITRD
3922 -static int keep_initrd;
3924 void free_initrd_mem(unsigned long start, unsigned long end)
3927 - free_area(start, end, "initrd");
3930 -static int __init keepinitrd_setup(char *__unused)
3934 + free_area(start, end, "initrd");
3937 -__setup("keepinitrd", keepinitrd_setup);
3939 diff --git a/drivers/i2c/busses/Kconfig b/drivers/i2c/busses/Kconfig
3940 index 9f3a4cd..6f5bcd6 100644
3941 --- a/drivers/i2c/busses/Kconfig
3942 +++ b/drivers/i2c/busses/Kconfig
3943 @@ -80,6 +80,14 @@ config I2C_AT91
3944 This supports the use of the I2C interface on Atmel AT91
3947 +config I2C_ATMELTWI
3948 + tristate "Atmel Two-Wire Interface (TWI)"
3949 + depends on I2C && (ARCH_AT91 || PLATFORM_AT32AP)
3951 + Atmel on-chip TWI controller. Say Y if you have an AT32 or
3952 + AT91-based device and want to use its built-in TWI
3956 tristate "Au1550/Au1200 SMBus interface"
3957 depends on SOC_AU1550 || SOC_AU1200
3958 diff --git a/drivers/i2c/busses/Makefile b/drivers/i2c/busses/Makefile
3959 index 5b752e4..e4644a8 100644
3960 --- a/drivers/i2c/busses/Makefile
3961 +++ b/drivers/i2c/busses/Makefile
3962 @@ -52,6 +52,7 @@ obj-$(CONFIG_I2C_VIAPRO) += i2c-viapro.o
3963 obj-$(CONFIG_I2C_VOODOO3) += i2c-voodoo3.o
3964 obj-$(CONFIG_SCx200_ACB) += scx200_acb.o
3965 obj-$(CONFIG_SCx200_I2C) += scx200_i2c.o
3966 +obj-$(CONFIG_I2C_ATMELTWI) += i2c-atmeltwi.o
3968 ifeq ($(CONFIG_I2C_DEBUG_BUS),y)
3969 EXTRA_CFLAGS += -DDEBUG
3970 diff --git a/drivers/i2c/busses/i2c-atmeltwi.c b/drivers/i2c/busses/i2c-atmeltwi.c
3971 new file mode 100644
3972 index 0000000..3f78b31
3974 +++ b/drivers/i2c/busses/i2c-atmeltwi.c
3977 + * i2c Support for Atmel's Two-Wire Interface (TWI)
3979 + * Based on the work of Copyright (C) 2004 Rick Bronson
3980 + * Converted to 2.6 by Andrew Victor <andrew at sanpeople.com>
3981 + * Ported to AVR32 and heavily modified by Espen Krangnes
3982 + * <ekrangnes at atmel.com>
3984 + * Copyright (C) 2006 Atmel Corporation
3986 + * Borrowed heavily from the original work by:
3987 + * Copyright (C) 2000 Philip Edelbrock <phil at stimpy.netroedge.com>
3989 + * Partialy rewriten by Karel Hojdar <cmkaho at seznam.cz>
3990 + * bugs removed, interrupt routine markedly rewritten
3992 + * This program is free software; you can redistribute it and/or modify
3993 + * it under the terms of the GNU General Public License as published by
3994 + * the Free Software Foundation; either version 2 of the License, or
3995 + * (at your option) any later version.
3997 +#undef VERBOSE_DEBUG
3999 +#include <linux/module.h>
4000 +#include <linux/slab.h>
4001 +#include <linux/i2c.h>
4002 +#include <linux/init.h>
4003 +#include <linux/clk.h>
4004 +#include <linux/err.h>
4005 +#include <linux/interrupt.h>
4006 +#include <linux/platform_device.h>
4007 +#include <linux/completion.h>
4008 +#include <linux/io.h>
4010 +#include "i2c-atmeltwi.h"
4012 +static unsigned int baudrate = 100 * 1000;
4013 +module_param(baudrate, uint, S_IRUGO);
4014 +MODULE_PARM_DESC(baudrate, "The TWI baudrate");
4018 + void __iomem *regs;
4019 + struct i2c_adapter adapter;
4021 + struct completion comp;
4030 +#define to_atmel_twi(adap) container_of(adap, struct atmel_twi, adapter)
4033 + * (Re)Initialize the TWI hardware registers.
4035 +static int twi_hwinit(struct atmel_twi *twi)
4037 + unsigned long cdiv, ckdiv = 0;
4039 + /* REVISIT: wait till SCL is high before resetting; otherwise,
4040 + * some versions will wedge forever.
4043 + twi_writel(twi, IDR, ~0UL);
4044 + twi_writel(twi, CR, TWI_BIT(SWRST)); /*Reset peripheral*/
4045 + twi_readl(twi, SR);
4047 + cdiv = (clk_get_rate(twi->pclk) / (2 * baudrate)) - 4;
4049 + while (cdiv > 255) {
4054 + /* REVISIT: there are various errata to consider re CDIV and CHDIV
4055 + * here, at least on at91 parts.
4061 + twi_writel(twi, CWGR, TWI_BF(CKDIV, ckdiv)
4062 + | TWI_BF(CHDIV, cdiv)
4063 + | TWI_BF(CLDIV, cdiv));
4068 + * Waits for the i2c status register to set the specified bitmask
4069 + * Returns 0 if timed out ... ~100ms is much longer than the SMBus
4070 + * limit, but I2C has no limit at all.
4072 +static int twi_complete(struct atmel_twi *twi, u32 mask)
4074 + int timeout = msecs_to_jiffies(100);
4076 + mask |= TWI_BIT(TXCOMP);
4077 + twi->mask = mask | TWI_BIT(NACK) | TWI_BIT(OVRE);
4078 + init_completion(&twi->comp);
4080 + twi_writel(twi, IER, mask);
4082 + if (!wait_for_completion_timeout(&twi->comp, timeout)) {
4083 + /* RESET TWI interface */
4084 + twi_writel(twi, CR, TWI_BIT(SWRST));
4086 + /* Reinitialize TWI */
4089 + return -ETIMEDOUT;
4095 + * Generic i2c master transfer entrypoint.
4097 +static int twi_xfer(struct i2c_adapter *adap, struct i2c_msg *pmsg, int num)
4099 + struct atmel_twi *twi = to_atmel_twi(adap);
4102 + dev_dbg(&adap->dev, "twi_xfer: processing %d messages:\n", num);
4105 + for (i = 0; i < num; i++, pmsg++) {
4106 + twi->len = pmsg->len;
4107 + twi->buf = pmsg->buf;
4108 + twi->acks_left = pmsg->len;
4109 + twi_writel(twi, MMR, TWI_BF(DADR, pmsg->addr) |
4110 + (pmsg->flags & I2C_M_RD ? TWI_BIT(MREAD) : 0));
4111 + twi_writel(twi, IADR, TWI_BF(IADR, pmsg->addr));
4113 + dev_dbg(&adap->dev,
4114 + "#%d: %s %d byte%s %s dev 0x%02x\n",
4116 + pmsg->flags & I2C_M_RD ? "reading" : "writing",
4118 + pmsg->len > 1 ? "s" : "",
4119 + pmsg->flags & I2C_M_RD ? "from" : "to", pmsg->addr);
4122 + twi_writel(twi, CR, TWI_BIT(MSEN));
4124 + if (pmsg->flags & I2C_M_RD) {
4125 + /* cleanup after previous RX overruns */
4126 + while (twi_readl(twi, SR) & TWI_BIT(RXRDY))
4127 + twi_readl(twi, RHR);
4129 + if (twi->len == 1)
4130 + twi_writel(twi, CR,
4131 + TWI_BIT(START) | TWI_BIT(STOP));
4133 + twi_writel(twi, CR, TWI_BIT(START));
4135 + if (twi_complete(twi, TWI_BIT(RXRDY)) == -ETIMEDOUT) {
4136 + dev_dbg(&adap->dev, "RX[%d] timeout. "
4137 + "Stopped with %d bytes left\n",
4138 + i, twi->acks_left);
4139 + return -ETIMEDOUT;
4142 + twi_writel(twi, THR, twi->buf[0]);
4144 + /* REVISIT: some chips don't start automagically:
4145 + * twi_writel(twi, CR, TWI_BIT(START));
4147 + if (twi_complete(twi, TWI_BIT(TXRDY)) == -ETIMEDOUT) {
4148 + dev_dbg(&adap->dev, "TX[%d] timeout. "
4149 + "Stopped with %d bytes left\n",
4150 + i, twi->acks_left);
4151 + return -ETIMEDOUT;
4153 + /* REVISIT: an erratum workaround may be needed here;
4154 + * see sam9261 "STOP not generated" (START either).
4158 + /* Disable TWI interface */
4159 + twi_writel(twi, CR, TWI_BIT(MSDIS));
4162 + return twi->status;
4164 + /* WARNING: This driver lies about properly supporting
4165 + * repeated start, or it would *ALWAYS* return here. It
4166 + * has issued a STOP. Continuing is a false claim -- that
4167 + * a second (or third, etc.) message is part of the same
4168 + * "combined" (no STOPs between parts) message.
4171 + } /* end cur msg */
4177 +static irqreturn_t twi_interrupt(int irq, void *dev_id)
4179 + struct atmel_twi *twi = dev_id;
4180 + int status = twi_readl(twi, SR);
4182 + /* Save state for later debug prints */
4183 + int old_status = status;
4185 + if (twi->mask & status) {
4187 + status &= twi->mask;
4189 + if (status & TWI_BIT(RXRDY)) {
4190 + if ((status & TWI_BIT(OVRE)) && twi->acks_left) {
4191 + /* Note weakness in fault reporting model:
4192 + * we can't say "the first N of these data
4193 + * bytes are valid".
4195 + dev_err(&twi->adapter.dev,
4196 + "OVERRUN RX! %04x, lost %d\n",
4197 + old_status, twi->acks_left);
4198 + twi->acks_left = 0;
4199 + twi_writel(twi, CR, TWI_BIT(STOP));
4200 + twi->status = -EOVERFLOW;
4201 + } else if (twi->acks_left > 0) {
4202 + twi->buf[twi->len - twi->acks_left] =
4203 + twi_readl(twi, RHR);
4206 + if (status & TWI_BIT(TXCOMP))
4208 + if (twi->acks_left == 1)
4209 + twi_writel(twi, CR, TWI_BIT(STOP));
4211 + } else if (status & (TWI_BIT(NACK) | TWI_BIT(TXCOMP))) {
4214 + } else if (status & TWI_BIT(TXRDY)) {
4215 + if (twi->acks_left > 0) {
4217 + twi_writel(twi, THR,
4218 + twi->buf[twi->len - twi->acks_left]);
4220 + twi_writel(twi, CR, TWI_BIT(STOP));
4223 + if (twi->acks_left == 0)
4224 + twi_writel(twi, IDR, ~TWI_BIT(TXCOMP));
4227 + /* enabling this message helps trigger overruns/underruns ... */
4228 + dev_vdbg(&twi->adapter.dev,
4229 + "ISR: SR 0x%04X, mask 0x%04X, acks %i\n",
4231 + twi->acks_left ? twi->mask : TWI_BIT(TXCOMP),
4234 + return IRQ_HANDLED;
4237 + /* Note weak fault reporting model: we can't report how many
4238 + * bytes we sent before the NAK, or let upper layers choose
4239 + * whether to continue. The I2C stack doesn't allow that...
4241 + if (status & TWI_BIT(NACK)) {
4242 + dev_dbg(&twi->adapter.dev, "NACK received! %d to go\n",
4244 + twi->status = -EPIPE;
4246 + /* TX underrun morphs automagically into a premature STOP;
4247 + * we'll probably observe UVRE even when it's not documented.
4249 + } else if (twi->acks_left && (twi->mask & TWI_BIT(TXRDY))) {
4250 + dev_err(&twi->adapter.dev, "UNDERRUN TX! %04x, %d to go\n",
4251 + old_status, twi->acks_left);
4252 + twi->status = -ENOSR;
4255 + twi_writel(twi, IDR, ~0UL);
4256 + complete(&twi->comp);
4258 + dev_dbg(&twi->adapter.dev, "ISR: SR 0x%04X, acks %i --> %d\n",
4259 + old_status, twi->acks_left, twi->status);
4261 + return IRQ_HANDLED;
4266 + * Return list of supported functionality.
4268 + * NOTE: see warning above about repeated starts; this driver is falsely
4269 + * claiming to support "combined" transfers. The mid-message STOPs mean
4270 + * some slaves will never work with this driver. (Use i2c-gpio...)
4272 +static u32 twi_func(struct i2c_adapter *adapter)
4274 + return (I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL)
4275 + & ~I2C_FUNC_SMBUS_QUICK;
4278 +static struct i2c_algorithm twi_algorithm = {
4279 + .master_xfer = twi_xfer,
4280 + .functionality = twi_func,
4284 + * Main initialization routine.
4286 +static int __init twi_probe(struct platform_device *pdev)
4288 + struct atmel_twi *twi;
4289 + struct resource *regs;
4291 + struct i2c_adapter *adapter;
4294 + regs = platform_get_resource(pdev, IORESOURCE_MEM, 0);
4298 + pclk = clk_get(&pdev->dev, "pclk");
4300 + return PTR_ERR(pclk);
4304 + twi = kzalloc(sizeof(struct atmel_twi), GFP_KERNEL);
4306 + dev_dbg(&pdev->dev, "can't allocate interface!\n");
4307 + goto err_alloc_twi;
4311 + twi->regs = ioremap(regs->start, regs->end - regs->start + 1);
4315 + irq = platform_get_irq(pdev, 0);
4316 + rc = request_irq(irq, twi_interrupt, 0, "twi", twi);
4318 + dev_dbg(&pdev->dev, "can't bind irq!\n");
4323 + rc = twi_hwinit(twi);
4325 + dev_err(&pdev->dev, "Unable to set baudrate\n");
4329 + adapter = &twi->adapter;
4330 + sprintf(adapter->name, "TWI");
4331 + adapter->algo = &twi_algorithm;
4332 + adapter->class = I2C_CLASS_ALL;
4333 + adapter->nr = pdev->id;
4334 + adapter->dev.parent = &pdev->dev;
4336 + platform_set_drvdata(pdev, twi);
4338 + rc = i2c_add_numbered_adapter(adapter);
4340 + dev_dbg(&pdev->dev, "Adapter %s registration failed\n",
4342 + goto err_register;
4345 + dev_info(&pdev->dev,
4346 + "Atmel TWI/I2C adapter (baudrate %dk) at 0x%08lx.\n",
4347 + baudrate/1000, (unsigned long)regs->start);
4353 + platform_set_drvdata(pdev, NULL);
4356 + free_irq(irq, twi);
4359 + iounmap(twi->regs);
4365 + clk_disable(pclk);
4371 +static int __exit twi_remove(struct platform_device *pdev)
4373 + struct atmel_twi *twi = platform_get_drvdata(pdev);
4376 + platform_set_drvdata(pdev, NULL);
4377 + res = i2c_del_adapter(&twi->adapter);
4378 + twi_writel(twi, CR, TWI_BIT(MSDIS));
4379 + iounmap(twi->regs);
4380 + clk_disable(twi->pclk);
4381 + clk_put(twi->pclk);
4382 + free_irq(twi->irq, twi);
4388 +static struct platform_driver twi_driver = {
4389 + .remove = __exit_p(twi_remove),
4391 + .name = "atmel_twi",
4392 + .owner = THIS_MODULE,
4396 +static int __init atmel_twi_init(void)
4398 + return platform_driver_probe(&twi_driver, twi_probe);
4401 +static void __exit atmel_twi_exit(void)
4403 + platform_driver_unregister(&twi_driver);
4406 +module_init(atmel_twi_init);
4407 +module_exit(atmel_twi_exit);
4409 +MODULE_AUTHOR("Espen Krangnes");
4410 +MODULE_DESCRIPTION("I2C driver for Atmel TWI");
4411 +MODULE_LICENSE("GPL");
4412 diff --git a/drivers/i2c/busses/i2c-atmeltwi.h b/drivers/i2c/busses/i2c-atmeltwi.h
4413 new file mode 100644
4414 index 0000000..1aca065
4416 +++ b/drivers/i2c/busses/i2c-atmeltwi.h
4419 + * Register definitions for the Atmel Two-Wire Interface
4422 +#ifndef __ATMELTWI_H__
4423 +#define __ATMELTWI_H__
4425 +/* TWI register offsets */
4426 +#define TWI_CR 0x0000
4427 +#define TWI_MMR 0x0004
4428 +#define TWI_SMR 0x0008
4429 +#define TWI_IADR 0x000c
4430 +#define TWI_CWGR 0x0010
4431 +#define TWI_SR 0x0020
4432 +#define TWI_IER 0x0024
4433 +#define TWI_IDR 0x0028
4434 +#define TWI_IMR 0x002c
4435 +#define TWI_RHR 0x0030
4436 +#define TWI_THR 0x0034
4438 +/* Bitfields in CR */
4439 +#define TWI_START_OFFSET 0
4440 +#define TWI_START_SIZE 1
4441 +#define TWI_STOP_OFFSET 1
4442 +#define TWI_STOP_SIZE 1
4443 +#define TWI_MSEN_OFFSET 2
4444 +#define TWI_MSEN_SIZE 1
4445 +#define TWI_MSDIS_OFFSET 3
4446 +#define TWI_MSDIS_SIZE 1
4447 +#define TWI_SVEN_OFFSET 4
4448 +#define TWI_SVEN_SIZE 1
4449 +#define TWI_SVDIS_OFFSET 5
4450 +#define TWI_SVDIS_SIZE 1
4451 +#define TWI_SWRST_OFFSET 7
4452 +#define TWI_SWRST_SIZE 1
4454 +/* Bitfields in MMR */
4455 +#define TWI_IADRSZ_OFFSET 8
4456 +#define TWI_IADRSZ_SIZE 2
4457 +#define TWI_MREAD_OFFSET 12
4458 +#define TWI_MREAD_SIZE 1
4459 +#define TWI_DADR_OFFSET 16
4460 +#define TWI_DADR_SIZE 7
4462 +/* Bitfields in SMR */
4463 +#define TWI_SADR_OFFSET 16
4464 +#define TWI_SADR_SIZE 7
4466 +/* Bitfields in IADR */
4467 +#define TWI_IADR_OFFSET 0
4468 +#define TWI_IADR_SIZE 24
4470 +/* Bitfields in CWGR */
4471 +#define TWI_CLDIV_OFFSET 0
4472 +#define TWI_CLDIV_SIZE 8
4473 +#define TWI_CHDIV_OFFSET 8
4474 +#define TWI_CHDIV_SIZE 8
4475 +#define TWI_CKDIV_OFFSET 16
4476 +#define TWI_CKDIV_SIZE 3
4478 +/* Bitfields in SR */
4479 +#define TWI_TXCOMP_OFFSET 0
4480 +#define TWI_TXCOMP_SIZE 1
4481 +#define TWI_RXRDY_OFFSET 1
4482 +#define TWI_RXRDY_SIZE 1
4483 +#define TWI_TXRDY_OFFSET 2
4484 +#define TWI_TXRDY_SIZE 1
4485 +#define TWI_SVDIR_OFFSET 3
4486 +#define TWI_SVDIR_SIZE 1
4487 +#define TWI_SVACC_OFFSET 4
4488 +#define TWI_SVACC_SIZE 1
4489 +#define TWI_GCACC_OFFSET 5
4490 +#define TWI_GCACC_SIZE 1
4491 +#define TWI_OVRE_OFFSET 6
4492 +#define TWI_OVRE_SIZE 1
4493 +#define TWI_UNRE_OFFSET 7
4494 +#define TWI_UNRE_SIZE 1
4495 +#define TWI_NACK_OFFSET 8
4496 +#define TWI_NACK_SIZE 1
4497 +#define TWI_ARBLST_OFFSET 9
4498 +#define TWI_ARBLST_SIZE 1
4500 +/* Bitfields in RHR */
4501 +#define TWI_RXDATA_OFFSET 0
4502 +#define TWI_RXDATA_SIZE 8
4504 +/* Bitfields in THR */
4505 +#define TWI_TXDATA_OFFSET 0
4506 +#define TWI_TXDATA_SIZE 8
4508 +/* Constants for IADRSZ */
4509 +#define TWI_IADRSZ_NO_ADDR 0
4510 +#define TWI_IADRSZ_ONE_BYTE 1
4511 +#define TWI_IADRSZ_TWO_BYTES 2
4512 +#define TWI_IADRSZ_THREE_BYTES 3
4514 +/* Bit manipulation macros */
4515 +#define TWI_BIT(name) \
4516 + (1 << TWI_##name##_OFFSET)
4517 +#define TWI_BF(name, value) \
4518 + (((value) & ((1 << TWI_##name##_SIZE) - 1)) \
4519 + << TWI_##name##_OFFSET)
4520 +#define TWI_BFEXT(name, value) \
4521 + (((value) >> TWI_##name##_OFFSET) \
4522 + & ((1 << TWI_##name##_SIZE) - 1))
4523 +#define TWI_BFINS(name, value, old) \
4524 + (((old) & ~(((1 << TWI_##name##_SIZE) - 1) \
4525 + << TWI_##name##_OFFSET)) \
4526 + | TWI_BF(name, (value)))
4528 +/* Register access macros */
4529 +#define twi_readl(port, reg) \
4530 + __raw_readl((port)->regs + TWI_##reg)
4531 +#define twi_writel(port, reg, value) \
4532 + __raw_writel((value), (port)->regs + TWI_##reg)
4534 +#endif /* __ATMELTWI_H__ */
4535 diff --git a/drivers/misc/Kconfig b/drivers/misc/Kconfig
4536 index 73e248f..9e848cc 100644
4537 --- a/drivers/misc/Kconfig
4538 +++ b/drivers/misc/Kconfig
4539 @@ -202,5 +202,14 @@ config THINKPAD_ACPI_BAY
4541 If you are not sure, say Y here.
4544 + tristate "Device driver for Atmel SSC peripheral"
4545 + depends on AVR32 || ARCH_AT91
4547 + This option enables device driver support for Atmel Syncronized
4548 + Serial Communication peripheral (SSC).
4550 + The SSC peripheral supports a wide variety of serial frame based
4551 + communications, i.e. I2S, SPI, etc.
4553 endif # MISC_DEVICES
4554 diff --git a/drivers/misc/Makefile b/drivers/misc/Makefile
4555 index b5ce0e3..40d8ed1 100644
4556 --- a/drivers/misc/Makefile
4557 +++ b/drivers/misc/Makefile
4558 @@ -15,3 +15,4 @@ obj-$(CONFIG_SGI_IOC4) += ioc4.o
4559 obj-$(CONFIG_SONY_LAPTOP) += sony-laptop.o
4560 obj-$(CONFIG_THINKPAD_ACPI) += thinkpad_acpi.o
4561 obj-$(CONFIG_EEPROM_93CX6) += eeprom_93cx6.o
4562 +obj-$(CONFIG_ATMEL_SSC) += atmel-ssc.o
4563 diff --git a/drivers/misc/atmel-ssc.c b/drivers/misc/atmel-ssc.c
4564 new file mode 100644
4565 index 0000000..058ccac
4567 +++ b/drivers/misc/atmel-ssc.c
4570 + * Atmel SSC driver
4572 + * Copyright (C) 2007 Atmel Corporation
4574 + * This program is free software; you can redistribute it and/or modify
4575 + * it under the terms of the GNU General Public License version 2 as
4576 + * published by the Free Software Foundation.
4579 +#include <linux/platform_device.h>
4580 +#include <linux/list.h>
4581 +#include <linux/clk.h>
4582 +#include <linux/err.h>
4583 +#include <linux/io.h>
4584 +#include <linux/list.h>
4585 +#include <linux/spinlock.h>
4586 +#include <linux/atmel-ssc.h>
4588 +/* Serialize access to ssc_list and user count */
4589 +static DEFINE_SPINLOCK(user_lock);
4590 +static LIST_HEAD(ssc_list);
4592 +struct ssc_device *ssc_request(unsigned int ssc_num)
4594 + int ssc_valid = 0;
4595 + struct ssc_device *ssc;
4597 + spin_lock(&user_lock);
4598 + list_for_each_entry(ssc, &ssc_list, list) {
4599 + if (ssc->pdev->id == ssc_num) {
4606 + spin_unlock(&user_lock);
4607 + dev_dbg(&ssc->pdev->dev, "could not find requested device\n");
4608 + return ERR_PTR(-ENODEV);
4612 + spin_unlock(&user_lock);
4613 + dev_dbg(&ssc->pdev->dev, "module busy\n");
4614 + return ERR_PTR(-EBUSY);
4617 + spin_unlock(&user_lock);
4619 + clk_enable(ssc->clk);
4623 +EXPORT_SYMBOL(ssc_request);
4625 +void ssc_free(struct ssc_device *ssc)
4627 + spin_lock(&user_lock);
4630 + clk_disable(ssc->clk);
4632 + dev_dbg(&ssc->pdev->dev, "device already free\n");
4634 + spin_unlock(&user_lock);
4636 +EXPORT_SYMBOL(ssc_free);
4638 +static int __init ssc_probe(struct platform_device *pdev)
4641 + struct resource *regs;
4642 + struct ssc_device *ssc;
4644 + ssc = kzalloc(sizeof(struct ssc_device), GFP_KERNEL);
4646 + dev_dbg(&pdev->dev, "out of memory\n");
4651 + regs = platform_get_resource(pdev, IORESOURCE_MEM, 0);
4653 + dev_dbg(&pdev->dev, "no mmio resource defined\n");
4658 + ssc->clk = clk_get(&pdev->dev, "pclk");
4659 + if (IS_ERR(ssc->clk)) {
4660 + dev_dbg(&pdev->dev, "no pclk clock defined\n");
4666 + ssc->regs = ioremap(regs->start, regs->end - regs->start + 1);
4668 + dev_dbg(&pdev->dev, "ioremap failed\n");
4673 + /* disable all interrupts */
4674 + clk_enable(ssc->clk);
4675 + ssc_writel(ssc->regs, IDR, ~0UL);
4676 + ssc_readl(ssc->regs, SR);
4677 + clk_disable(ssc->clk);
4679 + ssc->irq = platform_get_irq(pdev, 0);
4681 + dev_dbg(&pdev->dev, "could not get irq\n");
4686 + spin_lock(&user_lock);
4687 + list_add_tail(&ssc->list, &ssc_list);
4688 + spin_unlock(&user_lock);
4690 + platform_set_drvdata(pdev, ssc);
4692 + dev_info(&pdev->dev, "Atmel SSC device at 0x%p (irq %d)\n",
4693 + ssc->regs, ssc->irq);
4698 + iounmap(ssc->regs);
4700 + clk_put(ssc->clk);
4707 +static int __devexit ssc_remove(struct platform_device *pdev)
4709 + struct ssc_device *ssc = platform_get_drvdata(pdev);
4711 + spin_lock(&user_lock);
4712 + iounmap(ssc->regs);
4713 + clk_put(ssc->clk);
4714 + list_del(&ssc->list);
4716 + spin_unlock(&user_lock);
4721 +static struct platform_driver ssc_driver = {
4722 + .remove = __devexit_p(ssc_remove),
4728 +static int __init ssc_init(void)
4730 + return platform_driver_probe(&ssc_driver, ssc_probe);
4732 +module_init(ssc_init);
4734 +static void __exit ssc_exit(void)
4736 + platform_driver_unregister(&ssc_driver);
4738 +module_exit(ssc_exit);
4740 +MODULE_AUTHOR("Hans-Christian Egtvedt <hcegtvedt@atmel.com>");
4741 +MODULE_DESCRIPTION("SSC driver for Atmel AVR32 and AT91");
4742 +MODULE_LICENSE("GPL");
4743 diff --git a/drivers/mmc/host/Kconfig b/drivers/mmc/host/Kconfig
4744 index e23082f..1de1716 100644
4745 --- a/drivers/mmc/host/Kconfig
4746 +++ b/drivers/mmc/host/Kconfig
4747 @@ -74,6 +74,16 @@ config MMC_AT91
4751 +config MMC_ATMELMCI
4752 + tristate "Atmel Multimedia Card Interface support"
4753 + depends on AVR32 && MMC
4755 + This selects the Atmel Multimedia Card Interface. If you have
4756 + a AT91 (ARM) or AT32 (AVR32) platform with a Multimedia Card
4757 + slot, say Y or M here.
4762 tristate "Motorola i.MX Multimedia Card Interface support"
4764 diff --git a/drivers/mmc/host/Makefile b/drivers/mmc/host/Makefile
4765 index 6685f64..4b8e6e2 100644
4766 --- a/drivers/mmc/host/Makefile
4767 +++ b/drivers/mmc/host/Makefile
4768 @@ -14,5 +14,6 @@ obj-$(CONFIG_MMC_WBSD) += wbsd.o
4769 obj-$(CONFIG_MMC_AU1X) += au1xmmc.o
4770 obj-$(CONFIG_MMC_OMAP) += omap.o
4771 obj-$(CONFIG_MMC_AT91) += at91_mci.o
4772 +obj-$(CONFIG_MMC_ATMELMCI) += atmel-mci.o
4773 obj-$(CONFIG_MMC_TIFM_SD) += tifm_sd.o
4775 diff --git a/drivers/mmc/host/atmel-mci.c b/drivers/mmc/host/atmel-mci.c
4776 new file mode 100644
4777 index 0000000..45323c9
4779 +++ b/drivers/mmc/host/atmel-mci.c
4782 + * Atmel MultiMedia Card Interface driver
4784 + * Copyright (C) 2004-2006 Atmel Corporation
4786 + * This program is free software; you can redistribute it and/or modify
4787 + * it under the terms of the GNU General Public License version 2 as
4788 + * published by the Free Software Foundation.
4790 +#include <linux/blkdev.h>
4791 +#include <linux/clk.h>
4792 +#include <linux/device.h>
4793 +#include <linux/dma-mapping.h>
4794 +#include <linux/init.h>
4795 +#include <linux/interrupt.h>
4796 +#include <linux/ioport.h>
4797 +#include <linux/module.h>
4798 +#include <linux/platform_device.h>
4800 +#include <linux/mmc/host.h>
4802 +#include <asm/dma-controller.h>
4803 +#include <asm/io.h>
4804 +#include <asm/arch/board.h>
4805 +#include <asm/arch/gpio.h>
4807 +#include "atmel-mci.h"
4809 +#define DRIVER_NAME "atmel_mci"
4811 +#define MCI_DATA_ERROR_FLAGS (MCI_BIT(DCRCE) | MCI_BIT(DTOE) | \
4812 + MCI_BIT(OVRE) | MCI_BIT(UNRE))
4815 + EVENT_CMD_COMPLETE = 0,
4816 + EVENT_DATA_COMPLETE,
4819 + EVENT_STOP_COMPLETE,
4821 + EVENT_CARD_DETECT,
4824 +struct atmel_mci_dma {
4825 + struct dma_request_sg req;
4826 + unsigned short rx_periph_id;
4827 + unsigned short tx_periph_id;
4831 + struct mmc_host *mmc;
4832 + void __iomem *regs;
4833 + struct atmel_mci_dma dma;
4835 + struct mmc_request *mrq;
4836 + struct mmc_command *cmd;
4837 + struct mmc_data *data;
4844 + struct tasklet_struct tasklet;
4845 + unsigned long pending_events;
4846 + unsigned long completed_events;
4852 + unsigned long bus_hz;
4853 + unsigned long mapbase;
4855 + struct platform_device *pdev;
4857 +#ifdef CONFIG_DEBUG_FS
4858 + struct dentry *debugfs_root;
4859 + struct dentry *debugfs_regs;
4860 + struct dentry *debugfs_req;
4861 + struct dentry *debugfs_pending_events;
4862 + struct dentry *debugfs_completed_events;
4866 +/* Those printks take an awful lot of time... */
4868 +static unsigned int fmax = 15000000U;
4870 +static unsigned int fmax = 1000000U;
4872 +module_param(fmax, uint, 0444);
4873 +MODULE_PARM_DESC(fmax, "Max frequency in Hz of the MMC bus clock");
4875 +/* Test bit macros for completed events */
4876 +#define mci_cmd_is_complete(host) \
4877 + test_bit(EVENT_CMD_COMPLETE, &host->completed_events)
4878 +#define mci_data_is_complete(host) \
4879 + test_bit(EVENT_DATA_COMPLETE, &host->completed_events)
4880 +#define mci_data_error_is_complete(host) \
4881 + test_bit(EVENT_DATA_ERROR, &host->completed_events)
4882 +#define mci_stop_sent_is_complete(host) \
4883 + test_bit(EVENT_STOP_SENT, &host->completed_events)
4884 +#define mci_stop_is_complete(host) \
4885 + test_bit(EVENT_STOP_COMPLETE, &host->completed_events)
4886 +#define mci_dma_error_is_complete(host) \
4887 + test_bit(EVENT_DMA_ERROR, &host->completed_events)
4888 +#define mci_card_detect_is_complete(host) \
4889 + test_bit(EVENT_CARD_DETECT, &host->completed_events)
4891 +/* Test and clear bit macros for pending events */
4892 +#define mci_clear_cmd_is_pending(host) \
4893 + test_and_clear_bit(EVENT_CMD_COMPLETE, &host->pending_events)
4894 +#define mci_clear_data_is_pending(host) \
4895 + test_and_clear_bit(EVENT_DATA_COMPLETE, &host->pending_events)
4896 +#define mci_clear_data_error_is_pending(host) \
4897 + test_and_clear_bit(EVENT_DATA_ERROR, &host->pending_events)
4898 +#define mci_clear_stop_sent_is_pending(host) \
4899 + test_and_clear_bit(EVENT_STOP_SENT, &host->pending_events)
4900 +#define mci_clear_stop_is_pending(host) \
4901 + test_and_clear_bit(EVENT_STOP_COMPLETE, &host->pending_events)
4902 +#define mci_clear_dma_error_is_pending(host) \
4903 + test_and_clear_bit(EVENT_DMA_ERROR, &host->pending_events)
4904 +#define mci_clear_card_detect_is_pending(host) \
4905 + test_and_clear_bit(EVENT_CARD_DETECT, &host->pending_events)
4907 +/* Test and set bit macros for completed events */
4908 +#define mci_set_cmd_is_completed(host) \
4909 + test_and_set_bit(EVENT_CMD_COMPLETE, &host->completed_events)
4910 +#define mci_set_data_is_completed(host) \
4911 + test_and_set_bit(EVENT_DATA_COMPLETE, &host->completed_events)
4912 +#define mci_set_data_error_is_completed(host) \
4913 + test_and_set_bit(EVENT_DATA_ERROR, &host->completed_events)
4914 +#define mci_set_stop_sent_is_completed(host) \
4915 + test_and_set_bit(EVENT_STOP_SENT, &host->completed_events)
4916 +#define mci_set_stop_is_completed(host) \
4917 + test_and_set_bit(EVENT_STOP_COMPLETE, &host->completed_events)
4918 +#define mci_set_dma_error_is_completed(host) \
4919 + test_and_set_bit(EVENT_DMA_ERROR, &host->completed_events)
4920 +#define mci_set_card_detect_is_completed(host) \
4921 + test_and_set_bit(EVENT_CARD_DETECT, &host->completed_events)
4923 +/* Set bit macros for completed events */
4924 +#define mci_set_cmd_complete(host) \
4925 + set_bit(EVENT_CMD_COMPLETE, &host->completed_events)
4926 +#define mci_set_data_complete(host) \
4927 + set_bit(EVENT_DATA_COMPLETE, &host->completed_events)
4928 +#define mci_set_data_error_complete(host) \
4929 + set_bit(EVENT_DATA_ERROR, &host->completed_events)
4930 +#define mci_set_stop_sent_complete(host) \
4931 + set_bit(EVENT_STOP_SENT, &host->completed_events)
4932 +#define mci_set_stop_complete(host) \
4933 + set_bit(EVENT_STOP_COMPLETE, &host->completed_events)
4934 +#define mci_set_dma_error_complete(host) \
4935 + set_bit(EVENT_DMA_ERROR, &host->completed_events)
4936 +#define mci_set_card_detect_complete(host) \
4937 + set_bit(EVENT_CARD_DETECT, &host->completed_events)
4939 +/* Set bit macros for pending events */
4940 +#define mci_set_cmd_pending(host) \
4941 + set_bit(EVENT_CMD_COMPLETE, &host->pending_events)
4942 +#define mci_set_data_pending(host) \
4943 + set_bit(EVENT_DATA_COMPLETE, &host->pending_events)
4944 +#define mci_set_data_error_pending(host) \
4945 + set_bit(EVENT_DATA_ERROR, &host->pending_events)
4946 +#define mci_set_stop_sent_pending(host) \
4947 + set_bit(EVENT_STOP_SENT, &host->pending_events)
4948 +#define mci_set_stop_pending(host) \
4949 + set_bit(EVENT_STOP_COMPLETE, &host->pending_events)
4950 +#define mci_set_dma_error_pending(host) \
4951 + set_bit(EVENT_DMA_ERROR, &host->pending_events)
4952 +#define mci_set_card_detect_pending(host) \
4953 + set_bit(EVENT_CARD_DETECT, &host->pending_events)
4955 +/* Clear bit macros for pending events */
4956 +#define mci_clear_cmd_pending(host) \
4957 + clear_bit(EVENT_CMD_COMPLETE, &host->pending_events)
4958 +#define mci_clear_data_pending(host) \
4959 + clear_bit(EVENT_DATA_COMPLETE, &host->pending_events)
4960 +#define mci_clear_data_error_pending(host) \
4961 + clear_bit(EVENT_DATA_ERROR, &host->pending_events)
4962 +#define mci_clear_stop_sent_pending(host) \
4963 + clear_bit(EVENT_STOP_SENT, &host->pending_events)
4964 +#define mci_clear_stop_pending(host) \
4965 + clear_bit(EVENT_STOP_COMPLETE, &host->pending_events)
4966 +#define mci_clear_dma_error_pending(host) \
4967 + clear_bit(EVENT_DMA_ERROR, &host->pending_events)
4968 +#define mci_clear_card_detect_pending(host) \
4969 + clear_bit(EVENT_CARD_DETECT, &host->pending_events)
4972 +#ifdef CONFIG_DEBUG_FS
4973 +#include <linux/debugfs.h>
4975 +#define DBG_REQ_BUF_SIZE (4096 - sizeof(unsigned int))
4977 +struct req_dbg_data {
4978 + unsigned int nbytes;
4979 + char str[DBG_REQ_BUF_SIZE];
4982 +static int req_dbg_open(struct inode *inode, struct file *file)
4984 + struct atmel_mci *host;
4985 + struct mmc_request *mrq;
4986 + struct mmc_command *cmd, *stop;
4987 + struct mmc_data *data;
4988 + struct req_dbg_data *priv;
4990 + unsigned long n = 0;
4992 + priv = kzalloc(DBG_REQ_BUF_SIZE, GFP_KERNEL);
4997 + mutex_lock(&inode->i_mutex);
4998 + host = inode->i_private;
5000 + spin_lock_irq(&host->mmc->lock);
5006 + n = snprintf(str, DBG_REQ_BUF_SIZE,
5007 + "CMD%u(0x%x) %x %x %x %x %x (err %u)\n",
5008 + cmd->opcode, cmd->arg, cmd->flags,
5009 + cmd->resp[0], cmd->resp[1], cmd->resp[2],
5010 + cmd->resp[3], cmd->error);
5011 + if (n < DBG_REQ_BUF_SIZE && data)
5012 + n += snprintf(str + n, DBG_REQ_BUF_SIZE - n,
5013 + "DATA %u * %u (%u) %x (err %u)\n",
5014 + data->blocks, data->blksz,
5015 + data->bytes_xfered, data->flags,
5017 + if (n < DBG_REQ_BUF_SIZE && stop)
5018 + n += snprintf(str + n, DBG_REQ_BUF_SIZE - n,
5019 + "CMD%u(0x%x) %x %x %x %x %x (err %u)\n",
5020 + stop->opcode, stop->arg, stop->flags,
5021 + stop->resp[0], stop->resp[1],
5022 + stop->resp[2], stop->resp[3],
5025 + spin_unlock_irq(&host->mmc->lock);
5026 + mutex_unlock(&inode->i_mutex);
5028 + priv->nbytes = min(n, DBG_REQ_BUF_SIZE);
5029 + file->private_data = priv;
5034 +static ssize_t req_dbg_read(struct file *file, char __user *buf,
5035 + size_t nbytes, loff_t *ppos)
5037 + struct req_dbg_data *priv = file->private_data;
5039 + return simple_read_from_buffer(buf, nbytes, ppos,
5040 + priv->str, priv->nbytes);
5043 +static int req_dbg_release(struct inode *inode, struct file *file)
5045 + kfree(file->private_data);
5049 +static const struct file_operations req_dbg_fops = {
5050 + .owner = THIS_MODULE,
5051 + .open = req_dbg_open,
5052 + .llseek = no_llseek,
5053 + .read = req_dbg_read,
5054 + .release = req_dbg_release,
5057 +static int regs_dbg_open(struct inode *inode, struct file *file)
5059 + struct atmel_mci *host;
5062 + int ret = -ENOMEM;
5064 + mutex_lock(&inode->i_mutex);
5065 + host = inode->i_private;
5066 + data = kmalloc(inode->i_size, GFP_KERNEL);
5070 + spin_lock_irq(&host->mmc->lock);
5071 + for (i = 0; i < inode->i_size / 4; i++)
5072 + data[i] = __raw_readl(host->regs + i * 4);
5073 + spin_unlock_irq(&host->mmc->lock);
5075 + file->private_data = data;
5079 + mutex_unlock(&inode->i_mutex);
5084 +static ssize_t regs_dbg_read(struct file *file, char __user *buf,
5085 + size_t nbytes, loff_t *ppos)
5087 + struct inode *inode = file->f_dentry->d_inode;
5090 + mutex_lock(&inode->i_mutex);
5091 + ret = simple_read_from_buffer(buf, nbytes, ppos,
5092 + file->private_data,
5093 + file->f_dentry->d_inode->i_size);
5094 + mutex_unlock(&inode->i_mutex);
5099 +static int regs_dbg_release(struct inode *inode, struct file *file)
5101 + kfree(file->private_data);
5105 +static const struct file_operations regs_dbg_fops = {
5106 + .owner = THIS_MODULE,
5107 + .open = regs_dbg_open,
5108 + .llseek = generic_file_llseek,
5109 + .read = regs_dbg_read,
5110 + .release = regs_dbg_release,
5113 +static void atmci_init_debugfs(struct atmel_mci *host)
5115 + struct mmc_host *mmc;
5116 + struct dentry *root, *regs;
5117 + struct resource *res;
5120 + root = debugfs_create_dir(mmc_hostname(mmc), NULL);
5121 + if (IS_ERR(root) || !root)
5123 + host->debugfs_root = root;
5125 + regs = debugfs_create_file("regs", 0400, root, host, ®s_dbg_fops);
5129 + res = platform_get_resource(host->pdev, IORESOURCE_MEM, 0);
5130 + regs->d_inode->i_size = res->end - res->start + 1;
5131 + host->debugfs_regs = regs;
5133 + host->debugfs_req = debugfs_create_file("req", 0400, root,
5134 + host, &req_dbg_fops);
5135 + if (!host->debugfs_req)
5138 + host->debugfs_pending_events
5139 + = debugfs_create_u32("pending_events", 0400, root,
5140 + (u32 *)&host->pending_events);
5141 + if (!host->debugfs_pending_events)
5142 + goto err_pending_events;
5144 + host->debugfs_completed_events
5145 + = debugfs_create_u32("completed_events", 0400, root,
5146 + (u32 *)&host->completed_events);
5147 + if (!host->debugfs_completed_events)
5148 + goto err_completed_events;
5152 +err_completed_events:
5153 + debugfs_remove(host->debugfs_pending_events);
5154 +err_pending_events:
5155 + debugfs_remove(host->debugfs_req);
5157 + debugfs_remove(host->debugfs_regs);
5159 + debugfs_remove(host->debugfs_root);
5161 + host->debugfs_root = NULL;
5162 + dev_err(&host->pdev->dev,
5163 + "failed to initialize debugfs for %s\n",
5164 + mmc_hostname(mmc));
5167 +static void atmci_cleanup_debugfs(struct atmel_mci *host)
5169 + if (host->debugfs_root) {
5170 + debugfs_remove(host->debugfs_completed_events);
5171 + debugfs_remove(host->debugfs_pending_events);
5172 + debugfs_remove(host->debugfs_req);
5173 + debugfs_remove(host->debugfs_regs);
5174 + debugfs_remove(host->debugfs_root);
5175 + host->debugfs_root = NULL;
5179 +static inline void atmci_init_debugfs(struct atmel_mci *host)
5184 +static inline void atmci_cleanup_debugfs(struct atmel_mci *host)
5188 +#endif /* CONFIG_DEBUG_FS */
5190 +static inline unsigned int ns_to_clocks(struct atmel_mci *host,
5193 + return (ns * (host->bus_hz / 1000000) + 999) / 1000;
5196 +static void atmci_set_timeout(struct atmel_mci *host,
5197 + struct mmc_data *data)
5199 + static unsigned dtomul_to_shift[] = {
5200 + 0, 4, 7, 8, 10, 12, 16, 20
5203 + unsigned dtocyc, dtomul;
5205 + timeout = ns_to_clocks(host, data->timeout_ns) + data->timeout_clks;
5207 + for (dtomul = 0; dtomul < 8; dtomul++) {
5208 + unsigned shift = dtomul_to_shift[dtomul];
5209 + dtocyc = (timeout + (1 << shift) - 1) >> shift;
5214 + if (dtomul >= 8) {
5219 + dev_dbg(&host->mmc->class_dev, "setting timeout to %u cycles\n",
5220 + dtocyc << dtomul_to_shift[dtomul]);
5221 + mci_writel(host, DTOR, (MCI_BF(DTOMUL, dtomul)
5222 + | MCI_BF(DTOCYC, dtocyc)));
5226 + * Return mask with command flags to be enabled for this command.
5228 +static u32 atmci_prepare_command(struct mmc_host *mmc,
5229 + struct mmc_command *cmd)
5233 + cmd->error = MMC_ERR_NONE;
5235 + cmdr = MCI_BF(CMDNB, cmd->opcode);
5237 + if (cmd->flags & MMC_RSP_PRESENT) {
5238 + if (cmd->flags & MMC_RSP_136)
5239 + cmdr |= MCI_BF(RSPTYP, MCI_RSPTYP_136_BIT);
5241 + cmdr |= MCI_BF(RSPTYP, MCI_RSPTYP_48_BIT);
5245 + * This should really be MAXLAT_5 for CMD2 and ACMD41, but
5246 + * it's too difficult to determine whether this is an ACMD or
5247 + * not. Better make it 64.
5249 + cmdr |= MCI_BIT(MAXLAT);
5251 + if (mmc->ios.bus_mode == MMC_BUSMODE_OPENDRAIN)
5252 + cmdr |= MCI_BIT(OPDCMD);
5254 + dev_dbg(&mmc->class_dev,
5255 + "cmd: op %02x arg %08x flags %08x, cmdflags %08lx\n",
5256 + cmd->opcode, cmd->arg, cmd->flags, (unsigned long)cmdr);
5261 +static void atmci_start_command(struct atmel_mci *host,
5262 + struct mmc_command *cmd,
5265 + WARN_ON(host->cmd);
5268 + mci_writel(host, ARGR, cmd->arg);
5269 + mci_writel(host, CMDR, cmd_flags);
5272 + dma_start_request(host->dma.req.req.dmac,
5273 + host->dma.req.req.channel);
5277 + * Returns a mask of flags to be set in the command register when the
5278 + * command to start the transfer is to be sent.
5280 +static u32 atmci_prepare_data(struct mmc_host *mmc, struct mmc_data *data)
5282 + struct atmel_mci *host = mmc_priv(mmc);
5285 + WARN_ON(host->data);
5286 + host->data = data;
5288 + atmci_set_timeout(host, data);
5289 + mci_writel(host, BLKR, (MCI_BF(BCNT, data->blocks)
5290 + | MCI_BF(BLKLEN, data->blksz)));
5291 + host->dma.req.block_size = data->blksz;
5292 + host->dma.req.nr_blocks = data->blocks;
5294 + cmd_flags = MCI_BF(TRCMD, MCI_TRCMD_START_TRANS);
5295 + if (data->flags & MMC_DATA_STREAM)
5296 + cmd_flags |= MCI_BF(TRTYP, MCI_TRTYP_STREAM);
5297 + else if (data->blocks > 1)
5298 + cmd_flags |= MCI_BF(TRTYP, MCI_TRTYP_MULTI_BLOCK);
5300 + cmd_flags |= MCI_BF(TRTYP, MCI_TRTYP_BLOCK);
5302 + if (data->flags & MMC_DATA_READ) {
5303 + cmd_flags |= MCI_BIT(TRDIR);
5304 + host->dma.req.nr_sg
5305 + = dma_map_sg(&host->pdev->dev, data->sg,
5306 + data->sg_len, DMA_FROM_DEVICE);
5307 + host->dma.req.periph_id = host->dma.rx_periph_id;
5308 + host->dma.req.direction = DMA_DIR_PERIPH_TO_MEM;
5309 + host->dma.req.data_reg = host->mapbase + MCI_RDR;
5311 + host->dma.req.nr_sg
5312 + = dma_map_sg(&host->pdev->dev, data->sg,
5313 + data->sg_len, DMA_TO_DEVICE);
5314 + host->dma.req.periph_id = host->dma.tx_periph_id;
5315 + host->dma.req.direction = DMA_DIR_MEM_TO_PERIPH;
5316 + host->dma.req.data_reg = host->mapbase + MCI_TDR;
5318 + host->dma.req.sg = data->sg;
5320 + dma_prepare_request_sg(host->dma.req.req.dmac, &host->dma.req);
5325 +static void atmci_request(struct mmc_host *mmc, struct mmc_request *mrq)
5327 + struct atmel_mci *host = mmc_priv(mmc);
5328 + struct mmc_data *data = mrq->data;
5332 + iflags = mci_readl(host, IMR);
5334 + dev_warn(&mmc->class_dev, "WARNING: IMR=0x%08x\n",
5335 + mci_readl(host, IMR));
5337 + WARN_ON(host->mrq != NULL);
5339 + host->pending_events = 0;
5340 + host->completed_events = 0;
5342 + iflags = MCI_BIT(CMDRDY);
5343 + cmdflags = atmci_prepare_command(mmc, mrq->cmd);
5348 + host->stop_cmdr = atmci_prepare_command(mmc, mrq->stop);
5349 + host->stop_cmdr |= MCI_BF(TRCMD, MCI_TRCMD_STOP_TRANS);
5350 + if (!(data->flags & MMC_DATA_WRITE))
5351 + host->stop_cmdr |= MCI_BIT(TRDIR);
5352 + if (data->flags & MMC_DATA_STREAM)
5353 + host->stop_cmdr |= MCI_BF(TRTYP, MCI_TRTYP_STREAM);
5355 + host->stop_cmdr |= MCI_BF(TRTYP, MCI_TRTYP_MULTI_BLOCK);
5358 + cmdflags |= atmci_prepare_data(mmc, data);
5359 + iflags |= MCI_DATA_ERROR_FLAGS;
5362 + atmci_start_command(host, mrq->cmd, cmdflags);
5363 + mci_writel(host, IER, iflags);
5366 +static void atmci_set_ios(struct mmc_host *mmc, struct mmc_ios *ios)
5368 + struct atmel_mci *host = mmc_priv(mmc);
5374 + /* Set clock rate */
5375 + clkdiv = host->bus_hz / (2 * ios->clock) - 1;
5376 + if (clkdiv > 255) {
5377 + dev_warn(&mmc->class_dev,
5378 + "clock %u too slow; using %lu\n",
5379 + ios->clock, host->bus_hz / (2 * 256));
5383 + mr = mci_readl(host, MR);
5384 + mr = MCI_BFINS(CLKDIV, clkdiv, mr)
5385 + | MCI_BIT(WRPROOF) | MCI_BIT(RDPROOF);
5386 + mci_writel(host, MR, mr);
5388 + /* Enable the MCI controller */
5389 + mci_writel(host, CR, MCI_BIT(MCIEN));
5391 + /* Disable the MCI controller */
5392 + mci_writel(host, CR, MCI_BIT(MCIDIS));
5395 + switch (ios->bus_width) {
5396 + case MMC_BUS_WIDTH_1:
5397 + mci_writel(host, SDCR, 0);
5399 + case MMC_BUS_WIDTH_4:
5400 + mci_writel(host, SDCR, MCI_BIT(SDCBUS));
5404 + switch (ios->power_mode) {
5405 + case MMC_POWER_ON:
5406 + /* Send init sequence (74 clock cycles) */
5407 + mci_writel(host, IDR, ~0UL);
5408 + mci_writel(host, CMDR, MCI_BF(SPCMD, MCI_SPCMD_INIT_CMD));
5409 + while (!(mci_readl(host, SR) & MCI_BIT(CMDRDY)))
5414 + * TODO: None of the currently available AVR32-based
5415 + * boards allow MMC power to be turned off. Implement
5416 + * power control when this can be tested properly.
5422 +static int atmci_get_ro(struct mmc_host *mmc)
5424 + int read_only = 0;
5425 + struct atmel_mci *host = mmc_priv(mmc);
5427 + if (host->wp_pin >= 0) {
5428 + read_only = gpio_get_value(host->wp_pin);
5429 + dev_dbg(&mmc->class_dev, "card is %s\n",
5430 + read_only ? "read-only" : "read-write");
5432 + dev_dbg(&mmc->class_dev,
5433 + "no pin for checking read-only switch."
5434 + " Assuming write-enable.\n");
5440 +static struct mmc_host_ops atmci_ops = {
5441 + .request = atmci_request,
5442 + .set_ios = atmci_set_ios,
5443 + .get_ro = atmci_get_ro,
5446 +static void atmci_request_end(struct mmc_host *mmc, struct mmc_request *mrq)
5448 + struct atmel_mci *host = mmc_priv(mmc);
5450 + WARN_ON(host->cmd || host->data);
5453 + mmc_request_done(mmc, mrq);
5456 +static void send_stop_cmd(struct mmc_host *mmc, struct mmc_data *data,
5459 + struct atmel_mci *host = mmc_priv(mmc);
5461 + atmci_start_command(host, data->stop, host->stop_cmdr | flags);
5462 + mci_writel(host, IER, MCI_BIT(CMDRDY));
5465 +static void atmci_data_complete(struct atmel_mci *host, struct mmc_data *data)
5467 + host->data = NULL;
5468 + dma_unmap_sg(&host->pdev->dev, data->sg, host->dma.req.nr_sg,
5469 + ((data->flags & MMC_DATA_WRITE)
5470 + ? DMA_TO_DEVICE : DMA_FROM_DEVICE));
5473 + * Data might complete before command for very short transfers
5476 + if (mci_cmd_is_complete(host)
5477 + && (!data->stop || mci_stop_is_complete(host)))
5478 + atmci_request_end(host->mmc, data->mrq);
5481 +static void atmci_command_complete(struct atmel_mci *host,
5482 + struct mmc_command *cmd, u32 status)
5484 + if (status & MCI_BIT(RTOE))
5485 + cmd->error = MMC_ERR_TIMEOUT;
5486 + else if ((cmd->flags & MMC_RSP_CRC)
5487 + && (status & MCI_BIT(RCRCE)))
5488 + cmd->error = MMC_ERR_BADCRC;
5489 + else if (status & (MCI_BIT(RINDE) | MCI_BIT(RDIRE) | MCI_BIT(RENDE)))
5490 + cmd->error = MMC_ERR_FAILED;
5492 + if (cmd->error != MMC_ERR_NONE) {
5493 + dev_dbg(&host->mmc->class_dev,
5494 + "command error: op=0x%x status=0x%08x\n",
5495 + cmd->opcode, status);
5498 + dma_stop_request(host->dma.req.req.dmac,
5499 + host->dma.req.req.channel);
5500 + mci_writel(host, IDR, MCI_BIT(NOTBUSY)
5501 + | MCI_DATA_ERROR_FLAGS);
5502 + host->data = NULL;
5507 +static void atmci_tasklet_func(unsigned long priv)
5509 + struct mmc_host *mmc = (struct mmc_host *)priv;
5510 + struct atmel_mci *host = mmc_priv(mmc);
5511 + struct mmc_request *mrq = host->mrq;
5512 + struct mmc_data *data = host->data;
5514 + dev_vdbg(&mmc->class_dev,
5515 + "tasklet: pending/completed/mask %lx/%lx/%x\n",
5516 + host->pending_events, host->completed_events,
5517 + mci_readl(host, IMR));
5519 + if (mci_clear_cmd_is_pending(host)) {
5520 + mci_set_cmd_complete(host);
5521 + atmci_command_complete(host, mrq->cmd, host->cmd_status);
5522 + if (!host->data || mci_data_is_complete(host)
5523 + || mci_data_error_is_complete(host))
5524 + atmci_request_end(mmc, mrq);
5526 + if (mci_clear_stop_is_pending(host)) {
5527 + mci_set_stop_complete(host);
5528 + atmci_command_complete(host, mrq->stop, host->stop_status);
5529 + if (mci_data_is_complete(host)
5530 + || mci_data_error_is_complete(host))
5531 + atmci_request_end(mmc, mrq);
5533 + if (mci_clear_dma_error_is_pending(host)) {
5534 + mci_set_dma_error_complete(host);
5535 + mci_clear_data_pending(host);
5537 + /* DMA controller got bus error => invalid address */
5538 + data->error = MMC_ERR_INVALID;
5540 + dev_dbg(&mmc->class_dev, "dma error after %u bytes xfered\n",
5541 + host->data->bytes_xfered);
5544 + && !mci_set_stop_sent_is_completed(host))
5545 + /* TODO: Check if card is still present */
5546 + send_stop_cmd(host->mmc, data, 0);
5548 + atmci_data_complete(host, data);
5550 + if (mci_clear_data_error_is_pending(host)) {
5551 + u32 status = host->data_status;
5553 + mci_set_data_error_complete(host);
5554 + mci_clear_data_pending(host);
5556 + dma_stop_request(host->dma.req.req.dmac,
5557 + host->dma.req.req.channel);
5559 + if (status & MCI_BIT(DCRCE)) {
5560 + dev_dbg(&mmc->class_dev, "data CRC error\n");
5561 + data->error = MMC_ERR_BADCRC;
5562 + } else if (status & MCI_BIT(DTOE)) {
5563 + dev_dbg(&mmc->class_dev, "data timeout error\n");
5564 + data->error = MMC_ERR_TIMEOUT;
5566 + dev_dbg(&mmc->class_dev, "data FIFO error\n");
5567 + data->error = MMC_ERR_FIFO;
5569 + dev_dbg(&mmc->class_dev, "bytes xfered: %u\n",
5570 + data->bytes_xfered);
5573 + && !mci_set_stop_sent_is_completed(host))
5574 + /* TODO: Check if card is still present */
5575 + send_stop_cmd(host->mmc, data, 0);
5577 + atmci_data_complete(host, data);
5579 + if (mci_clear_data_is_pending(host)) {
5580 + mci_set_data_complete(host);
5581 + data->bytes_xfered = data->blocks * data->blksz;
5582 + atmci_data_complete(host, data);
5584 + if (mci_clear_card_detect_is_pending(host)) {
5585 + /* Reset controller if card is gone */
5586 + if (!host->present) {
5587 + mci_writel(host, CR, MCI_BIT(SWRST));
5588 + mci_writel(host, IDR, ~0UL);
5589 + mci_writel(host, CR, MCI_BIT(MCIEN));
5592 + /* Clean up queue if present */
5594 + if (!mci_cmd_is_complete(host))
5595 + mrq->cmd->error = MMC_ERR_TIMEOUT;
5596 + if (mrq->data && !mci_data_is_complete(host)
5597 + && !mci_data_error_is_complete(host)) {
5598 + dma_stop_request(host->dma.req.req.dmac,
5599 + host->dma.req.req.channel);
5600 + host->data->error = MMC_ERR_TIMEOUT;
5601 + atmci_data_complete(host, data);
5603 + if (mrq->stop && !mci_stop_is_complete(host))
5604 + mrq->stop->error = MMC_ERR_TIMEOUT;
5607 + atmci_request_end(mmc, mrq);
5609 + mmc_detect_change(host->mmc, msecs_to_jiffies(100));
5613 +static void atmci_cmd_interrupt(struct mmc_host *mmc, u32 status)
5615 + struct atmel_mci *host = mmc_priv(mmc);
5616 + struct mmc_command *cmd = host->cmd;
5619 + * Read the response now so that we're free to send a new
5620 + * command immediately.
5622 + cmd->resp[0] = mci_readl(host, RSPR);
5623 + cmd->resp[1] = mci_readl(host, RSPR);
5624 + cmd->resp[2] = mci_readl(host, RSPR);
5625 + cmd->resp[3] = mci_readl(host, RSPR);
5627 + mci_writel(host, IDR, MCI_BIT(CMDRDY));
5630 + if (mci_stop_sent_is_complete(host)) {
5631 + host->stop_status = status;
5632 + mci_set_stop_pending(host);
5634 + host->cmd_status = status;
5635 + mci_set_cmd_pending(host);
5638 + tasklet_schedule(&host->tasklet);
5641 +static void atmci_xfer_complete(struct dma_request *_req)
5643 + struct dma_request_sg *req = to_dma_request_sg(_req);
5644 + struct atmel_mci_dma *dma;
5645 + struct atmel_mci *host;
5646 + struct mmc_data *data;
5648 + dma = container_of(req, struct atmel_mci_dma, req);
5649 + host = container_of(dma, struct atmel_mci, dma);
5650 + data = host->data;
5652 + if (data->stop && !mci_set_stop_sent_is_completed(host))
5653 + send_stop_cmd(host->mmc, data, 0);
5656 + * Regardless of what the documentation says, we have to wait
5657 + * for NOTBUSY even after block read operations.
5659 + * When the DMA transfer is complete, the controller may still
5660 + * be reading the CRC from the card, i.e. the data transfer is
5661 + * still in progress and we haven't seen all the potential
5664 + mci_writel(host, IER, MCI_BIT(NOTBUSY));
5667 +static void atmci_dma_error(struct dma_request *_req)
5669 + struct dma_request_sg *req = to_dma_request_sg(_req);
5670 + struct atmel_mci_dma *dma;
5671 + struct atmel_mci *host;
5673 + dma = container_of(req, struct atmel_mci_dma, req);
5674 + host = container_of(dma, struct atmel_mci, dma);
5676 + mci_writel(host, IDR, (MCI_BIT(NOTBUSY)
5677 + | MCI_DATA_ERROR_FLAGS));
5679 + mci_set_dma_error_pending(host);
5680 + tasklet_schedule(&host->tasklet);
5683 +static irqreturn_t atmci_interrupt(int irq, void *dev_id)
5685 + struct mmc_host *mmc = dev_id;
5686 + struct atmel_mci *host = mmc_priv(mmc);
5687 + u32 status, mask, pending;
5689 + spin_lock(&mmc->lock);
5691 + status = mci_readl(host, SR);
5692 + mask = mci_readl(host, IMR);
5693 + pending = status & mask;
5696 + if (pending & MCI_DATA_ERROR_FLAGS) {
5697 + mci_writel(host, IDR, (MCI_BIT(NOTBUSY)
5698 + | MCI_DATA_ERROR_FLAGS));
5699 + host->data_status = status;
5700 + mci_set_data_error_pending(host);
5701 + tasklet_schedule(&host->tasklet);
5704 + if (pending & MCI_BIT(CMDRDY))
5705 + atmci_cmd_interrupt(mmc, status);
5706 + if (pending & MCI_BIT(NOTBUSY)) {
5707 + mci_writel(host, IDR, (MCI_BIT(NOTBUSY)
5708 + | MCI_DATA_ERROR_FLAGS));
5709 + mci_set_data_pending(host);
5710 + tasklet_schedule(&host->tasklet);
5713 + status = mci_readl(host, SR);
5714 + mask = mci_readl(host, IMR);
5715 + pending = status & mask;
5716 + } while (pending);
5718 + spin_unlock(&mmc->lock);
5720 + return IRQ_HANDLED;
5723 +static irqreturn_t atmci_detect_change(int irq, void *dev_id)
5725 + struct mmc_host *mmc = dev_id;
5726 + struct atmel_mci *host = mmc_priv(mmc);
5728 + int present = !gpio_get_value(irq_to_gpio(irq));
5730 + if (present != host->present) {
5731 + dev_dbg(&mmc->class_dev, "card %s\n",
5732 + present ? "inserted" : "removed");
5733 + host->present = present;
5734 + mci_set_card_detect_pending(host);
5735 + tasklet_schedule(&host->tasklet);
5737 + return IRQ_HANDLED;
5740 +static int __devinit atmci_probe(struct platform_device *pdev)
5742 + struct mci_platform_data *board;
5743 + struct atmel_mci *host;
5744 + struct mmc_host *mmc;
5745 + struct resource *regs;
5749 + regs = platform_get_resource(pdev, IORESOURCE_MEM, 0);
5752 + irq = platform_get_irq(pdev, 0);
5756 + board = pdev->dev.platform_data;
5758 + mmc = mmc_alloc_host(sizeof(struct atmel_mci), &pdev->dev);
5762 + host = mmc_priv(mmc);
5763 + host->pdev = pdev;
5766 + host->detect_pin = board->detect_pin;
5767 + host->wp_pin = board->wp_pin;
5769 + host->detect_pin = -1;
5770 + host->detect_pin = -1;
5773 + host->mck = clk_get(&pdev->dev, "mci_clk");
5774 + if (IS_ERR(host->mck)) {
5775 + ret = PTR_ERR(host->mck);
5776 + goto out_free_host;
5778 + clk_enable(host->mck);
5781 + host->regs = ioremap(regs->start, regs->end - regs->start + 1);
5783 + goto out_disable_clk;
5785 + host->bus_hz = clk_get_rate(host->mck);
5786 + host->mapbase = regs->start;
5788 + mmc->ops = &atmci_ops;
5789 + mmc->f_min = (host->bus_hz + 511) / 512;
5790 + mmc->f_max = min((unsigned int)(host->bus_hz / 2), fmax);
5791 + mmc->ocr_avail = MMC_VDD_32_33 | MMC_VDD_33_34;
5792 + mmc->caps |= MMC_CAP_4_BIT_DATA;
5794 + tasklet_init(&host->tasklet, atmci_tasklet_func, (unsigned long)mmc);
5796 + ret = request_irq(irq, atmci_interrupt, 0, "mmci", mmc);
5800 + /* Assume card is present if we don't have a detect pin */
5801 + host->present = 1;
5802 + if (host->detect_pin >= 0) {
5803 + if (gpio_request(host->detect_pin, "mmc_detect")) {
5804 + dev_dbg(&mmc->class_dev, "no detect pin available\n");
5805 + host->detect_pin = -1;
5807 + host->present = !gpio_get_value(host->detect_pin);
5810 + if (host->wp_pin >= 0) {
5811 + if (gpio_request(host->wp_pin, "mmc_wp")) {
5812 + dev_dbg(&mmc->class_dev, "no WP pin available\n");
5813 + host->wp_pin = -1;
5817 + /* TODO: Get this information from platform data */
5819 + host->dma.req.req.dmac = find_dma_controller(0);
5820 + if (!host->dma.req.req.dmac) {
5821 + dev_dbg(&mmc->class_dev, "no DMA controller available\n");
5822 + goto out_free_irq;
5824 + ret = dma_alloc_channel(host->dma.req.req.dmac);
5826 + dev_dbg(&mmc->class_dev, "unable to allocate DMA channel\n");
5827 + goto out_free_irq;
5829 + host->dma.req.req.channel = ret;
5830 + host->dma.req.width = DMA_WIDTH_32BIT;
5831 + host->dma.req.req.xfer_complete = atmci_xfer_complete;
5832 + host->dma.req.req.block_complete = NULL; // atmci_block_complete;
5833 + host->dma.req.req.error = atmci_dma_error;
5834 + host->dma.rx_periph_id = 0;
5835 + host->dma.tx_periph_id = 1;
5837 + mci_writel(host, CR, MCI_BIT(SWRST));
5838 + mci_writel(host, IDR, ~0UL);
5840 + platform_set_drvdata(pdev, host);
5842 + mmc_add_host(mmc);
5844 + if (host->detect_pin >= 0) {
5845 + ret = request_irq(gpio_to_irq(host->detect_pin),
5846 + atmci_detect_change,
5847 + IRQF_TRIGGER_FALLING | IRQF_TRIGGER_RISING,
5848 + DRIVER_NAME, mmc);
5850 + dev_dbg(&mmc->class_dev,
5851 + "could not request IRQ %d for detect pin\n",
5852 + gpio_to_irq(host->detect_pin));
5853 + gpio_free(host->detect_pin);
5854 + host->detect_pin = -1;
5858 + dev_info(&mmc->class_dev, "Atmel MCI controller at 0x%08lx irq %d\n",
5859 + host->mapbase, irq);
5861 + atmci_init_debugfs(host);
5866 + if (host->detect_pin >= 0)
5867 + gpio_free(host->detect_pin);
5868 + if (host->wp_pin >= 0)
5869 + gpio_free(host->wp_pin);
5870 + free_irq(irq, mmc);
5872 + iounmap(host->regs);
5874 + clk_disable(host->mck);
5875 + clk_put(host->mck);
5877 + mmc_free_host(mmc);
5881 +static int __devexit atmci_remove(struct platform_device *pdev)
5883 + struct atmel_mci *host = platform_get_drvdata(pdev);
5885 + platform_set_drvdata(pdev, NULL);
5888 + atmci_cleanup_debugfs(host);
5890 + if (host->detect_pin >= 0) {
5891 + free_irq(gpio_to_irq(host->detect_pin), host->mmc);
5892 + cancel_delayed_work(&host->mmc->detect);
5893 + gpio_free(host->detect_pin);
5896 + mmc_remove_host(host->mmc);
5898 + mci_writel(host, IDR, ~0UL);
5899 + mci_writel(host, CR, MCI_BIT(MCIDIS));
5900 + mci_readl(host, SR);
5902 + dma_release_channel(host->dma.req.req.dmac,
5903 + host->dma.req.req.channel);
5905 + if (host->wp_pin >= 0)
5906 + gpio_free(host->wp_pin);
5908 + free_irq(platform_get_irq(pdev, 0), host->mmc);
5909 + iounmap(host->regs);
5911 + clk_disable(host->mck);
5912 + clk_put(host->mck);
5914 + mmc_free_host(host->mmc);
5919 +static struct platform_driver atmci_driver = {
5920 + .probe = atmci_probe,
5921 + .remove = __devexit_p(atmci_remove),
5923 + .name = DRIVER_NAME,
5927 +static int __init atmci_init(void)
5929 + return platform_driver_register(&atmci_driver);
5932 +static void __exit atmci_exit(void)
5934 + platform_driver_unregister(&atmci_driver);
5937 +module_init(atmci_init);
5938 +module_exit(atmci_exit);
5940 +MODULE_DESCRIPTION("Atmel Multimedia Card Interface driver");
5941 +MODULE_LICENSE("GPL");
5942 diff --git a/drivers/mmc/host/atmel-mci.h b/drivers/mmc/host/atmel-mci.h
5943 new file mode 100644
5944 index 0000000..60d15c4
5946 +++ b/drivers/mmc/host/atmel-mci.h
5949 + * Atmel MultiMedia Card Interface driver
5951 + * Copyright (C) 2004-2006 Atmel Corporation
5953 + * This program is free software; you can redistribute it and/or modify
5954 + * it under the terms of the GNU General Public License version 2 as
5955 + * published by the Free Software Foundation.
5957 +#ifndef __DRIVERS_MMC_ATMEL_MCI_H__
5958 +#define __DRIVERS_MMC_ATMEL_MCI_H__
5960 +/* MCI register offsets */
5961 +#define MCI_CR 0x0000
5962 +#define MCI_MR 0x0004
5963 +#define MCI_DTOR 0x0008
5964 +#define MCI_SDCR 0x000c
5965 +#define MCI_ARGR 0x0010
5966 +#define MCI_CMDR 0x0014
5967 +#define MCI_BLKR 0x0018
5968 +#define MCI_RSPR 0x0020
5969 +#define MCI_RSPR1 0x0024
5970 +#define MCI_RSPR2 0x0028
5971 +#define MCI_RSPR3 0x002c
5972 +#define MCI_RDR 0x0030
5973 +#define MCI_TDR 0x0034
5974 +#define MCI_SR 0x0040
5975 +#define MCI_IER 0x0044
5976 +#define MCI_IDR 0x0048
5977 +#define MCI_IMR 0x004c
5979 +/* Bitfields in CR */
5980 +#define MCI_MCIEN_OFFSET 0
5981 +#define MCI_MCIEN_SIZE 1
5982 +#define MCI_MCIDIS_OFFSET 1
5983 +#define MCI_MCIDIS_SIZE 1
5984 +#define MCI_PWSEN_OFFSET 2
5985 +#define MCI_PWSEN_SIZE 1
5986 +#define MCI_PWSDIS_OFFSET 3
5987 +#define MCI_PWSDIS_SIZE 1
5988 +#define MCI_SWRST_OFFSET 7
5989 +#define MCI_SWRST_SIZE 1
5991 +/* Bitfields in MR */
5992 +#define MCI_CLKDIV_OFFSET 0
5993 +#define MCI_CLKDIV_SIZE 8
5994 +#define MCI_PWSDIV_OFFSET 8
5995 +#define MCI_PWSDIV_SIZE 3
5996 +#define MCI_RDPROOF_OFFSET 11
5997 +#define MCI_RDPROOF_SIZE 1
5998 +#define MCI_WRPROOF_OFFSET 12
5999 +#define MCI_WRPROOF_SIZE 1
6000 +#define MCI_DMAPADV_OFFSET 14
6001 +#define MCI_DMAPADV_SIZE 1
6002 +#define MCI_BLKLEN_OFFSET 16
6003 +#define MCI_BLKLEN_SIZE 16
6005 +/* Bitfields in DTOR */
6006 +#define MCI_DTOCYC_OFFSET 0
6007 +#define MCI_DTOCYC_SIZE 4
6008 +#define MCI_DTOMUL_OFFSET 4
6009 +#define MCI_DTOMUL_SIZE 3
6011 +/* Bitfields in SDCR */
6012 +#define MCI_SDCSEL_OFFSET 0
6013 +#define MCI_SDCSEL_SIZE 4
6014 +#define MCI_SDCBUS_OFFSET 7
6015 +#define MCI_SDCBUS_SIZE 1
6017 +/* Bitfields in ARGR */
6018 +#define MCI_ARG_OFFSET 0
6019 +#define MCI_ARG_SIZE 32
6021 +/* Bitfields in CMDR */
6022 +#define MCI_CMDNB_OFFSET 0
6023 +#define MCI_CMDNB_SIZE 6
6024 +#define MCI_RSPTYP_OFFSET 6
6025 +#define MCI_RSPTYP_SIZE 2
6026 +#define MCI_SPCMD_OFFSET 8
6027 +#define MCI_SPCMD_SIZE 3
6028 +#define MCI_OPDCMD_OFFSET 11
6029 +#define MCI_OPDCMD_SIZE 1
6030 +#define MCI_MAXLAT_OFFSET 12
6031 +#define MCI_MAXLAT_SIZE 1
6032 +#define MCI_TRCMD_OFFSET 16
6033 +#define MCI_TRCMD_SIZE 2
6034 +#define MCI_TRDIR_OFFSET 18
6035 +#define MCI_TRDIR_SIZE 1
6036 +#define MCI_TRTYP_OFFSET 19
6037 +#define MCI_TRTYP_SIZE 2
6039 +/* Bitfields in BLKR */
6040 +#define MCI_BCNT_OFFSET 0
6041 +#define MCI_BCNT_SIZE 16
6043 +/* Bitfields in RSPRn */
6044 +#define MCI_RSP_OFFSET 0
6045 +#define MCI_RSP_SIZE 32
6047 +/* Bitfields in SR/IER/IDR/IMR */
6048 +#define MCI_CMDRDY_OFFSET 0
6049 +#define MCI_CMDRDY_SIZE 1
6050 +#define MCI_RXRDY_OFFSET 1
6051 +#define MCI_RXRDY_SIZE 1
6052 +#define MCI_TXRDY_OFFSET 2
6053 +#define MCI_TXRDY_SIZE 1
6054 +#define MCI_BLKE_OFFSET 3
6055 +#define MCI_BLKE_SIZE 1
6056 +#define MCI_DTIP_OFFSET 4
6057 +#define MCI_DTIP_SIZE 1
6058 +#define MCI_NOTBUSY_OFFSET 5
6059 +#define MCI_NOTBUSY_SIZE 1
6060 +#define MCI_ENDRX_OFFSET 6
6061 +#define MCI_ENDRX_SIZE 1
6062 +#define MCI_ENDTX_OFFSET 7
6063 +#define MCI_ENDTX_SIZE 1
6064 +#define MCI_RXBUFF_OFFSET 14
6065 +#define MCI_RXBUFF_SIZE 1
6066 +#define MCI_TXBUFE_OFFSET 15
6067 +#define MCI_TXBUFE_SIZE 1
6068 +#define MCI_RINDE_OFFSET 16
6069 +#define MCI_RINDE_SIZE 1
6070 +#define MCI_RDIRE_OFFSET 17
6071 +#define MCI_RDIRE_SIZE 1
6072 +#define MCI_RCRCE_OFFSET 18
6073 +#define MCI_RCRCE_SIZE 1
6074 +#define MCI_RENDE_OFFSET 19
6075 +#define MCI_RENDE_SIZE 1
6076 +#define MCI_RTOE_OFFSET 20
6077 +#define MCI_RTOE_SIZE 1
6078 +#define MCI_DCRCE_OFFSET 21
6079 +#define MCI_DCRCE_SIZE 1
6080 +#define MCI_DTOE_OFFSET 22
6081 +#define MCI_DTOE_SIZE 1
6082 +#define MCI_OVRE_OFFSET 30
6083 +#define MCI_OVRE_SIZE 1
6084 +#define MCI_UNRE_OFFSET 31
6085 +#define MCI_UNRE_SIZE 1
6087 +/* Constants for DTOMUL */
6088 +#define MCI_DTOMUL_1_CYCLE 0
6089 +#define MCI_DTOMUL_16_CYCLES 1
6090 +#define MCI_DTOMUL_128_CYCLES 2
6091 +#define MCI_DTOMUL_256_CYCLES 3
6092 +#define MCI_DTOMUL_1024_CYCLES 4
6093 +#define MCI_DTOMUL_4096_CYCLES 5
6094 +#define MCI_DTOMUL_65536_CYCLES 6
6095 +#define MCI_DTOMUL_1048576_CYCLES 7
6097 +/* Constants for RSPTYP */
6098 +#define MCI_RSPTYP_NO_RESP 0
6099 +#define MCI_RSPTYP_48_BIT 1
6100 +#define MCI_RSPTYP_136_BIT 2
6102 +/* Constants for SPCMD */
6103 +#define MCI_SPCMD_NO_SPEC_CMD 0
6104 +#define MCI_SPCMD_INIT_CMD 1
6105 +#define MCI_SPCMD_SYNC_CMD 2
6106 +#define MCI_SPCMD_INT_CMD 4
6107 +#define MCI_SPCMD_INT_RESP 5
6109 +/* Constants for TRCMD */
6110 +#define MCI_TRCMD_NO_TRANS 0
6111 +#define MCI_TRCMD_START_TRANS 1
6112 +#define MCI_TRCMD_STOP_TRANS 2
6114 +/* Constants for TRTYP */
6115 +#define MCI_TRTYP_BLOCK 0
6116 +#define MCI_TRTYP_MULTI_BLOCK 1
6117 +#define MCI_TRTYP_STREAM 2
6119 +/* Bit manipulation macros */
6120 +#define MCI_BIT(name) \
6121 + (1 << MCI_##name##_OFFSET)
6122 +#define MCI_BF(name,value) \
6123 + (((value) & ((1 << MCI_##name##_SIZE) - 1)) \
6124 + << MCI_##name##_OFFSET)
6125 +#define MCI_BFEXT(name,value) \
6126 + (((value) >> MCI_##name##_OFFSET) \
6127 + & ((1 << MCI_##name##_SIZE) - 1))
6128 +#define MCI_BFINS(name,value,old) \
6129 + (((old) & ~(((1 << MCI_##name##_SIZE) - 1) \
6130 + << MCI_##name##_OFFSET)) \
6131 + | MCI_BF(name,value))
6133 +/* Register access macros */
6134 +#define mci_readl(port,reg) \
6135 + __raw_readl((port)->regs + MCI_##reg)
6136 +#define mci_writel(port,reg,value) \
6137 + __raw_writel((value), (port)->regs + MCI_##reg)
6139 +#endif /* __DRIVERS_MMC_ATMEL_MCI_H__ */
6140 diff --git a/drivers/mtd/chips/cfi_cmdset_0001.c b/drivers/mtd/chips/cfi_cmdset_0001.c
6141 index 2f19fa7..94304ca 100644
6142 --- a/drivers/mtd/chips/cfi_cmdset_0001.c
6143 +++ b/drivers/mtd/chips/cfi_cmdset_0001.c
6145 #define I82802AC 0x00ac
6146 #define MANUFACTURER_ST 0x0020
6147 #define M50LPW080 0x002F
6148 +#define AT49BV640D 0x02de
6150 static int cfi_intelext_read (struct mtd_info *, loff_t, size_t, size_t *, u_char *);
6151 static int cfi_intelext_write_words(struct mtd_info *, loff_t, size_t, size_t *, const u_char *);
6152 @@ -156,6 +157,47 @@ static void cfi_tell_features(struct cfi_pri_intelext *extp)
6156 +/* Atmel chips don't use the same PRI format as Intel chips */
6157 +static void fixup_convert_atmel_pri(struct mtd_info *mtd, void *param)
6159 + struct map_info *map = mtd->priv;
6160 + struct cfi_private *cfi = map->fldrv_priv;
6161 + struct cfi_pri_intelext *extp = cfi->cmdset_priv;
6162 + struct cfi_pri_atmel atmel_pri;
6163 + uint32_t features = 0;
6165 + /* Reverse byteswapping */
6166 + extp->FeatureSupport = cpu_to_le32(extp->FeatureSupport);
6167 + extp->BlkStatusRegMask = cpu_to_le16(extp->BlkStatusRegMask);
6168 + extp->ProtRegAddr = cpu_to_le16(extp->ProtRegAddr);
6170 + memcpy(&atmel_pri, extp, sizeof(atmel_pri));
6171 + memset((char *)extp + 5, 0, sizeof(*extp) - 5);
6173 + printk(KERN_ERR "atmel Features: %02x\n", atmel_pri.Features);
6175 + if (atmel_pri.Features & 0x01) /* chip erase supported */
6176 + features |= (1<<0);
6177 + if (atmel_pri.Features & 0x02) /* erase suspend supported */
6178 + features |= (1<<1);
6179 + if (atmel_pri.Features & 0x04) /* program suspend supported */
6180 + features |= (1<<2);
6181 + if (atmel_pri.Features & 0x08) /* simultaneous operations supported */
6182 + features |= (1<<9);
6183 + if (atmel_pri.Features & 0x20) /* page mode read supported */
6184 + features |= (1<<7);
6185 + if (atmel_pri.Features & 0x40) /* queued erase supported */
6186 + features |= (1<<4);
6187 + if (atmel_pri.Features & 0x80) /* Protection bits supported */
6188 + features |= (1<<6);
6190 + extp->FeatureSupport = features;
6192 + /* burst write mode not supported */
6193 + cfi->cfiq->BufWriteTimeoutTyp = 0;
6194 + cfi->cfiq->BufWriteTimeoutMax = 0;
6197 #ifdef CMDSET0001_DISABLE_ERASE_SUSPEND_ON_WRITE
6198 /* Some Intel Strata Flash prior to FPO revision C has bugs in this area */
6199 static void fixup_intel_strataflash(struct mtd_info *mtd, void* param)
6200 @@ -233,6 +275,7 @@ static void fixup_use_powerup_lock(struct mtd_info *mtd, void *param)
6203 static struct cfi_fixup cfi_fixup_table[] = {
6204 + { CFI_MFR_ATMEL, CFI_ID_ANY, fixup_convert_atmel_pri, NULL },
6205 #ifdef CMDSET0001_DISABLE_ERASE_SUSPEND_ON_WRITE
6206 { CFI_MFR_ANY, CFI_ID_ANY, fixup_intel_strataflash, NULL },
6208 diff --git a/drivers/mtd/chips/cfi_cmdset_0002.c b/drivers/mtd/chips/cfi_cmdset_0002.c
6209 index 1f64458..205977b 100644
6210 --- a/drivers/mtd/chips/cfi_cmdset_0002.c
6211 +++ b/drivers/mtd/chips/cfi_cmdset_0002.c
6212 @@ -185,6 +185,10 @@ static void fixup_convert_atmel_pri(struct mtd_info *mtd, void *param)
6213 extp->TopBottom = 2;
6215 extp->TopBottom = 3;
6217 + /* burst write mode not supported */
6218 + cfi->cfiq->BufWriteTimeoutTyp = 0;
6219 + cfi->cfiq->BufWriteTimeoutMax = 0;
6222 static void fixup_use_secsi(struct mtd_info *mtd, void *param)
6223 @@ -217,6 +221,7 @@ static void fixup_use_atmel_lock(struct mtd_info *mtd, void *param)
6226 static struct cfi_fixup cfi_fixup_table[] = {
6227 + { CFI_MFR_ATMEL, CFI_ID_ANY, fixup_convert_atmel_pri, NULL },
6228 #ifdef AMD_BOOTLOC_BUG
6229 { CFI_MFR_AMD, CFI_ID_ANY, fixup_amd_bootblock, NULL },
6231 @@ -229,7 +234,6 @@ static struct cfi_fixup cfi_fixup_table[] = {
6232 #if !FORCE_WORD_WRITE
6233 { CFI_MFR_ANY, CFI_ID_ANY, fixup_use_write_buffers, NULL, },
6235 - { CFI_MFR_ATMEL, CFI_ID_ANY, fixup_convert_atmel_pri, NULL },
6236 { 0, 0, NULL, NULL }
6238 static struct cfi_fixup jedec_fixup_table[] = {
6239 diff --git a/drivers/spi/atmel_spi.c b/drivers/spi/atmel_spi.c
6240 index b046974..bc90604 100644
6241 --- a/drivers/spi/atmel_spi.c
6242 +++ b/drivers/spi/atmel_spi.c
6243 @@ -491,8 +491,8 @@ static int atmel_spi_setup(struct spi_device *spi)
6244 csr |= SPI_BIT(NCPHA);
6246 /* TODO: DLYBS and DLYBCT */
6247 - csr |= SPI_BF(DLYBS, 10);
6248 - csr |= SPI_BF(DLYBCT, 10);
6249 + csr |= SPI_BF(DLYBS, 0);
6250 + csr |= SPI_BF(DLYBCT, 0);
6252 /* chipselect must have been muxed as GPIO (e.g. in board setup) */
6253 npcs_pin = (unsigned int)spi->controller_data;
6254 diff --git a/drivers/usb/gadget/Kconfig b/drivers/usb/gadget/Kconfig
6255 index 767aed5..f81d08d 100644
6256 --- a/drivers/usb/gadget/Kconfig
6257 +++ b/drivers/usb/gadget/Kconfig
6258 @@ -67,6 +67,17 @@ config USB_GADGET_DEBUG_FILES
6259 driver on a new board. Enable these files by choosing "Y"
6260 here. If in doubt, or to conserve kernel memory, say "N".
6262 +config USB_GADGET_DEBUG_FS
6263 + boolean "Debugging information files in debugfs"
6264 + depends on USB_GADGET && DEBUG_FS
6266 + Some of the drivers in the "gadget" framework can expose
6267 + debugging information in files under /sys/kernel/debug/.
6268 + The information in these files may help when you're
6269 + troubleshooting or bringing up a driver on a new board.
6270 + Enable these files by choosing "Y" here. If in doubt, or
6271 + to conserve kernel memory, say "N".
6273 config USB_GADGET_SELECTED
6276 @@ -103,6 +114,20 @@ config USB_AMD5536UDC
6278 select USB_GADGET_SELECTED
6280 +config USB_GADGET_ATMEL_USBA
6281 + boolean "Atmel USBA"
6282 + select USB_GADGET_DUALSPEED
6285 + USBA is the integrated high-speed USB Device controller on
6286 + the AT32AP700x processors from Atmel.
6288 +config USB_ATMEL_USBA
6290 + depends on USB_GADGET_ATMEL_USBA
6291 + default USB_GADGET
6292 + select USB_GADGET_SELECTED
6294 config USB_GADGET_FSL_USB2
6295 boolean "Freescale Highspeed USB DR Peripheral Controller"
6296 depends on MPC834x || PPC_MPC831x
6297 @@ -228,7 +253,6 @@ config USB_LH7A40X
6299 select USB_GADGET_SELECTED
6302 config USB_GADGET_OMAP
6303 boolean "OMAP USB Device Controller"
6304 depends on ARCH_OMAP
6305 diff --git a/drivers/usb/gadget/Makefile b/drivers/usb/gadget/Makefile
6306 index 1bc0f03..904e57b 100644
6307 --- a/drivers/usb/gadget/Makefile
6308 +++ b/drivers/usb/gadget/Makefile
6309 @@ -14,6 +14,7 @@ obj-$(CONFIG_USB_OMAP) += omap_udc.o
6310 obj-$(CONFIG_USB_LH7A40X) += lh7a40x_udc.o
6311 obj-$(CONFIG_USB_S3C2410) += s3c2410_udc.o
6312 obj-$(CONFIG_USB_AT91) += at91_udc.o
6313 +obj-$(CONFIG_USB_ATMEL_USBA) += atmel_usba_udc.o
6314 obj-$(CONFIG_USB_FSL_USB2) += fsl_usb2_udc.o
6315 obj-$(CONFIG_USB_M66592) += m66592-udc.o
6317 diff --git a/drivers/usb/gadget/atmel_usba_udc.c b/drivers/usb/gadget/atmel_usba_udc.c
6318 new file mode 100644
6319 index 0000000..e35362d
6321 +++ b/drivers/usb/gadget/atmel_usba_udc.c
6324 + * Driver for the Atmel USBA high speed USB device controller
6326 + * Copyright (C) 2005-2007 Atmel Corporation
6328 + * This program is free software; you can redistribute it and/or modify
6329 + * it under the terms of the GNU General Public License version 2 as
6330 + * published by the Free Software Foundation.
6332 +#include <linux/clk.h>
6333 +#include <linux/module.h>
6334 +#include <linux/init.h>
6335 +#include <linux/interrupt.h>
6336 +#include <linux/io.h>
6337 +#include <linux/device.h>
6338 +#include <linux/dma-mapping.h>
6339 +#include <linux/list.h>
6340 +#include <linux/platform_device.h>
6341 +#include <linux/usb/ch9.h>
6342 +#include <linux/usb_gadget.h>
6343 +#include <linux/delay.h>
6345 +#include <asm/gpio.h>
6346 +#include <asm/arch/board.h>
6348 +#include "atmel_usba_udc.h"
6351 +static struct usba_udc the_udc;
6353 +#ifdef CONFIG_USB_GADGET_DEBUG_FS
6354 +#include <linux/debugfs.h>
6355 +#include <linux/uaccess.h>
6357 +static int queue_dbg_open(struct inode *inode, struct file *file)
6359 + struct usba_ep *ep = inode->i_private;
6360 + struct usba_request *req, *req_copy;
6361 + struct list_head *queue_data;
6363 + queue_data = kmalloc(sizeof(*queue_data), GFP_KERNEL);
6366 + INIT_LIST_HEAD(queue_data);
6368 + spin_lock_irq(&ep->udc->lock);
6369 + list_for_each_entry(req, &ep->queue, queue) {
6370 + req_copy = kmalloc(sizeof(*req_copy), GFP_ATOMIC);
6373 + memcpy(req_copy, req, sizeof(*req_copy));
6374 + list_add_tail(&req_copy->queue, queue_data);
6376 + spin_unlock_irq(&ep->udc->lock);
6378 + file->private_data = queue_data;
6382 + spin_unlock_irq(&ep->udc->lock);
6383 + list_for_each_entry_safe(req, req_copy, queue_data, queue) {
6384 + list_del(&req->queue);
6387 + kfree(queue_data);
6392 + * bbbbbbbb llllllll IZS sssss nnnn FDL\n\0
6394 + * b: buffer address
6395 + * l: buffer length
6396 + * I/i: interrupt/no interrupt
6397 + * Z/z: zero/no zero
6398 + * S/s: short ok/short not ok
6401 + * F/f: submitted/not submitted to FIFO
6402 + * D/d: using/not using DMA
6403 + * L/l: last transaction/not last transaction
6405 +static ssize_t queue_dbg_read(struct file *file, char __user *buf,
6406 + size_t nbytes, loff_t *ppos)
6408 + struct list_head *queue = file->private_data;
6409 + struct usba_request *req, *tmp_req;
6410 + size_t len, remaining, actual = 0;
6413 + if (!access_ok(VERIFY_WRITE, buf, nbytes))
6416 + mutex_lock(&file->f_dentry->d_inode->i_mutex);
6417 + list_for_each_entry_safe(req, tmp_req, queue, queue) {
6418 + len = snprintf(tmpbuf, sizeof(tmpbuf),
6419 + "%8p %08x %c%c%c %5d %c%c%c\n",
6420 + req->req.buf, req->req.length,
6421 + req->req.no_interrupt ? 'i' : 'I',
6422 + req->req.zero ? 'Z' : 'z',
6423 + req->req.short_not_ok ? 's' : 'S',
6425 + req->submitted ? 'F' : 'f',
6426 + req->using_dma ? 'D' : 'd',
6427 + req->last_transaction ? 'L' : 'l');
6428 + len = min(len, sizeof(tmpbuf));
6432 + list_del(&req->queue);
6435 + remaining = __copy_to_user(buf, tmpbuf, len);
6436 + actual += len - remaining;
6443 + mutex_unlock(&file->f_dentry->d_inode->i_mutex);
6448 +static int queue_dbg_release(struct inode *inode, struct file *file)
6450 + struct list_head *queue_data = file->private_data;
6451 + struct usba_request *req, *tmp_req;
6453 + list_for_each_entry_safe(req, tmp_req, queue_data, queue) {
6454 + list_del(&req->queue);
6457 + kfree(queue_data);
6461 +static int regs_dbg_open(struct inode *inode, struct file *file)
6463 + struct usba_udc *udc;
6466 + int ret = -ENOMEM;
6468 + mutex_lock(&inode->i_mutex);
6469 + udc = inode->i_private;
6470 + data = kmalloc(inode->i_size, GFP_KERNEL);
6474 + spin_lock_irq(&udc->lock);
6475 + for (i = 0; i < inode->i_size / 4; i++)
6476 + data[i] = __raw_readl(udc->regs + i * 4);
6477 + spin_unlock_irq(&udc->lock);
6479 + file->private_data = data;
6483 + mutex_unlock(&inode->i_mutex);
6488 +static ssize_t regs_dbg_read(struct file *file, char __user *buf,
6489 + size_t nbytes, loff_t *ppos)
6491 + struct inode *inode = file->f_dentry->d_inode;
6494 + mutex_lock(&inode->i_mutex);
6495 + ret = simple_read_from_buffer(buf, nbytes, ppos,
6496 + file->private_data,
6497 + file->f_dentry->d_inode->i_size);
6498 + mutex_unlock(&inode->i_mutex);
6503 +static int regs_dbg_release(struct inode *inode, struct file *file)
6505 + kfree(file->private_data);
6509 +const struct file_operations queue_dbg_fops = {
6510 + .owner = THIS_MODULE,
6511 + .open = queue_dbg_open,
6512 + .llseek = no_llseek,
6513 + .read = queue_dbg_read,
6514 + .release = queue_dbg_release,
6517 +const struct file_operations regs_dbg_fops = {
6518 + .owner = THIS_MODULE,
6519 + .open = regs_dbg_open,
6520 + .llseek = generic_file_llseek,
6521 + .read = regs_dbg_read,
6522 + .release = regs_dbg_release,
6525 +static void usba_ep_init_debugfs(struct usba_udc *udc,
6526 + struct usba_ep *ep)
6528 + struct dentry *ep_root;
6530 + ep_root = debugfs_create_dir(ep->ep.name, udc->debugfs_root);
6533 + ep->debugfs_dir = ep_root;
6535 + ep->debugfs_queue = debugfs_create_file("queue", 0400, ep_root,
6536 + ep, &queue_dbg_fops);
6537 + if (!ep->debugfs_queue)
6540 + if (ep->can_dma) {
6541 + ep->debugfs_dma_status
6542 + = debugfs_create_u32("dma_status", 0400, ep_root,
6543 + &ep->last_dma_status);
6544 + if (!ep->debugfs_dma_status)
6545 + goto err_dma_status;
6547 + if (ep_is_control(ep)) {
6549 + = debugfs_create_u32("state", 0400, ep_root,
6551 + if (!ep->debugfs_state)
6559 + debugfs_remove(ep->debugfs_dma_status);
6561 + debugfs_remove(ep->debugfs_queue);
6563 + debugfs_remove(ep_root);
6565 + dev_err(&ep->udc->pdev->dev,
6566 + "failed to create debugfs directory for %s\n", ep->ep.name);
6569 +static void usba_ep_cleanup_debugfs(struct usba_ep *ep)
6571 + debugfs_remove(ep->debugfs_queue);
6572 + debugfs_remove(ep->debugfs_dma_status);
6573 + debugfs_remove(ep->debugfs_state);
6574 + debugfs_remove(ep->debugfs_dir);
6575 + ep->debugfs_dma_status = NULL;
6576 + ep->debugfs_dir = NULL;
6579 +static void usba_init_debugfs(struct usba_udc *udc)
6581 + struct dentry *root, *regs;
6582 + struct resource *regs_resource;
6584 + root = debugfs_create_dir(udc->gadget.name, NULL);
6585 + if (IS_ERR(root) || !root)
6587 + udc->debugfs_root = root;
6589 + regs = debugfs_create_file("regs", 0400, root, udc, ®s_dbg_fops);
6593 + regs_resource = platform_get_resource(udc->pdev, IORESOURCE_MEM,
6595 + regs->d_inode->i_size = regs_resource->end - regs_resource->start + 1;
6596 + udc->debugfs_regs = regs;
6598 + usba_ep_init_debugfs(udc, to_usba_ep(udc->gadget.ep0));
6603 + debugfs_remove(root);
6605 + udc->debugfs_root = NULL;
6606 + dev_err(&udc->pdev->dev, "debugfs is not available\n");
6609 +static void usba_cleanup_debugfs(struct usba_udc *udc)
6611 + usba_ep_cleanup_debugfs(to_usba_ep(udc->gadget.ep0));
6612 + debugfs_remove(udc->debugfs_regs);
6613 + debugfs_remove(udc->debugfs_root);
6614 + udc->debugfs_regs = NULL;
6615 + udc->debugfs_root = NULL;
6618 +static inline void usba_ep_init_debugfs(struct usba_udc *udc,
6619 + struct usba_ep *ep)
6624 +static inline void usba_ep_cleanup_debugfs(struct usba_ep *ep)
6629 +static inline void usba_init_debugfs(struct usba_udc *udc)
6634 +static inline void usba_cleanup_debugfs(struct usba_udc *udc)
6640 +static int vbus_is_present(struct usba_udc *udc)
6642 + if (udc->vbus_pin != -1)
6643 + return gpio_get_value(udc->vbus_pin);
6645 + /* No Vbus detection: Assume always present */
6649 +static void copy_to_fifo(void __iomem *fifo, const void *buf, int len)
6651 + unsigned long tmp;
6653 + DBG(DBG_FIFO, "copy to FIFO (len %d):\n", len);
6654 + for (; len > 0; len -= 4, buf += 4, fifo += 4) {
6655 + tmp = *(unsigned long *)buf;
6657 + DBG(DBG_FIFO, " -> %08lx\n", tmp);
6658 + __raw_writel(tmp, fifo);
6661 + DBG(DBG_FIFO, " -> %02lx\n", tmp >> 24);
6662 + __raw_writeb(tmp >> 24, fifo);
6671 +static void copy_from_fifo(void *buf, void __iomem *fifo, int len)
6677 + unsigned long tmp;
6679 + DBG(DBG_FIFO, "copy from FIFO (len %d):\n", len);
6680 + for (p.w = buf; len > 0; len -= 4, p.w++, fifo += 4) {
6682 + tmp = __raw_readl(fifo);
6684 + DBG(DBG_FIFO, " -> %08lx\n", tmp);
6687 + tmp = __raw_readb(fifo);
6689 + DBG(DBG_FIFO, " -> %02lx\n", tmp);
6696 +static void next_fifo_transaction(struct usba_ep *ep, struct usba_request *req)
6698 + unsigned int transaction_len;
6700 + transaction_len = req->req.length - req->req.actual;
6701 + req->last_transaction = 1;
6702 + if (transaction_len > ep->ep.maxpacket) {
6703 + transaction_len = ep->ep.maxpacket;
6704 + req->last_transaction = 0;
6705 + } else if (transaction_len == ep->ep.maxpacket && req->req.zero)
6706 + req->last_transaction = 0;
6708 + DBG(DBG_QUEUE, "%s: submit_transaction, req %p (length %d)%s\n",
6709 + ep->ep.name, req, transaction_len,
6710 + req->last_transaction ? ", done" : "");
6712 + copy_to_fifo(ep->fifo, req->req.buf + req->req.actual, transaction_len);
6713 + usba_ep_writel(ep, SET_STA, USBA_TX_PK_RDY);
6714 + req->req.actual += transaction_len;
6717 +static void submit_request(struct usba_ep *ep, struct usba_request *req)
6719 + DBG(DBG_QUEUE, "%s: submit_request: req %p (length %d)\n",
6720 + ep->ep.name, req, req->req.length);
6722 + req->req.actual = 0;
6723 + req->submitted = 1;
6725 + if (req->using_dma) {
6726 + if (req->req.length == 0) {
6727 + usba_ep_writel(ep, CTL_ENB, USBA_TX_PK_RDY);
6731 + if (req->req.zero)
6732 + usba_ep_writel(ep, CTL_ENB, USBA_SHORT_PACKET);
6734 + usba_ep_writel(ep, CTL_DIS, USBA_SHORT_PACKET);
6736 + usba_dma_writel(ep, ADDRESS, req->req.dma);
6737 + usba_dma_writel(ep, CONTROL, req->ctrl);
6739 + next_fifo_transaction(ep, req);
6740 + if (req->last_transaction) {
6741 + usba_ep_writel(ep, CTL_DIS, USBA_TX_PK_RDY);
6742 + usba_ep_writel(ep, CTL_ENB, USBA_TX_COMPLETE);
6744 + usba_ep_writel(ep, CTL_DIS, USBA_TX_COMPLETE);
6745 + usba_ep_writel(ep, CTL_ENB, USBA_TX_PK_RDY);
6750 +static void submit_next_request(struct usba_ep *ep)
6752 + struct usba_request *req;
6754 + if (list_empty(&ep->queue)) {
6755 + usba_ep_writel(ep, CTL_DIS, USBA_TX_PK_RDY | USBA_RX_BK_RDY);
6759 + req = list_entry(ep->queue.next, struct usba_request, queue);
6760 + if (!req->submitted)
6761 + submit_request(ep, req);
6764 +static void send_status(struct usba_udc *udc, struct usba_ep *ep)
6766 + ep->state = STATUS_STAGE_IN;
6767 + usba_ep_writel(ep, SET_STA, USBA_TX_PK_RDY);
6768 + usba_ep_writel(ep, CTL_ENB, USBA_TX_COMPLETE);
6771 +static void receive_data(struct usba_ep *ep)
6773 + struct usba_udc *udc = ep->udc;
6774 + struct usba_request *req;
6775 + unsigned long status;
6776 + unsigned int bytecount, nr_busy;
6777 + int is_complete = 0;
6779 + status = usba_ep_readl(ep, STA);
6780 + nr_busy = USBA_BFEXT(BUSY_BANKS, status);
6782 + DBG(DBG_QUEUE, "receive data: nr_busy=%u\n", nr_busy);
6784 + while (nr_busy > 0) {
6785 + if (list_empty(&ep->queue)) {
6786 + usba_ep_writel(ep, CTL_DIS, USBA_RX_BK_RDY);
6789 + req = list_entry(ep->queue.next,
6790 + struct usba_request, queue);
6792 + bytecount = USBA_BFEXT(BYTE_COUNT, status);
6794 + if (status & (1 << 31))
6796 + if (req->req.actual + bytecount >= req->req.length) {
6798 + bytecount = req->req.length - req->req.actual;
6801 + copy_from_fifo(req->req.buf + req->req.actual,
6802 + ep->fifo, bytecount);
6803 + req->req.actual += bytecount;
6805 + usba_ep_writel(ep, CLR_STA, USBA_RX_BK_RDY);
6807 + if (is_complete) {
6808 + DBG(DBG_QUEUE, "%s: request done\n", ep->ep.name);
6809 + req->req.status = 0;
6810 + list_del_init(&req->queue);
6811 + usba_ep_writel(ep, CTL_DIS, USBA_RX_BK_RDY);
6812 + spin_unlock(&udc->lock);
6813 + req->req.complete(&ep->ep, &req->req);
6814 + spin_lock(&udc->lock);
6817 + status = usba_ep_readl(ep, STA);
6818 + nr_busy = USBA_BFEXT(BUSY_BANKS, status);
6820 + if (is_complete && ep_is_control(ep)) {
6821 + send_status(udc, ep);
6828 +request_complete(struct usba_ep *ep, struct usba_request *req, int status)
6830 + struct usba_udc *udc = ep->udc;
6832 + WARN_ON(!list_empty(&req->queue));
6834 + if (req->req.status == -EINPROGRESS)
6835 + req->req.status = status;
6837 + if (req->mapped) {
6839 + &udc->pdev->dev, req->req.dma, req->req.length,
6840 + ep->is_in ? DMA_TO_DEVICE : DMA_FROM_DEVICE);
6841 + req->req.dma = DMA_ADDR_INVALID;
6845 + DBG(DBG_GADGET | DBG_REQ,
6846 + "%s: req %p complete: status %d, actual %u\n",
6847 + ep->ep.name, req, req->req.status, req->req.actual);
6849 + spin_unlock(&udc->lock);
6850 + req->req.complete(&ep->ep, &req->req);
6851 + spin_lock(&udc->lock);
6855 +request_complete_list(struct usba_ep *ep, struct list_head *list, int status)
6857 + struct usba_request *req, *tmp_req;
6859 + list_for_each_entry_safe(req, tmp_req, list, queue) {
6860 + list_del_init(&req->queue);
6861 + request_complete(ep, req, status);
6866 +usba_ep_enable(struct usb_ep *_ep, const struct usb_endpoint_descriptor *desc)
6868 + struct usba_ep *ep = to_usba_ep(_ep);
6869 + struct usba_udc *udc = ep->udc;
6870 + unsigned long flags, ept_cfg, maxpacket;
6871 + unsigned int nr_trans;
6873 + DBG(DBG_GADGET, "%s: ep_enable: desc=%p\n", ep->ep.name, desc);
6875 + maxpacket = le16_to_cpu(desc->wMaxPacketSize) & 0x7ff;
6877 + if (((desc->bEndpointAddress & USB_ENDPOINT_NUMBER_MASK) != ep->index)
6879 + || desc->bDescriptorType != USB_DT_ENDPOINT
6881 + || maxpacket > ep->fifo_size) {
6882 + DBG(DBG_ERR, "ep_enable: Invalid argument");
6889 + if (maxpacket <= 8)
6890 + ept_cfg = USBA_BF(EPT_SIZE, USBA_EPT_SIZE_8);
6892 + /* LSB is bit 1, not 0 */
6893 + ept_cfg = USBA_BF(EPT_SIZE, fls(maxpacket - 1) - 3);
6895 + DBG(DBG_HW, "%s: EPT_SIZE = %lu (maxpacket = %lu)\n",
6896 + ep->ep.name, ept_cfg, maxpacket);
6898 + if ((desc->bEndpointAddress & USB_ENDPOINT_DIR_MASK) == USB_DIR_IN) {
6900 + ept_cfg |= USBA_EPT_DIR_IN;
6903 + switch (desc->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) {
6904 + case USB_ENDPOINT_XFER_CONTROL:
6905 + ept_cfg |= USBA_BF(EPT_TYPE, USBA_EPT_TYPE_CONTROL);
6906 + ept_cfg |= USBA_BF(BK_NUMBER, USBA_BK_NUMBER_ONE);
6908 + case USB_ENDPOINT_XFER_ISOC:
6909 + if (!ep->can_isoc) {
6910 + DBG(DBG_ERR, "ep_enable: %s is not isoc capable\n",
6916 + * Bits 11:12 specify number of _additional_
6917 + * transactions per microframe.
6919 + nr_trans = ((le16_to_cpu(desc->wMaxPacketSize) >> 11) & 3) + 1;
6924 + ept_cfg |= USBA_BF(EPT_TYPE, USBA_EPT_TYPE_ISO);
6927 + * Do triple-buffering on high-bandwidth iso endpoints.
6929 + if (nr_trans > 1 && ep->nr_banks == 3)
6930 + ept_cfg |= USBA_BF(BK_NUMBER, USBA_BK_NUMBER_TRIPLE);
6932 + ept_cfg |= USBA_BF(BK_NUMBER, USBA_BK_NUMBER_DOUBLE);
6933 + ept_cfg |= USBA_BF(NB_TRANS, nr_trans);
6935 + case USB_ENDPOINT_XFER_BULK:
6936 + ept_cfg |= USBA_BF(EPT_TYPE, USBA_EPT_TYPE_BULK);
6937 + ept_cfg |= USBA_BF(BK_NUMBER, USBA_BK_NUMBER_DOUBLE);
6939 + case USB_ENDPOINT_XFER_INT:
6940 + ept_cfg |= USBA_BF(EPT_TYPE, USBA_EPT_TYPE_INT);
6941 + ept_cfg |= USBA_BF(BK_NUMBER, USBA_BK_NUMBER_DOUBLE);
6945 + spin_lock_irqsave(&ep->udc->lock, flags);
6948 + spin_unlock_irqrestore(&ep->udc->lock, flags);
6949 + DBG(DBG_ERR, "ep%d already enabled\n", ep->index);
6954 + ep->ep.maxpacket = maxpacket;
6956 + usba_ep_writel(ep, CFG, ept_cfg);
6957 + usba_ep_writel(ep, CTL_ENB, USBA_EPT_ENABLE);
6959 + if (ep->can_dma) {
6962 + usba_writel(udc, INT_ENB,
6963 + (usba_readl(udc, INT_ENB)
6964 + | USBA_BF(EPT_INT, 1 << ep->index)
6965 + | USBA_BF(DMA_INT, 1 << ep->index)));
6966 + ctrl = USBA_AUTO_VALID | USBA_INTDIS_DMA;
6967 + usba_ep_writel(ep, CTL_ENB, ctrl);
6969 + usba_writel(udc, INT_ENB,
6970 + (usba_readl(udc, INT_ENB)
6971 + | USBA_BF(EPT_INT, 1 << ep->index)));
6974 + spin_unlock_irqrestore(&udc->lock, flags);
6976 + DBG(DBG_HW, "EPT_CFG%d after init: %#08lx\n", ep->index,
6977 + (unsigned long)usba_ep_readl(ep, CFG));
6978 + DBG(DBG_HW, "INT_ENB after init: %#08lx\n",
6979 + (unsigned long)usba_readl(udc, INT_ENB));
6984 +static int usba_ep_disable(struct usb_ep *_ep)
6986 + struct usba_ep *ep = to_usba_ep(_ep);
6987 + struct usba_udc *udc = ep->udc;
6988 + LIST_HEAD(req_list);
6989 + unsigned long flags;
6991 + DBG(DBG_GADGET, "ep_disable: %s\n", ep->ep.name);
6993 + spin_lock_irqsave(&udc->lock, flags);
6996 + spin_unlock_irqrestore(&udc->lock, flags);
6997 + DBG(DBG_ERR, "ep_disable: %s not enabled\n", ep->ep.name);
7002 + list_splice_init(&ep->queue, &req_list);
7003 + if (ep->can_dma) {
7004 + usba_dma_writel(ep, CONTROL, 0);
7005 + usba_dma_writel(ep, ADDRESS, 0);
7006 + usba_dma_readl(ep, STATUS);
7008 + usba_ep_writel(ep, CTL_DIS, USBA_EPT_ENABLE);
7009 + usba_writel(udc, INT_ENB,
7010 + usba_readl(udc, INT_ENB)
7011 + & ~USBA_BF(EPT_INT, 1 << ep->index));
7013 + request_complete_list(ep, &req_list, -ESHUTDOWN);
7015 + spin_unlock_irqrestore(&udc->lock, flags);
7020 +static struct usb_request *
7021 +usba_ep_alloc_request(struct usb_ep *_ep, gfp_t gfp_flags)
7023 + struct usba_request *req;
7025 + DBG(DBG_GADGET, "ep_alloc_request: %p, 0x%x\n", _ep, gfp_flags);
7027 + req = kzalloc(sizeof(*req), gfp_flags);
7031 + INIT_LIST_HEAD(&req->queue);
7032 + req->req.dma = DMA_ADDR_INVALID;
7038 +usba_ep_free_request(struct usb_ep *_ep, struct usb_request *_req)
7040 + struct usba_request *req = to_usba_req(_req);
7042 + DBG(DBG_GADGET, "ep_free_request: %p, %p\n", _ep, _req);
7047 +static int queue_dma(struct usba_udc *udc, struct usba_ep *ep,
7048 + struct usba_request *req, gfp_t gfp_flags)
7050 + unsigned long flags;
7053 + DBG(DBG_DMA, "%s: req l/%u d/%08x %c%c%c\n",
7054 + ep->ep.name, req->req.length, req->req.dma,
7055 + req->req.zero ? 'Z' : 'z',
7056 + req->req.short_not_ok ? 'S' : 's',
7057 + req->req.no_interrupt ? 'I' : 'i');
7059 + if (req->req.length > 0x10000) {
7060 + /* Lengths from 0 to 65536 (inclusive) are supported */
7061 + DBG(DBG_ERR, "invalid request length %u\n", req->req.length);
7065 + req->using_dma = 1;
7067 + if (req->req.dma == DMA_ADDR_INVALID) {
7068 + req->req.dma = dma_map_single(
7069 + &udc->pdev->dev, req->req.buf, req->req.length,
7070 + ep->is_in ? DMA_TO_DEVICE : DMA_FROM_DEVICE);
7073 + dma_sync_single_for_device(
7074 + &udc->pdev->dev, req->req.dma, req->req.length,
7075 + ep->is_in ? DMA_TO_DEVICE : DMA_FROM_DEVICE);
7079 + req->ctrl = USBA_BF(DMA_BUF_LEN, req->req.length)
7080 + | USBA_DMA_CH_EN | USBA_DMA_END_BUF_IE
7081 + | USBA_DMA_END_TR_EN | USBA_DMA_END_TR_IE;
7084 + req->ctrl |= USBA_DMA_END_BUF_EN;
7087 + * Add this request to the queue and submit for DMA if
7088 + * possible. Check if we're still alive first -- we may have
7089 + * received a reset since last time we checked.
7092 + spin_lock_irqsave(&udc->lock, flags);
7094 + if (list_empty(&ep->queue))
7095 + submit_request(ep, req);
7097 + list_add_tail(&req->queue, &ep->queue);
7100 + spin_unlock_irqrestore(&udc->lock, flags);
7106 +usba_ep_queue(struct usb_ep *_ep, struct usb_request *_req, gfp_t gfp_flags)
7108 + struct usba_request *req = to_usba_req(_req);
7109 + struct usba_ep *ep = to_usba_ep(_ep);
7110 + struct usba_udc *udc = ep->udc;
7111 + unsigned long flags;
7114 + DBG(DBG_GADGET | DBG_QUEUE | DBG_REQ, "%s: queue req %p, len %u\n",
7115 + ep->ep.name, req, _req->length);
7117 + if (!udc->driver || udc->gadget.speed == USB_SPEED_UNKNOWN || !ep->desc)
7118 + return -ESHUTDOWN;
7120 + req->submitted = 0;
7121 + req->using_dma = 0;
7122 + req->last_transaction = 0;
7124 + _req->status = -EINPROGRESS;
7128 + return queue_dma(udc, ep, req, gfp_flags);
7130 + /* May have received a reset since last time we checked */
7132 + spin_lock_irqsave(&udc->lock, flags);
7134 + list_add_tail(&req->queue, &ep->queue);
7136 + if (ep->is_in || (ep_is_control(ep)
7137 + && (ep->state == DATA_STAGE_IN
7138 + || ep->state == STATUS_STAGE_IN)))
7139 + usba_ep_writel(ep, CTL_ENB, USBA_TX_PK_RDY);
7141 + usba_ep_writel(ep, CTL_ENB, USBA_RX_BK_RDY);
7144 + spin_unlock_irqrestore(&udc->lock, flags);
7150 +usba_update_req(struct usba_ep *ep, struct usba_request *req, u32 status)
7152 + req->req.actual = req->req.length - USBA_BFEXT(DMA_BUF_LEN, status);
7155 +static int stop_dma(struct usba_ep *ep, u32 *pstatus)
7157 + unsigned int timeout;
7161 + * Stop the DMA controller. When writing both CH_EN
7162 + * and LINK to 0, the other bits are not affected.
7164 + usba_dma_writel(ep, CONTROL, 0);
7166 + /* Wait for the FIFO to empty */
7167 + for (timeout = 40; timeout; --timeout) {
7168 + status = usba_dma_readl(ep, STATUS);
7169 + if (!(status & USBA_DMA_CH_EN))
7175 + *pstatus = status;
7177 + if (timeout == 0) {
7178 + dev_err(&ep->udc->pdev->dev,
7179 + "%s: timed out waiting for DMA FIFO to empty\n",
7181 + return -ETIMEDOUT;
7187 +static int usba_ep_dequeue(struct usb_ep *_ep, struct usb_request *_req)
7189 + struct usba_ep *ep = to_usba_ep(_ep);
7190 + struct usba_udc *udc = ep->udc;
7191 + struct usba_request *req = to_usba_req(_req);
7192 + unsigned long flags;
7195 + DBG(DBG_GADGET | DBG_QUEUE, "ep_dequeue: %s, req %p\n",
7196 + ep->ep.name, req);
7198 + spin_lock_irqsave(&udc->lock, flags);
7200 + if (req->using_dma) {
7202 + * If this request is currently being transferred,
7203 + * stop the DMA controller and reset the FIFO.
7205 + if (ep->queue.next == &req->queue) {
7206 + status = usba_dma_readl(ep, STATUS);
7207 + if (status & USBA_DMA_CH_EN)
7208 + stop_dma(ep, &status);
7210 +#ifdef CONFIG_USB_GADGET_DEBUG_FS
7211 + ep->last_dma_status = status;
7214 + usba_writel(udc, EPT_RST, 1 << ep->index);
7216 + usba_update_req(ep, req, status);
7221 + * Errors should stop the queue from advancing until the
7222 + * completion function returns.
7224 + list_del_init(&req->queue);
7226 + request_complete(ep, req, -ECONNRESET);
7228 + /* Process the next request if any */
7229 + submit_next_request(ep);
7230 + spin_unlock_irqrestore(&udc->lock, flags);
7235 +static int usba_ep_set_halt(struct usb_ep *_ep, int value)
7237 + struct usba_ep *ep = to_usba_ep(_ep);
7238 + struct usba_udc *udc = ep->udc;
7239 + unsigned long flags;
7242 + DBG(DBG_GADGET, "endpoint %s: %s HALT\n", ep->ep.name,
7243 + value ? "set" : "clear");
7246 + DBG(DBG_ERR, "Attempted to halt uninitialized ep %s\n",
7250 + if (ep->is_isoc) {
7251 + DBG(DBG_ERR, "Attempted to halt isochronous ep %s\n",
7256 + spin_lock_irqsave(&udc->lock, flags);
7259 + * We can't halt IN endpoints while there are still data to be
7262 + if (!list_empty(&ep->queue)
7263 + || ((value && ep->is_in && (usba_ep_readl(ep, STA)
7264 + & USBA_BF(BUSY_BANKS, -1L))))) {
7268 + usba_ep_writel(ep, SET_STA, USBA_FORCE_STALL);
7270 + usba_ep_writel(ep, CLR_STA,
7271 + USBA_FORCE_STALL | USBA_TOGGLE_CLR);
7272 + usba_ep_readl(ep, STA);
7275 + spin_unlock_irqrestore(&udc->lock, flags);
7280 +static int usba_ep_fifo_status(struct usb_ep *_ep)
7282 + struct usba_ep *ep = to_usba_ep(_ep);
7284 + return USBA_BFEXT(BYTE_COUNT, usba_ep_readl(ep, STA));
7287 +static void usba_ep_fifo_flush(struct usb_ep *_ep)
7289 + struct usba_ep *ep = to_usba_ep(_ep);
7290 + struct usba_udc *udc = ep->udc;
7292 + usba_writel(udc, EPT_RST, 1 << ep->index);
7295 +static const struct usb_ep_ops usba_ep_ops = {
7296 + .enable = usba_ep_enable,
7297 + .disable = usba_ep_disable,
7298 + .alloc_request = usba_ep_alloc_request,
7299 + .free_request = usba_ep_free_request,
7300 + .queue = usba_ep_queue,
7301 + .dequeue = usba_ep_dequeue,
7302 + .set_halt = usba_ep_set_halt,
7303 + .fifo_status = usba_ep_fifo_status,
7304 + .fifo_flush = usba_ep_fifo_flush,
7307 +static int usba_udc_get_frame(struct usb_gadget *gadget)
7309 + struct usba_udc *udc = to_usba_udc(gadget);
7311 + return USBA_BFEXT(FRAME_NUMBER, usba_readl(udc, FNUM));
7314 +static const struct usb_gadget_ops usba_udc_ops = {
7315 + .get_frame = usba_udc_get_frame,
7318 +#define EP(nam, idx, maxpkt, maxbk, dma, isoc) \
7321 + .ops = &usba_ep_ops, \
7323 + .maxpacket = maxpkt, \
7325 + .udc = &the_udc, \
7326 + .queue = LIST_HEAD_INIT(usba_ep[idx].queue), \
7327 + .fifo_size = maxpkt, \
7328 + .nr_banks = maxbk, \
7331 + .can_isoc = isoc, \
7334 +static struct usba_ep usba_ep[] = {
7335 + EP("ep0", 0, 64, 1, 0, 0),
7336 + EP("ep1in-bulk", 1, 512, 2, 1, 1),
7337 + EP("ep2out-bulk", 2, 512, 2, 1, 1),
7338 + EP("ep3in-int", 3, 64, 3, 1, 0),
7339 + EP("ep4out-int", 4, 64, 3, 1, 0),
7340 + EP("ep5in-iso", 5, 1024, 3, 1, 1),
7341 + EP("ep6out-iso", 6, 1024, 3, 1, 1),
7345 +static struct usb_endpoint_descriptor usba_ep0_desc = {
7346 + .bLength = USB_DT_ENDPOINT_SIZE,
7347 + .bDescriptorType = USB_DT_ENDPOINT,
7348 + .bEndpointAddress = 0,
7349 + .bmAttributes = USB_ENDPOINT_XFER_CONTROL,
7350 + .wMaxPacketSize = __constant_cpu_to_le16(64),
7351 + /* FIXME: I have no idea what to put here */
7355 +static void nop_release(struct device *dev)
7360 +static struct usba_udc the_udc = {
7362 + .ops = &usba_udc_ops,
7363 + .ep0 = &usba_ep[0].ep,
7364 + .ep_list = LIST_HEAD_INIT(the_udc.gadget.ep_list),
7365 + .is_dualspeed = 1,
7366 + .name = "atmel_usba_udc",
7368 + .bus_id = "gadget",
7369 + .release = nop_release,
7373 + .lock = SPIN_LOCK_UNLOCKED,
7377 + * Called with interrupts disabled and udc->lock held.
7379 +static void reset_all_endpoints(struct usba_udc *udc)
7381 + struct usba_ep *ep;
7382 + struct usba_request *req, *tmp_req;
7384 + usba_writel(udc, EPT_RST, ~0UL);
7386 + ep = to_usba_ep(udc->gadget.ep0);
7387 + list_for_each_entry_safe(req, tmp_req, &ep->queue, queue) {
7388 + list_del_init(&req->queue);
7389 + request_complete(ep, req, -ECONNRESET);
7392 + list_for_each_entry(ep, &udc->gadget.ep_list, ep.ep_list) {
7394 + usba_ep_disable(&ep->ep);
7398 +static struct usba_ep *get_ep_by_addr(struct usba_udc *udc, u16 wIndex)
7400 + struct usba_ep *ep;
7402 + if ((wIndex & USB_ENDPOINT_NUMBER_MASK) == 0)
7403 + return to_usba_ep(udc->gadget.ep0);
7405 + list_for_each_entry (ep, &udc->gadget.ep_list, ep.ep_list) {
7406 + u8 bEndpointAddress;
7410 + bEndpointAddress = ep->desc->bEndpointAddress;
7411 + if ((wIndex ^ bEndpointAddress) & USB_DIR_IN)
7413 + if ((bEndpointAddress & USB_ENDPOINT_NUMBER_MASK)
7414 + == (wIndex & USB_ENDPOINT_NUMBER_MASK))
7421 +/* Called with interrupts disabled and udc->lock held */
7422 +static inline void set_protocol_stall(struct usba_udc *udc, struct usba_ep *ep)
7424 + usba_ep_writel(ep, SET_STA, USBA_FORCE_STALL);
7425 + ep->state = WAIT_FOR_SETUP;
7428 +static inline int is_stalled(struct usba_udc *udc, struct usba_ep *ep)
7430 + if (usba_ep_readl(ep, STA) & USBA_FORCE_STALL)
7435 +static inline void set_address(struct usba_udc *udc, unsigned int addr)
7439 + DBG(DBG_BUS, "setting address %u...\n", addr);
7440 + regval = usba_readl(udc, CTRL);
7441 + regval = USBA_BFINS(DEV_ADDR, addr, regval);
7442 + usba_writel(udc, CTRL, regval);
7445 +static int do_test_mode(struct usba_udc *udc)
7447 + static const char test_packet_buffer[] = {
7448 + /* JKJKJKJK * 9 */
7449 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
7450 + /* JJKKJJKK * 8 */
7451 + 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA,
7452 + /* JJKKJJKK * 8 */
7453 + 0xEE, 0xEE, 0xEE, 0xEE, 0xEE, 0xEE, 0xEE, 0xEE,
7454 + /* JJJJJJJKKKKKKK * 8 */
7455 + 0xFE, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
7456 + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
7457 + /* JJJJJJJK * 8 */
7458 + 0x7F, 0xBF, 0xDF, 0xEF, 0xF7, 0xFB, 0xFD,
7459 + /* {JKKKKKKK * 10}, JK */
7460 + 0xFC, 0x7E, 0xBF, 0xDF, 0xEF, 0xF7, 0xFB, 0xFD, 0x7E
7462 + struct usba_ep *ep;
7463 + struct device *dev = &udc->pdev->dev;
7466 + test_mode = udc->test_mode;
7468 + /* Start from a clean slate */
7469 + reset_all_endpoints(udc);
7471 + switch (test_mode) {
7474 + usba_writel(udc, TST, USBA_TST_J_MODE);
7475 + dev_info(dev, "Entering Test_J mode...\n");
7479 + usba_writel(udc, TST, USBA_TST_K_MODE);
7480 + dev_info(dev, "Entering Test_K mode...\n");
7484 + * Test_SE0_NAK: Force high-speed mode and set up ep0
7485 + * for Bulk IN transfers
7488 + usba_writel(udc, TST,
7489 + USBA_BF(SPEED_CFG, USBA_SPEED_CFG_FORCE_HIGH));
7490 + usba_ep_writel(ep, CFG,
7491 + USBA_BF(EPT_SIZE, USBA_EPT_SIZE_64)
7493 + | USBA_BF(EPT_TYPE, USBA_EPT_TYPE_BULK)
7494 + | USBA_BF(BK_NUMBER, 1));
7495 + if (!(usba_ep_readl(ep, CFG) & USBA_EPT_MAPPED)) {
7496 + set_protocol_stall(udc, ep);
7497 + dev_err(dev, "Test_SE0_NAK: ep0 not mapped\n");
7499 + usba_ep_writel(ep, CTL_ENB, USBA_EPT_ENABLE);
7500 + dev_info(dev, "Entering Test_SE0_NAK mode...\n");
7506 + usba_ep_writel(ep, CFG,
7507 + USBA_BF(EPT_SIZE, USBA_EPT_SIZE_64)
7509 + | USBA_BF(EPT_TYPE, USBA_EPT_TYPE_BULK)
7510 + | USBA_BF(BK_NUMBER, 1));
7511 + if (!(usba_ep_readl(ep, CFG) & USBA_EPT_MAPPED)) {
7512 + set_protocol_stall(udc, ep);
7513 + dev_err(dev, "Test_Packet: ep0 not mapped\n");
7515 + usba_ep_writel(ep, CTL_ENB, USBA_EPT_ENABLE);
7516 + usba_writel(udc, TST, USBA_TST_PKT_MODE);
7517 + copy_to_fifo(ep->fifo, test_packet_buffer,
7518 + sizeof(test_packet_buffer));
7519 + usba_ep_writel(ep, SET_STA, USBA_TX_PK_RDY);
7520 + dev_info(dev, "Entering Test_Packet mode...\n");
7524 + dev_err(dev, "Invalid test mode: 0x%04x\n", test_mode);
7531 +/* Avoid overly long expressions */
7532 +static inline bool feature_is_dev_remote_wakeup(struct usb_ctrlrequest *crq)
7534 + if (crq->wValue == __constant_cpu_to_le16(USB_DEVICE_REMOTE_WAKEUP))
7539 +static inline bool feature_is_dev_test_mode(struct usb_ctrlrequest *crq)
7541 + if (crq->wValue == __constant_cpu_to_le16(USB_DEVICE_TEST_MODE))
7546 +static inline bool feature_is_ep_halt(struct usb_ctrlrequest *crq)
7548 + if (crq->wValue == __constant_cpu_to_le16(USB_ENDPOINT_HALT))
7553 +static int handle_ep0_setup(struct usba_udc *udc, struct usba_ep *ep,
7554 + struct usb_ctrlrequest *crq)
7558 + switch (crq->bRequest) {
7559 + case USB_REQ_GET_STATUS: {
7562 + if (crq->bRequestType == (USB_DIR_IN | USB_RECIP_DEVICE)) {
7563 + /* Self-powered, no remote wakeup */
7564 + status = __constant_cpu_to_le16(1 << 0);
7565 + } else if (crq->bRequestType
7566 + == (USB_DIR_IN | USB_RECIP_INTERFACE)) {
7567 + status = __constant_cpu_to_le16(0);
7568 + } else if (crq->bRequestType
7569 + == (USB_DIR_IN | USB_RECIP_ENDPOINT)) {
7570 + struct usba_ep *target;
7572 + target = get_ep_by_addr(udc, le16_to_cpu(crq->wIndex));
7577 + if (is_stalled(udc, target))
7578 + status |= __constant_cpu_to_le16(1);
7582 + /* Write directly to the FIFO. No queueing is done. */
7583 + if (crq->wLength != __constant_cpu_to_le16(sizeof(status)))
7585 + ep->state = DATA_STAGE_IN;
7586 + __raw_writew(status, ep->fifo);
7587 + usba_ep_writel(ep, SET_STA, USBA_TX_PK_RDY);
7591 + case USB_REQ_CLEAR_FEATURE: {
7592 + if (crq->bRequestType == USB_RECIP_DEVICE) {
7593 + if (feature_is_dev_remote_wakeup(crq)) {
7594 + /* TODO: Handle REMOTE_WAKEUP */
7596 + /* Can't CLEAR_FEATURE TEST_MODE */
7599 + } else if (crq->bRequestType == USB_RECIP_ENDPOINT) {
7600 + struct usba_ep *target;
7602 + if (crq->wLength != __constant_cpu_to_le16(0)
7603 + || !feature_is_ep_halt(crq))
7605 + target = get_ep_by_addr(udc, le16_to_cpu(crq->wIndex));
7609 + usba_ep_writel(target, CLR_STA, USBA_FORCE_STALL);
7610 + if (target->index != 0)
7611 + usba_ep_writel(target, CLR_STA,
7617 + send_status(udc, ep);
7621 + case USB_REQ_SET_FEATURE: {
7622 + if (crq->bRequestType == USB_RECIP_DEVICE) {
7623 + if (feature_is_dev_test_mode(crq)) {
7624 + send_status(udc, ep);
7625 + ep->state = STATUS_STAGE_TEST;
7626 + udc->test_mode = le16_to_cpu(crq->wIndex);
7628 + } else if (feature_is_dev_remote_wakeup(crq)) {
7629 + /* TODO: Handle REMOTE_WAKEUP */
7633 + } else if (crq->bRequestType == USB_RECIP_ENDPOINT) {
7634 + struct usba_ep *target;
7636 + if (crq->wLength != __constant_cpu_to_le16(0)
7637 + || !feature_is_ep_halt(crq))
7640 + target = get_ep_by_addr(udc, le16_to_cpu(crq->wIndex));
7644 + usba_ep_writel(target, SET_STA, USBA_FORCE_STALL);
7648 + send_status(udc, ep);
7652 + case USB_REQ_SET_ADDRESS:
7653 + if (crq->bRequestType != (USB_DIR_OUT | USB_RECIP_DEVICE))
7656 + set_address(udc, le16_to_cpu(crq->wValue));
7657 + send_status(udc, ep);
7658 + ep->state = STATUS_STAGE_ADDR;
7663 + spin_unlock(&udc->lock);
7664 + retval = udc->driver->setup(&udc->gadget, crq);
7665 + spin_lock(&udc->lock);
7672 + "udc: %s: Invalid setup request: %02x.%02x v%04x i%04x l%d, "
7673 + "halting endpoint...\n",
7674 + ep->ep.name, crq->bRequestType, crq->bRequest,
7675 + le16_to_cpu(crq->wValue), le16_to_cpu(crq->wIndex),
7676 + le16_to_cpu(crq->wLength));
7677 + set_protocol_stall(udc, ep);
7681 +static void usba_control_irq(struct usba_udc *udc, struct usba_ep *ep)
7683 + struct usba_request *req;
7688 + epstatus = usba_ep_readl(ep, STA);
7689 + epctrl = usba_ep_readl(ep, CTL);
7691 + DBG(DBG_INT, "%s [%d]: s/%08x c/%08x\n",
7692 + ep->ep.name, ep->state, epstatus, epctrl);
7695 + if (!list_empty(&ep->queue))
7696 + req = list_entry(ep->queue.next,
7697 + struct usba_request, queue);
7699 + if ((epctrl & USBA_TX_PK_RDY) && !(epstatus & USBA_TX_PK_RDY)) {
7700 + if (req->submitted)
7701 + next_fifo_transaction(ep, req);
7703 + submit_request(ep, req);
7705 + if (req->last_transaction) {
7706 + usba_ep_writel(ep, CTL_DIS, USBA_TX_PK_RDY);
7707 + usba_ep_writel(ep, CTL_ENB, USBA_TX_COMPLETE);
7711 + if ((epstatus & epctrl) & USBA_TX_COMPLETE) {
7712 + usba_ep_writel(ep, CLR_STA, USBA_TX_COMPLETE);
7714 + switch (ep->state) {
7715 + case DATA_STAGE_IN:
7716 + usba_ep_writel(ep, CTL_ENB, USBA_RX_BK_RDY);
7717 + usba_ep_writel(ep, CTL_DIS, USBA_TX_COMPLETE);
7718 + ep->state = STATUS_STAGE_OUT;
7720 + case STATUS_STAGE_ADDR:
7721 + /* Activate our new address */
7722 + usba_writel(udc, CTRL, (usba_readl(udc, CTRL)
7723 + | USBA_FADDR_EN));
7724 + usba_ep_writel(ep, CTL_DIS, USBA_TX_COMPLETE);
7725 + ep->state = WAIT_FOR_SETUP;
7727 + case STATUS_STAGE_IN:
7729 + list_del_init(&req->queue);
7730 + request_complete(ep, req, 0);
7731 + submit_next_request(ep);
7733 + usba_ep_writel(ep, CTL_DIS, USBA_TX_COMPLETE);
7734 + ep->state = WAIT_FOR_SETUP;
7736 + case STATUS_STAGE_TEST:
7737 + usba_ep_writel(ep, CTL_DIS, USBA_TX_COMPLETE);
7738 + ep->state = WAIT_FOR_SETUP;
7739 + if (do_test_mode(udc))
7740 + set_protocol_stall(udc, ep);
7744 + "udc: %s: TXCOMP: Invalid endpoint state %d, "
7745 + "halting endpoint...\n",
7746 + ep->ep.name, ep->state);
7747 + set_protocol_stall(udc, ep);
7753 + if ((epstatus & epctrl) & USBA_RX_BK_RDY) {
7754 + switch (ep->state) {
7755 + case STATUS_STAGE_OUT:
7756 + usba_ep_writel(ep, CLR_STA, USBA_RX_BK_RDY);
7757 + usba_ep_writel(ep, CTL_DIS, USBA_RX_BK_RDY);
7760 + list_del_init(&req->queue);
7761 + request_complete(ep, req, 0);
7763 + ep->state = WAIT_FOR_SETUP;
7766 + case DATA_STAGE_OUT:
7771 + usba_ep_writel(ep, CLR_STA, USBA_RX_BK_RDY);
7772 + usba_ep_writel(ep, CTL_DIS, USBA_RX_BK_RDY);
7774 + "udc: %s: RXRDY: Invalid endpoint state %d, "
7775 + "halting endpoint...\n",
7776 + ep->ep.name, ep->state);
7777 + set_protocol_stall(udc, ep);
7783 + if (epstatus & USBA_RX_SETUP) {
7785 + struct usb_ctrlrequest crq;
7786 + unsigned long data[2];
7788 + unsigned int pkt_len;
7791 + if (ep->state != WAIT_FOR_SETUP) {
7793 + * Didn't expect a SETUP packet at this
7794 + * point. Clean up any pending requests (which
7795 + * may be successful).
7797 + int status = -EPROTO;
7800 + * RXRDY and TXCOMP are dropped when SETUP
7801 + * packets arrive. Just pretend we received
7802 + * the status packet.
7804 + if (ep->state == STATUS_STAGE_OUT
7805 + || ep->state == STATUS_STAGE_IN) {
7806 + usba_ep_writel(ep, CTL_DIS, USBA_RX_BK_RDY);
7811 + list_del_init(&req->queue);
7812 + request_complete(ep, req, status);
7816 + pkt_len = USBA_BFEXT(BYTE_COUNT, usba_ep_readl(ep, STA));
7817 + DBG(DBG_HW, "Packet length: %u\n", pkt_len);
7818 + if (pkt_len != sizeof(crq)) {
7819 + printk(KERN_WARNING "udc: Invalid packet length %u "
7820 + "(expected %lu)\n", pkt_len, sizeof(crq));
7821 + set_protocol_stall(udc, ep);
7825 + DBG(DBG_FIFO, "Copying ctrl request from 0x%p:\n", ep->fifo);
7826 + copy_from_fifo(crq.data, ep->fifo, sizeof(crq));
7828 + /* Free up one bank in the FIFO so that we can
7829 + * generate or receive a reply right away. */
7830 + usba_ep_writel(ep, CLR_STA, USBA_RX_SETUP);
7832 + /* printk(KERN_DEBUG "setup: %d: %02x.%02x\n",
7833 + ep->state, crq.crq.bRequestType,
7834 + crq.crq.bRequest); */
7836 + if (crq.crq.bRequestType & USB_DIR_IN) {
7838 + * The USB 2.0 spec states that "if wLength is
7839 + * zero, there is no data transfer phase."
7840 + * However, testusb #14 seems to actually
7841 + * expect a data phase even if wLength = 0...
7843 + ep->state = DATA_STAGE_IN;
7845 + if (crq.crq.wLength != __constant_cpu_to_le16(0))
7846 + ep->state = DATA_STAGE_OUT;
7848 + ep->state = STATUS_STAGE_IN;
7852 + if (ep->index == 0)
7853 + ret = handle_ep0_setup(udc, ep, &crq.crq);
7855 + spin_unlock(&udc->lock);
7856 + ret = udc->driver->setup(&udc->gadget, &crq.crq);
7857 + spin_lock(&udc->lock);
7860 + DBG(DBG_BUS, "req %02x.%02x, length %d, state %d, ret %d\n",
7861 + crq.crq.bRequestType, crq.crq.bRequest,
7862 + le16_to_cpu(crq.crq.wLength), ep->state, ret);
7865 + /* Let the host know that we failed */
7866 + set_protocol_stall(udc, ep);
7871 +static void usba_ep_irq(struct usba_udc *udc, struct usba_ep *ep)
7873 + struct usba_request *req;
7877 + epstatus = usba_ep_readl(ep, STA);
7878 + epctrl = usba_ep_readl(ep, CTL);
7880 + DBG(DBG_INT, "%s: interrupt, status: 0x%08x\n", ep->ep.name, epstatus);
7882 + while ((epctrl & USBA_TX_PK_RDY) && !(epstatus & USBA_TX_PK_RDY)) {
7883 + DBG(DBG_BUS, "%s: TX PK ready\n", ep->ep.name);
7885 + if (list_empty(&ep->queue)) {
7886 + dev_warn(&udc->pdev->dev, "ep_irq: queue empty\n");
7887 + usba_ep_writel(ep, CTL_DIS, USBA_TX_PK_RDY);
7891 + req = list_entry(ep->queue.next, struct usba_request, queue);
7893 + if (req->using_dma) {
7894 + /* Send a zero-length packet */
7895 + usba_ep_writel(ep, SET_STA,
7897 + usba_ep_writel(ep, CTL_DIS,
7899 + list_del_init(&req->queue);
7900 + submit_next_request(ep);
7901 + request_complete(ep, req, 0);
7903 + if (req->submitted)
7904 + next_fifo_transaction(ep, req);
7906 + submit_request(ep, req);
7908 + if (req->last_transaction) {
7909 + list_del_init(&req->queue);
7910 + submit_next_request(ep);
7911 + request_complete(ep, req, 0);
7915 + epstatus = usba_ep_readl(ep, STA);
7916 + epctrl = usba_ep_readl(ep, CTL);
7918 + if ((epstatus & epctrl) & USBA_RX_BK_RDY) {
7919 + DBG(DBG_BUS, "%s: RX data ready\n", ep->ep.name);
7921 + usba_ep_writel(ep, CLR_STA, USBA_RX_BK_RDY);
7925 +static void usba_dma_irq(struct usba_udc *udc, struct usba_ep *ep)
7927 + struct usba_request *req;
7928 + u32 status, control, pending;
7930 + status = usba_dma_readl(ep, STATUS);
7931 + control = usba_dma_readl(ep, CONTROL);
7932 +#ifdef CONFIG_USB_GADGET_DEBUG_FS
7933 + ep->last_dma_status = status;
7935 + pending = status & control;
7936 + DBG(DBG_INT | DBG_DMA, "dma irq, s/%#08x, c/%#08x\n", status, control);
7938 + if (status & USBA_DMA_CH_EN) {
7939 + dev_err(&udc->pdev->dev,
7940 + "DMA_CH_EN is set after transfer is finished!\n");
7941 + dev_err(&udc->pdev->dev,
7942 + "status=%#08x, pending=%#08x, control=%#08x\n",
7943 + status, pending, control);
7946 + * try to pretend nothing happened. We might have to
7947 + * do something here...
7951 + if (list_empty(&ep->queue))
7952 + /* Might happen if a reset comes along at the right moment */
7955 + if (pending & (USBA_DMA_END_TR_ST | USBA_DMA_END_BUF_ST)) {
7956 + req = list_entry(ep->queue.next, struct usba_request, queue);
7957 + usba_update_req(ep, req, status);
7959 + list_del_init(&req->queue);
7960 + submit_next_request(ep);
7961 + request_complete(ep, req, 0);
7965 +static irqreturn_t usba_udc_irq(int irq, void *devid)
7967 + struct usba_udc *udc = devid;
7972 + spin_lock(&udc->lock);
7974 + status = usba_readl(udc, INT_STA);
7975 + DBG(DBG_INT, "irq, status=%#08x\n", status);
7977 + if (status & USBA_DET_SUSPEND) {
7978 + usba_writel(udc, INT_CLR, USBA_DET_SUSPEND);
7979 + DBG(DBG_BUS, "Suspend detected\n");
7980 + if (udc->gadget.speed != USB_SPEED_UNKNOWN
7981 + && udc->driver && udc->driver->suspend) {
7982 + spin_unlock(&udc->lock);
7983 + udc->driver->suspend(&udc->gadget);
7984 + spin_lock(&udc->lock);
7988 + if (status & USBA_WAKE_UP) {
7989 + usba_writel(udc, INT_CLR, USBA_WAKE_UP);
7990 + DBG(DBG_BUS, "Wake Up CPU detected\n");
7993 + if (status & USBA_END_OF_RESUME) {
7994 + usba_writel(udc, INT_CLR, USBA_END_OF_RESUME);
7995 + DBG(DBG_BUS, "Resume detected\n");
7996 + if (udc->gadget.speed != USB_SPEED_UNKNOWN
7997 + && udc->driver && udc->driver->resume) {
7998 + spin_unlock(&udc->lock);
7999 + udc->driver->resume(&udc->gadget);
8000 + spin_lock(&udc->lock);
8004 + dma_status = USBA_BFEXT(DMA_INT, status);
8008 + for (i = 1; i < USBA_NR_ENDPOINTS; i++)
8009 + if (dma_status & (1 << i))
8010 + usba_dma_irq(udc, &usba_ep[i]);
8013 + ep_status = USBA_BFEXT(EPT_INT, status);
8017 + for (i = 0; i < USBA_NR_ENDPOINTS; i++)
8018 + if (ep_status & (1 << i)) {
8019 + if (ep_is_control(&usba_ep[i]))
8020 + usba_control_irq(udc, &usba_ep[i]);
8022 + usba_ep_irq(udc, &usba_ep[i]);
8026 + if (status & USBA_END_OF_RESET) {
8027 + struct usba_ep *ep0;
8029 + usba_writel(udc, INT_CLR, USBA_END_OF_RESET);
8030 + reset_all_endpoints(udc);
8032 + if (status & USBA_HIGH_SPEED) {
8033 + DBG(DBG_BUS, "High-speed bus reset detected\n");
8034 + udc->gadget.speed = USB_SPEED_HIGH;
8036 + DBG(DBG_BUS, "Full-speed bus reset detected\n");
8037 + udc->gadget.speed = USB_SPEED_FULL;
8040 + ep0 = &usba_ep[0];
8041 + ep0->desc = &usba_ep0_desc;
8042 + ep0->state = WAIT_FOR_SETUP;
8043 + usba_ep_writel(ep0, CFG,
8044 + (USBA_BF(EPT_SIZE, EP0_EPT_SIZE)
8045 + | USBA_BF(EPT_TYPE, USBA_EPT_TYPE_CONTROL)
8046 + | USBA_BF(BK_NUMBER, USBA_BK_NUMBER_ONE)));
8047 + usba_ep_writel(ep0, CTL_ENB,
8048 + USBA_EPT_ENABLE | USBA_RX_SETUP);
8049 + usba_writel(udc, INT_ENB,
8050 + (usba_readl(udc, INT_ENB)
8051 + | USBA_BF(EPT_INT, 1)
8052 + | USBA_DET_SUSPEND
8053 + | USBA_END_OF_RESUME));
8055 + if (!(usba_ep_readl(ep0, CFG) & USBA_EPT_MAPPED))
8056 + dev_warn(&udc->pdev->dev,
8057 + "WARNING: EP0 configuration is invalid!\n");
8060 + spin_unlock(&udc->lock);
8062 + return IRQ_HANDLED;
8065 +static irqreturn_t usba_vbus_irq(int irq, void *devid)
8067 + struct usba_udc *udc = devid;
8073 + spin_lock(&udc->lock);
8075 + /* May happen if Vbus pin toggles during probe() */
8079 + vbus = gpio_get_value(udc->vbus_pin);
8080 + if (vbus != udc->vbus_prev) {
8082 + usba_writel(udc, CTRL, USBA_EN_USBA);
8083 + usba_writel(udc, INT_ENB, USBA_END_OF_RESET);
8085 + udc->gadget.speed = USB_SPEED_UNKNOWN;
8086 + reset_all_endpoints(udc);
8087 + usba_writel(udc, CTRL, 0);
8088 + spin_unlock(&udc->lock);
8089 + udc->driver->disconnect(&udc->gadget);
8090 + spin_lock(&udc->lock);
8092 + udc->vbus_prev = vbus;
8096 + spin_unlock(&udc->lock);
8098 + return IRQ_HANDLED;
8101 +int usb_gadget_register_driver(struct usb_gadget_driver *driver)
8103 + struct usba_udc *udc = &the_udc;
8104 + unsigned long flags;
8110 + spin_lock_irqsave(&udc->lock, flags);
8111 + if (udc->driver) {
8112 + spin_unlock_irqrestore(&udc->lock, flags);
8116 + udc->driver = driver;
8117 + udc->gadget.dev.driver = &driver->driver;
8118 + spin_unlock_irqrestore(&udc->lock, flags);
8120 + clk_enable(udc->pclk);
8121 + clk_enable(udc->hclk);
8123 + ret = driver->bind(&udc->gadget);
8125 + DBG(DBG_ERR, "Could not bind to driver %s: error %d\n",
8126 + driver->driver.name, ret);
8127 + goto err_driver_bind;
8130 + DBG(DBG_GADGET, "registered driver `%s'\n", driver->driver.name);
8132 + udc->vbus_prev = 0;
8133 + if (udc->vbus_pin != -1)
8134 + enable_irq(gpio_to_irq(udc->vbus_pin));
8136 + /* If Vbus is present, enable the controller and wait for reset */
8137 + spin_lock_irqsave(&udc->lock, flags);
8138 + if (vbus_is_present(udc) && udc->vbus_prev == 0) {
8139 + usba_writel(udc, CTRL, USBA_EN_USBA);
8140 + usba_writel(udc, INT_ENB, USBA_END_OF_RESET);
8142 + spin_unlock_irqrestore(&udc->lock, flags);
8147 + udc->driver = NULL;
8148 + udc->gadget.dev.driver = NULL;
8151 +EXPORT_SYMBOL(usb_gadget_register_driver);
8153 +int usb_gadget_unregister_driver(struct usb_gadget_driver *driver)
8155 + struct usba_udc *udc = &the_udc;
8156 + unsigned long flags;
8160 + if (driver != udc->driver)
8163 + if (udc->vbus_pin != -1)
8164 + disable_irq(gpio_to_irq(udc->vbus_pin));
8166 + spin_lock_irqsave(&udc->lock, flags);
8167 + udc->gadget.speed = USB_SPEED_UNKNOWN;
8168 + reset_all_endpoints(udc);
8169 + spin_unlock_irqrestore(&udc->lock, flags);
8171 + /* This will also disable the DP pullup */
8172 + usba_writel(udc, CTRL, 0);
8174 + driver->unbind(&udc->gadget);
8175 + udc->gadget.dev.driver = NULL;
8176 + udc->driver = NULL;
8178 + clk_disable(udc->hclk);
8179 + clk_disable(udc->pclk);
8181 + DBG(DBG_GADGET, "unregistered driver `%s'\n", driver->driver.name);
8185 +EXPORT_SYMBOL(usb_gadget_unregister_driver);
8187 +static int __init usba_udc_probe(struct platform_device *pdev)
8189 + struct usba_platform_data *pdata = pdev->dev.platform_data;
8190 + struct resource *regs, *fifo;
8191 + struct clk *pclk, *hclk;
8192 + struct usba_udc *udc = &the_udc;
8195 + regs = platform_get_resource(pdev, IORESOURCE_MEM, CTRL_IOMEM_ID);
8196 + fifo = platform_get_resource(pdev, IORESOURCE_MEM, FIFO_IOMEM_ID);
8197 + if (!regs || !fifo)
8200 + irq = platform_get_irq(pdev, 0);
8204 + pclk = clk_get(&pdev->dev, "pclk");
8206 + return PTR_ERR(pclk);
8207 + hclk = clk_get(&pdev->dev, "hclk");
8208 + if (IS_ERR(hclk)) {
8209 + ret = PTR_ERR(hclk);
8210 + goto err_get_hclk;
8216 + udc->vbus_pin = -1;
8219 + udc->regs = ioremap(regs->start, regs->end - regs->start + 1);
8221 + dev_err(&pdev->dev, "Unable to map I/O memory, aborting.\n");
8222 + goto err_map_regs;
8224 + dev_info(&pdev->dev, "MMIO registers at 0x%08lx mapped at %p\n",
8225 + (unsigned long)regs->start, udc->regs);
8226 + udc->fifo = ioremap(fifo->start, fifo->end - fifo->start + 1);
8228 + dev_err(&pdev->dev, "Unable to map FIFO, aborting.\n");
8229 + goto err_map_fifo;
8231 + dev_info(&pdev->dev, "FIFO at 0x%08lx mapped at %p\n",
8232 + (unsigned long)fifo->start, udc->fifo);
8234 + device_initialize(&udc->gadget.dev);
8235 + udc->gadget.dev.parent = &pdev->dev;
8236 + udc->gadget.dev.dma_mask = pdev->dev.dma_mask;
8238 + platform_set_drvdata(pdev, udc);
8240 + /* Make sure we start from a clean slate */
8242 + usba_writel(udc, CTRL, 0);
8243 + clk_disable(pclk);
8245 + INIT_LIST_HEAD(&usba_ep[0].ep.ep_list);
8246 + usba_ep[0].ep_regs = udc->regs + USBA_EPT_BASE(0);
8247 + usba_ep[0].dma_regs = udc->regs + USBA_DMA_BASE(0);
8248 + usba_ep[0].fifo = udc->fifo + USBA_FIFO_BASE(0);
8249 + for (i = 1; i < ARRAY_SIZE(usba_ep); i++) {
8250 + struct usba_ep *ep = &usba_ep[i];
8252 + ep->ep_regs = udc->regs + USBA_EPT_BASE(i);
8253 + ep->dma_regs = udc->regs + USBA_DMA_BASE(i);
8254 + ep->fifo = udc->fifo + USBA_FIFO_BASE(i);
8256 + list_add_tail(&ep->ep.ep_list, &udc->gadget.ep_list);
8259 + ret = request_irq(irq, usba_udc_irq, 0, "atmel_usba_udc", udc);
8261 + dev_err(&pdev->dev, "Cannot request irq %d (error %d)\n",
8263 + goto err_request_irq;
8267 + ret = device_add(&udc->gadget.dev);
8269 + dev_dbg(&pdev->dev, "Could not add gadget: %d\n", ret);
8270 + goto err_device_add;
8273 + if (pdata && pdata->vbus_pin != GPIO_PIN_NONE) {
8274 + if (!gpio_request(pdata->vbus_pin, "atmel_usba_udc")) {
8275 + udc->vbus_pin = pdata->vbus_pin;
8277 + ret = request_irq(gpio_to_irq(udc->vbus_pin),
8279 + "atmel_usba_udc", udc);
8281 + gpio_free(udc->vbus_pin);
8282 + udc->vbus_pin = -1;
8283 + dev_warn(&udc->pdev->dev,
8284 + "failed to request vbus irq; "
8285 + "assuming always on\n");
8287 + disable_irq(gpio_to_irq(udc->vbus_pin));
8292 + usba_init_debugfs(udc);
8293 + for (i = 1; i < ARRAY_SIZE(usba_ep); i++)
8294 + usba_ep_init_debugfs(udc, &usba_ep[i]);
8299 + free_irq(irq, udc);
8301 + iounmap(udc->fifo);
8303 + iounmap(udc->regs);
8309 + platform_set_drvdata(pdev, NULL);
8314 +static int __exit usba_udc_remove(struct platform_device *pdev)
8316 + struct usba_udc *udc;
8319 + udc = platform_get_drvdata(pdev);
8321 + for (i = 1; i < ARRAY_SIZE(usba_ep); i++)
8322 + usba_ep_cleanup_debugfs(&usba_ep[i]);
8323 + usba_cleanup_debugfs(udc);
8325 + if (udc->vbus_pin != -1)
8326 + gpio_free(udc->vbus_pin);
8328 + free_irq(udc->irq, udc);
8329 + iounmap(udc->fifo);
8330 + iounmap(udc->regs);
8331 + clk_put(udc->hclk);
8332 + clk_put(udc->pclk);
8334 + device_unregister(&udc->gadget.dev);
8339 +static struct platform_driver udc_driver = {
8340 + .remove = __exit_p(usba_udc_remove),
8342 + .name = "atmel_usba_udc",
8346 +static int __init udc_init(void)
8348 + return platform_driver_probe(&udc_driver, usba_udc_probe);
8350 +module_init(udc_init);
8352 +static void __exit udc_exit(void)
8354 + platform_driver_unregister(&udc_driver);
8356 +module_exit(udc_exit);
8358 +MODULE_DESCRIPTION("Atmel USBA UDC driver");
8359 +MODULE_AUTHOR("Haavard Skinnemoen <hskinnemoen@atmel.com>");
8360 +MODULE_LICENSE("GPL");
8361 diff --git a/drivers/usb/gadget/atmel_usba_udc.h b/drivers/usb/gadget/atmel_usba_udc.h
8362 new file mode 100644
8363 index 0000000..f4f0f8b
8365 +++ b/drivers/usb/gadget/atmel_usba_udc.h
8368 + * Driver for the Atmel USBA high speed USB device controller
8370 + * Copyright (C) 2005-2007 Atmel Corporation
8372 + * This program is free software; you can redistribute it and/or modify
8373 + * it under the terms of the GNU General Public License version 2 as
8374 + * published by the Free Software Foundation.
8376 +#ifndef __LINUX_USB_GADGET_USBA_UDC_H__
8377 +#define __LINUX_USB_GADGET_USBA_UDC_H__
8379 +/* USB register offsets */
8380 +#define USBA_CTRL 0x0000
8381 +#define USBA_FNUM 0x0004
8382 +#define USBA_INT_ENB 0x0010
8383 +#define USBA_INT_STA 0x0014
8384 +#define USBA_INT_CLR 0x0018
8385 +#define USBA_EPT_RST 0x001c
8386 +#define USBA_TST 0x00e0
8388 +/* USB endpoint register offsets */
8389 +#define USBA_EPT_CFG 0x0000
8390 +#define USBA_EPT_CTL_ENB 0x0004
8391 +#define USBA_EPT_CTL_DIS 0x0008
8392 +#define USBA_EPT_CTL 0x000c
8393 +#define USBA_EPT_SET_STA 0x0014
8394 +#define USBA_EPT_CLR_STA 0x0018
8395 +#define USBA_EPT_STA 0x001c
8397 +/* USB DMA register offsets */
8398 +#define USBA_DMA_NXT_DSC 0x0000
8399 +#define USBA_DMA_ADDRESS 0x0004
8400 +#define USBA_DMA_CONTROL 0x0008
8401 +#define USBA_DMA_STATUS 0x000c
8403 +/* Bitfields in CTRL */
8404 +#define USBA_DEV_ADDR_OFFSET 0
8405 +#define USBA_DEV_ADDR_SIZE 7
8406 +#define USBA_FADDR_EN (1 << 7)
8407 +#define USBA_EN_USBA (1 << 8)
8408 +#define USBA_DETACH (1 << 9)
8409 +#define USBA_REMOTE_WAKE_UP (1 << 10)
8411 +/* Bitfields in FNUM */
8412 +#define USBA_MICRO_FRAME_NUM_OFFSET 0
8413 +#define USBA_MICRO_FRAME_NUM_SIZE 3
8414 +#define USBA_FRAME_NUMBER_OFFSET 3
8415 +#define USBA_FRAME_NUMBER_SIZE 11
8416 +#define USBA_FRAME_NUM_ERROR (1 << 31)
8418 +/* Bitfields in INT_ENB/INT_STA/INT_CLR */
8419 +#define USBA_HIGH_SPEED (1 << 0)
8420 +#define USBA_DET_SUSPEND (1 << 1)
8421 +#define USBA_MICRO_SOF (1 << 2)
8422 +#define USBA_SOF (1 << 3)
8423 +#define USBA_END_OF_RESET (1 << 4)
8424 +#define USBA_WAKE_UP (1 << 5)
8425 +#define USBA_END_OF_RESUME (1 << 6)
8426 +#define USBA_UPSTREAM_RESUME (1 << 7)
8427 +#define USBA_EPT_INT_OFFSET 8
8428 +#define USBA_EPT_INT_SIZE 16
8429 +#define USBA_DMA_INT_OFFSET 24
8430 +#define USBA_DMA_INT_SIZE 8
8432 +/* Bitfields in EPT_RST */
8433 +#define USBA_RST_OFFSET 0
8434 +#define USBA_RST_SIZE 16
8436 +/* Bitfields in USBA_TST */
8437 +#define USBA_SPEED_CFG_OFFSET 0
8438 +#define USBA_SPEED_CFG_SIZE 2
8439 +#define USBA_TST_J_MODE (1 << 2)
8440 +#define USBA_TST_K_MODE (1 << 3)
8441 +#define USBA_TST_PKT_MODE (1 << 4)
8442 +#define USBA_OPMODE2 (1 << 5)
8444 +/* Bitfields in EPT_CFG */
8445 +#define USBA_EPT_SIZE_OFFSET 0
8446 +#define USBA_EPT_SIZE_SIZE 3
8447 +#define USBA_EPT_DIR_IN (1 << 3)
8448 +#define USBA_EPT_TYPE_OFFSET 4
8449 +#define USBA_EPT_TYPE_SIZE 2
8450 +#define USBA_BK_NUMBER_OFFSET 6
8451 +#define USBA_BK_NUMBER_SIZE 2
8452 +#define USBA_NB_TRANS_OFFSET 8
8453 +#define USBA_NB_TRANS_SIZE 2
8454 +#define USBA_EPT_MAPPED (1 << 31)
8456 +/* Bitfields in EPT_CTL/EPT_CTL_ENB/EPT_CTL_DIS */
8457 +#define USBA_EPT_ENABLE (1 << 0)
8458 +#define USBA_AUTO_VALID (1 << 1)
8459 +#define USBA_INTDIS_DMA (1 << 3)
8460 +#define USBA_NYET_DIS (1 << 4)
8461 +#define USBA_DATAX_RX (1 << 6)
8462 +#define USBA_MDATA_RX (1 << 7)
8463 +/* Bits 8-15 and 31 enable interrupts for respective bits in EPT_STA */
8464 +#define USBA_BUSY_BANK_IE (1 << 18)
8466 +/* Bitfields in EPT_SET_STA/EPT_CLR_STA/EPT_STA */
8467 +#define USBA_FORCE_STALL (1 << 5)
8468 +#define USBA_TOGGLE_CLR (1 << 6)
8469 +#define USBA_TOGGLE_SEQ_OFFSET 6
8470 +#define USBA_TOGGLE_SEQ_SIZE 2
8471 +#define USBA_ERR_OVFLW (1 << 8)
8472 +#define USBA_RX_BK_RDY (1 << 9)
8473 +#define USBA_KILL_BANK (1 << 9)
8474 +#define USBA_TX_COMPLETE (1 << 10)
8475 +#define USBA_TX_PK_RDY (1 << 11)
8476 +#define USBA_ISO_ERR_TRANS (1 << 11)
8477 +#define USBA_RX_SETUP (1 << 12)
8478 +#define USBA_ISO_ERR_FLOW (1 << 12)
8479 +#define USBA_STALL_SENT (1 << 13)
8480 +#define USBA_ISO_ERR_CRC (1 << 13)
8481 +#define USBA_ISO_ERR_NBTRANS (1 << 13)
8482 +#define USBA_NAK_IN (1 << 14)
8483 +#define USBA_ISO_ERR_FLUSH (1 << 14)
8484 +#define USBA_NAK_OUT (1 << 15)
8485 +#define USBA_CURRENT_BANK_OFFSET 16
8486 +#define USBA_CURRENT_BANK_SIZE 2
8487 +#define USBA_BUSY_BANKS_OFFSET 18
8488 +#define USBA_BUSY_BANKS_SIZE 2
8489 +#define USBA_BYTE_COUNT_OFFSET 20
8490 +#define USBA_BYTE_COUNT_SIZE 11
8491 +#define USBA_SHORT_PACKET (1 << 31)
8493 +/* Bitfields in DMA_CONTROL */
8494 +#define USBA_DMA_CH_EN (1 << 0)
8495 +#define USBA_DMA_LINK (1 << 1)
8496 +#define USBA_DMA_END_TR_EN (1 << 2)
8497 +#define USBA_DMA_END_BUF_EN (1 << 3)
8498 +#define USBA_DMA_END_TR_IE (1 << 4)
8499 +#define USBA_DMA_END_BUF_IE (1 << 5)
8500 +#define USBA_DMA_DESC_LOAD_IE (1 << 6)
8501 +#define USBA_DMA_BURST_LOCK (1 << 7)
8502 +#define USBA_DMA_BUF_LEN_OFFSET 16
8503 +#define USBA_DMA_BUF_LEN_SIZE 16
8505 +/* Bitfields in DMA_STATUS */
8506 +#define USBA_DMA_CH_ACTIVE (1 << 1)
8507 +#define USBA_DMA_END_TR_ST (1 << 4)
8508 +#define USBA_DMA_END_BUF_ST (1 << 5)
8509 +#define USBA_DMA_DESC_LOAD_ST (1 << 6)
8511 +/* Constants for SPEED_CFG */
8512 +#define USBA_SPEED_CFG_NORMAL 0
8513 +#define USBA_SPEED_CFG_FORCE_HIGH 2
8514 +#define USBA_SPEED_CFG_FORCE_FULL 3
8516 +/* Constants for EPT_SIZE */
8517 +#define USBA_EPT_SIZE_8 0
8518 +#define USBA_EPT_SIZE_16 1
8519 +#define USBA_EPT_SIZE_32 2
8520 +#define USBA_EPT_SIZE_64 3
8521 +#define USBA_EPT_SIZE_128 4
8522 +#define USBA_EPT_SIZE_256 5
8523 +#define USBA_EPT_SIZE_512 6
8524 +#define USBA_EPT_SIZE_1024 7
8526 +/* Constants for EPT_TYPE */
8527 +#define USBA_EPT_TYPE_CONTROL 0
8528 +#define USBA_EPT_TYPE_ISO 1
8529 +#define USBA_EPT_TYPE_BULK 2
8530 +#define USBA_EPT_TYPE_INT 3
8532 +/* Constants for BK_NUMBER */
8533 +#define USBA_BK_NUMBER_ZERO 0
8534 +#define USBA_BK_NUMBER_ONE 1
8535 +#define USBA_BK_NUMBER_DOUBLE 2
8536 +#define USBA_BK_NUMBER_TRIPLE 3
8538 +/* Bit manipulation macros */
8539 +#define USBA_BF(name, value) \
8540 + (((value) & ((1 << USBA_##name##_SIZE) - 1)) \
8541 + << USBA_##name##_OFFSET)
8542 +#define USBA_BFEXT(name, value) \
8543 + (((value) >> USBA_##name##_OFFSET) \
8544 + & ((1 << USBA_##name##_SIZE) - 1))
8545 +#define USBA_BFINS(name, value, old) \
8546 + (((old) & ~(((1 << USBA_##name##_SIZE) - 1) \
8547 + << USBA_##name##_OFFSET)) \
8548 + | USBA_BF(name, value))
8550 +/* Register access macros */
8551 +#define usba_readl(udc, reg) \
8552 + __raw_readl((udc)->regs + USBA_##reg)
8553 +#define usba_writel(udc, reg, value) \
8554 + __raw_writel((value), (udc)->regs + USBA_##reg)
8555 +#define usba_ep_readl(ep, reg) \
8556 + __raw_readl((ep)->ep_regs + USBA_EPT_##reg)
8557 +#define usba_ep_writel(ep, reg, value) \
8558 + __raw_writel((value), (ep)->ep_regs + USBA_EPT_##reg)
8559 +#define usba_dma_readl(ep, reg) \
8560 + __raw_readl((ep)->dma_regs + USBA_DMA_##reg)
8561 +#define usba_dma_writel(ep, reg, value) \
8562 + __raw_writel((value), (ep)->dma_regs + USBA_DMA_##reg)
8564 +/* Calculate base address for a given endpoint or DMA controller */
8565 +#define USBA_EPT_BASE(x) (0x100 + (x) * 0x20)
8566 +#define USBA_DMA_BASE(x) (0x300 + (x) * 0x10)
8567 +#define USBA_FIFO_BASE(x) ((x) << 16)
8569 +/* Synth parameters */
8570 +#define USBA_NR_ENDPOINTS 7
8572 +#define EP0_FIFO_SIZE 64
8573 +#define EP0_EPT_SIZE USBA_EPT_SIZE_64
8574 +#define EP0_NR_BANKS 1
8577 + * REVISIT: Try to eliminate this value. Can we rely on req->mapped to
8578 + * provide this information?
8580 +#define DMA_ADDR_INVALID (~(dma_addr_t)0)
8582 +#define FIFO_IOMEM_ID 0
8583 +#define CTRL_IOMEM_ID 1
8586 +#define DBG_ERR 0x0001 /* report all error returns */
8587 +#define DBG_HW 0x0002 /* debug hardware initialization */
8588 +#define DBG_GADGET 0x0004 /* calls to/from gadget driver */
8589 +#define DBG_INT 0x0008 /* interrupts */
8590 +#define DBG_BUS 0x0010 /* report changes in bus state */
8591 +#define DBG_QUEUE 0x0020 /* debug request queue processing */
8592 +#define DBG_FIFO 0x0040 /* debug FIFO contents */
8593 +#define DBG_DMA 0x0080 /* debug DMA handling */
8594 +#define DBG_REQ 0x0100 /* print out queued request length */
8595 +#define DBG_ALL 0xffff
8596 +#define DBG_NONE 0x0000
8598 +#define DEBUG_LEVEL (DBG_ERR)
8599 +#define DBG(level, fmt, ...) \
8601 + if ((level) & DEBUG_LEVEL) \
8602 + printk(KERN_DEBUG "udc: " fmt, ## __VA_ARGS__); \
8605 +#define DBG(level, fmt...)
8608 +enum usba_ctrl_state {
8614 + STATUS_STAGE_ADDR,
8615 + STATUS_STAGE_TEST,
8621 + EP_STATE_OUT_DATA,
8622 + EP_STATE_SET_ADDR_STATUS,
8623 + EP_STATE_RX_STATUS,
8624 + EP_STATE_TX_STATUS,
8628 +struct usba_dma_desc {
8636 + void __iomem *ep_regs;
8637 + void __iomem *dma_regs;
8638 + void __iomem *fifo;
8640 + struct usba_udc *udc;
8642 + struct list_head queue;
8643 + const struct usb_endpoint_descriptor *desc;
8648 + unsigned int can_dma:1;
8649 + unsigned int can_isoc:1;
8650 + unsigned int is_isoc:1;
8651 + unsigned int is_in:1;
8653 +#ifdef CONFIG_USB_GADGET_DEBUG_FS
8654 + u32 last_dma_status;
8655 + struct dentry *debugfs_dir;
8656 + struct dentry *debugfs_queue;
8657 + struct dentry *debugfs_dma_status;
8658 + struct dentry *debugfs_state;
8662 +struct usba_request {
8663 + struct usb_request req;
8664 + struct list_head queue;
8668 + unsigned int submitted:1;
8669 + unsigned int last_transaction:1;
8670 + unsigned int using_dma:1;
8671 + unsigned int mapped:1;
8675 + /* Protect hw registers from concurrent modifications */
8678 + void __iomem *regs;
8679 + void __iomem *fifo;
8681 + struct usb_gadget gadget;
8682 + struct usb_gadget_driver *driver;
8683 + struct platform_device *pdev;
8692 +#ifdef CONFIG_USB_GADGET_DEBUG_FS
8693 + struct dentry *debugfs_root;
8694 + struct dentry *debugfs_regs;
8698 +static inline struct usba_ep *to_usba_ep(struct usb_ep *ep)
8700 + return container_of(ep, struct usba_ep, ep);
8703 +static inline struct usba_request *to_usba_req(struct usb_request *req)
8705 + return container_of(req, struct usba_request, req);
8708 +static inline struct usba_udc *to_usba_udc(struct usb_gadget *gadget)
8710 + return container_of(gadget, struct usba_udc, gadget);
8713 +#define ep_is_control(ep) ((ep)->index == 0)
8714 +#define ep_is_idle(ep) ((ep)->state == EP_STATE_IDLE)
8716 +#endif /* __LINUX_USB_GADGET_USBA_UDC_H */
8717 diff --git a/drivers/video/atmel_lcdfb.c b/drivers/video/atmel_lcdfb.c
8718 index 235b618..bb361ab 100644
8719 --- a/drivers/video/atmel_lcdfb.c
8720 +++ b/drivers/video/atmel_lcdfb.c
8724 #if defined(CONFIG_ARCH_AT91)
8725 -#define ATMEL_LCDFB_FBINFO_DEFAULT FBINFO_DEFAULT
8726 +#define ATMEL_LCDFB_FBINFO_DEFAULT (FBINFO_DEFAULT \
8727 + | FBINFO_PARTIAL_PAN_OK \
8728 + | FBINFO_HWACCEL_YPAN)
8730 static inline void atmel_lcdfb_update_dma2d(struct atmel_lcdfb_info *sinfo,
8731 struct fb_var_screeninfo *var)
8732 @@ -74,7 +76,7 @@ static struct fb_fix_screeninfo atmel_lcdfb_fix __initdata = {
8733 .type = FB_TYPE_PACKED_PIXELS,
8734 .visual = FB_VISUAL_TRUECOLOR,
8739 .accel = FB_ACCEL_NONE,
8741 diff --git a/drivers/video/backlight/Kconfig b/drivers/video/backlight/Kconfig
8742 index 2580f5f..b6f936a 100644
8743 --- a/drivers/video/backlight/Kconfig
8744 +++ b/drivers/video/backlight/Kconfig
8745 @@ -24,6 +24,18 @@ config LCD_CLASS_DEVICE
8746 To have support for your specific LCD panel you will have to
8747 select the proper drivers which depend on this option.
8749 +config LCD_LTV350QV
8750 + tristate "Samsung LTV350QV LCD Panel"
8751 + depends on LCD_CLASS_DEVICE && SPI_MASTER
8754 + If you have a Samsung LTV350QV LCD panel, say y to include a
8755 + power control driver for it. The panel starts up in power
8756 + off state, so you need this driver in order to see any
8759 + The LTV350QV panel is present on all ATSTK1000 boards.
8764 diff --git a/drivers/video/backlight/Makefile b/drivers/video/backlight/Makefile
8765 index c6e2266..965a78b 100644
8766 --- a/drivers/video/backlight/Makefile
8767 +++ b/drivers/video/backlight/Makefile
8769 # Backlight & LCD drivers
8771 obj-$(CONFIG_LCD_CLASS_DEVICE) += lcd.o
8772 +obj-$(CONFIG_LCD_LTV350QV) += ltv350qv.o
8774 obj-$(CONFIG_BACKLIGHT_CLASS_DEVICE) += backlight.o
8775 obj-$(CONFIG_BACKLIGHT_CORGI) += corgi_bl.o
8776 obj-$(CONFIG_BACKLIGHT_HP680) += hp680_bl.o
8777 diff --git a/drivers/video/backlight/ltv350qv.c b/drivers/video/backlight/ltv350qv.c
8778 new file mode 100644
8779 index 0000000..751dc53
8781 +++ b/drivers/video/backlight/ltv350qv.c
8784 + * Power control for Samsung LTV350QV Quarter VGA LCD Panel
8786 + * Copyright (C) 2006, 2007 Atmel Corporation
8788 + * This program is free software; you can redistribute it and/or modify
8789 + * it under the terms of the GNU General Public License version 2 as
8790 + * published by the Free Software Foundation.
8792 +#include <linux/delay.h>
8793 +#include <linux/err.h>
8794 +#include <linux/fb.h>
8795 +#include <linux/init.h>
8796 +#include <linux/lcd.h>
8797 +#include <linux/module.h>
8798 +#include <linux/spi/spi.h>
8800 +#include "ltv350qv.h"
8802 +#define POWER_IS_ON(pwr) ((pwr) <= FB_BLANK_NORMAL)
8805 + struct spi_device *spi;
8808 + struct lcd_device *ld;
8812 + * The power-on and power-off sequences are taken from the
8813 + * LTV350QV-F04 data sheet from Samsung. The register definitions are
8814 + * taken from the S6F2002 command list also from Samsung. Both
8815 + * documents are distributed with the AVR32 Linux BSP CD from Atmel.
8817 + * There's still some voodoo going on here, but it's a lot better than
8818 + * in the first incarnation of the driver where all we had was the raw
8819 + * numbers from the initialization sequence.
8821 +static int ltv350qv_write_reg(struct ltv350qv *lcd, u8 reg, u16 val)
8823 + struct spi_message msg;
8824 + struct spi_transfer index_xfer = {
8828 + struct spi_transfer value_xfer = {
8832 + spi_message_init(&msg);
8834 + /* register index */
8835 + lcd->buffer[0] = LTV_OPC_INDEX;
8836 + lcd->buffer[1] = 0x00;
8837 + lcd->buffer[2] = reg & 0x7f;
8838 + index_xfer.tx_buf = lcd->buffer;
8839 + spi_message_add_tail(&index_xfer, &msg);
8841 + /* register value */
8842 + lcd->buffer[4] = LTV_OPC_DATA;
8843 + lcd->buffer[5] = val >> 8;
8844 + lcd->buffer[6] = val;
8845 + value_xfer.tx_buf = lcd->buffer + 4;
8846 + spi_message_add_tail(&value_xfer, &msg);
8848 + return spi_sync(lcd->spi, &msg);
8851 +/* The comments are taken straight from the data sheet */
8852 +static int ltv350qv_power_on(struct ltv350qv *lcd)
8856 + /* Power On Reset Display off State */
8857 + if (ltv350qv_write_reg(lcd, LTV_PWRCTL1, 0x0000))
8861 + /* Power Setting Function 1 */
8862 + if (ltv350qv_write_reg(lcd, LTV_PWRCTL1, LTV_VCOM_DISABLE))
8864 + if (ltv350qv_write_reg(lcd, LTV_PWRCTL2, LTV_VCOML_ENABLE))
8867 + /* Power Setting Function 2 */
8868 + if (ltv350qv_write_reg(lcd, LTV_PWRCTL1,
8869 + LTV_VCOM_DISABLE | LTV_DRIVE_CURRENT(5)
8870 + | LTV_SUPPLY_CURRENT(5)))
8875 + /* Instruction Setting */
8876 + ret = ltv350qv_write_reg(lcd, LTV_IFCTL,
8877 + LTV_NMD | LTV_REV | LTV_NL(0x1d));
8878 + ret |= ltv350qv_write_reg(lcd, LTV_DATACTL,
8879 + LTV_DS_SAME | LTV_CHS_480
8880 + | LTV_DF_RGB | LTV_RGB_BGR);
8881 + ret |= ltv350qv_write_reg(lcd, LTV_ENTRY_MODE,
8882 + LTV_VSPL_ACTIVE_LOW
8883 + | LTV_HSPL_ACTIVE_LOW
8884 + | LTV_DPL_SAMPLE_RISING
8885 + | LTV_EPL_ACTIVE_LOW
8886 + | LTV_SS_RIGHT_TO_LEFT);
8887 + ret |= ltv350qv_write_reg(lcd, LTV_GATECTL1, LTV_CLW(3));
8888 + ret |= ltv350qv_write_reg(lcd, LTV_GATECTL2,
8889 + LTV_NW_INV_1LINE | LTV_FWI(3));
8890 + ret |= ltv350qv_write_reg(lcd, LTV_VBP, 0x000a);
8891 + ret |= ltv350qv_write_reg(lcd, LTV_HBP, 0x0021);
8892 + ret |= ltv350qv_write_reg(lcd, LTV_SOTCTL, LTV_SDT(3) | LTV_EQ(0));
8893 + ret |= ltv350qv_write_reg(lcd, LTV_GAMMA(0), 0x0103);
8894 + ret |= ltv350qv_write_reg(lcd, LTV_GAMMA(1), 0x0301);
8895 + ret |= ltv350qv_write_reg(lcd, LTV_GAMMA(2), 0x1f0f);
8896 + ret |= ltv350qv_write_reg(lcd, LTV_GAMMA(3), 0x1f0f);
8897 + ret |= ltv350qv_write_reg(lcd, LTV_GAMMA(4), 0x0707);
8898 + ret |= ltv350qv_write_reg(lcd, LTV_GAMMA(5), 0x0307);
8899 + ret |= ltv350qv_write_reg(lcd, LTV_GAMMA(6), 0x0707);
8900 + ret |= ltv350qv_write_reg(lcd, LTV_GAMMA(7), 0x0000);
8901 + ret |= ltv350qv_write_reg(lcd, LTV_GAMMA(8), 0x0004);
8902 + ret |= ltv350qv_write_reg(lcd, LTV_GAMMA(9), 0x0000);
8904 + goto err_settings;
8906 + /* Wait more than 2 frames */
8909 + /* Display On Sequence */
8910 + ret = ltv350qv_write_reg(lcd, LTV_PWRCTL1,
8911 + LTV_VCOM_DISABLE | LTV_VCOMOUT_ENABLE
8912 + | LTV_POWER_ON | LTV_DRIVE_CURRENT(5)
8913 + | LTV_SUPPLY_CURRENT(5));
8914 + ret |= ltv350qv_write_reg(lcd, LTV_GATECTL2,
8915 + LTV_NW_INV_1LINE | LTV_DSC | LTV_FWI(3));
8919 + /* Display should now be ON. Phew. */
8924 + * Try to recover. Error handling probably isn't very useful
8925 + * at this point, just make a best effort to switch the panel
8928 + ltv350qv_write_reg(lcd, LTV_PWRCTL1,
8929 + LTV_VCOM_DISABLE | LTV_DRIVE_CURRENT(5)
8930 + | LTV_SUPPLY_CURRENT(5));
8931 + ltv350qv_write_reg(lcd, LTV_GATECTL2,
8932 + LTV_NW_INV_1LINE | LTV_FWI(3));
8936 + ltv350qv_write_reg(lcd, LTV_PWRCTL2, 0x0000);
8939 + ltv350qv_write_reg(lcd, LTV_PWRCTL1, LTV_VCOM_DISABLE);
8943 +static int ltv350qv_power_off(struct ltv350qv *lcd)
8947 + /* Display Off Sequence */
8948 + ret = ltv350qv_write_reg(lcd, LTV_PWRCTL1,
8950 + | LTV_DRIVE_CURRENT(5)
8951 + | LTV_SUPPLY_CURRENT(5));
8952 + ret |= ltv350qv_write_reg(lcd, LTV_GATECTL2,
8953 + LTV_NW_INV_1LINE | LTV_FWI(3));
8955 + /* Power down setting 1 */
8956 + ret |= ltv350qv_write_reg(lcd, LTV_PWRCTL2, 0x0000);
8958 + /* Wait at least 1 ms */
8961 + /* Power down setting 2 */
8962 + ret |= ltv350qv_write_reg(lcd, LTV_PWRCTL1, LTV_VCOM_DISABLE);
8965 + * No point in trying to recover here. If we can't switch the
8966 + * panel off, what are we supposed to do other than inform the
8967 + * user about the failure?
8972 + /* Display power should now be OFF */
8976 +static int ltv350qv_power(struct ltv350qv *lcd, int power)
8980 + if (POWER_IS_ON(power) && !POWER_IS_ON(lcd->power))
8981 + ret = ltv350qv_power_on(lcd);
8982 + else if (!POWER_IS_ON(power) && POWER_IS_ON(lcd->power))
8983 + ret = ltv350qv_power_off(lcd);
8986 + lcd->power = power;
8991 +static int ltv350qv_set_power(struct lcd_device *ld, int power)
8993 + struct ltv350qv *lcd;
8995 + lcd = lcd_get_data(ld);
8996 + return ltv350qv_power(lcd, power);
8999 +static int ltv350qv_get_power(struct lcd_device *ld)
9001 + struct ltv350qv *lcd;
9003 + lcd = lcd_get_data(ld);
9004 + return lcd->power;
9007 +static struct lcd_ops ltv_ops = {
9008 + .get_power = ltv350qv_get_power,
9009 + .set_power = ltv350qv_set_power,
9012 +static int __devinit ltv350qv_probe(struct spi_device *spi)
9014 + struct ltv350qv *lcd;
9015 + struct lcd_device *ld;
9018 + lcd = kzalloc(sizeof(struct ltv350qv), GFP_KERNEL);
9023 + lcd->power = FB_BLANK_POWERDOWN;
9024 + lcd->buffer = kzalloc(8, GFP_KERNEL);
9026 + ld = lcd_device_register("ltv350qv", &spi->dev, lcd, <v_ops);
9028 + ret = PTR_ERR(ld);
9029 + goto out_free_lcd;
9033 + ret = ltv350qv_power(lcd, FB_BLANK_UNBLANK);
9035 + goto out_unregister;
9037 + dev_set_drvdata(&spi->dev, lcd);
9042 + lcd_device_unregister(ld);
9048 +static int __devexit ltv350qv_remove(struct spi_device *spi)
9050 + struct ltv350qv *lcd = dev_get_drvdata(&spi->dev);
9052 + ltv350qv_power(lcd, FB_BLANK_POWERDOWN);
9053 + lcd_device_unregister(lcd->ld);
9060 +static int ltv350qv_suspend(struct spi_device *spi,
9061 + pm_message_t state, u32 level)
9063 + struct ltv350qv *lcd = dev_get_drvdata(&spi->dev);
9065 + if (level == SUSPEND_POWER_DOWN)
9066 + return ltv350qv_power(lcd, FB_BLANK_POWERDOWN);
9071 +static int ltv350qv_resume(struct spi_device *spi, u32 level)
9073 + struct ltv350qv *lcd = dev_get_drvdata(&spi->dev);
9075 + if (level == RESUME_POWER_ON)
9076 + return ltv350qv_power(lcd, FB_BLANK_UNBLANK);
9081 +#define ltv350qv_suspend NULL
9082 +#define ltv350qv_resume NULL
9085 +/* Power down all displays on reboot, poweroff or halt */
9086 +static void ltv350qv_shutdown(struct spi_device *spi)
9088 + struct ltv350qv *lcd = dev_get_drvdata(&spi->dev);
9090 + ltv350qv_power(lcd, FB_BLANK_POWERDOWN);
9093 +static struct spi_driver ltv350qv_driver = {
9095 + .name = "ltv350qv",
9096 + .bus = &spi_bus_type,
9097 + .owner = THIS_MODULE,
9100 + .probe = ltv350qv_probe,
9101 + .remove = __devexit_p(ltv350qv_remove),
9102 + .shutdown = ltv350qv_shutdown,
9103 + .suspend = ltv350qv_suspend,
9104 + .resume = ltv350qv_resume,
9107 +static int __init ltv350qv_init(void)
9109 + return spi_register_driver(<v350qv_driver);
9112 +static void __exit ltv350qv_exit(void)
9114 + spi_unregister_driver(<v350qv_driver);
9116 +module_init(ltv350qv_init);
9117 +module_exit(ltv350qv_exit);
9119 +MODULE_AUTHOR("Haavard Skinnemoen <hskinnemoen@atmel.com>");
9120 +MODULE_DESCRIPTION("Samsung LTV350QV LCD Driver");
9121 +MODULE_LICENSE("GPL");
9122 diff --git a/drivers/video/backlight/ltv350qv.h b/drivers/video/backlight/ltv350qv.h
9123 new file mode 100644
9124 index 0000000..189112e
9126 +++ b/drivers/video/backlight/ltv350qv.h
9129 + * Register definitions for Samsung LTV350QV Quarter VGA LCD Panel
9131 + * Copyright (C) 2006, 2007 Atmel Corporation
9133 + * This program is free software; you can redistribute it and/or modify
9134 + * it under the terms of the GNU General Public License version 2 as
9135 + * published by the Free Software Foundation.
9137 +#ifndef __LTV350QV_H
9138 +#define __LTV350QV_H
9140 +#define LTV_OPC_INDEX 0x74
9141 +#define LTV_OPC_DATA 0x76
9143 +#define LTV_ID 0x00 /* ID Read */
9144 +#define LTV_IFCTL 0x01 /* Display Interface Control */
9145 +#define LTV_DATACTL 0x02 /* Display Data Control */
9146 +#define LTV_ENTRY_MODE 0x03 /* Entry Mode */
9147 +#define LTV_GATECTL1 0x04 /* Gate Control 1 */
9148 +#define LTV_GATECTL2 0x05 /* Gate Control 2 */
9149 +#define LTV_VBP 0x06 /* Vertical Back Porch */
9150 +#define LTV_HBP 0x07 /* Horizontal Back Porch */
9151 +#define LTV_SOTCTL 0x08 /* Source Output Timing Control */
9152 +#define LTV_PWRCTL1 0x09 /* Power Control 1 */
9153 +#define LTV_PWRCTL2 0x0a /* Power Control 2 */
9154 +#define LTV_GAMMA(x) (0x10 + (x)) /* Gamma control */
9156 +/* Bit definitions for LTV_IFCTL */
9157 +#define LTV_IM (1 << 15)
9158 +#define LTV_NMD (1 << 14)
9159 +#define LTV_SSMD (1 << 13)
9160 +#define LTV_REV (1 << 7)
9161 +#define LTV_NL(x) (((x) & 0x001f) << 0)
9163 +/* Bit definitions for LTV_DATACTL */
9164 +#define LTV_DS_SAME (0 << 12)
9165 +#define LTV_DS_D_TO_S (1 << 12)
9166 +#define LTV_DS_S_TO_D (2 << 12)
9167 +#define LTV_CHS_384 (0 << 9)
9168 +#define LTV_CHS_480 (1 << 9)
9169 +#define LTV_CHS_492 (2 << 9)
9170 +#define LTV_DF_RGB (0 << 6)
9171 +#define LTV_DF_RGBX (1 << 6)
9172 +#define LTV_DF_XRGB (2 << 6)
9173 +#define LTV_RGB_RGB (0 << 2)
9174 +#define LTV_RGB_BGR (1 << 2)
9175 +#define LTV_RGB_GRB (2 << 2)
9176 +#define LTV_RGB_RBG (3 << 2)
9178 +/* Bit definitions for LTV_ENTRY_MODE */
9179 +#define LTV_VSPL_ACTIVE_LOW (0 << 15)
9180 +#define LTV_VSPL_ACTIVE_HIGH (1 << 15)
9181 +#define LTV_HSPL_ACTIVE_LOW (0 << 14)
9182 +#define LTV_HSPL_ACTIVE_HIGH (1 << 14)
9183 +#define LTV_DPL_SAMPLE_RISING (0 << 13)
9184 +#define LTV_DPL_SAMPLE_FALLING (1 << 13)
9185 +#define LTV_EPL_ACTIVE_LOW (0 << 12)
9186 +#define LTV_EPL_ACTIVE_HIGH (1 << 12)
9187 +#define LTV_SS_LEFT_TO_RIGHT (0 << 8)
9188 +#define LTV_SS_RIGHT_TO_LEFT (1 << 8)
9189 +#define LTV_STB (1 << 1)
9191 +/* Bit definitions for LTV_GATECTL1 */
9192 +#define LTV_CLW(x) (((x) & 0x0007) << 12)
9193 +#define LTV_GAON (1 << 5)
9194 +#define LTV_SDR (1 << 3)
9196 +/* Bit definitions for LTV_GATECTL2 */
9197 +#define LTV_NW_INV_FRAME (0 << 14)
9198 +#define LTV_NW_INV_1LINE (1 << 14)
9199 +#define LTV_NW_INV_2LINE (2 << 14)
9200 +#define LTV_DSC (1 << 12)
9201 +#define LTV_GIF (1 << 8)
9202 +#define LTV_FHN (1 << 7)
9203 +#define LTV_FTI(x) (((x) & 0x0003) << 4)
9204 +#define LTV_FWI(x) (((x) & 0x0003) << 0)
9206 +/* Bit definitions for LTV_SOTCTL */
9207 +#define LTV_SDT(x) (((x) & 0x0007) << 10)
9208 +#define LTV_EQ(x) (((x) & 0x0007) << 2)
9210 +/* Bit definitions for LTV_PWRCTL1 */
9211 +#define LTV_VCOM_DISABLE (1 << 14)
9212 +#define LTV_VCOMOUT_ENABLE (1 << 11)
9213 +#define LTV_POWER_ON (1 << 9)
9214 +#define LTV_DRIVE_CURRENT(x) (((x) & 0x0007) << 4) /* 0=off, 5=max */
9215 +#define LTV_SUPPLY_CURRENT(x) (((x) & 0x0007) << 0) /* 0=off, 5=max */
9217 +/* Bit definitions for LTV_PWRCTL2 */
9218 +#define LTV_VCOML_ENABLE (1 << 13)
9219 +#define LTV_VCOML_VOLTAGE(x) (((x) & 0x001f) << 8) /* 0=1V, 31=-1V */
9220 +#define LTV_VCOMH_VOLTAGE(x) (((x) & 0x001f) << 0) /* 0=3V, 31=4.5V */
9222 +#endif /* __LTV350QV_H */
9223 diff --git a/include/asm-avr32/arch-at32ap/board.h b/include/asm-avr32/arch-at32ap/board.h
9224 index 0215965..e1318e0 100644
9225 --- a/include/asm-avr32/arch-at32ap/board.h
9226 +++ b/include/asm-avr32/arch-at32ap/board.h
9229 #include <linux/types.h>
9231 +#define GPIO_PIN_NONE (-1)
9233 /* Add basic devices: system manager, interrupt controller, portmuxes, etc. */
9234 void at32_add_system_devices(void);
9236 @@ -31,11 +33,26 @@ struct spi_board_info;
9237 struct platform_device *
9238 at32_add_device_spi(unsigned int id, struct spi_board_info *b, unsigned int n);
9240 +struct platform_device *at32_add_device_twi(unsigned int id);
9242 +struct mci_platform_data {
9246 +struct platform_device *
9247 +at32_add_device_mci(unsigned int id, struct mci_platform_data *data);
9249 struct atmel_lcdfb_info;
9250 struct platform_device *
9251 at32_add_device_lcdc(unsigned int id, struct atmel_lcdfb_info *data,
9252 unsigned long fbmem_start, unsigned long fbmem_len);
9254 +struct usba_platform_data {
9257 +struct platform_device *
9258 +at32_add_device_usba(unsigned int id, struct usba_platform_data *data);
9260 /* depending on what's hooked up, not all SSC pins will be used */
9261 #define ATMEL_SSC_TK 0x01
9262 #define ATMEL_SSC_TF 0x02
9263 @@ -50,4 +67,7 @@ at32_add_device_lcdc(unsigned int id, struct atmel_lcdfb_info *data,
9264 struct platform_device *
9265 at32_add_device_ssc(unsigned int id, unsigned int flags);
9267 +struct platform_device *at32_add_device_ac97c(unsigned int id);
9268 +struct platform_device *at32_add_device_abdac(unsigned int id);
9270 #endif /* __ASM_ARCH_BOARD_H */
9271 diff --git a/include/asm-avr32/arch-at32ap/portmux.h b/include/asm-avr32/arch-at32ap/portmux.h
9272 index 9930871..135e034 100644
9273 --- a/include/asm-avr32/arch-at32ap/portmux.h
9274 +++ b/include/asm-avr32/arch-at32ap/portmux.h
9276 #define AT32_GPIOF_OUTPUT 0x00000002 /* (OUT) Enable output driver */
9277 #define AT32_GPIOF_HIGH 0x00000004 /* (OUT) Set output high */
9278 #define AT32_GPIOF_DEGLITCH 0x00000008 /* (IN) Filter glitches */
9279 +#define AT32_GPIOF_MULTIDRV 0x00000010 /* Enable multidriver option */
9281 void at32_select_periph(unsigned int pin, unsigned int periph,
9282 unsigned long flags);
9283 void at32_select_gpio(unsigned int pin, unsigned long flags);
9284 void at32_reserve_pin(unsigned int pin);
9286 +#ifdef CONFIG_GPIO_DEV
9288 +/* Gang allocators and accessors; used by the GPIO /dev driver */
9289 +int at32_gpio_port_is_valid(unsigned int port);
9290 +int at32_select_gpio_pins(unsigned int port, u32 pins, u32 oe_mask);
9291 +void at32_deselect_pins(unsigned int port, u32 pins);
9293 +u32 at32_gpio_get_value_multiple(unsigned int port, u32 pins);
9294 +void at32_gpio_set_value_multiple(unsigned int port, u32 value, u32 mask);
9296 +#endif /* CONFIG_GPIO_DEV */
9298 #endif /* __ASM_ARCH_PORTMUX_H__ */
9299 diff --git a/include/asm-avr32/arch-at32ap/smc.h b/include/asm-avr32/arch-at32ap/smc.h
9300 index 07152b7..c98eea4 100644
9301 --- a/include/asm-avr32/arch-at32ap/smc.h
9302 +++ b/include/asm-avr32/arch-at32ap/smc.h
9305 * All timing parameters are in nanoseconds.
9307 +struct smc_timing {
9308 + /* Delay from address valid to assertion of given strobe */
9309 + int ncs_read_setup;
9311 + int ncs_write_setup;
9314 + /* Pulse length of given strobe */
9315 + int ncs_read_pulse;
9317 + int ncs_write_pulse;
9320 + /* Total cycle length of given operation */
9324 + /* Minimal recovery times, will extend cycle if needed */
9325 + int ncs_read_recover;
9327 + int ncs_write_recover;
9332 + * All timing parameters are in clock cycles.
9336 /* Delay from address valid to assertion of given strobe */
9337 - u16 ncs_read_setup;
9339 - u16 ncs_write_setup;
9341 + u8 ncs_read_setup;
9343 + u8 ncs_write_setup;
9346 /* Pulse length of given strobe */
9347 - u16 ncs_read_pulse;
9349 - u16 ncs_write_pulse;
9351 + u8 ncs_read_pulse;
9353 + u8 ncs_write_pulse;
9356 /* Total cycle length of given operation */
9362 /* Bus width in bytes */
9364 @@ -76,6 +104,9 @@ struct smc_config {
9365 unsigned int tdf_mode:1;
9368 +extern void smc_set_timing(struct smc_config *config,
9369 + const struct smc_timing *timing);
9371 extern int smc_set_configuration(int cs, const struct smc_config *config);
9372 extern struct smc_config *smc_get_configuration(int cs);
9374 diff --git a/include/asm-avr32/dma-controller.h b/include/asm-avr32/dma-controller.h
9375 new file mode 100644
9376 index 0000000..56a4965
9378 +++ b/include/asm-avr32/dma-controller.h
9381 + * Copyright (C) 2005-2006 Atmel Corporation
9383 + * This program is free software; you can redistribute it and/or modify
9384 + * it under the terms of the GNU General Public License version 2 as
9385 + * published by the Free Software Foundation.
9387 +#ifndef __ASM_AVR32_DMA_CONTROLLER_H
9388 +#define __ASM_AVR32_DMA_CONTROLLER_H
9390 +#include <linux/device.h>
9392 +#define DMA_DIR_MEM_TO_MEM 0x0000
9393 +#define DMA_DIR_MEM_TO_PERIPH 0x0001
9394 +#define DMA_DIR_PERIPH_TO_MEM 0x0002
9395 +#define DMA_DIR_PERIPH_TO_PERIPH 0x0003
9397 +#define DMA_WIDTH_8BIT 0
9398 +#define DMA_WIDTH_16BIT 1
9399 +#define DMA_WIDTH_32BIT 2
9401 +struct dma_request {
9402 + struct dma_controller *dmac;
9403 + struct list_head list;
9405 + unsigned short channel;
9407 + void (*xfer_complete)(struct dma_request *req);
9408 + void (*block_complete)(struct dma_request *req);
9409 + void (*error)(struct dma_request *req);
9412 +struct dma_request_sg {
9413 + struct dma_request req;
9416 + struct scatterlist *sg;
9417 + unsigned long block_size;
9418 + unsigned int nr_blocks;
9420 + dma_addr_t data_reg;
9421 + unsigned short periph_id;
9423 + unsigned char direction;
9424 + unsigned char width;
9426 +#define to_dma_request_sg(_req) \
9427 + container_of(_req, struct dma_request_sg, req)
9429 +struct dma_request_cyclic {
9430 + struct dma_request req;
9433 + unsigned long buffer_size;
9435 + dma_addr_t buffer_start;
9436 + dma_addr_t data_reg;
9438 + unsigned short periph_id;
9439 + unsigned char direction;
9440 + unsigned char width;
9444 +#define to_dma_request_cyclic(_req) \
9445 + container_of(_req, struct dma_request_cyclic, req)
9447 +struct dma_request_memcpy {
9448 + struct dma_request req;
9450 + dma_addr_t src_addr;
9451 + unsigned int src_width;
9452 + unsigned int src_stride;
9454 + dma_addr_t dst_addr;
9455 + unsigned int dst_width;
9456 + unsigned int dst_stride;
9460 + unsigned short src_reverse:1;
9461 + unsigned short dst_reverse:1;
9463 +#define to_dma_request_memcpy(_req) \
9464 + container_of(_req, struct dma_request_memcpy, req)
9466 +struct dma_controller {
9467 + struct list_head list;
9469 + struct device *dev;
9471 + int (*alloc_channel)(struct dma_controller *dmac);
9472 + void (*release_channel)(struct dma_controller *dmac,
9474 + int (*prepare_request_sg)(struct dma_controller *dmac,
9475 + struct dma_request_sg *req);
9476 + int (*prepare_request_cyclic)(struct dma_controller *dmac,
9477 + struct dma_request_cyclic *req);
9478 + int (*prepare_request_memcpy)(struct dma_controller *dmac,
9479 + struct dma_request_memcpy *req);
9480 + int (*start_request)(struct dma_controller *dmac,
9481 + unsigned int channel);
9482 + int (*stop_request)(struct dma_controller *dmac,
9483 + unsigned int channel);
9484 + dma_addr_t (*get_current_pos)(struct dma_controller *dmac,
9485 + unsigned int channel);
9489 +dma_alloc_channel(struct dma_controller *dmac)
9491 + return dmac->alloc_channel(dmac);
9495 +dma_release_channel(struct dma_controller *dmac, int chan)
9497 + dmac->release_channel(dmac, chan);
9501 +dma_prepare_request_sg(struct dma_controller *dmac,
9502 + struct dma_request_sg *req)
9504 + return dmac->prepare_request_sg(dmac, req);
9508 +dma_prepare_request_cyclic(struct dma_controller *dmac,
9509 + struct dma_request_cyclic *req)
9511 + return dmac->prepare_request_cyclic(dmac, req);
9515 +dma_prepare_request_memcpy(struct dma_controller *dmac,
9516 + struct dma_request_memcpy *req)
9518 + return dmac->prepare_request_memcpy(dmac, req);
9522 +dma_start_request(struct dma_controller *dmac,
9523 + unsigned int channel)
9525 + return dmac->start_request(dmac, channel);
9529 +dma_stop_request(struct dma_controller *dmac,
9530 + unsigned int channel)
9532 + return dmac->stop_request(dmac, channel);
9535 +static inline dma_addr_t
9536 +dma_get_current_pos(struct dma_controller *dmac,
9537 + unsigned int channel)
9539 + return dmac->get_current_pos(dmac, channel);
9542 +extern int register_dma_controller(struct dma_controller *dmac);
9543 +extern struct dma_controller *find_dma_controller(int id);
9545 +#endif /* __ASM_AVR32_DMA_CONTROLLER_H */
9546 diff --git a/include/asm-avr32/dma-mapping.h b/include/asm-avr32/dma-mapping.h
9547 index 21bb60b..81e3426 100644
9548 --- a/include/asm-avr32/dma-mapping.h
9549 +++ b/include/asm-avr32/dma-mapping.h
9550 @@ -264,7 +264,11 @@ static inline void
9551 dma_sync_single_for_cpu(struct device *dev, dma_addr_t dma_handle,
9552 size_t size, enum dma_data_direction direction)
9554 - dma_cache_sync(dev, bus_to_virt(dma_handle), size, direction);
9556 + * No need to do anything since the CPU isn't supposed to
9557 + * touch this memory after we flushed it at mapping- or
9558 + * sync-for-device time.
9563 @@ -309,12 +313,11 @@ static inline void
9564 dma_sync_sg_for_cpu(struct device *dev, struct scatterlist *sg,
9565 int nents, enum dma_data_direction direction)
9569 - for (i = 0; i < nents; i++) {
9570 - dma_cache_sync(dev, page_address(sg[i].page) + sg[i].offset,
9571 - sg[i].length, direction);
9574 + * No need to do anything since the CPU isn't supposed to
9575 + * touch this memory after we flushed it at mapping- or
9576 + * sync-for-device time.
9581 diff --git a/include/asm-avr32/system.h b/include/asm-avr32/system.h
9582 index a8236ba..dc2d527 100644
9583 --- a/include/asm-avr32/system.h
9584 +++ b/include/asm-avr32/system.h
9585 @@ -73,11 +73,16 @@ extern struct task_struct *__switch_to(struct task_struct *,
9587 extern void __xchg_called_with_bad_pointer(void);
9590 -extern unsigned long __builtin_xchg(void *ptr, unsigned long x);
9592 +static inline unsigned long xchg_u32(u32 val, volatile u32 *m)
9596 -#define xchg_u32(val, m) __builtin_xchg((void *)m, val)
9597 + asm volatile("xchg %[ret], %[m], %[val]"
9598 + : [ret] "=&r"(ret), "=m"(*m)
9599 + : "m"(*m), [m] "r"(m), [val] "r"(val)
9604 static inline unsigned long __xchg(unsigned long x,
9606 diff --git a/include/asm-avr32/unistd.h b/include/asm-avr32/unistd.h
9607 index 3b4e35b..de09009 100644
9608 --- a/include/asm-avr32/unistd.h
9609 +++ b/include/asm-avr32/unistd.h
9610 @@ -303,6 +303,19 @@
9612 #define NR_syscalls 282
9615 +#define __IGNORE_uselib
9616 +#define __IGNORE_mmap
9619 +#define __IGNORE_mbind
9620 +#define __IGNORE_get_mempolicy
9621 +#define __IGNORE_set_mempolicy
9622 +#define __IGNORE_migrate_pages
9623 +#define __IGNORE_move_pages
9626 +#define __IGNORE_getcpu
9628 #define __ARCH_WANT_IPC_PARSE_VERSION
9629 #define __ARCH_WANT_STAT64
9630 diff --git a/include/linux/atmel-ssc.h b/include/linux/atmel-ssc.h
9631 new file mode 100644
9632 index 0000000..0602339
9634 +++ b/include/linux/atmel-ssc.h
9636 +#ifndef __INCLUDE_ATMEL_SSC_H
9637 +#define __INCLUDE_ATMEL_SSC_H
9639 +#include <linux/platform_device.h>
9640 +#include <linux/list.h>
9642 +struct ssc_device {
9643 + struct list_head list;
9644 + void __iomem *regs;
9645 + struct platform_device *pdev;
9651 +struct ssc_device * __must_check ssc_request(unsigned int ssc_num);
9652 +void ssc_free(struct ssc_device *ssc);
9654 +/* SSC register offsets */
9656 +/* SSC Control Register */
9657 +#define SSC_CR 0x00000000
9658 +#define SSC_CR_RXDIS_SIZE 1
9659 +#define SSC_CR_RXDIS_OFFSET 1
9660 +#define SSC_CR_RXEN_SIZE 1
9661 +#define SSC_CR_RXEN_OFFSET 0
9662 +#define SSC_CR_SWRST_SIZE 1
9663 +#define SSC_CR_SWRST_OFFSET 15
9664 +#define SSC_CR_TXDIS_SIZE 1
9665 +#define SSC_CR_TXDIS_OFFSET 9
9666 +#define SSC_CR_TXEN_SIZE 1
9667 +#define SSC_CR_TXEN_OFFSET 8
9669 +/* SSC Clock Mode Register */
9670 +#define SSC_CMR 0x00000004
9671 +#define SSC_CMR_DIV_SIZE 12
9672 +#define SSC_CMR_DIV_OFFSET 0
9674 +/* SSC Receive Clock Mode Register */
9675 +#define SSC_RCMR 0x00000010
9676 +#define SSC_RCMR_CKG_SIZE 2
9677 +#define SSC_RCMR_CKG_OFFSET 6
9678 +#define SSC_RCMR_CKI_SIZE 1
9679 +#define SSC_RCMR_CKI_OFFSET 5
9680 +#define SSC_RCMR_CKO_SIZE 3
9681 +#define SSC_RCMR_CKO_OFFSET 2
9682 +#define SSC_RCMR_CKS_SIZE 2
9683 +#define SSC_RCMR_CKS_OFFSET 0
9684 +#define SSC_RCMR_PERIOD_SIZE 8
9685 +#define SSC_RCMR_PERIOD_OFFSET 24
9686 +#define SSC_RCMR_START_SIZE 4
9687 +#define SSC_RCMR_START_OFFSET 8
9688 +#define SSC_RCMR_STOP_SIZE 1
9689 +#define SSC_RCMR_STOP_OFFSET 12
9690 +#define SSC_RCMR_STTDLY_SIZE 8
9691 +#define SSC_RCMR_STTDLY_OFFSET 16
9693 +/* SSC Receive Frame Mode Register */
9694 +#define SSC_RFMR 0x00000014
9695 +#define SSC_RFMR_DATLEN_SIZE 5
9696 +#define SSC_RFMR_DATLEN_OFFSET 0
9697 +#define SSC_RFMR_DATNB_SIZE 4
9698 +#define SSC_RFMR_DATNB_OFFSET 8
9699 +#define SSC_RFMR_FSEDGE_SIZE 1
9700 +#define SSC_RFMR_FSEDGE_OFFSET 24
9701 +#define SSC_RFMR_FSLEN_SIZE 4
9702 +#define SSC_RFMR_FSLEN_OFFSET 16
9703 +#define SSC_RFMR_FSOS_SIZE 4
9704 +#define SSC_RFMR_FSOS_OFFSET 20
9705 +#define SSC_RFMR_LOOP_SIZE 1
9706 +#define SSC_RFMR_LOOP_OFFSET 5
9707 +#define SSC_RFMR_MSBF_SIZE 1
9708 +#define SSC_RFMR_MSBF_OFFSET 7
9710 +/* SSC Transmit Clock Mode Register */
9711 +#define SSC_TCMR 0x00000018
9712 +#define SSC_TCMR_CKG_SIZE 2
9713 +#define SSC_TCMR_CKG_OFFSET 6
9714 +#define SSC_TCMR_CKI_SIZE 1
9715 +#define SSC_TCMR_CKI_OFFSET 5
9716 +#define SSC_TCMR_CKO_SIZE 3
9717 +#define SSC_TCMR_CKO_OFFSET 2
9718 +#define SSC_TCMR_CKS_SIZE 2
9719 +#define SSC_TCMR_CKS_OFFSET 0
9720 +#define SSC_TCMR_PERIOD_SIZE 8
9721 +#define SSC_TCMR_PERIOD_OFFSET 24
9722 +#define SSC_TCMR_START_SIZE 4
9723 +#define SSC_TCMR_START_OFFSET 8
9724 +#define SSC_TCMR_STTDLY_SIZE 8
9725 +#define SSC_TCMR_STTDLY_OFFSET 16
9727 +/* SSC Transmit Frame Mode Register */
9728 +#define SSC_TFMR 0x0000001c
9729 +#define SSC_TFMR_DATDEF_SIZE 1
9730 +#define SSC_TFMR_DATDEF_OFFSET 5
9731 +#define SSC_TFMR_DATLEN_SIZE 5
9732 +#define SSC_TFMR_DATLEN_OFFSET 0
9733 +#define SSC_TFMR_DATNB_SIZE 4
9734 +#define SSC_TFMR_DATNB_OFFSET 8
9735 +#define SSC_TFMR_FSDEN_SIZE 1
9736 +#define SSC_TFMR_FSDEN_OFFSET 23
9737 +#define SSC_TFMR_FSEDGE_SIZE 1
9738 +#define SSC_TFMR_FSEDGE_OFFSET 24
9739 +#define SSC_TFMR_FSLEN_SIZE 4
9740 +#define SSC_TFMR_FSLEN_OFFSET 16
9741 +#define SSC_TFMR_FSOS_SIZE 3
9742 +#define SSC_TFMR_FSOS_OFFSET 20
9743 +#define SSC_TFMR_MSBF_SIZE 1
9744 +#define SSC_TFMR_MSBF_OFFSET 7
9746 +/* SSC Receive Hold Register */
9747 +#define SSC_RHR 0x00000020
9748 +#define SSC_RHR_RDAT_SIZE 32
9749 +#define SSC_RHR_RDAT_OFFSET 0
9751 +/* SSC Transmit Hold Register */
9752 +#define SSC_THR 0x00000024
9753 +#define SSC_THR_TDAT_SIZE 32
9754 +#define SSC_THR_TDAT_OFFSET 0
9756 +/* SSC Receive Sync. Holding Register */
9757 +#define SSC_RSHR 0x00000030
9758 +#define SSC_RSHR_RSDAT_SIZE 16
9759 +#define SSC_RSHR_RSDAT_OFFSET 0
9761 +/* SSC Transmit Sync. Holding Register */
9762 +#define SSC_TSHR 0x00000034
9763 +#define SSC_TSHR_TSDAT_SIZE 16
9764 +#define SSC_TSHR_RSDAT_OFFSET 0
9766 +/* SSC Receive Compare 0 Register */
9767 +#define SSC_RC0R 0x00000038
9768 +#define SSC_RC0R_CP0_SIZE 16
9769 +#define SSC_RC0R_CP0_OFFSET 0
9771 +/* SSC Receive Compare 1 Register */
9772 +#define SSC_RC1R 0x0000003c
9773 +#define SSC_RC1R_CP1_SIZE 16
9774 +#define SSC_RC1R_CP1_OFFSET 0
9776 +/* SSC Status Register */
9777 +#define SSC_SR 0x00000040
9778 +#define SSC_SR_CP0_SIZE 1
9779 +#define SSC_SR_CP0_OFFSET 8
9780 +#define SSC_SR_CP1_SIZE 1
9781 +#define SSC_SR_CP1_OFFSET 9
9782 +#define SSC_SR_ENDRX_SIZE 1
9783 +#define SSC_SR_ENDRX_OFFSET 6
9784 +#define SSC_SR_ENDTX_SIZE 1
9785 +#define SSC_SR_ENDTX_OFFSET 2
9786 +#define SSC_SR_OVRUN_SIZE 1
9787 +#define SSC_SR_OVRUN_OFFSET 5
9788 +#define SSC_SR_RXBUFF_SIZE 1
9789 +#define SSC_SR_RXBUFF_OFFSET 7
9790 +#define SSC_SR_RXEN_SIZE 1
9791 +#define SSC_SR_RXEN_OFFSET 17
9792 +#define SSC_SR_RXRDY_SIZE 1
9793 +#define SSC_SR_RXRDY_OFFSET 4
9794 +#define SSC_SR_RXSYN_SIZE 1
9795 +#define SSC_SR_RXSYN_OFFSET 11
9796 +#define SSC_SR_TXBUFE_SIZE 1
9797 +#define SSC_SR_TXBUFE_OFFSET 3
9798 +#define SSC_SR_TXEMPTY_SIZE 1
9799 +#define SSC_SR_TXEMPTY_OFFSET 1
9800 +#define SSC_SR_TXEN_SIZE 1
9801 +#define SSC_SR_TXEN_OFFSET 16
9802 +#define SSC_SR_TXRDY_SIZE 1
9803 +#define SSC_SR_TXRDY_OFFSET 0
9804 +#define SSC_SR_TXSYN_SIZE 1
9805 +#define SSC_SR_TXSYN_OFFSET 10
9807 +/* SSC Interrupt Enable Register */
9808 +#define SSC_IER 0x00000044
9809 +#define SSC_IER_CP0_SIZE 1
9810 +#define SSC_IER_CP0_OFFSET 8
9811 +#define SSC_IER_CP1_SIZE 1
9812 +#define SSC_IER_CP1_OFFSET 9
9813 +#define SSC_IER_ENDRX_SIZE 1
9814 +#define SSC_IER_ENDRX_OFFSET 6
9815 +#define SSC_IER_ENDTX_SIZE 1
9816 +#define SSC_IER_ENDTX_OFFSET 2
9817 +#define SSC_IER_OVRUN_SIZE 1
9818 +#define SSC_IER_OVRUN_OFFSET 5
9819 +#define SSC_IER_RXBUFF_SIZE 1
9820 +#define SSC_IER_RXBUFF_OFFSET 7
9821 +#define SSC_IER_RXRDY_SIZE 1
9822 +#define SSC_IER_RXRDY_OFFSET 4
9823 +#define SSC_IER_RXSYN_SIZE 1
9824 +#define SSC_IER_RXSYN_OFFSET 11
9825 +#define SSC_IER_TXBUFE_SIZE 1
9826 +#define SSC_IER_TXBUFE_OFFSET 3
9827 +#define SSC_IER_TXEMPTY_SIZE 1
9828 +#define SSC_IER_TXEMPTY_OFFSET 1
9829 +#define SSC_IER_TXRDY_SIZE 1
9830 +#define SSC_IER_TXRDY_OFFSET 0
9831 +#define SSC_IER_TXSYN_SIZE 1
9832 +#define SSC_IER_TXSYN_OFFSET 10
9834 +/* SSC Interrupt Disable Register */
9835 +#define SSC_IDR 0x00000048
9836 +#define SSC_IDR_CP0_SIZE 1
9837 +#define SSC_IDR_CP0_OFFSET 8
9838 +#define SSC_IDR_CP1_SIZE 1
9839 +#define SSC_IDR_CP1_OFFSET 9
9840 +#define SSC_IDR_ENDRX_SIZE 1
9841 +#define SSC_IDR_ENDRX_OFFSET 6
9842 +#define SSC_IDR_ENDTX_SIZE 1
9843 +#define SSC_IDR_ENDTX_OFFSET 2
9844 +#define SSC_IDR_OVRUN_SIZE 1
9845 +#define SSC_IDR_OVRUN_OFFSET 5
9846 +#define SSC_IDR_RXBUFF_SIZE 1
9847 +#define SSC_IDR_RXBUFF_OFFSET 7
9848 +#define SSC_IDR_RXRDY_SIZE 1
9849 +#define SSC_IDR_RXRDY_OFFSET 4
9850 +#define SSC_IDR_RXSYN_SIZE 1
9851 +#define SSC_IDR_RXSYN_OFFSET 11
9852 +#define SSC_IDR_TXBUFE_SIZE 1
9853 +#define SSC_IDR_TXBUFE_OFFSET 3
9854 +#define SSC_IDR_TXEMPTY_SIZE 1
9855 +#define SSC_IDR_TXEMPTY_OFFSET 1
9856 +#define SSC_IDR_TXRDY_SIZE 1
9857 +#define SSC_IDR_TXRDY_OFFSET 0
9858 +#define SSC_IDR_TXSYN_SIZE 1
9859 +#define SSC_IDR_TXSYN_OFFSET 10
9861 +/* SSC Interrupt Mask Register */
9862 +#define SSC_IMR 0x0000004c
9863 +#define SSC_IMR_CP0_SIZE 1
9864 +#define SSC_IMR_CP0_OFFSET 8
9865 +#define SSC_IMR_CP1_SIZE 1
9866 +#define SSC_IMR_CP1_OFFSET 9
9867 +#define SSC_IMR_ENDRX_SIZE 1
9868 +#define SSC_IMR_ENDRX_OFFSET 6
9869 +#define SSC_IMR_ENDTX_SIZE 1
9870 +#define SSC_IMR_ENDTX_OFFSET 2
9871 +#define SSC_IMR_OVRUN_SIZE 1
9872 +#define SSC_IMR_OVRUN_OFFSET 5
9873 +#define SSC_IMR_RXBUFF_SIZE 1
9874 +#define SSC_IMR_RXBUFF_OFFSET 7
9875 +#define SSC_IMR_RXRDY_SIZE 1
9876 +#define SSC_IMR_RXRDY_OFFSET 4
9877 +#define SSC_IMR_RXSYN_SIZE 1
9878 +#define SSC_IMR_RXSYN_OFFSET 11
9879 +#define SSC_IMR_TXBUFE_SIZE 1
9880 +#define SSC_IMR_TXBUFE_OFFSET 3
9881 +#define SSC_IMR_TXEMPTY_SIZE 1
9882 +#define SSC_IMR_TXEMPTY_OFFSET 1
9883 +#define SSC_IMR_TXRDY_SIZE 1
9884 +#define SSC_IMR_TXRDY_OFFSET 0
9885 +#define SSC_IMR_TXSYN_SIZE 1
9886 +#define SSC_IMR_TXSYN_OFFSET 10
9888 +/* SSC PDC Receive Pointer Register */
9889 +#define SSC_PDC_RPR 0x00000100
9891 +/* SSC PDC Receive Counter Register */
9892 +#define SSC_PDC_RCR 0x00000104
9894 +/* SSC PDC Transmit Pointer Register */
9895 +#define SSC_PDC_TPR 0x00000108
9897 +/* SSC PDC Receive Next Pointer Register */
9898 +#define SSC_PDC_RNPR 0x00000110
9900 +/* SSC PDC Receive Next Counter Register */
9901 +#define SSC_PDC_RNCR 0x00000114
9903 +/* SSC PDC Transmit Counter Register */
9904 +#define SSC_PDC_TCR 0x0000010c
9906 +/* SSC PDC Transmit Next Pointer Register */
9907 +#define SSC_PDC_TNPR 0x00000118
9909 +/* SSC PDC Transmit Next Counter Register */
9910 +#define SSC_PDC_TNCR 0x0000011c
9912 +/* SSC PDC Transfer Control Register */
9913 +#define SSC_PDC_PTCR 0x00000120
9914 +#define SSC_PDC_PTCR_RXTDIS_SIZE 1
9915 +#define SSC_PDC_PTCR_RXTDIS_OFFSET 1
9916 +#define SSC_PDC_PTCR_RXTEN_SIZE 1
9917 +#define SSC_PDC_PTCR_RXTEN_OFFSET 0
9918 +#define SSC_PDC_PTCR_TXTDIS_SIZE 1
9919 +#define SSC_PDC_PTCR_TXTDIS_OFFSET 9
9920 +#define SSC_PDC_PTCR_TXTEN_SIZE 1
9921 +#define SSC_PDC_PTCR_TXTEN_OFFSET 8
9923 +/* SSC PDC Transfer Status Register */
9924 +#define SSC_PDC_PTSR 0x00000124
9925 +#define SSC_PDC_PTSR_RXTEN_SIZE 1
9926 +#define SSC_PDC_PTSR_RXTEN_OFFSET 0
9927 +#define SSC_PDC_PTSR_TXTEN_SIZE 1
9928 +#define SSC_PDC_PTSR_TXTEN_OFFSET 8
9930 +/* Bit manipulation macros */
9931 +#define SSC_BIT(name) \
9932 + (1 << SSC_##name##_OFFSET)
9933 +#define SSC_BF(name, value) \
9934 + (((value) & ((1 << SSC_##name##_SIZE) - 1)) \
9935 + << SSC_##name##_OFFSET)
9936 +#define SSC_BFEXT(name, value) \
9937 + (((value) >> SSC_##name##_OFFSET) \
9938 + & ((1 << SSC_##name##_SIZE) - 1))
9939 +#define SSC_BFINS(name, value, old) \
9940 + (((old) & ~(((1 << SSC_##name##_SIZE) - 1) \
9941 + << SSC_##name##_OFFSET)) | SSC_BF(name, value))
9943 +/* Register access macros */
9944 +#define ssc_readl(base, reg) __raw_readl(base + SSC_##reg)
9945 +#define ssc_writel(base, reg, value) __raw_writel((value), base + SSC_##reg)
9947 +#endif /* __INCLUDE_ATMEL_SSC_H */
9948 diff --git a/include/linux/spi/at73c213.h b/include/linux/spi/at73c213.h
9949 new file mode 100644
9950 index 0000000..0f20a70
9952 +++ b/include/linux/spi/at73c213.h
9955 + * Board-specific data used to set up AT73c213 audio DAC driver.
9958 +#ifndef __LINUX_SPI_AT73C213_H
9959 +#define __LINUX_SPI_AT73C213_H
9962 + * at73c213_board_info - how the external DAC is wired to the device.
9964 + * @ssc_id: SSC platform_driver id the DAC shall use to stream the audio.
9965 + * @dac_clk: the external clock used to provide master clock to the DAC.
9966 + * @shortname: a short discription for the DAC, seen by userspace tools.
9968 + * This struct contains the configuration of the hardware connection to the
9969 + * external DAC. The DAC needs a master clock and a I2S audio stream. It also
9970 + * provides a name which is used to identify it in userspace tools.
9972 +struct at73c213_board_info {
9974 + struct clk *dac_clk;
9975 + char shortname[32];
9978 +#endif /* __LINUX_SPI_AT73C213_H */
9979 diff --git a/scripts/checkstack.pl b/scripts/checkstack.pl
9980 index f7844f6..6631586 100755
9981 --- a/scripts/checkstack.pl
9982 +++ b/scripts/checkstack.pl
9984 # sh64 port by Paul Mundt
9985 # Random bits by Matt Mackall <mpm@selenic.com>
9986 # M68k port by Geert Uytterhoeven and Andreas Schwab
9987 +# AVR32 port by Haavard Skinnemoen <hskinnemoen@atmel.com>
9990 # objdump -d vmlinux | stackcheck.pl [arch]
9991 @@ -37,6 +38,10 @@ my (@stack, $re, $x, $xs);
9992 if ($arch eq 'arm') {
9993 #c0008ffc: e24dd064 sub sp, sp, #100 ; 0x64
9994 $re = qr/.*sub.*sp, sp, #(([0-9]{2}|[3-9])[0-9]{2})/o;
9995 + } elsif ($arch eq 'avr32') {
9996 + #8000008a: 20 1d sub sp,4
9997 + #80000ca8: fa cd 05 b0 sub sp,sp,1456
9998 + $re = qr/^.*sub.*sp.*,([0-9]{1,8})/o;
9999 } elsif ($arch =~ /^i[3456]86$/) {
10000 #c0105234: 81 ec ac 05 00 00 sub $0x5ac,%esp
10001 $re = qr/^.*[as][du][db] \$(0x$x{1,8}),\%esp$/o;
10002 diff --git a/sound/Kconfig b/sound/Kconfig
10003 index e48b9b3..29a9979 100644
10004 --- a/sound/Kconfig
10005 +++ b/sound/Kconfig
10006 @@ -63,6 +63,12 @@ source "sound/aoa/Kconfig"
10008 source "sound/arm/Kconfig"
10010 +source "sound/avr32/Kconfig"
10013 +source "sound/spi/Kconfig"
10016 source "sound/mips/Kconfig"
10018 source "sound/sh/Kconfig"
10019 diff --git a/sound/Makefile b/sound/Makefile
10020 index 3ead922..e655df7 100644
10021 --- a/sound/Makefile
10022 +++ b/sound/Makefile
10023 @@ -5,7 +5,8 @@ obj-$(CONFIG_SOUND) += soundcore.o
10024 obj-$(CONFIG_SOUND_PRIME) += sound_firmware.o
10025 obj-$(CONFIG_SOUND_PRIME) += oss/
10026 obj-$(CONFIG_DMASOUND) += oss/
10027 -obj-$(CONFIG_SND) += core/ i2c/ drivers/ isa/ pci/ ppc/ arm/ sh/ synth/ usb/ sparc/ parisc/ pcmcia/ mips/ soc/
10028 +obj-$(CONFIG_SND) += core/ i2c/ drivers/ isa/ pci/ ppc/ arm/ avr32/ sh/ synth/ usb/ sparc/ spi/ parisc/ pcmcia/ mips/ soc/
10030 obj-$(CONFIG_SND_AOA) += aoa/
10032 # This one must be compilable even if sound is configured out
10033 diff --git a/sound/avr32/Kconfig b/sound/avr32/Kconfig
10034 new file mode 100644
10035 index 0000000..17d1d91
10037 +++ b/sound/avr32/Kconfig
10039 +menu "AVR32 devices"
10040 + depends on SND != n && AVR32
10042 +config SND_ATMEL_AC97
10043 + tristate "Atmel AC97 Controller Driver"
10045 + select SND_AC97_CODEC
10047 + ALSA sound driver for the Atmel AC97 controller.
10050 diff --git a/sound/avr32/Makefile b/sound/avr32/Makefile
10051 new file mode 100644
10052 index 0000000..5d87d0e
10054 +++ b/sound/avr32/Makefile
10056 +snd-atmel-ac97-objs := ac97c.o
10058 +obj-$(CONFIG_SND_ATMEL_AC97) += snd-atmel-ac97.o
10059 diff --git a/sound/avr32/ac97c.c b/sound/avr32/ac97c.c
10060 new file mode 100644
10061 index 0000000..0ec0b1c
10063 +++ b/sound/avr32/ac97c.c
10066 + * Driver for the Atmel AC97 controller
10068 + * Copyright (C) 2005-2007 Atmel Corporation
10070 + * This program is free software; you can redistribute it and/or modify it
10071 + * under the terms of the GNU General Public License version 2 as published by
10072 + * the Free Software Foundation.
10074 +#include <linux/clk.h>
10075 +#include <linux/delay.h>
10076 +#include <linux/dma-mapping.h>
10077 +#include <linux/init.h>
10078 +#include <linux/interrupt.h>
10079 +#include <linux/module.h>
10080 +#include <linux/platform_device.h>
10081 +#include <linux/mutex.h>
10082 +#include <linux/io.h>
10084 +#include <sound/driver.h>
10085 +#include <sound/core.h>
10086 +#include <sound/initval.h>
10087 +#include <sound/pcm.h>
10088 +#include <sound/pcm_params.h>
10089 +#include <sound/ac97_codec.h>
10090 +#include <sound/memalloc.h>
10092 +#include <asm/dma-controller.h>
10094 +#include "ac97c.h"
10096 +/* Serialize access to opened */
10097 +static DEFINE_MUTEX(opened_mutex);
10099 +struct atmel_ac97_dma_info {
10100 + struct dma_request_cyclic req_tx;
10101 + struct dma_request_cyclic req_rx;
10102 + unsigned short rx_periph_id;
10103 + unsigned short tx_periph_id;
10106 +struct atmel_ac97 {
10107 + /* Serialize access to opened */
10109 + void __iomem *regs;
10110 + struct snd_pcm_substream *playback_substream;
10111 + struct snd_pcm_substream *capture_substream;
10112 + struct snd_card *card;
10113 + struct snd_pcm *pcm;
10114 + struct snd_ac97 *ac97;
10115 + struct snd_ac97_bus *ac97_bus;
10119 + unsigned int cur_rate;
10121 + struct platform_device *pdev;
10122 + struct atmel_ac97_dma_info dma;
10125 +#define get_chip(card) ((struct atmel_ac97 *)(card)->private_data)
10127 +#define ac97c_writel(chip, reg, val) \
10128 + __raw_writel((val), (chip)->regs + AC97C_##reg)
10129 +#define ac97c_readl(chip, reg) \
10130 + __raw_readl((chip)->regs + AC97C_##reg)
10135 +static struct snd_pcm_hardware snd_atmel_ac97_playback_hw = {
10136 + .info = (SNDRV_PCM_INFO_INTERLEAVED
10137 + | SNDRV_PCM_INFO_MMAP
10138 + | SNDRV_PCM_INFO_MMAP_VALID
10139 + | SNDRV_PCM_INFO_BLOCK_TRANSFER
10140 + | SNDRV_PCM_INFO_JOINT_DUPLEX),
10141 + .formats = (SNDRV_PCM_FMTBIT_S16_BE
10142 + | SNDRV_PCM_FMTBIT_S16_LE),
10143 + .rates = (SNDRV_PCM_RATE_CONTINUOUS),
10144 + .rate_min = 4000,
10145 + .rate_max = 48000,
10146 + .channels_min = 1,
10147 + .channels_max = 6,
10148 + .buffer_bytes_max = 64*1024,
10149 + .period_bytes_min = 512,
10150 + .period_bytes_max = 4095,
10151 + .periods_min = 8,
10152 + .periods_max = 1024,
10155 +static struct snd_pcm_hardware snd_atmel_ac97_capture_hw = {
10156 + .info = (SNDRV_PCM_INFO_INTERLEAVED
10157 + | SNDRV_PCM_INFO_MMAP
10158 + | SNDRV_PCM_INFO_MMAP_VALID
10159 + | SNDRV_PCM_INFO_BLOCK_TRANSFER
10160 + | SNDRV_PCM_INFO_JOINT_DUPLEX),
10161 + .formats = (SNDRV_PCM_FMTBIT_S16_BE
10162 + | SNDRV_PCM_FMTBIT_S16_LE),
10163 + .rates = (SNDRV_PCM_RATE_CONTINUOUS),
10164 + .rate_min = 4000,
10165 + .rate_max = 48000,
10166 + .channels_min = 1,
10167 + .channels_max = 2,
10168 + .buffer_bytes_max = 64*1024,
10169 + .period_bytes_min = 512,
10170 + .period_bytes_max = 4095,
10171 + .periods_min = 8,
10172 + .periods_max = 1024,
10179 +snd_atmel_ac97_playback_open(struct snd_pcm_substream *substream)
10181 + struct atmel_ac97 *chip = snd_pcm_substream_chip(substream);
10182 + struct snd_pcm_runtime *runtime = substream->runtime;
10184 + mutex_lock(&opened_mutex);
10186 + runtime->hw = snd_atmel_ac97_playback_hw;
10187 + if (chip->cur_rate) {
10188 + runtime->hw.rate_min = chip->cur_rate;
10189 + runtime->hw.rate_max = chip->cur_rate;
10191 + if (chip->cur_format)
10192 + runtime->hw.formats = (1ULL << chip->cur_format);
10193 + mutex_unlock(&opened_mutex);
10194 + chip->playback_substream = substream;
10195 + chip->period = 0;
10200 +snd_atmel_ac97_capture_open(struct snd_pcm_substream *substream)
10202 + struct atmel_ac97 *chip = snd_pcm_substream_chip(substream);
10203 + struct snd_pcm_runtime *runtime = substream->runtime;
10205 + mutex_lock(&opened_mutex);
10207 + runtime->hw = snd_atmel_ac97_capture_hw;
10208 + if (chip->cur_rate) {
10209 + runtime->hw.rate_min = chip->cur_rate;
10210 + runtime->hw.rate_max = chip->cur_rate;
10212 + if (chip->cur_format)
10213 + runtime->hw.formats = (1ULL << chip->cur_format);
10214 + mutex_unlock(&opened_mutex);
10215 + chip->capture_substream = substream;
10216 + chip->period = 0;
10220 +static int snd_atmel_ac97_playback_close(struct snd_pcm_substream *substream)
10222 + struct atmel_ac97 *chip = snd_pcm_substream_chip(substream);
10223 + mutex_lock(&opened_mutex);
10225 + if (!chip->opened) {
10226 + chip->cur_rate = 0;
10227 + chip->cur_format = 0;
10229 + mutex_unlock(&opened_mutex);
10233 +static int snd_atmel_ac97_capture_close(struct snd_pcm_substream *substream)
10235 + struct atmel_ac97 *chip = snd_pcm_substream_chip(substream);
10236 + mutex_lock(&opened_mutex);
10238 + if (!chip->opened) {
10239 + chip->cur_rate = 0;
10240 + chip->cur_format = 0;
10242 + mutex_unlock(&opened_mutex);
10247 +snd_atmel_ac97_playback_hw_params(struct snd_pcm_substream *substream,
10248 + struct snd_pcm_hw_params *hw_params)
10250 + struct atmel_ac97 *chip = snd_pcm_substream_chip(substream);
10253 + err = snd_pcm_lib_malloc_pages(substream,
10254 + params_buffer_bytes(hw_params));
10258 + /* Set restrictions to params */
10259 + mutex_lock(&opened_mutex);
10260 + chip->cur_rate = params_rate(hw_params);
10261 + chip->cur_format = params_format(hw_params);
10262 + mutex_unlock(&opened_mutex);
10268 +snd_atmel_ac97_capture_hw_params(struct snd_pcm_substream *substream,
10269 + struct snd_pcm_hw_params *hw_params)
10271 + struct atmel_ac97 *chip = snd_pcm_substream_chip(substream);
10274 + err = snd_pcm_lib_malloc_pages(substream,
10275 + params_buffer_bytes(hw_params));
10279 + /* Set restrictions to params */
10280 + mutex_lock(&opened_mutex);
10281 + chip->cur_rate = params_rate(hw_params);
10282 + chip->cur_format = params_format(hw_params);
10283 + mutex_unlock(&opened_mutex);
10288 +static int snd_atmel_ac97_playback_hw_free(struct snd_pcm_substream *substream)
10290 + return snd_pcm_lib_free_pages(substream);
10293 +static int snd_atmel_ac97_capture_hw_free(struct snd_pcm_substream *substream)
10296 + return snd_pcm_lib_free_pages(substream);
10299 +static int snd_atmel_ac97_playback_prepare(struct snd_pcm_substream *substream)
10301 + struct atmel_ac97 *chip = snd_pcm_substream_chip(substream);
10302 + struct platform_device *pdev = chip->pdev;
10303 + struct snd_pcm_runtime *runtime = substream->runtime;
10304 + int block_size = frames_to_bytes(runtime, runtime->period_size);
10305 + unsigned long word = 0;
10306 + unsigned long buffer_size = 0;
10308 + dma_sync_single_for_device(&pdev->dev, runtime->dma_addr,
10309 + block_size * 2, DMA_TO_DEVICE);
10311 + /* Assign slots to channels */
10312 + switch (substream->runtime->channels) {
10314 + word |= AC97C_CH_ASSIGN(PCM_LEFT, A);
10317 + /* Assign Left and Right slot to Channel A */
10318 + word |= AC97C_CH_ASSIGN(PCM_LEFT, A)
10319 + | AC97C_CH_ASSIGN(PCM_RIGHT, A);
10322 + /* TODO: support more than two channels */
10326 + ac97c_writel(chip, OCA, word);
10328 + /* Configure sample format and size */
10329 + word = AC97C_CMR_PDCEN | AC97C_CMR_SIZE_16;
10331 + switch (runtime->format) {
10332 + case SNDRV_PCM_FORMAT_S16_LE:
10333 + word |= AC97C_CMR_CEM_LITTLE;
10335 + case SNDRV_PCM_FORMAT_S16_BE: /* fall through */
10337 + word &= ~AC97C_CMR_CEM_LITTLE;
10341 + ac97c_writel(chip, CAMR, word);
10343 + /* Set variable rate if needed */
10344 + if (runtime->rate != 48000) {
10345 + word = ac97c_readl(chip, MR);
10346 + word |= AC97C_MR_VRA;
10347 + ac97c_writel(chip, MR, word);
10349 + /* Clear Variable Rate Bit */
10350 + word = ac97c_readl(chip, MR);
10351 + word &= ~AC97C_MR_VRA;
10352 + ac97c_writel(chip, MR, word);
10356 + snd_ac97_set_rate(chip->ac97, AC97_PCM_FRONT_DAC_RATE, runtime->rate);
10358 + buffer_size = frames_to_bytes(runtime, runtime->period_size) *
10359 + runtime->periods;
10361 + chip->dma.req_tx.buffer_size = buffer_size;
10362 + chip->dma.req_tx.periods = runtime->periods;
10364 + BUG_ON(chip->dma.req_tx.buffer_size !=
10365 + (chip->dma.req_tx.periods *
10366 + frames_to_bytes(runtime, runtime->period_size)));
10368 + chip->dma.req_tx.buffer_start = runtime->dma_addr;
10369 + chip->dma.req_tx.data_reg = (dma_addr_t)(chip->regs + AC97C_CATHR + 2);
10370 + chip->dma.req_tx.periph_id = chip->dma.tx_periph_id;
10371 + chip->dma.req_tx.direction = DMA_DIR_MEM_TO_PERIPH;
10372 + chip->dma.req_tx.width = DMA_WIDTH_16BIT;
10373 + chip->dma.req_tx.dev_id = chip;
10378 +static int snd_atmel_ac97_capture_prepare(struct snd_pcm_substream *substream)
10380 + struct atmel_ac97 *chip = snd_pcm_substream_chip(substream);
10381 + struct platform_device *pdev = chip->pdev;
10382 + struct snd_pcm_runtime *runtime = substream->runtime;
10383 + int block_size = frames_to_bytes(runtime, runtime->period_size);
10384 + unsigned long word = 0;
10385 + unsigned long buffer_size = 0;
10387 + dma_sync_single_for_device(&pdev->dev, runtime->dma_addr,
10388 + block_size * 2, DMA_FROM_DEVICE);
10390 + /* Assign slots to channels */
10391 + switch (substream->runtime->channels) {
10393 + word |= AC97C_CH_ASSIGN(PCM_LEFT, A);
10396 + /* Assign Left and Right slot to Channel A */
10397 + word |= AC97C_CH_ASSIGN(PCM_LEFT, A)
10398 + | AC97C_CH_ASSIGN(PCM_RIGHT, A);
10401 + /* TODO: support more than two channels */
10405 + ac97c_writel(chip, ICA, word);
10407 + /* Configure sample format and size */
10408 + word = AC97C_CMR_PDCEN | AC97C_CMR_SIZE_16;
10410 + switch (runtime->format) {
10411 + case SNDRV_PCM_FORMAT_S16_LE:
10412 + word |= AC97C_CMR_CEM_LITTLE;
10414 + case SNDRV_PCM_FORMAT_S16_BE:
10416 + word &= ~(AC97C_CMR_CEM_LITTLE);
10420 + ac97c_writel(chip, CAMR, word);
10422 + /* Set variable rate if needed */
10423 + if (runtime->rate != 48000) {
10424 + word = ac97c_readl(chip, MR);
10425 + word |= AC97C_MR_VRA;
10426 + ac97c_writel(chip, MR, word);
10428 + /* Clear Variable Rate Bit */
10429 + word = ac97c_readl(chip, MR);
10430 + word &= ~(AC97C_MR_VRA);
10431 + ac97c_writel(chip, MR, word);
10435 + snd_ac97_set_rate(chip->ac97, AC97_PCM_LR_ADC_RATE, runtime->rate);
10437 + buffer_size = frames_to_bytes(runtime, runtime->period_size) *
10438 + runtime->periods;
10440 + chip->dma.req_rx.buffer_size = buffer_size;
10441 + chip->dma.req_rx.periods = runtime->periods;
10443 + BUG_ON(chip->dma.req_rx.buffer_size !=
10444 + (chip->dma.req_rx.periods *
10445 + frames_to_bytes(runtime, runtime->period_size)));
10447 + chip->dma.req_rx.buffer_start = runtime->dma_addr;
10448 + chip->dma.req_rx.data_reg = (dma_addr_t)(chip->regs + AC97C_CARHR + 2);
10449 + chip->dma.req_rx.periph_id = chip->dma.rx_periph_id;
10450 + chip->dma.req_rx.direction = DMA_DIR_PERIPH_TO_MEM;
10451 + chip->dma.req_rx.width = DMA_WIDTH_16BIT;
10452 + chip->dma.req_rx.dev_id = chip;
10458 +snd_atmel_ac97_playback_trigger(struct snd_pcm_substream *substream, int cmd)
10460 + struct atmel_ac97 *chip = snd_pcm_substream_chip(substream);
10461 + unsigned long camr;
10462 + int flags, err = 0;
10464 + spin_lock_irqsave(&chip->lock, flags);
10465 + camr = ac97c_readl(chip, CAMR);
10468 + case SNDRV_PCM_TRIGGER_START:
10469 + err = dma_prepare_request_cyclic(chip->dma.req_tx.req.dmac,
10470 + &chip->dma.req_tx);
10471 + dma_start_request(chip->dma.req_tx.req.dmac,
10472 + chip->dma.req_tx.req.channel);
10473 + camr |= AC97C_CMR_CENA;
10475 + case SNDRV_PCM_TRIGGER_STOP:
10476 + err = dma_stop_request(chip->dma.req_tx.req.dmac,
10477 + chip->dma.req_tx.req.channel);
10478 + if (chip->opened <= 1)
10479 + camr &= ~AC97C_CMR_CENA;
10486 + ac97c_writel(chip, CAMR, camr);
10488 + spin_unlock_irqrestore(&chip->lock, flags);
10493 +snd_atmel_ac97_capture_trigger(struct snd_pcm_substream *substream, int cmd)
10495 + struct atmel_ac97 *chip = snd_pcm_substream_chip(substream);
10496 + unsigned long camr;
10497 + int flags, err = 0;
10499 + spin_lock_irqsave(&chip->lock, flags);
10500 + camr = ac97c_readl(chip, CAMR);
10503 + case SNDRV_PCM_TRIGGER_START:
10504 + err = dma_prepare_request_cyclic(chip->dma.req_rx.req.dmac,
10505 + &chip->dma.req_rx);
10506 + dma_start_request(chip->dma.req_rx.req.dmac,
10507 + chip->dma.req_rx.req.channel);
10508 + camr |= AC97C_CMR_CENA;
10510 + case SNDRV_PCM_TRIGGER_STOP:
10511 + err = dma_stop_request(chip->dma.req_rx.req.dmac,
10512 + chip->dma.req_rx.req.channel);
10513 + mutex_lock(&opened_mutex);
10514 + if (chip->opened <= 1)
10515 + camr &= ~AC97C_CMR_CENA;
10516 + mutex_unlock(&opened_mutex);
10523 + ac97c_writel(chip, CAMR, camr);
10525 + spin_unlock_irqrestore(&chip->lock, flags);
10529 + static snd_pcm_uframes_t
10530 +snd_atmel_ac97_playback_pointer(struct snd_pcm_substream *substream)
10532 + struct atmel_ac97 *chip = snd_pcm_substream_chip(substream);
10533 + struct snd_pcm_runtime *runtime = substream->runtime;
10534 + snd_pcm_uframes_t pos;
10535 + unsigned long bytes;
10537 + bytes = (dma_get_current_pos
10538 + (chip->dma.req_tx.req.dmac,
10539 + chip->dma.req_tx.req.channel) - runtime->dma_addr);
10540 + pos = bytes_to_frames(runtime, bytes);
10541 + if (pos >= runtime->buffer_size)
10542 + pos -= runtime->buffer_size;
10547 + static snd_pcm_uframes_t
10548 +snd_atmel_ac97_capture_pointer(struct snd_pcm_substream *substream)
10550 + struct atmel_ac97 *chip = snd_pcm_substream_chip(substream);
10551 + struct snd_pcm_runtime *runtime = substream->runtime;
10552 + snd_pcm_uframes_t pos;
10553 + unsigned long bytes;
10555 + bytes = (dma_get_current_pos
10556 + (chip->dma.req_rx.req.dmac,
10557 + chip->dma.req_rx.req.channel)
10558 + - runtime->dma_addr);
10559 + pos = bytes_to_frames(runtime, bytes);
10560 + if (pos >= runtime->buffer_size)
10561 + pos -= runtime->buffer_size;
10567 +static struct snd_pcm_ops atmel_ac97_playback_ops = {
10568 + .open = snd_atmel_ac97_playback_open,
10569 + .close = snd_atmel_ac97_playback_close,
10570 + .ioctl = snd_pcm_lib_ioctl,
10571 + .hw_params = snd_atmel_ac97_playback_hw_params,
10572 + .hw_free = snd_atmel_ac97_playback_hw_free,
10573 + .prepare = snd_atmel_ac97_playback_prepare,
10574 + .trigger = snd_atmel_ac97_playback_trigger,
10575 + .pointer = snd_atmel_ac97_playback_pointer,
10578 +static struct snd_pcm_ops atmel_ac97_capture_ops = {
10579 + .open = snd_atmel_ac97_capture_open,
10580 + .close = snd_atmel_ac97_capture_close,
10581 + .ioctl = snd_pcm_lib_ioctl,
10582 + .hw_params = snd_atmel_ac97_capture_hw_params,
10583 + .hw_free = snd_atmel_ac97_capture_hw_free,
10584 + .prepare = snd_atmel_ac97_capture_prepare,
10585 + .trigger = snd_atmel_ac97_capture_trigger,
10586 + .pointer = snd_atmel_ac97_capture_pointer,
10589 +static struct ac97_pcm atmel_ac97_pcm_defs[] __devinitdata = {
10594 + .slots = ((1 << AC97_SLOT_PCM_LEFT)
10595 + | (1 << AC97_SLOT_PCM_RIGHT)
10596 + | (1 << AC97_SLOT_PCM_CENTER)
10597 + | (1 << AC97_SLOT_PCM_SLEFT)
10598 + | (1 << AC97_SLOT_PCM_SRIGHT)
10599 + | (1 << AC97_SLOT_LFE)),
10607 + .slots = ((1 << AC97_SLOT_PCM_LEFT)
10608 + | (1 << AC97_SLOT_PCM_RIGHT)),
10616 + .slots = (1<<AC97_SLOT_MIC),
10621 +static int __devinit snd_atmel_ac97_pcm_new(struct atmel_ac97 *chip)
10623 + struct snd_pcm *pcm;
10626 + err = snd_ac97_pcm_assign(chip->ac97_bus,
10627 + ARRAY_SIZE(atmel_ac97_pcm_defs),
10628 + atmel_ac97_pcm_defs);
10632 + err = snd_pcm_new(chip->card, "Atmel-AC97", 0, 1, 1, &pcm);
10636 + snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK,
10637 + &atmel_ac97_playback_ops);
10639 + snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE,
10640 + &atmel_ac97_capture_ops);
10642 + snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV,
10643 + &chip->pdev->dev,
10644 + 128 * 1024, 128 * 1024);
10646 + pcm->private_data = chip;
10647 + pcm->info_flags = 0;
10648 + strcpy(pcm->name, "Atmel-AC97");
10657 +static int snd_atmel_ac97_mixer_new(struct atmel_ac97 *chip)
10660 + struct snd_ac97_template template;
10662 + memset(&template, 0, sizeof(template));
10663 + template.private_data = chip;
10664 + err = snd_ac97_mixer(chip->ac97_bus, &template, &chip->ac97);
10669 +static void atmel_ac97_error(struct dma_request *_req)
10671 + struct dma_request_cyclic *req = to_dma_request_cyclic(_req);
10672 + struct atmel_ac97 *chip = req->dev_id;
10674 + dev_dbg(&chip->pdev->dev, "DMA Controller error, channel %d\n",
10675 + req->req.channel);
10678 +static void atmel_ac97_block_complete(struct dma_request *_req)
10680 + struct dma_request_cyclic *req = to_dma_request_cyclic(_req);
10681 + struct atmel_ac97 *chip = req->dev_id;
10682 + if (req->periph_id == chip->dma.tx_periph_id)
10683 + snd_pcm_period_elapsed(chip->playback_substream);
10685 + snd_pcm_period_elapsed(chip->capture_substream);
10691 +static void snd_atmel_ac97_write(struct snd_ac97 *ac97, unsigned short reg,
10692 + unsigned short val)
10694 + struct atmel_ac97 *chip = get_chip(ac97);
10695 + unsigned long word;
10696 + int timeout = 40;
10698 + word = (reg & 0x7f) << 16 | val;
10701 + if (ac97c_readl(chip, COSR) & AC97C_CSR_TXRDY) {
10702 + ac97c_writel(chip, COTHR, word);
10706 + } while (--timeout);
10708 + dev_dbg(&chip->pdev->dev, "codec write timeout\n");
10711 +static unsigned short snd_atmel_ac97_read(struct snd_ac97 *ac97,
10712 + unsigned short reg)
10714 + struct atmel_ac97 *chip = get_chip(ac97);
10715 + unsigned long word;
10716 + int timeout = 40;
10719 + word = (0x80 | (reg & 0x7f)) << 16;
10721 + if ((ac97c_readl(chip, COSR) & AC97C_CSR_RXRDY) != 0)
10722 + ac97c_readl(chip, CORHR);
10728 + if ((ac97c_readl(chip, COSR) & AC97C_CSR_TXRDY) != 0) {
10729 + ac97c_writel(chip, COTHR, word);
10733 + } while (--timeout);
10737 + goto retry_write;
10741 + if ((ac97c_readl(chip, COSR) & AC97C_CSR_RXRDY) != 0) {
10742 + unsigned short val = ac97c_readl(chip, CORHR);
10746 + } while (--timeout);
10750 + goto retry_write;
10753 + dev_dbg(&chip->pdev->dev, "codec read timeout\n");
10757 +static void snd_atmel_ac97_reset(struct atmel_ac97 *chip)
10759 + ac97c_writel(chip, MR, AC97C_MR_WRST);
10761 + ac97c_writel(chip, MR, AC97C_MR_ENA);
10764 +static void snd_atmel_ac97_destroy(struct snd_card *card)
10766 + struct atmel_ac97 *chip = get_chip(card);
10769 + iounmap(chip->regs);
10772 + clk_disable(chip->mck);
10773 + clk_put(chip->mck);
10776 + if (chip->dma.req_tx.req.dmac) {
10777 + dma_release_channel(chip->dma.req_tx.req.dmac,
10778 + chip->dma.req_tx.req.channel);
10780 + if (chip->dma.req_rx.req.dmac) {
10781 + dma_release_channel(chip->dma.req_rx.req.dmac,
10782 + chip->dma.req_rx.req.channel);
10786 +static int __devinit snd_atmel_ac97_create(struct snd_card *card,
10787 + struct platform_device *pdev)
10789 + static struct snd_ac97_bus_ops ops = {
10790 + .write = snd_atmel_ac97_write,
10791 + .read = snd_atmel_ac97_read,
10793 + struct atmel_ac97 *chip = get_chip(card);
10794 + struct resource *regs;
10798 + regs = platform_get_resource(pdev, IORESOURCE_MEM, 0);
10802 + mck = clk_get(&pdev->dev, "pclk");
10804 + return PTR_ERR(mck);
10808 + card->private_free = snd_atmel_ac97_destroy;
10810 + spin_lock_init(&chip->lock);
10811 + chip->card = card;
10812 + chip->pdev = pdev;
10814 + chip->regs = ioremap(regs->start, regs->end - regs->start + 1);
10818 + snd_card_set_dev(card, &pdev->dev);
10820 + err = snd_ac97_bus(card, 0, &ops, chip, &chip->ac97_bus);
10825 +static int __devinit snd_atmel_ac97_probe(struct platform_device *pdev)
10828 + struct snd_card *card;
10829 + struct atmel_ac97 *chip;
10833 + mutex_init(&opened_mutex);
10836 + card = snd_card_new(SNDRV_DEFAULT_IDX1, SNDRV_DEFAULT_STR1,
10837 + THIS_MODULE, sizeof(struct atmel_ac97));
10840 + chip = get_chip(card);
10842 + err = snd_atmel_ac97_create(card, pdev);
10844 + goto out_free_card;
10846 + snd_atmel_ac97_reset(chip);
10848 + err = snd_atmel_ac97_mixer_new(chip);
10850 + goto out_free_card;
10852 + err = snd_atmel_ac97_pcm_new(chip);
10854 + goto out_free_card;
10856 + /* TODO: Get this information from the platform device */
10857 + chip->dma.req_tx.req.dmac = find_dma_controller(0);
10858 + if (!chip->dma.req_tx.req.dmac) {
10859 + dev_dbg(&chip->pdev->dev, "DMA controller for TX missing\n");
10861 + goto out_free_card;
10863 + chip->dma.req_rx.req.dmac = find_dma_controller(0);
10864 + if (!chip->dma.req_rx.req.dmac) {
10865 + dev_dbg(&chip->pdev->dev, "DMA controller for RX missing\n");
10867 + goto out_free_card;
10870 + chip->dma.rx_periph_id = 3;
10871 + chip->dma.tx_periph_id = 4;
10873 + ch = dma_alloc_channel(chip->dma.req_tx.req.dmac);
10875 + dev_dbg(&chip->pdev->dev,
10876 + "could not allocate TX DMA channel\n");
10878 + goto out_free_card;
10880 + chip->dma.req_tx.req.channel = ch;
10881 + chip->dma.req_tx.width = DMA_WIDTH_16BIT;
10882 + chip->dma.req_tx.req.block_complete = atmel_ac97_block_complete;
10883 + chip->dma.req_tx.req.error = atmel_ac97_error;
10885 + ch = dma_alloc_channel(chip->dma.req_rx.req.dmac);
10887 + dev_dbg(&chip->pdev->dev,
10888 + "could not allocate RX DMA channel\n");
10890 + goto out_free_card;
10892 + chip->dma.req_rx.req.channel = ch;
10893 + chip->dma.req_rx.width = DMA_WIDTH_16BIT;
10894 + chip->dma.req_rx.req.block_complete = atmel_ac97_block_complete;
10895 + chip->dma.req_rx.req.error = atmel_ac97_error;
10897 + strcpy(card->driver, "atmel_ac97c");
10898 + strcpy(card->shortname, "atmel_ac97c");
10899 + sprintf(card->longname, "Atmel AVR32 AC97 controller");
10901 + err = snd_card_register(card);
10903 + goto out_free_card;
10905 + platform_set_drvdata(pdev, card);
10908 + dev_info(&pdev->dev, "Atmel AVR32 AC97 controller at 0x%p\n",
10914 + snd_card_free(card);
10921 +snd_atmel_ac97_suspend(struct platform_device *pdev, pm_message_t msg)
10923 + struct snd_card *card = platform_get_drvdata(pdev);
10924 + struct atmel_ac97 *chip = card->private_data;
10926 + clk_disable(chip->mck);
10931 +static int snd_atmel_ac97_resume(struct platform_device *pdev)
10933 + struct snd_card *card = dev_get_drvdata(pdev);
10934 + struct atmel_ac97 *chip = card->private_data;
10936 + clk_enable(chip->mck);
10941 +#define snd_atmel_ac97_suspend NULL
10942 +#define snd_atmel_ac97_resume NULL
10945 +static int __devexit snd_atmel_ac97_remove(struct platform_device *pdev)
10947 + struct snd_card *card = platform_get_drvdata(pdev);
10949 + snd_card_free(card);
10950 + platform_set_drvdata(pdev, NULL);
10954 +static struct platform_driver atmel_ac97_driver = {
10955 + .remove = __devexit_p(snd_atmel_ac97_remove),
10957 + .name = "atmel_ac97c",
10959 + .suspend = snd_atmel_ac97_suspend,
10960 + .resume = snd_atmel_ac97_resume,
10963 +static int __init atmel_ac97_init(void)
10965 + return platform_driver_probe(&atmel_ac97_driver,
10966 + snd_atmel_ac97_probe);
10968 +module_init(atmel_ac97_init);
10970 +static void __exit atmel_ac97_exit(void)
10972 + platform_driver_unregister(&atmel_ac97_driver);
10974 +module_exit(atmel_ac97_exit);
10976 +MODULE_LICENSE("GPL");
10977 +MODULE_DESCRIPTION("Driver for Atmel AC97 Controller");
10978 +MODULE_AUTHOR("Haavard Skinnemoen <hskinnemoen@atmel.com>");
10979 diff --git a/sound/avr32/ac97c.h b/sound/avr32/ac97c.h
10980 new file mode 100644
10981 index 0000000..96246e7
10983 +++ b/sound/avr32/ac97c.h
10986 + * Register definitions for the Atmel AC97 Controller.
10988 + * Copyright (C) 2005-2006 Atmel Corporation
10990 + * This program is free software; you can redistribute it and/or modify
10991 + * it under the terms of the GNU General Public License version 2 as
10992 + * published by the Free Software Foundation.
10994 +#ifndef __SOUND_AVR32_AC97C_H
10995 +#define __SOUND_AVR32_AC97C_H
10997 +#define AC97C_MR 0x08
10998 +#define AC97C_ICA 0x10
10999 +#define AC97C_OCA 0x14
11000 +#define AC97C_CARHR 0x20
11001 +#define AC97C_CATHR 0x24
11002 +#define AC97C_CASR 0x28
11003 +#define AC97C_CAMR 0x2c
11004 +#define AC97C_CBRHR 0x30
11005 +#define AC97C_CBTHR 0x34
11006 +#define AC97C_CBSR 0x38
11007 +#define AC97C_CBMR 0x3c
11008 +#define AC97C_CORHR 0x40
11009 +#define AC97C_COTHR 0x44
11010 +#define AC97C_COSR 0x48
11011 +#define AC97C_COMR 0x4c
11012 +#define AC97C_SR 0x50
11013 +#define AC97C_IER 0x54
11014 +#define AC97C_IDR 0x58
11015 +#define AC97C_IMR 0x5c
11016 +#define AC97C_VERSION 0xfc
11018 +#define AC97C_CATPR PDC_TPR
11019 +#define AC97C_CATCR PDC_TCR
11020 +#define AC97C_CATNPR PDC_TNPR
11021 +#define AC97C_CATNCR PDC_TNCR
11022 +#define AC97C_CARPR PDC_RPR
11023 +#define AC97C_CARCR PDC_RCR
11024 +#define AC97C_CARNPR PDC_RNPR
11025 +#define AC97C_CARNCR PDC_RNCR
11026 +#define AC97C_PTCR PDC_PTCR
11028 +#define AC97C_MR_ENA (1 << 0)
11029 +#define AC97C_MR_WRST (1 << 1)
11030 +#define AC97C_MR_VRA (1 << 2)
11032 +#define AC97C_CSR_TXRDY (1 << 0)
11033 +#define AC97C_CSR_UNRUN (1 << 2)
11034 +#define AC97C_CSR_RXRDY (1 << 4)
11035 +#define AC97C_CSR_ENDTX (1 << 10)
11036 +#define AC97C_CSR_ENDRX (1 << 14)
11038 +#define AC97C_CMR_SIZE_20 (0 << 16)
11039 +#define AC97C_CMR_SIZE_18 (1 << 16)
11040 +#define AC97C_CMR_SIZE_16 (2 << 16)
11041 +#define AC97C_CMR_SIZE_10 (3 << 16)
11042 +#define AC97C_CMR_CEM_LITTLE (1 << 18)
11043 +#define AC97C_CMR_CEM_BIG (0 << 18)
11044 +#define AC97C_CMR_CENA (1 << 21)
11045 +#define AC97C_CMR_PDCEN (1 << 22)
11047 +#define AC97C_SR_CAEVT (1 << 3)
11049 +#define AC97C_CH_ASSIGN(slot, channel) \
11050 + (AC97C_CHANNEL_##channel << (3 * (AC97_SLOT_##slot - 3)))
11051 +#define AC97C_CHANNEL_NONE 0x0
11052 +#define AC97C_CHANNEL_A 0x1
11053 +#define AC97C_CHANNEL_B 0x2
11055 +#endif /* __SOUND_AVR32_AC97C_H */
11056 diff --git a/sound/oss/Kconfig b/sound/oss/Kconfig
11057 index af37cd0..e3cc557 100644
11058 --- a/sound/oss/Kconfig
11059 +++ b/sound/oss/Kconfig
11060 @@ -654,3 +654,7 @@ config SOUND_SH_DAC_AUDIO_CHANNEL
11063 depends on SOUND_SH_DAC_AUDIO
11065 +config SOUND_AT32_ABDAC
11066 + tristate "Atmel AT32 Audio Bitstream DAC (ABDAC) support"
11067 + depends on SOUND_PRIME && AVR32
11068 diff --git a/sound/oss/Makefile b/sound/oss/Makefile
11069 index 1200670..fafc246 100644
11070 --- a/sound/oss/Makefile
11071 +++ b/sound/oss/Makefile
11072 @@ -10,6 +10,7 @@ obj-$(CONFIG_SOUND_CS4232) += cs4232.o ad1848.o
11074 # Please leave it as is, cause the link order is significant !
11076 +obj-$(CONFIG_SOUND_AT32_ABDAC) += at32_abdac.o
11077 obj-$(CONFIG_SOUND_SH_DAC_AUDIO) += sh_dac_audio.o
11078 obj-$(CONFIG_SOUND_HAL2) += hal2.o
11079 obj-$(CONFIG_SOUND_AEDSP16) += aedsp16.o
11080 diff --git a/sound/oss/at32_abdac.c b/sound/oss/at32_abdac.c
11081 new file mode 100644
11082 index 0000000..cb997d7
11084 +++ b/sound/oss/at32_abdac.c
11087 + * OSS Sound Driver for the Atmel AT32 on-chip DAC.
11089 + * Copyright (C) 2006 Atmel Corporation
11091 + * This program is free software; you can redistribute it and/or modify
11092 + * it under the terms of the GNU General Public License version 2 as
11093 + * published by the Free Software Foundation.
11095 +#include <linux/clk.h>
11096 +#include <linux/dma-mapping.h>
11097 +#include <linux/fs.h>
11098 +#include <linux/init.h>
11099 +#include <linux/interrupt.h>
11100 +#include <linux/kernel.h>
11101 +#include <linux/module.h>
11102 +#include <linux/platform_device.h>
11103 +#include <linux/sound.h>
11104 +#include <linux/soundcard.h>
11106 +#include <asm/byteorder.h>
11107 +#include <asm/dma-controller.h>
11108 +#include <asm/io.h>
11109 +#include <asm/uaccess.h>
11111 +/* We want to use the "bizarre" swap-bytes-in-each-halfword macro */
11112 +#include <linux/byteorder/swabb.h>
11114 +#include "at32_abdac.h"
11116 +#define DMA_BUFFER_SIZE 32768
11117 +#define DMA_PERIOD_SHIFT 10
11118 +#define DMA_PERIOD_SIZE (1 << DMA_PERIOD_SHIFT)
11119 +#define DMA_WRITE_THRESHOLD DMA_PERIOD_SIZE
11121 +struct sound_settings {
11122 + unsigned int format;
11123 + unsigned int channels;
11124 + unsigned int sample_rate;
11125 + /* log2(bytes per sample) */
11126 + unsigned int input_order;
11131 + void __iomem *regs;
11133 + /* head and tail refer to number of words */
11140 + struct semaphore sem;
11141 + wait_queue_head_t write_wait;
11144 + * Read at most ucount bytes from ubuf, translate to 2-channel
11145 + * signed 16-bit big endian format and write to the DMA buffer
11146 + * as long as there is room left. Return the number of bytes
11147 + * successfully copied from ubuf, or -EFAULT if the first
11148 + * sample from ubuf couldn't be read. This function is not
11149 + * called unless there is room for at least one sample (4
11150 + * bytes) in the DMA buffer.
11152 + ssize_t (*trans)(struct at32_dac *dac, const char __user *ubuf,
11155 + struct sound_settings dsp_settings;
11156 + struct dma_request_cyclic req;
11159 + struct clk *sample_clk;
11160 + struct platform_device *pdev;
11165 +static struct at32_dac *the_dac;
11167 +static inline unsigned int abdac_get_head(struct at32_dac *dac)
11169 + return dac->dma.head & ((DMA_BUFFER_SIZE / 4) - 1);
11172 +static inline unsigned int abdac_get_tail(struct at32_dac *dac)
11174 + return dac->dma.tail & ((DMA_BUFFER_SIZE / 4) - 1);
11177 +static inline unsigned int abdac_dma_space(struct at32_dac *dac)
11179 + unsigned int space;
11181 + space = ((dac->dma.tail - dac->dma.head - 1)
11182 + & ((DMA_BUFFER_SIZE / 4) - 1));
11186 +static void abdac_update_dma_tail(struct at32_dac *dac)
11188 + dma_addr_t dma_addr;
11189 + unsigned int new_tail;
11191 + if (dac->playing) {
11192 + dma_addr = dma_get_current_pos(dac->req.req.dmac,
11193 + dac->req.req.channel);
11194 + new_tail = (dma_addr - dac->req.buffer_start) / 4;
11195 + if (new_tail >= dac->dma.head
11196 + && (dac->dma.tail < dac->dma.head
11197 + || dac->dma.tail > new_tail))
11198 + dev_notice(&dac->pdev->dev, "DMA underrun detected!\n");
11199 + dac->dma.tail = new_tail;
11200 + dev_dbg(&dac->pdev->dev, "update tail: 0x%x - 0x%x = %u\n",
11201 + dma_addr, dac->req.buffer_start, dac->dma.tail);
11205 +static int abdac_start(struct at32_dac *dac)
11209 + if (dac->playing)
11212 + memset(dac->dma.buf, 0, DMA_BUFFER_SIZE);
11214 + clk_enable(dac->sample_clk);
11216 + ret = dma_prepare_request_cyclic(dac->req.req.dmac, &dac->req);
11218 + goto out_stop_clock;
11220 + dev_dbg(&dac->pdev->dev, "starting DMA...\n");
11221 + ret = dma_start_request(dac->req.req.dmac, dac->req.req.channel);
11223 + goto out_stop_request;
11225 + dac_writel(dac, CTRL, DAC_BIT(EN));
11226 + dac->playing = 1;
11231 + dma_stop_request(dac->req.req.dmac,
11232 + dac->req.req.channel);
11234 + clk_disable(dac->sample_clk);
11238 +static int abdac_stop(struct at32_dac *dac)
11240 + if (dac->playing) {
11241 + dma_stop_request(dac->req.req.dmac, dac->req.req.channel);
11242 + dac_writel(dac, DATA, 0);
11243 + dac_writel(dac, CTRL, 0);
11244 + dac->playing = 0;
11245 + clk_disable(dac->sample_clk);
11251 +static int abdac_dma_prepare(struct at32_dac *dac)
11253 + dac->dma.buf = dma_alloc_coherent(&dac->pdev->dev, DMA_BUFFER_SIZE,
11254 + &dac->req.buffer_start, GFP_KERNEL);
11255 + if (!dac->dma.buf)
11258 + dac->dma.head = dac->dma.tail = 0;
11259 + dac->req.periods = DMA_BUFFER_SIZE / DMA_PERIOD_SIZE;
11260 + dac->req.buffer_size = DMA_BUFFER_SIZE;
11265 +static void abdac_dma_cleanup(struct at32_dac *dac)
11267 + if (dac->dma.buf)
11268 + dma_free_coherent(&dac->pdev->dev, DMA_BUFFER_SIZE,
11269 + dac->dma.buf, dac->req.buffer_start);
11270 + dac->dma.buf = NULL;
11273 +static void abdac_dma_block_complete(struct dma_request *req)
11275 + struct dma_request_cyclic *creq = to_dma_request_cyclic(req);
11276 + struct at32_dac *dac = container_of(creq, struct at32_dac, req);
11278 + wake_up(&dac->write_wait);
11281 +static void abdac_dma_error(struct dma_request *req)
11283 + struct dma_request_cyclic *creq = to_dma_request_cyclic(req);
11284 + struct at32_dac *dac = container_of(creq, struct at32_dac, req);
11286 + dev_err(&dac->pdev->dev, "DMA error\n");
11289 +static irqreturn_t abdac_interrupt(int irq, void *dev_id)
11291 + struct at32_dac *dac = dev_id;
11294 + status = dac_readl(dac, INT_STATUS);
11295 + if (status & DAC_BIT(UNDERRUN)) {
11296 + dev_err(&dac->pdev->dev, "Underrun detected!\n");
11297 + dac_writel(dac, INT_CLR, DAC_BIT(UNDERRUN));
11299 + dev_err(&dac->pdev->dev, "Spurious interrupt (status=0x%x)\n",
11301 + dac_writel(dac, INT_CLR, status);
11304 + return IRQ_HANDLED;
11307 +static ssize_t trans_s16be(struct at32_dac *dac, const char __user *ubuf,
11312 + if (dac->dsp_settings.channels == 2) {
11313 + const u32 __user *up = (const u32 __user *)ubuf;
11316 + for (ret = 0; ret < (ssize_t)(ucount - 3); ret += 4) {
11317 + if (!abdac_dma_space(dac))
11320 + if (unlikely(__get_user(sample, up++))) {
11325 + dac->dma.buf[abdac_get_head(dac)] = sample;
11329 + const u16 __user *up = (const u16 __user *)ubuf;
11332 + for (ret = 0; ret < (ssize_t)(ucount - 1); ret += 2) {
11333 + if (!abdac_dma_space(dac))
11336 + if (unlikely(__get_user(sample, up++))) {
11341 + dac->dma.buf[abdac_get_head(dac)]
11342 + = (sample << 16) | sample;
11350 +static ssize_t trans_s16le(struct at32_dac *dac, const char __user *ubuf,
11355 + if (dac->dsp_settings.channels == 2) {
11356 + const u32 __user *up = (const u32 __user *)ubuf;
11359 + for (ret = 0; ret < (ssize_t)(ucount - 3); ret += 4) {
11360 + if (!abdac_dma_space(dac))
11363 + if (unlikely(__get_user(sample, up++))) {
11368 + /* Swap bytes in each halfword */
11369 + dac->dma.buf[abdac_get_head(dac)] = swahb32(sample);
11373 + const u16 __user *up = (const u16 __user *)ubuf;
11376 + for (ret = 0; ret < (ssize_t)(ucount - 1); ret += 2) {
11377 + if (!abdac_dma_space(dac))
11380 + if (unlikely(__get_user(sample, up++))) {
11385 + sample = swab16(sample);
11386 + dac->dma.buf[abdac_get_head(dac)]
11387 + = (sample << 16) | sample;
11395 +static ssize_t abdac_dma_translate_from_user(struct at32_dac *dac,
11396 + const char __user *buffer,
11399 + /* At least one buffer must be available at this point */
11400 + dev_dbg(&dac->pdev->dev, "copying %zu bytes from user...\n", count);
11402 + return dac->trans(dac, buffer, count);
11405 +static int abdac_set_format(struct at32_dac *dac, int format)
11407 + unsigned int order;
11409 + switch (format) {
11410 + case AFMT_S16_BE:
11412 + dac->trans = trans_s16be;
11414 + case AFMT_S16_LE:
11416 + dac->trans = trans_s16le;
11419 + dev_dbg(&dac->pdev->dev, "unsupported format: %d\n", format);
11423 + if (dac->dsp_settings.channels == 2)
11426 + dac->dsp_settings.input_order = order;
11427 + dac->dsp_settings.format = format;
11431 +static int abdac_set_sample_rate(struct at32_dac *dac, unsigned long rate)
11433 + unsigned long new_rate;
11436 + ret = clk_set_rate(dac->sample_clk, 256 * rate);
11440 + /* TODO: mplayer seems to have a problem with this */
11442 + new_rate = clk_get_rate(dac->sample_clk);
11443 + dac->dsp_settings.sample_rate = new_rate / 256;
11445 + dac->dsp_settings.sample_rate = rate;
11451 +static ssize_t abdac_dsp_write(struct file *file,
11452 + const char __user *buffer,
11453 + size_t count, loff_t *ppos)
11455 + struct at32_dac *dac = file->private_data;
11456 + DECLARE_WAITQUEUE(wait, current);
11457 + unsigned int avail;
11461 + /* Avoid address space checking in the translation functions */
11462 + if (!access_ok(buffer, count, VERIFY_READ))
11467 + if (!dac->dma.buf) {
11468 + ret = abdac_dma_prepare(dac);
11473 + add_wait_queue(&dac->write_wait, &wait);
11475 + while (count > 0) {
11477 + abdac_update_dma_tail(dac);
11478 + avail = abdac_dma_space(dac);
11479 + set_current_state(TASK_INTERRUPTIBLE);
11480 + if (avail >= DMA_WRITE_THRESHOLD)
11483 + if (file->f_flags & O_NONBLOCK) {
11489 + pr_debug("Going to wait (avail = %u, count = %zu)\n",
11494 + if (signal_pending(current)) {
11496 + ret = -ERESTARTSYS;
11502 + copied = abdac_dma_translate_from_user(dac, buffer, count);
11503 + if (copied < 0) {
11509 + abdac_start(dac);
11518 + remove_wait_queue(&dac->write_wait, &wait);
11519 + set_current_state(TASK_RUNNING);
11523 +static int abdac_dsp_ioctl(struct inode *inode, struct file *file,
11524 + unsigned int cmd, unsigned long arg)
11526 + struct at32_dac *dac = file->private_data;
11527 + int __user *up = (int __user *)arg;
11528 + struct audio_buf_info abinfo;
11532 + case OSS_GETVERSION:
11533 + return put_user(SOUND_VERSION, up);
11535 + case SNDCTL_DSP_SPEED:
11536 + if (get_user(val, up))
11540 + ret = abdac_set_sample_rate(dac, val);
11544 + return put_user(dac->dsp_settings.sample_rate, up);
11546 + case SNDCTL_DSP_STEREO:
11547 + if (get_user(val, up))
11550 + if (val && dac->dsp_settings.channels == 1)
11551 + dac->dsp_settings.input_order++;
11552 + else if (!val && dac->dsp_settings.channels != 1)
11553 + dac->dsp_settings.input_order--;
11554 + dac->dsp_settings.channels = val ? 2 : 1;
11557 + case SNDCTL_DSP_CHANNELS:
11558 + if (get_user(val, up))
11562 + if (val < 0 || val > 2)
11566 + dac->dsp_settings.input_order
11567 + += val - dac->dsp_settings.channels;
11568 + dac->dsp_settings.channels = val;
11570 + return put_user(val, (int *)arg);
11572 + case SNDCTL_DSP_GETFMTS:
11573 + return put_user(AFMT_S16_BE | AFMT_S16_BE, up);
11575 + case SNDCTL_DSP_SETFMT:
11576 + if (get_user(val, up))
11579 + if (val == AFMT_QUERY) {
11580 + val = dac->dsp_settings.format;
11582 + ret = abdac_set_format(dac, val);
11586 + return put_user(val, up);
11588 + case SNDCTL_DSP_GETOSPACE:
11589 + abdac_update_dma_tail(dac);
11590 + abinfo.fragsize = ((1 << dac->dsp_settings.input_order)
11591 + * (DMA_PERIOD_SIZE / 4));
11592 + abinfo.bytes = (abdac_dma_space(dac)
11593 + << dac->dsp_settings.input_order);
11594 + abinfo.fragstotal = ((DMA_BUFFER_SIZE * 4)
11595 + >> (DMA_PERIOD_SHIFT
11596 + + dac->dsp_settings.input_order));
11597 + abinfo.fragments = ((abinfo.bytes
11598 + >> dac->dsp_settings.input_order)
11599 + / (DMA_PERIOD_SIZE / 4));
11600 + pr_debug("fragments=%d fragstotal=%d fragsize=%d bytes=%d\n",
11601 + abinfo.fragments, abinfo.fragstotal, abinfo.fragsize,
11603 + return copy_to_user(up, &abinfo, sizeof(abinfo)) ? -EFAULT : 0;
11606 + dev_dbg(&dac->pdev->dev, "Unimplemented ioctl cmd: 0x%x\n", cmd);
11611 +static int abdac_dsp_open(struct inode *inode, struct file *file)
11613 + struct at32_dac *dac = the_dac;
11616 + if (file->f_mode & FMODE_READ)
11624 + dac->dma.head = dac->dma.tail = 0;
11626 + /* FIXME: What are the correct defaults? */
11627 + dac->dsp_settings.channels = 2;
11628 + abdac_set_format(dac, AFMT_S16_BE);
11629 + ret = abdac_set_sample_rate(dac, 8000);
11633 + file->private_data = dac;
11643 +static int abdac_dsp_release(struct inode *inode, struct file *file)
11645 + struct at32_dac *dac = file->private_data;
11650 + abdac_dma_cleanup(dac);
11658 +static struct file_operations abdac_dsp_fops = {
11659 + .owner = THIS_MODULE,
11660 + .llseek = no_llseek,
11661 + .write = abdac_dsp_write,
11662 + .ioctl = abdac_dsp_ioctl,
11663 + .open = abdac_dsp_open,
11664 + .release = abdac_dsp_release,
11667 +static int __init abdac_probe(struct platform_device *pdev)
11669 + struct at32_dac *dac;
11670 + struct resource *regs;
11672 + struct clk *sample_clk;
11679 + regs = platform_get_resource(pdev, IORESOURCE_MEM, 0);
11682 + irq = platform_get_irq(pdev, 0);
11686 + mck = clk_get(&pdev->dev, "pclk");
11688 + return PTR_ERR(mck);
11689 + sample_clk = clk_get(&pdev->dev, "sample_clk");
11690 + if (IS_ERR(sample_clk)) {
11691 + ret = PTR_ERR(sample_clk);
11692 + goto out_put_mck;
11697 + dac = kzalloc(sizeof(struct at32_dac), GFP_KERNEL);
11699 + goto out_disable_clk;
11701 + spin_lock_init(&dac->lock);
11702 + init_MUTEX(&dac->sem);
11703 + init_waitqueue_head(&dac->write_wait);
11704 + dac->pdev = pdev;
11706 + dac->sample_clk = sample_clk;
11708 + dac->regs = ioremap(regs->start, regs->end - regs->start + 1);
11710 + goto out_free_dac;
11712 + ret = request_irq(irq, abdac_interrupt, 0, "dac", dac);
11714 + goto out_unmap_regs;
11717 + dac->req.req.dmac = find_dma_controller(0);
11718 + if (!dac->req.req.dmac)
11719 + goto out_free_irq;
11721 + ret = dma_alloc_channel(dac->req.req.dmac);
11723 + goto out_free_irq;
11725 + dac->req.req.channel = ret;
11726 + dac->req.req.block_complete = abdac_dma_block_complete;
11727 + dac->req.req.error = abdac_dma_error;
11728 + dac->req.data_reg = regs->start + DAC_DATA;
11729 + dac->req.periph_id = 2; /* FIXME */
11730 + dac->req.direction = DMA_DIR_MEM_TO_PERIPH;
11731 + dac->req.width = DMA_WIDTH_32BIT;
11733 + /* Make sure the DAC is silent and disabled */
11734 + dac_writel(dac, DATA, 0);
11735 + dac_writel(dac, CTRL, 0);
11737 + ret = register_sound_dsp(&abdac_dsp_fops, -1);
11739 + goto out_free_dma;
11740 + dac->dev_dsp = ret;
11742 + /* TODO: Register mixer */
11745 + platform_set_drvdata(pdev, dac);
11750 + dma_release_channel(dac->req.req.dmac, dac->req.req.channel);
11752 + free_irq(irq, dac);
11754 + iounmap(dac->regs);
11758 + clk_disable(mck);
11759 + clk_put(sample_clk);
11765 +static int __exit abdac_remove(struct platform_device *pdev)
11767 + struct at32_dac *dac;
11769 + dac = platform_get_drvdata(pdev);
11771 + unregister_sound_dsp(dac->dev_dsp);
11772 + dma_release_channel(dac->req.req.dmac, dac->req.req.channel);
11773 + free_irq(platform_get_irq(pdev, 0), dac);
11774 + iounmap(dac->regs);
11775 + clk_disable(dac->mck);
11776 + clk_put(dac->sample_clk);
11777 + clk_put(dac->mck);
11779 + platform_set_drvdata(pdev, NULL);
11786 +static struct platform_driver abdac_driver = {
11787 + .remove = __exit_p(abdac_remove),
11793 +static int __init abdac_init(void)
11795 + return platform_driver_probe(&abdac_driver, abdac_probe);
11797 +module_init(abdac_init);
11799 +static void __exit abdac_exit(void)
11801 + platform_driver_unregister(&abdac_driver);
11803 +module_exit(abdac_exit);
11805 +MODULE_AUTHOR("Haavard Skinnemoen <hskinnemoen@atmel.com>");
11806 +MODULE_DESCRIPTION("Sound Driver for the Atmel AT32 ABDAC");
11807 +MODULE_LICENSE("GPL");
11808 diff --git a/sound/oss/at32_abdac.h b/sound/oss/at32_abdac.h
11809 new file mode 100644
11810 index 0000000..3c88e25
11812 +++ b/sound/oss/at32_abdac.h
11815 + * Register definitions for the Atmel AT32 on-chip DAC.
11817 + * Copyright (C) 2006 Atmel Corporation
11819 + * This program is free software; you can redistribute it and/or modify
11820 + * it under the terms of the GNU General Public License version 2 as
11821 + * published by the Free Software Foundation.
11823 +#ifndef __SOUND_OSS_AT32_ABDAC_H__
11824 +#define __SOUND_OSS_AT32_ABDAC_H__
11826 +/* DAC register offsets */
11827 +#define DAC_DATA 0x0000
11828 +#define DAC_CTRL 0x0008
11829 +#define DAC_INT_MASK 0x000c
11830 +#define DAC_INT_EN 0x0010
11831 +#define DAC_INT_DIS 0x0014
11832 +#define DAC_INT_CLR 0x0018
11833 +#define DAC_INT_STATUS 0x001c
11834 +#define DAC_PDC_DATA 0x0020
11836 +/* Bitfields in CTRL */
11837 +#define DAC_SWAP_OFFSET 30
11838 +#define DAC_SWAP_SIZE 1
11839 +#define DAC_EN_OFFSET 31
11840 +#define DAC_EN_SIZE 1
11842 +/* Bitfields in INT_MASK/INT_EN/INT_DIS/INT_STATUS/INT_CLR */
11843 +#define DAC_UNDERRUN_OFFSET 28
11844 +#define DAC_UNDERRUN_SIZE 1
11845 +#define DAC_TX_READY_OFFSET 29
11846 +#define DAC_TX_READY_SIZE 1
11847 +#define DAC_TX_BUFFER_EMPTY_OFFSET 30
11848 +#define DAC_TX_BUFFER_EMPTY_SIZE 1
11849 +#define DAC_CHANNEL_TX_END_OFFSET 31
11850 +#define DAC_CHANNEL_TX_END_SIZE 1
11852 +/* Bit manipulation macros */
11853 +#define DAC_BIT(name) \
11854 + (1 << DAC_##name##_OFFSET)
11855 +#define DAC_BF(name, value) \
11856 + (((value) & ((1 << DAC_##name##_SIZE) - 1)) \
11857 + << DAC_##name##_OFFSET)
11858 +#define DAC_BFEXT(name, value) \
11859 + (((value) >> DAC_##name##_OFFSET) \
11860 + & ((1 << DAC_##name##_SIZE) - 1))
11861 +#define DAC_BFINS(name, value, old) \
11862 + (((old) & ~(((1 << DAC_##name##_SIZE) - 1) \
11863 + << DAC_##name##_OFFSET)) \
11864 + | DAC_BF(name,value))
11866 +/* Register access macros */
11867 +#define dac_readl(port, reg) \
11868 + __raw_readl((port)->regs + DAC_##reg)
11869 +#define dac_writel(port, reg, value) \
11870 + __raw_writel((value), (port)->regs + DAC_##reg)
11872 +#endif /* __SOUND_OSS_AT32_ABDAC_H__ */
11873 diff --git a/sound/spi/Kconfig b/sound/spi/Kconfig
11874 new file mode 100644
11875 index 0000000..0d08c29
11877 +++ b/sound/spi/Kconfig
11881 +menu "SPI devices"
11882 + depends on SND != n
11884 +config SND_AT73C213
11885 + tristate "Atmel AT73C213 DAC driver"
11886 + depends on ATMEL_SSC
11889 + Say Y here if you want to use the Atmel AT73C213 external DAC. This
11890 + DAC can be found on Atmel development boards.
11892 + This driver requires the Atmel SSC driver for sound sink, a
11893 + peripheral found on most AT91 and AVR32 microprocessors.
11895 + To compile this driver as a module, choose M here: the module will be
11896 + called snd-at73c213.
11898 +config SND_AT73C213_TARGET_BITRATE
11899 + int "Target bitrate for AT73C213"
11900 + depends on SND_AT73C213
11904 + Sets the target bitrate for the bitrate calculator in the driver.
11905 + Limited by hardware to be between 8000 Hz and 50000 Hz.
11907 + Set to 48000 Hz by default.
11910 diff --git a/sound/spi/Makefile b/sound/spi/Makefile
11911 new file mode 100644
11912 index 0000000..026fb73
11914 +++ b/sound/spi/Makefile
11916 +# Makefile for SPI drivers
11918 +snd-at73c213-objs := at73c213.o
11920 +obj-$(CONFIG_SND_AT73C213) += snd-at73c213.o
11921 diff --git a/sound/spi/at73c213.c b/sound/spi/at73c213.c
11922 new file mode 100644
11923 index 0000000..f514f47
11925 +++ b/sound/spi/at73c213.c
11928 + * Driver for AT73C213 16-bit stereo DAC connected to Atmel SSC
11930 + * Copyright (C) 2006-2007 Atmel Norway
11932 + * This program is free software; you can redistribute it and/or modify it
11933 + * under the terms of the GNU General Public License version 2 as published by
11934 + * the Free Software Foundation.
11939 +#include <linux/clk.h>
11940 +#include <linux/err.h>
11941 +#include <linux/delay.h>
11942 +#include <linux/device.h>
11943 +#include <linux/dma-mapping.h>
11944 +#include <linux/init.h>
11945 +#include <linux/interrupt.h>
11946 +#include <linux/module.h>
11947 +#include <linux/platform_device.h>
11948 +#include <linux/io.h>
11950 +#include <sound/driver.h>
11951 +#include <sound/initval.h>
11952 +#include <sound/control.h>
11953 +#include <sound/core.h>
11954 +#include <sound/pcm.h>
11956 +#include <linux/atmel-ssc.h>
11958 +#include <linux/spi/spi.h>
11959 +#include <linux/spi/at73c213.h>
11961 +#include "at73c213.h"
11963 +#define BITRATE_MIN 8000 /* Hardware limit? */
11964 +#define BITRATE_TARGET CONFIG_SND_AT73C213_TARGET_BITRATE
11965 +#define BITRATE_MAX 50000 /* Hardware limit. */
11967 +/* Initial (hardware reset) AT73C213 register values. */
11968 +static u8 snd_at73c213_original_image[18] =
11970 + 0x00, /* 00 - CTRL */
11971 + 0x05, /* 01 - LLIG */
11972 + 0x05, /* 02 - RLIG */
11973 + 0x08, /* 03 - LPMG */
11974 + 0x08, /* 04 - RPMG */
11975 + 0x00, /* 05 - LLOG */
11976 + 0x00, /* 06 - RLOG */
11977 + 0x22, /* 07 - OLC */
11978 + 0x09, /* 08 - MC */
11979 + 0x00, /* 09 - CSFC */
11980 + 0x00, /* 0A - MISC */
11982 + 0x00, /* 0C - PRECH */
11983 + 0x05, /* 0D - AUXG */
11986 + 0x00, /* 10 - RST */
11987 + 0x00, /* 11 - PA_CTRL */
11990 +struct snd_at73c213 {
11991 + struct snd_card *card;
11992 + struct snd_pcm *pcm;
11993 + struct snd_pcm_substream *substream;
11994 + struct at73c213_board_info *board;
11997 + unsigned long bitrate;
11998 + struct clk *bitclk;
11999 + struct ssc_device *ssc;
12000 + struct spi_device *spi;
12001 + u8 spi_wbuffer[2];
12002 + u8 spi_rbuffer[2];
12003 + /* Image of the SPI registers in AT73C213. */
12004 + u8 reg_image[18];
12005 + /* Protect registers against concurrent access. */
12009 +#define get_chip(card) ((struct snd_at73c213 *)card->private_data)
12012 +snd_at73c213_write_reg(struct snd_at73c213 *chip, u8 reg, u8 val)
12014 + struct spi_message msg;
12015 + struct spi_transfer msg_xfer = {
12021 + spi_message_init(&msg);
12023 + chip->spi_wbuffer[0] = reg;
12024 + chip->spi_wbuffer[1] = val;
12026 + msg_xfer.tx_buf = chip->spi_wbuffer;
12027 + msg_xfer.rx_buf = chip->spi_rbuffer;
12028 + spi_message_add_tail(&msg_xfer, &msg);
12030 + retval = spi_sync(chip->spi, &msg);
12033 + chip->reg_image[reg] = val;
12038 +static struct snd_pcm_hardware snd_at73c213_playback_hw = {
12039 + .info = SNDRV_PCM_INFO_INTERLEAVED |
12040 + SNDRV_PCM_INFO_BLOCK_TRANSFER,
12041 + .formats = SNDRV_PCM_FMTBIT_S16_BE,
12042 + .rates = SNDRV_PCM_RATE_CONTINUOUS,
12043 + .rate_min = 8000, /* Replaced by chip->bitrate later. */
12044 + .rate_max = 50000, /* Replaced by chip->bitrate later. */
12045 + .channels_min = 2,
12046 + .channels_max = 2,
12047 + .buffer_bytes_max = 64 * 1024 - 1,
12048 + .period_bytes_min = 512,
12049 + .period_bytes_max = 64 * 1024 - 1,
12050 + .periods_min = 4,
12051 + .periods_max = 1024,
12055 + * Calculate and set bitrate and divisions.
12057 +static int snd_at73c213_set_bitrate(struct snd_at73c213 *chip)
12059 + unsigned long ssc_rate = clk_get_rate(chip->ssc->clk);
12060 + unsigned long dac_rate_new, ssc_div, status;
12061 + unsigned long ssc_div_max, ssc_div_min;
12065 + * We connect two clocks here, picking divisors so the I2S clocks
12066 + * out data at the same rate the DAC clocks it in ... and as close
12067 + * as practical to the desired target rate.
12069 + * The DAC master clock (MCLK) is programmable, and is either 256
12070 + * or (not here) 384 times the I2S output clock (BCLK).
12073 + /* SSC clock / (bitrate * stereo * 16-bit). */
12074 + ssc_div = ssc_rate / (BITRATE_TARGET * 2 * 16);
12075 + ssc_div_min = ssc_rate / (BITRATE_MAX * 2 * 16);
12076 + ssc_div_max = ssc_rate / (BITRATE_MIN * 2 * 16);
12077 + max_tries = (ssc_div_max - ssc_div_min) / 2;
12079 + if (max_tries < 1)
12082 + /* ssc_div must be a power of 2. */
12083 + ssc_div = (ssc_div + 1) & ~1UL;
12085 + if ((ssc_rate / (ssc_div * 2 * 16)) < BITRATE_MIN) {
12087 + if ((ssc_rate / (ssc_div * 2 * 16)) > BITRATE_MAX)
12091 + /* Search for a possible bitrate. */
12093 + /* SSC clock / (ssc divider * 16-bit * stereo). */
12094 + if ((ssc_rate / (ssc_div * 2 * 16)) < BITRATE_MIN)
12097 + /* 256 / (2 * 16) = 8 */
12098 + dac_rate_new = 8 * (ssc_rate / ssc_div);
12100 + status = clk_round_rate(chip->board->dac_clk, dac_rate_new);
12104 + /* Ignore difference smaller than 256 Hz. */
12105 + if ((status/256) == (dac_rate_new/256))
12109 + } while (--max_tries);
12111 + /* Not able to find a valid bitrate. */
12115 + status = clk_set_rate(chip->board->dac_clk, status);
12119 + /* Set divider in SSC device. */
12120 + ssc_writel(chip->ssc->regs, CMR, ssc_div/2);
12122 + /* SSC clock / (ssc divider * 16-bit * stereo). */
12123 + chip->bitrate = ssc_rate / (ssc_div * 16 * 2);
12125 + dev_info(&chip->spi->dev,
12126 + "at73c213: supported bitrate is %lu (%lu divider)\n",
12127 + chip->bitrate, ssc_div);
12132 +static int snd_at73c213_pcm_open(struct snd_pcm_substream *substream)
12134 + struct snd_at73c213 *chip = snd_pcm_substream_chip(substream);
12135 + struct snd_pcm_runtime *runtime = substream->runtime;
12137 + snd_at73c213_playback_hw.rate_min = chip->bitrate;
12138 + snd_at73c213_playback_hw.rate_max = chip->bitrate;
12139 + runtime->hw = snd_at73c213_playback_hw;
12140 + chip->substream = substream;
12145 +static int snd_at73c213_pcm_close(struct snd_pcm_substream *substream)
12147 + struct snd_at73c213 *chip = snd_pcm_substream_chip(substream);
12148 + chip->substream = NULL;
12152 +static int snd_at73c213_pcm_hw_params(struct snd_pcm_substream *substream,
12153 + struct snd_pcm_hw_params *hw_params)
12155 + return snd_pcm_lib_malloc_pages(substream,
12156 + params_buffer_bytes(hw_params));
12159 +static int snd_at73c213_pcm_hw_free(struct snd_pcm_substream *substream)
12161 + return snd_pcm_lib_free_pages(substream);
12164 +static int snd_at73c213_pcm_prepare(struct snd_pcm_substream *substream)
12166 + struct snd_at73c213 *chip = snd_pcm_substream_chip(substream);
12167 + struct snd_pcm_runtime *runtime = substream->runtime;
12170 + block_size = frames_to_bytes(runtime, runtime->period_size);
12172 + chip->period = 0;
12174 + ssc_writel(chip->ssc->regs, PDC_TPR,
12175 + (long)runtime->dma_addr);
12176 + ssc_writel(chip->ssc->regs, PDC_TCR, runtime->period_size * 2);
12177 + ssc_writel(chip->ssc->regs, PDC_TNPR,
12178 + (long)runtime->dma_addr + block_size);
12179 + ssc_writel(chip->ssc->regs, PDC_TNCR, runtime->period_size * 2);
12184 +static int snd_at73c213_pcm_trigger(struct snd_pcm_substream *substream,
12187 + struct snd_at73c213 *chip = snd_pcm_substream_chip(substream);
12190 + spin_lock(&chip->lock);
12193 + case SNDRV_PCM_TRIGGER_START:
12194 + ssc_writel(chip->ssc->regs, IER, SSC_BIT(IER_ENDTX));
12195 + ssc_writel(chip->ssc->regs, PDC_PTCR, SSC_BIT(PDC_PTCR_TXTEN));
12197 + case SNDRV_PCM_TRIGGER_STOP:
12198 + ssc_writel(chip->ssc->regs, PDC_PTCR, SSC_BIT(PDC_PTCR_TXTDIS));
12199 + ssc_writel(chip->ssc->regs, IDR, SSC_BIT(IDR_ENDTX));
12202 + dev_dbg(&chip->spi->dev, "spurious command %x\n", cmd);
12203 + retval = -EINVAL;
12207 + spin_unlock(&chip->lock);
12212 +static snd_pcm_uframes_t
12213 +snd_at73c213_pcm_pointer(struct snd_pcm_substream *substream)
12215 + struct snd_at73c213 *chip = snd_pcm_substream_chip(substream);
12216 + struct snd_pcm_runtime *runtime = substream->runtime;
12217 + snd_pcm_uframes_t pos;
12218 + unsigned long bytes;
12220 + bytes = ssc_readl(chip->ssc->regs, PDC_TPR)
12221 + - (unsigned long)runtime->dma_addr;
12223 + pos = bytes_to_frames(runtime, bytes);
12224 + if (pos >= runtime->buffer_size)
12225 + pos -= runtime->buffer_size;
12230 +static struct snd_pcm_ops at73c213_playback_ops = {
12231 + .open = snd_at73c213_pcm_open,
12232 + .close = snd_at73c213_pcm_close,
12233 + .ioctl = snd_pcm_lib_ioctl,
12234 + .hw_params = snd_at73c213_pcm_hw_params,
12235 + .hw_free = snd_at73c213_pcm_hw_free,
12236 + .prepare = snd_at73c213_pcm_prepare,
12237 + .trigger = snd_at73c213_pcm_trigger,
12238 + .pointer = snd_at73c213_pcm_pointer,
12241 +static void snd_at73c213_pcm_free(struct snd_pcm *pcm)
12243 + struct snd_at73c213 *chip = snd_pcm_chip(pcm);
12245 + snd_pcm_lib_preallocate_free_for_all(chip->pcm);
12246 + chip->pcm = NULL;
12250 +static int __devinit snd_at73c213_pcm_new(struct snd_at73c213 *chip, int device)
12252 + struct snd_pcm *pcm;
12255 + retval = snd_pcm_new(chip->card, chip->card->shortname,
12256 + device, 1, 0, &pcm);
12260 + pcm->private_data = chip;
12261 + pcm->private_free = snd_at73c213_pcm_free;
12262 + pcm->info_flags = SNDRV_PCM_INFO_BLOCK_TRANSFER;
12263 + strcpy(pcm->name, "at73c213");
12266 + snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &at73c213_playback_ops);
12268 + retval = snd_pcm_lib_preallocate_pages_for_all(chip->pcm,
12269 + SNDRV_DMA_TYPE_DEV, &chip->ssc->pdev->dev,
12270 + 64 * 1024, 64 * 1024);
12275 +static irqreturn_t snd_at73c213_interrupt(int irq, void *dev_id)
12277 + struct snd_at73c213 *chip = dev_id;
12278 + struct snd_pcm_runtime *runtime = chip->substream->runtime;
12283 + int retval = IRQ_NONE;
12285 + spin_lock(&chip->lock);
12287 + block_size = frames_to_bytes(runtime, runtime->period_size);
12288 + status = ssc_readl(chip->ssc->regs, IMR);
12290 + if (status & SSC_BIT(IMR_ENDTX)) {
12292 + if (chip->period == runtime->periods)
12293 + chip->period = 0;
12294 + next_period = chip->period + 1;
12295 + if (next_period == runtime->periods)
12298 + offset = block_size * next_period;
12300 + ssc_writel(chip->ssc->regs, PDC_TNPR,
12301 + (long)runtime->dma_addr + offset);
12302 + ssc_writel(chip->ssc->regs, PDC_TNCR, runtime->period_size * 2);
12303 + retval = IRQ_HANDLED;
12306 + ssc_readl(chip->ssc->regs, IMR);
12307 + spin_unlock(&chip->lock);
12309 + if (status & SSC_BIT(IMR_ENDTX))
12310 + snd_pcm_period_elapsed(chip->substream);
12316 + * Mixer functions.
12318 +static int snd_at73c213_mono_get(struct snd_kcontrol *kcontrol,
12319 + struct snd_ctl_elem_value *ucontrol)
12321 + struct snd_at73c213 *chip = snd_kcontrol_chip(kcontrol);
12322 + int reg = kcontrol->private_value & 0xff;
12323 + int shift = (kcontrol->private_value >> 8) & 0xff;
12324 + int mask = (kcontrol->private_value >> 16) & 0xff;
12325 + int invert = (kcontrol->private_value >> 24) & 0xff;
12327 + spin_lock_irq(&chip->lock);
12329 + ucontrol->value.integer.value[0] = (chip->reg_image[reg] >> shift) & mask;
12332 + ucontrol->value.integer.value[0] =
12333 + (mask - ucontrol->value.integer.value[0]);
12335 + spin_unlock_irq(&chip->lock);
12340 +static int snd_at73c213_mono_put(struct snd_kcontrol *kcontrol,
12341 + struct snd_ctl_elem_value *ucontrol)
12343 + struct snd_at73c213 *chip = snd_kcontrol_chip(kcontrol);
12344 + int reg = kcontrol->private_value & 0xff;
12345 + int shift = (kcontrol->private_value >> 8) & 0xff;
12346 + int mask = (kcontrol->private_value >> 16) & 0xff;
12347 + int invert = (kcontrol->private_value >> 24) & 0xff;
12348 + int change, retval;
12349 + unsigned short val;
12351 + val = (ucontrol->value.integer.value[0] & mask);
12353 + val = mask - val;
12356 + spin_lock_irq(&chip->lock);
12358 + val = (chip->reg_image[reg] & ~(mask << shift)) | val;
12359 + change = val != chip->reg_image[reg];
12360 + retval = snd_at73c213_write_reg(chip, reg, val);
12362 + spin_unlock_irq(&chip->lock);
12370 +static int snd_at73c213_stereo_info(struct snd_kcontrol *kcontrol,
12371 + struct snd_ctl_elem_info *uinfo)
12373 + int mask = (kcontrol->private_value >> 24) & 0xff;
12376 + uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
12378 + uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
12380 + uinfo->count = 2;
12381 + uinfo->value.integer.min = 0;
12382 + uinfo->value.integer.max = mask;
12387 +static int snd_at73c213_stereo_get(struct snd_kcontrol *kcontrol,
12388 + struct snd_ctl_elem_value *ucontrol)
12390 + struct snd_at73c213 *chip = snd_kcontrol_chip(kcontrol);
12391 + int left_reg = kcontrol->private_value & 0xff;
12392 + int right_reg = (kcontrol->private_value >> 8) & 0xff;
12393 + int shift_left = (kcontrol->private_value >> 16) & 0x07;
12394 + int shift_right = (kcontrol->private_value >> 19) & 0x07;
12395 + int mask = (kcontrol->private_value >> 24) & 0xff;
12396 + int invert = (kcontrol->private_value >> 22) & 1;
12398 + spin_lock_irq(&chip->lock);
12400 + ucontrol->value.integer.value[0] =
12401 + (chip->reg_image[left_reg] >> shift_left) & mask;
12402 + ucontrol->value.integer.value[1] =
12403 + (chip->reg_image[right_reg] >> shift_right) & mask;
12406 + ucontrol->value.integer.value[0] =
12407 + (mask - ucontrol->value.integer.value[0]);
12408 + ucontrol->value.integer.value[1] =
12409 + (mask - ucontrol->value.integer.value[1]);
12412 + spin_unlock_irq(&chip->lock);
12417 +static int snd_at73c213_stereo_put(struct snd_kcontrol *kcontrol,
12418 + struct snd_ctl_elem_value *ucontrol)
12420 + struct snd_at73c213 *chip = snd_kcontrol_chip(kcontrol);
12421 + int left_reg = kcontrol->private_value & 0xff;
12422 + int right_reg = (kcontrol->private_value >> 8) & 0xff;
12423 + int shift_left = (kcontrol->private_value >> 16) & 0x07;
12424 + int shift_right = (kcontrol->private_value >> 19) & 0x07;
12425 + int mask = (kcontrol->private_value >> 24) & 0xff;
12426 + int invert = (kcontrol->private_value >> 22) & 1;
12427 + int change, retval;
12428 + unsigned short val1, val2;
12430 + val1 = ucontrol->value.integer.value[0] & mask;
12431 + val2 = ucontrol->value.integer.value[1] & mask;
12433 + val1 = mask - val1;
12434 + val2 = mask - val2;
12436 + val1 <<= shift_left;
12437 + val2 <<= shift_right;
12439 + spin_lock_irq(&chip->lock);
12441 + val1 = (chip->reg_image[left_reg] & ~(mask << shift_left)) | val1;
12442 + val2 = (chip->reg_image[right_reg] & ~(mask << shift_right)) | val2;
12443 + change = val1 != chip->reg_image[left_reg]
12444 + || val2 != chip->reg_image[right_reg];
12445 + retval = snd_at73c213_write_reg(chip, left_reg, val1);
12447 + spin_unlock_irq(&chip->lock);
12450 + retval = snd_at73c213_write_reg(chip, right_reg, val2);
12452 + spin_unlock_irq(&chip->lock);
12456 + spin_unlock_irq(&chip->lock);
12464 +static int snd_at73c213_mono_switch_info(struct snd_kcontrol *kcontrol,
12465 + struct snd_ctl_elem_info *uinfo)
12467 + uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
12468 + uinfo->count = 1;
12469 + uinfo->value.integer.min = 0;
12470 + uinfo->value.integer.max = 1;
12475 +static int snd_at73c213_mono_switch_get(struct snd_kcontrol *kcontrol,
12476 + struct snd_ctl_elem_value *ucontrol)
12478 + struct snd_at73c213 *chip = snd_kcontrol_chip(kcontrol);
12479 + int reg = kcontrol->private_value & 0xff;
12480 + int shift = (kcontrol->private_value >> 8) & 0xff;
12481 + int invert = (kcontrol->private_value >> 24) & 0xff;
12483 + spin_lock_irq(&chip->lock);
12485 + ucontrol->value.integer.value[0] = (chip->reg_image[reg] >> shift) & 0x01;
12488 + ucontrol->value.integer.value[0] =
12489 + (0x01 - ucontrol->value.integer.value[0]);
12491 + spin_unlock_irq(&chip->lock);
12496 +static int snd_at73c213_mono_switch_put(struct snd_kcontrol *kcontrol,
12497 + struct snd_ctl_elem_value *ucontrol)
12499 + struct snd_at73c213 *chip = snd_kcontrol_chip(kcontrol);
12500 + int reg = kcontrol->private_value & 0xff;
12501 + int shift = (kcontrol->private_value >> 8) & 0xff;
12502 + int mask = (kcontrol->private_value >> 16) & 0xff;
12503 + int invert = (kcontrol->private_value >> 24) & 0xff;
12504 + int change, retval;
12505 + unsigned short val;
12507 + if (ucontrol->value.integer.value[0])
12513 + val = mask - val;
12516 + spin_lock_irq(&chip->lock);
12518 + val |= (chip->reg_image[reg] & ~(mask << shift));
12519 + change = val != chip->reg_image[reg];
12521 + retval = snd_at73c213_write_reg(chip, reg, val);
12523 + spin_unlock_irq(&chip->lock);
12531 +static int snd_at73c213_pa_volume_info(struct snd_kcontrol *kcontrol,
12532 + struct snd_ctl_elem_info *uinfo)
12534 + uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
12535 + uinfo->count = 1;
12536 + uinfo->value.integer.min = 0;
12537 + uinfo->value.integer.max = ((kcontrol->private_value >> 16) & 0xff) - 1;
12542 +static int snd_at73c213_line_capture_volume_info(
12543 + struct snd_kcontrol *kcontrol,
12544 + struct snd_ctl_elem_info *uinfo)
12546 + uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
12547 + uinfo->count = 2;
12548 + /* When inverted will give values 0x10001 => 0. */
12549 + uinfo->value.integer.min = 14;
12550 + uinfo->value.integer.max = 31;
12555 +static int snd_at73c213_aux_capture_volume_info(
12556 + struct snd_kcontrol *kcontrol,
12557 + struct snd_ctl_elem_info *uinfo)
12559 + uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
12560 + uinfo->count = 1;
12561 + /* When inverted will give values 0x10001 => 0. */
12562 + uinfo->value.integer.min = 14;
12563 + uinfo->value.integer.max = 31;
12568 +#define AT73C213_MONO_SWITCH(xname, xindex, reg, shift, mask, invert) \
12570 + .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
12572 + .index = xindex, \
12573 + .info = snd_at73c213_mono_switch_info, \
12574 + .get = snd_at73c213_mono_switch_get, \
12575 + .put = snd_at73c213_mono_switch_put, \
12576 + .private_value = (reg | (shift << 8) | (mask << 16) | (invert << 24)) \
12579 +#define AT73C213_STEREO(xname, xindex, left_reg, right_reg, shift_left, shift_right, mask, invert) \
12581 + .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
12583 + .index = xindex, \
12584 + .info = snd_at73c213_stereo_info, \
12585 + .get = snd_at73c213_stereo_get, \
12586 + .put = snd_at73c213_stereo_put, \
12587 + .private_value = (left_reg | (right_reg << 8) \
12588 + | (shift_left << 16) | (shift_right << 19) \
12589 + | (mask << 24) | (invert << 22)) \
12592 +static struct snd_kcontrol_new snd_at73c213_controls[] __devinitdata = {
12593 +AT73C213_STEREO("Master Playback Volume", 0, DAC_LMPG, DAC_RMPG, 0, 0, 0x1f, 1),
12594 +AT73C213_STEREO("Master Playback Switch", 0, DAC_LMPG, DAC_RMPG, 5, 5, 1, 1),
12595 +AT73C213_STEREO("PCM Playback Volume", 0, DAC_LLOG, DAC_RLOG, 0, 0, 0x1f, 1),
12596 +AT73C213_STEREO("PCM Playback Switch", 0, DAC_LLOG, DAC_RLOG, 5, 5, 1, 1),
12597 +AT73C213_MONO_SWITCH("Mono PA Playback Switch", 0, DAC_CTRL, DAC_CTRL_ONPADRV, 0x01, 0),
12599 + .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
12600 + .name = "PA Playback Volume",
12602 + .info = snd_at73c213_pa_volume_info,
12603 + .get = snd_at73c213_mono_get,
12604 + .put = snd_at73c213_mono_put,
12605 + .private_value = PA_CTRL | (PA_CTRL_APAGAIN << 8) | (0x0f << 16) | (1 << 24),
12607 +AT73C213_MONO_SWITCH("PA High Gain Playback Switch", 0, PA_CTRL, PA_CTRL_APALP, 0x01, 1),
12608 +AT73C213_MONO_SWITCH("PA Playback Switch", 0, PA_CTRL, PA_CTRL_APAON, 0x01, 0),
12610 + .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
12611 + .name = "Aux Capture Volume",
12613 + .info = snd_at73c213_aux_capture_volume_info,
12614 + .get = snd_at73c213_mono_get,
12615 + .put = snd_at73c213_mono_put,
12616 + .private_value = DAC_AUXG | (0 << 8) | (0x1f << 16) | (1 << 24),
12618 +AT73C213_MONO_SWITCH("Aux Capture Switch", 0, DAC_CTRL, DAC_CTRL_ONAUXIN, 0x01, 0),
12620 + .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
12621 + .name = "Line Capture Volume",
12623 + .info = snd_at73c213_line_capture_volume_info,
12624 + .get = snd_at73c213_stereo_get,
12625 + .put = snd_at73c213_stereo_put,
12626 + .private_value = DAC_LLIG | (DAC_RLIG << 8) | (0 << 16) | (0 << 19)
12627 + | (0x1f << 24) | (1 << 22),
12629 +AT73C213_MONO_SWITCH("Line Capture Switch", 0, DAC_CTRL, 0, 0x03, 0),
12632 +static int __devinit snd_at73c213_mixer(struct snd_at73c213 *chip)
12634 + struct snd_card *card;
12637 + if (chip == NULL || chip->pcm == NULL)
12640 + card = chip->card;
12642 + strcpy(card->mixername, chip->pcm->name);
12644 + for (idx = 0; idx < ARRAY_SIZE(snd_at73c213_controls); idx++) {
12645 + errval = snd_ctl_add(card,
12646 + snd_ctl_new1(&snd_at73c213_controls[idx],
12655 + for (idx = 1; idx < ARRAY_SIZE(snd_at73c213_controls) + 1; idx++) {
12656 + struct snd_kcontrol *kctl;
12657 + kctl = snd_ctl_find_numid(card, idx);
12659 + snd_ctl_remove(card, kctl);
12665 + * Device functions
12667 +static int snd_at73c213_ssc_init(struct snd_at73c213 *chip)
12670 + * Continuous clock output.
12671 + * Starts on falling TF.
12672 + * Delay 1 cycle (1 bit).
12673 + * Periode is 16 bit (16 - 1).
12675 + ssc_writel(chip->ssc->regs, TCMR,
12676 + SSC_BF(TCMR_CKO, 1)
12677 + | SSC_BF(TCMR_START, 4)
12678 + | SSC_BF(TCMR_STTDLY, 1)
12679 + | SSC_BF(TCMR_PERIOD, 16 - 1));
12681 + * Data length is 16 bit (16 - 1).
12682 + * Transmit MSB first.
12683 + * Transmit 2 words each transfer.
12684 + * Frame sync length is 16 bit (16 - 1).
12685 + * Frame starts on negative pulse.
12687 + ssc_writel(chip->ssc->regs, TFMR,
12688 + SSC_BF(TFMR_DATLEN, 16 - 1)
12689 + | SSC_BIT(TFMR_MSBF)
12690 + | SSC_BF(TFMR_DATNB, 1)
12691 + | SSC_BF(TFMR_FSLEN, 16 - 1)
12692 + | SSC_BF(TFMR_FSOS, 1));
12697 +static int snd_at73c213_chip_init(struct snd_at73c213 *chip)
12700 + unsigned char dac_ctrl = 0;
12702 + retval = snd_at73c213_set_bitrate(chip);
12706 + /* Enable DAC master clock. */
12707 + clk_enable(chip->board->dac_clk);
12709 + /* Initialize at73c213 on SPI bus. */
12710 + retval = snd_at73c213_write_reg(chip, DAC_RST, 0x04);
12714 + retval = snd_at73c213_write_reg(chip, DAC_RST, 0x03);
12718 + /* Precharge everything. */
12719 + retval = snd_at73c213_write_reg(chip, DAC_PRECH, 0xff);
12722 + retval = snd_at73c213_write_reg(chip, PA_CTRL, (1<<PA_CTRL_APAPRECH));
12725 + retval = snd_at73c213_write_reg(chip, DAC_CTRL,
12726 + (1<<DAC_CTRL_ONLNOL) | (1<<DAC_CTRL_ONLNOR));
12732 + /* Stop precharging PA. */
12733 + retval = snd_at73c213_write_reg(chip, PA_CTRL,
12734 + (1<<PA_CTRL_APALP) | 0x0f);
12740 + /* Stop precharging DAC, turn on master power. */
12741 + retval = snd_at73c213_write_reg(chip, DAC_PRECH, (1<<DAC_PRECH_ONMSTR));
12747 + /* Turn on DAC. */
12748 + dac_ctrl = (1<<DAC_CTRL_ONDACL) | (1<<DAC_CTRL_ONDACR)
12749 + | (1<<DAC_CTRL_ONLNOL) | (1<<DAC_CTRL_ONLNOR);
12751 + retval = snd_at73c213_write_reg(chip, DAC_CTRL, dac_ctrl);
12755 + /* Mute sound. */
12756 + retval = snd_at73c213_write_reg(chip, DAC_LMPG, 0x3f);
12759 + retval = snd_at73c213_write_reg(chip, DAC_RMPG, 0x3f);
12762 + retval = snd_at73c213_write_reg(chip, DAC_LLOG, 0x3f);
12765 + retval = snd_at73c213_write_reg(chip, DAC_RLOG, 0x3f);
12768 + retval = snd_at73c213_write_reg(chip, DAC_LLIG, 0x11);
12771 + retval = snd_at73c213_write_reg(chip, DAC_RLIG, 0x11);
12774 + retval = snd_at73c213_write_reg(chip, DAC_AUXG, 0x11);
12778 + /* Enable I2S device, i.e. clock output. */
12779 + ssc_writel(chip->ssc->regs, CR, SSC_BIT(CR_TXEN));
12784 + clk_disable(chip->board->dac_clk);
12789 +static int snd_at73c213_dev_free(struct snd_device *device)
12791 + struct snd_at73c213 *chip = device->device_data;
12793 + ssc_writel(chip->ssc->regs, CR, SSC_BIT(CR_TXDIS));
12794 + if (chip->irq >= 0) {
12795 + free_irq(chip->irq, chip);
12802 +static int __devinit snd_at73c213_dev_init(struct snd_card *card,
12803 + struct spi_device *spi)
12805 + static struct snd_device_ops ops = {
12806 + .dev_free = snd_at73c213_dev_free,
12808 + struct snd_at73c213 *chip = get_chip(card);
12811 + irq = chip->ssc->irq;
12815 + spin_lock_init(&chip->lock);
12816 + chip->card = card;
12819 + retval = request_irq(irq, snd_at73c213_interrupt, 0, "at73c213", chip);
12821 + dev_dbg(&chip->spi->dev, "unable to request irq %d\n", irq);
12826 + memcpy(&chip->reg_image, &snd_at73c213_original_image,
12827 + sizeof(snd_at73c213_original_image));
12829 + retval = snd_at73c213_ssc_init(chip);
12833 + retval = snd_at73c213_chip_init(chip);
12837 + retval = snd_at73c213_pcm_new(chip, 0);
12841 + retval = snd_device_new(card, SNDRV_DEV_LOWLEVEL, chip, &ops);
12845 + retval = snd_at73c213_mixer(chip);
12847 + goto out_snd_dev;
12849 + snd_card_set_dev(card, &spi->dev);
12854 + snd_device_free(card, chip);
12856 + free_irq(chip->irq, chip);
12862 +static int snd_at73c213_probe(struct spi_device *spi)
12864 + struct snd_card *card;
12865 + struct snd_at73c213 *chip;
12866 + struct at73c213_board_info *board;
12870 + board = spi->dev.platform_data;
12872 + dev_dbg(&spi->dev, "no platform_data\n");
12876 + if (!board->dac_clk) {
12877 + dev_dbg(&spi->dev, "no DAC clk\n");
12881 + if (IS_ERR(board->dac_clk)) {
12882 + dev_dbg(&spi->dev, "no DAC clk\n");
12883 + return PTR_ERR(board->dac_clk);
12886 + retval = -ENOMEM;
12888 + /* Allocate "card" using some unused identifiers. */
12889 + snprintf(id, sizeof id, "at73c213_%d", board->ssc_id);
12890 + card = snd_card_new(-1, id, THIS_MODULE, sizeof(struct snd_at73c213));
12894 + chip = card->private_data;
12896 + chip->board = board;
12898 + chip->ssc = ssc_request(board->ssc_id);
12899 + if (IS_ERR(chip->ssc)) {
12900 + dev_dbg(&spi->dev, "could not get ssc%d device\n",
12902 + retval = PTR_ERR(chip->ssc);
12906 + retval = snd_at73c213_dev_init(card, spi);
12910 + strcpy(card->driver, "at73c213");
12911 + strcpy(card->shortname, board->shortname);
12912 + sprintf(card->longname, "%s on irq %d", card->shortname, chip->irq);
12914 + retval = snd_card_register(card);
12918 + dev_set_drvdata(&spi->dev, card);
12923 + ssc_free(chip->ssc);
12925 + snd_card_free(card);
12930 +static int __devexit snd_at73c213_remove(struct spi_device *spi)
12932 + struct snd_card *card = dev_get_drvdata(&spi->dev);
12933 + struct snd_at73c213 *chip = card->private_data;
12936 + /* Stop playback. */
12937 + ssc_writel(chip->ssc->regs, CR, SSC_BIT(CR_TXDIS));
12939 + /* Mute sound. */
12940 + retval = snd_at73c213_write_reg(chip, DAC_LMPG, 0x3f);
12943 + retval = snd_at73c213_write_reg(chip, DAC_RMPG, 0x3f);
12946 + retval = snd_at73c213_write_reg(chip, DAC_LLOG, 0x3f);
12949 + retval = snd_at73c213_write_reg(chip, DAC_RLOG, 0x3f);
12952 + retval = snd_at73c213_write_reg(chip, DAC_LLIG, 0x11);
12955 + retval = snd_at73c213_write_reg(chip, DAC_RLIG, 0x11);
12958 + retval = snd_at73c213_write_reg(chip, DAC_AUXG, 0x11);
12962 + /* Turn off PA. */
12963 + retval = snd_at73c213_write_reg(chip, PA_CTRL, (chip->reg_image[PA_CTRL]|0x0f));
12967 + retval = snd_at73c213_write_reg(chip, PA_CTRL, (1<<PA_CTRL_APALP)|0x0f);
12971 + /* Turn off external DAC. */
12972 + retval = snd_at73c213_write_reg(chip, DAC_CTRL, 0x0c);
12976 + retval = snd_at73c213_write_reg(chip, DAC_CTRL, 0x00);
12980 + /* Turn off master power. */
12981 + retval = snd_at73c213_write_reg(chip, DAC_PRECH, 0x00);
12986 + /* Stop DAC master clock. */
12987 + clk_disable(chip->board->dac_clk);
12989 + ssc_free(chip->ssc);
12990 + snd_card_free(card);
12991 + dev_set_drvdata(&spi->dev, NULL);
12997 +static int snd_at73c213_suspend(struct spi_device *spi, pm_message_t msg)
12999 + struct snd_card *card = dev_get_drvdata(&spi->dev);
13000 + struct snd_at73c213 *chip = card->private_data;
13002 + ssc_writel(chip->ssc->regs, CR, SSC_BIT(CR_TXDIS));
13003 + clk_disable(chip->board->dac_clk);
13008 +static int snd_at73c213_resume(struct spi_device *spi)
13010 + struct snd_card *card = dev_get_drvdata(&spi->dev);
13011 + struct snd_at73c213 *chip = card->private_data;
13013 + clk_enable(chip->board->dac_clk);
13014 + ssc_writel(chip->ssc->regs, CR, SSC_BIT(CR_TXEN));
13019 +#define snd_at73c213_suspend NULL
13020 +#define snd_at73c213_resume NULL
13023 +static struct spi_driver at73c213_driver = {
13025 + .name = "at73c213",
13027 + .probe = snd_at73c213_probe,
13028 + .suspend = snd_at73c213_suspend,
13029 + .resume = snd_at73c213_resume,
13030 + .remove = __devexit_p(snd_at73c213_remove),
13033 +static int __init at73c213_init(void)
13035 + return spi_register_driver(&at73c213_driver);
13037 +module_init(at73c213_init);
13039 +static void __exit at73c213_exit(void)
13041 + spi_unregister_driver(&at73c213_driver);
13043 +module_exit(at73c213_exit);
13045 +MODULE_AUTHOR("Hans-Christian Egtvedt <hcegtvedt@atmel.com>");
13046 +MODULE_DESCRIPTION("Sound driver for AT73C213 with Atmel SSC");
13047 +MODULE_LICENSE("GPL");
13048 diff --git a/sound/spi/at73c213.h b/sound/spi/at73c213.h
13049 new file mode 100644
13050 index 0000000..fd8b372
13052 +++ b/sound/spi/at73c213.h
13055 + * Driver for the AT73C213 16-bit stereo DAC on Atmel ATSTK1000
13057 + * Copyright (C) 2006 - 2007 Atmel Corporation
13059 + * This program is free software; you can redistribute it and/or
13060 + * modify it under the terms of the GNU General Public License as
13061 + * published by the Free Software Foundation; either version 2 of the
13062 + * License, or (at your option) any later version.
13064 + * This program is distributed in the hope that it will be useful, but
13065 + * WITHOUT ANY WARRANTY; without even the implied warranty of
13066 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13067 + * General Public License for more details.
13069 + * You should have received a copy of the GNU General Public License
13070 + * along with this program; if not, write to the Free Software
13071 + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
13072 + * 02111-1307, USA.
13074 + * The full GNU General Public License is included in this
13075 + * distribution in the file called COPYING.
13078 +#ifndef _SND_AT73C213_H
13079 +#define _SND_AT73C213_H
13081 +/* DAC control register */
13082 +#define DAC_CTRL 0x00
13083 +#define DAC_CTRL_ONPADRV 7
13084 +#define DAC_CTRL_ONAUXIN 6
13085 +#define DAC_CTRL_ONDACR 5
13086 +#define DAC_CTRL_ONDACL 4
13087 +#define DAC_CTRL_ONLNOR 3
13088 +#define DAC_CTRL_ONLNOL 2
13089 +#define DAC_CTRL_ONLNIR 1
13090 +#define DAC_CTRL_ONLNIL 0
13092 +/* DAC left line in gain register */
13093 +#define DAC_LLIG 0x01
13094 +#define DAC_LLIG_LLIG 0
13096 +/* DAC right line in gain register */
13097 +#define DAC_RLIG 0x02
13098 +#define DAC_RLIG_RLIG 0
13100 +/* DAC Left Master Playback Gain Register */
13101 +#define DAC_LMPG 0x03
13102 +#define DAC_LMPG_LMPG 0
13104 +/* DAC Right Master Playback Gain Register */
13105 +#define DAC_RMPG 0x04
13106 +#define DAC_RMPG_RMPG 0
13108 +/* DAC Left Line Out Gain Register */
13109 +#define DAC_LLOG 0x05
13110 +#define DAC_LLOG_LLOG 0
13112 +/* DAC Right Line Out Gain Register */
13113 +#define DAC_RLOG 0x06
13114 +#define DAC_RLOG_RLOG 0
13116 +/* DAC Output Level Control Register */
13117 +#define DAC_OLC 0x07
13118 +#define DAC_OLC_RSHORT 7
13119 +#define DAC_OLC_ROLC 4
13120 +#define DAC_OLC_LSHORT 3
13121 +#define DAC_OLC_LOLC 0
13123 +/* DAC Mixer Control Register */
13124 +#define DAC_MC 0x08
13125 +#define DAC_MC_INVR 5
13126 +#define DAC_MC_INVL 4
13127 +#define DAC_MC_RMSMIN2 3
13128 +#define DAC_MC_RMSMIN1 2
13129 +#define DAC_MC_LMSMIN2 1
13130 +#define DAC_MC_LMSMIN1 0
13132 +/* DAC Clock and Sampling Frequency Control Register */
13133 +#define DAC_CSFC 0x09
13134 +#define DAC_CSFC_OVRSEL 4
13136 +/* DAC Miscellaneous Register */
13137 +#define DAC_MISC 0x0A
13138 +#define DAC_MISC_VCMCAPSEL 7
13139 +#define DAC_MISC_DINTSEL 4
13140 +#define DAC_MISC_DITHEN 3
13141 +#define DAC_MISC_DEEMPEN 2
13142 +#define DAC_MISC_NBITS 0
13144 +/* DAC Precharge Control Register */
13145 +#define DAC_PRECH 0x0C
13146 +#define DAC_PRECH_PRCHGPDRV 7
13147 +#define DAC_PRECH_PRCHGAUX1 6
13148 +#define DAC_PRECH_PRCHGLNOR 5
13149 +#define DAC_PRECH_PRCHGLNOL 4
13150 +#define DAC_PRECH_PRCHGLNIR 3
13151 +#define DAC_PRECH_PRCHGLNIL 2
13152 +#define DAC_PRECH_PRCHG 1
13153 +#define DAC_PRECH_ONMSTR 0
13155 +/* DAC Auxiliary Input Gain Control Register */
13156 +#define DAC_AUXG 0x0D
13157 +#define DAC_AUXG_AUXG 0
13159 +/* DAC Reset Register */
13160 +#define DAC_RST 0x10
13161 +#define DAC_RST_RESMASK 2
13162 +#define DAC_RST_RESFILZ 1
13163 +#define DAC_RST_RSTZ 0
13165 +/* Power Amplifier Control Register */
13166 +#define PA_CTRL 0x11
13167 +#define PA_CTRL_APAON 6
13168 +#define PA_CTRL_APAPRECH 5
13169 +#define PA_CTRL_APALP 4
13170 +#define PA_CTRL_APAGAIN 0
13172 +#endif /* _SND_AT73C213_H */