17 #include <linux/module.h>
20 #include <linux/kernel.h>
22 #include <linux/errno.h>
25 #include <linux/slab.h>
31 #include <mach/hardware.h>
34 #include <asm/sizes.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)
89 #define SA1111_IRQ_NR (55)
119 static struct sa1111 *g_sa1111;
202 unsigned int stat0, stat1,
i;
203 struct sa1111 *sachip = irq_get_handler_data(irq);
215 if (stat0 == 0 && stat1 == 0) {
220 for (i = 0; stat0; i++, stat0 >>= 1)
224 for (i = 32; stat1; i++, stat1 >>= 1)
232 #define SA1111_IRQMASK_LO(x) (1 << (x - sachip->irq_base))
233 #define SA1111_IRQMASK_HI(x) (1 << (x - sachip->irq_base - 32))
235 static void sa1111_ack_irq(
struct irq_data *
d)
239 static void sa1111_mask_lowirq(
struct irq_data *
d)
241 struct sa1111 *sachip = irq_data_get_irq_chip_data(d);
250 static void sa1111_unmask_lowirq(
struct irq_data *
d)
252 struct sa1111 *sachip = irq_data_get_irq_chip_data(d);
268 static int sa1111_retrigger_lowirq(
struct irq_data *
d)
270 struct sa1111 *sachip = irq_data_get_irq_chip_data(d);
277 for (i = 0; i < 8; i++) {
286 "re-trigger IRQ%d\n", d->
irq);
287 return i == 8 ? -1 : 0;
290 static int sa1111_type_lowirq(
struct irq_data *d,
unsigned int flags)
292 struct sa1111 *sachip = irq_data_get_irq_chip_data(d);
304 if (flags & IRQ_TYPE_EDGE_RISING)
314 static int sa1111_wake_lowirq(
struct irq_data *d,
unsigned int on)
316 struct sa1111 *sachip = irq_data_get_irq_chip_data(d);
331 static struct irq_chip sa1111_low_chip = {
333 .irq_ack = sa1111_ack_irq,
334 .irq_mask = sa1111_mask_lowirq,
335 .irq_unmask = sa1111_unmask_lowirq,
336 .irq_retrigger = sa1111_retrigger_lowirq,
337 .irq_set_type = sa1111_type_lowirq,
338 .irq_set_wake = sa1111_wake_lowirq,
341 static void sa1111_mask_highirq(
struct irq_data *d)
343 struct sa1111 *sachip = irq_data_get_irq_chip_data(d);
352 static void sa1111_unmask_highirq(
struct irq_data *d)
354 struct sa1111 *sachip = irq_data_get_irq_chip_data(d);
370 static int sa1111_retrigger_highirq(
struct irq_data *d)
372 struct sa1111 *sachip = irq_data_get_irq_chip_data(d);
379 for (i = 0; i < 8; i++) {
388 "re-trigger IRQ%d\n", d->
irq);
389 return i == 8 ? -1 : 0;
392 static int sa1111_type_highirq(
struct irq_data *d,
unsigned int flags)
394 struct sa1111 *sachip = irq_data_get_irq_chip_data(d);
402 if ((!(flags & IRQ_TYPE_EDGE_RISING) ^ !(flags & IRQ_TYPE_EDGE_FALLING)) == 0)
406 if (flags & IRQ_TYPE_EDGE_RISING)
416 static int sa1111_wake_highirq(
struct irq_data *d,
unsigned int on)
418 struct sa1111 *sachip = irq_data_get_irq_chip_data(d);
433 static struct irq_chip sa1111_high_chip = {
435 .irq_ack = sa1111_ack_irq,
436 .irq_mask = sa1111_mask_highirq,
437 .irq_unmask = sa1111_unmask_highirq,
438 .irq_retrigger = sa1111_retrigger_highirq,
439 .irq_set_type = sa1111_type_highirq,
440 .irq_set_wake = sa1111_wake_highirq,
443 static int sa1111_setup_irq(
struct sa1111 *sachip,
unsigned irq_base)
456 dev_err(sachip->
dev,
"unable to allocate %u irqs: %d\n",
486 irq_set_chip_and_handler(irq, &sa1111_low_chip,
494 irq_set_chip_and_handler(irq, &sa1111_high_chip,
505 irq_set_chained_handler(sachip->
irq, sa1111_irq_handler);
527 static void sa1111_wake(
struct sa1111 *sachip)
567 spin_unlock_irqrestore(&sachip->
lock, flags);
570 #ifdef CONFIG_ARCH_SA1100
572 static u32 sa1111_dma_mask[] = {
587 sa1111_configure_smc(
struct sa1111 *sachip,
int sdram,
unsigned int drac,
588 unsigned int cas_latency)
592 if (cas_latency == 3)
602 if (sachip->
dev->dma_mask)
603 *sachip->
dev->dma_mask &= sa1111_dma_mask[drac >> 2];
605 sachip->
dev->coherent_dma_mask &= sa1111_dma_mask[drac >> 2];
609 static void sa1111_dev_release(
struct device *_dev)
617 sa1111_init_one_child(
struct sa1111 *sachip,
struct resource *parent,
633 dev->
dev.parent = sachip->
dev;
635 dev->
dev.release = sa1111_dev_release;
637 dev->
res.end = dev->
res.start + 511;
638 dev->
res.name = dev_name(&dev->
dev);
650 if (info->
dma && sachip->
dev->dma_mask) {
653 dev->
dev.coherent_dma_mask = sachip->
dev->coherent_dma_mask;
658 dev_err(sachip->
dev,
"failed to allocate resource for %s\n",
695 unsigned int has_devs;
706 if (IS_ERR(sachip->
clk)) {
707 ret = PTR_ERR(sachip->
clk);
745 "silicon revision %lx, metal revision %lx\n",
758 ret = sa1111_setup_irq(sachip, pd->
irq_base);
763 #ifdef CONFIG_ARCH_SA1100
774 sa1111_configure_smc(sachip, 1,
799 for (i = 0; i <
ARRAY_SIZE(sa1111_devices); i++)
800 if (sa1111_devices[i].
devid & has_devs)
801 sa1111_init_one_child(sachip, mem, &sa1111_devices[i]);
816 static int sa1111_remove_one(
struct device *dev,
void *
data)
825 static void __sa1111_remove(
struct sa1111 *sachip)
841 irq_set_chained_handler(sachip->
irq,
NULL);
878 struct sa1111 *sachip = platform_get_drvdata(dev);
887 sachip->saved_state = save;
923 spin_unlock_irqrestore(&sachip->
lock, flags);
925 #ifdef CONFIG_ARCH_SA1100
943 struct sa1111 *sachip = platform_get_drvdata(dev);
948 save = sachip->saved_state;
958 __sa1111_remove(sachip);
959 platform_set_drvdata(dev,
NULL);
969 #ifdef CONFIG_ARCH_SA1100
1001 spin_unlock_irqrestore(&sachip->
lock, flags);
1003 sachip->saved_state =
NULL;
1010 #define sa1111_suspend NULL
1011 #define sa1111_resume NULL
1026 return __sa1111_probe(&pdev->
dev, mem, irq);
1031 struct sa1111 *sachip = platform_get_drvdata(pdev);
1035 kfree(sachip->saved_state);
1036 sachip->saved_state =
NULL;
1038 __sa1111_remove(sachip);
1039 platform_set_drvdata(pdev,
NULL);
1055 .probe = sa1111_probe,
1056 .remove = sa1111_remove,
1077 static unsigned char opdiv_table[] = { 1, 4, 2, 8 };
1079 static unsigned int __sa1111_pll_clock(
struct sa1111 *sachip)
1081 unsigned int skcdr, fbdiv, ipdiv, opdiv;
1085 fbdiv = (skcdr & 0x007f) + 2;
1086 ipdiv = ((skcdr & 0x0f80) >> 7) + 2;
1087 opdiv = opdiv_table[(skcdr & 0x3000) >> 12];
1089 return 3686400 * fbdiv / (ipdiv * opdiv);
1103 struct sa1111 *sachip = sa1111_chip_driver(sadev);
1105 return __sa1111_pll_clock(sachip);
1119 struct sa1111 *sachip = sa1111_chip_driver(sadev);
1120 unsigned long flags;
1133 spin_unlock_irqrestore(&sachip->
lock, flags);
1144 struct sa1111 *sachip = sa1111_chip_driver(sadev);
1150 div = (__sa1111_pll_clock(sachip) / 256 + rate / 2) / rate;
1168 struct sa1111 *sachip = sa1111_chip_driver(sadev);
1176 return __sa1111_pll_clock(sachip) / (256 *
div);
1181 unsigned int bits,
unsigned int dir,
1182 unsigned int sleep_dir)
1184 struct sa1111 *sachip = sa1111_chip_driver(sadev);
1185 unsigned long flags;
1189 #define MODIFY_BITS(port, mask, dir) \
1191 val = sa1111_readl(port); \
1193 val |= (dir) & (mask); \
1194 sa1111_writel(val, port); \
1205 spin_unlock_irqrestore(&sachip->
lock, flags);
1211 struct sa1111 *sachip = sa1111_chip_driver(sadev);
1212 unsigned long flags;
1220 spin_unlock_irqrestore(&sachip->
lock, flags);
1226 struct sa1111 *sachip = sa1111_chip_driver(sadev);
1227 unsigned long flags;
1235 spin_unlock_irqrestore(&sachip->
lock, flags);
1249 struct sa1111 *sachip = sa1111_chip_driver(sadev);
1250 unsigned long flags;
1261 spin_unlock_irqrestore(&sachip->
lock, flags);
1273 struct sa1111 *sachip = sa1111_chip_driver(sadev);
1274 unsigned long flags;
1280 spin_unlock_irqrestore(&sachip->
lock, flags);
1308 ret = drv->
suspend(sadev, state);
1312 static int sa1111_bus_resume(
struct device *dev)
1319 ret = drv->
resume(sadev);
1323 static void sa1111_bus_shutdown(
struct device *dev)
1331 static int sa1111_bus_probe(
struct device *dev)
1338 ret = drv->
probe(sadev);
1342 static int sa1111_bus_remove(
struct device *dev)
1349 ret = drv->
remove(sadev);
1354 .name =
"sa1111-rab",
1355 .match = sa1111_match,
1356 .probe = sa1111_bus_probe,
1357 .remove = sa1111_bus_remove,
1358 .suspend = sa1111_bus_suspend,
1359 .resume = sa1111_bus_resume,
1360 .shutdown = sa1111_bus_shutdown,
1377 #ifdef CONFIG_DMABOUNCE
1402 return (machine_is_assabet() || machine_is_pfs168()) &&
1403 (addr >= 0xc8000000 || (addr +
size) >= 0xc8000000);
1413 if (dev->
dev.dma_mask && dev->
dma_mask < 0xffffffffUL) {
1415 sa1111_needs_bounce);
1417 dev_err(&dev->
dev,
"failed to register with dmabounce: %d\n", ret);
1422 if (dev->
dev.dma_mask && dev->
dma_mask < 0xffffffffUL)
1434 static int __init sa1111_init(
void)
1437 #ifdef CONFIG_DMABOUNCE
1446 static void __exit sa1111_exit(
void)
1449 #ifdef CONFIG_DMABOUNCE