1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Driver for the 1250-EV1 audio I/O module
5 * Copyright 2011 Wolfson Microelectronics plc
8 #include <linux/init.h>
9 #include <linux/module.h>
10 #include <linux/slab.h>
11 #include <linux/i2c.h>
12 #include <linux/gpio.h>
14 #include <sound/soc.h>
15 #include <sound/soc-dapm.h>
16 #include <sound/wm1250-ev1.h>
18 static const char *wm1250_gpio_names
[WM1250_EV1_NUM_GPIOS
] = {
27 struct gpio gpios
[WM1250_EV1_NUM_GPIOS
];
30 static int wm1250_ev1_set_bias_level(struct snd_soc_component
*component
,
31 enum snd_soc_bias_level level
)
33 struct wm1250_priv
*wm1250
= dev_get_drvdata(component
->dev
);
37 ena
= wm1250
->gpios
[WM1250_EV1_GPIO_CLK_ENA
].gpio
;
45 case SND_SOC_BIAS_PREPARE
:
48 case SND_SOC_BIAS_STANDBY
:
50 gpio_set_value_cansleep(ena
, 1);
53 case SND_SOC_BIAS_OFF
:
55 gpio_set_value_cansleep(ena
, 0);
62 static const struct snd_soc_dapm_widget wm1250_ev1_dapm_widgets
[] = {
63 SND_SOC_DAPM_ADC("ADC", "wm1250-ev1 Capture", SND_SOC_NOPM
, 0, 0),
64 SND_SOC_DAPM_DAC("DAC", "wm1250-ev1 Playback", SND_SOC_NOPM
, 0, 0),
66 SND_SOC_DAPM_INPUT("WM1250 Input"),
67 SND_SOC_DAPM_OUTPUT("WM1250 Output"),
70 static const struct snd_soc_dapm_route wm1250_ev1_dapm_routes
[] = {
71 { "ADC", NULL
, "WM1250 Input" },
72 { "WM1250 Output", NULL
, "DAC" },
75 static int wm1250_ev1_hw_params(struct snd_pcm_substream
*substream
,
76 struct snd_pcm_hw_params
*params
,
77 struct snd_soc_dai
*dai
)
79 struct wm1250_priv
*wm1250
= snd_soc_component_get_drvdata(dai
->component
);
81 switch (params_rate(params
)) {
83 gpio_set_value(wm1250
->gpios
[WM1250_EV1_GPIO_CLK_SEL0
].gpio
,
85 gpio_set_value(wm1250
->gpios
[WM1250_EV1_GPIO_CLK_SEL1
].gpio
,
89 gpio_set_value(wm1250
->gpios
[WM1250_EV1_GPIO_CLK_SEL0
].gpio
,
91 gpio_set_value(wm1250
->gpios
[WM1250_EV1_GPIO_CLK_SEL1
].gpio
,
95 gpio_set_value(wm1250
->gpios
[WM1250_EV1_GPIO_CLK_SEL0
].gpio
,
97 gpio_set_value(wm1250
->gpios
[WM1250_EV1_GPIO_CLK_SEL1
].gpio
,
101 gpio_set_value(wm1250
->gpios
[WM1250_EV1_GPIO_CLK_SEL0
].gpio
,
103 gpio_set_value(wm1250
->gpios
[WM1250_EV1_GPIO_CLK_SEL1
].gpio
,
113 static const struct snd_soc_dai_ops wm1250_ev1_ops
= {
114 .hw_params
= wm1250_ev1_hw_params
,
117 #define WM1250_EV1_RATES (SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_16000 |\
118 SNDRV_PCM_RATE_32000 | SNDRV_PCM_RATE_64000)
120 static struct snd_soc_dai_driver wm1250_ev1_dai
= {
121 .name
= "wm1250-ev1",
123 .stream_name
= "Playback",
126 .rates
= WM1250_EV1_RATES
,
127 .formats
= SNDRV_PCM_FMTBIT_S16_LE
,
130 .stream_name
= "Capture",
133 .rates
= WM1250_EV1_RATES
,
134 .formats
= SNDRV_PCM_FMTBIT_S16_LE
,
136 .ops
= &wm1250_ev1_ops
,
139 static const struct snd_soc_component_driver soc_component_dev_wm1250_ev1
= {
140 .dapm_widgets
= wm1250_ev1_dapm_widgets
,
141 .num_dapm_widgets
= ARRAY_SIZE(wm1250_ev1_dapm_widgets
),
142 .dapm_routes
= wm1250_ev1_dapm_routes
,
143 .num_dapm_routes
= ARRAY_SIZE(wm1250_ev1_dapm_routes
),
144 .set_bias_level
= wm1250_ev1_set_bias_level
,
145 .use_pmdown_time
= 1,
147 .non_legacy_dai_naming
= 1,
150 static int wm1250_ev1_pdata(struct i2c_client
*i2c
)
152 struct wm1250_ev1_pdata
*pdata
= dev_get_platdata(&i2c
->dev
);
153 struct wm1250_priv
*wm1250
;
159 wm1250
= devm_kzalloc(&i2c
->dev
, sizeof(*wm1250
), GFP_KERNEL
);
165 for (i
= 0; i
< ARRAY_SIZE(wm1250
->gpios
); i
++) {
166 wm1250
->gpios
[i
].gpio
= pdata
->gpios
[i
];
167 wm1250
->gpios
[i
].label
= wm1250_gpio_names
[i
];
168 wm1250
->gpios
[i
].flags
= GPIOF_OUT_INIT_LOW
;
170 wm1250
->gpios
[WM1250_EV1_GPIO_CLK_SEL0
].flags
= GPIOF_OUT_INIT_HIGH
;
171 wm1250
->gpios
[WM1250_EV1_GPIO_CLK_SEL1
].flags
= GPIOF_OUT_INIT_HIGH
;
173 ret
= gpio_request_array(wm1250
->gpios
, ARRAY_SIZE(wm1250
->gpios
));
175 dev_err(&i2c
->dev
, "Failed to get GPIOs: %d\n", ret
);
179 dev_set_drvdata(&i2c
->dev
, wm1250
);
187 static void wm1250_ev1_free(struct i2c_client
*i2c
)
189 struct wm1250_priv
*wm1250
= dev_get_drvdata(&i2c
->dev
);
192 gpio_free_array(wm1250
->gpios
, ARRAY_SIZE(wm1250
->gpios
));
195 static int wm1250_ev1_probe(struct i2c_client
*i2c
,
196 const struct i2c_device_id
*i2c_id
)
198 int id
, board
, rev
, ret
;
200 dev_set_drvdata(&i2c
->dev
, NULL
);
202 board
= i2c_smbus_read_byte_data(i2c
, 0);
204 dev_err(&i2c
->dev
, "Failed to read ID: %d\n", board
);
208 id
= (board
& 0xfe) >> 2;
212 dev_err(&i2c
->dev
, "Unknown board ID %d\n", id
);
216 dev_info(&i2c
->dev
, "revision %d\n", rev
+ 1);
218 ret
= wm1250_ev1_pdata(i2c
);
222 ret
= devm_snd_soc_register_component(&i2c
->dev
, &soc_component_dev_wm1250_ev1
,
225 dev_err(&i2c
->dev
, "Failed to register CODEC: %d\n", ret
);
226 wm1250_ev1_free(i2c
);
233 static int wm1250_ev1_remove(struct i2c_client
*i2c
)
235 wm1250_ev1_free(i2c
);
240 static const struct i2c_device_id wm1250_ev1_i2c_id
[] = {
244 MODULE_DEVICE_TABLE(i2c
, wm1250_ev1_i2c_id
);
246 static struct i2c_driver wm1250_ev1_i2c_driver
= {
248 .name
= "wm1250-ev1",
250 .probe
= wm1250_ev1_probe
,
251 .remove
= wm1250_ev1_remove
,
252 .id_table
= wm1250_ev1_i2c_id
,
255 module_i2c_driver(wm1250_ev1_i2c_driver
);
257 MODULE_AUTHOR("Mark Brown <broonie@opensource.wolfsonmicro.com>");
258 MODULE_DESCRIPTION("WM1250-EV1 audio I/O module driver");
259 MODULE_LICENSE("GPL");