[<prev] [next>] [day] [month] [year] [list]
Message-ID: <20250920225207.864348-1-alex.t.tran@gmail.com>
Date: Sat, 20 Sep 2025 15:52:07 -0700
From: Alex Tran <alex.t.tran@...il.com>
To: mchehab@...nel.org
Cc: linux-media@...r.kernel.org,
linux-kernel@...r.kernel.org,
Alex Tran <alex.t.tran@...il.com>
Subject: [PATCH v1] media: i2c: wm8775: parameterize wm8775_platform_data based on config
Parameterized wm8775_platform_data struct, removing the single boolean
for determining device type. wm8775_standard_cfg struct will be used
for standard devices and wm8775_nova_s_cfg for nova_s devices.
Signed-off-by: Alex Tran <alex.t.tran@...il.com>
---
drivers/media/i2c/wm8775.c | 114 ++++++++++++++++------------
drivers/media/pci/cx88/cx88-video.c | 4 +-
include/media/i2c/wm8775.h | 25 ++++--
3 files changed, 88 insertions(+), 55 deletions(-)
diff --git a/drivers/media/i2c/wm8775.c b/drivers/media/i2c/wm8775.c
index d4c83c398..1fec8c0c2 100644
--- a/drivers/media/i2c/wm8775.c
+++ b/drivers/media/i2c/wm8775.c
@@ -50,6 +50,48 @@ struct wm8775_state {
u8 input; /* Last selected input (0-0xf) */
};
+struct wm8775_platform_data wm8775_standard_cfg = {
+ .reset = 0x000, /* RESET */
+ .zero_cross_timeout = 0x000, /* Disable zero cross detect timeout */
+ .interface_ctrl =
+ 0x021, /* HPF enable, left justified, 24-bit (Philips) mode */
+ .master_mode = 0x102, /* Master mode, clock ratio 256fs */
+ .powerdown = 0x000, /* Powered up */
+ .adc_l = 0x1d4, /* ADC gain +2.5dB, enable zero cross */
+ .adc_r = 0x1d4, /* ADC gain +2.5dB, enable zero cross */
+ .alc_ctrl_1 =
+ 0x1bf, /* ALC Stereo, ALC target level -1dB FS max gain +8dB */
+ .alc_ctrl_2 =
+ 0x185, /* Enable gain control, use zero cross detection, ALC hold time 42.6 ms */
+ .alc_ctrl_3 =
+ 0x0a2, /* ALC gain ramp up delay 34 s, ALC gain ramp down delay 33 ms */
+ .noise_gate = 0x005, /* Enable noise gate, threshold -72dBfs */
+ .limiter_ctrl =
+ 0x07a, /* Transient window 4ms, lower PGA gain limit -1dB */
+ .adc_mixer = 0x102, /* LRBOTH = 1, use input 2. */
+ .should_set_audio = false,
+};
+
+struct wm8775_platform_data wm8775_nova_s_cfg = {
+ .reset = 0x000, /* RESET */
+ .zero_cross_timeout = 0x000, /* Disable zero cross detect timeout */
+ .interface_ctrl =
+ 0x021, /* HPF enable, left justified, 24-bit (Philips) mode */
+ .master_mode = 0x102, /* Master mode, clock ratio 256fs */
+ .powerdown = 0x000, /* Powered up */
+ .adc_l = WM8775_REG_UNUSED,
+ .adc_r = WM8775_REG_UNUSED,
+ .alc_ctrl_1 =
+ 0x1bb, /* ALC stereo, ALC target level -5dB FS, ALC max gain +8dB */
+ .alc_ctrl_2 = WM8775_REG_UNUSED,
+ .alc_ctrl_3 =
+ 0x0a2, /* ALC gain ramp up delay 34 s, ALC gain ramp down delay 33 ms */
+ .noise_gate = 0x005, /* Enable noise gate, threshold -72dBfs */
+ .limiter_ctrl = 0x0fb, /* Transient window 4ms, ALC min gain -5dB */
+ .adc_mixer = WM8775_REG_UNUSED,
+ .should_set_audio = true, /* set volume/mute/mux */
+};
+
static inline struct wm8775_state *to_state(struct v4l2_subdev *sd)
{
return container_of(sd, struct wm8775_state, sd);
@@ -196,12 +238,8 @@ static int wm8775_probe(struct i2c_client *client,
struct wm8775_state *state;
struct v4l2_subdev *sd;
int err;
- bool is_nova_s = false;
-
- if (client->dev.platform_data) {
- struct wm8775_platform_data *data = client->dev.platform_data;
- is_nova_s = data->is_nova_s;
- }
+ struct wm8775_platform_data *data =
+ client->dev.platform_data ?: &wm8775_standard_cfg;
/* Check if the adapter supports the needed features */
if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE_DATA))
@@ -234,49 +272,29 @@ static int wm8775_probe(struct i2c_client *client,
}
/* Initialize wm8775 */
+ wm8775_write(sd, R23, data->reset);
+ wm8775_write(sd, R7, data->zero_cross_timeout);
+ wm8775_write(sd, R11, data->interface_ctrl);
+ wm8775_write(sd, R12, data->master_mode);
+ wm8775_write(sd, R13, data->powerdown);
+ if (data->adc_l != WM8775_REG_UNUSED)
+ wm8775_write(sd, R14, data->adc_l);
+ if (data->adc_r != WM8775_REG_UNUSED)
+ wm8775_write(sd, R15, data->adc_r);
+ wm8775_write(sd, R16, data->alc_ctrl_1);
+ if (data->alc_ctrl_2 != WM8775_REG_UNUSED)
+ wm8775_write(sd, R17, data->alc_ctrl_2);
+ else
+ wm8775_write(sd, R17,
+ (state->loud->val ? ALC_EN : 0) | ALC_HOLD);
+ wm8775_write(sd, R18, data->alc_ctrl_3);
+ wm8775_write(sd, R19, data->noise_gate);
+ wm8775_write(sd, R20, data->limiter_ctrl);
+ if (data->adc_mixer != WM8775_REG_UNUSED)
+ wm8775_write(sd, R21, data->adc_mixer);
+ if (data->should_set_audio)
+ wm8775_set_audio(sd, 1);
- /* RESET */
- wm8775_write(sd, R23, 0x000);
- /* Disable zero cross detect timeout */
- wm8775_write(sd, R7, 0x000);
- /* HPF enable, left justified, 24-bit (Philips) mode */
- wm8775_write(sd, R11, 0x021);
- /* Master mode, clock ratio 256fs */
- wm8775_write(sd, R12, 0x102);
- /* Powered up */
- wm8775_write(sd, R13, 0x000);
-
- if (!is_nova_s) {
- /* ADC gain +2.5dB, enable zero cross */
- wm8775_write(sd, R14, 0x1d4);
- /* ADC gain +2.5dB, enable zero cross */
- wm8775_write(sd, R15, 0x1d4);
- /* ALC Stereo, ALC target level -1dB FS max gain +8dB */
- wm8775_write(sd, R16, 0x1bf);
- /* Enable gain control, use zero cross detection,
- ALC hold time 42.6 ms */
- wm8775_write(sd, R17, 0x185);
- } else {
- /* ALC stereo, ALC target level -5dB FS, ALC max gain +8dB */
- wm8775_write(sd, R16, 0x1bb);
- /* Set ALC mode and hold time */
- wm8775_write(sd, R17, (state->loud->val ? ALC_EN : 0) | ALC_HOLD);
- }
- /* ALC gain ramp up delay 34 s, ALC gain ramp down delay 33 ms */
- wm8775_write(sd, R18, 0x0a2);
- /* Enable noise gate, threshold -72dBfs */
- wm8775_write(sd, R19, 0x005);
- if (!is_nova_s) {
- /* Transient window 4ms, lower PGA gain limit -1dB */
- wm8775_write(sd, R20, 0x07a);
- /* LRBOTH = 1, use input 2. */
- wm8775_write(sd, R21, 0x102);
- } else {
- /* Transient window 4ms, ALC min gain -5dB */
- wm8775_write(sd, R20, 0x0fb);
-
- wm8775_set_audio(sd, 1); /* set volume/mute/mux */
- }
return 0;
}
diff --git a/drivers/media/pci/cx88/cx88-video.c b/drivers/media/pci/cx88/cx88-video.c
index 8cffdacf6..efba7477f 100644
--- a/drivers/media/pci/cx88/cx88-video.c
+++ b/drivers/media/pci/cx88/cx88-video.c
@@ -1354,9 +1354,9 @@ static int cx8800_initdev(struct pci_dev *pci_dev,
struct v4l2_subdev *sd;
if (core->boardnr == CX88_BOARD_HAUPPAUGE_NOVASPLUS_S1)
- core->wm8775_data.is_nova_s = true;
+ core->wm8775_data = wm8775_nova_s_cfg;
else
- core->wm8775_data.is_nova_s = false;
+ core->wm8775_data = wm8775_standard_cfg;
sd = v4l2_i2c_new_subdev_board(&core->v4l2_dev, &core->i2c_adap,
&wm8775_info, NULL);
diff --git a/include/media/i2c/wm8775.h b/include/media/i2c/wm8775.h
index 836758176..856f9ec64 100644
--- a/include/media/i2c/wm8775.h
+++ b/include/media/i2c/wm8775.h
@@ -20,13 +20,28 @@
#define WM8775_AIN3 4
#define WM8775_AIN4 8
+#define WM8775_REG_UNUSED ((u16)-1)
struct wm8775_platform_data {
- /*
- * FIXME: Instead, we should parametrize the params
- * that need different settings between ivtv, pvrusb2, and Nova-S
- */
- bool is_nova_s;
+ u16 reset; /* RESET (R23) */
+ u16 zero_cross_timeout; /* Zero cross detect timeout (R7) */
+ u16 interface_ctrl; /* Interface control (R11) */
+ u16 master_mode; /* Master mode (R12) */
+ u16 powerdown; /* Power down (R13) */
+
+ u16 adc_l; /* ADC left (R14) */
+ u16 adc_r; /* ADC right (R15) */
+ u16 alc_ctrl_1; /* ALC control 1 (R16)*/
+ u16 alc_ctrl_2; /* ALC control 2 (R17) */
+ u16 alc_ctrl_3; /* ALC control 3 (R18) */
+ u16 noise_gate; /* Noise gate (R19) */
+ u16 limiter_ctrl; /* Limiter control (R20) */
+ u16 adc_mixer; /* ADC mixer control (R21) */
+
+ bool should_set_audio;
};
+extern struct wm8775_platform_data wm8775_nova_s_cfg;
+extern struct wm8775_platform_data wm8775_standard_cfg;
+
#endif
--
2.51.0
Powered by blists - more mailing lists