ad1848.h 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. #ifndef __SOUND_AD1848_H
  2. #define __SOUND_AD1848_H
  3. /*
  4. * Copyright (c) by Jaroslav Kysela <perex@suse.cz>
  5. * Definitions for AD1847/AD1848/CS4248 chips
  6. *
  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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  21. *
  22. */
  23. #include "pcm.h"
  24. #include <linux/interrupt.h>
  25. /* IO ports */
  26. #define AD1848P( codec, x ) ( (chip) -> port + c_d_c_AD1848##x )
  27. #define c_d_c_AD1848REGSEL 0
  28. #define c_d_c_AD1848REG 1
  29. #define c_d_c_AD1848STATUS 2
  30. #define c_d_c_AD1848PIO 3
  31. /* codec registers */
  32. #define AD1848_LEFT_INPUT 0x00 /* left input control */
  33. #define AD1848_RIGHT_INPUT 0x01 /* right input control */
  34. #define AD1848_AUX1_LEFT_INPUT 0x02 /* left AUX1 input control */
  35. #define AD1848_AUX1_RIGHT_INPUT 0x03 /* right AUX1 input control */
  36. #define AD1848_AUX2_LEFT_INPUT 0x04 /* left AUX2 input control */
  37. #define AD1848_AUX2_RIGHT_INPUT 0x05 /* right AUX2 input control */
  38. #define AD1848_LEFT_OUTPUT 0x06 /* left output control register */
  39. #define AD1848_RIGHT_OUTPUT 0x07 /* right output control register */
  40. #define AD1848_DATA_FORMAT 0x08 /* clock and data format - playback/capture - bits 7-0 MCE */
  41. #define AD1848_IFACE_CTRL 0x09 /* interface control - bits 7-2 MCE */
  42. #define AD1848_PIN_CTRL 0x0a /* pin control */
  43. #define AD1848_TEST_INIT 0x0b /* test and initialization */
  44. #define AD1848_MISC_INFO 0x0c /* miscellaneaous information */
  45. #define AD1848_LOOPBACK 0x0d /* loopback control */
  46. #define AD1848_DATA_UPR_CNT 0x0e /* playback/capture upper base count */
  47. #define AD1848_DATA_LWR_CNT 0x0f /* playback/capture lower base count */
  48. /* definitions for codec register select port - CODECP( REGSEL ) */
  49. #define AD1848_INIT 0x80 /* CODEC is initializing */
  50. #define AD1848_MCE 0x40 /* mode change enable */
  51. #define AD1848_TRD 0x20 /* transfer request disable */
  52. /* definitions for codec status register - CODECP( STATUS ) */
  53. #define AD1848_GLOBALIRQ 0x01 /* IRQ is active */
  54. /* definitions for AD1848_LEFT_INPUT and AD1848_RIGHT_INPUT registers */
  55. #define AD1848_ENABLE_MIC_GAIN 0x20
  56. #define AD1848_MIXS_LINE1 0x00
  57. #define AD1848_MIXS_AUX1 0x40
  58. #define AD1848_MIXS_LINE2 0x80
  59. #define AD1848_MIXS_ALL 0xc0
  60. /* definitions for clock and data format register - AD1848_PLAYBK_FORMAT */
  61. #define AD1848_LINEAR_8 0x00 /* 8-bit unsigned data */
  62. #define AD1848_ALAW_8 0x60 /* 8-bit A-law companded */
  63. #define AD1848_ULAW_8 0x20 /* 8-bit U-law companded */
  64. #define AD1848_LINEAR_16 0x40 /* 16-bit twos complement data - little endian */
  65. #define AD1848_STEREO 0x10 /* stereo mode */
  66. /* bits 3-1 define frequency divisor */
  67. #define AD1848_XTAL1 0x00 /* 24.576 crystal */
  68. #define AD1848_XTAL2 0x01 /* 16.9344 crystal */
  69. /* definitions for interface control register - AD1848_IFACE_CTRL */
  70. #define AD1848_CAPTURE_PIO 0x80 /* capture PIO enable */
  71. #define AD1848_PLAYBACK_PIO 0x40 /* playback PIO enable */
  72. #define AD1848_CALIB_MODE 0x18 /* calibration mode bits */
  73. #define AD1848_AUTOCALIB 0x08 /* auto calibrate */
  74. #define AD1848_SINGLE_DMA 0x04 /* use single DMA channel */
  75. #define AD1848_CAPTURE_ENABLE 0x02 /* capture enable */
  76. #define AD1848_PLAYBACK_ENABLE 0x01 /* playback enable */
  77. /* definitions for pin control register - AD1848_PIN_CTRL */
  78. #define AD1848_IRQ_ENABLE 0x02 /* enable IRQ */
  79. #define AD1848_XCTL1 0x40 /* external control #1 */
  80. #define AD1848_XCTL0 0x80 /* external control #0 */
  81. /* definitions for test and init register - AD1848_TEST_INIT */
  82. #define AD1848_CALIB_IN_PROGRESS 0x20 /* auto calibrate in progress */
  83. #define AD1848_DMA_REQUEST 0x10 /* DMA request in progress */
  84. /* defines for codec.mode */
  85. #define AD1848_MODE_NONE 0x0000
  86. #define AD1848_MODE_PLAY 0x0001
  87. #define AD1848_MODE_CAPTURE 0x0002
  88. #define AD1848_MODE_TIMER 0x0004
  89. #define AD1848_MODE_OPEN (AD1848_MODE_PLAY|AD1848_MODE_CAPTURE|AD1848_MODE_TIMER)
  90. #define AD1848_MODE_RUNNING 0x0010
  91. /* defines for codec.hardware */
  92. #define AD1848_HW_DETECT 0x0000 /* let AD1848 driver detect chip */
  93. #define AD1848_HW_AD1847 0x0001 /* AD1847 chip */
  94. #define AD1848_HW_AD1848 0x0002 /* AD1848 chip */
  95. #define AD1848_HW_CS4248 0x0003 /* CS4248 chip */
  96. #define AD1848_HW_CMI8330 0x0004 /* CMI8330 chip */
  97. #define AD1848_HW_THINKPAD 0x0005 /* Thinkpad 360/750/755 */
  98. /* IBM Thinkpad specific stuff */
  99. #define AD1848_THINKPAD_CTL_PORT1 0x15e8
  100. #define AD1848_THINKPAD_CTL_PORT2 0x15e9
  101. #define AD1848_THINKPAD_CS4248_ENABLE_BIT 0x02
  102. struct snd_ad1848 {
  103. unsigned long port; /* i/o port */
  104. struct resource *res_port;
  105. int irq; /* IRQ line */
  106. int dma; /* data DMA */
  107. unsigned short version; /* version of CODEC chip */
  108. unsigned short mode; /* see to AD1848_MODE_XXXX */
  109. unsigned short hardware; /* see to AD1848_HW_XXXX */
  110. unsigned short single_dma:1; /* forced single DMA mode (GUS 16-bit daughter board) or dma1 == dma2 */
  111. struct snd_pcm *pcm;
  112. struct snd_pcm_substream *playback_substream;
  113. struct snd_pcm_substream *capture_substream;
  114. struct snd_card *card;
  115. unsigned char image[32]; /* SGalaxy needs an access to extended registers */
  116. int mce_bit;
  117. int calibrate_mute;
  118. int dma_size;
  119. int thinkpad_flag; /* Thinkpad CS4248 needs some extra help */
  120. #ifdef CONFIG_PM
  121. void (*suspend)(struct snd_ad1848 *chip);
  122. void (*resume)(struct snd_ad1848 *chip);
  123. #endif
  124. spinlock_t reg_lock;
  125. struct semaphore open_mutex;
  126. };
  127. /* exported functions */
  128. void snd_ad1848_out(struct snd_ad1848 *chip, unsigned char reg, unsigned char value);
  129. int snd_ad1848_create(struct snd_card *card,
  130. unsigned long port,
  131. int irq, int dma,
  132. unsigned short hardware,
  133. struct snd_ad1848 ** chip);
  134. int snd_ad1848_pcm(struct snd_ad1848 * chip, int device, struct snd_pcm **rpcm);
  135. const struct snd_pcm_ops *snd_ad1848_get_pcm_ops(int direction);
  136. int snd_ad1848_mixer(struct snd_ad1848 * chip);
  137. /* exported mixer stuffs */
  138. enum { AD1848_MIX_SINGLE, AD1848_MIX_DOUBLE, AD1848_MIX_CAPTURE };
  139. #define AD1848_MIXVAL_SINGLE(reg, shift, mask, invert) \
  140. ((reg) | ((shift) << 8) | ((mask) << 16) | ((invert) << 24))
  141. #define AD1848_MIXVAL_DOUBLE(left_reg, right_reg, shift_left, shift_right, mask, invert) \
  142. ((left_reg) | ((right_reg) << 8) | ((shift_left) << 16) | ((shift_right) << 19) | ((mask) << 24) | ((invert) << 22))
  143. int snd_ad1848_add_ctl(struct snd_ad1848 *chip, const char *name, int index, int type, unsigned long value);
  144. /* for ease of use */
  145. struct ad1848_mix_elem {
  146. const char *name;
  147. int index;
  148. int type;
  149. unsigned long private_value;
  150. };
  151. #define AD1848_SINGLE(xname, xindex, reg, shift, mask, invert) \
  152. { .name = xname, \
  153. .index = xindex, \
  154. .type = AD1848_MIX_SINGLE, \
  155. .private_value = AD1848_MIXVAL_SINGLE(reg, shift, mask, invert) }
  156. #define AD1848_DOUBLE(xname, xindex, left_reg, right_reg, shift_left, shift_right, mask, invert) \
  157. { .name = xname, \
  158. .index = xindex, \
  159. .type = AD1848_MIX_DOUBLE, \
  160. .private_value = AD1848_MIXVAL_DOUBLE(left_reg, right_reg, shift_left, shift_right, mask, invert) }
  161. static inline int snd_ad1848_add_ctl_elem(struct snd_ad1848 *chip, const struct ad1848_mix_elem *c)
  162. {
  163. return snd_ad1848_add_ctl(chip, c->name, c->index, c->type, c->private_value);
  164. }
  165. #endif /* __SOUND_AD1848_H */