| .. | .. |
|---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-only |
|---|
| 1 | 2 | /* rtc-ds1343.c |
|---|
| 2 | 3 | * |
|---|
| 3 | 4 | * Driver for Dallas Semiconductor DS1343 Low Current, SPI Compatible |
|---|
| .. | .. |
|---|
| 5 | 6 | * |
|---|
| 6 | 7 | * Author : Raghavendra Chandra Ganiga <ravi23ganiga@gmail.com> |
|---|
| 7 | 8 | * Ankur Srivastava <sankurece@gmail.com> : DS1343 Nvram Support |
|---|
| 8 | | - * |
|---|
| 9 | | - * This program is free software; you can redistribute it and/or modify |
|---|
| 10 | | - * it under the terms of the GNU General Public License version 2 as |
|---|
| 11 | | - * published by the Free Software Foundation. |
|---|
| 12 | | - * |
|---|
| 13 | 9 | */ |
|---|
| 14 | 10 | |
|---|
| 15 | 11 | #include <linux/init.h> |
|---|
| .. | .. |
|---|
| 79 | 75 | MODULE_DEVICE_TABLE(spi, ds1343_id); |
|---|
| 80 | 76 | |
|---|
| 81 | 77 | struct ds1343_priv { |
|---|
| 82 | | - struct spi_device *spi; |
|---|
| 83 | 78 | struct rtc_device *rtc; |
|---|
| 84 | 79 | struct regmap *map; |
|---|
| 85 | | - struct mutex mutex; |
|---|
| 86 | | - unsigned int irqen; |
|---|
| 87 | 80 | int irq; |
|---|
| 88 | | - int alarm_sec; |
|---|
| 89 | | - int alarm_min; |
|---|
| 90 | | - int alarm_hour; |
|---|
| 91 | | - int alarm_mday; |
|---|
| 92 | 81 | }; |
|---|
| 93 | | - |
|---|
| 94 | | -static int ds1343_ioctl(struct device *dev, unsigned int cmd, unsigned long arg) |
|---|
| 95 | | -{ |
|---|
| 96 | | - switch (cmd) { |
|---|
| 97 | | -#ifdef RTC_SET_CHARGE |
|---|
| 98 | | - case RTC_SET_CHARGE: |
|---|
| 99 | | - { |
|---|
| 100 | | - int val; |
|---|
| 101 | | - |
|---|
| 102 | | - if (copy_from_user(&val, (int __user *)arg, sizeof(int))) |
|---|
| 103 | | - return -EFAULT; |
|---|
| 104 | | - |
|---|
| 105 | | - return regmap_write(priv->map, DS1343_TRICKLE_REG, val); |
|---|
| 106 | | - } |
|---|
| 107 | | - break; |
|---|
| 108 | | -#endif |
|---|
| 109 | | - } |
|---|
| 110 | | - |
|---|
| 111 | | - return -ENOIOCTLCMD; |
|---|
| 112 | | -} |
|---|
| 113 | 82 | |
|---|
| 114 | 83 | static ssize_t ds1343_show_glitchfilter(struct device *dev, |
|---|
| 115 | 84 | struct device_attribute *attr, char *buf) |
|---|
| 116 | 85 | { |
|---|
| 117 | | - struct ds1343_priv *priv = dev_get_drvdata(dev); |
|---|
| 86 | + struct ds1343_priv *priv = dev_get_drvdata(dev->parent); |
|---|
| 118 | 87 | int glitch_filt_status, data; |
|---|
| 88 | + int res; |
|---|
| 119 | 89 | |
|---|
| 120 | | - regmap_read(priv->map, DS1343_CONTROL_REG, &data); |
|---|
| 90 | + res = regmap_read(priv->map, DS1343_CONTROL_REG, &data); |
|---|
| 91 | + if (res) |
|---|
| 92 | + return res; |
|---|
| 121 | 93 | |
|---|
| 122 | 94 | glitch_filt_status = !!(data & DS1343_EGFIL); |
|---|
| 123 | 95 | |
|---|
| .. | .. |
|---|
| 131 | 103 | struct device_attribute *attr, |
|---|
| 132 | 104 | const char *buf, size_t count) |
|---|
| 133 | 105 | { |
|---|
| 134 | | - struct ds1343_priv *priv = dev_get_drvdata(dev); |
|---|
| 135 | | - int data; |
|---|
| 136 | | - |
|---|
| 137 | | - regmap_read(priv->map, DS1343_CONTROL_REG, &data); |
|---|
| 106 | + struct ds1343_priv *priv = dev_get_drvdata(dev->parent); |
|---|
| 107 | + int data = 0; |
|---|
| 108 | + int res; |
|---|
| 138 | 109 | |
|---|
| 139 | 110 | if (strncmp(buf, "enabled", 7) == 0) |
|---|
| 140 | | - data |= DS1343_EGFIL; |
|---|
| 141 | | - |
|---|
| 142 | | - else if (strncmp(buf, "disabled", 8) == 0) |
|---|
| 143 | | - data &= ~(DS1343_EGFIL); |
|---|
| 144 | | - |
|---|
| 145 | | - else |
|---|
| 111 | + data = DS1343_EGFIL; |
|---|
| 112 | + else if (strncmp(buf, "disabled", 8)) |
|---|
| 146 | 113 | return -EINVAL; |
|---|
| 147 | 114 | |
|---|
| 148 | | - regmap_write(priv->map, DS1343_CONTROL_REG, data); |
|---|
| 115 | + res = regmap_update_bits(priv->map, DS1343_CONTROL_REG, |
|---|
| 116 | + DS1343_EGFIL, data); |
|---|
| 117 | + if (res) |
|---|
| 118 | + return res; |
|---|
| 149 | 119 | |
|---|
| 150 | 120 | return count; |
|---|
| 151 | 121 | } |
|---|
| .. | .. |
|---|
| 172 | 142 | static ssize_t ds1343_show_tricklecharger(struct device *dev, |
|---|
| 173 | 143 | struct device_attribute *attr, char *buf) |
|---|
| 174 | 144 | { |
|---|
| 175 | | - struct ds1343_priv *priv = dev_get_drvdata(dev); |
|---|
| 176 | | - int data; |
|---|
| 145 | + struct ds1343_priv *priv = dev_get_drvdata(dev->parent); |
|---|
| 146 | + int res, data; |
|---|
| 177 | 147 | char *diodes = "disabled", *resistors = " "; |
|---|
| 178 | 148 | |
|---|
| 179 | | - regmap_read(priv->map, DS1343_TRICKLE_REG, &data); |
|---|
| 149 | + res = regmap_read(priv->map, DS1343_TRICKLE_REG, &data); |
|---|
| 150 | + if (res) |
|---|
| 151 | + return res; |
|---|
| 180 | 152 | |
|---|
| 181 | 153 | if ((data & 0xf0) == DS1343_TRICKLE_MAGIC) { |
|---|
| 182 | 154 | switch (data & 0x0c) { |
|---|
| .. | .. |
|---|
| 213 | 185 | |
|---|
| 214 | 186 | static DEVICE_ATTR(trickle_charger, S_IRUGO, ds1343_show_tricklecharger, NULL); |
|---|
| 215 | 187 | |
|---|
| 216 | | -static int ds1343_sysfs_register(struct device *dev) |
|---|
| 217 | | -{ |
|---|
| 218 | | - int err; |
|---|
| 188 | +static struct attribute *ds1343_attrs[] = { |
|---|
| 189 | + &dev_attr_glitch_filter.attr, |
|---|
| 190 | + &dev_attr_trickle_charger.attr, |
|---|
| 191 | + NULL |
|---|
| 192 | +}; |
|---|
| 219 | 193 | |
|---|
| 220 | | - err = device_create_file(dev, &dev_attr_glitch_filter); |
|---|
| 221 | | - if (err) |
|---|
| 222 | | - return err; |
|---|
| 223 | | - |
|---|
| 224 | | - err = device_create_file(dev, &dev_attr_trickle_charger); |
|---|
| 225 | | - if (!err) |
|---|
| 226 | | - return 0; |
|---|
| 227 | | - |
|---|
| 228 | | - device_remove_file(dev, &dev_attr_glitch_filter); |
|---|
| 229 | | - |
|---|
| 230 | | - return err; |
|---|
| 231 | | -} |
|---|
| 232 | | - |
|---|
| 233 | | -static void ds1343_sysfs_unregister(struct device *dev) |
|---|
| 234 | | -{ |
|---|
| 235 | | - device_remove_file(dev, &dev_attr_glitch_filter); |
|---|
| 236 | | - device_remove_file(dev, &dev_attr_trickle_charger); |
|---|
| 237 | | -} |
|---|
| 194 | +static const struct attribute_group ds1343_attr_group = { |
|---|
| 195 | + .attrs = ds1343_attrs, |
|---|
| 196 | +}; |
|---|
| 238 | 197 | |
|---|
| 239 | 198 | static int ds1343_read_time(struct device *dev, struct rtc_time *dt) |
|---|
| 240 | 199 | { |
|---|
| .. | .. |
|---|
| 260 | 219 | static int ds1343_set_time(struct device *dev, struct rtc_time *dt) |
|---|
| 261 | 220 | { |
|---|
| 262 | 221 | struct ds1343_priv *priv = dev_get_drvdata(dev); |
|---|
| 263 | | - int res; |
|---|
| 222 | + u8 buf[7]; |
|---|
| 264 | 223 | |
|---|
| 265 | | - res = regmap_write(priv->map, DS1343_SECONDS_REG, |
|---|
| 266 | | - bin2bcd(dt->tm_sec)); |
|---|
| 267 | | - if (res) |
|---|
| 268 | | - return res; |
|---|
| 224 | + buf[0] = bin2bcd(dt->tm_sec); |
|---|
| 225 | + buf[1] = bin2bcd(dt->tm_min); |
|---|
| 226 | + buf[2] = bin2bcd(dt->tm_hour) & 0x3F; |
|---|
| 227 | + buf[3] = bin2bcd(dt->tm_wday + 1); |
|---|
| 228 | + buf[4] = bin2bcd(dt->tm_mday); |
|---|
| 229 | + buf[5] = bin2bcd(dt->tm_mon + 1); |
|---|
| 230 | + buf[6] = bin2bcd(dt->tm_year - 100); |
|---|
| 269 | 231 | |
|---|
| 270 | | - res = regmap_write(priv->map, DS1343_MINUTES_REG, |
|---|
| 271 | | - bin2bcd(dt->tm_min)); |
|---|
| 272 | | - if (res) |
|---|
| 273 | | - return res; |
|---|
| 274 | | - |
|---|
| 275 | | - res = regmap_write(priv->map, DS1343_HOURS_REG, |
|---|
| 276 | | - bin2bcd(dt->tm_hour) & 0x3F); |
|---|
| 277 | | - if (res) |
|---|
| 278 | | - return res; |
|---|
| 279 | | - |
|---|
| 280 | | - res = regmap_write(priv->map, DS1343_DAY_REG, |
|---|
| 281 | | - bin2bcd(dt->tm_wday + 1)); |
|---|
| 282 | | - if (res) |
|---|
| 283 | | - return res; |
|---|
| 284 | | - |
|---|
| 285 | | - res = regmap_write(priv->map, DS1343_DATE_REG, |
|---|
| 286 | | - bin2bcd(dt->tm_mday)); |
|---|
| 287 | | - if (res) |
|---|
| 288 | | - return res; |
|---|
| 289 | | - |
|---|
| 290 | | - res = regmap_write(priv->map, DS1343_MONTH_REG, |
|---|
| 291 | | - bin2bcd(dt->tm_mon + 1)); |
|---|
| 292 | | - if (res) |
|---|
| 293 | | - return res; |
|---|
| 294 | | - |
|---|
| 295 | | - dt->tm_year %= 100; |
|---|
| 296 | | - |
|---|
| 297 | | - res = regmap_write(priv->map, DS1343_YEAR_REG, |
|---|
| 298 | | - bin2bcd(dt->tm_year)); |
|---|
| 299 | | - if (res) |
|---|
| 300 | | - return res; |
|---|
| 301 | | - |
|---|
| 302 | | - return 0; |
|---|
| 303 | | -} |
|---|
| 304 | | - |
|---|
| 305 | | -static int ds1343_update_alarm(struct device *dev) |
|---|
| 306 | | -{ |
|---|
| 307 | | - struct ds1343_priv *priv = dev_get_drvdata(dev); |
|---|
| 308 | | - unsigned int control, stat; |
|---|
| 309 | | - unsigned char buf[4]; |
|---|
| 310 | | - int res = 0; |
|---|
| 311 | | - |
|---|
| 312 | | - res = regmap_read(priv->map, DS1343_CONTROL_REG, &control); |
|---|
| 313 | | - if (res) |
|---|
| 314 | | - return res; |
|---|
| 315 | | - |
|---|
| 316 | | - res = regmap_read(priv->map, DS1343_STATUS_REG, &stat); |
|---|
| 317 | | - if (res) |
|---|
| 318 | | - return res; |
|---|
| 319 | | - |
|---|
| 320 | | - control &= ~(DS1343_A0IE); |
|---|
| 321 | | - stat &= ~(DS1343_IRQF0); |
|---|
| 322 | | - |
|---|
| 323 | | - res = regmap_write(priv->map, DS1343_CONTROL_REG, control); |
|---|
| 324 | | - if (res) |
|---|
| 325 | | - return res; |
|---|
| 326 | | - |
|---|
| 327 | | - res = regmap_write(priv->map, DS1343_STATUS_REG, stat); |
|---|
| 328 | | - if (res) |
|---|
| 329 | | - return res; |
|---|
| 330 | | - |
|---|
| 331 | | - buf[0] = priv->alarm_sec < 0 || (priv->irqen & RTC_UF) ? |
|---|
| 332 | | - 0x80 : bin2bcd(priv->alarm_sec) & 0x7F; |
|---|
| 333 | | - buf[1] = priv->alarm_min < 0 || (priv->irqen & RTC_UF) ? |
|---|
| 334 | | - 0x80 : bin2bcd(priv->alarm_min) & 0x7F; |
|---|
| 335 | | - buf[2] = priv->alarm_hour < 0 || (priv->irqen & RTC_UF) ? |
|---|
| 336 | | - 0x80 : bin2bcd(priv->alarm_hour) & 0x3F; |
|---|
| 337 | | - buf[3] = priv->alarm_mday < 0 || (priv->irqen & RTC_UF) ? |
|---|
| 338 | | - 0x80 : bin2bcd(priv->alarm_mday) & 0x7F; |
|---|
| 339 | | - |
|---|
| 340 | | - res = regmap_bulk_write(priv->map, DS1343_ALM0_SEC_REG, buf, 4); |
|---|
| 341 | | - if (res) |
|---|
| 342 | | - return res; |
|---|
| 343 | | - |
|---|
| 344 | | - if (priv->irqen) { |
|---|
| 345 | | - control |= DS1343_A0IE; |
|---|
| 346 | | - res = regmap_write(priv->map, DS1343_CONTROL_REG, control); |
|---|
| 347 | | - } |
|---|
| 348 | | - |
|---|
| 349 | | - return res; |
|---|
| 232 | + return regmap_bulk_write(priv->map, DS1343_SECONDS_REG, |
|---|
| 233 | + buf, sizeof(buf)); |
|---|
| 350 | 234 | } |
|---|
| 351 | 235 | |
|---|
| 352 | 236 | static int ds1343_read_alarm(struct device *dev, struct rtc_wkalrm *alarm) |
|---|
| 353 | 237 | { |
|---|
| 354 | 238 | struct ds1343_priv *priv = dev_get_drvdata(dev); |
|---|
| 355 | | - int res = 0; |
|---|
| 356 | | - unsigned int stat; |
|---|
| 239 | + unsigned char buf[4]; |
|---|
| 240 | + unsigned int val; |
|---|
| 241 | + int res; |
|---|
| 357 | 242 | |
|---|
| 358 | 243 | if (priv->irq <= 0) |
|---|
| 359 | 244 | return -EINVAL; |
|---|
| 360 | 245 | |
|---|
| 361 | | - mutex_lock(&priv->mutex); |
|---|
| 362 | | - |
|---|
| 363 | | - res = regmap_read(priv->map, DS1343_STATUS_REG, &stat); |
|---|
| 246 | + res = regmap_read(priv->map, DS1343_STATUS_REG, &val); |
|---|
| 364 | 247 | if (res) |
|---|
| 365 | | - goto out; |
|---|
| 248 | + return res; |
|---|
| 366 | 249 | |
|---|
| 367 | | - alarm->enabled = !!(priv->irqen & RTC_AF); |
|---|
| 368 | | - alarm->pending = !!(stat & DS1343_IRQF0); |
|---|
| 250 | + alarm->pending = !!(val & DS1343_IRQF0); |
|---|
| 369 | 251 | |
|---|
| 370 | | - alarm->time.tm_sec = priv->alarm_sec < 0 ? 0 : priv->alarm_sec; |
|---|
| 371 | | - alarm->time.tm_min = priv->alarm_min < 0 ? 0 : priv->alarm_min; |
|---|
| 372 | | - alarm->time.tm_hour = priv->alarm_hour < 0 ? 0 : priv->alarm_hour; |
|---|
| 373 | | - alarm->time.tm_mday = priv->alarm_mday < 0 ? 0 : priv->alarm_mday; |
|---|
| 252 | + res = regmap_read(priv->map, DS1343_CONTROL_REG, &val); |
|---|
| 253 | + if (res) |
|---|
| 254 | + return res; |
|---|
| 255 | + alarm->enabled = !!(val & DS1343_A0IE); |
|---|
| 374 | 256 | |
|---|
| 375 | | -out: |
|---|
| 376 | | - mutex_unlock(&priv->mutex); |
|---|
| 377 | | - return res; |
|---|
| 257 | + res = regmap_bulk_read(priv->map, DS1343_ALM0_SEC_REG, buf, 4); |
|---|
| 258 | + if (res) |
|---|
| 259 | + return res; |
|---|
| 260 | + |
|---|
| 261 | + alarm->time.tm_sec = bcd2bin(buf[0]) & 0x7f; |
|---|
| 262 | + alarm->time.tm_min = bcd2bin(buf[1]) & 0x7f; |
|---|
| 263 | + alarm->time.tm_hour = bcd2bin(buf[2]) & 0x3f; |
|---|
| 264 | + alarm->time.tm_mday = bcd2bin(buf[3]) & 0x3f; |
|---|
| 265 | + |
|---|
| 266 | + return 0; |
|---|
| 378 | 267 | } |
|---|
| 379 | 268 | |
|---|
| 380 | 269 | static int ds1343_set_alarm(struct device *dev, struct rtc_wkalrm *alarm) |
|---|
| 381 | 270 | { |
|---|
| 382 | 271 | struct ds1343_priv *priv = dev_get_drvdata(dev); |
|---|
| 272 | + unsigned char buf[4]; |
|---|
| 383 | 273 | int res = 0; |
|---|
| 384 | 274 | |
|---|
| 385 | 275 | if (priv->irq <= 0) |
|---|
| 386 | 276 | return -EINVAL; |
|---|
| 387 | 277 | |
|---|
| 388 | | - mutex_lock(&priv->mutex); |
|---|
| 278 | + res = regmap_update_bits(priv->map, DS1343_CONTROL_REG, DS1343_A0IE, 0); |
|---|
| 279 | + if (res) |
|---|
| 280 | + return res; |
|---|
| 389 | 281 | |
|---|
| 390 | | - priv->alarm_sec = alarm->time.tm_sec; |
|---|
| 391 | | - priv->alarm_min = alarm->time.tm_min; |
|---|
| 392 | | - priv->alarm_hour = alarm->time.tm_hour; |
|---|
| 393 | | - priv->alarm_mday = alarm->time.tm_mday; |
|---|
| 282 | + buf[0] = bin2bcd(alarm->time.tm_sec); |
|---|
| 283 | + buf[1] = bin2bcd(alarm->time.tm_min); |
|---|
| 284 | + buf[2] = bin2bcd(alarm->time.tm_hour); |
|---|
| 285 | + buf[3] = bin2bcd(alarm->time.tm_mday); |
|---|
| 286 | + |
|---|
| 287 | + res = regmap_bulk_write(priv->map, DS1343_ALM0_SEC_REG, buf, 4); |
|---|
| 288 | + if (res) |
|---|
| 289 | + return res; |
|---|
| 394 | 290 | |
|---|
| 395 | 291 | if (alarm->enabled) |
|---|
| 396 | | - priv->irqen |= RTC_AF; |
|---|
| 397 | | - |
|---|
| 398 | | - res = ds1343_update_alarm(dev); |
|---|
| 399 | | - |
|---|
| 400 | | - mutex_unlock(&priv->mutex); |
|---|
| 292 | + res = regmap_update_bits(priv->map, DS1343_CONTROL_REG, |
|---|
| 293 | + DS1343_A0IE, DS1343_A0IE); |
|---|
| 401 | 294 | |
|---|
| 402 | 295 | return res; |
|---|
| 403 | 296 | } |
|---|
| .. | .. |
|---|
| 405 | 298 | static int ds1343_alarm_irq_enable(struct device *dev, unsigned int enabled) |
|---|
| 406 | 299 | { |
|---|
| 407 | 300 | struct ds1343_priv *priv = dev_get_drvdata(dev); |
|---|
| 408 | | - int res = 0; |
|---|
| 409 | 301 | |
|---|
| 410 | 302 | if (priv->irq <= 0) |
|---|
| 411 | 303 | return -EINVAL; |
|---|
| 412 | 304 | |
|---|
| 413 | | - mutex_lock(&priv->mutex); |
|---|
| 414 | | - |
|---|
| 415 | | - if (enabled) |
|---|
| 416 | | - priv->irqen |= RTC_AF; |
|---|
| 417 | | - else |
|---|
| 418 | | - priv->irqen &= ~RTC_AF; |
|---|
| 419 | | - |
|---|
| 420 | | - res = ds1343_update_alarm(dev); |
|---|
| 421 | | - |
|---|
| 422 | | - mutex_unlock(&priv->mutex); |
|---|
| 423 | | - |
|---|
| 424 | | - return res; |
|---|
| 305 | + return regmap_update_bits(priv->map, DS1343_CONTROL_REG, |
|---|
| 306 | + DS1343_A0IE, enabled ? DS1343_A0IE : 0); |
|---|
| 425 | 307 | } |
|---|
| 426 | 308 | |
|---|
| 427 | 309 | static irqreturn_t ds1343_thread(int irq, void *dev_id) |
|---|
| 428 | 310 | { |
|---|
| 429 | 311 | struct ds1343_priv *priv = dev_id; |
|---|
| 430 | | - unsigned int stat, control; |
|---|
| 312 | + unsigned int stat; |
|---|
| 431 | 313 | int res = 0; |
|---|
| 432 | 314 | |
|---|
| 433 | | - mutex_lock(&priv->mutex); |
|---|
| 315 | + rtc_lock(priv->rtc); |
|---|
| 434 | 316 | |
|---|
| 435 | 317 | res = regmap_read(priv->map, DS1343_STATUS_REG, &stat); |
|---|
| 436 | 318 | if (res) |
|---|
| .. | .. |
|---|
| 440 | 322 | stat &= ~DS1343_IRQF0; |
|---|
| 441 | 323 | regmap_write(priv->map, DS1343_STATUS_REG, stat); |
|---|
| 442 | 324 | |
|---|
| 443 | | - res = regmap_read(priv->map, DS1343_CONTROL_REG, &control); |
|---|
| 444 | | - if (res) |
|---|
| 445 | | - goto out; |
|---|
| 446 | | - |
|---|
| 447 | | - control &= ~DS1343_A0IE; |
|---|
| 448 | | - regmap_write(priv->map, DS1343_CONTROL_REG, control); |
|---|
| 449 | | - |
|---|
| 450 | 325 | rtc_update_irq(priv->rtc, 1, RTC_AF | RTC_IRQF); |
|---|
| 326 | + |
|---|
| 327 | + regmap_update_bits(priv->map, DS1343_CONTROL_REG, |
|---|
| 328 | + DS1343_A0IE, 0); |
|---|
| 451 | 329 | } |
|---|
| 452 | 330 | |
|---|
| 453 | 331 | out: |
|---|
| 454 | | - mutex_unlock(&priv->mutex); |
|---|
| 332 | + rtc_unlock(priv->rtc); |
|---|
| 455 | 333 | return IRQ_HANDLED; |
|---|
| 456 | 334 | } |
|---|
| 457 | 335 | |
|---|
| 458 | 336 | static const struct rtc_class_ops ds1343_rtc_ops = { |
|---|
| 459 | | - .ioctl = ds1343_ioctl, |
|---|
| 460 | 337 | .read_time = ds1343_read_time, |
|---|
| 461 | 338 | .set_time = ds1343_set_time, |
|---|
| 462 | 339 | .read_alarm = ds1343_read_alarm, |
|---|
| .. | .. |
|---|
| 484 | 361 | if (!priv) |
|---|
| 485 | 362 | return -ENOMEM; |
|---|
| 486 | 363 | |
|---|
| 487 | | - priv->spi = spi; |
|---|
| 488 | | - mutex_init(&priv->mutex); |
|---|
| 489 | | - |
|---|
| 490 | 364 | /* RTC DS1347 works in spi mode 3 and |
|---|
| 491 | | - * its chip select is active high |
|---|
| 365 | + * its chip select is active high. Active high should be defined as |
|---|
| 366 | + * "inverse polarity" as GPIO-based chip selects can be logically |
|---|
| 367 | + * active high but inverted by the GPIO library. |
|---|
| 492 | 368 | */ |
|---|
| 493 | | - spi->mode = SPI_MODE_3 | SPI_CS_HIGH; |
|---|
| 369 | + spi->mode |= SPI_MODE_3; |
|---|
| 370 | + spi->mode ^= SPI_CS_HIGH; |
|---|
| 494 | 371 | spi->bits_per_word = 8; |
|---|
| 495 | 372 | res = spi_setup(spi); |
|---|
| 496 | 373 | if (res) |
|---|
| .. | .. |
|---|
| 524 | 401 | |
|---|
| 525 | 402 | priv->rtc->nvram_old_abi = true; |
|---|
| 526 | 403 | priv->rtc->ops = &ds1343_rtc_ops; |
|---|
| 404 | + priv->rtc->range_min = RTC_TIMESTAMP_BEGIN_2000; |
|---|
| 405 | + priv->rtc->range_max = RTC_TIMESTAMP_END_2099; |
|---|
| 406 | + |
|---|
| 407 | + res = rtc_add_group(priv->rtc, &ds1343_attr_group); |
|---|
| 408 | + if (res) |
|---|
| 409 | + dev_err(&spi->dev, |
|---|
| 410 | + "unable to create sysfs entries for rtc ds1343\n"); |
|---|
| 527 | 411 | |
|---|
| 528 | 412 | res = rtc_register_device(priv->rtc); |
|---|
| 529 | 413 | if (res) |
|---|
| .. | .. |
|---|
| 548 | 432 | } |
|---|
| 549 | 433 | } |
|---|
| 550 | 434 | |
|---|
| 551 | | - res = ds1343_sysfs_register(&spi->dev); |
|---|
| 552 | | - if (res) |
|---|
| 553 | | - dev_err(&spi->dev, |
|---|
| 554 | | - "unable to create sysfs entries for rtc ds1343\n"); |
|---|
| 555 | | - |
|---|
| 556 | 435 | return 0; |
|---|
| 557 | 436 | } |
|---|
| 558 | 437 | |
|---|
| 559 | 438 | static int ds1343_remove(struct spi_device *spi) |
|---|
| 560 | 439 | { |
|---|
| 561 | | - struct ds1343_priv *priv = spi_get_drvdata(spi); |
|---|
| 562 | | - |
|---|
| 563 | | - if (spi->irq) { |
|---|
| 564 | | - mutex_lock(&priv->mutex); |
|---|
| 565 | | - priv->irqen &= ~RTC_AF; |
|---|
| 566 | | - mutex_unlock(&priv->mutex); |
|---|
| 567 | | - |
|---|
| 568 | | - dev_pm_clear_wake_irq(&spi->dev); |
|---|
| 569 | | - device_init_wakeup(&spi->dev, false); |
|---|
| 570 | | - devm_free_irq(&spi->dev, spi->irq, priv); |
|---|
| 571 | | - } |
|---|
| 572 | | - |
|---|
| 573 | | - spi_set_drvdata(spi, NULL); |
|---|
| 574 | | - |
|---|
| 575 | | - ds1343_sysfs_unregister(&spi->dev); |
|---|
| 440 | + dev_pm_clear_wake_irq(&spi->dev); |
|---|
| 576 | 441 | |
|---|
| 577 | 442 | return 0; |
|---|
| 578 | 443 | } |
|---|