2023-01-10 14:23:48

by Andy Shevchenko

[permalink] [raw]
Subject: [PATCH v2 0/5] rtc: isl12022: Clean up and simplify the driver

While looking for something else I noticed that this driver is dusted
a bit. Clean up and simplify it using available kernel types and APIs.

Changelog v2:
- added tags to patches 1,2,4,5 (Rasmus)

Andy Shevchenko (5):
rtc: isl12022: Get rid of unneeded private struct isl12022
rtc: isl12022: Explicitly use __le16 type for ISL12022_REG_TEMP_L
rtc: isl12022: Drop unneeded OF guards and of_match_ptr()
rtc: isl12022: Join string literals back
rtc: isl12022: sort header inclusion alphabetically

drivers/rtc/rtc-isl12022.c | 93 ++++++++++++++------------------------
1 file changed, 34 insertions(+), 59 deletions(-)

--
2.39.0


2023-01-10 14:48:17

by Andy Shevchenko

[permalink] [raw]
Subject: [PATCH v2 1/5] rtc: isl12022: Get rid of unneeded private struct isl12022

First of all, the struct rtc_device pointer is kept in the managed
resources, no need to keep it outside (no users in the driver).

Second, replace private struct isl12022 with a regmap.

Signed-off-by: Andy Shevchenko <[email protected]>
Acked-by: Rasmus Villemoes <[email protected]>
---
drivers/rtc/rtc-isl12022.c | 56 ++++++++++++++------------------------
1 file changed, 21 insertions(+), 35 deletions(-)

diff --git a/drivers/rtc/rtc-isl12022.c b/drivers/rtc/rtc-isl12022.c
index a3b0de3393f5..44058fa27277 100644
--- a/drivers/rtc/rtc-isl12022.c
+++ b/drivers/rtc/rtc-isl12022.c
@@ -46,11 +46,6 @@

static struct i2c_driver isl12022_driver;

