aboutsummaryrefslogtreecommitdiff
path: root/sound/pci/oxygen/oxygen_io.c
diff options
context:
space:
mode:
Diffstat (limited to 'sound/pci/oxygen/oxygen_io.c')
-rw-r--r--sound/pci/oxygen/oxygen_io.c34
1 files changed, 24 insertions, 10 deletions
diff --git a/sound/pci/oxygen/oxygen_io.c b/sound/pci/oxygen/oxygen_io.c
index 09b2b2a36df..4b8a32c37e3 100644
--- a/sound/pci/oxygen/oxygen_io.c
+++ b/sound/pci/oxygen/oxygen_io.c
@@ -19,6 +19,7 @@
#include <linux/delay.h>
#include <linux/sched.h>
+#include <linux/export.h>
#include <sound/core.h>
#include <sound/mpu401.h>
#include <asm/io.h>
@@ -146,7 +147,7 @@ void oxygen_write_ac97(struct oxygen *chip, unsigned int codec,
return;
}
}
- snd_printk(KERN_ERR "AC'97 write timeout\n");
+ dev_err(chip->card->dev, "AC'97 write timeout\n");
}
EXPORT_SYMBOL(oxygen_write_ac97);
@@ -178,7 +179,7 @@ u16 oxygen_read_ac97(struct oxygen *chip, unsigned int codec,
reg ^= 0xffff;
}
}
- snd_printk(KERN_ERR "AC'97 read timeout on codec %u\n", codec);
+ dev_err(chip->card->dev, "AC'97 read timeout on codec %u\n", codec);
return 0;
}
EXPORT_SYMBOL(oxygen_read_ac97);
@@ -193,23 +194,36 @@ void oxygen_write_ac97_masked(struct oxygen *chip, unsigned int codec,
}
EXPORT_SYMBOL(oxygen_write_ac97_masked);
-void oxygen_write_spi(struct oxygen *chip, u8 control, unsigned int data)
+static int oxygen_wait_spi(struct oxygen *chip)
{
unsigned int count;
- /* should not need more than 7.68 us (24 * 320 ns) */
- count = 10;
- while ((oxygen_read8(chip, OXYGEN_SPI_CONTROL) & OXYGEN_SPI_BUSY)
- && count > 0) {
- udelay(1);
- --count;
+ /*
+ * Higher timeout to be sure: 200 us;
+ * actual transaction should not need more than 40 us.
+ */
+ for (count = 50; count > 0; count--) {
+ udelay(4);
+ if ((oxygen_read8(chip, OXYGEN_SPI_CONTROL) &
+ OXYGEN_SPI_BUSY) == 0)
+ return 0;
}
+ dev_err(chip->card->dev, "oxygen: SPI wait timeout\n");
+ return -EIO;
+}
+int oxygen_write_spi(struct oxygen *chip, u8 control, unsigned int data)
+{
+ /*
+ * We need to wait AFTER initiating the SPI transaction,
+ * otherwise read operations will not work.
+ */
oxygen_write8(chip, OXYGEN_SPI_DATA1, data);
oxygen_write8(chip, OXYGEN_SPI_DATA2, data >> 8);
if (control & OXYGEN_SPI_DATA_LENGTH_3)
oxygen_write8(chip, OXYGEN_SPI_DATA3, data >> 16);
oxygen_write8(chip, OXYGEN_SPI_CONTROL, control);
+ return oxygen_wait_spi(chip);
}
EXPORT_SYMBOL(oxygen_write_spi);
@@ -274,5 +288,5 @@ void oxygen_write_eeprom(struct oxygen *chip, unsigned int index, u16 value)
& OXYGEN_EEPROM_BUSY))
return;
}
- snd_printk(KERN_ERR "EEPROM write timeout\n");
+ dev_err(chip->card->dev, "EEPROM write timeout\n");
}