Lars-Peter Clausen | 5898dd9 | 2010-06-19 16:52:51 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2009, Lars-Peter Clausen <lars@metafoo.de> |
| 3 | * |
| 4 | * This program is free software; you can redistribute it and/or modify |
| 5 | * it under the terms of the GNU General Public License version 2 as |
| 6 | * published by the Free Software Foundation. |
| 7 | * |
| 8 | * You should have received a copy of the GNU General Public License along |
| 9 | * with this program; if not, write to the Free Software Foundation, Inc., |
| 10 | * 675 Mass Ave, Cambridge, MA 02139, USA. |
| 11 | * |
| 12 | */ |
| 13 | |
| 14 | #include <linux/module.h> |
| 15 | #include <linux/moduleparam.h> |
| 16 | #include <linux/timer.h> |
| 17 | #include <linux/interrupt.h> |
| 18 | #include <linux/platform_device.h> |
| 19 | #include <sound/core.h> |
| 20 | #include <sound/pcm.h> |
| 21 | #include <sound/soc.h> |
Lars-Peter Clausen | 218e18a | 2014-04-22 22:46:35 +0200 | [diff] [blame] | 22 | #include <linux/gpio/consumer.h> |
Lars-Peter Clausen | 5898dd9 | 2010-06-19 16:52:51 +0200 | [diff] [blame] | 23 | |
Lars-Peter Clausen | 218e18a | 2014-04-22 22:46:35 +0200 | [diff] [blame] | 24 | struct qi_lb60 { |
| 25 | struct gpio_desc *snd_gpio; |
| 26 | struct gpio_desc *amp_gpio; |
| 27 | }; |
Lars-Peter Clausen | 5898dd9 | 2010-06-19 16:52:51 +0200 | [diff] [blame] | 28 | |
| 29 | static int qi_lb60_spk_event(struct snd_soc_dapm_widget *widget, |
| 30 | struct snd_kcontrol *ctrl, int event) |
| 31 | { |
Lars-Peter Clausen | 218e18a | 2014-04-22 22:46:35 +0200 | [diff] [blame] | 32 | struct qi_lb60 *qi_lb60 = snd_soc_card_get_drvdata(widget->dapm->card); |
Lars-Peter Clausen | 621206b | 2011-04-12 19:31:05 +0200 | [diff] [blame] | 33 | int on = !SND_SOC_DAPM_EVENT_OFF(event); |
Lars-Peter Clausen | 5898dd9 | 2010-06-19 16:52:51 +0200 | [diff] [blame] | 34 | |
Lars-Peter Clausen | 218e18a | 2014-04-22 22:46:35 +0200 | [diff] [blame] | 35 | gpiod_set_value_cansleep(qi_lb60->snd_gpio, on); |
| 36 | gpiod_set_value_cansleep(qi_lb60->amp_gpio, on); |
Lars-Peter Clausen | 5898dd9 | 2010-06-19 16:52:51 +0200 | [diff] [blame] | 37 | |
| 38 | return 0; |
| 39 | } |
| 40 | |
| 41 | static const struct snd_soc_dapm_widget qi_lb60_widgets[] = { |
| 42 | SND_SOC_DAPM_SPK("Speaker", qi_lb60_spk_event), |
| 43 | SND_SOC_DAPM_MIC("Mic", NULL), |
| 44 | }; |
| 45 | |
| 46 | static const struct snd_soc_dapm_route qi_lb60_routes[] = { |
| 47 | {"Mic", NULL, "MIC"}, |
| 48 | {"Speaker", NULL, "LOUT"}, |
| 49 | {"Speaker", NULL, "ROUT"}, |
| 50 | }; |
| 51 | |
Lars-Peter Clausen | 5898dd9 | 2010-06-19 16:52:51 +0200 | [diff] [blame] | 52 | static struct snd_soc_dai_link qi_lb60_dai = { |
| 53 | .name = "jz4740", |
| 54 | .stream_name = "jz4740", |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 55 | .cpu_dai_name = "jz4740-i2s", |
Lars-Peter Clausen | 0406a40 | 2013-12-03 18:53:03 +0100 | [diff] [blame] | 56 | .platform_name = "jz4740-i2s", |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 57 | .codec_dai_name = "jz4740-hifi", |
| 58 | .codec_name = "jz4740-codec", |
Lars-Peter Clausen | 0e746d7 | 2014-04-22 22:46:33 +0200 | [diff] [blame] | 59 | .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF | |
| 60 | SND_SOC_DAIFMT_CBM_CFM, |
Lars-Peter Clausen | 5898dd9 | 2010-06-19 16:52:51 +0200 | [diff] [blame] | 61 | }; |
| 62 | |
Lars-Peter Clausen | 218e18a | 2014-04-22 22:46:35 +0200 | [diff] [blame] | 63 | static struct snd_soc_card qi_lb60_card = { |
Lars-Peter Clausen | 5898dd9 | 2010-06-19 16:52:51 +0200 | [diff] [blame] | 64 | .name = "QI LB60", |
Axel Lin | 1d9d25b | 2011-12-23 14:48:19 +0800 | [diff] [blame] | 65 | .owner = THIS_MODULE, |
Lars-Peter Clausen | 5898dd9 | 2010-06-19 16:52:51 +0200 | [diff] [blame] | 66 | .dai_link = &qi_lb60_dai, |
| 67 | .num_links = 1, |
Lars-Peter Clausen | 1331969 | 2011-04-12 19:31:03 +0200 | [diff] [blame] | 68 | |
| 69 | .dapm_widgets = qi_lb60_widgets, |
| 70 | .num_dapm_widgets = ARRAY_SIZE(qi_lb60_widgets), |
| 71 | .dapm_routes = qi_lb60_routes, |
| 72 | .num_dapm_routes = ARRAY_SIZE(qi_lb60_routes), |
Lars-Peter Clausen | b8fb837 | 2014-04-22 22:46:32 +0200 | [diff] [blame] | 73 | .fully_routed = true, |
Lars-Peter Clausen | 5898dd9 | 2010-06-19 16:52:51 +0200 | [diff] [blame] | 74 | }; |
| 75 | |
Bill Pemberton | d6a29e3 | 2012-12-07 09:26:24 -0500 | [diff] [blame] | 76 | static int qi_lb60_probe(struct platform_device *pdev) |
Lars-Peter Clausen | 5898dd9 | 2010-06-19 16:52:51 +0200 | [diff] [blame] | 77 | { |
Lars-Peter Clausen | 218e18a | 2014-04-22 22:46:35 +0200 | [diff] [blame] | 78 | struct qi_lb60 *qi_lb60; |
| 79 | struct snd_soc_card *card = &qi_lb60_card; |
Lars-Peter Clausen | 5898dd9 | 2010-06-19 16:52:51 +0200 | [diff] [blame] | 80 | int ret; |
| 81 | |
Lars-Peter Clausen | 218e18a | 2014-04-22 22:46:35 +0200 | [diff] [blame] | 82 | qi_lb60 = devm_kzalloc(&pdev->dev, sizeof(*qi_lb60), GFP_KERNEL); |
| 83 | if (!qi_lb60) |
| 84 | return -ENOMEM; |
| 85 | |
| 86 | qi_lb60->snd_gpio = devm_gpiod_get(&pdev->dev, "snd"); |
| 87 | if (IS_ERR(qi_lb60->snd_gpio)) |
| 88 | return PTR_ERR(qi_lb60->snd_gpio); |
| 89 | ret = gpiod_direction_output(qi_lb60->snd_gpio, 0); |
| 90 | if (ret) |
| 91 | return ret; |
| 92 | |
| 93 | qi_lb60->amp_gpio = devm_gpiod_get(&pdev->dev, "amp"); |
| 94 | if (IS_ERR(qi_lb60->amp_gpio)) |
| 95 | return PTR_ERR(qi_lb60->amp_gpio); |
| 96 | ret = gpiod_direction_output(qi_lb60->amp_gpio, 0); |
Axel Lin | b33005f3 | 2012-01-06 11:30:10 +0800 | [diff] [blame] | 97 | if (ret) |
| 98 | return ret; |
| 99 | |
| 100 | card->dev = &pdev->dev; |
| 101 | |
Lars-Peter Clausen | 218e18a | 2014-04-22 22:46:35 +0200 | [diff] [blame] | 102 | snd_soc_card_set_drvdata(card, qi_lb60); |
Lars-Peter Clausen | 5898dd9 | 2010-06-19 16:52:51 +0200 | [diff] [blame] | 103 | |
Lars-Peter Clausen | 218e18a | 2014-04-22 22:46:35 +0200 | [diff] [blame] | 104 | return devm_snd_soc_register_card(&pdev->dev, card); |
Lars-Peter Clausen | 5898dd9 | 2010-06-19 16:52:51 +0200 | [diff] [blame] | 105 | } |
Axel Lin | b33005f3 | 2012-01-06 11:30:10 +0800 | [diff] [blame] | 106 | |
| 107 | static struct platform_driver qi_lb60_driver = { |
| 108 | .driver = { |
| 109 | .name = "qi-lb60-audio", |
| 110 | .owner = THIS_MODULE, |
| 111 | }, |
| 112 | .probe = qi_lb60_probe, |
Axel Lin | b33005f3 | 2012-01-06 11:30:10 +0800 | [diff] [blame] | 113 | }; |
| 114 | |
| 115 | module_platform_driver(qi_lb60_driver); |
Lars-Peter Clausen | 5898dd9 | 2010-06-19 16:52:51 +0200 | [diff] [blame] | 116 | |
| 117 | MODULE_AUTHOR("Lars-Peter Clausen <lars@metafoo.de>"); |
| 118 | MODULE_DESCRIPTION("ALSA SoC QI LB60 Audio support"); |
| 119 | MODULE_LICENSE("GPL v2"); |
Axel Lin | b33005f3 | 2012-01-06 11:30:10 +0800 | [diff] [blame] | 120 | MODULE_ALIAS("platform:qi-lb60-audio"); |