Skip to contentSkip to conversation

rtc: isl12026: Add driver.

PATCH Superseded David Daney 4 participants 6 messages Feb 14, 2018 – Feb 16, 2018

Subsystems (2)

v2 of 6 Superseded Latest is v6 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 rtc: isl12026: Add driver.

The ISL12026 is a combination RTC and EEPROM device with I2C interface. The standard RTC driver interface is provided. The EEPROM is accessed via the NVMEM interface via the "eeprom0" directory in the sysfs entry for the device.

---

Changes from v1:

o Fixed device tree bindings document example.

o Use RTC_NVMEM facility for eeprom support.

o Small code cleanups suggested by reviewers.

 .../devicetree/bindings/rtc/isil,isl12026.txt      |  28 ++
 drivers/rtc/Kconfig                                |   9 +
 drivers/rtc/Makefile                               |   1 +
 drivers/rtc/rtc-isl12026.c                         | 526 +++++++++++++++++++++
 4 files changed, 564 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/rtc/isil,isl12026.txt
 create mode 100644 drivers/rtc/rtc-isl12026.c
Documentation/devicetree/bindings/rtc/isil,isl12026.txt new file +28 -0
new file mode 100644
index 000000000000..2e0be45193bb
@@ -0,0 +1,28 @@
+ISL12026 I2C RTC/EEPROM
+
+ISL12026 is an I2C RTC/EEPROM combination device.  The RTC and control
+registers respond at bus address 0x6f, and the EEPROM array responds
+at bus address 0x57.  The canonical "reg" value will be for the RTC portion.
+
+Required properties supported by the device:
+
+ - "compatible": must be "isil,isl12026"
+ - "reg": I2C bus address of the device (always 0x6f)
+
+Optional properties:
+
+ - "isil,pwr-bsw": If present PWR.BSW bit must be set to the specified
+                   value for proper operation.
+
+ - "isil,pwr-sbib": If present PWR.SBIB bit must be set to the specified
+                    value for proper operation.
+
+
+Example:
+
+	rtc@6f {
+		compatible = "isil,isl12026";
+		reg = <0x6f>;
+		isil,pwr-bsw = <0>;
+		isil,pwr-sbib = <1>;
+	}
drivers/rtc/Kconfig +9 -0
index 8ab5f0a5d323..85171e9e3ada 100644
@@ -407,6 +407,15 @@ config RTC_DRV_ISL12022
 	  This driver can also be built as a module. If so, the module
 	  will be called rtc-isl12022.
 
+config RTC_DRV_ISL12026
+	tristate "Intersil ISL12026"
+	help
+	  If you say yes here you get support for the
+	  Intersil ISL12026 RTC chip.
+
+	  This driver can also be built as a module. If so, the module
+	  will be called rtc-isl12026.
+
 config RTC_DRV_X1205
 	tristate "Xicor/Intersil X1205"
 	help
drivers/rtc/Makefile +1 -0
index 4fbf87e45a7c..f481661a6eae 100644
@@ -76,6 +76,7 @@ obj-$(CONFIG_RTC_DRV_HID_SENSOR_TIME) += rtc-hid-sensor-time.o
 obj-$(CONFIG_RTC_DRV_HYM8563)	+= rtc-hym8563.o
 obj-$(CONFIG_RTC_DRV_IMXDI)	+= rtc-imxdi.o
 obj-$(CONFIG_RTC_DRV_ISL12022)	+= rtc-isl12022.o
+obj-$(CONFIG_RTC_DRV_ISL12026)	+= rtc-isl12026.o
 obj-$(CONFIG_RTC_DRV_ISL1208)	+= rtc-isl1208.o
 obj-$(CONFIG_RTC_DRV_JZ4740)	+= rtc-jz4740.o
 obj-$(CONFIG_RTC_DRV_LP8788)	+= rtc-lp8788.o
drivers/rtc/rtc-isl12026.c new file +526 -0

526 lines not on this page · raw message

Signature · 1 line
2.14.3
#1 lore raw
Quoted 4 lines · David Daney

The ISL12026 is a combination RTC and EEPROM device with I2C interface. The standard RTC driver interface is provided. The EEPROM is accessed via the NVMEM interface via the "eeprom0" directory in the sysfs entry for the device.

Thanks for an update, my comments below.

