ac97_codec.c
上传用户:jlfgdled
上传日期:2013-04-10
资源大小:33168k
文件大小:35k
源码类别:

Linux/Unix编程

开发平台:

Unix_Linux

  1. /*
  2.  * ac97_codec.c: Generic AC97 mixer/modem module
  3.  *
  4.  * Derived from ac97 mixer in maestro and trident driver.
  5.  *
  6.  * Copyright 2000 Silicon Integrated System Corporation
  7.  *
  8.  * This program is free software; you can redistribute it and/or modify
  9.  * it under the terms of the GNU General Public License as published by
  10.  * the Free Software Foundation; either version 2 of the License, or
  11.  * (at your option) any later version.
  12.  *
  13.  * This program is distributed in the hope that it will be useful,
  14.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  16.  * GNU General Public License for more details.
  17.  *
  18.  * You should have received a copy of the GNU General Public License
  19.  * along with this program; if not, write to the Free Software
  20.  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  21.  *
  22.  **************************************************************************
  23.  *
  24.  * The Intel Audio Codec '97 specification is available at the Intel
  25.  * audio homepage: http://developer.intel.com/ial/scalableplatforms/audio/
  26.  *
  27.  * The specification itself is currently available at:
  28.  * ftp://download.intel.com/ial/scalableplatforms/ac97r22.pdf
  29.  *
  30.  **************************************************************************
  31.  *
  32.  * History
  33.  * Mar 28, 2002 Randolph Bentson <bentson@holmsjoen.com>
  34.  * corrections to support WM9707 in ViewPad 1000
  35.  * v0.4 Mar 15 2000 Ollie Lho
  36.  * dual codecs support verified with 4 channels output
  37.  * v0.3 Feb 22 2000 Ollie Lho
  38.  * bug fix for record mask setting
  39.  * v0.2 Feb 10 2000 Ollie Lho
  40.  * add ac97_read_proc for /proc/driver/{vendor}/ac97
  41.  * v0.1 Jan 14 2000 Ollie Lho <ollie@sis.com.tw> 
  42.  * Isolated from trident.c to support multiple ac97 codec
  43.  */
  44. #include <linux/module.h>
  45. #include <linux/version.h>
  46. #include <linux/kernel.h>
  47. #include <linux/string.h>
  48. #include <linux/errno.h>
  49. #include <linux/bitops.h>
  50. #include <linux/delay.h>
  51. #include <linux/ac97_codec.h>
  52. #include <asm/uaccess.h>
  53. static int ac97_read_mixer(struct ac97_codec *codec, int oss_channel);
  54. static void ac97_write_mixer(struct ac97_codec *codec, int oss_channel, 
  55.      unsigned int left, unsigned int right);
  56. static void ac97_set_mixer(struct ac97_codec *codec, unsigned int oss_mixer, unsigned int val );
  57. static int ac97_recmask_io(struct ac97_codec *codec, int rw, int mask);
  58. static int ac97_mixer_ioctl(struct ac97_codec *codec, unsigned int cmd, unsigned long arg);
  59. static int ac97_init_mixer(struct ac97_codec *codec);
  60. static int wolfson_init00(struct ac97_codec * codec);
  61. static int wolfson_init03(struct ac97_codec * codec);
  62. static int wolfson_init04(struct ac97_codec * codec);
  63. static int tritech_init(struct ac97_codec * codec);
  64. static int tritech_maestro_init(struct ac97_codec * codec);
  65. static int sigmatel_9708_init(struct ac97_codec *codec);
  66. static int sigmatel_9721_init(struct ac97_codec *codec);
  67. static int sigmatel_9744_init(struct ac97_codec *codec);
  68. static int ad1886_init(struct ac97_codec *codec);
  69. static int eapd_control(struct ac97_codec *codec, int);
  70. static int crystal_digital_control(struct ac97_codec *codec, int mode);
  71. /*
  72.  * AC97 operations.
  73.  *
  74.  * If you are adding a codec then you should be able to use
  75.  * eapd_ops - any codec that supports EAPD amp control (most)
  76.  * null_ops - any ancient codec that supports nothing
  77.  *
  78.  * The three functions are
  79.  * init - used for non AC97 standard initialisation
  80.  * amplifier - used to do amplifier control (1=on 0=off)
  81.  * digital - switch to digital modes (0 = analog)
  82.  *
  83.  * Not all codecs support all features, not all drivers use all the
  84.  * operations yet
  85.  */
  86.  
  87. static struct ac97_ops null_ops = { NULL, NULL, NULL };
  88. static struct ac97_ops default_ops = { NULL, eapd_control, NULL };
  89. static struct ac97_ops wolfson_ops00 = { wolfson_init00, NULL, NULL };
  90. static struct ac97_ops wolfson_ops03 = { wolfson_init03, NULL, NULL };
  91. static struct ac97_ops wolfson_ops04 = { wolfson_init04, NULL, NULL };
  92. static struct ac97_ops tritech_ops = { tritech_init, NULL, NULL };
  93. static struct ac97_ops tritech_m_ops = { tritech_maestro_init, NULL, NULL };
  94. static struct ac97_ops sigmatel_9708_ops = { sigmatel_9708_init, NULL, NULL };
  95. static struct ac97_ops sigmatel_9721_ops = { sigmatel_9721_init, NULL, NULL };
  96. static struct ac97_ops sigmatel_9744_ops = { sigmatel_9744_init, NULL, NULL };
  97. static struct ac97_ops crystal_digital_ops = { NULL, eapd_control, crystal_digital_control };
  98. static struct ac97_ops ad1886_ops = { ad1886_init, eapd_control, NULL };
  99. /* sorted by vendor/device id */
  100. static const struct {
  101. u32 id;
  102. char *name;
  103. struct ac97_ops *ops;
  104. } ac97_codec_ids[] = {
  105. {0x41445303, "Analog Devices AD1819", &null_ops},
  106. {0x41445340, "Analog Devices AD1881", &null_ops},
  107. {0x41445348, "Analog Devices AD1881A", &null_ops},
  108. {0x41445360, "Analog Devices AD1885", &default_ops},
  109. {0x41445361, "Analog Devices AD1886", &ad1886_ops},
  110. {0x41445460, "Analog Devices AD1885", &default_ops},
  111. {0x41445461, "Analog Devices AD1886", &ad1886_ops},
  112. {0x414B4D00, "Asahi Kasei AK4540", &null_ops},
  113. {0x414B4D01, "Asahi Kasei AK4542", &null_ops},
  114. {0x414B4D02, "Asahi Kasei AK4543", &null_ops},
  115. {0x414C4710, "ALC200/200P", &null_ops},
  116. {0x414C4720, "ALC650", &null_ops},
  117. {0x43525900, "Cirrus Logic CS4297", &default_ops},
  118. {0x43525903, "Cirrus Logic CS4297", &default_ops},
  119. {0x43525913, "Cirrus Logic CS4297A rev A", &default_ops},
  120. {0x43525914, "Cirrus Logic CS4297A rev B", &default_ops},
  121. {0x43525923, "Cirrus Logic CS4298", &null_ops},
  122. {0x4352592B, "Cirrus Logic CS4294", &null_ops},
  123. {0x4352592D, "Cirrus Logic CS4294", &null_ops},
  124. {0x43525931, "Cirrus Logic CS4299 rev A", &crystal_digital_ops},
  125. {0x43525933, "Cirrus Logic CS4299 rev C", &crystal_digital_ops},
  126. {0x43525934, "Cirrus Logic CS4299 rev D", &crystal_digital_ops},
  127. {0x45838308, "ESS Allegro ES1988", &null_ops},
  128. {0x49434511, "ICE1232", &null_ops}, /* I hope --jk */
  129. {0x4e534331, "National Semiconductor LM4549", &null_ops},
  130. {0x53494c22, "Silicon Laboratory Si3036", &null_ops},
  131. {0x53494c23, "Silicon Laboratory Si3038", &null_ops},
  132. {0x545200FF, "TriTech TR?????", &tritech_m_ops},
  133. {0x54524102, "TriTech TR28022", &null_ops},
  134. {0x54524103, "TriTech TR28023", &null_ops},
  135. {0x54524106, "TriTech TR28026", &null_ops},
  136. {0x54524108, "TriTech TR28028", &tritech_ops},
  137. {0x54524123, "TriTech TR A5", &null_ops},
  138. {0x574D4C00, "Wolfson WM9700A", &wolfson_ops00},
  139. {0x574D4C03, "Wolfson WM9703/WM9707", &wolfson_ops03},
  140. {0x574D4C04, "Wolfson WM9704M/WM9704Q", &wolfson_ops04},
  141. {0x83847600, "SigmaTel STAC????", &null_ops},
  142. {0x83847604, "SigmaTel STAC9701/3/4/5", &null_ops},
  143. {0x83847605, "SigmaTel STAC9704", &null_ops},
  144. {0x83847608, "SigmaTel STAC9708", &sigmatel_9708_ops},
  145. {0x83847609, "SigmaTel STAC9721/23", &sigmatel_9721_ops},
  146. {0x83847644, "SigmaTel STAC9744/45", &sigmatel_9744_ops},
  147. {0x83847656, "SigmaTel STAC9756/57", &sigmatel_9744_ops},
  148. {0x83847666, "SigmaTel STAC9750T", &sigmatel_9744_ops},
  149. {0x83847684, "SigmaTel STAC9783/84?", &null_ops},
  150. {0x57454301, "Winbond 83971D", &null_ops},
  151. };
  152. static const char *ac97_stereo_enhancements[] =
  153. {
  154. /*   0 */ "No 3D Stereo Enhancement",
  155. /*   1 */ "Analog Devices Phat Stereo",
  156. /*   2 */ "Creative Stereo Enhancement",
  157. /*   3 */ "National Semi 3D Stereo Enhancement",
  158. /*   4 */ "YAMAHA Ymersion",
  159. /*   5 */ "BBE 3D Stereo Enhancement",
  160. /*   6 */ "Crystal Semi 3D Stereo Enhancement",
  161. /*   7 */ "Qsound QXpander",
  162. /*   8 */ "Spatializer 3D Stereo Enhancement",
  163. /*   9 */ "SRS 3D Stereo Enhancement",
  164. /*  10 */ "Platform Tech 3D Stereo Enhancement",
  165. /*  11 */ "AKM 3D Audio",
  166. /*  12 */ "Aureal Stereo Enhancement",
  167. /*  13 */ "Aztech 3D Enhancement",
  168. /*  14 */ "Binaura 3D Audio Enhancement",
  169. /*  15 */ "ESS Technology Stereo Enhancement",
  170. /*  16 */ "Harman International VMAx",
  171. /*  17 */ "Nvidea 3D Stereo Enhancement",
  172. /*  18 */ "Philips Incredible Sound",
  173. /*  19 */ "Texas Instruments 3D Stereo Enhancement",
  174. /*  20 */ "VLSI Technology 3D Stereo Enhancement",
  175. /*  21 */ "TriTech 3D Stereo Enhancement",
  176. /*  22 */ "Realtek 3D Stereo Enhancement",
  177. /*  23 */ "Samsung 3D Stereo Enhancement",
  178. /*  24 */ "Wolfson Microelectronics 3D Enhancement",
  179. /*  25 */ "Delta Integration 3D Enhancement",
  180. /*  26 */ "SigmaTel 3D Enhancement",
  181. /*  27 */ "Winbond 3D Stereo Enhancement",
  182. /*  28 */ "Rockwell 3D Stereo Enhancement",
  183. /*  29 */ "Reserved 29",
  184. /*  30 */ "Reserved 30",
  185. /*  31 */ "Reserved 31"
  186. };
  187. /* this table has default mixer values for all OSS mixers. */
  188. static struct mixer_defaults {
  189. int mixer;
  190. unsigned int value;
  191. } mixer_defaults[SOUND_MIXER_NRDEVICES] = {
  192. /* all values 0 -> 100 in bytes */
  193. {SOUND_MIXER_VOLUME, 0x4343},
  194. {SOUND_MIXER_BASS, 0x4343},
  195. {SOUND_MIXER_TREBLE, 0x4343},
  196. {SOUND_MIXER_PCM, 0x4343},
  197. {SOUND_MIXER_SPEAKER, 0x4343},
  198. {SOUND_MIXER_LINE, 0x4343},
  199. {SOUND_MIXER_MIC, 0x0000},
  200. {SOUND_MIXER_CD, 0x4343},
  201. {SOUND_MIXER_ALTPCM, 0x4343},
  202. {SOUND_MIXER_IGAIN, 0x4343},
  203. {SOUND_MIXER_LINE1, 0x4343},
  204. {SOUND_MIXER_PHONEIN, 0x4343},
  205. {SOUND_MIXER_PHONEOUT, 0x4343},
  206. {SOUND_MIXER_VIDEO, 0x4343},
  207. {-1,0}
  208. };
  209. /* table to scale scale from OSS mixer value to AC97 mixer register value */
  210. static struct ac97_mixer_hw {
  211. unsigned char offset;
  212. int scale;
  213. } ac97_hw[SOUND_MIXER_NRDEVICES]= {
  214. [SOUND_MIXER_VOLUME] = {AC97_MASTER_VOL_STEREO,64},
  215. [SOUND_MIXER_BASS] = {AC97_MASTER_TONE, 16},
  216. [SOUND_MIXER_TREBLE] = {AC97_MASTER_TONE, 16},
  217. [SOUND_MIXER_PCM] = {AC97_PCMOUT_VOL, 32},
  218. [SOUND_MIXER_SPEAKER] = {AC97_PCBEEP_VOL, 16},
  219. [SOUND_MIXER_LINE] = {AC97_LINEIN_VOL, 32},
  220. [SOUND_MIXER_MIC] = {AC97_MIC_VOL, 32},
  221. [SOUND_MIXER_CD] = {AC97_CD_VOL, 32},
  222. [SOUND_MIXER_ALTPCM] = {AC97_HEADPHONE_VOL, 64},
  223. [SOUND_MIXER_IGAIN] = {AC97_RECORD_GAIN, 16},
  224. [SOUND_MIXER_LINE1] = {AC97_AUX_VOL, 32},
  225. [SOUND_MIXER_PHONEIN] =  {AC97_PHONE_VOL, 32},
  226. [SOUND_MIXER_PHONEOUT] =  {AC97_MASTER_VOL_MONO, 64},
  227. [SOUND_MIXER_VIDEO] = {AC97_VIDEO_VOL, 32},
  228. };
  229. /* the following tables allow us to go from OSS <-> ac97 quickly. */
  230. enum ac97_recsettings {
  231. AC97_REC_MIC=0,
  232. AC97_REC_CD,
  233. AC97_REC_VIDEO,
  234. AC97_REC_AUX,
  235. AC97_REC_LINE,
  236. AC97_REC_STEREO, /* combination of all enabled outputs..  */
  237. AC97_REC_MONO,       /*.. or the mono equivalent */
  238. AC97_REC_PHONE
  239. };
  240. static const unsigned int ac97_rm2oss[] = {
  241. [AC97_REC_MIC]   = SOUND_MIXER_MIC,
  242. [AC97_REC_CD]   = SOUND_MIXER_CD,
  243. [AC97_REC_VIDEO] = SOUND_MIXER_VIDEO,
  244. [AC97_REC_AUX]   = SOUND_MIXER_LINE1,
  245. [AC97_REC_LINE]  = SOUND_MIXER_LINE,
  246. [AC97_REC_STEREO]= SOUND_MIXER_IGAIN,
  247. [AC97_REC_PHONE] = SOUND_MIXER_PHONEIN
  248. };
  249. /* indexed by bit position */
  250. static const unsigned int ac97_oss_rm[] = {
  251. [SOUND_MIXER_MIC]  = AC97_REC_MIC,
  252. [SOUND_MIXER_CD]  = AC97_REC_CD,
  253. [SOUND_MIXER_VIDEO]  = AC97_REC_VIDEO,
  254. [SOUND_MIXER_LINE1]  = AC97_REC_AUX,
  255. [SOUND_MIXER_LINE]  = AC97_REC_LINE,
  256. [SOUND_MIXER_IGAIN] = AC97_REC_STEREO,
  257. [SOUND_MIXER_PHONEIN]  = AC97_REC_PHONE
  258. };
  259. /* reads the given OSS mixer from the ac97 the caller must have insured that the ac97 knows
  260.    about that given mixer, and should be holding a spinlock for the card */
  261. static int ac97_read_mixer(struct ac97_codec *codec, int oss_channel) 
  262. {
  263. u16 val;
  264. int ret = 0;
  265. int scale;
  266. struct ac97_mixer_hw *mh = &ac97_hw[oss_channel];
  267. val = codec->codec_read(codec , mh->offset);
  268. if (val & AC97_MUTE) {
  269. ret = 0;
  270. } else if (AC97_STEREO_MASK & (1 << oss_channel)) {
  271. /* nice stereo mixers .. */
  272. int left,right;
  273. left = (val >> 8)  & 0x7f;
  274. right = val  & 0x7f;
  275. if (oss_channel == SOUND_MIXER_IGAIN) {
  276. right = (right * 100) / mh->scale;
  277. left = (left * 100) / mh->scale;
  278. } else {
  279. /* these may have 5 or 6 bit resolution */
  280. if(oss_channel == SOUND_MIXER_VOLUME || oss_channel == SOUND_MIXER_ALTPCM)
  281. scale = (1 << codec->bit_resolution);
  282. else
  283. scale = mh->scale;
  284. right = 100 - ((right * 100) / scale);
  285. left = 100 - ((left * 100) / scale);
  286. }
  287. ret = left | (right << 8);
  288. } else if (oss_channel == SOUND_MIXER_SPEAKER) {
  289. ret = 100 - ((((val & 0x1e)>>1) * 100) / mh->scale);
  290. } else if (oss_channel == SOUND_MIXER_PHONEIN) {
  291. ret = 100 - (((val & 0x1f) * 100) / mh->scale);
  292. } else if (oss_channel == SOUND_MIXER_PHONEOUT) {
  293. scale = (1 << codec->bit_resolution);
  294. ret = 100 - (((val & 0x1f) * 100) / scale);
  295. } else if (oss_channel == SOUND_MIXER_MIC) {
  296. ret = 100 - (((val & 0x1f) * 100) / mh->scale);
  297. /*  the low bit is optional in the tone sliders and masking
  298.     it lets us avoid the 0xf 'bypass'.. */
  299. } else if (oss_channel == SOUND_MIXER_BASS) {
  300. ret = 100 - ((((val >> 8) & 0xe) * 100) / mh->scale);
  301. } else if (oss_channel == SOUND_MIXER_TREBLE) {
  302. ret = 100 - (((val & 0xe) * 100) / mh->scale);
  303. }
  304. #ifdef DEBUG
  305. printk("ac97_codec: read OSS mixer %2d (%s ac97 register 0x%02x), "
  306.        "0x%04x -> 0x%04xn",
  307.        oss_channel, codec->id ? "Secondary" : "Primary",
  308.        mh->offset, val, ret);
  309. #endif
  310. return ret;
  311. }
  312. /* write the OSS encoded volume to the given OSS encoded mixer, again caller's job to
  313.    make sure all is well in arg land, call with spinlock held */
  314. static void ac97_write_mixer(struct ac97_codec *codec, int oss_channel,
  315.       unsigned int left, unsigned int right)
  316. {
  317. u16 val = 0;
  318. int scale;
  319. struct ac97_mixer_hw *mh = &ac97_hw[oss_channel];
  320. #ifdef DEBUG
  321. printk("ac97_codec: wrote OSS mixer %2d (%s ac97 register 0x%02x), "
  322.        "left vol:%2d, right vol:%2d:",
  323.        oss_channel, codec->id ? "Secondary" : "Primary",
  324.        mh->offset, left, right);
  325. #endif
  326. if (AC97_STEREO_MASK & (1 << oss_channel)) {
  327. /* stereo mixers */
  328. if (left == 0 && right == 0) {
  329. val = AC97_MUTE;
  330. } else {
  331. if (oss_channel == SOUND_MIXER_IGAIN) {
  332. right = (right * mh->scale) / 100;
  333. left = (left * mh->scale) / 100;
  334. if (right >= mh->scale)
  335. right = mh->scale-1;
  336. if (left >= mh->scale)
  337. left = mh->scale-1;
  338. } else {
  339. /* these may have 5 or 6 bit resolution */
  340. if (oss_channel == SOUND_MIXER_VOLUME ||
  341.     oss_channel == SOUND_MIXER_ALTPCM)
  342. scale = (1 << codec->bit_resolution);
  343. else
  344. scale = mh->scale;
  345. right = ((100 - right) * scale) / 100;
  346. left = ((100 - left) * scale) / 100;
  347. if (right >= scale)
  348. right = scale-1;
  349. if (left >= scale)
  350. left = scale-1;
  351. }
  352. val = (left << 8) | right;
  353. }
  354. } else if (oss_channel == SOUND_MIXER_BASS) {
  355. val = codec->codec_read(codec , mh->offset) & ~0x0f00;
  356. left = ((100 - left) * mh->scale) / 100;
  357. if (left >= mh->scale)
  358. left = mh->scale-1;
  359. val |= (left << 8) & 0x0e00;
  360. } else if (oss_channel == SOUND_MIXER_TREBLE) {
  361. val = codec->codec_read(codec , mh->offset) & ~0x000f;
  362. left = ((100 - left) * mh->scale) / 100;
  363. if (left >= mh->scale)
  364. left = mh->scale-1;
  365. val |= left & 0x000e;
  366. } else if(left == 0) {
  367. val = AC97_MUTE;
  368. } else if (oss_channel == SOUND_MIXER_SPEAKER) {
  369. left = ((100 - left) * mh->scale) / 100;
  370. if (left >= mh->scale)
  371. left = mh->scale-1;
  372. val = left << 1;
  373. } else if (oss_channel == SOUND_MIXER_PHONEIN) {
  374. left = ((100 - left) * mh->scale) / 100;
  375. if (left >= mh->scale)
  376. left = mh->scale-1;
  377. val = left;
  378. } else if (oss_channel == SOUND_MIXER_PHONEOUT) {
  379. scale = (1 << codec->bit_resolution);
  380. left = ((100 - left) * scale) / 100;
  381. if (left >= mh->scale)
  382. left = mh->scale-1;
  383. val = left;
  384. } else if (oss_channel == SOUND_MIXER_MIC) {
  385. val = codec->codec_read(codec , mh->offset) & ~0x801f;
  386. left = ((100 - left) * mh->scale) / 100;
  387. if (left >= mh->scale)
  388. left = mh->scale-1;
  389. val |= left;
  390. /*  the low bit is optional in the tone sliders and masking
  391.     it lets us avoid the 0xf 'bypass'.. */
  392. }
  393. #ifdef DEBUG
  394. printk(" 0x%04x", val);
  395. #endif
  396. codec->codec_write(codec, mh->offset, val);
  397. #ifdef DEBUG
  398. val = codec->codec_read(codec, mh->offset);
  399. printk(" -> 0x%04xn", val);
  400. #endif
  401. }
  402. /* a thin wrapper for write_mixer */
  403. static void ac97_set_mixer(struct ac97_codec *codec, unsigned int oss_mixer, unsigned int val ) 
  404. {
  405. unsigned int left,right;
  406. /* cleanse input a little */
  407. right = ((val >> 8)  & 0xff) ;
  408. left = (val  & 0xff) ;
  409. if (right > 100) right = 100;
  410. if (left > 100) left = 100;
  411. codec->mixer_state[oss_mixer] = (right << 8) | left;
  412. codec->write_mixer(codec, oss_mixer, left, right);
  413. }
  414. /* read or write the recmask, the ac97 can really have left and right recording
  415.    inputs independantly set, but OSS doesn't seem to want us to express that to
  416.    the user. the caller guarantees that we have a supported bit set, and they
  417.    must be holding the card's spinlock */
  418. static int ac97_recmask_io(struct ac97_codec *codec, int rw, int mask) 
  419. {
  420. unsigned int val;
  421. if (rw) {
  422. /* read it from the card */
  423. val = codec->codec_read(codec, AC97_RECORD_SELECT);
  424. #ifdef DEBUG
  425. printk("ac97_codec: ac97 recmask to set to 0x%04xn", val);
  426. #endif
  427. return (1 << ac97_rm2oss[val & 0x07]);
  428. }
  429. /* else, write the first set in the mask as the
  430.    output */
  431. /* clear out current set value first (AC97 supports only 1 input!) */
  432. val = (1 << ac97_rm2oss[codec->codec_read(codec, AC97_RECORD_SELECT) & 0x07]);
  433. if (mask != val)
  434.     mask &= ~val;
  435.        
  436. val = ffs(mask); 
  437. val = ac97_oss_rm[val-1];
  438. val |= val << 8;  /* set both channels */
  439. #ifdef DEBUG
  440. printk("ac97_codec: setting ac97 recmask to 0x%04xn", val);
  441. #endif
  442. codec->codec_write(codec, AC97_RECORD_SELECT, val);
  443. return 0;
  444. };
  445. static int ac97_mixer_ioctl(struct ac97_codec *codec, unsigned int cmd, unsigned long arg)
  446. {
  447. int i, val = 0;
  448. if (cmd == SOUND_MIXER_INFO) {
  449. mixer_info info;
  450. strncpy(info.id, codec->name, sizeof(info.id));
  451. strncpy(info.name, codec->name, sizeof(info.name));
  452. info.modify_counter = codec->modcnt;
  453. if (copy_to_user((void *)arg, &info, sizeof(info)))
  454. return -EFAULT;
  455. return 0;
  456. }
  457. if (cmd == SOUND_OLD_MIXER_INFO) {
  458. _old_mixer_info info;
  459. strncpy(info.id, codec->name, sizeof(info.id));
  460. strncpy(info.name, codec->name, sizeof(info.name));
  461. if (copy_to_user((void *)arg, &info, sizeof(info)))
  462. return -EFAULT;
  463. return 0;
  464. }
  465. if (_IOC_TYPE(cmd) != 'M' || _SIOC_SIZE(cmd) != sizeof(int))
  466. return -EINVAL;
  467. if (cmd == OSS_GETVERSION)
  468. return put_user(SOUND_VERSION, (int *)arg);
  469. if (_SIOC_DIR(cmd) == _SIOC_READ) {
  470. switch (_IOC_NR(cmd)) {
  471. case SOUND_MIXER_RECSRC: /* give them the current record source */
  472. if (!codec->recmask_io) {
  473. val = 0;
  474. } else {
  475. val = codec->recmask_io(codec, 1, 0);
  476. }
  477. break;
  478. case SOUND_MIXER_DEVMASK: /* give them the supported mixers */
  479. val = codec->supported_mixers;
  480. break;
  481. case SOUND_MIXER_RECMASK: /* Arg contains a bit for each supported recording source */
  482. val = codec->record_sources;
  483. break;
  484. case SOUND_MIXER_STEREODEVS: /* Mixer channels supporting stereo */
  485. val = codec->stereo_mixers;
  486. break;
  487. case SOUND_MIXER_CAPS:
  488. val = SOUND_CAP_EXCL_INPUT;
  489. break;
  490. default: /* read a specific mixer */
  491. i = _IOC_NR(cmd);
  492. if (!supported_mixer(codec, i)) 
  493. return -EINVAL;
  494. /* do we ever want to touch the hardware? */
  495.         /* val = codec->read_mixer(codec, i); */
  496. val = codec->mixer_state[i];
  497.   break;
  498. }
  499. return put_user(val, (int *)arg);
  500. }
  501. if (_SIOC_DIR(cmd) == (_SIOC_WRITE|_SIOC_READ)) {
  502. codec->modcnt++;
  503. if (get_user(val, (int *)arg))
  504. return -EFAULT;
  505. switch (_IOC_NR(cmd)) {
  506. case SOUND_MIXER_RECSRC: /* Arg contains a bit for each recording source */
  507. if (!codec->recmask_io) return -EINVAL;
  508. if (!val) return 0;
  509. if (!(val &= codec->record_sources)) return -EINVAL;
  510. codec->recmask_io(codec, 0, val);
  511. return 0;
  512. default: /* write a specific mixer */
  513. i = _IOC_NR(cmd);
  514. if (!supported_mixer(codec, i)) 
  515. return -EINVAL;
  516. ac97_set_mixer(codec, i, val);
  517. return 0;
  518. }
  519. }
  520. return -EINVAL;
  521. }
  522. /* entry point for /proc/driver/controller_vendor/ac97/%d */
  523. int ac97_read_proc (char *page, char **start, off_t off,
  524.     int count, int *eof, void *data)
  525. {
  526. int len = 0, cap, extid, val, id1, id2;
  527. struct ac97_codec *codec;
  528. int is_ac97_20 = 0;
  529. if ((codec = data) == NULL)
  530. return -ENODEV;
  531. id1 = codec->codec_read(codec, AC97_VENDOR_ID1);
  532. id2 = codec->codec_read(codec, AC97_VENDOR_ID2);
  533. len += sprintf (page+len, "Vendor name      : %sn", codec->name);
  534. len += sprintf (page+len, "Vendor id        : %04X %04Xn", id1, id2);
  535. extid = codec->codec_read(codec, AC97_EXTENDED_ID);
  536. extid &= ~((1<<2)|(1<<4)|(1<<5)|(1<<10)|(1<<11)|(1<<12)|(1<<13));
  537. len += sprintf (page+len, "AC97 Version     : %sn",
  538. extid ? "2.0 or later" : "1.0");
  539. if (extid) is_ac97_20 = 1;
  540. cap = codec->codec_read(codec, AC97_RESET);
  541. len += sprintf (page+len, "Capabilities     :%s%s%s%s%s%sn",
  542. cap & 0x0001 ? " -dedicated MIC PCM IN channel-" : "",
  543. cap & 0x0002 ? " -reserved1-" : "",
  544. cap & 0x0004 ? " -bass & treble-" : "",
  545. cap & 0x0008 ? " -simulated stereo-" : "",
  546. cap & 0x0010 ? " -headphone out-" : "",
  547. cap & 0x0020 ? " -loudness-" : "");
  548. val = cap & 0x00c0;
  549. len += sprintf (page+len, "DAC resolutions  :%s%s%sn",
  550. " -16-bit-",
  551. val & 0x0040 ? " -18-bit-" : "",
  552. val & 0x0080 ? " -20-bit-" : "");
  553. val = cap & 0x0300;
  554. len += sprintf (page+len, "ADC resolutions  :%s%s%sn",
  555. " -16-bit-",
  556. val & 0x0100 ? " -18-bit-" : "",
  557. val & 0x0200 ? " -20-bit-" : "");
  558. len += sprintf (page+len, "3D enhancement   : %sn",
  559. ac97_stereo_enhancements[(cap >> 10) & 0x1f]);
  560. val = codec->codec_read(codec, AC97_GENERAL_PURPOSE);
  561. len += sprintf (page+len, "POP path         : %s 3Dn"
  562. "Sim. stereo      : %sn"
  563. "3D enhancement   : %sn"
  564. "Loudness         : %sn"
  565. "Mono output      : %sn"
  566. "MIC select       : %sn"
  567. "ADC/DAC loopback : %sn",
  568. val & 0x8000 ? "post" : "pre",
  569. val & 0x4000 ? "on" : "off",
  570. val & 0x2000 ? "on" : "off",
  571. val & 0x1000 ? "on" : "off",
  572. val & 0x0200 ? "MIC" : "MIX",
  573. val & 0x0100 ? "MIC2" : "MIC1",
  574. val & 0x0080 ? "on" : "off");
  575. extid = codec->codec_read(codec, AC97_EXTENDED_ID);
  576. cap = extid;
  577. len += sprintf (page+len, "Ext Capabilities :%s%s%s%s%s%s%sn",
  578. cap & 0x0001 ? " -var rate PCM audio-" : "",
  579. cap & 0x0002 ? " -2x PCM audio out-" : "",
  580. cap & 0x0008 ? " -var rate MIC in-" : "",
  581. cap & 0x0040 ? " -PCM center DAC-" : "",
  582. cap & 0x0080 ? " -PCM surround DAC-" : "",
  583. cap & 0x0100 ? " -PCM LFE DAC-" : "",
  584. cap & 0x0200 ? " -slot/DAC mappings-" : "");
  585. if (is_ac97_20) {
  586. len += sprintf (page+len, "Front DAC rate   : %dn",
  587. codec->codec_read(codec, AC97_PCM_FRONT_DAC_RATE));
  588. }
  589. return len;
  590. }
  591. /**
  592.  * codec_id -  Turn id1/id2 into a PnP string
  593.  * @id1: Vendor ID1
  594.  * @id2: Vendor ID2
  595.  * @buf: 10 byte buffer
  596.  *
  597.  * Fills buf with a zero terminated PnP ident string for the id1/id2
  598.  * pair. For convenience the return is the passed in buffer pointer.
  599.  */
  600.  
  601. static char *codec_id(u16 id1, u16 id2, char *buf)
  602. {
  603. if(id1&0x8080)
  604. snprintf(buf, 10, "%0x4X:%0x4X", id1, id2);
  605. buf[0] = (id1 >> 8);
  606. buf[1] = (id1 & 0xFF);
  607. buf[2] = (id2 >> 8);
  608. snprintf(buf+3, 7, "%d", id2&0xFF);
  609. return buf;
  610. }
  611.  
  612. /**
  613.  * ac97_probe_codec - Initialize and setup AC97-compatible codec
  614.  * @codec: (in/out) Kernel info for a single AC97 codec
  615.  *
  616.  * Reset the AC97 codec, then initialize the mixer and
  617.  * the rest of the @codec structure.
  618.  *
  619.  * The codec_read and codec_write fields of @codec are
  620.  * required to be setup and working when this function
  621.  * is called.  All other fields are set by this function.
  622.  *
  623.  * codec_wait field of @codec can optionally be provided
  624.  * when calling this function.  If codec_wait is not %NULL,
  625.  * this function will call codec_wait any time it is
  626.  * necessary to wait for the audio chip to reach the
  627.  * codec-ready state.  If codec_wait is %NULL, then
  628.  * the default behavior is to call schedule_timeout.
  629.  * Currently codec_wait is used to wait for AC97 codec
  630.  * reset to complete. 
  631.  *
  632.  * Returns 1 (true) on success, or 0 (false) on failure.
  633.  */
  634.  
  635. int ac97_probe_codec(struct ac97_codec *codec)
  636. {
  637. u16 id1, id2;
  638. u16 audio, modem;
  639. int i;
  640. char cidbuf[10];
  641. /* probing AC97 codec, AC97 2.0 says that bit 15 of register 0x00 (reset) should 
  642.  * be read zero.
  643.  *
  644.  * FIXME: is the following comment outdated?  -jgarzik 
  645.  * Probing of AC97 in this way is not reliable, it is not even SAFE !!
  646.  */
  647. codec->codec_write(codec, AC97_RESET, 0L);
  648. /* also according to spec, we wait for codec-ready state */
  649. if (codec->codec_wait)
  650. codec->codec_wait(codec);
  651. else
  652. udelay(10);
  653. if ((audio = codec->codec_read(codec, AC97_RESET)) & 0x8000) {
  654. printk(KERN_ERR "ac97_codec: %s ac97 codec not presentn",
  655.        (codec->id & 0x2) ? (codec->id&1 ? "4th" : "Tertiary") 
  656.        : (codec->id&1 ? "Secondary":  "Primary"));
  657. return 0;
  658. }
  659. /* probe for Modem Codec */
  660. codec->codec_write(codec, AC97_EXTENDED_MODEM_ID, 0L);
  661. modem = codec->codec_read(codec, AC97_EXTENDED_MODEM_ID) & 1;
  662. modem |= (audio&2);
  663. audio &= ~2;
  664. codec->name = NULL;
  665. codec->codec_ops = &null_ops;
  666. id1 = codec->codec_read(codec, AC97_VENDOR_ID1);
  667. id2 = codec->codec_read(codec, AC97_VENDOR_ID2);
  668. for (i = 0; i < ARRAY_SIZE(ac97_codec_ids); i++) {
  669. if (ac97_codec_ids[i].id == ((id1 << 16) | id2)) {
  670. codec->type = ac97_codec_ids[i].id;
  671. codec->name = ac97_codec_ids[i].name;
  672. codec->codec_ops = ac97_codec_ids[i].ops;
  673. break;
  674. }
  675. }
  676. if (codec->name == NULL)
  677. codec->name = "Unknown";
  678. printk(KERN_INFO "ac97_codec: AC97 %s codec, id: %s(%s)n", 
  679. modem ? "Modem" : (audio ? "Audio" : ""),
  680.        codec_id(id1, id2, cidbuf), codec->name);
  681. return ac97_init_mixer(codec);
  682. }
  683. static int ac97_init_mixer(struct ac97_codec *codec)
  684. {
  685. u16 cap;
  686. int i;
  687. cap = codec->codec_read(codec, AC97_RESET);
  688. /* mixer masks */
  689. codec->supported_mixers = AC97_SUPPORTED_MASK;
  690. codec->stereo_mixers = AC97_STEREO_MASK;
  691. codec->record_sources = AC97_RECORD_MASK;
  692. if (!(cap & 0x04))
  693. codec->supported_mixers &= ~(SOUND_MASK_BASS|SOUND_MASK_TREBLE);
  694. if (!(cap & 0x10))
  695. codec->supported_mixers &= ~SOUND_MASK_ALTPCM;
  696. /* detect bit resolution */
  697. codec->codec_write(codec, AC97_MASTER_VOL_STEREO, 0x2020);
  698. if(codec->codec_read(codec, AC97_MASTER_VOL_STEREO) == 0x2020)
  699. codec->bit_resolution = 6;
  700. else
  701. codec->bit_resolution = 5;
  702. /* generic OSS to AC97 wrapper */
  703. codec->read_mixer = ac97_read_mixer;
  704. codec->write_mixer = ac97_write_mixer;
  705. codec->recmask_io = ac97_recmask_io;
  706. codec->mixer_ioctl = ac97_mixer_ioctl;
  707. /* codec specific initialization for 4-6 channel output or secondary codec stuff */
  708. if (codec->codec_ops->init != NULL) {
  709. codec->codec_ops->init(codec);
  710. }
  711. /* initialize mixer channel volumes */
  712. for (i = 0; i < SOUND_MIXER_NRDEVICES; i++) {
  713. struct mixer_defaults *md = &mixer_defaults[i];
  714. if (md->mixer == -1) 
  715. break;
  716. if (!supported_mixer(codec, md->mixer)) 
  717. continue;
  718. ac97_set_mixer(codec, md->mixer, md->value);
  719. }
  720. return 1;
  721. }
  722. #define AC97_SIGMATEL_ANALOG    0x6c /* Analog Special */
  723. #define AC97_SIGMATEL_DAC2INVERT 0x6e
  724. #define AC97_SIGMATEL_BIAS1     0x70
  725. #define AC97_SIGMATEL_BIAS2     0x72
  726. #define AC97_SIGMATEL_MULTICHN  0x74 /* Multi-Channel programming */
  727. #define AC97_SIGMATEL_CIC1      0x76
  728. #define AC97_SIGMATEL_CIC2      0x78
  729. static int sigmatel_9708_init(struct ac97_codec * codec)
  730. {
  731. u16 codec72, codec6c;
  732. codec72 = codec->codec_read(codec, AC97_SIGMATEL_BIAS2) & 0x8000;
  733. codec6c = codec->codec_read(codec, AC97_SIGMATEL_ANALOG);
  734. if ((codec72==0) && (codec6c==0)) {
  735. codec->codec_write(codec, AC97_SIGMATEL_CIC1, 0xabba);
  736. codec->codec_write(codec, AC97_SIGMATEL_CIC2, 0x1000);
  737. codec->codec_write(codec, AC97_SIGMATEL_BIAS1, 0xabba);
  738. codec->codec_write(codec, AC97_SIGMATEL_BIAS2, 0x0007);
  739. } else if ((codec72==0x8000) && (codec6c==0)) {
  740. codec->codec_write(codec, AC97_SIGMATEL_CIC1, 0xabba);
  741. codec->codec_write(codec, AC97_SIGMATEL_CIC2, 0x1001);
  742. codec->codec_write(codec, AC97_SIGMATEL_DAC2INVERT, 0x0008);
  743. } else if ((codec72==0x8000) && (codec6c==0x0080)) {
  744. /* nothing */
  745. }
  746. codec->codec_write(codec, AC97_SIGMATEL_MULTICHN, 0x0000);
  747. return 0;
  748. }
  749. static int sigmatel_9721_init(struct ac97_codec * codec)
  750. {
  751. /* Only set up secondary codec */
  752. if (codec->id == 0)
  753. return 0;
  754. codec->codec_write(codec, AC97_SURROUND_MASTER, 0L);
  755. /* initialize SigmaTel STAC9721/23 as secondary codec, decoding AC link
  756.    sloc 3,4 = 0x01, slot 7,8 = 0x00, */
  757. codec->codec_write(codec, AC97_SIGMATEL_MULTICHN, 0x00);
  758. /* we don't have the crystal when we are on an AMR card, so use
  759.    BIT_CLK as our clock source. Write the magic word ABBA and read
  760.    back to enable register 0x78 */
  761. codec->codec_write(codec, AC97_SIGMATEL_CIC1, 0xabba);
  762. codec->codec_read(codec, AC97_SIGMATEL_CIC1);
  763. /* sync all the clocks*/
  764. codec->codec_write(codec, AC97_SIGMATEL_CIC2, 0x3802);
  765. return 0;
  766. }
  767. static int sigmatel_9744_init(struct ac97_codec * codec)
  768. {
  769. // patch for SigmaTel
  770. codec->codec_write(codec, AC97_SIGMATEL_CIC1, 0xabba);
  771. codec->codec_write(codec, AC97_SIGMATEL_CIC2, 0x0000); // is this correct? --jk
  772. codec->codec_write(codec, AC97_SIGMATEL_BIAS1, 0xabba);
  773. codec->codec_write(codec, AC97_SIGMATEL_BIAS2, 0x0002);
  774. codec->codec_write(codec, AC97_SIGMATEL_MULTICHN, 0x0000);
  775. return 0;
  776. }
  777. static int wolfson_init00(struct ac97_codec * codec)
  778. {
  779. /* This initialization is suspect, but not known to be wrong.
  780.    It was copied from the initialization for the WM9704Q, but
  781.    that same sequence is known to fail for the WM9707.  Thus
  782.    this warning may help someone with hardware to test
  783.    this code. */
  784. codec->codec_write(codec, 0x72, 0x0808);
  785. codec->codec_write(codec, 0x74, 0x0808);
  786. // patch for DVD noise
  787. codec->codec_write(codec, 0x5a, 0x0200);
  788. // init vol as PCM vol
  789. codec->codec_write(codec, 0x70,
  790. codec->codec_read(codec, AC97_PCMOUT_VOL));
  791. codec->codec_write(codec, AC97_SURROUND_MASTER, 0x0000);
  792. return 0;
  793. }
  794. static int wolfson_init03(struct ac97_codec * codec)
  795. {
  796. /* this is known to work for the ViewSonic ViewPad 1000 */
  797. codec->codec_write(codec, 0x72, 0x0808);
  798. codec->codec_write(codec, 0x20, 0x8000);
  799. return 0;
  800. }
  801. static int wolfson_init04(struct ac97_codec * codec)
  802. {
  803. codec->codec_write(codec, 0x72, 0x0808);
  804. codec->codec_write(codec, 0x74, 0x0808);
  805. // patch for DVD noise
  806. codec->codec_write(codec, 0x5a, 0x0200);
  807. // init vol as PCM vol
  808. codec->codec_write(codec, 0x70,
  809. codec->codec_read(codec, AC97_PCMOUT_VOL));
  810. codec->codec_write(codec, AC97_SURROUND_MASTER, 0x0000);
  811. return 0;
  812. }
  813. static int tritech_init(struct ac97_codec * codec)
  814. {
  815. codec->codec_write(codec, 0x26, 0x0300);
  816. codec->codec_write(codec, 0x26, 0x0000);
  817. codec->codec_write(codec, AC97_SURROUND_MASTER, 0x0000);
  818. codec->codec_write(codec, AC97_RESERVED_3A, 0x0000);
  819. return 0;
  820. }
  821. /* copied from drivers/sound/maestro.c */
  822. static int tritech_maestro_init(struct ac97_codec * codec)
  823. {
  824. /* no idea what this does */
  825. codec->codec_write(codec, 0x2A, 0x0001);
  826. codec->codec_write(codec, 0x2C, 0x0000);
  827. codec->codec_write(codec, 0x2C, 0XFFFF);
  828. return 0;
  829. }
  830. /* 
  831.  * Presario700 workaround 
  832.  *  for Jack Sense/SPDIF Register mis-setting causing
  833.  * no audible output
  834.  * by Santiago Nullo 04/05/2002
  835.  */
  836. #define AC97_AD1886_JACK_SENSE 0x72
  837. static int ad1886_init(struct ac97_codec * codec)
  838. {
  839. /* from AD1886 Specs */
  840. codec->codec_write(codec, AC97_AD1886_JACK_SENSE, 0x0010);
  841. return 0;
  842. }
  843. /*
  844.  * This is basically standard AC97. It should work as a default for
  845.  * almost all modern codecs. Note that some cards wire EAPD *backwards*
  846.  * That side of it is up to the card driver not us to cope with.
  847.  *
  848.  */
  849. static int eapd_control(struct ac97_codec * codec, int on)
  850. {
  851. if(on)
  852. codec->codec_write(codec, AC97_POWER_CONTROL,
  853. codec->codec_read(codec, AC97_POWER_CONTROL)|0x8000);
  854. else
  855. codec->codec_write(codec, AC97_POWER_CONTROL,
  856. codec->codec_read(codec, AC97_POWER_CONTROL)&~0x8000);
  857. return 0;
  858. }
  859. /*
  860.  * Crystal digital audio control (CS4299
  861.  */
  862.  
  863. static int crystal_digital_control(struct ac97_codec *codec, int mode)
  864. {
  865. u16 cv;
  866. switch(mode)
  867. {
  868. case 0: cv = 0x0; break; /* SPEN off */
  869. case 1: cv = 0x8004; break; /* 48KHz digital */
  870. case 2: cv = 0x8104; break; /* 44.1KHz digital */
  871. default:
  872. return -1; /* Not supported yet(eg AC3) */
  873. }
  874. codec->codec_write(codec, 0x68, cv);
  875. return 0;
  876. }
  877. /* copied from drivers/sound/maestro.c */
  878. #if 0  /* there has been 1 person on the planet with a pt101 that we
  879.         know of.  If they care, they can put this back in :) */
  880. static int pt101_init(struct ac97_codec * codec)
  881. {
  882. printk(KERN_INFO "ac97_codec: PT101 Codec detected, initializing but _not_ installing mixer device.n");
  883. /* who knows.. */
  884. codec->codec_write(codec, 0x2A, 0x0001);
  885. codec->codec_write(codec, 0x2C, 0x0000);
  886. codec->codec_write(codec, 0x2C, 0xFFFF);
  887. codec->codec_write(codec, 0x10, 0x9F1F);
  888. codec->codec_write(codec, 0x12, 0x0808);
  889. codec->codec_write(codec, 0x14, 0x9F1F);
  890. codec->codec_write(codec, 0x16, 0x9F1F);
  891. codec->codec_write(codec, 0x18, 0x0404);
  892. codec->codec_write(codec, 0x1A, 0x0000);
  893. codec->codec_write(codec, 0x1C, 0x0000);
  894. codec->codec_write(codec, 0x02, 0x0404);
  895. codec->codec_write(codec, 0x04, 0x0808);
  896. codec->codec_write(codec, 0x0C, 0x801F);
  897. codec->codec_write(codec, 0x0E, 0x801F);
  898. return 0;
  899. }
  900. #endif
  901. EXPORT_SYMBOL(ac97_read_proc);
  902. EXPORT_SYMBOL(ac97_probe_codec);
  903. /*
  904.  * AC97 library support routines
  905.  */
  906.  
  907. /**
  908.  * ac97_set_dac_rate - set codec rate adaption
  909.  * @codec: ac97 code
  910.  * @rate: rate in hertz
  911.  *
  912.  * Set the DAC rate. Assumes the codec supports VRA. The caller is
  913.  * expected to have checked this little detail.
  914.  */
  915.  
  916. unsigned int ac97_set_dac_rate(struct ac97_codec *codec, unsigned int rate)
  917. {
  918. unsigned int new_rate = rate;
  919. u32 dacp;
  920. u32 mast_vol, phone_vol, mono_vol, pcm_vol;
  921. u32 mute_vol = 0x8000; /* The mute volume? */
  922. if(rate != codec->codec_read(codec, AC97_PCM_FRONT_DAC_RATE))
  923. {
  924. /* Mute several registers */
  925. mast_vol = codec->codec_read(codec, AC97_MASTER_VOL_STEREO);
  926. mono_vol = codec->codec_read(codec, AC97_MASTER_VOL_MONO);
  927. phone_vol = codec->codec_read(codec, AC97_HEADPHONE_VOL);
  928. pcm_vol = codec->codec_read(codec, AC97_PCMOUT_VOL);
  929. codec->codec_write(codec, AC97_MASTER_VOL_STEREO, mute_vol);
  930. codec->codec_write(codec, AC97_MASTER_VOL_MONO, mute_vol);
  931. codec->codec_write(codec, AC97_HEADPHONE_VOL, mute_vol);
  932. codec->codec_write(codec, AC97_PCMOUT_VOL, mute_vol);
  933. /* Power down the DAC */
  934. dacp=codec->codec_read(codec, AC97_POWER_CONTROL);
  935. codec->codec_write(codec, AC97_POWER_CONTROL, dacp|0x0200);
  936. /* Load the rate and read the effective rate */
  937. codec->codec_write(codec, AC97_PCM_FRONT_DAC_RATE, rate);
  938. new_rate=codec->codec_read(codec, AC97_PCM_FRONT_DAC_RATE);
  939. /* Power it back up */
  940. codec->codec_write(codec, AC97_POWER_CONTROL, dacp);
  941. /* Restore volumes */
  942. codec->codec_write(codec, AC97_MASTER_VOL_STEREO, mast_vol);
  943. codec->codec_write(codec, AC97_MASTER_VOL_MONO, mono_vol);
  944. codec->codec_write(codec, AC97_HEADPHONE_VOL, phone_vol);
  945. codec->codec_write(codec, AC97_PCMOUT_VOL, pcm_vol);
  946. }
  947. return new_rate;
  948. }
  949. EXPORT_SYMBOL(ac97_set_dac_rate);
  950. /**
  951.  * ac97_set_adc_rate - set codec rate adaption
  952.  * @codec: ac97 code
  953.  * @rate: rate in hertz
  954.  *
  955.  * Set the ADC rate. Assumes the codec supports VRA. The caller is
  956.  * expected to have checked this little detail.
  957.  */
  958. unsigned int ac97_set_adc_rate(struct ac97_codec *codec, unsigned int rate)
  959. {
  960. unsigned int new_rate = rate;
  961. u32 dacp;
  962. if(rate != codec->codec_read(codec, AC97_PCM_LR_ADC_RATE))
  963. {
  964. /* Power down the ADC */
  965. dacp=codec->codec_read(codec, AC97_POWER_CONTROL);
  966. codec->codec_write(codec, AC97_POWER_CONTROL, dacp|0x0100);
  967. /* Load the rate and read the effective rate */
  968. codec->codec_write(codec, AC97_PCM_LR_ADC_RATE, rate);
  969. new_rate=codec->codec_read(codec, AC97_PCM_LR_ADC_RATE);
  970. /* Power it back up */
  971. codec->codec_write(codec, AC97_POWER_CONTROL, dacp);
  972. }
  973. return new_rate;
  974. }
  975. EXPORT_SYMBOL(ac97_set_adc_rate);
  976. int ac97_save_state(struct ac97_codec *codec)
  977. {
  978. return 0;
  979. }
  980. EXPORT_SYMBOL(ac97_save_state);
  981. int ac97_restore_state(struct ac97_codec *codec)
  982. {
  983. int i;
  984. unsigned int left, right, val;
  985. for (i = 0; i < SOUND_MIXER_NRDEVICES; i++) {
  986. if (!supported_mixer(codec, i)) 
  987. continue;
  988. val = codec->mixer_state[i];
  989. right = val >> 8;
  990. left = val  & 0xff;
  991. codec->write_mixer(codec, i, left, right);
  992. }
  993. return 0;
  994. }
  995. EXPORT_SYMBOL(ac97_restore_state);
  996. MODULE_LICENSE("GPL");