| .. | .. |
|---|
| 1 | | -/* |
|---|
| 2 | | - * h1940-uda1380.c -- ALSA Soc Audio Layer |
|---|
| 3 | | - * |
|---|
| 4 | | - * Copyright (c) 2010 Arnaud Patard <arnaud.patard@rtp-net.org> |
|---|
| 5 | | - * Copyright (c) 2010 Vasily Khoruzhick <anarsoul@gmail.com> |
|---|
| 6 | | - * |
|---|
| 7 | | - * Based on version from Arnaud Patard <arnaud.patard@rtp-net.org> |
|---|
| 8 | | - * |
|---|
| 9 | | - * This program is free software; you can redistribute it and/or modify it |
|---|
| 10 | | - * under the terms of the GNU General Public License as published by the |
|---|
| 11 | | - * Free Software Foundation; either version 2 of the License, or (at your |
|---|
| 12 | | - * option) any later version. |
|---|
| 13 | | - * |
|---|
| 14 | | - */ |
|---|
| 1 | +// SPDX-License-Identifier: GPL-2.0+ |
|---|
| 2 | +// |
|---|
| 3 | +// h1940_uda1380.c - ALSA SoC Audio Layer |
|---|
| 4 | +// |
|---|
| 5 | +// Copyright (c) 2010 Arnaud Patard <arnaud.patard@rtp-net.org> |
|---|
| 6 | +// Copyright (c) 2010 Vasily Khoruzhick <anarsoul@gmail.com> |
|---|
| 7 | +// |
|---|
| 8 | +// Based on version from Arnaud Patard <arnaud.patard@rtp-net.org> |
|---|
| 15 | 9 | |
|---|
| 16 | 10 | #include <linux/types.h> |
|---|
| 17 | | -#include <linux/gpio.h> |
|---|
| 11 | +#include <linux/gpio/consumer.h> |
|---|
| 18 | 12 | #include <linux/module.h> |
|---|
| 19 | 13 | |
|---|
| 20 | 14 | #include <sound/soc.h> |
|---|
| 21 | 15 | #include <sound/jack.h> |
|---|
| 22 | 16 | |
|---|
| 23 | 17 | #include "regs-iis.h" |
|---|
| 24 | | -#include <asm/mach-types.h> |
|---|
| 25 | | - |
|---|
| 26 | | -#include <mach/gpio-samsung.h> |
|---|
| 27 | 18 | #include "s3c24xx-i2s.h" |
|---|
| 28 | 19 | |
|---|
| 29 | 20 | static const unsigned int rates[] = { |
|---|
| .. | .. |
|---|
| 36 | 27 | .count = ARRAY_SIZE(rates), |
|---|
| 37 | 28 | .list = rates, |
|---|
| 38 | 29 | }; |
|---|
| 30 | + |
|---|
| 31 | +static struct gpio_desc *gpiod_speaker_power; |
|---|
| 39 | 32 | |
|---|
| 40 | 33 | static struct snd_soc_jack hp_jack; |
|---|
| 41 | 34 | |
|---|
| .. | .. |
|---|
| 53 | 46 | |
|---|
| 54 | 47 | static struct snd_soc_jack_gpio hp_jack_gpios[] = { |
|---|
| 55 | 48 | { |
|---|
| 56 | | - .gpio = S3C2410_GPG(4), |
|---|
| 57 | 49 | .name = "hp-gpio", |
|---|
| 58 | 50 | .report = SND_JACK_HEADPHONE, |
|---|
| 59 | 51 | .invert = 1, |
|---|
| .. | .. |
|---|
| 73 | 65 | static int h1940_hw_params(struct snd_pcm_substream *substream, |
|---|
| 74 | 66 | struct snd_pcm_hw_params *params) |
|---|
| 75 | 67 | { |
|---|
| 76 | | - struct snd_soc_pcm_runtime *rtd = substream->private_data; |
|---|
| 77 | | - struct snd_soc_dai *cpu_dai = rtd->cpu_dai; |
|---|
| 68 | + struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream); |
|---|
| 69 | + struct snd_soc_dai *cpu_dai = asoc_rtd_to_cpu(rtd, 0); |
|---|
| 78 | 70 | int div; |
|---|
| 79 | 71 | int ret; |
|---|
| 80 | 72 | unsigned int rate = params_rate(params); |
|---|
| .. | .. |
|---|
| 129 | 121 | struct snd_kcontrol *kcontrol, int event) |
|---|
| 130 | 122 | { |
|---|
| 131 | 123 | if (SND_SOC_DAPM_EVENT_ON(event)) |
|---|
| 132 | | - gpio_set_value(S3C_GPIO_END + 9, 1); |
|---|
| 124 | + gpiod_set_value(gpiod_speaker_power, 1); |
|---|
| 133 | 125 | else |
|---|
| 134 | | - gpio_set_value(S3C_GPIO_END + 9, 0); |
|---|
| 126 | + gpiod_set_value(gpiod_speaker_power, 0); |
|---|
| 135 | 127 | |
|---|
| 136 | 128 | return 0; |
|---|
| 137 | 129 | } |
|---|
| .. | .. |
|---|
| 157 | 149 | {"VINM", NULL, "Mic Jack"}, |
|---|
| 158 | 150 | }; |
|---|
| 159 | 151 | |
|---|
| 160 | | -static struct platform_device *s3c24xx_snd_device; |
|---|
| 161 | | - |
|---|
| 162 | 152 | static int h1940_uda1380_init(struct snd_soc_pcm_runtime *rtd) |
|---|
| 163 | 153 | { |
|---|
| 164 | 154 | snd_soc_card_jack_new(rtd->card, "Headphone Jack", SND_JACK_HEADPHONE, |
|---|
| .. | .. |
|---|
| 171 | 161 | } |
|---|
| 172 | 162 | |
|---|
| 173 | 163 | /* s3c24xx digital audio interface glue - connects codec <--> CPU */ |
|---|
| 164 | +SND_SOC_DAILINK_DEFS(uda1380, |
|---|
| 165 | + DAILINK_COMP_ARRAY(COMP_CPU("s3c24xx-iis")), |
|---|
| 166 | + DAILINK_COMP_ARRAY(COMP_CODEC("uda1380-codec.0-001a", "uda1380-hifi")), |
|---|
| 167 | + DAILINK_COMP_ARRAY(COMP_PLATFORM("s3c24xx-iis"))); |
|---|
| 168 | + |
|---|
| 174 | 169 | static struct snd_soc_dai_link h1940_uda1380_dai[] = { |
|---|
| 175 | 170 | { |
|---|
| 176 | 171 | .name = "uda1380", |
|---|
| 177 | 172 | .stream_name = "UDA1380 Duplex", |
|---|
| 178 | | - .cpu_dai_name = "s3c24xx-iis", |
|---|
| 179 | | - .codec_dai_name = "uda1380-hifi", |
|---|
| 180 | 173 | .init = h1940_uda1380_init, |
|---|
| 181 | | - .platform_name = "s3c24xx-iis", |
|---|
| 182 | | - .codec_name = "uda1380-codec.0-001a", |
|---|
| 183 | 174 | .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF | |
|---|
| 184 | 175 | SND_SOC_DAIFMT_CBS_CFS, |
|---|
| 185 | 176 | .ops = &h1940_ops, |
|---|
| 177 | + SND_SOC_DAILINK_REG(uda1380), |
|---|
| 186 | 178 | }, |
|---|
| 187 | 179 | }; |
|---|
| 188 | 180 | |
|---|
| .. | .. |
|---|
| 198 | 190 | .num_dapm_routes = ARRAY_SIZE(audio_map), |
|---|
| 199 | 191 | }; |
|---|
| 200 | 192 | |
|---|
| 201 | | -static int __init h1940_init(void) |
|---|
| 193 | +static int h1940_probe(struct platform_device *pdev) |
|---|
| 202 | 194 | { |
|---|
| 203 | | - int ret; |
|---|
| 195 | + struct device *dev = &pdev->dev; |
|---|
| 204 | 196 | |
|---|
| 205 | | - if (!machine_is_h1940()) |
|---|
| 206 | | - return -ENODEV; |
|---|
| 197 | + h1940_asoc.dev = dev; |
|---|
| 198 | + hp_jack_gpios[0].gpiod_dev = dev; |
|---|
| 199 | + gpiod_speaker_power = devm_gpiod_get(&pdev->dev, "speaker-power", |
|---|
| 200 | + GPIOD_OUT_LOW); |
|---|
| 207 | 201 | |
|---|
| 208 | | - /* configure some gpios */ |
|---|
| 209 | | - ret = gpio_request(S3C_GPIO_END + 9, "speaker-power"); |
|---|
| 210 | | - if (ret) |
|---|
| 211 | | - goto err_out; |
|---|
| 212 | | - |
|---|
| 213 | | - ret = gpio_direction_output(S3C_GPIO_END + 9, 0); |
|---|
| 214 | | - if (ret) |
|---|
| 215 | | - goto err_gpio; |
|---|
| 216 | | - |
|---|
| 217 | | - s3c24xx_snd_device = platform_device_alloc("soc-audio", -1); |
|---|
| 218 | | - if (!s3c24xx_snd_device) { |
|---|
| 219 | | - ret = -ENOMEM; |
|---|
| 220 | | - goto err_gpio; |
|---|
| 202 | + if (IS_ERR(gpiod_speaker_power)) { |
|---|
| 203 | + dev_err(dev, "Could not get gpio\n"); |
|---|
| 204 | + return PTR_ERR(gpiod_speaker_power); |
|---|
| 221 | 205 | } |
|---|
| 222 | 206 | |
|---|
| 223 | | - platform_set_drvdata(s3c24xx_snd_device, &h1940_asoc); |
|---|
| 224 | | - ret = platform_device_add(s3c24xx_snd_device); |
|---|
| 225 | | - |
|---|
| 226 | | - if (ret) |
|---|
| 227 | | - goto err_plat; |
|---|
| 228 | | - |
|---|
| 229 | | - return 0; |
|---|
| 230 | | - |
|---|
| 231 | | -err_plat: |
|---|
| 232 | | - platform_device_put(s3c24xx_snd_device); |
|---|
| 233 | | -err_gpio: |
|---|
| 234 | | - gpio_free(S3C_GPIO_END + 9); |
|---|
| 235 | | - |
|---|
| 236 | | -err_out: |
|---|
| 237 | | - return ret; |
|---|
| 207 | + return devm_snd_soc_register_card(dev, &h1940_asoc); |
|---|
| 238 | 208 | } |
|---|
| 239 | 209 | |
|---|
| 240 | | -static void __exit h1940_exit(void) |
|---|
| 241 | | -{ |
|---|
| 242 | | - platform_device_unregister(s3c24xx_snd_device); |
|---|
| 243 | | - gpio_free(S3C_GPIO_END + 9); |
|---|
| 244 | | -} |
|---|
| 245 | | - |
|---|
| 246 | | -module_init(h1940_init); |
|---|
| 247 | | -module_exit(h1940_exit); |
|---|
| 210 | +static struct platform_driver h1940_audio_driver = { |
|---|
| 211 | + .driver = { |
|---|
| 212 | + .name = "h1940-audio", |
|---|
| 213 | + .pm = &snd_soc_pm_ops, |
|---|
| 214 | + }, |
|---|
| 215 | + .probe = h1940_probe, |
|---|
| 216 | +}; |
|---|
| 217 | +module_platform_driver(h1940_audio_driver); |
|---|
| 248 | 218 | |
|---|
| 249 | 219 | /* Module information */ |
|---|
| 250 | 220 | MODULE_AUTHOR("Arnaud Patard, Vasily Khoruzhick"); |
|---|
| 251 | 221 | MODULE_DESCRIPTION("ALSA SoC H1940"); |
|---|
| 252 | 222 | MODULE_LICENSE("GPL"); |
|---|
| 223 | +MODULE_ALIAS("platform:h1940-audio"); |
|---|