From: Alex Tran <alex.t.tran@gmail.com>
To: mchehab@kernel.org
Cc: laurent.pinchart@ideasonboard.com, hansg@kernel.org,
hverkuil+cisco@kernel.org, cascardo@igalia.com,
ribalda@chromium.org, linux-media@vger.kernel.org,
linux-kernel@vger.kernel.org, Alex Tran <alex.t.tran@gmail.com>
Subject: [PATCH v3] media: i2c: wm8775: parameterize wm8775_platform_data based on config
Date: Sat, 20 Sep 2025 17:56:35 -0700 [thread overview]
Message-ID: <20250921005635.949377-1-alex.t.tran@gmail.com> (raw)
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@gmail.com>
---
Changes in v2:
- rebased from mchehab linux media onto media committers tree
- resolve patch and build errors
Changes in v3:
- cc updated maintainers list
drivers/media/i2c/wm8775.c | 109 ++++++++++++++++------------
drivers/media/pci/cx88/cx88-video.c | 4 +-
include/media/i2c/wm8775.h | 25 +++++--
3 files changed, 83 insertions(+), 55 deletions(-)
diff --git a/drivers/media/i2c/wm8775.c b/drivers/media/i2c/wm8775.c
index 56778d3bc..6218fc3fe 100644
--- a/drivers/media/i2c/wm8775.c
+++ b/drivers/media/i2c/wm8775.c
@@ -50,6 +50,43 @@ 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, ALC hold time 42.6 ms */
+ .alc_ctrl_3 = 0x0a2, /* Ramp up delay 34 s, ramp down delay 33 ms */
+ .noise_gate = 0x005, /* Enable noise gate, threshold -72dBfs */
+ .limiter_ctrl = 0x07a, /* 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, /* Stereo, target level -5dB FS, max gain +8dB */
+ .alc_ctrl_2 = WM8775_REG_UNUSED,
+ .alc_ctrl_3 = 0x0a2, /* Ramp up delay 34 s, 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);
@@ -195,12 +232,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))
@@ -233,49 +266,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 0c8732768..a3729fd73 100644
--- a/drivers/media/pci/cx88/cx88-video.c
+++ b/drivers/media/pci/cx88/cx88-video.c
@@ -1353,9 +1353,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 a02695ee3..99678d165 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 parameterize 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
next reply other threads:[~2025-09-21 0:57 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-09-21 0:56 Alex Tran [this message]
2025-09-21 12:02 ` kernel test robot
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250921005635.949377-1-alex.t.tran@gmail.com \
--to=alex.t.tran@gmail.com \
--cc=cascardo@igalia.com \
--cc=hansg@kernel.org \
--cc=hverkuil+cisco@kernel.org \
--cc=laurent.pinchart@ideasonboard.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-media@vger.kernel.org \
--cc=mchehab@kernel.org \
--cc=ribalda@chromium.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®