drivers/rtc/rtc-isl12026.c line 43

Quoted 10 lines
drivers/rtc/rtc-isl12026.c new file +9 -0
+struct isl12026 {
+       struct rtc_device *rtc;
+       struct i2c_client *nvm_client;
+       struct nvmem_config nvm_cfg;
+       /*
+        * RTC write operations require that multiple messages be
+        * transmitted, we hold the lock for all accesses to the
+        * device so that these sequences cannot be disrupted.  Also,
 
+        * the write cycle to the nvmem takes many mS during which the

What mS means? milliseconds? The standard abbreviation for it 'ms'.

Quoted 8 lines
drivers/rtc/rtc-isl12026.c new file +7 -0
+        * device does not respond to commands, so holding the lock
+        * also prevents access during these times.
+        */
+       struct mutex lock;
+};
 
+static int isl12026_read_reg(struct i2c_client *client, int reg)
+{

drivers/rtc/rtc-isl12026.c line 83

Quoted 10 lines
drivers/rtc/rtc-isl12026.c new file +8 -0
 
+       ret = i2c_transfer(client->adapter, msgs, ARRAY_SIZE(msgs));
+       if (ret != ARRAY_SIZE(msgs)) {
+               dev_err(&client->dev, "read reg error, ret=%d\n", ret);
+               ret = ret < 0 ? ret : -EIO;
+       } else {
+               ret = val;
+       }
 
+       return val;

Something wrong. ret is not used after all.

Quoted 1 line

+}

Check entire code for such.

drivers/rtc/rtc-isl12026.c line 332

Quoted 3 lines
drivers/rtc/rtc-isl12026.c new file +3 -0
+       /* 2 bytes of address, most significant first */
+       addr[0] = (offset >> 8) & 0xff;
+       addr[1] = offset & 0xff;

Consider to drop '& 0xff', they are pointless (you have u8 type).

drivers/rtc/rtc-isl12026.c line 380

Quoted 2 lines
drivers/rtc/rtc-isl12026.c new file +2 -0
+               payload[0] = (offset >> 8) & 0xff;
+               payload[1] = offset & 0xff;

Ditto.

drivers/rtc/rtc-isl12026.c line 410

Quoted 12 lines
drivers/rtc/rtc-isl12026.c new file +10 -0
+static void isl12026_force_power_modes(struct i2c_client *client)
+{
+       int ret;
+       int pwr, requested_pwr;
+       u32 bsw_val, sbib_val;
 
+       bool set_bsw, set_sbib;
+
 
+       ret = of_property_read_u32(client->dev.of_node,
+                                  "isil,pwr-bsw", &bsw_val);
+       set_bsw = (ret == 0);

Which is not fully correct. Better to do

set_bsw = of_property_present();

ret = of_property_read...();
if (ret)
return ret;

drivers/rtc/rtc-isl12026.c line 414

Quoted 4 lines
drivers/rtc/rtc-isl12026.c new file +4 -0
+
+       ret = of_property_read_u32(client->dev.of_node,
+                                  "isil,pwr-sbib", &sbib_val);
+       set_sbib = (ret == 0);

Ditto.

drivers/rtc/rtc-isl12026.c line 418

Quoted 5 lines
drivers/rtc/rtc-isl12026.c new file +4 -0
+
+       /* Check if PWR.BSW and/or PWR.SBIB need specified values */
+
 
+       if (set_bsw || set_sbib) {

if (!x && !y)
return;

Quoted 5 lines
drivers/rtc/rtc-isl12026.c new file +5 -0
+               pwr = isl12026_read_reg(client, ISL12026_REG_PWR);
+               if (pwr < 0) {
+                       dev_err(&client->dev,
+                               "Error: Failed to read PWR %d\n", pwr);
+                       return;

drivers/rtc/rtc-isl12026.c line 433

Quoted 10 lines
drivers/rtc/rtc-isl12026.c new file +10 -0
+               }
+
+               requested_pwr = pwr;
+
+               if (set_bsw) {
+                       if (bsw_val)
+                               requested_pwr |= ISL12026_REG_PWR_BSW;
+                       else
+                               requested_pwr &= ~ISL12026_REG_PWR_BSW;
+               }

Undefined state if no value?

drivers/rtc/rtc-isl12026.c line 439

Quoted 6 lines
drivers/rtc/rtc-isl12026.c new file +6 -0
+               if (set_sbib) {
+                       if (sbib_val)
+                               requested_pwr |= ISL12026_REG_PWR_SBIB;
+                       else
+                               requested_pwr &= ~ISL12026_REG_PWR_SBIB;
+               }

Ditto.

drivers/rtc/rtc-isl12026.c line 446

Quoted 8 lines
drivers/rtc/rtc-isl12026.c new file +7 -0
+
+               if (pwr >= 0 && pwr != requested_pwr) {
 
+                       dev_info(&client->dev, "PWR: %02x\n", (u8)pwr);
+                       dev_info(&client->dev,
+                                "Updating PWR to: %02x\n", (u8)requested_pwr);
+                       isl12026_write_reg(client,
+                                          ISL12026_REG_PWR, requested_pwr);

If you do explicit casting in printf() parameters you are doing something wrong in 99.9% cases.

drivers/rtc/rtc-isl12026.c line 470

Quoted 12 lines
drivers/rtc/rtc-isl12026.c new file +9 -0
+               }
+       }
+}
 
