2 * linux/arch/arm/common/sa1111.c
6 * Original code by John Dorsey
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 as
10 * published by the Free Software Foundation.
12 * This file contains all generic SA1111 support.
14 * All initialization functions provided here are intended to be called
15 * from machine specific code with proper arguments when required.
17 #include <linux/module.h>
18 #include <linux/init.h>
19 #include <linux/kernel.h>
20 #include <linux/delay.h>
21 #include <linux/errno.h>
22 #include <linux/ioport.h>
23 #include <linux/platform_device.h>
24 #include <linux/slab.h>
25 #include <linux/spinlock.h>
26 #include <linux/dma-mapping.h>
27 #include <linux/clk.h>
30 #include <mach/hardware.h>
31 #include <asm/mach-types.h>
33 #include <asm/mach/irq.h>
34 #include <asm/sizes.h>
36 #include <asm/hardware/sa1111.h>
39 #define IRQ_GPAIN0 (0)
40 #define IRQ_GPAIN1 (1)
41 #define IRQ_GPAIN2 (2)
42 #define IRQ_GPAIN3 (3)
43 #define IRQ_GPBIN0 (4)
44 #define IRQ_GPBIN1 (5)
45 #define IRQ_GPBIN2 (6)
46 #define IRQ_GPBIN3 (7)
47 #define IRQ_GPBIN4 (8)
48 #define IRQ_GPBIN5 (9)
49 #define IRQ_GPCIN0 (10)
50 #define IRQ_GPCIN1 (11)
51 #define IRQ_GPCIN2 (12)
52 #define IRQ_GPCIN3 (13)
53 #define IRQ_GPCIN4 (14)
54 #define IRQ_GPCIN5 (15)
55 #define IRQ_GPCIN6 (16)
56 #define IRQ_GPCIN7 (17)
57 #define IRQ_MSTXINT (18)
58 #define IRQ_MSRXINT (19)
59 #define IRQ_MSSTOPERRINT (20)
60 #define IRQ_TPTXINT (21)
61 #define IRQ_TPRXINT (22)
62 #define IRQ_TPSTOPERRINT (23)
63 #define SSPXMTINT (24)
64 #define SSPRCVINT (25)
66 #define AUDXMTDMADONEA (32)
67 #define AUDRCVDMADONEA (33)
68 #define AUDXMTDMADONEB (34)
69 #define AUDRCVDMADONEB (35)
77 #define IRQ_USBPWR (43)
79 #define IRQ_HCIBUFFACC (45)
80 #define IRQ_HCIRMTWKP (46)
81 #define IRQ_NHCIMFCIR (47)
82 #define IRQ_USB_PORT_RESUME (48)
83 #define IRQ_S0_READY_NINT (49)
84 #define IRQ_S1_READY_NINT (50)
85 #define IRQ_S0_CD_VALID (51)
86 #define IRQ_S1_CD_VALID (52)
87 #define IRQ_S0_BVD1_STSCHG (53)
88 #define IRQ_S1_BVD1_STSCHG (54)
90 extern void __init
sa1110_mb_enable(void);
93 * We keep the following data for the overall SA1111. Note that the
94 * struct device and struct resource are "fake"; they should be supplied
95 * by the bus above us. However, in the interests of getting all SA1111
96 * drivers converted over to the device model, we provide this as an
97 * anchor point for all the other drivers.
104 int irq_base
; /* base for cascaded on-chip IRQs */
113 * We _really_ need to eliminate this. Its only users
114 * are the PWM and DMA checking code.
116 static struct sa1111
*g_sa1111
;
118 struct sa1111_dev_info
{
119 unsigned long offset
;
120 unsigned long skpcr_mask
;
125 static struct sa1111_dev_info sa1111_devices
[] = {
127 .offset
= SA1111_USB
,
128 .skpcr_mask
= SKPCR_UCLKEN
,
129 .devid
= SA1111_DEVID_USB
,
141 .skpcr_mask
= SKPCR_I2SCLKEN
| SKPCR_L3CLKEN
,
142 .devid
= SA1111_DEVID_SAC
,
152 .skpcr_mask
= SKPCR_SCLKEN
,
153 .devid
= SA1111_DEVID_SSP
,
156 .offset
= SA1111_KBD
,
157 .skpcr_mask
= SKPCR_PTCLKEN
,
158 .devid
= SA1111_DEVID_PS2
,
165 .offset
= SA1111_MSE
,
166 .skpcr_mask
= SKPCR_PMCLKEN
,
167 .devid
= SA1111_DEVID_PS2
,
176 .devid
= SA1111_DEVID_PCMCIA
,
188 void __init
sa1111_adjust_zones(int node
, unsigned long *size
, unsigned long *holes
)
190 unsigned int sz
= SZ_1M
>> PAGE_SHIFT
;
195 size
[1] = size
[0] - sz
;
200 * SA1111 interrupt support. Since clearing an IRQ while there are
201 * active IRQs causes the interrupt output to pulse, the upper levels
202 * will call us again if there are more interrupts to process.
205 sa1111_irq_handler(unsigned int irq
, struct irq_desc
*desc
)
207 unsigned int stat0
, stat1
, i
;
208 struct sa1111
*sachip
= get_irq_data(irq
);
209 void __iomem
*mapbase
= sachip
->base
+ SA1111_INTC
;
211 stat0
= sa1111_readl(mapbase
+ SA1111_INTSTATCLR0
);
212 stat1
= sa1111_readl(mapbase
+ SA1111_INTSTATCLR1
);
214 sa1111_writel(stat0
, mapbase
+ SA1111_INTSTATCLR0
);
216 desc
->chip
->ack(irq
);
218 sa1111_writel(stat1
, mapbase
+ SA1111_INTSTATCLR1
);
220 if (stat0
== 0 && stat1
== 0) {
221 do_bad_IRQ(irq
, desc
);
225 for (i
= 0; stat0
; i
++, stat0
>>= 1)
227 generic_handle_irq(i
+ sachip
->irq_base
);
229 for (i
= 32; stat1
; i
++, stat1
>>= 1)
231 generic_handle_irq(i
+ sachip
->irq_base
);
233 /* For level-based interrupts */
234 desc
->chip
->unmask(irq
);
237 #define SA1111_IRQMASK_LO(x) (1 << (x - sachip->irq_base))
238 #define SA1111_IRQMASK_HI(x) (1 << (x - sachip->irq_base - 32))
240 static void sa1111_ack_irq(unsigned int irq
)
244 static void sa1111_mask_lowirq(unsigned int irq
)
246 struct sa1111
*sachip
= get_irq_chip_data(irq
);
247 void __iomem
*mapbase
= sachip
->base
+ SA1111_INTC
;
250 ie0
= sa1111_readl(mapbase
+ SA1111_INTEN0
);
251 ie0
&= ~SA1111_IRQMASK_LO(irq
);
252 writel(ie0
, mapbase
+ SA1111_INTEN0
);
255 static void sa1111_unmask_lowirq(unsigned int irq
)
257 struct sa1111
*sachip
= get_irq_chip_data(irq
);
258 void __iomem
*mapbase
= sachip
->base
+ SA1111_INTC
;
261 ie0
= sa1111_readl(mapbase
+ SA1111_INTEN0
);
262 ie0
|= SA1111_IRQMASK_LO(irq
);
263 sa1111_writel(ie0
, mapbase
+ SA1111_INTEN0
);
267 * Attempt to re-trigger the interrupt. The SA1111 contains a register
268 * (INTSET) which claims to do this. However, in practice no amount of
269 * manipulation of INTEN and INTSET guarantees that the interrupt will
270 * be triggered. In fact, its very difficult, if not impossible to get
271 * INTSET to re-trigger the interrupt.
273 static int sa1111_retrigger_lowirq(unsigned int irq
)
275 struct sa1111
*sachip
= get_irq_chip_data(irq
);
276 void __iomem
*mapbase
= sachip
->base
+ SA1111_INTC
;
277 unsigned int mask
= SA1111_IRQMASK_LO(irq
);
281 ip0
= sa1111_readl(mapbase
+ SA1111_INTPOL0
);
282 for (i
= 0; i
< 8; i
++) {
283 sa1111_writel(ip0
^ mask
, mapbase
+ SA1111_INTPOL0
);
284 sa1111_writel(ip0
, mapbase
+ SA1111_INTPOL0
);
285 if (sa1111_readl(mapbase
+ SA1111_INTSTATCLR1
) & mask
)
290 printk(KERN_ERR
"Danger Will Robinson: failed to "
291 "re-trigger IRQ%d\n", irq
);
292 return i
== 8 ? -1 : 0;
295 static int sa1111_type_lowirq(unsigned int irq
, unsigned int flags
)
297 struct sa1111
*sachip
= get_irq_chip_data(irq
);
298 void __iomem
*mapbase
= sachip
->base
+ SA1111_INTC
;
299 unsigned int mask
= SA1111_IRQMASK_LO(irq
);
302 if (flags
== IRQ_TYPE_PROBE
)
305 if ((!(flags
& IRQ_TYPE_EDGE_RISING
) ^ !(flags
& IRQ_TYPE_EDGE_FALLING
)) == 0)
308 ip0
= sa1111_readl(mapbase
+ SA1111_INTPOL0
);
309 if (flags
& IRQ_TYPE_EDGE_RISING
)
313 sa1111_writel(ip0
, mapbase
+ SA1111_INTPOL0
);
314 sa1111_writel(ip0
, mapbase
+ SA1111_WAKEPOL0
);
319 static int sa1111_wake_lowirq(unsigned int irq
, unsigned int on
)
321 struct sa1111
*sachip
= get_irq_chip_data(irq
);
322 void __iomem
*mapbase
= sachip
->base
+ SA1111_INTC
;
323 unsigned int mask
= SA1111_IRQMASK_LO(irq
);
326 we0
= sa1111_readl(mapbase
+ SA1111_WAKEEN0
);
331 sa1111_writel(we0
, mapbase
+ SA1111_WAKEEN0
);
336 static struct irq_chip sa1111_low_chip
= {
338 .ack
= sa1111_ack_irq
,
339 .mask
= sa1111_mask_lowirq
,
340 .unmask
= sa1111_unmask_lowirq
,
341 .retrigger
= sa1111_retrigger_lowirq
,
342 .set_type
= sa1111_type_lowirq
,
343 .set_wake
= sa1111_wake_lowirq
,
346 static void sa1111_mask_highirq(unsigned int irq
)
348 struct sa1111
*sachip
= get_irq_chip_data(irq
);
349 void __iomem
*mapbase
= sachip
->base
+ SA1111_INTC
;
352 ie1
= sa1111_readl(mapbase
+ SA1111_INTEN1
);
353 ie1
&= ~SA1111_IRQMASK_HI(irq
);
354 sa1111_writel(ie1
, mapbase
+ SA1111_INTEN1
);
357 static void sa1111_unmask_highirq(unsigned int irq
)
359 struct sa1111
*sachip
= get_irq_chip_data(irq
);
360 void __iomem
*mapbase
= sachip
->base
+ SA1111_INTC
;
363 ie1
= sa1111_readl(mapbase
+ SA1111_INTEN1
);
364 ie1
|= SA1111_IRQMASK_HI(irq
);
365 sa1111_writel(ie1
, mapbase
+ SA1111_INTEN1
);
369 * Attempt to re-trigger the interrupt. The SA1111 contains a register
370 * (INTSET) which claims to do this. However, in practice no amount of
371 * manipulation of INTEN and INTSET guarantees that the interrupt will
372 * be triggered. In fact, its very difficult, if not impossible to get
373 * INTSET to re-trigger the interrupt.
375 static int sa1111_retrigger_highirq(unsigned int irq
)
377 struct sa1111
*sachip
= get_irq_chip_data(irq
);
378 void __iomem
*mapbase
= sachip
->base
+ SA1111_INTC
;
379 unsigned int mask
= SA1111_IRQMASK_HI(irq
);
383 ip1
= sa1111_readl(mapbase
+ SA1111_INTPOL1
);
384 for (i
= 0; i
< 8; i
++) {
385 sa1111_writel(ip1
^ mask
, mapbase
+ SA1111_INTPOL1
);
386 sa1111_writel(ip1
, mapbase
+ SA1111_INTPOL1
);
387 if (sa1111_readl(mapbase
+ SA1111_INTSTATCLR1
) & mask
)
392 printk(KERN_ERR
"Danger Will Robinson: failed to "
393 "re-trigger IRQ%d\n", irq
);
394 return i
== 8 ? -1 : 0;
397 static int sa1111_type_highirq(unsigned int irq
, unsigned int flags
)
399 struct sa1111
*sachip
= get_irq_chip_data(irq
);
400 void __iomem
*mapbase
= sachip
->base
+ SA1111_INTC
;
401 unsigned int mask
= SA1111_IRQMASK_HI(irq
);
404 if (flags
== IRQ_TYPE_PROBE
)
407 if ((!(flags
& IRQ_TYPE_EDGE_RISING
) ^ !(flags
& IRQ_TYPE_EDGE_FALLING
)) == 0)
410 ip1
= sa1111_readl(mapbase
+ SA1111_INTPOL1
);
411 if (flags
& IRQ_TYPE_EDGE_RISING
)
415 sa1111_writel(ip1
, mapbase
+ SA1111_INTPOL1
);
416 sa1111_writel(ip1
, mapbase
+ SA1111_WAKEPOL1
);
421 static int sa1111_wake_highirq(unsigned int irq
, unsigned int on
)
423 struct sa1111
*sachip
= get_irq_chip_data(irq
);
424 void __iomem
*mapbase
= sachip
->base
+ SA1111_INTC
;
425 unsigned int mask
= SA1111_IRQMASK_HI(irq
);
428 we1
= sa1111_readl(mapbase
+ SA1111_WAKEEN1
);
433 sa1111_writel(we1
, mapbase
+ SA1111_WAKEEN1
);
438 static struct irq_chip sa1111_high_chip
= {
440 .ack
= sa1111_ack_irq
,
441 .mask
= sa1111_mask_highirq
,
442 .unmask
= sa1111_unmask_highirq
,
443 .retrigger
= sa1111_retrigger_highirq
,
444 .set_type
= sa1111_type_highirq
,
445 .set_wake
= sa1111_wake_highirq
,
448 static void sa1111_setup_irq(struct sa1111
*sachip
)
450 void __iomem
*irqbase
= sachip
->base
+ SA1111_INTC
;
454 * We're guaranteed that this region hasn't been taken.
456 request_mem_region(sachip
->phys
+ SA1111_INTC
, 512, "irq");
458 /* disable all IRQs */
459 sa1111_writel(0, irqbase
+ SA1111_INTEN0
);
460 sa1111_writel(0, irqbase
+ SA1111_INTEN1
);
461 sa1111_writel(0, irqbase
+ SA1111_WAKEEN0
);
462 sa1111_writel(0, irqbase
+ SA1111_WAKEEN1
);
465 * detect on rising edge. Note: Feb 2001 Errata for SA1111
466 * specifies that S0ReadyInt and S1ReadyInt should be '1'.
468 sa1111_writel(0, irqbase
+ SA1111_INTPOL0
);
469 sa1111_writel(SA1111_IRQMASK_HI(IRQ_S0_READY_NINT
) |
470 SA1111_IRQMASK_HI(IRQ_S1_READY_NINT
),
471 irqbase
+ SA1111_INTPOL1
);
474 sa1111_writel(~0, irqbase
+ SA1111_INTSTATCLR0
);
475 sa1111_writel(~0, irqbase
+ SA1111_INTSTATCLR1
);
477 for (irq
= IRQ_GPAIN0
; irq
<= SSPROR
; irq
++) {
478 set_irq_chip(irq
, &sa1111_low_chip
);
479 set_irq_chip_data(irq
, sachip
);
480 set_irq_handler(irq
, handle_edge_irq
);
481 set_irq_flags(irq
, IRQF_VALID
| IRQF_PROBE
);
484 for (irq
= AUDXMTDMADONEA
; irq
<= IRQ_S1_BVD1_STSCHG
; irq
++) {
485 set_irq_chip(irq
, &sa1111_high_chip
);
486 set_irq_chip_data(irq
, sachip
);
487 set_irq_handler(irq
, handle_edge_irq
);
488 set_irq_flags(irq
, IRQF_VALID
| IRQF_PROBE
);
492 * Register SA1111 interrupt
494 set_irq_type(sachip
->irq
, IRQ_TYPE_EDGE_RISING
);
495 set_irq_data(sachip
->irq
, sachip
);
496 set_irq_chained_handler(sachip
->irq
, sa1111_irq_handler
);
500 * Bring the SA1111 out of reset. This requires a set procedure:
501 * 1. nRESET asserted (by hardware)
502 * 2. CLK turned on from SA1110
503 * 3. nRESET deasserted
504 * 4. VCO turned on, PLL_BYPASS turned off
505 * 5. Wait lock time, then assert RCLKEn
506 * 7. PCR set to allow clocking of individual functions
508 * Until we've done this, the only registers we can access are:
513 static void sa1111_wake(struct sa1111
*sachip
)
515 unsigned long flags
, r
;
517 spin_lock_irqsave(&sachip
->lock
, flags
);
519 clk_enable(sachip
->clk
);
522 * Turn VCO on, and disable PLL Bypass.
524 r
= sa1111_readl(sachip
->base
+ SA1111_SKCR
);
526 sa1111_writel(r
, sachip
->base
+ SA1111_SKCR
);
527 r
|= SKCR_PLL_BYPASS
| SKCR_OE_EN
;
528 sa1111_writel(r
, sachip
->base
+ SA1111_SKCR
);
531 * Wait lock time. SA1111 manual _doesn't_
532 * specify a figure for this! We choose 100us.
537 * Enable RCLK. We also ensure that RDYEN is set.
539 r
|= SKCR_RCLKEN
| SKCR_RDYEN
;
540 sa1111_writel(r
, sachip
->base
+ SA1111_SKCR
);
543 * Wait 14 RCLK cycles for the chip to finish coming out
544 * of reset. (RCLK=24MHz). This is 590ns.
549 * Ensure all clocks are initially off.
551 sa1111_writel(0, sachip
->base
+ SA1111_SKPCR
);
553 spin_unlock_irqrestore(&sachip
->lock
, flags
);
556 #ifdef CONFIG_ARCH_SA1100
558 static u32 sa1111_dma_mask
[] = {
570 * Configure the SA1111 shared memory controller.
573 sa1111_configure_smc(struct sa1111
*sachip
, int sdram
, unsigned int drac
,
574 unsigned int cas_latency
)
576 unsigned int smcr
= SMCR_DTIM
| SMCR_MBGE
| FInsrt(drac
, SMCR_DRAC
);
578 if (cas_latency
== 3)
581 sa1111_writel(smcr
, sachip
->base
+ SA1111_SMCR
);
584 * Now clear the bits in the DMA mask to work around the SA1111
585 * DMA erratum (Intel StrongARM SA-1111 Microprocessor Companion
586 * Chip Specification Update, June 2000, Erratum #7).
588 if (sachip
->dev
->dma_mask
)
589 *sachip
->dev
->dma_mask
&= sa1111_dma_mask
[drac
>> 2];
591 sachip
->dev
->coherent_dma_mask
&= sa1111_dma_mask
[drac
>> 2];
596 static void sa1111_dev_release(struct device
*_dev
)
598 struct sa1111_dev
*dev
= SA1111_DEV(_dev
);
600 release_resource(&dev
->res
);
605 sa1111_init_one_child(struct sa1111
*sachip
, struct resource
*parent
,
606 struct sa1111_dev_info
*info
)
608 struct sa1111_dev
*dev
;
611 dev
= kzalloc(sizeof(struct sa1111_dev
), GFP_KERNEL
);
617 dev_set_name(&dev
->dev
, "%4.4lx", info
->offset
);
618 dev
->devid
= info
->devid
;
619 dev
->dev
.parent
= sachip
->dev
;
620 dev
->dev
.bus
= &sa1111_bus_type
;
621 dev
->dev
.release
= sa1111_dev_release
;
622 dev
->dev
.coherent_dma_mask
= sachip
->dev
->coherent_dma_mask
;
623 dev
->res
.start
= sachip
->phys
+ info
->offset
;
624 dev
->res
.end
= dev
->res
.start
+ 511;
625 dev
->res
.name
= dev_name(&dev
->dev
);
626 dev
->res
.flags
= IORESOURCE_MEM
;
627 dev
->mapbase
= sachip
->base
+ info
->offset
;
628 dev
->skpcr_mask
= info
->skpcr_mask
;
629 memmove(dev
->irq
, info
->irq
, sizeof(dev
->irq
));
631 ret
= request_resource(parent
, &dev
->res
);
633 printk("SA1111: failed to allocate resource for %s\n",
635 dev_set_name(&dev
->dev
, NULL
);
641 ret
= device_register(&dev
->dev
);
643 release_resource(&dev
->res
);
648 #ifdef CONFIG_DMABOUNCE
650 * If the parent device has a DMA mask associated with it,
651 * propagate it down to the children.
653 if (sachip
->dev
->dma_mask
) {
654 dev
->dma_mask
= *sachip
->dev
->dma_mask
;
655 dev
->dev
.dma_mask
= &dev
->dma_mask
;
657 if (dev
->dma_mask
!= 0xffffffffUL
) {
658 ret
= dmabounce_register_dev(&dev
->dev
, 1024, 4096);
660 dev_err(&dev
->dev
, "SA1111: Failed to register"
661 " with dmabounce\n");
662 device_unregister(&dev
->dev
);
673 * sa1111_probe - probe for a single SA1111 chip.
674 * @phys_addr: physical address of device.
676 * Probe for a SA1111 chip. This must be called
677 * before any other SA1111-specific code.
680 * %-ENODEV device not found.
681 * %-EBUSY physical address already marked in-use.
685 __sa1111_probe(struct device
*me
, struct resource
*mem
, int irq
)
687 struct sa1111
*sachip
;
689 unsigned int has_devs
;
690 int i
, ret
= -ENODEV
;
692 sachip
= kzalloc(sizeof(struct sa1111
), GFP_KERNEL
);
696 sachip
->clk
= clk_get(me
, "SA1111_CLK");
697 if (IS_ERR(sachip
->clk
)) {
698 ret
= PTR_ERR(sachip
->clk
);
702 spin_lock_init(&sachip
->lock
);
705 dev_set_drvdata(sachip
->dev
, sachip
);
707 sachip
->phys
= mem
->start
;
711 * Map the whole region. This also maps the
712 * registers for our children.
714 sachip
->base
= ioremap(mem
->start
, PAGE_SIZE
* 2);
721 * Probe for the chip. Only touch the SBI registers.
723 id
= sa1111_readl(sachip
->base
+ SA1111_SKID
);
724 if ((id
& SKID_ID_MASK
) != SKID_SA1111_ID
) {
725 printk(KERN_DEBUG
"SA1111 not detected: ID = %08lx\n", id
);
730 printk(KERN_INFO
"SA1111 Microprocessor Companion Chip: "
731 "silicon revision %lx, metal revision %lx\n",
732 (id
& SKID_SIREV_MASK
)>>4, (id
& SKID_MTREV_MASK
));
735 * We found it. Wake the chip up, and initialise.
739 #ifdef CONFIG_ARCH_SA1100
744 * The SDRAM configuration of the SA1110 and the SA1111 must
745 * match. This is very important to ensure that SA1111 accesses
746 * don't corrupt the SDRAM. Note that this ungates the SA1111's
747 * MBGNT signal, so we must have called sa1110_mb_disable()
750 sa1111_configure_smc(sachip
, 1,
751 FExtr(MDCNFG
, MDCNFG_SA1110_DRAC0
),
752 FExtr(MDCNFG
, MDCNFG_SA1110_TDL0
));
755 * We only need to turn on DCLK whenever we want to use the
756 * DMA. It can otherwise be held firmly in the off position.
757 * (currently, we always enable it.)
759 val
= sa1111_readl(sachip
->base
+ SA1111_SKPCR
);
760 sa1111_writel(val
| SKPCR_DCLKEN
, sachip
->base
+ SA1111_SKPCR
);
763 * Enable the SA1110 memory bus request and grant signals.
770 * The interrupt controller must be initialised before any
771 * other device to ensure that the interrupts are available.
773 if (sachip
->irq
!= NO_IRQ
)
774 sa1111_setup_irq(sachip
);
779 if (machine_is_assabet() || machine_is_jornada720() ||
781 has_devs
&= ~(1 << 4);
783 has_devs
&= ~(1 << 1);
785 for (i
= 0; i
< ARRAY_SIZE(sa1111_devices
); i
++)
786 if (has_devs
& (1 << i
))
787 sa1111_init_one_child(sachip
, mem
, &sa1111_devices
[i
]);
792 iounmap(sachip
->base
);
794 clk_put(sachip
->clk
);
800 static int sa1111_remove_one(struct device
*dev
, void *data
)
802 device_unregister(dev
);
806 static void __sa1111_remove(struct sa1111
*sachip
)
808 void __iomem
*irqbase
= sachip
->base
+ SA1111_INTC
;
810 device_for_each_child(sachip
->dev
, NULL
, sa1111_remove_one
);
812 /* disable all IRQs */
813 sa1111_writel(0, irqbase
+ SA1111_INTEN0
);
814 sa1111_writel(0, irqbase
+ SA1111_INTEN1
);
815 sa1111_writel(0, irqbase
+ SA1111_WAKEEN0
);
816 sa1111_writel(0, irqbase
+ SA1111_WAKEEN1
);
818 clk_disable(sachip
->clk
);
820 if (sachip
->irq
!= NO_IRQ
) {
821 set_irq_chained_handler(sachip
->irq
, NULL
);
822 set_irq_data(sachip
->irq
, NULL
);
824 release_mem_region(sachip
->phys
+ SA1111_INTC
, 512);
827 iounmap(sachip
->base
);
828 clk_put(sachip
->clk
);
833 * According to the "Intel StrongARM SA-1111 Microprocessor Companion
834 * Chip Specification Update" (June 2000), erratum #7, there is a
835 * significant bug in the SA1111 SDRAM shared memory controller. If
836 * an access to a region of memory above 1MB relative to the bank base,
837 * it is important that address bit 10 _NOT_ be asserted. Depending
838 * on the configuration of the RAM, bit 10 may correspond to one
839 * of several different (processor-relative) address bits.
841 * This routine only identifies whether or not a given DMA address
842 * is susceptible to the bug.
844 * This should only get called for sa1111_device types due to the
845 * way we configure our device dma_masks.
847 int dma_needs_bounce(struct device
*dev
, dma_addr_t addr
, size_t size
)
850 * Section 4.6 of the "Intel StrongARM SA-1111 Development Module
851 * User's Guide" mentions that jumpers R51 and R52 control the
852 * target of SA-1111 DMA (either SDRAM bank 0 on Assabet, or
853 * SDRAM bank 1 on Neponset). The default configuration selects
854 * Assabet, so any address in bank 1 is necessarily invalid.
856 return ((machine_is_assabet() || machine_is_pfs168()) &&
857 (addr
>= 0xc8000000 || (addr
+ size
) >= 0xc8000000));
860 struct sa1111_save_data
{
865 unsigned char skpwm0
;
866 unsigned char skpwm1
;
869 * Interrupt controller
871 unsigned int intpol0
;
872 unsigned int intpol1
;
875 unsigned int wakepol0
;
876 unsigned int wakepol1
;
877 unsigned int wakeen0
;
878 unsigned int wakeen1
;
883 static int sa1111_suspend(struct platform_device
*dev
, pm_message_t state
)
885 struct sa1111
*sachip
= platform_get_drvdata(dev
);
886 struct sa1111_save_data
*save
;
891 save
= kmalloc(sizeof(struct sa1111_save_data
), GFP_KERNEL
);
894 sachip
->saved_state
= save
;
896 spin_lock_irqsave(&sachip
->lock
, flags
);
902 save
->skcr
= sa1111_readl(base
+ SA1111_SKCR
);
903 save
->skpcr
= sa1111_readl(base
+ SA1111_SKPCR
);
904 save
->skcdr
= sa1111_readl(base
+ SA1111_SKCDR
);
905 save
->skaud
= sa1111_readl(base
+ SA1111_SKAUD
);
906 save
->skpwm0
= sa1111_readl(base
+ SA1111_SKPWM0
);
907 save
->skpwm1
= sa1111_readl(base
+ SA1111_SKPWM1
);
909 base
= sachip
->base
+ SA1111_INTC
;
910 save
->intpol0
= sa1111_readl(base
+ SA1111_INTPOL0
);
911 save
->intpol1
= sa1111_readl(base
+ SA1111_INTPOL1
);
912 save
->inten0
= sa1111_readl(base
+ SA1111_INTEN0
);
913 save
->inten1
= sa1111_readl(base
+ SA1111_INTEN1
);
914 save
->wakepol0
= sa1111_readl(base
+ SA1111_WAKEPOL0
);
915 save
->wakepol1
= sa1111_readl(base
+ SA1111_WAKEPOL1
);
916 save
->wakeen0
= sa1111_readl(base
+ SA1111_WAKEEN0
);
917 save
->wakeen1
= sa1111_readl(base
+ SA1111_WAKEEN1
);
922 val
= sa1111_readl(sachip
->base
+ SA1111_SKCR
);
923 sa1111_writel(val
| SKCR_SLEEP
, sachip
->base
+ SA1111_SKCR
);
924 sa1111_writel(0, sachip
->base
+ SA1111_SKPWM0
);
925 sa1111_writel(0, sachip
->base
+ SA1111_SKPWM1
);
927 clk_disable(sachip
->clk
);
929 spin_unlock_irqrestore(&sachip
->lock
, flags
);
935 * sa1111_resume - Restore the SA1111 device state.
936 * @dev: device to restore
938 * Restore the general state of the SA1111; clock control and
939 * interrupt controller. Other parts of the SA1111 must be
940 * restored by their respective drivers, and must be called
941 * via LDM after this function.
943 static int sa1111_resume(struct platform_device
*dev
)
945 struct sa1111
*sachip
= platform_get_drvdata(dev
);
946 struct sa1111_save_data
*save
;
947 unsigned long flags
, id
;
950 save
= sachip
->saved_state
;
955 * Ensure that the SA1111 is still here.
956 * FIXME: shouldn't do this here.
958 id
= sa1111_readl(sachip
->base
+ SA1111_SKID
);
959 if ((id
& SKID_ID_MASK
) != SKID_SA1111_ID
) {
960 __sa1111_remove(sachip
);
961 platform_set_drvdata(dev
, NULL
);
967 * First of all, wake up the chip.
972 * Only lock for write ops. Also, sa1111_wake must be called with
975 spin_lock_irqsave(&sachip
->lock
, flags
);
977 sa1111_writel(0, sachip
->base
+ SA1111_INTC
+ SA1111_INTEN0
);
978 sa1111_writel(0, sachip
->base
+ SA1111_INTC
+ SA1111_INTEN1
);
981 sa1111_writel(save
->skcr
, base
+ SA1111_SKCR
);
982 sa1111_writel(save
->skpcr
, base
+ SA1111_SKPCR
);
983 sa1111_writel(save
->skcdr
, base
+ SA1111_SKCDR
);
984 sa1111_writel(save
->skaud
, base
+ SA1111_SKAUD
);
985 sa1111_writel(save
->skpwm0
, base
+ SA1111_SKPWM0
);
986 sa1111_writel(save
->skpwm1
, base
+ SA1111_SKPWM1
);
988 base
= sachip
->base
+ SA1111_INTC
;
989 sa1111_writel(save
->intpol0
, base
+ SA1111_INTPOL0
);
990 sa1111_writel(save
->intpol1
, base
+ SA1111_INTPOL1
);
991 sa1111_writel(save
->inten0
, base
+ SA1111_INTEN0
);
992 sa1111_writel(save
->inten1
, base
+ SA1111_INTEN1
);
993 sa1111_writel(save
->wakepol0
, base
+ SA1111_WAKEPOL0
);
994 sa1111_writel(save
->wakepol1
, base
+ SA1111_WAKEPOL1
);
995 sa1111_writel(save
->wakeen0
, base
+ SA1111_WAKEEN0
);
996 sa1111_writel(save
->wakeen1
, base
+ SA1111_WAKEEN1
);
998 spin_unlock_irqrestore(&sachip
->lock
, flags
);
1000 sachip
->saved_state
= NULL
;
1007 #define sa1111_suspend NULL
1008 #define sa1111_resume NULL
1011 static int __devinit
sa1111_probe(struct platform_device
*pdev
)
1013 struct resource
*mem
;
1016 mem
= platform_get_resource(pdev
, IORESOURCE_MEM
, 0);
1019 irq
= platform_get_irq(pdev
, 0);
1023 return __sa1111_probe(&pdev
->dev
, mem
, irq
);
1026 static int sa1111_remove(struct platform_device
*pdev
)
1028 struct sa1111
*sachip
= platform_get_drvdata(pdev
);
1031 __sa1111_remove(sachip
);
1032 platform_set_drvdata(pdev
, NULL
);
1035 kfree(sachip
->saved_state
);
1036 sachip
->saved_state
= NULL
;
1044 * Not sure if this should be on the system bus or not yet.
1045 * We really want some way to register a system device at
1046 * the per-machine level, and then have this driver pick
1047 * up the registered devices.
1049 * We also need to handle the SDRAM configuration for
1050 * PXA250/SA1110 machine classes.
1052 static struct platform_driver sa1111_device_driver
= {
1053 .probe
= sa1111_probe
,
1054 .remove
= sa1111_remove
,
1055 .suspend
= sa1111_suspend
,
1056 .resume
= sa1111_resume
,
1063 * Get the parent device driver (us) structure
1064 * from a child function device
1066 static inline struct sa1111
*sa1111_chip_driver(struct sa1111_dev
*sadev
)
1068 return (struct sa1111
*)dev_get_drvdata(sadev
->dev
.parent
);
1072 * The bits in the opdiv field are non-linear.
1074 static unsigned char opdiv_table
[] = { 1, 4, 2, 8 };
1076 static unsigned int __sa1111_pll_clock(struct sa1111
*sachip
)
1078 unsigned int skcdr
, fbdiv
, ipdiv
, opdiv
;
1080 skcdr
= sa1111_readl(sachip
->base
+ SA1111_SKCDR
);
1082 fbdiv
= (skcdr
& 0x007f) + 2;
1083 ipdiv
= ((skcdr
& 0x0f80) >> 7) + 2;
1084 opdiv
= opdiv_table
[(skcdr
& 0x3000) >> 12];
1086 return 3686400 * fbdiv
/ (ipdiv
* opdiv
);
1090 * sa1111_pll_clock - return the current PLL clock frequency.
1091 * @sadev: SA1111 function block
1093 * BUG: we should look at SKCR. We also blindly believe that
1094 * the chip is being fed with the 3.6864MHz clock.
1096 * Returns the PLL clock in Hz.
1098 unsigned int sa1111_pll_clock(struct sa1111_dev
*sadev
)
1100 struct sa1111
*sachip
= sa1111_chip_driver(sadev
);
1102 return __sa1111_pll_clock(sachip
);
1104 EXPORT_SYMBOL(sa1111_pll_clock
);
1107 * sa1111_select_audio_mode - select I2S or AC link mode
1108 * @sadev: SA1111 function block
1109 * @mode: One of %SA1111_AUDIO_ACLINK or %SA1111_AUDIO_I2S
1111 * Frob the SKCR to select AC Link mode or I2S mode for
1114 void sa1111_select_audio_mode(struct sa1111_dev
*sadev
, int mode
)
1116 struct sa1111
*sachip
= sa1111_chip_driver(sadev
);
1117 unsigned long flags
;
1120 spin_lock_irqsave(&sachip
->lock
, flags
);
1122 val
= sa1111_readl(sachip
->base
+ SA1111_SKCR
);
1123 if (mode
== SA1111_AUDIO_I2S
) {
1128 sa1111_writel(val
, sachip
->base
+ SA1111_SKCR
);
1130 spin_unlock_irqrestore(&sachip
->lock
, flags
);
1132 EXPORT_SYMBOL(sa1111_select_audio_mode
);
1135 * sa1111_set_audio_rate - set the audio sample rate
1136 * @sadev: SA1111 SAC function block
1137 * @rate: sample rate to select
1139 int sa1111_set_audio_rate(struct sa1111_dev
*sadev
, int rate
)
1141 struct sa1111
*sachip
= sa1111_chip_driver(sadev
);
1144 if (sadev
->devid
!= SA1111_DEVID_SAC
)
1147 div
= (__sa1111_pll_clock(sachip
) / 256 + rate
/ 2) / rate
;
1153 sa1111_writel(div
- 1, sachip
->base
+ SA1111_SKAUD
);
1157 EXPORT_SYMBOL(sa1111_set_audio_rate
);
1160 * sa1111_get_audio_rate - get the audio sample rate
1161 * @sadev: SA1111 SAC function block device
1163 int sa1111_get_audio_rate(struct sa1111_dev
*sadev
)
1165 struct sa1111
*sachip
= sa1111_chip_driver(sadev
);
1168 if (sadev
->devid
!= SA1111_DEVID_SAC
)
1171 div
= sa1111_readl(sachip
->base
+ SA1111_SKAUD
) + 1;
1173 return __sa1111_pll_clock(sachip
) / (256 * div
);
1175 EXPORT_SYMBOL(sa1111_get_audio_rate
);
1177 void sa1111_set_io_dir(struct sa1111_dev
*sadev
,
1178 unsigned int bits
, unsigned int dir
,
1179 unsigned int sleep_dir
)
1181 struct sa1111
*sachip
= sa1111_chip_driver(sadev
);
1182 unsigned long flags
;
1184 void __iomem
*gpio
= sachip
->base
+ SA1111_GPIO
;
1186 #define MODIFY_BITS(port, mask, dir) \
1188 val = sa1111_readl(port); \
1190 val |= (dir) & (mask); \
1191 sa1111_writel(val, port); \
1194 spin_lock_irqsave(&sachip
->lock
, flags
);
1195 MODIFY_BITS(gpio
+ SA1111_GPIO_PADDR
, bits
& 15, dir
);
1196 MODIFY_BITS(gpio
+ SA1111_GPIO_PBDDR
, (bits
>> 8) & 255, dir
>> 8);
1197 MODIFY_BITS(gpio
+ SA1111_GPIO_PCDDR
, (bits
>> 16) & 255, dir
>> 16);
1199 MODIFY_BITS(gpio
+ SA1111_GPIO_PASDR
, bits
& 15, sleep_dir
);
1200 MODIFY_BITS(gpio
+ SA1111_GPIO_PBSDR
, (bits
>> 8) & 255, sleep_dir
>> 8);
1201 MODIFY_BITS(gpio
+ SA1111_GPIO_PCSDR
, (bits
>> 16) & 255, sleep_dir
>> 16);
1202 spin_unlock_irqrestore(&sachip
->lock
, flags
);
1204 EXPORT_SYMBOL(sa1111_set_io_dir
);
1206 void sa1111_set_io(struct sa1111_dev
*sadev
, unsigned int bits
, unsigned int v
)
1208 struct sa1111
*sachip
= sa1111_chip_driver(sadev
);
1209 unsigned long flags
;
1211 void __iomem
*gpio
= sachip
->base
+ SA1111_GPIO
;
1213 spin_lock_irqsave(&sachip
->lock
, flags
);
1214 MODIFY_BITS(gpio
+ SA1111_GPIO_PADWR
, bits
& 15, v
);
1215 MODIFY_BITS(gpio
+ SA1111_GPIO_PBDWR
, (bits
>> 8) & 255, v
>> 8);
1216 MODIFY_BITS(gpio
+ SA1111_GPIO_PCDWR
, (bits
>> 16) & 255, v
>> 16);
1217 spin_unlock_irqrestore(&sachip
->lock
, flags
);
1219 EXPORT_SYMBOL(sa1111_set_io
);
1221 void sa1111_set_sleep_io(struct sa1111_dev
*sadev
, unsigned int bits
, unsigned int v
)
1223 struct sa1111
*sachip
= sa1111_chip_driver(sadev
);
1224 unsigned long flags
;
1226 void __iomem
*gpio
= sachip
->base
+ SA1111_GPIO
;
1228 spin_lock_irqsave(&sachip
->lock
, flags
);
1229 MODIFY_BITS(gpio
+ SA1111_GPIO_PASSR
, bits
& 15, v
);
1230 MODIFY_BITS(gpio
+ SA1111_GPIO_PBSSR
, (bits
>> 8) & 255, v
>> 8);
1231 MODIFY_BITS(gpio
+ SA1111_GPIO_PCSSR
, (bits
>> 16) & 255, v
>> 16);
1232 spin_unlock_irqrestore(&sachip
->lock
, flags
);
1234 EXPORT_SYMBOL(sa1111_set_sleep_io
);
1237 * Individual device operations.
1241 * sa1111_enable_device - enable an on-chip SA1111 function block
1242 * @sadev: SA1111 function block device to enable
1244 void sa1111_enable_device(struct sa1111_dev
*sadev
)
1246 struct sa1111
*sachip
= sa1111_chip_driver(sadev
);
1247 unsigned long flags
;
1250 spin_lock_irqsave(&sachip
->lock
, flags
);
1251 val
= sa1111_readl(sachip
->base
+ SA1111_SKPCR
);
1252 sa1111_writel(val
| sadev
->skpcr_mask
, sachip
->base
+ SA1111_SKPCR
);
1253 spin_unlock_irqrestore(&sachip
->lock
, flags
);
1255 EXPORT_SYMBOL(sa1111_enable_device
);
1258 * sa1111_disable_device - disable an on-chip SA1111 function block
1259 * @sadev: SA1111 function block device to disable
1261 void sa1111_disable_device(struct sa1111_dev
*sadev
)
1263 struct sa1111
*sachip
= sa1111_chip_driver(sadev
);
1264 unsigned long flags
;
1267 spin_lock_irqsave(&sachip
->lock
, flags
);
1268 val
= sa1111_readl(sachip
->base
+ SA1111_SKPCR
);
1269 sa1111_writel(val
& ~sadev
->skpcr_mask
, sachip
->base
+ SA1111_SKPCR
);
1270 spin_unlock_irqrestore(&sachip
->lock
, flags
);
1272 EXPORT_SYMBOL(sa1111_disable_device
);
1275 * SA1111 "Register Access Bus."
1277 * We model this as a regular bus type, and hang devices directly
1280 static int sa1111_match(struct device
*_dev
, struct device_driver
*_drv
)
1282 struct sa1111_dev
*dev
= SA1111_DEV(_dev
);
1283 struct sa1111_driver
*drv
= SA1111_DRV(_drv
);
1285 return dev
->devid
== drv
->devid
;
1288 static int sa1111_bus_suspend(struct device
*dev
, pm_message_t state
)
1290 struct sa1111_dev
*sadev
= SA1111_DEV(dev
);
1291 struct sa1111_driver
*drv
= SA1111_DRV(dev
->driver
);
1294 if (drv
&& drv
->suspend
)
1295 ret
= drv
->suspend(sadev
, state
);
1299 static int sa1111_bus_resume(struct device
*dev
)
1301 struct sa1111_dev
*sadev
= SA1111_DEV(dev
);
1302 struct sa1111_driver
*drv
= SA1111_DRV(dev
->driver
);
1305 if (drv
&& drv
->resume
)
1306 ret
= drv
->resume(sadev
);
1310 static int sa1111_bus_probe(struct device
*dev
)
1312 struct sa1111_dev
*sadev
= SA1111_DEV(dev
);
1313 struct sa1111_driver
*drv
= SA1111_DRV(dev
->driver
);
1317 ret
= drv
->probe(sadev
);
1321 static int sa1111_bus_remove(struct device
*dev
)
1323 struct sa1111_dev
*sadev
= SA1111_DEV(dev
);
1324 struct sa1111_driver
*drv
= SA1111_DRV(dev
->driver
);
1328 ret
= drv
->remove(sadev
);
1332 struct bus_type sa1111_bus_type
= {
1333 .name
= "sa1111-rab",
1334 .match
= sa1111_match
,
1335 .probe
= sa1111_bus_probe
,
1336 .remove
= sa1111_bus_remove
,
1337 .suspend
= sa1111_bus_suspend
,
1338 .resume
= sa1111_bus_resume
,
1340 EXPORT_SYMBOL(sa1111_bus_type
);
1342 int sa1111_driver_register(struct sa1111_driver
*driver
)
1344 driver
->drv
.bus
= &sa1111_bus_type
;
1345 return driver_register(&driver
->drv
);
1347 EXPORT_SYMBOL(sa1111_driver_register
);
1349 void sa1111_driver_unregister(struct sa1111_driver
*driver
)
1351 driver_unregister(&driver
->drv
);
1353 EXPORT_SYMBOL(sa1111_driver_unregister
);
1355 static int __init
sa1111_init(void)
1357 int ret
= bus_register(&sa1111_bus_type
);
1359 platform_driver_register(&sa1111_device_driver
);
1363 static void __exit
sa1111_exit(void)
1365 platform_driver_unregister(&sa1111_device_driver
);
1366 bus_unregister(&sa1111_bus_type
);
1369 subsys_initcall(sa1111_init
);
1370 module_exit(sa1111_exit
);
1372 MODULE_DESCRIPTION("Intel Corporation SA1111 core driver");
1373 MODULE_LICENSE("GPL");