| .. | .. |
|---|
| 21 | 21 | #include <linux/delay.h> |
|---|
| 22 | 22 | #include <linux/pm.h> |
|---|
| 23 | 23 | #include <linux/i2c.h> |
|---|
| 24 | +#include <linux/regulator/consumer.h> |
|---|
| 24 | 25 | #include <linux/spi/spi.h> |
|---|
| 25 | 26 | #include <linux/platform_device.h> |
|---|
| 26 | 27 | #include <linux/slab.h> |
|---|
| .. | .. |
|---|
| 50 | 51 | struct i2c_client *i2c; |
|---|
| 51 | 52 | |
|---|
| 52 | 53 | unsigned int pwr_vdd_voltage; |
|---|
| 54 | + struct regulator *vdd; |
|---|
| 53 | 55 | int reset_gpio; |
|---|
| 54 | 56 | bool reset_active_level; |
|---|
| 55 | 57 | }; |
|---|
| .. | .. |
|---|
| 72 | 74 | read_cmd[0] = reg; |
|---|
| 73 | 75 | cmd_len = 1; |
|---|
| 74 | 76 | |
|---|
| 75 | | - if (client->adapter == NULL) |
|---|
| 76 | | - printk("es7202_read client->adapter==NULL\n"); |
|---|
| 77 | + if (!client || !client->adapter) |
|---|
| 78 | + return -1; |
|---|
| 77 | 79 | |
|---|
| 78 | 80 | ret = i2c_master_send(client, read_cmd, cmd_len); |
|---|
| 79 | 81 | if (ret != cmd_len) { |
|---|
| .. | .. |
|---|
| 94 | 96 | { |
|---|
| 95 | 97 | int ret = 0; |
|---|
| 96 | 98 | u8 write_cmd[2] = { 0 }; |
|---|
| 99 | + |
|---|
| 100 | + if (!client || !client->adapter) |
|---|
| 101 | + return -1; |
|---|
| 97 | 102 | |
|---|
| 98 | 103 | write_cmd[0] = reg; |
|---|
| 99 | 104 | write_cmd[1] = value; |
|---|
| .. | .. |
|---|
| 533 | 538 | #endif |
|---|
| 534 | 539 | }; |
|---|
| 535 | 540 | |
|---|
| 536 | | -static int es7202_mute(struct snd_soc_dai *dai, int mute) |
|---|
| 541 | +static int es7202_mute(struct snd_soc_dai *dai, int mute, int stream) |
|---|
| 537 | 542 | { |
|---|
| 543 | + if (stream == SNDRV_PCM_STREAM_PLAYBACK) |
|---|
| 544 | + return 0; |
|---|
| 545 | + |
|---|
| 538 | 546 | if (mute) { |
|---|
| 539 | 547 | es7202_multi_chips_update_bits(ES7202_PDM_INF_CTL_REG07, 0x03,0x03); |
|---|
| 540 | | - } else if (dai->playback_active) { |
|---|
| 541 | | - es7202_multi_chips_update_bits(ES7202_PDM_INF_CTL_REG07, 0x03,0x00); |
|---|
| 548 | + } else { |
|---|
| 549 | + es7202_multi_chips_update_bits(ES7202_PDM_INF_CTL_REG07, 0x03,0x00); |
|---|
| 542 | 550 | } |
|---|
| 551 | + |
|---|
| 543 | 552 | return 0; |
|---|
| 544 | 553 | } |
|---|
| 545 | 554 | |
|---|
| 546 | 555 | #define es7202_RATES SNDRV_PCM_RATE_8000_96000 |
|---|
| 547 | 556 | |
|---|
| 548 | 557 | static struct snd_soc_dai_ops es7202_ops = { |
|---|
| 549 | | - .digital_mute = es7202_mute, |
|---|
| 558 | + .mute_stream = es7202_mute, |
|---|
| 550 | 559 | }; |
|---|
| 551 | 560 | #if ES7202_CHANNELS_MAX > 0 |
|---|
| 552 | 561 | static struct snd_soc_dai_driver es7202_dai0 = { |
|---|
| .. | .. |
|---|
| 554 | 563 | .capture = { |
|---|
| 555 | 564 | .stream_name = "Capture", |
|---|
| 556 | 565 | .channels_min = 1, |
|---|
| 557 | | - .channels_max = 2, |
|---|
| 566 | + .channels_max = 8, |
|---|
| 558 | 567 | .rates = es7202_RATES, |
|---|
| 559 | 568 | .formats = SNDRV_PCM_FMTBIT_S16_LE, |
|---|
| 560 | 569 | }, |
|---|
| .. | .. |
|---|
| 568 | 577 | .capture = { |
|---|
| 569 | 578 | .stream_name = "Capture", |
|---|
| 570 | 579 | .channels_min = 1, |
|---|
| 571 | | - .channels_max = 4, |
|---|
| 580 | + .channels_max = 8, |
|---|
| 572 | 581 | .rates = es7202_RATES, |
|---|
| 573 | 582 | .formats = SNDRV_PCM_FMTBIT_S16_LE, |
|---|
| 574 | 583 | }, |
|---|
| .. | .. |
|---|
| 582 | 591 | .capture = { |
|---|
| 583 | 592 | .stream_name = "Capture", |
|---|
| 584 | 593 | .channels_min = 1, |
|---|
| 585 | | - .channels_max = 6, |
|---|
| 594 | + .channels_max = 8, |
|---|
| 586 | 595 | .rates = es7202_RATES, |
|---|
| 587 | 596 | .formats = SNDRV_PCM_FMTBIT_S16_LE, |
|---|
| 588 | 597 | }, |
|---|
| .. | .. |
|---|
| 835 | 844 | const struct i2c_device_id *id) |
|---|
| 836 | 845 | { |
|---|
| 837 | 846 | struct es7202_priv *es7202; |
|---|
| 847 | + int uV; |
|---|
| 838 | 848 | int ret = -1; |
|---|
| 839 | | - //enum of_gpio_flags flags; |
|---|
| 840 | | - //struct device_node *np = i2c->dev.of_node; |
|---|
| 841 | | - |
|---|
| 842 | | - printk("enter into %s()\n", __func__); |
|---|
| 843 | | - |
|---|
| 849 | + |
|---|
| 850 | + dev_info(&i2c->dev, "probe\n"); |
|---|
| 844 | 851 | es7202 = devm_kzalloc(&i2c->dev, sizeof(*es7202), GFP_KERNEL); |
|---|
| 845 | 852 | if (!es7202) |
|---|
| 846 | 853 | return -ENOMEM; |
|---|
| 847 | | - |
|---|
| 848 | 854 | es7202->i2c = i2c; |
|---|
| 849 | | - es7202->pwr_vdd_voltage = ES7202_VDD_VOLTAGE; |
|---|
| 850 | | - |
|---|
| 855 | + es7202->vdd = devm_regulator_get_optional(&i2c->dev, "power"); |
|---|
| 856 | + if (IS_ERR(es7202->vdd)) { |
|---|
| 857 | + if (PTR_ERR(es7202->vdd) == -EPROBE_DEFER) |
|---|
| 858 | + return -EPROBE_DEFER; |
|---|
| 859 | + dev_warn(&i2c->dev, "power-supply get fail, use 3v3 as default\n"); |
|---|
| 860 | + es7202->pwr_vdd_voltage = VDD_3V3; |
|---|
| 861 | + } else { |
|---|
| 862 | + uV = regulator_get_voltage(es7202->vdd); |
|---|
| 863 | + dev_info(&i2c->dev, "probe power-supply %duV\n", uV); |
|---|
| 864 | + if (uV <= MAX_VOLTAGE_1_8) |
|---|
| 865 | + es7202->pwr_vdd_voltage = VDD_1V8; |
|---|
| 866 | + else |
|---|
| 867 | + es7202->pwr_vdd_voltage = VDD_3V3; |
|---|
| 868 | + } |
|---|
| 851 | 869 | dev_set_drvdata(&i2c->dev, es7202); |
|---|
| 852 | 870 | if (id->driver_data < ADC_DEV_MAXNUM) { |
|---|
| 853 | 871 | i2c_ctl[id->driver_data] = i2c; |
|---|
| 854 | | - #if 0 |
|---|
| 855 | | - if(id->driver_data == 0) { |
|---|
| 856 | | - es7202->reset_gpio = of_get_named_gpio_flags(np, |
|---|
| 857 | | - "es7202-reset-gpio", |
|---|
| 858 | | - 0, |
|---|
| 859 | | - &flags); |
|---|
| 860 | | - if (es7202->reset_gpio < 0) { |
|---|
| 861 | | - dev_info(&i2c->dev, |
|---|
| 862 | | - "Can not read property spk_ctl_gpio\n"); |
|---|
| 863 | | - es7202->reset_gpio = -1; |
|---|
| 864 | | - } else { |
|---|
| 865 | | - es7202->reset_active_level = |
|---|
| 866 | | - !(flags & OF_GPIO_ACTIVE_LOW); |
|---|
| 867 | | - ret = devm_gpio_request_one(&i2c->dev, |
|---|
| 868 | | - es7202->reset_gpio, |
|---|
| 869 | | - GPIOF_DIR_OUT, |
|---|
| 870 | | - NULL); |
|---|
| 871 | | - if (ret) { |
|---|
| 872 | | - dev_err(&i2c->dev, |
|---|
| 873 | | - "Failed to request spk_ctl_gpio\n"); |
|---|
| 874 | | - //return ret; |
|---|
| 875 | | - } else { |
|---|
| 876 | | - gpio_set_value(es7202->reset_gpio, |
|---|
| 877 | | - es7202->reset_active_level); |
|---|
| 878 | | - msleep(50); |
|---|
| 879 | | - gpio_set_value(es7202->reset_gpio, |
|---|
| 880 | | - !es7202->reset_active_level); |
|---|
| 881 | | - } |
|---|
| 882 | | - } |
|---|
| 883 | | - } |
|---|
| 884 | | -#endif |
|---|
| 885 | | - printk("%s()-----1\n", __func__); |
|---|
| 872 | + dev_info(&i2c->dev, "probe reigister es7202 dai(%s) component\n", |
|---|
| 873 | + es7202_dai[id->driver_data]->name); |
|---|
| 886 | 874 | ret = devm_snd_soc_register_component(&i2c->dev, &soc_codec_dev_es7202, |
|---|
| 887 | | - es7202_dai[id->driver_data], |
|---|
| 888 | | - 1); |
|---|
| 875 | + es7202_dai[id->driver_data], 1); |
|---|
| 889 | 876 | if (ret < 0) { |
|---|
| 890 | 877 | return ret; |
|---|
| 891 | | - } |
|---|
| 878 | + } |
|---|
| 892 | 879 | } |
|---|
| 893 | 880 | ret = sysfs_create_group(&i2c->dev.kobj, &es7202_debug_attr_group); |
|---|
| 894 | 881 | if (ret) { |
|---|
| 895 | | - pr_err("failed to create attr group\n"); |
|---|
| 896 | | - } |
|---|
| 897 | | - |
|---|
| 882 | + dev_err(&i2c->dev, "failed to create attr group\n"); |
|---|
| 883 | + } |
|---|
| 898 | 884 | return ret; |
|---|
| 899 | 885 | } |
|---|
| 900 | 886 | |
|---|