Linux kernel & device driver programming

Cross-Referenced Linux and Device Driver Code

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