Skip to content

Commit 700f325

Browse files
nxpfrankligroeck
authored andcommitted
hwmon: (tmp108) Add helper function tmp108_common_probe() to prepare I3C support
Add help function tmp108_common_probe() to pave road to support i3c for P3T1085(NXP) chip. Use dev_err_probe() to simplify the code. Signed-off-by: Frank Li <[email protected]> Message-ID: <[email protected]> Signed-off-by: Guenter Roeck <[email protected]>
1 parent fabb1f8 commit 700f325

File tree

1 file changed

+21
-18
lines changed

1 file changed

+21
-18
lines changed

drivers/hwmon/tmp108.c

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -323,33 +323,19 @@ static const struct regmap_config tmp108_regmap_config = {
323323
.use_single_write = true,
324324
};
325325

326-
static int tmp108_probe(struct i2c_client *client)
326+
static int tmp108_common_probe(struct device *dev, struct regmap *regmap, char *name)
327327
{
328-
struct device *dev = &client->dev;
329328
struct device *hwmon_dev;
330329
struct tmp108 *tmp108;
331-
int err;
332330
u32 config;
333-
334-
if (!i2c_check_functionality(client->adapter,
335-
I2C_FUNC_SMBUS_WORD_DATA)) {
336-
dev_err(dev,
337-
"adapter doesn't support SMBus word transactions\n");
338-
return -ENODEV;
339-
}
331+
int err;
340332

341333
tmp108 = devm_kzalloc(dev, sizeof(*tmp108), GFP_KERNEL);
342334
if (!tmp108)
343335
return -ENOMEM;
344336

345337
dev_set_drvdata(dev, tmp108);
346-
347-
tmp108->regmap = devm_regmap_init_i2c(client, &tmp108_regmap_config);
348-
if (IS_ERR(tmp108->regmap)) {
349-
err = PTR_ERR(tmp108->regmap);
350-
dev_err(dev, "regmap init failed: %d", err);
351-
return err;
352-
}
338+
tmp108->regmap = regmap;
353339

354340
err = regmap_read(tmp108->regmap, TMP108_REG_CONF, &config);
355341
if (err < 0) {
@@ -383,13 +369,30 @@ static int tmp108_probe(struct i2c_client *client)
383369
return err;
384370
}
385371

386-
hwmon_dev = devm_hwmon_device_register_with_info(dev, client->name,
372+
hwmon_dev = devm_hwmon_device_register_with_info(dev, name,
387373
tmp108,
388374
&tmp108_chip_info,
389375
NULL);
390376
return PTR_ERR_OR_ZERO(hwmon_dev);
391377
}
392378

379+
static int tmp108_probe(struct i2c_client *client)
380+
{
381+
struct device *dev = &client->dev;
382+
struct regmap *regmap;
383+
384+
if (!i2c_check_functionality(client->adapter,
385+
I2C_FUNC_SMBUS_WORD_DATA))
386+
return dev_err_probe(dev, -ENODEV,
387+
"adapter doesn't support SMBus word transactions\n");
388+
389+
regmap = devm_regmap_init_i2c(client, &tmp108_regmap_config);
390+
if (IS_ERR(regmap))
391+
return dev_err_probe(dev, PTR_ERR(regmap), "regmap init failed");
392+
393+
return tmp108_common_probe(dev, regmap, client->name);
394+
}
395+
393396
static int tmp108_suspend(struct device *dev)
394397
{
395398
struct tmp108 *tmp108 = dev_get_drvdata(dev);

0 commit comments

Comments
 (0)