|
| 1 | +/* |
| 2 | + * ASoC Driver for ESS Q2M |
| 3 | + * |
| 4 | + * Author: Xiao |
| 5 | + * |
| 6 | + * This program is free software; you can redistribute it and/or |
| 7 | + * modify it under the terms of the GNU General Public License |
| 8 | + * version 2 as published by the Free Software Foundation. |
| 9 | + * |
| 10 | + * This program is distributed in the hope that it will be useful, but |
| 11 | + * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 13 | + * General Public License for more details. |
| 14 | + */ |
| 15 | + |
| 16 | +#include <linux/kernel.h> |
| 17 | +#include <linux/init.h> |
| 18 | +#include <linux/module.h> |
| 19 | +#include <linux/delay.h> |
| 20 | +#include <linux/fs.h> |
| 21 | +#include <asm/uaccess.h> |
| 22 | +#include <sound/core.h> |
| 23 | +#include <sound/soc.h> |
| 24 | +#include <sound/pcm.h> |
| 25 | +#include <sound/pcm_params.h> |
| 26 | + |
| 27 | +#include "es90x8q2m-dac.h" |
| 28 | + |
| 29 | +#ifdef ROCKCHIP_AUDIO |
| 30 | +#define ROCKCHIP_I2S_MCLK 512 |
| 31 | +#endif |
| 32 | + |
| 33 | +static int snd_soc_es90x8q2m_dac_init(struct snd_soc_pcm_runtime *rtd) |
| 34 | +{ |
| 35 | + //struct snd_soc_codec *codec = rtd->codec; |
| 36 | + //unsigned int value; |
| 37 | + |
| 38 | + /* Device ID */ |
| 39 | + //value = snd_soc_read(codec, ES9028Q2M_REG_01); |
| 40 | + //dev_info(codec->dev, "xxx Device ID : %02X\n", value); |
| 41 | + |
| 42 | + /* API revision */ |
| 43 | + //value = snd_soc_read(codec, ES9028Q2M_REG_02); |
| 44 | + //dev_info(codec->dev, "xxx API revision : %02X\n", value); |
| 45 | + |
| 46 | + return 0; |
| 47 | +} |
| 48 | + |
| 49 | +static int snd_soc_es90x8q2m_dac_hw_params( |
| 50 | + struct snd_pcm_substream *substream, struct snd_pcm_hw_params *params) |
| 51 | +{ |
| 52 | + struct snd_soc_pcm_runtime *rtd = substream->private_data; |
| 53 | + struct snd_soc_dai *cpu_dai = rtd->cpu_dai; |
| 54 | +#ifdef ROCKCHIP_AUDIO |
| 55 | + unsigned int mclk; |
| 56 | + |
| 57 | + mclk = params_rate(params) * ROCKCHIP_I2S_MCLK; |
| 58 | + return snd_soc_dai_set_sysclk(cpu_dai, 0, mclk, |
| 59 | + SND_SOC_CLOCK_OUT); |
| 60 | +#else |
| 61 | + int bclk_ratio; |
| 62 | + |
| 63 | + bclk_ratio = snd_pcm_format_physical_width( |
| 64 | + params_format(params)) * params_channels(params); |
| 65 | + return snd_soc_dai_set_bclk_ratio(cpu_dai, bclk_ratio); |
| 66 | +#endif |
| 67 | +} |
| 68 | + |
| 69 | +/* machine stream operations */ |
| 70 | +static struct snd_soc_ops snd_soc_es90x8q2m_dac_ops = { |
| 71 | + .hw_params = snd_soc_es90x8q2m_dac_hw_params, |
| 72 | +}; |
| 73 | + |
| 74 | + |
| 75 | +static struct snd_soc_dai_link snd_rpi_es90x8q2m_dai[] = { |
| 76 | + { |
| 77 | + .name = "ES90x8Q2M", |
| 78 | + .stream_name = "ES90x8Q2M DAC", |
| 79 | + .cpu_dai_name = "bcm2708-i2s.0", |
| 80 | + .codec_dai_name = "es90x8q2m-dac-dai", |
| 81 | + .platform_name = "bcm2708-i2s.0", |
| 82 | + .codec_name = "es90x8q2m-codec-i2c.1-0048", |
| 83 | + .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
| 84 | + | SND_SOC_DAIFMT_CBS_CFS, |
| 85 | + .init = snd_soc_es90x8q2m_dac_init, |
| 86 | + .ops = &snd_soc_es90x8q2m_dac_ops, |
| 87 | + } |
| 88 | +}; |
| 89 | + |
| 90 | +/* audio machine driver */ |
| 91 | +static struct snd_soc_card snd_soc_es90x8q2m_dac = { |
| 92 | + .name = "ES90x8Q2M DAC", |
| 93 | + .owner = THIS_MODULE, |
| 94 | + .dai_link = snd_rpi_es90x8q2m_dai, |
| 95 | + .num_links = ARRAY_SIZE(snd_rpi_es90x8q2m_dai) |
| 96 | +}; |
| 97 | + |
| 98 | + |
| 99 | +static int snd_soc_es90x8q2m_dac_probe(struct platform_device *pdev) |
| 100 | +{ |
| 101 | + int ret = 0; |
| 102 | + |
| 103 | + snd_soc_es90x8q2m_dac.dev = &pdev->dev; |
| 104 | + if (pdev->dev.of_node) { |
| 105 | + struct device_node *i2s_node; |
| 106 | + struct snd_soc_dai_link *dai; |
| 107 | + |
| 108 | + dai = &snd_rpi_es90x8q2m_dai[0]; |
| 109 | + i2s_node = of_parse_phandle(pdev->dev.of_node, |
| 110 | + "i2s-controller", 0); |
| 111 | + if (i2s_node) { |
| 112 | + dai->cpu_dai_name = NULL; |
| 113 | + dai->cpu_of_node = i2s_node; |
| 114 | + dai->platform_name = NULL; |
| 115 | + dai->platform_of_node = i2s_node; |
| 116 | + } else { |
| 117 | + dev_err(&pdev->dev, |
| 118 | + "Property 'i2s-controller' missing or invalid\n"); |
| 119 | + return (-EINVAL); |
| 120 | + } |
| 121 | + |
| 122 | + dai->name = "ES90x8Q2M"; |
| 123 | + dai->stream_name = "ES90x8Q2M DAC"; |
| 124 | + dai->dai_fmt = SND_SOC_DAIFMT_I2S |
| 125 | + | SND_SOC_DAIFMT_NB_NF |
| 126 | + | SND_SOC_DAIFMT_CBS_CFS; |
| 127 | + } |
| 128 | + |
| 129 | + /* Wait for registering codec driver */ |
| 130 | + mdelay(50); |
| 131 | + |
| 132 | + ret = snd_soc_register_card(&snd_soc_es90x8q2m_dac); |
| 133 | + if (ret) { |
| 134 | + dev_err(&pdev->dev, |
| 135 | + "snd_soc_register_card() failed: %d\n", ret); |
| 136 | + } |
| 137 | + |
| 138 | + return ret; |
| 139 | +} |
| 140 | + |
| 141 | +static int snd_soc_es90x8q2m_dac_remove(struct platform_device *pdev) |
| 142 | +{ |
| 143 | + return snd_soc_unregister_card(&snd_soc_es90x8q2m_dac); |
| 144 | +} |
| 145 | + |
| 146 | +static const struct of_device_id snd_soc_es90x8q2m_dac_of_match[] = { |
| 147 | + { .compatible = "xiao,es90x8q2m-dac", }, //see es90x8q2m-dac-overlay.dts |
| 148 | + {} |
| 149 | +}; |
| 150 | +MODULE_DEVICE_TABLE(of, snd_soc_es90x8q2m_dac_of_match); |
| 151 | + |
| 152 | +static struct platform_driver snd_soc_es90x8q2m_dac_driver = { |
| 153 | + .driver = { |
| 154 | + .name = "snd-soc-es90x8q2m-dac", |
0 commit comments