| .. | .. |
|---|
| 1 | | -/* |
|---|
| 2 | | - * rx1950.c -- ALSA Soc Audio Layer |
|---|
| 3 | | - * |
|---|
| 4 | | - * Copyright (c) 2010 Vasily Khoruzhick <anarsoul@gmail.com> |
|---|
| 5 | | - * |
|---|
| 6 | | - * Based on smdk2440.c and magician.c |
|---|
| 7 | | - * |
|---|
| 8 | | - * Authors: Graeme Gregory graeme.gregory@wolfsonmicro.com |
|---|
| 9 | | - * Philipp Zabel <philipp.zabel@gmail.com> |
|---|
| 10 | | - * Denis Grigoriev <dgreenday@gmail.com> |
|---|
| 11 | | - * Vasily Khoruzhick <anarsoul@gmail.com> |
|---|
| 12 | | - * |
|---|
| 13 | | - * This program is free software; you can redistribute it and/or modify it |
|---|
| 14 | | - * under the terms of the GNU General Public License as published by the |
|---|
| 15 | | - * Free Software Foundation; either version 2 of the License, or (at your |
|---|
| 16 | | - * option) any later version. |
|---|
| 17 | | - * |
|---|
| 18 | | - */ |
|---|
| 1 | +// SPDX-License-Identifier: GPL-2.0+ |
|---|
| 2 | +// |
|---|
| 3 | +// rx1950.c - ALSA SoC Audio Layer |
|---|
| 4 | +// |
|---|
| 5 | +// Copyright (c) 2010 Vasily Khoruzhick <anarsoul@gmail.com> |
|---|
| 6 | +// |
|---|
| 7 | +// Based on smdk2440.c and magician.c |
|---|
| 8 | +// |
|---|
| 9 | +// Authors: Graeme Gregory graeme.gregory@wolfsonmicro.com |
|---|
| 10 | +// Philipp Zabel <philipp.zabel@gmail.com> |
|---|
| 11 | +// Denis Grigoriev <dgreenday@gmail.com> |
|---|
| 12 | +// Vasily Khoruzhick <anarsoul@gmail.com> |
|---|
| 19 | 13 | |
|---|
| 20 | 14 | #include <linux/types.h> |
|---|
| 21 | | -#include <linux/gpio.h> |
|---|
| 15 | +#include <linux/gpio/consumer.h> |
|---|
| 22 | 16 | #include <linux/module.h> |
|---|
| 23 | 17 | |
|---|
| 24 | 18 | #include <sound/soc.h> |
|---|
| 25 | 19 | #include <sound/jack.h> |
|---|
| 26 | 20 | |
|---|
| 27 | | -#include <mach/gpio-samsung.h> |
|---|
| 28 | 21 | #include "regs-iis.h" |
|---|
| 29 | | -#include <asm/mach-types.h> |
|---|
| 30 | | - |
|---|
| 31 | 22 | #include "s3c24xx-i2s.h" |
|---|
| 32 | 23 | |
|---|
| 33 | 24 | static int rx1950_uda1380_init(struct snd_soc_pcm_runtime *rtd); |
|---|
| .. | .. |
|---|
| 64 | 55 | |
|---|
| 65 | 56 | static struct snd_soc_jack_gpio hp_jack_gpios[] = { |
|---|
| 66 | 57 | [0] = { |
|---|
| 67 | | - .gpio = S3C2410_GPG(12), |
|---|
| 68 | 58 | .name = "hp-gpio", |
|---|
| 69 | 59 | .report = SND_JACK_HEADPHONE, |
|---|
| 70 | 60 | .invert = 1, |
|---|
| .. | .. |
|---|
| 78 | 68 | }; |
|---|
| 79 | 69 | |
|---|
| 80 | 70 | /* s3c24xx digital audio interface glue - connects codec <--> CPU */ |
|---|
| 71 | +SND_SOC_DAILINK_DEFS(uda1380, |
|---|
| 72 | + DAILINK_COMP_ARRAY(COMP_CPU("s3c24xx-iis")), |
|---|
| 73 | + DAILINK_COMP_ARRAY(COMP_CODEC("uda1380-codec.0-001a", |
|---|
| 74 | + "uda1380-hifi")), |
|---|
| 75 | + DAILINK_COMP_ARRAY(COMP_PLATFORM("s3c24xx-iis"))); |
|---|
| 76 | + |
|---|
| 81 | 77 | static struct snd_soc_dai_link rx1950_uda1380_dai[] = { |
|---|
| 82 | 78 | { |
|---|
| 83 | 79 | .name = "uda1380", |
|---|
| 84 | 80 | .stream_name = "UDA1380 Duplex", |
|---|
| 85 | | - .cpu_dai_name = "s3c24xx-iis", |
|---|
| 86 | | - .codec_dai_name = "uda1380-hifi", |
|---|
| 87 | 81 | .init = rx1950_uda1380_init, |
|---|
| 88 | | - .platform_name = "s3c24xx-iis", |
|---|
| 89 | | - .codec_name = "uda1380-codec.0-001a", |
|---|
| 90 | 82 | .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF | |
|---|
| 91 | 83 | SND_SOC_DAIFMT_CBS_CFS, |
|---|
| 92 | 84 | .ops = &rx1950_ops, |
|---|
| 85 | + SND_SOC_DAILINK_REG(uda1380), |
|---|
| 93 | 86 | }, |
|---|
| 94 | 87 | }; |
|---|
| 95 | 88 | |
|---|
| .. | .. |
|---|
| 126 | 119 | .num_dapm_routes = ARRAY_SIZE(audio_map), |
|---|
| 127 | 120 | }; |
|---|
| 128 | 121 | |
|---|
| 129 | | -static struct platform_device *s3c24xx_snd_device; |
|---|
| 130 | | - |
|---|
| 131 | 122 | static int rx1950_startup(struct snd_pcm_substream *substream) |
|---|
| 132 | 123 | { |
|---|
| 133 | 124 | struct snd_pcm_runtime *runtime = substream->runtime; |
|---|
| .. | .. |
|---|
| 137 | 128 | &hw_rates); |
|---|
| 138 | 129 | } |
|---|
| 139 | 130 | |
|---|
| 131 | +static struct gpio_desc *gpiod_speaker_power; |
|---|
| 132 | + |
|---|
| 140 | 133 | static int rx1950_spk_power(struct snd_soc_dapm_widget *w, |
|---|
| 141 | 134 | struct snd_kcontrol *kcontrol, int event) |
|---|
| 142 | 135 | { |
|---|
| 143 | 136 | if (SND_SOC_DAPM_EVENT_ON(event)) |
|---|
| 144 | | - gpio_set_value(S3C2410_GPA(1), 1); |
|---|
| 137 | + gpiod_set_value(gpiod_speaker_power, 1); |
|---|
| 145 | 138 | else |
|---|
| 146 | | - gpio_set_value(S3C2410_GPA(1), 0); |
|---|
| 139 | + gpiod_set_value(gpiod_speaker_power, 0); |
|---|
| 147 | 140 | |
|---|
| 148 | 141 | return 0; |
|---|
| 149 | 142 | } |
|---|
| .. | .. |
|---|
| 151 | 144 | static int rx1950_hw_params(struct snd_pcm_substream *substream, |
|---|
| 152 | 145 | struct snd_pcm_hw_params *params) |
|---|
| 153 | 146 | { |
|---|
| 154 | | - struct snd_soc_pcm_runtime *rtd = substream->private_data; |
|---|
| 155 | | - struct snd_soc_dai *cpu_dai = rtd->cpu_dai; |
|---|
| 147 | + struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream); |
|---|
| 148 | + struct snd_soc_dai *cpu_dai = asoc_rtd_to_cpu(rtd, 0); |
|---|
| 156 | 149 | int div; |
|---|
| 157 | 150 | int ret; |
|---|
| 158 | 151 | unsigned int rate = params_rate(params); |
|---|
| .. | .. |
|---|
| 217 | 210 | return 0; |
|---|
| 218 | 211 | } |
|---|
| 219 | 212 | |
|---|
| 220 | | -static int __init rx1950_init(void) |
|---|
| 213 | +static int rx1950_probe(struct platform_device *pdev) |
|---|
| 221 | 214 | { |
|---|
| 222 | | - int ret; |
|---|
| 223 | | - |
|---|
| 224 | | - if (!machine_is_rx1950()) |
|---|
| 225 | | - return -ENODEV; |
|---|
| 215 | + struct device *dev = &pdev->dev; |
|---|
| 226 | 216 | |
|---|
| 227 | 217 | /* configure some gpios */ |
|---|
| 228 | | - ret = gpio_request(S3C2410_GPA(1), "speaker-power"); |
|---|
| 229 | | - if (ret) |
|---|
| 230 | | - goto err_gpio; |
|---|
| 231 | | - |
|---|
| 232 | | - ret = gpio_direction_output(S3C2410_GPA(1), 0); |
|---|
| 233 | | - if (ret) |
|---|
| 234 | | - goto err_gpio_conf; |
|---|
| 235 | | - |
|---|
| 236 | | - s3c24xx_snd_device = platform_device_alloc("soc-audio", -1); |
|---|
| 237 | | - if (!s3c24xx_snd_device) { |
|---|
| 238 | | - ret = -ENOMEM; |
|---|
| 239 | | - goto err_plat_alloc; |
|---|
| 218 | + gpiod_speaker_power = devm_gpiod_get(dev, "speaker-power", GPIOD_OUT_LOW); |
|---|
| 219 | + if (IS_ERR(gpiod_speaker_power)) { |
|---|
| 220 | + dev_err(dev, "cannot get gpio\n"); |
|---|
| 221 | + return PTR_ERR(gpiod_speaker_power); |
|---|
| 240 | 222 | } |
|---|
| 241 | 223 | |
|---|
| 242 | | - platform_set_drvdata(s3c24xx_snd_device, &rx1950_asoc); |
|---|
| 243 | | - ret = platform_device_add(s3c24xx_snd_device); |
|---|
| 224 | + hp_jack_gpios[0].gpiod_dev = dev; |
|---|
| 225 | + rx1950_asoc.dev = dev; |
|---|
| 244 | 226 | |
|---|
| 245 | | - if (ret) { |
|---|
| 246 | | - platform_device_put(s3c24xx_snd_device); |
|---|
| 247 | | - goto err_plat_add; |
|---|
| 248 | | - } |
|---|
| 249 | | - |
|---|
| 250 | | - return 0; |
|---|
| 251 | | - |
|---|
| 252 | | -err_plat_add: |
|---|
| 253 | | -err_plat_alloc: |
|---|
| 254 | | -err_gpio_conf: |
|---|
| 255 | | - gpio_free(S3C2410_GPA(1)); |
|---|
| 256 | | - |
|---|
| 257 | | -err_gpio: |
|---|
| 258 | | - return ret; |
|---|
| 227 | + return devm_snd_soc_register_card(dev, &rx1950_asoc); |
|---|
| 259 | 228 | } |
|---|
| 260 | 229 | |
|---|
| 261 | | -static void __exit rx1950_exit(void) |
|---|
| 262 | | -{ |
|---|
| 263 | | - platform_device_unregister(s3c24xx_snd_device); |
|---|
| 264 | | - gpio_free(S3C2410_GPA(1)); |
|---|
| 265 | | -} |
|---|
| 230 | +static struct platform_driver rx1950_audio = { |
|---|
| 231 | + .driver = { |
|---|
| 232 | + .name = "rx1950-audio", |
|---|
| 233 | + .pm = &snd_soc_pm_ops, |
|---|
| 234 | + }, |
|---|
| 235 | + .probe = rx1950_probe, |
|---|
| 236 | +}; |
|---|
| 266 | 237 | |
|---|
| 267 | | -module_init(rx1950_init); |
|---|
| 268 | | -module_exit(rx1950_exit); |
|---|
| 238 | +module_platform_driver(rx1950_audio); |
|---|
| 269 | 239 | |
|---|
| 270 | 240 | /* Module information */ |
|---|
| 271 | 241 | MODULE_AUTHOR("Vasily Khoruzhick"); |
|---|
| 272 | 242 | MODULE_DESCRIPTION("ALSA SoC RX1950"); |
|---|
| 273 | 243 | MODULE_LICENSE("GPL"); |
|---|
| 244 | +MODULE_ALIAS("platform:rx1950-audio"); |
|---|