es8326.c (0663286e58e6f611f3578b5e63e1faa576d139fd) | es8326.c (04f96c9340463aae20d2511a3d6cb0b005b07d24) |
---|---|
1// SPDX-License-Identifier: GPL-2.0-only 2// 3// es8326.c -- es8326 ALSA SoC audio driver 4// Copyright Everest Semiconductor Co., Ltd 5// 6// Authors: David Yang <yangxiaohua@everest-semi.com> 7// 8 --- 27 unchanged lines hidden (view full) --- 36 u8 jack_pol; 37 u8 interrupt_src; 38 u8 interrupt_clk; 39 bool jd_inverted; 40 unsigned int sysclk; 41 42 bool calibrated; 43 int version; | 1// SPDX-License-Identifier: GPL-2.0-only 2// 3// es8326.c -- es8326 ALSA SoC audio driver 4// Copyright Everest Semiconductor Co., Ltd 5// 6// Authors: David Yang <yangxiaohua@everest-semi.com> 7// 8 --- 27 unchanged lines hidden (view full) --- 36 u8 jack_pol; 37 u8 interrupt_src; 38 u8 interrupt_clk; 39 bool jd_inverted; 40 unsigned int sysclk; 41 42 bool calibrated; 43 int version; |
44 int hp; 45 int jack_remove_retry; |
|
44}; 45 46static const SNDRV_CTL_TLVD_DECLARE_DB_SCALE(dac_vol_tlv, -9550, 50, 0); 47static const SNDRV_CTL_TLVD_DECLARE_DB_SCALE(adc_vol_tlv, -9550, 50, 0); 48static const SNDRV_CTL_TLVD_DECLARE_DB_SCALE(adc_analog_pga_tlv, 0, 300, 0); 49static const SNDRV_CTL_TLVD_DECLARE_DB_SCALE(adc_pga_tlv, 0, 600, 0); 50static const SNDRV_CTL_TLVD_DECLARE_DB_SCALE(softramp_rate, 0, 100, 0); 51static const SNDRV_CTL_TLVD_DECLARE_DB_SCALE(drc_target_tlv, -3200, 200, 0); --- 478 unchanged lines hidden (view full) --- 530 mutex_lock(&es8326->lock); 531 iface = snd_soc_component_read(comp, ES8326_HPDET_STA); 532 switch (iface) { 533 case 0x93: 534 /* pause button detected */ 535 cur_button = SND_JACK_BTN_0; 536 break; 537 case 0x6f: | 46}; 47 48static const SNDRV_CTL_TLVD_DECLARE_DB_SCALE(dac_vol_tlv, -9550, 50, 0); 49static const SNDRV_CTL_TLVD_DECLARE_DB_SCALE(adc_vol_tlv, -9550, 50, 0); 50static const SNDRV_CTL_TLVD_DECLARE_DB_SCALE(adc_analog_pga_tlv, 0, 300, 0); 51static const SNDRV_CTL_TLVD_DECLARE_DB_SCALE(adc_pga_tlv, 0, 600, 0); 52static const SNDRV_CTL_TLVD_DECLARE_DB_SCALE(softramp_rate, 0, 100, 0); 53static const SNDRV_CTL_TLVD_DECLARE_DB_SCALE(drc_target_tlv, -3200, 200, 0); --- 478 unchanged lines hidden (view full) --- 532 mutex_lock(&es8326->lock); 533 iface = snd_soc_component_read(comp, ES8326_HPDET_STA); 534 switch (iface) { 535 case 0x93: 536 /* pause button detected */ 537 cur_button = SND_JACK_BTN_0; 538 break; 539 case 0x6f: |
540 case 0x4b: |
|
538 /* button volume up */ 539 cur_button = SND_JACK_BTN_1; 540 break; 541 case 0x27: 542 /* button volume down */ 543 cur_button = SND_JACK_BTN_2; 544 break; 545 case 0x1e: | 541 /* button volume up */ 542 cur_button = SND_JACK_BTN_1; 543 break; 544 case 0x27: 545 /* button volume down */ 546 cur_button = SND_JACK_BTN_2; 547 break; 548 case 0x1e: |
549 case 0xe2: |
|
546 /* button released or not pressed */ 547 cur_button = 0; 548 break; 549 default: 550 break; 551 } 552 553 if ((prev_button == cur_button) && (cur_button != 0)) { 554 press_count++; | 550 /* button released or not pressed */ 551 cur_button = 0; 552 break; 553 default: 554 break; 555 } 556 557 if ((prev_button == cur_button) && (cur_button != 0)) { 558 press_count++; |
555 if (press_count > 10) { 556 /* report a press every 500ms */ | 559 if (press_count > 3) { 560 /* report a press every 120ms */ |
557 snd_soc_jack_report(es8326->jack, cur_button, 558 SND_JACK_BTN_0 | SND_JACK_BTN_1 | SND_JACK_BTN_2); 559 press_count = 0; 560 } 561 button_to_report = cur_button; 562 queue_delayed_work(system_wq, &es8326->button_press_work, | 561 snd_soc_jack_report(es8326->jack, cur_button, 562 SND_JACK_BTN_0 | SND_JACK_BTN_1 | SND_JACK_BTN_2); 563 press_count = 0; 564 } 565 button_to_report = cur_button; 566 queue_delayed_work(system_wq, &es8326->button_press_work, |
563 msecs_to_jiffies(50)); | 567 msecs_to_jiffies(35)); |
564 } else if (prev_button != cur_button) { 565 /* mismatch, detect again */ 566 prev_button = cur_button; 567 queue_delayed_work(system_wq, &es8326->button_press_work, | 568 } else if (prev_button != cur_button) { 569 /* mismatch, detect again */ 570 prev_button = cur_button; 571 queue_delayed_work(system_wq, &es8326->button_press_work, |
568 msecs_to_jiffies(50)); | 572 msecs_to_jiffies(35)); |
569 } else { 570 /* released or no pressed */ 571 if (button_to_report != 0) { 572 snd_soc_jack_report(es8326->jack, button_to_report, 573 SND_JACK_BTN_0 | SND_JACK_BTN_1 | SND_JACK_BTN_2); 574 snd_soc_jack_report(es8326->jack, 0, 575 SND_JACK_BTN_0 | SND_JACK_BTN_1 | SND_JACK_BTN_2); 576 button_to_report = 0; --- 7 unchanged lines hidden (view full) --- 584 struct es8326_priv *es8326 = 585 container_of(work, struct es8326_priv, jack_detect_work.work); 586 struct snd_soc_component *comp = es8326->component; 587 unsigned int iface; 588 589 mutex_lock(&es8326->lock); 590 iface = snd_soc_component_read(comp, ES8326_HPDET_STA); 591 dev_dbg(comp->dev, "gpio flag %#04x", iface); | 573 } else { 574 /* released or no pressed */ 575 if (button_to_report != 0) { 576 snd_soc_jack_report(es8326->jack, button_to_report, 577 SND_JACK_BTN_0 | SND_JACK_BTN_1 | SND_JACK_BTN_2); 578 snd_soc_jack_report(es8326->jack, 0, 579 SND_JACK_BTN_0 | SND_JACK_BTN_1 | SND_JACK_BTN_2); 580 button_to_report = 0; --- 7 unchanged lines hidden (view full) --- 588 struct es8326_priv *es8326 = 589 container_of(work, struct es8326_priv, jack_detect_work.work); 590 struct snd_soc_component *comp = es8326->component; 591 unsigned int iface; 592 593 mutex_lock(&es8326->lock); 594 iface = snd_soc_component_read(comp, ES8326_HPDET_STA); 595 dev_dbg(comp->dev, "gpio flag %#04x", iface); |
596 597 if (es8326->jack_remove_retry == 1) { 598 if (iface & ES8326_HPINSERT_FLAG) 599 es8326->jack_remove_retry = 2; 600 else 601 es8326->jack_remove_retry = 0; 602 603 dev_dbg(comp->dev, "remove event check, set HPJACK_POL normal, cnt = %d\n", 604 es8326->jack_remove_retry); 605 /* 606 * Inverted HPJACK_POL bit to trigger one IRQ to double check HP Removal event 607 */ 608 regmap_update_bits(es8326->regmap, ES8326_HPDET_TYPE, 609 ES8326_HP_DET_JACK_POL, (es8326->jd_inverted ? 610 ~es8326->jack_pol : es8326->jack_pol)); 611 goto exit; 612 } 613 |
|
592 if ((iface & ES8326_HPINSERT_FLAG) == 0) { 593 /* Jack unplugged or spurious IRQ */ | 614 if ((iface & ES8326_HPINSERT_FLAG) == 0) { 615 /* Jack unplugged or spurious IRQ */ |
594 dev_dbg(comp->dev, "No headset detected"); | 616 dev_dbg(comp->dev, "No headset detected\n"); 617 es8326_disable_micbias(es8326->component); |
595 if (es8326->jack->status & SND_JACK_HEADPHONE) { | 618 if (es8326->jack->status & SND_JACK_HEADPHONE) { |
619 dev_dbg(comp->dev, "Report hp remove event\n"); |
|
596 snd_soc_jack_report(es8326->jack, 0, SND_JACK_HEADSET); | 620 snd_soc_jack_report(es8326->jack, 0, SND_JACK_HEADSET); |
597 snd_soc_component_write(comp, ES8326_ADC1_SRC, es8326->mic2_src); 598 es8326_disable_micbias(comp); | 621 /* mute adc when mic path switch */ 622 regmap_write(es8326->regmap, ES8326_ADC_SCALE, 0x33); 623 regmap_write(es8326->regmap, ES8326_ADC1_SRC, 0x44); 624 regmap_write(es8326->regmap, ES8326_ADC2_SRC, 0x66); 625 es8326->hp = 0; |
599 } | 626 } |
627 regmap_update_bits(es8326->regmap, ES8326_HPDET_TYPE, 0x03, 0x01); 628 /* 629 * Inverted HPJACK_POL bit to trigger one IRQ to double check HP Removal event 630 */ 631 if (es8326->jack_remove_retry == 0) { 632 es8326->jack_remove_retry = 1; 633 dev_dbg(comp->dev, "remove event check, invert HPJACK_POL, cnt = %d\n", 634 es8326->jack_remove_retry); 635 regmap_update_bits(es8326->regmap, ES8326_HPDET_TYPE, 636 ES8326_HP_DET_JACK_POL, (es8326->jd_inverted ? 637 es8326->jack_pol : ~es8326->jack_pol)); 638 639 } else { 640 es8326->jack_remove_retry = 0; 641 } |
|
600 } else if ((iface & ES8326_HPINSERT_FLAG) == ES8326_HPINSERT_FLAG) { | 642 } else if ((iface & ES8326_HPINSERT_FLAG) == ES8326_HPINSERT_FLAG) { |
643 es8326->jack_remove_retry = 0; 644 if (es8326->hp == 0) { 645 dev_dbg(comp->dev, "First insert, start OMTP/CTIA type check\n"); 646 /* 647 * set auto-check mode, then restart jack_detect_work after 100ms. 648 * Don't report jack status. 649 */ 650 regmap_update_bits(es8326->regmap, ES8326_HPDET_TYPE, 0x03, 0x01); 651 usleep_range(50000, 70000); 652 regmap_update_bits(es8326->regmap, ES8326_HPDET_TYPE, 0x03, 0x00); 653 queue_delayed_work(system_wq, &es8326->jack_detect_work, 654 msecs_to_jiffies(100)); 655 es8326->hp = 1; 656 goto exit; 657 } |
|
601 if (es8326->jack->status & SND_JACK_HEADSET) { 602 /* detect button */ | 658 if (es8326->jack->status & SND_JACK_HEADSET) { 659 /* detect button */ |
660 dev_dbg(comp->dev, "button pressed\n"); |
|
603 queue_delayed_work(system_wq, &es8326->button_press_work, 10); | 661 queue_delayed_work(system_wq, &es8326->button_press_work, 10); |
662 goto exit; 663 } 664 if ((iface & ES8326_HPBUTTON_FLAG) == 0x01) { 665 dev_dbg(comp->dev, "Headphone detected\n"); 666 snd_soc_jack_report(es8326->jack, 667 SND_JACK_HEADPHONE, SND_JACK_HEADSET); |
|
604 } else { | 668 } else { |
605 if ((iface & ES8326_HPBUTTON_FLAG) == 0x00) { 606 dev_dbg(comp->dev, "Headset detected"); 607 snd_soc_jack_report(es8326->jack, 608 SND_JACK_HEADSET, SND_JACK_HEADSET); 609 snd_soc_component_write(comp, 610 ES8326_ADC1_SRC, es8326->mic1_src); 611 } else { 612 dev_dbg(comp->dev, "Headphone detected"); 613 snd_soc_jack_report(es8326->jack, 614 SND_JACK_HEADPHONE, SND_JACK_HEADSET); 615 } | 669 dev_dbg(comp->dev, "Headset detected\n"); 670 snd_soc_jack_report(es8326->jack, 671 SND_JACK_HEADSET, SND_JACK_HEADSET); 672 673 regmap_write(es8326->regmap, ES8326_ADC_SCALE, 0x33); 674 regmap_update_bits(es8326->regmap, ES8326_PGA_PDN, 675 0x08, 0x08); 676 regmap_update_bits(es8326->regmap, ES8326_PGAGAIN, 677 0x80, 0x80); 678 regmap_write(es8326->regmap, ES8326_ADC1_SRC, 0x00); 679 regmap_write(es8326->regmap, ES8326_ADC2_SRC, 0x00); 680 regmap_update_bits(es8326->regmap, ES8326_PGA_PDN, 681 0x08, 0x00); 682 usleep_range(10000, 15000); |
616 } 617 } | 683 } 684 } |
685exit: |
|
618 mutex_unlock(&es8326->lock); 619} 620 621static irqreturn_t es8326_irq(int irq, void *dev_id) 622{ 623 struct es8326_priv *es8326 = dev_id; 624 struct snd_soc_component *comp = es8326->component; 625 626 if (!es8326->jack) 627 goto out; 628 629 es8326_enable_micbias(comp); 630 631 if (es8326->jack->status & SND_JACK_HEADSET) 632 queue_delayed_work(system_wq, &es8326->jack_detect_work, 633 msecs_to_jiffies(10)); 634 else 635 queue_delayed_work(system_wq, &es8326->jack_detect_work, | 686 mutex_unlock(&es8326->lock); 687} 688 689static irqreturn_t es8326_irq(int irq, void *dev_id) 690{ 691 struct es8326_priv *es8326 = dev_id; 692 struct snd_soc_component *comp = es8326->component; 693 694 if (!es8326->jack) 695 goto out; 696 697 es8326_enable_micbias(comp); 698 699 if (es8326->jack->status & SND_JACK_HEADSET) 700 queue_delayed_work(system_wq, &es8326->jack_detect_work, 701 msecs_to_jiffies(10)); 702 else 703 queue_delayed_work(system_wq, &es8326->jack_detect_work, |
636 msecs_to_jiffies(300)); | 704 msecs_to_jiffies(600)); |
637 638out: 639 return IRQ_HANDLED; 640} 641 642static int es8326_calibrate(struct snd_soc_component *component) 643{ 644 struct es8326_priv *es8326 = snd_soc_component_get_drvdata(component); --- 113 unchanged lines hidden (view full) --- 758 regmap_update_bits(es8326->regmap, ES8326_DAC_MUTE, ES8326_MUTE_MASK, 759 ES8326_MUTE); 760 761 regmap_write(es8326->regmap, ES8326_HPDET_TYPE, 0x80 | 762 ((es8326->version == ES8326_VERSION_B) ? 763 (ES8326_HP_DET_SRC_PIN9 | es8326->jack_pol) : 764 (ES8326_HP_DET_SRC_PIN9 | es8326->jack_pol | 0x04))); 765 | 705 706out: 707 return IRQ_HANDLED; 708} 709 710static int es8326_calibrate(struct snd_soc_component *component) 711{ 712 struct es8326_priv *es8326 = snd_soc_component_get_drvdata(component); --- 113 unchanged lines hidden (view full) --- 826 regmap_update_bits(es8326->regmap, ES8326_DAC_MUTE, ES8326_MUTE_MASK, 827 ES8326_MUTE); 828 829 regmap_write(es8326->regmap, ES8326_HPDET_TYPE, 0x80 | 830 ((es8326->version == ES8326_VERSION_B) ? 831 (ES8326_HP_DET_SRC_PIN9 | es8326->jack_pol) : 832 (ES8326_HP_DET_SRC_PIN9 | es8326->jack_pol | 0x04))); 833 |
766 es8326_irq(es8326->irq, es8326); | 834 es8326->jack_remove_retry = 0; 835 es8326->hp = 0; |
767 return 0; 768} 769 770static int es8326_suspend(struct snd_soc_component *component) 771{ 772 struct es8326_priv *es8326 = snd_soc_component_get_drvdata(component); 773 774 cancel_delayed_work_sync(&es8326->jack_detect_work); --- 218 unchanged lines hidden --- | 836 return 0; 837} 838 839static int es8326_suspend(struct snd_soc_component *component) 840{ 841 struct es8326_priv *es8326 = snd_soc_component_get_drvdata(component); 842 843 cancel_delayed_work_sync(&es8326->jack_detect_work); --- 218 unchanged lines hidden --- |