rtc: ds3232: add temperature support
PATCH v2 1/1 rtc: ds3232: add temperature support
DS3232/DS3234 has the temperature registers with a resolution of 0.25 degree celsius. This enables to get the value through hwmon.
# cat /sys/class/hwmon/hwmon0/temp1_input 37250
--- drivers/rtc/Kconfig | 9 ++++ drivers/rtc/rtc-ds3232.c | 134 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 143 insertions(+)
drivers/rtc/Kconfig +9 -0
@@ -791,6 +791,15 @@ config RTC_DRV_DS3232 This driver can also be built as a module. If so, the module will be called rtc-ds3232. +config RTC_DRV_DS3232_HWMON + bool "HWMON support for Dallas/Maxim DS3232/DS3234" + depends on RTC_DRV_DS3232 && HWMON + depends on !(RTC_DRV_DS3232=y && HWMON=m) + default y + help + Say Y here if you want to expose temperature sensor data on + rtc-ds3232 + config RTC_DRV_PCF2127 tristate "NXP PCF2127" depends on RTC_I2C_AND_SPI
drivers/rtc/rtc-ds3232.c +134 -0
152 lines not on this page · raw message
Signature · 1 line
2.7.4
drivers/rtc/Kconfig config RTC_DRV_DS3232 · line 797
Quoted 11 lines · Kirill Esipov
DS3232/DS3234 has the temperature registers with a resolution of 0.25 degree celsius. This enables to get the value through hwmon.
# cat /sys/class/hwmon/hwmon0/temp1_input 37250drivers/rtc/Kconfig +4
-0+config RTC_DRV_DS3232_HWMON + bool "HWMON support for Dallas/Maxim DS3232/DS3234" + depends on RTC_DRV_DS3232 && HWMON + depends on !(RTC_DRV_DS3232=y && HWMON=m)
Perhaps it might be squeezed into one line (something like that logic has been required by I2C related PMIC IIRC)
Quoted 1 line
+ default y
Is it really sane default?
Quoted 1 line
+#ifdef
CONFIG_RTC_DRV_DS3232_HWMON
IS_BUILTIN() ?
drivers/rtc/rtc-ds3232.c static int ds3232_update_alarm(struct device *dev, unsigned int enabled) · line 302
Quoted 11 lines
drivers/rtc/rtc-ds3232.c +10
-0+static int ds3232_hwmon_read_temp (struct device *dev,long int *mC) +{ +struct ds3232 *ds3232 =dev_get_drvdata (dev); +u8 temp_buf[2 ]; +s16 temp; +int ret; + + ret =regmap_bulk_read (ds3232->regmap,DS3232_REG_TEMPERATURE , temp_buf, +sizeof (temp_buf)); +
Remove.
Quoted 24 lines
drivers/rtc/rtc-ds3232.c +23
-0+if (ret <0 ) +return ret; +static umode_t ds3232_hwmon_is_visible (const void *data, +enum hwmon_sensor_types type, +u32 attr,int channel) +{ +if (type != hwmon_temp) +return 0 ; + +switch (attr) { +case hwmon_temp_input: +return 0444 ; +default : +return 0 ; + } +} + +static int ds3232_hwmon_read (struct device *dev, +enum hwmon_sensor_types type, +u32 attr,int channel,long *temp) +{ +int err; +
drivers/rtc/rtc-ds3232.c static int ds3232_update_alarm(struct device *dev, unsigned int enabled) · line 347
Quoted 10 lines
drivers/rtc/rtc-ds3232.c +10
-0+switch (attr) { +case hwmon_temp_input: +ds3232_hwmon_read_temp (dev, temp); + err =0 ; +break ; +default : +return -EOPNOTSUPP ; + } + +return err;
You may do as in previous function. Or what did you mean here by introducing an err variable?
drivers/rtc/rtc-ds3232.c static int ds3232_update_alarm(struct device *dev, unsigned int enabled) · line 323
Quoted 4 lines
drivers/rtc/rtc-ds3232.c +3
-0+} + +
Remove one of them.
drivers/rtc/rtc-ds3232.c static int ds3232_update_alarm(struct device *dev, unsigned int enabled) · line 395
Quoted 10 lines
drivers/rtc/rtc-ds3232.c +9
-0+static void ds3232_hwmon_register (struct device *dev,const char *name) +{ +struct ds3232 *ds3232 =dev_get_drvdata (dev); +struct device *hwmon_dev; + + hwmon_dev =devm_hwmon_device_register_with_info (dev, name, ds3232, + &ds3232_hwmon_chip_info, +NULL ); +
Remove.
drivers/rtc/rtc-ds3232.c static int ds3232_update_alarm(struct device *dev, unsigned int enabled) · line 402
Quoted 8 lines
drivers/rtc/rtc-ds3232.c +7
-0+if (IS_ERR (hwmon_dev)) { +dev_warn (dev,"unable to register hwmon device %ld\n" , +PTR_ERR (hwmon_dev)); + } +} + +#else
I dunno which style is preferred, though you may use if (IS_BUILTIN(...))
return;
at the beginning of the function and allow gcc optimizer to take care of everything else.
Quoted 6 lines
drivers/rtc/rtc-ds3232.c +6
-0+ +static void ds3232_hwmon_register (struct device *dev,const char *name) +{ +} + +#endif
Signature · 2 lines
With Best Regards, Andy Shevchenko
2017-06-25 19:39 GMT+03:00 Andy Shevchenko <[email protected]>:
Quoted 13 lines · Kirill Esipov
drivers/rtc/Kconfig config RTC_DRV_DS3232 · line 797
Quoted 11 lines
DS3232/DS3234 has the temperature registers with a resolution of 0.25 degree celsius. This enables to get the value through hwmon.
# cat /sys/class/hwmon/hwmon0/temp1_input 37250drivers/rtc/Kconfig +4
-0+config RTC_DRV_DS3232_HWMON + bool "HWMON support for Dallas/Maxim DS3232/DS3234" + depends on RTC_DRV_DS3232 && HWMON + depends on !(RTC_DRV_DS3232=y && HWMON=m)
Quoted 7 lines
Perhaps it might be squeezed into one line (something like that logic has been required by I2C related PMIC IIRC)
Quoted 1 line
+ default y
Is it really sane default?
At first sight i thought that yes it is sane default (and others RTC with hwmon set it "default y" (ds1307, rv3029c2)).
But if it's not sane, then we should turn it off by default in others drivers?
Quoted 102 lines
Quoted 1 line
+#ifdef
CONFIG_RTC_DRV_DS3232_HWMON
IS_BUILTIN()?drivers/rtc/rtc-ds3232.c static int ds3232_update_alarm(struct device *dev, unsigned int enabled) · line 302
Quoted 11 lines
drivers/rtc/rtc-ds3232.c +10
-0+static int ds3232_hwmon_read_temp (struct device *dev,long int *mC) +{ +struct ds3232 *ds3232 =dev_get_drvdata (dev); +u8 temp_buf[2 ]; +s16 temp; +int ret; + + ret =regmap_bulk_read (ds3232->regmap,DS3232_REG_TEMPERATURE , temp_buf, +sizeof (temp_buf)); +Remove.
Quoted 24 lines
drivers/rtc/rtc-ds3232.c +23
-0+if (ret <0 ) +return ret; +static umode_t ds3232_hwmon_is_visible (const void *data, +enum hwmon_sensor_types type, +u32 attr,int channel) +{ +if (type != hwmon_temp) +return 0 ; + +switch (attr) { +case hwmon_temp_input: +return 0444 ; +default : +return 0 ; + } +} + +static int ds3232_hwmon_read (struct device *dev, +enum hwmon_sensor_types type, +u32 attr,int channel,long *temp) +{ +int err; +drivers/rtc/rtc-ds3232.c static int ds3232_update_alarm(struct device *dev, unsigned int enabled) · line 347
Quoted 10 lines
drivers/rtc/rtc-ds3232.c +10
-0+switch (attr) { +case hwmon_temp_input: +ds3232_hwmon_read_temp (dev, temp); + err =0 ; +break ; +default : +return -EOPNOTSUPP ; + } + +return err;You may do as in previous function. Or what did you mean here by introducing an err variable?
drivers/rtc/rtc-ds3232.c static int ds3232_update_alarm(struct device *dev, unsigned int enabled) · line 323
Quoted 4 lines
drivers/rtc/rtc-ds3232.c +3
-0+} + +Remove one of them.
drivers/rtc/rtc-ds3232.c static int ds3232_update_alarm(struct device *dev, unsigned int enabled) · line 395
Quoted 10 lines
drivers/rtc/rtc-ds3232.c +9
-0+static void ds3232_hwmon_register (struct device *dev,const char *name) +{ +struct ds3232 *ds3232 =dev_get_drvdata (dev); +struct device *hwmon_dev; + + hwmon_dev =devm_hwmon_device_register_with_info (dev, name, ds3232, + &ds3232_hwmon_chip_info, +NULL ); +Remove.
drivers/rtc/rtc-ds3232.c static int ds3232_update_alarm(struct device *dev, unsigned int enabled) · line 402
Quoted 8 lines
drivers/rtc/rtc-ds3232.c +7
-0+if (IS_ERR (hwmon_dev)) { +dev_warn (dev,"unable to register hwmon device %ld\n" , +PTR_ERR (hwmon_dev)); + } +} + +#else I dunno which style is preferred, though you may use if (
IS_BUILTIN(...))
return;at the beginning of the function and allow gcc optimizer to take care of everything else.
drivers/rtc/rtc-ds3232.c static int ds3232_update_alarm(struct device *dev, unsigned int enabled) · line 408
Quoted 6 lines
drivers/rtc/rtc-ds3232.c +6
-0+ +static void ds3232_hwmon_register (struct device *dev,const char *name) +{ +} + +#endif --
With Best Regards,
Andy Shevchenko
Signature · 1 line
Kirill Esipov
Quoted 17 lines · Kirill Esipov
2017-06-25 19:39 GMT+03:00 Andy Shevchenko <[email protected]>:
Quoted 16 lines · Kirill Esipov
drivers/rtc/Kconfig config RTC_DRV_DS3232 · line 797
Quoted 11 lines
DS3232/DS3234 has the temperature registers with a resolution of 0.25 degree celsius. This enables to get the value through hwmon.
# cat /sys/class/hwmon/hwmon0/temp1_input 37250drivers/rtc/Kconfig +4
-0+config RTC_DRV_DS3232_HWMON + bool "HWMON support for Dallas/Maxim DS3232/DS3234" + depends on RTC_DRV_DS3232 && HWMON + depends on !(RTC_DRV_DS3232=y && HWMON=m)Perhaps it might be squeezed into one line (something like that logic has been required by I2C related PMIC IIRC)
Quoted 9 lines
Quoted 4 lines
Quoted 1 line
+ default y
Is it really sane default?
At first sight i thought that yes it is sane default (and others RTC with hwmon set it "default y" (ds1307, rv3029c2)).
But if it's not sane, then we should turn it off by default in others drivers?
It is definitively sane.
Quoted 5 lines
Quoted 5 lines
Quoted 2 lines
+#ifdef
CONFIG_RTC_DRV_DS3232_HWMON
IS_BUILTIN()?
I'd use IS_ENABLED in that case.
Quoted 10 lines
Quoted 10 lines
Quoted 9 lines
drivers/rtc/rtc-ds3232.c +9
-0+static int ds3232_hwmon_read_temp (struct device *dev,long int *mC) +{ +struct ds3232 *ds3232 =dev_get_drvdata (dev); +u8 temp_buf[2 ]; +s16 temp; +int ret; + + ret =regmap_bulk_read (ds3232->regmap,DS3232_REG_TEMPERATURE , temp_buf, +sizeof (temp_buf));
Quoted 3 lines
Quoted 3 lines
Quoted 1 line
+
Remove.
I'd recommend running checkpatch.pl --strict to remove the remaining whitespace issues too (a few alignments are off).
Quoted 8 lines
Quoted 8 lines
I dunno which style is preferred, though you may use if (
IS_BUILTIN(...))
return;at the beginning of the function and allow gcc optimizer to take care of everything else.
I don't have a strong opinion there.
Signature · 3 lines
Alexandre Belloni, Free Electrons Embedded Linux and Kernel engineering http://free-electrons.com
2017-06-27 16:00 GMT+03:00 Alexandre Belloni
<[email protected]>:
Quoted 31 lines · Kirill Esipov
Quoted 17 lines
2017-06-25 19:39 GMT+03:00 Andy Shevchenko <[email protected]>:
Quoted 16 lines · Kirill Esipov
drivers/rtc/Kconfig config RTC_DRV_DS3232 · line 797
Quoted 11 lines
DS3232/DS3234 has the temperature registers with a resolution of 0.25 degree celsius. This enables to get the value through hwmon.
# cat /sys/class/hwmon/hwmon0/temp1_input 37250drivers/rtc/Kconfig +4
-0+config RTC_DRV_DS3232_HWMON + bool "HWMON support for Dallas/Maxim DS3232/DS3234" + depends on RTC_DRV_DS3232 && HWMON + depends on !(RTC_DRV_DS3232=y && HWMON=m)Perhaps it might be squeezed into one line (something like that logic has been required by I2C related PMIC IIRC)
Quoted 9 lines
Quoted 4 lines
Quoted 1 line
+ default y
Is it really sane default?
At first sight i thought that yes it is sane default (and others RTC with hwmon set it "default y" (ds1307, rv3029c2)).
But if it's not sane, then we should turn it off by default in others drivers?It is definitively sane.
Quoted 1 line
Quoted 7 lines
Quoted 4 lines
Quoted 4 lines
Quoted 1 line
+#ifdef
CONFIG_RTC_DRV_DS3232_HWMON
IS_BUILTIN()?I'd use
IS_ENABLEDin that case.
Why? "RTC_DRV_DS3232_HWMON" is bool, not tristate. So it can't be defined as "m".
Quoted 32 lines
Quoted 10 lines
Quoted 10 lines
Quoted 9 lines
drivers/rtc/rtc-ds3232.c +9
-0+static int ds3232_hwmon_read_temp (struct device *dev,long int *mC) +{ +struct ds3232 *ds3232 =dev_get_drvdata (dev); +u8 temp_buf[2 ]; +s16 temp; +int ret; + + ret =regmap_bulk_read (ds3232->regmap,DS3232_REG_TEMPERATURE , temp_buf, +sizeof (temp_buf));Quoted 3 lines
Quoted 3 lines
Quoted 1 line
+
Remove.
I'd recommend running checkpatch.pl --strict to remove the remaining whitespace issues too (a few alignments are off).
Quoted 8 lines
Quoted 8 lines
I dunno which style is preferred, though you may use if (
IS_BUILTIN(...))
return;at the beginning of the function and allow gcc optimizer to take care of everything else.
I don't have a strong opinion there.
--
Alexandre Belloni, Free Electrons
Embedded Linux and Kernel engineering
http://free-electrons.com
Signature · 1 line
Kirill Esipov
Quoted 35 lines · Kirill Esipov
2017-06-27 16:00 GMT+03:00 Alexandre Belloni
<[email protected]>:Quoted 33 lines · Kirill Esipov
Quoted 17 lines
2017-06-25 19:39 GMT+03:00 Andy Shevchenko <[email protected]>:
Quoted 16 lines · Kirill Esipov
drivers/rtc/Kconfig config RTC_DRV_DS3232 · line 797
Quoted 11 lines
DS3232/DS3234 has the temperature registers with a resolution of 0.25 degree celsius. This enables to get the value through hwmon.
# cat /sys/class/hwmon/hwmon0/temp1_input 37250drivers/rtc/Kconfig +4
-0+config RTC_DRV_DS3232_HWMON + bool "HWMON support for Dallas/Maxim DS3232/DS3234" + depends on RTC_DRV_DS3232 && HWMON + depends on !(RTC_DRV_DS3232=y && HWMON=m)Perhaps it might be squeezed into one line (something like that logic has been required by I2C related PMIC IIRC)
Quoted 9 lines
Quoted 4 lines
Quoted 1 line
+ default y
Is it really sane default?
At first sight i thought that yes it is sane default (and others RTC with hwmon set it "default y" (ds1307, rv3029c2)).
But if it's not sane, then we should turn it off by default in others drivers?It is definitively sane.
Quoted 3 lines
Quoted 3 lines
Quoted 2 lines
+#ifdef
CONFIG_RTC_DRV_DS3232_HWMON
Quoted 9 lines
Quoted 5 lines
Quoted 2 lines
Quoted 2 lines
IS_BUILTIN()?I'd use
IS_ENABLEDin that case.Why? "
RTC_DRV_DS3232_HWMON" is bool, not tristate. So it can't be defined as "m".
It's clearer and doesn't hurt but really, #ifdefCONFIG_RTC_DRV_DS3232_HWMON is just fine.
Quoted 37 lines
Quoted 32 lines
Quoted 10 lines
Quoted 10 lines
Quoted 9 lines
drivers/rtc/rtc-ds3232.c +9
-0+static int ds3232_hwmon_read_temp (struct device *dev,long int *mC) +{ +struct ds3232 *ds3232 =dev_get_drvdata (dev); +u8 temp_buf[2 ]; +s16 temp; +int ret; + + ret =regmap_bulk_read (ds3232->regmap,DS3232_REG_TEMPERATURE , temp_buf, +sizeof (temp_buf));Quoted 3 lines
Quoted 3 lines
Quoted 1 line
+
Remove.
I'd recommend running checkpatch.pl --strict to remove the remaining whitespace issues too (a few alignments are off).
Quoted 8 lines
Quoted 8 lines
I dunno which style is preferred, though you may use if (
IS_BUILTIN(...))
return;at the beginning of the function and allow gcc optimizer to take care of everything else.
I don't have a strong opinion there.
--
Alexandre Belloni, Free Electrons
Embedded Linux and Kernel engineering
http://free-electrons.comSignature · 1 line
Kirill Esipov
Signature · 3 lines
Alexandre Belloni, Free Electrons Embedded Linux and Kernel engineering http://free-electrons.com