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