1 // SPDX-License-Identifier: GPL-2.0
2 //
3 // Copyright (c) 2009 Simtec Electronics
4 //	http://armlinux.simtec.co.uk/
5 //	Ben Dooks <ben@simtec.co.uk>
6 //
7 // Audio setup for various Simtec S3C24XX implementations
8 
9 #include <linux/kernel.h>
10 #include <linux/interrupt.h>
11 #include <linux/init.h>
12 #include <linux/device.h>
13 #include <linux/io.h>
14 
15 #include "regs-gpio.h"
16 #include "gpio-samsung.h"
17 #include "gpio-cfg.h"
18 
19 #include <linux/platform_data/asoc-s3c24xx_simtec.h>
20 #include "devs.h"
21 
22 #include "bast.h"
23 #include "simtec.h"
24 
25 /* platform ops for audio */
26 
simtec_audio_startup_lrroute(void)27 static void simtec_audio_startup_lrroute(void)
28 {
29 	unsigned int tmp;
30 	unsigned long flags;
31 
32 	local_irq_save(flags);
33 
34 	tmp = __raw_readb(BAST_VA_CTRL1);
35 	tmp &= ~BAST_CPLD_CTRL1_LRMASK;
36 	tmp |= BAST_CPLD_CTRL1_LRCDAC;
37 	__raw_writeb(tmp, BAST_VA_CTRL1);
38 
39 	local_irq_restore(flags);
40 }
41 
42 static struct s3c24xx_audio_simtec_pdata simtec_audio_platdata;
43 static char our_name[32];
44 
45 static struct platform_device simtec_audio_dev = {
46 	.name	= our_name,
47 	.id	= -1,
48 	.dev	= {
49 		.parent		= &s3c_device_iis.dev,
50 		.platform_data	= &simtec_audio_platdata,
51 	},
52 };
53 
simtec_audio_add(const char * name,bool has_lr_routing,struct s3c24xx_audio_simtec_pdata * spd)54 int __init simtec_audio_add(const char *name, bool has_lr_routing,
55 			    struct s3c24xx_audio_simtec_pdata *spd)
56 {
57 	if (!name)
58 		name = "tlv320aic23";
59 
60 	snprintf(our_name, sizeof(our_name)-1, "s3c24xx-simtec-%s", name);
61 
62 	/* copy platform data so the source can be __initdata */
63 	if (spd)
64 		simtec_audio_platdata = *spd;
65 
66 	if (has_lr_routing)
67 		simtec_audio_platdata.startup = simtec_audio_startup_lrroute;
68 
69 	/* Configure the I2S pins (GPE0...GPE4) in correct mode */
70 	s3c_gpio_cfgall_range(S3C2410_GPE(0), 5, S3C_GPIO_SFN(2),
71 			      S3C_GPIO_PULL_NONE);
72 
73 	platform_device_register(&s3c_device_iis);
74 	platform_device_register(&simtec_audio_dev);
75 	return 0;
76 }
77