diff options
-rw-r--r-- | Documentation/devicetree/bindings/sound/sgtl5000.txt | 13 | ||||
-rw-r--r-- | sound/soc/codecs/sgtl5000.c | 98 |
2 files changed, 92 insertions, 19 deletions
diff --git a/Documentation/devicetree/bindings/sound/sgtl5000.txt b/Documentation/devicetree/bindings/sound/sgtl5000.txt index d556dcb8816b..0e5e4eb3ef1b 100644 --- a/Documentation/devicetree/bindings/sound/sgtl5000.txt +++ b/Documentation/devicetree/bindings/sound/sgtl5000.txt | |||
@@ -7,6 +7,17 @@ Required properties: | |||
7 | 7 | ||
8 | - clocks : the clock provider of SYS_MCLK | 8 | - clocks : the clock provider of SYS_MCLK |
9 | 9 | ||
10 | - micbias-resistor-k-ohms : the bias resistor to be used in kOmhs | ||
11 | The resistor can take values of 2k, 4k or 8k. | ||
12 | If set to 0 it will be off. | ||
13 | If this node is not mentioned or if the value is unknown, then | ||
14 | micbias resistor is set to 4K. | ||
15 | |||
16 | - micbias-voltage-m-volts : the bias voltage to be used in mVolts | ||
17 | The voltage can take values from 1.25V to 3V by 250mV steps | ||
18 | If this node is not mentionned or the value is unknown, then | ||
19 | the value is set to 1.25V. | ||
20 | |||
10 | - VDDA-supply : the regulator provider of VDDA | 21 | - VDDA-supply : the regulator provider of VDDA |
11 | 22 | ||
12 | - VDDIO-supply: the regulator provider of VDDIO | 23 | - VDDIO-supply: the regulator provider of VDDIO |
@@ -21,6 +32,8 @@ codec: sgtl5000@0a { | |||
21 | compatible = "fsl,sgtl5000"; | 32 | compatible = "fsl,sgtl5000"; |
22 | reg = <0x0a>; | 33 | reg = <0x0a>; |
23 | clocks = <&clks 150>; | 34 | clocks = <&clks 150>; |
35 | micbias-resistor-k-ohms = <2>; | ||
36 | micbias-voltage-m-volts = <2250>; | ||
24 | VDDA-supply = <®_3p3v>; | 37 | VDDA-supply = <®_3p3v>; |
25 | VDDIO-supply = <®_3p3v>; | 38 | VDDIO-supply = <®_3p3v>; |
26 | }; | 39 | }; |
diff --git a/sound/soc/codecs/sgtl5000.c b/sound/soc/codecs/sgtl5000.c index 6bb77d76561b..490404c6b4d8 100644 --- a/sound/soc/codecs/sgtl5000.c +++ b/sound/soc/codecs/sgtl5000.c | |||
@@ -16,6 +16,7 @@ | |||
16 | #include <linux/pm.h> | 16 | #include <linux/pm.h> |
17 | #include <linux/i2c.h> | 17 | #include <linux/i2c.h> |
18 | #include <linux/clk.h> | 18 | #include <linux/clk.h> |
19 | #include <linux/log2.h> | ||
19 | #include <linux/regmap.h> | 20 | #include <linux/regmap.h> |
20 | #include <linux/regulator/driver.h> | 21 | #include <linux/regulator/driver.h> |
21 | #include <linux/regulator/machine.h> | 22 | #include <linux/regulator/machine.h> |
@@ -121,6 +122,13 @@ struct ldo_regulator { | |||
121 | bool enabled; | 122 | bool enabled; |
122 | }; | 123 | }; |
123 | 124 | ||
125 | enum sgtl5000_micbias_resistor { | ||
126 | SGTL5000_MICBIAS_OFF = 0, | ||
127 | SGTL5000_MICBIAS_2K = 2, | ||
128 | SGTL5000_MICBIAS_4K = 4, | ||
129 | SGTL5000_MICBIAS_8K = 8, | ||
130 | }; | ||
131 | |||
124 | /* sgtl5000 private structure in codec */ | 132 | /* sgtl5000 private structure in codec */ |
125 | struct sgtl5000_priv { | 133 | struct sgtl5000_priv { |
126 | int sysclk; /* sysclk rate */ | 134 | int sysclk; /* sysclk rate */ |
@@ -131,6 +139,8 @@ struct sgtl5000_priv { | |||
131 | struct regmap *regmap; | 139 | struct regmap *regmap; |
132 | struct clk *mclk; | 140 | struct clk *mclk; |
133 | int revision; | 141 | int revision; |
142 | u8 micbias_resistor; | ||
143 | u8 micbias_voltage; | ||
134 | }; | 144 | }; |
135 | 145 | ||
136 | /* | 146 | /* |
@@ -145,12 +155,14 @@ struct sgtl5000_priv { | |||
145 | static int mic_bias_event(struct snd_soc_dapm_widget *w, | 155 | static int mic_bias_event(struct snd_soc_dapm_widget *w, |
146 | struct snd_kcontrol *kcontrol, int event) | 156 | struct snd_kcontrol *kcontrol, int event) |
147 | { | 157 | { |
158 | struct sgtl5000_priv *sgtl5000 = snd_soc_codec_get_drvdata(w->codec); | ||
159 | |||
148 | switch (event) { | 160 | switch (event) { |
149 | case SND_SOC_DAPM_POST_PMU: | 161 | case SND_SOC_DAPM_POST_PMU: |
150 | /* change mic bias resistor to 4Kohm */ | 162 | /* change mic bias resistor */ |
151 | snd_soc_update_bits(w->codec, SGTL5000_CHIP_MIC_CTRL, | 163 | snd_soc_update_bits(w->codec, SGTL5000_CHIP_MIC_CTRL, |
152 | SGTL5000_BIAS_R_MASK, | 164 | SGTL5000_BIAS_R_MASK, |
153 | SGTL5000_BIAS_R_4k << SGTL5000_BIAS_R_SHIFT); | 165 | sgtl5000->micbias_resistor << SGTL5000_BIAS_R_SHIFT); |
154 | break; | 166 | break; |
155 | 167 | ||
156 | case SND_SOC_DAPM_PRE_PMD: | 168 | case SND_SOC_DAPM_PRE_PMD: |
@@ -530,16 +542,16 @@ static int sgtl5000_set_dai_sysclk(struct snd_soc_dai *codec_dai, | |||
530 | 542 | ||
531 | /* | 543 | /* |
532 | * set clock according to i2s frame clock, | 544 | * set clock according to i2s frame clock, |
533 | * sgtl5000 provide 2 clock sources. | 545 | * sgtl5000 provides 2 clock sources: |
534 | * 1. sys_mclk. sample freq can only configure to | 546 | * 1. sys_mclk: sample freq can only be configured to |
535 | * 1/256, 1/384, 1/512 of sys_mclk. | 547 | * 1/256, 1/384, 1/512 of sys_mclk. |
536 | * 2. pll. can derive any audio clocks. | 548 | * 2. pll: can derive any audio clocks. |
537 | * | 549 | * |
538 | * clock setting rules: | 550 | * clock setting rules: |
539 | * 1. in slave mode, only sys_mclk can use. | 551 | * 1. in slave mode, only sys_mclk can be used |
540 | * 2. as constraint by sys_mclk, sample freq should | 552 | * 2. as constraint by sys_mclk, sample freq should be set to 32 kHz, 44.1 kHz |
541 | * set to 32k, 44.1k and above. | 553 | * and above. |
542 | * 3. using sys_mclk prefer to pll to save power. | 554 | * 3. usage of sys_mclk is preferred over pll to save power. |
543 | */ | 555 | */ |
544 | static int sgtl5000_set_clock(struct snd_soc_codec *codec, int frame_rate) | 556 | static int sgtl5000_set_clock(struct snd_soc_codec *codec, int frame_rate) |
545 | { | 557 | { |
@@ -549,8 +561,8 @@ static int sgtl5000_set_clock(struct snd_soc_codec *codec, int frame_rate) | |||
549 | 561 | ||
550 | /* | 562 | /* |
551 | * sample freq should be divided by frame clock, | 563 | * sample freq should be divided by frame clock, |
552 | * if frame clock lower than 44.1khz, sample feq should set to | 564 | * if frame clock is lower than 44.1 kHz, sample freq should be set to |
553 | * 32khz or 44.1khz. | 565 | * 32 kHz or 44.1 kHz. |
554 | */ | 566 | */ |
555 | switch (frame_rate) { | 567 | switch (frame_rate) { |
556 | case 8000: | 568 | case 8000: |
@@ -603,7 +615,8 @@ static int sgtl5000_set_clock(struct snd_soc_codec *codec, int frame_rate) | |||
603 | 615 | ||
604 | /* | 616 | /* |
605 | * calculate the divider of mclk/sample_freq, | 617 | * calculate the divider of mclk/sample_freq, |
606 | * factor of freq =96k can only be 256, since mclk in range (12m,27m) | 618 | * factor of freq = 96 kHz can only be 256, since mclk is in the range |
619 | * of 8 MHz - 27 MHz | ||
607 | */ | 620 | */ |
608 | switch (sgtl5000->sysclk / sys_fs) { | 621 | switch (sgtl5000->sysclk / sys_fs) { |
609 | case 256: | 622 | case 256: |
@@ -619,7 +632,7 @@ static int sgtl5000_set_clock(struct snd_soc_codec *codec, int frame_rate) | |||
619 | SGTL5000_MCLK_FREQ_SHIFT; | 632 | SGTL5000_MCLK_FREQ_SHIFT; |
620 | break; | 633 | break; |
621 | default: | 634 | default: |
622 | /* if mclk not satisify the divider, use pll */ | 635 | /* if mclk does not satisfy the divider, use pll */ |
623 | if (sgtl5000->master) { | 636 | if (sgtl5000->master) { |
624 | clk_ctl |= SGTL5000_MCLK_FREQ_PLL << | 637 | clk_ctl |= SGTL5000_MCLK_FREQ_PLL << |
625 | SGTL5000_MCLK_FREQ_SHIFT; | 638 | SGTL5000_MCLK_FREQ_SHIFT; |
@@ -795,7 +808,7 @@ static int ldo_regulator_enable(struct regulator_dev *dev) | |||
795 | SGTL5000_LINEREG_D_POWERUP, | 808 | SGTL5000_LINEREG_D_POWERUP, |
796 | SGTL5000_LINEREG_D_POWERUP); | 809 | SGTL5000_LINEREG_D_POWERUP); |
797 | 810 | ||
798 | /* when internal ldo enabled, simple digital power can be disabled */ | 811 | /* when internal ldo is enabled, simple digital power can be disabled */ |
799 | snd_soc_update_bits(codec, SGTL5000_CHIP_ANA_POWER, | 812 | snd_soc_update_bits(codec, SGTL5000_CHIP_ANA_POWER, |
800 | SGTL5000_LINREG_SIMPLE_POWERUP, | 813 | SGTL5000_LINREG_SIMPLE_POWERUP, |
801 | 0); | 814 | 0); |
@@ -1079,7 +1092,7 @@ static bool sgtl5000_readable(struct device *dev, unsigned int reg) | |||
1079 | /* | 1092 | /* |
1080 | * sgtl5000 has 3 internal power supplies: | 1093 | * sgtl5000 has 3 internal power supplies: |
1081 | * 1. VAG, normally set to vdda/2 | 1094 | * 1. VAG, normally set to vdda/2 |
1082 | * 2. chargepump, set to different value | 1095 | * 2. charge pump, set to different value |
1083 | * according to voltage of vdda and vddio | 1096 | * according to voltage of vdda and vddio |
1084 | * 3. line out VAG, normally set to vddio/2 | 1097 | * 3. line out VAG, normally set to vddio/2 |
1085 | * | 1098 | * |
@@ -1326,8 +1339,13 @@ static int sgtl5000_probe(struct snd_soc_codec *codec) | |||
1326 | SGTL5000_HP_ZCD_EN | | 1339 | SGTL5000_HP_ZCD_EN | |
1327 | SGTL5000_ADC_ZCD_EN); | 1340 | SGTL5000_ADC_ZCD_EN); |
1328 | 1341 | ||
1329 | snd_soc_write(codec, SGTL5000_CHIP_MIC_CTRL, 2); | 1342 | snd_soc_update_bits(codec, SGTL5000_CHIP_MIC_CTRL, |
1343 | SGTL5000_BIAS_R_MASK, | ||
1344 | sgtl5000->micbias_resistor << SGTL5000_BIAS_R_SHIFT); | ||
1330 | 1345 | ||
1346 | snd_soc_update_bits(codec, SGTL5000_CHIP_MIC_CTRL, | ||
1347 | SGTL5000_BIAS_R_MASK, | ||
1348 | sgtl5000->micbias_voltage << SGTL5000_BIAS_R_SHIFT); | ||
1331 | /* | 1349 | /* |
1332 | * disable DAP | 1350 | * disable DAP |
1333 | * TODO: | 1351 | * TODO: |
@@ -1418,9 +1436,10 @@ static int sgtl5000_i2c_probe(struct i2c_client *client, | |||
1418 | struct sgtl5000_priv *sgtl5000; | 1436 | struct sgtl5000_priv *sgtl5000; |
1419 | int ret, reg, rev; | 1437 | int ret, reg, rev; |
1420 | unsigned int mclk; | 1438 | unsigned int mclk; |
1439 | struct device_node *np = client->dev.of_node; | ||
1440 | u32 value; | ||
1421 | 1441 | ||
1422 | sgtl5000 = devm_kzalloc(&client->dev, sizeof(struct sgtl5000_priv), | 1442 | sgtl5000 = devm_kzalloc(&client->dev, sizeof(*sgtl5000), GFP_KERNEL); |
1423 | GFP_KERNEL); | ||
1424 | if (!sgtl5000) | 1443 | if (!sgtl5000) |
1425 | return -ENOMEM; | 1444 | return -ENOMEM; |
1426 | 1445 | ||
@@ -1470,6 +1489,47 @@ static int sgtl5000_i2c_probe(struct i2c_client *client, | |||
1470 | dev_info(&client->dev, "sgtl5000 revision 0x%x\n", rev); | 1489 | dev_info(&client->dev, "sgtl5000 revision 0x%x\n", rev); |
1471 | sgtl5000->revision = rev; | 1490 | sgtl5000->revision = rev; |
1472 | 1491 | ||
1492 | if (np) { | ||
1493 | if (!of_property_read_u32(np, | ||
1494 | "micbias-resistor-k-ohms", &value)) { | ||
1495 | switch (value) { | ||
1496 | case SGTL5000_MICBIAS_OFF: | ||
1497 | sgtl5000->micbias_resistor = 0; | ||
1498 | break; | ||
1499 | case SGTL5000_MICBIAS_2K: | ||
1500 | sgtl5000->micbias_resistor = 1; | ||
1501 | break; | ||
1502 | case SGTL5000_MICBIAS_4K: | ||
1503 | sgtl5000->micbias_resistor = 2; | ||
1504 | break; | ||
1505 | case SGTL5000_MICBIAS_8K: | ||
1506 | sgtl5000->micbias_resistor = 3; | ||
1507 | break; | ||
1508 | default: | ||
1509 | sgtl5000->micbias_resistor = 2; | ||
1510 | dev_err(&client->dev, | ||
1511 | "Unsuitable MicBias resistor\n"); | ||
1512 | } | ||
1513 | } else { | ||
1514 | /* default is 4Kohms */ | ||
1515 | sgtl5000->micbias_resistor = 2; | ||
1516 | } | ||
1517 | if (!of_property_read_u32(np, | ||
1518 | "micbias-voltage-m-volts", &value)) { | ||
1519 | /* 1250mV => 0 */ | ||
1520 | /* steps of 250mV */ | ||
1521 | if ((value >= 1250) && (value <= 3000)) | ||
1522 | sgtl5000->micbias_voltage = (value / 250) - 5; | ||
1523 | else { | ||
1524 | sgtl5000->micbias_voltage = 0; | ||
1525 | dev_err(&client->dev, | ||
1526 | "Unsuitable MicBias resistor\n"); | ||
1527 | } | ||
1528 | } else { | ||
1529 | sgtl5000->micbias_voltage = 0; | ||
1530 | } | ||
1531 | } | ||
1532 | |||
1473 | i2c_set_clientdata(client, sgtl5000); | 1533 | i2c_set_clientdata(client, sgtl5000); |
1474 | 1534 | ||
1475 | /* Ensure sgtl5000 will start with sane register values */ | 1535 | /* Ensure sgtl5000 will start with sane register values */ |