Skip to content

Commit 4b490e0

Browse files
harinworkstiwai
authored andcommitted
ALSA: ctxfi: Add ADC helper functions for GPIO
Add helper functions hw_adc_stop(), hw_adc_start(), and hw_adc_reset() to encapsulate ADC reset sequence operations. These functions reduce duplication by centralizing the GPIO-based ADC control logic. Signed-off-by: Harin Lee <me@harin.net> Signed-off-by: Takashi Iwai <tiwai@suse.de> Link: https://patch.msgid.link/20251124180501.2760421-3-me@harin.net
1 parent 5ebd054 commit 4b490e0

1 file changed

Lines changed: 28 additions & 9 deletions

File tree

sound/pci/ctxfi/cthw20k2.c

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1826,6 +1826,32 @@ static int hw_adc_input_select(struct hw *hw, enum ADCSRC type)
18261826
return 0;
18271827
}
18281828

1829+
static void hw_adc_stop(struct hw *hw)
1830+
{
1831+
u32 data;
1832+
/* Reset the ADC (reset is active low). */
1833+
data = hw_read_20kx(hw, GPIO_DATA);
1834+
data &= ~(0x1 << 15);
1835+
hw_write_20kx(hw, GPIO_DATA, data);
1836+
usleep_range(10000, 11000);
1837+
}
1838+
1839+
static void hw_adc_start(struct hw *hw)
1840+
{
1841+
u32 data;
1842+
/* Return the ADC to normal operation. */
1843+
data = hw_read_20kx(hw, GPIO_DATA);
1844+
data |= (0x1 << 15);
1845+
hw_write_20kx(hw, GPIO_DATA, data);
1846+
msleep(50);
1847+
}
1848+
1849+
static void __maybe_unused hw_adc_reset(struct hw *hw)
1850+
{
1851+
hw_adc_stop(hw);
1852+
hw_adc_start(hw);
1853+
}
1854+
18291855
static int hw_adc_init(struct hw *hw, const struct adc_conf *info)
18301856
{
18311857
int err;
@@ -1843,10 +1869,7 @@ static int hw_adc_init(struct hw *hw, const struct adc_conf *info)
18431869
goto error;
18441870
}
18451871

1846-
/* Reset the ADC (reset is active low). */
1847-
data = hw_read_20kx(hw, GPIO_DATA);
1848-
data &= ~(0x1 << 15);
1849-
hw_write_20kx(hw, GPIO_DATA, data);
1872+
hw_adc_stop(hw);
18501873

18511874
if (hw->model == CTSB1270) {
18521875
/* Set up the PCM4220 ADC on Titanium HD */
@@ -1860,11 +1883,7 @@ static int hw_adc_init(struct hw *hw, const struct adc_conf *info)
18601883
hw_write_20kx(hw, GPIO_DATA, data);
18611884
}
18621885

1863-
usleep_range(10000, 11000);
1864-
/* Return the ADC to normal operation. */
1865-
data |= (0x1 << 15);
1866-
hw_write_20kx(hw, GPIO_DATA, data);
1867-
msleep(50);
1886+
hw_adc_start(hw);
18681887

18691888
/* I2C write to register offset 0x0B to set ADC LRCLK polarity */
18701889
/* invert bit, interface format to I2S, word length to 24-bit, */

0 commit comments

Comments
 (0)