hifier.c 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. /*
  2. * C-Media CMI8788 driver for the MediaTek/TempoTec HiFier Fantasia
  3. *
  4. * Copyright (c) Clemens Ladisch <clemens@ladisch.de>
  5. *
  6. *
  7. * This driver is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License, version 2.
  9. *
  10. * This driver is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this driver; if not, write to the Free Software
  17. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  18. */
  19. #include <linux/pci.h>
  20. #include <sound/control.h>
  21. #include <sound/core.h>
  22. #include <sound/initval.h>
  23. #include <sound/pcm.h>
  24. #include <sound/tlv.h>
  25. #include "oxygen.h"
  26. #include "ak4396.h"
  27. MODULE_AUTHOR("Clemens Ladisch <clemens@ladisch.de>");
  28. MODULE_DESCRIPTION("TempoTec HiFier driver");
  29. MODULE_LICENSE("GPL");
  30. static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX;
  31. static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR;
  32. static int enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP;
  33. module_param_array(index, int, NULL, 0444);
  34. MODULE_PARM_DESC(index, "card index");
  35. module_param_array(id, charp, NULL, 0444);
  36. MODULE_PARM_DESC(id, "ID string");
  37. module_param_array(enable, bool, NULL, 0444);
  38. MODULE_PARM_DESC(enable, "enable card");
  39. static struct pci_device_id hifier_ids[] __devinitdata = {
  40. { OXYGEN_PCI_SUBID(0x14c3, 0x1710) },
  41. { OXYGEN_PCI_SUBID(0x14c3, 0x1711) },
  42. { }
  43. };
  44. MODULE_DEVICE_TABLE(pci, hifier_ids);
  45. struct hifier_data {
  46. u8 ak4396_ctl2;
  47. };
  48. static void ak4396_write(struct oxygen *chip, u8 reg, u8 value)
  49. {
  50. oxygen_write_spi(chip, OXYGEN_SPI_TRIGGER |
  51. OXYGEN_SPI_DATA_LENGTH_2 |
  52. OXYGEN_SPI_CLOCK_160 |
  53. (0 << OXYGEN_SPI_CODEC_SHIFT) |
  54. OXYGEN_SPI_CEN_LATCH_CLOCK_HI,
  55. AK4396_WRITE | (reg << 8) | value);
  56. }
  57. static void hifier_init(struct oxygen *chip)
  58. {
  59. struct hifier_data *data = chip->model_data;
  60. data->ak4396_ctl2 = AK4396_DEM_OFF | AK4396_DFS_NORMAL;
  61. ak4396_write(chip, AK4396_CONTROL_1, AK4396_DIF_24_MSB | AK4396_RSTN);
  62. ak4396_write(chip, AK4396_CONTROL_2, data->ak4396_ctl2);
  63. ak4396_write(chip, AK4396_CONTROL_3, AK4396_PCM);
  64. ak4396_write(chip, AK4396_LCH_ATT, 0xff);
  65. ak4396_write(chip, AK4396_RCH_ATT, 0xff);
  66. snd_component_add(chip->card, "AK4396");
  67. snd_component_add(chip->card, "CS5340");
  68. }
  69. static void hifier_cleanup(struct oxygen *chip)
  70. {
  71. }
  72. static void set_ak4396_params(struct oxygen *chip,
  73. struct snd_pcm_hw_params *params)
  74. {
  75. struct hifier_data *data = chip->model_data;
  76. u8 value;
  77. value = data->ak4396_ctl2 & ~AK4396_DFS_MASK;
  78. if (params_rate(params) <= 54000)
  79. value |= AK4396_DFS_NORMAL;
  80. else if (params_rate(params) <= 108000)
  81. value |= AK4396_DFS_DOUBLE;
  82. else
  83. value |= AK4396_DFS_QUAD;
  84. data->ak4396_ctl2 = value;
  85. ak4396_write(chip, AK4396_CONTROL_1, AK4396_DIF_24_MSB);
  86. ak4396_write(chip, AK4396_CONTROL_2, value);
  87. ak4396_write(chip, AK4396_CONTROL_1, AK4396_DIF_24_MSB | AK4396_RSTN);
  88. }
  89. static void update_ak4396_volume(struct oxygen *chip)
  90. {
  91. ak4396_write(chip, AK4396_LCH_ATT, chip->dac_volume[0]);
  92. ak4396_write(chip, AK4396_RCH_ATT, chip->dac_volume[1]);
  93. }
  94. static void update_ak4396_mute(struct oxygen *chip)
  95. {
  96. struct hifier_data *data = chip->model_data;
  97. u8 value;
  98. value = data->ak4396_ctl2 & ~AK4396_SMUTE;
  99. if (chip->dac_mute)
  100. value |= AK4396_SMUTE;
  101. data->ak4396_ctl2 = value;
  102. ak4396_write(chip, AK4396_CONTROL_2, value);
  103. }
  104. static void set_cs5340_params(struct oxygen *chip,
  105. struct snd_pcm_hw_params *params)
  106. {
  107. }
  108. static const DECLARE_TLV_DB_LINEAR(ak4396_db_scale, TLV_DB_GAIN_MUTE, 0);
  109. static int hifier_control_filter(struct snd_kcontrol_new *template)
  110. {
  111. if (!strcmp(template->name, "Master Playback Volume")) {
  112. template->access |= SNDRV_CTL_ELEM_ACCESS_TLV_READ;
  113. template->tlv.p = ak4396_db_scale;
  114. } else if (!strcmp(template->name, "Stereo Upmixing")) {
  115. return 1; /* stereo only - we don't need upmixing */
  116. } else if (!strcmp(template->name,
  117. SNDRV_CTL_NAME_IEC958("", CAPTURE, MASK)) ||
  118. !strcmp(template->name,
  119. SNDRV_CTL_NAME_IEC958("", CAPTURE, DEFAULT))) {
  120. return 1; /* no digital input */
  121. }
  122. return 0;
  123. }
  124. static int hifier_mixer_init(struct oxygen *chip)
  125. {
  126. return 0;
  127. }
  128. static const struct oxygen_model model_hifier = {
  129. .shortname = "C-Media CMI8787",
  130. .longname = "C-Media Oxygen HD Audio",
  131. .chip = "CMI8788",
  132. .owner = THIS_MODULE,
  133. .init = hifier_init,
  134. .control_filter = hifier_control_filter,
  135. .mixer_init = hifier_mixer_init,
  136. .cleanup = hifier_cleanup,
  137. .set_dac_params = set_ak4396_params,
  138. .set_adc_params = set_cs5340_params,
  139. .update_dac_volume = update_ak4396_volume,
  140. .update_dac_mute = update_ak4396_mute,
  141. .model_data_size = sizeof(struct hifier_data),
  142. .dac_channels = 2,
  143. .used_channels = OXYGEN_CHANNEL_A |
  144. OXYGEN_CHANNEL_SPDIF |
  145. OXYGEN_CHANNEL_MULTICH,
  146. .function_flags = 0,
  147. .dac_i2s_format = OXYGEN_I2S_FORMAT_LJUST,
  148. .adc_i2s_format = OXYGEN_I2S_FORMAT_LJUST,
  149. };
  150. static int __devinit hifier_probe(struct pci_dev *pci,
  151. const struct pci_device_id *pci_id)
  152. {
  153. static int dev;
  154. int err;
  155. if (dev >= SNDRV_CARDS)
  156. return -ENODEV;
  157. if (!enable[dev]) {
  158. ++dev;
  159. return -ENOENT;
  160. }
  161. err = oxygen_pci_probe(pci, index[dev], id[dev], 0, &model_hifier);
  162. if (err >= 0)
  163. ++dev;
  164. return err;
  165. }
  166. static struct pci_driver hifier_driver = {
  167. .name = "CMI8787HiFier",
  168. .id_table = hifier_ids,
  169. .probe = hifier_probe,
  170. .remove = __devexit_p(oxygen_pci_remove),
  171. };
  172. static int __init alsa_card_hifier_init(void)
  173. {
  174. return pci_register_driver(&hifier_driver);
  175. }
  176. static void __exit alsa_card_hifier_exit(void)
  177. {
  178. pci_unregister_driver(&hifier_driver);
  179. }
  180. module_init(alsa_card_hifier_init)
  181. module_exit(alsa_card_hifier_exit)