diff mbox series

[v3,3/5] hwmon: tmp108: Add helper function tmp108_common_probe() to prepare I3C support

Message ID 20241111-p3t1085-v3-3-bff511550aad@nxp.com (mailing list archive)
State Superseded
Headers show
Series hwmon: tmp108: Add support for P3T1085 | expand

Commit Message

Frank Li Nov. 11, 2024, 5:32 p.m. UTC
Add help function tmp108_common_probe() to pave road to support i3c for
P3T1085(NXP) chip.

Use dev_err_probe() to simple code.

Signed-off-by: Frank Li <Frank.Li@nxp.com>
---
dev_err_probe() have not involve addition diff change. The difference
always list these code block change regardless use dev_err_probe().
---
change from v2 to v3
- update subject by add  prepare I3C support"
---
 drivers/hwmon/tmp108.c | 39 +++++++++++++++++++++------------------
 1 file changed, 21 insertions(+), 18 deletions(-)

Comments

Guenter Roeck Nov. 11, 2024, 7:44 p.m. UTC | #1
On 11/11/24 09:32, Frank Li wrote:
> Add help function tmp108_common_probe() to pave road to support i3c for
> P3T1085(NXP) chip.
> 
> Use dev_err_probe() to simple code.
> 
> Signed-off-by: Frank Li <Frank.Li@nxp.com>

I applied the first two patches of the series, but I am holding back this
and the subsequent patches since I don't know how the kernel handles having
two drivers in a single module, and one of them fails to instantiate. I did
not find a matching example elsewhere in the kernel. We may have to use
the method used by the st_lsm6dsx driver - essentially splitting the driver
into three parts (i2c, i3c, and common). That would be overkill; the alternative
might be something like the approach used by module_i3c_i2c_driver(), but with
a set of #ifdefs around (some of) the i3c code.

Guenter
Frank Li Nov. 11, 2024, 9:59 p.m. UTC | #2
On Mon, Nov 11, 2024 at 11:44:08AM -0800, Guenter Roeck wrote:
> On 11/11/24 09:32, Frank Li wrote:
> > Add help function tmp108_common_probe() to pave road to support i3c for
> > P3T1085(NXP) chip.
> >
> > Use dev_err_probe() to simple code.
> >
> > Signed-off-by: Frank Li <Frank.Li@nxp.com>
>
> I applied the first two patches of the series, but I am holding back this
> and the subsequent patches since I don't know how the kernel handles having
> two drivers in a single module, and one of them fails to instantiate. I did
> not find a matching example elsewhere in the kernel. We may have to use
> the method used by the st_lsm6dsx driver - essentially splitting the driver
> into three parts (i2c, i3c, and common). That would be overkill; the alternative
> might be something like the approach used by module_i3c_i2c_driver(), but with
> a set of #ifdefs around (some of) the i3c code.

Thanks, let me think more about this.

>
> Guenter
>
diff mbox series

Patch

diff --git a/drivers/hwmon/tmp108.c b/drivers/hwmon/tmp108.c
index b561b452d8d39..bfbea6349a95f 100644
--- a/drivers/hwmon/tmp108.c
+++ b/drivers/hwmon/tmp108.c
@@ -323,33 +323,19 @@  static const struct regmap_config tmp108_regmap_config = {
 	.use_single_write = true,
 };
 
-static int tmp108_probe(struct i2c_client *client)
+static int tmp108_common_probe(struct device *dev, struct regmap *regmap, char *name)
 {
-	struct device *dev = &client->dev;
 	struct device *hwmon_dev;
 	struct tmp108 *tmp108;
-	int err;
 	u32 config;
-
-	if (!i2c_check_functionality(client->adapter,
-				     I2C_FUNC_SMBUS_WORD_DATA)) {
-		dev_err(dev,
-			"adapter doesn't support SMBus word transactions\n");
-		return -ENODEV;
-	}
+	int err;
 
 	tmp108 = devm_kzalloc(dev, sizeof(*tmp108), GFP_KERNEL);
 	if (!tmp108)
 		return -ENOMEM;
 
 	dev_set_drvdata(dev, tmp108);
-
-	tmp108->regmap = devm_regmap_init_i2c(client, &tmp108_regmap_config);
-	if (IS_ERR(tmp108->regmap)) {
-		err = PTR_ERR(tmp108->regmap);
-		dev_err(dev, "regmap init failed: %d", err);
-		return err;
-	}
+	tmp108->regmap = regmap;
 
 	err = regmap_read(tmp108->regmap, TMP108_REG_CONF, &config);
 	if (err < 0) {
@@ -383,13 +369,30 @@  static int tmp108_probe(struct i2c_client *client)
 		return err;
 	}
 
-	hwmon_dev = devm_hwmon_device_register_with_info(dev, client->name,
+	hwmon_dev = devm_hwmon_device_register_with_info(dev, name,
 							 tmp108,
 							 &tmp108_chip_info,
 							 NULL);
 	return PTR_ERR_OR_ZERO(hwmon_dev);
 }
 
+static int tmp108_probe(struct i2c_client *client)
+{
+	struct device *dev = &client->dev;
+	struct regmap *regmap;
+
+	if (!i2c_check_functionality(client->adapter,
+				     I2C_FUNC_SMBUS_WORD_DATA))
+		return dev_err_probe(dev, -ENODEV,
+				     "adapter doesn't support SMBus word transactions\n");
+
+	regmap = devm_regmap_init_i2c(client, &tmp108_regmap_config);
+	if (IS_ERR(regmap))
+		return dev_err_probe(dev, PTR_ERR(regmap), "regmap init failed");
+
+	return tmp108_common_probe(dev, regmap, client->name);
+}
+
 static int tmp108_suspend(struct device *dev)
 {
 	struct tmp108 *tmp108 = dev_get_drvdata(dev);