+static int isl12026_probe_new(struct i2c_client *client)
+{
+       struct isl12026 *priv;
+       int ret;
 
 
+       /* The NVMem array responds at i2c address 0x57 */
+       priv->nvm_client = i2c_new_dummy(client->adapter, 0x57);

Magic. Make it #define and put comment there.

drivers/rtc/rtc-isl12026.c line 506

Quoted 6 lines
drivers/rtc/rtc-isl12026.c new file +4 -0
+       if (!priv->nvm_client)
+               return -ENOMEM;
 
+}
 
+#ifdef CONFIG_OF

Remove this ugly #ifdef. Your driver OF only one.

drivers/rtc/rtc-isl12026.c line 517

Quoted 9 lines
drivers/rtc/rtc-isl12026.c new file +7 -0
+static const struct of_device_id isl12026_dt_match[] = {
+       { .compatible = "isil,isl12026" },
+       { },
+};
+MODULE_DEVICE_TABLE(of, isl12026_dt_match);
 
+#endif
 
+               .of_match_table = of_match_ptr(isl12026_dt_match),

Drop of_match_ptr().

Signature · 6 lines
With Best Regards,
Andy Shevchenko
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#2 lore raw
Quoted 148 lines · Andy Shevchenko
Quoted 4 lines · David Daney

The ISL12026 is a combination RTC and EEPROM device with I2C interface. The standard RTC driver interface is provided. The EEPROM is accessed via the NVMEM interface via the "eeprom0" directory in the sysfs entry for the device.

Thanks for an update, my comments below.

drivers/rtc/rtc-isl12026.c line 43

Quoted 10 lines
drivers/rtc/rtc-isl12026.c new file +9 -0
+struct isl12026 {
+       struct rtc_device *rtc;
+       struct i2c_client *nvm_client;
+       struct nvmem_config nvm_cfg;
+       /*
+        * RTC write operations require that multiple messages be
+        * transmitted, we hold the lock for all accesses to the
+        * device so that these sequences cannot be disrupted.  Also,
 
+        * the write cycle to the nvmem takes many mS during which the

What mS means? milliseconds? The standard abbreviation for it 'ms'.

Quoted 8 lines
drivers/rtc/rtc-isl12026.c new file +7 -0
+        * device does not respond to commands, so holding the lock
+        * also prevents access during these times.
+        */
+       struct mutex lock;
+};
 
+static int isl12026_read_reg(struct i2c_client *client, int reg)
+{

drivers/rtc/rtc-isl12026.c line 83

Quoted 10 lines
drivers/rtc/rtc-isl12026.c new file +8 -0
 
+       ret = i2c_transfer(client->adapter, msgs, ARRAY_SIZE(msgs));
+       if (ret != ARRAY_SIZE(msgs)) {
+               dev_err(&client->dev, "read reg error, ret=%d\n", ret);
+               ret = ret < 0 ? ret : -EIO;
+       } else {
+               ret = val;
+       }
 
+       return val;

Something wrong. ret is not used after all.

Quoted 1 line

+}

Check entire code for such.

drivers/rtc/rtc-isl12026.c line 332

