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