linux/sound/pci/oxygen/hifier.c
<<
>>
Prefs
   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
  20#include <linux/delay.h>
  21#include <linux/pci.h>
  22#include <sound/control.h>
  23#include <sound/core.h>
  24#include <sound/initval.h>
  25#include <sound/pcm.h>
  26#include <sound/tlv.h>
  27#include "oxygen.h"
  28#include "ak4396.h"
  29
  30MODULE_AUTHOR("Clemens Ladisch <clemens@ladisch.de>");
  31MODULE_DESCRIPTION("TempoTec HiFier driver");
  32MODULE_LICENSE("GPL v2");
  33
  34static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX;
  35static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR;
  36static int enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP;
  37
  38module_param_array(index, int, NULL, 0444);
  39MODULE_PARM_DESC(index, "card index");
  40module_param_array(id, charp, NULL, 0444);
  41MODULE_PARM_DESC(id, "ID string");
  42module_param_array(enable, bool, NULL, 0444);
  43MODULE_PARM_DESC(enable, "enable card");
  44
  45static struct pci_device_id hifier_ids[] __devinitdata = {
  46        { OXYGEN_PCI_SUBID(0x14c3, 0x1710) },
  47        { OXYGEN_PCI_SUBID(0x14c3, 0x1711) },
  48        { }
  49};
  50MODULE_DEVICE_TABLE(pci, hifier_ids);
  51
  52struct hifier_data {
  53        u8 ak4396_ctl2;
  54};
  55
  56static void ak4396_write(struct oxygen *chip, u8 reg, u8 value)
  57{
  58        oxygen_write_spi(chip, OXYGEN_SPI_TRIGGER  |
  59                         OXYGEN_SPI_DATA_LENGTH_2 |
  60                         OXYGEN_SPI_CLOCK_160 |
  61                         (0 << OXYGEN_SPI_CODEC_SHIFT) |
  62                         OXYGEN_SPI_CEN_LATCH_CLOCK_HI,
  63                         AK4396_WRITE | (reg << 8) | value);
  64}
  65
  66static void update_ak4396_volume(struct oxygen *chip)
  67{
  68        ak4396_write(chip, AK4396_LCH_ATT, chip->dac_volume[0]);
  69        ak4396_write(chip, AK4396_RCH_ATT, chip->dac_volume[1]);
  70}
  71
  72static void hifier_registers_init(struct oxygen *chip)
  73{
  74        struct hifier_data *data = chip->model_data;
  75
  76        ak4396_write(chip, AK4396_CONTROL_1, AK4396_DIF_24_MSB | AK4396_RSTN);
  77        ak4396_write(chip, AK4396_CONTROL_2, data->ak4396_ctl2);
  78        ak4396_write(chip, AK4396_CONTROL_3, AK4396_PCM);
  79        update_ak4396_volume(chip);
  80}
  81
  82static void hifier_init(struct oxygen *chip)
  83{
  84        struct hifier_data *data = chip->model_data;
  85
  86        data->ak4396_ctl2 = AK4396_SMUTE | AK4396_DEM_OFF | AK4396_DFS_NORMAL;
  87        hifier_registers_init(chip);
  88
  89        snd_component_add(chip->card, "AK4396");
  90        snd_component_add(chip->card, "CS5340");
  91}
  92
  93static void hifier_cleanup(struct oxygen *chip)
  94{
  95}
  96
  97static void hifier_resume(struct oxygen *chip)
  98{
  99        hifier_registers_init(chip);
 100}
 101
 102static void set_ak4396_params(struct oxygen *chip,
 103                               struct snd_pcm_hw_params *params)
 104{
 105        struct hifier_data *data = chip->model_data;
 106        u8 value;
 107
 108        value = data->ak4396_ctl2 & ~AK4396_DFS_MASK;
 109        if (params_rate(params) <= 54000)
 110                value |= AK4396_DFS_NORMAL;
 111        else if (params_rate(params) <= 108000)
 112                value |= AK4396_DFS_DOUBLE;
 113        else
 114                value |= AK4396_DFS_QUAD;
 115        data->ak4396_ctl2 = value;
 116
 117        msleep(1); /* wait for the new MCLK to become stable */
 118
 119        ak4396_write(chip, AK4396_CONTROL_1, AK4396_DIF_24_MSB);
 120        ak4396_write(chip, AK4396_CONTROL_2, value);
 121        ak4396_write(chip, AK4396_CONTROL_1, AK4396_DIF_24_MSB | AK4396_RSTN);
 122}
 123
 124static void update_ak4396_mute(struct oxygen *chip)
 125{
 126        struct hifier_data *data = chip->model_data;
 127        u8 value;
 128
 129        value = data->ak4396_ctl2 & ~AK4396_SMUTE;
 130        if (chip->dac_mute)
 131                value |= AK4396_SMUTE;
 132        data->ak4396_ctl2 = value;
 133        ak4396_write(chip, AK4396_CONTROL_2, value);
 134}
 135
 136static void set_cs5340_params(struct oxygen *chip,
 137                              struct snd_pcm_hw_params *params)
 138{
 139}
 140
 141static const DECLARE_TLV_DB_LINEAR(ak4396_db_scale, TLV_DB_GAIN_MUTE, 0);
 142
 143static int hifier_control_filter(struct snd_kcontrol_new *template)
 144{
 145        if (!strcmp(template->name, "Stereo Upmixing"))
 146                return 1; /* stereo only - we don't need upmixing */
 147        return 0;
 148}
 149
 150static const struct oxygen_model model_hifier = {
 151        .shortname = "C-Media CMI8787",
 152        .longname = "C-Media Oxygen HD Audio",
 153        .chip = "CMI8788",
 154        .owner = THIS_MODULE,
 155        .init = hifier_init,
 156        .control_filter = hifier_control_filter,
 157        .cleanup = hifier_cleanup,
 158        .resume = hifier_resume,
 159        .set_dac_params = set_ak4396_params,
 160        .set_adc_params = set_cs5340_params,
 161        .update_dac_volume = update_ak4396_volume,
 162        .update_dac_mute = update_ak4396_mute,
 163        .dac_tlv = ak4396_db_scale,
 164        .model_data_size = sizeof(struct hifier_data),
 165        .device_config = PLAYBACK_0_TO_I2S |
 166                         PLAYBACK_1_TO_SPDIF |
 167                         CAPTURE_0_FROM_I2S_1,
 168        .dac_channels = 2,
 169        .dac_volume_min = 0,
 170        .dac_volume_max = 255,
 171        .function_flags = OXYGEN_FUNCTION_SPI,
 172        .dac_i2s_format = OXYGEN_I2S_FORMAT_LJUST,
 173        .adc_i2s_format = OXYGEN_I2S_FORMAT_LJUST,
 174};
 175
 176static int __devinit hifier_probe(struct pci_dev *pci,
 177                                  const struct pci_device_id *pci_id)
 178{
 179        static int dev;
 180        int err;
 181
 182        if (dev >= SNDRV_CARDS)
 183                return -ENODEV;
 184        if (!enable[dev]) {
 185                ++dev;
 186                return -ENOENT;
 187        }
 188        err = oxygen_pci_probe(pci, index[dev], id[dev], &model_hifier, 0);
 189        if (err >= 0)
 190                ++dev;
 191        return err;
 192}
 193
 194static struct pci_driver hifier_driver = {
 195        .name = "CMI8787HiFier",
 196        .id_table = hifier_ids,
 197        .probe = hifier_probe,
 198        .remove = __devexit_p(oxygen_pci_remove),
 199#ifdef CONFIG_PM
 200        .suspend = oxygen_pci_suspend,
 201        .resume = oxygen_pci_resume,
 202#endif
 203};
 204
 205static int __init alsa_card_hifier_init(void)
 206{
 207        return pci_register_driver(&hifier_driver);
 208}
 209
 210static void __exit alsa_card_hifier_exit(void)
 211{
 212        pci_unregister_driver(&hifier_driver);
 213}
 214
 215module_init(alsa_card_hifier_init)
 216module_exit(alsa_card_hifier_exit)
 217
lxr.linux.no kindly hosted by Redpill Linpro AS, provider of Linux consulting and operations services since 1995.