vx_core.h 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551
  1. /*
  2. * Driver for Digigram VX soundcards
  3. *
  4. * Hardware core part
  5. *
  6. * Copyright (c) 2002 by Takashi Iwai <tiwai@suse.de>
  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. #ifndef __SOUND_VX_COMMON_H
  23. #define __SOUND_VX_COMMON_H
  24. #include <sound/pcm.h>
  25. #include <sound/hwdep.h>
  26. #include <linux/interrupt.h>
  27. struct firmware;
  28. struct device;
  29. #define VX_DRIVER_VERSION 0x010000 /* 1.0.0 */
  30. /*
  31. */
  32. #define SIZE_MAX_CMD 0x10
  33. #define SIZE_MAX_STATUS 0x10
  34. struct vx_rmh {
  35. u16 LgCmd; /* length of the command to send (WORDs) */
  36. u16 LgStat; /* length of the status received (WORDs) */
  37. u32 Cmd[SIZE_MAX_CMD];
  38. u32 Stat[SIZE_MAX_STATUS];
  39. u16 DspStat; /* status type, RMP_SSIZE_XXX */
  40. };
  41. typedef u64 pcx_time_t;
  42. #define VX_MAX_PIPES 16
  43. #define VX_MAX_PERIODS 32
  44. #define VX_MAX_CODECS 2
  45. struct vx_ibl_info {
  46. int size; /* the current IBL size (0 = query) in bytes */
  47. int max_size; /* max. IBL size in bytes */
  48. int min_size; /* min. IBL size in bytes */
  49. int granularity; /* granularity */
  50. };
  51. struct vx_pipe {
  52. int number;
  53. unsigned int is_capture: 1;
  54. unsigned int data_mode: 1;
  55. unsigned int running: 1;
  56. unsigned int prepared: 1;
  57. int channels;
  58. unsigned int differed_type;
  59. pcx_time_t pcx_time;
  60. struct snd_pcm_substream *substream;
  61. int hbuf_size; /* H-buffer size in bytes */
  62. int buffer_bytes; /* the ALSA pcm buffer size in bytes */
  63. int period_bytes; /* the ALSA pcm period size in bytes */
  64. int hw_ptr; /* the current hardware pointer in bytes */
  65. int position; /* the current position in frames (playback only) */
  66. int transferred; /* the transferred size (per period) in frames */
  67. int align; /* size of alignment */
  68. u64 cur_count; /* current sample position (for playback) */
  69. unsigned int references; /* an output pipe may be used for monitoring and/or playback */
  70. struct vx_pipe *monitoring_pipe; /* pointer to the monitoring pipe (capture pipe only)*/
  71. struct tasklet_struct start_tq;
  72. };
  73. struct vx_core;
  74. struct snd_vx_ops {
  75. /* low-level i/o */
  76. unsigned char (*in8)(struct vx_core *chip, int reg);
  77. unsigned int (*in32)(struct vx_core *chip, int reg);
  78. void (*out8)(struct vx_core *chip, int reg, unsigned char val);
  79. void (*out32)(struct vx_core *chip, int reg, unsigned int val);
  80. /* irq */
  81. int (*test_and_ack)(struct vx_core *chip);
  82. void (*validate_irq)(struct vx_core *chip, int enable);
  83. /* codec */
  84. void (*write_codec)(struct vx_core *chip, int codec, unsigned int data);
  85. void (*akm_write)(struct vx_core *chip, int reg, unsigned int data);
  86. void (*reset_codec)(struct vx_core *chip);
  87. void (*change_audio_source)(struct vx_core *chip, int src);
  88. void (*set_clock_source)(struct vx_core *chp, int src);
  89. /* chip init */
  90. int (*load_dsp)(struct vx_core *chip, int idx, const struct firmware *fw);
  91. void (*reset_dsp)(struct vx_core *chip);
  92. void (*reset_board)(struct vx_core *chip, int cold_reset);
  93. int (*add_controls)(struct vx_core *chip);
  94. /* pcm */
  95. void (*dma_write)(struct vx_core *chip, struct snd_pcm_runtime *runtime,
  96. struct vx_pipe *pipe, int count);
  97. void (*dma_read)(struct vx_core *chip, struct snd_pcm_runtime *runtime,
  98. struct vx_pipe *pipe, int count);
  99. };
  100. struct snd_vx_hardware {
  101. const char *name;
  102. int type; /* VX_TYPE_XXX */
  103. /* hardware specs */
  104. unsigned int num_codecs;
  105. unsigned int num_ins;
  106. unsigned int num_outs;
  107. unsigned int output_level_max;
  108. const unsigned int *output_level_db_scale;
  109. };
  110. /* hwdep id string */
  111. #define SND_VX_HWDEP_ID "VX Loader"
  112. /* hardware type */
  113. enum {
  114. /* VX222 PCI */
  115. VX_TYPE_BOARD, /* old VX222 PCI */
  116. VX_TYPE_V2, /* VX222 V2 PCI */
  117. VX_TYPE_MIC, /* VX222 Mic PCI */
  118. /* VX-pocket */
  119. VX_TYPE_VXPOCKET, /* VXpocket V2 */
  120. VX_TYPE_VXP440, /* VXpocket 440 */
  121. VX_TYPE_NUMS
  122. };
  123. /* chip status */
  124. enum {
  125. VX_STAT_XILINX_LOADED = (1 << 0), /* devices are registered */
  126. VX_STAT_DEVICE_INIT = (1 << 1), /* devices are registered */
  127. VX_STAT_CHIP_INIT = (1 << 2), /* all operational */
  128. VX_STAT_IN_SUSPEND = (1 << 10), /* in suspend phase */
  129. VX_STAT_IS_STALE = (1 << 15) /* device is stale */
  130. };
  131. /* min/max values for analog output for old codecs */
  132. #define VX_ANALOG_OUT_LEVEL_MAX 0xe3
  133. struct vx_core {
  134. /* ALSA stuff */
  135. struct snd_card *card;
  136. struct snd_pcm *pcm[VX_MAX_CODECS];
  137. int type; /* VX_TYPE_XXX */
  138. int irq;
  139. /* ports are defined externally */
  140. /* low-level functions */
  141. struct snd_vx_hardware *hw;
  142. struct snd_vx_ops *ops;
  143. spinlock_t lock;
  144. spinlock_t irq_lock;
  145. struct tasklet_struct tq;
  146. unsigned int chip_status;
  147. unsigned int pcm_running;
  148. struct device *dev;
  149. struct snd_hwdep *hwdep;
  150. struct vx_rmh irq_rmh; /* RMH used in interrupts */
  151. unsigned int audio_info; /* see VX_AUDIO_INFO */
  152. unsigned int audio_ins;
  153. unsigned int audio_outs;
  154. struct vx_pipe **playback_pipes;
  155. struct vx_pipe **capture_pipes;
  156. /* clock and audio sources */
  157. unsigned int audio_source; /* current audio input source */
  158. unsigned int audio_source_target;
  159. unsigned int clock_mode; /* clock mode (VX_CLOCK_MODE_XXX) */
  160. unsigned int clock_source; /* current clock source (INTERNAL_QUARTZ or UER_SYNC) */
  161. unsigned int freq; /* current frequency */
  162. unsigned int freq_detected; /* detected frequency from digital in */
  163. unsigned int uer_detected; /* VX_UER_MODE_XXX */
  164. unsigned int uer_bits; /* IEC958 status bits */
  165. struct vx_ibl_info ibl; /* IBL information */
  166. /* mixer setting */
  167. int output_level[VX_MAX_CODECS][2]; /* analog output level */
  168. int audio_gain[2][4]; /* digital audio level (playback/capture) */
  169. unsigned char audio_active[4]; /* mute/unmute on digital playback */
  170. int audio_monitor[4]; /* playback hw-monitor level */
  171. unsigned char audio_monitor_active[4]; /* playback hw-monitor mute/unmute */
  172. struct mutex mixer_mutex;
  173. const struct firmware *firmware[4]; /* loaded firmware data */
  174. };
  175. /*
  176. * constructor
  177. */
  178. struct vx_core *snd_vx_create(struct snd_card *card, struct snd_vx_hardware *hw,
  179. struct snd_vx_ops *ops, int extra_size);
  180. int snd_vx_setup_firmware(struct vx_core *chip);
  181. int snd_vx_load_boot_image(struct vx_core *chip, const struct firmware *dsp);
  182. int snd_vx_dsp_boot(struct vx_core *chip, const struct firmware *dsp);
  183. int snd_vx_dsp_load(struct vx_core *chip, const struct firmware *dsp);
  184. void snd_vx_free_firmware(struct vx_core *chip);
  185. /*
  186. * interrupt handler; exported for pcmcia
  187. */
  188. irqreturn_t snd_vx_irq_handler(int irq, void *dev);
  189. /*
  190. * lowlevel functions
  191. */
  192. static inline int vx_test_and_ack(struct vx_core *chip)
  193. {
  194. return chip->ops->test_and_ack(chip);
  195. }
  196. static inline void vx_validate_irq(struct vx_core *chip, int enable)
  197. {
  198. chip->ops->validate_irq(chip, enable);
  199. }
  200. static inline unsigned char snd_vx_inb(struct vx_core *chip, int reg)
  201. {
  202. return chip->ops->in8(chip, reg);
  203. }
  204. static inline unsigned int snd_vx_inl(struct vx_core *chip, int reg)
  205. {
  206. return chip->ops->in32(chip, reg);
  207. }
  208. static inline void snd_vx_outb(struct vx_core *chip, int reg, unsigned char val)
  209. {
  210. chip->ops->out8(chip, reg, val);
  211. }
  212. static inline void snd_vx_outl(struct vx_core *chip, int reg, unsigned int val)
  213. {
  214. chip->ops->out32(chip, reg, val);
  215. }
  216. #define vx_inb(chip,reg) snd_vx_inb(chip, VX_##reg)
  217. #define vx_outb(chip,reg,val) snd_vx_outb(chip, VX_##reg,val)
  218. #define vx_inl(chip,reg) snd_vx_inl(chip, VX_##reg)
  219. #define vx_outl(chip,reg,val) snd_vx_outl(chip, VX_##reg,val)
  220. static inline void vx_reset_dsp(struct vx_core *chip)
  221. {
  222. chip->ops->reset_dsp(chip);
  223. }
  224. int vx_send_msg(struct vx_core *chip, struct vx_rmh *rmh);
  225. int vx_send_msg_nolock(struct vx_core *chip, struct vx_rmh *rmh);
  226. int vx_send_rih(struct vx_core *chip, int cmd);
  227. int vx_send_rih_nolock(struct vx_core *chip, int cmd);
  228. void vx_reset_codec(struct vx_core *chip, int cold_reset);
  229. /*
  230. * check the bit on the specified register
  231. * returns zero if a bit matches, or a negative error code.
  232. * exported for vxpocket driver
  233. */
  234. int snd_vx_check_reg_bit(struct vx_core *chip, int reg, int mask, int bit, int time);
  235. #define vx_check_isr(chip,mask,bit,time) snd_vx_check_reg_bit(chip, VX_ISR, mask, bit, time)
  236. #define vx_wait_isr_bit(chip,bit) vx_check_isr(chip, bit, bit, 200)
  237. #define vx_wait_for_rx_full(chip) vx_wait_isr_bit(chip, ISR_RX_FULL)
  238. /*
  239. * pseudo-DMA transfer
  240. */
  241. static inline void vx_pseudo_dma_write(struct vx_core *chip, struct snd_pcm_runtime *runtime,
  242. struct vx_pipe *pipe, int count)
  243. {
  244. chip->ops->dma_write(chip, runtime, pipe, count);
  245. }
  246. static inline void vx_pseudo_dma_read(struct vx_core *chip, struct snd_pcm_runtime *runtime,
  247. struct vx_pipe *pipe, int count)
  248. {
  249. chip->ops->dma_read(chip, runtime, pipe, count);
  250. }
  251. /* error with hardware code,
  252. * the return value is -(VX_ERR_MASK | actual-hw-error-code)
  253. */
  254. #define VX_ERR_MASK 0x1000000
  255. #define vx_get_error(err) (-(err) & ~VX_ERR_MASK)
  256. /*
  257. * pcm stuff
  258. */
  259. int snd_vx_pcm_new(struct vx_core *chip);
  260. void vx_pcm_update_intr(struct vx_core *chip, unsigned int events);
  261. /*
  262. * mixer stuff
  263. */
  264. int snd_vx_mixer_new(struct vx_core *chip);
  265. void vx_toggle_dac_mute(struct vx_core *chip, int mute);
  266. int vx_sync_audio_source(struct vx_core *chip);
  267. int vx_set_monitor_level(struct vx_core *chip, int audio, int level, int active);
  268. /*
  269. * IEC958 & clock stuff
  270. */
  271. void vx_set_iec958_status(struct vx_core *chip, unsigned int bits);
  272. int vx_set_clock(struct vx_core *chip, unsigned int freq);
  273. void vx_set_internal_clock(struct vx_core *chip, unsigned int freq);
  274. int vx_change_frequency(struct vx_core *chip);
  275. /*
  276. * PM
  277. */
  278. int snd_vx_suspend(struct vx_core *card);
  279. int snd_vx_resume(struct vx_core *card);
  280. /*
  281. * hardware constants
  282. */
  283. #define vx_has_new_dsp(chip) ((chip)->type != VX_TYPE_BOARD)
  284. #define vx_is_pcmcia(chip) ((chip)->type >= VX_TYPE_VXPOCKET)
  285. /* audio input source */
  286. enum {
  287. VX_AUDIO_SRC_DIGITAL,
  288. VX_AUDIO_SRC_LINE,
  289. VX_AUDIO_SRC_MIC
  290. };
  291. /* clock source */
  292. enum {
  293. INTERNAL_QUARTZ,
  294. UER_SYNC
  295. };
  296. /* clock mode */
  297. enum {
  298. VX_CLOCK_MODE_AUTO, /* depending on the current audio source */
  299. VX_CLOCK_MODE_INTERNAL, /* fixed to internal quartz */
  300. VX_CLOCK_MODE_EXTERNAL /* fixed to UER sync */
  301. };
  302. /* SPDIF/UER type */
  303. enum {
  304. VX_UER_MODE_CONSUMER,
  305. VX_UER_MODE_PROFESSIONAL,
  306. VX_UER_MODE_NOT_PRESENT,
  307. };
  308. /* register indices */
  309. enum {
  310. VX_ICR,
  311. VX_CVR,
  312. VX_ISR,
  313. VX_IVR,
  314. VX_RXH,
  315. VX_TXH = VX_RXH,
  316. VX_RXM,
  317. VX_TXM = VX_RXM,
  318. VX_RXL,
  319. VX_TXL = VX_RXL,
  320. VX_DMA,
  321. VX_CDSP,
  322. VX_RFREQ,
  323. VX_RUER_V2,
  324. VX_GAIN,
  325. VX_DATA = VX_GAIN,
  326. VX_MEMIRQ,
  327. VX_ACQ,
  328. VX_BIT0,
  329. VX_BIT1,
  330. VX_MIC0,
  331. VX_MIC1,
  332. VX_MIC2,
  333. VX_MIC3,
  334. VX_PLX0,
  335. VX_PLX1,
  336. VX_PLX2,
  337. VX_LOFREQ, // V2: ACQ, VP: RFREQ
  338. VX_HIFREQ, // V2: BIT0, VP: RUER_V2
  339. VX_CSUER, // V2: BIT1, VP: BIT0
  340. VX_RUER, // V2: RUER_V2, VP: BIT1
  341. VX_REG_MAX,
  342. /* aliases for VX board */
  343. VX_RESET_DMA = VX_ISR,
  344. VX_CFG = VX_RFREQ,
  345. VX_STATUS = VX_MEMIRQ,
  346. VX_SELMIC = VX_MIC0,
  347. VX_COMPOT = VX_MIC1,
  348. VX_SCOMPR = VX_MIC2,
  349. VX_GLIMIT = VX_MIC3,
  350. VX_INTCSR = VX_PLX0,
  351. VX_CNTRL = VX_PLX1,
  352. VX_GPIOC = VX_PLX2,
  353. /* aliases for VXPOCKET board */
  354. VX_MICRO = VX_MEMIRQ,
  355. VX_CODEC2 = VX_MEMIRQ,
  356. VX_DIALOG = VX_ACQ,
  357. };
  358. /* RMH status type */
  359. enum {
  360. RMH_SSIZE_FIXED = 0, /* status size given by the driver (in LgStat) */
  361. RMH_SSIZE_ARG = 1, /* status size given in the LSB byte */
  362. RMH_SSIZE_MASK = 2, /* status size given in bitmask */
  363. };
  364. /* bits for ICR register */
  365. #define ICR_HF1 0x10
  366. #define ICR_HF0 0x08
  367. #define ICR_TREQ 0x02 /* Interrupt mode + HREQ set on for transfer (->DSP) request */
  368. #define ICR_RREQ 0x01 /* Interrupt mode + RREQ set on for transfer (->PC) request */
  369. /* bits for CVR register */
  370. #define CVR_HC 0x80
  371. /* bits for ISR register */
  372. #define ISR_HF3 0x10
  373. #define ISR_HF2 0x08
  374. #define ISR_CHK 0x10
  375. #define ISR_ERR 0x08
  376. #define ISR_TX_READY 0x04
  377. #define ISR_TX_EMPTY 0x02
  378. #define ISR_RX_FULL 0x01
  379. /* Constants used to access the DATA register */
  380. #define VX_DATA_CODEC_MASK 0x80
  381. #define VX_DATA_XICOR_MASK 0x80
  382. /* Constants used to access the CSUER register (both for VX2 and VXP) */
  383. #define VX_SUER_FREQ_MASK 0x0c
  384. #define VX_SUER_FREQ_32KHz_MASK 0x0c
  385. #define VX_SUER_FREQ_44KHz_MASK 0x00
  386. #define VX_SUER_FREQ_48KHz_MASK 0x04
  387. #define VX_SUER_DATA_PRESENT_MASK 0x02
  388. #define VX_SUER_CLOCK_PRESENT_MASK 0x01
  389. #define VX_CUER_HH_BITC_SEL_MASK 0x08
  390. #define VX_CUER_MH_BITC_SEL_MASK 0x04
  391. #define VX_CUER_ML_BITC_SEL_MASK 0x02
  392. #define VX_CUER_LL_BITC_SEL_MASK 0x01
  393. #define XX_UER_CBITS_OFFSET_MASK 0x1f
  394. /* bits for audio_info */
  395. #define VX_AUDIO_INFO_REAL_TIME (1<<0) /* real-time processing available */
  396. #define VX_AUDIO_INFO_OFFLINE (1<<1) /* offline processing available */
  397. #define VX_AUDIO_INFO_MPEG1 (1<<5)
  398. #define VX_AUDIO_INFO_MPEG2 (1<<6)
  399. #define VX_AUDIO_INFO_LINEAR_8 (1<<7)
  400. #define VX_AUDIO_INFO_LINEAR_16 (1<<8)
  401. #define VX_AUDIO_INFO_LINEAR_24 (1<<9)
  402. /* DSP Interrupt Request values */
  403. #define VXP_IRQ_OFFSET 0x40 /* add 0x40 offset for vxpocket and vx222/v2 */
  404. /* call with vx_send_irq_dsp() */
  405. #define IRQ_MESS_WRITE_END 0x30
  406. #define IRQ_MESS_WRITE_NEXT 0x32
  407. #define IRQ_MESS_READ_NEXT 0x34
  408. #define IRQ_MESS_READ_END 0x36
  409. #define IRQ_MESSAGE 0x38
  410. #define IRQ_RESET_CHK 0x3A
  411. #define IRQ_CONNECT_STREAM_NEXT 0x26
  412. #define IRQ_CONNECT_STREAM_END 0x28
  413. #define IRQ_PAUSE_START_CONNECT 0x2A
  414. #define IRQ_END_CONNECTION 0x2C
  415. /* Is there async. events pending ( IT Source Test ) */
  416. #define ASYNC_EVENTS_PENDING 0x008000
  417. #define HBUFFER_EVENTS_PENDING 0x004000 // Not always accurate
  418. #define NOTIF_EVENTS_PENDING 0x002000
  419. #define TIME_CODE_EVENT_PENDING 0x001000
  420. #define FREQUENCY_CHANGE_EVENT_PENDING 0x000800
  421. #define END_OF_BUFFER_EVENTS_PENDING 0x000400
  422. #define FATAL_DSP_ERROR 0xff0000
  423. /* Stream Format Header Defines */
  424. #define HEADER_FMT_BASE 0xFED00000
  425. #define HEADER_FMT_MONO 0x000000C0
  426. #define HEADER_FMT_INTEL 0x00008000
  427. #define HEADER_FMT_16BITS 0x00002000
  428. #define HEADER_FMT_24BITS 0x00004000
  429. #define HEADER_FMT_UPTO11 0x00000200 /* frequency is less or equ. to 11k.*/
  430. #define HEADER_FMT_UPTO32 0x00000100 /* frequency is over 11k and less then 32k.*/
  431. /* Constants used to access the Codec */
  432. #define XX_CODEC_SELECTOR 0x20
  433. /* codec commands */
  434. #define XX_CODEC_ADC_CONTROL_REGISTER 0x01
  435. #define XX_CODEC_DAC_CONTROL_REGISTER 0x02
  436. #define XX_CODEC_LEVEL_LEFT_REGISTER 0x03
  437. #define XX_CODEC_LEVEL_RIGHT_REGISTER 0x04
  438. #define XX_CODEC_PORT_MODE_REGISTER 0x05
  439. #define XX_CODEC_STATUS_REPORT_REGISTER 0x06
  440. #define XX_CODEC_CLOCK_CONTROL_REGISTER 0x07
  441. /*
  442. * Audio-level control values
  443. */
  444. #define CVAL_M110DB 0x000 /* -110dB */
  445. #define CVAL_M99DB 0x02C
  446. #define CVAL_M21DB 0x163
  447. #define CVAL_M18DB 0x16F
  448. #define CVAL_M10DB 0x18F
  449. #define CVAL_0DB 0x1B7
  450. #define CVAL_18DB 0x1FF /* +18dB */
  451. #define CVAL_MAX 0x1FF
  452. #define AUDIO_IO_HAS_MUTE_LEVEL 0x400000
  453. #define AUDIO_IO_HAS_MUTE_MONITORING_1 0x200000
  454. #define AUDIO_IO_HAS_MUTE_MONITORING_2 0x100000
  455. #define VALID_AUDIO_IO_DIGITAL_LEVEL 0x01
  456. #define VALID_AUDIO_IO_MONITORING_LEVEL 0x02
  457. #define VALID_AUDIO_IO_MUTE_LEVEL 0x04
  458. #define VALID_AUDIO_IO_MUTE_MONITORING_1 0x08
  459. #define VALID_AUDIO_IO_MUTE_MONITORING_2 0x10
  460. #endif /* __SOUND_VX_COMMON_H */