+static int ac97_codec_not_present(struct ac97_codec *codec)
+{
+ struct vrc5477_ac97_state *s =
+ (struct vrc5477_ac97_state *)codec->private_data;
+ unsigned long flags;
+ unsigned short count = 0xffff;
+
+ spin_lock_irqsave(&s->lock, flags);
+
+ /* wait until we can access codec registers */
+ do {
+ if (!(inl(s->io + VRC5477_CODEC_WR) & 0x80000000))
+ break;
+ } while (--count);
+
+ if (count == 0) {
+ spin_unlock_irqrestore(&s->lock, flags);
+ return -1;
+ }
+
+ /* write 0 to reset */
+ outl((AC97_RESET << 16) | 0, s->io + VRC5477_CODEC_WR);
+
+ /* test whether we get a response from ac97 chip */
+ count = 0xffff;
+ do {
+ if (!(inl(s->io + VRC5477_CODEC_WR) & 0x80000000))
+ break;
+ } while (--count);
+
+ if (count == 0) {
+ spin_unlock_irqrestore(&s->lock, flags);
+ return -1;
+ }
+ spin_unlock_irqrestore(&s->lock, flags);
+ return 0;
+}