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/interrupt.h> |
| 20 | #include <linux/err.h> |
Russell King | f8ce254 | 2006-01-07 16:15:52 +0000 | [diff] [blame] | 21 | #include <linux/clk.h> |
Tony Lindgren | 04fbf6a | 2007-02-12 10:50:53 -0800 | [diff] [blame] | 22 | #include <linux/delay.h> |
Eduardo Valentin | fb78d80 | 2008-07-03 12:24:39 +0300 | [diff] [blame] | 23 | #include <linux/io.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 24 | #include <linux/slab.h> |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 25 | |
Tony Lindgren | ce491cf | 2009-10-20 09:40:47 -0700 | [diff] [blame] | 26 | #include <plat/mcbsp.h> |
Kishon Vijay Abraham I | e95496d | 2011-02-24 15:16:54 +0530 | [diff] [blame] | 27 | #include <linux/pm_runtime.h> |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 28 | |
Chandra Shekhar | b4b58f5 | 2008-10-08 10:01:39 +0300 | [diff] [blame] | 29 | struct omap_mcbsp **mcbsp_ptr; |
Jarkko Nikula | ac6747ca | 2011-09-26 10:45:43 +0300 | [diff] [blame] | 30 | int omap_mcbsp_count; |
Eduardo Valentin | bc5d0c8 | 2008-07-03 12:24:39 +0300 | [diff] [blame] | 31 | |
Jarkko Nikula | 09d28d2 | 2011-09-26 10:45:48 +0300 | [diff] [blame] | 32 | #define omap_mcbsp_check_valid_id(id) (id < omap_mcbsp_count) |
| 33 | #define id_to_mcbsp_ptr(id) mcbsp_ptr[id]; |
| 34 | |
Manjunath Kondaiah G | b0a330d | 2010-10-08 10:00:19 -0700 | [diff] [blame] | 35 | static void omap_mcbsp_write(struct omap_mcbsp *mcbsp, u16 reg, u32 val) |
Chandra Shekhar | b4b58f5 | 2008-10-08 10:01:39 +0300 | [diff] [blame] | 36 | { |
Jarkko Nikula | cdc71514 | 2011-09-26 10:45:39 +0300 | [diff] [blame] | 37 | void __iomem *addr = mcbsp->io_base + reg * mcbsp->pdata->reg_step; |
| 38 | |
| 39 | if (mcbsp->pdata->reg_size == 2) { |
| 40 | ((u16 *)mcbsp->reg_cache)[reg] = (u16)val; |
| 41 | __raw_writew((u16)val, addr); |
Janusz Krzysztofik | c8c9969 | 2010-02-15 10:03:33 -0800 | [diff] [blame] | 42 | } else { |
Jarkko Nikula | cdc71514 | 2011-09-26 10:45:39 +0300 | [diff] [blame] | 43 | ((u32 *)mcbsp->reg_cache)[reg] = val; |
| 44 | __raw_writel(val, addr); |
Janusz Krzysztofik | c8c9969 | 2010-02-15 10:03:33 -0800 | [diff] [blame] | 45 | } |
Chandra Shekhar | b4b58f5 | 2008-10-08 10:01:39 +0300 | [diff] [blame] | 46 | } |
| 47 | |
Manjunath Kondaiah G | b0a330d | 2010-10-08 10:00:19 -0700 | [diff] [blame] | 48 | static int omap_mcbsp_read(struct omap_mcbsp *mcbsp, u16 reg, bool from_cache) |
Chandra Shekhar | b4b58f5 | 2008-10-08 10:01:39 +0300 | [diff] [blame] | 49 | { |
Jarkko Nikula | cdc71514 | 2011-09-26 10:45:39 +0300 | [diff] [blame] | 50 | void __iomem *addr = mcbsp->io_base + reg * mcbsp->pdata->reg_step; |
| 51 | |
| 52 | if (mcbsp->pdata->reg_size == 2) { |
| 53 | return !from_cache ? __raw_readw(addr) : |
| 54 | ((u16 *)mcbsp->reg_cache)[reg]; |
Janusz Krzysztofik | c8c9969 | 2010-02-15 10:03:33 -0800 | [diff] [blame] | 55 | } else { |
Jarkko Nikula | cdc71514 | 2011-09-26 10:45:39 +0300 | [diff] [blame] | 56 | return !from_cache ? __raw_readl(addr) : |
| 57 | ((u32 *)mcbsp->reg_cache)[reg]; |
Janusz Krzysztofik | c8c9969 | 2010-02-15 10:03:33 -0800 | [diff] [blame] | 58 | } |
Chandra Shekhar | b4b58f5 | 2008-10-08 10:01:39 +0300 | [diff] [blame] | 59 | } |
| 60 | |
Manjunath Kondaiah G | b0a330d | 2010-10-08 10:00:19 -0700 | [diff] [blame] | 61 | static void omap_mcbsp_st_write(struct omap_mcbsp *mcbsp, u16 reg, u32 val) |
Eero Nurkkala | d912fa9 | 2010-02-22 12:21:11 +0000 | [diff] [blame] | 62 | { |
| 63 | __raw_writel(val, mcbsp->st_data->io_base_st + reg); |
| 64 | } |
| 65 | |
Manjunath Kondaiah G | b0a330d | 2010-10-08 10:00:19 -0700 | [diff] [blame] | 66 | static int omap_mcbsp_st_read(struct omap_mcbsp *mcbsp, u16 reg) |
Eero Nurkkala | d912fa9 | 2010-02-22 12:21:11 +0000 | [diff] [blame] | 67 | { |
| 68 | return __raw_readl(mcbsp->st_data->io_base_st + reg); |
| 69 | } |
Eero Nurkkala | d912fa9 | 2010-02-22 12:21:11 +0000 | [diff] [blame] | 70 | |
Janusz Krzysztofik | 8ea3200 | 2010-02-15 10:03:32 -0800 | [diff] [blame] | 71 | #define MCBSP_READ(mcbsp, reg) \ |
Janusz Krzysztofik | c8c9969 | 2010-02-15 10:03:33 -0800 | [diff] [blame] | 72 | omap_mcbsp_read(mcbsp, OMAP_MCBSP_REG_##reg, 0) |
Janusz Krzysztofik | 8ea3200 | 2010-02-15 10:03:32 -0800 | [diff] [blame] | 73 | #define MCBSP_WRITE(mcbsp, reg, val) \ |
| 74 | omap_mcbsp_write(mcbsp, OMAP_MCBSP_REG_##reg, val) |
Janusz Krzysztofik | c8c9969 | 2010-02-15 10:03:33 -0800 | [diff] [blame] | 75 | #define MCBSP_READ_CACHE(mcbsp, reg) \ |
| 76 | omap_mcbsp_read(mcbsp, OMAP_MCBSP_REG_##reg, 1) |
Chandra Shekhar | b4b58f5 | 2008-10-08 10:01:39 +0300 | [diff] [blame] | 77 | |
Eero Nurkkala | d912fa9 | 2010-02-22 12:21:11 +0000 | [diff] [blame] | 78 | #define MCBSP_ST_READ(mcbsp, reg) \ |
| 79 | omap_mcbsp_st_read(mcbsp, OMAP_ST_REG_##reg) |
| 80 | #define MCBSP_ST_WRITE(mcbsp, reg, val) \ |
| 81 | omap_mcbsp_st_write(mcbsp, OMAP_ST_REG_##reg, val) |
| 82 | |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 83 | static void omap_mcbsp_dump_reg(u8 id) |
| 84 | { |
Chandra Shekhar | b4b58f5 | 2008-10-08 10:01:39 +0300 | [diff] [blame] | 85 | struct omap_mcbsp *mcbsp = id_to_mcbsp_ptr(id); |
| 86 | |
| 87 | dev_dbg(mcbsp->dev, "**** McBSP%d regs ****\n", mcbsp->id); |
| 88 | dev_dbg(mcbsp->dev, "DRR2: 0x%04x\n", |
Janusz Krzysztofik | 8ea3200 | 2010-02-15 10:03:32 -0800 | [diff] [blame] | 89 | MCBSP_READ(mcbsp, DRR2)); |
Chandra Shekhar | b4b58f5 | 2008-10-08 10:01:39 +0300 | [diff] [blame] | 90 | dev_dbg(mcbsp->dev, "DRR1: 0x%04x\n", |
Janusz Krzysztofik | 8ea3200 | 2010-02-15 10:03:32 -0800 | [diff] [blame] | 91 | MCBSP_READ(mcbsp, DRR1)); |
Chandra Shekhar | b4b58f5 | 2008-10-08 10:01:39 +0300 | [diff] [blame] | 92 | dev_dbg(mcbsp->dev, "DXR2: 0x%04x\n", |
Janusz Krzysztofik | 8ea3200 | 2010-02-15 10:03:32 -0800 | [diff] [blame] | 93 | MCBSP_READ(mcbsp, DXR2)); |
Chandra Shekhar | b4b58f5 | 2008-10-08 10:01:39 +0300 | [diff] [blame] | 94 | dev_dbg(mcbsp->dev, "DXR1: 0x%04x\n", |
Janusz Krzysztofik | 8ea3200 | 2010-02-15 10:03:32 -0800 | [diff] [blame] | 95 | MCBSP_READ(mcbsp, DXR1)); |
Chandra Shekhar | b4b58f5 | 2008-10-08 10:01:39 +0300 | [diff] [blame] | 96 | dev_dbg(mcbsp->dev, "SPCR2: 0x%04x\n", |
Janusz Krzysztofik | 8ea3200 | 2010-02-15 10:03:32 -0800 | [diff] [blame] | 97 | MCBSP_READ(mcbsp, SPCR2)); |
Chandra Shekhar | b4b58f5 | 2008-10-08 10:01:39 +0300 | [diff] [blame] | 98 | dev_dbg(mcbsp->dev, "SPCR1: 0x%04x\n", |
Janusz Krzysztofik | 8ea3200 | 2010-02-15 10:03:32 -0800 | [diff] [blame] | 99 | MCBSP_READ(mcbsp, SPCR1)); |
Chandra Shekhar | b4b58f5 | 2008-10-08 10:01:39 +0300 | [diff] [blame] | 100 | dev_dbg(mcbsp->dev, "RCR2: 0x%04x\n", |
Janusz Krzysztofik | 8ea3200 | 2010-02-15 10:03:32 -0800 | [diff] [blame] | 101 | MCBSP_READ(mcbsp, RCR2)); |
Chandra Shekhar | b4b58f5 | 2008-10-08 10:01:39 +0300 | [diff] [blame] | 102 | dev_dbg(mcbsp->dev, "RCR1: 0x%04x\n", |
Janusz Krzysztofik | 8ea3200 | 2010-02-15 10:03:32 -0800 | [diff] [blame] | 103 | MCBSP_READ(mcbsp, RCR1)); |
Chandra Shekhar | b4b58f5 | 2008-10-08 10:01:39 +0300 | [diff] [blame] | 104 | dev_dbg(mcbsp->dev, "XCR2: 0x%04x\n", |
Janusz Krzysztofik | 8ea3200 | 2010-02-15 10:03:32 -0800 | [diff] [blame] | 105 | MCBSP_READ(mcbsp, XCR2)); |
Chandra Shekhar | b4b58f5 | 2008-10-08 10:01:39 +0300 | [diff] [blame] | 106 | dev_dbg(mcbsp->dev, "XCR1: 0x%04x\n", |
Janusz Krzysztofik | 8ea3200 | 2010-02-15 10:03:32 -0800 | [diff] [blame] | 107 | MCBSP_READ(mcbsp, XCR1)); |
Chandra Shekhar | b4b58f5 | 2008-10-08 10:01:39 +0300 | [diff] [blame] | 108 | dev_dbg(mcbsp->dev, "SRGR2: 0x%04x\n", |
Janusz Krzysztofik | 8ea3200 | 2010-02-15 10:03:32 -0800 | [diff] [blame] | 109 | MCBSP_READ(mcbsp, SRGR2)); |
Chandra Shekhar | b4b58f5 | 2008-10-08 10:01:39 +0300 | [diff] [blame] | 110 | dev_dbg(mcbsp->dev, "SRGR1: 0x%04x\n", |
Janusz Krzysztofik | 8ea3200 | 2010-02-15 10:03:32 -0800 | [diff] [blame] | 111 | MCBSP_READ(mcbsp, SRGR1)); |
Chandra Shekhar | b4b58f5 | 2008-10-08 10:01:39 +0300 | [diff] [blame] | 112 | dev_dbg(mcbsp->dev, "PCR0: 0x%04x\n", |
Janusz Krzysztofik | 8ea3200 | 2010-02-15 10:03:32 -0800 | [diff] [blame] | 113 | MCBSP_READ(mcbsp, PCR0)); |
Chandra Shekhar | b4b58f5 | 2008-10-08 10:01:39 +0300 | [diff] [blame] | 114 | dev_dbg(mcbsp->dev, "***********************\n"); |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 115 | } |
| 116 | |
Linus Torvalds | 0cd61b6 | 2006-10-06 10:53:39 -0700 | [diff] [blame] | 117 | 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] | 118 | { |
Jeff Garzik | e8f2af1 | 2007-10-26 05:40:25 -0400 | [diff] [blame] | 119 | struct omap_mcbsp *mcbsp_tx = dev_id; |
Eero Nurkkala | d6d834b | 2009-05-25 11:08:42 -0700 | [diff] [blame] | 120 | u16 irqst_spcr2; |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 121 | |
Janusz Krzysztofik | 8ea3200 | 2010-02-15 10:03:32 -0800 | [diff] [blame] | 122 | irqst_spcr2 = MCBSP_READ(mcbsp_tx, SPCR2); |
Eero Nurkkala | d6d834b | 2009-05-25 11:08:42 -0700 | [diff] [blame] | 123 | 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] | 124 | |
Eero Nurkkala | d6d834b | 2009-05-25 11:08:42 -0700 | [diff] [blame] | 125 | if (irqst_spcr2 & XSYNC_ERR) { |
| 126 | dev_err(mcbsp_tx->dev, "TX Frame Sync Error! : 0x%x\n", |
| 127 | irqst_spcr2); |
| 128 | /* Writing zero to XSYNC_ERR clears the IRQ */ |
Janusz Krzysztofik | 0841cb8 | 2010-02-23 15:50:38 +0000 | [diff] [blame] | 129 | MCBSP_WRITE(mcbsp_tx, SPCR2, MCBSP_READ_CACHE(mcbsp_tx, SPCR2)); |
Eero Nurkkala | d6d834b | 2009-05-25 11:08:42 -0700 | [diff] [blame] | 130 | } |
Eduardo Valentin | fb78d80 | 2008-07-03 12:24:39 +0300 | [diff] [blame] | 131 | |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 132 | return IRQ_HANDLED; |
| 133 | } |
| 134 | |
Linus Torvalds | 0cd61b6 | 2006-10-06 10:53:39 -0700 | [diff] [blame] | 135 | 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] | 136 | { |
Jeff Garzik | e8f2af1 | 2007-10-26 05:40:25 -0400 | [diff] [blame] | 137 | struct omap_mcbsp *mcbsp_rx = dev_id; |
Eero Nurkkala | d6d834b | 2009-05-25 11:08:42 -0700 | [diff] [blame] | 138 | u16 irqst_spcr1; |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 139 | |
Janusz Krzysztofik | 8ea3200 | 2010-02-15 10:03:32 -0800 | [diff] [blame] | 140 | irqst_spcr1 = MCBSP_READ(mcbsp_rx, SPCR1); |
Eero Nurkkala | d6d834b | 2009-05-25 11:08:42 -0700 | [diff] [blame] | 141 | 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] | 142 | |
Eero Nurkkala | d6d834b | 2009-05-25 11:08:42 -0700 | [diff] [blame] | 143 | if (irqst_spcr1 & RSYNC_ERR) { |
| 144 | dev_err(mcbsp_rx->dev, "RX Frame Sync Error! : 0x%x\n", |
| 145 | irqst_spcr1); |
| 146 | /* Writing zero to RSYNC_ERR clears the IRQ */ |
Janusz Krzysztofik | 0841cb8 | 2010-02-23 15:50:38 +0000 | [diff] [blame] | 147 | MCBSP_WRITE(mcbsp_rx, SPCR1, MCBSP_READ_CACHE(mcbsp_rx, SPCR1)); |
Eero Nurkkala | d6d834b | 2009-05-25 11:08:42 -0700 | [diff] [blame] | 148 | } |
Eduardo Valentin | fb78d80 | 2008-07-03 12:24:39 +0300 | [diff] [blame] | 149 | |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 150 | return IRQ_HANDLED; |
| 151 | } |
| 152 | |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 153 | /* |
| 154 | * omap_mcbsp_config simply write a config to the |
| 155 | * appropriate McBSP. |
| 156 | * You either call this function or set the McBSP registers |
| 157 | * by yourself before calling omap_mcbsp_start(). |
| 158 | */ |
Eduardo Valentin | fb78d80 | 2008-07-03 12:24:39 +0300 | [diff] [blame] | 159 | 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] | 160 | { |
Chandra Shekhar | b4b58f5 | 2008-10-08 10:01:39 +0300 | [diff] [blame] | 161 | struct omap_mcbsp *mcbsp; |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 162 | |
Eduardo Valentin | bc5d0c8 | 2008-07-03 12:24:39 +0300 | [diff] [blame] | 163 | if (!omap_mcbsp_check_valid_id(id)) { |
| 164 | printk(KERN_ERR "%s: Invalid id (%d)\n", __func__, id + 1); |
| 165 | return; |
| 166 | } |
Chandra Shekhar | b4b58f5 | 2008-10-08 10:01:39 +0300 | [diff] [blame] | 167 | mcbsp = id_to_mcbsp_ptr(id); |
Eduardo Valentin | bc5d0c8 | 2008-07-03 12:24:39 +0300 | [diff] [blame] | 168 | |
Chandra Shekhar | b4b58f5 | 2008-10-08 10:01:39 +0300 | [diff] [blame] | 169 | dev_dbg(mcbsp->dev, "Configuring McBSP%d phys_base: 0x%08lx\n", |
| 170 | mcbsp->id, mcbsp->phys_base); |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 171 | |
| 172 | /* We write the given config */ |
Janusz Krzysztofik | 8ea3200 | 2010-02-15 10:03:32 -0800 | [diff] [blame] | 173 | MCBSP_WRITE(mcbsp, SPCR2, config->spcr2); |
| 174 | MCBSP_WRITE(mcbsp, SPCR1, config->spcr1); |
| 175 | MCBSP_WRITE(mcbsp, RCR2, config->rcr2); |
| 176 | MCBSP_WRITE(mcbsp, RCR1, config->rcr1); |
| 177 | MCBSP_WRITE(mcbsp, XCR2, config->xcr2); |
| 178 | MCBSP_WRITE(mcbsp, XCR1, config->xcr1); |
| 179 | MCBSP_WRITE(mcbsp, SRGR2, config->srgr2); |
| 180 | MCBSP_WRITE(mcbsp, SRGR1, config->srgr1); |
| 181 | MCBSP_WRITE(mcbsp, MCR2, config->mcr2); |
| 182 | MCBSP_WRITE(mcbsp, MCR1, config->mcr1); |
| 183 | MCBSP_WRITE(mcbsp, PCR0, config->pcr0); |
Jarkko Nikula | 8840823 | 2011-09-26 10:45:41 +0300 | [diff] [blame] | 184 | if (mcbsp->pdata->has_ccr) { |
Janusz Krzysztofik | 8ea3200 | 2010-02-15 10:03:32 -0800 | [diff] [blame] | 185 | MCBSP_WRITE(mcbsp, XCCR, config->xccr); |
| 186 | MCBSP_WRITE(mcbsp, RCCR, config->rccr); |
Tony Lindgren | 3127f8f | 2009-01-15 13:09:54 +0200 | [diff] [blame] | 187 | } |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 188 | } |
Eduardo Valentin | fb78d80 | 2008-07-03 12:24:39 +0300 | [diff] [blame] | 189 | EXPORT_SYMBOL(omap_mcbsp_config); |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 190 | |
Kishon Vijay Abraham I | 9504ba6 | 2011-02-24 15:16:55 +0530 | [diff] [blame] | 191 | /** |
| 192 | * omap_mcbsp_dma_params - returns the dma channel number |
| 193 | * @id - mcbsp id |
| 194 | * @stream - indicates the direction of data flow (rx or tx) |
| 195 | * |
| 196 | * Returns the dma channel number for the rx channel or tx channel |
| 197 | * based on the value of @stream for the requested mcbsp given by @id |
| 198 | */ |
| 199 | int omap_mcbsp_dma_ch_params(unsigned int id, unsigned int stream) |
| 200 | { |
| 201 | struct omap_mcbsp *mcbsp; |
| 202 | |
| 203 | if (!omap_mcbsp_check_valid_id(id)) { |
| 204 | printk(KERN_ERR "%s: Invalid id (%d)\n", __func__, id + 1); |
| 205 | return -ENODEV; |
| 206 | } |
| 207 | mcbsp = id_to_mcbsp_ptr(id); |
| 208 | |
| 209 | if (stream) |
| 210 | return mcbsp->dma_rx_sync; |
| 211 | else |
| 212 | return mcbsp->dma_tx_sync; |
| 213 | } |
| 214 | EXPORT_SYMBOL(omap_mcbsp_dma_ch_params); |
| 215 | |
| 216 | /** |
| 217 | * omap_mcbsp_dma_reg_params - returns the address of mcbsp data register |
| 218 | * @id - mcbsp id |
| 219 | * @stream - indicates the direction of data flow (rx or tx) |
| 220 | * |
| 221 | * Returns the address of mcbsp data transmit register or data receive register |
| 222 | * to be used by DMA for transferring/receiving data based on the value of |
| 223 | * @stream for the requested mcbsp given by @id |
| 224 | */ |
| 225 | int omap_mcbsp_dma_reg_params(unsigned int id, unsigned int stream) |
| 226 | { |
| 227 | struct omap_mcbsp *mcbsp; |
| 228 | int data_reg; |
| 229 | |
| 230 | if (!omap_mcbsp_check_valid_id(id)) { |
| 231 | printk(KERN_ERR "%s: Invalid id (%d)\n", __func__, id + 1); |
| 232 | return -ENODEV; |
| 233 | } |
| 234 | mcbsp = id_to_mcbsp_ptr(id); |
| 235 | |
Jarkko Nikula | cdc71514 | 2011-09-26 10:45:39 +0300 | [diff] [blame] | 236 | if (mcbsp->pdata->reg_size == 2) { |
Kishon Vijay Abraham I | 9504ba6 | 2011-02-24 15:16:55 +0530 | [diff] [blame] | 237 | if (stream) |
Jarkko Nikula | cdc71514 | 2011-09-26 10:45:39 +0300 | [diff] [blame] | 238 | data_reg = OMAP_MCBSP_REG_DRR1; |
Kishon Vijay Abraham I | 9504ba6 | 2011-02-24 15:16:55 +0530 | [diff] [blame] | 239 | else |
Jarkko Nikula | cdc71514 | 2011-09-26 10:45:39 +0300 | [diff] [blame] | 240 | data_reg = OMAP_MCBSP_REG_DXR1; |
Kishon Vijay Abraham I | 9504ba6 | 2011-02-24 15:16:55 +0530 | [diff] [blame] | 241 | } else { |
| 242 | if (stream) |
Jarkko Nikula | cdc71514 | 2011-09-26 10:45:39 +0300 | [diff] [blame] | 243 | data_reg = OMAP_MCBSP_REG_DRR; |
Kishon Vijay Abraham I | 9504ba6 | 2011-02-24 15:16:55 +0530 | [diff] [blame] | 244 | else |
Jarkko Nikula | cdc71514 | 2011-09-26 10:45:39 +0300 | [diff] [blame] | 245 | data_reg = OMAP_MCBSP_REG_DXR; |
Kishon Vijay Abraham I | 9504ba6 | 2011-02-24 15:16:55 +0530 | [diff] [blame] | 246 | } |
| 247 | |
Jarkko Nikula | cdc71514 | 2011-09-26 10:45:39 +0300 | [diff] [blame] | 248 | return mcbsp->phys_dma_base + data_reg * mcbsp->pdata->reg_step; |
Kishon Vijay Abraham I | 9504ba6 | 2011-02-24 15:16:55 +0530 | [diff] [blame] | 249 | } |
| 250 | EXPORT_SYMBOL(omap_mcbsp_dma_reg_params); |
| 251 | |
Eero Nurkkala | d912fa9 | 2010-02-22 12:21:11 +0000 | [diff] [blame] | 252 | static void omap_st_on(struct omap_mcbsp *mcbsp) |
| 253 | { |
| 254 | unsigned int w; |
| 255 | |
Jarkko Nikula | 1743d14 | 2011-09-26 10:45:44 +0300 | [diff] [blame] | 256 | if (mcbsp->pdata->enable_st_clock) |
| 257 | mcbsp->pdata->enable_st_clock(mcbsp->id, 1); |
Eero Nurkkala | d912fa9 | 2010-02-22 12:21:11 +0000 | [diff] [blame] | 258 | |
| 259 | /* Enable McBSP Sidetone */ |
| 260 | w = MCBSP_READ(mcbsp, SSELCR); |
| 261 | MCBSP_WRITE(mcbsp, SSELCR, w | SIDETONEEN); |
| 262 | |
Eero Nurkkala | d912fa9 | 2010-02-22 12:21:11 +0000 | [diff] [blame] | 263 | /* Enable Sidetone from Sidetone Core */ |
| 264 | w = MCBSP_ST_READ(mcbsp, SSELCR); |
| 265 | MCBSP_ST_WRITE(mcbsp, SSELCR, w | ST_SIDETONEEN); |
| 266 | } |
| 267 | |
| 268 | static void omap_st_off(struct omap_mcbsp *mcbsp) |
| 269 | { |
| 270 | unsigned int w; |
| 271 | |
| 272 | w = MCBSP_ST_READ(mcbsp, SSELCR); |
| 273 | MCBSP_ST_WRITE(mcbsp, SSELCR, w & ~(ST_SIDETONEEN)); |
| 274 | |
Eero Nurkkala | d912fa9 | 2010-02-22 12:21:11 +0000 | [diff] [blame] | 275 | w = MCBSP_READ(mcbsp, SSELCR); |
| 276 | MCBSP_WRITE(mcbsp, SSELCR, w & ~(SIDETONEEN)); |
| 277 | |
Jarkko Nikula | 1743d14 | 2011-09-26 10:45:44 +0300 | [diff] [blame] | 278 | if (mcbsp->pdata->enable_st_clock) |
| 279 | mcbsp->pdata->enable_st_clock(mcbsp->id, 0); |
Eero Nurkkala | d912fa9 | 2010-02-22 12:21:11 +0000 | [diff] [blame] | 280 | } |
| 281 | |
| 282 | static void omap_st_fir_write(struct omap_mcbsp *mcbsp, s16 *fir) |
| 283 | { |
| 284 | u16 val, i; |
Eero Nurkkala | d912fa9 | 2010-02-22 12:21:11 +0000 | [diff] [blame] | 285 | |
| 286 | val = MCBSP_ST_READ(mcbsp, SSELCR); |
| 287 | |
| 288 | if (val & ST_COEFFWREN) |
| 289 | MCBSP_ST_WRITE(mcbsp, SSELCR, val & ~(ST_COEFFWREN)); |
| 290 | |
| 291 | MCBSP_ST_WRITE(mcbsp, SSELCR, val | ST_COEFFWREN); |
| 292 | |
| 293 | for (i = 0; i < 128; i++) |
| 294 | MCBSP_ST_WRITE(mcbsp, SFIRCR, fir[i]); |
| 295 | |
| 296 | i = 0; |
| 297 | |
| 298 | val = MCBSP_ST_READ(mcbsp, SSELCR); |
| 299 | while (!(val & ST_COEFFWRDONE) && (++i < 1000)) |
| 300 | val = MCBSP_ST_READ(mcbsp, SSELCR); |
| 301 | |
| 302 | MCBSP_ST_WRITE(mcbsp, SSELCR, val & ~(ST_COEFFWREN)); |
| 303 | |
| 304 | if (i == 1000) |
| 305 | dev_err(mcbsp->dev, "McBSP FIR load error!\n"); |
| 306 | } |
| 307 | |
| 308 | static void omap_st_chgain(struct omap_mcbsp *mcbsp) |
| 309 | { |
| 310 | u16 w; |
| 311 | struct omap_mcbsp_st_data *st_data = mcbsp->st_data; |
Eero Nurkkala | d912fa9 | 2010-02-22 12:21:11 +0000 | [diff] [blame] | 312 | |
| 313 | w = MCBSP_ST_READ(mcbsp, SSELCR); |
| 314 | |
| 315 | MCBSP_ST_WRITE(mcbsp, SGAINCR, ST_CH0GAIN(st_data->ch0gain) | \ |
| 316 | ST_CH1GAIN(st_data->ch1gain)); |
| 317 | } |
| 318 | |
| 319 | int omap_st_set_chgain(unsigned int id, int channel, s16 chgain) |
| 320 | { |
| 321 | struct omap_mcbsp *mcbsp; |
| 322 | struct omap_mcbsp_st_data *st_data; |
| 323 | int ret = 0; |
| 324 | |
| 325 | if (!omap_mcbsp_check_valid_id(id)) { |
| 326 | printk(KERN_ERR "%s: Invalid id (%d)\n", __func__, id + 1); |
| 327 | return -ENODEV; |
| 328 | } |
| 329 | |
| 330 | mcbsp = id_to_mcbsp_ptr(id); |
| 331 | st_data = mcbsp->st_data; |
| 332 | |
| 333 | if (!st_data) |
| 334 | return -ENOENT; |
| 335 | |
| 336 | spin_lock_irq(&mcbsp->lock); |
| 337 | if (channel == 0) |
| 338 | st_data->ch0gain = chgain; |
| 339 | else if (channel == 1) |
| 340 | st_data->ch1gain = chgain; |
| 341 | else |
| 342 | ret = -EINVAL; |
| 343 | |
| 344 | if (st_data->enabled) |
| 345 | omap_st_chgain(mcbsp); |
| 346 | spin_unlock_irq(&mcbsp->lock); |
| 347 | |
| 348 | return ret; |
| 349 | } |
| 350 | EXPORT_SYMBOL(omap_st_set_chgain); |
| 351 | |
| 352 | int omap_st_get_chgain(unsigned int id, int channel, s16 *chgain) |
| 353 | { |
| 354 | struct omap_mcbsp *mcbsp; |
| 355 | struct omap_mcbsp_st_data *st_data; |
| 356 | int ret = 0; |
| 357 | |
| 358 | if (!omap_mcbsp_check_valid_id(id)) { |
| 359 | printk(KERN_ERR "%s: Invalid id (%d)\n", __func__, id + 1); |
| 360 | return -ENODEV; |
| 361 | } |
| 362 | |
| 363 | mcbsp = id_to_mcbsp_ptr(id); |
| 364 | st_data = mcbsp->st_data; |
| 365 | |
| 366 | if (!st_data) |
| 367 | return -ENOENT; |
| 368 | |
| 369 | spin_lock_irq(&mcbsp->lock); |
| 370 | if (channel == 0) |
| 371 | *chgain = st_data->ch0gain; |
| 372 | else if (channel == 1) |
| 373 | *chgain = st_data->ch1gain; |
| 374 | else |
| 375 | ret = -EINVAL; |
| 376 | spin_unlock_irq(&mcbsp->lock); |
| 377 | |
| 378 | return ret; |
| 379 | } |
| 380 | EXPORT_SYMBOL(omap_st_get_chgain); |
| 381 | |
| 382 | static int omap_st_start(struct omap_mcbsp *mcbsp) |
| 383 | { |
| 384 | struct omap_mcbsp_st_data *st_data = mcbsp->st_data; |
| 385 | |
| 386 | if (st_data && st_data->enabled && !st_data->running) { |
| 387 | omap_st_fir_write(mcbsp, st_data->taps); |
| 388 | omap_st_chgain(mcbsp); |
| 389 | |
| 390 | if (!mcbsp->free) { |
| 391 | omap_st_on(mcbsp); |
| 392 | st_data->running = 1; |
| 393 | } |
| 394 | } |
| 395 | |
| 396 | return 0; |
| 397 | } |
| 398 | |
| 399 | int omap_st_enable(unsigned int id) |
| 400 | { |
| 401 | struct omap_mcbsp *mcbsp; |
| 402 | struct omap_mcbsp_st_data *st_data; |
| 403 | |
| 404 | if (!omap_mcbsp_check_valid_id(id)) { |
| 405 | printk(KERN_ERR "%s: Invalid id (%d)\n", __func__, id + 1); |
| 406 | return -ENODEV; |
| 407 | } |
| 408 | |
| 409 | mcbsp = id_to_mcbsp_ptr(id); |
| 410 | st_data = mcbsp->st_data; |
| 411 | |
| 412 | if (!st_data) |
| 413 | return -ENODEV; |
| 414 | |
| 415 | spin_lock_irq(&mcbsp->lock); |
| 416 | st_data->enabled = 1; |
| 417 | omap_st_start(mcbsp); |
| 418 | spin_unlock_irq(&mcbsp->lock); |
| 419 | |
| 420 | return 0; |
| 421 | } |
| 422 | EXPORT_SYMBOL(omap_st_enable); |
| 423 | |
| 424 | static int omap_st_stop(struct omap_mcbsp *mcbsp) |
| 425 | { |
| 426 | struct omap_mcbsp_st_data *st_data = mcbsp->st_data; |
| 427 | |
| 428 | if (st_data && st_data->running) { |
| 429 | if (!mcbsp->free) { |
| 430 | omap_st_off(mcbsp); |
| 431 | st_data->running = 0; |
| 432 | } |
| 433 | } |
| 434 | |
| 435 | return 0; |
| 436 | } |
| 437 | |
| 438 | int omap_st_disable(unsigned int id) |
| 439 | { |
| 440 | struct omap_mcbsp *mcbsp; |
| 441 | struct omap_mcbsp_st_data *st_data; |
| 442 | int ret = 0; |
| 443 | |
| 444 | if (!omap_mcbsp_check_valid_id(id)) { |
| 445 | printk(KERN_ERR "%s: Invalid id (%d)\n", __func__, id + 1); |
| 446 | return -ENODEV; |
| 447 | } |
| 448 | |
| 449 | mcbsp = id_to_mcbsp_ptr(id); |
| 450 | st_data = mcbsp->st_data; |
| 451 | |
| 452 | if (!st_data) |
| 453 | return -ENODEV; |
| 454 | |
| 455 | spin_lock_irq(&mcbsp->lock); |
| 456 | omap_st_stop(mcbsp); |
| 457 | st_data->enabled = 0; |
| 458 | spin_unlock_irq(&mcbsp->lock); |
| 459 | |
| 460 | return ret; |
| 461 | } |
| 462 | EXPORT_SYMBOL(omap_st_disable); |
| 463 | |
| 464 | int omap_st_is_enabled(unsigned int id) |
| 465 | { |
| 466 | struct omap_mcbsp *mcbsp; |
| 467 | struct omap_mcbsp_st_data *st_data; |
| 468 | |
| 469 | if (!omap_mcbsp_check_valid_id(id)) { |
| 470 | printk(KERN_ERR "%s: Invalid id (%d)\n", __func__, id + 1); |
| 471 | return -ENODEV; |
| 472 | } |
| 473 | |
| 474 | mcbsp = id_to_mcbsp_ptr(id); |
| 475 | st_data = mcbsp->st_data; |
| 476 | |
| 477 | if (!st_data) |
| 478 | return -ENODEV; |
| 479 | |
| 480 | |
| 481 | return st_data->enabled; |
| 482 | } |
| 483 | EXPORT_SYMBOL(omap_st_is_enabled); |
| 484 | |
Eduardo Valentin | 7aa9ff5 | 2009-08-20 16:18:10 +0300 | [diff] [blame] | 485 | /* |
Peter Ujfalusi | 451fd82 | 2010-06-03 07:39:33 +0300 | [diff] [blame] | 486 | * omap_mcbsp_set_rx_threshold configures the transmit threshold in words. |
| 487 | * The threshold parameter is 1 based, and it is converted (threshold - 1) |
| 488 | * for the THRSH2 register. |
Eduardo Valentin | 7aa9ff5 | 2009-08-20 16:18:10 +0300 | [diff] [blame] | 489 | */ |
| 490 | void omap_mcbsp_set_tx_threshold(unsigned int id, u16 threshold) |
| 491 | { |
| 492 | struct omap_mcbsp *mcbsp; |
Eduardo Valentin | 7aa9ff5 | 2009-08-20 16:18:10 +0300 | [diff] [blame] | 493 | |
Eduardo Valentin | 7aa9ff5 | 2009-08-20 16:18:10 +0300 | [diff] [blame] | 494 | if (!omap_mcbsp_check_valid_id(id)) { |
| 495 | printk(KERN_ERR "%s: Invalid id (%d)\n", __func__, id + 1); |
| 496 | return; |
| 497 | } |
| 498 | mcbsp = id_to_mcbsp_ptr(id); |
Jarkko Nikula | 7bba67a | 2011-09-26 10:45:42 +0300 | [diff] [blame] | 499 | if (mcbsp->pdata->buffer_size == 0) |
| 500 | return; |
Eduardo Valentin | 7aa9ff5 | 2009-08-20 16:18:10 +0300 | [diff] [blame] | 501 | |
Peter Ujfalusi | 451fd82 | 2010-06-03 07:39:33 +0300 | [diff] [blame] | 502 | if (threshold && threshold <= mcbsp->max_tx_thres) |
| 503 | MCBSP_WRITE(mcbsp, THRSH2, threshold - 1); |
Eduardo Valentin | 7aa9ff5 | 2009-08-20 16:18:10 +0300 | [diff] [blame] | 504 | } |
| 505 | EXPORT_SYMBOL(omap_mcbsp_set_tx_threshold); |
| 506 | |
| 507 | /* |
Peter Ujfalusi | 451fd82 | 2010-06-03 07:39:33 +0300 | [diff] [blame] | 508 | * omap_mcbsp_set_rx_threshold configures the receive threshold in words. |
| 509 | * The threshold parameter is 1 based, and it is converted (threshold - 1) |
| 510 | * for the THRSH1 register. |
Eduardo Valentin | 7aa9ff5 | 2009-08-20 16:18:10 +0300 | [diff] [blame] | 511 | */ |
| 512 | void omap_mcbsp_set_rx_threshold(unsigned int id, u16 threshold) |
| 513 | { |
| 514 | struct omap_mcbsp *mcbsp; |
Eduardo Valentin | 7aa9ff5 | 2009-08-20 16:18:10 +0300 | [diff] [blame] | 515 | |
Eduardo Valentin | 7aa9ff5 | 2009-08-20 16:18:10 +0300 | [diff] [blame] | 516 | if (!omap_mcbsp_check_valid_id(id)) { |
| 517 | printk(KERN_ERR "%s: Invalid id (%d)\n", __func__, id + 1); |
| 518 | return; |
| 519 | } |
| 520 | mcbsp = id_to_mcbsp_ptr(id); |
Jarkko Nikula | 7bba67a | 2011-09-26 10:45:42 +0300 | [diff] [blame] | 521 | if (mcbsp->pdata->buffer_size == 0) |
| 522 | return; |
Eduardo Valentin | 7aa9ff5 | 2009-08-20 16:18:10 +0300 | [diff] [blame] | 523 | |
Peter Ujfalusi | 451fd82 | 2010-06-03 07:39:33 +0300 | [diff] [blame] | 524 | if (threshold && threshold <= mcbsp->max_rx_thres) |
| 525 | MCBSP_WRITE(mcbsp, THRSH1, threshold - 1); |
Eduardo Valentin | 7aa9ff5 | 2009-08-20 16:18:10 +0300 | [diff] [blame] | 526 | } |
| 527 | EXPORT_SYMBOL(omap_mcbsp_set_rx_threshold); |
Eduardo Valentin | a1a56f5f | 2009-08-20 16:18:11 +0300 | [diff] [blame] | 528 | |
| 529 | /* |
| 530 | * omap_mcbsp_get_max_tx_thres just return the current configured |
| 531 | * maximum threshold for transmission |
| 532 | */ |
| 533 | u16 omap_mcbsp_get_max_tx_threshold(unsigned int id) |
| 534 | { |
| 535 | struct omap_mcbsp *mcbsp; |
| 536 | |
| 537 | if (!omap_mcbsp_check_valid_id(id)) { |
| 538 | printk(KERN_ERR "%s: Invalid id (%d)\n", __func__, id + 1); |
| 539 | return -ENODEV; |
| 540 | } |
| 541 | mcbsp = id_to_mcbsp_ptr(id); |
| 542 | |
| 543 | return mcbsp->max_tx_thres; |
| 544 | } |
| 545 | EXPORT_SYMBOL(omap_mcbsp_get_max_tx_threshold); |
| 546 | |
| 547 | /* |
| 548 | * omap_mcbsp_get_max_rx_thres just return the current configured |
| 549 | * maximum threshold for reception |
| 550 | */ |
| 551 | u16 omap_mcbsp_get_max_rx_threshold(unsigned int id) |
| 552 | { |
| 553 | struct omap_mcbsp *mcbsp; |
| 554 | |
| 555 | if (!omap_mcbsp_check_valid_id(id)) { |
| 556 | printk(KERN_ERR "%s: Invalid id (%d)\n", __func__, id + 1); |
| 557 | return -ENODEV; |
| 558 | } |
| 559 | mcbsp = id_to_mcbsp_ptr(id); |
| 560 | |
| 561 | return mcbsp->max_rx_thres; |
| 562 | } |
| 563 | EXPORT_SYMBOL(omap_mcbsp_get_max_rx_threshold); |
Peter Ujfalusi | 98cb20e | 2009-08-20 16:18:14 +0300 | [diff] [blame] | 564 | |
Peter Ujfalusi | 0acce82 | 2010-06-03 07:39:32 +0300 | [diff] [blame] | 565 | u16 omap_mcbsp_get_fifo_size(unsigned int id) |
| 566 | { |
| 567 | struct omap_mcbsp *mcbsp; |
| 568 | |
| 569 | if (!omap_mcbsp_check_valid_id(id)) { |
| 570 | printk(KERN_ERR "%s: Invalid id (%d)\n", __func__, id + 1); |
| 571 | return -ENODEV; |
| 572 | } |
| 573 | mcbsp = id_to_mcbsp_ptr(id); |
| 574 | |
| 575 | return mcbsp->pdata->buffer_size; |
| 576 | } |
| 577 | EXPORT_SYMBOL(omap_mcbsp_get_fifo_size); |
| 578 | |
Peter Ujfalusi | 7dc976e | 2010-03-03 15:08:08 +0200 | [diff] [blame] | 579 | /* |
| 580 | * omap_mcbsp_get_tx_delay returns the number of used slots in the McBSP FIFO |
| 581 | */ |
| 582 | u16 omap_mcbsp_get_tx_delay(unsigned int id) |
| 583 | { |
| 584 | struct omap_mcbsp *mcbsp; |
| 585 | u16 buffstat; |
| 586 | |
| 587 | if (!omap_mcbsp_check_valid_id(id)) { |
| 588 | printk(KERN_ERR "%s: Invalid id (%d)\n", __func__, id + 1); |
| 589 | return -ENODEV; |
| 590 | } |
| 591 | mcbsp = id_to_mcbsp_ptr(id); |
Jarkko Nikula | 7bba67a | 2011-09-26 10:45:42 +0300 | [diff] [blame] | 592 | if (mcbsp->pdata->buffer_size == 0) |
| 593 | return 0; |
Peter Ujfalusi | 7dc976e | 2010-03-03 15:08:08 +0200 | [diff] [blame] | 594 | |
| 595 | /* Returns the number of free locations in the buffer */ |
| 596 | buffstat = MCBSP_READ(mcbsp, XBUFFSTAT); |
| 597 | |
| 598 | /* Number of slots are different in McBSP ports */ |
Peter Ujfalusi | f10b8ad | 2010-06-03 07:39:34 +0300 | [diff] [blame] | 599 | return mcbsp->pdata->buffer_size - buffstat; |
Peter Ujfalusi | 7dc976e | 2010-03-03 15:08:08 +0200 | [diff] [blame] | 600 | } |
| 601 | EXPORT_SYMBOL(omap_mcbsp_get_tx_delay); |
| 602 | |
| 603 | /* |
| 604 | * omap_mcbsp_get_rx_delay returns the number of free slots in the McBSP FIFO |
| 605 | * to reach the threshold value (when the DMA will be triggered to read it) |
| 606 | */ |
| 607 | u16 omap_mcbsp_get_rx_delay(unsigned int id) |
| 608 | { |
| 609 | struct omap_mcbsp *mcbsp; |
| 610 | u16 buffstat, threshold; |
| 611 | |
| 612 | if (!omap_mcbsp_check_valid_id(id)) { |
| 613 | printk(KERN_ERR "%s: Invalid id (%d)\n", __func__, id + 1); |
| 614 | return -ENODEV; |
| 615 | } |
| 616 | mcbsp = id_to_mcbsp_ptr(id); |
Jarkko Nikula | 7bba67a | 2011-09-26 10:45:42 +0300 | [diff] [blame] | 617 | if (mcbsp->pdata->buffer_size == 0) |
| 618 | return 0; |
Peter Ujfalusi | 7dc976e | 2010-03-03 15:08:08 +0200 | [diff] [blame] | 619 | |
| 620 | /* Returns the number of used locations in the buffer */ |
| 621 | buffstat = MCBSP_READ(mcbsp, RBUFFSTAT); |
| 622 | /* RX threshold */ |
| 623 | threshold = MCBSP_READ(mcbsp, THRSH1); |
| 624 | |
| 625 | /* Return the number of location till we reach the threshold limit */ |
| 626 | if (threshold <= buffstat) |
| 627 | return 0; |
| 628 | else |
| 629 | return threshold - buffstat; |
| 630 | } |
| 631 | EXPORT_SYMBOL(omap_mcbsp_get_rx_delay); |
| 632 | |
Peter Ujfalusi | 98cb20e | 2009-08-20 16:18:14 +0300 | [diff] [blame] | 633 | /* |
| 634 | * omap_mcbsp_get_dma_op_mode just return the current configured |
| 635 | * operating mode for the mcbsp channel |
| 636 | */ |
| 637 | int omap_mcbsp_get_dma_op_mode(unsigned int id) |
| 638 | { |
| 639 | struct omap_mcbsp *mcbsp; |
| 640 | int dma_op_mode; |
| 641 | |
| 642 | if (!omap_mcbsp_check_valid_id(id)) { |
| 643 | printk(KERN_ERR "%s: Invalid id (%u)\n", __func__, id + 1); |
| 644 | return -ENODEV; |
| 645 | } |
| 646 | mcbsp = id_to_mcbsp_ptr(id); |
| 647 | |
Peter Ujfalusi | 98cb20e | 2009-08-20 16:18:14 +0300 | [diff] [blame] | 648 | dma_op_mode = mcbsp->dma_op_mode; |
Peter Ujfalusi | 98cb20e | 2009-08-20 16:18:14 +0300 | [diff] [blame] | 649 | |
| 650 | return dma_op_mode; |
| 651 | } |
| 652 | EXPORT_SYMBOL(omap_mcbsp_get_dma_op_mode); |
Eero Nurkkala | 2122fdc | 2009-08-20 16:18:15 +0300 | [diff] [blame] | 653 | |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 654 | int omap_mcbsp_request(unsigned int id) |
| 655 | { |
Chandra Shekhar | b4b58f5 | 2008-10-08 10:01:39 +0300 | [diff] [blame] | 656 | struct omap_mcbsp *mcbsp; |
Janusz Krzysztofik | c8c9969 | 2010-02-15 10:03:33 -0800 | [diff] [blame] | 657 | void *reg_cache; |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 658 | int err; |
| 659 | |
Eduardo Valentin | bc5d0c8 | 2008-07-03 12:24:39 +0300 | [diff] [blame] | 660 | if (!omap_mcbsp_check_valid_id(id)) { |
| 661 | printk(KERN_ERR "%s: Invalid id (%d)\n", __func__, id + 1); |
| 662 | return -ENODEV; |
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 | mcbsp = id_to_mcbsp_ptr(id); |
Eduardo Valentin | bc5d0c8 | 2008-07-03 12:24:39 +0300 | [diff] [blame] | 665 | |
Jarkko Nikula | ac6747ca | 2011-09-26 10:45:43 +0300 | [diff] [blame] | 666 | reg_cache = kzalloc(mcbsp->reg_cache_size, GFP_KERNEL); |
Janusz Krzysztofik | c8c9969 | 2010-02-15 10:03:33 -0800 | [diff] [blame] | 667 | if (!reg_cache) { |
| 668 | return -ENOMEM; |
| 669 | } |
| 670 | |
Chandra Shekhar | b4b58f5 | 2008-10-08 10:01:39 +0300 | [diff] [blame] | 671 | spin_lock(&mcbsp->lock); |
| 672 | if (!mcbsp->free) { |
| 673 | dev_err(mcbsp->dev, "McBSP%d is currently in use\n", |
| 674 | mcbsp->id); |
Janusz Krzysztofik | c8c9969 | 2010-02-15 10:03:33 -0800 | [diff] [blame] | 675 | err = -EBUSY; |
| 676 | goto err_kfree; |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 677 | } |
| 678 | |
Shubhrajyoti D | 6722a72 | 2010-12-07 16:25:41 -0800 | [diff] [blame] | 679 | mcbsp->free = false; |
Janusz Krzysztofik | c8c9969 | 2010-02-15 10:03:33 -0800 | [diff] [blame] | 680 | mcbsp->reg_cache = reg_cache; |
Chandra Shekhar | b4b58f5 | 2008-10-08 10:01:39 +0300 | [diff] [blame] | 681 | spin_unlock(&mcbsp->lock); |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 682 | |
Russell King | b820ce4 | 2009-01-23 10:26:46 +0000 | [diff] [blame] | 683 | if (mcbsp->pdata && mcbsp->pdata->ops && mcbsp->pdata->ops->request) |
| 684 | mcbsp->pdata->ops->request(id); |
| 685 | |
Kishon Vijay Abraham I | e95496d | 2011-02-24 15:16:54 +0530 | [diff] [blame] | 686 | pm_runtime_get_sync(mcbsp->dev); |
Russell King | b820ce4 | 2009-01-23 10:26:46 +0000 | [diff] [blame] | 687 | |
Jarkko Nikula | 1a64588 | 2011-09-26 10:45:40 +0300 | [diff] [blame] | 688 | /* Enable wakeup behavior */ |
| 689 | if (mcbsp->pdata->has_wakeup) |
| 690 | MCBSP_WRITE(mcbsp, WAKEUPEN, XRDYEN | RRDYEN); |
Eero Nurkkala | 2122fdc | 2009-08-20 16:18:15 +0300 | [diff] [blame] | 691 | |
Jarkko Nikula | 5a07055 | 2008-10-08 10:01:41 +0300 | [diff] [blame] | 692 | /* |
| 693 | * Make sure that transmitter, receiver and sample-rate generator are |
| 694 | * not running before activating IRQs. |
| 695 | */ |
Janusz Krzysztofik | 8ea3200 | 2010-02-15 10:03:32 -0800 | [diff] [blame] | 696 | MCBSP_WRITE(mcbsp, SPCR1, 0); |
| 697 | MCBSP_WRITE(mcbsp, SPCR2, 0); |
Jarkko Nikula | 5a07055 | 2008-10-08 10:01:41 +0300 | [diff] [blame] | 698 | |
Jarkko Nikula | bafe272 | 2011-06-14 11:23:52 +0000 | [diff] [blame] | 699 | err = request_irq(mcbsp->tx_irq, omap_mcbsp_tx_irq_handler, |
| 700 | 0, "McBSP", (void *)mcbsp); |
| 701 | if (err != 0) { |
| 702 | dev_err(mcbsp->dev, "Unable to request TX IRQ %d " |
| 703 | "for McBSP%d\n", mcbsp->tx_irq, |
| 704 | mcbsp->id); |
| 705 | goto err_clk_disable; |
| 706 | } |
Tony Lindgren | 120db2c | 2006-04-02 17:46:27 +0100 | [diff] [blame] | 707 | |
Jarkko Nikula | bafe272 | 2011-06-14 11:23:52 +0000 | [diff] [blame] | 708 | if (mcbsp->rx_irq) { |
| 709 | err = request_irq(mcbsp->rx_irq, |
| 710 | omap_mcbsp_rx_irq_handler, |
| 711 | 0, "McBSP", (void *)mcbsp); |
| 712 | if (err != 0) { |
| 713 | dev_err(mcbsp->dev, "Unable to request RX IRQ %d " |
| 714 | "for McBSP%d\n", mcbsp->rx_irq, |
| 715 | mcbsp->id); |
| 716 | goto err_free_irq; |
Tony Lindgren | 120db2c | 2006-04-02 17:46:27 +0100 | [diff] [blame] | 717 | } |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 718 | } |
| 719 | |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 720 | return 0; |
Janusz Krzysztofik | c8c9969 | 2010-02-15 10:03:33 -0800 | [diff] [blame] | 721 | err_free_irq: |
Janusz Krzysztofik | 1866b54 | 2010-01-08 10:29:04 -0800 | [diff] [blame] | 722 | free_irq(mcbsp->tx_irq, (void *)mcbsp); |
Janusz Krzysztofik | c8c9969 | 2010-02-15 10:03:33 -0800 | [diff] [blame] | 723 | err_clk_disable: |
Janusz Krzysztofik | 1866b54 | 2010-01-08 10:29:04 -0800 | [diff] [blame] | 724 | if (mcbsp->pdata && mcbsp->pdata->ops && mcbsp->pdata->ops->free) |
Janusz Krzysztofik | c8c9969 | 2010-02-15 10:03:33 -0800 | [diff] [blame] | 725 | mcbsp->pdata->ops->free(id); |
Janusz Krzysztofik | 1866b54 | 2010-01-08 10:29:04 -0800 | [diff] [blame] | 726 | |
Jarkko Nikula | 1a64588 | 2011-09-26 10:45:40 +0300 | [diff] [blame] | 727 | /* Disable wakeup behavior */ |
| 728 | if (mcbsp->pdata->has_wakeup) |
| 729 | MCBSP_WRITE(mcbsp, WAKEUPEN, 0); |
Janusz Krzysztofik | 1866b54 | 2010-01-08 10:29:04 -0800 | [diff] [blame] | 730 | |
Kishon Vijay Abraham I | e95496d | 2011-02-24 15:16:54 +0530 | [diff] [blame] | 731 | pm_runtime_put_sync(mcbsp->dev); |
Janusz Krzysztofik | 1866b54 | 2010-01-08 10:29:04 -0800 | [diff] [blame] | 732 | |
Janusz Krzysztofik | c8c9969 | 2010-02-15 10:03:33 -0800 | [diff] [blame] | 733 | spin_lock(&mcbsp->lock); |
Shubhrajyoti D | 6722a72 | 2010-12-07 16:25:41 -0800 | [diff] [blame] | 734 | mcbsp->free = true; |
Janusz Krzysztofik | c8c9969 | 2010-02-15 10:03:33 -0800 | [diff] [blame] | 735 | mcbsp->reg_cache = NULL; |
| 736 | err_kfree: |
| 737 | spin_unlock(&mcbsp->lock); |
| 738 | kfree(reg_cache); |
Janusz Krzysztofik | 1866b54 | 2010-01-08 10:29:04 -0800 | [diff] [blame] | 739 | |
| 740 | return err; |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 741 | } |
Eduardo Valentin | fb78d80 | 2008-07-03 12:24:39 +0300 | [diff] [blame] | 742 | EXPORT_SYMBOL(omap_mcbsp_request); |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 743 | |
| 744 | void omap_mcbsp_free(unsigned int id) |
| 745 | { |
Chandra Shekhar | b4b58f5 | 2008-10-08 10:01:39 +0300 | [diff] [blame] | 746 | struct omap_mcbsp *mcbsp; |
Janusz Krzysztofik | c8c9969 | 2010-02-15 10:03:33 -0800 | [diff] [blame] | 747 | void *reg_cache; |
Chandra Shekhar | b4b58f5 | 2008-10-08 10:01:39 +0300 | [diff] [blame] | 748 | |
Eduardo Valentin | bc5d0c8 | 2008-07-03 12:24:39 +0300 | [diff] [blame] | 749 | if (!omap_mcbsp_check_valid_id(id)) { |
| 750 | printk(KERN_ERR "%s: Invalid id (%d)\n", __func__, id + 1); |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 751 | return; |
Tony Lindgren | 120db2c | 2006-04-02 17:46:27 +0100 | [diff] [blame] | 752 | } |
Chandra Shekhar | b4b58f5 | 2008-10-08 10:01:39 +0300 | [diff] [blame] | 753 | mcbsp = id_to_mcbsp_ptr(id); |
Tony Lindgren | 120db2c | 2006-04-02 17:46:27 +0100 | [diff] [blame] | 754 | |
Chandra Shekhar | b4b58f5 | 2008-10-08 10:01:39 +0300 | [diff] [blame] | 755 | if (mcbsp->pdata && mcbsp->pdata->ops && mcbsp->pdata->ops->free) |
| 756 | mcbsp->pdata->ops->free(id); |
Eduardo Valentin | bc5d0c8 | 2008-07-03 12:24:39 +0300 | [diff] [blame] | 757 | |
Jarkko Nikula | 1a64588 | 2011-09-26 10:45:40 +0300 | [diff] [blame] | 758 | /* Disable wakeup behavior */ |
| 759 | if (mcbsp->pdata->has_wakeup) |
| 760 | MCBSP_WRITE(mcbsp, WAKEUPEN, 0); |
Eero Nurkkala | 2122fdc | 2009-08-20 16:18:15 +0300 | [diff] [blame] | 761 | |
Kishon Vijay Abraham I | e95496d | 2011-02-24 15:16:54 +0530 | [diff] [blame] | 762 | pm_runtime_put_sync(mcbsp->dev); |
Russell King | b820ce4 | 2009-01-23 10:26:46 +0000 | [diff] [blame] | 763 | |
Jarkko Nikula | bafe272 | 2011-06-14 11:23:52 +0000 | [diff] [blame] | 764 | if (mcbsp->rx_irq) |
| 765 | free_irq(mcbsp->rx_irq, (void *)mcbsp); |
| 766 | free_irq(mcbsp->tx_irq, (void *)mcbsp); |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 767 | |
Janusz Krzysztofik | c8c9969 | 2010-02-15 10:03:33 -0800 | [diff] [blame] | 768 | reg_cache = mcbsp->reg_cache; |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 769 | |
Janusz Krzysztofik | c8c9969 | 2010-02-15 10:03:33 -0800 | [diff] [blame] | 770 | spin_lock(&mcbsp->lock); |
| 771 | if (mcbsp->free) |
| 772 | dev_err(mcbsp->dev, "McBSP%d was not reserved\n", mcbsp->id); |
| 773 | else |
Shubhrajyoti D | 6722a72 | 2010-12-07 16:25:41 -0800 | [diff] [blame] | 774 | mcbsp->free = true; |
Janusz Krzysztofik | c8c9969 | 2010-02-15 10:03:33 -0800 | [diff] [blame] | 775 | mcbsp->reg_cache = NULL; |
Chandra Shekhar | b4b58f5 | 2008-10-08 10:01:39 +0300 | [diff] [blame] | 776 | spin_unlock(&mcbsp->lock); |
Janusz Krzysztofik | c8c9969 | 2010-02-15 10:03:33 -0800 | [diff] [blame] | 777 | |
| 778 | if (reg_cache) |
| 779 | kfree(reg_cache); |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 780 | } |
Eduardo Valentin | fb78d80 | 2008-07-03 12:24:39 +0300 | [diff] [blame] | 781 | EXPORT_SYMBOL(omap_mcbsp_free); |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 782 | |
| 783 | /* |
Jarkko Nikula | c12abc0 | 2009-08-07 09:59:47 +0300 | [diff] [blame] | 784 | * Here we start the McBSP, by enabling transmitter, receiver or both. |
| 785 | * If no transmitter or receiver is active prior calling, then sample-rate |
| 786 | * generator and frame sync are started. |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 787 | */ |
Jarkko Nikula | c12abc0 | 2009-08-07 09:59:47 +0300 | [diff] [blame] | 788 | void omap_mcbsp_start(unsigned int id, int tx, int rx) |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 789 | { |
Chandra Shekhar | b4b58f5 | 2008-10-08 10:01:39 +0300 | [diff] [blame] | 790 | struct omap_mcbsp *mcbsp; |
Peter Ujfalusi | ce3f054 | 2010-08-31 08:11:44 +0000 | [diff] [blame] | 791 | int enable_srg = 0; |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 792 | u16 w; |
| 793 | |
Eduardo Valentin | bc5d0c8 | 2008-07-03 12:24:39 +0300 | [diff] [blame] | 794 | if (!omap_mcbsp_check_valid_id(id)) { |
| 795 | printk(KERN_ERR "%s: Invalid id (%d)\n", __func__, id + 1); |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 796 | return; |
Eduardo Valentin | bc5d0c8 | 2008-07-03 12:24:39 +0300 | [diff] [blame] | 797 | } |
Chandra Shekhar | b4b58f5 | 2008-10-08 10:01:39 +0300 | [diff] [blame] | 798 | mcbsp = id_to_mcbsp_ptr(id); |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 799 | |
Jarkko Nikula | f821eec | 2011-09-26 10:45:45 +0300 | [diff] [blame] | 800 | if (mcbsp->st_data) |
Eero Nurkkala | d912fa9 | 2010-02-22 12:21:11 +0000 | [diff] [blame] | 801 | omap_st_start(mcbsp); |
| 802 | |
Peter Ujfalusi | ce3f054 | 2010-08-31 08:11:44 +0000 | [diff] [blame] | 803 | /* Only enable SRG, if McBSP is master */ |
| 804 | w = MCBSP_READ_CACHE(mcbsp, PCR0); |
| 805 | if (w & (FSXM | FSRM | CLKXM | CLKRM)) |
| 806 | enable_srg = !((MCBSP_READ_CACHE(mcbsp, SPCR2) | |
| 807 | MCBSP_READ_CACHE(mcbsp, SPCR1)) & 1); |
Jarkko Nikula | c12abc0 | 2009-08-07 09:59:47 +0300 | [diff] [blame] | 808 | |
Peter Ujfalusi | ce3f054 | 2010-08-31 08:11:44 +0000 | [diff] [blame] | 809 | if (enable_srg) { |
Jarkko Nikula | c12abc0 | 2009-08-07 09:59:47 +0300 | [diff] [blame] | 810 | /* Start the sample generator */ |
Janusz Krzysztofik | 96fbd74 | 2010-02-15 10:03:33 -0800 | [diff] [blame] | 811 | w = MCBSP_READ_CACHE(mcbsp, SPCR2); |
Janusz Krzysztofik | 8ea3200 | 2010-02-15 10:03:32 -0800 | [diff] [blame] | 812 | MCBSP_WRITE(mcbsp, SPCR2, w | (1 << 6)); |
Jarkko Nikula | c12abc0 | 2009-08-07 09:59:47 +0300 | [diff] [blame] | 813 | } |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 814 | |
| 815 | /* Enable transmitter and receiver */ |
Jarkko Nikula | d09a2af | 2009-08-23 12:24:27 +0300 | [diff] [blame] | 816 | tx &= 1; |
Janusz Krzysztofik | 96fbd74 | 2010-02-15 10:03:33 -0800 | [diff] [blame] | 817 | w = MCBSP_READ_CACHE(mcbsp, SPCR2); |
Janusz Krzysztofik | 8ea3200 | 2010-02-15 10:03:32 -0800 | [diff] [blame] | 818 | MCBSP_WRITE(mcbsp, SPCR2, w | tx); |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 819 | |
Jarkko Nikula | d09a2af | 2009-08-23 12:24:27 +0300 | [diff] [blame] | 820 | rx &= 1; |
Janusz Krzysztofik | 96fbd74 | 2010-02-15 10:03:33 -0800 | [diff] [blame] | 821 | w = MCBSP_READ_CACHE(mcbsp, SPCR1); |
Janusz Krzysztofik | 8ea3200 | 2010-02-15 10:03:32 -0800 | [diff] [blame] | 822 | MCBSP_WRITE(mcbsp, SPCR1, w | rx); |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 823 | |
Eduardo Valentin | 44a6311 | 2009-08-20 16:18:09 +0300 | [diff] [blame] | 824 | /* |
| 825 | * Worst case: CLKSRG*2 = 8000khz: (1/8000) * 2 * 2 usec |
| 826 | * REVISIT: 100us may give enough time for two CLKSRG, however |
| 827 | * due to some unknown PM related, clock gating etc. reason it |
| 828 | * is now at 500us. |
| 829 | */ |
| 830 | udelay(500); |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 831 | |
Peter Ujfalusi | ce3f054 | 2010-08-31 08:11:44 +0000 | [diff] [blame] | 832 | if (enable_srg) { |
Jarkko Nikula | c12abc0 | 2009-08-07 09:59:47 +0300 | [diff] [blame] | 833 | /* Start frame sync */ |
Janusz Krzysztofik | 96fbd74 | 2010-02-15 10:03:33 -0800 | [diff] [blame] | 834 | w = MCBSP_READ_CACHE(mcbsp, SPCR2); |
Janusz Krzysztofik | 8ea3200 | 2010-02-15 10:03:32 -0800 | [diff] [blame] | 835 | MCBSP_WRITE(mcbsp, SPCR2, w | (1 << 7)); |
Jarkko Nikula | c12abc0 | 2009-08-07 09:59:47 +0300 | [diff] [blame] | 836 | } |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 837 | |
Jarkko Nikula | 8840823 | 2011-09-26 10:45:41 +0300 | [diff] [blame] | 838 | if (mcbsp->pdata->has_ccr) { |
Jarkko Nikula | d09a2af | 2009-08-23 12:24:27 +0300 | [diff] [blame] | 839 | /* Release the transmitter and receiver */ |
Janusz Krzysztofik | 96fbd74 | 2010-02-15 10:03:33 -0800 | [diff] [blame] | 840 | w = MCBSP_READ_CACHE(mcbsp, XCCR); |
Jarkko Nikula | d09a2af | 2009-08-23 12:24:27 +0300 | [diff] [blame] | 841 | w &= ~(tx ? XDISABLE : 0); |
Janusz Krzysztofik | 8ea3200 | 2010-02-15 10:03:32 -0800 | [diff] [blame] | 842 | MCBSP_WRITE(mcbsp, XCCR, w); |
Janusz Krzysztofik | 96fbd74 | 2010-02-15 10:03:33 -0800 | [diff] [blame] | 843 | w = MCBSP_READ_CACHE(mcbsp, RCCR); |
Jarkko Nikula | d09a2af | 2009-08-23 12:24:27 +0300 | [diff] [blame] | 844 | w &= ~(rx ? RDISABLE : 0); |
Janusz Krzysztofik | 8ea3200 | 2010-02-15 10:03:32 -0800 | [diff] [blame] | 845 | MCBSP_WRITE(mcbsp, RCCR, w); |
Jarkko Nikula | d09a2af | 2009-08-23 12:24:27 +0300 | [diff] [blame] | 846 | } |
| 847 | |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 848 | /* Dump McBSP Regs */ |
| 849 | omap_mcbsp_dump_reg(id); |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 850 | } |
Eduardo Valentin | fb78d80 | 2008-07-03 12:24:39 +0300 | [diff] [blame] | 851 | EXPORT_SYMBOL(omap_mcbsp_start); |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 852 | |
Jarkko Nikula | c12abc0 | 2009-08-07 09:59:47 +0300 | [diff] [blame] | 853 | void omap_mcbsp_stop(unsigned int id, int tx, int rx) |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 854 | { |
Chandra Shekhar | b4b58f5 | 2008-10-08 10:01:39 +0300 | [diff] [blame] | 855 | struct omap_mcbsp *mcbsp; |
Jarkko Nikula | c12abc0 | 2009-08-07 09:59:47 +0300 | [diff] [blame] | 856 | int idle; |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 857 | u16 w; |
| 858 | |
Eduardo Valentin | bc5d0c8 | 2008-07-03 12:24:39 +0300 | [diff] [blame] | 859 | if (!omap_mcbsp_check_valid_id(id)) { |
| 860 | printk(KERN_ERR "%s: Invalid id (%d)\n", __func__, id + 1); |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 861 | return; |
Eduardo Valentin | bc5d0c8 | 2008-07-03 12:24:39 +0300 | [diff] [blame] | 862 | } |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 863 | |
Chandra Shekhar | b4b58f5 | 2008-10-08 10:01:39 +0300 | [diff] [blame] | 864 | mcbsp = id_to_mcbsp_ptr(id); |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 865 | |
Eduardo Valentin | fb78d80 | 2008-07-03 12:24:39 +0300 | [diff] [blame] | 866 | /* Reset transmitter */ |
Jarkko Nikula | d09a2af | 2009-08-23 12:24:27 +0300 | [diff] [blame] | 867 | tx &= 1; |
Jarkko Nikula | 8840823 | 2011-09-26 10:45:41 +0300 | [diff] [blame] | 868 | if (mcbsp->pdata->has_ccr) { |
Janusz Krzysztofik | 96fbd74 | 2010-02-15 10:03:33 -0800 | [diff] [blame] | 869 | w = MCBSP_READ_CACHE(mcbsp, XCCR); |
Jarkko Nikula | d09a2af | 2009-08-23 12:24:27 +0300 | [diff] [blame] | 870 | w |= (tx ? XDISABLE : 0); |
Janusz Krzysztofik | 8ea3200 | 2010-02-15 10:03:32 -0800 | [diff] [blame] | 871 | MCBSP_WRITE(mcbsp, XCCR, w); |
Jarkko Nikula | d09a2af | 2009-08-23 12:24:27 +0300 | [diff] [blame] | 872 | } |
Janusz Krzysztofik | 96fbd74 | 2010-02-15 10:03:33 -0800 | [diff] [blame] | 873 | w = MCBSP_READ_CACHE(mcbsp, SPCR2); |
Janusz Krzysztofik | 8ea3200 | 2010-02-15 10:03:32 -0800 | [diff] [blame] | 874 | MCBSP_WRITE(mcbsp, SPCR2, w & ~tx); |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 875 | |
| 876 | /* Reset receiver */ |
Jarkko Nikula | d09a2af | 2009-08-23 12:24:27 +0300 | [diff] [blame] | 877 | rx &= 1; |
Jarkko Nikula | 8840823 | 2011-09-26 10:45:41 +0300 | [diff] [blame] | 878 | if (mcbsp->pdata->has_ccr) { |
Janusz Krzysztofik | 96fbd74 | 2010-02-15 10:03:33 -0800 | [diff] [blame] | 879 | w = MCBSP_READ_CACHE(mcbsp, RCCR); |
Jarkko Nikula | a93d4ed | 2009-10-14 09:56:35 -0700 | [diff] [blame] | 880 | w |= (rx ? RDISABLE : 0); |
Janusz Krzysztofik | 8ea3200 | 2010-02-15 10:03:32 -0800 | [diff] [blame] | 881 | MCBSP_WRITE(mcbsp, RCCR, w); |
Jarkko Nikula | d09a2af | 2009-08-23 12:24:27 +0300 | [diff] [blame] | 882 | } |
Janusz Krzysztofik | 96fbd74 | 2010-02-15 10:03:33 -0800 | [diff] [blame] | 883 | w = MCBSP_READ_CACHE(mcbsp, SPCR1); |
Janusz Krzysztofik | 8ea3200 | 2010-02-15 10:03:32 -0800 | [diff] [blame] | 884 | MCBSP_WRITE(mcbsp, SPCR1, w & ~rx); |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 885 | |
Janusz Krzysztofik | 96fbd74 | 2010-02-15 10:03:33 -0800 | [diff] [blame] | 886 | idle = !((MCBSP_READ_CACHE(mcbsp, SPCR2) | |
| 887 | MCBSP_READ_CACHE(mcbsp, SPCR1)) & 1); |
Jarkko Nikula | c12abc0 | 2009-08-07 09:59:47 +0300 | [diff] [blame] | 888 | |
| 889 | if (idle) { |
| 890 | /* Reset the sample rate generator */ |
Janusz Krzysztofik | 96fbd74 | 2010-02-15 10:03:33 -0800 | [diff] [blame] | 891 | w = MCBSP_READ_CACHE(mcbsp, SPCR2); |
Janusz Krzysztofik | 8ea3200 | 2010-02-15 10:03:32 -0800 | [diff] [blame] | 892 | MCBSP_WRITE(mcbsp, SPCR2, w & ~(1 << 6)); |
Jarkko Nikula | c12abc0 | 2009-08-07 09:59:47 +0300 | [diff] [blame] | 893 | } |
Eero Nurkkala | d912fa9 | 2010-02-22 12:21:11 +0000 | [diff] [blame] | 894 | |
Jarkko Nikula | f821eec | 2011-09-26 10:45:45 +0300 | [diff] [blame] | 895 | if (mcbsp->st_data) |
Eero Nurkkala | d912fa9 | 2010-02-22 12:21:11 +0000 | [diff] [blame] | 896 | omap_st_stop(mcbsp); |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 897 | } |
Eduardo Valentin | fb78d80 | 2008-07-03 12:24:39 +0300 | [diff] [blame] | 898 | EXPORT_SYMBOL(omap_mcbsp_stop); |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 899 | |
Paul Walmsley | 69d042d | 2011-07-01 08:52:25 +0000 | [diff] [blame] | 900 | int omap2_mcbsp_set_clks_src(u8 id, u8 fck_src_id) |
| 901 | { |
Jarkko Nikula | 09d28d2 | 2011-09-26 10:45:48 +0300 | [diff] [blame] | 902 | struct omap_mcbsp *mcbsp; |
| 903 | const char *src; |
Paul Walmsley | 69d042d | 2011-07-01 08:52:25 +0000 | [diff] [blame] | 904 | |
Jarkko Nikula | 09d28d2 | 2011-09-26 10:45:48 +0300 | [diff] [blame] | 905 | if (!omap_mcbsp_check_valid_id(id)) { |
| 906 | pr_err("%s: Invalid id (%d)\n", __func__, id + 1); |
| 907 | return -EINVAL; |
| 908 | } |
| 909 | mcbsp = id_to_mcbsp_ptr(id); |
| 910 | |
| 911 | if (fck_src_id == MCBSP_CLKS_PAD_SRC) |
| 912 | src = "clks_ext"; |
| 913 | else if (fck_src_id == MCBSP_CLKS_PRCM_SRC) |
| 914 | src = "clks_fclk"; |
| 915 | else |
| 916 | return -EINVAL; |
| 917 | |
| 918 | if (mcbsp->pdata->set_clk_src) |
| 919 | return mcbsp->pdata->set_clk_src(mcbsp->dev, mcbsp->fclk, src); |
| 920 | else |
| 921 | return -EINVAL; |
| 922 | } |
| 923 | EXPORT_SYMBOL(omap2_mcbsp_set_clks_src); |
| 924 | |
Paul Walmsley | 69d042d | 2011-07-01 08:52:25 +0000 | [diff] [blame] | 925 | void omap2_mcbsp1_mux_clkr_src(u8 mux) |
| 926 | { |
Jarkko Nikula | 7bc0c4b | 2011-09-26 10:45:49 +0300 | [diff] [blame] | 927 | struct omap_mcbsp *mcbsp; |
| 928 | const char *src; |
| 929 | |
| 930 | if (mux == CLKR_SRC_CLKR) |
| 931 | src = "clkr"; |
| 932 | else if (mux == CLKR_SRC_CLKX) |
| 933 | src = "clkx"; |
| 934 | else |
| 935 | return; |
| 936 | |
| 937 | mcbsp = id_to_mcbsp_ptr(0); |
| 938 | if (mcbsp->pdata->mux_signal) |
| 939 | mcbsp->pdata->mux_signal(mcbsp->dev, "clkr", src); |
Paul Walmsley | 69d042d | 2011-07-01 08:52:25 +0000 | [diff] [blame] | 940 | } |
Jarkko Nikula | 7bc0c4b | 2011-09-26 10:45:49 +0300 | [diff] [blame] | 941 | EXPORT_SYMBOL(omap2_mcbsp1_mux_clkr_src); |
Paul Walmsley | 69d042d | 2011-07-01 08:52:25 +0000 | [diff] [blame] | 942 | |
| 943 | void omap2_mcbsp1_mux_fsr_src(u8 mux) |
| 944 | { |
Jarkko Nikula | 7bc0c4b | 2011-09-26 10:45:49 +0300 | [diff] [blame] | 945 | struct omap_mcbsp *mcbsp; |
| 946 | const char *src; |
| 947 | |
| 948 | if (mux == FSR_SRC_FSR) |
| 949 | src = "fsr"; |
| 950 | else if (mux == FSR_SRC_FSX) |
| 951 | src = "fsx"; |
| 952 | else |
| 953 | return; |
| 954 | |
| 955 | mcbsp = id_to_mcbsp_ptr(0); |
| 956 | if (mcbsp->pdata->mux_signal) |
| 957 | mcbsp->pdata->mux_signal(mcbsp->dev, "fsr", src); |
Paul Walmsley | 69d042d | 2011-07-01 08:52:25 +0000 | [diff] [blame] | 958 | } |
Jarkko Nikula | 7bc0c4b | 2011-09-26 10:45:49 +0300 | [diff] [blame] | 959 | EXPORT_SYMBOL(omap2_mcbsp1_mux_fsr_src); |
Paul Walmsley | 69d042d | 2011-07-01 08:52:25 +0000 | [diff] [blame] | 960 | |
Eduardo Valentin | a1a56f5f | 2009-08-20 16:18:11 +0300 | [diff] [blame] | 961 | #define max_thres(m) (mcbsp->pdata->buffer_size) |
| 962 | #define valid_threshold(m, val) ((val) <= max_thres(m)) |
| 963 | #define THRESHOLD_PROP_BUILDER(prop) \ |
| 964 | static ssize_t prop##_show(struct device *dev, \ |
| 965 | struct device_attribute *attr, char *buf) \ |
| 966 | { \ |
| 967 | struct omap_mcbsp *mcbsp = dev_get_drvdata(dev); \ |
| 968 | \ |
| 969 | return sprintf(buf, "%u\n", mcbsp->prop); \ |
| 970 | } \ |
| 971 | \ |
| 972 | static ssize_t prop##_store(struct device *dev, \ |
| 973 | struct device_attribute *attr, \ |
| 974 | const char *buf, size_t size) \ |
| 975 | { \ |
| 976 | struct omap_mcbsp *mcbsp = dev_get_drvdata(dev); \ |
| 977 | unsigned long val; \ |
| 978 | int status; \ |
| 979 | \ |
| 980 | status = strict_strtoul(buf, 0, &val); \ |
| 981 | if (status) \ |
| 982 | return status; \ |
| 983 | \ |
| 984 | if (!valid_threshold(mcbsp, val)) \ |
| 985 | return -EDOM; \ |
| 986 | \ |
| 987 | mcbsp->prop = val; \ |
| 988 | return size; \ |
| 989 | } \ |
| 990 | \ |
| 991 | static DEVICE_ATTR(prop, 0644, prop##_show, prop##_store); |
| 992 | |
| 993 | THRESHOLD_PROP_BUILDER(max_tx_thres); |
| 994 | THRESHOLD_PROP_BUILDER(max_rx_thres); |
| 995 | |
Jarkko Nikula | 9b30050 | 2009-08-24 17:45:50 +0300 | [diff] [blame] | 996 | static const char *dma_op_modes[] = { |
| 997 | "element", "threshold", "frame", |
| 998 | }; |
| 999 | |
Peter Ujfalusi | 98cb20e | 2009-08-20 16:18:14 +0300 | [diff] [blame] | 1000 | static ssize_t dma_op_mode_show(struct device *dev, |
| 1001 | struct device_attribute *attr, char *buf) |
| 1002 | { |
| 1003 | struct omap_mcbsp *mcbsp = dev_get_drvdata(dev); |
Jarkko Nikula | 9b30050 | 2009-08-24 17:45:50 +0300 | [diff] [blame] | 1004 | int dma_op_mode, i = 0; |
| 1005 | ssize_t len = 0; |
| 1006 | const char * const *s; |
Peter Ujfalusi | 98cb20e | 2009-08-20 16:18:14 +0300 | [diff] [blame] | 1007 | |
Peter Ujfalusi | 98cb20e | 2009-08-20 16:18:14 +0300 | [diff] [blame] | 1008 | dma_op_mode = mcbsp->dma_op_mode; |
Peter Ujfalusi | 98cb20e | 2009-08-20 16:18:14 +0300 | [diff] [blame] | 1009 | |
Jarkko Nikula | 9b30050 | 2009-08-24 17:45:50 +0300 | [diff] [blame] | 1010 | for (s = &dma_op_modes[i]; i < ARRAY_SIZE(dma_op_modes); s++, i++) { |
| 1011 | if (dma_op_mode == i) |
| 1012 | len += sprintf(buf + len, "[%s] ", *s); |
| 1013 | else |
| 1014 | len += sprintf(buf + len, "%s ", *s); |
| 1015 | } |
| 1016 | len += sprintf(buf + len, "\n"); |
| 1017 | |
| 1018 | return len; |
Peter Ujfalusi | 98cb20e | 2009-08-20 16:18:14 +0300 | [diff] [blame] | 1019 | } |
| 1020 | |
| 1021 | static ssize_t dma_op_mode_store(struct device *dev, |
| 1022 | struct device_attribute *attr, |
| 1023 | const char *buf, size_t size) |
| 1024 | { |
| 1025 | struct omap_mcbsp *mcbsp = dev_get_drvdata(dev); |
Jarkko Nikula | 9b30050 | 2009-08-24 17:45:50 +0300 | [diff] [blame] | 1026 | const char * const *s; |
| 1027 | int i = 0; |
Peter Ujfalusi | 98cb20e | 2009-08-20 16:18:14 +0300 | [diff] [blame] | 1028 | |
Jarkko Nikula | 9b30050 | 2009-08-24 17:45:50 +0300 | [diff] [blame] | 1029 | for (s = &dma_op_modes[i]; i < ARRAY_SIZE(dma_op_modes); s++, i++) |
| 1030 | if (sysfs_streq(buf, *s)) |
| 1031 | break; |
| 1032 | |
| 1033 | if (i == ARRAY_SIZE(dma_op_modes)) |
| 1034 | return -EINVAL; |
Peter Ujfalusi | 98cb20e | 2009-08-20 16:18:14 +0300 | [diff] [blame] | 1035 | |
| 1036 | spin_lock_irq(&mcbsp->lock); |
Peter Ujfalusi | 98cb20e | 2009-08-20 16:18:14 +0300 | [diff] [blame] | 1037 | if (!mcbsp->free) { |
| 1038 | size = -EBUSY; |
| 1039 | goto unlock; |
| 1040 | } |
Jarkko Nikula | 9b30050 | 2009-08-24 17:45:50 +0300 | [diff] [blame] | 1041 | mcbsp->dma_op_mode = i; |
Peter Ujfalusi | 98cb20e | 2009-08-20 16:18:14 +0300 | [diff] [blame] | 1042 | |
| 1043 | unlock: |
| 1044 | spin_unlock_irq(&mcbsp->lock); |
| 1045 | |
| 1046 | return size; |
| 1047 | } |
| 1048 | |
| 1049 | static DEVICE_ATTR(dma_op_mode, 0644, dma_op_mode_show, dma_op_mode_store); |
| 1050 | |
Jarkko Nikula | 7bba67a | 2011-09-26 10:45:42 +0300 | [diff] [blame] | 1051 | static const struct attribute *additional_attrs[] = { |
| 1052 | &dev_attr_max_tx_thres.attr, |
| 1053 | &dev_attr_max_rx_thres.attr, |
| 1054 | &dev_attr_dma_op_mode.attr, |
| 1055 | NULL, |
| 1056 | }; |
| 1057 | |
| 1058 | static const struct attribute_group additional_attr_group = { |
| 1059 | .attrs = (struct attribute **)additional_attrs, |
| 1060 | }; |
| 1061 | |
Eero Nurkkala | d912fa9 | 2010-02-22 12:21:11 +0000 | [diff] [blame] | 1062 | static ssize_t st_taps_show(struct device *dev, |
| 1063 | struct device_attribute *attr, char *buf) |
| 1064 | { |
| 1065 | struct omap_mcbsp *mcbsp = dev_get_drvdata(dev); |
| 1066 | struct omap_mcbsp_st_data *st_data = mcbsp->st_data; |
| 1067 | ssize_t status = 0; |
| 1068 | int i; |
| 1069 | |
| 1070 | spin_lock_irq(&mcbsp->lock); |
| 1071 | for (i = 0; i < st_data->nr_taps; i++) |
| 1072 | status += sprintf(&buf[status], (i ? ", %d" : "%d"), |
| 1073 | st_data->taps[i]); |
| 1074 | if (i) |
| 1075 | status += sprintf(&buf[status], "\n"); |
| 1076 | spin_unlock_irq(&mcbsp->lock); |
| 1077 | |
| 1078 | return status; |
| 1079 | } |
| 1080 | |
| 1081 | static ssize_t st_taps_store(struct device *dev, |
| 1082 | struct device_attribute *attr, |
| 1083 | const char *buf, size_t size) |
| 1084 | { |
| 1085 | struct omap_mcbsp *mcbsp = dev_get_drvdata(dev); |
| 1086 | struct omap_mcbsp_st_data *st_data = mcbsp->st_data; |
| 1087 | int val, tmp, status, i = 0; |
| 1088 | |
| 1089 | spin_lock_irq(&mcbsp->lock); |
| 1090 | memset(st_data->taps, 0, sizeof(st_data->taps)); |
| 1091 | st_data->nr_taps = 0; |
| 1092 | |
| 1093 | do { |
| 1094 | status = sscanf(buf, "%d%n", &val, &tmp); |
| 1095 | if (status < 0 || status == 0) { |
| 1096 | size = -EINVAL; |
| 1097 | goto out; |
| 1098 | } |
| 1099 | if (val < -32768 || val > 32767) { |
| 1100 | size = -EINVAL; |
| 1101 | goto out; |
| 1102 | } |
| 1103 | st_data->taps[i++] = val; |
| 1104 | buf += tmp; |
| 1105 | if (*buf != ',') |
| 1106 | break; |
| 1107 | buf++; |
| 1108 | } while (1); |
| 1109 | |
| 1110 | st_data->nr_taps = i; |
| 1111 | |
| 1112 | out: |
| 1113 | spin_unlock_irq(&mcbsp->lock); |
| 1114 | |
| 1115 | return size; |
| 1116 | } |
| 1117 | |
| 1118 | static DEVICE_ATTR(st_taps, 0644, st_taps_show, st_taps_store); |
| 1119 | |
Eero Nurkkala | d912fa9 | 2010-02-22 12:21:11 +0000 | [diff] [blame] | 1120 | static const struct attribute *sidetone_attrs[] = { |
| 1121 | &dev_attr_st_taps.attr, |
| 1122 | NULL, |
| 1123 | }; |
| 1124 | |
| 1125 | static const struct attribute_group sidetone_attr_group = { |
| 1126 | .attrs = (struct attribute **)sidetone_attrs, |
| 1127 | }; |
| 1128 | |
Jarkko Nikula | f821eec | 2011-09-26 10:45:45 +0300 | [diff] [blame] | 1129 | static int __devinit omap_st_add(struct omap_mcbsp *mcbsp, |
| 1130 | struct resource *res) |
Eero Nurkkala | d912fa9 | 2010-02-22 12:21:11 +0000 | [diff] [blame] | 1131 | { |
Eero Nurkkala | d912fa9 | 2010-02-22 12:21:11 +0000 | [diff] [blame] | 1132 | struct omap_mcbsp_st_data *st_data; |
| 1133 | int err; |
| 1134 | |
| 1135 | st_data = kzalloc(sizeof(*mcbsp->st_data), GFP_KERNEL); |
| 1136 | if (!st_data) { |
| 1137 | err = -ENOMEM; |
| 1138 | goto err1; |
| 1139 | } |
| 1140 | |
Kishon Vijay Abraham I | 3cf32bb | 2011-02-24 12:51:45 -0800 | [diff] [blame] | 1141 | st_data->io_base_st = ioremap(res->start, resource_size(res)); |
Eero Nurkkala | d912fa9 | 2010-02-22 12:21:11 +0000 | [diff] [blame] | 1142 | if (!st_data->io_base_st) { |
| 1143 | err = -ENOMEM; |
| 1144 | goto err2; |
| 1145 | } |
| 1146 | |
| 1147 | err = sysfs_create_group(&mcbsp->dev->kobj, &sidetone_attr_group); |
| 1148 | if (err) |
| 1149 | goto err3; |
| 1150 | |
| 1151 | mcbsp->st_data = st_data; |
| 1152 | return 0; |
| 1153 | |
| 1154 | err3: |
| 1155 | iounmap(st_data->io_base_st); |
| 1156 | err2: |
| 1157 | kfree(st_data); |
| 1158 | err1: |
| 1159 | return err; |
| 1160 | |
| 1161 | } |
| 1162 | |
| 1163 | static void __devexit omap_st_remove(struct omap_mcbsp *mcbsp) |
| 1164 | { |
| 1165 | struct omap_mcbsp_st_data *st_data = mcbsp->st_data; |
| 1166 | |
Jarkko Nikula | f821eec | 2011-09-26 10:45:45 +0300 | [diff] [blame] | 1167 | sysfs_remove_group(&mcbsp->dev->kobj, &sidetone_attr_group); |
| 1168 | iounmap(st_data->io_base_st); |
| 1169 | kfree(st_data); |
Eero Nurkkala | d912fa9 | 2010-02-22 12:21:11 +0000 | [diff] [blame] | 1170 | } |
| 1171 | |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 1172 | /* |
| 1173 | * McBSP1 and McBSP3 are directly mapped on 1610 and 1510. |
| 1174 | * 730 has only 2 McBSP, and both of them are MPU peripherals. |
| 1175 | */ |
Uwe Kleine-König | 25cef22 | 2008-10-08 10:01:39 +0300 | [diff] [blame] | 1176 | static int __devinit omap_mcbsp_probe(struct platform_device *pdev) |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 1177 | { |
Eduardo Valentin | bc5d0c8 | 2008-07-03 12:24:39 +0300 | [diff] [blame] | 1178 | struct omap_mcbsp_platform_data *pdata = pdev->dev.platform_data; |
Chandra Shekhar | b4b58f5 | 2008-10-08 10:01:39 +0300 | [diff] [blame] | 1179 | struct omap_mcbsp *mcbsp; |
Eduardo Valentin | bc5d0c8 | 2008-07-03 12:24:39 +0300 | [diff] [blame] | 1180 | int id = pdev->id - 1; |
Kishon Vijay Abraham I | 3cf32bb | 2011-02-24 12:51:45 -0800 | [diff] [blame] | 1181 | struct resource *res; |
Eduardo Valentin | bc5d0c8 | 2008-07-03 12:24:39 +0300 | [diff] [blame] | 1182 | int ret = 0; |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 1183 | |
Eduardo Valentin | bc5d0c8 | 2008-07-03 12:24:39 +0300 | [diff] [blame] | 1184 | if (!pdata) { |
| 1185 | dev_err(&pdev->dev, "McBSP device initialized without" |
| 1186 | "platform data\n"); |
| 1187 | ret = -EINVAL; |
| 1188 | goto exit; |
| 1189 | } |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 1190 | |
Eduardo Valentin | bc5d0c8 | 2008-07-03 12:24:39 +0300 | [diff] [blame] | 1191 | dev_dbg(&pdev->dev, "Initializing OMAP McBSP (%d).\n", pdev->id); |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 1192 | |
Chandra Shekhar | b4b58f5 | 2008-10-08 10:01:39 +0300 | [diff] [blame] | 1193 | if (id >= omap_mcbsp_count) { |
Eduardo Valentin | bc5d0c8 | 2008-07-03 12:24:39 +0300 | [diff] [blame] | 1194 | dev_err(&pdev->dev, "Invalid McBSP device id (%d)\n", id); |
| 1195 | ret = -EINVAL; |
| 1196 | goto exit; |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 1197 | } |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 1198 | |
Chandra Shekhar | b4b58f5 | 2008-10-08 10:01:39 +0300 | [diff] [blame] | 1199 | mcbsp = kzalloc(sizeof(struct omap_mcbsp), GFP_KERNEL); |
| 1200 | if (!mcbsp) { |
| 1201 | ret = -ENOMEM; |
| 1202 | goto exit; |
| 1203 | } |
Eduardo Valentin | bc5d0c8 | 2008-07-03 12:24:39 +0300 | [diff] [blame] | 1204 | |
Chandra Shekhar | b4b58f5 | 2008-10-08 10:01:39 +0300 | [diff] [blame] | 1205 | spin_lock_init(&mcbsp->lock); |
| 1206 | mcbsp->id = id + 1; |
Shubhrajyoti D | 6722a72 | 2010-12-07 16:25:41 -0800 | [diff] [blame] | 1207 | mcbsp->free = true; |
Chandra Shekhar | b4b58f5 | 2008-10-08 10:01:39 +0300 | [diff] [blame] | 1208 | |
Kishon Vijay Abraham I | 3cf32bb | 2011-02-24 12:51:45 -0800 | [diff] [blame] | 1209 | res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "mpu"); |
| 1210 | if (!res) { |
| 1211 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
| 1212 | if (!res) { |
| 1213 | dev_err(&pdev->dev, "%s:mcbsp%d has invalid memory" |
| 1214 | "resource\n", __func__, pdev->id); |
| 1215 | ret = -ENOMEM; |
| 1216 | goto exit; |
| 1217 | } |
| 1218 | } |
| 1219 | mcbsp->phys_base = res->start; |
Jarkko Nikula | ac6747ca | 2011-09-26 10:45:43 +0300 | [diff] [blame] | 1220 | mcbsp->reg_cache_size = resource_size(res); |
Kishon Vijay Abraham I | 3cf32bb | 2011-02-24 12:51:45 -0800 | [diff] [blame] | 1221 | mcbsp->io_base = ioremap(res->start, resource_size(res)); |
Chandra Shekhar | b4b58f5 | 2008-10-08 10:01:39 +0300 | [diff] [blame] | 1222 | if (!mcbsp->io_base) { |
Russell King | d592dd1 | 2008-09-04 14:25:42 +0100 | [diff] [blame] | 1223 | ret = -ENOMEM; |
| 1224 | goto err_ioremap; |
| 1225 | } |
| 1226 | |
Kishon Vijay Abraham I | 3cf32bb | 2011-02-24 12:51:45 -0800 | [diff] [blame] | 1227 | res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "dma"); |
| 1228 | if (!res) |
| 1229 | mcbsp->phys_dma_base = mcbsp->phys_base; |
| 1230 | else |
| 1231 | mcbsp->phys_dma_base = res->start; |
| 1232 | |
Kishon Vijay Abraham I | 3cf32bb | 2011-02-24 12:51:45 -0800 | [diff] [blame] | 1233 | mcbsp->tx_irq = platform_get_irq_byname(pdev, "tx"); |
| 1234 | mcbsp->rx_irq = platform_get_irq_byname(pdev, "rx"); |
| 1235 | |
Kishon Vijay Abraham I | cb7e9de | 2011-02-24 15:16:50 +0530 | [diff] [blame] | 1236 | /* From OMAP4 there will be a single irq line */ |
| 1237 | if (mcbsp->tx_irq == -ENXIO) |
| 1238 | mcbsp->tx_irq = platform_get_irq(pdev, 0); |
| 1239 | |
Kishon Vijay Abraham I | 3cf32bb | 2011-02-24 12:51:45 -0800 | [diff] [blame] | 1240 | res = platform_get_resource_byname(pdev, IORESOURCE_DMA, "rx"); |
| 1241 | if (!res) { |
| 1242 | dev_err(&pdev->dev, "%s:mcbsp%d has invalid rx DMA channel\n", |
| 1243 | __func__, pdev->id); |
| 1244 | ret = -ENODEV; |
| 1245 | goto err_res; |
| 1246 | } |
| 1247 | mcbsp->dma_rx_sync = res->start; |
| 1248 | |
| 1249 | res = platform_get_resource_byname(pdev, IORESOURCE_DMA, "tx"); |
| 1250 | if (!res) { |
| 1251 | dev_err(&pdev->dev, "%s:mcbsp%d has invalid tx DMA channel\n", |
| 1252 | __func__, pdev->id); |
| 1253 | ret = -ENODEV; |
| 1254 | goto err_res; |
| 1255 | } |
| 1256 | mcbsp->dma_tx_sync = res->start; |
Eduardo Valentin | bc5d0c8 | 2008-07-03 12:24:39 +0300 | [diff] [blame] | 1257 | |
Russell King | b820ce4 | 2009-01-23 10:26:46 +0000 | [diff] [blame] | 1258 | mcbsp->fclk = clk_get(&pdev->dev, "fck"); |
| 1259 | if (IS_ERR(mcbsp->fclk)) { |
| 1260 | ret = PTR_ERR(mcbsp->fclk); |
| 1261 | dev_err(&pdev->dev, "unable to get fck: %d\n", ret); |
Kishon Vijay Abraham I | e95496d | 2011-02-24 15:16:54 +0530 | [diff] [blame] | 1262 | goto err_res; |
Eduardo Valentin | bc5d0c8 | 2008-07-03 12:24:39 +0300 | [diff] [blame] | 1263 | } |
| 1264 | |
Chandra Shekhar | b4b58f5 | 2008-10-08 10:01:39 +0300 | [diff] [blame] | 1265 | mcbsp->pdata = pdata; |
| 1266 | mcbsp->dev = &pdev->dev; |
Russell King | b820ce4 | 2009-01-23 10:26:46 +0000 | [diff] [blame] | 1267 | mcbsp_ptr[id] = mcbsp; |
Chandra Shekhar | b4b58f5 | 2008-10-08 10:01:39 +0300 | [diff] [blame] | 1268 | platform_set_drvdata(pdev, mcbsp); |
Kishon Vijay Abraham I | e95496d | 2011-02-24 15:16:54 +0530 | [diff] [blame] | 1269 | pm_runtime_enable(mcbsp->dev); |
Eduardo Valentin | a1a56f5f | 2009-08-20 16:18:11 +0300 | [diff] [blame] | 1270 | |
Jarkko Nikula | 7bba67a | 2011-09-26 10:45:42 +0300 | [diff] [blame] | 1271 | mcbsp->dma_op_mode = MCBSP_DMA_MODE_ELEMENT; |
| 1272 | if (mcbsp->pdata->buffer_size) { |
| 1273 | /* |
| 1274 | * Initially configure the maximum thresholds to a safe value. |
| 1275 | * The McBSP FIFO usage with these values should not go under |
| 1276 | * 16 locations. |
| 1277 | * If the whole FIFO without safety buffer is used, than there |
| 1278 | * is a possibility that the DMA will be not able to push the |
| 1279 | * new data on time, causing channel shifts in runtime. |
| 1280 | */ |
| 1281 | mcbsp->max_tx_thres = max_thres(mcbsp) - 0x10; |
| 1282 | mcbsp->max_rx_thres = max_thres(mcbsp) - 0x10; |
| 1283 | |
| 1284 | ret = sysfs_create_group(&mcbsp->dev->kobj, |
| 1285 | &additional_attr_group); |
| 1286 | if (ret) { |
| 1287 | dev_err(mcbsp->dev, |
| 1288 | "Unable to create additional controls\n"); |
| 1289 | goto err_thres; |
| 1290 | } |
| 1291 | } else { |
| 1292 | mcbsp->max_tx_thres = -EINVAL; |
| 1293 | mcbsp->max_rx_thres = -EINVAL; |
| 1294 | } |
| 1295 | |
Jarkko Nikula | f821eec | 2011-09-26 10:45:45 +0300 | [diff] [blame] | 1296 | res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "sidetone"); |
| 1297 | if (res) { |
| 1298 | ret = omap_st_add(mcbsp, res); |
| 1299 | if (ret) { |
| 1300 | dev_err(mcbsp->dev, |
| 1301 | "Unable to create sidetone controls\n"); |
| 1302 | goto err_st; |
| 1303 | } |
| 1304 | } |
Eduardo Valentin | a1a56f5f | 2009-08-20 16:18:11 +0300 | [diff] [blame] | 1305 | |
Russell King | d592dd1 | 2008-09-04 14:25:42 +0100 | [diff] [blame] | 1306 | return 0; |
Eduardo Valentin | bc5d0c8 | 2008-07-03 12:24:39 +0300 | [diff] [blame] | 1307 | |
Jarkko Nikula | f821eec | 2011-09-26 10:45:45 +0300 | [diff] [blame] | 1308 | err_st: |
| 1309 | if (mcbsp->pdata->buffer_size) |
| 1310 | sysfs_remove_group(&mcbsp->dev->kobj, |
| 1311 | &additional_attr_group); |
Jarkko Nikula | 7bba67a | 2011-09-26 10:45:42 +0300 | [diff] [blame] | 1312 | err_thres: |
| 1313 | clk_put(mcbsp->fclk); |
Kishon Vijay Abraham I | 3cf32bb | 2011-02-24 12:51:45 -0800 | [diff] [blame] | 1314 | err_res: |
Chandra Shekhar | b4b58f5 | 2008-10-08 10:01:39 +0300 | [diff] [blame] | 1315 | iounmap(mcbsp->io_base); |
Russell King | d592dd1 | 2008-09-04 14:25:42 +0100 | [diff] [blame] | 1316 | err_ioremap: |
Russell King | b820ce4 | 2009-01-23 10:26:46 +0000 | [diff] [blame] | 1317 | kfree(mcbsp); |
Eduardo Valentin | bc5d0c8 | 2008-07-03 12:24:39 +0300 | [diff] [blame] | 1318 | exit: |
| 1319 | return ret; |
| 1320 | } |
| 1321 | |
Uwe Kleine-König | 25cef22 | 2008-10-08 10:01:39 +0300 | [diff] [blame] | 1322 | static int __devexit omap_mcbsp_remove(struct platform_device *pdev) |
Eduardo Valentin | bc5d0c8 | 2008-07-03 12:24:39 +0300 | [diff] [blame] | 1323 | { |
| 1324 | struct omap_mcbsp *mcbsp = platform_get_drvdata(pdev); |
| 1325 | |
| 1326 | platform_set_drvdata(pdev, NULL); |
| 1327 | if (mcbsp) { |
| 1328 | |
| 1329 | if (mcbsp->pdata && mcbsp->pdata->ops && |
| 1330 | mcbsp->pdata->ops->free) |
| 1331 | mcbsp->pdata->ops->free(mcbsp->id); |
| 1332 | |
Jarkko Nikula | 7bba67a | 2011-09-26 10:45:42 +0300 | [diff] [blame] | 1333 | if (mcbsp->pdata->buffer_size) |
| 1334 | sysfs_remove_group(&mcbsp->dev->kobj, |
| 1335 | &additional_attr_group); |
| 1336 | |
Jarkko Nikula | f821eec | 2011-09-26 10:45:45 +0300 | [diff] [blame] | 1337 | if (mcbsp->st_data) |
| 1338 | omap_st_remove(mcbsp); |
Eduardo Valentin | a1a56f5f | 2009-08-20 16:18:11 +0300 | [diff] [blame] | 1339 | |
Russell King | b820ce4 | 2009-01-23 10:26:46 +0000 | [diff] [blame] | 1340 | clk_put(mcbsp->fclk); |
Eduardo Valentin | bc5d0c8 | 2008-07-03 12:24:39 +0300 | [diff] [blame] | 1341 | |
Russell King | d592dd1 | 2008-09-04 14:25:42 +0100 | [diff] [blame] | 1342 | iounmap(mcbsp->io_base); |
Jarkko Nikula | 5f3b728 | 2010-12-07 16:25:40 -0800 | [diff] [blame] | 1343 | kfree(mcbsp); |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 1344 | } |
| 1345 | |
| 1346 | return 0; |
| 1347 | } |
| 1348 | |
Eduardo Valentin | bc5d0c8 | 2008-07-03 12:24:39 +0300 | [diff] [blame] | 1349 | static struct platform_driver omap_mcbsp_driver = { |
| 1350 | .probe = omap_mcbsp_probe, |
Uwe Kleine-König | 25cef22 | 2008-10-08 10:01:39 +0300 | [diff] [blame] | 1351 | .remove = __devexit_p(omap_mcbsp_remove), |
Eduardo Valentin | bc5d0c8 | 2008-07-03 12:24:39 +0300 | [diff] [blame] | 1352 | .driver = { |
| 1353 | .name = "omap-mcbsp", |
| 1354 | }, |
| 1355 | }; |
| 1356 | |
| 1357 | int __init omap_mcbsp_init(void) |
| 1358 | { |
| 1359 | /* Register the McBSP driver */ |
| 1360 | return platform_driver_register(&omap_mcbsp_driver); |
| 1361 | } |