Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 1 | /* |
| 2 | * linux/arch/arm/plat-omap/mcbsp.c |
| 3 | * |
| 4 | * Copyright (C) 2004 Nokia Corporation |
| 5 | * Author: Samuel Ortiz <samuel.ortiz@nokia.com> |
| 6 | * |
| 7 | * |
| 8 | * This program is free software; you can redistribute it and/or modify |
| 9 | * it under the terms of the GNU General Public License version 2 as |
| 10 | * published by the Free Software Foundation. |
| 11 | * |
| 12 | * Multichannel mode not supported. |
| 13 | */ |
| 14 | |
| 15 | #include <linux/module.h> |
| 16 | #include <linux/init.h> |
| 17 | #include <linux/device.h> |
Eduardo Valentin | bc5d0c8 | 2008-07-03 12:24:39 +0300 | [diff] [blame] | 18 | #include <linux/platform_device.h> |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 19 | #include <linux/wait.h> |
| 20 | #include <linux/completion.h> |
| 21 | #include <linux/interrupt.h> |
| 22 | #include <linux/err.h> |
Russell King | f8ce254 | 2006-01-07 16:15:52 +0000 | [diff] [blame] | 23 | #include <linux/clk.h> |
Tony Lindgren | 04fbf6a | 2007-02-12 10:50:53 -0800 | [diff] [blame] | 24 | #include <linux/delay.h> |
Eduardo Valentin | fb78d80 | 2008-07-03 12:24:39 +0300 | [diff] [blame] | 25 | #include <linux/io.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 26 | #include <linux/slab.h> |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 27 | |
Tony Lindgren | ce491cf | 2009-10-20 09:40:47 -0700 | [diff] [blame] | 28 | #include <plat/dma.h> |
| 29 | #include <plat/mcbsp.h> |
Kishon Vijay Abraham I | f36d01d | 2011-02-24 15:16:53 +0530 | [diff] [blame] | 30 | #include <plat/omap_device.h> |
Kishon Vijay Abraham I | e95496d | 2011-02-24 15:16:54 +0530 | [diff] [blame] | 31 | #include <linux/pm_runtime.h> |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 32 | |
Paul Walmsley | 59fb659 | 2010-12-21 15:30:55 -0700 | [diff] [blame] | 33 | /* XXX These "sideways" includes are a sign that something is wrong */ |
| 34 | #include "../mach-omap2/cm2xxx_3xxx.h" |
Eero Nurkkala | d912fa9 | 2010-02-22 12:21:11 +0000 | [diff] [blame] | 35 | #include "../mach-omap2/cm-regbits-34xx.h" |
| 36 | |
Chandra Shekhar | b4b58f5 | 2008-10-08 10:01:39 +0300 | [diff] [blame] | 37 | struct omap_mcbsp **mcbsp_ptr; |
Janusz Krzysztofik | c8c9969 | 2010-02-15 10:03:33 -0800 | [diff] [blame] | 38 | int omap_mcbsp_count, omap_mcbsp_cache_size; |
Eduardo Valentin | bc5d0c8 | 2008-07-03 12:24:39 +0300 | [diff] [blame] | 39 | |
Manjunath Kondaiah G | b0a330d | 2010-10-08 10:00:19 -0700 | [diff] [blame] | 40 | static void omap_mcbsp_write(struct omap_mcbsp *mcbsp, u16 reg, u32 val) |
Chandra Shekhar | b4b58f5 | 2008-10-08 10:01:39 +0300 | [diff] [blame] | 41 | { |
Janusz Krzysztofik | c8c9969 | 2010-02-15 10:03:33 -0800 | [diff] [blame] | 42 | if (cpu_class_is_omap1()) { |
| 43 | ((u16 *)mcbsp->reg_cache)[reg / sizeof(u16)] = (u16)val; |
Janusz Krzysztofik | 8ea3200 | 2010-02-15 10:03:32 -0800 | [diff] [blame] | 44 | __raw_writew((u16)val, mcbsp->io_base + reg); |
Janusz Krzysztofik | c8c9969 | 2010-02-15 10:03:33 -0800 | [diff] [blame] | 45 | } else if (cpu_is_omap2420()) { |
| 46 | ((u16 *)mcbsp->reg_cache)[reg / sizeof(u32)] = (u16)val; |
| 47 | __raw_writew((u16)val, mcbsp->io_base + reg); |
| 48 | } else { |
| 49 | ((u32 *)mcbsp->reg_cache)[reg / sizeof(u32)] = val; |
Janusz Krzysztofik | 8ea3200 | 2010-02-15 10:03:32 -0800 | [diff] [blame] | 50 | __raw_writel(val, mcbsp->io_base + reg); |
Janusz Krzysztofik | c8c9969 | 2010-02-15 10:03:33 -0800 | [diff] [blame] | 51 | } |
Chandra Shekhar | b4b58f5 | 2008-10-08 10:01:39 +0300 | [diff] [blame] | 52 | } |
| 53 | |
Manjunath Kondaiah G | b0a330d | 2010-10-08 10:00:19 -0700 | [diff] [blame] | 54 | static int omap_mcbsp_read(struct omap_mcbsp *mcbsp, u16 reg, bool from_cache) |
Chandra Shekhar | b4b58f5 | 2008-10-08 10:01:39 +0300 | [diff] [blame] | 55 | { |
Janusz Krzysztofik | c8c9969 | 2010-02-15 10:03:33 -0800 | [diff] [blame] | 56 | if (cpu_class_is_omap1()) { |
| 57 | return !from_cache ? __raw_readw(mcbsp->io_base + reg) : |
| 58 | ((u16 *)mcbsp->reg_cache)[reg / sizeof(u16)]; |
| 59 | } else if (cpu_is_omap2420()) { |
| 60 | return !from_cache ? __raw_readw(mcbsp->io_base + reg) : |
| 61 | ((u16 *)mcbsp->reg_cache)[reg / sizeof(u32)]; |
| 62 | } else { |
| 63 | return !from_cache ? __raw_readl(mcbsp->io_base + reg) : |
| 64 | ((u32 *)mcbsp->reg_cache)[reg / sizeof(u32)]; |
| 65 | } |
Chandra Shekhar | b4b58f5 | 2008-10-08 10:01:39 +0300 | [diff] [blame] | 66 | } |
| 67 | |
Eero Nurkkala | d912fa9 | 2010-02-22 12:21:11 +0000 | [diff] [blame] | 68 | #ifdef CONFIG_ARCH_OMAP3 |
Manjunath Kondaiah G | b0a330d | 2010-10-08 10:00:19 -0700 | [diff] [blame] | 69 | static void omap_mcbsp_st_write(struct omap_mcbsp *mcbsp, u16 reg, u32 val) |
Eero Nurkkala | d912fa9 | 2010-02-22 12:21:11 +0000 | [diff] [blame] | 70 | { |
| 71 | __raw_writel(val, mcbsp->st_data->io_base_st + reg); |
| 72 | } |
| 73 | |
Manjunath Kondaiah G | b0a330d | 2010-10-08 10:00:19 -0700 | [diff] [blame] | 74 | static int omap_mcbsp_st_read(struct omap_mcbsp *mcbsp, u16 reg) |
Eero Nurkkala | d912fa9 | 2010-02-22 12:21:11 +0000 | [diff] [blame] | 75 | { |
| 76 | return __raw_readl(mcbsp->st_data->io_base_st + reg); |
| 77 | } |
| 78 | #endif |
| 79 | |
Janusz Krzysztofik | 8ea3200 | 2010-02-15 10:03:32 -0800 | [diff] [blame] | 80 | #define MCBSP_READ(mcbsp, reg) \ |
Janusz Krzysztofik | c8c9969 | 2010-02-15 10:03:33 -0800 | [diff] [blame] | 81 | omap_mcbsp_read(mcbsp, OMAP_MCBSP_REG_##reg, 0) |
Janusz Krzysztofik | 8ea3200 | 2010-02-15 10:03:32 -0800 | [diff] [blame] | 82 | #define MCBSP_WRITE(mcbsp, reg, val) \ |
| 83 | omap_mcbsp_write(mcbsp, OMAP_MCBSP_REG_##reg, val) |
Janusz Krzysztofik | c8c9969 | 2010-02-15 10:03:33 -0800 | [diff] [blame] | 84 | #define MCBSP_READ_CACHE(mcbsp, reg) \ |
| 85 | omap_mcbsp_read(mcbsp, OMAP_MCBSP_REG_##reg, 1) |
Chandra Shekhar | b4b58f5 | 2008-10-08 10:01:39 +0300 | [diff] [blame] | 86 | |
Eero Nurkkala | d912fa9 | 2010-02-22 12:21:11 +0000 | [diff] [blame] | 87 | #define MCBSP_ST_READ(mcbsp, reg) \ |
| 88 | omap_mcbsp_st_read(mcbsp, OMAP_ST_REG_##reg) |
| 89 | #define MCBSP_ST_WRITE(mcbsp, reg, val) \ |
| 90 | omap_mcbsp_st_write(mcbsp, OMAP_ST_REG_##reg, val) |
| 91 | |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 92 | static void omap_mcbsp_dump_reg(u8 id) |
| 93 | { |
Chandra Shekhar | b4b58f5 | 2008-10-08 10:01:39 +0300 | [diff] [blame] | 94 | struct omap_mcbsp *mcbsp = id_to_mcbsp_ptr(id); |
| 95 | |
| 96 | dev_dbg(mcbsp->dev, "**** McBSP%d regs ****\n", mcbsp->id); |
| 97 | dev_dbg(mcbsp->dev, "DRR2: 0x%04x\n", |
Janusz Krzysztofik | 8ea3200 | 2010-02-15 10:03:32 -0800 | [diff] [blame] | 98 | MCBSP_READ(mcbsp, DRR2)); |
Chandra Shekhar | b4b58f5 | 2008-10-08 10:01:39 +0300 | [diff] [blame] | 99 | dev_dbg(mcbsp->dev, "DRR1: 0x%04x\n", |
Janusz Krzysztofik | 8ea3200 | 2010-02-15 10:03:32 -0800 | [diff] [blame] | 100 | MCBSP_READ(mcbsp, DRR1)); |
Chandra Shekhar | b4b58f5 | 2008-10-08 10:01:39 +0300 | [diff] [blame] | 101 | dev_dbg(mcbsp->dev, "DXR2: 0x%04x\n", |
Janusz Krzysztofik | 8ea3200 | 2010-02-15 10:03:32 -0800 | [diff] [blame] | 102 | MCBSP_READ(mcbsp, DXR2)); |
Chandra Shekhar | b4b58f5 | 2008-10-08 10:01:39 +0300 | [diff] [blame] | 103 | dev_dbg(mcbsp->dev, "DXR1: 0x%04x\n", |
Janusz Krzysztofik | 8ea3200 | 2010-02-15 10:03:32 -0800 | [diff] [blame] | 104 | MCBSP_READ(mcbsp, DXR1)); |
Chandra Shekhar | b4b58f5 | 2008-10-08 10:01:39 +0300 | [diff] [blame] | 105 | dev_dbg(mcbsp->dev, "SPCR2: 0x%04x\n", |
Janusz Krzysztofik | 8ea3200 | 2010-02-15 10:03:32 -0800 | [diff] [blame] | 106 | MCBSP_READ(mcbsp, SPCR2)); |
Chandra Shekhar | b4b58f5 | 2008-10-08 10:01:39 +0300 | [diff] [blame] | 107 | dev_dbg(mcbsp->dev, "SPCR1: 0x%04x\n", |
Janusz Krzysztofik | 8ea3200 | 2010-02-15 10:03:32 -0800 | [diff] [blame] | 108 | MCBSP_READ(mcbsp, SPCR1)); |
Chandra Shekhar | b4b58f5 | 2008-10-08 10:01:39 +0300 | [diff] [blame] | 109 | dev_dbg(mcbsp->dev, "RCR2: 0x%04x\n", |
Janusz Krzysztofik | 8ea3200 | 2010-02-15 10:03:32 -0800 | [diff] [blame] | 110 | MCBSP_READ(mcbsp, RCR2)); |
Chandra Shekhar | b4b58f5 | 2008-10-08 10:01:39 +0300 | [diff] [blame] | 111 | dev_dbg(mcbsp->dev, "RCR1: 0x%04x\n", |
Janusz Krzysztofik | 8ea3200 | 2010-02-15 10:03:32 -0800 | [diff] [blame] | 112 | MCBSP_READ(mcbsp, RCR1)); |
Chandra Shekhar | b4b58f5 | 2008-10-08 10:01:39 +0300 | [diff] [blame] | 113 | dev_dbg(mcbsp->dev, "XCR2: 0x%04x\n", |
Janusz Krzysztofik | 8ea3200 | 2010-02-15 10:03:32 -0800 | [diff] [blame] | 114 | MCBSP_READ(mcbsp, XCR2)); |
Chandra Shekhar | b4b58f5 | 2008-10-08 10:01:39 +0300 | [diff] [blame] | 115 | dev_dbg(mcbsp->dev, "XCR1: 0x%04x\n", |
Janusz Krzysztofik | 8ea3200 | 2010-02-15 10:03:32 -0800 | [diff] [blame] | 116 | MCBSP_READ(mcbsp, XCR1)); |
Chandra Shekhar | b4b58f5 | 2008-10-08 10:01:39 +0300 | [diff] [blame] | 117 | dev_dbg(mcbsp->dev, "SRGR2: 0x%04x\n", |
Janusz Krzysztofik | 8ea3200 | 2010-02-15 10:03:32 -0800 | [diff] [blame] | 118 | MCBSP_READ(mcbsp, SRGR2)); |
Chandra Shekhar | b4b58f5 | 2008-10-08 10:01:39 +0300 | [diff] [blame] | 119 | dev_dbg(mcbsp->dev, "SRGR1: 0x%04x\n", |
Janusz Krzysztofik | 8ea3200 | 2010-02-15 10:03:32 -0800 | [diff] [blame] | 120 | MCBSP_READ(mcbsp, SRGR1)); |
Chandra Shekhar | b4b58f5 | 2008-10-08 10:01:39 +0300 | [diff] [blame] | 121 | dev_dbg(mcbsp->dev, "PCR0: 0x%04x\n", |
Janusz Krzysztofik | 8ea3200 | 2010-02-15 10:03:32 -0800 | [diff] [blame] | 122 | MCBSP_READ(mcbsp, PCR0)); |
Chandra Shekhar | b4b58f5 | 2008-10-08 10:01:39 +0300 | [diff] [blame] | 123 | dev_dbg(mcbsp->dev, "***********************\n"); |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 124 | } |
| 125 | |
Linus Torvalds | 0cd61b6 | 2006-10-06 10:53:39 -0700 | [diff] [blame] | 126 | static irqreturn_t omap_mcbsp_tx_irq_handler(int irq, void *dev_id) |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 127 | { |
Jeff Garzik | e8f2af1 | 2007-10-26 05:40:25 -0400 | [diff] [blame] | 128 | struct omap_mcbsp *mcbsp_tx = dev_id; |
Eero Nurkkala | d6d834b | 2009-05-25 11:08:42 -0700 | [diff] [blame] | 129 | u16 irqst_spcr2; |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 130 | |
Janusz Krzysztofik | 8ea3200 | 2010-02-15 10:03:32 -0800 | [diff] [blame] | 131 | irqst_spcr2 = MCBSP_READ(mcbsp_tx, SPCR2); |
Eero Nurkkala | d6d834b | 2009-05-25 11:08:42 -0700 | [diff] [blame] | 132 | dev_dbg(mcbsp_tx->dev, "TX IRQ callback : 0x%x\n", irqst_spcr2); |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 133 | |
Eero Nurkkala | d6d834b | 2009-05-25 11:08:42 -0700 | [diff] [blame] | 134 | if (irqst_spcr2 & XSYNC_ERR) { |
| 135 | dev_err(mcbsp_tx->dev, "TX Frame Sync Error! : 0x%x\n", |
| 136 | irqst_spcr2); |
| 137 | /* Writing zero to XSYNC_ERR clears the IRQ */ |
Janusz Krzysztofik | 0841cb8 | 2010-02-23 15:50:38 +0000 | [diff] [blame] | 138 | MCBSP_WRITE(mcbsp_tx, SPCR2, MCBSP_READ_CACHE(mcbsp_tx, SPCR2)); |
Eero Nurkkala | d6d834b | 2009-05-25 11:08:42 -0700 | [diff] [blame] | 139 | } else { |
| 140 | complete(&mcbsp_tx->tx_irq_completion); |
| 141 | } |
Eduardo Valentin | fb78d80 | 2008-07-03 12:24:39 +0300 | [diff] [blame] | 142 | |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 143 | return IRQ_HANDLED; |
| 144 | } |
| 145 | |
Linus Torvalds | 0cd61b6 | 2006-10-06 10:53:39 -0700 | [diff] [blame] | 146 | static irqreturn_t omap_mcbsp_rx_irq_handler(int irq, void *dev_id) |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 147 | { |
Jeff Garzik | e8f2af1 | 2007-10-26 05:40:25 -0400 | [diff] [blame] | 148 | struct omap_mcbsp *mcbsp_rx = dev_id; |
Eero Nurkkala | d6d834b | 2009-05-25 11:08:42 -0700 | [diff] [blame] | 149 | u16 irqst_spcr1; |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 150 | |
Janusz Krzysztofik | 8ea3200 | 2010-02-15 10:03:32 -0800 | [diff] [blame] | 151 | irqst_spcr1 = MCBSP_READ(mcbsp_rx, SPCR1); |
Eero Nurkkala | d6d834b | 2009-05-25 11:08:42 -0700 | [diff] [blame] | 152 | dev_dbg(mcbsp_rx->dev, "RX IRQ callback : 0x%x\n", irqst_spcr1); |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 153 | |
Eero Nurkkala | d6d834b | 2009-05-25 11:08:42 -0700 | [diff] [blame] | 154 | if (irqst_spcr1 & RSYNC_ERR) { |
| 155 | dev_err(mcbsp_rx->dev, "RX Frame Sync Error! : 0x%x\n", |
| 156 | irqst_spcr1); |
| 157 | /* Writing zero to RSYNC_ERR clears the IRQ */ |
Janusz Krzysztofik | 0841cb8 | 2010-02-23 15:50:38 +0000 | [diff] [blame] | 158 | MCBSP_WRITE(mcbsp_rx, SPCR1, MCBSP_READ_CACHE(mcbsp_rx, SPCR1)); |
Eero Nurkkala | d6d834b | 2009-05-25 11:08:42 -0700 | [diff] [blame] | 159 | } else { |
Scott Ellis | cb922d2 | 2010-09-23 18:47:23 -0700 | [diff] [blame] | 160 | complete(&mcbsp_rx->rx_irq_completion); |
Eero Nurkkala | d6d834b | 2009-05-25 11:08:42 -0700 | [diff] [blame] | 161 | } |
Eduardo Valentin | fb78d80 | 2008-07-03 12:24:39 +0300 | [diff] [blame] | 162 | |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 163 | return IRQ_HANDLED; |
| 164 | } |
| 165 | |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 166 | static void omap_mcbsp_tx_dma_callback(int lch, u16 ch_status, void *data) |
| 167 | { |
Jeff Garzik | e8f2af1 | 2007-10-26 05:40:25 -0400 | [diff] [blame] | 168 | struct omap_mcbsp *mcbsp_dma_tx = data; |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 169 | |
Eduardo Valentin | bc5d0c8 | 2008-07-03 12:24:39 +0300 | [diff] [blame] | 170 | dev_dbg(mcbsp_dma_tx->dev, "TX DMA callback : 0x%x\n", |
Janusz Krzysztofik | 8ea3200 | 2010-02-15 10:03:32 -0800 | [diff] [blame] | 171 | MCBSP_READ(mcbsp_dma_tx, SPCR2)); |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 172 | |
| 173 | /* We can free the channels */ |
| 174 | omap_free_dma(mcbsp_dma_tx->dma_tx_lch); |
| 175 | mcbsp_dma_tx->dma_tx_lch = -1; |
| 176 | |
| 177 | complete(&mcbsp_dma_tx->tx_dma_completion); |
| 178 | } |
| 179 | |
| 180 | static void omap_mcbsp_rx_dma_callback(int lch, u16 ch_status, void *data) |
| 181 | { |
Jeff Garzik | e8f2af1 | 2007-10-26 05:40:25 -0400 | [diff] [blame] | 182 | struct omap_mcbsp *mcbsp_dma_rx = data; |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 183 | |
Eduardo Valentin | bc5d0c8 | 2008-07-03 12:24:39 +0300 | [diff] [blame] | 184 | dev_dbg(mcbsp_dma_rx->dev, "RX DMA callback : 0x%x\n", |
Janusz Krzysztofik | 8ea3200 | 2010-02-15 10:03:32 -0800 | [diff] [blame] | 185 | MCBSP_READ(mcbsp_dma_rx, SPCR2)); |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 186 | |
| 187 | /* We can free the channels */ |
| 188 | omap_free_dma(mcbsp_dma_rx->dma_rx_lch); |
| 189 | mcbsp_dma_rx->dma_rx_lch = -1; |
| 190 | |
| 191 | complete(&mcbsp_dma_rx->rx_dma_completion); |
| 192 | } |
| 193 | |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 194 | /* |
| 195 | * omap_mcbsp_config simply write a config to the |
| 196 | * appropriate McBSP. |
| 197 | * You either call this function or set the McBSP registers |
| 198 | * by yourself before calling omap_mcbsp_start(). |
| 199 | */ |
Eduardo Valentin | fb78d80 | 2008-07-03 12:24:39 +0300 | [diff] [blame] | 200 | void omap_mcbsp_config(unsigned int id, const struct omap_mcbsp_reg_cfg *config) |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 201 | { |
Chandra Shekhar | b4b58f5 | 2008-10-08 10:01:39 +0300 | [diff] [blame] | 202 | struct omap_mcbsp *mcbsp; |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 203 | |
Eduardo Valentin | bc5d0c8 | 2008-07-03 12:24:39 +0300 | [diff] [blame] | 204 | if (!omap_mcbsp_check_valid_id(id)) { |
| 205 | printk(KERN_ERR "%s: Invalid id (%d)\n", __func__, id + 1); |
| 206 | return; |
| 207 | } |
Chandra Shekhar | b4b58f5 | 2008-10-08 10:01:39 +0300 | [diff] [blame] | 208 | mcbsp = id_to_mcbsp_ptr(id); |
Eduardo Valentin | bc5d0c8 | 2008-07-03 12:24:39 +0300 | [diff] [blame] | 209 | |
Chandra Shekhar | b4b58f5 | 2008-10-08 10:01:39 +0300 | [diff] [blame] | 210 | dev_dbg(mcbsp->dev, "Configuring McBSP%d phys_base: 0x%08lx\n", |
| 211 | mcbsp->id, mcbsp->phys_base); |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 212 | |
| 213 | /* We write the given config */ |
Janusz Krzysztofik | 8ea3200 | 2010-02-15 10:03:32 -0800 | [diff] [blame] | 214 | MCBSP_WRITE(mcbsp, SPCR2, config->spcr2); |
| 215 | MCBSP_WRITE(mcbsp, SPCR1, config->spcr1); |
| 216 | MCBSP_WRITE(mcbsp, RCR2, config->rcr2); |
| 217 | MCBSP_WRITE(mcbsp, RCR1, config->rcr1); |
| 218 | MCBSP_WRITE(mcbsp, XCR2, config->xcr2); |
| 219 | MCBSP_WRITE(mcbsp, XCR1, config->xcr1); |
| 220 | MCBSP_WRITE(mcbsp, SRGR2, config->srgr2); |
| 221 | MCBSP_WRITE(mcbsp, SRGR1, config->srgr1); |
| 222 | MCBSP_WRITE(mcbsp, MCR2, config->mcr2); |
| 223 | MCBSP_WRITE(mcbsp, MCR1, config->mcr1); |
| 224 | MCBSP_WRITE(mcbsp, PCR0, config->pcr0); |
Syed Rafiuddin | a5b92cc | 2009-07-28 18:57:10 +0530 | [diff] [blame] | 225 | if (cpu_is_omap2430() || cpu_is_omap34xx() || cpu_is_omap44xx()) { |
Janusz Krzysztofik | 8ea3200 | 2010-02-15 10:03:32 -0800 | [diff] [blame] | 226 | MCBSP_WRITE(mcbsp, XCCR, config->xccr); |
| 227 | MCBSP_WRITE(mcbsp, RCCR, config->rccr); |
Tony Lindgren | 3127f8f | 2009-01-15 13:09:54 +0200 | [diff] [blame] | 228 | } |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 229 | } |
Eduardo Valentin | fb78d80 | 2008-07-03 12:24:39 +0300 | [diff] [blame] | 230 | EXPORT_SYMBOL(omap_mcbsp_config); |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 231 | |
Kishon Vijay Abraham I | 9504ba6 | 2011-02-24 15:16:55 +0530 | [diff] [blame] | 232 | /** |
| 233 | * omap_mcbsp_dma_params - returns the dma channel number |
| 234 | * @id - mcbsp id |
| 235 | * @stream - indicates the direction of data flow (rx or tx) |
| 236 | * |
| 237 | * Returns the dma channel number for the rx channel or tx channel |
| 238 | * based on the value of @stream for the requested mcbsp given by @id |
| 239 | */ |
| 240 | int omap_mcbsp_dma_ch_params(unsigned int id, unsigned int stream) |
| 241 | { |
| 242 | struct omap_mcbsp *mcbsp; |
| 243 | |
| 244 | if (!omap_mcbsp_check_valid_id(id)) { |
| 245 | printk(KERN_ERR "%s: Invalid id (%d)\n", __func__, id + 1); |
| 246 | return -ENODEV; |
| 247 | } |
| 248 | mcbsp = id_to_mcbsp_ptr(id); |
| 249 | |
| 250 | if (stream) |
| 251 | return mcbsp->dma_rx_sync; |
| 252 | else |
| 253 | return mcbsp->dma_tx_sync; |
| 254 | } |
| 255 | EXPORT_SYMBOL(omap_mcbsp_dma_ch_params); |
| 256 | |
| 257 | /** |
| 258 | * omap_mcbsp_dma_reg_params - returns the address of mcbsp data register |
| 259 | * @id - mcbsp id |
| 260 | * @stream - indicates the direction of data flow (rx or tx) |
| 261 | * |
| 262 | * Returns the address of mcbsp data transmit register or data receive register |
| 263 | * to be used by DMA for transferring/receiving data based on the value of |
| 264 | * @stream for the requested mcbsp given by @id |
| 265 | */ |
| 266 | int omap_mcbsp_dma_reg_params(unsigned int id, unsigned int stream) |
| 267 | { |
| 268 | struct omap_mcbsp *mcbsp; |
| 269 | int data_reg; |
| 270 | |
| 271 | if (!omap_mcbsp_check_valid_id(id)) { |
| 272 | printk(KERN_ERR "%s: Invalid id (%d)\n", __func__, id + 1); |
| 273 | return -ENODEV; |
| 274 | } |
| 275 | mcbsp = id_to_mcbsp_ptr(id); |
| 276 | |
| 277 | data_reg = mcbsp->phys_dma_base; |
| 278 | |
| 279 | if (mcbsp->mcbsp_config_type < MCBSP_CONFIG_TYPE2) { |
| 280 | if (stream) |
| 281 | data_reg += OMAP_MCBSP_REG_DRR1; |
| 282 | else |
| 283 | data_reg += OMAP_MCBSP_REG_DXR1; |
| 284 | } else { |
| 285 | if (stream) |
| 286 | data_reg += OMAP_MCBSP_REG_DRR; |
| 287 | else |
| 288 | data_reg += OMAP_MCBSP_REG_DXR; |
| 289 | } |
| 290 | |
| 291 | return data_reg; |
| 292 | } |
| 293 | EXPORT_SYMBOL(omap_mcbsp_dma_reg_params); |
| 294 | |
Tony Lindgren | a8eb7ca | 2010-02-12 12:26:48 -0800 | [diff] [blame] | 295 | #ifdef CONFIG_ARCH_OMAP3 |
Kishon Vijay Abraham I | f36d01d | 2011-02-24 15:16:53 +0530 | [diff] [blame] | 296 | static struct omap_device *find_omap_device_by_dev(struct device *dev) |
| 297 | { |
| 298 | struct platform_device *pdev = container_of(dev, |
| 299 | struct platform_device, dev); |
| 300 | return container_of(pdev, struct omap_device, pdev); |
| 301 | } |
| 302 | |
Eero Nurkkala | d912fa9 | 2010-02-22 12:21:11 +0000 | [diff] [blame] | 303 | static void omap_st_on(struct omap_mcbsp *mcbsp) |
| 304 | { |
| 305 | unsigned int w; |
Kishon Vijay Abraham I | f36d01d | 2011-02-24 15:16:53 +0530 | [diff] [blame] | 306 | struct omap_device *od; |
| 307 | |
| 308 | od = find_omap_device_by_dev(mcbsp->dev); |
Eero Nurkkala | d912fa9 | 2010-02-22 12:21:11 +0000 | [diff] [blame] | 309 | |
| 310 | /* |
| 311 | * Sidetone uses McBSP ICLK - which must not idle when sidetones |
| 312 | * are enabled or sidetones start sounding ugly. |
| 313 | */ |
Paul Walmsley | c4d7e58 | 2010-12-21 21:05:14 -0700 | [diff] [blame] | 314 | w = omap2_cm_read_mod_reg(OMAP3430_PER_MOD, CM_AUTOIDLE); |
Eero Nurkkala | d912fa9 | 2010-02-22 12:21:11 +0000 | [diff] [blame] | 315 | w &= ~(1 << (mcbsp->id - 2)); |
Paul Walmsley | c4d7e58 | 2010-12-21 21:05:14 -0700 | [diff] [blame] | 316 | omap2_cm_write_mod_reg(w, OMAP3430_PER_MOD, CM_AUTOIDLE); |
Eero Nurkkala | d912fa9 | 2010-02-22 12:21:11 +0000 | [diff] [blame] | 317 | |
| 318 | /* Enable McBSP Sidetone */ |
| 319 | w = MCBSP_READ(mcbsp, SSELCR); |
| 320 | MCBSP_WRITE(mcbsp, SSELCR, w | SIDETONEEN); |
| 321 | |
Eero Nurkkala | d912fa9 | 2010-02-22 12:21:11 +0000 | [diff] [blame] | 322 | /* Enable Sidetone from Sidetone Core */ |
| 323 | w = MCBSP_ST_READ(mcbsp, SSELCR); |
| 324 | MCBSP_ST_WRITE(mcbsp, SSELCR, w | ST_SIDETONEEN); |
| 325 | } |
| 326 | |
| 327 | static void omap_st_off(struct omap_mcbsp *mcbsp) |
| 328 | { |
| 329 | unsigned int w; |
Kishon Vijay Abraham I | f36d01d | 2011-02-24 15:16:53 +0530 | [diff] [blame] | 330 | struct omap_device *od; |
| 331 | |
| 332 | od = find_omap_device_by_dev(mcbsp->dev); |
Eero Nurkkala | d912fa9 | 2010-02-22 12:21:11 +0000 | [diff] [blame] | 333 | |
| 334 | w = MCBSP_ST_READ(mcbsp, SSELCR); |
| 335 | MCBSP_ST_WRITE(mcbsp, SSELCR, w & ~(ST_SIDETONEEN)); |
| 336 | |
Eero Nurkkala | d912fa9 | 2010-02-22 12:21:11 +0000 | [diff] [blame] | 337 | w = MCBSP_READ(mcbsp, SSELCR); |
| 338 | MCBSP_WRITE(mcbsp, SSELCR, w & ~(SIDETONEEN)); |
| 339 | |
Paul Walmsley | c4d7e58 | 2010-12-21 21:05:14 -0700 | [diff] [blame] | 340 | w = omap2_cm_read_mod_reg(OMAP3430_PER_MOD, CM_AUTOIDLE); |
Eero Nurkkala | d912fa9 | 2010-02-22 12:21:11 +0000 | [diff] [blame] | 341 | w |= 1 << (mcbsp->id - 2); |
Paul Walmsley | c4d7e58 | 2010-12-21 21:05:14 -0700 | [diff] [blame] | 342 | omap2_cm_write_mod_reg(w, OMAP3430_PER_MOD, CM_AUTOIDLE); |
Eero Nurkkala | d912fa9 | 2010-02-22 12:21:11 +0000 | [diff] [blame] | 343 | } |
| 344 | |
| 345 | static void omap_st_fir_write(struct omap_mcbsp *mcbsp, s16 *fir) |
| 346 | { |
| 347 | u16 val, i; |
Kishon Vijay Abraham I | f36d01d | 2011-02-24 15:16:53 +0530 | [diff] [blame] | 348 | struct omap_device *od; |
Eero Nurkkala | d912fa9 | 2010-02-22 12:21:11 +0000 | [diff] [blame] | 349 | |
Kishon Vijay Abraham I | f36d01d | 2011-02-24 15:16:53 +0530 | [diff] [blame] | 350 | od = find_omap_device_by_dev(mcbsp->dev); |
Eero Nurkkala | d912fa9 | 2010-02-22 12:21:11 +0000 | [diff] [blame] | 351 | |
| 352 | val = MCBSP_ST_READ(mcbsp, SSELCR); |
| 353 | |
| 354 | if (val & ST_COEFFWREN) |
| 355 | MCBSP_ST_WRITE(mcbsp, SSELCR, val & ~(ST_COEFFWREN)); |
| 356 | |
| 357 | MCBSP_ST_WRITE(mcbsp, SSELCR, val | ST_COEFFWREN); |
| 358 | |
| 359 | for (i = 0; i < 128; i++) |
| 360 | MCBSP_ST_WRITE(mcbsp, SFIRCR, fir[i]); |
| 361 | |
| 362 | i = 0; |
| 363 | |
| 364 | val = MCBSP_ST_READ(mcbsp, SSELCR); |
| 365 | while (!(val & ST_COEFFWRDONE) && (++i < 1000)) |
| 366 | val = MCBSP_ST_READ(mcbsp, SSELCR); |
| 367 | |
| 368 | MCBSP_ST_WRITE(mcbsp, SSELCR, val & ~(ST_COEFFWREN)); |
| 369 | |
| 370 | if (i == 1000) |
| 371 | dev_err(mcbsp->dev, "McBSP FIR load error!\n"); |
| 372 | } |
| 373 | |
| 374 | static void omap_st_chgain(struct omap_mcbsp *mcbsp) |
| 375 | { |
| 376 | u16 w; |
| 377 | struct omap_mcbsp_st_data *st_data = mcbsp->st_data; |
Kishon Vijay Abraham I | f36d01d | 2011-02-24 15:16:53 +0530 | [diff] [blame] | 378 | struct omap_device *od; |
Eero Nurkkala | d912fa9 | 2010-02-22 12:21:11 +0000 | [diff] [blame] | 379 | |
Kishon Vijay Abraham I | f36d01d | 2011-02-24 15:16:53 +0530 | [diff] [blame] | 380 | od = find_omap_device_by_dev(mcbsp->dev); |
Eero Nurkkala | d912fa9 | 2010-02-22 12:21:11 +0000 | [diff] [blame] | 381 | |
| 382 | w = MCBSP_ST_READ(mcbsp, SSELCR); |
| 383 | |
| 384 | MCBSP_ST_WRITE(mcbsp, SGAINCR, ST_CH0GAIN(st_data->ch0gain) | \ |
| 385 | ST_CH1GAIN(st_data->ch1gain)); |
| 386 | } |
| 387 | |
| 388 | int omap_st_set_chgain(unsigned int id, int channel, s16 chgain) |
| 389 | { |
| 390 | struct omap_mcbsp *mcbsp; |
| 391 | struct omap_mcbsp_st_data *st_data; |
| 392 | int ret = 0; |
| 393 | |
| 394 | if (!omap_mcbsp_check_valid_id(id)) { |
| 395 | printk(KERN_ERR "%s: Invalid id (%d)\n", __func__, id + 1); |
| 396 | return -ENODEV; |
| 397 | } |
| 398 | |
| 399 | mcbsp = id_to_mcbsp_ptr(id); |
| 400 | st_data = mcbsp->st_data; |
| 401 | |
| 402 | if (!st_data) |
| 403 | return -ENOENT; |
| 404 | |
| 405 | spin_lock_irq(&mcbsp->lock); |
| 406 | if (channel == 0) |
| 407 | st_data->ch0gain = chgain; |
| 408 | else if (channel == 1) |
| 409 | st_data->ch1gain = chgain; |
| 410 | else |
| 411 | ret = -EINVAL; |
| 412 | |
| 413 | if (st_data->enabled) |
| 414 | omap_st_chgain(mcbsp); |
| 415 | spin_unlock_irq(&mcbsp->lock); |
| 416 | |
| 417 | return ret; |
| 418 | } |
| 419 | EXPORT_SYMBOL(omap_st_set_chgain); |
| 420 | |
| 421 | int omap_st_get_chgain(unsigned int id, int channel, s16 *chgain) |
| 422 | { |
| 423 | struct omap_mcbsp *mcbsp; |
| 424 | struct omap_mcbsp_st_data *st_data; |
| 425 | int ret = 0; |
| 426 | |
| 427 | if (!omap_mcbsp_check_valid_id(id)) { |
| 428 | printk(KERN_ERR "%s: Invalid id (%d)\n", __func__, id + 1); |
| 429 | return -ENODEV; |
| 430 | } |
| 431 | |
| 432 | mcbsp = id_to_mcbsp_ptr(id); |
| 433 | st_data = mcbsp->st_data; |
| 434 | |
| 435 | if (!st_data) |
| 436 | return -ENOENT; |
| 437 | |
| 438 | spin_lock_irq(&mcbsp->lock); |
| 439 | if (channel == 0) |
| 440 | *chgain = st_data->ch0gain; |
| 441 | else if (channel == 1) |
| 442 | *chgain = st_data->ch1gain; |
| 443 | else |
| 444 | ret = -EINVAL; |
| 445 | spin_unlock_irq(&mcbsp->lock); |
| 446 | |
| 447 | return ret; |
| 448 | } |
| 449 | EXPORT_SYMBOL(omap_st_get_chgain); |
| 450 | |
| 451 | static int omap_st_start(struct omap_mcbsp *mcbsp) |
| 452 | { |
| 453 | struct omap_mcbsp_st_data *st_data = mcbsp->st_data; |
| 454 | |
| 455 | if (st_data && st_data->enabled && !st_data->running) { |
| 456 | omap_st_fir_write(mcbsp, st_data->taps); |
| 457 | omap_st_chgain(mcbsp); |
| 458 | |
| 459 | if (!mcbsp->free) { |
| 460 | omap_st_on(mcbsp); |
| 461 | st_data->running = 1; |
| 462 | } |
| 463 | } |
| 464 | |
| 465 | return 0; |
| 466 | } |
| 467 | |
| 468 | int omap_st_enable(unsigned int id) |
| 469 | { |
| 470 | struct omap_mcbsp *mcbsp; |
| 471 | struct omap_mcbsp_st_data *st_data; |
| 472 | |
| 473 | if (!omap_mcbsp_check_valid_id(id)) { |
| 474 | printk(KERN_ERR "%s: Invalid id (%d)\n", __func__, id + 1); |
| 475 | return -ENODEV; |
| 476 | } |
| 477 | |
| 478 | mcbsp = id_to_mcbsp_ptr(id); |
| 479 | st_data = mcbsp->st_data; |
| 480 | |
| 481 | if (!st_data) |
| 482 | return -ENODEV; |
| 483 | |
| 484 | spin_lock_irq(&mcbsp->lock); |
| 485 | st_data->enabled = 1; |
| 486 | omap_st_start(mcbsp); |
| 487 | spin_unlock_irq(&mcbsp->lock); |
| 488 | |
| 489 | return 0; |
| 490 | } |
| 491 | EXPORT_SYMBOL(omap_st_enable); |
| 492 | |
| 493 | static int omap_st_stop(struct omap_mcbsp *mcbsp) |
| 494 | { |
| 495 | struct omap_mcbsp_st_data *st_data = mcbsp->st_data; |
| 496 | |
| 497 | if (st_data && st_data->running) { |
| 498 | if (!mcbsp->free) { |
| 499 | omap_st_off(mcbsp); |
| 500 | st_data->running = 0; |
| 501 | } |
| 502 | } |
| 503 | |
| 504 | return 0; |
| 505 | } |
| 506 | |
| 507 | int omap_st_disable(unsigned int id) |
| 508 | { |
| 509 | struct omap_mcbsp *mcbsp; |
| 510 | struct omap_mcbsp_st_data *st_data; |
| 511 | int ret = 0; |
| 512 | |
| 513 | if (!omap_mcbsp_check_valid_id(id)) { |
| 514 | printk(KERN_ERR "%s: Invalid id (%d)\n", __func__, id + 1); |
| 515 | return -ENODEV; |
| 516 | } |
| 517 | |
| 518 | mcbsp = id_to_mcbsp_ptr(id); |
| 519 | st_data = mcbsp->st_data; |
| 520 | |
| 521 | if (!st_data) |
| 522 | return -ENODEV; |
| 523 | |
| 524 | spin_lock_irq(&mcbsp->lock); |
| 525 | omap_st_stop(mcbsp); |
| 526 | st_data->enabled = 0; |
| 527 | spin_unlock_irq(&mcbsp->lock); |
| 528 | |
| 529 | return ret; |
| 530 | } |
| 531 | EXPORT_SYMBOL(omap_st_disable); |
| 532 | |
| 533 | int omap_st_is_enabled(unsigned int id) |
| 534 | { |
| 535 | struct omap_mcbsp *mcbsp; |
| 536 | struct omap_mcbsp_st_data *st_data; |
| 537 | |
| 538 | if (!omap_mcbsp_check_valid_id(id)) { |
| 539 | printk(KERN_ERR "%s: Invalid id (%d)\n", __func__, id + 1); |
| 540 | return -ENODEV; |
| 541 | } |
| 542 | |
| 543 | mcbsp = id_to_mcbsp_ptr(id); |
| 544 | st_data = mcbsp->st_data; |
| 545 | |
| 546 | if (!st_data) |
| 547 | return -ENODEV; |
| 548 | |
| 549 | |
| 550 | return st_data->enabled; |
| 551 | } |
| 552 | EXPORT_SYMBOL(omap_st_is_enabled); |
| 553 | |
Eduardo Valentin | 7aa9ff5 | 2009-08-20 16:18:10 +0300 | [diff] [blame] | 554 | /* |
Peter Ujfalusi | 451fd82 | 2010-06-03 07:39:33 +0300 | [diff] [blame] | 555 | * omap_mcbsp_set_rx_threshold configures the transmit threshold in words. |
| 556 | * The threshold parameter is 1 based, and it is converted (threshold - 1) |
| 557 | * for the THRSH2 register. |
Eduardo Valentin | 7aa9ff5 | 2009-08-20 16:18:10 +0300 | [diff] [blame] | 558 | */ |
| 559 | void omap_mcbsp_set_tx_threshold(unsigned int id, u16 threshold) |
| 560 | { |
| 561 | struct omap_mcbsp *mcbsp; |
Eduardo Valentin | 7aa9ff5 | 2009-08-20 16:18:10 +0300 | [diff] [blame] | 562 | |
Jorge Eduardo Candelaria | 752ec2f | 2010-05-12 12:18:40 -0500 | [diff] [blame] | 563 | if (!cpu_is_omap34xx() && !cpu_is_omap44xx()) |
Eduardo Valentin | 7aa9ff5 | 2009-08-20 16:18:10 +0300 | [diff] [blame] | 564 | return; |
| 565 | |
| 566 | if (!omap_mcbsp_check_valid_id(id)) { |
| 567 | printk(KERN_ERR "%s: Invalid id (%d)\n", __func__, id + 1); |
| 568 | return; |
| 569 | } |
| 570 | mcbsp = id_to_mcbsp_ptr(id); |
Eduardo Valentin | 7aa9ff5 | 2009-08-20 16:18:10 +0300 | [diff] [blame] | 571 | |
Peter Ujfalusi | 451fd82 | 2010-06-03 07:39:33 +0300 | [diff] [blame] | 572 | if (threshold && threshold <= mcbsp->max_tx_thres) |
| 573 | MCBSP_WRITE(mcbsp, THRSH2, threshold - 1); |
Eduardo Valentin | 7aa9ff5 | 2009-08-20 16:18:10 +0300 | [diff] [blame] | 574 | } |
| 575 | EXPORT_SYMBOL(omap_mcbsp_set_tx_threshold); |
| 576 | |
| 577 | /* |
Peter Ujfalusi | 451fd82 | 2010-06-03 07:39:33 +0300 | [diff] [blame] | 578 | * omap_mcbsp_set_rx_threshold configures the receive threshold in words. |
| 579 | * The threshold parameter is 1 based, and it is converted (threshold - 1) |
| 580 | * for the THRSH1 register. |
Eduardo Valentin | 7aa9ff5 | 2009-08-20 16:18:10 +0300 | [diff] [blame] | 581 | */ |
| 582 | void omap_mcbsp_set_rx_threshold(unsigned int id, u16 threshold) |
| 583 | { |
| 584 | struct omap_mcbsp *mcbsp; |
Eduardo Valentin | 7aa9ff5 | 2009-08-20 16:18:10 +0300 | [diff] [blame] | 585 | |
Jorge Eduardo Candelaria | 752ec2f | 2010-05-12 12:18:40 -0500 | [diff] [blame] | 586 | if (!cpu_is_omap34xx() && !cpu_is_omap44xx()) |
Eduardo Valentin | 7aa9ff5 | 2009-08-20 16:18:10 +0300 | [diff] [blame] | 587 | return; |
| 588 | |
| 589 | if (!omap_mcbsp_check_valid_id(id)) { |
| 590 | printk(KERN_ERR "%s: Invalid id (%d)\n", __func__, id + 1); |
| 591 | return; |
| 592 | } |
| 593 | mcbsp = id_to_mcbsp_ptr(id); |
Eduardo Valentin | 7aa9ff5 | 2009-08-20 16:18:10 +0300 | [diff] [blame] | 594 | |
Peter Ujfalusi | 451fd82 | 2010-06-03 07:39:33 +0300 | [diff] [blame] | 595 | if (threshold && threshold <= mcbsp->max_rx_thres) |
| 596 | MCBSP_WRITE(mcbsp, THRSH1, threshold - 1); |
Eduardo Valentin | 7aa9ff5 | 2009-08-20 16:18:10 +0300 | [diff] [blame] | 597 | } |
| 598 | EXPORT_SYMBOL(omap_mcbsp_set_rx_threshold); |
Eduardo Valentin | a1a56f5 | 2009-08-20 16:18:11 +0300 | [diff] [blame] | 599 | |
| 600 | /* |
| 601 | * omap_mcbsp_get_max_tx_thres just return the current configured |
| 602 | * maximum threshold for transmission |
| 603 | */ |
| 604 | u16 omap_mcbsp_get_max_tx_threshold(unsigned int id) |
| 605 | { |
| 606 | struct omap_mcbsp *mcbsp; |
| 607 | |
| 608 | if (!omap_mcbsp_check_valid_id(id)) { |
| 609 | printk(KERN_ERR "%s: Invalid id (%d)\n", __func__, id + 1); |
| 610 | return -ENODEV; |
| 611 | } |
| 612 | mcbsp = id_to_mcbsp_ptr(id); |
| 613 | |
| 614 | return mcbsp->max_tx_thres; |
| 615 | } |
| 616 | EXPORT_SYMBOL(omap_mcbsp_get_max_tx_threshold); |
| 617 | |
| 618 | /* |
| 619 | * omap_mcbsp_get_max_rx_thres just return the current configured |
| 620 | * maximum threshold for reception |
| 621 | */ |
| 622 | u16 omap_mcbsp_get_max_rx_threshold(unsigned int id) |
| 623 | { |
| 624 | struct omap_mcbsp *mcbsp; |
| 625 | |
| 626 | if (!omap_mcbsp_check_valid_id(id)) { |
| 627 | printk(KERN_ERR "%s: Invalid id (%d)\n", __func__, id + 1); |
| 628 | return -ENODEV; |
| 629 | } |
| 630 | mcbsp = id_to_mcbsp_ptr(id); |
| 631 | |
| 632 | return mcbsp->max_rx_thres; |
| 633 | } |
| 634 | EXPORT_SYMBOL(omap_mcbsp_get_max_rx_threshold); |
Peter Ujfalusi | 98cb20e | 2009-08-20 16:18:14 +0300 | [diff] [blame] | 635 | |
Peter Ujfalusi | 0acce82 | 2010-06-03 07:39:32 +0300 | [diff] [blame] | 636 | u16 omap_mcbsp_get_fifo_size(unsigned int id) |
| 637 | { |
| 638 | struct omap_mcbsp *mcbsp; |
| 639 | |
| 640 | if (!omap_mcbsp_check_valid_id(id)) { |
| 641 | printk(KERN_ERR "%s: Invalid id (%d)\n", __func__, id + 1); |
| 642 | return -ENODEV; |
| 643 | } |
| 644 | mcbsp = id_to_mcbsp_ptr(id); |
| 645 | |
| 646 | return mcbsp->pdata->buffer_size; |
| 647 | } |
| 648 | EXPORT_SYMBOL(omap_mcbsp_get_fifo_size); |
| 649 | |
Peter Ujfalusi | 7dc976e | 2010-03-03 15:08:08 +0200 | [diff] [blame] | 650 | /* |
| 651 | * omap_mcbsp_get_tx_delay returns the number of used slots in the McBSP FIFO |
| 652 | */ |
| 653 | u16 omap_mcbsp_get_tx_delay(unsigned int id) |
| 654 | { |
| 655 | struct omap_mcbsp *mcbsp; |
| 656 | u16 buffstat; |
| 657 | |
| 658 | if (!omap_mcbsp_check_valid_id(id)) { |
| 659 | printk(KERN_ERR "%s: Invalid id (%d)\n", __func__, id + 1); |
| 660 | return -ENODEV; |
| 661 | } |
| 662 | mcbsp = id_to_mcbsp_ptr(id); |
| 663 | |
| 664 | /* Returns the number of free locations in the buffer */ |
| 665 | buffstat = MCBSP_READ(mcbsp, XBUFFSTAT); |
| 666 | |
| 667 | /* Number of slots are different in McBSP ports */ |
Peter Ujfalusi | f10b8ad | 2010-06-03 07:39:34 +0300 | [diff] [blame] | 668 | return mcbsp->pdata->buffer_size - buffstat; |
Peter Ujfalusi | 7dc976e | 2010-03-03 15:08:08 +0200 | [diff] [blame] | 669 | } |
| 670 | EXPORT_SYMBOL(omap_mcbsp_get_tx_delay); |
| 671 | |
| 672 | /* |
| 673 | * omap_mcbsp_get_rx_delay returns the number of free slots in the McBSP FIFO |
| 674 | * to reach the threshold value (when the DMA will be triggered to read it) |
| 675 | */ |
| 676 | u16 omap_mcbsp_get_rx_delay(unsigned int id) |
| 677 | { |
| 678 | struct omap_mcbsp *mcbsp; |
| 679 | u16 buffstat, threshold; |
| 680 | |
| 681 | if (!omap_mcbsp_check_valid_id(id)) { |
| 682 | printk(KERN_ERR "%s: Invalid id (%d)\n", __func__, id + 1); |
| 683 | return -ENODEV; |
| 684 | } |
| 685 | mcbsp = id_to_mcbsp_ptr(id); |
| 686 | |
| 687 | /* Returns the number of used locations in the buffer */ |
| 688 | buffstat = MCBSP_READ(mcbsp, RBUFFSTAT); |
| 689 | /* RX threshold */ |
| 690 | threshold = MCBSP_READ(mcbsp, THRSH1); |
| 691 | |
| 692 | /* Return the number of location till we reach the threshold limit */ |
| 693 | if (threshold <= buffstat) |
| 694 | return 0; |
| 695 | else |
| 696 | return threshold - buffstat; |
| 697 | } |
| 698 | EXPORT_SYMBOL(omap_mcbsp_get_rx_delay); |
| 699 | |
Peter Ujfalusi | 98cb20e | 2009-08-20 16:18:14 +0300 | [diff] [blame] | 700 | /* |
| 701 | * omap_mcbsp_get_dma_op_mode just return the current configured |
| 702 | * operating mode for the mcbsp channel |
| 703 | */ |
| 704 | int omap_mcbsp_get_dma_op_mode(unsigned int id) |
| 705 | { |
| 706 | struct omap_mcbsp *mcbsp; |
| 707 | int dma_op_mode; |
| 708 | |
| 709 | if (!omap_mcbsp_check_valid_id(id)) { |
| 710 | printk(KERN_ERR "%s: Invalid id (%u)\n", __func__, id + 1); |
| 711 | return -ENODEV; |
| 712 | } |
| 713 | mcbsp = id_to_mcbsp_ptr(id); |
| 714 | |
Peter Ujfalusi | 98cb20e | 2009-08-20 16:18:14 +0300 | [diff] [blame] | 715 | dma_op_mode = mcbsp->dma_op_mode; |
Peter Ujfalusi | 98cb20e | 2009-08-20 16:18:14 +0300 | [diff] [blame] | 716 | |
| 717 | return dma_op_mode; |
| 718 | } |
| 719 | EXPORT_SYMBOL(omap_mcbsp_get_dma_op_mode); |
Eero Nurkkala | 2122fdc | 2009-08-20 16:18:15 +0300 | [diff] [blame] | 720 | |
| 721 | static inline void omap34xx_mcbsp_request(struct omap_mcbsp *mcbsp) |
| 722 | { |
Kishon Vijay Abraham I | f36d01d | 2011-02-24 15:16:53 +0530 | [diff] [blame] | 723 | struct omap_device *od; |
| 724 | |
| 725 | od = find_omap_device_by_dev(mcbsp->dev); |
Eero Nurkkala | 2122fdc | 2009-08-20 16:18:15 +0300 | [diff] [blame] | 726 | /* |
| 727 | * Enable wakup behavior, smart idle and all wakeups |
| 728 | * REVISIT: some wakeups may be unnecessary |
| 729 | */ |
Jorge Eduardo Candelaria | 752ec2f | 2010-05-12 12:18:40 -0500 | [diff] [blame] | 730 | if (cpu_is_omap34xx() || cpu_is_omap44xx()) { |
Kishon Vijay Abraham I | f36d01d | 2011-02-24 15:16:53 +0530 | [diff] [blame] | 731 | MCBSP_WRITE(mcbsp, WAKEUPEN, XRDYEN | RRDYEN); |
Eero Nurkkala | 2122fdc | 2009-08-20 16:18:15 +0300 | [diff] [blame] | 732 | } |
| 733 | } |
| 734 | |
| 735 | static inline void omap34xx_mcbsp_free(struct omap_mcbsp *mcbsp) |
| 736 | { |
Kishon Vijay Abraham I | f36d01d | 2011-02-24 15:16:53 +0530 | [diff] [blame] | 737 | struct omap_device *od; |
| 738 | |
| 739 | od = find_omap_device_by_dev(mcbsp->dev); |
| 740 | |
Eero Nurkkala | 2122fdc | 2009-08-20 16:18:15 +0300 | [diff] [blame] | 741 | /* |
| 742 | * Disable wakup behavior, smart idle and all wakeups |
| 743 | */ |
Jorge Eduardo Candelaria | 752ec2f | 2010-05-12 12:18:40 -0500 | [diff] [blame] | 744 | if (cpu_is_omap34xx() || cpu_is_omap44xx()) { |
Eero Nurkkala | 72cc6d7 | 2009-08-20 16:18:20 +0300 | [diff] [blame] | 745 | /* |
| 746 | * HW bug workaround - If no_idle mode is taken, we need to |
| 747 | * go to smart_idle before going to always_idle, or the |
| 748 | * device will not hit retention anymore. |
| 749 | */ |
Eero Nurkkala | 2122fdc | 2009-08-20 16:18:15 +0300 | [diff] [blame] | 750 | |
Janusz Krzysztofik | 8ea3200 | 2010-02-15 10:03:32 -0800 | [diff] [blame] | 751 | MCBSP_WRITE(mcbsp, WAKEUPEN, 0); |
Eero Nurkkala | 2122fdc | 2009-08-20 16:18:15 +0300 | [diff] [blame] | 752 | } |
| 753 | } |
| 754 | #else |
| 755 | static inline void omap34xx_mcbsp_request(struct omap_mcbsp *mcbsp) {} |
| 756 | static inline void omap34xx_mcbsp_free(struct omap_mcbsp *mcbsp) {} |
Eero Nurkkala | d912fa9 | 2010-02-22 12:21:11 +0000 | [diff] [blame] | 757 | static inline void omap_st_start(struct omap_mcbsp *mcbsp) {} |
| 758 | static inline void omap_st_stop(struct omap_mcbsp *mcbsp) {} |
Eduardo Valentin | 7aa9ff5 | 2009-08-20 16:18:10 +0300 | [diff] [blame] | 759 | #endif |
| 760 | |
Tony Lindgren | 120db2c | 2006-04-02 17:46:27 +0100 | [diff] [blame] | 761 | /* |
| 762 | * We can choose between IRQ based or polled IO. |
| 763 | * This needs to be called before omap_mcbsp_request(). |
| 764 | */ |
| 765 | int omap_mcbsp_set_io_type(unsigned int id, omap_mcbsp_io_type_t io_type) |
| 766 | { |
Chandra Shekhar | b4b58f5 | 2008-10-08 10:01:39 +0300 | [diff] [blame] | 767 | struct omap_mcbsp *mcbsp; |
| 768 | |
Eduardo Valentin | bc5d0c8 | 2008-07-03 12:24:39 +0300 | [diff] [blame] | 769 | if (!omap_mcbsp_check_valid_id(id)) { |
| 770 | printk(KERN_ERR "%s: Invalid id (%d)\n", __func__, id + 1); |
| 771 | return -ENODEV; |
| 772 | } |
Chandra Shekhar | b4b58f5 | 2008-10-08 10:01:39 +0300 | [diff] [blame] | 773 | mcbsp = id_to_mcbsp_ptr(id); |
Tony Lindgren | 120db2c | 2006-04-02 17:46:27 +0100 | [diff] [blame] | 774 | |
Chandra Shekhar | b4b58f5 | 2008-10-08 10:01:39 +0300 | [diff] [blame] | 775 | spin_lock(&mcbsp->lock); |
Tony Lindgren | 120db2c | 2006-04-02 17:46:27 +0100 | [diff] [blame] | 776 | |
Chandra Shekhar | b4b58f5 | 2008-10-08 10:01:39 +0300 | [diff] [blame] | 777 | if (!mcbsp->free) { |
| 778 | dev_err(mcbsp->dev, "McBSP%d is currently in use\n", |
| 779 | mcbsp->id); |
| 780 | spin_unlock(&mcbsp->lock); |
Tony Lindgren | 120db2c | 2006-04-02 17:46:27 +0100 | [diff] [blame] | 781 | return -EINVAL; |
| 782 | } |
| 783 | |
Chandra Shekhar | b4b58f5 | 2008-10-08 10:01:39 +0300 | [diff] [blame] | 784 | mcbsp->io_type = io_type; |
Tony Lindgren | 120db2c | 2006-04-02 17:46:27 +0100 | [diff] [blame] | 785 | |
Chandra Shekhar | b4b58f5 | 2008-10-08 10:01:39 +0300 | [diff] [blame] | 786 | spin_unlock(&mcbsp->lock); |
Tony Lindgren | 120db2c | 2006-04-02 17:46:27 +0100 | [diff] [blame] | 787 | |
| 788 | return 0; |
| 789 | } |
Eduardo Valentin | fb78d80 | 2008-07-03 12:24:39 +0300 | [diff] [blame] | 790 | EXPORT_SYMBOL(omap_mcbsp_set_io_type); |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 791 | |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 792 | int omap_mcbsp_request(unsigned int id) |
| 793 | { |
Chandra Shekhar | b4b58f5 | 2008-10-08 10:01:39 +0300 | [diff] [blame] | 794 | struct omap_mcbsp *mcbsp; |
Janusz Krzysztofik | c8c9969 | 2010-02-15 10:03:33 -0800 | [diff] [blame] | 795 | void *reg_cache; |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 796 | int err; |
| 797 | |
Eduardo Valentin | bc5d0c8 | 2008-07-03 12:24:39 +0300 | [diff] [blame] | 798 | if (!omap_mcbsp_check_valid_id(id)) { |
| 799 | printk(KERN_ERR "%s: Invalid id (%d)\n", __func__, id + 1); |
| 800 | return -ENODEV; |
Tony Lindgren | 120db2c | 2006-04-02 17:46:27 +0100 | [diff] [blame] | 801 | } |
Chandra Shekhar | b4b58f5 | 2008-10-08 10:01:39 +0300 | [diff] [blame] | 802 | mcbsp = id_to_mcbsp_ptr(id); |
Eduardo Valentin | bc5d0c8 | 2008-07-03 12:24:39 +0300 | [diff] [blame] | 803 | |
Janusz Krzysztofik | c8c9969 | 2010-02-15 10:03:33 -0800 | [diff] [blame] | 804 | reg_cache = kzalloc(omap_mcbsp_cache_size, GFP_KERNEL); |
| 805 | if (!reg_cache) { |
| 806 | return -ENOMEM; |
| 807 | } |
| 808 | |
Chandra Shekhar | b4b58f5 | 2008-10-08 10:01:39 +0300 | [diff] [blame] | 809 | spin_lock(&mcbsp->lock); |
| 810 | if (!mcbsp->free) { |
| 811 | dev_err(mcbsp->dev, "McBSP%d is currently in use\n", |
| 812 | mcbsp->id); |
Janusz Krzysztofik | c8c9969 | 2010-02-15 10:03:33 -0800 | [diff] [blame] | 813 | err = -EBUSY; |
| 814 | goto err_kfree; |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 815 | } |
| 816 | |
Shubhrajyoti D | 6722a72 | 2010-12-07 16:25:41 -0800 | [diff] [blame] | 817 | mcbsp->free = false; |
Janusz Krzysztofik | c8c9969 | 2010-02-15 10:03:33 -0800 | [diff] [blame] | 818 | mcbsp->reg_cache = reg_cache; |
Chandra Shekhar | b4b58f5 | 2008-10-08 10:01:39 +0300 | [diff] [blame] | 819 | spin_unlock(&mcbsp->lock); |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 820 | |
Russell King | b820ce4 | 2009-01-23 10:26:46 +0000 | [diff] [blame] | 821 | if (mcbsp->pdata && mcbsp->pdata->ops && mcbsp->pdata->ops->request) |
| 822 | mcbsp->pdata->ops->request(id); |
| 823 | |
Kishon Vijay Abraham I | e95496d | 2011-02-24 15:16:54 +0530 | [diff] [blame] | 824 | pm_runtime_get_sync(mcbsp->dev); |
Russell King | b820ce4 | 2009-01-23 10:26:46 +0000 | [diff] [blame] | 825 | |
Eero Nurkkala | 2122fdc | 2009-08-20 16:18:15 +0300 | [diff] [blame] | 826 | /* Do procedure specific to omap34xx arch, if applicable */ |
| 827 | omap34xx_mcbsp_request(mcbsp); |
| 828 | |
Jarkko Nikula | 5a07055 | 2008-10-08 10:01:41 +0300 | [diff] [blame] | 829 | /* |
| 830 | * Make sure that transmitter, receiver and sample-rate generator are |
| 831 | * not running before activating IRQs. |
| 832 | */ |
Janusz Krzysztofik | 8ea3200 | 2010-02-15 10:03:32 -0800 | [diff] [blame] | 833 | MCBSP_WRITE(mcbsp, SPCR1, 0); |
| 834 | MCBSP_WRITE(mcbsp, SPCR2, 0); |
Jarkko Nikula | 5a07055 | 2008-10-08 10:01:41 +0300 | [diff] [blame] | 835 | |
Chandra Shekhar | b4b58f5 | 2008-10-08 10:01:39 +0300 | [diff] [blame] | 836 | if (mcbsp->io_type == OMAP_MCBSP_IRQ_IO) { |
Tony Lindgren | 120db2c | 2006-04-02 17:46:27 +0100 | [diff] [blame] | 837 | /* We need to get IRQs here */ |
Jarkko Nikula | 5a07055 | 2008-10-08 10:01:41 +0300 | [diff] [blame] | 838 | init_completion(&mcbsp->tx_irq_completion); |
Chandra Shekhar | b4b58f5 | 2008-10-08 10:01:39 +0300 | [diff] [blame] | 839 | err = request_irq(mcbsp->tx_irq, omap_mcbsp_tx_irq_handler, |
| 840 | 0, "McBSP", (void *)mcbsp); |
Tony Lindgren | 120db2c | 2006-04-02 17:46:27 +0100 | [diff] [blame] | 841 | if (err != 0) { |
Chandra Shekhar | b4b58f5 | 2008-10-08 10:01:39 +0300 | [diff] [blame] | 842 | dev_err(mcbsp->dev, "Unable to request TX IRQ %d " |
| 843 | "for McBSP%d\n", mcbsp->tx_irq, |
| 844 | mcbsp->id); |
Janusz Krzysztofik | c8c9969 | 2010-02-15 10:03:33 -0800 | [diff] [blame] | 845 | goto err_clk_disable; |
Tony Lindgren | 120db2c | 2006-04-02 17:46:27 +0100 | [diff] [blame] | 846 | } |
| 847 | |
Jorge Eduardo Candelaria | 9319b9d | 2010-05-12 12:18:39 -0500 | [diff] [blame] | 848 | if (mcbsp->rx_irq) { |
| 849 | init_completion(&mcbsp->rx_irq_completion); |
| 850 | err = request_irq(mcbsp->rx_irq, |
| 851 | omap_mcbsp_rx_irq_handler, |
Chandra Shekhar | b4b58f5 | 2008-10-08 10:01:39 +0300 | [diff] [blame] | 852 | 0, "McBSP", (void *)mcbsp); |
Jorge Eduardo Candelaria | 9319b9d | 2010-05-12 12:18:39 -0500 | [diff] [blame] | 853 | if (err != 0) { |
| 854 | dev_err(mcbsp->dev, "Unable to request RX IRQ %d " |
| 855 | "for McBSP%d\n", mcbsp->rx_irq, |
| 856 | mcbsp->id); |
| 857 | goto err_free_irq; |
| 858 | } |
Tony Lindgren | 120db2c | 2006-04-02 17:46:27 +0100 | [diff] [blame] | 859 | } |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 860 | } |
| 861 | |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 862 | return 0; |
Janusz Krzysztofik | c8c9969 | 2010-02-15 10:03:33 -0800 | [diff] [blame] | 863 | err_free_irq: |
Janusz Krzysztofik | 1866b54 | 2010-01-08 10:29:04 -0800 | [diff] [blame] | 864 | free_irq(mcbsp->tx_irq, (void *)mcbsp); |
Janusz Krzysztofik | c8c9969 | 2010-02-15 10:03:33 -0800 | [diff] [blame] | 865 | err_clk_disable: |
Janusz Krzysztofik | 1866b54 | 2010-01-08 10:29:04 -0800 | [diff] [blame] | 866 | if (mcbsp->pdata && mcbsp->pdata->ops && mcbsp->pdata->ops->free) |
Janusz Krzysztofik | c8c9969 | 2010-02-15 10:03:33 -0800 | [diff] [blame] | 867 | mcbsp->pdata->ops->free(id); |
Janusz Krzysztofik | 1866b54 | 2010-01-08 10:29:04 -0800 | [diff] [blame] | 868 | |
| 869 | /* Do procedure specific to omap34xx arch, if applicable */ |
| 870 | omap34xx_mcbsp_free(mcbsp); |
| 871 | |
Kishon Vijay Abraham I | e95496d | 2011-02-24 15:16:54 +0530 | [diff] [blame] | 872 | pm_runtime_put_sync(mcbsp->dev); |
Janusz Krzysztofik | 1866b54 | 2010-01-08 10:29:04 -0800 | [diff] [blame] | 873 | |
Janusz Krzysztofik | c8c9969 | 2010-02-15 10:03:33 -0800 | [diff] [blame] | 874 | spin_lock(&mcbsp->lock); |
Shubhrajyoti D | 6722a72 | 2010-12-07 16:25:41 -0800 | [diff] [blame] | 875 | mcbsp->free = true; |
Janusz Krzysztofik | c8c9969 | 2010-02-15 10:03:33 -0800 | [diff] [blame] | 876 | mcbsp->reg_cache = NULL; |
| 877 | err_kfree: |
| 878 | spin_unlock(&mcbsp->lock); |
| 879 | kfree(reg_cache); |
Janusz Krzysztofik | 1866b54 | 2010-01-08 10:29:04 -0800 | [diff] [blame] | 880 | |
| 881 | return err; |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 882 | } |
Eduardo Valentin | fb78d80 | 2008-07-03 12:24:39 +0300 | [diff] [blame] | 883 | EXPORT_SYMBOL(omap_mcbsp_request); |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 884 | |
| 885 | void omap_mcbsp_free(unsigned int id) |
| 886 | { |
Chandra Shekhar | b4b58f5 | 2008-10-08 10:01:39 +0300 | [diff] [blame] | 887 | struct omap_mcbsp *mcbsp; |
Janusz Krzysztofik | c8c9969 | 2010-02-15 10:03:33 -0800 | [diff] [blame] | 888 | void *reg_cache; |
Chandra Shekhar | b4b58f5 | 2008-10-08 10:01:39 +0300 | [diff] [blame] | 889 | |
Eduardo Valentin | bc5d0c8 | 2008-07-03 12:24:39 +0300 | [diff] [blame] | 890 | if (!omap_mcbsp_check_valid_id(id)) { |
| 891 | printk(KERN_ERR "%s: Invalid id (%d)\n", __func__, id + 1); |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 892 | return; |
Tony Lindgren | 120db2c | 2006-04-02 17:46:27 +0100 | [diff] [blame] | 893 | } |
Chandra Shekhar | b4b58f5 | 2008-10-08 10:01:39 +0300 | [diff] [blame] | 894 | mcbsp = id_to_mcbsp_ptr(id); |
Tony Lindgren | 120db2c | 2006-04-02 17:46:27 +0100 | [diff] [blame] | 895 | |
Chandra Shekhar | b4b58f5 | 2008-10-08 10:01:39 +0300 | [diff] [blame] | 896 | if (mcbsp->pdata && mcbsp->pdata->ops && mcbsp->pdata->ops->free) |
| 897 | mcbsp->pdata->ops->free(id); |
Eduardo Valentin | bc5d0c8 | 2008-07-03 12:24:39 +0300 | [diff] [blame] | 898 | |
Eero Nurkkala | 2122fdc | 2009-08-20 16:18:15 +0300 | [diff] [blame] | 899 | /* Do procedure specific to omap34xx arch, if applicable */ |
| 900 | omap34xx_mcbsp_free(mcbsp); |
| 901 | |
Kishon Vijay Abraham I | e95496d | 2011-02-24 15:16:54 +0530 | [diff] [blame] | 902 | pm_runtime_put_sync(mcbsp->dev); |
Russell King | b820ce4 | 2009-01-23 10:26:46 +0000 | [diff] [blame] | 903 | |
| 904 | if (mcbsp->io_type == OMAP_MCBSP_IRQ_IO) { |
| 905 | /* Free IRQs */ |
Jorge Eduardo Candelaria | 9319b9d | 2010-05-12 12:18:39 -0500 | [diff] [blame] | 906 | if (mcbsp->rx_irq) |
| 907 | free_irq(mcbsp->rx_irq, (void *)mcbsp); |
Russell King | b820ce4 | 2009-01-23 10:26:46 +0000 | [diff] [blame] | 908 | free_irq(mcbsp->tx_irq, (void *)mcbsp); |
| 909 | } |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 910 | |
Janusz Krzysztofik | c8c9969 | 2010-02-15 10:03:33 -0800 | [diff] [blame] | 911 | reg_cache = mcbsp->reg_cache; |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 912 | |
Janusz Krzysztofik | c8c9969 | 2010-02-15 10:03:33 -0800 | [diff] [blame] | 913 | spin_lock(&mcbsp->lock); |
| 914 | if (mcbsp->free) |
| 915 | dev_err(mcbsp->dev, "McBSP%d was not reserved\n", mcbsp->id); |
| 916 | else |
Shubhrajyoti D | 6722a72 | 2010-12-07 16:25:41 -0800 | [diff] [blame] | 917 | mcbsp->free = true; |
Janusz Krzysztofik | c8c9969 | 2010-02-15 10:03:33 -0800 | [diff] [blame] | 918 | mcbsp->reg_cache = NULL; |
Chandra Shekhar | b4b58f5 | 2008-10-08 10:01:39 +0300 | [diff] [blame] | 919 | spin_unlock(&mcbsp->lock); |
Janusz Krzysztofik | c8c9969 | 2010-02-15 10:03:33 -0800 | [diff] [blame] | 920 | |
| 921 | if (reg_cache) |
| 922 | kfree(reg_cache); |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 923 | } |
Eduardo Valentin | fb78d80 | 2008-07-03 12:24:39 +0300 | [diff] [blame] | 924 | EXPORT_SYMBOL(omap_mcbsp_free); |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 925 | |
| 926 | /* |
Jarkko Nikula | c12abc0 | 2009-08-07 09:59:47 +0300 | [diff] [blame] | 927 | * Here we start the McBSP, by enabling transmitter, receiver or both. |
| 928 | * If no transmitter or receiver is active prior calling, then sample-rate |
| 929 | * generator and frame sync are started. |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 930 | */ |
Jarkko Nikula | c12abc0 | 2009-08-07 09:59:47 +0300 | [diff] [blame] | 931 | void omap_mcbsp_start(unsigned int id, int tx, int rx) |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 932 | { |
Chandra Shekhar | b4b58f5 | 2008-10-08 10:01:39 +0300 | [diff] [blame] | 933 | struct omap_mcbsp *mcbsp; |
Peter Ujfalusi | ce3f054 | 2010-08-31 08:11:44 +0000 | [diff] [blame] | 934 | int enable_srg = 0; |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 935 | u16 w; |
| 936 | |
Eduardo Valentin | bc5d0c8 | 2008-07-03 12:24:39 +0300 | [diff] [blame] | 937 | if (!omap_mcbsp_check_valid_id(id)) { |
| 938 | printk(KERN_ERR "%s: Invalid id (%d)\n", __func__, id + 1); |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 939 | return; |
Eduardo Valentin | bc5d0c8 | 2008-07-03 12:24:39 +0300 | [diff] [blame] | 940 | } |
Chandra Shekhar | b4b58f5 | 2008-10-08 10:01:39 +0300 | [diff] [blame] | 941 | mcbsp = id_to_mcbsp_ptr(id); |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 942 | |
Eero Nurkkala | d912fa9 | 2010-02-22 12:21:11 +0000 | [diff] [blame] | 943 | if (cpu_is_omap34xx()) |
| 944 | omap_st_start(mcbsp); |
| 945 | |
Janusz Krzysztofik | 96fbd74 | 2010-02-15 10:03:33 -0800 | [diff] [blame] | 946 | mcbsp->rx_word_length = (MCBSP_READ_CACHE(mcbsp, RCR1) >> 5) & 0x7; |
| 947 | mcbsp->tx_word_length = (MCBSP_READ_CACHE(mcbsp, XCR1) >> 5) & 0x7; |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 948 | |
Peter Ujfalusi | ce3f054 | 2010-08-31 08:11:44 +0000 | [diff] [blame] | 949 | /* Only enable SRG, if McBSP is master */ |
| 950 | w = MCBSP_READ_CACHE(mcbsp, PCR0); |
| 951 | if (w & (FSXM | FSRM | CLKXM | CLKRM)) |
| 952 | enable_srg = !((MCBSP_READ_CACHE(mcbsp, SPCR2) | |
| 953 | MCBSP_READ_CACHE(mcbsp, SPCR1)) & 1); |
Jarkko Nikula | c12abc0 | 2009-08-07 09:59:47 +0300 | [diff] [blame] | 954 | |
Peter Ujfalusi | ce3f054 | 2010-08-31 08:11:44 +0000 | [diff] [blame] | 955 | if (enable_srg) { |
Jarkko Nikula | c12abc0 | 2009-08-07 09:59:47 +0300 | [diff] [blame] | 956 | /* Start the sample generator */ |
Janusz Krzysztofik | 96fbd74 | 2010-02-15 10:03:33 -0800 | [diff] [blame] | 957 | w = MCBSP_READ_CACHE(mcbsp, SPCR2); |
Janusz Krzysztofik | 8ea3200 | 2010-02-15 10:03:32 -0800 | [diff] [blame] | 958 | MCBSP_WRITE(mcbsp, SPCR2, w | (1 << 6)); |
Jarkko Nikula | c12abc0 | 2009-08-07 09:59:47 +0300 | [diff] [blame] | 959 | } |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 960 | |
| 961 | /* Enable transmitter and receiver */ |
Jarkko Nikula | d09a2af | 2009-08-23 12:24:27 +0300 | [diff] [blame] | 962 | tx &= 1; |
Janusz Krzysztofik | 96fbd74 | 2010-02-15 10:03:33 -0800 | [diff] [blame] | 963 | w = MCBSP_READ_CACHE(mcbsp, SPCR2); |
Janusz Krzysztofik | 8ea3200 | 2010-02-15 10:03:32 -0800 | [diff] [blame] | 964 | MCBSP_WRITE(mcbsp, SPCR2, w | tx); |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 965 | |
Jarkko Nikula | d09a2af | 2009-08-23 12:24:27 +0300 | [diff] [blame] | 966 | rx &= 1; |
Janusz Krzysztofik | 96fbd74 | 2010-02-15 10:03:33 -0800 | [diff] [blame] | 967 | w = MCBSP_READ_CACHE(mcbsp, SPCR1); |
Janusz Krzysztofik | 8ea3200 | 2010-02-15 10:03:32 -0800 | [diff] [blame] | 968 | MCBSP_WRITE(mcbsp, SPCR1, w | rx); |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 969 | |
Eduardo Valentin | 44a6311 | 2009-08-20 16:18:09 +0300 | [diff] [blame] | 970 | /* |
| 971 | * Worst case: CLKSRG*2 = 8000khz: (1/8000) * 2 * 2 usec |
| 972 | * REVISIT: 100us may give enough time for two CLKSRG, however |
| 973 | * due to some unknown PM related, clock gating etc. reason it |
| 974 | * is now at 500us. |
| 975 | */ |
| 976 | udelay(500); |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 977 | |
Peter Ujfalusi | ce3f054 | 2010-08-31 08:11:44 +0000 | [diff] [blame] | 978 | if (enable_srg) { |
Jarkko Nikula | c12abc0 | 2009-08-07 09:59:47 +0300 | [diff] [blame] | 979 | /* Start frame sync */ |
Janusz Krzysztofik | 96fbd74 | 2010-02-15 10:03:33 -0800 | [diff] [blame] | 980 | w = MCBSP_READ_CACHE(mcbsp, SPCR2); |
Janusz Krzysztofik | 8ea3200 | 2010-02-15 10:03:32 -0800 | [diff] [blame] | 981 | MCBSP_WRITE(mcbsp, SPCR2, w | (1 << 7)); |
Jarkko Nikula | c12abc0 | 2009-08-07 09:59:47 +0300 | [diff] [blame] | 982 | } |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 983 | |
Jorge Eduardo Candelaria | 752ec2f | 2010-05-12 12:18:40 -0500 | [diff] [blame] | 984 | if (cpu_is_omap2430() || cpu_is_omap34xx() || cpu_is_omap44xx()) { |
Jarkko Nikula | d09a2af | 2009-08-23 12:24:27 +0300 | [diff] [blame] | 985 | /* Release the transmitter and receiver */ |
Janusz Krzysztofik | 96fbd74 | 2010-02-15 10:03:33 -0800 | [diff] [blame] | 986 | w = MCBSP_READ_CACHE(mcbsp, XCCR); |
Jarkko Nikula | d09a2af | 2009-08-23 12:24:27 +0300 | [diff] [blame] | 987 | w &= ~(tx ? XDISABLE : 0); |
Janusz Krzysztofik | 8ea3200 | 2010-02-15 10:03:32 -0800 | [diff] [blame] | 988 | MCBSP_WRITE(mcbsp, XCCR, w); |
Janusz Krzysztofik | 96fbd74 | 2010-02-15 10:03:33 -0800 | [diff] [blame] | 989 | w = MCBSP_READ_CACHE(mcbsp, RCCR); |
Jarkko Nikula | d09a2af | 2009-08-23 12:24:27 +0300 | [diff] [blame] | 990 | w &= ~(rx ? RDISABLE : 0); |
Janusz Krzysztofik | 8ea3200 | 2010-02-15 10:03:32 -0800 | [diff] [blame] | 991 | MCBSP_WRITE(mcbsp, RCCR, w); |
Jarkko Nikula | d09a2af | 2009-08-23 12:24:27 +0300 | [diff] [blame] | 992 | } |
| 993 | |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 994 | /* Dump McBSP Regs */ |
| 995 | omap_mcbsp_dump_reg(id); |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 996 | } |
Eduardo Valentin | fb78d80 | 2008-07-03 12:24:39 +0300 | [diff] [blame] | 997 | EXPORT_SYMBOL(omap_mcbsp_start); |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 998 | |
Jarkko Nikula | c12abc0 | 2009-08-07 09:59:47 +0300 | [diff] [blame] | 999 | void omap_mcbsp_stop(unsigned int id, int tx, int rx) |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 1000 | { |
Chandra Shekhar | b4b58f5 | 2008-10-08 10:01:39 +0300 | [diff] [blame] | 1001 | struct omap_mcbsp *mcbsp; |
Jarkko Nikula | c12abc0 | 2009-08-07 09:59:47 +0300 | [diff] [blame] | 1002 | int idle; |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 1003 | u16 w; |
| 1004 | |
Eduardo Valentin | bc5d0c8 | 2008-07-03 12:24:39 +0300 | [diff] [blame] | 1005 | if (!omap_mcbsp_check_valid_id(id)) { |
| 1006 | printk(KERN_ERR "%s: Invalid id (%d)\n", __func__, id + 1); |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 1007 | return; |
Eduardo Valentin | bc5d0c8 | 2008-07-03 12:24:39 +0300 | [diff] [blame] | 1008 | } |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 1009 | |
Chandra Shekhar | b4b58f5 | 2008-10-08 10:01:39 +0300 | [diff] [blame] | 1010 | mcbsp = id_to_mcbsp_ptr(id); |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 1011 | |
Eduardo Valentin | fb78d80 | 2008-07-03 12:24:39 +0300 | [diff] [blame] | 1012 | /* Reset transmitter */ |
Jarkko Nikula | d09a2af | 2009-08-23 12:24:27 +0300 | [diff] [blame] | 1013 | tx &= 1; |
Jorge Eduardo Candelaria | 752ec2f | 2010-05-12 12:18:40 -0500 | [diff] [blame] | 1014 | if (cpu_is_omap2430() || cpu_is_omap34xx() || cpu_is_omap44xx()) { |
Janusz Krzysztofik | 96fbd74 | 2010-02-15 10:03:33 -0800 | [diff] [blame] | 1015 | w = MCBSP_READ_CACHE(mcbsp, XCCR); |
Jarkko Nikula | d09a2af | 2009-08-23 12:24:27 +0300 | [diff] [blame] | 1016 | w |= (tx ? XDISABLE : 0); |
Janusz Krzysztofik | 8ea3200 | 2010-02-15 10:03:32 -0800 | [diff] [blame] | 1017 | MCBSP_WRITE(mcbsp, XCCR, w); |
Jarkko Nikula | d09a2af | 2009-08-23 12:24:27 +0300 | [diff] [blame] | 1018 | } |
Janusz Krzysztofik | 96fbd74 | 2010-02-15 10:03:33 -0800 | [diff] [blame] | 1019 | w = MCBSP_READ_CACHE(mcbsp, SPCR2); |
Janusz Krzysztofik | 8ea3200 | 2010-02-15 10:03:32 -0800 | [diff] [blame] | 1020 | MCBSP_WRITE(mcbsp, SPCR2, w & ~tx); |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 1021 | |
| 1022 | /* Reset receiver */ |
Jarkko Nikula | d09a2af | 2009-08-23 12:24:27 +0300 | [diff] [blame] | 1023 | rx &= 1; |
Jorge Eduardo Candelaria | 752ec2f | 2010-05-12 12:18:40 -0500 | [diff] [blame] | 1024 | if (cpu_is_omap2430() || cpu_is_omap34xx() || cpu_is_omap44xx()) { |
Janusz Krzysztofik | 96fbd74 | 2010-02-15 10:03:33 -0800 | [diff] [blame] | 1025 | w = MCBSP_READ_CACHE(mcbsp, RCCR); |
Jarkko Nikula | a93d4ed | 2009-10-14 09:56:35 -0700 | [diff] [blame] | 1026 | w |= (rx ? RDISABLE : 0); |
Janusz Krzysztofik | 8ea3200 | 2010-02-15 10:03:32 -0800 | [diff] [blame] | 1027 | MCBSP_WRITE(mcbsp, RCCR, w); |
Jarkko Nikula | d09a2af | 2009-08-23 12:24:27 +0300 | [diff] [blame] | 1028 | } |
Janusz Krzysztofik | 96fbd74 | 2010-02-15 10:03:33 -0800 | [diff] [blame] | 1029 | w = MCBSP_READ_CACHE(mcbsp, SPCR1); |
Janusz Krzysztofik | 8ea3200 | 2010-02-15 10:03:32 -0800 | [diff] [blame] | 1030 | MCBSP_WRITE(mcbsp, SPCR1, w & ~rx); |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 1031 | |
Janusz Krzysztofik | 96fbd74 | 2010-02-15 10:03:33 -0800 | [diff] [blame] | 1032 | idle = !((MCBSP_READ_CACHE(mcbsp, SPCR2) | |
| 1033 | MCBSP_READ_CACHE(mcbsp, SPCR1)) & 1); |
Jarkko Nikula | c12abc0 | 2009-08-07 09:59:47 +0300 | [diff] [blame] | 1034 | |
| 1035 | if (idle) { |
| 1036 | /* Reset the sample rate generator */ |
Janusz Krzysztofik | 96fbd74 | 2010-02-15 10:03:33 -0800 | [diff] [blame] | 1037 | w = MCBSP_READ_CACHE(mcbsp, SPCR2); |
Janusz Krzysztofik | 8ea3200 | 2010-02-15 10:03:32 -0800 | [diff] [blame] | 1038 | MCBSP_WRITE(mcbsp, SPCR2, w & ~(1 << 6)); |
Jarkko Nikula | c12abc0 | 2009-08-07 09:59:47 +0300 | [diff] [blame] | 1039 | } |
Eero Nurkkala | d912fa9 | 2010-02-22 12:21:11 +0000 | [diff] [blame] | 1040 | |
| 1041 | if (cpu_is_omap34xx()) |
| 1042 | omap_st_stop(mcbsp); |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 1043 | } |
Eduardo Valentin | fb78d80 | 2008-07-03 12:24:39 +0300 | [diff] [blame] | 1044 | EXPORT_SYMBOL(omap_mcbsp_stop); |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 1045 | |
Tony Lindgren | bb13b5f | 2005-07-10 19:58:18 +0100 | [diff] [blame] | 1046 | /* polled mcbsp i/o operations */ |
| 1047 | int omap_mcbsp_pollwrite(unsigned int id, u16 buf) |
| 1048 | { |
Chandra Shekhar | b4b58f5 | 2008-10-08 10:01:39 +0300 | [diff] [blame] | 1049 | struct omap_mcbsp *mcbsp; |
Eduardo Valentin | bc5d0c8 | 2008-07-03 12:24:39 +0300 | [diff] [blame] | 1050 | |
| 1051 | if (!omap_mcbsp_check_valid_id(id)) { |
| 1052 | printk(KERN_ERR "%s: Invalid id (%d)\n", __func__, id + 1); |
| 1053 | return -ENODEV; |
| 1054 | } |
| 1055 | |
Chandra Shekhar | b4b58f5 | 2008-10-08 10:01:39 +0300 | [diff] [blame] | 1056 | mcbsp = id_to_mcbsp_ptr(id); |
Chandra Shekhar | b4b58f5 | 2008-10-08 10:01:39 +0300 | [diff] [blame] | 1057 | |
Janusz Krzysztofik | 8ea3200 | 2010-02-15 10:03:32 -0800 | [diff] [blame] | 1058 | MCBSP_WRITE(mcbsp, DXR1, buf); |
Tony Lindgren | bb13b5f | 2005-07-10 19:58:18 +0100 | [diff] [blame] | 1059 | /* if frame sync error - clear the error */ |
Janusz Krzysztofik | 8ea3200 | 2010-02-15 10:03:32 -0800 | [diff] [blame] | 1060 | if (MCBSP_READ(mcbsp, SPCR2) & XSYNC_ERR) { |
Tony Lindgren | bb13b5f | 2005-07-10 19:58:18 +0100 | [diff] [blame] | 1061 | /* clear error */ |
Janusz Krzysztofik | 0841cb8 | 2010-02-23 15:50:38 +0000 | [diff] [blame] | 1062 | MCBSP_WRITE(mcbsp, SPCR2, MCBSP_READ_CACHE(mcbsp, SPCR2)); |
Tony Lindgren | bb13b5f | 2005-07-10 19:58:18 +0100 | [diff] [blame] | 1063 | /* resend */ |
| 1064 | return -1; |
| 1065 | } else { |
| 1066 | /* wait for transmit confirmation */ |
| 1067 | int attemps = 0; |
Janusz Krzysztofik | 8ea3200 | 2010-02-15 10:03:32 -0800 | [diff] [blame] | 1068 | while (!(MCBSP_READ(mcbsp, SPCR2) & XRDY)) { |
Tony Lindgren | bb13b5f | 2005-07-10 19:58:18 +0100 | [diff] [blame] | 1069 | if (attemps++ > 1000) { |
Janusz Krzysztofik | 8ea3200 | 2010-02-15 10:03:32 -0800 | [diff] [blame] | 1070 | MCBSP_WRITE(mcbsp, SPCR2, |
Janusz Krzysztofik | 96fbd74 | 2010-02-15 10:03:33 -0800 | [diff] [blame] | 1071 | MCBSP_READ_CACHE(mcbsp, SPCR2) & |
| 1072 | (~XRST)); |
Tony Lindgren | bb13b5f | 2005-07-10 19:58:18 +0100 | [diff] [blame] | 1073 | udelay(10); |
Janusz Krzysztofik | 8ea3200 | 2010-02-15 10:03:32 -0800 | [diff] [blame] | 1074 | MCBSP_WRITE(mcbsp, SPCR2, |
Janusz Krzysztofik | 96fbd74 | 2010-02-15 10:03:33 -0800 | [diff] [blame] | 1075 | MCBSP_READ_CACHE(mcbsp, SPCR2) | |
| 1076 | (XRST)); |
Tony Lindgren | bb13b5f | 2005-07-10 19:58:18 +0100 | [diff] [blame] | 1077 | udelay(10); |
Chandra Shekhar | b4b58f5 | 2008-10-08 10:01:39 +0300 | [diff] [blame] | 1078 | dev_err(mcbsp->dev, "Could not write to" |
| 1079 | " McBSP%d Register\n", mcbsp->id); |
Tony Lindgren | bb13b5f | 2005-07-10 19:58:18 +0100 | [diff] [blame] | 1080 | return -2; |
| 1081 | } |
| 1082 | } |
| 1083 | } |
Eduardo Valentin | fb78d80 | 2008-07-03 12:24:39 +0300 | [diff] [blame] | 1084 | |
Tony Lindgren | bb13b5f | 2005-07-10 19:58:18 +0100 | [diff] [blame] | 1085 | return 0; |
| 1086 | } |
Eduardo Valentin | fb78d80 | 2008-07-03 12:24:39 +0300 | [diff] [blame] | 1087 | EXPORT_SYMBOL(omap_mcbsp_pollwrite); |
Tony Lindgren | bb13b5f | 2005-07-10 19:58:18 +0100 | [diff] [blame] | 1088 | |
Eduardo Valentin | fb78d80 | 2008-07-03 12:24:39 +0300 | [diff] [blame] | 1089 | int omap_mcbsp_pollread(unsigned int id, u16 *buf) |
Tony Lindgren | bb13b5f | 2005-07-10 19:58:18 +0100 | [diff] [blame] | 1090 | { |
Chandra Shekhar | b4b58f5 | 2008-10-08 10:01:39 +0300 | [diff] [blame] | 1091 | struct omap_mcbsp *mcbsp; |
Eduardo Valentin | bc5d0c8 | 2008-07-03 12:24:39 +0300 | [diff] [blame] | 1092 | |
| 1093 | if (!omap_mcbsp_check_valid_id(id)) { |
| 1094 | printk(KERN_ERR "%s: Invalid id (%d)\n", __func__, id + 1); |
| 1095 | return -ENODEV; |
| 1096 | } |
Chandra Shekhar | b4b58f5 | 2008-10-08 10:01:39 +0300 | [diff] [blame] | 1097 | mcbsp = id_to_mcbsp_ptr(id); |
Eduardo Valentin | bc5d0c8 | 2008-07-03 12:24:39 +0300 | [diff] [blame] | 1098 | |
Tony Lindgren | bb13b5f | 2005-07-10 19:58:18 +0100 | [diff] [blame] | 1099 | /* if frame sync error - clear the error */ |
Janusz Krzysztofik | 8ea3200 | 2010-02-15 10:03:32 -0800 | [diff] [blame] | 1100 | if (MCBSP_READ(mcbsp, SPCR1) & RSYNC_ERR) { |
Tony Lindgren | bb13b5f | 2005-07-10 19:58:18 +0100 | [diff] [blame] | 1101 | /* clear error */ |
Janusz Krzysztofik | 0841cb8 | 2010-02-23 15:50:38 +0000 | [diff] [blame] | 1102 | MCBSP_WRITE(mcbsp, SPCR1, MCBSP_READ_CACHE(mcbsp, SPCR1)); |
Tony Lindgren | bb13b5f | 2005-07-10 19:58:18 +0100 | [diff] [blame] | 1103 | /* resend */ |
| 1104 | return -1; |
| 1105 | } else { |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 1106 | /* wait for receive confirmation */ |
Tony Lindgren | bb13b5f | 2005-07-10 19:58:18 +0100 | [diff] [blame] | 1107 | int attemps = 0; |
Janusz Krzysztofik | 8ea3200 | 2010-02-15 10:03:32 -0800 | [diff] [blame] | 1108 | while (!(MCBSP_READ(mcbsp, SPCR1) & RRDY)) { |
Tony Lindgren | bb13b5f | 2005-07-10 19:58:18 +0100 | [diff] [blame] | 1109 | if (attemps++ > 1000) { |
Janusz Krzysztofik | 8ea3200 | 2010-02-15 10:03:32 -0800 | [diff] [blame] | 1110 | MCBSP_WRITE(mcbsp, SPCR1, |
Janusz Krzysztofik | 96fbd74 | 2010-02-15 10:03:33 -0800 | [diff] [blame] | 1111 | MCBSP_READ_CACHE(mcbsp, SPCR1) & |
| 1112 | (~RRST)); |
Tony Lindgren | bb13b5f | 2005-07-10 19:58:18 +0100 | [diff] [blame] | 1113 | udelay(10); |
Janusz Krzysztofik | 8ea3200 | 2010-02-15 10:03:32 -0800 | [diff] [blame] | 1114 | MCBSP_WRITE(mcbsp, SPCR1, |
Janusz Krzysztofik | 96fbd74 | 2010-02-15 10:03:33 -0800 | [diff] [blame] | 1115 | MCBSP_READ_CACHE(mcbsp, SPCR1) | |
| 1116 | (RRST)); |
Tony Lindgren | bb13b5f | 2005-07-10 19:58:18 +0100 | [diff] [blame] | 1117 | udelay(10); |
Chandra Shekhar | b4b58f5 | 2008-10-08 10:01:39 +0300 | [diff] [blame] | 1118 | dev_err(mcbsp->dev, "Could not read from" |
| 1119 | " McBSP%d Register\n", mcbsp->id); |
Tony Lindgren | bb13b5f | 2005-07-10 19:58:18 +0100 | [diff] [blame] | 1120 | return -2; |
| 1121 | } |
| 1122 | } |
| 1123 | } |
Janusz Krzysztofik | 8ea3200 | 2010-02-15 10:03:32 -0800 | [diff] [blame] | 1124 | *buf = MCBSP_READ(mcbsp, DRR1); |
Eduardo Valentin | fb78d80 | 2008-07-03 12:24:39 +0300 | [diff] [blame] | 1125 | |
Tony Lindgren | bb13b5f | 2005-07-10 19:58:18 +0100 | [diff] [blame] | 1126 | return 0; |
| 1127 | } |
Eduardo Valentin | fb78d80 | 2008-07-03 12:24:39 +0300 | [diff] [blame] | 1128 | EXPORT_SYMBOL(omap_mcbsp_pollread); |
Tony Lindgren | bb13b5f | 2005-07-10 19:58:18 +0100 | [diff] [blame] | 1129 | |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 1130 | /* |
| 1131 | * IRQ based word transmission. |
| 1132 | */ |
| 1133 | void omap_mcbsp_xmit_word(unsigned int id, u32 word) |
| 1134 | { |
Chandra Shekhar | b4b58f5 | 2008-10-08 10:01:39 +0300 | [diff] [blame] | 1135 | struct omap_mcbsp *mcbsp; |
Eduardo Valentin | bc5d0c8 | 2008-07-03 12:24:39 +0300 | [diff] [blame] | 1136 | omap_mcbsp_word_length word_length; |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 1137 | |
Eduardo Valentin | bc5d0c8 | 2008-07-03 12:24:39 +0300 | [diff] [blame] | 1138 | if (!omap_mcbsp_check_valid_id(id)) { |
| 1139 | printk(KERN_ERR "%s: Invalid id (%d)\n", __func__, id + 1); |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 1140 | return; |
Eduardo Valentin | bc5d0c8 | 2008-07-03 12:24:39 +0300 | [diff] [blame] | 1141 | } |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 1142 | |
Chandra Shekhar | b4b58f5 | 2008-10-08 10:01:39 +0300 | [diff] [blame] | 1143 | mcbsp = id_to_mcbsp_ptr(id); |
Chandra Shekhar | b4b58f5 | 2008-10-08 10:01:39 +0300 | [diff] [blame] | 1144 | word_length = mcbsp->tx_word_length; |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 1145 | |
Chandra Shekhar | b4b58f5 | 2008-10-08 10:01:39 +0300 | [diff] [blame] | 1146 | wait_for_completion(&mcbsp->tx_irq_completion); |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 1147 | |
| 1148 | if (word_length > OMAP_MCBSP_WORD_16) |
Janusz Krzysztofik | 8ea3200 | 2010-02-15 10:03:32 -0800 | [diff] [blame] | 1149 | MCBSP_WRITE(mcbsp, DXR2, word >> 16); |
| 1150 | MCBSP_WRITE(mcbsp, DXR1, word & 0xffff); |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 1151 | } |
Eduardo Valentin | fb78d80 | 2008-07-03 12:24:39 +0300 | [diff] [blame] | 1152 | EXPORT_SYMBOL(omap_mcbsp_xmit_word); |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 1153 | |
| 1154 | u32 omap_mcbsp_recv_word(unsigned int id) |
| 1155 | { |
Chandra Shekhar | b4b58f5 | 2008-10-08 10:01:39 +0300 | [diff] [blame] | 1156 | struct omap_mcbsp *mcbsp; |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 1157 | u16 word_lsb, word_msb = 0; |
Eduardo Valentin | bc5d0c8 | 2008-07-03 12:24:39 +0300 | [diff] [blame] | 1158 | omap_mcbsp_word_length word_length; |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 1159 | |
Eduardo Valentin | bc5d0c8 | 2008-07-03 12:24:39 +0300 | [diff] [blame] | 1160 | if (!omap_mcbsp_check_valid_id(id)) { |
| 1161 | printk(KERN_ERR "%s: Invalid id (%d)\n", __func__, id + 1); |
| 1162 | return -ENODEV; |
| 1163 | } |
Chandra Shekhar | b4b58f5 | 2008-10-08 10:01:39 +0300 | [diff] [blame] | 1164 | mcbsp = id_to_mcbsp_ptr(id); |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 1165 | |
Chandra Shekhar | b4b58f5 | 2008-10-08 10:01:39 +0300 | [diff] [blame] | 1166 | word_length = mcbsp->rx_word_length; |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 1167 | |
Chandra Shekhar | b4b58f5 | 2008-10-08 10:01:39 +0300 | [diff] [blame] | 1168 | wait_for_completion(&mcbsp->rx_irq_completion); |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 1169 | |
| 1170 | if (word_length > OMAP_MCBSP_WORD_16) |
Janusz Krzysztofik | 8ea3200 | 2010-02-15 10:03:32 -0800 | [diff] [blame] | 1171 | word_msb = MCBSP_READ(mcbsp, DRR2); |
| 1172 | word_lsb = MCBSP_READ(mcbsp, DRR1); |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 1173 | |
| 1174 | return (word_lsb | (word_msb << 16)); |
| 1175 | } |
Eduardo Valentin | fb78d80 | 2008-07-03 12:24:39 +0300 | [diff] [blame] | 1176 | EXPORT_SYMBOL(omap_mcbsp_recv_word); |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 1177 | |
Tony Lindgren | 120db2c | 2006-04-02 17:46:27 +0100 | [diff] [blame] | 1178 | int omap_mcbsp_spi_master_xmit_word_poll(unsigned int id, u32 word) |
| 1179 | { |
Chandra Shekhar | b4b58f5 | 2008-10-08 10:01:39 +0300 | [diff] [blame] | 1180 | struct omap_mcbsp *mcbsp; |
Eduardo Valentin | bc5d0c8 | 2008-07-03 12:24:39 +0300 | [diff] [blame] | 1181 | omap_mcbsp_word_length tx_word_length; |
| 1182 | omap_mcbsp_word_length rx_word_length; |
Tony Lindgren | 120db2c | 2006-04-02 17:46:27 +0100 | [diff] [blame] | 1183 | u16 spcr2, spcr1, attempts = 0, word_lsb, word_msb = 0; |
| 1184 | |
Eduardo Valentin | bc5d0c8 | 2008-07-03 12:24:39 +0300 | [diff] [blame] | 1185 | if (!omap_mcbsp_check_valid_id(id)) { |
| 1186 | printk(KERN_ERR "%s: Invalid id (%d)\n", __func__, id + 1); |
| 1187 | return -ENODEV; |
| 1188 | } |
Chandra Shekhar | b4b58f5 | 2008-10-08 10:01:39 +0300 | [diff] [blame] | 1189 | mcbsp = id_to_mcbsp_ptr(id); |
Chandra Shekhar | b4b58f5 | 2008-10-08 10:01:39 +0300 | [diff] [blame] | 1190 | tx_word_length = mcbsp->tx_word_length; |
| 1191 | rx_word_length = mcbsp->rx_word_length; |
Eduardo Valentin | bc5d0c8 | 2008-07-03 12:24:39 +0300 | [diff] [blame] | 1192 | |
Tony Lindgren | 120db2c | 2006-04-02 17:46:27 +0100 | [diff] [blame] | 1193 | if (tx_word_length != rx_word_length) |
| 1194 | return -EINVAL; |
| 1195 | |
| 1196 | /* First we wait for the transmitter to be ready */ |
Janusz Krzysztofik | 8ea3200 | 2010-02-15 10:03:32 -0800 | [diff] [blame] | 1197 | spcr2 = MCBSP_READ(mcbsp, SPCR2); |
Tony Lindgren | 120db2c | 2006-04-02 17:46:27 +0100 | [diff] [blame] | 1198 | while (!(spcr2 & XRDY)) { |
Janusz Krzysztofik | 8ea3200 | 2010-02-15 10:03:32 -0800 | [diff] [blame] | 1199 | spcr2 = MCBSP_READ(mcbsp, SPCR2); |
Tony Lindgren | 120db2c | 2006-04-02 17:46:27 +0100 | [diff] [blame] | 1200 | if (attempts++ > 1000) { |
| 1201 | /* We must reset the transmitter */ |
Janusz Krzysztofik | 96fbd74 | 2010-02-15 10:03:33 -0800 | [diff] [blame] | 1202 | MCBSP_WRITE(mcbsp, SPCR2, |
| 1203 | MCBSP_READ_CACHE(mcbsp, SPCR2) & (~XRST)); |
Tony Lindgren | 120db2c | 2006-04-02 17:46:27 +0100 | [diff] [blame] | 1204 | udelay(10); |
Janusz Krzysztofik | 96fbd74 | 2010-02-15 10:03:33 -0800 | [diff] [blame] | 1205 | MCBSP_WRITE(mcbsp, SPCR2, |
| 1206 | MCBSP_READ_CACHE(mcbsp, SPCR2) | XRST); |
Tony Lindgren | 120db2c | 2006-04-02 17:46:27 +0100 | [diff] [blame] | 1207 | udelay(10); |
Chandra Shekhar | b4b58f5 | 2008-10-08 10:01:39 +0300 | [diff] [blame] | 1208 | dev_err(mcbsp->dev, "McBSP%d transmitter not " |
| 1209 | "ready\n", mcbsp->id); |
Tony Lindgren | 120db2c | 2006-04-02 17:46:27 +0100 | [diff] [blame] | 1210 | return -EAGAIN; |
| 1211 | } |
| 1212 | } |
| 1213 | |
| 1214 | /* Now we can push the data */ |
| 1215 | if (tx_word_length > OMAP_MCBSP_WORD_16) |
Janusz Krzysztofik | 8ea3200 | 2010-02-15 10:03:32 -0800 | [diff] [blame] | 1216 | MCBSP_WRITE(mcbsp, DXR2, word >> 16); |
| 1217 | MCBSP_WRITE(mcbsp, DXR1, word & 0xffff); |
Tony Lindgren | 120db2c | 2006-04-02 17:46:27 +0100 | [diff] [blame] | 1218 | |
| 1219 | /* We wait for the receiver to be ready */ |
Janusz Krzysztofik | 8ea3200 | 2010-02-15 10:03:32 -0800 | [diff] [blame] | 1220 | spcr1 = MCBSP_READ(mcbsp, SPCR1); |
Tony Lindgren | 120db2c | 2006-04-02 17:46:27 +0100 | [diff] [blame] | 1221 | while (!(spcr1 & RRDY)) { |
Janusz Krzysztofik | 8ea3200 | 2010-02-15 10:03:32 -0800 | [diff] [blame] | 1222 | spcr1 = MCBSP_READ(mcbsp, SPCR1); |
Tony Lindgren | 120db2c | 2006-04-02 17:46:27 +0100 | [diff] [blame] | 1223 | if (attempts++ > 1000) { |
| 1224 | /* We must reset the receiver */ |
Janusz Krzysztofik | 96fbd74 | 2010-02-15 10:03:33 -0800 | [diff] [blame] | 1225 | MCBSP_WRITE(mcbsp, SPCR1, |
| 1226 | MCBSP_READ_CACHE(mcbsp, SPCR1) & (~RRST)); |
Tony Lindgren | 120db2c | 2006-04-02 17:46:27 +0100 | [diff] [blame] | 1227 | udelay(10); |
Janusz Krzysztofik | 96fbd74 | 2010-02-15 10:03:33 -0800 | [diff] [blame] | 1228 | MCBSP_WRITE(mcbsp, SPCR1, |
| 1229 | MCBSP_READ_CACHE(mcbsp, SPCR1) | RRST); |
Tony Lindgren | 120db2c | 2006-04-02 17:46:27 +0100 | [diff] [blame] | 1230 | udelay(10); |
Chandra Shekhar | b4b58f5 | 2008-10-08 10:01:39 +0300 | [diff] [blame] | 1231 | dev_err(mcbsp->dev, "McBSP%d receiver not " |
| 1232 | "ready\n", mcbsp->id); |
Tony Lindgren | 120db2c | 2006-04-02 17:46:27 +0100 | [diff] [blame] | 1233 | return -EAGAIN; |
| 1234 | } |
| 1235 | } |
| 1236 | |
| 1237 | /* Receiver is ready, let's read the dummy data */ |
| 1238 | if (rx_word_length > OMAP_MCBSP_WORD_16) |
Janusz Krzysztofik | 8ea3200 | 2010-02-15 10:03:32 -0800 | [diff] [blame] | 1239 | word_msb = MCBSP_READ(mcbsp, DRR2); |
| 1240 | word_lsb = MCBSP_READ(mcbsp, DRR1); |
Tony Lindgren | 120db2c | 2006-04-02 17:46:27 +0100 | [diff] [blame] | 1241 | |
| 1242 | return 0; |
| 1243 | } |
Eduardo Valentin | fb78d80 | 2008-07-03 12:24:39 +0300 | [diff] [blame] | 1244 | EXPORT_SYMBOL(omap_mcbsp_spi_master_xmit_word_poll); |
Tony Lindgren | 120db2c | 2006-04-02 17:46:27 +0100 | [diff] [blame] | 1245 | |
Eduardo Valentin | fb78d80 | 2008-07-03 12:24:39 +0300 | [diff] [blame] | 1246 | int omap_mcbsp_spi_master_recv_word_poll(unsigned int id, u32 *word) |
Tony Lindgren | 120db2c | 2006-04-02 17:46:27 +0100 | [diff] [blame] | 1247 | { |
Chandra Shekhar | b4b58f5 | 2008-10-08 10:01:39 +0300 | [diff] [blame] | 1248 | struct omap_mcbsp *mcbsp; |
Russell King | d592dd1 | 2008-09-04 14:25:42 +0100 | [diff] [blame] | 1249 | u32 clock_word = 0; |
Eduardo Valentin | bc5d0c8 | 2008-07-03 12:24:39 +0300 | [diff] [blame] | 1250 | omap_mcbsp_word_length tx_word_length; |
| 1251 | omap_mcbsp_word_length rx_word_length; |
Tony Lindgren | 120db2c | 2006-04-02 17:46:27 +0100 | [diff] [blame] | 1252 | u16 spcr2, spcr1, attempts = 0, word_lsb, word_msb = 0; |
| 1253 | |
Eduardo Valentin | bc5d0c8 | 2008-07-03 12:24:39 +0300 | [diff] [blame] | 1254 | if (!omap_mcbsp_check_valid_id(id)) { |
| 1255 | printk(KERN_ERR "%s: Invalid id (%d)\n", __func__, id + 1); |
| 1256 | return -ENODEV; |
| 1257 | } |
| 1258 | |
Chandra Shekhar | b4b58f5 | 2008-10-08 10:01:39 +0300 | [diff] [blame] | 1259 | mcbsp = id_to_mcbsp_ptr(id); |
Chandra Shekhar | b4b58f5 | 2008-10-08 10:01:39 +0300 | [diff] [blame] | 1260 | |
| 1261 | tx_word_length = mcbsp->tx_word_length; |
| 1262 | rx_word_length = mcbsp->rx_word_length; |
Eduardo Valentin | bc5d0c8 | 2008-07-03 12:24:39 +0300 | [diff] [blame] | 1263 | |
Tony Lindgren | 120db2c | 2006-04-02 17:46:27 +0100 | [diff] [blame] | 1264 | if (tx_word_length != rx_word_length) |
| 1265 | return -EINVAL; |
| 1266 | |
| 1267 | /* First we wait for the transmitter to be ready */ |
Janusz Krzysztofik | 8ea3200 | 2010-02-15 10:03:32 -0800 | [diff] [blame] | 1268 | spcr2 = MCBSP_READ(mcbsp, SPCR2); |
Tony Lindgren | 120db2c | 2006-04-02 17:46:27 +0100 | [diff] [blame] | 1269 | while (!(spcr2 & XRDY)) { |
Janusz Krzysztofik | 8ea3200 | 2010-02-15 10:03:32 -0800 | [diff] [blame] | 1270 | spcr2 = MCBSP_READ(mcbsp, SPCR2); |
Tony Lindgren | 120db2c | 2006-04-02 17:46:27 +0100 | [diff] [blame] | 1271 | if (attempts++ > 1000) { |
| 1272 | /* We must reset the transmitter */ |
Janusz Krzysztofik | 96fbd74 | 2010-02-15 10:03:33 -0800 | [diff] [blame] | 1273 | MCBSP_WRITE(mcbsp, SPCR2, |
| 1274 | MCBSP_READ_CACHE(mcbsp, SPCR2) & (~XRST)); |
Tony Lindgren | 120db2c | 2006-04-02 17:46:27 +0100 | [diff] [blame] | 1275 | udelay(10); |
Janusz Krzysztofik | 96fbd74 | 2010-02-15 10:03:33 -0800 | [diff] [blame] | 1276 | MCBSP_WRITE(mcbsp, SPCR2, |
| 1277 | MCBSP_READ_CACHE(mcbsp, SPCR2) | XRST); |
Tony Lindgren | 120db2c | 2006-04-02 17:46:27 +0100 | [diff] [blame] | 1278 | udelay(10); |
Chandra Shekhar | b4b58f5 | 2008-10-08 10:01:39 +0300 | [diff] [blame] | 1279 | dev_err(mcbsp->dev, "McBSP%d transmitter not " |
| 1280 | "ready\n", mcbsp->id); |
Tony Lindgren | 120db2c | 2006-04-02 17:46:27 +0100 | [diff] [blame] | 1281 | return -EAGAIN; |
| 1282 | } |
| 1283 | } |
| 1284 | |
| 1285 | /* We first need to enable the bus clock */ |
| 1286 | if (tx_word_length > OMAP_MCBSP_WORD_16) |
Janusz Krzysztofik | 8ea3200 | 2010-02-15 10:03:32 -0800 | [diff] [blame] | 1287 | MCBSP_WRITE(mcbsp, DXR2, clock_word >> 16); |
| 1288 | MCBSP_WRITE(mcbsp, DXR1, clock_word & 0xffff); |
Tony Lindgren | 120db2c | 2006-04-02 17:46:27 +0100 | [diff] [blame] | 1289 | |
| 1290 | /* We wait for the receiver to be ready */ |
Janusz Krzysztofik | 8ea3200 | 2010-02-15 10:03:32 -0800 | [diff] [blame] | 1291 | spcr1 = MCBSP_READ(mcbsp, SPCR1); |
Tony Lindgren | 120db2c | 2006-04-02 17:46:27 +0100 | [diff] [blame] | 1292 | while (!(spcr1 & RRDY)) { |
Janusz Krzysztofik | 8ea3200 | 2010-02-15 10:03:32 -0800 | [diff] [blame] | 1293 | spcr1 = MCBSP_READ(mcbsp, SPCR1); |
Tony Lindgren | 120db2c | 2006-04-02 17:46:27 +0100 | [diff] [blame] | 1294 | if (attempts++ > 1000) { |
| 1295 | /* We must reset the receiver */ |
Janusz Krzysztofik | 96fbd74 | 2010-02-15 10:03:33 -0800 | [diff] [blame] | 1296 | MCBSP_WRITE(mcbsp, SPCR1, |
| 1297 | MCBSP_READ_CACHE(mcbsp, SPCR1) & (~RRST)); |
Tony Lindgren | 120db2c | 2006-04-02 17:46:27 +0100 | [diff] [blame] | 1298 | udelay(10); |
Janusz Krzysztofik | 96fbd74 | 2010-02-15 10:03:33 -0800 | [diff] [blame] | 1299 | MCBSP_WRITE(mcbsp, SPCR1, |
| 1300 | MCBSP_READ_CACHE(mcbsp, SPCR1) | RRST); |
Tony Lindgren | 120db2c | 2006-04-02 17:46:27 +0100 | [diff] [blame] | 1301 | udelay(10); |
Chandra Shekhar | b4b58f5 | 2008-10-08 10:01:39 +0300 | [diff] [blame] | 1302 | dev_err(mcbsp->dev, "McBSP%d receiver not " |
| 1303 | "ready\n", mcbsp->id); |
Tony Lindgren | 120db2c | 2006-04-02 17:46:27 +0100 | [diff] [blame] | 1304 | return -EAGAIN; |
| 1305 | } |
| 1306 | } |
| 1307 | |
| 1308 | /* Receiver is ready, there is something for us */ |
| 1309 | if (rx_word_length > OMAP_MCBSP_WORD_16) |
Janusz Krzysztofik | 8ea3200 | 2010-02-15 10:03:32 -0800 | [diff] [blame] | 1310 | word_msb = MCBSP_READ(mcbsp, DRR2); |
| 1311 | word_lsb = MCBSP_READ(mcbsp, DRR1); |
Tony Lindgren | 120db2c | 2006-04-02 17:46:27 +0100 | [diff] [blame] | 1312 | |
| 1313 | word[0] = (word_lsb | (word_msb << 16)); |
| 1314 | |
| 1315 | return 0; |
| 1316 | } |
Eduardo Valentin | fb78d80 | 2008-07-03 12:24:39 +0300 | [diff] [blame] | 1317 | EXPORT_SYMBOL(omap_mcbsp_spi_master_recv_word_poll); |
Tony Lindgren | 120db2c | 2006-04-02 17:46:27 +0100 | [diff] [blame] | 1318 | |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 1319 | /* |
| 1320 | * Simple DMA based buffer rx/tx routines. |
| 1321 | * Nothing fancy, just a single buffer tx/rx through DMA. |
| 1322 | * The DMA resources are released once the transfer is done. |
| 1323 | * For anything fancier, you should use your own customized DMA |
| 1324 | * routines and callbacks. |
| 1325 | */ |
Eduardo Valentin | fb78d80 | 2008-07-03 12:24:39 +0300 | [diff] [blame] | 1326 | int omap_mcbsp_xmit_buffer(unsigned int id, dma_addr_t buffer, |
| 1327 | unsigned int length) |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 1328 | { |
Chandra Shekhar | b4b58f5 | 2008-10-08 10:01:39 +0300 | [diff] [blame] | 1329 | struct omap_mcbsp *mcbsp; |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 1330 | int dma_tx_ch; |
Tony Lindgren | 120db2c | 2006-04-02 17:46:27 +0100 | [diff] [blame] | 1331 | int src_port = 0; |
| 1332 | int dest_port = 0; |
| 1333 | int sync_dev = 0; |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 1334 | |
Eduardo Valentin | bc5d0c8 | 2008-07-03 12:24:39 +0300 | [diff] [blame] | 1335 | if (!omap_mcbsp_check_valid_id(id)) { |
| 1336 | printk(KERN_ERR "%s: Invalid id (%d)\n", __func__, id + 1); |
| 1337 | return -ENODEV; |
| 1338 | } |
Chandra Shekhar | b4b58f5 | 2008-10-08 10:01:39 +0300 | [diff] [blame] | 1339 | mcbsp = id_to_mcbsp_ptr(id); |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 1340 | |
Chandra Shekhar | b4b58f5 | 2008-10-08 10:01:39 +0300 | [diff] [blame] | 1341 | if (omap_request_dma(mcbsp->dma_tx_sync, "McBSP TX", |
Eduardo Valentin | fb78d80 | 2008-07-03 12:24:39 +0300 | [diff] [blame] | 1342 | omap_mcbsp_tx_dma_callback, |
Chandra Shekhar | b4b58f5 | 2008-10-08 10:01:39 +0300 | [diff] [blame] | 1343 | mcbsp, |
Eduardo Valentin | fb78d80 | 2008-07-03 12:24:39 +0300 | [diff] [blame] | 1344 | &dma_tx_ch)) { |
Chandra Shekhar | b4b58f5 | 2008-10-08 10:01:39 +0300 | [diff] [blame] | 1345 | dev_err(mcbsp->dev, " Unable to request DMA channel for " |
Eduardo Valentin | bc5d0c8 | 2008-07-03 12:24:39 +0300 | [diff] [blame] | 1346 | "McBSP%d TX. Trying IRQ based TX\n", |
Chandra Shekhar | b4b58f5 | 2008-10-08 10:01:39 +0300 | [diff] [blame] | 1347 | mcbsp->id); |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 1348 | return -EAGAIN; |
| 1349 | } |
Chandra Shekhar | b4b58f5 | 2008-10-08 10:01:39 +0300 | [diff] [blame] | 1350 | mcbsp->dma_tx_lch = dma_tx_ch; |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 1351 | |
Chandra Shekhar | b4b58f5 | 2008-10-08 10:01:39 +0300 | [diff] [blame] | 1352 | dev_err(mcbsp->dev, "McBSP%d TX DMA on channel %d\n", mcbsp->id, |
Eduardo Valentin | bc5d0c8 | 2008-07-03 12:24:39 +0300 | [diff] [blame] | 1353 | dma_tx_ch); |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 1354 | |
Chandra Shekhar | b4b58f5 | 2008-10-08 10:01:39 +0300 | [diff] [blame] | 1355 | init_completion(&mcbsp->tx_dma_completion); |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 1356 | |
Tony Lindgren | 120db2c | 2006-04-02 17:46:27 +0100 | [diff] [blame] | 1357 | if (cpu_class_is_omap1()) { |
| 1358 | src_port = OMAP_DMA_PORT_TIPB; |
| 1359 | dest_port = OMAP_DMA_PORT_EMIFF; |
| 1360 | } |
Eduardo Valentin | bc5d0c8 | 2008-07-03 12:24:39 +0300 | [diff] [blame] | 1361 | if (cpu_class_is_omap2()) |
Chandra Shekhar | b4b58f5 | 2008-10-08 10:01:39 +0300 | [diff] [blame] | 1362 | sync_dev = mcbsp->dma_tx_sync; |
Tony Lindgren | 120db2c | 2006-04-02 17:46:27 +0100 | [diff] [blame] | 1363 | |
Chandra Shekhar | b4b58f5 | 2008-10-08 10:01:39 +0300 | [diff] [blame] | 1364 | omap_set_dma_transfer_params(mcbsp->dma_tx_lch, |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 1365 | OMAP_DMA_DATA_TYPE_S16, |
| 1366 | length >> 1, 1, |
Tony Lindgren | 1a8bfa1 | 2005-11-10 14:26:50 +0000 | [diff] [blame] | 1367 | OMAP_DMA_SYNC_ELEMENT, |
Tony Lindgren | 120db2c | 2006-04-02 17:46:27 +0100 | [diff] [blame] | 1368 | sync_dev, 0); |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 1369 | |
Chandra Shekhar | b4b58f5 | 2008-10-08 10:01:39 +0300 | [diff] [blame] | 1370 | omap_set_dma_dest_params(mcbsp->dma_tx_lch, |
Tony Lindgren | 120db2c | 2006-04-02 17:46:27 +0100 | [diff] [blame] | 1371 | src_port, |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 1372 | OMAP_DMA_AMODE_CONSTANT, |
Chandra Shekhar | b4b58f5 | 2008-10-08 10:01:39 +0300 | [diff] [blame] | 1373 | mcbsp->phys_base + OMAP_MCBSP_REG_DXR1, |
Tony Lindgren | 1a8bfa1 | 2005-11-10 14:26:50 +0000 | [diff] [blame] | 1374 | 0, 0); |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 1375 | |
Chandra Shekhar | b4b58f5 | 2008-10-08 10:01:39 +0300 | [diff] [blame] | 1376 | omap_set_dma_src_params(mcbsp->dma_tx_lch, |
Tony Lindgren | 120db2c | 2006-04-02 17:46:27 +0100 | [diff] [blame] | 1377 | dest_port, |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 1378 | OMAP_DMA_AMODE_POST_INC, |
Tony Lindgren | 1a8bfa1 | 2005-11-10 14:26:50 +0000 | [diff] [blame] | 1379 | buffer, |
| 1380 | 0, 0); |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 1381 | |
Chandra Shekhar | b4b58f5 | 2008-10-08 10:01:39 +0300 | [diff] [blame] | 1382 | omap_start_dma(mcbsp->dma_tx_lch); |
| 1383 | wait_for_completion(&mcbsp->tx_dma_completion); |
Eduardo Valentin | fb78d80 | 2008-07-03 12:24:39 +0300 | [diff] [blame] | 1384 | |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 1385 | return 0; |
| 1386 | } |
Eduardo Valentin | fb78d80 | 2008-07-03 12:24:39 +0300 | [diff] [blame] | 1387 | EXPORT_SYMBOL(omap_mcbsp_xmit_buffer); |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 1388 | |
Eduardo Valentin | fb78d80 | 2008-07-03 12:24:39 +0300 | [diff] [blame] | 1389 | int omap_mcbsp_recv_buffer(unsigned int id, dma_addr_t buffer, |
| 1390 | unsigned int length) |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 1391 | { |
Chandra Shekhar | b4b58f5 | 2008-10-08 10:01:39 +0300 | [diff] [blame] | 1392 | struct omap_mcbsp *mcbsp; |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 1393 | int dma_rx_ch; |
Tony Lindgren | 120db2c | 2006-04-02 17:46:27 +0100 | [diff] [blame] | 1394 | int src_port = 0; |
| 1395 | int dest_port = 0; |
| 1396 | int sync_dev = 0; |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 1397 | |
Eduardo Valentin | bc5d0c8 | 2008-07-03 12:24:39 +0300 | [diff] [blame] | 1398 | if (!omap_mcbsp_check_valid_id(id)) { |
| 1399 | printk(KERN_ERR "%s: Invalid id (%d)\n", __func__, id + 1); |
| 1400 | return -ENODEV; |
| 1401 | } |
Chandra Shekhar | b4b58f5 | 2008-10-08 10:01:39 +0300 | [diff] [blame] | 1402 | mcbsp = id_to_mcbsp_ptr(id); |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 1403 | |
Chandra Shekhar | b4b58f5 | 2008-10-08 10:01:39 +0300 | [diff] [blame] | 1404 | if (omap_request_dma(mcbsp->dma_rx_sync, "McBSP RX", |
Eduardo Valentin | fb78d80 | 2008-07-03 12:24:39 +0300 | [diff] [blame] | 1405 | omap_mcbsp_rx_dma_callback, |
Chandra Shekhar | b4b58f5 | 2008-10-08 10:01:39 +0300 | [diff] [blame] | 1406 | mcbsp, |
Eduardo Valentin | fb78d80 | 2008-07-03 12:24:39 +0300 | [diff] [blame] | 1407 | &dma_rx_ch)) { |
Chandra Shekhar | b4b58f5 | 2008-10-08 10:01:39 +0300 | [diff] [blame] | 1408 | dev_err(mcbsp->dev, "Unable to request DMA channel for " |
Eduardo Valentin | bc5d0c8 | 2008-07-03 12:24:39 +0300 | [diff] [blame] | 1409 | "McBSP%d RX. Trying IRQ based RX\n", |
Chandra Shekhar | b4b58f5 | 2008-10-08 10:01:39 +0300 | [diff] [blame] | 1410 | mcbsp->id); |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 1411 | return -EAGAIN; |
| 1412 | } |
Chandra Shekhar | b4b58f5 | 2008-10-08 10:01:39 +0300 | [diff] [blame] | 1413 | mcbsp->dma_rx_lch = dma_rx_ch; |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 1414 | |
Chandra Shekhar | b4b58f5 | 2008-10-08 10:01:39 +0300 | [diff] [blame] | 1415 | dev_err(mcbsp->dev, "McBSP%d RX DMA on channel %d\n", mcbsp->id, |
Eduardo Valentin | bc5d0c8 | 2008-07-03 12:24:39 +0300 | [diff] [blame] | 1416 | dma_rx_ch); |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 1417 | |
Chandra Shekhar | b4b58f5 | 2008-10-08 10:01:39 +0300 | [diff] [blame] | 1418 | init_completion(&mcbsp->rx_dma_completion); |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 1419 | |
Tony Lindgren | 120db2c | 2006-04-02 17:46:27 +0100 | [diff] [blame] | 1420 | if (cpu_class_is_omap1()) { |
| 1421 | src_port = OMAP_DMA_PORT_TIPB; |
| 1422 | dest_port = OMAP_DMA_PORT_EMIFF; |
| 1423 | } |
Eduardo Valentin | bc5d0c8 | 2008-07-03 12:24:39 +0300 | [diff] [blame] | 1424 | if (cpu_class_is_omap2()) |
Chandra Shekhar | b4b58f5 | 2008-10-08 10:01:39 +0300 | [diff] [blame] | 1425 | sync_dev = mcbsp->dma_rx_sync; |
Tony Lindgren | 120db2c | 2006-04-02 17:46:27 +0100 | [diff] [blame] | 1426 | |
Chandra Shekhar | b4b58f5 | 2008-10-08 10:01:39 +0300 | [diff] [blame] | 1427 | omap_set_dma_transfer_params(mcbsp->dma_rx_lch, |
Eduardo Valentin | fb78d80 | 2008-07-03 12:24:39 +0300 | [diff] [blame] | 1428 | OMAP_DMA_DATA_TYPE_S16, |
| 1429 | length >> 1, 1, |
| 1430 | OMAP_DMA_SYNC_ELEMENT, |
| 1431 | sync_dev, 0); |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 1432 | |
Chandra Shekhar | b4b58f5 | 2008-10-08 10:01:39 +0300 | [diff] [blame] | 1433 | omap_set_dma_src_params(mcbsp->dma_rx_lch, |
Tony Lindgren | 120db2c | 2006-04-02 17:46:27 +0100 | [diff] [blame] | 1434 | src_port, |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 1435 | OMAP_DMA_AMODE_CONSTANT, |
Chandra Shekhar | b4b58f5 | 2008-10-08 10:01:39 +0300 | [diff] [blame] | 1436 | mcbsp->phys_base + OMAP_MCBSP_REG_DRR1, |
Tony Lindgren | 1a8bfa1 | 2005-11-10 14:26:50 +0000 | [diff] [blame] | 1437 | 0, 0); |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 1438 | |
Chandra Shekhar | b4b58f5 | 2008-10-08 10:01:39 +0300 | [diff] [blame] | 1439 | omap_set_dma_dest_params(mcbsp->dma_rx_lch, |
Eduardo Valentin | fb78d80 | 2008-07-03 12:24:39 +0300 | [diff] [blame] | 1440 | dest_port, |
| 1441 | OMAP_DMA_AMODE_POST_INC, |
| 1442 | buffer, |
| 1443 | 0, 0); |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 1444 | |
Chandra Shekhar | b4b58f5 | 2008-10-08 10:01:39 +0300 | [diff] [blame] | 1445 | omap_start_dma(mcbsp->dma_rx_lch); |
| 1446 | wait_for_completion(&mcbsp->rx_dma_completion); |
Eduardo Valentin | fb78d80 | 2008-07-03 12:24:39 +0300 | [diff] [blame] | 1447 | |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 1448 | return 0; |
| 1449 | } |
Eduardo Valentin | fb78d80 | 2008-07-03 12:24:39 +0300 | [diff] [blame] | 1450 | EXPORT_SYMBOL(omap_mcbsp_recv_buffer); |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 1451 | |
| 1452 | /* |
| 1453 | * SPI wrapper. |
| 1454 | * Since SPI setup is much simpler than the generic McBSP one, |
| 1455 | * this wrapper just need an omap_mcbsp_spi_cfg structure as an input. |
| 1456 | * Once this is done, you can call omap_mcbsp_start(). |
| 1457 | */ |
Eduardo Valentin | fb78d80 | 2008-07-03 12:24:39 +0300 | [diff] [blame] | 1458 | void omap_mcbsp_set_spi_mode(unsigned int id, |
| 1459 | const struct omap_mcbsp_spi_cfg *spi_cfg) |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 1460 | { |
Chandra Shekhar | b4b58f5 | 2008-10-08 10:01:39 +0300 | [diff] [blame] | 1461 | struct omap_mcbsp *mcbsp; |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 1462 | struct omap_mcbsp_reg_cfg mcbsp_cfg; |
| 1463 | |
Eduardo Valentin | bc5d0c8 | 2008-07-03 12:24:39 +0300 | [diff] [blame] | 1464 | if (!omap_mcbsp_check_valid_id(id)) { |
| 1465 | printk(KERN_ERR "%s: Invalid id (%d)\n", __func__, id + 1); |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 1466 | return; |
Eduardo Valentin | bc5d0c8 | 2008-07-03 12:24:39 +0300 | [diff] [blame] | 1467 | } |
Chandra Shekhar | b4b58f5 | 2008-10-08 10:01:39 +0300 | [diff] [blame] | 1468 | mcbsp = id_to_mcbsp_ptr(id); |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 1469 | |
| 1470 | memset(&mcbsp_cfg, 0, sizeof(struct omap_mcbsp_reg_cfg)); |
| 1471 | |
| 1472 | /* SPI has only one frame */ |
| 1473 | mcbsp_cfg.rcr1 |= (RWDLEN1(spi_cfg->word_length) | RFRLEN1(0)); |
| 1474 | mcbsp_cfg.xcr1 |= (XWDLEN1(spi_cfg->word_length) | XFRLEN1(0)); |
| 1475 | |
Eduardo Valentin | fb78d80 | 2008-07-03 12:24:39 +0300 | [diff] [blame] | 1476 | /* Clock stop mode */ |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 1477 | if (spi_cfg->clk_stp_mode == OMAP_MCBSP_CLK_STP_MODE_NO_DELAY) |
| 1478 | mcbsp_cfg.spcr1 |= (1 << 12); |
| 1479 | else |
| 1480 | mcbsp_cfg.spcr1 |= (3 << 11); |
| 1481 | |
| 1482 | /* Set clock parities */ |
| 1483 | if (spi_cfg->rx_clock_polarity == OMAP_MCBSP_CLK_RISING) |
| 1484 | mcbsp_cfg.pcr0 |= CLKRP; |
| 1485 | else |
| 1486 | mcbsp_cfg.pcr0 &= ~CLKRP; |
| 1487 | |
| 1488 | if (spi_cfg->tx_clock_polarity == OMAP_MCBSP_CLK_RISING) |
| 1489 | mcbsp_cfg.pcr0 &= ~CLKXP; |
| 1490 | else |
| 1491 | mcbsp_cfg.pcr0 |= CLKXP; |
| 1492 | |
| 1493 | /* Set SCLKME to 0 and CLKSM to 1 */ |
| 1494 | mcbsp_cfg.pcr0 &= ~SCLKME; |
| 1495 | mcbsp_cfg.srgr2 |= CLKSM; |
| 1496 | |
| 1497 | /* Set FSXP */ |
| 1498 | if (spi_cfg->fsx_polarity == OMAP_MCBSP_FS_ACTIVE_HIGH) |
| 1499 | mcbsp_cfg.pcr0 &= ~FSXP; |
| 1500 | else |
| 1501 | mcbsp_cfg.pcr0 |= FSXP; |
| 1502 | |
| 1503 | if (spi_cfg->spi_mode == OMAP_MCBSP_SPI_MASTER) { |
| 1504 | mcbsp_cfg.pcr0 |= CLKXM; |
Eduardo Valentin | fb78d80 | 2008-07-03 12:24:39 +0300 | [diff] [blame] | 1505 | mcbsp_cfg.srgr1 |= CLKGDV(spi_cfg->clk_div - 1); |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 1506 | mcbsp_cfg.pcr0 |= FSXM; |
| 1507 | mcbsp_cfg.srgr2 &= ~FSGM; |
| 1508 | mcbsp_cfg.xcr2 |= XDATDLY(1); |
| 1509 | mcbsp_cfg.rcr2 |= RDATDLY(1); |
Eduardo Valentin | fb78d80 | 2008-07-03 12:24:39 +0300 | [diff] [blame] | 1510 | } else { |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 1511 | mcbsp_cfg.pcr0 &= ~CLKXM; |
| 1512 | mcbsp_cfg.srgr1 |= CLKGDV(1); |
| 1513 | mcbsp_cfg.pcr0 &= ~FSXM; |
| 1514 | mcbsp_cfg.xcr2 &= ~XDATDLY(3); |
| 1515 | mcbsp_cfg.rcr2 &= ~RDATDLY(3); |
| 1516 | } |
| 1517 | |
| 1518 | mcbsp_cfg.xcr2 &= ~XPHASE; |
| 1519 | mcbsp_cfg.rcr2 &= ~RPHASE; |
| 1520 | |
| 1521 | omap_mcbsp_config(id, &mcbsp_cfg); |
| 1522 | } |
Eduardo Valentin | fb78d80 | 2008-07-03 12:24:39 +0300 | [diff] [blame] | 1523 | EXPORT_SYMBOL(omap_mcbsp_set_spi_mode); |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 1524 | |
Tony Lindgren | a8eb7ca | 2010-02-12 12:26:48 -0800 | [diff] [blame] | 1525 | #ifdef CONFIG_ARCH_OMAP3 |
Eduardo Valentin | a1a56f5 | 2009-08-20 16:18:11 +0300 | [diff] [blame] | 1526 | #define max_thres(m) (mcbsp->pdata->buffer_size) |
| 1527 | #define valid_threshold(m, val) ((val) <= max_thres(m)) |
| 1528 | #define THRESHOLD_PROP_BUILDER(prop) \ |
| 1529 | static ssize_t prop##_show(struct device *dev, \ |
| 1530 | struct device_attribute *attr, char *buf) \ |
| 1531 | { \ |
| 1532 | struct omap_mcbsp *mcbsp = dev_get_drvdata(dev); \ |
| 1533 | \ |
| 1534 | return sprintf(buf, "%u\n", mcbsp->prop); \ |
| 1535 | } \ |
| 1536 | \ |
| 1537 | static ssize_t prop##_store(struct device *dev, \ |
| 1538 | struct device_attribute *attr, \ |
| 1539 | const char *buf, size_t size) \ |
| 1540 | { \ |
| 1541 | struct omap_mcbsp *mcbsp = dev_get_drvdata(dev); \ |
| 1542 | unsigned long val; \ |
| 1543 | int status; \ |
| 1544 | \ |
| 1545 | status = strict_strtoul(buf, 0, &val); \ |
| 1546 | if (status) \ |
| 1547 | return status; \ |
| 1548 | \ |
| 1549 | if (!valid_threshold(mcbsp, val)) \ |
| 1550 | return -EDOM; \ |
| 1551 | \ |
| 1552 | mcbsp->prop = val; \ |
| 1553 | return size; \ |
| 1554 | } \ |
| 1555 | \ |
| 1556 | static DEVICE_ATTR(prop, 0644, prop##_show, prop##_store); |
| 1557 | |
| 1558 | THRESHOLD_PROP_BUILDER(max_tx_thres); |
| 1559 | THRESHOLD_PROP_BUILDER(max_rx_thres); |
| 1560 | |
Jarkko Nikula | 9b30050 | 2009-08-24 17:45:50 +0300 | [diff] [blame] | 1561 | static const char *dma_op_modes[] = { |
| 1562 | "element", "threshold", "frame", |
| 1563 | }; |
| 1564 | |
Peter Ujfalusi | 98cb20e | 2009-08-20 16:18:14 +0300 | [diff] [blame] | 1565 | static ssize_t dma_op_mode_show(struct device *dev, |
| 1566 | struct device_attribute *attr, char *buf) |
| 1567 | { |
| 1568 | struct omap_mcbsp *mcbsp = dev_get_drvdata(dev); |
Jarkko Nikula | 9b30050 | 2009-08-24 17:45:50 +0300 | [diff] [blame] | 1569 | int dma_op_mode, i = 0; |
| 1570 | ssize_t len = 0; |
| 1571 | const char * const *s; |
Peter Ujfalusi | 98cb20e | 2009-08-20 16:18:14 +0300 | [diff] [blame] | 1572 | |
Peter Ujfalusi | 98cb20e | 2009-08-20 16:18:14 +0300 | [diff] [blame] | 1573 | dma_op_mode = mcbsp->dma_op_mode; |
Peter Ujfalusi | 98cb20e | 2009-08-20 16:18:14 +0300 | [diff] [blame] | 1574 | |
Jarkko Nikula | 9b30050 | 2009-08-24 17:45:50 +0300 | [diff] [blame] | 1575 | for (s = &dma_op_modes[i]; i < ARRAY_SIZE(dma_op_modes); s++, i++) { |
| 1576 | if (dma_op_mode == i) |
| 1577 | len += sprintf(buf + len, "[%s] ", *s); |
| 1578 | else |
| 1579 | len += sprintf(buf + len, "%s ", *s); |
| 1580 | } |
| 1581 | len += sprintf(buf + len, "\n"); |
| 1582 | |
| 1583 | return len; |
Peter Ujfalusi | 98cb20e | 2009-08-20 16:18:14 +0300 | [diff] [blame] | 1584 | } |
| 1585 | |
| 1586 | static ssize_t dma_op_mode_store(struct device *dev, |
| 1587 | struct device_attribute *attr, |
| 1588 | const char *buf, size_t size) |
| 1589 | { |
| 1590 | struct omap_mcbsp *mcbsp = dev_get_drvdata(dev); |
Jarkko Nikula | 9b30050 | 2009-08-24 17:45:50 +0300 | [diff] [blame] | 1591 | const char * const *s; |
| 1592 | int i = 0; |
Peter Ujfalusi | 98cb20e | 2009-08-20 16:18:14 +0300 | [diff] [blame] | 1593 | |
Jarkko Nikula | 9b30050 | 2009-08-24 17:45:50 +0300 | [diff] [blame] | 1594 | for (s = &dma_op_modes[i]; i < ARRAY_SIZE(dma_op_modes); s++, i++) |
| 1595 | if (sysfs_streq(buf, *s)) |
| 1596 | break; |
| 1597 | |
| 1598 | if (i == ARRAY_SIZE(dma_op_modes)) |
| 1599 | return -EINVAL; |
Peter Ujfalusi | 98cb20e | 2009-08-20 16:18:14 +0300 | [diff] [blame] | 1600 | |
| 1601 | spin_lock_irq(&mcbsp->lock); |
Peter Ujfalusi | 98cb20e | 2009-08-20 16:18:14 +0300 | [diff] [blame] | 1602 | if (!mcbsp->free) { |
| 1603 | size = -EBUSY; |
| 1604 | goto unlock; |
| 1605 | } |
Jarkko Nikula | 9b30050 | 2009-08-24 17:45:50 +0300 | [diff] [blame] | 1606 | mcbsp->dma_op_mode = i; |
Peter Ujfalusi | 98cb20e | 2009-08-20 16:18:14 +0300 | [diff] [blame] | 1607 | |
| 1608 | unlock: |
| 1609 | spin_unlock_irq(&mcbsp->lock); |
| 1610 | |
| 1611 | return size; |
| 1612 | } |
| 1613 | |
| 1614 | static DEVICE_ATTR(dma_op_mode, 0644, dma_op_mode_show, dma_op_mode_store); |
| 1615 | |
Eero Nurkkala | d912fa9 | 2010-02-22 12:21:11 +0000 | [diff] [blame] | 1616 | static ssize_t st_taps_show(struct device *dev, |
| 1617 | struct device_attribute *attr, char *buf) |
| 1618 | { |
| 1619 | struct omap_mcbsp *mcbsp = dev_get_drvdata(dev); |
| 1620 | struct omap_mcbsp_st_data *st_data = mcbsp->st_data; |
| 1621 | ssize_t status = 0; |
| 1622 | int i; |
| 1623 | |
| 1624 | spin_lock_irq(&mcbsp->lock); |
| 1625 | for (i = 0; i < st_data->nr_taps; i++) |
| 1626 | status += sprintf(&buf[status], (i ? ", %d" : "%d"), |
| 1627 | st_data->taps[i]); |
| 1628 | if (i) |
| 1629 | status += sprintf(&buf[status], "\n"); |
| 1630 | spin_unlock_irq(&mcbsp->lock); |
| 1631 | |
| 1632 | return status; |
| 1633 | } |
| 1634 | |
| 1635 | static ssize_t st_taps_store(struct device *dev, |
| 1636 | struct device_attribute *attr, |
| 1637 | const char *buf, size_t size) |
| 1638 | { |
| 1639 | struct omap_mcbsp *mcbsp = dev_get_drvdata(dev); |
| 1640 | struct omap_mcbsp_st_data *st_data = mcbsp->st_data; |
| 1641 | int val, tmp, status, i = 0; |
| 1642 | |
| 1643 | spin_lock_irq(&mcbsp->lock); |
| 1644 | memset(st_data->taps, 0, sizeof(st_data->taps)); |
| 1645 | st_data->nr_taps = 0; |
| 1646 | |
| 1647 | do { |
| 1648 | status = sscanf(buf, "%d%n", &val, &tmp); |
| 1649 | if (status < 0 || status == 0) { |
| 1650 | size = -EINVAL; |
| 1651 | goto out; |
| 1652 | } |
| 1653 | if (val < -32768 || val > 32767) { |
| 1654 | size = -EINVAL; |
| 1655 | goto out; |
| 1656 | } |
| 1657 | st_data->taps[i++] = val; |
| 1658 | buf += tmp; |
| 1659 | if (*buf != ',') |
| 1660 | break; |
| 1661 | buf++; |
| 1662 | } while (1); |
| 1663 | |
| 1664 | st_data->nr_taps = i; |
| 1665 | |
| 1666 | out: |
| 1667 | spin_unlock_irq(&mcbsp->lock); |
| 1668 | |
| 1669 | return size; |
| 1670 | } |
| 1671 | |
| 1672 | static DEVICE_ATTR(st_taps, 0644, st_taps_show, st_taps_store); |
| 1673 | |
Eduardo Valentin | 4c8200a | 2009-08-20 16:18:13 +0300 | [diff] [blame] | 1674 | static const struct attribute *additional_attrs[] = { |
Eduardo Valentin | a1a56f5 | 2009-08-20 16:18:11 +0300 | [diff] [blame] | 1675 | &dev_attr_max_tx_thres.attr, |
| 1676 | &dev_attr_max_rx_thres.attr, |
Peter Ujfalusi | 98cb20e | 2009-08-20 16:18:14 +0300 | [diff] [blame] | 1677 | &dev_attr_dma_op_mode.attr, |
Eduardo Valentin | a1a56f5 | 2009-08-20 16:18:11 +0300 | [diff] [blame] | 1678 | NULL, |
| 1679 | }; |
| 1680 | |
Eduardo Valentin | 4c8200a | 2009-08-20 16:18:13 +0300 | [diff] [blame] | 1681 | static const struct attribute_group additional_attr_group = { |
| 1682 | .attrs = (struct attribute **)additional_attrs, |
Eduardo Valentin | a1a56f5 | 2009-08-20 16:18:11 +0300 | [diff] [blame] | 1683 | }; |
| 1684 | |
Eduardo Valentin | 4c8200a | 2009-08-20 16:18:13 +0300 | [diff] [blame] | 1685 | static inline int __devinit omap_additional_add(struct device *dev) |
Eduardo Valentin | a1a56f5 | 2009-08-20 16:18:11 +0300 | [diff] [blame] | 1686 | { |
Eduardo Valentin | 4c8200a | 2009-08-20 16:18:13 +0300 | [diff] [blame] | 1687 | return sysfs_create_group(&dev->kobj, &additional_attr_group); |
Eduardo Valentin | a1a56f5 | 2009-08-20 16:18:11 +0300 | [diff] [blame] | 1688 | } |
| 1689 | |
Eduardo Valentin | 4c8200a | 2009-08-20 16:18:13 +0300 | [diff] [blame] | 1690 | static inline void __devexit omap_additional_remove(struct device *dev) |
Eduardo Valentin | a1a56f5 | 2009-08-20 16:18:11 +0300 | [diff] [blame] | 1691 | { |
Eduardo Valentin | 4c8200a | 2009-08-20 16:18:13 +0300 | [diff] [blame] | 1692 | sysfs_remove_group(&dev->kobj, &additional_attr_group); |
Eduardo Valentin | a1a56f5 | 2009-08-20 16:18:11 +0300 | [diff] [blame] | 1693 | } |
| 1694 | |
Eero Nurkkala | d912fa9 | 2010-02-22 12:21:11 +0000 | [diff] [blame] | 1695 | static const struct attribute *sidetone_attrs[] = { |
| 1696 | &dev_attr_st_taps.attr, |
| 1697 | NULL, |
| 1698 | }; |
| 1699 | |
| 1700 | static const struct attribute_group sidetone_attr_group = { |
| 1701 | .attrs = (struct attribute **)sidetone_attrs, |
| 1702 | }; |
| 1703 | |
Manjunath Kondaiah G | b0a330d | 2010-10-08 10:00:19 -0700 | [diff] [blame] | 1704 | static int __devinit omap_st_add(struct omap_mcbsp *mcbsp) |
Eero Nurkkala | d912fa9 | 2010-02-22 12:21:11 +0000 | [diff] [blame] | 1705 | { |
Kishon Vijay Abraham I | 3cf32bb | 2011-02-24 12:51:45 -0800 | [diff] [blame] | 1706 | struct platform_device *pdev; |
| 1707 | struct resource *res; |
Eero Nurkkala | d912fa9 | 2010-02-22 12:21:11 +0000 | [diff] [blame] | 1708 | struct omap_mcbsp_st_data *st_data; |
| 1709 | int err; |
| 1710 | |
| 1711 | st_data = kzalloc(sizeof(*mcbsp->st_data), GFP_KERNEL); |
| 1712 | if (!st_data) { |
| 1713 | err = -ENOMEM; |
| 1714 | goto err1; |
| 1715 | } |
| 1716 | |
Kishon Vijay Abraham I | 3cf32bb | 2011-02-24 12:51:45 -0800 | [diff] [blame] | 1717 | pdev = container_of(mcbsp->dev, struct platform_device, dev); |
| 1718 | |
| 1719 | res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "sidetone"); |
| 1720 | st_data->io_base_st = ioremap(res->start, resource_size(res)); |
Eero Nurkkala | d912fa9 | 2010-02-22 12:21:11 +0000 | [diff] [blame] | 1721 | if (!st_data->io_base_st) { |
| 1722 | err = -ENOMEM; |
| 1723 | goto err2; |
| 1724 | } |
| 1725 | |
| 1726 | err = sysfs_create_group(&mcbsp->dev->kobj, &sidetone_attr_group); |
| 1727 | if (err) |
| 1728 | goto err3; |
| 1729 | |
| 1730 | mcbsp->st_data = st_data; |
| 1731 | return 0; |
| 1732 | |
| 1733 | err3: |
| 1734 | iounmap(st_data->io_base_st); |
| 1735 | err2: |
| 1736 | kfree(st_data); |
| 1737 | err1: |
| 1738 | return err; |
| 1739 | |
| 1740 | } |
| 1741 | |
| 1742 | static void __devexit omap_st_remove(struct omap_mcbsp *mcbsp) |
| 1743 | { |
| 1744 | struct omap_mcbsp_st_data *st_data = mcbsp->st_data; |
| 1745 | |
| 1746 | if (st_data) { |
| 1747 | sysfs_remove_group(&mcbsp->dev->kobj, &sidetone_attr_group); |
| 1748 | iounmap(st_data->io_base_st); |
| 1749 | kfree(st_data); |
| 1750 | } |
| 1751 | } |
| 1752 | |
Eduardo Valentin | a1a56f5 | 2009-08-20 16:18:11 +0300 | [diff] [blame] | 1753 | static inline void __devinit omap34xx_device_init(struct omap_mcbsp *mcbsp) |
| 1754 | { |
Peter Ujfalusi | 98cb20e | 2009-08-20 16:18:14 +0300 | [diff] [blame] | 1755 | mcbsp->dma_op_mode = MCBSP_DMA_MODE_ELEMENT; |
Eduardo Valentin | a1a56f5 | 2009-08-20 16:18:11 +0300 | [diff] [blame] | 1756 | if (cpu_is_omap34xx()) { |
Peter Ujfalusi | 451fd82 | 2010-06-03 07:39:33 +0300 | [diff] [blame] | 1757 | /* |
| 1758 | * Initially configure the maximum thresholds to a safe value. |
| 1759 | * The McBSP FIFO usage with these values should not go under |
| 1760 | * 16 locations. |
| 1761 | * If the whole FIFO without safety buffer is used, than there |
| 1762 | * is a possibility that the DMA will be not able to push the |
| 1763 | * new data on time, causing channel shifts in runtime. |
| 1764 | */ |
| 1765 | mcbsp->max_tx_thres = max_thres(mcbsp) - 0x10; |
| 1766 | mcbsp->max_rx_thres = max_thres(mcbsp) - 0x10; |
Peter Ujfalusi | 98cb20e | 2009-08-20 16:18:14 +0300 | [diff] [blame] | 1767 | /* |
| 1768 | * REVISIT: Set dmap_op_mode to THRESHOLD as default |
| 1769 | * for mcbsp2 instances. |
| 1770 | */ |
Eduardo Valentin | 4c8200a | 2009-08-20 16:18:13 +0300 | [diff] [blame] | 1771 | if (omap_additional_add(mcbsp->dev)) |
Eduardo Valentin | a1a56f5 | 2009-08-20 16:18:11 +0300 | [diff] [blame] | 1772 | dev_warn(mcbsp->dev, |
Eduardo Valentin | 4c8200a | 2009-08-20 16:18:13 +0300 | [diff] [blame] | 1773 | "Unable to create additional controls\n"); |
Eero Nurkkala | d912fa9 | 2010-02-22 12:21:11 +0000 | [diff] [blame] | 1774 | |
| 1775 | if (mcbsp->id == 2 || mcbsp->id == 3) |
| 1776 | if (omap_st_add(mcbsp)) |
| 1777 | dev_warn(mcbsp->dev, |
| 1778 | "Unable to create sidetone controls\n"); |
| 1779 | |
Eduardo Valentin | a1a56f5 | 2009-08-20 16:18:11 +0300 | [diff] [blame] | 1780 | } else { |
| 1781 | mcbsp->max_tx_thres = -EINVAL; |
| 1782 | mcbsp->max_rx_thres = -EINVAL; |
| 1783 | } |
| 1784 | } |
| 1785 | |
| 1786 | static inline void __devexit omap34xx_device_exit(struct omap_mcbsp *mcbsp) |
| 1787 | { |
Eero Nurkkala | d912fa9 | 2010-02-22 12:21:11 +0000 | [diff] [blame] | 1788 | if (cpu_is_omap34xx()) { |
Eduardo Valentin | 4c8200a | 2009-08-20 16:18:13 +0300 | [diff] [blame] | 1789 | omap_additional_remove(mcbsp->dev); |
Eero Nurkkala | d912fa9 | 2010-02-22 12:21:11 +0000 | [diff] [blame] | 1790 | |
| 1791 | if (mcbsp->id == 2 || mcbsp->id == 3) |
| 1792 | omap_st_remove(mcbsp); |
| 1793 | } |
Eduardo Valentin | a1a56f5 | 2009-08-20 16:18:11 +0300 | [diff] [blame] | 1794 | } |
| 1795 | #else |
| 1796 | static inline void __devinit omap34xx_device_init(struct omap_mcbsp *mcbsp) {} |
| 1797 | static inline void __devexit omap34xx_device_exit(struct omap_mcbsp *mcbsp) {} |
Tony Lindgren | a8eb7ca | 2010-02-12 12:26:48 -0800 | [diff] [blame] | 1798 | #endif /* CONFIG_ARCH_OMAP3 */ |
Eduardo Valentin | a1a56f5 | 2009-08-20 16:18:11 +0300 | [diff] [blame] | 1799 | |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 1800 | /* |
| 1801 | * McBSP1 and McBSP3 are directly mapped on 1610 and 1510. |
| 1802 | * 730 has only 2 McBSP, and both of them are MPU peripherals. |
| 1803 | */ |
Uwe Kleine-König | 25cef22 | 2008-10-08 10:01:39 +0300 | [diff] [blame] | 1804 | static int __devinit omap_mcbsp_probe(struct platform_device *pdev) |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 1805 | { |
Eduardo Valentin | bc5d0c8 | 2008-07-03 12:24:39 +0300 | [diff] [blame] | 1806 | struct omap_mcbsp_platform_data *pdata = pdev->dev.platform_data; |
Chandra Shekhar | b4b58f5 | 2008-10-08 10:01:39 +0300 | [diff] [blame] | 1807 | struct omap_mcbsp *mcbsp; |
Eduardo Valentin | bc5d0c8 | 2008-07-03 12:24:39 +0300 | [diff] [blame] | 1808 | int id = pdev->id - 1; |
Kishon Vijay Abraham I | 3cf32bb | 2011-02-24 12:51:45 -0800 | [diff] [blame] | 1809 | struct resource *res; |
Eduardo Valentin | bc5d0c8 | 2008-07-03 12:24:39 +0300 | [diff] [blame] | 1810 | int ret = 0; |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 1811 | |
Eduardo Valentin | bc5d0c8 | 2008-07-03 12:24:39 +0300 | [diff] [blame] | 1812 | if (!pdata) { |
| 1813 | dev_err(&pdev->dev, "McBSP device initialized without" |
| 1814 | "platform data\n"); |
| 1815 | ret = -EINVAL; |
| 1816 | goto exit; |
| 1817 | } |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 1818 | |
Eduardo Valentin | bc5d0c8 | 2008-07-03 12:24:39 +0300 | [diff] [blame] | 1819 | dev_dbg(&pdev->dev, "Initializing OMAP McBSP (%d).\n", pdev->id); |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 1820 | |
Chandra Shekhar | b4b58f5 | 2008-10-08 10:01:39 +0300 | [diff] [blame] | 1821 | if (id >= omap_mcbsp_count) { |
Eduardo Valentin | bc5d0c8 | 2008-07-03 12:24:39 +0300 | [diff] [blame] | 1822 | dev_err(&pdev->dev, "Invalid McBSP device id (%d)\n", id); |
| 1823 | ret = -EINVAL; |
| 1824 | goto exit; |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 1825 | } |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 1826 | |
Chandra Shekhar | b4b58f5 | 2008-10-08 10:01:39 +0300 | [diff] [blame] | 1827 | mcbsp = kzalloc(sizeof(struct omap_mcbsp), GFP_KERNEL); |
| 1828 | if (!mcbsp) { |
| 1829 | ret = -ENOMEM; |
| 1830 | goto exit; |
| 1831 | } |
Eduardo Valentin | bc5d0c8 | 2008-07-03 12:24:39 +0300 | [diff] [blame] | 1832 | |
Chandra Shekhar | b4b58f5 | 2008-10-08 10:01:39 +0300 | [diff] [blame] | 1833 | spin_lock_init(&mcbsp->lock); |
| 1834 | mcbsp->id = id + 1; |
Shubhrajyoti D | 6722a72 | 2010-12-07 16:25:41 -0800 | [diff] [blame] | 1835 | mcbsp->free = true; |
Chandra Shekhar | b4b58f5 | 2008-10-08 10:01:39 +0300 | [diff] [blame] | 1836 | mcbsp->dma_tx_lch = -1; |
| 1837 | mcbsp->dma_rx_lch = -1; |
| 1838 | |
Kishon Vijay Abraham I | 3cf32bb | 2011-02-24 12:51:45 -0800 | [diff] [blame] | 1839 | res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "mpu"); |
| 1840 | if (!res) { |
| 1841 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
| 1842 | if (!res) { |
| 1843 | dev_err(&pdev->dev, "%s:mcbsp%d has invalid memory" |
| 1844 | "resource\n", __func__, pdev->id); |
| 1845 | ret = -ENOMEM; |
| 1846 | goto exit; |
| 1847 | } |
| 1848 | } |
| 1849 | mcbsp->phys_base = res->start; |
| 1850 | omap_mcbsp_cache_size = resource_size(res); |
| 1851 | mcbsp->io_base = ioremap(res->start, resource_size(res)); |
Chandra Shekhar | b4b58f5 | 2008-10-08 10:01:39 +0300 | [diff] [blame] | 1852 | if (!mcbsp->io_base) { |
Russell King | d592dd1 | 2008-09-04 14:25:42 +0100 | [diff] [blame] | 1853 | ret = -ENOMEM; |
| 1854 | goto err_ioremap; |
| 1855 | } |
| 1856 | |
Kishon Vijay Abraham I | 3cf32bb | 2011-02-24 12:51:45 -0800 | [diff] [blame] | 1857 | res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "dma"); |
| 1858 | if (!res) |
| 1859 | mcbsp->phys_dma_base = mcbsp->phys_base; |
| 1860 | else |
| 1861 | mcbsp->phys_dma_base = res->start; |
| 1862 | |
Eduardo Valentin | bc5d0c8 | 2008-07-03 12:24:39 +0300 | [diff] [blame] | 1863 | /* Default I/O is IRQ based */ |
Chandra Shekhar | b4b58f5 | 2008-10-08 10:01:39 +0300 | [diff] [blame] | 1864 | mcbsp->io_type = OMAP_MCBSP_IRQ_IO; |
Kishon Vijay Abraham I | 3cf32bb | 2011-02-24 12:51:45 -0800 | [diff] [blame] | 1865 | |
| 1866 | mcbsp->tx_irq = platform_get_irq_byname(pdev, "tx"); |
| 1867 | mcbsp->rx_irq = platform_get_irq_byname(pdev, "rx"); |
| 1868 | |
Kishon Vijay Abraham I | cb7e9de | 2011-02-24 15:16:50 +0530 | [diff] [blame] | 1869 | /* From OMAP4 there will be a single irq line */ |
| 1870 | if (mcbsp->tx_irq == -ENXIO) |
| 1871 | mcbsp->tx_irq = platform_get_irq(pdev, 0); |
| 1872 | |
Kishon Vijay Abraham I | 3cf32bb | 2011-02-24 12:51:45 -0800 | [diff] [blame] | 1873 | res = platform_get_resource_byname(pdev, IORESOURCE_DMA, "rx"); |
| 1874 | if (!res) { |
| 1875 | dev_err(&pdev->dev, "%s:mcbsp%d has invalid rx DMA channel\n", |
| 1876 | __func__, pdev->id); |
| 1877 | ret = -ENODEV; |
| 1878 | goto err_res; |
| 1879 | } |
| 1880 | mcbsp->dma_rx_sync = res->start; |
| 1881 | |
| 1882 | res = platform_get_resource_byname(pdev, IORESOURCE_DMA, "tx"); |
| 1883 | if (!res) { |
| 1884 | dev_err(&pdev->dev, "%s:mcbsp%d has invalid tx DMA channel\n", |
| 1885 | __func__, pdev->id); |
| 1886 | ret = -ENODEV; |
| 1887 | goto err_res; |
| 1888 | } |
| 1889 | mcbsp->dma_tx_sync = res->start; |
Eduardo Valentin | bc5d0c8 | 2008-07-03 12:24:39 +0300 | [diff] [blame] | 1890 | |
Russell King | b820ce4 | 2009-01-23 10:26:46 +0000 | [diff] [blame] | 1891 | mcbsp->fclk = clk_get(&pdev->dev, "fck"); |
| 1892 | if (IS_ERR(mcbsp->fclk)) { |
| 1893 | ret = PTR_ERR(mcbsp->fclk); |
| 1894 | dev_err(&pdev->dev, "unable to get fck: %d\n", ret); |
Kishon Vijay Abraham I | e95496d | 2011-02-24 15:16:54 +0530 | [diff] [blame] | 1895 | goto err_res; |
Eduardo Valentin | bc5d0c8 | 2008-07-03 12:24:39 +0300 | [diff] [blame] | 1896 | } |
| 1897 | |
Chandra Shekhar | b4b58f5 | 2008-10-08 10:01:39 +0300 | [diff] [blame] | 1898 | mcbsp->pdata = pdata; |
| 1899 | mcbsp->dev = &pdev->dev; |
Russell King | b820ce4 | 2009-01-23 10:26:46 +0000 | [diff] [blame] | 1900 | mcbsp_ptr[id] = mcbsp; |
Kishon Vijay Abraham I | 9504ba6 | 2011-02-24 15:16:55 +0530 | [diff] [blame] | 1901 | mcbsp->mcbsp_config_type = pdata->mcbsp_config_type; |
Chandra Shekhar | b4b58f5 | 2008-10-08 10:01:39 +0300 | [diff] [blame] | 1902 | platform_set_drvdata(pdev, mcbsp); |
Kishon Vijay Abraham I | e95496d | 2011-02-24 15:16:54 +0530 | [diff] [blame] | 1903 | pm_runtime_enable(mcbsp->dev); |
Eduardo Valentin | a1a56f5 | 2009-08-20 16:18:11 +0300 | [diff] [blame] | 1904 | |
| 1905 | /* Initialize mcbsp properties for OMAP34XX if needed / applicable */ |
| 1906 | omap34xx_device_init(mcbsp); |
| 1907 | |
Russell King | d592dd1 | 2008-09-04 14:25:42 +0100 | [diff] [blame] | 1908 | return 0; |
Eduardo Valentin | bc5d0c8 | 2008-07-03 12:24:39 +0300 | [diff] [blame] | 1909 | |
Kishon Vijay Abraham I | 3cf32bb | 2011-02-24 12:51:45 -0800 | [diff] [blame] | 1910 | err_res: |
Chandra Shekhar | b4b58f5 | 2008-10-08 10:01:39 +0300 | [diff] [blame] | 1911 | iounmap(mcbsp->io_base); |
Russell King | d592dd1 | 2008-09-04 14:25:42 +0100 | [diff] [blame] | 1912 | err_ioremap: |
Russell King | b820ce4 | 2009-01-23 10:26:46 +0000 | [diff] [blame] | 1913 | kfree(mcbsp); |
Eduardo Valentin | bc5d0c8 | 2008-07-03 12:24:39 +0300 | [diff] [blame] | 1914 | exit: |
| 1915 | return ret; |
| 1916 | } |
| 1917 | |
Uwe Kleine-König | 25cef22 | 2008-10-08 10:01:39 +0300 | [diff] [blame] | 1918 | static int __devexit omap_mcbsp_remove(struct platform_device *pdev) |
Eduardo Valentin | bc5d0c8 | 2008-07-03 12:24:39 +0300 | [diff] [blame] | 1919 | { |
| 1920 | struct omap_mcbsp *mcbsp = platform_get_drvdata(pdev); |
| 1921 | |
| 1922 | platform_set_drvdata(pdev, NULL); |
| 1923 | if (mcbsp) { |
| 1924 | |
| 1925 | if (mcbsp->pdata && mcbsp->pdata->ops && |
| 1926 | mcbsp->pdata->ops->free) |
| 1927 | mcbsp->pdata->ops->free(mcbsp->id); |
| 1928 | |
Eduardo Valentin | a1a56f5 | 2009-08-20 16:18:11 +0300 | [diff] [blame] | 1929 | omap34xx_device_exit(mcbsp); |
| 1930 | |
Russell King | b820ce4 | 2009-01-23 10:26:46 +0000 | [diff] [blame] | 1931 | clk_put(mcbsp->fclk); |
Eduardo Valentin | bc5d0c8 | 2008-07-03 12:24:39 +0300 | [diff] [blame] | 1932 | |
Russell King | d592dd1 | 2008-09-04 14:25:42 +0100 | [diff] [blame] | 1933 | iounmap(mcbsp->io_base); |
Jarkko Nikula | 5f3b728 | 2010-12-07 16:25:40 -0800 | [diff] [blame] | 1934 | kfree(mcbsp); |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 1935 | } |
| 1936 | |
| 1937 | return 0; |
| 1938 | } |
| 1939 | |
Eduardo Valentin | bc5d0c8 | 2008-07-03 12:24:39 +0300 | [diff] [blame] | 1940 | static struct platform_driver omap_mcbsp_driver = { |
| 1941 | .probe = omap_mcbsp_probe, |
Uwe Kleine-König | 25cef22 | 2008-10-08 10:01:39 +0300 | [diff] [blame] | 1942 | .remove = __devexit_p(omap_mcbsp_remove), |
Eduardo Valentin | bc5d0c8 | 2008-07-03 12:24:39 +0300 | [diff] [blame] | 1943 | .driver = { |
| 1944 | .name = "omap-mcbsp", |
| 1945 | }, |
| 1946 | }; |
| 1947 | |
| 1948 | int __init omap_mcbsp_init(void) |
| 1949 | { |
| 1950 | /* Register the McBSP driver */ |
| 1951 | return platform_driver_register(&omap_mcbsp_driver); |
| 1952 | } |