123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377 |
- /*
- * escore-i2s.c -- Audience eScore I2S interface
- *
- * Copyright 2011 Audience, Inc.
- *
- * Author: Greg Clemson <gclemson@audience.com>
- *
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 as
- * published by the Free Software Foundation.
- */
- #include <linux/module.h>
- #include <linux/moduleparam.h>
- #include <linux/init.h>
- #include <linux/firmware.h>
- #include <linux/delay.h>
- #include <linux/pm.h>
- #include <linux/completion.h>
- #include <linux/gpio.h>
- #include <linux/platform_device.h>
- #include <linux/slab.h>
- #include <linux/err.h>
- #include <sound/core.h>
- #include <sound/pcm.h>
- #include <sound/pcm_params.h>
- #include <sound/soc.h>
- #include <sound/soc-dapm.h>
- #include <sound/initval.h>
- #include <sound/tlv.h>
- #include <linux/kthread.h>
- #include <linux/esxxx.h>
- #include "escore.h"
- #include "es515.h"
- #include "escore-list.h"
- static int escore_i2s_set_sysclk(struct snd_soc_dai *dai, int clk_id,
- unsigned int freq, int dir)
- {
- struct snd_soc_codec *codec = dai->codec;
- int rc = 0;
- dev_dbg(codec->dev, "%s()\n", __func__);
- return rc;
- }
- static int escore_i2s_set_pll(struct snd_soc_dai *dai, int pll_id,
- int source, unsigned int freq_in,
- unsigned int freq_out)
- {
- struct snd_soc_codec *codec = dai->codec;
- int rc = 0;
- dev_dbg(codec->dev, "%s()\n", __func__);
- return rc;
- }
- static int escore_i2s_set_clkdiv(struct snd_soc_dai *dai, int div_id,
- int div)
- {
- struct snd_soc_codec *codec = dai->codec;
- int rc = 0;
- dev_dbg(codec->dev, "%s()\n", __func__);
- return rc;
- }
- static int escore_i2s_set_dai_fmt(struct snd_soc_dai *dai, unsigned int fmt)
- {
- struct snd_soc_codec *codec = dai->codec;
- int rc = 0;
- dev_dbg(codec->dev, "%s()\n", __func__);
- return rc;
- }
- static int escore_i2s_set_tdm_slot(struct snd_soc_dai *dai,
- unsigned int tx_mask, unsigned int rx_mask,
- int slots, int slot_width)
- {
- struct snd_soc_codec *codec = dai->codec;
- int rc = 0;
- dev_dbg(codec->dev, "%s()\n", __func__);
- return rc;
- }
- static int escore_i2s_set_channel_map(struct snd_soc_dai *dai,
- unsigned int tx_num, unsigned int *tx_slot,
- unsigned int rx_num, unsigned int *rx_slot)
- {
- struct snd_soc_codec *codec = dai->codec;
- int rc = 0;
- dev_dbg(codec->dev, "%s()\n", __func__);
- return rc;
- }
- static int escore_i2s_set_tristate(struct snd_soc_dai *dai, int tristate)
- {
- struct snd_soc_codec *codec = dai->codec;
- unsigned int paramid = 0;
- unsigned int val = 0;
- dev_dbg(codec->dev, "%s()\n", __func__);
- switch (dai->id) {
- case 0:
- break;
- case 1:
- break;
- default:
- return -EINVAL;
- }
- if (tristate)
- val = 0x0001;
- else
- val = 0x0000;
- return snd_soc_write(codec, paramid, val);
- }
- static int escore_i2s_port_mute(struct snd_soc_dai *dai, int mute)
- {
- struct snd_soc_codec *codec = dai->codec;
- unsigned int paramid = 0;
- unsigned int val = 0;
- dev_dbg(codec->dev, "%s()\n", __func__);
- /* Is this valid since DACs are not statically mapped to DAIs? */
- switch (dai->id) {
- case 0:
- break;
- case 1:
- break;
- default:
- return -EINVAL;
- }
- if (mute)
- val = 0x0000;
- else
- val = 0x0001;
- return snd_soc_write(codec, paramid, val);
- }
- static int escore_i2s_startup(struct snd_pcm_substream *substream,
- struct snd_soc_dai *dai)
- {
- struct snd_soc_codec *codec = dai->codec;
- struct escore_priv *escore = snd_soc_codec_get_drvdata(codec);
- int rc = 0;
- dev_dbg(codec->dev, "%s(): dai->name = %s, dai->id = %d\n", __func__,
- dai->name, dai->id);
- atomic_inc(&escore->active_streams);
- return rc;
- }
- static void escore_i2s_shutdown(struct snd_pcm_substream *substream,
- struct snd_soc_dai *dai)
- {
- struct snd_soc_codec *codec = dai->codec;
- struct escore_priv *escore = snd_soc_codec_get_drvdata(codec);
- dev_dbg(codec->dev, "%s(): dai->name = %s, dai->id = %d\n", __func__,
- dai->name, dai->id);
- atomic_dec(&escore->active_streams);
- if (!atomic_read(&escore->active_streams))
- escore_flush_msg_list(escore);
- }
- static int escore_i2s_hw_params(struct snd_pcm_substream *substream,
- struct snd_pcm_hw_params *params,
- struct snd_soc_dai *dai)
- {
- struct snd_soc_codec *codec = dai->codec;
- struct escore_priv *escore = snd_soc_codec_get_drvdata(codec);
- int bits_per_sample = 0;
- int rc = 0;
- dev_dbg(codec->dev, "%s(): dai->name = %s, dai->id = %d\n", __func__,
- dai->name, dai->id);
- switch (dai->id) {
- case ES_I2S_PORTA:
- dev_dbg(codec->dev, "%s(): ES_PORTA_PARAM_ID\n", __func__);
- break;
- case ES_I2S_PORTB:
- dev_dbg(codec->dev, "%s(): ES_PORTB_PARAM_ID\n", __func__);
- break;
- default:
- dev_dbg(codec->dev, "%s(): unknown port\n", __func__);
- return -EINVAL;
- }
- dev_dbg(codec->dev, "%s(): params_channels(params) = %d\n", __func__,
- params_channels(params));
- switch (params_channels(params)) {
- case 1:
- dev_dbg(codec->dev, "%s(): 1 channel\n", __func__);
- break;
- case 2:
- dev_dbg(codec->dev, "%s(): 2 channels\n", __func__);
- break;
- case 4:
- dev_dbg(codec->dev, "%s(): 4 channels\n", __func__);
- break;
- default:
- dev_dbg(codec->dev, "%s(): unsupported number of channels\n",
- __func__);
- return -EINVAL;
- }
- dev_dbg(codec->dev, "%s(): params_rate(params) = %d\n", __func__,
- params_rate(params));
- switch (params_rate(params)) {
- case 8000:
- dev_dbg(codec->dev, "%s(): 8000Hz\n", __func__);
- break;
- case 11025:
- dev_dbg(codec->dev, "%s(): 11025\n", __func__);
- break;
- case 16000:
- dev_dbg(codec->dev, "%s(): 16000\n", __func__);
- break;
- case 22050:
- dev_dbg(codec->dev, "%s(): 22050\n", __func__);
- break;
- case 32000:
- dev_dbg(codec->dev, "%s(): 32000\n", __func__);
- break;
- case 48000:
- dev_dbg(codec->dev, "%s(): 48000\n", __func__);
- break;
- case 96000:
- dev_dbg(codec->dev, "%s(): 96000\n", __func__);
- break;
- case 192000:
- dev_dbg(codec->dev, "%s(): 96000\n", __func__);
- break;
- default:
- dev_dbg(codec->dev, "%s(): unsupported rate = %d\n", __func__,
- params_rate(params));
- return -EINVAL;
- }
- switch (params_format(params)) {
- case SNDRV_PCM_FORMAT_S16_LE:
- dev_dbg(codec->dev, "%s(): S16_LE\n", __func__);
- bits_per_sample = 16;
- break;
- case SNDRV_PCM_FORMAT_S16_BE:
- dev_dbg(codec->dev, "%s(): S16_BE\n", __func__);
- bits_per_sample = 16;
- break;
- case SNDRV_PCM_FORMAT_S20_3LE:
- dev_dbg(codec->dev, "%s(): S20_3LE\n", __func__);
- bits_per_sample = 20;
- break;
- case SNDRV_PCM_FORMAT_S20_3BE:
- dev_dbg(codec->dev, "%s(): S20_3BE\n", __func__);
- bits_per_sample = 20;
- break;
- case SNDRV_PCM_FORMAT_S24_LE:
- dev_dbg(codec->dev, "%s(): S24_LE\n", __func__);
- bits_per_sample = 24;
- break;
- case SNDRV_PCM_FORMAT_S24_BE:
- dev_dbg(codec->dev, "%s(): S24_BE\n", __func__);
- bits_per_sample = 24;
- break;
- case SNDRV_PCM_FORMAT_S32_LE:
- dev_dbg(codec->dev, "%s(): S32_LE\n", __func__);
- bits_per_sample = 32;
- break;
- case SNDRV_PCM_FORMAT_S32_BE:
- dev_dbg(codec->dev, "%s(): S32_BE\n", __func__);
- bits_per_sample = 32;
- break;
- default:
- dev_dbg(codec->dev, "%s(): unknown format\n", __func__);
- return -EINVAL;
- }
- if (rc) {
- dev_dbg(codec->dev, "%s(): snd_soc_update_bits() failed\n",
- __func__);
- return rc;
- }
- if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
- dev_dbg(codec->dev, "%s(): PLAYBACK\n", __func__);
- else
- dev_dbg(codec->dev, "%s(): CAPTURE\n", __func__);
- escore_write_msg_list(escore);
- return rc;
- }
- static int escore_i2s_hw_free(struct snd_pcm_substream *substream,
- struct snd_soc_dai *dai)
- {
- struct snd_soc_codec *codec = dai->codec;
- int rc = 0;
- dev_dbg(codec->dev, "%s() dai->name = %s, dai->id = %d\n", __func__,
- dai->name, dai->id);
- if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
- dev_dbg(codec->dev, "%s(): PLAYBACK\n", __func__);
- else
- dev_dbg(codec->dev, "%s(): CAPTURE\n", __func__);
- return rc;
- }
- static int escore_i2s_prepare(struct snd_pcm_substream *substream,
- struct snd_soc_dai *dai)
- {
- struct snd_soc_codec *codec = dai->codec;
- int rc = 0;
- dev_dbg(codec->dev, "%s() dai->name = %s, dai->id = %d\n", __func__,
- dai->name, dai->id);
- return rc;
- }
- static int escore_i2s_trigger(struct snd_pcm_substream *substream,
- int cmd, struct snd_soc_dai *dai)
- {
- struct snd_soc_codec *codec = dai->codec;
- int rc = 0;
- dev_dbg(codec->dev, "%s() dai->name = %s, dai->id = %d\n", __func__,
- dai->name, dai->id);
- switch (cmd) {
- case SNDRV_PCM_TRIGGER_START:
- break;
- case SNDRV_PCM_TRIGGER_STOP:
- break;
- }
- return rc;
- }
- struct snd_soc_dai_ops escore_i2s_port_dai_ops = {
- .set_sysclk = escore_i2s_set_sysclk,
- .set_pll = escore_i2s_set_pll,
- .set_clkdiv = escore_i2s_set_clkdiv,
- .set_fmt = escore_i2s_set_dai_fmt,
- .set_tdm_slot = escore_i2s_set_tdm_slot,
- .set_channel_map = escore_i2s_set_channel_map,
- .set_tristate = escore_i2s_set_tristate,
- .digital_mute = escore_i2s_port_mute,
- .startup = escore_i2s_startup,
- .shutdown = escore_i2s_shutdown,
- .hw_params = escore_i2s_hw_params,
- .hw_free = escore_i2s_hw_free,
- .prepare = escore_i2s_prepare,
- .trigger = escore_i2s_trigger,
- };
- MODULE_DESCRIPTION("ASoC ES driver");
- MODULE_AUTHOR("Greg Clemson <gclemson@audience.com>");
- MODULE_LICENSE("GPL");
|