static unsigned char read_codec(struct device *dev, unsigned char idx) { int timeout = 900000; /* wait until codec ready */ while (timeout > 0 && inb(WSS_CODEC_IA(dev->base_addr)) & 0x80) timeout--; outb(idx & 0x1f, WSS_CODEC_IA(dev->base_addr)); return inb(WSS_CODEC_ID(dev->base_addr)); }
static void write_codec(struct device *dev, unsigned char idx, unsigned char data) { int timeout = 900000; /* wait until codec ready */ while (timeout > 0 && inb(WSS_CODEC_IA(dev->base_addr)) & 0x80) timeout--; outb(idx, WSS_CODEC_IA(dev->base_addr)); outb(data, WSS_CODEC_ID(dev->base_addr)); }
static int wss_set_codec_fmt(struct net_device *dev, struct sm_state *sm, unsigned char fmt, unsigned char fmt2, char fdx, char fullcalib) { unsigned long time; unsigned long flags; save_flags(flags); cli(); /* Clock and data format register */ write_codec(dev, 0x48, fmt); if (SCSTATE->crystal) { write_codec(dev, 0x5c, fmt2 & 0xf0); /* MCE and interface config reg */ write_codec(dev, 0x49, (fdx ? 0 : 0x4) | (fullcalib ? 0x18 : 0)); } else /* MCE and interface config reg */ write_codec(dev, 0x49, fdx ? 0x8 : 0xc); outb(0xb, WSS_CODEC_IA(dev->base_addr)); /* leave MCE */ if (SCSTATE->crystal && !fullcalib) { restore_flags(flags); return 0; } /* * wait for ACI start */ time = 1000; while (!(read_codec(dev, 0x0b) & 0x20)) if (!(--time)) { printk(KERN_WARNING "%s: ad1848 auto calibration timed out (1)\n", sm_drvname); restore_flags(flags); return -1; } /* * wait for ACI end */ sti(); time = jiffies + HZ/4; while ((read_codec(dev, 0x0b) & 0x20) && ((signed)(jiffies - time) < 0)); restore_flags(flags); if ((signed)(jiffies - time) >= 0) { printk(KERN_WARNING "%s: ad1848 auto calibration timed out (2)\n", sm_drvname); return -1; } return 0; }