1 diff -x .git -Nur linux-2.6.22.1/arch/avr32/boards/atngw100/setup.c linux-avr32.git/arch/avr32/boards/atngw100/setup.c
2 --- linux-2.6.22.1/arch/avr32/boards/atngw100/setup.c 2007-07-10 20:56:30.000000000 +0200
3 +++ linux-avr32.git/arch/avr32/boards/atngw100/setup.c 2007-07-12 13:59:49.000000000 +0200
5 #include <linux/linkage.h>
6 #include <linux/platform_device.h>
7 #include <linux/types.h>
8 +#include <linux/leds.h>
9 #include <linux/spi/spi.h>
13 #include <asm/arch/at32ap7000.h>
14 #include <asm/arch/board.h>
15 #include <asm/arch/init.h>
16 +#include <asm/arch/portmux.h>
18 /* Initialized by bootloader-specific startup code. */
19 struct tag *bootloader_tags __initdata;
24 +static struct mci_platform_data __initdata mci0_data = {
25 + .detect_pin = GPIO_PIN_PC(25),
26 + .wp_pin = GPIO_PIN_PE(0),
30 * The next two functions should go away as the boot loader is
31 * supposed to initialize the macb address registers with a valid
33 at32_setup_serial_console(0);
36 +static const struct gpio_led ngw_leds[] = {
37 + { .name = "sys", .gpio = GPIO_PIN_PA(16), .active_low = 1,
38 + .default_trigger = "heartbeat",
40 + { .name = "a", .gpio = GPIO_PIN_PA(19), .active_low = 1, },
41 + { .name = "b", .gpio = GPIO_PIN_PE(19), .active_low = 1, },
44 +static const struct gpio_led_platform_data ngw_led_data = {
45 + .num_leds = ARRAY_SIZE(ngw_leds),
46 + .leds = (void *) ngw_leds,
49 +static struct platform_device ngw_gpio_leds = {
50 + .name = "leds-gpio",
53 + .platform_data = (void *) &ngw_led_data,
57 static int __init atngw100_init(void)
62 * ATNGW100 uses 16-bit SDRAM interface, so we don't need to
63 * reserve any pins for it.
65 set_hw_addr(at32_add_device_eth(1, ð_data[1]));
67 at32_add_device_spi(0, spi0_board_info, ARRAY_SIZE(spi0_board_info));
68 + at32_add_device_mci(0, &mci0_data);
69 + at32_add_device_usba(0, NULL);
71 + for (i = 0; i < ARRAY_SIZE(ngw_leds); i++) {
72 + at32_select_gpio(ngw_leds[i].gpio,
73 + AT32_GPIOF_OUTPUT | AT32_GPIOF_HIGH);
75 + platform_device_register(&ngw_gpio_leds);
79 diff -x .git -Nur linux-2.6.22.1/arch/avr32/boards/atstk1000/atstk1002.c linux-avr32.git/arch/avr32/boards/atstk1000/atstk1002.c
80 --- linux-2.6.22.1/arch/avr32/boards/atstk1000/atstk1002.c 2007-07-10 20:56:30.000000000 +0200
81 +++ linux-avr32.git/arch/avr32/boards/atstk1000/atstk1002.c 2007-07-12 13:59:49.000000000 +0200
83 #include <linux/etherdevice.h>
84 #include <linux/init.h>
85 #include <linux/kernel.h>
86 +#include <linux/leds.h>
87 #include <linux/platform_device.h>
88 #include <linux/string.h>
89 #include <linux/types.h>
92 #include "atstk1000.h"
94 -#define SW2_DEFAULT /* MMCI and UART_A available */
99 static struct eth_addr __initdata hw_addr[2];
100 static struct eth_platform_data __initdata eth_data[2];
102 +#ifndef CONFIG_BOARD_ATSTK1002_SW1_CUSTOM
103 static struct spi_board_info spi0_board_info[] __initdata = {
112 +#ifdef CONFIG_BOARD_ATSTK1002_SPI1
113 +static struct spi_board_info spi1_board_info[] __initdata = { {
114 + /* patch in custom entries here */
118 +static struct mci_platform_data __initdata mci0_data = {
119 + .detect_pin = GPIO_PIN_NONE,
120 + .wp_pin = GPIO_PIN_NONE,
124 * The next two functions should go away as the boot loader is
125 @@ -101,12 +114,71 @@
129 -void __init setup_board(void)
130 +#ifdef CONFIG_BOARD_ATSTK1002_J2_LED
132 +static struct gpio_led stk_j2_led[] = {
133 +#ifdef CONFIG_BOARD_ATSTK1002_J2_LED8
134 +#define LEDSTRING "J2 jumpered to LED8"
135 + { .name = "led0:amber", .gpio = GPIO_PIN_PB( 8), },
136 + { .name = "led1:amber", .gpio = GPIO_PIN_PB( 9), },
137 + { .name = "led2:amber", .gpio = GPIO_PIN_PB(10), },
138 + { .name = "led3:amber", .gpio = GPIO_PIN_PB(13), },
139 + { .name = "led4:amber", .gpio = GPIO_PIN_PB(14), },
140 + { .name = "led5:amber", .gpio = GPIO_PIN_PB(15), },
141 + { .name = "led6:amber", .gpio = GPIO_PIN_PB(16), },
142 + { .name = "led7:amber", .gpio = GPIO_PIN_PB(30),
143 + .default_trigger = "heartbeat", },
145 +#define LEDSTRING "J2 jumpered to RGB LEDs"
146 + { .name = "r1:red", .gpio = GPIO_PIN_PB( 8), },
147 + { .name = "g1:green", .gpio = GPIO_PIN_PB(10), },
148 + { .name = "b1:blue", .gpio = GPIO_PIN_PB(14), },
150 + { .name = "r2:red", .gpio = GPIO_PIN_PB( 9),
151 + .default_trigger = "heartbeat", },
152 + { .name = "g2:green", .gpio = GPIO_PIN_PB(13), },
153 + { .name = "b2:blue", .gpio = GPIO_PIN_PB(15),
154 + .default_trigger = "heartbeat", },
155 + /* PB16, PB30 unused */
159 +static struct gpio_led_platform_data stk_j2_led_data = {
160 + .num_leds = ARRAY_SIZE(stk_j2_led),
161 + .leds = stk_j2_led,
164 +static struct platform_device stk_j2_led_dev = {
165 + .name = "leds-gpio",
166 + .id = 2, /* gpio block J2 */
168 + .platform_data = &stk_j2_led_data,
172 +static void setup_j2_leds(void)
175 - at32_map_usart(1, 0); /* USART 1/A: /dev/ttyS0, DB9 */
178 + for (i = 0; i < ARRAY_SIZE(stk_j2_led); i++)
179 + at32_select_gpio(stk_j2_led[i].gpio, AT32_GPIOF_OUTPUT);
181 + printk("STK1002: " LEDSTRING "\n");
182 + platform_device_register(&stk_j2_led_dev);
186 +static void setup_j2_leds(void)
191 +void __init setup_board(void)
193 +#ifdef CONFIG_BOARD_ATSTK1002_SW2_CUSTOM
194 at32_map_usart(0, 1); /* USART 0/B: /dev/ttyS1, IRDA */
196 + at32_map_usart(1, 0); /* USART 1/A: /dev/ttyS0, DB9 */
198 /* USART 2/unused: expansion connector */
199 at32_map_usart(3, 2); /* USART 3/C: /dev/ttyS2, DB9 */
200 @@ -140,18 +212,40 @@
202 at32_add_system_devices();
205 - at32_add_device_usart(0);
207 +#ifdef CONFIG_BOARD_ATSTK1002_SW2_CUSTOM
208 at32_add_device_usart(1);
210 + at32_add_device_usart(0);
212 at32_add_device_usart(2);
214 +#ifndef CONFIG_BOARD_ATSTK1002_SW6_CUSTOM
215 set_hw_addr(at32_add_device_eth(0, ð_data[0]));
217 - at32_add_device_spi(0, spi0_board_info, ARRAY_SIZE(spi0_board_info));
219 +#ifdef CONFIG_BOARD_ATSTK1002_SW5_CUSTOM
220 + set_hw_addr(at32_add_device_eth(1, ð_data[1]));
222 at32_add_device_lcdc(0, &atstk1000_lcdc_data,
223 fbmem_start, fbmem_size);
226 +#ifndef CONFIG_BOARD_ATSTK1002_SW1_CUSTOM
227 + at32_add_device_spi(0, spi0_board_info, ARRAY_SIZE(spi0_board_info));
229 +#ifdef CONFIG_BOARD_ATSTK1002_SPI1
230 + at32_add_device_spi(1, spi1_board_info, ARRAY_SIZE(spi1_board_info));
232 + at32_add_device_twi(0);
233 +#ifndef CONFIG_BOARD_ATSTK1002_SW2_CUSTOM
234 + at32_add_device_mci(0, &mci0_data);
236 + at32_add_device_usba(0, NULL);
237 + at32_add_device_abdac(0);
238 +#ifndef CONFIG_BOARD_ATSTK1002_SW3_CUSTOM
239 + at32_add_device_ssc(0, ATMEL_SSC_TX);
246 diff -x .git -Nur linux-2.6.22.1/arch/avr32/boards/atstk1000/Kconfig linux-avr32.git/arch/avr32/boards/atstk1000/Kconfig
247 --- linux-2.6.22.1/arch/avr32/boards/atstk1000/Kconfig 1970-01-01 01:00:00.000000000 +0100
248 +++ linux-avr32.git/arch/avr32/boards/atstk1000/Kconfig 2007-07-12 13:59:49.000000000 +0200
250 +# STK1000 customization
254 +config BOARD_ATSTK1002_CUSTOM
255 + bool "Non-default STK-1002 jumper settings"
257 + You will normally leave the jumpers on the CPU card at their
258 + default settings. If you need to use certain peripherals,
259 + you will need to change some of those jumpers.
261 +if BOARD_ATSTK1002_CUSTOM
263 +config BOARD_ATSTK1002_SW1_CUSTOM
264 + bool "SW1: use SSC1 (not SPI0)"
266 + This also prevents using the external DAC as an audio interface,
267 + and means you can't initialize the on-board QVGA display.
269 +config BOARD_ATSTK1002_SW2_CUSTOM
270 + bool "SW2: use IRDA or TIMER0 (not UART-A, MMC/SD, and PS2-A)"
272 + If you change this you'll want an updated boot loader putting
273 + the console on UART-C not UART-A.
275 +config BOARD_ATSTK1002_SW3_CUSTOM
276 + bool "SW3: use TIMER1 (not SSC0 and GCLK)"
278 + This also prevents using the external DAC as an audio interface.
280 +config BOARD_ATSTK1002_SW4_CUSTOM
281 + bool "SW4: use ISI/Camera (not GPIOs, SPI1, and PS2-B)"
283 + To use the camera interface you'll need a custom card (on the
284 + PCI-format connector) connect a video sensor.
286 +config BOARD_ATSTK1002_SW5_CUSTOM
287 + bool "SW5: use MACB1 (not LCDC)"
289 +config BOARD_ATSTK1002_SW6_CUSTOM
290 + bool "SW6: more GPIOs (not MACB0)"
294 +config BOARD_ATSTK1002_SPI1
295 + bool "Configure SPI1 controller"
296 + depends on !BOARD_ATSTK1002_SW4_CUSTOM
298 + All the signals for the second SPI controller are available on
299 + GPIO lines and accessed through the J1 jumper block. Say "y"
300 + here to configure that SPI controller.
302 +config BOARD_ATSTK1002_J2_LED
304 + default BOARD_ATSTK1002_J2_LED8 || BOARD_ATSTK1002_J2_RGB
307 + prompt "LEDs connected to J2:"
308 + depends on LEDS_GPIO && !BOARD_ATSTK1002_SW4_CUSTOM
311 + Select this if you have jumpered the J2 jumper block to the
312 + LED0..LED7 amber leds, or to the RGB leds, using a ten-pin
313 + IDC cable. A default "heartbeat" trigger is provided, but
314 + you can of course override this.
316 +config BOARD_ATSTK1002_J2_LED8
319 + Select this if J2 is jumpered to LED0..LED7 amber leds.
321 +config BOARD_ATSTK1002_J2_RGB
324 + Select this if J2 is jumpered to the RGB leds.
329 diff -x .git -Nur linux-2.6.22.1/arch/avr32/configs/atngw100_defconfig linux-avr32.git/arch/avr32/configs/atngw100_defconfig
330 --- linux-2.6.22.1/arch/avr32/configs/atngw100_defconfig 2007-07-10 20:56:30.000000000 +0200
331 +++ linux-avr32.git/arch/avr32/configs/atngw100_defconfig 2007-07-12 13:59:49.000000000 +0200
336 -# CONFIG_NEW_LEDS is not set
348 +CONFIG_LEDS_TRIGGERS=y
349 +CONFIG_LEDS_TRIGGER_TIMER=y
350 +CONFIG_LEDS_TRIGGER_HEARTBEAT=y
355 diff -x .git -Nur linux-2.6.22.1/arch/avr32/drivers/dw-dmac.c linux-avr32.git/arch/avr32/drivers/dw-dmac.c
356 --- linux-2.6.22.1/arch/avr32/drivers/dw-dmac.c 1970-01-01 01:00:00.000000000 +0100
357 +++ linux-avr32.git/arch/avr32/drivers/dw-dmac.c 2007-06-06 11:33:46.000000000 +0200
360 + * Driver for the Synopsys DesignWare DMA Controller
362 + * Copyright (C) 2005-2006 Atmel Corporation
364 + * This program is free software; you can redistribute it and/or modify
365 + * it under the terms of the GNU General Public License version 2 as
366 + * published by the Free Software Foundation.
368 +#include <linux/clk.h>
369 +#include <linux/device.h>
370 +#include <linux/dma-mapping.h>
371 +#include <linux/dmapool.h>
372 +#include <linux/init.h>
373 +#include <linux/interrupt.h>
374 +#include <linux/module.h>
375 +#include <linux/platform_device.h>
377 +#include <asm/dma-controller.h>
380 +#include "dw-dmac.h"
382 +#define DMAC_NR_CHANNELS 3
383 +#define DMAC_MAX_BLOCKSIZE 4095
387 + CH_STATE_ALLOCATED,
401 +struct dw_dma_block {
402 + struct dw_dma_lli *lli_vaddr;
403 + dma_addr_t lli_dma_addr;
406 +struct dw_dma_channel {
407 + unsigned int state;
409 + struct dma_request_sg *req_sg;
410 + struct dma_request_cyclic *req_cyclic;
411 + unsigned int nr_blocks;
413 + struct dw_dma_block *block;
416 +struct dw_dma_controller {
418 + void * __iomem regs;
419 + struct dma_pool *lli_pool;
421 + struct dma_controller dma;
422 + struct dw_dma_channel channel[DMAC_NR_CHANNELS];
424 +#define to_dw_dmac(dmac) container_of(dmac, struct dw_dma_controller, dma)
426 +#define dmac_writel_hi(dmac, reg, value) \
427 + __raw_writel((value), (dmac)->regs + DW_DMAC_##reg + 4)
428 +#define dmac_readl_hi(dmac, reg) \
429 + __raw_readl((dmac)->regs + DW_DMAC_##reg + 4)
430 +#define dmac_writel_lo(dmac, reg, value) \
431 + __raw_writel((value), (dmac)->regs + DW_DMAC_##reg)
432 +#define dmac_readl_lo(dmac, reg) \
433 + __raw_readl((dmac)->regs + DW_DMAC_##reg)
434 +#define dmac_chan_writel_hi(dmac, chan, reg, value) \
435 + __raw_writel((value), ((dmac)->regs + 0x58 * (chan) \
436 + + DW_DMAC_CHAN_##reg + 4))
437 +#define dmac_chan_readl_hi(dmac, chan, reg) \
438 + __raw_readl((dmac)->regs + 0x58 * (chan) + DW_DMAC_CHAN_##reg + 4)
439 +#define dmac_chan_writel_lo(dmac, chan, reg, value) \
440 + __raw_writel((value), (dmac)->regs + 0x58 * (chan) + DW_DMAC_CHAN_##reg)
441 +#define dmac_chan_readl_lo(dmac, chan, reg) \
442 + __raw_readl((dmac)->regs + 0x58 * (chan) + DW_DMAC_CHAN_##reg)
443 +#define set_channel_bit(dmac, reg, chan) \
444 + dmac_writel_lo(dmac, reg, (1 << (chan)) | (1 << ((chan) + 8)))
445 +#define clear_channel_bit(dmac, reg, chan) \
446 + dmac_writel_lo(dmac, reg, (0 << (chan)) | (1 << ((chan) + 8)))
448 +static int dmac_alloc_channel(struct dma_controller *_dmac)
450 + struct dw_dma_controller *dmac = to_dw_dmac(_dmac);
451 + struct dw_dma_channel *chan;
452 + unsigned long flags;
455 + spin_lock_irqsave(&dmac->lock, flags);
456 + for (i = 0; i < DMAC_NR_CHANNELS; i++)
457 + if (dmac->channel[i].state == CH_STATE_FREE)
460 + if (i < DMAC_NR_CHANNELS) {
461 + chan = &dmac->channel[i];
462 + chan->state = CH_STATE_ALLOCATED;
467 + spin_unlock_irqrestore(&dmac->lock, flags);
472 +static void dmac_release_channel(struct dma_controller *_dmac, int channel)
474 + struct dw_dma_controller *dmac = to_dw_dmac(_dmac);
476 + BUG_ON(channel >= DMAC_NR_CHANNELS
477 + || dmac->channel[channel].state != CH_STATE_ALLOCATED);
479 + dmac->channel[channel].state = CH_STATE_FREE;
482 +static struct dw_dma_block *allocate_blocks(struct dw_dma_controller *dmac,
483 + unsigned int nr_blocks)
485 + struct dw_dma_block *block;
489 + block = kmalloc(nr_blocks * sizeof(*block),
491 + if (unlikely(!block))
494 + for (i = 0; i < nr_blocks; i++) {
495 + p = dma_pool_alloc(dmac->lli_pool, GFP_KERNEL,
496 + &block[i].lli_dma_addr);
497 + block[i].lli_vaddr = p;
505 + for (i = 0; i < nr_blocks; i++) {
506 + if (!block[i].lli_vaddr)
508 + dma_pool_free(dmac->lli_pool, block[i].lli_vaddr,
509 + block[i].lli_dma_addr);
515 +static void cleanup_channel(struct dw_dma_controller *dmac,
516 + struct dw_dma_channel *chan)
520 + if (chan->nr_blocks > 1) {
521 + for (i = 0; i < chan->nr_blocks; i++)
522 + dma_pool_free(dmac->lli_pool, chan->block[i].lli_vaddr,
523 + chan->block[i].lli_dma_addr);
524 + kfree(chan->block);
527 + chan->state = CH_STATE_ALLOCATED;
530 +static int dmac_prepare_request_sg(struct dma_controller *_dmac,
531 + struct dma_request_sg *req)
533 + struct dw_dma_controller *dmac = to_dw_dmac(_dmac);
534 + struct dw_dma_channel *chan;
535 + unsigned long ctlhi, ctllo, cfghi, cfglo;
536 + unsigned long block_size;
537 + unsigned int nr_blocks;
538 + int ret, i, direction;
539 + unsigned long flags;
541 + spin_lock_irqsave(&dmac->lock, flags);
544 + if (req->req.channel >= DMAC_NR_CHANNELS
545 + || dmac->channel[req->req.channel].state != CH_STATE_ALLOCATED
546 + || req->block_size > DMAC_MAX_BLOCKSIZE) {
547 + spin_unlock_irqrestore(&dmac->lock, flags);
551 + chan = &dmac->channel[req->req.channel];
552 + chan->state = CH_STATE_BUSY;
553 + chan->req_sg = req;
554 + chan->is_cyclic = 0;
557 + * We have marked the channel as busy, so no need to keep the
558 + * lock as long as we only touch the channel-specific
561 + spin_unlock_irqrestore(&dmac->lock, flags);
564 + * There may be limitations in the driver and/or the DMA
565 + * controller that prevents us from sending a whole
566 + * scatterlist item in one go. Taking this into account,
567 + * calculate the number of block transfers we need to set up.
569 + * FIXME: Let the peripheral driver know about the maximum
570 + * block size we support. We really don't want to use a
571 + * different block size than what was suggested by the
574 + * Each block will get its own Linked List Item (LLI) below.
576 + block_size = req->block_size;
577 + nr_blocks = req->nr_blocks;
578 + pr_debug("block_size %lu, nr_blocks %u nr_sg = %u\n",
579 + block_size, nr_blocks, req->nr_sg);
581 + BUG_ON(nr_blocks == 0);
582 + chan->nr_blocks = nr_blocks;
586 + switch (req->direction) {
587 + case DMA_DIR_MEM_TO_PERIPH:
588 + direction = DMA_TO_DEVICE;
589 + cfghi = req->periph_id << (43 - 32);
592 + case DMA_DIR_PERIPH_TO_MEM:
593 + direction = DMA_FROM_DEVICE;
594 + cfghi = req->periph_id << (39 - 32);
597 + goto out_unclaim_channel;
600 + chan->direction = direction;
602 + dmac_chan_writel_hi(dmac, req->req.channel, CFG, cfghi);
603 + dmac_chan_writel_lo(dmac, req->req.channel, CFG, cfglo);
605 + ctlhi = block_size >> req->width;
606 + ctllo = ((req->direction << 20)
607 + // | (1 << 14) | (1 << 11) // source/dest burst trans len
608 + | (req->width << 4) | (req->width << 1)
609 + | (1 << 0)); // interrupt enable
611 + if (nr_blocks == 1) {
612 + /* Only one block: No need to use block chaining */
613 + if (direction == DMA_TO_DEVICE) {
614 + dmac_chan_writel_lo(dmac, req->req.channel, SAR,
615 + req->sg->dma_address);
616 + dmac_chan_writel_lo(dmac, req->req.channel, DAR,
618 + ctllo |= 2 << 7; // no dst increment
620 + dmac_chan_writel_lo(dmac, req->req.channel, SAR,
622 + dmac_chan_writel_lo(dmac, req->req.channel, DAR,
623 + req->sg->dma_address);
624 + ctllo |= 2 << 9; // no src increment
626 + dmac_chan_writel_lo(dmac, req->req.channel, CTL, ctllo);
627 + dmac_chan_writel_hi(dmac, req->req.channel, CTL, ctlhi);
628 + pr_debug("ctl hi:lo 0x%lx:%lx\n", ctlhi, ctllo);
630 + struct dw_dma_lli *lli, *lli_prev = NULL;
631 + int j = 0, offset = 0;
634 + chan->block = allocate_blocks(dmac, nr_blocks);
636 + goto out_unclaim_channel;
638 + if (direction == DMA_TO_DEVICE)
639 + ctllo |= 1 << 28 | 1 << 27 | 2 << 7;
641 + ctllo |= 1 << 28 | 1 << 27 | 2 << 9;
644 + * Map scatterlist items to blocks. One scatterlist
645 + * item may need more than one block for the reasons
648 + for (i = 0; i < nr_blocks; i++) {
649 + lli = chan->block[i].lli_vaddr;
651 + lli_prev->llp = chan->block[i].lli_dma_addr;
652 + pr_debug("lli[%d] (0x%p/0x%x): 0x%x 0x%x 0x%x 0x%x 0x%x\n",
653 + i - 1, chan->block[i - 1].lli_vaddr,
654 + chan->block[i - 1].lli_dma_addr,
655 + lli_prev->sar, lli_prev->dar, lli_prev->llp,
656 + lli_prev->ctllo, lli_prev->ctlhi);
659 + lli->ctllo = ctllo;
660 + lli->ctlhi = ctlhi;
661 + if (direction == DMA_TO_DEVICE) {
662 + lli->sar = req->sg[j].dma_address + offset;
663 + lli->dar = req->data_reg;
665 + lli->sar = req->data_reg;
666 + lli->dar = req->sg[j].dma_address + offset;
670 + offset += block_size;
671 + if (offset > req->sg[j].length) {
677 + pr_debug("lli[%d] (0x%p/0x%x): 0x%x 0x%x 0x%x 0x%x 0x%x\n",
678 + i - 1, chan->block[i - 1].lli_vaddr,
679 + chan->block[i - 1].lli_dma_addr, lli_prev->sar,
680 + lli_prev->dar, lli_prev->llp,
681 + lli_prev->ctllo, lli_prev->ctlhi);
684 + * SAR, DAR and CTL are initialized from the LLI. We
685 + * only have to enable the LLI bits in CTL.
687 + dmac_chan_writel_hi(dmac, req->req.channel, CTL, 0);
688 + dmac_chan_writel_lo(dmac, req->req.channel, LLP,
689 + chan->block[0].lli_dma_addr);
690 + dmac_chan_writel_lo(dmac, req->req.channel, CTL, 1 << 28 | 1 << 27);
693 + set_channel_bit(dmac, MASK_XFER, req->req.channel);
694 + set_channel_bit(dmac, MASK_ERROR, req->req.channel);
695 + if (req->req.block_complete)
696 + set_channel_bit(dmac, MASK_BLOCK, req->req.channel);
698 + clear_channel_bit(dmac, MASK_BLOCK, req->req.channel);
702 +out_unclaim_channel:
703 + chan->state = CH_STATE_ALLOCATED;
707 +static int dmac_prepare_request_cyclic(struct dma_controller *_dmac,
708 + struct dma_request_cyclic *req)
710 + struct dw_dma_controller *dmac = to_dw_dmac(_dmac);
711 + struct dw_dma_channel *chan;
712 + unsigned long ctlhi, ctllo, cfghi, cfglo;
713 + unsigned long block_size;
714 + int ret, i, direction;
715 + unsigned long flags;
717 + spin_lock_irqsave(&dmac->lock, flags);
719 + block_size = (req->buffer_size/req->periods) >> req->width;
722 + if (req->req.channel >= DMAC_NR_CHANNELS
723 + || dmac->channel[req->req.channel].state != CH_STATE_ALLOCATED
724 + || (req->periods == 0)
725 + || block_size > DMAC_MAX_BLOCKSIZE) {
726 + spin_unlock_irqrestore(&dmac->lock, flags);
730 + chan = &dmac->channel[req->req.channel];
731 + chan->state = CH_STATE_BUSY;
732 + chan->is_cyclic = 1;
733 + chan->req_cyclic = req;
736 + * We have marked the channel as busy, so no need to keep the
737 + * lock as long as we only touch the channel-specific
740 + spin_unlock_irqrestore(&dmac->lock, flags);
745 + BUG_ON(req->buffer_size % req->periods);
746 + /* printk(KERN_INFO "block_size = %lu, periods = %u\n", block_size, req->periods); */
748 + chan->nr_blocks = req->periods;
752 + switch (req->direction) {
753 + case DMA_DIR_MEM_TO_PERIPH:
754 + direction = DMA_TO_DEVICE;
755 + cfghi = req->periph_id << (43 - 32);
758 + case DMA_DIR_PERIPH_TO_MEM:
759 + direction = DMA_FROM_DEVICE;
760 + cfghi = req->periph_id << (39 - 32);
763 + goto out_unclaim_channel;
766 + chan->direction = direction;
768 + dmac_chan_writel_hi(dmac, req->req.channel, CFG, cfghi);
769 + dmac_chan_writel_lo(dmac, req->req.channel, CFG, cfglo);
771 + ctlhi = block_size;
772 + ctllo = ((req->direction << 20)
773 + | (req->width << 4) | (req->width << 1)
774 + | (1 << 0)); // interrupt enable
777 + struct dw_dma_lli *lli = NULL, *lli_prev = NULL;
780 + chan->block = allocate_blocks(dmac, req->periods);
782 + goto out_unclaim_channel;
784 + if (direction == DMA_TO_DEVICE)
785 + ctllo |= 1 << 28 | 1 << 27 | 2 << 7;
787 + ctllo |= 1 << 28 | 1 << 27 | 2 << 9;
790 + * Set up a linked list items where each period gets
791 + * an item. The linked list item for the last period
792 + * points back to the star of the buffer making a
795 + for (i = 0; i < req->periods; i++) {
796 + lli = chan->block[i].lli_vaddr;
798 + lli_prev->llp = chan->block[i].lli_dma_addr;
799 + /* printk(KERN_INFO "lli[%d] (0x%p/0x%x): 0x%x 0x%x 0x%x 0x%x 0x%x\n",
800 + i - 1, chan->block[i - 1].lli_vaddr,
801 + chan->block[i - 1].lli_dma_addr,
802 + lli_prev->sar, lli_prev->dar, lli_prev->llp,
803 + lli_prev->ctllo, lli_prev->ctlhi);*/
806 + lli->ctllo = ctllo;
807 + lli->ctlhi = ctlhi;
808 + if (direction == DMA_TO_DEVICE) {
809 + lli->sar = req->buffer_start + i*(block_size << req->width);
810 + lli->dar = req->data_reg;
812 + lli->sar = req->data_reg;
813 + lli->dar = req->buffer_start + i*(block_size << req->width);
817 + lli->llp = chan->block[0].lli_dma_addr;
819 + /*printk(KERN_INFO "lli[%d] (0x%p/0x%x): 0x%x 0x%x 0x%x 0x%x 0x%x\n",
820 + i - 1, chan->block[i - 1].lli_vaddr,
821 + chan->block[i - 1].lli_dma_addr, lli_prev->sar,
822 + lli_prev->dar, lli_prev->llp,
823 + lli_prev->ctllo, lli_prev->ctlhi); */
826 + * SAR, DAR and CTL are initialized from the LLI. We
827 + * only have to enable the LLI bits in CTL.
829 + dmac_chan_writel_lo(dmac, req->req.channel, LLP,
830 + chan->block[0].lli_dma_addr);
831 + dmac_chan_writel_lo(dmac, req->req.channel, CTL, 1 << 28 | 1 << 27);
834 + clear_channel_bit(dmac, MASK_XFER, req->req.channel);
835 + set_channel_bit(dmac, MASK_ERROR, req->req.channel);
836 + if (req->req.block_complete)
837 + set_channel_bit(dmac, MASK_BLOCK, req->req.channel);
839 + clear_channel_bit(dmac, MASK_BLOCK, req->req.channel);
843 +out_unclaim_channel:
844 + chan->state = CH_STATE_ALLOCATED;
848 +static int dmac_start_request(struct dma_controller *_dmac,
849 + unsigned int channel)
851 + struct dw_dma_controller *dmac = to_dw_dmac(_dmac);
853 + BUG_ON(channel >= DMAC_NR_CHANNELS);
855 + set_channel_bit(dmac, CH_EN, channel);
860 +static dma_addr_t dmac_get_current_pos(struct dma_controller *_dmac,
861 + unsigned int channel)
863 + struct dw_dma_controller *dmac = to_dw_dmac(_dmac);
864 + struct dw_dma_channel *chan;
865 + dma_addr_t current_pos;
867 + BUG_ON(channel >= DMAC_NR_CHANNELS);
869 + chan = &dmac->channel[channel];
871 + switch (chan->direction) {
872 + case DMA_TO_DEVICE:
873 + current_pos = dmac_chan_readl_lo(dmac, channel, SAR);
875 + case DMA_FROM_DEVICE:
876 + current_pos = dmac_chan_readl_lo(dmac, channel, DAR);
883 + if (!current_pos) {
884 + if (chan->is_cyclic) {
885 + current_pos = chan->req_cyclic->buffer_start;
887 + current_pos = chan->req_sg->sg->dma_address;
891 + return current_pos;
895 +static int dmac_stop_request(struct dma_controller *_dmac,
896 + unsigned int channel)
898 + struct dw_dma_controller *dmac = to_dw_dmac(_dmac);
899 + struct dw_dma_channel *chan;
901 + BUG_ON(channel >= DMAC_NR_CHANNELS);
903 + chan = &dmac->channel[channel];
904 + pr_debug("stop: st%u s%08x d%08x l%08x ctl0x%08x:0x%08x\n",
905 + chan->state, dmac_chan_readl_lo(dmac, channel, SAR),
906 + dmac_chan_readl_lo(dmac, channel, DAR),
907 + dmac_chan_readl_lo(dmac, channel, LLP),
908 + dmac_chan_readl_hi(dmac, channel, CTL),
909 + dmac_chan_readl_lo(dmac, channel, CTL));
911 + if (chan->state == CH_STATE_BUSY) {
912 + clear_channel_bit(dmac, CH_EN, channel);
913 + cleanup_channel(dmac, &dmac->channel[channel]);
920 +static void dmac_block_complete(struct dw_dma_controller *dmac)
922 + struct dw_dma_channel *chan;
923 + unsigned long status, chanid;
925 + status = dmac_readl_lo(dmac, STATUS_BLOCK);
928 + struct dma_request *req;
929 + chanid = __ffs(status);
930 + chan = &dmac->channel[chanid];
932 + if (chan->is_cyclic) {
933 + BUG_ON(!chan->req_cyclic
934 + || !chan->req_cyclic->req.block_complete);
935 + req = &chan->req_cyclic->req;
937 + BUG_ON(!chan->req_sg || !chan->req_sg->req.block_complete);
938 + req = &chan->req_sg->req;
940 + dmac_writel_lo(dmac, CLEAR_BLOCK, 1 << chanid);
941 + req->block_complete(req);
942 + status = dmac_readl_lo(dmac, STATUS_BLOCK);
946 +static void dmac_xfer_complete(struct dw_dma_controller *dmac)
948 + struct dw_dma_channel *chan;
949 + struct dma_request *req;
950 + unsigned long status, chanid;
952 + status = dmac_readl_lo(dmac, STATUS_XFER);
955 + chanid = __ffs(status);
956 + chan = &dmac->channel[chanid];
958 + dmac_writel_lo(dmac, CLEAR_XFER, 1 << chanid);
960 + req = &chan->req_sg->req;
962 + cleanup_channel(dmac, chan);
963 + if (req->xfer_complete)
964 + req->xfer_complete(req);
966 + status = dmac_readl_lo(dmac, STATUS_XFER);
970 +static void dmac_error(struct dw_dma_controller *dmac)
972 + struct dw_dma_channel *chan;
973 + unsigned long status, chanid;
975 + status = dmac_readl_lo(dmac, STATUS_ERROR);
978 + struct dma_request *req;
980 + chanid = __ffs(status);
981 + chan = &dmac->channel[chanid];
983 + dmac_writel_lo(dmac, CLEAR_ERROR, 1 << chanid);
984 + clear_channel_bit(dmac, CH_EN, chanid);
986 + if (chan->is_cyclic) {
987 + BUG_ON(!chan->req_cyclic);
988 + req = &chan->req_cyclic->req;
990 + BUG_ON(!chan->req_sg);
991 + req = &chan->req_sg->req;
994 + cleanup_channel(dmac, chan);
998 + status = dmac_readl_lo(dmac, STATUS_XFER);
1002 +static irqreturn_t dmac_interrupt(int irq, void *dev_id)
1004 + struct dw_dma_controller *dmac = dev_id;
1005 + unsigned long status;
1006 + int ret = IRQ_NONE;
1008 + spin_lock(&dmac->lock);
1010 + status = dmac_readl_lo(dmac, STATUS_INT);
1013 + ret = IRQ_HANDLED;
1014 + if (status & 0x10)
1016 + if (status & 0x02)
1017 + dmac_block_complete(dmac);
1018 + if (status & 0x01)
1019 + dmac_xfer_complete(dmac);
1021 + status = dmac_readl_lo(dmac, STATUS_INT);
1024 + spin_unlock(&dmac->lock);
1028 +static int __devinit dmac_probe(struct platform_device *pdev)
1030 + struct dw_dma_controller *dmac;
1031 + struct resource *regs;
1034 + regs = platform_get_resource(pdev, IORESOURCE_MEM, 0);
1038 + dmac = kmalloc(sizeof(*dmac), GFP_KERNEL);
1041 + memset(dmac, 0, sizeof(*dmac));
1043 + dmac->hclk = clk_get(&pdev->dev, "hclk");
1044 + if (IS_ERR(dmac->hclk)) {
1045 + ret = PTR_ERR(dmac->hclk);
1046 + goto out_free_dmac;
1048 + clk_enable(dmac->hclk);
1051 + dmac->lli_pool = dma_pool_create("dmac", &pdev->dev,
1052 + sizeof(struct dw_dma_lli), 4, 0);
1053 + if (!dmac->lli_pool)
1054 + goto out_disable_clk;
1056 + spin_lock_init(&dmac->lock);
1057 + dmac->dma.dev = &pdev->dev;
1058 + dmac->dma.alloc_channel = dmac_alloc_channel;
1059 + dmac->dma.release_channel = dmac_release_channel;
1060 + dmac->dma.prepare_request_sg = dmac_prepare_request_sg;
1061 + dmac->dma.prepare_request_cyclic = dmac_prepare_request_cyclic;
1062 + dmac->dma.start_request = dmac_start_request;
1063 + dmac->dma.stop_request = dmac_stop_request;
1064 + dmac->dma.get_current_pos = dmac_get_current_pos;
1066 + dmac->regs = ioremap(regs->start, regs->end - regs->start + 1);
1068 + goto out_free_pool;
1070 + ret = request_irq(platform_get_irq(pdev, 0), dmac_interrupt,
1071 + IRQF_SAMPLE_RANDOM, pdev->name, dmac);
1073 + goto out_unmap_regs;
1075 + /* Enable the DMA controller */
1076 + dmac_writel_lo(dmac, CFG, 1);
1078 + register_dma_controller(&dmac->dma);
1081 + "dmac%d: DesignWare DMA controller at 0x%p irq %d\n",
1082 + dmac->dma.id, dmac->regs, platform_get_irq(pdev, 0));
1087 + iounmap(dmac->regs);
1089 + dma_pool_destroy(dmac->lli_pool);
1091 + clk_disable(dmac->hclk);
1092 + clk_put(dmac->hclk);
1098 +static struct platform_driver dmac_driver = {
1099 + .probe = dmac_probe,
1105 +static int __init dmac_init(void)
1107 + return platform_driver_register(&dmac_driver);
1109 +subsys_initcall(dmac_init);
1111 +static void __exit dmac_exit(void)
1113 + platform_driver_unregister(&dmac_driver);
1115 +module_exit(dmac_exit);
1117 +MODULE_DESCRIPTION("Synopsys DesignWare DMA Controller driver");
1118 +MODULE_AUTHOR("Haavard Skinnemoen <hskinnemoen@atmel.com>");
1119 +MODULE_LICENSE("GPL");
1120 diff -x .git -Nur linux-2.6.22.1/arch/avr32/drivers/dw-dmac.h linux-avr32.git/arch/avr32/drivers/dw-dmac.h
1121 --- linux-2.6.22.1/arch/avr32/drivers/dw-dmac.h 1970-01-01 01:00:00.000000000 +0100
1122 +++ linux-avr32.git/arch/avr32/drivers/dw-dmac.h 2007-06-06 11:33:46.000000000 +0200
1125 + * Driver for the Synopsys DesignWare DMA Controller
1127 + * Copyright (C) 2005-2006 Atmel Corporation
1129 + * This program is free software; you can redistribute it and/or modify
1130 + * it under the terms of the GNU General Public License version 2 as
1131 + * published by the Free Software Foundation.
1133 +#ifndef __AVR32_DW_DMAC_H__
1134 +#define __AVR32_DW_DMAC_H__
1136 +#define DW_DMAC_CFG 0x398
1137 +#define DW_DMAC_CH_EN 0x3a0
1139 +#define DW_DMAC_STATUS_XFER 0x2e8
1140 +#define DW_DMAC_STATUS_BLOCK 0x2f0
1141 +#define DW_DMAC_STATUS_ERROR 0x308
1143 +#define DW_DMAC_MASK_XFER 0x310
1144 +#define DW_DMAC_MASK_BLOCK 0x318
1145 +#define DW_DMAC_MASK_ERROR 0x330
1147 +#define DW_DMAC_CLEAR_XFER 0x338
1148 +#define DW_DMAC_CLEAR_BLOCK 0x340
1149 +#define DW_DMAC_CLEAR_ERROR 0x358
1151 +#define DW_DMAC_STATUS_INT 0x360
1153 +#define DW_DMAC_CHAN_SAR 0x000
1154 +#define DW_DMAC_CHAN_DAR 0x008
1155 +#define DW_DMAC_CHAN_LLP 0x010
1156 +#define DW_DMAC_CHAN_CTL 0x018
1157 +#define DW_DMAC_CHAN_SSTAT 0x020
1158 +#define DW_DMAC_CHAN_DSTAT 0x028
1159 +#define DW_DMAC_CHAN_SSTATAR 0x030
1160 +#define DW_DMAC_CHAN_DSTATAR 0x038
1161 +#define DW_DMAC_CHAN_CFG 0x040
1162 +#define DW_DMAC_CHAN_SGR 0x048
1163 +#define DW_DMAC_CHAN_DSR 0x050
1165 +#endif /* __AVR32_DW_DMAC_H__ */
1166 diff -x .git -Nur linux-2.6.22.1/arch/avr32/drivers/Makefile linux-avr32.git/arch/avr32/drivers/Makefile
1167 --- linux-2.6.22.1/arch/avr32/drivers/Makefile 1970-01-01 01:00:00.000000000 +0100
1168 +++ linux-avr32.git/arch/avr32/drivers/Makefile 2007-06-06 11:33:46.000000000 +0200
1170 +obj-$(CONFIG_DW_DMAC) += dw-dmac.o
1171 diff -x .git -Nur linux-2.6.22.1/arch/avr32/Kconfig linux-avr32.git/arch/avr32/Kconfig
1172 --- linux-2.6.22.1/arch/avr32/Kconfig 2007-07-10 20:56:30.000000000 +0200
1173 +++ linux-avr32.git/arch/avr32/Kconfig 2007-07-12 13:59:49.000000000 +0200
1174 @@ -113,6 +113,10 @@
1175 bool "ATNGW100 Network Gateway"
1179 +source "arch/avr32/boards/atstk1000/Kconfig"
1183 prompt "Boot loader type"
1184 default LOADER_U_BOOT
1185 @@ -171,6 +175,10 @@
1186 enabling Nexus-compliant debuggers to keep track of the PID of the
1187 currently executing task.
1190 + tristate "Synopsys DesignWare DMA Controller support"
1191 + default y if CPU_AT32AP7000
1193 # FPU emulation goes here
1195 source "kernel/Kconfig.hz"
1196 @@ -185,6 +193,27 @@
1200 +menu "Power managment options"
1202 +menu "CPU Frequency scaling"
1204 +source "drivers/cpufreq/Kconfig"
1206 +config CPU_FREQ_AT32AP
1207 + bool "CPU frequency driver for AT32AP"
1208 + depends on CPU_FREQ && PLATFORM_AT32AP
1211 + This enables the CPU frequency driver for AT32AP processors.
1213 + For details, take a look in <file:Documentation/cpu-freq>.
1215 + If in doubt, say N.
1224 diff -x .git -Nur linux-2.6.22.1/arch/avr32/kernel/dma-controller.c linux-avr32.git/arch/avr32/kernel/dma-controller.c
1225 --- linux-2.6.22.1/arch/avr32/kernel/dma-controller.c 1970-01-01 01:00:00.000000000 +0100
1226 +++ linux-avr32.git/arch/avr32/kernel/dma-controller.c 2007-06-06 11:33:46.000000000 +0200
1229 + * Preliminary DMA controller framework for AVR32
1231 + * Copyright (C) 2005-2006 Atmel Corporation
1233 + * This program is free software; you can redistribute it and/or modify
1234 + * it under the terms of the GNU General Public License version 2 as
1235 + * published by the Free Software Foundation.
1237 +#include <asm/dma-controller.h>
1239 +static LIST_HEAD(controllers);
1241 +int register_dma_controller(struct dma_controller *dmac)
1243 + static int next_id;
1245 + dmac->id = next_id++;
1246 + list_add_tail(&dmac->list, &controllers);
1250 +EXPORT_SYMBOL(register_dma_controller);
1252 +struct dma_controller *find_dma_controller(int id)
1254 + struct dma_controller *dmac;
1256 + list_for_each_entry(dmac, &controllers, list)
1257 + if (dmac->id == id)
1261 +EXPORT_SYMBOL(find_dma_controller);
1262 diff -x .git -Nur linux-2.6.22.1/arch/avr32/kernel/Makefile linux-avr32.git/arch/avr32/kernel/Makefile
1263 --- linux-2.6.22.1/arch/avr32/kernel/Makefile 2007-07-10 20:56:30.000000000 +0200
1264 +++ linux-avr32.git/arch/avr32/kernel/Makefile 2007-06-06 11:33:46.000000000 +0200
1266 obj-y += setup.o traps.o semaphore.o ptrace.o
1267 obj-y += signal.o sys_avr32.o process.o time.o
1268 obj-y += init_task.o switch_to.o cpu.o
1269 +obj-y += dma-controller.o
1270 obj-$(CONFIG_MODULES) += module.o avr32_ksyms.o
1271 obj-$(CONFIG_KPROBES) += kprobes.o
1273 diff -x .git -Nur linux-2.6.22.1/arch/avr32/mach-at32ap/at32ap7000.c linux-avr32.git/arch/avr32/mach-at32ap/at32ap7000.c
1274 --- linux-2.6.22.1/arch/avr32/mach-at32ap/at32ap7000.c 2007-07-10 20:56:30.000000000 +0200
1275 +++ linux-avr32.git/arch/avr32/mach-at32ap/at32ap7000.c 2007-07-12 13:59:49.000000000 +0200
1277 #include <asm/arch/at32ap7000.h>
1278 #include <asm/arch/board.h>
1279 #include <asm/arch/portmux.h>
1280 -#include <asm/arch/sm.h>
1282 #include <video/atmel_lcdc.h>
1285 #include "hmatrix.h"
1291 + * We can reduce the code size a bit by using a constant here. Since
1292 + * this file is completely chip-specific, it's safe to not use
1293 + * ioremap. Generic drivers should of course never do this.
1295 +#define AT32_PM_BASE 0xfff00000
1297 #define PBMEM(base) \
1303 +static DEFINE_SPINLOCK(pm_lock);
1305 unsigned long at32ap7000_osc_rates[3] = {
1307 /* FIXME: these are ATSTK1002-specific */
1308 @@ -104,11 +112,11 @@
1310 unsigned long div, mul, rate;
1312 - if (!(control & SM_BIT(PLLEN)))
1313 + if (!(control & PM_BIT(PLLEN)))
1316 - div = SM_BFEXT(PLLDIV, control) + 1;
1317 - mul = SM_BFEXT(PLLMUL, control) + 1;
1318 + div = PM_BFEXT(PLLDIV, control) + 1;
1319 + mul = PM_BFEXT(PLLMUL, control) + 1;
1321 rate = clk->parent->get_rate(clk->parent);
1322 rate = (rate + div / 2) / div;
1327 - control = sm_readl(&system_manager, PM_PLL0);
1328 + control = pm_readl(PLL0);
1330 return pll_get_rate(clk, control);
1336 - control = sm_readl(&system_manager, PM_PLL1);
1337 + control = pm_readl(PLL1);
1339 return pll_get_rate(clk, control);
1341 @@ -187,108 +195,139 @@
1343 static void cpu_clk_mode(struct clk *clk, int enabled)
1345 - struct at32_sm *sm = &system_manager;
1346 unsigned long flags;
1349 - spin_lock_irqsave(&sm->lock, flags);
1350 - mask = sm_readl(sm, PM_CPU_MASK);
1351 + spin_lock_irqsave(&pm_lock, flags);
1352 + mask = pm_readl(CPU_MASK);
1354 mask |= 1 << clk->index;
1356 mask &= ~(1 << clk->index);
1357 - sm_writel(sm, PM_CPU_MASK, mask);
1358 - spin_unlock_irqrestore(&sm->lock, flags);
1359 + pm_writel(CPU_MASK, mask);
1360 + spin_unlock_irqrestore(&pm_lock, flags);
1363 static unsigned long cpu_clk_get_rate(struct clk *clk)
1365 unsigned long cksel, shift = 0;
1367 - cksel = sm_readl(&system_manager, PM_CKSEL);
1368 - if (cksel & SM_BIT(CPUDIV))
1369 - shift = SM_BFEXT(CPUSEL, cksel) + 1;
1370 + cksel = pm_readl(CKSEL);
1371 + if (cksel & PM_BIT(CPUDIV))
1372 + shift = PM_BFEXT(CPUSEL, cksel) + 1;
1374 return bus_clk_get_rate(clk, shift);
1377 +static long cpu_clk_set_rate(struct clk *clk, unsigned long rate, int apply)
1380 + unsigned long parent_rate, child_div, actual_rate, div;
1382 + parent_rate = clk->parent->get_rate(clk->parent);
1383 + control = pm_readl(CKSEL);
1385 + if (control & PM_BIT(HSBDIV))
1386 + child_div = 1 << (PM_BFEXT(HSBSEL, control) + 1);
1390 + if (rate > 3 * (parent_rate / 4) || child_div == 1) {
1391 + actual_rate = parent_rate;
1392 + control &= ~PM_BIT(CPUDIV);
1394 + unsigned int cpusel;
1395 + div = (parent_rate + rate / 2) / rate;
1396 + if (div > child_div)
1398 + cpusel = (div > 1) ? (fls(div) - 2) : 0;
1399 + control = PM_BIT(CPUDIV) | PM_BFINS(CPUSEL, cpusel, control);
1400 + actual_rate = parent_rate / (1 << (cpusel + 1));
1403 + pr_debug("clk %s: new rate %lu (actual rate %lu)\n",
1404 + clk->name, rate, actual_rate);
1407 + pm_writel(CKSEL, control);
1409 + return actual_rate;
1412 static void hsb_clk_mode(struct clk *clk, int enabled)
1414 - struct at32_sm *sm = &system_manager;
1415 unsigned long flags;
1418 - spin_lock_irqsave(&sm->lock, flags);
1419 - mask = sm_readl(sm, PM_HSB_MASK);
1420 + spin_lock_irqsave(&pm_lock, flags);
1421 + mask = pm_readl(HSB_MASK);
1423 mask |= 1 << clk->index;
1425 mask &= ~(1 << clk->index);
1426 - sm_writel(sm, PM_HSB_MASK, mask);
1427 - spin_unlock_irqrestore(&sm->lock, flags);
1428 + pm_writel(HSB_MASK, mask);
1429 + spin_unlock_irqrestore(&pm_lock, flags);
1432 static unsigned long hsb_clk_get_rate(struct clk *clk)
1434 unsigned long cksel, shift = 0;
1436 - cksel = sm_readl(&system_manager, PM_CKSEL);
1437 - if (cksel & SM_BIT(HSBDIV))
1438 - shift = SM_BFEXT(HSBSEL, cksel) + 1;
1439 + cksel = pm_readl(CKSEL);
1440 + if (cksel & PM_BIT(HSBDIV))
1441 + shift = PM_BFEXT(HSBSEL, cksel) + 1;
1443 return bus_clk_get_rate(clk, shift);
1446 static void pba_clk_mode(struct clk *clk, int enabled)
1448 - struct at32_sm *sm = &system_manager;
1449 unsigned long flags;
1452 - spin_lock_irqsave(&sm->lock, flags);
1453 - mask = sm_readl(sm, PM_PBA_MASK);
1454 + spin_lock_irqsave(&pm_lock, flags);
1455 + mask = pm_readl(PBA_MASK);
1457 mask |= 1 << clk->index;
1459 mask &= ~(1 << clk->index);
1460 - sm_writel(sm, PM_PBA_MASK, mask);
1461 - spin_unlock_irqrestore(&sm->lock, flags);
1462 + pm_writel(PBA_MASK, mask);
1463 + spin_unlock_irqrestore(&pm_lock, flags);
1466 static unsigned long pba_clk_get_rate(struct clk *clk)
1468 unsigned long cksel, shift = 0;
1470 - cksel = sm_readl(&system_manager, PM_CKSEL);
1471 - if (cksel & SM_BIT(PBADIV))
1472 - shift = SM_BFEXT(PBASEL, cksel) + 1;
1473 + cksel = pm_readl(CKSEL);
1474 + if (cksel & PM_BIT(PBADIV))
1475 + shift = PM_BFEXT(PBASEL, cksel) + 1;
1477 return bus_clk_get_rate(clk, shift);
1480 static void pbb_clk_mode(struct clk *clk, int enabled)
1482 - struct at32_sm *sm = &system_manager;
1483 unsigned long flags;
1486 - spin_lock_irqsave(&sm->lock, flags);
1487 - mask = sm_readl(sm, PM_PBB_MASK);
1488 + spin_lock_irqsave(&pm_lock, flags);
1489 + mask = pm_readl(PBB_MASK);
1491 mask |= 1 << clk->index;
1493 mask &= ~(1 << clk->index);
1494 - sm_writel(sm, PM_PBB_MASK, mask);
1495 - spin_unlock_irqrestore(&sm->lock, flags);
1496 + pm_writel(PBB_MASK, mask);
1497 + spin_unlock_irqrestore(&pm_lock, flags);
1500 static unsigned long pbb_clk_get_rate(struct clk *clk)
1502 unsigned long cksel, shift = 0;
1504 - cksel = sm_readl(&system_manager, PM_CKSEL);
1505 - if (cksel & SM_BIT(PBBDIV))
1506 - shift = SM_BFEXT(PBBSEL, cksel) + 1;
1507 + cksel = pm_readl(CKSEL);
1508 + if (cksel & PM_BIT(PBBDIV))
1509 + shift = PM_BFEXT(PBBSEL, cksel) + 1;
1511 return bus_clk_get_rate(clk, shift);
1514 static struct clk cpu_clk = {
1516 .get_rate = cpu_clk_get_rate,
1517 + .set_rate = cpu_clk_set_rate,
1520 static struct clk hsb_clk = {
1521 @@ -327,12 +367,12 @@
1525 - control = sm_readl(&system_manager, PM_GCCTRL + 4 * clk->index);
1526 + control = pm_readl(GCCTRL(clk->index));
1528 - control |= SM_BIT(CEN);
1529 + control |= PM_BIT(CEN);
1531 - control &= ~SM_BIT(CEN);
1532 - sm_writel(&system_manager, PM_GCCTRL + 4 * clk->index, control);
1533 + control &= ~PM_BIT(CEN);
1534 + pm_writel(GCCTRL(clk->index), control);
1537 static unsigned long genclk_get_rate(struct clk *clk)
1540 unsigned long div = 1;
1542 - control = sm_readl(&system_manager, PM_GCCTRL + 4 * clk->index);
1543 - if (control & SM_BIT(DIVEN))
1544 - div = 2 * (SM_BFEXT(DIV, control) + 1);
1545 + control = pm_readl(GCCTRL(clk->index));
1546 + if (control & PM_BIT(DIVEN))
1547 + div = 2 * (PM_BFEXT(DIV, control) + 1);
1549 return clk->parent->get_rate(clk->parent) / div;
1551 @@ -353,23 +393,22 @@
1552 unsigned long parent_rate, actual_rate, div;
1554 parent_rate = clk->parent->get_rate(clk->parent);
1555 - control = sm_readl(&system_manager, PM_GCCTRL + 4 * clk->index);
1556 + control = pm_readl(GCCTRL(clk->index));
1558 if (rate > 3 * parent_rate / 4) {
1559 actual_rate = parent_rate;
1560 - control &= ~SM_BIT(DIVEN);
1561 + control &= ~PM_BIT(DIVEN);
1563 div = (parent_rate + rate) / (2 * rate) - 1;
1564 - control = SM_BFINS(DIV, div, control) | SM_BIT(DIVEN);
1565 + control = PM_BFINS(DIV, div, control) | PM_BIT(DIVEN);
1566 actual_rate = parent_rate / (2 * (div + 1));
1569 - printk("clk %s: new rate %lu (actual rate %lu)\n",
1570 - clk->name, rate, actual_rate);
1571 + dev_dbg(clk->dev, "clk %s: new rate %lu (actual rate %lu)\n",
1572 + clk->name, rate, actual_rate);
1575 - sm_writel(&system_manager, PM_GCCTRL + 4 * clk->index,
1577 + pm_writel(GCCTRL(clk->index), control);
1581 @@ -378,24 +417,24 @@
1585 - printk("clk %s: new parent %s (was %s)\n",
1586 - clk->name, parent->name, clk->parent->name);
1587 + dev_dbg(clk->dev, "clk %s: new parent %s (was %s)\n",
1588 + clk->name, parent->name, clk->parent->name);
1590 - control = sm_readl(&system_manager, PM_GCCTRL + 4 * clk->index);
1591 + control = pm_readl(GCCTRL(clk->index));
1593 if (parent == &osc1 || parent == &pll1)
1594 - control |= SM_BIT(OSCSEL);
1595 + control |= PM_BIT(OSCSEL);
1596 else if (parent == &osc0 || parent == &pll0)
1597 - control &= ~SM_BIT(OSCSEL);
1598 + control &= ~PM_BIT(OSCSEL);
1602 if (parent == &pll0 || parent == &pll1)
1603 - control |= SM_BIT(PLLSEL);
1604 + control |= PM_BIT(PLLSEL);
1606 - control &= ~SM_BIT(PLLSEL);
1607 + control &= ~PM_BIT(PLLSEL);
1609 - sm_writel(&system_manager, PM_GCCTRL + 4 * clk->index, control);
1610 + pm_writel(GCCTRL(clk->index), control);
1611 clk->parent = parent;
1614 @@ -408,11 +447,11 @@
1616 BUG_ON(clk->index > 7);
1618 - control = sm_readl(&system_manager, PM_GCCTRL + 4 * clk->index);
1619 - if (control & SM_BIT(OSCSEL))
1620 - parent = (control & SM_BIT(PLLSEL)) ? &pll1 : &osc1;
1621 + control = pm_readl(GCCTRL(clk->index));
1622 + if (control & PM_BIT(OSCSEL))
1623 + parent = (control & PM_BIT(PLLSEL)) ? &pll1 : &osc1;
1625 - parent = (control & SM_BIT(PLLSEL)) ? &pll0 : &osc0;
1626 + parent = (control & PM_BIT(PLLSEL)) ? &pll0 : &osc0;
1628 clk->parent = parent;
1630 @@ -420,21 +459,53 @@
1631 /* --------------------------------------------------------------------
1632 * System peripherals
1633 * -------------------------------------------------------------------- */
1634 -static struct resource sm_resource[] = {
1635 - PBMEM(0xfff00000),
1636 - NAMED_IRQ(19, "eim"),
1637 - NAMED_IRQ(20, "pm"),
1638 - NAMED_IRQ(21, "rtc"),
1639 +static struct resource at32_pm0_resource[] = {
1641 + .start = 0xfff00000,
1642 + .end = 0xfff0007f,
1643 + .flags = IORESOURCE_MEM,
1647 -struct platform_device at32_sm_device = {
1650 - .resource = sm_resource,
1651 - .num_resources = ARRAY_SIZE(sm_resource),
1653 +static struct resource at32ap700x_rtc0_resource[] = {
1655 + .start = 0xfff00080,
1656 + .end = 0xfff000af,
1657 + .flags = IORESOURCE_MEM,
1662 +static struct resource at32_wdt0_resource[] = {
1664 + .start = 0xfff000b0,
1665 + .end = 0xfff000bf,
1666 + .flags = IORESOURCE_MEM,
1670 +static struct resource at32_eic0_resource[] = {
1672 + .start = 0xfff00100,
1673 + .end = 0xfff0013f,
1674 + .flags = IORESOURCE_MEM,
1678 -static struct clk at32_sm_pclk = {
1680 +DEFINE_DEV(at32_pm, 0);
1681 +DEFINE_DEV(at32ap700x_rtc, 0);
1682 +DEFINE_DEV(at32_wdt, 0);
1683 +DEFINE_DEV(at32_eic, 0);
1686 + * Peripheral clock for PM, RTC, WDT and EIC. PM will ensure that this
1687 + * is always running.
1689 +static struct clk at32_pm_pclk = {
1691 - .dev = &at32_sm_device.dev,
1692 + .dev = &at32_pm0_device.dev,
1694 .mode = pbb_clk_mode,
1695 .get_rate = pbb_clk_get_rate,
1696 @@ -491,6 +562,17 @@
1700 +static struct resource dmaca0_resource[] = {
1702 + .start = 0xff200000,
1703 + .end = 0xff20ffff,
1704 + .flags = IORESOURCE_MEM,
1708 +DEFINE_DEV(dmaca, 0);
1709 +DEV_CLK(hclk, dmaca0, hsb, 10);
1711 /* --------------------------------------------------------------------
1713 * -------------------------------------------------------------------- */
1714 @@ -583,12 +665,14 @@
1716 void __init at32_add_system_devices(void)
1718 - system_manager.eim_first_irq = EIM_IRQ_BASE;
1720 - platform_device_register(&at32_sm_device);
1721 + platform_device_register(&at32_pm0_device);
1722 platform_device_register(&at32_intc0_device);
1723 + platform_device_register(&at32ap700x_rtc0_device);
1724 + platform_device_register(&at32_wdt0_device);
1725 + platform_device_register(&at32_eic0_device);
1726 platform_device_register(&smc0_device);
1727 platform_device_register(&pdc_device);
1728 + platform_device_register(&dmaca0_device);
1730 platform_device_register(&at32_systc0_device);
1732 @@ -894,6 +978,83 @@
1735 /* --------------------------------------------------------------------
1737 + * -------------------------------------------------------------------- */
1739 +static struct resource atmel_twi0_resource[] = {
1740 + PBMEM(0xffe00800),
1743 +DEFINE_DEV(atmel_twi, 0);
1744 +DEV_CLK(pclk,atmel_twi0,pba,2);
1746 +struct platform_device *__init
1747 +at32_add_device_twi(unsigned int id)
1749 + struct platform_device *pdev;
1753 + pdev = &atmel_twi0_device;
1754 + select_peripheral(PA(6), PERIPH_A, 0); /* SDA */
1755 + select_peripheral(PA(7), PERIPH_A, 0); /* SCL */
1762 + platform_device_register(pdev);
1766 +/* --------------------------------------------------------------------
1768 + * -------------------------------------------------------------------- */
1769 +static struct mci_platform_data atmel_mci0_data = {
1770 + .detect_pin = GPIO_PIN_NONE,
1771 + .wp_pin = GPIO_PIN_NONE,
1773 +static struct resource atmel_mci0_resource[] = {
1774 + PBMEM(0xfff02400),
1777 +DEFINE_DEV_DATA(atmel_mci, 0);
1778 +DEV_CLK(mci_clk, atmel_mci0, pbb, 9);
1780 +struct platform_device *__init
1781 +at32_add_device_mci(unsigned int id, struct mci_platform_data *data)
1783 + struct platform_device *pdev;
1787 + pdev = &atmel_mci0_device;
1788 + select_peripheral(PA(10), PERIPH_A, 0); /* CLK */
1789 + select_peripheral(PA(11), PERIPH_A, 0); /* CMD */
1790 + select_peripheral(PA(12), PERIPH_A, 0); /* DATA0 */
1791 + select_peripheral(PA(13), PERIPH_A, 0); /* DATA1 */
1792 + select_peripheral(PA(14), PERIPH_A, 0); /* DATA2 */
1793 + select_peripheral(PA(15), PERIPH_A, 0); /* DATA3 */
1800 + if (data->detect_pin != GPIO_PIN_NONE)
1801 + at32_select_gpio(data->detect_pin, 0);
1802 + if (data->wp_pin != GPIO_PIN_NONE)
1803 + at32_select_gpio(data->wp_pin, 0);
1804 + memcpy(pdev->dev.platform_data, data,
1805 + sizeof(struct mci_platform_data));
1808 + platform_device_register(pdev);
1812 +/* --------------------------------------------------------------------
1814 * -------------------------------------------------------------------- */
1815 static struct atmel_lcdfb_info atmel_lcdfb0_data;
1816 @@ -1013,6 +1174,228 @@
1819 /* --------------------------------------------------------------------
1820 + * USB Device Controller
1821 + * -------------------------------------------------------------------- */
1822 +static struct resource usba0_resource[] __initdata = {
1825 + .start = 0xff300000,
1826 + .end = 0xff3fffff,
1827 + .flags = IORESOURCE_MEM,
1830 + .start = 0xfff03000,
1831 + .end = 0xfff033ff,
1832 + .flags = IORESOURCE_MEM,
1836 +static struct clk usba0_pclk = {
1838 + .parent = &pbb_clk,
1839 + .mode = pbb_clk_mode,
1840 + .get_rate = pbb_clk_get_rate,
1843 +static struct clk usba0_hclk = {
1845 + .parent = &hsb_clk,
1846 + .mode = hsb_clk_mode,
1847 + .get_rate = hsb_clk_get_rate,
1851 +struct platform_device *__init
1852 +at32_add_device_usba(unsigned int id, struct usba_platform_data *data)
1854 + struct platform_device *pdev;
1859 + pdev = platform_device_alloc("atmel_usba_udc", 0);
1863 + if (platform_device_add_resources(pdev, usba0_resource,
1864 + ARRAY_SIZE(usba0_resource)))
1865 + goto out_free_pdev;
1868 + if (platform_device_add_data(pdev, data, sizeof(*data)))
1869 + goto out_free_pdev;
1871 + if (data->vbus_pin != GPIO_PIN_NONE)
1872 + at32_select_gpio(data->vbus_pin, 0);
1875 + usba0_pclk.dev = &pdev->dev;
1876 + usba0_hclk.dev = &pdev->dev;
1878 + platform_device_add(pdev);
1883 + platform_device_put(pdev);
1887 +/* --------------------------------------------------------------------
1889 + * -------------------------------------------------------------------- */
1890 +static struct resource ssc0_resource[] = {
1891 + PBMEM(0xffe01c00),
1894 +DEFINE_DEV(ssc, 0);
1895 +DEV_CLK(pclk, ssc0, pba, 7);
1897 +static struct resource ssc1_resource[] = {
1898 + PBMEM(0xffe02000),
1901 +DEFINE_DEV(ssc, 1);
1902 +DEV_CLK(pclk, ssc1, pba, 8);
1904 +static struct resource ssc2_resource[] = {
1905 + PBMEM(0xffe02400),
1908 +DEFINE_DEV(ssc, 2);
1909 +DEV_CLK(pclk, ssc2, pba, 9);
1911 +struct platform_device *__init
1912 +at32_add_device_ssc(unsigned int id, unsigned int flags)
1914 + struct platform_device *pdev;
1918 + pdev = &ssc0_device;
1919 + if (flags & ATMEL_SSC_RF)
1920 + select_peripheral(PA(21), PERIPH_A, 0); /* RF */
1921 + if (flags & ATMEL_SSC_RK)
1922 + select_peripheral(PA(22), PERIPH_A, 0); /* RK */
1923 + if (flags & ATMEL_SSC_TK)
1924 + select_peripheral(PA(23), PERIPH_A, 0); /* TK */
1925 + if (flags & ATMEL_SSC_TF)
1926 + select_peripheral(PA(24), PERIPH_A, 0); /* TF */
1927 + if (flags & ATMEL_SSC_TD)
1928 + select_peripheral(PA(25), PERIPH_A, 0); /* TD */
1929 + if (flags & ATMEL_SSC_RD)
1930 + select_peripheral(PA(26), PERIPH_A, 0); /* RD */
1933 + pdev = &ssc1_device;
1934 + if (flags & ATMEL_SSC_RF)
1935 + select_peripheral(PA(0), PERIPH_B, 0); /* RF */
1936 + if (flags & ATMEL_SSC_RK)
1937 + select_peripheral(PA(1), PERIPH_B, 0); /* RK */
1938 + if (flags & ATMEL_SSC_TK)
1939 + select_peripheral(PA(2), PERIPH_B, 0); /* TK */
1940 + if (flags & ATMEL_SSC_TF)
1941 + select_peripheral(PA(3), PERIPH_B, 0); /* TF */
1942 + if (flags & ATMEL_SSC_TD)
1943 + select_peripheral(PA(4), PERIPH_B, 0); /* TD */
1944 + if (flags & ATMEL_SSC_RD)
1945 + select_peripheral(PA(5), PERIPH_B, 0); /* RD */
1948 + pdev = &ssc2_device;
1949 + if (flags & ATMEL_SSC_TD)
1950 + select_peripheral(PB(13), PERIPH_A, 0); /* TD */
1951 + if (flags & ATMEL_SSC_RD)
1952 + select_peripheral(PB(14), PERIPH_A, 0); /* RD */
1953 + if (flags & ATMEL_SSC_TK)
1954 + select_peripheral(PB(15), PERIPH_A, 0); /* TK */
1955 + if (flags & ATMEL_SSC_TF)
1956 + select_peripheral(PB(16), PERIPH_A, 0); /* TF */
1957 + if (flags & ATMEL_SSC_RF)
1958 + select_peripheral(PB(17), PERIPH_A, 0); /* RF */
1959 + if (flags & ATMEL_SSC_RK)
1960 + select_peripheral(PB(18), PERIPH_A, 0); /* RK */
1966 + platform_device_register(pdev);
1970 +/* --------------------------------------------------------------------
1972 + * -------------------------------------------------------------------- */
1973 +static struct resource atmel_ac97c0_resource[] = {
1974 + PBMEM(0xfff02800),
1977 +DEFINE_DEV(atmel_ac97c, 0);
1978 +DEV_CLK(pclk, atmel_ac97c0, pbb, 10);
1980 +struct platform_device *__init
1981 +at32_add_device_ac97c(unsigned int id)
1983 + struct platform_device *pdev;
1987 + pdev = &atmel_ac97c0_device;
1988 + select_peripheral(PB(20), PERIPH_B, 0); /* SYNC */
1989 + select_peripheral(PB(21), PERIPH_B, 0); /* SDO */
1990 + select_peripheral(PB(22), PERIPH_B, 0); /* SDI */
1991 + select_peripheral(PB(23), PERIPH_B, 0); /* SCLK */
1997 + platform_device_register(pdev);
2001 +/* --------------------------------------------------------------------
2003 + * -------------------------------------------------------------------- */
2004 +static struct resource abdac0_resource[] = {
2005 + PBMEM(0xfff02000),
2008 +DEFINE_DEV(abdac, 0);
2009 +DEV_CLK(pclk, abdac0, pbb, 8);
2010 +static struct clk abdac0_sample_clk = {
2011 + .name = "sample_clk",
2012 + .dev = &abdac0_device.dev,
2013 + .mode = genclk_mode,
2014 + .get_rate = genclk_get_rate,
2015 + .set_rate = genclk_set_rate,
2016 + .set_parent = genclk_set_parent,
2020 +struct platform_device *__init
2021 +at32_add_device_abdac(unsigned int id)
2023 + struct platform_device *pdev;
2027 + pdev = &abdac0_device;
2028 + select_peripheral(PB(20), PERIPH_A, 0); /* DATA1 */
2029 + select_peripheral(PB(21), PERIPH_A, 0); /* DATA0 */
2030 + select_peripheral(PB(22), PERIPH_A, 0); /* DATAN1 */
2031 + select_peripheral(PB(23), PERIPH_A, 0); /* DATAN0 */
2037 + platform_device_register(pdev);
2041 +/* --------------------------------------------------------------------
2043 * -------------------------------------------------------------------- */
2044 static struct clk gclk0 = {
2045 @@ -1066,7 +1449,7 @@
2054 @@ -1075,6 +1458,7 @@
2062 @@ -1092,8 +1476,18 @@
2064 &atmel_spi0_spi_clk,
2065 &atmel_spi1_spi_clk,
2067 + &atmel_mci0_mci_clk,
2069 &atmel_lcdfb0_pixclk,
2075 + &atmel_ac97c0_pclk,
2077 + &abdac0_sample_clk,
2081 @@ -1113,18 +1507,20 @@
2083 void __init at32_clock_init(void)
2085 - struct at32_sm *sm = &system_manager;
2086 u32 cpu_mask = 0, hsb_mask = 0, pba_mask = 0, pbb_mask = 0;
2089 - if (sm_readl(sm, PM_MCCTRL) & SM_BIT(PLLSEL))
2090 + if (pm_readl(MCCTRL) & PM_BIT(PLLSEL)) {
2093 + cpu_clk.parent = &pll0;
2096 + cpu_clk.parent = &osc0;
2099 - if (sm_readl(sm, PM_PLL0) & SM_BIT(PLLOSC))
2100 + if (pm_readl(PLL0) & PM_BIT(PLLOSC))
2101 pll0.parent = &osc1;
2102 - if (sm_readl(sm, PM_PLL1) & SM_BIT(PLLOSC))
2103 + if (pm_readl(PLL1) & PM_BIT(PLLOSC))
2104 pll1.parent = &osc1;
2106 genclk_init_parent(&gclk0);
2107 @@ -1133,6 +1529,7 @@
2108 genclk_init_parent(&gclk3);
2109 genclk_init_parent(&gclk4);
2110 genclk_init_parent(&atmel_lcdfb0_pixclk);
2111 + genclk_init_parent(&abdac0_sample_clk);
2114 * Turn on all clocks that have at least one user already, and
2115 @@ -1157,8 +1554,8 @@
2116 pbb_mask |= 1 << clk->index;
2119 - sm_writel(sm, PM_CPU_MASK, cpu_mask);
2120 - sm_writel(sm, PM_HSB_MASK, hsb_mask);
2121 - sm_writel(sm, PM_PBA_MASK, pba_mask);
2122 - sm_writel(sm, PM_PBB_MASK, pbb_mask);
2123 + pm_writel(CPU_MASK, cpu_mask);
2124 + pm_writel(HSB_MASK, hsb_mask);
2125 + pm_writel(PBA_MASK, pba_mask);
2126 + pm_writel(PBB_MASK, pbb_mask);
2128 diff -x .git -Nur linux-2.6.22.1/arch/avr32/mach-at32ap/at32ap.c linux-avr32.git/arch/avr32/mach-at32ap/at32ap.c
2129 --- linux-2.6.22.1/arch/avr32/mach-at32ap/at32ap.c 2007-07-10 20:56:30.000000000 +0200
2130 +++ linux-avr32.git/arch/avr32/mach-at32ap/at32ap.c 2007-07-12 13:59:49.000000000 +0200
2132 #include <linux/init.h>
2133 #include <linux/platform_device.h>
2135 -#include <asm/io.h>
2137 #include <asm/arch/init.h>
2138 -#include <asm/arch/sm.h>
2140 -struct at32_sm system_manager;
2142 -static int __init at32_sm_init(void)
2144 - struct resource *regs;
2145 - struct at32_sm *sm = &system_manager;
2148 - regs = platform_get_resource(&at32_sm_device, IORESOURCE_MEM, 0);
2152 - spin_lock_init(&sm->lock);
2153 - sm->pdev = &at32_sm_device;
2156 - sm->regs = ioremap(regs->start, regs->end - regs->start + 1);
2163 - printk(KERN_ERR "Failed to initialize System Manager: %d\n", ret);
2167 void __init setup_platform(void)
2171 at32_portmux_init();
2173 diff -x .git -Nur linux-2.6.22.1/arch/avr32/mach-at32ap/cpufreq.c linux-avr32.git/arch/avr32/mach-at32ap/cpufreq.c
2174 --- linux-2.6.22.1/arch/avr32/mach-at32ap/cpufreq.c 1970-01-01 01:00:00.000000000 +0100
2175 +++ linux-avr32.git/arch/avr32/mach-at32ap/cpufreq.c 2007-07-12 13:59:49.000000000 +0200
2178 + * Copyright (C) 2004-2007 Atmel Corporation
2180 + * Based on MIPS implementation arch/mips/kernel/time.c
2181 + * Copyright 2001 MontaVista Software Inc.
2183 + * This program is free software; you can redistribute it and/or modify
2184 + * it under the terms of the GNU General Public License version 2 as
2185 + * published by the Free Software Foundation.
2190 +#include <linux/kernel.h>
2191 +#include <linux/types.h>
2192 +#include <linux/init.h>
2193 +#include <linux/cpufreq.h>
2194 +#include <linux/io.h>
2195 +#include <linux/clk.h>
2196 +#include <linux/err.h>
2197 +#include <asm/system.h>
2199 +static struct clk *cpuclk;
2201 +static int at32_verify_speed(struct cpufreq_policy *policy)
2203 + if (policy->cpu != 0)
2206 + cpufreq_verify_within_limits(policy, policy->cpuinfo.min_freq,
2207 + policy->cpuinfo.max_freq);
2211 +static unsigned int at32_get_speed(unsigned int cpu)
2213 + /* No SMP support */
2216 + return (unsigned int)((clk_get_rate(cpuclk) + 500) / 1000);
2219 +static int at32_set_target(struct cpufreq_policy *policy,
2220 + unsigned int target_freq,
2221 + unsigned int relation)
2223 + struct cpufreq_freqs freqs;
2226 + /* Convert target_freq from kHz to Hz */
2227 + freq = clk_round_rate(cpuclk, target_freq * 1000);
2229 + /* Check if policy->min <= new_freq <= policy->max */
2230 + if(freq < (policy->min * 1000) || freq > (policy->max * 1000))
2233 + pr_debug("cpufreq: requested frequency %u Hz\n", target_freq * 1000);
2235 + freqs.old = at32_get_speed(0);
2236 + freqs.new = (freq + 500) / 1000;
2240 + cpufreq_notify_transition(&freqs, CPUFREQ_PRECHANGE);
2241 + clk_set_rate(cpuclk, freq);
2242 + cpufreq_notify_transition(&freqs, CPUFREQ_POSTCHANGE);
2244 + pr_debug("cpufreq: set frequency %lu Hz\n", freq);
2249 +static int __init at32_cpufreq_driver_init(struct cpufreq_policy *policy)
2251 + if (policy->cpu != 0)
2254 + cpuclk = clk_get(NULL, "cpu");
2255 + if (IS_ERR(cpuclk)) {
2256 + pr_debug("cpufreq: could not get CPU clk\n");
2257 + return PTR_ERR(cpuclk);
2260 + policy->cpuinfo.min_freq = (clk_round_rate(cpuclk, 1) + 500) / 1000;
2261 + policy->cpuinfo.max_freq = (clk_round_rate(cpuclk, ~0UL) + 500) / 1000;
2262 + policy->cpuinfo.transition_latency = 0;
2263 + policy->cur = at32_get_speed(0);
2264 + policy->min = policy->cpuinfo.min_freq;
2265 + policy->max = policy->cpuinfo.max_freq;
2266 + policy->governor = CPUFREQ_DEFAULT_GOVERNOR;
2268 + printk("cpufreq: AT32AP CPU frequency driver\n");
2273 +static struct cpufreq_driver at32_driver = {
2275 + .owner = THIS_MODULE,
2276 + .init = at32_cpufreq_driver_init,
2277 + .verify = at32_verify_speed,
2278 + .target = at32_set_target,
2279 + .get = at32_get_speed,
2280 + .flags = CPUFREQ_STICKY,
2283 +static int __init at32_cpufreq_init(void)
2285 + return cpufreq_register_driver(&at32_driver);
2288 +arch_initcall(at32_cpufreq_init);
2289 diff -x .git -Nur linux-2.6.22.1/arch/avr32/mach-at32ap/extint.c linux-avr32.git/arch/avr32/mach-at32ap/extint.c
2290 --- linux-2.6.22.1/arch/avr32/mach-at32ap/extint.c 2007-07-10 20:56:30.000000000 +0200
2291 +++ linux-avr32.git/arch/avr32/mach-at32ap/extint.c 2007-07-12 13:59:49.000000000 +0200
2296 -#include <asm/arch/sm.h>
2299 +/* EIC register offsets */
2300 +#define EIC_IER 0x0000
2301 +#define EIC_IDR 0x0004
2302 +#define EIC_IMR 0x0008
2303 +#define EIC_ISR 0x000c
2304 +#define EIC_ICR 0x0010
2305 +#define EIC_MODE 0x0014
2306 +#define EIC_EDGE 0x0018
2307 +#define EIC_LEVEL 0x001c
2308 +#define EIC_TEST 0x0020
2309 +#define EIC_NMIC 0x0024
2311 +/* Bitfields in TEST */
2312 +#define EIC_TESTEN_OFFSET 31
2313 +#define EIC_TESTEN_SIZE 1
2315 +/* Bitfields in NMIC */
2316 +#define EIC_EN_OFFSET 0
2317 +#define EIC_EN_SIZE 1
2319 +/* Bit manipulation macros */
2320 +#define EIC_BIT(name) \
2321 + (1 << EIC_##name##_OFFSET)
2322 +#define EIC_BF(name,value) \
2323 + (((value) & ((1 << EIC_##name##_SIZE) - 1)) \
2324 + << EIC_##name##_OFFSET)
2325 +#define EIC_BFEXT(name,value) \
2326 + (((value) >> EIC_##name##_OFFSET) \
2327 + & ((1 << EIC_##name##_SIZE) - 1))
2328 +#define EIC_BFINS(name,value,old) \
2329 + (((old) & ~(((1 << EIC_##name##_SIZE) - 1) \
2330 + << EIC_##name##_OFFSET)) \
2331 + | EIC_BF(name,value))
2333 +/* Register access macros */
2334 +#define eic_readl(port,reg) \
2335 + __raw_readl((port)->regs + EIC_##reg)
2336 +#define eic_writel(port,reg,value) \
2337 + __raw_writel((value), (port)->regs + EIC_##reg)
2340 + void __iomem *regs;
2341 + struct irq_chip *chip;
2342 + unsigned int first_irq;
2345 -static void eim_ack_irq(unsigned int irq)
2346 +static void eic_ack_irq(unsigned int irq)
2348 - struct at32_sm *sm = get_irq_chip_data(irq);
2349 - sm_writel(sm, EIM_ICR, 1 << (irq - sm->eim_first_irq));
2350 + struct eic *eic = get_irq_chip_data(irq);
2351 + eic_writel(eic, ICR, 1 << (irq - eic->first_irq));
2354 -static void eim_mask_irq(unsigned int irq)
2355 +static void eic_mask_irq(unsigned int irq)
2357 - struct at32_sm *sm = get_irq_chip_data(irq);
2358 - sm_writel(sm, EIM_IDR, 1 << (irq - sm->eim_first_irq));
2359 + struct eic *eic = get_irq_chip_data(irq);
2360 + eic_writel(eic, IDR, 1 << (irq - eic->first_irq));
2363 -static void eim_mask_ack_irq(unsigned int irq)
2364 +static void eic_mask_ack_irq(unsigned int irq)
2366 - struct at32_sm *sm = get_irq_chip_data(irq);
2367 - sm_writel(sm, EIM_ICR, 1 << (irq - sm->eim_first_irq));
2368 - sm_writel(sm, EIM_IDR, 1 << (irq - sm->eim_first_irq));
2369 + struct eic *eic = get_irq_chip_data(irq);
2370 + eic_writel(eic, ICR, 1 << (irq - eic->first_irq));
2371 + eic_writel(eic, IDR, 1 << (irq - eic->first_irq));
2374 -static void eim_unmask_irq(unsigned int irq)
2375 +static void eic_unmask_irq(unsigned int irq)
2377 - struct at32_sm *sm = get_irq_chip_data(irq);
2378 - sm_writel(sm, EIM_IER, 1 << (irq - sm->eim_first_irq));
2379 + struct eic *eic = get_irq_chip_data(irq);
2380 + eic_writel(eic, IER, 1 << (irq - eic->first_irq));
2383 -static int eim_set_irq_type(unsigned int irq, unsigned int flow_type)
2384 +static int eic_set_irq_type(unsigned int irq, unsigned int flow_type)
2386 - struct at32_sm *sm = get_irq_chip_data(irq);
2387 + struct eic *eic = get_irq_chip_data(irq);
2388 struct irq_desc *desc;
2389 - unsigned int i = irq - sm->eim_first_irq;
2390 + unsigned int i = irq - eic->first_irq;
2391 u32 mode, edge, level;
2392 - unsigned long flags;
2395 flow_type &= IRQ_TYPE_SENSE_MASK;
2396 @@ -60,11 +101,10 @@
2397 flow_type = IRQ_TYPE_LEVEL_LOW;
2399 desc = &irq_desc[irq];
2400 - spin_lock_irqsave(&sm->lock, flags);
2402 - mode = sm_readl(sm, EIM_MODE);
2403 - edge = sm_readl(sm, EIM_EDGE);
2404 - level = sm_readl(sm, EIM_LEVEL);
2405 + mode = eic_readl(eic, MODE);
2406 + edge = eic_readl(eic, EDGE);
2407 + level = eic_readl(eic, LEVEL);
2409 switch (flow_type) {
2410 case IRQ_TYPE_LEVEL_LOW:
2415 - sm_writel(sm, EIM_MODE, mode);
2416 - sm_writel(sm, EIM_EDGE, edge);
2417 - sm_writel(sm, EIM_LEVEL, level);
2418 + eic_writel(eic, MODE, mode);
2419 + eic_writel(eic, EDGE, edge);
2420 + eic_writel(eic, LEVEL, level);
2422 if (flow_type & (IRQ_TYPE_LEVEL_LOW | IRQ_TYPE_LEVEL_HIGH))
2423 flow_type |= IRQ_LEVEL;
2424 @@ -99,35 +139,33 @@
2425 desc->status |= flow_type;
2428 - spin_unlock_irqrestore(&sm->lock, flags);
2433 -struct irq_chip eim_chip = {
2435 - .ack = eim_ack_irq,
2436 - .mask = eim_mask_irq,
2437 - .mask_ack = eim_mask_ack_irq,
2438 - .unmask = eim_unmask_irq,
2439 - .set_type = eim_set_irq_type,
2440 +struct irq_chip eic_chip = {
2442 + .ack = eic_ack_irq,
2443 + .mask = eic_mask_irq,
2444 + .mask_ack = eic_mask_ack_irq,
2445 + .unmask = eic_unmask_irq,
2446 + .set_type = eic_set_irq_type,
2449 -static void demux_eim_irq(unsigned int irq, struct irq_desc *desc)
2450 +static void demux_eic_irq(unsigned int irq, struct irq_desc *desc)
2452 - struct at32_sm *sm = desc->handler_data;
2453 + struct eic *eic = desc->handler_data;
2454 struct irq_desc *ext_desc;
2455 unsigned long status, pending;
2456 unsigned int i, ext_irq;
2458 - status = sm_readl(sm, EIM_ISR);
2459 - pending = status & sm_readl(sm, EIM_IMR);
2460 + status = eic_readl(eic, ISR);
2461 + pending = status & eic_readl(eic, IMR);
2464 i = fls(pending) - 1;
2465 pending &= ~(1 << i);
2467 - ext_irq = i + sm->eim_first_irq;
2468 + ext_irq = i + eic->first_irq;
2469 ext_desc = irq_desc + ext_irq;
2470 if (ext_desc->status & IRQ_LEVEL)
2471 handle_level_irq(ext_irq, ext_desc);
2472 @@ -136,51 +174,85 @@
2476 -static int __init eim_init(void)
2477 +static int __init eic_probe(struct platform_device *pdev)
2479 - struct at32_sm *sm = &system_manager;
2481 + struct resource *regs;
2483 unsigned int nr_irqs;
2484 unsigned int int_irq;
2489 - * The EIM is really the same module as SM, so register
2490 - * mapping, etc. has been taken care of already.
2492 + regs = platform_get_resource(pdev, IORESOURCE_MEM, 0);
2493 + int_irq = platform_get_irq(pdev, 0);
2494 + if (!regs || !int_irq) {
2495 + dev_dbg(&pdev->dev, "missing regs and/or irq resource\n");
2500 + eic = kzalloc(sizeof(struct eic), GFP_KERNEL);
2502 + dev_dbg(&pdev->dev, "no memory for eic structure\n");
2506 + eic->first_irq = EIM_IRQ_BASE + 32 * pdev->id;
2507 + eic->regs = ioremap(regs->start, regs->end - regs->start + 1);
2509 + dev_dbg(&pdev->dev, "failed to map regs\n");
2514 * Find out how many interrupt lines that are actually
2515 * implemented in hardware.
2517 - sm_writel(sm, EIM_IDR, ~0UL);
2518 - sm_writel(sm, EIM_MODE, ~0UL);
2519 - pattern = sm_readl(sm, EIM_MODE);
2520 + eic_writel(eic, IDR, ~0UL);
2521 + eic_writel(eic, MODE, ~0UL);
2522 + pattern = eic_readl(eic, MODE);
2523 nr_irqs = fls(pattern);
2525 /* Trigger on falling edge unless overridden by driver */
2526 - sm_writel(sm, EIM_MODE, 0UL);
2527 - sm_writel(sm, EIM_EDGE, 0UL);
2528 + eic_writel(eic, MODE, 0UL);
2529 + eic_writel(eic, EDGE, 0UL);
2531 - sm->eim_chip = &eim_chip;
2532 + eic->chip = &eic_chip;
2534 for (i = 0; i < nr_irqs; i++) {
2535 /* NOTE the handler we set here is ignored by the demux */
2536 - set_irq_chip_and_handler(sm->eim_first_irq + i, &eim_chip,
2537 + set_irq_chip_and_handler(eic->first_irq + i, &eic_chip,
2539 - set_irq_chip_data(sm->eim_first_irq + i, sm);
2540 + set_irq_chip_data(eic->first_irq + i, eic);
2543 - int_irq = platform_get_irq_byname(sm->pdev, "eim");
2545 - set_irq_chained_handler(int_irq, demux_eim_irq);
2546 - set_irq_data(int_irq, sm);
2547 + set_irq_chained_handler(int_irq, demux_eic_irq);
2548 + set_irq_data(int_irq, eic);
2550 - printk("EIM: External Interrupt Module at 0x%p, IRQ %u\n",
2551 - sm->regs, int_irq);
2552 - printk("EIM: Handling %u external IRQs, starting with IRQ %u\n",
2553 - nr_irqs, sm->eim_first_irq);
2554 + dev_info(&pdev->dev,
2555 + "External Interrupt Controller at 0x%p, IRQ %u\n",
2556 + eic->regs, int_irq);
2557 + dev_info(&pdev->dev,
2558 + "Handling %u external IRQs, starting with IRQ %u\n",
2559 + nr_irqs, eic->first_irq);
2569 +static struct platform_driver eic_driver = {
2571 + .name = "at32_eic",
2575 +static int __init eic_init(void)
2577 + return platform_driver_probe(&eic_driver, eic_probe);
2579 -arch_initcall(eim_init);
2580 +arch_initcall(eic_init);
2581 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
2582 --- linux-2.6.22.1/arch/avr32/mach-at32ap/gpio-dev.c 1970-01-01 01:00:00.000000000 +0100
2583 +++ linux-avr32.git/arch/avr32/mach-at32ap/gpio-dev.c 2007-07-12 13:59:49.000000000 +0200
2586 + * GPIO /dev and configfs interface
2588 + * Copyright (C) 2006-2007 Atmel Corporation
2590 + * This program is free software; you can redistribute it and/or modify
2591 + * it under the terms of the GNU General Public License version 2 as
2592 + * published by the Free Software Foundation.
2594 +#include <linux/configfs.h>
2595 +#include <linux/cdev.h>
2596 +#include <linux/fs.h>
2597 +#include <linux/interrupt.h>
2598 +#include <linux/poll.h>
2599 +#include <linux/uaccess.h>
2600 +#include <linux/wait.h>
2602 +#include <asm/gpio.h>
2603 +#include <asm/arch/portmux.h>
2605 +#define GPIO_DEV_MAX 8
2607 +static struct class *gpio_dev_class;
2608 +static dev_t gpio_devt;
2619 + /* Pin state last time we read it (for blocking reads) */
2623 + wait_queue_head_t change_wq;
2624 + struct fasync_struct *async_queue;
2627 + struct class_device *gpio_dev;
2628 + struct cdev char_dev;
2629 + struct config_item item;
2632 +struct gpio_attribute {
2633 + struct configfs_attribute attr;
2634 + ssize_t (*show)(struct gpio_item *, char *);
2635 + ssize_t (*store)(struct gpio_item *, const char *, size_t);
2638 +static irqreturn_t gpio_dev_interrupt(int irq, void *dev_id)
2640 + struct gpio_item *gpio = dev_id;
2641 + u32 old_state, new_state;
2643 + old_state = gpio->pin_state;
2644 + new_state = at32_gpio_get_value_multiple(gpio->port, gpio->pin_mask);
2645 + gpio->pin_state = new_state;
2647 + if (new_state != old_state) {
2648 + gpio->changed = 1;
2649 + wake_up_interruptible(&gpio->change_wq);
2651 + if (gpio->async_queue)
2652 + kill_fasync(&gpio->async_queue, SIGIO, POLL_IN);
2655 + return IRQ_HANDLED;
2658 +static int gpio_dev_open(struct inode *inode, struct file *file)
2660 + struct gpio_item *gpio = container_of(inode->i_cdev,
2667 + nonseekable_open(inode, file);
2668 + config_item_get(&gpio->item);
2669 + file->private_data = gpio;
2671 + gpio->pin_state = at32_gpio_get_value_multiple(gpio->port,
2673 + gpio->changed = 1;
2675 + for (i = 0; i < 32; i++) {
2676 + if (gpio->pin_mask & (1 << i)) {
2677 + irq = gpio_to_irq(32 * gpio->port + i);
2678 + ret = request_irq(irq, gpio_dev_interrupt, 0,
2679 + "gpio-dev", gpio);
2689 + if (gpio->pin_mask & (1 << i)) {
2690 + irq = gpio_to_irq(32 * gpio->port + i);
2691 + free_irq(irq, gpio);
2695 + config_item_put(&gpio->item);
2700 +static int gpio_dev_fasync(int fd, struct file *file, int mode)
2702 + struct gpio_item *gpio = file->private_data;
2704 + return fasync_helper(fd, file, mode, &gpio->async_queue);
2707 +static int gpio_dev_release(struct inode *inode, struct file *file)
2709 + struct gpio_item *gpio = file->private_data;
2713 + gpio_dev_fasync(-1, file, 0);
2715 + for (i = 0; i < 32; i++) {
2716 + if (gpio->pin_mask & (1 << i)) {
2717 + irq = gpio_to_irq(32 * gpio->port + i);
2718 + free_irq(irq, gpio);
2722 + config_item_put(&gpio->item);
2727 +static unsigned int gpio_dev_poll(struct file *file, poll_table *wait)
2729 + struct gpio_item *gpio = file->private_data;
2730 + unsigned int mask = 0;
2732 + poll_wait(file, &gpio->change_wq, wait);
2733 + if (gpio->changed)
2734 + mask |= POLLIN | POLLRDNORM;
2739 +static ssize_t gpio_dev_read(struct file *file, char __user *buf,
2740 + size_t count, loff_t *offset)
2742 + struct gpio_item *gpio = file->private_data;
2745 + spin_lock_irq(&gpio->lock);
2746 + while (!gpio->changed) {
2747 + spin_unlock_irq(&gpio->lock);
2749 + if (file->f_flags & O_NONBLOCK)
2752 + if (wait_event_interruptible(gpio->change_wq, gpio->changed))
2753 + return -ERESTARTSYS;
2755 + spin_lock_irq(&gpio->lock);
2758 + gpio->changed = 0;
2759 + value = at32_gpio_get_value_multiple(gpio->port, gpio->pin_mask);
2761 + spin_unlock_irq(&gpio->lock);
2763 + count = min(count, (size_t)4);
2764 + if (copy_to_user(buf, &value, count))
2770 +static ssize_t gpio_dev_write(struct file *file, const char __user *buf,
2771 + size_t count, loff_t *offset)
2773 + struct gpio_item *gpio = file->private_data;
2777 + count = min(count, (size_t)4);
2778 + if (copy_from_user(&value, buf, count))
2781 + /* Assuming big endian */
2782 + mask <<= (4 - count) * 8;
2783 + mask &= gpio->pin_mask;
2785 + at32_gpio_set_value_multiple(gpio->port, value, mask);
2790 +static struct file_operations gpio_dev_fops = {
2791 + .owner = THIS_MODULE,
2792 + .llseek = no_llseek,
2793 + .open = gpio_dev_open,
2794 + .release = gpio_dev_release,
2795 + .fasync = gpio_dev_fasync,
2796 + .poll = gpio_dev_poll,
2797 + .read = gpio_dev_read,
2798 + .write = gpio_dev_write,
2801 +static struct gpio_item *to_gpio_item(struct config_item *item)
2803 + return item ? container_of(item, struct gpio_item, item) : NULL;
2806 +static ssize_t gpio_show_gpio_id(struct gpio_item *gpio, char *page)
2808 + return sprintf(page, "%d\n", gpio->port);
2811 +static ssize_t gpio_store_gpio_id(struct gpio_item *gpio,
2812 + const char *page, size_t count)
2815 + char *p = (char *)page;
2816 + ssize_t ret = -EINVAL;
2818 + id = simple_strtoul(p, &p, 0);
2819 + if (!p || (*p && (*p != '\n')))
2822 + /* Switching PIO is not allowed when live... */
2823 + spin_lock(&gpio->lock);
2824 + if (!gpio->enabled) {
2826 + if (at32_gpio_port_is_valid(id)) {
2831 + spin_unlock(&gpio->lock);
2836 +static ssize_t gpio_show_pin_mask(struct gpio_item *gpio, char *page)
2838 + return sprintf(page, "0x%08x\n", gpio->pin_mask);
2841 +static ssize_t gpio_store_pin_mask(struct gpio_item *gpio,
2842 + const char *page, size_t count)
2845 + char *p = (char *)page;
2846 + ssize_t ret = -EINVAL;
2848 + new_mask = simple_strtoul(p, &p, 0);
2849 + if (!p || (*p && (*p != '\n')))
2852 + /* Can't update the pin mask while live. */
2853 + spin_lock(&gpio->lock);
2854 + if (!gpio->enabled) {
2855 + gpio->oe_mask &= new_mask;
2856 + gpio->pin_mask = new_mask;
2859 + spin_unlock(&gpio->lock);
2864 +static ssize_t gpio_show_oe_mask(struct gpio_item *gpio, char *page)
2866 + return sprintf(page, "0x%08x\n", gpio->oe_mask);
2869 +static ssize_t gpio_store_oe_mask(struct gpio_item *gpio,
2870 + const char *page, size_t count)
2873 + char *p = (char *)page;
2874 + ssize_t ret = -EINVAL;
2876 + mask = simple_strtoul(p, &p, 0);
2877 + if (!p || (*p && (*p != '\n')))
2880 + spin_lock(&gpio->lock);
2881 + if (!gpio->enabled) {
2882 + gpio->oe_mask = mask & gpio->pin_mask;
2885 + spin_unlock(&gpio->lock);
2890 +static ssize_t gpio_show_enabled(struct gpio_item *gpio, char *page)
2892 + return sprintf(page, "%d\n", gpio->enabled);
2895 +static ssize_t gpio_store_enabled(struct gpio_item *gpio,
2896 + const char *page, size_t count)
2898 + char *p = (char *)page;
2902 + enabled = simple_strtoul(p, &p, 0);
2903 + if (!p || (*p && (*p != '\n')))
2906 + /* make it a boolean value */
2907 + enabled = !!enabled;
2909 + if (gpio->enabled == enabled)
2910 + /* No change; do nothing. */
2913 + BUG_ON(gpio->id >= GPIO_DEV_MAX);
2916 + class_device_unregister(gpio->gpio_dev);
2917 + cdev_del(&gpio->char_dev);
2918 + at32_deselect_pins(gpio->port, gpio->pin_mask);
2919 + gpio->initialized = 0;
2921 + if (gpio->port < 0 || !gpio->pin_mask)
2925 + /* Disallow any updates to gpio_id or pin_mask */
2926 + spin_lock(&gpio->lock);
2927 + gpio->enabled = enabled;
2928 + spin_unlock(&gpio->lock);
2933 + /* Now, try to allocate the pins */
2934 + ret = at32_select_gpio_pins(gpio->port, gpio->pin_mask, gpio->oe_mask);
2936 + goto err_alloc_pins;
2938 + gpio->initialized = 1;
2940 + cdev_init(&gpio->char_dev, &gpio_dev_fops);
2941 + gpio->char_dev.owner = THIS_MODULE;
2942 + ret = cdev_add(&gpio->char_dev, MKDEV(MAJOR(gpio_devt), gpio->id), 1);
2944 + goto err_cdev_add;
2945 + gpio->gpio_dev = class_device_create(gpio_dev_class, NULL,
2946 + MKDEV(MAJOR(gpio_devt), gpio->id),
2948 + "gpio%d", gpio->id);
2949 + if (IS_ERR(gpio->gpio_dev)) {
2950 + printk(KERN_ERR "failed to create gpio%d\n", gpio->id);
2951 + ret = PTR_ERR(gpio->gpio_dev);
2952 + goto err_class_dev;
2955 + printk(KERN_INFO "created gpio%d (port%d/0x%08x) as (%d:%d)\n",
2956 + gpio->id, gpio->port, gpio->pin_mask,
2957 + MAJOR(gpio->gpio_dev->devt), MINOR(gpio->gpio_dev->devt));
2962 + cdev_del(&gpio->char_dev);
2964 + at32_deselect_pins(gpio->port, gpio->pin_mask);
2965 + gpio->initialized = 0;
2967 + spin_lock(&gpio->lock);
2968 + gpio->enabled = 0;
2969 + spin_unlock(&gpio->lock);
2974 +static struct gpio_attribute gpio_item_attr_gpio_id = {
2976 + .ca_owner = THIS_MODULE,
2977 + .ca_name = "gpio_id",
2978 + .ca_mode = S_IRUGO | S_IWUSR,
2980 + .show = gpio_show_gpio_id,
2981 + .store = gpio_store_gpio_id,
2983 +static struct gpio_attribute gpio_item_attr_pin_mask = {
2985 + .ca_owner = THIS_MODULE,
2986 + .ca_name = "pin_mask",
2987 + .ca_mode = S_IRUGO | S_IWUSR,
2989 + .show = gpio_show_pin_mask,
2990 + .store = gpio_store_pin_mask,
2992 +static struct gpio_attribute gpio_item_attr_oe_mask = {
2994 + .ca_owner = THIS_MODULE,
2995 + .ca_name = "oe_mask",
2996 + .ca_mode = S_IRUGO | S_IWUSR,
2998 + .show = gpio_show_oe_mask,
2999 + .store = gpio_store_oe_mask,
3001 +static struct gpio_attribute gpio_item_attr_enabled = {
3003 + .ca_owner = THIS_MODULE,
3004 + .ca_name = "enabled",
3005 + .ca_mode = S_IRUGO | S_IWUSR,
3007 + .show = gpio_show_enabled,
3008 + .store = gpio_store_enabled,
3011 +static struct configfs_attribute *gpio_item_attrs[] = {
3012 + &gpio_item_attr_gpio_id.attr,
3013 + &gpio_item_attr_pin_mask.attr,
3014 + &gpio_item_attr_oe_mask.attr,
3015 + &gpio_item_attr_enabled.attr,
3019 +static ssize_t gpio_show_attr(struct config_item *item,
3020 + struct configfs_attribute *attr,
3023 + struct gpio_item *gpio_item = to_gpio_item(item);
3024 + struct gpio_attribute *gpio_attr
3025 + = container_of(attr, struct gpio_attribute, attr);
3028 + if (gpio_attr->show)
3029 + ret = gpio_attr->show(gpio_item, page);
3033 +static ssize_t gpio_store_attr(struct config_item *item,
3034 + struct configfs_attribute *attr,
3035 + const char *page, size_t count)
3037 + struct gpio_item *gpio_item = to_gpio_item(item);
3038 + struct gpio_attribute *gpio_attr
3039 + = container_of(attr, struct gpio_attribute, attr);
3040 + ssize_t ret = -EINVAL;
3042 + if (gpio_attr->store)
3043 + ret = gpio_attr->store(gpio_item, page, count);
3047 +static void gpio_release(struct config_item *item)
3049 + kfree(to_gpio_item(item));
3052 +static struct configfs_item_operations gpio_item_ops = {
3053 + .release = gpio_release,
3054 + .show_attribute = gpio_show_attr,
3055 + .store_attribute = gpio_store_attr,
3058 +static struct config_item_type gpio_item_type = {
3059 + .ct_item_ops = &gpio_item_ops,
3060 + .ct_attrs = gpio_item_attrs,
3061 + .ct_owner = THIS_MODULE,
3064 +static struct config_item *gpio_make_item(struct config_group *group,
3067 + static int next_id;
3068 + struct gpio_item *gpio;
3070 + if (next_id >= GPIO_DEV_MAX)
3073 + gpio = kzalloc(sizeof(struct gpio_item), GFP_KERNEL);
3077 + gpio->id = next_id++;
3078 + config_item_init_type_name(&gpio->item, name, &gpio_item_type);
3079 + spin_lock_init(&gpio->lock);
3080 + init_waitqueue_head(&gpio->change_wq);
3082 + return &gpio->item;
3085 +static void gpio_drop_item(struct config_group *group,
3086 + struct config_item *item)
3088 + struct gpio_item *gpio = to_gpio_item(item);
3090 + spin_lock(&gpio->lock);
3091 + if (gpio->enabled) {
3092 + class_device_unregister(gpio->gpio_dev);
3093 + cdev_del(&gpio->char_dev);
3096 + if (gpio->initialized) {
3097 + at32_deselect_pins(gpio->port, gpio->pin_mask);
3098 + gpio->initialized = 0;
3099 + gpio->enabled = 0;
3101 + spin_unlock(&gpio->lock);
3104 +static struct configfs_group_operations gpio_group_ops = {
3105 + .make_item = gpio_make_item,
3106 + .drop_item = gpio_drop_item,
3109 +static struct config_item_type gpio_group_type = {
3110 + .ct_group_ops = &gpio_group_ops,
3111 + .ct_owner = THIS_MODULE,
3114 +static struct configfs_subsystem gpio_subsys = {
3117 + .ci_namebuf = "gpio",
3118 + .ci_type = &gpio_group_type,
3123 +static int __init gpio_dev_init(void)
3127 + gpio_dev_class = class_create(THIS_MODULE, "gpio-dev");
3128 + if (IS_ERR(gpio_dev_class)) {
3129 + err = PTR_ERR(gpio_dev_class);
3130 + goto err_class_create;
3133 + err = alloc_chrdev_region(&gpio_devt, 0, GPIO_DEV_MAX, "gpio");
3135 + goto err_alloc_chrdev;
3137 + /* Configfs initialization */
3138 + config_group_init(&gpio_subsys.su_group);
3139 + init_MUTEX(&gpio_subsys.su_sem);
3140 + err = configfs_register_subsystem(&gpio_subsys);
3142 + goto err_register_subsys;
3146 +err_register_subsys:
3147 + unregister_chrdev_region(gpio_devt, GPIO_DEV_MAX);
3149 + class_destroy(gpio_dev_class);
3151 + printk(KERN_WARNING "Failed to initialize gpio /dev interface\n");
3154 +late_initcall(gpio_dev_init);
3155 diff -x .git -Nur linux-2.6.22.1/arch/avr32/mach-at32ap/Kconfig linux-avr32.git/arch/avr32/mach-at32ap/Kconfig
3156 --- linux-2.6.22.1/arch/avr32/mach-at32ap/Kconfig 2007-07-10 20:56:30.000000000 +0200
3157 +++ linux-avr32.git/arch/avr32/mach-at32ap/Kconfig 2007-07-12 13:59:49.000000000 +0200
3163 + bool "GPIO /dev interface"
3164 + select CONFIGFS_FS
3167 + Say `Y' to enable a /dev interface to the GPIO pins.
3171 endif # PLATFORM_AT32AP
3172 diff -x .git -Nur linux-2.6.22.1/arch/avr32/mach-at32ap/Makefile linux-avr32.git/arch/avr32/mach-at32ap/Makefile
3173 --- linux-2.6.22.1/arch/avr32/mach-at32ap/Makefile 2007-07-10 20:56:30.000000000 +0200
3174 +++ linux-avr32.git/arch/avr32/mach-at32ap/Makefile 2007-07-12 13:59:49.000000000 +0200
3176 obj-y += at32ap.o clock.o intc.o extint.o pio.o hsmc.o
3177 obj-$(CONFIG_CPU_AT32AP7000) += at32ap7000.o
3178 obj-$(CONFIG_CPU_AT32AP7000) += time-tc.o
3179 +obj-$(CONFIG_CPU_FREQ_AT32AP) += cpufreq.o
3180 +obj-$(CONFIG_GPIO_DEV) += gpio-dev.o
3181 diff -x .git -Nur linux-2.6.22.1/arch/avr32/mach-at32ap/pio.c linux-avr32.git/arch/avr32/mach-at32ap/pio.c
3182 --- linux-2.6.22.1/arch/avr32/mach-at32ap/pio.c 2007-07-10 20:56:30.000000000 +0200
3183 +++ linux-avr32.git/arch/avr32/mach-at32ap/pio.c 2007-07-12 13:59:49.000000000 +0200
3184 @@ -158,6 +158,82 @@
3188 +#ifdef CONFIG_GPIO_DEV
3190 +/* Gang allocators and accessors; used by the GPIO /dev driver */
3191 +int at32_gpio_port_is_valid(unsigned int port)
3193 + return port < MAX_NR_PIO_DEVICES && pio_dev[port].regs != NULL;
3196 +int at32_select_gpio_pins(unsigned int port, u32 pins, u32 oe_mask)
3198 + struct pio_device *pio;
3201 + pio = &pio_dev[port];
3202 + BUG_ON(port > ARRAY_SIZE(pio_dev) || !pio->regs || (oe_mask & ~pins));
3204 + /* Try to allocate the pins */
3206 + old = pio->pinmux_mask;
3211 + } while (cmpxchg(&pio->pinmux_mask, old, new) != old);
3213 + /* That went well, now configure the port */
3214 + pio_writel(pio, OER, oe_mask);
3215 + pio_writel(pio, PER, pins);
3220 +void at32_deselect_pins(unsigned int port, u32 pins)
3222 + struct pio_device *pio;
3225 + pio = &pio_dev[port];
3226 + BUG_ON(port > ARRAY_SIZE(pio_dev) || !pio->regs);
3228 + /* Return to a "safe" mux configuration */
3229 + pio_writel(pio, PUER, pins);
3230 + pio_writel(pio, ODR, pins);
3232 + /* Deallocate the pins */
3234 + old = pio->pinmux_mask;
3235 + new = old & ~pins;
3236 + } while (cmpxchg(&pio->pinmux_mask, old, new) != old);
3239 +u32 at32_gpio_get_value_multiple(unsigned int port, u32 pins)
3241 + struct pio_device *pio;
3243 + pio = &pio_dev[port];
3244 + BUG_ON(port > ARRAY_SIZE(pio_dev) || !pio->regs);
3246 + return pio_readl(pio, PDSR) & pins;
3249 +void at32_gpio_set_value_multiple(unsigned int port, u32 value, u32 mask)
3251 + struct pio_device *pio;
3253 + pio = &pio_dev[port];
3254 + BUG_ON(port > ARRAY_SIZE(pio_dev) || !pio->regs);
3256 + /* No atomic updates for now... */
3257 + pio_writel(pio, CODR, ~value & mask);
3258 + pio_writel(pio, SODR, value & mask);
3261 +#endif /* CONFIG_GPIO_DEV */
3264 /*--------------------------------------------------------------------------*/
3267 diff -x .git -Nur linux-2.6.22.1/arch/avr32/mach-at32ap/pm.h linux-avr32.git/arch/avr32/mach-at32ap/pm.h
3268 --- linux-2.6.22.1/arch/avr32/mach-at32ap/pm.h 1970-01-01 01:00:00.000000000 +0100
3269 +++ linux-avr32.git/arch/avr32/mach-at32ap/pm.h 2007-07-12 13:59:49.000000000 +0200
3272 + * Register definitions for the Power Manager (PM)
3274 +#ifndef __ARCH_AVR32_MACH_AT32AP_PM_H__
3275 +#define __ARCH_AVR32_MACH_AT32AP_PM_H__
3277 +/* PM register offsets */
3278 +#define PM_MCCTRL 0x0000
3279 +#define PM_CKSEL 0x0004
3280 +#define PM_CPU_MASK 0x0008
3281 +#define PM_HSB_MASK 0x000c
3282 +#define PM_PBA_MASK 0x0010
3283 +#define PM_PBB_MASK 0x0014
3284 +#define PM_PLL0 0x0020
3285 +#define PM_PLL1 0x0024
3286 +#define PM_IER 0x0040
3287 +#define PM_IDR 0x0044
3288 +#define PM_IMR 0x0048
3289 +#define PM_ISR 0x004c
3290 +#define PM_ICR 0x0050
3291 +#define PM_GCCTRL(x) (0x0060 + 4 * (x))
3292 +#define PM_RCAUSE 0x00c0
3294 +/* Bitfields in CKSEL */
3295 +#define PM_CPUSEL_OFFSET 0
3296 +#define PM_CPUSEL_SIZE 3
3297 +#define PM_CPUDIV_OFFSET 7
3298 +#define PM_CPUDIV_SIZE 1
3299 +#define PM_HSBSEL_OFFSET 8
3300 +#define PM_HSBSEL_SIZE 3
3301 +#define PM_HSBDIV_OFFSET 15
3302 +#define PM_HSBDIV_SIZE 1
3303 +#define PM_PBASEL_OFFSET 16
3304 +#define PM_PBASEL_SIZE 3
3305 +#define PM_PBADIV_OFFSET 23
3306 +#define PM_PBADIV_SIZE 1
3307 +#define PM_PBBSEL_OFFSET 24
3308 +#define PM_PBBSEL_SIZE 3
3309 +#define PM_PBBDIV_OFFSET 31
3310 +#define PM_PBBDIV_SIZE 1
3312 +/* Bitfields in PLL0 */
3313 +#define PM_PLLEN_OFFSET 0
3314 +#define PM_PLLEN_SIZE 1
3315 +#define PM_PLLOSC_OFFSET 1
3316 +#define PM_PLLOSC_SIZE 1
3317 +#define PM_PLLOPT_OFFSET 2
3318 +#define PM_PLLOPT_SIZE 3
3319 +#define PM_PLLDIV_OFFSET 8
3320 +#define PM_PLLDIV_SIZE 8
3321 +#define PM_PLLMUL_OFFSET 16
3322 +#define PM_PLLMUL_SIZE 8
3323 +#define PM_PLLCOUNT_OFFSET 24
3324 +#define PM_PLLCOUNT_SIZE 6
3325 +#define PM_PLLTEST_OFFSET 31
3326 +#define PM_PLLTEST_SIZE 1
3328 +/* Bitfields in ICR */
3329 +#define PM_LOCK0_OFFSET 0
3330 +#define PM_LOCK0_SIZE 1
3331 +#define PM_LOCK1_OFFSET 1
3332 +#define PM_LOCK1_SIZE 1
3333 +#define PM_WAKE_OFFSET 2
3334 +#define PM_WAKE_SIZE 1
3335 +#define PM_CKRDY_OFFSET 5
3336 +#define PM_CKRDY_SIZE 1
3337 +#define PM_MSKRDY_OFFSET 6
3338 +#define PM_MSKRDY_SIZE 1
3340 +/* Bitfields in GCCTRL0 */
3341 +#define PM_OSCSEL_OFFSET 0
3342 +#define PM_OSCSEL_SIZE 1
3343 +#define PM_PLLSEL_OFFSET 1
3344 +#define PM_PLLSEL_SIZE 1
3345 +#define PM_CEN_OFFSET 2
3346 +#define PM_CEN_SIZE 1
3347 +#define PM_DIVEN_OFFSET 4
3348 +#define PM_DIVEN_SIZE 1
3349 +#define PM_DIV_OFFSET 8
3350 +#define PM_DIV_SIZE 8
3352 +/* Bitfields in RCAUSE */
3353 +#define PM_POR_OFFSET 0
3354 +#define PM_POR_SIZE 1
3355 +#define PM_EXT_OFFSET 2
3356 +#define PM_EXT_SIZE 1
3357 +#define PM_WDT_OFFSET 3
3358 +#define PM_WDT_SIZE 1
3359 +#define PM_NTAE_OFFSET 4
3360 +#define PM_NTAE_SIZE 1
3362 +/* Bit manipulation macros */
3363 +#define PM_BIT(name) \
3364 + (1 << PM_##name##_OFFSET)
3365 +#define PM_BF(name,value) \
3366 + (((value) & ((1 << PM_##name##_SIZE) - 1)) \
3367 + << PM_##name##_OFFSET)
3368 +#define PM_BFEXT(name,value) \
3369 + (((value) >> PM_##name##_OFFSET) \
3370 + & ((1 << PM_##name##_SIZE) - 1))
3371 +#define PM_BFINS(name,value,old)\
3372 + (((old) & ~(((1 << PM_##name##_SIZE) - 1) \
3373 + << PM_##name##_OFFSET)) \
3374 + | PM_BF(name,value))
3376 +/* Register access macros */
3377 +#define pm_readl(reg) \
3378 + __raw_readl((void __iomem *)AT32_PM_BASE + PM_##reg)
3379 +#define pm_writel(reg,value) \
3380 + __raw_writel((value), (void __iomem *)AT32_PM_BASE + PM_##reg)
3382 +#endif /* __ARCH_AVR32_MACH_AT32AP_PM_H__ */
3383 diff -x .git -Nur linux-2.6.22.1/arch/avr32/mach-at32ap/sm.h linux-avr32.git/arch/avr32/mach-at32ap/sm.h
3384 --- linux-2.6.22.1/arch/avr32/mach-at32ap/sm.h 2007-07-10 20:56:30.000000000 +0200
3385 +++ linux-avr32.git/arch/avr32/mach-at32ap/sm.h 1970-01-01 01:00:00.000000000 +0100
3388 - * Register definitions for SM
3392 -#ifndef __ASM_AVR32_SM_H__
3393 -#define __ASM_AVR32_SM_H__
3395 -/* SM register offsets */
3396 -#define SM_PM_MCCTRL 0x0000
3397 -#define SM_PM_CKSEL 0x0004
3398 -#define SM_PM_CPU_MASK 0x0008
3399 -#define SM_PM_HSB_MASK 0x000c
3400 -#define SM_PM_PBA_MASK 0x0010
3401 -#define SM_PM_PBB_MASK 0x0014
3402 -#define SM_PM_PLL0 0x0020
3403 -#define SM_PM_PLL1 0x0024
3404 -#define SM_PM_VCTRL 0x0030
3405 -#define SM_PM_VMREF 0x0034
3406 -#define SM_PM_VMV 0x0038
3407 -#define SM_PM_IER 0x0040
3408 -#define SM_PM_IDR 0x0044
3409 -#define SM_PM_IMR 0x0048
3410 -#define SM_PM_ISR 0x004c
3411 -#define SM_PM_ICR 0x0050
3412 -#define SM_PM_GCCTRL 0x0060
3413 -#define SM_RTC_CTRL 0x0080
3414 -#define SM_RTC_VAL 0x0084
3415 -#define SM_RTC_TOP 0x0088
3416 -#define SM_RTC_IER 0x0090
3417 -#define SM_RTC_IDR 0x0094
3418 -#define SM_RTC_IMR 0x0098
3419 -#define SM_RTC_ISR 0x009c
3420 -#define SM_RTC_ICR 0x00a0
3421 -#define SM_WDT_CTRL 0x00b0
3422 -#define SM_WDT_CLR 0x00b4
3423 -#define SM_WDT_EXT 0x00b8
3424 -#define SM_RC_RCAUSE 0x00c0
3425 -#define SM_EIM_IER 0x0100
3426 -#define SM_EIM_IDR 0x0104
3427 -#define SM_EIM_IMR 0x0108
3428 -#define SM_EIM_ISR 0x010c
3429 -#define SM_EIM_ICR 0x0110
3430 -#define SM_EIM_MODE 0x0114
3431 -#define SM_EIM_EDGE 0x0118
3432 -#define SM_EIM_LEVEL 0x011c
3433 -#define SM_EIM_TEST 0x0120
3434 -#define SM_EIM_NMIC 0x0124
3436 -/* Bitfields in PM_MCCTRL */
3438 -/* Bitfields in PM_CKSEL */
3439 -#define SM_CPUSEL_OFFSET 0
3440 -#define SM_CPUSEL_SIZE 3
3441 -#define SM_CPUDIV_OFFSET 7
3442 -#define SM_CPUDIV_SIZE 1
3443 -#define SM_HSBSEL_OFFSET 8
3444 -#define SM_HSBSEL_SIZE 3
3445 -#define SM_HSBDIV_OFFSET 15
3446 -#define SM_HSBDIV_SIZE 1
3447 -#define SM_PBASEL_OFFSET 16
3448 -#define SM_PBASEL_SIZE 3
3449 -#define SM_PBADIV_OFFSET 23
3450 -#define SM_PBADIV_SIZE 1
3451 -#define SM_PBBSEL_OFFSET 24
3452 -#define SM_PBBSEL_SIZE 3
3453 -#define SM_PBBDIV_OFFSET 31
3454 -#define SM_PBBDIV_SIZE 1
3456 -/* Bitfields in PM_CPU_MASK */
3458 -/* Bitfields in PM_HSB_MASK */
3460 -/* Bitfields in PM_PBA_MASK */
3462 -/* Bitfields in PM_PBB_MASK */
3464 -/* Bitfields in PM_PLL0 */
3465 -#define SM_PLLEN_OFFSET 0
3466 -#define SM_PLLEN_SIZE 1
3467 -#define SM_PLLOSC_OFFSET 1
3468 -#define SM_PLLOSC_SIZE 1
3469 -#define SM_PLLOPT_OFFSET 2
3470 -#define SM_PLLOPT_SIZE 3
3471 -#define SM_PLLDIV_OFFSET 8
3472 -#define SM_PLLDIV_SIZE 8
3473 -#define SM_PLLMUL_OFFSET 16
3474 -#define SM_PLLMUL_SIZE 8
3475 -#define SM_PLLCOUNT_OFFSET 24
3476 -#define SM_PLLCOUNT_SIZE 6
3477 -#define SM_PLLTEST_OFFSET 31
3478 -#define SM_PLLTEST_SIZE 1
3480 -/* Bitfields in PM_PLL1 */
3482 -/* Bitfields in PM_VCTRL */
3483 -#define SM_VAUTO_OFFSET 0
3484 -#define SM_VAUTO_SIZE 1
3485 -#define SM_PM_VCTRL_VAL_OFFSET 8
3486 -#define SM_PM_VCTRL_VAL_SIZE 7
3488 -/* Bitfields in PM_VMREF */
3489 -#define SM_REFSEL_OFFSET 0
3490 -#define SM_REFSEL_SIZE 4
3492 -/* Bitfields in PM_VMV */
3493 -#define SM_PM_VMV_VAL_OFFSET 0
3494 -#define SM_PM_VMV_VAL_SIZE 8
3496 -/* Bitfields in PM_IER */
3498 -/* Bitfields in PM_IDR */
3500 -/* Bitfields in PM_IMR */
3502 -/* Bitfields in PM_ISR */
3504 -/* Bitfields in PM_ICR */
3505 -#define SM_LOCK0_OFFSET 0
3506 -#define SM_LOCK0_SIZE 1
3507 -#define SM_LOCK1_OFFSET 1
3508 -#define SM_LOCK1_SIZE 1
3509 -#define SM_WAKE_OFFSET 2
3510 -#define SM_WAKE_SIZE 1
3511 -#define SM_VOK_OFFSET 3
3512 -#define SM_VOK_SIZE 1
3513 -#define SM_VMRDY_OFFSET 4
3514 -#define SM_VMRDY_SIZE 1
3515 -#define SM_CKRDY_OFFSET 5
3516 -#define SM_CKRDY_SIZE 1
3518 -/* Bitfields in PM_GCCTRL */
3519 -#define SM_OSCSEL_OFFSET 0
3520 -#define SM_OSCSEL_SIZE 1
3521 -#define SM_PLLSEL_OFFSET 1
3522 -#define SM_PLLSEL_SIZE 1
3523 -#define SM_CEN_OFFSET 2
3524 -#define SM_CEN_SIZE 1
3525 -#define SM_CPC_OFFSET 3
3526 -#define SM_CPC_SIZE 1
3527 -#define SM_DIVEN_OFFSET 4
3528 -#define SM_DIVEN_SIZE 1
3529 -#define SM_DIV_OFFSET 8
3530 -#define SM_DIV_SIZE 8
3532 -/* Bitfields in RTC_CTRL */
3533 -#define SM_PCLR_OFFSET 1
3534 -#define SM_PCLR_SIZE 1
3535 -#define SM_TOPEN_OFFSET 2
3536 -#define SM_TOPEN_SIZE 1
3537 -#define SM_CLKEN_OFFSET 3
3538 -#define SM_CLKEN_SIZE 1
3539 -#define SM_PSEL_OFFSET 8
3540 -#define SM_PSEL_SIZE 16
3542 -/* Bitfields in RTC_VAL */
3543 -#define SM_RTC_VAL_VAL_OFFSET 0
3544 -#define SM_RTC_VAL_VAL_SIZE 31
3546 -/* Bitfields in RTC_TOP */
3547 -#define SM_RTC_TOP_VAL_OFFSET 0
3548 -#define SM_RTC_TOP_VAL_SIZE 32
3550 -/* Bitfields in RTC_IER */
3552 -/* Bitfields in RTC_IDR */
3554 -/* Bitfields in RTC_IMR */
3556 -/* Bitfields in RTC_ISR */
3558 -/* Bitfields in RTC_ICR */
3559 -#define SM_TOPI_OFFSET 0
3560 -#define SM_TOPI_SIZE 1
3562 -/* Bitfields in WDT_CTRL */
3563 -#define SM_KEY_OFFSET 24
3564 -#define SM_KEY_SIZE 8
3566 -/* Bitfields in WDT_CLR */
3568 -/* Bitfields in WDT_EXT */
3570 -/* Bitfields in RC_RCAUSE */
3571 -#define SM_POR_OFFSET 0
3572 -#define SM_POR_SIZE 1
3573 -#define SM_BOD_OFFSET 1
3574 -#define SM_BOD_SIZE 1
3575 -#define SM_EXT_OFFSET 2
3576 -#define SM_EXT_SIZE 1
3577 -#define SM_WDT_OFFSET 3
3578 -#define SM_WDT_SIZE 1
3579 -#define SM_NTAE_OFFSET 4
3580 -#define SM_NTAE_SIZE 1
3581 -#define SM_SERP_OFFSET 5
3582 -#define SM_SERP_SIZE 1
3584 -/* Bitfields in EIM_IER */
3586 -/* Bitfields in EIM_IDR */
3588 -/* Bitfields in EIM_IMR */
3590 -/* Bitfields in EIM_ISR */
3592 -/* Bitfields in EIM_ICR */
3594 -/* Bitfields in EIM_MODE */
3596 -/* Bitfields in EIM_EDGE */
3597 -#define SM_INT0_OFFSET 0
3598 -#define SM_INT0_SIZE 1
3599 -#define SM_INT1_OFFSET 1
3600 -#define SM_INT1_SIZE 1
3601 -#define SM_INT2_OFFSET 2
3602 -#define SM_INT2_SIZE 1
3603 -#define SM_INT3_OFFSET 3
3604 -#define SM_INT3_SIZE 1
3606 -/* Bitfields in EIM_LEVEL */
3608 -/* Bitfields in EIM_TEST */
3609 -#define SM_TESTEN_OFFSET 31
3610 -#define SM_TESTEN_SIZE 1
3612 -/* Bitfields in EIM_NMIC */
3613 -#define SM_EN_OFFSET 0
3614 -#define SM_EN_SIZE 1
3616 -/* Bit manipulation macros */
3617 -#define SM_BIT(name) (1 << SM_##name##_OFFSET)
3618 -#define SM_BF(name,value) (((value) & ((1 << SM_##name##_SIZE) - 1)) << SM_##name##_OFFSET)
3619 -#define SM_BFEXT(name,value) (((value) >> SM_##name##_OFFSET) & ((1 << SM_##name##_SIZE) - 1))
3620 -#define SM_BFINS(name,value,old) (((old) & ~(((1 << SM_##name##_SIZE) - 1) << SM_##name##_OFFSET)) | SM_BF(name,value))
3622 -/* Register access macros */
3623 -#define sm_readl(port,reg) \
3624 - __raw_readl((port)->regs + SM_##reg)
3625 -#define sm_writel(port,reg,value) \
3626 - __raw_writel((value), (port)->regs + SM_##reg)
3628 -#endif /* __ASM_AVR32_SM_H__ */
3629 diff -x .git -Nur linux-2.6.22.1/arch/avr32/Makefile linux-avr32.git/arch/avr32/Makefile
3630 --- linux-2.6.22.1/arch/avr32/Makefile 2007-07-10 20:56:30.000000000 +0200
3631 +++ linux-avr32.git/arch/avr32/Makefile 2007-06-06 11:33:46.000000000 +0200
3633 core-$(CONFIG_LOADER_U_BOOT) += arch/avr32/boot/u-boot/
3634 core-y += arch/avr32/kernel/
3635 core-y += arch/avr32/mm/
3636 +drivers-y += arch/avr32/drivers/
3637 libs-y += arch/avr32/lib/
3639 archincdir-$(CONFIG_PLATFORM_AT32AP) := arch-at32ap
3640 diff -x .git -Nur linux-2.6.22.1/arch/avr32/mm/dma-coherent.c linux-avr32.git/arch/avr32/mm/dma-coherent.c
3641 --- linux-2.6.22.1/arch/avr32/mm/dma-coherent.c 2007-07-10 20:56:30.000000000 +0200
3642 +++ linux-avr32.git/arch/avr32/mm/dma-coherent.c 2007-07-12 13:59:49.000000000 +0200
3644 struct page *page, *free, *end;
3647 + /* Following is a work-around (a.k.a. hack) to prevent pages
3648 + * with __GFP_COMP being passed to split_page() which cannot
3649 + * handle them. The real problem is that this flag probably
3650 + * should be 0 on AVR32 as it is not supported on this
3651 + * platform--see CONFIG_HUGETLB_PAGE. */
3652 + gfp &= ~(__GFP_COMP);
3654 size = PAGE_ALIGN(size);
3655 order = get_order(size);
3657 diff -x .git -Nur linux-2.6.22.1/drivers/char/watchdog/at32ap700x_wdt.c linux-avr32.git/drivers/char/watchdog/at32ap700x_wdt.c
3658 --- linux-2.6.22.1/drivers/char/watchdog/at32ap700x_wdt.c 1970-01-01 01:00:00.000000000 +0100
3659 +++ linux-avr32.git/drivers/char/watchdog/at32ap700x_wdt.c 2007-07-12 13:59:59.000000000 +0200
3662 + * Watchdog driver for Atmel AT32AP700X devices
3664 + * Copyright (C) 2005-2006 Atmel Corporation
3666 + * This program is free software; you can redistribute it and/or modify
3667 + * it under the terms of the GNU General Public License version 2 as
3668 + * published by the Free Software Foundation.
3671 +#include <linux/init.h>
3672 +#include <linux/kernel.h>
3673 +#include <linux/module.h>
3674 +#include <linux/moduleparam.h>
3675 +#include <linux/miscdevice.h>
3676 +#include <linux/fs.h>
3677 +#include <linux/platform_device.h>
3678 +#include <linux/watchdog.h>
3679 +#include <linux/uaccess.h>
3680 +#include <linux/io.h>
3682 +#define TIMEOUT_MIN 1
3683 +#define TIMEOUT_DEFAULT CONFIG_AT32AP700X_WDT_TIMEOUT
3684 +#define TIMEOUT_MAX 2
3686 +/* Watchdog registers and write/read macro */
3687 +#define WDT_CTRL 0x00
3688 +#define WDT_CTRL_EN 0
3689 +#define WDT_CTRL_PSEL 8
3690 +#define WDT_CTRL_KEY 24
3692 +#define WDT_CLR 0x04
3694 +#define WDT_BIT(name) (1 << WDT_##name)
3695 +#define WDT_BF(name,value) ((value) << WDT_##name)
3697 +#define wdt_readl(dev,reg) \
3698 + __raw_readl((dev)->regs + WDT_##reg)
3699 +#define wdt_writel(dev,reg,value) \
3700 + __raw_writel((value), (dev)->regs + WDT_##reg)
3702 +struct wdt_at32ap700x {
3703 + void __iomem *regs;
3706 + struct miscdevice miscdev;
3709 +static struct wdt_at32ap700x *wdt;
3712 + * Disable the watchdog.
3714 +static void inline at32_wdt_stop(void)
3716 + unsigned long psel = wdt_readl(wdt, CTRL) & WDT_BF(CTRL_PSEL, 0x0f);
3717 + wdt_writel(wdt, CTRL, psel | WDT_BF(CTRL_KEY, 0x55));
3718 + wdt_writel(wdt, CTRL, psel | WDT_BF(CTRL_KEY, 0xaa));
3722 + * Enable and reset the watchdog.
3724 +static void inline at32_wdt_start(void)
3726 + /* 0xf is 2^16 divider = 2 sec, 0xe is 2^15 divider = 1 sec */
3727 + unsigned long psel = (wdt->timeout > 1) ? 0xf : 0xe;
3729 + wdt_writel(wdt, CTRL, WDT_BIT(CTRL_EN)
3730 + | WDT_BF(CTRL_PSEL, psel)
3731 + | WDT_BF(CTRL_KEY, 0x55));
3732 + wdt_writel(wdt, CTRL, WDT_BIT(CTRL_EN)
3733 + | WDT_BF(CTRL_PSEL, psel)
3734 + | WDT_BF(CTRL_KEY, 0xaa));
3738 + * Pat the watchdog timer.
3740 +static void inline at32_wdt_pat(void)
3742 + wdt_writel(wdt, CLR, 0x42);
3746 + * Watchdog device is opened, and watchdog starts running.
3748 +static int at32_wdt_open(struct inode *inode, struct file *file)
3750 + if (test_and_set_bit(1, &wdt->users))
3754 + return nonseekable_open(inode, file);
3758 + * Close the watchdog device. If CONFIG_WATCHDOG_NOWAYOUT is _not_ defined then
3759 + * the watchdog is also disabled.
3761 +static int at32_wdt_close(struct inode *inode, struct file *file)
3763 +#ifndef CONFIG_WATCHDOG_NOWAYOUT
3766 + clear_bit(1, &wdt->users);
3771 + * Change the watchdog time interval.
3773 +static int at32_wdt_settimeout(int time)
3776 + * All counting occurs at 1 / SLOW_CLOCK (32 kHz) and max prescaler is
3777 + * 2 ^ 16 allowing up to 2 seconds timeout.
3779 + if ((time < TIMEOUT_MIN) || (time > TIMEOUT_MAX))
3783 + * Set new watchdog time. It will be used when at32_wdt_start() is
3786 + wdt->timeout = time;
3790 +static struct watchdog_info at32_wdt_info = {
3791 + .identity = "at32ap700x watchdog",
3792 + .options = WDIOF_SETTIMEOUT | WDIOF_KEEPALIVEPING,
3796 + * Handle commands from user-space.
3798 +static int at32_wdt_ioctl(struct inode *inode, struct file *file,
3799 + unsigned int cmd, unsigned long arg)
3801 + int ret = -ENOTTY;
3803 + void __user *argp = (void __user *)arg;
3804 + int __user *p = argp;
3807 + case WDIOC_KEEPALIVE:
3811 + case WDIOC_GETSUPPORT:
3812 + ret = copy_to_user(argp, &at32_wdt_info,
3813 + sizeof(at32_wdt_info)) ? -EFAULT : 0;
3815 + case WDIOC_SETTIMEOUT:
3816 + ret = get_user(time, p);
3819 + ret = at32_wdt_settimeout(time);
3822 + /* Enable new time value */
3824 + /* fall through */
3825 + case WDIOC_GETTIMEOUT:
3826 + ret = put_user(wdt->timeout, p);
3828 + case WDIOC_GETSTATUS: /* fall through */
3829 + case WDIOC_GETBOOTSTATUS:
3830 + ret = put_user(0, p);
3832 + case WDIOC_SETOPTIONS:
3833 + ret = get_user(time, p);
3836 + if (time & WDIOS_DISABLECARD)
3838 + if (time & WDIOS_ENABLECARD)
3847 +static ssize_t at32_wdt_write(struct file *file, const char *data, size_t len,
3854 +static const struct file_operations at32_wdt_fops = {
3855 + .owner = THIS_MODULE,
3856 + .llseek = no_llseek,
3857 + .ioctl = at32_wdt_ioctl,
3858 + .open = at32_wdt_open,
3859 + .release = at32_wdt_close,
3860 + .write = at32_wdt_write,
3863 +static int __init at32_wdt_probe(struct platform_device *pdev)
3865 + struct resource *regs;
3869 + dev_dbg(&pdev->dev, "only 1 wdt instance supported.\n");
3873 + regs = platform_get_resource(pdev, IORESOURCE_MEM, 0);
3875 + dev_dbg(&pdev->dev, "missing mmio resource\n");
3879 + wdt = kzalloc(sizeof(struct wdt_at32ap700x), GFP_KERNEL);
3881 + dev_dbg(&pdev->dev, "no memory for wdt structure\n");
3885 + wdt->regs = ioremap(regs->start, regs->end - regs->start + 1);
3888 + dev_dbg(&pdev->dev, "could not map I/O memory\n");
3892 + wdt->miscdev.minor = WATCHDOG_MINOR;
3893 + wdt->miscdev.name = "watchdog";
3894 + wdt->miscdev.fops = &at32_wdt_fops;
3896 + if (at32_wdt_settimeout(TIMEOUT_DEFAULT)) {
3897 + at32_wdt_settimeout(TIMEOUT_MAX);
3898 + dev_dbg(&pdev->dev,
3899 + "default timeout invalid, set to %d sec.\n",
3903 + ret = misc_register(&wdt->miscdev);
3905 + dev_dbg(&pdev->dev, "failed to register wdt miscdev\n");
3909 + platform_set_drvdata(pdev, wdt);
3910 + wdt->miscdev.parent = &pdev->dev;
3911 + dev_info(&pdev->dev, "AT32AP700X WDT at 0x%p\n", wdt->regs);
3916 + iounmap(wdt->regs);
3923 +static int __exit at32_wdt_remove(struct platform_device *pdev)
3925 + if (wdt && platform_get_drvdata(pdev) == wdt) {
3926 + misc_deregister(&wdt->miscdev);
3927 + iounmap(wdt->regs);
3930 + platform_set_drvdata(pdev, NULL);
3936 +static void at32_wdt_shutdown(struct platform_device *pdev)
3942 +static int at32_wdt_suspend(struct platform_device *pdev, pm_message_t message)
3948 +static int at32_wdt_resume(struct platform_device *pdev)
3955 +#define at32_wdt_suspend NULL
3956 +#define at32_wdt_resume NULL
3959 +static struct platform_driver at32_wdt_driver = {
3960 + .remove = __exit_p(at32_wdt_remove),
3961 + .suspend = at32_wdt_suspend,
3962 + .resume = at32_wdt_resume,
3964 + .name = "at32_wdt",
3965 + .owner = THIS_MODULE,
3967 + .shutdown = at32_wdt_shutdown,
3970 +static int __init at32_wdt_init(void)
3972 + return platform_driver_probe(&at32_wdt_driver, at32_wdt_probe);
3974 +module_init(at32_wdt_init);
3976 +static void __exit at32_wdt_exit(void)
3978 + platform_driver_unregister(&at32_wdt_driver);
3980 +module_exit(at32_wdt_exit);
3982 +MODULE_AUTHOR("Hans-Christian Egtvedt <hcegtvedt@atmel.com>");
3983 +MODULE_DESCRIPTION("Watchdog driver for Atmel AT32AP700X");
3984 +MODULE_LICENSE("GPL");
3985 +MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR);
3986 diff -x .git -Nur linux-2.6.22.1/drivers/char/watchdog/Kconfig linux-avr32.git/drivers/char/watchdog/Kconfig
3987 --- linux-2.6.22.1/drivers/char/watchdog/Kconfig 2007-07-10 20:56:30.000000000 +0200
3988 +++ linux-avr32.git/drivers/char/watchdog/Kconfig 2007-07-12 13:59:59.000000000 +0200
3989 @@ -187,6 +187,26 @@
3991 Say N if you are unsure.
3993 +# AVR32 Architecture
3995 +config AT32AP700X_WDT
3996 + tristate "AT32AP700x watchdog"
3997 + depends on WATCHDOG && CPU_AT32AP7000
3999 + Watchdog timer embedded into AT32AP700x devices. This will reboot
4000 + your system when the timeout is reached.
4002 +config AT32AP700X_WDT_TIMEOUT
4003 + int "Timeout value for AT32AP700x watchdog"
4004 + depends on AT32AP700X_WDT
4008 + Sets the timeout value for the watchdog in AT32AP700x devices.
4009 + Limited by hardware to be 1 or 2 seconds.
4011 + Set to 2 seconds by default.
4013 # X86 (i386 + ia64 + x86_64) Architecture
4016 diff -x .git -Nur linux-2.6.22.1/drivers/char/watchdog/Makefile linux-avr32.git/drivers/char/watchdog/Makefile
4017 --- linux-2.6.22.1/drivers/char/watchdog/Makefile 2007-07-10 20:56:30.000000000 +0200
4018 +++ linux-avr32.git/drivers/char/watchdog/Makefile 2007-07-12 13:59:59.000000000 +0200
4020 obj-$(CONFIG_EP93XX_WATCHDOG) += ep93xx_wdt.o
4021 obj-$(CONFIG_PNX4008_WATCHDOG) += pnx4008_wdt.o
4023 +# AVR32 Architecture
4024 +obj-$(CONFIG_AT32AP700X_WDT) += at32ap700x_wdt.o
4026 # X86 (i386 + ia64 + x86_64) Architecture
4027 obj-$(CONFIG_ACQUIRE_WDT) += acquirewdt.o
4028 obj-$(CONFIG_ADVANTECH_WDT) += advantechwdt.o
4029 diff -x .git -Nur linux-2.6.22.1/drivers/i2c/busses/atmeltwi.h linux-avr32.git/drivers/i2c/busses/atmeltwi.h
4030 --- linux-2.6.22.1/drivers/i2c/busses/atmeltwi.h 1970-01-01 01:00:00.000000000 +0100
4031 +++ linux-avr32.git/drivers/i2c/busses/atmeltwi.h 2007-06-06 11:33:51.000000000 +0200
4034 + * Register definitions for the Atmel Two-Wire Interface
4037 +#ifndef __ASM_AVR32_TWI_H__
4038 +#define __ASM_AVR32_TWI_H__
4040 +/* TWI register offsets */
4041 +#define TWI_CR 0x0000
4042 +#define TWI_MMR 0x0004
4043 +#define TWI_SMR 0x0008
4044 +#define TWI_IADR 0x000c
4045 +#define TWI_CWGR 0x0010
4046 +#define TWI_SR 0x0020
4047 +#define TWI_IER 0x0024
4048 +#define TWI_IDR 0x0028
4049 +#define TWI_IMR 0x002c
4050 +#define TWI_RHR 0x0030
4051 +#define TWI_THR 0x0034
4053 +/* Bitfields in CR */
4054 +#define TWI_START_OFFSET 0
4055 +#define TWI_START_SIZE 1
4056 +#define TWI_STOP_OFFSET 1
4057 +#define TWI_STOP_SIZE 1
4058 +#define TWI_MSEN_OFFSET 2
4059 +#define TWI_MSEN_SIZE 1
4060 +#define TWI_MSDIS_OFFSET 3
4061 +#define TWI_MSDIS_SIZE 1
4062 +#define TWI_SVEN_OFFSET 4
4063 +#define TWI_SVEN_SIZE 1
4064 +#define TWI_SVDIS_OFFSET 5
4065 +#define TWI_SVDIS_SIZE 1
4066 +#define TWI_SWRST_OFFSET 7
4067 +#define TWI_SWRST_SIZE 1
4069 +/* Bitfields in MMR */
4070 +#define TWI_IADRSZ_OFFSET 8
4071 +#define TWI_IADRSZ_SIZE 2
4072 +#define TWI_MREAD_OFFSET 12
4073 +#define TWI_MREAD_SIZE 1
4074 +#define TWI_DADR_OFFSET 16
4075 +#define TWI_DADR_SIZE 7
4077 +/* Bitfields in SMR */
4078 +#define TWI_SADR_OFFSET 16
4079 +#define TWI_SADR_SIZE 7
4081 +/* Bitfields in IADR */
4082 +#define TWI_IADR_OFFSET 0
4083 +#define TWI_IADR_SIZE 24
4085 +/* Bitfields in CWGR */
4086 +#define TWI_CLDIV_OFFSET 0
4087 +#define TWI_CLDIV_SIZE 8
4088 +#define TWI_CHDIV_OFFSET 8
4089 +#define TWI_CHDIV_SIZE 8
4090 +#define TWI_CKDIV_OFFSET 16
4091 +#define TWI_CKDIV_SIZE 3
4093 +/* Bitfields in SR */
4094 +#define TWI_TXCOMP_OFFSET 0
4095 +#define TWI_TXCOMP_SIZE 1
4096 +#define TWI_RXRDY_OFFSET 1
4097 +#define TWI_RXRDY_SIZE 1
4098 +#define TWI_TXRDY_OFFSET 2
4099 +#define TWI_TXRDY_SIZE 1
4100 +#define TWI_SVDIR_OFFSET 3
4101 +#define TWI_SVDIR_SIZE 1
4102 +#define TWI_SVACC_OFFSET 4
4103 +#define TWI_SVACC_SIZE 1
4104 +#define TWI_GCACC_OFFSET 5
4105 +#define TWI_GCACC_SIZE 1
4106 +#define TWI_OVRE_OFFSET 6
4107 +#define TWI_OVRE_SIZE 1
4108 +#define TWI_UNRE_OFFSET 7
4109 +#define TWI_UNRE_SIZE 1
4110 +#define TWI_NACK_OFFSET 8
4111 +#define TWI_NACK_SIZE 1
4112 +#define TWI_ARBLST_OFFSET 9
4113 +#define TWI_ARBLST_SIZE 1
4115 +/* Bitfields in RHR */
4116 +#define TWI_RXDATA_OFFSET 0
4117 +#define TWI_RXDATA_SIZE 8
4119 +/* Bitfields in THR */
4120 +#define TWI_TXDATA_OFFSET 0
4121 +#define TWI_TXDATA_SIZE 8
4123 +/* Constants for IADRSZ */
4124 +#define TWI_IADRSZ_NO_ADDR 0
4125 +#define TWI_IADRSZ_ONE_BYTE 1
4126 +#define TWI_IADRSZ_TWO_BYTES 2
4127 +#define TWI_IADRSZ_THREE_BYTES 3
4129 +/* Bit manipulation macros */
4130 +#define TWI_BIT(name) \
4131 + (1 << TWI_##name##_OFFSET)
4132 +#define TWI_BF(name,value) \
4133 + (((value) & ((1 << TWI_##name##_SIZE) - 1)) \
4134 + << TWI_##name##_OFFSET)
4135 +#define TWI_BFEXT(name,value) \
4136 + (((value) >> TWI_##name##_OFFSET) \
4137 + & ((1 << TWI_##name##_SIZE) - 1))
4138 +#define TWI_BFINS(name,value,old) \
4139 + (((old) & ~(((1 << TWI_##name##_SIZE) - 1) \
4140 + << TWI_##name##_OFFSET)) \
4141 + | TWI_BF(name,value))
4143 +/* Register access macros */
4144 +#define twi_readl(port,reg) \
4145 + __raw_readl((port)->regs + TWI_##reg)
4146 +#define twi_writel(port,reg,value) \
4147 + __raw_writel((value), (port)->regs + TWI_##reg)
4149 +#endif /* __ASM_AVR32_TWI_H__ */
4150 diff -x .git -Nur linux-2.6.22.1/drivers/i2c/busses/i2c-atmeltwi.c linux-avr32.git/drivers/i2c/busses/i2c-atmeltwi.c
4151 --- linux-2.6.22.1/drivers/i2c/busses/i2c-atmeltwi.c 1970-01-01 01:00:00.000000000 +0100
4152 +++ linux-avr32.git/drivers/i2c/busses/i2c-atmeltwi.c 2007-07-12 13:59:59.000000000 +0200
4155 + * i2c Support for Atmel's Two-Wire Interface (TWI)
4157 + * Based on the work of Copyright (C) 2004 Rick Bronson
4158 + * Converted to 2.6 by Andrew Victor <andrew at sanpeople.com>
4159 + * Ported to AVR32 and heavily modified by Espen Krangnes <ekrangnes at atmel.com>
4161 + * Copyright (C) 2006 Atmel Corporation
4163 + * Borrowed heavily from the original work by:
4164 + * Copyright (C) 2000 Philip Edelbrock <phil at stimpy.netroedge.com>
4166 + * This program is free software; you can redistribute it and/or modify
4167 + * it under the terms of the GNU General Public License as published by
4168 + * the Free Software Foundation; either version 2 of the License, or
4169 + * (at your option) any later version.
4173 +#include <linux/err.h>
4174 +#include <linux/module.h>
4175 +#include <linux/kernel.h>
4176 +#include <linux/slab.h>
4177 +#include <linux/types.h>
4178 +#include <linux/delay.h>
4179 +#include <linux/i2c.h>
4180 +#include <linux/init.h>
4181 +#include <linux/clk.h>
4182 +#include <linux/interrupt.h>
4183 +#include <linux/irq.h>
4184 +#include <linux/platform_device.h>
4185 +#include <linux/completion.h>
4186 +#include <asm/io.h>
4187 +#include <linux/time.h>
4188 +#include "atmeltwi.h"
4190 +static unsigned int baudrate = CONFIG_I2C_ATMELTWI_BAUDRATE;
4191 +module_param(baudrate, uint, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP);
4192 +MODULE_PARM_DESC(baudrate, "The TWI baudrate");
4196 + void __iomem *regs;
4197 + struct i2c_adapter adapter;
4200 + struct completion comp;
4208 +#define to_atmel_twi(adap) container_of(adap, struct atmel_twi, adapter)
4211 + * Initialize the TWI hardware registers.
4213 +static int __devinit twi_hwinit(struct atmel_twi *twi)
4215 + unsigned long cdiv, ckdiv=0;
4217 + twi_writel(twi, IDR, ~0UL);
4218 + twi_writel(twi, CR, TWI_BIT(SWRST)); /*Reset peripheral*/
4219 + twi_readl(twi, SR);
4221 + cdiv = (clk_get_rate(twi->pclk) / (2 * baudrate)) - 4;
4223 + while (cdiv > 255) {
4231 + twi_writel(twi, CWGR, (TWI_BF(CKDIV, ckdiv)
4232 + | TWI_BF(CHDIV, cdiv)
4233 + | TWI_BF(CLDIV, cdiv)));
4238 + * Waits for the i2c status register to set the specified bitmask
4239 + * Returns 0 if timed out (~100ms).
4241 +static short twi_wait_for_completion(struct atmel_twi *twi,
4244 + int timeout = msecs_to_jiffies(100);
4246 + twi->intmask = mask;
4247 + init_completion(&twi->comp);
4249 + twi_writel(twi, IER, mask);
4251 + if(!wait_for_completion_timeout(&twi->comp, timeout))
4252 + return -ETIMEDOUT;
4258 + * Generic i2c master transfer entrypoint.
4260 +static int twi_xfer(struct i2c_adapter *adap, struct i2c_msg msgs[], int num)
4262 + struct atmel_twi *twi = to_atmel_twi(adap);
4263 + struct i2c_msg *pmsg;
4266 + /* get first message */
4269 + dev_dbg(&adap->dev, "twi_xfer: processing %d messages:\n", num);
4271 + for (i = 0; i < num; i++, pmsg++) {
4273 + twi->len = pmsg->len;
4274 + twi->buf = pmsg->buf;
4275 + twi->acks_left = pmsg->len;
4276 + twi_writel(twi, MMR, TWI_BF(DADR, pmsg->addr) |
4277 + (pmsg->flags & I2C_M_RD ? TWI_BIT(MREAD) : 0));
4278 + twi_writel(twi, IADR, TWI_BF(IADR, pmsg->addr));
4280 + dev_dbg(&adap->dev,"#%d: internal addr %d %s byte%s %s 0x%02x\n",
4281 + i,pmsg->len, pmsg->flags & I2C_M_RD ? "reading" : "writing",
4282 + pmsg->len > 1 ? "s" : "",
4283 + pmsg->flags & I2C_M_RD ? "from" : "to", pmsg->addr);
4286 + twi_writel(twi, CR, TWI_BIT(MSEN));
4288 + if (pmsg->flags & I2C_M_RD) {
4289 + twi_writel(twi, CR, TWI_BIT(START));
4290 + if ( twi_wait_for_completion(twi,TWI_BIT(RXRDY))==-ETIMEDOUT ) {
4291 + dev_dbg(&adap->dev, "RXRDY timeout. Stopped with %d bytes left\n",
4293 + return -ETIMEDOUT;
4296 + /* Send Stop, and Wait until transfer is finished */
4297 + if ( twi_wait_for_completion(twi,TWI_BIT(TXCOMP))==-ETIMEDOUT ) {
4298 + dev_dbg(&adap->dev, "TXCOMP timeout\n");
4299 + return -ETIMEDOUT;
4303 + twi_writel(twi, THR, twi->buf[0]);
4304 + if ( twi_wait_for_completion(twi,TWI_BIT(TXRDY))==-ETIMEDOUT ) {
4305 + dev_dbg(&adap->dev, "TXRDY timeout. Stopped with %d bytes left\n",
4307 + return -ETIMEDOUT;
4311 + /* Disable TWI interface */
4312 + twi_writel(twi, CR, TWI_BIT(MSDIS));
4314 + } /* end cur msg */
4320 +static irqreturn_t twi_interrupt(int irq, void *dev_id)
4322 + struct atmel_twi *twi = dev_id;
4323 + int status = twi_readl(twi, SR);
4325 + if (twi->intmask & status){
4326 + if (twi->intmask & TWI_BIT(NACK)) {
4328 + } else if (twi->intmask & TWI_BIT(RXRDY)){
4329 + twi->buf[twi->len - twi->acks_left] = twi_readl(twi,RHR);
4330 + if(--twi->acks_left==1)
4331 + twi_writel(twi, CR, TWI_BIT(STOP));
4332 + if (twi->acks_left==0)
4334 + } else if (twi->intmask & TWI_BIT(TXRDY)) {
4336 + if (twi->acks_left==0) {
4337 + twi->intmask = TWI_BIT(TXCOMP);
4338 + twi_writel(twi, IER, TWI_BIT(TXCOMP));
4340 + twi_writel(twi, THR, twi->buf[twi->len - twi->acks_left]);
4341 + } else if (twi->intmask & TWI_BIT(TXCOMP)) {
4346 + return IRQ_HANDLED;
4349 + printk(KERN_INFO "NACK received!\n");
4352 + twi_writel(twi, IDR, ~0UL);
4353 + complete(&twi->comp);
4355 + return IRQ_HANDLED;
4361 + * Return list of supported functionality.
4363 +static u32 twi_func(struct i2c_adapter *adapter)
4365 + return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL;
4368 +/* For now, we only handle combined mode (smbus) */
4369 +static struct i2c_algorithm twi_algorithm = {
4370 + .master_xfer = twi_xfer,
4371 + .functionality = twi_func,
4375 + * Main initialization routine.
4377 +static int __devinit twi_probe(struct platform_device *pdev)
4379 + struct atmel_twi *twi;
4380 + struct resource *regs;
4382 + struct i2c_adapter *adapter;
4385 + regs = platform_get_resource(pdev, IORESOURCE_MEM, 0);
4389 + pclk = clk_get(&pdev->dev, "pclk");
4391 + return PTR_ERR(pclk);
4395 + twi = kzalloc(sizeof(struct atmel_twi), GFP_KERNEL);
4397 + dev_err(&pdev->dev, "can't allocate interface!\n");
4398 + goto err_alloc_twi;
4402 + twi->regs = ioremap(regs->start, regs->end - regs->start + 1);
4406 + irq = platform_get_irq(pdev,0);
4407 + rc = request_irq(irq, twi_interrupt, 0, "twi", twi);
4409 + dev_err(&pdev->dev, "can't bind irq!\n");
4414 + rc = twi_hwinit(twi);
4416 + dev_err(&pdev->dev, "Unable to set baudrate\n");
4420 + adapter = &twi->adapter;
4421 + sprintf(adapter->name, "TWI");
4422 + adapter->algo = &twi_algorithm;
4423 + adapter->class = I2C_CLASS_HWMON;
4424 + adapter->dev.parent = &pdev->dev;
4426 + platform_set_drvdata(pdev, twi);
4428 + rc = i2c_add_adapter(adapter);
4430 + dev_err(&pdev->dev, "Adapter %s registration failed\n",
4432 + goto err_register;
4435 + dev_info(&pdev->dev, "Atmel TWI i2c bus device (baudrate %dk) at 0x%08lx.\n",
4436 + baudrate/1000, (unsigned long)regs->start);
4442 + platform_set_drvdata(pdev, NULL);
4445 + free_irq(irq, twi);
4448 + iounmap(twi->regs);
4454 + clk_disable(pclk);
4460 +static int __devexit twi_remove(struct platform_device *pdev)
4462 + struct atmel_twi *twi = platform_get_drvdata(pdev);
4465 + platform_set_drvdata(pdev, NULL);
4466 + res = i2c_del_adapter(&twi->adapter);
4467 + twi_writel(twi, CR, TWI_BIT(MSDIS));
4468 + iounmap(twi->regs);
4469 + clk_disable(twi->pclk);
4470 + clk_put(twi->pclk);
4471 + free_irq(twi->irq, twi);
4477 +static struct platform_driver twi_driver = {
4478 + .probe = twi_probe,
4479 + .remove = __devexit_p(twi_remove),
4481 + .name = "atmel_twi",
4482 + .owner = THIS_MODULE,
4486 +static int __init atmel_twi_init(void)
4488 + return platform_driver_register(&twi_driver);
4491 +static void __exit atmel_twi_exit(void)
4493 + platform_driver_unregister(&twi_driver);
4496 +module_init(atmel_twi_init);
4497 +module_exit(atmel_twi_exit);
4499 +MODULE_AUTHOR("Espen Krangnes");
4500 +MODULE_DESCRIPTION("I2C driver for Atmel TWI");
4501 +MODULE_LICENSE("GPL");
4502 diff -x .git -Nur linux-2.6.22.1/drivers/i2c/busses/Kconfig linux-avr32.git/drivers/i2c/busses/Kconfig
4503 --- linux-2.6.22.1/drivers/i2c/busses/Kconfig 2007-07-10 20:56:30.000000000 +0200
4504 +++ linux-avr32.git/drivers/i2c/busses/Kconfig 2007-07-12 13:59:59.000000000 +0200
4507 menu "I2C Hardware Bus support"
4509 +config I2C_ATMELTWI
4510 + tristate "Atmel TWI/I2C"
4513 + Atmel on-chip TWI controller. Say Y if you have an AT32 or
4514 + AT91-based device and want to use its built-in TWI
4515 + functionality. Atmel's TWI is compatible with Philips' I2C
4516 + protocol. If in doubt, say NO
4518 +config I2C_ATMELTWI_BAUDRATE
4519 + prompt "Atmel TWI baudrate"
4520 + depends on I2C_ATMELTWI
4524 + Set the TWI/I2C baudrate. This will alter the default value. A
4525 + different baudrate can be set by using a module parameter as well. If
4526 + no parameter is provided when loading, this is the value that will be
4532 diff -x .git -Nur linux-2.6.22.1/drivers/i2c/busses/Makefile linux-avr32.git/drivers/i2c/busses/Makefile
4533 --- linux-2.6.22.1/drivers/i2c/busses/Makefile 2007-07-10 20:56:30.000000000 +0200
4534 +++ linux-avr32.git/drivers/i2c/busses/Makefile 2007-07-12 13:59:59.000000000 +0200
4536 obj-$(CONFIG_I2C_VOODOO3) += i2c-voodoo3.o
4537 obj-$(CONFIG_SCx200_ACB) += scx200_acb.o
4538 obj-$(CONFIG_SCx200_I2C) += scx200_i2c.o
4539 +obj-$(CONFIG_I2C_ATMELTWI) += i2c-atmeltwi.o
4541 ifeq ($(CONFIG_I2C_DEBUG_BUS),y)
4542 EXTRA_CFLAGS += -DDEBUG
4543 diff -x .git -Nur linux-2.6.22.1/drivers/leds/Kconfig linux-avr32.git/drivers/leds/Kconfig
4544 --- linux-2.6.22.1/drivers/leds/Kconfig 2007-07-10 20:56:30.000000000 +0200
4545 +++ linux-avr32.git/drivers/leds/Kconfig 2007-07-12 14:00:02.000000000 +0200
4548 This option enables support for the front LED on Cobalt Server
4551 + tristate "LED Support for GPIO connected LEDs"
4552 + depends on LEDS_CLASS && GENERIC_GPIO
4554 + This option enables support for the LEDs connected to GPIO
4555 + outputs. To be useful the particular board must have LEDs
4556 + and they must be connected to the GPIO lines.
4558 comment "LED Triggers"
4560 config LEDS_TRIGGERS
4561 diff -x .git -Nur linux-2.6.22.1/drivers/leds/leds-gpio.c linux-avr32.git/drivers/leds/leds-gpio.c
4562 --- linux-2.6.22.1/drivers/leds/leds-gpio.c 1970-01-01 01:00:00.000000000 +0100
4563 +++ linux-avr32.git/drivers/leds/leds-gpio.c 2007-07-12 14:00:02.000000000 +0200
4566 + * LEDs driver for GPIOs
4568 + * Copyright (C) 2007 8D Technologies inc.
4569 + * Raphael Assenat <raph@8d.com>
4571 + * This program is free software; you can redistribute it and/or modify
4572 + * it under the terms of the GNU General Public License version 2 as
4573 + * published by the Free Software Foundation.
4576 +#include <linux/kernel.h>
4577 +#include <linux/init.h>
4578 +#include <linux/platform_device.h>
4579 +#include <linux/leds.h>
4580 +#include <linux/workqueue.h>
4582 +#include <asm/gpio.h>
4584 +struct gpio_led_data {
4585 + struct led_classdev cdev;
4587 + struct work_struct work;
4593 +static void gpio_led_work(struct work_struct *work)
4595 + struct gpio_led_data *led_dat =
4596 + container_of(work, struct gpio_led_data, work);
4598 + gpio_set_value_cansleep(led_dat->gpio, led_dat->new_level);
4601 +static void gpio_led_set(struct led_classdev *led_cdev,
4602 + enum led_brightness value)
4604 + struct gpio_led_data *led_dat =
4605 + container_of(led_cdev, struct gpio_led_data, cdev);
4608 + if (value == LED_OFF)
4613 + if (led_dat->active_low)
4616 + /* setting GPIOs with I2C/etc requires a preemptible task context */
4617 + if (led_dat->can_sleep) {
4618 + if (preempt_count()) {
4619 + led_dat->new_level = level;
4620 + schedule_work(&led_dat->work);
4622 + gpio_set_value_cansleep(led_dat->gpio, level);
4624 + gpio_set_value(led_dat->gpio, level);
4627 +static int __init gpio_led_probe(struct platform_device *pdev)
4629 + struct gpio_led_platform_data *pdata = pdev->dev.platform_data;
4630 + struct gpio_led *cur_led;
4631 + struct gpio_led_data *leds_data, *led_dat;
4637 + leds_data = kzalloc(sizeof(struct gpio_led_data) * pdata->num_leds,
4642 + for (i = 0; i < pdata->num_leds; i++) {
4643 + cur_led = &pdata->leds[i];
4644 + led_dat = &leds_data[i];
4646 + led_dat->cdev.name = cur_led->name;
4647 + led_dat->cdev.default_trigger = cur_led->default_trigger;
4648 + led_dat->gpio = cur_led->gpio;
4649 + led_dat->can_sleep = gpio_cansleep(cur_led->gpio);
4650 + led_dat->active_low = cur_led->active_low;
4651 + led_dat->cdev.brightness_set = gpio_led_set;
4652 + led_dat->cdev.brightness = cur_led->active_low ? LED_FULL : LED_OFF;
4654 + ret = gpio_request(led_dat->gpio, led_dat->cdev.name);
4658 + gpio_direction_output(led_dat->gpio, led_dat->active_low);
4660 + ret = led_classdev_register(&pdev->dev, &led_dat->cdev);
4662 + gpio_free(led_dat->gpio);
4666 + INIT_WORK(&led_dat->work, gpio_led_work);
4669 + platform_set_drvdata(pdev, leds_data);
4675 + for (i = i - 1; i >= 0; i--) {
4676 + led_classdev_unregister(&leds_data[i].cdev);
4677 + gpio_free(leds_data[i].gpio);
4681 + flush_scheduled_work();
4687 +static int __exit gpio_led_remove(struct platform_device *pdev)
4690 + struct gpio_led_platform_data *pdata = pdev->dev.platform_data;
4691 + struct gpio_led_data *leds_data;
4693 + leds_data = platform_get_drvdata(pdev);
4695 + for (i = 0; i < pdata->num_leds; i++) {
4696 + led_classdev_unregister(&leds_data[i].cdev);
4697 + gpio_free(leds_data[i].gpio);
4706 +static int gpio_led_suspend(struct platform_device *pdev, pm_message_t state)
4708 + struct gpio_led_platform_data *pdata = pdev->dev.platform_data;
4709 + struct gpio_led_data *leds_data;
4712 + leds_data = platform_get_drvdata(pdev);
4714 + for (i = 0; i < pdata->num_leds; i++)
4715 + led_classdev_suspend(&leds_data[i].cdev);
4720 +static int gpio_led_resume(struct platform_device *pdev)
4722 + struct gpio_led_platform_data *pdata = pdev->dev.platform_data;
4723 + struct gpio_led_data *leds_data;
4726 + leds_data = platform_get_drvdata(pdev);
4728 + for (i = 0; i < pdata->num_leds; i++)
4729 + led_classdev_resume(&leds_data[i].cdev);
4734 +#define gpio_led_suspend NULL
4735 +#define gpio_led_resume NULL
4738 +static struct platform_driver gpio_led_driver = {
4739 + .remove = __exit_p(gpio_led_remove),
4740 + .suspend = gpio_led_suspend,
4741 + .resume = gpio_led_resume,
4743 + .name = "leds-gpio",
4744 + .owner = THIS_MODULE,
4748 +static int __init gpio_led_init(void)
4750 + return platform_driver_probe(&gpio_led_driver, gpio_led_probe);
4753 +static void __exit gpio_led_exit(void)
4755 + platform_driver_unregister(&gpio_led_driver);
4758 +module_init(gpio_led_init);
4759 +module_exit(gpio_led_exit);
4761 +MODULE_AUTHOR("Raphael Assenat <raph@8d.com>");
4762 +MODULE_DESCRIPTION("GPIO LED driver");
4763 +MODULE_LICENSE("GPL");
4764 diff -x .git -Nur linux-2.6.22.1/drivers/leds/Makefile linux-avr32.git/drivers/leds/Makefile
4765 --- linux-2.6.22.1/drivers/leds/Makefile 2007-07-10 20:56:30.000000000 +0200
4766 +++ linux-avr32.git/drivers/leds/Makefile 2007-07-12 14:00:02.000000000 +0200
4768 obj-$(CONFIG_LEDS_WRAP) += leds-wrap.o
4769 obj-$(CONFIG_LEDS_H1940) += leds-h1940.o
4770 obj-$(CONFIG_LEDS_COBALT) += leds-cobalt.o
4771 +obj-$(CONFIG_LEDS_GPIO) += leds-gpio.o
4774 obj-$(CONFIG_LEDS_TRIGGER_TIMER) += ledtrig-timer.o
4775 diff -x .git -Nur linux-2.6.22.1/drivers/mmc/host/atmel-mci.c linux-avr32.git/drivers/mmc/host/atmel-mci.c
4776 --- linux-2.6.22.1/drivers/mmc/host/atmel-mci.c 1970-01-01 01:00:00.000000000 +0100
4777 +++ linux-avr32.git/drivers/mmc/host/atmel-mci.c 2007-07-12 14:00:03.000000000 +0200
4780 + * Atmel MultiMedia Card Interface driver
4782 + * Copyright (C) 2004-2006 Atmel Corporation
4784 + * This program is free software; you can redistribute it and/or modify
4785 + * it under the terms of the GNU General Public License version 2 as
4786 + * published by the Free Software Foundation.
4788 +#include <linux/blkdev.h>
4789 +#include <linux/clk.h>
4790 +#include <linux/device.h>
4791 +#include <linux/dma-mapping.h>
4792 +#include <linux/init.h>
4793 +#include <linux/interrupt.h>
4794 +#include <linux/ioport.h>
4795 +#include <linux/module.h>
4796 +#include <linux/platform_device.h>
4798 +#include <linux/mmc/host.h>
4800 +#include <asm/dma-controller.h>
4801 +#include <asm/io.h>
4802 +#include <asm/arch/board.h>
4803 +#include <asm/arch/gpio.h>
4805 +#include "atmel-mci.h"
4807 +#define DRIVER_NAME "atmel_mci"
4809 +#define MCI_CMD_ERROR_FLAGS (MCI_BIT(RINDE) | MCI_BIT(RDIRE) | \
4810 + MCI_BIT(RCRCE) | MCI_BIT(RENDE) | \
4812 +#define MCI_DATA_ERROR_FLAGS (MCI_BIT(DCRCE) | MCI_BIT(DTOE) | \
4813 + MCI_BIT(OVRE) | MCI_BIT(UNRE))
4816 + EVENT_CMD_COMPLETE = 0,
4818 + EVENT_DATA_COMPLETE,
4821 + EVENT_STOP_COMPLETE,
4824 + EVENT_CARD_DETECT,
4827 +struct atmel_mci_dma {
4828 + struct dma_request_sg req;
4829 + unsigned short rx_periph_id;
4830 + unsigned short tx_periph_id;
4834 + struct mmc_host *mmc;
4835 + void __iomem *regs;
4836 + struct atmel_mci_dma dma;
4838 + struct mmc_request *mrq;
4839 + struct mmc_command *cmd;
4840 + struct mmc_data *data;
4845 + struct tasklet_struct tasklet;
4846 + unsigned long pending_events;
4847 + unsigned long completed_events;
4854 + unsigned long bus_hz;
4855 + unsigned long mapbase;
4857 + struct platform_device *pdev;
4859 +#ifdef CONFIG_DEBUG_FS
4860 + struct dentry *debugfs_root;
4861 + struct dentry *debugfs_regs;
4862 + struct dentry *debugfs_req;
4863 + struct dentry *debugfs_pending_events;
4864 + struct dentry *debugfs_completed_events;
4868 +/* Those printks take an awful lot of time... */
4870 +static unsigned int fmax = 15000000U;
4872 +static unsigned int fmax = 1000000U;
4874 +module_param(fmax, uint, 0444);
4875 +MODULE_PARM_DESC(fmax, "Max frequency in Hz of the MMC bus clock");
4877 +/* Test bit macros for completed events */
4878 +#define mci_cmd_is_complete(host) \
4879 + test_bit(EVENT_CMD_COMPLETE, &host->completed_events)
4880 +#define mci_cmd_error_is_complete(host) \
4881 + test_bit(EVENT_CMD_ERROR, &host->completed_events)
4882 +#define mci_data_is_complete(host) \
4883 + test_bit(EVENT_DATA_COMPLETE, &host->completed_events)
4884 +#define mci_data_error_is_complete(host) \
4885 + test_bit(EVENT_DATA_ERROR, &host->completed_events)
4886 +#define mci_stop_sent_is_complete(host) \
4887 + test_bit(EVENT_STOP_SENT, &host->completed_events)
4888 +#define mci_stop_is_complete(host) \
4889 + test_bit(EVENT_STOP_COMPLETE, &host->completed_events)
4890 +#define mci_stop_error_is_complete(host) \
4891 + test_bit(EVENT_STOP_ERROR, &host->completed_events)
4892 +#define mci_dma_error_is_complete(host) \
4893 + test_bit(EVENT_DMA_ERROR, &host->completed_events)
4894 +#define mci_card_detect_is_complete(host) \
4895 + test_bit(EVENT_CARD_DETECT, &host->completed_events)
4897 +/* Test and clear bit macros for pending events */
4898 +#define mci_clear_cmd_is_pending(host) \
4899 + test_and_clear_bit(EVENT_CMD_COMPLETE, &host->pending_events)
4900 +#define mci_clear_cmd_error_is_pending(host) \
4901 + test_and_clear_bit(EVENT_CMD_ERROR, &host->pending_events)
4902 +#define mci_clear_data_is_pending(host) \
4903 + test_and_clear_bit(EVENT_DATA_COMPLETE, &host->pending_events)
4904 +#define mci_clear_data_error_is_pending(host) \
4905 + test_and_clear_bit(EVENT_DATA_ERROR, &host->pending_events)
4906 +#define mci_clear_stop_sent_is_pending(host) \
4907 + test_and_clear_bit(EVENT_STOP_SENT, &host->pending_events)
4908 +#define mci_clear_stop_is_pending(host) \
4909 + test_and_clear_bit(EVENT_STOP_COMPLETE, &host->pending_events)
4910 +#define mci_clear_stop_error_is_pending(host) \
4911 + test_and_clear_bit(EVENT_STOP_ERROR, &host->pending_events)
4912 +#define mci_clear_dma_error_is_pending(host) \
4913 + test_and_clear_bit(EVENT_DMA_ERROR, &host->pending_events)
4914 +#define mci_clear_card_detect_is_pending(host) \
4915 + test_and_clear_bit(EVENT_CARD_DETECT, &host->pending_events)
4917 +/* Test and set bit macros for completed events */
4918 +#define mci_set_cmd_is_completed(host) \
4919 + test_and_set_bit(EVENT_CMD_COMPLETE, &host->completed_events)
4920 +#define mci_set_cmd_error_is_completed(host) \
4921 + test_and_set_bit(EVENT_CMD_ERROR, &host->completed_events)
4922 +#define mci_set_data_is_completed(host) \
4923 + test_and_set_bit(EVENT_DATA_COMPLETE, &host->completed_events)
4924 +#define mci_set_data_error_is_completed(host) \
4925 + test_and_set_bit(EVENT_DATA_ERROR, &host->completed_events)
4926 +#define mci_set_stop_sent_is_completed(host) \
4927 + test_and_set_bit(EVENT_STOP_SENT, &host->completed_events)
4928 +#define mci_set_stop_is_completed(host) \
4929 + test_and_set_bit(EVENT_STOP_COMPLETE, &host->completed_events)
4930 +#define mci_set_stop_error_is_completed(host) \
4931 + test_and_set_bit(EVENT_STOP_ERROR, &host->completed_events)
4932 +#define mci_set_dma_error_is_completed(host) \
4933 + test_and_set_bit(EVENT_DMA_ERROR, &host->completed_events)
4934 +#define mci_set_card_detect_is_completed(host) \
4935 + test_and_set_bit(EVENT_CARD_DETECT, &host->completed_events)
4937 +/* Set bit macros for completed events */
4938 +#define mci_set_cmd_complete(host) \
4939 + set_bit(EVENT_CMD_COMPLETE, &host->completed_events)
4940 +#define mci_set_cmd_error_complete(host) \
4941 + set_bit(EVENT_CMD_ERROR, &host->completed_events)
4942 +#define mci_set_data_complete(host) \
4943 + set_bit(EVENT_DATA_COMPLETE, &host->completed_events)
4944 +#define mci_set_data_error_complete(host) \
4945 + set_bit(EVENT_DATA_ERROR, &host->completed_events)
4946 +#define mci_set_stop_sent_complete(host) \
4947 + set_bit(EVENT_STOP_SENT, &host->completed_events)
4948 +#define mci_set_stop_complete(host) \
4949 + set_bit(EVENT_STOP_COMPLETE, &host->completed_events)
4950 +#define mci_set_stop_error_complete(host) \
4951 + set_bit(EVENT_STOP_ERROR, &host->completed_events)
4952 +#define mci_set_dma_error_complete(host) \
4953 + set_bit(EVENT_DMA_ERROR, &host->completed_events)
4954 +#define mci_set_card_detect_complete(host) \
4955 + set_bit(EVENT_CARD_DETECT, &host->completed_events)
4957 +/* Set bit macros for pending events */
4958 +#define mci_set_cmd_pending(host) \
4959 + set_bit(EVENT_CMD_COMPLETE, &host->pending_events)
4960 +#define mci_set_cmd_error_pending(host) \
4961 + set_bit(EVENT_CMD_ERROR, &host->pending_events)
4962 +#define mci_set_data_pending(host) \
4963 + set_bit(EVENT_DATA_COMPLETE, &host->pending_events)
4964 +#define mci_set_data_error_pending(host) \
4965 + set_bit(EVENT_DATA_ERROR, &host->pending_events)
4966 +#define mci_set_stop_sent_pending(host) \
4967 + set_bit(EVENT_STOP_SENT, &host->pending_events)
4968 +#define mci_set_stop_pending(host) \
4969 + set_bit(EVENT_STOP_COMPLETE, &host->pending_events)
4970 +#define mci_set_stop_error_pending(host) \
4971 + set_bit(EVENT_STOP_ERROR, &host->pending_events)
4972 +#define mci_set_dma_error_pending(host) \
4973 + set_bit(EVENT_DMA_ERROR, &host->pending_events)
4974 +#define mci_set_card_detect_pending(host) \
4975 + set_bit(EVENT_CARD_DETECT, &host->pending_events)
4977 +/* Clear bit macros for pending events */
4978 +#define mci_clear_cmd_pending(host) \
4979 + clear_bit(EVENT_CMD_COMPLETE, &host->pending_events)
4980 +#define mci_clear_cmd_error_pending(host) \
4981 + clear_bit(EVENT_CMD_ERROR, &host->pending_events)
4982 +#define mci_clear_data_pending(host) \
4983 + clear_bit(EVENT_DATA_COMPLETE, &host->pending_events)
4984 +#define mci_clear_data_error_pending(host) \
4985 + clear_bit(EVENT_DATA_ERROR, &host->pending_events)
4986 +#define mci_clear_stop_sent_pending(host) \
4987 + clear_bit(EVENT_STOP_SENT, &host->pending_events)
4988 +#define mci_clear_stop_pending(host) \
4989 + clear_bit(EVENT_STOP_COMPLETE, &host->pending_events)
4990 +#define mci_clear_stop_error_pending(host) \
4991 + clear_bit(EVENT_STOP_ERROR, &host->pending_events)
4992 +#define mci_clear_dma_error_pending(host) \
4993 + clear_bit(EVENT_DMA_ERROR, &host->pending_events)
4994 +#define mci_clear_card_detect_pending(host) \
4995 + clear_bit(EVENT_CARD_DETECT, &host->pending_events)
4998 +#ifdef CONFIG_DEBUG_FS
4999 +#include <linux/debugfs.h>
5001 +#define DBG_REQ_BUF_SIZE (4096 - sizeof(unsigned int))
5003 +struct req_dbg_data {
5004 + unsigned int nbytes;
5005 + char str[DBG_REQ_BUF_SIZE];
5008 +static int req_dbg_open(struct inode *inode, struct file *file)
5010 + struct atmel_mci *host;
5011 + struct mmc_request *mrq;
5012 + struct mmc_command *cmd, *stop;
5013 + struct mmc_data *data;
5014 + struct req_dbg_data *priv;
5016 + unsigned long n = 0;
5018 + priv = kzalloc(DBG_REQ_BUF_SIZE, GFP_KERNEL);
5023 + mutex_lock(&inode->i_mutex);
5024 + host = inode->i_private;
5026 + spin_lock_irq(&host->mmc->lock);
5032 + n = snprintf(str, DBG_REQ_BUF_SIZE,
5033 + "CMD%u(0x%x) %x %x %x %x %x (err %u)\n",
5034 + cmd->opcode, cmd->arg, cmd->flags,
5035 + cmd->resp[0], cmd->resp[1], cmd->resp[2],
5036 + cmd->resp[3], cmd->error);
5037 + if (n < DBG_REQ_BUF_SIZE && data)
5038 + n += snprintf(str + n, DBG_REQ_BUF_SIZE - n,
5039 + "DATA %u * %u (%u) %x (err %u)\n",
5040 + data->blocks, data->blksz,
5041 + data->bytes_xfered, data->flags,
5043 + if (n < DBG_REQ_BUF_SIZE && stop)
5044 + n += snprintf(str + n, DBG_REQ_BUF_SIZE - n,
5045 + "CMD%u(0x%x) %x %x %x %x %x (err %u)\n",
5046 + stop->opcode, stop->arg, stop->flags,
5047 + stop->resp[0], stop->resp[1],
5048 + stop->resp[2], stop->resp[3],
5051 + spin_unlock_irq(&host->mmc->lock);
5052 + mutex_unlock(&inode->i_mutex);
5054 + priv->nbytes = min(n, DBG_REQ_BUF_SIZE);
5055 + file->private_data = priv;
5060 +static ssize_t req_dbg_read(struct file *file, char __user *buf,
5061 + size_t nbytes, loff_t *ppos)
5063 + struct req_dbg_data *priv = file->private_data;
5065 + return simple_read_from_buffer(buf, nbytes, ppos,
5066 + priv->str, priv->nbytes);
5069 +static int req_dbg_release(struct inode *inode, struct file *file)
5071 + kfree(file->private_data);
5075 +static const struct file_operations req_dbg_fops = {
5076 + .owner = THIS_MODULE,
5077 + .open = req_dbg_open,
5078 + .llseek = no_llseek,
5079 + .read = req_dbg_read,
5080 + .release = req_dbg_release,
5083 +static int regs_dbg_open(struct inode *inode, struct file *file)
5085 + struct atmel_mci *host;
5088 + int ret = -ENOMEM;
5090 + mutex_lock(&inode->i_mutex);
5091 + host = inode->i_private;
5092 + data = kmalloc(inode->i_size, GFP_KERNEL);
5096 + spin_lock_irq(&host->mmc->lock);
5097 + for (i = 0; i < inode->i_size / 4; i++)
5098 + data[i] = __raw_readl(host->regs + i * 4);
5099 + spin_unlock_irq(&host->mmc->lock);
5101 + file->private_data = data;
5105 + mutex_unlock(&inode->i_mutex);
5110 +static ssize_t regs_dbg_read(struct file *file, char __user *buf,
5111 + size_t nbytes, loff_t *ppos)
5113 + struct inode *inode = file->f_dentry->d_inode;
5116 + mutex_lock(&inode->i_mutex);
5117 + ret = simple_read_from_buffer(buf, nbytes, ppos,
5118 + file->private_data,
5119 + file->f_dentry->d_inode->i_size);
5120 + mutex_unlock(&inode->i_mutex);
5125 +static int regs_dbg_release(struct inode *inode, struct file *file)
5127 + kfree(file->private_data);
5131 +static const struct file_operations regs_dbg_fops = {
5132 + .owner = THIS_MODULE,
5133 + .open = regs_dbg_open,
5134 + .llseek = generic_file_llseek,
5135 + .read = regs_dbg_read,
5136 + .release = regs_dbg_release,
5139 +static void atmci_init_debugfs(struct atmel_mci *host)
5141 + struct mmc_host *mmc;
5142 + struct dentry *root, *regs;
5143 + struct resource *res;
5146 + root = debugfs_create_dir(mmc_hostname(mmc), NULL);
5147 + if (IS_ERR(root) || !root)
5149 + host->debugfs_root = root;
5151 + regs = debugfs_create_file("regs", 0400, root, host, ®s_dbg_fops);
5155 + res = platform_get_resource(host->pdev, IORESOURCE_MEM, 0);
5156 + regs->d_inode->i_size = res->end - res->start + 1;
5157 + host->debugfs_regs = regs;
5159 + host->debugfs_req = debugfs_create_file("req", 0400, root,
5160 + host, &req_dbg_fops);
5161 + if (!host->debugfs_req)
5164 + host->debugfs_pending_events
5165 + = debugfs_create_u32("pending_events", 0400, root,
5166 + (u32 *)&host->pending_events);
5167 + if (!host->debugfs_pending_events)
5168 + goto err_pending_events;
5170 + host->debugfs_completed_events
5171 + = debugfs_create_u32("completed_events", 0400, root,
5172 + (u32 *)&host->completed_events);
5173 + if (!host->debugfs_completed_events)
5174 + goto err_completed_events;
5178 +err_completed_events:
5179 + debugfs_remove(host->debugfs_pending_events);
5180 +err_pending_events:
5181 + debugfs_remove(host->debugfs_req);
5183 + debugfs_remove(host->debugfs_regs);
5185 + debugfs_remove(host->debugfs_root);
5187 + host->debugfs_root = NULL;
5188 + dev_err(&host->pdev->dev,
5189 + "failed to initialize debugfs for %s\n",
5190 + mmc_hostname(mmc));
5193 +static void atmci_cleanup_debugfs(struct atmel_mci *host)
5195 + if (host->debugfs_root) {
5196 + debugfs_remove(host->debugfs_completed_events);
5197 + debugfs_remove(host->debugfs_pending_events);
5198 + debugfs_remove(host->debugfs_req);
5199 + debugfs_remove(host->debugfs_regs);
5200 + debugfs_remove(host->debugfs_root);
5201 + host->debugfs_root = NULL;
5205 +static inline void atmci_init_debugfs(struct atmel_mci *host)
5210 +static inline void atmci_cleanup_debugfs(struct atmel_mci *host)
5214 +#endif /* CONFIG_DEBUG_FS */
5216 +static inline unsigned int ns_to_clocks(struct atmel_mci *host,
5219 + return (ns * (host->bus_hz / 1000000) + 999) / 1000;
5222 +static void atmci_set_timeout(struct atmel_mci *host,
5223 + struct mmc_data *data)
5225 + static unsigned dtomul_to_shift[] = {
5226 + 0, 4, 7, 8, 10, 12, 16, 20
5229 + unsigned dtocyc, dtomul;
5231 + timeout = ns_to_clocks(host, data->timeout_ns) + data->timeout_clks;
5233 + for (dtomul = 0; dtomul < 8; dtomul++) {
5234 + unsigned shift = dtomul_to_shift[dtomul];
5235 + dtocyc = (timeout + (1 << shift) - 1) >> shift;
5240 + if (dtomul >= 8) {
5245 + pr_debug("%s: setting timeout to %u cycles\n",
5246 + mmc_hostname(host->mmc),
5247 + dtocyc << dtomul_to_shift[dtomul]);
5248 + mci_writel(host, DTOR, (MCI_BF(DTOMUL, dtomul)
5249 + | MCI_BF(DTOCYC, dtocyc)));
5253 + * Return mask with interrupt flags to be handled for this command.
5255 +static u32 atmci_prepare_command(struct mmc_host *mmc,
5256 + struct mmc_command *cmd,
5262 + cmd->error = MMC_ERR_NONE;
5265 + BUG_ON(MCI_BFEXT(CMDNB, cmdr) != 0);
5266 + cmdr = MCI_BFINS(CMDNB, cmd->opcode, cmdr);
5268 + if (cmd->flags & MMC_RSP_PRESENT) {
5269 + if (cmd->flags & MMC_RSP_136)
5270 + cmdr |= MCI_BF(RSPTYP, MCI_RSPTYP_136_BIT);
5272 + cmdr |= MCI_BF(RSPTYP, MCI_RSPTYP_48_BIT);
5276 + * This should really be MAXLAT_5 for CMD2 and ACMD41, but
5277 + * it's too difficult to determine whether this is an ACMD or
5278 + * not. Better make it 64.
5280 + cmdr |= MCI_BIT(MAXLAT);
5282 + if (mmc->ios.bus_mode == MMC_BUSMODE_OPENDRAIN)
5283 + cmdr |= MCI_BIT(OPDCMD);
5285 + iflags = MCI_BIT(CMDRDY) | MCI_CMD_ERROR_FLAGS;
5286 + if (!(cmd->flags & MMC_RSP_CRC))
5287 + iflags &= ~MCI_BIT(RCRCE);
5289 + pr_debug("%s: cmd: op %02x arg %08x flags %08x, cmdflags %08lx\n",
5290 + mmc_hostname(mmc), cmd->opcode, cmd->arg, cmd->flags,
5291 + (unsigned long)cmdr);
5293 + *cmd_flags = cmdr;
5297 +static void atmci_start_command(struct atmel_mci *host,
5298 + struct mmc_command *cmd,
5301 + WARN_ON(host->cmd);
5304 + mci_writel(host, ARGR, cmd->arg);
5305 + mci_writel(host, CMDR, cmd_flags);
5308 + dma_start_request(host->dma.req.req.dmac,
5309 + host->dma.req.req.channel);
5313 + * Returns a mask of flags to be set in the command register when the
5314 + * command to start the transfer is to be sent.
5316 +static u32 atmci_prepare_data(struct mmc_host *mmc, struct mmc_data *data)
5318 + struct atmel_mci *host = mmc_priv(mmc);
5321 + WARN_ON(host->data);
5322 + host->data = data;
5324 + atmci_set_timeout(host, data);
5325 + mci_writel(host, BLKR, (MCI_BF(BCNT, data->blocks)
5326 + | MCI_BF(BLKLEN, data->blksz)));
5327 + host->dma.req.block_size = data->blksz;
5328 + host->dma.req.nr_blocks = data->blocks;
5330 + cmd_flags = MCI_BF(TRCMD, MCI_TRCMD_START_TRANS);
5331 + if (data->flags & MMC_DATA_STREAM)
5332 + cmd_flags |= MCI_BF(TRTYP, MCI_TRTYP_STREAM);
5333 + else if (data->blocks > 1)
5334 + cmd_flags |= MCI_BF(TRTYP, MCI_TRTYP_MULTI_BLOCK);
5336 + cmd_flags |= MCI_BF(TRTYP, MCI_TRTYP_BLOCK);
5338 + if (data->flags & MMC_DATA_READ) {
5339 + cmd_flags |= MCI_BIT(TRDIR);
5340 + host->dma.req.nr_sg
5341 + = dma_map_sg(&host->pdev->dev, data->sg,
5342 + data->sg_len, DMA_FROM_DEVICE);
5343 + host->dma.req.periph_id = host->dma.rx_periph_id;
5344 + host->dma.req.direction = DMA_DIR_PERIPH_TO_MEM;
5345 + host->dma.req.data_reg = host->mapbase + MCI_RDR;
5347 + host->dma.req.nr_sg
5348 + = dma_map_sg(&host->pdev->dev, data->sg,
5349 + data->sg_len, DMA_TO_DEVICE);
5350 + host->dma.req.periph_id = host->dma.tx_periph_id;
5351 + host->dma.req.direction = DMA_DIR_MEM_TO_PERIPH;
5352 + host->dma.req.data_reg = host->mapbase + MCI_TDR;
5354 + host->dma.req.sg = data->sg;
5356 + dma_prepare_request_sg(host->dma.req.req.dmac, &host->dma.req);
5361 +static void atmci_request(struct mmc_host *mmc, struct mmc_request *mrq)
5363 + struct atmel_mci *host = mmc_priv(mmc);
5364 + struct mmc_data *data = mrq->data;
5368 + iflags = mci_readl(host, IMR);
5370 + printk("WARNING: IMR=0x%08x\n", mci_readl(host, IMR));
5372 + WARN_ON(host->mrq != NULL);
5374 + host->pending_events = 0;
5375 + host->completed_events = 0;
5377 + iflags = atmci_prepare_command(mmc, mrq->cmd, &cmdflags);
5382 + host->stop_iflags = atmci_prepare_command(mmc, mrq->stop,
5383 + &host->stop_cmdr);
5384 + host->stop_cmdr |= MCI_BF(TRCMD, MCI_TRCMD_STOP_TRANS);
5385 + if (!(data->flags & MMC_DATA_WRITE))
5386 + host->stop_cmdr |= MCI_BIT(TRDIR);
5387 + if (data->flags & MMC_DATA_STREAM)
5388 + host->stop_cmdr |= MCI_BF(TRTYP, MCI_TRTYP_STREAM);
5390 + host->stop_cmdr |= MCI_BF(TRTYP, MCI_TRTYP_MULTI_BLOCK);
5393 + cmdflags |= atmci_prepare_data(mmc, data);
5394 + iflags |= MCI_DATA_ERROR_FLAGS;
5397 + atmci_start_command(host, mrq->cmd, cmdflags);
5398 + mci_writel(host, IER, iflags);
5401 +static void atmci_set_ios(struct mmc_host *mmc, struct mmc_ios *ios)
5403 + struct atmel_mci *host = mmc_priv(mmc);
5408 + clkdiv = host->bus_hz / (2 * ios->clock) - 1;
5411 + mci_writel(host, MR, (clkdiv
5412 + | MCI_BIT(WRPROOF)
5413 + | MCI_BIT(RDPROOF)));
5416 + switch (ios->bus_width) {
5417 + case MMC_BUS_WIDTH_1:
5418 + mci_writel(host, SDCR, 0);
5420 + case MMC_BUS_WIDTH_4:
5421 + mci_writel(host, SDCR, MCI_BIT(SDCBUS));
5425 + switch (ios->power_mode) {
5426 + case MMC_POWER_OFF:
5427 + mci_writel(host, CR, MCI_BIT(MCIDIS));
5429 + case MMC_POWER_UP:
5430 + mci_writel(host, CR, MCI_BIT(SWRST));
5432 + case MMC_POWER_ON:
5433 + mci_writel(host, CR, MCI_BIT(MCIEN));
5438 +static int atmci_get_ro(struct mmc_host *mmc)
5440 + int read_only = 0;
5441 + struct atmel_mci *host = mmc_priv(mmc);
5443 + if (host->wp_pin >= 0) {
5444 + read_only = gpio_get_value(host->wp_pin);
5445 + pr_debug("%s: card is %s\n", mmc_hostname(mmc),
5446 + read_only ? "read-only" : "read-write");
5448 + pr_debug("%s: no pin for checking read-only switch."
5449 + " Assuming write-enable.\n", mmc_hostname(mmc));
5455 +static struct mmc_host_ops atmci_ops = {
5456 + .request = atmci_request,
5457 + .set_ios = atmci_set_ios,
5458 + .get_ro = atmci_get_ro,
5461 +static void atmci_request_end(struct mmc_host *mmc, struct mmc_request *mrq)
5463 + struct atmel_mci *host = mmc_priv(mmc);
5465 + WARN_ON(host->cmd || host->data);
5468 + mmc_request_done(mmc, mrq);
5471 +static void send_stop_cmd(struct mmc_host *mmc, struct mmc_data *data,
5474 + struct atmel_mci *host = mmc_priv(mmc);
5476 + atmci_start_command(host, data->stop, host->stop_cmdr | flags);
5477 + mci_writel(host, IER, host->stop_iflags);
5480 +static void atmci_data_complete(struct atmel_mci *host, struct mmc_data *data)
5482 + host->data = NULL;
5483 + dma_unmap_sg(&host->pdev->dev, data->sg, host->dma.req.nr_sg,
5484 + ((data->flags & MMC_DATA_WRITE)
5485 + ? DMA_TO_DEVICE : DMA_FROM_DEVICE));
5488 + * Data might complete before command for very short transfers
5491 + if (mci_cmd_is_complete(host)
5492 + && (!data->stop || mci_stop_is_complete(host)))
5493 + atmci_request_end(host->mmc, data->mrq);
5496 +static void atmci_command_error(struct mmc_host *mmc,
5497 + struct mmc_command *cmd,
5500 + pr_debug("%s: command error: status=0x%08x\n",
5501 + mmc_hostname(mmc), status);
5503 + if (status & MCI_BIT(RTOE))
5504 + cmd->error = MMC_ERR_TIMEOUT;
5505 + else if (status & MCI_BIT(RCRCE))
5506 + cmd->error = MMC_ERR_BADCRC;
5508 + cmd->error = MMC_ERR_FAILED;
5511 +static void atmci_tasklet_func(unsigned long priv)
5513 + struct mmc_host *mmc = (struct mmc_host *)priv;
5514 + struct atmel_mci *host = mmc_priv(mmc);
5515 + struct mmc_request *mrq = host->mrq;
5516 + struct mmc_data *data = host->data;
5518 + pr_debug("atmci_tasklet: pending/completed/mask %lx/%lx/%x\n",
5519 + host->pending_events, host->completed_events,
5520 + mci_readl(host, IMR));
5522 + if (mci_clear_cmd_error_is_pending(host)) {
5523 + struct mmc_command *cmd;
5525 + mci_set_cmd_error_complete(host);
5526 + mci_clear_cmd_pending(host);
5527 + cmd = host->mrq->cmd;
5530 + dma_stop_request(host->dma.req.req.dmac,
5531 + host->dma.req.req.channel);
5532 + host->data = NULL;
5535 + atmci_command_error(mmc, cmd, host->error_status);
5536 + atmci_request_end(mmc, cmd->mrq);
5538 + if (mci_clear_stop_error_is_pending(host)) {
5539 + mci_set_stop_error_complete(host);
5540 + mci_clear_stop_pending(host);
5541 + atmci_command_error(mmc, host->mrq->stop,
5542 + host->error_status);
5544 + atmci_request_end(mmc, host->mrq);
5546 + if (mci_clear_cmd_is_pending(host)) {
5547 + mci_set_cmd_complete(host);
5548 + if (!mrq->data || mci_data_is_complete(host)
5549 + || mci_data_error_is_complete(host))
5550 + atmci_request_end(mmc, mrq);
5552 + if (mci_clear_stop_is_pending(host)) {
5553 + mci_set_stop_complete(host);
5554 + if (mci_data_is_complete(host)
5555 + || mci_data_error_is_complete(host))
5556 + atmci_request_end(mmc, mrq);
5558 + if (mci_clear_dma_error_is_pending(host)) {
5559 + mci_set_dma_error_complete(host);
5560 + mci_clear_data_pending(host);
5562 + /* DMA controller got bus error => invalid address */
5563 + data->error = MMC_ERR_INVALID;
5565 + printk(KERN_DEBUG "%s: dma error after %u bytes xfered\n",
5566 + mmc_hostname(mmc), host->data->bytes_xfered);
5569 + && !mci_set_stop_sent_is_completed(host))
5570 + /* TODO: Check if card is still present */
5571 + send_stop_cmd(host->mmc, data, 0);
5573 + atmci_data_complete(host, data);
5575 + if (mci_clear_data_error_is_pending(host)) {
5576 + u32 status = host->error_status;
5578 + mci_set_data_error_complete(host);
5579 + mci_clear_data_pending(host);
5581 + dma_stop_request(host->dma.req.req.dmac,
5582 + host->dma.req.req.channel);
5584 + printk(KERN_DEBUG "%s: data error: status=0x%08x\n",
5585 + mmc_hostname(host->mmc), status);
5587 + if (status & MCI_BIT(DCRCE)) {
5588 + printk(KERN_DEBUG "%s: Data CRC error\n",
5589 + mmc_hostname(host->mmc));
5590 + data->error = MMC_ERR_BADCRC;
5591 + } else if (status & MCI_BIT(DTOE)) {
5592 + printk(KERN_DEBUG "%s: Data Timeout error\n",
5593 + mmc_hostname(host->mmc));
5594 + data->error = MMC_ERR_TIMEOUT;
5596 + printk(KERN_DEBUG "%s: Data FIFO error\n",
5597 + mmc_hostname(host->mmc));
5598 + data->error = MMC_ERR_FIFO;
5600 + printk(KERN_DEBUG "%s: Bytes xfered: %u\n",
5601 + mmc_hostname(host->mmc), data->bytes_xfered);
5604 + && !mci_set_stop_sent_is_completed(host))
5605 + /* TODO: Check if card is still present */
5606 + send_stop_cmd(host->mmc, data, 0);
5608 + atmci_data_complete(host, data);
5610 + if (mci_clear_data_is_pending(host)) {
5611 + mci_set_data_complete(host);
5612 + data->bytes_xfered = data->blocks * data->blksz;
5613 + atmci_data_complete(host, data);
5615 + if (mci_clear_card_detect_is_pending(host)) {
5616 + /* Reset controller if card is gone */
5617 + if (!host->present) {
5618 + mci_writel(host, CR, MCI_BIT(SWRST));
5619 + mci_writel(host, IDR, ~0UL);
5620 + mci_writel(host, CR, MCI_BIT(MCIEN));
5623 + /* Clean up queue if present */
5625 + if (!mci_cmd_is_complete(host)
5626 + && !mci_cmd_error_is_complete(host)) {
5627 + mrq->cmd->error = MMC_ERR_TIMEOUT;
5629 + if (mrq->data && !mci_data_is_complete(host)
5630 + && !mci_data_error_is_complete(host)) {
5631 + dma_stop_request(host->dma.req.req.dmac,
5632 + host->dma.req.req.channel);
5633 + host->data->error = MMC_ERR_TIMEOUT;
5634 + atmci_data_complete(host, data);
5636 + if (mrq->stop && !mci_stop_is_complete(host)
5637 + && !mci_stop_error_is_complete(host)) {
5638 + mrq->stop->error = MMC_ERR_TIMEOUT;
5642 + atmci_request_end(mmc, mrq);
5644 + mmc_detect_change(host->mmc, msecs_to_jiffies(100));
5648 +static void atmci_cmd_interrupt(struct mmc_host *mmc, u32 status)
5650 + struct atmel_mci *host = mmc_priv(mmc);
5651 + struct mmc_command *cmd = host->cmd;
5654 + * Read the response now so that we're free to send a new
5655 + * command immediately.
5657 + cmd->resp[0] = mci_readl(host, RSPR);
5658 + cmd->resp[1] = mci_readl(host, RSPR);
5659 + cmd->resp[2] = mci_readl(host, RSPR);
5660 + cmd->resp[3] = mci_readl(host, RSPR);
5662 + mci_writel(host, IDR, MCI_BIT(CMDRDY) | MCI_CMD_ERROR_FLAGS);
5665 + if (mci_stop_sent_is_complete(host))
5666 + mci_set_stop_pending(host);
5668 + mci_set_cmd_pending(host);
5670 + tasklet_schedule(&host->tasklet);
5673 +static void atmci_xfer_complete(struct dma_request *_req)
5675 + struct dma_request_sg *req = to_dma_request_sg(_req);
5676 + struct atmel_mci_dma *dma;
5677 + struct atmel_mci *host;
5678 + struct mmc_data *data;
5680 + dma = container_of(req, struct atmel_mci_dma, req);
5681 + host = container_of(dma, struct atmel_mci, dma);
5682 + data = host->data;
5684 + if (data->stop && !mci_set_stop_sent_is_completed(host))
5685 + send_stop_cmd(host->mmc, data, 0);
5687 + if (data->flags & MMC_DATA_READ) {
5688 + mci_writel(host, IDR, MCI_DATA_ERROR_FLAGS);
5689 + mci_set_data_pending(host);
5690 + tasklet_schedule(&host->tasklet);
5693 + * For the WRITE case, wait for NOTBUSY. This function
5694 + * is called when everything has been written to the
5695 + * controller, not when the card is done programming.
5697 + mci_writel(host, IER, MCI_BIT(NOTBUSY));
5701 +static void atmci_dma_error(struct dma_request *_req)
5703 + struct dma_request_sg *req = to_dma_request_sg(_req);
5704 + struct atmel_mci_dma *dma;
5705 + struct atmel_mci *host;
5707 + dma = container_of(req, struct atmel_mci_dma, req);
5708 + host = container_of(dma, struct atmel_mci, dma);
5710 + mci_writel(host, IDR, (MCI_BIT(NOTBUSY)
5711 + | MCI_DATA_ERROR_FLAGS));
5713 + mci_set_dma_error_pending(host);
5714 + tasklet_schedule(&host->tasklet);
5717 +static irqreturn_t atmci_interrupt(int irq, void *dev_id)
5719 + struct mmc_host *mmc = dev_id;
5720 + struct atmel_mci *host = mmc_priv(mmc);
5721 + u32 status, mask, pending;
5723 + spin_lock(&mmc->lock);
5725 + status = mci_readl(host, SR);
5726 + mask = mci_readl(host, IMR);
5727 + pending = status & mask;
5730 + if (pending & MCI_CMD_ERROR_FLAGS) {
5731 + mci_writel(host, IDR, (MCI_BIT(CMDRDY)
5732 + | MCI_BIT(NOTBUSY)
5733 + | MCI_CMD_ERROR_FLAGS
5734 + | MCI_DATA_ERROR_FLAGS));
5735 + host->error_status = status;
5737 + if (mci_stop_sent_is_complete(host))
5738 + mci_set_stop_error_pending(host);
5740 + mci_set_cmd_error_pending(host);
5741 + tasklet_schedule(&host->tasklet);
5744 + if (pending & MCI_DATA_ERROR_FLAGS) {
5745 + mci_writel(host, IDR, (MCI_BIT(NOTBUSY)
5746 + | MCI_DATA_ERROR_FLAGS));
5747 + host->error_status = status;
5748 + mci_set_data_error_pending(host);
5749 + tasklet_schedule(&host->tasklet);
5752 + if (pending & MCI_BIT(CMDRDY))
5753 + atmci_cmd_interrupt(mmc, status);
5754 + if (pending & MCI_BIT(NOTBUSY)) {
5755 + mci_writel(host, IDR, (MCI_BIT(NOTBUSY)
5756 + | MCI_DATA_ERROR_FLAGS));
5757 + mci_set_data_pending(host);
5758 + tasklet_schedule(&host->tasklet);
5761 + status = mci_readl(host, SR);
5762 + mask = mci_readl(host, IMR);
5763 + pending = status & mask;
5764 + } while (pending);
5766 + spin_unlock(&mmc->lock);
5768 + return IRQ_HANDLED;
5771 +static irqreturn_t atmci_detect_change(int irq, void *dev_id)
5773 + struct mmc_host *mmc = dev_id;
5774 + struct atmel_mci *host = mmc_priv(mmc);
5776 + int present = !gpio_get_value(irq_to_gpio(irq));
5778 + if (present != host->present) {
5779 + pr_debug("%s: card %s\n", mmc_hostname(host->mmc),
5780 + present ? "inserted" : "removed");
5781 + host->present = present;
5782 + mci_set_card_detect_pending(host);
5783 + tasklet_schedule(&host->tasklet);
5785 + return IRQ_HANDLED;
5788 +static int __devinit atmci_probe(struct platform_device *pdev)
5790 + struct mci_platform_data *board;
5791 + struct atmel_mci *host;
5792 + struct mmc_host *mmc;
5793 + struct resource *regs;
5797 + regs = platform_get_resource(pdev, IORESOURCE_MEM, 0);
5800 + irq = platform_get_irq(pdev, 0);
5804 + board = pdev->dev.platform_data;
5806 + mmc = mmc_alloc_host(sizeof(struct atmel_mci), &pdev->dev);
5810 + host = mmc_priv(mmc);
5811 + host->pdev = pdev;
5814 + host->detect_pin = board->detect_pin;
5815 + host->wp_pin = board->wp_pin;
5817 + host->detect_pin = -1;
5818 + host->detect_pin = -1;
5821 + host->mck = clk_get(&pdev->dev, "mci_clk");
5822 + if (IS_ERR(host->mck)) {
5823 + ret = PTR_ERR(host->mck);
5824 + goto out_free_host;
5826 + clk_enable(host->mck);
5829 + host->regs = ioremap(regs->start, regs->end - regs->start + 1);
5831 + goto out_disable_clk;
5833 + host->bus_hz = clk_get_rate(host->mck);
5834 + host->mapbase = regs->start;
5836 + mmc->ops = &atmci_ops;
5837 + mmc->f_min = (host->bus_hz + 511) / 512;
5838 + mmc->f_max = min((unsigned int)(host->bus_hz / 2), fmax);
5839 + mmc->ocr_avail = 0x00100000;
5840 + mmc->caps |= MMC_CAP_4_BIT_DATA;
5842 + tasklet_init(&host->tasklet, atmci_tasklet_func, (unsigned long)mmc);
5844 + ret = request_irq(irq, atmci_interrupt, 0, "mmci", mmc);
5848 + /* Assume card is present if we don't have a detect pin */
5849 + host->present = 1;
5850 + if (host->detect_pin >= 0) {
5851 + if (gpio_request(host->detect_pin, "mmc_detect")) {
5852 + printk(KERN_WARNING "%s: no detect pin available\n",
5853 + mmc_hostname(host->mmc));
5854 + host->detect_pin = -1;
5856 + host->present = !gpio_get_value(host->detect_pin);
5859 + if (host->wp_pin >= 0) {
5860 + if (gpio_request(host->wp_pin, "mmc_wp")) {
5861 + printk(KERN_WARNING "%s: no WP pin available\n",
5862 + mmc_hostname(host->mmc));
5863 + host->wp_pin = -1;
5867 + /* TODO: Get this information from platform data */
5869 + host->dma.req.req.dmac = find_dma_controller(0);
5870 + if (!host->dma.req.req.dmac) {
5872 + "mmci: No DMA controller available, aborting\n");
5873 + goto out_free_irq;
5875 + ret = dma_alloc_channel(host->dma.req.req.dmac);
5878 + "mmci: Unable to allocate DMA channel, aborting\n");
5879 + goto out_free_irq;
5881 + host->dma.req.req.channel = ret;
5882 + host->dma.req.width = DMA_WIDTH_32BIT;
5883 + host->dma.req.req.xfer_complete = atmci_xfer_complete;
5884 + host->dma.req.req.block_complete = NULL; // atmci_block_complete;
5885 + host->dma.req.req.error = atmci_dma_error;
5886 + host->dma.rx_periph_id = 0;
5887 + host->dma.tx_periph_id = 1;
5889 + mci_writel(host, CR, MCI_BIT(SWRST));
5890 + mci_writel(host, IDR, ~0UL);
5891 + mci_writel(host, CR, MCI_BIT(MCIEN));
5893 + platform_set_drvdata(pdev, host);
5895 + mmc_add_host(mmc);
5897 + if (host->detect_pin >= 0) {
5898 + ret = request_irq(gpio_to_irq(host->detect_pin),
5899 + atmci_detect_change,
5900 + IRQF_TRIGGER_FALLING | IRQF_TRIGGER_RISING,
5901 + DRIVER_NAME, mmc);
5904 + "%s: could not request IRQ %d for detect pin\n",
5905 + mmc_hostname(mmc),
5906 + gpio_to_irq(host->detect_pin));
5907 + gpio_free(host->detect_pin);
5908 + host->detect_pin = -1;
5912 + printk(KERN_INFO "%s: Atmel MCI controller at 0x%08lx irq %d\n",
5913 + mmc_hostname(mmc), host->mapbase, irq);
5915 + atmci_init_debugfs(host);
5920 + if (host->detect_pin >= 0)
5921 + gpio_free(host->detect_pin);
5922 + if (host->wp_pin >= 0)
5923 + gpio_free(host->wp_pin);
5924 + free_irq(irq, mmc);
5926 + iounmap(host->regs);
5928 + clk_disable(host->mck);
5929 + clk_put(host->mck);
5931 + mmc_free_host(mmc);
5935 +static int __devexit atmci_remove(struct platform_device *pdev)
5937 + struct atmel_mci *host = platform_get_drvdata(pdev);
5939 + platform_set_drvdata(pdev, NULL);
5942 + atmci_cleanup_debugfs(host);
5944 + if (host->detect_pin >= 0) {
5945 + free_irq(gpio_to_irq(host->detect_pin), host->mmc);
5946 + cancel_delayed_work(&host->mmc->detect);
5947 + gpio_free(host->detect_pin);
5950 + mmc_remove_host(host->mmc);
5952 + mci_writel(host, IDR, ~0UL);
5953 + mci_writel(host, CR, MCI_BIT(MCIDIS));
5954 + mci_readl(host, SR);
5956 + dma_release_channel(host->dma.req.req.dmac,
5957 + host->dma.req.req.channel);
5959 + if (host->wp_pin >= 0)
5960 + gpio_free(host->wp_pin);
5962 + free_irq(platform_get_irq(pdev, 0), host->mmc);
5963 + iounmap(host->regs);
5965 + clk_disable(host->mck);
5966 + clk_put(host->mck);
5968 + mmc_free_host(host->mmc);
5973 +static struct platform_driver atmci_driver = {
5974 + .probe = atmci_probe,
5975 + .remove = __devexit_p(atmci_remove),
5977 + .name = DRIVER_NAME,
5981 +static int __init atmci_init(void)
5983 + return platform_driver_register(&atmci_driver);
5986 +static void __exit atmci_exit(void)
5988 + platform_driver_unregister(&atmci_driver);
5991 +module_init(atmci_init);
5992 +module_exit(atmci_exit);
5994 +MODULE_DESCRIPTION("Atmel Multimedia Card Interface driver");
5995 +MODULE_LICENSE("GPL");
5996 diff -x .git -Nur linux-2.6.22.1/drivers/mmc/host/atmel-mci.h linux-avr32.git/drivers/mmc/host/atmel-mci.h
5997 --- linux-2.6.22.1/drivers/mmc/host/atmel-mci.h 1970-01-01 01:00:00.000000000 +0100
5998 +++ linux-avr32.git/drivers/mmc/host/atmel-mci.h 2007-07-12 14:00:03.000000000 +0200
6001 + * Atmel MultiMedia Card Interface driver
6003 + * Copyright (C) 2004-2006 Atmel Corporation
6005 + * This program is free software; you can redistribute it and/or modify
6006 + * it under the terms of the GNU General Public License version 2 as
6007 + * published by the Free Software Foundation.
6009 +#ifndef __DRIVERS_MMC_ATMEL_MCI_H__
6010 +#define __DRIVERS_MMC_ATMEL_MCI_H__
6012 +/* MCI register offsets */
6013 +#define MCI_CR 0x0000
6014 +#define MCI_MR 0x0004
6015 +#define MCI_DTOR 0x0008
6016 +#define MCI_SDCR 0x000c
6017 +#define MCI_ARGR 0x0010
6018 +#define MCI_CMDR 0x0014
6019 +#define MCI_BLKR 0x0018
6020 +#define MCI_RSPR 0x0020
6021 +#define MCI_RSPR1 0x0024
6022 +#define MCI_RSPR2 0x0028
6023 +#define MCI_RSPR3 0x002c
6024 +#define MCI_RDR 0x0030
6025 +#define MCI_TDR 0x0034
6026 +#define MCI_SR 0x0040
6027 +#define MCI_IER 0x0044
6028 +#define MCI_IDR 0x0048
6029 +#define MCI_IMR 0x004c
6031 +/* Bitfields in CR */
6032 +#define MCI_MCIEN_OFFSET 0
6033 +#define MCI_MCIEN_SIZE 1
6034 +#define MCI_MCIDIS_OFFSET 1
6035 +#define MCI_MCIDIS_SIZE 1
6036 +#define MCI_PWSEN_OFFSET 2
6037 +#define MCI_PWSEN_SIZE 1
6038 +#define MCI_PWSDIS_OFFSET 3
6039 +#define MCI_PWSDIS_SIZE 1
6040 +#define MCI_SWRST_OFFSET 7
6041 +#define MCI_SWRST_SIZE 1
6043 +/* Bitfields in MR */
6044 +#define MCI_CLKDIV_OFFSET 0
6045 +#define MCI_CLKDIV_SIZE 8
6046 +#define MCI_PWSDIV_OFFSET 8
6047 +#define MCI_PWSDIV_SIZE 3
6048 +#define MCI_RDPROOF_OFFSET 11
6049 +#define MCI_RDPROOF_SIZE 1
6050 +#define MCI_WRPROOF_OFFSET 12
6051 +#define MCI_WRPROOF_SIZE 1
6052 +#define MCI_DMAPADV_OFFSET 14
6053 +#define MCI_DMAPADV_SIZE 1
6054 +#define MCI_BLKLEN_OFFSET 16
6055 +#define MCI_BLKLEN_SIZE 16
6057 +/* Bitfields in DTOR */
6058 +#define MCI_DTOCYC_OFFSET 0
6059 +#define MCI_DTOCYC_SIZE 4
6060 +#define MCI_DTOMUL_OFFSET 4
6061 +#define MCI_DTOMUL_SIZE 3
6063 +/* Bitfields in SDCR */
6064 +#define MCI_SDCSEL_OFFSET 0
6065 +#define MCI_SDCSEL_SIZE 4
6066 +#define MCI_SDCBUS_OFFSET 7
6067 +#define MCI_SDCBUS_SIZE 1
6069 +/* Bitfields in ARGR */
6070 +#define MCI_ARG_OFFSET 0
6071 +#define MCI_ARG_SIZE 32
6073 +/* Bitfields in CMDR */
6074 +#define MCI_CMDNB_OFFSET 0
6075 +#define MCI_CMDNB_SIZE 6
6076 +#define MCI_RSPTYP_OFFSET 6
6077 +#define MCI_RSPTYP_SIZE 2
6078 +#define MCI_SPCMD_OFFSET 8
6079 +#define MCI_SPCMD_SIZE 3
6080 +#define MCI_OPDCMD_OFFSET 11
6081 +#define MCI_OPDCMD_SIZE 1
6082 +#define MCI_MAXLAT_OFFSET 12
6083 +#define MCI_MAXLAT_SIZE 1
6084 +#define MCI_TRCMD_OFFSET 16
6085 +#define MCI_TRCMD_SIZE 2
6086 +#define MCI_TRDIR_OFFSET 18
6087 +#define MCI_TRDIR_SIZE 1
6088 +#define MCI_TRTYP_OFFSET 19
6089 +#define MCI_TRTYP_SIZE 2
6091 +/* Bitfields in BLKR */
6092 +#define MCI_BCNT_OFFSET 0
6093 +#define MCI_BCNT_SIZE 16
6095 +/* Bitfields in RSPRn */
6096 +#define MCI_RSP_OFFSET 0
6097 +#define MCI_RSP_SIZE 32
6099 +/* Bitfields in SR/IER/IDR/IMR */
6100 +#define MCI_CMDRDY_OFFSET 0
6101 +#define MCI_CMDRDY_SIZE 1
6102 +#define MCI_RXRDY_OFFSET 1
6103 +#define MCI_RXRDY_SIZE 1
6104 +#define MCI_TXRDY_OFFSET 2
6105 +#define MCI_TXRDY_SIZE 1
6106 +#define MCI_BLKE_OFFSET 3
6107 +#define MCI_BLKE_SIZE 1
6108 +#define MCI_DTIP_OFFSET 4
6109 +#define MCI_DTIP_SIZE 1
6110 +#define MCI_NOTBUSY_OFFSET 5
6111 +#define MCI_NOTBUSY_SIZE 1
6112 +#define MCI_ENDRX_OFFSET 6
6113 +#define MCI_ENDRX_SIZE 1
6114 +#define MCI_ENDTX_OFFSET 7
6115 +#define MCI_ENDTX_SIZE 1
6116 +#define MCI_RXBUFF_OFFSET 14
6117 +#define MCI_RXBUFF_SIZE 1
6118 +#define MCI_TXBUFE_OFFSET 15
6119 +#define MCI_TXBUFE_SIZE 1
6120 +#define MCI_RINDE_OFFSET 16
6121 +#define MCI_RINDE_SIZE 1
6122 +#define MCI_RDIRE_OFFSET 17
6123 +#define MCI_RDIRE_SIZE 1
6124 +#define MCI_RCRCE_OFFSET 18
6125 +#define MCI_RCRCE_SIZE 1
6126 +#define MCI_RENDE_OFFSET 19
6127 +#define MCI_RENDE_SIZE 1
6128 +#define MCI_RTOE_OFFSET 20
6129 +#define MCI_RTOE_SIZE 1
6130 +#define MCI_DCRCE_OFFSET 21
6131 +#define MCI_DCRCE_SIZE 1
6132 +#define MCI_DTOE_OFFSET 22
6133 +#define MCI_DTOE_SIZE 1
6134 +#define MCI_OVRE_OFFSET 30
6135 +#define MCI_OVRE_SIZE 1
6136 +#define MCI_UNRE_OFFSET 31
6137 +#define MCI_UNRE_SIZE 1
6139 +/* Constants for DTOMUL */
6140 +#define MCI_DTOMUL_1_CYCLE 0
6141 +#define MCI_DTOMUL_16_CYCLES 1
6142 +#define MCI_DTOMUL_128_CYCLES 2
6143 +#define MCI_DTOMUL_256_CYCLES 3
6144 +#define MCI_DTOMUL_1024_CYCLES 4
6145 +#define MCI_DTOMUL_4096_CYCLES 5
6146 +#define MCI_DTOMUL_65536_CYCLES 6
6147 +#define MCI_DTOMUL_1048576_CYCLES 7
6149 +/* Constants for RSPTYP */
6150 +#define MCI_RSPTYP_NO_RESP 0
6151 +#define MCI_RSPTYP_48_BIT 1
6152 +#define MCI_RSPTYP_136_BIT 2
6154 +/* Constants for SPCMD */
6155 +#define MCI_SPCMD_NO_SPEC_CMD 0
6156 +#define MCI_SPCMD_INIT_CMD 1
6157 +#define MCI_SPCMD_SYNC_CMD 2
6158 +#define MCI_SPCMD_INT_CMD 4
6159 +#define MCI_SPCMD_INT_RESP 5
6161 +/* Constants for TRCMD */
6162 +#define MCI_TRCMD_NO_TRANS 0
6163 +#define MCI_TRCMD_START_TRANS 1
6164 +#define MCI_TRCMD_STOP_TRANS 2
6166 +/* Constants for TRTYP */
6167 +#define MCI_TRTYP_BLOCK 0
6168 +#define MCI_TRTYP_MULTI_BLOCK 1
6169 +#define MCI_TRTYP_STREAM 2
6171 +/* Bit manipulation macros */
6172 +#define MCI_BIT(name) \
6173 + (1 << MCI_##name##_OFFSET)
6174 +#define MCI_BF(name,value) \
6175 + (((value) & ((1 << MCI_##name##_SIZE) - 1)) \
6176 + << MCI_##name##_OFFSET)
6177 +#define MCI_BFEXT(name,value) \
6178 + (((value) >> MCI_##name##_OFFSET) \
6179 + & ((1 << MCI_##name##_SIZE) - 1))
6180 +#define MCI_BFINS(name,value,old) \
6181 + (((old) & ~(((1 << MCI_##name##_SIZE) - 1) \
6182 + << MCI_##name##_OFFSET)) \
6183 + | MCI_BF(name,value))
6185 +/* Register access macros */
6186 +#define mci_readl(port,reg) \
6187 + __raw_readl((port)->regs + MCI_##reg)
6188 +#define mci_writel(port,reg,value) \
6189 + __raw_writel((value), (port)->regs + MCI_##reg)
6191 +#endif /* __DRIVERS_MMC_ATMEL_MCI_H__ */
6192 diff -x .git -Nur linux-2.6.22.1/drivers/mmc/host/Kconfig linux-avr32.git/drivers/mmc/host/Kconfig
6193 --- linux-2.6.22.1/drivers/mmc/host/Kconfig 2007-07-10 20:56:30.000000000 +0200
6194 +++ linux-avr32.git/drivers/mmc/host/Kconfig 2007-07-12 14:00:03.000000000 +0200
6199 +config MMC_ATMELMCI
6200 + tristate "Atmel Multimedia Card Interface support"
6201 + depends on AVR32 && MMC
6203 + This selects the Atmel Multimedia Card Interface. If you have
6204 + a AT91 (ARM) or AT32 (AVR32) platform with a Multimedia Card
6205 + slot, say Y or M here.
6210 tristate "Motorola i.MX Multimedia Card Interface support"
6212 diff -x .git -Nur linux-2.6.22.1/drivers/mmc/host/Makefile linux-avr32.git/drivers/mmc/host/Makefile
6213 --- linux-2.6.22.1/drivers/mmc/host/Makefile 2007-07-10 20:56:30.000000000 +0200
6214 +++ linux-avr32.git/drivers/mmc/host/Makefile 2007-07-12 14:00:03.000000000 +0200
6216 obj-$(CONFIG_MMC_AU1X) += au1xmmc.o
6217 obj-$(CONFIG_MMC_OMAP) += omap.o
6218 obj-$(CONFIG_MMC_AT91) += at91_mci.o
6219 +obj-$(CONFIG_MMC_ATMELMCI) += atmel-mci.o
6220 obj-$(CONFIG_MMC_TIFM_SD) += tifm_sd.o
6222 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
6223 --- linux-2.6.22.1/drivers/mtd/chips/cfi_cmdset_0001.c 2007-07-10 20:56:30.000000000 +0200
6224 +++ linux-avr32.git/drivers/mtd/chips/cfi_cmdset_0001.c 2007-07-12 14:00:03.000000000 +0200
6226 #define I82802AC 0x00ac
6227 #define MANUFACTURER_ST 0x0020
6228 #define M50LPW080 0x002F
6229 +#define AT49BV640D 0x02de
6231 static int cfi_intelext_read (struct mtd_info *, loff_t, size_t, size_t *, u_char *);
6232 static int cfi_intelext_write_words(struct mtd_info *, loff_t, size_t, size_t *, const u_char *);
6233 @@ -156,6 +157,47 @@
6237 +/* Atmel chips don't use the same PRI format as Intel chips */
6238 +static void fixup_convert_atmel_pri(struct mtd_info *mtd, void *param)
6240 + struct map_info *map = mtd->priv;
6241 + struct cfi_private *cfi = map->fldrv_priv;
6242 + struct cfi_pri_intelext *extp = cfi->cmdset_priv;
6243 + struct cfi_pri_atmel atmel_pri;
6244 + uint32_t features = 0;
6246 + /* Reverse byteswapping */
6247 + extp->FeatureSupport = cpu_to_le32(extp->FeatureSupport);
6248 + extp->BlkStatusRegMask = cpu_to_le16(extp->BlkStatusRegMask);
6249 + extp->ProtRegAddr = cpu_to_le16(extp->ProtRegAddr);
6251 + memcpy(&atmel_pri, extp, sizeof(atmel_pri));
6252 + memset((char *)extp + 5, 0, sizeof(*extp) - 5);
6254 + printk(KERN_ERR "atmel Features: %02x\n", atmel_pri.Features);
6256 + if (atmel_pri.Features & 0x01) /* chip erase supported */
6257 + features |= (1<<0);
6258 + if (atmel_pri.Features & 0x02) /* erase suspend supported */
6259 + features |= (1<<1);
6260 + if (atmel_pri.Features & 0x04) /* program suspend supported */
6261 + features |= (1<<2);
6262 + if (atmel_pri.Features & 0x08) /* simultaneous operations supported */
6263 + features |= (1<<9);
6264 + if (atmel_pri.Features & 0x20) /* page mode read supported */
6265 + features |= (1<<7);
6266 + if (atmel_pri.Features & 0x40) /* queued erase supported */
6267 + features |= (1<<4);
6268 + if (atmel_pri.Features & 0x80) /* Protection bits supported */
6269 + features |= (1<<6);
6271 + extp->FeatureSupport = features;
6273 + /* burst write mode not supported */
6274 + cfi->cfiq->BufWriteTimeoutTyp = 0;
6275 + cfi->cfiq->BufWriteTimeoutMax = 0;
6278 #ifdef CMDSET0001_DISABLE_ERASE_SUSPEND_ON_WRITE
6279 /* Some Intel Strata Flash prior to FPO revision C has bugs in this area */
6280 static void fixup_intel_strataflash(struct mtd_info *mtd, void* param)
6284 static struct cfi_fixup cfi_fixup_table[] = {
6285 + { CFI_MFR_ATMEL, CFI_ID_ANY, fixup_convert_atmel_pri, NULL },
6286 #ifdef CMDSET0001_DISABLE_ERASE_SUSPEND_ON_WRITE
6287 { CFI_MFR_ANY, CFI_ID_ANY, fixup_intel_strataflash, NULL },
6289 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
6290 --- linux-2.6.22.1/drivers/mtd/chips/cfi_cmdset_0002.c 2007-07-10 20:56:30.000000000 +0200
6291 +++ linux-avr32.git/drivers/mtd/chips/cfi_cmdset_0002.c 2007-06-06 11:33:56.000000000 +0200
6292 @@ -186,6 +186,10 @@
6293 extp->TopBottom = 2;
6295 extp->TopBottom = 3;
6297 + /* burst write mode not supported */
6298 + cfi->cfiq->BufWriteTimeoutTyp = 0;
6299 + cfi->cfiq->BufWriteTimeoutMax = 0;
6302 static void fixup_use_secsi(struct mtd_info *mtd, void *param)
6306 static struct cfi_fixup cfi_fixup_table[] = {
6307 + { CFI_MFR_ATMEL, CFI_ID_ANY, fixup_convert_atmel_pri, NULL },
6308 #ifdef AMD_BOOTLOC_BUG
6309 { CFI_MFR_AMD, CFI_ID_ANY, fixup_amd_bootblock, NULL },
6312 #if !FORCE_WORD_WRITE
6313 { CFI_MFR_ANY, CFI_ID_ANY, fixup_use_write_buffers, NULL, },
6315 - { CFI_MFR_ATMEL, CFI_ID_ANY, fixup_convert_atmel_pri, NULL },
6316 { 0, 0, NULL, NULL }
6318 static struct cfi_fixup jedec_fixup_table[] = {
6319 diff -x .git -Nur linux-2.6.22.1/drivers/net/Kconfig linux-avr32.git/drivers/net/Kconfig
6320 --- linux-2.6.22.1/drivers/net/Kconfig 2007-07-10 20:56:30.000000000 +0200
6321 +++ linux-avr32.git/drivers/net/Kconfig 2007-07-12 14:00:03.000000000 +0200
6324 tristate "Atmel MACB support"
6325 depends on NET_ETHERNET && (AVR32 || ARCH_AT91SAM9260 || ARCH_AT91SAM9263)
6329 The Atmel MACB ethernet interface is found on many AT32 and AT91
6330 parts. Say Y to include support for the MACB chip.
6331 diff -x .git -Nur linux-2.6.22.1/drivers/net/macb.c linux-avr32.git/drivers/net/macb.c
6332 --- linux-2.6.22.1/drivers/net/macb.c 2007-07-10 20:56:30.000000000 +0200
6333 +++ linux-avr32.git/drivers/net/macb.c 2007-07-12 14:00:04.000000000 +0200
6335 #include <linux/init.h>
6336 #include <linux/netdevice.h>
6337 #include <linux/etherdevice.h>
6338 -#include <linux/mii.h>
6339 -#include <linux/mutex.h>
6340 #include <linux/dma-mapping.h>
6341 -#include <linux/ethtool.h>
6342 #include <linux/platform_device.h>
6343 +#include <linux/phy.h>
6345 #include <asm/arch/board.h>
6346 +#if defined(CONFIG_ARCH_AT91)
6347 +#include <asm/arch/cpu.h>
6352 @@ -85,172 +86,202 @@
6353 memcpy(bp->dev->dev_addr, addr, sizeof(addr));
6356 -static void macb_enable_mdio(struct macb *bp)
6358 - unsigned long flags;
6361 - spin_lock_irqsave(&bp->lock, flags);
6362 - reg = macb_readl(bp, NCR);
6363 - reg |= MACB_BIT(MPE);
6364 - macb_writel(bp, NCR, reg);
6365 - macb_writel(bp, IER, MACB_BIT(MFD));
6366 - spin_unlock_irqrestore(&bp->lock, flags);
6369 -static void macb_disable_mdio(struct macb *bp)
6371 - unsigned long flags;
6374 - spin_lock_irqsave(&bp->lock, flags);
6375 - reg = macb_readl(bp, NCR);
6376 - reg &= ~MACB_BIT(MPE);
6377 - macb_writel(bp, NCR, reg);
6378 - macb_writel(bp, IDR, MACB_BIT(MFD));
6379 - spin_unlock_irqrestore(&bp->lock, flags);
6382 -static int macb_mdio_read(struct net_device *dev, int phy_id, int location)
6383 +static int macb_mdio_read(struct mii_bus *bus, int mii_id, int regnum)
6385 - struct macb *bp = netdev_priv(dev);
6386 + struct macb *bp = bus->priv;
6389 - mutex_lock(&bp->mdio_mutex);
6391 - macb_enable_mdio(bp);
6392 macb_writel(bp, MAN, (MACB_BF(SOF, MACB_MAN_SOF)
6393 | MACB_BF(RW, MACB_MAN_READ)
6394 - | MACB_BF(PHYA, phy_id)
6395 - | MACB_BF(REGA, location)
6396 + | MACB_BF(PHYA, mii_id)
6397 + | MACB_BF(REGA, regnum)
6398 | MACB_BF(CODE, MACB_MAN_CODE)));
6400 - wait_for_completion(&bp->mdio_complete);
6401 + /* wait for end of transfer */
6402 + while (!MACB_BFEXT(IDLE, macb_readl(bp, NSR)))
6405 value = MACB_BFEXT(DATA, macb_readl(bp, MAN));
6406 - macb_disable_mdio(bp);
6407 - mutex_unlock(&bp->mdio_mutex);
6412 -static void macb_mdio_write(struct net_device *dev, int phy_id,
6413 - int location, int val)
6414 +static int macb_mdio_write(struct mii_bus *bus, int mii_id, int regnum,
6417 - struct macb *bp = netdev_priv(dev);
6419 - dev_dbg(&bp->pdev->dev, "mdio_write %02x:%02x <- %04x\n",
6420 - phy_id, location, val);
6422 - mutex_lock(&bp->mdio_mutex);
6423 - macb_enable_mdio(bp);
6424 + struct macb *bp = bus->priv;
6426 macb_writel(bp, MAN, (MACB_BF(SOF, MACB_MAN_SOF)
6427 | MACB_BF(RW, MACB_MAN_WRITE)
6428 - | MACB_BF(PHYA, phy_id)
6429 - | MACB_BF(REGA, location)
6430 + | MACB_BF(PHYA, mii_id)
6431 + | MACB_BF(REGA, regnum)
6432 | MACB_BF(CODE, MACB_MAN_CODE)
6433 - | MACB_BF(DATA, val)));
6434 + | MACB_BF(DATA, value)));
6436 + /* wait for end of transfer */
6437 + while (!MACB_BFEXT(IDLE, macb_readl(bp, NSR)))
6440 - wait_for_completion(&bp->mdio_complete);
6444 - macb_disable_mdio(bp);
6445 - mutex_unlock(&bp->mdio_mutex);
6446 +static int macb_mdio_reset(struct mii_bus *bus)
6451 -static int macb_phy_probe(struct macb *bp)
6452 +static void macb_handle_link_change(struct net_device *dev)
6455 - u16 phyid1, phyid2;
6456 + struct macb *bp = netdev_priv(dev);
6457 + struct phy_device *phydev = bp->phy_dev;
6458 + unsigned long flags;
6460 - for (phy_address = 0; phy_address < 32; phy_address++) {
6461 - phyid1 = macb_mdio_read(bp->dev, phy_address, MII_PHYSID1);
6462 - phyid2 = macb_mdio_read(bp->dev, phy_address, MII_PHYSID2);
6463 + int status_change = 0;
6465 - if (phyid1 != 0xffff && phyid1 != 0x0000
6466 - && phyid2 != 0xffff && phyid2 != 0x0000)
6468 + spin_lock_irqsave(&bp->lock, flags);
6470 + if (phydev->link) {
6471 + if ((bp->speed != phydev->speed) ||
6472 + (bp->duplex != phydev->duplex)) {
6475 + reg = macb_readl(bp, NCFGR);
6476 + reg &= ~(MACB_BIT(SPD) | MACB_BIT(FD));
6478 + if (phydev->duplex)
6479 + reg |= MACB_BIT(FD);
6480 + if (phydev->speed)
6481 + reg |= MACB_BIT(SPD);
6483 + macb_writel(bp, NCFGR, reg);
6485 + bp->speed = phydev->speed;
6486 + bp->duplex = phydev->duplex;
6487 + status_change = 1;
6491 - if (phy_address == 32)
6493 + if (phydev->link != bp->link) {
6495 + netif_schedule(dev);
6500 + bp->link = phydev->link;
6502 - dev_info(&bp->pdev->dev,
6503 - "detected PHY at address %d (ID %04x:%04x)\n",
6504 - phy_address, phyid1, phyid2);
6505 + status_change = 1;
6508 - bp->mii.phy_id = phy_address;
6510 + spin_unlock_irqrestore(&bp->lock, flags);
6512 + if (status_change) {
6514 + printk(KERN_INFO "%s: link up (%d/%s)\n",
6515 + dev->name, phydev->speed,
6516 + DUPLEX_FULL == phydev->duplex ? "Full":"Half");
6518 + printk(KERN_INFO "%s: link down\n", dev->name);
6522 -static void macb_set_media(struct macb *bp, int media)
6523 +/* based on au1000_eth. c*/
6524 +static int macb_mii_probe(struct net_device *dev)
6527 + struct macb *bp = netdev_priv(dev);
6528 + struct phy_device *phydev = NULL;
6529 + struct eth_platform_data *pdata;
6532 - spin_lock_irq(&bp->lock);
6533 - reg = macb_readl(bp, NCFGR);
6534 - reg &= ~(MACB_BIT(SPD) | MACB_BIT(FD));
6535 - if (media & (ADVERTISE_100HALF | ADVERTISE_100FULL))
6536 - reg |= MACB_BIT(SPD);
6537 - if (media & ADVERTISE_FULL)
6538 - reg |= MACB_BIT(FD);
6539 - macb_writel(bp, NCFGR, reg);
6540 - spin_unlock_irq(&bp->lock);
6541 + /* find the first phy */
6542 + for (phy_addr = 0; phy_addr < PHY_MAX_ADDR; phy_addr++) {
6543 + if (bp->mii_bus.phy_map[phy_addr]) {
6544 + phydev = bp->mii_bus.phy_map[phy_addr];
6550 + printk (KERN_ERR "%s: no PHY found\n", dev->name);
6554 + pdata = bp->pdev->dev.platform_data;
6555 + /* TODO : add pin_irq */
6557 + /* attach the mac to the phy */
6558 + if (pdata && pdata->is_rmii) {
6559 + phydev = phy_connect(dev, phydev->dev.bus_id,
6560 + &macb_handle_link_change, 0, PHY_INTERFACE_MODE_RMII);
6562 + phydev = phy_connect(dev, phydev->dev.bus_id,
6563 + &macb_handle_link_change, 0, PHY_INTERFACE_MODE_MII);
6566 + if (IS_ERR(phydev)) {
6567 + printk(KERN_ERR "%s: Could not attach to PHY\n", dev->name);
6568 + return PTR_ERR(phydev);
6571 + /* mask with MAC supported features */
6572 + phydev->supported &= PHY_BASIC_FEATURES;
6574 + phydev->advertising = phydev->supported;
6579 + bp->phy_dev = phydev;
6584 -static void macb_check_media(struct macb *bp, int ok_to_print, int init_media)
6585 +static int macb_mii_init(struct macb *bp)
6587 - struct mii_if_info *mii = &bp->mii;
6588 - unsigned int old_carrier, new_carrier;
6589 - int advertise, lpa, media, duplex;
6590 + struct eth_platform_data *pdata;
6591 + int err = -ENXIO, i;
6593 - /* if forced media, go no further */
6594 - if (mii->force_media)
6596 + /* Enable managment port */
6597 + macb_writel(bp, NCR, MACB_BIT(MPE));
6599 - /* check current and old link status */
6600 - old_carrier = netif_carrier_ok(mii->dev) ? 1 : 0;
6601 - new_carrier = (unsigned int) mii_link_ok(mii);
6602 + bp->mii_bus.name = "MACB_mii_bus",
6603 + bp->mii_bus.read = &macb_mdio_read,
6604 + bp->mii_bus.write = &macb_mdio_write,
6605 + bp->mii_bus.reset = &macb_mdio_reset,
6606 + bp->mii_bus.id = bp->pdev->id,
6607 + bp->mii_bus.priv = bp,
6608 + bp->mii_bus.dev = &bp->dev->dev;
6609 + pdata = bp->pdev->dev.platform_data;
6611 - /* if carrier state did not change, assume nothing else did */
6612 - if (!init_media && old_carrier == new_carrier)
6615 + bp->mii_bus.phy_mask = pdata->phy_mask;
6617 - /* no carrier, nothing much to do */
6618 - if (!new_carrier) {
6619 - netif_carrier_off(mii->dev);
6620 - printk(KERN_INFO "%s: link down\n", mii->dev->name);
6622 + bp->mii_bus.irq = kmalloc(sizeof(int)*PHY_MAX_ADDR, GFP_KERNEL);
6623 + if (!bp->mii_bus.irq) {
6629 - * we have carrier, see who's on the other end
6631 - netif_carrier_on(mii->dev);
6632 + for (i = 0; i < PHY_MAX_ADDR; i++)
6633 + bp->mii_bus.irq[i] = PHY_POLL;
6635 - /* get MII advertise and LPA values */
6636 - if (!init_media && mii->advertising) {
6637 - advertise = mii->advertising;
6639 - advertise = mii->mdio_read(mii->dev, mii->phy_id, MII_ADVERTISE);
6640 - mii->advertising = advertise;
6642 - lpa = mii->mdio_read(mii->dev, mii->phy_id, MII_LPA);
6643 + platform_set_drvdata(bp->dev, &bp->mii_bus);
6645 - /* figure out media and duplex from advertise and LPA values */
6646 - media = mii_nway_result(lpa & advertise);
6647 - duplex = (media & ADVERTISE_FULL) ? 1 : 0;
6648 + if (mdiobus_register(&bp->mii_bus))
6649 + goto err_out_free_mdio_irq;
6652 - printk(KERN_INFO "%s: link up, %sMbps, %s-duplex, lpa 0x%04X\n",
6654 - media & (ADVERTISE_100FULL | ADVERTISE_100HALF) ? "100" : "10",
6655 - duplex ? "full" : "half", lpa);
6656 + if (macb_mii_probe(bp->dev) != 0) {
6657 + goto err_out_unregister_bus;
6660 - mii->full_duplex = duplex;
6663 - /* Let the MAC know about the new link state */
6664 - macb_set_media(bp, media);
6665 +err_out_unregister_bus:
6666 + mdiobus_unregister(&bp->mii_bus);
6667 +err_out_free_mdio_irq:
6668 + kfree(bp->mii_bus.irq);
6673 static void macb_update_stats(struct macb *bp)
6674 @@ -265,16 +296,6 @@
6675 *p += __raw_readl(reg);
6678 -static void macb_periodic_task(struct work_struct *work)
6680 - struct macb *bp = container_of(work, struct macb, periodic_task.work);
6682 - macb_update_stats(bp);
6683 - macb_check_media(bp, 1, 0);
6685 - schedule_delayed_work(&bp->periodic_task, HZ);
6688 static void macb_tx(struct macb *bp)
6692 spin_lock(&bp->lock);
6695 - if (status & MACB_BIT(MFD))
6696 - complete(&bp->mdio_complete);
6698 /* close possible race with dev_close */
6699 if (unlikely(!netif_running(dev))) {
6700 macb_writel(bp, IDR, ~0UL);
6702 * until we have processed the buffers
6704 macb_writel(bp, IDR, MACB_RX_INT_FLAGS);
6705 - dev_dbg(&bp->pdev->dev, "scheduling RX softirq\n");
6706 + dev_dbg(&bp->pdev->dev,
6707 + "scheduling RX softirq\n");
6708 __netif_rx_schedule(dev);
6712 macb_writel(bp, TBQP, bp->tx_ring_dma);
6714 /* Enable TX and RX */
6715 - macb_writel(bp, NCR, MACB_BIT(RE) | MACB_BIT(TE));
6716 + macb_writel(bp, NCR, MACB_BIT(RE) | MACB_BIT(TE) | MACB_BIT(MPE));
6718 /* Enable interrupts */
6719 macb_writel(bp, IER, (MACB_BIT(RCOMP)
6720 @@ -776,18 +795,7 @@
6722 | MACB_BIT(ISR_ROVR)
6723 | MACB_BIT(HRESP)));
6726 -static void macb_init_phy(struct net_device *dev)
6728 - struct macb *bp = netdev_priv(dev);
6730 - /* Set some reasonable default settings */
6731 - macb_mdio_write(dev, bp->mii.phy_id, MII_ADVERTISE,
6732 - ADVERTISE_CSMA | ADVERTISE_ALL);
6733 - macb_mdio_write(dev, bp->mii.phy_id, MII_BMCR,
6734 - (BMCR_SPEED100 | BMCR_ANENABLE
6735 - | BMCR_ANRESTART | BMCR_FULLDPLX));
6738 static int macb_open(struct net_device *dev)
6739 @@ -797,6 +805,10 @@
6741 dev_dbg(&bp->pdev->dev, "open\n");
6743 + /* if the phy is not yet register, retry later*/
6747 if (!is_valid_ether_addr(dev->dev_addr))
6748 return -EADDRNOTAVAIL;
6750 @@ -810,12 +822,11 @@
6752 macb_init_rings(bp);
6754 - macb_init_phy(dev);
6756 - macb_check_media(bp, 1, 1);
6757 - netif_start_queue(dev);
6758 + /* schedule a link state check */
6759 + phy_start(bp->phy_dev);
6761 - schedule_delayed_work(&bp->periodic_task, HZ);
6762 + netif_start_queue(dev);
6766 @@ -825,10 +836,11 @@
6767 struct macb *bp = netdev_priv(dev);
6768 unsigned long flags;
6770 - cancel_rearming_delayed_work(&bp->periodic_task);
6772 netif_stop_queue(dev);
6775 + phy_stop(bp->phy_dev);
6777 spin_lock_irqsave(&bp->lock, flags);
6779 netif_carrier_off(dev);
6781 struct net_device_stats *nstat = &bp->stats;
6782 struct macb_stats *hwstat = &bp->hw_stats;
6784 + /* read stats from hardware */
6785 + macb_update_stats(bp);
6787 /* Convert HW stats into netdevice stats */
6788 nstat->rx_errors = (hwstat->rx_fcs_errors +
6789 hwstat->rx_align_errors +
6790 @@ -882,18 +897,27 @@
6791 static int macb_get_settings(struct net_device *dev, struct ethtool_cmd *cmd)
6793 struct macb *bp = netdev_priv(dev);
6794 + struct phy_device *phydev = bp->phy_dev;
6796 - return mii_ethtool_gset(&bp->mii, cmd);
6800 + return phy_ethtool_gset(phydev, cmd);
6803 static int macb_set_settings(struct net_device *dev, struct ethtool_cmd *cmd)
6805 struct macb *bp = netdev_priv(dev);
6806 + struct phy_device *phydev = bp->phy_dev;
6811 - return mii_ethtool_sset(&bp->mii, cmd);
6812 + return phy_ethtool_sset(phydev, cmd);
6815 -static void macb_get_drvinfo(struct net_device *dev, struct ethtool_drvinfo *info)
6816 +static void macb_get_drvinfo(struct net_device *dev,
6817 + struct ethtool_drvinfo *info)
6819 struct macb *bp = netdev_priv(dev);
6821 @@ -902,104 +926,34 @@
6822 strcpy(info->bus_info, bp->pdev->dev.bus_id);
6825 -static int macb_nway_reset(struct net_device *dev)
6827 - struct macb *bp = netdev_priv(dev);
6828 - return mii_nway_restart(&bp->mii);
6831 static struct ethtool_ops macb_ethtool_ops = {
6832 .get_settings = macb_get_settings,
6833 .set_settings = macb_set_settings,
6834 .get_drvinfo = macb_get_drvinfo,
6835 - .nway_reset = macb_nway_reset,
6836 .get_link = ethtool_op_get_link,
6839 static int macb_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
6841 struct macb *bp = netdev_priv(dev);
6842 + struct phy_device *phydev = bp->phy_dev;
6844 if (!netif_running(dev))
6847 - return generic_mii_ioctl(&bp->mii, if_mii(rq), cmd, NULL);
6850 -static ssize_t macb_mii_show(const struct device *_dev, char *buf,
6851 - unsigned long addr)
6853 - struct net_device *dev = to_net_dev(_dev);
6854 - struct macb *bp = netdev_priv(dev);
6855 - ssize_t ret = -EINVAL;
6857 - if (netif_running(dev)) {
6859 - value = macb_mdio_read(dev, bp->mii.phy_id, addr);
6860 - ret = sprintf(buf, "0x%04x\n", (uint16_t)value);
6866 -#define MII_ENTRY(name, addr) \
6867 -static ssize_t show_##name(struct device *_dev, \
6868 - struct device_attribute *attr, \
6871 - return macb_mii_show(_dev, buf, addr); \
6873 -static DEVICE_ATTR(name, S_IRUGO, show_##name, NULL)
6875 -MII_ENTRY(bmcr, MII_BMCR);
6876 -MII_ENTRY(bmsr, MII_BMSR);
6877 -MII_ENTRY(physid1, MII_PHYSID1);
6878 -MII_ENTRY(physid2, MII_PHYSID2);
6879 -MII_ENTRY(advertise, MII_ADVERTISE);
6880 -MII_ENTRY(lpa, MII_LPA);
6881 -MII_ENTRY(expansion, MII_EXPANSION);
6883 -static struct attribute *macb_mii_attrs[] = {
6884 - &dev_attr_bmcr.attr,
6885 - &dev_attr_bmsr.attr,
6886 - &dev_attr_physid1.attr,
6887 - &dev_attr_physid2.attr,
6888 - &dev_attr_advertise.attr,
6889 - &dev_attr_lpa.attr,
6890 - &dev_attr_expansion.attr,
6894 -static struct attribute_group macb_mii_group = {
6896 - .attrs = macb_mii_attrs,
6899 -static void macb_unregister_sysfs(struct net_device *net)
6901 - struct device *_dev = &net->dev;
6905 - sysfs_remove_group(&_dev->kobj, &macb_mii_group);
6906 + return phy_mii_ioctl(phydev, if_mii(rq), cmd);
6909 -static int macb_register_sysfs(struct net_device *net)
6911 - struct device *_dev = &net->dev;
6914 - ret = sysfs_create_group(&_dev->kobj, &macb_mii_group);
6916 - printk(KERN_WARNING
6917 - "%s: sysfs mii attribute registration failed: %d\n",
6921 static int __devinit macb_probe(struct platform_device *pdev)
6923 struct eth_platform_data *pdata;
6924 struct resource *regs;
6925 struct net_device *dev;
6927 + struct phy_device *phydev;
6928 unsigned long pclk_hz;
6931 @@ -1080,10 +1034,6 @@
6933 dev->base_addr = regs->start;
6935 - INIT_DELAYED_WORK(&bp->periodic_task, macb_periodic_task);
6936 - mutex_init(&bp->mdio_mutex);
6937 - init_completion(&bp->mdio_complete);
6939 /* Set MII management clock divider */
6940 pclk_hz = clk_get_rate(bp->pclk);
6941 if (pclk_hz <= 20000000)
6942 @@ -1096,20 +1046,9 @@
6943 config = MACB_BF(CLK, MACB_CLK_DIV64);
6944 macb_writel(bp, NCFGR, config);
6946 - bp->mii.dev = dev;
6947 - bp->mii.mdio_read = macb_mdio_read;
6948 - bp->mii.mdio_write = macb_mdio_write;
6949 - bp->mii.phy_id_mask = 0x1f;
6950 - bp->mii.reg_num_mask = 0x1f;
6952 macb_get_hwaddr(bp);
6953 - err = macb_phy_probe(bp);
6955 - dev_err(&pdev->dev, "Failed to detect PHY, aborting.\n");
6956 - goto err_out_free_irq;
6959 pdata = pdev->dev.platform_data;
6961 if (pdata && pdata->is_rmii)
6962 #if defined(CONFIG_ARCH_AT91)
6963 macb_writel(bp, USRIO, (MACB_BIT(RMII) | MACB_BIT(CLKEN)) );
6964 @@ -1131,9 +1070,11 @@
6965 goto err_out_free_irq;
6968 - platform_set_drvdata(pdev, dev);
6969 + if (macb_mii_init(bp) != 0) {
6970 + goto err_out_unregister_netdev;
6973 - macb_register_sysfs(dev);
6974 + platform_set_drvdata(pdev, dev);
6976 printk(KERN_INFO "%s: Atmel MACB at 0x%08lx irq %d "
6977 "(%02x:%02x:%02x:%02x:%02x:%02x)\n",
6978 @@ -1141,8 +1082,15 @@
6979 dev->dev_addr[0], dev->dev_addr[1], dev->dev_addr[2],
6980 dev->dev_addr[3], dev->dev_addr[4], dev->dev_addr[5]);
6982 + phydev = bp->phy_dev;
6983 + printk(KERN_INFO "%s: attached PHY driver [%s] "
6984 + "(mii_bus:phy_addr=%s, irq=%d)\n",
6985 + dev->name, phydev->drv->name, phydev->dev.bus_id, phydev->irq);
6989 +err_out_unregister_netdev:
6990 + unregister_netdev(dev);
6992 free_irq(dev->irq, dev);
6994 @@ -1153,7 +1101,9 @@
6997 clk_disable(bp->pclk);
6998 +#ifndef CONFIG_ARCH_AT91
7004 @@ -1171,7 +1121,8 @@
7007 bp = netdev_priv(dev);
7008 - macb_unregister_sysfs(dev);
7009 + mdiobus_unregister(&bp->mii_bus);
7010 + kfree(bp->mii_bus.irq);
7011 unregister_netdev(dev);
7012 free_irq(dev->irq, dev);
7014 diff -x .git -Nur linux-2.6.22.1/drivers/net/macb.h linux-avr32.git/drivers/net/macb.h
7015 --- linux-2.6.22.1/drivers/net/macb.h 2007-07-10 20:56:30.000000000 +0200
7016 +++ linux-avr32.git/drivers/net/macb.h 2007-07-12 14:00:04.000000000 +0200
7017 @@ -383,11 +383,11 @@
7019 unsigned int rx_pending, tx_pending;
7021 - struct delayed_work periodic_task;
7023 - struct mutex mdio_mutex;
7024 - struct completion mdio_complete;
7025 - struct mii_if_info mii;
7026 + struct mii_bus mii_bus;
7027 + struct phy_device *phy_dev;
7028 + unsigned int link;
7029 + unsigned int speed;
7030 + unsigned int duplex;
7033 #endif /* _MACB_H */
7034 diff -x .git -Nur linux-2.6.22.1/drivers/rtc/Kconfig linux-avr32.git/drivers/rtc/Kconfig
7035 --- linux-2.6.22.1/drivers/rtc/Kconfig 2007-07-10 20:56:30.000000000 +0200
7036 +++ linux-avr32.git/drivers/rtc/Kconfig 2007-07-12 14:00:13.000000000 +0200
7037 @@ -379,6 +379,13 @@
7038 To compile this driver as a module, choose M here: the
7039 module will be called rtc-pl031.
7041 +config RTC_DRV_AT32AP700X
7042 + tristate "AT32AP700X series RTC"
7043 + depends on RTC_CLASS && PLATFORM_AT32AP
7045 + Driver for the internal RTC (Realtime Clock) on Atmel AVR32
7046 + AT32AP700x family processors.
7048 config RTC_DRV_AT91RM9200
7049 tristate "AT91RM9200"
7050 depends on RTC_CLASS && ARCH_AT91RM9200
7051 diff -x .git -Nur linux-2.6.22.1/drivers/rtc/Makefile linux-avr32.git/drivers/rtc/Makefile
7052 --- linux-2.6.22.1/drivers/rtc/Makefile 2007-07-10 20:56:30.000000000 +0200
7053 +++ linux-avr32.git/drivers/rtc/Makefile 2007-07-12 14:00:13.000000000 +0200
7055 obj-$(CONFIG_RTC_DRV_X1205) += rtc-x1205.o
7056 obj-$(CONFIG_RTC_DRV_ISL1208) += rtc-isl1208.o
7057 obj-$(CONFIG_RTC_DRV_TEST) += rtc-test.o
7058 +obj-$(CONFIG_RTC_DRV_AT32AP700X) += rtc-at32ap700x.o
7059 obj-$(CONFIG_RTC_DRV_DS1307) += rtc-ds1307.o
7060 obj-$(CONFIG_RTC_DRV_DS1672) += rtc-ds1672.o
7061 obj-$(CONFIG_RTC_DRV_DS1742) += rtc-ds1742.o
7062 diff -x .git -Nur linux-2.6.22.1/drivers/rtc/rtc-at32ap700x.c linux-avr32.git/drivers/rtc/rtc-at32ap700x.c
7063 --- linux-2.6.22.1/drivers/rtc/rtc-at32ap700x.c 1970-01-01 01:00:00.000000000 +0100
7064 +++ linux-avr32.git/drivers/rtc/rtc-at32ap700x.c 2007-07-12 14:00:13.000000000 +0200
7067 + * An RTC driver for the AVR32 AT32AP700x processor series.
7069 + * Copyright (C) 2007 Atmel Corporation
7071 + * This program is free software; you can redistribute it and/or modify it
7072 + * under the terms of the GNU General Public License version 2 as published
7073 + * by the Free Software Foundation.
7076 +#include <linux/module.h>
7077 +#include <linux/kernel.h>
7078 +#include <linux/platform_device.h>
7079 +#include <linux/rtc.h>
7080 +#include <linux/io.h>
7083 + * This is a bare-bones RTC. It runs during most system sleep states, but has
7084 + * no battery backup and gets reset during system restart. It must be
7085 + * initialized from an external clock (network, I2C, etc) before it can be of
7088 + * The alarm functionality is limited by the hardware, not supporting
7089 + * periodic interrupts.
7092 +#define RTC_CTRL 0x00
7093 +#define RTC_CTRL_EN 0
7094 +#define RTC_CTRL_PCLR 1
7095 +#define RTC_CTRL_TOPEN 2
7096 +#define RTC_CTRL_PSEL 8
7098 +#define RTC_VAL 0x04
7100 +#define RTC_TOP 0x08
7102 +#define RTC_IER 0x10
7103 +#define RTC_IER_TOPI 0
7105 +#define RTC_IDR 0x14
7106 +#define RTC_IDR_TOPI 0
7108 +#define RTC_IMR 0x18
7109 +#define RTC_IMR_TOPI 0
7111 +#define RTC_ISR 0x1c
7112 +#define RTC_ISR_TOPI 0
7114 +#define RTC_ICR 0x20
7115 +#define RTC_ICR_TOPI 0
7117 +#define RTC_BIT(name) (1 << RTC_##name)
7118 +#define RTC_BF(name, value) ((value) << RTC_##name)
7120 +#define rtc_readl(dev, reg) \
7121 + __raw_readl((dev)->regs + RTC_##reg)
7122 +#define rtc_writel(dev, reg, value) \
7123 + __raw_writel((value), (dev)->regs + RTC_##reg)
7125 +struct rtc_at32ap700x {
7126 + struct rtc_device *rtc;
7127 + void __iomem *regs;
7128 + unsigned long alarm_time;
7129 + unsigned long irq;
7130 + /* Protect against concurrent register access. */
7134 +static int at32_rtc_readtime(struct device *dev, struct rtc_time *tm)
7136 + struct rtc_at32ap700x *rtc = dev_get_drvdata(dev);
7137 + unsigned long now;
7139 + now = rtc_readl(rtc, VAL);
7140 + rtc_time_to_tm(now, tm);
7145 +static int at32_rtc_settime(struct device *dev, struct rtc_time *tm)
7147 + struct rtc_at32ap700x *rtc = dev_get_drvdata(dev);
7148 + unsigned long now;
7151 + ret = rtc_tm_to_time(tm, &now);
7153 + rtc_writel(rtc, VAL, now);
7158 +static int at32_rtc_readalarm(struct device *dev, struct rtc_wkalrm *alrm)
7160 + struct rtc_at32ap700x *rtc = dev_get_drvdata(dev);
7162 + rtc_time_to_tm(rtc->alarm_time, &alrm->time);
7163 + alrm->pending = rtc_readl(rtc, IMR) & RTC_BIT(IMR_TOPI) ? 1 : 0;
7168 +static int at32_rtc_setalarm(struct device *dev, struct rtc_wkalrm *alrm)
7170 + struct rtc_at32ap700x *rtc = dev_get_drvdata(dev);
7171 + unsigned long rtc_unix_time;
7172 + unsigned long alarm_unix_time;
7175 + rtc_unix_time = rtc_readl(rtc, VAL);
7177 + /* RTC does only support one alarm time, not periodic */
7178 + if (alrm->time.tm_mday <= 0) {
7179 + struct rtc_time tm;
7180 + unsigned long then;
7182 + rtc_time_to_tm(rtc_unix_time, &tm);
7184 + alrm->time.tm_mday = tm.tm_mday;
7185 + alrm->time.tm_mon = tm.tm_mon;
7186 + alrm->time.tm_year = tm.tm_year;
7188 + rtc_tm_to_time(&alrm->time, &then);
7190 + /* check if the alarm wraps into tomorrow */
7191 + if (then < rtc_unix_time) {
7192 + rtc_time_to_tm(rtc_unix_time + 24 * 60 * 60, &tm);
7193 + alrm->time.tm_mday = tm.tm_mday;
7194 + alrm->time.tm_mon = tm.tm_mon;
7195 + alrm->time.tm_year = tm.tm_year;
7199 + ret = rtc_tm_to_time(&alrm->time, &alarm_unix_time);
7203 + if (alarm_unix_time < rtc_unix_time)
7206 + spin_lock_irq(&rtc->lock);
7207 + rtc->alarm_time = alarm_unix_time;
7208 + rtc_writel(rtc, TOP, rtc->alarm_time);
7209 + if (alrm->pending)
7210 + rtc_writel(rtc, CTRL, rtc_readl(rtc, CTRL)
7211 + | RTC_BIT(CTRL_TOPEN));
7213 + rtc_writel(rtc, CTRL, rtc_readl(rtc, CTRL)
7214 + & ~RTC_BIT(CTRL_TOPEN));
7215 + spin_unlock_irq(&rtc->lock);
7220 +static int at32_rtc_ioctl(struct device *dev, unsigned int cmd,
7221 + unsigned long arg)
7223 + struct rtc_at32ap700x *rtc = dev_get_drvdata(dev);
7226 + spin_lock_irq(&rtc->lock);
7230 + if (rtc_readl(rtc, VAL) > rtc->alarm_time) {
7234 + rtc_writel(rtc, CTRL, rtc_readl(rtc, CTRL)
7235 + | RTC_BIT(CTRL_TOPEN));
7236 + rtc_writel(rtc, ICR, RTC_BIT(ICR_TOPI));
7237 + rtc_writel(rtc, IER, RTC_BIT(IER_TOPI));
7240 + rtc_writel(rtc, CTRL, rtc_readl(rtc, CTRL)
7241 + & ~RTC_BIT(CTRL_TOPEN));
7242 + rtc_writel(rtc, IDR, RTC_BIT(IDR_TOPI));
7243 + rtc_writel(rtc, ICR, RTC_BIT(ICR_TOPI));
7246 + ret = -ENOIOCTLCMD;
7250 + spin_unlock_irq(&rtc->lock);
7255 +static irqreturn_t at32_rtc_interrupt(int irq, void *dev_id)
7257 + struct rtc_at32ap700x *rtc = (struct rtc_at32ap700x *)dev_id;
7258 + unsigned long isr = rtc_readl(rtc, ISR);
7259 + unsigned long events = 0;
7260 + int ret = IRQ_NONE;
7262 + spin_lock(&rtc->lock);
7264 + if (isr & RTC_BIT(ISR_TOPI)) {
7265 + rtc_writel(rtc, ICR, RTC_BIT(ICR_TOPI));
7266 + rtc_writel(rtc, IDR, RTC_BIT(IDR_TOPI));
7267 + rtc_writel(rtc, CTRL, rtc_readl(rtc, CTRL)
7268 + & ~RTC_BIT(CTRL_TOPEN));
7269 + rtc_writel(rtc, VAL, rtc->alarm_time);
7270 + events = RTC_AF | RTC_IRQF;
7271 + rtc_update_irq(rtc->rtc, 1, events);
7272 + ret = IRQ_HANDLED;
7275 + spin_unlock(&rtc->lock);
7280 +static struct rtc_class_ops at32_rtc_ops = {
7281 + .ioctl = at32_rtc_ioctl,
7282 + .read_time = at32_rtc_readtime,
7283 + .set_time = at32_rtc_settime,
7284 + .read_alarm = at32_rtc_readalarm,
7285 + .set_alarm = at32_rtc_setalarm,
7288 +static int __init at32_rtc_probe(struct platform_device *pdev)
7290 + struct resource *regs;
7291 + struct rtc_at32ap700x *rtc;
7295 + rtc = kzalloc(sizeof(struct rtc_at32ap700x), GFP_KERNEL);
7297 + dev_dbg(&pdev->dev, "out of memory\n");
7301 + regs = platform_get_resource(pdev, IORESOURCE_MEM, 0);
7303 + dev_dbg(&pdev->dev, "no mmio resource defined\n");
7308 + irq = platform_get_irq(pdev, 0);
7310 + dev_dbg(&pdev->dev, "could not get irq\n");
7315 + ret = request_irq(irq, at32_rtc_interrupt, IRQF_SHARED, "rtc", rtc);
7317 + dev_dbg(&pdev->dev, "could not request irq %d\n", irq);
7322 + rtc->regs = ioremap(regs->start, regs->end - regs->start + 1);
7325 + dev_dbg(&pdev->dev, "could not map I/O memory\n");
7326 + goto out_free_irq;
7328 + spin_lock_init(&rtc->lock);
7331 + * Maybe init RTC: count from zero at 1 Hz, disable wrap irq.
7333 + * Do not reset VAL register, as it can hold an old time
7334 + * from last JTAG reset.
7336 + if (!(rtc_readl(rtc, CTRL) & RTC_BIT(CTRL_EN))) {
7337 + rtc_writel(rtc, CTRL, RTC_BIT(CTRL_PCLR));
7338 + rtc_writel(rtc, IDR, RTC_BIT(IDR_TOPI));
7339 + rtc_writel(rtc, CTRL, RTC_BF(CTRL_PSEL, 0xe)
7340 + | RTC_BIT(CTRL_EN));
7343 + rtc->rtc = rtc_device_register(pdev->name, &pdev->dev,
7344 + &at32_rtc_ops, THIS_MODULE);
7345 + if (IS_ERR(rtc->rtc)) {
7346 + dev_dbg(&pdev->dev, "could not register rtc device\n");
7347 + ret = PTR_ERR(rtc->rtc);
7351 + platform_set_drvdata(pdev, rtc);
7353 + dev_info(&pdev->dev, "Atmel RTC for AT32AP700x at %08lx irq %ld\n",
7354 + (unsigned long)rtc->regs, rtc->irq);
7359 + iounmap(rtc->regs);
7361 + free_irq(irq, rtc);
7367 +static int __exit at32_rtc_remove(struct platform_device *pdev)
7369 + struct rtc_at32ap700x *rtc = platform_get_drvdata(pdev);
7371 + free_irq(rtc->irq, rtc);
7372 + iounmap(rtc->regs);
7373 + rtc_device_unregister(rtc->rtc);
7375 + platform_set_drvdata(pdev, NULL);
7380 +static struct platform_driver at32_rtc_driver = {
7381 + .remove = __exit_p(at32_rtc_remove),
7383 + .name = "rtc-at32ap700x",
7384 + .owner = THIS_MODULE,
7388 +static int __init at32_rtc_init(void)
7390 + return platform_driver_probe(&at32_rtc_driver, at32_rtc_probe);
7392 +module_init(at32_rtc_init);
7394 +static void __exit at32_rtc_exit(void)
7396 + platform_driver_unregister(&at32_rtc_driver);
7398 +module_exit(at32_rtc_exit);
7400 +MODULE_AUTHOR("Hans-Christian Egtvedt <hcegtvedt@atmel.com>");
7401 +MODULE_DESCRIPTION("Real time clock for AVR32 AT32AP700x");
7402 +MODULE_LICENSE("GPL");
7403 diff -x .git -Nur linux-2.6.22.1/drivers/serial/atmel_serial.c linux-avr32.git/drivers/serial/atmel_serial.c
7404 --- linux-2.6.22.1/drivers/serial/atmel_serial.c 2007-07-10 20:56:30.000000000 +0200
7405 +++ linux-avr32.git/drivers/serial/atmel_serial.c 2007-06-06 11:33:59.000000000 +0200
7407 struct uart_port uart; /* uart */
7408 struct clk *clk; /* uart clock */
7409 unsigned short suspended; /* is port suspended? */
7410 + int break_active; /* break being received */
7413 static struct atmel_uart_port atmel_ports[ATMEL_MAX_UART];
7416 static void atmel_rx_chars(struct uart_port *port)
7418 + struct atmel_uart_port *atmel_port = (struct atmel_uart_port *) port;
7419 struct tty_struct *tty = port->info->tty;
7420 unsigned int status, ch, flg;
7422 @@ -267,13 +269,29 @@
7423 * note that the error handling code is
7424 * out of the main execution path
7426 - if (unlikely(status & (ATMEL_US_PARE | ATMEL_US_FRAME | ATMEL_US_OVRE | ATMEL_US_RXBRK))) {
7427 + if (unlikely(status & (ATMEL_US_PARE | ATMEL_US_FRAME
7428 + | ATMEL_US_OVRE | ATMEL_US_RXBRK)
7429 + || atmel_port->break_active)) {
7430 UART_PUT_CR(port, ATMEL_US_RSTSTA); /* clear error */
7431 - if (status & ATMEL_US_RXBRK) {
7432 + if (status & ATMEL_US_RXBRK
7433 + && !atmel_port->break_active) {
7434 status &= ~(ATMEL_US_PARE | ATMEL_US_FRAME); /* ignore side-effect */
7436 + atmel_port->break_active = 1;
7437 + UART_PUT_IER(port, ATMEL_US_RXBRK);
7438 if (uart_handle_break(port))
7442 + * This is either the end-of-break
7443 + * condition or we've received at
7444 + * least one character without RXBRK
7445 + * being set. In both cases, the next
7446 + * RXBRK will indicate start-of-break.
7448 + UART_PUT_IDR(port, ATMEL_US_RXBRK);
7449 + status &= ~ATMEL_US_RXBRK;
7450 + atmel_port->break_active = 0;
7452 if (status & ATMEL_US_PARE)
7453 port->icount.parity++;
7454 @@ -352,6 +370,16 @@
7455 /* Interrupt receive */
7456 if (pending & ATMEL_US_RXRDY)
7457 atmel_rx_chars(port);
7458 + else if (pending & ATMEL_US_RXBRK) {
7460 + * End of break detected. If it came along
7461 + * with a character, atmel_rx_chars will
7464 + UART_PUT_CR(port, ATMEL_US_RSTSTA);
7465 + UART_PUT_IDR(port, ATMEL_US_RXBRK);
7466 + atmel_port->break_active = 0;
7469 // TODO: All reads to CSR will clear these interrupts!
7470 if (pending & ATMEL_US_RIIC) port->icount.rng++;
7471 diff -x .git -Nur linux-2.6.22.1/drivers/spi/atmel_spi.c linux-avr32.git/drivers/spi/atmel_spi.c
7472 --- linux-2.6.22.1/drivers/spi/atmel_spi.c 2007-07-10 20:56:30.000000000 +0200
7473 +++ linux-avr32.git/drivers/spi/atmel_spi.c 2007-06-06 11:33:59.000000000 +0200
7475 csr |= SPI_BIT(NCPHA);
7477 /* TODO: DLYBS and DLYBCT */
7478 - csr |= SPI_BF(DLYBS, 10);
7479 - csr |= SPI_BF(DLYBCT, 10);
7480 + csr |= SPI_BF(DLYBS, 0);
7481 + csr |= SPI_BF(DLYBCT, 0);
7483 /* chipselect must have been muxed as GPIO (e.g. in board setup) */
7484 npcs_pin = (unsigned int)spi->controller_data;
7485 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
7486 --- linux-2.6.22.1/drivers/usb/gadget/atmel_usba_udc.c 1970-01-01 01:00:00.000000000 +0100
7487 +++ linux-avr32.git/drivers/usb/gadget/atmel_usba_udc.c 2007-07-12 14:00:19.000000000 +0200
7490 + * Driver for the Atmel USBA high speed USB device controller
7492 + * Copyright (C) 2005-2007 Atmel Corporation
7494 + * This program is free software; you can redistribute it and/or modify
7495 + * it under the terms of the GNU General Public License version 2 as
7496 + * published by the Free Software Foundation.
7498 +/* #define DEBUG */
7500 +#include <linux/clk.h>
7501 +#include <linux/module.h>
7502 +#include <linux/init.h>
7503 +#include <linux/interrupt.h>
7504 +#include <linux/io.h>
7505 +#include <linux/device.h>
7506 +#include <linux/dma-mapping.h>
7507 +#include <linux/list.h>
7508 +#include <linux/platform_device.h>
7509 +#include <linux/usb/ch9.h>
7510 +#include <linux/usb_gadget.h>
7511 +#include <linux/delay.h>
7513 +#include <asm/gpio.h>
7514 +#include <asm/arch/board.h>
7516 +#include "atmel_usba_udc.h"
7518 +#define DMA_ADDR_INVALID (~(dma_addr_t)0)
7520 +#define FIFO_IOMEM_ID 0
7521 +#define CTRL_IOMEM_ID 1
7524 +#define DBG_ERR 0x0001 /* report all error returns */
7525 +#define DBG_HW 0x0002 /* debug hardware initialization */
7526 +#define DBG_GADGET 0x0004 /* calls to/from gadget driver */
7527 +#define DBG_INT 0x0008 /* interrupts */
7528 +#define DBG_BUS 0x0010 /* report changes in bus state */
7529 +#define DBG_QUEUE 0x0020 /* debug request queue processing */
7530 +#define DBG_FIFO 0x0040 /* debug FIFO contents */
7531 +#define DBG_DMA 0x0080 /* debug DMA handling */
7532 +#define DBG_REQ 0x0100 /* print out queued request length */
7533 +#define DBG_ALL 0xffff
7534 +#define DBG_NONE 0x0000
7536 +#define DEBUG_LEVEL (DBG_ERR)
7537 +#define DBG(level, fmt, ...) \
7539 + if ((level) & DEBUG_LEVEL) \
7540 + printk(KERN_DEBUG "udc: " fmt, ## __VA_ARGS__); \
7543 +#define DBG(level, fmt...)
7546 +static struct usba_udc the_udc;
7548 +#ifdef CONFIG_DEBUG_FS
7549 +#include <linux/debugfs.h>
7550 +#include <linux/uaccess.h>
7552 +static int queue_dbg_open(struct inode *inode, struct file *file)
7554 + struct usba_ep *ep = inode->i_private;
7555 + struct usba_request *req, *req_copy;
7556 + struct list_head *queue_data;
7558 + queue_data = kmalloc(sizeof(*queue_data), GFP_KERNEL);
7561 + INIT_LIST_HEAD(queue_data);
7563 + spin_lock_irq(&ep->udc->lock);
7564 + list_for_each_entry(req, &ep->queue, queue) {
7565 + req_copy = kmalloc(sizeof(*req_copy), GFP_ATOMIC);
7568 + memcpy(req_copy, req, sizeof(*req_copy));
7569 + list_add_tail(&req_copy->queue, queue_data);
7571 + spin_unlock_irq(&ep->udc->lock);
7573 + file->private_data = queue_data;
7577 + spin_unlock_irq(&ep->udc->lock);
7578 + list_for_each_entry_safe(req, req_copy, queue_data, queue) {
7579 + list_del(&req->queue);
7582 + kfree(queue_data);
7587 + * bbbbbbbb llllllll IZS sssss nnnn FDL\n\0
7589 + * b: buffer address
7590 + * l: buffer length
7591 + * I/i: interrupt/no interrupt
7592 + * Z/z: zero/no zero
7593 + * S/s: short ok/short not ok
7596 + * F/f: submitted/not submitted to FIFO
7597 + * D/d: using/not using DMA
7598 + * L/l: last transaction/not last transaction
7600 +static ssize_t queue_dbg_read(struct file *file, char __user *buf,
7601 + size_t nbytes, loff_t *ppos)
7603 + struct list_head *queue = file->private_data;
7604 + struct usba_request *req, *tmp_req;
7605 + size_t len, remaining, actual = 0;
7608 + if (!access_ok(VERIFY_WRITE, buf, nbytes))
7611 + mutex_lock(&file->f_dentry->d_inode->i_mutex);
7612 + list_for_each_entry_safe(req, tmp_req, queue, queue) {
7613 + len = snprintf(tmpbuf, sizeof(tmpbuf),
7614 + "%8p %08x %c%c%c %5d %c%c%c\n",
7615 + req->req.buf, req->req.length,
7616 + req->req.no_interrupt ? 'i' : 'I',
7617 + req->req.zero ? 'Z' : 'z',
7618 + req->req.short_not_ok ? 's' : 'S',
7620 + req->submitted ? 'F' : 'f',
7621 + req->using_dma ? 'D' : 'd',
7622 + req->last_transaction ? 'L' : 'l');
7623 + len = min(len, sizeof(tmpbuf));
7627 + list_del(&req->queue);
7630 + remaining = __copy_to_user(buf, tmpbuf, len);
7631 + actual += len - remaining;
7638 + mutex_unlock(&file->f_dentry->d_inode->i_mutex);
7643 +static int queue_dbg_release(struct inode *inode, struct file *file)
7645 + struct list_head *queue_data = file->private_data;
7646 + struct usba_request *req, *tmp_req;
7648 + list_for_each_entry_safe(req, tmp_req, queue_data, queue) {
7649 + list_del(&req->queue);
7652 + kfree(queue_data);
7656 +static int regs_dbg_open(struct inode *inode, struct file *file)
7658 + struct usba_udc *udc;
7661 + int ret = -ENOMEM;
7663 + mutex_lock(&inode->i_mutex);
7664 + udc = inode->i_private;
7665 + data = kmalloc(inode->i_size, GFP_KERNEL);
7669 + spin_lock_irq(&udc->lock);
7670 + for (i = 0; i < inode->i_size / 4; i++)
7671 + data[i] = __raw_readl(udc->regs + i * 4);
7672 + spin_unlock_irq(&udc->lock);
7674 + file->private_data = data;
7678 + mutex_unlock(&inode->i_mutex);
7683 +static ssize_t regs_dbg_read(struct file *file, char __user *buf,
7684 + size_t nbytes, loff_t *ppos)
7686 + struct inode *inode = file->f_dentry->d_inode;
7689 + mutex_lock(&inode->i_mutex);
7690 + ret = simple_read_from_buffer(buf, nbytes, ppos,
7691 + file->private_data,
7692 + file->f_dentry->d_inode->i_size);
7693 + mutex_unlock(&inode->i_mutex);
7698 +static int regs_dbg_release(struct inode *inode, struct file *file)
7700 + kfree(file->private_data);
7704 +const struct file_operations queue_dbg_fops = {
7705 + .owner = THIS_MODULE,
7706 + .open = queue_dbg_open,
7707 + .llseek = no_llseek,
7708 + .read = queue_dbg_read,
7709 + .release = queue_dbg_release,
7712 +const struct file_operations regs_dbg_fops = {
7713 + .owner = THIS_MODULE,
7714 + .open = regs_dbg_open,
7715 + .llseek = generic_file_llseek,
7716 + .read = regs_dbg_read,
7717 + .release = regs_dbg_release,
7720 +static void usba_ep_init_debugfs(struct usba_udc *udc,
7721 + struct usba_ep *ep)
7723 + struct dentry *ep_root;
7725 + ep_root = debugfs_create_dir(ep_name(ep), udc->debugfs_root);
7728 + ep->debugfs_dir = ep_root;
7730 + ep->debugfs_queue = debugfs_create_file("queue", 0400, ep_root,
7731 + ep, &queue_dbg_fops);
7732 + if (!ep->debugfs_queue)
7735 + if (ep_can_dma(ep)) {
7736 + ep->debugfs_dma_status
7737 + = debugfs_create_u32("dma_status", 0400, ep_root,
7738 + &ep->last_dma_status);
7739 + if (!ep->debugfs_dma_status)
7740 + goto err_dma_status;
7742 + if (ep_is_control(ep)) {
7744 + = debugfs_create_u32("state", 0400, ep_root,
7746 + if (!ep->debugfs_state)
7753 + if (ep_can_dma(ep))
7754 + debugfs_remove(ep->debugfs_dma_status);
7756 + debugfs_remove(ep->debugfs_queue);
7758 + debugfs_remove(ep_root);
7760 + dev_err(&ep->udc->pdev->dev,
7761 + "failed to create debugfs directory for %s\n", ep_name(ep));
7764 +static void usba_ep_cleanup_debugfs(struct usba_ep *ep)
7766 + debugfs_remove(ep->debugfs_queue);
7767 + debugfs_remove(ep->debugfs_dma_status);
7768 + debugfs_remove(ep->debugfs_state);
7769 + debugfs_remove(ep->debugfs_dir);
7770 + ep->debugfs_dma_status = NULL;
7771 + ep->debugfs_dir = NULL;
7774 +static void usba_init_debugfs(struct usba_udc *udc)
7776 + struct dentry *root, *regs;
7777 + struct resource *regs_resource;
7779 + root = debugfs_create_dir(udc->gadget.name, NULL);
7780 + if (IS_ERR(root) || !root)
7782 + udc->debugfs_root = root;
7784 + regs = debugfs_create_file("regs", 0400, root, udc, ®s_dbg_fops);
7788 + regs_resource = platform_get_resource(udc->pdev, IORESOURCE_MEM,
7790 + regs->d_inode->i_size = regs_resource->end - regs_resource->start + 1;
7791 + udc->debugfs_regs = regs;
7793 + usba_ep_init_debugfs(udc, to_usba_ep(udc->gadget.ep0));
7798 + debugfs_remove(root);
7800 + udc->debugfs_root = NULL;
7801 + dev_err(&udc->pdev->dev, "debugfs is not available\n");
7804 +static void usba_cleanup_debugfs(struct usba_udc *udc)
7806 + usba_ep_cleanup_debugfs(to_usba_ep(udc->gadget.ep0));
7807 + debugfs_remove(udc->debugfs_regs);
7808 + debugfs_remove(udc->debugfs_root);
7809 + udc->debugfs_regs = NULL;
7810 + udc->debugfs_root = NULL;
7813 +static inline void usba_ep_init_debugfs(struct usba_udc *udc,
7814 + struct usba_ep *ep)
7819 +static inline void usba_ep_cleanup_debugfs(struct usba_ep *ep)
7824 +static inline void usba_init_debugfs(struct usba_udc *udc)
7829 +static inline void usba_cleanup_debugfs(struct usba_udc *udc)
7835 +static int vbus_is_present(struct usba_udc *udc)
7837 + if (udc->vbus_pin != -1)
7838 + return gpio_get_value(udc->vbus_pin);
7840 + /* No Vbus detection: Assume always present */
7844 +static void copy_to_fifo(void __iomem *fifo, const void *buf, int len)
7846 + unsigned long tmp;
7848 + DBG(DBG_FIFO, "copy to FIFO (len %d):\n", len);
7849 + for (; len > 0; len -= 4, buf += 4, fifo += 4) {
7850 + tmp = *(unsigned long *)buf;
7852 + DBG(DBG_FIFO, " -> %08lx\n", tmp);
7853 + __raw_writel(tmp, fifo);
7856 + DBG(DBG_FIFO, " -> %02lx\n", tmp >> 24);
7857 + __raw_writeb(tmp >> 24, fifo);
7866 +static void copy_from_fifo(void *buf, void __iomem *fifo, int len)
7872 + unsigned long tmp;
7874 + DBG(DBG_FIFO, "copy from FIFO (len %d):\n", len);
7875 + for (p.w = buf; len > 0; len -= 4, p.w++, fifo += 4) {
7877 + tmp = __raw_readl(fifo);
7879 + DBG(DBG_FIFO, " -> %08lx\n", tmp);
7882 + tmp = __raw_readb(fifo);
7884 + DBG(DBG_FIFO, " -> %02lx\n", tmp);
7891 +static void next_fifo_transaction(struct usba_ep *ep,
7892 + struct usba_request *req)
7894 + unsigned int transaction_len;
7896 + transaction_len = req->req.length - req->req.actual;
7897 + req->last_transaction = 1;
7898 + if (transaction_len > ep->ep.maxpacket) {
7899 + transaction_len = ep->ep.maxpacket;
7900 + req->last_transaction = 0;
7901 + } else if (transaction_len == ep->ep.maxpacket
7902 + && req->req.zero) {
7903 + req->last_transaction = 0;
7905 + DBG(DBG_QUEUE, "%s: submit_transaction, req %p (length %d)%s\n",
7906 + ep_name(ep), req, transaction_len,
7907 + req->last_transaction ? ", done" : "");
7909 + copy_to_fifo(ep->fifo, req->req.buf + req->req.actual, transaction_len);
7910 + usba_ep_writel(ep, SET_STA, USBA_BIT(TX_PK_RDY));
7911 + req->req.actual += transaction_len;
7914 +static void submit_request(struct usba_ep *ep, struct usba_request *req)
7916 + DBG(DBG_QUEUE, "%s: submit_request: req %p (length %d)\n",
7917 + ep_name(ep), req, req->req.length);
7919 + req->req.actual = 0;
7920 + req->submitted = 1;
7922 + if (req->using_dma) {
7923 + if (req->req.length == 0) {
7924 + usba_ep_writel(ep, CTL_ENB, USBA_BIT(TX_PK_RDY));
7928 + if (req->req.zero)
7929 + usba_ep_writel(ep, CTL_ENB, USBA_BIT(SHORT_PACKET));
7931 + usba_ep_writel(ep, CTL_DIS, USBA_BIT(SHORT_PACKET));
7933 + usba_dma_writel(ep, ADDRESS, req->req.dma);
7934 + usba_dma_writel(ep, CONTROL, req->ctrl);
7936 + next_fifo_transaction(ep, req);
7937 + if (req->last_transaction) {
7938 + usba_ep_writel(ep, CTL_DIS, USBA_BIT(TX_PK_RDY));
7939 + usba_ep_writel(ep, CTL_ENB, USBA_BIT(TX_COMPLETE));
7941 + usba_ep_writel(ep, CTL_DIS, USBA_BIT(TX_COMPLETE));
7942 + usba_ep_writel(ep, CTL_ENB, USBA_BIT(TX_PK_RDY));
7947 +static void submit_next_request(struct usba_ep *ep)
7949 + struct usba_request *req;
7951 + if (list_empty(&ep->queue)) {
7952 + usba_ep_writel(ep, CTL_DIS, (USBA_BIT(TX_PK_RDY)
7953 + | USBA_BIT(RX_BK_RDY)));
7957 + req = list_entry(ep->queue.next, struct usba_request, queue);
7958 + if (!req->submitted)
7959 + submit_request(ep, req);
7962 +static void send_status(struct usba_udc *udc, struct usba_ep *ep)
7964 + ep->state = STATUS_STAGE_IN;
7965 + usba_ep_writel(ep, SET_STA, USBA_BIT(TX_PK_RDY));
7966 + usba_ep_writel(ep, CTL_ENB, USBA_BIT(TX_COMPLETE));
7969 +static void receive_data(struct usba_ep *ep)
7971 + struct usba_udc *udc = ep->udc;
7972 + struct usba_request *req;
7973 + unsigned long status;
7974 + unsigned int bytecount, nr_busy;
7975 + int is_complete = 0;
7977 + status = usba_ep_readl(ep, STA);
7978 + nr_busy = USBA_BFEXT(BUSY_BANKS, status);
7980 + DBG(DBG_QUEUE, "receive data: nr_busy=%u\n", nr_busy);
7982 + while (nr_busy > 0) {
7983 + if (list_empty(&ep->queue)) {
7984 + usba_ep_writel(ep, CTL_DIS, USBA_BIT(RX_BK_RDY));
7987 + req = list_entry(ep->queue.next,
7988 + struct usba_request, queue);
7990 + bytecount = USBA_BFEXT(BYTE_COUNT, status);
7992 + if (status & (1 << 31))
7994 + if (req->req.actual + bytecount >= req->req.length) {
7996 + bytecount = req->req.length - req->req.actual;
7999 + copy_from_fifo(req->req.buf + req->req.actual,
8000 + ep->fifo, bytecount);
8001 + req->req.actual += bytecount;
8003 + usba_ep_writel(ep, CLR_STA, USBA_BIT(RX_BK_RDY));
8005 + if (is_complete) {
8006 + DBG(DBG_QUEUE, "%s: request done\n", ep_name(ep));
8007 + req->req.status = 0;
8008 + list_del_init(&req->queue);
8009 + usba_ep_writel(ep, CTL_DIS, USBA_BIT(RX_BK_RDY));
8010 + req->req.complete(&ep->ep, &req->req);
8013 + status = usba_ep_readl(ep, STA);
8014 + nr_busy = USBA_BFEXT(BUSY_BANKS, status);
8016 + if (is_complete && ep_is_control(ep)) {
8017 + send_status(udc, ep);
8023 +static void request_complete(struct usba_ep *ep,
8024 + struct usba_request *req,
8027 + struct usba_udc *udc = ep->udc;
8029 + WARN_ON(!list_empty(&req->queue));
8031 + if (req->req.status == -EINPROGRESS)
8032 + req->req.status = status;
8034 + if (req->mapped) {
8036 + &udc->pdev->dev, req->req.dma, req->req.length,
8037 + ep_is_in(ep) ? DMA_TO_DEVICE : DMA_FROM_DEVICE);
8038 + req->req.dma = DMA_ADDR_INVALID;
8042 + DBG(DBG_GADGET | DBG_REQ,
8043 + "%s: req %p complete: status %d, actual %u\n",
8044 + ep_name(ep), req, req->req.status, req->req.actual);
8045 + req->req.complete(&ep->ep, &req->req);
8048 +static void request_complete_list(struct usba_ep *ep,
8049 + struct list_head *list,
8052 + struct usba_request *req, *tmp_req;
8054 + list_for_each_entry_safe(req, tmp_req, list, queue) {
8055 + list_del_init(&req->queue);
8056 + request_complete(ep, req, status);
8060 +static int usba_ep_enable(struct usb_ep *_ep,
8061 + const struct usb_endpoint_descriptor *desc)
8063 + struct usba_ep *ep = to_usba_ep(_ep);
8064 + struct usba_udc *udc = ep->udc;
8065 + unsigned long flags, ept_cfg, maxpacket;
8067 + DBG(DBG_GADGET, "%s: ep_enable: desc=%p\n", ep_name(ep), desc);
8069 + maxpacket = le16_to_cpu(desc->wMaxPacketSize);
8071 + if (ep->index == 0
8072 + || desc->bDescriptorType != USB_DT_ENDPOINT
8073 + || ((desc->bEndpointAddress & USB_ENDPOINT_NUMBER_MASK)
8076 + || maxpacket > ep->fifo_size) {
8077 + DBG(DBG_ERR, "ep_enable: Invalid argument");
8084 + if ((desc->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK)
8085 + == USB_ENDPOINT_XFER_ISOC) {
8086 + if (!ep->can_isoc) {
8087 + DBG(DBG_ERR, "ep_enable: %s is not isoc capable\n",
8094 + if (maxpacket <= 8)
8095 + ept_cfg = USBA_BF(EPT_SIZE, USBA_EPT_SIZE_8);
8097 + /* LSB is bit 1, not 0 */
8098 + ept_cfg = USBA_BF(EPT_SIZE, fls(maxpacket - 1) - 3);
8099 + DBG(DBG_HW, "%s: EPT_SIZE = %lu (maxpacket = %lu)\n",
8100 + ep_name(ep), ept_cfg, maxpacket);
8102 + if ((desc->bEndpointAddress & USB_ENDPOINT_DIR_MASK) == USB_DIR_IN) {
8104 + ept_cfg |= USBA_BIT(EPT_DIR);
8107 + switch (desc->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) {
8108 + case USB_ENDPOINT_XFER_CONTROL:
8109 + ept_cfg |= USBA_BF(EPT_TYPE, USBA_EPT_TYPE_CONTROL);
8111 + case USB_ENDPOINT_XFER_ISOC:
8112 + ept_cfg |= USBA_BF(EPT_TYPE, USBA_EPT_TYPE_ISO);
8114 + case USB_ENDPOINT_XFER_BULK:
8115 + ept_cfg |= USBA_BF(EPT_TYPE, USBA_EPT_TYPE_BULK);
8117 + case USB_ENDPOINT_XFER_INT:
8118 + ept_cfg |= USBA_BF(EPT_TYPE, USBA_EPT_TYPE_INT);
8121 + ept_cfg |= USBA_BF(BK_NUMBER, ep->nr_banks);
8123 + spin_lock_irqsave(&ep->udc->lock, flags);
8126 + spin_unlock_irqrestore(&ep->udc->lock, flags);
8127 + DBG(DBG_ERR, "ep%d already enabled\n", ep->index);
8132 + ep->ep.maxpacket = maxpacket;
8134 + usba_ep_writel(ep, CFG, ept_cfg);
8135 + usba_ep_writel(ep, CTL_ENB, USBA_BIT(EPT_ENABLE));
8137 + if (ep_can_dma(ep)) {
8140 + usba_writel(udc, INT_ENB,
8141 + (usba_readl(udc, INT_ENB)
8142 + | USBA_BF(EPT_INT, 1 << ep->index)
8143 + | USBA_BF(DMA_INT, 1 << ep->index)));
8144 + ctrl = USBA_BIT(AUTO_VALID) | USBA_BIT(INTDIS_DMA);
8145 + usba_ep_writel(ep, CTL_ENB, ctrl);
8147 + usba_writel(udc, INT_ENB,
8148 + (usba_readl(udc, INT_ENB)
8149 + | USBA_BF(EPT_INT, 1 << ep->index)));
8152 + spin_unlock_irqrestore(&udc->lock, flags);
8154 + DBG(DBG_HW, "EPT_CFG%d after init: %#08lx\n", ep->index,
8155 + (unsigned long)usba_ep_readl(ep, CFG));
8156 + DBG(DBG_HW, "INT_ENB after init: %#08lx\n",
8157 + (unsigned long)usba_readl(udc, INT_ENB));
8162 +static int usba_ep_disable(struct usb_ep *_ep)
8164 + struct usba_ep *ep = to_usba_ep(_ep);
8165 + struct usba_udc *udc = ep->udc;
8166 + LIST_HEAD(req_list);
8167 + unsigned long flags;
8169 + DBG(DBG_GADGET, "ep_disable: %s\n", ep_name(ep));
8171 + spin_lock_irqsave(&udc->lock, flags);
8174 + spin_unlock_irqrestore(&udc->lock, flags);
8175 + DBG(DBG_ERR, "ep_disable: %s not enabled\n",
8181 + list_splice_init(&ep->queue, &req_list);
8182 + if (ep_can_dma(ep)) {
8183 + usba_dma_writel(ep, CONTROL, 0);
8184 + usba_dma_writel(ep, ADDRESS, 0);
8185 + usba_dma_readl(ep, STATUS);
8187 + usba_ep_writel(ep, CTL_DIS, USBA_BIT(EPT_ENABLE));
8188 + usba_writel(udc, INT_ENB, (usba_readl(udc, INT_ENB)
8189 + & ~USBA_BF(EPT_INT, 1 << ep->index)));
8191 + spin_unlock_irqrestore(&udc->lock, flags);
8193 + request_complete_list(ep, &req_list, -ESHUTDOWN);
8198 +static struct usb_request *
8199 +usba_ep_alloc_request(struct usb_ep *_ep, unsigned gfp_flags)
8201 + struct usba_request *req;
8203 + DBG(DBG_GADGET, "ep_alloc_request: %p, 0x%x\n", _ep, gfp_flags);
8205 + req = kzalloc(sizeof(*req), gfp_flags);
8209 + INIT_LIST_HEAD(&req->queue);
8210 + req->req.dma = DMA_ADDR_INVALID;
8216 +usba_ep_free_request(struct usb_ep *_ep, struct usb_request *_req)
8218 + struct usba_request *req = to_usba_req(_req);
8220 + DBG(DBG_GADGET, "ep_free_request: %p, %p\n", _ep, _req);
8225 +static void *usba_ep_alloc_buffer(struct usb_ep *_ep, unsigned bytes,
8226 + dma_addr_t *dma, unsigned gfp_flags)
8230 + if (bytes < L1_CACHE_BYTES)
8231 + bytes = L1_CACHE_BYTES;
8233 + buf = kmalloc(bytes, gfp_flags);
8236 + * Seems like we have to map the buffer any chance we get.
8237 + * ether.c wants us to initialize the dma member of a
8238 + * different request than the one receiving the buffer, so one
8241 + * Ah, screw it. The ether driver is probably wrong, and this
8242 + * is not the right place to do the mapping. The driver
8243 + * shouldn't mess with our DMA mappings anyway.
8245 + *dma = DMA_ADDR_INVALID;
8250 +static void usba_ep_free_buffer(struct usb_ep *_ep, void *buf,
8251 + dma_addr_t dma, unsigned bytes)
8253 + DBG(DBG_GADGET, "ep_free_buffer: %s, buf %p (size %u)\n",
8254 + _ep->name, buf, bytes);
8258 +static int queue_dma(struct usba_udc *udc, struct usba_ep *ep,
8259 + struct usba_request *req, gfp_t gfp_flags)
8261 + unsigned long flags;
8264 + DBG(DBG_DMA, "%s: req l/%u d/%08x %c%c%c\n",
8265 + ep_name(ep), req->req.length, req->req.dma,
8266 + req->req.zero ? 'Z' : 'z',
8267 + req->req.short_not_ok ? 'S' : 's',
8268 + req->req.no_interrupt ? 'I' : 'i');
8270 + if (req->req.length > 0x10000) {
8271 + /* Lengths from 0 to 65536 (inclusive) are supported */
8272 + DBG(DBG_ERR, "invalid request length %u\n", req->req.length);
8276 + req->using_dma = 1;
8278 + if (req->req.dma == DMA_ADDR_INVALID) {
8279 + req->req.dma = dma_map_single(
8280 + &udc->pdev->dev, req->req.buf, req->req.length,
8281 + ep_is_in(ep) ? DMA_TO_DEVICE : DMA_FROM_DEVICE);
8284 + dma_sync_single_for_device(
8285 + &udc->pdev->dev, req->req.dma, req->req.length,
8286 + ep_is_in(ep) ? DMA_TO_DEVICE : DMA_FROM_DEVICE);
8290 + req->ctrl = (USBA_BF(DMA_BUF_LEN, req->req.length)
8291 + | USBA_BIT(DMA_CH_EN) | USBA_BIT(DMA_END_BUF_IE)
8292 + | USBA_BIT(DMA_END_TR_EN) | USBA_BIT(DMA_END_TR_IE));
8295 + req->ctrl |= USBA_BIT(DMA_END_BUF_EN);
8298 + * Add this request to the queue and submit for DMA if
8299 + * possible. Check if we're still alive first -- we may have
8300 + * received a reset since last time we checked.
8303 + spin_lock_irqsave(&udc->lock, flags);
8305 + if (list_empty(&ep->queue))
8306 + submit_request(ep, req);
8308 + list_add_tail(&req->queue, &ep->queue);
8311 + spin_unlock_irqrestore(&udc->lock, flags);
8316 +static int usba_ep_queue(struct usb_ep *_ep, struct usb_request *_req,
8319 + struct usba_request *req = to_usba_req(_req);
8320 + struct usba_ep *ep = to_usba_ep(_ep);
8321 + struct usba_udc *udc = ep->udc;
8322 + unsigned long flags;
8325 + DBG(DBG_GADGET | DBG_QUEUE | DBG_REQ,
8326 + "%s: queue req %p, len %u\n", ep_name(ep), req, _req->length);
8328 + if (!udc->driver || udc->gadget.speed == USB_SPEED_UNKNOWN
8330 + return -ESHUTDOWN;
8332 + req->submitted = 0;
8333 + req->using_dma = 0;
8334 + req->last_transaction = 0;
8336 + _req->status = -EINPROGRESS;
8339 + if (ep_can_dma(ep))
8340 + return queue_dma(udc, ep, req, gfp_flags);
8342 + /* May have received a reset since last time we checked */
8344 + spin_lock_irqsave(&udc->lock, flags);
8346 + list_add_tail(&req->queue, &ep->queue);
8349 + || (ep_is_control(ep)
8350 + && (ep->state == DATA_STAGE_IN
8351 + || ep->state == STATUS_STAGE_IN)))
8352 + usba_ep_writel(ep, CTL_ENB, USBA_BIT(TX_PK_RDY));
8354 + usba_ep_writel(ep, CTL_ENB, USBA_BIT(RX_BK_RDY));
8357 + spin_unlock_irqrestore(&udc->lock, flags);
8362 +static void usba_update_req(struct usba_ep *ep, struct usba_request *req,
8365 + req->req.actual = req->req.length - USBA_BFEXT(DMA_BUF_LEN, status);
8368 +static int stop_dma(struct usba_ep *ep, u32 *pstatus)
8370 + unsigned int timeout;
8374 + * Stop the DMA controller. When writing both CH_EN
8375 + * and LINK to 0, the other bits are not affected.
8377 + usba_dma_writel(ep, CONTROL, 0);
8379 + /* Wait for the FIFO to empty */
8380 + for (timeout = 40; timeout; --timeout) {
8381 + status = usba_dma_readl(ep, STATUS);
8382 + if (!(status & USBA_BIT(DMA_CH_EN)))
8388 + *pstatus = status;
8390 + if (timeout == 0) {
8391 + dev_err(&ep->udc->pdev->dev,
8392 + "%s: timed out waiting for DMA FIFO to empty\n",
8394 + return -ETIMEDOUT;
8400 +static int usba_ep_dequeue(struct usb_ep *_ep, struct usb_request *_req)
8402 + struct usba_ep *ep = to_usba_ep(_ep);
8403 + struct usba_udc *udc = ep->udc;
8404 + struct usba_request *req = to_usba_req(_req);
8405 + unsigned long flags;
8408 + DBG(DBG_GADGET | DBG_QUEUE, "ep_dequeue: %s, req %p\n",
8409 + ep_name(ep), req);
8411 + spin_lock_irqsave(&udc->lock, flags);
8413 + if (req->using_dma) {
8415 + * If this request is currently being transferred,
8416 + * stop the DMA controller and reset the FIFO.
8418 + if (ep->queue.next == &req->queue) {
8419 + status = usba_dma_readl(ep, STATUS);
8420 + if (status & USBA_BIT(DMA_CH_EN))
8421 + stop_dma(ep, &status);
8423 +#ifdef CONFIG_DEBUG_FS
8424 + ep->last_dma_status = status;
8427 + usba_writel(udc, EPT_RST,
8428 + 1 << ep_index(ep));
8430 + usba_update_req(ep, req, status);
8435 + * Errors should stop the queue from advancing until the
8436 + * completion function returns.
8438 + list_del_init(&req->queue);
8439 + spin_unlock_irqrestore(&udc->lock, flags);
8441 + request_complete(ep, req, -ECONNRESET);
8443 + /* Process the next request if any */
8444 + spin_lock_irqsave(&udc->lock, flags);
8445 + submit_next_request(ep);
8446 + spin_unlock_irqrestore(&udc->lock, flags);
8451 +static int usba_ep_set_halt(struct usb_ep *_ep, int value)
8453 + struct usba_ep *ep = to_usba_ep(_ep);
8454 + struct usba_udc *udc = ep->udc;
8455 + unsigned long flags;
8458 + DBG(DBG_GADGET, "endpoint %s: %s HALT\n", ep_name(ep),
8459 + value ? "set" : "clear");
8462 + DBG(DBG_ERR, "Attempted to halt uninitialized ep %s\n",
8466 + if (ep_is_isochronous(ep)) {
8467 + DBG(DBG_ERR, "Attempted to halt isochronous ep %s\n",
8472 + spin_lock_irqsave(&udc->lock, flags);
8475 + * We can't halt IN endpoints while there are still data to be
8478 + if (!list_empty(&ep->queue)
8479 + || ((value && ep_is_in(ep)
8480 + && (usba_ep_readl(ep, STA)
8481 + & USBA_BF(BUSY_BANKS, -1L))))) {
8485 + usba_ep_writel(ep, SET_STA, USBA_BIT(FORCE_STALL));
8487 + usba_ep_writel(ep, CLR_STA, (USBA_BIT(FORCE_STALL)
8488 + | USBA_BIT(TOGGLE_SEQ)));
8489 + usba_ep_readl(ep, STA);
8492 + spin_unlock_irqrestore(&udc->lock, flags);
8497 +static int usba_ep_fifo_status(struct usb_ep *_ep)
8499 + struct usba_ep *ep = to_usba_ep(_ep);
8501 + return USBA_BFEXT(BYTE_COUNT, usba_ep_readl(ep, STA));
8504 +static void usba_ep_fifo_flush(struct usb_ep *_ep)
8506 + struct usba_ep *ep = to_usba_ep(_ep);
8507 + struct usba_udc *udc = ep->udc;
8509 + usba_writel(udc, EPT_RST, 1 << ep->index);
8512 +struct usb_ep_ops usba_ep_ops = {
8513 + .enable = usba_ep_enable,
8514 + .disable = usba_ep_disable,
8515 + .alloc_request = usba_ep_alloc_request,
8516 + .free_request = usba_ep_free_request,
8517 + .alloc_buffer = usba_ep_alloc_buffer,
8518 + .free_buffer = usba_ep_free_buffer,
8519 + .queue = usba_ep_queue,
8520 + .dequeue = usba_ep_dequeue,
8521 + .set_halt = usba_ep_set_halt,
8522 + .fifo_status = usba_ep_fifo_status,
8523 + .fifo_flush = usba_ep_fifo_flush,
8526 +static int usba_udc_get_frame(struct usb_gadget *gadget)
8528 + struct usba_udc *udc = to_usba_udc(gadget);
8530 + return USBA_BFEXT(FRAME_NUMBER, usba_readl(udc, FNUM));
8533 +struct usb_gadget_ops usba_udc_ops = {
8534 + .get_frame = usba_udc_get_frame,
8537 +#define EP(nam, type, idx, dma, isoc) \
8540 + .ops = &usba_ep_ops, \
8542 + .maxpacket = type##_FIFO_SIZE, \
8544 + .udc = &the_udc, \
8545 + .queue = LIST_HEAD_INIT(usba_ep[idx].queue), \
8546 + .fifo_size = type##_FIFO_SIZE, \
8547 + .nr_banks = type##_NR_BANKS, \
8550 + .can_isoc = isoc, \
8553 +static struct usba_ep usba_ep[] = {
8554 + EP("ep0", EP0, 0, 0, 0),
8555 + EP("ep1in-bulk", BULK, 1, 1, 0),
8556 + EP("ep2out-bulk", BULK, 2, 1, 0),
8557 + EP("ep3in-iso", ISO, 3, 1, 1),
8558 + EP("ep4out-iso", ISO, 4, 1, 1),
8559 + EP("ep5in-int", INT, 5, 1, 0),
8560 + EP("ep6out-int", INT, 6, 1, 0),
8564 +static struct usb_endpoint_descriptor usba_ep0_desc = {
8565 + .bLength = USB_DT_ENDPOINT_SIZE,
8566 + .bDescriptorType = USB_DT_ENDPOINT,
8567 + .bEndpointAddress = 0,
8568 + .bmAttributes = USB_ENDPOINT_XFER_CONTROL,
8569 + .wMaxPacketSize = __constant_cpu_to_le16(64),
8570 + /* FIXME: I have no idea what to put here */
8574 +static void nop_release(struct device *dev)
8579 +static struct usba_udc the_udc = {
8581 + .ops = &usba_udc_ops,
8582 + .ep0 = &usba_ep[0].ep,
8583 + .ep_list = LIST_HEAD_INIT(the_udc.gadget.ep_list),
8584 + .is_dualspeed = 1,
8585 + .name = "atmel_usba_udc",
8587 + .bus_id = "gadget",
8588 + .release = nop_release,
8592 + .lock = SPIN_LOCK_UNLOCKED,
8596 + * Called with interrupts disabled and udc->lock held.
8598 +static void reset_all_endpoints(struct usba_udc *udc)
8600 + struct usba_ep *ep;
8601 + struct usba_request *req, *tmp_req;
8603 + usba_writel(udc, EPT_RST, ~0UL);
8605 + ep = to_usba_ep(udc->gadget.ep0);
8606 + list_for_each_entry_safe(req, tmp_req, &ep->queue, queue) {
8607 + list_del_init(&req->queue);
8608 + request_complete(ep, req, -ECONNRESET);
8611 + list_for_each_entry(ep, &udc->gadget.ep_list, ep.ep_list) {
8613 + usba_ep_disable(&ep->ep);
8617 +static struct usba_ep *get_ep_by_addr(struct usba_udc *udc, u16 wIndex)
8619 + struct usba_ep *ep;
8621 + if ((wIndex & USB_ENDPOINT_NUMBER_MASK) == 0)
8622 + return to_usba_ep(udc->gadget.ep0);
8624 + list_for_each_entry (ep, &udc->gadget.ep_list, ep.ep_list) {
8625 + u8 bEndpointAddress;
8629 + bEndpointAddress = ep->desc->bEndpointAddress;
8630 + if ((wIndex ^ bEndpointAddress) & USB_DIR_IN)
8632 + if ((wIndex & USB_ENDPOINT_NUMBER_MASK)
8633 + == (bEndpointAddress & USB_ENDPOINT_NUMBER_MASK))
8640 +/* Called with interrupts disabled and udc->lock held */
8641 +static inline void set_protocol_stall(struct usba_udc *udc,
8642 + struct usba_ep *ep)
8644 + usba_ep_writel(ep, SET_STA, USBA_BIT(FORCE_STALL));
8645 + ep->state = WAIT_FOR_SETUP;
8648 +static inline int is_stalled(struct usba_udc *udc, struct usba_ep *ep)
8650 + if (usba_ep_readl(ep, STA) & USBA_BIT(FORCE_STALL))
8655 +static inline void set_address(struct usba_udc *udc, unsigned int addr)
8659 + DBG(DBG_BUS, "setting address %u...\n", addr);
8660 + regval = usba_readl(udc, CTRL);
8661 + regval = USBA_BFINS(DEV_ADDR, addr, regval);
8662 + usba_writel(udc, CTRL, regval);
8665 +static int do_test_mode(struct usba_udc *udc)
8667 + static const char test_packet_buffer[] = {
8668 + /* JKJKJKJK * 9 */
8669 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
8670 + /* JJKKJJKK * 8 */
8671 + 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA,
8672 + /* JJKKJJKK * 8 */
8673 + 0xEE, 0xEE, 0xEE, 0xEE, 0xEE, 0xEE, 0xEE, 0xEE,
8674 + /* JJJJJJJKKKKKKK * 8 */
8675 + 0xFE, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
8676 + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
8677 + /* JJJJJJJK * 8 */
8678 + 0x7F, 0xBF, 0xDF, 0xEF, 0xF7, 0xFB, 0xFD,
8679 + /* {JKKKKKKK * 10}, JK */
8680 + 0xFC, 0x7E, 0xBF, 0xDF, 0xEF, 0xF7, 0xFB, 0xFD, 0x7E
8682 + struct device *dev = &udc->pdev->dev;
8683 + struct usba_ep *ep;
8686 + test_mode = udc->test_mode;
8688 + /* Start from a clean slate */
8689 + reset_all_endpoints(udc);
8691 + switch (test_mode) {
8694 + usba_writel(udc, TST, USBA_BIT(TST_J_MODE));
8695 + dev_info(dev, "Entering Test_J mode...\n");
8699 + usba_writel(udc, TST, USBA_BIT(TST_K_MODE));
8700 + dev_info(dev, "Entering Test_K mode...\n");
8704 + * Test_SE0_NAK: Force high-speed mode and set up ep0
8705 + * for Bulk IN transfers
8708 + usba_writel(udc, TST,
8709 + USBA_BF(SPEED_CFG, USBA_SPEED_CFG_FORCE_HIGH));
8710 + usba_ep_writel(ep, CFG,
8711 + USBA_BF(EPT_SIZE, USBA_EPT_SIZE_64)
8712 + | USBA_BIT(EPT_DIR)
8713 + | USBA_BF(EPT_TYPE, USBA_EPT_TYPE_BULK)
8714 + | USBA_BF(BK_NUMBER, 1));
8715 + if (!(usba_ep_readl(ep, CFG) & USBA_BIT(EPT_MAPPED))) {
8716 + set_protocol_stall(udc, ep);
8717 + dev_err(dev, "Test_SE0_NAK: ep0 not mapped\n");
8719 + usba_ep_writel(ep, CTL_ENB, USBA_BIT(EPT_ENABLE));
8720 + dev_info(dev, "Entering Test_SE0_NAK mode...\n");
8726 + usba_ep_writel(ep, CFG,
8727 + USBA_BF(EPT_SIZE, USBA_EPT_SIZE_64)
8728 + | USBA_BIT(EPT_DIR)
8729 + | USBA_BF(EPT_TYPE, USBA_EPT_TYPE_BULK)
8730 + | USBA_BF(BK_NUMBER, 1));
8731 + if (!(usba_ep_readl(ep, CFG) & USBA_BIT(EPT_MAPPED))) {
8732 + set_protocol_stall(udc, ep);
8733 + dev_err(dev, "Test_Packet: ep0 not mapped\n");
8735 + usba_ep_writel(ep, CTL_ENB, USBA_BIT(EPT_ENABLE));
8736 + usba_writel(udc, TST, USBA_BIT(TST_PKT_MODE));
8737 + copy_to_fifo(ep->fifo, test_packet_buffer,
8738 + sizeof(test_packet_buffer));
8739 + usba_ep_writel(ep, SET_STA, USBA_BIT(TX_PK_RDY));
8740 + dev_info(dev, "Entering Test_Packet mode...\n");
8744 + dev_err(dev, "Invalid test mode: 0x%04x\n", test_mode);
8751 +/* Avoid overly long expressions */
8752 +static inline bool feature_is_dev_remote_wakeup(struct usb_ctrlrequest *crq)
8754 + if (crq->wValue == __constant_cpu_to_le16(USB_DEVICE_REMOTE_WAKEUP))
8759 +static inline bool feature_is_dev_test_mode(struct usb_ctrlrequest *crq)
8761 + if (crq->wValue == __constant_cpu_to_le16(USB_DEVICE_TEST_MODE))
8766 +static inline bool feature_is_ep_halt(struct usb_ctrlrequest *crq)
8768 + if (crq->wValue == __constant_cpu_to_le16(USB_ENDPOINT_HALT))
8773 +static int handle_ep0_setup(struct usba_udc *udc, struct usba_ep *ep,
8774 + struct usb_ctrlrequest *crq)
8776 + switch (crq->bRequest) {
8777 + case USB_REQ_GET_STATUS: {
8780 + if (crq->bRequestType == (USB_DIR_IN | USB_RECIP_DEVICE)) {
8781 + /* Self-powered, no remote wakeup */
8782 + status = __constant_cpu_to_le16(1 << 0);
8783 + } else if (crq->bRequestType
8784 + == (USB_DIR_IN | USB_RECIP_INTERFACE)) {
8785 + status = __constant_cpu_to_le16(0);
8786 + } else if (crq->bRequestType
8787 + == (USB_DIR_IN | USB_RECIP_ENDPOINT)) {
8788 + struct usba_ep *target;
8790 + target = get_ep_by_addr(udc, le16_to_cpu(crq->wIndex));
8795 + if (is_stalled(udc, target))
8796 + status |= __constant_cpu_to_le16(1);
8801 + /* Write directly to the FIFO. No queueing is done. */
8802 + if (crq->wLength != __constant_cpu_to_le16(sizeof(status)))
8804 + ep->state = DATA_STAGE_IN;
8805 + __raw_writew(status, ep->fifo);
8806 + usba_ep_writel(ep, SET_STA, USBA_BIT(TX_PK_RDY));
8810 + case USB_REQ_CLEAR_FEATURE: {
8811 + if (crq->bRequestType == USB_RECIP_DEVICE) {
8812 + if (feature_is_dev_remote_wakeup(crq)) {
8813 + /* TODO: Handle REMOTE_WAKEUP */
8815 + /* Can't CLEAR_FEATURE TEST_MODE */
8818 + } else if (crq->bRequestType == USB_RECIP_ENDPOINT) {
8819 + struct usba_ep *target;
8821 + if (!feature_is_ep_halt(crq)
8822 + || crq->wLength != __constant_cpu_to_le16(0))
8824 + target = get_ep_by_addr(udc, le16_to_cpu(crq->wIndex));
8828 + usba_ep_writel(target, CLR_STA,
8829 + (USBA_BIT(FORCE_STALL)
8830 + | USBA_BIT(TOGGLE_SEQ)));
8835 + send_status(udc, ep);
8839 + case USB_REQ_SET_FEATURE: {
8840 + if (crq->bRequestType == USB_RECIP_DEVICE) {
8841 + if (feature_is_dev_test_mode(crq)) {
8842 + send_status(udc, ep);
8843 + ep->state = STATUS_STAGE_TEST;
8844 + udc->test_mode = le16_to_cpu(crq->wIndex);
8846 + } else if (feature_is_dev_remote_wakeup(crq)) {
8847 + /* TODO: Handle REMOTE_WAKEUP */
8851 + } else if (crq->bRequestType == USB_RECIP_ENDPOINT) {
8852 + struct usba_ep *target;
8854 + if (!feature_is_ep_halt(crq)
8855 + || crq->wLength != __constant_cpu_to_le16(0))
8858 + target = get_ep_by_addr(udc, le16_to_cpu(crq->wIndex));
8862 + usba_ep_writel(target, SET_STA, USBA_BIT(FORCE_STALL));
8866 + send_status(udc, ep);
8870 + case USB_REQ_SET_ADDRESS:
8871 + if (crq->bRequestType != (USB_DIR_OUT | USB_RECIP_DEVICE))
8874 + set_address(udc, le16_to_cpu(crq->wValue));
8875 + send_status(udc, ep);
8876 + ep->state = STATUS_STAGE_ADDR;
8881 + return udc->driver->setup(&udc->gadget, crq);
8888 + "udc: %s: Invalid setup request: %02x.%02x v%04x i%04x l%d, "
8889 + "halting endpoint...\n",
8890 + ep_name(ep), crq->bRequestType, crq->bRequest,
8891 + le16_to_cpu(crq->wValue), le16_to_cpu(crq->wIndex),
8892 + le16_to_cpu(crq->wLength));
8893 + set_protocol_stall(udc, ep);
8897 +static void usba_control_irq(struct usba_udc *udc, struct usba_ep *ep)
8899 + struct usba_request *req;
8904 + epstatus = usba_ep_readl(ep, STA);
8905 + epctrl = usba_ep_readl(ep, CTL);
8907 + DBG(DBG_INT, "%s [%d]: s/%08x c/%08x\n",
8908 + ep_name(ep), ep->state, epstatus, epctrl);
8911 + if (!list_empty(&ep->queue))
8912 + req = list_entry(ep->queue.next,
8913 + struct usba_request, queue);
8915 + if ((epctrl & USBA_BIT(TX_PK_RDY))
8916 + && !(epstatus & USBA_BIT(TX_PK_RDY))) {
8917 + if (req->submitted)
8918 + next_fifo_transaction(ep, req);
8920 + submit_request(ep, req);
8922 + if (req->last_transaction) {
8923 + usba_ep_writel(ep, CTL_DIS, USBA_BIT(TX_PK_RDY));
8924 + usba_ep_writel(ep, CTL_ENB, USBA_BIT(TX_COMPLETE));
8928 + if ((epstatus & epctrl) & USBA_BIT(TX_COMPLETE)) {
8929 + usba_ep_writel(ep, CLR_STA, USBA_BIT(TX_COMPLETE));
8931 + switch (ep->state) {
8932 + case DATA_STAGE_IN:
8933 + usba_ep_writel(ep, CTL_ENB, USBA_BIT(RX_BK_RDY));
8934 + usba_ep_writel(ep, CTL_DIS, USBA_BIT(TX_COMPLETE));
8935 + ep->state = STATUS_STAGE_OUT;
8937 + case STATUS_STAGE_ADDR:
8938 + /* Activate our new address */
8939 + usba_writel(udc, CTRL, (usba_readl(udc, CTRL)
8940 + | USBA_BIT(FADDR_EN)));
8941 + usba_ep_writel(ep, CTL_DIS, USBA_BIT(TX_COMPLETE));
8942 + ep->state = WAIT_FOR_SETUP;
8944 + case STATUS_STAGE_IN:
8946 + list_del_init(&req->queue);
8947 + request_complete(ep, req, 0);
8948 + submit_next_request(ep);
8950 + usba_ep_writel(ep, CTL_DIS, USBA_BIT(TX_COMPLETE));
8951 + ep->state = WAIT_FOR_SETUP;
8953 + case STATUS_STAGE_TEST:
8954 + usba_ep_writel(ep, CTL_DIS, USBA_BIT(TX_COMPLETE));
8955 + ep->state = WAIT_FOR_SETUP;
8956 + if (do_test_mode(udc))
8957 + set_protocol_stall(udc, ep);
8961 + "udc: %s: TXCOMP: Invalid endpoint state %d, "
8962 + "halting endpoint...\n",
8963 + ep_name(ep), ep->state);
8964 + set_protocol_stall(udc, ep);
8970 + if ((epstatus & epctrl) & USBA_BIT(RX_BK_RDY)) {
8971 + switch (ep->state) {
8972 + case STATUS_STAGE_OUT:
8973 + usba_ep_writel(ep, CLR_STA, USBA_BIT(RX_BK_RDY));
8974 + usba_ep_writel(ep, CTL_DIS, USBA_BIT(RX_BK_RDY));
8977 + list_del_init(&req->queue);
8978 + request_complete(ep, req, 0);
8980 + ep->state = WAIT_FOR_SETUP;
8983 + case DATA_STAGE_OUT:
8988 + usba_ep_writel(ep, CLR_STA, USBA_BIT(RX_BK_RDY));
8989 + usba_ep_writel(ep, CTL_DIS, USBA_BIT(RX_BK_RDY));
8991 + "udc: %s: RXRDY: Invalid endpoint state %d, "
8992 + "halting endpoint...\n",
8993 + ep_name(ep), ep->state);
8994 + set_protocol_stall(udc, ep);
9000 + if (epstatus & USBA_BIT(RX_SETUP)) {
9002 + struct usb_ctrlrequest crq;
9003 + unsigned long data[2];
9005 + unsigned int pkt_len;
9008 + if (ep->state != WAIT_FOR_SETUP) {
9010 + * Didn't expect a SETUP packet at this
9011 + * point. Clean up any pending requests (which
9012 + * may be successful).
9014 + int status = -EPROTO;
9017 + * RXRDY and TXCOMP are dropped when SETUP
9018 + * packets arrive. Just pretend we received
9019 + * the status packet.
9021 + if (ep->state == STATUS_STAGE_OUT
9022 + || ep->state == STATUS_STAGE_IN) {
9023 + usba_ep_writel(ep, CTL_DIS,
9024 + USBA_BIT(RX_BK_RDY));
9029 + list_del_init(&req->queue);
9030 + request_complete(ep, req, status);
9034 + pkt_len = USBA_BFEXT(BYTE_COUNT, usba_ep_readl(ep, STA));
9035 + DBG(DBG_HW, "Packet length: %u\n", pkt_len);
9036 + if (pkt_len != sizeof(crq)) {
9037 + printk(KERN_WARNING
9038 + "udc: Invalid packet length %u (expected %lu)\n",
9039 + pkt_len, sizeof(crq));
9040 + set_protocol_stall(udc, ep);
9044 + DBG(DBG_FIFO, "Copying ctrl request from 0x%p:\n", ep->fifo);
9045 + copy_from_fifo(crq.data, ep->fifo, sizeof(crq));
9047 + /* Free up one bank in the FIFO so that we can
9048 + * generate or receive a reply right away. */
9049 + usba_ep_writel(ep, CLR_STA, USBA_BIT(RX_SETUP));
9051 + /* printk(KERN_DEBUG "setup: %d: %02x.%02x\n",
9052 + ep->state, crq.crq.bRequestType,
9053 + crq.crq.bRequest); */
9055 + if (crq.crq.bRequestType & USB_DIR_IN) {
9057 + * The USB 2.0 spec states that "if wLength is
9058 + * zero, there is no data transfer phase."
9059 + * However, testusb #14 seems to actually
9060 + * expect a data phase even if wLength = 0...
9062 + ep->state = DATA_STAGE_IN;
9064 + if (crq.crq.wLength != __constant_cpu_to_le16(0))
9065 + ep->state = DATA_STAGE_OUT;
9067 + ep->state = STATUS_STAGE_IN;
9071 + if (ep->index == 0)
9072 + ret = handle_ep0_setup(udc, ep, &crq.crq);
9074 + ret = udc->driver->setup(&udc->gadget, &crq.crq);
9076 + DBG(DBG_BUS, "req %02x.%02x, length %d, state %d, ret %d\n",
9077 + crq.crq.bRequestType, crq.crq.bRequest,
9078 + le16_to_cpu(crq.crq.wLength), ep->state, ret);
9081 + /* Let the host know that we failed */
9082 + set_protocol_stall(udc, ep);
9087 +static void usba_ep_irq(struct usba_udc *udc, struct usba_ep *ep)
9089 + struct usba_request *req;
9093 + epstatus = usba_ep_readl(ep, STA);
9094 + epctrl = usba_ep_readl(ep, CTL);
9096 + DBG(DBG_INT, "%s: interrupt, status: 0x%08x\n",
9097 + ep_name(ep), epstatus);
9099 + while ((epctrl & USBA_BIT(TX_PK_RDY))
9100 + && !(epstatus & USBA_BIT(TX_PK_RDY))) {
9101 + DBG(DBG_BUS, "%s: TX PK ready\n", ep_name(ep));
9103 + if (list_empty(&ep->queue)) {
9104 + dev_warn(&udc->pdev->dev, "ep_irq: queue empty\n");
9105 + usba_ep_writel(ep, CTL_DIS, USBA_BIT(TX_PK_RDY));
9109 + req = list_entry(ep->queue.next, struct usba_request, queue);
9111 + if (req->using_dma) {
9112 + /* Send a zero-length packet */
9113 + usba_ep_writel(ep, SET_STA,
9114 + USBA_BIT(TX_PK_RDY));
9115 + usba_ep_writel(ep, CTL_DIS,
9116 + USBA_BIT(TX_PK_RDY));
9117 + list_del_init(&req->queue);
9118 + submit_next_request(ep);
9119 + request_complete(ep, req, 0);
9121 + if (req->submitted)
9122 + next_fifo_transaction(ep, req);
9124 + submit_request(ep, req);
9126 + if (req->last_transaction) {
9127 + list_del_init(&req->queue);
9128 + submit_next_request(ep);
9129 + request_complete(ep, req, 0);
9133 + epstatus = usba_ep_readl(ep, STA);
9134 + epctrl = usba_ep_readl(ep, CTL);
9136 + if ((epstatus & epctrl) & USBA_BIT(RX_BK_RDY)) {
9137 + DBG(DBG_BUS, "%s: RX data ready\n", ep_name(ep));
9139 + usba_ep_writel(ep, CLR_STA, USBA_BIT(RX_BK_RDY));
9143 +static void usba_dma_irq(struct usba_udc *udc, struct usba_ep *ep)
9145 + struct usba_request *req;
9146 + u32 status, control, pending;
9148 + status = usba_dma_readl(ep, STATUS);
9149 + control = usba_dma_readl(ep, CONTROL);
9150 +#ifdef CONFIG_DEBUG_FS
9151 + ep->last_dma_status = status;
9153 + pending = status & control;
9154 + DBG(DBG_INT | DBG_DMA, "dma irq, s/%#08x, c/%#08x\n",
9157 + if (status & USBA_BIT(DMA_CH_EN)) {
9158 + dev_err(&udc->pdev->dev,
9159 + "DMA_CH_EN is set after transfer is finished!\n");
9160 + dev_err(&udc->pdev->dev,
9161 + "status=%#08x, pending=%#08x, control=%#08x\n",
9162 + status, pending, control);
9165 + * try to pretend nothing happened. We might have to
9166 + * do something here...
9170 + if (list_empty(&ep->queue))
9171 + /* Might happen if a reset comes along at the right moment */
9174 + if (pending & (USBA_BIT(DMA_END_TR_ST) | USBA_BIT(DMA_END_BUF_ST))) {
9175 + req = list_entry(ep->queue.next, struct usba_request, queue);
9176 + usba_update_req(ep, req, status);
9178 + list_del_init(&req->queue);
9179 + submit_next_request(ep);
9180 + request_complete(ep, req, 0);
9184 +static irqreturn_t usba_udc_irq(int irq, void *devid)
9186 + struct usba_udc *udc = devid;
9191 + spin_lock(&udc->lock);
9193 + status = usba_readl(udc, INT_STA);
9194 + DBG(DBG_INT, "irq, status=%#08x\n", status);
9196 + if (status & USBA_BIT(DET_SUSPEND)) {
9197 + usba_writel(udc, INT_CLR, USBA_BIT(DET_SUSPEND));
9198 + DBG(DBG_BUS, "Suspend detected\n");
9199 + if (udc->gadget.speed != USB_SPEED_UNKNOWN
9200 + && udc->driver && udc->driver->suspend)
9201 + udc->driver->suspend(&udc->gadget);
9204 + if (status & USBA_BIT(WAKE_UP)) {
9205 + usba_writel(udc, INT_CLR, USBA_BIT(WAKE_UP));
9206 + DBG(DBG_BUS, "Wake Up CPU detected\n");
9209 + if (status & USBA_BIT(END_OF_RESUME)) {
9210 + usba_writel(udc, INT_CLR, USBA_BIT(END_OF_RESUME));
9211 + DBG(DBG_BUS, "Resume detected\n");
9212 + if (udc->gadget.speed != USB_SPEED_UNKNOWN
9213 + && udc->driver && udc->driver->resume)
9214 + udc->driver->resume(&udc->gadget);
9217 + dma_status = USBA_BFEXT(DMA_INT, status);
9221 + for (i = 1; i < USBA_NR_ENDPOINTS; i++)
9222 + if (dma_status & (1 << i))
9223 + usba_dma_irq(udc, &usba_ep[i]);
9226 + ep_status = USBA_BFEXT(EPT_INT, status);
9230 + for (i = 0; i < USBA_NR_ENDPOINTS; i++)
9231 + if (ep_status & (1 << i)) {
9232 + if (ep_is_control(&usba_ep[i]))
9233 + usba_control_irq(udc, &usba_ep[i]);
9235 + usba_ep_irq(udc, &usba_ep[i]);
9239 + if (status & USBA_BIT(END_OF_RESET)) {
9240 + struct usba_ep *ep0;
9242 + usba_writel(udc, INT_CLR, USBA_BIT(END_OF_RESET));
9243 + reset_all_endpoints(udc);
9245 + if (status & USBA_BIT(HIGH_SPEED)) {
9246 + DBG(DBG_BUS, "High-speed bus reset detected\n");
9247 + udc->gadget.speed = USB_SPEED_HIGH;
9249 + DBG(DBG_BUS, "Full-speed bus reset detected\n");
9250 + udc->gadget.speed = USB_SPEED_FULL;
9253 + ep0 = &usba_ep[0];
9254 + ep0->desc = &usba_ep0_desc;
9255 + ep0->state = WAIT_FOR_SETUP;
9256 + usba_ep_writel(ep0, CFG,
9257 + (USBA_BF(EPT_SIZE, EP0_EPT_SIZE)
9258 + | USBA_BF(EPT_TYPE, USBA_EPT_TYPE_CONTROL)
9259 + | USBA_BF(BK_NUMBER, USBA_BK_NUMBER_ONE)));
9260 + usba_ep_writel(ep0, CTL_ENB,
9261 + USBA_BIT(EPT_ENABLE) | USBA_BIT(RX_SETUP));
9262 + usba_writel(udc, INT_ENB, (usba_readl(udc, INT_ENB)
9263 + | USBA_BF(EPT_INT, 1)
9264 + | USBA_BIT(DET_SUSPEND)
9265 + | USBA_BIT(END_OF_RESUME)));
9267 + if (!(usba_ep_readl(ep0, CFG) & USBA_BIT(EPT_MAPPED)))
9268 + dev_warn(&udc->pdev->dev,
9269 + "WARNING: EP0 configuration is invalid!\n");
9272 + spin_unlock(&udc->lock);
9274 + return IRQ_HANDLED;
9277 +static irqreturn_t usba_vbus_irq(int irq, void *devid)
9279 + struct usba_udc *udc = devid;
9285 + spin_lock(&udc->lock);
9286 + vbus = gpio_get_value(udc->vbus_pin);
9287 + if (vbus != udc->vbus_prev) {
9289 + usba_writel(udc, CTRL, USBA_BIT(EN_USBA));
9290 + usba_writel(udc, INT_ENB, USBA_BIT(END_OF_RESET));
9292 + udc->gadget.speed = USB_SPEED_UNKNOWN;
9293 + reset_all_endpoints(udc);
9294 + usba_writel(udc, CTRL, 0);
9296 + udc->driver->disconnect(&udc->gadget);
9298 + udc->vbus_prev = vbus;
9300 + spin_unlock(&udc->lock);
9302 + return IRQ_HANDLED;
9305 +int usb_gadget_register_driver(struct usb_gadget_driver *driver)
9307 + struct usba_udc *udc = &the_udc;
9308 + unsigned long flags;
9314 + spin_lock_irqsave(&udc->lock, flags);
9315 + if (udc->driver) {
9316 + spin_unlock_irqrestore(&udc->lock, flags);
9320 + udc->driver = driver;
9321 + udc->gadget.dev.driver = &driver->driver;
9322 + spin_unlock_irqrestore(&udc->lock, flags);
9324 + clk_enable(udc->pclk);
9325 + clk_enable(udc->hclk);
9327 + ret = driver->bind(&udc->gadget);
9329 + DBG(DBG_ERR, "Could not bind to driver %s: error %d\n",
9330 + driver->driver.name, ret);
9331 + goto err_driver_bind;
9334 + DBG(DBG_GADGET, "registered driver `%s'\n", driver->driver.name);
9336 + udc->vbus_prev = 0;
9337 + if (udc->vbus_pin != -1) {
9338 + ret = request_irq(gpio_to_irq(udc->vbus_pin),
9339 + usba_vbus_irq, 0, "atmel_usba_udc", udc);
9341 + gpio_free(udc->vbus_pin);
9342 + udc->vbus_pin = -1;
9343 + dev_warn(&udc->pdev->dev,
9344 + "failed to request vbus irq; "
9345 + "assuming always on\n");
9349 + /* If Vbus is present, enable the controller and wait for reset */
9350 + spin_lock_irqsave(&udc->lock, flags);
9351 + if (vbus_is_present(udc) && udc->vbus_prev == 0) {
9352 + usba_writel(udc, CTRL, USBA_BIT(EN_USBA));
9353 + usba_writel(udc, INT_ENB, USBA_BIT(END_OF_RESET));
9355 + spin_unlock_irqrestore(&udc->lock, flags);
9360 + udc->driver = NULL;
9361 + udc->gadget.dev.driver = NULL;
9364 +EXPORT_SYMBOL(usb_gadget_register_driver);
9366 +int usb_gadget_unregister_driver(struct usb_gadget_driver *driver)
9368 + struct usba_udc *udc = &the_udc;
9369 + unsigned long flags;
9373 + if (driver != udc->driver)
9376 + if (udc->vbus_pin != -1)
9377 + free_irq(gpio_to_irq(udc->vbus_pin), udc);
9379 + spin_lock_irqsave(&udc->lock, flags);
9380 + udc->gadget.speed = USB_SPEED_UNKNOWN;
9381 + reset_all_endpoints(udc);
9382 + spin_unlock_irqrestore(&udc->lock, flags);
9384 + /* This will also disable the DP pullup */
9385 + usba_writel(udc, CTRL, 0);
9387 + driver->unbind(&udc->gadget);
9388 + udc->gadget.dev.driver = NULL;
9389 + udc->driver = NULL;
9391 + clk_disable(udc->hclk);
9392 + clk_disable(udc->pclk);
9394 + DBG(DBG_GADGET, "unregistered driver `%s'\n", driver->driver.name);
9398 +EXPORT_SYMBOL(usb_gadget_unregister_driver);
9400 +static int __devinit usba_udc_probe(struct platform_device *pdev)
9402 + struct usba_platform_data *pdata = pdev->dev.platform_data;
9403 + struct resource *regs, *fifo;
9404 + struct clk *pclk, *hclk;
9405 + struct usba_udc *udc = &the_udc;
9408 + regs = platform_get_resource(pdev, IORESOURCE_MEM, CTRL_IOMEM_ID);
9409 + fifo = platform_get_resource(pdev, IORESOURCE_MEM, FIFO_IOMEM_ID);
9410 + if (!regs || !fifo)
9413 + irq = platform_get_irq(pdev, 0);
9417 + pclk = clk_get(&pdev->dev, "pclk");
9419 + return PTR_ERR(pclk);
9420 + hclk = clk_get(&pdev->dev, "hclk");
9421 + if (IS_ERR(hclk)) {
9422 + ret = PTR_ERR(hclk);
9423 + goto err_get_hclk;
9429 + udc->vbus_pin = -1;
9432 + udc->regs = ioremap(regs->start, regs->end - regs->start + 1);
9434 + dev_err(&pdev->dev, "Unable to map I/O memory, aborting.\n");
9435 + goto err_map_regs;
9437 + dev_info(&pdev->dev, "MMIO registers at 0x%08lx mapped at %p\n",
9438 + (unsigned long)regs->start, udc->regs);
9439 + udc->fifo = ioremap(fifo->start, fifo->end - fifo->start + 1);
9441 + dev_err(&pdev->dev, "Unable to map FIFO, aborting.\n");
9442 + goto err_map_fifo;
9444 + dev_info(&pdev->dev, "FIFO at 0x%08lx mapped at %p\n",
9445 + (unsigned long)fifo->start, udc->fifo);
9447 + device_initialize(&udc->gadget.dev);
9448 + udc->gadget.dev.parent = &pdev->dev;
9449 + udc->gadget.dev.dma_mask = pdev->dev.dma_mask;
9451 + platform_set_drvdata(pdev, udc);
9453 + /* Make sure we start from a clean slate */
9455 + usba_writel(udc, CTRL, 0);
9456 + clk_disable(pclk);
9458 + INIT_LIST_HEAD(&usba_ep[0].ep.ep_list);
9459 + usba_ep[0].ep_regs = udc->regs + USBA_EPT_BASE(0);
9460 + usba_ep[0].dma_regs = udc->regs + USBA_DMA_BASE(0);
9461 + usba_ep[0].fifo = udc->fifo + USBA_FIFO_BASE(0);
9462 + for (i = 1; i < ARRAY_SIZE(usba_ep); i++) {
9463 + struct usba_ep *ep = &usba_ep[i];
9465 + ep->ep_regs = udc->regs + USBA_EPT_BASE(i);
9466 + ep->dma_regs = udc->regs + USBA_DMA_BASE(i);
9467 + ep->fifo = udc->fifo + USBA_FIFO_BASE(i);
9469 + list_add_tail(&ep->ep.ep_list, &udc->gadget.ep_list);
9472 + ret = request_irq(irq, usba_udc_irq, IRQF_SAMPLE_RANDOM,
9473 + "atmel_usba_udc", udc);
9475 + dev_err(&pdev->dev, "Cannot request irq %d (error %d)\n",
9477 + goto err_request_irq;
9481 + ret = device_add(&udc->gadget.dev);
9483 + dev_dbg(&pdev->dev, "Could not add gadget: %d\n", ret);
9484 + goto err_device_add;
9487 + if (pdata && pdata->vbus_pin != GPIO_PIN_NONE)
9488 + if (!gpio_request(pdata->vbus_pin, "atmel_usba_udc"))
9489 + udc->vbus_pin = pdata->vbus_pin;
9491 + usba_init_debugfs(udc);
9492 + for (i = 1; i < ARRAY_SIZE(usba_ep); i++)
9493 + usba_ep_init_debugfs(udc, &usba_ep[i]);
9498 + free_irq(irq, udc);
9500 + iounmap(udc->fifo);
9502 + iounmap(udc->regs);
9508 + platform_set_drvdata(pdev, NULL);
9513 +static int __devexit usba_udc_remove(struct platform_device *pdev)
9515 + struct usba_udc *udc;
9518 + udc = platform_get_drvdata(pdev);
9520 + for (i = 1; i < ARRAY_SIZE(usba_ep); i++)
9521 + usba_ep_cleanup_debugfs(&usba_ep[i]);
9522 + usba_cleanup_debugfs(udc);
9524 + if (udc->vbus_pin != -1)
9525 + gpio_free(udc->vbus_pin);
9527 + free_irq(udc->irq, udc);
9528 + iounmap(udc->fifo);
9529 + iounmap(udc->regs);
9530 + clk_put(udc->hclk);
9531 + clk_put(udc->pclk);
9533 + device_unregister(&udc->gadget.dev);
9538 +static struct platform_driver udc_driver = {
9539 + .probe = usba_udc_probe,
9540 + .remove = __devexit_p(usba_udc_remove),
9542 + .name = "atmel_usba_udc",
9546 +static int __init udc_init(void)
9548 + return platform_driver_register(&udc_driver);
9550 +module_init(udc_init);
9552 +static void __exit udc_exit(void)
9554 + platform_driver_unregister(&udc_driver);
9556 +module_exit(udc_exit);
9558 +MODULE_DESCRIPTION("Atmel USBA UDC driver");
9559 +MODULE_AUTHOR("Haavard Skinnemoen <hskinnemoen@atmel.com>");
9560 +MODULE_LICENSE("GPL");
9561 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
9562 --- linux-2.6.22.1/drivers/usb/gadget/atmel_usba_udc.h 1970-01-01 01:00:00.000000000 +0100
9563 +++ linux-avr32.git/drivers/usb/gadget/atmel_usba_udc.h 2007-07-12 14:00:19.000000000 +0200
9566 + * Driver for the Atmel USBA high speed USB device controller
9568 + * Copyright (C) 2005-2007 Atmel Corporation
9570 + * This program is free software; you can redistribute it and/or modify
9571 + * it under the terms of the GNU General Public License version 2 as
9572 + * published by the Free Software Foundation.
9574 +#ifndef __LINUX_USB_GADGET_USBA_UDC_H__
9575 +#define __LINUX_USB_GADGET_USBA_UDC_H__
9577 +/* USB register offsets */
9578 +#define USBA_CTRL 0x0000
9579 +#define USBA_FNUM 0x0004
9580 +#define USBA_INT_ENB 0x0010
9581 +#define USBA_INT_STA 0x0014
9582 +#define USBA_INT_CLR 0x0018
9583 +#define USBA_EPT_RST 0x001c
9584 +#define USBA_TST_SOF_CNT 0x00d0
9585 +#define USBA_TST_CNT_A 0x00d4
9586 +#define USBA_TST_CNT_B 0x00d8
9587 +#define USBA_TST_MODE_REG 0x00dc
9588 +#define USBA_TST 0x00e0
9590 +/* USB endpoint register offsets */
9591 +#define USBA_EPT_CFG 0x0000
9592 +#define USBA_EPT_CTL_ENB 0x0004
9593 +#define USBA_EPT_CTL_DIS 0x0008
9594 +#define USBA_EPT_CTL 0x000c
9595 +#define USBA_EPT_SET_STA 0x0014
9596 +#define USBA_EPT_CLR_STA 0x0018
9597 +#define USBA_EPT_STA 0x001c
9599 +/* USB DMA register offsets */
9600 +#define USBA_DMA_NXT_DSC 0x0000
9601 +#define USBA_DMA_ADDRESS 0x0004
9602 +#define USBA_DMA_CONTROL 0x0008
9603 +#define USBA_DMA_STATUS 0x000c
9605 +/* Bitfields in CTRL */
9606 +#define USBA_DEV_ADDR_OFFSET 0
9607 +#define USBA_DEV_ADDR_SIZE 7
9608 +#define USBA_FADDR_EN_OFFSET 7
9609 +#define USBA_FADDR_EN_SIZE 1
9610 +#define USBA_EN_USBA_OFFSET 8
9611 +#define USBA_EN_USBA_SIZE 1
9612 +#define USBA_DETACH_OFFSET 9
9613 +#define USBA_DETACH_SIZE 1
9614 +#define USBA_REMOTE_WAKE_UP_OFFSET 10
9615 +#define USBA_REMOTE_WAKE_UP_SIZE 1
9617 +/* Bitfields in FNUM */
9618 +#define USBA_MICRO_FRAME_NUM_OFFSET 0
9619 +#define USBA_MICRO_FRAME_NUM_SIZE 3
9620 +#define USBA_FRAME_NUMBER_OFFSET 3
9621 +#define USBA_FRAME_NUMBER_SIZE 11
9622 +#define USBA_FRAME_NUM_ERROR_OFFSET 31
9623 +#define USBA_FRAME_NUM_ERROR_SIZE 1
9625 +/* Bitfields in INT_ENB/INT_STA/INT_CLR */
9626 +#define USBA_HIGH_SPEED_OFFSET 0
9627 +#define USBA_HIGH_SPEED_SIZE 1
9628 +#define USBA_DET_SUSPEND_OFFSET 1
9629 +#define USBA_DET_SUSPEND_SIZE 1
9630 +#define USBA_MICRO_SOF_OFFSET 2
9631 +#define USBA_MICRO_SOF_SIZE 1
9632 +#define USBA_SOF_OFFSET 3
9633 +#define USBA_SOF_SIZE 1
9634 +#define USBA_END_OF_RESET_OFFSET 4
9635 +#define USBA_END_OF_RESET_SIZE 1
9636 +#define USBA_WAKE_UP_OFFSET 5
9637 +#define USBA_WAKE_UP_SIZE 1
9638 +#define USBA_END_OF_RESUME_OFFSET 6
9639 +#define USBA_END_OF_RESUME_SIZE 1
9640 +#define USBA_UPSTREAM_RESUME_OFFSET 7
9641 +#define USBA_UPSTREAM_RESUME_SIZE 1
9642 +#define USBA_EPT_INT_OFFSET 8
9643 +#define USBA_EPT_INT_SIZE 16
9644 +#define USBA_DMA_INT_OFFSET 24
9645 +#define USBA_DMA_INT_SIZE 8
9647 +/* Bitfields in EPT_RST */
9648 +#define USBA_RST_OFFSET 0
9649 +#define USBA_RST_SIZE 16
9651 +/* Bitfields in TST_SOF_CNT */
9652 +#define USBA_SOF_CNT_MAX_OFFSET 0
9653 +#define USBA_SOF_CNT_MAX_SIZE 7
9654 +#define USBA_SOF_CNT_LOAD_OFFSET 7
9655 +#define USBA_SOF_CNT_LOAD_SIZE 1
9657 +/* Bitfields in TST_CNT_A */
9658 +#define USBA_CNT_A_MAX_OFFSET 0
9659 +#define USBA_CNT_A_MAX_SIZE 7
9660 +#define USBA_CNT_A_LOAD_OFFSET 7
9661 +#define USBA_CNT_A_LOAD_SIZE 1
9663 +/* Bitfields in TST_CNT_B */
9664 +#define USBA_CNT_B_MAX_OFFSET 0
9665 +#define USBA_CNT_B_MAX_SIZE 7
9666 +#define USBA_CNT_B_LOAD_OFFSET 7
9667 +#define USBA_CNT_B_LOAD_SIZE 1
9669 +/* Bitfields in TST_MODE_REG */
9670 +#define USBA_TST_MODE_OFFSET 0
9671 +#define USBA_TST_MODE_SIZE 6
9673 +/* Bitfields in USBA_TST */
9674 +#define USBA_SPEED_CFG_OFFSET 0
9675 +#define USBA_SPEED_CFG_SIZE 2
9676 +#define USBA_TST_J_MODE_OFFSET 2
9677 +#define USBA_TST_J_MODE_SIZE 1
9678 +#define USBA_TST_K_MODE_OFFSET 3
9679 +#define USBA_TST_K_MODE_SIZE 1
9680 +#define USBA_TST_PKT_MODE_OFFSET 4
9681 +#define USBA_TST_PKT_MODE_SIZE 1
9682 +#define USBA_OPMODE2_OFFSET 5
9683 +#define USBA_OPMODE2_SIZE 1
9685 +/* Bitfields in EPT_CFG */
9686 +#define USBA_EPT_SIZE_OFFSET 0
9687 +#define USBA_EPT_SIZE_SIZE 3
9688 +#define USBA_EPT_DIR_OFFSET 3
9689 +#define USBA_EPT_DIR_SIZE 1
9690 +#define USBA_EPT_TYPE_OFFSET 4
9691 +#define USBA_EPT_TYPE_SIZE 2
9692 +#define USBA_BK_NUMBER_OFFSET 6
9693 +#define USBA_BK_NUMBER_SIZE 2
9694 +#define USBA_NB_TRANS_OFFSET 8
9695 +#define USBA_NB_TRANS_SIZE 2
9696 +#define USBA_EPT_MAPPED_OFFSET 31
9697 +#define USBA_EPT_MAPPED_SIZE 1
9699 +/* Bitfields in EPT_CTL/EPT_CTL_ENB/EPT_CTL_DIS */
9700 +#define USBA_EPT_ENABLE_OFFSET 0
9701 +#define USBA_EPT_ENABLE_SIZE 1
9702 +#define USBA_AUTO_VALID_OFFSET 1
9703 +#define USBA_AUTO_VALID_SIZE 1
9704 +#define USBA_INTDIS_DMA_OFFSET 3
9705 +#define USBA_INTDIS_DMA_SIZE 1
9706 +#define USBA_NYET_DIS_OFFSET 4
9707 +#define USBA_NYET_DIS_SIZE 1
9708 +#define USBA_DATAX_RX_OFFSET 6
9709 +#define USBA_DATAX_RX_SIZE 1
9710 +#define USBA_MDATA_RX_OFFSET 7
9711 +#define USBA_MDATA_RX_SIZE 1
9712 +/* Bits 8-15 and 31 enable interrupts for respective bits in EPT_STA */
9713 +#define USBA_BUSY_BANK_IE_OFFSET 18
9714 +#define USBA_BUSY_BANK_IE_SIZE 1
9716 +/* Bitfields in EPT_SET_STA/EPT_CLR_STA/EPT_STA */
9717 +#define USBA_FORCE_STALL_OFFSET 5
9718 +#define USBA_FORCE_STALL_SIZE 1
9719 +#define USBA_TOGGLE_SEQ_OFFSET 6
9720 +#define USBA_TOGGLE_SEQ_SIZE 2
9721 +#define USBA_ERR_OVFLW_OFFSET 8
9722 +#define USBA_ERR_OVFLW_SIZE 1
9723 +#define USBA_RX_BK_RDY_OFFSET 9
9724 +#define USBA_RX_BK_RDY_SIZE 1
9725 +#define USBA_KILL_BANK_OFFSET 9
9726 +#define USBA_KILL_BANK_SIZE 1
9727 +#define USBA_TX_COMPLETE_OFFSET 10
9728 +#define USBA_TX_COMPLETE_SIZE 1
9729 +#define USBA_TX_PK_RDY_OFFSET 11
9730 +#define USBA_TX_PK_RDY_SIZE 1
9731 +#define USBA_ISO_ERR_TRANS_OFFSET 11
9732 +#define USBA_ISO_ERR_TRANS_SIZE 1
9733 +#define USBA_RX_SETUP_OFFSET 12
9734 +#define USBA_RX_SETUP_SIZE 1
9735 +#define USBA_ISO_ERR_FLOW_OFFSET 12
9736 +#define USBA_ISO_ERR_FLOW_SIZE 1
9737 +#define USBA_STALL_SENT_OFFSET 13
9738 +#define USBA_STALL_SENT_SIZE 1
9739 +#define USBA_ISO_ERR_CRC_OFFSET 13
9740 +#define USBA_ISO_ERR_CRC_SIZE 1
9741 +#define USBA_ISO_ERR_NBTRANS_OFFSET 13
9742 +#define USBA_ISO_ERR_NBTRANS_SIZE 1
9743 +#define USBA_NAK_IN_OFFSET 14
9744 +#define USBA_NAK_IN_SIZE 1
9745 +#define USBA_ISO_ERR_FLUSH_OFFSET 14
9746 +#define USBA_ISO_ERR_FLUSH_SIZE 1
9747 +#define USBA_NAK_OUT_OFFSET 15
9748 +#define USBA_NAK_OUT_SIZE 1
9749 +#define USBA_CURRENT_BANK_OFFSET 16
9750 +#define USBA_CURRENT_BANK_SIZE 2
9751 +#define USBA_BUSY_BANKS_OFFSET 18
9752 +#define USBA_BUSY_BANKS_SIZE 2
9753 +#define USBA_BYTE_COUNT_OFFSET 20
9754 +#define USBA_BYTE_COUNT_SIZE 11
9755 +#define USBA_SHORT_PACKET_OFFSET 31
9756 +#define USBA_SHORT_PACKET_SIZE 1
9758 +/* Bitfields in DMA_CONTROL */
9759 +#define USBA_DMA_CH_EN_OFFSET 0
9760 +#define USBA_DMA_CH_EN_SIZE 1
9761 +#define USBA_DMA_LINK_OFFSET 1
9762 +#define USBA_DMA_LINK_SIZE 1
9763 +#define USBA_DMA_END_TR_EN_OFFSET 2
9764 +#define USBA_DMA_END_TR_EN_SIZE 1
9765 +#define USBA_DMA_END_BUF_EN_OFFSET 3
9766 +#define USBA_DMA_END_BUF_EN_SIZE 1
9767 +#define USBA_DMA_END_TR_IE_OFFSET 4
9768 +#define USBA_DMA_END_TR_IE_SIZE 1
9769 +#define USBA_DMA_END_BUF_IE_OFFSET 5
9770 +#define USBA_DMA_END_BUF_IE_SIZE 1
9771 +#define USBA_DMA_DESC_LOAD_IE_OFFSET 6
9772 +#define USBA_DMA_DESC_LOAD_IE_SIZE 1
9773 +#define USBA_DMA_BURST_LOCK_OFFSET 7
9774 +#define USBA_DMA_BURST_LOCK_SIZE 1
9775 +#define USBA_DMA_BUF_LEN_OFFSET 16
9776 +#define USBA_DMA_BUF_LEN_SIZE 16
9778 +/* Bitfields in DMA_STATUS */
9779 +#define USBA_DMA_CH_ACTIVE_OFFSET 1
9780 +#define USBA_DMA_CH_ACTIVE_SIZE 1
9781 +#define USBA_DMA_END_TR_ST_OFFSET 4
9782 +#define USBA_DMA_END_TR_ST_SIZE 1
9783 +#define USBA_DMA_END_BUF_ST_OFFSET 5
9784 +#define USBA_DMA_END_BUF_ST_SIZE 1
9785 +#define USBA_DMA_DESC_LOAD_ST_OFFSET 6
9786 +#define USBA_DMA_DESC_LOAD_ST_SIZE 1
9788 +/* Constants for SPEED_CFG */
9789 +#define USBA_SPEED_CFG_NORMAL 0
9790 +#define USBA_SPEED_CFG_FORCE_HIGH 2
9791 +#define USBA_SPEED_CFG_FORCE_FULL 3
9793 +/* Constants for EPT_SIZE */
9794 +#define USBA_EPT_SIZE_8 0
9795 +#define USBA_EPT_SIZE_16 1
9796 +#define USBA_EPT_SIZE_32 2
9797 +#define USBA_EPT_SIZE_64 3
9798 +#define USBA_EPT_SIZE_128 4
9799 +#define USBA_EPT_SIZE_256 5
9800 +#define USBA_EPT_SIZE_512 6
9801 +#define USBA_EPT_SIZE_1024 7
9803 +/* Constants for EPT_TYPE */
9804 +#define USBA_EPT_TYPE_CONTROL 0
9805 +#define USBA_EPT_TYPE_ISO 1
9806 +#define USBA_EPT_TYPE_BULK 2
9807 +#define USBA_EPT_TYPE_INT 3
9809 +/* Constants for BK_NUMBER */
9810 +#define USBA_BK_NUMBER_ZERO 0
9811 +#define USBA_BK_NUMBER_ONE 1
9812 +#define USBA_BK_NUMBER_DOUBLE 2
9813 +#define USBA_BK_NUMBER_TRIPLE 3
9815 +/* Bit manipulation macros */
9816 +#define USBA_BIT(name) \
9817 + (1 << USBA_##name##_OFFSET)
9818 +#define USBA_BF(name, value) \
9819 + (((value) & ((1 << USBA_##name##_SIZE) - 1)) \
9820 + << USBA_##name##_OFFSET)
9821 +#define USBA_BFEXT(name, value) \
9822 + (((value) >> USBA_##name##_OFFSET) \
9823 + & ((1 << USBA_##name##_SIZE) - 1))
9824 +#define USBA_BFINS(name, value, old) \
9825 + (((old) & ~(((1 << USBA_##name##_SIZE) - 1) \
9826 + << USBA_##name##_OFFSET)) \
9827 + | USBA_BF(name, value))
9829 +/* Register access macros */
9830 +#define usba_readl(udc, reg) \
9831 + __raw_readl((udc)->regs + USBA_##reg)
9832 +#define usba_writel(udc, reg, value) \
9833 + __raw_writel((value), (udc)->regs + USBA_##reg)
9834 +#define usba_ep_readl(ep, reg) \
9835 + __raw_readl((ep)->ep_regs + USBA_EPT_##reg)
9836 +#define usba_ep_writel(ep, reg, value) \
9837 + __raw_writel((value), (ep)->ep_regs + USBA_EPT_##reg)
9838 +#define usba_dma_readl(ep, reg) \
9839 + __raw_readl((ep)->dma_regs + USBA_DMA_##reg)
9840 +#define usba_dma_writel(ep, reg, value) \
9841 + __raw_writel((value), (ep)->dma_regs + USBA_DMA_##reg)
9843 +/* Calculate base address for a given endpoint or DMA controller */
9844 +#define USBA_EPT_BASE(x) (0x100 + (x) * 0x20)
9845 +#define USBA_DMA_BASE(x) (0x300 + (x) * 0x10)
9846 +#define USBA_FIFO_BASE(x) ((x) << 16)
9848 +/* Synth parameters */
9849 +#define USBA_NR_ENDPOINTS 7
9851 +#define EP0_FIFO_SIZE 64
9852 +#define EP0_EPT_SIZE USBA_EPT_SIZE_64
9853 +#define EP0_NR_BANKS 1
9854 +#define BULK_FIFO_SIZE 512
9855 +#define BULK_EPT_SIZE USBA_EPT_SIZE_512
9856 +#define BULK_NR_BANKS 2
9857 +#define ISO_FIFO_SIZE 1024
9858 +#define ISO_EPT_SIZE USBA_EPT_SIZE_1024
9859 +#define ISO_NR_BANKS 3
9860 +#define INT_FIFO_SIZE 64
9861 +#define INT_EPT_SIZE USBA_EPT_SIZE_64
9862 +#define INT_NR_BANKS 3
9864 +enum usba_ctrl_state {
9870 + STATUS_STAGE_ADDR,
9871 + STATUS_STAGE_TEST,
9877 + EP_STATE_OUT_DATA,
9878 + EP_STATE_SET_ADDR_STATUS,
9879 + EP_STATE_RX_STATUS,
9880 + EP_STATE_TX_STATUS,
9884 +struct usba_dma_desc {
9892 + void __iomem *ep_regs;
9893 + void __iomem *dma_regs;
9894 + void __iomem *fifo;
9896 + struct usba_udc *udc;
9898 + struct list_head queue;
9899 + const struct usb_endpoint_descriptor *desc;
9904 + unsigned int can_dma:1;
9905 + unsigned int can_isoc:1;
9906 + unsigned int is_isoc:1;
9907 + unsigned int is_in:1;
9909 +#ifdef CONFIG_DEBUG_FS
9910 + u32 last_dma_status;
9911 + struct dentry *debugfs_dir;
9912 + struct dentry *debugfs_queue;
9913 + struct dentry *debugfs_dma_status;
9914 + struct dentry *debugfs_state;
9918 +struct usba_request {
9919 + struct usb_request req;
9920 + struct list_head queue;
9924 + unsigned int submitted:1;
9925 + unsigned int last_transaction:1;
9926 + unsigned int using_dma:1;
9927 + unsigned int mapped:1;
9931 + /* Protect hw registers from concurrent modifications */
9934 + void __iomem *regs;
9935 + void __iomem *fifo;
9937 + struct usb_gadget gadget;
9938 + struct usb_gadget_driver *driver;
9939 + struct platform_device *pdev;
9948 +#ifdef CONFIG_DEBUG_FS
9949 + struct dentry *debugfs_root;
9950 + struct dentry *debugfs_regs;
9954 +#define to_usba_ep(x) container_of((x), struct usba_ep, ep)
9955 +#define to_usba_req(x) container_of((x), struct usba_request, req)
9956 +#define to_usba_udc(x) container_of((x), struct usba_udc, gadget)
9958 +#define ep_index(ep) ((ep)->index)
9959 +#define ep_can_dma(ep) ((ep)->can_dma)
9960 +#define ep_is_in(ep) ((ep)->is_in)
9961 +#define ep_is_isochronous(ep) ((ep)->is_isoc)
9962 +#define ep_is_control(ep) (ep_index(ep) == 0)
9963 +#define ep_name(ep) ((ep)->ep.name)
9964 +#define ep_is_idle(ep) ((ep)->state == EP_STATE_IDLE)
9966 +#endif /* __LINUX_USB_GADGET_USBA_UDC_H */
9967 diff -x .git -Nur linux-2.6.22.1/drivers/usb/gadget/ether.c linux-avr32.git/drivers/usb/gadget/ether.c
9968 --- linux-2.6.22.1/drivers/usb/gadget/ether.c 2007-07-10 20:56:30.000000000 +0200
9969 +++ linux-avr32.git/drivers/usb/gadget/ether.c 2007-07-12 14:00:19.000000000 +0200
9971 #define DEV_CONFIG_CDC
9974 -#ifdef CONFIG_USB_GADGET_HUSB2DEV
9975 +#ifdef CONFIG_USB_GADGET_ATMEL_USBA
9976 #define DEV_CONFIG_CDC
9979 diff -x .git -Nur linux-2.6.22.1/drivers/usb/gadget/gadget_chips.h linux-avr32.git/drivers/usb/gadget/gadget_chips.h
9980 --- linux-2.6.22.1/drivers/usb/gadget/gadget_chips.h 2007-07-10 20:56:30.000000000 +0200
9981 +++ linux-avr32.git/drivers/usb/gadget/gadget_chips.h 2007-07-12 14:00:19.000000000 +0200
9983 #define gadget_is_pxa27x(g) 0
9986 -#ifdef CONFIG_USB_GADGET_HUSB2DEV
9987 -#define gadget_is_husb2dev(g) !strcmp("husb2_udc", (g)->name)
9988 +#ifdef CONFIG_USB_GADGET_ATMEL_USBA
9989 +#define gadget_is_atmel_usba(g) !strcmp("atmel_usba_udc", (g)->name)
9991 -#define gadget_is_husb2dev(g) 0
9992 +#define gadget_is_atmel_usba(g) 0
9995 #ifdef CONFIG_USB_GADGET_S3C2410
9998 else if (gadget_is_mpc8272(gadget))
10000 - else if (gadget_is_husb2dev(gadget))
10001 + else if (gadget_is_atmel_usba(gadget))
10003 else if (gadget_is_fsl_usb2(gadget))
10005 diff -x .git -Nur linux-2.6.22.1/drivers/usb/gadget/inode.c linux-avr32.git/drivers/usb/gadget/inode.c
10006 --- linux-2.6.22.1/drivers/usb/gadget/inode.c 2007-07-10 20:56:30.000000000 +0200
10007 +++ linux-avr32.git/drivers/usb/gadget/inode.c 2007-07-12 14:00:19.000000000 +0200
10009 #include <linux/device.h>
10010 #include <linux/moduleparam.h>
10012 -#include <linux/usb_gadgetfs.h>
10013 +#include <linux/usb/gadgetfs.h>
10014 #include <linux/usb_gadget.h>
10017 diff -x .git -Nur linux-2.6.22.1/drivers/usb/gadget/Kconfig linux-avr32.git/drivers/usb/gadget/Kconfig
10018 --- linux-2.6.22.1/drivers/usb/gadget/Kconfig 2007-07-10 20:56:30.000000000 +0200
10019 +++ linux-avr32.git/drivers/usb/gadget/Kconfig 2007-07-12 14:00:19.000000000 +0200
10020 @@ -175,6 +175,19 @@
10022 select USB_GADGET_SELECTED
10024 +config USB_GADGET_ATMEL_USBA
10025 + boolean "Atmel USBA"
10026 + select USB_GADGET_DUALSPEED
10029 + USBA is the integrated high-speed USB Device controller on
10030 + the AT32AP700x processors from Atmel.
10032 +config USB_ATMEL_USBA
10034 + depends on USB_GADGET_ATMEL_USBA
10035 + default USB_GADGET
10036 + select USB_GADGET_SELECTED
10038 config USB_GADGET_OMAP
10039 boolean "OMAP USB Device Controller"
10040 diff -x .git -Nur linux-2.6.22.1/drivers/usb/gadget/Makefile linux-avr32.git/drivers/usb/gadget/Makefile
10041 --- linux-2.6.22.1/drivers/usb/gadget/Makefile 2007-07-10 20:56:30.000000000 +0200
10042 +++ linux-avr32.git/drivers/usb/gadget/Makefile 2007-07-12 14:00:19.000000000 +0200
10044 obj-$(CONFIG_USB_OMAP) += omap_udc.o
10045 obj-$(CONFIG_USB_LH7A40X) += lh7a40x_udc.o
10046 obj-$(CONFIG_USB_AT91) += at91_udc.o
10047 +obj-$(CONFIG_USB_ATMEL_USBA) += atmel_usba_udc.o
10048 obj-$(CONFIG_USB_FSL_USB2) += fsl_usb2_udc.o
10051 diff -x .git -Nur linux-2.6.22.1/drivers/video/atmel_lcdfb.c linux-avr32.git/drivers/video/atmel_lcdfb.c
10052 --- linux-2.6.22.1/drivers/video/atmel_lcdfb.c 2007-07-10 20:56:30.000000000 +0200
10053 +++ linux-avr32.git/drivers/video/atmel_lcdfb.c 2007-07-12 14:00:20.000000000 +0200
10057 #if defined(CONFIG_ARCH_AT91)
10058 -#define ATMEL_LCDFB_FBINFO_DEFAULT FBINFO_DEFAULT
10059 +#define ATMEL_LCDFB_FBINFO_DEFAULT (FBINFO_DEFAULT \
10060 + | FBINFO_PARTIAL_PAN_OK \
10061 + | FBINFO_HWACCEL_YPAN)
10063 static inline void atmel_lcdfb_update_dma2d(struct atmel_lcdfb_info *sinfo,
10064 struct fb_var_screeninfo *var)
10065 @@ -74,11 +76,34 @@
10066 .type = FB_TYPE_PACKED_PIXELS,
10067 .visual = FB_VISUAL_TRUECOLOR,
10072 .accel = FB_ACCEL_NONE,
10075 +static unsigned long compute_hozval(unsigned long xres, unsigned long lcdcon2)
10077 + unsigned long value;
10079 + if (!(cpu_is_at91sam9261() || cpu_is_at32ap7000()))
10083 + if ((lcdcon2 & ATMEL_LCDC_DISTYPE) != ATMEL_LCDC_DISTYPE_TFT) {
10084 + /* STN display */
10085 + if ((lcdcon2 & ATMEL_LCDC_DISTYPE) == ATMEL_LCDC_DISTYPE_STNCOLOR) {
10088 + if ( (lcdcon2 & ATMEL_LCDC_IFWIDTH) == ATMEL_LCDC_IFWIDTH_4
10089 + || ( (lcdcon2 & ATMEL_LCDC_IFWIDTH) == ATMEL_LCDC_IFWIDTH_8
10090 + && (lcdcon2 & ATMEL_LCDC_SCANMOD) == ATMEL_LCDC_SCANMOD_DUAL ))
10091 + value = DIV_ROUND_UP(value, 4);
10093 + value = DIV_ROUND_UP(value, 8);
10099 static void atmel_lcdfb_update_dma(struct fb_info *info,
10100 struct fb_var_screeninfo *var)
10101 @@ -181,6 +206,7 @@
10102 var->xoffset = var->yoffset = 0;
10104 switch (var->bits_per_pixel) {
10109 @@ -195,8 +221,11 @@
10110 var->blue.offset = 10;
10111 var->red.length = var->green.length = var->blue.length = 5;
10115 + var->transp.offset = 24;
10116 + var->transp.length = 8;
10117 + /* fall through */
10119 var->red.offset = 0;
10120 var->green.offset = 8;
10121 var->blue.offset = 16;
10122 @@ -228,8 +257,10 @@
10123 static int atmel_lcdfb_set_par(struct fb_info *info)
10125 struct atmel_lcdfb_info *sinfo = info->par;
10126 + unsigned long hozval_linesz;
10127 unsigned long value;
10128 unsigned long clk_value_khz;
10129 + unsigned long bits_per_line;
10131 dev_dbg(info->device, "%s:\n", __func__);
10132 dev_dbg(info->device, " * resolution: %ux%u (%ux%u virtual)\n",
10133 @@ -241,12 +272,15 @@
10135 lcdc_writel(sinfo, ATMEL_LCDC_DMACON, 0);
10137 - if (info->var.bits_per_pixel <= 8)
10138 + if (info->var.bits_per_pixel == 1)
10139 + info->fix.visual = FB_VISUAL_MONO01;
10140 + else if (info->var.bits_per_pixel <= 8)
10141 info->fix.visual = FB_VISUAL_PSEUDOCOLOR;
10143 info->fix.visual = FB_VISUAL_TRUECOLOR;
10145 - info->fix.line_length = info->var.xres_virtual * (info->var.bits_per_pixel / 8);
10146 + bits_per_line = info->var.xres_virtual * info->var.bits_per_pixel;
10147 + info->fix.line_length = DIV_ROUND_UP(bits_per_line, 8);
10149 /* Re-initialize the DMA engine... */
10150 dev_dbg(info->device, " * update DMA engine\n");
10151 @@ -262,18 +296,21 @@
10152 /* Set pixel clock */
10153 clk_value_khz = clk_get_rate(sinfo->lcdc_clk) / 1000;
10155 - value = clk_value_khz / PICOS2KHZ(info->var.pixclock);
10157 - if (clk_value_khz % PICOS2KHZ(info->var.pixclock))
10159 + value = DIV_ROUND_UP(clk_value_khz, PICOS2KHZ(info->var.pixclock));
10161 value = (value / 2) - 1;
10162 + dev_dbg(info->device, " * programming CLKVAL = 0x%08lx\n", value);
10165 dev_notice(info->device, "Bypassing pixel clock divider\n");
10166 lcdc_writel(sinfo, ATMEL_LCDC_LCDCON1, ATMEL_LCDC_BYPASS);
10169 lcdc_writel(sinfo, ATMEL_LCDC_LCDCON1, value << ATMEL_LCDC_CLKVAL_OFFSET);
10170 + info->var.pixclock = KHZ2PICOS(clk_value_khz / (2 * (value + 1)));
10171 + dev_dbg(info->device, " updated pixclk: %lu KHz\n",
10172 + PICOS2KHZ(info->var.pixclock));
10176 /* Initialize control register 2 */
10177 value = sinfo->default_lcdcon2;
10178 @@ -311,9 +348,14 @@
10179 dev_dbg(info->device, " * LCDTIM2 = %08lx\n", value);
10180 lcdc_writel(sinfo, ATMEL_LCDC_TIM2, value);
10182 + /* Horizontal value (aka line size) */
10183 + hozval_linesz = compute_hozval(info->var.xres,
10184 + lcdc_readl(sinfo, ATMEL_LCDC_LCDCON2));
10187 - value = (info->var.xres - 1) << ATMEL_LCDC_HOZVAL_OFFSET;
10188 + value = (hozval_linesz - 1) << ATMEL_LCDC_HOZVAL_OFFSET;
10189 value |= info->var.yres - 1;
10190 + dev_dbg(info->device, " * LCDFRMCFG = %08lx\n", value);
10191 lcdc_writel(sinfo, ATMEL_LCDC_LCDFRMCFG, value);
10193 /* FIFO Threshold: Use formula from data sheet */
10194 @@ -421,6 +463,15 @@
10199 + case FB_VISUAL_MONO01:
10201 + val = (regno == 0) ? 0x00 : 0x1F;
10202 + lcdc_writel(sinfo, ATMEL_LCDC_LUT(regno), val);
10210 diff -x .git -Nur linux-2.6.22.1/drivers/video/backlight/Kconfig linux-avr32.git/drivers/video/backlight/Kconfig
10211 --- linux-2.6.22.1/drivers/video/backlight/Kconfig 2007-07-10 20:56:30.000000000 +0200
10212 +++ linux-avr32.git/drivers/video/backlight/Kconfig 2007-07-12 14:00:20.000000000 +0200
10214 Enable this to be able to choose the drivers for controlling the
10215 backlight and the LCD panel on some platforms, for example on PDAs.
10217 -config BACKLIGHT_CLASS_DEVICE
10218 - tristate "Lowlevel Backlight controls"
10222 +config LCD_CLASS_DEVICE
10223 + tristate "Lowlevel LCD controls"
10224 depends on BACKLIGHT_LCD_SUPPORT
10227 - This framework adds support for low-level control of the LCD
10228 - backlight. This includes support for brightness and power.
10229 + This framework adds support for low-level control of LCD.
10230 + Some framebuffer devices connect to platform-specific LCD modules
10231 + in order to have a platform-specific way to control the flat panel
10232 + (contrast and applying power to the LCD (not to the backlight!)).
10234 To have support for your specific LCD panel you will have to
10235 select the proper drivers which depend on this option.
10237 -config LCD_CLASS_DEVICE
10238 - tristate "Lowlevel LCD controls"
10239 +config LCD_LTV350QV
10240 + tristate "Samsung LTV350QV LCD Panel"
10241 + depends on LCD_CLASS_DEVICE && SPI_MASTER
10244 + If you have a Samsung LTV350QV LCD panel, say y to include a
10245 + power control driver for it. The panel starts up in power
10246 + off state, so you need this driver in order to see any
10249 + The LTV350QV panel is present on all ATSTK1000 boards.
10254 +config BACKLIGHT_CLASS_DEVICE
10255 + tristate "Lowlevel Backlight controls"
10256 depends on BACKLIGHT_LCD_SUPPORT
10259 - This framework adds support for low-level control of LCD.
10260 - Some framebuffer devices connect to platform-specific LCD modules
10261 - in order to have a platform-specific way to control the flat panel
10262 - (contrast and applying power to the LCD (not to the backlight!)).
10263 + This framework adds support for low-level control of the LCD
10264 + backlight. This includes support for brightness and power.
10266 To have support for your specific LCD panel you will have to
10267 select the proper drivers which depend on this option.
10268 diff -x .git -Nur linux-2.6.22.1/drivers/video/backlight/ltv350qv.c linux-avr32.git/drivers/video/backlight/ltv350qv.c
10269 --- linux-2.6.22.1/drivers/video/backlight/ltv350qv.c 1970-01-01 01:00:00.000000000 +0100
10270 +++ linux-avr32.git/drivers/video/backlight/ltv350qv.c 2007-06-06 11:34:00.000000000 +0200
10273 + * Power control for Samsung LTV350QV Quarter VGA LCD Panel
10275 + * Copyright (C) 2006, 2007 Atmel Corporation
10277 + * This program is free software; you can redistribute it and/or modify
10278 + * it under the terms of the GNU General Public License version 2 as
10279 + * published by the Free Software Foundation.
10281 +#include <linux/delay.h>
10282 +#include <linux/err.h>
10283 +#include <linux/fb.h>
10284 +#include <linux/init.h>
10285 +#include <linux/lcd.h>
10286 +#include <linux/module.h>
10287 +#include <linux/spi/spi.h>
10289 +#include "ltv350qv.h"
10291 +#define POWER_IS_ON(pwr) ((pwr) <= FB_BLANK_NORMAL)
10294 + struct spi_device *spi;
10297 + struct lcd_device *ld;
10301 + * The power-on and power-off sequences are taken from the
10302 + * LTV350QV-F04 data sheet from Samsung. The register definitions are
10303 + * taken from the S6F2002 command list also from Samsung. Both
10304 + * documents are distributed with the AVR32 Linux BSP CD from Atmel.
10306 + * There's still some voodoo going on here, but it's a lot better than
10307 + * in the first incarnation of the driver where all we had was the raw
10308 + * numbers from the initialization sequence.
10310 +static int ltv350qv_write_reg(struct ltv350qv *lcd, u8 reg, u16 val)
10312 + struct spi_message msg;
10313 + struct spi_transfer index_xfer = {
10317 + struct spi_transfer value_xfer = {
10322 + spi_message_init(&msg);
10324 + /* register index */
10325 + lcd->buffer[0] = LTV_OPC_INDEX;
10326 + lcd->buffer[1] = 0x00;
10327 + lcd->buffer[2] = reg & 0x7f;
10328 + index_xfer.tx_buf = lcd->buffer;
10329 + spi_message_add_tail(&index_xfer, &msg);
10331 + /* register value */
10332 + lcd->buffer[4] = LTV_OPC_DATA;
10333 + lcd->buffer[5] = val >> 8;
10334 + lcd->buffer[6] = val;
10335 + value_xfer.tx_buf = lcd->buffer + 4;
10336 + spi_message_add_tail(&value_xfer, &msg);
10338 + return spi_sync(lcd->spi, &msg);
10341 +/* The comments are taken straight from the data sheet */
10342 +static int ltv350qv_power_on(struct ltv350qv *lcd)
10346 + /* Power On Reset Display off State */
10347 + if (ltv350qv_write_reg(lcd, LTV_PWRCTL1, 0x0000))
10351 + /* Power Setting Function 1 */
10352 + if (ltv350qv_write_reg(lcd, LTV_PWRCTL1, LTV_VCOM_DISABLE))
10354 + if (ltv350qv_write_reg(lcd, LTV_PWRCTL2, LTV_VCOML_ENABLE))
10357 + /* Power Setting Function 2 */
10358 + if (ltv350qv_write_reg(lcd, LTV_PWRCTL1,
10359 + LTV_VCOM_DISABLE | LTV_DRIVE_CURRENT(5)
10360 + | LTV_SUPPLY_CURRENT(5)))
10365 + /* Instruction Setting */
10366 + ret = ltv350qv_write_reg(lcd, LTV_IFCTL,
10367 + LTV_NMD | LTV_REV | LTV_NL(0x1d));
10368 + ret |= ltv350qv_write_reg(lcd, LTV_DATACTL,
10369 + LTV_DS_SAME | LTV_CHS_480
10370 + | LTV_DF_RGB | LTV_RGB_BGR);
10371 + ret |= ltv350qv_write_reg(lcd, LTV_ENTRY_MODE,
10372 + LTV_VSPL_ACTIVE_LOW
10373 + | LTV_HSPL_ACTIVE_LOW
10374 + | LTV_DPL_SAMPLE_RISING
10375 + | LTV_EPL_ACTIVE_LOW
10376 + | LTV_SS_RIGHT_TO_LEFT);
10377 + ret |= ltv350qv_write_reg(lcd, LTV_GATECTL1, LTV_CLW(3));
10378 + ret |= ltv350qv_write_reg(lcd, LTV_GATECTL2,
10379 + LTV_NW_INV_1LINE | LTV_FWI(3));
10380 + ret |= ltv350qv_write_reg(lcd, LTV_VBP, 0x000a);
10381 + ret |= ltv350qv_write_reg(lcd, LTV_HBP, 0x0021);
10382 + ret |= ltv350qv_write_reg(lcd, LTV_SOTCTL, LTV_SDT(3) | LTV_EQ(0));
10383 + ret |= ltv350qv_write_reg(lcd, LTV_GAMMA(0), 0x0103);
10384 + ret |= ltv350qv_write_reg(lcd, LTV_GAMMA(1), 0x0301);
10385 + ret |= ltv350qv_write_reg(lcd, LTV_GAMMA(2), 0x1f0f);
10386 + ret |= ltv350qv_write_reg(lcd, LTV_GAMMA(3), 0x1f0f);
10387 + ret |= ltv350qv_write_reg(lcd, LTV_GAMMA(4), 0x0707);
10388 + ret |= ltv350qv_write_reg(lcd, LTV_GAMMA(5), 0x0307);
10389 + ret |= ltv350qv_write_reg(lcd, LTV_GAMMA(6), 0x0707);
10390 + ret |= ltv350qv_write_reg(lcd, LTV_GAMMA(7), 0x0000);
10391 + ret |= ltv350qv_write_reg(lcd, LTV_GAMMA(8), 0x0004);
10392 + ret |= ltv350qv_write_reg(lcd, LTV_GAMMA(9), 0x0000);
10394 + goto err_settings;
10396 + /* Wait more than 2 frames */
10399 + /* Display On Sequence */
10400 + ret = ltv350qv_write_reg(lcd, LTV_PWRCTL1,
10401 + LTV_VCOM_DISABLE | LTV_VCOMOUT_ENABLE
10402 + | LTV_POWER_ON | LTV_DRIVE_CURRENT(5)
10403 + | LTV_SUPPLY_CURRENT(5));
10404 + ret |= ltv350qv_write_reg(lcd, LTV_GATECTL2,
10405 + LTV_NW_INV_1LINE | LTV_DSC | LTV_FWI(3));
10407 + goto err_disp_on;
10409 + /* Display should now be ON. Phew. */
10414 + * Try to recover. Error handling probably isn't very useful
10415 + * at this point, just make a best effort to switch the panel
10418 + ltv350qv_write_reg(lcd, LTV_PWRCTL1,
10419 + LTV_VCOM_DISABLE | LTV_DRIVE_CURRENT(5)
10420 + | LTV_SUPPLY_CURRENT(5));
10421 + ltv350qv_write_reg(lcd, LTV_GATECTL2,
10422 + LTV_NW_INV_1LINE | LTV_FWI(3));
10426 + ltv350qv_write_reg(lcd, LTV_PWRCTL2, 0x0000);
10429 + ltv350qv_write_reg(lcd, LTV_PWRCTL1, LTV_VCOM_DISABLE);
10433 +static int ltv350qv_power_off(struct ltv350qv *lcd)
10437 + /* Display Off Sequence */
10438 + ret = ltv350qv_write_reg(lcd, LTV_PWRCTL1,
10440 + | LTV_DRIVE_CURRENT(5)
10441 + | LTV_SUPPLY_CURRENT(5));
10442 + ret |= ltv350qv_write_reg(lcd, LTV_GATECTL2,
10443 + LTV_NW_INV_1LINE | LTV_FWI(3));
10445 + /* Power down setting 1 */
10446 + ret |= ltv350qv_write_reg(lcd, LTV_PWRCTL2, 0x0000);
10448 + /* Wait at least 1 ms */
10451 + /* Power down setting 2 */
10452 + ret |= ltv350qv_write_reg(lcd, LTV_PWRCTL1, LTV_VCOM_DISABLE);
10455 + * No point in trying to recover here. If we can't switch the
10456 + * panel off, what are we supposed to do other than inform the
10457 + * user about the failure?
10462 + /* Display power should now be OFF */
10466 +static int ltv350qv_power(struct ltv350qv *lcd, int power)
10470 + if (POWER_IS_ON(power) && !POWER_IS_ON(lcd->power))
10471 + ret = ltv350qv_power_on(lcd);
10472 + else if (!POWER_IS_ON(power) && POWER_IS_ON(lcd->power))
10473 + ret = ltv350qv_power_off(lcd);
10476 + lcd->power = power;
10481 +static int ltv350qv_set_power(struct lcd_device *ld, int power)
10483 + struct ltv350qv *lcd;
10485 + lcd = class_get_devdata(&ld->class_dev);
10486 + return ltv350qv_power(lcd, power);
10489 +static int ltv350qv_get_power(struct lcd_device *ld)
10491 + struct ltv350qv *lcd;
10493 + lcd = class_get_devdata(&ld->class_dev);
10494 + return lcd->power;
10497 +static struct lcd_ops ltv_ops = {
10498 + .get_power = ltv350qv_get_power,
10499 + .set_power = ltv350qv_set_power,
10502 +static int __devinit ltv350qv_probe(struct spi_device *spi)
10504 + struct ltv350qv *lcd;
10505 + struct lcd_device *ld;
10508 + lcd = kzalloc(sizeof(struct ltv350qv), GFP_KERNEL);
10513 + lcd->power = FB_BLANK_POWERDOWN;
10514 + lcd->buffer = kzalloc(8, GFP_KERNEL);
10516 + ld = lcd_device_register("ltv350qv", lcd, <v_ops);
10517 + if (IS_ERR(ld)) {
10518 + ret = PTR_ERR(ld);
10519 + goto out_free_lcd;
10523 + ret = ltv350qv_power(lcd, FB_BLANK_UNBLANK);
10525 + goto out_unregister;
10527 + dev_set_drvdata(&spi->dev, lcd);
10532 + lcd_device_unregister(ld);
10538 +static int __devexit ltv350qv_remove(struct spi_device *spi)
10540 + struct ltv350qv *lcd = dev_get_drvdata(&spi->dev);
10542 + ltv350qv_power(lcd, FB_BLANK_POWERDOWN);
10543 + lcd_device_unregister(lcd->ld);
10550 +static int ltv350qv_suspend(struct spi_device *spi,
10551 + pm_message_t state, u32 level)
10553 + struct ltv350qv *lcd = dev_get_drvdata(&spi->dev);
10555 + if (level == SUSPEND_POWER_DOWN)
10556 + return ltv350qv_power(lcd, FB_BLANK_POWERDOWN);
10561 +static int ltv350qv_resume(struct spi_device *spi, u32 level)
10563 + struct ltv350qv *lcd = dev_get_drvdata(&spi->dev);
10565 + if (level == RESUME_POWER_ON)
10566 + return ltv350qv_power(lcd, FB_BLANK_UNBLANK);
10571 +#define ltv350qv_suspend NULL
10572 +#define ltv350qv_resume NULL
10575 +/* Power down all displays on reboot, poweroff or halt */
10576 +static void ltv350qv_shutdown(struct spi_device *spi)
10578 + struct ltv350qv *lcd = dev_get_drvdata(&spi->dev);
10580 + ltv350qv_power(lcd, FB_BLANK_POWERDOWN);
10583 +static struct spi_driver ltv350qv_driver = {
10585 + .name = "ltv350qv",
10586 + .bus = &spi_bus_type,
10587 + .owner = THIS_MODULE,
10590 + .probe = ltv350qv_probe,
10591 + .remove = __devexit_p(ltv350qv_remove),
10592 + .shutdown = ltv350qv_shutdown,
10593 + .suspend = ltv350qv_suspend,
10594 + .resume = ltv350qv_resume,
10597 +static int __init ltv350qv_init(void)
10599 + return spi_register_driver(<v350qv_driver);
10602 +static void __exit ltv350qv_exit(void)
10604 + spi_unregister_driver(<v350qv_driver);
10606 +module_init(ltv350qv_init);
10607 +module_exit(ltv350qv_exit);
10609 +MODULE_AUTHOR("Haavard Skinnemoen <hskinnemoen@atmel.com>");
10610 +MODULE_DESCRIPTION("Samsung LTV350QV LCD Driver");
10611 +MODULE_LICENSE("GPL");
10612 diff -x .git -Nur linux-2.6.22.1/drivers/video/backlight/ltv350qv.h linux-avr32.git/drivers/video/backlight/ltv350qv.h
10613 --- linux-2.6.22.1/drivers/video/backlight/ltv350qv.h 1970-01-01 01:00:00.000000000 +0100
10614 +++ linux-avr32.git/drivers/video/backlight/ltv350qv.h 2007-06-06 11:34:00.000000000 +0200
10617 + * Register definitions for Samsung LTV350QV Quarter VGA LCD Panel
10619 + * Copyright (C) 2006, 2007 Atmel Corporation
10621 + * This program is free software; you can redistribute it and/or modify
10622 + * it under the terms of the GNU General Public License version 2 as
10623 + * published by the Free Software Foundation.
10625 +#ifndef __LTV350QV_H
10626 +#define __LTV350QV_H
10628 +#define LTV_OPC_INDEX 0x74
10629 +#define LTV_OPC_DATA 0x76
10631 +#define LTV_ID 0x00 /* ID Read */
10632 +#define LTV_IFCTL 0x01 /* Display Interface Control */
10633 +#define LTV_DATACTL 0x02 /* Display Data Control */
10634 +#define LTV_ENTRY_MODE 0x03 /* Entry Mode */
10635 +#define LTV_GATECTL1 0x04 /* Gate Control 1 */
10636 +#define LTV_GATECTL2 0x05 /* Gate Control 2 */
10637 +#define LTV_VBP 0x06 /* Vertical Back Porch */
10638 +#define LTV_HBP 0x07 /* Horizontal Back Porch */
10639 +#define LTV_SOTCTL 0x08 /* Source Output Timing Control */
10640 +#define LTV_PWRCTL1 0x09 /* Power Control 1 */
10641 +#define LTV_PWRCTL2 0x0a /* Power Control 2 */
10642 +#define LTV_GAMMA(x) (0x10 + (x)) /* Gamma control */
10644 +/* Bit definitions for LTV_IFCTL */
10645 +#define LTV_IM (1 << 15)
10646 +#define LTV_NMD (1 << 14)
10647 +#define LTV_SSMD (1 << 13)
10648 +#define LTV_REV (1 << 7)
10649 +#define LTV_NL(x) (((x) & 0x001f) << 0)
10651 +/* Bit definitions for LTV_DATACTL */
10652 +#define LTV_DS_SAME (0 << 12)
10653 +#define LTV_DS_D_TO_S (1 << 12)
10654 +#define LTV_DS_S_TO_D (2 << 12)
10655 +#define LTV_CHS_384 (0 << 9)
10656 +#define LTV_CHS_480 (1 << 9)
10657 +#define LTV_CHS_492 (2 << 9)
10658 +#define LTV_DF_RGB (0 << 6)
10659 +#define LTV_DF_RGBX (1 << 6)
10660 +#define LTV_DF_XRGB (2 << 6)
10661 +#define LTV_RGB_RGB (0 << 2)
10662 +#define LTV_RGB_BGR (1 << 2)
10663 +#define LTV_RGB_GRB (2 << 2)
10664 +#define LTV_RGB_RBG (3 << 2)
10666 +/* Bit definitions for LTV_ENTRY_MODE */
10667 +#define LTV_VSPL_ACTIVE_LOW (0 << 15)
10668 +#define LTV_VSPL_ACTIVE_HIGH (1 << 15)
10669 +#define LTV_HSPL_ACTIVE_LOW (0 << 14)
10670 +#define LTV_HSPL_ACTIVE_HIGH (1 << 14)
10671 +#define LTV_DPL_SAMPLE_RISING (0 << 13)
10672 +#define LTV_DPL_SAMPLE_FALLING (1 << 13)
10673 +#define LTV_EPL_ACTIVE_LOW (0 << 12)
10674 +#define LTV_EPL_ACTIVE_HIGH (1 << 12)
10675 +#define LTV_SS_LEFT_TO_RIGHT (0 << 8)
10676 +#define LTV_SS_RIGHT_TO_LEFT (1 << 8)
10677 +#define LTV_STB (1 << 1)
10679 +/* Bit definitions for LTV_GATECTL1 */
10680 +#define LTV_CLW(x) (((x) & 0x0007) << 12)
10681 +#define LTV_GAON (1 << 5)
10682 +#define LTV_SDR (1 << 3)
10684 +/* Bit definitions for LTV_GATECTL2 */
10685 +#define LTV_NW_INV_FRAME (0 << 14)
10686 +#define LTV_NW_INV_1LINE (1 << 14)
10687 +#define LTV_NW_INV_2LINE (2 << 14)
10688 +#define LTV_DSC (1 << 12)
10689 +#define LTV_GIF (1 << 8)
10690 +#define LTV_FHN (1 << 7)
10691 +#define LTV_FTI(x) (((x) & 0x0003) << 4)
10692 +#define LTV_FWI(x) (((x) & 0x0003) << 0)
10694 +/* Bit definitions for LTV_SOTCTL */
10695 +#define LTV_SDT(x) (((x) & 0x0007) << 10)
10696 +#define LTV_EQ(x) (((x) & 0x0007) << 2)
10698 +/* Bit definitions for LTV_PWRCTL1 */
10699 +#define LTV_VCOM_DISABLE (1 << 14)
10700 +#define LTV_VCOMOUT_ENABLE (1 << 11)
10701 +#define LTV_POWER_ON (1 << 9)
10702 +#define LTV_DRIVE_CURRENT(x) (((x) & 0x0007) << 4) /* 0=off, 5=max */
10703 +#define LTV_SUPPLY_CURRENT(x) (((x) & 0x0007) << 0) /* 0=off, 5=max */
10705 +/* Bit definitions for LTV_PWRCTL2 */
10706 +#define LTV_VCOML_ENABLE (1 << 13)
10707 +#define LTV_VCOML_VOLTAGE(x) (((x) & 0x001f) << 8) /* 0=1V, 31=-1V */
10708 +#define LTV_VCOMH_VOLTAGE(x) (((x) & 0x001f) << 0) /* 0=3V, 31=4.5V */
10710 +#endif /* __LTV350QV_H */
10711 diff -x .git -Nur linux-2.6.22.1/drivers/video/backlight/Makefile linux-avr32.git/drivers/video/backlight/Makefile
10712 --- linux-2.6.22.1/drivers/video/backlight/Makefile 2007-07-10 20:56:30.000000000 +0200
10713 +++ linux-avr32.git/drivers/video/backlight/Makefile 2007-07-12 14:00:20.000000000 +0200
10715 # Backlight & LCD drivers
10717 obj-$(CONFIG_LCD_CLASS_DEVICE) += lcd.o
10718 +obj-$(CONFIG_LCD_LTV350QV) += ltv350qv.o
10720 obj-$(CONFIG_BACKLIGHT_CLASS_DEVICE) += backlight.o
10721 obj-$(CONFIG_BACKLIGHT_CORGI) += corgi_bl.o
10722 obj-$(CONFIG_BACKLIGHT_HP680) += hp680_bl.o
10723 diff -x .git -Nur linux-2.6.22.1/drivers/video/Kconfig linux-avr32.git/drivers/video/Kconfig
10724 --- linux-2.6.22.1/drivers/video/Kconfig 2007-07-10 20:56:30.000000000 +0200
10725 +++ linux-avr32.git/drivers/video/Kconfig 2007-07-12 14:00:20.000000000 +0200
10726 @@ -849,6 +849,16 @@
10727 Say Y if you want to map Frame Buffer in internal SRAM. Say N if you want
10728 to let frame buffer in external SDRAM.
10730 +config FB_ATMEL_STN
10731 + bool "Use a STN display with AT91/AT32 LCD Controller"
10732 + depends on FB_ATMEL && ARCH_AT91SAM9261
10735 + Say Y if you want to connect a STN LCD display to the AT91/AT32 LCD
10736 + Controller. Say N if you want to connect a TFT.
10738 + If unsure, say N.
10741 tristate "nVidia Framebuffer Support"
10742 depends on FB && PCI
10743 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
10744 --- linux-2.6.22.1/include/asm-arm/arch-at91/board.h 2007-07-10 20:56:30.000000000 +0200
10745 +++ linux-avr32.git/include/asm-arm/arch-at91/board.h 2007-07-12 14:00:26.000000000 +0200
10748 /* Ethernet (EMAC & MACB) */
10749 struct at91_eth_data {
10751 u8 phy_irq_pin; /* PHY IRQ */
10752 u8 is_rmii; /* using RMII interface? */
10754 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
10755 --- linux-2.6.22.1/include/asm-avr32/arch-at32ap/board.h 2007-07-10 20:56:30.000000000 +0200
10756 +++ linux-avr32.git/include/asm-avr32/arch-at32ap/board.h 2007-07-12 14:00:26.000000000 +0200
10759 #include <linux/types.h>
10761 +#define GPIO_PIN_NONE (-1)
10763 /* Add basic devices: system manager, interrupt controller, portmuxes, etc. */
10764 void at32_add_system_devices(void);
10767 struct platform_device *at32_add_device_usart(unsigned int id);
10769 struct eth_platform_data {
10773 struct platform_device *
10775 struct platform_device *
10776 at32_add_device_spi(unsigned int id, struct spi_board_info *b, unsigned int n);
10778 +struct platform_device *at32_add_device_twi(unsigned int id);
10780 +struct mci_platform_data {
10784 +struct platform_device *
10785 +at32_add_device_mci(unsigned int id, struct mci_platform_data *data);
10787 +struct usba_platform_data {
10790 +struct platform_device *
10791 +at32_add_device_usba(unsigned int id, struct usba_platform_data *data);
10793 struct atmel_lcdfb_info;
10794 struct platform_device *
10795 at32_add_device_lcdc(unsigned int id, struct atmel_lcdfb_info *data,
10796 unsigned long fbmem_start, unsigned long fbmem_len);
10798 +struct platform_device *at32_add_device_ac97c(unsigned int id);
10799 +struct platform_device *at32_add_device_abdac(unsigned int id);
10801 +/* depending on what's hooked up, not all SSC pins will be used */
10802 +#define ATMEL_SSC_TK 0x01
10803 +#define ATMEL_SSC_TF 0x02
10804 +#define ATMEL_SSC_TD 0x04
10805 +#define ATMEL_SSC_TX (ATMEL_SSC_TK | ATMEL_SSC_TF | ATMEL_SSC_TD)
10807 +#define ATMEL_SSC_RK 0x10
10808 +#define ATMEL_SSC_RF 0x20
10809 +#define ATMEL_SSC_RD 0x40
10810 +#define ATMEL_SSC_RX (ATMEL_SSC_RK | ATMEL_SSC_RF | ATMEL_SSC_RD)
10812 +struct platform_device *
10813 +at32_add_device_ssc(unsigned int id, unsigned int flags);
10815 #endif /* __ASM_ARCH_BOARD_H */
10816 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
10817 --- linux-2.6.22.1/include/asm-avr32/arch-at32ap/portmux.h 2007-07-10 20:56:30.000000000 +0200
10818 +++ linux-avr32.git/include/asm-avr32/arch-at32ap/portmux.h 2007-07-12 14:00:26.000000000 +0200
10820 void at32_select_gpio(unsigned int pin, unsigned long flags);
10821 void at32_reserve_pin(unsigned int pin);
10823 +#ifdef CONFIG_GPIO_DEV
10825 +/* Gang allocators and accessors; used by the GPIO /dev driver */
10826 +int at32_gpio_port_is_valid(unsigned int port);
10827 +int at32_select_gpio_pins(unsigned int port, u32 pins, u32 oe_mask);
10828 +void at32_deselect_pins(unsigned int port, u32 pins);
10830 +u32 at32_gpio_get_value_multiple(unsigned int port, u32 pins);
10831 +void at32_gpio_set_value_multiple(unsigned int port, u32 value, u32 mask);
10833 +#endif /* CONFIG_GPIO_DEV */
10835 #endif /* __ASM_ARCH_PORTMUX_H__ */
10836 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
10837 --- linux-2.6.22.1/include/asm-avr32/arch-at32ap/sm.h 2007-07-10 20:56:30.000000000 +0200
10838 +++ linux-avr32.git/include/asm-avr32/arch-at32ap/sm.h 1970-01-01 01:00:00.000000000 +0100
10841 - * AT32 System Manager interface.
10843 - * Copyright (C) 2006 Atmel Corporation
10845 - * This program is free software; you can redistribute it and/or modify
10846 - * it under the terms of the GNU General Public License version 2 as
10847 - * published by the Free Software Foundation.
10849 -#ifndef __ASM_AVR32_AT32_SM_H__
10850 -#define __ASM_AVR32_AT32_SM_H__
10853 -struct platform_device;
10857 - void __iomem *regs;
10858 - struct irq_chip *eim_chip;
10859 - unsigned int eim_first_irq;
10860 - struct platform_device *pdev;
10863 -extern struct platform_device at32_sm_device;
10864 -extern struct at32_sm system_manager;
10866 -#endif /* __ASM_AVR32_AT32_SM_H__ */
10867 diff -x .git -Nur linux-2.6.22.1/include/asm-avr32/dma-controller.h linux-avr32.git/include/asm-avr32/dma-controller.h
10868 --- linux-2.6.22.1/include/asm-avr32/dma-controller.h 1970-01-01 01:00:00.000000000 +0100
10869 +++ linux-avr32.git/include/asm-avr32/dma-controller.h 2007-06-06 11:34:11.000000000 +0200
10872 + * Copyright (C) 2005-2006 Atmel Corporation
10874 + * This program is free software; you can redistribute it and/or modify
10875 + * it under the terms of the GNU General Public License version 2 as
10876 + * published by the Free Software Foundation.
10878 +#ifndef __ASM_AVR32_DMA_CONTROLLER_H
10879 +#define __ASM_AVR32_DMA_CONTROLLER_H
10881 +#include <linux/device.h>
10883 +#define DMA_DIR_MEM_TO_MEM 0x0000
10884 +#define DMA_DIR_MEM_TO_PERIPH 0x0001
10885 +#define DMA_DIR_PERIPH_TO_MEM 0x0002
10886 +#define DMA_DIR_PERIPH_TO_PERIPH 0x0003
10888 +#define DMA_WIDTH_8BIT 0
10889 +#define DMA_WIDTH_16BIT 1
10890 +#define DMA_WIDTH_32BIT 2
10892 +struct dma_request {
10893 + struct dma_controller *dmac;
10894 + struct list_head list;
10896 + unsigned short channel;
10898 + void (*xfer_complete)(struct dma_request *req);
10899 + void (*block_complete)(struct dma_request *req);
10900 + void (*error)(struct dma_request *req);
10903 +struct dma_request_sg {
10904 + struct dma_request req;
10907 + struct scatterlist *sg;
10908 + unsigned long block_size;
10909 + unsigned int nr_blocks;
10911 + dma_addr_t data_reg;
10912 + unsigned short periph_id;
10914 + unsigned char direction;
10915 + unsigned char width;
10917 +#define to_dma_request_sg(_req) \
10918 + container_of(_req, struct dma_request_sg, req)
10920 +struct dma_request_cyclic {
10921 + struct dma_request req;
10924 + unsigned long buffer_size;
10926 + dma_addr_t buffer_start;
10927 + dma_addr_t data_reg;
10929 + unsigned short periph_id;
10930 + unsigned char direction;
10931 + unsigned char width;
10935 +#define to_dma_request_cyclic(_req) \
10936 + container_of(_req, struct dma_request_cyclic, req)
10938 +struct dma_request_memcpy {
10939 + struct dma_request req;
10941 + dma_addr_t src_addr;
10942 + unsigned int src_width;
10943 + unsigned int src_stride;
10945 + dma_addr_t dst_addr;
10946 + unsigned int dst_width;
10947 + unsigned int dst_stride;
10951 + unsigned short src_reverse:1;
10952 + unsigned short dst_reverse:1;
10954 +#define to_dma_request_memcpy(_req) \
10955 + container_of(_req, struct dma_request_memcpy, req)
10957 +struct dma_controller {
10958 + struct list_head list;
10960 + struct device *dev;
10962 + int (*alloc_channel)(struct dma_controller *dmac);
10963 + void (*release_channel)(struct dma_controller *dmac,
10965 + int (*prepare_request_sg)(struct dma_controller *dmac,
10966 + struct dma_request_sg *req);
10967 + int (*prepare_request_cyclic)(struct dma_controller *dmac,
10968 + struct dma_request_cyclic *req);
10969 + int (*prepare_request_memcpy)(struct dma_controller *dmac,
10970 + struct dma_request_memcpy *req);
10971 + int (*start_request)(struct dma_controller *dmac,
10972 + unsigned int channel);
10973 + int (*stop_request)(struct dma_controller *dmac,
10974 + unsigned int channel);
10975 + dma_addr_t (*get_current_pos)(struct dma_controller *dmac,
10976 + unsigned int channel);
10980 +dma_alloc_channel(struct dma_controller *dmac)
10982 + return dmac->alloc_channel(dmac);
10985 +static inline void
10986 +dma_release_channel(struct dma_controller *dmac, int chan)
10988 + dmac->release_channel(dmac, chan);
10992 +dma_prepare_request_sg(struct dma_controller *dmac,
10993 + struct dma_request_sg *req)
10995 + return dmac->prepare_request_sg(dmac, req);
10999 +dma_prepare_request_cyclic(struct dma_controller *dmac,
11000 + struct dma_request_cyclic *req)
11002 + return dmac->prepare_request_cyclic(dmac, req);
11006 +dma_prepare_request_memcpy(struct dma_controller *dmac,
11007 + struct dma_request_memcpy *req)
11009 + return dmac->prepare_request_memcpy(dmac, req);
11013 +dma_start_request(struct dma_controller *dmac,
11014 + unsigned int channel)
11016 + return dmac->start_request(dmac, channel);
11020 +dma_stop_request(struct dma_controller *dmac,
11021 + unsigned int channel)
11023 + return dmac->stop_request(dmac, channel);
11026 +static inline dma_addr_t
11027 +dma_get_current_pos(struct dma_controller *dmac,
11028 + unsigned int channel)
11030 + return dmac->get_current_pos(dmac, channel);
11033 +extern int register_dma_controller(struct dma_controller *dmac);
11034 +extern struct dma_controller *find_dma_controller(int id);
11036 +#endif /* __ASM_AVR32_DMA_CONTROLLER_H */
11037 diff -x .git -Nur linux-2.6.22.1/include/asm-avr32/unaligned.h linux-avr32.git/include/asm-avr32/unaligned.h
11038 --- linux-2.6.22.1/include/asm-avr32/unaligned.h 2007-07-10 20:56:30.000000000 +0200
11039 +++ linux-avr32.git/include/asm-avr32/unaligned.h 2007-07-12 14:00:26.000000000 +0200
11041 * words, but halfwords must be halfword-aligned, and doublewords must
11044 - * TODO: Make all this CPU-specific and optimize.
11045 + * However, swapped word loads must be word-aligned so we can't
11046 + * optimize word loads in general.
11049 -#include <linux/string.h>
11051 -/* Use memmove here, so gcc does not insert a __builtin_memcpy. */
11053 -#define get_unaligned(ptr) \
11054 - ({ __typeof__(*(ptr)) __tmp; memmove(&__tmp, (ptr), sizeof(*(ptr))); __tmp; })
11056 -#define put_unaligned(val, ptr) \
11057 - ({ __typeof__(*(ptr)) __tmp = (val); \
11058 - memmove((ptr), &__tmp, sizeof(*(ptr))); \
11060 +#include <asm-generic/unaligned.h>
11062 #endif /* __ASM_AVR32_UNALIGNED_H */
11063 diff -x .git -Nur linux-2.6.22.1/include/linux/leds.h linux-avr32.git/include/linux/leds.h
11064 --- linux-2.6.22.1/include/linux/leds.h 2007-07-10 20:56:30.000000000 +0200
11065 +++ linux-avr32.git/include/linux/leds.h 2007-07-12 14:00:30.000000000 +0200
11066 @@ -110,4 +110,18 @@
11067 #define ledtrig_ide_activity() do {} while(0)
11070 +/* For the leds-gpio driver */
11072 + const char *name;
11073 + char *default_trigger;
11078 +struct gpio_led_platform_data {
11080 + struct gpio_led *leds;
11084 #endif /* __LINUX_LEDS_H_INCLUDED */
11085 diff -x .git -Nur linux-2.6.22.1/include/linux/usb/gadgetfs.h linux-avr32.git/include/linux/usb/gadgetfs.h
11086 --- linux-2.6.22.1/include/linux/usb/gadgetfs.h 1970-01-01 01:00:00.000000000 +0100
11087 +++ linux-avr32.git/include/linux/usb/gadgetfs.h 2007-07-12 14:00:31.000000000 +0200
11089 +#ifndef __LINUX_USB_GADGETFS_H
11090 +#define __LINUX_USB_GADGETFS_H
11092 +#include <asm/types.h>
11093 +#include <asm/ioctl.h>
11095 +#include <linux/usb/ch9.h>
11098 + * Filesystem based user-mode API to USB Gadget controller hardware
11100 + * Other than ep0 operations, most things are done by read() and write()
11101 + * on endpoint files found in one directory. They are configured by
11102 + * writing descriptors, and then may be used for normal stream style
11103 + * i/o requests. When ep0 is configured, the device can enumerate;
11104 + * when it's closed, the device disconnects from usb. Operations on
11105 + * ep0 require ioctl() operations.
11107 + * Configuration and device descriptors get written to /dev/gadget/$CHIP,
11108 + * which may then be used to read usb_gadgetfs_event structs. The driver
11109 + * may activate endpoints as it handles SET_CONFIGURATION setup events,
11110 + * or earlier; writing endpoint descriptors to /dev/gadget/$ENDPOINT
11111 + * then performing data transfers by reading or writing.
11115 + * Events are delivered on the ep0 file descriptor, when the user mode driver
11116 + * reads from this file descriptor after writing the descriptors. Don't
11117 + * stop polling this descriptor.
11120 +enum usb_gadgetfs_event_type {
11121 + GADGETFS_NOP = 0,
11123 + GADGETFS_CONNECT,
11124 + GADGETFS_DISCONNECT,
11126 + GADGETFS_SUSPEND,
11127 + // and likely more !
11130 +/* NOTE: this structure must stay the same size and layout on
11131 + * both 32-bit and 64-bit kernels.
11133 +struct usb_gadgetfs_event {
11135 + // NOP, DISCONNECT, SUSPEND: nothing
11136 + // ... some hardware can't report disconnection
11138 + // CONNECT: just the speed
11139 + enum usb_device_speed speed;
11141 + // SETUP: packet; DATA phase i/o precedes next event
11142 + // (setup.bmRequestType & USB_DIR_IN) flags direction
11143 + // ... includes SET_CONFIGURATION, SET_INTERFACE
11144 + struct usb_ctrlrequest setup;
11146 + enum usb_gadgetfs_event_type type;
11150 +/* endpoint ioctls */
11152 +/* IN transfers may be reported to the gadget driver as complete
11153 + * when the fifo is loaded, before the host reads the data;
11154 + * OUT transfers may be reported to the host's "client" driver as
11155 + * complete when they're sitting in the FIFO unread.
11156 + * THIS returns how many bytes are "unclaimed" in the endpoint fifo
11157 + * (needed for precise fault handling, when the hardware allows it)
11159 +#define GADGETFS_FIFO_STATUS _IO('g',1)
11161 +/* discards any unclaimed data in the fifo. */
11162 +#define GADGETFS_FIFO_FLUSH _IO('g',2)
11164 +/* resets endpoint halt+toggle; used to implement set_interface.
11165 + * some hardware (like pxa2xx) can't support this.
11167 +#define GADGETFS_CLEAR_HALT _IO('g',3)
11169 +#endif /* __LINUX_USB_GADGETFS_H */
11170 diff -x .git -Nur linux-2.6.22.1/include/linux/usb/Kbuild linux-avr32.git/include/linux/usb/Kbuild
11171 --- linux-2.6.22.1/include/linux/usb/Kbuild 2007-07-10 20:56:30.000000000 +0200
11172 +++ linux-avr32.git/include/linux/usb/Kbuild 2007-07-12 14:00:31.000000000 +0200
11174 unifdef-y += audio.h
11177 +unifdef-y += gadgetfs.h
11178 unifdef-y += midi.h
11180 diff -x .git -Nur linux-2.6.22.1/include/linux/usb_gadgetfs.h linux-avr32.git/include/linux/usb_gadgetfs.h
11181 --- linux-2.6.22.1/include/linux/usb_gadgetfs.h 2007-07-10 20:56:30.000000000 +0200
11182 +++ linux-avr32.git/include/linux/usb_gadgetfs.h 1970-01-01 01:00:00.000000000 +0100
11185 -#include <asm/types.h>
11186 -#include <asm/ioctl.h>
11188 -#include <linux/usb/ch9.h>
11191 - * Filesystem based user-mode API to USB Gadget controller hardware
11193 - * Almost everything can be done with only read and write operations,
11194 - * on endpoint files found in one directory. They are configured by
11195 - * writing descriptors, and then may be used for normal stream style
11196 - * i/o requests. When ep0 is configured, the device can enumerate;
11197 - * when it's closed, the device disconnects from usb.
11199 - * Configuration and device descriptors get written to /dev/gadget/$CHIP,
11200 - * which may then be used to read usb_gadgetfs_event structs. The driver
11201 - * may activate endpoints as it handles SET_CONFIGURATION setup events,
11202 - * or earlier; writing endpoint descriptors to /dev/gadget/$ENDPOINT
11203 - * then performing data transfers by reading or writing.
11207 - * Events are delivered on the ep0 file descriptor, if the user mode driver
11208 - * reads from this file descriptor after writing the descriptors. Don't
11209 - * stop polling this descriptor, if you write that kind of driver.
11212 -enum usb_gadgetfs_event_type {
11213 - GADGETFS_NOP = 0,
11215 - GADGETFS_CONNECT,
11216 - GADGETFS_DISCONNECT,
11218 - GADGETFS_SUSPEND,
11219 - // and likely more !
11222 -struct usb_gadgetfs_event {
11223 - enum usb_gadgetfs_event_type type;
11225 - // NOP, DISCONNECT, SUSPEND: nothing
11226 - // ... some hardware can't report disconnection
11228 - // CONNECT: just the speed
11229 - enum usb_device_speed speed;
11231 - // SETUP: packet; DATA phase i/o precedes next event
11232 - // (setup.bmRequestType & USB_DIR_IN) flags direction
11233 - // ... includes SET_CONFIGURATION, SET_INTERFACE
11234 - struct usb_ctrlrequest setup;
11239 -/* endpoint ioctls */
11241 -/* IN transfers may be reported to the gadget driver as complete
11242 - * when the fifo is loaded, before the host reads the data;
11243 - * OUT transfers may be reported to the host's "client" driver as
11244 - * complete when they're sitting in the FIFO unread.
11245 - * THIS returns how many bytes are "unclaimed" in the endpoint fifo
11246 - * (needed for precise fault handling, when the hardware allows it)
11248 -#define GADGETFS_FIFO_STATUS _IO('g',1)
11250 -/* discards any unclaimed data in the fifo. */
11251 -#define GADGETFS_FIFO_FLUSH _IO('g',2)
11253 -/* resets endpoint halt+toggle; used to implement set_interface.
11254 - * some hardware (like pxa2xx) can't support this.
11256 -#define GADGETFS_CLEAR_HALT _IO('g',3)
11259 diff -x .git -Nur linux-2.6.22.1/init/do_mounts.c linux-avr32.git/init/do_mounts.c
11260 --- linux-2.6.22.1/init/do_mounts.c 2007-07-10 20:56:30.000000000 +0200
11261 +++ linux-avr32.git/init/do_mounts.c 2007-07-12 14:00:31.000000000 +0200
11263 int root_mountflags = MS_RDONLY | MS_SILENT;
11264 char * __initdata root_device_name;
11265 static char __initdata saved_root_name[64];
11266 +int __initdata root_wait;
11270 @@ -216,6 +217,14 @@
11272 __setup("root=", root_dev_setup);
11274 +static int __init rootwait_setup(char *line)
11276 + root_wait = simple_strtol(line,NULL,0);
11280 +__setup("rootwait=", rootwait_setup);
11282 static char * __initdata root_mount_data;
11283 static int __init root_data_setup(char *str)
11285 @@ -438,11 +447,24 @@
11286 root_device_name += 5;
11289 - is_floppy = MAJOR(ROOT_DEV) == FLOPPY_MAJOR;
11294 + /* wait for any asynchronous scanning to complete */
11295 + if ((ROOT_DEV == 0) && root_wait) {
11296 + printk(KERN_INFO "Waiting for root device %s...\n",
11297 + saved_root_name);
11299 + while (driver_probe_done() != 0)
11301 + ROOT_DEV = name_to_dev_t(saved_root_name);
11302 + if (ROOT_DEV == 0)
11304 + } while (ROOT_DEV == 0);
11307 + is_floppy = MAJOR(ROOT_DEV) == FLOPPY_MAJOR;
11309 if (is_floppy && rd_doload && rd_load_disk(0))
11310 ROOT_DEV = Root_RAM0;
11312 diff -x .git -Nur linux-2.6.22.1/MAINTAINERS linux-avr32.git/MAINTAINERS
11313 --- linux-2.6.22.1/MAINTAINERS 2007-07-10 20:56:30.000000000 +0200
11314 +++ linux-avr32.git/MAINTAINERS 2007-07-12 13:59:48.000000000 +0200
11315 @@ -674,6 +674,13 @@
11316 M: hskinnemoen@atmel.com
11319 +ATMEL USBA UDC DRIVER
11320 +P: Haavard Skinnemoen
11321 +M: hskinnemoen@atmel.com
11322 +L: kernel@avr32linux.org
11323 +W: http://avr32linux.org/twiki/bin/view/Main/AtmelUsbDeviceDriver
11326 ATMEL WIRELESS DRIVER
11328 M: simon@thekelleys.org.uk
11329 diff -x .git -Nur linux-2.6.22.1/scripts/checkstack.pl linux-avr32.git/scripts/checkstack.pl
11330 --- linux-2.6.22.1/scripts/checkstack.pl 2007-07-10 20:56:30.000000000 +0200
11331 +++ linux-avr32.git/scripts/checkstack.pl 2007-06-06 11:34:14.000000000 +0200
11333 # sh64 port by Paul Mundt
11334 # Random bits by Matt Mackall <mpm@selenic.com>
11335 # M68k port by Geert Uytterhoeven and Andreas Schwab
11336 +# AVR32 port by Haavard Skinnemoen <hskinnemoen@atmel.com>
11339 # objdump -d vmlinux | stackcheck.pl [arch]
11341 if ($arch eq 'arm') {
11342 #c0008ffc: e24dd064 sub sp, sp, #100 ; 0x64
11343 $re = qr/.*sub.*sp, sp, #(([0-9]{2}|[3-9])[0-9]{2})/o;
11344 + } elsif ($arch eq 'avr32') {
11345 + #8000008a: 20 1d sub sp,4
11346 + #80000ca8: fa cd 05 b0 sub sp,sp,1456
11347 + $re = qr/^.*sub.*sp.*,([0-9]{1,8})/o;
11348 } elsif ($arch =~ /^i[3456]86$/) {
11349 #c0105234: 81 ec ac 05 00 00 sub $0x5ac,%esp
11350 $re = qr/^.*[as][du][db] \$(0x$x{1,8}),\%esp$/o;