-struct isl12022 {
- struct rtc_device *rtc;
- struct regmap *regmap;
-};
-
static umode_t isl12022_hwmon_is_visible(const void *data,
enum hwmon_sensor_types type,
u32 attr, int channel)
@@ -67,8 +62,7 @@ static umode_t isl12022_hwmon_is_visible(const void *data,
*/
static int isl12022_hwmon_read_temp(struct device *dev, long *mC)
{
- struct isl12022 *isl12022 = dev_get_drvdata(dev);
- struct regmap *regmap = isl12022->regmap;
+ struct regmap *regmap = dev_get_drvdata(dev);
u8 temp_buf[2];
int temp, ret;

@@ -115,23 +109,21 @@ static const struct hwmon_chip_info isl12022_hwmon_chip_info = {

static void isl12022_hwmon_register(struct device *dev)
{
- struct isl12022 *isl12022;
+ struct regmap *regmap = dev_get_drvdata(dev);
struct device *hwmon;
int ret;

if (!IS_REACHABLE(CONFIG_HWMON))
return;

- isl12022 = dev_get_drvdata(dev);
-
- ret = regmap_update_bits(isl12022->regmap, ISL12022_REG_BETA,
+ ret = regmap_update_bits(regmap, ISL12022_REG_BETA,
ISL12022_BETA_TSE, ISL12022_BETA_TSE);
if (ret) {
dev_warn(dev, "unable to enable temperature sensor\n");
return;
}

- hwmon = devm_hwmon_device_register_with_info(dev, "isl12022", isl12022,
+ hwmon = devm_hwmon_device_register_with_info(dev, "isl12022", regmap,
&isl12022_hwmon_chip_info,
NULL);
if (IS_ERR(hwmon))
@@ -144,8 +136,7 @@ static void isl12022_hwmon_register(struct device *dev)
*/
static int isl12022_rtc_read_time(struct device *dev, struct rtc_time *tm)
{
- struct isl12022 *isl12022 = dev_get_drvdata(dev);
- struct regmap *regmap = isl12022->regmap;
+ struct regmap *regmap = dev_get_drvdata(dev);
uint8_t buf[ISL12022_REG_INT + 1];
int ret;

@@ -190,8 +181,7 @@ static int isl12022_rtc_read_time(struct device *dev, struct rtc_time *tm)

static int isl12022_rtc_set_time(struct device *dev, struct rtc_time *tm)
{
- struct isl12022 *isl12022 = dev_get_drvdata(dev);
- struct regmap *regmap = isl12022->regmap;
+ struct regmap *regmap = dev_get_drvdata(dev);
int ret;
uint8_t buf[ISL12022_REG_DW + 1];

@@ -218,8 +208,7 @@ static int isl12022_rtc_set_time(struct device *dev, struct rtc_time *tm)

buf[ISL12022_REG_DW] = tm->tm_wday & 0x07;

- return regmap_bulk_write(isl12022->regmap, ISL12022_REG_SC,
- buf, sizeof(buf));
+ return regmap_bulk_write(regmap, ISL12022_REG_SC, buf, sizeof(buf));
}

static const struct rtc_class_ops isl12022_rtc_ops = {
@@ -235,34 +224,31 @@ static const struct regmap_config regmap_config = {

static int isl12022_probe(struct i2c_client *client)
{
- struct isl12022 *isl12022;
+ struct rtc_device *rtc;
+ struct regmap *regmap;

if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C))
return -ENODEV;

- isl12022 = devm_kzalloc(&client->dev, sizeof(struct isl12022),
- GFP_KERNEL);
- if (!isl12022)
- return -ENOMEM;
- dev_set_drvdata(&client->dev, isl12022);
-
- isl12022->regmap = devm_regmap_init_i2c(client, &regmap_config);
- if (IS_ERR(isl12022->regmap)) {
+ regmap = devm_regmap_init_i2c(client, &regmap_config);
+ if (IS_ERR(regmap)) {
dev_err(&client->dev, "regmap allocation failed\n");
- return PTR_ERR(isl12022->regmap);
+ return PTR_ERR(regmap);
}

+ dev_set_drvdata(&client->dev, regmap);
+
isl12022_hwmon_register(&client->dev);

- isl12022->rtc = devm_rtc_allocate_device(&client->dev);
- if (IS_ERR(isl12022->rtc))
- return PTR_ERR(isl12022->rtc);
+ rtc = devm_rtc_allocate_device(&client->dev);
+ if (IS_ERR(rtc))
+ return PTR_ERR(rtc);

- isl12022->rtc->ops = &isl12022_rtc_ops;
- isl12022->rtc->range_min = RTC_TIMESTAMP_BEGIN_2000;
- isl12022->rtc->range_max = RTC_TIMESTAMP_END_2099;
+ rtc->ops = &isl12022_rtc_ops;
+ rtc->range_min = RTC_TIMESTAMP_BEGIN_2000;
+ rtc->range_max = RTC_TIMESTAMP_END_2099;

- return devm_rtc_register_device(isl12022->rtc);
+ return devm_rtc_register_device(rtc);
}

#ifdef CONFIG_OF
--
2.39.0

2023-01-10 14:58:52

by Andy Shevchenko

[permalink] [raw]
Subject: [PATCH v2 2/5] rtc: isl12022: Explicitly use __le16 type for ISL12022_REG_TEMP_L

We are reading 10-bit value in a 16-bit register in LE format.
Make this explicit by using __le16 type for it and corresponding
conversion function.

Signed-off-by: Andy Shevchenko <[email protected]>
Acked-by: Rasmus Villemoes <[email protected]>
---
drivers/rtc/rtc-isl12022.c | 9 +++++----
1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/drivers/rtc/rtc-isl12022.c b/drivers/rtc/rtc-isl12022.c
index 44058fa27277..bf1aa6f6560d 100644
--- a/drivers/rtc/rtc-isl12022.c
+++ b/drivers/rtc/rtc-isl12022.c
@@ -19,6 +19,8 @@
#include <linux/regmap.h>
#include <linux/hwmon.h>

+#include <asm/byteorder.h>
+
/* ISL register offsets */
#define ISL12022_REG_SC 0x00
#define ISL12022_REG_MN 0x01
@@ -63,17 +65,16 @@ static umode_t isl12022_hwmon_is_visible(const void *data,
static int isl12022_hwmon_read_temp(struct device *dev, long *mC)
{
struct regmap *regmap = dev_get_drvdata(dev);
- u8 temp_buf[2];
int temp, ret;
+ __le16 buf;

- ret = regmap_bulk_read(regmap, ISL12022_REG_TEMP_L,
- temp_buf, sizeof(temp_buf));
+ ret = regmap_bulk_read(regmap, ISL12022_REG_TEMP_L, &buf, sizeof(buf));
if (ret)
return ret;
/*
* Temperature is represented as a 10-bit number, unit half-Kelvins.
*/
- temp = (temp_buf[1] << 8) | temp_buf[0];
+ temp = le16_to_cpu(buf);
temp *= 500;
temp -= 273000;

--
2.39.0

2023-01-10 14:59:46

by Andy Shevchenko

[permalink] [raw]
Subject: [PATCH v2 5/5] rtc: isl12022: sort header inclusion alphabetically

Sort header inclusion alphabetically for better maintenance.

Signed-off-by: Andy Shevchenko <[email protected]>
Acked-by: Rasmus Villemoes <[email protected]>
---
drivers/rtc/rtc-isl12022.c | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/drivers/rtc/rtc-isl12022.c b/drivers/rtc/rtc-isl12022.c
index ee38c5067ea8..e68a79b5e00e 100644
--- a/drivers/rtc/rtc-isl12022.c
+++ b/drivers/rtc/rtc-isl12022.c
@@ -8,14 +8,14 @@
* by Alessandro Zummo <[email protected]>.
*/

-#include <linux/i2c.h>
#include <linux/bcd.h>
-#include <linux/rtc.h>
-#include <linux/slab.h>
-#include <linux/module.h>
#include <linux/err.h>
-#include <linux/regmap.h>
#include <linux/hwmon.h>
+#include <linux/i2c.h>
+#include <linux/module.h>
+#include <linux/regmap.h>
+#include <linux/rtc.h>
+#include <linux/slab.h>

#include <asm/byteorder.h>

--
2.39.0

2023-02-22 20:10:26

by Alexandre Belloni

[permalink] [raw]
Subject: Re: [PATCH v2 0/5] rtc: isl12022: Clean up and simplify the driver


On Tue, 10 Jan 2023 16:08:01 +0200, Andy Shevchenko wrote:
> While looking for something else I noticed that this driver is dusted
> a bit. Clean up and simplify it using available kernel types and APIs.
>
> Changelog v2:
> - added tags to patches 1,2,4,5 (Rasmus)
>
> Andy Shevchenko (5):
> rtc: isl12022: Get rid of unneeded private struct isl12022
> rtc: isl12022: Explicitly use __le16 type for ISL12022_REG_TEMP_L
> rtc: isl12022: Drop unneeded OF guards and of_match_ptr()
> rtc: isl12022: Join string literals back
> rtc: isl12022: sort header inclusion alphabetically
>
> [...]

Applied, thanks!

[1/5] rtc: isl12022: Get rid of unneeded private struct isl12022
commit: f525b210e9d4dcefb88594d50e426068e62840f4
[2/5] rtc: isl12022: Explicitly use __le16 type for ISL12022_REG_TEMP_L
commit: 93219a4fb8bdf279f749b5eef40bef1bbe805fc3
[3/5] rtc: isl12022: Drop unneeded OF guards and of_match_ptr()
commit: c8ae2735cb3d28892fd734804b60e5abf1f6fa91
[4/5] rtc: isl12022: Join string literals back
commit: 9bb1e189d7d2c3838938efcc497333803b946081
[5/5] rtc: isl12022: sort header inclusion alphabetically
commit: 303eac653a181be59674920725142cfbdd5ba4cd

Best regards,

--
Alexandre Belloni, co-owner and COO, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com