Quoted 3 lines
drivers/rtc/rtc-isl12026.c new file +3 -0
+       /* 2 bytes of address, most significant first */
+       addr[0] = (offset >> 8) & 0xff;
+       addr[1] = offset & 0xff;

Consider to drop '& 0xff', they are pointless (you have u8 type).

drivers/rtc/rtc-isl12026.c line 380

Quoted 2 lines
drivers/rtc/rtc-isl12026.c new file +2 -0
+               payload[0] = (offset >> 8) & 0xff;
+               payload[1] = offset & 0xff;

Ditto.

drivers/rtc/rtc-isl12026.c line 410

Quoted 12 lines
drivers/rtc/rtc-isl12026.c new file +10 -0
+static void isl12026_force_power_modes(struct i2c_client *client)
+{
+       int ret;
+       int pwr, requested_pwr;
+       u32 bsw_val, sbib_val;
 
+       bool set_bsw, set_sbib;
+
 
+       ret = of_property_read_u32(client->dev.of_node,
+                                  "isil,pwr-bsw", &bsw_val);
+       set_bsw = (ret == 0);

Which is not fully correct. Better to do

set_bsw = of_property_present();

ret = of_property_read...();
if (ret)
return ret;

drivers/rtc/rtc-isl12026.c line 414

Quoted 4 lines
drivers/rtc/rtc-isl12026.c new file +4 -0
+
+       ret = of_property_read_u32(client->dev.of_node,
+                                  "isil,pwr-sbib", &sbib_val);
+       set_sbib = (ret == 0);

Ditto.

drivers/rtc/rtc-isl12026.c line 418

Quoted 5 lines
drivers/rtc/rtc-isl12026.c new file +4 -0
+
+       /* Check if PWR.BSW and/or PWR.SBIB need specified values */
+
 
+       if (set_bsw || set_sbib) {

if (!x && !y)
return;

Quoted 5 lines
drivers/rtc/rtc-isl12026.c new file +5 -0
+               pwr = isl12026_read_reg(client, ISL12026_REG_PWR);
+               if (pwr < 0) {
+                       dev_err(&client->dev,
+                               "Error: Failed to read PWR %d\n", pwr);
+                       return;

drivers/rtc/rtc-isl12026.c line 433

Quoted 10 lines
drivers/rtc/rtc-isl12026.c new file +10 -0
+               }
+
+               requested_pwr = pwr;
+
+               if (set_bsw) {
+                       if (bsw_val)
+                               requested_pwr |= ISL12026_REG_PWR_BSW;
+                       else
+                               requested_pwr &= ~ISL12026_REG_PWR_BSW;
+               }

Undefined state if no value?

drivers/rtc/rtc-isl12026.c line 439

Quoted 6 lines
drivers/rtc/rtc-isl12026.c new file +6 -0
+               if (set_sbib) {
+                       if (sbib_val)
+                               requested_pwr |= ISL12026_REG_PWR_SBIB;
+                       else
+                               requested_pwr &= ~ISL12026_REG_PWR_SBIB;
+               }

Ditto.

drivers/rtc/rtc-isl12026.c line 446

Quoted 8 lines
drivers/rtc/rtc-isl12026.c new file +7 -0
+
+               if (pwr >= 0 && pwr != requested_pwr) {
 
+                       dev_info(&client->dev, "PWR: %02x\n", (u8)pwr);
+                       dev_info(&client->dev,
+                                "Updating PWR to: %02x\n", (u8)requested_pwr);
+                       isl12026_write_reg(client,
+                                          ISL12026_REG_PWR, requested_pwr);

If you do explicit casting in printf() parameters you are doing something wrong in 99.9% cases.

drivers/rtc/rtc-isl12026.c line 470

Quoted 12 lines
drivers/rtc/rtc-isl12026.c new file +9 -0
+               }
+       }
+}
 
+static int isl12026_probe_new(struct i2c_client *client)
+{
+       struct isl12026 *priv;
+       int ret;
 
 
+       /* The NVMem array responds at i2c address 0x57 */
+       priv->nvm_client = i2c_new_dummy(client->adapter, 0x57);

Magic. Make it #define and put comment there.

Quoted 9 lines

drivers/rtc/rtc-isl12026.c line 506

Quoted 6 lines
drivers/rtc/rtc-isl12026.c new file +4 -0
+       if (!priv->nvm_client)
+               return -ENOMEM;
 
+}
 
