Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

drivers/rtc/rtc-ds1343.c: add support of nvram for maxim dallas rtc ds1343

This is a patch to add support of nvram for maxim dallas rtc ds1343.

Signed-off-by: Raghavendra Chandra Ganiga <ravi23ganiga@gmail.com>
Cc: Alessandro Zummo <a.zummo@towertech.it>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

authored by

Raghavendra Ganiga and committed by
Linus Torvalds
571eb883 3b97dd05

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