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> |
Paul Gortmaker | dc28094 | 2011-07-31 16:17:29 -0400 | [diff] [blame] | 16 | #include <linux/export.h> |
Mark Brown | 52da219 | 2009-06-03 20:08:38 +0100 | [diff] [blame] | 17 | |
| 18 | #include <mach/irqs.h> |
| 19 | #include <mach/map.h> |
Jassi Brar | acf1aef | 2009-11-17 16:53:56 +0900 | [diff] [blame] | 20 | #include <mach/dma.h> |
Mark Brown | 52da219 | 2009-06-03 20:08:38 +0100 | [diff] [blame] | 21 | |
| 22 | #include <plat/devs.h> |
Jassi Brar | acf1aef | 2009-11-17 16:53:56 +0900 | [diff] [blame] | 23 | #include <plat/audio.h> |
Jassi Brar | acf1aef | 2009-11-17 16:53:56 +0900 | [diff] [blame] | 24 | #include <plat/gpio-cfg.h> |
Mark Brown | 52da219 | 2009-06-03 20:08:38 +0100 | [diff] [blame] | 25 | |
Jassi Brar | 6a62bee | 2010-11-19 08:49:44 +0900 | [diff] [blame] | 26 | static const char *rclksrc[] = { |
| 27 | [0] = "iis", |
| 28 | [1] = "audio-bus", |
| 29 | }; |
| 30 | |
| 31 | static int s3c64xx_i2s_cfg_gpio(struct platform_device *pdev) |
Jassi Brar | 7126936 | 2010-01-06 15:33:44 +0900 | [diff] [blame] | 32 | { |
Ben Dooks | 2618b55 | 2010-05-27 15:54:06 +0900 | [diff] [blame] | 33 | unsigned int base; |
| 34 | |
Jassi Brar | 7126936 | 2010-01-06 15:33:44 +0900 | [diff] [blame] | 35 | switch (pdev->id) { |
| 36 | case 0: |
Ben Dooks | 2618b55 | 2010-05-27 15:54:06 +0900 | [diff] [blame] | 37 | base = S3C64XX_GPD(0); |
Jassi Brar | 7126936 | 2010-01-06 15:33:44 +0900 | [diff] [blame] | 38 | break; |
| 39 | case 1: |
Ben Dooks | 2618b55 | 2010-05-27 15:54:06 +0900 | [diff] [blame] | 40 | base = S3C64XX_GPE(0); |
Dimitris Papastamos | e4b6b74 | 2010-08-26 16:07:23 +0100 | [diff] [blame] | 41 | break; |
Jassi Brar | 6a62bee | 2010-11-19 08:49:44 +0900 | [diff] [blame] | 42 | case 2: |
| 43 | s3c_gpio_cfgpin(S3C64XX_GPC(4), S3C_GPIO_SFN(5)); |
| 44 | s3c_gpio_cfgpin(S3C64XX_GPC(5), S3C_GPIO_SFN(5)); |
| 45 | s3c_gpio_cfgpin(S3C64XX_GPC(7), S3C_GPIO_SFN(5)); |
| 46 | s3c_gpio_cfgpin_range(S3C64XX_GPH(6), 4, S3C_GPIO_SFN(5)); |
| 47 | return 0; |
Jassi Brar | 7126936 | 2010-01-06 15:33:44 +0900 | [diff] [blame] | 48 | default: |
Dimitris Papastamos | e4b6b74 | 2010-08-26 16:07:23 +0100 | [diff] [blame] | 49 | printk(KERN_DEBUG "Invalid I2S Controller number: %d\n", |
| 50 | pdev->id); |
Jassi Brar | 7126936 | 2010-01-06 15:33:44 +0900 | [diff] [blame] | 51 | return -EINVAL; |
| 52 | } |
| 53 | |
Ben Dooks | 2618b55 | 2010-05-27 15:54:06 +0900 | [diff] [blame] | 54 | s3c_gpio_cfgpin_range(base, 5, S3C_GPIO_SFN(3)); |
| 55 | |
Jassi Brar | 7126936 | 2010-01-06 15:33:44 +0900 | [diff] [blame] | 56 | return 0; |
| 57 | } |
| 58 | |
Mark Brown | 52da219 | 2009-06-03 20:08:38 +0100 | [diff] [blame] | 59 | static struct resource s3c64xx_iis0_resource[] = { |
| 60 | [0] = { |
| 61 | .start = S3C64XX_PA_IIS0, |
| 62 | .end = S3C64XX_PA_IIS0 + 0x100 - 1, |
| 63 | .flags = IORESOURCE_MEM, |
| 64 | }, |
Jassi Brar | 7126936 | 2010-01-06 15:33:44 +0900 | [diff] [blame] | 65 | [1] = { |
| 66 | .start = DMACH_I2S0_OUT, |
| 67 | .end = DMACH_I2S0_OUT, |
| 68 | .flags = IORESOURCE_DMA, |
| 69 | }, |
| 70 | [2] = { |
| 71 | .start = DMACH_I2S0_IN, |
| 72 | .end = DMACH_I2S0_IN, |
| 73 | .flags = IORESOURCE_DMA, |
| 74 | }, |
| 75 | }; |
| 76 | |
Jassi Brar | 6a62bee | 2010-11-19 08:49:44 +0900 | [diff] [blame] | 77 | static struct s3c_audio_pdata i2sv3_pdata = { |
| 78 | .cfg_gpio = s3c64xx_i2s_cfg_gpio, |
| 79 | .type = { |
| 80 | .i2s = { |
| 81 | .src_clk = rclksrc, |
| 82 | }, |
| 83 | }, |
Mark Brown | 52da219 | 2009-06-03 20:08:38 +0100 | [diff] [blame] | 84 | }; |
| 85 | |
| 86 | struct platform_device s3c64xx_device_iis0 = { |
Jassi Brar | daea9b4 | 2010-11-19 08:49:43 +0900 | [diff] [blame] | 87 | .name = "samsung-i2s", |
Mark Brown | 52da219 | 2009-06-03 20:08:38 +0100 | [diff] [blame] | 88 | .id = 0, |
| 89 | .num_resources = ARRAY_SIZE(s3c64xx_iis0_resource), |
| 90 | .resource = s3c64xx_iis0_resource, |
Jassi Brar | 7126936 | 2010-01-06 15:33:44 +0900 | [diff] [blame] | 91 | .dev = { |
Jassi Brar | 6a62bee | 2010-11-19 08:49:44 +0900 | [diff] [blame] | 92 | .platform_data = &i2sv3_pdata, |
Jassi Brar | 7126936 | 2010-01-06 15:33:44 +0900 | [diff] [blame] | 93 | }, |
Mark Brown | 52da219 | 2009-06-03 20:08:38 +0100 | [diff] [blame] | 94 | }; |
| 95 | EXPORT_SYMBOL(s3c64xx_device_iis0); |
| 96 | |
| 97 | static struct resource s3c64xx_iis1_resource[] = { |
| 98 | [0] = { |
| 99 | .start = S3C64XX_PA_IIS1, |
| 100 | .end = S3C64XX_PA_IIS1 + 0x100 - 1, |
| 101 | .flags = IORESOURCE_MEM, |
| 102 | }, |
Jassi Brar | 7126936 | 2010-01-06 15:33:44 +0900 | [diff] [blame] | 103 | [1] = { |
| 104 | .start = DMACH_I2S1_OUT, |
| 105 | .end = DMACH_I2S1_OUT, |
| 106 | .flags = IORESOURCE_DMA, |
| 107 | }, |
| 108 | [2] = { |
| 109 | .start = DMACH_I2S1_IN, |
| 110 | .end = DMACH_I2S1_IN, |
| 111 | .flags = IORESOURCE_DMA, |
| 112 | }, |
| 113 | }; |
| 114 | |
Mark Brown | 52da219 | 2009-06-03 20:08:38 +0100 | [diff] [blame] | 115 | struct platform_device s3c64xx_device_iis1 = { |
Jassi Brar | daea9b4 | 2010-11-19 08:49:43 +0900 | [diff] [blame] | 116 | .name = "samsung-i2s", |
Mark Brown | 52da219 | 2009-06-03 20:08:38 +0100 | [diff] [blame] | 117 | .id = 1, |
| 118 | .num_resources = ARRAY_SIZE(s3c64xx_iis1_resource), |
| 119 | .resource = s3c64xx_iis1_resource, |
Jassi Brar | 7126936 | 2010-01-06 15:33:44 +0900 | [diff] [blame] | 120 | .dev = { |
Jassi Brar | 6a62bee | 2010-11-19 08:49:44 +0900 | [diff] [blame] | 121 | .platform_data = &i2sv3_pdata, |
Jassi Brar | 7126936 | 2010-01-06 15:33:44 +0900 | [diff] [blame] | 122 | }, |
Mark Brown | 52da219 | 2009-06-03 20:08:38 +0100 | [diff] [blame] | 123 | }; |
| 124 | EXPORT_SYMBOL(s3c64xx_device_iis1); |
Mark Brown | d06a49e | 2009-06-03 20:08:39 +0100 | [diff] [blame] | 125 | |
| 126 | static struct resource s3c64xx_iisv4_resource[] = { |
| 127 | [0] = { |
| 128 | .start = S3C64XX_PA_IISV4, |
| 129 | .end = S3C64XX_PA_IISV4 + 0x100 - 1, |
| 130 | .flags = IORESOURCE_MEM, |
| 131 | }, |
Jassi Brar | 7126936 | 2010-01-06 15:33:44 +0900 | [diff] [blame] | 132 | [1] = { |
| 133 | .start = DMACH_HSI_I2SV40_TX, |
| 134 | .end = DMACH_HSI_I2SV40_TX, |
| 135 | .flags = IORESOURCE_DMA, |
| 136 | }, |
| 137 | [2] = { |
| 138 | .start = DMACH_HSI_I2SV40_RX, |
| 139 | .end = DMACH_HSI_I2SV40_RX, |
| 140 | .flags = IORESOURCE_DMA, |
| 141 | }, |
| 142 | }; |
| 143 | |
Jassi Brar | 6a62bee | 2010-11-19 08:49:44 +0900 | [diff] [blame] | 144 | static struct s3c_audio_pdata i2sv4_pdata = { |
| 145 | .cfg_gpio = s3c64xx_i2s_cfg_gpio, |
| 146 | .type = { |
| 147 | .i2s = { |
| 148 | .quirks = QUIRK_PRI_6CHAN, |
| 149 | .src_clk = rclksrc, |
| 150 | }, |
| 151 | }, |
Mark Brown | d06a49e | 2009-06-03 20:08:39 +0100 | [diff] [blame] | 152 | }; |
| 153 | |
| 154 | struct platform_device s3c64xx_device_iisv4 = { |
Jassi Brar | 6a62bee | 2010-11-19 08:49:44 +0900 | [diff] [blame] | 155 | .name = "samsung-i2s", |
| 156 | .id = 2, |
Mark Brown | d06a49e | 2009-06-03 20:08:39 +0100 | [diff] [blame] | 157 | .num_resources = ARRAY_SIZE(s3c64xx_iisv4_resource), |
| 158 | .resource = s3c64xx_iisv4_resource, |
Jassi Brar | 7126936 | 2010-01-06 15:33:44 +0900 | [diff] [blame] | 159 | .dev = { |
Jassi Brar | 6a62bee | 2010-11-19 08:49:44 +0900 | [diff] [blame] | 160 | .platform_data = &i2sv4_pdata, |
Jassi Brar | 7126936 | 2010-01-06 15:33:44 +0900 | [diff] [blame] | 161 | }, |
Mark Brown | d06a49e | 2009-06-03 20:08:39 +0100 | [diff] [blame] | 162 | }; |
| 163 | EXPORT_SYMBOL(s3c64xx_device_iisv4); |
Jassi Brar | acf1aef | 2009-11-17 16:53:56 +0900 | [diff] [blame] | 164 | |
| 165 | |
| 166 | /* PCM Controller platform_devices */ |
| 167 | |
| 168 | static int s3c64xx_pcm_cfg_gpio(struct platform_device *pdev) |
| 169 | { |
Ben Dooks | 2618b55 | 2010-05-27 15:54:06 +0900 | [diff] [blame] | 170 | unsigned int base; |
| 171 | |
Jassi Brar | acf1aef | 2009-11-17 16:53:56 +0900 | [diff] [blame] | 172 | switch (pdev->id) { |
| 173 | case 0: |
Ben Dooks | 2618b55 | 2010-05-27 15:54:06 +0900 | [diff] [blame] | 174 | base = S3C64XX_GPD(0); |
Jassi Brar | acf1aef | 2009-11-17 16:53:56 +0900 | [diff] [blame] | 175 | break; |
| 176 | case 1: |
Ben Dooks | 2618b55 | 2010-05-27 15:54:06 +0900 | [diff] [blame] | 177 | base = S3C64XX_GPE(0); |
Jassi Brar | acf1aef | 2009-11-17 16:53:56 +0900 | [diff] [blame] | 178 | break; |
| 179 | default: |
Dimitris Papastamos | e4b6b74 | 2010-08-26 16:07:23 +0100 | [diff] [blame] | 180 | printk(KERN_DEBUG "Invalid PCM Controller number: %d\n", |
| 181 | pdev->id); |
Jassi Brar | acf1aef | 2009-11-17 16:53:56 +0900 | [diff] [blame] | 182 | return -EINVAL; |
| 183 | } |
| 184 | |
Ben Dooks | 2618b55 | 2010-05-27 15:54:06 +0900 | [diff] [blame] | 185 | s3c_gpio_cfgpin_range(base, 5, S3C_GPIO_SFN(2)); |
Jassi Brar | acf1aef | 2009-11-17 16:53:56 +0900 | [diff] [blame] | 186 | return 0; |
| 187 | } |
| 188 | |
| 189 | static struct resource s3c64xx_pcm0_resource[] = { |
| 190 | [0] = { |
| 191 | .start = S3C64XX_PA_PCM0, |
| 192 | .end = S3C64XX_PA_PCM0 + 0x100 - 1, |
| 193 | .flags = IORESOURCE_MEM, |
| 194 | }, |
| 195 | [1] = { |
| 196 | .start = DMACH_PCM0_TX, |
| 197 | .end = DMACH_PCM0_TX, |
| 198 | .flags = IORESOURCE_DMA, |
| 199 | }, |
| 200 | [2] = { |
| 201 | .start = DMACH_PCM0_RX, |
| 202 | .end = DMACH_PCM0_RX, |
| 203 | .flags = IORESOURCE_DMA, |
| 204 | }, |
| 205 | }; |
| 206 | |
Mark Brown | 43f0de8 | 2009-11-27 16:43:53 +0000 | [diff] [blame] | 207 | static struct s3c_audio_pdata s3c_pcm0_pdata = { |
Jassi Brar | acf1aef | 2009-11-17 16:53:56 +0900 | [diff] [blame] | 208 | .cfg_gpio = s3c64xx_pcm_cfg_gpio, |
| 209 | }; |
| 210 | |
| 211 | struct platform_device s3c64xx_device_pcm0 = { |
| 212 | .name = "samsung-pcm", |
| 213 | .id = 0, |
| 214 | .num_resources = ARRAY_SIZE(s3c64xx_pcm0_resource), |
| 215 | .resource = s3c64xx_pcm0_resource, |
| 216 | .dev = { |
| 217 | .platform_data = &s3c_pcm0_pdata, |
| 218 | }, |
| 219 | }; |
| 220 | EXPORT_SYMBOL(s3c64xx_device_pcm0); |
| 221 | |
| 222 | static struct resource s3c64xx_pcm1_resource[] = { |
| 223 | [0] = { |
| 224 | .start = S3C64XX_PA_PCM1, |
| 225 | .end = S3C64XX_PA_PCM1 + 0x100 - 1, |
| 226 | .flags = IORESOURCE_MEM, |
| 227 | }, |
| 228 | [1] = { |
| 229 | .start = DMACH_PCM1_TX, |
| 230 | .end = DMACH_PCM1_TX, |
| 231 | .flags = IORESOURCE_DMA, |
| 232 | }, |
| 233 | [2] = { |
| 234 | .start = DMACH_PCM1_RX, |
| 235 | .end = DMACH_PCM1_RX, |
| 236 | .flags = IORESOURCE_DMA, |
| 237 | }, |
| 238 | }; |
| 239 | |
Mark Brown | 43f0de8 | 2009-11-27 16:43:53 +0000 | [diff] [blame] | 240 | static struct s3c_audio_pdata s3c_pcm1_pdata = { |
Jassi Brar | acf1aef | 2009-11-17 16:53:56 +0900 | [diff] [blame] | 241 | .cfg_gpio = s3c64xx_pcm_cfg_gpio, |
| 242 | }; |
| 243 | |
| 244 | struct platform_device s3c64xx_device_pcm1 = { |
| 245 | .name = "samsung-pcm", |
| 246 | .id = 1, |
| 247 | .num_resources = ARRAY_SIZE(s3c64xx_pcm1_resource), |
| 248 | .resource = s3c64xx_pcm1_resource, |
| 249 | .dev = { |
| 250 | .platform_data = &s3c_pcm1_pdata, |
| 251 | }, |
| 252 | }; |
| 253 | EXPORT_SYMBOL(s3c64xx_device_pcm1); |
Jassi Brar | de6985b | 2010-02-12 10:38:51 +0000 | [diff] [blame] | 254 | |
| 255 | /* AC97 Controller platform devices */ |
| 256 | |
| 257 | static int s3c64xx_ac97_cfg_gpd(struct platform_device *pdev) |
| 258 | { |
Ben Dooks | 2618b55 | 2010-05-27 15:54:06 +0900 | [diff] [blame] | 259 | return s3c_gpio_cfgpin_range(S3C64XX_GPD(0), 5, S3C_GPIO_SFN(4)); |
Jassi Brar | de6985b | 2010-02-12 10:38:51 +0000 | [diff] [blame] | 260 | } |
| 261 | |
| 262 | static int s3c64xx_ac97_cfg_gpe(struct platform_device *pdev) |
| 263 | { |
Ben Dooks | 2618b55 | 2010-05-27 15:54:06 +0900 | [diff] [blame] | 264 | return s3c_gpio_cfgpin_range(S3C64XX_GPE(0), 5, S3C_GPIO_SFN(4)); |
Jassi Brar | de6985b | 2010-02-12 10:38:51 +0000 | [diff] [blame] | 265 | } |
| 266 | |
| 267 | static struct resource s3c64xx_ac97_resource[] = { |
| 268 | [0] = { |
| 269 | .start = S3C64XX_PA_AC97, |
| 270 | .end = S3C64XX_PA_AC97 + 0x100 - 1, |
| 271 | .flags = IORESOURCE_MEM, |
| 272 | }, |
| 273 | [1] = { |
| 274 | .start = DMACH_AC97_PCMOUT, |
| 275 | .end = DMACH_AC97_PCMOUT, |
| 276 | .flags = IORESOURCE_DMA, |
| 277 | }, |
| 278 | [2] = { |
| 279 | .start = DMACH_AC97_PCMIN, |
| 280 | .end = DMACH_AC97_PCMIN, |
| 281 | .flags = IORESOURCE_DMA, |
| 282 | }, |
| 283 | [3] = { |
| 284 | .start = DMACH_AC97_MICIN, |
| 285 | .end = DMACH_AC97_MICIN, |
| 286 | .flags = IORESOURCE_DMA, |
| 287 | }, |
| 288 | [4] = { |
| 289 | .start = IRQ_AC97, |
| 290 | .end = IRQ_AC97, |
| 291 | .flags = IORESOURCE_IRQ, |
| 292 | }, |
| 293 | }; |
| 294 | |
| 295 | static struct s3c_audio_pdata s3c_ac97_pdata; |
| 296 | |
| 297 | static u64 s3c64xx_ac97_dmamask = DMA_BIT_MASK(32); |
| 298 | |
| 299 | struct platform_device s3c64xx_device_ac97 = { |
Jassi Brar | e610467 | 2010-11-22 15:36:00 +0900 | [diff] [blame] | 300 | .name = "samsung-ac97", |
Jassi Brar | de6985b | 2010-02-12 10:38:51 +0000 | [diff] [blame] | 301 | .id = -1, |
| 302 | .num_resources = ARRAY_SIZE(s3c64xx_ac97_resource), |
| 303 | .resource = s3c64xx_ac97_resource, |
| 304 | .dev = { |
| 305 | .platform_data = &s3c_ac97_pdata, |
| 306 | .dma_mask = &s3c64xx_ac97_dmamask, |
| 307 | .coherent_dma_mask = DMA_BIT_MASK(32), |
| 308 | }, |
| 309 | }; |
| 310 | EXPORT_SYMBOL(s3c64xx_device_ac97); |
| 311 | |
| 312 | void __init s3c64xx_ac97_setup_gpio(int num) |
| 313 | { |
| 314 | if (num == S3C64XX_AC97_GPD) |
| 315 | s3c_ac97_pdata.cfg_gpio = s3c64xx_ac97_cfg_gpd; |
| 316 | else |
| 317 | s3c_ac97_pdata.cfg_gpio = s3c64xx_ac97_cfg_gpe; |
| 318 | } |