+#ifdef CONFIG_OF

Remove this ugly #ifdef. Your driver OF only one.

Well, it is DT only because you asked for that on v1.

Signature · 3 lines
Alexandre Belloni, Bootlin (formerly Free Electrons)
Embedded Linux and Kernel engineering
http://bootlin.com
#3 lore raw
Quoted 9 lines · Alexandre Belloni
Quoted 6 lines · Andy Shevchenko
Quoted 1 line · David Daney

+#ifdef CONFIG_OF

Remove this ugly #ifdef. Your driver OF only one.

Well, it is DT only because you asked for that on v1.

Yes, and I asked to remove these #ifdef:s there as well.

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#4 lore raw
In reply to Andy Shevchenko
Quoted 17 lines · Andy Shevchenko
Quoted 4 lines · David Daney

The ISL12026 is a combination RTC and EEPROM device with I2C interface. The standard RTC driver interface is provided. The EEPROM is accessed via the NVMEM interface via the "eeprom0" directory in the sysfs entry for the device.

Thanks for an update, my comments below.

Quoted 8 lines
drivers/rtc/rtc-isl12026.c new file +8 -0
+struct isl12026 {
+       struct rtc_device *rtc;
+       struct i2c_client *nvm_client;
+       struct nvmem_config nvm_cfg;
+       /*
+        * RTC write operations require that multiple messages be
+        * transmitted, we hold the lock for all accesses to the
+        * device so that these sequences cannot be disrupted.  Also,
Quoted 3 lines
Quoted 1 line

+ * the write cycle to the nvmem takes many mS during which the

What mS means? milliseconds? The standard abbreviation for it 'ms'.

Yes, milliseconds. OK.

Quoted 18 lines
Quoted 17 lines
drivers/rtc/rtc-isl12026.c new file +14 -0
+        * device does not respond to commands, so holding the lock
+        * also prevents access during these times.
+        */
+       struct mutex lock;
+};
 
+static int isl12026_read_reg(struct i2c_client *client, int reg)
+{
 
+       ret = i2c_transfer(client->adapter, msgs, ARRAY_SIZE(msgs));
+       if (ret != ARRAY_SIZE(msgs)) {
+               dev_err(&client->dev, "read reg error, ret=%d\n", ret);
+               ret = ret < 0 ? ret : -EIO;
+       } else {
+               ret = val;
+       }
Quoted 7 lines
Quoted 1 line

+ return val;

Something wrong. ret is not used after all.

Quoted 1 line

+}

Check entire code for such.

OK.

Quoted 6 lines

drivers/rtc/rtc-isl12026.c line 332

Quoted 4 lines
drivers/rtc/rtc-isl12026.c new file +3 -0
+       /* 2 bytes of address, most significant first */
+       addr[0] = (offset >> 8) & 0xff;
+       addr[1] = offset & 0xff;

Consider to drop '& 0xff', they are pointless (you have u8 type).

Generated code is the same, but the intent of the code is less clear when the explicit masking is removed. Never the less, since this seems to be impeding progress, I will remove it.

Quoted 12 lines

drivers/rtc/rtc-isl12026.c line 380

Quoted 3 lines
drivers/rtc/rtc-isl12026.c new file +2 -0
+               payload[0] = (offset >> 8) & 0xff;
+               payload[1] = offset & 0xff;

Ditto.

