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>
29 #include <asm/hardware.h>
30 #include <asm/mach-types.h>
33 #include <asm/mach/irq.h>
34 #include <asm/sizes.h>
36 #include <asm/hardware/sa1111.h>
38 extern void __init sa1110_mb_enable(void);
41 * We keep the following data for the overall SA1111. Note that the
42 * struct device and struct resource are "fake"; they should be supplied
43 * by the bus above us. However, in the interests of getting all SA1111
44 * drivers converted over to the device model, we provide this as an
45 * anchor point for all the other drivers.
60 * We _really_ need to eliminate this. Its only users
61 * are the PWM and DMA checking code.
63 static struct sa1111 *g_sa1111;
65 struct sa1111_dev_info {
67 unsigned long skpcr_mask;
72 static struct sa1111_dev_info sa1111_devices[] = {
75 .skpcr_mask = SKPCR_UCLKEN,
76 .devid = SA1111_DEVID_USB,
88 .skpcr_mask = SKPCR_I2SCLKEN | SKPCR_L3CLKEN,
89 .devid = SA1111_DEVID_SAC,
99 .skpcr_mask = SKPCR_SCLKEN,
100 .devid = SA1111_DEVID_SSP,
103 .offset = SA1111_KBD,
104 .skpcr_mask = SKPCR_PTCLKEN,
105 .devid = SA1111_DEVID_PS2,
112 .offset = SA1111_MSE,
113 .skpcr_mask = SKPCR_PMCLKEN,
114 .devid = SA1111_DEVID_PS2,
123 .devid = SA1111_DEVID_PCMCIA,
135 void __init sa1111_adjust_zones(int node, unsigned long *size, unsigned long *holes)
137 unsigned int sz = SZ_1M >> PAGE_SHIFT;
142 size[1] = size[0] - sz;
147 * SA1111 interrupt support. Since clearing an IRQ while there are
148 * active IRQs causes the interrupt output to pulse, the upper levels
149 * will call us again if there are more interrupts to process.
152 sa1111_irq_handler(unsigned int irq, struct irq_desc *desc)
154 unsigned int stat0, stat1, i;
155 void __iomem *base = get_irq_data(irq);
157 stat0 = sa1111_readl(base + SA1111_INTSTATCLR0);
158 stat1 = sa1111_readl(base + SA1111_INTSTATCLR1);
160 sa1111_writel(stat0, base + SA1111_INTSTATCLR0);
162 desc->chip->ack(irq);
164 sa1111_writel(stat1, base + SA1111_INTSTATCLR1);
166 if (stat0 == 0 && stat1 == 0) {
167 do_bad_IRQ(irq, desc);
171 for (i = IRQ_SA1111_START; stat0; i++, stat0 >>= 1)
173 handle_edge_irq(i, irq_desc + i);
175 for (i = IRQ_SA1111_START + 32; stat1; i++, stat1 >>= 1)
177 handle_edge_irq(i, irq_desc + i);
179 /* For level-based interrupts */
180 desc->chip->unmask(irq);
183 #define SA1111_IRQMASK_LO(x) (1 << (x - IRQ_SA1111_START))
184 #define SA1111_IRQMASK_HI(x) (1 << (x - IRQ_SA1111_START - 32))
186 static void sa1111_ack_irq(unsigned int irq)
190 static void sa1111_mask_lowirq(unsigned int irq)
192 void __iomem *mapbase = get_irq_chip_data(irq);
195 ie0 = sa1111_readl(mapbase + SA1111_INTEN0);
196 ie0 &= ~SA1111_IRQMASK_LO(irq);
197 writel(ie0, mapbase + SA1111_INTEN0);
200 static void sa1111_unmask_lowirq(unsigned int irq)
202 void __iomem *mapbase = get_irq_chip_data(irq);
205 ie0 = sa1111_readl(mapbase + SA1111_INTEN0);
206 ie0 |= SA1111_IRQMASK_LO(irq);
207 sa1111_writel(ie0, mapbase + SA1111_INTEN0);
211 * Attempt to re-trigger the interrupt. The SA1111 contains a register
212 * (INTSET) which claims to do this. However, in practice no amount of
213 * manipulation of INTEN and INTSET guarantees that the interrupt will
214 * be triggered. In fact, its very difficult, if not impossible to get
215 * INTSET to re-trigger the interrupt.
217 static int sa1111_retrigger_lowirq(unsigned int irq)
219 unsigned int mask = SA1111_IRQMASK_LO(irq);
220 void __iomem *mapbase = get_irq_chip_data(irq);
224 ip0 = sa1111_readl(mapbase + SA1111_INTPOL0);
225 for (i = 0; i < 8; i++) {
226 sa1111_writel(ip0 ^ mask, mapbase + SA1111_INTPOL0);
227 sa1111_writel(ip0, mapbase + SA1111_INTPOL0);
228 if (sa1111_readl(mapbase + SA1111_INTSTATCLR1) & mask)
233 printk(KERN_ERR "Danger Will Robinson: failed to "
234 "re-trigger IRQ%d\n", irq);
235 return i == 8 ? -1 : 0;
238 static int sa1111_type_lowirq(unsigned int irq, unsigned int flags)
240 unsigned int mask = SA1111_IRQMASK_LO(irq);
241 void __iomem *mapbase = get_irq_chip_data(irq);
244 if (flags == IRQT_PROBE)
247 if ((!(flags & __IRQT_RISEDGE) ^ !(flags & __IRQT_FALEDGE)) == 0)
250 ip0 = sa1111_readl(mapbase + SA1111_INTPOL0);
251 if (flags & __IRQT_RISEDGE)
255 sa1111_writel(ip0, mapbase + SA1111_INTPOL0);
256 sa1111_writel(ip0, mapbase + SA1111_WAKEPOL0);
261 static int sa1111_wake_lowirq(unsigned int irq, unsigned int on)
263 unsigned int mask = SA1111_IRQMASK_LO(irq);
264 void __iomem *mapbase = get_irq_chip_data(irq);
267 we0 = sa1111_readl(mapbase + SA1111_WAKEEN0);
272 sa1111_writel(we0, mapbase + SA1111_WAKEEN0);
277 static struct irq_chip sa1111_low_chip = {
279 .ack = sa1111_ack_irq,
280 .mask = sa1111_mask_lowirq,
281 .unmask = sa1111_unmask_lowirq,
282 .retrigger = sa1111_retrigger_lowirq,
283 .set_type = sa1111_type_lowirq,
284 .set_wake = sa1111_wake_lowirq,
287 static void sa1111_mask_highirq(unsigned int irq)
289 void __iomem *mapbase = get_irq_chip_data(irq);
292 ie1 = sa1111_readl(mapbase + SA1111_INTEN1);
293 ie1 &= ~SA1111_IRQMASK_HI(irq);
294 sa1111_writel(ie1, mapbase + SA1111_INTEN1);
297 static void sa1111_unmask_highirq(unsigned int irq)
299 void __iomem *mapbase = get_irq_chip_data(irq);
302 ie1 = sa1111_readl(mapbase + SA1111_INTEN1);
303 ie1 |= SA1111_IRQMASK_HI(irq);
304 sa1111_writel(ie1, mapbase + SA1111_INTEN1);
308 * Attempt to re-trigger the interrupt. The SA1111 contains a register
309 * (INTSET) which claims to do this. However, in practice no amount of
310 * manipulation of INTEN and INTSET guarantees that the interrupt will
311 * be triggered. In fact, its very difficult, if not impossible to get
312 * INTSET to re-trigger the interrupt.
314 static int sa1111_retrigger_highirq(unsigned int irq)
316 unsigned int mask = SA1111_IRQMASK_HI(irq);
317 void __iomem *mapbase = get_irq_chip_data(irq);
321 ip1 = sa1111_readl(mapbase + SA1111_INTPOL1);
322 for (i = 0; i < 8; i++) {
323 sa1111_writel(ip1 ^ mask, mapbase + SA1111_INTPOL1);
324 sa1111_writel(ip1, mapbase + SA1111_INTPOL1);
325 if (sa1111_readl(mapbase + SA1111_INTSTATCLR1) & mask)
330 printk(KERN_ERR "Danger Will Robinson: failed to "
331 "re-trigger IRQ%d\n", irq);
332 return i == 8 ? -1 : 0;
335 static int sa1111_type_highirq(unsigned int irq, unsigned int flags)
337 unsigned int mask = SA1111_IRQMASK_HI(irq);
338 void __iomem *mapbase = get_irq_chip_data(irq);
341 if (flags == IRQT_PROBE)
344 if ((!(flags & __IRQT_RISEDGE) ^ !(flags & __IRQT_FALEDGE)) == 0)
347 ip1 = sa1111_readl(mapbase + SA1111_INTPOL1);
348 if (flags & __IRQT_RISEDGE)
352 sa1111_writel(ip1, mapbase + SA1111_INTPOL1);
353 sa1111_writel(ip1, mapbase + SA1111_WAKEPOL1);
358 static int sa1111_wake_highirq(unsigned int irq, unsigned int on)
360 unsigned int mask = SA1111_IRQMASK_HI(irq);
361 void __iomem *mapbase = get_irq_chip_data(irq);
364 we1 = sa1111_readl(mapbase + SA1111_WAKEEN1);
369 sa1111_writel(we1, mapbase + SA1111_WAKEEN1);
374 static struct irq_chip sa1111_high_chip = {
376 .ack = sa1111_ack_irq,
377 .mask = sa1111_mask_highirq,
378 .unmask = sa1111_unmask_highirq,
379 .retrigger = sa1111_retrigger_highirq,
380 .set_type = sa1111_type_highirq,
381 .set_wake = sa1111_wake_highirq,
384 static void sa1111_setup_irq(struct sa1111 *sachip)
386 void __iomem *irqbase = sachip->base + SA1111_INTC;
390 * We're guaranteed that this region hasn't been taken.
392 request_mem_region(sachip->phys + SA1111_INTC, 512, "irq");
394 /* disable all IRQs */
395 sa1111_writel(0, irqbase + SA1111_INTEN0);
396 sa1111_writel(0, irqbase + SA1111_INTEN1);
397 sa1111_writel(0, irqbase + SA1111_WAKEEN0);
398 sa1111_writel(0, irqbase + SA1111_WAKEEN1);
401 * detect on rising edge. Note: Feb 2001 Errata for SA1111
402 * specifies that S0ReadyInt and S1ReadyInt should be '1'.
404 sa1111_writel(0, irqbase + SA1111_INTPOL0);
405 sa1111_writel(SA1111_IRQMASK_HI(IRQ_S0_READY_NINT) |
406 SA1111_IRQMASK_HI(IRQ_S1_READY_NINT),
407 irqbase + SA1111_INTPOL1);
410 sa1111_writel(~0, irqbase + SA1111_INTSTATCLR0);
411 sa1111_writel(~0, irqbase + SA1111_INTSTATCLR1);
413 for (irq = IRQ_GPAIN0; irq <= SSPROR; irq++) {
414 set_irq_chip(irq, &sa1111_low_chip);
415 set_irq_chip_data(irq, irqbase);
416 set_irq_handler(irq, handle_edge_irq);
417 set_irq_flags(irq, IRQF_VALID | IRQF_PROBE);
420 for (irq = AUDXMTDMADONEA; irq <= IRQ_S1_BVD1_STSCHG; irq++) {
421 set_irq_chip(irq, &sa1111_high_chip);
422 set_irq_chip_data(irq, irqbase);
423 set_irq_handler(irq, handle_edge_irq);
424 set_irq_flags(irq, IRQF_VALID | IRQF_PROBE);
428 * Register SA1111 interrupt
430 set_irq_type(sachip->irq, IRQT_RISING);
431 set_irq_data(sachip->irq, irqbase);
432 set_irq_chained_handler(sachip->irq, sa1111_irq_handler);
436 * Bring the SA1111 out of reset. This requires a set procedure:
437 * 1. nRESET asserted (by hardware)
438 * 2. CLK turned on from SA1110
439 * 3. nRESET deasserted
440 * 4. VCO turned on, PLL_BYPASS turned off
441 * 5. Wait lock time, then assert RCLKEn
442 * 7. PCR set to allow clocking of individual functions
444 * Until we've done this, the only registers we can access are:
449 static void sa1111_wake(struct sa1111 *sachip)
451 unsigned long flags, r;
453 spin_lock_irqsave(&sachip->lock, flags);
455 clk_enable(sachip->clk);
458 * Turn VCO on, and disable PLL Bypass.
460 r = sa1111_readl(sachip->base + SA1111_SKCR);
462 sa1111_writel(r, sachip->base + SA1111_SKCR);
463 r |= SKCR_PLL_BYPASS | SKCR_OE_EN;
464 sa1111_writel(r, sachip->base + SA1111_SKCR);
467 * Wait lock time. SA1111 manual _doesn't_
468 * specify a figure for this! We choose 100us.
473 * Enable RCLK. We also ensure that RDYEN is set.
475 r |= SKCR_RCLKEN | SKCR_RDYEN;
476 sa1111_writel(r, sachip->base + SA1111_SKCR);
479 * Wait 14 RCLK cycles for the chip to finish coming out
480 * of reset. (RCLK=24MHz). This is 590ns.
485 * Ensure all clocks are initially off.
487 sa1111_writel(0, sachip->base + SA1111_SKPCR);
489 spin_unlock_irqrestore(&sachip->lock, flags);
492 #ifdef CONFIG_ARCH_SA1100
494 static u32 sa1111_dma_mask[] = {
506 * Configure the SA1111 shared memory controller.
509 sa1111_configure_smc(struct sa1111 *sachip, int sdram, unsigned int drac,
510 unsigned int cas_latency)
512 unsigned int smcr = SMCR_DTIM | SMCR_MBGE | FInsrt(drac, SMCR_DRAC);
514 if (cas_latency == 3)
517 sa1111_writel(smcr, sachip->base + SA1111_SMCR);
520 * Now clear the bits in the DMA mask to work around the SA1111
521 * DMA erratum (Intel StrongARM SA-1111 Microprocessor Companion
522 * Chip Specification Update, June 2000, Erratum #7).
524 if (sachip->dev->dma_mask)
525 *sachip->dev->dma_mask &= sa1111_dma_mask[drac >> 2];
527 sachip->dev->coherent_dma_mask &= sa1111_dma_mask[drac >> 2];
532 static void sa1111_dev_release(struct device *_dev)
534 struct sa1111_dev *dev = SA1111_DEV(_dev);
536 release_resource(&dev->res);
541 sa1111_init_one_child(struct sa1111 *sachip, struct resource *parent,
542 struct sa1111_dev_info *info)
544 struct sa1111_dev *dev;
547 dev = kzalloc(sizeof(struct sa1111_dev), GFP_KERNEL);
553 dev_set_name(&dev->dev, "%4.4lx", info->offset);
554 dev->devid = info->devid;
555 dev->dev.parent = sachip->dev;
556 dev->dev.bus = &sa1111_bus_type;
557 dev->dev.release = sa1111_dev_release;
558 dev->dev.coherent_dma_mask = sachip->dev->coherent_dma_mask;
559 dev->res.start = sachip->phys + info->offset;
560 dev->res.end = dev->res.start + 511;
561 dev->res.name = dev_name(&dev->dev);
562 dev->res.flags = IORESOURCE_MEM;
563 dev->mapbase = sachip->base + info->offset;
564 dev->skpcr_mask = info->skpcr_mask;
565 memmove(dev->irq, info->irq, sizeof(dev->irq));
567 ret = request_resource(parent, &dev->res);
569 printk("SA1111: failed to allocate resource for %s\n",
571 dev_set_name(&dev->dev, NULL);
577 ret = device_register(&dev->dev);
579 release_resource(&dev->res);
585 * If the parent device has a DMA mask associated with it,
586 * propagate it down to the children.
588 if (sachip->dev->dma_mask) {
589 dev->dma_mask = *sachip->dev->dma_mask;
590 dev->dev.dma_mask = &dev->dma_mask;
592 if (dev->dma_mask != 0xffffffffUL) {
593 ret = dmabounce_register_dev(&dev->dev, 1024, 4096);
595 dev_err(&dev->dev, "SA1111: Failed to register"
596 " with dmabounce\n");
597 device_unregister(&dev->dev);
607 * sa1111_probe - probe for a single SA1111 chip.
608 * @phys_addr: physical address of device.
610 * Probe for a SA1111 chip. This must be called
611 * before any other SA1111-specific code.
614 * %-ENODEV device not found.
615 * %-EBUSY physical address already marked in-use.
619 __sa1111_probe(struct device *me, struct resource *mem, int irq)
621 struct sa1111 *sachip;
623 unsigned int has_devs;
624 int i, ret = -ENODEV;
626 sachip = kzalloc(sizeof(struct sa1111), GFP_KERNEL);
630 sachip->clk = clk_get(me, "SA1111_CLK");
632 ret = PTR_ERR(sachip->clk);
636 spin_lock_init(&sachip->lock);
639 dev_set_drvdata(sachip->dev, sachip);
641 sachip->phys = mem->start;
645 * Map the whole region. This also maps the
646 * registers for our children.
648 sachip->base = ioremap(mem->start, PAGE_SIZE * 2);
655 * Probe for the chip. Only touch the SBI registers.
657 id = sa1111_readl(sachip->base + SA1111_SKID);
658 if ((id & SKID_ID_MASK) != SKID_SA1111_ID) {
659 printk(KERN_DEBUG "SA1111 not detected: ID = %08lx\n", id);
664 printk(KERN_INFO "SA1111 Microprocessor Companion Chip: "
665 "silicon revision %lx, metal revision %lx\n",
666 (id & SKID_SIREV_MASK)>>4, (id & SKID_MTREV_MASK));
669 * We found it. Wake the chip up, and initialise.
673 #ifdef CONFIG_ARCH_SA1100
678 * The SDRAM configuration of the SA1110 and the SA1111 must
679 * match. This is very important to ensure that SA1111 accesses
680 * don't corrupt the SDRAM. Note that this ungates the SA1111's
681 * MBGNT signal, so we must have called sa1110_mb_disable()
684 sa1111_configure_smc(sachip, 1,
685 FExtr(MDCNFG, MDCNFG_SA1110_DRAC0),
686 FExtr(MDCNFG, MDCNFG_SA1110_TDL0));
689 * We only need to turn on DCLK whenever we want to use the
690 * DMA. It can otherwise be held firmly in the off position.
691 * (currently, we always enable it.)
693 val = sa1111_readl(sachip->base + SA1111_SKPCR);
694 sa1111_writel(val | SKPCR_DCLKEN, sachip->base + SA1111_SKPCR);
697 * Enable the SA1110 memory bus request and grant signals.
704 * The interrupt controller must be initialised before any
705 * other device to ensure that the interrupts are available.
707 if (sachip->irq != NO_IRQ)
708 sa1111_setup_irq(sachip);
713 if (machine_is_assabet() || machine_is_jornada720() ||
715 has_devs &= ~(1 << 4);
717 has_devs &= ~(1 << 1);
719 for (i = 0; i < ARRAY_SIZE(sa1111_devices); i++)
720 if (has_devs & (1 << i))
721 sa1111_init_one_child(sachip, mem, &sa1111_devices[i]);
726 iounmap(sachip->base);
728 clk_put(sachip->clk);
734 static int sa1111_remove_one(struct device *dev, void *data)
736 device_unregister(dev);
740 static void __sa1111_remove(struct sa1111 *sachip)
742 void __iomem *irqbase = sachip->base + SA1111_INTC;
744 device_for_each_child(sachip->dev, NULL, sa1111_remove_one);
746 /* disable all IRQs */
747 sa1111_writel(0, irqbase + SA1111_INTEN0);
748 sa1111_writel(0, irqbase + SA1111_INTEN1);
749 sa1111_writel(0, irqbase + SA1111_WAKEEN0);
750 sa1111_writel(0, irqbase + SA1111_WAKEEN1);
752 clk_disable(sachip->clk);
754 if (sachip->irq != NO_IRQ) {
755 set_irq_chained_handler(sachip->irq, NULL);
756 set_irq_data(sachip->irq, NULL);
758 release_mem_region(sachip->phys + SA1111_INTC, 512);
761 iounmap(sachip->base);
762 clk_put(sachip->clk);
767 * According to the "Intel StrongARM SA-1111 Microprocessor Companion
768 * Chip Specification Update" (June 2000), erratum #7, there is a
769 * significant bug in the SA1111 SDRAM shared memory controller. If
770 * an access to a region of memory above 1MB relative to the bank base,
771 * it is important that address bit 10 _NOT_ be asserted. Depending
772 * on the configuration of the RAM, bit 10 may correspond to one
773 * of several different (processor-relative) address bits.
775 * This routine only identifies whether or not a given DMA address
776 * is susceptible to the bug.
778 * This should only get called for sa1111_device types due to the
779 * way we configure our device dma_masks.
781 int dma_needs_bounce(struct device *dev, dma_addr_t addr, size_t size)
784 * Section 4.6 of the "Intel StrongARM SA-1111 Development Module
785 * User's Guide" mentions that jumpers R51 and R52 control the
786 * target of SA-1111 DMA (either SDRAM bank 0 on Assabet, or
787 * SDRAM bank 1 on Neponset). The default configuration selects
788 * Assabet, so any address in bank 1 is necessarily invalid.
790 return ((machine_is_assabet() || machine_is_pfs168()) &&
791 (addr >= 0xc8000000 || (addr + size) >= 0xc8000000));
794 struct sa1111_save_data {
799 unsigned char skpwm0;
800 unsigned char skpwm1;
803 * Interrupt controller
805 unsigned int intpol0;
806 unsigned int intpol1;
809 unsigned int wakepol0;
810 unsigned int wakepol1;
811 unsigned int wakeen0;
812 unsigned int wakeen1;
817 static int sa1111_suspend(struct platform_device *dev, pm_message_t state)
819 struct sa1111 *sachip = platform_get_drvdata(dev);
820 struct sa1111_save_data *save;
825 save = kmalloc(sizeof(struct sa1111_save_data), GFP_KERNEL);
828 sachip->saved_state = save;
830 spin_lock_irqsave(&sachip->lock, flags);
836 save->skcr = sa1111_readl(base + SA1111_SKCR);
837 save->skpcr = sa1111_readl(base + SA1111_SKPCR);
838 save->skcdr = sa1111_readl(base + SA1111_SKCDR);
839 save->skaud = sa1111_readl(base + SA1111_SKAUD);
840 save->skpwm0 = sa1111_readl(base + SA1111_SKPWM0);
841 save->skpwm1 = sa1111_readl(base + SA1111_SKPWM1);
843 base = sachip->base + SA1111_INTC;
844 save->intpol0 = sa1111_readl(base + SA1111_INTPOL0);
845 save->intpol1 = sa1111_readl(base + SA1111_INTPOL1);
846 save->inten0 = sa1111_readl(base + SA1111_INTEN0);
847 save->inten1 = sa1111_readl(base + SA1111_INTEN1);
848 save->wakepol0 = sa1111_readl(base + SA1111_WAKEPOL0);
849 save->wakepol1 = sa1111_readl(base + SA1111_WAKEPOL1);
850 save->wakeen0 = sa1111_readl(base + SA1111_WAKEEN0);
851 save->wakeen1 = sa1111_readl(base + SA1111_WAKEEN1);
856 val = sa1111_readl(sachip->base + SA1111_SKCR);
857 sa1111_writel(val | SKCR_SLEEP, sachip->base + SA1111_SKCR);
858 sa1111_writel(0, sachip->base + SA1111_SKPWM0);
859 sa1111_writel(0, sachip->base + SA1111_SKPWM1);
861 clk_disable(sachip->clk);
863 spin_unlock_irqrestore(&sachip->lock, flags);
869 * sa1111_resume - Restore the SA1111 device state.
870 * @dev: device to restore
872 * Restore the general state of the SA1111; clock control and
873 * interrupt controller. Other parts of the SA1111 must be
874 * restored by their respective drivers, and must be called
875 * via LDM after this function.
877 static int sa1111_resume(struct platform_device *dev)
879 struct sa1111 *sachip = platform_get_drvdata(dev);
880 struct sa1111_save_data *save;
881 unsigned long flags, id;
884 save = sachip->saved_state;
888 spin_lock_irqsave(&sachip->lock, flags);
891 * Ensure that the SA1111 is still here.
892 * FIXME: shouldn't do this here.
894 id = sa1111_readl(sachip->base + SA1111_SKID);
895 if ((id & SKID_ID_MASK) != SKID_SA1111_ID) {
896 __sa1111_remove(sachip);
897 platform_set_drvdata(dev, NULL);
903 * First of all, wake up the chip.
906 sa1111_writel(0, sachip->base + SA1111_INTC + SA1111_INTEN0);
907 sa1111_writel(0, sachip->base + SA1111_INTC + SA1111_INTEN1);
910 sa1111_writel(save->skcr, base + SA1111_SKCR);
911 sa1111_writel(save->skpcr, base + SA1111_SKPCR);
912 sa1111_writel(save->skcdr, base + SA1111_SKCDR);
913 sa1111_writel(save->skaud, base + SA1111_SKAUD);
914 sa1111_writel(save->skpwm0, base + SA1111_SKPWM0);
915 sa1111_writel(save->skpwm1, base + SA1111_SKPWM1);
917 base = sachip->base + SA1111_INTC;
918 sa1111_writel(save->intpol0, base + SA1111_INTPOL0);
919 sa1111_writel(save->intpol1, base + SA1111_INTPOL1);
920 sa1111_writel(save->inten0, base + SA1111_INTEN0);
921 sa1111_writel(save->inten1, base + SA1111_INTEN1);
922 sa1111_writel(save->wakepol0, base + SA1111_WAKEPOL0);
923 sa1111_writel(save->wakepol1, base + SA1111_WAKEPOL1);
924 sa1111_writel(save->wakeen0, base + SA1111_WAKEEN0);
925 sa1111_writel(save->wakeen1, base + SA1111_WAKEEN1);
927 spin_unlock_irqrestore(&sachip->lock, flags);
929 sachip->saved_state = NULL;
936 #define sa1111_suspend NULL
937 #define sa1111_resume NULL
940 static int sa1111_probe(struct platform_device *pdev)
942 struct resource *mem;
945 mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
948 irq = platform_get_irq(pdev, 0);
952 return __sa1111_probe(&pdev->dev, mem, irq);
955 static int sa1111_remove(struct platform_device *pdev)
957 struct sa1111 *sachip = platform_get_drvdata(pdev);
960 __sa1111_remove(sachip);
961 platform_set_drvdata(pdev, NULL);
964 kfree(sachip->saved_state);
965 sachip->saved_state = NULL;
973 * Not sure if this should be on the system bus or not yet.
974 * We really want some way to register a system device at
975 * the per-machine level, and then have this driver pick
976 * up the registered devices.
978 * We also need to handle the SDRAM configuration for
979 * PXA250/SA1110 machine classes.
981 static struct platform_driver sa1111_device_driver = {
982 .probe = sa1111_probe,
983 .remove = sa1111_remove,
984 .suspend = sa1111_suspend,
985 .resume = sa1111_resume,
992 * Get the parent device driver (us) structure
993 * from a child function device
995 static inline struct sa1111 *sa1111_chip_driver(struct sa1111_dev *sadev)
997 return (struct sa1111 *)dev_get_drvdata(sadev->dev.parent);
1001 * The bits in the opdiv field are non-linear.
1003 static unsigned char opdiv_table[] = { 1, 4, 2, 8 };
1005 static unsigned int __sa1111_pll_clock(struct sa1111 *sachip)
1007 unsigned int skcdr, fbdiv, ipdiv, opdiv;
1009 skcdr = sa1111_readl(sachip->base + SA1111_SKCDR);
1011 fbdiv = (skcdr & 0x007f) + 2;
1012 ipdiv = ((skcdr & 0x0f80) >> 7) + 2;
1013 opdiv = opdiv_table[(skcdr & 0x3000) >> 12];
1015 return 3686400 * fbdiv / (ipdiv * opdiv);
1019 * sa1111_pll_clock - return the current PLL clock frequency.
1020 * @sadev: SA1111 function block
1022 * BUG: we should look at SKCR. We also blindly believe that
1023 * the chip is being fed with the 3.6864MHz clock.
1025 * Returns the PLL clock in Hz.
1027 unsigned int sa1111_pll_clock(struct sa1111_dev *sadev)
1029 struct sa1111 *sachip = sa1111_chip_driver(sadev);
1031 return __sa1111_pll_clock(sachip);
1035 * sa1111_select_audio_mode - select I2S or AC link mode
1036 * @sadev: SA1111 function block
1037 * @mode: One of %SA1111_AUDIO_ACLINK or %SA1111_AUDIO_I2S
1039 * Frob the SKCR to select AC Link mode or I2S mode for
1042 void sa1111_select_audio_mode(struct sa1111_dev *sadev, int mode)
1044 struct sa1111 *sachip = sa1111_chip_driver(sadev);
1045 unsigned long flags;
1048 spin_lock_irqsave(&sachip->lock, flags);
1050 val = sa1111_readl(sachip->base + SA1111_SKCR);
1051 if (mode == SA1111_AUDIO_I2S) {
1056 sa1111_writel(val, sachip->base + SA1111_SKCR);
1058 spin_unlock_irqrestore(&sachip->lock, flags);
1062 * sa1111_set_audio_rate - set the audio sample rate
1063 * @sadev: SA1111 SAC function block
1064 * @rate: sample rate to select
1066 int sa1111_set_audio_rate(struct sa1111_dev *sadev, int rate)
1068 struct sa1111 *sachip = sa1111_chip_driver(sadev);
1071 if (sadev->devid != SA1111_DEVID_SAC)
1074 div = (__sa1111_pll_clock(sachip) / 256 + rate / 2) / rate;
1080 sa1111_writel(div - 1, sachip->base + SA1111_SKAUD);
1086 * sa1111_get_audio_rate - get the audio sample rate
1087 * @sadev: SA1111 SAC function block device
1089 int sa1111_get_audio_rate(struct sa1111_dev *sadev)
1091 struct sa1111 *sachip = sa1111_chip_driver(sadev);
1094 if (sadev->devid != SA1111_DEVID_SAC)
1097 div = sa1111_readl(sachip->base + SA1111_SKAUD) + 1;
1099 return __sa1111_pll_clock(sachip) / (256 * div);
1102 void sa1111_set_io_dir(struct sa1111_dev *sadev,
1103 unsigned int bits, unsigned int dir,
1104 unsigned int sleep_dir)
1106 struct sa1111 *sachip = sa1111_chip_driver(sadev);
1107 unsigned long flags;
1109 void __iomem *gpio = sachip->base + SA1111_GPIO;
1111 #define MODIFY_BITS(port, mask, dir) \
1113 val = sa1111_readl(port); \
1115 val |= (dir) & (mask); \
1116 sa1111_writel(val, port); \
1119 spin_lock_irqsave(&sachip->lock, flags);
1120 MODIFY_BITS(gpio + SA1111_GPIO_PADDR, bits & 15, dir);
1121 MODIFY_BITS(gpio + SA1111_GPIO_PBDDR, (bits >> 8) & 255, dir >> 8);
1122 MODIFY_BITS(gpio + SA1111_GPIO_PCDDR, (bits >> 16) & 255, dir >> 16);
1124 MODIFY_BITS(gpio + SA1111_GPIO_PASDR, bits & 15, sleep_dir);
1125 MODIFY_BITS(gpio + SA1111_GPIO_PBSDR, (bits >> 8) & 255, sleep_dir >> 8);
1126 MODIFY_BITS(gpio + SA1111_GPIO_PCSDR, (bits >> 16) & 255, sleep_dir >> 16);
1127 spin_unlock_irqrestore(&sachip->lock, flags);
1130 void sa1111_set_io(struct sa1111_dev *sadev, unsigned int bits, unsigned int v)
1132 struct sa1111 *sachip = sa1111_chip_driver(sadev);
1133 unsigned long flags;
1135 void __iomem *gpio = sachip->base + SA1111_GPIO;
1137 spin_lock_irqsave(&sachip->lock, flags);
1138 MODIFY_BITS(gpio + SA1111_GPIO_PADWR, bits & 15, v);
1139 MODIFY_BITS(gpio + SA1111_GPIO_PBDWR, (bits >> 8) & 255, v >> 8);
1140 MODIFY_BITS(gpio + SA1111_GPIO_PCDWR, (bits >> 16) & 255, v >> 16);
1141 spin_unlock_irqrestore(&sachip->lock, flags);
1144 void sa1111_set_sleep_io(struct sa1111_dev *sadev, unsigned int bits, unsigned int v)
1146 struct sa1111 *sachip = sa1111_chip_driver(sadev);
1147 unsigned long flags;
1149 void __iomem *gpio = sachip->base + SA1111_GPIO;
1151 spin_lock_irqsave(&sachip->lock, flags);
1152 MODIFY_BITS(gpio + SA1111_GPIO_PASSR, bits & 15, v);
1153 MODIFY_BITS(gpio + SA1111_GPIO_PBSSR, (bits >> 8) & 255, v >> 8);
1154 MODIFY_BITS(gpio + SA1111_GPIO_PCSSR, (bits >> 16) & 255, v >> 16);
1155 spin_unlock_irqrestore(&sachip->lock, flags);
1159 * Individual device operations.
1163 * sa1111_enable_device - enable an on-chip SA1111 function block
1164 * @sadev: SA1111 function block device to enable
1166 void sa1111_enable_device(struct sa1111_dev *sadev)
1168 struct sa1111 *sachip = sa1111_chip_driver(sadev);
1169 unsigned long flags;
1172 spin_lock_irqsave(&sachip->lock, flags);
1173 val = sa1111_readl(sachip->base + SA1111_SKPCR);
1174 sa1111_writel(val | sadev->skpcr_mask, sachip->base + SA1111_SKPCR);
1175 spin_unlock_irqrestore(&sachip->lock, flags);
1179 * sa1111_disable_device - disable an on-chip SA1111 function block
1180 * @sadev: SA1111 function block device to disable
1182 void sa1111_disable_device(struct sa1111_dev *sadev)
1184 struct sa1111 *sachip = sa1111_chip_driver(sadev);
1185 unsigned long flags;
1188 spin_lock_irqsave(&sachip->lock, flags);
1189 val = sa1111_readl(sachip->base + SA1111_SKPCR);
1190 sa1111_writel(val & ~sadev->skpcr_mask, sachip->base + SA1111_SKPCR);
1191 spin_unlock_irqrestore(&sachip->lock, flags);
1195 * SA1111 "Register Access Bus."
1197 * We model this as a regular bus type, and hang devices directly
1200 static int sa1111_match(struct device *_dev, struct device_driver *_drv)
1202 struct sa1111_dev *dev = SA1111_DEV(_dev);
1203 struct sa1111_driver *drv = SA1111_DRV(_drv);
1205 return dev->devid == drv->devid;
1208 static int sa1111_bus_suspend(struct device *dev, pm_message_t state)
1210 struct sa1111_dev *sadev = SA1111_DEV(dev);
1211 struct sa1111_driver *drv = SA1111_DRV(dev->driver);
1214 if (drv && drv->suspend)
1215 ret = drv->suspend(sadev, state);
1219 static int sa1111_bus_resume(struct device *dev)
1221 struct sa1111_dev *sadev = SA1111_DEV(dev);
1222 struct sa1111_driver *drv = SA1111_DRV(dev->driver);
1225 if (drv && drv->resume)
1226 ret = drv->resume(sadev);
1230 static int sa1111_bus_probe(struct device *dev)
1232 struct sa1111_dev *sadev = SA1111_DEV(dev);
1233 struct sa1111_driver *drv = SA1111_DRV(dev->driver);
1237 ret = drv->probe(sadev);
1241 static int sa1111_bus_remove(struct device *dev)
1243 struct sa1111_dev *sadev = SA1111_DEV(dev);
1244 struct sa1111_driver *drv = SA1111_DRV(dev->driver);
1248 ret = drv->remove(sadev);
1252 struct bus_type sa1111_bus_type = {
1253 .name = "sa1111-rab",
1254 .match = sa1111_match,
1255 .probe = sa1111_bus_probe,
1256 .remove = sa1111_bus_remove,
1257 .suspend = sa1111_bus_suspend,
1258 .resume = sa1111_bus_resume,
1261 int sa1111_driver_register(struct sa1111_driver *driver)
1263 driver->drv.bus = &sa1111_bus_type;
1264 return driver_register(&driver->drv);
1267 void sa1111_driver_unregister(struct sa1111_driver *driver)
1269 driver_unregister(&driver->drv);
1272 static int __init sa1111_init(void)
1274 int ret = bus_register(&sa1111_bus_type);
1276 platform_driver_register(&sa1111_device_driver);
1280 static void __exit sa1111_exit(void)
1282 platform_driver_unregister(&sa1111_device_driver);
1283 bus_unregister(&sa1111_bus_type);
1286 subsys_initcall(sa1111_init);
1287 module_exit(sa1111_exit);
1289 MODULE_DESCRIPTION("Intel Corporation SA1111 core driver");
1290 MODULE_LICENSE("GPL");
1292 EXPORT_SYMBOL(sa1111_select_audio_mode);
1293 EXPORT_SYMBOL(sa1111_set_audio_rate);
1294 EXPORT_SYMBOL(sa1111_get_audio_rate);
1295 EXPORT_SYMBOL(sa1111_set_io_dir);
1296 EXPORT_SYMBOL(sa1111_set_io);
1297 EXPORT_SYMBOL(sa1111_set_sleep_io);
1298 EXPORT_SYMBOL(sa1111_enable_device);
1299 EXPORT_SYMBOL(sa1111_disable_device);
1300 EXPORT_SYMBOL(sa1111_pll_clock);
1301 EXPORT_SYMBOL(sa1111_bus_type);
1302 EXPORT_SYMBOL(sa1111_driver_register);
1303 EXPORT_SYMBOL(sa1111_driver_unregister);