Commit ed3c52a0 authored by Trent Piepho's avatar Trent Piepho Committed by Alexandre Belloni

rtc: isl1208: Introduce driver state struct

This driver has no state of its own, depending entirely on what is in
the generic rtc device.

Intoduce a state struct.  For now it only contains a pointer to the rtc
device struct, but future patches will add more data.

Cc: Alessandro Zummo <a.zummo@towertech.it>
Cc: Alexandre Belloni <alexandre.belloni@bootlin.com>
Signed-off-by: default avatarTrent Piepho <tpiepho@impinj.com>
Signed-off-by: default avatarAlexandre Belloni <alexandre.belloni@bootlin.com>
parent 5736610a
...@@ -79,6 +79,11 @@ enum { ...@@ -79,6 +79,11 @@ enum {
TYPE_ISL1219, TYPE_ISL1219,
}; };
/* Device state */
struct isl1208_state {
struct rtc_device *rtc;
};
/* block read */ /* block read */
static int static int
isl1208_i2c_read_regs(struct i2c_client *client, u8 reg, u8 buf[], isl1208_i2c_read_regs(struct i2c_client *client, u8 reg, u8 buf[],
...@@ -557,7 +562,7 @@ isl1208_rtc_interrupt(int irq, void *data) ...@@ -557,7 +562,7 @@ isl1208_rtc_interrupt(int irq, void *data)
{ {
unsigned long timeout = jiffies + msecs_to_jiffies(1000); unsigned long timeout = jiffies + msecs_to_jiffies(1000);
struct i2c_client *client = data; struct i2c_client *client = data;
struct rtc_device *rtc = i2c_get_clientdata(client); struct isl1208_state *isl1208 = i2c_get_clientdata(client);
int handled = 0, sr, err; int handled = 0, sr, err;
/* /*
...@@ -580,7 +585,7 @@ isl1208_rtc_interrupt(int irq, void *data) ...@@ -580,7 +585,7 @@ isl1208_rtc_interrupt(int irq, void *data)
if (sr & ISL1208_REG_SR_ALM) { if (sr & ISL1208_REG_SR_ALM) {
dev_dbg(&client->dev, "alarm!\n"); dev_dbg(&client->dev, "alarm!\n");
rtc_update_irq(rtc, 1, RTC_IRQF | RTC_AF); rtc_update_irq(isl1208->rtc, 1, RTC_IRQF | RTC_AF);
/* Clear the alarm */ /* Clear the alarm */
sr &= ~ISL1208_REG_SR_ALM; sr &= ~ISL1208_REG_SR_ALM;
...@@ -598,7 +603,7 @@ isl1208_rtc_interrupt(int irq, void *data) ...@@ -598,7 +603,7 @@ isl1208_rtc_interrupt(int irq, void *data)
} }
if (sr & ISL1208_REG_SR_EVT) { if (sr & ISL1208_REG_SR_EVT) {
sysfs_notify(&rtc->dev.kobj, NULL, sysfs_notify(&isl1208->rtc->dev.kobj, NULL,
dev_attr_timestamp0.attr.name); dev_attr_timestamp0.attr.name);
dev_warn(&client->dev, "event detected"); dev_warn(&client->dev, "event detected");
handled = 1; handled = 1;
...@@ -723,7 +728,7 @@ static int ...@@ -723,7 +728,7 @@ static int
isl1208_probe(struct i2c_client *client, const struct i2c_device_id *id) isl1208_probe(struct i2c_client *client, const struct i2c_device_id *id)
{ {
int rc = 0; int rc = 0;
struct rtc_device *rtc; struct isl1208_state *isl1208;
int evdet_irq = -1; int evdet_irq = -1;
if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C))
...@@ -732,13 +737,17 @@ isl1208_probe(struct i2c_client *client, const struct i2c_device_id *id) ...@@ -732,13 +737,17 @@ isl1208_probe(struct i2c_client *client, const struct i2c_device_id *id)
if (isl1208_i2c_validate_client(client) < 0) if (isl1208_i2c_validate_client(client) < 0)
return -ENODEV; return -ENODEV;
rtc = devm_rtc_allocate_device(&client->dev); /* Allocate driver state, point i2c client data to it */
if (IS_ERR(rtc)) isl1208 = devm_kzalloc(&client->dev, sizeof(*isl1208), GFP_KERNEL);
return PTR_ERR(rtc); if (!isl1208)
return -ENOMEM;
i2c_set_clientdata(client, isl1208);
rtc->ops = &isl1208_rtc_ops; isl1208->rtc = devm_rtc_allocate_device(&client->dev);
if (IS_ERR(isl1208->rtc))
return PTR_ERR(isl1208->rtc);
i2c_set_clientdata(client, rtc); isl1208->rtc->ops = &isl1208_rtc_ops;
rc = isl1208_i2c_get_sr(client); rc = isl1208_i2c_get_sr(client);
if (rc < 0) { if (rc < 0) {
...@@ -771,13 +780,13 @@ isl1208_probe(struct i2c_client *client, const struct i2c_device_id *id) ...@@ -771,13 +780,13 @@ isl1208_probe(struct i2c_client *client, const struct i2c_device_id *id)
dev_err(&client->dev, "could not enable tamper detection\n"); dev_err(&client->dev, "could not enable tamper detection\n");
return rc; return rc;
} }
rc = rtc_add_group(rtc, &isl1219_rtc_sysfs_files); rc = rtc_add_group(isl1208->rtc, &isl1219_rtc_sysfs_files);
if (rc) if (rc)
return rc; return rc;
evdet_irq = of_irq_get_byname(np, "evdet"); evdet_irq = of_irq_get_byname(np, "evdet");
} }
rc = rtc_add_group(rtc, &isl1208_rtc_sysfs_files); rc = rtc_add_group(isl1208->rtc, &isl1208_rtc_sysfs_files);
if (rc) if (rc)
return rc; return rc;
...@@ -791,7 +800,7 @@ isl1208_probe(struct i2c_client *client, const struct i2c_device_id *id) ...@@ -791,7 +800,7 @@ isl1208_probe(struct i2c_client *client, const struct i2c_device_id *id)
if (rc) if (rc)
return rc; return rc;
return rtc_register_device(rtc); return rtc_register_device(isl1208->rtc);
} }
static const struct i2c_device_id isl1208_id[] = { static const struct i2c_device_id isl1208_id[] = {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment