aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorArnd Bergmann <arnd@arndb.de>2014-07-09 05:09:42 -0400
committerArnd Bergmann <arnd@arndb.de>2015-12-01 15:50:24 -0500
commitdf0cc2d1e15f739a428f630feb62ce6f040a4e19 (patch)
tree7c0144ec3d6b25346177c41a70d2e0378fcda198
parent94eb81ad43cedbb8354a14130329f06853b31a60 (diff)
ASoC: samsung/smartq: use dynamic registration
As a prerequisite for moving s3c64xx into multiplatform configurations, we need to change the smartq audio driver to stop using hardcoded gpio numbers from the header file, and instead pass the gpio data through platform_data. In order to do that, we also move the code to use module_platform_driver and register the platform device using platform_device_register_simple and register the gpios through the gpiod API. Signed-off-by: Arnd Bergmann <arnd@arndb.de> Acked-by: Mark Brown <broonie@kernel.org> Reviewed-by: Krzysztof Kozlowski <k.kozlowski@samsung.com>
-rw-r--r--arch/arm/mach-s3c64xx/mach-smartq.c13
-rw-r--r--sound/soc/samsung/smartq_wm8987.c76
2 files changed, 39 insertions, 50 deletions
diff --git a/arch/arm/mach-s3c64xx/mach-smartq.c b/arch/arm/mach-s3c64xx/mach-smartq.c
index acdfb5fac40f..96784e7f894a 100644
--- a/arch/arm/mach-s3c64xx/mach-smartq.c
+++ b/arch/arm/mach-s3c64xx/mach-smartq.c
@@ -12,6 +12,7 @@
12#include <linux/delay.h> 12#include <linux/delay.h>
13#include <linux/fb.h> 13#include <linux/fb.h>
14#include <linux/gpio.h> 14#include <linux/gpio.h>
15#include <linux/gpio/machine.h>
15#include <linux/init.h> 16#include <linux/init.h>
16#include <linux/platform_device.h> 17#include <linux/platform_device.h>
17#include <linux/pwm.h> 18#include <linux/pwm.h>
@@ -383,6 +384,15 @@ void __init smartq_map_io(void)
383 smartq_lcd_mode_set(); 384 smartq_lcd_mode_set();
384} 385}
385 386
387static struct gpiod_lookup_table smartq_audio_gpios = {
388 .dev_id = "smartq-audio",
389 .table = {
390 GPIO_LOOKUP("GPL", 12, "headphone detect", 0),
391 GPIO_LOOKUP("GPK", 12, "amplifiers shutdown", 0),
392 { },
393 },
394};
395
386void __init smartq_machine_init(void) 396void __init smartq_machine_init(void)
387{ 397{
388 s3c_i2c0_set_platdata(NULL); 398 s3c_i2c0_set_platdata(NULL);
@@ -402,4 +412,7 @@ void __init smartq_machine_init(void)
402 412
403 pwm_add_table(smartq_pwm_lookup, ARRAY_SIZE(smartq_pwm_lookup)); 413 pwm_add_table(smartq_pwm_lookup, ARRAY_SIZE(smartq_pwm_lookup));
404 platform_add_devices(smartq_devices, ARRAY_SIZE(smartq_devices)); 414 platform_add_devices(smartq_devices, ARRAY_SIZE(smartq_devices));
415
416 gpiod_add_lookup_table(&smartq_audio_gpios);
417 platform_device_register_simple("smartq-audio", -1, NULL, 0);
405} 418}
diff --git a/sound/soc/samsung/smartq_wm8987.c b/sound/soc/samsung/smartq_wm8987.c
index a0fe37fbed9f..425ee2ba37f0 100644
--- a/sound/soc/samsung/smartq_wm8987.c
+++ b/sound/soc/samsung/smartq_wm8987.c
@@ -13,15 +13,12 @@
13 * 13 *
14 */ 14 */
15 15
16#include <linux/gpio.h> 16#include <linux/gpio/consumer.h>
17#include <linux/module.h> 17#include <linux/module.h>
18 18
19#include <sound/soc.h> 19#include <sound/soc.h>
20#include <sound/jack.h> 20#include <sound/jack.h>
21 21
22#include <mach/gpio-samsung.h>
23#include <asm/mach-types.h>
24
25#include "i2s.h" 22#include "i2s.h"
26#include "../codecs/wm8750.h" 23#include "../codecs/wm8750.h"
27 24
@@ -96,7 +93,7 @@ static struct snd_soc_jack_pin smartq_jack_pins[] = {
96 93
97static struct snd_soc_jack_gpio smartq_jack_gpios[] = { 94static struct snd_soc_jack_gpio smartq_jack_gpios[] = {
98 { 95 {
99 .gpio = S3C64XX_GPL(12), 96 .gpio = -1,
100 .name = "headphone detect", 97 .name = "headphone detect",
101 .report = SND_JACK_HEADPHONE, 98 .report = SND_JACK_HEADPHONE,
102 .debounce_time = 200, 99 .debounce_time = 200,
@@ -113,7 +110,9 @@ static int smartq_speaker_event(struct snd_soc_dapm_widget *w,
113 struct snd_kcontrol *k, 110 struct snd_kcontrol *k,
114 int event) 111 int event)
115{ 112{
116 gpio_set_value(S3C64XX_GPK(12), SND_SOC_DAPM_EVENT_OFF(event)); 113 struct gpio_desc *gpio = snd_soc_card_get_drvdata(&snd_soc_smartq);
114
115 gpiod_set_value(gpio, SND_SOC_DAPM_EVENT_OFF(event));
117 116
118 return 0; 117 return 0;
119} 118}
@@ -199,62 +198,39 @@ static struct snd_soc_card snd_soc_smartq = {
199 .num_controls = ARRAY_SIZE(wm8987_smartq_controls), 198 .num_controls = ARRAY_SIZE(wm8987_smartq_controls),
200}; 199};
201 200
202static struct platform_device *smartq_snd_device; 201static int smartq_probe(struct platform_device *pdev)
203
204static int __init smartq_init(void)
205{ 202{
203 struct gpio_desc *gpio;
206 int ret; 204 int ret;
207 205
208 if (!machine_is_smartq7() && !machine_is_smartq5()) { 206 platform_set_drvdata(pdev, &snd_soc_smartq);
209 pr_info("Only SmartQ is supported by this ASoC driver\n");
210 return -ENODEV;
211 }
212
213 smartq_snd_device = platform_device_alloc("soc-audio", -1);
214 if (!smartq_snd_device)
215 return -ENOMEM;
216
217 platform_set_drvdata(smartq_snd_device, &snd_soc_smartq);
218
219 ret = platform_device_add(smartq_snd_device);
220 if (ret) {
221 platform_device_put(smartq_snd_device);
222 return ret;
223 }
224 207
225 /* Initialise GPIOs used by amplifiers */ 208 /* Initialise GPIOs used by amplifiers */
226 ret = gpio_request(S3C64XX_GPK(12), "amplifiers shutdown"); 209 gpio = devm_gpiod_get(&pdev->dev, "amplifiers shutdown",
227 if (ret) { 210 GPIOD_OUT_HIGH);
228 dev_err(&smartq_snd_device->dev, "Failed to register GPK12\n"); 211 if (IS_ERR(gpio)) {
229 goto err_unregister_device; 212 dev_err(&pdev->dev, "Failed to register GPK12\n");
213 ret = PTR_ERR(gpio);
214 goto out;
230 } 215 }
216 snd_soc_card_set_drvdata(&snd_soc_smartq, gpio);
231 217
232 /* Disable amplifiers */ 218 ret = devm_snd_soc_register_card(&pdev->dev, &snd_soc_smartq);
233 ret = gpio_direction_output(S3C64XX_GPK(12), 1); 219 if (ret)
234 if (ret) { 220 dev_err(&pdev->dev, "Failed to register card\n");
235 dev_err(&smartq_snd_device->dev, "Failed to configure GPK12\n");
236 goto err_free_gpio_amp_shut;
237 }
238
239 return 0;
240
241err_free_gpio_amp_shut:
242 gpio_free(S3C64XX_GPK(12));
243err_unregister_device:
244 platform_device_unregister(smartq_snd_device);
245 221
222out:
246 return ret; 223 return ret;
247} 224}
248 225
249static void __exit smartq_exit(void) 226static struct platform_driver smartq_driver = {
250{ 227 .driver = {
251 gpio_free(S3C64XX_GPK(12)); 228 .name = "smartq-audio",
252 229 },
253 platform_device_unregister(smartq_snd_device); 230 .probe = smartq_probe,
254} 231};
255 232
256module_init(smartq_init); 233module_platform_driver(smartq_driver);
257module_exit(smartq_exit);
258 234
259/* Module information */ 235/* Module information */
260MODULE_AUTHOR("Maurus Cuelenaere <mcuelenaere@gmail.com>"); 236MODULE_AUTHOR("Maurus Cuelenaere <mcuelenaere@gmail.com>");