forked from ~ljy/RK356X_SDK_RELEASE

hc
2023-12-11 1f93a7dfd1f8d5ff7a5c53246c7534fe2332d6f4
kernel/sound/soc/rockchip/rockchip_multicodecs.c
....@@ -19,9 +19,18 @@
1919 *
2020 */
2121
22
+#include <linux/extcon-provider.h>
23
+#include <linux/gpio.h>
24
+#include <linux/iio/consumer.h>
25
+#include <linux/iio/iio.h>
26
+#include <linux/input.h>
27
+#include <linux/interrupt.h>
28
+#include <linux/irq.h>
2229 #include <linux/module.h>
30
+#include <linux/of_gpio.h>
2331 #include <linux/platform_device.h>
2432 #include <linux/slab.h>
33
+#include <linux/workqueue.h>
2534 #include <sound/core.h>
2635 #include <sound/jack.h>
2736 #include <sound/pcm.h>
....@@ -29,39 +38,320 @@
2938 #include <sound/soc.h>
3039 #include <sound/soc-dapm.h>
3140
32
-#include "../codecs/rk3308_codec_provider.h"
33
-
3441 #define DRV_NAME "rk-multicodecs"
35
-#define MAX_CODECS 2
3642 #define WAIT_CARDS (SNDRV_CARDS - 1)
3743 #define DEFAULT_MCLK_FS 256
44
+
45
+struct adc_keys_button {
46
+ u32 voltage;
47
+ u32 keycode;
48
+};
49
+
50
+struct input_dev_poller {
51
+ void (*poll)(struct input_dev *dev);
52
+
53
+ unsigned int poll_interval_ms;
54
+ struct input_dev *input;
55
+ struct delayed_work work;
56
+};
3857
3958 struct multicodecs_data {
4059 struct snd_soc_card snd_card;
4160 struct snd_soc_dai_link dai_link;
61
+ struct snd_soc_jack *jack_headset;
62
+ struct gpio_desc *hp_ctl_gpio;
63
+ struct gpio_desc *spk_ctl_gpio;
64
+ struct gpio_desc *hp_det_gpio;
65
+ struct iio_channel *adc;
66
+ struct extcon_dev *extcon;
67
+ struct delayed_work handler;
4268 unsigned int mclk_fs;
4369 bool codec_hp_det;
70
+ u32 num_keys;
71
+ u32 last_key;
72
+ u32 keyup_voltage;
73
+ const struct adc_keys_button *map;
74
+ struct input_dev *input;
75
+ struct input_dev_poller *poller;
4476 };
4577
46
-static struct snd_soc_jack mc_hp_jack;
78
+static const unsigned int headset_extcon_cable[] = {
79
+ EXTCON_JACK_MICROPHONE,
80
+ EXTCON_JACK_HEADPHONE,
81
+ EXTCON_NONE,
82
+};
83
+
84
+static void mc_set_poll_interval(struct input_dev_poller *poller, unsigned int interval)
85
+{
86
+ if (poller)
87
+ poller->poll_interval_ms = interval;
88
+}
89
+
90
+static void mc_keys_poller_queue_work(struct input_dev_poller *poller)
91
+{
92
+ unsigned long delay;
93
+
94
+ delay = msecs_to_jiffies(poller->poll_interval_ms);
95
+ if (delay >= HZ)
96
+ delay = round_jiffies_relative(delay);
97
+
98
+ queue_delayed_work(system_freezable_wq, &poller->work, delay);
99
+}
100
+
101
+static void mc_keys_poller_work(struct work_struct *work)
102
+{
103
+ struct input_dev_poller *poller =
104
+ container_of(work, struct input_dev_poller, work.work);
105
+
106
+ poller->poll(poller->input);
107
+ mc_keys_poller_queue_work(poller);
108
+}
109
+
110
+static void mc_keys_poller_start(struct input_dev_poller *poller)
111
+{
112
+ if (poller->poll_interval_ms > 0) {
113
+ poller->poll(poller->input);
114
+ mc_keys_poller_queue_work(poller);
115
+ }
116
+}
117
+
118
+static void mc_keys_poller_stop(struct input_dev_poller *poller)
119
+{
120
+ cancel_delayed_work_sync(&poller->work);
121
+}
122
+
123
+static int mc_keys_setup_polling(struct multicodecs_data *mc_data,
124
+ void (*poll_fn)(struct input_dev *dev))
125
+{
126
+ struct input_dev_poller *poller;
127
+
128
+ poller = devm_kzalloc(mc_data->snd_card.dev, sizeof(*poller), GFP_KERNEL);
129
+ if (!poller)
130
+ return -ENOMEM;
131
+
132
+ INIT_DELAYED_WORK(&poller->work, mc_keys_poller_work);
133
+ poller->input = mc_data->input;
134
+ poller->poll = poll_fn;
135
+ mc_data->poller = poller;
136
+
137
+ return 0;
138
+}
139
+
140
+static void mc_keys_poll(struct input_dev *input)
141
+{
142
+ struct multicodecs_data *mc_data = input_get_drvdata(input);
143
+ int i, value, ret;
144
+ u32 diff, closest = 0xffffffff;
145
+ int keycode = 0;
146
+
147
+ ret = iio_read_channel_processed(mc_data->adc, &value);
148
+ if (unlikely(ret < 0)) {
149
+ /* Forcibly release key if any was pressed */
150
+ value = mc_data->keyup_voltage;
151
+ } else {
152
+ for (i = 0; i < mc_data->num_keys; i++) {
153
+ diff = abs(mc_data->map[i].voltage - value);
154
+ if (diff < closest) {
155
+ closest = diff;
156
+ keycode = mc_data->map[i].keycode;
157
+ }
158
+ }
159
+ }
160
+
161
+ if (abs(mc_data->keyup_voltage - value) < closest)
162
+ keycode = 0;
163
+
164
+ if (mc_data->last_key && mc_data->last_key != keycode)
165
+ input_report_key(input, mc_data->last_key, 0);
166
+
167
+ if (keycode)
168
+ input_report_key(input, keycode, 1);
169
+
170
+ input_sync(input);
171
+ mc_data->last_key = keycode;
172
+}
173
+
174
+static int mc_keys_load_keymap(struct device *dev,
175
+ struct multicodecs_data *mc_data)
176
+{
177
+ struct adc_keys_button *map;
178
+ struct fwnode_handle *child;
179
+ int i = 0;
180
+
181
+ mc_data->num_keys = device_get_child_node_count(dev);
182
+ if (mc_data->num_keys == 0) {
183
+ dev_err(dev, "keymap is missing\n");
184
+ return -EINVAL;
185
+ }
186
+
187
+ map = devm_kmalloc_array(dev, mc_data->num_keys, sizeof(*map), GFP_KERNEL);
188
+ if (!map)
189
+ return -ENOMEM;
190
+
191
+ device_for_each_child_node(dev, child) {
192
+ if (fwnode_property_read_u32(child, "press-threshold-microvolt",
193
+ &map[i].voltage)) {
194
+ dev_err(dev, "Key with invalid or missing voltage\n");
195
+ fwnode_handle_put(child);
196
+ return -EINVAL;
197
+ }
198
+ map[i].voltage /= 1000;
199
+
200
+ if (fwnode_property_read_u32(child, "linux,code",
201
+ &map[i].keycode)) {
202
+ dev_err(dev, "Key with invalid or missing linux,code\n");
203
+ fwnode_handle_put(child);
204
+ return -EINVAL;
205
+ }
206
+
207
+ i++;
208
+ }
209
+ mc_data->map = map;
210
+ return 0;
211
+}
212
+
213
+static void adc_jack_handler(struct work_struct *work)
214
+{
215
+ struct multicodecs_data *mc_data = container_of(to_delayed_work(work),
216
+ struct multicodecs_data,
217
+ handler);
218
+ struct snd_soc_jack *jack_headset = mc_data->jack_headset;
219
+ int adc, ret = 0;
220
+
221
+ if (!gpiod_get_value(mc_data->hp_det_gpio)) {
222
+ snd_soc_jack_report(jack_headset, 0, SND_JACK_HEADSET);
223
+ extcon_set_state_sync(mc_data->extcon,
224
+ EXTCON_JACK_HEADPHONE, false);
225
+ extcon_set_state_sync(mc_data->extcon,
226
+ EXTCON_JACK_MICROPHONE, false);
227
+ if (mc_data->poller)
228
+ mc_keys_poller_stop(mc_data->poller);
229
+
230
+ return;
231
+ }
232
+ if (!mc_data->adc) {
233
+ /* no ADC, so is headphone */
234
+ snd_soc_jack_report(jack_headset, SND_JACK_HEADPHONE, SND_JACK_HEADSET);
235
+ extcon_set_state_sync(mc_data->extcon, EXTCON_JACK_HEADPHONE, true);
236
+ extcon_set_state_sync(mc_data->extcon, EXTCON_JACK_MICROPHONE, false);
237
+ return;
238
+ }
239
+ ret = iio_read_channel_processed(mc_data->adc, &adc);
240
+ if (ret < 0) {
241
+ /* failed to read ADC, so assume headphone */
242
+ snd_soc_jack_report(jack_headset, SND_JACK_HEADPHONE, SND_JACK_HEADSET);
243
+ extcon_set_state_sync(mc_data->extcon, EXTCON_JACK_HEADPHONE, true);
244
+ extcon_set_state_sync(mc_data->extcon, EXTCON_JACK_MICROPHONE, false);
245
+
246
+ } else {
247
+ snd_soc_jack_report(jack_headset,
248
+ snd_soc_jack_get_type(jack_headset, adc),
249
+ SND_JACK_HEADSET);
250
+ extcon_set_state_sync(mc_data->extcon, EXTCON_JACK_HEADPHONE, true);
251
+
252
+ if (snd_soc_jack_get_type(jack_headset, adc) == SND_JACK_HEADSET) {
253
+ extcon_set_state_sync(mc_data->extcon, EXTCON_JACK_MICROPHONE, true);
254
+ if (mc_data->poller)
255
+ mc_keys_poller_start(mc_data->poller);
256
+ }
257
+ }
258
+};
259
+
260
+static irqreturn_t headset_det_irq_thread(int irq, void *data)
261
+{
262
+ struct multicodecs_data *mc_data = (struct multicodecs_data *)data;
263
+
264
+ queue_delayed_work(system_power_efficient_wq, &mc_data->handler, msecs_to_jiffies(200));
265
+
266
+ return IRQ_HANDLED;
267
+};
268
+
269
+static int mc_hp_event(struct snd_soc_dapm_widget *w,
270
+ struct snd_kcontrol *kcontrol, int event)
271
+{
272
+ struct snd_soc_card *card = w->dapm->card;
273
+ struct multicodecs_data *mc_data = snd_soc_card_get_drvdata(card);
274
+
275
+ switch (event) {
276
+ case SND_SOC_DAPM_POST_PMU:
277
+ gpiod_set_value_cansleep(mc_data->hp_ctl_gpio, 1);
278
+ break;
279
+ case SND_SOC_DAPM_PRE_PMD:
280
+ gpiod_set_value_cansleep(mc_data->hp_ctl_gpio, 0);
281
+ break;
282
+ default:
283
+ return 0;
284
+
285
+ }
286
+
287
+ return 0;
288
+}
289
+
290
+static int mc_spk_event(struct snd_soc_dapm_widget *w,
291
+ struct snd_kcontrol *kcontrol, int event)
292
+{
293
+ struct snd_soc_card *card = w->dapm->card;
294
+ struct multicodecs_data *mc_data = snd_soc_card_get_drvdata(card);
295
+
296
+ switch (event) {
297
+ case SND_SOC_DAPM_POST_PMU:
298
+ gpiod_set_value_cansleep(mc_data->spk_ctl_gpio, 1);
299
+ break;
300
+ case SND_SOC_DAPM_PRE_PMD:
301
+ gpiod_set_value_cansleep(mc_data->spk_ctl_gpio, 0);
302
+ break;
303
+ default:
304
+ return 0;
305
+
306
+ }
307
+
308
+ return 0;
309
+}
310
+
311
+static const struct snd_soc_dapm_widget mc_dapm_widgets[] = {
312
+
313
+ SND_SOC_DAPM_HP("Headphone", NULL),
314
+ SND_SOC_DAPM_SPK("Speaker", NULL),
315
+ SND_SOC_DAPM_MIC("Main Mic", NULL),
316
+ SND_SOC_DAPM_MIC("Headset Mic", NULL),
317
+ SND_SOC_DAPM_SUPPLY("Speaker Power",
318
+ SND_SOC_NOPM, 0, 0,
319
+ mc_spk_event,
320
+ SND_SOC_DAPM_POST_PMU |
321
+ SND_SOC_DAPM_PRE_PMD),
322
+ SND_SOC_DAPM_SUPPLY("Headphone Power",
323
+ SND_SOC_NOPM, 0, 0,
324
+ mc_hp_event,
325
+ SND_SOC_DAPM_POST_PMU |
326
+ SND_SOC_DAPM_PRE_PMD),
327
+};
328
+
329
+static const struct snd_kcontrol_new mc_controls[] = {
330
+ SOC_DAPM_PIN_SWITCH("Headphone"),
331
+ SOC_DAPM_PIN_SWITCH("Speaker"),
332
+ SOC_DAPM_PIN_SWITCH("Main Mic"),
333
+ SOC_DAPM_PIN_SWITCH("Headset Mic"),
334
+};
47335
48336 static int rk_multicodecs_hw_params(struct snd_pcm_substream *substream,
49337 struct snd_pcm_hw_params *params)
50338 {
51
- struct snd_soc_pcm_runtime *rtd = substream->private_data;
52
- struct snd_soc_dai *codec_dai = rtd->codec_dai;
53
- struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
339
+ struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
340
+ struct snd_soc_dai *cpu_dai = asoc_rtd_to_cpu(rtd, 0);
341
+ struct snd_soc_dai *codec_dai;
54342 struct multicodecs_data *mc_data = snd_soc_card_get_drvdata(rtd->card);
55343 unsigned int mclk;
56
- int ret;
344
+ int ret, i;
57345
58346 mclk = params_rate(params) * mc_data->mclk_fs;
59347
60
- ret = snd_soc_dai_set_sysclk(codec_dai, substream->stream, mclk,
61
- SND_SOC_CLOCK_IN);
62
- if (ret && ret != -ENOTSUPP) {
63
- pr_err("Set codec_dai sysclk failed: %d\n", ret);
64
- goto out;
348
+ for_each_rtd_codec_dais(rtd, i, codec_dai) {
349
+ ret = snd_soc_dai_set_sysclk(codec_dai, substream->stream, mclk,
350
+ SND_SOC_CLOCK_IN);
351
+ if (ret && ret != -ENOTSUPP) {
352
+ pr_err("Set codec_dai sysclk failed: %d\n", ret);
353
+ goto out;
354
+ }
65355 }
66356
67357 ret = snd_soc_dai_set_sysclk(cpu_dai, substream->stream, mclk,
....@@ -80,16 +370,96 @@
80370 static int rk_dailink_init(struct snd_soc_pcm_runtime *rtd)
81371 {
82372 struct multicodecs_data *mc_data = snd_soc_card_get_drvdata(rtd->card);
373
+ struct snd_soc_card *card = rtd->card;
374
+ struct snd_soc_jack *jack_headset;
375
+ int ret, irq;
376
+ struct snd_soc_jack_pin *pins;
377
+ struct snd_soc_jack_zone *zones;
378
+ struct snd_soc_jack_pin jack_pins[] = {
379
+ {
380
+ .pin = "Headphone",
381
+ .mask = SND_JACK_HEADPHONE,
382
+ }, {
383
+ .pin = "Headset Mic",
384
+ .mask = SND_JACK_MICROPHONE,
385
+ },
386
+ };
387
+ struct snd_soc_jack_zone headset_zones[] = {
388
+ {
389
+ .min_mv = 0,
390
+ .max_mv = 222,
391
+ .jack_type = SND_JACK_HEADPHONE,
392
+ }, {
393
+ .min_mv = 223,
394
+ .max_mv = 1500,
395
+ .jack_type = SND_JACK_HEADSET,
396
+ }, {
397
+ .min_mv = 1501,
398
+ .max_mv = UINT_MAX,
399
+ .jack_type = SND_JACK_HEADPHONE,
400
+ }
401
+ };
402
+
403
+ if ((!mc_data->codec_hp_det) && (gpiod_to_irq(mc_data->hp_det_gpio) < 0)) {
404
+ dev_info(card->dev, "Don't need to map headset detect gpio to irq\n");
405
+ return 0;
406
+ }
407
+
408
+ jack_headset = devm_kzalloc(card->dev, sizeof(*jack_headset), GFP_KERNEL);
409
+ if (!jack_headset)
410
+ return -ENOMEM;
411
+
412
+ pins = devm_kmemdup(card->dev, jack_pins,
413
+ sizeof(*jack_pins) * ARRAY_SIZE(jack_pins), GFP_KERNEL);
414
+ if (!pins)
415
+ return -ENOMEM;
416
+
417
+ zones = devm_kmemdup(card->dev, headset_zones,
418
+ sizeof(*headset_zones) * ARRAY_SIZE(headset_zones), GFP_KERNEL);
419
+ if (!zones)
420
+ return -ENOMEM;
421
+
422
+ ret = snd_soc_card_jack_new(card, "Headset",
423
+ SND_JACK_HEADSET,
424
+ jack_headset,
425
+ pins, ARRAY_SIZE(jack_pins));
426
+ if (ret)
427
+ return ret;
428
+ ret = snd_soc_jack_add_zones(jack_headset, ARRAY_SIZE(headset_zones), zones);
429
+ if (ret)
430
+ return ret;
431
+
432
+ mc_data->jack_headset = jack_headset;
83433
84434 if (mc_data->codec_hp_det) {
85
- snd_soc_card_jack_new(rtd->card, "Headphones",
86
- SND_JACK_HEADPHONE,
87
- &mc_hp_jack, NULL, 0);
435
+ struct snd_soc_dai *codec_dai;
436
+ int i;
88437
89
-#ifdef CONFIG_SND_SOC_RK3308
90
- if (rk3308_codec_set_jack_detect_cb)
91
- rk3308_codec_set_jack_detect_cb(rtd->codec_dai->component, &mc_hp_jack);
92
-#endif
438
+ /* set jack for the first successful one */
439
+ for_each_rtd_codec_dais(rtd, i, codec_dai) {
440
+ ret = snd_soc_component_set_jack(codec_dai->component,
441
+ jack_headset, NULL);
442
+ if (ret >= 0)
443
+ break;
444
+ }
445
+ } else {
446
+ irq = gpiod_to_irq(mc_data->hp_det_gpio);
447
+ if (irq >= 0) {
448
+ ret = devm_request_threaded_irq(card->dev, irq, NULL,
449
+ headset_det_irq_thread,
450
+ IRQF_TRIGGER_RISING |
451
+ IRQF_TRIGGER_FALLING |
452
+ IRQF_ONESHOT,
453
+ "headset_detect",
454
+ mc_data);
455
+ if (ret) {
456
+ dev_err(card->dev, "Failed to request headset detect irq");
457
+ return ret;
458
+ }
459
+
460
+ queue_delayed_work(system_power_efficient_wq,
461
+ &mc_data->handler, msecs_to_jiffies(50));
462
+ }
93463 }
94464
95465 return 0;
....@@ -212,12 +582,15 @@
212582 struct snd_soc_card *card;
213583 struct device_node *np = pdev->dev.of_node;
214584 struct snd_soc_dai_link *link;
585
+ struct snd_soc_dai_link_component *cpus;
586
+ struct snd_soc_dai_link_component *platforms;
215587 struct snd_soc_dai_link_component *codecs;
216588 struct multicodecs_data *mc_data;
217589 struct of_phandle_args args;
218590 struct device_node *node;
591
+ struct input_dev *input;
219592 u32 val;
220
- int count;
593
+ int count, value;
221594 int ret = 0, i = 0, idx = 0;
222595 const char *prefix = "rockchip,";
223596
....@@ -229,6 +602,14 @@
229602
230603 mc_data = devm_kzalloc(&pdev->dev, sizeof(*mc_data), GFP_KERNEL);
231604 if (!mc_data)
605
+ return -ENOMEM;
606
+
607
+ cpus = devm_kzalloc(&pdev->dev, sizeof(*cpus), GFP_KERNEL);
608
+ if (!cpus)
609
+ return -ENOMEM;
610
+
611
+ platforms = devm_kzalloc(&pdev->dev, sizeof(*platforms), GFP_KERNEL);
612
+ if (!platforms)
232613 return -ENOMEM;
233614
234615 card = &mc_data->snd_card;
....@@ -244,13 +625,22 @@
244625 link->stream_name = link->name;
245626 link->init = rk_dailink_init;
246627 link->ops = &rk_ops;
628
+ link->cpus = cpus;
629
+ link->platforms = platforms;
630
+ link->num_cpus = 1;
631
+ link->num_platforms = 1;
632
+ link->ignore_pmdown_time = 1;
247633
248634 card->dai_link = link;
249635 card->num_links = 1;
636
+ card->dapm_widgets = mc_dapm_widgets;
637
+ card->num_dapm_widgets = ARRAY_SIZE(mc_dapm_widgets);
638
+ card->controls = mc_controls;
639
+ card->num_controls = ARRAY_SIZE(mc_controls);
250640 card->num_aux_devs = 0;
251641
252642 count = of_count_phandle_with_args(np, "rockchip,codec", NULL);
253
- if (count < 0 || count > MAX_CODECS)
643
+ if (count < 0)
254644 return -EINVAL;
255645
256646 /* refine codecs, remove unavailable node */
....@@ -267,6 +657,9 @@
267657
268658 codecs = devm_kcalloc(&pdev->dev, idx,
269659 sizeof(*codecs), GFP_KERNEL);
660
+ if (!codecs)
661
+ return -ENOMEM;
662
+
270663 link->codecs = codecs;
271664 link->num_codecs = idx;
272665 idx = 0;
....@@ -292,11 +685,11 @@
292685 /* Only reference the codecs[0].of_node which maybe as master. */
293686 rk_multicodecs_parse_daifmt(np, codecs[0].of_node, mc_data, prefix);
294687
295
- link->cpu_of_node = of_parse_phandle(np, "rockchip,cpu", 0);
296
- if (!link->cpu_of_node)
688
+ link->cpus->of_node = of_parse_phandle(np, "rockchip,cpu", 0);
689
+ if (!link->cpus->of_node)
297690 return -ENODEV;
298691
299
- link->platform_of_node = link->cpu_of_node;
692
+ link->platforms->of_node = link->cpus->of_node;
300693
301694 mc_data->mclk_fs = DEFAULT_MCLK_FS;
302695 if (!of_property_read_u32(np, "rockchip,mclk-fs", &val))
....@@ -305,6 +698,101 @@
305698 mc_data->codec_hp_det =
306699 of_property_read_bool(np, "rockchip,codec-hp-det");
307700
701
+ mc_data->adc = devm_iio_channel_get(&pdev->dev, "adc-detect");
702
+
703
+ if (IS_ERR(mc_data->adc)) {
704
+ if (PTR_ERR(mc_data->adc) != -EPROBE_DEFER) {
705
+ mc_data->adc = NULL;
706
+ dev_warn(&pdev->dev, "Failed to get ADC channel");
707
+ }
708
+ } else {
709
+ if (mc_data->adc->channel->type != IIO_VOLTAGE)
710
+ return -EINVAL;
711
+
712
+ if (device_property_read_u32(&pdev->dev, "keyup-threshold-microvolt",
713
+ &mc_data->keyup_voltage)) {
714
+ dev_warn(&pdev->dev, "Invalid or missing keyup voltage\n");
715
+ return -EINVAL;
716
+ }
717
+ mc_data->keyup_voltage /= 1000;
718
+
719
+ ret = mc_keys_load_keymap(&pdev->dev, mc_data);
720
+ if (ret)
721
+ return ret;
722
+
723
+ input = devm_input_allocate_device(&pdev->dev);
724
+ if (IS_ERR(input)) {
725
+ dev_err(&pdev->dev, "failed to allocate input device\n");
726
+ return PTR_ERR(input);
727
+ }
728
+
729
+ input_set_drvdata(input, mc_data);
730
+
731
+ input->name = "headset-keys";
732
+ input->phys = "headset-keys/input0";
733
+ input->id.bustype = BUS_HOST;
734
+ input->id.vendor = 0x0001;
735
+ input->id.product = 0x0001;
736
+ input->id.version = 0x0100;
737
+
738
+ __set_bit(EV_KEY, input->evbit);
739
+ for (i = 0; i < mc_data->num_keys; i++)
740
+ __set_bit(mc_data->map[i].keycode, input->keybit);
741
+
742
+ if (device_property_read_bool(&pdev->dev, "autorepeat"))
743
+ __set_bit(EV_REP, input->evbit);
744
+
745
+ mc_data->input = input;
746
+ ret = mc_keys_setup_polling(mc_data, mc_keys_poll);
747
+ if (ret) {
748
+ dev_err(&pdev->dev, "Unable to set up polling: %d\n", ret);
749
+ return ret;
750
+ }
751
+
752
+ if (!device_property_read_u32(&pdev->dev, "poll-interval", &value))
753
+ mc_set_poll_interval(mc_data->poller, value);
754
+
755
+ ret = input_register_device(mc_data->input);
756
+ if (ret) {
757
+ dev_err(&pdev->dev, "Unable to register input device: %d\n", ret);
758
+ return ret;
759
+ }
760
+ }
761
+
762
+ INIT_DEFERRABLE_WORK(&mc_data->handler, adc_jack_handler);
763
+
764
+ mc_data->spk_ctl_gpio = devm_gpiod_get_optional(&pdev->dev,
765
+ "spk-con",
766
+ GPIOD_OUT_LOW);
767
+ if (IS_ERR(mc_data->spk_ctl_gpio))
768
+ return PTR_ERR(mc_data->spk_ctl_gpio);
769
+
770
+ mc_data->hp_ctl_gpio = devm_gpiod_get_optional(&pdev->dev,
771
+ "hp-con",
772
+ GPIOD_OUT_LOW);
773
+ if (IS_ERR(mc_data->hp_ctl_gpio))
774
+ return PTR_ERR(mc_data->hp_ctl_gpio);
775
+
776
+ mc_data->hp_det_gpio = devm_gpiod_get_optional(&pdev->dev, "hp-det", GPIOD_IN);
777
+ if (IS_ERR(mc_data->hp_det_gpio))
778
+ return PTR_ERR(mc_data->hp_det_gpio);
779
+
780
+ mc_data->extcon = devm_extcon_dev_allocate(&pdev->dev, headset_extcon_cable);
781
+ if (IS_ERR(mc_data->extcon)) {
782
+ dev_err(&pdev->dev, "allocate extcon failed\n");
783
+ return PTR_ERR(mc_data->extcon);
784
+ }
785
+
786
+ ret = devm_extcon_dev_register(&pdev->dev, mc_data->extcon);
787
+ if (ret) {
788
+ dev_err(&pdev->dev, "failed to register extcon: %d\n", ret);
789
+ return ret;
790
+ }
791
+
792
+ ret = snd_soc_of_parse_audio_routing(card, "rockchip,audio-routing");
793
+ if (ret < 0)
794
+ dev_warn(&pdev->dev, "Audio routing invalid/unspecified\n");
795
+
308796 snd_soc_card_set_drvdata(card, mc_data);
309797
310798 ret = devm_snd_soc_register_card(&pdev->dev, card);