ymfpci.h 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361
  1. #ifndef __YMFPCI_H
  2. #define __YMFPCI_H
  3. /*
  4. * Copyright (c) by Jaroslav Kysela <perex@suse.cz>
  5. * Definitions for Yahama YMF724/740/744/754 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., 675 Mass Ave, Cambridge, MA 02139, USA.
  21. *
  22. */
  23. #include <linux/config.h>
  24. #include <linux/mutex.h>
  25. /*
  26. * Direct registers
  27. */
  28. /* #define YMFREG(codec, reg) (codec->port + YDSXGR_##reg) */
  29. #define YDSXGR_INTFLAG 0x0004
  30. #define YDSXGR_ACTIVITY 0x0006
  31. #define YDSXGR_GLOBALCTRL 0x0008
  32. #define YDSXGR_ZVCTRL 0x000A
  33. #define YDSXGR_TIMERCTRL 0x0010
  34. #define YDSXGR_TIMERCTRL_TEN 0x0001
  35. #define YDSXGR_TIMERCTRL_TIEN 0x0002
  36. #define YDSXGR_TIMERCOUNT 0x0012
  37. #define YDSXGR_SPDIFOUTCTRL 0x0018
  38. #define YDSXGR_SPDIFOUTSTATUS 0x001C
  39. #define YDSXGR_EEPROMCTRL 0x0020
  40. #define YDSXGR_SPDIFINCTRL 0x0034
  41. #define YDSXGR_SPDIFINSTATUS 0x0038
  42. #define YDSXGR_DSPPROGRAMDL 0x0048
  43. #define YDSXGR_DLCNTRL 0x004C
  44. #define YDSXGR_GPIOININTFLAG 0x0050
  45. #define YDSXGR_GPIOININTENABLE 0x0052
  46. #define YDSXGR_GPIOINSTATUS 0x0054
  47. #define YDSXGR_GPIOOUTCTRL 0x0056
  48. #define YDSXGR_GPIOFUNCENABLE 0x0058
  49. #define YDSXGR_GPIOTYPECONFIG 0x005A
  50. #define YDSXGR_AC97CMDDATA 0x0060
  51. #define YDSXGR_AC97CMDADR 0x0062
  52. #define YDSXGR_PRISTATUSDATA 0x0064
  53. #define YDSXGR_PRISTATUSADR 0x0066
  54. #define YDSXGR_SECSTATUSDATA 0x0068
  55. #define YDSXGR_SECSTATUSADR 0x006A
  56. #define YDSXGR_SECCONFIG 0x0070
  57. #define YDSXGR_LEGACYOUTVOL 0x0080
  58. #define YDSXGR_LEGACYOUTVOLL 0x0080
  59. #define YDSXGR_LEGACYOUTVOLR 0x0082
  60. #define YDSXGR_NATIVEDACOUTVOL 0x0084
  61. #define YDSXGR_NATIVEDACOUTVOLL 0x0084
  62. #define YDSXGR_NATIVEDACOUTVOLR 0x0086
  63. #define YDSXGR_SPDIFOUTVOL 0x0088
  64. #define YDSXGR_SPDIFOUTVOLL 0x0088
  65. #define YDSXGR_SPDIFOUTVOLR 0x008A
  66. #define YDSXGR_AC3OUTVOL 0x008C
  67. #define YDSXGR_AC3OUTVOLL 0x008C
  68. #define YDSXGR_AC3OUTVOLR 0x008E
  69. #define YDSXGR_PRIADCOUTVOL 0x0090
  70. #define YDSXGR_PRIADCOUTVOLL 0x0090
  71. #define YDSXGR_PRIADCOUTVOLR 0x0092
  72. #define YDSXGR_LEGACYLOOPVOL 0x0094
  73. #define YDSXGR_LEGACYLOOPVOLL 0x0094
  74. #define YDSXGR_LEGACYLOOPVOLR 0x0096
  75. #define YDSXGR_NATIVEDACLOOPVOL 0x0098
  76. #define YDSXGR_NATIVEDACLOOPVOLL 0x0098
  77. #define YDSXGR_NATIVEDACLOOPVOLR 0x009A
  78. #define YDSXGR_SPDIFLOOPVOL 0x009C
  79. #define YDSXGR_SPDIFLOOPVOLL 0x009E
  80. #define YDSXGR_SPDIFLOOPVOLR 0x009E
  81. #define YDSXGR_AC3LOOPVOL 0x00A0
  82. #define YDSXGR_AC3LOOPVOLL 0x00A0
  83. #define YDSXGR_AC3LOOPVOLR 0x00A2
  84. #define YDSXGR_PRIADCLOOPVOL 0x00A4
  85. #define YDSXGR_PRIADCLOOPVOLL 0x00A4
  86. #define YDSXGR_PRIADCLOOPVOLR 0x00A6
  87. #define YDSXGR_NATIVEADCINVOL 0x00A8
  88. #define YDSXGR_NATIVEADCINVOLL 0x00A8
  89. #define YDSXGR_NATIVEADCINVOLR 0x00AA
  90. #define YDSXGR_NATIVEDACINVOL 0x00AC
  91. #define YDSXGR_NATIVEDACINVOLL 0x00AC
  92. #define YDSXGR_NATIVEDACINVOLR 0x00AE
  93. #define YDSXGR_BUF441OUTVOL 0x00B0
  94. #define YDSXGR_BUF441OUTVOLL 0x00B0
  95. #define YDSXGR_BUF441OUTVOLR 0x00B2
  96. #define YDSXGR_BUF441LOOPVOL 0x00B4
  97. #define YDSXGR_BUF441LOOPVOLL 0x00B4
  98. #define YDSXGR_BUF441LOOPVOLR 0x00B6
  99. #define YDSXGR_SPDIFOUTVOL2 0x00B8
  100. #define YDSXGR_SPDIFOUTVOL2L 0x00B8
  101. #define YDSXGR_SPDIFOUTVOL2R 0x00BA
  102. #define YDSXGR_SPDIFLOOPVOL2 0x00BC
  103. #define YDSXGR_SPDIFLOOPVOL2L 0x00BC
  104. #define YDSXGR_SPDIFLOOPVOL2R 0x00BE
  105. #define YDSXGR_ADCSLOTSR 0x00C0
  106. #define YDSXGR_RECSLOTSR 0x00C4
  107. #define YDSXGR_ADCFORMAT 0x00C8
  108. #define YDSXGR_RECFORMAT 0x00CC
  109. #define YDSXGR_P44SLOTSR 0x00D0
  110. #define YDSXGR_STATUS 0x0100
  111. #define YDSXGR_CTRLSELECT 0x0104
  112. #define YDSXGR_MODE 0x0108
  113. #define YDSXGR_SAMPLECOUNT 0x010C
  114. #define YDSXGR_NUMOFSAMPLES 0x0110
  115. #define YDSXGR_CONFIG 0x0114
  116. #define YDSXGR_PLAYCTRLSIZE 0x0140
  117. #define YDSXGR_RECCTRLSIZE 0x0144
  118. #define YDSXGR_EFFCTRLSIZE 0x0148
  119. #define YDSXGR_WORKSIZE 0x014C
  120. #define YDSXGR_MAPOFREC 0x0150
  121. #define YDSXGR_MAPOFEFFECT 0x0154
  122. #define YDSXGR_PLAYCTRLBASE 0x0158
  123. #define YDSXGR_RECCTRLBASE 0x015C
  124. #define YDSXGR_EFFCTRLBASE 0x0160
  125. #define YDSXGR_WORKBASE 0x0164
  126. #define YDSXGR_DSPINSTRAM 0x1000
  127. #define YDSXGR_CTRLINSTRAM 0x4000
  128. #define YDSXG_AC97READCMD 0x8000
  129. #define YDSXG_AC97WRITECMD 0x0000
  130. #define PCIR_LEGCTRL 0x40
  131. #define PCIR_ELEGCTRL 0x42
  132. #define PCIR_DSXGCTRL 0x48
  133. #define PCIR_DSXPWRCTRL1 0x4a
  134. #define PCIR_DSXPWRCTRL2 0x4e
  135. #define PCIR_OPLADR 0x60
  136. #define PCIR_SBADR 0x62
  137. #define PCIR_MPUADR 0x64
  138. #define YDSXG_DSPLENGTH 0x0080
  139. #define YDSXG_CTRLLENGTH 0x3000
  140. #define YDSXG_DEFAULT_WORK_SIZE 0x0400
  141. #define YDSXG_PLAYBACK_VOICES 64
  142. #define YDSXG_CAPTURE_VOICES 2
  143. #define YDSXG_EFFECT_VOICES 5
  144. /* maxinum number of AC97 codecs connected, AC97 2.0 defined 4 */
  145. #define NR_AC97 2
  146. #define YMF_SAMPF 256 /* Samples per frame @48000 */
  147. /*
  148. * The slot/voice control bank (2 of these per voice)
  149. */
  150. typedef struct stru_ymfpci_playback_bank {
  151. u32 format;
  152. u32 loop_default;
  153. u32 base; /* 32-bit address */
  154. u32 loop_start; /* 32-bit offset */
  155. u32 loop_end; /* 32-bit offset */
  156. u32 loop_frac; /* 8-bit fraction - loop_start */
  157. u32 delta_end; /* pitch delta end */
  158. u32 lpfK_end;
  159. u32 eg_gain_end;
  160. u32 left_gain_end;
  161. u32 right_gain_end;
  162. u32 eff1_gain_end;
  163. u32 eff2_gain_end;
  164. u32 eff3_gain_end;
  165. u32 lpfQ;
  166. u32 status; /* P3: Always 0 for some reason. */
  167. u32 num_of_frames;
  168. u32 loop_count;
  169. u32 start; /* P3: J. reads this to know where chip is. */
  170. u32 start_frac;
  171. u32 delta;
  172. u32 lpfK;
  173. u32 eg_gain;
  174. u32 left_gain;
  175. u32 right_gain;
  176. u32 eff1_gain;
  177. u32 eff2_gain;
  178. u32 eff3_gain;
  179. u32 lpfD1;
  180. u32 lpfD2;
  181. } ymfpci_playback_bank_t;
  182. typedef struct stru_ymfpci_capture_bank {
  183. u32 base; /* 32-bit address (aligned at 4) */
  184. u32 loop_end; /* size in BYTES (aligned at 4) */
  185. u32 start; /* 32-bit offset */
  186. u32 num_of_loops; /* counter */
  187. } ymfpci_capture_bank_t;
  188. typedef struct stru_ymfpci_effect_bank {
  189. u32 base; /* 32-bit address */
  190. u32 loop_end; /* 32-bit offset */
  191. u32 start; /* 32-bit offset */
  192. u32 temp;
  193. } ymfpci_effect_bank_t;
  194. typedef struct ymf_voice ymfpci_voice_t;
  195. /*
  196. * Throughout the code Yaroslav names YMF unit pointer "codec"
  197. * even though it does not correspond to any codec. Must be historic.
  198. * We replace it with "unit" over time.
  199. * AC97 parts use "codec" to denote a codec, naturally.
  200. */
  201. typedef struct ymf_unit ymfpci_t;
  202. typedef enum {
  203. YMFPCI_PCM,
  204. YMFPCI_SYNTH,
  205. YMFPCI_MIDI
  206. } ymfpci_voice_type_t;
  207. struct ymf_voice {
  208. // ymfpci_t *codec;
  209. int number;
  210. char use, pcm, synth, midi; // bool
  211. ymfpci_playback_bank_t *bank;
  212. struct ymf_pcm *ypcm;
  213. dma_addr_t bank_ba;
  214. };
  215. struct ymf_capture {
  216. // struct ymf_unit *unit;
  217. int use;
  218. ymfpci_capture_bank_t *bank;
  219. struct ymf_pcm *ypcm;
  220. };
  221. struct ymf_unit {
  222. u8 rev; /* PCI revision */
  223. void __iomem *reg_area_virt;
  224. void *dma_area_va;
  225. dma_addr_t dma_area_ba;
  226. unsigned int dma_area_size;
  227. dma_addr_t bank_base_capture;
  228. dma_addr_t bank_base_effect;
  229. dma_addr_t work_base;
  230. unsigned int work_size;
  231. u32 *ctrl_playback;
  232. dma_addr_t ctrl_playback_ba;
  233. ymfpci_playback_bank_t *bank_playback[YDSXG_PLAYBACK_VOICES][2];
  234. ymfpci_capture_bank_t *bank_capture[YDSXG_CAPTURE_VOICES][2];
  235. ymfpci_effect_bank_t *bank_effect[YDSXG_EFFECT_VOICES][2];
  236. int start_count;
  237. int suspended;
  238. u32 active_bank;
  239. struct ymf_voice voices[YDSXG_PLAYBACK_VOICES];
  240. struct ymf_capture capture[YDSXG_CAPTURE_VOICES];
  241. struct ac97_codec *ac97_codec[NR_AC97];
  242. u16 ac97_features;
  243. struct pci_dev *pci;
  244. #ifdef CONFIG_SOUND_YMFPCI_LEGACY
  245. /* legacy hardware resources */
  246. unsigned int iosynth, iomidi;
  247. struct address_info opl3_data, mpu_data;
  248. #endif
  249. spinlock_t reg_lock;
  250. spinlock_t voice_lock;
  251. spinlock_t ac97_lock;
  252. /* soundcore stuff */
  253. int dev_audio;
  254. struct mutex open_mutex;
  255. struct list_head ymf_devs;
  256. struct list_head states; /* List of states for this unit */
  257. };
  258. struct ymf_dmabuf {
  259. dma_addr_t dma_addr;
  260. void *rawbuf;
  261. unsigned buforder;
  262. /* OSS buffer management stuff */
  263. unsigned numfrag;
  264. unsigned fragshift;
  265. /* our buffer acts like a circular ring */
  266. unsigned hwptr; /* where dma last started */
  267. unsigned swptr; /* where driver last clear/filled */
  268. int count; /* fill count */
  269. unsigned total_bytes; /* total bytes dmaed by hardware */
  270. wait_queue_head_t wait; /* put process on wait queue when no more space in buffer */
  271. /* redundant, but makes calculations easier */
  272. unsigned fragsize;
  273. unsigned dmasize; /* Total rawbuf[] size */
  274. /* OSS stuff */
  275. unsigned mapped:1;
  276. unsigned ready:1;
  277. unsigned ossfragshift;
  278. int ossmaxfrags;
  279. unsigned subdivision;
  280. };
  281. struct ymf_pcm_format {
  282. int format; /* OSS format */
  283. int rate; /* rate in Hz */
  284. int voices; /* number of voices */
  285. int shift; /* redundant, computed from the above */
  286. };
  287. typedef enum {
  288. PLAYBACK_VOICE,
  289. CAPTURE_REC,
  290. CAPTURE_AC97,
  291. EFFECT_DRY_LEFT,
  292. EFFECT_DRY_RIGHT,
  293. EFFECT_EFF1,
  294. EFFECT_EFF2,
  295. EFFECT_EFF3
  296. } ymfpci_pcm_type_t;
  297. /* This is variant record, but we hate unions. Little waste on pointers []. */
  298. struct ymf_pcm {
  299. ymfpci_pcm_type_t type;
  300. struct ymf_state *state;
  301. ymfpci_voice_t *voices[2];
  302. int capture_bank_number;
  303. struct ymf_dmabuf dmabuf;
  304. int running;
  305. int spdif;
  306. };
  307. /*
  308. * "Software" or virtual channel, an instance of opened /dev/dsp.
  309. * It may have two physical channels (pcms) for duplex operations.
  310. */
  311. struct ymf_state {
  312. struct list_head chain;
  313. struct ymf_unit *unit; /* backpointer */
  314. struct ymf_pcm rpcm, wpcm;
  315. struct ymf_pcm_format format;
  316. };
  317. #endif /* __YMFPCI_H */