ALSA: oxygen: Change SPI writing/waiting logic
Subsystems (2)
PATCH v2 1/4 ALSA: oxygen: Change SPI writing/waiting logic
Move waiting logic into separate function, wait after triggering the transaction (not before), increase the wait timeout, error handling. Should not affect other card models.
Signed-off-by Roman I. Volkov <[email protected]>
---
sound/pci/oxygen/oxygen.h +1 -1
@@ -198,7 +198,7 @@ void oxygen_write_ac97(struct oxygen *chvoid oxygen_write_ac97_masked (struct oxygen *chip,unsigned int codec,unsigned int index,u16 data,u16 mask); -void oxygen_write_spi (struct oxygen *chip,u8 control,unsigned int data); +int oxygen_write_spi (struct oxygen *chip,u8 control,unsigned int data);void oxygen_write_i2c (struct oxygen *chip,u8 device,u8 map,u8 data);void oxygen_reset_uart (struct oxygen *chip);
sound/pci/oxygen/oxygen_io.c +18 -7
@@ -194,23 +194,34 @@ void oxygen_write_ac97_masked(struct oxy }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; +/* Higher interval to be sure - 400 microseconds */ +unsigned int count =100 ; -/* should not need more than 30.72 us (24 * 1.28 us) */ - count =10 ; -while ((oxygen_read8 (chip,OXYGEN_SPI_CONTROL ) &OXYGEN_SPI_BUSY ) - && count >0 ) { +for (;;) { +if ((oxygen_read8 (chip,OXYGEN_SPI_CONTROL ) & +OXYGEN_SPI_BUSY ) ==0 ) +break ; +if (count ==0 ) { +snd_printk (KERN_ERR "oxygen: spi wait timeout\n" ); +return -EIO ; + }udelay (4 ); - --count; + count--; } +return 0 ; +} +int oxygen_write_spi (struct oxygen *chip,u8 control,unsigned int data) +{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);
Signature · 3 lines
Kind regards, Roman Volkov, [email protected]