| 1 | From ad2a34ac6d06aa5362e648bba89d8796e94b4e7d Mon Sep 17 00:00:00 2001 |
| 2 | From: Lars-Peter Clausen <lars@metafoo.de> |
| 3 | Date: Sat, 24 Apr 2010 12:38:41 +0200 |
| 4 | Subject: [PATCH 09/23] Add N526 sound SoC board driver |
| 5 | |
| 6 | --- |
| 7 | sound/soc/jz4740/Kconfig | 8 ++ |
| 8 | sound/soc/jz4740/Makefile | 2 + |
| 9 | sound/soc/jz4740/n526.c | 169 +++++++++++++++++++++++++++++++++++++++++++++ |
| 10 | 3 files changed, 179 insertions(+), 0 deletions(-) |
| 11 | create mode 100644 sound/soc/jz4740/n526.c |
| 12 | |
| 13 | --- a/sound/soc/jz4740/Kconfig |
| 14 | +++ b/sound/soc/jz4740/Kconfig |
| 15 | @@ -29,3 +29,11 @@ config SND_JZ4740_SOC_N516 |
| 16 | select SND_SOC_JZCODEC |
| 17 | help |
| 18 | Say Y if you want to enable support for SoC audio on the Hanvon N516. |
| 19 | + |
| 20 | +config SND_JZ4740_SOC_N526 |
| 21 | + tristate "SoC Audio support for Hanvon N526 eBook reader" |
| 22 | + depends on SND_JZ4740_SOC && JZ4740_N526 |
| 23 | + select SND_JZ4740_SOC_I2S |
| 24 | + select SND_SOC_JZCODEC |
| 25 | + help |
| 26 | + Say Y if you want to enable support for SoC audio on the Hanvon N526. |
| 27 | --- a/sound/soc/jz4740/Makefile |
| 28 | +++ b/sound/soc/jz4740/Makefile |
| 29 | @@ -10,6 +10,8 @@ obj-$(CONFIG_SND_JZ4740_SOC_I2S) += snd- |
| 30 | # Jz4740 Machine Support |
| 31 | snd-soc-qi-lb60-objs := qi_lb60.o |
| 32 | snd-soc-n516-objs := n516.o |
| 33 | +snd-soc-n526-objs := n526.o |
| 34 | |
| 35 | obj-$(CONFIG_SND_JZ4740_SOC_QI_LB60) += snd-soc-qi-lb60.o |
| 36 | obj-$(CONFIG_SND_JZ4740_SOC_N516) += snd-soc-n516.o |
| 37 | +obj-$(CONFIG_SND_JZ4740_SOC_N526) += snd-soc-n526.o |
| 38 | --- /dev/null |
| 39 | +++ b/sound/soc/jz4740/n526.c |
| 40 | @@ -0,0 +1,169 @@ |
| 41 | +/* |
| 42 | + * Copyright (C) 2009, Lars-Peter Clausen <lars@metafoo.de> |
| 43 | + * |
| 44 | + * This program is free software; you can redistribute it and/or modify |
| 45 | + * it under the terms of the GNU General Public License version 2 as |
| 46 | + * published by the Free Software Foundation. |
| 47 | + * |
| 48 | + * You should have received a copy of the GNU General Public License along |
| 49 | + * with this program; if not, write to the Free Software Foundation, Inc., |
| 50 | + * 675 Mass Ave, Cambridge, MA 02139, USA. |
| 51 | + * |
| 52 | + */ |
| 53 | + |
| 54 | +#include <linux/module.h> |
| 55 | +#include <linux/moduleparam.h> |
| 56 | +#include <linux/timer.h> |
| 57 | +#include <linux/interrupt.h> |
| 58 | +#include <linux/platform_device.h> |
| 59 | +#include <sound/core.h> |
| 60 | +#include <sound/pcm.h> |
| 61 | +#include <sound/soc.h> |
| 62 | +#include <sound/soc-dapm.h> |
| 63 | +#include <linux/gpio.h> |
| 64 | + |
| 65 | +#include "../codecs/jzcodec.h" |
| 66 | +#include "jz4740-pcm.h" |
| 67 | +#include "jz4740-i2s.h" |
| 68 | + |
| 69 | +#define N526_AMP_EN_GPIO JZ_GPIO_PORTD(4) |
| 70 | + |
| 71 | +static int n526_spk_event(struct snd_soc_dapm_widget *widget, |
| 72 | + struct snd_kcontrol *ctrl, int event) |
| 73 | +{ |
| 74 | + gpio_set_value(N526_AMP_EN_GPIO, !SND_SOC_DAPM_EVENT_OFF(event)); |
| 75 | + return 0; |
| 76 | +} |
| 77 | + |
| 78 | +static const struct snd_soc_dapm_widget n526_widgets[] = { |
| 79 | + SND_SOC_DAPM_SPK("Speaker", n526_spk_event), |
| 80 | + SND_SOC_DAPM_HP("Headphone", NULL), |
| 81 | + SND_SOC_DAPM_MIC("Mic", NULL), |
| 82 | +}; |
| 83 | + |
| 84 | +static const struct snd_soc_dapm_route n526_routes[] = { |
| 85 | + {"Mic", NULL, "MIC"}, |
| 86 | + {"Speaker", NULL, "LOUT"}, |
| 87 | + {"Speaker", NULL, "ROUT"}, |
| 88 | + {"Headphone", NULL, "LOUT"}, |
| 89 | + {"Headphone", NULL, "ROUT"}, |
| 90 | +}; |
| 91 | + |
| 92 | +static const struct snd_kcontrol_new n526_controls[] = { |
| 93 | + SOC_DAPM_PIN_SWITCH("Speaker"), |
| 94 | +}; |
| 95 | + |
| 96 | +#define N526_DAIFMT (SND_SOC_DAIFMT_I2S | \ |
| 97 | + SND_SOC_DAIFMT_NB_NF | \ |
| 98 | + SND_SOC_DAIFMT_CBM_CFM) |
| 99 | + |
| 100 | +static int n526_codec_init(struct snd_soc_codec *codec) |
| 101 | +{ |
| 102 | + int ret; |
| 103 | + struct snd_soc_dai *cpu_dai = codec->socdev->card->dai_link->cpu_dai; |
| 104 | + struct snd_soc_dai *codec_dai = codec->socdev->card->dai_link->codec_dai; |
| 105 | + |
| 106 | + snd_soc_dapm_nc_pin(codec, "LIN"); |
| 107 | + snd_soc_dapm_nc_pin(codec, "RIN"); |
| 108 | + |
| 109 | + ret = snd_soc_dai_set_fmt(codec_dai, N526_DAIFMT); |
| 110 | + if (ret < 0) { |
| 111 | + dev_err(codec->dev, "Failed to set codec dai format: %d\n", ret); |
| 112 | + return ret; |
| 113 | + } |
| 114 | + |
| 115 | + ret = snd_soc_dai_set_fmt(cpu_dai, N526_DAIFMT); |
| 116 | + if (ret < 0) { |
| 117 | + dev_err(codec->dev, "Failed to set cpu dai format: %d\n", ret); |
| 118 | + return ret; |
| 119 | + } |
| 120 | + |
| 121 | + ret = snd_soc_dai_set_sysclk(codec_dai, JZCODEC_SYSCLK, 111, |
| 122 | + SND_SOC_CLOCK_IN); |
| 123 | + if (ret < 0) { |
| 124 | + dev_err(codec->dev, "Failed to set codec dai sysclk: %d\n", ret); |
| 125 | + return ret; |
| 126 | + } |
| 127 | + |
| 128 | + snd_soc_dapm_new_controls(codec, n526_widgets, ARRAY_SIZE(n526_widgets)); |
| 129 | + |
| 130 | + snd_soc_add_controls(codec, n526_controls, |
| 131 | + ARRAY_SIZE(n526_controls)); |
| 132 | + |
| 133 | + snd_soc_dapm_add_routes(codec, n526_routes, ARRAY_SIZE(n526_routes)); |
| 134 | + |
| 135 | + snd_soc_dapm_sync(codec); |
| 136 | + |
| 137 | + return 0; |
| 138 | +} |
| 139 | + |
| 140 | +static struct snd_soc_dai_link n526_dai = { |
| 141 | + .name = "jz-codec", |
| 142 | + .stream_name = "JZCODEC", |
| 143 | + .cpu_dai = &jz4740_i2s_dai, |
| 144 | + .codec_dai = &jz_codec_dai, |
| 145 | + .init = n526_codec_init, |
| 146 | +}; |
| 147 | + |
| 148 | +static struct snd_soc_card n526 = { |
| 149 | + .name = "N526", |
| 150 | + .dai_link = &n526_dai, |
| 151 | + .num_links = 1, |
| 152 | + .platform = &jz4740_soc_platform, |
| 153 | +}; |
| 154 | + |
| 155 | +static struct snd_soc_device n526_snd_devdata = { |
| 156 | + .card = &n526, |
| 157 | + .codec_dev = &soc_codec_dev_jzcodec, |
| 158 | +}; |
| 159 | + |
| 160 | +static struct platform_device *n526_snd_device; |
| 161 | + |
| 162 | +static int __init n526_init(void) |
| 163 | +{ |
| 164 | + int ret; |
| 165 | + |
| 166 | + n526_snd_device = platform_device_alloc("soc-audio", -1); |
| 167 | + |
| 168 | + if (!n526_snd_device) |
| 169 | + return -ENOMEM; |
| 170 | + |
| 171 | + ret = gpio_request(N526_AMP_EN_GPIO, "AMP"); |
| 172 | + if (ret) { |
| 173 | + pr_err("n526 snd: Failed to request AMP GPIO(%d): %d\n", |
| 174 | + N526_AMP_EN_GPIO, ret); |
| 175 | + goto err_device_put; |
| 176 | + } |
| 177 | + |
| 178 | + gpio_direction_output(JZ_GPIO_PORTD(4), 0); |
| 179 | + |
| 180 | + platform_set_drvdata(n526_snd_device, &n526_snd_devdata); |
| 181 | + n526_snd_devdata.dev = &n526_snd_device->dev; |
| 182 | + ret = platform_device_add(n526_snd_device); |
| 183 | + if (ret) { |
| 184 | + pr_err("n526 snd: Failed to add snd soc device: %d\n", ret); |
| 185 | + goto err_unset_pdata; |
| 186 | + } |
| 187 | + |
| 188 | + return 0; |
| 189 | + |
| 190 | +err_unset_pdata: |
| 191 | + platform_set_drvdata(n526_snd_device, NULL); |
| 192 | + gpio_free(N526_AMP_EN_GPIO); |
| 193 | +err_device_put: |
| 194 | + platform_device_put(n526_snd_device); |
| 195 | + |
| 196 | + return ret; |
| 197 | +} |
| 198 | +module_init(n526_init); |
| 199 | + |
| 200 | +static void __exit n526_exit(void) |
| 201 | +{ |
| 202 | + gpio_free(N526_AMP_EN_GPIO); |
| 203 | + platform_device_unregister(n526_snd_device); |
| 204 | +} |
| 205 | +module_exit(n526_exit); |
| 206 | + |
| 207 | +MODULE_AUTHOR("Lars-Peter Clausen <lars@metafoo.de>"); |
| 208 | +MODULE_DESCRIPTION("ALSA SoC N526 audio support"); |
| 209 | +MODULE_LICENSE("GPL v2"); |
| 210 | |