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> 1936d31213SRussell King #include <linux/irq.h> 201da177e4SLinus Torvalds #include <linux/kernel.h> 211da177e4SLinus Torvalds #include <linux/delay.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> 29fced80c7SRussell King #include <linux/io.h> 301da177e4SLinus Torvalds 31a09e64fbSRussell King #include <mach/hardware.h> 321da177e4SLinus Torvalds #include <asm/mach/irq.h> 3336d31213SRussell King #include <asm/mach-types.h> 3445e109d0SRussell King #include <asm/sizes.h> 351da177e4SLinus Torvalds 361da177e4SLinus Torvalds #include <asm/hardware/sa1111.h> 371da177e4SLinus Torvalds 3819851c58SEric Miao /* SA1111 IRQs */ 3919851c58SEric Miao #define IRQ_GPAIN0 (0) 4019851c58SEric Miao #define IRQ_GPAIN1 (1) 4119851c58SEric Miao #define IRQ_GPAIN2 (2) 4219851c58SEric Miao #define IRQ_GPAIN3 (3) 4319851c58SEric Miao #define IRQ_GPBIN0 (4) 4419851c58SEric Miao #define IRQ_GPBIN1 (5) 4519851c58SEric Miao #define IRQ_GPBIN2 (6) 4619851c58SEric Miao #define IRQ_GPBIN3 (7) 4719851c58SEric Miao #define IRQ_GPBIN4 (8) 4819851c58SEric Miao #define IRQ_GPBIN5 (9) 4919851c58SEric Miao #define IRQ_GPCIN0 (10) 5019851c58SEric Miao #define IRQ_GPCIN1 (11) 5119851c58SEric Miao #define IRQ_GPCIN2 (12) 5219851c58SEric Miao #define IRQ_GPCIN3 (13) 5319851c58SEric Miao #define IRQ_GPCIN4 (14) 5419851c58SEric Miao #define IRQ_GPCIN5 (15) 5519851c58SEric Miao #define IRQ_GPCIN6 (16) 5619851c58SEric Miao #define IRQ_GPCIN7 (17) 5719851c58SEric Miao #define IRQ_MSTXINT (18) 5819851c58SEric Miao #define IRQ_MSRXINT (19) 5919851c58SEric Miao #define IRQ_MSSTOPERRINT (20) 6019851c58SEric Miao #define IRQ_TPTXINT (21) 6119851c58SEric Miao #define IRQ_TPRXINT (22) 6219851c58SEric Miao #define IRQ_TPSTOPERRINT (23) 6319851c58SEric Miao #define SSPXMTINT (24) 6419851c58SEric Miao #define SSPRCVINT (25) 6519851c58SEric Miao #define SSPROR (26) 6619851c58SEric Miao #define AUDXMTDMADONEA (32) 6719851c58SEric Miao #define AUDRCVDMADONEA (33) 6819851c58SEric Miao #define AUDXMTDMADONEB (34) 6919851c58SEric Miao #define AUDRCVDMADONEB (35) 7019851c58SEric Miao #define AUDTFSR (36) 7119851c58SEric Miao #define AUDRFSR (37) 7219851c58SEric Miao #define AUDTUR (38) 7319851c58SEric Miao #define AUDROR (39) 7419851c58SEric Miao #define AUDDTS (40) 7519851c58SEric Miao #define AUDRDD (41) 7619851c58SEric Miao #define AUDSTO (42) 7719851c58SEric Miao #define IRQ_USBPWR (43) 7819851c58SEric Miao #define IRQ_HCIM (44) 7919851c58SEric Miao #define IRQ_HCIBUFFACC (45) 8019851c58SEric Miao #define IRQ_HCIRMTWKP (46) 8119851c58SEric Miao #define IRQ_NHCIMFCIR (47) 8219851c58SEric Miao #define IRQ_USB_PORT_RESUME (48) 8319851c58SEric Miao #define IRQ_S0_READY_NINT (49) 8419851c58SEric Miao #define IRQ_S1_READY_NINT (50) 8519851c58SEric Miao #define IRQ_S0_CD_VALID (51) 8619851c58SEric Miao #define IRQ_S1_CD_VALID (52) 8719851c58SEric Miao #define IRQ_S0_BVD1_STSCHG (53) 8819851c58SEric Miao #define IRQ_S1_BVD1_STSCHG (54) 8936d31213SRussell King #define SA1111_IRQ_NR (55) 9019851c58SEric Miao 9129c140b6SRussell King extern void sa1110_mb_enable(void); 9229c140b6SRussell King extern void sa1110_mb_disable(void); 931da177e4SLinus Torvalds 941da177e4SLinus Torvalds /* 951da177e4SLinus Torvalds * We keep the following data for the overall SA1111. Note that the 961da177e4SLinus Torvalds * struct device and struct resource are "fake"; they should be supplied 971da177e4SLinus Torvalds * by the bus above us. However, in the interests of getting all SA1111 981da177e4SLinus Torvalds * drivers converted over to the device model, we provide this as an 991da177e4SLinus Torvalds * anchor point for all the other drivers. 1001da177e4SLinus Torvalds */ 1011da177e4SLinus Torvalds struct sa1111 { 1021da177e4SLinus Torvalds struct device *dev; 10397d654f8SRussell King struct clk *clk; 1041da177e4SLinus Torvalds unsigned long phys; 1051da177e4SLinus Torvalds int irq; 10619851c58SEric Miao int irq_base; /* base for cascaded on-chip IRQs */ 1071da177e4SLinus Torvalds spinlock_t lock; 1081da177e4SLinus Torvalds void __iomem *base; 109ae99ddbcSRussell King struct sa1111_platform_data *pdata; 11093160c63SRafael J. Wysocki #ifdef CONFIG_PM 11193160c63SRafael J. Wysocki void *saved_state; 11293160c63SRafael J. Wysocki #endif 1131da177e4SLinus Torvalds }; 1141da177e4SLinus Torvalds 1151da177e4SLinus Torvalds /* 1161da177e4SLinus Torvalds * We _really_ need to eliminate this. Its only users 1171da177e4SLinus Torvalds * are the PWM and DMA checking code. 1181da177e4SLinus Torvalds */ 1191da177e4SLinus Torvalds static struct sa1111 *g_sa1111; 1201da177e4SLinus Torvalds 1211da177e4SLinus Torvalds struct sa1111_dev_info { 1221da177e4SLinus Torvalds unsigned long offset; 1231da177e4SLinus Torvalds unsigned long skpcr_mask; 12421d1c770SRussell King bool dma; 1251da177e4SLinus Torvalds unsigned int devid; 1261da177e4SLinus Torvalds unsigned int irq[6]; 1271da177e4SLinus Torvalds }; 1281da177e4SLinus Torvalds 1291da177e4SLinus Torvalds static struct sa1111_dev_info sa1111_devices[] = { 1301da177e4SLinus Torvalds { 1311da177e4SLinus Torvalds .offset = SA1111_USB, 1321da177e4SLinus Torvalds .skpcr_mask = SKPCR_UCLKEN, 13321d1c770SRussell King .dma = true, 1341da177e4SLinus Torvalds .devid = SA1111_DEVID_USB, 1351da177e4SLinus Torvalds .irq = { 1361da177e4SLinus Torvalds IRQ_USBPWR, 1371da177e4SLinus Torvalds IRQ_HCIM, 1381da177e4SLinus Torvalds IRQ_HCIBUFFACC, 1391da177e4SLinus Torvalds IRQ_HCIRMTWKP, 1401da177e4SLinus Torvalds IRQ_NHCIMFCIR, 1411da177e4SLinus Torvalds IRQ_USB_PORT_RESUME 1421da177e4SLinus Torvalds }, 1431da177e4SLinus Torvalds }, 1441da177e4SLinus Torvalds { 1451da177e4SLinus Torvalds .offset = 0x0600, 1461da177e4SLinus Torvalds .skpcr_mask = SKPCR_I2SCLKEN | SKPCR_L3CLKEN, 14721d1c770SRussell King .dma = true, 1481da177e4SLinus Torvalds .devid = SA1111_DEVID_SAC, 1491da177e4SLinus Torvalds .irq = { 1501da177e4SLinus Torvalds AUDXMTDMADONEA, 1511da177e4SLinus Torvalds AUDXMTDMADONEB, 1521da177e4SLinus Torvalds AUDRCVDMADONEA, 1531da177e4SLinus Torvalds AUDRCVDMADONEB 1541da177e4SLinus Torvalds }, 1551da177e4SLinus Torvalds }, 1561da177e4SLinus Torvalds { 1571da177e4SLinus Torvalds .offset = 0x0800, 1581da177e4SLinus Torvalds .skpcr_mask = SKPCR_SCLKEN, 1591da177e4SLinus Torvalds .devid = SA1111_DEVID_SSP, 1601da177e4SLinus Torvalds }, 1611da177e4SLinus Torvalds { 1621da177e4SLinus Torvalds .offset = SA1111_KBD, 1631da177e4SLinus Torvalds .skpcr_mask = SKPCR_PTCLKEN, 164e5c0fc41SRussell King .devid = SA1111_DEVID_PS2_KBD, 1651da177e4SLinus Torvalds .irq = { 1661da177e4SLinus Torvalds IRQ_TPRXINT, 1671da177e4SLinus Torvalds IRQ_TPTXINT 1681da177e4SLinus Torvalds }, 1691da177e4SLinus Torvalds }, 1701da177e4SLinus Torvalds { 1711da177e4SLinus Torvalds .offset = SA1111_MSE, 1721da177e4SLinus Torvalds .skpcr_mask = SKPCR_PMCLKEN, 173e5c0fc41SRussell King .devid = SA1111_DEVID_PS2_MSE, 1741da177e4SLinus Torvalds .irq = { 1751da177e4SLinus Torvalds IRQ_MSRXINT, 1761da177e4SLinus Torvalds IRQ_MSTXINT 1771da177e4SLinus Torvalds }, 1781da177e4SLinus Torvalds }, 1791da177e4SLinus Torvalds { 1801da177e4SLinus Torvalds .offset = 0x1800, 1811da177e4SLinus Torvalds .skpcr_mask = 0, 1821da177e4SLinus Torvalds .devid = SA1111_DEVID_PCMCIA, 1831da177e4SLinus Torvalds .irq = { 1841da177e4SLinus Torvalds IRQ_S0_READY_NINT, 1851da177e4SLinus Torvalds IRQ_S0_CD_VALID, 1861da177e4SLinus Torvalds IRQ_S0_BVD1_STSCHG, 1871da177e4SLinus Torvalds IRQ_S1_READY_NINT, 1881da177e4SLinus Torvalds IRQ_S1_CD_VALID, 1891da177e4SLinus Torvalds IRQ_S1_BVD1_STSCHG, 1901da177e4SLinus Torvalds }, 1911da177e4SLinus Torvalds }, 1921da177e4SLinus Torvalds }; 1931da177e4SLinus Torvalds 1941da177e4SLinus Torvalds /* 1951da177e4SLinus Torvalds * SA1111 interrupt support. Since clearing an IRQ while there are 1961da177e4SLinus Torvalds * active IRQs causes the interrupt output to pulse, the upper levels 1971da177e4SLinus Torvalds * will call us again if there are more interrupts to process. 1981da177e4SLinus Torvalds */ 199bd0b9ac4SThomas Gleixner static void sa1111_irq_handler(struct irq_desc *desc) 2001da177e4SLinus Torvalds { 2011da177e4SLinus Torvalds unsigned int stat0, stat1, i; 202f575398bSJiang Liu struct sa1111 *sachip = irq_desc_get_handler_data(desc); 20319851c58SEric Miao void __iomem *mapbase = sachip->base + SA1111_INTC; 2041da177e4SLinus Torvalds 20519851c58SEric Miao stat0 = sa1111_readl(mapbase + SA1111_INTSTATCLR0); 20619851c58SEric Miao stat1 = sa1111_readl(mapbase + SA1111_INTSTATCLR1); 2071da177e4SLinus Torvalds 20819851c58SEric Miao sa1111_writel(stat0, mapbase + SA1111_INTSTATCLR0); 2091da177e4SLinus Torvalds 2108231e741SLennert Buytenhek desc->irq_data.chip->irq_ack(&desc->irq_data); 2111da177e4SLinus Torvalds 21219851c58SEric Miao sa1111_writel(stat1, mapbase + SA1111_INTSTATCLR1); 2131da177e4SLinus Torvalds 2141da177e4SLinus Torvalds if (stat0 == 0 && stat1 == 0) { 215bd0b9ac4SThomas Gleixner do_bad_IRQ(desc); 2161da177e4SLinus Torvalds return; 2171da177e4SLinus Torvalds } 2181da177e4SLinus Torvalds 21919851c58SEric Miao for (i = 0; stat0; i++, stat0 >>= 1) 2201da177e4SLinus Torvalds if (stat0 & 1) 22119851c58SEric Miao generic_handle_irq(i + sachip->irq_base); 2221da177e4SLinus Torvalds 22319851c58SEric Miao for (i = 32; stat1; i++, stat1 >>= 1) 2241da177e4SLinus Torvalds if (stat1 & 1) 22519851c58SEric Miao generic_handle_irq(i + sachip->irq_base); 2261da177e4SLinus Torvalds 2271da177e4SLinus Torvalds /* For level-based interrupts */ 2288231e741SLennert Buytenhek desc->irq_data.chip->irq_unmask(&desc->irq_data); 2291da177e4SLinus Torvalds } 2301da177e4SLinus Torvalds 23119851c58SEric Miao #define SA1111_IRQMASK_LO(x) (1 << (x - sachip->irq_base)) 23219851c58SEric Miao #define SA1111_IRQMASK_HI(x) (1 << (x - sachip->irq_base - 32)) 2331da177e4SLinus Torvalds 2348231e741SLennert Buytenhek static void sa1111_ack_irq(struct irq_data *d) 2351da177e4SLinus Torvalds { 2361da177e4SLinus Torvalds } 2371da177e4SLinus Torvalds 2388231e741SLennert Buytenhek static void sa1111_mask_lowirq(struct irq_data *d) 2391da177e4SLinus Torvalds { 2408231e741SLennert Buytenhek struct sa1111 *sachip = irq_data_get_irq_chip_data(d); 24119851c58SEric Miao void __iomem *mapbase = sachip->base + SA1111_INTC; 2421da177e4SLinus Torvalds unsigned long ie0; 2431da177e4SLinus Torvalds 2441da177e4SLinus Torvalds ie0 = sa1111_readl(mapbase + SA1111_INTEN0); 2458231e741SLennert Buytenhek ie0 &= ~SA1111_IRQMASK_LO(d->irq); 2461da177e4SLinus Torvalds writel(ie0, mapbase + SA1111_INTEN0); 2471da177e4SLinus Torvalds } 2481da177e4SLinus Torvalds 2498231e741SLennert Buytenhek static void sa1111_unmask_lowirq(struct irq_data *d) 2501da177e4SLinus Torvalds { 2518231e741SLennert Buytenhek struct sa1111 *sachip = irq_data_get_irq_chip_data(d); 25219851c58SEric Miao void __iomem *mapbase = sachip->base + SA1111_INTC; 2531da177e4SLinus Torvalds unsigned long ie0; 2541da177e4SLinus Torvalds 2551da177e4SLinus Torvalds ie0 = sa1111_readl(mapbase + SA1111_INTEN0); 2568231e741SLennert Buytenhek ie0 |= SA1111_IRQMASK_LO(d->irq); 2571da177e4SLinus Torvalds sa1111_writel(ie0, mapbase + SA1111_INTEN0); 2581da177e4SLinus Torvalds } 2591da177e4SLinus Torvalds 2601da177e4SLinus Torvalds /* 2611da177e4SLinus Torvalds * Attempt to re-trigger the interrupt. The SA1111 contains a register 2621da177e4SLinus Torvalds * (INTSET) which claims to do this. However, in practice no amount of 2631da177e4SLinus Torvalds * manipulation of INTEN and INTSET guarantees that the interrupt will 2641da177e4SLinus Torvalds * be triggered. In fact, its very difficult, if not impossible to get 2651da177e4SLinus Torvalds * INTSET to re-trigger the interrupt. 2661da177e4SLinus Torvalds */ 2678231e741SLennert Buytenhek static int sa1111_retrigger_lowirq(struct irq_data *d) 2681da177e4SLinus Torvalds { 2698231e741SLennert Buytenhek struct sa1111 *sachip = irq_data_get_irq_chip_data(d); 27019851c58SEric Miao void __iomem *mapbase = sachip->base + SA1111_INTC; 2718231e741SLennert Buytenhek unsigned int mask = SA1111_IRQMASK_LO(d->irq); 2721da177e4SLinus Torvalds unsigned long ip0; 2731da177e4SLinus Torvalds int i; 2741da177e4SLinus Torvalds 2751da177e4SLinus Torvalds ip0 = sa1111_readl(mapbase + SA1111_INTPOL0); 2761da177e4SLinus Torvalds for (i = 0; i < 8; i++) { 2771da177e4SLinus Torvalds sa1111_writel(ip0 ^ mask, mapbase + SA1111_INTPOL0); 2781da177e4SLinus Torvalds sa1111_writel(ip0, mapbase + SA1111_INTPOL0); 279cae39988SPavel Machek if (sa1111_readl(mapbase + SA1111_INTSTATCLR0) & mask) 2801da177e4SLinus Torvalds break; 2811da177e4SLinus Torvalds } 2821da177e4SLinus Torvalds 2831da177e4SLinus Torvalds if (i == 8) 2844ed89f22SRussell King pr_err("Danger Will Robinson: failed to re-trigger IRQ%d\n", 2854ed89f22SRussell King d->irq); 2861da177e4SLinus Torvalds return i == 8 ? -1 : 0; 2871da177e4SLinus Torvalds } 2881da177e4SLinus Torvalds 2898231e741SLennert Buytenhek static int sa1111_type_lowirq(struct irq_data *d, unsigned int flags) 2901da177e4SLinus Torvalds { 2918231e741SLennert Buytenhek struct sa1111 *sachip = irq_data_get_irq_chip_data(d); 29219851c58SEric Miao void __iomem *mapbase = sachip->base + SA1111_INTC; 2938231e741SLennert Buytenhek unsigned int mask = SA1111_IRQMASK_LO(d->irq); 2941da177e4SLinus Torvalds unsigned long ip0; 2951da177e4SLinus Torvalds 2966cab4860SDmitry Baryshkov if (flags == IRQ_TYPE_PROBE) 2971da177e4SLinus Torvalds return 0; 2981da177e4SLinus Torvalds 2996cab4860SDmitry Baryshkov if ((!(flags & IRQ_TYPE_EDGE_RISING) ^ !(flags & IRQ_TYPE_EDGE_FALLING)) == 0) 3001da177e4SLinus Torvalds return -EINVAL; 3011da177e4SLinus Torvalds 3021da177e4SLinus Torvalds ip0 = sa1111_readl(mapbase + SA1111_INTPOL0); 3036cab4860SDmitry Baryshkov if (flags & IRQ_TYPE_EDGE_RISING) 3041da177e4SLinus Torvalds ip0 &= ~mask; 3051da177e4SLinus Torvalds else 3061da177e4SLinus Torvalds ip0 |= mask; 3071da177e4SLinus Torvalds sa1111_writel(ip0, mapbase + SA1111_INTPOL0); 3081da177e4SLinus Torvalds sa1111_writel(ip0, mapbase + SA1111_WAKEPOL0); 3091da177e4SLinus Torvalds 3101da177e4SLinus Torvalds return 0; 3111da177e4SLinus Torvalds } 3121da177e4SLinus Torvalds 3138231e741SLennert Buytenhek static int sa1111_wake_lowirq(struct irq_data *d, unsigned int on) 3141da177e4SLinus Torvalds { 3158231e741SLennert Buytenhek struct sa1111 *sachip = irq_data_get_irq_chip_data(d); 31619851c58SEric Miao void __iomem *mapbase = sachip->base + SA1111_INTC; 3178231e741SLennert Buytenhek unsigned int mask = SA1111_IRQMASK_LO(d->irq); 3181da177e4SLinus Torvalds unsigned long we0; 3191da177e4SLinus Torvalds 3201da177e4SLinus Torvalds we0 = sa1111_readl(mapbase + SA1111_WAKEEN0); 3211da177e4SLinus Torvalds if (on) 3221da177e4SLinus Torvalds we0 |= mask; 3231da177e4SLinus Torvalds else 3241da177e4SLinus Torvalds we0 &= ~mask; 3251da177e4SLinus Torvalds sa1111_writel(we0, mapbase + SA1111_WAKEEN0); 3261da177e4SLinus Torvalds 3271da177e4SLinus Torvalds return 0; 3281da177e4SLinus Torvalds } 3291da177e4SLinus Torvalds 33038c677cbSDavid Brownell static struct irq_chip sa1111_low_chip = { 33138c677cbSDavid Brownell .name = "SA1111-l", 3328231e741SLennert Buytenhek .irq_ack = sa1111_ack_irq, 3338231e741SLennert Buytenhek .irq_mask = sa1111_mask_lowirq, 3348231e741SLennert Buytenhek .irq_unmask = sa1111_unmask_lowirq, 3358231e741SLennert Buytenhek .irq_retrigger = sa1111_retrigger_lowirq, 3368231e741SLennert Buytenhek .irq_set_type = sa1111_type_lowirq, 3378231e741SLennert Buytenhek .irq_set_wake = sa1111_wake_lowirq, 3381da177e4SLinus Torvalds }; 3391da177e4SLinus Torvalds 3408231e741SLennert Buytenhek static void sa1111_mask_highirq(struct irq_data *d) 3411da177e4SLinus Torvalds { 3428231e741SLennert Buytenhek struct sa1111 *sachip = irq_data_get_irq_chip_data(d); 34319851c58SEric Miao void __iomem *mapbase = sachip->base + SA1111_INTC; 3441da177e4SLinus Torvalds unsigned long ie1; 3451da177e4SLinus Torvalds 3461da177e4SLinus Torvalds ie1 = sa1111_readl(mapbase + SA1111_INTEN1); 3478231e741SLennert Buytenhek ie1 &= ~SA1111_IRQMASK_HI(d->irq); 3481da177e4SLinus Torvalds sa1111_writel(ie1, mapbase + SA1111_INTEN1); 3491da177e4SLinus Torvalds } 3501da177e4SLinus Torvalds 3518231e741SLennert Buytenhek static void sa1111_unmask_highirq(struct irq_data *d) 3521da177e4SLinus Torvalds { 3538231e741SLennert Buytenhek struct sa1111 *sachip = irq_data_get_irq_chip_data(d); 35419851c58SEric Miao void __iomem *mapbase = sachip->base + SA1111_INTC; 3551da177e4SLinus Torvalds unsigned long ie1; 3561da177e4SLinus Torvalds 3571da177e4SLinus Torvalds ie1 = sa1111_readl(mapbase + SA1111_INTEN1); 3588231e741SLennert Buytenhek ie1 |= SA1111_IRQMASK_HI(d->irq); 3591da177e4SLinus Torvalds sa1111_writel(ie1, mapbase + SA1111_INTEN1); 3601da177e4SLinus Torvalds } 3611da177e4SLinus Torvalds 3621da177e4SLinus Torvalds /* 3631da177e4SLinus Torvalds * Attempt to re-trigger the interrupt. The SA1111 contains a register 3641da177e4SLinus Torvalds * (INTSET) which claims to do this. However, in practice no amount of 3651da177e4SLinus Torvalds * manipulation of INTEN and INTSET guarantees that the interrupt will 3661da177e4SLinus Torvalds * be triggered. In fact, its very difficult, if not impossible to get 3671da177e4SLinus Torvalds * INTSET to re-trigger the interrupt. 3681da177e4SLinus Torvalds */ 3698231e741SLennert Buytenhek static int sa1111_retrigger_highirq(struct irq_data *d) 3701da177e4SLinus Torvalds { 3718231e741SLennert Buytenhek struct sa1111 *sachip = irq_data_get_irq_chip_data(d); 37219851c58SEric Miao void __iomem *mapbase = sachip->base + SA1111_INTC; 3738231e741SLennert Buytenhek unsigned int mask = SA1111_IRQMASK_HI(d->irq); 3741da177e4SLinus Torvalds unsigned long ip1; 3751da177e4SLinus Torvalds int i; 3761da177e4SLinus Torvalds 3771da177e4SLinus Torvalds ip1 = sa1111_readl(mapbase + SA1111_INTPOL1); 3781da177e4SLinus Torvalds for (i = 0; i < 8; i++) { 3791da177e4SLinus Torvalds sa1111_writel(ip1 ^ mask, mapbase + SA1111_INTPOL1); 3801da177e4SLinus Torvalds sa1111_writel(ip1, mapbase + SA1111_INTPOL1); 3811da177e4SLinus Torvalds if (sa1111_readl(mapbase + SA1111_INTSTATCLR1) & mask) 3821da177e4SLinus Torvalds break; 3831da177e4SLinus Torvalds } 3841da177e4SLinus Torvalds 3851da177e4SLinus Torvalds if (i == 8) 3864ed89f22SRussell King pr_err("Danger Will Robinson: failed to re-trigger IRQ%d\n", 3874ed89f22SRussell King d->irq); 3881da177e4SLinus Torvalds return i == 8 ? -1 : 0; 3891da177e4SLinus Torvalds } 3901da177e4SLinus Torvalds 3918231e741SLennert Buytenhek static int sa1111_type_highirq(struct irq_data *d, unsigned int flags) 3921da177e4SLinus Torvalds { 3938231e741SLennert Buytenhek struct sa1111 *sachip = irq_data_get_irq_chip_data(d); 39419851c58SEric Miao void __iomem *mapbase = sachip->base + SA1111_INTC; 3958231e741SLennert Buytenhek unsigned int mask = SA1111_IRQMASK_HI(d->irq); 3961da177e4SLinus Torvalds unsigned long ip1; 3971da177e4SLinus Torvalds 3986cab4860SDmitry Baryshkov if (flags == IRQ_TYPE_PROBE) 3991da177e4SLinus Torvalds return 0; 4001da177e4SLinus Torvalds 4016cab4860SDmitry Baryshkov if ((!(flags & IRQ_TYPE_EDGE_RISING) ^ !(flags & IRQ_TYPE_EDGE_FALLING)) == 0) 4021da177e4SLinus Torvalds return -EINVAL; 4031da177e4SLinus Torvalds 4041da177e4SLinus Torvalds ip1 = sa1111_readl(mapbase + SA1111_INTPOL1); 4056cab4860SDmitry Baryshkov if (flags & IRQ_TYPE_EDGE_RISING) 4061da177e4SLinus Torvalds ip1 &= ~mask; 4071da177e4SLinus Torvalds else 4081da177e4SLinus Torvalds ip1 |= mask; 4091da177e4SLinus Torvalds sa1111_writel(ip1, mapbase + SA1111_INTPOL1); 4101da177e4SLinus Torvalds sa1111_writel(ip1, mapbase + SA1111_WAKEPOL1); 4111da177e4SLinus Torvalds 4121da177e4SLinus Torvalds return 0; 4131da177e4SLinus Torvalds } 4141da177e4SLinus Torvalds 4158231e741SLennert Buytenhek static int sa1111_wake_highirq(struct irq_data *d, unsigned int on) 4161da177e4SLinus Torvalds { 4178231e741SLennert Buytenhek struct sa1111 *sachip = irq_data_get_irq_chip_data(d); 41819851c58SEric Miao void __iomem *mapbase = sachip->base + SA1111_INTC; 4198231e741SLennert Buytenhek unsigned int mask = SA1111_IRQMASK_HI(d->irq); 4201da177e4SLinus Torvalds unsigned long we1; 4211da177e4SLinus Torvalds 4221da177e4SLinus Torvalds we1 = sa1111_readl(mapbase + SA1111_WAKEEN1); 4231da177e4SLinus Torvalds if (on) 4241da177e4SLinus Torvalds we1 |= mask; 4251da177e4SLinus Torvalds else 4261da177e4SLinus Torvalds we1 &= ~mask; 4271da177e4SLinus Torvalds sa1111_writel(we1, mapbase + SA1111_WAKEEN1); 4281da177e4SLinus Torvalds 4291da177e4SLinus Torvalds return 0; 4301da177e4SLinus Torvalds } 4311da177e4SLinus Torvalds 43238c677cbSDavid Brownell static struct irq_chip sa1111_high_chip = { 43338c677cbSDavid Brownell .name = "SA1111-h", 4348231e741SLennert Buytenhek .irq_ack = sa1111_ack_irq, 4358231e741SLennert Buytenhek .irq_mask = sa1111_mask_highirq, 4368231e741SLennert Buytenhek .irq_unmask = sa1111_unmask_highirq, 4378231e741SLennert Buytenhek .irq_retrigger = sa1111_retrigger_highirq, 4388231e741SLennert Buytenhek .irq_set_type = sa1111_type_highirq, 4398231e741SLennert Buytenhek .irq_set_wake = sa1111_wake_highirq, 4401da177e4SLinus Torvalds }; 4411da177e4SLinus Torvalds 44236d31213SRussell King static int sa1111_setup_irq(struct sa1111 *sachip, unsigned irq_base) 4431da177e4SLinus Torvalds { 4441da177e4SLinus Torvalds void __iomem *irqbase = sachip->base + SA1111_INTC; 445f03ecaa0SRussell King unsigned i, irq; 44636d31213SRussell King int ret; 4471da177e4SLinus Torvalds 4481da177e4SLinus Torvalds /* 4491da177e4SLinus Torvalds * We're guaranteed that this region hasn't been taken. 4501da177e4SLinus Torvalds */ 4511da177e4SLinus Torvalds request_mem_region(sachip->phys + SA1111_INTC, 512, "irq"); 4521da177e4SLinus Torvalds 45336d31213SRussell King ret = irq_alloc_descs(-1, irq_base, SA1111_IRQ_NR, -1); 45436d31213SRussell King if (ret <= 0) { 45536d31213SRussell King dev_err(sachip->dev, "unable to allocate %u irqs: %d\n", 45636d31213SRussell King SA1111_IRQ_NR, ret); 45736d31213SRussell King if (ret == 0) 45836d31213SRussell King ret = -EINVAL; 45936d31213SRussell King return ret; 46036d31213SRussell King } 46136d31213SRussell King 46236d31213SRussell King sachip->irq_base = ret; 46336d31213SRussell King 4641da177e4SLinus Torvalds /* disable all IRQs */ 4651da177e4SLinus Torvalds sa1111_writel(0, irqbase + SA1111_INTEN0); 4661da177e4SLinus Torvalds sa1111_writel(0, irqbase + SA1111_INTEN1); 4671da177e4SLinus Torvalds sa1111_writel(0, irqbase + SA1111_WAKEEN0); 4681da177e4SLinus Torvalds sa1111_writel(0, irqbase + SA1111_WAKEEN1); 4691da177e4SLinus Torvalds 4701da177e4SLinus Torvalds /* 4711da177e4SLinus Torvalds * detect on rising edge. Note: Feb 2001 Errata for SA1111 4721da177e4SLinus Torvalds * specifies that S0ReadyInt and S1ReadyInt should be '1'. 4731da177e4SLinus Torvalds */ 4741da177e4SLinus Torvalds sa1111_writel(0, irqbase + SA1111_INTPOL0); 4757c0091ecSRussell King sa1111_writel(BIT(IRQ_S0_READY_NINT & 31) | 4767c0091ecSRussell King BIT(IRQ_S1_READY_NINT & 31), 4771da177e4SLinus Torvalds irqbase + SA1111_INTPOL1); 4781da177e4SLinus Torvalds 4791da177e4SLinus Torvalds /* clear all IRQs */ 4801da177e4SLinus Torvalds sa1111_writel(~0, irqbase + SA1111_INTSTATCLR0); 4811da177e4SLinus Torvalds sa1111_writel(~0, irqbase + SA1111_INTSTATCLR1); 4821da177e4SLinus Torvalds 483f03ecaa0SRussell King for (i = IRQ_GPAIN0; i <= SSPROR; i++) { 484f03ecaa0SRussell King irq = sachip->irq_base + i; 485f38c02f3SThomas Gleixner irq_set_chip_and_handler(irq, &sa1111_low_chip, 486f38c02f3SThomas Gleixner handle_edge_irq); 4879323f261SThomas Gleixner irq_set_chip_data(irq, sachip); 488e8d36d5dSRob Herring irq_clear_status_flags(irq, IRQ_NOREQUEST | IRQ_NOPROBE); 4891da177e4SLinus Torvalds } 4901da177e4SLinus Torvalds 491f03ecaa0SRussell King for (i = AUDXMTDMADONEA; i <= IRQ_S1_BVD1_STSCHG; i++) { 492f03ecaa0SRussell King irq = sachip->irq_base + i; 493f38c02f3SThomas Gleixner irq_set_chip_and_handler(irq, &sa1111_high_chip, 494f38c02f3SThomas Gleixner handle_edge_irq); 4959323f261SThomas Gleixner irq_set_chip_data(irq, sachip); 496e8d36d5dSRob Herring irq_clear_status_flags(irq, IRQ_NOREQUEST | IRQ_NOPROBE); 4971da177e4SLinus Torvalds } 4981da177e4SLinus Torvalds 4991da177e4SLinus Torvalds /* 5001da177e4SLinus Torvalds * Register SA1111 interrupt 5011da177e4SLinus Torvalds */ 5026845664aSThomas Gleixner irq_set_irq_type(sachip->irq, IRQ_TYPE_EDGE_RISING); 503056c0acfSRussell King irq_set_chained_handler_and_data(sachip->irq, sa1111_irq_handler, 504056c0acfSRussell King sachip); 50536d31213SRussell King 50636d31213SRussell King dev_info(sachip->dev, "Providing IRQ%u-%u\n", 50736d31213SRussell King sachip->irq_base, sachip->irq_base + SA1111_IRQ_NR - 1); 50836d31213SRussell King 50936d31213SRussell King return 0; 5101da177e4SLinus Torvalds } 5111da177e4SLinus Torvalds 5121da177e4SLinus Torvalds /* 5131da177e4SLinus Torvalds * Bring the SA1111 out of reset. This requires a set procedure: 5141da177e4SLinus Torvalds * 1. nRESET asserted (by hardware) 5151da177e4SLinus Torvalds * 2. CLK turned on from SA1110 5161da177e4SLinus Torvalds * 3. nRESET deasserted 5171da177e4SLinus Torvalds * 4. VCO turned on, PLL_BYPASS turned off 5181da177e4SLinus Torvalds * 5. Wait lock time, then assert RCLKEn 5191da177e4SLinus Torvalds * 7. PCR set to allow clocking of individual functions 5201da177e4SLinus Torvalds * 5211da177e4SLinus Torvalds * Until we've done this, the only registers we can access are: 5221da177e4SLinus Torvalds * SBI_SKCR 5231da177e4SLinus Torvalds * SBI_SMCR 5241da177e4SLinus Torvalds * SBI_SKID 5251da177e4SLinus Torvalds */ 5261da177e4SLinus Torvalds static void sa1111_wake(struct sa1111 *sachip) 5271da177e4SLinus Torvalds { 5281da177e4SLinus Torvalds unsigned long flags, r; 5291da177e4SLinus Torvalds 5301da177e4SLinus Torvalds spin_lock_irqsave(&sachip->lock, flags); 5311da177e4SLinus Torvalds 53297d654f8SRussell King clk_enable(sachip->clk); 5331da177e4SLinus Torvalds 5341da177e4SLinus Torvalds /* 5351da177e4SLinus Torvalds * Turn VCO on, and disable PLL Bypass. 5361da177e4SLinus Torvalds */ 5371da177e4SLinus Torvalds r = sa1111_readl(sachip->base + SA1111_SKCR); 5381da177e4SLinus Torvalds r &= ~SKCR_VCO_OFF; 5391da177e4SLinus Torvalds sa1111_writel(r, sachip->base + SA1111_SKCR); 5401da177e4SLinus Torvalds r |= SKCR_PLL_BYPASS | SKCR_OE_EN; 5411da177e4SLinus Torvalds sa1111_writel(r, sachip->base + SA1111_SKCR); 5421da177e4SLinus Torvalds 5431da177e4SLinus Torvalds /* 5441da177e4SLinus Torvalds * Wait lock time. SA1111 manual _doesn't_ 5451da177e4SLinus Torvalds * specify a figure for this! We choose 100us. 5461da177e4SLinus Torvalds */ 5471da177e4SLinus Torvalds udelay(100); 5481da177e4SLinus Torvalds 5491da177e4SLinus Torvalds /* 5501da177e4SLinus Torvalds * Enable RCLK. We also ensure that RDYEN is set. 5511da177e4SLinus Torvalds */ 5521da177e4SLinus Torvalds r |= SKCR_RCLKEN | SKCR_RDYEN; 5531da177e4SLinus Torvalds sa1111_writel(r, sachip->base + SA1111_SKCR); 5541da177e4SLinus Torvalds 5551da177e4SLinus Torvalds /* 5561da177e4SLinus Torvalds * Wait 14 RCLK cycles for the chip to finish coming out 5571da177e4SLinus Torvalds * of reset. (RCLK=24MHz). This is 590ns. 5581da177e4SLinus Torvalds */ 5591da177e4SLinus Torvalds udelay(1); 5601da177e4SLinus Torvalds 5611da177e4SLinus Torvalds /* 5621da177e4SLinus Torvalds * Ensure all clocks are initially off. 5631da177e4SLinus Torvalds */ 5641da177e4SLinus Torvalds sa1111_writel(0, sachip->base + SA1111_SKPCR); 5651da177e4SLinus Torvalds 5661da177e4SLinus Torvalds spin_unlock_irqrestore(&sachip->lock, flags); 5671da177e4SLinus Torvalds } 5681da177e4SLinus Torvalds 5691da177e4SLinus Torvalds #ifdef CONFIG_ARCH_SA1100 5701da177e4SLinus Torvalds 5711da177e4SLinus Torvalds static u32 sa1111_dma_mask[] = { 5721da177e4SLinus Torvalds ~0, 5731da177e4SLinus Torvalds ~(1 << 20), 5741da177e4SLinus Torvalds ~(1 << 23), 5751da177e4SLinus Torvalds ~(1 << 24), 5761da177e4SLinus Torvalds ~(1 << 25), 5771da177e4SLinus Torvalds ~(1 << 20), 5781da177e4SLinus Torvalds ~(1 << 20), 5791da177e4SLinus Torvalds 0, 5801da177e4SLinus Torvalds }; 5811da177e4SLinus Torvalds 5821da177e4SLinus Torvalds /* 5831da177e4SLinus Torvalds * Configure the SA1111 shared memory controller. 5841da177e4SLinus Torvalds */ 5851da177e4SLinus Torvalds void 5861da177e4SLinus Torvalds sa1111_configure_smc(struct sa1111 *sachip, int sdram, unsigned int drac, 5871da177e4SLinus Torvalds unsigned int cas_latency) 5881da177e4SLinus Torvalds { 5891da177e4SLinus Torvalds unsigned int smcr = SMCR_DTIM | SMCR_MBGE | FInsrt(drac, SMCR_DRAC); 5901da177e4SLinus Torvalds 5911da177e4SLinus Torvalds if (cas_latency == 3) 5921da177e4SLinus Torvalds smcr |= SMCR_CLAT; 5931da177e4SLinus Torvalds 5941da177e4SLinus Torvalds sa1111_writel(smcr, sachip->base + SA1111_SMCR); 5951da177e4SLinus Torvalds 5961da177e4SLinus Torvalds /* 5971da177e4SLinus Torvalds * Now clear the bits in the DMA mask to work around the SA1111 5981da177e4SLinus Torvalds * DMA erratum (Intel StrongARM SA-1111 Microprocessor Companion 5991da177e4SLinus Torvalds * Chip Specification Update, June 2000, Erratum #7). 6001da177e4SLinus Torvalds */ 6011da177e4SLinus Torvalds if (sachip->dev->dma_mask) 6021da177e4SLinus Torvalds *sachip->dev->dma_mask &= sa1111_dma_mask[drac >> 2]; 6031da177e4SLinus Torvalds 6041da177e4SLinus Torvalds sachip->dev->coherent_dma_mask &= sa1111_dma_mask[drac >> 2]; 6051da177e4SLinus Torvalds } 6060703ed2aSRussell King #endif 6071da177e4SLinus Torvalds 6081da177e4SLinus Torvalds static void sa1111_dev_release(struct device *_dev) 6091da177e4SLinus Torvalds { 6101da177e4SLinus Torvalds struct sa1111_dev *dev = SA1111_DEV(_dev); 6111da177e4SLinus Torvalds 6121da177e4SLinus Torvalds kfree(dev); 6131da177e4SLinus Torvalds } 6141da177e4SLinus Torvalds 6151da177e4SLinus Torvalds static int 6161da177e4SLinus Torvalds sa1111_init_one_child(struct sa1111 *sachip, struct resource *parent, 6171da177e4SLinus Torvalds struct sa1111_dev_info *info) 6181da177e4SLinus Torvalds { 6191da177e4SLinus Torvalds struct sa1111_dev *dev; 620f03ecaa0SRussell King unsigned i; 6211da177e4SLinus Torvalds int ret; 6221da177e4SLinus Torvalds 623d2a02b93SRussell King dev = kzalloc(sizeof(struct sa1111_dev), GFP_KERNEL); 6241da177e4SLinus Torvalds if (!dev) { 6251da177e4SLinus Torvalds ret = -ENOMEM; 626924e1d49SRussell King goto err_alloc; 6271da177e4SLinus Torvalds } 6281da177e4SLinus Torvalds 629924e1d49SRussell King device_initialize(&dev->dev); 6303f978704SKay Sievers dev_set_name(&dev->dev, "%4.4lx", info->offset); 6311da177e4SLinus Torvalds dev->devid = info->devid; 6321da177e4SLinus Torvalds dev->dev.parent = sachip->dev; 6331da177e4SLinus Torvalds dev->dev.bus = &sa1111_bus_type; 6341da177e4SLinus Torvalds dev->dev.release = sa1111_dev_release; 6351da177e4SLinus Torvalds dev->res.start = sachip->phys + info->offset; 6361da177e4SLinus Torvalds dev->res.end = dev->res.start + 511; 6373f978704SKay Sievers dev->res.name = dev_name(&dev->dev); 6381da177e4SLinus Torvalds dev->res.flags = IORESOURCE_MEM; 6391da177e4SLinus Torvalds dev->mapbase = sachip->base + info->offset; 6401da177e4SLinus Torvalds dev->skpcr_mask = info->skpcr_mask; 641f03ecaa0SRussell King 642f03ecaa0SRussell King for (i = 0; i < ARRAY_SIZE(info->irq); i++) 643f03ecaa0SRussell King dev->irq[i] = sachip->irq_base + info->irq[i]; 6441da177e4SLinus Torvalds 64509a2ba2fSRussell King /* 64621d1c770SRussell King * If the parent device has a DMA mask associated with it, and 64721d1c770SRussell King * this child supports DMA, propagate it down to the children. 64809a2ba2fSRussell King */ 64921d1c770SRussell King if (info->dma && sachip->dev->dma_mask) { 65009a2ba2fSRussell King dev->dma_mask = *sachip->dev->dma_mask; 65109a2ba2fSRussell King dev->dev.dma_mask = &dev->dma_mask; 65209a2ba2fSRussell King dev->dev.coherent_dma_mask = sachip->dev->coherent_dma_mask; 65309a2ba2fSRussell King } 65409a2ba2fSRussell King 6551da177e4SLinus Torvalds ret = request_resource(parent, &dev->res); 6561da177e4SLinus Torvalds if (ret) { 65722eeaff3SRussell King dev_err(sachip->dev, "failed to allocate resource for %s\n", 6581da177e4SLinus Torvalds dev->res.name); 659924e1d49SRussell King goto err_resource; 6601da177e4SLinus Torvalds } 6611da177e4SLinus Torvalds 662924e1d49SRussell King ret = device_add(&dev->dev); 663924e1d49SRussell King if (ret) 664924e1d49SRussell King goto err_add; 665924e1d49SRussell King return 0; 666924e1d49SRussell King 667924e1d49SRussell King err_add: 6681da177e4SLinus Torvalds release_resource(&dev->res); 669924e1d49SRussell King err_resource: 670924e1d49SRussell King put_device(&dev->dev); 671924e1d49SRussell King err_alloc: 6721da177e4SLinus Torvalds return ret; 6731da177e4SLinus Torvalds } 6741da177e4SLinus Torvalds 6751da177e4SLinus Torvalds /** 6761da177e4SLinus Torvalds * sa1111_probe - probe for a single SA1111 chip. 6771da177e4SLinus Torvalds * @phys_addr: physical address of device. 6781da177e4SLinus Torvalds * 6791da177e4SLinus Torvalds * Probe for a SA1111 chip. This must be called 6801da177e4SLinus Torvalds * before any other SA1111-specific code. 6811da177e4SLinus Torvalds * 6821da177e4SLinus Torvalds * Returns: 6831da177e4SLinus Torvalds * %-ENODEV device not found. 6841da177e4SLinus Torvalds * %-EBUSY physical address already marked in-use. 685f03ecaa0SRussell King * %-EINVAL no platform data passed 6861da177e4SLinus Torvalds * %0 successful. 6871da177e4SLinus Torvalds */ 688351a102dSGreg Kroah-Hartman static int __sa1111_probe(struct device *me, struct resource *mem, int irq) 6891da177e4SLinus Torvalds { 690f03ecaa0SRussell King struct sa1111_platform_data *pd = me->platform_data; 6911da177e4SLinus Torvalds struct sa1111 *sachip; 6921da177e4SLinus Torvalds unsigned long id; 693416112f8SDavid Brownell unsigned int has_devs; 6941da177e4SLinus Torvalds int i, ret = -ENODEV; 6951da177e4SLinus Torvalds 696f03ecaa0SRussell King if (!pd) 697f03ecaa0SRussell King return -EINVAL; 698f03ecaa0SRussell King 699*7d53c1f0SRussell King sachip = devm_kzalloc(me, sizeof(struct sa1111), GFP_KERNEL); 7001da177e4SLinus Torvalds if (!sachip) 7011da177e4SLinus Torvalds return -ENOMEM; 7021da177e4SLinus Torvalds 70313f75582SIan Molton sachip->clk = clk_get(me, "SA1111_CLK"); 704442a9022SJulia Lawall if (IS_ERR(sachip->clk)) { 70597d654f8SRussell King ret = PTR_ERR(sachip->clk); 70697d654f8SRussell King goto err_free; 70797d654f8SRussell King } 70897d654f8SRussell King 70972ae00c9SRussell King ret = clk_prepare(sachip->clk); 71072ae00c9SRussell King if (ret) 71172ae00c9SRussell King goto err_clkput; 71272ae00c9SRussell King 7131da177e4SLinus Torvalds spin_lock_init(&sachip->lock); 7141da177e4SLinus Torvalds 7151da177e4SLinus Torvalds sachip->dev = me; 7161da177e4SLinus Torvalds dev_set_drvdata(sachip->dev, sachip); 7171da177e4SLinus Torvalds 718ae99ddbcSRussell King sachip->pdata = pd; 7191da177e4SLinus Torvalds sachip->phys = mem->start; 7201da177e4SLinus Torvalds sachip->irq = irq; 7211da177e4SLinus Torvalds 7221da177e4SLinus Torvalds /* 7231da177e4SLinus Torvalds * Map the whole region. This also maps the 7241da177e4SLinus Torvalds * registers for our children. 7251da177e4SLinus Torvalds */ 7261da177e4SLinus Torvalds sachip->base = ioremap(mem->start, PAGE_SIZE * 2); 7271da177e4SLinus Torvalds if (!sachip->base) { 7281da177e4SLinus Torvalds ret = -ENOMEM; 72972ae00c9SRussell King goto err_clk_unprep; 7301da177e4SLinus Torvalds } 7311da177e4SLinus Torvalds 7321da177e4SLinus Torvalds /* 7331da177e4SLinus Torvalds * Probe for the chip. Only touch the SBI registers. 7341da177e4SLinus Torvalds */ 7351da177e4SLinus Torvalds id = sa1111_readl(sachip->base + SA1111_SKID); 7361da177e4SLinus Torvalds if ((id & SKID_ID_MASK) != SKID_SA1111_ID) { 7371da177e4SLinus Torvalds printk(KERN_DEBUG "SA1111 not detected: ID = %08lx\n", id); 7381da177e4SLinus Torvalds ret = -ENODEV; 73997d654f8SRussell King goto err_unmap; 7401da177e4SLinus Torvalds } 7411da177e4SLinus Torvalds 7424ed89f22SRussell King pr_info("SA1111 Microprocessor Companion Chip: silicon revision %lx, metal revision %lx\n", 7434ed89f22SRussell King (id & SKID_SIREV_MASK) >> 4, id & SKID_MTREV_MASK); 7441da177e4SLinus Torvalds 7451da177e4SLinus Torvalds /* 7461da177e4SLinus Torvalds * We found it. Wake the chip up, and initialise. 7471da177e4SLinus Torvalds */ 7481da177e4SLinus Torvalds sa1111_wake(sachip); 7491da177e4SLinus Torvalds 75036d31213SRussell King /* 75136d31213SRussell King * The interrupt controller must be initialised before any 75236d31213SRussell King * other device to ensure that the interrupts are available. 75336d31213SRussell King */ 75436d31213SRussell King if (sachip->irq != NO_IRQ) { 75536d31213SRussell King ret = sa1111_setup_irq(sachip, pd->irq_base); 75636d31213SRussell King if (ret) 75787d5dd62SRussell King goto err_clk; 75836d31213SRussell King } 75936d31213SRussell King 7601da177e4SLinus Torvalds #ifdef CONFIG_ARCH_SA1100 761416112f8SDavid Brownell { 762416112f8SDavid Brownell unsigned int val; 763416112f8SDavid Brownell 7641da177e4SLinus Torvalds /* 7651da177e4SLinus Torvalds * The SDRAM configuration of the SA1110 and the SA1111 must 7661da177e4SLinus Torvalds * match. This is very important to ensure that SA1111 accesses 7671da177e4SLinus Torvalds * don't corrupt the SDRAM. Note that this ungates the SA1111's 7681da177e4SLinus Torvalds * MBGNT signal, so we must have called sa1110_mb_disable() 7691da177e4SLinus Torvalds * beforehand. 7701da177e4SLinus Torvalds */ 7711da177e4SLinus Torvalds sa1111_configure_smc(sachip, 1, 7721da177e4SLinus Torvalds FExtr(MDCNFG, MDCNFG_SA1110_DRAC0), 7731da177e4SLinus Torvalds FExtr(MDCNFG, MDCNFG_SA1110_TDL0)); 7741da177e4SLinus Torvalds 7751da177e4SLinus Torvalds /* 7761da177e4SLinus Torvalds * We only need to turn on DCLK whenever we want to use the 7771da177e4SLinus Torvalds * DMA. It can otherwise be held firmly in the off position. 7781da177e4SLinus Torvalds * (currently, we always enable it.) 7791da177e4SLinus Torvalds */ 7801da177e4SLinus Torvalds val = sa1111_readl(sachip->base + SA1111_SKPCR); 7811da177e4SLinus Torvalds sa1111_writel(val | SKPCR_DCLKEN, sachip->base + SA1111_SKPCR); 7821da177e4SLinus Torvalds 7831da177e4SLinus Torvalds /* 7841da177e4SLinus Torvalds * Enable the SA1110 memory bus request and grant signals. 7851da177e4SLinus Torvalds */ 7861da177e4SLinus Torvalds sa1110_mb_enable(); 787416112f8SDavid Brownell } 7881da177e4SLinus Torvalds #endif 7891da177e4SLinus Torvalds 7901da177e4SLinus Torvalds g_sa1111 = sachip; 7911da177e4SLinus Torvalds 7921da177e4SLinus Torvalds has_devs = ~0; 79307be45f5SRussell King if (pd) 79407be45f5SRussell King has_devs &= ~pd->disable_devs; 7951da177e4SLinus Torvalds 7961da177e4SLinus Torvalds for (i = 0; i < ARRAY_SIZE(sa1111_devices); i++) 797e5c0fc41SRussell King if (sa1111_devices[i].devid & has_devs) 7981da177e4SLinus Torvalds sa1111_init_one_child(sachip, mem, &sa1111_devices[i]); 7991da177e4SLinus Torvalds 8001da177e4SLinus Torvalds return 0; 8011da177e4SLinus Torvalds 80287d5dd62SRussell King err_clk: 80387d5dd62SRussell King clk_disable(sachip->clk); 80497d654f8SRussell King err_unmap: 8051da177e4SLinus Torvalds iounmap(sachip->base); 80672ae00c9SRussell King err_clk_unprep: 80772ae00c9SRussell King clk_unprepare(sachip->clk); 80897d654f8SRussell King err_clkput: 80997d654f8SRussell King clk_put(sachip->clk); 81097d654f8SRussell King err_free: 8111da177e4SLinus Torvalds return ret; 8121da177e4SLinus Torvalds } 8131da177e4SLinus Torvalds 814522c37b9SRussell King static int sa1111_remove_one(struct device *dev, void *data) 815522c37b9SRussell King { 816924e1d49SRussell King struct sa1111_dev *sadev = SA1111_DEV(dev); 817eac8dbf7SRussell King if (dev->bus != &sa1111_bus_type) 818eac8dbf7SRussell King return 0; 819924e1d49SRussell King device_del(&sadev->dev); 820924e1d49SRussell King release_resource(&sadev->res); 821924e1d49SRussell King put_device(&sadev->dev); 822522c37b9SRussell King return 0; 823522c37b9SRussell King } 824522c37b9SRussell King 8251da177e4SLinus Torvalds static void __sa1111_remove(struct sa1111 *sachip) 8261da177e4SLinus Torvalds { 8271da177e4SLinus Torvalds void __iomem *irqbase = sachip->base + SA1111_INTC; 8281da177e4SLinus Torvalds 829522c37b9SRussell King device_for_each_child(sachip->dev, NULL, sa1111_remove_one); 8301da177e4SLinus Torvalds 8311da177e4SLinus Torvalds /* disable all IRQs */ 8321da177e4SLinus Torvalds sa1111_writel(0, irqbase + SA1111_INTEN0); 8331da177e4SLinus Torvalds sa1111_writel(0, irqbase + SA1111_INTEN1); 8341da177e4SLinus Torvalds sa1111_writel(0, irqbase + SA1111_WAKEEN0); 8351da177e4SLinus Torvalds sa1111_writel(0, irqbase + SA1111_WAKEEN1); 8361da177e4SLinus Torvalds 83797d654f8SRussell King clk_disable(sachip->clk); 83872ae00c9SRussell King clk_unprepare(sachip->clk); 83997d654f8SRussell King 8401da177e4SLinus Torvalds if (sachip->irq != NO_IRQ) { 841056c0acfSRussell King irq_set_chained_handler_and_data(sachip->irq, NULL, NULL); 84236d31213SRussell King irq_free_descs(sachip->irq_base, SA1111_IRQ_NR); 8431da177e4SLinus Torvalds 8441da177e4SLinus Torvalds release_mem_region(sachip->phys + SA1111_INTC, 512); 8451da177e4SLinus Torvalds } 8461da177e4SLinus Torvalds 8471da177e4SLinus Torvalds iounmap(sachip->base); 84897d654f8SRussell King clk_put(sachip->clk); 8491da177e4SLinus Torvalds } 8501da177e4SLinus Torvalds 8511da177e4SLinus Torvalds struct sa1111_save_data { 8521da177e4SLinus Torvalds unsigned int skcr; 8531da177e4SLinus Torvalds unsigned int skpcr; 8541da177e4SLinus Torvalds unsigned int skcdr; 8551da177e4SLinus Torvalds unsigned char skaud; 8561da177e4SLinus Torvalds unsigned char skpwm0; 8571da177e4SLinus Torvalds unsigned char skpwm1; 8581da177e4SLinus Torvalds 8591da177e4SLinus Torvalds /* 8601da177e4SLinus Torvalds * Interrupt controller 8611da177e4SLinus Torvalds */ 8621da177e4SLinus Torvalds unsigned int intpol0; 8631da177e4SLinus Torvalds unsigned int intpol1; 8641da177e4SLinus Torvalds unsigned int inten0; 8651da177e4SLinus Torvalds unsigned int inten1; 8661da177e4SLinus Torvalds unsigned int wakepol0; 8671da177e4SLinus Torvalds unsigned int wakepol1; 8681da177e4SLinus Torvalds unsigned int wakeen0; 8691da177e4SLinus Torvalds unsigned int wakeen1; 8701da177e4SLinus Torvalds }; 8711da177e4SLinus Torvalds 8721da177e4SLinus Torvalds #ifdef CONFIG_PM 8731da177e4SLinus Torvalds 87406dfe5ccSRussell King static int sa1111_suspend_noirq(struct device *dev) 8751da177e4SLinus Torvalds { 87606dfe5ccSRussell King struct sa1111 *sachip = dev_get_drvdata(dev); 8771da177e4SLinus Torvalds struct sa1111_save_data *save; 8781da177e4SLinus Torvalds unsigned long flags; 8791da177e4SLinus Torvalds unsigned int val; 8801da177e4SLinus Torvalds void __iomem *base; 8811da177e4SLinus Torvalds 8821da177e4SLinus Torvalds save = kmalloc(sizeof(struct sa1111_save_data), GFP_KERNEL); 8831da177e4SLinus Torvalds if (!save) 8841da177e4SLinus Torvalds return -ENOMEM; 88593160c63SRafael J. Wysocki sachip->saved_state = save; 8861da177e4SLinus Torvalds 8871da177e4SLinus Torvalds spin_lock_irqsave(&sachip->lock, flags); 8881da177e4SLinus Torvalds 8891da177e4SLinus Torvalds /* 8901da177e4SLinus Torvalds * Save state. 8911da177e4SLinus Torvalds */ 8921da177e4SLinus Torvalds base = sachip->base; 8931da177e4SLinus Torvalds save->skcr = sa1111_readl(base + SA1111_SKCR); 8941da177e4SLinus Torvalds save->skpcr = sa1111_readl(base + SA1111_SKPCR); 8951da177e4SLinus Torvalds save->skcdr = sa1111_readl(base + SA1111_SKCDR); 8961da177e4SLinus Torvalds save->skaud = sa1111_readl(base + SA1111_SKAUD); 8971da177e4SLinus Torvalds save->skpwm0 = sa1111_readl(base + SA1111_SKPWM0); 8981da177e4SLinus Torvalds save->skpwm1 = sa1111_readl(base + SA1111_SKPWM1); 8991da177e4SLinus Torvalds 900a22db0f3SRussell King sa1111_writel(0, sachip->base + SA1111_SKPWM0); 901a22db0f3SRussell King sa1111_writel(0, sachip->base + SA1111_SKPWM1); 902a22db0f3SRussell King 9031da177e4SLinus Torvalds base = sachip->base + SA1111_INTC; 9041da177e4SLinus Torvalds save->intpol0 = sa1111_readl(base + SA1111_INTPOL0); 9051da177e4SLinus Torvalds save->intpol1 = sa1111_readl(base + SA1111_INTPOL1); 9061da177e4SLinus Torvalds save->inten0 = sa1111_readl(base + SA1111_INTEN0); 9071da177e4SLinus Torvalds save->inten1 = sa1111_readl(base + SA1111_INTEN1); 9081da177e4SLinus Torvalds save->wakepol0 = sa1111_readl(base + SA1111_WAKEPOL0); 9091da177e4SLinus Torvalds save->wakepol1 = sa1111_readl(base + SA1111_WAKEPOL1); 9101da177e4SLinus Torvalds save->wakeen0 = sa1111_readl(base + SA1111_WAKEEN0); 9111da177e4SLinus Torvalds save->wakeen1 = sa1111_readl(base + SA1111_WAKEEN1); 9121da177e4SLinus Torvalds 9131da177e4SLinus Torvalds /* 9141da177e4SLinus Torvalds * Disable. 9151da177e4SLinus Torvalds */ 9161da177e4SLinus Torvalds val = sa1111_readl(sachip->base + SA1111_SKCR); 9171da177e4SLinus Torvalds sa1111_writel(val | SKCR_SLEEP, sachip->base + SA1111_SKCR); 9181da177e4SLinus Torvalds 91997d654f8SRussell King clk_disable(sachip->clk); 92097d654f8SRussell King 9211da177e4SLinus Torvalds spin_unlock_irqrestore(&sachip->lock, flags); 9221da177e4SLinus Torvalds 92329c140b6SRussell King #ifdef CONFIG_ARCH_SA1100 92429c140b6SRussell King sa1110_mb_disable(); 92529c140b6SRussell King #endif 92629c140b6SRussell King 9271da177e4SLinus Torvalds return 0; 9281da177e4SLinus Torvalds } 9291da177e4SLinus Torvalds 9301da177e4SLinus Torvalds /* 9311da177e4SLinus Torvalds * sa1111_resume - Restore the SA1111 device state. 9321da177e4SLinus Torvalds * @dev: device to restore 9331da177e4SLinus Torvalds * 9341da177e4SLinus Torvalds * Restore the general state of the SA1111; clock control and 9351da177e4SLinus Torvalds * interrupt controller. Other parts of the SA1111 must be 9361da177e4SLinus Torvalds * restored by their respective drivers, and must be called 9371da177e4SLinus Torvalds * via LDM after this function. 9381da177e4SLinus Torvalds */ 93906dfe5ccSRussell King static int sa1111_resume_noirq(struct device *dev) 9401da177e4SLinus Torvalds { 94106dfe5ccSRussell King struct sa1111 *sachip = dev_get_drvdata(dev); 9421da177e4SLinus Torvalds struct sa1111_save_data *save; 9431da177e4SLinus Torvalds unsigned long flags, id; 9441da177e4SLinus Torvalds void __iomem *base; 9451da177e4SLinus Torvalds 94693160c63SRafael J. Wysocki save = sachip->saved_state; 9471da177e4SLinus Torvalds if (!save) 9481da177e4SLinus Torvalds return 0; 9491da177e4SLinus Torvalds 9501da177e4SLinus Torvalds /* 9511da177e4SLinus Torvalds * Ensure that the SA1111 is still here. 9521da177e4SLinus Torvalds * FIXME: shouldn't do this here. 9531da177e4SLinus Torvalds */ 9541da177e4SLinus Torvalds id = sa1111_readl(sachip->base + SA1111_SKID); 9551da177e4SLinus Torvalds if ((id & SKID_ID_MASK) != SKID_SA1111_ID) { 9561da177e4SLinus Torvalds __sa1111_remove(sachip); 95706dfe5ccSRussell King dev_set_drvdata(dev, NULL); 9581da177e4SLinus Torvalds kfree(save); 9591da177e4SLinus Torvalds return 0; 9601da177e4SLinus Torvalds } 9611da177e4SLinus Torvalds 9621da177e4SLinus Torvalds /* 9631da177e4SLinus Torvalds * First of all, wake up the chip. 9641da177e4SLinus Torvalds */ 9651da177e4SLinus Torvalds sa1111_wake(sachip); 9663defb247SMarek Vašut 96729c140b6SRussell King #ifdef CONFIG_ARCH_SA1100 96829c140b6SRussell King /* Enable the memory bus request/grant signals */ 96929c140b6SRussell King sa1110_mb_enable(); 97029c140b6SRussell King #endif 97129c140b6SRussell King 9723defb247SMarek Vašut /* 9733defb247SMarek Vašut * Only lock for write ops. Also, sa1111_wake must be called with 9743defb247SMarek Vašut * released spinlock! 9753defb247SMarek Vašut */ 9763defb247SMarek Vašut spin_lock_irqsave(&sachip->lock, flags); 9773defb247SMarek Vašut 9781da177e4SLinus Torvalds sa1111_writel(0, sachip->base + SA1111_INTC + SA1111_INTEN0); 9791da177e4SLinus Torvalds sa1111_writel(0, sachip->base + SA1111_INTC + SA1111_INTEN1); 9801da177e4SLinus Torvalds 9811da177e4SLinus Torvalds base = sachip->base; 9821da177e4SLinus Torvalds sa1111_writel(save->skcr, base + SA1111_SKCR); 9831da177e4SLinus Torvalds sa1111_writel(save->skpcr, base + SA1111_SKPCR); 9841da177e4SLinus Torvalds sa1111_writel(save->skcdr, base + SA1111_SKCDR); 9851da177e4SLinus Torvalds sa1111_writel(save->skaud, base + SA1111_SKAUD); 9861da177e4SLinus Torvalds sa1111_writel(save->skpwm0, base + SA1111_SKPWM0); 9871da177e4SLinus Torvalds sa1111_writel(save->skpwm1, base + SA1111_SKPWM1); 9881da177e4SLinus Torvalds 9891da177e4SLinus Torvalds base = sachip->base + SA1111_INTC; 9901da177e4SLinus Torvalds sa1111_writel(save->intpol0, base + SA1111_INTPOL0); 9911da177e4SLinus Torvalds sa1111_writel(save->intpol1, base + SA1111_INTPOL1); 9921da177e4SLinus Torvalds sa1111_writel(save->inten0, base + SA1111_INTEN0); 9931da177e4SLinus Torvalds sa1111_writel(save->inten1, base + SA1111_INTEN1); 9941da177e4SLinus Torvalds sa1111_writel(save->wakepol0, base + SA1111_WAKEPOL0); 9951da177e4SLinus Torvalds sa1111_writel(save->wakepol1, base + SA1111_WAKEPOL1); 9961da177e4SLinus Torvalds sa1111_writel(save->wakeen0, base + SA1111_WAKEEN0); 9971da177e4SLinus Torvalds sa1111_writel(save->wakeen1, base + SA1111_WAKEEN1); 9981da177e4SLinus Torvalds 9991da177e4SLinus Torvalds spin_unlock_irqrestore(&sachip->lock, flags); 10001da177e4SLinus Torvalds 100193160c63SRafael J. Wysocki sachip->saved_state = NULL; 10021da177e4SLinus Torvalds kfree(save); 10031da177e4SLinus Torvalds 10041da177e4SLinus Torvalds return 0; 10051da177e4SLinus Torvalds } 10061da177e4SLinus Torvalds 10071da177e4SLinus Torvalds #else 100806dfe5ccSRussell King #define sa1111_suspend_noirq NULL 100906dfe5ccSRussell King #define sa1111_resume_noirq NULL 10101da177e4SLinus Torvalds #endif 10111da177e4SLinus Torvalds 1012351a102dSGreg Kroah-Hartman static int sa1111_probe(struct platform_device *pdev) 10131da177e4SLinus Torvalds { 10141da177e4SLinus Torvalds struct resource *mem; 10151da177e4SLinus Torvalds int irq; 10161da177e4SLinus Torvalds 10171da177e4SLinus Torvalds mem = platform_get_resource(pdev, IORESOURCE_MEM, 0); 10181da177e4SLinus Torvalds if (!mem) 10191da177e4SLinus Torvalds return -EINVAL; 10201da177e4SLinus Torvalds irq = platform_get_irq(pdev, 0); 102148944738SDavid Vrabel if (irq < 0) 1022cb034407SRussell King return irq; 10231da177e4SLinus Torvalds 10243ae5eaecSRussell King return __sa1111_probe(&pdev->dev, mem, irq); 10251da177e4SLinus Torvalds } 10261da177e4SLinus Torvalds 10273ae5eaecSRussell King static int sa1111_remove(struct platform_device *pdev) 10281da177e4SLinus Torvalds { 10293ae5eaecSRussell King struct sa1111 *sachip = platform_get_drvdata(pdev); 10301da177e4SLinus Torvalds 10311da177e4SLinus Torvalds if (sachip) { 10321da177e4SLinus Torvalds #ifdef CONFIG_PM 103393160c63SRafael J. Wysocki kfree(sachip->saved_state); 103493160c63SRafael J. Wysocki sachip->saved_state = NULL; 10351da177e4SLinus Torvalds #endif 1036f2d2420bSJulia Lawall __sa1111_remove(sachip); 1037f2d2420bSJulia Lawall platform_set_drvdata(pdev, NULL); 10381da177e4SLinus Torvalds } 10391da177e4SLinus Torvalds 10401da177e4SLinus Torvalds return 0; 10411da177e4SLinus Torvalds } 10421da177e4SLinus Torvalds 104306dfe5ccSRussell King static struct dev_pm_ops sa1111_pm_ops = { 104406dfe5ccSRussell King .suspend_noirq = sa1111_suspend_noirq, 104506dfe5ccSRussell King .resume_noirq = sa1111_resume_noirq, 104606dfe5ccSRussell King }; 104706dfe5ccSRussell King 10481da177e4SLinus Torvalds /* 10491da177e4SLinus Torvalds * Not sure if this should be on the system bus or not yet. 10501da177e4SLinus Torvalds * We really want some way to register a system device at 10511da177e4SLinus Torvalds * the per-machine level, and then have this driver pick 10521da177e4SLinus Torvalds * up the registered devices. 10531da177e4SLinus Torvalds * 10541da177e4SLinus Torvalds * We also need to handle the SDRAM configuration for 10551da177e4SLinus Torvalds * PXA250/SA1110 machine classes. 10561da177e4SLinus Torvalds */ 10573ae5eaecSRussell King static struct platform_driver sa1111_device_driver = { 10581da177e4SLinus Torvalds .probe = sa1111_probe, 10591da177e4SLinus Torvalds .remove = sa1111_remove, 10603ae5eaecSRussell King .driver = { 10613ae5eaecSRussell King .name = "sa1111", 106206dfe5ccSRussell King .pm = &sa1111_pm_ops, 10633ae5eaecSRussell King }, 10641da177e4SLinus Torvalds }; 10651da177e4SLinus Torvalds 10661da177e4SLinus Torvalds /* 10671da177e4SLinus Torvalds * Get the parent device driver (us) structure 10681da177e4SLinus Torvalds * from a child function device 10691da177e4SLinus Torvalds */ 10701da177e4SLinus Torvalds static inline struct sa1111 *sa1111_chip_driver(struct sa1111_dev *sadev) 10711da177e4SLinus Torvalds { 10721da177e4SLinus Torvalds return (struct sa1111 *)dev_get_drvdata(sadev->dev.parent); 10731da177e4SLinus Torvalds } 10741da177e4SLinus Torvalds 10751da177e4SLinus Torvalds /* 10761da177e4SLinus Torvalds * The bits in the opdiv field are non-linear. 10771da177e4SLinus Torvalds */ 10781da177e4SLinus Torvalds static unsigned char opdiv_table[] = { 1, 4, 2, 8 }; 10791da177e4SLinus Torvalds 10801da177e4SLinus Torvalds static unsigned int __sa1111_pll_clock(struct sa1111 *sachip) 10811da177e4SLinus Torvalds { 10821da177e4SLinus Torvalds unsigned int skcdr, fbdiv, ipdiv, opdiv; 10831da177e4SLinus Torvalds 10841da177e4SLinus Torvalds skcdr = sa1111_readl(sachip->base + SA1111_SKCDR); 10851da177e4SLinus Torvalds 10861da177e4SLinus Torvalds fbdiv = (skcdr & 0x007f) + 2; 10871da177e4SLinus Torvalds ipdiv = ((skcdr & 0x0f80) >> 7) + 2; 10881da177e4SLinus Torvalds opdiv = opdiv_table[(skcdr & 0x3000) >> 12]; 10891da177e4SLinus Torvalds 10901da177e4SLinus Torvalds return 3686400 * fbdiv / (ipdiv * opdiv); 10911da177e4SLinus Torvalds } 10921da177e4SLinus Torvalds 10931da177e4SLinus Torvalds /** 10941da177e4SLinus Torvalds * sa1111_pll_clock - return the current PLL clock frequency. 10951da177e4SLinus Torvalds * @sadev: SA1111 function block 10961da177e4SLinus Torvalds * 10971da177e4SLinus Torvalds * BUG: we should look at SKCR. We also blindly believe that 10981da177e4SLinus Torvalds * the chip is being fed with the 3.6864MHz clock. 10991da177e4SLinus Torvalds * 11001da177e4SLinus Torvalds * Returns the PLL clock in Hz. 11011da177e4SLinus Torvalds */ 11021da177e4SLinus Torvalds unsigned int sa1111_pll_clock(struct sa1111_dev *sadev) 11031da177e4SLinus Torvalds { 11041da177e4SLinus Torvalds struct sa1111 *sachip = sa1111_chip_driver(sadev); 11051da177e4SLinus Torvalds 11061da177e4SLinus Torvalds return __sa1111_pll_clock(sachip); 11071da177e4SLinus Torvalds } 11080a4bc5e8SHartley Sweeten EXPORT_SYMBOL(sa1111_pll_clock); 11091da177e4SLinus Torvalds 11101da177e4SLinus Torvalds /** 11111da177e4SLinus Torvalds * sa1111_select_audio_mode - select I2S or AC link mode 11121da177e4SLinus Torvalds * @sadev: SA1111 function block 11131da177e4SLinus Torvalds * @mode: One of %SA1111_AUDIO_ACLINK or %SA1111_AUDIO_I2S 11141da177e4SLinus Torvalds * 11151da177e4SLinus Torvalds * Frob the SKCR to select AC Link mode or I2S mode for 11161da177e4SLinus Torvalds * the audio block. 11171da177e4SLinus Torvalds */ 11181da177e4SLinus Torvalds void sa1111_select_audio_mode(struct sa1111_dev *sadev, int mode) 11191da177e4SLinus Torvalds { 11201da177e4SLinus Torvalds struct sa1111 *sachip = sa1111_chip_driver(sadev); 11211da177e4SLinus Torvalds unsigned long flags; 11221da177e4SLinus Torvalds unsigned int val; 11231da177e4SLinus Torvalds 11241da177e4SLinus Torvalds spin_lock_irqsave(&sachip->lock, flags); 11251da177e4SLinus Torvalds 11261da177e4SLinus Torvalds val = sa1111_readl(sachip->base + SA1111_SKCR); 11271da177e4SLinus Torvalds if (mode == SA1111_AUDIO_I2S) { 11281da177e4SLinus Torvalds val &= ~SKCR_SELAC; 11291da177e4SLinus Torvalds } else { 11301da177e4SLinus Torvalds val |= SKCR_SELAC; 11311da177e4SLinus Torvalds } 11321da177e4SLinus Torvalds sa1111_writel(val, sachip->base + SA1111_SKCR); 11331da177e4SLinus Torvalds 11341da177e4SLinus Torvalds spin_unlock_irqrestore(&sachip->lock, flags); 11351da177e4SLinus Torvalds } 11360a4bc5e8SHartley Sweeten EXPORT_SYMBOL(sa1111_select_audio_mode); 11371da177e4SLinus Torvalds 11381da177e4SLinus Torvalds /** 11391da177e4SLinus Torvalds * sa1111_set_audio_rate - set the audio sample rate 11401da177e4SLinus Torvalds * @sadev: SA1111 SAC function block 11411da177e4SLinus Torvalds * @rate: sample rate to select 11421da177e4SLinus Torvalds */ 11431da177e4SLinus Torvalds int sa1111_set_audio_rate(struct sa1111_dev *sadev, int rate) 11441da177e4SLinus Torvalds { 11451da177e4SLinus Torvalds struct sa1111 *sachip = sa1111_chip_driver(sadev); 11461da177e4SLinus Torvalds unsigned int div; 11471da177e4SLinus Torvalds 11481da177e4SLinus Torvalds if (sadev->devid != SA1111_DEVID_SAC) 11491da177e4SLinus Torvalds return -EINVAL; 11501da177e4SLinus Torvalds 11511da177e4SLinus Torvalds div = (__sa1111_pll_clock(sachip) / 256 + rate / 2) / rate; 11521da177e4SLinus Torvalds if (div == 0) 11531da177e4SLinus Torvalds div = 1; 11541da177e4SLinus Torvalds if (div > 128) 11551da177e4SLinus Torvalds div = 128; 11561da177e4SLinus Torvalds 11571da177e4SLinus Torvalds sa1111_writel(div - 1, sachip->base + SA1111_SKAUD); 11581da177e4SLinus Torvalds 11591da177e4SLinus Torvalds return 0; 11601da177e4SLinus Torvalds } 11610a4bc5e8SHartley Sweeten EXPORT_SYMBOL(sa1111_set_audio_rate); 11621da177e4SLinus Torvalds 11631da177e4SLinus Torvalds /** 11641da177e4SLinus Torvalds * sa1111_get_audio_rate - get the audio sample rate 11651da177e4SLinus Torvalds * @sadev: SA1111 SAC function block device 11661da177e4SLinus Torvalds */ 11671da177e4SLinus Torvalds int sa1111_get_audio_rate(struct sa1111_dev *sadev) 11681da177e4SLinus Torvalds { 11691da177e4SLinus Torvalds struct sa1111 *sachip = sa1111_chip_driver(sadev); 11701da177e4SLinus Torvalds unsigned long div; 11711da177e4SLinus Torvalds 11721da177e4SLinus Torvalds if (sadev->devid != SA1111_DEVID_SAC) 11731da177e4SLinus Torvalds return -EINVAL; 11741da177e4SLinus Torvalds 11751da177e4SLinus Torvalds div = sa1111_readl(sachip->base + SA1111_SKAUD) + 1; 11761da177e4SLinus Torvalds 11771da177e4SLinus Torvalds return __sa1111_pll_clock(sachip) / (256 * div); 11781da177e4SLinus Torvalds } 11790a4bc5e8SHartley Sweeten EXPORT_SYMBOL(sa1111_get_audio_rate); 11801da177e4SLinus Torvalds 11811da177e4SLinus Torvalds void sa1111_set_io_dir(struct sa1111_dev *sadev, 11821da177e4SLinus Torvalds unsigned int bits, unsigned int dir, 11831da177e4SLinus Torvalds unsigned int sleep_dir) 11841da177e4SLinus Torvalds { 11851da177e4SLinus Torvalds struct sa1111 *sachip = sa1111_chip_driver(sadev); 11861da177e4SLinus Torvalds unsigned long flags; 11871da177e4SLinus Torvalds unsigned int val; 11881da177e4SLinus Torvalds void __iomem *gpio = sachip->base + SA1111_GPIO; 11891da177e4SLinus Torvalds 11901da177e4SLinus Torvalds #define MODIFY_BITS(port, mask, dir) \ 11911da177e4SLinus Torvalds if (mask) { \ 11921da177e4SLinus Torvalds val = sa1111_readl(port); \ 11931da177e4SLinus Torvalds val &= ~(mask); \ 11941da177e4SLinus Torvalds val |= (dir) & (mask); \ 11951da177e4SLinus Torvalds sa1111_writel(val, port); \ 11961da177e4SLinus Torvalds } 11971da177e4SLinus Torvalds 11981da177e4SLinus Torvalds spin_lock_irqsave(&sachip->lock, flags); 11991da177e4SLinus Torvalds MODIFY_BITS(gpio + SA1111_GPIO_PADDR, bits & 15, dir); 12001da177e4SLinus Torvalds MODIFY_BITS(gpio + SA1111_GPIO_PBDDR, (bits >> 8) & 255, dir >> 8); 12011da177e4SLinus Torvalds MODIFY_BITS(gpio + SA1111_GPIO_PCDDR, (bits >> 16) & 255, dir >> 16); 12021da177e4SLinus Torvalds 12031da177e4SLinus Torvalds MODIFY_BITS(gpio + SA1111_GPIO_PASDR, bits & 15, sleep_dir); 12041da177e4SLinus Torvalds MODIFY_BITS(gpio + SA1111_GPIO_PBSDR, (bits >> 8) & 255, sleep_dir >> 8); 12051da177e4SLinus Torvalds MODIFY_BITS(gpio + SA1111_GPIO_PCSDR, (bits >> 16) & 255, sleep_dir >> 16); 12061da177e4SLinus Torvalds spin_unlock_irqrestore(&sachip->lock, flags); 12071da177e4SLinus Torvalds } 12080a4bc5e8SHartley Sweeten EXPORT_SYMBOL(sa1111_set_io_dir); 12091da177e4SLinus Torvalds 12101da177e4SLinus Torvalds void sa1111_set_io(struct sa1111_dev *sadev, unsigned int bits, unsigned int v) 12111da177e4SLinus Torvalds { 12121da177e4SLinus Torvalds struct sa1111 *sachip = sa1111_chip_driver(sadev); 12131da177e4SLinus Torvalds unsigned long flags; 12141da177e4SLinus Torvalds unsigned int val; 12151da177e4SLinus Torvalds void __iomem *gpio = sachip->base + SA1111_GPIO; 12161da177e4SLinus Torvalds 12171da177e4SLinus Torvalds spin_lock_irqsave(&sachip->lock, flags); 12181da177e4SLinus Torvalds MODIFY_BITS(gpio + SA1111_GPIO_PADWR, bits & 15, v); 12191da177e4SLinus Torvalds MODIFY_BITS(gpio + SA1111_GPIO_PBDWR, (bits >> 8) & 255, v >> 8); 12201da177e4SLinus Torvalds MODIFY_BITS(gpio + SA1111_GPIO_PCDWR, (bits >> 16) & 255, v >> 16); 12211da177e4SLinus Torvalds spin_unlock_irqrestore(&sachip->lock, flags); 12221da177e4SLinus Torvalds } 12230a4bc5e8SHartley Sweeten EXPORT_SYMBOL(sa1111_set_io); 12241da177e4SLinus Torvalds 12251da177e4SLinus Torvalds void sa1111_set_sleep_io(struct sa1111_dev *sadev, unsigned int bits, unsigned int v) 12261da177e4SLinus Torvalds { 12271da177e4SLinus Torvalds struct sa1111 *sachip = sa1111_chip_driver(sadev); 12281da177e4SLinus Torvalds unsigned long flags; 12291da177e4SLinus Torvalds unsigned int val; 12301da177e4SLinus Torvalds void __iomem *gpio = sachip->base + SA1111_GPIO; 12311da177e4SLinus Torvalds 12321da177e4SLinus Torvalds spin_lock_irqsave(&sachip->lock, flags); 12331da177e4SLinus Torvalds MODIFY_BITS(gpio + SA1111_GPIO_PASSR, bits & 15, v); 12341da177e4SLinus Torvalds MODIFY_BITS(gpio + SA1111_GPIO_PBSSR, (bits >> 8) & 255, v >> 8); 12351da177e4SLinus Torvalds MODIFY_BITS(gpio + SA1111_GPIO_PCSSR, (bits >> 16) & 255, v >> 16); 12361da177e4SLinus Torvalds spin_unlock_irqrestore(&sachip->lock, flags); 12371da177e4SLinus Torvalds } 12380a4bc5e8SHartley Sweeten EXPORT_SYMBOL(sa1111_set_sleep_io); 12391da177e4SLinus Torvalds 12401da177e4SLinus Torvalds /* 12411da177e4SLinus Torvalds * Individual device operations. 12421da177e4SLinus Torvalds */ 12431da177e4SLinus Torvalds 12441da177e4SLinus Torvalds /** 12451da177e4SLinus Torvalds * sa1111_enable_device - enable an on-chip SA1111 function block 12461da177e4SLinus Torvalds * @sadev: SA1111 function block device to enable 12471da177e4SLinus Torvalds */ 1248ae99ddbcSRussell King int sa1111_enable_device(struct sa1111_dev *sadev) 12491da177e4SLinus Torvalds { 12501da177e4SLinus Torvalds struct sa1111 *sachip = sa1111_chip_driver(sadev); 12511da177e4SLinus Torvalds unsigned long flags; 12521da177e4SLinus Torvalds unsigned int val; 1253ae99ddbcSRussell King int ret = 0; 12541da177e4SLinus Torvalds 1255ae99ddbcSRussell King if (sachip->pdata && sachip->pdata->enable) 1256ae99ddbcSRussell King ret = sachip->pdata->enable(sachip->pdata->data, sadev->devid); 1257ae99ddbcSRussell King 1258ae99ddbcSRussell King if (ret == 0) { 12591da177e4SLinus Torvalds spin_lock_irqsave(&sachip->lock, flags); 12601da177e4SLinus Torvalds val = sa1111_readl(sachip->base + SA1111_SKPCR); 12611da177e4SLinus Torvalds sa1111_writel(val | sadev->skpcr_mask, sachip->base + SA1111_SKPCR); 12621da177e4SLinus Torvalds spin_unlock_irqrestore(&sachip->lock, flags); 12631da177e4SLinus Torvalds } 1264ae99ddbcSRussell King return ret; 1265ae99ddbcSRussell King } 12660a4bc5e8SHartley Sweeten EXPORT_SYMBOL(sa1111_enable_device); 12671da177e4SLinus Torvalds 12681da177e4SLinus Torvalds /** 12691da177e4SLinus Torvalds * sa1111_disable_device - disable an on-chip SA1111 function block 12701da177e4SLinus Torvalds * @sadev: SA1111 function block device to disable 12711da177e4SLinus Torvalds */ 12721da177e4SLinus Torvalds void sa1111_disable_device(struct sa1111_dev *sadev) 12731da177e4SLinus Torvalds { 12741da177e4SLinus Torvalds struct sa1111 *sachip = sa1111_chip_driver(sadev); 12751da177e4SLinus Torvalds unsigned long flags; 12761da177e4SLinus Torvalds unsigned int val; 12771da177e4SLinus Torvalds 12781da177e4SLinus Torvalds spin_lock_irqsave(&sachip->lock, flags); 12791da177e4SLinus Torvalds val = sa1111_readl(sachip->base + SA1111_SKPCR); 12801da177e4SLinus Torvalds sa1111_writel(val & ~sadev->skpcr_mask, sachip->base + SA1111_SKPCR); 12811da177e4SLinus Torvalds spin_unlock_irqrestore(&sachip->lock, flags); 1282ae99ddbcSRussell King 1283ae99ddbcSRussell King if (sachip->pdata && sachip->pdata->disable) 1284ae99ddbcSRussell King sachip->pdata->disable(sachip->pdata->data, sadev->devid); 12851da177e4SLinus Torvalds } 12860a4bc5e8SHartley Sweeten EXPORT_SYMBOL(sa1111_disable_device); 12871da177e4SLinus Torvalds 12881da177e4SLinus Torvalds /* 12891da177e4SLinus Torvalds * SA1111 "Register Access Bus." 12901da177e4SLinus Torvalds * 12911da177e4SLinus Torvalds * We model this as a regular bus type, and hang devices directly 12921da177e4SLinus Torvalds * off this. 12931da177e4SLinus Torvalds */ 12941da177e4SLinus Torvalds static int sa1111_match(struct device *_dev, struct device_driver *_drv) 12951da177e4SLinus Torvalds { 12961da177e4SLinus Torvalds struct sa1111_dev *dev = SA1111_DEV(_dev); 12971da177e4SLinus Torvalds struct sa1111_driver *drv = SA1111_DRV(_drv); 12981da177e4SLinus Torvalds 129917f29d36SMarek Szyprowski return !!(dev->devid & drv->devid); 13001da177e4SLinus Torvalds } 13011da177e4SLinus Torvalds 13021da177e4SLinus Torvalds static int sa1111_bus_suspend(struct device *dev, pm_message_t state) 13031da177e4SLinus Torvalds { 13041da177e4SLinus Torvalds struct sa1111_dev *sadev = SA1111_DEV(dev); 13051da177e4SLinus Torvalds struct sa1111_driver *drv = SA1111_DRV(dev->driver); 13061da177e4SLinus Torvalds int ret = 0; 13071da177e4SLinus Torvalds 13081da177e4SLinus Torvalds if (drv && drv->suspend) 13091da177e4SLinus Torvalds ret = drv->suspend(sadev, state); 13101da177e4SLinus Torvalds return ret; 13111da177e4SLinus Torvalds } 13121da177e4SLinus Torvalds 13131da177e4SLinus Torvalds static int sa1111_bus_resume(struct device *dev) 13141da177e4SLinus Torvalds { 13151da177e4SLinus Torvalds struct sa1111_dev *sadev = SA1111_DEV(dev); 13161da177e4SLinus Torvalds struct sa1111_driver *drv = SA1111_DRV(dev->driver); 13171da177e4SLinus Torvalds int ret = 0; 13181da177e4SLinus Torvalds 13191da177e4SLinus Torvalds if (drv && drv->resume) 13201da177e4SLinus Torvalds ret = drv->resume(sadev); 13211da177e4SLinus Torvalds return ret; 13221da177e4SLinus Torvalds } 13231da177e4SLinus Torvalds 13246bd72f05SRussell King static void sa1111_bus_shutdown(struct device *dev) 13256bd72f05SRussell King { 13266bd72f05SRussell King struct sa1111_driver *drv = SA1111_DRV(dev->driver); 13276bd72f05SRussell King 13286bd72f05SRussell King if (drv && drv->shutdown) 13296bd72f05SRussell King drv->shutdown(SA1111_DEV(dev)); 13306bd72f05SRussell King } 13316bd72f05SRussell King 13321da177e4SLinus Torvalds static int sa1111_bus_probe(struct device *dev) 13331da177e4SLinus Torvalds { 13341da177e4SLinus Torvalds struct sa1111_dev *sadev = SA1111_DEV(dev); 13351da177e4SLinus Torvalds struct sa1111_driver *drv = SA1111_DRV(dev->driver); 13361da177e4SLinus Torvalds int ret = -ENODEV; 13371da177e4SLinus Torvalds 13381da177e4SLinus Torvalds if (drv->probe) 13391da177e4SLinus Torvalds ret = drv->probe(sadev); 13401da177e4SLinus Torvalds return ret; 13411da177e4SLinus Torvalds } 13421da177e4SLinus Torvalds 13431da177e4SLinus Torvalds static int sa1111_bus_remove(struct device *dev) 13441da177e4SLinus Torvalds { 13451da177e4SLinus Torvalds struct sa1111_dev *sadev = SA1111_DEV(dev); 13461da177e4SLinus Torvalds struct sa1111_driver *drv = SA1111_DRV(dev->driver); 13471da177e4SLinus Torvalds int ret = 0; 13481da177e4SLinus Torvalds 13491da177e4SLinus Torvalds if (drv->remove) 13501da177e4SLinus Torvalds ret = drv->remove(sadev); 13511da177e4SLinus Torvalds return ret; 13521da177e4SLinus Torvalds } 13531da177e4SLinus Torvalds 13541da177e4SLinus Torvalds struct bus_type sa1111_bus_type = { 13551da177e4SLinus Torvalds .name = "sa1111-rab", 13561da177e4SLinus Torvalds .match = sa1111_match, 13572876ba43SRussell King .probe = sa1111_bus_probe, 13582876ba43SRussell King .remove = sa1111_bus_remove, 13591da177e4SLinus Torvalds .suspend = sa1111_bus_suspend, 13601da177e4SLinus Torvalds .resume = sa1111_bus_resume, 13616bd72f05SRussell King .shutdown = sa1111_bus_shutdown, 13621da177e4SLinus Torvalds }; 13630a4bc5e8SHartley Sweeten EXPORT_SYMBOL(sa1111_bus_type); 13641da177e4SLinus Torvalds 13651da177e4SLinus Torvalds int sa1111_driver_register(struct sa1111_driver *driver) 13661da177e4SLinus Torvalds { 13671da177e4SLinus Torvalds driver->drv.bus = &sa1111_bus_type; 13681da177e4SLinus Torvalds return driver_register(&driver->drv); 13691da177e4SLinus Torvalds } 13700a4bc5e8SHartley Sweeten EXPORT_SYMBOL(sa1111_driver_register); 13711da177e4SLinus Torvalds 13721da177e4SLinus Torvalds void sa1111_driver_unregister(struct sa1111_driver *driver) 13731da177e4SLinus Torvalds { 13741da177e4SLinus Torvalds driver_unregister(&driver->drv); 13751da177e4SLinus Torvalds } 13760a4bc5e8SHartley Sweeten EXPORT_SYMBOL(sa1111_driver_unregister); 13771da177e4SLinus Torvalds 137809a2ba2fSRussell King #ifdef CONFIG_DMABOUNCE 137909a2ba2fSRussell King /* 138009a2ba2fSRussell King * According to the "Intel StrongARM SA-1111 Microprocessor Companion 138109a2ba2fSRussell King * Chip Specification Update" (June 2000), erratum #7, there is a 138209a2ba2fSRussell King * significant bug in the SA1111 SDRAM shared memory controller. If 138309a2ba2fSRussell King * an access to a region of memory above 1MB relative to the bank base, 138409a2ba2fSRussell King * it is important that address bit 10 _NOT_ be asserted. Depending 138509a2ba2fSRussell King * on the configuration of the RAM, bit 10 may correspond to one 138609a2ba2fSRussell King * of several different (processor-relative) address bits. 138709a2ba2fSRussell King * 138809a2ba2fSRussell King * This routine only identifies whether or not a given DMA address 138909a2ba2fSRussell King * is susceptible to the bug. 139009a2ba2fSRussell King * 139109a2ba2fSRussell King * This should only get called for sa1111_device types due to the 139209a2ba2fSRussell King * way we configure our device dma_masks. 139309a2ba2fSRussell King */ 139409a2ba2fSRussell King static int sa1111_needs_bounce(struct device *dev, dma_addr_t addr, size_t size) 139509a2ba2fSRussell King { 139609a2ba2fSRussell King /* 139709a2ba2fSRussell King * Section 4.6 of the "Intel StrongARM SA-1111 Development Module 139809a2ba2fSRussell King * User's Guide" mentions that jumpers R51 and R52 control the 139909a2ba2fSRussell King * target of SA-1111 DMA (either SDRAM bank 0 on Assabet, or 140009a2ba2fSRussell King * SDRAM bank 1 on Neponset). The default configuration selects 140109a2ba2fSRussell King * Assabet, so any address in bank 1 is necessarily invalid. 140209a2ba2fSRussell King */ 140309a2ba2fSRussell King return (machine_is_assabet() || machine_is_pfs168()) && 140409a2ba2fSRussell King (addr >= 0xc8000000 || (addr + size) >= 0xc8000000); 140509a2ba2fSRussell King } 140609a2ba2fSRussell King 140709a2ba2fSRussell King static int sa1111_notifier_call(struct notifier_block *n, unsigned long action, 140809a2ba2fSRussell King void *data) 140909a2ba2fSRussell King { 141009a2ba2fSRussell King struct sa1111_dev *dev = SA1111_DEV(data); 141109a2ba2fSRussell King 141209a2ba2fSRussell King switch (action) { 141309a2ba2fSRussell King case BUS_NOTIFY_ADD_DEVICE: 141409a2ba2fSRussell King if (dev->dev.dma_mask && dev->dma_mask < 0xffffffffUL) { 141509a2ba2fSRussell King int ret = dmabounce_register_dev(&dev->dev, 1024, 4096, 141609a2ba2fSRussell King sa1111_needs_bounce); 141709a2ba2fSRussell King if (ret) 141809a2ba2fSRussell King dev_err(&dev->dev, "failed to register with dmabounce: %d\n", ret); 141909a2ba2fSRussell King } 142009a2ba2fSRussell King break; 142109a2ba2fSRussell King 142209a2ba2fSRussell King case BUS_NOTIFY_DEL_DEVICE: 142309a2ba2fSRussell King if (dev->dev.dma_mask && dev->dma_mask < 0xffffffffUL) 142409a2ba2fSRussell King dmabounce_unregister_dev(&dev->dev); 142509a2ba2fSRussell King break; 142609a2ba2fSRussell King } 142709a2ba2fSRussell King return NOTIFY_OK; 142809a2ba2fSRussell King } 142909a2ba2fSRussell King 143009a2ba2fSRussell King static struct notifier_block sa1111_bus_notifier = { 143109a2ba2fSRussell King .notifier_call = sa1111_notifier_call, 143209a2ba2fSRussell King }; 143309a2ba2fSRussell King #endif 143409a2ba2fSRussell King 14351da177e4SLinus Torvalds static int __init sa1111_init(void) 14361da177e4SLinus Torvalds { 14371da177e4SLinus Torvalds int ret = bus_register(&sa1111_bus_type); 143809a2ba2fSRussell King #ifdef CONFIG_DMABOUNCE 143909a2ba2fSRussell King if (ret == 0) 144009a2ba2fSRussell King bus_register_notifier(&sa1111_bus_type, &sa1111_bus_notifier); 144109a2ba2fSRussell King #endif 14421da177e4SLinus Torvalds if (ret == 0) 14433ae5eaecSRussell King platform_driver_register(&sa1111_device_driver); 14441da177e4SLinus Torvalds return ret; 14451da177e4SLinus Torvalds } 14461da177e4SLinus Torvalds 14471da177e4SLinus Torvalds static void __exit sa1111_exit(void) 14481da177e4SLinus Torvalds { 14493ae5eaecSRussell King platform_driver_unregister(&sa1111_device_driver); 145009a2ba2fSRussell King #ifdef CONFIG_DMABOUNCE 145109a2ba2fSRussell King bus_unregister_notifier(&sa1111_bus_type, &sa1111_bus_notifier); 145209a2ba2fSRussell King #endif 14531da177e4SLinus Torvalds bus_unregister(&sa1111_bus_type); 14541da177e4SLinus Torvalds } 14551da177e4SLinus Torvalds 145672724382SRussell King subsys_initcall(sa1111_init); 14571da177e4SLinus Torvalds module_exit(sa1111_exit); 14581da177e4SLinus Torvalds 14591da177e4SLinus Torvalds MODULE_DESCRIPTION("Intel Corporation SA1111 core driver"); 14601da177e4SLinus Torvalds MODULE_LICENSE("GPL"); 1461