summaryrefslogtreecommitdiff
path: root/sound/soc/samsung/odroidx2_max98090.c
blob: 4ac69024619b9df7fe5122f1da66d8a48b579183 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
/*
 * Copyright (C) 2014 Samsung Electronics Co., Ltd.
 *
 * This program is free software; you can redistribute  it and/or modify it
 * under  the terms of  the GNU General  Public License as published by the
 * Free Software Foundation;  either version 2 of the  License, or (at your
 * option) any later version.
 */

#include <linux/of.h>
#include <linux/module.h>
#include <sound/soc.h>
#include <sound/pcm_params.h>
#include "i2s.h"

/* Config I2S CDCLK output 19.2MHZ clock to Max98090 */
#define MAX98090_MCLK 19200000

static int odroidx2_hw_params(struct snd_pcm_substream *substream,
	struct snd_pcm_hw_params *params)
{
	struct snd_soc_pcm_runtime *rtd = substream->private_data;
	struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
	struct snd_soc_dai *codec_dai = rtd->codec_dai;
	int ret;

	ret = snd_soc_dai_set_sysclk(codec_dai, 0, MAX98090_MCLK,
						SND_SOC_CLOCK_IN);
	if (ret < 0) {
		dev_err(codec_dai->dev,
			"Unable to switch to FLL1: %d\n", ret);
		return ret;
	}

	/* Set the cpu DAI configuration in order to use CDCLK */
	ret = snd_soc_dai_set_sysclk(cpu_dai, SAMSUNG_I2S_CDCLK,
					0, SND_SOC_CLOCK_OUT);
	if (ret < 0)
		return ret;

	dev_dbg(codec_dai->dev, "HiFi DAI %s params: channels: %d, rate: %d\n",
		snd_pcm_stream_str(substream), params_channels(params),
		params_rate(params));

	return 0;
}

static struct snd_soc_ops odroidx2_ops = {
	.hw_params	= odroidx2_hw_params,
};

static struct snd_soc_dai_link odroidx2_dai[] = {
	{
		.name		= "MAX98090",
		.stream_name	= "MAX98090 PCM",
		.codec_dai_name	= "HiFi",
		.dai_fmt	= SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
				  SND_SOC_DAIFMT_CBM_CFM,
		.ops		= &odroidx2_ops,
	}, {
		.name		= "MAX98090 SEC",
		.stream_name	= "MAX98090 PCM SEC",
		.codec_dai_name	= "HiFi",
		.cpu_dai_name	= "samsung-i2s-sec",
		.platform_name	= "samsung-i2s-sec",
		.dai_fmt	= SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
				  SND_SOC_DAIFMT_CBM_CFM,
		.ops		= &odroidx2_ops,
	},
};

static struct snd_soc_card odroidx2 = {
	.name		= "odroidx2",
	.owner		= THIS_MODULE,
	.dai_link	= odroidx2_dai,
	.num_links	= ARRAY_SIZE(odroidx2_dai),
};

static int odroidx2_audio_probe(struct platform_device *pdev)
{
	struct device_node *np = pdev->dev.of_node;
	struct snd_soc_card *card = &odroidx2;

	if (!np)
		return -ENODEV;

	card->dev = &pdev->dev;

	odroidx2_dai[0].codec_name = NULL;
	odroidx2_dai[0].codec_of_node = of_parse_phandle(np,
						"samsung,audio-codec", 0);
	if (!odroidx2_dai[0].codec_of_node) {
		dev_err(&pdev->dev,
			"Property 'samsung,audio-codec' missing or invalid\n");
		return -EINVAL;
	}

	odroidx2_dai[0].cpu_name = NULL;
	odroidx2_dai[0].cpu_of_node = of_parse_phandle(np,
						"samsung,i2s-controller", 0);
	if (!odroidx2_dai[0].cpu_of_node) {
		dev_err(&pdev->dev,
			"Property 'samsung,i2s-controller' missing or invalid\n");
		return -EINVAL;
	}

	odroidx2_dai[0].platform_of_node = odroidx2_dai[0].cpu_of_node;

	/* Configure the secondary audio interface with the same codec dai */
	odroidx2_dai[1].codec_name = NULL;
	odroidx2_dai[1].codec_of_node = odroidx2_dai[0].codec_of_node;

	return snd_soc_register_card(card);
}

static int odroidx2_audio_remove(struct platform_device *pdev)
{
	struct snd_soc_card *card = platform_get_drvdata(pdev);

	snd_soc_unregister_card(card);

	return 0;
}

static const struct of_device_id odroidx2_audio_of_match[] = {
	{ .compatible = "samsung,odroidx2-audio", },
	{ .compatible = "samsung,odroidu3-audio", },
	{ },
};
MODULE_DEVICE_TABLE(of, odroid_audio_of_match);

static struct platform_driver odroidx2_audio_driver = {
	.driver = {
		.name		= "odroidx2-audio",
		.owner		= THIS_MODULE,
		.of_match_table	= odroidx2_audio_of_match,
	},
	.probe	= odroidx2_audio_probe,
	.remove	= odroidx2_audio_remove,
};
module_platform_driver(odroidx2_audio_driver);

MODULE_AUTHOR("zhen1.chen@samsung.com");
MODULE_DESCRIPTION("ALSA SoC Odroidx2 Audio Support");
MODULE_LICENSE("GPL v2");