rtc: s35390a: convert to devm_i2c_new_dummy_device()
I was about to simplify the call to i2c_unregister_device() when I realized that converting to devm_i2c_new_dummy_device() will simplify the driver a lot. So I took this approach. Signed-off-by: Wolfram Sang <wsa+renesas@sang-engineering.com> Link: https://lore.kernel.org/r/20190830133124.21633-3-wsa+renesas@sang-engineering.com Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
This commit is contained in:
parent
59a7f24fce
commit
4053e74996
|
@ -434,37 +434,32 @@ static int s35390a_probe(struct i2c_client *client,
|
||||||
char buf, status1;
|
char buf, status1;
|
||||||
struct device *dev = &client->dev;
|
struct device *dev = &client->dev;
|
||||||
|
|
||||||
if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) {
|
if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C))
|
||||||
err = -ENODEV;
|
return -ENODEV;
|
||||||
goto exit;
|
|
||||||
}
|
|
||||||
|
|
||||||
s35390a = devm_kzalloc(dev, sizeof(struct s35390a), GFP_KERNEL);
|
s35390a = devm_kzalloc(dev, sizeof(struct s35390a), GFP_KERNEL);
|
||||||
if (!s35390a) {
|
if (!s35390a)
|
||||||
err = -ENOMEM;
|
return -ENOMEM;
|
||||||
goto exit;
|
|
||||||
}
|
|
||||||
|
|
||||||
s35390a->client[0] = client;
|
s35390a->client[0] = client;
|
||||||
i2c_set_clientdata(client, s35390a);
|
i2c_set_clientdata(client, s35390a);
|
||||||
|
|
||||||
/* This chip uses multiple addresses, use dummy devices for them */
|
/* This chip uses multiple addresses, use dummy devices for them */
|
||||||
for (i = 1; i < 8; ++i) {
|
for (i = 1; i < 8; ++i) {
|
||||||
s35390a->client[i] = i2c_new_dummy_device(client->adapter,
|
s35390a->client[i] = devm_i2c_new_dummy_device(dev,
|
||||||
client->addr + i);
|
client->adapter,
|
||||||
|
client->addr + i);
|
||||||
if (IS_ERR(s35390a->client[i])) {
|
if (IS_ERR(s35390a->client[i])) {
|
||||||
dev_err(dev, "Address %02x unavailable\n",
|
dev_err(dev, "Address %02x unavailable\n",
|
||||||
client->addr + i);
|
client->addr + i);
|
||||||
err = PTR_ERR(s35390a->client[i]);
|
return PTR_ERR(s35390a->client[i]);
|
||||||
goto exit_dummy;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
err_read = s35390a_read_status(s35390a, &status1);
|
err_read = s35390a_read_status(s35390a, &status1);
|
||||||
if (err_read < 0) {
|
if (err_read < 0) {
|
||||||
err = err_read;
|
|
||||||
dev_err(dev, "error resetting chip\n");
|
dev_err(dev, "error resetting chip\n");
|
||||||
goto exit_dummy;
|
return err_read;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (status1 & S35390A_FLAG_24H)
|
if (status1 & S35390A_FLAG_24H)
|
||||||
|
@ -478,13 +473,13 @@ static int s35390a_probe(struct i2c_client *client,
|
||||||
err = s35390a_set_reg(s35390a, S35390A_CMD_STATUS2, &buf, 1);
|
err = s35390a_set_reg(s35390a, S35390A_CMD_STATUS2, &buf, 1);
|
||||||
if (err < 0) {
|
if (err < 0) {
|
||||||
dev_err(dev, "error disabling alarm");
|
dev_err(dev, "error disabling alarm");
|
||||||
goto exit_dummy;
|
return err;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
err = s35390a_disable_test_mode(s35390a);
|
err = s35390a_disable_test_mode(s35390a);
|
||||||
if (err < 0) {
|
if (err < 0) {
|
||||||
dev_err(dev, "error disabling test mode\n");
|
dev_err(dev, "error disabling test mode\n");
|
||||||
goto exit_dummy;
|
return err;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -493,10 +488,8 @@ static int s35390a_probe(struct i2c_client *client,
|
||||||
s35390a->rtc = devm_rtc_device_register(dev, s35390a_driver.driver.name,
|
s35390a->rtc = devm_rtc_device_register(dev, s35390a_driver.driver.name,
|
||||||
&s35390a_rtc_ops, THIS_MODULE);
|
&s35390a_rtc_ops, THIS_MODULE);
|
||||||
|
|
||||||
if (IS_ERR(s35390a->rtc)) {
|
if (IS_ERR(s35390a->rtc))
|
||||||
err = PTR_ERR(s35390a->rtc);
|
return PTR_ERR(s35390a->rtc);
|
||||||
goto exit_dummy;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* supports per-minute alarms only, therefore set uie_unsupported */
|
/* supports per-minute alarms only, therefore set uie_unsupported */
|
||||||
s35390a->rtc->uie_unsupported = 1;
|
s35390a->rtc->uie_unsupported = 1;
|
||||||
|
@ -505,26 +498,6 @@ static int s35390a_probe(struct i2c_client *client,
|
||||||
rtc_update_irq(s35390a->rtc, 1, RTC_AF);
|
rtc_update_irq(s35390a->rtc, 1, RTC_AF);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
exit_dummy:
|
|
||||||
for (i = 1; i < 8; ++i)
|
|
||||||
if (s35390a->client[i])
|
|
||||||
i2c_unregister_device(s35390a->client[i]);
|
|
||||||
|
|
||||||
exit:
|
|
||||||
return err;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int s35390a_remove(struct i2c_client *client)
|
|
||||||
{
|
|
||||||
unsigned int i;
|
|
||||||
struct s35390a *s35390a = i2c_get_clientdata(client);
|
|
||||||
|
|
||||||
for (i = 1; i < 8; ++i)
|
|
||||||
if (s35390a->client[i])
|
|
||||||
i2c_unregister_device(s35390a->client[i]);
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct i2c_driver s35390a_driver = {
|
static struct i2c_driver s35390a_driver = {
|
||||||
|
@ -533,7 +506,6 @@ static struct i2c_driver s35390a_driver = {
|
||||||
.of_match_table = of_match_ptr(s35390a_of_match),
|
.of_match_table = of_match_ptr(s35390a_of_match),
|
||||||
},
|
},
|
||||||
.probe = s35390a_probe,
|
.probe = s35390a_probe,
|
||||||
.remove = s35390a_remove,
|
|
||||||
.id_table = s35390a_id,
|
.id_table = s35390a_id,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue