11da177e4SLinus Torvalds /* 2f30c2269SUwe Zeisberger * linux/arch/arm/common/sa1111.c 31da177e4SLinus Torvalds * 41da177e4SLinus Torvalds * SA1111 support 51da177e4SLinus Torvalds * 61da177e4SLinus Torvalds * Original code by John Dorsey 71da177e4SLinus Torvalds * 81da177e4SLinus Torvalds * This program is free software; you can redistribute it and/or modify 91da177e4SLinus Torvalds * it under the terms of the GNU General Public License version 2 as 101da177e4SLinus Torvalds * published by the Free Software Foundation. 111da177e4SLinus Torvalds * 121da177e4SLinus Torvalds * This file contains all generic SA1111 support. 131da177e4SLinus Torvalds * 141da177e4SLinus Torvalds * All initialization functions provided here are intended to be called 151da177e4SLinus Torvalds * from machine specific code with proper arguments when required. 161da177e4SLinus Torvalds */ 171da177e4SLinus Torvalds #include <linux/module.h> 181da177e4SLinus Torvalds #include <linux/init.h> 191da177e4SLinus Torvalds #include <linux/kernel.h> 201da177e4SLinus Torvalds #include <linux/delay.h> 211da177e4SLinus Torvalds #include <linux/ptrace.h> 221da177e4SLinus Torvalds #include <linux/errno.h> 231da177e4SLinus Torvalds #include <linux/ioport.h> 24d052d1beSRussell King #include <linux/platform_device.h> 251da177e4SLinus Torvalds #include <linux/slab.h> 261da177e4SLinus Torvalds #include <linux/spinlock.h> 271da177e4SLinus Torvalds #include <linux/dma-mapping.h> 2897d654f8SRussell King #include <linux/clk.h> 291da177e4SLinus Torvalds 301da177e4SLinus Torvalds #include <asm/hardware.h> 311da177e4SLinus Torvalds #include <asm/mach-types.h> 321da177e4SLinus Torvalds #include <asm/io.h> 331da177e4SLinus Torvalds #include <asm/irq.h> 341da177e4SLinus Torvalds #include <asm/mach/irq.h> 3545e109d0SRussell King #include <asm/sizes.h> 361da177e4SLinus Torvalds 371da177e4SLinus Torvalds #include <asm/hardware/sa1111.h> 381da177e4SLinus Torvalds 391da177e4SLinus Torvalds extern void __init sa1110_mb_enable(void); 401da177e4SLinus Torvalds 411da177e4SLinus Torvalds /* 421da177e4SLinus Torvalds * We keep the following data for the overall SA1111. Note that the 431da177e4SLinus Torvalds * struct device and struct resource are "fake"; they should be supplied 441da177e4SLinus Torvalds * by the bus above us. However, in the interests of getting all SA1111 451da177e4SLinus Torvalds * drivers converted over to the device model, we provide this as an 461da177e4SLinus Torvalds * anchor point for all the other drivers. 471da177e4SLinus Torvalds */ 481da177e4SLinus Torvalds struct sa1111 { 491da177e4SLinus Torvalds struct device *dev; 5097d654f8SRussell King struct clk *clk; 511da177e4SLinus Torvalds unsigned long phys; 521da177e4SLinus Torvalds int irq; 531da177e4SLinus Torvalds spinlock_t lock; 541da177e4SLinus Torvalds void __iomem *base; 551da177e4SLinus Torvalds }; 561da177e4SLinus Torvalds 571da177e4SLinus Torvalds /* 581da177e4SLinus Torvalds * We _really_ need to eliminate this. Its only users 591da177e4SLinus Torvalds * are the PWM and DMA checking code. 601da177e4SLinus Torvalds */ 611da177e4SLinus Torvalds static struct sa1111 *g_sa1111; 621da177e4SLinus Torvalds 631da177e4SLinus Torvalds struct sa1111_dev_info { 641da177e4SLinus Torvalds unsigned long offset; 651da177e4SLinus Torvalds unsigned long skpcr_mask; 661da177e4SLinus Torvalds unsigned int devid; 671da177e4SLinus Torvalds unsigned int irq[6]; 681da177e4SLinus Torvalds }; 691da177e4SLinus Torvalds 701da177e4SLinus Torvalds static struct sa1111_dev_info sa1111_devices[] = { 711da177e4SLinus Torvalds { 721da177e4SLinus Torvalds .offset = SA1111_USB, 731da177e4SLinus Torvalds .skpcr_mask = SKPCR_UCLKEN, 741da177e4SLinus Torvalds .devid = SA1111_DEVID_USB, 751da177e4SLinus Torvalds .irq = { 761da177e4SLinus Torvalds IRQ_USBPWR, 771da177e4SLinus Torvalds IRQ_HCIM, 781da177e4SLinus Torvalds IRQ_HCIBUFFACC, 791da177e4SLinus Torvalds IRQ_HCIRMTWKP, 801da177e4SLinus Torvalds IRQ_NHCIMFCIR, 811da177e4SLinus Torvalds IRQ_USB_PORT_RESUME 821da177e4SLinus Torvalds }, 831da177e4SLinus Torvalds }, 841da177e4SLinus Torvalds { 851da177e4SLinus Torvalds .offset = 0x0600, 861da177e4SLinus Torvalds .skpcr_mask = SKPCR_I2SCLKEN | SKPCR_L3CLKEN, 871da177e4SLinus Torvalds .devid = SA1111_DEVID_SAC, 881da177e4SLinus Torvalds .irq = { 891da177e4SLinus Torvalds AUDXMTDMADONEA, 901da177e4SLinus Torvalds AUDXMTDMADONEB, 911da177e4SLinus Torvalds AUDRCVDMADONEA, 921da177e4SLinus Torvalds AUDRCVDMADONEB 931da177e4SLinus Torvalds }, 941da177e4SLinus Torvalds }, 951da177e4SLinus Torvalds { 961da177e4SLinus Torvalds .offset = 0x0800, 971da177e4SLinus Torvalds .skpcr_mask = SKPCR_SCLKEN, 981da177e4SLinus Torvalds .devid = SA1111_DEVID_SSP, 991da177e4SLinus Torvalds }, 1001da177e4SLinus Torvalds { 1011da177e4SLinus Torvalds .offset = SA1111_KBD, 1021da177e4SLinus Torvalds .skpcr_mask = SKPCR_PTCLKEN, 1031da177e4SLinus Torvalds .devid = SA1111_DEVID_PS2, 1041da177e4SLinus Torvalds .irq = { 1051da177e4SLinus Torvalds IRQ_TPRXINT, 1061da177e4SLinus Torvalds IRQ_TPTXINT 1071da177e4SLinus Torvalds }, 1081da177e4SLinus Torvalds }, 1091da177e4SLinus Torvalds { 1101da177e4SLinus Torvalds .offset = SA1111_MSE, 1111da177e4SLinus Torvalds .skpcr_mask = SKPCR_PMCLKEN, 1121da177e4SLinus Torvalds .devid = SA1111_DEVID_PS2, 1131da177e4SLinus Torvalds .irq = { 1141da177e4SLinus Torvalds IRQ_MSRXINT, 1151da177e4SLinus Torvalds IRQ_MSTXINT 1161da177e4SLinus Torvalds }, 1171da177e4SLinus Torvalds }, 1181da177e4SLinus Torvalds { 1191da177e4SLinus Torvalds .offset = 0x1800, 1201da177e4SLinus Torvalds .skpcr_mask = 0, 1211da177e4SLinus Torvalds .devid = SA1111_DEVID_PCMCIA, 1221da177e4SLinus Torvalds .irq = { 1231da177e4SLinus Torvalds IRQ_S0_READY_NINT, 1241da177e4SLinus Torvalds IRQ_S0_CD_VALID, 1251da177e4SLinus Torvalds IRQ_S0_BVD1_STSCHG, 1261da177e4SLinus Torvalds IRQ_S1_READY_NINT, 1271da177e4SLinus Torvalds IRQ_S1_CD_VALID, 1281da177e4SLinus Torvalds IRQ_S1_BVD1_STSCHG, 1291da177e4SLinus Torvalds }, 1301da177e4SLinus Torvalds }, 1311da177e4SLinus Torvalds }; 1321da177e4SLinus Torvalds 1331b12050fSRussell King void __init sa1111_adjust_zones(int node, unsigned long *size, unsigned long *holes) 1341b12050fSRussell King { 1351b12050fSRussell King unsigned int sz = SZ_1M >> PAGE_SHIFT; 1361b12050fSRussell King 1371b12050fSRussell King if (node != 0) 1381b12050fSRussell King sz = 0; 1391b12050fSRussell King 1401b12050fSRussell King size[1] = size[0] - sz; 1411b12050fSRussell King size[0] = sz; 1421b12050fSRussell King } 1431b12050fSRussell King 1441da177e4SLinus Torvalds /* 1451da177e4SLinus Torvalds * SA1111 interrupt support. Since clearing an IRQ while there are 1461da177e4SLinus Torvalds * active IRQs causes the interrupt output to pulse, the upper levels 1471da177e4SLinus Torvalds * will call us again if there are more interrupts to process. 1481da177e4SLinus Torvalds */ 1491da177e4SLinus Torvalds static void 150*0cd61b68SLinus Torvalds sa1111_irq_handler(unsigned int irq, struct irqdesc *desc) 1511da177e4SLinus Torvalds { 1521da177e4SLinus Torvalds unsigned int stat0, stat1, i; 153c4bfa28aSThomas Gleixner void __iomem *base = get_irq_data(irq); 1541da177e4SLinus Torvalds 1551da177e4SLinus Torvalds stat0 = sa1111_readl(base + SA1111_INTSTATCLR0); 1561da177e4SLinus Torvalds stat1 = sa1111_readl(base + SA1111_INTSTATCLR1); 1571da177e4SLinus Torvalds 1581da177e4SLinus Torvalds sa1111_writel(stat0, base + SA1111_INTSTATCLR0); 1591da177e4SLinus Torvalds 1601da177e4SLinus Torvalds desc->chip->ack(irq); 1611da177e4SLinus Torvalds 1621da177e4SLinus Torvalds sa1111_writel(stat1, base + SA1111_INTSTATCLR1); 1631da177e4SLinus Torvalds 1641da177e4SLinus Torvalds if (stat0 == 0 && stat1 == 0) { 165*0cd61b68SLinus Torvalds do_bad_IRQ(irq, desc); 1661da177e4SLinus Torvalds return; 1671da177e4SLinus Torvalds } 1681da177e4SLinus Torvalds 1691da177e4SLinus Torvalds for (i = IRQ_SA1111_START; stat0; i++, stat0 >>= 1) 1701da177e4SLinus Torvalds if (stat0 & 1) 171*0cd61b68SLinus Torvalds handle_edge_irq(i, irq_desc + i); 1721da177e4SLinus Torvalds 1731da177e4SLinus Torvalds for (i = IRQ_SA1111_START + 32; stat1; i++, stat1 >>= 1) 1741da177e4SLinus Torvalds if (stat1 & 1) 175*0cd61b68SLinus Torvalds handle_edge_irq(i, irq_desc + i); 1761da177e4SLinus Torvalds 1771da177e4SLinus Torvalds /* For level-based interrupts */ 1781da177e4SLinus Torvalds desc->chip->unmask(irq); 1791da177e4SLinus Torvalds } 1801da177e4SLinus Torvalds 1811da177e4SLinus Torvalds #define SA1111_IRQMASK_LO(x) (1 << (x - IRQ_SA1111_START)) 1821da177e4SLinus Torvalds #define SA1111_IRQMASK_HI(x) (1 << (x - IRQ_SA1111_START - 32)) 1831da177e4SLinus Torvalds 1841da177e4SLinus Torvalds static void sa1111_ack_irq(unsigned int irq) 1851da177e4SLinus Torvalds { 1861da177e4SLinus Torvalds } 1871da177e4SLinus Torvalds 1881da177e4SLinus Torvalds static void sa1111_mask_lowirq(unsigned int irq) 1891da177e4SLinus Torvalds { 1901da177e4SLinus Torvalds void __iomem *mapbase = get_irq_chipdata(irq); 1911da177e4SLinus Torvalds unsigned long ie0; 1921da177e4SLinus Torvalds 1931da177e4SLinus Torvalds ie0 = sa1111_readl(mapbase + SA1111_INTEN0); 1941da177e4SLinus Torvalds ie0 &= ~SA1111_IRQMASK_LO(irq); 1951da177e4SLinus Torvalds writel(ie0, mapbase + SA1111_INTEN0); 1961da177e4SLinus Torvalds } 1971da177e4SLinus Torvalds 1981da177e4SLinus Torvalds static void sa1111_unmask_lowirq(unsigned int irq) 1991da177e4SLinus Torvalds { 2001da177e4SLinus Torvalds void __iomem *mapbase = get_irq_chipdata(irq); 2011da177e4SLinus Torvalds unsigned long ie0; 2021da177e4SLinus Torvalds 2031da177e4SLinus Torvalds ie0 = sa1111_readl(mapbase + SA1111_INTEN0); 2041da177e4SLinus Torvalds ie0 |= SA1111_IRQMASK_LO(irq); 2051da177e4SLinus Torvalds sa1111_writel(ie0, mapbase + SA1111_INTEN0); 2061da177e4SLinus Torvalds } 2071da177e4SLinus Torvalds 2081da177e4SLinus Torvalds /* 2091da177e4SLinus Torvalds * Attempt to re-trigger the interrupt. The SA1111 contains a register 2101da177e4SLinus Torvalds * (INTSET) which claims to do this. However, in practice no amount of 2111da177e4SLinus Torvalds * manipulation of INTEN and INTSET guarantees that the interrupt will 2121da177e4SLinus Torvalds * be triggered. In fact, its very difficult, if not impossible to get 2131da177e4SLinus Torvalds * INTSET to re-trigger the interrupt. 2141da177e4SLinus Torvalds */ 2151da177e4SLinus Torvalds static int sa1111_retrigger_lowirq(unsigned int irq) 2161da177e4SLinus Torvalds { 2171da177e4SLinus Torvalds unsigned int mask = SA1111_IRQMASK_LO(irq); 2181da177e4SLinus Torvalds void __iomem *mapbase = get_irq_chipdata(irq); 2191da177e4SLinus Torvalds unsigned long ip0; 2201da177e4SLinus Torvalds int i; 2211da177e4SLinus Torvalds 2221da177e4SLinus Torvalds ip0 = sa1111_readl(mapbase + SA1111_INTPOL0); 2231da177e4SLinus Torvalds for (i = 0; i < 8; i++) { 2241da177e4SLinus Torvalds sa1111_writel(ip0 ^ mask, mapbase + SA1111_INTPOL0); 2251da177e4SLinus Torvalds sa1111_writel(ip0, mapbase + SA1111_INTPOL0); 2261da177e4SLinus Torvalds if (sa1111_readl(mapbase + SA1111_INTSTATCLR1) & mask) 2271da177e4SLinus Torvalds break; 2281da177e4SLinus Torvalds } 2291da177e4SLinus Torvalds 2301da177e4SLinus Torvalds if (i == 8) 2311da177e4SLinus Torvalds printk(KERN_ERR "Danger Will Robinson: failed to " 2321da177e4SLinus Torvalds "re-trigger IRQ%d\n", irq); 2331da177e4SLinus Torvalds return i == 8 ? -1 : 0; 2341da177e4SLinus Torvalds } 2351da177e4SLinus Torvalds 2361da177e4SLinus Torvalds static int sa1111_type_lowirq(unsigned int irq, unsigned int flags) 2371da177e4SLinus Torvalds { 2381da177e4SLinus Torvalds unsigned int mask = SA1111_IRQMASK_LO(irq); 2391da177e4SLinus Torvalds void __iomem *mapbase = get_irq_chipdata(irq); 2401da177e4SLinus Torvalds unsigned long ip0; 2411da177e4SLinus Torvalds 2421da177e4SLinus Torvalds if (flags == IRQT_PROBE) 2431da177e4SLinus Torvalds return 0; 2441da177e4SLinus Torvalds 2451da177e4SLinus Torvalds if ((!(flags & __IRQT_RISEDGE) ^ !(flags & __IRQT_FALEDGE)) == 0) 2461da177e4SLinus Torvalds return -EINVAL; 2471da177e4SLinus Torvalds 2481da177e4SLinus Torvalds ip0 = sa1111_readl(mapbase + SA1111_INTPOL0); 2491da177e4SLinus Torvalds if (flags & __IRQT_RISEDGE) 2501da177e4SLinus Torvalds ip0 &= ~mask; 2511da177e4SLinus Torvalds else 2521da177e4SLinus Torvalds ip0 |= mask; 2531da177e4SLinus Torvalds sa1111_writel(ip0, mapbase + SA1111_INTPOL0); 2541da177e4SLinus Torvalds sa1111_writel(ip0, mapbase + SA1111_WAKEPOL0); 2551da177e4SLinus Torvalds 2561da177e4SLinus Torvalds return 0; 2571da177e4SLinus Torvalds } 2581da177e4SLinus Torvalds 2591da177e4SLinus Torvalds static int sa1111_wake_lowirq(unsigned int irq, unsigned int on) 2601da177e4SLinus Torvalds { 2611da177e4SLinus Torvalds unsigned int mask = SA1111_IRQMASK_LO(irq); 2621da177e4SLinus Torvalds void __iomem *mapbase = get_irq_chipdata(irq); 2631da177e4SLinus Torvalds unsigned long we0; 2641da177e4SLinus Torvalds 2651da177e4SLinus Torvalds we0 = sa1111_readl(mapbase + SA1111_WAKEEN0); 2661da177e4SLinus Torvalds if (on) 2671da177e4SLinus Torvalds we0 |= mask; 2681da177e4SLinus Torvalds else 2691da177e4SLinus Torvalds we0 &= ~mask; 2701da177e4SLinus Torvalds sa1111_writel(we0, mapbase + SA1111_WAKEEN0); 2711da177e4SLinus Torvalds 2721da177e4SLinus Torvalds return 0; 2731da177e4SLinus Torvalds } 2741da177e4SLinus Torvalds 27538c677cbSDavid Brownell static struct irq_chip sa1111_low_chip = { 27638c677cbSDavid Brownell .name = "SA1111-l", 2771da177e4SLinus Torvalds .ack = sa1111_ack_irq, 2781da177e4SLinus Torvalds .mask = sa1111_mask_lowirq, 2791da177e4SLinus Torvalds .unmask = sa1111_unmask_lowirq, 2801da177e4SLinus Torvalds .retrigger = sa1111_retrigger_lowirq, 2817801907bSRussell King .set_type = sa1111_type_lowirq, 2827801907bSRussell King .set_wake = sa1111_wake_lowirq, 2831da177e4SLinus Torvalds }; 2841da177e4SLinus Torvalds 2851da177e4SLinus Torvalds static void sa1111_mask_highirq(unsigned int irq) 2861da177e4SLinus Torvalds { 2871da177e4SLinus Torvalds void __iomem *mapbase = get_irq_chipdata(irq); 2881da177e4SLinus Torvalds unsigned long ie1; 2891da177e4SLinus Torvalds 2901da177e4SLinus Torvalds ie1 = sa1111_readl(mapbase + SA1111_INTEN1); 2911da177e4SLinus Torvalds ie1 &= ~SA1111_IRQMASK_HI(irq); 2921da177e4SLinus Torvalds sa1111_writel(ie1, mapbase + SA1111_INTEN1); 2931da177e4SLinus Torvalds } 2941da177e4SLinus Torvalds 2951da177e4SLinus Torvalds static void sa1111_unmask_highirq(unsigned int irq) 2961da177e4SLinus Torvalds { 2971da177e4SLinus Torvalds void __iomem *mapbase = get_irq_chipdata(irq); 2981da177e4SLinus Torvalds unsigned long ie1; 2991da177e4SLinus Torvalds 3001da177e4SLinus Torvalds ie1 = sa1111_readl(mapbase + SA1111_INTEN1); 3011da177e4SLinus Torvalds ie1 |= SA1111_IRQMASK_HI(irq); 3021da177e4SLinus Torvalds sa1111_writel(ie1, mapbase + SA1111_INTEN1); 3031da177e4SLinus Torvalds } 3041da177e4SLinus Torvalds 3051da177e4SLinus Torvalds /* 3061da177e4SLinus Torvalds * Attempt to re-trigger the interrupt. The SA1111 contains a register 3071da177e4SLinus Torvalds * (INTSET) which claims to do this. However, in practice no amount of 3081da177e4SLinus Torvalds * manipulation of INTEN and INTSET guarantees that the interrupt will 3091da177e4SLinus Torvalds * be triggered. In fact, its very difficult, if not impossible to get 3101da177e4SLinus Torvalds * INTSET to re-trigger the interrupt. 3111da177e4SLinus Torvalds */ 3121da177e4SLinus Torvalds static int sa1111_retrigger_highirq(unsigned int irq) 3131da177e4SLinus Torvalds { 3141da177e4SLinus Torvalds unsigned int mask = SA1111_IRQMASK_HI(irq); 3151da177e4SLinus Torvalds void __iomem *mapbase = get_irq_chipdata(irq); 3161da177e4SLinus Torvalds unsigned long ip1; 3171da177e4SLinus Torvalds int i; 3181da177e4SLinus Torvalds 3191da177e4SLinus Torvalds ip1 = sa1111_readl(mapbase + SA1111_INTPOL1); 3201da177e4SLinus Torvalds for (i = 0; i < 8; i++) { 3211da177e4SLinus Torvalds sa1111_writel(ip1 ^ mask, mapbase + SA1111_INTPOL1); 3221da177e4SLinus Torvalds sa1111_writel(ip1, mapbase + SA1111_INTPOL1); 3231da177e4SLinus Torvalds if (sa1111_readl(mapbase + SA1111_INTSTATCLR1) & mask) 3241da177e4SLinus Torvalds break; 3251da177e4SLinus Torvalds } 3261da177e4SLinus Torvalds 3271da177e4SLinus Torvalds if (i == 8) 3281da177e4SLinus Torvalds printk(KERN_ERR "Danger Will Robinson: failed to " 3291da177e4SLinus Torvalds "re-trigger IRQ%d\n", irq); 3301da177e4SLinus Torvalds return i == 8 ? -1 : 0; 3311da177e4SLinus Torvalds } 3321da177e4SLinus Torvalds 3331da177e4SLinus Torvalds static int sa1111_type_highirq(unsigned int irq, unsigned int flags) 3341da177e4SLinus Torvalds { 3351da177e4SLinus Torvalds unsigned int mask = SA1111_IRQMASK_HI(irq); 3361da177e4SLinus Torvalds void __iomem *mapbase = get_irq_chipdata(irq); 3371da177e4SLinus Torvalds unsigned long ip1; 3381da177e4SLinus Torvalds 3391da177e4SLinus Torvalds if (flags == IRQT_PROBE) 3401da177e4SLinus Torvalds return 0; 3411da177e4SLinus Torvalds 3421da177e4SLinus Torvalds if ((!(flags & __IRQT_RISEDGE) ^ !(flags & __IRQT_FALEDGE)) == 0) 3431da177e4SLinus Torvalds return -EINVAL; 3441da177e4SLinus Torvalds 3451da177e4SLinus Torvalds ip1 = sa1111_readl(mapbase + SA1111_INTPOL1); 3461da177e4SLinus Torvalds if (flags & __IRQT_RISEDGE) 3471da177e4SLinus Torvalds ip1 &= ~mask; 3481da177e4SLinus Torvalds else 3491da177e4SLinus Torvalds ip1 |= mask; 3501da177e4SLinus Torvalds sa1111_writel(ip1, mapbase + SA1111_INTPOL1); 3511da177e4SLinus Torvalds sa1111_writel(ip1, mapbase + SA1111_WAKEPOL1); 3521da177e4SLinus Torvalds 3531da177e4SLinus Torvalds return 0; 3541da177e4SLinus Torvalds } 3551da177e4SLinus Torvalds 3561da177e4SLinus Torvalds static int sa1111_wake_highirq(unsigned int irq, unsigned int on) 3571da177e4SLinus Torvalds { 3581da177e4SLinus Torvalds unsigned int mask = SA1111_IRQMASK_HI(irq); 3591da177e4SLinus Torvalds void __iomem *mapbase = get_irq_chipdata(irq); 3601da177e4SLinus Torvalds unsigned long we1; 3611da177e4SLinus Torvalds 3621da177e4SLinus Torvalds we1 = sa1111_readl(mapbase + SA1111_WAKEEN1); 3631da177e4SLinus Torvalds if (on) 3641da177e4SLinus Torvalds we1 |= mask; 3651da177e4SLinus Torvalds else 3661da177e4SLinus Torvalds we1 &= ~mask; 3671da177e4SLinus Torvalds sa1111_writel(we1, mapbase + SA1111_WAKEEN1); 3681da177e4SLinus Torvalds 3691da177e4SLinus Torvalds return 0; 3701da177e4SLinus Torvalds } 3711da177e4SLinus Torvalds 37238c677cbSDavid Brownell static struct irq_chip sa1111_high_chip = { 37338c677cbSDavid Brownell .name = "SA1111-h", 3741da177e4SLinus Torvalds .ack = sa1111_ack_irq, 3751da177e4SLinus Torvalds .mask = sa1111_mask_highirq, 3761da177e4SLinus Torvalds .unmask = sa1111_unmask_highirq, 3771da177e4SLinus Torvalds .retrigger = sa1111_retrigger_highirq, 3787801907bSRussell King .set_type = sa1111_type_highirq, 3797801907bSRussell King .set_wake = sa1111_wake_highirq, 3801da177e4SLinus Torvalds }; 3811da177e4SLinus Torvalds 3821da177e4SLinus Torvalds static void sa1111_setup_irq(struct sa1111 *sachip) 3831da177e4SLinus Torvalds { 3841da177e4SLinus Torvalds void __iomem *irqbase = sachip->base + SA1111_INTC; 3851da177e4SLinus Torvalds unsigned int irq; 3861da177e4SLinus Torvalds 3871da177e4SLinus Torvalds /* 3881da177e4SLinus Torvalds * We're guaranteed that this region hasn't been taken. 3891da177e4SLinus Torvalds */ 3901da177e4SLinus Torvalds request_mem_region(sachip->phys + SA1111_INTC, 512, "irq"); 3911da177e4SLinus Torvalds 3921da177e4SLinus Torvalds /* disable all IRQs */ 3931da177e4SLinus Torvalds sa1111_writel(0, irqbase + SA1111_INTEN0); 3941da177e4SLinus Torvalds sa1111_writel(0, irqbase + SA1111_INTEN1); 3951da177e4SLinus Torvalds sa1111_writel(0, irqbase + SA1111_WAKEEN0); 3961da177e4SLinus Torvalds sa1111_writel(0, irqbase + SA1111_WAKEEN1); 3971da177e4SLinus Torvalds 3981da177e4SLinus Torvalds /* 3991da177e4SLinus Torvalds * detect on rising edge. Note: Feb 2001 Errata for SA1111 4001da177e4SLinus Torvalds * specifies that S0ReadyInt and S1ReadyInt should be '1'. 4011da177e4SLinus Torvalds */ 4021da177e4SLinus Torvalds sa1111_writel(0, irqbase + SA1111_INTPOL0); 4031da177e4SLinus Torvalds sa1111_writel(SA1111_IRQMASK_HI(IRQ_S0_READY_NINT) | 4041da177e4SLinus Torvalds SA1111_IRQMASK_HI(IRQ_S1_READY_NINT), 4051da177e4SLinus Torvalds irqbase + SA1111_INTPOL1); 4061da177e4SLinus Torvalds 4071da177e4SLinus Torvalds /* clear all IRQs */ 4081da177e4SLinus Torvalds sa1111_writel(~0, irqbase + SA1111_INTSTATCLR0); 4091da177e4SLinus Torvalds sa1111_writel(~0, irqbase + SA1111_INTSTATCLR1); 4101da177e4SLinus Torvalds 4111da177e4SLinus Torvalds for (irq = IRQ_GPAIN0; irq <= SSPROR; irq++) { 4121da177e4SLinus Torvalds set_irq_chip(irq, &sa1111_low_chip); 4131da177e4SLinus Torvalds set_irq_chipdata(irq, irqbase); 4141da177e4SLinus Torvalds set_irq_handler(irq, do_edge_IRQ); 4151da177e4SLinus Torvalds set_irq_flags(irq, IRQF_VALID | IRQF_PROBE); 4161da177e4SLinus Torvalds } 4171da177e4SLinus Torvalds 4181da177e4SLinus Torvalds for (irq = AUDXMTDMADONEA; irq <= IRQ_S1_BVD1_STSCHG; irq++) { 4191da177e4SLinus Torvalds set_irq_chip(irq, &sa1111_high_chip); 4201da177e4SLinus Torvalds set_irq_chipdata(irq, irqbase); 4211da177e4SLinus Torvalds set_irq_handler(irq, do_edge_IRQ); 4221da177e4SLinus Torvalds set_irq_flags(irq, IRQF_VALID | IRQF_PROBE); 4231da177e4SLinus Torvalds } 4241da177e4SLinus Torvalds 4251da177e4SLinus Torvalds /* 4261da177e4SLinus Torvalds * Register SA1111 interrupt 4271da177e4SLinus Torvalds */ 4281da177e4SLinus Torvalds set_irq_type(sachip->irq, IRQT_RISING); 4291da177e4SLinus Torvalds set_irq_data(sachip->irq, irqbase); 4301da177e4SLinus Torvalds set_irq_chained_handler(sachip->irq, sa1111_irq_handler); 4311da177e4SLinus Torvalds } 4321da177e4SLinus Torvalds 4331da177e4SLinus Torvalds /* 4341da177e4SLinus Torvalds * Bring the SA1111 out of reset. This requires a set procedure: 4351da177e4SLinus Torvalds * 1. nRESET asserted (by hardware) 4361da177e4SLinus Torvalds * 2. CLK turned on from SA1110 4371da177e4SLinus Torvalds * 3. nRESET deasserted 4381da177e4SLinus Torvalds * 4. VCO turned on, PLL_BYPASS turned off 4391da177e4SLinus Torvalds * 5. Wait lock time, then assert RCLKEn 4401da177e4SLinus Torvalds * 7. PCR set to allow clocking of individual functions 4411da177e4SLinus Torvalds * 4421da177e4SLinus Torvalds * Until we've done this, the only registers we can access are: 4431da177e4SLinus Torvalds * SBI_SKCR 4441da177e4SLinus Torvalds * SBI_SMCR 4451da177e4SLinus Torvalds * SBI_SKID 4461da177e4SLinus Torvalds */ 4471da177e4SLinus Torvalds static void sa1111_wake(struct sa1111 *sachip) 4481da177e4SLinus Torvalds { 4491da177e4SLinus Torvalds unsigned long flags, r; 4501da177e4SLinus Torvalds 4511da177e4SLinus Torvalds spin_lock_irqsave(&sachip->lock, flags); 4521da177e4SLinus Torvalds 45397d654f8SRussell King clk_enable(sachip->clk); 4541da177e4SLinus Torvalds 4551da177e4SLinus Torvalds /* 4561da177e4SLinus Torvalds * Turn VCO on, and disable PLL Bypass. 4571da177e4SLinus Torvalds */ 4581da177e4SLinus Torvalds r = sa1111_readl(sachip->base + SA1111_SKCR); 4591da177e4SLinus Torvalds r &= ~SKCR_VCO_OFF; 4601da177e4SLinus Torvalds sa1111_writel(r, sachip->base + SA1111_SKCR); 4611da177e4SLinus Torvalds r |= SKCR_PLL_BYPASS | SKCR_OE_EN; 4621da177e4SLinus Torvalds sa1111_writel(r, sachip->base + SA1111_SKCR); 4631da177e4SLinus Torvalds 4641da177e4SLinus Torvalds /* 4651da177e4SLinus Torvalds * Wait lock time. SA1111 manual _doesn't_ 4661da177e4SLinus Torvalds * specify a figure for this! We choose 100us. 4671da177e4SLinus Torvalds */ 4681da177e4SLinus Torvalds udelay(100); 4691da177e4SLinus Torvalds 4701da177e4SLinus Torvalds /* 4711da177e4SLinus Torvalds * Enable RCLK. We also ensure that RDYEN is set. 4721da177e4SLinus Torvalds */ 4731da177e4SLinus Torvalds r |= SKCR_RCLKEN | SKCR_RDYEN; 4741da177e4SLinus Torvalds sa1111_writel(r, sachip->base + SA1111_SKCR); 4751da177e4SLinus Torvalds 4761da177e4SLinus Torvalds /* 4771da177e4SLinus Torvalds * Wait 14 RCLK cycles for the chip to finish coming out 4781da177e4SLinus Torvalds * of reset. (RCLK=24MHz). This is 590ns. 4791da177e4SLinus Torvalds */ 4801da177e4SLinus Torvalds udelay(1); 4811da177e4SLinus Torvalds 4821da177e4SLinus Torvalds /* 4831da177e4SLinus Torvalds * Ensure all clocks are initially off. 4841da177e4SLinus Torvalds */ 4851da177e4SLinus Torvalds sa1111_writel(0, sachip->base + SA1111_SKPCR); 4861da177e4SLinus Torvalds 4871da177e4SLinus Torvalds spin_unlock_irqrestore(&sachip->lock, flags); 4881da177e4SLinus Torvalds } 4891da177e4SLinus Torvalds 4901da177e4SLinus Torvalds #ifdef CONFIG_ARCH_SA1100 4911da177e4SLinus Torvalds 4921da177e4SLinus Torvalds static u32 sa1111_dma_mask[] = { 4931da177e4SLinus Torvalds ~0, 4941da177e4SLinus Torvalds ~(1 << 20), 4951da177e4SLinus Torvalds ~(1 << 23), 4961da177e4SLinus Torvalds ~(1 << 24), 4971da177e4SLinus Torvalds ~(1 << 25), 4981da177e4SLinus Torvalds ~(1 << 20), 4991da177e4SLinus Torvalds ~(1 << 20), 5001da177e4SLinus Torvalds 0, 5011da177e4SLinus Torvalds }; 5021da177e4SLinus Torvalds 5031da177e4SLinus Torvalds /* 5041da177e4SLinus Torvalds * Configure the SA1111 shared memory controller. 5051da177e4SLinus Torvalds */ 5061da177e4SLinus Torvalds void 5071da177e4SLinus Torvalds sa1111_configure_smc(struct sa1111 *sachip, int sdram, unsigned int drac, 5081da177e4SLinus Torvalds unsigned int cas_latency) 5091da177e4SLinus Torvalds { 5101da177e4SLinus Torvalds unsigned int smcr = SMCR_DTIM | SMCR_MBGE | FInsrt(drac, SMCR_DRAC); 5111da177e4SLinus Torvalds 5121da177e4SLinus Torvalds if (cas_latency == 3) 5131da177e4SLinus Torvalds smcr |= SMCR_CLAT; 5141da177e4SLinus Torvalds 5151da177e4SLinus Torvalds sa1111_writel(smcr, sachip->base + SA1111_SMCR); 5161da177e4SLinus Torvalds 5171da177e4SLinus Torvalds /* 5181da177e4SLinus Torvalds * Now clear the bits in the DMA mask to work around the SA1111 5191da177e4SLinus Torvalds * DMA erratum (Intel StrongARM SA-1111 Microprocessor Companion 5201da177e4SLinus Torvalds * Chip Specification Update, June 2000, Erratum #7). 5211da177e4SLinus Torvalds */ 5221da177e4SLinus Torvalds if (sachip->dev->dma_mask) 5231da177e4SLinus Torvalds *sachip->dev->dma_mask &= sa1111_dma_mask[drac >> 2]; 5241da177e4SLinus Torvalds 5251da177e4SLinus Torvalds sachip->dev->coherent_dma_mask &= sa1111_dma_mask[drac >> 2]; 5261da177e4SLinus Torvalds } 5271da177e4SLinus Torvalds 5281da177e4SLinus Torvalds #endif 5291da177e4SLinus Torvalds 5301da177e4SLinus Torvalds static void sa1111_dev_release(struct device *_dev) 5311da177e4SLinus Torvalds { 5321da177e4SLinus Torvalds struct sa1111_dev *dev = SA1111_DEV(_dev); 5331da177e4SLinus Torvalds 5341da177e4SLinus Torvalds release_resource(&dev->res); 5351da177e4SLinus Torvalds kfree(dev); 5361da177e4SLinus Torvalds } 5371da177e4SLinus Torvalds 5381da177e4SLinus Torvalds static int 5391da177e4SLinus Torvalds sa1111_init_one_child(struct sa1111 *sachip, struct resource *parent, 5401da177e4SLinus Torvalds struct sa1111_dev_info *info) 5411da177e4SLinus Torvalds { 5421da177e4SLinus Torvalds struct sa1111_dev *dev; 5431da177e4SLinus Torvalds int ret; 5441da177e4SLinus Torvalds 545d2a02b93SRussell King dev = kzalloc(sizeof(struct sa1111_dev), GFP_KERNEL); 5461da177e4SLinus Torvalds if (!dev) { 5471da177e4SLinus Torvalds ret = -ENOMEM; 5481da177e4SLinus Torvalds goto out; 5491da177e4SLinus Torvalds } 5501da177e4SLinus Torvalds 5511da177e4SLinus Torvalds snprintf(dev->dev.bus_id, sizeof(dev->dev.bus_id), 5521da177e4SLinus Torvalds "%4.4lx", info->offset); 5531da177e4SLinus Torvalds 5541da177e4SLinus Torvalds dev->devid = info->devid; 5551da177e4SLinus Torvalds dev->dev.parent = sachip->dev; 5561da177e4SLinus Torvalds dev->dev.bus = &sa1111_bus_type; 5571da177e4SLinus Torvalds dev->dev.release = sa1111_dev_release; 5581da177e4SLinus Torvalds dev->dev.coherent_dma_mask = sachip->dev->coherent_dma_mask; 5591da177e4SLinus Torvalds dev->res.start = sachip->phys + info->offset; 5601da177e4SLinus Torvalds dev->res.end = dev->res.start + 511; 5611da177e4SLinus Torvalds dev->res.name = dev->dev.bus_id; 5621da177e4SLinus Torvalds dev->res.flags = IORESOURCE_MEM; 5631da177e4SLinus Torvalds dev->mapbase = sachip->base + info->offset; 5641da177e4SLinus Torvalds dev->skpcr_mask = info->skpcr_mask; 5651da177e4SLinus Torvalds memmove(dev->irq, info->irq, sizeof(dev->irq)); 5661da177e4SLinus Torvalds 5671da177e4SLinus Torvalds ret = request_resource(parent, &dev->res); 5681da177e4SLinus Torvalds if (ret) { 5691da177e4SLinus Torvalds printk("SA1111: failed to allocate resource for %s\n", 5701da177e4SLinus Torvalds dev->res.name); 5711da177e4SLinus Torvalds kfree(dev); 5721da177e4SLinus Torvalds goto out; 5731da177e4SLinus Torvalds } 5741da177e4SLinus Torvalds 5751da177e4SLinus Torvalds 5761da177e4SLinus Torvalds ret = device_register(&dev->dev); 5771da177e4SLinus Torvalds if (ret) { 5781da177e4SLinus Torvalds release_resource(&dev->res); 5791da177e4SLinus Torvalds kfree(dev); 5801da177e4SLinus Torvalds goto out; 5811da177e4SLinus Torvalds } 5821da177e4SLinus Torvalds 5831da177e4SLinus Torvalds /* 5841da177e4SLinus Torvalds * If the parent device has a DMA mask associated with it, 5851da177e4SLinus Torvalds * propagate it down to the children. 5861da177e4SLinus Torvalds */ 5871da177e4SLinus Torvalds if (sachip->dev->dma_mask) { 5881da177e4SLinus Torvalds dev->dma_mask = *sachip->dev->dma_mask; 5891da177e4SLinus Torvalds dev->dev.dma_mask = &dev->dma_mask; 5901da177e4SLinus Torvalds 5911da177e4SLinus Torvalds if (dev->dma_mask != 0xffffffffUL) { 5921da177e4SLinus Torvalds ret = dmabounce_register_dev(&dev->dev, 1024, 4096); 5931da177e4SLinus Torvalds if (ret) { 5941da177e4SLinus Torvalds printk("SA1111: Failed to register %s with dmabounce", dev->dev.bus_id); 5951da177e4SLinus Torvalds device_unregister(&dev->dev); 5961da177e4SLinus Torvalds } 5971da177e4SLinus Torvalds } 5981da177e4SLinus Torvalds } 5991da177e4SLinus Torvalds 6001da177e4SLinus Torvalds out: 6011da177e4SLinus Torvalds return ret; 6021da177e4SLinus Torvalds } 6031da177e4SLinus Torvalds 6041da177e4SLinus Torvalds /** 6051da177e4SLinus Torvalds * sa1111_probe - probe for a single SA1111 chip. 6061da177e4SLinus Torvalds * @phys_addr: physical address of device. 6071da177e4SLinus Torvalds * 6081da177e4SLinus Torvalds * Probe for a SA1111 chip. This must be called 6091da177e4SLinus Torvalds * before any other SA1111-specific code. 6101da177e4SLinus Torvalds * 6111da177e4SLinus Torvalds * Returns: 6121da177e4SLinus Torvalds * %-ENODEV device not found. 6131da177e4SLinus Torvalds * %-EBUSY physical address already marked in-use. 6141da177e4SLinus Torvalds * %0 successful. 6151da177e4SLinus Torvalds */ 6161da177e4SLinus Torvalds static int 6171da177e4SLinus Torvalds __sa1111_probe(struct device *me, struct resource *mem, int irq) 6181da177e4SLinus Torvalds { 6191da177e4SLinus Torvalds struct sa1111 *sachip; 6201da177e4SLinus Torvalds unsigned long id; 621416112f8SDavid Brownell unsigned int has_devs; 6221da177e4SLinus Torvalds int i, ret = -ENODEV; 6231da177e4SLinus Torvalds 624d2a02b93SRussell King sachip = kzalloc(sizeof(struct sa1111), GFP_KERNEL); 6251da177e4SLinus Torvalds if (!sachip) 6261da177e4SLinus Torvalds return -ENOMEM; 6271da177e4SLinus Torvalds 62897d654f8SRussell King sachip->clk = clk_get(me, "GPIO27_CLK"); 62997d654f8SRussell King if (!sachip->clk) { 63097d654f8SRussell King ret = PTR_ERR(sachip->clk); 63197d654f8SRussell King goto err_free; 63297d654f8SRussell King } 63397d654f8SRussell King 6341da177e4SLinus Torvalds spin_lock_init(&sachip->lock); 6351da177e4SLinus Torvalds 6361da177e4SLinus Torvalds sachip->dev = me; 6371da177e4SLinus Torvalds dev_set_drvdata(sachip->dev, sachip); 6381da177e4SLinus Torvalds 6391da177e4SLinus Torvalds sachip->phys = mem->start; 6401da177e4SLinus Torvalds sachip->irq = irq; 6411da177e4SLinus Torvalds 6421da177e4SLinus Torvalds /* 6431da177e4SLinus Torvalds * Map the whole region. This also maps the 6441da177e4SLinus Torvalds * registers for our children. 6451da177e4SLinus Torvalds */ 6461da177e4SLinus Torvalds sachip->base = ioremap(mem->start, PAGE_SIZE * 2); 6471da177e4SLinus Torvalds if (!sachip->base) { 6481da177e4SLinus Torvalds ret = -ENOMEM; 64997d654f8SRussell King goto err_clkput; 6501da177e4SLinus Torvalds } 6511da177e4SLinus Torvalds 6521da177e4SLinus Torvalds /* 6531da177e4SLinus Torvalds * Probe for the chip. Only touch the SBI registers. 6541da177e4SLinus Torvalds */ 6551da177e4SLinus Torvalds id = sa1111_readl(sachip->base + SA1111_SKID); 6561da177e4SLinus Torvalds if ((id & SKID_ID_MASK) != SKID_SA1111_ID) { 6571da177e4SLinus Torvalds printk(KERN_DEBUG "SA1111 not detected: ID = %08lx\n", id); 6581da177e4SLinus Torvalds ret = -ENODEV; 65997d654f8SRussell King goto err_unmap; 6601da177e4SLinus Torvalds } 6611da177e4SLinus Torvalds 6621da177e4SLinus Torvalds printk(KERN_INFO "SA1111 Microprocessor Companion Chip: " 6631da177e4SLinus Torvalds "silicon revision %lx, metal revision %lx\n", 6641da177e4SLinus Torvalds (id & SKID_SIREV_MASK)>>4, (id & SKID_MTREV_MASK)); 6651da177e4SLinus Torvalds 6661da177e4SLinus Torvalds /* 6671da177e4SLinus Torvalds * We found it. Wake the chip up, and initialise. 6681da177e4SLinus Torvalds */ 6691da177e4SLinus Torvalds sa1111_wake(sachip); 6701da177e4SLinus Torvalds 6711da177e4SLinus Torvalds #ifdef CONFIG_ARCH_SA1100 672416112f8SDavid Brownell { 673416112f8SDavid Brownell unsigned int val; 674416112f8SDavid Brownell 6751da177e4SLinus Torvalds /* 6761da177e4SLinus Torvalds * The SDRAM configuration of the SA1110 and the SA1111 must 6771da177e4SLinus Torvalds * match. This is very important to ensure that SA1111 accesses 6781da177e4SLinus Torvalds * don't corrupt the SDRAM. Note that this ungates the SA1111's 6791da177e4SLinus Torvalds * MBGNT signal, so we must have called sa1110_mb_disable() 6801da177e4SLinus Torvalds * beforehand. 6811da177e4SLinus Torvalds */ 6821da177e4SLinus Torvalds sa1111_configure_smc(sachip, 1, 6831da177e4SLinus Torvalds FExtr(MDCNFG, MDCNFG_SA1110_DRAC0), 6841da177e4SLinus Torvalds FExtr(MDCNFG, MDCNFG_SA1110_TDL0)); 6851da177e4SLinus Torvalds 6861da177e4SLinus Torvalds /* 6871da177e4SLinus Torvalds * We only need to turn on DCLK whenever we want to use the 6881da177e4SLinus Torvalds * DMA. It can otherwise be held firmly in the off position. 6891da177e4SLinus Torvalds * (currently, we always enable it.) 6901da177e4SLinus Torvalds */ 6911da177e4SLinus Torvalds val = sa1111_readl(sachip->base + SA1111_SKPCR); 6921da177e4SLinus Torvalds sa1111_writel(val | SKPCR_DCLKEN, sachip->base + SA1111_SKPCR); 6931da177e4SLinus Torvalds 6941da177e4SLinus Torvalds /* 6951da177e4SLinus Torvalds * Enable the SA1110 memory bus request and grant signals. 6961da177e4SLinus Torvalds */ 6971da177e4SLinus Torvalds sa1110_mb_enable(); 698416112f8SDavid Brownell } 6991da177e4SLinus Torvalds #endif 7001da177e4SLinus Torvalds 7011da177e4SLinus Torvalds /* 7021da177e4SLinus Torvalds * The interrupt controller must be initialised before any 7031da177e4SLinus Torvalds * other device to ensure that the interrupts are available. 7041da177e4SLinus Torvalds */ 7051da177e4SLinus Torvalds if (sachip->irq != NO_IRQ) 7061da177e4SLinus Torvalds sa1111_setup_irq(sachip); 7071da177e4SLinus Torvalds 7081da177e4SLinus Torvalds g_sa1111 = sachip; 7091da177e4SLinus Torvalds 7101da177e4SLinus Torvalds has_devs = ~0; 7111da177e4SLinus Torvalds if (machine_is_assabet() || machine_is_jornada720() || 7121da177e4SLinus Torvalds machine_is_badge4()) 7131da177e4SLinus Torvalds has_devs &= ~(1 << 4); 7141da177e4SLinus Torvalds else 7151da177e4SLinus Torvalds has_devs &= ~(1 << 1); 7161da177e4SLinus Torvalds 7171da177e4SLinus Torvalds for (i = 0; i < ARRAY_SIZE(sa1111_devices); i++) 7181da177e4SLinus Torvalds if (has_devs & (1 << i)) 7191da177e4SLinus Torvalds sa1111_init_one_child(sachip, mem, &sa1111_devices[i]); 7201da177e4SLinus Torvalds 7211da177e4SLinus Torvalds return 0; 7221da177e4SLinus Torvalds 72397d654f8SRussell King err_unmap: 7241da177e4SLinus Torvalds iounmap(sachip->base); 72597d654f8SRussell King err_clkput: 72697d654f8SRussell King clk_put(sachip->clk); 72797d654f8SRussell King err_free: 7281da177e4SLinus Torvalds kfree(sachip); 7291da177e4SLinus Torvalds return ret; 7301da177e4SLinus Torvalds } 7311da177e4SLinus Torvalds 732522c37b9SRussell King static int sa1111_remove_one(struct device *dev, void *data) 733522c37b9SRussell King { 734522c37b9SRussell King device_unregister(dev); 735522c37b9SRussell King return 0; 736522c37b9SRussell King } 737522c37b9SRussell King 7381da177e4SLinus Torvalds static void __sa1111_remove(struct sa1111 *sachip) 7391da177e4SLinus Torvalds { 7401da177e4SLinus Torvalds void __iomem *irqbase = sachip->base + SA1111_INTC; 7411da177e4SLinus Torvalds 742522c37b9SRussell King device_for_each_child(sachip->dev, NULL, sa1111_remove_one); 7431da177e4SLinus Torvalds 7441da177e4SLinus Torvalds /* disable all IRQs */ 7451da177e4SLinus Torvalds sa1111_writel(0, irqbase + SA1111_INTEN0); 7461da177e4SLinus Torvalds sa1111_writel(0, irqbase + SA1111_INTEN1); 7471da177e4SLinus Torvalds sa1111_writel(0, irqbase + SA1111_WAKEEN0); 7481da177e4SLinus Torvalds sa1111_writel(0, irqbase + SA1111_WAKEEN1); 7491da177e4SLinus Torvalds 75097d654f8SRussell King clk_disable(sachip->clk); 75197d654f8SRussell King 7521da177e4SLinus Torvalds if (sachip->irq != NO_IRQ) { 7531da177e4SLinus Torvalds set_irq_chained_handler(sachip->irq, NULL); 7541da177e4SLinus Torvalds set_irq_data(sachip->irq, NULL); 7551da177e4SLinus Torvalds 7561da177e4SLinus Torvalds release_mem_region(sachip->phys + SA1111_INTC, 512); 7571da177e4SLinus Torvalds } 7581da177e4SLinus Torvalds 7591da177e4SLinus Torvalds iounmap(sachip->base); 76097d654f8SRussell King clk_put(sachip->clk); 7611da177e4SLinus Torvalds kfree(sachip); 7621da177e4SLinus Torvalds } 7631da177e4SLinus Torvalds 7641da177e4SLinus Torvalds /* 7651da177e4SLinus Torvalds * According to the "Intel StrongARM SA-1111 Microprocessor Companion 7661da177e4SLinus Torvalds * Chip Specification Update" (June 2000), erratum #7, there is a 7671da177e4SLinus Torvalds * significant bug in the SA1111 SDRAM shared memory controller. If 7681da177e4SLinus Torvalds * an access to a region of memory above 1MB relative to the bank base, 7691da177e4SLinus Torvalds * it is important that address bit 10 _NOT_ be asserted. Depending 7701da177e4SLinus Torvalds * on the configuration of the RAM, bit 10 may correspond to one 7711da177e4SLinus Torvalds * of several different (processor-relative) address bits. 7721da177e4SLinus Torvalds * 7731da177e4SLinus Torvalds * This routine only identifies whether or not a given DMA address 7741da177e4SLinus Torvalds * is susceptible to the bug. 7751da177e4SLinus Torvalds * 7761da177e4SLinus Torvalds * This should only get called for sa1111_device types due to the 7771da177e4SLinus Torvalds * way we configure our device dma_masks. 7781da177e4SLinus Torvalds */ 7791da177e4SLinus Torvalds int dma_needs_bounce(struct device *dev, dma_addr_t addr, size_t size) 7801da177e4SLinus Torvalds { 7811da177e4SLinus Torvalds /* 7821da177e4SLinus Torvalds * Section 4.6 of the "Intel StrongARM SA-1111 Development Module 7831da177e4SLinus Torvalds * User's Guide" mentions that jumpers R51 and R52 control the 7841da177e4SLinus Torvalds * target of SA-1111 DMA (either SDRAM bank 0 on Assabet, or 7851da177e4SLinus Torvalds * SDRAM bank 1 on Neponset). The default configuration selects 7861da177e4SLinus Torvalds * Assabet, so any address in bank 1 is necessarily invalid. 7871da177e4SLinus Torvalds */ 7881da177e4SLinus Torvalds return ((machine_is_assabet() || machine_is_pfs168()) && 7891da177e4SLinus Torvalds (addr >= 0xc8000000 || (addr + size) >= 0xc8000000)); 7901da177e4SLinus Torvalds } 7911da177e4SLinus Torvalds 7921da177e4SLinus Torvalds struct sa1111_save_data { 7931da177e4SLinus Torvalds unsigned int skcr; 7941da177e4SLinus Torvalds unsigned int skpcr; 7951da177e4SLinus Torvalds unsigned int skcdr; 7961da177e4SLinus Torvalds unsigned char skaud; 7971da177e4SLinus Torvalds unsigned char skpwm0; 7981da177e4SLinus Torvalds unsigned char skpwm1; 7991da177e4SLinus Torvalds 8001da177e4SLinus Torvalds /* 8011da177e4SLinus Torvalds * Interrupt controller 8021da177e4SLinus Torvalds */ 8031da177e4SLinus Torvalds unsigned int intpol0; 8041da177e4SLinus Torvalds unsigned int intpol1; 8051da177e4SLinus Torvalds unsigned int inten0; 8061da177e4SLinus Torvalds unsigned int inten1; 8071da177e4SLinus Torvalds unsigned int wakepol0; 8081da177e4SLinus Torvalds unsigned int wakepol1; 8091da177e4SLinus Torvalds unsigned int wakeen0; 8101da177e4SLinus Torvalds unsigned int wakeen1; 8111da177e4SLinus Torvalds }; 8121da177e4SLinus Torvalds 8131da177e4SLinus Torvalds #ifdef CONFIG_PM 8141da177e4SLinus Torvalds 8153ae5eaecSRussell King static int sa1111_suspend(struct platform_device *dev, pm_message_t state) 8161da177e4SLinus Torvalds { 8173ae5eaecSRussell King struct sa1111 *sachip = platform_get_drvdata(dev); 8181da177e4SLinus Torvalds struct sa1111_save_data *save; 8191da177e4SLinus Torvalds unsigned long flags; 8201da177e4SLinus Torvalds unsigned int val; 8211da177e4SLinus Torvalds void __iomem *base; 8221da177e4SLinus Torvalds 8231da177e4SLinus Torvalds save = kmalloc(sizeof(struct sa1111_save_data), GFP_KERNEL); 8241da177e4SLinus Torvalds if (!save) 8251da177e4SLinus Torvalds return -ENOMEM; 8263ae5eaecSRussell King dev->dev.power.saved_state = save; 8271da177e4SLinus Torvalds 8281da177e4SLinus Torvalds spin_lock_irqsave(&sachip->lock, flags); 8291da177e4SLinus Torvalds 8301da177e4SLinus Torvalds /* 8311da177e4SLinus Torvalds * Save state. 8321da177e4SLinus Torvalds */ 8331da177e4SLinus Torvalds base = sachip->base; 8341da177e4SLinus Torvalds save->skcr = sa1111_readl(base + SA1111_SKCR); 8351da177e4SLinus Torvalds save->skpcr = sa1111_readl(base + SA1111_SKPCR); 8361da177e4SLinus Torvalds save->skcdr = sa1111_readl(base + SA1111_SKCDR); 8371da177e4SLinus Torvalds save->skaud = sa1111_readl(base + SA1111_SKAUD); 8381da177e4SLinus Torvalds save->skpwm0 = sa1111_readl(base + SA1111_SKPWM0); 8391da177e4SLinus Torvalds save->skpwm1 = sa1111_readl(base + SA1111_SKPWM1); 8401da177e4SLinus Torvalds 8411da177e4SLinus Torvalds base = sachip->base + SA1111_INTC; 8421da177e4SLinus Torvalds save->intpol0 = sa1111_readl(base + SA1111_INTPOL0); 8431da177e4SLinus Torvalds save->intpol1 = sa1111_readl(base + SA1111_INTPOL1); 8441da177e4SLinus Torvalds save->inten0 = sa1111_readl(base + SA1111_INTEN0); 8451da177e4SLinus Torvalds save->inten1 = sa1111_readl(base + SA1111_INTEN1); 8461da177e4SLinus Torvalds save->wakepol0 = sa1111_readl(base + SA1111_WAKEPOL0); 8471da177e4SLinus Torvalds save->wakepol1 = sa1111_readl(base + SA1111_WAKEPOL1); 8481da177e4SLinus Torvalds save->wakeen0 = sa1111_readl(base + SA1111_WAKEEN0); 8491da177e4SLinus Torvalds save->wakeen1 = sa1111_readl(base + SA1111_WAKEEN1); 8501da177e4SLinus Torvalds 8511da177e4SLinus Torvalds /* 8521da177e4SLinus Torvalds * Disable. 8531da177e4SLinus Torvalds */ 8541da177e4SLinus Torvalds val = sa1111_readl(sachip->base + SA1111_SKCR); 8551da177e4SLinus Torvalds sa1111_writel(val | SKCR_SLEEP, sachip->base + SA1111_SKCR); 8561da177e4SLinus Torvalds sa1111_writel(0, sachip->base + SA1111_SKPWM0); 8571da177e4SLinus Torvalds sa1111_writel(0, sachip->base + SA1111_SKPWM1); 8581da177e4SLinus Torvalds 85997d654f8SRussell King clk_disable(sachip->clk); 86097d654f8SRussell King 8611da177e4SLinus Torvalds spin_unlock_irqrestore(&sachip->lock, flags); 8621da177e4SLinus Torvalds 8631da177e4SLinus Torvalds return 0; 8641da177e4SLinus Torvalds } 8651da177e4SLinus Torvalds 8661da177e4SLinus Torvalds /* 8671da177e4SLinus Torvalds * sa1111_resume - Restore the SA1111 device state. 8681da177e4SLinus Torvalds * @dev: device to restore 8691da177e4SLinus Torvalds * 8701da177e4SLinus Torvalds * Restore the general state of the SA1111; clock control and 8711da177e4SLinus Torvalds * interrupt controller. Other parts of the SA1111 must be 8721da177e4SLinus Torvalds * restored by their respective drivers, and must be called 8731da177e4SLinus Torvalds * via LDM after this function. 8741da177e4SLinus Torvalds */ 8753ae5eaecSRussell King static int sa1111_resume(struct platform_device *dev) 8761da177e4SLinus Torvalds { 8773ae5eaecSRussell King struct sa1111 *sachip = platform_get_drvdata(dev); 8781da177e4SLinus Torvalds struct sa1111_save_data *save; 8791da177e4SLinus Torvalds unsigned long flags, id; 8801da177e4SLinus Torvalds void __iomem *base; 8811da177e4SLinus Torvalds 8823ae5eaecSRussell King save = (struct sa1111_save_data *)dev->dev.power.saved_state; 8831da177e4SLinus Torvalds if (!save) 8841da177e4SLinus Torvalds return 0; 8851da177e4SLinus Torvalds 8861da177e4SLinus Torvalds spin_lock_irqsave(&sachip->lock, flags); 8871da177e4SLinus Torvalds 8881da177e4SLinus Torvalds /* 8891da177e4SLinus Torvalds * Ensure that the SA1111 is still here. 8901da177e4SLinus Torvalds * FIXME: shouldn't do this here. 8911da177e4SLinus Torvalds */ 8921da177e4SLinus Torvalds id = sa1111_readl(sachip->base + SA1111_SKID); 8931da177e4SLinus Torvalds if ((id & SKID_ID_MASK) != SKID_SA1111_ID) { 8941da177e4SLinus Torvalds __sa1111_remove(sachip); 8953ae5eaecSRussell King platform_set_drvdata(dev, NULL); 8961da177e4SLinus Torvalds kfree(save); 8971da177e4SLinus Torvalds return 0; 8981da177e4SLinus Torvalds } 8991da177e4SLinus Torvalds 9001da177e4SLinus Torvalds /* 9011da177e4SLinus Torvalds * First of all, wake up the chip. 9021da177e4SLinus Torvalds */ 9031da177e4SLinus Torvalds sa1111_wake(sachip); 9041da177e4SLinus Torvalds sa1111_writel(0, sachip->base + SA1111_INTC + SA1111_INTEN0); 9051da177e4SLinus Torvalds sa1111_writel(0, sachip->base + SA1111_INTC + SA1111_INTEN1); 9061da177e4SLinus Torvalds 9071da177e4SLinus Torvalds base = sachip->base; 9081da177e4SLinus Torvalds sa1111_writel(save->skcr, base + SA1111_SKCR); 9091da177e4SLinus Torvalds sa1111_writel(save->skpcr, base + SA1111_SKPCR); 9101da177e4SLinus Torvalds sa1111_writel(save->skcdr, base + SA1111_SKCDR); 9111da177e4SLinus Torvalds sa1111_writel(save->skaud, base + SA1111_SKAUD); 9121da177e4SLinus Torvalds sa1111_writel(save->skpwm0, base + SA1111_SKPWM0); 9131da177e4SLinus Torvalds sa1111_writel(save->skpwm1, base + SA1111_SKPWM1); 9141da177e4SLinus Torvalds 9151da177e4SLinus Torvalds base = sachip->base + SA1111_INTC; 9161da177e4SLinus Torvalds sa1111_writel(save->intpol0, base + SA1111_INTPOL0); 9171da177e4SLinus Torvalds sa1111_writel(save->intpol1, base + SA1111_INTPOL1); 9181da177e4SLinus Torvalds sa1111_writel(save->inten0, base + SA1111_INTEN0); 9191da177e4SLinus Torvalds sa1111_writel(save->inten1, base + SA1111_INTEN1); 9201da177e4SLinus Torvalds sa1111_writel(save->wakepol0, base + SA1111_WAKEPOL0); 9211da177e4SLinus Torvalds sa1111_writel(save->wakepol1, base + SA1111_WAKEPOL1); 9221da177e4SLinus Torvalds sa1111_writel(save->wakeen0, base + SA1111_WAKEEN0); 9231da177e4SLinus Torvalds sa1111_writel(save->wakeen1, base + SA1111_WAKEEN1); 9241da177e4SLinus Torvalds 9251da177e4SLinus Torvalds spin_unlock_irqrestore(&sachip->lock, flags); 9261da177e4SLinus Torvalds 9273ae5eaecSRussell King dev->dev.power.saved_state = NULL; 9281da177e4SLinus Torvalds kfree(save); 9291da177e4SLinus Torvalds 9301da177e4SLinus Torvalds return 0; 9311da177e4SLinus Torvalds } 9321da177e4SLinus Torvalds 9331da177e4SLinus Torvalds #else 9341da177e4SLinus Torvalds #define sa1111_suspend NULL 9351da177e4SLinus Torvalds #define sa1111_resume NULL 9361da177e4SLinus Torvalds #endif 9371da177e4SLinus Torvalds 9383ae5eaecSRussell King static int sa1111_probe(struct platform_device *pdev) 9391da177e4SLinus Torvalds { 9401da177e4SLinus Torvalds struct resource *mem; 9411da177e4SLinus Torvalds int irq; 9421da177e4SLinus Torvalds 9431da177e4SLinus Torvalds mem = platform_get_resource(pdev, IORESOURCE_MEM, 0); 9441da177e4SLinus Torvalds if (!mem) 9451da177e4SLinus Torvalds return -EINVAL; 9461da177e4SLinus Torvalds irq = platform_get_irq(pdev, 0); 94748944738SDavid Vrabel if (irq < 0) 94848944738SDavid Vrabel return -ENXIO; 9491da177e4SLinus Torvalds 9503ae5eaecSRussell King return __sa1111_probe(&pdev->dev, mem, irq); 9511da177e4SLinus Torvalds } 9521da177e4SLinus Torvalds 9533ae5eaecSRussell King static int sa1111_remove(struct platform_device *pdev) 9541da177e4SLinus Torvalds { 9553ae5eaecSRussell King struct sa1111 *sachip = platform_get_drvdata(pdev); 9561da177e4SLinus Torvalds 9571da177e4SLinus Torvalds if (sachip) { 9581da177e4SLinus Torvalds __sa1111_remove(sachip); 9593ae5eaecSRussell King platform_set_drvdata(pdev, NULL); 9601da177e4SLinus Torvalds 9611da177e4SLinus Torvalds #ifdef CONFIG_PM 9623ae5eaecSRussell King kfree(pdev->dev.power.saved_state); 9633ae5eaecSRussell King pdev->dev.power.saved_state = NULL; 9641da177e4SLinus Torvalds #endif 9651da177e4SLinus Torvalds } 9661da177e4SLinus Torvalds 9671da177e4SLinus Torvalds return 0; 9681da177e4SLinus Torvalds } 9691da177e4SLinus Torvalds 9701da177e4SLinus Torvalds /* 9711da177e4SLinus Torvalds * Not sure if this should be on the system bus or not yet. 9721da177e4SLinus Torvalds * We really want some way to register a system device at 9731da177e4SLinus Torvalds * the per-machine level, and then have this driver pick 9741da177e4SLinus Torvalds * up the registered devices. 9751da177e4SLinus Torvalds * 9761da177e4SLinus Torvalds * We also need to handle the SDRAM configuration for 9771da177e4SLinus Torvalds * PXA250/SA1110 machine classes. 9781da177e4SLinus Torvalds */ 9793ae5eaecSRussell King static struct platform_driver sa1111_device_driver = { 9801da177e4SLinus Torvalds .probe = sa1111_probe, 9811da177e4SLinus Torvalds .remove = sa1111_remove, 9821da177e4SLinus Torvalds .suspend = sa1111_suspend, 9831da177e4SLinus Torvalds .resume = sa1111_resume, 9843ae5eaecSRussell King .driver = { 9853ae5eaecSRussell King .name = "sa1111", 9863ae5eaecSRussell King }, 9871da177e4SLinus Torvalds }; 9881da177e4SLinus Torvalds 9891da177e4SLinus Torvalds /* 9901da177e4SLinus Torvalds * Get the parent device driver (us) structure 9911da177e4SLinus Torvalds * from a child function device 9921da177e4SLinus Torvalds */ 9931da177e4SLinus Torvalds static inline struct sa1111 *sa1111_chip_driver(struct sa1111_dev *sadev) 9941da177e4SLinus Torvalds { 9951da177e4SLinus Torvalds return (struct sa1111 *)dev_get_drvdata(sadev->dev.parent); 9961da177e4SLinus Torvalds } 9971da177e4SLinus Torvalds 9981da177e4SLinus Torvalds /* 9991da177e4SLinus Torvalds * The bits in the opdiv field are non-linear. 10001da177e4SLinus Torvalds */ 10011da177e4SLinus Torvalds static unsigned char opdiv_table[] = { 1, 4, 2, 8 }; 10021da177e4SLinus Torvalds 10031da177e4SLinus Torvalds static unsigned int __sa1111_pll_clock(struct sa1111 *sachip) 10041da177e4SLinus Torvalds { 10051da177e4SLinus Torvalds unsigned int skcdr, fbdiv, ipdiv, opdiv; 10061da177e4SLinus Torvalds 10071da177e4SLinus Torvalds skcdr = sa1111_readl(sachip->base + SA1111_SKCDR); 10081da177e4SLinus Torvalds 10091da177e4SLinus Torvalds fbdiv = (skcdr & 0x007f) + 2; 10101da177e4SLinus Torvalds ipdiv = ((skcdr & 0x0f80) >> 7) + 2; 10111da177e4SLinus Torvalds opdiv = opdiv_table[(skcdr & 0x3000) >> 12]; 10121da177e4SLinus Torvalds 10131da177e4SLinus Torvalds return 3686400 * fbdiv / (ipdiv * opdiv); 10141da177e4SLinus Torvalds } 10151da177e4SLinus Torvalds 10161da177e4SLinus Torvalds /** 10171da177e4SLinus Torvalds * sa1111_pll_clock - return the current PLL clock frequency. 10181da177e4SLinus Torvalds * @sadev: SA1111 function block 10191da177e4SLinus Torvalds * 10201da177e4SLinus Torvalds * BUG: we should look at SKCR. We also blindly believe that 10211da177e4SLinus Torvalds * the chip is being fed with the 3.6864MHz clock. 10221da177e4SLinus Torvalds * 10231da177e4SLinus Torvalds * Returns the PLL clock in Hz. 10241da177e4SLinus Torvalds */ 10251da177e4SLinus Torvalds unsigned int sa1111_pll_clock(struct sa1111_dev *sadev) 10261da177e4SLinus Torvalds { 10271da177e4SLinus Torvalds struct sa1111 *sachip = sa1111_chip_driver(sadev); 10281da177e4SLinus Torvalds 10291da177e4SLinus Torvalds return __sa1111_pll_clock(sachip); 10301da177e4SLinus Torvalds } 10311da177e4SLinus Torvalds 10321da177e4SLinus Torvalds /** 10331da177e4SLinus Torvalds * sa1111_select_audio_mode - select I2S or AC link mode 10341da177e4SLinus Torvalds * @sadev: SA1111 function block 10351da177e4SLinus Torvalds * @mode: One of %SA1111_AUDIO_ACLINK or %SA1111_AUDIO_I2S 10361da177e4SLinus Torvalds * 10371da177e4SLinus Torvalds * Frob the SKCR to select AC Link mode or I2S mode for 10381da177e4SLinus Torvalds * the audio block. 10391da177e4SLinus Torvalds */ 10401da177e4SLinus Torvalds void sa1111_select_audio_mode(struct sa1111_dev *sadev, int mode) 10411da177e4SLinus Torvalds { 10421da177e4SLinus Torvalds struct sa1111 *sachip = sa1111_chip_driver(sadev); 10431da177e4SLinus Torvalds unsigned long flags; 10441da177e4SLinus Torvalds unsigned int val; 10451da177e4SLinus Torvalds 10461da177e4SLinus Torvalds spin_lock_irqsave(&sachip->lock, flags); 10471da177e4SLinus Torvalds 10481da177e4SLinus Torvalds val = sa1111_readl(sachip->base + SA1111_SKCR); 10491da177e4SLinus Torvalds if (mode == SA1111_AUDIO_I2S) { 10501da177e4SLinus Torvalds val &= ~SKCR_SELAC; 10511da177e4SLinus Torvalds } else { 10521da177e4SLinus Torvalds val |= SKCR_SELAC; 10531da177e4SLinus Torvalds } 10541da177e4SLinus Torvalds sa1111_writel(val, sachip->base + SA1111_SKCR); 10551da177e4SLinus Torvalds 10561da177e4SLinus Torvalds spin_unlock_irqrestore(&sachip->lock, flags); 10571da177e4SLinus Torvalds } 10581da177e4SLinus Torvalds 10591da177e4SLinus Torvalds /** 10601da177e4SLinus Torvalds * sa1111_set_audio_rate - set the audio sample rate 10611da177e4SLinus Torvalds * @sadev: SA1111 SAC function block 10621da177e4SLinus Torvalds * @rate: sample rate to select 10631da177e4SLinus Torvalds */ 10641da177e4SLinus Torvalds int sa1111_set_audio_rate(struct sa1111_dev *sadev, int rate) 10651da177e4SLinus Torvalds { 10661da177e4SLinus Torvalds struct sa1111 *sachip = sa1111_chip_driver(sadev); 10671da177e4SLinus Torvalds unsigned int div; 10681da177e4SLinus Torvalds 10691da177e4SLinus Torvalds if (sadev->devid != SA1111_DEVID_SAC) 10701da177e4SLinus Torvalds return -EINVAL; 10711da177e4SLinus Torvalds 10721da177e4SLinus Torvalds div = (__sa1111_pll_clock(sachip) / 256 + rate / 2) / rate; 10731da177e4SLinus Torvalds if (div == 0) 10741da177e4SLinus Torvalds div = 1; 10751da177e4SLinus Torvalds if (div > 128) 10761da177e4SLinus Torvalds div = 128; 10771da177e4SLinus Torvalds 10781da177e4SLinus Torvalds sa1111_writel(div - 1, sachip->base + SA1111_SKAUD); 10791da177e4SLinus Torvalds 10801da177e4SLinus Torvalds return 0; 10811da177e4SLinus Torvalds } 10821da177e4SLinus Torvalds 10831da177e4SLinus Torvalds /** 10841da177e4SLinus Torvalds * sa1111_get_audio_rate - get the audio sample rate 10851da177e4SLinus Torvalds * @sadev: SA1111 SAC function block device 10861da177e4SLinus Torvalds */ 10871da177e4SLinus Torvalds int sa1111_get_audio_rate(struct sa1111_dev *sadev) 10881da177e4SLinus Torvalds { 10891da177e4SLinus Torvalds struct sa1111 *sachip = sa1111_chip_driver(sadev); 10901da177e4SLinus Torvalds unsigned long div; 10911da177e4SLinus Torvalds 10921da177e4SLinus Torvalds if (sadev->devid != SA1111_DEVID_SAC) 10931da177e4SLinus Torvalds return -EINVAL; 10941da177e4SLinus Torvalds 10951da177e4SLinus Torvalds div = sa1111_readl(sachip->base + SA1111_SKAUD) + 1; 10961da177e4SLinus Torvalds 10971da177e4SLinus Torvalds return __sa1111_pll_clock(sachip) / (256 * div); 10981da177e4SLinus Torvalds } 10991da177e4SLinus Torvalds 11001da177e4SLinus Torvalds void sa1111_set_io_dir(struct sa1111_dev *sadev, 11011da177e4SLinus Torvalds unsigned int bits, unsigned int dir, 11021da177e4SLinus Torvalds unsigned int sleep_dir) 11031da177e4SLinus Torvalds { 11041da177e4SLinus Torvalds struct sa1111 *sachip = sa1111_chip_driver(sadev); 11051da177e4SLinus Torvalds unsigned long flags; 11061da177e4SLinus Torvalds unsigned int val; 11071da177e4SLinus Torvalds void __iomem *gpio = sachip->base + SA1111_GPIO; 11081da177e4SLinus Torvalds 11091da177e4SLinus Torvalds #define MODIFY_BITS(port, mask, dir) \ 11101da177e4SLinus Torvalds if (mask) { \ 11111da177e4SLinus Torvalds val = sa1111_readl(port); \ 11121da177e4SLinus Torvalds val &= ~(mask); \ 11131da177e4SLinus Torvalds val |= (dir) & (mask); \ 11141da177e4SLinus Torvalds sa1111_writel(val, port); \ 11151da177e4SLinus Torvalds } 11161da177e4SLinus Torvalds 11171da177e4SLinus Torvalds spin_lock_irqsave(&sachip->lock, flags); 11181da177e4SLinus Torvalds MODIFY_BITS(gpio + SA1111_GPIO_PADDR, bits & 15, dir); 11191da177e4SLinus Torvalds MODIFY_BITS(gpio + SA1111_GPIO_PBDDR, (bits >> 8) & 255, dir >> 8); 11201da177e4SLinus Torvalds MODIFY_BITS(gpio + SA1111_GPIO_PCDDR, (bits >> 16) & 255, dir >> 16); 11211da177e4SLinus Torvalds 11221da177e4SLinus Torvalds MODIFY_BITS(gpio + SA1111_GPIO_PASDR, bits & 15, sleep_dir); 11231da177e4SLinus Torvalds MODIFY_BITS(gpio + SA1111_GPIO_PBSDR, (bits >> 8) & 255, sleep_dir >> 8); 11241da177e4SLinus Torvalds MODIFY_BITS(gpio + SA1111_GPIO_PCSDR, (bits >> 16) & 255, sleep_dir >> 16); 11251da177e4SLinus Torvalds spin_unlock_irqrestore(&sachip->lock, flags); 11261da177e4SLinus Torvalds } 11271da177e4SLinus Torvalds 11281da177e4SLinus Torvalds void sa1111_set_io(struct sa1111_dev *sadev, unsigned int bits, unsigned int v) 11291da177e4SLinus Torvalds { 11301da177e4SLinus Torvalds struct sa1111 *sachip = sa1111_chip_driver(sadev); 11311da177e4SLinus Torvalds unsigned long flags; 11321da177e4SLinus Torvalds unsigned int val; 11331da177e4SLinus Torvalds void __iomem *gpio = sachip->base + SA1111_GPIO; 11341da177e4SLinus Torvalds 11351da177e4SLinus Torvalds spin_lock_irqsave(&sachip->lock, flags); 11361da177e4SLinus Torvalds MODIFY_BITS(gpio + SA1111_GPIO_PADWR, bits & 15, v); 11371da177e4SLinus Torvalds MODIFY_BITS(gpio + SA1111_GPIO_PBDWR, (bits >> 8) & 255, v >> 8); 11381da177e4SLinus Torvalds MODIFY_BITS(gpio + SA1111_GPIO_PCDWR, (bits >> 16) & 255, v >> 16); 11391da177e4SLinus Torvalds spin_unlock_irqrestore(&sachip->lock, flags); 11401da177e4SLinus Torvalds } 11411da177e4SLinus Torvalds 11421da177e4SLinus Torvalds void sa1111_set_sleep_io(struct sa1111_dev *sadev, unsigned int bits, unsigned int v) 11431da177e4SLinus Torvalds { 11441da177e4SLinus Torvalds struct sa1111 *sachip = sa1111_chip_driver(sadev); 11451da177e4SLinus Torvalds unsigned long flags; 11461da177e4SLinus Torvalds unsigned int val; 11471da177e4SLinus Torvalds void __iomem *gpio = sachip->base + SA1111_GPIO; 11481da177e4SLinus Torvalds 11491da177e4SLinus Torvalds spin_lock_irqsave(&sachip->lock, flags); 11501da177e4SLinus Torvalds MODIFY_BITS(gpio + SA1111_GPIO_PASSR, bits & 15, v); 11511da177e4SLinus Torvalds MODIFY_BITS(gpio + SA1111_GPIO_PBSSR, (bits >> 8) & 255, v >> 8); 11521da177e4SLinus Torvalds MODIFY_BITS(gpio + SA1111_GPIO_PCSSR, (bits >> 16) & 255, v >> 16); 11531da177e4SLinus Torvalds spin_unlock_irqrestore(&sachip->lock, flags); 11541da177e4SLinus Torvalds } 11551da177e4SLinus Torvalds 11561da177e4SLinus Torvalds /* 11571da177e4SLinus Torvalds * Individual device operations. 11581da177e4SLinus Torvalds */ 11591da177e4SLinus Torvalds 11601da177e4SLinus Torvalds /** 11611da177e4SLinus Torvalds * sa1111_enable_device - enable an on-chip SA1111 function block 11621da177e4SLinus Torvalds * @sadev: SA1111 function block device to enable 11631da177e4SLinus Torvalds */ 11641da177e4SLinus Torvalds void sa1111_enable_device(struct sa1111_dev *sadev) 11651da177e4SLinus Torvalds { 11661da177e4SLinus Torvalds struct sa1111 *sachip = sa1111_chip_driver(sadev); 11671da177e4SLinus Torvalds unsigned long flags; 11681da177e4SLinus Torvalds unsigned int val; 11691da177e4SLinus Torvalds 11701da177e4SLinus Torvalds spin_lock_irqsave(&sachip->lock, flags); 11711da177e4SLinus Torvalds val = sa1111_readl(sachip->base + SA1111_SKPCR); 11721da177e4SLinus Torvalds sa1111_writel(val | sadev->skpcr_mask, sachip->base + SA1111_SKPCR); 11731da177e4SLinus Torvalds spin_unlock_irqrestore(&sachip->lock, flags); 11741da177e4SLinus Torvalds } 11751da177e4SLinus Torvalds 11761da177e4SLinus Torvalds /** 11771da177e4SLinus Torvalds * sa1111_disable_device - disable an on-chip SA1111 function block 11781da177e4SLinus Torvalds * @sadev: SA1111 function block device to disable 11791da177e4SLinus Torvalds */ 11801da177e4SLinus Torvalds void sa1111_disable_device(struct sa1111_dev *sadev) 11811da177e4SLinus Torvalds { 11821da177e4SLinus Torvalds struct sa1111 *sachip = sa1111_chip_driver(sadev); 11831da177e4SLinus Torvalds unsigned long flags; 11841da177e4SLinus Torvalds unsigned int val; 11851da177e4SLinus Torvalds 11861da177e4SLinus Torvalds spin_lock_irqsave(&sachip->lock, flags); 11871da177e4SLinus Torvalds val = sa1111_readl(sachip->base + SA1111_SKPCR); 11881da177e4SLinus Torvalds sa1111_writel(val & ~sadev->skpcr_mask, sachip->base + SA1111_SKPCR); 11891da177e4SLinus Torvalds spin_unlock_irqrestore(&sachip->lock, flags); 11901da177e4SLinus Torvalds } 11911da177e4SLinus Torvalds 11921da177e4SLinus Torvalds /* 11931da177e4SLinus Torvalds * SA1111 "Register Access Bus." 11941da177e4SLinus Torvalds * 11951da177e4SLinus Torvalds * We model this as a regular bus type, and hang devices directly 11961da177e4SLinus Torvalds * off this. 11971da177e4SLinus Torvalds */ 11981da177e4SLinus Torvalds static int sa1111_match(struct device *_dev, struct device_driver *_drv) 11991da177e4SLinus Torvalds { 12001da177e4SLinus Torvalds struct sa1111_dev *dev = SA1111_DEV(_dev); 12011da177e4SLinus Torvalds struct sa1111_driver *drv = SA1111_DRV(_drv); 12021da177e4SLinus Torvalds 12031da177e4SLinus Torvalds return dev->devid == drv->devid; 12041da177e4SLinus Torvalds } 12051da177e4SLinus Torvalds 12061da177e4SLinus Torvalds static int sa1111_bus_suspend(struct device *dev, pm_message_t state) 12071da177e4SLinus Torvalds { 12081da177e4SLinus Torvalds struct sa1111_dev *sadev = SA1111_DEV(dev); 12091da177e4SLinus Torvalds struct sa1111_driver *drv = SA1111_DRV(dev->driver); 12101da177e4SLinus Torvalds int ret = 0; 12111da177e4SLinus Torvalds 12121da177e4SLinus Torvalds if (drv && drv->suspend) 12131da177e4SLinus Torvalds ret = drv->suspend(sadev, state); 12141da177e4SLinus Torvalds return ret; 12151da177e4SLinus Torvalds } 12161da177e4SLinus Torvalds 12171da177e4SLinus Torvalds static int sa1111_bus_resume(struct device *dev) 12181da177e4SLinus Torvalds { 12191da177e4SLinus Torvalds struct sa1111_dev *sadev = SA1111_DEV(dev); 12201da177e4SLinus Torvalds struct sa1111_driver *drv = SA1111_DRV(dev->driver); 12211da177e4SLinus Torvalds int ret = 0; 12221da177e4SLinus Torvalds 12231da177e4SLinus Torvalds if (drv && drv->resume) 12241da177e4SLinus Torvalds ret = drv->resume(sadev); 12251da177e4SLinus Torvalds return ret; 12261da177e4SLinus Torvalds } 12271da177e4SLinus Torvalds 12281da177e4SLinus Torvalds static int sa1111_bus_probe(struct device *dev) 12291da177e4SLinus Torvalds { 12301da177e4SLinus Torvalds struct sa1111_dev *sadev = SA1111_DEV(dev); 12311da177e4SLinus Torvalds struct sa1111_driver *drv = SA1111_DRV(dev->driver); 12321da177e4SLinus Torvalds int ret = -ENODEV; 12331da177e4SLinus Torvalds 12341da177e4SLinus Torvalds if (drv->probe) 12351da177e4SLinus Torvalds ret = drv->probe(sadev); 12361da177e4SLinus Torvalds return ret; 12371da177e4SLinus Torvalds } 12381da177e4SLinus Torvalds 12391da177e4SLinus Torvalds static int sa1111_bus_remove(struct device *dev) 12401da177e4SLinus Torvalds { 12411da177e4SLinus Torvalds struct sa1111_dev *sadev = SA1111_DEV(dev); 12421da177e4SLinus Torvalds struct sa1111_driver *drv = SA1111_DRV(dev->driver); 12431da177e4SLinus Torvalds int ret = 0; 12441da177e4SLinus Torvalds 12451da177e4SLinus Torvalds if (drv->remove) 12461da177e4SLinus Torvalds ret = drv->remove(sadev); 12471da177e4SLinus Torvalds return ret; 12481da177e4SLinus Torvalds } 12491da177e4SLinus Torvalds 12501da177e4SLinus Torvalds struct bus_type sa1111_bus_type = { 12511da177e4SLinus Torvalds .name = "sa1111-rab", 12521da177e4SLinus Torvalds .match = sa1111_match, 12532876ba43SRussell King .probe = sa1111_bus_probe, 12542876ba43SRussell King .remove = sa1111_bus_remove, 12551da177e4SLinus Torvalds .suspend = sa1111_bus_suspend, 12561da177e4SLinus Torvalds .resume = sa1111_bus_resume, 12571da177e4SLinus Torvalds }; 12581da177e4SLinus Torvalds 12591da177e4SLinus Torvalds int sa1111_driver_register(struct sa1111_driver *driver) 12601da177e4SLinus Torvalds { 12611da177e4SLinus Torvalds driver->drv.bus = &sa1111_bus_type; 12621da177e4SLinus Torvalds return driver_register(&driver->drv); 12631da177e4SLinus Torvalds } 12641da177e4SLinus Torvalds 12651da177e4SLinus Torvalds void sa1111_driver_unregister(struct sa1111_driver *driver) 12661da177e4SLinus Torvalds { 12671da177e4SLinus Torvalds driver_unregister(&driver->drv); 12681da177e4SLinus Torvalds } 12691da177e4SLinus Torvalds 12701da177e4SLinus Torvalds static int __init sa1111_init(void) 12711da177e4SLinus Torvalds { 12721da177e4SLinus Torvalds int ret = bus_register(&sa1111_bus_type); 12731da177e4SLinus Torvalds if (ret == 0) 12743ae5eaecSRussell King platform_driver_register(&sa1111_device_driver); 12751da177e4SLinus Torvalds return ret; 12761da177e4SLinus Torvalds } 12771da177e4SLinus Torvalds 12781da177e4SLinus Torvalds static void __exit sa1111_exit(void) 12791da177e4SLinus Torvalds { 12803ae5eaecSRussell King platform_driver_unregister(&sa1111_device_driver); 12811da177e4SLinus Torvalds bus_unregister(&sa1111_bus_type); 12821da177e4SLinus Torvalds } 12831da177e4SLinus Torvalds 128472724382SRussell King subsys_initcall(sa1111_init); 12851da177e4SLinus Torvalds module_exit(sa1111_exit); 12861da177e4SLinus Torvalds 12871da177e4SLinus Torvalds MODULE_DESCRIPTION("Intel Corporation SA1111 core driver"); 12881da177e4SLinus Torvalds MODULE_LICENSE("GPL"); 12891da177e4SLinus Torvalds 12901da177e4SLinus Torvalds EXPORT_SYMBOL(sa1111_select_audio_mode); 12911da177e4SLinus Torvalds EXPORT_SYMBOL(sa1111_set_audio_rate); 12921da177e4SLinus Torvalds EXPORT_SYMBOL(sa1111_get_audio_rate); 12931da177e4SLinus Torvalds EXPORT_SYMBOL(sa1111_set_io_dir); 12941da177e4SLinus Torvalds EXPORT_SYMBOL(sa1111_set_io); 12951da177e4SLinus Torvalds EXPORT_SYMBOL(sa1111_set_sleep_io); 12961da177e4SLinus Torvalds EXPORT_SYMBOL(sa1111_enable_device); 12971da177e4SLinus Torvalds EXPORT_SYMBOL(sa1111_disable_device); 12981da177e4SLinus Torvalds EXPORT_SYMBOL(sa1111_pll_clock); 12991da177e4SLinus Torvalds EXPORT_SYMBOL(sa1111_bus_type); 13001da177e4SLinus Torvalds EXPORT_SYMBOL(sa1111_driver_register); 13011da177e4SLinus Torvalds EXPORT_SYMBOL(sa1111_driver_unregister); 1302