.. | .. |
---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-only |
---|
1 | 2 | /* |
---|
2 | 3 | * es8316.c -- es8316 ALSA SoC audio driver |
---|
3 | 4 | * Copyright Everest Semiconductor Co.,Ltd |
---|
4 | 5 | * |
---|
5 | 6 | * Authors: David Yang <yangxiaohua@everest-semi.com>, |
---|
6 | 7 | * Daniel Drake <drake@endlessm.com> |
---|
7 | | - * |
---|
8 | | - * This program is free software; you can redistribute it and/or modify |
---|
9 | | - * it under the terms of the GNU General Public License version 2 as |
---|
10 | | - * published by the Free Software Foundation. |
---|
11 | 8 | */ |
---|
12 | 9 | |
---|
13 | 10 | #include <linux/module.h> |
---|
14 | 11 | #include <linux/acpi.h> |
---|
15 | 12 | #include <linux/clk.h> |
---|
16 | 13 | #include <linux/delay.h> |
---|
17 | | -#include <linux/extcon.h> |
---|
18 | | -#include <linux/gpio.h> |
---|
19 | 14 | #include <linux/i2c.h> |
---|
20 | 15 | #include <linux/mod_devicetable.h> |
---|
21 | | -#include <linux/of_gpio.h> |
---|
| 16 | +#include <linux/mutex.h> |
---|
22 | 17 | #include <linux/regmap.h> |
---|
23 | 18 | #include <sound/pcm.h> |
---|
24 | 19 | #include <sound/pcm_params.h> |
---|
25 | 20 | #include <sound/soc.h> |
---|
26 | 21 | #include <sound/soc-dapm.h> |
---|
27 | 22 | #include <sound/tlv.h> |
---|
| 23 | +#include <sound/jack.h> |
---|
28 | 24 | #include "es8316.h" |
---|
29 | 25 | |
---|
30 | | -#define ES8316_EXTCON_ID EXTCON_JACK_HEADPHONE |
---|
31 | 26 | /* In slave mode at single speed, the codec is documented as accepting 5 |
---|
32 | 27 | * MCLK/LRCK ratios, but we also add ratio 400, which is commonly used on |
---|
33 | 28 | * Intel Cherry Trail platforms (19.2MHz MCLK, 48kHz LRCK). |
---|
.. | .. |
---|
38 | 33 | }; |
---|
39 | 34 | |
---|
40 | 35 | struct es8316_priv { |
---|
| 36 | + struct mutex lock; |
---|
| 37 | + struct clk *mclk; |
---|
| 38 | + struct regmap *regmap; |
---|
| 39 | + struct snd_soc_component *component; |
---|
| 40 | + struct snd_soc_jack *jack; |
---|
| 41 | + int irq; |
---|
41 | 42 | unsigned int sysclk; |
---|
42 | 43 | unsigned int allowed_rates[NR_SUPPORTED_MCLK_LRCK_RATIOS]; |
---|
43 | 44 | struct snd_pcm_hw_constraint_list sysclk_constraints; |
---|
44 | | - struct clk *mclk; |
---|
45 | | - |
---|
46 | | - struct gpio_desc *gpiod_spk_ctl; |
---|
47 | | - bool muted; |
---|
48 | | - bool hp_inserted; |
---|
49 | | - struct notifier_block extcon_nb; |
---|
50 | | - int pwr_count; |
---|
| 45 | + bool jd_inverted; |
---|
51 | 46 | }; |
---|
52 | 47 | |
---|
53 | 48 | /* |
---|
.. | .. |
---|
94 | 89 | SOC_DOUBLE_TLV("Headphone Playback Volume", ES8316_CPHP_ICAL_VOL, |
---|
95 | 90 | 4, 0, 3, 1, hpout_vol_tlv), |
---|
96 | 91 | SOC_DOUBLE_TLV("Headphone Mixer Volume", ES8316_HPMIX_VOL, |
---|
97 | | - 0, 4, 11, 0, hpmixer_gain_tlv), |
---|
| 92 | + 4, 0, 11, 0, hpmixer_gain_tlv), |
---|
98 | 93 | |
---|
99 | 94 | SOC_ENUM("Playback Polarity", dacpol), |
---|
100 | 95 | SOC_DOUBLE_R_TLV("DAC Playback Volume", ES8316_DAC_VOLL, |
---|
.. | .. |
---|
104 | 99 | SOC_SINGLE("DAC Notch Filter Switch", ES8316_DAC_SET2, 6, 1, 0), |
---|
105 | 100 | SOC_SINGLE("DAC Double Fs Switch", ES8316_DAC_SET2, 7, 1, 0), |
---|
106 | 101 | SOC_SINGLE("DAC Stereo Enhancement", ES8316_DAC_SET3, 0, 7, 0), |
---|
| 102 | + SOC_SINGLE("DAC Mono Mix Switch", ES8316_DAC_SET3, 3, 1, 0), |
---|
107 | 103 | |
---|
108 | 104 | SOC_ENUM("Capture Polarity", adcpol), |
---|
109 | 105 | SOC_SINGLE("Mic Boost Switch", ES8316_ADC_D2SEPGA, 0, 1, 0), |
---|
.. | .. |
---|
169 | 165 | "lin-rin with Boost and PGA" |
---|
170 | 166 | }; |
---|
171 | 167 | |
---|
172 | | -static const unsigned int es8316_hpmux_values[] = { 0, 1, 2, 3 }; |
---|
173 | | - |
---|
174 | 168 | static SOC_ENUM_SINGLE_DECL(es8316_left_hpmux_enum, ES8316_HPMIX_SEL, |
---|
175 | 169 | 4, es8316_hpmux_texts); |
---|
176 | 170 | |
---|
.. | .. |
---|
200 | 194 | "RDATA TO LDAC, RDATA TO RDAC", |
---|
201 | 195 | "RDATA TO LDAC, LDATA TO RDAC", |
---|
202 | 196 | }; |
---|
203 | | - |
---|
204 | | -static const unsigned int es8316_dacsrc_values[] = { 0, 1, 2, 3 }; |
---|
205 | 197 | |
---|
206 | 198 | static SOC_ENUM_SINGLE_DECL(es8316_dacsrc_mux_enum, ES8316_DAC_SET1, |
---|
207 | 199 | 6, es8316_dacsrc_texts); |
---|
.. | .. |
---|
368 | 360 | { |
---|
369 | 361 | struct snd_soc_component *component = codec_dai->component; |
---|
370 | 362 | struct es8316_priv *es8316 = snd_soc_component_get_drvdata(component); |
---|
371 | | - int i; |
---|
| 363 | + int i, ret; |
---|
372 | 364 | int count = 0; |
---|
373 | 365 | |
---|
374 | 366 | es8316->sysclk = freq; |
---|
375 | 367 | |
---|
376 | | - if (freq == 0) |
---|
| 368 | + if (freq == 0) { |
---|
| 369 | + es8316->sysclk_constraints.list = NULL; |
---|
| 370 | + es8316->sysclk_constraints.count = 0; |
---|
| 371 | + |
---|
377 | 372 | return 0; |
---|
| 373 | + } |
---|
| 374 | + |
---|
| 375 | + ret = clk_set_rate(es8316->mclk, freq); |
---|
| 376 | + if (ret) |
---|
| 377 | + return ret; |
---|
378 | 378 | |
---|
379 | 379 | /* Limit supported sample rates to ones that can be autodetected |
---|
380 | 380 | * by the codec running in slave mode. |
---|
.. | .. |
---|
449 | 449 | struct snd_soc_component *component = dai->component; |
---|
450 | 450 | struct es8316_priv *es8316 = snd_soc_component_get_drvdata(component); |
---|
451 | 451 | |
---|
452 | | - if (es8316->sysclk == 0) { |
---|
453 | | - dev_err(component->dev, "No sysclk provided\n"); |
---|
454 | | - return -EINVAL; |
---|
455 | | - } |
---|
456 | | - |
---|
457 | | - /* The set of sample rates that can be supported depends on the |
---|
458 | | - * MCLK supplied to the CODEC. |
---|
459 | | - */ |
---|
460 | | - snd_pcm_hw_constraint_list(substream->runtime, 0, |
---|
461 | | - SNDRV_PCM_HW_PARAM_RATE, |
---|
462 | | - &es8316->sysclk_constraints); |
---|
| 452 | + if (es8316->sysclk_constraints.list) |
---|
| 453 | + snd_pcm_hw_constraint_list(substream->runtime, 0, |
---|
| 454 | + SNDRV_PCM_HW_PARAM_RATE, |
---|
| 455 | + &es8316->sysclk_constraints); |
---|
463 | 456 | |
---|
464 | 457 | return 0; |
---|
465 | 458 | } |
---|
.. | .. |
---|
471 | 464 | struct snd_soc_component *component = dai->component; |
---|
472 | 465 | struct es8316_priv *es8316 = snd_soc_component_get_drvdata(component); |
---|
473 | 466 | u8 wordlen = 0; |
---|
| 467 | + int i; |
---|
474 | 468 | |
---|
475 | | - if (!es8316->sysclk) { |
---|
476 | | - dev_err(component->dev, "No MCLK configured\n"); |
---|
477 | | - return -EINVAL; |
---|
| 469 | + /* Validate supported sample rates that are autodetected from MCLK */ |
---|
| 470 | + for (i = 0; i < NR_SUPPORTED_MCLK_LRCK_RATIOS; i++) { |
---|
| 471 | + const unsigned int ratio = supported_mclk_lrck_ratios[i]; |
---|
| 472 | + |
---|
| 473 | + if (es8316->sysclk % ratio != 0) |
---|
| 474 | + continue; |
---|
| 475 | + if (es8316->sysclk / ratio == params_rate(params)) |
---|
| 476 | + break; |
---|
478 | 477 | } |
---|
| 478 | + if (i == NR_SUPPORTED_MCLK_LRCK_RATIOS) |
---|
| 479 | + return -EINVAL; |
---|
479 | 480 | |
---|
480 | 481 | switch (params_format(params)) { |
---|
481 | 482 | case SNDRV_PCM_FORMAT_S16_LE: |
---|
.. | .. |
---|
501 | 502 | return 0; |
---|
502 | 503 | } |
---|
503 | 504 | |
---|
504 | | -static void es8316_enable_spk(struct es8316_priv *es8316, bool enable) |
---|
| 505 | +static int es8316_mute(struct snd_soc_dai *dai, int mute, int direction) |
---|
505 | 506 | { |
---|
506 | | - if (!es8316 || !es8316->gpiod_spk_ctl) |
---|
507 | | - return; |
---|
508 | | - gpiod_set_value(es8316->gpiod_spk_ctl, enable); |
---|
509 | | -} |
---|
510 | | - |
---|
511 | | -static int es8316_extcon_notifier(struct notifier_block *self, unsigned long event, void *ptr) |
---|
512 | | -{ |
---|
513 | | - struct es8316_priv *es8316 = container_of(self, struct es8316_priv, |
---|
514 | | - extcon_nb); |
---|
515 | | - |
---|
516 | | - if (event) { |
---|
517 | | - es8316->hp_inserted = true; |
---|
518 | | - es8316_enable_spk(es8316, false); |
---|
519 | | - } else { |
---|
520 | | - es8316->hp_inserted = false; |
---|
521 | | - } |
---|
522 | | - return NOTIFY_DONE; |
---|
523 | | -} |
---|
524 | | - |
---|
525 | | -static int es8316_mute(struct snd_soc_dai *dai, int mute) |
---|
526 | | -{ |
---|
527 | | - struct snd_soc_component *component = dai->component; |
---|
528 | | - struct es8316_priv *es8316 = snd_soc_component_get_drvdata(component); |
---|
529 | | - unsigned int val = mute ? 0x20 : 0; |
---|
530 | | - |
---|
531 | | - es8316->muted = mute; |
---|
532 | | - if (mute) { |
---|
533 | | - es8316_enable_spk(es8316, false); |
---|
534 | | - msleep(100); |
---|
535 | | - snd_soc_component_update_bits(dai->component, ES8316_DAC_SET1, 0x20, val); |
---|
536 | | - } else { |
---|
537 | | - snd_soc_component_update_bits(dai->component, ES8316_DAC_SET1, 0x20, val); |
---|
538 | | - msleep(130); |
---|
539 | | - if (!es8316->hp_inserted) |
---|
540 | | - es8316_enable_spk(es8316, true); |
---|
541 | | - } |
---|
542 | | - return 0; |
---|
543 | | -} |
---|
544 | | - |
---|
545 | | -static int es8316_set_bias_level(struct snd_soc_component *component, |
---|
546 | | - enum snd_soc_bias_level level) |
---|
547 | | -{ |
---|
548 | | - struct es8316_priv *es8316 = snd_soc_component_get_drvdata(component); |
---|
549 | | - int ret; |
---|
550 | | - |
---|
551 | | - switch (level) { |
---|
552 | | - case SND_SOC_BIAS_ON: |
---|
553 | | - break; |
---|
554 | | - case SND_SOC_BIAS_PREPARE: |
---|
555 | | - if (IS_ERR(es8316->mclk)) |
---|
556 | | - break; |
---|
557 | | - |
---|
558 | | - if (snd_soc_component_get_bias_level(component) == SND_SOC_BIAS_ON) { |
---|
559 | | - clk_disable_unprepare(es8316->mclk); |
---|
560 | | - } else { |
---|
561 | | - ret = clk_prepare_enable(es8316->mclk); |
---|
562 | | - if (ret) |
---|
563 | | - return ret; |
---|
564 | | - } |
---|
565 | | - break; |
---|
566 | | - |
---|
567 | | - case SND_SOC_BIAS_STANDBY: |
---|
568 | | - break; |
---|
569 | | - |
---|
570 | | - case SND_SOC_BIAS_OFF: |
---|
571 | | - break; |
---|
572 | | - } |
---|
| 507 | + snd_soc_component_update_bits(dai->component, ES8316_DAC_SET1, 0x20, |
---|
| 508 | + mute ? 0x20 : 0); |
---|
573 | 509 | return 0; |
---|
574 | 510 | } |
---|
575 | 511 | |
---|
.. | .. |
---|
581 | 517 | .hw_params = es8316_pcm_hw_params, |
---|
582 | 518 | .set_fmt = es8316_set_dai_fmt, |
---|
583 | 519 | .set_sysclk = es8316_set_dai_sysclk, |
---|
584 | | - .digital_mute = es8316_mute, |
---|
| 520 | + .mute_stream = es8316_mute, |
---|
| 521 | + .no_capture_mute = 1, |
---|
585 | 522 | }; |
---|
586 | 523 | |
---|
587 | 524 | static struct snd_soc_dai_driver es8316_dai = { |
---|
.. | .. |
---|
604 | 541 | .symmetric_rates = 1, |
---|
605 | 542 | }; |
---|
606 | 543 | |
---|
| 544 | +static void es8316_enable_micbias_for_mic_gnd_short_detect( |
---|
| 545 | + struct snd_soc_component *component) |
---|
| 546 | +{ |
---|
| 547 | + struct snd_soc_dapm_context *dapm = snd_soc_component_get_dapm(component); |
---|
| 548 | + |
---|
| 549 | + snd_soc_dapm_mutex_lock(dapm); |
---|
| 550 | + snd_soc_dapm_force_enable_pin_unlocked(dapm, "Bias"); |
---|
| 551 | + snd_soc_dapm_force_enable_pin_unlocked(dapm, "Analog power"); |
---|
| 552 | + snd_soc_dapm_force_enable_pin_unlocked(dapm, "Mic Bias"); |
---|
| 553 | + snd_soc_dapm_sync_unlocked(dapm); |
---|
| 554 | + snd_soc_dapm_mutex_unlock(dapm); |
---|
| 555 | + |
---|
| 556 | + msleep(20); |
---|
| 557 | +} |
---|
| 558 | + |
---|
| 559 | +static void es8316_disable_micbias_for_mic_gnd_short_detect( |
---|
| 560 | + struct snd_soc_component *component) |
---|
| 561 | +{ |
---|
| 562 | + struct snd_soc_dapm_context *dapm = snd_soc_component_get_dapm(component); |
---|
| 563 | + |
---|
| 564 | + snd_soc_dapm_mutex_lock(dapm); |
---|
| 565 | + snd_soc_dapm_disable_pin_unlocked(dapm, "Mic Bias"); |
---|
| 566 | + snd_soc_dapm_disable_pin_unlocked(dapm, "Analog power"); |
---|
| 567 | + snd_soc_dapm_disable_pin_unlocked(dapm, "Bias"); |
---|
| 568 | + snd_soc_dapm_sync_unlocked(dapm); |
---|
| 569 | + snd_soc_dapm_mutex_unlock(dapm); |
---|
| 570 | +} |
---|
| 571 | + |
---|
| 572 | +static irqreturn_t es8316_irq(int irq, void *data) |
---|
| 573 | +{ |
---|
| 574 | + struct es8316_priv *es8316 = data; |
---|
| 575 | + struct snd_soc_component *comp = es8316->component; |
---|
| 576 | + unsigned int flags; |
---|
| 577 | + |
---|
| 578 | + mutex_lock(&es8316->lock); |
---|
| 579 | + |
---|
| 580 | + regmap_read(es8316->regmap, ES8316_GPIO_FLAG, &flags); |
---|
| 581 | + if (flags == 0x00) |
---|
| 582 | + goto out; /* Powered-down / reset */ |
---|
| 583 | + |
---|
| 584 | + /* Catch spurious IRQ before set_jack is called */ |
---|
| 585 | + if (!es8316->jack) |
---|
| 586 | + goto out; |
---|
| 587 | + |
---|
| 588 | + if (es8316->jd_inverted) |
---|
| 589 | + flags ^= ES8316_GPIO_FLAG_HP_NOT_INSERTED; |
---|
| 590 | + |
---|
| 591 | + dev_dbg(comp->dev, "gpio flags %#04x\n", flags); |
---|
| 592 | + if (flags & ES8316_GPIO_FLAG_HP_NOT_INSERTED) { |
---|
| 593 | + /* Jack removed, or spurious IRQ? */ |
---|
| 594 | + if (es8316->jack->status & SND_JACK_MICROPHONE) |
---|
| 595 | + es8316_disable_micbias_for_mic_gnd_short_detect(comp); |
---|
| 596 | + |
---|
| 597 | + if (es8316->jack->status & SND_JACK_HEADPHONE) { |
---|
| 598 | + snd_soc_jack_report(es8316->jack, 0, |
---|
| 599 | + SND_JACK_HEADSET | SND_JACK_BTN_0); |
---|
| 600 | + dev_dbg(comp->dev, "jack unplugged\n"); |
---|
| 601 | + } |
---|
| 602 | + } else if (!(es8316->jack->status & SND_JACK_HEADPHONE)) { |
---|
| 603 | + /* Jack inserted, determine type */ |
---|
| 604 | + es8316_enable_micbias_for_mic_gnd_short_detect(comp); |
---|
| 605 | + regmap_read(es8316->regmap, ES8316_GPIO_FLAG, &flags); |
---|
| 606 | + if (es8316->jd_inverted) |
---|
| 607 | + flags ^= ES8316_GPIO_FLAG_HP_NOT_INSERTED; |
---|
| 608 | + dev_dbg(comp->dev, "gpio flags %#04x\n", flags); |
---|
| 609 | + if (flags & ES8316_GPIO_FLAG_HP_NOT_INSERTED) { |
---|
| 610 | + /* Jack unplugged underneath us */ |
---|
| 611 | + es8316_disable_micbias_for_mic_gnd_short_detect(comp); |
---|
| 612 | + } else if (flags & ES8316_GPIO_FLAG_GM_NOT_SHORTED) { |
---|
| 613 | + /* Open, headset */ |
---|
| 614 | + snd_soc_jack_report(es8316->jack, |
---|
| 615 | + SND_JACK_HEADSET, |
---|
| 616 | + SND_JACK_HEADSET); |
---|
| 617 | + /* Keep mic-gnd-short detection on for button press */ |
---|
| 618 | + } else { |
---|
| 619 | + /* Shorted, headphones */ |
---|
| 620 | + snd_soc_jack_report(es8316->jack, |
---|
| 621 | + SND_JACK_HEADPHONE, |
---|
| 622 | + SND_JACK_HEADSET); |
---|
| 623 | + /* No longer need mic-gnd-short detection */ |
---|
| 624 | + es8316_disable_micbias_for_mic_gnd_short_detect(comp); |
---|
| 625 | + } |
---|
| 626 | + } else if (es8316->jack->status & SND_JACK_MICROPHONE) { |
---|
| 627 | + /* Interrupt while jack inserted, report button state */ |
---|
| 628 | + if (flags & ES8316_GPIO_FLAG_GM_NOT_SHORTED) { |
---|
| 629 | + /* Open, button release */ |
---|
| 630 | + snd_soc_jack_report(es8316->jack, 0, SND_JACK_BTN_0); |
---|
| 631 | + } else { |
---|
| 632 | + /* Short, button press */ |
---|
| 633 | + snd_soc_jack_report(es8316->jack, |
---|
| 634 | + SND_JACK_BTN_0, |
---|
| 635 | + SND_JACK_BTN_0); |
---|
| 636 | + } |
---|
| 637 | + } |
---|
| 638 | + |
---|
| 639 | +out: |
---|
| 640 | + mutex_unlock(&es8316->lock); |
---|
| 641 | + return IRQ_HANDLED; |
---|
| 642 | +} |
---|
| 643 | + |
---|
| 644 | +static void es8316_enable_jack_detect(struct snd_soc_component *component, |
---|
| 645 | + struct snd_soc_jack *jack) |
---|
| 646 | +{ |
---|
| 647 | + struct es8316_priv *es8316 = snd_soc_component_get_drvdata(component); |
---|
| 648 | + |
---|
| 649 | + /* |
---|
| 650 | + * Init es8316->jd_inverted here and not in the probe, as we cannot |
---|
| 651 | + * guarantee that the bytchr-es8316 driver, which might set this |
---|
| 652 | + * property, will probe before us. |
---|
| 653 | + */ |
---|
| 654 | + es8316->jd_inverted = device_property_read_bool(component->dev, |
---|
| 655 | + "everest,jack-detect-inverted"); |
---|
| 656 | + |
---|
| 657 | + mutex_lock(&es8316->lock); |
---|
| 658 | + |
---|
| 659 | + es8316->jack = jack; |
---|
| 660 | + |
---|
| 661 | + if (es8316->jack->status & SND_JACK_MICROPHONE) |
---|
| 662 | + es8316_enable_micbias_for_mic_gnd_short_detect(component); |
---|
| 663 | + |
---|
| 664 | + snd_soc_component_update_bits(component, ES8316_GPIO_DEBOUNCE, |
---|
| 665 | + ES8316_GPIO_ENABLE_INTERRUPT, |
---|
| 666 | + ES8316_GPIO_ENABLE_INTERRUPT); |
---|
| 667 | + |
---|
| 668 | + mutex_unlock(&es8316->lock); |
---|
| 669 | + |
---|
| 670 | + /* Enable irq and sync initial jack state */ |
---|
| 671 | + enable_irq(es8316->irq); |
---|
| 672 | + es8316_irq(es8316->irq, es8316); |
---|
| 673 | +} |
---|
| 674 | + |
---|
| 675 | +static void es8316_disable_jack_detect(struct snd_soc_component *component) |
---|
| 676 | +{ |
---|
| 677 | + struct es8316_priv *es8316 = snd_soc_component_get_drvdata(component); |
---|
| 678 | + |
---|
| 679 | + disable_irq(es8316->irq); |
---|
| 680 | + |
---|
| 681 | + mutex_lock(&es8316->lock); |
---|
| 682 | + |
---|
| 683 | + snd_soc_component_update_bits(component, ES8316_GPIO_DEBOUNCE, |
---|
| 684 | + ES8316_GPIO_ENABLE_INTERRUPT, 0); |
---|
| 685 | + |
---|
| 686 | + if (es8316->jack->status & SND_JACK_MICROPHONE) { |
---|
| 687 | + es8316_disable_micbias_for_mic_gnd_short_detect(component); |
---|
| 688 | + snd_soc_jack_report(es8316->jack, 0, SND_JACK_BTN_0); |
---|
| 689 | + } |
---|
| 690 | + |
---|
| 691 | + es8316->jack = NULL; |
---|
| 692 | + |
---|
| 693 | + mutex_unlock(&es8316->lock); |
---|
| 694 | +} |
---|
| 695 | + |
---|
| 696 | +static int es8316_set_jack(struct snd_soc_component *component, |
---|
| 697 | + struct snd_soc_jack *jack, void *data) |
---|
| 698 | +{ |
---|
| 699 | + if (jack) |
---|
| 700 | + es8316_enable_jack_detect(component, jack); |
---|
| 701 | + else |
---|
| 702 | + es8316_disable_jack_detect(component); |
---|
| 703 | + |
---|
| 704 | + return 0; |
---|
| 705 | +} |
---|
| 706 | + |
---|
607 | 707 | static int es8316_probe(struct snd_soc_component *component) |
---|
608 | 708 | { |
---|
609 | 709 | struct es8316_priv *es8316 = snd_soc_component_get_drvdata(component); |
---|
610 | | - int ret = 0; |
---|
| 710 | + int ret; |
---|
611 | 711 | |
---|
612 | | - es8316->mclk = devm_clk_get(component->dev, "mclk"); |
---|
613 | | - if (PTR_ERR(es8316->mclk) == -EPROBE_DEFER) |
---|
614 | | - return -EPROBE_DEFER; |
---|
| 712 | + es8316->component = component; |
---|
| 713 | + |
---|
| 714 | + es8316->mclk = devm_clk_get_optional(component->dev, "mclk"); |
---|
| 715 | + if (IS_ERR(es8316->mclk)) { |
---|
| 716 | + dev_err(component->dev, "unable to get mclk\n"); |
---|
| 717 | + return PTR_ERR(es8316->mclk); |
---|
| 718 | + } |
---|
| 719 | + if (!es8316->mclk) |
---|
| 720 | + dev_warn(component->dev, "assuming static mclk\n"); |
---|
615 | 721 | |
---|
616 | 722 | ret = clk_prepare_enable(es8316->mclk); |
---|
617 | | - if (ret) |
---|
| 723 | + if (ret) { |
---|
| 724 | + dev_err(component->dev, "unable to enable mclk\n"); |
---|
618 | 725 | return ret; |
---|
| 726 | + } |
---|
619 | 727 | |
---|
620 | 728 | /* Reset codec and enable current state machine */ |
---|
621 | 729 | snd_soc_component_write(component, ES8316_RESET, 0x3f); |
---|
.. | .. |
---|
649 | 757 | static const struct snd_soc_component_driver soc_component_dev_es8316 = { |
---|
650 | 758 | .probe = es8316_probe, |
---|
651 | 759 | .remove = es8316_remove, |
---|
652 | | - .set_bias_level = es8316_set_bias_level, |
---|
| 760 | + .set_jack = es8316_set_jack, |
---|
653 | 761 | .controls = es8316_snd_controls, |
---|
654 | 762 | .num_controls = ARRAY_SIZE(es8316_snd_controls), |
---|
655 | 763 | .dapm_widgets = es8316_dapm_widgets, |
---|
.. | .. |
---|
661 | 769 | .non_legacy_dai_naming = 1, |
---|
662 | 770 | }; |
---|
663 | 771 | |
---|
| 772 | +static const struct regmap_range es8316_volatile_ranges[] = { |
---|
| 773 | + regmap_reg_range(ES8316_GPIO_FLAG, ES8316_GPIO_FLAG), |
---|
| 774 | +}; |
---|
| 775 | + |
---|
| 776 | +static const struct regmap_access_table es8316_volatile_table = { |
---|
| 777 | + .yes_ranges = es8316_volatile_ranges, |
---|
| 778 | + .n_yes_ranges = ARRAY_SIZE(es8316_volatile_ranges), |
---|
| 779 | +}; |
---|
| 780 | + |
---|
664 | 781 | static const struct regmap_config es8316_regmap = { |
---|
665 | 782 | .reg_bits = 8, |
---|
666 | 783 | .val_bits = 8, |
---|
667 | 784 | .max_register = 0x53, |
---|
| 785 | + .volatile_table = &es8316_volatile_table, |
---|
668 | 786 | .cache_type = REGCACHE_RBTREE, |
---|
669 | 787 | }; |
---|
670 | 788 | |
---|
671 | 789 | static int es8316_i2c_probe(struct i2c_client *i2c_client, |
---|
672 | 790 | const struct i2c_device_id *id) |
---|
673 | 791 | { |
---|
| 792 | + struct device *dev = &i2c_client->dev; |
---|
674 | 793 | struct es8316_priv *es8316; |
---|
675 | | - struct extcon_dev *edev; |
---|
676 | | - struct regmap *regmap; |
---|
677 | | - int ret = -1; |
---|
| 794 | + int ret; |
---|
678 | 795 | |
---|
679 | 796 | es8316 = devm_kzalloc(&i2c_client->dev, sizeof(struct es8316_priv), |
---|
680 | 797 | GFP_KERNEL); |
---|
681 | 798 | if (es8316 == NULL) |
---|
682 | 799 | return -ENOMEM; |
---|
683 | | - es8316->hp_inserted = false; |
---|
684 | | - es8316->muted = true; |
---|
| 800 | + |
---|
685 | 801 | i2c_set_clientdata(i2c_client, es8316); |
---|
686 | 802 | |
---|
687 | | - regmap = devm_regmap_init_i2c(i2c_client, &es8316_regmap); |
---|
688 | | - if (IS_ERR(regmap)) |
---|
689 | | - return PTR_ERR(regmap); |
---|
690 | | - es8316->gpiod_spk_ctl = devm_gpiod_get_optional(&i2c_client->dev, |
---|
691 | | - "spk-con", |
---|
692 | | - GPIOD_OUT_LOW); |
---|
693 | | - if (IS_ERR(es8316->gpiod_spk_ctl)) { |
---|
694 | | - ret = IS_ERR(es8316->gpiod_spk_ctl); |
---|
695 | | - es8316->gpiod_spk_ctl = NULL; |
---|
696 | | - dev_warn(&i2c_client->dev, "cannot get spk-con-gpio %d\n", ret); |
---|
| 803 | + es8316->regmap = devm_regmap_init_i2c(i2c_client, &es8316_regmap); |
---|
| 804 | + if (IS_ERR(es8316->regmap)) |
---|
| 805 | + return PTR_ERR(es8316->regmap); |
---|
| 806 | + |
---|
| 807 | + es8316->irq = i2c_client->irq; |
---|
| 808 | + mutex_init(&es8316->lock); |
---|
| 809 | + |
---|
| 810 | + ret = devm_request_threaded_irq(dev, es8316->irq, NULL, es8316_irq, |
---|
| 811 | + IRQF_TRIGGER_HIGH | IRQF_ONESHOT, |
---|
| 812 | + "es8316", es8316); |
---|
| 813 | + if (ret == 0) { |
---|
| 814 | + /* Gets re-enabled by es8316_set_jack() */ |
---|
| 815 | + disable_irq(es8316->irq); |
---|
| 816 | + } else { |
---|
| 817 | + dev_warn(dev, "Failed to get IRQ %d: %d\n", es8316->irq, ret); |
---|
| 818 | + es8316->irq = -ENXIO; |
---|
697 | 819 | } |
---|
698 | | - if (device_property_read_bool(&i2c_client->dev, "extcon")) { |
---|
699 | | - edev = extcon_get_edev_by_phandle(&i2c_client->dev, 0); |
---|
700 | | - if (IS_ERR(edev)) { |
---|
701 | | - if (PTR_ERR(edev) == -EPROBE_DEFER) |
---|
702 | | - return -EPROBE_DEFER; |
---|
703 | | - dev_err(&i2c_client->dev, "Invalid or missing extcon\n"); |
---|
704 | | - return PTR_ERR(edev); |
---|
705 | | - } |
---|
706 | | - es8316->extcon_nb.notifier_call = es8316_extcon_notifier; |
---|
707 | | - ret = devm_extcon_register_notifier(&i2c_client->dev, edev, |
---|
708 | | - ES8316_EXTCON_ID, |
---|
709 | | - &es8316->extcon_nb); |
---|
710 | | - if (ret < 0) { |
---|
711 | | - dev_err(&i2c_client->dev, "register notifier fail\n"); |
---|
712 | | - return ret; |
---|
713 | | - } |
---|
714 | | - } |
---|
| 820 | + |
---|
715 | 821 | return devm_snd_soc_register_component(&i2c_client->dev, |
---|
716 | | - &soc_component_dev_es8316, |
---|
717 | | - &es8316_dai, 1); |
---|
| 822 | + &soc_component_dev_es8316, |
---|
| 823 | + &es8316_dai, 1); |
---|
718 | 824 | } |
---|
719 | 825 | |
---|
720 | 826 | static const struct i2c_device_id es8316_i2c_id[] = { |
---|
.. | .. |
---|
729 | 835 | }; |
---|
730 | 836 | MODULE_DEVICE_TABLE(of, es8316_of_match); |
---|
731 | 837 | |
---|
| 838 | +#ifdef CONFIG_ACPI |
---|
732 | 839 | static const struct acpi_device_id es8316_acpi_match[] = { |
---|
733 | 840 | {"ESSX8316", 0}, |
---|
734 | 841 | {}, |
---|
735 | 842 | }; |
---|
736 | 843 | MODULE_DEVICE_TABLE(acpi, es8316_acpi_match); |
---|
| 844 | +#endif |
---|
737 | 845 | |
---|
738 | 846 | static struct i2c_driver es8316_i2c_driver = { |
---|
739 | 847 | .driver = { |
---|