nm256.h 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292
  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. /* The BIOS signature. */
  102. #define NM_SIGNATURE 0x4e4d0000
  103. /* Signature mask. */
  104. #define NM_SIG_MASK 0xffff0000
  105. /* Size of the second memory area. */
  106. #define NM_PORT2_SIZE 4096
  107. /* The base offset of the mixer in the second memory area. */
  108. #define NM_MIXER_OFFSET 0x600
  109. /* The maximum size of a coefficient entry. */
  110. #define NM_MAX_COEFFICIENT 0x5000
  111. /* The interrupt register. */
  112. #define NM_INT_REG 0xa04
  113. /* And its bits. */
  114. #define NM_PLAYBACK_INT 0x40
  115. #define NM_RECORD_INT 0x100
  116. #define NM_MISC_INT_1 0x4000
  117. #define NM_MISC_INT_2 0x1
  118. #define NM_ACK_INT(CARD, X) nm256_writePort16((CARD), 2, NM_INT_REG, (X) << 1)
  119. /* The AV's "mixer ready" status bit and location. */
  120. #define NM_MIXER_STATUS_OFFSET 0xa04
  121. #define NM_MIXER_READY_MASK 0x0800
  122. #define NM_MIXER_PRESENCE 0xa06
  123. #define NM_PRESENCE_MASK 0x0050
  124. #define NM_PRESENCE_VALUE 0x0040
  125. /*
  126. * For the ZX. It uses the same interrupt register, but it holds 32
  127. * bits instead of 16.
  128. */
  129. #define NM2_PLAYBACK_INT 0x10000
  130. #define NM2_RECORD_INT 0x80000
  131. #define NM2_MISC_INT_1 0x8
  132. #define NM2_MISC_INT_2 0x2
  133. #define NM2_ACK_INT(CARD, X) nm256_writePort32((CARD), 2, NM_INT_REG, (X))
  134. /* The ZX's "mixer ready" status bit and location. */
  135. #define NM2_MIXER_STATUS_OFFSET 0xa06
  136. #define NM2_MIXER_READY_MASK 0x0800
  137. /* The playback registers start from here. */
  138. #define NM_PLAYBACK_REG_OFFSET 0x0
  139. /* The record registers start from here. */
  140. #define NM_RECORD_REG_OFFSET 0x200
  141. /* The rate register is located 2 bytes from the start of the register area. */
  142. #define NM_RATE_REG_OFFSET 2
  143. /* Mono/stereo flag, number of bits on playback, and rate mask. */
  144. #define NM_RATE_STEREO 1
  145. #define NM_RATE_BITS_16 2
  146. #define NM_RATE_MASK 0xf0
  147. /* Playback enable register. */
  148. #define NM_PLAYBACK_ENABLE_REG (NM_PLAYBACK_REG_OFFSET + 0x1)
  149. #define NM_PLAYBACK_ENABLE_FLAG 1
  150. #define NM_PLAYBACK_ONESHOT 2
  151. #define NM_PLAYBACK_FREERUN 4
  152. /* Mutes the audio output. */
  153. #define NM_AUDIO_MUTE_REG (NM_PLAYBACK_REG_OFFSET + 0x18)
  154. #define NM_AUDIO_MUTE_LEFT 0x8000
  155. #define NM_AUDIO_MUTE_RIGHT 0x0080
  156. /* Recording enable register. */
  157. #define NM_RECORD_ENABLE_REG (NM_RECORD_REG_OFFSET + 0)
  158. #define NM_RECORD_ENABLE_FLAG 1
  159. #define NM_RECORD_FREERUN 2
  160. #define NM_RBUFFER_START (NM_RECORD_REG_OFFSET + 0x4)
  161. #define NM_RBUFFER_END (NM_RECORD_REG_OFFSET + 0x10)
  162. #define NM_RBUFFER_WMARK (NM_RECORD_REG_OFFSET + 0xc)
  163. #define NM_RBUFFER_CURRP (NM_RECORD_REG_OFFSET + 0x8)
  164. #define NM_PBUFFER_START (NM_PLAYBACK_REG_OFFSET + 0x4)
  165. #define NM_PBUFFER_END (NM_PLAYBACK_REG_OFFSET + 0x14)
  166. #define NM_PBUFFER_WMARK (NM_PLAYBACK_REG_OFFSET + 0xc)
  167. #define NM_PBUFFER_CURRP (NM_PLAYBACK_REG_OFFSET + 0x8)
  168. /* A few trivial routines to make it easier to work with the registers
  169. on the chip. */
  170. /* This is a common code portion used to fix up the port offsets. */
  171. #define NM_FIX_PORT \
  172. if (port < 1 || port > 2 || card == NULL) \
  173. return -1; \
  174. \
  175. if (offset < card->port[port - 1].start_offset \
  176. || offset >= card->port[port - 1].end_offset) { \
  177. printk (KERN_ERR "Bad access: port %d, offset 0x%x\n", port, offset); \
  178. return -1; \
  179. } \
  180. offset -= card->port[port - 1].start_offset;
  181. #define DEFwritePortX(X, func) \
  182. static inline int nm256_writePort##X (struct nm256_info *card,\
  183. int port, int offset, int value)\
  184. {\
  185. u##X __iomem *addr;\
  186. \
  187. if (nm256_debug > 1)\
  188. printk (KERN_DEBUG "Writing 0x%x to %d:0x%x\n", value, port, offset);\
  189. \
  190. NM_FIX_PORT;\
  191. \
  192. addr = (u##X __iomem *)(card->port[port - 1].ptr + offset);\
  193. func (value, addr);\
  194. return 0;\
  195. }
  196. DEFwritePortX (8, writeb)
  197. DEFwritePortX (16, writew)
  198. DEFwritePortX (32, writel)
  199. #define DEFreadPortX(X, func) \
  200. static inline u##X nm256_readPort##X (struct nm256_info *card,\
  201. int port, int offset)\
  202. {\
  203. u##X __iomem *addr;\
  204. \
  205. NM_FIX_PORT\
  206. \
  207. addr = (u##X __iomem *)(card->port[port - 1].ptr + offset);\
  208. return func(addr);\
  209. }
  210. DEFreadPortX (8, readb)
  211. DEFreadPortX (16, readw)
  212. DEFreadPortX (32, readl)
  213. static inline int
  214. nm256_writeBuffer8 (struct nm256_info *card, u8 *src, int port, int offset,
  215. int amt)
  216. {
  217. NM_FIX_PORT;
  218. memcpy_toio (card->port[port - 1].ptr + offset, src, amt);
  219. return 0;
  220. }
  221. static inline int
  222. nm256_readBuffer8 (struct nm256_info *card, u8 *dst, int port, int offset,
  223. int amt)
  224. {
  225. NM_FIX_PORT;
  226. memcpy_fromio (dst, card->port[port - 1].ptr + offset, amt);
  227. return 0;
  228. }
  229. /* Returns a non-zero value if we should use the coefficient cache. */
  230. static int nm256_cachedCoefficients (struct nm256_info *card);
  231. #endif
  232. /*
  233. * Local variables:
  234. * c-basic-offset: 4
  235. * End:
  236. */