nm256.h 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295
  1. #ifndef _NM256_H_
  2. #define _NM256_H_
  3. #include <linux/spinlock.h>
  4. #include <linux/interrupt.h>
  5. #include "ac97.h"
  6. /* The revisions that we currently handle. */
  7. enum nm256rev {
  8. REV_NM256AV, REV_NM256ZX
  9. };
  10. /* Per-card structure. */
  11. struct nm256_info
  12. {
  13. /* Magic number used to verify that this struct is valid. */
  14. #define NM_MAGIC_SIG 0x55aa00ff
  15. int magsig;
  16. /* Revision number */
  17. enum nm256rev rev;
  18. struct ac97_hwint mdev;
  19. /* Our audio device numbers. */
  20. int dev[2];
  21. /* The # of times each device has been opened. (Should only be
  22. 0 or 1). */
  23. int opencnt[2];
  24. /* We use two devices, because we can do simultaneous play and record.
  25. This keeps track of which device is being used for what purpose;
  26. these are the actual device numbers. */
  27. int dev_for_play;
  28. int dev_for_record;
  29. spinlock_t lock;
  30. /* The mixer device. */
  31. int mixer_oss_dev;
  32. /*
  33. * Can only be opened once for each operation. These aren't set
  34. * until an actual I/O operation is performed; this allows one
  35. * device to be open for read/write without inhibiting I/O to
  36. * the other device.
  37. */
  38. int is_open_play;
  39. int is_open_record;
  40. /* Non-zero if we're currently playing a sample. */
  41. int playing;
  42. /* Ditto for recording a sample. */
  43. int recording;
  44. /* The two memory ports. */
  45. struct nm256_ports {
  46. /* Physical address of the port. */
  47. u32 physaddr;
  48. /* Our mapped-in pointer. */
  49. char __iomem *ptr;
  50. /* PTR's offset within the physical port. */
  51. u32 start_offset;
  52. /* And the offset of the end of the buffer. */
  53. u32 end_offset;
  54. } port[2];
  55. /* The following are offsets within memory port 1. */
  56. u32 coeffBuf;
  57. u32 allCoeffBuf;
  58. /* Record and playback buffers. */
  59. u32 abuf1, abuf2;
  60. /* Offset of the AC97 mixer in memory port 2. */
  61. u32 mixer;
  62. /* Offset of the mixer status register in memory port 2. */
  63. u32 mixer_status_offset;
  64. /* Non-zero if we have written initial values to the mixer. */
  65. u8 mixer_values_init;
  66. /*
  67. * Status mask bit; (*mixer_status_loc & mixer_status_mask) == 0 means
  68. * it's ready.
  69. */
  70. u16 mixer_status_mask;
  71. /* The sizes of the playback and record ring buffers. */
  72. u32 playbackBufferSize;
  73. u32 recordBufferSize;
  74. /* Are the coefficient values in the memory cache current? */
  75. u8 coeffsCurrent;
  76. /* For writes, the amount we last wrote. */
  77. u32 requested_amt;
  78. /* The start of the block currently playing. */
  79. u32 curPlayPos;
  80. /* The amount of data we were requested to record. */
  81. u32 requestedRecAmt;
  82. /* The offset of the currently-recording block. */
  83. u32 curRecPos;
  84. /* The destination buffer. */
  85. char *recBuf;
  86. /* Our IRQ number. */
  87. int irq;
  88. /* A flag indicating how many times we've grabbed the IRQ. */
  89. int has_irq;
  90. /* The card interrupt service routine. */
  91. irqreturn_t (*introutine) (int, void *, struct pt_regs *);
  92. /* Current audio config, cached. */
  93. struct sinfo {
  94. u32 samplerate;
  95. u8 bits;
  96. u8 stereo;
  97. } sinfo[2]; /* goes with each device */
  98. /* The cards are stored in a chain; this is the next card. */
  99. struct nm256_info *next_card;
  100. };
  101. /* Debug flag--bigger numbers mean more output. */
  102. extern int nm256_debug;
  103. /* The BIOS signature. */
  104. #define NM_SIGNATURE 0x4e4d0000
  105. /* Signature mask. */
  106. #define NM_SIG_MASK 0xffff0000
  107. /* Size of the second memory area. */
  108. #define NM_PORT2_SIZE 4096
  109. /* The base offset of the mixer in the second memory area. */
  110. #define NM_MIXER_OFFSET 0x600
  111. /* The maximum size of a coefficient entry. */
  112. #define NM_MAX_COEFFICIENT 0x5000
  113. /* The interrupt register. */
  114. #define NM_INT_REG 0xa04
  115. /* And its bits. */
  116. #define NM_PLAYBACK_INT 0x40
  117. #define NM_RECORD_INT 0x100
  118. #define NM_MISC_INT_1 0x4000
  119. #define NM_MISC_INT_2 0x1
  120. #define NM_ACK_INT(CARD, X) nm256_writePort16((CARD), 2, NM_INT_REG, (X) << 1)
  121. /* The AV's "mixer ready" status bit and location. */
  122. #define NM_MIXER_STATUS_OFFSET 0xa04
  123. #define NM_MIXER_READY_MASK 0x0800
  124. #define NM_MIXER_PRESENCE 0xa06
  125. #define NM_PRESENCE_MASK 0x0050
  126. #define NM_PRESENCE_VALUE 0x0040
  127. /*
  128. * For the ZX. It uses the same interrupt register, but it holds 32
  129. * bits instead of 16.
  130. */
  131. #define NM2_PLAYBACK_INT 0x10000
  132. #define NM2_RECORD_INT 0x80000
  133. #define NM2_MISC_INT_1 0x8
  134. #define NM2_MISC_INT_2 0x2
  135. #define NM2_ACK_INT(CARD, X) nm256_writePort32((CARD), 2, NM_INT_REG, (X))
  136. /* The ZX's "mixer ready" status bit and location. */
  137. #define NM2_MIXER_STATUS_OFFSET 0xa06
  138. #define NM2_MIXER_READY_MASK 0x0800
  139. /* The playback registers start from here. */
  140. #define NM_PLAYBACK_REG_OFFSET 0x0
  141. /* The record registers start from here. */
  142. #define NM_RECORD_REG_OFFSET 0x200
  143. /* The rate register is located 2 bytes from the start of the register area. */
  144. #define NM_RATE_REG_OFFSET 2
  145. /* Mono/stereo flag, number of bits on playback, and rate mask. */
  146. #define NM_RATE_STEREO 1
  147. #define NM_RATE_BITS_16 2
  148. #define NM_RATE_MASK 0xf0
  149. /* Playback enable register. */
  150. #define NM_PLAYBACK_ENABLE_REG (NM_PLAYBACK_REG_OFFSET + 0x1)
  151. #define NM_PLAYBACK_ENABLE_FLAG 1
  152. #define NM_PLAYBACK_ONESHOT 2
  153. #define NM_PLAYBACK_FREERUN 4
  154. /* Mutes the audio output. */
  155. #define NM_AUDIO_MUTE_REG (NM_PLAYBACK_REG_OFFSET + 0x18)
  156. #define NM_AUDIO_MUTE_LEFT 0x8000
  157. #define NM_AUDIO_MUTE_RIGHT 0x0080
  158. /* Recording enable register. */
  159. #define NM_RECORD_ENABLE_REG (NM_RECORD_REG_OFFSET + 0)
  160. #define NM_RECORD_ENABLE_FLAG 1
  161. #define NM_RECORD_FREERUN 2
  162. #define NM_RBUFFER_START (NM_RECORD_REG_OFFSET + 0x4)
  163. #define NM_RBUFFER_END (NM_RECORD_REG_OFFSET + 0x10)
  164. #define NM_RBUFFER_WMARK (NM_RECORD_REG_OFFSET + 0xc)
  165. #define NM_RBUFFER_CURRP (NM_RECORD_REG_OFFSET + 0x8)
  166. #define NM_PBUFFER_START (NM_PLAYBACK_REG_OFFSET + 0x4)
  167. #define NM_PBUFFER_END (NM_PLAYBACK_REG_OFFSET + 0x14)
  168. #define NM_PBUFFER_WMARK (NM_PLAYBACK_REG_OFFSET + 0xc)
  169. #define NM_PBUFFER_CURRP (NM_PLAYBACK_REG_OFFSET + 0x8)
  170. /* A few trivial routines to make it easier to work with the registers
  171. on the chip. */
  172. /* This is a common code portion used to fix up the port offsets. */
  173. #define NM_FIX_PORT \
  174. if (port < 1 || port > 2 || card == NULL) \
  175. return -1; \
  176. \
  177. if (offset < card->port[port - 1].start_offset \
  178. || offset >= card->port[port - 1].end_offset) { \
  179. printk (KERN_ERR "Bad access: port %d, offset 0x%x\n", port, offset); \
  180. return -1; \
  181. } \
  182. offset -= card->port[port - 1].start_offset;
  183. #define DEFwritePortX(X, func) \
  184. static inline int nm256_writePort##X (struct nm256_info *card,\
  185. int port, int offset, int value)\
  186. {\
  187. u##X __iomem *addr;\
  188. \
  189. if (nm256_debug > 1)\
  190. printk (KERN_DEBUG "Writing 0x%x to %d:0x%x\n", value, port, offset);\
  191. \
  192. NM_FIX_PORT;\
  193. \
  194. addr = (u##X __iomem *)(card->port[port - 1].ptr + offset);\
  195. func (value, addr);\
  196. return 0;\
  197. }
  198. DEFwritePortX (8, writeb)
  199. DEFwritePortX (16, writew)
  200. DEFwritePortX (32, writel)
  201. #define DEFreadPortX(X, func) \
  202. static inline u##X nm256_readPort##X (struct nm256_info *card,\
  203. int port, int offset)\
  204. {\
  205. u##X __iomem *addr;\
  206. \
  207. NM_FIX_PORT\
  208. \
  209. addr = (u##X __iomem *)(card->port[port - 1].ptr + offset);\
  210. return func(addr);\
  211. }
  212. DEFreadPortX (8, readb)
  213. DEFreadPortX (16, readw)
  214. DEFreadPortX (32, readl)
  215. static inline int
  216. nm256_writeBuffer8 (struct nm256_info *card, u8 *src, int port, int offset,
  217. int amt)
  218. {
  219. NM_FIX_PORT;
  220. memcpy_toio (card->port[port - 1].ptr + offset, src, amt);
  221. return 0;
  222. }
  223. static inline int
  224. nm256_readBuffer8 (struct nm256_info *card, u8 *dst, int port, int offset,
  225. int amt)
  226. {
  227. NM_FIX_PORT;
  228. memcpy_fromio (dst, card->port[port - 1].ptr + offset, amt);
  229. return 0;
  230. }
  231. /* Returns a non-zero value if we should use the coefficient cache. */
  232. extern int nm256_cachedCoefficients (struct nm256_info *card);
  233. #endif
  234. /*
  235. * Local variables:
  236. * c-basic-offset: 4
  237. * End:
  238. */