Skip to content

Commit f525b21

Browse files
andy-shevalexandrebelloni
authored andcommitted
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]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Alexandre Belloni <[email protected]>
1 parent fd9a6a1 commit f525b21

File tree

1 file changed

+21
-35
lines changed

1 file changed

+21
-35
lines changed

drivers/rtc/rtc-isl12022.c

Lines changed: 21 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,6 @@
4646

4747
static struct i2c_driver isl12022_driver;
4848

49-
struct isl12022 {
50-
struct rtc_device *rtc;
51-
struct regmap *regmap;
52-
};
53-
5449
static umode_t isl12022_hwmon_is_visible(const void *data,
5550
enum hwmon_sensor_types type,
5651
u32 attr, int channel)
@@ -67,8 +62,7 @@ static umode_t isl12022_hwmon_is_visible(const void *data,
6762
*/
6863
static int isl12022_hwmon_read_temp(struct device *dev, long *mC)
6964
{
70-
struct isl12022 *isl12022 = dev_get_drvdata(dev);
71-
struct regmap *regmap = isl12022->regmap;
65+
struct regmap *regmap = dev_get_drvdata(dev);
7266
u8 temp_buf[2];
7367
int temp, ret;
7468

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

116110
static void isl12022_hwmon_register(struct device *dev)
117111
{
118-
struct isl12022 *isl12022;
112+
struct regmap *regmap = dev_get_drvdata(dev);
119113
struct device *hwmon;
120114
int ret;
121115

122116
if (!IS_REACHABLE(CONFIG_HWMON))
123117
return;
124118

125-
isl12022 = dev_get_drvdata(dev);
126-
127-
ret = regmap_update_bits(isl12022->regmap, ISL12022_REG_BETA,
119+
ret = regmap_update_bits(regmap, ISL12022_REG_BETA,
128120
ISL12022_BETA_TSE, ISL12022_BETA_TSE);
129121
if (ret) {
130122
dev_warn(dev, "unable to enable temperature sensor\n");
131123
return;
132124
}
133125

134-
hwmon = devm_hwmon_device_register_with_info(dev, "isl12022", isl12022,
126+
hwmon = devm_hwmon_device_register_with_info(dev, "isl12022", regmap,
135127
&isl12022_hwmon_chip_info,
136128
NULL);
137129
if (IS_ERR(hwmon))
@@ -144,8 +136,7 @@ static void isl12022_hwmon_register(struct device *dev)
144136
*/
145137
static int isl12022_rtc_read_time(struct device *dev, struct rtc_time *tm)
146138
{
147-
struct isl12022 *isl12022 = dev_get_drvdata(dev);
148-
struct regmap *regmap = isl12022->regmap;
139+
struct regmap *regmap = dev_get_drvdata(dev);
149140
uint8_t buf[ISL12022_REG_INT + 1];
150141
int ret;
151142

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

191182
static int isl12022_rtc_set_time(struct device *dev, struct rtc_time *tm)
192183
{
193-
struct isl12022 *isl12022 = dev_get_drvdata(dev);
194-
struct regmap *regmap = isl12022->regmap;
184+
struct regmap *regmap = dev_get_drvdata(dev);
195185
int ret;
196186
uint8_t buf[ISL12022_REG_DW + 1];
197187

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

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

221-
return regmap_bulk_write(isl12022->regmap, ISL12022_REG_SC,
222-
buf, sizeof(buf));
211+
return regmap_bulk_write(regmap, ISL12022_REG_SC, buf, sizeof(buf));
223212
}
224213

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

236225
static int isl12022_probe(struct i2c_client *client)
237226
{
238-
struct isl12022 *isl12022;
227+
struct rtc_device *rtc;
228+
struct regmap *regmap;
239229

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

243-
isl12022 = devm_kzalloc(&client->dev, sizeof(struct isl12022),
244-
GFP_KERNEL);
245-
if (!isl12022)
246-
return -ENOMEM;
247-
dev_set_drvdata(&client->dev, isl12022);
248-
249-
isl12022->regmap = devm_regmap_init_i2c(client, &regmap_config);
250-
if (IS_ERR(isl12022->regmap)) {
233+
regmap = devm_regmap_init_i2c(client, &regmap_config);
234+
if (IS_ERR(regmap)) {
251235
dev_err(&client->dev, "regmap allocation failed\n");
252-
return PTR_ERR(isl12022->regmap);
236+
return PTR_ERR(regmap);
253237
}
254238

239+
dev_set_drvdata(&client->dev, regmap);
240+
255241
isl12022_hwmon_register(&client->dev);
256242

257-
isl12022->rtc = devm_rtc_allocate_device(&client->dev);
258-
if (IS_ERR(isl12022->rtc))
259-
return PTR_ERR(isl12022->rtc);
243+
rtc = devm_rtc_allocate_device(&client->dev);
244+
if (IS_ERR(rtc))
245+
return PTR_ERR(rtc);
260246

261-
isl12022->rtc->ops = &isl12022_rtc_ops;
262-
isl12022->rtc->range_min = RTC_TIMESTAMP_BEGIN_2000;
263-
isl12022->rtc->range_max = RTC_TIMESTAMP_END_2099;
247+
rtc->ops = &isl12022_rtc_ops;
248+
rtc->range_min = RTC_TIMESTAMP_BEGIN_2000;
249+
rtc->range_max = RTC_TIMESTAMP_END_2099;
264250

265-
return devm_rtc_register_device(isl12022->rtc);
251+
return devm_rtc_register_device(rtc);
266252
}
267253

268254
#ifdef CONFIG_OF

0 commit comments

Comments
 (0)