11da177e4SLinus Torvalds /* 21da177e4SLinus Torvalds * linux/drivers/pcmcia/sa1111_generic.c 31da177e4SLinus Torvalds * 41da177e4SLinus Torvalds * We implement the generic parts of a SA1111 PCMCIA driver. This 51da177e4SLinus Torvalds * basically means we handle everything except controlling the 61da177e4SLinus Torvalds * power. Power is machine specific... 71da177e4SLinus Torvalds */ 81da177e4SLinus Torvalds #include <linux/config.h> 91da177e4SLinus Torvalds #include <linux/module.h> 101da177e4SLinus Torvalds #include <linux/kernel.h> 111da177e4SLinus Torvalds #include <linux/ioport.h> 121da177e4SLinus Torvalds #include <linux/device.h> 131da177e4SLinus Torvalds #include <linux/interrupt.h> 141da177e4SLinus Torvalds #include <linux/init.h> 151da177e4SLinus Torvalds 161da177e4SLinus Torvalds #include <pcmcia/ss.h> 171da177e4SLinus Torvalds 181da177e4SLinus Torvalds #include <asm/hardware.h> 191da177e4SLinus Torvalds #include <asm/hardware/sa1111.h> 201da177e4SLinus Torvalds #include <asm/io.h> 211da177e4SLinus Torvalds #include <asm/irq.h> 221da177e4SLinus Torvalds 231da177e4SLinus Torvalds #include "sa1111_generic.h" 241da177e4SLinus Torvalds 251da177e4SLinus Torvalds static struct pcmcia_irqs irqs[] = { 261da177e4SLinus Torvalds { 0, IRQ_S0_CD_VALID, "SA1111 PCMCIA card detect" }, 271da177e4SLinus Torvalds { 0, IRQ_S0_BVD1_STSCHG, "SA1111 PCMCIA BVD1" }, 281da177e4SLinus Torvalds { 1, IRQ_S1_CD_VALID, "SA1111 CF card detect" }, 291da177e4SLinus Torvalds { 1, IRQ_S1_BVD1_STSCHG, "SA1111 CF BVD1" }, 301da177e4SLinus Torvalds }; 311da177e4SLinus Torvalds 321da177e4SLinus Torvalds int sa1111_pcmcia_hw_init(struct soc_pcmcia_socket *skt) 331da177e4SLinus Torvalds { 341da177e4SLinus Torvalds if (skt->irq == NO_IRQ) 351da177e4SLinus Torvalds skt->irq = skt->nr ? IRQ_S1_READY_NINT : IRQ_S0_READY_NINT; 361da177e4SLinus Torvalds 371da177e4SLinus Torvalds return soc_pcmcia_request_irqs(skt, irqs, ARRAY_SIZE(irqs)); 381da177e4SLinus Torvalds } 391da177e4SLinus Torvalds 401da177e4SLinus Torvalds void sa1111_pcmcia_hw_shutdown(struct soc_pcmcia_socket *skt) 411da177e4SLinus Torvalds { 421da177e4SLinus Torvalds soc_pcmcia_free_irqs(skt, irqs, ARRAY_SIZE(irqs)); 431da177e4SLinus Torvalds } 441da177e4SLinus Torvalds 451da177e4SLinus Torvalds void sa1111_pcmcia_socket_state(struct soc_pcmcia_socket *skt, struct pcmcia_state *state) 461da177e4SLinus Torvalds { 471da177e4SLinus Torvalds struct sa1111_dev *sadev = SA1111_DEV(skt->dev); 481da177e4SLinus Torvalds unsigned long status = sa1111_readl(sadev->mapbase + SA1111_PCSR); 491da177e4SLinus Torvalds 501da177e4SLinus Torvalds switch (skt->nr) { 511da177e4SLinus Torvalds case 0: 521da177e4SLinus Torvalds state->detect = status & PCSR_S0_DETECT ? 0 : 1; 531da177e4SLinus Torvalds state->ready = status & PCSR_S0_READY ? 1 : 0; 541da177e4SLinus Torvalds state->bvd1 = status & PCSR_S0_BVD1 ? 1 : 0; 551da177e4SLinus Torvalds state->bvd2 = status & PCSR_S0_BVD2 ? 1 : 0; 561da177e4SLinus Torvalds state->wrprot = status & PCSR_S0_WP ? 1 : 0; 571da177e4SLinus Torvalds state->vs_3v = status & PCSR_S0_VS1 ? 0 : 1; 581da177e4SLinus Torvalds state->vs_Xv = status & PCSR_S0_VS2 ? 0 : 1; 591da177e4SLinus Torvalds break; 601da177e4SLinus Torvalds 611da177e4SLinus Torvalds case 1: 621da177e4SLinus Torvalds state->detect = status & PCSR_S1_DETECT ? 0 : 1; 631da177e4SLinus Torvalds state->ready = status & PCSR_S1_READY ? 1 : 0; 641da177e4SLinus Torvalds state->bvd1 = status & PCSR_S1_BVD1 ? 1 : 0; 651da177e4SLinus Torvalds state->bvd2 = status & PCSR_S1_BVD2 ? 1 : 0; 661da177e4SLinus Torvalds state->wrprot = status & PCSR_S1_WP ? 1 : 0; 671da177e4SLinus Torvalds state->vs_3v = status & PCSR_S1_VS1 ? 0 : 1; 681da177e4SLinus Torvalds state->vs_Xv = status & PCSR_S1_VS2 ? 0 : 1; 691da177e4SLinus Torvalds break; 701da177e4SLinus Torvalds } 711da177e4SLinus Torvalds } 721da177e4SLinus Torvalds 731da177e4SLinus Torvalds int sa1111_pcmcia_configure_socket(struct soc_pcmcia_socket *skt, const socket_state_t *state) 741da177e4SLinus Torvalds { 751da177e4SLinus Torvalds struct sa1111_dev *sadev = SA1111_DEV(skt->dev); 761da177e4SLinus Torvalds unsigned int pccr_skt_mask, pccr_set_mask, val; 771da177e4SLinus Torvalds unsigned long flags; 781da177e4SLinus Torvalds 791da177e4SLinus Torvalds switch (skt->nr) { 801da177e4SLinus Torvalds case 0: 811da177e4SLinus Torvalds pccr_skt_mask = PCCR_S0_RST|PCCR_S0_FLT|PCCR_S0_PWAITEN|PCCR_S0_PSE; 821da177e4SLinus Torvalds break; 831da177e4SLinus Torvalds 841da177e4SLinus Torvalds case 1: 851da177e4SLinus Torvalds pccr_skt_mask = PCCR_S1_RST|PCCR_S1_FLT|PCCR_S1_PWAITEN|PCCR_S1_PSE; 861da177e4SLinus Torvalds break; 871da177e4SLinus Torvalds 881da177e4SLinus Torvalds default: 891da177e4SLinus Torvalds return -1; 901da177e4SLinus Torvalds } 911da177e4SLinus Torvalds 921da177e4SLinus Torvalds pccr_set_mask = 0; 931da177e4SLinus Torvalds 941da177e4SLinus Torvalds if (state->Vcc != 0) 951da177e4SLinus Torvalds pccr_set_mask |= PCCR_S0_PWAITEN|PCCR_S1_PWAITEN; 961da177e4SLinus Torvalds if (state->Vcc == 50) 971da177e4SLinus Torvalds pccr_set_mask |= PCCR_S0_PSE|PCCR_S1_PSE; 981da177e4SLinus Torvalds if (state->flags & SS_RESET) 991da177e4SLinus Torvalds pccr_set_mask |= PCCR_S0_RST|PCCR_S1_RST; 1001da177e4SLinus Torvalds if (state->flags & SS_OUTPUT_ENA) 1011da177e4SLinus Torvalds pccr_set_mask |= PCCR_S0_FLT|PCCR_S1_FLT; 1021da177e4SLinus Torvalds 1031da177e4SLinus Torvalds local_irq_save(flags); 1041da177e4SLinus Torvalds val = sa1111_readl(sadev->mapbase + SA1111_PCCR); 1051da177e4SLinus Torvalds val &= ~pccr_skt_mask; 1061da177e4SLinus Torvalds val |= pccr_set_mask & pccr_skt_mask; 1071da177e4SLinus Torvalds sa1111_writel(val, sadev->mapbase + SA1111_PCCR); 1081da177e4SLinus Torvalds local_irq_restore(flags); 1091da177e4SLinus Torvalds 1101da177e4SLinus Torvalds return 0; 1111da177e4SLinus Torvalds } 1121da177e4SLinus Torvalds 1131da177e4SLinus Torvalds void sa1111_pcmcia_socket_init(struct soc_pcmcia_socket *skt) 1141da177e4SLinus Torvalds { 1151da177e4SLinus Torvalds soc_pcmcia_enable_irqs(skt, irqs, ARRAY_SIZE(irqs)); 1161da177e4SLinus Torvalds } 1171da177e4SLinus Torvalds 1181da177e4SLinus Torvalds void sa1111_pcmcia_socket_suspend(struct soc_pcmcia_socket *skt) 1191da177e4SLinus Torvalds { 1201da177e4SLinus Torvalds soc_pcmcia_disable_irqs(skt, irqs, ARRAY_SIZE(irqs)); 1211da177e4SLinus Torvalds } 1221da177e4SLinus Torvalds 1231da177e4SLinus Torvalds static int pcmcia_probe(struct sa1111_dev *dev) 1241da177e4SLinus Torvalds { 125*f339ab3dSRussell King void __iomem *base; 1261da177e4SLinus Torvalds 1271da177e4SLinus Torvalds if (!request_mem_region(dev->res.start, 512, 1281da177e4SLinus Torvalds SA1111_DRIVER_NAME(dev))) 1291da177e4SLinus Torvalds return -EBUSY; 1301da177e4SLinus Torvalds 1311da177e4SLinus Torvalds base = dev->mapbase; 1321da177e4SLinus Torvalds 1331da177e4SLinus Torvalds /* 1341da177e4SLinus Torvalds * Initialise the suspend state. 1351da177e4SLinus Torvalds */ 1361da177e4SLinus Torvalds sa1111_writel(PCSSR_S0_SLEEP | PCSSR_S1_SLEEP, base + SA1111_PCSSR); 1371da177e4SLinus Torvalds sa1111_writel(PCCR_S0_FLT | PCCR_S1_FLT, base + SA1111_PCCR); 1381da177e4SLinus Torvalds 1391da177e4SLinus Torvalds #ifdef CONFIG_SA1100_BADGE4 1401da177e4SLinus Torvalds pcmcia_badge4_init(&dev->dev); 1411da177e4SLinus Torvalds #endif 1421da177e4SLinus Torvalds #ifdef CONFIG_SA1100_JORNADA720 1431da177e4SLinus Torvalds pcmcia_jornada720_init(&dev->dev); 1441da177e4SLinus Torvalds #endif 1451da177e4SLinus Torvalds #ifdef CONFIG_ARCH_LUBBOCK 1461da177e4SLinus Torvalds pcmcia_lubbock_init(dev); 1471da177e4SLinus Torvalds #endif 1481da177e4SLinus Torvalds #ifdef CONFIG_ASSABET_NEPONSET 1491da177e4SLinus Torvalds pcmcia_neponset_init(dev); 1501da177e4SLinus Torvalds #endif 1511da177e4SLinus Torvalds return 0; 1521da177e4SLinus Torvalds } 1531da177e4SLinus Torvalds 1541da177e4SLinus Torvalds static int __devexit pcmcia_remove(struct sa1111_dev *dev) 1551da177e4SLinus Torvalds { 1561da177e4SLinus Torvalds soc_common_drv_pcmcia_remove(&dev->dev); 1571da177e4SLinus Torvalds release_mem_region(dev->res.start, 512); 1581da177e4SLinus Torvalds return 0; 1591da177e4SLinus Torvalds } 1601da177e4SLinus Torvalds 1618bf28030SPavel Machek static int pcmcia_suspend(struct sa1111_dev *dev, pm_message_t state) 1621da177e4SLinus Torvalds { 1631da177e4SLinus Torvalds return pcmcia_socket_dev_suspend(&dev->dev, state); 1641da177e4SLinus Torvalds } 1651da177e4SLinus Torvalds 1661da177e4SLinus Torvalds static int pcmcia_resume(struct sa1111_dev *dev) 1671da177e4SLinus Torvalds { 1681da177e4SLinus Torvalds return pcmcia_socket_dev_resume(&dev->dev); 1691da177e4SLinus Torvalds } 1701da177e4SLinus Torvalds 1711da177e4SLinus Torvalds static struct sa1111_driver pcmcia_driver = { 1721da177e4SLinus Torvalds .drv = { 1731da177e4SLinus Torvalds .name = "sa1111-pcmcia", 1741da177e4SLinus Torvalds }, 1751da177e4SLinus Torvalds .devid = SA1111_DEVID_PCMCIA, 1761da177e4SLinus Torvalds .probe = pcmcia_probe, 1771da177e4SLinus Torvalds .remove = __devexit_p(pcmcia_remove), 1781da177e4SLinus Torvalds .suspend = pcmcia_suspend, 1791da177e4SLinus Torvalds .resume = pcmcia_resume, 1801da177e4SLinus Torvalds }; 1811da177e4SLinus Torvalds 1821da177e4SLinus Torvalds static int __init sa1111_drv_pcmcia_init(void) 1831da177e4SLinus Torvalds { 1841da177e4SLinus Torvalds return sa1111_driver_register(&pcmcia_driver); 1851da177e4SLinus Torvalds } 1861da177e4SLinus Torvalds 1871da177e4SLinus Torvalds static void __exit sa1111_drv_pcmcia_exit(void) 1881da177e4SLinus Torvalds { 1891da177e4SLinus Torvalds sa1111_driver_unregister(&pcmcia_driver); 1901da177e4SLinus Torvalds } 1911da177e4SLinus Torvalds 192f36598aeSRichard Purdie fs_initcall(sa1111_drv_pcmcia_init); 1931da177e4SLinus Torvalds module_exit(sa1111_drv_pcmcia_exit); 1941da177e4SLinus Torvalds 1951da177e4SLinus Torvalds MODULE_DESCRIPTION("SA1111 PCMCIA card socket driver"); 1961da177e4SLinus Torvalds MODULE_LICENSE("GPL"); 197