Lines Matching +full:chip +full:- +full:to +full:- +full:chip

1 // SPDX-License-Identifier: GPL-2.0-only
3 * C-Media CMI8788 driver - helper functions
16 u8 oxygen_read8(struct oxygen *chip, unsigned int reg) in oxygen_read8() argument
18 return inb(chip->addr + reg); in oxygen_read8()
22 u16 oxygen_read16(struct oxygen *chip, unsigned int reg) in oxygen_read16() argument
24 return inw(chip->addr + reg); in oxygen_read16()
28 u32 oxygen_read32(struct oxygen *chip, unsigned int reg) in oxygen_read32() argument
30 return inl(chip->addr + reg); in oxygen_read32()
34 void oxygen_write8(struct oxygen *chip, unsigned int reg, u8 value) in oxygen_write8() argument
36 outb(value, chip->addr + reg); in oxygen_write8()
37 chip->saved_registers._8[reg] = value; in oxygen_write8()
41 void oxygen_write16(struct oxygen *chip, unsigned int reg, u16 value) in oxygen_write16() argument
43 outw(value, chip->addr + reg); in oxygen_write16()
44 chip->saved_registers._16[reg / 2] = cpu_to_le16(value); in oxygen_write16()
48 void oxygen_write32(struct oxygen *chip, unsigned int reg, u32 value) in oxygen_write32() argument
50 outl(value, chip->addr + reg); in oxygen_write32()
51 chip->saved_registers._32[reg / 4] = cpu_to_le32(value); in oxygen_write32()
55 void oxygen_write8_masked(struct oxygen *chip, unsigned int reg, in oxygen_write8_masked() argument
58 u8 tmp = inb(chip->addr + reg); in oxygen_write8_masked()
61 outb(tmp, chip->addr + reg); in oxygen_write8_masked()
62 chip->saved_registers._8[reg] = tmp; in oxygen_write8_masked()
66 void oxygen_write16_masked(struct oxygen *chip, unsigned int reg, in oxygen_write16_masked() argument
69 u16 tmp = inw(chip->addr + reg); in oxygen_write16_masked()
72 outw(tmp, chip->addr + reg); in oxygen_write16_masked()
73 chip->saved_registers._16[reg / 2] = cpu_to_le16(tmp); in oxygen_write16_masked()
77 void oxygen_write32_masked(struct oxygen *chip, unsigned int reg, in oxygen_write32_masked() argument
80 u32 tmp = inl(chip->addr + reg); in oxygen_write32_masked()
83 outl(tmp, chip->addr + reg); in oxygen_write32_masked()
84 chip->saved_registers._32[reg / 4] = cpu_to_le32(tmp); in oxygen_write32_masked()
88 static int oxygen_ac97_wait(struct oxygen *chip, unsigned int mask) in oxygen_ac97_wait() argument
93 * Reading the status register also clears the bits, so we have to save in oxygen_ac97_wait()
96 wait_event_timeout(chip->ac97_waitqueue, in oxygen_ac97_wait()
97 ({ status |= oxygen_read8(chip, OXYGEN_AC97_INTERRUPT_STATUS); in oxygen_ac97_wait()
102 * the AC'97 interrupt to be enabled. in oxygen_ac97_wait()
104 status |= oxygen_read8(chip, OXYGEN_AC97_INTERRUPT_STATUS); in oxygen_ac97_wait()
105 return status & mask ? 0 : -EIO; in oxygen_ac97_wait()
109 * About 10% of AC'97 register reads or writes fail to complete, but even those
110 * where the controller indicates completion aren't guaranteed to have actually
113 * It's hard to assign blame to either the controller or the codec because both
114 * were made by C-Media ...
117 void oxygen_write_ac97(struct oxygen *chip, unsigned int codec, in oxygen_write_ac97() argument
128 for (count = 5; count > 0; --count) { in oxygen_write_ac97()
130 oxygen_write32(chip, OXYGEN_AC97_REGS, reg); in oxygen_write_ac97()
131 /* require two "completed" writes, just to be sure */ in oxygen_write_ac97()
132 if (oxygen_ac97_wait(chip, OXYGEN_AC97_INT_WRITE_DONE) >= 0 && in oxygen_write_ac97()
134 chip->saved_ac97_registers[codec][index / 2] = data; in oxygen_write_ac97()
138 dev_err(chip->card->dev, "AC'97 write timeout\n"); in oxygen_write_ac97()
142 u16 oxygen_read_ac97(struct oxygen *chip, unsigned int codec, in oxygen_read_ac97() argument
152 for (count = 5; count > 0; --count) { in oxygen_read_ac97()
154 oxygen_write32(chip, OXYGEN_AC97_REGS, reg); in oxygen_read_ac97()
156 if (oxygen_ac97_wait(chip, OXYGEN_AC97_INT_READ_DONE) >= 0) { in oxygen_read_ac97()
157 u16 value = oxygen_read16(chip, OXYGEN_AC97_REGS); in oxygen_read_ac97()
163 * Invert the register value bits to make sure that two in oxygen_read_ac97()
170 dev_err(chip->card->dev, "AC'97 read timeout on codec %u\n", codec); in oxygen_read_ac97()
175 void oxygen_write_ac97_masked(struct oxygen *chip, unsigned int codec, in oxygen_write_ac97_masked() argument
178 u16 value = oxygen_read_ac97(chip, codec, index); in oxygen_write_ac97_masked()
181 oxygen_write_ac97(chip, codec, index, value); in oxygen_write_ac97_masked()
185 static int oxygen_wait_spi(struct oxygen *chip) in oxygen_wait_spi() argument
190 * Higher timeout to be sure: 200 us; in oxygen_wait_spi()
193 for (count = 50; count > 0; count--) { in oxygen_wait_spi()
195 if ((oxygen_read8(chip, OXYGEN_SPI_CONTROL) & in oxygen_wait_spi()
199 dev_err(chip->card->dev, "oxygen: SPI wait timeout\n"); in oxygen_wait_spi()
200 return -EIO; in oxygen_wait_spi()
203 int oxygen_write_spi(struct oxygen *chip, u8 control, unsigned int data) in oxygen_write_spi() argument
206 * We need to wait AFTER initiating the SPI transaction, in oxygen_write_spi()
209 oxygen_write8(chip, OXYGEN_SPI_DATA1, data); in oxygen_write_spi()
210 oxygen_write8(chip, OXYGEN_SPI_DATA2, data >> 8); in oxygen_write_spi()
212 oxygen_write8(chip, OXYGEN_SPI_DATA3, data >> 16); in oxygen_write_spi()
213 oxygen_write8(chip, OXYGEN_SPI_CONTROL, control); in oxygen_write_spi()
214 return oxygen_wait_spi(chip); in oxygen_write_spi()
218 void oxygen_write_i2c(struct oxygen *chip, u8 device, u8 map, u8 data) in oxygen_write_i2c() argument
223 oxygen_write8(chip, OXYGEN_2WIRE_MAP, map); in oxygen_write_i2c()
224 oxygen_write8(chip, OXYGEN_2WIRE_DATA, data); in oxygen_write_i2c()
225 oxygen_write8(chip, OXYGEN_2WIRE_CONTROL, in oxygen_write_i2c()
230 static void _write_uart(struct oxygen *chip, unsigned int port, u8 data) in _write_uart() argument
232 if (oxygen_read8(chip, OXYGEN_MPU401 + 1) & MPU401_TX_FULL) in _write_uart()
234 oxygen_write8(chip, OXYGEN_MPU401 + port, data); in _write_uart()
237 void oxygen_reset_uart(struct oxygen *chip) in oxygen_reset_uart() argument
239 _write_uart(chip, 1, MPU401_RESET); in oxygen_reset_uart()
241 _write_uart(chip, 1, MPU401_ENTER_UART); in oxygen_reset_uart()
245 void oxygen_write_uart(struct oxygen *chip, u8 data) in oxygen_write_uart() argument
247 _write_uart(chip, 0, data); in oxygen_write_uart()
251 u16 oxygen_read_eeprom(struct oxygen *chip, unsigned int index) in oxygen_read_eeprom() argument
255 oxygen_write8(chip, OXYGEN_EEPROM_CONTROL, in oxygen_read_eeprom()
259 if (!(oxygen_read8(chip, OXYGEN_EEPROM_STATUS) in oxygen_read_eeprom()
263 return oxygen_read16(chip, OXYGEN_EEPROM_DATA); in oxygen_read_eeprom()
266 void oxygen_write_eeprom(struct oxygen *chip, unsigned int index, u16 value) in oxygen_write_eeprom() argument
270 oxygen_write16(chip, OXYGEN_EEPROM_DATA, value); in oxygen_write_eeprom()
271 oxygen_write8(chip, OXYGEN_EEPROM_CONTROL, in oxygen_write_eeprom()
275 if (!(oxygen_read8(chip, OXYGEN_EEPROM_STATUS) in oxygen_write_eeprom()
279 dev_err(chip->card->dev, "EEPROM write timeout\n"); in oxygen_write_eeprom()