1 diff -x .git -Nur linux-2.6.22.1/arch/avr32/boards/atngw100/Kconfig linux-avr32.git/arch/avr32/boards/atngw100/Kconfig
2 --- linux-2.6.22.1/arch/avr32/boards/atngw100/Kconfig 1970-01-01 01:00:00.000000000 +0100
3 +++ linux-avr32.git/arch/avr32/boards/atngw100/Kconfig 2007-07-13 11:24:16.000000000 +0200
5 +# NGW100 customization
7 +config BOARD_ATNGW100_I2C_GPIO
8 + bool "Use GPIO for i2c instead of built-in TWI module"
10 + The driver for the built-in TWI module has been plagued by
11 + various problems, while the i2c-gpio driver is based on the
12 + trusty old i2c-algo-bit bitbanging engine, making it work
13 + on pretty much any setup.
15 + Choose 'Y' here if you're having i2c-related problems and
16 + want to rule out the i2c bus driver.
17 diff -x .git -Nur linux-2.6.22.1/arch/avr32/boards/atngw100/setup.c linux-avr32.git/arch/avr32/boards/atngw100/setup.c
18 --- linux-2.6.22.1/arch/avr32/boards/atngw100/setup.c 2007-07-10 20:56:30.000000000 +0200
19 +++ linux-avr32.git/arch/avr32/boards/atngw100/setup.c 2007-07-13 11:24:16.000000000 +0200
22 #include <linux/clk.h>
23 #include <linux/etherdevice.h>
24 +#include <linux/i2c-gpio.h>
25 #include <linux/init.h>
26 #include <linux/linkage.h>
27 #include <linux/platform_device.h>
28 #include <linux/types.h>
29 +#include <linux/leds.h>
30 #include <linux/spi/spi.h>
34 #include <asm/arch/at32ap7000.h>
35 #include <asm/arch/board.h>
36 #include <asm/arch/init.h>
37 +#include <asm/arch/portmux.h>
39 /* Initialized by bootloader-specific startup code. */
40 struct tag *bootloader_tags __initdata;
45 +static struct mci_platform_data __initdata mci0_data = {
46 + .detect_pin = GPIO_PIN_PC(25),
47 + .wp_pin = GPIO_PIN_PE(0),
51 * The next two functions should go away as the boot loader is
52 * supposed to initialize the macb address registers with a valid
54 at32_setup_serial_console(0);
57 +static const struct gpio_led ngw_leds[] = {
58 + { .name = "sys", .gpio = GPIO_PIN_PA(16), .active_low = 1,
59 + .default_trigger = "heartbeat",
61 + { .name = "a", .gpio = GPIO_PIN_PA(19), .active_low = 1, },
62 + { .name = "b", .gpio = GPIO_PIN_PE(19), .active_low = 1, },
65 +static const struct gpio_led_platform_data ngw_led_data = {
66 + .num_leds = ARRAY_SIZE(ngw_leds),
67 + .leds = (void *) ngw_leds,
70 +static struct platform_device ngw_gpio_leds = {
71 + .name = "leds-gpio",
74 + .platform_data = (void *) &ngw_led_data,
78 +#ifdef CONFIG_BOARD_ATNGW100_I2C_GPIO
79 +static struct i2c_gpio_platform_data i2c_gpio_data = {
80 + .sda_pin = GPIO_PIN_PA(6),
81 + .scl_pin = GPIO_PIN_PA(7),
84 +static struct platform_device i2c_gpio_device = {
88 + .platform_data = &i2c_gpio_data,
93 static int __init atngw100_init(void)
98 * ATNGW100 uses 16-bit SDRAM interface, so we don't need to
99 * reserve any pins for it.
101 set_hw_addr(at32_add_device_eth(1, ð_data[1]));
103 at32_add_device_spi(0, spi0_board_info, ARRAY_SIZE(spi0_board_info));
104 + at32_add_device_mci(0, &mci0_data);
105 + at32_add_device_usba(0, NULL);
107 + for (i = 0; i < ARRAY_SIZE(ngw_leds); i++) {
108 + at32_select_gpio(ngw_leds[i].gpio,
109 + AT32_GPIOF_OUTPUT | AT32_GPIOF_HIGH);
111 + platform_device_register(&ngw_gpio_leds);
113 +#ifdef CONFIG_BOARD_ATNGW100_I2C_GPIO
114 + at32_select_gpio(i2c_gpio_data.sda_pin, 0);
115 + at32_select_gpio(i2c_gpio_data.scl_pin, 0);
116 + platform_device_register(&i2c_gpio_device);
118 + at32_add_device_twi(0);
123 diff -x .git -Nur linux-2.6.22.1/arch/avr32/boards/atstk1000/atstk1002.c linux-avr32.git/arch/avr32/boards/atstk1000/atstk1002.c
124 --- linux-2.6.22.1/arch/avr32/boards/atstk1000/atstk1002.c 2007-07-10 20:56:30.000000000 +0200
125 +++ linux-avr32.git/arch/avr32/boards/atstk1000/atstk1002.c 2007-07-12 13:59:49.000000000 +0200
127 #include <linux/etherdevice.h>
128 #include <linux/init.h>
129 #include <linux/kernel.h>
130 +#include <linux/leds.h>
131 #include <linux/platform_device.h>
132 #include <linux/string.h>
133 #include <linux/types.h>
136 #include "atstk1000.h"
138 -#define SW2_DEFAULT /* MMCI and UART_A available */
143 static struct eth_addr __initdata hw_addr[2];
144 static struct eth_platform_data __initdata eth_data[2];
146 +#ifndef CONFIG_BOARD_ATSTK1002_SW1_CUSTOM
147 static struct spi_board_info spi0_board_info[] __initdata = {
156 +#ifdef CONFIG_BOARD_ATSTK1002_SPI1
157 +static struct spi_board_info spi1_board_info[] __initdata = { {
158 + /* patch in custom entries here */
162 +static struct mci_platform_data __initdata mci0_data = {
163 + .detect_pin = GPIO_PIN_NONE,
164 + .wp_pin = GPIO_PIN_NONE,
168 * The next two functions should go away as the boot loader is
169 @@ -101,12 +114,71 @@
173 -void __init setup_board(void)
174 +#ifdef CONFIG_BOARD_ATSTK1002_J2_LED
176 +static struct gpio_led stk_j2_led[] = {
177 +#ifdef CONFIG_BOARD_ATSTK1002_J2_LED8
178 +#define LEDSTRING "J2 jumpered to LED8"
179 + { .name = "led0:amber", .gpio = GPIO_PIN_PB( 8), },
180 + { .name = "led1:amber", .gpio = GPIO_PIN_PB( 9), },
181 + { .name = "led2:amber", .gpio = GPIO_PIN_PB(10), },
182 + { .name = "led3:amber", .gpio = GPIO_PIN_PB(13), },
183 + { .name = "led4:amber", .gpio = GPIO_PIN_PB(14), },
184 + { .name = "led5:amber", .gpio = GPIO_PIN_PB(15), },
185 + { .name = "led6:amber", .gpio = GPIO_PIN_PB(16), },
186 + { .name = "led7:amber", .gpio = GPIO_PIN_PB(30),
187 + .default_trigger = "heartbeat", },
189 +#define LEDSTRING "J2 jumpered to RGB LEDs"
190 + { .name = "r1:red", .gpio = GPIO_PIN_PB( 8), },
191 + { .name = "g1:green", .gpio = GPIO_PIN_PB(10), },
192 + { .name = "b1:blue", .gpio = GPIO_PIN_PB(14), },
194 + { .name = "r2:red", .gpio = GPIO_PIN_PB( 9),
195 + .default_trigger = "heartbeat", },
196 + { .name = "g2:green", .gpio = GPIO_PIN_PB(13), },
197 + { .name = "b2:blue", .gpio = GPIO_PIN_PB(15),
198 + .default_trigger = "heartbeat", },
199 + /* PB16, PB30 unused */
203 +static struct gpio_led_platform_data stk_j2_led_data = {
204 + .num_leds = ARRAY_SIZE(stk_j2_led),
205 + .leds = stk_j2_led,
208 +static struct platform_device stk_j2_led_dev = {
209 + .name = "leds-gpio",
210 + .id = 2, /* gpio block J2 */
212 + .platform_data = &stk_j2_led_data,
216 +static void setup_j2_leds(void)
219 - at32_map_usart(1, 0); /* USART 1/A: /dev/ttyS0, DB9 */
222 + for (i = 0; i < ARRAY_SIZE(stk_j2_led); i++)
223 + at32_select_gpio(stk_j2_led[i].gpio, AT32_GPIOF_OUTPUT);
225 + printk("STK1002: " LEDSTRING "\n");
226 + platform_device_register(&stk_j2_led_dev);
230 +static void setup_j2_leds(void)
235 +void __init setup_board(void)
237 +#ifdef CONFIG_BOARD_ATSTK1002_SW2_CUSTOM
238 at32_map_usart(0, 1); /* USART 0/B: /dev/ttyS1, IRDA */
240 + at32_map_usart(1, 0); /* USART 1/A: /dev/ttyS0, DB9 */
242 /* USART 2/unused: expansion connector */
243 at32_map_usart(3, 2); /* USART 3/C: /dev/ttyS2, DB9 */
244 @@ -140,18 +212,40 @@
246 at32_add_system_devices();
249 - at32_add_device_usart(0);
251 +#ifdef CONFIG_BOARD_ATSTK1002_SW2_CUSTOM
252 at32_add_device_usart(1);
254 + at32_add_device_usart(0);
256 at32_add_device_usart(2);
258 +#ifndef CONFIG_BOARD_ATSTK1002_SW6_CUSTOM
259 set_hw_addr(at32_add_device_eth(0, ð_data[0]));
261 - at32_add_device_spi(0, spi0_board_info, ARRAY_SIZE(spi0_board_info));
263 +#ifdef CONFIG_BOARD_ATSTK1002_SW5_CUSTOM
264 + set_hw_addr(at32_add_device_eth(1, ð_data[1]));
266 at32_add_device_lcdc(0, &atstk1000_lcdc_data,
267 fbmem_start, fbmem_size);
270 +#ifndef CONFIG_BOARD_ATSTK1002_SW1_CUSTOM
271 + at32_add_device_spi(0, spi0_board_info, ARRAY_SIZE(spi0_board_info));
273 +#ifdef CONFIG_BOARD_ATSTK1002_SPI1
274 + at32_add_device_spi(1, spi1_board_info, ARRAY_SIZE(spi1_board_info));
276 + at32_add_device_twi(0);
277 +#ifndef CONFIG_BOARD_ATSTK1002_SW2_CUSTOM
278 + at32_add_device_mci(0, &mci0_data);
280 + at32_add_device_usba(0, NULL);
281 + at32_add_device_abdac(0);
282 +#ifndef CONFIG_BOARD_ATSTK1002_SW3_CUSTOM
283 + at32_add_device_ssc(0, ATMEL_SSC_TX);
290 diff -x .git -Nur linux-2.6.22.1/arch/avr32/boards/atstk1000/Kconfig linux-avr32.git/arch/avr32/boards/atstk1000/Kconfig
291 --- linux-2.6.22.1/arch/avr32/boards/atstk1000/Kconfig 1970-01-01 01:00:00.000000000 +0100
292 +++ linux-avr32.git/arch/avr32/boards/atstk1000/Kconfig 2007-07-12 13:59:49.000000000 +0200
294 +# STK1000 customization
298 +config BOARD_ATSTK1002_CUSTOM
299 + bool "Non-default STK-1002 jumper settings"
301 + You will normally leave the jumpers on the CPU card at their
302 + default settings. If you need to use certain peripherals,
303 + you will need to change some of those jumpers.
305 +if BOARD_ATSTK1002_CUSTOM
307 +config BOARD_ATSTK1002_SW1_CUSTOM
308 + bool "SW1: use SSC1 (not SPI0)"
310 + This also prevents using the external DAC as an audio interface,
311 + and means you can't initialize the on-board QVGA display.
313 +config BOARD_ATSTK1002_SW2_CUSTOM
314 + bool "SW2: use IRDA or TIMER0 (not UART-A, MMC/SD, and PS2-A)"
316 + If you change this you'll want an updated boot loader putting
317 + the console on UART-C not UART-A.
319 +config BOARD_ATSTK1002_SW3_CUSTOM
320 + bool "SW3: use TIMER1 (not SSC0 and GCLK)"
322 + This also prevents using the external DAC as an audio interface.
324 +config BOARD_ATSTK1002_SW4_CUSTOM
325 + bool "SW4: use ISI/Camera (not GPIOs, SPI1, and PS2-B)"
327 + To use the camera interface you'll need a custom card (on the
328 + PCI-format connector) connect a video sensor.
330 +config BOARD_ATSTK1002_SW5_CUSTOM
331 + bool "SW5: use MACB1 (not LCDC)"
333 +config BOARD_ATSTK1002_SW6_CUSTOM
334 + bool "SW6: more GPIOs (not MACB0)"
338 +config BOARD_ATSTK1002_SPI1
339 + bool "Configure SPI1 controller"
340 + depends on !BOARD_ATSTK1002_SW4_CUSTOM
342 + All the signals for the second SPI controller are available on
343 + GPIO lines and accessed through the J1 jumper block. Say "y"
344 + here to configure that SPI controller.
346 +config BOARD_ATSTK1002_J2_LED
348 + default BOARD_ATSTK1002_J2_LED8 || BOARD_ATSTK1002_J2_RGB
351 + prompt "LEDs connected to J2:"
352 + depends on LEDS_GPIO && !BOARD_ATSTK1002_SW4_CUSTOM
355 + Select this if you have jumpered the J2 jumper block to the
356 + LED0..LED7 amber leds, or to the RGB leds, using a ten-pin
357 + IDC cable. A default "heartbeat" trigger is provided, but
358 + you can of course override this.
360 +config BOARD_ATSTK1002_J2_LED8
363 + Select this if J2 is jumpered to LED0..LED7 amber leds.
365 +config BOARD_ATSTK1002_J2_RGB
368 + Select this if J2 is jumpered to the RGB leds.
373 diff -x .git -Nur linux-2.6.22.1/arch/avr32/configs/atngw100_defconfig linux-avr32.git/arch/avr32/configs/atngw100_defconfig
374 --- linux-2.6.22.1/arch/avr32/configs/atngw100_defconfig 2007-07-10 20:56:30.000000000 +0200
375 +++ linux-avr32.git/arch/avr32/configs/atngw100_defconfig 2007-07-13 11:24:16.000000000 +0200
378 # Automatically generated make config: don't edit
379 -# Linux kernel version: 2.6.22-rc5
380 -# Sat Jun 23 15:40:05 2007
381 +# Linux kernel version: 2.6.22.atmel.1
382 +# Thu Jul 12 17:49:20 2007
385 CONFIG_GENERIC_GPIO=y
387 CONFIG_CPU_AT32AP7000=y
388 # CONFIG_BOARD_ATSTK1000 is not set
389 CONFIG_BOARD_ATNGW100=y
390 +# CONFIG_BOARD_ATNGW100_I2C_GPIO is not set
391 CONFIG_LOADER_U_BOOT=y
395 # CONFIG_AP7000_32_BIT_SMC is not set
396 CONFIG_AP7000_16_BIT_SMC=y
397 # CONFIG_AP7000_8_BIT_SMC is not set
399 CONFIG_LOAD_ADDRESS=0x10000000
400 CONFIG_ENTRY_ADDRESS=0x90000000
401 CONFIG_PHYS_OFFSET=0x10000000
403 # CONFIG_RESOURCES_64BIT is not set
404 CONFIG_ZONE_DMA_FLAG=0
405 # CONFIG_OWNERSHIP_TRACE is not set
407 # CONFIG_HZ_100 is not set
409 # CONFIG_HZ_300 is not set
414 +# Power managment options
418 +# CPU Frequency scaling
421 +CONFIG_CPU_FREQ_TABLE=y
422 +# CONFIG_CPU_FREQ_DEBUG is not set
423 +CONFIG_CPU_FREQ_STAT=m
424 +# CONFIG_CPU_FREQ_STAT_DETAILS is not set
425 +CONFIG_CPU_FREQ_DEFAULT_GOV_PERFORMANCE=y
426 +# CONFIG_CPU_FREQ_DEFAULT_GOV_USERSPACE is not set
427 +CONFIG_CPU_FREQ_GOV_PERFORMANCE=y
428 +CONFIG_CPU_FREQ_GOV_POWERSAVE=y
429 +CONFIG_CPU_FREQ_GOV_USERSPACE=y
430 +CONFIG_CPU_FREQ_GOV_ONDEMAND=y
431 +# CONFIG_CPU_FREQ_GOV_CONSERVATIVE is not set
432 +CONFIG_CPU_FREQ_AT32AP=y
437 # CONFIG_ARCH_SUPPORTS_MSI is not set
439 # CONFIG_NET_KEY_MIGRATE is not set
441 CONFIG_IP_MULTICAST=y
442 -CONFIG_IP_ADVANCED_ROUTER=y
443 -CONFIG_ASK_IP_FIB_HASH=y
444 -# CONFIG_IP_FIB_TRIE is not set
445 +# CONFIG_IP_ADVANCED_ROUTER is not set
447 -# CONFIG_IP_MULTIPLE_TABLES is not set
448 -# CONFIG_IP_ROUTE_MULTIPATH is not set
449 -# CONFIG_IP_ROUTE_VERBOSE is not set
452 # CONFIG_IP_PNP_BOOTP is not set
454 # CONFIG_NETWORK_SECMARK is not set
456 # CONFIG_NETFILTER_DEBUG is not set
457 +CONFIG_BRIDGE_NETFILTER=y
460 # Core Netfilter Configuration
462 CONFIG_NETFILTER_XT_MATCH_MARK=m
463 CONFIG_NETFILTER_XT_MATCH_POLICY=m
464 CONFIG_NETFILTER_XT_MATCH_MULTIPORT=m
465 +# CONFIG_NETFILTER_XT_MATCH_PHYSDEV is not set
466 CONFIG_NETFILTER_XT_MATCH_PKTTYPE=m
467 CONFIG_NETFILTER_XT_MATCH_QUOTA=m
468 CONFIG_NETFILTER_XT_MATCH_REALM=m
469 @@ -359,13 +380,19 @@
470 CONFIG_IP6_NF_MANGLE=m
471 CONFIG_IP6_NF_TARGET_HL=m
475 +# Bridge: Netfilter Configuration
477 +# CONFIG_BRIDGE_NF_EBTABLES is not set
478 # CONFIG_IP_DCCP is not set
479 # CONFIG_IP_SCTP is not set
480 # CONFIG_TIPC is not set
481 # CONFIG_ATM is not set
482 -# CONFIG_BRIDGE is not set
485 # CONFIG_DECNET is not set
487 # CONFIG_LLC2 is not set
488 # CONFIG_IPX is not set
489 # CONFIG_ATALK is not set
494 -# CONFIG_BLINK is not set
495 # CONFIG_IDE is not set
498 @@ -545,13 +571,26 @@
499 # CONFIG_BONDING is not set
500 # CONFIG_EQUALIZER is not set
502 -# CONFIG_PHYLIB is not set
506 +# MII PHY device drivers
508 +# CONFIG_MARVELL_PHY is not set
509 +# CONFIG_DAVICOM_PHY is not set
510 +# CONFIG_QSEMI_PHY is not set
511 +# CONFIG_LXT_PHY is not set
512 +# CONFIG_CICADA_PHY is not set
513 +# CONFIG_VITESSE_PHY is not set
514 +# CONFIG_SMSC_PHY is not set
515 +# CONFIG_BROADCOM_PHY is not set
516 +# CONFIG_FIXED_PHY is not set
519 # Ethernet (10 or 100Mbit)
521 CONFIG_NET_ETHERNET=y
523 +# CONFIG_MII is not set
525 # CONFIG_NETDEV_1000 is not set
526 # CONFIG_NETDEV_10000 is not set
530 # CONFIG_IPMI_HANDLER is not set
531 -# CONFIG_WATCHDOG is not set
533 +# CONFIG_WATCHDOG_NOWAYOUT is not set
536 +# Watchdog Device Drivers
538 +# CONFIG_SOFT_WATCHDOG is not set
539 +CONFIG_AT32AP700X_WDT=y
540 +CONFIG_AT32AP700X_WDT_TIMEOUT=2
541 # CONFIG_HW_RANDOM is not set
542 # CONFIG_RTC is not set
543 # CONFIG_GEN_RTC is not set
547 # CONFIG_TCG_TPM is not set
548 -# CONFIG_I2C is not set
550 +CONFIG_I2C_BOARDINFO=y
551 +CONFIG_I2C_CHARDEV=m
556 +CONFIG_I2C_ALGOBIT=m
557 +# CONFIG_I2C_ALGOPCF is not set
558 +# CONFIG_I2C_ALGOPCA is not set
561 +# I2C Hardware Bus support
563 +CONFIG_I2C_ATMELTWI=m
564 +CONFIG_I2C_ATMELTWI_BAUDRATE=100000
566 +# CONFIG_I2C_OCORES is not set
567 +# CONFIG_I2C_PARPORT_LIGHT is not set
568 +# CONFIG_I2C_SIMTEC is not set
569 +# CONFIG_I2C_STUB is not set
572 +# Miscellaneous I2C Chip support
574 +# CONFIG_SENSORS_DS1337 is not set
575 +# CONFIG_SENSORS_DS1374 is not set
576 +# CONFIG_SENSORS_EEPROM is not set
577 +# CONFIG_SENSORS_PCF8574 is not set
578 +# CONFIG_SENSORS_PCA9539 is not set
579 +# CONFIG_SENSORS_PCF8591 is not set
580 +# CONFIG_SENSORS_MAX6875 is not set
581 +# CONFIG_I2C_DEBUG_CORE is not set
582 +# CONFIG_I2C_DEBUG_ALGO is not set
583 +# CONFIG_I2C_DEBUG_BUS is not set
584 +# CONFIG_I2C_DEBUG_CHIP is not set
589 # SPI Protocol Masters
591 # CONFIG_SPI_AT25 is not set
592 -# CONFIG_SPI_SPIDEV is not set
596 # Dallas's 1-wire bus
597 @@ -706,21 +788,59 @@
601 -# CONFIG_USB_GADGET is not set
602 -# CONFIG_MMC is not set
604 +# CONFIG_USB_GADGET_DEBUG_FILES is not set
605 +CONFIG_USB_GADGET_SELECTED=y
606 +# CONFIG_USB_GADGET_FSL_USB2 is not set
607 +# CONFIG_USB_GADGET_NET2280 is not set
608 +# CONFIG_USB_GADGET_PXA2XX is not set
609 +# CONFIG_USB_GADGET_GOKU is not set
610 +# CONFIG_USB_GADGET_LH7A40X is not set
611 +CONFIG_USB_GADGET_ATMEL_USBA=y
612 +CONFIG_USB_ATMEL_USBA=y
613 +# CONFIG_USB_GADGET_OMAP is not set
614 +# CONFIG_USB_GADGET_AT91 is not set
615 +# CONFIG_USB_GADGET_DUMMY_HCD is not set
616 +CONFIG_USB_GADGET_DUALSPEED=y
619 +CONFIG_USB_ETH_RNDIS=y
620 +CONFIG_USB_GADGETFS=m
621 +CONFIG_USB_FILE_STORAGE=m
622 +# CONFIG_USB_FILE_STORAGE_TEST is not set
623 +CONFIG_USB_G_SERIAL=m
624 +# CONFIG_USB_MIDI_GADGET is not set
626 +# CONFIG_MMC_DEBUG is not set
627 +# CONFIG_MMC_UNSAFE_RESUME is not set
630 +# MMC/SD Card Drivers
635 +# MMC/SD Host Controller Drivers
637 +CONFIG_MMC_ATMELMCI=y
642 -# CONFIG_NEW_LEDS is not set
654 +CONFIG_LEDS_TRIGGERS=y
655 +CONFIG_LEDS_TRIGGER_TIMER=y
656 +CONFIG_LEDS_TRIGGER_HEARTBEAT=y
664 -# CONFIG_RTC_CLASS is not set
667 +CONFIG_RTC_HCTOSYS=y
668 +CONFIG_RTC_HCTOSYS_DEVICE="rtc0"
669 +# CONFIG_RTC_DEBUG is not set
674 +CONFIG_RTC_INTF_SYSFS=y
675 +CONFIG_RTC_INTF_PROC=y
676 +CONFIG_RTC_INTF_DEV=y
677 +# CONFIG_RTC_INTF_DEV_UIE_EMUL is not set
678 +# CONFIG_RTC_DRV_TEST is not set
683 +# CONFIG_RTC_DRV_DS1307 is not set
684 +# CONFIG_RTC_DRV_DS1672 is not set
685 +# CONFIG_RTC_DRV_MAX6900 is not set
686 +# CONFIG_RTC_DRV_RS5C372 is not set
687 +# CONFIG_RTC_DRV_ISL1208 is not set
688 +# CONFIG_RTC_DRV_X1205 is not set
689 +# CONFIG_RTC_DRV_PCF8563 is not set
690 +# CONFIG_RTC_DRV_PCF8583 is not set
695 +# CONFIG_RTC_DRV_RS5C348 is not set
696 +# CONFIG_RTC_DRV_MAX6902 is not set
699 +# Platform RTC drivers
701 +# CONFIG_RTC_DRV_DS1553 is not set
702 +# CONFIG_RTC_DRV_DS1742 is not set
703 +# CONFIG_RTC_DRV_M48T86 is not set
704 +# CONFIG_RTC_DRV_V3020 is not set
707 +# on-CPU RTC drivers
709 +CONFIG_RTC_DRV_AT32AP700X=y
714 # CONFIG_OCFS2_FS is not set
715 # CONFIG_MINIX_FS is not set
716 # CONFIG_ROMFS_FS is not set
717 -# CONFIG_INOTIFY is not set
719 +CONFIG_INOTIFY_USER=y
720 # CONFIG_QUOTA is not set
721 # CONFIG_DNOTIFY is not set
722 # CONFIG_AUTOFS_FS is not set
724 CONFIG_ENABLE_MUST_CHECK=y
726 # CONFIG_UNUSED_SYMBOLS is not set
727 -# CONFIG_DEBUG_FS is not set
729 # CONFIG_HEADERS_CHECK is not set
730 CONFIG_DEBUG_KERNEL=y
731 # CONFIG_DEBUG_SHIRQ is not set
732 diff -x .git -Nur linux-2.6.22.1/arch/avr32/configs/atstk1002_defconfig linux-avr32.git/arch/avr32/configs/atstk1002_defconfig
733 --- linux-2.6.22.1/arch/avr32/configs/atstk1002_defconfig 2007-07-10 20:56:30.000000000 +0200
734 +++ linux-avr32.git/arch/avr32/configs/atstk1002_defconfig 2007-07-13 11:24:16.000000000 +0200
737 # Automatically generated make config: don't edit
738 -# Linux kernel version: 2.6.22-rc5
739 -# Sat Jun 23 15:32:08 2007
740 +# Linux kernel version: 2.6.22.atmel.1
741 +# Thu Jul 12 19:34:17 2007
744 CONFIG_GENERIC_GPIO=y
748 CONFIG_MODULE_UNLOAD=y
749 -# CONFIG_MODULE_FORCE_UNLOAD is not set
750 +CONFIG_MODULE_FORCE_UNLOAD=y
751 # CONFIG_MODVERSIONS is not set
752 # CONFIG_MODULE_SRCVERSION_ALL is not set
753 -# CONFIG_KMOD is not set
759 CONFIG_IOSCHED_NOOP=y
760 # CONFIG_IOSCHED_AS is not set
761 # CONFIG_IOSCHED_DEADLINE is not set
762 -# CONFIG_IOSCHED_CFQ is not set
763 +CONFIG_IOSCHED_CFQ=y
764 # CONFIG_DEFAULT_AS is not set
765 # CONFIG_DEFAULT_DEADLINE is not set
766 -# CONFIG_DEFAULT_CFQ is not set
767 -CONFIG_DEFAULT_NOOP=y
768 -CONFIG_DEFAULT_IOSCHED="noop"
769 +CONFIG_DEFAULT_CFQ=y
770 +# CONFIG_DEFAULT_NOOP is not set
771 +CONFIG_DEFAULT_IOSCHED="cfq"
774 # System Type and features
776 CONFIG_BOARD_ATSTK1002=y
777 CONFIG_BOARD_ATSTK1000=y
778 # CONFIG_BOARD_ATNGW100 is not set
779 +# CONFIG_BOARD_ATSTK1002_CUSTOM is not set
780 +# CONFIG_BOARD_ATSTK1002_SPI1 is not set
781 +# CONFIG_BOARD_ATSTK1002_J2_LED is not set
782 +# CONFIG_BOARD_ATSTK1002_J2_LED8 is not set
783 +# CONFIG_BOARD_ATSTK1002_J2_RGB is not set
784 CONFIG_LOADER_U_BOOT=y
788 # CONFIG_AP7000_32_BIT_SMC is not set
789 CONFIG_AP7000_16_BIT_SMC=y
790 # CONFIG_AP7000_8_BIT_SMC is not set
792 CONFIG_LOAD_ADDRESS=0x10000000
793 CONFIG_ENTRY_ADDRESS=0x90000000
794 CONFIG_PHYS_OFFSET=0x10000000
796 # CONFIG_RESOURCES_64BIT is not set
797 CONFIG_ZONE_DMA_FLAG=0
798 # CONFIG_OWNERSHIP_TRACE is not set
800 # CONFIG_HZ_100 is not set
802 # CONFIG_HZ_300 is not set
807 +# Power managment options
811 +# CPU Frequency scaling
814 +CONFIG_CPU_FREQ_TABLE=y
815 +# CONFIG_CPU_FREQ_DEBUG is not set
816 +CONFIG_CPU_FREQ_STAT=m
817 +# CONFIG_CPU_FREQ_STAT_DETAILS is not set
818 +CONFIG_CPU_FREQ_DEFAULT_GOV_PERFORMANCE=y
819 +# CONFIG_CPU_FREQ_DEFAULT_GOV_USERSPACE is not set
820 +CONFIG_CPU_FREQ_GOV_PERFORMANCE=y
821 +CONFIG_CPU_FREQ_GOV_POWERSAVE=y
822 +CONFIG_CPU_FREQ_GOV_USERSPACE=y
823 +CONFIG_CPU_FREQ_GOV_ONDEMAND=y
824 +# CONFIG_CPU_FREQ_GOV_CONSERVATIVE is not set
825 +CONFIG_CPU_FREQ_AT32AP=y
830 # CONFIG_ARCH_SUPPORTS_MSI is not set
833 # Self-contained MTD device drivers
835 +CONFIG_MTD_DATAFLASH=m
836 +# CONFIG_MTD_M25P80 is not set
837 # CONFIG_MTD_SLRAM is not set
838 # CONFIG_MTD_PHRAM is not set
839 # CONFIG_MTD_MTDRAM is not set
844 -# CONFIG_BLINK is not set
845 # CONFIG_IDE is not set
848 @@ -397,13 +426,26 @@
849 # CONFIG_BONDING is not set
850 # CONFIG_EQUALIZER is not set
852 -# CONFIG_PHYLIB is not set
856 +# MII PHY device drivers
858 +# CONFIG_MARVELL_PHY is not set
859 +# CONFIG_DAVICOM_PHY is not set
860 +# CONFIG_QSEMI_PHY is not set
862 +# CONFIG_CICADA_PHY is not set
863 +# CONFIG_VITESSE_PHY is not set
864 +# CONFIG_SMSC_PHY is not set
865 +# CONFIG_BROADCOM_PHY is not set
866 +# CONFIG_FIXED_PHY is not set
869 # Ethernet (10 or 100Mbit)
871 CONFIG_NET_ETHERNET=y
873 +# CONFIG_MII is not set
875 # CONFIG_NETDEV_1000 is not set
876 # CONFIG_NETDEV_10000 is not set
879 # Input device support
881 -# CONFIG_INPUT is not set
883 +# CONFIG_INPUT_FF_MEMLESS is not set
884 +CONFIG_INPUT_POLLDEV=m
887 +# Userland interfaces
889 +CONFIG_INPUT_MOUSEDEV=m
890 +CONFIG_INPUT_MOUSEDEV_PSAUX=y
891 +CONFIG_INPUT_MOUSEDEV_SCREEN_X=1024
892 +CONFIG_INPUT_MOUSEDEV_SCREEN_Y=768
893 +# CONFIG_INPUT_JOYDEV is not set
894 +# CONFIG_INPUT_TSDEV is not set
895 +# CONFIG_INPUT_EVDEV is not set
896 +# CONFIG_INPUT_EVBUG is not set
899 +# Input Device Drivers
901 +CONFIG_INPUT_KEYBOARD=y
902 +# CONFIG_KEYBOARD_ATKBD is not set
903 +# CONFIG_KEYBOARD_SUNKBD is not set
904 +# CONFIG_KEYBOARD_LKKBD is not set
905 +# CONFIG_KEYBOARD_XTKBD is not set
906 +# CONFIG_KEYBOARD_NEWTON is not set
907 +# CONFIG_KEYBOARD_STOWAWAY is not set
908 +CONFIG_KEYBOARD_GPIO=m
909 +CONFIG_INPUT_MOUSE=y
910 +# CONFIG_MOUSE_PS2 is not set
911 +# CONFIG_MOUSE_SERIAL is not set
912 +# CONFIG_MOUSE_VSXXXAA is not set
914 +# CONFIG_INPUT_JOYSTICK is not set
915 +# CONFIG_INPUT_TABLET is not set
916 +# CONFIG_INPUT_TOUCHSCREEN is not set
917 +# CONFIG_INPUT_MISC is not set
924 # CONFIG_IPMI_HANDLER is not set
925 -# CONFIG_WATCHDOG is not set
927 +# CONFIG_WATCHDOG_NOWAYOUT is not set
930 +# Watchdog Device Drivers
932 +# CONFIG_SOFT_WATCHDOG is not set
933 +CONFIG_AT32AP700X_WDT=y
934 +CONFIG_AT32AP700X_WDT_TIMEOUT=2
935 # CONFIG_HW_RANDOM is not set
936 # CONFIG_RTC is not set
937 # CONFIG_GEN_RTC is not set
938 @@ -488,13 +573,61 @@
941 # CONFIG_TCG_TPM is not set
942 -# CONFIG_I2C is not set
944 +CONFIG_I2C_BOARDINFO=y
945 +CONFIG_I2C_CHARDEV=m
950 +CONFIG_I2C_ALGOBIT=m
951 +# CONFIG_I2C_ALGOPCF is not set
952 +# CONFIG_I2C_ALGOPCA is not set
955 +# I2C Hardware Bus support
957 +CONFIG_I2C_ATMELTWI=m
958 +CONFIG_I2C_ATMELTWI_BAUDRATE=100000
960 +# CONFIG_I2C_OCORES is not set
961 +# CONFIG_I2C_PARPORT_LIGHT is not set
962 +# CONFIG_I2C_SIMTEC is not set
963 +# CONFIG_I2C_STUB is not set
966 +# Miscellaneous I2C Chip support
968 +# CONFIG_SENSORS_DS1337 is not set
969 +# CONFIG_SENSORS_DS1374 is not set
970 +# CONFIG_SENSORS_EEPROM is not set
971 +# CONFIG_SENSORS_PCF8574 is not set
972 +# CONFIG_SENSORS_PCA9539 is not set
973 +# CONFIG_SENSORS_PCF8591 is not set
974 +# CONFIG_SENSORS_MAX6875 is not set
975 +# CONFIG_I2C_DEBUG_CORE is not set
976 +# CONFIG_I2C_DEBUG_ALGO is not set
977 +# CONFIG_I2C_DEBUG_BUS is not set
978 +# CONFIG_I2C_DEBUG_CHIP is not set
983 -# CONFIG_SPI is not set
984 -# CONFIG_SPI_MASTER is not set
986 +# CONFIG_SPI_DEBUG is not set
990 +# SPI Master Controller Drivers
993 +# CONFIG_SPI_BITBANG is not set
996 +# SPI Protocol Masters
998 +# CONFIG_SPI_AT25 is not set
1002 # Dallas's 1-wire bus
1003 @@ -517,14 +650,40 @@
1007 -# CONFIG_BACKLIGHT_LCD_SUPPORT is not set
1008 +CONFIG_BACKLIGHT_LCD_SUPPORT=y
1009 +CONFIG_LCD_CLASS_DEVICE=y
1010 +CONFIG_LCD_LTV350QV=y
1011 +# CONFIG_BACKLIGHT_CLASS_DEVICE is not set
1014 # Display device support
1016 # CONFIG_DISPLAY_SUPPORT is not set
1017 # CONFIG_VGASTATE is not set
1018 -# CONFIG_FB is not set
1020 +# CONFIG_FIRMWARE_EDID is not set
1021 +# CONFIG_FB_DDC is not set
1022 +CONFIG_FB_CFB_FILLRECT=y
1023 +CONFIG_FB_CFB_COPYAREA=y
1024 +CONFIG_FB_CFB_IMAGEBLIT=y
1025 +# CONFIG_FB_SYS_FILLRECT is not set
1026 +# CONFIG_FB_SYS_COPYAREA is not set
1027 +# CONFIG_FB_SYS_IMAGEBLIT is not set
1028 +# CONFIG_FB_SYS_FOPS is not set
1029 +CONFIG_FB_DEFERRED_IO=y
1030 +# CONFIG_FB_SVGALIB is not set
1031 +# CONFIG_FB_MACMODES is not set
1032 +# CONFIG_FB_BACKLIGHT is not set
1033 +# CONFIG_FB_MODE_HELPERS is not set
1034 +# CONFIG_FB_TILEBLITTING is not set
1037 +# Frame buffer hardware drivers
1039 +# CONFIG_FB_S1D13XXX is not set
1041 +# CONFIG_FB_VIRTUAL is not set
1042 +# CONFIG_LOGO is not set
1046 @@ -532,6 +691,11 @@
1047 # CONFIG_SOUND is not set
1052 +# CONFIG_HID is not set
1057 # CONFIG_USB_ARCH_HAS_HCD is not set
1058 @@ -545,21 +709,59 @@
1060 # USB Gadget Support
1062 -# CONFIG_USB_GADGET is not set
1063 -# CONFIG_MMC is not set
1064 +CONFIG_USB_GADGET=y
1065 +# CONFIG_USB_GADGET_DEBUG_FILES is not set
1066 +CONFIG_USB_GADGET_SELECTED=y
1067 +# CONFIG_USB_GADGET_FSL_USB2 is not set
1068 +# CONFIG_USB_GADGET_NET2280 is not set
1069 +# CONFIG_USB_GADGET_PXA2XX is not set
1070 +# CONFIG_USB_GADGET_GOKU is not set
1071 +# CONFIG_USB_GADGET_LH7A40X is not set
1072 +CONFIG_USB_GADGET_ATMEL_USBA=y
1073 +CONFIG_USB_ATMEL_USBA=y
1074 +# CONFIG_USB_GADGET_OMAP is not set
1075 +# CONFIG_USB_GADGET_AT91 is not set
1076 +# CONFIG_USB_GADGET_DUMMY_HCD is not set
1077 +CONFIG_USB_GADGET_DUALSPEED=y
1080 +CONFIG_USB_ETH_RNDIS=y
1081 +CONFIG_USB_GADGETFS=m
1082 +CONFIG_USB_FILE_STORAGE=m
1083 +# CONFIG_USB_FILE_STORAGE_TEST is not set
1084 +CONFIG_USB_G_SERIAL=m
1085 +# CONFIG_USB_MIDI_GADGET is not set
1087 +# CONFIG_MMC_DEBUG is not set
1088 +# CONFIG_MMC_UNSAFE_RESUME is not set
1091 +# MMC/SD Card Drivers
1096 +# MMC/SD Host Controller Drivers
1098 +CONFIG_MMC_ATMELMCI=y
1103 -# CONFIG_NEW_LEDS is not set
1105 +CONFIG_LEDS_CLASS=m
1115 +CONFIG_LEDS_TRIGGERS=y
1116 +CONFIG_LEDS_TRIGGER_TIMER=m
1117 +CONFIG_LEDS_TRIGGER_HEARTBEAT=m
1120 # InfiniBand support
1121 @@ -572,7 +774,50 @@
1125 -# CONFIG_RTC_CLASS is not set
1128 +# CONFIG_RTC_HCTOSYS is not set
1129 +# CONFIG_RTC_DEBUG is not set
1134 +CONFIG_RTC_INTF_SYSFS=y
1135 +CONFIG_RTC_INTF_PROC=y
1136 +CONFIG_RTC_INTF_DEV=y
1137 +# CONFIG_RTC_INTF_DEV_UIE_EMUL is not set
1138 +# CONFIG_RTC_DRV_TEST is not set
1143 +# CONFIG_RTC_DRV_DS1307 is not set
1144 +# CONFIG_RTC_DRV_DS1672 is not set
1145 +# CONFIG_RTC_DRV_MAX6900 is not set
1146 +# CONFIG_RTC_DRV_RS5C372 is not set
1147 +# CONFIG_RTC_DRV_ISL1208 is not set
1148 +# CONFIG_RTC_DRV_X1205 is not set
1149 +# CONFIG_RTC_DRV_PCF8563 is not set
1150 +# CONFIG_RTC_DRV_PCF8583 is not set
1155 +# CONFIG_RTC_DRV_RS5C348 is not set
1156 +# CONFIG_RTC_DRV_MAX6902 is not set
1159 +# Platform RTC drivers
1161 +# CONFIG_RTC_DRV_DS1553 is not set
1162 +# CONFIG_RTC_DRV_DS1742 is not set
1163 +# CONFIG_RTC_DRV_M48T86 is not set
1164 +# CONFIG_RTC_DRV_V3020 is not set
1167 +# on-CPU RTC drivers
1169 +CONFIG_RTC_DRV_AT32AP700X=y
1172 # DMA Engine support
1173 @@ -590,11 +835,14 @@
1179 # CONFIG_EXT2_FS_XATTR is not set
1180 # CONFIG_EXT2_FS_XIP is not set
1181 -# CONFIG_EXT3_FS is not set
1183 +# CONFIG_EXT3_FS_XATTR is not set
1184 # CONFIG_EXT4DEV_FS is not set
1186 +# CONFIG_JBD_DEBUG is not set
1187 # CONFIG_REISERFS_FS is not set
1188 # CONFIG_JFS_FS is not set
1189 # CONFIG_FS_POSIX_ACL is not set
1191 # CONFIG_DNOTIFY is not set
1192 # CONFIG_AUTOFS_FS is not set
1193 # CONFIG_AUTOFS4_FS is not set
1194 -# CONFIG_FUSE_FS is not set
1198 # CD-ROM/DVD Filesystems
1200 # CONFIG_TMPFS_POSIX_ACL is not set
1201 # CONFIG_HUGETLB_PAGE is not set
1203 -CONFIG_CONFIGFS_FS=m
1204 +CONFIG_CONFIGFS_FS=y
1207 # Miscellaneous filesystems
1208 @@ -683,8 +931,14 @@
1209 # CONFIG_SUNRPC_BIND34 is not set
1210 # CONFIG_RPCSEC_GSS_KRB5 is not set
1211 # CONFIG_RPCSEC_GSS_SPKM3 is not set
1212 -# CONFIG_SMB_FS is not set
1213 -# CONFIG_CIFS is not set
1215 +# CONFIG_SMB_NLS_DEFAULT is not set
1217 +# CONFIG_CIFS_STATS is not set
1218 +# CONFIG_CIFS_WEAK_PW_HASH is not set
1219 +# CONFIG_CIFS_XATTR is not set
1220 +# CONFIG_CIFS_DEBUG2 is not set
1221 +# CONFIG_CIFS_EXPERIMENTAL is not set
1222 # CONFIG_NCP_FS is not set
1223 # CONFIG_CODA_FS is not set
1224 # CONFIG_AFS_FS is not set
1225 diff -x .git -Nur linux-2.6.22.1/arch/avr32/drivers/dw-dmac.c linux-avr32.git/arch/avr32/drivers/dw-dmac.c
1226 --- linux-2.6.22.1/arch/avr32/drivers/dw-dmac.c 1970-01-01 01:00:00.000000000 +0100
1227 +++ linux-avr32.git/arch/avr32/drivers/dw-dmac.c 2007-07-13 11:24:16.000000000 +0200
1230 + * Driver for the Synopsys DesignWare DMA Controller
1232 + * Copyright (C) 2005-2006 Atmel Corporation
1234 + * This program is free software; you can redistribute it and/or modify
1235 + * it under the terms of the GNU General Public License version 2 as
1236 + * published by the Free Software Foundation.
1238 +#include <linux/clk.h>
1239 +#include <linux/device.h>
1240 +#include <linux/dma-mapping.h>
1241 +#include <linux/dmapool.h>
1242 +#include <linux/init.h>
1243 +#include <linux/interrupt.h>
1244 +#include <linux/module.h>
1245 +#include <linux/platform_device.h>
1247 +#include <asm/dma-controller.h>
1248 +#include <asm/io.h>
1250 +#include "dw-dmac.h"
1252 +#define DMAC_NR_CHANNELS 3
1253 +#define DMAC_MAX_BLOCKSIZE 4095
1256 + CH_STATE_FREE = 0,
1257 + CH_STATE_ALLOCATED,
1261 +struct dw_dma_lli {
1271 +struct dw_dma_block {
1272 + struct dw_dma_lli *lli_vaddr;
1273 + dma_addr_t lli_dma_addr;
1276 +struct dw_dma_channel {
1277 + unsigned int state;
1279 + struct dma_request_sg *req_sg;
1280 + struct dma_request_cyclic *req_cyclic;
1281 + unsigned int nr_blocks;
1283 + struct dw_dma_block *block;
1286 +struct dw_dma_controller {
1288 + void * __iomem regs;
1289 + struct dma_pool *lli_pool;
1291 + struct dma_controller dma;
1292 + struct dw_dma_channel channel[DMAC_NR_CHANNELS];
1294 +#define to_dw_dmac(dmac) container_of(dmac, struct dw_dma_controller, dma)
1296 +#define dmac_writel_hi(dmac, reg, value) \
1297 + __raw_writel((value), (dmac)->regs + DW_DMAC_##reg + 4)
1298 +#define dmac_readl_hi(dmac, reg) \
1299 + __raw_readl((dmac)->regs + DW_DMAC_##reg + 4)
1300 +#define dmac_writel_lo(dmac, reg, value) \
1301 + __raw_writel((value), (dmac)->regs + DW_DMAC_##reg)
1302 +#define dmac_readl_lo(dmac, reg) \
1303 + __raw_readl((dmac)->regs + DW_DMAC_##reg)
1304 +#define dmac_chan_writel_hi(dmac, chan, reg, value) \
1305 + __raw_writel((value), ((dmac)->regs + 0x58 * (chan) \
1306 + + DW_DMAC_CHAN_##reg + 4))
1307 +#define dmac_chan_readl_hi(dmac, chan, reg) \
1308 + __raw_readl((dmac)->regs + 0x58 * (chan) + DW_DMAC_CHAN_##reg + 4)
1309 +#define dmac_chan_writel_lo(dmac, chan, reg, value) \
1310 + __raw_writel((value), (dmac)->regs + 0x58 * (chan) + DW_DMAC_CHAN_##reg)
1311 +#define dmac_chan_readl_lo(dmac, chan, reg) \
1312 + __raw_readl((dmac)->regs + 0x58 * (chan) + DW_DMAC_CHAN_##reg)
1313 +#define set_channel_bit(dmac, reg, chan) \
1314 + dmac_writel_lo(dmac, reg, (1 << (chan)) | (1 << ((chan) + 8)))
1315 +#define clear_channel_bit(dmac, reg, chan) \
1316 + dmac_writel_lo(dmac, reg, (0 << (chan)) | (1 << ((chan) + 8)))
1318 +static int dmac_alloc_channel(struct dma_controller *_dmac)
1320 + struct dw_dma_controller *dmac = to_dw_dmac(_dmac);
1321 + struct dw_dma_channel *chan;
1322 + unsigned long flags;
1325 + spin_lock_irqsave(&dmac->lock, flags);
1326 + for (i = 0; i < DMAC_NR_CHANNELS; i++)
1327 + if (dmac->channel[i].state == CH_STATE_FREE)
1330 + if (i < DMAC_NR_CHANNELS) {
1331 + chan = &dmac->channel[i];
1332 + chan->state = CH_STATE_ALLOCATED;
1337 + spin_unlock_irqrestore(&dmac->lock, flags);
1342 +static void dmac_release_channel(struct dma_controller *_dmac, int channel)
1344 + struct dw_dma_controller *dmac = to_dw_dmac(_dmac);
1346 + BUG_ON(channel >= DMAC_NR_CHANNELS
1347 + || dmac->channel[channel].state != CH_STATE_ALLOCATED);
1349 + dmac->channel[channel].state = CH_STATE_FREE;
1352 +static struct dw_dma_block *allocate_blocks(struct dw_dma_controller *dmac,
1353 + unsigned int nr_blocks)
1355 + struct dw_dma_block *block;
1359 + block = kmalloc(nr_blocks * sizeof(*block),
1361 + if (unlikely(!block))
1364 + for (i = 0; i < nr_blocks; i++) {
1365 + p = dma_pool_alloc(dmac->lli_pool, GFP_KERNEL,
1366 + &block[i].lli_dma_addr);
1367 + block[i].lli_vaddr = p;
1375 + for (i = 0; i < nr_blocks; i++) {
1376 + if (!block[i].lli_vaddr)
1378 + dma_pool_free(dmac->lli_pool, block[i].lli_vaddr,
1379 + block[i].lli_dma_addr);
1385 +static void cleanup_channel(struct dw_dma_controller *dmac,
1386 + struct dw_dma_channel *chan)
1390 + if (chan->nr_blocks > 1) {
1391 + for (i = 0; i < chan->nr_blocks; i++)
1392 + dma_pool_free(dmac->lli_pool, chan->block[i].lli_vaddr,
1393 + chan->block[i].lli_dma_addr);
1394 + kfree(chan->block);
1397 + chan->state = CH_STATE_ALLOCATED;
1400 +static int dmac_prepare_request_sg(struct dma_controller *_dmac,
1401 + struct dma_request_sg *req)
1403 + struct dw_dma_controller *dmac = to_dw_dmac(_dmac);
1404 + struct dw_dma_channel *chan;
1405 + unsigned long ctlhi, ctllo, cfghi, cfglo;
1406 + unsigned long block_size;
1407 + unsigned int nr_blocks;
1408 + int ret, i, direction;
1409 + unsigned long flags;
1411 + spin_lock_irqsave(&dmac->lock, flags);
1414 + if (req->req.channel >= DMAC_NR_CHANNELS
1415 + || dmac->channel[req->req.channel].state != CH_STATE_ALLOCATED
1416 + || req->block_size > DMAC_MAX_BLOCKSIZE) {
1417 + spin_unlock_irqrestore(&dmac->lock, flags);
1421 + chan = &dmac->channel[req->req.channel];
1422 + chan->state = CH_STATE_BUSY;
1423 + chan->req_sg = req;
1424 + chan->is_cyclic = 0;
1427 + * We have marked the channel as busy, so no need to keep the
1428 + * lock as long as we only touch the channel-specific
1431 + spin_unlock_irqrestore(&dmac->lock, flags);
1434 + * There may be limitations in the driver and/or the DMA
1435 + * controller that prevents us from sending a whole
1436 + * scatterlist item in one go. Taking this into account,
1437 + * calculate the number of block transfers we need to set up.
1439 + * FIXME: Let the peripheral driver know about the maximum
1440 + * block size we support. We really don't want to use a
1441 + * different block size than what was suggested by the
1444 + * Each block will get its own Linked List Item (LLI) below.
1446 + block_size = req->block_size;
1447 + nr_blocks = req->nr_blocks;
1448 + pr_debug("block_size %lu, nr_blocks %u nr_sg = %u\n",
1449 + block_size, nr_blocks, req->nr_sg);
1451 + BUG_ON(nr_blocks == 0);
1452 + chan->nr_blocks = nr_blocks;
1455 + cfglo = cfghi = 0;
1456 + switch (req->direction) {
1457 + case DMA_DIR_MEM_TO_PERIPH:
1458 + direction = DMA_TO_DEVICE;
1459 + cfghi = req->periph_id << (43 - 32);
1462 + case DMA_DIR_PERIPH_TO_MEM:
1463 + direction = DMA_FROM_DEVICE;
1464 + cfghi = req->periph_id << (39 - 32);
1467 + goto out_unclaim_channel;
1470 + chan->direction = direction;
1472 + dmac_chan_writel_hi(dmac, req->req.channel, CFG, cfghi);
1473 + dmac_chan_writel_lo(dmac, req->req.channel, CFG, cfglo);
1475 + ctlhi = block_size >> req->width;
1476 + ctllo = ((req->direction << 20)
1477 + // | (1 << 14) | (1 << 11) // source/dest burst trans len
1478 + | (req->width << 4) | (req->width << 1)
1479 + | (1 << 0)); // interrupt enable
1481 + if (nr_blocks == 1) {
1482 + /* Only one block: No need to use block chaining */
1483 + if (direction == DMA_TO_DEVICE) {
1484 + dmac_chan_writel_lo(dmac, req->req.channel, SAR,
1485 + req->sg->dma_address);
1486 + dmac_chan_writel_lo(dmac, req->req.channel, DAR,
1488 + ctllo |= 2 << 7; // no dst increment
1490 + dmac_chan_writel_lo(dmac, req->req.channel, SAR,
1492 + dmac_chan_writel_lo(dmac, req->req.channel, DAR,
1493 + req->sg->dma_address);
1494 + ctllo |= 2 << 9; // no src increment
1496 + dmac_chan_writel_lo(dmac, req->req.channel, CTL, ctllo);
1497 + dmac_chan_writel_hi(dmac, req->req.channel, CTL, ctlhi);
1498 + pr_debug("ctl hi:lo 0x%lx:%lx\n", ctlhi, ctllo);
1500 + struct dw_dma_lli *lli, *lli_prev = NULL;
1501 + int j = 0, offset = 0;
1504 + chan->block = allocate_blocks(dmac, nr_blocks);
1506 + goto out_unclaim_channel;
1508 + if (direction == DMA_TO_DEVICE)
1509 + ctllo |= 1 << 28 | 1 << 27 | 2 << 7;
1511 + ctllo |= 1 << 28 | 1 << 27 | 2 << 9;
1514 + * Map scatterlist items to blocks. One scatterlist
1515 + * item may need more than one block for the reasons
1516 + * mentioned above.
1518 + for (i = 0; i < nr_blocks; i++) {
1519 + lli = chan->block[i].lli_vaddr;
1521 + lli_prev->llp = chan->block[i].lli_dma_addr;
1522 + pr_debug("lli[%d] (0x%p/0x%x): 0x%x 0x%x 0x%x 0x%x 0x%x\n",
1523 + i - 1, chan->block[i - 1].lli_vaddr,
1524 + chan->block[i - 1].lli_dma_addr,
1525 + lli_prev->sar, lli_prev->dar, lli_prev->llp,
1526 + lli_prev->ctllo, lli_prev->ctlhi);
1529 + lli->ctllo = ctllo;
1530 + lli->ctlhi = ctlhi;
1531 + if (direction == DMA_TO_DEVICE) {
1532 + lli->sar = req->sg[j].dma_address + offset;
1533 + lli->dar = req->data_reg;
1535 + lli->sar = req->data_reg;
1536 + lli->dar = req->sg[j].dma_address + offset;
1540 + offset += block_size;
1541 + if (offset > req->sg[j].length) {
1547 + pr_debug("lli[%d] (0x%p/0x%x): 0x%x 0x%x 0x%x 0x%x 0x%x\n",
1548 + i - 1, chan->block[i - 1].lli_vaddr,
1549 + chan->block[i - 1].lli_dma_addr, lli_prev->sar,
1550 + lli_prev->dar, lli_prev->llp,
1551 + lli_prev->ctllo, lli_prev->ctlhi);
1554 + * SAR, DAR and CTL are initialized from the LLI. We
1555 + * only have to enable the LLI bits in CTL.
1557 + dmac_chan_writel_hi(dmac, req->req.channel, CTL, 0);
1558 + dmac_chan_writel_lo(dmac, req->req.channel, LLP,
1559 + chan->block[0].lli_dma_addr);
1560 + dmac_chan_writel_lo(dmac, req->req.channel, CTL, 1 << 28 | 1 << 27);
1563 + set_channel_bit(dmac, MASK_XFER, req->req.channel);
1564 + set_channel_bit(dmac, MASK_ERROR, req->req.channel);
1565 + if (req->req.block_complete)
1566 + set_channel_bit(dmac, MASK_BLOCK, req->req.channel);
1568 + clear_channel_bit(dmac, MASK_BLOCK, req->req.channel);
1572 +out_unclaim_channel:
1573 + chan->state = CH_STATE_ALLOCATED;
1577 +static int dmac_prepare_request_cyclic(struct dma_controller *_dmac,
1578 + struct dma_request_cyclic *req)
1580 + struct dw_dma_controller *dmac = to_dw_dmac(_dmac);
1581 + struct dw_dma_channel *chan;
1582 + unsigned long ctlhi, ctllo, cfghi, cfglo;
1583 + unsigned long block_size;
1584 + int ret, i, direction;
1585 + unsigned long flags;
1587 + spin_lock_irqsave(&dmac->lock, flags);
1589 + block_size = (req->buffer_size/req->periods) >> req->width;
1592 + if (req->req.channel >= DMAC_NR_CHANNELS
1593 + || dmac->channel[req->req.channel].state != CH_STATE_ALLOCATED
1594 + || (req->periods == 0)
1595 + || block_size > DMAC_MAX_BLOCKSIZE) {
1596 + spin_unlock_irqrestore(&dmac->lock, flags);
1600 + chan = &dmac->channel[req->req.channel];
1601 + chan->state = CH_STATE_BUSY;
1602 + chan->is_cyclic = 1;
1603 + chan->req_cyclic = req;
1606 + * We have marked the channel as busy, so no need to keep the
1607 + * lock as long as we only touch the channel-specific
1610 + spin_unlock_irqrestore(&dmac->lock, flags);
1615 + BUG_ON(req->buffer_size % req->periods);
1616 + /* printk(KERN_INFO "block_size = %lu, periods = %u\n", block_size, req->periods); */
1618 + chan->nr_blocks = req->periods;
1621 + cfglo = cfghi = 0;
1622 + switch (req->direction) {
1623 + case DMA_DIR_MEM_TO_PERIPH:
1624 + direction = DMA_TO_DEVICE;
1625 + cfghi = req->periph_id << (43 - 32);
1628 + case DMA_DIR_PERIPH_TO_MEM:
1629 + direction = DMA_FROM_DEVICE;
1630 + cfghi = req->periph_id << (39 - 32);
1633 + goto out_unclaim_channel;
1636 + chan->direction = direction;
1638 + dmac_chan_writel_hi(dmac, req->req.channel, CFG, cfghi);
1639 + dmac_chan_writel_lo(dmac, req->req.channel, CFG, cfglo);
1641 + ctlhi = block_size;
1642 + ctllo = ((req->direction << 20)
1643 + | (req->width << 4) | (req->width << 1)
1644 + | (1 << 0)); // interrupt enable
1647 + struct dw_dma_lli *lli = NULL, *lli_prev = NULL;
1650 + chan->block = allocate_blocks(dmac, req->periods);
1652 + goto out_unclaim_channel;
1654 + if (direction == DMA_TO_DEVICE)
1655 + ctllo |= 1 << 28 | 1 << 27 | 2 << 7;
1657 + ctllo |= 1 << 28 | 1 << 27 | 2 << 9;
1660 + * Set up a linked list items where each period gets
1661 + * an item. The linked list item for the last period
1662 + * points back to the star of the buffer making a
1665 + for (i = 0; i < req->periods; i++) {
1666 + lli = chan->block[i].lli_vaddr;
1668 + lli_prev->llp = chan->block[i].lli_dma_addr;
1669 + /* printk(KERN_INFO "lli[%d] (0x%p/0x%x): 0x%x 0x%x 0x%x 0x%x 0x%x\n",
1670 + i - 1, chan->block[i - 1].lli_vaddr,
1671 + chan->block[i - 1].lli_dma_addr,
1672 + lli_prev->sar, lli_prev->dar, lli_prev->llp,
1673 + lli_prev->ctllo, lli_prev->ctlhi);*/
1676 + lli->ctllo = ctllo;
1677 + lli->ctlhi = ctlhi;
1678 + if (direction == DMA_TO_DEVICE) {
1679 + lli->sar = req->buffer_start + i*(block_size << req->width);
1680 + lli->dar = req->data_reg;
1682 + lli->sar = req->data_reg;
1683 + lli->dar = req->buffer_start + i*(block_size << req->width);
1687 + lli->llp = chan->block[0].lli_dma_addr;
1689 + /*printk(KERN_INFO "lli[%d] (0x%p/0x%x): 0x%x 0x%x 0x%x 0x%x 0x%x\n",
1690 + i - 1, chan->block[i - 1].lli_vaddr,
1691 + chan->block[i - 1].lli_dma_addr, lli_prev->sar,
1692 + lli_prev->dar, lli_prev->llp,
1693 + lli_prev->ctllo, lli_prev->ctlhi); */
1696 + * SAR, DAR and CTL are initialized from the LLI. We
1697 + * only have to enable the LLI bits in CTL.
1699 + dmac_chan_writel_lo(dmac, req->req.channel, LLP,
1700 + chan->block[0].lli_dma_addr);
1701 + dmac_chan_writel_lo(dmac, req->req.channel, CTL, 1 << 28 | 1 << 27);
1704 + clear_channel_bit(dmac, MASK_XFER, req->req.channel);
1705 + set_channel_bit(dmac, MASK_ERROR, req->req.channel);
1706 + if (req->req.block_complete)
1707 + set_channel_bit(dmac, MASK_BLOCK, req->req.channel);
1709 + clear_channel_bit(dmac, MASK_BLOCK, req->req.channel);
1713 +out_unclaim_channel:
1714 + chan->state = CH_STATE_ALLOCATED;
1718 +static int dmac_start_request(struct dma_controller *_dmac,
1719 + unsigned int channel)
1721 + struct dw_dma_controller *dmac = to_dw_dmac(_dmac);
1723 + BUG_ON(channel >= DMAC_NR_CHANNELS);
1725 + set_channel_bit(dmac, CH_EN, channel);
1730 +static dma_addr_t dmac_get_current_pos(struct dma_controller *_dmac,
1731 + unsigned int channel)
1733 + struct dw_dma_controller *dmac = to_dw_dmac(_dmac);
1734 + struct dw_dma_channel *chan;
1735 + dma_addr_t current_pos;
1737 + BUG_ON(channel >= DMAC_NR_CHANNELS);
1739 + chan = &dmac->channel[channel];
1741 + switch (chan->direction) {
1742 + case DMA_TO_DEVICE:
1743 + current_pos = dmac_chan_readl_lo(dmac, channel, SAR);
1745 + case DMA_FROM_DEVICE:
1746 + current_pos = dmac_chan_readl_lo(dmac, channel, DAR);
1753 + if (!current_pos) {
1754 + if (chan->is_cyclic) {
1755 + current_pos = chan->req_cyclic->buffer_start;
1757 + current_pos = chan->req_sg->sg->dma_address;
1761 + return current_pos;
1765 +static int dmac_stop_request(struct dma_controller *_dmac,
1766 + unsigned int channel)
1768 + struct dw_dma_controller *dmac = to_dw_dmac(_dmac);
1769 + struct dw_dma_channel *chan;
1771 + BUG_ON(channel >= DMAC_NR_CHANNELS);
1773 + chan = &dmac->channel[channel];
1774 + pr_debug("stop: st%u s%08x d%08x l%08x ctl0x%08x:0x%08x\n",
1775 + chan->state, dmac_chan_readl_lo(dmac, channel, SAR),
1776 + dmac_chan_readl_lo(dmac, channel, DAR),
1777 + dmac_chan_readl_lo(dmac, channel, LLP),
1778 + dmac_chan_readl_hi(dmac, channel, CTL),
1779 + dmac_chan_readl_lo(dmac, channel, CTL));
1781 + if (chan->state == CH_STATE_BUSY) {
1782 + clear_channel_bit(dmac, CH_EN, channel);
1783 + cleanup_channel(dmac, &dmac->channel[channel]);
1790 +static void dmac_block_complete(struct dw_dma_controller *dmac)
1792 + struct dw_dma_channel *chan;
1793 + unsigned long status, chanid;
1795 + status = dmac_readl_lo(dmac, STATUS_BLOCK);
1798 + struct dma_request *req;
1799 + chanid = __ffs(status);
1800 + chan = &dmac->channel[chanid];
1802 + if (chan->is_cyclic) {
1803 + BUG_ON(!chan->req_cyclic
1804 + || !chan->req_cyclic->req.block_complete);
1805 + req = &chan->req_cyclic->req;
1807 + BUG_ON(!chan->req_sg || !chan->req_sg->req.block_complete);
1808 + req = &chan->req_sg->req;
1810 + dmac_writel_lo(dmac, CLEAR_BLOCK, 1 << chanid);
1811 + req->block_complete(req);
1812 + status = dmac_readl_lo(dmac, STATUS_BLOCK);
1816 +static void dmac_xfer_complete(struct dw_dma_controller *dmac)
1818 + struct dw_dma_channel *chan;
1819 + struct dma_request *req;
1820 + unsigned long status, chanid;
1822 + status = dmac_readl_lo(dmac, STATUS_XFER);
1825 + chanid = __ffs(status);
1826 + chan = &dmac->channel[chanid];
1828 + dmac_writel_lo(dmac, CLEAR_XFER, 1 << chanid);
1830 + req = &chan->req_sg->req;
1832 + cleanup_channel(dmac, chan);
1833 + if (req->xfer_complete)
1834 + req->xfer_complete(req);
1836 + status = dmac_readl_lo(dmac, STATUS_XFER);
1840 +static void dmac_error(struct dw_dma_controller *dmac)
1842 + struct dw_dma_channel *chan;
1843 + unsigned long status, chanid;
1845 + status = dmac_readl_lo(dmac, STATUS_ERROR);
1848 + struct dma_request *req;
1850 + chanid = __ffs(status);
1851 + chan = &dmac->channel[chanid];
1853 + dmac_writel_lo(dmac, CLEAR_ERROR, 1 << chanid);
1854 + clear_channel_bit(dmac, CH_EN, chanid);
1856 + if (chan->is_cyclic) {
1857 + BUG_ON(!chan->req_cyclic);
1858 + req = &chan->req_cyclic->req;
1860 + BUG_ON(!chan->req_sg);
1861 + req = &chan->req_sg->req;
1864 + cleanup_channel(dmac, chan);
1868 + status = dmac_readl_lo(dmac, STATUS_XFER);
1872 +static irqreturn_t dmac_interrupt(int irq, void *dev_id)
1874 + struct dw_dma_controller *dmac = dev_id;
1875 + unsigned long status;
1876 + int ret = IRQ_NONE;
1878 + spin_lock(&dmac->lock);
1880 + status = dmac_readl_lo(dmac, STATUS_INT);
1883 + ret = IRQ_HANDLED;
1884 + if (status & 0x10)
1886 + if (status & 0x02)
1887 + dmac_block_complete(dmac);
1888 + if (status & 0x01)
1889 + dmac_xfer_complete(dmac);
1891 + status = dmac_readl_lo(dmac, STATUS_INT);
1894 + spin_unlock(&dmac->lock);
1898 +static int __devinit dmac_probe(struct platform_device *pdev)
1900 + struct dw_dma_controller *dmac;
1901 + struct resource *regs;
1904 + regs = platform_get_resource(pdev, IORESOURCE_MEM, 0);
1908 + dmac = kmalloc(sizeof(*dmac), GFP_KERNEL);
1911 + memset(dmac, 0, sizeof(*dmac));
1913 + dmac->hclk = clk_get(&pdev->dev, "hclk");
1914 + if (IS_ERR(dmac->hclk)) {
1915 + ret = PTR_ERR(dmac->hclk);
1916 + goto out_free_dmac;
1918 + clk_enable(dmac->hclk);
1921 + dmac->lli_pool = dma_pool_create("dmac", &pdev->dev,
1922 + sizeof(struct dw_dma_lli), 4, 0);
1923 + if (!dmac->lli_pool)
1924 + goto out_disable_clk;
1926 + spin_lock_init(&dmac->lock);
1927 + dmac->dma.dev = &pdev->dev;
1928 + dmac->dma.alloc_channel = dmac_alloc_channel;
1929 + dmac->dma.release_channel = dmac_release_channel;
1930 + dmac->dma.prepare_request_sg = dmac_prepare_request_sg;
1931 + dmac->dma.prepare_request_cyclic = dmac_prepare_request_cyclic;
1932 + dmac->dma.start_request = dmac_start_request;
1933 + dmac->dma.stop_request = dmac_stop_request;
1934 + dmac->dma.get_current_pos = dmac_get_current_pos;
1936 + dmac->regs = ioremap(regs->start, regs->end - regs->start + 1);
1938 + goto out_free_pool;
1940 + ret = request_irq(platform_get_irq(pdev, 0), dmac_interrupt,
1941 + IRQF_SAMPLE_RANDOM, pdev->name, dmac);
1943 + goto out_unmap_regs;
1945 + /* Enable the DMA controller */
1946 + dmac_writel_lo(dmac, CFG, 1);
1948 + register_dma_controller(&dmac->dma);
1951 + "dmac%d: DesignWare DMA controller at 0x%p irq %d\n",
1952 + dmac->dma.id, dmac->regs, platform_get_irq(pdev, 0));
1957 + iounmap(dmac->regs);
1959 + dma_pool_destroy(dmac->lli_pool);
1961 + clk_disable(dmac->hclk);
1962 + clk_put(dmac->hclk);
1968 +static struct platform_driver dmac_driver = {
1969 + .probe = dmac_probe,
1975 +static int __init dmac_init(void)
1977 + return platform_driver_register(&dmac_driver);
1979 +subsys_initcall(dmac_init);
1981 +static void __exit dmac_exit(void)
1983 + platform_driver_unregister(&dmac_driver);
1985 +module_exit(dmac_exit);
1987 +MODULE_DESCRIPTION("Synopsys DesignWare DMA Controller driver");
1988 +MODULE_AUTHOR("Haavard Skinnemoen <hskinnemoen@atmel.com>");
1989 +MODULE_LICENSE("GPL");
1990 diff -x .git -Nur linux-2.6.22.1/arch/avr32/drivers/dw-dmac.h linux-avr32.git/arch/avr32/drivers/dw-dmac.h
1991 --- linux-2.6.22.1/arch/avr32/drivers/dw-dmac.h 1970-01-01 01:00:00.000000000 +0100
1992 +++ linux-avr32.git/arch/avr32/drivers/dw-dmac.h 2007-06-06 11:33:46.000000000 +0200
1995 + * Driver for the Synopsys DesignWare DMA Controller
1997 + * Copyright (C) 2005-2006 Atmel Corporation
1999 + * This program is free software; you can redistribute it and/or modify
2000 + * it under the terms of the GNU General Public License version 2 as
2001 + * published by the Free Software Foundation.
2003 +#ifndef __AVR32_DW_DMAC_H__
2004 +#define __AVR32_DW_DMAC_H__
2006 +#define DW_DMAC_CFG 0x398
2007 +#define DW_DMAC_CH_EN 0x3a0
2009 +#define DW_DMAC_STATUS_XFER 0x2e8
2010 +#define DW_DMAC_STATUS_BLOCK 0x2f0
2011 +#define DW_DMAC_STATUS_ERROR 0x308
2013 +#define DW_DMAC_MASK_XFER 0x310
2014 +#define DW_DMAC_MASK_BLOCK 0x318
2015 +#define DW_DMAC_MASK_ERROR 0x330
2017 +#define DW_DMAC_CLEAR_XFER 0x338
2018 +#define DW_DMAC_CLEAR_BLOCK 0x340
2019 +#define DW_DMAC_CLEAR_ERROR 0x358
2021 +#define DW_DMAC_STATUS_INT 0x360
2023 +#define DW_DMAC_CHAN_SAR 0x000
2024 +#define DW_DMAC_CHAN_DAR 0x008
2025 +#define DW_DMAC_CHAN_LLP 0x010
2026 +#define DW_DMAC_CHAN_CTL 0x018
2027 +#define DW_DMAC_CHAN_SSTAT 0x020
2028 +#define DW_DMAC_CHAN_DSTAT 0x028
2029 +#define DW_DMAC_CHAN_SSTATAR 0x030
2030 +#define DW_DMAC_CHAN_DSTATAR 0x038
2031 +#define DW_DMAC_CHAN_CFG 0x040
2032 +#define DW_DMAC_CHAN_SGR 0x048
2033 +#define DW_DMAC_CHAN_DSR 0x050
2035 +#endif /* __AVR32_DW_DMAC_H__ */
2036 diff -x .git -Nur linux-2.6.22.1/arch/avr32/drivers/Makefile linux-avr32.git/arch/avr32/drivers/Makefile
2037 --- linux-2.6.22.1/arch/avr32/drivers/Makefile 1970-01-01 01:00:00.000000000 +0100
2038 +++ linux-avr32.git/arch/avr32/drivers/Makefile 2007-06-06 11:33:46.000000000 +0200
2040 +obj-$(CONFIG_DW_DMAC) += dw-dmac.o
2041 diff -x .git -Nur linux-2.6.22.1/arch/avr32/Kconfig linux-avr32.git/arch/avr32/Kconfig
2042 --- linux-2.6.22.1/arch/avr32/Kconfig 2007-07-10 20:56:30.000000000 +0200
2043 +++ linux-avr32.git/arch/avr32/Kconfig 2007-07-13 11:24:16.000000000 +0200
2044 @@ -113,6 +113,13 @@
2045 bool "ATNGW100 Network Gateway"
2049 +source "arch/avr32/boards/atstk1000/Kconfig"
2052 +source "arch/avr32/boards/atngw100/Kconfig"
2056 prompt "Boot loader type"
2057 default LOADER_U_BOOT
2058 @@ -171,6 +178,10 @@
2059 enabling Nexus-compliant debuggers to keep track of the PID of the
2060 currently executing task.
2063 + tristate "Synopsys DesignWare DMA Controller support"
2064 + default y if CPU_AT32AP7000
2066 # FPU emulation goes here
2068 source "kernel/Kconfig.hz"
2069 @@ -185,6 +196,27 @@
2073 +menu "Power managment options"
2075 +menu "CPU Frequency scaling"
2077 +source "drivers/cpufreq/Kconfig"
2079 +config CPU_FREQ_AT32AP
2080 + bool "CPU frequency driver for AT32AP"
2081 + depends on CPU_FREQ && PLATFORM_AT32AP
2084 + This enables the CPU frequency driver for AT32AP processors.
2086 + For details, take a look in <file:Documentation/cpu-freq>.
2088 + If in doubt, say N.
2097 diff -x .git -Nur linux-2.6.22.1/arch/avr32/kernel/dma-controller.c linux-avr32.git/arch/avr32/kernel/dma-controller.c
2098 --- linux-2.6.22.1/arch/avr32/kernel/dma-controller.c 1970-01-01 01:00:00.000000000 +0100
2099 +++ linux-avr32.git/arch/avr32/kernel/dma-controller.c 2007-06-06 11:33:46.000000000 +0200
2102 + * Preliminary DMA controller framework for AVR32
2104 + * Copyright (C) 2005-2006 Atmel Corporation
2106 + * This program is free software; you can redistribute it and/or modify
2107 + * it under the terms of the GNU General Public License version 2 as
2108 + * published by the Free Software Foundation.
2110 +#include <asm/dma-controller.h>
2112 +static LIST_HEAD(controllers);
2114 +int register_dma_controller(struct dma_controller *dmac)
2116 + static int next_id;
2118 + dmac->id = next_id++;
2119 + list_add_tail(&dmac->list, &controllers);
2123 +EXPORT_SYMBOL(register_dma_controller);
2125 +struct dma_controller *find_dma_controller(int id)
2127 + struct dma_controller *dmac;
2129 + list_for_each_entry(dmac, &controllers, list)
2130 + if (dmac->id == id)
2134 +EXPORT_SYMBOL(find_dma_controller);
2135 diff -x .git -Nur linux-2.6.22.1/arch/avr32/kernel/Makefile linux-avr32.git/arch/avr32/kernel/Makefile
2136 --- linux-2.6.22.1/arch/avr32/kernel/Makefile 2007-07-10 20:56:30.000000000 +0200
2137 +++ linux-avr32.git/arch/avr32/kernel/Makefile 2007-06-06 11:33:46.000000000 +0200
2139 obj-y += setup.o traps.o semaphore.o ptrace.o
2140 obj-y += signal.o sys_avr32.o process.o time.o
2141 obj-y += init_task.o switch_to.o cpu.o
2142 +obj-y += dma-controller.o
2143 obj-$(CONFIG_MODULES) += module.o avr32_ksyms.o
2144 obj-$(CONFIG_KPROBES) += kprobes.o
2146 diff -x .git -Nur linux-2.6.22.1/arch/avr32/mach-at32ap/at32ap7000.c linux-avr32.git/arch/avr32/mach-at32ap/at32ap7000.c
2147 --- linux-2.6.22.1/arch/avr32/mach-at32ap/at32ap7000.c 2007-07-10 20:56:30.000000000 +0200
2148 +++ linux-avr32.git/arch/avr32/mach-at32ap/at32ap7000.c 2007-07-12 13:59:49.000000000 +0200
2150 #include <asm/arch/at32ap7000.h>
2151 #include <asm/arch/board.h>
2152 #include <asm/arch/portmux.h>
2153 -#include <asm/arch/sm.h>
2155 #include <video/atmel_lcdc.h>
2158 #include "hmatrix.h"
2164 + * We can reduce the code size a bit by using a constant here. Since
2165 + * this file is completely chip-specific, it's safe to not use
2166 + * ioremap. Generic drivers should of course never do this.
2168 +#define AT32_PM_BASE 0xfff00000
2170 #define PBMEM(base) \
2176 +static DEFINE_SPINLOCK(pm_lock);
2178 unsigned long at32ap7000_osc_rates[3] = {
2180 /* FIXME: these are ATSTK1002-specific */
2181 @@ -104,11 +112,11 @@
2183 unsigned long div, mul, rate;
2185 - if (!(control & SM_BIT(PLLEN)))
2186 + if (!(control & PM_BIT(PLLEN)))
2189 - div = SM_BFEXT(PLLDIV, control) + 1;
2190 - mul = SM_BFEXT(PLLMUL, control) + 1;
2191 + div = PM_BFEXT(PLLDIV, control) + 1;
2192 + mul = PM_BFEXT(PLLMUL, control) + 1;
2194 rate = clk->parent->get_rate(clk->parent);
2195 rate = (rate + div / 2) / div;
2200 - control = sm_readl(&system_manager, PM_PLL0);
2201 + control = pm_readl(PLL0);
2203 return pll_get_rate(clk, control);
2209 - control = sm_readl(&system_manager, PM_PLL1);
2210 + control = pm_readl(PLL1);
2212 return pll_get_rate(clk, control);
2214 @@ -187,108 +195,139 @@
2216 static void cpu_clk_mode(struct clk *clk, int enabled)
2218 - struct at32_sm *sm = &system_manager;
2219 unsigned long flags;
2222 - spin_lock_irqsave(&sm->lock, flags);
2223 - mask = sm_readl(sm, PM_CPU_MASK);
2224 + spin_lock_irqsave(&pm_lock, flags);
2225 + mask = pm_readl(CPU_MASK);
2227 mask |= 1 << clk->index;
2229 mask &= ~(1 << clk->index);
2230 - sm_writel(sm, PM_CPU_MASK, mask);
2231 - spin_unlock_irqrestore(&sm->lock, flags);
2232 + pm_writel(CPU_MASK, mask);
2233 + spin_unlock_irqrestore(&pm_lock, flags);
2236 static unsigned long cpu_clk_get_rate(struct clk *clk)
2238 unsigned long cksel, shift = 0;
2240 - cksel = sm_readl(&system_manager, PM_CKSEL);
2241 - if (cksel & SM_BIT(CPUDIV))
2242 - shift = SM_BFEXT(CPUSEL, cksel) + 1;
2243 + cksel = pm_readl(CKSEL);
2244 + if (cksel & PM_BIT(CPUDIV))
2245 + shift = PM_BFEXT(CPUSEL, cksel) + 1;
2247 return bus_clk_get_rate(clk, shift);
2250 +static long cpu_clk_set_rate(struct clk *clk, unsigned long rate, int apply)
2253 + unsigned long parent_rate, child_div, actual_rate, div;
2255 + parent_rate = clk->parent->get_rate(clk->parent);
2256 + control = pm_readl(CKSEL);
2258 + if (control & PM_BIT(HSBDIV))
2259 + child_div = 1 << (PM_BFEXT(HSBSEL, control) + 1);
2263 + if (rate > 3 * (parent_rate / 4) || child_div == 1) {
2264 + actual_rate = parent_rate;
2265 + control &= ~PM_BIT(CPUDIV);
2267 + unsigned int cpusel;
2268 + div = (parent_rate + rate / 2) / rate;
2269 + if (div > child_div)
2271 + cpusel = (div > 1) ? (fls(div) - 2) : 0;
2272 + control = PM_BIT(CPUDIV) | PM_BFINS(CPUSEL, cpusel, control);
2273 + actual_rate = parent_rate / (1 << (cpusel + 1));
2276 + pr_debug("clk %s: new rate %lu (actual rate %lu)\n",
2277 + clk->name, rate, actual_rate);
2280 + pm_writel(CKSEL, control);
2282 + return actual_rate;
2285 static void hsb_clk_mode(struct clk *clk, int enabled)
2287 - struct at32_sm *sm = &system_manager;
2288 unsigned long flags;
2291 - spin_lock_irqsave(&sm->lock, flags);
2292 - mask = sm_readl(sm, PM_HSB_MASK);
2293 + spin_lock_irqsave(&pm_lock, flags);
2294 + mask = pm_readl(HSB_MASK);
2296 mask |= 1 << clk->index;
2298 mask &= ~(1 << clk->index);
2299 - sm_writel(sm, PM_HSB_MASK, mask);
2300 - spin_unlock_irqrestore(&sm->lock, flags);
2301 + pm_writel(HSB_MASK, mask);
2302 + spin_unlock_irqrestore(&pm_lock, flags);
2305 static unsigned long hsb_clk_get_rate(struct clk *clk)
2307 unsigned long cksel, shift = 0;
2309 - cksel = sm_readl(&system_manager, PM_CKSEL);
2310 - if (cksel & SM_BIT(HSBDIV))
2311 - shift = SM_BFEXT(HSBSEL, cksel) + 1;
2312 + cksel = pm_readl(CKSEL);
2313 + if (cksel & PM_BIT(HSBDIV))
2314 + shift = PM_BFEXT(HSBSEL, cksel) + 1;
2316 return bus_clk_get_rate(clk, shift);
2319 static void pba_clk_mode(struct clk *clk, int enabled)
2321 - struct at32_sm *sm = &system_manager;
2322 unsigned long flags;
2325 - spin_lock_irqsave(&sm->lock, flags);
2326 - mask = sm_readl(sm, PM_PBA_MASK);
2327 + spin_lock_irqsave(&pm_lock, flags);
2328 + mask = pm_readl(PBA_MASK);
2330 mask |= 1 << clk->index;
2332 mask &= ~(1 << clk->index);
2333 - sm_writel(sm, PM_PBA_MASK, mask);
2334 - spin_unlock_irqrestore(&sm->lock, flags);
2335 + pm_writel(PBA_MASK, mask);
2336 + spin_unlock_irqrestore(&pm_lock, flags);
2339 static unsigned long pba_clk_get_rate(struct clk *clk)
2341 unsigned long cksel, shift = 0;
2343 - cksel = sm_readl(&system_manager, PM_CKSEL);
2344 - if (cksel & SM_BIT(PBADIV))
2345 - shift = SM_BFEXT(PBASEL, cksel) + 1;
2346 + cksel = pm_readl(CKSEL);
2347 + if (cksel & PM_BIT(PBADIV))
2348 + shift = PM_BFEXT(PBASEL, cksel) + 1;
2350 return bus_clk_get_rate(clk, shift);
2353 static void pbb_clk_mode(struct clk *clk, int enabled)
2355 - struct at32_sm *sm = &system_manager;
2356 unsigned long flags;
2359 - spin_lock_irqsave(&sm->lock, flags);
2360 - mask = sm_readl(sm, PM_PBB_MASK);
2361 + spin_lock_irqsave(&pm_lock, flags);
2362 + mask = pm_readl(PBB_MASK);
2364 mask |= 1 << clk->index;
2366 mask &= ~(1 << clk->index);
2367 - sm_writel(sm, PM_PBB_MASK, mask);
2368 - spin_unlock_irqrestore(&sm->lock, flags);
2369 + pm_writel(PBB_MASK, mask);
2370 + spin_unlock_irqrestore(&pm_lock, flags);
2373 static unsigned long pbb_clk_get_rate(struct clk *clk)
2375 unsigned long cksel, shift = 0;
2377 - cksel = sm_readl(&system_manager, PM_CKSEL);
2378 - if (cksel & SM_BIT(PBBDIV))
2379 - shift = SM_BFEXT(PBBSEL, cksel) + 1;
2380 + cksel = pm_readl(CKSEL);
2381 + if (cksel & PM_BIT(PBBDIV))
2382 + shift = PM_BFEXT(PBBSEL, cksel) + 1;
2384 return bus_clk_get_rate(clk, shift);
2387 static struct clk cpu_clk = {
2389 .get_rate = cpu_clk_get_rate,
2390 + .set_rate = cpu_clk_set_rate,
2393 static struct clk hsb_clk = {
2394 @@ -327,12 +367,12 @@
2398 - control = sm_readl(&system_manager, PM_GCCTRL + 4 * clk->index);
2399 + control = pm_readl(GCCTRL(clk->index));
2401 - control |= SM_BIT(CEN);
2402 + control |= PM_BIT(CEN);
2404 - control &= ~SM_BIT(CEN);
2405 - sm_writel(&system_manager, PM_GCCTRL + 4 * clk->index, control);
2406 + control &= ~PM_BIT(CEN);
2407 + pm_writel(GCCTRL(clk->index), control);
2410 static unsigned long genclk_get_rate(struct clk *clk)
2413 unsigned long div = 1;
2415 - control = sm_readl(&system_manager, PM_GCCTRL + 4 * clk->index);
2416 - if (control & SM_BIT(DIVEN))
2417 - div = 2 * (SM_BFEXT(DIV, control) + 1);
2418 + control = pm_readl(GCCTRL(clk->index));
2419 + if (control & PM_BIT(DIVEN))
2420 + div = 2 * (PM_BFEXT(DIV, control) + 1);
2422 return clk->parent->get_rate(clk->parent) / div;
2424 @@ -353,23 +393,22 @@
2425 unsigned long parent_rate, actual_rate, div;
2427 parent_rate = clk->parent->get_rate(clk->parent);
2428 - control = sm_readl(&system_manager, PM_GCCTRL + 4 * clk->index);
2429 + control = pm_readl(GCCTRL(clk->index));
2431 if (rate > 3 * parent_rate / 4) {
2432 actual_rate = parent_rate;
2433 - control &= ~SM_BIT(DIVEN);
2434 + control &= ~PM_BIT(DIVEN);
2436 div = (parent_rate + rate) / (2 * rate) - 1;
2437 - control = SM_BFINS(DIV, div, control) | SM_BIT(DIVEN);
2438 + control = PM_BFINS(DIV, div, control) | PM_BIT(DIVEN);
2439 actual_rate = parent_rate / (2 * (div + 1));
2442 - printk("clk %s: new rate %lu (actual rate %lu)\n",
2443 - clk->name, rate, actual_rate);
2444 + dev_dbg(clk->dev, "clk %s: new rate %lu (actual rate %lu)\n",
2445 + clk->name, rate, actual_rate);
2448 - sm_writel(&system_manager, PM_GCCTRL + 4 * clk->index,
2450 + pm_writel(GCCTRL(clk->index), control);
2454 @@ -378,24 +417,24 @@
2458 - printk("clk %s: new parent %s (was %s)\n",
2459 - clk->name, parent->name, clk->parent->name);
2460 + dev_dbg(clk->dev, "clk %s: new parent %s (was %s)\n",
2461 + clk->name, parent->name, clk->parent->name);
2463 - control = sm_readl(&system_manager, PM_GCCTRL + 4 * clk->index);
2464 + control = pm_readl(GCCTRL(clk->index));
2466 if (parent == &osc1 || parent == &pll1)
2467 - control |= SM_BIT(OSCSEL);
2468 + control |= PM_BIT(OSCSEL);
2469 else if (parent == &osc0 || parent == &pll0)
2470 - control &= ~SM_BIT(OSCSEL);
2471 + control &= ~PM_BIT(OSCSEL);
2475 if (parent == &pll0 || parent == &pll1)
2476 - control |= SM_BIT(PLLSEL);
2477 + control |= PM_BIT(PLLSEL);
2479 - control &= ~SM_BIT(PLLSEL);
2480 + control &= ~PM_BIT(PLLSEL);
2482 - sm_writel(&system_manager, PM_GCCTRL + 4 * clk->index, control);
2483 + pm_writel(GCCTRL(clk->index), control);
2484 clk->parent = parent;
2487 @@ -408,11 +447,11 @@
2489 BUG_ON(clk->index > 7);
2491 - control = sm_readl(&system_manager, PM_GCCTRL + 4 * clk->index);
2492 - if (control & SM_BIT(OSCSEL))
2493 - parent = (control & SM_BIT(PLLSEL)) ? &pll1 : &osc1;
2494 + control = pm_readl(GCCTRL(clk->index));
2495 + if (control & PM_BIT(OSCSEL))
2496 + parent = (control & PM_BIT(PLLSEL)) ? &pll1 : &osc1;
2498 - parent = (control & SM_BIT(PLLSEL)) ? &pll0 : &osc0;
2499 + parent = (control & PM_BIT(PLLSEL)) ? &pll0 : &osc0;
2501 clk->parent = parent;
2503 @@ -420,21 +459,53 @@
2504 /* --------------------------------------------------------------------
2505 * System peripherals
2506 * -------------------------------------------------------------------- */
2507 -static struct resource sm_resource[] = {
2508 - PBMEM(0xfff00000),
2509 - NAMED_IRQ(19, "eim"),
2510 - NAMED_IRQ(20, "pm"),
2511 - NAMED_IRQ(21, "rtc"),
2512 +static struct resource at32_pm0_resource[] = {
2514 + .start = 0xfff00000,
2515 + .end = 0xfff0007f,
2516 + .flags = IORESOURCE_MEM,
2520 -struct platform_device at32_sm_device = {
2523 - .resource = sm_resource,
2524 - .num_resources = ARRAY_SIZE(sm_resource),
2526 +static struct resource at32ap700x_rtc0_resource[] = {
2528 + .start = 0xfff00080,
2529 + .end = 0xfff000af,
2530 + .flags = IORESOURCE_MEM,
2535 +static struct resource at32_wdt0_resource[] = {
2537 + .start = 0xfff000b0,
2538 + .end = 0xfff000bf,
2539 + .flags = IORESOURCE_MEM,
2543 +static struct resource at32_eic0_resource[] = {
2545 + .start = 0xfff00100,
2546 + .end = 0xfff0013f,
2547 + .flags = IORESOURCE_MEM,
2551 -static struct clk at32_sm_pclk = {
2553 +DEFINE_DEV(at32_pm, 0);
2554 +DEFINE_DEV(at32ap700x_rtc, 0);
2555 +DEFINE_DEV(at32_wdt, 0);
2556 +DEFINE_DEV(at32_eic, 0);
2559 + * Peripheral clock for PM, RTC, WDT and EIC. PM will ensure that this
2560 + * is always running.
2562 +static struct clk at32_pm_pclk = {
2564 - .dev = &at32_sm_device.dev,
2565 + .dev = &at32_pm0_device.dev,
2567 .mode = pbb_clk_mode,
2568 .get_rate = pbb_clk_get_rate,
2569 @@ -491,6 +562,17 @@
2573 +static struct resource dmaca0_resource[] = {
2575 + .start = 0xff200000,
2576 + .end = 0xff20ffff,
2577 + .flags = IORESOURCE_MEM,
2581 +DEFINE_DEV(dmaca, 0);
2582 +DEV_CLK(hclk, dmaca0, hsb, 10);
2584 /* --------------------------------------------------------------------
2586 * -------------------------------------------------------------------- */
2587 @@ -583,12 +665,14 @@
2589 void __init at32_add_system_devices(void)
2591 - system_manager.eim_first_irq = EIM_IRQ_BASE;
2593 - platform_device_register(&at32_sm_device);
2594 + platform_device_register(&at32_pm0_device);
2595 platform_device_register(&at32_intc0_device);
2596 + platform_device_register(&at32ap700x_rtc0_device);
2597 + platform_device_register(&at32_wdt0_device);
2598 + platform_device_register(&at32_eic0_device);
2599 platform_device_register(&smc0_device);
2600 platform_device_register(&pdc_device);
2601 + platform_device_register(&dmaca0_device);
2603 platform_device_register(&at32_systc0_device);
2605 @@ -894,6 +978,83 @@
2608 /* --------------------------------------------------------------------
2610 + * -------------------------------------------------------------------- */
2612 +static struct resource atmel_twi0_resource[] = {
2613 + PBMEM(0xffe00800),
2616 +DEFINE_DEV(atmel_twi, 0);
2617 +DEV_CLK(pclk,atmel_twi0,pba,2);
2619 +struct platform_device *__init
2620 +at32_add_device_twi(unsigned int id)
2622 + struct platform_device *pdev;
2626 + pdev = &atmel_twi0_device;
2627 + select_peripheral(PA(6), PERIPH_A, 0); /* SDA */
2628 + select_peripheral(PA(7), PERIPH_A, 0); /* SCL */
2635 + platform_device_register(pdev);
2639 +/* --------------------------------------------------------------------
2641 + * -------------------------------------------------------------------- */
2642 +static struct mci_platform_data atmel_mci0_data = {
2643 + .detect_pin = GPIO_PIN_NONE,
2644 + .wp_pin = GPIO_PIN_NONE,
2646 +static struct resource atmel_mci0_resource[] = {
2647 + PBMEM(0xfff02400),
2650 +DEFINE_DEV_DATA(atmel_mci, 0);
2651 +DEV_CLK(mci_clk, atmel_mci0, pbb, 9);
2653 +struct platform_device *__init
2654 +at32_add_device_mci(unsigned int id, struct mci_platform_data *data)
2656 + struct platform_device *pdev;
2660 + pdev = &atmel_mci0_device;
2661 + select_peripheral(PA(10), PERIPH_A, 0); /* CLK */
2662 + select_peripheral(PA(11), PERIPH_A, 0); /* CMD */
2663 + select_peripheral(PA(12), PERIPH_A, 0); /* DATA0 */
2664 + select_peripheral(PA(13), PERIPH_A, 0); /* DATA1 */
2665 + select_peripheral(PA(14), PERIPH_A, 0); /* DATA2 */
2666 + select_peripheral(PA(15), PERIPH_A, 0); /* DATA3 */
2673 + if (data->detect_pin != GPIO_PIN_NONE)
2674 + at32_select_gpio(data->detect_pin, 0);
2675 + if (data->wp_pin != GPIO_PIN_NONE)
2676 + at32_select_gpio(data->wp_pin, 0);
2677 + memcpy(pdev->dev.platform_data, data,
2678 + sizeof(struct mci_platform_data));
2681 + platform_device_register(pdev);
2685 +/* --------------------------------------------------------------------
2687 * -------------------------------------------------------------------- */
2688 static struct atmel_lcdfb_info atmel_lcdfb0_data;
2689 @@ -1013,6 +1174,228 @@
2692 /* --------------------------------------------------------------------
2693 + * USB Device Controller
2694 + * -------------------------------------------------------------------- */
2695 +static struct resource usba0_resource[] __initdata = {
2698 + .start = 0xff300000,
2699 + .end = 0xff3fffff,
2700 + .flags = IORESOURCE_MEM,
2703 + .start = 0xfff03000,
2704 + .end = 0xfff033ff,
2705 + .flags = IORESOURCE_MEM,
2709 +static struct clk usba0_pclk = {
2711 + .parent = &pbb_clk,
2712 + .mode = pbb_clk_mode,
2713 + .get_rate = pbb_clk_get_rate,
2716 +static struct clk usba0_hclk = {
2718 + .parent = &hsb_clk,
2719 + .mode = hsb_clk_mode,
2720 + .get_rate = hsb_clk_get_rate,
2724 +struct platform_device *__init
2725 +at32_add_device_usba(unsigned int id, struct usba_platform_data *data)
2727 + struct platform_device *pdev;
2732 + pdev = platform_device_alloc("atmel_usba_udc", 0);
2736 + if (platform_device_add_resources(pdev, usba0_resource,
2737 + ARRAY_SIZE(usba0_resource)))
2738 + goto out_free_pdev;
2741 + if (platform_device_add_data(pdev, data, sizeof(*data)))
2742 + goto out_free_pdev;
2744 + if (data->vbus_pin != GPIO_PIN_NONE)
2745 + at32_select_gpio(data->vbus_pin, 0);
2748 + usba0_pclk.dev = &pdev->dev;
2749 + usba0_hclk.dev = &pdev->dev;
2751 + platform_device_add(pdev);
2756 + platform_device_put(pdev);
2760 +/* --------------------------------------------------------------------
2762 + * -------------------------------------------------------------------- */
2763 +static struct resource ssc0_resource[] = {
2764 + PBMEM(0xffe01c00),
2767 +DEFINE_DEV(ssc, 0);
2768 +DEV_CLK(pclk, ssc0, pba, 7);
2770 +static struct resource ssc1_resource[] = {
2771 + PBMEM(0xffe02000),
2774 +DEFINE_DEV(ssc, 1);
2775 +DEV_CLK(pclk, ssc1, pba, 8);
2777 +static struct resource ssc2_resource[] = {
2778 + PBMEM(0xffe02400),
2781 +DEFINE_DEV(ssc, 2);
2782 +DEV_CLK(pclk, ssc2, pba, 9);
2784 +struct platform_device *__init
2785 +at32_add_device_ssc(unsigned int id, unsigned int flags)
2787 + struct platform_device *pdev;
2791 + pdev = &ssc0_device;
2792 + if (flags & ATMEL_SSC_RF)
2793 + select_peripheral(PA(21), PERIPH_A, 0); /* RF */
2794 + if (flags & ATMEL_SSC_RK)
2795 + select_peripheral(PA(22), PERIPH_A, 0); /* RK */
2796 + if (flags & ATMEL_SSC_TK)
2797 + select_peripheral(PA(23), PERIPH_A, 0); /* TK */
2798 + if (flags & ATMEL_SSC_TF)
2799 + select_peripheral(PA(24), PERIPH_A, 0); /* TF */
2800 + if (flags & ATMEL_SSC_TD)
2801 + select_peripheral(PA(25), PERIPH_A, 0); /* TD */
2802 + if (flags & ATMEL_SSC_RD)
2803 + select_peripheral(PA(26), PERIPH_A, 0); /* RD */
2806 + pdev = &ssc1_device;
2807 + if (flags & ATMEL_SSC_RF)
2808 + select_peripheral(PA(0), PERIPH_B, 0); /* RF */
2809 + if (flags & ATMEL_SSC_RK)
2810 + select_peripheral(PA(1), PERIPH_B, 0); /* RK */
2811 + if (flags & ATMEL_SSC_TK)
2812 + select_peripheral(PA(2), PERIPH_B, 0); /* TK */
2813 + if (flags & ATMEL_SSC_TF)
2814 + select_peripheral(PA(3), PERIPH_B, 0); /* TF */
2815 + if (flags & ATMEL_SSC_TD)
2816 + select_peripheral(PA(4), PERIPH_B, 0); /* TD */
2817 + if (flags & ATMEL_SSC_RD)
2818 + select_peripheral(PA(5), PERIPH_B, 0); /* RD */
2821 + pdev = &ssc2_device;
2822 + if (flags & ATMEL_SSC_TD)
2823 + select_peripheral(PB(13), PERIPH_A, 0); /* TD */
2824 + if (flags & ATMEL_SSC_RD)
2825 + select_peripheral(PB(14), PERIPH_A, 0); /* RD */
2826 + if (flags & ATMEL_SSC_TK)
2827 + select_peripheral(PB(15), PERIPH_A, 0); /* TK */
2828 + if (flags & ATMEL_SSC_TF)
2829 + select_peripheral(PB(16), PERIPH_A, 0); /* TF */
2830 + if (flags & ATMEL_SSC_RF)
2831 + select_peripheral(PB(17), PERIPH_A, 0); /* RF */
2832 + if (flags & ATMEL_SSC_RK)
2833 + select_peripheral(PB(18), PERIPH_A, 0); /* RK */
2839 + platform_device_register(pdev);
2843 +/* --------------------------------------------------------------------
2845 + * -------------------------------------------------------------------- */
2846 +static struct resource atmel_ac97c0_resource[] = {
2847 + PBMEM(0xfff02800),
2850 +DEFINE_DEV(atmel_ac97c, 0);
2851 +DEV_CLK(pclk, atmel_ac97c0, pbb, 10);
2853 +struct platform_device *__init
2854 +at32_add_device_ac97c(unsigned int id)
2856 + struct platform_device *pdev;
2860 + pdev = &atmel_ac97c0_device;
2861 + select_peripheral(PB(20), PERIPH_B, 0); /* SYNC */
2862 + select_peripheral(PB(21), PERIPH_B, 0); /* SDO */
2863 + select_peripheral(PB(22), PERIPH_B, 0); /* SDI */
2864 + select_peripheral(PB(23), PERIPH_B, 0); /* SCLK */
2870 + platform_device_register(pdev);
2874 +/* --------------------------------------------------------------------
2876 + * -------------------------------------------------------------------- */
2877 +static struct resource abdac0_resource[] = {
2878 + PBMEM(0xfff02000),
2881 +DEFINE_DEV(abdac, 0);
2882 +DEV_CLK(pclk, abdac0, pbb, 8);
2883 +static struct clk abdac0_sample_clk = {
2884 + .name = "sample_clk",
2885 + .dev = &abdac0_device.dev,
2886 + .mode = genclk_mode,
2887 + .get_rate = genclk_get_rate,
2888 + .set_rate = genclk_set_rate,
2889 + .set_parent = genclk_set_parent,
2893 +struct platform_device *__init
2894 +at32_add_device_abdac(unsigned int id)
2896 + struct platform_device *pdev;
2900 + pdev = &abdac0_device;
2901 + select_peripheral(PB(20), PERIPH_A, 0); /* DATA1 */
2902 + select_peripheral(PB(21), PERIPH_A, 0); /* DATA0 */
2903 + select_peripheral(PB(22), PERIPH_A, 0); /* DATAN1 */
2904 + select_peripheral(PB(23), PERIPH_A, 0); /* DATAN0 */
2910 + platform_device_register(pdev);
2914 +/* --------------------------------------------------------------------
2916 * -------------------------------------------------------------------- */
2917 static struct clk gclk0 = {
2918 @@ -1066,7 +1449,7 @@
2927 @@ -1075,6 +1458,7 @@
2935 @@ -1092,8 +1476,18 @@
2937 &atmel_spi0_spi_clk,
2938 &atmel_spi1_spi_clk,
2940 + &atmel_mci0_mci_clk,
2942 &atmel_lcdfb0_pixclk,
2948 + &atmel_ac97c0_pclk,
2950 + &abdac0_sample_clk,
2954 @@ -1113,18 +1507,20 @@
2956 void __init at32_clock_init(void)
2958 - struct at32_sm *sm = &system_manager;
2959 u32 cpu_mask = 0, hsb_mask = 0, pba_mask = 0, pbb_mask = 0;
2962 - if (sm_readl(sm, PM_MCCTRL) & SM_BIT(PLLSEL))
2963 + if (pm_readl(MCCTRL) & PM_BIT(PLLSEL)) {
2966 + cpu_clk.parent = &pll0;
2969 + cpu_clk.parent = &osc0;
2972 - if (sm_readl(sm, PM_PLL0) & SM_BIT(PLLOSC))
2973 + if (pm_readl(PLL0) & PM_BIT(PLLOSC))
2974 pll0.parent = &osc1;
2975 - if (sm_readl(sm, PM_PLL1) & SM_BIT(PLLOSC))
2976 + if (pm_readl(PLL1) & PM_BIT(PLLOSC))
2977 pll1.parent = &osc1;
2979 genclk_init_parent(&gclk0);
2980 @@ -1133,6 +1529,7 @@
2981 genclk_init_parent(&gclk3);
2982 genclk_init_parent(&gclk4);
2983 genclk_init_parent(&atmel_lcdfb0_pixclk);
2984 + genclk_init_parent(&abdac0_sample_clk);
2987 * Turn on all clocks that have at least one user already, and
2988 @@ -1157,8 +1554,8 @@
2989 pbb_mask |= 1 << clk->index;
2992 - sm_writel(sm, PM_CPU_MASK, cpu_mask);
2993 - sm_writel(sm, PM_HSB_MASK, hsb_mask);
2994 - sm_writel(sm, PM_PBA_MASK, pba_mask);
2995 - sm_writel(sm, PM_PBB_MASK, pbb_mask);
2996 + pm_writel(CPU_MASK, cpu_mask);
2997 + pm_writel(HSB_MASK, hsb_mask);
2998 + pm_writel(PBA_MASK, pba_mask);
2999 + pm_writel(PBB_MASK, pbb_mask);
3001 diff -x .git -Nur linux-2.6.22.1/arch/avr32/mach-at32ap/at32ap.c linux-avr32.git/arch/avr32/mach-at32ap/at32ap.c
3002 --- linux-2.6.22.1/arch/avr32/mach-at32ap/at32ap.c 2007-07-10 20:56:30.000000000 +0200
3003 +++ linux-avr32.git/arch/avr32/mach-at32ap/at32ap.c 2007-07-12 13:59:49.000000000 +0200
3005 #include <linux/init.h>
3006 #include <linux/platform_device.h>
3008 -#include <asm/io.h>
3010 #include <asm/arch/init.h>
3011 -#include <asm/arch/sm.h>
3013 -struct at32_sm system_manager;
3015 -static int __init at32_sm_init(void)
3017 - struct resource *regs;
3018 - struct at32_sm *sm = &system_manager;
3021 - regs = platform_get_resource(&at32_sm_device, IORESOURCE_MEM, 0);
3025 - spin_lock_init(&sm->lock);
3026 - sm->pdev = &at32_sm_device;
3029 - sm->regs = ioremap(regs->start, regs->end - regs->start + 1);
3036 - printk(KERN_ERR "Failed to initialize System Manager: %d\n", ret);
3040 void __init setup_platform(void)
3044 at32_portmux_init();
3046 diff -x .git -Nur linux-2.6.22.1/arch/avr32/mach-at32ap/cpufreq.c linux-avr32.git/arch/avr32/mach-at32ap/cpufreq.c
3047 --- linux-2.6.22.1/arch/avr32/mach-at32ap/cpufreq.c 1970-01-01 01:00:00.000000000 +0100
3048 +++ linux-avr32.git/arch/avr32/mach-at32ap/cpufreq.c 2007-07-12 13:59:49.000000000 +0200
3051 + * Copyright (C) 2004-2007 Atmel Corporation
3053 + * Based on MIPS implementation arch/mips/kernel/time.c
3054 + * Copyright 2001 MontaVista Software Inc.
3056 + * This program is free software; you can redistribute it and/or modify
3057 + * it under the terms of the GNU General Public License version 2 as
3058 + * published by the Free Software Foundation.
3063 +#include <linux/kernel.h>
3064 +#include <linux/types.h>
3065 +#include <linux/init.h>
3066 +#include <linux/cpufreq.h>
3067 +#include <linux/io.h>
3068 +#include <linux/clk.h>
3069 +#include <linux/err.h>
3070 +#include <asm/system.h>
3072 +static struct clk *cpuclk;
3074 +static int at32_verify_speed(struct cpufreq_policy *policy)
3076 + if (policy->cpu != 0)
3079 + cpufreq_verify_within_limits(policy, policy->cpuinfo.min_freq,
3080 + policy->cpuinfo.max_freq);
3084 +static unsigned int at32_get_speed(unsigned int cpu)
3086 + /* No SMP support */
3089 + return (unsigned int)((clk_get_rate(cpuclk) + 500) / 1000);
3092 +static int at32_set_target(struct cpufreq_policy *policy,
3093 + unsigned int target_freq,
3094 + unsigned int relation)
3096 + struct cpufreq_freqs freqs;
3099 + /* Convert target_freq from kHz to Hz */
3100 + freq = clk_round_rate(cpuclk, target_freq * 1000);
3102 + /* Check if policy->min <= new_freq <= policy->max */
3103 + if(freq < (policy->min * 1000) || freq > (policy->max * 1000))
3106 + pr_debug("cpufreq: requested frequency %u Hz\n", target_freq * 1000);
3108 + freqs.old = at32_get_speed(0);
3109 + freqs.new = (freq + 500) / 1000;
3113 + cpufreq_notify_transition(&freqs, CPUFREQ_PRECHANGE);
3114 + clk_set_rate(cpuclk, freq);
3115 + cpufreq_notify_transition(&freqs, CPUFREQ_POSTCHANGE);
3117 + pr_debug("cpufreq: set frequency %lu Hz\n", freq);
3122 +static int __init at32_cpufreq_driver_init(struct cpufreq_policy *policy)
3124 + if (policy->cpu != 0)
3127 + cpuclk = clk_get(NULL, "cpu");
3128 + if (IS_ERR(cpuclk)) {
3129 + pr_debug("cpufreq: could not get CPU clk\n");
3130 + return PTR_ERR(cpuclk);
3133 + policy->cpuinfo.min_freq = (clk_round_rate(cpuclk, 1) + 500) / 1000;
3134 + policy->cpuinfo.max_freq = (clk_round_rate(cpuclk, ~0UL) + 500) / 1000;
3135 + policy->cpuinfo.transition_latency = 0;
3136 + policy->cur = at32_get_speed(0);
3137 + policy->min = policy->cpuinfo.min_freq;
3138 + policy->max = policy->cpuinfo.max_freq;
3139 + policy->governor = CPUFREQ_DEFAULT_GOVERNOR;
3141 + printk("cpufreq: AT32AP CPU frequency driver\n");
3146 +static struct cpufreq_driver at32_driver = {
3148 + .owner = THIS_MODULE,
3149 + .init = at32_cpufreq_driver_init,
3150 + .verify = at32_verify_speed,
3151 + .target = at32_set_target,
3152 + .get = at32_get_speed,
3153 + .flags = CPUFREQ_STICKY,
3156 +static int __init at32_cpufreq_init(void)
3158 + return cpufreq_register_driver(&at32_driver);
3161 +arch_initcall(at32_cpufreq_init);
3162 diff -x .git -Nur linux-2.6.22.1/arch/avr32/mach-at32ap/extint.c linux-avr32.git/arch/avr32/mach-at32ap/extint.c
3163 --- linux-2.6.22.1/arch/avr32/mach-at32ap/extint.c 2007-07-10 20:56:30.000000000 +0200
3164 +++ linux-avr32.git/arch/avr32/mach-at32ap/extint.c 2007-07-12 13:59:49.000000000 +0200
3169 -#include <asm/arch/sm.h>
3172 +/* EIC register offsets */
3173 +#define EIC_IER 0x0000
3174 +#define EIC_IDR 0x0004
3175 +#define EIC_IMR 0x0008
3176 +#define EIC_ISR 0x000c
3177 +#define EIC_ICR 0x0010
3178 +#define EIC_MODE 0x0014
3179 +#define EIC_EDGE 0x0018
3180 +#define EIC_LEVEL 0x001c
3181 +#define EIC_TEST 0x0020
3182 +#define EIC_NMIC 0x0024
3184 +/* Bitfields in TEST */
3185 +#define EIC_TESTEN_OFFSET 31
3186 +#define EIC_TESTEN_SIZE 1
3188 +/* Bitfields in NMIC */
3189 +#define EIC_EN_OFFSET 0
3190 +#define EIC_EN_SIZE 1
3192 +/* Bit manipulation macros */
3193 +#define EIC_BIT(name) \
3194 + (1 << EIC_##name##_OFFSET)
3195 +#define EIC_BF(name,value) \
3196 + (((value) & ((1 << EIC_##name##_SIZE) - 1)) \
3197 + << EIC_##name##_OFFSET)
3198 +#define EIC_BFEXT(name,value) \
3199 + (((value) >> EIC_##name##_OFFSET) \
3200 + & ((1 << EIC_##name##_SIZE) - 1))
3201 +#define EIC_BFINS(name,value,old) \
3202 + (((old) & ~(((1 << EIC_##name##_SIZE) - 1) \
3203 + << EIC_##name##_OFFSET)) \
3204 + | EIC_BF(name,value))
3206 +/* Register access macros */
3207 +#define eic_readl(port,reg) \
3208 + __raw_readl((port)->regs + EIC_##reg)
3209 +#define eic_writel(port,reg,value) \
3210 + __raw_writel((value), (port)->regs + EIC_##reg)
3213 + void __iomem *regs;
3214 + struct irq_chip *chip;
3215 + unsigned int first_irq;
3218 -static void eim_ack_irq(unsigned int irq)
3219 +static void eic_ack_irq(unsigned int irq)
3221 - struct at32_sm *sm = get_irq_chip_data(irq);
3222 - sm_writel(sm, EIM_ICR, 1 << (irq - sm->eim_first_irq));
3223 + struct eic *eic = get_irq_chip_data(irq);
3224 + eic_writel(eic, ICR, 1 << (irq - eic->first_irq));
3227 -static void eim_mask_irq(unsigned int irq)
3228 +static void eic_mask_irq(unsigned int irq)
3230 - struct at32_sm *sm = get_irq_chip_data(irq);
3231 - sm_writel(sm, EIM_IDR, 1 << (irq - sm->eim_first_irq));
3232 + struct eic *eic = get_irq_chip_data(irq);
3233 + eic_writel(eic, IDR, 1 << (irq - eic->first_irq));
3236 -static void eim_mask_ack_irq(unsigned int irq)
3237 +static void eic_mask_ack_irq(unsigned int irq)
3239 - struct at32_sm *sm = get_irq_chip_data(irq);
3240 - sm_writel(sm, EIM_ICR, 1 << (irq - sm->eim_first_irq));
3241 - sm_writel(sm, EIM_IDR, 1 << (irq - sm->eim_first_irq));
3242 + struct eic *eic = get_irq_chip_data(irq);
3243 + eic_writel(eic, ICR, 1 << (irq - eic->first_irq));
3244 + eic_writel(eic, IDR, 1 << (irq - eic->first_irq));
3247 -static void eim_unmask_irq(unsigned int irq)
3248 +static void eic_unmask_irq(unsigned int irq)
3250 - struct at32_sm *sm = get_irq_chip_data(irq);
3251 - sm_writel(sm, EIM_IER, 1 << (irq - sm->eim_first_irq));
3252 + struct eic *eic = get_irq_chip_data(irq);
3253 + eic_writel(eic, IER, 1 << (irq - eic->first_irq));
3256 -static int eim_set_irq_type(unsigned int irq, unsigned int flow_type)
3257 +static int eic_set_irq_type(unsigned int irq, unsigned int flow_type)
3259 - struct at32_sm *sm = get_irq_chip_data(irq);
3260 + struct eic *eic = get_irq_chip_data(irq);
3261 struct irq_desc *desc;
3262 - unsigned int i = irq - sm->eim_first_irq;
3263 + unsigned int i = irq - eic->first_irq;
3264 u32 mode, edge, level;
3265 - unsigned long flags;
3268 flow_type &= IRQ_TYPE_SENSE_MASK;
3269 @@ -60,11 +101,10 @@
3270 flow_type = IRQ_TYPE_LEVEL_LOW;
3272 desc = &irq_desc[irq];
3273 - spin_lock_irqsave(&sm->lock, flags);
3275 - mode = sm_readl(sm, EIM_MODE);
3276 - edge = sm_readl(sm, EIM_EDGE);
3277 - level = sm_readl(sm, EIM_LEVEL);
3278 + mode = eic_readl(eic, MODE);
3279 + edge = eic_readl(eic, EDGE);
3280 + level = eic_readl(eic, LEVEL);
3282 switch (flow_type) {
3283 case IRQ_TYPE_LEVEL_LOW:
3288 - sm_writel(sm, EIM_MODE, mode);
3289 - sm_writel(sm, EIM_EDGE, edge);
3290 - sm_writel(sm, EIM_LEVEL, level);
3291 + eic_writel(eic, MODE, mode);
3292 + eic_writel(eic, EDGE, edge);
3293 + eic_writel(eic, LEVEL, level);
3295 if (flow_type & (IRQ_TYPE_LEVEL_LOW | IRQ_TYPE_LEVEL_HIGH))
3296 flow_type |= IRQ_LEVEL;
3297 @@ -99,35 +139,33 @@
3298 desc->status |= flow_type;
3301 - spin_unlock_irqrestore(&sm->lock, flags);
3306 -struct irq_chip eim_chip = {
3308 - .ack = eim_ack_irq,
3309 - .mask = eim_mask_irq,
3310 - .mask_ack = eim_mask_ack_irq,
3311 - .unmask = eim_unmask_irq,
3312 - .set_type = eim_set_irq_type,
3313 +struct irq_chip eic_chip = {
3315 + .ack = eic_ack_irq,
3316 + .mask = eic_mask_irq,
3317 + .mask_ack = eic_mask_ack_irq,
3318 + .unmask = eic_unmask_irq,
3319 + .set_type = eic_set_irq_type,
3322 -static void demux_eim_irq(unsigned int irq, struct irq_desc *desc)
3323 +static void demux_eic_irq(unsigned int irq, struct irq_desc *desc)
3325 - struct at32_sm *sm = desc->handler_data;
3326 + struct eic *eic = desc->handler_data;
3327 struct irq_desc *ext_desc;
3328 unsigned long status, pending;
3329 unsigned int i, ext_irq;
3331 - status = sm_readl(sm, EIM_ISR);
3332 - pending = status & sm_readl(sm, EIM_IMR);
3333 + status = eic_readl(eic, ISR);
3334 + pending = status & eic_readl(eic, IMR);
3337 i = fls(pending) - 1;
3338 pending &= ~(1 << i);
3340 - ext_irq = i + sm->eim_first_irq;
3341 + ext_irq = i + eic->first_irq;
3342 ext_desc = irq_desc + ext_irq;
3343 if (ext_desc->status & IRQ_LEVEL)
3344 handle_level_irq(ext_irq, ext_desc);
3345 @@ -136,51 +174,85 @@
3349 -static int __init eim_init(void)
3350 +static int __init eic_probe(struct platform_device *pdev)
3352 - struct at32_sm *sm = &system_manager;
3354 + struct resource *regs;
3356 unsigned int nr_irqs;
3357 unsigned int int_irq;
3362 - * The EIM is really the same module as SM, so register
3363 - * mapping, etc. has been taken care of already.
3365 + regs = platform_get_resource(pdev, IORESOURCE_MEM, 0);
3366 + int_irq = platform_get_irq(pdev, 0);
3367 + if (!regs || !int_irq) {
3368 + dev_dbg(&pdev->dev, "missing regs and/or irq resource\n");
3373 + eic = kzalloc(sizeof(struct eic), GFP_KERNEL);
3375 + dev_dbg(&pdev->dev, "no memory for eic structure\n");
3379 + eic->first_irq = EIM_IRQ_BASE + 32 * pdev->id;
3380 + eic->regs = ioremap(regs->start, regs->end - regs->start + 1);
3382 + dev_dbg(&pdev->dev, "failed to map regs\n");
3387 * Find out how many interrupt lines that are actually
3388 * implemented in hardware.
3390 - sm_writel(sm, EIM_IDR, ~0UL);
3391 - sm_writel(sm, EIM_MODE, ~0UL);
3392 - pattern = sm_readl(sm, EIM_MODE);
3393 + eic_writel(eic, IDR, ~0UL);
3394 + eic_writel(eic, MODE, ~0UL);
3395 + pattern = eic_readl(eic, MODE);
3396 nr_irqs = fls(pattern);
3398 /* Trigger on falling edge unless overridden by driver */
3399 - sm_writel(sm, EIM_MODE, 0UL);
3400 - sm_writel(sm, EIM_EDGE, 0UL);
3401 + eic_writel(eic, MODE, 0UL);
3402 + eic_writel(eic, EDGE, 0UL);
3404 - sm->eim_chip = &eim_chip;
3405 + eic->chip = &eic_chip;
3407 for (i = 0; i < nr_irqs; i++) {
3408 /* NOTE the handler we set here is ignored by the demux */
3409 - set_irq_chip_and_handler(sm->eim_first_irq + i, &eim_chip,
3410 + set_irq_chip_and_handler(eic->first_irq + i, &eic_chip,
3412 - set_irq_chip_data(sm->eim_first_irq + i, sm);
3413 + set_irq_chip_data(eic->first_irq + i, eic);
3416 - int_irq = platform_get_irq_byname(sm->pdev, "eim");
3418 - set_irq_chained_handler(int_irq, demux_eim_irq);
3419 - set_irq_data(int_irq, sm);
3420 + set_irq_chained_handler(int_irq, demux_eic_irq);
3421 + set_irq_data(int_irq, eic);
3423 - printk("EIM: External Interrupt Module at 0x%p, IRQ %u\n",
3424 - sm->regs, int_irq);
3425 - printk("EIM: Handling %u external IRQs, starting with IRQ %u\n",
3426 - nr_irqs, sm->eim_first_irq);
3427 + dev_info(&pdev->dev,
3428 + "External Interrupt Controller at 0x%p, IRQ %u\n",
3429 + eic->regs, int_irq);
3430 + dev_info(&pdev->dev,
3431 + "Handling %u external IRQs, starting with IRQ %u\n",
3432 + nr_irqs, eic->first_irq);
3442 +static struct platform_driver eic_driver = {
3444 + .name = "at32_eic",
3448 +static int __init eic_init(void)
3450 + return platform_driver_probe(&eic_driver, eic_probe);
3452 -arch_initcall(eim_init);
3453 +arch_initcall(eic_init);
3454 diff -x .git -Nur linux-2.6.22.1/arch/avr32/mach-at32ap/gpio-dev.c linux-avr32.git/arch/avr32/mach-at32ap/gpio-dev.c
3455 --- linux-2.6.22.1/arch/avr32/mach-at32ap/gpio-dev.c 1970-01-01 01:00:00.000000000 +0100
3456 +++ linux-avr32.git/arch/avr32/mach-at32ap/gpio-dev.c 2007-07-12 13:59:49.000000000 +0200
3459 + * GPIO /dev and configfs interface
3461 + * Copyright (C) 2006-2007 Atmel Corporation
3463 + * This program is free software; you can redistribute it and/or modify
3464 + * it under the terms of the GNU General Public License version 2 as
3465 + * published by the Free Software Foundation.
3467 +#include <linux/configfs.h>
3468 +#include <linux/cdev.h>
3469 +#include <linux/fs.h>
3470 +#include <linux/interrupt.h>
3471 +#include <linux/poll.h>
3472 +#include <linux/uaccess.h>
3473 +#include <linux/wait.h>
3475 +#include <asm/gpio.h>
3476 +#include <asm/arch/portmux.h>
3478 +#define GPIO_DEV_MAX 8
3480 +static struct class *gpio_dev_class;
3481 +static dev_t gpio_devt;
3492 + /* Pin state last time we read it (for blocking reads) */
3496 + wait_queue_head_t change_wq;
3497 + struct fasync_struct *async_queue;
3500 + struct class_device *gpio_dev;
3501 + struct cdev char_dev;
3502 + struct config_item item;
3505 +struct gpio_attribute {
3506 + struct configfs_attribute attr;
3507 + ssize_t (*show)(struct gpio_item *, char *);
3508 + ssize_t (*store)(struct gpio_item *, const char *, size_t);
3511 +static irqreturn_t gpio_dev_interrupt(int irq, void *dev_id)
3513 + struct gpio_item *gpio = dev_id;
3514 + u32 old_state, new_state;
3516 + old_state = gpio->pin_state;
3517 + new_state = at32_gpio_get_value_multiple(gpio->port, gpio->pin_mask);
3518 + gpio->pin_state = new_state;
3520 + if (new_state != old_state) {
3521 + gpio->changed = 1;
3522 + wake_up_interruptible(&gpio->change_wq);
3524 + if (gpio->async_queue)
3525 + kill_fasync(&gpio->async_queue, SIGIO, POLL_IN);
3528 + return IRQ_HANDLED;
3531 +static int gpio_dev_open(struct inode *inode, struct file *file)
3533 + struct gpio_item *gpio = container_of(inode->i_cdev,
3540 + nonseekable_open(inode, file);
3541 + config_item_get(&gpio->item);
3542 + file->private_data = gpio;
3544 + gpio->pin_state = at32_gpio_get_value_multiple(gpio->port,
3546 + gpio->changed = 1;
3548 + for (i = 0; i < 32; i++) {
3549 + if (gpio->pin_mask & (1 << i)) {
3550 + irq = gpio_to_irq(32 * gpio->port + i);
3551 + ret = request_irq(irq, gpio_dev_interrupt, 0,
3552 + "gpio-dev", gpio);
3562 + if (gpio->pin_mask & (1 << i)) {
3563 + irq = gpio_to_irq(32 * gpio->port + i);
3564 + free_irq(irq, gpio);
3568 + config_item_put(&gpio->item);
3573 +static int gpio_dev_fasync(int fd, struct file *file, int mode)
3575 + struct gpio_item *gpio = file->private_data;
3577 + return fasync_helper(fd, file, mode, &gpio->async_queue);
3580 +static int gpio_dev_release(struct inode *inode, struct file *file)
3582 + struct gpio_item *gpio = file->private_data;
3586 + gpio_dev_fasync(-1, file, 0);
3588 + for (i = 0; i < 32; i++) {
3589 + if (gpio->pin_mask & (1 << i)) {
3590 + irq = gpio_to_irq(32 * gpio->port + i);
3591 + free_irq(irq, gpio);
3595 + config_item_put(&gpio->item);
3600 +static unsigned int gpio_dev_poll(struct file *file, poll_table *wait)
3602 + struct gpio_item *gpio = file->private_data;
3603 + unsigned int mask = 0;
3605 + poll_wait(file, &gpio->change_wq, wait);
3606 + if (gpio->changed)
3607 + mask |= POLLIN | POLLRDNORM;
3612 +static ssize_t gpio_dev_read(struct file *file, char __user *buf,
3613 + size_t count, loff_t *offset)
3615 + struct gpio_item *gpio = file->private_data;
3618 + spin_lock_irq(&gpio->lock);
3619 + while (!gpio->changed) {
3620 + spin_unlock_irq(&gpio->lock);
3622 + if (file->f_flags & O_NONBLOCK)
3625 + if (wait_event_interruptible(gpio->change_wq, gpio->changed))
3626 + return -ERESTARTSYS;
3628 + spin_lock_irq(&gpio->lock);
3631 + gpio->changed = 0;
3632 + value = at32_gpio_get_value_multiple(gpio->port, gpio->pin_mask);
3634 + spin_unlock_irq(&gpio->lock);
3636 + count = min(count, (size_t)4);
3637 + if (copy_to_user(buf, &value, count))
3643 +static ssize_t gpio_dev_write(struct file *file, const char __user *buf,
3644 + size_t count, loff_t *offset)
3646 + struct gpio_item *gpio = file->private_data;
3650 + count = min(count, (size_t)4);
3651 + if (copy_from_user(&value, buf, count))
3654 + /* Assuming big endian */
3655 + mask <<= (4 - count) * 8;
3656 + mask &= gpio->pin_mask;
3658 + at32_gpio_set_value_multiple(gpio->port, value, mask);
3663 +static struct file_operations gpio_dev_fops = {
3664 + .owner = THIS_MODULE,
3665 + .llseek = no_llseek,
3666 + .open = gpio_dev_open,
3667 + .release = gpio_dev_release,
3668 + .fasync = gpio_dev_fasync,
3669 + .poll = gpio_dev_poll,
3670 + .read = gpio_dev_read,
3671 + .write = gpio_dev_write,
3674 +static struct gpio_item *to_gpio_item(struct config_item *item)
3676 + return item ? container_of(item, struct gpio_item, item) : NULL;
3679 +static ssize_t gpio_show_gpio_id(struct gpio_item *gpio, char *page)
3681 + return sprintf(page, "%d\n", gpio->port);
3684 +static ssize_t gpio_store_gpio_id(struct gpio_item *gpio,
3685 + const char *page, size_t count)
3688 + char *p = (char *)page;
3689 + ssize_t ret = -EINVAL;
3691 + id = simple_strtoul(p, &p, 0);
3692 + if (!p || (*p && (*p != '\n')))
3695 + /* Switching PIO is not allowed when live... */
3696 + spin_lock(&gpio->lock);
3697 + if (!gpio->enabled) {
3699 + if (at32_gpio_port_is_valid(id)) {
3704 + spin_unlock(&gpio->lock);
3709 +static ssize_t gpio_show_pin_mask(struct gpio_item *gpio, char *page)
3711 + return sprintf(page, "0x%08x\n", gpio->pin_mask);
3714 +static ssize_t gpio_store_pin_mask(struct gpio_item *gpio,
3715 + const char *page, size_t count)
3718 + char *p = (char *)page;
3719 + ssize_t ret = -EINVAL;
3721 + new_mask = simple_strtoul(p, &p, 0);
3722 + if (!p || (*p && (*p != '\n')))
3725 + /* Can't update the pin mask while live. */
3726 + spin_lock(&gpio->lock);
3727 + if (!gpio->enabled) {
3728 + gpio->oe_mask &= new_mask;
3729 + gpio->pin_mask = new_mask;
3732 + spin_unlock(&gpio->lock);
3737 +static ssize_t gpio_show_oe_mask(struct gpio_item *gpio, char *page)
3739 + return sprintf(page, "0x%08x\n", gpio->oe_mask);
3742 +static ssize_t gpio_store_oe_mask(struct gpio_item *gpio,
3743 + const char *page, size_t count)
3746 + char *p = (char *)page;
3747 + ssize_t ret = -EINVAL;
3749 + mask = simple_strtoul(p, &p, 0);
3750 + if (!p || (*p && (*p != '\n')))
3753 + spin_lock(&gpio->lock);
3754 + if (!gpio->enabled) {
3755 + gpio->oe_mask = mask & gpio->pin_mask;
3758 + spin_unlock(&gpio->lock);
3763 +static ssize_t gpio_show_enabled(struct gpio_item *gpio, char *page)
3765 + return sprintf(page, "%d\n", gpio->enabled);
3768 +static ssize_t gpio_store_enabled(struct gpio_item *gpio,
3769 + const char *page, size_t count)
3771 + char *p = (char *)page;
3775 + enabled = simple_strtoul(p, &p, 0);
3776 + if (!p || (*p && (*p != '\n')))
3779 + /* make it a boolean value */
3780 + enabled = !!enabled;
3782 + if (gpio->enabled == enabled)
3783 + /* No change; do nothing. */
3786 + BUG_ON(gpio->id >= GPIO_DEV_MAX);
3789 + class_device_unregister(gpio->gpio_dev);
3790 + cdev_del(&gpio->char_dev);
3791 + at32_deselect_pins(gpio->port, gpio->pin_mask);
3792 + gpio->initialized = 0;
3794 + if (gpio->port < 0 || !gpio->pin_mask)
3798 + /* Disallow any updates to gpio_id or pin_mask */
3799 + spin_lock(&gpio->lock);
3800 + gpio->enabled = enabled;
3801 + spin_unlock(&gpio->lock);
3806 + /* Now, try to allocate the pins */
3807 + ret = at32_select_gpio_pins(gpio->port, gpio->pin_mask, gpio->oe_mask);
3809 + goto err_alloc_pins;
3811 + gpio->initialized = 1;
3813 + cdev_init(&gpio->char_dev, &gpio_dev_fops);
3814 + gpio->char_dev.owner = THIS_MODULE;
3815 + ret = cdev_add(&gpio->char_dev, MKDEV(MAJOR(gpio_devt), gpio->id), 1);
3817 + goto err_cdev_add;
3818 + gpio->gpio_dev = class_device_create(gpio_dev_class, NULL,
3819 + MKDEV(MAJOR(gpio_devt), gpio->id),
3821 + "gpio%d", gpio->id);
3822 + if (IS_ERR(gpio->gpio_dev)) {
3823 + printk(KERN_ERR "failed to create gpio%d\n", gpio->id);
3824 + ret = PTR_ERR(gpio->gpio_dev);
3825 + goto err_class_dev;
3828 + printk(KERN_INFO "created gpio%d (port%d/0x%08x) as (%d:%d)\n",
3829 + gpio->id, gpio->port, gpio->pin_mask,
3830 + MAJOR(gpio->gpio_dev->devt), MINOR(gpio->gpio_dev->devt));
3835 + cdev_del(&gpio->char_dev);
3837 + at32_deselect_pins(gpio->port, gpio->pin_mask);
3838 + gpio->initialized = 0;
3840 + spin_lock(&gpio->lock);
3841 + gpio->enabled = 0;
3842 + spin_unlock(&gpio->lock);
3847 +static struct gpio_attribute gpio_item_attr_gpio_id = {
3849 + .ca_owner = THIS_MODULE,
3850 + .ca_name = "gpio_id",
3851 + .ca_mode = S_IRUGO | S_IWUSR,
3853 + .show = gpio_show_gpio_id,
3854 + .store = gpio_store_gpio_id,
3856 +static struct gpio_attribute gpio_item_attr_pin_mask = {
3858 + .ca_owner = THIS_MODULE,
3859 + .ca_name = "pin_mask",
3860 + .ca_mode = S_IRUGO | S_IWUSR,
3862 + .show = gpio_show_pin_mask,
3863 + .store = gpio_store_pin_mask,
3865 +static struct gpio_attribute gpio_item_attr_oe_mask = {
3867 + .ca_owner = THIS_MODULE,
3868 + .ca_name = "oe_mask",
3869 + .ca_mode = S_IRUGO | S_IWUSR,
3871 + .show = gpio_show_oe_mask,
3872 + .store = gpio_store_oe_mask,
3874 +static struct gpio_attribute gpio_item_attr_enabled = {
3876 + .ca_owner = THIS_MODULE,
3877 + .ca_name = "enabled",
3878 + .ca_mode = S_IRUGO | S_IWUSR,
3880 + .show = gpio_show_enabled,
3881 + .store = gpio_store_enabled,
3884 +static struct configfs_attribute *gpio_item_attrs[] = {
3885 + &gpio_item_attr_gpio_id.attr,
3886 + &gpio_item_attr_pin_mask.attr,
3887 + &gpio_item_attr_oe_mask.attr,
3888 + &gpio_item_attr_enabled.attr,
3892 +static ssize_t gpio_show_attr(struct config_item *item,
3893 + struct configfs_attribute *attr,
3896 + struct gpio_item *gpio_item = to_gpio_item(item);
3897 + struct gpio_attribute *gpio_attr
3898 + = container_of(attr, struct gpio_attribute, attr);
3901 + if (gpio_attr->show)
3902 + ret = gpio_attr->show(gpio_item, page);
3906 +static ssize_t gpio_store_attr(struct config_item *item,
3907 + struct configfs_attribute *attr,
3908 + const char *page, size_t count)
3910 + struct gpio_item *gpio_item = to_gpio_item(item);
3911 + struct gpio_attribute *gpio_attr
3912 + = container_of(attr, struct gpio_attribute, attr);
3913 + ssize_t ret = -EINVAL;
3915 + if (gpio_attr->store)
3916 + ret = gpio_attr->store(gpio_item, page, count);
3920 +static void gpio_release(struct config_item *item)
3922 + kfree(to_gpio_item(item));
3925 +static struct configfs_item_operations gpio_item_ops = {
3926 + .release = gpio_release,
3927 + .show_attribute = gpio_show_attr,
3928 + .store_attribute = gpio_store_attr,
3931 +static struct config_item_type gpio_item_type = {
3932 + .ct_item_ops = &gpio_item_ops,
3933 + .ct_attrs = gpio_item_attrs,
3934 + .ct_owner = THIS_MODULE,
3937 +static struct config_item *gpio_make_item(struct config_group *group,
3940 + static int next_id;
3941 + struct gpio_item *gpio;
3943 + if (next_id >= GPIO_DEV_MAX)
3946 + gpio = kzalloc(sizeof(struct gpio_item), GFP_KERNEL);
3950 + gpio->id = next_id++;
3951 + config_item_init_type_name(&gpio->item, name, &gpio_item_type);
3952 + spin_lock_init(&gpio->lock);
3953 + init_waitqueue_head(&gpio->change_wq);
3955 + return &gpio->item;
3958 +static void gpio_drop_item(struct config_group *group,
3959 + struct config_item *item)
3961 + struct gpio_item *gpio = to_gpio_item(item);
3963 + spin_lock(&gpio->lock);
3964 + if (gpio->enabled) {
3965 + class_device_unregister(gpio->gpio_dev);
3966 + cdev_del(&gpio->char_dev);
3969 + if (gpio->initialized) {
3970 + at32_deselect_pins(gpio->port, gpio->pin_mask);
3971 + gpio->initialized = 0;
3972 + gpio->enabled = 0;
3974 + spin_unlock(&gpio->lock);
3977 +static struct configfs_group_operations gpio_group_ops = {
3978 + .make_item = gpio_make_item,
3979 + .drop_item = gpio_drop_item,
3982 +static struct config_item_type gpio_group_type = {
3983 + .ct_group_ops = &gpio_group_ops,
3984 + .ct_owner = THIS_MODULE,
3987 +static struct configfs_subsystem gpio_subsys = {
3990 + .ci_namebuf = "gpio",
3991 + .ci_type = &gpio_group_type,
3996 +static int __init gpio_dev_init(void)
4000 + gpio_dev_class = class_create(THIS_MODULE, "gpio-dev");
4001 + if (IS_ERR(gpio_dev_class)) {
4002 + err = PTR_ERR(gpio_dev_class);
4003 + goto err_class_create;
4006 + err = alloc_chrdev_region(&gpio_devt, 0, GPIO_DEV_MAX, "gpio");
4008 + goto err_alloc_chrdev;
4010 + /* Configfs initialization */
4011 + config_group_init(&gpio_subsys.su_group);
4012 + init_MUTEX(&gpio_subsys.su_sem);
4013 + err = configfs_register_subsystem(&gpio_subsys);
4015 + goto err_register_subsys;
4019 +err_register_subsys:
4020 + unregister_chrdev_region(gpio_devt, GPIO_DEV_MAX);
4022 + class_destroy(gpio_dev_class);
4024 + printk(KERN_WARNING "Failed to initialize gpio /dev interface\n");
4027 +late_initcall(gpio_dev_init);
4028 diff -x .git -Nur linux-2.6.22.1/arch/avr32/mach-at32ap/Kconfig linux-avr32.git/arch/avr32/mach-at32ap/Kconfig
4029 --- linux-2.6.22.1/arch/avr32/mach-at32ap/Kconfig 2007-07-10 20:56:30.000000000 +0200
4030 +++ linux-avr32.git/arch/avr32/mach-at32ap/Kconfig 2007-07-12 13:59:49.000000000 +0200
4036 + bool "GPIO /dev interface"
4037 + select CONFIGFS_FS
4040 + Say `Y' to enable a /dev interface to the GPIO pins.
4044 endif # PLATFORM_AT32AP
4045 diff -x .git -Nur linux-2.6.22.1/arch/avr32/mach-at32ap/Makefile linux-avr32.git/arch/avr32/mach-at32ap/Makefile
4046 --- linux-2.6.22.1/arch/avr32/mach-at32ap/Makefile 2007-07-10 20:56:30.000000000 +0200
4047 +++ linux-avr32.git/arch/avr32/mach-at32ap/Makefile 2007-07-12 13:59:49.000000000 +0200
4049 obj-y += at32ap.o clock.o intc.o extint.o pio.o hsmc.o
4050 obj-$(CONFIG_CPU_AT32AP7000) += at32ap7000.o
4051 obj-$(CONFIG_CPU_AT32AP7000) += time-tc.o
4052 +obj-$(CONFIG_CPU_FREQ_AT32AP) += cpufreq.o
4053 +obj-$(CONFIG_GPIO_DEV) += gpio-dev.o
4054 diff -x .git -Nur linux-2.6.22.1/arch/avr32/mach-at32ap/pio.c linux-avr32.git/arch/avr32/mach-at32ap/pio.c
4055 --- linux-2.6.22.1/arch/avr32/mach-at32ap/pio.c 2007-07-10 20:56:30.000000000 +0200
4056 +++ linux-avr32.git/arch/avr32/mach-at32ap/pio.c 2007-07-12 13:59:49.000000000 +0200
4057 @@ -158,6 +158,82 @@
4061 +#ifdef CONFIG_GPIO_DEV
4063 +/* Gang allocators and accessors; used by the GPIO /dev driver */
4064 +int at32_gpio_port_is_valid(unsigned int port)
4066 + return port < MAX_NR_PIO_DEVICES && pio_dev[port].regs != NULL;
4069 +int at32_select_gpio_pins(unsigned int port, u32 pins, u32 oe_mask)
4071 + struct pio_device *pio;
4074 + pio = &pio_dev[port];
4075 + BUG_ON(port > ARRAY_SIZE(pio_dev) || !pio->regs || (oe_mask & ~pins));
4077 + /* Try to allocate the pins */
4079 + old = pio->pinmux_mask;
4084 + } while (cmpxchg(&pio->pinmux_mask, old, new) != old);
4086 + /* That went well, now configure the port */
4087 + pio_writel(pio, OER, oe_mask);
4088 + pio_writel(pio, PER, pins);
4093 +void at32_deselect_pins(unsigned int port, u32 pins)
4095 + struct pio_device *pio;
4098 + pio = &pio_dev[port];
4099 + BUG_ON(port > ARRAY_SIZE(pio_dev) || !pio->regs);
4101 + /* Return to a "safe" mux configuration */
4102 + pio_writel(pio, PUER, pins);
4103 + pio_writel(pio, ODR, pins);
4105 + /* Deallocate the pins */
4107 + old = pio->pinmux_mask;
4108 + new = old & ~pins;
4109 + } while (cmpxchg(&pio->pinmux_mask, old, new) != old);
4112 +u32 at32_gpio_get_value_multiple(unsigned int port, u32 pins)
4114 + struct pio_device *pio;
4116 + pio = &pio_dev[port];
4117 + BUG_ON(port > ARRAY_SIZE(pio_dev) || !pio->regs);
4119 + return pio_readl(pio, PDSR) & pins;
4122 +void at32_gpio_set_value_multiple(unsigned int port, u32 value, u32 mask)
4124 + struct pio_device *pio;
4126 + pio = &pio_dev[port];
4127 + BUG_ON(port > ARRAY_SIZE(pio_dev) || !pio->regs);
4129 + /* No atomic updates for now... */
4130 + pio_writel(pio, CODR, ~value & mask);
4131 + pio_writel(pio, SODR, value & mask);
4134 +#endif /* CONFIG_GPIO_DEV */
4137 /*--------------------------------------------------------------------------*/
4140 diff -x .git -Nur linux-2.6.22.1/arch/avr32/mach-at32ap/pm.h linux-avr32.git/arch/avr32/mach-at32ap/pm.h
4141 --- linux-2.6.22.1/arch/avr32/mach-at32ap/pm.h 1970-01-01 01:00:00.000000000 +0100
4142 +++ linux-avr32.git/arch/avr32/mach-at32ap/pm.h 2007-07-12 13:59:49.000000000 +0200
4145 + * Register definitions for the Power Manager (PM)
4147 +#ifndef __ARCH_AVR32_MACH_AT32AP_PM_H__
4148 +#define __ARCH_AVR32_MACH_AT32AP_PM_H__
4150 +/* PM register offsets */
4151 +#define PM_MCCTRL 0x0000
4152 +#define PM_CKSEL 0x0004
4153 +#define PM_CPU_MASK 0x0008
4154 +#define PM_HSB_MASK 0x000c
4155 +#define PM_PBA_MASK 0x0010
4156 +#define PM_PBB_MASK 0x0014
4157 +#define PM_PLL0 0x0020
4158 +#define PM_PLL1 0x0024
4159 +#define PM_IER 0x0040
4160 +#define PM_IDR 0x0044
4161 +#define PM_IMR 0x0048
4162 +#define PM_ISR 0x004c
4163 +#define PM_ICR 0x0050
4164 +#define PM_GCCTRL(x) (0x0060 + 4 * (x))
4165 +#define PM_RCAUSE 0x00c0
4167 +/* Bitfields in CKSEL */
4168 +#define PM_CPUSEL_OFFSET 0
4169 +#define PM_CPUSEL_SIZE 3
4170 +#define PM_CPUDIV_OFFSET 7
4171 +#define PM_CPUDIV_SIZE 1
4172 +#define PM_HSBSEL_OFFSET 8
4173 +#define PM_HSBSEL_SIZE 3
4174 +#define PM_HSBDIV_OFFSET 15
4175 +#define PM_HSBDIV_SIZE 1
4176 +#define PM_PBASEL_OFFSET 16
4177 +#define PM_PBASEL_SIZE 3
4178 +#define PM_PBADIV_OFFSET 23
4179 +#define PM_PBADIV_SIZE 1
4180 +#define PM_PBBSEL_OFFSET 24
4181 +#define PM_PBBSEL_SIZE 3
4182 +#define PM_PBBDIV_OFFSET 31
4183 +#define PM_PBBDIV_SIZE 1
4185 +/* Bitfields in PLL0 */
4186 +#define PM_PLLEN_OFFSET 0
4187 +#define PM_PLLEN_SIZE 1
4188 +#define PM_PLLOSC_OFFSET 1
4189 +#define PM_PLLOSC_SIZE 1
4190 +#define PM_PLLOPT_OFFSET 2
4191 +#define PM_PLLOPT_SIZE 3
4192 +#define PM_PLLDIV_OFFSET 8
4193 +#define PM_PLLDIV_SIZE 8
4194 +#define PM_PLLMUL_OFFSET 16
4195 +#define PM_PLLMUL_SIZE 8
4196 +#define PM_PLLCOUNT_OFFSET 24
4197 +#define PM_PLLCOUNT_SIZE 6
4198 +#define PM_PLLTEST_OFFSET 31
4199 +#define PM_PLLTEST_SIZE 1
4201 +/* Bitfields in ICR */
4202 +#define PM_LOCK0_OFFSET 0
4203 +#define PM_LOCK0_SIZE 1
4204 +#define PM_LOCK1_OFFSET 1
4205 +#define PM_LOCK1_SIZE 1
4206 +#define PM_WAKE_OFFSET 2
4207 +#define PM_WAKE_SIZE 1
4208 +#define PM_CKRDY_OFFSET 5
4209 +#define PM_CKRDY_SIZE 1
4210 +#define PM_MSKRDY_OFFSET 6
4211 +#define PM_MSKRDY_SIZE 1
4213 +/* Bitfields in GCCTRL0 */
4214 +#define PM_OSCSEL_OFFSET 0
4215 +#define PM_OSCSEL_SIZE 1
4216 +#define PM_PLLSEL_OFFSET 1
4217 +#define PM_PLLSEL_SIZE 1
4218 +#define PM_CEN_OFFSET 2
4219 +#define PM_CEN_SIZE 1
4220 +#define PM_DIVEN_OFFSET 4
4221 +#define PM_DIVEN_SIZE 1
4222 +#define PM_DIV_OFFSET 8
4223 +#define PM_DIV_SIZE 8
4225 +/* Bitfields in RCAUSE */
4226 +#define PM_POR_OFFSET 0
4227 +#define PM_POR_SIZE 1
4228 +#define PM_EXT_OFFSET 2
4229 +#define PM_EXT_SIZE 1
4230 +#define PM_WDT_OFFSET 3
4231 +#define PM_WDT_SIZE 1
4232 +#define PM_NTAE_OFFSET 4
4233 +#define PM_NTAE_SIZE 1
4235 +/* Bit manipulation macros */
4236 +#define PM_BIT(name) \
4237 + (1 << PM_##name##_OFFSET)
4238 +#define PM_BF(name,value) \
4239 + (((value) & ((1 << PM_##name##_SIZE) - 1)) \
4240 + << PM_##name##_OFFSET)
4241 +#define PM_BFEXT(name,value) \
4242 + (((value) >> PM_##name##_OFFSET) \
4243 + & ((1 << PM_##name##_SIZE) - 1))
4244 +#define PM_BFINS(name,value,old)\
4245 + (((old) & ~(((1 << PM_##name##_SIZE) - 1) \
4246 + << PM_##name##_OFFSET)) \
4247 + | PM_BF(name,value))
4249 +/* Register access macros */
4250 +#define pm_readl(reg) \
4251 + __raw_readl((void __iomem *)AT32_PM_BASE + PM_##reg)
4252 +#define pm_writel(reg,value) \
4253 + __raw_writel((value), (void __iomem *)AT32_PM_BASE + PM_##reg)
4255 +#endif /* __ARCH_AVR32_MACH_AT32AP_PM_H__ */
4256 diff -x .git -Nur linux-2.6.22.1/arch/avr32/mach-at32ap/sm.h linux-avr32.git/arch/avr32/mach-at32ap/sm.h
4257 --- linux-2.6.22.1/arch/avr32/mach-at32ap/sm.h 2007-07-10 20:56:30.000000000 +0200
4258 +++ linux-avr32.git/arch/avr32/mach-at32ap/sm.h 1970-01-01 01:00:00.000000000 +0100
4261 - * Register definitions for SM
4265 -#ifndef __ASM_AVR32_SM_H__
4266 -#define __ASM_AVR32_SM_H__
4268 -/* SM register offsets */
4269 -#define SM_PM_MCCTRL 0x0000
4270 -#define SM_PM_CKSEL 0x0004
4271 -#define SM_PM_CPU_MASK 0x0008
4272 -#define SM_PM_HSB_MASK 0x000c
4273 -#define SM_PM_PBA_MASK 0x0010
4274 -#define SM_PM_PBB_MASK 0x0014
4275 -#define SM_PM_PLL0 0x0020
4276 -#define SM_PM_PLL1 0x0024
4277 -#define SM_PM_VCTRL 0x0030
4278 -#define SM_PM_VMREF 0x0034
4279 -#define SM_PM_VMV 0x0038
4280 -#define SM_PM_IER 0x0040
4281 -#define SM_PM_IDR 0x0044
4282 -#define SM_PM_IMR 0x0048
4283 -#define SM_PM_ISR 0x004c
4284 -#define SM_PM_ICR 0x0050
4285 -#define SM_PM_GCCTRL 0x0060
4286 -#define SM_RTC_CTRL 0x0080
4287 -#define SM_RTC_VAL 0x0084
4288 -#define SM_RTC_TOP 0x0088
4289 -#define SM_RTC_IER 0x0090
4290 -#define SM_RTC_IDR 0x0094
4291 -#define SM_RTC_IMR 0x0098
4292 -#define SM_RTC_ISR 0x009c
4293 -#define SM_RTC_ICR 0x00a0
4294 -#define SM_WDT_CTRL 0x00b0
4295 -#define SM_WDT_CLR 0x00b4
4296 -#define SM_WDT_EXT 0x00b8
4297 -#define SM_RC_RCAUSE 0x00c0
4298 -#define SM_EIM_IER 0x0100
4299 -#define SM_EIM_IDR 0x0104
4300 -#define SM_EIM_IMR 0x0108
4301 -#define SM_EIM_ISR 0x010c
4302 -#define SM_EIM_ICR 0x0110
4303 -#define SM_EIM_MODE 0x0114
4304 -#define SM_EIM_EDGE 0x0118
4305 -#define SM_EIM_LEVEL 0x011c
4306 -#define SM_EIM_TEST 0x0120
4307 -#define SM_EIM_NMIC 0x0124
4309 -/* Bitfields in PM_MCCTRL */
4311 -/* Bitfields in PM_CKSEL */
4312 -#define SM_CPUSEL_OFFSET 0
4313 -#define SM_CPUSEL_SIZE 3
4314 -#define SM_CPUDIV_OFFSET 7
4315 -#define SM_CPUDIV_SIZE 1
4316 -#define SM_HSBSEL_OFFSET 8
4317 -#define SM_HSBSEL_SIZE 3
4318 -#define SM_HSBDIV_OFFSET 15
4319 -#define SM_HSBDIV_SIZE 1
4320 -#define SM_PBASEL_OFFSET 16
4321 -#define SM_PBASEL_SIZE 3
4322 -#define SM_PBADIV_OFFSET 23
4323 -#define SM_PBADIV_SIZE 1
4324 -#define SM_PBBSEL_OFFSET 24
4325 -#define SM_PBBSEL_SIZE 3
4326 -#define SM_PBBDIV_OFFSET 31
4327 -#define SM_PBBDIV_SIZE 1
4329 -/* Bitfields in PM_CPU_MASK */
4331 -/* Bitfields in PM_HSB_MASK */
4333 -/* Bitfields in PM_PBA_MASK */
4335 -/* Bitfields in PM_PBB_MASK */
4337 -/* Bitfields in PM_PLL0 */
4338 -#define SM_PLLEN_OFFSET 0
4339 -#define SM_PLLEN_SIZE 1
4340 -#define SM_PLLOSC_OFFSET 1
4341 -#define SM_PLLOSC_SIZE 1
4342 -#define SM_PLLOPT_OFFSET 2
4343 -#define SM_PLLOPT_SIZE 3
4344 -#define SM_PLLDIV_OFFSET 8
4345 -#define SM_PLLDIV_SIZE 8
4346 -#define SM_PLLMUL_OFFSET 16
4347 -#define SM_PLLMUL_SIZE 8
4348 -#define SM_PLLCOUNT_OFFSET 24
4349 -#define SM_PLLCOUNT_SIZE 6
4350 -#define SM_PLLTEST_OFFSET 31
4351 -#define SM_PLLTEST_SIZE 1
4353 -/* Bitfields in PM_PLL1 */
4355 -/* Bitfields in PM_VCTRL */
4356 -#define SM_VAUTO_OFFSET 0
4357 -#define SM_VAUTO_SIZE 1
4358 -#define SM_PM_VCTRL_VAL_OFFSET 8
4359 -#define SM_PM_VCTRL_VAL_SIZE 7
4361 -/* Bitfields in PM_VMREF */
4362 -#define SM_REFSEL_OFFSET 0
4363 -#define SM_REFSEL_SIZE 4
4365 -/* Bitfields in PM_VMV */
4366 -#define SM_PM_VMV_VAL_OFFSET 0
4367 -#define SM_PM_VMV_VAL_SIZE 8
4369 -/* Bitfields in PM_IER */
4371 -/* Bitfields in PM_IDR */
4373 -/* Bitfields in PM_IMR */
4375 -/* Bitfields in PM_ISR */
4377 -/* Bitfields in PM_ICR */
4378 -#define SM_LOCK0_OFFSET 0
4379 -#define SM_LOCK0_SIZE 1
4380 -#define SM_LOCK1_OFFSET 1
4381 -#define SM_LOCK1_SIZE 1
4382 -#define SM_WAKE_OFFSET 2
4383 -#define SM_WAKE_SIZE 1
4384 -#define SM_VOK_OFFSET 3
4385 -#define SM_VOK_SIZE 1
4386 -#define SM_VMRDY_OFFSET 4
4387 -#define SM_VMRDY_SIZE 1
4388 -#define SM_CKRDY_OFFSET 5
4389 -#define SM_CKRDY_SIZE 1
4391 -/* Bitfields in PM_GCCTRL */
4392 -#define SM_OSCSEL_OFFSET 0
4393 -#define SM_OSCSEL_SIZE 1
4394 -#define SM_PLLSEL_OFFSET 1
4395 -#define SM_PLLSEL_SIZE 1
4396 -#define SM_CEN_OFFSET 2
4397 -#define SM_CEN_SIZE 1
4398 -#define SM_CPC_OFFSET 3
4399 -#define SM_CPC_SIZE 1
4400 -#define SM_DIVEN_OFFSET 4
4401 -#define SM_DIVEN_SIZE 1
4402 -#define SM_DIV_OFFSET 8
4403 -#define SM_DIV_SIZE 8
4405 -/* Bitfields in RTC_CTRL */
4406 -#define SM_PCLR_OFFSET 1
4407 -#define SM_PCLR_SIZE 1
4408 -#define SM_TOPEN_OFFSET 2
4409 -#define SM_TOPEN_SIZE 1
4410 -#define SM_CLKEN_OFFSET 3
4411 -#define SM_CLKEN_SIZE 1
4412 -#define SM_PSEL_OFFSET 8
4413 -#define SM_PSEL_SIZE 16
4415 -/* Bitfields in RTC_VAL */
4416 -#define SM_RTC_VAL_VAL_OFFSET 0
4417 -#define SM_RTC_VAL_VAL_SIZE 31
4419 -/* Bitfields in RTC_TOP */
4420 -#define SM_RTC_TOP_VAL_OFFSET 0
4421 -#define SM_RTC_TOP_VAL_SIZE 32
4423 -/* Bitfields in RTC_IER */
4425 -/* Bitfields in RTC_IDR */
4427 -/* Bitfields in RTC_IMR */
4429 -/* Bitfields in RTC_ISR */
4431 -/* Bitfields in RTC_ICR */
4432 -#define SM_TOPI_OFFSET 0
4433 -#define SM_TOPI_SIZE 1
4435 -/* Bitfields in WDT_CTRL */
4436 -#define SM_KEY_OFFSET 24
4437 -#define SM_KEY_SIZE 8
4439 -/* Bitfields in WDT_CLR */
4441 -/* Bitfields in WDT_EXT */
4443 -/* Bitfields in RC_RCAUSE */
4444 -#define SM_POR_OFFSET 0
4445 -#define SM_POR_SIZE 1
4446 -#define SM_BOD_OFFSET 1
4447 -#define SM_BOD_SIZE 1
4448 -#define SM_EXT_OFFSET 2
4449 -#define SM_EXT_SIZE 1
4450 -#define SM_WDT_OFFSET 3
4451 -#define SM_WDT_SIZE 1
4452 -#define SM_NTAE_OFFSET 4
4453 -#define SM_NTAE_SIZE 1
4454 -#define SM_SERP_OFFSET 5
4455 -#define SM_SERP_SIZE 1
4457 -/* Bitfields in EIM_IER */
4459 -/* Bitfields in EIM_IDR */
4461 -/* Bitfields in EIM_IMR */
4463 -/* Bitfields in EIM_ISR */
4465 -/* Bitfields in EIM_ICR */
4467 -/* Bitfields in EIM_MODE */
4469 -/* Bitfields in EIM_EDGE */
4470 -#define SM_INT0_OFFSET 0
4471 -#define SM_INT0_SIZE 1
4472 -#define SM_INT1_OFFSET 1
4473 -#define SM_INT1_SIZE 1
4474 -#define SM_INT2_OFFSET 2
4475 -#define SM_INT2_SIZE 1
4476 -#define SM_INT3_OFFSET 3
4477 -#define SM_INT3_SIZE 1
4479 -/* Bitfields in EIM_LEVEL */
4481 -/* Bitfields in EIM_TEST */
4482 -#define SM_TESTEN_OFFSET 31
4483 -#define SM_TESTEN_SIZE 1
4485 -/* Bitfields in EIM_NMIC */
4486 -#define SM_EN_OFFSET 0
4487 -#define SM_EN_SIZE 1
4489 -/* Bit manipulation macros */
4490 -#define SM_BIT(name) (1 << SM_##name##_OFFSET)
4491 -#define SM_BF(name,value) (((value) & ((1 << SM_##name##_SIZE) - 1)) << SM_##name##_OFFSET)
4492 -#define SM_BFEXT(name,value) (((value) >> SM_##name##_OFFSET) & ((1 << SM_##name##_SIZE) - 1))
4493 -#define SM_BFINS(name,value,old) (((old) & ~(((1 << SM_##name##_SIZE) - 1) << SM_##name##_OFFSET)) | SM_BF(name,value))
4495 -/* Register access macros */
4496 -#define sm_readl(port,reg) \
4497 - __raw_readl((port)->regs + SM_##reg)
4498 -#define sm_writel(port,reg,value) \
4499 - __raw_writel((value), (port)->regs + SM_##reg)
4501 -#endif /* __ASM_AVR32_SM_H__ */
4502 diff -x .git -Nur linux-2.6.22.1/arch/avr32/Makefile linux-avr32.git/arch/avr32/Makefile
4503 --- linux-2.6.22.1/arch/avr32/Makefile 2007-07-10 20:56:30.000000000 +0200
4504 +++ linux-avr32.git/arch/avr32/Makefile 2007-06-06 11:33:46.000000000 +0200
4506 core-$(CONFIG_LOADER_U_BOOT) += arch/avr32/boot/u-boot/
4507 core-y += arch/avr32/kernel/
4508 core-y += arch/avr32/mm/
4509 +drivers-y += arch/avr32/drivers/
4510 libs-y += arch/avr32/lib/
4512 archincdir-$(CONFIG_PLATFORM_AT32AP) := arch-at32ap
4513 diff -x .git -Nur linux-2.6.22.1/arch/avr32/mm/dma-coherent.c linux-avr32.git/arch/avr32/mm/dma-coherent.c
4514 --- linux-2.6.22.1/arch/avr32/mm/dma-coherent.c 2007-07-10 20:56:30.000000000 +0200
4515 +++ linux-avr32.git/arch/avr32/mm/dma-coherent.c 2007-07-12 13:59:49.000000000 +0200
4517 struct page *page, *free, *end;
4520 + /* Following is a work-around (a.k.a. hack) to prevent pages
4521 + * with __GFP_COMP being passed to split_page() which cannot
4522 + * handle them. The real problem is that this flag probably
4523 + * should be 0 on AVR32 as it is not supported on this
4524 + * platform--see CONFIG_HUGETLB_PAGE. */
4525 + gfp &= ~(__GFP_COMP);
4527 size = PAGE_ALIGN(size);
4528 order = get_order(size);
4530 diff -x .git -Nur linux-2.6.22.1/drivers/char/watchdog/at32ap700x_wdt.c linux-avr32.git/drivers/char/watchdog/at32ap700x_wdt.c
4531 --- linux-2.6.22.1/drivers/char/watchdog/at32ap700x_wdt.c 1970-01-01 01:00:00.000000000 +0100
4532 +++ linux-avr32.git/drivers/char/watchdog/at32ap700x_wdt.c 2007-07-12 13:59:59.000000000 +0200
4535 + * Watchdog driver for Atmel AT32AP700X devices
4537 + * Copyright (C) 2005-2006 Atmel Corporation
4539 + * This program is free software; you can redistribute it and/or modify
4540 + * it under the terms of the GNU General Public License version 2 as
4541 + * published by the Free Software Foundation.
4544 +#include <linux/init.h>
4545 +#include <linux/kernel.h>
4546 +#include <linux/module.h>
4547 +#include <linux/moduleparam.h>
4548 +#include <linux/miscdevice.h>
4549 +#include <linux/fs.h>
4550 +#include <linux/platform_device.h>
4551 +#include <linux/watchdog.h>
4552 +#include <linux/uaccess.h>
4553 +#include <linux/io.h>
4555 +#define TIMEOUT_MIN 1
4556 +#define TIMEOUT_DEFAULT CONFIG_AT32AP700X_WDT_TIMEOUT
4557 +#define TIMEOUT_MAX 2
4559 +/* Watchdog registers and write/read macro */
4560 +#define WDT_CTRL 0x00
4561 +#define WDT_CTRL_EN 0
4562 +#define WDT_CTRL_PSEL 8
4563 +#define WDT_CTRL_KEY 24
4565 +#define WDT_CLR 0x04
4567 +#define WDT_BIT(name) (1 << WDT_##name)
4568 +#define WDT_BF(name,value) ((value) << WDT_##name)
4570 +#define wdt_readl(dev,reg) \
4571 + __raw_readl((dev)->regs + WDT_##reg)
4572 +#define wdt_writel(dev,reg,value) \
4573 + __raw_writel((value), (dev)->regs + WDT_##reg)
4575 +struct wdt_at32ap700x {
4576 + void __iomem *regs;
4579 + struct miscdevice miscdev;
4582 +static struct wdt_at32ap700x *wdt;
4585 + * Disable the watchdog.
4587 +static void inline at32_wdt_stop(void)
4589 + unsigned long psel = wdt_readl(wdt, CTRL) & WDT_BF(CTRL_PSEL, 0x0f);
4590 + wdt_writel(wdt, CTRL, psel | WDT_BF(CTRL_KEY, 0x55));
4591 + wdt_writel(wdt, CTRL, psel | WDT_BF(CTRL_KEY, 0xaa));
4595 + * Enable and reset the watchdog.
4597 +static void inline at32_wdt_start(void)
4599 + /* 0xf is 2^16 divider = 2 sec, 0xe is 2^15 divider = 1 sec */
4600 + unsigned long psel = (wdt->timeout > 1) ? 0xf : 0xe;
4602 + wdt_writel(wdt, CTRL, WDT_BIT(CTRL_EN)
4603 + | WDT_BF(CTRL_PSEL, psel)
4604 + | WDT_BF(CTRL_KEY, 0x55));
4605 + wdt_writel(wdt, CTRL, WDT_BIT(CTRL_EN)
4606 + | WDT_BF(CTRL_PSEL, psel)
4607 + | WDT_BF(CTRL_KEY, 0xaa));
4611 + * Pat the watchdog timer.
4613 +static void inline at32_wdt_pat(void)
4615 + wdt_writel(wdt, CLR, 0x42);
4619 + * Watchdog device is opened, and watchdog starts running.
4621 +static int at32_wdt_open(struct inode *inode, struct file *file)
4623 + if (test_and_set_bit(1, &wdt->users))
4627 + return nonseekable_open(inode, file);
4631 + * Close the watchdog device. If CONFIG_WATCHDOG_NOWAYOUT is _not_ defined then
4632 + * the watchdog is also disabled.
4634 +static int at32_wdt_close(struct inode *inode, struct file *file)
4636 +#ifndef CONFIG_WATCHDOG_NOWAYOUT
4639 + clear_bit(1, &wdt->users);
4644 + * Change the watchdog time interval.
4646 +static int at32_wdt_settimeout(int time)
4649 + * All counting occurs at 1 / SLOW_CLOCK (32 kHz) and max prescaler is
4650 + * 2 ^ 16 allowing up to 2 seconds timeout.
4652 + if ((time < TIMEOUT_MIN) || (time > TIMEOUT_MAX))
4656 + * Set new watchdog time. It will be used when at32_wdt_start() is
4659 + wdt->timeout = time;
4663 +static struct watchdog_info at32_wdt_info = {
4664 + .identity = "at32ap700x watchdog",
4665 + .options = WDIOF_SETTIMEOUT | WDIOF_KEEPALIVEPING,
4669 + * Handle commands from user-space.
4671 +static int at32_wdt_ioctl(struct inode *inode, struct file *file,
4672 + unsigned int cmd, unsigned long arg)
4674 + int ret = -ENOTTY;
4676 + void __user *argp = (void __user *)arg;
4677 + int __user *p = argp;
4680 + case WDIOC_KEEPALIVE:
4684 + case WDIOC_GETSUPPORT:
4685 + ret = copy_to_user(argp, &at32_wdt_info,
4686 + sizeof(at32_wdt_info)) ? -EFAULT : 0;
4688 + case WDIOC_SETTIMEOUT:
4689 + ret = get_user(time, p);
4692 + ret = at32_wdt_settimeout(time);
4695 + /* Enable new time value */
4697 + /* fall through */
4698 + case WDIOC_GETTIMEOUT:
4699 + ret = put_user(wdt->timeout, p);
4701 + case WDIOC_GETSTATUS: /* fall through */
4702 + case WDIOC_GETBOOTSTATUS:
4703 + ret = put_user(0, p);
4705 + case WDIOC_SETOPTIONS:
4706 + ret = get_user(time, p);
4709 + if (time & WDIOS_DISABLECARD)
4711 + if (time & WDIOS_ENABLECARD)
4720 +static ssize_t at32_wdt_write(struct file *file, const char *data, size_t len,
4727 +static const struct file_operations at32_wdt_fops = {
4728 + .owner = THIS_MODULE,
4729 + .llseek = no_llseek,
4730 + .ioctl = at32_wdt_ioctl,
4731 + .open = at32_wdt_open,
4732 + .release = at32_wdt_close,
4733 + .write = at32_wdt_write,
4736 +static int __init at32_wdt_probe(struct platform_device *pdev)
4738 + struct resource *regs;
4742 + dev_dbg(&pdev->dev, "only 1 wdt instance supported.\n");
4746 + regs = platform_get_resource(pdev, IORESOURCE_MEM, 0);
4748 + dev_dbg(&pdev->dev, "missing mmio resource\n");
4752 + wdt = kzalloc(sizeof(struct wdt_at32ap700x), GFP_KERNEL);
4754 + dev_dbg(&pdev->dev, "no memory for wdt structure\n");
4758 + wdt->regs = ioremap(regs->start, regs->end - regs->start + 1);
4761 + dev_dbg(&pdev->dev, "could not map I/O memory\n");
4765 + wdt->miscdev.minor = WATCHDOG_MINOR;
4766 + wdt->miscdev.name = "watchdog";
4767 + wdt->miscdev.fops = &at32_wdt_fops;
4769 + if (at32_wdt_settimeout(TIMEOUT_DEFAULT)) {
4770 + at32_wdt_settimeout(TIMEOUT_MAX);
4771 + dev_dbg(&pdev->dev,
4772 + "default timeout invalid, set to %d sec.\n",
4776 + ret = misc_register(&wdt->miscdev);
4778 + dev_dbg(&pdev->dev, "failed to register wdt miscdev\n");
4782 + platform_set_drvdata(pdev, wdt);
4783 + wdt->miscdev.parent = &pdev->dev;
4784 + dev_info(&pdev->dev, "AT32AP700X WDT at 0x%p\n", wdt->regs);
4789 + iounmap(wdt->regs);
4796 +static int __exit at32_wdt_remove(struct platform_device *pdev)
4798 + if (wdt && platform_get_drvdata(pdev) == wdt) {
4799 + misc_deregister(&wdt->miscdev);
4800 + iounmap(wdt->regs);
4803 + platform_set_drvdata(pdev, NULL);
4809 +static void at32_wdt_shutdown(struct platform_device *pdev)
4815 +static int at32_wdt_suspend(struct platform_device *pdev, pm_message_t message)
4821 +static int at32_wdt_resume(struct platform_device *pdev)
4828 +#define at32_wdt_suspend NULL
4829 +#define at32_wdt_resume NULL
4832 +static struct platform_driver at32_wdt_driver = {
4833 + .remove = __exit_p(at32_wdt_remove),
4834 + .suspend = at32_wdt_suspend,
4835 + .resume = at32_wdt_resume,
4837 + .name = "at32_wdt",
4838 + .owner = THIS_MODULE,
4840 + .shutdown = at32_wdt_shutdown,
4843 +static int __init at32_wdt_init(void)
4845 + return platform_driver_probe(&at32_wdt_driver, at32_wdt_probe);
4847 +module_init(at32_wdt_init);
4849 +static void __exit at32_wdt_exit(void)
4851 + platform_driver_unregister(&at32_wdt_driver);
4853 +module_exit(at32_wdt_exit);
4855 +MODULE_AUTHOR("Hans-Christian Egtvedt <hcegtvedt@atmel.com>");
4856 +MODULE_DESCRIPTION("Watchdog driver for Atmel AT32AP700X");
4857 +MODULE_LICENSE("GPL");
4858 +MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR);
4859 diff -x .git -Nur linux-2.6.22.1/drivers/char/watchdog/Kconfig linux-avr32.git/drivers/char/watchdog/Kconfig
4860 --- linux-2.6.22.1/drivers/char/watchdog/Kconfig 2007-07-10 20:56:30.000000000 +0200
4861 +++ linux-avr32.git/drivers/char/watchdog/Kconfig 2007-07-12 13:59:59.000000000 +0200
4862 @@ -187,6 +187,26 @@
4864 Say N if you are unsure.
4866 +# AVR32 Architecture
4868 +config AT32AP700X_WDT
4869 + tristate "AT32AP700x watchdog"
4870 + depends on WATCHDOG && CPU_AT32AP7000
4872 + Watchdog timer embedded into AT32AP700x devices. This will reboot
4873 + your system when the timeout is reached.
4875 +config AT32AP700X_WDT_TIMEOUT
4876 + int "Timeout value for AT32AP700x watchdog"
4877 + depends on AT32AP700X_WDT
4881 + Sets the timeout value for the watchdog in AT32AP700x devices.
4882 + Limited by hardware to be 1 or 2 seconds.
4884 + Set to 2 seconds by default.
4886 # X86 (i386 + ia64 + x86_64) Architecture
4889 diff -x .git -Nur linux-2.6.22.1/drivers/char/watchdog/Makefile linux-avr32.git/drivers/char/watchdog/Makefile
4890 --- linux-2.6.22.1/drivers/char/watchdog/Makefile 2007-07-10 20:56:30.000000000 +0200
4891 +++ linux-avr32.git/drivers/char/watchdog/Makefile 2007-07-12 13:59:59.000000000 +0200
4893 obj-$(CONFIG_EP93XX_WATCHDOG) += ep93xx_wdt.o
4894 obj-$(CONFIG_PNX4008_WATCHDOG) += pnx4008_wdt.o
4896 +# AVR32 Architecture
4897 +obj-$(CONFIG_AT32AP700X_WDT) += at32ap700x_wdt.o
4899 # X86 (i386 + ia64 + x86_64) Architecture
4900 obj-$(CONFIG_ACQUIRE_WDT) += acquirewdt.o
4901 obj-$(CONFIG_ADVANTECH_WDT) += advantechwdt.o
4902 diff -x .git -Nur linux-2.6.22.1/drivers/i2c/busses/atmeltwi.h linux-avr32.git/drivers/i2c/busses/atmeltwi.h
4903 --- linux-2.6.22.1/drivers/i2c/busses/atmeltwi.h 1970-01-01 01:00:00.000000000 +0100
4904 +++ linux-avr32.git/drivers/i2c/busses/atmeltwi.h 2007-06-06 11:33:51.000000000 +0200
4907 + * Register definitions for the Atmel Two-Wire Interface
4910 +#ifndef __ASM_AVR32_TWI_H__
4911 +#define __ASM_AVR32_TWI_H__
4913 +/* TWI register offsets */
4914 +#define TWI_CR 0x0000
4915 +#define TWI_MMR 0x0004
4916 +#define TWI_SMR 0x0008
4917 +#define TWI_IADR 0x000c
4918 +#define TWI_CWGR 0x0010
4919 +#define TWI_SR 0x0020
4920 +#define TWI_IER 0x0024
4921 +#define TWI_IDR 0x0028
4922 +#define TWI_IMR 0x002c
4923 +#define TWI_RHR 0x0030
4924 +#define TWI_THR 0x0034
4926 +/* Bitfields in CR */
4927 +#define TWI_START_OFFSET 0
4928 +#define TWI_START_SIZE 1
4929 +#define TWI_STOP_OFFSET 1
4930 +#define TWI_STOP_SIZE 1
4931 +#define TWI_MSEN_OFFSET 2
4932 +#define TWI_MSEN_SIZE 1
4933 +#define TWI_MSDIS_OFFSET 3
4934 +#define TWI_MSDIS_SIZE 1
4935 +#define TWI_SVEN_OFFSET 4
4936 +#define TWI_SVEN_SIZE 1
4937 +#define TWI_SVDIS_OFFSET 5
4938 +#define TWI_SVDIS_SIZE 1
4939 +#define TWI_SWRST_OFFSET 7
4940 +#define TWI_SWRST_SIZE 1
4942 +/* Bitfields in MMR */
4943 +#define TWI_IADRSZ_OFFSET 8
4944 +#define TWI_IADRSZ_SIZE 2
4945 +#define TWI_MREAD_OFFSET 12
4946 +#define TWI_MREAD_SIZE 1
4947 +#define TWI_DADR_OFFSET 16
4948 +#define TWI_DADR_SIZE 7
4950 +/* Bitfields in SMR */
4951 +#define TWI_SADR_OFFSET 16
4952 +#define TWI_SADR_SIZE 7
4954 +/* Bitfields in IADR */
4955 +#define TWI_IADR_OFFSET 0
4956 +#define TWI_IADR_SIZE 24
4958 +/* Bitfields in CWGR */
4959 +#define TWI_CLDIV_OFFSET 0
4960 +#define TWI_CLDIV_SIZE 8
4961 +#define TWI_CHDIV_OFFSET 8
4962 +#define TWI_CHDIV_SIZE 8
4963 +#define TWI_CKDIV_OFFSET 16
4964 +#define TWI_CKDIV_SIZE 3
4966 +/* Bitfields in SR */
4967 +#define TWI_TXCOMP_OFFSET 0
4968 +#define TWI_TXCOMP_SIZE 1
4969 +#define TWI_RXRDY_OFFSET 1
4970 +#define TWI_RXRDY_SIZE 1
4971 +#define TWI_TXRDY_OFFSET 2
4972 +#define TWI_TXRDY_SIZE 1
4973 +#define TWI_SVDIR_OFFSET 3
4974 +#define TWI_SVDIR_SIZE 1
4975 +#define TWI_SVACC_OFFSET 4
4976 +#define TWI_SVACC_SIZE 1
4977 +#define TWI_GCACC_OFFSET 5
4978 +#define TWI_GCACC_SIZE 1
4979 +#define TWI_OVRE_OFFSET 6
4980 +#define TWI_OVRE_SIZE 1
4981 +#define TWI_UNRE_OFFSET 7
4982 +#define TWI_UNRE_SIZE 1
4983 +#define TWI_NACK_OFFSET 8
4984 +#define TWI_NACK_SIZE 1
4985 +#define TWI_ARBLST_OFFSET 9
4986 +#define TWI_ARBLST_SIZE 1
4988 +/* Bitfields in RHR */
4989 +#define TWI_RXDATA_OFFSET 0
4990 +#define TWI_RXDATA_SIZE 8
4992 +/* Bitfields in THR */
4993 +#define TWI_TXDATA_OFFSET 0
4994 +#define TWI_TXDATA_SIZE 8
4996 +/* Constants for IADRSZ */
4997 +#define TWI_IADRSZ_NO_ADDR 0
4998 +#define TWI_IADRSZ_ONE_BYTE 1
4999 +#define TWI_IADRSZ_TWO_BYTES 2
5000 +#define TWI_IADRSZ_THREE_BYTES 3
5002 +/* Bit manipulation macros */
5003 +#define TWI_BIT(name) \
5004 + (1 << TWI_##name##_OFFSET)
5005 +#define TWI_BF(name,value) \
5006 + (((value) & ((1 << TWI_##name##_SIZE) - 1)) \
5007 + << TWI_##name##_OFFSET)
5008 +#define TWI_BFEXT(name,value) \
5009 + (((value) >> TWI_##name##_OFFSET) \
5010 + & ((1 << TWI_##name##_SIZE) - 1))
5011 +#define TWI_BFINS(name,value,old) \
5012 + (((old) & ~(((1 << TWI_##name##_SIZE) - 1) \
5013 + << TWI_##name##_OFFSET)) \
5014 + | TWI_BF(name,value))
5016 +/* Register access macros */
5017 +#define twi_readl(port,reg) \
5018 + __raw_readl((port)->regs + TWI_##reg)
5019 +#define twi_writel(port,reg,value) \
5020 + __raw_writel((value), (port)->regs + TWI_##reg)
5022 +#endif /* __ASM_AVR32_TWI_H__ */
5023 diff -x .git -Nur linux-2.6.22.1/drivers/i2c/busses/i2c-atmeltwi.c linux-avr32.git/drivers/i2c/busses/i2c-atmeltwi.c
5024 --- linux-2.6.22.1/drivers/i2c/busses/i2c-atmeltwi.c 1970-01-01 01:00:00.000000000 +0100
5025 +++ linux-avr32.git/drivers/i2c/busses/i2c-atmeltwi.c 2007-07-13 11:24:16.000000000 +0200
5028 + * i2c Support for Atmel's Two-Wire Interface (TWI)
5030 + * Based on the work of Copyright (C) 2004 Rick Bronson
5031 + * Converted to 2.6 by Andrew Victor <andrew at sanpeople.com>
5032 + * Ported to AVR32 and heavily modified by Espen Krangnes
5033 + * <ekrangnes at atmel.com>
5035 + * Copyright (C) 2006 Atmel Corporation
5037 + * Borrowed heavily from the original work by:
5038 + * Copyright (C) 2000 Philip Edelbrock <phil at stimpy.netroedge.com>
5040 + * Partialy rewriten by Karel Hojdar <cmkaho at seznam.cz>
5041 + * bugs removed, interrupt routine markedly rewritten
5043 + * This program is free software; you can redistribute it and/or modify
5044 + * it under the terms of the GNU General Public License as published by
5045 + * the Free Software Foundation; either version 2 of the License, or
5046 + * (at your option) any later version.
5050 +#include <linux/err.h>
5051 +#include <linux/module.h>
5052 +#include <linux/kernel.h>
5053 +#include <linux/slab.h>
5054 +#include <linux/types.h>
5055 +#include <linux/delay.h>
5056 +#include <linux/i2c.h>
5057 +#include <linux/init.h>
5058 +#include <linux/clk.h>
5059 +#include <linux/interrupt.h>
5060 +#include <linux/irq.h>
5061 +#include <linux/platform_device.h>
5062 +#include <linux/completion.h>
5063 +#include <asm/io.h>
5064 +#include <linux/time.h>
5065 +#include "atmeltwi.h"
5067 +static unsigned int baudrate = CONFIG_I2C_ATMELTWI_BAUDRATE;
5068 +module_param(baudrate, uint, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP);
5069 +MODULE_PARM_DESC(baudrate, "The TWI baudrate");
5073 + void __iomem *regs;
5074 + struct i2c_adapter adapter;
5077 + struct completion comp;
5086 +#define to_atmel_twi(adap) container_of(adap, struct atmel_twi, adapter)
5089 + * Initialize the TWI hardware registers.
5091 +static int __devinit twi_hwinit(struct atmel_twi *twi)
5093 + unsigned long cdiv, ckdiv=0;
5095 + twi_writel(twi, IDR, ~0UL);
5096 + twi_writel(twi, CR, TWI_BIT(SWRST)); /*Reset peripheral*/
5097 + twi_readl(twi, SR);
5099 + cdiv = (clk_get_rate(twi->pclk) / (2 * baudrate)) - 4;
5101 + while (cdiv > 255) {
5109 + twi_writel(twi, CWGR, (TWI_BF(CKDIV, ckdiv)
5110 + | TWI_BF(CHDIV, cdiv)
5111 + | TWI_BF(CLDIV, cdiv)));
5116 + * Waits for the i2c status register to set the specified bitmask
5117 + * Returns 0 if timed out (~100ms).
5119 +static short twi_complete(struct atmel_twi *twi, u32 mask)
5121 + int timeout = msecs_to_jiffies(100);
5123 + twi->intmask = mask;
5124 + init_completion(&twi->comp);
5126 + twi_writel(twi, IER, mask);
5128 + if (!wait_for_completion_timeout(&twi->comp, timeout)) {
5129 + /* RESET TWI interface */
5130 + twi_writel(twi, CR, TWI_BIT(SWRST));
5132 + /* Reinitialize TWI */
5135 + return -ETIMEDOUT;
5141 + * Generic i2c master transfer entrypoint.
5143 +static int twi_xfer(struct i2c_adapter *adap, struct i2c_msg msgs[], int num)
5145 + struct atmel_twi *twi = to_atmel_twi(adap);
5146 + struct i2c_msg *pmsg;
5149 + /* get first message */
5152 + dev_dbg(&adap->dev, "twi_xfer: processing %d messages:\n", num);
5155 + for (i = 0; i < num; i++, pmsg++) {
5156 + twi->len = pmsg->len;
5157 + twi->buf = pmsg->buf;
5158 + twi->acks_left = pmsg->len;
5159 + twi_writel(twi, MMR, TWI_BF(DADR, pmsg->addr) |
5160 + (pmsg->flags & I2C_M_RD ? TWI_BIT(MREAD) : 0));
5161 + twi_writel(twi, IADR, TWI_BF(IADR, pmsg->addr));
5163 + dev_dbg(&adap->dev,"#%d: internal addr %d %s byte%s %s 0x%02x\n",
5164 + i,pmsg->len, pmsg->flags & I2C_M_RD ? "reading" : "writing",
5165 + pmsg->len > 1 ? "s" : "",
5166 + pmsg->flags & I2C_M_RD ? "from" : "to", pmsg->addr);
5169 + twi_writel(twi, CR, TWI_BIT(MSEN));
5171 + if (pmsg->flags & I2C_M_RD) {
5172 + if (twi->len == 1)
5173 + twi_writel(twi, CR,
5174 + TWI_BIT(START) | TWI_BIT(STOP));
5176 + twi_writel(twi, CR, TWI_BIT(START));
5178 + if (twi_complete(twi, TWI_BIT(RXRDY)) == -ETIMEDOUT) {
5179 + dev_dbg(&adap->dev, "RXRDY timeout. Stopped with %d bytes left\n",
5181 + return -ETIMEDOUT;
5184 + twi_writel(twi, THR, twi->buf[0]);
5185 + if (twi_complete(twi, TWI_BIT(TXRDY)) == -ETIMEDOUT) {
5186 + dev_dbg(&adap->dev, "TXRDY timeout. Stopped with %d bytes left\n",
5188 + return -ETIMEDOUT;
5195 + /* Disable TWI interface */
5196 + twi_writel(twi, CR, TWI_BIT(MSDIS));
5198 + } /* end cur msg */
5204 +static irqreturn_t twi_interrupt(int irq, void *dev_id)
5206 + struct atmel_twi *twi = dev_id;
5207 + int status = twi_readl(twi, SR);
5209 + /* Save state for later debug prints */
5210 + int old_mask = twi->intmask;
5211 + int old_status = status;
5213 + if (twi->intmask & status) {
5214 + if (status & TWI_BIT(NACK))
5217 + status &= twi->intmask;
5219 + if (status & TWI_BIT(TXCOMP))
5222 + else if (status & TWI_BIT(RXRDY)) {
5223 + if ( twi->acks_left > 0 ) {
5224 + twi->buf[twi->len - twi->acks_left] =
5225 + twi_readl(twi, RHR);
5228 + if ( twi->acks_left == 1 )
5229 + twi_writel(twi, CR, TWI_BIT(STOP));
5231 + if (twi->acks_left == 0 ) {
5232 + twi->intmask = TWI_BIT(TXCOMP);
5233 + twi_writel(twi, IER, TWI_BIT(TXCOMP));
5235 + } else if (status & TWI_BIT(TXRDY)) {
5237 + if ( twi->acks_left == 0 ) {
5238 + twi->intmask = TWI_BIT(TXCOMP);
5239 + twi_writel(twi, IER, TWI_BIT(TXCOMP));
5240 + } else if (twi->acks_left > 0)
5241 + twi_writel(twi, THR, twi->buf[twi->len - twi->acks_left]);
5245 + dev_dbg(&twi->adapter.dev,
5246 + "TWI ISR, SR 0x%08X, intmask 0x%08X, acks_left %i.\n",
5247 + old_status, old_mask, twi->acks_left);
5249 + return IRQ_HANDLED;
5252 + dev_dbg(&twi->adapter.dev, "NACK received!\n");
5256 + twi_writel(twi, IDR, ~0UL);
5257 + complete(&twi->comp);
5259 + dev_dbg(&twi->adapter.dev,
5260 + "TWI ISR, SR 0x%08X, intmask 0x%08X, \
5261 + acks_left %i - completed.\n",
5262 + old_status, old_mask, twi->acks_left);
5264 + return IRQ_HANDLED;
5269 + * Return list of supported functionality.
5271 +static u32 twi_func(struct i2c_adapter *adapter)
5273 + return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL;
5276 +/* For now, we only handle combined mode (smbus) */
5277 +static struct i2c_algorithm twi_algorithm = {
5278 + .master_xfer = twi_xfer,
5279 + .functionality = twi_func,
5283 + * Main initialization routine.
5285 +static int __devinit twi_probe(struct platform_device *pdev)
5287 + struct atmel_twi *twi;
5288 + struct resource *regs;
5290 + struct i2c_adapter *adapter;
5293 + regs = platform_get_resource(pdev, IORESOURCE_MEM, 0);
5297 + pclk = clk_get(&pdev->dev, "pclk");
5299 + return PTR_ERR(pclk);
5303 + twi = kzalloc(sizeof(struct atmel_twi), GFP_KERNEL);
5305 + dev_err(&pdev->dev, "can't allocate interface!\n");
5306 + goto err_alloc_twi;
5310 + twi->regs = ioremap(regs->start, regs->end - regs->start + 1);
5314 + irq = platform_get_irq(pdev,0);
5315 + rc = request_irq(irq, twi_interrupt, 0, "twi", twi);
5317 + dev_err(&pdev->dev, "can't bind irq!\n");
5322 + rc = twi_hwinit(twi);
5324 + dev_err(&pdev->dev, "Unable to set baudrate\n");
5328 + adapter = &twi->adapter;
5329 + sprintf(adapter->name, "TWI");
5330 + adapter->algo = &twi_algorithm;
5331 + adapter->class = I2C_CLASS_HWMON;
5332 + adapter->dev.parent = &pdev->dev;
5334 + platform_set_drvdata(pdev, twi);
5336 + rc = i2c_add_adapter(adapter);
5338 + dev_err(&pdev->dev, "Adapter %s registration failed\n",
5340 + goto err_register;
5343 + dev_info(&pdev->dev, "Atmel TWI i2c bus device (baudrate %dk) at 0x%08lx.\n",
5344 + baudrate/1000, (unsigned long)regs->start);
5350 + platform_set_drvdata(pdev, NULL);
5353 + free_irq(irq, twi);
5356 + iounmap(twi->regs);
5362 + clk_disable(pclk);
5368 +static int __devexit twi_remove(struct platform_device *pdev)
5370 + struct atmel_twi *twi = platform_get_drvdata(pdev);
5373 + platform_set_drvdata(pdev, NULL);
5374 + res = i2c_del_adapter(&twi->adapter);
5375 + twi_writel(twi, CR, TWI_BIT(MSDIS));
5376 + iounmap(twi->regs);
5377 + clk_disable(twi->pclk);
5378 + clk_put(twi->pclk);
5379 + free_irq(twi->irq, twi);
5385 +static struct platform_driver twi_driver = {
5386 + .probe = twi_probe,
5387 + .remove = __devexit_p(twi_remove),
5389 + .name = "atmel_twi",
5390 + .owner = THIS_MODULE,
5394 +static int __init atmel_twi_init(void)
5396 + return platform_driver_register(&twi_driver);
5399 +static void __exit atmel_twi_exit(void)
5401 + platform_driver_unregister(&twi_driver);
5404 +module_init(atmel_twi_init);
5405 +module_exit(atmel_twi_exit);
5407 +MODULE_AUTHOR("Espen Krangnes");
5408 +MODULE_DESCRIPTION("I2C driver for Atmel TWI");
5409 +MODULE_LICENSE("GPL");
5410 diff -x .git -Nur linux-2.6.22.1/drivers/i2c/busses/Kconfig linux-avr32.git/drivers/i2c/busses/Kconfig
5411 --- linux-2.6.22.1/drivers/i2c/busses/Kconfig 2007-07-10 20:56:30.000000000 +0200
5412 +++ linux-avr32.git/drivers/i2c/busses/Kconfig 2007-07-12 13:59:59.000000000 +0200
5415 menu "I2C Hardware Bus support"
5417 +config I2C_ATMELTWI
5418 + tristate "Atmel TWI/I2C"
5421 + Atmel on-chip TWI controller. Say Y if you have an AT32 or
5422 + AT91-based device and want to use its built-in TWI
5423 + functionality. Atmel's TWI is compatible with Philips' I2C
5424 + protocol. If in doubt, say NO
5426 +config I2C_ATMELTWI_BAUDRATE
5427 + prompt "Atmel TWI baudrate"
5428 + depends on I2C_ATMELTWI
5432 + Set the TWI/I2C baudrate. This will alter the default value. A
5433 + different baudrate can be set by using a module parameter as well. If
5434 + no parameter is provided when loading, this is the value that will be
5440 diff -x .git -Nur linux-2.6.22.1/drivers/i2c/busses/Makefile linux-avr32.git/drivers/i2c/busses/Makefile
5441 --- linux-2.6.22.1/drivers/i2c/busses/Makefile 2007-07-10 20:56:30.000000000 +0200
5442 +++ linux-avr32.git/drivers/i2c/busses/Makefile 2007-07-12 13:59:59.000000000 +0200
5444 obj-$(CONFIG_I2C_VOODOO3) += i2c-voodoo3.o
5445 obj-$(CONFIG_SCx200_ACB) += scx200_acb.o
5446 obj-$(CONFIG_SCx200_I2C) += scx200_i2c.o
5447 +obj-$(CONFIG_I2C_ATMELTWI) += i2c-atmeltwi.o
5449 ifeq ($(CONFIG_I2C_DEBUG_BUS),y)
5450 EXTRA_CFLAGS += -DDEBUG
5451 diff -x .git -Nur linux-2.6.22.1/drivers/input/mouse/gpio_mouse.c linux-avr32.git/drivers/input/mouse/gpio_mouse.c
5452 --- linux-2.6.22.1/drivers/input/mouse/gpio_mouse.c 1970-01-01 01:00:00.000000000 +0100
5453 +++ linux-avr32.git/drivers/input/mouse/gpio_mouse.c 2007-07-13 11:24:16.000000000 +0200
5456 + * Driver for simulating a mouse on GPIO lines.
5458 + * Copyright (C) 2007 Atmel Corporation
5460 + * This program is free software; you can redistribute it and/or modify
5461 + * it under the terms of the GNU General Public License version 2 as
5462 + * published by the Free Software Foundation.
5465 +#include <linux/init.h>
5466 +#include <linux/version.h>
5467 +#include <linux/module.h>
5468 +#include <linux/platform_device.h>
5469 +#include <linux/input-polldev.h>
5470 +#include <linux/gpio_mouse.h>
5472 +#include <asm/gpio.h>
5475 + * Timer function which is run every scan_ms ms when the device is opened.
5476 + * The dev input varaible is set to the the input_dev pointer.
5478 +static void gpio_mouse_scan(struct input_polled_dev *dev)
5480 + struct gpio_mouse_platform_data *gpio = dev->private;
5481 + struct input_dev *input = dev->input;
5484 + if (gpio->bleft >= 0)
5485 + input_report_key(input, BTN_LEFT,
5486 + gpio_get_value(gpio->bleft) ^ gpio->polarity);
5487 + if (gpio->bmiddle >= 0)
5488 + input_report_key(input, BTN_MIDDLE,
5489 + gpio_get_value(gpio->bmiddle) ^ gpio->polarity);
5490 + if (gpio->bright >= 0)
5491 + input_report_key(input, BTN_RIGHT,
5492 + gpio_get_value(gpio->bright) ^ gpio->polarity);
5494 + x = (gpio_get_value(gpio->right) ^ gpio->polarity)
5495 + - (gpio_get_value(gpio->left) ^ gpio->polarity);
5496 + y = (gpio_get_value(gpio->down) ^ gpio->polarity)
5497 + - (gpio_get_value(gpio->up) ^ gpio->polarity);
5499 + input_report_rel(input, REL_X, x);
5500 + input_report_rel(input, REL_Y, y);
5501 + input_sync(input);
5504 +static int __init gpio_mouse_probe(struct platform_device *pdev)
5506 + struct gpio_mouse_platform_data *pdata = pdev->dev.platform_data;
5507 + struct input_polled_dev *input_poll;
5508 + struct input_dev *input;
5513 + dev_err(&pdev->dev, "no platform data\n");
5518 + if (pdata->scan_ms < 0) {
5519 + dev_err(&pdev->dev, "invalid scan time\n");
5524 + for (i = 0; i < GPIO_MOUSE_PIN_MAX; i++) {
5525 + pin = pdata->pins[i];
5529 + if (i <= GPIO_MOUSE_PIN_RIGHT) {
5530 + /* Mouse direction is required. */
5531 + dev_err(&pdev->dev,
5532 + "missing GPIO for directions\n");
5534 + goto out_free_gpios;
5537 + if (i == GPIO_MOUSE_PIN_BLEFT)
5538 + dev_dbg(&pdev->dev, "no left button defined\n");
5541 + error = gpio_request(pin, "gpio_mouse");
5543 + dev_err(&pdev->dev, "fail %d pin (%d idx)\n",
5545 + goto out_free_gpios;
5548 + gpio_direction_input(pin);
5552 + input_poll = input_allocate_polled_device();
5553 + if (!input_poll) {
5554 + dev_err(&pdev->dev, "not enough memory for input device\n");
5556 + goto out_free_gpios;
5559 + platform_set_drvdata(pdev, input_poll);
5561 + /* set input-polldev handlers */
5562 + input_poll->private = pdata;
5563 + input_poll->poll = gpio_mouse_scan;
5564 + input_poll->poll_interval = pdata->scan_ms;
5566 + input = input_poll->input;
5567 + input->name = pdev->name;
5568 + input->id.bustype = BUS_HOST;
5569 + input->dev.parent = &pdev->dev;
5571 + input_set_capability(input, EV_REL, REL_X);
5572 + input_set_capability(input, EV_REL, REL_Y);
5573 + if (pdata->bleft >= 0)
5574 + input_set_capability(input, EV_KEY, BTN_LEFT);
5575 + if (pdata->bmiddle >= 0)
5576 + input_set_capability(input, EV_KEY, BTN_MIDDLE);
5577 + if (pdata->bright >= 0)
5578 + input_set_capability(input, EV_KEY, BTN_RIGHT);
5580 + error = input_register_polled_device(input_poll);
5582 + dev_err(&pdev->dev, "could not register input device\n");
5583 + goto out_free_polldev;
5586 + dev_dbg(&pdev->dev, "%d ms scan time, buttons: %s%s%s\n",
5588 + pdata->bleft < 0 ? "" : "left ",
5589 + pdata->bmiddle < 0 ? "" : "middle ",
5590 + pdata->bright < 0 ? "" : "right");
5595 + input_free_polled_device(input_poll);
5596 + platform_set_drvdata(pdev, NULL);
5599 + while (--i >= 0) {
5600 + pin = pdata->pins[i];
5608 +static int __devexit gpio_mouse_remove(struct platform_device *pdev)
5610 + struct input_polled_dev *input = platform_get_drvdata(pdev);
5611 + struct gpio_mouse_platform_data *pdata = input->private;
5614 + input_unregister_polled_device(input);
5615 + input_free_polled_device(input);
5617 + for (i = 0; i < GPIO_MOUSE_PIN_MAX; i++) {
5618 + pin = pdata->pins[i];
5623 + platform_set_drvdata(pdev, NULL);
5628 +struct platform_driver gpio_mouse_device_driver = {
5629 + .remove = __devexit_p(gpio_mouse_remove),
5631 + .name = "gpio_mouse",
5635 +static int __init gpio_mouse_init(void)
5637 + return platform_driver_probe(&gpio_mouse_device_driver,
5638 + gpio_mouse_probe);
5640 +module_init(gpio_mouse_init);
5642 +static void __exit gpio_mouse_exit(void)
5644 + platform_driver_unregister(&gpio_mouse_device_driver);
5646 +module_exit(gpio_mouse_exit);
5648 +MODULE_AUTHOR("Hans-Christian Egtvedt <hcegtvedt@atmel.com>");
5649 +MODULE_DESCRIPTION("GPIO mouse driver");
5650 +MODULE_LICENSE("GPL");
5651 diff -x .git -Nur linux-2.6.22.1/drivers/input/mouse/Kconfig linux-avr32.git/drivers/input/mouse/Kconfig
5652 --- linux-2.6.22.1/drivers/input/mouse/Kconfig 2007-07-10 20:56:30.000000000 +0200
5653 +++ linux-avr32.git/drivers/input/mouse/Kconfig 2007-07-13 11:24:16.000000000 +0200
5654 @@ -216,4 +216,20 @@
5656 Say Y here to support HIL pointers.
5659 + tristate "GPIO mouse"
5660 + depends on GENERIC_GPIO
5661 + select INPUT_POLLDEV
5663 + This driver simulates a mouse on GPIO lines of various CPUs (and some
5666 + Say Y here if your device has buttons or a simple joystick connected
5667 + directly to GPIO lines. Your board-specific setup logic must also
5668 + provide a platform device and platform data saying which GPIOs are
5671 + To compile this driver as a module, choose M here: the
5672 + module will be called gpio_mouse.
5675 diff -x .git -Nur linux-2.6.22.1/drivers/input/mouse/Makefile linux-avr32.git/drivers/input/mouse/Makefile
5676 --- linux-2.6.22.1/drivers/input/mouse/Makefile 2007-07-10 20:56:30.000000000 +0200
5677 +++ linux-avr32.git/drivers/input/mouse/Makefile 2007-07-13 11:24:16.000000000 +0200
5679 obj-$(CONFIG_MOUSE_SERIAL) += sermouse.o
5680 obj-$(CONFIG_MOUSE_HIL) += hil_ptr.o
5681 obj-$(CONFIG_MOUSE_VSXXXAA) += vsxxxaa.o
5682 +obj-$(CONFIG_MOUSE_GPIO) += gpio_mouse.o
5684 psmouse-objs := psmouse-base.o synaptics.o
5686 diff -x .git -Nur linux-2.6.22.1/drivers/leds/Kconfig linux-avr32.git/drivers/leds/Kconfig
5687 --- linux-2.6.22.1/drivers/leds/Kconfig 2007-07-10 20:56:30.000000000 +0200
5688 +++ linux-avr32.git/drivers/leds/Kconfig 2007-07-12 14:00:02.000000000 +0200
5691 This option enables support for the front LED on Cobalt Server
5694 + tristate "LED Support for GPIO connected LEDs"
5695 + depends on LEDS_CLASS && GENERIC_GPIO
5697 + This option enables support for the LEDs connected to GPIO
5698 + outputs. To be useful the particular board must have LEDs
5699 + and they must be connected to the GPIO lines.
5701 comment "LED Triggers"
5703 config LEDS_TRIGGERS
5704 diff -x .git -Nur linux-2.6.22.1/drivers/leds/leds-gpio.c linux-avr32.git/drivers/leds/leds-gpio.c
5705 --- linux-2.6.22.1/drivers/leds/leds-gpio.c 1970-01-01 01:00:00.000000000 +0100
5706 +++ linux-avr32.git/drivers/leds/leds-gpio.c 2007-07-12 14:00:02.000000000 +0200
5709 + * LEDs driver for GPIOs
5711 + * Copyright (C) 2007 8D Technologies inc.
5712 + * Raphael Assenat <raph@8d.com>
5714 + * This program is free software; you can redistribute it and/or modify
5715 + * it under the terms of the GNU General Public License version 2 as
5716 + * published by the Free Software Foundation.
5719 +#include <linux/kernel.h>
5720 +#include <linux/init.h>
5721 +#include <linux/platform_device.h>
5722 +#include <linux/leds.h>
5723 +#include <linux/workqueue.h>
5725 +#include <asm/gpio.h>
5727 +struct gpio_led_data {
5728 + struct led_classdev cdev;
5730 + struct work_struct work;
5736 +static void gpio_led_work(struct work_struct *work)
5738 + struct gpio_led_data *led_dat =
5739 + container_of(work, struct gpio_led_data, work);
5741 + gpio_set_value_cansleep(led_dat->gpio, led_dat->new_level);
5744 +static void gpio_led_set(struct led_classdev *led_cdev,
5745 + enum led_brightness value)
5747 + struct gpio_led_data *led_dat =
5748 + container_of(led_cdev, struct gpio_led_data, cdev);
5751 + if (value == LED_OFF)
5756 + if (led_dat->active_low)
5759 + /* setting GPIOs with I2C/etc requires a preemptible task context */
5760 + if (led_dat->can_sleep) {
5761 + if (preempt_count()) {
5762 + led_dat->new_level = level;
5763 + schedule_work(&led_dat->work);
5765 + gpio_set_value_cansleep(led_dat->gpio, level);
5767 + gpio_set_value(led_dat->gpio, level);
5770 +static int __init gpio_led_probe(struct platform_device *pdev)
5772 + struct gpio_led_platform_data *pdata = pdev->dev.platform_data;
5773 + struct gpio_led *cur_led;
5774 + struct gpio_led_data *leds_data, *led_dat;
5780 + leds_data = kzalloc(sizeof(struct gpio_led_data) * pdata->num_leds,
5785 + for (i = 0; i < pdata->num_leds; i++) {
5786 + cur_led = &pdata->leds[i];
5787 + led_dat = &leds_data[i];
5789 + led_dat->cdev.name = cur_led->name;
5790 + led_dat->cdev.default_trigger = cur_led->default_trigger;
5791 + led_dat->gpio = cur_led->gpio;
5792 + led_dat->can_sleep = gpio_cansleep(cur_led->gpio);
5793 + led_dat->active_low = cur_led->active_low;
5794 + led_dat->cdev.brightness_set = gpio_led_set;
5795 + led_dat->cdev.brightness = cur_led->active_low ? LED_FULL : LED_OFF;
5797 + ret = gpio_request(led_dat->gpio, led_dat->cdev.name);
5801 + gpio_direction_output(led_dat->gpio, led_dat->active_low);
5803 + ret = led_classdev_register(&pdev->dev, &led_dat->cdev);
5805 + gpio_free(led_dat->gpio);
5809 + INIT_WORK(&led_dat->work, gpio_led_work);
5812 + platform_set_drvdata(pdev, leds_data);
5818 + for (i = i - 1; i >= 0; i--) {
5819 + led_classdev_unregister(&leds_data[i].cdev);
5820 + gpio_free(leds_data[i].gpio);
5824 + flush_scheduled_work();
5830 +static int __exit gpio_led_remove(struct platform_device *pdev)
5833 + struct gpio_led_platform_data *pdata = pdev->dev.platform_data;
5834 + struct gpio_led_data *leds_data;
5836 + leds_data = platform_get_drvdata(pdev);
5838 + for (i = 0; i < pdata->num_leds; i++) {
5839 + led_classdev_unregister(&leds_data[i].cdev);
5840 + gpio_free(leds_data[i].gpio);
5849 +static int gpio_led_suspend(struct platform_device *pdev, pm_message_t state)
5851 + struct gpio_led_platform_data *pdata = pdev->dev.platform_data;
5852 + struct gpio_led_data *leds_data;
5855 + leds_data = platform_get_drvdata(pdev);
5857 + for (i = 0; i < pdata->num_leds; i++)
5858 + led_classdev_suspend(&leds_data[i].cdev);
5863 +static int gpio_led_resume(struct platform_device *pdev)
5865 + struct gpio_led_platform_data *pdata = pdev->dev.platform_data;
5866 + struct gpio_led_data *leds_data;
5869 + leds_data = platform_get_drvdata(pdev);
5871 + for (i = 0; i < pdata->num_leds; i++)
5872 + led_classdev_resume(&leds_data[i].cdev);
5877 +#define gpio_led_suspend NULL
5878 +#define gpio_led_resume NULL
5881 +static struct platform_driver gpio_led_driver = {
5882 + .remove = __exit_p(gpio_led_remove),
5883 + .suspend = gpio_led_suspend,
5884 + .resume = gpio_led_resume,
5886 + .name = "leds-gpio",
5887 + .owner = THIS_MODULE,
5891 +static int __init gpio_led_init(void)
5893 + return platform_driver_probe(&gpio_led_driver, gpio_led_probe);
5896 +static void __exit gpio_led_exit(void)
5898 + platform_driver_unregister(&gpio_led_driver);
5901 +module_init(gpio_led_init);
5902 +module_exit(gpio_led_exit);
5904 +MODULE_AUTHOR("Raphael Assenat <raph@8d.com>");
5905 +MODULE_DESCRIPTION("GPIO LED driver");
5906 +MODULE_LICENSE("GPL");
5907 diff -x .git -Nur linux-2.6.22.1/drivers/leds/Makefile linux-avr32.git/drivers/leds/Makefile
5908 --- linux-2.6.22.1/drivers/leds/Makefile 2007-07-10 20:56:30.000000000 +0200
5909 +++ linux-avr32.git/drivers/leds/Makefile 2007-07-12 14:00:02.000000000 +0200
5911 obj-$(CONFIG_LEDS_WRAP) += leds-wrap.o
5912 obj-$(CONFIG_LEDS_H1940) += leds-h1940.o
5913 obj-$(CONFIG_LEDS_COBALT) += leds-cobalt.o
5914 +obj-$(CONFIG_LEDS_GPIO) += leds-gpio.o
5917 obj-$(CONFIG_LEDS_TRIGGER_TIMER) += ledtrig-timer.o
5918 diff -x .git -Nur linux-2.6.22.1/drivers/mmc/host/atmel-mci.c linux-avr32.git/drivers/mmc/host/atmel-mci.c
5919 --- linux-2.6.22.1/drivers/mmc/host/atmel-mci.c 1970-01-01 01:00:00.000000000 +0100
5920 +++ linux-avr32.git/drivers/mmc/host/atmel-mci.c 2007-07-12 14:00:03.000000000 +0200
5923 + * Atmel MultiMedia Card Interface driver
5925 + * Copyright (C) 2004-2006 Atmel Corporation
5927 + * This program is free software; you can redistribute it and/or modify
5928 + * it under the terms of the GNU General Public License version 2 as
5929 + * published by the Free Software Foundation.
5931 +#include <linux/blkdev.h>
5932 +#include <linux/clk.h>
5933 +#include <linux/device.h>
5934 +#include <linux/dma-mapping.h>
5935 +#include <linux/init.h>
5936 +#include <linux/interrupt.h>
5937 +#include <linux/ioport.h>
5938 +#include <linux/module.h>
5939 +#include <linux/platform_device.h>
5941 +#include <linux/mmc/host.h>
5943 +#include <asm/dma-controller.h>
5944 +#include <asm/io.h>
5945 +#include <asm/arch/board.h>
5946 +#include <asm/arch/gpio.h>
5948 +#include "atmel-mci.h"
5950 +#define DRIVER_NAME "atmel_mci"
5952 +#define MCI_CMD_ERROR_FLAGS (MCI_BIT(RINDE) | MCI_BIT(RDIRE) | \
5953 + MCI_BIT(RCRCE) | MCI_BIT(RENDE) | \
5955 +#define MCI_DATA_ERROR_FLAGS (MCI_BIT(DCRCE) | MCI_BIT(DTOE) | \
5956 + MCI_BIT(OVRE) | MCI_BIT(UNRE))
5959 + EVENT_CMD_COMPLETE = 0,
5961 + EVENT_DATA_COMPLETE,
5964 + EVENT_STOP_COMPLETE,
5967 + EVENT_CARD_DETECT,
5970 +struct atmel_mci_dma {
5971 + struct dma_request_sg req;
5972 + unsigned short rx_periph_id;
5973 + unsigned short tx_periph_id;
5977 + struct mmc_host *mmc;
5978 + void __iomem *regs;
5979 + struct atmel_mci_dma dma;
5981 + struct mmc_request *mrq;
5982 + struct mmc_command *cmd;
5983 + struct mmc_data *data;
5988 + struct tasklet_struct tasklet;
5989 + unsigned long pending_events;
5990 + unsigned long completed_events;
5997 + unsigned long bus_hz;
5998 + unsigned long mapbase;
6000 + struct platform_device *pdev;
6002 +#ifdef CONFIG_DEBUG_FS
6003 + struct dentry *debugfs_root;
6004 + struct dentry *debugfs_regs;
6005 + struct dentry *debugfs_req;
6006 + struct dentry *debugfs_pending_events;
6007 + struct dentry *debugfs_completed_events;
6011 +/* Those printks take an awful lot of time... */
6013 +static unsigned int fmax = 15000000U;
6015 +static unsigned int fmax = 1000000U;
6017 +module_param(fmax, uint, 0444);
6018 +MODULE_PARM_DESC(fmax, "Max frequency in Hz of the MMC bus clock");
6020 +/* Test bit macros for completed events */
6021 +#define mci_cmd_is_complete(host) \
6022 + test_bit(EVENT_CMD_COMPLETE, &host->completed_events)
6023 +#define mci_cmd_error_is_complete(host) \
6024 + test_bit(EVENT_CMD_ERROR, &host->completed_events)
6025 +#define mci_data_is_complete(host) \
6026 + test_bit(EVENT_DATA_COMPLETE, &host->completed_events)
6027 +#define mci_data_error_is_complete(host) \
6028 + test_bit(EVENT_DATA_ERROR, &host->completed_events)
6029 +#define mci_stop_sent_is_complete(host) \
6030 + test_bit(EVENT_STOP_SENT, &host->completed_events)
6031 +#define mci_stop_is_complete(host) \
6032 + test_bit(EVENT_STOP_COMPLETE, &host->completed_events)
6033 +#define mci_stop_error_is_complete(host) \
6034 + test_bit(EVENT_STOP_ERROR, &host->completed_events)
6035 +#define mci_dma_error_is_complete(host) \
6036 + test_bit(EVENT_DMA_ERROR, &host->completed_events)
6037 +#define mci_card_detect_is_complete(host) \
6038 + test_bit(EVENT_CARD_DETECT, &host->completed_events)
6040 +/* Test and clear bit macros for pending events */
6041 +#define mci_clear_cmd_is_pending(host) \
6042 + test_and_clear_bit(EVENT_CMD_COMPLETE, &host->pending_events)
6043 +#define mci_clear_cmd_error_is_pending(host) \
6044 + test_and_clear_bit(EVENT_CMD_ERROR, &host->pending_events)
6045 +#define mci_clear_data_is_pending(host) \
6046 + test_and_clear_bit(EVENT_DATA_COMPLETE, &host->pending_events)
6047 +#define mci_clear_data_error_is_pending(host) \
6048 + test_and_clear_bit(EVENT_DATA_ERROR, &host->pending_events)
6049 +#define mci_clear_stop_sent_is_pending(host) \
6050 + test_and_clear_bit(EVENT_STOP_SENT, &host->pending_events)
6051 +#define mci_clear_stop_is_pending(host) \
6052 + test_and_clear_bit(EVENT_STOP_COMPLETE, &host->pending_events)
6053 +#define mci_clear_stop_error_is_pending(host) \
6054 + test_and_clear_bit(EVENT_STOP_ERROR, &host->pending_events)
6055 +#define mci_clear_dma_error_is_pending(host) \
6056 + test_and_clear_bit(EVENT_DMA_ERROR, &host->pending_events)
6057 +#define mci_clear_card_detect_is_pending(host) \
6058 + test_and_clear_bit(EVENT_CARD_DETECT, &host->pending_events)
6060 +/* Test and set bit macros for completed events */
6061 +#define mci_set_cmd_is_completed(host) \
6062 + test_and_set_bit(EVENT_CMD_COMPLETE, &host->completed_events)
6063 +#define mci_set_cmd_error_is_completed(host) \
6064 + test_and_set_bit(EVENT_CMD_ERROR, &host->completed_events)
6065 +#define mci_set_data_is_completed(host) \
6066 + test_and_set_bit(EVENT_DATA_COMPLETE, &host->completed_events)
6067 +#define mci_set_data_error_is_completed(host) \
6068 + test_and_set_bit(EVENT_DATA_ERROR, &host->completed_events)
6069 +#define mci_set_stop_sent_is_completed(host) \
6070 + test_and_set_bit(EVENT_STOP_SENT, &host->completed_events)
6071 +#define mci_set_stop_is_completed(host) \
6072 + test_and_set_bit(EVENT_STOP_COMPLETE, &host->completed_events)
6073 +#define mci_set_stop_error_is_completed(host) \
6074 + test_and_set_bit(EVENT_STOP_ERROR, &host->completed_events)
6075 +#define mci_set_dma_error_is_completed(host) \
6076 + test_and_set_bit(EVENT_DMA_ERROR, &host->completed_events)
6077 +#define mci_set_card_detect_is_completed(host) \
6078 + test_and_set_bit(EVENT_CARD_DETECT, &host->completed_events)
6080 +/* Set bit macros for completed events */
6081 +#define mci_set_cmd_complete(host) \
6082 + set_bit(EVENT_CMD_COMPLETE, &host->completed_events)
6083 +#define mci_set_cmd_error_complete(host) \
6084 + set_bit(EVENT_CMD_ERROR, &host->completed_events)
6085 +#define mci_set_data_complete(host) \
6086 + set_bit(EVENT_DATA_COMPLETE, &host->completed_events)
6087 +#define mci_set_data_error_complete(host) \
6088 + set_bit(EVENT_DATA_ERROR, &host->completed_events)
6089 +#define mci_set_stop_sent_complete(host) \
6090 + set_bit(EVENT_STOP_SENT, &host->completed_events)
6091 +#define mci_set_stop_complete(host) \
6092 + set_bit(EVENT_STOP_COMPLETE, &host->completed_events)
6093 +#define mci_set_stop_error_complete(host) \
6094 + set_bit(EVENT_STOP_ERROR, &host->completed_events)
6095 +#define mci_set_dma_error_complete(host) \
6096 + set_bit(EVENT_DMA_ERROR, &host->completed_events)
6097 +#define mci_set_card_detect_complete(host) \
6098 + set_bit(EVENT_CARD_DETECT, &host->completed_events)
6100 +/* Set bit macros for pending events */
6101 +#define mci_set_cmd_pending(host) \
6102 + set_bit(EVENT_CMD_COMPLETE, &host->pending_events)
6103 +#define mci_set_cmd_error_pending(host) \
6104 + set_bit(EVENT_CMD_ERROR, &host->pending_events)
6105 +#define mci_set_data_pending(host) \
6106 + set_bit(EVENT_DATA_COMPLETE, &host->pending_events)
6107 +#define mci_set_data_error_pending(host) \
6108 + set_bit(EVENT_DATA_ERROR, &host->pending_events)
6109 +#define mci_set_stop_sent_pending(host) \
6110 + set_bit(EVENT_STOP_SENT, &host->pending_events)
6111 +#define mci_set_stop_pending(host) \
6112 + set_bit(EVENT_STOP_COMPLETE, &host->pending_events)
6113 +#define mci_set_stop_error_pending(host) \
6114 + set_bit(EVENT_STOP_ERROR, &host->pending_events)
6115 +#define mci_set_dma_error_pending(host) \
6116 + set_bit(EVENT_DMA_ERROR, &host->pending_events)
6117 +#define mci_set_card_detect_pending(host) \
6118 + set_bit(EVENT_CARD_DETECT, &host->pending_events)
6120 +/* Clear bit macros for pending events */
6121 +#define mci_clear_cmd_pending(host) \
6122 + clear_bit(EVENT_CMD_COMPLETE, &host->pending_events)
6123 +#define mci_clear_cmd_error_pending(host) \
6124 + clear_bit(EVENT_CMD_ERROR, &host->pending_events)
6125 +#define mci_clear_data_pending(host) \
6126 + clear_bit(EVENT_DATA_COMPLETE, &host->pending_events)
6127 +#define mci_clear_data_error_pending(host) \
6128 + clear_bit(EVENT_DATA_ERROR, &host->pending_events)
6129 +#define mci_clear_stop_sent_pending(host) \
6130 + clear_bit(EVENT_STOP_SENT, &host->pending_events)
6131 +#define mci_clear_stop_pending(host) \
6132 + clear_bit(EVENT_STOP_COMPLETE, &host->pending_events)
6133 +#define mci_clear_stop_error_pending(host) \
6134 + clear_bit(EVENT_STOP_ERROR, &host->pending_events)
6135 +#define mci_clear_dma_error_pending(host) \
6136 + clear_bit(EVENT_DMA_ERROR, &host->pending_events)
6137 +#define mci_clear_card_detect_pending(host) \
6138 + clear_bit(EVENT_CARD_DETECT, &host->pending_events)
6141 +#ifdef CONFIG_DEBUG_FS
6142 +#include <linux/debugfs.h>
6144 +#define DBG_REQ_BUF_SIZE (4096 - sizeof(unsigned int))
6146 +struct req_dbg_data {
6147 + unsigned int nbytes;
6148 + char str[DBG_REQ_BUF_SIZE];
6151 +static int req_dbg_open(struct inode *inode, struct file *file)
6153 + struct atmel_mci *host;
6154 + struct mmc_request *mrq;
6155 + struct mmc_command *cmd, *stop;
6156 + struct mmc_data *data;
6157 + struct req_dbg_data *priv;
6159 + unsigned long n = 0;
6161 + priv = kzalloc(DBG_REQ_BUF_SIZE, GFP_KERNEL);
6166 + mutex_lock(&inode->i_mutex);
6167 + host = inode->i_private;
6169 + spin_lock_irq(&host->mmc->lock);
6175 + n = snprintf(str, DBG_REQ_BUF_SIZE,
6176 + "CMD%u(0x%x) %x %x %x %x %x (err %u)\n",
6177 + cmd->opcode, cmd->arg, cmd->flags,
6178 + cmd->resp[0], cmd->resp[1], cmd->resp[2],
6179 + cmd->resp[3], cmd->error);
6180 + if (n < DBG_REQ_BUF_SIZE && data)
6181 + n += snprintf(str + n, DBG_REQ_BUF_SIZE - n,
6182 + "DATA %u * %u (%u) %x (err %u)\n",
6183 + data->blocks, data->blksz,
6184 + data->bytes_xfered, data->flags,
6186 + if (n < DBG_REQ_BUF_SIZE && stop)
6187 + n += snprintf(str + n, DBG_REQ_BUF_SIZE - n,
6188 + "CMD%u(0x%x) %x %x %x %x %x (err %u)\n",
6189 + stop->opcode, stop->arg, stop->flags,
6190 + stop->resp[0], stop->resp[1],
6191 + stop->resp[2], stop->resp[3],
6194 + spin_unlock_irq(&host->mmc->lock);
6195 + mutex_unlock(&inode->i_mutex);
6197 + priv->nbytes = min(n, DBG_REQ_BUF_SIZE);
6198 + file->private_data = priv;
6203 +static ssize_t req_dbg_read(struct file *file, char __user *buf,
6204 + size_t nbytes, loff_t *ppos)
6206 + struct req_dbg_data *priv = file->private_data;
6208 + return simple_read_from_buffer(buf, nbytes, ppos,
6209 + priv->str, priv->nbytes);
6212 +static int req_dbg_release(struct inode *inode, struct file *file)
6214 + kfree(file->private_data);
6218 +static const struct file_operations req_dbg_fops = {
6219 + .owner = THIS_MODULE,
6220 + .open = req_dbg_open,
6221 + .llseek = no_llseek,
6222 + .read = req_dbg_read,
6223 + .release = req_dbg_release,
6226 +static int regs_dbg_open(struct inode *inode, struct file *file)
6228 + struct atmel_mci *host;
6231 + int ret = -ENOMEM;
6233 + mutex_lock(&inode->i_mutex);
6234 + host = inode->i_private;
6235 + data = kmalloc(inode->i_size, GFP_KERNEL);
6239 + spin_lock_irq(&host->mmc->lock);
6240 + for (i = 0; i < inode->i_size / 4; i++)
6241 + data[i] = __raw_readl(host->regs + i * 4);
6242 + spin_unlock_irq(&host->mmc->lock);
6244 + file->private_data = data;
6248 + mutex_unlock(&inode->i_mutex);
6253 +static ssize_t regs_dbg_read(struct file *file, char __user *buf,
6254 + size_t nbytes, loff_t *ppos)
6256 + struct inode *inode = file->f_dentry->d_inode;
6259 + mutex_lock(&inode->i_mutex);
6260 + ret = simple_read_from_buffer(buf, nbytes, ppos,
6261 + file->private_data,
6262 + file->f_dentry->d_inode->i_size);
6263 + mutex_unlock(&inode->i_mutex);
6268 +static int regs_dbg_release(struct inode *inode, struct file *file)
6270 + kfree(file->private_data);
6274 +static const struct file_operations regs_dbg_fops = {
6275 + .owner = THIS_MODULE,
6276 + .open = regs_dbg_open,
6277 + .llseek = generic_file_llseek,
6278 + .read = regs_dbg_read,
6279 + .release = regs_dbg_release,
6282 +static void atmci_init_debugfs(struct atmel_mci *host)
6284 + struct mmc_host *mmc;
6285 + struct dentry *root, *regs;
6286 + struct resource *res;
6289 + root = debugfs_create_dir(mmc_hostname(mmc), NULL);
6290 + if (IS_ERR(root) || !root)
6292 + host->debugfs_root = root;
6294 + regs = debugfs_create_file("regs", 0400, root, host, ®s_dbg_fops);
6298 + res = platform_get_resource(host->pdev, IORESOURCE_MEM, 0);
6299 + regs->d_inode->i_size = res->end - res->start + 1;
6300 + host->debugfs_regs = regs;
6302 + host->debugfs_req = debugfs_create_file("req", 0400, root,
6303 + host, &req_dbg_fops);
6304 + if (!host->debugfs_req)
6307 + host->debugfs_pending_events
6308 + = debugfs_create_u32("pending_events", 0400, root,
6309 + (u32 *)&host->pending_events);
6310 + if (!host->debugfs_pending_events)
6311 + goto err_pending_events;
6313 + host->debugfs_completed_events
6314 + = debugfs_create_u32("completed_events", 0400, root,
6315 + (u32 *)&host->completed_events);
6316 + if (!host->debugfs_completed_events)
6317 + goto err_completed_events;
6321 +err_completed_events:
6322 + debugfs_remove(host->debugfs_pending_events);
6323 +err_pending_events:
6324 + debugfs_remove(host->debugfs_req);
6326 + debugfs_remove(host->debugfs_regs);
6328 + debugfs_remove(host->debugfs_root);
6330 + host->debugfs_root = NULL;
6331 + dev_err(&host->pdev->dev,
6332 + "failed to initialize debugfs for %s\n",
6333 + mmc_hostname(mmc));
6336 +static void atmci_cleanup_debugfs(struct atmel_mci *host)
6338 + if (host->debugfs_root) {
6339 + debugfs_remove(host->debugfs_completed_events);
6340 + debugfs_remove(host->debugfs_pending_events);
6341 + debugfs_remove(host->debugfs_req);
6342 + debugfs_remove(host->debugfs_regs);
6343 + debugfs_remove(host->debugfs_root);
6344 + host->debugfs_root = NULL;
6348 +static inline void atmci_init_debugfs(struct atmel_mci *host)
6353 +static inline void atmci_cleanup_debugfs(struct atmel_mci *host)
6357 +#endif /* CONFIG_DEBUG_FS */
6359 +static inline unsigned int ns_to_clocks(struct atmel_mci *host,
6362 + return (ns * (host->bus_hz / 1000000) + 999) / 1000;
6365 +static void atmci_set_timeout(struct atmel_mci *host,
6366 + struct mmc_data *data)
6368 + static unsigned dtomul_to_shift[] = {
6369 + 0, 4, 7, 8, 10, 12, 16, 20
6372 + unsigned dtocyc, dtomul;
6374 + timeout = ns_to_clocks(host, data->timeout_ns) + data->timeout_clks;
6376 + for (dtomul = 0; dtomul < 8; dtomul++) {
6377 + unsigned shift = dtomul_to_shift[dtomul];
6378 + dtocyc = (timeout + (1 << shift) - 1) >> shift;
6383 + if (dtomul >= 8) {
6388 + pr_debug("%s: setting timeout to %u cycles\n",
6389 + mmc_hostname(host->mmc),
6390 + dtocyc << dtomul_to_shift[dtomul]);
6391 + mci_writel(host, DTOR, (MCI_BF(DTOMUL, dtomul)
6392 + | MCI_BF(DTOCYC, dtocyc)));
6396 + * Return mask with interrupt flags to be handled for this command.
6398 +static u32 atmci_prepare_command(struct mmc_host *mmc,
6399 + struct mmc_command *cmd,
6405 + cmd->error = MMC_ERR_NONE;
6408 + BUG_ON(MCI_BFEXT(CMDNB, cmdr) != 0);
6409 + cmdr = MCI_BFINS(CMDNB, cmd->opcode, cmdr);
6411 + if (cmd->flags & MMC_RSP_PRESENT) {
6412 + if (cmd->flags & MMC_RSP_136)
6413 + cmdr |= MCI_BF(RSPTYP, MCI_RSPTYP_136_BIT);
6415 + cmdr |= MCI_BF(RSPTYP, MCI_RSPTYP_48_BIT);
6419 + * This should really be MAXLAT_5 for CMD2 and ACMD41, but
6420 + * it's too difficult to determine whether this is an ACMD or
6421 + * not. Better make it 64.
6423 + cmdr |= MCI_BIT(MAXLAT);
6425 + if (mmc->ios.bus_mode == MMC_BUSMODE_OPENDRAIN)
6426 + cmdr |= MCI_BIT(OPDCMD);
6428 + iflags = MCI_BIT(CMDRDY) | MCI_CMD_ERROR_FLAGS;
6429 + if (!(cmd->flags & MMC_RSP_CRC))
6430 + iflags &= ~MCI_BIT(RCRCE);
6432 + pr_debug("%s: cmd: op %02x arg %08x flags %08x, cmdflags %08lx\n",
6433 + mmc_hostname(mmc), cmd->opcode, cmd->arg, cmd->flags,
6434 + (unsigned long)cmdr);
6436 + *cmd_flags = cmdr;
6440 +static void atmci_start_command(struct atmel_mci *host,
6441 + struct mmc_command *cmd,
6444 + WARN_ON(host->cmd);
6447 + mci_writel(host, ARGR, cmd->arg);
6448 + mci_writel(host, CMDR, cmd_flags);
6451 + dma_start_request(host->dma.req.req.dmac,
6452 + host->dma.req.req.channel);
6456 + * Returns a mask of flags to be set in the command register when the
6457 + * command to start the transfer is to be sent.
6459 +static u32 atmci_prepare_data(struct mmc_host *mmc, struct mmc_data *data)
6461 + struct atmel_mci *host = mmc_priv(mmc);
6464 + WARN_ON(host->data);
6465 + host->data = data;
6467 + atmci_set_timeout(host, data);
6468 + mci_writel(host, BLKR, (MCI_BF(BCNT, data->blocks)
6469 + | MCI_BF(BLKLEN, data->blksz)));
6470 + host->dma.req.block_size = data->blksz;
6471 + host->dma.req.nr_blocks = data->blocks;
6473 + cmd_flags = MCI_BF(TRCMD, MCI_TRCMD_START_TRANS);
6474 + if (data->flags & MMC_DATA_STREAM)
6475 + cmd_flags |= MCI_BF(TRTYP, MCI_TRTYP_STREAM);
6476 + else if (data->blocks > 1)
6477 + cmd_flags |= MCI_BF(TRTYP, MCI_TRTYP_MULTI_BLOCK);
6479 + cmd_flags |= MCI_BF(TRTYP, MCI_TRTYP_BLOCK);
6481 + if (data->flags & MMC_DATA_READ) {
6482 + cmd_flags |= MCI_BIT(TRDIR);
6483 + host->dma.req.nr_sg
6484 + = dma_map_sg(&host->pdev->dev, data->sg,
6485 + data->sg_len, DMA_FROM_DEVICE);
6486 + host->dma.req.periph_id = host->dma.rx_periph_id;
6487 + host->dma.req.direction = DMA_DIR_PERIPH_TO_MEM;
6488 + host->dma.req.data_reg = host->mapbase + MCI_RDR;
6490 + host->dma.req.nr_sg
6491 + = dma_map_sg(&host->pdev->dev, data->sg,
6492 + data->sg_len, DMA_TO_DEVICE);
6493 + host->dma.req.periph_id = host->dma.tx_periph_id;
6494 + host->dma.req.direction = DMA_DIR_MEM_TO_PERIPH;
6495 + host->dma.req.data_reg = host->mapbase + MCI_TDR;
6497 + host->dma.req.sg = data->sg;
6499 + dma_prepare_request_sg(host->dma.req.req.dmac, &host->dma.req);
6504 +static void atmci_request(struct mmc_host *mmc, struct mmc_request *mrq)
6506 + struct atmel_mci *host = mmc_priv(mmc);
6507 + struct mmc_data *data = mrq->data;
6511 + iflags = mci_readl(host, IMR);
6513 + printk("WARNING: IMR=0x%08x\n", mci_readl(host, IMR));
6515 + WARN_ON(host->mrq != NULL);
6517 + host->pending_events = 0;
6518 + host->completed_events = 0;
6520 + iflags = atmci_prepare_command(mmc, mrq->cmd, &cmdflags);
6525 + host->stop_iflags = atmci_prepare_command(mmc, mrq->stop,
6526 + &host->stop_cmdr);
6527 + host->stop_cmdr |= MCI_BF(TRCMD, MCI_TRCMD_STOP_TRANS);
6528 + if (!(data->flags & MMC_DATA_WRITE))
6529 + host->stop_cmdr |= MCI_BIT(TRDIR);
6530 + if (data->flags & MMC_DATA_STREAM)
6531 + host->stop_cmdr |= MCI_BF(TRTYP, MCI_TRTYP_STREAM);
6533 + host->stop_cmdr |= MCI_BF(TRTYP, MCI_TRTYP_MULTI_BLOCK);
6536 + cmdflags |= atmci_prepare_data(mmc, data);
6537 + iflags |= MCI_DATA_ERROR_FLAGS;
6540 + atmci_start_command(host, mrq->cmd, cmdflags);
6541 + mci_writel(host, IER, iflags);
6544 +static void atmci_set_ios(struct mmc_host *mmc, struct mmc_ios *ios)
6546 + struct atmel_mci *host = mmc_priv(mmc);
6551 + clkdiv = host->bus_hz / (2 * ios->clock) - 1;
6554 + mci_writel(host, MR, (clkdiv
6555 + | MCI_BIT(WRPROOF)
6556 + | MCI_BIT(RDPROOF)));
6559 + switch (ios->bus_width) {
6560 + case MMC_BUS_WIDTH_1:
6561 + mci_writel(host, SDCR, 0);
6563 + case MMC_BUS_WIDTH_4:
6564 + mci_writel(host, SDCR, MCI_BIT(SDCBUS));
6568 + switch (ios->power_mode) {
6569 + case MMC_POWER_OFF:
6570 + mci_writel(host, CR, MCI_BIT(MCIDIS));
6572 + case MMC_POWER_UP:
6573 + mci_writel(host, CR, MCI_BIT(SWRST));
6575 + case MMC_POWER_ON:
6576 + mci_writel(host, CR, MCI_BIT(MCIEN));
6581 +static int atmci_get_ro(struct mmc_host *mmc)
6583 + int read_only = 0;
6584 + struct atmel_mci *host = mmc_priv(mmc);
6586 + if (host->wp_pin >= 0) {
6587 + read_only = gpio_get_value(host->wp_pin);
6588 + pr_debug("%s: card is %s\n", mmc_hostname(mmc),
6589 + read_only ? "read-only" : "read-write");
6591 + pr_debug("%s: no pin for checking read-only switch."
6592 + " Assuming write-enable.\n", mmc_hostname(mmc));
6598 +static struct mmc_host_ops atmci_ops = {
6599 + .request = atmci_request,
6600 + .set_ios = atmci_set_ios,
6601 + .get_ro = atmci_get_ro,
6604 +static void atmci_request_end(struct mmc_host *mmc, struct mmc_request *mrq)
6606 + struct atmel_mci *host = mmc_priv(mmc);
6608 + WARN_ON(host->cmd || host->data);
6611 + mmc_request_done(mmc, mrq);
6614 +static void send_stop_cmd(struct mmc_host *mmc, struct mmc_data *data,
6617 + struct atmel_mci *host = mmc_priv(mmc);
6619 + atmci_start_command(host, data->stop, host->stop_cmdr | flags);
6620 + mci_writel(host, IER, host->stop_iflags);
6623 +static void atmci_data_complete(struct atmel_mci *host, struct mmc_data *data)
6625 + host->data = NULL;
6626 + dma_unmap_sg(&host->pdev->dev, data->sg, host->dma.req.nr_sg,
6627 + ((data->flags & MMC_DATA_WRITE)
6628 + ? DMA_TO_DEVICE : DMA_FROM_DEVICE));
6631 + * Data might complete before command for very short transfers
6634 + if (mci_cmd_is_complete(host)
6635 + && (!data->stop || mci_stop_is_complete(host)))
6636 + atmci_request_end(host->mmc, data->mrq);
6639 +static void atmci_command_error(struct mmc_host *mmc,
6640 + struct mmc_command *cmd,
6643 + pr_debug("%s: command error: status=0x%08x\n",
6644 + mmc_hostname(mmc), status);
6646 + if (status & MCI_BIT(RTOE))
6647 + cmd->error = MMC_ERR_TIMEOUT;
6648 + else if (status & MCI_BIT(RCRCE))
6649 + cmd->error = MMC_ERR_BADCRC;
6651 + cmd->error = MMC_ERR_FAILED;
6654 +static void atmci_tasklet_func(unsigned long priv)
6656 + struct mmc_host *mmc = (struct mmc_host *)priv;
6657 + struct atmel_mci *host = mmc_priv(mmc);
6658 + struct mmc_request *mrq = host->mrq;
6659 + struct mmc_data *data = host->data;
6661 + pr_debug("atmci_tasklet: pending/completed/mask %lx/%lx/%x\n",
6662 + host->pending_events, host->completed_events,
6663 + mci_readl(host, IMR));
6665 + if (mci_clear_cmd_error_is_pending(host)) {
6666 + struct mmc_command *cmd;
6668 + mci_set_cmd_error_complete(host);
6669 + mci_clear_cmd_pending(host);
6670 + cmd = host->mrq->cmd;
6673 + dma_stop_request(host->dma.req.req.dmac,
6674 + host->dma.req.req.channel);
6675 + host->data = NULL;
6678 + atmci_command_error(mmc, cmd, host->error_status);
6679 + atmci_request_end(mmc, cmd->mrq);
6681 + if (mci_clear_stop_error_is_pending(host)) {
6682 + mci_set_stop_error_complete(host);
6683 + mci_clear_stop_pending(host);
6684 + atmci_command_error(mmc, host->mrq->stop,
6685 + host->error_status);
6687 + atmci_request_end(mmc, host->mrq);
6689 + if (mci_clear_cmd_is_pending(host)) {
6690 + mci_set_cmd_complete(host);
6691 + if (!mrq->data || mci_data_is_complete(host)
6692 + || mci_data_error_is_complete(host))
6693 + atmci_request_end(mmc, mrq);
6695 + if (mci_clear_stop_is_pending(host)) {
6696 + mci_set_stop_complete(host);
6697 + if (mci_data_is_complete(host)
6698 + || mci_data_error_is_complete(host))
6699 + atmci_request_end(mmc, mrq);
6701 + if (mci_clear_dma_error_is_pending(host)) {
6702 + mci_set_dma_error_complete(host);
6703 + mci_clear_data_pending(host);
6705 + /* DMA controller got bus error => invalid address */
6706 + data->error = MMC_ERR_INVALID;
6708 + printk(KERN_DEBUG "%s: dma error after %u bytes xfered\n",
6709 + mmc_hostname(mmc), host->data->bytes_xfered);
6712 + && !mci_set_stop_sent_is_completed(host))
6713 + /* TODO: Check if card is still present */
6714 + send_stop_cmd(host->mmc, data, 0);
6716 + atmci_data_complete(host, data);
6718 + if (mci_clear_data_error_is_pending(host)) {
6719 + u32 status = host->error_status;
6721 + mci_set_data_error_complete(host);
6722 + mci_clear_data_pending(host);
6724 + dma_stop_request(host->dma.req.req.dmac,
6725 + host->dma.req.req.channel);
6727 + printk(KERN_DEBUG "%s: data error: status=0x%08x\n",
6728 + mmc_hostname(host->mmc), status);
6730 + if (status & MCI_BIT(DCRCE)) {
6731 + printk(KERN_DEBUG "%s: Data CRC error\n",
6732 + mmc_hostname(host->mmc));
6733 + data->error = MMC_ERR_BADCRC;
6734 + } else if (status & MCI_BIT(DTOE)) {
6735 + printk(KERN_DEBUG "%s: Data Timeout error\n",
6736 + mmc_hostname(host->mmc));
6737 + data->error = MMC_ERR_TIMEOUT;
6739 + printk(KERN_DEBUG "%s: Data FIFO error\n",
6740 + mmc_hostname(host->mmc));
6741 + data->error = MMC_ERR_FIFO;
6743 + printk(KERN_DEBUG "%s: Bytes xfered: %u\n",
6744 + mmc_hostname(host->mmc), data->bytes_xfered);
6747 + && !mci_set_stop_sent_is_completed(host))
6748 + /* TODO: Check if card is still present */
6749 + send_stop_cmd(host->mmc, data, 0);
6751 + atmci_data_complete(host, data);
6753 + if (mci_clear_data_is_pending(host)) {
6754 + mci_set_data_complete(host);
6755 + data->bytes_xfered = data->blocks * data->blksz;
6756 + atmci_data_complete(host, data);
6758 + if (mci_clear_card_detect_is_pending(host)) {
6759 + /* Reset controller if card is gone */
6760 + if (!host->present) {
6761 + mci_writel(host, CR, MCI_BIT(SWRST));
6762 + mci_writel(host, IDR, ~0UL);
6763 + mci_writel(host, CR, MCI_BIT(MCIEN));
6766 + /* Clean up queue if present */
6768 + if (!mci_cmd_is_complete(host)
6769 + && !mci_cmd_error_is_complete(host)) {
6770 + mrq->cmd->error = MMC_ERR_TIMEOUT;
6772 + if (mrq->data && !mci_data_is_complete(host)
6773 + && !mci_data_error_is_complete(host)) {
6774 + dma_stop_request(host->dma.req.req.dmac,
6775 + host->dma.req.req.channel);
6776 + host->data->error = MMC_ERR_TIMEOUT;
6777 + atmci_data_complete(host, data);
6779 + if (mrq->stop && !mci_stop_is_complete(host)
6780 + && !mci_stop_error_is_complete(host)) {
6781 + mrq->stop->error = MMC_ERR_TIMEOUT;
6785 + atmci_request_end(mmc, mrq);
6787 + mmc_detect_change(host->mmc, msecs_to_jiffies(100));
6791 +static void atmci_cmd_interrupt(struct mmc_host *mmc, u32 status)
6793 + struct atmel_mci *host = mmc_priv(mmc);
6794 + struct mmc_command *cmd = host->cmd;
6797 + * Read the response now so that we're free to send a new
6798 + * command immediately.
6800 + cmd->resp[0] = mci_readl(host, RSPR);
6801 + cmd->resp[1] = mci_readl(host, RSPR);
6802 + cmd->resp[2] = mci_readl(host, RSPR);
6803 + cmd->resp[3] = mci_readl(host, RSPR);
6805 + mci_writel(host, IDR, MCI_BIT(CMDRDY) | MCI_CMD_ERROR_FLAGS);
6808 + if (mci_stop_sent_is_complete(host))
6809 + mci_set_stop_pending(host);
6811 + mci_set_cmd_pending(host);
6813 + tasklet_schedule(&host->tasklet);
6816 +static void atmci_xfer_complete(struct dma_request *_req)
6818 + struct dma_request_sg *req = to_dma_request_sg(_req);
6819 + struct atmel_mci_dma *dma;
6820 + struct atmel_mci *host;
6821 + struct mmc_data *data;
6823 + dma = container_of(req, struct atmel_mci_dma, req);
6824 + host = container_of(dma, struct atmel_mci, dma);
6825 + data = host->data;
6827 + if (data->stop && !mci_set_stop_sent_is_completed(host))
6828 + send_stop_cmd(host->mmc, data, 0);
6830 + if (data->flags & MMC_DATA_READ) {
6831 + mci_writel(host, IDR, MCI_DATA_ERROR_FLAGS);
6832 + mci_set_data_pending(host);
6833 + tasklet_schedule(&host->tasklet);
6836 + * For the WRITE case, wait for NOTBUSY. This function
6837 + * is called when everything has been written to the
6838 + * controller, not when the card is done programming.
6840 + mci_writel(host, IER, MCI_BIT(NOTBUSY));
6844 +static void atmci_dma_error(struct dma_request *_req)
6846 + struct dma_request_sg *req = to_dma_request_sg(_req);
6847 + struct atmel_mci_dma *dma;
6848 + struct atmel_mci *host;
6850 + dma = container_of(req, struct atmel_mci_dma, req);
6851 + host = container_of(dma, struct atmel_mci, dma);
6853 + mci_writel(host, IDR, (MCI_BIT(NOTBUSY)
6854 + | MCI_DATA_ERROR_FLAGS));
6856 + mci_set_dma_error_pending(host);
6857 + tasklet_schedule(&host->tasklet);
6860 +static irqreturn_t atmci_interrupt(int irq, void *dev_id)
6862 + struct mmc_host *mmc = dev_id;
6863 + struct atmel_mci *host = mmc_priv(mmc);
6864 + u32 status, mask, pending;
6866 + spin_lock(&mmc->lock);
6868 + status = mci_readl(host, SR);
6869 + mask = mci_readl(host, IMR);
6870 + pending = status & mask;
6873 + if (pending & MCI_CMD_ERROR_FLAGS) {
6874 + mci_writel(host, IDR, (MCI_BIT(CMDRDY)
6875 + | MCI_BIT(NOTBUSY)
6876 + | MCI_CMD_ERROR_FLAGS
6877 + | MCI_DATA_ERROR_FLAGS));
6878 + host->error_status = status;
6880 + if (mci_stop_sent_is_complete(host))
6881 + mci_set_stop_error_pending(host);
6883 + mci_set_cmd_error_pending(host);
6884 + tasklet_schedule(&host->tasklet);
6887 + if (pending & MCI_DATA_ERROR_FLAGS) {
6888 + mci_writel(host, IDR, (MCI_BIT(NOTBUSY)
6889 + | MCI_DATA_ERROR_FLAGS));
6890 + host->error_status = status;
6891 + mci_set_data_error_pending(host);
6892 + tasklet_schedule(&host->tasklet);
6895 + if (pending & MCI_BIT(CMDRDY))
6896 + atmci_cmd_interrupt(mmc, status);
6897 + if (pending & MCI_BIT(NOTBUSY)) {
6898 + mci_writel(host, IDR, (MCI_BIT(NOTBUSY)
6899 + | MCI_DATA_ERROR_FLAGS));
6900 + mci_set_data_pending(host);
6901 + tasklet_schedule(&host->tasklet);
6904 + status = mci_readl(host, SR);
6905 + mask = mci_readl(host, IMR);
6906 + pending = status & mask;
6907 + } while (pending);
6909 + spin_unlock(&mmc->lock);
6911 + return IRQ_HANDLED;
6914 +static irqreturn_t atmci_detect_change(int irq, void *dev_id)
6916 + struct mmc_host *mmc = dev_id;
6917 + struct atmel_mci *host = mmc_priv(mmc);
6919 + int present = !gpio_get_value(irq_to_gpio(irq));
6921 + if (present != host->present) {
6922 + pr_debug("%s: card %s\n", mmc_hostname(host->mmc),
6923 + present ? "inserted" : "removed");
6924 + host->present = present;
6925 + mci_set_card_detect_pending(host);
6926 + tasklet_schedule(&host->tasklet);
6928 + return IRQ_HANDLED;
6931 +static int __devinit atmci_probe(struct platform_device *pdev)
6933 + struct mci_platform_data *board;
6934 + struct atmel_mci *host;
6935 + struct mmc_host *mmc;
6936 + struct resource *regs;
6940 + regs = platform_get_resource(pdev, IORESOURCE_MEM, 0);
6943 + irq = platform_get_irq(pdev, 0);
6947 + board = pdev->dev.platform_data;
6949 + mmc = mmc_alloc_host(sizeof(struct atmel_mci), &pdev->dev);
6953 + host = mmc_priv(mmc);
6954 + host->pdev = pdev;
6957 + host->detect_pin = board->detect_pin;
6958 + host->wp_pin = board->wp_pin;
6960 + host->detect_pin = -1;
6961 + host->detect_pin = -1;
6964 + host->mck = clk_get(&pdev->dev, "mci_clk");
6965 + if (IS_ERR(host->mck)) {
6966 + ret = PTR_ERR(host->mck);
6967 + goto out_free_host;
6969 + clk_enable(host->mck);
6972 + host->regs = ioremap(regs->start, regs->end - regs->start + 1);
6974 + goto out_disable_clk;
6976 + host->bus_hz = clk_get_rate(host->mck);
6977 + host->mapbase = regs->start;
6979 + mmc->ops = &atmci_ops;
6980 + mmc->f_min = (host->bus_hz + 511) / 512;
6981 + mmc->f_max = min((unsigned int)(host->bus_hz / 2), fmax);
6982 + mmc->ocr_avail = 0x00100000;
6983 + mmc->caps |= MMC_CAP_4_BIT_DATA;
6985 + tasklet_init(&host->tasklet, atmci_tasklet_func, (unsigned long)mmc);
6987 + ret = request_irq(irq, atmci_interrupt, 0, "mmci", mmc);
6991 + /* Assume card is present if we don't have a detect pin */
6992 + host->present = 1;
6993 + if (host->detect_pin >= 0) {
6994 + if (gpio_request(host->detect_pin, "mmc_detect")) {
6995 + printk(KERN_WARNING "%s: no detect pin available\n",
6996 + mmc_hostname(host->mmc));
6997 + host->detect_pin = -1;
6999 + host->present = !gpio_get_value(host->detect_pin);
7002 + if (host->wp_pin >= 0) {
7003 + if (gpio_request(host->wp_pin, "mmc_wp")) {
7004 + printk(KERN_WARNING "%s: no WP pin available\n",
7005 + mmc_hostname(host->mmc));
7006 + host->wp_pin = -1;
7010 + /* TODO: Get this information from platform data */
7012 + host->dma.req.req.dmac = find_dma_controller(0);
7013 + if (!host->dma.req.req.dmac) {
7015 + "mmci: No DMA controller available, aborting\n");
7016 + goto out_free_irq;
7018 + ret = dma_alloc_channel(host->dma.req.req.dmac);
7021 + "mmci: Unable to allocate DMA channel, aborting\n");
7022 + goto out_free_irq;
7024 + host->dma.req.req.channel = ret;
7025 + host->dma.req.width = DMA_WIDTH_32BIT;
7026 + host->dma.req.req.xfer_complete = atmci_xfer_complete;
7027 + host->dma.req.req.block_complete = NULL; // atmci_block_complete;
7028 + host->dma.req.req.error = atmci_dma_error;
7029 + host->dma.rx_periph_id = 0;
7030 + host->dma.tx_periph_id = 1;
7032 + mci_writel(host, CR, MCI_BIT(SWRST));
7033 + mci_writel(host, IDR, ~0UL);
7034 + mci_writel(host, CR, MCI_BIT(MCIEN));
7036 + platform_set_drvdata(pdev, host);
7038 + mmc_add_host(mmc);
7040 + if (host->detect_pin >= 0) {
7041 + ret = request_irq(gpio_to_irq(host->detect_pin),
7042 + atmci_detect_change,
7043 + IRQF_TRIGGER_FALLING | IRQF_TRIGGER_RISING,
7044 + DRIVER_NAME, mmc);
7047 + "%s: could not request IRQ %d for detect pin\n",
7048 + mmc_hostname(mmc),
7049 + gpio_to_irq(host->detect_pin));
7050 + gpio_free(host->detect_pin);
7051 + host->detect_pin = -1;
7055 + printk(KERN_INFO "%s: Atmel MCI controller at 0x%08lx irq %d\n",
7056 + mmc_hostname(mmc), host->mapbase, irq);
7058 + atmci_init_debugfs(host);
7063 + if (host->detect_pin >= 0)
7064 + gpio_free(host->detect_pin);
7065 + if (host->wp_pin >= 0)
7066 + gpio_free(host->wp_pin);
7067 + free_irq(irq, mmc);
7069 + iounmap(host->regs);
7071 + clk_disable(host->mck);
7072 + clk_put(host->mck);
7074 + mmc_free_host(mmc);
7078 +static int __devexit atmci_remove(struct platform_device *pdev)
7080 + struct atmel_mci *host = platform_get_drvdata(pdev);
7082 + platform_set_drvdata(pdev, NULL);
7085 + atmci_cleanup_debugfs(host);
7087 + if (host->detect_pin >= 0) {
7088 + free_irq(gpio_to_irq(host->detect_pin), host->mmc);
7089 + cancel_delayed_work(&host->mmc->detect);
7090 + gpio_free(host->detect_pin);
7093 + mmc_remove_host(host->mmc);
7095 + mci_writel(host, IDR, ~0UL);
7096 + mci_writel(host, CR, MCI_BIT(MCIDIS));
7097 + mci_readl(host, SR);
7099 + dma_release_channel(host->dma.req.req.dmac,
7100 + host->dma.req.req.channel);
7102 + if (host->wp_pin >= 0)
7103 + gpio_free(host->wp_pin);
7105 + free_irq(platform_get_irq(pdev, 0), host->mmc);
7106 + iounmap(host->regs);
7108 + clk_disable(host->mck);
7109 + clk_put(host->mck);
7111 + mmc_free_host(host->mmc);
7116 +static struct platform_driver atmci_driver = {
7117 + .probe = atmci_probe,
7118 + .remove = __devexit_p(atmci_remove),
7120 + .name = DRIVER_NAME,
7124 +static int __init atmci_init(void)
7126 + return platform_driver_register(&atmci_driver);
7129 +static void __exit atmci_exit(void)
7131 + platform_driver_unregister(&atmci_driver);
7134 +module_init(atmci_init);
7135 +module_exit(atmci_exit);
7137 +MODULE_DESCRIPTION("Atmel Multimedia Card Interface driver");
7138 +MODULE_LICENSE("GPL");
7139 diff -x .git -Nur linux-2.6.22.1/drivers/mmc/host/atmel-mci.h linux-avr32.git/drivers/mmc/host/atmel-mci.h
7140 --- linux-2.6.22.1/drivers/mmc/host/atmel-mci.h 1970-01-01 01:00:00.000000000 +0100
7141 +++ linux-avr32.git/drivers/mmc/host/atmel-mci.h 2007-07-12 14:00:03.000000000 +0200
7144 + * Atmel MultiMedia Card Interface driver
7146 + * Copyright (C) 2004-2006 Atmel Corporation
7148 + * This program is free software; you can redistribute it and/or modify
7149 + * it under the terms of the GNU General Public License version 2 as
7150 + * published by the Free Software Foundation.
7152 +#ifndef __DRIVERS_MMC_ATMEL_MCI_H__
7153 +#define __DRIVERS_MMC_ATMEL_MCI_H__
7155 +/* MCI register offsets */
7156 +#define MCI_CR 0x0000
7157 +#define MCI_MR 0x0004
7158 +#define MCI_DTOR 0x0008
7159 +#define MCI_SDCR 0x000c
7160 +#define MCI_ARGR 0x0010
7161 +#define MCI_CMDR 0x0014
7162 +#define MCI_BLKR 0x0018
7163 +#define MCI_RSPR 0x0020
7164 +#define MCI_RSPR1 0x0024
7165 +#define MCI_RSPR2 0x0028
7166 +#define MCI_RSPR3 0x002c
7167 +#define MCI_RDR 0x0030
7168 +#define MCI_TDR 0x0034
7169 +#define MCI_SR 0x0040
7170 +#define MCI_IER 0x0044
7171 +#define MCI_IDR 0x0048
7172 +#define MCI_IMR 0x004c
7174 +/* Bitfields in CR */
7175 +#define MCI_MCIEN_OFFSET 0
7176 +#define MCI_MCIEN_SIZE 1
7177 +#define MCI_MCIDIS_OFFSET 1
7178 +#define MCI_MCIDIS_SIZE 1
7179 +#define MCI_PWSEN_OFFSET 2
7180 +#define MCI_PWSEN_SIZE 1
7181 +#define MCI_PWSDIS_OFFSET 3
7182 +#define MCI_PWSDIS_SIZE 1
7183 +#define MCI_SWRST_OFFSET 7
7184 +#define MCI_SWRST_SIZE 1
7186 +/* Bitfields in MR */
7187 +#define MCI_CLKDIV_OFFSET 0
7188 +#define MCI_CLKDIV_SIZE 8
7189 +#define MCI_PWSDIV_OFFSET 8
7190 +#define MCI_PWSDIV_SIZE 3
7191 +#define MCI_RDPROOF_OFFSET 11
7192 +#define MCI_RDPROOF_SIZE 1
7193 +#define MCI_WRPROOF_OFFSET 12
7194 +#define MCI_WRPROOF_SIZE 1
7195 +#define MCI_DMAPADV_OFFSET 14
7196 +#define MCI_DMAPADV_SIZE 1
7197 +#define MCI_BLKLEN_OFFSET 16
7198 +#define MCI_BLKLEN_SIZE 16
7200 +/* Bitfields in DTOR */
7201 +#define MCI_DTOCYC_OFFSET 0
7202 +#define MCI_DTOCYC_SIZE 4
7203 +#define MCI_DTOMUL_OFFSET 4
7204 +#define MCI_DTOMUL_SIZE 3
7206 +/* Bitfields in SDCR */
7207 +#define MCI_SDCSEL_OFFSET 0
7208 +#define MCI_SDCSEL_SIZE 4
7209 +#define MCI_SDCBUS_OFFSET 7
7210 +#define MCI_SDCBUS_SIZE 1
7212 +/* Bitfields in ARGR */
7213 +#define MCI_ARG_OFFSET 0
7214 +#define MCI_ARG_SIZE 32
7216 +/* Bitfields in CMDR */
7217 +#define MCI_CMDNB_OFFSET 0
7218 +#define MCI_CMDNB_SIZE 6
7219 +#define MCI_RSPTYP_OFFSET 6
7220 +#define MCI_RSPTYP_SIZE 2
7221 +#define MCI_SPCMD_OFFSET 8
7222 +#define MCI_SPCMD_SIZE 3
7223 +#define MCI_OPDCMD_OFFSET 11
7224 +#define MCI_OPDCMD_SIZE 1
7225 +#define MCI_MAXLAT_OFFSET 12
7226 +#define MCI_MAXLAT_SIZE 1
7227 +#define MCI_TRCMD_OFFSET 16
7228 +#define MCI_TRCMD_SIZE 2
7229 +#define MCI_TRDIR_OFFSET 18
7230 +#define MCI_TRDIR_SIZE 1
7231 +#define MCI_TRTYP_OFFSET 19
7232 +#define MCI_TRTYP_SIZE 2
7234 +/* Bitfields in BLKR */
7235 +#define MCI_BCNT_OFFSET 0
7236 +#define MCI_BCNT_SIZE 16
7238 +/* Bitfields in RSPRn */
7239 +#define MCI_RSP_OFFSET 0
7240 +#define MCI_RSP_SIZE 32
7242 +/* Bitfields in SR/IER/IDR/IMR */
7243 +#define MCI_CMDRDY_OFFSET 0
7244 +#define MCI_CMDRDY_SIZE 1
7245 +#define MCI_RXRDY_OFFSET 1
7246 +#define MCI_RXRDY_SIZE 1
7247 +#define MCI_TXRDY_OFFSET 2
7248 +#define MCI_TXRDY_SIZE 1
7249 +#define MCI_BLKE_OFFSET 3
7250 +#define MCI_BLKE_SIZE 1
7251 +#define MCI_DTIP_OFFSET 4
7252 +#define MCI_DTIP_SIZE 1
7253 +#define MCI_NOTBUSY_OFFSET 5
7254 +#define MCI_NOTBUSY_SIZE 1
7255 +#define MCI_ENDRX_OFFSET 6
7256 +#define MCI_ENDRX_SIZE 1
7257 +#define MCI_ENDTX_OFFSET 7
7258 +#define MCI_ENDTX_SIZE 1
7259 +#define MCI_RXBUFF_OFFSET 14
7260 +#define MCI_RXBUFF_SIZE 1
7261 +#define MCI_TXBUFE_OFFSET 15
7262 +#define MCI_TXBUFE_SIZE 1
7263 +#define MCI_RINDE_OFFSET 16
7264 +#define MCI_RINDE_SIZE 1
7265 +#define MCI_RDIRE_OFFSET 17
7266 +#define MCI_RDIRE_SIZE 1
7267 +#define MCI_RCRCE_OFFSET 18
7268 +#define MCI_RCRCE_SIZE 1
7269 +#define MCI_RENDE_OFFSET 19
7270 +#define MCI_RENDE_SIZE 1
7271 +#define MCI_RTOE_OFFSET 20
7272 +#define MCI_RTOE_SIZE 1
7273 +#define MCI_DCRCE_OFFSET 21
7274 +#define MCI_DCRCE_SIZE 1
7275 +#define MCI_DTOE_OFFSET 22
7276 +#define MCI_DTOE_SIZE 1
7277 +#define MCI_OVRE_OFFSET 30
7278 +#define MCI_OVRE_SIZE 1
7279 +#define MCI_UNRE_OFFSET 31
7280 +#define MCI_UNRE_SIZE 1
7282 +/* Constants for DTOMUL */
7283 +#define MCI_DTOMUL_1_CYCLE 0
7284 +#define MCI_DTOMUL_16_CYCLES 1
7285 +#define MCI_DTOMUL_128_CYCLES 2
7286 +#define MCI_DTOMUL_256_CYCLES 3
7287 +#define MCI_DTOMUL_1024_CYCLES 4
7288 +#define MCI_DTOMUL_4096_CYCLES 5
7289 +#define MCI_DTOMUL_65536_CYCLES 6
7290 +#define MCI_DTOMUL_1048576_CYCLES 7
7292 +/* Constants for RSPTYP */
7293 +#define MCI_RSPTYP_NO_RESP 0
7294 +#define MCI_RSPTYP_48_BIT 1
7295 +#define MCI_RSPTYP_136_BIT 2
7297 +/* Constants for SPCMD */
7298 +#define MCI_SPCMD_NO_SPEC_CMD 0
7299 +#define MCI_SPCMD_INIT_CMD 1
7300 +#define MCI_SPCMD_SYNC_CMD 2
7301 +#define MCI_SPCMD_INT_CMD 4
7302 +#define MCI_SPCMD_INT_RESP 5
7304 +/* Constants for TRCMD */
7305 +#define MCI_TRCMD_NO_TRANS 0
7306 +#define MCI_TRCMD_START_TRANS 1
7307 +#define MCI_TRCMD_STOP_TRANS 2
7309 +/* Constants for TRTYP */
7310 +#define MCI_TRTYP_BLOCK 0
7311 +#define MCI_TRTYP_MULTI_BLOCK 1
7312 +#define MCI_TRTYP_STREAM 2
7314 +/* Bit manipulation macros */
7315 +#define MCI_BIT(name) \
7316 + (1 << MCI_##name##_OFFSET)
7317 +#define MCI_BF(name,value) \
7318 + (((value) & ((1 << MCI_##name##_SIZE) - 1)) \
7319 + << MCI_##name##_OFFSET)
7320 +#define MCI_BFEXT(name,value) \
7321 + (((value) >> MCI_##name##_OFFSET) \
7322 + & ((1 << MCI_##name##_SIZE) - 1))
7323 +#define MCI_BFINS(name,value,old) \
7324 + (((old) & ~(((1 << MCI_##name##_SIZE) - 1) \
7325 + << MCI_##name##_OFFSET)) \
7326 + | MCI_BF(name,value))
7328 +/* Register access macros */
7329 +#define mci_readl(port,reg) \
7330 + __raw_readl((port)->regs + MCI_##reg)
7331 +#define mci_writel(port,reg,value) \
7332 + __raw_writel((value), (port)->regs + MCI_##reg)
7334 +#endif /* __DRIVERS_MMC_ATMEL_MCI_H__ */
7335 diff -x .git -Nur linux-2.6.22.1/drivers/mmc/host/Kconfig linux-avr32.git/drivers/mmc/host/Kconfig
7336 --- linux-2.6.22.1/drivers/mmc/host/Kconfig 2007-07-10 20:56:30.000000000 +0200
7337 +++ linux-avr32.git/drivers/mmc/host/Kconfig 2007-07-12 14:00:03.000000000 +0200
7342 +config MMC_ATMELMCI
7343 + tristate "Atmel Multimedia Card Interface support"
7344 + depends on AVR32 && MMC
7346 + This selects the Atmel Multimedia Card Interface. If you have
7347 + a AT91 (ARM) or AT32 (AVR32) platform with a Multimedia Card
7348 + slot, say Y or M here.
7353 tristate "Motorola i.MX Multimedia Card Interface support"
7355 diff -x .git -Nur linux-2.6.22.1/drivers/mmc/host/Makefile linux-avr32.git/drivers/mmc/host/Makefile
7356 --- linux-2.6.22.1/drivers/mmc/host/Makefile 2007-07-10 20:56:30.000000000 +0200
7357 +++ linux-avr32.git/drivers/mmc/host/Makefile 2007-07-12 14:00:03.000000000 +0200
7359 obj-$(CONFIG_MMC_AU1X) += au1xmmc.o
7360 obj-$(CONFIG_MMC_OMAP) += omap.o
7361 obj-$(CONFIG_MMC_AT91) += at91_mci.o
7362 +obj-$(CONFIG_MMC_ATMELMCI) += atmel-mci.o
7363 obj-$(CONFIG_MMC_TIFM_SD) += tifm_sd.o
7365 diff -x .git -Nur linux-2.6.22.1/drivers/mtd/chips/cfi_cmdset_0001.c linux-avr32.git/drivers/mtd/chips/cfi_cmdset_0001.c
7366 --- linux-2.6.22.1/drivers/mtd/chips/cfi_cmdset_0001.c 2007-07-10 20:56:30.000000000 +0200
7367 +++ linux-avr32.git/drivers/mtd/chips/cfi_cmdset_0001.c 2007-07-12 14:00:03.000000000 +0200
7369 #define I82802AC 0x00ac
7370 #define MANUFACTURER_ST 0x0020
7371 #define M50LPW080 0x002F
7372 +#define AT49BV640D 0x02de
7374 static int cfi_intelext_read (struct mtd_info *, loff_t, size_t, size_t *, u_char *);
7375 static int cfi_intelext_write_words(struct mtd_info *, loff_t, size_t, size_t *, const u_char *);
7376 @@ -156,6 +157,47 @@
7380 +/* Atmel chips don't use the same PRI format as Intel chips */
7381 +static void fixup_convert_atmel_pri(struct mtd_info *mtd, void *param)
7383 + struct map_info *map = mtd->priv;
7384 + struct cfi_private *cfi = map->fldrv_priv;
7385 + struct cfi_pri_intelext *extp = cfi->cmdset_priv;
7386 + struct cfi_pri_atmel atmel_pri;
7387 + uint32_t features = 0;
7389 + /* Reverse byteswapping */
7390 + extp->FeatureSupport = cpu_to_le32(extp->FeatureSupport);
7391 + extp->BlkStatusRegMask = cpu_to_le16(extp->BlkStatusRegMask);
7392 + extp->ProtRegAddr = cpu_to_le16(extp->ProtRegAddr);
7394 + memcpy(&atmel_pri, extp, sizeof(atmel_pri));
7395 + memset((char *)extp + 5, 0, sizeof(*extp) - 5);
7397 + printk(KERN_ERR "atmel Features: %02x\n", atmel_pri.Features);
7399 + if (atmel_pri.Features & 0x01) /* chip erase supported */
7400 + features |= (1<<0);
7401 + if (atmel_pri.Features & 0x02) /* erase suspend supported */
7402 + features |= (1<<1);
7403 + if (atmel_pri.Features & 0x04) /* program suspend supported */
7404 + features |= (1<<2);
7405 + if (atmel_pri.Features & 0x08) /* simultaneous operations supported */
7406 + features |= (1<<9);
7407 + if (atmel_pri.Features & 0x20) /* page mode read supported */
7408 + features |= (1<<7);
7409 + if (atmel_pri.Features & 0x40) /* queued erase supported */
7410 + features |= (1<<4);
7411 + if (atmel_pri.Features & 0x80) /* Protection bits supported */
7412 + features |= (1<<6);
7414 + extp->FeatureSupport = features;
7416 + /* burst write mode not supported */
7417 + cfi->cfiq->BufWriteTimeoutTyp = 0;
7418 + cfi->cfiq->BufWriteTimeoutMax = 0;
7421 #ifdef CMDSET0001_DISABLE_ERASE_SUSPEND_ON_WRITE
7422 /* Some Intel Strata Flash prior to FPO revision C has bugs in this area */
7423 static void fixup_intel_strataflash(struct mtd_info *mtd, void* param)
7427 static struct cfi_fixup cfi_fixup_table[] = {
7428 + { CFI_MFR_ATMEL, CFI_ID_ANY, fixup_convert_atmel_pri, NULL },
7429 #ifdef CMDSET0001_DISABLE_ERASE_SUSPEND_ON_WRITE
7430 { CFI_MFR_ANY, CFI_ID_ANY, fixup_intel_strataflash, NULL },
7432 diff -x .git -Nur linux-2.6.22.1/drivers/mtd/chips/cfi_cmdset_0002.c linux-avr32.git/drivers/mtd/chips/cfi_cmdset_0002.c
7433 --- linux-2.6.22.1/drivers/mtd/chips/cfi_cmdset_0002.c 2007-07-10 20:56:30.000000000 +0200
7434 +++ linux-avr32.git/drivers/mtd/chips/cfi_cmdset_0002.c 2007-06-06 11:33:56.000000000 +0200
7435 @@ -186,6 +186,10 @@
7436 extp->TopBottom = 2;
7438 extp->TopBottom = 3;
7440 + /* burst write mode not supported */
7441 + cfi->cfiq->BufWriteTimeoutTyp = 0;
7442 + cfi->cfiq->BufWriteTimeoutMax = 0;
7445 static void fixup_use_secsi(struct mtd_info *mtd, void *param)
7449 static struct cfi_fixup cfi_fixup_table[] = {
7450 + { CFI_MFR_ATMEL, CFI_ID_ANY, fixup_convert_atmel_pri, NULL },
7451 #ifdef AMD_BOOTLOC_BUG
7452 { CFI_MFR_AMD, CFI_ID_ANY, fixup_amd_bootblock, NULL },
7455 #if !FORCE_WORD_WRITE
7456 { CFI_MFR_ANY, CFI_ID_ANY, fixup_use_write_buffers, NULL, },
7458 - { CFI_MFR_ATMEL, CFI_ID_ANY, fixup_convert_atmel_pri, NULL },
7459 { 0, 0, NULL, NULL }
7461 static struct cfi_fixup jedec_fixup_table[] = {
7462 diff -x .git -Nur linux-2.6.22.1/drivers/net/Kconfig linux-avr32.git/drivers/net/Kconfig
7463 --- linux-2.6.22.1/drivers/net/Kconfig 2007-07-10 20:56:30.000000000 +0200
7464 +++ linux-avr32.git/drivers/net/Kconfig 2007-07-12 14:00:03.000000000 +0200
7467 tristate "Atmel MACB support"
7468 depends on NET_ETHERNET && (AVR32 || ARCH_AT91SAM9260 || ARCH_AT91SAM9263)
7472 The Atmel MACB ethernet interface is found on many AT32 and AT91
7473 parts. Say Y to include support for the MACB chip.
7474 diff -x .git -Nur linux-2.6.22.1/drivers/net/macb.c linux-avr32.git/drivers/net/macb.c
7475 --- linux-2.6.22.1/drivers/net/macb.c 2007-07-10 20:56:30.000000000 +0200
7476 +++ linux-avr32.git/drivers/net/macb.c 2007-07-13 11:24:16.000000000 +0200
7478 #include <linux/init.h>
7479 #include <linux/netdevice.h>
7480 #include <linux/etherdevice.h>
7481 -#include <linux/mii.h>
7482 -#include <linux/mutex.h>
7483 #include <linux/dma-mapping.h>
7484 -#include <linux/ethtool.h>
7485 #include <linux/platform_device.h>
7486 +#include <linux/phy.h>
7488 #include <asm/arch/board.h>
7489 +#if defined(CONFIG_ARCH_AT91)
7490 +#include <asm/arch/cpu.h>
7495 @@ -85,172 +86,202 @@
7496 memcpy(bp->dev->dev_addr, addr, sizeof(addr));
7499 -static void macb_enable_mdio(struct macb *bp)
7501 - unsigned long flags;
7504 - spin_lock_irqsave(&bp->lock, flags);
7505 - reg = macb_readl(bp, NCR);
7506 - reg |= MACB_BIT(MPE);
7507 - macb_writel(bp, NCR, reg);
7508 - macb_writel(bp, IER, MACB_BIT(MFD));
7509 - spin_unlock_irqrestore(&bp->lock, flags);
7512 -static void macb_disable_mdio(struct macb *bp)
7513 +static int macb_mdio_read(struct mii_bus *bus, int mii_id, int regnum)
7515 - unsigned long flags;
7518 - spin_lock_irqsave(&bp->lock, flags);
7519 - reg = macb_readl(bp, NCR);
7520 - reg &= ~MACB_BIT(MPE);
7521 - macb_writel(bp, NCR, reg);
7522 - macb_writel(bp, IDR, MACB_BIT(MFD));
7523 - spin_unlock_irqrestore(&bp->lock, flags);
7526 -static int macb_mdio_read(struct net_device *dev, int phy_id, int location)
7528 - struct macb *bp = netdev_priv(dev);
7529 + struct macb *bp = bus->priv;
7532 - mutex_lock(&bp->mdio_mutex);
7534 - macb_enable_mdio(bp);
7535 macb_writel(bp, MAN, (MACB_BF(SOF, MACB_MAN_SOF)
7536 | MACB_BF(RW, MACB_MAN_READ)
7537 - | MACB_BF(PHYA, phy_id)
7538 - | MACB_BF(REGA, location)
7539 + | MACB_BF(PHYA, mii_id)
7540 + | MACB_BF(REGA, regnum)
7541 | MACB_BF(CODE, MACB_MAN_CODE)));
7543 - wait_for_completion(&bp->mdio_complete);
7544 + /* wait for end of transfer */
7545 + while (!MACB_BFEXT(IDLE, macb_readl(bp, NSR)))
7548 value = MACB_BFEXT(DATA, macb_readl(bp, MAN));
7549 - macb_disable_mdio(bp);
7550 - mutex_unlock(&bp->mdio_mutex);
7555 -static void macb_mdio_write(struct net_device *dev, int phy_id,
7556 - int location, int val)
7557 +static int macb_mdio_write(struct mii_bus *bus, int mii_id, int regnum,
7560 - struct macb *bp = netdev_priv(dev);
7562 - dev_dbg(&bp->pdev->dev, "mdio_write %02x:%02x <- %04x\n",
7563 - phy_id, location, val);
7565 - mutex_lock(&bp->mdio_mutex);
7566 - macb_enable_mdio(bp);
7567 + struct macb *bp = bus->priv;
7569 macb_writel(bp, MAN, (MACB_BF(SOF, MACB_MAN_SOF)
7570 | MACB_BF(RW, MACB_MAN_WRITE)
7571 - | MACB_BF(PHYA, phy_id)
7572 - | MACB_BF(REGA, location)
7573 + | MACB_BF(PHYA, mii_id)
7574 + | MACB_BF(REGA, regnum)
7575 | MACB_BF(CODE, MACB_MAN_CODE)
7576 - | MACB_BF(DATA, val)));
7577 + | MACB_BF(DATA, value)));
7579 - wait_for_completion(&bp->mdio_complete);
7580 + /* wait for end of transfer */
7581 + while (!MACB_BFEXT(IDLE, macb_readl(bp, NSR)))
7584 - macb_disable_mdio(bp);
7585 - mutex_unlock(&bp->mdio_mutex);
7589 -static int macb_phy_probe(struct macb *bp)
7590 +static int macb_mdio_reset(struct mii_bus *bus)
7593 - u16 phyid1, phyid2;
7597 - for (phy_address = 0; phy_address < 32; phy_address++) {
7598 - phyid1 = macb_mdio_read(bp->dev, phy_address, MII_PHYSID1);
7599 - phyid2 = macb_mdio_read(bp->dev, phy_address, MII_PHYSID2);
7600 +static void macb_handle_link_change(struct net_device *dev)
7602 + struct macb *bp = netdev_priv(dev);
7603 + struct phy_device *phydev = bp->phy_dev;
7604 + unsigned long flags;
7606 - if (phyid1 != 0xffff && phyid1 != 0x0000
7607 - && phyid2 != 0xffff && phyid2 != 0x0000)
7609 + int status_change = 0;
7611 + spin_lock_irqsave(&bp->lock, flags);
7613 + if (phydev->link) {
7614 + if ((bp->speed != phydev->speed) ||
7615 + (bp->duplex != phydev->duplex)) {
7618 + reg = macb_readl(bp, NCFGR);
7619 + reg &= ~(MACB_BIT(SPD) | MACB_BIT(FD));
7621 + if (phydev->duplex)
7622 + reg |= MACB_BIT(FD);
7623 + if (phydev->speed)
7624 + reg |= MACB_BIT(SPD);
7626 + macb_writel(bp, NCFGR, reg);
7628 + bp->speed = phydev->speed;
7629 + bp->duplex = phydev->duplex;
7630 + status_change = 1;
7634 - if (phy_address == 32)
7636 + if (phydev->link != bp->link) {
7638 + netif_schedule(dev);
7643 + bp->link = phydev->link;
7645 - dev_info(&bp->pdev->dev,
7646 - "detected PHY at address %d (ID %04x:%04x)\n",
7647 - phy_address, phyid1, phyid2);
7648 + status_change = 1;
7651 - bp->mii.phy_id = phy_address;
7653 + spin_unlock_irqrestore(&bp->lock, flags);
7655 + if (status_change) {
7657 + printk(KERN_INFO "%s: link up (%d/%s)\n",
7658 + dev->name, phydev->speed,
7659 + DUPLEX_FULL == phydev->duplex ? "Full":"Half");
7661 + printk(KERN_INFO "%s: link down\n", dev->name);
7665 -static void macb_set_media(struct macb *bp, int media)
7666 +/* based on au1000_eth. c*/
7667 +static int macb_mii_probe(struct net_device *dev)
7670 + struct macb *bp = netdev_priv(dev);
7671 + struct phy_device *phydev = NULL;
7672 + struct eth_platform_data *pdata;
7675 - spin_lock_irq(&bp->lock);
7676 - reg = macb_readl(bp, NCFGR);
7677 - reg &= ~(MACB_BIT(SPD) | MACB_BIT(FD));
7678 - if (media & (ADVERTISE_100HALF | ADVERTISE_100FULL))
7679 - reg |= MACB_BIT(SPD);
7680 - if (media & ADVERTISE_FULL)
7681 - reg |= MACB_BIT(FD);
7682 - macb_writel(bp, NCFGR, reg);
7683 - spin_unlock_irq(&bp->lock);
7684 + /* find the first phy */
7685 + for (phy_addr = 0; phy_addr < PHY_MAX_ADDR; phy_addr++) {
7686 + if (bp->mii_bus.phy_map[phy_addr]) {
7687 + phydev = bp->mii_bus.phy_map[phy_addr];
7693 + printk (KERN_ERR "%s: no PHY found\n", dev->name);
7697 + pdata = bp->pdev->dev.platform_data;
7698 + /* TODO : add pin_irq */
7700 + /* attach the mac to the phy */
7701 + if (pdata && pdata->is_rmii) {
7702 + phydev = phy_connect(dev, phydev->dev.bus_id,
7703 + &macb_handle_link_change, 0, PHY_INTERFACE_MODE_RMII);
7705 + phydev = phy_connect(dev, phydev->dev.bus_id,
7706 + &macb_handle_link_change, 0, PHY_INTERFACE_MODE_MII);
7709 + if (IS_ERR(phydev)) {
7710 + printk(KERN_ERR "%s: Could not attach to PHY\n", dev->name);
7711 + return PTR_ERR(phydev);
7714 + /* mask with MAC supported features */
7715 + phydev->supported &= PHY_BASIC_FEATURES;
7717 + phydev->advertising = phydev->supported;
7722 + bp->phy_dev = phydev;
7727 -static void macb_check_media(struct macb *bp, int ok_to_print, int init_media)
7728 +static int macb_mii_init(struct macb *bp)
7730 - struct mii_if_info *mii = &bp->mii;
7731 - unsigned int old_carrier, new_carrier;
7732 - int advertise, lpa, media, duplex;
7733 + struct eth_platform_data *pdata;
7734 + int err = -ENXIO, i;
7736 - /* if forced media, go no further */
7737 - if (mii->force_media)
7739 + /* Enable managment port */
7740 + macb_writel(bp, NCR, MACB_BIT(MPE));
7742 - /* check current and old link status */
7743 - old_carrier = netif_carrier_ok(mii->dev) ? 1 : 0;
7744 - new_carrier = (unsigned int) mii_link_ok(mii);
7745 + bp->mii_bus.name = "MACB_mii_bus",
7746 + bp->mii_bus.read = &macb_mdio_read,
7747 + bp->mii_bus.write = &macb_mdio_write,
7748 + bp->mii_bus.reset = &macb_mdio_reset,
7749 + bp->mii_bus.id = bp->pdev->id,
7750 + bp->mii_bus.priv = bp,
7751 + bp->mii_bus.dev = &bp->dev->dev;
7752 + pdata = bp->pdev->dev.platform_data;
7754 - /* if carrier state did not change, assume nothing else did */
7755 - if (!init_media && old_carrier == new_carrier)
7758 + bp->mii_bus.phy_mask = pdata->phy_mask;
7760 - /* no carrier, nothing much to do */
7761 - if (!new_carrier) {
7762 - netif_carrier_off(mii->dev);
7763 - printk(KERN_INFO "%s: link down\n", mii->dev->name);
7765 + bp->mii_bus.irq = kmalloc(sizeof(int)*PHY_MAX_ADDR, GFP_KERNEL);
7766 + if (!bp->mii_bus.irq) {
7772 - * we have carrier, see who's on the other end
7774 - netif_carrier_on(mii->dev);
7775 + for (i = 0; i < PHY_MAX_ADDR; i++)
7776 + bp->mii_bus.irq[i] = PHY_POLL;
7778 - /* get MII advertise and LPA values */
7779 - if (!init_media && mii->advertising) {
7780 - advertise = mii->advertising;
7782 - advertise = mii->mdio_read(mii->dev, mii->phy_id, MII_ADVERTISE);
7783 - mii->advertising = advertise;
7785 - lpa = mii->mdio_read(mii->dev, mii->phy_id, MII_LPA);
7786 + platform_set_drvdata(bp->dev, &bp->mii_bus);
7788 - /* figure out media and duplex from advertise and LPA values */
7789 - media = mii_nway_result(lpa & advertise);
7790 - duplex = (media & ADVERTISE_FULL) ? 1 : 0;
7791 + if (mdiobus_register(&bp->mii_bus))
7792 + goto err_out_free_mdio_irq;
7795 - printk(KERN_INFO "%s: link up, %sMbps, %s-duplex, lpa 0x%04X\n",
7797 - media & (ADVERTISE_100FULL | ADVERTISE_100HALF) ? "100" : "10",
7798 - duplex ? "full" : "half", lpa);
7799 + if (macb_mii_probe(bp->dev) != 0) {
7800 + goto err_out_unregister_bus;
7803 - mii->full_duplex = duplex;
7806 - /* Let the MAC know about the new link state */
7807 - macb_set_media(bp, media);
7808 +err_out_unregister_bus:
7809 + mdiobus_unregister(&bp->mii_bus);
7810 +err_out_free_mdio_irq:
7811 + kfree(bp->mii_bus.irq);
7816 static void macb_update_stats(struct macb *bp)
7817 @@ -265,16 +296,6 @@
7818 *p += __raw_readl(reg);
7821 -static void macb_periodic_task(struct work_struct *work)
7823 - struct macb *bp = container_of(work, struct macb, periodic_task.work);
7825 - macb_update_stats(bp);
7826 - macb_check_media(bp, 1, 0);
7828 - schedule_delayed_work(&bp->periodic_task, HZ);
7831 static void macb_tx(struct macb *bp)
7835 spin_lock(&bp->lock);
7838 - if (status & MACB_BIT(MFD))
7839 - complete(&bp->mdio_complete);
7841 /* close possible race with dev_close */
7842 if (unlikely(!netif_running(dev))) {
7843 macb_writel(bp, IDR, ~0UL);
7845 * until we have processed the buffers
7847 macb_writel(bp, IDR, MACB_RX_INT_FLAGS);
7848 - dev_dbg(&bp->pdev->dev, "scheduling RX softirq\n");
7849 + dev_dbg(&bp->pdev->dev,
7850 + "scheduling RX softirq\n");
7851 __netif_rx_schedule(dev);
7855 macb_writel(bp, TBQP, bp->tx_ring_dma);
7857 /* Enable TX and RX */
7858 - macb_writel(bp, NCR, MACB_BIT(RE) | MACB_BIT(TE));
7859 + macb_writel(bp, NCR, MACB_BIT(RE) | MACB_BIT(TE) | MACB_BIT(MPE));
7861 /* Enable interrupts */
7862 macb_writel(bp, IER, (MACB_BIT(RCOMP)
7863 @@ -776,18 +795,126 @@
7865 | MACB_BIT(ISR_ROVR)
7866 | MACB_BIT(HRESP)));
7871 + * The hash address register is 64 bits long and takes up two
7872 + * locations in the memory map. The least significant bits are stored
7873 + * in EMAC_HSL and the most significant bits in EMAC_HSH.
7875 + * The unicast hash enable and the multicast hash enable bits in the
7876 + * network configuration register enable the reception of hash matched
7877 + * frames. The destination address is reduced to a 6 bit index into
7878 + * the 64 bit hash register using the following hash function. The
7879 + * hash function is an exclusive or of every sixth bit of the
7880 + * destination address.
7882 + * hi[5] = da[5] ^ da[11] ^ da[17] ^ da[23] ^ da[29] ^ da[35] ^ da[41] ^ da[47]
7883 + * hi[4] = da[4] ^ da[10] ^ da[16] ^ da[22] ^ da[28] ^ da[34] ^ da[40] ^ da[46]
7884 + * hi[3] = da[3] ^ da[09] ^ da[15] ^ da[21] ^ da[27] ^ da[33] ^ da[39] ^ da[45]
7885 + * hi[2] = da[2] ^ da[08] ^ da[14] ^ da[20] ^ da[26] ^ da[32] ^ da[38] ^ da[44]
7886 + * hi[1] = da[1] ^ da[07] ^ da[13] ^ da[19] ^ da[25] ^ da[31] ^ da[37] ^ da[43]
7887 + * hi[0] = da[0] ^ da[06] ^ da[12] ^ da[18] ^ da[24] ^ da[30] ^ da[36] ^ da[42]
7889 + * da[0] represents the least significant bit of the first byte
7890 + * received, that is, the multicast/unicast indicator, and da[47]
7891 + * represents the most significant bit of the last byte received. If
7892 + * the hash index, hi[n], points to a bit that is set in the hash
7893 + * register then the frame will be matched according to whether the
7894 + * frame is multicast or unicast. A multicast match will be signalled
7895 + * if the multicast hash enable bit is set, da[0] is 1 and the hash
7896 + * index points to a bit set in the hash register. A unicast match
7897 + * will be signalled if the unicast hash enable bit is set, da[0] is 0
7898 + * and the hash index points to a bit set in the hash register. To
7899 + * receive all multicast frames, the hash register should be set with
7900 + * all ones and the multicast hash enable bit should be set in the
7901 + * network configuration register.
7904 +static inline int hash_bit_value(int bitnr, __u8 *addr)
7906 + if (addr[bitnr / 8] & (1 << (bitnr % 8)))
7912 + * Return the hash index value for the specified address.
7914 +static int hash_get_index(__u8 *addr)
7917 + int hash_index = 0;
7919 + for (j = 0; j < 6; j++) {
7920 + for (i = 0, bitval = 0; i < 8; i++)
7921 + bitval ^= hash_bit_value(i*6 + j, addr);
7923 + hash_index |= (bitval << j);
7926 + return hash_index;
7929 -static void macb_init_phy(struct net_device *dev)
7931 + * Add multicast addresses to the internal multicast-hash table.
7933 +static void macb_sethashtable(struct net_device *dev)
7935 + struct dev_mc_list *curr;
7936 + unsigned long mc_filter[2];
7937 + unsigned int i, bitnr;
7938 struct macb *bp = netdev_priv(dev);
7940 - /* Set some reasonable default settings */
7941 - macb_mdio_write(dev, bp->mii.phy_id, MII_ADVERTISE,
7942 - ADVERTISE_CSMA | ADVERTISE_ALL);
7943 - macb_mdio_write(dev, bp->mii.phy_id, MII_BMCR,
7944 - (BMCR_SPEED100 | BMCR_ANENABLE
7945 - | BMCR_ANRESTART | BMCR_FULLDPLX));
7946 + mc_filter[0] = mc_filter[1] = 0;
7948 + curr = dev->mc_list;
7949 + for (i = 0; i < dev->mc_count; i++, curr = curr->next) {
7950 + if (!curr) break; /* unexpected end of list */
7952 + bitnr = hash_get_index(curr->dmi_addr);
7953 + mc_filter[bitnr >> 5] |= 1 << (bitnr & 31);
7956 + macb_writel(bp, HRB, mc_filter[0]);
7957 + macb_writel(bp, HRT, mc_filter[1]);
7961 + * Enable/Disable promiscuous and multicast modes.
7963 +static void macb_set_rx_mode(struct net_device *dev)
7965 + unsigned long cfg;
7966 + struct macb *bp = netdev_priv(dev);
7968 + cfg = macb_readl(bp, NCFGR);
7970 + if (dev->flags & IFF_PROMISC)
7971 + /* Enable promiscuous mode */
7972 + cfg |= MACB_BIT(CAF);
7973 + else if (dev->flags & (~IFF_PROMISC))
7974 + /* Disable promiscuous mode */
7975 + cfg &= ~MACB_BIT(CAF);
7977 + if (dev->flags & IFF_ALLMULTI) {
7978 + /* Enable all multicast mode */
7979 + macb_writel(bp, HRB, -1);
7980 + macb_writel(bp, HRT, -1);
7981 + cfg |= MACB_BIT(NCFGR_MTI);
7982 + } else if (dev->mc_count > 0) {
7983 + /* Enable specific multicasts */
7984 + macb_sethashtable(dev);
7985 + cfg |= MACB_BIT(NCFGR_MTI);
7986 + } else if (dev->flags & (~IFF_ALLMULTI)) {
7987 + /* Disable all multicast mode */
7988 + macb_writel(bp, HRB, 0);
7989 + macb_writel(bp, HRT, 0);
7990 + cfg &= ~MACB_BIT(NCFGR_MTI);
7993 + macb_writel(bp, NCFGR, cfg);
7996 static int macb_open(struct net_device *dev)
7997 @@ -797,6 +924,10 @@
7999 dev_dbg(&bp->pdev->dev, "open\n");
8001 + /* if the phy is not yet register, retry later*/
8005 if (!is_valid_ether_addr(dev->dev_addr))
8006 return -EADDRNOTAVAIL;
8008 @@ -810,12 +941,11 @@
8010 macb_init_rings(bp);
8012 - macb_init_phy(dev);
8014 - macb_check_media(bp, 1, 1);
8015 - netif_start_queue(dev);
8016 + /* schedule a link state check */
8017 + phy_start(bp->phy_dev);
8019 - schedule_delayed_work(&bp->periodic_task, HZ);
8020 + netif_start_queue(dev);
8024 @@ -825,10 +955,11 @@
8025 struct macb *bp = netdev_priv(dev);
8026 unsigned long flags;
8028 - cancel_rearming_delayed_work(&bp->periodic_task);
8030 netif_stop_queue(dev);
8033 + phy_stop(bp->phy_dev);
8035 spin_lock_irqsave(&bp->lock, flags);
8037 netif_carrier_off(dev);
8039 struct net_device_stats *nstat = &bp->stats;
8040 struct macb_stats *hwstat = &bp->hw_stats;
8042 + /* read stats from hardware */
8043 + macb_update_stats(bp);
8045 /* Convert HW stats into netdevice stats */
8046 nstat->rx_errors = (hwstat->rx_fcs_errors +
8047 hwstat->rx_align_errors +
8048 @@ -882,18 +1016,27 @@
8049 static int macb_get_settings(struct net_device *dev, struct ethtool_cmd *cmd)
8051 struct macb *bp = netdev_priv(dev);
8052 + struct phy_device *phydev = bp->phy_dev;
8057 - return mii_ethtool_gset(&bp->mii, cmd);
8058 + return phy_ethtool_gset(phydev, cmd);
8061 static int macb_set_settings(struct net_device *dev, struct ethtool_cmd *cmd)
8063 struct macb *bp = netdev_priv(dev);
8064 + struct phy_device *phydev = bp->phy_dev;
8069 - return mii_ethtool_sset(&bp->mii, cmd);
8070 + return phy_ethtool_sset(phydev, cmd);
8073 -static void macb_get_drvinfo(struct net_device *dev, struct ethtool_drvinfo *info)
8074 +static void macb_get_drvinfo(struct net_device *dev,
8075 + struct ethtool_drvinfo *info)
8077 struct macb *bp = netdev_priv(dev);
8079 @@ -902,104 +1045,34 @@
8080 strcpy(info->bus_info, bp->pdev->dev.bus_id);
8083 -static int macb_nway_reset(struct net_device *dev)
8085 - struct macb *bp = netdev_priv(dev);
8086 - return mii_nway_restart(&bp->mii);
8089 static struct ethtool_ops macb_ethtool_ops = {
8090 .get_settings = macb_get_settings,
8091 .set_settings = macb_set_settings,
8092 .get_drvinfo = macb_get_drvinfo,
8093 - .nway_reset = macb_nway_reset,
8094 .get_link = ethtool_op_get_link,
8097 static int macb_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
8099 struct macb *bp = netdev_priv(dev);
8100 + struct phy_device *phydev = bp->phy_dev;
8102 if (!netif_running(dev))
8105 - return generic_mii_ioctl(&bp->mii, if_mii(rq), cmd, NULL);
8108 -static ssize_t macb_mii_show(const struct device *_dev, char *buf,
8109 - unsigned long addr)
8111 - struct net_device *dev = to_net_dev(_dev);
8112 - struct macb *bp = netdev_priv(dev);
8113 - ssize_t ret = -EINVAL;
8115 - if (netif_running(dev)) {
8117 - value = macb_mdio_read(dev, bp->mii.phy_id, addr);
8118 - ret = sprintf(buf, "0x%04x\n", (uint16_t)value);
8124 -#define MII_ENTRY(name, addr) \
8125 -static ssize_t show_##name(struct device *_dev, \
8126 - struct device_attribute *attr, \
8129 - return macb_mii_show(_dev, buf, addr); \
8131 -static DEVICE_ATTR(name, S_IRUGO, show_##name, NULL)
8133 -MII_ENTRY(bmcr, MII_BMCR);
8134 -MII_ENTRY(bmsr, MII_BMSR);
8135 -MII_ENTRY(physid1, MII_PHYSID1);
8136 -MII_ENTRY(physid2, MII_PHYSID2);
8137 -MII_ENTRY(advertise, MII_ADVERTISE);
8138 -MII_ENTRY(lpa, MII_LPA);
8139 -MII_ENTRY(expansion, MII_EXPANSION);
8141 -static struct attribute *macb_mii_attrs[] = {
8142 - &dev_attr_bmcr.attr,
8143 - &dev_attr_bmsr.attr,
8144 - &dev_attr_physid1.attr,
8145 - &dev_attr_physid2.attr,
8146 - &dev_attr_advertise.attr,
8147 - &dev_attr_lpa.attr,
8148 - &dev_attr_expansion.attr,
8152 -static struct attribute_group macb_mii_group = {
8154 - .attrs = macb_mii_attrs,
8157 -static void macb_unregister_sysfs(struct net_device *net)
8159 - struct device *_dev = &net->dev;
8163 - sysfs_remove_group(&_dev->kobj, &macb_mii_group);
8164 + return phy_mii_ioctl(phydev, if_mii(rq), cmd);
8167 -static int macb_register_sysfs(struct net_device *net)
8169 - struct device *_dev = &net->dev;
8172 - ret = sysfs_create_group(&_dev->kobj, &macb_mii_group);
8174 - printk(KERN_WARNING
8175 - "%s: sysfs mii attribute registration failed: %d\n",
8179 static int __devinit macb_probe(struct platform_device *pdev)
8181 struct eth_platform_data *pdata;
8182 struct resource *regs;
8183 struct net_device *dev;
8185 + struct phy_device *phydev;
8186 unsigned long pclk_hz;
8189 @@ -1073,6 +1146,7 @@
8190 dev->stop = macb_close;
8191 dev->hard_start_xmit = macb_start_xmit;
8192 dev->get_stats = macb_get_stats;
8193 + dev->set_multicast_list = macb_set_rx_mode;
8194 dev->do_ioctl = macb_ioctl;
8195 dev->poll = macb_poll;
8197 @@ -1080,10 +1154,6 @@
8199 dev->base_addr = regs->start;
8201 - INIT_DELAYED_WORK(&bp->periodic_task, macb_periodic_task);
8202 - mutex_init(&bp->mdio_mutex);
8203 - init_completion(&bp->mdio_complete);
8205 /* Set MII management clock divider */
8206 pclk_hz = clk_get_rate(bp->pclk);
8207 if (pclk_hz <= 20000000)
8208 @@ -1096,20 +1166,9 @@
8209 config = MACB_BF(CLK, MACB_CLK_DIV64);
8210 macb_writel(bp, NCFGR, config);
8212 - bp->mii.dev = dev;
8213 - bp->mii.mdio_read = macb_mdio_read;
8214 - bp->mii.mdio_write = macb_mdio_write;
8215 - bp->mii.phy_id_mask = 0x1f;
8216 - bp->mii.reg_num_mask = 0x1f;
8218 macb_get_hwaddr(bp);
8219 - err = macb_phy_probe(bp);
8221 - dev_err(&pdev->dev, "Failed to detect PHY, aborting.\n");
8222 - goto err_out_free_irq;
8225 pdata = pdev->dev.platform_data;
8227 if (pdata && pdata->is_rmii)
8228 #if defined(CONFIG_ARCH_AT91)
8229 macb_writel(bp, USRIO, (MACB_BIT(RMII) | MACB_BIT(CLKEN)) );
8230 @@ -1131,9 +1190,11 @@
8231 goto err_out_free_irq;
8234 - platform_set_drvdata(pdev, dev);
8235 + if (macb_mii_init(bp) != 0) {
8236 + goto err_out_unregister_netdev;
8239 - macb_register_sysfs(dev);
8240 + platform_set_drvdata(pdev, dev);
8242 printk(KERN_INFO "%s: Atmel MACB at 0x%08lx irq %d "
8243 "(%02x:%02x:%02x:%02x:%02x:%02x)\n",
8244 @@ -1141,8 +1202,15 @@
8245 dev->dev_addr[0], dev->dev_addr[1], dev->dev_addr[2],
8246 dev->dev_addr[3], dev->dev_addr[4], dev->dev_addr[5]);
8248 + phydev = bp->phy_dev;
8249 + printk(KERN_INFO "%s: attached PHY driver [%s] "
8250 + "(mii_bus:phy_addr=%s, irq=%d)\n",
8251 + dev->name, phydev->drv->name, phydev->dev.bus_id, phydev->irq);
8255 +err_out_unregister_netdev:
8256 + unregister_netdev(dev);
8258 free_irq(dev->irq, dev);
8260 @@ -1153,7 +1221,9 @@
8263 clk_disable(bp->pclk);
8264 +#ifndef CONFIG_ARCH_AT91
8270 @@ -1171,7 +1241,8 @@
8273 bp = netdev_priv(dev);
8274 - macb_unregister_sysfs(dev);
8275 + mdiobus_unregister(&bp->mii_bus);
8276 + kfree(bp->mii_bus.irq);
8277 unregister_netdev(dev);
8278 free_irq(dev->irq, dev);
8280 diff -x .git -Nur linux-2.6.22.1/drivers/net/macb.h linux-avr32.git/drivers/net/macb.h
8281 --- linux-2.6.22.1/drivers/net/macb.h 2007-07-10 20:56:30.000000000 +0200
8282 +++ linux-avr32.git/drivers/net/macb.h 2007-07-12 14:00:04.000000000 +0200
8283 @@ -383,11 +383,11 @@
8285 unsigned int rx_pending, tx_pending;
8287 - struct delayed_work periodic_task;
8289 - struct mutex mdio_mutex;
8290 - struct completion mdio_complete;
8291 - struct mii_if_info mii;
8292 + struct mii_bus mii_bus;
8293 + struct phy_device *phy_dev;
8294 + unsigned int link;
8295 + unsigned int speed;
8296 + unsigned int duplex;
8299 #endif /* _MACB_H */
8300 diff -x .git -Nur linux-2.6.22.1/drivers/rtc/Kconfig linux-avr32.git/drivers/rtc/Kconfig
8301 --- linux-2.6.22.1/drivers/rtc/Kconfig 2007-07-10 20:56:30.000000000 +0200
8302 +++ linux-avr32.git/drivers/rtc/Kconfig 2007-07-12 14:00:13.000000000 +0200
8303 @@ -379,6 +379,13 @@
8304 To compile this driver as a module, choose M here: the
8305 module will be called rtc-pl031.
8307 +config RTC_DRV_AT32AP700X
8308 + tristate "AT32AP700X series RTC"
8309 + depends on RTC_CLASS && PLATFORM_AT32AP
8311 + Driver for the internal RTC (Realtime Clock) on Atmel AVR32
8312 + AT32AP700x family processors.
8314 config RTC_DRV_AT91RM9200
8315 tristate "AT91RM9200"
8316 depends on RTC_CLASS && ARCH_AT91RM9200
8317 diff -x .git -Nur linux-2.6.22.1/drivers/rtc/Makefile linux-avr32.git/drivers/rtc/Makefile
8318 --- linux-2.6.22.1/drivers/rtc/Makefile 2007-07-10 20:56:30.000000000 +0200
8319 +++ linux-avr32.git/drivers/rtc/Makefile 2007-07-12 14:00:13.000000000 +0200
8321 obj-$(CONFIG_RTC_DRV_X1205) += rtc-x1205.o
8322 obj-$(CONFIG_RTC_DRV_ISL1208) += rtc-isl1208.o
8323 obj-$(CONFIG_RTC_DRV_TEST) += rtc-test.o
8324 +obj-$(CONFIG_RTC_DRV_AT32AP700X) += rtc-at32ap700x.o
8325 obj-$(CONFIG_RTC_DRV_DS1307) += rtc-ds1307.o
8326 obj-$(CONFIG_RTC_DRV_DS1672) += rtc-ds1672.o
8327 obj-$(CONFIG_RTC_DRV_DS1742) += rtc-ds1742.o
8328 diff -x .git -Nur linux-2.6.22.1/drivers/rtc/rtc-at32ap700x.c linux-avr32.git/drivers/rtc/rtc-at32ap700x.c
8329 --- linux-2.6.22.1/drivers/rtc/rtc-at32ap700x.c 1970-01-01 01:00:00.000000000 +0100
8330 +++ linux-avr32.git/drivers/rtc/rtc-at32ap700x.c 2007-07-12 14:00:13.000000000 +0200
8333 + * An RTC driver for the AVR32 AT32AP700x processor series.
8335 + * Copyright (C) 2007 Atmel Corporation
8337 + * This program is free software; you can redistribute it and/or modify it
8338 + * under the terms of the GNU General Public License version 2 as published
8339 + * by the Free Software Foundation.
8342 +#include <linux/module.h>
8343 +#include <linux/kernel.h>
8344 +#include <linux/platform_device.h>
8345 +#include <linux/rtc.h>
8346 +#include <linux/io.h>
8349 + * This is a bare-bones RTC. It runs during most system sleep states, but has
8350 + * no battery backup and gets reset during system restart. It must be
8351 + * initialized from an external clock (network, I2C, etc) before it can be of
8354 + * The alarm functionality is limited by the hardware, not supporting
8355 + * periodic interrupts.
8358 +#define RTC_CTRL 0x00
8359 +#define RTC_CTRL_EN 0
8360 +#define RTC_CTRL_PCLR 1
8361 +#define RTC_CTRL_TOPEN 2
8362 +#define RTC_CTRL_PSEL 8
8364 +#define RTC_VAL 0x04
8366 +#define RTC_TOP 0x08
8368 +#define RTC_IER 0x10
8369 +#define RTC_IER_TOPI 0
8371 +#define RTC_IDR 0x14
8372 +#define RTC_IDR_TOPI 0
8374 +#define RTC_IMR 0x18
8375 +#define RTC_IMR_TOPI 0
8377 +#define RTC_ISR 0x1c
8378 +#define RTC_ISR_TOPI 0
8380 +#define RTC_ICR 0x20
8381 +#define RTC_ICR_TOPI 0
8383 +#define RTC_BIT(name) (1 << RTC_##name)
8384 +#define RTC_BF(name, value) ((value) << RTC_##name)
8386 +#define rtc_readl(dev, reg) \
8387 + __raw_readl((dev)->regs + RTC_##reg)
8388 +#define rtc_writel(dev, reg, value) \
8389 + __raw_writel((value), (dev)->regs + RTC_##reg)
8391 +struct rtc_at32ap700x {
8392 + struct rtc_device *rtc;
8393 + void __iomem *regs;
8394 + unsigned long alarm_time;
8395 + unsigned long irq;
8396 + /* Protect against concurrent register access. */
8400 +static int at32_rtc_readtime(struct device *dev, struct rtc_time *tm)
8402 + struct rtc_at32ap700x *rtc = dev_get_drvdata(dev);
8403 + unsigned long now;
8405 + now = rtc_readl(rtc, VAL);
8406 + rtc_time_to_tm(now, tm);
8411 +static int at32_rtc_settime(struct device *dev, struct rtc_time *tm)
8413 + struct rtc_at32ap700x *rtc = dev_get_drvdata(dev);
8414 + unsigned long now;
8417 + ret = rtc_tm_to_time(tm, &now);
8419 + rtc_writel(rtc, VAL, now);
8424 +static int at32_rtc_readalarm(struct device *dev, struct rtc_wkalrm *alrm)
8426 + struct rtc_at32ap700x *rtc = dev_get_drvdata(dev);
8428 + rtc_time_to_tm(rtc->alarm_time, &alrm->time);
8429 + alrm->pending = rtc_readl(rtc, IMR) & RTC_BIT(IMR_TOPI) ? 1 : 0;
8434 +static int at32_rtc_setalarm(struct device *dev, struct rtc_wkalrm *alrm)
8436 + struct rtc_at32ap700x *rtc = dev_get_drvdata(dev);
8437 + unsigned long rtc_unix_time;
8438 + unsigned long alarm_unix_time;
8441 + rtc_unix_time = rtc_readl(rtc, VAL);
8443 + /* RTC does only support one alarm time, not periodic */
8444 + if (alrm->time.tm_mday <= 0) {
8445 + struct rtc_time tm;
8446 + unsigned long then;
8448 + rtc_time_to_tm(rtc_unix_time, &tm);
8450 + alrm->time.tm_mday = tm.tm_mday;
8451 + alrm->time.tm_mon = tm.tm_mon;
8452 + alrm->time.tm_year = tm.tm_year;
8454 + rtc_tm_to_time(&alrm->time, &then);
8456 + /* check if the alarm wraps into tomorrow */
8457 + if (then < rtc_unix_time) {
8458 + rtc_time_to_tm(rtc_unix_time + 24 * 60 * 60, &tm);
8459 + alrm->time.tm_mday = tm.tm_mday;
8460 + alrm->time.tm_mon = tm.tm_mon;
8461 + alrm->time.tm_year = tm.tm_year;
8465 + ret = rtc_tm_to_time(&alrm->time, &alarm_unix_time);
8469 + if (alarm_unix_time < rtc_unix_time)
8472 + spin_lock_irq(&rtc->lock);
8473 + rtc->alarm_time = alarm_unix_time;
8474 + rtc_writel(rtc, TOP, rtc->alarm_time);
8475 + if (alrm->pending)
8476 + rtc_writel(rtc, CTRL, rtc_readl(rtc, CTRL)
8477 + | RTC_BIT(CTRL_TOPEN));
8479 + rtc_writel(rtc, CTRL, rtc_readl(rtc, CTRL)
8480 + & ~RTC_BIT(CTRL_TOPEN));
8481 + spin_unlock_irq(&rtc->lock);
8486 +static int at32_rtc_ioctl(struct device *dev, unsigned int cmd,
8487 + unsigned long arg)
8489 + struct rtc_at32ap700x *rtc = dev_get_drvdata(dev);
8492 + spin_lock_irq(&rtc->lock);
8496 + if (rtc_readl(rtc, VAL) > rtc->alarm_time) {
8500 + rtc_writel(rtc, CTRL, rtc_readl(rtc, CTRL)
8501 + | RTC_BIT(CTRL_TOPEN));
8502 + rtc_writel(rtc, ICR, RTC_BIT(ICR_TOPI));
8503 + rtc_writel(rtc, IER, RTC_BIT(IER_TOPI));
8506 + rtc_writel(rtc, CTRL, rtc_readl(rtc, CTRL)
8507 + & ~RTC_BIT(CTRL_TOPEN));
8508 + rtc_writel(rtc, IDR, RTC_BIT(IDR_TOPI));
8509 + rtc_writel(rtc, ICR, RTC_BIT(ICR_TOPI));
8512 + ret = -ENOIOCTLCMD;
8516 + spin_unlock_irq(&rtc->lock);
8521 +static irqreturn_t at32_rtc_interrupt(int irq, void *dev_id)
8523 + struct rtc_at32ap700x *rtc = (struct rtc_at32ap700x *)dev_id;
8524 + unsigned long isr = rtc_readl(rtc, ISR);
8525 + unsigned long events = 0;
8526 + int ret = IRQ_NONE;
8528 + spin_lock(&rtc->lock);
8530 + if (isr & RTC_BIT(ISR_TOPI)) {
8531 + rtc_writel(rtc, ICR, RTC_BIT(ICR_TOPI));
8532 + rtc_writel(rtc, IDR, RTC_BIT(IDR_TOPI));
8533 + rtc_writel(rtc, CTRL, rtc_readl(rtc, CTRL)
8534 + & ~RTC_BIT(CTRL_TOPEN));
8535 + rtc_writel(rtc, VAL, rtc->alarm_time);
8536 + events = RTC_AF | RTC_IRQF;
8537 + rtc_update_irq(rtc->rtc, 1, events);
8538 + ret = IRQ_HANDLED;
8541 + spin_unlock(&rtc->lock);
8546 +static struct rtc_class_ops at32_rtc_ops = {
8547 + .ioctl = at32_rtc_ioctl,
8548 + .read_time = at32_rtc_readtime,
8549 + .set_time = at32_rtc_settime,
8550 + .read_alarm = at32_rtc_readalarm,
8551 + .set_alarm = at32_rtc_setalarm,
8554 +static int __init at32_rtc_probe(struct platform_device *pdev)
8556 + struct resource *regs;
8557 + struct rtc_at32ap700x *rtc;
8561 + rtc = kzalloc(sizeof(struct rtc_at32ap700x), GFP_KERNEL);
8563 + dev_dbg(&pdev->dev, "out of memory\n");
8567 + regs = platform_get_resource(pdev, IORESOURCE_MEM, 0);
8569 + dev_dbg(&pdev->dev, "no mmio resource defined\n");
8574 + irq = platform_get_irq(pdev, 0);
8576 + dev_dbg(&pdev->dev, "could not get irq\n");
8581 + ret = request_irq(irq, at32_rtc_interrupt, IRQF_SHARED, "rtc", rtc);
8583 + dev_dbg(&pdev->dev, "could not request irq %d\n", irq);
8588 + rtc->regs = ioremap(regs->start, regs->end - regs->start + 1);
8591 + dev_dbg(&pdev->dev, "could not map I/O memory\n");
8592 + goto out_free_irq;
8594 + spin_lock_init(&rtc->lock);
8597 + * Maybe init RTC: count from zero at 1 Hz, disable wrap irq.
8599 + * Do not reset VAL register, as it can hold an old time
8600 + * from last JTAG reset.
8602 + if (!(rtc_readl(rtc, CTRL) & RTC_BIT(CTRL_EN))) {
8603 + rtc_writel(rtc, CTRL, RTC_BIT(CTRL_PCLR));
8604 + rtc_writel(rtc, IDR, RTC_BIT(IDR_TOPI));
8605 + rtc_writel(rtc, CTRL, RTC_BF(CTRL_PSEL, 0xe)
8606 + | RTC_BIT(CTRL_EN));
8609 + rtc->rtc = rtc_device_register(pdev->name, &pdev->dev,
8610 + &at32_rtc_ops, THIS_MODULE);
8611 + if (IS_ERR(rtc->rtc)) {
8612 + dev_dbg(&pdev->dev, "could not register rtc device\n");
8613 + ret = PTR_ERR(rtc->rtc);
8617 + platform_set_drvdata(pdev, rtc);
8619 + dev_info(&pdev->dev, "Atmel RTC for AT32AP700x at %08lx irq %ld\n",
8620 + (unsigned long)rtc->regs, rtc->irq);
8625 + iounmap(rtc->regs);
8627 + free_irq(irq, rtc);
8633 +static int __exit at32_rtc_remove(struct platform_device *pdev)
8635 + struct rtc_at32ap700x *rtc = platform_get_drvdata(pdev);
8637 + free_irq(rtc->irq, rtc);
8638 + iounmap(rtc->regs);
8639 + rtc_device_unregister(rtc->rtc);
8641 + platform_set_drvdata(pdev, NULL);
8646 +static struct platform_driver at32_rtc_driver = {
8647 + .remove = __exit_p(at32_rtc_remove),
8649 + .name = "rtc-at32ap700x",
8650 + .owner = THIS_MODULE,
8654 +static int __init at32_rtc_init(void)
8656 + return platform_driver_probe(&at32_rtc_driver, at32_rtc_probe);
8658 +module_init(at32_rtc_init);
8660 +static void __exit at32_rtc_exit(void)
8662 + platform_driver_unregister(&at32_rtc_driver);
8664 +module_exit(at32_rtc_exit);
8666 +MODULE_AUTHOR("Hans-Christian Egtvedt <hcegtvedt@atmel.com>");
8667 +MODULE_DESCRIPTION("Real time clock for AVR32 AT32AP700x");
8668 +MODULE_LICENSE("GPL");
8669 diff -x .git -Nur linux-2.6.22.1/drivers/serial/atmel_serial.c linux-avr32.git/drivers/serial/atmel_serial.c
8670 --- linux-2.6.22.1/drivers/serial/atmel_serial.c 2007-07-10 20:56:30.000000000 +0200
8671 +++ linux-avr32.git/drivers/serial/atmel_serial.c 2007-06-06 11:33:59.000000000 +0200
8673 struct uart_port uart; /* uart */
8674 struct clk *clk; /* uart clock */
8675 unsigned short suspended; /* is port suspended? */
8676 + int break_active; /* break being received */
8679 static struct atmel_uart_port atmel_ports[ATMEL_MAX_UART];
8682 static void atmel_rx_chars(struct uart_port *port)
8684 + struct atmel_uart_port *atmel_port = (struct atmel_uart_port *) port;
8685 struct tty_struct *tty = port->info->tty;
8686 unsigned int status, ch, flg;
8688 @@ -267,13 +269,29 @@
8689 * note that the error handling code is
8690 * out of the main execution path
8692 - if (unlikely(status & (ATMEL_US_PARE | ATMEL_US_FRAME | ATMEL_US_OVRE | ATMEL_US_RXBRK))) {
8693 + if (unlikely(status & (ATMEL_US_PARE | ATMEL_US_FRAME
8694 + | ATMEL_US_OVRE | ATMEL_US_RXBRK)
8695 + || atmel_port->break_active)) {
8696 UART_PUT_CR(port, ATMEL_US_RSTSTA); /* clear error */
8697 - if (status & ATMEL_US_RXBRK) {
8698 + if (status & ATMEL_US_RXBRK
8699 + && !atmel_port->break_active) {
8700 status &= ~(ATMEL_US_PARE | ATMEL_US_FRAME); /* ignore side-effect */
8702 + atmel_port->break_active = 1;
8703 + UART_PUT_IER(port, ATMEL_US_RXBRK);
8704 if (uart_handle_break(port))
8708 + * This is either the end-of-break
8709 + * condition or we've received at
8710 + * least one character without RXBRK
8711 + * being set. In both cases, the next
8712 + * RXBRK will indicate start-of-break.
8714 + UART_PUT_IDR(port, ATMEL_US_RXBRK);
8715 + status &= ~ATMEL_US_RXBRK;
8716 + atmel_port->break_active = 0;
8718 if (status & ATMEL_US_PARE)
8719 port->icount.parity++;
8720 @@ -352,6 +370,16 @@
8721 /* Interrupt receive */
8722 if (pending & ATMEL_US_RXRDY)
8723 atmel_rx_chars(port);
8724 + else if (pending & ATMEL_US_RXBRK) {
8726 + * End of break detected. If it came along
8727 + * with a character, atmel_rx_chars will
8730 + UART_PUT_CR(port, ATMEL_US_RSTSTA);
8731 + UART_PUT_IDR(port, ATMEL_US_RXBRK);
8732 + atmel_port->break_active = 0;
8735 // TODO: All reads to CSR will clear these interrupts!
8736 if (pending & ATMEL_US_RIIC) port->icount.rng++;
8737 diff -x .git -Nur linux-2.6.22.1/drivers/spi/atmel_spi.c linux-avr32.git/drivers/spi/atmel_spi.c
8738 --- linux-2.6.22.1/drivers/spi/atmel_spi.c 2007-07-10 20:56:30.000000000 +0200
8739 +++ linux-avr32.git/drivers/spi/atmel_spi.c 2007-06-06 11:33:59.000000000 +0200
8741 csr |= SPI_BIT(NCPHA);
8743 /* TODO: DLYBS and DLYBCT */
8744 - csr |= SPI_BF(DLYBS, 10);
8745 - csr |= SPI_BF(DLYBCT, 10);
8746 + csr |= SPI_BF(DLYBS, 0);
8747 + csr |= SPI_BF(DLYBCT, 0);
8749 /* chipselect must have been muxed as GPIO (e.g. in board setup) */
8750 npcs_pin = (unsigned int)spi->controller_data;
8751 diff -x .git -Nur linux-2.6.22.1/drivers/usb/gadget/atmel_usba_udc.c linux-avr32.git/drivers/usb/gadget/atmel_usba_udc.c
8752 --- linux-2.6.22.1/drivers/usb/gadget/atmel_usba_udc.c 1970-01-01 01:00:00.000000000 +0100
8753 +++ linux-avr32.git/drivers/usb/gadget/atmel_usba_udc.c 2007-07-12 14:00:19.000000000 +0200
8756 + * Driver for the Atmel USBA high speed USB device controller
8758 + * Copyright (C) 2005-2007 Atmel Corporation
8760 + * This program is free software; you can redistribute it and/or modify
8761 + * it under the terms of the GNU General Public License version 2 as
8762 + * published by the Free Software Foundation.
8764 +/* #define DEBUG */
8766 +#include <linux/clk.h>
8767 +#include <linux/module.h>
8768 +#include <linux/init.h>
8769 +#include <linux/interrupt.h>
8770 +#include <linux/io.h>
8771 +#include <linux/device.h>
8772 +#include <linux/dma-mapping.h>
8773 +#include <linux/list.h>
8774 +#include <linux/platform_device.h>
8775 +#include <linux/usb/ch9.h>
8776 +#include <linux/usb_gadget.h>
8777 +#include <linux/delay.h>
8779 +#include <asm/gpio.h>
8780 +#include <asm/arch/board.h>
8782 +#include "atmel_usba_udc.h"
8784 +#define DMA_ADDR_INVALID (~(dma_addr_t)0)
8786 +#define FIFO_IOMEM_ID 0
8787 +#define CTRL_IOMEM_ID 1
8790 +#define DBG_ERR 0x0001 /* report all error returns */
8791 +#define DBG_HW 0x0002 /* debug hardware initialization */
8792 +#define DBG_GADGET 0x0004 /* calls to/from gadget driver */
8793 +#define DBG_INT 0x0008 /* interrupts */
8794 +#define DBG_BUS 0x0010 /* report changes in bus state */
8795 +#define DBG_QUEUE 0x0020 /* debug request queue processing */
8796 +#define DBG_FIFO 0x0040 /* debug FIFO contents */
8797 +#define DBG_DMA 0x0080 /* debug DMA handling */
8798 +#define DBG_REQ 0x0100 /* print out queued request length */
8799 +#define DBG_ALL 0xffff
8800 +#define DBG_NONE 0x0000
8802 +#define DEBUG_LEVEL (DBG_ERR)
8803 +#define DBG(level, fmt, ...) \
8805 + if ((level) & DEBUG_LEVEL) \
8806 + printk(KERN_DEBUG "udc: " fmt, ## __VA_ARGS__); \
8809 +#define DBG(level, fmt...)
8812 +static struct usba_udc the_udc;
8814 +#ifdef CONFIG_DEBUG_FS
8815 +#include <linux/debugfs.h>
8816 +#include <linux/uaccess.h>
8818 +static int queue_dbg_open(struct inode *inode, struct file *file)
8820 + struct usba_ep *ep = inode->i_private;
8821 + struct usba_request *req, *req_copy;
8822 + struct list_head *queue_data;
8824 + queue_data = kmalloc(sizeof(*queue_data), GFP_KERNEL);
8827 + INIT_LIST_HEAD(queue_data);
8829 + spin_lock_irq(&ep->udc->lock);
8830 + list_for_each_entry(req, &ep->queue, queue) {
8831 + req_copy = kmalloc(sizeof(*req_copy), GFP_ATOMIC);
8834 + memcpy(req_copy, req, sizeof(*req_copy));
8835 + list_add_tail(&req_copy->queue, queue_data);
8837 + spin_unlock_irq(&ep->udc->lock);
8839 + file->private_data = queue_data;
8843 + spin_unlock_irq(&ep->udc->lock);
8844 + list_for_each_entry_safe(req, req_copy, queue_data, queue) {
8845 + list_del(&req->queue);
8848 + kfree(queue_data);
8853 + * bbbbbbbb llllllll IZS sssss nnnn FDL\n\0
8855 + * b: buffer address
8856 + * l: buffer length
8857 + * I/i: interrupt/no interrupt
8858 + * Z/z: zero/no zero
8859 + * S/s: short ok/short not ok
8862 + * F/f: submitted/not submitted to FIFO
8863 + * D/d: using/not using DMA
8864 + * L/l: last transaction/not last transaction
8866 +static ssize_t queue_dbg_read(struct file *file, char __user *buf,
8867 + size_t nbytes, loff_t *ppos)
8869 + struct list_head *queue = file->private_data;
8870 + struct usba_request *req, *tmp_req;
8871 + size_t len, remaining, actual = 0;
8874 + if (!access_ok(VERIFY_WRITE, buf, nbytes))
8877 + mutex_lock(&file->f_dentry->d_inode->i_mutex);
8878 + list_for_each_entry_safe(req, tmp_req, queue, queue) {
8879 + len = snprintf(tmpbuf, sizeof(tmpbuf),
8880 + "%8p %08x %c%c%c %5d %c%c%c\n",
8881 + req->req.buf, req->req.length,
8882 + req->req.no_interrupt ? 'i' : 'I',
8883 + req->req.zero ? 'Z' : 'z',
8884 + req->req.short_not_ok ? 's' : 'S',
8886 + req->submitted ? 'F' : 'f',
8887 + req->using_dma ? 'D' : 'd',
8888 + req->last_transaction ? 'L' : 'l');
8889 + len = min(len, sizeof(tmpbuf));
8893 + list_del(&req->queue);
8896 + remaining = __copy_to_user(buf, tmpbuf, len);
8897 + actual += len - remaining;
8904 + mutex_unlock(&file->f_dentry->d_inode->i_mutex);
8909 +static int queue_dbg_release(struct inode *inode, struct file *file)
8911 + struct list_head *queue_data = file->private_data;
8912 + struct usba_request *req, *tmp_req;
8914 + list_for_each_entry_safe(req, tmp_req, queue_data, queue) {
8915 + list_del(&req->queue);
8918 + kfree(queue_data);
8922 +static int regs_dbg_open(struct inode *inode, struct file *file)
8924 + struct usba_udc *udc;
8927 + int ret = -ENOMEM;
8929 + mutex_lock(&inode->i_mutex);
8930 + udc = inode->i_private;
8931 + data = kmalloc(inode->i_size, GFP_KERNEL);
8935 + spin_lock_irq(&udc->lock);
8936 + for (i = 0; i < inode->i_size / 4; i++)
8937 + data[i] = __raw_readl(udc->regs + i * 4);
8938 + spin_unlock_irq(&udc->lock);
8940 + file->private_data = data;
8944 + mutex_unlock(&inode->i_mutex);
8949 +static ssize_t regs_dbg_read(struct file *file, char __user *buf,
8950 + size_t nbytes, loff_t *ppos)
8952 + struct inode *inode = file->f_dentry->d_inode;
8955 + mutex_lock(&inode->i_mutex);
8956 + ret = simple_read_from_buffer(buf, nbytes, ppos,
8957 + file->private_data,
8958 + file->f_dentry->d_inode->i_size);
8959 + mutex_unlock(&inode->i_mutex);
8964 +static int regs_dbg_release(struct inode *inode, struct file *file)
8966 + kfree(file->private_data);
8970 +const struct file_operations queue_dbg_fops = {
8971 + .owner = THIS_MODULE,
8972 + .open = queue_dbg_open,
8973 + .llseek = no_llseek,
8974 + .read = queue_dbg_read,
8975 + .release = queue_dbg_release,
8978 +const struct file_operations regs_dbg_fops = {
8979 + .owner = THIS_MODULE,
8980 + .open = regs_dbg_open,
8981 + .llseek = generic_file_llseek,
8982 + .read = regs_dbg_read,
8983 + .release = regs_dbg_release,
8986 +static void usba_ep_init_debugfs(struct usba_udc *udc,
8987 + struct usba_ep *ep)
8989 + struct dentry *ep_root;
8991 + ep_root = debugfs_create_dir(ep_name(ep), udc->debugfs_root);
8994 + ep->debugfs_dir = ep_root;
8996 + ep->debugfs_queue = debugfs_create_file("queue", 0400, ep_root,
8997 + ep, &queue_dbg_fops);
8998 + if (!ep->debugfs_queue)
9001 + if (ep_can_dma(ep)) {
9002 + ep->debugfs_dma_status
9003 + = debugfs_create_u32("dma_status", 0400, ep_root,
9004 + &ep->last_dma_status);
9005 + if (!ep->debugfs_dma_status)
9006 + goto err_dma_status;
9008 + if (ep_is_control(ep)) {
9010 + = debugfs_create_u32("state", 0400, ep_root,
9012 + if (!ep->debugfs_state)
9019 + if (ep_can_dma(ep))
9020 + debugfs_remove(ep->debugfs_dma_status);
9022 + debugfs_remove(ep->debugfs_queue);
9024 + debugfs_remove(ep_root);
9026 + dev_err(&ep->udc->pdev->dev,
9027 + "failed to create debugfs directory for %s\n", ep_name(ep));
9030 +static void usba_ep_cleanup_debugfs(struct usba_ep *ep)
9032 + debugfs_remove(ep->debugfs_queue);
9033 + debugfs_remove(ep->debugfs_dma_status);
9034 + debugfs_remove(ep->debugfs_state);
9035 + debugfs_remove(ep->debugfs_dir);
9036 + ep->debugfs_dma_status = NULL;
9037 + ep->debugfs_dir = NULL;
9040 +static void usba_init_debugfs(struct usba_udc *udc)
9042 + struct dentry *root, *regs;
9043 + struct resource *regs_resource;
9045 + root = debugfs_create_dir(udc->gadget.name, NULL);
9046 + if (IS_ERR(root) || !root)
9048 + udc->debugfs_root = root;
9050 + regs = debugfs_create_file("regs", 0400, root, udc, ®s_dbg_fops);
9054 + regs_resource = platform_get_resource(udc->pdev, IORESOURCE_MEM,
9056 + regs->d_inode->i_size = regs_resource->end - regs_resource->start + 1;
9057 + udc->debugfs_regs = regs;
9059 + usba_ep_init_debugfs(udc, to_usba_ep(udc->gadget.ep0));
9064 + debugfs_remove(root);
9066 + udc->debugfs_root = NULL;
9067 + dev_err(&udc->pdev->dev, "debugfs is not available\n");
9070 +static void usba_cleanup_debugfs(struct usba_udc *udc)
9072 + usba_ep_cleanup_debugfs(to_usba_ep(udc->gadget.ep0));
9073 + debugfs_remove(udc->debugfs_regs);
9074 + debugfs_remove(udc->debugfs_root);
9075 + udc->debugfs_regs = NULL;
9076 + udc->debugfs_root = NULL;
9079 +static inline void usba_ep_init_debugfs(struct usba_udc *udc,
9080 + struct usba_ep *ep)
9085 +static inline void usba_ep_cleanup_debugfs(struct usba_ep *ep)
9090 +static inline void usba_init_debugfs(struct usba_udc *udc)
9095 +static inline void usba_cleanup_debugfs(struct usba_udc *udc)
9101 +static int vbus_is_present(struct usba_udc *udc)
9103 + if (udc->vbus_pin != -1)
9104 + return gpio_get_value(udc->vbus_pin);
9106 + /* No Vbus detection: Assume always present */
9110 +static void copy_to_fifo(void __iomem *fifo, const void *buf, int len)
9112 + unsigned long tmp;
9114 + DBG(DBG_FIFO, "copy to FIFO (len %d):\n", len);
9115 + for (; len > 0; len -= 4, buf += 4, fifo += 4) {
9116 + tmp = *(unsigned long *)buf;
9118 + DBG(DBG_FIFO, " -> %08lx\n", tmp);
9119 + __raw_writel(tmp, fifo);
9122 + DBG(DBG_FIFO, " -> %02lx\n", tmp >> 24);
9123 + __raw_writeb(tmp >> 24, fifo);
9132 +static void copy_from_fifo(void *buf, void __iomem *fifo, int len)
9138 + unsigned long tmp;
9140 + DBG(DBG_FIFO, "copy from FIFO (len %d):\n", len);
9141 + for (p.w = buf; len > 0; len -= 4, p.w++, fifo += 4) {
9143 + tmp = __raw_readl(fifo);
9145 + DBG(DBG_FIFO, " -> %08lx\n", tmp);
9148 + tmp = __raw_readb(fifo);
9150 + DBG(DBG_FIFO, " -> %02lx\n", tmp);
9157 +static void next_fifo_transaction(struct usba_ep *ep,
9158 + struct usba_request *req)
9160 + unsigned int transaction_len;
9162 + transaction_len = req->req.length - req->req.actual;
9163 + req->last_transaction = 1;
9164 + if (transaction_len > ep->ep.maxpacket) {
9165 + transaction_len = ep->ep.maxpacket;
9166 + req->last_transaction = 0;
9167 + } else if (transaction_len == ep->ep.maxpacket
9168 + && req->req.zero) {
9169 + req->last_transaction = 0;
9171 + DBG(DBG_QUEUE, "%s: submit_transaction, req %p (length %d)%s\n",
9172 + ep_name(ep), req, transaction_len,
9173 + req->last_transaction ? ", done" : "");
9175 + copy_to_fifo(ep->fifo, req->req.buf + req->req.actual, transaction_len);
9176 + usba_ep_writel(ep, SET_STA, USBA_BIT(TX_PK_RDY));
9177 + req->req.actual += transaction_len;
9180 +static void submit_request(struct usba_ep *ep, struct usba_request *req)
9182 + DBG(DBG_QUEUE, "%s: submit_request: req %p (length %d)\n",
9183 + ep_name(ep), req, req->req.length);
9185 + req->req.actual = 0;
9186 + req->submitted = 1;
9188 + if (req->using_dma) {
9189 + if (req->req.length == 0) {
9190 + usba_ep_writel(ep, CTL_ENB, USBA_BIT(TX_PK_RDY));
9194 + if (req->req.zero)
9195 + usba_ep_writel(ep, CTL_ENB, USBA_BIT(SHORT_PACKET));
9197 + usba_ep_writel(ep, CTL_DIS, USBA_BIT(SHORT_PACKET));
9199 + usba_dma_writel(ep, ADDRESS, req->req.dma);
9200 + usba_dma_writel(ep, CONTROL, req->ctrl);
9202 + next_fifo_transaction(ep, req);
9203 + if (req->last_transaction) {
9204 + usba_ep_writel(ep, CTL_DIS, USBA_BIT(TX_PK_RDY));
9205 + usba_ep_writel(ep, CTL_ENB, USBA_BIT(TX_COMPLETE));
9207 + usba_ep_writel(ep, CTL_DIS, USBA_BIT(TX_COMPLETE));
9208 + usba_ep_writel(ep, CTL_ENB, USBA_BIT(TX_PK_RDY));
9213 +static void submit_next_request(struct usba_ep *ep)
9215 + struct usba_request *req;
9217 + if (list_empty(&ep->queue)) {
9218 + usba_ep_writel(ep, CTL_DIS, (USBA_BIT(TX_PK_RDY)
9219 + | USBA_BIT(RX_BK_RDY)));
9223 + req = list_entry(ep->queue.next, struct usba_request, queue);
9224 + if (!req->submitted)
9225 + submit_request(ep, req);
9228 +static void send_status(struct usba_udc *udc, struct usba_ep *ep)
9230 + ep->state = STATUS_STAGE_IN;
9231 + usba_ep_writel(ep, SET_STA, USBA_BIT(TX_PK_RDY));
9232 + usba_ep_writel(ep, CTL_ENB, USBA_BIT(TX_COMPLETE));
9235 +static void receive_data(struct usba_ep *ep)
9237 + struct usba_udc *udc = ep->udc;
9238 + struct usba_request *req;
9239 + unsigned long status;
9240 + unsigned int bytecount, nr_busy;
9241 + int is_complete = 0;
9243 + status = usba_ep_readl(ep, STA);
9244 + nr_busy = USBA_BFEXT(BUSY_BANKS, status);
9246 + DBG(DBG_QUEUE, "receive data: nr_busy=%u\n", nr_busy);
9248 + while (nr_busy > 0) {
9249 + if (list_empty(&ep->queue)) {
9250 + usba_ep_writel(ep, CTL_DIS, USBA_BIT(RX_BK_RDY));
9253 + req = list_entry(ep->queue.next,
9254 + struct usba_request, queue);
9256 + bytecount = USBA_BFEXT(BYTE_COUNT, status);
9258 + if (status & (1 << 31))
9260 + if (req->req.actual + bytecount >= req->req.length) {
9262 + bytecount = req->req.length - req->req.actual;
9265 + copy_from_fifo(req->req.buf + req->req.actual,
9266 + ep->fifo, bytecount);
9267 + req->req.actual += bytecount;
9269 + usba_ep_writel(ep, CLR_STA, USBA_BIT(RX_BK_RDY));
9271 + if (is_complete) {
9272 + DBG(DBG_QUEUE, "%s: request done\n", ep_name(ep));
9273 + req->req.status = 0;
9274 + list_del_init(&req->queue);
9275 + usba_ep_writel(ep, CTL_DIS, USBA_BIT(RX_BK_RDY));
9276 + req->req.complete(&ep->ep, &req->req);
9279 + status = usba_ep_readl(ep, STA);
9280 + nr_busy = USBA_BFEXT(BUSY_BANKS, status);
9282 + if (is_complete && ep_is_control(ep)) {
9283 + send_status(udc, ep);
9289 +static void request_complete(struct usba_ep *ep,
9290 + struct usba_request *req,
9293 + struct usba_udc *udc = ep->udc;
9295 + WARN_ON(!list_empty(&req->queue));
9297 + if (req->req.status == -EINPROGRESS)
9298 + req->req.status = status;
9300 + if (req->mapped) {
9302 + &udc->pdev->dev, req->req.dma, req->req.length,
9303 + ep_is_in(ep) ? DMA_TO_DEVICE : DMA_FROM_DEVICE);
9304 + req->req.dma = DMA_ADDR_INVALID;
9308 + DBG(DBG_GADGET | DBG_REQ,
9309 + "%s: req %p complete: status %d, actual %u\n",
9310 + ep_name(ep), req, req->req.status, req->req.actual);
9311 + req->req.complete(&ep->ep, &req->req);
9314 +static void request_complete_list(struct usba_ep *ep,
9315 + struct list_head *list,
9318 + struct usba_request *req, *tmp_req;
9320 + list_for_each_entry_safe(req, tmp_req, list, queue) {
9321 + list_del_init(&req->queue);
9322 + request_complete(ep, req, status);
9326 +static int usba_ep_enable(struct usb_ep *_ep,
9327 + const struct usb_endpoint_descriptor *desc)
9329 + struct usba_ep *ep = to_usba_ep(_ep);
9330 + struct usba_udc *udc = ep->udc;
9331 + unsigned long flags, ept_cfg, maxpacket;
9333 + DBG(DBG_GADGET, "%s: ep_enable: desc=%p\n", ep_name(ep), desc);
9335 + maxpacket = le16_to_cpu(desc->wMaxPacketSize);
9337 + if (ep->index == 0
9338 + || desc->bDescriptorType != USB_DT_ENDPOINT
9339 + || ((desc->bEndpointAddress & USB_ENDPOINT_NUMBER_MASK)
9342 + || maxpacket > ep->fifo_size) {
9343 + DBG(DBG_ERR, "ep_enable: Invalid argument");
9350 + if ((desc->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK)
9351 + == USB_ENDPOINT_XFER_ISOC) {
9352 + if (!ep->can_isoc) {
9353 + DBG(DBG_ERR, "ep_enable: %s is not isoc capable\n",
9360 + if (maxpacket <= 8)
9361 + ept_cfg = USBA_BF(EPT_SIZE, USBA_EPT_SIZE_8);
9363 + /* LSB is bit 1, not 0 */
9364 + ept_cfg = USBA_BF(EPT_SIZE, fls(maxpacket - 1) - 3);
9365 + DBG(DBG_HW, "%s: EPT_SIZE = %lu (maxpacket = %lu)\n",
9366 + ep_name(ep), ept_cfg, maxpacket);
9368 + if ((desc->bEndpointAddress & USB_ENDPOINT_DIR_MASK) == USB_DIR_IN) {
9370 + ept_cfg |= USBA_BIT(EPT_DIR);
9373 + switch (desc->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) {
9374 + case USB_ENDPOINT_XFER_CONTROL:
9375 + ept_cfg |= USBA_BF(EPT_TYPE, USBA_EPT_TYPE_CONTROL);
9377 + case USB_ENDPOINT_XFER_ISOC:
9378 + ept_cfg |= USBA_BF(EPT_TYPE, USBA_EPT_TYPE_ISO);
9380 + case USB_ENDPOINT_XFER_BULK:
9381 + ept_cfg |= USBA_BF(EPT_TYPE, USBA_EPT_TYPE_BULK);
9383 + case USB_ENDPOINT_XFER_INT:
9384 + ept_cfg |= USBA_BF(EPT_TYPE, USBA_EPT_TYPE_INT);
9387 + ept_cfg |= USBA_BF(BK_NUMBER, ep->nr_banks);
9389 + spin_lock_irqsave(&ep->udc->lock, flags);
9392 + spin_unlock_irqrestore(&ep->udc->lock, flags);
9393 + DBG(DBG_ERR, "ep%d already enabled\n", ep->index);
9398 + ep->ep.maxpacket = maxpacket;
9400 + usba_ep_writel(ep, CFG, ept_cfg);
9401 + usba_ep_writel(ep, CTL_ENB, USBA_BIT(EPT_ENABLE));
9403 + if (ep_can_dma(ep)) {
9406 + usba_writel(udc, INT_ENB,
9407 + (usba_readl(udc, INT_ENB)
9408 + | USBA_BF(EPT_INT, 1 << ep->index)
9409 + | USBA_BF(DMA_INT, 1 << ep->index)));
9410 + ctrl = USBA_BIT(AUTO_VALID) | USBA_BIT(INTDIS_DMA);
9411 + usba_ep_writel(ep, CTL_ENB, ctrl);
9413 + usba_writel(udc, INT_ENB,
9414 + (usba_readl(udc, INT_ENB)
9415 + | USBA_BF(EPT_INT, 1 << ep->index)));
9418 + spin_unlock_irqrestore(&udc->lock, flags);
9420 + DBG(DBG_HW, "EPT_CFG%d after init: %#08lx\n", ep->index,
9421 + (unsigned long)usba_ep_readl(ep, CFG));
9422 + DBG(DBG_HW, "INT_ENB after init: %#08lx\n",
9423 + (unsigned long)usba_readl(udc, INT_ENB));
9428 +static int usba_ep_disable(struct usb_ep *_ep)
9430 + struct usba_ep *ep = to_usba_ep(_ep);
9431 + struct usba_udc *udc = ep->udc;
9432 + LIST_HEAD(req_list);
9433 + unsigned long flags;
9435 + DBG(DBG_GADGET, "ep_disable: %s\n", ep_name(ep));
9437 + spin_lock_irqsave(&udc->lock, flags);
9440 + spin_unlock_irqrestore(&udc->lock, flags);
9441 + DBG(DBG_ERR, "ep_disable: %s not enabled\n",
9447 + list_splice_init(&ep->queue, &req_list);
9448 + if (ep_can_dma(ep)) {
9449 + usba_dma_writel(ep, CONTROL, 0);
9450 + usba_dma_writel(ep, ADDRESS, 0);
9451 + usba_dma_readl(ep, STATUS);
9453 + usba_ep_writel(ep, CTL_DIS, USBA_BIT(EPT_ENABLE));
9454 + usba_writel(udc, INT_ENB, (usba_readl(udc, INT_ENB)
9455 + & ~USBA_BF(EPT_INT, 1 << ep->index)));
9457 + spin_unlock_irqrestore(&udc->lock, flags);
9459 + request_complete_list(ep, &req_list, -ESHUTDOWN);
9464 +static struct usb_request *
9465 +usba_ep_alloc_request(struct usb_ep *_ep, unsigned gfp_flags)
9467 + struct usba_request *req;
9469 + DBG(DBG_GADGET, "ep_alloc_request: %p, 0x%x\n", _ep, gfp_flags);
9471 + req = kzalloc(sizeof(*req), gfp_flags);
9475 + INIT_LIST_HEAD(&req->queue);
9476 + req->req.dma = DMA_ADDR_INVALID;
9482 +usba_ep_free_request(struct usb_ep *_ep, struct usb_request *_req)
9484 + struct usba_request *req = to_usba_req(_req);
9486 + DBG(DBG_GADGET, "ep_free_request: %p, %p\n", _ep, _req);
9491 +static void *usba_ep_alloc_buffer(struct usb_ep *_ep, unsigned bytes,
9492 + dma_addr_t *dma, unsigned gfp_flags)
9496 + if (bytes < L1_CACHE_BYTES)
9497 + bytes = L1_CACHE_BYTES;
9499 + buf = kmalloc(bytes, gfp_flags);
9502 + * Seems like we have to map the buffer any chance we get.
9503 + * ether.c wants us to initialize the dma member of a
9504 + * different request than the one receiving the buffer, so one
9507 + * Ah, screw it. The ether driver is probably wrong, and this
9508 + * is not the right place to do the mapping. The driver
9509 + * shouldn't mess with our DMA mappings anyway.
9511 + *dma = DMA_ADDR_INVALID;
9516 +static void usba_ep_free_buffer(struct usb_ep *_ep, void *buf,
9517 + dma_addr_t dma, unsigned bytes)
9519 + DBG(DBG_GADGET, "ep_free_buffer: %s, buf %p (size %u)\n",
9520 + _ep->name, buf, bytes);
9524 +static int queue_dma(struct usba_udc *udc, struct usba_ep *ep,
9525 + struct usba_request *req, gfp_t gfp_flags)
9527 + unsigned long flags;
9530 + DBG(DBG_DMA, "%s: req l/%u d/%08x %c%c%c\n",
9531 + ep_name(ep), req->req.length, req->req.dma,
9532 + req->req.zero ? 'Z' : 'z',
9533 + req->req.short_not_ok ? 'S' : 's',
9534 + req->req.no_interrupt ? 'I' : 'i');
9536 + if (req->req.length > 0x10000) {
9537 + /* Lengths from 0 to 65536 (inclusive) are supported */
9538 + DBG(DBG_ERR, "invalid request length %u\n", req->req.length);
9542 + req->using_dma = 1;
9544 + if (req->req.dma == DMA_ADDR_INVALID) {
9545 + req->req.dma = dma_map_single(
9546 + &udc->pdev->dev, req->req.buf, req->req.length,
9547 + ep_is_in(ep) ? DMA_TO_DEVICE : DMA_FROM_DEVICE);
9550 + dma_sync_single_for_device(
9551 + &udc->pdev->dev, req->req.dma, req->req.length,
9552 + ep_is_in(ep) ? DMA_TO_DEVICE : DMA_FROM_DEVICE);
9556 + req->ctrl = (USBA_BF(DMA_BUF_LEN, req->req.length)
9557 + | USBA_BIT(DMA_CH_EN) | USBA_BIT(DMA_END_BUF_IE)
9558 + | USBA_BIT(DMA_END_TR_EN) | USBA_BIT(DMA_END_TR_IE));
9561 + req->ctrl |= USBA_BIT(DMA_END_BUF_EN);
9564 + * Add this request to the queue and submit for DMA if
9565 + * possible. Check if we're still alive first -- we may have
9566 + * received a reset since last time we checked.
9569 + spin_lock_irqsave(&udc->lock, flags);
9571 + if (list_empty(&ep->queue))
9572 + submit_request(ep, req);
9574 + list_add_tail(&req->queue, &ep->queue);
9577 + spin_unlock_irqrestore(&udc->lock, flags);
9582 +static int usba_ep_queue(struct usb_ep *_ep, struct usb_request *_req,
9585 + struct usba_request *req = to_usba_req(_req);
9586 + struct usba_ep *ep = to_usba_ep(_ep);
9587 + struct usba_udc *udc = ep->udc;
9588 + unsigned long flags;
9591 + DBG(DBG_GADGET | DBG_QUEUE | DBG_REQ,
9592 + "%s: queue req %p, len %u\n", ep_name(ep), req, _req->length);
9594 + if (!udc->driver || udc->gadget.speed == USB_SPEED_UNKNOWN
9596 + return -ESHUTDOWN;
9598 + req->submitted = 0;
9599 + req->using_dma = 0;
9600 + req->last_transaction = 0;
9602 + _req->status = -EINPROGRESS;
9605 + if (ep_can_dma(ep))
9606 + return queue_dma(udc, ep, req, gfp_flags);
9608 + /* May have received a reset since last time we checked */
9610 + spin_lock_irqsave(&udc->lock, flags);
9612 + list_add_tail(&req->queue, &ep->queue);
9615 + || (ep_is_control(ep)
9616 + && (ep->state == DATA_STAGE_IN
9617 + || ep->state == STATUS_STAGE_IN)))
9618 + usba_ep_writel(ep, CTL_ENB, USBA_BIT(TX_PK_RDY));
9620 + usba_ep_writel(ep, CTL_ENB, USBA_BIT(RX_BK_RDY));
9623 + spin_unlock_irqrestore(&udc->lock, flags);
9628 +static void usba_update_req(struct usba_ep *ep, struct usba_request *req,
9631 + req->req.actual = req->req.length - USBA_BFEXT(DMA_BUF_LEN, status);
9634 +static int stop_dma(struct usba_ep *ep, u32 *pstatus)
9636 + unsigned int timeout;
9640 + * Stop the DMA controller. When writing both CH_EN
9641 + * and LINK to 0, the other bits are not affected.
9643 + usba_dma_writel(ep, CONTROL, 0);
9645 + /* Wait for the FIFO to empty */
9646 + for (timeout = 40; timeout; --timeout) {
9647 + status = usba_dma_readl(ep, STATUS);
9648 + if (!(status & USBA_BIT(DMA_CH_EN)))
9654 + *pstatus = status;
9656 + if (timeout == 0) {
9657 + dev_err(&ep->udc->pdev->dev,
9658 + "%s: timed out waiting for DMA FIFO to empty\n",
9660 + return -ETIMEDOUT;
9666 +static int usba_ep_dequeue(struct usb_ep *_ep, struct usb_request *_req)
9668 + struct usba_ep *ep = to_usba_ep(_ep);
9669 + struct usba_udc *udc = ep->udc;
9670 + struct usba_request *req = to_usba_req(_req);
9671 + unsigned long flags;
9674 + DBG(DBG_GADGET | DBG_QUEUE, "ep_dequeue: %s, req %p\n",
9675 + ep_name(ep), req);
9677 + spin_lock_irqsave(&udc->lock, flags);
9679 + if (req->using_dma) {
9681 + * If this request is currently being transferred,
9682 + * stop the DMA controller and reset the FIFO.
9684 + if (ep->queue.next == &req->queue) {
9685 + status = usba_dma_readl(ep, STATUS);
9686 + if (status & USBA_BIT(DMA_CH_EN))
9687 + stop_dma(ep, &status);
9689 +#ifdef CONFIG_DEBUG_FS
9690 + ep->last_dma_status = status;
9693 + usba_writel(udc, EPT_RST,
9694 + 1 << ep_index(ep));
9696 + usba_update_req(ep, req, status);
9701 + * Errors should stop the queue from advancing until the
9702 + * completion function returns.
9704 + list_del_init(&req->queue);
9705 + spin_unlock_irqrestore(&udc->lock, flags);
9707 + request_complete(ep, req, -ECONNRESET);
9709 + /* Process the next request if any */
9710 + spin_lock_irqsave(&udc->lock, flags);
9711 + submit_next_request(ep);
9712 + spin_unlock_irqrestore(&udc->lock, flags);
9717 +static int usba_ep_set_halt(struct usb_ep *_ep, int value)
9719 + struct usba_ep *ep = to_usba_ep(_ep);
9720 + struct usba_udc *udc = ep->udc;
9721 + unsigned long flags;
9724 + DBG(DBG_GADGET, "endpoint %s: %s HALT\n", ep_name(ep),
9725 + value ? "set" : "clear");
9728 + DBG(DBG_ERR, "Attempted to halt uninitialized ep %s\n",
9732 + if (ep_is_isochronous(ep)) {
9733 + DBG(DBG_ERR, "Attempted to halt isochronous ep %s\n",
9738 + spin_lock_irqsave(&udc->lock, flags);
9741 + * We can't halt IN endpoints while there are still data to be
9744 + if (!list_empty(&ep->queue)
9745 + || ((value && ep_is_in(ep)
9746 + && (usba_ep_readl(ep, STA)
9747 + & USBA_BF(BUSY_BANKS, -1L))))) {
9751 + usba_ep_writel(ep, SET_STA, USBA_BIT(FORCE_STALL));
9753 + usba_ep_writel(ep, CLR_STA, (USBA_BIT(FORCE_STALL)
9754 + | USBA_BIT(TOGGLE_SEQ)));
9755 + usba_ep_readl(ep, STA);
9758 + spin_unlock_irqrestore(&udc->lock, flags);
9763 +static int usba_ep_fifo_status(struct usb_ep *_ep)
9765 + struct usba_ep *ep = to_usba_ep(_ep);
9767 + return USBA_BFEXT(BYTE_COUNT, usba_ep_readl(ep, STA));
9770 +static void usba_ep_fifo_flush(struct usb_ep *_ep)
9772 + struct usba_ep *ep = to_usba_ep(_ep);
9773 + struct usba_udc *udc = ep->udc;
9775 + usba_writel(udc, EPT_RST, 1 << ep->index);
9778 +struct usb_ep_ops usba_ep_ops = {
9779 + .enable = usba_ep_enable,
9780 + .disable = usba_ep_disable,
9781 + .alloc_request = usba_ep_alloc_request,
9782 + .free_request = usba_ep_free_request,
9783 + .alloc_buffer = usba_ep_alloc_buffer,
9784 + .free_buffer = usba_ep_free_buffer,
9785 + .queue = usba_ep_queue,
9786 + .dequeue = usba_ep_dequeue,
9787 + .set_halt = usba_ep_set_halt,
9788 + .fifo_status = usba_ep_fifo_status,
9789 + .fifo_flush = usba_ep_fifo_flush,
9792 +static int usba_udc_get_frame(struct usb_gadget *gadget)
9794 + struct usba_udc *udc = to_usba_udc(gadget);
9796 + return USBA_BFEXT(FRAME_NUMBER, usba_readl(udc, FNUM));
9799 +struct usb_gadget_ops usba_udc_ops = {
9800 + .get_frame = usba_udc_get_frame,
9803 +#define EP(nam, type, idx, dma, isoc) \
9806 + .ops = &usba_ep_ops, \
9808 + .maxpacket = type##_FIFO_SIZE, \
9810 + .udc = &the_udc, \
9811 + .queue = LIST_HEAD_INIT(usba_ep[idx].queue), \
9812 + .fifo_size = type##_FIFO_SIZE, \
9813 + .nr_banks = type##_NR_BANKS, \
9816 + .can_isoc = isoc, \
9819 +static struct usba_ep usba_ep[] = {
9820 + EP("ep0", EP0, 0, 0, 0),
9821 + EP("ep1in-bulk", BULK, 1, 1, 0),
9822 + EP("ep2out-bulk", BULK, 2, 1, 0),
9823 + EP("ep3in-iso", ISO, 3, 1, 1),
9824 + EP("ep4out-iso", ISO, 4, 1, 1),
9825 + EP("ep5in-int", INT, 5, 1, 0),
9826 + EP("ep6out-int", INT, 6, 1, 0),
9830 +static struct usb_endpoint_descriptor usba_ep0_desc = {
9831 + .bLength = USB_DT_ENDPOINT_SIZE,
9832 + .bDescriptorType = USB_DT_ENDPOINT,
9833 + .bEndpointAddress = 0,
9834 + .bmAttributes = USB_ENDPOINT_XFER_CONTROL,
9835 + .wMaxPacketSize = __constant_cpu_to_le16(64),
9836 + /* FIXME: I have no idea what to put here */
9840 +static void nop_release(struct device *dev)
9845 +static struct usba_udc the_udc = {
9847 + .ops = &usba_udc_ops,
9848 + .ep0 = &usba_ep[0].ep,
9849 + .ep_list = LIST_HEAD_INIT(the_udc.gadget.ep_list),
9850 + .is_dualspeed = 1,
9851 + .name = "atmel_usba_udc",
9853 + .bus_id = "gadget",
9854 + .release = nop_release,
9858 + .lock = SPIN_LOCK_UNLOCKED,
9862 + * Called with interrupts disabled and udc->lock held.
9864 +static void reset_all_endpoints(struct usba_udc *udc)
9866 + struct usba_ep *ep;
9867 + struct usba_request *req, *tmp_req;
9869 + usba_writel(udc, EPT_RST, ~0UL);
9871 + ep = to_usba_ep(udc->gadget.ep0);
9872 + list_for_each_entry_safe(req, tmp_req, &ep->queue, queue) {
9873 + list_del_init(&req->queue);
9874 + request_complete(ep, req, -ECONNRESET);
9877 + list_for_each_entry(ep, &udc->gadget.ep_list, ep.ep_list) {
9879 + usba_ep_disable(&ep->ep);
9883 +static struct usba_ep *get_ep_by_addr(struct usba_udc *udc, u16 wIndex)
9885 + struct usba_ep *ep;
9887 + if ((wIndex & USB_ENDPOINT_NUMBER_MASK) == 0)
9888 + return to_usba_ep(udc->gadget.ep0);
9890 + list_for_each_entry (ep, &udc->gadget.ep_list, ep.ep_list) {
9891 + u8 bEndpointAddress;
9895 + bEndpointAddress = ep->desc->bEndpointAddress;
9896 + if ((wIndex ^ bEndpointAddress) & USB_DIR_IN)
9898 + if ((wIndex & USB_ENDPOINT_NUMBER_MASK)
9899 + == (bEndpointAddress & USB_ENDPOINT_NUMBER_MASK))
9906 +/* Called with interrupts disabled and udc->lock held */
9907 +static inline void set_protocol_stall(struct usba_udc *udc,
9908 + struct usba_ep *ep)
9910 + usba_ep_writel(ep, SET_STA, USBA_BIT(FORCE_STALL));
9911 + ep->state = WAIT_FOR_SETUP;
9914 +static inline int is_stalled(struct usba_udc *udc, struct usba_ep *ep)
9916 + if (usba_ep_readl(ep, STA) & USBA_BIT(FORCE_STALL))
9921 +static inline void set_address(struct usba_udc *udc, unsigned int addr)
9925 + DBG(DBG_BUS, "setting address %u...\n", addr);
9926 + regval = usba_readl(udc, CTRL);
9927 + regval = USBA_BFINS(DEV_ADDR, addr, regval);
9928 + usba_writel(udc, CTRL, regval);
9931 +static int do_test_mode(struct usba_udc *udc)
9933 + static const char test_packet_buffer[] = {
9934 + /* JKJKJKJK * 9 */
9935 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
9936 + /* JJKKJJKK * 8 */
9937 + 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA,
9938 + /* JJKKJJKK * 8 */
9939 + 0xEE, 0xEE, 0xEE, 0xEE, 0xEE, 0xEE, 0xEE, 0xEE,
9940 + /* JJJJJJJKKKKKKK * 8 */
9941 + 0xFE, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
9942 + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
9943 + /* JJJJJJJK * 8 */
9944 + 0x7F, 0xBF, 0xDF, 0xEF, 0xF7, 0xFB, 0xFD,
9945 + /* {JKKKKKKK * 10}, JK */
9946 + 0xFC, 0x7E, 0xBF, 0xDF, 0xEF, 0xF7, 0xFB, 0xFD, 0x7E
9948 + struct device *dev = &udc->pdev->dev;
9949 + struct usba_ep *ep;
9952 + test_mode = udc->test_mode;
9954 + /* Start from a clean slate */
9955 + reset_all_endpoints(udc);
9957 + switch (test_mode) {
9960 + usba_writel(udc, TST, USBA_BIT(TST_J_MODE));
9961 + dev_info(dev, "Entering Test_J mode...\n");
9965 + usba_writel(udc, TST, USBA_BIT(TST_K_MODE));
9966 + dev_info(dev, "Entering Test_K mode...\n");
9970 + * Test_SE0_NAK: Force high-speed mode and set up ep0
9971 + * for Bulk IN transfers
9974 + usba_writel(udc, TST,
9975 + USBA_BF(SPEED_CFG, USBA_SPEED_CFG_FORCE_HIGH));
9976 + usba_ep_writel(ep, CFG,
9977 + USBA_BF(EPT_SIZE, USBA_EPT_SIZE_64)
9978 + | USBA_BIT(EPT_DIR)
9979 + | USBA_BF(EPT_TYPE, USBA_EPT_TYPE_BULK)
9980 + | USBA_BF(BK_NUMBER, 1));
9981 + if (!(usba_ep_readl(ep, CFG) & USBA_BIT(EPT_MAPPED))) {
9982 + set_protocol_stall(udc, ep);
9983 + dev_err(dev, "Test_SE0_NAK: ep0 not mapped\n");
9985 + usba_ep_writel(ep, CTL_ENB, USBA_BIT(EPT_ENABLE));
9986 + dev_info(dev, "Entering Test_SE0_NAK mode...\n");
9992 + usba_ep_writel(ep, CFG,
9993 + USBA_BF(EPT_SIZE, USBA_EPT_SIZE_64)
9994 + | USBA_BIT(EPT_DIR)
9995 + | USBA_BF(EPT_TYPE, USBA_EPT_TYPE_BULK)
9996 + | USBA_BF(BK_NUMBER, 1));
9997 + if (!(usba_ep_readl(ep, CFG) & USBA_BIT(EPT_MAPPED))) {
9998 + set_protocol_stall(udc, ep);
9999 + dev_err(dev, "Test_Packet: ep0 not mapped\n");
10001 + usba_ep_writel(ep, CTL_ENB, USBA_BIT(EPT_ENABLE));
10002 + usba_writel(udc, TST, USBA_BIT(TST_PKT_MODE));
10003 + copy_to_fifo(ep->fifo, test_packet_buffer,
10004 + sizeof(test_packet_buffer));
10005 + usba_ep_writel(ep, SET_STA, USBA_BIT(TX_PK_RDY));
10006 + dev_info(dev, "Entering Test_Packet mode...\n");
10010 + dev_err(dev, "Invalid test mode: 0x%04x\n", test_mode);
10017 +/* Avoid overly long expressions */
10018 +static inline bool feature_is_dev_remote_wakeup(struct usb_ctrlrequest *crq)
10020 + if (crq->wValue == __constant_cpu_to_le16(USB_DEVICE_REMOTE_WAKEUP))
10025 +static inline bool feature_is_dev_test_mode(struct usb_ctrlrequest *crq)
10027 + if (crq->wValue == __constant_cpu_to_le16(USB_DEVICE_TEST_MODE))
10032 +static inline bool feature_is_ep_halt(struct usb_ctrlrequest *crq)
10034 + if (crq->wValue == __constant_cpu_to_le16(USB_ENDPOINT_HALT))
10039 +static int handle_ep0_setup(struct usba_udc *udc, struct usba_ep *ep,
10040 + struct usb_ctrlrequest *crq)
10042 + switch (crq->bRequest) {
10043 + case USB_REQ_GET_STATUS: {
10046 + if (crq->bRequestType == (USB_DIR_IN | USB_RECIP_DEVICE)) {
10047 + /* Self-powered, no remote wakeup */
10048 + status = __constant_cpu_to_le16(1 << 0);
10049 + } else if (crq->bRequestType
10050 + == (USB_DIR_IN | USB_RECIP_INTERFACE)) {
10051 + status = __constant_cpu_to_le16(0);
10052 + } else if (crq->bRequestType
10053 + == (USB_DIR_IN | USB_RECIP_ENDPOINT)) {
10054 + struct usba_ep *target;
10056 + target = get_ep_by_addr(udc, le16_to_cpu(crq->wIndex));
10061 + if (is_stalled(udc, target))
10062 + status |= __constant_cpu_to_le16(1);
10067 + /* Write directly to the FIFO. No queueing is done. */
10068 + if (crq->wLength != __constant_cpu_to_le16(sizeof(status)))
10070 + ep->state = DATA_STAGE_IN;
10071 + __raw_writew(status, ep->fifo);
10072 + usba_ep_writel(ep, SET_STA, USBA_BIT(TX_PK_RDY));
10076 + case USB_REQ_CLEAR_FEATURE: {
10077 + if (crq->bRequestType == USB_RECIP_DEVICE) {
10078 + if (feature_is_dev_remote_wakeup(crq)) {
10079 + /* TODO: Handle REMOTE_WAKEUP */
10081 + /* Can't CLEAR_FEATURE TEST_MODE */
10084 + } else if (crq->bRequestType == USB_RECIP_ENDPOINT) {
10085 + struct usba_ep *target;
10087 + if (!feature_is_ep_halt(crq)
10088 + || crq->wLength != __constant_cpu_to_le16(0))
10090 + target = get_ep_by_addr(udc, le16_to_cpu(crq->wIndex));
10094 + usba_ep_writel(target, CLR_STA,
10095 + (USBA_BIT(FORCE_STALL)
10096 + | USBA_BIT(TOGGLE_SEQ)));
10101 + send_status(udc, ep);
10105 + case USB_REQ_SET_FEATURE: {
10106 + if (crq->bRequestType == USB_RECIP_DEVICE) {
10107 + if (feature_is_dev_test_mode(crq)) {
10108 + send_status(udc, ep);
10109 + ep->state = STATUS_STAGE_TEST;
10110 + udc->test_mode = le16_to_cpu(crq->wIndex);
10112 + } else if (feature_is_dev_remote_wakeup(crq)) {
10113 + /* TODO: Handle REMOTE_WAKEUP */
10117 + } else if (crq->bRequestType == USB_RECIP_ENDPOINT) {
10118 + struct usba_ep *target;
10120 + if (!feature_is_ep_halt(crq)
10121 + || crq->wLength != __constant_cpu_to_le16(0))
10124 + target = get_ep_by_addr(udc, le16_to_cpu(crq->wIndex));
10128 + usba_ep_writel(target, SET_STA, USBA_BIT(FORCE_STALL));
10132 + send_status(udc, ep);
10136 + case USB_REQ_SET_ADDRESS:
10137 + if (crq->bRequestType != (USB_DIR_OUT | USB_RECIP_DEVICE))
10140 + set_address(udc, le16_to_cpu(crq->wValue));
10141 + send_status(udc, ep);
10142 + ep->state = STATUS_STAGE_ADDR;
10147 + return udc->driver->setup(&udc->gadget, crq);
10154 + "udc: %s: Invalid setup request: %02x.%02x v%04x i%04x l%d, "
10155 + "halting endpoint...\n",
10156 + ep_name(ep), crq->bRequestType, crq->bRequest,
10157 + le16_to_cpu(crq->wValue), le16_to_cpu(crq->wIndex),
10158 + le16_to_cpu(crq->wLength));
10159 + set_protocol_stall(udc, ep);
10163 +static void usba_control_irq(struct usba_udc *udc, struct usba_ep *ep)
10165 + struct usba_request *req;
10170 + epstatus = usba_ep_readl(ep, STA);
10171 + epctrl = usba_ep_readl(ep, CTL);
10173 + DBG(DBG_INT, "%s [%d]: s/%08x c/%08x\n",
10174 + ep_name(ep), ep->state, epstatus, epctrl);
10177 + if (!list_empty(&ep->queue))
10178 + req = list_entry(ep->queue.next,
10179 + struct usba_request, queue);
10181 + if ((epctrl & USBA_BIT(TX_PK_RDY))
10182 + && !(epstatus & USBA_BIT(TX_PK_RDY))) {
10183 + if (req->submitted)
10184 + next_fifo_transaction(ep, req);
10186 + submit_request(ep, req);
10188 + if (req->last_transaction) {
10189 + usba_ep_writel(ep, CTL_DIS, USBA_BIT(TX_PK_RDY));
10190 + usba_ep_writel(ep, CTL_ENB, USBA_BIT(TX_COMPLETE));
10194 + if ((epstatus & epctrl) & USBA_BIT(TX_COMPLETE)) {
10195 + usba_ep_writel(ep, CLR_STA, USBA_BIT(TX_COMPLETE));
10197 + switch (ep->state) {
10198 + case DATA_STAGE_IN:
10199 + usba_ep_writel(ep, CTL_ENB, USBA_BIT(RX_BK_RDY));
10200 + usba_ep_writel(ep, CTL_DIS, USBA_BIT(TX_COMPLETE));
10201 + ep->state = STATUS_STAGE_OUT;
10203 + case STATUS_STAGE_ADDR:
10204 + /* Activate our new address */
10205 + usba_writel(udc, CTRL, (usba_readl(udc, CTRL)
10206 + | USBA_BIT(FADDR_EN)));
10207 + usba_ep_writel(ep, CTL_DIS, USBA_BIT(TX_COMPLETE));
10208 + ep->state = WAIT_FOR_SETUP;
10210 + case STATUS_STAGE_IN:
10212 + list_del_init(&req->queue);
10213 + request_complete(ep, req, 0);
10214 + submit_next_request(ep);
10216 + usba_ep_writel(ep, CTL_DIS, USBA_BIT(TX_COMPLETE));
10217 + ep->state = WAIT_FOR_SETUP;
10219 + case STATUS_STAGE_TEST:
10220 + usba_ep_writel(ep, CTL_DIS, USBA_BIT(TX_COMPLETE));
10221 + ep->state = WAIT_FOR_SETUP;
10222 + if (do_test_mode(udc))
10223 + set_protocol_stall(udc, ep);
10227 + "udc: %s: TXCOMP: Invalid endpoint state %d, "
10228 + "halting endpoint...\n",
10229 + ep_name(ep), ep->state);
10230 + set_protocol_stall(udc, ep);
10236 + if ((epstatus & epctrl) & USBA_BIT(RX_BK_RDY)) {
10237 + switch (ep->state) {
10238 + case STATUS_STAGE_OUT:
10239 + usba_ep_writel(ep, CLR_STA, USBA_BIT(RX_BK_RDY));
10240 + usba_ep_writel(ep, CTL_DIS, USBA_BIT(RX_BK_RDY));
10243 + list_del_init(&req->queue);
10244 + request_complete(ep, req, 0);
10246 + ep->state = WAIT_FOR_SETUP;
10249 + case DATA_STAGE_OUT:
10250 + receive_data(ep);
10254 + usba_ep_writel(ep, CLR_STA, USBA_BIT(RX_BK_RDY));
10255 + usba_ep_writel(ep, CTL_DIS, USBA_BIT(RX_BK_RDY));
10257 + "udc: %s: RXRDY: Invalid endpoint state %d, "
10258 + "halting endpoint...\n",
10259 + ep_name(ep), ep->state);
10260 + set_protocol_stall(udc, ep);
10266 + if (epstatus & USBA_BIT(RX_SETUP)) {
10268 + struct usb_ctrlrequest crq;
10269 + unsigned long data[2];
10271 + unsigned int pkt_len;
10274 + if (ep->state != WAIT_FOR_SETUP) {
10276 + * Didn't expect a SETUP packet at this
10277 + * point. Clean up any pending requests (which
10278 + * may be successful).
10280 + int status = -EPROTO;
10283 + * RXRDY and TXCOMP are dropped when SETUP
10284 + * packets arrive. Just pretend we received
10285 + * the status packet.
10287 + if (ep->state == STATUS_STAGE_OUT
10288 + || ep->state == STATUS_STAGE_IN) {
10289 + usba_ep_writel(ep, CTL_DIS,
10290 + USBA_BIT(RX_BK_RDY));
10295 + list_del_init(&req->queue);
10296 + request_complete(ep, req, status);
10300 + pkt_len = USBA_BFEXT(BYTE_COUNT, usba_ep_readl(ep, STA));
10301 + DBG(DBG_HW, "Packet length: %u\n", pkt_len);
10302 + if (pkt_len != sizeof(crq)) {
10303 + printk(KERN_WARNING
10304 + "udc: Invalid packet length %u (expected %lu)\n",
10305 + pkt_len, sizeof(crq));
10306 + set_protocol_stall(udc, ep);
10310 + DBG(DBG_FIFO, "Copying ctrl request from 0x%p:\n", ep->fifo);
10311 + copy_from_fifo(crq.data, ep->fifo, sizeof(crq));
10313 + /* Free up one bank in the FIFO so that we can
10314 + * generate or receive a reply right away. */
10315 + usba_ep_writel(ep, CLR_STA, USBA_BIT(RX_SETUP));
10317 + /* printk(KERN_DEBUG "setup: %d: %02x.%02x\n",
10318 + ep->state, crq.crq.bRequestType,
10319 + crq.crq.bRequest); */
10321 + if (crq.crq.bRequestType & USB_DIR_IN) {
10323 + * The USB 2.0 spec states that "if wLength is
10324 + * zero, there is no data transfer phase."
10325 + * However, testusb #14 seems to actually
10326 + * expect a data phase even if wLength = 0...
10328 + ep->state = DATA_STAGE_IN;
10330 + if (crq.crq.wLength != __constant_cpu_to_le16(0))
10331 + ep->state = DATA_STAGE_OUT;
10333 + ep->state = STATUS_STAGE_IN;
10337 + if (ep->index == 0)
10338 + ret = handle_ep0_setup(udc, ep, &crq.crq);
10340 + ret = udc->driver->setup(&udc->gadget, &crq.crq);
10342 + DBG(DBG_BUS, "req %02x.%02x, length %d, state %d, ret %d\n",
10343 + crq.crq.bRequestType, crq.crq.bRequest,
10344 + le16_to_cpu(crq.crq.wLength), ep->state, ret);
10347 + /* Let the host know that we failed */
10348 + set_protocol_stall(udc, ep);
10353 +static void usba_ep_irq(struct usba_udc *udc, struct usba_ep *ep)
10355 + struct usba_request *req;
10359 + epstatus = usba_ep_readl(ep, STA);
10360 + epctrl = usba_ep_readl(ep, CTL);
10362 + DBG(DBG_INT, "%s: interrupt, status: 0x%08x\n",
10363 + ep_name(ep), epstatus);
10365 + while ((epctrl & USBA_BIT(TX_PK_RDY))
10366 + && !(epstatus & USBA_BIT(TX_PK_RDY))) {
10367 + DBG(DBG_BUS, "%s: TX PK ready\n", ep_name(ep));
10369 + if (list_empty(&ep->queue)) {
10370 + dev_warn(&udc->pdev->dev, "ep_irq: queue empty\n");
10371 + usba_ep_writel(ep, CTL_DIS, USBA_BIT(TX_PK_RDY));
10375 + req = list_entry(ep->queue.next, struct usba_request, queue);
10377 + if (req->using_dma) {
10378 + /* Send a zero-length packet */
10379 + usba_ep_writel(ep, SET_STA,
10380 + USBA_BIT(TX_PK_RDY));
10381 + usba_ep_writel(ep, CTL_DIS,
10382 + USBA_BIT(TX_PK_RDY));
10383 + list_del_init(&req->queue);
10384 + submit_next_request(ep);
10385 + request_complete(ep, req, 0);
10387 + if (req->submitted)
10388 + next_fifo_transaction(ep, req);
10390 + submit_request(ep, req);
10392 + if (req->last_transaction) {
10393 + list_del_init(&req->queue);
10394 + submit_next_request(ep);
10395 + request_complete(ep, req, 0);
10399 + epstatus = usba_ep_readl(ep, STA);
10400 + epctrl = usba_ep_readl(ep, CTL);
10402 + if ((epstatus & epctrl) & USBA_BIT(RX_BK_RDY)) {
10403 + DBG(DBG_BUS, "%s: RX data ready\n", ep_name(ep));
10404 + receive_data(ep);
10405 + usba_ep_writel(ep, CLR_STA, USBA_BIT(RX_BK_RDY));
10409 +static void usba_dma_irq(struct usba_udc *udc, struct usba_ep *ep)
10411 + struct usba_request *req;
10412 + u32 status, control, pending;
10414 + status = usba_dma_readl(ep, STATUS);
10415 + control = usba_dma_readl(ep, CONTROL);
10416 +#ifdef CONFIG_DEBUG_FS
10417 + ep->last_dma_status = status;
10419 + pending = status & control;
10420 + DBG(DBG_INT | DBG_DMA, "dma irq, s/%#08x, c/%#08x\n",
10421 + status, control);
10423 + if (status & USBA_BIT(DMA_CH_EN)) {
10424 + dev_err(&udc->pdev->dev,
10425 + "DMA_CH_EN is set after transfer is finished!\n");
10426 + dev_err(&udc->pdev->dev,
10427 + "status=%#08x, pending=%#08x, control=%#08x\n",
10428 + status, pending, control);
10431 + * try to pretend nothing happened. We might have to
10432 + * do something here...
10436 + if (list_empty(&ep->queue))
10437 + /* Might happen if a reset comes along at the right moment */
10440 + if (pending & (USBA_BIT(DMA_END_TR_ST) | USBA_BIT(DMA_END_BUF_ST))) {
10441 + req = list_entry(ep->queue.next, struct usba_request, queue);
10442 + usba_update_req(ep, req, status);
10444 + list_del_init(&req->queue);
10445 + submit_next_request(ep);
10446 + request_complete(ep, req, 0);
10450 +static irqreturn_t usba_udc_irq(int irq, void *devid)
10452 + struct usba_udc *udc = devid;
10457 + spin_lock(&udc->lock);
10459 + status = usba_readl(udc, INT_STA);
10460 + DBG(DBG_INT, "irq, status=%#08x\n", status);
10462 + if (status & USBA_BIT(DET_SUSPEND)) {
10463 + usba_writel(udc, INT_CLR, USBA_BIT(DET_SUSPEND));
10464 + DBG(DBG_BUS, "Suspend detected\n");
10465 + if (udc->gadget.speed != USB_SPEED_UNKNOWN
10466 + && udc->driver && udc->driver->suspend)
10467 + udc->driver->suspend(&udc->gadget);
10470 + if (status & USBA_BIT(WAKE_UP)) {
10471 + usba_writel(udc, INT_CLR, USBA_BIT(WAKE_UP));
10472 + DBG(DBG_BUS, "Wake Up CPU detected\n");
10475 + if (status & USBA_BIT(END_OF_RESUME)) {
10476 + usba_writel(udc, INT_CLR, USBA_BIT(END_OF_RESUME));
10477 + DBG(DBG_BUS, "Resume detected\n");
10478 + if (udc->gadget.speed != USB_SPEED_UNKNOWN
10479 + && udc->driver && udc->driver->resume)
10480 + udc->driver->resume(&udc->gadget);
10483 + dma_status = USBA_BFEXT(DMA_INT, status);
10484 + if (dma_status) {
10487 + for (i = 1; i < USBA_NR_ENDPOINTS; i++)
10488 + if (dma_status & (1 << i))
10489 + usba_dma_irq(udc, &usba_ep[i]);
10492 + ep_status = USBA_BFEXT(EPT_INT, status);
10496 + for (i = 0; i < USBA_NR_ENDPOINTS; i++)
10497 + if (ep_status & (1 << i)) {
10498 + if (ep_is_control(&usba_ep[i]))
10499 + usba_control_irq(udc, &usba_ep[i]);
10501 + usba_ep_irq(udc, &usba_ep[i]);
10505 + if (status & USBA_BIT(END_OF_RESET)) {
10506 + struct usba_ep *ep0;
10508 + usba_writel(udc, INT_CLR, USBA_BIT(END_OF_RESET));
10509 + reset_all_endpoints(udc);
10511 + if (status & USBA_BIT(HIGH_SPEED)) {
10512 + DBG(DBG_BUS, "High-speed bus reset detected\n");
10513 + udc->gadget.speed = USB_SPEED_HIGH;
10515 + DBG(DBG_BUS, "Full-speed bus reset detected\n");
10516 + udc->gadget.speed = USB_SPEED_FULL;
10519 + ep0 = &usba_ep[0];
10520 + ep0->desc = &usba_ep0_desc;
10521 + ep0->state = WAIT_FOR_SETUP;
10522 + usba_ep_writel(ep0, CFG,
10523 + (USBA_BF(EPT_SIZE, EP0_EPT_SIZE)
10524 + | USBA_BF(EPT_TYPE, USBA_EPT_TYPE_CONTROL)
10525 + | USBA_BF(BK_NUMBER, USBA_BK_NUMBER_ONE)));
10526 + usba_ep_writel(ep0, CTL_ENB,
10527 + USBA_BIT(EPT_ENABLE) | USBA_BIT(RX_SETUP));
10528 + usba_writel(udc, INT_ENB, (usba_readl(udc, INT_ENB)
10529 + | USBA_BF(EPT_INT, 1)
10530 + | USBA_BIT(DET_SUSPEND)
10531 + | USBA_BIT(END_OF_RESUME)));
10533 + if (!(usba_ep_readl(ep0, CFG) & USBA_BIT(EPT_MAPPED)))
10534 + dev_warn(&udc->pdev->dev,
10535 + "WARNING: EP0 configuration is invalid!\n");
10538 + spin_unlock(&udc->lock);
10540 + return IRQ_HANDLED;
10543 +static irqreturn_t usba_vbus_irq(int irq, void *devid)
10545 + struct usba_udc *udc = devid;
10551 + spin_lock(&udc->lock);
10552 + vbus = gpio_get_value(udc->vbus_pin);
10553 + if (vbus != udc->vbus_prev) {
10555 + usba_writel(udc, CTRL, USBA_BIT(EN_USBA));
10556 + usba_writel(udc, INT_ENB, USBA_BIT(END_OF_RESET));
10558 + udc->gadget.speed = USB_SPEED_UNKNOWN;
10559 + reset_all_endpoints(udc);
10560 + usba_writel(udc, CTRL, 0);
10562 + udc->driver->disconnect(&udc->gadget);
10564 + udc->vbus_prev = vbus;
10566 + spin_unlock(&udc->lock);
10568 + return IRQ_HANDLED;
10571 +int usb_gadget_register_driver(struct usb_gadget_driver *driver)
10573 + struct usba_udc *udc = &the_udc;
10574 + unsigned long flags;
10580 + spin_lock_irqsave(&udc->lock, flags);
10581 + if (udc->driver) {
10582 + spin_unlock_irqrestore(&udc->lock, flags);
10586 + udc->driver = driver;
10587 + udc->gadget.dev.driver = &driver->driver;
10588 + spin_unlock_irqrestore(&udc->lock, flags);
10590 + clk_enable(udc->pclk);
10591 + clk_enable(udc->hclk);
10593 + ret = driver->bind(&udc->gadget);
10595 + DBG(DBG_ERR, "Could not bind to driver %s: error %d\n",
10596 + driver->driver.name, ret);
10597 + goto err_driver_bind;
10600 + DBG(DBG_GADGET, "registered driver `%s'\n", driver->driver.name);
10602 + udc->vbus_prev = 0;
10603 + if (udc->vbus_pin != -1) {
10604 + ret = request_irq(gpio_to_irq(udc->vbus_pin),
10605 + usba_vbus_irq, 0, "atmel_usba_udc", udc);
10607 + gpio_free(udc->vbus_pin);
10608 + udc->vbus_pin = -1;
10609 + dev_warn(&udc->pdev->dev,
10610 + "failed to request vbus irq; "
10611 + "assuming always on\n");
10615 + /* If Vbus is present, enable the controller and wait for reset */
10616 + spin_lock_irqsave(&udc->lock, flags);
10617 + if (vbus_is_present(udc) && udc->vbus_prev == 0) {
10618 + usba_writel(udc, CTRL, USBA_BIT(EN_USBA));
10619 + usba_writel(udc, INT_ENB, USBA_BIT(END_OF_RESET));
10621 + spin_unlock_irqrestore(&udc->lock, flags);
10626 + udc->driver = NULL;
10627 + udc->gadget.dev.driver = NULL;
10630 +EXPORT_SYMBOL(usb_gadget_register_driver);
10632 +int usb_gadget_unregister_driver(struct usb_gadget_driver *driver)
10634 + struct usba_udc *udc = &the_udc;
10635 + unsigned long flags;
10639 + if (driver != udc->driver)
10642 + if (udc->vbus_pin != -1)
10643 + free_irq(gpio_to_irq(udc->vbus_pin), udc);
10645 + spin_lock_irqsave(&udc->lock, flags);
10646 + udc->gadget.speed = USB_SPEED_UNKNOWN;
10647 + reset_all_endpoints(udc);
10648 + spin_unlock_irqrestore(&udc->lock, flags);
10650 + /* This will also disable the DP pullup */
10651 + usba_writel(udc, CTRL, 0);
10653 + driver->unbind(&udc->gadget);
10654 + udc->gadget.dev.driver = NULL;
10655 + udc->driver = NULL;
10657 + clk_disable(udc->hclk);
10658 + clk_disable(udc->pclk);
10660 + DBG(DBG_GADGET, "unregistered driver `%s'\n", driver->driver.name);
10664 +EXPORT_SYMBOL(usb_gadget_unregister_driver);
10666 +static int __devinit usba_udc_probe(struct platform_device *pdev)
10668 + struct usba_platform_data *pdata = pdev->dev.platform_data;
10669 + struct resource *regs, *fifo;
10670 + struct clk *pclk, *hclk;
10671 + struct usba_udc *udc = &the_udc;
10674 + regs = platform_get_resource(pdev, IORESOURCE_MEM, CTRL_IOMEM_ID);
10675 + fifo = platform_get_resource(pdev, IORESOURCE_MEM, FIFO_IOMEM_ID);
10676 + if (!regs || !fifo)
10679 + irq = platform_get_irq(pdev, 0);
10683 + pclk = clk_get(&pdev->dev, "pclk");
10684 + if (IS_ERR(pclk))
10685 + return PTR_ERR(pclk);
10686 + hclk = clk_get(&pdev->dev, "hclk");
10687 + if (IS_ERR(hclk)) {
10688 + ret = PTR_ERR(hclk);
10689 + goto err_get_hclk;
10692 + udc->pdev = pdev;
10693 + udc->pclk = pclk;
10694 + udc->hclk = hclk;
10695 + udc->vbus_pin = -1;
10698 + udc->regs = ioremap(regs->start, regs->end - regs->start + 1);
10699 + if (!udc->regs) {
10700 + dev_err(&pdev->dev, "Unable to map I/O memory, aborting.\n");
10701 + goto err_map_regs;
10703 + dev_info(&pdev->dev, "MMIO registers at 0x%08lx mapped at %p\n",
10704 + (unsigned long)regs->start, udc->regs);
10705 + udc->fifo = ioremap(fifo->start, fifo->end - fifo->start + 1);
10706 + if (!udc->fifo) {
10707 + dev_err(&pdev->dev, "Unable to map FIFO, aborting.\n");
10708 + goto err_map_fifo;
10710 + dev_info(&pdev->dev, "FIFO at 0x%08lx mapped at %p\n",
10711 + (unsigned long)fifo->start, udc->fifo);
10713 + device_initialize(&udc->gadget.dev);
10714 + udc->gadget.dev.parent = &pdev->dev;
10715 + udc->gadget.dev.dma_mask = pdev->dev.dma_mask;
10717 + platform_set_drvdata(pdev, udc);
10719 + /* Make sure we start from a clean slate */
10720 + clk_enable(pclk);
10721 + usba_writel(udc, CTRL, 0);
10722 + clk_disable(pclk);
10724 + INIT_LIST_HEAD(&usba_ep[0].ep.ep_list);
10725 + usba_ep[0].ep_regs = udc->regs + USBA_EPT_BASE(0);
10726 + usba_ep[0].dma_regs = udc->regs + USBA_DMA_BASE(0);
10727 + usba_ep[0].fifo = udc->fifo + USBA_FIFO_BASE(0);
10728 + for (i = 1; i < ARRAY_SIZE(usba_ep); i++) {
10729 + struct usba_ep *ep = &usba_ep[i];
10731 + ep->ep_regs = udc->regs + USBA_EPT_BASE(i);
10732 + ep->dma_regs = udc->regs + USBA_DMA_BASE(i);
10733 + ep->fifo = udc->fifo + USBA_FIFO_BASE(i);
10735 + list_add_tail(&ep->ep.ep_list, &udc->gadget.ep_list);
10738 + ret = request_irq(irq, usba_udc_irq, IRQF_SAMPLE_RANDOM,
10739 + "atmel_usba_udc", udc);
10741 + dev_err(&pdev->dev, "Cannot request irq %d (error %d)\n",
10743 + goto err_request_irq;
10747 + ret = device_add(&udc->gadget.dev);
10749 + dev_dbg(&pdev->dev, "Could not add gadget: %d\n", ret);
10750 + goto err_device_add;
10753 + if (pdata && pdata->vbus_pin != GPIO_PIN_NONE)
10754 + if (!gpio_request(pdata->vbus_pin, "atmel_usba_udc"))
10755 + udc->vbus_pin = pdata->vbus_pin;
10757 + usba_init_debugfs(udc);
10758 + for (i = 1; i < ARRAY_SIZE(usba_ep); i++)
10759 + usba_ep_init_debugfs(udc, &usba_ep[i]);
10764 + free_irq(irq, udc);
10766 + iounmap(udc->fifo);
10768 + iounmap(udc->regs);
10774 + platform_set_drvdata(pdev, NULL);
10779 +static int __devexit usba_udc_remove(struct platform_device *pdev)
10781 + struct usba_udc *udc;
10784 + udc = platform_get_drvdata(pdev);
10786 + for (i = 1; i < ARRAY_SIZE(usba_ep); i++)
10787 + usba_ep_cleanup_debugfs(&usba_ep[i]);
10788 + usba_cleanup_debugfs(udc);
10790 + if (udc->vbus_pin != -1)
10791 + gpio_free(udc->vbus_pin);
10793 + free_irq(udc->irq, udc);
10794 + iounmap(udc->fifo);
10795 + iounmap(udc->regs);
10796 + clk_put(udc->hclk);
10797 + clk_put(udc->pclk);
10799 + device_unregister(&udc->gadget.dev);
10804 +static struct platform_driver udc_driver = {
10805 + .probe = usba_udc_probe,
10806 + .remove = __devexit_p(usba_udc_remove),
10808 + .name = "atmel_usba_udc",
10812 +static int __init udc_init(void)
10814 + return platform_driver_register(&udc_driver);
10816 +module_init(udc_init);
10818 +static void __exit udc_exit(void)
10820 + platform_driver_unregister(&udc_driver);
10822 +module_exit(udc_exit);
10824 +MODULE_DESCRIPTION("Atmel USBA UDC driver");
10825 +MODULE_AUTHOR("Haavard Skinnemoen <hskinnemoen@atmel.com>");
10826 +MODULE_LICENSE("GPL");
10827 diff -x .git -Nur linux-2.6.22.1/drivers/usb/gadget/atmel_usba_udc.h linux-avr32.git/drivers/usb/gadget/atmel_usba_udc.h
10828 --- linux-2.6.22.1/drivers/usb/gadget/atmel_usba_udc.h 1970-01-01 01:00:00.000000000 +0100
10829 +++ linux-avr32.git/drivers/usb/gadget/atmel_usba_udc.h 2007-07-12 14:00:19.000000000 +0200
10832 + * Driver for the Atmel USBA high speed USB device controller
10834 + * Copyright (C) 2005-2007 Atmel Corporation
10836 + * This program is free software; you can redistribute it and/or modify
10837 + * it under the terms of the GNU General Public License version 2 as
10838 + * published by the Free Software Foundation.
10840 +#ifndef __LINUX_USB_GADGET_USBA_UDC_H__
10841 +#define __LINUX_USB_GADGET_USBA_UDC_H__
10843 +/* USB register offsets */
10844 +#define USBA_CTRL 0x0000
10845 +#define USBA_FNUM 0x0004
10846 +#define USBA_INT_ENB 0x0010
10847 +#define USBA_INT_STA 0x0014
10848 +#define USBA_INT_CLR 0x0018
10849 +#define USBA_EPT_RST 0x001c
10850 +#define USBA_TST_SOF_CNT 0x00d0
10851 +#define USBA_TST_CNT_A 0x00d4
10852 +#define USBA_TST_CNT_B 0x00d8
10853 +#define USBA_TST_MODE_REG 0x00dc
10854 +#define USBA_TST 0x00e0
10856 +/* USB endpoint register offsets */
10857 +#define USBA_EPT_CFG 0x0000
10858 +#define USBA_EPT_CTL_ENB 0x0004
10859 +#define USBA_EPT_CTL_DIS 0x0008
10860 +#define USBA_EPT_CTL 0x000c
10861 +#define USBA_EPT_SET_STA 0x0014
10862 +#define USBA_EPT_CLR_STA 0x0018
10863 +#define USBA_EPT_STA 0x001c
10865 +/* USB DMA register offsets */
10866 +#define USBA_DMA_NXT_DSC 0x0000
10867 +#define USBA_DMA_ADDRESS 0x0004
10868 +#define USBA_DMA_CONTROL 0x0008
10869 +#define USBA_DMA_STATUS 0x000c
10871 +/* Bitfields in CTRL */
10872 +#define USBA_DEV_ADDR_OFFSET 0
10873 +#define USBA_DEV_ADDR_SIZE 7
10874 +#define USBA_FADDR_EN_OFFSET 7
10875 +#define USBA_FADDR_EN_SIZE 1
10876 +#define USBA_EN_USBA_OFFSET 8
10877 +#define USBA_EN_USBA_SIZE 1
10878 +#define USBA_DETACH_OFFSET 9
10879 +#define USBA_DETACH_SIZE 1
10880 +#define USBA_REMOTE_WAKE_UP_OFFSET 10
10881 +#define USBA_REMOTE_WAKE_UP_SIZE 1
10883 +/* Bitfields in FNUM */
10884 +#define USBA_MICRO_FRAME_NUM_OFFSET 0
10885 +#define USBA_MICRO_FRAME_NUM_SIZE 3
10886 +#define USBA_FRAME_NUMBER_OFFSET 3
10887 +#define USBA_FRAME_NUMBER_SIZE 11
10888 +#define USBA_FRAME_NUM_ERROR_OFFSET 31
10889 +#define USBA_FRAME_NUM_ERROR_SIZE 1
10891 +/* Bitfields in INT_ENB/INT_STA/INT_CLR */
10892 +#define USBA_HIGH_SPEED_OFFSET 0
10893 +#define USBA_HIGH_SPEED_SIZE 1
10894 +#define USBA_DET_SUSPEND_OFFSET 1
10895 +#define USBA_DET_SUSPEND_SIZE 1
10896 +#define USBA_MICRO_SOF_OFFSET 2
10897 +#define USBA_MICRO_SOF_SIZE 1
10898 +#define USBA_SOF_OFFSET 3
10899 +#define USBA_SOF_SIZE 1
10900 +#define USBA_END_OF_RESET_OFFSET 4
10901 +#define USBA_END_OF_RESET_SIZE 1
10902 +#define USBA_WAKE_UP_OFFSET 5
10903 +#define USBA_WAKE_UP_SIZE 1
10904 +#define USBA_END_OF_RESUME_OFFSET 6
10905 +#define USBA_END_OF_RESUME_SIZE 1
10906 +#define USBA_UPSTREAM_RESUME_OFFSET 7
10907 +#define USBA_UPSTREAM_RESUME_SIZE 1
10908 +#define USBA_EPT_INT_OFFSET 8
10909 +#define USBA_EPT_INT_SIZE 16
10910 +#define USBA_DMA_INT_OFFSET 24
10911 +#define USBA_DMA_INT_SIZE 8
10913 +/* Bitfields in EPT_RST */
10914 +#define USBA_RST_OFFSET 0
10915 +#define USBA_RST_SIZE 16
10917 +/* Bitfields in TST_SOF_CNT */
10918 +#define USBA_SOF_CNT_MAX_OFFSET 0
10919 +#define USBA_SOF_CNT_MAX_SIZE 7
10920 +#define USBA_SOF_CNT_LOAD_OFFSET 7
10921 +#define USBA_SOF_CNT_LOAD_SIZE 1
10923 +/* Bitfields in TST_CNT_A */
10924 +#define USBA_CNT_A_MAX_OFFSET 0
10925 +#define USBA_CNT_A_MAX_SIZE 7
10926 +#define USBA_CNT_A_LOAD_OFFSET 7
10927 +#define USBA_CNT_A_LOAD_SIZE 1
10929 +/* Bitfields in TST_CNT_B */
10930 +#define USBA_CNT_B_MAX_OFFSET 0
10931 +#define USBA_CNT_B_MAX_SIZE 7
10932 +#define USBA_CNT_B_LOAD_OFFSET 7
10933 +#define USBA_CNT_B_LOAD_SIZE 1
10935 +/* Bitfields in TST_MODE_REG */
10936 +#define USBA_TST_MODE_OFFSET 0
10937 +#define USBA_TST_MODE_SIZE 6
10939 +/* Bitfields in USBA_TST */
10940 +#define USBA_SPEED_CFG_OFFSET 0
10941 +#define USBA_SPEED_CFG_SIZE 2
10942 +#define USBA_TST_J_MODE_OFFSET 2
10943 +#define USBA_TST_J_MODE_SIZE 1
10944 +#define USBA_TST_K_MODE_OFFSET 3
10945 +#define USBA_TST_K_MODE_SIZE 1
10946 +#define USBA_TST_PKT_MODE_OFFSET 4
10947 +#define USBA_TST_PKT_MODE_SIZE 1
10948 +#define USBA_OPMODE2_OFFSET 5
10949 +#define USBA_OPMODE2_SIZE 1
10951 +/* Bitfields in EPT_CFG */
10952 +#define USBA_EPT_SIZE_OFFSET 0
10953 +#define USBA_EPT_SIZE_SIZE 3
10954 +#define USBA_EPT_DIR_OFFSET 3
10955 +#define USBA_EPT_DIR_SIZE 1
10956 +#define USBA_EPT_TYPE_OFFSET 4
10957 +#define USBA_EPT_TYPE_SIZE 2
10958 +#define USBA_BK_NUMBER_OFFSET 6
10959 +#define USBA_BK_NUMBER_SIZE 2
10960 +#define USBA_NB_TRANS_OFFSET 8
10961 +#define USBA_NB_TRANS_SIZE 2
10962 +#define USBA_EPT_MAPPED_OFFSET 31
10963 +#define USBA_EPT_MAPPED_SIZE 1
10965 +/* Bitfields in EPT_CTL/EPT_CTL_ENB/EPT_CTL_DIS */
10966 +#define USBA_EPT_ENABLE_OFFSET 0
10967 +#define USBA_EPT_ENABLE_SIZE 1
10968 +#define USBA_AUTO_VALID_OFFSET 1
10969 +#define USBA_AUTO_VALID_SIZE 1
10970 +#define USBA_INTDIS_DMA_OFFSET 3
10971 +#define USBA_INTDIS_DMA_SIZE 1
10972 +#define USBA_NYET_DIS_OFFSET 4
10973 +#define USBA_NYET_DIS_SIZE 1
10974 +#define USBA_DATAX_RX_OFFSET 6
10975 +#define USBA_DATAX_RX_SIZE 1
10976 +#define USBA_MDATA_RX_OFFSET 7
10977 +#define USBA_MDATA_RX_SIZE 1
10978 +/* Bits 8-15 and 31 enable interrupts for respective bits in EPT_STA */
10979 +#define USBA_BUSY_BANK_IE_OFFSET 18
10980 +#define USBA_BUSY_BANK_IE_SIZE 1
10982 +/* Bitfields in EPT_SET_STA/EPT_CLR_STA/EPT_STA */
10983 +#define USBA_FORCE_STALL_OFFSET 5
10984 +#define USBA_FORCE_STALL_SIZE 1
10985 +#define USBA_TOGGLE_SEQ_OFFSET 6
10986 +#define USBA_TOGGLE_SEQ_SIZE 2
10987 +#define USBA_ERR_OVFLW_OFFSET 8
10988 +#define USBA_ERR_OVFLW_SIZE 1
10989 +#define USBA_RX_BK_RDY_OFFSET 9
10990 +#define USBA_RX_BK_RDY_SIZE 1
10991 +#define USBA_KILL_BANK_OFFSET 9
10992 +#define USBA_KILL_BANK_SIZE 1
10993 +#define USBA_TX_COMPLETE_OFFSET 10
10994 +#define USBA_TX_COMPLETE_SIZE 1
10995 +#define USBA_TX_PK_RDY_OFFSET 11
10996 +#define USBA_TX_PK_RDY_SIZE 1
10997 +#define USBA_ISO_ERR_TRANS_OFFSET 11
10998 +#define USBA_ISO_ERR_TRANS_SIZE 1
10999 +#define USBA_RX_SETUP_OFFSET 12
11000 +#define USBA_RX_SETUP_SIZE 1
11001 +#define USBA_ISO_ERR_FLOW_OFFSET 12
11002 +#define USBA_ISO_ERR_FLOW_SIZE 1
11003 +#define USBA_STALL_SENT_OFFSET 13
11004 +#define USBA_STALL_SENT_SIZE 1
11005 +#define USBA_ISO_ERR_CRC_OFFSET 13
11006 +#define USBA_ISO_ERR_CRC_SIZE 1
11007 +#define USBA_ISO_ERR_NBTRANS_OFFSET 13
11008 +#define USBA_ISO_ERR_NBTRANS_SIZE 1
11009 +#define USBA_NAK_IN_OFFSET 14
11010 +#define USBA_NAK_IN_SIZE 1
11011 +#define USBA_ISO_ERR_FLUSH_OFFSET 14
11012 +#define USBA_ISO_ERR_FLUSH_SIZE 1
11013 +#define USBA_NAK_OUT_OFFSET 15
11014 +#define USBA_NAK_OUT_SIZE 1
11015 +#define USBA_CURRENT_BANK_OFFSET 16
11016 +#define USBA_CURRENT_BANK_SIZE 2
11017 +#define USBA_BUSY_BANKS_OFFSET 18
11018 +#define USBA_BUSY_BANKS_SIZE 2
11019 +#define USBA_BYTE_COUNT_OFFSET 20
11020 +#define USBA_BYTE_COUNT_SIZE 11
11021 +#define USBA_SHORT_PACKET_OFFSET 31
11022 +#define USBA_SHORT_PACKET_SIZE 1
11024 +/* Bitfields in DMA_CONTROL */
11025 +#define USBA_DMA_CH_EN_OFFSET 0
11026 +#define USBA_DMA_CH_EN_SIZE 1
11027 +#define USBA_DMA_LINK_OFFSET 1
11028 +#define USBA_DMA_LINK_SIZE 1
11029 +#define USBA_DMA_END_TR_EN_OFFSET 2
11030 +#define USBA_DMA_END_TR_EN_SIZE 1
11031 +#define USBA_DMA_END_BUF_EN_OFFSET 3
11032 +#define USBA_DMA_END_BUF_EN_SIZE 1
11033 +#define USBA_DMA_END_TR_IE_OFFSET 4
11034 +#define USBA_DMA_END_TR_IE_SIZE 1
11035 +#define USBA_DMA_END_BUF_IE_OFFSET 5
11036 +#define USBA_DMA_END_BUF_IE_SIZE 1
11037 +#define USBA_DMA_DESC_LOAD_IE_OFFSET 6
11038 +#define USBA_DMA_DESC_LOAD_IE_SIZE 1
11039 +#define USBA_DMA_BURST_LOCK_OFFSET 7
11040 +#define USBA_DMA_BURST_LOCK_SIZE 1
11041 +#define USBA_DMA_BUF_LEN_OFFSET 16
11042 +#define USBA_DMA_BUF_LEN_SIZE 16
11044 +/* Bitfields in DMA_STATUS */
11045 +#define USBA_DMA_CH_ACTIVE_OFFSET 1
11046 +#define USBA_DMA_CH_ACTIVE_SIZE 1
11047 +#define USBA_DMA_END_TR_ST_OFFSET 4
11048 +#define USBA_DMA_END_TR_ST_SIZE 1
11049 +#define USBA_DMA_END_BUF_ST_OFFSET 5
11050 +#define USBA_DMA_END_BUF_ST_SIZE 1
11051 +#define USBA_DMA_DESC_LOAD_ST_OFFSET 6
11052 +#define USBA_DMA_DESC_LOAD_ST_SIZE 1
11054 +/* Constants for SPEED_CFG */
11055 +#define USBA_SPEED_CFG_NORMAL 0
11056 +#define USBA_SPEED_CFG_FORCE_HIGH 2
11057 +#define USBA_SPEED_CFG_FORCE_FULL 3
11059 +/* Constants for EPT_SIZE */
11060 +#define USBA_EPT_SIZE_8 0
11061 +#define USBA_EPT_SIZE_16 1
11062 +#define USBA_EPT_SIZE_32 2
11063 +#define USBA_EPT_SIZE_64 3
11064 +#define USBA_EPT_SIZE_128 4
11065 +#define USBA_EPT_SIZE_256 5
11066 +#define USBA_EPT_SIZE_512 6
11067 +#define USBA_EPT_SIZE_1024 7
11069 +/* Constants for EPT_TYPE */
11070 +#define USBA_EPT_TYPE_CONTROL 0
11071 +#define USBA_EPT_TYPE_ISO 1
11072 +#define USBA_EPT_TYPE_BULK 2
11073 +#define USBA_EPT_TYPE_INT 3
11075 +/* Constants for BK_NUMBER */
11076 +#define USBA_BK_NUMBER_ZERO 0
11077 +#define USBA_BK_NUMBER_ONE 1
11078 +#define USBA_BK_NUMBER_DOUBLE 2
11079 +#define USBA_BK_NUMBER_TRIPLE 3
11081 +/* Bit manipulation macros */
11082 +#define USBA_BIT(name) \
11083 + (1 << USBA_##name##_OFFSET)
11084 +#define USBA_BF(name, value) \
11085 + (((value) & ((1 << USBA_##name##_SIZE) - 1)) \
11086 + << USBA_##name##_OFFSET)
11087 +#define USBA_BFEXT(name, value) \
11088 + (((value) >> USBA_##name##_OFFSET) \
11089 + & ((1 << USBA_##name##_SIZE) - 1))
11090 +#define USBA_BFINS(name, value, old) \
11091 + (((old) & ~(((1 << USBA_##name##_SIZE) - 1) \
11092 + << USBA_##name##_OFFSET)) \
11093 + | USBA_BF(name, value))
11095 +/* Register access macros */
11096 +#define usba_readl(udc, reg) \
11097 + __raw_readl((udc)->regs + USBA_##reg)
11098 +#define usba_writel(udc, reg, value) \
11099 + __raw_writel((value), (udc)->regs + USBA_##reg)
11100 +#define usba_ep_readl(ep, reg) \
11101 + __raw_readl((ep)->ep_regs + USBA_EPT_##reg)
11102 +#define usba_ep_writel(ep, reg, value) \
11103 + __raw_writel((value), (ep)->ep_regs + USBA_EPT_##reg)
11104 +#define usba_dma_readl(ep, reg) \
11105 + __raw_readl((ep)->dma_regs + USBA_DMA_##reg)
11106 +#define usba_dma_writel(ep, reg, value) \
11107 + __raw_writel((value), (ep)->dma_regs + USBA_DMA_##reg)
11109 +/* Calculate base address for a given endpoint or DMA controller */
11110 +#define USBA_EPT_BASE(x) (0x100 + (x) * 0x20)
11111 +#define USBA_DMA_BASE(x) (0x300 + (x) * 0x10)
11112 +#define USBA_FIFO_BASE(x) ((x) << 16)
11114 +/* Synth parameters */
11115 +#define USBA_NR_ENDPOINTS 7
11117 +#define EP0_FIFO_SIZE 64
11118 +#define EP0_EPT_SIZE USBA_EPT_SIZE_64
11119 +#define EP0_NR_BANKS 1
11120 +#define BULK_FIFO_SIZE 512
11121 +#define BULK_EPT_SIZE USBA_EPT_SIZE_512
11122 +#define BULK_NR_BANKS 2
11123 +#define ISO_FIFO_SIZE 1024
11124 +#define ISO_EPT_SIZE USBA_EPT_SIZE_1024
11125 +#define ISO_NR_BANKS 3
11126 +#define INT_FIFO_SIZE 64
11127 +#define INT_EPT_SIZE USBA_EPT_SIZE_64
11128 +#define INT_NR_BANKS 3
11130 +enum usba_ctrl_state {
11135 + STATUS_STAGE_OUT,
11136 + STATUS_STAGE_ADDR,
11137 + STATUS_STAGE_TEST,
11142 + EP_STATE_IN_DATA,
11143 + EP_STATE_OUT_DATA,
11144 + EP_STATE_SET_ADDR_STATUS,
11145 + EP_STATE_RX_STATUS,
11146 + EP_STATE_TX_STATUS,
11150 +struct usba_dma_desc {
11158 + void __iomem *ep_regs;
11159 + void __iomem *dma_regs;
11160 + void __iomem *fifo;
11161 + struct usb_ep ep;
11162 + struct usba_udc *udc;
11164 + struct list_head queue;
11165 + const struct usb_endpoint_descriptor *desc;
11170 + unsigned int can_dma:1;
11171 + unsigned int can_isoc:1;
11172 + unsigned int is_isoc:1;
11173 + unsigned int is_in:1;
11175 +#ifdef CONFIG_DEBUG_FS
11176 + u32 last_dma_status;
11177 + struct dentry *debugfs_dir;
11178 + struct dentry *debugfs_queue;
11179 + struct dentry *debugfs_dma_status;
11180 + struct dentry *debugfs_state;
11184 +struct usba_request {
11185 + struct usb_request req;
11186 + struct list_head queue;
11190 + unsigned int submitted:1;
11191 + unsigned int last_transaction:1;
11192 + unsigned int using_dma:1;
11193 + unsigned int mapped:1;
11197 + /* Protect hw registers from concurrent modifications */
11200 + void __iomem *regs;
11201 + void __iomem *fifo;
11203 + struct usb_gadget gadget;
11204 + struct usb_gadget_driver *driver;
11205 + struct platform_device *pdev;
11208 + struct clk *pclk;
11209 + struct clk *hclk;
11214 +#ifdef CONFIG_DEBUG_FS
11215 + struct dentry *debugfs_root;
11216 + struct dentry *debugfs_regs;
11220 +#define to_usba_ep(x) container_of((x), struct usba_ep, ep)
11221 +#define to_usba_req(x) container_of((x), struct usba_request, req)
11222 +#define to_usba_udc(x) container_of((x), struct usba_udc, gadget)
11224 +#define ep_index(ep) ((ep)->index)
11225 +#define ep_can_dma(ep) ((ep)->can_dma)
11226 +#define ep_is_in(ep) ((ep)->is_in)
11227 +#define ep_is_isochronous(ep) ((ep)->is_isoc)
11228 +#define ep_is_control(ep) (ep_index(ep) == 0)
11229 +#define ep_name(ep) ((ep)->ep.name)
11230 +#define ep_is_idle(ep) ((ep)->state == EP_STATE_IDLE)
11232 +#endif /* __LINUX_USB_GADGET_USBA_UDC_H */
11233 diff -x .git -Nur linux-2.6.22.1/drivers/usb/gadget/ether.c linux-avr32.git/drivers/usb/gadget/ether.c
11234 --- linux-2.6.22.1/drivers/usb/gadget/ether.c 2007-07-10 20:56:30.000000000 +0200
11235 +++ linux-avr32.git/drivers/usb/gadget/ether.c 2007-07-12 14:00:19.000000000 +0200
11236 @@ -277,7 +277,7 @@
11237 #define DEV_CONFIG_CDC
11240 -#ifdef CONFIG_USB_GADGET_HUSB2DEV
11241 +#ifdef CONFIG_USB_GADGET_ATMEL_USBA
11242 #define DEV_CONFIG_CDC
11245 diff -x .git -Nur linux-2.6.22.1/drivers/usb/gadget/gadget_chips.h linux-avr32.git/drivers/usb/gadget/gadget_chips.h
11246 --- linux-2.6.22.1/drivers/usb/gadget/gadget_chips.h 2007-07-10 20:56:30.000000000 +0200
11247 +++ linux-avr32.git/drivers/usb/gadget/gadget_chips.h 2007-07-12 14:00:19.000000000 +0200
11248 @@ -75,10 +75,10 @@
11249 #define gadget_is_pxa27x(g) 0
11252 -#ifdef CONFIG_USB_GADGET_HUSB2DEV
11253 -#define gadget_is_husb2dev(g) !strcmp("husb2_udc", (g)->name)
11254 +#ifdef CONFIG_USB_GADGET_ATMEL_USBA
11255 +#define gadget_is_atmel_usba(g) !strcmp("atmel_usba_udc", (g)->name)
11257 -#define gadget_is_husb2dev(g) 0
11258 +#define gadget_is_atmel_usba(g) 0
11261 #ifdef CONFIG_USB_GADGET_S3C2410
11262 @@ -181,7 +181,7 @@
11264 else if (gadget_is_mpc8272(gadget))
11266 - else if (gadget_is_husb2dev(gadget))
11267 + else if (gadget_is_atmel_usba(gadget))
11269 else if (gadget_is_fsl_usb2(gadget))
11271 diff -x .git -Nur linux-2.6.22.1/drivers/usb/gadget/inode.c linux-avr32.git/drivers/usb/gadget/inode.c
11272 --- linux-2.6.22.1/drivers/usb/gadget/inode.c 2007-07-10 20:56:30.000000000 +0200
11273 +++ linux-avr32.git/drivers/usb/gadget/inode.c 2007-07-12 14:00:19.000000000 +0200
11275 #include <linux/device.h>
11276 #include <linux/moduleparam.h>
11278 -#include <linux/usb_gadgetfs.h>
11279 +#include <linux/usb/gadgetfs.h>
11280 #include <linux/usb_gadget.h>
11283 diff -x .git -Nur linux-2.6.22.1/drivers/usb/gadget/Kconfig linux-avr32.git/drivers/usb/gadget/Kconfig
11284 --- linux-2.6.22.1/drivers/usb/gadget/Kconfig 2007-07-10 20:56:30.000000000 +0200
11285 +++ linux-avr32.git/drivers/usb/gadget/Kconfig 2007-07-12 14:00:19.000000000 +0200
11286 @@ -175,6 +175,19 @@
11288 select USB_GADGET_SELECTED
11290 +config USB_GADGET_ATMEL_USBA
11291 + boolean "Atmel USBA"
11292 + select USB_GADGET_DUALSPEED
11295 + USBA is the integrated high-speed USB Device controller on
11296 + the AT32AP700x processors from Atmel.
11298 +config USB_ATMEL_USBA
11300 + depends on USB_GADGET_ATMEL_USBA
11301 + default USB_GADGET
11302 + select USB_GADGET_SELECTED
11304 config USB_GADGET_OMAP
11305 boolean "OMAP USB Device Controller"
11306 diff -x .git -Nur linux-2.6.22.1/drivers/usb/gadget/Makefile linux-avr32.git/drivers/usb/gadget/Makefile
11307 --- linux-2.6.22.1/drivers/usb/gadget/Makefile 2007-07-10 20:56:30.000000000 +0200
11308 +++ linux-avr32.git/drivers/usb/gadget/Makefile 2007-07-12 14:00:19.000000000 +0200
11310 obj-$(CONFIG_USB_OMAP) += omap_udc.o
11311 obj-$(CONFIG_USB_LH7A40X) += lh7a40x_udc.o
11312 obj-$(CONFIG_USB_AT91) += at91_udc.o
11313 +obj-$(CONFIG_USB_ATMEL_USBA) += atmel_usba_udc.o
11314 obj-$(CONFIG_USB_FSL_USB2) += fsl_usb2_udc.o
11317 diff -x .git -Nur linux-2.6.22.1/drivers/video/atmel_lcdfb.c linux-avr32.git/drivers/video/atmel_lcdfb.c
11318 --- linux-2.6.22.1/drivers/video/atmel_lcdfb.c 2007-07-10 20:56:30.000000000 +0200
11319 +++ linux-avr32.git/drivers/video/atmel_lcdfb.c 2007-07-12 14:00:20.000000000 +0200
11323 #if defined(CONFIG_ARCH_AT91)
11324 -#define ATMEL_LCDFB_FBINFO_DEFAULT FBINFO_DEFAULT
11325 +#define ATMEL_LCDFB_FBINFO_DEFAULT (FBINFO_DEFAULT \
11326 + | FBINFO_PARTIAL_PAN_OK \
11327 + | FBINFO_HWACCEL_YPAN)
11329 static inline void atmel_lcdfb_update_dma2d(struct atmel_lcdfb_info *sinfo,
11330 struct fb_var_screeninfo *var)
11331 @@ -74,11 +76,34 @@
11332 .type = FB_TYPE_PACKED_PIXELS,
11333 .visual = FB_VISUAL_TRUECOLOR,
11338 .accel = FB_ACCEL_NONE,
11341 +static unsigned long compute_hozval(unsigned long xres, unsigned long lcdcon2)
11343 + unsigned long value;
11345 + if (!(cpu_is_at91sam9261() || cpu_is_at32ap7000()))
11349 + if ((lcdcon2 & ATMEL_LCDC_DISTYPE) != ATMEL_LCDC_DISTYPE_TFT) {
11350 + /* STN display */
11351 + if ((lcdcon2 & ATMEL_LCDC_DISTYPE) == ATMEL_LCDC_DISTYPE_STNCOLOR) {
11354 + if ( (lcdcon2 & ATMEL_LCDC_IFWIDTH) == ATMEL_LCDC_IFWIDTH_4
11355 + || ( (lcdcon2 & ATMEL_LCDC_IFWIDTH) == ATMEL_LCDC_IFWIDTH_8
11356 + && (lcdcon2 & ATMEL_LCDC_SCANMOD) == ATMEL_LCDC_SCANMOD_DUAL ))
11357 + value = DIV_ROUND_UP(value, 4);
11359 + value = DIV_ROUND_UP(value, 8);
11365 static void atmel_lcdfb_update_dma(struct fb_info *info,
11366 struct fb_var_screeninfo *var)
11367 @@ -181,6 +206,7 @@
11368 var->xoffset = var->yoffset = 0;
11370 switch (var->bits_per_pixel) {
11375 @@ -195,8 +221,11 @@
11376 var->blue.offset = 10;
11377 var->red.length = var->green.length = var->blue.length = 5;
11381 + var->transp.offset = 24;
11382 + var->transp.length = 8;
11383 + /* fall through */
11385 var->red.offset = 0;
11386 var->green.offset = 8;
11387 var->blue.offset = 16;
11388 @@ -228,8 +257,10 @@
11389 static int atmel_lcdfb_set_par(struct fb_info *info)
11391 struct atmel_lcdfb_info *sinfo = info->par;
11392 + unsigned long hozval_linesz;
11393 unsigned long value;
11394 unsigned long clk_value_khz;
11395 + unsigned long bits_per_line;
11397 dev_dbg(info->device, "%s:\n", __func__);
11398 dev_dbg(info->device, " * resolution: %ux%u (%ux%u virtual)\n",
11399 @@ -241,12 +272,15 @@
11401 lcdc_writel(sinfo, ATMEL_LCDC_DMACON, 0);
11403 - if (info->var.bits_per_pixel <= 8)
11404 + if (info->var.bits_per_pixel == 1)
11405 + info->fix.visual = FB_VISUAL_MONO01;
11406 + else if (info->var.bits_per_pixel <= 8)
11407 info->fix.visual = FB_VISUAL_PSEUDOCOLOR;
11409 info->fix.visual = FB_VISUAL_TRUECOLOR;
11411 - info->fix.line_length = info->var.xres_virtual * (info->var.bits_per_pixel / 8);
11412 + bits_per_line = info->var.xres_virtual * info->var.bits_per_pixel;
11413 + info->fix.line_length = DIV_ROUND_UP(bits_per_line, 8);
11415 /* Re-initialize the DMA engine... */
11416 dev_dbg(info->device, " * update DMA engine\n");
11417 @@ -262,18 +296,21 @@
11418 /* Set pixel clock */
11419 clk_value_khz = clk_get_rate(sinfo->lcdc_clk) / 1000;
11421 - value = clk_value_khz / PICOS2KHZ(info->var.pixclock);
11423 - if (clk_value_khz % PICOS2KHZ(info->var.pixclock))
11425 + value = DIV_ROUND_UP(clk_value_khz, PICOS2KHZ(info->var.pixclock));
11427 value = (value / 2) - 1;
11428 + dev_dbg(info->device, " * programming CLKVAL = 0x%08lx\n", value);
11431 dev_notice(info->device, "Bypassing pixel clock divider\n");
11432 lcdc_writel(sinfo, ATMEL_LCDC_LCDCON1, ATMEL_LCDC_BYPASS);
11435 lcdc_writel(sinfo, ATMEL_LCDC_LCDCON1, value << ATMEL_LCDC_CLKVAL_OFFSET);
11436 + info->var.pixclock = KHZ2PICOS(clk_value_khz / (2 * (value + 1)));
11437 + dev_dbg(info->device, " updated pixclk: %lu KHz\n",
11438 + PICOS2KHZ(info->var.pixclock));
11442 /* Initialize control register 2 */
11443 value = sinfo->default_lcdcon2;
11444 @@ -311,9 +348,14 @@
11445 dev_dbg(info->device, " * LCDTIM2 = %08lx\n", value);
11446 lcdc_writel(sinfo, ATMEL_LCDC_TIM2, value);
11448 + /* Horizontal value (aka line size) */
11449 + hozval_linesz = compute_hozval(info->var.xres,
11450 + lcdc_readl(sinfo, ATMEL_LCDC_LCDCON2));
11453 - value = (info->var.xres - 1) << ATMEL_LCDC_HOZVAL_OFFSET;
11454 + value = (hozval_linesz - 1) << ATMEL_LCDC_HOZVAL_OFFSET;
11455 value |= info->var.yres - 1;
11456 + dev_dbg(info->device, " * LCDFRMCFG = %08lx\n", value);
11457 lcdc_writel(sinfo, ATMEL_LCDC_LCDFRMCFG, value);
11459 /* FIFO Threshold: Use formula from data sheet */
11460 @@ -421,6 +463,15 @@
11465 + case FB_VISUAL_MONO01:
11467 + val = (regno == 0) ? 0x00 : 0x1F;
11468 + lcdc_writel(sinfo, ATMEL_LCDC_LUT(regno), val);
11476 diff -x .git -Nur linux-2.6.22.1/drivers/video/backlight/Kconfig linux-avr32.git/drivers/video/backlight/Kconfig
11477 --- linux-2.6.22.1/drivers/video/backlight/Kconfig 2007-07-10 20:56:30.000000000 +0200
11478 +++ linux-avr32.git/drivers/video/backlight/Kconfig 2007-07-12 14:00:20.000000000 +0200
11480 Enable this to be able to choose the drivers for controlling the
11481 backlight and the LCD panel on some platforms, for example on PDAs.
11483 -config BACKLIGHT_CLASS_DEVICE
11484 - tristate "Lowlevel Backlight controls"
11488 +config LCD_CLASS_DEVICE
11489 + tristate "Lowlevel LCD controls"
11490 depends on BACKLIGHT_LCD_SUPPORT
11493 - This framework adds support for low-level control of the LCD
11494 - backlight. This includes support for brightness and power.
11495 + This framework adds support for low-level control of LCD.
11496 + Some framebuffer devices connect to platform-specific LCD modules
11497 + in order to have a platform-specific way to control the flat panel
11498 + (contrast and applying power to the LCD (not to the backlight!)).
11500 To have support for your specific LCD panel you will have to
11501 select the proper drivers which depend on this option.
11503 -config LCD_CLASS_DEVICE
11504 - tristate "Lowlevel LCD controls"
11505 +config LCD_LTV350QV
11506 + tristate "Samsung LTV350QV LCD Panel"
11507 + depends on LCD_CLASS_DEVICE && SPI_MASTER
11510 + If you have a Samsung LTV350QV LCD panel, say y to include a
11511 + power control driver for it. The panel starts up in power
11512 + off state, so you need this driver in order to see any
11515 + The LTV350QV panel is present on all ATSTK1000 boards.
11520 +config BACKLIGHT_CLASS_DEVICE
11521 + tristate "Lowlevel Backlight controls"
11522 depends on BACKLIGHT_LCD_SUPPORT
11525 - This framework adds support for low-level control of LCD.
11526 - Some framebuffer devices connect to platform-specific LCD modules
11527 - in order to have a platform-specific way to control the flat panel
11528 - (contrast and applying power to the LCD (not to the backlight!)).
11529 + This framework adds support for low-level control of the LCD
11530 + backlight. This includes support for brightness and power.
11532 To have support for your specific LCD panel you will have to
11533 select the proper drivers which depend on this option.
11534 diff -x .git -Nur linux-2.6.22.1/drivers/video/backlight/ltv350qv.c linux-avr32.git/drivers/video/backlight/ltv350qv.c
11535 --- linux-2.6.22.1/drivers/video/backlight/ltv350qv.c 1970-01-01 01:00:00.000000000 +0100
11536 +++ linux-avr32.git/drivers/video/backlight/ltv350qv.c 2007-06-06 11:34:00.000000000 +0200
11539 + * Power control for Samsung LTV350QV Quarter VGA LCD Panel
11541 + * Copyright (C) 2006, 2007 Atmel Corporation
11543 + * This program is free software; you can redistribute it and/or modify
11544 + * it under the terms of the GNU General Public License version 2 as
11545 + * published by the Free Software Foundation.
11547 +#include <linux/delay.h>
11548 +#include <linux/err.h>
11549 +#include <linux/fb.h>
11550 +#include <linux/init.h>
11551 +#include <linux/lcd.h>
11552 +#include <linux/module.h>
11553 +#include <linux/spi/spi.h>
11555 +#include "ltv350qv.h"
11557 +#define POWER_IS_ON(pwr) ((pwr) <= FB_BLANK_NORMAL)
11560 + struct spi_device *spi;
11563 + struct lcd_device *ld;
11567 + * The power-on and power-off sequences are taken from the
11568 + * LTV350QV-F04 data sheet from Samsung. The register definitions are
11569 + * taken from the S6F2002 command list also from Samsung. Both
11570 + * documents are distributed with the AVR32 Linux BSP CD from Atmel.
11572 + * There's still some voodoo going on here, but it's a lot better than
11573 + * in the first incarnation of the driver where all we had was the raw
11574 + * numbers from the initialization sequence.
11576 +static int ltv350qv_write_reg(struct ltv350qv *lcd, u8 reg, u16 val)
11578 + struct spi_message msg;
11579 + struct spi_transfer index_xfer = {
11583 + struct spi_transfer value_xfer = {
11588 + spi_message_init(&msg);
11590 + /* register index */
11591 + lcd->buffer[0] = LTV_OPC_INDEX;
11592 + lcd->buffer[1] = 0x00;
11593 + lcd->buffer[2] = reg & 0x7f;
11594 + index_xfer.tx_buf = lcd->buffer;
11595 + spi_message_add_tail(&index_xfer, &msg);
11597 + /* register value */
11598 + lcd->buffer[4] = LTV_OPC_DATA;
11599 + lcd->buffer[5] = val >> 8;
11600 + lcd->buffer[6] = val;
11601 + value_xfer.tx_buf = lcd->buffer + 4;
11602 + spi_message_add_tail(&value_xfer, &msg);
11604 + return spi_sync(lcd->spi, &msg);
11607 +/* The comments are taken straight from the data sheet */
11608 +static int ltv350qv_power_on(struct ltv350qv *lcd)
11612 + /* Power On Reset Display off State */
11613 + if (ltv350qv_write_reg(lcd, LTV_PWRCTL1, 0x0000))
11617 + /* Power Setting Function 1 */
11618 + if (ltv350qv_write_reg(lcd, LTV_PWRCTL1, LTV_VCOM_DISABLE))
11620 + if (ltv350qv_write_reg(lcd, LTV_PWRCTL2, LTV_VCOML_ENABLE))
11623 + /* Power Setting Function 2 */
11624 + if (ltv350qv_write_reg(lcd, LTV_PWRCTL1,
11625 + LTV_VCOM_DISABLE | LTV_DRIVE_CURRENT(5)
11626 + | LTV_SUPPLY_CURRENT(5)))
11631 + /* Instruction Setting */
11632 + ret = ltv350qv_write_reg(lcd, LTV_IFCTL,
11633 + LTV_NMD | LTV_REV | LTV_NL(0x1d));
11634 + ret |= ltv350qv_write_reg(lcd, LTV_DATACTL,
11635 + LTV_DS_SAME | LTV_CHS_480
11636 + | LTV_DF_RGB | LTV_RGB_BGR);
11637 + ret |= ltv350qv_write_reg(lcd, LTV_ENTRY_MODE,
11638 + LTV_VSPL_ACTIVE_LOW
11639 + | LTV_HSPL_ACTIVE_LOW
11640 + | LTV_DPL_SAMPLE_RISING
11641 + | LTV_EPL_ACTIVE_LOW
11642 + | LTV_SS_RIGHT_TO_LEFT);
11643 + ret |= ltv350qv_write_reg(lcd, LTV_GATECTL1, LTV_CLW(3));
11644 + ret |= ltv350qv_write_reg(lcd, LTV_GATECTL2,
11645 + LTV_NW_INV_1LINE | LTV_FWI(3));
11646 + ret |= ltv350qv_write_reg(lcd, LTV_VBP, 0x000a);
11647 + ret |= ltv350qv_write_reg(lcd, LTV_HBP, 0x0021);
11648 + ret |= ltv350qv_write_reg(lcd, LTV_SOTCTL, LTV_SDT(3) | LTV_EQ(0));
11649 + ret |= ltv350qv_write_reg(lcd, LTV_GAMMA(0), 0x0103);
11650 + ret |= ltv350qv_write_reg(lcd, LTV_GAMMA(1), 0x0301);
11651 + ret |= ltv350qv_write_reg(lcd, LTV_GAMMA(2), 0x1f0f);
11652 + ret |= ltv350qv_write_reg(lcd, LTV_GAMMA(3), 0x1f0f);
11653 + ret |= ltv350qv_write_reg(lcd, LTV_GAMMA(4), 0x0707);
11654 + ret |= ltv350qv_write_reg(lcd, LTV_GAMMA(5), 0x0307);
11655 + ret |= ltv350qv_write_reg(lcd, LTV_GAMMA(6), 0x0707);
11656 + ret |= ltv350qv_write_reg(lcd, LTV_GAMMA(7), 0x0000);
11657 + ret |= ltv350qv_write_reg(lcd, LTV_GAMMA(8), 0x0004);
11658 + ret |= ltv350qv_write_reg(lcd, LTV_GAMMA(9), 0x0000);
11660 + goto err_settings;
11662 + /* Wait more than 2 frames */
11665 + /* Display On Sequence */
11666 + ret = ltv350qv_write_reg(lcd, LTV_PWRCTL1,
11667 + LTV_VCOM_DISABLE | LTV_VCOMOUT_ENABLE
11668 + | LTV_POWER_ON | LTV_DRIVE_CURRENT(5)
11669 + | LTV_SUPPLY_CURRENT(5));
11670 + ret |= ltv350qv_write_reg(lcd, LTV_GATECTL2,
11671 + LTV_NW_INV_1LINE | LTV_DSC | LTV_FWI(3));
11673 + goto err_disp_on;
11675 + /* Display should now be ON. Phew. */
11680 + * Try to recover. Error handling probably isn't very useful
11681 + * at this point, just make a best effort to switch the panel
11684 + ltv350qv_write_reg(lcd, LTV_PWRCTL1,
11685 + LTV_VCOM_DISABLE | LTV_DRIVE_CURRENT(5)
11686 + | LTV_SUPPLY_CURRENT(5));
11687 + ltv350qv_write_reg(lcd, LTV_GATECTL2,
11688 + LTV_NW_INV_1LINE | LTV_FWI(3));
11692 + ltv350qv_write_reg(lcd, LTV_PWRCTL2, 0x0000);
11695 + ltv350qv_write_reg(lcd, LTV_PWRCTL1, LTV_VCOM_DISABLE);
11699 +static int ltv350qv_power_off(struct ltv350qv *lcd)
11703 + /* Display Off Sequence */
11704 + ret = ltv350qv_write_reg(lcd, LTV_PWRCTL1,
11706 + | LTV_DRIVE_CURRENT(5)
11707 + | LTV_SUPPLY_CURRENT(5));
11708 + ret |= ltv350qv_write_reg(lcd, LTV_GATECTL2,
11709 + LTV_NW_INV_1LINE | LTV_FWI(3));
11711 + /* Power down setting 1 */
11712 + ret |= ltv350qv_write_reg(lcd, LTV_PWRCTL2, 0x0000);
11714 + /* Wait at least 1 ms */
11717 + /* Power down setting 2 */
11718 + ret |= ltv350qv_write_reg(lcd, LTV_PWRCTL1, LTV_VCOM_DISABLE);
11721 + * No point in trying to recover here. If we can't switch the
11722 + * panel off, what are we supposed to do other than inform the
11723 + * user about the failure?
11728 + /* Display power should now be OFF */
11732 +static int ltv350qv_power(struct ltv350qv *lcd, int power)
11736 + if (POWER_IS_ON(power) && !POWER_IS_ON(lcd->power))
11737 + ret = ltv350qv_power_on(lcd);
11738 + else if (!POWER_IS_ON(power) && POWER_IS_ON(lcd->power))
11739 + ret = ltv350qv_power_off(lcd);
11742 + lcd->power = power;
11747 +static int ltv350qv_set_power(struct lcd_device *ld, int power)
11749 + struct ltv350qv *lcd;
11751 + lcd = class_get_devdata(&ld->class_dev);
11752 + return ltv350qv_power(lcd, power);
11755 +static int ltv350qv_get_power(struct lcd_device *ld)
11757 + struct ltv350qv *lcd;
11759 + lcd = class_get_devdata(&ld->class_dev);
11760 + return lcd->power;
11763 +static struct lcd_ops ltv_ops = {
11764 + .get_power = ltv350qv_get_power,
11765 + .set_power = ltv350qv_set_power,
11768 +static int __devinit ltv350qv_probe(struct spi_device *spi)
11770 + struct ltv350qv *lcd;
11771 + struct lcd_device *ld;
11774 + lcd = kzalloc(sizeof(struct ltv350qv), GFP_KERNEL);
11779 + lcd->power = FB_BLANK_POWERDOWN;
11780 + lcd->buffer = kzalloc(8, GFP_KERNEL);
11782 + ld = lcd_device_register("ltv350qv", lcd, <v_ops);
11783 + if (IS_ERR(ld)) {
11784 + ret = PTR_ERR(ld);
11785 + goto out_free_lcd;
11789 + ret = ltv350qv_power(lcd, FB_BLANK_UNBLANK);
11791 + goto out_unregister;
11793 + dev_set_drvdata(&spi->dev, lcd);
11798 + lcd_device_unregister(ld);
11804 +static int __devexit ltv350qv_remove(struct spi_device *spi)
11806 + struct ltv350qv *lcd = dev_get_drvdata(&spi->dev);
11808 + ltv350qv_power(lcd, FB_BLANK_POWERDOWN);
11809 + lcd_device_unregister(lcd->ld);
11816 +static int ltv350qv_suspend(struct spi_device *spi,
11817 + pm_message_t state, u32 level)
11819 + struct ltv350qv *lcd = dev_get_drvdata(&spi->dev);
11821 + if (level == SUSPEND_POWER_DOWN)
11822 + return ltv350qv_power(lcd, FB_BLANK_POWERDOWN);
11827 +static int ltv350qv_resume(struct spi_device *spi, u32 level)
11829 + struct ltv350qv *lcd = dev_get_drvdata(&spi->dev);
11831 + if (level == RESUME_POWER_ON)
11832 + return ltv350qv_power(lcd, FB_BLANK_UNBLANK);
11837 +#define ltv350qv_suspend NULL
11838 +#define ltv350qv_resume NULL
11841 +/* Power down all displays on reboot, poweroff or halt */
11842 +static void ltv350qv_shutdown(struct spi_device *spi)
11844 + struct ltv350qv *lcd = dev_get_drvdata(&spi->dev);
11846 + ltv350qv_power(lcd, FB_BLANK_POWERDOWN);
11849 +static struct spi_driver ltv350qv_driver = {
11851 + .name = "ltv350qv",
11852 + .bus = &spi_bus_type,
11853 + .owner = THIS_MODULE,
11856 + .probe = ltv350qv_probe,
11857 + .remove = __devexit_p(ltv350qv_remove),
11858 + .shutdown = ltv350qv_shutdown,
11859 + .suspend = ltv350qv_suspend,
11860 + .resume = ltv350qv_resume,
11863 +static int __init ltv350qv_init(void)
11865 + return spi_register_driver(<v350qv_driver);
11868 +static void __exit ltv350qv_exit(void)
11870 + spi_unregister_driver(<v350qv_driver);
11872 +module_init(ltv350qv_init);
11873 +module_exit(ltv350qv_exit);
11875 +MODULE_AUTHOR("Haavard Skinnemoen <hskinnemoen@atmel.com>");
11876 +MODULE_DESCRIPTION("Samsung LTV350QV LCD Driver");
11877 +MODULE_LICENSE("GPL");
11878 diff -x .git -Nur linux-2.6.22.1/drivers/video/backlight/ltv350qv.h linux-avr32.git/drivers/video/backlight/ltv350qv.h
11879 --- linux-2.6.22.1/drivers/video/backlight/ltv350qv.h 1970-01-01 01:00:00.000000000 +0100
11880 +++ linux-avr32.git/drivers/video/backlight/ltv350qv.h 2007-06-06 11:34:00.000000000 +0200
11883 + * Register definitions for Samsung LTV350QV Quarter VGA LCD Panel
11885 + * Copyright (C) 2006, 2007 Atmel Corporation
11887 + * This program is free software; you can redistribute it and/or modify
11888 + * it under the terms of the GNU General Public License version 2 as
11889 + * published by the Free Software Foundation.
11891 +#ifndef __LTV350QV_H
11892 +#define __LTV350QV_H
11894 +#define LTV_OPC_INDEX 0x74
11895 +#define LTV_OPC_DATA 0x76
11897 +#define LTV_ID 0x00 /* ID Read */
11898 +#define LTV_IFCTL 0x01 /* Display Interface Control */
11899 +#define LTV_DATACTL 0x02 /* Display Data Control */
11900 +#define LTV_ENTRY_MODE 0x03 /* Entry Mode */
11901 +#define LTV_GATECTL1 0x04 /* Gate Control 1 */
11902 +#define LTV_GATECTL2 0x05 /* Gate Control 2 */
11903 +#define LTV_VBP 0x06 /* Vertical Back Porch */
11904 +#define LTV_HBP 0x07 /* Horizontal Back Porch */
11905 +#define LTV_SOTCTL 0x08 /* Source Output Timing Control */
11906 +#define LTV_PWRCTL1 0x09 /* Power Control 1 */
11907 +#define LTV_PWRCTL2 0x0a /* Power Control 2 */
11908 +#define LTV_GAMMA(x) (0x10 + (x)) /* Gamma control */
11910 +/* Bit definitions for LTV_IFCTL */
11911 +#define LTV_IM (1 << 15)
11912 +#define LTV_NMD (1 << 14)
11913 +#define LTV_SSMD (1 << 13)
11914 +#define LTV_REV (1 << 7)
11915 +#define LTV_NL(x) (((x) & 0x001f) << 0)
11917 +/* Bit definitions for LTV_DATACTL */
11918 +#define LTV_DS_SAME (0 << 12)
11919 +#define LTV_DS_D_TO_S (1 << 12)
11920 +#define LTV_DS_S_TO_D (2 << 12)
11921 +#define LTV_CHS_384 (0 << 9)
11922 +#define LTV_CHS_480 (1 << 9)
11923 +#define LTV_CHS_492 (2 << 9)
11924 +#define LTV_DF_RGB (0 << 6)
11925 +#define LTV_DF_RGBX (1 << 6)
11926 +#define LTV_DF_XRGB (2 << 6)
11927 +#define LTV_RGB_RGB (0 << 2)
11928 +#define LTV_RGB_BGR (1 << 2)
11929 +#define LTV_RGB_GRB (2 << 2)
11930 +#define LTV_RGB_RBG (3 << 2)
11932 +/* Bit definitions for LTV_ENTRY_MODE */
11933 +#define LTV_VSPL_ACTIVE_LOW (0 << 15)
11934 +#define LTV_VSPL_ACTIVE_HIGH (1 << 15)
11935 +#define LTV_HSPL_ACTIVE_LOW (0 << 14)
11936 +#define LTV_HSPL_ACTIVE_HIGH (1 << 14)
11937 +#define LTV_DPL_SAMPLE_RISING (0 << 13)
11938 +#define LTV_DPL_SAMPLE_FALLING (1 << 13)
11939 +#define LTV_EPL_ACTIVE_LOW (0 << 12)
11940 +#define LTV_EPL_ACTIVE_HIGH (1 << 12)
11941 +#define LTV_SS_LEFT_TO_RIGHT (0 << 8)
11942 +#define LTV_SS_RIGHT_TO_LEFT (1 << 8)
11943 +#define LTV_STB (1 << 1)
11945 +/* Bit definitions for LTV_GATECTL1 */
11946 +#define LTV_CLW(x) (((x) & 0x0007) << 12)
11947 +#define LTV_GAON (1 << 5)
11948 +#define LTV_SDR (1 << 3)
11950 +/* Bit definitions for LTV_GATECTL2 */
11951 +#define LTV_NW_INV_FRAME (0 << 14)
11952 +#define LTV_NW_INV_1LINE (1 << 14)
11953 +#define LTV_NW_INV_2LINE (2 << 14)
11954 +#define LTV_DSC (1 << 12)
11955 +#define LTV_GIF (1 << 8)
11956 +#define LTV_FHN (1 << 7)
11957 +#define LTV_FTI(x) (((x) & 0x0003) << 4)
11958 +#define LTV_FWI(x) (((x) & 0x0003) << 0)
11960 +/* Bit definitions for LTV_SOTCTL */
11961 +#define LTV_SDT(x) (((x) & 0x0007) << 10)
11962 +#define LTV_EQ(x) (((x) & 0x0007) << 2)
11964 +/* Bit definitions for LTV_PWRCTL1 */
11965 +#define LTV_VCOM_DISABLE (1 << 14)
11966 +#define LTV_VCOMOUT_ENABLE (1 << 11)
11967 +#define LTV_POWER_ON (1 << 9)
11968 +#define LTV_DRIVE_CURRENT(x) (((x) & 0x0007) << 4) /* 0=off, 5=max */
11969 +#define LTV_SUPPLY_CURRENT(x) (((x) & 0x0007) << 0) /* 0=off, 5=max */
11971 +/* Bit definitions for LTV_PWRCTL2 */
11972 +#define LTV_VCOML_ENABLE (1 << 13)
11973 +#define LTV_VCOML_VOLTAGE(x) (((x) & 0x001f) << 8) /* 0=1V, 31=-1V */
11974 +#define LTV_VCOMH_VOLTAGE(x) (((x) & 0x001f) << 0) /* 0=3V, 31=4.5V */
11976 +#endif /* __LTV350QV_H */
11977 diff -x .git -Nur linux-2.6.22.1/drivers/video/backlight/Makefile linux-avr32.git/drivers/video/backlight/Makefile
11978 --- linux-2.6.22.1/drivers/video/backlight/Makefile 2007-07-10 20:56:30.000000000 +0200
11979 +++ linux-avr32.git/drivers/video/backlight/Makefile 2007-07-12 14:00:20.000000000 +0200
11981 # Backlight & LCD drivers
11983 obj-$(CONFIG_LCD_CLASS_DEVICE) += lcd.o
11984 +obj-$(CONFIG_LCD_LTV350QV) += ltv350qv.o
11986 obj-$(CONFIG_BACKLIGHT_CLASS_DEVICE) += backlight.o
11987 obj-$(CONFIG_BACKLIGHT_CORGI) += corgi_bl.o
11988 obj-$(CONFIG_BACKLIGHT_HP680) += hp680_bl.o
11989 diff -x .git -Nur linux-2.6.22.1/drivers/video/Kconfig linux-avr32.git/drivers/video/Kconfig
11990 --- linux-2.6.22.1/drivers/video/Kconfig 2007-07-10 20:56:30.000000000 +0200
11991 +++ linux-avr32.git/drivers/video/Kconfig 2007-07-12 14:00:20.000000000 +0200
11992 @@ -849,6 +849,16 @@
11993 Say Y if you want to map Frame Buffer in internal SRAM. Say N if you want
11994 to let frame buffer in external SDRAM.
11996 +config FB_ATMEL_STN
11997 + bool "Use a STN display with AT91/AT32 LCD Controller"
11998 + depends on FB_ATMEL && ARCH_AT91SAM9261
12001 + Say Y if you want to connect a STN LCD display to the AT91/AT32 LCD
12002 + Controller. Say N if you want to connect a TFT.
12004 + If unsure, say N.
12007 tristate "nVidia Framebuffer Support"
12008 depends on FB && PCI
12009 diff -x .git -Nur linux-2.6.22.1/include/asm-arm/arch-at91/board.h linux-avr32.git/include/asm-arm/arch-at91/board.h
12010 --- linux-2.6.22.1/include/asm-arm/arch-at91/board.h 2007-07-10 20:56:30.000000000 +0200
12011 +++ linux-avr32.git/include/asm-arm/arch-at91/board.h 2007-07-12 14:00:26.000000000 +0200
12014 /* Ethernet (EMAC & MACB) */
12015 struct at91_eth_data {
12017 u8 phy_irq_pin; /* PHY IRQ */
12018 u8 is_rmii; /* using RMII interface? */
12020 diff -x .git -Nur linux-2.6.22.1/include/asm-avr32/arch-at32ap/board.h linux-avr32.git/include/asm-avr32/arch-at32ap/board.h
12021 --- linux-2.6.22.1/include/asm-avr32/arch-at32ap/board.h 2007-07-10 20:56:30.000000000 +0200
12022 +++ linux-avr32.git/include/asm-avr32/arch-at32ap/board.h 2007-07-12 14:00:26.000000000 +0200
12025 #include <linux/types.h>
12027 +#define GPIO_PIN_NONE (-1)
12029 /* Add basic devices: system manager, interrupt controller, portmuxes, etc. */
12030 void at32_add_system_devices(void);
12033 struct platform_device *at32_add_device_usart(unsigned int id);
12035 struct eth_platform_data {
12039 struct platform_device *
12041 struct platform_device *
12042 at32_add_device_spi(unsigned int id, struct spi_board_info *b, unsigned int n);
12044 +struct platform_device *at32_add_device_twi(unsigned int id);
12046 +struct mci_platform_data {
12050 +struct platform_device *
12051 +at32_add_device_mci(unsigned int id, struct mci_platform_data *data);
12053 +struct usba_platform_data {
12056 +struct platform_device *
12057 +at32_add_device_usba(unsigned int id, struct usba_platform_data *data);
12059 struct atmel_lcdfb_info;
12060 struct platform_device *
12061 at32_add_device_lcdc(unsigned int id, struct atmel_lcdfb_info *data,
12062 unsigned long fbmem_start, unsigned long fbmem_len);
12064 +struct platform_device *at32_add_device_ac97c(unsigned int id);
12065 +struct platform_device *at32_add_device_abdac(unsigned int id);
12067 +/* depending on what's hooked up, not all SSC pins will be used */
12068 +#define ATMEL_SSC_TK 0x01
12069 +#define ATMEL_SSC_TF 0x02
12070 +#define ATMEL_SSC_TD 0x04
12071 +#define ATMEL_SSC_TX (ATMEL_SSC_TK | ATMEL_SSC_TF | ATMEL_SSC_TD)
12073 +#define ATMEL_SSC_RK 0x10
12074 +#define ATMEL_SSC_RF 0x20
12075 +#define ATMEL_SSC_RD 0x40
12076 +#define ATMEL_SSC_RX (ATMEL_SSC_RK | ATMEL_SSC_RF | ATMEL_SSC_RD)
12078 +struct platform_device *
12079 +at32_add_device_ssc(unsigned int id, unsigned int flags);
12081 #endif /* __ASM_ARCH_BOARD_H */
12082 diff -x .git -Nur linux-2.6.22.1/include/asm-avr32/arch-at32ap/portmux.h linux-avr32.git/include/asm-avr32/arch-at32ap/portmux.h
12083 --- linux-2.6.22.1/include/asm-avr32/arch-at32ap/portmux.h 2007-07-10 20:56:30.000000000 +0200
12084 +++ linux-avr32.git/include/asm-avr32/arch-at32ap/portmux.h 2007-07-12 14:00:26.000000000 +0200
12086 void at32_select_gpio(unsigned int pin, unsigned long flags);
12087 void at32_reserve_pin(unsigned int pin);
12089 +#ifdef CONFIG_GPIO_DEV
12091 +/* Gang allocators and accessors; used by the GPIO /dev driver */
12092 +int at32_gpio_port_is_valid(unsigned int port);
12093 +int at32_select_gpio_pins(unsigned int port, u32 pins, u32 oe_mask);
12094 +void at32_deselect_pins(unsigned int port, u32 pins);
12096 +u32 at32_gpio_get_value_multiple(unsigned int port, u32 pins);
12097 +void at32_gpio_set_value_multiple(unsigned int port, u32 value, u32 mask);
12099 +#endif /* CONFIG_GPIO_DEV */
12101 #endif /* __ASM_ARCH_PORTMUX_H__ */
12102 diff -x .git -Nur linux-2.6.22.1/include/asm-avr32/arch-at32ap/sm.h linux-avr32.git/include/asm-avr32/arch-at32ap/sm.h
12103 --- linux-2.6.22.1/include/asm-avr32/arch-at32ap/sm.h 2007-07-10 20:56:30.000000000 +0200
12104 +++ linux-avr32.git/include/asm-avr32/arch-at32ap/sm.h 1970-01-01 01:00:00.000000000 +0100
12107 - * AT32 System Manager interface.
12109 - * Copyright (C) 2006 Atmel Corporation
12111 - * This program is free software; you can redistribute it and/or modify
12112 - * it under the terms of the GNU General Public License version 2 as
12113 - * published by the Free Software Foundation.
12115 -#ifndef __ASM_AVR32_AT32_SM_H__
12116 -#define __ASM_AVR32_AT32_SM_H__
12119 -struct platform_device;
12123 - void __iomem *regs;
12124 - struct irq_chip *eim_chip;
12125 - unsigned int eim_first_irq;
12126 - struct platform_device *pdev;
12129 -extern struct platform_device at32_sm_device;
12130 -extern struct at32_sm system_manager;
12132 -#endif /* __ASM_AVR32_AT32_SM_H__ */
12133 diff -x .git -Nur linux-2.6.22.1/include/asm-avr32/dma-controller.h linux-avr32.git/include/asm-avr32/dma-controller.h
12134 --- linux-2.6.22.1/include/asm-avr32/dma-controller.h 1970-01-01 01:00:00.000000000 +0100
12135 +++ linux-avr32.git/include/asm-avr32/dma-controller.h 2007-06-06 11:34:11.000000000 +0200
12138 + * Copyright (C) 2005-2006 Atmel Corporation
12140 + * This program is free software; you can redistribute it and/or modify
12141 + * it under the terms of the GNU General Public License version 2 as
12142 + * published by the Free Software Foundation.
12144 +#ifndef __ASM_AVR32_DMA_CONTROLLER_H
12145 +#define __ASM_AVR32_DMA_CONTROLLER_H
12147 +#include <linux/device.h>
12149 +#define DMA_DIR_MEM_TO_MEM 0x0000
12150 +#define DMA_DIR_MEM_TO_PERIPH 0x0001
12151 +#define DMA_DIR_PERIPH_TO_MEM 0x0002
12152 +#define DMA_DIR_PERIPH_TO_PERIPH 0x0003
12154 +#define DMA_WIDTH_8BIT 0
12155 +#define DMA_WIDTH_16BIT 1
12156 +#define DMA_WIDTH_32BIT 2
12158 +struct dma_request {
12159 + struct dma_controller *dmac;
12160 + struct list_head list;
12162 + unsigned short channel;
12164 + void (*xfer_complete)(struct dma_request *req);
12165 + void (*block_complete)(struct dma_request *req);
12166 + void (*error)(struct dma_request *req);
12169 +struct dma_request_sg {
12170 + struct dma_request req;
12173 + struct scatterlist *sg;
12174 + unsigned long block_size;
12175 + unsigned int nr_blocks;
12177 + dma_addr_t data_reg;
12178 + unsigned short periph_id;
12180 + unsigned char direction;
12181 + unsigned char width;
12183 +#define to_dma_request_sg(_req) \
12184 + container_of(_req, struct dma_request_sg, req)
12186 +struct dma_request_cyclic {
12187 + struct dma_request req;
12190 + unsigned long buffer_size;
12192 + dma_addr_t buffer_start;
12193 + dma_addr_t data_reg;
12195 + unsigned short periph_id;
12196 + unsigned char direction;
12197 + unsigned char width;
12201 +#define to_dma_request_cyclic(_req) \
12202 + container_of(_req, struct dma_request_cyclic, req)
12204 +struct dma_request_memcpy {
12205 + struct dma_request req;
12207 + dma_addr_t src_addr;
12208 + unsigned int src_width;
12209 + unsigned int src_stride;
12211 + dma_addr_t dst_addr;
12212 + unsigned int dst_width;
12213 + unsigned int dst_stride;
12217 + unsigned short src_reverse:1;
12218 + unsigned short dst_reverse:1;
12220 +#define to_dma_request_memcpy(_req) \
12221 + container_of(_req, struct dma_request_memcpy, req)
12223 +struct dma_controller {
12224 + struct list_head list;
12226 + struct device *dev;
12228 + int (*alloc_channel)(struct dma_controller *dmac);
12229 + void (*release_channel)(struct dma_controller *dmac,
12231 + int (*prepare_request_sg)(struct dma_controller *dmac,
12232 + struct dma_request_sg *req);
12233 + int (*prepare_request_cyclic)(struct dma_controller *dmac,
12234 + struct dma_request_cyclic *req);
12235 + int (*prepare_request_memcpy)(struct dma_controller *dmac,
12236 + struct dma_request_memcpy *req);
12237 + int (*start_request)(struct dma_controller *dmac,
12238 + unsigned int channel);
12239 + int (*stop_request)(struct dma_controller *dmac,
12240 + unsigned int channel);
12241 + dma_addr_t (*get_current_pos)(struct dma_controller *dmac,
12242 + unsigned int channel);
12246 +dma_alloc_channel(struct dma_controller *dmac)
12248 + return dmac->alloc_channel(dmac);
12251 +static inline void
12252 +dma_release_channel(struct dma_controller *dmac, int chan)
12254 + dmac->release_channel(dmac, chan);
12258 +dma_prepare_request_sg(struct dma_controller *dmac,
12259 + struct dma_request_sg *req)
12261 + return dmac->prepare_request_sg(dmac, req);
12265 +dma_prepare_request_cyclic(struct dma_controller *dmac,
12266 + struct dma_request_cyclic *req)
12268 + return dmac->prepare_request_cyclic(dmac, req);
12272 +dma_prepare_request_memcpy(struct dma_controller *dmac,
12273 + struct dma_request_memcpy *req)
12275 + return dmac->prepare_request_memcpy(dmac, req);
12279 +dma_start_request(struct dma_controller *dmac,
12280 + unsigned int channel)
12282 + return dmac->start_request(dmac, channel);
12286 +dma_stop_request(struct dma_controller *dmac,
12287 + unsigned int channel)
12289 + return dmac->stop_request(dmac, channel);
12292 +static inline dma_addr_t
12293 +dma_get_current_pos(struct dma_controller *dmac,
12294 + unsigned int channel)
12296 + return dmac->get_current_pos(dmac, channel);
12299 +extern int register_dma_controller(struct dma_controller *dmac);
12300 +extern struct dma_controller *find_dma_controller(int id);
12302 +#endif /* __ASM_AVR32_DMA_CONTROLLER_H */
12303 diff -x .git -Nur linux-2.6.22.1/include/asm-avr32/unaligned.h linux-avr32.git/include/asm-avr32/unaligned.h
12304 --- linux-2.6.22.1/include/asm-avr32/unaligned.h 2007-07-10 20:56:30.000000000 +0200
12305 +++ linux-avr32.git/include/asm-avr32/unaligned.h 2007-07-12 14:00:26.000000000 +0200
12307 * words, but halfwords must be halfword-aligned, and doublewords must
12310 - * TODO: Make all this CPU-specific and optimize.
12311 + * However, swapped word loads must be word-aligned so we can't
12312 + * optimize word loads in general.
12315 -#include <linux/string.h>
12317 -/* Use memmove here, so gcc does not insert a __builtin_memcpy. */
12319 -#define get_unaligned(ptr) \
12320 - ({ __typeof__(*(ptr)) __tmp; memmove(&__tmp, (ptr), sizeof(*(ptr))); __tmp; })
12322 -#define put_unaligned(val, ptr) \
12323 - ({ __typeof__(*(ptr)) __tmp = (val); \
12324 - memmove((ptr), &__tmp, sizeof(*(ptr))); \
12326 +#include <asm-generic/unaligned.h>
12328 #endif /* __ASM_AVR32_UNALIGNED_H */
12329 diff -x .git -Nur linux-2.6.22.1/include/linux/gpio_mouse.h linux-avr32.git/include/linux/gpio_mouse.h
12330 --- linux-2.6.22.1/include/linux/gpio_mouse.h 1970-01-01 01:00:00.000000000 +0100
12331 +++ linux-avr32.git/include/linux/gpio_mouse.h 2007-07-13 11:24:16.000000000 +0200
12334 + * Driver for simulating a mouse on GPIO lines.
12336 + * Copyright (C) 2007 Atmel Corporation
12338 + * This program is free software; you can redistribute it and/or modify
12339 + * it under the terms of the GNU General Public License version 2 as
12340 + * published by the Free Software Foundation.
12343 +#ifndef _GPIO_MOUSE_H
12344 +#define _GPIO_MOUSE_H
12346 +#define GPIO_MOUSE_POLARITY_ACT_HIGH 0x00
12347 +#define GPIO_MOUSE_POLARITY_ACT_LOW 0x01
12349 +#define GPIO_MOUSE_PIN_UP 0
12350 +#define GPIO_MOUSE_PIN_DOWN 1
12351 +#define GPIO_MOUSE_PIN_LEFT 2
12352 +#define GPIO_MOUSE_PIN_RIGHT 3
12353 +#define GPIO_MOUSE_PIN_BLEFT 4
12354 +#define GPIO_MOUSE_PIN_BMIDDLE 5
12355 +#define GPIO_MOUSE_PIN_BRIGHT 6
12356 +#define GPIO_MOUSE_PIN_MAX 7
12359 + * struct gpio_mouse_platform_data
12360 + * @scan_ms: integer in ms specifying the scan periode.
12361 + * @polarity: Pin polarity, active high or low.
12362 + * @up: GPIO line for up value.
12363 + * @down: GPIO line for down value.
12364 + * @left: GPIO line for left value.
12365 + * @right: GPIO line for right value.
12366 + * @bleft: GPIO line for left button.
12367 + * @bmiddle: GPIO line for middle button.
12368 + * @bright: GPIO line for right button.
12370 + * This struct must be added to the platform_device in the board code.
12371 + * It is used by the gpio_mouse driver to setup GPIO lines and to
12372 + * calculate mouse movement.
12374 +struct gpio_mouse_platform_data {
12389 + int pins[GPIO_MOUSE_PIN_MAX];
12393 +#endif /* _GPIO_MOUSE_H */
12394 diff -x .git -Nur linux-2.6.22.1/include/linux/leds.h linux-avr32.git/include/linux/leds.h
12395 --- linux-2.6.22.1/include/linux/leds.h 2007-07-10 20:56:30.000000000 +0200
12396 +++ linux-avr32.git/include/linux/leds.h 2007-07-12 14:00:30.000000000 +0200
12397 @@ -110,4 +110,18 @@
12398 #define ledtrig_ide_activity() do {} while(0)
12401 +/* For the leds-gpio driver */
12403 + const char *name;
12404 + char *default_trigger;
12409 +struct gpio_led_platform_data {
12411 + struct gpio_led *leds;
12415 #endif /* __LINUX_LEDS_H_INCLUDED */
12416 diff -x .git -Nur linux-2.6.22.1/include/linux/usb/gadgetfs.h linux-avr32.git/include/linux/usb/gadgetfs.h
12417 --- linux-2.6.22.1/include/linux/usb/gadgetfs.h 1970-01-01 01:00:00.000000000 +0100
12418 +++ linux-avr32.git/include/linux/usb/gadgetfs.h 2007-07-12 14:00:31.000000000 +0200
12420 +#ifndef __LINUX_USB_GADGETFS_H
12421 +#define __LINUX_USB_GADGETFS_H
12423 +#include <asm/types.h>
12424 +#include <asm/ioctl.h>
12426 +#include <linux/usb/ch9.h>
12429 + * Filesystem based user-mode API to USB Gadget controller hardware
12431 + * Other than ep0 operations, most things are done by read() and write()
12432 + * on endpoint files found in one directory. They are configured by
12433 + * writing descriptors, and then may be used for normal stream style
12434 + * i/o requests. When ep0 is configured, the device can enumerate;
12435 + * when it's closed, the device disconnects from usb. Operations on
12436 + * ep0 require ioctl() operations.
12438 + * Configuration and device descriptors get written to /dev/gadget/$CHIP,
12439 + * which may then be used to read usb_gadgetfs_event structs. The driver
12440 + * may activate endpoints as it handles SET_CONFIGURATION setup events,
12441 + * or earlier; writing endpoint descriptors to /dev/gadget/$ENDPOINT
12442 + * then performing data transfers by reading or writing.
12446 + * Events are delivered on the ep0 file descriptor, when the user mode driver
12447 + * reads from this file descriptor after writing the descriptors. Don't
12448 + * stop polling this descriptor.
12451 +enum usb_gadgetfs_event_type {
12452 + GADGETFS_NOP = 0,
12454 + GADGETFS_CONNECT,
12455 + GADGETFS_DISCONNECT,
12457 + GADGETFS_SUSPEND,
12458 + // and likely more !
12461 +/* NOTE: this structure must stay the same size and layout on
12462 + * both 32-bit and 64-bit kernels.
12464 +struct usb_gadgetfs_event {
12466 + // NOP, DISCONNECT, SUSPEND: nothing
12467 + // ... some hardware can't report disconnection
12469 + // CONNECT: just the speed
12470 + enum usb_device_speed speed;
12472 + // SETUP: packet; DATA phase i/o precedes next event
12473 + // (setup.bmRequestType & USB_DIR_IN) flags direction
12474 + // ... includes SET_CONFIGURATION, SET_INTERFACE
12475 + struct usb_ctrlrequest setup;
12477 + enum usb_gadgetfs_event_type type;
12481 +/* endpoint ioctls */
12483 +/* IN transfers may be reported to the gadget driver as complete
12484 + * when the fifo is loaded, before the host reads the data;
12485 + * OUT transfers may be reported to the host's "client" driver as
12486 + * complete when they're sitting in the FIFO unread.
12487 + * THIS returns how many bytes are "unclaimed" in the endpoint fifo
12488 + * (needed for precise fault handling, when the hardware allows it)
12490 +#define GADGETFS_FIFO_STATUS _IO('g',1)
12492 +/* discards any unclaimed data in the fifo. */
12493 +#define GADGETFS_FIFO_FLUSH _IO('g',2)
12495 +/* resets endpoint halt+toggle; used to implement set_interface.
12496 + * some hardware (like pxa2xx) can't support this.
12498 +#define GADGETFS_CLEAR_HALT _IO('g',3)
12500 +#endif /* __LINUX_USB_GADGETFS_H */
12501 diff -x .git -Nur linux-2.6.22.1/include/linux/usb/Kbuild linux-avr32.git/include/linux/usb/Kbuild
12502 --- linux-2.6.22.1/include/linux/usb/Kbuild 2007-07-10 20:56:30.000000000 +0200
12503 +++ linux-avr32.git/include/linux/usb/Kbuild 2007-07-12 14:00:31.000000000 +0200
12505 unifdef-y += audio.h
12508 +unifdef-y += gadgetfs.h
12509 unifdef-y += midi.h
12511 diff -x .git -Nur linux-2.6.22.1/include/linux/usb_gadgetfs.h linux-avr32.git/include/linux/usb_gadgetfs.h
12512 --- linux-2.6.22.1/include/linux/usb_gadgetfs.h 2007-07-10 20:56:30.000000000 +0200
12513 +++ linux-avr32.git/include/linux/usb_gadgetfs.h 1970-01-01 01:00:00.000000000 +0100
12516 -#include <asm/types.h>
12517 -#include <asm/ioctl.h>
12519 -#include <linux/usb/ch9.h>
12522 - * Filesystem based user-mode API to USB Gadget controller hardware
12524 - * Almost everything can be done with only read and write operations,
12525 - * on endpoint files found in one directory. They are configured by
12526 - * writing descriptors, and then may be used for normal stream style
12527 - * i/o requests. When ep0 is configured, the device can enumerate;
12528 - * when it's closed, the device disconnects from usb.
12530 - * Configuration and device descriptors get written to /dev/gadget/$CHIP,
12531 - * which may then be used to read usb_gadgetfs_event structs. The driver
12532 - * may activate endpoints as it handles SET_CONFIGURATION setup events,
12533 - * or earlier; writing endpoint descriptors to /dev/gadget/$ENDPOINT
12534 - * then performing data transfers by reading or writing.
12538 - * Events are delivered on the ep0 file descriptor, if the user mode driver
12539 - * reads from this file descriptor after writing the descriptors. Don't
12540 - * stop polling this descriptor, if you write that kind of driver.
12543 -enum usb_gadgetfs_event_type {
12544 - GADGETFS_NOP = 0,
12546 - GADGETFS_CONNECT,
12547 - GADGETFS_DISCONNECT,
12549 - GADGETFS_SUSPEND,
12550 - // and likely more !
12553 -struct usb_gadgetfs_event {
12554 - enum usb_gadgetfs_event_type type;
12556 - // NOP, DISCONNECT, SUSPEND: nothing
12557 - // ... some hardware can't report disconnection
12559 - // CONNECT: just the speed
12560 - enum usb_device_speed speed;
12562 - // SETUP: packet; DATA phase i/o precedes next event
12563 - // (setup.bmRequestType & USB_DIR_IN) flags direction
12564 - // ... includes SET_CONFIGURATION, SET_INTERFACE
12565 - struct usb_ctrlrequest setup;
12570 -/* endpoint ioctls */
12572 -/* IN transfers may be reported to the gadget driver as complete
12573 - * when the fifo is loaded, before the host reads the data;
12574 - * OUT transfers may be reported to the host's "client" driver as
12575 - * complete when they're sitting in the FIFO unread.
12576 - * THIS returns how many bytes are "unclaimed" in the endpoint fifo
12577 - * (needed for precise fault handling, when the hardware allows it)
12579 -#define GADGETFS_FIFO_STATUS _IO('g',1)
12581 -/* discards any unclaimed data in the fifo. */
12582 -#define GADGETFS_FIFO_FLUSH _IO('g',2)
12584 -/* resets endpoint halt+toggle; used to implement set_interface.
12585 - * some hardware (like pxa2xx) can't support this.
12587 -#define GADGETFS_CLEAR_HALT _IO('g',3)
12590 diff -x .git -Nur linux-2.6.22.1/init/do_mounts.c linux-avr32.git/init/do_mounts.c
12591 --- linux-2.6.22.1/init/do_mounts.c 2007-07-10 20:56:30.000000000 +0200
12592 +++ linux-avr32.git/init/do_mounts.c 2007-07-12 14:00:31.000000000 +0200
12594 int root_mountflags = MS_RDONLY | MS_SILENT;
12595 char * __initdata root_device_name;
12596 static char __initdata saved_root_name[64];
12597 +int __initdata root_wait;
12601 @@ -216,6 +217,14 @@
12603 __setup("root=", root_dev_setup);
12605 +static int __init rootwait_setup(char *line)
12607 + root_wait = simple_strtol(line,NULL,0);
12611 +__setup("rootwait=", rootwait_setup);
12613 static char * __initdata root_mount_data;
12614 static int __init root_data_setup(char *str)
12616 @@ -438,11 +447,24 @@
12617 root_device_name += 5;
12620 - is_floppy = MAJOR(ROOT_DEV) == FLOPPY_MAJOR;
12625 + /* wait for any asynchronous scanning to complete */
12626 + if ((ROOT_DEV == 0) && root_wait) {
12627 + printk(KERN_INFO "Waiting for root device %s...\n",
12628 + saved_root_name);
12630 + while (driver_probe_done() != 0)
12632 + ROOT_DEV = name_to_dev_t(saved_root_name);
12633 + if (ROOT_DEV == 0)
12635 + } while (ROOT_DEV == 0);
12638 + is_floppy = MAJOR(ROOT_DEV) == FLOPPY_MAJOR;
12640 if (is_floppy && rd_doload && rd_load_disk(0))
12641 ROOT_DEV = Root_RAM0;
12643 diff -x .git -Nur linux-2.6.22.1/MAINTAINERS linux-avr32.git/MAINTAINERS
12644 --- linux-2.6.22.1/MAINTAINERS 2007-07-10 20:56:30.000000000 +0200
12645 +++ linux-avr32.git/MAINTAINERS 2007-07-12 13:59:48.000000000 +0200
12646 @@ -674,6 +674,13 @@
12647 M: hskinnemoen@atmel.com
12650 +ATMEL USBA UDC DRIVER
12651 +P: Haavard Skinnemoen
12652 +M: hskinnemoen@atmel.com
12653 +L: kernel@avr32linux.org
12654 +W: http://avr32linux.org/twiki/bin/view/Main/AtmelUsbDeviceDriver
12657 ATMEL WIRELESS DRIVER
12659 M: simon@thekelleys.org.uk
12660 diff -x .git -Nur linux-2.6.22.1/scripts/checkstack.pl linux-avr32.git/scripts/checkstack.pl
12661 --- linux-2.6.22.1/scripts/checkstack.pl 2007-07-10 20:56:30.000000000 +0200
12662 +++ linux-avr32.git/scripts/checkstack.pl 2007-06-06 11:34:14.000000000 +0200
12664 # sh64 port by Paul Mundt
12665 # Random bits by Matt Mackall <mpm@selenic.com>
12666 # M68k port by Geert Uytterhoeven and Andreas Schwab
12667 +# AVR32 port by Haavard Skinnemoen <hskinnemoen@atmel.com>
12670 # objdump -d vmlinux | stackcheck.pl [arch]
12672 if ($arch eq 'arm') {
12673 #c0008ffc: e24dd064 sub sp, sp, #100 ; 0x64
12674 $re = qr/.*sub.*sp, sp, #(([0-9]{2}|[3-9])[0-9]{2})/o;
12675 + } elsif ($arch eq 'avr32') {
12676 + #8000008a: 20 1d sub sp,4
12677 + #80000ca8: fa cd 05 b0 sub sp,sp,1456
12678 + $re = qr/^.*sub.*sp.*,([0-9]{1,8})/o;
12679 } elsif ($arch =~ /^i[3456]86$/) {
12680 #c0105234: 81 ec ac 05 00 00 sub $0x5ac,%esp
12681 $re = qr/^.*[as][du][db] \$(0x$x{1,8}),\%esp$/o;