wm8731.c (06be5eefe1192eb8ce8d07497f67595b6bfe9741) | wm8731.c (6702dfcc571d962df499f7466f54e07d044e6cd1) |
---|---|
1/* 2 * wm8731.c -- WM8731 ALSA SoC Audio driver 3 * 4 * Copyright 2005 Openedhand Ltd. 5 * Copyright 2006-12 Wolfson Microelectronics, plc 6 * 7 * Author: Richard Purdie <richard@openedhand.com> 8 * --- 70 unchanged lines hidden (view full) --- 79 return reg == WM8731_RESET; 80} 81 82static bool wm8731_writeable(struct device *dev, unsigned int reg) 83{ 84 return reg <= WM8731_RESET; 85} 86 | 1/* 2 * wm8731.c -- WM8731 ALSA SoC Audio driver 3 * 4 * Copyright 2005 Openedhand Ltd. 5 * Copyright 2006-12 Wolfson Microelectronics, plc 6 * 7 * Author: Richard Purdie <richard@openedhand.com> 8 * --- 70 unchanged lines hidden (view full) --- 79 return reg == WM8731_RESET; 80} 81 82static bool wm8731_writeable(struct device *dev, unsigned int reg) 83{ 84 return reg <= WM8731_RESET; 85} 86 |
87#define wm8731_reset(c) snd_soc_write(c, WM8731_RESET, 0) | 87#define wm8731_reset(m) regmap_write(m, WM8731_RESET, 0) |
88 89static const char *wm8731_input_select[] = {"Line In", "Mic"}; 90 91static SOC_ENUM_SINGLE_DECL(wm8731_insel_enum, 92 WM8731_APANA, 2, wm8731_input_select); 93 94static int wm8731_deemph[] = { 0, 32000, 44100, 48000 }; 95 --- 470 unchanged lines hidden (view full) --- 566 .channels_min = 1, 567 .channels_max = 2, 568 .rates = WM8731_RATES, 569 .formats = WM8731_FORMATS,}, 570 .ops = &wm8731_dai_ops, 571 .symmetric_rates = 1, 572}; 573 | 88 89static const char *wm8731_input_select[] = {"Line In", "Mic"}; 90 91static SOC_ENUM_SINGLE_DECL(wm8731_insel_enum, 92 WM8731_APANA, 2, wm8731_input_select); 93 94static int wm8731_deemph[] = { 0, 32000, 44100, 48000 }; 95 --- 470 unchanged lines hidden (view full) --- 566 .channels_min = 1, 567 .channels_max = 2, 568 .rates = WM8731_RATES, 569 .formats = WM8731_FORMATS,}, 570 .ops = &wm8731_dai_ops, 571 .symmetric_rates = 1, 572}; 573 |
574static int wm8731_probe(struct snd_soc_codec *codec) | 574static int wm8731_request_supplies(struct device *dev, 575 struct wm8731_priv *wm8731) |
575{ | 576{ |
576 struct wm8731_priv *wm8731 = snd_soc_codec_get_drvdata(codec); | |
577 int ret = 0, i; 578 579 for (i = 0; i < ARRAY_SIZE(wm8731->supplies); i++) 580 wm8731->supplies[i].supply = wm8731_supply_names[i]; 581 | 577 int ret = 0, i; 578 579 for (i = 0; i < ARRAY_SIZE(wm8731->supplies); i++) 580 wm8731->supplies[i].supply = wm8731_supply_names[i]; 581 |
582 ret = devm_regulator_bulk_get(codec->dev, ARRAY_SIZE(wm8731->supplies), | 582 ret = devm_regulator_bulk_get(dev, ARRAY_SIZE(wm8731->supplies), |
583 wm8731->supplies); 584 if (ret != 0) { | 583 wm8731->supplies); 584 if (ret != 0) { |
585 dev_err(codec->dev, "Failed to request supplies: %d\n", ret); | 585 dev_err(dev, "Failed to request supplies: %d\n", ret); |
586 return ret; 587 } 588 589 ret = regulator_bulk_enable(ARRAY_SIZE(wm8731->supplies), 590 wm8731->supplies); 591 if (ret != 0) { | 586 return ret; 587 } 588 589 ret = regulator_bulk_enable(ARRAY_SIZE(wm8731->supplies), 590 wm8731->supplies); 591 if (ret != 0) { |
592 dev_err(codec->dev, "Failed to enable supplies: %d\n", ret); | 592 dev_err(dev, "Failed to enable supplies: %d\n", ret); |
593 return ret; 594 } 595 | 593 return ret; 594 } 595 |
596 ret = wm8731_reset(codec); | 596 return 0; 597} 598 599static int wm8731_hw_init(struct device *dev, struct wm8731_priv *wm8731) 600{ 601 int ret = 0; 602 603 ret = wm8731_reset(wm8731->regmap); |
597 if (ret < 0) { | 604 if (ret < 0) { |
598 dev_err(codec->dev, "Failed to issue reset: %d\n", ret); | 605 dev_err(dev, "Failed to issue reset: %d\n", ret); |
599 goto err_regulator_enable; 600 } 601 | 606 goto err_regulator_enable; 607 } 608 |
602 snd_soc_codec_force_bias_level(codec, SND_SOC_BIAS_STANDBY); | 609 /* Clear POWEROFF, keep everything else disabled */ 610 regmap_write(wm8731->regmap, WM8731_PWR, 0x7f); |
603 604 /* Latch the update bits */ | 611 612 /* Latch the update bits */ |
605 snd_soc_update_bits(codec, WM8731_LOUT1V, 0x100, 0); 606 snd_soc_update_bits(codec, WM8731_ROUT1V, 0x100, 0); 607 snd_soc_update_bits(codec, WM8731_LINVOL, 0x100, 0); 608 snd_soc_update_bits(codec, WM8731_RINVOL, 0x100, 0); | 613 regmap_update_bits(wm8731->regmap, WM8731_LOUT1V, 0x100, 0); 614 regmap_update_bits(wm8731->regmap, WM8731_ROUT1V, 0x100, 0); 615 regmap_update_bits(wm8731->regmap, WM8731_LINVOL, 0x100, 0); 616 regmap_update_bits(wm8731->regmap, WM8731_RINVOL, 0x100, 0); |
609 610 /* Disable bypass path by default */ | 617 618 /* Disable bypass path by default */ |
611 snd_soc_update_bits(codec, WM8731_APANA, 0x8, 0); | 619 regmap_update_bits(wm8731->regmap, WM8731_APANA, 0x8, 0); |
612 | 620 |
613 /* Regulators will have been enabled by bias management */ 614 regulator_bulk_disable(ARRAY_SIZE(wm8731->supplies), wm8731->supplies); | 621 regcache_mark_dirty(wm8731->regmap); |
615 | 622 |
616 return 0; 617 | |
618err_regulator_enable: | 623err_regulator_enable: |
624 /* Regulators will be enabled by bias management */ |
|
619 regulator_bulk_disable(ARRAY_SIZE(wm8731->supplies), wm8731->supplies); 620 621 return ret; 622} 623 | 625 regulator_bulk_disable(ARRAY_SIZE(wm8731->supplies), wm8731->supplies); 626 627 return ret; 628} 629 |
624/* power down chip */ 625static int wm8731_remove(struct snd_soc_codec *codec) 626{ 627 struct wm8731_priv *wm8731 = snd_soc_codec_get_drvdata(codec); 628 629 regulator_bulk_disable(ARRAY_SIZE(wm8731->supplies), wm8731->supplies); 630 631 return 0; 632} 633 | |
634static struct snd_soc_codec_driver soc_codec_dev_wm8731 = { | 630static struct snd_soc_codec_driver soc_codec_dev_wm8731 = { |
635 .probe = wm8731_probe, 636 .remove = wm8731_remove, | |
637 .set_bias_level = wm8731_set_bias_level, 638 .suspend_bias_off = true, 639 640 .dapm_widgets = wm8731_dapm_widgets, 641 .num_dapm_widgets = ARRAY_SIZE(wm8731_dapm_widgets), 642 .dapm_routes = wm8731_intercon, 643 .num_dapm_routes = ARRAY_SIZE(wm8731_intercon), 644 .controls = wm8731_snd_controls, --- 40 unchanged lines hidden (view full) --- 685 dev_err(&spi->dev, "Failed to get MCLK: %d\n", 686 ret); 687 return ret; 688 } 689 } 690 691 mutex_init(&wm8731->lock); 692 | 631 .set_bias_level = wm8731_set_bias_level, 632 .suspend_bias_off = true, 633 634 .dapm_widgets = wm8731_dapm_widgets, 635 .num_dapm_widgets = ARRAY_SIZE(wm8731_dapm_widgets), 636 .dapm_routes = wm8731_intercon, 637 .num_dapm_routes = ARRAY_SIZE(wm8731_intercon), 638 .controls = wm8731_snd_controls, --- 40 unchanged lines hidden (view full) --- 679 dev_err(&spi->dev, "Failed to get MCLK: %d\n", 680 ret); 681 return ret; 682 } 683 } 684 685 mutex_init(&wm8731->lock); 686 |
687 spi_set_drvdata(spi, wm8731); 688 689 ret = wm8731_request_supplies(&spi->dev, wm8731); 690 if (ret != 0) 691 return ret; 692 |
|
693 wm8731->regmap = devm_regmap_init_spi(spi, &wm8731_regmap); 694 if (IS_ERR(wm8731->regmap)) { 695 ret = PTR_ERR(wm8731->regmap); 696 dev_err(&spi->dev, "Failed to allocate register map: %d\n", 697 ret); 698 return ret; 699 } 700 | 693 wm8731->regmap = devm_regmap_init_spi(spi, &wm8731_regmap); 694 if (IS_ERR(wm8731->regmap)) { 695 ret = PTR_ERR(wm8731->regmap); 696 dev_err(&spi->dev, "Failed to allocate register map: %d\n", 697 ret); 698 return ret; 699 } 700 |
701 spi_set_drvdata(spi, wm8731); | 701 ret = wm8731_hw_init(&spi->dev, wm8731); 702 if (ret != 0) 703 return ret; |
702 703 ret = snd_soc_register_codec(&spi->dev, 704 &soc_codec_dev_wm8731, &wm8731_dai, 1); 705 if (ret != 0) { 706 dev_err(&spi->dev, "Failed to register CODEC: %d\n", ret); 707 return ret; 708 } 709 --- 39 unchanged lines hidden (view full) --- 749 dev_err(&i2c->dev, "Failed to get MCLK: %d\n", 750 ret); 751 return ret; 752 } 753 } 754 755 mutex_init(&wm8731->lock); 756 | 704 705 ret = snd_soc_register_codec(&spi->dev, 706 &soc_codec_dev_wm8731, &wm8731_dai, 1); 707 if (ret != 0) { 708 dev_err(&spi->dev, "Failed to register CODEC: %d\n", ret); 709 return ret; 710 } 711 --- 39 unchanged lines hidden (view full) --- 751 dev_err(&i2c->dev, "Failed to get MCLK: %d\n", 752 ret); 753 return ret; 754 } 755 } 756 757 mutex_init(&wm8731->lock); 758 |
759 i2c_set_clientdata(i2c, wm8731); 760 761 ret = wm8731_request_supplies(&i2c->dev, wm8731); 762 if (ret != 0) 763 return ret; 764 |
|
757 wm8731->regmap = devm_regmap_init_i2c(i2c, &wm8731_regmap); 758 if (IS_ERR(wm8731->regmap)) { 759 ret = PTR_ERR(wm8731->regmap); 760 dev_err(&i2c->dev, "Failed to allocate register map: %d\n", 761 ret); 762 return ret; 763 } 764 | 765 wm8731->regmap = devm_regmap_init_i2c(i2c, &wm8731_regmap); 766 if (IS_ERR(wm8731->regmap)) { 767 ret = PTR_ERR(wm8731->regmap); 768 dev_err(&i2c->dev, "Failed to allocate register map: %d\n", 769 ret); 770 return ret; 771 } 772 |
765 i2c_set_clientdata(i2c, wm8731); | 773 ret = wm8731_hw_init(&i2c->dev, wm8731); 774 if (ret != 0) 775 return ret; |
766 767 ret = snd_soc_register_codec(&i2c->dev, 768 &soc_codec_dev_wm8731, &wm8731_dai, 1); 769 if (ret != 0) { 770 dev_err(&i2c->dev, "Failed to register CODEC: %d\n", ret); 771 return ret; 772 } 773 --- 62 unchanged lines hidden --- | 776 777 ret = snd_soc_register_codec(&i2c->dev, 778 &soc_codec_dev_wm8731, &wm8731_dai, 1); 779 if (ret != 0) { 780 dev_err(&i2c->dev, "Failed to register CODEC: %d\n", ret); 781 return ret; 782 } 783 --- 62 unchanged lines hidden --- |