hifier.c 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  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 v2");
  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 update_ak4396_volume(struct oxygen *chip)
  58. {
  59. ak4396_write(chip, AK4396_LCH_ATT, chip->dac_volume[0]);
  60. ak4396_write(chip, AK4396_RCH_ATT, chip->dac_volume[1]);
  61. }
  62. static void hifier_init(struct oxygen *chip)
  63. {
  64. struct hifier_data *data = chip->model_data;
  65. data->ak4396_ctl2 = AK4396_SMUTE | AK4396_DEM_OFF | AK4396_DFS_NORMAL;
  66. ak4396_write(chip, AK4396_CONTROL_1, AK4396_DIF_24_MSB | AK4396_RSTN);
  67. ak4396_write(chip, AK4396_CONTROL_2, data->ak4396_ctl2);
  68. ak4396_write(chip, AK4396_CONTROL_3, AK4396_PCM);
  69. update_ak4396_volume(chip);
  70. snd_component_add(chip->card, "AK4396");
  71. snd_component_add(chip->card, "CS5340");
  72. }
  73. static void hifier_cleanup(struct oxygen *chip)
  74. {
  75. }
  76. static void set_ak4396_params(struct oxygen *chip,
  77. struct snd_pcm_hw_params *params)
  78. {
  79. struct hifier_data *data = chip->model_data;
  80. u8 value;
  81. value = data->ak4396_ctl2 & ~AK4396_DFS_MASK;
  82. if (params_rate(params) <= 54000)
  83. value |= AK4396_DFS_NORMAL;
  84. else if (params_rate(params) <= 108000)
  85. value |= AK4396_DFS_DOUBLE;
  86. else
  87. value |= AK4396_DFS_QUAD;
  88. data->ak4396_ctl2 = value;
  89. ak4396_write(chip, AK4396_CONTROL_1, AK4396_DIF_24_MSB);
  90. ak4396_write(chip, AK4396_CONTROL_2, value);
  91. ak4396_write(chip, AK4396_CONTROL_1, AK4396_DIF_24_MSB | AK4396_RSTN);
  92. }
  93. static void update_ak4396_mute(struct oxygen *chip)
  94. {
  95. struct hifier_data *data = chip->model_data;
  96. u8 value;
  97. value = data->ak4396_ctl2 & ~AK4396_SMUTE;
  98. if (chip->dac_mute)
  99. value |= AK4396_SMUTE;
  100. data->ak4396_ctl2 = value;
  101. ak4396_write(chip, AK4396_CONTROL_2, value);
  102. }
  103. static void set_cs5340_params(struct oxygen *chip,
  104. struct snd_pcm_hw_params *params)
  105. {
  106. }
  107. static const DECLARE_TLV_DB_LINEAR(ak4396_db_scale, TLV_DB_GAIN_MUTE, 0);
  108. static int hifier_control_filter(struct snd_kcontrol_new *template)
  109. {
  110. if (!strcmp(template->name, "Stereo Upmixing"))
  111. return 1; /* stereo only - we don't need upmixing */
  112. return 0;
  113. }
  114. static const struct oxygen_model model_hifier = {
  115. .shortname = "C-Media CMI8787",
  116. .longname = "C-Media Oxygen HD Audio",
  117. .chip = "CMI8788",
  118. .owner = THIS_MODULE,
  119. .init = hifier_init,
  120. .control_filter = hifier_control_filter,
  121. .cleanup = hifier_cleanup,
  122. .set_dac_params = set_ak4396_params,
  123. .set_adc_params = set_cs5340_params,
  124. .update_dac_volume = update_ak4396_volume,
  125. .update_dac_mute = update_ak4396_mute,
  126. .dac_tlv = ak4396_db_scale,
  127. .model_data_size = sizeof(struct hifier_data),
  128. .pcm_dev_cfg = PLAYBACK_0_TO_I2S |
  129. PLAYBACK_1_TO_SPDIF |
  130. CAPTURE_0_FROM_I2S_1,
  131. .dac_channels = 2,
  132. .dac_volume_min = 0,
  133. .dac_volume_max = 255,
  134. .function_flags = OXYGEN_FUNCTION_SPI,
  135. .dac_i2s_format = OXYGEN_I2S_FORMAT_LJUST,
  136. .adc_i2s_format = OXYGEN_I2S_FORMAT_LJUST,
  137. };
  138. static int __devinit hifier_probe(struct pci_dev *pci,
  139. const struct pci_device_id *pci_id)
  140. {
  141. static int dev;
  142. int err;
  143. if (dev >= SNDRV_CARDS)
  144. return -ENODEV;
  145. if (!enable[dev]) {
  146. ++dev;
  147. return -ENOENT;
  148. }
  149. err = oxygen_pci_probe(pci, index[dev], id[dev], &model_hifier);
  150. if (err >= 0)
  151. ++dev;
  152. return err;
  153. }
  154. static struct pci_driver hifier_driver = {
  155. .name = "CMI8787HiFier",
  156. .id_table = hifier_ids,
  157. .probe = hifier_probe,
  158. .remove = __devexit_p(oxygen_pci_remove),
  159. };
  160. static int __init alsa_card_hifier_init(void)
  161. {
  162. return pci_register_driver(&hifier_driver);
  163. }
  164. static void __exit alsa_card_hifier_exit(void)
  165. {
  166. pci_unregister_driver(&hifier_driver);
  167. }
  168. module_init(alsa_card_hifier_init)
  169. module_exit(alsa_card_hifier_exit)