Quoted 5 lines
drivers/rtc/rtc-isl12026.c new file +5 -0
+static void isl12026_force_power_modes(struct i2c_client *client)
+{
+       int ret;
+       int pwr, requested_pwr;
+       u32 bsw_val, sbib_val;
Quoted 8 lines

drivers/rtc/rtc-isl12026.c line 410

Quoted 6 lines
drivers/rtc/rtc-isl12026.c new file +5 -0
+       bool set_bsw, set_sbib;
+
 
+       ret = of_property_read_u32(client->dev.of_node,
+                                  "isil,pwr-bsw", &bsw_val);
+       set_bsw = (ret == 0);

Which is not fully correct. Better to do

I think it is correct. The properties are optional, so it it perfectly fine for of_property_read_u32() to fail. If it fails, we simply keep the current value. I will add comments to document the intended logic.

Quoted 2 lines

set_bsw = of_property_present();

There are no occurrences of "of_property_present" in my source tree.

Quoted 12 lines

ret = of_property_read...();
if (ret)
return ret;

drivers/rtc/rtc-isl12026.c line 414

Quoted 4 lines
drivers/rtc/rtc-isl12026.c new file +4 -0
+
+       ret = of_property_read_u32(client->dev.of_node,
+                                  "isil,pwr-sbib", &sbib_val);
+       set_sbib = (ret == 0);

Ditto.

Quoted 8 lines

drivers/rtc/rtc-isl12026.c line 418

Quoted 5 lines
drivers/rtc/rtc-isl12026.c new file +4 -0
+
+       /* Check if PWR.BSW and/or PWR.SBIB need specified values */
+
 
+       if (set_bsw || set_sbib) {

if (!x && !y)
return;

OK.

Quoted 10 lines
Quoted 10 lines
drivers/rtc/rtc-isl12026.c new file +9 -0
+               pwr = isl12026_read_reg(client, ISL12026_REG_PWR);
+               if (pwr < 0) {
+                       dev_err(&client->dev,
+                               "Error: Failed to read PWR %d\n", pwr);
+                       return;
+               }
+
+               requested_pwr = pwr;
+
Quoted 8 lines

drivers/rtc/rtc-isl12026.c line 433

Quoted 6 lines
drivers/rtc/rtc-isl12026.c new file +6 -0
+               if (set_bsw) {
+                       if (bsw_val)
+                               requested_pwr |= ISL12026_REG_PWR_BSW;
+                       else
+                               requested_pwr &= ~ISL12026_REG_PWR_BSW;
+               }

Undefined state if no value?

It is defined. See above.

Quoted 13 lines

drivers/rtc/rtc-isl12026.c line 439

Quoted 7 lines
drivers/rtc/rtc-isl12026.c new file +6 -0
+               if (set_sbib) {
+                       if (sbib_val)
+                               requested_pwr |= ISL12026_REG_PWR_SBIB;
+                       else
+                               requested_pwr &= ~ISL12026_REG_PWR_SBIB;
+               }

Ditto.

Quoted 2 lines
drivers/rtc/rtc-isl12026.c new file +2 -0
+
+               if (pwr >= 0 && pwr != requested_pwr) {
Quoted 8 lines

drivers/rtc/rtc-isl12026.c line 446

Quoted 5 lines
drivers/rtc/rtc-isl12026.c new file +5 -0
+                       dev_info(&client->dev, "PWR: %02x\n", (u8)pwr);
+                       dev_info(&client->dev,
+                                "Updating PWR to: %02x\n", (u8)requested_pwr);
+                       isl12026_write_reg(client,
+                                          ISL12026_REG_PWR, requested_pwr);

If you do explicit casting in printf() parameters you are doing something wrong in 99.9% cases.

OK.

Quoted 16 lines

drivers/rtc/rtc-isl12026.c line 470

Quoted 13 lines
drivers/rtc/rtc-isl12026.c new file +9 -0
+               }
+       }
+}
 
+static int isl12026_probe_new(struct i2c_client *client)
+{
+       struct isl12026 *priv;
+       int ret;
 
 
+       /* The NVMem array responds at i2c address 0x57 */
+       priv->nvm_client = i2c_new_dummy(client->adapter, 0x57);

Magic. Make it #define and put comment there.

Quoted 8 lines

drivers/rtc/rtc-isl12026.c line 506

Quoted 6 lines
drivers/rtc/rtc-isl12026.c new file +4 -0
+       if (!priv->nvm_client)
+               return -ENOMEM;
 
+}
 
+#ifdef CONFIG_OF

Remove this ugly #ifdef. Your driver OF only one.

The driver doesn't require OF. By removing the #if (which I will do), the size of the module may be bloated in the non-OF case. If anybody cares about this, they can add back the #if.

Quoted 7 lines
Quoted 6 lines
drivers/rtc/rtc-isl12026.c new file +5 -0
+static const struct of_device_id isl12026_dt_match[] = {
+       { .compatible = "isil,isl12026" },
+       { },
+};
+MODULE_DEVICE_TABLE(of, isl12026_dt_match);
Quoted 5 lines

