From: Heiner Kallweit <hkallweit1@gmail.com>
To: Jean Delvare <jdelvare@suse.com>
Cc: "linux-i2c@vger.kernel.org" <linux-i2c@vger.kernel.org>
Subject: [PATCH RFC] i2c: i801: Add i801_register_jc42, similar to i2c_register_spd
Date: Wed, 8 Nov 2023 08:27:30 +0100 [thread overview]
Message-ID: <79977020-69c3-4f87-b861-b043c7fb9077@gmail.com> (raw)
As discussed, this is a RFC version of changing jc42 auto-detection
with the goal to get rid of I2C_CLASS_SPD completely mid-term.
Code of i801_jc42_probe() was copied from jc42 driver, just w/o
the device id check. I think it's safe enough w/o this check.
I don't have hw to test this, therefore it's compile-tested only.
Link: https://lore.kernel.org/linux-i2c/a22978a4-88e4-46f4-b71c-032b22321599@gmail.com/
Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com>
---
drivers/i2c/busses/i2c-i801.c | 48 ++++++++++++++++++++++++++++++++---
1 file changed, 44 insertions(+), 4 deletions(-)
diff --git a/drivers/i2c/busses/i2c-i801.c b/drivers/i2c/busses/i2c-i801.c
index 070999139..4d5103288 100644
--- a/drivers/i2c/busses/i2c-i801.c
+++ b/drivers/i2c/busses/i2c-i801.c
@@ -261,7 +261,6 @@ struct i801_mux_config {
char *gpio_chip;
unsigned values[3];
int n_values;
- unsigned classes[3];
unsigned gpios[2]; /* Relative to gpio_chip->base */
int n_gpios;
};
@@ -1298,7 +1297,6 @@ static struct i801_mux_config i801_mux_config_asus_z8_d12 = {
.gpio_chip = "gpio_ich",
.values = { 0x02, 0x03 },
.n_values = 2,
- .classes = { I2C_CLASS_SPD, I2C_CLASS_SPD },
.gpios = { 52, 53 },
.n_gpios = 2,
};
@@ -1307,7 +1305,6 @@ static struct i801_mux_config i801_mux_config_asus_z8_d18 = {
.gpio_chip = "gpio_ich",
.values = { 0x02, 0x03, 0x01 },
.n_values = 3,
- .classes = { I2C_CLASS_SPD, I2C_CLASS_SPD, I2C_CLASS_SPD },
.gpios = { 52, 53 },
.n_gpios = 2,
};
@@ -1379,6 +1376,47 @@ static const struct dmi_system_id mux_dmi_table[] = {
{ }
};
+#define JC42_REG_CAP 0x00
+#define JC42_REG_CONFIG 0x01
+#define JC42_REG_MANID 0x06
+#define JC42_REG_DEVICEID 0x07
+
+static int i801_jc42_probe(struct i2c_adapter *adap, unsigned short addr)
+{
+ struct i2c_client cl = {.adapter = adap, .addr = addr};
+ int cap, config, manid, devid;
+
+ cap = i2c_smbus_read_word_swapped(&cl, JC42_REG_CAP);
+ config = i2c_smbus_read_word_swapped(&cl, JC42_REG_CONFIG);
+ manid = i2c_smbus_read_word_swapped(&cl, JC42_REG_MANID);
+ devid = i2c_smbus_read_word_swapped(&cl, JC42_REG_DEVICEID);
+
+ if (cap < 0 || config < 0 || manid < 0 || devid < 0)
+ return 0;
+
+ if (cap & 0xff00 || config & 0xf800 || !manid)
+ return 0;
+
+ return 1;
+}
+
+static int i801_register_jc42(struct device *dev, void *data)
+{
+ struct i2c_adapter *adap;
+ struct i2c_client *client;
+ struct i2c_board_info info = {.type = "jc42"};
+ static const unsigned short addrs[] =
+ {0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, I2C_CLIENT_END};
+
+ adap = i2c_verify_adapter(dev);
+ if(!adap)
+ return 0;
+
+ client = i2c_new_scanned_device(adap, &info, addrs, i801_jc42_probe);
+
+ return PTR_ERR_OR_ZERO(client);
+}
+
/* Setup multiplexing if needed */
static void i801_add_mux(struct i801_priv *priv)
{
@@ -1400,7 +1438,6 @@ static void i801_add_mux(struct i801_priv *priv)
gpio_data.parent = priv->adapter.nr;
gpio_data.values = mux_config->values;
gpio_data.n_values = mux_config->n_values;
- gpio_data.classes = mux_config->classes;
gpio_data.idle = I2C_MUX_GPIO_NO_IDLE;
/* Register GPIO descriptor lookup table */
@@ -1430,6 +1467,9 @@ static void i801_add_mux(struct i801_priv *priv)
gpiod_remove_lookup_table(lookup);
dev_err(dev, "Failed to register i2c-mux-gpio device\n");
}
+
+ /* Ignore errors */
+ device_for_each_child(dev, NULL, i801_register_jc42);
}
static void i801_del_mux(struct i801_priv *priv)
--
2.42.1
next reply other threads:[~2023-11-08 7:27 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-11-08 7:27 Heiner Kallweit [this message]
2023-11-08 10:28 ` [PATCH RFC] i2c: i801: Add i801_register_jc42, similar to i2c_register_spd Heiner Kallweit
2023-11-14 14:00 ` Jean Delvare
2023-11-14 14:44 ` Heiner Kallweit
2023-11-14 15:00 ` Heiner Kallweit
2023-11-15 11:00 ` Heiner Kallweit
2023-11-19 8:39 ` Jean Delvare
2023-11-21 12:34 ` Heiner Kallweit
2023-11-15 18:27 ` Jean Delvare
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=79977020-69c3-4f87-b861-b043c7fb9077@gmail.com \
--to=hkallweit1@gmail.com \
--cc=jdelvare@suse.com \
--cc=linux-i2c@vger.kernel.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