max9877.c 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. /*
  2. * max9877.c -- amp driver for max9877
  3. *
  4. * Copyright (C) 2009 Samsung Electronics Co.Ltd
  5. * Author: Joonyoung Shim <jy0922.shim@samsung.com>
  6. *
  7. * This program is free software; you can redistribute it and/or modify it
  8. * under the terms of the GNU General Public License as published by the
  9. * Free Software Foundation; either version 2 of the License, or (at your
  10. * option) any later version.
  11. *
  12. */
  13. #include <linux/module.h>
  14. #include <linux/init.h>
  15. #include <linux/i2c.h>
  16. #include <linux/regmap.h>
  17. #include <sound/soc.h>
  18. #include <sound/tlv.h>
  19. #include "max9877.h"
  20. static const struct reg_default max9877_regs[] = {
  21. { 0, 0x40 },
  22. { 1, 0x00 },
  23. { 2, 0x00 },
  24. { 3, 0x00 },
  25. { 4, 0x49 },
  26. };
  27. static const DECLARE_TLV_DB_RANGE(max9877_pgain_tlv,
  28. 0, 1, TLV_DB_SCALE_ITEM(0, 900, 0),
  29. 2, 2, TLV_DB_SCALE_ITEM(2000, 0, 0)
  30. );
  31. static const DECLARE_TLV_DB_RANGE(max9877_output_tlv,
  32. 0, 7, TLV_DB_SCALE_ITEM(-7900, 400, 1),
  33. 8, 15, TLV_DB_SCALE_ITEM(-4700, 300, 0),
  34. 16, 23, TLV_DB_SCALE_ITEM(-2300, 200, 0),
  35. 24, 31, TLV_DB_SCALE_ITEM(-700, 100, 0)
  36. );
  37. static const char *max9877_out_mode[] = {
  38. "INA -> SPK",
  39. "INA -> HP",
  40. "INA -> SPK and HP",
  41. "INB -> SPK",
  42. "INB -> HP",
  43. "INB -> SPK and HP",
  44. "INA + INB -> SPK",
  45. "INA + INB -> HP",
  46. "INA + INB -> SPK and HP",
  47. };
  48. static const char *max9877_osc_mode[] = {
  49. "1176KHz",
  50. "1100KHz",
  51. "700KHz",
  52. };
  53. static const struct soc_enum max9877_enum[] = {
  54. SOC_ENUM_SINGLE(MAX9877_OUTPUT_MODE, 0, ARRAY_SIZE(max9877_out_mode),
  55. max9877_out_mode),
  56. SOC_ENUM_SINGLE(MAX9877_OUTPUT_MODE, MAX9877_OSC_OFFSET,
  57. ARRAY_SIZE(max9877_osc_mode), max9877_osc_mode),
  58. };
  59. static const struct snd_kcontrol_new max9877_controls[] = {
  60. SOC_SINGLE_TLV("MAX9877 PGAINA Playback Volume",
  61. MAX9877_INPUT_MODE, 0, 2, 0, max9877_pgain_tlv),
  62. SOC_SINGLE_TLV("MAX9877 PGAINB Playback Volume",
  63. MAX9877_INPUT_MODE, 2, 2, 0, max9877_pgain_tlv),
  64. SOC_SINGLE_TLV("MAX9877 Amp Speaker Playback Volume",
  65. MAX9877_SPK_VOLUME, 0, 31, 0, max9877_output_tlv),
  66. SOC_DOUBLE_R_TLV("MAX9877 Amp HP Playback Volume",
  67. MAX9877_HPL_VOLUME, MAX9877_HPR_VOLUME, 0, 31, 0,
  68. max9877_output_tlv),
  69. SOC_SINGLE("MAX9877 INB Stereo Switch",
  70. MAX9877_INPUT_MODE, 4, 1, 1),
  71. SOC_SINGLE("MAX9877 INA Stereo Switch",
  72. MAX9877_INPUT_MODE, 5, 1, 1),
  73. SOC_SINGLE("MAX9877 Zero-crossing detection Switch",
  74. MAX9877_INPUT_MODE, 6, 1, 0),
  75. SOC_SINGLE("MAX9877 Bypass Mode Switch",
  76. MAX9877_OUTPUT_MODE, 6, 1, 0),
  77. SOC_ENUM("MAX9877 Output Mode", max9877_enum[0]),
  78. SOC_ENUM("MAX9877 Oscillator Mode", max9877_enum[1]),
  79. };
  80. static const struct snd_soc_dapm_widget max9877_dapm_widgets[] = {
  81. SND_SOC_DAPM_INPUT("INA1"),
  82. SND_SOC_DAPM_INPUT("INA2"),
  83. SND_SOC_DAPM_INPUT("INB1"),
  84. SND_SOC_DAPM_INPUT("INB2"),
  85. SND_SOC_DAPM_INPUT("RXIN+"),
  86. SND_SOC_DAPM_INPUT("RXIN-"),
  87. SND_SOC_DAPM_PGA("SHDN", MAX9877_OUTPUT_MODE, 7, 1, NULL, 0),
  88. SND_SOC_DAPM_OUTPUT("OUT+"),
  89. SND_SOC_DAPM_OUTPUT("OUT-"),
  90. SND_SOC_DAPM_OUTPUT("HPL"),
  91. SND_SOC_DAPM_OUTPUT("HPR"),
  92. };
  93. static const struct snd_soc_dapm_route max9877_dapm_routes[] = {
  94. { "SHDN", NULL, "INA1" },
  95. { "SHDN", NULL, "INA2" },
  96. { "SHDN", NULL, "INB1" },
  97. { "SHDN", NULL, "INB2" },
  98. { "OUT+", NULL, "RXIN+" },
  99. { "OUT+", NULL, "SHDN" },
  100. { "OUT-", NULL, "SHDN" },
  101. { "OUT-", NULL, "RXIN-" },
  102. { "HPL", NULL, "SHDN" },
  103. { "HPR", NULL, "SHDN" },
  104. };
  105. static const struct snd_soc_component_driver max9877_component_driver = {
  106. .controls = max9877_controls,
  107. .num_controls = ARRAY_SIZE(max9877_controls),
  108. .dapm_widgets = max9877_dapm_widgets,
  109. .num_dapm_widgets = ARRAY_SIZE(max9877_dapm_widgets),
  110. .dapm_routes = max9877_dapm_routes,
  111. .num_dapm_routes = ARRAY_SIZE(max9877_dapm_routes),
  112. };
  113. static const struct regmap_config max9877_regmap = {
  114. .reg_bits = 8,
  115. .val_bits = 8,
  116. .reg_defaults = max9877_regs,
  117. .num_reg_defaults = ARRAY_SIZE(max9877_regs),
  118. .cache_type = REGCACHE_RBTREE,
  119. };
  120. static int max9877_i2c_probe(struct i2c_client *client,
  121. const struct i2c_device_id *id)
  122. {
  123. struct regmap *regmap;
  124. int i;
  125. regmap = devm_regmap_init_i2c(client, &max9877_regmap);
  126. if (IS_ERR(regmap))
  127. return PTR_ERR(regmap);
  128. /* Ensure the device is in reset state */
  129. for (i = 0; i < ARRAY_SIZE(max9877_regs); i++)
  130. regmap_write(regmap, max9877_regs[i].reg, max9877_regs[i].def);
  131. return devm_snd_soc_register_component(&client->dev,
  132. &max9877_component_driver, NULL, 0);
  133. }
  134. static const struct i2c_device_id max9877_i2c_id[] = {
  135. { "max9877", 0 },
  136. { }
  137. };
  138. MODULE_DEVICE_TABLE(i2c, max9877_i2c_id);
  139. static struct i2c_driver max9877_i2c_driver = {
  140. .driver = {
  141. .name = "max9877",
  142. },
  143. .probe = max9877_i2c_probe,
  144. .id_table = max9877_i2c_id,
  145. };
  146. module_i2c_driver(max9877_i2c_driver);
  147. MODULE_DESCRIPTION("ASoC MAX9877 amp driver");
  148. MODULE_AUTHOR("Joonyoung Shim <jy0922.shim@samsung.com>");
  149. MODULE_LICENSE("GPL");