Candelaria Villareal, Jorge | b3b0b45 | 2010-02-22 17:17:21 -0600 | [diff] [blame] | 1 | /* |
Jorge Eduardo Candelaria | 9fc71e8 | 2010-03-18 19:45:41 -0600 | [diff] [blame] | 2 | * mcpdm.c -- McPDM interface driver |
Candelaria Villareal, Jorge | b3b0b45 | 2010-02-22 17:17:21 -0600 | [diff] [blame] | 3 | * |
| 4 | * Author: Jorge Eduardo Candelaria <x0107209@ti.com> |
| 5 | * Copyright (C) 2009 - Texas Instruments, Inc. |
| 6 | * |
| 7 | * This program is free software; you can redistribute it and/or |
| 8 | * modify it under the terms of the GNU General Public License |
| 9 | * version 2 as published by the Free Software Foundation. |
| 10 | * |
| 11 | * This program is distributed in the hope that it will be useful, but |
| 12 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 14 | * General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU General Public License |
| 17 | * along with this program; if not, write to the Free Software |
| 18 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA |
| 19 | * 02110-1301 USA |
| 20 | * |
| 21 | */ |
| 22 | |
| 23 | #include <linux/module.h> |
| 24 | #include <linux/init.h> |
| 25 | #include <linux/device.h> |
| 26 | #include <linux/platform_device.h> |
| 27 | #include <linux/wait.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 28 | #include <linux/slab.h> |
Candelaria Villareal, Jorge | b3b0b45 | 2010-02-22 17:17:21 -0600 | [diff] [blame] | 29 | #include <linux/interrupt.h> |
| 30 | #include <linux/err.h> |
| 31 | #include <linux/clk.h> |
| 32 | #include <linux/delay.h> |
| 33 | #include <linux/io.h> |
| 34 | #include <linux/irq.h> |
| 35 | |
| 36 | #include "mcpdm.h" |
| 37 | |
| 38 | static struct omap_mcpdm *mcpdm; |
| 39 | |
| 40 | static inline void omap_mcpdm_write(u16 reg, u32 val) |
| 41 | { |
Jorge Eduardo Candelaria | 9fc71e8 | 2010-03-18 19:45:41 -0600 | [diff] [blame] | 42 | __raw_writel(val, mcpdm->io_base + reg); |
Candelaria Villareal, Jorge | b3b0b45 | 2010-02-22 17:17:21 -0600 | [diff] [blame] | 43 | } |
| 44 | |
| 45 | static inline int omap_mcpdm_read(u16 reg) |
| 46 | { |
Jorge Eduardo Candelaria | 9fc71e8 | 2010-03-18 19:45:41 -0600 | [diff] [blame] | 47 | return __raw_readl(mcpdm->io_base + reg); |
Candelaria Villareal, Jorge | b3b0b45 | 2010-02-22 17:17:21 -0600 | [diff] [blame] | 48 | } |
| 49 | |
| 50 | static void omap_mcpdm_reg_dump(void) |
| 51 | { |
Jorge Eduardo Candelaria | 9fc71e8 | 2010-03-18 19:45:41 -0600 | [diff] [blame] | 52 | dev_dbg(mcpdm->dev, "***********************\n"); |
| 53 | dev_dbg(mcpdm->dev, "IRQSTATUS_RAW: 0x%04x\n", |
| 54 | omap_mcpdm_read(MCPDM_IRQSTATUS_RAW)); |
| 55 | dev_dbg(mcpdm->dev, "IRQSTATUS: 0x%04x\n", |
| 56 | omap_mcpdm_read(MCPDM_IRQSTATUS)); |
| 57 | dev_dbg(mcpdm->dev, "IRQENABLE_SET: 0x%04x\n", |
| 58 | omap_mcpdm_read(MCPDM_IRQENABLE_SET)); |
| 59 | dev_dbg(mcpdm->dev, "IRQENABLE_CLR: 0x%04x\n", |
| 60 | omap_mcpdm_read(MCPDM_IRQENABLE_CLR)); |
| 61 | dev_dbg(mcpdm->dev, "IRQWAKE_EN: 0x%04x\n", |
| 62 | omap_mcpdm_read(MCPDM_IRQWAKE_EN)); |
| 63 | dev_dbg(mcpdm->dev, "DMAENABLE_SET: 0x%04x\n", |
| 64 | omap_mcpdm_read(MCPDM_DMAENABLE_SET)); |
| 65 | dev_dbg(mcpdm->dev, "DMAENABLE_CLR: 0x%04x\n", |
| 66 | omap_mcpdm_read(MCPDM_DMAENABLE_CLR)); |
| 67 | dev_dbg(mcpdm->dev, "DMAWAKEEN: 0x%04x\n", |
| 68 | omap_mcpdm_read(MCPDM_DMAWAKEEN)); |
| 69 | dev_dbg(mcpdm->dev, "CTRL: 0x%04x\n", |
| 70 | omap_mcpdm_read(MCPDM_CTRL)); |
| 71 | dev_dbg(mcpdm->dev, "DN_DATA: 0x%04x\n", |
| 72 | omap_mcpdm_read(MCPDM_DN_DATA)); |
| 73 | dev_dbg(mcpdm->dev, "UP_DATA: 0x%04x\n", |
| 74 | omap_mcpdm_read(MCPDM_UP_DATA)); |
| 75 | dev_dbg(mcpdm->dev, "FIFO_CTRL_DN: 0x%04x\n", |
| 76 | omap_mcpdm_read(MCPDM_FIFO_CTRL_DN)); |
| 77 | dev_dbg(mcpdm->dev, "FIFO_CTRL_UP: 0x%04x\n", |
| 78 | omap_mcpdm_read(MCPDM_FIFO_CTRL_UP)); |
| 79 | dev_dbg(mcpdm->dev, "DN_OFFSET: 0x%04x\n", |
| 80 | omap_mcpdm_read(MCPDM_DN_OFFSET)); |
| 81 | dev_dbg(mcpdm->dev, "***********************\n"); |
Candelaria Villareal, Jorge | b3b0b45 | 2010-02-22 17:17:21 -0600 | [diff] [blame] | 82 | } |
| 83 | |
| 84 | /* |
| 85 | * Takes the McPDM module in and out of reset state. |
| 86 | * Uplink and downlink can be reset individually. |
| 87 | */ |
| 88 | static void omap_mcpdm_reset_capture(int reset) |
| 89 | { |
Jorge Eduardo Candelaria | 9fc71e8 | 2010-03-18 19:45:41 -0600 | [diff] [blame] | 90 | int ctrl = omap_mcpdm_read(MCPDM_CTRL); |
Candelaria Villareal, Jorge | b3b0b45 | 2010-02-22 17:17:21 -0600 | [diff] [blame] | 91 | |
Jorge Eduardo Candelaria | 9fc71e8 | 2010-03-18 19:45:41 -0600 | [diff] [blame] | 92 | if (reset) |
| 93 | ctrl |= SW_UP_RST; |
| 94 | else |
| 95 | ctrl &= ~SW_UP_RST; |
Candelaria Villareal, Jorge | b3b0b45 | 2010-02-22 17:17:21 -0600 | [diff] [blame] | 96 | |
Jorge Eduardo Candelaria | 9fc71e8 | 2010-03-18 19:45:41 -0600 | [diff] [blame] | 97 | omap_mcpdm_write(MCPDM_CTRL, ctrl); |
Candelaria Villareal, Jorge | b3b0b45 | 2010-02-22 17:17:21 -0600 | [diff] [blame] | 98 | } |
| 99 | |
| 100 | static void omap_mcpdm_reset_playback(int reset) |
| 101 | { |
Jorge Eduardo Candelaria | 9fc71e8 | 2010-03-18 19:45:41 -0600 | [diff] [blame] | 102 | int ctrl = omap_mcpdm_read(MCPDM_CTRL); |
Candelaria Villareal, Jorge | b3b0b45 | 2010-02-22 17:17:21 -0600 | [diff] [blame] | 103 | |
Jorge Eduardo Candelaria | 9fc71e8 | 2010-03-18 19:45:41 -0600 | [diff] [blame] | 104 | if (reset) |
| 105 | ctrl |= SW_DN_RST; |
| 106 | else |
| 107 | ctrl &= ~SW_DN_RST; |
Candelaria Villareal, Jorge | b3b0b45 | 2010-02-22 17:17:21 -0600 | [diff] [blame] | 108 | |
Jorge Eduardo Candelaria | 9fc71e8 | 2010-03-18 19:45:41 -0600 | [diff] [blame] | 109 | omap_mcpdm_write(MCPDM_CTRL, ctrl); |
Candelaria Villareal, Jorge | b3b0b45 | 2010-02-22 17:17:21 -0600 | [diff] [blame] | 110 | } |
| 111 | |
| 112 | /* |
| 113 | * Enables the transfer through the PDM interface to/from the Phoenix |
| 114 | * codec by enabling the corresponding UP or DN channels. |
| 115 | */ |
| 116 | void omap_mcpdm_start(int stream) |
| 117 | { |
Jorge Eduardo Candelaria | 9fc71e8 | 2010-03-18 19:45:41 -0600 | [diff] [blame] | 118 | int ctrl = omap_mcpdm_read(MCPDM_CTRL); |
Candelaria Villareal, Jorge | b3b0b45 | 2010-02-22 17:17:21 -0600 | [diff] [blame] | 119 | |
Jorge Eduardo Candelaria | 9fc71e8 | 2010-03-18 19:45:41 -0600 | [diff] [blame] | 120 | if (stream) |
| 121 | ctrl |= mcpdm->up_channels; |
| 122 | else |
| 123 | ctrl |= mcpdm->dn_channels; |
Candelaria Villareal, Jorge | b3b0b45 | 2010-02-22 17:17:21 -0600 | [diff] [blame] | 124 | |
Jorge Eduardo Candelaria | 9fc71e8 | 2010-03-18 19:45:41 -0600 | [diff] [blame] | 125 | omap_mcpdm_write(MCPDM_CTRL, ctrl); |
Candelaria Villareal, Jorge | b3b0b45 | 2010-02-22 17:17:21 -0600 | [diff] [blame] | 126 | } |
| 127 | |
| 128 | /* |
| 129 | * Disables the transfer through the PDM interface to/from the Phoenix |
| 130 | * codec by disabling the corresponding UP or DN channels. |
| 131 | */ |
| 132 | void omap_mcpdm_stop(int stream) |
| 133 | { |
Jorge Eduardo Candelaria | 9fc71e8 | 2010-03-18 19:45:41 -0600 | [diff] [blame] | 134 | int ctrl = omap_mcpdm_read(MCPDM_CTRL); |
Candelaria Villareal, Jorge | b3b0b45 | 2010-02-22 17:17:21 -0600 | [diff] [blame] | 135 | |
Jorge Eduardo Candelaria | 9fc71e8 | 2010-03-18 19:45:41 -0600 | [diff] [blame] | 136 | if (stream) |
| 137 | ctrl &= ~mcpdm->up_channels; |
| 138 | else |
| 139 | ctrl &= ~mcpdm->dn_channels; |
Candelaria Villareal, Jorge | b3b0b45 | 2010-02-22 17:17:21 -0600 | [diff] [blame] | 140 | |
Jorge Eduardo Candelaria | 9fc71e8 | 2010-03-18 19:45:41 -0600 | [diff] [blame] | 141 | omap_mcpdm_write(MCPDM_CTRL, ctrl); |
Candelaria Villareal, Jorge | b3b0b45 | 2010-02-22 17:17:21 -0600 | [diff] [blame] | 142 | } |
| 143 | |
| 144 | /* |
| 145 | * Configures McPDM uplink for audio recording. |
| 146 | * This function should be called before omap_mcpdm_start. |
| 147 | */ |
| 148 | int omap_mcpdm_capture_open(struct omap_mcpdm_link *uplink) |
| 149 | { |
Jorge Eduardo Candelaria | 9fc71e8 | 2010-03-18 19:45:41 -0600 | [diff] [blame] | 150 | int irq_mask = 0; |
| 151 | int ctrl; |
Candelaria Villareal, Jorge | b3b0b45 | 2010-02-22 17:17:21 -0600 | [diff] [blame] | 152 | |
Jorge Eduardo Candelaria | 9fc71e8 | 2010-03-18 19:45:41 -0600 | [diff] [blame] | 153 | if (!uplink) |
| 154 | return -EINVAL; |
Candelaria Villareal, Jorge | b3b0b45 | 2010-02-22 17:17:21 -0600 | [diff] [blame] | 155 | |
Jorge Eduardo Candelaria | 9fc71e8 | 2010-03-18 19:45:41 -0600 | [diff] [blame] | 156 | mcpdm->uplink = uplink; |
Candelaria Villareal, Jorge | b3b0b45 | 2010-02-22 17:17:21 -0600 | [diff] [blame] | 157 | |
Jorge Eduardo Candelaria | 9fc71e8 | 2010-03-18 19:45:41 -0600 | [diff] [blame] | 158 | /* Enable irq request generation */ |
| 159 | irq_mask |= uplink->irq_mask & MCPDM_UPLINK_IRQ_MASK; |
| 160 | omap_mcpdm_write(MCPDM_IRQENABLE_SET, irq_mask); |
Candelaria Villareal, Jorge | b3b0b45 | 2010-02-22 17:17:21 -0600 | [diff] [blame] | 161 | |
Jorge Eduardo Candelaria | 9fc71e8 | 2010-03-18 19:45:41 -0600 | [diff] [blame] | 162 | /* Configure uplink threshold */ |
| 163 | if (uplink->threshold > UP_THRES_MAX) |
| 164 | uplink->threshold = UP_THRES_MAX; |
Candelaria Villareal, Jorge | b3b0b45 | 2010-02-22 17:17:21 -0600 | [diff] [blame] | 165 | |
Jorge Eduardo Candelaria | 9fc71e8 | 2010-03-18 19:45:41 -0600 | [diff] [blame] | 166 | omap_mcpdm_write(MCPDM_FIFO_CTRL_UP, uplink->threshold); |
Candelaria Villareal, Jorge | b3b0b45 | 2010-02-22 17:17:21 -0600 | [diff] [blame] | 167 | |
Jorge Eduardo Candelaria | 9fc71e8 | 2010-03-18 19:45:41 -0600 | [diff] [blame] | 168 | /* Configure DMA controller */ |
| 169 | omap_mcpdm_write(MCPDM_DMAENABLE_SET, DMA_UP_ENABLE); |
Candelaria Villareal, Jorge | b3b0b45 | 2010-02-22 17:17:21 -0600 | [diff] [blame] | 170 | |
Jorge Eduardo Candelaria | 9fc71e8 | 2010-03-18 19:45:41 -0600 | [diff] [blame] | 171 | /* Set pdm out format */ |
| 172 | ctrl = omap_mcpdm_read(MCPDM_CTRL); |
| 173 | ctrl &= ~PDMOUTFORMAT; |
| 174 | ctrl |= uplink->format & PDMOUTFORMAT; |
Candelaria Villareal, Jorge | b3b0b45 | 2010-02-22 17:17:21 -0600 | [diff] [blame] | 175 | |
Jorge Eduardo Candelaria | 9fc71e8 | 2010-03-18 19:45:41 -0600 | [diff] [blame] | 176 | /* Uplink channels */ |
| 177 | mcpdm->up_channels = uplink->channels & (PDM_UP_MASK | PDM_STATUS_MASK); |
Candelaria Villareal, Jorge | b3b0b45 | 2010-02-22 17:17:21 -0600 | [diff] [blame] | 178 | |
Jorge Eduardo Candelaria | 9fc71e8 | 2010-03-18 19:45:41 -0600 | [diff] [blame] | 179 | omap_mcpdm_write(MCPDM_CTRL, ctrl); |
Candelaria Villareal, Jorge | b3b0b45 | 2010-02-22 17:17:21 -0600 | [diff] [blame] | 180 | |
Jorge Eduardo Candelaria | 9fc71e8 | 2010-03-18 19:45:41 -0600 | [diff] [blame] | 181 | return 0; |
Candelaria Villareal, Jorge | b3b0b45 | 2010-02-22 17:17:21 -0600 | [diff] [blame] | 182 | } |
| 183 | |
| 184 | /* |
| 185 | * Configures McPDM downlink for audio playback. |
| 186 | * This function should be called before omap_mcpdm_start. |
| 187 | */ |
| 188 | int omap_mcpdm_playback_open(struct omap_mcpdm_link *downlink) |
| 189 | { |
Jorge Eduardo Candelaria | 9fc71e8 | 2010-03-18 19:45:41 -0600 | [diff] [blame] | 190 | int irq_mask = 0; |
| 191 | int ctrl; |
Candelaria Villareal, Jorge | b3b0b45 | 2010-02-22 17:17:21 -0600 | [diff] [blame] | 192 | |
Jorge Eduardo Candelaria | 9fc71e8 | 2010-03-18 19:45:41 -0600 | [diff] [blame] | 193 | if (!downlink) |
| 194 | return -EINVAL; |
Candelaria Villareal, Jorge | b3b0b45 | 2010-02-22 17:17:21 -0600 | [diff] [blame] | 195 | |
Jorge Eduardo Candelaria | 9fc71e8 | 2010-03-18 19:45:41 -0600 | [diff] [blame] | 196 | mcpdm->downlink = downlink; |
Candelaria Villareal, Jorge | b3b0b45 | 2010-02-22 17:17:21 -0600 | [diff] [blame] | 197 | |
Jorge Eduardo Candelaria | 9fc71e8 | 2010-03-18 19:45:41 -0600 | [diff] [blame] | 198 | /* Enable irq request generation */ |
| 199 | irq_mask |= downlink->irq_mask & MCPDM_DOWNLINK_IRQ_MASK; |
| 200 | omap_mcpdm_write(MCPDM_IRQENABLE_SET, irq_mask); |
Candelaria Villareal, Jorge | b3b0b45 | 2010-02-22 17:17:21 -0600 | [diff] [blame] | 201 | |
Jorge Eduardo Candelaria | 9fc71e8 | 2010-03-18 19:45:41 -0600 | [diff] [blame] | 202 | /* Configure uplink threshold */ |
| 203 | if (downlink->threshold > DN_THRES_MAX) |
| 204 | downlink->threshold = DN_THRES_MAX; |
Candelaria Villareal, Jorge | b3b0b45 | 2010-02-22 17:17:21 -0600 | [diff] [blame] | 205 | |
Jorge Eduardo Candelaria | 9fc71e8 | 2010-03-18 19:45:41 -0600 | [diff] [blame] | 206 | omap_mcpdm_write(MCPDM_FIFO_CTRL_DN, downlink->threshold); |
Candelaria Villareal, Jorge | b3b0b45 | 2010-02-22 17:17:21 -0600 | [diff] [blame] | 207 | |
Jorge Eduardo Candelaria | 9fc71e8 | 2010-03-18 19:45:41 -0600 | [diff] [blame] | 208 | /* Enable DMA request generation */ |
| 209 | omap_mcpdm_write(MCPDM_DMAENABLE_SET, DMA_DN_ENABLE); |
Candelaria Villareal, Jorge | b3b0b45 | 2010-02-22 17:17:21 -0600 | [diff] [blame] | 210 | |
Jorge Eduardo Candelaria | 9fc71e8 | 2010-03-18 19:45:41 -0600 | [diff] [blame] | 211 | /* Set pdm out format */ |
| 212 | ctrl = omap_mcpdm_read(MCPDM_CTRL); |
| 213 | ctrl &= ~PDMOUTFORMAT; |
| 214 | ctrl |= downlink->format & PDMOUTFORMAT; |
Candelaria Villareal, Jorge | b3b0b45 | 2010-02-22 17:17:21 -0600 | [diff] [blame] | 215 | |
Jorge Eduardo Candelaria | 9fc71e8 | 2010-03-18 19:45:41 -0600 | [diff] [blame] | 216 | /* Downlink channels */ |
| 217 | mcpdm->dn_channels = downlink->channels & (PDM_DN_MASK | PDM_CMD_MASK); |
Candelaria Villareal, Jorge | b3b0b45 | 2010-02-22 17:17:21 -0600 | [diff] [blame] | 218 | |
Jorge Eduardo Candelaria | 9fc71e8 | 2010-03-18 19:45:41 -0600 | [diff] [blame] | 219 | omap_mcpdm_write(MCPDM_CTRL, ctrl); |
Candelaria Villareal, Jorge | b3b0b45 | 2010-02-22 17:17:21 -0600 | [diff] [blame] | 220 | |
Jorge Eduardo Candelaria | 9fc71e8 | 2010-03-18 19:45:41 -0600 | [diff] [blame] | 221 | return 0; |
Candelaria Villareal, Jorge | b3b0b45 | 2010-02-22 17:17:21 -0600 | [diff] [blame] | 222 | } |
| 223 | |
| 224 | /* |
| 225 | * Cleans McPDM uplink configuration. |
| 226 | * This function should be called when the stream is closed. |
| 227 | */ |
| 228 | int omap_mcpdm_capture_close(struct omap_mcpdm_link *uplink) |
| 229 | { |
Jorge Eduardo Candelaria | 9fc71e8 | 2010-03-18 19:45:41 -0600 | [diff] [blame] | 230 | int irq_mask = 0; |
Candelaria Villareal, Jorge | b3b0b45 | 2010-02-22 17:17:21 -0600 | [diff] [blame] | 231 | |
Jorge Eduardo Candelaria | 9fc71e8 | 2010-03-18 19:45:41 -0600 | [diff] [blame] | 232 | if (!uplink) |
| 233 | return -EINVAL; |
Candelaria Villareal, Jorge | b3b0b45 | 2010-02-22 17:17:21 -0600 | [diff] [blame] | 234 | |
Jorge Eduardo Candelaria | 9fc71e8 | 2010-03-18 19:45:41 -0600 | [diff] [blame] | 235 | /* Disable irq request generation */ |
| 236 | irq_mask |= uplink->irq_mask & MCPDM_UPLINK_IRQ_MASK; |
| 237 | omap_mcpdm_write(MCPDM_IRQENABLE_CLR, irq_mask); |
Candelaria Villareal, Jorge | b3b0b45 | 2010-02-22 17:17:21 -0600 | [diff] [blame] | 238 | |
Jorge Eduardo Candelaria | 9fc71e8 | 2010-03-18 19:45:41 -0600 | [diff] [blame] | 239 | /* Disable DMA request generation */ |
| 240 | omap_mcpdm_write(MCPDM_DMAENABLE_CLR, DMA_UP_ENABLE); |
Candelaria Villareal, Jorge | b3b0b45 | 2010-02-22 17:17:21 -0600 | [diff] [blame] | 241 | |
Jorge Eduardo Candelaria | 9fc71e8 | 2010-03-18 19:45:41 -0600 | [diff] [blame] | 242 | /* Clear Downlink channels */ |
| 243 | mcpdm->up_channels = 0; |
Candelaria Villareal, Jorge | b3b0b45 | 2010-02-22 17:17:21 -0600 | [diff] [blame] | 244 | |
Jorge Eduardo Candelaria | 9fc71e8 | 2010-03-18 19:45:41 -0600 | [diff] [blame] | 245 | mcpdm->uplink = NULL; |
Candelaria Villareal, Jorge | b3b0b45 | 2010-02-22 17:17:21 -0600 | [diff] [blame] | 246 | |
Jorge Eduardo Candelaria | 9fc71e8 | 2010-03-18 19:45:41 -0600 | [diff] [blame] | 247 | return 0; |
Candelaria Villareal, Jorge | b3b0b45 | 2010-02-22 17:17:21 -0600 | [diff] [blame] | 248 | } |
| 249 | |
| 250 | /* |
| 251 | * Cleans McPDM downlink configuration. |
| 252 | * This function should be called when the stream is closed. |
| 253 | */ |
| 254 | int omap_mcpdm_playback_close(struct omap_mcpdm_link *downlink) |
| 255 | { |
Jorge Eduardo Candelaria | 9fc71e8 | 2010-03-18 19:45:41 -0600 | [diff] [blame] | 256 | int irq_mask = 0; |
Candelaria Villareal, Jorge | b3b0b45 | 2010-02-22 17:17:21 -0600 | [diff] [blame] | 257 | |
Jorge Eduardo Candelaria | 9fc71e8 | 2010-03-18 19:45:41 -0600 | [diff] [blame] | 258 | if (!downlink) |
| 259 | return -EINVAL; |
Candelaria Villareal, Jorge | b3b0b45 | 2010-02-22 17:17:21 -0600 | [diff] [blame] | 260 | |
Jorge Eduardo Candelaria | 9fc71e8 | 2010-03-18 19:45:41 -0600 | [diff] [blame] | 261 | /* Disable irq request generation */ |
| 262 | irq_mask |= downlink->irq_mask & MCPDM_DOWNLINK_IRQ_MASK; |
| 263 | omap_mcpdm_write(MCPDM_IRQENABLE_CLR, irq_mask); |
Candelaria Villareal, Jorge | b3b0b45 | 2010-02-22 17:17:21 -0600 | [diff] [blame] | 264 | |
Jorge Eduardo Candelaria | 9fc71e8 | 2010-03-18 19:45:41 -0600 | [diff] [blame] | 265 | /* Disable DMA request generation */ |
| 266 | omap_mcpdm_write(MCPDM_DMAENABLE_CLR, DMA_DN_ENABLE); |
Candelaria Villareal, Jorge | b3b0b45 | 2010-02-22 17:17:21 -0600 | [diff] [blame] | 267 | |
Jorge Eduardo Candelaria | 9fc71e8 | 2010-03-18 19:45:41 -0600 | [diff] [blame] | 268 | /* clear Downlink channels */ |
| 269 | mcpdm->dn_channels = 0; |
Candelaria Villareal, Jorge | b3b0b45 | 2010-02-22 17:17:21 -0600 | [diff] [blame] | 270 | |
Jorge Eduardo Candelaria | 9fc71e8 | 2010-03-18 19:45:41 -0600 | [diff] [blame] | 271 | mcpdm->downlink = NULL; |
Candelaria Villareal, Jorge | b3b0b45 | 2010-02-22 17:17:21 -0600 | [diff] [blame] | 272 | |
Jorge Eduardo Candelaria | 9fc71e8 | 2010-03-18 19:45:41 -0600 | [diff] [blame] | 273 | return 0; |
Candelaria Villareal, Jorge | b3b0b45 | 2010-02-22 17:17:21 -0600 | [diff] [blame] | 274 | } |
| 275 | |
| 276 | static irqreturn_t omap_mcpdm_irq_handler(int irq, void *dev_id) |
| 277 | { |
Jorge Eduardo Candelaria | 9fc71e8 | 2010-03-18 19:45:41 -0600 | [diff] [blame] | 278 | struct omap_mcpdm *mcpdm_irq = dev_id; |
| 279 | int irq_status; |
Candelaria Villareal, Jorge | b3b0b45 | 2010-02-22 17:17:21 -0600 | [diff] [blame] | 280 | |
Jorge Eduardo Candelaria | 9fc71e8 | 2010-03-18 19:45:41 -0600 | [diff] [blame] | 281 | irq_status = omap_mcpdm_read(MCPDM_IRQSTATUS); |
Candelaria Villareal, Jorge | b3b0b45 | 2010-02-22 17:17:21 -0600 | [diff] [blame] | 282 | |
Jorge Eduardo Candelaria | 9fc71e8 | 2010-03-18 19:45:41 -0600 | [diff] [blame] | 283 | /* Acknowledge irq event */ |
| 284 | omap_mcpdm_write(MCPDM_IRQSTATUS, irq_status); |
Candelaria Villareal, Jorge | b3b0b45 | 2010-02-22 17:17:21 -0600 | [diff] [blame] | 285 | |
Jorge Eduardo Candelaria | 9fc71e8 | 2010-03-18 19:45:41 -0600 | [diff] [blame] | 286 | if (irq & MCPDM_DN_IRQ_FULL) { |
| 287 | dev_err(mcpdm_irq->dev, "DN FIFO error %x\n", irq_status); |
| 288 | omap_mcpdm_reset_playback(1); |
| 289 | omap_mcpdm_playback_open(mcpdm_irq->downlink); |
| 290 | omap_mcpdm_reset_playback(0); |
| 291 | } |
Candelaria Villareal, Jorge | b3b0b45 | 2010-02-22 17:17:21 -0600 | [diff] [blame] | 292 | |
Jorge Eduardo Candelaria | 9fc71e8 | 2010-03-18 19:45:41 -0600 | [diff] [blame] | 293 | if (irq & MCPDM_DN_IRQ_EMPTY) { |
| 294 | dev_err(mcpdm_irq->dev, "DN FIFO error %x\n", irq_status); |
| 295 | omap_mcpdm_reset_playback(1); |
| 296 | omap_mcpdm_playback_open(mcpdm_irq->downlink); |
| 297 | omap_mcpdm_reset_playback(0); |
| 298 | } |
Candelaria Villareal, Jorge | b3b0b45 | 2010-02-22 17:17:21 -0600 | [diff] [blame] | 299 | |
Jorge Eduardo Candelaria | 9fc71e8 | 2010-03-18 19:45:41 -0600 | [diff] [blame] | 300 | if (irq & MCPDM_DN_IRQ) { |
| 301 | dev_dbg(mcpdm_irq->dev, "DN write request\n"); |
| 302 | } |
Candelaria Villareal, Jorge | b3b0b45 | 2010-02-22 17:17:21 -0600 | [diff] [blame] | 303 | |
Jorge Eduardo Candelaria | 9fc71e8 | 2010-03-18 19:45:41 -0600 | [diff] [blame] | 304 | if (irq & MCPDM_UP_IRQ_FULL) { |
| 305 | dev_err(mcpdm_irq->dev, "UP FIFO error %x\n", irq_status); |
| 306 | omap_mcpdm_reset_capture(1); |
| 307 | omap_mcpdm_capture_open(mcpdm_irq->uplink); |
| 308 | omap_mcpdm_reset_capture(0); |
| 309 | } |
Candelaria Villareal, Jorge | b3b0b45 | 2010-02-22 17:17:21 -0600 | [diff] [blame] | 310 | |
Jorge Eduardo Candelaria | 9fc71e8 | 2010-03-18 19:45:41 -0600 | [diff] [blame] | 311 | if (irq & MCPDM_UP_IRQ_EMPTY) { |
| 312 | dev_err(mcpdm_irq->dev, "UP FIFO error %x\n", irq_status); |
| 313 | omap_mcpdm_reset_capture(1); |
| 314 | omap_mcpdm_capture_open(mcpdm_irq->uplink); |
| 315 | omap_mcpdm_reset_capture(0); |
| 316 | } |
Candelaria Villareal, Jorge | b3b0b45 | 2010-02-22 17:17:21 -0600 | [diff] [blame] | 317 | |
Jorge Eduardo Candelaria | 9fc71e8 | 2010-03-18 19:45:41 -0600 | [diff] [blame] | 318 | if (irq & MCPDM_UP_IRQ) { |
| 319 | dev_dbg(mcpdm_irq->dev, "UP write request\n"); |
| 320 | } |
Candelaria Villareal, Jorge | b3b0b45 | 2010-02-22 17:17:21 -0600 | [diff] [blame] | 321 | |
Jorge Eduardo Candelaria | 9fc71e8 | 2010-03-18 19:45:41 -0600 | [diff] [blame] | 322 | return IRQ_HANDLED; |
Candelaria Villareal, Jorge | b3b0b45 | 2010-02-22 17:17:21 -0600 | [diff] [blame] | 323 | } |
| 324 | |
| 325 | int omap_mcpdm_request(void) |
| 326 | { |
Jorge Eduardo Candelaria | 9fc71e8 | 2010-03-18 19:45:41 -0600 | [diff] [blame] | 327 | int ret; |
Candelaria Villareal, Jorge | b3b0b45 | 2010-02-22 17:17:21 -0600 | [diff] [blame] | 328 | |
Jorge Eduardo Candelaria | 9fc71e8 | 2010-03-18 19:45:41 -0600 | [diff] [blame] | 329 | clk_enable(mcpdm->clk); |
Candelaria Villareal, Jorge | b3b0b45 | 2010-02-22 17:17:21 -0600 | [diff] [blame] | 330 | |
Jorge Eduardo Candelaria | 9fc71e8 | 2010-03-18 19:45:41 -0600 | [diff] [blame] | 331 | spin_lock(&mcpdm->lock); |
Candelaria Villareal, Jorge | b3b0b45 | 2010-02-22 17:17:21 -0600 | [diff] [blame] | 332 | |
Jorge Eduardo Candelaria | 9fc71e8 | 2010-03-18 19:45:41 -0600 | [diff] [blame] | 333 | if (!mcpdm->free) { |
| 334 | dev_err(mcpdm->dev, "McPDM interface is in use\n"); |
| 335 | spin_unlock(&mcpdm->lock); |
| 336 | ret = -EBUSY; |
| 337 | goto err; |
| 338 | } |
| 339 | mcpdm->free = 0; |
Candelaria Villareal, Jorge | b3b0b45 | 2010-02-22 17:17:21 -0600 | [diff] [blame] | 340 | |
Jorge Eduardo Candelaria | 9fc71e8 | 2010-03-18 19:45:41 -0600 | [diff] [blame] | 341 | spin_unlock(&mcpdm->lock); |
Candelaria Villareal, Jorge | b3b0b45 | 2010-02-22 17:17:21 -0600 | [diff] [blame] | 342 | |
Jorge Eduardo Candelaria | 9fc71e8 | 2010-03-18 19:45:41 -0600 | [diff] [blame] | 343 | /* Disable lines while request is ongoing */ |
| 344 | omap_mcpdm_write(MCPDM_CTRL, 0x00); |
Candelaria Villareal, Jorge | b3b0b45 | 2010-02-22 17:17:21 -0600 | [diff] [blame] | 345 | |
Jorge Eduardo Candelaria | 9fc71e8 | 2010-03-18 19:45:41 -0600 | [diff] [blame] | 346 | ret = request_irq(mcpdm->irq, omap_mcpdm_irq_handler, |
| 347 | 0, "McPDM", (void *)mcpdm); |
| 348 | if (ret) { |
| 349 | dev_err(mcpdm->dev, "Request for McPDM IRQ failed\n"); |
| 350 | goto err; |
| 351 | } |
Candelaria Villareal, Jorge | b3b0b45 | 2010-02-22 17:17:21 -0600 | [diff] [blame] | 352 | |
Jorge Eduardo Candelaria | 9fc71e8 | 2010-03-18 19:45:41 -0600 | [diff] [blame] | 353 | return 0; |
Candelaria Villareal, Jorge | b3b0b45 | 2010-02-22 17:17:21 -0600 | [diff] [blame] | 354 | |
| 355 | err: |
Jorge Eduardo Candelaria | 9fc71e8 | 2010-03-18 19:45:41 -0600 | [diff] [blame] | 356 | clk_disable(mcpdm->clk); |
| 357 | return ret; |
Candelaria Villareal, Jorge | b3b0b45 | 2010-02-22 17:17:21 -0600 | [diff] [blame] | 358 | } |
| 359 | |
| 360 | void omap_mcpdm_free(void) |
| 361 | { |
Jorge Eduardo Candelaria | 9fc71e8 | 2010-03-18 19:45:41 -0600 | [diff] [blame] | 362 | spin_lock(&mcpdm->lock); |
| 363 | if (mcpdm->free) { |
| 364 | dev_err(mcpdm->dev, "McPDM interface is already free\n"); |
| 365 | spin_unlock(&mcpdm->lock); |
| 366 | return; |
| 367 | } |
| 368 | mcpdm->free = 1; |
| 369 | spin_unlock(&mcpdm->lock); |
Candelaria Villareal, Jorge | b3b0b45 | 2010-02-22 17:17:21 -0600 | [diff] [blame] | 370 | |
Jorge Eduardo Candelaria | 9fc71e8 | 2010-03-18 19:45:41 -0600 | [diff] [blame] | 371 | clk_disable(mcpdm->clk); |
Candelaria Villareal, Jorge | b3b0b45 | 2010-02-22 17:17:21 -0600 | [diff] [blame] | 372 | |
Jorge Eduardo Candelaria | 9fc71e8 | 2010-03-18 19:45:41 -0600 | [diff] [blame] | 373 | free_irq(mcpdm->irq, (void *)mcpdm); |
Candelaria Villareal, Jorge | b3b0b45 | 2010-02-22 17:17:21 -0600 | [diff] [blame] | 374 | } |
| 375 | |
| 376 | /* Enable/disable DC offset cancelation for the analog |
| 377 | * headset path (PDM channels 1 and 2). |
| 378 | */ |
| 379 | int omap_mcpdm_set_offset(int offset1, int offset2) |
| 380 | { |
Jorge Eduardo Candelaria | 9fc71e8 | 2010-03-18 19:45:41 -0600 | [diff] [blame] | 381 | int offset; |
Candelaria Villareal, Jorge | b3b0b45 | 2010-02-22 17:17:21 -0600 | [diff] [blame] | 382 | |
Jorge Eduardo Candelaria | 9fc71e8 | 2010-03-18 19:45:41 -0600 | [diff] [blame] | 383 | if ((offset1 > DN_OFST_MAX) || (offset2 > DN_OFST_MAX)) |
| 384 | return -EINVAL; |
Candelaria Villareal, Jorge | b3b0b45 | 2010-02-22 17:17:21 -0600 | [diff] [blame] | 385 | |
Jorge Eduardo Candelaria | 9fc71e8 | 2010-03-18 19:45:41 -0600 | [diff] [blame] | 386 | offset = (offset1 << DN_OFST_RX1) | (offset2 << DN_OFST_RX2); |
Candelaria Villareal, Jorge | b3b0b45 | 2010-02-22 17:17:21 -0600 | [diff] [blame] | 387 | |
Jorge Eduardo Candelaria | 9fc71e8 | 2010-03-18 19:45:41 -0600 | [diff] [blame] | 388 | /* offset cancellation for channel 1 */ |
| 389 | if (offset1) |
| 390 | offset |= DN_OFST_RX1_EN; |
| 391 | else |
| 392 | offset &= ~DN_OFST_RX1_EN; |
Candelaria Villareal, Jorge | b3b0b45 | 2010-02-22 17:17:21 -0600 | [diff] [blame] | 393 | |
Jorge Eduardo Candelaria | 9fc71e8 | 2010-03-18 19:45:41 -0600 | [diff] [blame] | 394 | /* offset cancellation for channel 2 */ |
| 395 | if (offset2) |
| 396 | offset |= DN_OFST_RX2_EN; |
| 397 | else |
| 398 | offset &= ~DN_OFST_RX2_EN; |
Candelaria Villareal, Jorge | b3b0b45 | 2010-02-22 17:17:21 -0600 | [diff] [blame] | 399 | |
Jorge Eduardo Candelaria | 9fc71e8 | 2010-03-18 19:45:41 -0600 | [diff] [blame] | 400 | omap_mcpdm_write(MCPDM_DN_OFFSET, offset); |
Candelaria Villareal, Jorge | b3b0b45 | 2010-02-22 17:17:21 -0600 | [diff] [blame] | 401 | |
Jorge Eduardo Candelaria | 9fc71e8 | 2010-03-18 19:45:41 -0600 | [diff] [blame] | 402 | return 0; |
Candelaria Villareal, Jorge | b3b0b45 | 2010-02-22 17:17:21 -0600 | [diff] [blame] | 403 | } |
| 404 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 405 | int __devinit omap_mcpdm_probe(struct platform_device *pdev) |
Candelaria Villareal, Jorge | b3b0b45 | 2010-02-22 17:17:21 -0600 | [diff] [blame] | 406 | { |
Jorge Eduardo Candelaria | 9fc71e8 | 2010-03-18 19:45:41 -0600 | [diff] [blame] | 407 | struct resource *res; |
| 408 | int ret = 0; |
Candelaria Villareal, Jorge | b3b0b45 | 2010-02-22 17:17:21 -0600 | [diff] [blame] | 409 | |
Jorge Eduardo Candelaria | 9fc71e8 | 2010-03-18 19:45:41 -0600 | [diff] [blame] | 410 | mcpdm = kzalloc(sizeof(struct omap_mcpdm), GFP_KERNEL); |
| 411 | if (!mcpdm) { |
| 412 | ret = -ENOMEM; |
| 413 | goto exit; |
| 414 | } |
Candelaria Villareal, Jorge | b3b0b45 | 2010-02-22 17:17:21 -0600 | [diff] [blame] | 415 | |
Jorge Eduardo Candelaria | 9fc71e8 | 2010-03-18 19:45:41 -0600 | [diff] [blame] | 416 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
| 417 | if (res == NULL) { |
| 418 | dev_err(&pdev->dev, "no resource\n"); |
| 419 | goto err_resource; |
| 420 | } |
Candelaria Villareal, Jorge | b3b0b45 | 2010-02-22 17:17:21 -0600 | [diff] [blame] | 421 | |
Jorge Eduardo Candelaria | 9fc71e8 | 2010-03-18 19:45:41 -0600 | [diff] [blame] | 422 | spin_lock_init(&mcpdm->lock); |
| 423 | mcpdm->free = 1; |
| 424 | mcpdm->io_base = ioremap(res->start, resource_size(res)); |
| 425 | if (!mcpdm->io_base) { |
| 426 | ret = -ENOMEM; |
| 427 | goto err_resource; |
| 428 | } |
Candelaria Villareal, Jorge | b3b0b45 | 2010-02-22 17:17:21 -0600 | [diff] [blame] | 429 | |
Jorge Eduardo Candelaria | 9fc71e8 | 2010-03-18 19:45:41 -0600 | [diff] [blame] | 430 | mcpdm->irq = platform_get_irq(pdev, 0); |
Candelaria Villareal, Jorge | b3b0b45 | 2010-02-22 17:17:21 -0600 | [diff] [blame] | 431 | |
Jorge Eduardo Candelaria | 9fc71e8 | 2010-03-18 19:45:41 -0600 | [diff] [blame] | 432 | mcpdm->clk = clk_get(&pdev->dev, "pdm_ck"); |
| 433 | if (IS_ERR(mcpdm->clk)) { |
| 434 | ret = PTR_ERR(mcpdm->clk); |
| 435 | dev_err(&pdev->dev, "unable to get pdm_ck: %d\n", ret); |
| 436 | goto err_clk; |
| 437 | } |
Candelaria Villareal, Jorge | b3b0b45 | 2010-02-22 17:17:21 -0600 | [diff] [blame] | 438 | |
Jorge Eduardo Candelaria | 9fc71e8 | 2010-03-18 19:45:41 -0600 | [diff] [blame] | 439 | mcpdm->dev = &pdev->dev; |
| 440 | platform_set_drvdata(pdev, mcpdm); |
Candelaria Villareal, Jorge | b3b0b45 | 2010-02-22 17:17:21 -0600 | [diff] [blame] | 441 | |
Jorge Eduardo Candelaria | 9fc71e8 | 2010-03-18 19:45:41 -0600 | [diff] [blame] | 442 | return 0; |
Candelaria Villareal, Jorge | b3b0b45 | 2010-02-22 17:17:21 -0600 | [diff] [blame] | 443 | |
| 444 | err_clk: |
Jorge Eduardo Candelaria | 9fc71e8 | 2010-03-18 19:45:41 -0600 | [diff] [blame] | 445 | iounmap(mcpdm->io_base); |
Candelaria Villareal, Jorge | b3b0b45 | 2010-02-22 17:17:21 -0600 | [diff] [blame] | 446 | err_resource: |
Jorge Eduardo Candelaria | 9fc71e8 | 2010-03-18 19:45:41 -0600 | [diff] [blame] | 447 | kfree(mcpdm); |
Candelaria Villareal, Jorge | b3b0b45 | 2010-02-22 17:17:21 -0600 | [diff] [blame] | 448 | exit: |
Jorge Eduardo Candelaria | 9fc71e8 | 2010-03-18 19:45:41 -0600 | [diff] [blame] | 449 | return ret; |
Candelaria Villareal, Jorge | b3b0b45 | 2010-02-22 17:17:21 -0600 | [diff] [blame] | 450 | } |
| 451 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 452 | int __devexit omap_mcpdm_remove(struct platform_device *pdev) |
Candelaria Villareal, Jorge | b3b0b45 | 2010-02-22 17:17:21 -0600 | [diff] [blame] | 453 | { |
Jorge Eduardo Candelaria | 9fc71e8 | 2010-03-18 19:45:41 -0600 | [diff] [blame] | 454 | struct omap_mcpdm *mcpdm_ptr = platform_get_drvdata(pdev); |
Candelaria Villareal, Jorge | b3b0b45 | 2010-02-22 17:17:21 -0600 | [diff] [blame] | 455 | |
Jorge Eduardo Candelaria | 9fc71e8 | 2010-03-18 19:45:41 -0600 | [diff] [blame] | 456 | platform_set_drvdata(pdev, NULL); |
Candelaria Villareal, Jorge | b3b0b45 | 2010-02-22 17:17:21 -0600 | [diff] [blame] | 457 | |
Jorge Eduardo Candelaria | 9fc71e8 | 2010-03-18 19:45:41 -0600 | [diff] [blame] | 458 | clk_put(mcpdm_ptr->clk); |
Candelaria Villareal, Jorge | b3b0b45 | 2010-02-22 17:17:21 -0600 | [diff] [blame] | 459 | |
Jorge Eduardo Candelaria | 9fc71e8 | 2010-03-18 19:45:41 -0600 | [diff] [blame] | 460 | iounmap(mcpdm_ptr->io_base); |
Candelaria Villareal, Jorge | b3b0b45 | 2010-02-22 17:17:21 -0600 | [diff] [blame] | 461 | |
Jorge Eduardo Candelaria | 9fc71e8 | 2010-03-18 19:45:41 -0600 | [diff] [blame] | 462 | mcpdm_ptr->clk = NULL; |
| 463 | mcpdm_ptr->free = 0; |
| 464 | mcpdm_ptr->dev = NULL; |
Candelaria Villareal, Jorge | b3b0b45 | 2010-02-22 17:17:21 -0600 | [diff] [blame] | 465 | |
Jorge Eduardo Candelaria | 9fc71e8 | 2010-03-18 19:45:41 -0600 | [diff] [blame] | 466 | kfree(mcpdm_ptr); |
Candelaria Villareal, Jorge | b3b0b45 | 2010-02-22 17:17:21 -0600 | [diff] [blame] | 467 | |
Jorge Eduardo Candelaria | 9fc71e8 | 2010-03-18 19:45:41 -0600 | [diff] [blame] | 468 | return 0; |
Candelaria Villareal, Jorge | b3b0b45 | 2010-02-22 17:17:21 -0600 | [diff] [blame] | 469 | } |
| 470 | |