Cliff Cai | f202862 | 2008-09-05 18:21:37 +0800 | [diff] [blame] | 1 | /* |
| 2 | * bf5xx-ac97.c -- AC97 support for the ADI blackfin chip. |
| 3 | * |
| 4 | * Author: Roy Huang |
| 5 | * Created: 11th. June 2007 |
| 6 | * Copyright: Analog Device Inc. |
| 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 | |
| 13 | #include <linux/init.h> |
| 14 | #include <linux/module.h> |
| 15 | #include <linux/platform_device.h> |
| 16 | #include <linux/interrupt.h> |
| 17 | #include <linux/wait.h> |
| 18 | #include <linux/delay.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 19 | #include <linux/slab.h> |
Cliff Cai | f202862 | 2008-09-05 18:21:37 +0800 | [diff] [blame] | 20 | |
| 21 | #include <sound/core.h> |
| 22 | #include <sound/pcm.h> |
| 23 | #include <sound/ac97_codec.h> |
| 24 | #include <sound/initval.h> |
| 25 | #include <sound/soc.h> |
| 26 | |
| 27 | #include <asm/irq.h> |
| 28 | #include <asm/portmux.h> |
| 29 | #include <linux/mutex.h> |
| 30 | #include <linux/gpio.h> |
| 31 | |
| 32 | #include "bf5xx-sport.h" |
| 33 | #include "bf5xx-ac97.h" |
| 34 | |
Sonic Zhang | cf485da | 2009-06-02 00:18:57 -0400 | [diff] [blame] | 35 | /* Anomaly notes: |
| 36 | * 05000250 - AD1980 is running in TDM mode and RFS/TFS are generated by SPORT |
| 37 | * contrtoller. But, RFSDIV and TFSDIV are always set to 16*16-1, |
| 38 | * while the max AC97 data size is 13*16. The DIV is always larger |
| 39 | * than data size. AD73311 and ad2602 are not running in TDM mode. |
| 40 | * AD1836 and AD73322 depend on external RFS/TFS only. So, this |
| 41 | * anomaly does not affect blackfin sound drivers. |
| 42 | */ |
| 43 | |
Barry Song | 2c66cb9 | 2011-03-28 01:45:10 -0400 | [diff] [blame] | 44 | static struct sport_device *ac97_sport_handle; |
Cliff Cai | f202862 | 2008-09-05 18:21:37 +0800 | [diff] [blame] | 45 | |
Cliff Cai | 67f854b | 2008-11-18 16:18:17 +0800 | [diff] [blame] | 46 | void bf5xx_pcm_to_ac97(struct ac97_frame *dst, const __u16 *src, |
| 47 | size_t count, unsigned int chan_mask) |
Cliff Cai | f202862 | 2008-09-05 18:21:37 +0800 | [diff] [blame] | 48 | { |
| 49 | while (count--) { |
Cliff Cai | 67f854b | 2008-11-18 16:18:17 +0800 | [diff] [blame] | 50 | dst->ac97_tag = TAG_VALID; |
| 51 | if (chan_mask & SP_FL) { |
| 52 | dst->ac97_pcm_r = *src++; |
| 53 | dst->ac97_tag |= TAG_PCM_RIGHT; |
| 54 | } |
| 55 | if (chan_mask & SP_FR) { |
| 56 | dst->ac97_pcm_l = *src++; |
| 57 | dst->ac97_tag |= TAG_PCM_LEFT; |
| 58 | |
| 59 | } |
| 60 | #if defined(CONFIG_SND_BF5XX_MULTICHAN_SUPPORT) |
| 61 | if (chan_mask & SP_SR) { |
| 62 | dst->ac97_sl = *src++; |
| 63 | dst->ac97_tag |= TAG_PCM_SL; |
| 64 | } |
| 65 | if (chan_mask & SP_SL) { |
| 66 | dst->ac97_sr = *src++; |
| 67 | dst->ac97_tag |= TAG_PCM_SR; |
| 68 | } |
| 69 | if (chan_mask & SP_LFE) { |
| 70 | dst->ac97_lfe = *src++; |
| 71 | dst->ac97_tag |= TAG_PCM_LFE; |
| 72 | } |
| 73 | if (chan_mask & SP_FC) { |
| 74 | dst->ac97_center = *src++; |
| 75 | dst->ac97_tag |= TAG_PCM_CENTER; |
| 76 | } |
| 77 | #endif |
| 78 | dst++; |
Cliff Cai | f202862 | 2008-09-05 18:21:37 +0800 | [diff] [blame] | 79 | } |
| 80 | } |
| 81 | EXPORT_SYMBOL(bf5xx_pcm_to_ac97); |
| 82 | |
Cliff Cai | 67f854b | 2008-11-18 16:18:17 +0800 | [diff] [blame] | 83 | void bf5xx_ac97_to_pcm(const struct ac97_frame *src, __u16 *dst, |
Cliff Cai | f202862 | 2008-09-05 18:21:37 +0800 | [diff] [blame] | 84 | size_t count) |
| 85 | { |
Cliff Cai | 67f854b | 2008-11-18 16:18:17 +0800 | [diff] [blame] | 86 | while (count--) { |
| 87 | *(dst++) = src->ac97_pcm_l; |
| 88 | *(dst++) = src->ac97_pcm_r; |
| 89 | src++; |
| 90 | } |
Cliff Cai | f202862 | 2008-09-05 18:21:37 +0800 | [diff] [blame] | 91 | } |
| 92 | EXPORT_SYMBOL(bf5xx_ac97_to_pcm); |
| 93 | |
| 94 | static unsigned int sport_tx_curr_frag(struct sport_device *sport) |
| 95 | { |
Cliff Cai | 67f854b | 2008-11-18 16:18:17 +0800 | [diff] [blame] | 96 | return sport->tx_curr_frag = sport_curr_offset_tx(sport) / |
Cliff Cai | f202862 | 2008-09-05 18:21:37 +0800 | [diff] [blame] | 97 | sport->tx_fragsize; |
| 98 | } |
| 99 | |
| 100 | static void enqueue_cmd(struct snd_ac97 *ac97, __u16 addr, __u16 data) |
| 101 | { |
Barry Song | 2c66cb9 | 2011-03-28 01:45:10 -0400 | [diff] [blame] | 102 | struct sport_device *sport = ac97_sport_handle; |
| 103 | int *cmd_count = sport->private_data; |
Cliff Cai | f202862 | 2008-09-05 18:21:37 +0800 | [diff] [blame] | 104 | int nextfrag = sport_tx_curr_frag(sport); |
| 105 | struct ac97_frame *nextwrite; |
| 106 | |
| 107 | sport_incfrag(sport, &nextfrag, 1); |
Cliff Cai | f202862 | 2008-09-05 18:21:37 +0800 | [diff] [blame] | 108 | |
Cliff Cai | 67f854b | 2008-11-18 16:18:17 +0800 | [diff] [blame] | 109 | nextwrite = (struct ac97_frame *)(sport->tx_buf + |
Cliff Cai | f202862 | 2008-09-05 18:21:37 +0800 | [diff] [blame] | 110 | nextfrag * sport->tx_fragsize); |
| 111 | pr_debug("sport->tx_buf:%p, nextfrag:0x%x nextwrite:%p, cmd_count:%d\n", |
| 112 | sport->tx_buf, nextfrag, nextwrite, cmd_count[nextfrag]); |
| 113 | nextwrite[cmd_count[nextfrag]].ac97_tag |= TAG_CMD; |
| 114 | nextwrite[cmd_count[nextfrag]].ac97_addr = addr; |
| 115 | nextwrite[cmd_count[nextfrag]].ac97_data = data; |
| 116 | ++cmd_count[nextfrag]; |
| 117 | pr_debug("ac97_sport: Inserting %02x/%04x into fragment %d\n", |
| 118 | addr >> 8, data, nextfrag); |
| 119 | } |
| 120 | |
| 121 | static unsigned short bf5xx_ac97_read(struct snd_ac97 *ac97, |
| 122 | unsigned short reg) |
| 123 | { |
Barry Song | 2c66cb9 | 2011-03-28 01:45:10 -0400 | [diff] [blame] | 124 | struct sport_device *sport_handle = ac97_sport_handle; |
Cliff Cai | f202862 | 2008-09-05 18:21:37 +0800 | [diff] [blame] | 125 | struct ac97_frame out_frame[2], in_frame[2]; |
| 126 | |
| 127 | pr_debug("%s enter 0x%x\n", __func__, reg); |
| 128 | |
| 129 | /* When dma descriptor is enabled, the register should not be read */ |
| 130 | if (sport_handle->tx_run || sport_handle->rx_run) { |
| 131 | pr_err("Could you send a mail to cliff.cai@analog.com " |
| 132 | "to report this?\n"); |
| 133 | return -EFAULT; |
| 134 | } |
| 135 | |
| 136 | memset(&out_frame, 0, 2 * sizeof(struct ac97_frame)); |
| 137 | memset(&in_frame, 0, 2 * sizeof(struct ac97_frame)); |
| 138 | out_frame[0].ac97_tag = TAG_VALID | TAG_CMD; |
| 139 | out_frame[0].ac97_addr = ((reg << 8) | 0x8000); |
| 140 | sport_send_and_recv(sport_handle, (unsigned char *)&out_frame, |
| 141 | (unsigned char *)&in_frame, |
| 142 | 2 * sizeof(struct ac97_frame)); |
| 143 | return in_frame[1].ac97_data; |
| 144 | } |
| 145 | |
| 146 | void bf5xx_ac97_write(struct snd_ac97 *ac97, unsigned short reg, |
| 147 | unsigned short val) |
| 148 | { |
Barry Song | 2c66cb9 | 2011-03-28 01:45:10 -0400 | [diff] [blame] | 149 | struct sport_device *sport_handle = ac97_sport_handle; |
| 150 | |
Cliff Cai | f202862 | 2008-09-05 18:21:37 +0800 | [diff] [blame] | 151 | pr_debug("%s enter 0x%x:0x%04x\n", __func__, reg, val); |
| 152 | |
| 153 | if (sport_handle->tx_run) { |
| 154 | enqueue_cmd(ac97, (reg << 8), val); /* write */ |
| 155 | enqueue_cmd(ac97, (reg << 8) | 0x8000, 0); /* read back */ |
| 156 | } else { |
| 157 | struct ac97_frame frame; |
| 158 | memset(&frame, 0, sizeof(struct ac97_frame)); |
| 159 | frame.ac97_tag = TAG_VALID | TAG_CMD; |
| 160 | frame.ac97_addr = (reg << 8); |
| 161 | frame.ac97_data = val; |
| 162 | sport_send_and_recv(sport_handle, (unsigned char *)&frame, \ |
| 163 | NULL, sizeof(struct ac97_frame)); |
| 164 | } |
| 165 | } |
| 166 | |
| 167 | static void bf5xx_ac97_warm_reset(struct snd_ac97 *ac97) |
| 168 | { |
Barry Song | 2c66cb9 | 2011-03-28 01:45:10 -0400 | [diff] [blame] | 169 | struct sport_device *sport_handle = ac97_sport_handle; |
| 170 | u16 gpio = P_IDENT(sport_handle->pin_req[3]); |
Cliff Cai | f202862 | 2008-09-05 18:21:37 +0800 | [diff] [blame] | 171 | |
| 172 | pr_debug("%s enter\n", __func__); |
| 173 | |
Barry Song | 2c66cb9 | 2011-03-28 01:45:10 -0400 | [diff] [blame] | 174 | peripheral_free_list(sport_handle->pin_req); |
Cliff Cai | f202862 | 2008-09-05 18:21:37 +0800 | [diff] [blame] | 175 | gpio_request(gpio, "bf5xx-ac97"); |
| 176 | gpio_direction_output(gpio, 1); |
| 177 | udelay(2); |
| 178 | gpio_set_value(gpio, 0); |
| 179 | udelay(1); |
| 180 | gpio_free(gpio); |
Barry Song | 2c66cb9 | 2011-03-28 01:45:10 -0400 | [diff] [blame] | 181 | peripheral_request_list(sport_handle->pin_req, "soc-audio"); |
Cliff Cai | f202862 | 2008-09-05 18:21:37 +0800 | [diff] [blame] | 182 | } |
| 183 | |
| 184 | static void bf5xx_ac97_cold_reset(struct snd_ac97 *ac97) |
| 185 | { |
| 186 | #ifdef CONFIG_SND_BF5XX_HAVE_COLD_RESET |
| 187 | pr_debug("%s enter\n", __func__); |
| 188 | |
| 189 | /* It is specified for bf548-ezkit */ |
| 190 | gpio_set_value(CONFIG_SND_BF5XX_RESET_GPIO_NUM, 0); |
| 191 | /* Keep reset pin low for 1 ms */ |
| 192 | mdelay(1); |
| 193 | gpio_set_value(CONFIG_SND_BF5XX_RESET_GPIO_NUM, 1); |
| 194 | /* Wait for bit clock recover */ |
| 195 | mdelay(1); |
| 196 | #else |
| 197 | pr_info("%s: Not implemented\n", __func__); |
| 198 | #endif |
| 199 | } |
| 200 | |
Mark Brown | b047e1c | 2013-06-26 12:45:59 +0100 | [diff] [blame] | 201 | static struct snd_ac97_bus_ops bf5xx_ac97_ops = { |
Cliff Cai | f202862 | 2008-09-05 18:21:37 +0800 | [diff] [blame] | 202 | .read = bf5xx_ac97_read, |
| 203 | .write = bf5xx_ac97_write, |
| 204 | .warm_reset = bf5xx_ac97_warm_reset, |
| 205 | .reset = bf5xx_ac97_cold_reset, |
| 206 | }; |
Cliff Cai | f202862 | 2008-09-05 18:21:37 +0800 | [diff] [blame] | 207 | |
| 208 | #ifdef CONFIG_PM |
Mark Brown | dc7d7b8 | 2008-12-03 18:21:52 +0000 | [diff] [blame] | 209 | static int bf5xx_ac97_suspend(struct snd_soc_dai *dai) |
Cliff Cai | f202862 | 2008-09-05 18:21:37 +0800 | [diff] [blame] | 210 | { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 211 | struct sport_device *sport = snd_soc_dai_get_drvdata(dai); |
Cliff Cai | f202862 | 2008-09-05 18:21:37 +0800 | [diff] [blame] | 212 | |
| 213 | pr_debug("%s : sport %d\n", __func__, dai->id); |
| 214 | if (!dai->active) |
| 215 | return 0; |
Mike Frysinger | e9c2048 | 2011-01-11 19:57:33 -0500 | [diff] [blame] | 216 | if (dai->capture_active) |
Cliff Cai | f202862 | 2008-09-05 18:21:37 +0800 | [diff] [blame] | 217 | sport_rx_stop(sport); |
Mike Frysinger | e9c2048 | 2011-01-11 19:57:33 -0500 | [diff] [blame] | 218 | if (dai->playback_active) |
Cliff Cai | f202862 | 2008-09-05 18:21:37 +0800 | [diff] [blame] | 219 | sport_tx_stop(sport); |
| 220 | return 0; |
| 221 | } |
| 222 | |
Mark Brown | dc7d7b8 | 2008-12-03 18:21:52 +0000 | [diff] [blame] | 223 | static int bf5xx_ac97_resume(struct snd_soc_dai *dai) |
Cliff Cai | f202862 | 2008-09-05 18:21:37 +0800 | [diff] [blame] | 224 | { |
| 225 | int ret; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 226 | struct sport_device *sport = snd_soc_dai_get_drvdata(dai); |
Cliff Cai | f202862 | 2008-09-05 18:21:37 +0800 | [diff] [blame] | 227 | |
| 228 | pr_debug("%s : sport %d\n", __func__, dai->id); |
| 229 | if (!dai->active) |
| 230 | return 0; |
| 231 | |
Cliff Cai | 79dfc96 | 2009-09-16 20:25:08 -0400 | [diff] [blame] | 232 | #if defined(CONFIG_SND_BF5XX_MULTICHAN_SUPPORT) |
Lars-Peter Clausen | 6344260 | 2013-05-28 19:22:11 +0200 | [diff] [blame] | 233 | ret = sport_set_multichannel(sport, 16, 0x3FF, 0x3FF, 1); |
Cliff Cai | 79dfc96 | 2009-09-16 20:25:08 -0400 | [diff] [blame] | 234 | #else |
Lars-Peter Clausen | 6344260 | 2013-05-28 19:22:11 +0200 | [diff] [blame] | 235 | ret = sport_set_multichannel(sport, 16, 0x1F, 0x1F, 1); |
Cliff Cai | 79dfc96 | 2009-09-16 20:25:08 -0400 | [diff] [blame] | 236 | #endif |
Cliff Cai | f202862 | 2008-09-05 18:21:37 +0800 | [diff] [blame] | 237 | if (ret) { |
| 238 | pr_err("SPORT is busy!\n"); |
| 239 | return -EBUSY; |
| 240 | } |
| 241 | |
Cliff Cai | 18d02bc | 2009-07-14 10:01:39 -0400 | [diff] [blame] | 242 | ret = sport_config_rx(sport, IRFS, 0xF, 0, (16*16-1)); |
Cliff Cai | f202862 | 2008-09-05 18:21:37 +0800 | [diff] [blame] | 243 | if (ret) { |
| 244 | pr_err("SPORT is busy!\n"); |
| 245 | return -EBUSY; |
| 246 | } |
| 247 | |
Cliff Cai | 18d02bc | 2009-07-14 10:01:39 -0400 | [diff] [blame] | 248 | ret = sport_config_tx(sport, ITFS, 0xF, 0, (16*16-1)); |
Cliff Cai | f202862 | 2008-09-05 18:21:37 +0800 | [diff] [blame] | 249 | if (ret) { |
| 250 | pr_err("SPORT is busy!\n"); |
| 251 | return -EBUSY; |
| 252 | } |
| 253 | |
Cliff Cai | f202862 | 2008-09-05 18:21:37 +0800 | [diff] [blame] | 254 | return 0; |
| 255 | } |
| 256 | |
| 257 | #else |
| 258 | #define bf5xx_ac97_suspend NULL |
| 259 | #define bf5xx_ac97_resume NULL |
| 260 | #endif |
| 261 | |
Barry Song | 2c66cb9 | 2011-03-28 01:45:10 -0400 | [diff] [blame] | 262 | static struct snd_soc_dai_driver bfin_ac97_dai = { |
Lars-Peter Clausen | bc26321 | 2014-11-10 22:41:52 +0100 | [diff] [blame] | 263 | .bus_control = true, |
Barry Song | 2c66cb9 | 2011-03-28 01:45:10 -0400 | [diff] [blame] | 264 | .suspend = bf5xx_ac97_suspend, |
| 265 | .resume = bf5xx_ac97_resume, |
| 266 | .playback = { |
| 267 | .stream_name = "AC97 Playback", |
| 268 | .channels_min = 2, |
| 269 | #if defined(CONFIG_SND_BF5XX_MULTICHAN_SUPPORT) |
| 270 | .channels_max = 6, |
| 271 | #else |
| 272 | .channels_max = 2, |
| 273 | #endif |
| 274 | .rates = SNDRV_PCM_RATE_48000, |
| 275 | .formats = SNDRV_PCM_FMTBIT_S16_LE, }, |
| 276 | .capture = { |
| 277 | .stream_name = "AC97 Capture", |
| 278 | .channels_min = 2, |
| 279 | .channels_max = 2, |
| 280 | .rates = SNDRV_PCM_RATE_48000, |
| 281 | .formats = SNDRV_PCM_FMTBIT_S16_LE, }, |
| 282 | }; |
Cliff Cai | f202862 | 2008-09-05 18:21:37 +0800 | [diff] [blame] | 283 | |
Kuninori Morimoto | 514f6ac | 2013-03-21 03:29:57 -0700 | [diff] [blame] | 284 | static const struct snd_soc_component_driver bfin_ac97_component = { |
| 285 | .name = "bfin-ac97", |
| 286 | }; |
| 287 | |
Bill Pemberton | dca66da | 2012-12-07 09:26:13 -0500 | [diff] [blame] | 288 | static int asoc_bfin_ac97_probe(struct platform_device *pdev) |
Barry Song | 2c66cb9 | 2011-03-28 01:45:10 -0400 | [diff] [blame] | 289 | { |
| 290 | struct sport_device *sport_handle; |
| 291 | int ret; |
Cliff Cai | f202862 | 2008-09-05 18:21:37 +0800 | [diff] [blame] | 292 | |
| 293 | #ifdef CONFIG_SND_BF5XX_HAVE_COLD_RESET |
| 294 | /* Request PB3 as reset pin */ |
Mark Brown | 6dab2fd | 2013-06-26 11:47:56 +0100 | [diff] [blame] | 295 | ret = devm_gpio_request_one(&pdev->dev, |
| 296 | CONFIG_SND_BF5XX_RESET_GPIO_NUM, |
Lars-Peter Clausen | 610d80e | 2013-07-30 13:34:09 +0200 | [diff] [blame] | 297 | GPIOF_OUT_INIT_HIGH, "SND_AD198x RESET"); |
| 298 | if (ret) { |
Mark Brown | 6dab2fd | 2013-06-26 11:47:56 +0100 | [diff] [blame] | 299 | dev_err(&pdev->dev, |
| 300 | "Failed to request GPIO_%d for reset: %d\n", |
| 301 | CONFIG_SND_BF5XX_RESET_GPIO_NUM, ret); |
Lars-Peter Clausen | 610d80e | 2013-07-30 13:34:09 +0200 | [diff] [blame] | 302 | return ret; |
Cliff Cai | f202862 | 2008-09-05 18:21:37 +0800 | [diff] [blame] | 303 | } |
Cliff Cai | f202862 | 2008-09-05 18:21:37 +0800 | [diff] [blame] | 304 | #endif |
Barry Song | 2c66cb9 | 2011-03-28 01:45:10 -0400 | [diff] [blame] | 305 | |
| 306 | sport_handle = sport_init(pdev, 2, sizeof(struct ac97_frame), |
| 307 | PAGE_SIZE); |
Cliff Cai | f202862 | 2008-09-05 18:21:37 +0800 | [diff] [blame] | 308 | if (!sport_handle) { |
Cliff Cai | 67f854b | 2008-11-18 16:18:17 +0800 | [diff] [blame] | 309 | ret = -ENODEV; |
| 310 | goto sport_err; |
Cliff Cai | f202862 | 2008-09-05 18:21:37 +0800 | [diff] [blame] | 311 | } |
Barry Song | 2c66cb9 | 2011-03-28 01:45:10 -0400 | [diff] [blame] | 312 | |
Cliff Cai | f202862 | 2008-09-05 18:21:37 +0800 | [diff] [blame] | 313 | /*SPORT works in TDM mode to simulate AC97 transfers*/ |
Cliff Cai | 79dfc96 | 2009-09-16 20:25:08 -0400 | [diff] [blame] | 314 | #if defined(CONFIG_SND_BF5XX_MULTICHAN_SUPPORT) |
Lars-Peter Clausen | 6344260 | 2013-05-28 19:22:11 +0200 | [diff] [blame] | 315 | ret = sport_set_multichannel(sport_handle, 16, 0x3FF, 0x3FF, 1); |
Cliff Cai | 79dfc96 | 2009-09-16 20:25:08 -0400 | [diff] [blame] | 316 | #else |
Lars-Peter Clausen | 6344260 | 2013-05-28 19:22:11 +0200 | [diff] [blame] | 317 | ret = sport_set_multichannel(sport_handle, 16, 0x1F, 0x1F, 1); |
Cliff Cai | 79dfc96 | 2009-09-16 20:25:08 -0400 | [diff] [blame] | 318 | #endif |
Cliff Cai | f202862 | 2008-09-05 18:21:37 +0800 | [diff] [blame] | 319 | if (ret) { |
| 320 | pr_err("SPORT is busy!\n"); |
Cliff Cai | 67f854b | 2008-11-18 16:18:17 +0800 | [diff] [blame] | 321 | ret = -EBUSY; |
| 322 | goto sport_config_err; |
Cliff Cai | f202862 | 2008-09-05 18:21:37 +0800 | [diff] [blame] | 323 | } |
| 324 | |
| 325 | ret = sport_config_rx(sport_handle, IRFS, 0xF, 0, (16*16-1)); |
| 326 | if (ret) { |
| 327 | pr_err("SPORT is busy!\n"); |
Cliff Cai | 67f854b | 2008-11-18 16:18:17 +0800 | [diff] [blame] | 328 | ret = -EBUSY; |
| 329 | goto sport_config_err; |
Cliff Cai | f202862 | 2008-09-05 18:21:37 +0800 | [diff] [blame] | 330 | } |
| 331 | |
| 332 | ret = sport_config_tx(sport_handle, ITFS, 0xF, 0, (16*16-1)); |
| 333 | if (ret) { |
| 334 | pr_err("SPORT is busy!\n"); |
Cliff Cai | 67f854b | 2008-11-18 16:18:17 +0800 | [diff] [blame] | 335 | ret = -EBUSY; |
| 336 | goto sport_config_err; |
Cliff Cai | f202862 | 2008-09-05 18:21:37 +0800 | [diff] [blame] | 337 | } |
Cliff Cai | 67f854b | 2008-11-18 16:18:17 +0800 | [diff] [blame] | 338 | |
Mark Brown | b047e1c | 2013-06-26 12:45:59 +0100 | [diff] [blame] | 339 | ret = snd_soc_set_ac97_ops(&bf5xx_ac97_ops); |
| 340 | if (ret != 0) { |
| 341 | dev_err(&pdev->dev, "Failed to set AC'97 ops: %d\n", ret); |
| 342 | goto sport_config_err; |
| 343 | } |
| 344 | |
Kuninori Morimoto | 514f6ac | 2013-03-21 03:29:57 -0700 | [diff] [blame] | 345 | ret = snd_soc_register_component(&pdev->dev, &bfin_ac97_component, |
| 346 | &bfin_ac97_dai, 1); |
Barry Song | 2c66cb9 | 2011-03-28 01:45:10 -0400 | [diff] [blame] | 347 | if (ret) { |
| 348 | pr_err("Failed to register DAI: %d\n", ret); |
| 349 | goto sport_config_err; |
| 350 | } |
| 351 | |
| 352 | ac97_sport_handle = sport_handle; |
| 353 | |
Michael Hennerich | 0cade26 | 2008-11-18 16:18:19 +0800 | [diff] [blame] | 354 | return 0; |
| 355 | |
Cliff Cai | 67f854b | 2008-11-18 16:18:17 +0800 | [diff] [blame] | 356 | sport_config_err: |
Barry Song | 2c66cb9 | 2011-03-28 01:45:10 -0400 | [diff] [blame] | 357 | sport_done(sport_handle); |
Cliff Cai | 67f854b | 2008-11-18 16:18:17 +0800 | [diff] [blame] | 358 | sport_err: |
Mark Brown | b047e1c | 2013-06-26 12:45:59 +0100 | [diff] [blame] | 359 | snd_soc_set_ac97_ops(NULL); |
Cliff Cai | 67f854b | 2008-11-18 16:18:17 +0800 | [diff] [blame] | 360 | |
| 361 | return ret; |
Cliff Cai | f202862 | 2008-09-05 18:21:37 +0800 | [diff] [blame] | 362 | } |
| 363 | |
Bill Pemberton | dca66da | 2012-12-07 09:26:13 -0500 | [diff] [blame] | 364 | static int asoc_bfin_ac97_remove(struct platform_device *pdev) |
Cliff Cai | f202862 | 2008-09-05 18:21:37 +0800 | [diff] [blame] | 365 | { |
Barry Song | 2c66cb9 | 2011-03-28 01:45:10 -0400 | [diff] [blame] | 366 | struct sport_device *sport_handle = platform_get_drvdata(pdev); |
| 367 | |
Kuninori Morimoto | 514f6ac | 2013-03-21 03:29:57 -0700 | [diff] [blame] | 368 | snd_soc_unregister_component(&pdev->dev); |
Barry Song | 2c66cb9 | 2011-03-28 01:45:10 -0400 | [diff] [blame] | 369 | sport_done(sport_handle); |
Mark Brown | b047e1c | 2013-06-26 12:45:59 +0100 | [diff] [blame] | 370 | snd_soc_set_ac97_ops(NULL); |
Cliff Cai | f202862 | 2008-09-05 18:21:37 +0800 | [diff] [blame] | 371 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 372 | return 0; |
| 373 | } |
| 374 | |
| 375 | static struct platform_driver asoc_bfin_ac97_driver = { |
| 376 | .driver = { |
| 377 | .name = "bfin-ac97", |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 378 | }, |
| 379 | |
| 380 | .probe = asoc_bfin_ac97_probe, |
Bill Pemberton | dca66da | 2012-12-07 09:26:13 -0500 | [diff] [blame] | 381 | .remove = asoc_bfin_ac97_remove, |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 382 | }; |
| 383 | |
Axel Lin | fb80297 | 2011-11-24 14:44:52 +0800 | [diff] [blame] | 384 | module_platform_driver(asoc_bfin_ac97_driver); |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 385 | |
Cliff Cai | f202862 | 2008-09-05 18:21:37 +0800 | [diff] [blame] | 386 | MODULE_AUTHOR("Roy Huang"); |
| 387 | MODULE_DESCRIPTION("AC97 driver for ADI Blackfin"); |
| 388 | MODULE_LICENSE("GPL"); |