Ben Dooks | f8cf817 | 2009-03-04 00:49:31 +0000 | [diff] [blame] | 1 | /* sound/soc/s3c24xx/s3c64xx-i2s.c |
| 2 | * |
| 3 | * ALSA SoC Audio Layer - S3C64XX I2S driver |
| 4 | * |
| 5 | * Copyright 2008 Openmoko, Inc. |
| 6 | * Copyright 2008 Simtec Electronics |
| 7 | * Ben Dooks <ben@simtec.co.uk> |
| 8 | * http://armlinux.simtec.co.uk/ |
| 9 | * |
| 10 | * This program is free software; you can redistribute it and/or modify |
| 11 | * it under the terms of the GNU General Public License version 2 as |
| 12 | * published by the Free Software Foundation. |
| 13 | */ |
| 14 | |
Ben Dooks | f8cf817 | 2009-03-04 00:49:31 +0000 | [diff] [blame] | 15 | #include <linux/clk.h> |
Ben Dooks | f8cf817 | 2009-03-04 00:49:31 +0000 | [diff] [blame] | 16 | #include <linux/gpio.h> |
| 17 | #include <linux/io.h> |
| 18 | |
Ben Dooks | f8cf817 | 2009-03-04 00:49:31 +0000 | [diff] [blame] | 19 | #include <sound/soc.h> |
| 20 | |
Mark Brown | facf926 | 2010-03-01 19:57:59 +0000 | [diff] [blame] | 21 | #include <mach/gpio-bank-d.h> |
| 22 | #include <mach/gpio-bank-e.h> |
Ben Dooks | f8cf817 | 2009-03-04 00:49:31 +0000 | [diff] [blame] | 23 | #include <plat/gpio-cfg.h> |
Ben Dooks | f8cf817 | 2009-03-04 00:49:31 +0000 | [diff] [blame] | 24 | |
| 25 | #include <mach/map.h> |
| 26 | #include <mach/dma.h> |
| 27 | |
Jassi Brar | d3ff5a3 | 2009-11-17 16:53:31 +0900 | [diff] [blame] | 28 | #include "s3c-dma.h" |
Jassi Brar | d07e7ce | 2010-04-27 15:55:21 +0900 | [diff] [blame] | 29 | #include "regs-i2s-v2.h" |
Ben Dooks | f8cf817 | 2009-03-04 00:49:31 +0000 | [diff] [blame] | 30 | #include "s3c64xx-i2s.h" |
| 31 | |
Jassi Brar | 0fe6922 | 2009-12-09 13:29:25 +0900 | [diff] [blame] | 32 | /* The value should be set to maximum of the total number |
| 33 | * of I2Sv3 controllers that any supported SoC has. |
| 34 | */ |
| 35 | #define MAX_I2SV3 2 |
| 36 | |
Ben Dooks | f8cf817 | 2009-03-04 00:49:31 +0000 | [diff] [blame] | 37 | static struct s3c2410_dma_client s3c64xx_dma_client_out = { |
| 38 | .name = "I2S PCM Stereo out" |
| 39 | }; |
| 40 | |
| 41 | static struct s3c2410_dma_client s3c64xx_dma_client_in = { |
| 42 | .name = "I2S PCM Stereo in" |
| 43 | }; |
| 44 | |
Jassi Brar | 0fe6922 | 2009-12-09 13:29:25 +0900 | [diff] [blame] | 45 | static struct s3c_dma_params s3c64xx_i2s_pcm_stereo_out[MAX_I2SV3]; |
| 46 | static struct s3c_dma_params s3c64xx_i2s_pcm_stereo_in[MAX_I2SV3]; |
| 47 | static struct s3c_i2sv2_info s3c64xx_i2s[MAX_I2SV3]; |
Ben Dooks | f8cf817 | 2009-03-04 00:49:31 +0000 | [diff] [blame] | 48 | |
Jassi Brar | 0fe6922 | 2009-12-09 13:29:25 +0900 | [diff] [blame] | 49 | struct snd_soc_dai s3c64xx_i2s_dai[MAX_I2SV3]; |
| 50 | EXPORT_SYMBOL_GPL(s3c64xx_i2s_dai); |
Ben Dooks | f8cf817 | 2009-03-04 00:49:31 +0000 | [diff] [blame] | 51 | |
| 52 | static inline struct s3c_i2sv2_info *to_info(struct snd_soc_dai *cpu_dai) |
| 53 | { |
| 54 | return cpu_dai->private_data; |
| 55 | } |
| 56 | |
Ben Dooks | f8cf817 | 2009-03-04 00:49:31 +0000 | [diff] [blame] | 57 | static int s3c64xx_i2s_probe(struct platform_device *pdev, |
| 58 | struct snd_soc_dai *dai) |
| 59 | { |
Ben Dooks | f8cf817 | 2009-03-04 00:49:31 +0000 | [diff] [blame] | 60 | /* configure GPIO for i2s port */ |
Mark Brown | 172fd9e | 2009-04-24 16:33:10 +0100 | [diff] [blame] | 61 | switch (dai->id) { |
Ben Dooks | f8cf817 | 2009-03-04 00:49:31 +0000 | [diff] [blame] | 62 | case 0: |
| 63 | s3c_gpio_cfgpin(S3C64XX_GPD(0), S3C64XX_GPD0_I2S0_CLK); |
| 64 | s3c_gpio_cfgpin(S3C64XX_GPD(1), S3C64XX_GPD1_I2S0_CDCLK); |
| 65 | s3c_gpio_cfgpin(S3C64XX_GPD(2), S3C64XX_GPD2_I2S0_LRCLK); |
| 66 | s3c_gpio_cfgpin(S3C64XX_GPD(3), S3C64XX_GPD3_I2S0_DI); |
| 67 | s3c_gpio_cfgpin(S3C64XX_GPD(4), S3C64XX_GPD4_I2S0_D0); |
| 68 | break; |
| 69 | case 1: |
| 70 | s3c_gpio_cfgpin(S3C64XX_GPE(0), S3C64XX_GPE0_I2S1_CLK); |
| 71 | s3c_gpio_cfgpin(S3C64XX_GPE(1), S3C64XX_GPE1_I2S1_CDCLK); |
| 72 | s3c_gpio_cfgpin(S3C64XX_GPE(2), S3C64XX_GPE2_I2S1_LRCLK); |
| 73 | s3c_gpio_cfgpin(S3C64XX_GPE(3), S3C64XX_GPE3_I2S1_DI); |
| 74 | s3c_gpio_cfgpin(S3C64XX_GPE(4), S3C64XX_GPE4_I2S1_D0); |
| 75 | } |
| 76 | |
| 77 | return 0; |
| 78 | } |
| 79 | |
| 80 | |
Jassi Brar | 8a7c251 | 2010-04-27 15:57:05 +0900 | [diff] [blame^] | 81 | static struct snd_soc_dai_ops s3c64xx_i2s_dai_ops; |
Mark Brown | f2a5d6a | 2009-03-16 14:02:07 +0000 | [diff] [blame] | 82 | |
Mark Brown | 172fd9e | 2009-04-24 16:33:10 +0100 | [diff] [blame] | 83 | static __devinit int s3c64xx_iis_dev_probe(struct platform_device *pdev) |
| 84 | { |
| 85 | struct s3c_i2sv2_info *i2s; |
| 86 | struct snd_soc_dai *dai; |
| 87 | int ret; |
| 88 | |
Jassi Brar | 0fe6922 | 2009-12-09 13:29:25 +0900 | [diff] [blame] | 89 | if (pdev->id >= MAX_I2SV3) { |
Mark Brown | 172fd9e | 2009-04-24 16:33:10 +0100 | [diff] [blame] | 90 | dev_err(&pdev->dev, "id %d out of range\n", pdev->id); |
| 91 | return -EINVAL; |
| 92 | } |
| 93 | |
| 94 | i2s = &s3c64xx_i2s[pdev->id]; |
| 95 | dai = &s3c64xx_i2s_dai[pdev->id]; |
| 96 | dai->dev = &pdev->dev; |
Jassi Brar | 0fe6922 | 2009-12-09 13:29:25 +0900 | [diff] [blame] | 97 | dai->name = "s3c64xx-i2s"; |
| 98 | dai->id = pdev->id; |
| 99 | dai->symmetric_rates = 1; |
| 100 | dai->playback.channels_min = 2; |
| 101 | dai->playback.channels_max = 2; |
| 102 | dai->playback.rates = S3C64XX_I2S_RATES; |
| 103 | dai->playback.formats = S3C64XX_I2S_FMTS; |
| 104 | dai->capture.channels_min = 2; |
| 105 | dai->capture.channels_max = 2; |
| 106 | dai->capture.rates = S3C64XX_I2S_RATES; |
| 107 | dai->capture.formats = S3C64XX_I2S_FMTS; |
| 108 | dai->probe = s3c64xx_i2s_probe; |
| 109 | dai->ops = &s3c64xx_i2s_dai_ops; |
Mark Brown | 172fd9e | 2009-04-24 16:33:10 +0100 | [diff] [blame] | 110 | |
Jassi Brar | 8a7c251 | 2010-04-27 15:57:05 +0900 | [diff] [blame^] | 111 | i2s->feature |= S3C_FEATURE_CDCLKCON; |
| 112 | |
Mark Brown | 172fd9e | 2009-04-24 16:33:10 +0100 | [diff] [blame] | 113 | i2s->dma_capture = &s3c64xx_i2s_pcm_stereo_in[pdev->id]; |
| 114 | i2s->dma_playback = &s3c64xx_i2s_pcm_stereo_out[pdev->id]; |
| 115 | |
Jassi Brar | 0fe6922 | 2009-12-09 13:29:25 +0900 | [diff] [blame] | 116 | if (pdev->id == 0) { |
| 117 | i2s->dma_capture->channel = DMACH_I2S0_IN; |
| 118 | i2s->dma_capture->dma_addr = S3C64XX_PA_IIS0 + S3C2412_IISRXD; |
| 119 | i2s->dma_playback->channel = DMACH_I2S0_OUT; |
| 120 | i2s->dma_playback->dma_addr = S3C64XX_PA_IIS0 + S3C2412_IISTXD; |
| 121 | } else { |
| 122 | i2s->dma_capture->channel = DMACH_I2S1_IN; |
| 123 | i2s->dma_capture->dma_addr = S3C64XX_PA_IIS1 + S3C2412_IISRXD; |
| 124 | i2s->dma_playback->channel = DMACH_I2S1_OUT; |
| 125 | i2s->dma_playback->dma_addr = S3C64XX_PA_IIS1 + S3C2412_IISTXD; |
| 126 | } |
| 127 | |
| 128 | i2s->dma_capture->client = &s3c64xx_dma_client_in; |
| 129 | i2s->dma_capture->dma_size = 4; |
| 130 | i2s->dma_playback->client = &s3c64xx_dma_client_out; |
| 131 | i2s->dma_playback->dma_size = 4; |
| 132 | |
Mark Brown | 172fd9e | 2009-04-24 16:33:10 +0100 | [diff] [blame] | 133 | i2s->iis_cclk = clk_get(&pdev->dev, "audio-bus"); |
| 134 | if (IS_ERR(i2s->iis_cclk)) { |
Mark Brown | 09aa60d | 2009-04-29 18:51:48 +0100 | [diff] [blame] | 135 | dev_err(&pdev->dev, "failed to get audio-bus\n"); |
Mark Brown | 172fd9e | 2009-04-24 16:33:10 +0100 | [diff] [blame] | 136 | ret = PTR_ERR(i2s->iis_cclk); |
| 137 | goto err; |
| 138 | } |
| 139 | |
Jassi Brar | 6fc786d | 2009-11-06 18:00:24 +0900 | [diff] [blame] | 140 | clk_enable(i2s->iis_cclk); |
| 141 | |
Mark Brown | 7143755 | 2009-04-30 13:42:04 +0100 | [diff] [blame] | 142 | ret = s3c_i2sv2_probe(pdev, dai, i2s, 0); |
Mark Brown | 172fd9e | 2009-04-24 16:33:10 +0100 | [diff] [blame] | 143 | if (ret) |
| 144 | goto err_clk; |
| 145 | |
Mark Brown | a7be4d9 | 2009-04-27 20:24:15 +0100 | [diff] [blame] | 146 | ret = s3c_i2sv2_register_dai(dai); |
Mark Brown | 172fd9e | 2009-04-24 16:33:10 +0100 | [diff] [blame] | 147 | if (ret != 0) |
| 148 | goto err_i2sv2; |
| 149 | |
| 150 | return 0; |
| 151 | |
| 152 | err_i2sv2: |
| 153 | /* Not implemented for I2Sv2 core yet */ |
| 154 | err_clk: |
| 155 | clk_put(i2s->iis_cclk); |
| 156 | err: |
| 157 | return ret; |
| 158 | } |
| 159 | |
| 160 | static __devexit int s3c64xx_iis_dev_remove(struct platform_device *pdev) |
| 161 | { |
| 162 | dev_err(&pdev->dev, "Device removal not yet supported\n"); |
| 163 | return 0; |
| 164 | } |
| 165 | |
| 166 | static struct platform_driver s3c64xx_iis_driver = { |
| 167 | .probe = s3c64xx_iis_dev_probe, |
| 168 | .remove = s3c64xx_iis_dev_remove, |
| 169 | .driver = { |
| 170 | .name = "s3c64xx-iis", |
| 171 | .owner = THIS_MODULE, |
| 172 | }, |
| 173 | }; |
| 174 | |
Ben Dooks | f8cf817 | 2009-03-04 00:49:31 +0000 | [diff] [blame] | 175 | static int __init s3c64xx_i2s_init(void) |
| 176 | { |
Mark Brown | 172fd9e | 2009-04-24 16:33:10 +0100 | [diff] [blame] | 177 | return platform_driver_register(&s3c64xx_iis_driver); |
Ben Dooks | f8cf817 | 2009-03-04 00:49:31 +0000 | [diff] [blame] | 178 | } |
| 179 | module_init(s3c64xx_i2s_init); |
| 180 | |
| 181 | static void __exit s3c64xx_i2s_exit(void) |
| 182 | { |
Mark Brown | 172fd9e | 2009-04-24 16:33:10 +0100 | [diff] [blame] | 183 | platform_driver_unregister(&s3c64xx_iis_driver); |
Ben Dooks | f8cf817 | 2009-03-04 00:49:31 +0000 | [diff] [blame] | 184 | } |
| 185 | module_exit(s3c64xx_i2s_exit); |
| 186 | |
| 187 | /* Module information */ |
| 188 | MODULE_AUTHOR("Ben Dooks, <ben@simtec.co.uk>"); |
| 189 | MODULE_DESCRIPTION("S3C64XX I2S SoC Interface"); |
| 190 | MODULE_LICENSE("GPL"); |