drivers/rtc/rtc-isl12026.c line 517

Quoted 3 lines
drivers/rtc/rtc-isl12026.c new file +2 -0
+#endif
 
+               .of_match_table = of_match_ptr(isl12026_dt_match),

Drop of_match_ptr().

Best to keep it so that the non-OF case is correctly handled.

Quoted 1 line
#5 lore raw
Quoted 14 lines · David Daney
Quoted 13 lines · Andy Shevchenko
Quoted 9 lines · David Daney

The ISL12026 is a combination RTC and EEPROM device with I2C interface. The standard RTC driver interface is provided. The EEPROM is accessed via the NVMEM interface via the "eeprom0" directory in the sysfs entry for the device.

drivers/rtc/rtc-isl12026.c new file +3 -0
+       /* 2 bytes of address, most significant first */
+       addr[0] = (offset >> 8) & 0xff;
+       addr[1] = offset & 0xff;
Quoted 6 lines
Quoted 1 line

Consider to drop '& 0xff', they are pointless (you have u8 type).

Generated code is the same, but the intent of the code is less clear when the explicit masking is removed. Never the less, since this seems to be impeding progress, I will remove it.

You can use the following:

      addr[0] = offset >> 8;
      addr[1] = offset >> 0;
Quoted 7 lines
Quoted 6 lines
Quoted 6 lines
drivers/rtc/rtc-isl12026.c new file +5 -0
+       bool set_bsw, set_sbib;
+
 
+       ret = of_property_read_u32(client->dev.of_node,
+                                  "isil,pwr-bsw", &bsw_val);
+       set_bsw = (ret == 0);
Quoted 5 lines
Quoted 1 line

Which is not fully correct. Better to do

I think it is correct. The properties are optional, so it it perfectly fine for of_property_read_u32() to fail. If it fails, we simply keep the current value. I will add comments to document the intended logic.

OK.

Quoted 3 lines
Quoted 1 line

set_bsw = of_property_present();

There are no occurrences of "of_property_present" in my source tree.

Ah, indeed.

Quoted 3 lines
Quoted 3 lines

ret = of_property_read...();
if (ret)
return ret;

What about then

set_bsw = of_property_read_bool();

set_sbid = ...

if (!x && !y)
return ...

...

if (x) {

}

Quoted 17 lines
Quoted 17 lines

drivers/rtc/rtc-isl12026.c line 414

Quoted 5 lines
drivers/rtc/rtc-isl12026.c new file +4 -0
+
+       ret = of_property_read_u32(client->dev.of_node,
+                                  "isil,pwr-sbib", &sbib_val);
+       set_sbib = (ret == 0);

Ditto.

Quoted 6 lines
drivers/rtc/rtc-isl12026.c new file +6 -0
+               if (set_bsw) {
+                       if (bsw_val)
+                               requested_pwr |= ISL12026_REG_PWR_BSW;
+                       else
+                               requested_pwr &= ~ISL12026_REG_PWR_BSW;
+               }
Quoted 3 lines
Quoted 1 line

Undefined state if no value?

It is defined. See above.

It's opaque. Depends on firmware settings, boot loader, etc.

Quoted 8 lines
Quoted 2 lines
Quoted 1 line

+#ifdef CONFIG_OF

Remove this ugly #ifdef. Your driver OF only one.

The driver doesn't require OF.

By removing the #if (which I will do), the
size of the module may be bloated in the non-OF case. If anybody cares about this, they can add back the #if.

Nobody.

Quoted 10 lines
Quoted 8 lines

drivers/rtc/rtc-isl12026.c line 517

Quoted 7 lines
drivers/rtc/rtc-isl12026.c new file +6 -0
+static const struct of_device_id isl12026_dt_match[] = {
+       { .compatible = "isil,isl12026" },
+       { },
+};
+MODULE_DEVICE_TABLE(of, isl12026_dt_match);
 
+               .of_match_table = of_match_ptr(isl12026_dt_match),

Drop of_match_ptr().

Best to keep it so that the non-OF case is correctly handled.

If you drop above ifdef, you need to drop this macro. And code bloat is not big.

Btw, driver since ->probe_new() is become OF/ACPI only, so, otherwise there will be no way to enumerate.

Signature · 2 lines
With Best Regards,
Andy Shevchenko