RTC: nvmem improvements
Alexandre Belloni
maintainercover RTC: nvmem improvements
This series makes some change to the RTC nvmem API to simplify drivers and clean the way the nvmem_config is used.
The main issue was the different lifecycle of the struct nvmem_config (only needed at probe time) and rtc_device (needed for the lifetime of the driver).
Then, it converts the remaining drivers (except ds1685) to the API. A few other improvements are also made along the way.
Alexandre Belloni (45):
rtc: documentation: correct nvmem date and version
rtc: nvmem: pass nvmem_config to rtc_nvmem_register()
rtc: nvmem: return error values
rtc: nvmem: disallow registering nvmem more than once
rtc: export rtc_nvmem_register() to drivers
rtc: ds1305: call rtc_nvmem_register()
rtc: ds1305: put ds1305_nvmem_cfg on the stack
rtc: ds1307: call rtc_nvmem_register()
rtc: ds1307: put struct nvmem_config on the stack
rtc: ds1511: call rtc_nvmem_register()
rtc: ds1511: put ds1511_nvmem_cfg on the stack
rtc: m48t86: call rtc_nvmem_register()
rtc: m48t86: put m48t86_nvmem_cfg on the stack
rtc: omap: call rtc_nvmem_register()
rtc: pcf85363: call rtc_nvmem_register()
rtc: pcf85363: put struct nvmem_config on the stack
rtc: rv8803: call rtc_nvmem_register()
rtc: rv8803: put struct nvmem_config on the stack
rtc: rv8803: fix possible race condition
rtc: remove nvmem_config
rtc: ds1343: simplify regmap initialization
rtc: ds1343: switch to rtc_register_device
rtc: ds1343: remove undocumented and useless sysfs files
rtc: ds1343: use generic nvmem
rtc: m48t59: switch to rtc_register_device
rtc: m48t59: use generic nvmem
rtc: sirfsoc: remove useless sirfsoc_rtc_ioctl
rtc: ds1553: switch to rtc_register_device
rtc: ds1553: use generic nvmem
rtc: ds1553: make alarms useful
rtc: cmos: fix possible race condition
rtc: cmos: use generic nvmem
rtc: ds1742: switch to rtc_register_device
rtc: ds1742: use generic nvmem
rtc: rp5c01: fix possible race condition
rtc: rp5c01: use generic nvmem
rtc: stk17ta8: make alarms useful
rtc: stk17ta8: switch to rtc_register_device
rtc: stk17ta8: fix possible race condition
rtc: stk17ta8: use generic nvmem
rtc: tx4939: remove arch/mips dependency
rtc: tx4939: extend test coverage
rtc: tx4939: switch to rtc_register_device
rtc: tx4939: fix possible race condition
rtc: tx4939: use generic nvmem
Documentation/ABI/testing/sysfs-class-rtc | 4 +- drivers/rtc/Kconfig | 2 +- drivers/rtc/class.c | 2 - drivers/rtc/nvmem.c | 29 +++-- drivers/rtc/rtc-cmos.c | 75 ++++++------ drivers/rtc/rtc-core.h | 8 -- drivers/rtc/rtc-ds1305.c | 21 ++-- drivers/rtc/rtc-ds1307.c | 29 ++--- drivers/rtc/rtc-ds1343.c | 183 +++++------------------------- drivers/rtc/rtc-ds1511.c | 22 ++-- drivers/rtc/rtc-ds1553.c | 74 +++++------- drivers/rtc/rtc-ds1742.c | 73 ++++++------ drivers/rtc/rtc-m48t59.c | 57 +++++----- drivers/rtc/rtc-m48t86.c | 23 ++-- drivers/rtc/rtc-omap.c | 3 +- drivers/rtc/rtc-pcf85363.c | 25 ++-- drivers/rtc/rtc-rp5c01.c | 63 +++++----- drivers/rtc/rtc-rv8803.c | 33 +++--- drivers/rtc/rtc-sirfsoc.c | 18 --- drivers/rtc/rtc-stk17ta8.c | 70 +++++------- drivers/rtc/rtc-tx4939.c | 87 +++++++++----- include/linux/rtc.h | 14 ++- 22 files changed, 380 insertions(+), 535 deletions(-)
Signature · 1 line
2.16.1
Alexandre Belloni
maintainerPATCH 1/45 rtc: documentation: correct nvmem date and version
The nvmem interface appaeared in linux 4.13
--- Documentation/ABI/testing/sysfs-class-rtc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
Documentation/ABI/testing/sysfs-class-rtc +2 -2
@@ -58,8 +58,8 @@ Description: (RO) RTC-provided time in 24-hour notation (hh:mm:ss) What: /sys/class/rtc/rtcX/*/nvmem -Date: February 2016 -KernelVersion: 4.6 +Date: July 2017 +KernelVersion: 4.13 Contact: [email protected] Description: (RW) The non volatile storage exported as a raw file, as
Signature · 1 line
2.16.1
Alexandre Belloni
maintainerPATCH 2/45 rtc: nvmem: pass nvmem_config to rtc_nvmem_register()
In reply to Alexandre BelloniTo be able to remove nvmem_config from struct rtc_device, pass it as a parameter to rtc_nvmem_register.
--- drivers/rtc/class.c | 2 +- drivers/rtc/nvmem.c | 17 +++++++++-------- drivers/rtc/rtc-core.h | 6 ++++-- 3 files changed, 14 insertions(+), 11 deletions(-)
drivers/rtc/class.c +1 -1
@@ -453,7 +453,7 @@ int __rtc_register_device(struct module *owner, struct rtc_device *rtc)rtc_proc_add_device (rtc); -rtc_nvmem_register (rtc); +rtc_nvmem_register (rtc, rtc->nvmem_config); rtc->registered = true; dev_info(rtc->dev.parent, "registered as %s\n",
drivers/rtc/nvmem.c +9 -8
@@ -46,7 +46,7 @@ rtc_nvram_write(struct file *filp, struct kobject *kobj,return nvmem_device_write (rtc->nvmem, off, count, buf); } -static int rtc_nvram_register (struct rtc_device *rtc) +static int rtc_nvram_register (struct rtc_device *rtc,size_t size) {int err;
@@ -64,7 +64,7 @@ static int rtc_nvram_register(struct rtc_device *rtc) rtc->nvram->read = rtc_nvram_read; rtc->nvram->write = rtc_nvram_write; - rtc->nvram->size = rtc->nvmem_config->size; + rtc->nvram->size = size; err =sysfs_create_bin_file (&rtc->dev.parent->kobj, rtc->nvram);
@@ -84,20 +84,21 @@ static void rtc_nvram_unregister(struct rtc_device *rtc)/* * New ABI, uses nvmem */ -void rtc_nvmem_register (struct rtc_device *rtc) +void rtc_nvmem_register (struct rtc_device *rtc, +struct nvmem_config *nvmem_config) { -if (!rtc->nvmem_config) +if (!nvmem_config)return ; - rtc->nvmem_config->dev = &rtc->dev; - rtc->nvmem_config->owner = rtc->owner; - rtc->nvmem =nvmem_register (rtc->nvmem_config); + nvmem_config->dev = &rtc->dev; + nvmem_config->owner = rtc->owner; + rtc->nvmem =nvmem_register (nvmem_config);if (IS_ERR_OR_NULL (rtc->nvmem))return ;/* Register the old ABI */ if (rtc->nvram_old_abi) -rtc_nvram_register (rtc); +rtc_nvram_register (rtc, nvmem_config->size); }void rtc_nvmem_unregister (struct rtc_device *rtc)
drivers/rtc/rtc-core.h +4 -2
@@ -48,9 +48,11 @@ static inline const struct attribute_group **rtc_get_dev_attribute_groups(void)#endif #ifdef CONFIG_RTC_NVMEM -void rtc_nvmem_register (struct rtc_device *rtc); +void rtc_nvmem_register (struct rtc_device *rtc, +struct nvmem_config *nvmem_config);void rtc_nvmem_unregister (struct rtc_device *rtc);#else -static inline void rtc_nvmem_register (struct rtc_device *rtc) {} +static inline void rtc_nvmem_register (struct rtc_device *rtc, +struct nvmem_config *nvmem_config) {}static inline void rtc_nvmem_unregister (struct rtc_device *rtc) {}#endif
Signature · 1 line
2.16.1
Alexandre Belloni
maintainerPATCH 3/45 rtc: nvmem: return error values
In reply to Alexandre BelloniIn case of error, make rtc_nvmem_register() able to return an error value to its caller.
--- drivers/rtc/nvmem.c | 10 ++++++---- drivers/rtc/rtc-core.h | 11 +++++++---- 2 files changed, 13 insertions(+), 8 deletions(-)
drivers/rtc/nvmem.c +6 -4
@@ -84,21 +84,23 @@ static void rtc_nvram_unregister(struct rtc_device *rtc)/* * New ABI, uses nvmem */ -void rtc_nvmem_register (struct rtc_device *rtc, -struct nvmem_config *nvmem_config) +int rtc_nvmem_register (struct rtc_device *rtc, +struct nvmem_config *nvmem_config) {if (!nvmem_config) -return ; +return -ENODEV ; nvmem_config->dev = &rtc->dev; nvmem_config->owner = rtc->owner; rtc->nvmem =nvmem_register (nvmem_config);if (IS_ERR_OR_NULL (rtc->nvmem)) -return ; +return PTR_ERR (rtc->nvmem);/* Register the old ABI */ if (rtc->nvram_old_abi)rtc_nvram_register (rtc, nvmem_config->size); + +return 0 ; }void rtc_nvmem_unregister (struct rtc_device *rtc)
drivers/rtc/rtc-core.h +7 -4
@@ -48,11 +48,14 @@ static inline const struct attribute_group **rtc_get_dev_attribute_groups(void)#endif #ifdef CONFIG_RTC_NVMEM -void rtc_nvmem_register (struct rtc_device *rtc, -struct nvmem_config *nvmem_config); +int rtc_nvmem_register (struct rtc_device *rtc, +struct nvmem_config *nvmem_config);void rtc_nvmem_unregister (struct rtc_device *rtc);#else -static inline void rtc_nvmem_register (struct rtc_device *rtc, -struct nvmem_config *nvmem_config) {} +static inline int rtc_nvmem_register (struct rtc_device *rtc, +struct nvmem_config *nvmem_config) +{ +return -ENODEV ; +}static inline void rtc_nvmem_unregister (struct rtc_device *rtc) {}#endif
Signature · 1 line
2.16.1
Alexandre Belloni
maintainerPATCH 4/45 rtc: nvmem: disallow registering nvmem more than once
In reply to Alexandre BelloniMake rtc_nvmem_register return -EBUSY when an nvmem is already registered for that RTC.
--- drivers/rtc/nvmem.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/rtc/nvmem.c +3 -0
@@ -87,6 +87,9 @@ static void rtc_nvram_unregister(struct rtc_device *rtc)int rtc_nvmem_register (struct rtc_device *rtc,struct nvmem_config *nvmem_config) { +if (!IS_ERR_OR_NULL (rtc->nvmem)) +return -EBUSY ; +if (!nvmem_config)return -ENODEV ;
Signature · 1 line
2.16.1
Alexandre Belloni
maintainerPATCH 5/45 rtc: export rtc_nvmem_register() to drivers
In reply to Alexandre BelloniExport rtc_nvmem_register() so it can be called from drivers instead of only the core.
--- drivers/rtc/nvmem.c | 3 +-- drivers/rtc/rtc-core.h | 13 ------------- include/linux/rtc.h | 13 +++++++++++++ 3 files changed, 14 insertions(+), 15 deletions(-)
drivers/rtc/nvmem.c +1 -2
@@ -14,8 +14,6 @@#include <linux/rtc.h> #include <linux/sysfs.h> -#include "rtc-core.h" -/* * Deprecated ABI compatibility, this should be removed at some point */
@@ -105,6 +103,7 @@ int rtc_nvmem_register(struct rtc_device *rtc,return 0 ; } +EXPORT_SYMBOL_GPL (rtc_nvmem_register);void rtc_nvmem_unregister (struct rtc_device *rtc) {
drivers/rtc/rtc-core.h +0 -13
@@ -46,16 +46,3 @@ static inline const struct attribute_group **rtc_get_dev_attribute_groups(void) return NULL; }#endif - -#ifdef CONFIG_RTC_NVMEM -int rtc_nvmem_register (struct rtc_device *rtc, -struct nvmem_config *nvmem_config); -void rtc_nvmem_unregister (struct rtc_device *rtc); -#else -static inline int rtc_nvmem_register (struct rtc_device *rtc, -struct nvmem_config *nvmem_config) -{ -return -ENODEV ; -} -static inline void rtc_nvmem_unregister (struct rtc_device *rtc) {} -#endif
include/linux/rtc.h +13 -0
@@ -271,4 +271,17 @@ extern int rtc_hctosys_ret;#define rtc_hctosys_ret -ENODEV#endif +#ifdef CONFIG_RTC_NVMEM +int rtc_nvmem_register (struct rtc_device *rtc, +struct nvmem_config *nvmem_config); +void rtc_nvmem_unregister (struct rtc_device *rtc); +#else +static inline int rtc_nvmem_register (struct rtc_device *rtc, +struct nvmem_config *nvmem_config) +{ +return -ENODEV ; +} +static inline void rtc_nvmem_unregister (struct rtc_device *rtc) {} +#endif +#endif /* _LINUX_RTC_H_ */
Signature · 1 line
2.16.1
Alexandre Belloni
maintainerPATCH 6/45 rtc: ds1305: call rtc_nvmem_register()
In reply to Alexandre BelloniCall rtc_nvmem_register instead of letting the core do it and stop using the nvmem_config member of struct rtc_device.
--- drivers/rtc/rtc-ds1305.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/rtc/rtc-ds1305.c +2 -2
@@ -703,15 +703,15 @@ static int ds1305_probe(struct spi_device *spi) ds1305->rtc->ops = &ds1305_ops; ds1305_nvmem_cfg.priv = ds1305; - ds1305->rtc->nvmem_config = &ds1305_nvmem_cfg; ds1305->rtc->nvram_old_abi = true; - status =rtc_register_device (ds1305->rtc);if (status) {dev_dbg (&spi->dev,"register rtc --> %d\n" , status);return status; } +rtc_nvmem_register (ds1305->rtc, &ds1305_nvmem_cfg); +/* Maybe set up alarm IRQ; be ready to handle it triggering right * away. NOTE that we don't share this. The signal is active low, * and we can't ack it before a SPI message delay. We temporarily
Signature · 1 line
2.16.1
Alexandre Belloni
maintainerPATCH 7/45 rtc: ds1305: put ds1305_nvmem_cfg on the stack
In reply to Alexandre BelloniThis makes to code safer on system using two similar RTCs.
--- drivers/rtc/rtc-ds1305.c | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-)
drivers/rtc/rtc-ds1305.c +8 -9
@@ -544,15 +544,6 @@ static int ds1305_nvram_write(void *priv, unsigned int off, void *buf,return spi_sync (spi, &m); } -static struct nvmem_config ds1305_nvmem_cfg = { - .name ="ds1305_nvram" , - .word_size =1 , - .stride =1 , - .size =DS1305_NVRAM_LEN , - .reg_read = ds1305_nvram_read, - .reg_write = ds1305_nvram_write, -}; -/*----------------------------------------------------------------------*/ /*
@@ -566,6 +557,14 @@ static int ds1305_probe(struct spi_device *spi)u8 addr, value;struct ds1305_platform_data *pdata =dev_get_platdata (&spi->dev);bool write_ctrl = false; +struct nvmem_config ds1305_nvmem_cfg = { + .name ="ds1305_nvram" , + .word_size =1 , + .stride =1 , + .size =DS1305_NVRAM_LEN , + .reg_read = ds1305_nvram_read, + .reg_write = ds1305_nvram_write, + };/* Sanity check board setup data. This may be hooked up * in 3wire mode, but we don't care. Note that unless
Signature · 1 line
2.16.1
Alexandre Belloni
maintainerPATCH 8/45 rtc: ds1307: call rtc_nvmem_register()
In reply to Alexandre BelloniCall rtc_nvmem_register instead of letting the core do it and stop using the nvmem_config member of struct rtc_device.
--- drivers/rtc/rtc-ds1307.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)
drivers/rtc/rtc-ds1307.c +6 -6
@@ -1696,6 +1696,11 @@ static int ds1307_probe(struct i2c_client *client, } } + ds1307->rtc->ops = chip->rtc_ops ?: &ds13xx_rtc_ops; + err =rtc_register_device (ds1307->rtc); +if (err) +return err; +if (chip->nvram_size) { ds1307->nvmem_cfg.name ="ds1307_nvram" ; ds1307->nvmem_cfg.word_size =1 ;
@@ -1705,15 +1710,10 @@ static int ds1307_probe(struct i2c_client *client, ds1307->nvmem_cfg.reg_write = ds1307_nvram_write; ds1307->nvmem_cfg.priv = ds1307; - ds1307->rtc->nvmem_config = &ds1307->nvmem_cfg; ds1307->rtc->nvram_old_abi = true; +rtc_nvmem_register (ds1307->rtc, &ds1307->nvmem_cfg); } - ds1307->rtc->ops = chip->rtc_ops ?: &ds13xx_rtc_ops; - err =rtc_register_device (ds1307->rtc); -if (err) -return err; -ds1307_hwmon_register (ds1307);ds1307_clks_register (ds1307);
Signature · 1 line
2.16.1
Alexandre Belloni
maintainerPATCH 9/45 rtc: ds1307: put struct nvmem_config on the stack
In reply to Alexandre BelloniAvoid allocating memory for struct nvmem_config as it is only necessary at the nvmem registration.
--- drivers/rtc/rtc-ds1307.c | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-)
drivers/rtc/rtc-ds1307.c +10 -9
@@ -114,7 +114,6 @@ enum ds_type {# define RX8025_BIT_XST 0x20struct ds1307 { -struct nvmem_config nvmem_cfg;enum ds_type type;unsigned long flags;#define HAS_NVRAM 0/* bit 0 == sysfs file active */
@@ -1702,16 +1701,18 @@ static int ds1307_probe(struct i2c_client *client,return err;if (chip->nvram_size) { - ds1307->nvmem_cfg.name ="ds1307_nvram" ; - ds1307->nvmem_cfg.word_size =1 ; - ds1307->nvmem_cfg.stride =1 ; - ds1307->nvmem_cfg.size = chip->nvram_size; - ds1307->nvmem_cfg.reg_read = ds1307_nvram_read; - ds1307->nvmem_cfg.reg_write = ds1307_nvram_write; - ds1307->nvmem_cfg.priv = ds1307; +struct nvmem_config nvmem_cfg = { + .name ="ds1307_nvram" , + .word_size =1 , + .stride =1 , + .size = chip->nvram_size, + .reg_read = ds1307_nvram_read, + .reg_write = ds1307_nvram_write, + .priv = ds1307, + }; ds1307->rtc->nvram_old_abi = true; -rtc_nvmem_register (ds1307->rtc, &ds1307->nvmem_cfg); +rtc_nvmem_register (ds1307->rtc, &nvmem_cfg); }ds1307_hwmon_register (ds1307);
Signature · 1 line
2.16.1
Alexandre Belloni
maintainerPATCH 10/45 rtc: ds1511: call rtc_nvmem_register()
In reply to Alexandre BelloniCall rtc_nvmem_register instead of letting the core do it and stop using the nvmem_config member of struct rtc_device.
--- drivers/rtc/rtc-ds1511.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/rtc/rtc-ds1511.c +2 -1
@@ -479,13 +479,14 @@ static int ds1511_rtc_probe(struct platform_device *pdev) pdata->rtc->ops = &ds1511_rtc_ops; ds1511_nvmem_cfg.priv = &pdev->dev; - pdata->rtc->nvmem_config = &ds1511_nvmem_cfg; pdata->rtc->nvram_old_abi = true; ret =rtc_register_device (pdata->rtc);if (ret)return ret; +rtc_nvmem_register (pdata->rtc, &ds1511_nvmem_cfg); +/* * if the platform has an interrupt in mind for this device, * then by all means, set it
Signature · 1 line
2.16.1
Alexandre Belloni
maintainerPATCH 11/45 rtc: ds1511: put ds1511_nvmem_cfg on the stack
In reply to Alexandre BelloniMove ds1511_nvmem_cfg to the stack of ds1511_rtc_probe. This results in a very small code size reduction and make it safer on systems with two similar RTCs:
text data bss dec hex filename 2128 164 4 2296 8f8 drivers/rtc/rtc-ds1511.o.before 2175 100 4 2279 8e7 drivers/rtc/rtc-ds1511.o.after
--- drivers/rtc/rtc-ds1511.c | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-)
drivers/rtc/rtc-ds1511.c +9 -10
@@ -422,20 +422,20 @@ static int ds1511_nvram_write(void *priv, unsigned int pos, void *buf,return 0 ; } -static struct nvmem_config ds1511_nvmem_cfg = { - .name ="ds1511_nvram" , - .word_size =1 , - .stride =1 , - .size =DS1511_RAM_MAX , - .reg_read = ds1511_nvram_read, - .reg_write = ds1511_nvram_write, -}; -static int ds1511_rtc_probe (struct platform_device *pdev) {struct resource *res;struct rtc_plat_data *pdata;int ret =0 ; +struct nvmem_config ds1511_nvmem_cfg = { + .name ="ds1511_nvram" , + .word_size =1 , + .stride =1 , + .size =DS1511_RAM_MAX , + .reg_read = ds1511_nvram_read, + .reg_write = ds1511_nvram_write, + .priv = &pdev->dev, + }; pdata =devm_kzalloc (&pdev->dev,sizeof (*pdata),GFP_KERNEL );if (!pdata)
@@ -478,7 +478,6 @@ static int ds1511_rtc_probe(struct platform_device *pdev) pdata->rtc->ops = &ds1511_rtc_ops; - ds1511_nvmem_cfg.priv = &pdev->dev; pdata->rtc->nvram_old_abi = true; ret =rtc_register_device (pdata->rtc);
Signature · 1 line
2.16.1
Alexandre Belloni
maintainerPATCH 12/45 rtc: m48t86: call rtc_nvmem_register()
In reply to Alexandre BelloniCall rtc_nvmem_register instead of letting the core do it and stop using the nvmem_config member of struct rtc_device.
--- drivers/rtc/rtc-m48t86.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/rtc/rtc-m48t86.c +2 -1
@@ -266,13 +266,14 @@ static int m48t86_rtc_probe(struct platform_device *pdev) info->rtc->ops = &m48t86_rtc_ops; m48t86_nvmem_cfg.priv = &pdev->dev; - info->rtc->nvmem_config = &m48t86_nvmem_cfg; info->rtc->nvram_old_abi = true; err =rtc_register_device (info->rtc);if (err)return err; +rtc_nvmem_register (info->rtc, &m48t86_nvmem_cfg); +/* read battery status */ reg =m48t86_readb (&pdev->dev,M48T86_D ); dev_info(&pdev->dev, "battery %s\n",
Signature · 1 line
2.16.1
Alexandre Belloni
maintainerPATCH 13/45 rtc: m48t86: put m48t86_nvmem_cfg on the stack
In reply to Alexandre BelloniMove m48t86_nvmem_cfg to the stack of m48t86_rtc_probe. This results in a very small code size reduction and make it safer on systems with two similar RTCs:
text data bss dec hex filename 1733 164 0 1897 769 drivers/rtc/rtc-m48t86.o.before 1793 100 0 1893 765 drivers/rtc/rtc-m48t86.o.after
--- drivers/rtc/rtc-m48t86.c | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-)
drivers/rtc/rtc-m48t86.c +9 -11
@@ -218,21 +218,21 @@ static bool m48t86_verify_chip(struct platform_device *pdev)return false; } -static struct nvmem_config m48t86_nvmem_cfg = { - .name ="m48t86_nvram" , - .word_size =1 , - .stride =1 , - .size =M48T86_NVRAM_LEN , - .reg_read = m48t86_nvram_read, - .reg_write = m48t86_nvram_write, -}; -static int m48t86_rtc_probe (struct platform_device *pdev) {struct m48t86_rtc_info *info;struct resource *res;unsigned char reg;int err; +struct nvmem_config m48t86_nvmem_cfg = { + .name ="m48t86_nvram" , + .word_size =1 , + .stride =1 , + .size =M48T86_NVRAM_LEN , + .reg_read = m48t86_nvram_read, + .reg_write = m48t86_nvram_write, + .priv = &pdev->dev, + }; info =devm_kzalloc (&pdev->dev,sizeof (*info),GFP_KERNEL );if (!info)
@@ -264,8 +264,6 @@ static int m48t86_rtc_probe(struct platform_device *pdev)return PTR_ERR (info->rtc); info->rtc->ops = &m48t86_rtc_ops; - - m48t86_nvmem_cfg.priv = &pdev->dev; info->rtc->nvram_old_abi = true; err =rtc_register_device (info->rtc);
Signature · 1 line
2.16.1
Alexandre Belloni
maintainerPATCH 14/45 rtc: omap: call rtc_nvmem_register()
In reply to Alexandre BelloniCall rtc_nvmem_register instead of letting the core do it and stop using the nvmem_config member of struct rtc_device.
--- drivers/rtc/rtc-omap.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/rtc/rtc-omap.c +2 -1
@@ -850,7 +850,6 @@ static int omap_rtc_probe(struct platform_device *pdev) rtc->rtc->ops = &omap_rtc_ops; omap_rtc_nvmem_config.priv = rtc; - rtc->rtc->nvmem_config = &omap_rtc_nvmem_config;/* handle periodic and alarm irqs */ ret = devm_request_irq(&pdev->dev, rtc->irq_timer, rtc_irq, 0,
@@ -886,6 +885,8 @@ static int omap_rtc_probe(struct platform_device *pdev)if (ret) goto err; +rtc_nvmem_register (rtc->rtc, &omap_rtc_nvmem_config); +return 0 ; err:
Signature · 1 line
2.16.1
Alexandre Belloni
maintainerPATCH 15/45 rtc: pcf85363: call rtc_nvmem_register()
In reply to Alexandre BelloniCall rtc_nvmem_register instead of letting the core do it and stop using the nvmem_config member of struct rtc_device.
--- drivers/rtc/rtc-pcf85363.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
drivers/rtc/rtc-pcf85363.c +6 -2
@@ -164,6 +164,7 @@ static int pcf85363_probe(struct i2c_client *client, const struct i2c_device_id *id) {struct pcf85363 *pcf85363; +int ret;if (!i2c_check_functionality (client->adapter,I2C_FUNC_I2C ))return -ENODEV ;
@@ -193,10 +194,13 @@ static int pcf85363_probe(struct i2c_client *client, pcf85363->nvmem_cfg.reg_read = pcf85363_nvram_read; pcf85363->nvmem_cfg.reg_write = pcf85363_nvram_write; pcf85363->nvmem_cfg.priv = pcf85363; - pcf85363->rtc->nvmem_config = &pcf85363->nvmem_cfg; pcf85363->rtc->ops = &rtc_ops; -return rtc_register_device (pcf85363->rtc); + ret =rtc_register_device (pcf85363->rtc); + +rtc_nvmem_register (pcf85363->rtc, &pcf85363->nvmem_cfg); + +return ret; }static const struct of_device_id dev_ids[] = {
Signature · 1 line
2.16.1
Alexandre Belloni
maintainerPATCH 16/45 rtc: pcf85363: put struct nvmem_config on the stack
In reply to Alexandre BelloniAvoid allocating memory for struct nvmem_config.
--- drivers/rtc/rtc-pcf85363.c | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-)
drivers/rtc/rtc-pcf85363.c +10 -9
@@ -80,7 +80,6 @@ static struct i2c_driver pcf85363_driver;struct pcf85363 {struct device *dev;struct rtc_device *rtc; -struct nvmem_config nvmem_cfg;struct regmap *regmap; };
@@ -164,6 +163,14 @@ static int pcf85363_probe(struct i2c_client *client, const struct i2c_device_id *id) {struct pcf85363 *pcf85363; +struct nvmem_config nvmem_cfg = { + .name ="pcf85363-" , + .word_size =1 , + .stride =1 , + .size =NVRAM_SIZE , + .reg_read = pcf85363_nvram_read, + .reg_write = pcf85363_nvram_write, + };int ret;if (!i2c_check_functionality (client->adapter,I2C_FUNC_I2C ))
@@ -187,18 +194,12 @@ static int pcf85363_probe(struct i2c_client *client,if (IS_ERR (pcf85363->rtc))return PTR_ERR (pcf85363->rtc); - pcf85363->nvmem_cfg.name ="pcf85363-" ; - pcf85363->nvmem_cfg.word_size =1 ; - pcf85363->nvmem_cfg.stride =1 ; - pcf85363->nvmem_cfg.size =NVRAM_SIZE ; - pcf85363->nvmem_cfg.reg_read = pcf85363_nvram_read; - pcf85363->nvmem_cfg.reg_write = pcf85363_nvram_write; - pcf85363->nvmem_cfg.priv = pcf85363; pcf85363->rtc->ops = &rtc_ops; ret =rtc_register_device (pcf85363->rtc); -rtc_nvmem_register (pcf85363->rtc, &pcf85363->nvmem_cfg); + nvmem_cfg.priv = pcf85363; +rtc_nvmem_register (pcf85363->rtc, &nvmem_cfg);return ret; }
Signature · 1 line
2.16.1
Alexandre Belloni
maintainerPATCH 17/45 rtc: rv8803: call rtc_nvmem_register()
In reply to Alexandre BelloniCall rtc_nvmem_register instead of letting the core do it and stop using the nvmem_config member of struct rtc_device.
--- drivers/rtc/rtc-rv8803.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/rtc/rtc-rv8803.c +2 -1
@@ -591,12 +591,13 @@ static int rv8803_probe(struct i2c_client *client, rv8803->nvmem_cfg.priv = client; rv8803->rtc->ops = &rv8803_rtc_ops; - rv8803->rtc->nvmem_config = &rv8803->nvmem_cfg; rv8803->rtc->nvram_old_abi = true; err =rtc_register_device (rv8803->rtc);if (err)return err; +rtc_nvmem_register (rv8803->rtc, &rv8803->nvmem_cfg); + err =rv8803_write_reg (rv8803->client,RV8803_EXT ,RV8803_EXT_WADA );if (err)return err;
Signature · 1 line
2.16.1
Alexandre Belloni
maintainerPATCH 18/45 rtc: rv8803: put struct nvmem_config on the stack
In reply to Alexandre BelloniAvoid allocating memory for struct nvmem_config.
--- drivers/rtc/rtc-rv8803.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-)
drivers/rtc/rtc-rv8803.c +10 -10
@@ -68,7 +68,6 @@ struct rv8803_data {struct mutex flags_lock;u8 ctrl;enum rv8803_type type; -struct nvmem_config nvmem_cfg; };static int rv8803_read_reg (const struct i2c_client *client,u8 reg)
@@ -528,6 +527,15 @@ static int rv8803_probe(struct i2c_client *client,struct i2c_adapter *adapter =to_i2c_adapter (client->dev.parent);struct rv8803_data *rv8803;int err, flags; +struct nvmem_config nvmem_cfg = { + .name ="rv8803_nvram" , + .word_size =1 , + .stride =1 , + .size =1 , + .reg_read = rv8803_nvram_read, + .reg_write = rv8803_nvram_write, + .priv = client, + };if (!i2c_check_functionality (adapter,I2C_FUNC_SMBUS_BYTE_DATA |I2C_FUNC_SMBUS_I2C_BLOCK )) {
@@ -582,21 +590,13 @@ static int rv8803_probe(struct i2c_client *client, } } - rv8803->nvmem_cfg.name ="rv8803_nvram" , - rv8803->nvmem_cfg.word_size =1 , - rv8803->nvmem_cfg.stride =1 , - rv8803->nvmem_cfg.size =1 , - rv8803->nvmem_cfg.reg_read = rv8803_nvram_read, - rv8803->nvmem_cfg.reg_write = rv8803_nvram_write, - rv8803->nvmem_cfg.priv = client; - rv8803->rtc->ops = &rv8803_rtc_ops; rv8803->rtc->nvram_old_abi = true; err =rtc_register_device (rv8803->rtc);if (err)return err; -rtc_nvmem_register (rv8803->rtc, &rv8803->nvmem_cfg); +rtc_nvmem_register (rv8803->rtc, &nvmem_cfg); err =rv8803_write_reg (rv8803->client,RV8803_EXT ,RV8803_EXT_WADA );if (err)
Signature · 1 line
2.16.1
Alexandre Belloni
maintainerPATCH 19/45 rtc: rv8803: fix possible race condition
In reply to Alexandre BelloniThe probe function is not allowed to fail after registering the RTC. Call rtc_register_device() at the end.
--- drivers/rtc/rtc-rv8803.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-)
drivers/rtc/rtc-rv8803.c +8 -8
@@ -590,14 +590,6 @@ static int rv8803_probe(struct i2c_client *client, } } - rv8803->rtc->ops = &rv8803_rtc_ops; - rv8803->rtc->nvram_old_abi = true; - err =rtc_register_device (rv8803->rtc); -if (err) -return err; - -rtc_nvmem_register (rv8803->rtc, &nvmem_cfg); - err =rv8803_write_reg (rv8803->client,RV8803_EXT ,RV8803_EXT_WADA );if (err)return err;
@@ -608,6 +600,14 @@ static int rv8803_probe(struct i2c_client *client,return err; } + rv8803->rtc->ops = &rv8803_rtc_ops; + rv8803->rtc->nvram_old_abi = true; + err =rtc_register_device (rv8803->rtc); +if (err) +return err; + +rtc_nvmem_register (rv8803->rtc, &nvmem_cfg); + rv8803->rtc->max_user_freq =1 ;return 0 ;
Signature · 1 line
2.16.1
Alexandre Belloni
maintainerPATCH 20/45 rtc: remove nvmem_config
In reply to Alexandre BelloniBecause nvmem_config is only used and copied at nvmem registration, remove it from struct rtc_device.
All the rtc drivers using nvmem are now calling rtc_nvmem_register directly.
--- drivers/rtc/class.c | 2 -- include/linux/rtc.h | 1 - 2 files changed, 3 deletions(-)
drivers/rtc/class.c +0 -2
@@ -453,8 +453,6 @@ int __rtc_register_device(struct module *owner, struct rtc_device *rtc)rtc_proc_add_device (rtc); -rtc_nvmem_register (rtc, rtc->nvmem_config); - rtc->registered = true;dev_info (rtc->dev.parent,"registered as %s\n" ,dev_name (&rtc->dev));
include/linux/rtc.h +0 -1
@@ -145,7 +145,6 @@ struct rtc_device {bool registered; -struct nvmem_config *nvmem_config;struct nvmem_device *nvmem;/* Old ABI support */ bool nvram_old_abi;
Signature · 1 line
2.16.1
Alexandre Belloni
maintainerPATCH 21/45 rtc: ds1343: simplify regmap initialization
In reply to Alexandre BelloniAvoid using memset as gcc can properly initialize structures.
--- drivers/rtc/rtc-ds1343.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-)
drivers/rtc/rtc-ds1343.c +2 -6
@@ -599,15 +599,11 @@ static const struct rtc_class_ops ds1343_rtc_ops = {static int ds1343_probe (struct spi_device *spi) {struct ds1343_priv *priv; -struct regmap_config config; +struct regmap_config config = { .reg_bits =8 , .val_bits =8 , + .write_flag_mask =0x80 , };unsigned int data;int res; -memset (&config,0 ,sizeof (config)); - config.reg_bits =8 ; - config.val_bits =8 ; - config.write_flag_mask =0x80 ; - priv =devm_kzalloc (&spi->dev,sizeof (struct ds1343_priv ),GFP_KERNEL );if (!priv)return -ENOMEM ;
Signature · 1 line
2.16.1
Alexandre Belloni
maintainerPATCH 22/45 rtc: ds1343: switch to rtc_register_device
In reply to Alexandre BelloniThis allows for future improvement of the driver.
--- drivers/rtc/rtc-ds1343.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-)
drivers/rtc/rtc-ds1343.c +8 -5
@@ -642,12 +642,15 @@ static int ds1343_probe(struct spi_device *spi) data &= ~(DS1343_OSF |DS1343_IRQF1 |DS1343_IRQF0 );regmap_write (priv->map,DS1343_STATUS_REG , data); - priv->rtc =devm_rtc_device_register (&spi->dev,"ds1343" , - &ds1343_rtc_ops,THIS_MODULE ); -if (IS_ERR (priv->rtc)) { -dev_err (&spi->dev,"unable to register rtc ds1343\n" ); + priv->rtc =devm_rtc_allocate_device (&spi->dev); +if (IS_ERR (priv->rtc))return PTR_ERR (priv->rtc); - } + + priv->rtc->ops = &ds1343_rtc_ops; + + res =rtc_register_device (priv->rtc); +if (res) +return res; priv->irq = spi->irq;
Signature · 1 line
2.16.1
Alexandre Belloni
maintainerPATCH 23/45 rtc: ds1343: remove undocumented and useless sysfs files
In reply to Alexandre BelloniA documented ABI already exists to get information about the alarm. It is the only one that is used.
--- drivers/rtc/rtc-ds1343.c | 96 +----------------------------------------------- 1 file changed, 1 insertion(+), 95 deletions(-)
drivers/rtc/rtc-ds1343.c +1 -95
@@ -199,74 +199,6 @@ static struct bin_attribute nvram_attr = { .size = DS1343_NVRAM_LEN, }; -static ssize_t ds1343_show_alarmstatus (struct device *dev, -struct device_attribute *attr,char *buf) -{ -struct ds1343_priv *priv =dev_get_drvdata (dev); -int alarmstatus, data; - -regmap_read (priv->map,DS1343_CONTROL_REG , &data); - - alarmstatus = !!(data &DS1343_A0IE ); - -if (alarmstatus) -return sprintf (buf,"enabled\n" ); -else -return sprintf (buf,"disabled\n" ); -} - -static DEVICE_ATTR(alarm_status, S_IRUGO, ds1343_show_alarmstatus, NULL); - -static ssize_t ds1343_show_alarmmode (struct device *dev, -struct device_attribute *attr,char *buf) -{ -struct ds1343_priv *priv =dev_get_drvdata (dev); -int alarm_mode, data; -char *alarm_str; - -regmap_read (priv->map,DS1343_ALM0_SEC_REG , &data); - alarm_mode = (data &0x80 ) >>4 ; - -regmap_read (priv->map,DS1343_ALM0_MIN_REG , &data); - alarm_mode |= (data &0x80 ) >>5 ; - -regmap_read (priv->map,DS1343_ALM0_HOUR_REG , &data); - alarm_mode |= (data &0x80 ) >>6 ; - -regmap_read (priv->map,DS1343_ALM0_DAY_REG , &data); - alarm_mode |= (data &0x80 ) >>7 ; - -switch (alarm_mode) { -case 15 : - alarm_str ="each second" ; -break ; - -case 7 : - alarm_str ="seconds match" ; -break ; - -case 3 : - alarm_str ="minutes and seconds match" ; -break ; - -case 1 : - alarm_str ="hours, minutes and seconds match" ; -break ; - -case 0 : - alarm_str ="day, hours, minutes and seconds match" ; -break ; - -default : - alarm_str ="invalid" ; -break ; - } - -return sprintf (buf,"%s\n" , alarm_str); -} - -static DEVICE_ATTR(alarm_mode, S_IRUGO, ds1343_show_alarmmode, NULL); -static ssize_t ds1343_show_tricklecharger (struct device *dev,struct device_attribute *attr,char *buf) {
@@ -313,7 +245,6 @@ static DEVICE_ATTR(trickle_charger, S_IRUGO, ds1343_show_tricklecharger, NULL);static int ds1343_sysfs_register (struct device *dev) { -struct ds1343_priv *priv =dev_get_drvdata (dev);int err; err =device_create_file (dev, &dev_attr_glitch_filter);
@@ -325,26 +256,9 @@ static int ds1343_sysfs_register(struct device *dev) goto error1; err =device_create_bin_file (dev, &nvram_attr); -if (err) - goto error2; - -if (priv->irq <=0 ) -return err; - - err =device_create_file (dev, &dev_attr_alarm_mode); -if (err) - goto error3; - - err =device_create_file (dev, &dev_attr_alarm_status);if (!err) -return err; - -device_remove_file (dev, &dev_attr_alarm_mode); - -error3: -device_remove_bin_file (dev, &nvram_attr); +return 0 ; -error2:device_remove_file (dev, &dev_attr_trickle_charger); error1:
@@ -355,17 +269,9 @@ static int ds1343_sysfs_register(struct device *dev)static void ds1343_sysfs_unregister (struct device *dev) { -struct ds1343_priv *priv =dev_get_drvdata (dev); -device_remove_file (dev, &dev_attr_glitch_filter);device_remove_file (dev, &dev_attr_trickle_charger);device_remove_bin_file (dev, &nvram_attr); - -if (priv->irq <=0 ) -return ; - -device_remove_file (dev, &dev_attr_alarm_status); -device_remove_file (dev, &dev_attr_alarm_mode); }static int ds1343_read_time (struct device *dev,struct rtc_time *dt)
Signature · 1 line
2.16.1
Alexandre Belloni
maintainerPATCH 24/45 rtc: ds1343: use generic nvmem
In reply to Alexandre BelloniInstead of adding a binary sysfs attribute from the driver (which suffers from a race condition as the attribute appears after the device), use the core to register an nvmem device.
--- drivers/rtc/rtc-ds1343.c | 66 +++++++++++++++--------------------------------- 1 file changed, 20 insertions(+), 46 deletions(-)
drivers/rtc/rtc-ds1343.c +20 -46
@@ -153,52 +153,22 @@ static ssize_t ds1343_store_glitchfilter(struct device *dev, static DEVICE_ATTR(glitch_filter, S_IRUGO | S_IWUSR, ds1343_show_glitchfilter, ds1343_store_glitchfilter); -static ssize_t ds1343_nvram_write (struct file *filp,struct kobject *kobj, -struct bin_attribute *attr, -char *buf,loff_t off,size_t count) +static int ds1343_nvram_write (void *priv,unsigned int off,void *val, +size_t bytes) { -int ret; -unsigned char address; -struct device *dev =kobj_to_dev (kobj); -struct ds1343_priv *priv =dev_get_drvdata (dev); - - address =DS1343_NVRAM + off; +struct ds1343_priv *ds1343 = priv; - ret =regmap_bulk_write (priv->map, address, buf, count); -if (ret <0 ) -dev_err (&priv->spi->dev,"Error in nvram write %d" , ret); - -return (ret <0 ) ? ret : count; +return regmap_bulk_write (ds1343->map,DS1343_NVRAM + off, val, bytes); } - -static ssize_t ds1343_nvram_read (struct file *filp,struct kobject *kobj, -struct bin_attribute *attr, -char *buf,loff_t off,size_t count) +static int ds1343_nvram_read (void *priv,unsigned int off,void *val, +size_t bytes) { -int ret; -unsigned char address; -struct device *dev =kobj_to_dev (kobj); -struct ds1343_priv *priv =dev_get_drvdata (dev); - - address =DS1343_NVRAM + off; +struct ds1343_priv *ds1343 = priv; - ret =regmap_bulk_read (priv->map, address, buf, count); -if (ret <0 ) -dev_err (&priv->spi->dev,"Error in nvram read %d\n" , ret); - -return (ret <0 ) ? ret : count; +return regmap_bulk_read (ds1343->map,DS1343_NVRAM + off, val, bytes); } - -static struct bin_attribute nvram_attr = { - .attr.name ="nvram" , - .attr.mode =S_IRUGO |S_IWUSR , - .read = ds1343_nvram_read, - .write = ds1343_nvram_write, - .size =DS1343_NVRAM_LEN , -}; -static ssize_t ds1343_show_tricklecharger (struct device *dev,struct device_attribute *attr,char *buf) {
@@ -252,16 +222,9 @@ static int ds1343_sysfs_register(struct device *dev)return err; err =device_create_file (dev, &dev_attr_trickle_charger); -if (err) - goto error1; - - err =device_create_bin_file (dev, &nvram_attr);if (!err)return 0 ; -device_remove_file (dev, &dev_attr_trickle_charger); - -error1:device_remove_file (dev, &dev_attr_glitch_filter);return err;
@@ -271,7 +234,6 @@ static void ds1343_sysfs_unregister(struct device *dev) {device_remove_file (dev, &dev_attr_glitch_filter);device_remove_file (dev, &dev_attr_trickle_charger); -device_remove_bin_file (dev, &nvram_attr); }static int ds1343_read_time (struct device *dev,struct rtc_time *dt)
@@ -509,6 +471,14 @@ static int ds1343_probe(struct spi_device *spi) .write_flag_mask = 0x80, };unsigned int data;int res; +struct nvmem_config nvmem_cfg = { + .name ="ds1343-" , + .word_size =1 , + .stride =1 , + .size =DS1343_NVRAM_LEN , + .reg_read = ds1343_nvram_read, + .reg_write = ds1343_nvram_write, + }; priv =devm_kzalloc (&spi->dev,sizeof (struct ds1343_priv ),GFP_KERNEL );if (!priv)
@@ -552,12 +522,16 @@ static int ds1343_probe(struct spi_device *spi)if (IS_ERR (priv->rtc))return PTR_ERR (priv->rtc); + priv->rtc->nvram_old_abi = true; priv->rtc->ops = &ds1343_rtc_ops; res =rtc_register_device (priv->rtc);if (res)return res; + nvmem_cfg.priv = priv; +rtc_nvmem_register (priv->rtc, &nvmem_cfg); + priv->irq = spi->irq;if (priv->irq >=0 ) {
Signature · 1 line
2.16.1
Alexandre Belloni
maintainerPATCH 25/45 rtc: m48t59: switch to rtc_register_device
In reply to Alexandre BelloniThis allows for future improvement of the driver.
--- drivers/rtc/rtc-m48t59.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-)
drivers/rtc/rtc-m48t59.c +7 -2
@@ -480,11 +480,16 @@ static int m48t59_rtc_probe(struct platform_device *pdev)spin_lock_init (&m48t59->lock);platform_set_drvdata (pdev, m48t59); - m48t59->rtc =devm_rtc_device_register (&pdev->dev, name, ops, -THIS_MODULE ); + m48t59->rtc =devm_rtc_allocate_device (&pdev->dev);if (IS_ERR (m48t59->rtc))return PTR_ERR (m48t59->rtc); + m48t59->rtc->ops = ops; + + ret =rtc_register_device (m48t59->rtc); +if (ret) +return ret; + m48t59_nvram_attr.size = pdata->offset; ret =sysfs_create_bin_file (&pdev->dev.kobj, &m48t59_nvram_attr);
Signature · 1 line
2.16.1
Alexandre Belloni
maintainerPATCH 26/45 rtc: m48t59: use generic nvmem
In reply to Alexandre BelloniInstead of adding a binary sysfs attribute from the driver (which suffers from a race condition as the attribute appears after the device), use the core to register an nvmem device.
--- drivers/rtc/rtc-m48t59.c | 56 ++++++++++++++++++++---------------------------- 1 file changed, 23 insertions(+), 33 deletions(-)
drivers/rtc/rtc-m48t59.c +23 -33
@@ -334,16 +334,16 @@ static const struct rtc_class_ops m48t02_rtc_ops = { .set_time = m48t59_rtc_set_time, }; -static ssize_t m48t59_nvram_read (struct file *filp,struct kobject *kobj, -struct bin_attribute *bin_attr, -char *buf,loff_t pos,size_t size) +static int m48t59_nvram_read (void *priv,unsigned int offset,void *val, +size_t size) { - struct device *dev = container_of(kobj, struct device, kobj); -struct platform_device *pdev =to_platform_device (dev); +struct platform_device *pdev = priv; +struct device *dev = &pdev->dev;struct m48t59_plat_data *pdata =dev_get_platdata (&pdev->dev);struct m48t59_private *m48t59 =platform_get_drvdata (pdev);ssize_t cnt =0 ;unsigned long flags; +u8 *buf = val;spin_lock_irqsave (&m48t59->lock, flags);
@@ -352,19 +352,19 @@ static ssize_t m48t59_nvram_read(struct file *filp, struct kobject *kobj,spin_unlock_irqrestore (&m48t59->lock, flags); -return cnt; +return 0 ; } -static ssize_t m48t59_nvram_write (struct file *filp,struct kobject *kobj, -struct bin_attribute *bin_attr, -char *buf,loff_t pos,size_t size) +static int m48t59_nvram_write (void *priv,unsigned int offset,void *val, +size_t size) { - struct device *dev = container_of(kobj, struct device, kobj); -struct platform_device *pdev =to_platform_device (dev); +struct platform_device *pdev = priv; +struct device *dev = &pdev->dev;struct m48t59_plat_data *pdata =dev_get_platdata (&pdev->dev);struct m48t59_private *m48t59 =platform_get_drvdata (pdev);ssize_t cnt =0 ;unsigned long flags; +u8 *buf = val;spin_lock_irqsave (&m48t59->lock, flags);
@@ -373,18 +373,9 @@ static ssize_t m48t59_nvram_write(struct file *filp, struct kobject *kobj,spin_unlock_irqrestore (&m48t59->lock, flags); -return cnt; +return 0 ; } -static struct bin_attribute m48t59_nvram_attr = { - .attr = { - .name ="nvram" , - .mode =S_IRUGO |S_IWUSR , - }, - .read = m48t59_nvram_read, - .write = m48t59_nvram_write, -}; -static int m48t59_rtc_probe (struct platform_device *pdev) {struct m48t59_plat_data *pdata =dev_get_platdata (&pdev->dev);
@@ -393,6 +384,15 @@ static int m48t59_rtc_probe(struct platform_device *pdev)int ret = -ENOMEM ;char *name;const struct rtc_class_ops *ops; +struct nvmem_config nvmem_cfg = { + .name ="m48t59-" , + .word_size =1 , + .stride =1 , + .size = pdata->offset, + .reg_read = m48t59_nvram_read, + .reg_write = m48t59_nvram_write, + .priv = pdev, + };/* This chip could be memory-mapped or I/O-mapped */ res =platform_get_resource (pdev,IORESOURCE_MEM ,0 );
@@ -484,24 +484,15 @@ static int m48t59_rtc_probe(struct platform_device *pdev)if (IS_ERR (m48t59->rtc))return PTR_ERR (m48t59->rtc); + m48t59->rtc->nvram_old_abi = true; m48t59->rtc->ops = ops; ret =rtc_register_device (m48t59->rtc);if (ret)return ret; - m48t59_nvram_attr.size = pdata->offset; +rtc_nvmem_register (m48t59->rtc, &nvmem_cfg); - ret =sysfs_create_bin_file (&pdev->dev.kobj, &m48t59_nvram_attr); -if (ret) -return ret; - -return 0 ; -} - -static int m48t59_rtc_remove (struct platform_device *pdev) -{ -sysfs_remove_bin_file (&pdev->dev.kobj, &m48t59_nvram_attr);return 0 ; }
@@ -513,7 +504,6 @@ static struct platform_driver m48t59_rtc_driver = { .name = "rtc-m48t59", }, .probe = m48t59_rtc_probe, - .remove = m48t59_rtc_remove, };module_platform_driver (m48t59_rtc_driver);
Signature · 1 line
2.16.1
Alexandre Belloni
maintainerPATCH 27/45 rtc: sirfsoc: remove useless sirfsoc_rtc_ioctl
In reply to Alexandre Bellonisirfsoc_rtc_ioctl() doesn't implement any actual ioctl, remove it.
--- drivers/rtc/rtc-sirfsoc.c | 18 ------------------ 1 file changed, 18 deletions(-)
drivers/rtc/rtc-sirfsoc.c +0 -18
@@ -204,23 +204,6 @@ static int sirfsoc_rtc_set_time(struct device *dev,return 0 ; } -static int sirfsoc_rtc_ioctl (struct device *dev,unsigned int cmd, -unsigned long arg) -{ -switch (cmd) { -case RTC_PIE_ON : -case RTC_PIE_OFF : -case RTC_UIE_ON : -case RTC_UIE_OFF : -case RTC_AIE_ON : -case RTC_AIE_OFF : -return 0 ; - -default : -return -ENOIOCTLCMD ; - } -} -static int sirfsoc_rtc_alarm_irq_enable (struct device *dev,unsigned int enabled) {
@@ -250,7 +233,6 @@ static const struct rtc_class_ops sirfsoc_rtc_ops = { .set_time = sirfsoc_rtc_set_time, .read_alarm = sirfsoc_rtc_read_alarm, .set_alarm = sirfsoc_rtc_set_alarm, - .ioctl = sirfsoc_rtc_ioctl, .alarm_irq_enable = sirfsoc_rtc_alarm_irq_enable };
Signature · 1 line
2.16.1
Alexandre Belloni
maintainerPATCH 28/45 rtc: ds1553: switch to rtc_register_device
In reply to Alexandre BelloniThis allows for future improvement of the driver.
--- drivers/rtc/rtc-ds1553.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-)
drivers/rtc/rtc-ds1553.c +7 -2
@@ -308,11 +308,16 @@ static int ds1553_rtc_probe(struct platform_device *pdev) pdata->last_jiffies = jiffies;platform_set_drvdata (pdev, pdata); - pdata->rtc =devm_rtc_device_register (&pdev->dev, pdev->name, - &ds1553_rtc_ops,THIS_MODULE ); + pdata->rtc =devm_rtc_allocate_device (&pdev->dev);if (IS_ERR (pdata->rtc))return PTR_ERR (pdata->rtc); + pdata->rtc->ops = &ds1553_rtc_ops; + + ret =rtc_register_device (pdata->rtc); +if (ret) +return ret; +if (pdata->irq >0 ) {writeb (0 , ioaddr +RTC_INTERRUPTS ); if (devm_request_irq(&pdev->dev, pdata->irq,
Signature · 1 line
2.16.1
Alexandre Belloni
maintainerPATCH 29/45 rtc: ds1553: use generic nvmem
In reply to Alexandre BelloniInstead of adding a binary sysfs attribute from the driver (which suffers from a race condition as the attribute appears after the device), use the core to register an nvmem device.
--- drivers/rtc/rtc-ds1553.c | 55 +++++++++++++++++++++--------------------------- 1 file changed, 24 insertions(+), 31 deletions(-)
drivers/rtc/rtc-ds1553.c +24 -31
@@ -233,46 +233,32 @@ static const struct rtc_class_ops ds1553_rtc_ops = { .alarm_irq_enable = ds1553_rtc_alarm_irq_enable, }; -static ssize_t ds1553_nvram_read (struct file *filp,struct kobject *kobj, -struct bin_attribute *bin_attr, -char *buf,loff_t pos,size_t size) +static int ds1553_nvram_read (void *priv,unsigned int pos,void *val, +size_t bytes) { - struct device *dev = container_of(kobj, struct device, kobj); -struct platform_device *pdev =to_platform_device (dev); +struct platform_device *pdev = priv;struct rtc_plat_data *pdata =platform_get_drvdata (pdev);void __iomem *ioaddr = pdata->ioaddr; -ssize_t count; +u8 *buf = val; -for (count =0 ; count < size; count++) +for (; bytes; bytes--) *buf++ =readb (ioaddr + pos++); -return count; +return 0 ; } -static ssize_t ds1553_nvram_write (struct file *filp,struct kobject *kobj, -struct bin_attribute *bin_attr, -char *buf,loff_t pos,size_t size) +static int ds1553_nvram_write (void *priv,unsigned int pos,void *val, +size_t bytes) { - struct device *dev = container_of(kobj, struct device, kobj); -struct platform_device *pdev =to_platform_device (dev); +struct platform_device *pdev = priv;struct rtc_plat_data *pdata =platform_get_drvdata (pdev);void __iomem *ioaddr = pdata->ioaddr; -ssize_t count; +u8 *buf = val; -for (count =0 ; count < size; count++) +for (; bytes; bytes--)writeb (*buf++, ioaddr + pos++); -return count; +return 0 ; } -static struct bin_attribute ds1553_nvram_attr = { - .attr = { - .name ="nvram" , - .mode =S_IRUGO |S_IWUSR , - }, - .size =RTC_OFFSET , - .read = ds1553_nvram_read, - .write = ds1553_nvram_write, -}; -static int ds1553_rtc_probe (struct platform_device *pdev) {struct resource *res;
@@ -280,6 +266,15 @@ static int ds1553_rtc_probe(struct platform_device *pdev)struct rtc_plat_data *pdata;void __iomem *ioaddr;int ret =0 ; +struct nvmem_config nvmem_cfg = { + .name ="ds1553_nvram" , + .word_size =1 , + .stride =1 , + .size =RTC_OFFSET , + .reg_read = ds1553_nvram_read, + .reg_write = ds1553_nvram_write, + .priv = pdev, + }; pdata =devm_kzalloc (&pdev->dev,sizeof (*pdata),GFP_KERNEL );if (!pdata)
@@ -313,6 +308,7 @@ static int ds1553_rtc_probe(struct platform_device *pdev)return PTR_ERR (pdata->rtc); pdata->rtc->ops = &ds1553_rtc_ops; + pdata->rtc->nvram_old_abi = true; ret =rtc_register_device (pdata->rtc);if (ret)
@@ -328,10 +324,8 @@ static int ds1553_rtc_probe(struct platform_device *pdev) } } - ret =sysfs_create_bin_file (&pdev->dev.kobj, &ds1553_nvram_attr); -if (ret) -dev_err (&pdev->dev,"unable to create sysfs file: %s\n" , - ds1553_nvram_attr.attr.name); +if (rtc_nvmem_register (pdata->rtc, &nvmem_cfg)) +dev_err (&pdev->dev,"unable to register nvmem\n" );return 0 ; }
@@ -340,7 +334,6 @@ static int ds1553_rtc_remove(struct platform_device *pdev) {struct rtc_plat_data *pdata =platform_get_drvdata (pdev); -sysfs_remove_bin_file (&pdev->dev.kobj, &ds1553_nvram_attr);if (pdata->irq >0 )writeb (0 , pdata->ioaddr +RTC_INTERRUPTS );return 0 ;
Signature · 1 line
2.16.1
Alexandre Belloni
maintainerPATCH 30/45 rtc: ds1553: make alarms useful
In reply to Alexandre BelloniCurrently, the IRQs are disabled when the rtc driver is removed (e.g. when shutting down the platform).
This means that the RTC will be unable to wakeup the platform.
--- drivers/rtc/rtc-ds1553.c | 10 ---------- 1 file changed, 10 deletions(-)
drivers/rtc/rtc-ds1553.c +0 -10
@@ -330,21 +330,11 @@ static int ds1553_rtc_probe(struct platform_device *pdev)return 0 ; } -static int ds1553_rtc_remove (struct platform_device *pdev) -{ -struct rtc_plat_data *pdata =platform_get_drvdata (pdev); - -if (pdata->irq >0 ) -writeb (0 , pdata->ioaddr +RTC_INTERRUPTS ); -return 0 ; -} -/* work with hotplug and coldplug */ MODULE_ALIAS ("platform:rtc-ds1553" );static struct platform_driver ds1553_rtc_driver = { .probe = ds1553_rtc_probe, - .remove = ds1553_rtc_remove, .driver = { .name ="rtc-ds1553" , },
Signature · 1 line
2.16.1
Alexandre Belloni
maintainerPATCH 31/45 rtc: cmos: fix possible race condition
In reply to Alexandre BelloniThe probe function is not allowed to fail after registering the RTC because the following may happen:
CPU0: CPU1:sys_load_module()
do_init_module()
do_one_initcall()
cmos_do_probe()
rtc_device_register()
__register_chrdev()
cdev->owner = struct module*
open("/dev/rtc0")
rtc_device_unregister()
module_put()
free_module()
module_free(mod->module_core)
/* struct module *module is now
freed */
chrdev_open()
spin_lock(cdev_lock)
cdev_get()
try_module_get()
module_is_live()
/* dereferences already
freed struct module* */Switch to devm_rtc_allocate_device/rtc_register_device to register the rtc as late as possible.
--- drivers/rtc/rtc-cmos.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-)
drivers/rtc/rtc-cmos.c +8 -4
@@ -751,8 +751,7 @@ cmos_do_probe(struct device *dev, struct resource *ports, int rtc_irq) cmos_rtc.dev = dev;dev_set_drvdata (dev, &cmos_rtc); - cmos_rtc.rtc =rtc_device_register (driver_name, dev, - &cmos_rtc_ops,THIS_MODULE ); + cmos_rtc.rtc =devm_rtc_allocate_device (dev);if (IS_ERR (cmos_rtc.rtc)) { retval =PTR_ERR (cmos_rtc.rtc); goto cleanup0;
@@ -822,6 +821,11 @@ cmos_do_probe(struct device *dev, struct resource *ports, int rtc_irq) goto cleanup2; } + cmos_rtc.rtc->ops = &cmos_rtc_ops; + retval =rtc_register_device (cmos_rtc.rtc); +if (retval) + goto cleanup3; +dev_info (dev,"%s%s, %zd bytes nvram%s\n" , !is_valid_irq (rtc_irq) ?"no alarms" : cmos_rtc.mon_alrm ? "alarms up to one year" :
@@ -833,12 +837,13 @@ cmos_do_probe(struct device *dev, struct resource *ports, int rtc_irq)return 0 ; +cleanup3: +sysfs_remove_bin_file (&dev->kobj, &nvram); cleanup2:if (is_valid_irq (rtc_irq))free_irq (rtc_irq, cmos_rtc.rtc); cleanup1: cmos_rtc.dev =NULL ; -rtc_device_unregister (cmos_rtc.rtc); cleanup0:if (RTC_IOMAPPED )release_region (ports->start,resource_size (ports));
@@ -869,7 +874,6 @@ static void cmos_do_remove(struct device *dev)hpet_unregister_irq_handler (cmos_interrupt); } -rtc_device_unregister (cmos->rtc); cmos->rtc =NULL ; ports = cmos->iomem;
Signature · 1 line
2.16.1
Alexandre Belloni
maintainerPATCH 32/45 rtc: cmos: use generic nvmem
In reply to Alexandre BelloniInstead of adding a binary sysfs attribute from the driver, use the core to register an nvmem device. This allows to use the in-kernel interface to access the nvram.
--- drivers/rtc/rtc-cmos.c | 73 +++++++++++++++++++++----------------------------- 1 file changed, 30 insertions(+), 43 deletions(-)
drivers/rtc/rtc-cmos.c +30 -43
@@ -541,11 +541,10 @@ static const struct rtc_class_ops cmos_rtc_ops = {#define NVRAM_OFFSET (RTC_REG_D + 1) -static ssize_t -cmos_nvram_read (struct file *filp,struct kobject *kobj, -struct bin_attribute *attr, -char *buf,loff_t off,size_t count) +static int cmos_nvram_read (void *priv,unsigned int off,void *val, +size_t count) { +unsigned char *buf = val;int retval; off +=NVRAM_OFFSET ;
@@ -563,16 +562,13 @@ cmos_nvram_read(struct file *filp, struct kobject *kobj,return retval; } -static ssize_t -cmos_nvram_write (struct file *filp,struct kobject *kobj, -struct bin_attribute *attr, -char *buf,loff_t off,size_t count) +static int cmos_nvram_write (void *priv,unsigned int off,void *val, +size_t count) { -struct cmos_rtc *cmos; +struct cmos_rtc *cmos = priv; +unsigned char *buf = val;int retval; - cmos = dev_get_drvdata(container_of(kobj, struct device, kobj)); -/* NOTE: on at least PCs and Ataris, the boot firmware uses a * checksum on part of the NVRAM data. That's currently ignored * here. If userspace is smart enough to know what fields of
@@ -598,17 +594,6 @@ cmos_nvram_write(struct file *filp, struct kobject *kobj,return retval; } -static struct bin_attribute nvram = { - .attr = { - .name ="nvram" , - .mode =S_IRUGO |S_IWUSR , - }, - - .read = cmos_nvram_read, - .write = cmos_nvram_write, -/* size gets set up later */ -}; -/*----------------------------------------------------------------*/ static struct cmos_rtc cmos_rtc;
@@ -675,6 +660,14 @@ cmos_do_probe(struct device *dev, struct resource *ports, int rtc_irq)unsigned char rtc_control;unsigned address_space;u32 flags =0 ; +struct nvmem_config nvmem_cfg = { + .name ="cmos_nvram" , + .word_size =1 , + .stride =1 , + .reg_read = cmos_nvram_read, + .reg_write = cmos_nvram_write, + .priv = &cmos_rtc, + };/* there can be only one ... */ if (cmos_rtc.dev)
@@ -813,32 +806,28 @@ cmos_do_probe(struct device *dev, struct resource *ports, int rtc_irq) } } -/* export at least the first block of NVRAM */ - nvram.size = address_space -NVRAM_OFFSET ; - retval =sysfs_create_bin_file (&dev->kobj, &nvram); -if (retval <0 ) { -dev_dbg (dev,"can't create nvram file? %d\n" , retval); - goto cleanup2; - } - cmos_rtc.rtc->ops = &cmos_rtc_ops; + cmos_rtc.rtc->nvram_old_abi = true; retval =rtc_register_device (cmos_rtc.rtc);if (retval) - goto cleanup3; + goto cleanup2; -dev_info (dev,"%s%s, %zd bytes nvram%s\n" , - !is_valid_irq (rtc_irq) ?"no alarms" : - cmos_rtc.mon_alrm ?"alarms up to one year" : - cmos_rtc.day_alrm ?"alarms up to one month" : -"alarms up to one day" , - cmos_rtc.century ?", y3k" :"" , - nvram.size, -is_hpet_enabled () ?", hpet irqs" :"" ); +/* export at least the first block of NVRAM */ + nvmem_cfg.size = address_space -NVRAM_OFFSET ; +if (rtc_nvmem_register (cmos_rtc.rtc, &nvmem_cfg)) +dev_err (dev,"nvmem registration failed\n" ); + +dev_info (dev,"%s%s, %d bytes nvram%s\n" , + !is_valid_irq (rtc_irq) ?"no alarms" : + cmos_rtc.mon_alrm ?"alarms up to one year" : + cmos_rtc.day_alrm ?"alarms up to one month" : +"alarms up to one day" , + cmos_rtc.century ?", y3k" :"" , + nvmem_cfg.size, +is_hpet_enabled () ?", hpet irqs" :"" );return 0 ; -cleanup3: -sysfs_remove_bin_file (&dev->kobj, &nvram); cleanup2:if (is_valid_irq (rtc_irq))free_irq (rtc_irq, cmos_rtc.rtc);
@@ -867,8 +856,6 @@ static void cmos_do_remove(struct device *dev)cmos_do_shutdown (cmos->irq); -sysfs_remove_bin_file (&dev->kobj, &nvram); -if (is_valid_irq (cmos->irq)) {free_irq (cmos->irq, cmos->rtc);hpet_unregister_irq_handler (cmos_interrupt);
Signature · 1 line
2.16.1
Alexandre Belloni
maintainerPATCH 33/45 rtc: ds1742: switch to rtc_register_device
In reply to Alexandre BelloniThis allows for future improvement of the driver.
--- drivers/rtc/rtc-ds1742.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-)
drivers/rtc/rtc-ds1742.c +8 -2
@@ -196,11 +196,17 @@ static int ds1742_rtc_probe(struct platform_device *pdev) pdata->last_jiffies = jiffies;platform_set_drvdata (pdev, pdata); - rtc =devm_rtc_device_register (&pdev->dev, pdev->name, - &ds1742_rtc_ops,THIS_MODULE ); + + rtc =devm_rtc_allocate_device (&pdev->dev);if (IS_ERR (rtc))return PTR_ERR (rtc); + rtc->ops = &ds1742_rtc_ops; + + ret =rtc_register_device (rtc); +if (ret) +return ret; + ret =sysfs_create_bin_file (&pdev->dev.kobj, &pdata->nvram_attr);if (ret) dev_err(&pdev->dev, "Unable to create sysfs entry: %s\n",
Signature · 1 line
2.16.1
Alexandre Belloni
maintainerPATCH 34/45 rtc: ds1742: use generic nvmem
In reply to Alexandre BelloniInstead of adding a binary sysfs attribute from the driver (which suffers from a race condition as the attribute appears after the device), use the core to register an nvmem device.
--- drivers/rtc/rtc-ds1742.c | 67 +++++++++++++++++++----------------------------- 1 file changed, 26 insertions(+), 41 deletions(-)
drivers/rtc/rtc-ds1742.c +26 -41
@@ -53,9 +53,7 @@struct rtc_plat_data {void __iomem *ioaddr_nvram;void __iomem *ioaddr_rtc; -size_t size_nvram;unsigned long last_jiffies; -struct bin_attribute nvram_attr; };static int ds1742_rtc_set_time (struct device *dev,struct rtc_time *tm)
@@ -122,34 +120,28 @@ static const struct rtc_class_ops ds1742_rtc_ops = { .set_time = ds1742_rtc_set_time, }; -static ssize_t ds1742_nvram_read (struct file *filp,struct kobject *kobj, -struct bin_attribute *bin_attr, -char *buf,loff_t pos,size_t size) +static int ds1742_nvram_read (void *priv,unsigned int pos,void *val, +size_t bytes) { - struct device *dev = container_of(kobj, struct device, kobj); -struct platform_device *pdev =to_platform_device (dev); -struct rtc_plat_data *pdata =platform_get_drvdata (pdev); +struct rtc_plat_data *pdata = priv;void __iomem *ioaddr = pdata->ioaddr_nvram; -ssize_t count; +u8 *buf = val; -for (count =0 ; count < size; count++) +for (; bytes; bytes--) *buf++ =readb (ioaddr + pos++); -return count; +return 0 ; } -static ssize_t ds1742_nvram_write (struct file *filp,struct kobject *kobj, -struct bin_attribute *bin_attr, -char *buf,loff_t pos,size_t size) +static int ds1742_nvram_write (void *priv,unsigned int pos,void *val, +size_t bytes) { - struct device *dev = container_of(kobj, struct device, kobj); -struct platform_device *pdev =to_platform_device (dev); -struct rtc_plat_data *pdata =platform_get_drvdata (pdev); +struct rtc_plat_data *pdata = priv;void __iomem *ioaddr = pdata->ioaddr_nvram; -ssize_t count; +u8 *buf = val; -for (count =0 ; count < size; count++) +for (; bytes; bytes--)writeb (*buf++, ioaddr + pos++); -return count; +return 0 ; }static int ds1742_rtc_probe (struct platform_device *pdev)
@@ -160,6 +152,14 @@ static int ds1742_rtc_probe(struct platform_device *pdev)struct rtc_plat_data *pdata;void __iomem *ioaddr;int ret =0 ; +struct nvmem_config nvmem_cfg = { + .name ="ds1742_nvram" , + .word_size =1 , + .stride =1 , + .reg_read = ds1742_nvram_read, + .reg_write = ds1742_nvram_write, + }; + pdata =devm_kzalloc (&pdev->dev,sizeof (*pdata),GFP_KERNEL );if (!pdata)
@@ -171,15 +171,10 @@ static int ds1742_rtc_probe(struct platform_device *pdev)return PTR_ERR (ioaddr); pdata->ioaddr_nvram = ioaddr; - pdata->size_nvram =resource_size (res) -RTC_SIZE ; - pdata->ioaddr_rtc = ioaddr + pdata->size_nvram; + pdata->ioaddr_rtc = ioaddr +resource_size (res) -RTC_SIZE ; -sysfs_bin_attr_init (&pdata->nvram_attr); - pdata->nvram_attr.attr.name ="nvram" ; - pdata->nvram_attr.attr.mode =S_IRUGO |S_IWUSR ; - pdata->nvram_attr.read = ds1742_nvram_read; - pdata->nvram_attr.write = ds1742_nvram_write; - pdata->nvram_attr.size = pdata->size_nvram; + nvmem_cfg.size =resource_size (res) -RTC_SIZE ; + nvmem_cfg.priv = pdata;/* turn RTC on if it was not on */ ioaddr = pdata->ioaddr_rtc;
@@ -202,24 +197,15 @@ static int ds1742_rtc_probe(struct platform_device *pdev)return PTR_ERR (rtc); rtc->ops = &ds1742_rtc_ops; + rtc->nvram_old_abi = true; ret =rtc_register_device (rtc);if (ret)return ret; - ret =sysfs_create_bin_file (&pdev->dev.kobj, &pdata->nvram_attr); -if (ret) -dev_err (&pdev->dev,"Unable to create sysfs entry: %s\n" , - pdata->nvram_attr.attr.name); - -return 0 ; -} - -static int ds1742_rtc_remove (struct platform_device *pdev) -{ -struct rtc_plat_data *pdata =platform_get_drvdata (pdev); +if (rtc_nvmem_register (rtc, &nvmem_cfg)) +dev_err (&pdev->dev,"Unable to register nvmem\n" ); -sysfs_remove_bin_file (&pdev->dev.kobj, &pdata->nvram_attr);return 0 ; }
@@ -231,7 +217,6 @@ MODULE_DEVICE_TABLE(of, ds1742_rtc_of_match);static struct platform_driver ds1742_rtc_driver = { .probe = ds1742_rtc_probe, - .remove = ds1742_rtc_remove, .driver = { .name ="rtc-ds1742" , .of_match_table =of_match_ptr (ds1742_rtc_of_match),
Signature · 1 line
2.16.1
Alexandre Belloni
maintainerPATCH 35/45 rtc: rp5c01: fix possible race condition
In reply to Alexandre BelloniThe probe function is not allowed to fail after registering the RTC because the following may happen:
CPU0: CPU1:sys_load_module()
do_init_module()
do_one_initcall()
cmos_do_probe()
rtc_device_register()
__register_chrdev()
cdev->owner = struct module*
open("/dev/rtc0")
rtc_device_unregister()
module_put()
free_module()
module_free(mod->module_core)
/* struct module *module is now
freed */
chrdev_open()
spin_lock(cdev_lock)
cdev_get()
try_module_get()
module_is_live()
/* dereferences already
freed struct module* */Switch to devm_rtc_allocate_device/rtc_register_device to register the rtc as late as possible.
--- drivers/rtc/rtc-rp5c01.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-)
drivers/rtc/rtc-rp5c01.c +10 -2
@@ -249,16 +249,24 @@ static int __init rp5c01_rtc_probe(struct platform_device *dev)platform_set_drvdata (dev, priv); - rtc =devm_rtc_device_register (&dev->dev,"rtc-rp5c01" , &rp5c01_rtc_ops, -THIS_MODULE ); + rtc =devm_rtc_allocate_device (&dev->dev);if (IS_ERR (rtc))return PTR_ERR (rtc); + + rtc->ops = &rp5c01_rtc_ops; + priv->rtc = rtc; error =sysfs_create_bin_file (&dev->dev.kobj, &priv->nvram_attr);if (error)return error; + error =rtc_register_device (rtc); +if (error) { +sysfs_remove_bin_file (&dev->dev.kobj, &priv->nvram_attr); +return error; + } +return 0 ; }
Signature · 1 line
2.16.1
Alexandre Belloni
maintainerPATCH 36/45 rtc: rp5c01: use generic nvmem
In reply to Alexandre BelloniInstead of adding a binary sysfs attribute from the driver, use the core to register an nvmem device.
--- drivers/rtc/rtc-rp5c01.c | 63 ++++++++++++++++++------------------------------ 1 file changed, 24 insertions(+), 39 deletions(-)
drivers/rtc/rtc-rp5c01.c +24 -39
@@ -64,7 +64,6 @@ struct rp5c01_priv {u32 __iomem *regs;struct rtc_device *rtc;spinlock_t lock;/* against concurrent RTC/NVRAM access */ -struct bin_attribute nvram_attr; }; static inline unsigned int rp5c01_read(struct rp5c01_priv *priv,
@@ -160,17 +159,15 @@ static const struct rtc_class_ops rp5c01_rtc_ops = {* byte is stored in BLOCK10, the low nibble in BLOCK11. */ -static ssize_t rp5c01_nvram_read (struct file *filp,struct kobject *kobj, -struct bin_attribute *bin_attr, -char *buf,loff_t pos,size_t size) +static int rp5c01_nvram_read (void *_priv,unsigned int pos,void *val, +size_t bytes) { - struct device *dev = container_of(kobj, struct device, kobj); -struct rp5c01_priv *priv =dev_get_drvdata (dev); -ssize_t count; +struct rp5c01_priv *priv = _priv; +u8 *buf = val;spin_lock_irq (&priv->lock); -for (count =0 ; count < size; count++) { +for (; bytes; bytes--) {u8 data; rp5c01_write(priv,
@@ -187,20 +184,18 @@ static ssize_t rp5c01_nvram_read(struct file *filp, struct kobject *kobj, }spin_unlock_irq (&priv->lock); -return count; +return 0 ; } -static ssize_t rp5c01_nvram_write (struct file *filp,struct kobject *kobj, -struct bin_attribute *bin_attr, -char *buf,loff_t pos,size_t size) +static int rp5c01_nvram_write (void *_priv,unsigned int pos,void *val, +size_t bytes) { - struct device *dev = container_of(kobj, struct device, kobj); -struct rp5c01_priv *priv =dev_get_drvdata (dev); -ssize_t count; +struct rp5c01_priv *priv = _priv; +u8 *buf = val;spin_lock_irq (&priv->lock); -for (count =0 ; count < size; count++) { +for (; bytes; bytes--) {u8 data = *buf++; rp5c01_write(priv,
@@ -216,7 +211,7 @@ static ssize_t rp5c01_nvram_write(struct file *filp, struct kobject *kobj, }spin_unlock_irq (&priv->lock); -return count; +return 0 ; }static int __init rp5c01_rtc_probe (struct platform_device *dev)
@@ -225,6 +220,14 @@ static int __init rp5c01_rtc_probe(struct platform_device *dev)struct rp5c01_priv *priv;struct rtc_device *rtc;int error; +struct nvmem_config nvmem_cfg = { + .name ="rp5c01_nvram" , + .word_size =1 , + .stride =1 , + .size =RP5C01_MODE , + .reg_read = rp5c01_nvram_read, + .reg_write = rp5c01_nvram_write, + }; res =platform_get_resource (dev,IORESOURCE_MEM ,0 );if (!res)
@@ -238,13 +241,6 @@ static int __init rp5c01_rtc_probe(struct platform_device *dev)if (!priv->regs)return -ENOMEM ; -sysfs_bin_attr_init (&priv->nvram_attr); - priv->nvram_attr.attr.name ="nvram" ; - priv->nvram_attr.attr.mode =S_IRUGO |S_IWUSR ; - priv->nvram_attr.read = rp5c01_nvram_read; - priv->nvram_attr.write = rp5c01_nvram_write; - priv->nvram_attr.size =RP5C01_MODE ; -spin_lock_init (&priv->lock);platform_set_drvdata (dev, priv);
@@ -254,27 +250,17 @@ static int __init rp5c01_rtc_probe(struct platform_device *dev)return PTR_ERR (rtc); rtc->ops = &rp5c01_rtc_ops; + rtc->nvram_old_abi = true; priv->rtc = rtc; - error =sysfs_create_bin_file (&dev->dev.kobj, &priv->nvram_attr); -if (error) -return error; - error =rtc_register_device (rtc); -if (error) { -sysfs_remove_bin_file (&dev->dev.kobj, &priv->nvram_attr); +if (error)return error; - } -return 0 ; -} - -static int __exit rp5c01_rtc_remove(struct platform_device *dev) -{ -struct rp5c01_priv *priv =platform_get_drvdata (dev); + nvmem_cfg.priv = priv; +rtc_nvmem_register (rtc, &nvmem_cfg); -sysfs_remove_bin_file (&dev->dev.kobj, &priv->nvram_attr);return 0 ; }
@@ -282,7 +268,6 @@ static struct platform_driver rp5c01_rtc_driver = { .driver = { .name = "rtc-rp5c01", }, - .remove = __exit_p(rp5c01_rtc_remove), };module_platform_driver_probe (rp5c01_rtc_driver, rp5c01_rtc_probe);
Signature · 1 line
2.16.1
Alexandre Belloni
maintainerPATCH 37/45 rtc: stk17ta8: make alarms useful
In reply to Alexandre BelloniCurrently, the IRQs are disabled when the rtc driver is removed (e.g. when shutting down the platform).
This means that the RTC will be unable to wakeup the platform.
--- drivers/rtc/rtc-stk17ta8.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-)
drivers/rtc/rtc-stk17ta8.c +1 -4
@@ -340,11 +340,8 @@ static int stk17ta8_rtc_probe(struct platform_device *pdev)static int stk17ta8_rtc_remove (struct platform_device *pdev) { -struct rtc_plat_data *pdata =platform_get_drvdata (pdev); -sysfs_remove_bin_file (&pdev->dev.kobj, &stk17ta8_nvram_attr); -if (pdata->irq >0 ) -writeb (0 , pdata->ioaddr +RTC_INTERRUPTS ); +return 0 ; }
Signature · 1 line
2.16.1
Alexandre Belloni
maintainerPATCH 38/45 rtc: stk17ta8: switch to rtc_register_device
In reply to Alexandre BelloniThis allows for future improvement of the driver.
--- drivers/rtc/rtc-stk17ta8.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-)
drivers/rtc/rtc-stk17ta8.c +7 -2
@@ -328,11 +328,16 @@ static int stk17ta8_rtc_probe(struct platform_device *pdev) } } - pdata->rtc =devm_rtc_device_register (&pdev->dev, pdev->name, - &stk17ta8_rtc_ops,THIS_MODULE ); + pdata->rtc =devm_rtc_allocate_device (&pdev->dev);if (IS_ERR (pdata->rtc))return PTR_ERR (pdata->rtc); + pdata->rtc->ops = &stk17ta8_rtc_ops; + + ret =rtc_register_device (pdata->rtc); +if (ret) +return ret; + ret =sysfs_create_bin_file (&pdev->dev.kobj, &stk17ta8_nvram_attr);return ret;
Signature · 1 line
2.16.1
Alexandre Belloni
maintainerPATCH 39/45 rtc: stk17ta8: fix possible race condition
In reply to Alexandre BelloniThe probe function is not allowed to fail after registering the RTC. Call rtc_register_device() at the end.
--- drivers/rtc/rtc-stk17ta8.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/rtc/rtc-stk17ta8.c +2 -2
@@ -334,11 +334,11 @@ static int stk17ta8_rtc_probe(struct platform_device *pdev) pdata->rtc->ops = &stk17ta8_rtc_ops; - ret =rtc_register_device (pdata->rtc); + ret =sysfs_create_bin_file (&pdev->dev.kobj, &stk17ta8_nvram_attr);if (ret)return ret; - ret =sysfs_create_bin_file (&pdev->dev.kobj, &stk17ta8_nvram_attr); + ret =rtc_register_device (pdata->rtc);return ret; }
Signature · 1 line
2.16.1
Alexandre Belloni
maintainerPATCH 40/45 rtc: stk17ta8: use generic nvmem
In reply to Alexandre BelloniInstead of adding a binary sysfs attribute from the driver, use the core to register an nvmem device.
--- drivers/rtc/rtc-stk17ta8.c | 62 ++++++++++++++++++---------------------------- 1 file changed, 24 insertions(+), 38 deletions(-)
drivers/rtc/rtc-stk17ta8.c +24 -38
@@ -242,46 +242,30 @@ static const struct rtc_class_ops stk17ta8_rtc_ops = { .alarm_irq_enable = stk17ta8_rtc_alarm_irq_enable, }; -static ssize_t stk17ta8_nvram_read (struct file *filp,struct kobject *kobj, -struct bin_attribute *attr,char *buf, -loff_t pos,size_t size) +static int stk17ta8_nvram_read (void *priv,unsigned int pos,void *val, +size_t bytes) { - struct device *dev = container_of(kobj, struct device, kobj); -struct platform_device *pdev =to_platform_device (dev); -struct rtc_plat_data *pdata =platform_get_drvdata (pdev); +struct rtc_plat_data *pdata = priv;void __iomem *ioaddr = pdata->ioaddr; -ssize_t count; +u8 *buf = val; -for (count =0 ; count < size; count++) +for (; bytes; bytes--) *buf++ =readb (ioaddr + pos++); -return count; +return 0 ; } -static ssize_t stk17ta8_nvram_write (struct file *filp,struct kobject *kobj, -struct bin_attribute *attr,char *buf, -loff_t pos,size_t size) +static int stk17ta8_nvram_write (void *priv,unsigned int pos,void *val, +size_t bytes) { - struct device *dev = container_of(kobj, struct device, kobj); -struct platform_device *pdev =to_platform_device (dev); -struct rtc_plat_data *pdata =platform_get_drvdata (pdev); +struct rtc_plat_data *pdata = priv;void __iomem *ioaddr = pdata->ioaddr; -ssize_t count; +u8 *buf = val; -for (count =0 ; count < size; count++) +for (; bytes; bytes--)writeb (*buf++, ioaddr + pos++); -return count; +return 0 ; } -static struct bin_attribute stk17ta8_nvram_attr = { - .attr = { - .name ="nvram" , - .mode =S_IRUGO |S_IWUSR , - }, - .size =RTC_OFFSET , - .read = stk17ta8_nvram_read, - .write = stk17ta8_nvram_write, -}; -static int stk17ta8_rtc_probe (struct platform_device *pdev) {struct resource *res;
@@ -290,6 +274,14 @@ static int stk17ta8_rtc_probe(struct platform_device *pdev)struct rtc_plat_data *pdata;void __iomem *ioaddr;int ret =0 ; +struct nvmem_config nvmem_cfg = { + .name ="stk17ta8_nvram" , + .word_size =1 , + .stride =1 , + .size =RTC_OFFSET , + .reg_read = stk17ta8_nvram_read, + .reg_write = stk17ta8_nvram_write, + }; pdata =devm_kzalloc (&pdev->dev,sizeof (*pdata),GFP_KERNEL );if (!pdata)
@@ -333,29 +325,23 @@ static int stk17ta8_rtc_probe(struct platform_device *pdev)return PTR_ERR (pdata->rtc); pdata->rtc->ops = &stk17ta8_rtc_ops; + pdata->rtc->nvram_old_abi = true; - ret =sysfs_create_bin_file (&pdev->dev.kobj, &stk17ta8_nvram_attr); + ret =rtc_register_device (pdata->rtc);if (ret)return ret; - ret =rtc_register_device (pdata->rtc); + nvmem_cfg.priv = pdata; +rtc_nvmem_register (pdata->rtc, &nvmem_cfg);return ret; } -static int stk17ta8_rtc_remove (struct platform_device *pdev) -{ -sysfs_remove_bin_file (&pdev->dev.kobj, &stk17ta8_nvram_attr); - -return 0 ; -} -/* work with hotplug and coldplug */ MODULE_ALIAS ("platform:stk17ta8" );static struct platform_driver stk17ta8_rtc_driver = { .probe = stk17ta8_rtc_probe, - .remove = stk17ta8_rtc_remove, .driver = { .name ="stk17ta8" , },
Signature · 1 line
2.16.1
Alexandre Belloni
maintainerPATCH 41/45 rtc: tx4939: remove arch/mips dependency
In reply to Alexandre BelloniCopy RTC definitions from arch/mips/include/asm/txx9/tx4939.h to the RTC driver so it doesn't depend on arch/mips anymore.
--- drivers/rtc/rtc-tx4939.c | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-)
drivers/rtc/rtc-tx4939.c +24 -1
@@ -14,7 +14,30 @@#include <linux/module.h> #include <linux/io.h> #include <linux/gfp.h> -#include <asm/txx9/tx4939.h> + +#define TX4939_RTCCTL_ALME 0x00000080 +#define TX4939_RTCCTL_ALMD 0x00000040 +#define TX4939_RTCCTL_BUSY 0x00000020 + +#define TX4939_RTCCTL_COMMAND 0x00000007 +#define TX4939_RTCCTL_COMMAND_NOP 0x00000000 +#define TX4939_RTCCTL_COMMAND_GETTIME 0x00000001 +#define TX4939_RTCCTL_COMMAND_SETTIME 0x00000002 +#define TX4939_RTCCTL_COMMAND_GETALARM 0x00000003 +#define TX4939_RTCCTL_COMMAND_SETALARM 0x00000004 + +#define TX4939_RTCTBC_PM 0x00000080 +#define TX4939_RTCTBC_COMP 0x0000007f + +#define TX4939_RTC_REG_RAMSIZE 0x00000100 +#define TX4939_RTC_REG_RWBSIZE 0x00000006 + +struct tx4939_rtc_reg { +__u32 ctl; +__u32 adr; +__u32 dat; +__u32 tbc; +};struct tx4939rtc_plat_data {struct rtc_device *rtc;
Signature · 1 line
2.16.1
Alexandre Belloni
maintainerPATCH 42/45 rtc: tx4939: extend test coverage
In reply to Alexandre BelloniThe rtc-tx4939 driver now compiles correctly on other architectures, add COMPILE_TEST to improve code coverage.
--- drivers/rtc/Kconfig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/rtc/Kconfig +1 -1
@@ -1512,7 +1512,7 @@ config RTC_DRV_STARFIRE config RTC_DRV_TX4939 tristate "TX4939 SoC" - depends on SOC_TX4939 + depends on SOC_TX4939 || COMPILE_TEST help Driver for the internal RTC (Realtime Clock) module found on Toshiba TX4939 SoC.
Signature · 1 line
2.16.1
Alexandre Belloni
maintainerPATCH 43/45 rtc: tx4939: switch to rtc_register_device
In reply to Alexandre BelloniThis allows for future improvement of the driver.
--- drivers/rtc/rtc-tx4939.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-)
drivers/rtc/rtc-tx4939.c +8 -2
@@ -283,10 +283,16 @@ static int __init tx4939_rtc_probe(struct platform_device *pdev)if (devm_request_irq (&pdev->dev, irq, tx4939_rtc_interrupt,0 , pdev->name, &pdev->dev) <0 )return -EBUSY ; - rtc =devm_rtc_device_register (&pdev->dev, pdev->name, - &tx4939_rtc_ops,THIS_MODULE ); + rtc =devm_rtc_allocate_device (&pdev->dev);if (IS_ERR (rtc))return PTR_ERR (rtc); + + rtc->ops = &tx4939_rtc_ops; + + ret =rtc_register_device (rtc); +if (ret) +return ret; + pdata->rtc = rtc; ret =sysfs_create_bin_file (&pdev->dev.kobj, &tx4939_rtc_nvram_attr);
Signature · 1 line
2.16.1
Alexandre Belloni
maintainerPATCH 44/45 rtc: tx4939: fix possible race condition
In reply to Alexandre BelloniThe probe function is not allowed to fail after registering the RTC. Call rtc_register_device() at the end.
--- drivers/rtc/rtc-tx4939.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/rtc/rtc-tx4939.c +3 -2
@@ -289,12 +289,13 @@ static int __init tx4939_rtc_probe(struct platform_device *pdev) rtc->ops = &tx4939_rtc_ops; - ret =rtc_register_device (rtc); + ret =sysfs_create_bin_file (&pdev->dev.kobj, &tx4939_rtc_nvram_attr);if (ret)return ret; pdata->rtc = rtc; - ret =sysfs_create_bin_file (&pdev->dev.kobj, &tx4939_rtc_nvram_attr); + + ret =rtc_register_device (rtc);return ret; }
Signature · 1 line
2.16.1
Alexandre Belloni
maintainerPATCH 45/45 rtc: tx4939: use generic nvmem
In reply to Alexandre BelloniInstead of adding a binary sysfs attribute from the driver, use the core to register an nvmem device.
--- drivers/rtc/rtc-tx4939.c | 57 ++++++++++++++++++++++-------------------------- 1 file changed, 26 insertions(+), 31 deletions(-)
drivers/rtc/rtc-tx4939.c +26 -31
@@ -212,58 +212,52 @@ static const struct rtc_class_ops tx4939_rtc_ops = { .alarm_irq_enable = tx4939_rtc_alarm_irq_enable, }; -static ssize_t tx4939_rtc_nvram_read (struct file *filp,struct kobject *kobj, -struct bin_attribute *bin_attr, -char *buf,loff_t pos,size_t size) +static int tx4939_nvram_read (void *priv,unsigned int pos,void *val, +size_t bytes) { - struct device *dev = container_of(kobj, struct device, kobj); -struct tx4939rtc_plat_data *pdata =get_tx4939rtc_plat_data (dev); +struct tx4939rtc_plat_data *pdata = priv;struct tx4939_rtc_reg __iomem *rtcreg = pdata->rtcreg; -ssize_t count; +u8 *buf = val;spin_lock_irq (&pdata->lock); -for (count =0 ; count < size; count++) { +for (; bytes; bytes--) {__raw_writel (pos++, &rtcreg->adr); *buf++ =__raw_readl (&rtcreg->dat); }spin_unlock_irq (&pdata->lock); -return count; +return 0 ; } -static ssize_t tx4939_rtc_nvram_write (struct file *filp,struct kobject *kobj, -struct bin_attribute *bin_attr, -char *buf,loff_t pos,size_t size) +static int tx4939_nvram_write (void *priv,unsigned int pos,void *val, +size_t bytes) { - struct device *dev = container_of(kobj, struct device, kobj); -struct tx4939rtc_plat_data *pdata =get_tx4939rtc_plat_data (dev); +struct tx4939rtc_plat_data *pdata = priv;struct tx4939_rtc_reg __iomem *rtcreg = pdata->rtcreg; -ssize_t count; +u8 *buf = val;spin_lock_irq (&pdata->lock); -for (count =0 ; count < size; count++) { +for (; bytes; bytes--) {__raw_writel (pos++, &rtcreg->adr);__raw_writel (*buf++, &rtcreg->dat); }spin_unlock_irq (&pdata->lock); -return count; +return 0 ; } -static struct bin_attribute tx4939_rtc_nvram_attr = { - .attr = { - .name ="nvram" , - .mode =S_IRUGO |S_IWUSR , - }, - .size =TX4939_RTC_REG_RAMSIZE , - .read = tx4939_rtc_nvram_read, - .write = tx4939_rtc_nvram_write, -}; -static int __init tx4939_rtc_probe (struct platform_device *pdev) {struct rtc_device *rtc;struct tx4939rtc_plat_data *pdata;struct resource *res;int irq, ret; +struct nvmem_config nvmem_cfg = { + .name ="rv8803_nvram" , + .word_size =4 , + .stride =4 , + .size =TX4939_RTC_REG_RAMSIZE , + .reg_read = tx4939_nvram_read, + .reg_write = tx4939_nvram_write, + }; irq =platform_get_irq (pdev,0 );if (irq <0 )
@@ -288,14 +282,16 @@ static int __init tx4939_rtc_probe(struct platform_device *pdev)return PTR_ERR (rtc); rtc->ops = &tx4939_rtc_ops; - - ret =sysfs_create_bin_file (&pdev->dev.kobj, &tx4939_rtc_nvram_attr); -if (ret) -return ret; + rtc->nvram_old_abi = true; pdata->rtc = rtc; ret =rtc_register_device (rtc); +if (ret) +return ret; + + nvmem_cfg.priv = pdata; + ret =rtc_nvmem_register (rtc, &nvmem_cfg);return ret; }
@@ -304,7 +300,6 @@ static int __exit tx4939_rtc_remove(struct platform_device *pdev) {struct tx4939rtc_plat_data *pdata =platform_get_drvdata (pdev); -sysfs_remove_bin_file (&pdev->dev.kobj, &tx4939_rtc_nvram_attr);spin_lock_irq (&pdata->lock);tx4939_rtc_cmd (pdata->rtcreg,TX4939_RTCCTL_COMMAND_NOP );spin_unlock_irq (&pdata->lock);
Signature · 1 line
2.16.1