ac100.c 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. /*
  2. * MFD core driver for X-Powers' AC100 Audio Codec IC
  3. *
  4. * The AC100 is a highly integrated audio codec and RTC subsystem designed
  5. * for mobile applications. It has 3 I2S/PCM interfaces, a 2 channel DAC,
  6. * a 2 channel ADC with 5 inputs and a builtin mixer. The RTC subsystem has
  7. * 3 clock outputs.
  8. *
  9. * The audio codec and RTC parts are completely separate, sharing only the
  10. * host interface for access to its registers.
  11. *
  12. * Copyright (2016) Chen-Yu Tsai
  13. *
  14. * Author: Chen-Yu Tsai <wens@csie.org>
  15. *
  16. * This program is free software; you can redistribute it and/or modify
  17. * it under the terms of the GNU General Public License version 2 as
  18. * published by the Free Software Foundation.
  19. */
  20. #include <linux/interrupt.h>
  21. #include <linux/kernel.h>
  22. #include <linux/mfd/core.h>
  23. #include <linux/mfd/ac100.h>
  24. #include <linux/module.h>
  25. #include <linux/of.h>
  26. #include <linux/regmap.h>
  27. #include <linux/sunxi-rsb.h>
  28. static const struct regmap_range ac100_writeable_ranges[] = {
  29. regmap_reg_range(AC100_CHIP_AUDIO_RST, AC100_I2S_SR_CTRL),
  30. regmap_reg_range(AC100_I2S1_CLK_CTRL, AC100_I2S1_MXR_GAIN),
  31. regmap_reg_range(AC100_I2S2_CLK_CTRL, AC100_I2S2_MXR_GAIN),
  32. regmap_reg_range(AC100_I2S3_CLK_CTRL, AC100_I2S3_SIG_PATH_CTRL),
  33. regmap_reg_range(AC100_ADC_DIG_CTRL, AC100_ADC_VOL_CTRL),
  34. regmap_reg_range(AC100_HMIC_CTRL1, AC100_HMIC_STATUS),
  35. regmap_reg_range(AC100_DAC_DIG_CTRL, AC100_DAC_MXR_GAIN),
  36. regmap_reg_range(AC100_ADC_APC_CTRL, AC100_LINEOUT_CTRL),
  37. regmap_reg_range(AC100_ADC_DAP_L_CTRL, AC100_ADC_DAP_OPT),
  38. regmap_reg_range(AC100_DAC_DAP_CTRL, AC100_DAC_DAP_OPT),
  39. regmap_reg_range(AC100_ADC_DAP_ENA, AC100_DAC_DAP_ENA),
  40. regmap_reg_range(AC100_SRC1_CTRL1, AC100_SRC1_CTRL2),
  41. regmap_reg_range(AC100_SRC2_CTRL1, AC100_SRC2_CTRL2),
  42. regmap_reg_range(AC100_CLK32K_ANALOG_CTRL, AC100_CLKOUT_CTRL3),
  43. regmap_reg_range(AC100_RTC_RST, AC100_RTC_UPD),
  44. regmap_reg_range(AC100_ALM_INT_ENA, AC100_ALM_INT_STA),
  45. regmap_reg_range(AC100_ALM_SEC, AC100_RTC_GP(15)),
  46. };
  47. static const struct regmap_range ac100_volatile_ranges[] = {
  48. regmap_reg_range(AC100_CHIP_AUDIO_RST, AC100_PLL_CTRL2),
  49. regmap_reg_range(AC100_HMIC_STATUS, AC100_HMIC_STATUS),
  50. regmap_reg_range(AC100_ADC_DAP_L_STA, AC100_ADC_DAP_L_STA),
  51. regmap_reg_range(AC100_SRC1_CTRL1, AC100_SRC1_CTRL1),
  52. regmap_reg_range(AC100_SRC1_CTRL3, AC100_SRC2_CTRL1),
  53. regmap_reg_range(AC100_SRC2_CTRL3, AC100_SRC2_CTRL4),
  54. regmap_reg_range(AC100_RTC_RST, AC100_RTC_RST),
  55. regmap_reg_range(AC100_RTC_SEC, AC100_ALM_INT_STA),
  56. regmap_reg_range(AC100_ALM_SEC, AC100_ALM_UPD),
  57. };
  58. static const struct regmap_access_table ac100_writeable_table = {
  59. .yes_ranges = ac100_writeable_ranges,
  60. .n_yes_ranges = ARRAY_SIZE(ac100_writeable_ranges),
  61. };
  62. static const struct regmap_access_table ac100_volatile_table = {
  63. .yes_ranges = ac100_volatile_ranges,
  64. .n_yes_ranges = ARRAY_SIZE(ac100_volatile_ranges),
  65. };
  66. static const struct regmap_config ac100_regmap_config = {
  67. .reg_bits = 8,
  68. .val_bits = 16,
  69. .wr_table = &ac100_writeable_table,
  70. .volatile_table = &ac100_volatile_table,
  71. .max_register = AC100_RTC_GP(15),
  72. .cache_type = REGCACHE_RBTREE,
  73. };
  74. static struct mfd_cell ac100_cells[] = {
  75. {
  76. .name = "ac100-codec",
  77. .of_compatible = "x-powers,ac100-codec",
  78. }, {
  79. .name = "ac100-rtc",
  80. .of_compatible = "x-powers,ac100-rtc",
  81. },
  82. };
  83. static int ac100_rsb_probe(struct sunxi_rsb_device *rdev)
  84. {
  85. struct ac100_dev *ac100;
  86. int ret;
  87. ac100 = devm_kzalloc(&rdev->dev, sizeof(*ac100), GFP_KERNEL);
  88. if (!ac100)
  89. return -ENOMEM;
  90. ac100->dev = &rdev->dev;
  91. sunxi_rsb_device_set_drvdata(rdev, ac100);
  92. ac100->regmap = devm_regmap_init_sunxi_rsb(rdev, &ac100_regmap_config);
  93. if (IS_ERR(ac100->regmap)) {
  94. ret = PTR_ERR(ac100->regmap);
  95. dev_err(ac100->dev, "regmap init failed: %d\n", ret);
  96. return ret;
  97. }
  98. ret = devm_mfd_add_devices(ac100->dev, PLATFORM_DEVID_NONE, ac100_cells,
  99. ARRAY_SIZE(ac100_cells), NULL, 0, NULL);
  100. if (ret) {
  101. dev_err(ac100->dev, "failed to add MFD devices: %d\n", ret);
  102. return ret;
  103. }
  104. return 0;
  105. }
  106. static const struct of_device_id ac100_of_match[] = {
  107. { .compatible = "x-powers,ac100" },
  108. { },
  109. };
  110. MODULE_DEVICE_TABLE(of, ac100_of_match);
  111. static struct sunxi_rsb_driver ac100_rsb_driver = {
  112. .driver = {
  113. .name = "ac100",
  114. .of_match_table = of_match_ptr(ac100_of_match),
  115. },
  116. .probe = ac100_rsb_probe,
  117. };
  118. module_sunxi_rsb_driver(ac100_rsb_driver);
  119. MODULE_DESCRIPTION("Audio codec MFD core driver for AC100");
  120. MODULE_AUTHOR("Chen-Yu Tsai <wens@csie.org>");
  121. MODULE_LICENSE("GPL v2");