wm8731.c (8875d104af6c237bfedb47309afd938984a3c05b) | wm8731.c (9dc15f81baf273b5aaaa3302ee8faacd78f361fd) |
---|---|
1// SPDX-License-Identifier: GPL-2.0-only 2/* 3 * wm8731.c -- WM8731 ALSA SoC Audio driver 4 * 5 * Copyright 2005 Openedhand Ltd. 6 * Copyright 2006-12 Wolfson Microelectronics, plc 7 * 8 * Author: Richard Purdie <richard@openedhand.com> 9 * 10 * Based on wm8753.c by Liam Girdwood 11 */ 12 13#include <linux/module.h> 14#include <linux/moduleparam.h> 15#include <linux/init.h> 16#include <linux/delay.h> 17#include <linux/pm.h> | 1// SPDX-License-Identifier: GPL-2.0-only 2/* 3 * wm8731.c -- WM8731 ALSA SoC Audio driver 4 * 5 * Copyright 2005 Openedhand Ltd. 6 * Copyright 2006-12 Wolfson Microelectronics, plc 7 * 8 * Author: Richard Purdie <richard@openedhand.com> 9 * 10 * Based on wm8753.c by Liam Girdwood 11 */ 12 13#include <linux/module.h> 14#include <linux/moduleparam.h> 15#include <linux/init.h> 16#include <linux/delay.h> 17#include <linux/pm.h> |
18#include <linux/i2c.h> | |
19#include <linux/slab.h> 20#include <linux/regmap.h> 21#include <linux/regulator/consumer.h> | 18#include <linux/slab.h> 19#include <linux/regmap.h> 20#include <linux/regulator/consumer.h> |
22#include <linux/spi/spi.h> 23#include <linux/of_device.h> 24#include <linux/mutex.h> | |
25#include <linux/clk.h> 26#include <sound/core.h> 27#include <sound/pcm.h> 28#include <sound/pcm_params.h> 29#include <sound/soc.h> 30#include <sound/initval.h> 31#include <sound/tlv.h> 32 33#include "wm8731.h" 34 | 21#include <linux/clk.h> 22#include <sound/core.h> 23#include <sound/pcm.h> 24#include <sound/pcm_params.h> 25#include <sound/soc.h> 26#include <sound/initval.h> 27#include <sound/tlv.h> 28 29#include "wm8731.h" 30 |
35#define WM8731_NUM_SUPPLIES 4 | |
36static const char *wm8731_supply_names[WM8731_NUM_SUPPLIES] = { 37 "AVDD", 38 "HPVDD", 39 "DCVDD", 40 "DBVDD", 41}; 42 | 31static const char *wm8731_supply_names[WM8731_NUM_SUPPLIES] = { 32 "AVDD", 33 "HPVDD", 34 "DCVDD", 35 "DBVDD", 36}; 37 |
43/* codec private data */ 44struct wm8731_priv { 45 struct regmap *regmap; 46 struct clk *mclk; 47 struct regulator_bulk_data supplies[WM8731_NUM_SUPPLIES]; 48 const struct snd_pcm_hw_constraint_list *constraints; 49 unsigned int sysclk; 50 int sysclk_type; 51 int playback_fs; 52 bool deemph; 53 54 struct mutex lock; 55}; 56 57 | |
58/* 59 * wm8731 register cache 60 */ 61static const struct reg_default wm8731_reg_defaults[] = { 62 { 0, 0x0097 }, 63 { 1, 0x0097 }, 64 { 2, 0x0079 }, 65 { 3, 0x0079 }, --- 513 unchanged lines hidden (view full) --- 579 .num_dapm_routes = ARRAY_SIZE(wm8731_intercon), 580 .suspend_bias_off = 1, 581 .idle_bias_on = 1, 582 .use_pmdown_time = 1, 583 .endianness = 1, 584 .non_legacy_dai_naming = 1, 585}; 586 | 38/* 39 * wm8731 register cache 40 */ 41static const struct reg_default wm8731_reg_defaults[] = { 42 { 0, 0x0097 }, 43 { 1, 0x0097 }, 44 { 2, 0x0079 }, 45 { 3, 0x0079 }, --- 513 unchanged lines hidden (view full) --- 559 .num_dapm_routes = ARRAY_SIZE(wm8731_intercon), 560 .suspend_bias_off = 1, 561 .idle_bias_on = 1, 562 .use_pmdown_time = 1, 563 .endianness = 1, 564 .non_legacy_dai_naming = 1, 565}; 566 |
587static int wm8731_init(struct device *dev, struct wm8731_priv *wm8731) | 567int wm8731_init(struct device *dev, struct wm8731_priv *wm8731) |
588{ 589 int ret = 0, i; 590 591 wm8731->mclk = devm_clk_get(dev, "mclk"); 592 if (IS_ERR(wm8731->mclk)) { 593 ret = PTR_ERR(wm8731->mclk); 594 if (ret == -ENOENT) { 595 wm8731->mclk = NULL; --- 53 unchanged lines hidden (view full) --- 649 return 0; 650 651err_regulator_enable: 652 /* Regulators will be enabled by bias management */ 653 regulator_bulk_disable(ARRAY_SIZE(wm8731->supplies), wm8731->supplies); 654 655 return ret; 656} | 568{ 569 int ret = 0, i; 570 571 wm8731->mclk = devm_clk_get(dev, "mclk"); 572 if (IS_ERR(wm8731->mclk)) { 573 ret = PTR_ERR(wm8731->mclk); 574 if (ret == -ENOENT) { 575 wm8731->mclk = NULL; --- 53 unchanged lines hidden (view full) --- 629 return 0; 630 631err_regulator_enable: 632 /* Regulators will be enabled by bias management */ 633 regulator_bulk_disable(ARRAY_SIZE(wm8731->supplies), wm8731->supplies); 634 635 return ret; 636} |
637EXPORT_SYMBOL_GPL(wm8731_init); |
|
657 | 638 |
658static const struct of_device_id wm8731_of_match[] = { 659 { .compatible = "wlf,wm8731", }, 660 { } 661}; 662 663MODULE_DEVICE_TABLE(of, wm8731_of_match); 664 665static const struct regmap_config wm8731_regmap = { | 639const struct regmap_config wm8731_regmap = { |
666 .reg_bits = 7, 667 .val_bits = 9, 668 669 .max_register = WM8731_RESET, 670 .volatile_reg = wm8731_volatile, 671 672 .cache_type = REGCACHE_RBTREE, 673 .reg_defaults = wm8731_reg_defaults, 674 .num_reg_defaults = ARRAY_SIZE(wm8731_reg_defaults), 675}; | 640 .reg_bits = 7, 641 .val_bits = 9, 642 643 .max_register = WM8731_RESET, 644 .volatile_reg = wm8731_volatile, 645 646 .cache_type = REGCACHE_RBTREE, 647 .reg_defaults = wm8731_reg_defaults, 648 .num_reg_defaults = ARRAY_SIZE(wm8731_reg_defaults), 649}; |
650EXPORT_SYMBOL_GPL(wm8731_regmap); |
|
676 | 651 |
677#if defined(CONFIG_SPI_MASTER) 678static int wm8731_spi_probe(struct spi_device *spi) 679{ 680 struct wm8731_priv *wm8731; 681 int ret; 682 683 wm8731 = devm_kzalloc(&spi->dev, sizeof(*wm8731), GFP_KERNEL); 684 if (wm8731 == NULL) 685 return -ENOMEM; 686 687 spi_set_drvdata(spi, wm8731); 688 689 wm8731->regmap = devm_regmap_init_spi(spi, &wm8731_regmap); 690 if (IS_ERR(wm8731->regmap)) { 691 ret = PTR_ERR(wm8731->regmap); 692 dev_err(&spi->dev, "Failed to allocate register map: %d\n", 693 ret); 694 return ret; 695 } 696 697 return wm8731_init(&spi->dev, wm8731); 698} 699 700static struct spi_driver wm8731_spi_driver = { 701 .driver = { 702 .name = "wm8731", 703 .of_match_table = wm8731_of_match, 704 }, 705 .probe = wm8731_spi_probe, 706}; 707#endif /* CONFIG_SPI_MASTER */ 708 709#if IS_ENABLED(CONFIG_I2C) 710static int wm8731_i2c_probe(struct i2c_client *i2c, 711 const struct i2c_device_id *id) 712{ 713 struct wm8731_priv *wm8731; 714 int ret; 715 716 wm8731 = devm_kzalloc(&i2c->dev, sizeof(struct wm8731_priv), 717 GFP_KERNEL); 718 if (wm8731 == NULL) 719 return -ENOMEM; 720 721 i2c_set_clientdata(i2c, wm8731); 722 723 wm8731->regmap = devm_regmap_init_i2c(i2c, &wm8731_regmap); 724 if (IS_ERR(wm8731->regmap)) { 725 ret = PTR_ERR(wm8731->regmap); 726 dev_err(&i2c->dev, "Failed to allocate register map: %d\n", 727 ret); 728 return ret; 729 } 730 731 return wm8731_init(&i2c->dev, wm8731); 732} 733 734static const struct i2c_device_id wm8731_i2c_id[] = { 735 { "wm8731", 0 }, 736 { } 737}; 738MODULE_DEVICE_TABLE(i2c, wm8731_i2c_id); 739 740static struct i2c_driver wm8731_i2c_driver = { 741 .driver = { 742 .name = "wm8731", 743 .of_match_table = wm8731_of_match, 744 }, 745 .probe = wm8731_i2c_probe, 746 .id_table = wm8731_i2c_id, 747}; 748#endif 749 750static int __init wm8731_modinit(void) 751{ 752 int ret = 0; 753#if IS_ENABLED(CONFIG_I2C) 754 ret = i2c_add_driver(&wm8731_i2c_driver); 755 if (ret != 0) { 756 printk(KERN_ERR "Failed to register WM8731 I2C driver: %d\n", 757 ret); 758 } 759#endif 760#if defined(CONFIG_SPI_MASTER) 761 ret = spi_register_driver(&wm8731_spi_driver); 762 if (ret != 0) { 763 printk(KERN_ERR "Failed to register WM8731 SPI driver: %d\n", 764 ret); 765 } 766#endif 767 return ret; 768} 769module_init(wm8731_modinit); 770 771static void __exit wm8731_exit(void) 772{ 773#if IS_ENABLED(CONFIG_I2C) 774 i2c_del_driver(&wm8731_i2c_driver); 775#endif 776#if defined(CONFIG_SPI_MASTER) 777 spi_unregister_driver(&wm8731_spi_driver); 778#endif 779} 780module_exit(wm8731_exit); 781 | |
782MODULE_DESCRIPTION("ASoC WM8731 driver"); 783MODULE_AUTHOR("Richard Purdie"); 784MODULE_LICENSE("GPL"); | 652MODULE_DESCRIPTION("ASoC WM8731 driver"); 653MODULE_AUTHOR("Richard Purdie"); 654MODULE_LICENSE("GPL"); |