171b9114dSArnd Bergmann // SPDX-License-Identifier: GPL-2.0 271b9114dSArnd Bergmann // 371b9114dSArnd Bergmann // Copyright 2009 Wolfson Microelectronics 471b9114dSArnd Bergmann // Mark Brown <broonie@opensource.wolfsonmicro.com> 571b9114dSArnd Bergmann 671b9114dSArnd Bergmann #include <linux/kernel.h> 771b9114dSArnd Bergmann #include <linux/string.h> 871b9114dSArnd Bergmann #include <linux/platform_device.h> 971b9114dSArnd Bergmann #include <linux/dma-mapping.h> 1071b9114dSArnd Bergmann #include <linux/gpio.h> 1171b9114dSArnd Bergmann #include <linux/export.h> 1271b9114dSArnd Bergmann 1371b9114dSArnd Bergmann #include <mach/irqs.h> 14*c6ff132dSArnd Bergmann #include "map.h" 1571b9114dSArnd Bergmann 16*c6ff132dSArnd Bergmann #include "devs.h" 1771b9114dSArnd Bergmann #include <linux/platform_data/asoc-s3c.h> 18*c6ff132dSArnd Bergmann #include "gpio-cfg.h" 19*c6ff132dSArnd Bergmann #include "gpio-samsung.h" 2071b9114dSArnd Bergmann 2171b9114dSArnd Bergmann static int s3c64xx_i2s_cfg_gpio(struct platform_device *pdev) 2271b9114dSArnd Bergmann { 2371b9114dSArnd Bergmann unsigned int base; 2471b9114dSArnd Bergmann 2571b9114dSArnd Bergmann switch (pdev->id) { 2671b9114dSArnd Bergmann case 0: 2771b9114dSArnd Bergmann base = S3C64XX_GPD(0); 2871b9114dSArnd Bergmann break; 2971b9114dSArnd Bergmann case 1: 3071b9114dSArnd Bergmann base = S3C64XX_GPE(0); 3171b9114dSArnd Bergmann break; 3271b9114dSArnd Bergmann case 2: 3371b9114dSArnd Bergmann s3c_gpio_cfgpin(S3C64XX_GPC(4), S3C_GPIO_SFN(5)); 3471b9114dSArnd Bergmann s3c_gpio_cfgpin(S3C64XX_GPC(5), S3C_GPIO_SFN(5)); 3571b9114dSArnd Bergmann s3c_gpio_cfgpin(S3C64XX_GPC(7), S3C_GPIO_SFN(5)); 3671b9114dSArnd Bergmann s3c_gpio_cfgpin_range(S3C64XX_GPH(6), 4, S3C_GPIO_SFN(5)); 3771b9114dSArnd Bergmann return 0; 3871b9114dSArnd Bergmann default: 3971b9114dSArnd Bergmann printk(KERN_DEBUG "Invalid I2S Controller number: %d\n", 4071b9114dSArnd Bergmann pdev->id); 4171b9114dSArnd Bergmann return -EINVAL; 4271b9114dSArnd Bergmann } 4371b9114dSArnd Bergmann 4471b9114dSArnd Bergmann s3c_gpio_cfgpin_range(base, 5, S3C_GPIO_SFN(3)); 4571b9114dSArnd Bergmann 4671b9114dSArnd Bergmann return 0; 4771b9114dSArnd Bergmann } 4871b9114dSArnd Bergmann 4971b9114dSArnd Bergmann static struct resource s3c64xx_iis0_resource[] = { 5071b9114dSArnd Bergmann [0] = DEFINE_RES_MEM(S3C64XX_PA_IIS0, SZ_256), 5171b9114dSArnd Bergmann }; 5271b9114dSArnd Bergmann 5371b9114dSArnd Bergmann static struct s3c_audio_pdata i2s0_pdata = { 5471b9114dSArnd Bergmann .cfg_gpio = s3c64xx_i2s_cfg_gpio, 5571b9114dSArnd Bergmann }; 5671b9114dSArnd Bergmann 5771b9114dSArnd Bergmann struct platform_device s3c64xx_device_iis0 = { 5871b9114dSArnd Bergmann .name = "samsung-i2s", 5971b9114dSArnd Bergmann .id = 0, 6071b9114dSArnd Bergmann .num_resources = ARRAY_SIZE(s3c64xx_iis0_resource), 6171b9114dSArnd Bergmann .resource = s3c64xx_iis0_resource, 6271b9114dSArnd Bergmann .dev = { 6371b9114dSArnd Bergmann .platform_data = &i2s0_pdata, 6471b9114dSArnd Bergmann }, 6571b9114dSArnd Bergmann }; 6671b9114dSArnd Bergmann EXPORT_SYMBOL(s3c64xx_device_iis0); 6771b9114dSArnd Bergmann 6871b9114dSArnd Bergmann static struct resource s3c64xx_iis1_resource[] = { 6971b9114dSArnd Bergmann [0] = DEFINE_RES_MEM(S3C64XX_PA_IIS1, SZ_256), 7071b9114dSArnd Bergmann }; 7171b9114dSArnd Bergmann 7271b9114dSArnd Bergmann static struct s3c_audio_pdata i2s1_pdata = { 7371b9114dSArnd Bergmann .cfg_gpio = s3c64xx_i2s_cfg_gpio, 7471b9114dSArnd Bergmann }; 7571b9114dSArnd Bergmann 7671b9114dSArnd Bergmann struct platform_device s3c64xx_device_iis1 = { 7771b9114dSArnd Bergmann .name = "samsung-i2s", 7871b9114dSArnd Bergmann .id = 1, 7971b9114dSArnd Bergmann .num_resources = ARRAY_SIZE(s3c64xx_iis1_resource), 8071b9114dSArnd Bergmann .resource = s3c64xx_iis1_resource, 8171b9114dSArnd Bergmann .dev = { 8271b9114dSArnd Bergmann .platform_data = &i2s1_pdata, 8371b9114dSArnd Bergmann }, 8471b9114dSArnd Bergmann }; 8571b9114dSArnd Bergmann EXPORT_SYMBOL(s3c64xx_device_iis1); 8671b9114dSArnd Bergmann 8771b9114dSArnd Bergmann static struct resource s3c64xx_iisv4_resource[] = { 8871b9114dSArnd Bergmann [0] = DEFINE_RES_MEM(S3C64XX_PA_IISV4, SZ_256), 8971b9114dSArnd Bergmann }; 9071b9114dSArnd Bergmann 9171b9114dSArnd Bergmann static struct s3c_audio_pdata i2sv4_pdata = { 9271b9114dSArnd Bergmann .cfg_gpio = s3c64xx_i2s_cfg_gpio, 9371b9114dSArnd Bergmann .type = { 9471b9114dSArnd Bergmann .quirks = QUIRK_PRI_6CHAN, 9571b9114dSArnd Bergmann }, 9671b9114dSArnd Bergmann }; 9771b9114dSArnd Bergmann 9871b9114dSArnd Bergmann struct platform_device s3c64xx_device_iisv4 = { 9971b9114dSArnd Bergmann .name = "samsung-i2s", 10071b9114dSArnd Bergmann .id = 2, 10171b9114dSArnd Bergmann .num_resources = ARRAY_SIZE(s3c64xx_iisv4_resource), 10271b9114dSArnd Bergmann .resource = s3c64xx_iisv4_resource, 10371b9114dSArnd Bergmann .dev = { 10471b9114dSArnd Bergmann .platform_data = &i2sv4_pdata, 10571b9114dSArnd Bergmann }, 10671b9114dSArnd Bergmann }; 10771b9114dSArnd Bergmann EXPORT_SYMBOL(s3c64xx_device_iisv4); 10871b9114dSArnd Bergmann 10971b9114dSArnd Bergmann 11071b9114dSArnd Bergmann /* PCM Controller platform_devices */ 11171b9114dSArnd Bergmann 11271b9114dSArnd Bergmann static int s3c64xx_pcm_cfg_gpio(struct platform_device *pdev) 11371b9114dSArnd Bergmann { 11471b9114dSArnd Bergmann unsigned int base; 11571b9114dSArnd Bergmann 11671b9114dSArnd Bergmann switch (pdev->id) { 11771b9114dSArnd Bergmann case 0: 11871b9114dSArnd Bergmann base = S3C64XX_GPD(0); 11971b9114dSArnd Bergmann break; 12071b9114dSArnd Bergmann case 1: 12171b9114dSArnd Bergmann base = S3C64XX_GPE(0); 12271b9114dSArnd Bergmann break; 12371b9114dSArnd Bergmann default: 12471b9114dSArnd Bergmann printk(KERN_DEBUG "Invalid PCM Controller number: %d\n", 12571b9114dSArnd Bergmann pdev->id); 12671b9114dSArnd Bergmann return -EINVAL; 12771b9114dSArnd Bergmann } 12871b9114dSArnd Bergmann 12971b9114dSArnd Bergmann s3c_gpio_cfgpin_range(base, 5, S3C_GPIO_SFN(2)); 13071b9114dSArnd Bergmann return 0; 13171b9114dSArnd Bergmann } 13271b9114dSArnd Bergmann 13371b9114dSArnd Bergmann static struct resource s3c64xx_pcm0_resource[] = { 13471b9114dSArnd Bergmann [0] = DEFINE_RES_MEM(S3C64XX_PA_PCM0, SZ_256), 13571b9114dSArnd Bergmann }; 13671b9114dSArnd Bergmann 13771b9114dSArnd Bergmann static struct s3c_audio_pdata s3c_pcm0_pdata = { 13871b9114dSArnd Bergmann .cfg_gpio = s3c64xx_pcm_cfg_gpio, 13971b9114dSArnd Bergmann }; 14071b9114dSArnd Bergmann 14171b9114dSArnd Bergmann struct platform_device s3c64xx_device_pcm0 = { 14271b9114dSArnd Bergmann .name = "samsung-pcm", 14371b9114dSArnd Bergmann .id = 0, 14471b9114dSArnd Bergmann .num_resources = ARRAY_SIZE(s3c64xx_pcm0_resource), 14571b9114dSArnd Bergmann .resource = s3c64xx_pcm0_resource, 14671b9114dSArnd Bergmann .dev = { 14771b9114dSArnd Bergmann .platform_data = &s3c_pcm0_pdata, 14871b9114dSArnd Bergmann }, 14971b9114dSArnd Bergmann }; 15071b9114dSArnd Bergmann EXPORT_SYMBOL(s3c64xx_device_pcm0); 15171b9114dSArnd Bergmann 15271b9114dSArnd Bergmann static struct resource s3c64xx_pcm1_resource[] = { 15371b9114dSArnd Bergmann [0] = DEFINE_RES_MEM(S3C64XX_PA_PCM1, SZ_256), 15471b9114dSArnd Bergmann }; 15571b9114dSArnd Bergmann 15671b9114dSArnd Bergmann static struct s3c_audio_pdata s3c_pcm1_pdata = { 15771b9114dSArnd Bergmann .cfg_gpio = s3c64xx_pcm_cfg_gpio, 15871b9114dSArnd Bergmann }; 15971b9114dSArnd Bergmann 16071b9114dSArnd Bergmann struct platform_device s3c64xx_device_pcm1 = { 16171b9114dSArnd Bergmann .name = "samsung-pcm", 16271b9114dSArnd Bergmann .id = 1, 16371b9114dSArnd Bergmann .num_resources = ARRAY_SIZE(s3c64xx_pcm1_resource), 16471b9114dSArnd Bergmann .resource = s3c64xx_pcm1_resource, 16571b9114dSArnd Bergmann .dev = { 16671b9114dSArnd Bergmann .platform_data = &s3c_pcm1_pdata, 16771b9114dSArnd Bergmann }, 16871b9114dSArnd Bergmann }; 16971b9114dSArnd Bergmann EXPORT_SYMBOL(s3c64xx_device_pcm1); 17071b9114dSArnd Bergmann 17171b9114dSArnd Bergmann /* AC97 Controller platform devices */ 17271b9114dSArnd Bergmann 17371b9114dSArnd Bergmann static int s3c64xx_ac97_cfg_gpd(struct platform_device *pdev) 17471b9114dSArnd Bergmann { 17571b9114dSArnd Bergmann return s3c_gpio_cfgpin_range(S3C64XX_GPD(0), 5, S3C_GPIO_SFN(4)); 17671b9114dSArnd Bergmann } 17771b9114dSArnd Bergmann 17871b9114dSArnd Bergmann static int s3c64xx_ac97_cfg_gpe(struct platform_device *pdev) 17971b9114dSArnd Bergmann { 18071b9114dSArnd Bergmann return s3c_gpio_cfgpin_range(S3C64XX_GPE(0), 5, S3C_GPIO_SFN(4)); 18171b9114dSArnd Bergmann } 18271b9114dSArnd Bergmann 18371b9114dSArnd Bergmann static struct resource s3c64xx_ac97_resource[] = { 18471b9114dSArnd Bergmann [0] = DEFINE_RES_MEM(S3C64XX_PA_AC97, SZ_256), 18571b9114dSArnd Bergmann [1] = DEFINE_RES_IRQ(IRQ_AC97), 18671b9114dSArnd Bergmann }; 18771b9114dSArnd Bergmann 18871b9114dSArnd Bergmann static struct s3c_audio_pdata s3c_ac97_pdata = { 18971b9114dSArnd Bergmann }; 19071b9114dSArnd Bergmann 19171b9114dSArnd Bergmann static u64 s3c64xx_ac97_dmamask = DMA_BIT_MASK(32); 19271b9114dSArnd Bergmann 19371b9114dSArnd Bergmann struct platform_device s3c64xx_device_ac97 = { 19471b9114dSArnd Bergmann .name = "samsung-ac97", 19571b9114dSArnd Bergmann .id = -1, 19671b9114dSArnd Bergmann .num_resources = ARRAY_SIZE(s3c64xx_ac97_resource), 19771b9114dSArnd Bergmann .resource = s3c64xx_ac97_resource, 19871b9114dSArnd Bergmann .dev = { 19971b9114dSArnd Bergmann .platform_data = &s3c_ac97_pdata, 20071b9114dSArnd Bergmann .dma_mask = &s3c64xx_ac97_dmamask, 20171b9114dSArnd Bergmann .coherent_dma_mask = DMA_BIT_MASK(32), 20271b9114dSArnd Bergmann }, 20371b9114dSArnd Bergmann }; 20471b9114dSArnd Bergmann EXPORT_SYMBOL(s3c64xx_device_ac97); 20571b9114dSArnd Bergmann 20671b9114dSArnd Bergmann void __init s3c64xx_ac97_setup_gpio(int num) 20771b9114dSArnd Bergmann { 20871b9114dSArnd Bergmann if (num == S3C64XX_AC97_GPD) 20971b9114dSArnd Bergmann s3c_ac97_pdata.cfg_gpio = s3c64xx_ac97_cfg_gpd; 21071b9114dSArnd Bergmann else 21171b9114dSArnd Bergmann s3c_ac97_pdata.cfg_gpio = s3c64xx_ac97_cfg_gpe; 21271b9114dSArnd Bergmann } 213