⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 aci.c

📁 arm平台上的uclinux系统全部源代码
💻 C
📖 第 1 页 / 共 2 页
字号:
/* * Audio Command Interface (ACI) driver (sound/aci.c) * * ACI is a protocol used to communicate with the microcontroller on * some sound cards produced by miro, e.g. the miroSOUND PCM12 and * PCM20. The ACI has been developed for miro by Norberto Pellicci * <pellicci@ix.netcom.com>. Special thanks to both him and miro for * providing the ACI specification. * * The main function of the ACI is to control the mixer and to get a * product identification. On the PCM20, ACI also controls the radio * tuner on this card, however this is not yet supported in this * software. *  * This Voxware ACI driver currently only supports the ACI functions * on the miroSOUND PCM12 card. Support for miro soundcards with * additional ACI functions can easily be added later. * * Revision history: * *   1995-11-10  Markus Kuhn <mskuhn@cip.informatik.uni-erlangen.de> *        First version written. *   1995-12-31  Markus Kuhn *        Second revision, general code cleanup. *   1996-05-16	 Hannu Savolainen *	  Integrated with other parts of the driver. *   1996-05-28  Markus Kuhn *        Initialize CS4231A mixer, make ACI first mixer, *        use new private mixer API for solo mode. *//* * Some driver specific information and features: * * This mixer driver identifies itself to applications as "ACI" in * mixer_info.id as retrieved by ioctl(fd, SOUND_MIXER_INFO, &mixer_info). * * Proprietary mixer features that go beyond the standard USS mixer * interface are: *  * Full duplex solo configuration: * *   int solo_mode; *   ioctl(fd, SOUND_MIXER_PRIVATE1, &solo_mode); * *   solo_mode = 0: deactivate solo mode (default) *   solo_mode > 0: activate solo mode *                  With activated solo mode, the PCM input can not any *                  longer hear the signals produced by the PCM output. *                  Activating solo mode is important in duplex mode in order *                  to avoid feedback distortions. *   solo_mode < 0: do not change solo mode (just retrieve the status) * *   When the ioctl() returns 0, solo_mode contains the previous *   status (0 = deactivated, 1 = activated). If solo mode is not *   implemented on this card, ioctl() returns -1 and sets errno to *   EINVAL. * */#include <linux/config.h> /* CONFIG_ACI_MIXER */#include "../sound_config.h"#ifdef CONFIG_ACI_MIXER#undef  DEBUG             /* if defined, produce a verbose report via syslog */int aci_port = 0x354; /* as determined by bit 4 in the OPTi 929 MC4 register */unsigned char aci_idcode[2] = {0, 0};         /* manufacturer and product ID */unsigned char aci_version = 0;                       /* ACI firmware version */int aci_solo;                     /* status bit of the card that can't be    *                                   * checked with ACI versions prior to 0xb0 */static int aci_present = 0;#define COMMAND_REGISTER    (aci_port)#define STATUS_REGISTER     (aci_port + 1)#define BUSY_REGISTER       (aci_port + 2)/* * Wait until the ACI microcontroller has set the READYFLAG in the * Busy/IRQ Source Register to 0. This is required to avoid * overrunning the soundcard microcontroller. We do a busy wait here, * because the microcontroller is not supposed to signal a busy * condition for more than a few clock cycles. In case of a time-out, * this function returns -1. * * This busy wait code normally requires less than 15 loops and * practically always less than 100 loops on my i486/DX2 66 MHz. * * Warning: Waiting on the general status flag after reseting the MUTE * function can take a VERY long time, because the PCM12 does some kind * of fade-in effect. For this reason, access to the MUTE function has * not been implemented at all. */static int busy_wait(void){  long timeout;  for (timeout = 0; timeout < 10000000L; timeout++)    if ((inb_p(BUSY_REGISTER) & 1) == 0)      return 0;#ifdef DEBUG  printk("ACI: READYFLAG timed out.\n");#endif  return -1;}/* * Read the GENERAL STATUS register. */static int read_general_status(void){  unsigned long flags;  int status;  save_flags(flags);  cli();  if (busy_wait()) { restore_flags(flags); return -1; }  status = (unsigned) inb_p(STATUS_REGISTER);  restore_flags(flags);  return status;}/* * The four ACI command types (implied, write, read and indexed) can * be sent to the microcontroller using the following four functions. * If a problem occurred, they return -1. */static int implied_cmd(unsigned char opcode){  unsigned long flags;#ifdef DEBUG  printk("ACI: implied_cmd(0x%02x)\n", opcode);#endif  save_flags(flags);  cli();    if (read_general_status() < 0 || busy_wait()) {    restore_flags(flags);    return -1;  }  outb_p(opcode, COMMAND_REGISTER);  restore_flags(flags);  return 0;}static int write_cmd(unsigned char opcode, unsigned char parameter){  unsigned long flags;  int status;#ifdef DEBUG  printk("ACI: write_cmd(0x%02x, 0x%02x)\n", opcode, parameter);#endif  save_flags(flags);  cli();    if (read_general_status() < 0 || busy_wait()) {    restore_flags(flags);    return -1;  }  outb_p(opcode, COMMAND_REGISTER);  if (busy_wait()) { restore_flags(flags); return -1; }  outb_p(parameter, COMMAND_REGISTER);  if ((status = read_general_status()) < 0) {    restore_flags(flags);    return -1;  }  /* polarity of the INVALID flag depends on ACI version */  if ((aci_version <  0xb0 && (status & 0x40) != 0) ||      (aci_version >= 0xb0 && (status & 0x40) == 0)) {    restore_flags(flags);    printk("ACI: invalid write command 0x%02x, 0x%02x.\n",	   opcode, parameter);    return -1;  }  restore_flags(flags);  return 0;}static int read_cmd(unsigned char opcode, int length, unsigned char *parameter){  unsigned long flags;  int i = 0;  save_flags(flags);  cli();    if (read_general_status() < 0) { restore_flags(flags); return -1; }  while (i < length) {    if (busy_wait()) { restore_flags(flags); return -1; }    outb_p(opcode, COMMAND_REGISTER);    if (busy_wait()) { restore_flags(flags); return -1; }    parameter[i++] = inb_p(STATUS_REGISTER);#ifdef DEBUG    if (i == 1)      printk("ACI: read_cmd(0x%02x, %d) = 0x%02x\n", opcode, length,	     parameter[i-1]);    else      printk("ACI: read_cmd cont.: 0x%02x\n", parameter[i-1]);#endif  }  restore_flags(flags);  return 0;}static int indexed_cmd(unsigned char opcode, unsigned char index,		       unsigned char *parameter){  unsigned long flags;  save_flags(flags);  cli();    if (read_general_status() < 0 || busy_wait()) {    restore_flags(flags);    return -1;  }  outb_p(opcode, COMMAND_REGISTER);  if (busy_wait()) { restore_flags(flags); return -1; }  outb_p(index, COMMAND_REGISTER);  if (busy_wait()) { restore_flags(flags); return -1; }  *parameter = inb_p(STATUS_REGISTER);#ifdef DEBUG  printk("ACI: indexed_cmd(0x%02x, 0x%02x) = 0x%02x\n", opcode, index,	 *parameter);#endif  restore_flags(flags);  return 0;}/* * The following macro SCALE can be used to scale one integer volume * value into another one using only integer arithmetic. If the input * value x is in the range 0 <= x <= xmax, then the result will be in * the range 0 <= SCALE(xmax,ymax,x) <= ymax. * * This macro has for all xmax, ymax > 0 and all 0 <= x <= xmax the * following nice properties: * * - SCALE(xmax,ymax,xmax) = ymax * - SCALE(xmax,ymax,0) = 0 * - SCALE(xmax,ymax,SCALE(ymax,xmax,SCALE(xmax,ymax,x))) = SCALE(xmax,ymax,x) * * In addition, the rounding error is minimal and nicely distributed. * The proofs are left as an exercise to the reader. */#define SCALE(xmax,ymax,x) (((x)*(ymax)+(xmax)/2)/(xmax))static int getvolume(caddr_t arg,		     unsigned char left_index, unsigned char right_index){  int vol;  unsigned char buf;  /* left channel */  if (indexed_cmd(0xf0, left_index, &buf)) return -EIO;  vol = SCALE(0x20, 100, buf < 0x20 ? 0x20-buf : 0);  /* right channel */  if (indexed_cmd(0xf0, right_index, &buf)) return -EIO;  vol |= SCALE(0x20, 100, buf < 0x20 ? 0x20-buf : 0) << 8;  return snd_ioctl_return((int *) arg, vol);}static int setvolume(caddr_t arg, 		     unsigned char left_index, unsigned char right_index){  int vol, ret;  unsigned param;  param = get_user((int *) arg);  /* left channel */  vol = param & 0xff;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -