2 * ASoC Driver for I-Sabre Q2M
4 * Author: Satoru Kawase
5 * Modified by: Xiao Qingyong
6 * Update kernel v4.18+ by : Audiophonics
7 * Copyright 2018 Audiophonics
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * version 2 as published by the Free Software Foundation.
13 * This program is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
19 #include <linux/kernel.h>
20 #include <linux/init.h>
21 #include <linux/module.h>
22 #include <linux/delay.h>
24 #include <asm/uaccess.h>
25 #include <sound/core.h>
26 #include <sound/soc.h>
27 #include <sound/pcm.h>
28 #include <sound/pcm_params.h>
30 #include "../codecs/i-sabre-codec.h"
33 static int snd_rpi_i_sabre_q2m_init(struct snd_soc_pcm_runtime *rtd)
35 struct snd_soc_component *component = asoc_rtd_to_codec(rtd, 0)->component;
39 value = snd_soc_component_read(component, ISABRECODEC_REG_01);
40 dev_info(component->card->dev, "Audiophonics Device ID : %02X\n", value);
43 value = snd_soc_component_read(component, ISABRECODEC_REG_02);
44 dev_info(component->card->dev, "Audiophonics API revision : %02X\n", value);
49 static int snd_rpi_i_sabre_q2m_hw_params(
50 struct snd_pcm_substream *substream, struct snd_pcm_hw_params *params)
52 struct snd_soc_pcm_runtime *rtd = substream->private_data;
53 struct snd_soc_dai *cpu_dai = asoc_rtd_to_cpu(rtd, 0);
56 bclk_ratio = snd_pcm_format_physical_width(
57 params_format(params)) * params_channels(params);
58 return snd_soc_dai_set_bclk_ratio(cpu_dai, bclk_ratio);
61 /* machine stream operations */
62 static struct snd_soc_ops snd_rpi_i_sabre_q2m_ops = {
63 .hw_params = snd_rpi_i_sabre_q2m_hw_params,
66 SND_SOC_DAILINK_DEFS(rpi_i_sabre_q2m,
67 DAILINK_COMP_ARRAY(COMP_CPU("bcm2708-i2s.0")),
68 DAILINK_COMP_ARRAY(COMP_CODEC("i-sabre-codec-i2c.1-0048", "i-sabre-codec-dai")),
69 DAILINK_COMP_ARRAY(COMP_PLATFORM("bcm2708-i2s.0")));
71 static struct snd_soc_dai_link snd_rpi_i_sabre_q2m_dai[] = {
73 .name = "I-Sabre Q2M",
74 .stream_name = "I-Sabre Q2M DAC",
75 .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF
76 | SND_SOC_DAIFMT_CBS_CFS,
77 .init = snd_rpi_i_sabre_q2m_init,
78 .ops = &snd_rpi_i_sabre_q2m_ops,
79 SND_SOC_DAILINK_REG(rpi_i_sabre_q2m),
83 /* audio machine driver */
84 static struct snd_soc_card snd_rpi_i_sabre_q2m = {
85 .name = "I-Sabre Q2M DAC",
87 .dai_link = snd_rpi_i_sabre_q2m_dai,
88 .num_links = ARRAY_SIZE(snd_rpi_i_sabre_q2m_dai)
92 static int snd_rpi_i_sabre_q2m_probe(struct platform_device *pdev)
96 snd_rpi_i_sabre_q2m.dev = &pdev->dev;
97 if (pdev->dev.of_node) {
98 struct device_node *i2s_node;
99 struct snd_soc_dai_link *dai;
101 dai = &snd_rpi_i_sabre_q2m_dai[0];
102 i2s_node = of_parse_phandle(pdev->dev.of_node,
103 "i2s-controller", 0);
105 dai->cpus->dai_name = NULL;
106 dai->cpus->of_node = i2s_node;
107 dai->platforms->name = NULL;
108 dai->platforms->of_node = i2s_node;
111 "Property 'i2s-controller' missing or invalid\n");
115 dai->name = "I-Sabre Q2M";
116 dai->stream_name = "I-Sabre Q2M DAC";
117 dai->dai_fmt = SND_SOC_DAIFMT_I2S
118 | SND_SOC_DAIFMT_NB_NF
119 | SND_SOC_DAIFMT_CBS_CFS;
122 /* Wait for registering codec driver */
125 ret = snd_soc_register_card(&snd_rpi_i_sabre_q2m);
128 "snd_soc_register_card() failed: %d\n", ret);
134 static int snd_rpi_i_sabre_q2m_remove(struct platform_device *pdev)
136 return snd_soc_unregister_card(&snd_rpi_i_sabre_q2m);
139 static const struct of_device_id snd_rpi_i_sabre_q2m_of_match[] = {
140 { .compatible = "audiophonics,i-sabre-q2m", },
143 MODULE_DEVICE_TABLE(of, snd_rpi_i_sabre_q2m_of_match);
145 static struct platform_driver snd_rpi_i_sabre_q2m_driver = {
147 .name = "snd-rpi-i-sabre-q2m",
148 .owner = THIS_MODULE,
149 .of_match_table = snd_rpi_i_sabre_q2m_of_match,
151 .probe = snd_rpi_i_sabre_q2m_probe,
152 .remove = snd_rpi_i_sabre_q2m_remove,
154 module_platform_driver(snd_rpi_i_sabre_q2m_driver);
156 MODULE_DESCRIPTION("ASoC Driver for I-Sabre Q2M");
157 MODULE_AUTHOR("Audiophonics <http://www.audiophonics.fr>");
158 MODULE_LICENSE("GPL");