diff options
author | Linus Torvalds <torvalds@linux-foundation.org> | 2018-04-10 10:22:27 -0700 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2018-04-10 10:22:27 -0700 |
commit | fbe173e3ffbd897b5a859020d714c0eaf4af2a1a (patch) | |
tree | 602fd9da34454d934fcee56b8a74ebed05ba7d1c /drivers/rtc/rtc-ds1343.c | |
parent | 5e630afdcb82779f5bf03fd4a5e86adc56fe7c8a (diff) | |
parent | 1485991c024603b2fb4ae77beb7a0d741128a48e (diff) | |
download | op-kernel-dev-fbe173e3ffbd897b5a859020d714c0eaf4af2a1a.zip op-kernel-dev-fbe173e3ffbd897b5a859020d714c0eaf4af2a1a.tar.gz |
Merge tag 'rtc-4.17' of git://git.kernel.org/pub/scm/linux/kernel/git/abelloni/linux
Pull RTC updates from Alexandre Belloni:
"This contains a few series that have been in preparation for a while
and that will help systems with RTCs that will fail in 2038, 2069 or
2100.
Subsystem:
- Add tracepoints
- Rework of the RTC/nvmem API to allow drivers to discard struct
nvmem_config after registration
- New range API, drivers can now expose the useful range of the RTC
- New offset API the core is now able to add an offset to the RTC
time, modifying the supported range.
- Multiple rtc_time64_to_tm fixes
- Handle time_t overflow on 32 bit platforms in the core instead of
letting drivers do crazy things.
- remove rtc_control API
New driver:
- Intersil ISL12026
Drivers:
- Drivers exposing the RTC non volatile memory have been converted to
use nvmem
- Removed useless time and date validation
- Removed an indirection pattern that was a cargo cult from ancient
drivers
- Removed VLA usage
- Fixed a possible race condition in probe functions
- AB8540 support is dropped from ab8500
- pcf85363 now has alarm support"
* tag 'rtc-4.17' of git://git.kernel.org/pub/scm/linux/kernel/git/abelloni/linux: (128 commits)
rtc: snvs: Fix usage of snvs_rtc_enable
rtc: mt7622: fix module autoloading for OF platform drivers
rtc: isl12022: use true and false for boolean values
rtc: ab8500: Drop AB8540 support
rtc: remove a warning during scripts/kernel-doc step
rtc: 88pm860x: remove artificial limitation
rtc: 88pm80x: remove artificial limitation
rtc: st-lpc: remove artificial limitation
rtc: mrst: remove artificial limitation
rtc: mv: remove artificial limitation
rtc: hctosys: Ensure system time doesn't overflow time_t
parisc: time: stop validating rtc_time in .read_time
rtc: pcf85063: fix clearing bits in pcf85063_start_clock
rtc: at91sam9: Set name of regmap_config
rtc: s5m: Remove VLA usage
rtc: s5m: Move enum from rtc.h to rtc-s5m.c
rtc: remove VLA usage
rtc: Add useful timestamp definitions
rtc: Add one offset seconds to expand RTC range
rtc: Factor out the RTC range validation into rtc_valid_range()
...
Diffstat (limited to 'drivers/rtc/rtc-ds1343.c')
-rw-r--r-- | drivers/rtc/rtc-ds1343.c | 185 |
1 files changed, 32 insertions, 153 deletions
diff --git a/drivers/rtc/rtc-ds1343.c b/drivers/rtc/rtc-ds1343.c index 895fbee..5208da4 100644 --- a/drivers/rtc/rtc-ds1343.c +++ b/drivers/rtc/rtc-ds1343.c @@ -153,120 +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; - - ret = regmap_bulk_write(priv->map, address, buf, count); - if (ret < 0) - dev_err(&priv->spi->dev, "Error in nvram write %d", ret); + struct ds1343_priv *ds1343 = priv; - 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); + struct ds1343_priv *ds1343 = priv; - address = DS1343_NVRAM + off; - - 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_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 +215,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); @@ -321,33 +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) - 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; + return 0; - device_remove_file(dev, &dev_attr_alarm_mode); - -error3: - device_remove_bin_file(dev, &nvram_attr); - -error2: - device_remove_file(dev, &dev_attr_trickle_charger); - -error1: device_remove_file(dev, &dev_attr_glitch_filter); return err; @@ -355,17 +232,8 @@ error1: 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) @@ -386,7 +254,7 @@ static int ds1343_read_time(struct device *dev, struct rtc_time *dt) dt->tm_mon = bcd2bin(buf[5] & 0x1F) - 1; dt->tm_year = bcd2bin(buf[6]) + 100; /* year offset from 1900 */ - return rtc_valid_tm(dt); + return 0; } static int ds1343_set_time(struct device *dev, struct rtc_time *dt) @@ -599,14 +467,18 @@ 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; + 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) @@ -646,12 +518,19 @@ 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->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; |