hifier.c 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  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_SMUTE | 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, 0);
  65. ak4396_write(chip, AK4396_RCH_ATT, 0);
  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, "Stereo Upmixing"))
  112. return 1; /* stereo only - we don't need upmixing */
  113. return 0;
  114. }
  115. static const struct oxygen_model model_hifier = {
  116. .shortname = "C-Media CMI8787",
  117. .longname = "C-Media Oxygen HD Audio",
  118. .chip = "CMI8788",
  119. .owner = THIS_MODULE,
  120. .init = hifier_init,
  121. .control_filter = hifier_control_filter,
  122. .cleanup = hifier_cleanup,
  123. .set_dac_params = set_ak4396_params,
  124. .set_adc_params = set_cs5340_params,
  125. .update_dac_volume = update_ak4396_volume,
  126. .update_dac_mute = update_ak4396_mute,
  127. .dac_tlv = ak4396_db_scale,
  128. .model_data_size = sizeof(struct hifier_data),
  129. .pcm_dev_cfg = PLAYBACK_0_TO_I2S |
  130. PLAYBACK_1_TO_SPDIF |
  131. CAPTURE_0_FROM_I2S_1,
  132. .dac_channels = 2,
  133. .dac_volume_min = 0,
  134. .dac_volume_max = 255,
  135. .function_flags = OXYGEN_FUNCTION_SPI,
  136. .dac_i2s_format = OXYGEN_I2S_FORMAT_LJUST,
  137. .adc_i2s_format = OXYGEN_I2S_FORMAT_LJUST,
  138. };
  139. static int __devinit hifier_probe(struct pci_dev *pci,
  140. const struct pci_device_id *pci_id)
  141. {
  142. static int dev;
  143. int err;
  144. if (dev >= SNDRV_CARDS)
  145. return -ENODEV;
  146. if (!enable[dev]) {
  147. ++dev;
  148. return -ENOENT;
  149. }
  150. err = oxygen_pci_probe(pci, index[dev], id[dev], &model_hifier);
  151. if (err >= 0)
  152. ++dev;
  153. return err;
  154. }
  155. static struct pci_driver hifier_driver = {
  156. .name = "CMI8787HiFier",
  157. .id_table = hifier_ids,
  158. .probe = hifier_probe,
  159. .remove = __devexit_p(oxygen_pci_remove),
  160. };
  161. static int __init alsa_card_hifier_init(void)
  162. {
  163. return pci_register_driver(&hifier_driver);
  164. }
  165. static void __exit alsa_card_hifier_exit(void)
  166. {
  167. pci_unregister_driver(&hifier_driver);
  168. }
  169. module_init(alsa_card_hifier_init)
  170. module_exit(alsa_card_hifier_exit)