Mark Brown | 52da219 | 2009-06-03 20:08:38 +0100 | [diff] [blame] | 1 | /* linux/arch/arm/plat-s3c/dev-audio.c |
| 2 | * |
| 3 | * Copyright 2009 Wolfson Microelectronics |
| 4 | * Mark Brown <broonie@opensource.wolfsonmicro.com> |
| 5 | * |
Mark Brown | 52da219 | 2009-06-03 20:08:38 +0100 | [diff] [blame] | 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License version 2 as |
| 8 | * published by the Free Software Foundation. |
| 9 | */ |
| 10 | |
| 11 | #include <linux/kernel.h> |
| 12 | #include <linux/string.h> |
| 13 | #include <linux/platform_device.h> |
Jassi Brar | de6985b | 2010-02-12 10:38:51 +0000 | [diff] [blame] | 14 | #include <linux/dma-mapping.h> |
Kukjin Kim | 1c739c7 | 2010-08-05 07:54:49 +0900 | [diff] [blame] | 15 | #include <linux/gpio.h> |
Mark Brown | 52da219 | 2009-06-03 20:08:38 +0100 | [diff] [blame] | 16 | |
| 17 | #include <mach/irqs.h> |
| 18 | #include <mach/map.h> |
Jassi Brar | acf1aef | 2009-11-17 16:53:56 +0900 | [diff] [blame] | 19 | #include <mach/dma.h> |
Mark Brown | 52da219 | 2009-06-03 20:08:38 +0100 | [diff] [blame] | 20 | |
| 21 | #include <plat/devs.h> |
Jassi Brar | acf1aef | 2009-11-17 16:53:56 +0900 | [diff] [blame] | 22 | #include <plat/audio.h> |
Jassi Brar | acf1aef | 2009-11-17 16:53:56 +0900 | [diff] [blame] | 23 | #include <plat/gpio-cfg.h> |
Mark Brown | 52da219 | 2009-06-03 20:08:38 +0100 | [diff] [blame] | 24 | |
Ben Dooks | 3501c9a | 2010-01-26 10:45:40 +0900 | [diff] [blame] | 25 | #include <mach/gpio-bank-c.h> |
| 26 | #include <mach/gpio-bank-d.h> |
| 27 | #include <mach/gpio-bank-e.h> |
| 28 | #include <mach/gpio-bank-h.h> |
| 29 | |
Jassi Brar | 7126936 | 2010-01-06 15:33:44 +0900 | [diff] [blame] | 30 | static int s3c64xx_i2sv3_cfg_gpio(struct platform_device *pdev) |
| 31 | { |
| 32 | switch (pdev->id) { |
| 33 | case 0: |
| 34 | s3c_gpio_cfgpin(S3C64XX_GPD(0), S3C64XX_GPD0_I2S0_CLK); |
| 35 | s3c_gpio_cfgpin(S3C64XX_GPD(1), S3C64XX_GPD1_I2S0_CDCLK); |
| 36 | s3c_gpio_cfgpin(S3C64XX_GPD(2), S3C64XX_GPD2_I2S0_LRCLK); |
| 37 | s3c_gpio_cfgpin(S3C64XX_GPD(3), S3C64XX_GPD3_I2S0_DI); |
| 38 | s3c_gpio_cfgpin(S3C64XX_GPD(4), S3C64XX_GPD4_I2S0_D0); |
| 39 | break; |
| 40 | case 1: |
| 41 | s3c_gpio_cfgpin(S3C64XX_GPE(0), S3C64XX_GPE0_I2S1_CLK); |
| 42 | s3c_gpio_cfgpin(S3C64XX_GPE(1), S3C64XX_GPE1_I2S1_CDCLK); |
| 43 | s3c_gpio_cfgpin(S3C64XX_GPE(2), S3C64XX_GPE2_I2S1_LRCLK); |
| 44 | s3c_gpio_cfgpin(S3C64XX_GPE(3), S3C64XX_GPE3_I2S1_DI); |
| 45 | s3c_gpio_cfgpin(S3C64XX_GPE(4), S3C64XX_GPE4_I2S1_D0); |
Dimitris Papastamos | e4b6b74 | 2010-08-26 16:07:23 +0100 | [diff] [blame^] | 46 | break; |
Jassi Brar | 7126936 | 2010-01-06 15:33:44 +0900 | [diff] [blame] | 47 | default: |
Dimitris Papastamos | e4b6b74 | 2010-08-26 16:07:23 +0100 | [diff] [blame^] | 48 | printk(KERN_DEBUG "Invalid I2S Controller number: %d\n", |
| 49 | pdev->id); |
Jassi Brar | 7126936 | 2010-01-06 15:33:44 +0900 | [diff] [blame] | 50 | return -EINVAL; |
| 51 | } |
| 52 | |
| 53 | return 0; |
| 54 | } |
| 55 | |
| 56 | static int s3c64xx_i2sv4_cfg_gpio(struct platform_device *pdev) |
| 57 | { |
Mark Brown | 1c24522 | 2010-01-20 12:05:55 +0000 | [diff] [blame] | 58 | s3c_gpio_cfgpin(S3C64XX_GPC(4), S3C64XX_GPC4_I2S_V40_DO0); |
| 59 | s3c_gpio_cfgpin(S3C64XX_GPC(5), S3C64XX_GPC5_I2S_V40_DO1); |
| 60 | s3c_gpio_cfgpin(S3C64XX_GPC(7), S3C64XX_GPC7_I2S_V40_DO2); |
Jassi Brar | 7126936 | 2010-01-06 15:33:44 +0900 | [diff] [blame] | 61 | s3c_gpio_cfgpin(S3C64XX_GPH(6), S3C64XX_GPH6_I2S_V40_BCLK); |
| 62 | s3c_gpio_cfgpin(S3C64XX_GPH(7), S3C64XX_GPH7_I2S_V40_CDCLK); |
| 63 | s3c_gpio_cfgpin(S3C64XX_GPH(8), S3C64XX_GPH8_I2S_V40_LRCLK); |
| 64 | s3c_gpio_cfgpin(S3C64XX_GPH(9), S3C64XX_GPH9_I2S_V40_DI); |
| 65 | |
| 66 | return 0; |
| 67 | } |
| 68 | |
Mark Brown | 52da219 | 2009-06-03 20:08:38 +0100 | [diff] [blame] | 69 | static struct resource s3c64xx_iis0_resource[] = { |
| 70 | [0] = { |
| 71 | .start = S3C64XX_PA_IIS0, |
| 72 | .end = S3C64XX_PA_IIS0 + 0x100 - 1, |
| 73 | .flags = IORESOURCE_MEM, |
| 74 | }, |
Jassi Brar | 7126936 | 2010-01-06 15:33:44 +0900 | [diff] [blame] | 75 | [1] = { |
| 76 | .start = DMACH_I2S0_OUT, |
| 77 | .end = DMACH_I2S0_OUT, |
| 78 | .flags = IORESOURCE_DMA, |
| 79 | }, |
| 80 | [2] = { |
| 81 | .start = DMACH_I2S0_IN, |
| 82 | .end = DMACH_I2S0_IN, |
| 83 | .flags = IORESOURCE_DMA, |
| 84 | }, |
| 85 | }; |
| 86 | |
Mark Brown | 8dcdd6e | 2010-01-20 13:06:04 +0000 | [diff] [blame] | 87 | static struct s3c_audio_pdata s3c_i2s0_pdata = { |
Jassi Brar | 7126936 | 2010-01-06 15:33:44 +0900 | [diff] [blame] | 88 | .cfg_gpio = s3c64xx_i2sv3_cfg_gpio, |
Mark Brown | 52da219 | 2009-06-03 20:08:38 +0100 | [diff] [blame] | 89 | }; |
| 90 | |
| 91 | struct platform_device s3c64xx_device_iis0 = { |
| 92 | .name = "s3c64xx-iis", |
| 93 | .id = 0, |
| 94 | .num_resources = ARRAY_SIZE(s3c64xx_iis0_resource), |
| 95 | .resource = s3c64xx_iis0_resource, |
Jassi Brar | 7126936 | 2010-01-06 15:33:44 +0900 | [diff] [blame] | 96 | .dev = { |
| 97 | .platform_data = &s3c_i2s0_pdata, |
| 98 | }, |
Mark Brown | 52da219 | 2009-06-03 20:08:38 +0100 | [diff] [blame] | 99 | }; |
| 100 | EXPORT_SYMBOL(s3c64xx_device_iis0); |
| 101 | |
| 102 | static struct resource s3c64xx_iis1_resource[] = { |
| 103 | [0] = { |
| 104 | .start = S3C64XX_PA_IIS1, |
| 105 | .end = S3C64XX_PA_IIS1 + 0x100 - 1, |
| 106 | .flags = IORESOURCE_MEM, |
| 107 | }, |
Jassi Brar | 7126936 | 2010-01-06 15:33:44 +0900 | [diff] [blame] | 108 | [1] = { |
| 109 | .start = DMACH_I2S1_OUT, |
| 110 | .end = DMACH_I2S1_OUT, |
| 111 | .flags = IORESOURCE_DMA, |
| 112 | }, |
| 113 | [2] = { |
| 114 | .start = DMACH_I2S1_IN, |
| 115 | .end = DMACH_I2S1_IN, |
| 116 | .flags = IORESOURCE_DMA, |
| 117 | }, |
| 118 | }; |
| 119 | |
Mark Brown | 8dcdd6e | 2010-01-20 13:06:04 +0000 | [diff] [blame] | 120 | static struct s3c_audio_pdata s3c_i2s1_pdata = { |
Jassi Brar | 7126936 | 2010-01-06 15:33:44 +0900 | [diff] [blame] | 121 | .cfg_gpio = s3c64xx_i2sv3_cfg_gpio, |
Mark Brown | 52da219 | 2009-06-03 20:08:38 +0100 | [diff] [blame] | 122 | }; |
| 123 | |
| 124 | struct platform_device s3c64xx_device_iis1 = { |
| 125 | .name = "s3c64xx-iis", |
| 126 | .id = 1, |
| 127 | .num_resources = ARRAY_SIZE(s3c64xx_iis1_resource), |
| 128 | .resource = s3c64xx_iis1_resource, |
Jassi Brar | 7126936 | 2010-01-06 15:33:44 +0900 | [diff] [blame] | 129 | .dev = { |
| 130 | .platform_data = &s3c_i2s1_pdata, |
| 131 | }, |
Mark Brown | 52da219 | 2009-06-03 20:08:38 +0100 | [diff] [blame] | 132 | }; |
| 133 | EXPORT_SYMBOL(s3c64xx_device_iis1); |
Mark Brown | d06a49e | 2009-06-03 20:08:39 +0100 | [diff] [blame] | 134 | |
| 135 | static struct resource s3c64xx_iisv4_resource[] = { |
| 136 | [0] = { |
| 137 | .start = S3C64XX_PA_IISV4, |
| 138 | .end = S3C64XX_PA_IISV4 + 0x100 - 1, |
| 139 | .flags = IORESOURCE_MEM, |
| 140 | }, |
Jassi Brar | 7126936 | 2010-01-06 15:33:44 +0900 | [diff] [blame] | 141 | [1] = { |
| 142 | .start = DMACH_HSI_I2SV40_TX, |
| 143 | .end = DMACH_HSI_I2SV40_TX, |
| 144 | .flags = IORESOURCE_DMA, |
| 145 | }, |
| 146 | [2] = { |
| 147 | .start = DMACH_HSI_I2SV40_RX, |
| 148 | .end = DMACH_HSI_I2SV40_RX, |
| 149 | .flags = IORESOURCE_DMA, |
| 150 | }, |
| 151 | }; |
| 152 | |
Mark Brown | 8dcdd6e | 2010-01-20 13:06:04 +0000 | [diff] [blame] | 153 | static struct s3c_audio_pdata s3c_i2sv4_pdata = { |
Jassi Brar | 7126936 | 2010-01-06 15:33:44 +0900 | [diff] [blame] | 154 | .cfg_gpio = s3c64xx_i2sv4_cfg_gpio, |
Mark Brown | d06a49e | 2009-06-03 20:08:39 +0100 | [diff] [blame] | 155 | }; |
| 156 | |
| 157 | struct platform_device s3c64xx_device_iisv4 = { |
| 158 | .name = "s3c64xx-iis-v4", |
| 159 | .id = -1, |
| 160 | .num_resources = ARRAY_SIZE(s3c64xx_iisv4_resource), |
| 161 | .resource = s3c64xx_iisv4_resource, |
Jassi Brar | 7126936 | 2010-01-06 15:33:44 +0900 | [diff] [blame] | 162 | .dev = { |
| 163 | .platform_data = &s3c_i2sv4_pdata, |
| 164 | }, |
Mark Brown | d06a49e | 2009-06-03 20:08:39 +0100 | [diff] [blame] | 165 | }; |
| 166 | EXPORT_SYMBOL(s3c64xx_device_iisv4); |
Jassi Brar | acf1aef | 2009-11-17 16:53:56 +0900 | [diff] [blame] | 167 | |
| 168 | |
| 169 | /* PCM Controller platform_devices */ |
| 170 | |
| 171 | static int s3c64xx_pcm_cfg_gpio(struct platform_device *pdev) |
| 172 | { |
| 173 | switch (pdev->id) { |
| 174 | case 0: |
| 175 | s3c_gpio_cfgpin(S3C64XX_GPD(0), S3C64XX_GPD0_PCM0_SCLK); |
| 176 | s3c_gpio_cfgpin(S3C64XX_GPD(1), S3C64XX_GPD1_PCM0_EXTCLK); |
| 177 | s3c_gpio_cfgpin(S3C64XX_GPD(2), S3C64XX_GPD2_PCM0_FSYNC); |
| 178 | s3c_gpio_cfgpin(S3C64XX_GPD(3), S3C64XX_GPD3_PCM0_SIN); |
| 179 | s3c_gpio_cfgpin(S3C64XX_GPD(4), S3C64XX_GPD4_PCM0_SOUT); |
| 180 | break; |
| 181 | case 1: |
| 182 | s3c_gpio_cfgpin(S3C64XX_GPE(0), S3C64XX_GPE0_PCM1_SCLK); |
| 183 | s3c_gpio_cfgpin(S3C64XX_GPE(1), S3C64XX_GPE1_PCM1_EXTCLK); |
| 184 | s3c_gpio_cfgpin(S3C64XX_GPE(2), S3C64XX_GPE2_PCM1_FSYNC); |
| 185 | s3c_gpio_cfgpin(S3C64XX_GPE(3), S3C64XX_GPE3_PCM1_SIN); |
| 186 | s3c_gpio_cfgpin(S3C64XX_GPE(4), S3C64XX_GPE4_PCM1_SOUT); |
| 187 | break; |
| 188 | default: |
Dimitris Papastamos | e4b6b74 | 2010-08-26 16:07:23 +0100 | [diff] [blame^] | 189 | printk(KERN_DEBUG "Invalid PCM Controller number: %d\n", |
| 190 | pdev->id); |
Jassi Brar | acf1aef | 2009-11-17 16:53:56 +0900 | [diff] [blame] | 191 | return -EINVAL; |
| 192 | } |
| 193 | |
| 194 | return 0; |
| 195 | } |
| 196 | |
| 197 | static struct resource s3c64xx_pcm0_resource[] = { |
| 198 | [0] = { |
| 199 | .start = S3C64XX_PA_PCM0, |
| 200 | .end = S3C64XX_PA_PCM0 + 0x100 - 1, |
| 201 | .flags = IORESOURCE_MEM, |
| 202 | }, |
| 203 | [1] = { |
| 204 | .start = DMACH_PCM0_TX, |
| 205 | .end = DMACH_PCM0_TX, |
| 206 | .flags = IORESOURCE_DMA, |
| 207 | }, |
| 208 | [2] = { |
| 209 | .start = DMACH_PCM0_RX, |
| 210 | .end = DMACH_PCM0_RX, |
| 211 | .flags = IORESOURCE_DMA, |
| 212 | }, |
| 213 | }; |
| 214 | |
Mark Brown | 43f0de8 | 2009-11-27 16:43:53 +0000 | [diff] [blame] | 215 | static struct s3c_audio_pdata s3c_pcm0_pdata = { |
Jassi Brar | acf1aef | 2009-11-17 16:53:56 +0900 | [diff] [blame] | 216 | .cfg_gpio = s3c64xx_pcm_cfg_gpio, |
| 217 | }; |
| 218 | |
| 219 | struct platform_device s3c64xx_device_pcm0 = { |
| 220 | .name = "samsung-pcm", |
| 221 | .id = 0, |
| 222 | .num_resources = ARRAY_SIZE(s3c64xx_pcm0_resource), |
| 223 | .resource = s3c64xx_pcm0_resource, |
| 224 | .dev = { |
| 225 | .platform_data = &s3c_pcm0_pdata, |
| 226 | }, |
| 227 | }; |
| 228 | EXPORT_SYMBOL(s3c64xx_device_pcm0); |
| 229 | |
| 230 | static struct resource s3c64xx_pcm1_resource[] = { |
| 231 | [0] = { |
| 232 | .start = S3C64XX_PA_PCM1, |
| 233 | .end = S3C64XX_PA_PCM1 + 0x100 - 1, |
| 234 | .flags = IORESOURCE_MEM, |
| 235 | }, |
| 236 | [1] = { |
| 237 | .start = DMACH_PCM1_TX, |
| 238 | .end = DMACH_PCM1_TX, |
| 239 | .flags = IORESOURCE_DMA, |
| 240 | }, |
| 241 | [2] = { |
| 242 | .start = DMACH_PCM1_RX, |
| 243 | .end = DMACH_PCM1_RX, |
| 244 | .flags = IORESOURCE_DMA, |
| 245 | }, |
| 246 | }; |
| 247 | |
Mark Brown | 43f0de8 | 2009-11-27 16:43:53 +0000 | [diff] [blame] | 248 | static struct s3c_audio_pdata s3c_pcm1_pdata = { |
Jassi Brar | acf1aef | 2009-11-17 16:53:56 +0900 | [diff] [blame] | 249 | .cfg_gpio = s3c64xx_pcm_cfg_gpio, |
| 250 | }; |
| 251 | |
| 252 | struct platform_device s3c64xx_device_pcm1 = { |
| 253 | .name = "samsung-pcm", |
| 254 | .id = 1, |
| 255 | .num_resources = ARRAY_SIZE(s3c64xx_pcm1_resource), |
| 256 | .resource = s3c64xx_pcm1_resource, |
| 257 | .dev = { |
| 258 | .platform_data = &s3c_pcm1_pdata, |
| 259 | }, |
| 260 | }; |
| 261 | EXPORT_SYMBOL(s3c64xx_device_pcm1); |
Jassi Brar | de6985b | 2010-02-12 10:38:51 +0000 | [diff] [blame] | 262 | |
| 263 | /* AC97 Controller platform devices */ |
| 264 | |
| 265 | static int s3c64xx_ac97_cfg_gpd(struct platform_device *pdev) |
| 266 | { |
| 267 | s3c_gpio_cfgpin(S3C64XX_GPD(0), S3C64XX_GPD0_AC97_BITCLK); |
| 268 | s3c_gpio_cfgpin(S3C64XX_GPD(1), S3C64XX_GPD1_AC97_nRESET); |
| 269 | s3c_gpio_cfgpin(S3C64XX_GPD(2), S3C64XX_GPD2_AC97_SYNC); |
| 270 | s3c_gpio_cfgpin(S3C64XX_GPD(3), S3C64XX_GPD3_AC97_SDI); |
| 271 | s3c_gpio_cfgpin(S3C64XX_GPD(4), S3C64XX_GPD4_AC97_SDO); |
| 272 | |
| 273 | return 0; |
| 274 | } |
| 275 | |
| 276 | static int s3c64xx_ac97_cfg_gpe(struct platform_device *pdev) |
| 277 | { |
| 278 | s3c_gpio_cfgpin(S3C64XX_GPE(0), S3C64XX_GPE0_AC97_BITCLK); |
| 279 | s3c_gpio_cfgpin(S3C64XX_GPE(1), S3C64XX_GPE1_AC97_nRESET); |
| 280 | s3c_gpio_cfgpin(S3C64XX_GPE(2), S3C64XX_GPE2_AC97_SYNC); |
| 281 | s3c_gpio_cfgpin(S3C64XX_GPE(3), S3C64XX_GPE3_AC97_SDI); |
| 282 | s3c_gpio_cfgpin(S3C64XX_GPE(4), S3C64XX_GPE4_AC97_SDO); |
| 283 | |
| 284 | return 0; |
| 285 | } |
| 286 | |
| 287 | static struct resource s3c64xx_ac97_resource[] = { |
| 288 | [0] = { |
| 289 | .start = S3C64XX_PA_AC97, |
| 290 | .end = S3C64XX_PA_AC97 + 0x100 - 1, |
| 291 | .flags = IORESOURCE_MEM, |
| 292 | }, |
| 293 | [1] = { |
| 294 | .start = DMACH_AC97_PCMOUT, |
| 295 | .end = DMACH_AC97_PCMOUT, |
| 296 | .flags = IORESOURCE_DMA, |
| 297 | }, |
| 298 | [2] = { |
| 299 | .start = DMACH_AC97_PCMIN, |
| 300 | .end = DMACH_AC97_PCMIN, |
| 301 | .flags = IORESOURCE_DMA, |
| 302 | }, |
| 303 | [3] = { |
| 304 | .start = DMACH_AC97_MICIN, |
| 305 | .end = DMACH_AC97_MICIN, |
| 306 | .flags = IORESOURCE_DMA, |
| 307 | }, |
| 308 | [4] = { |
| 309 | .start = IRQ_AC97, |
| 310 | .end = IRQ_AC97, |
| 311 | .flags = IORESOURCE_IRQ, |
| 312 | }, |
| 313 | }; |
| 314 | |
| 315 | static struct s3c_audio_pdata s3c_ac97_pdata; |
| 316 | |
| 317 | static u64 s3c64xx_ac97_dmamask = DMA_BIT_MASK(32); |
| 318 | |
| 319 | struct platform_device s3c64xx_device_ac97 = { |
| 320 | .name = "s3c-ac97", |
| 321 | .id = -1, |
| 322 | .num_resources = ARRAY_SIZE(s3c64xx_ac97_resource), |
| 323 | .resource = s3c64xx_ac97_resource, |
| 324 | .dev = { |
| 325 | .platform_data = &s3c_ac97_pdata, |
| 326 | .dma_mask = &s3c64xx_ac97_dmamask, |
| 327 | .coherent_dma_mask = DMA_BIT_MASK(32), |
| 328 | }, |
| 329 | }; |
| 330 | EXPORT_SYMBOL(s3c64xx_device_ac97); |
| 331 | |
| 332 | void __init s3c64xx_ac97_setup_gpio(int num) |
| 333 | { |
| 334 | if (num == S3C64XX_AC97_GPD) |
| 335 | s3c_ac97_pdata.cfg_gpio = s3c64xx_ac97_cfg_gpd; |
| 336 | else |
| 337 | s3c_ac97_pdata.cfg_gpio = s3c64xx_ac97_cfg_gpe; |
| 338 | } |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 339 | |
| 340 | static u64 s3c_device_audio_dmamask = 0xffffffffUL; |
| 341 | |
| 342 | struct platform_device s3c_device_pcm = { |
| 343 | .name = "s3c24xx-pcm-audio", |
| 344 | .id = -1, |
| 345 | .dev = { |
| 346 | .dma_mask = &s3c_device_audio_dmamask, |
| 347 | .coherent_dma_mask = 0xffffffffUL |
| 348 | } |
| 349 | }; |
| 350 | EXPORT_SYMBOL(s3c_device_pcm); |
| 351 | |