178673bc8SEduardo Valentin /* 278673bc8SEduardo Valentin * linux/arch/arm/mach-omap2/mcbsp.c 378673bc8SEduardo Valentin * 478673bc8SEduardo Valentin * Copyright (C) 2008 Instituto Nokia de Tecnologia 578673bc8SEduardo Valentin * Contact: Eduardo Valentin <eduardo.valentin@indt.org.br> 678673bc8SEduardo Valentin * 778673bc8SEduardo Valentin * This program is free software; you can redistribute it and/or modify 878673bc8SEduardo Valentin * it under the terms of the GNU General Public License version 2 as 978673bc8SEduardo Valentin * published by the Free Software Foundation. 1078673bc8SEduardo Valentin * 1178673bc8SEduardo Valentin * Multichannel mode not supported. 1278673bc8SEduardo Valentin */ 1378673bc8SEduardo Valentin #include <linux/module.h> 1478673bc8SEduardo Valentin #include <linux/init.h> 1578673bc8SEduardo Valentin #include <linux/clk.h> 1678673bc8SEduardo Valentin #include <linux/err.h> 1778673bc8SEduardo Valentin #include <linux/io.h> 1878673bc8SEduardo Valentin #include <linux/platform_device.h> 195a0e3ad6STejun Heo #include <linux/slab.h> 2078673bc8SEduardo Valentin 21dd7667aaSTony Lindgren #include <mach/irqs.h> 22ce491cf8STony Lindgren #include <plat/dma.h> 23ce491cf8STony Lindgren #include <plat/cpu.h> 24ce491cf8STony Lindgren #include <plat/mcbsp.h> 25*cf4c87abSPaul Walmsley #include <plat/control.h> 2678673bc8SEduardo Valentin 27*cf4c87abSPaul Walmsley /* McBSP internal signal muxing functions */ 28*cf4c87abSPaul Walmsley 29*cf4c87abSPaul Walmsley void omap2_mcbsp1_mux_clkr_src(u8 mux) 30*cf4c87abSPaul Walmsley { 31*cf4c87abSPaul Walmsley u32 v; 32*cf4c87abSPaul Walmsley 33*cf4c87abSPaul Walmsley v = omap_ctrl_readl(OMAP2_CONTROL_DEVCONF0); 34*cf4c87abSPaul Walmsley if (mux == CLKR_SRC_CLKR) 35*cf4c87abSPaul Walmsley v &= OMAP2_MCBSP1_CLKR_MASK; 36*cf4c87abSPaul Walmsley else if (mux == CLKR_SRC_CLKX) 37*cf4c87abSPaul Walmsley v |= OMAP2_MCBSP1_CLKR_MASK; 38*cf4c87abSPaul Walmsley omap_ctrl_writel(v, OMAP2_CONTROL_DEVCONF0); 39*cf4c87abSPaul Walmsley } 40*cf4c87abSPaul Walmsley EXPORT_SYMBOL(omap2_mcbsp1_mux_clkr_src); 41*cf4c87abSPaul Walmsley 42*cf4c87abSPaul Walmsley void omap2_mcbsp1_mux_fsr_src(u8 mux) 43*cf4c87abSPaul Walmsley { 44*cf4c87abSPaul Walmsley u32 v; 45*cf4c87abSPaul Walmsley 46*cf4c87abSPaul Walmsley v = omap_ctrl_readl(OMAP2_CONTROL_DEVCONF0); 47*cf4c87abSPaul Walmsley if (mux == FSR_SRC_FSR) 48*cf4c87abSPaul Walmsley v &= OMAP2_MCBSP1_FSR_MASK; 49*cf4c87abSPaul Walmsley else if (mux == FSR_SRC_FSX) 50*cf4c87abSPaul Walmsley v |= OMAP2_MCBSP1_FSR_MASK; 51*cf4c87abSPaul Walmsley omap_ctrl_writel(v, OMAP2_CONTROL_DEVCONF0); 52*cf4c87abSPaul Walmsley } 53*cf4c87abSPaul Walmsley EXPORT_SYMBOL(omap2_mcbsp1_mux_fsr_src); 54*cf4c87abSPaul Walmsley 55*cf4c87abSPaul Walmsley /* Platform data */ 5678673bc8SEduardo Valentin 5705228c35SJarkko Nikula #ifdef CONFIG_ARCH_OMAP2420 5805228c35SJarkko Nikula static struct omap_mcbsp_platform_data omap2420_mcbsp_pdata[] = { 5978673bc8SEduardo Valentin { 6065846909SRussell King .phys_base = OMAP24XX_MCBSP1_BASE, 6178673bc8SEduardo Valentin .dma_rx_sync = OMAP24XX_DMA_MCBSP1_RX, 6278673bc8SEduardo Valentin .dma_tx_sync = OMAP24XX_DMA_MCBSP1_TX, 6378673bc8SEduardo Valentin .rx_irq = INT_24XX_MCBSP1_IRQ_RX, 6478673bc8SEduardo Valentin .tx_irq = INT_24XX_MCBSP1_IRQ_TX, 6578673bc8SEduardo Valentin }, 6678673bc8SEduardo Valentin { 6765846909SRussell King .phys_base = OMAP24XX_MCBSP2_BASE, 6878673bc8SEduardo Valentin .dma_rx_sync = OMAP24XX_DMA_MCBSP2_RX, 6978673bc8SEduardo Valentin .dma_tx_sync = OMAP24XX_DMA_MCBSP2_TX, 7078673bc8SEduardo Valentin .rx_irq = INT_24XX_MCBSP2_IRQ_RX, 7178673bc8SEduardo Valentin .tx_irq = INT_24XX_MCBSP2_IRQ_TX, 7278673bc8SEduardo Valentin }, 7378673bc8SEduardo Valentin }; 7405228c35SJarkko Nikula #define OMAP2420_MCBSP_PDATA_SZ ARRAY_SIZE(omap2420_mcbsp_pdata) 75c8c99699SJanusz Krzysztofik #define OMAP2420_MCBSP_REG_NUM (OMAP_MCBSP_REG_RCCR / sizeof(u32) + 1) 7678673bc8SEduardo Valentin #else 7705228c35SJarkko Nikula #define omap2420_mcbsp_pdata NULL 7805228c35SJarkko Nikula #define OMAP2420_MCBSP_PDATA_SZ 0 79c8c99699SJanusz Krzysztofik #define OMAP2420_MCBSP_REG_NUM 0 8005228c35SJarkko Nikula #endif 8105228c35SJarkko Nikula 8205228c35SJarkko Nikula #ifdef CONFIG_ARCH_OMAP2430 8305228c35SJarkko Nikula static struct omap_mcbsp_platform_data omap2430_mcbsp_pdata[] = { 8405228c35SJarkko Nikula { 8505228c35SJarkko Nikula .phys_base = OMAP24XX_MCBSP1_BASE, 8605228c35SJarkko Nikula .dma_rx_sync = OMAP24XX_DMA_MCBSP1_RX, 8705228c35SJarkko Nikula .dma_tx_sync = OMAP24XX_DMA_MCBSP1_TX, 8805228c35SJarkko Nikula .rx_irq = INT_24XX_MCBSP1_IRQ_RX, 8905228c35SJarkko Nikula .tx_irq = INT_24XX_MCBSP1_IRQ_TX, 9005228c35SJarkko Nikula }, 9105228c35SJarkko Nikula { 9205228c35SJarkko Nikula .phys_base = OMAP24XX_MCBSP2_BASE, 9305228c35SJarkko Nikula .dma_rx_sync = OMAP24XX_DMA_MCBSP2_RX, 9405228c35SJarkko Nikula .dma_tx_sync = OMAP24XX_DMA_MCBSP2_TX, 9505228c35SJarkko Nikula .rx_irq = INT_24XX_MCBSP2_IRQ_RX, 9605228c35SJarkko Nikula .tx_irq = INT_24XX_MCBSP2_IRQ_TX, 9705228c35SJarkko Nikula }, 9805228c35SJarkko Nikula { 9905228c35SJarkko Nikula .phys_base = OMAP2430_MCBSP3_BASE, 10005228c35SJarkko Nikula .dma_rx_sync = OMAP24XX_DMA_MCBSP3_RX, 10105228c35SJarkko Nikula .dma_tx_sync = OMAP24XX_DMA_MCBSP3_TX, 10205228c35SJarkko Nikula .rx_irq = INT_24XX_MCBSP3_IRQ_RX, 10305228c35SJarkko Nikula .tx_irq = INT_24XX_MCBSP3_IRQ_TX, 10405228c35SJarkko Nikula }, 10505228c35SJarkko Nikula { 10605228c35SJarkko Nikula .phys_base = OMAP2430_MCBSP4_BASE, 10705228c35SJarkko Nikula .dma_rx_sync = OMAP24XX_DMA_MCBSP4_RX, 10805228c35SJarkko Nikula .dma_tx_sync = OMAP24XX_DMA_MCBSP4_TX, 10905228c35SJarkko Nikula .rx_irq = INT_24XX_MCBSP4_IRQ_RX, 11005228c35SJarkko Nikula .tx_irq = INT_24XX_MCBSP4_IRQ_TX, 11105228c35SJarkko Nikula }, 11205228c35SJarkko Nikula { 11305228c35SJarkko Nikula .phys_base = OMAP2430_MCBSP5_BASE, 11405228c35SJarkko Nikula .dma_rx_sync = OMAP24XX_DMA_MCBSP5_RX, 11505228c35SJarkko Nikula .dma_tx_sync = OMAP24XX_DMA_MCBSP5_TX, 11605228c35SJarkko Nikula .rx_irq = INT_24XX_MCBSP5_IRQ_RX, 11705228c35SJarkko Nikula .tx_irq = INT_24XX_MCBSP5_IRQ_TX, 11805228c35SJarkko Nikula }, 11905228c35SJarkko Nikula }; 12005228c35SJarkko Nikula #define OMAP2430_MCBSP_PDATA_SZ ARRAY_SIZE(omap2430_mcbsp_pdata) 121c8c99699SJanusz Krzysztofik #define OMAP2430_MCBSP_REG_NUM (OMAP_MCBSP_REG_RCCR / sizeof(u32) + 1) 12205228c35SJarkko Nikula #else 12305228c35SJarkko Nikula #define omap2430_mcbsp_pdata NULL 12405228c35SJarkko Nikula #define OMAP2430_MCBSP_PDATA_SZ 0 125c8c99699SJanusz Krzysztofik #define OMAP2430_MCBSP_REG_NUM 0 12678673bc8SEduardo Valentin #endif 12778673bc8SEduardo Valentin 128a8eb7ca0STony Lindgren #ifdef CONFIG_ARCH_OMAP3 12978673bc8SEduardo Valentin static struct omap_mcbsp_platform_data omap34xx_mcbsp_pdata[] = { 13078673bc8SEduardo Valentin { 13165846909SRussell King .phys_base = OMAP34XX_MCBSP1_BASE, 13278673bc8SEduardo Valentin .dma_rx_sync = OMAP24XX_DMA_MCBSP1_RX, 13378673bc8SEduardo Valentin .dma_tx_sync = OMAP24XX_DMA_MCBSP1_TX, 13478673bc8SEduardo Valentin .rx_irq = INT_24XX_MCBSP1_IRQ_RX, 13578673bc8SEduardo Valentin .tx_irq = INT_24XX_MCBSP1_IRQ_TX, 136451fd82dSPeter Ujfalusi .buffer_size = 0x80, /* The FIFO has 128 locations */ 13778673bc8SEduardo Valentin }, 13878673bc8SEduardo Valentin { 13965846909SRussell King .phys_base = OMAP34XX_MCBSP2_BASE, 140d912fa92SEero Nurkkala .phys_base_st = OMAP34XX_MCBSP2_ST_BASE, 14178673bc8SEduardo Valentin .dma_rx_sync = OMAP24XX_DMA_MCBSP2_RX, 14278673bc8SEduardo Valentin .dma_tx_sync = OMAP24XX_DMA_MCBSP2_TX, 14378673bc8SEduardo Valentin .rx_irq = INT_24XX_MCBSP2_IRQ_RX, 14478673bc8SEduardo Valentin .tx_irq = INT_24XX_MCBSP2_IRQ_TX, 145451fd82dSPeter Ujfalusi .buffer_size = 0x500, /* The FIFO has 1024 + 256 locations */ 14678673bc8SEduardo Valentin }, 1479c8e3a0fSChandra Shekhar { 1489c8e3a0fSChandra Shekhar .phys_base = OMAP34XX_MCBSP3_BASE, 149d912fa92SEero Nurkkala .phys_base_st = OMAP34XX_MCBSP3_ST_BASE, 1509c8e3a0fSChandra Shekhar .dma_rx_sync = OMAP24XX_DMA_MCBSP3_RX, 1519c8e3a0fSChandra Shekhar .dma_tx_sync = OMAP24XX_DMA_MCBSP3_TX, 1529c8e3a0fSChandra Shekhar .rx_irq = INT_24XX_MCBSP3_IRQ_RX, 1539c8e3a0fSChandra Shekhar .tx_irq = INT_24XX_MCBSP3_IRQ_TX, 154451fd82dSPeter Ujfalusi .buffer_size = 0x80, /* The FIFO has 128 locations */ 1559c8e3a0fSChandra Shekhar }, 1569c8e3a0fSChandra Shekhar { 1579c8e3a0fSChandra Shekhar .phys_base = OMAP34XX_MCBSP4_BASE, 1589c8e3a0fSChandra Shekhar .dma_rx_sync = OMAP24XX_DMA_MCBSP4_RX, 1599c8e3a0fSChandra Shekhar .dma_tx_sync = OMAP24XX_DMA_MCBSP4_TX, 1609c8e3a0fSChandra Shekhar .rx_irq = INT_24XX_MCBSP4_IRQ_RX, 1619c8e3a0fSChandra Shekhar .tx_irq = INT_24XX_MCBSP4_IRQ_TX, 162451fd82dSPeter Ujfalusi .buffer_size = 0x80, /* The FIFO has 128 locations */ 1639c8e3a0fSChandra Shekhar }, 1649c8e3a0fSChandra Shekhar { 1659c8e3a0fSChandra Shekhar .phys_base = OMAP34XX_MCBSP5_BASE, 1669c8e3a0fSChandra Shekhar .dma_rx_sync = OMAP24XX_DMA_MCBSP5_RX, 1679c8e3a0fSChandra Shekhar .dma_tx_sync = OMAP24XX_DMA_MCBSP5_TX, 1689c8e3a0fSChandra Shekhar .rx_irq = INT_24XX_MCBSP5_IRQ_RX, 1699c8e3a0fSChandra Shekhar .tx_irq = INT_24XX_MCBSP5_IRQ_TX, 170451fd82dSPeter Ujfalusi .buffer_size = 0x80, /* The FIFO has 128 locations */ 1719c8e3a0fSChandra Shekhar }, 17278673bc8SEduardo Valentin }; 17378673bc8SEduardo Valentin #define OMAP34XX_MCBSP_PDATA_SZ ARRAY_SIZE(omap34xx_mcbsp_pdata) 174c8c99699SJanusz Krzysztofik #define OMAP34XX_MCBSP_REG_NUM (OMAP_MCBSP_REG_RCCR / sizeof(u32) + 1) 17578673bc8SEduardo Valentin #else 17678673bc8SEduardo Valentin #define omap34xx_mcbsp_pdata NULL 17778673bc8SEduardo Valentin #define OMAP34XX_MCBSP_PDATA_SZ 0 178c8c99699SJanusz Krzysztofik #define OMAP34XX_MCBSP_REG_NUM 0 17978673bc8SEduardo Valentin #endif 18078673bc8SEduardo Valentin 181a5b92cc3SSyed Rafiuddin static struct omap_mcbsp_platform_data omap44xx_mcbsp_pdata[] = { 182a5b92cc3SSyed Rafiuddin { 183a5b92cc3SSyed Rafiuddin .phys_base = OMAP44XX_MCBSP1_BASE, 184a5b92cc3SSyed Rafiuddin .dma_rx_sync = OMAP44XX_DMA_MCBSP1_RX, 185a5b92cc3SSyed Rafiuddin .dma_tx_sync = OMAP44XX_DMA_MCBSP1_TX, 1869319b9daSJorge Eduardo Candelaria .tx_irq = OMAP44XX_IRQ_MCBSP1, 187a5b92cc3SSyed Rafiuddin }, 188a5b92cc3SSyed Rafiuddin { 189a5b92cc3SSyed Rafiuddin .phys_base = OMAP44XX_MCBSP2_BASE, 190a5b92cc3SSyed Rafiuddin .dma_rx_sync = OMAP44XX_DMA_MCBSP2_RX, 191a5b92cc3SSyed Rafiuddin .dma_tx_sync = OMAP44XX_DMA_MCBSP2_TX, 1929319b9daSJorge Eduardo Candelaria .tx_irq = OMAP44XX_IRQ_MCBSP2, 193a5b92cc3SSyed Rafiuddin }, 194a5b92cc3SSyed Rafiuddin { 195a5b92cc3SSyed Rafiuddin .phys_base = OMAP44XX_MCBSP3_BASE, 196a5b92cc3SSyed Rafiuddin .dma_rx_sync = OMAP44XX_DMA_MCBSP3_RX, 197a5b92cc3SSyed Rafiuddin .dma_tx_sync = OMAP44XX_DMA_MCBSP3_TX, 1989319b9daSJorge Eduardo Candelaria .tx_irq = OMAP44XX_IRQ_MCBSP3, 199a5b92cc3SSyed Rafiuddin }, 200a5b92cc3SSyed Rafiuddin { 201a5b92cc3SSyed Rafiuddin .phys_base = OMAP44XX_MCBSP4_BASE, 202a5b92cc3SSyed Rafiuddin .dma_rx_sync = OMAP44XX_DMA_MCBSP4_RX, 203a5b92cc3SSyed Rafiuddin .dma_tx_sync = OMAP44XX_DMA_MCBSP4_TX, 2049319b9daSJorge Eduardo Candelaria .tx_irq = OMAP44XX_IRQ_MCBSP4, 205a5b92cc3SSyed Rafiuddin }, 206a5b92cc3SSyed Rafiuddin }; 207a5b92cc3SSyed Rafiuddin #define OMAP44XX_MCBSP_PDATA_SZ ARRAY_SIZE(omap44xx_mcbsp_pdata) 208c8c99699SJanusz Krzysztofik #define OMAP44XX_MCBSP_REG_NUM (OMAP_MCBSP_REG_RCCR / sizeof(u32) + 1) 209a5b92cc3SSyed Rafiuddin 210b4b58f58SChandra Shekhar static int __init omap2_mcbsp_init(void) 21178673bc8SEduardo Valentin { 212c8c99699SJanusz Krzysztofik if (cpu_is_omap2420()) { 21305228c35SJarkko Nikula omap_mcbsp_count = OMAP2420_MCBSP_PDATA_SZ; 214c8c99699SJanusz Krzysztofik omap_mcbsp_cache_size = OMAP2420_MCBSP_REG_NUM * sizeof(u16); 215c8c99699SJanusz Krzysztofik } else if (cpu_is_omap2430()) { 21605228c35SJarkko Nikula omap_mcbsp_count = OMAP2430_MCBSP_PDATA_SZ; 217c8c99699SJanusz Krzysztofik omap_mcbsp_cache_size = OMAP2430_MCBSP_REG_NUM * sizeof(u32); 218c8c99699SJanusz Krzysztofik } else if (cpu_is_omap34xx()) { 219b4b58f58SChandra Shekhar omap_mcbsp_count = OMAP34XX_MCBSP_PDATA_SZ; 220c8c99699SJanusz Krzysztofik omap_mcbsp_cache_size = OMAP34XX_MCBSP_REG_NUM * sizeof(u32); 221c8c99699SJanusz Krzysztofik } else if (cpu_is_omap44xx()) { 222a5b92cc3SSyed Rafiuddin omap_mcbsp_count = OMAP44XX_MCBSP_PDATA_SZ; 223c8c99699SJanusz Krzysztofik omap_mcbsp_cache_size = OMAP44XX_MCBSP_REG_NUM * sizeof(u32); 224c8c99699SJanusz Krzysztofik } 225b4b58f58SChandra Shekhar 226b4b58f58SChandra Shekhar mcbsp_ptr = kzalloc(omap_mcbsp_count * sizeof(struct omap_mcbsp *), 227b4b58f58SChandra Shekhar GFP_KERNEL); 228b4b58f58SChandra Shekhar if (!mcbsp_ptr) 229b4b58f58SChandra Shekhar return -ENOMEM; 230b4b58f58SChandra Shekhar 23105228c35SJarkko Nikula if (cpu_is_omap2420()) 23205228c35SJarkko Nikula omap_mcbsp_register_board_cfg(omap2420_mcbsp_pdata, 23305228c35SJarkko Nikula OMAP2420_MCBSP_PDATA_SZ); 23405228c35SJarkko Nikula if (cpu_is_omap2430()) 23505228c35SJarkko Nikula omap_mcbsp_register_board_cfg(omap2430_mcbsp_pdata, 23605228c35SJarkko Nikula OMAP2430_MCBSP_PDATA_SZ); 2379c8e3a0fSChandra Shekhar if (cpu_is_omap34xx()) 2389c8e3a0fSChandra Shekhar omap_mcbsp_register_board_cfg(omap34xx_mcbsp_pdata, 2399c8e3a0fSChandra Shekhar OMAP34XX_MCBSP_PDATA_SZ); 240a5b92cc3SSyed Rafiuddin if (cpu_is_omap44xx()) 241a5b92cc3SSyed Rafiuddin omap_mcbsp_register_board_cfg(omap44xx_mcbsp_pdata, 242a5b92cc3SSyed Rafiuddin OMAP44XX_MCBSP_PDATA_SZ); 24378673bc8SEduardo Valentin 24478673bc8SEduardo Valentin return omap_mcbsp_init(); 24578673bc8SEduardo Valentin } 24678673bc8SEduardo Valentin arch_initcall(omap2_mcbsp_init); 247