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

Merge tag 'rtc-4.6-2' of git://git.kernel.org/pub/scm/linux/kernel/git/abelloni/linux

Pull more RTC updates from Alexandre Belloni:
"A second pull request for v4.6 with a few fixesi before -rc1. The new
features for abx80x actually make the RTC behave correctly.

Drivers:
- abx80x: handle both XT and RC oscillators, XT failure bit and
autocalibration
- m41t80: avoid out of range year values
- rv8803: workaround an i2c HW issue"

* tag 'rtc-4.6-2' of git://git.kernel.org/pub/scm/linux/kernel/git/abelloni/linux:
rtc: abx80x: handle the oscillator failure bit
rtc: abx80x: handle autocalibration
rtc: rv8803: workaround i2c HW issue
rtc: mcp795: add devicetree support
rtc: asm9260: remove incorrect __init/__exit annotations
rtc: m41t80: avoid out of range year values
rtc: s3c: Don't print an error on probe deferral
rtc: rv3029: stop mentioning rv3029c2

+316 -16
+11
Documentation/devicetree/bindings/rtc/maxim,mcp795.txt
··· 1 + * Maxim MCP795 SPI Serial Real-Time Clock 2 + 3 + Required properties: 4 + - compatible: Should contain "maxim,mcp795". 5 + - reg: SPI address for chip 6 + 7 + Example: 8 + mcp795: rtc@0 { 9 + compatible = "maxim,mcp795"; 10 + reg = <0>; 11 + };
+1 -1
drivers/rtc/Kconfig
··· 589 589 default y 590 590 help 591 591 Say Y here if you want to expose temperature sensor data on 592 - rtc-rv3029c2. 592 + rtc-rv3029. 593 593 594 594 config RTC_DRV_RV8803 595 595 tristate "Micro Crystal RV8803"
+250 -2
drivers/rtc/rtc-abx80x.c
··· 49 49 50 50 #define ABX8XX_REG_CD_TIMER_CTL 0x18 51 51 52 + #define ABX8XX_REG_OSC 0x1c 53 + #define ABX8XX_OSC_FOS BIT(3) 54 + #define ABX8XX_OSC_BOS BIT(4) 55 + #define ABX8XX_OSC_ACAL_512 BIT(5) 56 + #define ABX8XX_OSC_ACAL_1024 BIT(6) 57 + 58 + #define ABX8XX_OSC_OSEL BIT(7) 59 + 60 + #define ABX8XX_REG_OSS 0x1d 61 + #define ABX8XX_OSS_OF BIT(1) 62 + #define ABX8XX_OSS_OMODE BIT(4) 63 + 52 64 #define ABX8XX_REG_CFG_KEY 0x1f 65 + #define ABX8XX_CFG_KEY_OSC 0xa1 53 66 #define ABX8XX_CFG_KEY_MISC 0x9d 54 67 55 68 #define ABX8XX_REG_ID0 0x28 ··· 93 80 [AB1805] = {.pn = 0x1805, .has_tc = true}, 94 81 [ABX80X] = {.pn = 0} 95 82 }; 83 + 84 + static int abx80x_is_rc_mode(struct i2c_client *client) 85 + { 86 + int flags = 0; 87 + 88 + flags = i2c_smbus_read_byte_data(client, ABX8XX_REG_OSS); 89 + if (flags < 0) { 90 + dev_err(&client->dev, 91 + "Failed to read autocalibration attribute\n"); 92 + return flags; 93 + } 94 + 95 + return (flags & ABX8XX_OSS_OMODE) ? 1 : 0; 96 + } 96 97 97 98 static int abx80x_enable_trickle_charger(struct i2c_client *client, 98 99 u8 trickle_cfg) ··· 139 112 { 140 113 struct i2c_client *client = to_i2c_client(dev); 141 114 unsigned char buf[8]; 142 - int err; 115 + int err, flags, rc_mode = 0; 116 + 117 + /* Read the Oscillator Failure only in XT mode */ 118 + rc_mode = abx80x_is_rc_mode(client); 119 + if (rc_mode < 0) 120 + return rc_mode; 121 + 122 + if (!rc_mode) { 123 + flags = i2c_smbus_read_byte_data(client, ABX8XX_REG_OSS); 124 + if (flags < 0) 125 + return flags; 126 + 127 + if (flags & ABX8XX_OSS_OF) { 128 + dev_err(dev, "Oscillator failure, data is invalid.\n"); 129 + return -EINVAL; 130 + } 131 + } 143 132 144 133 err = i2c_smbus_read_i2c_block_data(client, ABX8XX_REG_HTH, 145 134 sizeof(buf), buf); ··· 183 140 { 184 141 struct i2c_client *client = to_i2c_client(dev); 185 142 unsigned char buf[8]; 186 - int err; 143 + int err, flags; 187 144 188 145 if (tm->tm_year < 100) 189 146 return -EINVAL; ··· 202 159 if (err < 0) { 203 160 dev_err(&client->dev, "Unable to write to date registers\n"); 204 161 return -EIO; 162 + } 163 + 164 + /* Clear the OF bit of Oscillator Status Register */ 165 + flags = i2c_smbus_read_byte_data(client, ABX8XX_REG_OSS); 166 + if (flags < 0) 167 + return flags; 168 + 169 + err = i2c_smbus_write_byte_data(client, ABX8XX_REG_OSS, 170 + flags & ~ABX8XX_OSS_OF); 171 + if (err < 0) { 172 + dev_err(&client->dev, "Unable to write oscillator status register\n"); 173 + return err; 205 174 } 206 175 207 176 return 0; ··· 303 248 return 0; 304 249 } 305 250 251 + static int abx80x_rtc_set_autocalibration(struct device *dev, 252 + int autocalibration) 253 + { 254 + struct i2c_client *client = to_i2c_client(dev); 255 + int retval, flags = 0; 256 + 257 + if ((autocalibration != 0) && (autocalibration != 1024) && 258 + (autocalibration != 512)) { 259 + dev_err(dev, "autocalibration value outside permitted range\n"); 260 + return -EINVAL; 261 + } 262 + 263 + flags = i2c_smbus_read_byte_data(client, ABX8XX_REG_OSC); 264 + if (flags < 0) 265 + return flags; 266 + 267 + if (autocalibration == 0) { 268 + flags &= ~(ABX8XX_OSC_ACAL_512 | ABX8XX_OSC_ACAL_1024); 269 + } else if (autocalibration == 1024) { 270 + /* 1024 autocalibration is 0x10 */ 271 + flags |= ABX8XX_OSC_ACAL_1024; 272 + flags &= ~(ABX8XX_OSC_ACAL_512); 273 + } else { 274 + /* 512 autocalibration is 0x11 */ 275 + flags |= (ABX8XX_OSC_ACAL_1024 | ABX8XX_OSC_ACAL_512); 276 + } 277 + 278 + /* Unlock write access to Oscillator Control Register */ 279 + retval = i2c_smbus_write_byte_data(client, ABX8XX_REG_CFG_KEY, 280 + ABX8XX_CFG_KEY_OSC); 281 + if (retval < 0) { 282 + dev_err(dev, "Failed to write CONFIG_KEY register\n"); 283 + return retval; 284 + } 285 + 286 + retval = i2c_smbus_write_byte_data(client, ABX8XX_REG_OSC, flags); 287 + 288 + return retval; 289 + } 290 + 291 + static int abx80x_rtc_get_autocalibration(struct device *dev) 292 + { 293 + struct i2c_client *client = to_i2c_client(dev); 294 + int flags = 0, autocalibration; 295 + 296 + flags = i2c_smbus_read_byte_data(client, ABX8XX_REG_OSC); 297 + if (flags < 0) 298 + return flags; 299 + 300 + if (flags & ABX8XX_OSC_ACAL_512) 301 + autocalibration = 512; 302 + else if (flags & ABX8XX_OSC_ACAL_1024) 303 + autocalibration = 1024; 304 + else 305 + autocalibration = 0; 306 + 307 + return autocalibration; 308 + } 309 + 310 + static ssize_t autocalibration_store(struct device *dev, 311 + struct device_attribute *attr, 312 + const char *buf, size_t count) 313 + { 314 + int retval; 315 + unsigned long autocalibration = 0; 316 + 317 + retval = kstrtoul(buf, 10, &autocalibration); 318 + if (retval < 0) { 319 + dev_err(dev, "Failed to store RTC autocalibration attribute\n"); 320 + return -EINVAL; 321 + } 322 + 323 + retval = abx80x_rtc_set_autocalibration(dev, autocalibration); 324 + 325 + return retval ? retval : count; 326 + } 327 + 328 + static ssize_t autocalibration_show(struct device *dev, 329 + struct device_attribute *attr, char *buf) 330 + { 331 + int autocalibration = 0; 332 + 333 + autocalibration = abx80x_rtc_get_autocalibration(dev); 334 + if (autocalibration < 0) { 335 + dev_err(dev, "Failed to read RTC autocalibration\n"); 336 + sprintf(buf, "0\n"); 337 + return autocalibration; 338 + } 339 + 340 + return sprintf(buf, "%d\n", autocalibration); 341 + } 342 + 343 + static DEVICE_ATTR_RW(autocalibration); 344 + 345 + static ssize_t oscillator_store(struct device *dev, 346 + struct device_attribute *attr, 347 + const char *buf, size_t count) 348 + { 349 + struct i2c_client *client = to_i2c_client(dev); 350 + int retval, flags, rc_mode = 0; 351 + 352 + if (strncmp(buf, "rc", 2) == 0) { 353 + rc_mode = 1; 354 + } else if (strncmp(buf, "xtal", 4) == 0) { 355 + rc_mode = 0; 356 + } else { 357 + dev_err(dev, "Oscillator selection value outside permitted ones\n"); 358 + return -EINVAL; 359 + } 360 + 361 + flags = i2c_smbus_read_byte_data(client, ABX8XX_REG_OSC); 362 + if (flags < 0) 363 + return flags; 364 + 365 + if (rc_mode == 0) 366 + flags &= ~(ABX8XX_OSC_OSEL); 367 + else 368 + flags |= (ABX8XX_OSC_OSEL); 369 + 370 + /* Unlock write access on Oscillator Control register */ 371 + retval = i2c_smbus_write_byte_data(client, ABX8XX_REG_CFG_KEY, 372 + ABX8XX_CFG_KEY_OSC); 373 + if (retval < 0) { 374 + dev_err(dev, "Failed to write CONFIG_KEY register\n"); 375 + return retval; 376 + } 377 + 378 + retval = i2c_smbus_write_byte_data(client, ABX8XX_REG_OSC, flags); 379 + if (retval < 0) { 380 + dev_err(dev, "Failed to write Oscillator Control register\n"); 381 + return retval; 382 + } 383 + 384 + return retval ? retval : count; 385 + } 386 + 387 + static ssize_t oscillator_show(struct device *dev, 388 + struct device_attribute *attr, char *buf) 389 + { 390 + int rc_mode = 0; 391 + struct i2c_client *client = to_i2c_client(dev); 392 + 393 + rc_mode = abx80x_is_rc_mode(client); 394 + 395 + if (rc_mode < 0) { 396 + dev_err(dev, "Failed to read RTC oscillator selection\n"); 397 + sprintf(buf, "\n"); 398 + return rc_mode; 399 + } 400 + 401 + if (rc_mode) 402 + return sprintf(buf, "rc\n"); 403 + else 404 + return sprintf(buf, "xtal\n"); 405 + } 406 + 407 + static DEVICE_ATTR_RW(oscillator); 408 + 409 + static struct attribute *rtc_calib_attrs[] = { 410 + &dev_attr_autocalibration.attr, 411 + &dev_attr_oscillator.attr, 412 + NULL, 413 + }; 414 + 415 + static const struct attribute_group rtc_calib_attr_group = { 416 + .attrs = rtc_calib_attrs, 417 + }; 418 + 306 419 static int abx80x_alarm_irq_enable(struct device *dev, unsigned int enabled) 307 420 { 308 421 struct i2c_client *client = to_i2c_client(dev); ··· 524 301 return -EINVAL; 525 302 526 303 return (trickle_cfg | i); 304 + } 305 + 306 + static void rtc_calib_remove_sysfs_group(void *_dev) 307 + { 308 + struct device *dev = _dev; 309 + 310 + sysfs_remove_group(&dev->kobj, &rtc_calib_attr_group); 527 311 } 528 312 529 313 static int abx80x_probe(struct i2c_client *client, ··· 633 403 dev_err(&client->dev, "unable to request IRQ, alarms disabled\n"); 634 404 client->irq = 0; 635 405 } 406 + } 407 + 408 + /* Export sysfs entries */ 409 + err = sysfs_create_group(&(&client->dev)->kobj, &rtc_calib_attr_group); 410 + if (err) { 411 + dev_err(&client->dev, "Failed to create sysfs group: %d\n", 412 + err); 413 + return err; 414 + } 415 + 416 + err = devm_add_action(&client->dev, rtc_calib_remove_sysfs_group, 417 + &client->dev); 418 + if (err) { 419 + rtc_calib_remove_sysfs_group(&client->dev); 420 + dev_err(&client->dev, 421 + "Failed to add sysfs cleanup action: %d\n", 422 + err); 423 + return err; 636 424 } 637 425 638 426 return 0;
+2 -2
drivers/rtc/rtc-asm9260.c
··· 255 255 .alarm_irq_enable = asm9260_alarm_irq_enable, 256 256 }; 257 257 258 - static int __init asm9260_rtc_probe(struct platform_device *pdev) 258 + static int asm9260_rtc_probe(struct platform_device *pdev) 259 259 { 260 260 struct asm9260_rtc_priv *priv; 261 261 struct device *dev = &pdev->dev; ··· 323 323 return ret; 324 324 } 325 325 326 - static int __exit asm9260_rtc_remove(struct platform_device *pdev) 326 + static int asm9260_rtc_remove(struct platform_device *pdev) 327 327 { 328 328 struct asm9260_rtc_priv *priv = platform_get_drvdata(pdev); 329 329
+6
drivers/rtc/rtc-m41t80.c
··· 176 176 bin2bcd(tm->tm_mday) | (buf[M41T80_REG_DAY] & ~0x3f); 177 177 buf[M41T80_REG_MON] = 178 178 bin2bcd(tm->tm_mon + 1) | (buf[M41T80_REG_MON] & ~0x1f); 179 + 179 180 /* assume 20YY not 19YY */ 181 + if (tm->tm_year < 100 || tm->tm_year > 199) { 182 + dev_err(&client->dev, "Year must be between 2000 and 2099. It's %d.\n", 183 + tm->tm_year + 1900); 184 + return -EINVAL; 185 + } 180 186 buf[M41T80_REG_YEAR] = bin2bcd(tm->tm_year % 100); 181 187 182 188 if (i2c_transfer(client->adapter, msgs, 1) != 1) {
+10
drivers/rtc/rtc-mcp795.c
··· 20 20 #include <linux/printk.h> 21 21 #include <linux/spi/spi.h> 22 22 #include <linux/rtc.h> 23 + #include <linux/of.h> 23 24 24 25 /* MCP795 Instructions, see datasheet table 3-1 */ 25 26 #define MCP795_EEREAD 0x03 ··· 184 183 return 0; 185 184 } 186 185 186 + #ifdef CONFIG_OF 187 + static const struct of_device_id mcp795_of_match[] = { 188 + { .compatible = "maxim,mcp795" }, 189 + { } 190 + }; 191 + MODULE_DEVICE_TABLE(of, mcp795_of_match); 192 + #endif 193 + 187 194 static struct spi_driver mcp795_driver = { 188 195 .driver = { 189 196 .name = "rtc-mcp795", 197 + .of_match_table = of_match_ptr(mcp795_of_match), 190 198 }, 191 199 .probe = mcp795_probe, 192 200 };
+22 -6
drivers/rtc/rtc-rv8803.c
··· 61 61 struct i2c_client *client = dev_id; 62 62 struct rv8803_data *rv8803 = i2c_get_clientdata(client); 63 63 unsigned long events = 0; 64 - int flags; 64 + int flags, try = 0; 65 65 66 66 mutex_lock(&rv8803->flags_lock); 67 67 68 - flags = i2c_smbus_read_byte_data(client, RV8803_FLAG); 68 + do { 69 + flags = i2c_smbus_read_byte_data(client, RV8803_FLAG); 70 + try++; 71 + } while ((flags == -ENXIO) && (try < 3)); 69 72 if (flags <= 0) { 70 73 mutex_unlock(&rv8803->flags_lock); 71 74 return IRQ_NONE; ··· 427 424 { 428 425 struct i2c_adapter *adapter = to_i2c_adapter(client->dev.parent); 429 426 struct rv8803_data *rv8803; 430 - int err, flags; 427 + int err, flags, try = 0; 431 428 432 429 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA | 433 430 I2C_FUNC_SMBUS_I2C_BLOCK)) { ··· 444 441 rv8803->client = client; 445 442 i2c_set_clientdata(client, rv8803); 446 443 447 - flags = i2c_smbus_read_byte_data(client, RV8803_FLAG); 444 + /* 445 + * There is a 60µs window where the RTC may not reply on the i2c bus in 446 + * that case, the transfer is not ACKed. In that case, ensure there are 447 + * multiple attempts. 448 + */ 449 + do { 450 + flags = i2c_smbus_read_byte_data(client, RV8803_FLAG); 451 + try++; 452 + } while ((flags == -ENXIO) && (try < 3)); 453 + 448 454 if (flags < 0) 449 455 return flags; 450 456 ··· 488 476 return PTR_ERR(rv8803->rtc); 489 477 } 490 478 491 - err = i2c_smbus_write_byte_data(rv8803->client, RV8803_EXT, 492 - RV8803_EXT_WADA); 479 + try = 0; 480 + do { 481 + err = i2c_smbus_write_byte_data(rv8803->client, RV8803_EXT, 482 + RV8803_EXT_WADA); 483 + try++; 484 + } while ((err == -ENXIO) && (try < 3)); 493 485 if (err) 494 486 return err; 495 487
+14 -5
drivers/rtc/rtc-s3c.c
··· 501 501 502 502 info->rtc_clk = devm_clk_get(&pdev->dev, "rtc"); 503 503 if (IS_ERR(info->rtc_clk)) { 504 - dev_err(&pdev->dev, "failed to find rtc clock\n"); 505 - return PTR_ERR(info->rtc_clk); 504 + ret = PTR_ERR(info->rtc_clk); 505 + if (ret != -EPROBE_DEFER) 506 + dev_err(&pdev->dev, "failed to find rtc clock\n"); 507 + else 508 + dev_dbg(&pdev->dev, "probe deferred due to missing rtc clk\n"); 509 + return ret; 506 510 } 507 511 clk_prepare_enable(info->rtc_clk); 508 512 509 513 if (info->data->needs_src_clk) { 510 514 info->rtc_src_clk = devm_clk_get(&pdev->dev, "rtc_src"); 511 515 if (IS_ERR(info->rtc_src_clk)) { 512 - dev_err(&pdev->dev, 513 - "failed to find rtc source clock\n"); 516 + ret = PTR_ERR(info->rtc_src_clk); 517 + if (ret != -EPROBE_DEFER) 518 + dev_err(&pdev->dev, 519 + "failed to find rtc source clock\n"); 520 + else 521 + dev_dbg(&pdev->dev, 522 + "probe deferred due to missing rtc src clk\n"); 514 523 clk_disable_unprepare(info->rtc_clk); 515 - return PTR_ERR(info->rtc_src_clk); 524 + return ret; 516 525 } 517 526 clk_prepare_enable(info->rtc_src_clk); 518 527 }