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 | 5898dd9 | 2010-06-19 16:52:51 +0200 | [diff] [blame] | 22 | #include <linux/gpio.h> |
| 23 | |
Lars-Peter Clausen | 5898dd9 | 2010-06-19 16:52:51 +0200 | [diff] [blame] | 24 | #define QI_LB60_SND_GPIO JZ_GPIO_PORTB(29) |
| 25 | #define QI_LB60_AMP_GPIO JZ_GPIO_PORTD(4) |
| 26 | |
| 27 | static int qi_lb60_spk_event(struct snd_soc_dapm_widget *widget, |
| 28 | struct snd_kcontrol *ctrl, int event) |
| 29 | { |
Lars-Peter Clausen | 621206b | 2011-04-12 19:31:05 +0200 | [diff] [blame] | 30 | int on = !SND_SOC_DAPM_EVENT_OFF(event); |
Lars-Peter Clausen | 5898dd9 | 2010-06-19 16:52:51 +0200 | [diff] [blame] | 31 | |
| 32 | gpio_set_value(QI_LB60_SND_GPIO, on); |
| 33 | gpio_set_value(QI_LB60_AMP_GPIO, on); |
| 34 | |
| 35 | return 0; |
| 36 | } |
| 37 | |
| 38 | static const struct snd_soc_dapm_widget qi_lb60_widgets[] = { |
| 39 | SND_SOC_DAPM_SPK("Speaker", qi_lb60_spk_event), |
| 40 | SND_SOC_DAPM_MIC("Mic", NULL), |
| 41 | }; |
| 42 | |
| 43 | static const struct snd_soc_dapm_route qi_lb60_routes[] = { |
| 44 | {"Mic", NULL, "MIC"}, |
| 45 | {"Speaker", NULL, "LOUT"}, |
| 46 | {"Speaker", NULL, "ROUT"}, |
| 47 | }; |
| 48 | |
| 49 | #define QI_LB60_DAIFMT (SND_SOC_DAIFMT_I2S | \ |
| 50 | SND_SOC_DAIFMT_NB_NF | \ |
| 51 | SND_SOC_DAIFMT_CBM_CFM) |
| 52 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 53 | static int qi_lb60_codec_init(struct snd_soc_pcm_runtime *rtd) |
Lars-Peter Clausen | 5898dd9 | 2010-06-19 16:52:51 +0200 | [diff] [blame] | 54 | { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 55 | struct snd_soc_codec *codec = rtd->codec; |
| 56 | struct snd_soc_dai *cpu_dai = rtd->cpu_dai; |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 57 | struct snd_soc_dapm_context *dapm = &codec->dapm; |
Lars-Peter Clausen | 5898dd9 | 2010-06-19 16:52:51 +0200 | [diff] [blame] | 58 | int ret; |
Lars-Peter Clausen | 5898dd9 | 2010-06-19 16:52:51 +0200 | [diff] [blame] | 59 | |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 60 | snd_soc_dapm_nc_pin(dapm, "LIN"); |
| 61 | snd_soc_dapm_nc_pin(dapm, "RIN"); |
Lars-Peter Clausen | 5898dd9 | 2010-06-19 16:52:51 +0200 | [diff] [blame] | 62 | |
| 63 | ret = snd_soc_dai_set_fmt(cpu_dai, QI_LB60_DAIFMT); |
| 64 | if (ret < 0) { |
| 65 | dev_err(codec->dev, "Failed to set cpu dai format: %d\n", ret); |
| 66 | return ret; |
| 67 | } |
| 68 | |
Lars-Peter Clausen | 5898dd9 | 2010-06-19 16:52:51 +0200 | [diff] [blame] | 69 | return 0; |
| 70 | } |
| 71 | |
| 72 | static struct snd_soc_dai_link qi_lb60_dai = { |
| 73 | .name = "jz4740", |
| 74 | .stream_name = "jz4740", |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 75 | .cpu_dai_name = "jz4740-i2s", |
Lars-Peter Clausen | 0406a40 | 2013-12-03 18:53:03 +0100 | [diff] [blame] | 76 | .platform_name = "jz4740-i2s", |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 77 | .codec_dai_name = "jz4740-hifi", |
| 78 | .codec_name = "jz4740-codec", |
Lars-Peter Clausen | 5898dd9 | 2010-06-19 16:52:51 +0200 | [diff] [blame] | 79 | .init = qi_lb60_codec_init, |
| 80 | }; |
| 81 | |
| 82 | static struct snd_soc_card qi_lb60 = { |
| 83 | .name = "QI LB60", |
Axel Lin | 1d9d25b | 2011-12-23 14:48:19 +0800 | [diff] [blame] | 84 | .owner = THIS_MODULE, |
Lars-Peter Clausen | 5898dd9 | 2010-06-19 16:52:51 +0200 | [diff] [blame] | 85 | .dai_link = &qi_lb60_dai, |
| 86 | .num_links = 1, |
Lars-Peter Clausen | 1331969 | 2011-04-12 19:31:03 +0200 | [diff] [blame] | 87 | |
| 88 | .dapm_widgets = qi_lb60_widgets, |
| 89 | .num_dapm_widgets = ARRAY_SIZE(qi_lb60_widgets), |
| 90 | .dapm_routes = qi_lb60_routes, |
| 91 | .num_dapm_routes = ARRAY_SIZE(qi_lb60_routes), |
Lars-Peter Clausen | 5898dd9 | 2010-06-19 16:52:51 +0200 | [diff] [blame] | 92 | }; |
| 93 | |
Lars-Peter Clausen | c6f0ede | 2011-04-12 19:31:04 +0200 | [diff] [blame] | 94 | static const struct gpio qi_lb60_gpios[] = { |
| 95 | { QI_LB60_SND_GPIO, GPIOF_OUT_INIT_LOW, "SND" }, |
| 96 | { QI_LB60_AMP_GPIO, GPIOF_OUT_INIT_LOW, "AMP" }, |
| 97 | }; |
| 98 | |
Bill Pemberton | d6a29e3 | 2012-12-07 09:26:24 -0500 | [diff] [blame] | 99 | static int qi_lb60_probe(struct platform_device *pdev) |
Lars-Peter Clausen | 5898dd9 | 2010-06-19 16:52:51 +0200 | [diff] [blame] | 100 | { |
Axel Lin | b33005f3 | 2012-01-06 11:30:10 +0800 | [diff] [blame] | 101 | struct snd_soc_card *card = &qi_lb60; |
Lars-Peter Clausen | 5898dd9 | 2010-06-19 16:52:51 +0200 | [diff] [blame] | 102 | int ret; |
| 103 | |
Lars-Peter Clausen | c6f0ede | 2011-04-12 19:31:04 +0200 | [diff] [blame] | 104 | ret = gpio_request_array(qi_lb60_gpios, ARRAY_SIZE(qi_lb60_gpios)); |
Axel Lin | b33005f3 | 2012-01-06 11:30:10 +0800 | [diff] [blame] | 105 | if (ret) |
| 106 | return ret; |
| 107 | |
| 108 | card->dev = &pdev->dev; |
| 109 | |
| 110 | ret = snd_soc_register_card(card); |
Lars-Peter Clausen | 5898dd9 | 2010-06-19 16:52:51 +0200 | [diff] [blame] | 111 | if (ret) { |
Axel Lin | b33005f3 | 2012-01-06 11:30:10 +0800 | [diff] [blame] | 112 | dev_err(&pdev->dev, "snd_soc_register_card() failed: %d\n", |
| 113 | ret); |
| 114 | gpio_free_array(qi_lb60_gpios, ARRAY_SIZE(qi_lb60_gpios)); |
Lars-Peter Clausen | 5898dd9 | 2010-06-19 16:52:51 +0200 | [diff] [blame] | 115 | } |
Lars-Peter Clausen | 5898dd9 | 2010-06-19 16:52:51 +0200 | [diff] [blame] | 116 | return ret; |
| 117 | } |
Lars-Peter Clausen | 5898dd9 | 2010-06-19 16:52:51 +0200 | [diff] [blame] | 118 | |
Bill Pemberton | d6a29e3 | 2012-12-07 09:26:24 -0500 | [diff] [blame] | 119 | static int qi_lb60_remove(struct platform_device *pdev) |
Lars-Peter Clausen | 5898dd9 | 2010-06-19 16:52:51 +0200 | [diff] [blame] | 120 | { |
Axel Lin | b33005f3 | 2012-01-06 11:30:10 +0800 | [diff] [blame] | 121 | struct snd_soc_card *card = platform_get_drvdata(pdev); |
| 122 | |
| 123 | snd_soc_unregister_card(card); |
Lars-Peter Clausen | c6f0ede | 2011-04-12 19:31:04 +0200 | [diff] [blame] | 124 | gpio_free_array(qi_lb60_gpios, ARRAY_SIZE(qi_lb60_gpios)); |
Axel Lin | b33005f3 | 2012-01-06 11:30:10 +0800 | [diff] [blame] | 125 | return 0; |
Lars-Peter Clausen | 5898dd9 | 2010-06-19 16:52:51 +0200 | [diff] [blame] | 126 | } |
Axel Lin | b33005f3 | 2012-01-06 11:30:10 +0800 | [diff] [blame] | 127 | |
| 128 | static struct platform_driver qi_lb60_driver = { |
| 129 | .driver = { |
| 130 | .name = "qi-lb60-audio", |
| 131 | .owner = THIS_MODULE, |
| 132 | }, |
| 133 | .probe = qi_lb60_probe, |
Bill Pemberton | d6a29e3 | 2012-12-07 09:26:24 -0500 | [diff] [blame] | 134 | .remove = qi_lb60_remove, |
Axel Lin | b33005f3 | 2012-01-06 11:30:10 +0800 | [diff] [blame] | 135 | }; |
| 136 | |
| 137 | module_platform_driver(qi_lb60_driver); |
Lars-Peter Clausen | 5898dd9 | 2010-06-19 16:52:51 +0200 | [diff] [blame] | 138 | |
| 139 | MODULE_AUTHOR("Lars-Peter Clausen <lars@metafoo.de>"); |
| 140 | MODULE_DESCRIPTION("ALSA SoC QI LB60 Audio support"); |
| 141 | MODULE_LICENSE("GPL v2"); |
Axel Lin | b33005f3 | 2012-01-06 11:30:10 +0800 | [diff] [blame] | 142 | MODULE_ALIAS("platform:qi-lb60-audio"); |