blob: 5ba1ee042349eab9a5b606737c988b4abc2f54dc [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * linux/arch/arm/mach-sa1100/sa1111.c
3 *
4 * SA1111 support
5 *
6 * Original code by John Dorsey
7 *
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.
11 *
12 * This file contains all generic SA1111 support.
13 *
14 * All initialization functions provided here are intended to be called
15 * from machine specific code with proper arguments when required.
16 */
17#include <linux/config.h>
18#include <linux/module.h>
19#include <linux/init.h>
20#include <linux/kernel.h>
21#include <linux/delay.h>
22#include <linux/ptrace.h>
23#include <linux/errno.h>
24#include <linux/ioport.h>
Russell Kingd052d1b2005-10-29 19:07:23 +010025#include <linux/platform_device.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070026#include <linux/slab.h>
27#include <linux/spinlock.h>
28#include <linux/dma-mapping.h>
Russell King97d654f2006-03-15 15:54:37 +000029#include <linux/clk.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070030
31#include <asm/hardware.h>
32#include <asm/mach-types.h>
33#include <asm/io.h>
34#include <asm/irq.h>
35#include <asm/mach/irq.h>
Russell King45e109d2005-11-16 18:29:51 +000036#include <asm/sizes.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070037
38#include <asm/hardware/sa1111.h>
39
Linus Torvalds1da177e2005-04-16 15:20:36 -070040extern void __init sa1110_mb_enable(void);
41
42/*
43 * We keep the following data for the overall SA1111. Note that the
44 * struct device and struct resource are "fake"; they should be supplied
45 * by the bus above us. However, in the interests of getting all SA1111
46 * drivers converted over to the device model, we provide this as an
47 * anchor point for all the other drivers.
48 */
49struct sa1111 {
50 struct device *dev;
Russell King97d654f2006-03-15 15:54:37 +000051 struct clk *clk;
Linus Torvalds1da177e2005-04-16 15:20:36 -070052 unsigned long phys;
53 int irq;
54 spinlock_t lock;
55 void __iomem *base;
56};
57
58/*
59 * We _really_ need to eliminate this. Its only users
60 * are the PWM and DMA checking code.
61 */
62static struct sa1111 *g_sa1111;
63
64struct sa1111_dev_info {
65 unsigned long offset;
66 unsigned long skpcr_mask;
67 unsigned int devid;
68 unsigned int irq[6];
69};
70
71static struct sa1111_dev_info sa1111_devices[] = {
72 {
73 .offset = SA1111_USB,
74 .skpcr_mask = SKPCR_UCLKEN,
75 .devid = SA1111_DEVID_USB,
76 .irq = {
77 IRQ_USBPWR,
78 IRQ_HCIM,
79 IRQ_HCIBUFFACC,
80 IRQ_HCIRMTWKP,
81 IRQ_NHCIMFCIR,
82 IRQ_USB_PORT_RESUME
83 },
84 },
85 {
86 .offset = 0x0600,
87 .skpcr_mask = SKPCR_I2SCLKEN | SKPCR_L3CLKEN,
88 .devid = SA1111_DEVID_SAC,
89 .irq = {
90 AUDXMTDMADONEA,
91 AUDXMTDMADONEB,
92 AUDRCVDMADONEA,
93 AUDRCVDMADONEB
94 },
95 },
96 {
97 .offset = 0x0800,
98 .skpcr_mask = SKPCR_SCLKEN,
99 .devid = SA1111_DEVID_SSP,
100 },
101 {
102 .offset = SA1111_KBD,
103 .skpcr_mask = SKPCR_PTCLKEN,
104 .devid = SA1111_DEVID_PS2,
105 .irq = {
106 IRQ_TPRXINT,
107 IRQ_TPTXINT
108 },
109 },
110 {
111 .offset = SA1111_MSE,
112 .skpcr_mask = SKPCR_PMCLKEN,
113 .devid = SA1111_DEVID_PS2,
114 .irq = {
115 IRQ_MSRXINT,
116 IRQ_MSTXINT
117 },
118 },
119 {
120 .offset = 0x1800,
121 .skpcr_mask = 0,
122 .devid = SA1111_DEVID_PCMCIA,
123 .irq = {
124 IRQ_S0_READY_NINT,
125 IRQ_S0_CD_VALID,
126 IRQ_S0_BVD1_STSCHG,
127 IRQ_S1_READY_NINT,
128 IRQ_S1_CD_VALID,
129 IRQ_S1_BVD1_STSCHG,
130 },
131 },
132};
133
Russell King1b120502005-11-16 17:38:40 +0000134void __init sa1111_adjust_zones(int node, unsigned long *size, unsigned long *holes)
135{
136 unsigned int sz = SZ_1M >> PAGE_SHIFT;
137
138 if (node != 0)
139 sz = 0;
140
141 size[1] = size[0] - sz;
142 size[0] = sz;
143}
144
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145/*
146 * SA1111 interrupt support. Since clearing an IRQ while there are
147 * active IRQs causes the interrupt output to pulse, the upper levels
148 * will call us again if there are more interrupts to process.
149 */
150static void
151sa1111_irq_handler(unsigned int irq, struct irqdesc *desc, struct pt_regs *regs)
152{
153 unsigned int stat0, stat1, i;
154 void __iomem *base = desc->data;
155
156 stat0 = sa1111_readl(base + SA1111_INTSTATCLR0);
157 stat1 = sa1111_readl(base + SA1111_INTSTATCLR1);
158
159 sa1111_writel(stat0, base + SA1111_INTSTATCLR0);
160
161 desc->chip->ack(irq);
162
163 sa1111_writel(stat1, base + SA1111_INTSTATCLR1);
164
165 if (stat0 == 0 && stat1 == 0) {
166 do_bad_IRQ(irq, desc, regs);
167 return;
168 }
169
170 for (i = IRQ_SA1111_START; stat0; i++, stat0 >>= 1)
171 if (stat0 & 1)
172 do_edge_IRQ(i, irq_desc + i, regs);
173
174 for (i = IRQ_SA1111_START + 32; stat1; i++, stat1 >>= 1)
175 if (stat1 & 1)
176 do_edge_IRQ(i, irq_desc + i, regs);
177
178 /* For level-based interrupts */
179 desc->chip->unmask(irq);
180}
181
182#define SA1111_IRQMASK_LO(x) (1 << (x - IRQ_SA1111_START))
183#define SA1111_IRQMASK_HI(x) (1 << (x - IRQ_SA1111_START - 32))
184
185static void sa1111_ack_irq(unsigned int irq)
186{
187}
188
189static void sa1111_mask_lowirq(unsigned int irq)
190{
191 void __iomem *mapbase = get_irq_chipdata(irq);
192 unsigned long ie0;
193
194 ie0 = sa1111_readl(mapbase + SA1111_INTEN0);
195 ie0 &= ~SA1111_IRQMASK_LO(irq);
196 writel(ie0, mapbase + SA1111_INTEN0);
197}
198
199static void sa1111_unmask_lowirq(unsigned int irq)
200{
201 void __iomem *mapbase = get_irq_chipdata(irq);
202 unsigned long ie0;
203
204 ie0 = sa1111_readl(mapbase + SA1111_INTEN0);
205 ie0 |= SA1111_IRQMASK_LO(irq);
206 sa1111_writel(ie0, mapbase + SA1111_INTEN0);
207}
208
209/*
210 * Attempt to re-trigger the interrupt. The SA1111 contains a register
211 * (INTSET) which claims to do this. However, in practice no amount of
212 * manipulation of INTEN and INTSET guarantees that the interrupt will
213 * be triggered. In fact, its very difficult, if not impossible to get
214 * INTSET to re-trigger the interrupt.
215 */
216static int sa1111_retrigger_lowirq(unsigned int irq)
217{
218 unsigned int mask = SA1111_IRQMASK_LO(irq);
219 void __iomem *mapbase = get_irq_chipdata(irq);
220 unsigned long ip0;
221 int i;
222
223 ip0 = sa1111_readl(mapbase + SA1111_INTPOL0);
224 for (i = 0; i < 8; i++) {
225 sa1111_writel(ip0 ^ mask, mapbase + SA1111_INTPOL0);
226 sa1111_writel(ip0, mapbase + SA1111_INTPOL0);
227 if (sa1111_readl(mapbase + SA1111_INTSTATCLR1) & mask)
228 break;
229 }
230
231 if (i == 8)
232 printk(KERN_ERR "Danger Will Robinson: failed to "
233 "re-trigger IRQ%d\n", irq);
234 return i == 8 ? -1 : 0;
235}
236
237static int sa1111_type_lowirq(unsigned int irq, unsigned int flags)
238{
239 unsigned int mask = SA1111_IRQMASK_LO(irq);
240 void __iomem *mapbase = get_irq_chipdata(irq);
241 unsigned long ip0;
242
243 if (flags == IRQT_PROBE)
244 return 0;
245
246 if ((!(flags & __IRQT_RISEDGE) ^ !(flags & __IRQT_FALEDGE)) == 0)
247 return -EINVAL;
248
249 ip0 = sa1111_readl(mapbase + SA1111_INTPOL0);
250 if (flags & __IRQT_RISEDGE)
251 ip0 &= ~mask;
252 else
253 ip0 |= mask;
254 sa1111_writel(ip0, mapbase + SA1111_INTPOL0);
255 sa1111_writel(ip0, mapbase + SA1111_WAKEPOL0);
256
257 return 0;
258}
259
260static int sa1111_wake_lowirq(unsigned int irq, unsigned int on)
261{
262 unsigned int mask = SA1111_IRQMASK_LO(irq);
263 void __iomem *mapbase = get_irq_chipdata(irq);
264 unsigned long we0;
265
266 we0 = sa1111_readl(mapbase + SA1111_WAKEEN0);
267 if (on)
268 we0 |= mask;
269 else
270 we0 &= ~mask;
271 sa1111_writel(we0, mapbase + SA1111_WAKEEN0);
272
273 return 0;
274}
275
276static struct irqchip sa1111_low_chip = {
277 .ack = sa1111_ack_irq,
278 .mask = sa1111_mask_lowirq,
279 .unmask = sa1111_unmask_lowirq,
280 .retrigger = sa1111_retrigger_lowirq,
Russell King78019072005-09-04 19:43:13 +0100281 .set_type = sa1111_type_lowirq,
282 .set_wake = sa1111_wake_lowirq,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700283};
284
285static void sa1111_mask_highirq(unsigned int irq)
286{
287 void __iomem *mapbase = get_irq_chipdata(irq);
288 unsigned long ie1;
289
290 ie1 = sa1111_readl(mapbase + SA1111_INTEN1);
291 ie1 &= ~SA1111_IRQMASK_HI(irq);
292 sa1111_writel(ie1, mapbase + SA1111_INTEN1);
293}
294
295static void sa1111_unmask_highirq(unsigned int irq)
296{
297 void __iomem *mapbase = get_irq_chipdata(irq);
298 unsigned long ie1;
299
300 ie1 = sa1111_readl(mapbase + SA1111_INTEN1);
301 ie1 |= SA1111_IRQMASK_HI(irq);
302 sa1111_writel(ie1, mapbase + SA1111_INTEN1);
303}
304
305/*
306 * Attempt to re-trigger the interrupt. The SA1111 contains a register
307 * (INTSET) which claims to do this. However, in practice no amount of
308 * manipulation of INTEN and INTSET guarantees that the interrupt will
309 * be triggered. In fact, its very difficult, if not impossible to get
310 * INTSET to re-trigger the interrupt.
311 */
312static int sa1111_retrigger_highirq(unsigned int irq)
313{
314 unsigned int mask = SA1111_IRQMASK_HI(irq);
315 void __iomem *mapbase = get_irq_chipdata(irq);
316 unsigned long ip1;
317 int i;
318
319 ip1 = sa1111_readl(mapbase + SA1111_INTPOL1);
320 for (i = 0; i < 8; i++) {
321 sa1111_writel(ip1 ^ mask, mapbase + SA1111_INTPOL1);
322 sa1111_writel(ip1, mapbase + SA1111_INTPOL1);
323 if (sa1111_readl(mapbase + SA1111_INTSTATCLR1) & mask)
324 break;
325 }
326
327 if (i == 8)
328 printk(KERN_ERR "Danger Will Robinson: failed to "
329 "re-trigger IRQ%d\n", irq);
330 return i == 8 ? -1 : 0;
331}
332
333static int sa1111_type_highirq(unsigned int irq, unsigned int flags)
334{
335 unsigned int mask = SA1111_IRQMASK_HI(irq);
336 void __iomem *mapbase = get_irq_chipdata(irq);
337 unsigned long ip1;
338
339 if (flags == IRQT_PROBE)
340 return 0;
341
342 if ((!(flags & __IRQT_RISEDGE) ^ !(flags & __IRQT_FALEDGE)) == 0)
343 return -EINVAL;
344
345 ip1 = sa1111_readl(mapbase + SA1111_INTPOL1);
346 if (flags & __IRQT_RISEDGE)
347 ip1 &= ~mask;
348 else
349 ip1 |= mask;
350 sa1111_writel(ip1, mapbase + SA1111_INTPOL1);
351 sa1111_writel(ip1, mapbase + SA1111_WAKEPOL1);
352
353 return 0;
354}
355
356static int sa1111_wake_highirq(unsigned int irq, unsigned int on)
357{
358 unsigned int mask = SA1111_IRQMASK_HI(irq);
359 void __iomem *mapbase = get_irq_chipdata(irq);
360 unsigned long we1;
361
362 we1 = sa1111_readl(mapbase + SA1111_WAKEEN1);
363 if (on)
364 we1 |= mask;
365 else
366 we1 &= ~mask;
367 sa1111_writel(we1, mapbase + SA1111_WAKEEN1);
368
369 return 0;
370}
371
372static struct irqchip sa1111_high_chip = {
373 .ack = sa1111_ack_irq,
374 .mask = sa1111_mask_highirq,
375 .unmask = sa1111_unmask_highirq,
376 .retrigger = sa1111_retrigger_highirq,
Russell King78019072005-09-04 19:43:13 +0100377 .set_type = sa1111_type_highirq,
378 .set_wake = sa1111_wake_highirq,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700379};
380
381static void sa1111_setup_irq(struct sa1111 *sachip)
382{
383 void __iomem *irqbase = sachip->base + SA1111_INTC;
384 unsigned int irq;
385
386 /*
387 * We're guaranteed that this region hasn't been taken.
388 */
389 request_mem_region(sachip->phys + SA1111_INTC, 512, "irq");
390
391 /* disable all IRQs */
392 sa1111_writel(0, irqbase + SA1111_INTEN0);
393 sa1111_writel(0, irqbase + SA1111_INTEN1);
394 sa1111_writel(0, irqbase + SA1111_WAKEEN0);
395 sa1111_writel(0, irqbase + SA1111_WAKEEN1);
396
397 /*
398 * detect on rising edge. Note: Feb 2001 Errata for SA1111
399 * specifies that S0ReadyInt and S1ReadyInt should be '1'.
400 */
401 sa1111_writel(0, irqbase + SA1111_INTPOL0);
402 sa1111_writel(SA1111_IRQMASK_HI(IRQ_S0_READY_NINT) |
403 SA1111_IRQMASK_HI(IRQ_S1_READY_NINT),
404 irqbase + SA1111_INTPOL1);
405
406 /* clear all IRQs */
407 sa1111_writel(~0, irqbase + SA1111_INTSTATCLR0);
408 sa1111_writel(~0, irqbase + SA1111_INTSTATCLR1);
409
410 for (irq = IRQ_GPAIN0; irq <= SSPROR; irq++) {
411 set_irq_chip(irq, &sa1111_low_chip);
412 set_irq_chipdata(irq, irqbase);
413 set_irq_handler(irq, do_edge_IRQ);
414 set_irq_flags(irq, IRQF_VALID | IRQF_PROBE);
415 }
416
417 for (irq = AUDXMTDMADONEA; irq <= IRQ_S1_BVD1_STSCHG; irq++) {
418 set_irq_chip(irq, &sa1111_high_chip);
419 set_irq_chipdata(irq, irqbase);
420 set_irq_handler(irq, do_edge_IRQ);
421 set_irq_flags(irq, IRQF_VALID | IRQF_PROBE);
422 }
423
424 /*
425 * Register SA1111 interrupt
426 */
427 set_irq_type(sachip->irq, IRQT_RISING);
428 set_irq_data(sachip->irq, irqbase);
429 set_irq_chained_handler(sachip->irq, sa1111_irq_handler);
430}
431
432/*
433 * Bring the SA1111 out of reset. This requires a set procedure:
434 * 1. nRESET asserted (by hardware)
435 * 2. CLK turned on from SA1110
436 * 3. nRESET deasserted
437 * 4. VCO turned on, PLL_BYPASS turned off
438 * 5. Wait lock time, then assert RCLKEn
439 * 7. PCR set to allow clocking of individual functions
440 *
441 * Until we've done this, the only registers we can access are:
442 * SBI_SKCR
443 * SBI_SMCR
444 * SBI_SKID
445 */
446static void sa1111_wake(struct sa1111 *sachip)
447{
448 unsigned long flags, r;
449
450 spin_lock_irqsave(&sachip->lock, flags);
451
Russell King97d654f2006-03-15 15:54:37 +0000452 clk_enable(sachip->clk);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700453
454 /*
455 * Turn VCO on, and disable PLL Bypass.
456 */
457 r = sa1111_readl(sachip->base + SA1111_SKCR);
458 r &= ~SKCR_VCO_OFF;
459 sa1111_writel(r, sachip->base + SA1111_SKCR);
460 r |= SKCR_PLL_BYPASS | SKCR_OE_EN;
461 sa1111_writel(r, sachip->base + SA1111_SKCR);
462
463 /*
464 * Wait lock time. SA1111 manual _doesn't_
465 * specify a figure for this! We choose 100us.
466 */
467 udelay(100);
468
469 /*
470 * Enable RCLK. We also ensure that RDYEN is set.
471 */
472 r |= SKCR_RCLKEN | SKCR_RDYEN;
473 sa1111_writel(r, sachip->base + SA1111_SKCR);
474
475 /*
476 * Wait 14 RCLK cycles for the chip to finish coming out
477 * of reset. (RCLK=24MHz). This is 590ns.
478 */
479 udelay(1);
480
481 /*
482 * Ensure all clocks are initially off.
483 */
484 sa1111_writel(0, sachip->base + SA1111_SKPCR);
485
486 spin_unlock_irqrestore(&sachip->lock, flags);
487}
488
489#ifdef CONFIG_ARCH_SA1100
490
491static u32 sa1111_dma_mask[] = {
492 ~0,
493 ~(1 << 20),
494 ~(1 << 23),
495 ~(1 << 24),
496 ~(1 << 25),
497 ~(1 << 20),
498 ~(1 << 20),
499 0,
500};
501
502/*
503 * Configure the SA1111 shared memory controller.
504 */
505void
506sa1111_configure_smc(struct sa1111 *sachip, int sdram, unsigned int drac,
507 unsigned int cas_latency)
508{
509 unsigned int smcr = SMCR_DTIM | SMCR_MBGE | FInsrt(drac, SMCR_DRAC);
510
511 if (cas_latency == 3)
512 smcr |= SMCR_CLAT;
513
514 sa1111_writel(smcr, sachip->base + SA1111_SMCR);
515
516 /*
517 * Now clear the bits in the DMA mask to work around the SA1111
518 * DMA erratum (Intel StrongARM SA-1111 Microprocessor Companion
519 * Chip Specification Update, June 2000, Erratum #7).
520 */
521 if (sachip->dev->dma_mask)
522 *sachip->dev->dma_mask &= sa1111_dma_mask[drac >> 2];
523
524 sachip->dev->coherent_dma_mask &= sa1111_dma_mask[drac >> 2];
525}
526
527#endif
528
529static void sa1111_dev_release(struct device *_dev)
530{
531 struct sa1111_dev *dev = SA1111_DEV(_dev);
532
533 release_resource(&dev->res);
534 kfree(dev);
535}
536
537static int
538sa1111_init_one_child(struct sa1111 *sachip, struct resource *parent,
539 struct sa1111_dev_info *info)
540{
541 struct sa1111_dev *dev;
542 int ret;
543
544 dev = kmalloc(sizeof(struct sa1111_dev), GFP_KERNEL);
545 if (!dev) {
546 ret = -ENOMEM;
547 goto out;
548 }
549 memset(dev, 0, sizeof(struct sa1111_dev));
550
551 snprintf(dev->dev.bus_id, sizeof(dev->dev.bus_id),
552 "%4.4lx", info->offset);
553
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->dev.bus_id;
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));
566
567 ret = request_resource(parent, &dev->res);
568 if (ret) {
569 printk("SA1111: failed to allocate resource for %s\n",
570 dev->res.name);
571 kfree(dev);
572 goto out;
573 }
574
575
576 ret = device_register(&dev->dev);
577 if (ret) {
578 release_resource(&dev->res);
579 kfree(dev);
580 goto out;
581 }
582
583 /*
584 * If the parent device has a DMA mask associated with it,
585 * propagate it down to the children.
586 */
587 if (sachip->dev->dma_mask) {
588 dev->dma_mask = *sachip->dev->dma_mask;
589 dev->dev.dma_mask = &dev->dma_mask;
590
591 if (dev->dma_mask != 0xffffffffUL) {
592 ret = dmabounce_register_dev(&dev->dev, 1024, 4096);
593 if (ret) {
594 printk("SA1111: Failed to register %s with dmabounce", dev->dev.bus_id);
595 device_unregister(&dev->dev);
596 }
597 }
598 }
599
600out:
601 return ret;
602}
603
604/**
605 * sa1111_probe - probe for a single SA1111 chip.
606 * @phys_addr: physical address of device.
607 *
608 * Probe for a SA1111 chip. This must be called
609 * before any other SA1111-specific code.
610 *
611 * Returns:
612 * %-ENODEV device not found.
613 * %-EBUSY physical address already marked in-use.
614 * %0 successful.
615 */
616static int
617__sa1111_probe(struct device *me, struct resource *mem, int irq)
618{
619 struct sa1111 *sachip;
620 unsigned long id;
621 unsigned int has_devs, val;
622 int i, ret = -ENODEV;
623
624 sachip = kmalloc(sizeof(struct sa1111), GFP_KERNEL);
625 if (!sachip)
626 return -ENOMEM;
627
628 memset(sachip, 0, sizeof(struct sa1111));
629
Russell King97d654f2006-03-15 15:54:37 +0000630 sachip->clk = clk_get(me, "GPIO27_CLK");
631 if (!sachip->clk) {
632 ret = PTR_ERR(sachip->clk);
633 goto err_free;
634 }
635
Linus Torvalds1da177e2005-04-16 15:20:36 -0700636 spin_lock_init(&sachip->lock);
637
638 sachip->dev = me;
639 dev_set_drvdata(sachip->dev, sachip);
640
641 sachip->phys = mem->start;
642 sachip->irq = irq;
643
644 /*
645 * Map the whole region. This also maps the
646 * registers for our children.
647 */
648 sachip->base = ioremap(mem->start, PAGE_SIZE * 2);
649 if (!sachip->base) {
650 ret = -ENOMEM;
Russell King97d654f2006-03-15 15:54:37 +0000651 goto err_clkput;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700652 }
653
654 /*
655 * Probe for the chip. Only touch the SBI registers.
656 */
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);
660 ret = -ENODEV;
Russell King97d654f2006-03-15 15:54:37 +0000661 goto err_unmap;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700662 }
663
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));
667
668 /*
669 * We found it. Wake the chip up, and initialise.
670 */
671 sa1111_wake(sachip);
672
673#ifdef CONFIG_ARCH_SA1100
674 /*
675 * The SDRAM configuration of the SA1110 and the SA1111 must
676 * match. This is very important to ensure that SA1111 accesses
677 * don't corrupt the SDRAM. Note that this ungates the SA1111's
678 * MBGNT signal, so we must have called sa1110_mb_disable()
679 * beforehand.
680 */
681 sa1111_configure_smc(sachip, 1,
682 FExtr(MDCNFG, MDCNFG_SA1110_DRAC0),
683 FExtr(MDCNFG, MDCNFG_SA1110_TDL0));
684
685 /*
686 * We only need to turn on DCLK whenever we want to use the
687 * DMA. It can otherwise be held firmly in the off position.
688 * (currently, we always enable it.)
689 */
690 val = sa1111_readl(sachip->base + SA1111_SKPCR);
691 sa1111_writel(val | SKPCR_DCLKEN, sachip->base + SA1111_SKPCR);
692
693 /*
694 * Enable the SA1110 memory bus request and grant signals.
695 */
696 sa1110_mb_enable();
697#endif
698
699 /*
700 * The interrupt controller must be initialised before any
701 * other device to ensure that the interrupts are available.
702 */
703 if (sachip->irq != NO_IRQ)
704 sa1111_setup_irq(sachip);
705
706 g_sa1111 = sachip;
707
708 has_devs = ~0;
709 if (machine_is_assabet() || machine_is_jornada720() ||
710 machine_is_badge4())
711 has_devs &= ~(1 << 4);
712 else
713 has_devs &= ~(1 << 1);
714
715 for (i = 0; i < ARRAY_SIZE(sa1111_devices); i++)
716 if (has_devs & (1 << i))
717 sa1111_init_one_child(sachip, mem, &sa1111_devices[i]);
718
719 return 0;
720
Russell King97d654f2006-03-15 15:54:37 +0000721 err_unmap:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700722 iounmap(sachip->base);
Russell King97d654f2006-03-15 15:54:37 +0000723 err_clkput:
724 clk_put(sachip->clk);
725 err_free:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700726 kfree(sachip);
727 return ret;
728}
729
Russell King522c37b2005-06-22 09:52:26 +0100730static int sa1111_remove_one(struct device *dev, void *data)
731{
732 device_unregister(dev);
733 return 0;
734}
735
Linus Torvalds1da177e2005-04-16 15:20:36 -0700736static void __sa1111_remove(struct sa1111 *sachip)
737{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700738 void __iomem *irqbase = sachip->base + SA1111_INTC;
739
Russell King522c37b2005-06-22 09:52:26 +0100740 device_for_each_child(sachip->dev, NULL, sa1111_remove_one);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700741
742 /* disable all IRQs */
743 sa1111_writel(0, irqbase + SA1111_INTEN0);
744 sa1111_writel(0, irqbase + SA1111_INTEN1);
745 sa1111_writel(0, irqbase + SA1111_WAKEEN0);
746 sa1111_writel(0, irqbase + SA1111_WAKEEN1);
747
Russell King97d654f2006-03-15 15:54:37 +0000748 clk_disable(sachip->clk);
749
Linus Torvalds1da177e2005-04-16 15:20:36 -0700750 if (sachip->irq != NO_IRQ) {
751 set_irq_chained_handler(sachip->irq, NULL);
752 set_irq_data(sachip->irq, NULL);
753
754 release_mem_region(sachip->phys + SA1111_INTC, 512);
755 }
756
757 iounmap(sachip->base);
Russell King97d654f2006-03-15 15:54:37 +0000758 clk_put(sachip->clk);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700759 kfree(sachip);
760}
761
762/*
763 * According to the "Intel StrongARM SA-1111 Microprocessor Companion
764 * Chip Specification Update" (June 2000), erratum #7, there is a
765 * significant bug in the SA1111 SDRAM shared memory controller. If
766 * an access to a region of memory above 1MB relative to the bank base,
767 * it is important that address bit 10 _NOT_ be asserted. Depending
768 * on the configuration of the RAM, bit 10 may correspond to one
769 * of several different (processor-relative) address bits.
770 *
771 * This routine only identifies whether or not a given DMA address
772 * is susceptible to the bug.
773 *
774 * This should only get called for sa1111_device types due to the
775 * way we configure our device dma_masks.
776 */
777int dma_needs_bounce(struct device *dev, dma_addr_t addr, size_t size)
778{
779 /*
780 * Section 4.6 of the "Intel StrongARM SA-1111 Development Module
781 * User's Guide" mentions that jumpers R51 and R52 control the
782 * target of SA-1111 DMA (either SDRAM bank 0 on Assabet, or
783 * SDRAM bank 1 on Neponset). The default configuration selects
784 * Assabet, so any address in bank 1 is necessarily invalid.
785 */
786 return ((machine_is_assabet() || machine_is_pfs168()) &&
787 (addr >= 0xc8000000 || (addr + size) >= 0xc8000000));
788}
789
790struct sa1111_save_data {
791 unsigned int skcr;
792 unsigned int skpcr;
793 unsigned int skcdr;
794 unsigned char skaud;
795 unsigned char skpwm0;
796 unsigned char skpwm1;
797
798 /*
799 * Interrupt controller
800 */
801 unsigned int intpol0;
802 unsigned int intpol1;
803 unsigned int inten0;
804 unsigned int inten1;
805 unsigned int wakepol0;
806 unsigned int wakepol1;
807 unsigned int wakeen0;
808 unsigned int wakeen1;
809};
810
811#ifdef CONFIG_PM
812
Russell King3ae5eae2005-11-09 22:32:44 +0000813static int sa1111_suspend(struct platform_device *dev, pm_message_t state)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700814{
Russell King3ae5eae2005-11-09 22:32:44 +0000815 struct sa1111 *sachip = platform_get_drvdata(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700816 struct sa1111_save_data *save;
817 unsigned long flags;
818 unsigned int val;
819 void __iomem *base;
820
Linus Torvalds1da177e2005-04-16 15:20:36 -0700821 save = kmalloc(sizeof(struct sa1111_save_data), GFP_KERNEL);
822 if (!save)
823 return -ENOMEM;
Russell King3ae5eae2005-11-09 22:32:44 +0000824 dev->dev.power.saved_state = save;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700825
826 spin_lock_irqsave(&sachip->lock, flags);
827
828 /*
829 * Save state.
830 */
831 base = sachip->base;
832 save->skcr = sa1111_readl(base + SA1111_SKCR);
833 save->skpcr = sa1111_readl(base + SA1111_SKPCR);
834 save->skcdr = sa1111_readl(base + SA1111_SKCDR);
835 save->skaud = sa1111_readl(base + SA1111_SKAUD);
836 save->skpwm0 = sa1111_readl(base + SA1111_SKPWM0);
837 save->skpwm1 = sa1111_readl(base + SA1111_SKPWM1);
838
839 base = sachip->base + SA1111_INTC;
840 save->intpol0 = sa1111_readl(base + SA1111_INTPOL0);
841 save->intpol1 = sa1111_readl(base + SA1111_INTPOL1);
842 save->inten0 = sa1111_readl(base + SA1111_INTEN0);
843 save->inten1 = sa1111_readl(base + SA1111_INTEN1);
844 save->wakepol0 = sa1111_readl(base + SA1111_WAKEPOL0);
845 save->wakepol1 = sa1111_readl(base + SA1111_WAKEPOL1);
846 save->wakeen0 = sa1111_readl(base + SA1111_WAKEEN0);
847 save->wakeen1 = sa1111_readl(base + SA1111_WAKEEN1);
848
849 /*
850 * Disable.
851 */
852 val = sa1111_readl(sachip->base + SA1111_SKCR);
853 sa1111_writel(val | SKCR_SLEEP, sachip->base + SA1111_SKCR);
854 sa1111_writel(0, sachip->base + SA1111_SKPWM0);
855 sa1111_writel(0, sachip->base + SA1111_SKPWM1);
856
Russell King97d654f2006-03-15 15:54:37 +0000857 clk_disable(sachip->clk);
858
Linus Torvalds1da177e2005-04-16 15:20:36 -0700859 spin_unlock_irqrestore(&sachip->lock, flags);
860
861 return 0;
862}
863
864/*
865 * sa1111_resume - Restore the SA1111 device state.
866 * @dev: device to restore
Linus Torvalds1da177e2005-04-16 15:20:36 -0700867 *
868 * Restore the general state of the SA1111; clock control and
869 * interrupt controller. Other parts of the SA1111 must be
870 * restored by their respective drivers, and must be called
871 * via LDM after this function.
872 */
Russell King3ae5eae2005-11-09 22:32:44 +0000873static int sa1111_resume(struct platform_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700874{
Russell King3ae5eae2005-11-09 22:32:44 +0000875 struct sa1111 *sachip = platform_get_drvdata(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700876 struct sa1111_save_data *save;
877 unsigned long flags, id;
878 void __iomem *base;
879
Russell King3ae5eae2005-11-09 22:32:44 +0000880 save = (struct sa1111_save_data *)dev->dev.power.saved_state;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700881 if (!save)
882 return 0;
883
884 spin_lock_irqsave(&sachip->lock, flags);
885
886 /*
887 * Ensure that the SA1111 is still here.
888 * FIXME: shouldn't do this here.
889 */
890 id = sa1111_readl(sachip->base + SA1111_SKID);
891 if ((id & SKID_ID_MASK) != SKID_SA1111_ID) {
892 __sa1111_remove(sachip);
Russell King3ae5eae2005-11-09 22:32:44 +0000893 platform_set_drvdata(dev, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700894 kfree(save);
895 return 0;
896 }
897
898 /*
899 * First of all, wake up the chip.
900 */
901 sa1111_wake(sachip);
902 sa1111_writel(0, sachip->base + SA1111_INTC + SA1111_INTEN0);
903 sa1111_writel(0, sachip->base + SA1111_INTC + SA1111_INTEN1);
904
905 base = sachip->base;
906 sa1111_writel(save->skcr, base + SA1111_SKCR);
907 sa1111_writel(save->skpcr, base + SA1111_SKPCR);
908 sa1111_writel(save->skcdr, base + SA1111_SKCDR);
909 sa1111_writel(save->skaud, base + SA1111_SKAUD);
910 sa1111_writel(save->skpwm0, base + SA1111_SKPWM0);
911 sa1111_writel(save->skpwm1, base + SA1111_SKPWM1);
912
913 base = sachip->base + SA1111_INTC;
914 sa1111_writel(save->intpol0, base + SA1111_INTPOL0);
915 sa1111_writel(save->intpol1, base + SA1111_INTPOL1);
916 sa1111_writel(save->inten0, base + SA1111_INTEN0);
917 sa1111_writel(save->inten1, base + SA1111_INTEN1);
918 sa1111_writel(save->wakepol0, base + SA1111_WAKEPOL0);
919 sa1111_writel(save->wakepol1, base + SA1111_WAKEPOL1);
920 sa1111_writel(save->wakeen0, base + SA1111_WAKEEN0);
921 sa1111_writel(save->wakeen1, base + SA1111_WAKEEN1);
922
923 spin_unlock_irqrestore(&sachip->lock, flags);
924
Russell King3ae5eae2005-11-09 22:32:44 +0000925 dev->dev.power.saved_state = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700926 kfree(save);
927
928 return 0;
929}
930
931#else
932#define sa1111_suspend NULL
933#define sa1111_resume NULL
934#endif
935
Russell King3ae5eae2005-11-09 22:32:44 +0000936static int sa1111_probe(struct platform_device *pdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700937{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700938 struct resource *mem;
939 int irq;
940
941 mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
942 if (!mem)
943 return -EINVAL;
944 irq = platform_get_irq(pdev, 0);
David Vrabel48944732006-01-19 17:56:29 +0000945 if (irq < 0)
946 return -ENXIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700947
Russell King3ae5eae2005-11-09 22:32:44 +0000948 return __sa1111_probe(&pdev->dev, mem, irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700949}
950
Russell King3ae5eae2005-11-09 22:32:44 +0000951static int sa1111_remove(struct platform_device *pdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700952{
Russell King3ae5eae2005-11-09 22:32:44 +0000953 struct sa1111 *sachip = platform_get_drvdata(pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700954
955 if (sachip) {
956 __sa1111_remove(sachip);
Russell King3ae5eae2005-11-09 22:32:44 +0000957 platform_set_drvdata(pdev, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700958
959#ifdef CONFIG_PM
Russell King3ae5eae2005-11-09 22:32:44 +0000960 kfree(pdev->dev.power.saved_state);
961 pdev->dev.power.saved_state = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700962#endif
963 }
964
965 return 0;
966}
967
968/*
969 * Not sure if this should be on the system bus or not yet.
970 * We really want some way to register a system device at
971 * the per-machine level, and then have this driver pick
972 * up the registered devices.
973 *
974 * We also need to handle the SDRAM configuration for
975 * PXA250/SA1110 machine classes.
976 */
Russell King3ae5eae2005-11-09 22:32:44 +0000977static struct platform_driver sa1111_device_driver = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700978 .probe = sa1111_probe,
979 .remove = sa1111_remove,
980 .suspend = sa1111_suspend,
981 .resume = sa1111_resume,
Russell King3ae5eae2005-11-09 22:32:44 +0000982 .driver = {
983 .name = "sa1111",
984 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700985};
986
987/*
988 * Get the parent device driver (us) structure
989 * from a child function device
990 */
991static inline struct sa1111 *sa1111_chip_driver(struct sa1111_dev *sadev)
992{
993 return (struct sa1111 *)dev_get_drvdata(sadev->dev.parent);
994}
995
996/*
997 * The bits in the opdiv field are non-linear.
998 */
999static unsigned char opdiv_table[] = { 1, 4, 2, 8 };
1000
1001static unsigned int __sa1111_pll_clock(struct sa1111 *sachip)
1002{
1003 unsigned int skcdr, fbdiv, ipdiv, opdiv;
1004
1005 skcdr = sa1111_readl(sachip->base + SA1111_SKCDR);
1006
1007 fbdiv = (skcdr & 0x007f) + 2;
1008 ipdiv = ((skcdr & 0x0f80) >> 7) + 2;
1009 opdiv = opdiv_table[(skcdr & 0x3000) >> 12];
1010
1011 return 3686400 * fbdiv / (ipdiv * opdiv);
1012}
1013
1014/**
1015 * sa1111_pll_clock - return the current PLL clock frequency.
1016 * @sadev: SA1111 function block
1017 *
1018 * BUG: we should look at SKCR. We also blindly believe that
1019 * the chip is being fed with the 3.6864MHz clock.
1020 *
1021 * Returns the PLL clock in Hz.
1022 */
1023unsigned int sa1111_pll_clock(struct sa1111_dev *sadev)
1024{
1025 struct sa1111 *sachip = sa1111_chip_driver(sadev);
1026
1027 return __sa1111_pll_clock(sachip);
1028}
1029
1030/**
1031 * sa1111_select_audio_mode - select I2S or AC link mode
1032 * @sadev: SA1111 function block
1033 * @mode: One of %SA1111_AUDIO_ACLINK or %SA1111_AUDIO_I2S
1034 *
1035 * Frob the SKCR to select AC Link mode or I2S mode for
1036 * the audio block.
1037 */
1038void sa1111_select_audio_mode(struct sa1111_dev *sadev, int mode)
1039{
1040 struct sa1111 *sachip = sa1111_chip_driver(sadev);
1041 unsigned long flags;
1042 unsigned int val;
1043
1044 spin_lock_irqsave(&sachip->lock, flags);
1045
1046 val = sa1111_readl(sachip->base + SA1111_SKCR);
1047 if (mode == SA1111_AUDIO_I2S) {
1048 val &= ~SKCR_SELAC;
1049 } else {
1050 val |= SKCR_SELAC;
1051 }
1052 sa1111_writel(val, sachip->base + SA1111_SKCR);
1053
1054 spin_unlock_irqrestore(&sachip->lock, flags);
1055}
1056
1057/**
1058 * sa1111_set_audio_rate - set the audio sample rate
1059 * @sadev: SA1111 SAC function block
1060 * @rate: sample rate to select
1061 */
1062int sa1111_set_audio_rate(struct sa1111_dev *sadev, int rate)
1063{
1064 struct sa1111 *sachip = sa1111_chip_driver(sadev);
1065 unsigned int div;
1066
1067 if (sadev->devid != SA1111_DEVID_SAC)
1068 return -EINVAL;
1069
1070 div = (__sa1111_pll_clock(sachip) / 256 + rate / 2) / rate;
1071 if (div == 0)
1072 div = 1;
1073 if (div > 128)
1074 div = 128;
1075
1076 sa1111_writel(div - 1, sachip->base + SA1111_SKAUD);
1077
1078 return 0;
1079}
1080
1081/**
1082 * sa1111_get_audio_rate - get the audio sample rate
1083 * @sadev: SA1111 SAC function block device
1084 */
1085int sa1111_get_audio_rate(struct sa1111_dev *sadev)
1086{
1087 struct sa1111 *sachip = sa1111_chip_driver(sadev);
1088 unsigned long div;
1089
1090 if (sadev->devid != SA1111_DEVID_SAC)
1091 return -EINVAL;
1092
1093 div = sa1111_readl(sachip->base + SA1111_SKAUD) + 1;
1094
1095 return __sa1111_pll_clock(sachip) / (256 * div);
1096}
1097
1098void sa1111_set_io_dir(struct sa1111_dev *sadev,
1099 unsigned int bits, unsigned int dir,
1100 unsigned int sleep_dir)
1101{
1102 struct sa1111 *sachip = sa1111_chip_driver(sadev);
1103 unsigned long flags;
1104 unsigned int val;
1105 void __iomem *gpio = sachip->base + SA1111_GPIO;
1106
1107#define MODIFY_BITS(port, mask, dir) \
1108 if (mask) { \
1109 val = sa1111_readl(port); \
1110 val &= ~(mask); \
1111 val |= (dir) & (mask); \
1112 sa1111_writel(val, port); \
1113 }
1114
1115 spin_lock_irqsave(&sachip->lock, flags);
1116 MODIFY_BITS(gpio + SA1111_GPIO_PADDR, bits & 15, dir);
1117 MODIFY_BITS(gpio + SA1111_GPIO_PBDDR, (bits >> 8) & 255, dir >> 8);
1118 MODIFY_BITS(gpio + SA1111_GPIO_PCDDR, (bits >> 16) & 255, dir >> 16);
1119
1120 MODIFY_BITS(gpio + SA1111_GPIO_PASDR, bits & 15, sleep_dir);
1121 MODIFY_BITS(gpio + SA1111_GPIO_PBSDR, (bits >> 8) & 255, sleep_dir >> 8);
1122 MODIFY_BITS(gpio + SA1111_GPIO_PCSDR, (bits >> 16) & 255, sleep_dir >> 16);
1123 spin_unlock_irqrestore(&sachip->lock, flags);
1124}
1125
1126void sa1111_set_io(struct sa1111_dev *sadev, unsigned int bits, unsigned int v)
1127{
1128 struct sa1111 *sachip = sa1111_chip_driver(sadev);
1129 unsigned long flags;
1130 unsigned int val;
1131 void __iomem *gpio = sachip->base + SA1111_GPIO;
1132
1133 spin_lock_irqsave(&sachip->lock, flags);
1134 MODIFY_BITS(gpio + SA1111_GPIO_PADWR, bits & 15, v);
1135 MODIFY_BITS(gpio + SA1111_GPIO_PBDWR, (bits >> 8) & 255, v >> 8);
1136 MODIFY_BITS(gpio + SA1111_GPIO_PCDWR, (bits >> 16) & 255, v >> 16);
1137 spin_unlock_irqrestore(&sachip->lock, flags);
1138}
1139
1140void sa1111_set_sleep_io(struct sa1111_dev *sadev, unsigned int bits, unsigned int v)
1141{
1142 struct sa1111 *sachip = sa1111_chip_driver(sadev);
1143 unsigned long flags;
1144 unsigned int val;
1145 void __iomem *gpio = sachip->base + SA1111_GPIO;
1146
1147 spin_lock_irqsave(&sachip->lock, flags);
1148 MODIFY_BITS(gpio + SA1111_GPIO_PASSR, bits & 15, v);
1149 MODIFY_BITS(gpio + SA1111_GPIO_PBSSR, (bits >> 8) & 255, v >> 8);
1150 MODIFY_BITS(gpio + SA1111_GPIO_PCSSR, (bits >> 16) & 255, v >> 16);
1151 spin_unlock_irqrestore(&sachip->lock, flags);
1152}
1153
1154/*
1155 * Individual device operations.
1156 */
1157
1158/**
1159 * sa1111_enable_device - enable an on-chip SA1111 function block
1160 * @sadev: SA1111 function block device to enable
1161 */
1162void sa1111_enable_device(struct sa1111_dev *sadev)
1163{
1164 struct sa1111 *sachip = sa1111_chip_driver(sadev);
1165 unsigned long flags;
1166 unsigned int val;
1167
1168 spin_lock_irqsave(&sachip->lock, flags);
1169 val = sa1111_readl(sachip->base + SA1111_SKPCR);
1170 sa1111_writel(val | sadev->skpcr_mask, sachip->base + SA1111_SKPCR);
1171 spin_unlock_irqrestore(&sachip->lock, flags);
1172}
1173
1174/**
1175 * sa1111_disable_device - disable an on-chip SA1111 function block
1176 * @sadev: SA1111 function block device to disable
1177 */
1178void sa1111_disable_device(struct sa1111_dev *sadev)
1179{
1180 struct sa1111 *sachip = sa1111_chip_driver(sadev);
1181 unsigned long flags;
1182 unsigned int val;
1183
1184 spin_lock_irqsave(&sachip->lock, flags);
1185 val = sa1111_readl(sachip->base + SA1111_SKPCR);
1186 sa1111_writel(val & ~sadev->skpcr_mask, sachip->base + SA1111_SKPCR);
1187 spin_unlock_irqrestore(&sachip->lock, flags);
1188}
1189
1190/*
1191 * SA1111 "Register Access Bus."
1192 *
1193 * We model this as a regular bus type, and hang devices directly
1194 * off this.
1195 */
1196static int sa1111_match(struct device *_dev, struct device_driver *_drv)
1197{
1198 struct sa1111_dev *dev = SA1111_DEV(_dev);
1199 struct sa1111_driver *drv = SA1111_DRV(_drv);
1200
1201 return dev->devid == drv->devid;
1202}
1203
1204static int sa1111_bus_suspend(struct device *dev, pm_message_t state)
1205{
1206 struct sa1111_dev *sadev = SA1111_DEV(dev);
1207 struct sa1111_driver *drv = SA1111_DRV(dev->driver);
1208 int ret = 0;
1209
1210 if (drv && drv->suspend)
1211 ret = drv->suspend(sadev, state);
1212 return ret;
1213}
1214
1215static int sa1111_bus_resume(struct device *dev)
1216{
1217 struct sa1111_dev *sadev = SA1111_DEV(dev);
1218 struct sa1111_driver *drv = SA1111_DRV(dev->driver);
1219 int ret = 0;
1220
1221 if (drv && drv->resume)
1222 ret = drv->resume(sadev);
1223 return ret;
1224}
1225
1226static int sa1111_bus_probe(struct device *dev)
1227{
1228 struct sa1111_dev *sadev = SA1111_DEV(dev);
1229 struct sa1111_driver *drv = SA1111_DRV(dev->driver);
1230 int ret = -ENODEV;
1231
1232 if (drv->probe)
1233 ret = drv->probe(sadev);
1234 return ret;
1235}
1236
1237static int sa1111_bus_remove(struct device *dev)
1238{
1239 struct sa1111_dev *sadev = SA1111_DEV(dev);
1240 struct sa1111_driver *drv = SA1111_DRV(dev->driver);
1241 int ret = 0;
1242
1243 if (drv->remove)
1244 ret = drv->remove(sadev);
1245 return ret;
1246}
1247
1248struct bus_type sa1111_bus_type = {
1249 .name = "sa1111-rab",
1250 .match = sa1111_match,
Russell King2876ba42006-01-05 14:32:32 +00001251 .probe = sa1111_bus_probe,
1252 .remove = sa1111_bus_remove,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001253 .suspend = sa1111_bus_suspend,
1254 .resume = sa1111_bus_resume,
1255};
1256
1257int sa1111_driver_register(struct sa1111_driver *driver)
1258{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001259 driver->drv.bus = &sa1111_bus_type;
1260 return driver_register(&driver->drv);
1261}
1262
1263void sa1111_driver_unregister(struct sa1111_driver *driver)
1264{
1265 driver_unregister(&driver->drv);
1266}
1267
1268static int __init sa1111_init(void)
1269{
1270 int ret = bus_register(&sa1111_bus_type);
1271 if (ret == 0)
Russell King3ae5eae2005-11-09 22:32:44 +00001272 platform_driver_register(&sa1111_device_driver);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001273 return ret;
1274}
1275
1276static void __exit sa1111_exit(void)
1277{
Russell King3ae5eae2005-11-09 22:32:44 +00001278 platform_driver_unregister(&sa1111_device_driver);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001279 bus_unregister(&sa1111_bus_type);
1280}
1281
Russell King72724382005-11-15 19:04:22 +00001282subsys_initcall(sa1111_init);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001283module_exit(sa1111_exit);
1284
1285MODULE_DESCRIPTION("Intel Corporation SA1111 core driver");
1286MODULE_LICENSE("GPL");
1287
1288EXPORT_SYMBOL(sa1111_select_audio_mode);
1289EXPORT_SYMBOL(sa1111_set_audio_rate);
1290EXPORT_SYMBOL(sa1111_get_audio_rate);
1291EXPORT_SYMBOL(sa1111_set_io_dir);
1292EXPORT_SYMBOL(sa1111_set_io);
1293EXPORT_SYMBOL(sa1111_set_sleep_io);
1294EXPORT_SYMBOL(sa1111_enable_device);
1295EXPORT_SYMBOL(sa1111_disable_device);
1296EXPORT_SYMBOL(sa1111_pll_clock);
1297EXPORT_SYMBOL(sa1111_bus_type);
1298EXPORT_SYMBOL(sa1111_driver_register);
1299EXPORT_SYMBOL(sa1111_driver_unregister);