diff options
Diffstat (limited to 'drivers/rtc/rtc-ds1343.c')
| -rw-r--r-- | drivers/rtc/rtc-ds1343.c | 75 |
1 files changed, 73 insertions, 2 deletions
diff --git a/drivers/rtc/rtc-ds1343.c b/drivers/rtc/rtc-ds1343.c index c3719189dd96..ae9f997223b1 100644 --- a/drivers/rtc/rtc-ds1343.c +++ b/drivers/rtc/rtc-ds1343.c | |||
| @@ -4,6 +4,7 @@ | |||
| 4 | * Real Time Clock | 4 | * Real Time Clock |
| 5 | * | 5 | * |
| 6 | * Author : Raghavendra Chandra Ganiga <ravi23ganiga@gmail.com> | 6 | * Author : Raghavendra Chandra Ganiga <ravi23ganiga@gmail.com> |
| 7 | * Ankur Srivastava <sankurece@gmail.com> : DS1343 Nvram Support | ||
| 7 | * | 8 | * |
| 8 | * This program is free software; you can redistribute it and/or modify | 9 | * This program is free software; you can redistribute it and/or modify |
| 9 | * it under the terms of the GNU General Public License version 2 as | 10 | * it under the terms of the GNU General Public License version 2 as |
| @@ -45,6 +46,9 @@ | |||
| 45 | #define DS1343_CONTROL_REG 0x0F | 46 | #define DS1343_CONTROL_REG 0x0F |
| 46 | #define DS1343_STATUS_REG 0x10 | 47 | #define DS1343_STATUS_REG 0x10 |
| 47 | #define DS1343_TRICKLE_REG 0x11 | 48 | #define DS1343_TRICKLE_REG 0x11 |
| 49 | #define DS1343_NVRAM 0x20 | ||
| 50 | |||
| 51 | #define DS1343_NVRAM_LEN 96 | ||
| 48 | 52 | ||
| 49 | /* DS1343 Control Registers bits */ | 53 | /* DS1343 Control Registers bits */ |
| 50 | #define DS1343_EOSC 0x80 | 54 | #define DS1343_EOSC 0x80 |
| @@ -149,6 +153,64 @@ static ssize_t ds1343_store_glitchfilter(struct device *dev, | |||
| 149 | static DEVICE_ATTR(glitch_filter, S_IRUGO | S_IWUSR, ds1343_show_glitchfilter, | 153 | static DEVICE_ATTR(glitch_filter, S_IRUGO | S_IWUSR, ds1343_show_glitchfilter, |
| 150 | ds1343_store_glitchfilter); | 154 | ds1343_store_glitchfilter); |
| 151 | 155 | ||
| 156 | static ssize_t ds1343_nvram_write(struct file *filp, struct kobject *kobj, | ||
| 157 | struct bin_attribute *attr, | ||
| 158 | char *buf, loff_t off, size_t count) | ||
| 159 | { | ||
| 160 | int ret; | ||
| 161 | unsigned char address; | ||
| 162 | struct device *dev = kobj_to_dev(kobj); | ||
| 163 | struct ds1343_priv *priv = dev_get_drvdata(dev); | ||
| 164 | |||
| 165 | if (unlikely(!count)) | ||
| 166 | return count; | ||
| 167 | |||
| 168 | if ((count + off) > DS1343_NVRAM_LEN) | ||
| 169 | count = DS1343_NVRAM_LEN - off; | ||
| 170 | |||
| 171 | address = DS1343_NVRAM + off; | ||
| 172 | |||
| 173 | ret = regmap_bulk_write(priv->map, address, buf, count); | ||
| 174 | if (ret < 0) | ||
| 175 | dev_err(&priv->spi->dev, "Error in nvram write %d", ret); | ||
| 176 | |||
| 177 | return (ret < 0) ? ret : count; | ||
| 178 | } | ||
| 179 | |||
| 180 | |||
| 181 | static ssize_t ds1343_nvram_read(struct file *filp, struct kobject *kobj, | ||
| 182 | struct bin_attribute *attr, | ||
| 183 | char *buf, loff_t off, size_t count) | ||
| 184 | { | ||
| 185 | int ret; | ||
| 186 | unsigned char address; | ||
| 187 | struct device *dev = kobj_to_dev(kobj); | ||
| 188 | struct ds1343_priv *priv = dev_get_drvdata(dev); | ||
| 189 | |||
| 190 | if (unlikely(!count)) | ||
| 191 | return count; | ||
| 192 | |||
| 193 | if ((count + off) > DS1343_NVRAM_LEN) | ||
| 194 | count = DS1343_NVRAM_LEN - off; | ||
| 195 | |||
| 196 | address = DS1343_NVRAM + off; | ||
| 197 | |||
| 198 | ret = regmap_bulk_read(priv->map, address, buf, count); | ||
| 199 | if (ret < 0) | ||
| 200 | dev_err(&priv->spi->dev, "Error in nvram read %d\n", ret); | ||
| 201 | |||
| 202 | return (ret < 0) ? ret : count; | ||
| 203 | } | ||
| 204 | |||
| 205 | |||
| 206 | static struct bin_attribute nvram_attr = { | ||
| 207 | .attr.name = "nvram", | ||
| 208 | .attr.mode = S_IRUGO | S_IWUSR, | ||
| 209 | .read = ds1343_nvram_read, | ||
| 210 | .write = ds1343_nvram_write, | ||
| 211 | .size = DS1343_NVRAM_LEN, | ||
| 212 | }; | ||
| 213 | |||
| 152 | static ssize_t ds1343_show_alarmstatus(struct device *dev, | 214 | static ssize_t ds1343_show_alarmstatus(struct device *dev, |
| 153 | struct device_attribute *attr, char *buf) | 215 | struct device_attribute *attr, char *buf) |
| 154 | { | 216 | { |
| @@ -274,12 +336,16 @@ static int ds1343_sysfs_register(struct device *dev) | |||
| 274 | if (err) | 336 | if (err) |
| 275 | goto error1; | 337 | goto error1; |
| 276 | 338 | ||
| 339 | err = device_create_bin_file(dev, &nvram_attr); | ||
| 340 | if (err) | ||
| 341 | goto error2; | ||
| 342 | |||
| 277 | if (priv->irq <= 0) | 343 | if (priv->irq <= 0) |
| 278 | return err; | 344 | return err; |
| 279 | 345 | ||
| 280 | err = device_create_file(dev, &dev_attr_alarm_mode); | 346 | err = device_create_file(dev, &dev_attr_alarm_mode); |
| 281 | if (err) | 347 | if (err) |
| 282 | goto error2; | 348 | goto error3; |
| 283 | 349 | ||
| 284 | err = device_create_file(dev, &dev_attr_alarm_status); | 350 | err = device_create_file(dev, &dev_attr_alarm_status); |
| 285 | if (!err) | 351 | if (!err) |
| @@ -287,6 +353,9 @@ static int ds1343_sysfs_register(struct device *dev) | |||
| 287 | 353 | ||
| 288 | device_remove_file(dev, &dev_attr_alarm_mode); | 354 | device_remove_file(dev, &dev_attr_alarm_mode); |
| 289 | 355 | ||
| 356 | error3: | ||
| 357 | device_remove_bin_file(dev, &nvram_attr); | ||
| 358 | |||
| 290 | error2: | 359 | error2: |
| 291 | device_remove_file(dev, &dev_attr_trickle_charger); | 360 | device_remove_file(dev, &dev_attr_trickle_charger); |
| 292 | 361 | ||
| @@ -302,6 +371,7 @@ static void ds1343_sysfs_unregister(struct device *dev) | |||
| 302 | 371 | ||
| 303 | device_remove_file(dev, &dev_attr_glitch_filter); | 372 | device_remove_file(dev, &dev_attr_glitch_filter); |
| 304 | device_remove_file(dev, &dev_attr_trickle_charger); | 373 | device_remove_file(dev, &dev_attr_trickle_charger); |
| 374 | device_remove_bin_file(dev, &nvram_attr); | ||
| 305 | 375 | ||
| 306 | if (priv->irq <= 0) | 376 | if (priv->irq <= 0) |
| 307 | return; | 377 | return; |
| @@ -684,6 +754,7 @@ static struct spi_driver ds1343_driver = { | |||
| 684 | module_spi_driver(ds1343_driver); | 754 | module_spi_driver(ds1343_driver); |
| 685 | 755 | ||
| 686 | MODULE_DESCRIPTION("DS1343 RTC SPI Driver"); | 756 | MODULE_DESCRIPTION("DS1343 RTC SPI Driver"); |
| 687 | MODULE_AUTHOR("Raghavendra Chandra Ganiga <ravi23ganiga@gmail.com>"); | 757 | MODULE_AUTHOR("Raghavendra Chandra Ganiga <ravi23ganiga@gmail.com>," |
| 758 | "Ankur Srivastava <sankurece@gmail.com>"); | ||
| 688 | MODULE_LICENSE("GPL v2"); | 759 | MODULE_LICENSE("GPL v2"); |
| 689 | MODULE_VERSION(DS1343_DRV_VERSION); | 760 | MODULE_VERSION(DS1343_DRV_VERSION); |
