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

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

Pull RTC updates from Alexandre Belloni:
"Core:
- Fix rtctest error path

New drivers:
- Microcrystal RV8803

Subsystem wide cleanups:
- remove misuse of IRQF_NO_SUSPEND flag

Drivers:
- at91rm9200: clear RTC alarm status flag prior to suspending
- davinci: remove incorrect reference to probe function
- ds1307: Fix alarm programming for mcp794xx
- ds1390: trickle charger support, fix ds1390_get_reg
- isl1208: Pass the IRQF_ONESHOT flag
- opal: fix type of token
- pcf2127: fix RTC_READ_VL, remove useless driver version
- pcf85063: return an error when date is invalid
- pcf8563: add CLKOUT to common clock framework
- rx8025: remove unnecessary braces
- s3c: Set year, month, day value for setting alarm
- stmp3xxx: unify register access macros
- License fixes: pcf2127, da9063
- wakeup-source support for isl12057 and opal"

* tag 'rtc-v4.4' of git://git.kernel.org/pub/scm/linux/kernel/git/abelloni/linux: (23 commits)
rtc: Add a driver for Micro Crystal RV8803
rtc: s3c: Set year, month, day value for setting alarm
rtc: ds1307: Fix alarm programming for mcp794xx
rtc: isl12057: enable support for the standard "wakeup-source" property
rtc: opal: enable support for the stardard "wakeup-source" property
rtc: isl1208: Pass the IRQF_ONESHOT flag
rtc: pcf8563: add CLKOUT to common clock framework
rtc: davinci: remove incorrect reference to probe function
rtc: at91rm9200: clear RTC alarm status flag prior to suspending
rtc: pcf2127: remove useless driver version
rtc: pcf2127: fix reading uninitialized value on RTC_READ_VL ioctl
rtc: stmp3xxx: unify register access macros
rtc: da9063: GPL copyright inconsistency fix
rtc: pcf85063: return an error when date is invalid
rtc: rx8025: remove unnecessary braces
rtc: ds1343: remove misuse of IRQF_NO_SUSPEND flag
rtc: ab8500: remove misuse of IRQF_NO_SUSPEND flag
rtc: pl031: remove misuse of IRQF_NO_SUSPEND flag
rtc: opal: fix type of token
rtc: ds1390: Add trickle charger device tree binding
...

+908 -83
+18
Documentation/devicetree/bindings/rtc/dallas,ds1390.txt
··· 1 + * Dallas DS1390 SPI Serial Real-Time Clock 2 + 3 + Required properties: 4 + - compatible: Should contain "dallas,ds1390". 5 + - reg: SPI address for chip 6 + 7 + Optional properties: 8 + - trickle-resistor-ohms : Selected resistor for trickle charger 9 + Values usable for ds1390 are 250, 2000, 4000 10 + Should be given if trickle charger should be enabled 11 + - trickle-diode-disable : Do not use internal trickle charger diode 12 + Should be given if internal trickle charger diode should be disabled 13 + Example: 14 + ds1390: rtc@68 { 15 + compatible = "dallas,ds1390"; 16 + trickle-resistor-ohms = <250>; 17 + reg = <0>; 18 + };
+25
Documentation/devicetree/bindings/rtc/pcf8563.txt
··· 1 + * Philips PCF8563/Epson RTC8564 Real Time Clock 2 + 3 + Philips PCF8563/Epson RTC8564 Real Time Clock 4 + 5 + Required properties: 6 + see: Documentation/devicetree/bindings/i2c/trivial-devices.txt 7 + 8 + Optional property: 9 + - #clock-cells: Should be 0. 10 + - clock-output-names: 11 + overwrite the default clock name "pcf8563-clkout" 12 + 13 + Example: 14 + 15 + pcf8563: pcf8563@51 { 16 + compatible = "nxp,pcf8563"; 17 + reg = <0x51>; 18 + #clock-cells = <0>; 19 + }; 20 + 21 + device { 22 + ... 23 + clocks = <&pcf8563>; 24 + ... 25 + };
+11 -2
drivers/rtc/Kconfig
··· 593 593 This driver can also be built as a module. If so, the module 594 594 will be called rtc-rv3029c2. 595 595 596 + config RTC_DRV_RV8803 597 + tristate "Micro Crystal RV8803" 598 + help 599 + If you say yes here you get support for the Micro Crystal 600 + RV8803 RTC chips. 601 + 602 + This driver can also be built as a module. If so, the module 603 + will be called rtc-rv8803. 604 + 596 605 config RTC_DRV_S5M 597 606 tristate "Samsung S2M/S5M series" 598 607 depends on MFD_SEC_CORE ··· 675 666 If you say yes here you get support for the 676 667 Dallas/Maxim DS1390/93/94 chips. 677 668 678 - This driver only supports the RTC feature, and not other chip 679 - features such as alarms and trickle charging. 669 + This driver supports the RTC feature and trickle charging but not 670 + other chip features such as alarms. 680 671 681 672 This driver can also be built as a module. If so, the module 682 673 will be called rtc-ds1390.
+1
drivers/rtc/Makefile
··· 126 126 obj-$(CONFIG_RTC_DRV_RS5C348) += rtc-rs5c348.o 127 127 obj-$(CONFIG_RTC_DRV_RS5C372) += rtc-rs5c372.o 128 128 obj-$(CONFIG_RTC_DRV_RV3029C2) += rtc-rv3029c2.o 129 + obj-$(CONFIG_RTC_DRV_RV8803) += rtc-rv8803.o 129 130 obj-$(CONFIG_RTC_DRV_RX4581) += rtc-rx4581.o 130 131 obj-$(CONFIG_RTC_DRV_RX8025) += rtc-rx8025.o 131 132 obj-$(CONFIG_RTC_DRV_RX8581) += rtc-rx8581.o
+5 -1
drivers/rtc/rtc-ab8500.c
··· 18 18 #include <linux/mfd/abx500/ab8500.h> 19 19 #include <linux/delay.h> 20 20 #include <linux/of.h> 21 + #include <linux/pm_wakeirq.h> 21 22 22 23 #define AB8500_RTC_SOFF_STAT_REG 0x00 23 24 #define AB8500_RTC_CC_CONF_REG 0x01 ··· 494 493 } 495 494 496 495 err = devm_request_threaded_irq(&pdev->dev, irq, NULL, 497 - rtc_alarm_handler, IRQF_NO_SUSPEND | IRQF_ONESHOT, 496 + rtc_alarm_handler, IRQF_ONESHOT, 498 497 "ab8500-rtc", rtc); 499 498 if (err < 0) 500 499 return err; 501 500 501 + dev_pm_set_wake_irq(&pdev->dev, irq); 502 502 platform_set_drvdata(pdev, rtc); 503 503 504 504 err = ab8500_sysfs_rtc_register(&pdev->dev); ··· 515 513 516 514 static int ab8500_rtc_remove(struct platform_device *pdev) 517 515 { 516 + dev_pm_clear_wake_irq(&pdev->dev); 517 + device_init_wakeup(&pdev->dev, false); 518 518 ab8500_sysfs_rtc_unregister(&pdev->dev); 519 519 520 520 return 0;
+2
drivers/rtc/rtc-at91rm9200.c
··· 495 495 /* this IRQ is shared with DBGU and other hardware which isn't 496 496 * necessarily doing PM like we are... 497 497 */ 498 + at91_rtc_write(AT91_RTC_SCCR, AT91_RTC_ALARM); 499 + 498 500 at91_rtc_imr = at91_rtc_read_imr() 499 501 & (AT91_RTC_ALARM|AT91_RTC_SECEV); 500 502 if (at91_rtc_imr) {
+9 -9
drivers/rtc/rtc-da9063.c
··· 1 1 /* rtc-da9063.c - Real time clock device driver for DA9063 2 - * Copyright (C) 2013-14 Dialog Semiconductor Ltd. 2 + * Copyright (C) 2013-2015 Dialog Semiconductor Ltd. 3 3 * 4 - * This library is free software; you can redistribute it and/or 5 - * modify it under the terms of the GNU Library General Public 6 - * License as published by the Free Software Foundation; either 7 - * version 2 of the License, or (at your option) any later version. 4 + * This program is free software; you can redistribute it and/or 5 + * modify it under the terms of the GNU General Public License 6 + * as published by the Free Software Foundation; either version 2 7 + * of the License, or (at your option) any later version. 8 8 * 9 - * This library is distributed in the hope that it will be useful, 9 + * This program is distributed in the hope that it will be useful, 10 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 - * Library General Public License for more details. 11 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 + * GNU General Public License for more details. 13 13 */ 14 14 15 15 #include <linux/delay.h> ··· 516 516 517 517 MODULE_AUTHOR("S Twiss <stwiss.opensource@diasemi.com>"); 518 518 MODULE_DESCRIPTION("Real time clock device driver for Dialog DA9063"); 519 - MODULE_LICENSE("GPL v2"); 519 + MODULE_LICENSE("GPL"); 520 520 MODULE_ALIAS("platform:" DA9063_DRVNAME_RTC);
-1
drivers/rtc/rtc-davinci.c
··· 546 546 } 547 547 548 548 static struct platform_driver davinci_rtc_driver = { 549 - .probe = davinci_rtc_probe, 550 549 .remove = __exit_p(davinci_rtc_remove), 551 550 .driver = { 552 551 .name = "rtc_davinci",
+2 -2
drivers/rtc/rtc-ds1307.c
··· 718 718 regs[3] = bin2bcd(t->time.tm_sec); 719 719 regs[4] = bin2bcd(t->time.tm_min); 720 720 regs[5] = bin2bcd(t->time.tm_hour); 721 - regs[6] = bin2bcd(t->time.tm_wday) + 1; 721 + regs[6] = bin2bcd(t->time.tm_wday + 1); 722 722 regs[7] = bin2bcd(t->time.tm_mday); 723 - regs[8] = bin2bcd(t->time.tm_mon) + 1; 723 + regs[8] = bin2bcd(t->time.tm_mon + 1); 724 724 725 725 /* Clear the alarm 0 interrupt flag. */ 726 726 regs[6] &= ~MCP794XX_BIT_ALMX_IF;
+6 -3
drivers/rtc/rtc-ds1343.c
··· 21 21 #include <linux/rtc.h> 22 22 #include <linux/bcd.h> 23 23 #include <linux/pm.h> 24 + #include <linux/pm_wakeirq.h> 24 25 #include <linux/slab.h> 25 26 26 27 #define DS1343_DRV_VERSION "01.00" ··· 664 663 665 664 if (priv->irq >= 0) { 666 665 res = devm_request_threaded_irq(&spi->dev, spi->irq, NULL, 667 - ds1343_thread, 668 - IRQF_NO_SUSPEND | IRQF_ONESHOT, 666 + ds1343_thread, IRQF_ONESHOT, 669 667 "ds1343", priv); 670 668 if (res) { 671 669 priv->irq = -1; 672 670 dev_err(&spi->dev, 673 671 "unable to request irq for rtc ds1343\n"); 674 672 } else { 675 - device_set_wakeup_capable(&spi->dev, 1); 673 + device_init_wakeup(&spi->dev, true); 674 + dev_pm_set_wake_irq(&spi->dev, spi->irq); 676 675 } 677 676 } 678 677 ··· 693 692 priv->irqen &= ~RTC_AF; 694 693 mutex_unlock(&priv->mutex); 695 694 695 + dev_pm_clear_wake_irq(&spi->dev); 696 + device_init_wakeup(&spi->dev, false); 696 697 devm_free_irq(&spi->dev, spi->irq, priv); 697 698 } 698 699
+64 -1
drivers/rtc/rtc-ds1390.c
··· 20 20 #include <linux/spi/spi.h> 21 21 #include <linux/bcd.h> 22 22 #include <linux/slab.h> 23 + #include <linux/of.h> 23 24 24 25 #define DS1390_REG_100THS 0x00 25 26 #define DS1390_REG_SECONDS 0x01 ··· 41 40 #define DS1390_REG_STATUS 0x0E 42 41 #define DS1390_REG_TRICKLE 0x0F 43 42 43 + #define DS1390_TRICKLE_CHARGER_ENABLE 0xA0 44 + #define DS1390_TRICKLE_CHARGER_250_OHM 0x01 45 + #define DS1390_TRICKLE_CHARGER_2K_OHM 0x02 46 + #define DS1390_TRICKLE_CHARGER_4K_OHM 0x03 47 + #define DS1390_TRICKLE_CHARGER_NO_DIODE 0x04 48 + #define DS1390_TRICKLE_CHARGER_DIODE 0x08 49 + 44 50 struct ds1390 { 45 51 struct rtc_device *rtc; 46 52 u8 txrx_buf[9]; /* cmd + 8 registers */ 47 53 }; 54 + 55 + static void ds1390_set_reg(struct device *dev, unsigned char address, 56 + unsigned char data) 57 + { 58 + struct spi_device *spi = to_spi_device(dev); 59 + unsigned char buf[2]; 60 + 61 + /* MSB must be '1' to write */ 62 + buf[0] = address | 0x80; 63 + buf[1] = data; 64 + 65 + spi_write(spi, buf, 2); 66 + } 48 67 49 68 static int ds1390_get_reg(struct device *dev, unsigned char address, 50 69 unsigned char *data) ··· 83 62 if (status != 0) 84 63 return status; 85 64 86 - *data = chip->txrx_buf[1]; 65 + *data = chip->txrx_buf[0]; 87 66 88 67 return 0; 68 + } 69 + 70 + static void ds1390_trickle_of_init(struct spi_device *spi) 71 + { 72 + u32 ohms = 0; 73 + u8 value; 74 + 75 + if (of_property_read_u32(spi->dev.of_node, "trickle-resistor-ohms", 76 + &ohms)) 77 + goto out; 78 + 79 + /* Enable charger */ 80 + value = DS1390_TRICKLE_CHARGER_ENABLE; 81 + if (of_property_read_bool(spi->dev.of_node, "trickle-diode-disable")) 82 + value |= DS1390_TRICKLE_CHARGER_NO_DIODE; 83 + else 84 + value |= DS1390_TRICKLE_CHARGER_DIODE; 85 + 86 + /* Resistor select */ 87 + switch (ohms) { 88 + case 250: 89 + value |= DS1390_TRICKLE_CHARGER_250_OHM; 90 + break; 91 + case 2000: 92 + value |= DS1390_TRICKLE_CHARGER_2K_OHM; 93 + break; 94 + case 4000: 95 + value |= DS1390_TRICKLE_CHARGER_4K_OHM; 96 + break; 97 + default: 98 + dev_warn(&spi->dev, 99 + "Unsupported ohm value %02ux in dt\n", ohms); 100 + return; 101 + } 102 + 103 + ds1390_set_reg(&spi->dev, DS1390_REG_TRICKLE, value); 104 + 105 + out: 106 + return; 89 107 } 90 108 91 109 static int ds1390_read_time(struct device *dev, struct rtc_time *dt) ··· 202 142 dev_err(&spi->dev, "unable to read device\n"); 203 143 return res; 204 144 } 145 + 146 + if (spi->dev.of_node) 147 + ds1390_trickle_of_init(spi); 205 148 206 149 chip->rtc = devm_rtc_device_register(&spi->dev, "ds1390", 207 150 &ds1390_rtc_ops, THIS_MODULE);
+5 -5
drivers/rtc/rtc-isl12057.c
··· 466 466 * is for instance the case on ReadyNAS 102, 104 and 2120. On those 467 467 * devices with no IRQ driectly connected to the SoC, the RTC chip 468 468 * can be forced as a wakeup source by stating that explicitly in 469 - * the device's .dts file using the "isil,irq2-can-wakeup-machine" 470 - * boolean property. This will guarantee 'wakealarm' sysfs entry is 471 - * available on the device. 469 + * the device's .dts file using the "wakeup-source" boolean property. 470 + * This will guarantee 'wakealarm' sysfs entry is available on the device. 472 471 * 473 472 * The function below returns 1, i.e. the capability of the chip to 474 473 * wakeup the device, based on IRQ availability or if the boolean ··· 478 479 { 479 480 struct isl12057_rtc_data *data = dev_get_drvdata(dev); 480 481 481 - return (data->irq || of_property_read_bool(dev->of_node, 482 - "isil,irq2-can-wakeup-machine")); 482 + return data->irq || of_property_read_bool(dev->of_node, "wakeup-source") 483 + || of_property_read_bool(dev->of_node, /* legacy */ 484 + "isil,irq2-can-wakeup-machine"); 483 485 } 484 486 #else 485 487 static bool isl12057_can_wakeup_machine(struct device *dev)
+1 -1
drivers/rtc/rtc-isl1208.c
··· 638 638 if (client->irq > 0) { 639 639 rc = devm_request_threaded_irq(&client->dev, client->irq, NULL, 640 640 isl1208_rtc_interrupt, 641 - IRQF_SHARED, 641 + IRQF_SHARED | IRQF_ONESHOT, 642 642 isl1208_driver.driver.name, 643 643 client); 644 644 if (!rc) {
+5 -4
drivers/rtc/rtc-opal.c
··· 152 152 /* Set Timed Power-On */ 153 153 static int opal_set_tpo_time(struct device *dev, struct rtc_wkalrm *alarm) 154 154 { 155 - u64 h_m_s_ms = 0, token; 155 + u64 h_m_s_ms = 0; 156 156 struct opal_msg msg; 157 157 u32 y_m_d = 0; 158 - int rc; 158 + int token, rc; 159 159 160 160 tm_to_opal(&alarm->time, &y_m_d, &h_m_s_ms); 161 161 ··· 199 199 { 200 200 struct rtc_device *rtc; 201 201 202 - if (pdev->dev.of_node && of_get_property(pdev->dev.of_node, "has-tpo", 203 - NULL)) { 202 + if (pdev->dev.of_node && 203 + (of_property_read_bool(pdev->dev.of_node, "wakeup-source") || 204 + of_property_read_bool(pdev->dev.of_node, "has-tpo")/* legacy */)) { 204 205 device_set_wakeup_capable(&pdev->dev, true); 205 206 opal_rtc_ops.read_alarm = opal_get_tpo_time; 206 207 opal_rtc_ops.set_alarm = opal_set_tpo_time;
+23 -24
drivers/rtc/rtc-pcf2127.c
··· 20 20 #include <linux/module.h> 21 21 #include <linux/of.h> 22 22 23 - #define DRV_VERSION "0.0.1" 24 - 25 23 #define PCF2127_REG_CTRL1 (0x00) /* Control Register 1 */ 26 24 #define PCF2127_REG_CTRL2 (0x01) /* Control Register 2 */ 25 + 27 26 #define PCF2127_REG_CTRL3 (0x02) /* Control Register 3 */ 27 + #define PCF2127_REG_CTRL3_BLF BIT(2) 28 + 28 29 #define PCF2127_REG_SC (0x03) /* datetime */ 29 30 #define PCF2127_REG_MN (0x04) 30 31 #define PCF2127_REG_HR (0x05) ··· 40 39 41 40 struct pcf2127 { 42 41 struct rtc_device *rtc; 43 - int voltage_low; /* indicates if a low_voltage was detected */ 44 - int oscillator_failed; /* OSF was detected and date is unreliable */ 45 42 }; 46 43 47 44 /* ··· 48 49 */ 49 50 static int pcf2127_get_datetime(struct i2c_client *client, struct rtc_time *tm) 50 51 { 51 - struct pcf2127 *pcf2127 = i2c_get_clientdata(client); 52 52 unsigned char buf[10] = { PCF2127_REG_CTRL1 }; 53 53 54 54 /* read registers */ ··· 57 59 return -EIO; 58 60 } 59 61 60 - if (buf[PCF2127_REG_CTRL3] & 0x04) { 61 - pcf2127->voltage_low = 1; 62 + if (buf[PCF2127_REG_CTRL3] & PCF2127_REG_CTRL3_BLF) 62 63 dev_info(&client->dev, 63 64 "low voltage detected, check/replace RTC battery.\n"); 64 - } 65 65 66 66 if (buf[PCF2127_REG_SC] & PCF2127_OSF) { 67 67 /* 68 68 * no need clear the flag here, 69 69 * it will be cleared once the new date is saved 70 70 */ 71 - pcf2127->oscillator_failed = 1; 72 71 dev_warn(&client->dev, 73 72 "oscillator stop detected, date/time is not reliable\n"); 74 73 return -EINVAL; ··· 102 107 103 108 static int pcf2127_set_datetime(struct i2c_client *client, struct rtc_time *tm) 104 109 { 105 - struct pcf2127 *pcf2127 = i2c_get_clientdata(client); 106 110 unsigned char buf[8]; 107 111 int i = 0, err; 108 112 ··· 135 141 return -EIO; 136 142 } 137 143 138 - /* clear OSF flag in client data */ 139 - pcf2127->oscillator_failed = 0; 140 - 141 144 return 0; 142 145 } 143 146 ··· 142 151 static int pcf2127_rtc_ioctl(struct device *dev, 143 152 unsigned int cmd, unsigned long arg) 144 153 { 145 - struct pcf2127 *pcf2127 = i2c_get_clientdata(to_i2c_client(dev)); 154 + struct i2c_client *client = to_i2c_client(dev); 155 + unsigned char buf = PCF2127_REG_CTRL3; 156 + int touser; 157 + int ret; 146 158 147 159 switch (cmd) { 148 160 case RTC_VL_READ: 149 - if (pcf2127->voltage_low) 150 - dev_info(dev, "low voltage detected, check/replace battery\n"); 151 - if (pcf2127->oscillator_failed) 152 - dev_info(dev, "oscillator stop detected, date/time is not reliable\n"); 161 + ret = i2c_master_send(client, &buf, 1); 162 + if (!ret) 163 + ret = -EIO; 164 + if (ret < 0) 165 + return ret; 153 166 154 - if (copy_to_user((void __user *)arg, &pcf2127->voltage_low, 155 - sizeof(int))) 167 + ret = i2c_master_recv(client, &buf, 1); 168 + if (!ret) 169 + ret = -EIO; 170 + if (ret < 0) 171 + return ret; 172 + 173 + touser = buf & PCF2127_REG_CTRL3_BLF ? 1 : 0; 174 + 175 + if (copy_to_user((void __user *)arg, &touser, sizeof(int))) 156 176 return -EFAULT; 157 177 return 0; 158 178 default: ··· 205 203 if (!pcf2127) 206 204 return -ENOMEM; 207 205 208 - dev_info(&client->dev, "chip found, driver version " DRV_VERSION "\n"); 209 - 210 206 i2c_set_clientdata(client, pcf2127); 211 207 212 208 pcf2127->rtc = devm_rtc_device_register(&client->dev, ··· 241 241 242 242 MODULE_AUTHOR("Renaud Cerrato <r.cerrato@til-technologies.fr>"); 243 243 MODULE_DESCRIPTION("NXP PCF2127 RTC driver"); 244 - MODULE_LICENSE("GPL"); 245 - MODULE_VERSION(DRV_VERSION); 244 + MODULE_LICENSE("GPL v2");
+1 -7
drivers/rtc/rtc-pcf85063.c
··· 80 80 pcf85063->c_polarity = (buf[PCF85063_REG_MO] & PCF85063_MO_C) ? 81 81 (tm->tm_year >= 100) : (tm->tm_year < 100); 82 82 83 - /* the clock can give out invalid datetime, but we cannot return 84 - * -EINVAL otherwise hwclock will refuse to set the time on bootup. 85 - */ 86 - if (rtc_valid_tm(tm) < 0) 87 - dev_err(&client->dev, "retrieved date/time is not valid.\n"); 88 - 89 - return 0; 83 + return rtc_valid_tm(tm); 90 84 } 91 85 92 86 static int pcf85063_set_datetime(struct i2c_client *client, struct rtc_time *tm)
+169 -1
drivers/rtc/rtc-pcf8563.c
··· 14 14 * published by the Free Software Foundation. 15 15 */ 16 16 17 + #include <linux/clk-provider.h> 17 18 #include <linux/i2c.h> 18 19 #include <linux/bcd.h> 19 20 #include <linux/rtc.h> ··· 41 40 42 41 #define PCF8563_REG_AMN 0x09 /* alarm */ 43 42 44 - #define PCF8563_REG_CLKO 0x0D /* clock out */ 43 + #define PCF8563_REG_CLKO 0x0D /* clock out */ 44 + #define PCF8563_REG_CLKO_FE 0x80 /* clock out enabled */ 45 + #define PCF8563_REG_CLKO_F_MASK 0x03 /* frequenc mask */ 46 + #define PCF8563_REG_CLKO_F_32768HZ 0x00 47 + #define PCF8563_REG_CLKO_F_1024HZ 0x01 48 + #define PCF8563_REG_CLKO_F_32HZ 0x02 49 + #define PCF8563_REG_CLKO_F_1HZ 0x03 50 + 45 51 #define PCF8563_REG_TMRC 0x0E /* timer control */ 46 52 #define PCF8563_TMRC_ENABLE BIT(7) 47 53 #define PCF8563_TMRC_4096 0 ··· 84 76 int voltage_low; /* incicates if a low_voltage was detected */ 85 77 86 78 struct i2c_client *client; 79 + #ifdef CONFIG_COMMON_CLK 80 + struct clk_hw clkout_hw; 81 + #endif 87 82 }; 88 83 89 84 static int pcf8563_read_block_data(struct i2c_client *client, unsigned char reg, ··· 401 390 return pcf8563_set_alarm_mode(to_i2c_client(dev), !!enabled); 402 391 } 403 392 393 + #ifdef CONFIG_COMMON_CLK 394 + /* 395 + * Handling of the clkout 396 + */ 397 + 398 + #define clkout_hw_to_pcf8563(_hw) container_of(_hw, struct pcf8563, clkout_hw) 399 + 400 + static int clkout_rates[] = { 401 + 32768, 402 + 1024, 403 + 32, 404 + 1, 405 + }; 406 + 407 + static unsigned long pcf8563_clkout_recalc_rate(struct clk_hw *hw, 408 + unsigned long parent_rate) 409 + { 410 + struct pcf8563 *pcf8563 = clkout_hw_to_pcf8563(hw); 411 + struct i2c_client *client = pcf8563->client; 412 + unsigned char buf; 413 + int ret = pcf8563_read_block_data(client, PCF8563_REG_CLKO, 1, &buf); 414 + 415 + if (ret < 0) 416 + return 0; 417 + 418 + buf &= PCF8563_REG_CLKO_F_MASK; 419 + return clkout_rates[ret]; 420 + } 421 + 422 + static long pcf8563_clkout_round_rate(struct clk_hw *hw, unsigned long rate, 423 + unsigned long *prate) 424 + { 425 + int i; 426 + 427 + for (i = 0; i < ARRAY_SIZE(clkout_rates); i++) 428 + if (clkout_rates[i] <= rate) 429 + return clkout_rates[i]; 430 + 431 + return 0; 432 + } 433 + 434 + static int pcf8563_clkout_set_rate(struct clk_hw *hw, unsigned long rate, 435 + unsigned long parent_rate) 436 + { 437 + struct pcf8563 *pcf8563 = clkout_hw_to_pcf8563(hw); 438 + struct i2c_client *client = pcf8563->client; 439 + unsigned char buf; 440 + int ret = pcf8563_read_block_data(client, PCF8563_REG_CLKO, 1, &buf); 441 + int i; 442 + 443 + if (ret < 0) 444 + return ret; 445 + 446 + for (i = 0; i < ARRAY_SIZE(clkout_rates); i++) 447 + if (clkout_rates[i] == rate) { 448 + buf &= ~PCF8563_REG_CLKO_F_MASK; 449 + buf |= i; 450 + ret = pcf8563_write_block_data(client, 451 + PCF8563_REG_CLKO, 1, 452 + &buf); 453 + return ret; 454 + } 455 + 456 + return -EINVAL; 457 + } 458 + 459 + static int pcf8563_clkout_control(struct clk_hw *hw, bool enable) 460 + { 461 + struct pcf8563 *pcf8563 = clkout_hw_to_pcf8563(hw); 462 + struct i2c_client *client = pcf8563->client; 463 + unsigned char buf; 464 + int ret = pcf8563_read_block_data(client, PCF8563_REG_CLKO, 1, &buf); 465 + 466 + if (ret < 0) 467 + return ret; 468 + 469 + if (enable) 470 + buf |= PCF8563_REG_CLKO_FE; 471 + else 472 + buf &= ~PCF8563_REG_CLKO_FE; 473 + 474 + ret = pcf8563_write_block_data(client, PCF8563_REG_CLKO, 1, &buf); 475 + return ret; 476 + } 477 + 478 + static int pcf8563_clkout_prepare(struct clk_hw *hw) 479 + { 480 + return pcf8563_clkout_control(hw, 1); 481 + } 482 + 483 + static void pcf8563_clkout_unprepare(struct clk_hw *hw) 484 + { 485 + pcf8563_clkout_control(hw, 0); 486 + } 487 + 488 + static int pcf8563_clkout_is_prepared(struct clk_hw *hw) 489 + { 490 + struct pcf8563 *pcf8563 = clkout_hw_to_pcf8563(hw); 491 + struct i2c_client *client = pcf8563->client; 492 + unsigned char buf; 493 + int ret = pcf8563_read_block_data(client, PCF8563_REG_CLKO, 1, &buf); 494 + 495 + if (ret < 0) 496 + return ret; 497 + 498 + return !!(buf & PCF8563_REG_CLKO_FE); 499 + } 500 + 501 + static const struct clk_ops pcf8563_clkout_ops = { 502 + .prepare = pcf8563_clkout_prepare, 503 + .unprepare = pcf8563_clkout_unprepare, 504 + .is_prepared = pcf8563_clkout_is_prepared, 505 + .recalc_rate = pcf8563_clkout_recalc_rate, 506 + .round_rate = pcf8563_clkout_round_rate, 507 + .set_rate = pcf8563_clkout_set_rate, 508 + }; 509 + 510 + static struct clk *pcf8563_clkout_register_clk(struct pcf8563 *pcf8563) 511 + { 512 + struct i2c_client *client = pcf8563->client; 513 + struct device_node *node = client->dev.of_node; 514 + struct clk *clk; 515 + struct clk_init_data init; 516 + int ret; 517 + unsigned char buf; 518 + 519 + /* disable the clkout output */ 520 + buf = 0; 521 + ret = pcf8563_write_block_data(client, PCF8563_REG_CLKO, 1, &buf); 522 + if (ret < 0) 523 + return ERR_PTR(ret); 524 + 525 + init.name = "pcf8563-clkout"; 526 + init.ops = &pcf8563_clkout_ops; 527 + init.flags = CLK_IS_ROOT; 528 + init.parent_names = NULL; 529 + init.num_parents = 0; 530 + pcf8563->clkout_hw.init = &init; 531 + 532 + /* optional override of the clockname */ 533 + of_property_read_string(node, "clock-output-names", &init.name); 534 + 535 + /* register the clock */ 536 + clk = devm_clk_register(&client->dev, &pcf8563->clkout_hw); 537 + 538 + if (!IS_ERR(clk)) 539 + of_clk_add_provider(node, of_clk_src_simple_get, clk); 540 + 541 + return clk; 542 + } 543 + #endif 544 + 404 545 static const struct rtc_class_ops pcf8563_rtc_ops = { 405 546 .ioctl = pcf8563_rtc_ioctl, 406 547 .read_time = pcf8563_rtc_read_time, ··· 621 458 } 622 459 623 460 } 461 + 462 + #ifdef CONFIG_COMMON_CLK 463 + /* register clk in common clk framework */ 464 + pcf8563_clkout_register_clk(pcf8563); 465 + #endif 624 466 625 467 /* the pcf8563 alarm only supports a minute accuracy */ 626 468 pcf8563->rtc->uie_unsupported = 1;
+8 -5
drivers/rtc/rtc-pl031.c
··· 23 23 #include <linux/io.h> 24 24 #include <linux/bcd.h> 25 25 #include <linux/delay.h> 26 + #include <linux/pm_wakeirq.h> 26 27 #include <linux/slab.h> 27 28 28 29 /* ··· 306 305 { 307 306 struct pl031_local *ldata = dev_get_drvdata(&adev->dev); 308 307 308 + dev_pm_clear_wake_irq(&adev->dev); 309 + device_init_wakeup(&adev->dev, false); 309 310 free_irq(adev->irq[0], ldata); 310 311 rtc_device_unregister(ldata->rtc); 311 312 iounmap(ldata->base); ··· 373 370 } 374 371 } 375 372 376 - device_init_wakeup(&adev->dev, 1); 373 + device_init_wakeup(&adev->dev, true); 377 374 ldata->rtc = rtc_device_register("pl031", &adev->dev, ops, 378 375 THIS_MODULE); 379 376 if (IS_ERR(ldata->rtc)) { ··· 386 383 ret = -EIO; 387 384 goto out_no_irq; 388 385 } 389 - 386 + dev_pm_set_wake_irq(&adev->dev, adev->irq[0]); 390 387 return 0; 391 388 392 389 out_no_irq: ··· 411 408 .set_alarm = pl031_set_alarm, 412 409 .alarm_irq_enable = pl031_alarm_irq_enable, 413 410 }, 414 - .irqflags = IRQF_NO_SUSPEND, 415 411 }; 416 412 417 413 /* The First ST derivative */ ··· 424 422 }, 425 423 .clockwatch = true, 426 424 .st_weekday = true, 427 - .irqflags = IRQF_NO_SUSPEND, 428 425 }; 429 426 430 427 /* And the second ST derivative */ ··· 440 439 /* 441 440 * This variant shares the IRQ with another block and must not 442 441 * suspend that IRQ line. 442 + * TODO check if it shares with IRQF_NO_SUSPEND user, else we can 443 + * remove IRQF_COND_SUSPEND 443 444 */ 444 - .irqflags = IRQF_SHARED | IRQF_NO_SUSPEND, 445 + .irqflags = IRQF_SHARED | IRQF_COND_SUSPEND, 445 446 }; 446 447 447 448 static struct amba_id pl031_ids[] = {
+521
drivers/rtc/rtc-rv8803.c
··· 1 + /* 2 + * RTC driver for the Micro Crystal RV8803 3 + * 4 + * Copyright (C) 2015 Micro Crystal SA 5 + * 6 + * Alexandre Belloni <alexandre.belloni@free-electrons.com> 7 + * 8 + * 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 + * published by the Free Software Foundation. 11 + * 12 + */ 13 + 14 + #include <linux/bcd.h> 15 + #include <linux/bitops.h> 16 + #include <linux/i2c.h> 17 + #include <linux/interrupt.h> 18 + #include <linux/kernel.h> 19 + #include <linux/module.h> 20 + #include <linux/rtc.h> 21 + 22 + #define RV8803_SEC 0x00 23 + #define RV8803_MIN 0x01 24 + #define RV8803_HOUR 0x02 25 + #define RV8803_WEEK 0x03 26 + #define RV8803_DAY 0x04 27 + #define RV8803_MONTH 0x05 28 + #define RV8803_YEAR 0x06 29 + #define RV8803_RAM 0x07 30 + #define RV8803_ALARM_MIN 0x08 31 + #define RV8803_ALARM_HOUR 0x09 32 + #define RV8803_ALARM_WEEK_OR_DAY 0x0A 33 + #define RV8803_EXT 0x0D 34 + #define RV8803_FLAG 0x0E 35 + #define RV8803_CTRL 0x0F 36 + 37 + #define RV8803_EXT_WADA BIT(6) 38 + 39 + #define RV8803_FLAG_V1F BIT(0) 40 + #define RV8803_FLAG_V2F BIT(1) 41 + #define RV8803_FLAG_AF BIT(3) 42 + #define RV8803_FLAG_TF BIT(4) 43 + #define RV8803_FLAG_UF BIT(5) 44 + 45 + #define RV8803_CTRL_RESET BIT(0) 46 + 47 + #define RV8803_CTRL_EIE BIT(2) 48 + #define RV8803_CTRL_AIE BIT(3) 49 + #define RV8803_CTRL_TIE BIT(4) 50 + #define RV8803_CTRL_UIE BIT(5) 51 + 52 + struct rv8803_data { 53 + struct i2c_client *client; 54 + struct rtc_device *rtc; 55 + spinlock_t flags_lock; 56 + u8 ctrl; 57 + }; 58 + 59 + static irqreturn_t rv8803_handle_irq(int irq, void *dev_id) 60 + { 61 + struct i2c_client *client = dev_id; 62 + struct rv8803_data *rv8803 = i2c_get_clientdata(client); 63 + unsigned long events = 0; 64 + u8 flags; 65 + 66 + spin_lock(&rv8803->flags_lock); 67 + 68 + flags = i2c_smbus_read_byte_data(client, RV8803_FLAG); 69 + if (flags <= 0) { 70 + spin_unlock(&rv8803->flags_lock); 71 + return IRQ_NONE; 72 + } 73 + 74 + if (flags & RV8803_FLAG_V1F) 75 + dev_warn(&client->dev, "Voltage low, temperature compensation stopped.\n"); 76 + 77 + if (flags & RV8803_FLAG_V2F) 78 + dev_warn(&client->dev, "Voltage low, data loss detected.\n"); 79 + 80 + if (flags & RV8803_FLAG_TF) { 81 + flags &= ~RV8803_FLAG_TF; 82 + rv8803->ctrl &= ~RV8803_CTRL_TIE; 83 + events |= RTC_PF; 84 + } 85 + 86 + if (flags & RV8803_FLAG_AF) { 87 + flags &= ~RV8803_FLAG_AF; 88 + rv8803->ctrl &= ~RV8803_CTRL_AIE; 89 + events |= RTC_AF; 90 + } 91 + 92 + if (flags & RV8803_FLAG_UF) { 93 + flags &= ~RV8803_FLAG_UF; 94 + rv8803->ctrl &= ~RV8803_CTRL_UIE; 95 + events |= RTC_UF; 96 + } 97 + 98 + if (events) { 99 + rtc_update_irq(rv8803->rtc, 1, events); 100 + i2c_smbus_write_byte_data(client, RV8803_FLAG, flags); 101 + i2c_smbus_write_byte_data(rv8803->client, RV8803_CTRL, 102 + rv8803->ctrl); 103 + } 104 + 105 + spin_unlock(&rv8803->flags_lock); 106 + 107 + return IRQ_HANDLED; 108 + } 109 + 110 + static int rv8803_get_time(struct device *dev, struct rtc_time *tm) 111 + { 112 + struct rv8803_data *rv8803 = dev_get_drvdata(dev); 113 + u8 date1[7]; 114 + u8 date2[7]; 115 + u8 *date = date1; 116 + int ret, flags; 117 + 118 + flags = i2c_smbus_read_byte_data(rv8803->client, RV8803_FLAG); 119 + if (flags < 0) 120 + return flags; 121 + 122 + if (flags & RV8803_FLAG_V2F) { 123 + dev_warn(dev, "Voltage low, data is invalid.\n"); 124 + return -EINVAL; 125 + } 126 + 127 + ret = i2c_smbus_read_i2c_block_data(rv8803->client, RV8803_SEC, 128 + 7, date); 129 + if (ret != 7) 130 + return ret < 0 ? ret : -EIO; 131 + 132 + if ((date1[RV8803_SEC] & 0x7f) == bin2bcd(59)) { 133 + ret = i2c_smbus_read_i2c_block_data(rv8803->client, RV8803_SEC, 134 + 7, date2); 135 + if (ret != 7) 136 + return ret < 0 ? ret : -EIO; 137 + 138 + if ((date2[RV8803_SEC] & 0x7f) != bin2bcd(59)) 139 + date = date2; 140 + } 141 + 142 + tm->tm_sec = bcd2bin(date[RV8803_SEC] & 0x7f); 143 + tm->tm_min = bcd2bin(date[RV8803_MIN] & 0x7f); 144 + tm->tm_hour = bcd2bin(date[RV8803_HOUR] & 0x3f); 145 + tm->tm_wday = ffs(date[RV8803_WEEK] & 0x7f); 146 + tm->tm_mday = bcd2bin(date[RV8803_DAY] & 0x3f); 147 + tm->tm_mon = bcd2bin(date[RV8803_MONTH] & 0x1f) - 1; 148 + tm->tm_year = bcd2bin(date[RV8803_YEAR]) + 100; 149 + 150 + return rtc_valid_tm(tm); 151 + } 152 + 153 + static int rv8803_set_time(struct device *dev, struct rtc_time *tm) 154 + { 155 + struct rv8803_data *rv8803 = dev_get_drvdata(dev); 156 + u8 date[7]; 157 + int flags, ret; 158 + unsigned long irqflags; 159 + 160 + if ((tm->tm_year < 100) || (tm->tm_year > 199)) 161 + return -EINVAL; 162 + 163 + date[RV8803_SEC] = bin2bcd(tm->tm_sec); 164 + date[RV8803_MIN] = bin2bcd(tm->tm_min); 165 + date[RV8803_HOUR] = bin2bcd(tm->tm_hour); 166 + date[RV8803_WEEK] = 1 << (tm->tm_wday); 167 + date[RV8803_DAY] = bin2bcd(tm->tm_mday); 168 + date[RV8803_MONTH] = bin2bcd(tm->tm_mon + 1); 169 + date[RV8803_YEAR] = bin2bcd(tm->tm_year - 100); 170 + 171 + ret = i2c_smbus_write_i2c_block_data(rv8803->client, RV8803_SEC, 172 + 7, date); 173 + if (ret < 0) 174 + return ret; 175 + 176 + spin_lock_irqsave(&rv8803->flags_lock, irqflags); 177 + 178 + flags = i2c_smbus_read_byte_data(rv8803->client, RV8803_FLAG); 179 + if (flags < 0) { 180 + spin_unlock_irqrestore(&rv8803->flags_lock, irqflags); 181 + return flags; 182 + } 183 + 184 + ret = i2c_smbus_write_byte_data(rv8803->client, RV8803_FLAG, 185 + flags & ~RV8803_FLAG_V2F); 186 + 187 + spin_unlock_irqrestore(&rv8803->flags_lock, irqflags); 188 + 189 + return ret; 190 + } 191 + 192 + static int rv8803_get_alarm(struct device *dev, struct rtc_wkalrm *alrm) 193 + { 194 + struct rv8803_data *rv8803 = dev_get_drvdata(dev); 195 + struct i2c_client *client = rv8803->client; 196 + u8 alarmvals[3]; 197 + int flags, ret; 198 + 199 + ret = i2c_smbus_read_i2c_block_data(client, RV8803_ALARM_MIN, 200 + 3, alarmvals); 201 + if (ret != 3) 202 + return ret < 0 ? ret : -EIO; 203 + 204 + flags = i2c_smbus_read_byte_data(client, RV8803_FLAG); 205 + if (flags < 0) 206 + return flags; 207 + 208 + alrm->time.tm_sec = 0; 209 + alrm->time.tm_min = bcd2bin(alarmvals[0] & 0x7f); 210 + alrm->time.tm_hour = bcd2bin(alarmvals[1] & 0x3f); 211 + alrm->time.tm_wday = -1; 212 + alrm->time.tm_mday = bcd2bin(alarmvals[2] & 0x3f); 213 + alrm->time.tm_mon = -1; 214 + alrm->time.tm_year = -1; 215 + 216 + alrm->enabled = !!(rv8803->ctrl & RV8803_CTRL_AIE); 217 + alrm->pending = (flags & RV8803_FLAG_AF) && alrm->enabled; 218 + 219 + return 0; 220 + } 221 + 222 + static int rv8803_set_alarm(struct device *dev, struct rtc_wkalrm *alrm) 223 + { 224 + struct i2c_client *client = to_i2c_client(dev); 225 + struct rv8803_data *rv8803 = dev_get_drvdata(dev); 226 + u8 alarmvals[3]; 227 + u8 ctrl[2]; 228 + int ret, err; 229 + unsigned long irqflags; 230 + 231 + /* The alarm has no seconds, round up to nearest minute */ 232 + if (alrm->time.tm_sec) { 233 + time64_t alarm_time = rtc_tm_to_time64(&alrm->time); 234 + 235 + alarm_time += 60 - alrm->time.tm_sec; 236 + rtc_time64_to_tm(alarm_time, &alrm->time); 237 + } 238 + 239 + spin_lock_irqsave(&rv8803->flags_lock, irqflags); 240 + 241 + ret = i2c_smbus_read_i2c_block_data(client, RV8803_FLAG, 2, ctrl); 242 + if (ret != 2) { 243 + spin_unlock_irqrestore(&rv8803->flags_lock, irqflags); 244 + return ret < 0 ? ret : -EIO; 245 + } 246 + 247 + alarmvals[0] = bin2bcd(alrm->time.tm_min); 248 + alarmvals[1] = bin2bcd(alrm->time.tm_hour); 249 + alarmvals[2] = bin2bcd(alrm->time.tm_mday); 250 + 251 + if (rv8803->ctrl & (RV8803_CTRL_AIE | RV8803_CTRL_UIE)) { 252 + rv8803->ctrl &= ~(RV8803_CTRL_AIE | RV8803_CTRL_UIE); 253 + err = i2c_smbus_write_byte_data(rv8803->client, RV8803_CTRL, 254 + rv8803->ctrl); 255 + if (err) { 256 + spin_unlock_irqrestore(&rv8803->flags_lock, irqflags); 257 + return err; 258 + } 259 + } 260 + 261 + ctrl[1] &= ~RV8803_FLAG_AF; 262 + err = i2c_smbus_write_byte_data(rv8803->client, RV8803_FLAG, ctrl[1]); 263 + spin_unlock_irqrestore(&rv8803->flags_lock, irqflags); 264 + if (err) 265 + return err; 266 + 267 + err = i2c_smbus_write_i2c_block_data(rv8803->client, RV8803_ALARM_MIN, 268 + 3, alarmvals); 269 + if (err) 270 + return err; 271 + 272 + if (alrm->enabled) { 273 + if (rv8803->rtc->uie_rtctimer.enabled) 274 + rv8803->ctrl |= RV8803_CTRL_UIE; 275 + if (rv8803->rtc->aie_timer.enabled) 276 + rv8803->ctrl |= RV8803_CTRL_AIE; 277 + 278 + err = i2c_smbus_write_byte_data(rv8803->client, RV8803_CTRL, 279 + rv8803->ctrl); 280 + if (err) 281 + return err; 282 + } 283 + 284 + return 0; 285 + } 286 + 287 + static int rv8803_alarm_irq_enable(struct device *dev, unsigned int enabled) 288 + { 289 + struct i2c_client *client = to_i2c_client(dev); 290 + struct rv8803_data *rv8803 = dev_get_drvdata(dev); 291 + int ctrl, flags, err; 292 + unsigned long irqflags; 293 + 294 + ctrl = rv8803->ctrl; 295 + 296 + if (enabled) { 297 + if (rv8803->rtc->uie_rtctimer.enabled) 298 + ctrl |= RV8803_CTRL_UIE; 299 + if (rv8803->rtc->aie_timer.enabled) 300 + ctrl |= RV8803_CTRL_AIE; 301 + } else { 302 + if (!rv8803->rtc->uie_rtctimer.enabled) 303 + ctrl &= ~RV8803_CTRL_UIE; 304 + if (!rv8803->rtc->aie_timer.enabled) 305 + ctrl &= ~RV8803_CTRL_AIE; 306 + } 307 + 308 + spin_lock_irqsave(&rv8803->flags_lock, irqflags); 309 + flags = i2c_smbus_read_byte_data(client, RV8803_FLAG); 310 + if (flags < 0) { 311 + spin_unlock_irqrestore(&rv8803->flags_lock, irqflags); 312 + return flags; 313 + } 314 + flags &= ~(RV8803_FLAG_AF | RV8803_FLAG_UF); 315 + err = i2c_smbus_write_byte_data(client, RV8803_FLAG, flags); 316 + spin_unlock_irqrestore(&rv8803->flags_lock, irqflags); 317 + if (err) 318 + return err; 319 + 320 + if (ctrl != rv8803->ctrl) { 321 + rv8803->ctrl = ctrl; 322 + err = i2c_smbus_write_byte_data(client, RV8803_CTRL, 323 + rv8803->ctrl); 324 + if (err) 325 + return err; 326 + } 327 + 328 + return 0; 329 + } 330 + 331 + static int rv8803_ioctl(struct device *dev, unsigned int cmd, unsigned long arg) 332 + { 333 + struct i2c_client *client = to_i2c_client(dev); 334 + struct rv8803_data *rv8803 = dev_get_drvdata(dev); 335 + int flags, ret = 0; 336 + unsigned long irqflags; 337 + 338 + switch (cmd) { 339 + case RTC_VL_READ: 340 + flags = i2c_smbus_read_byte_data(client, RV8803_FLAG); 341 + if (flags < 0) 342 + return flags; 343 + 344 + if (flags & RV8803_FLAG_V1F) 345 + dev_warn(&client->dev, "Voltage low, temperature compensation stopped.\n"); 346 + 347 + if (flags & RV8803_FLAG_V2F) 348 + dev_warn(&client->dev, "Voltage low, data loss detected.\n"); 349 + 350 + flags &= RV8803_FLAG_V1F | RV8803_FLAG_V2F; 351 + 352 + if (copy_to_user((void __user *)arg, &flags, sizeof(int))) 353 + return -EFAULT; 354 + 355 + return 0; 356 + 357 + case RTC_VL_CLR: 358 + spin_lock_irqsave(&rv8803->flags_lock, irqflags); 359 + flags = i2c_smbus_read_byte_data(client, RV8803_FLAG); 360 + if (flags < 0) { 361 + spin_unlock_irqrestore(&rv8803->flags_lock, irqflags); 362 + return flags; 363 + } 364 + 365 + flags &= ~(RV8803_FLAG_V1F | RV8803_FLAG_V2F); 366 + ret = i2c_smbus_write_byte_data(client, RV8803_FLAG, flags); 367 + spin_unlock_irqrestore(&rv8803->flags_lock, irqflags); 368 + if (ret < 0) 369 + return ret; 370 + 371 + return 0; 372 + 373 + default: 374 + return -ENOIOCTLCMD; 375 + } 376 + } 377 + 378 + static ssize_t rv8803_nvram_write(struct file *filp, struct kobject *kobj, 379 + struct bin_attribute *attr, 380 + char *buf, loff_t off, size_t count) 381 + { 382 + struct device *dev = kobj_to_dev(kobj); 383 + struct i2c_client *client = to_i2c_client(dev); 384 + int ret; 385 + 386 + ret = i2c_smbus_write_byte_data(client, RV8803_RAM, buf[0]); 387 + if (ret < 0) 388 + return ret; 389 + 390 + return 1; 391 + } 392 + 393 + static ssize_t rv8803_nvram_read(struct file *filp, struct kobject *kobj, 394 + struct bin_attribute *attr, 395 + char *buf, loff_t off, size_t count) 396 + { 397 + struct device *dev = kobj_to_dev(kobj); 398 + struct i2c_client *client = to_i2c_client(dev); 399 + int ret; 400 + 401 + ret = i2c_smbus_read_byte_data(client, RV8803_RAM); 402 + if (ret < 0) 403 + return ret; 404 + 405 + buf[0] = ret; 406 + 407 + return 1; 408 + } 409 + 410 + static struct bin_attribute rv8803_nvram_attr = { 411 + .attr = { 412 + .name = "nvram", 413 + .mode = S_IRUGO | S_IWUSR, 414 + }, 415 + .size = 1, 416 + .read = rv8803_nvram_read, 417 + .write = rv8803_nvram_write, 418 + }; 419 + 420 + static struct rtc_class_ops rv8803_rtc_ops = { 421 + .read_time = rv8803_get_time, 422 + .set_time = rv8803_set_time, 423 + .ioctl = rv8803_ioctl, 424 + }; 425 + 426 + static int rv8803_probe(struct i2c_client *client, 427 + const struct i2c_device_id *id) 428 + { 429 + struct i2c_adapter *adapter = to_i2c_adapter(client->dev.parent); 430 + struct rv8803_data *rv8803; 431 + int err, flags; 432 + 433 + if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA | 434 + I2C_FUNC_SMBUS_I2C_BLOCK)) { 435 + dev_err(&adapter->dev, "doesn't support I2C_FUNC_SMBUS_BYTE_DATA | I2C_FUNC_SMBUS_I2C_BLOCK\n"); 436 + return -EIO; 437 + } 438 + 439 + rv8803 = devm_kzalloc(&client->dev, sizeof(struct rv8803_data), 440 + GFP_KERNEL); 441 + if (!rv8803) 442 + return -ENOMEM; 443 + 444 + rv8803->client = client; 445 + i2c_set_clientdata(client, rv8803); 446 + 447 + flags = i2c_smbus_read_byte_data(client, RV8803_FLAG); 448 + if (flags < 0) 449 + return flags; 450 + 451 + if (flags & RV8803_FLAG_V1F) 452 + dev_warn(&client->dev, "Voltage low, temperature compensation stopped.\n"); 453 + 454 + if (flags & RV8803_FLAG_V2F) 455 + dev_warn(&client->dev, "Voltage low, data loss detected.\n"); 456 + 457 + if (flags & RV8803_FLAG_AF) 458 + dev_warn(&client->dev, "An alarm maybe have been missed.\n"); 459 + 460 + if (client->irq > 0) { 461 + err = devm_request_threaded_irq(&client->dev, client->irq, 462 + NULL, rv8803_handle_irq, 463 + IRQF_TRIGGER_LOW | IRQF_ONESHOT, 464 + "rv8803", client); 465 + if (err) { 466 + dev_warn(&client->dev, "unable to request IRQ, alarms disabled\n"); 467 + client->irq = 0; 468 + } else { 469 + rv8803_rtc_ops.read_alarm = rv8803_get_alarm; 470 + rv8803_rtc_ops.set_alarm = rv8803_set_alarm; 471 + rv8803_rtc_ops.alarm_irq_enable = rv8803_alarm_irq_enable; 472 + } 473 + } 474 + 475 + rv8803->rtc = devm_rtc_device_register(&client->dev, client->name, 476 + &rv8803_rtc_ops, THIS_MODULE); 477 + if (IS_ERR(rv8803->rtc)) { 478 + dev_err(&client->dev, "unable to register the class device\n"); 479 + return PTR_ERR(rv8803->rtc); 480 + } 481 + 482 + err = i2c_smbus_write_byte_data(rv8803->client, RV8803_EXT, 483 + RV8803_EXT_WADA); 484 + if (err) 485 + return err; 486 + 487 + err = device_create_bin_file(&client->dev, &rv8803_nvram_attr); 488 + if (err) 489 + return err; 490 + 491 + rv8803->rtc->max_user_freq = 1; 492 + 493 + return 0; 494 + } 495 + 496 + static int rv8803_remove(struct i2c_client *client) 497 + { 498 + device_remove_bin_file(&client->dev, &rv8803_nvram_attr); 499 + 500 + return 0; 501 + } 502 + 503 + static const struct i2c_device_id rv8803_id[] = { 504 + { "rv8803", 0 }, 505 + { } 506 + }; 507 + MODULE_DEVICE_TABLE(i2c, rv8803_id); 508 + 509 + static struct i2c_driver rv8803_driver = { 510 + .driver = { 511 + .name = "rtc-rv8803", 512 + }, 513 + .probe = rv8803_probe, 514 + .remove = rv8803_remove, 515 + .id_table = rv8803_id, 516 + }; 517 + module_i2c_driver(rv8803_driver); 518 + 519 + MODULE_AUTHOR("Alexandre Belloni <alexandre.belloni@free-electrons.com>"); 520 + MODULE_DESCRIPTION("Micro Crystal RV8803 RTC driver"); 521 + MODULE_LICENSE("GPL v2");
+2 -2
drivers/rtc/rtc-rx8025.c
··· 65 65 66 66 static const struct i2c_device_id rx8025_id[] = { 67 67 { "rx8025", 0 }, 68 + { "rv8803", 1 }, 68 69 { } 69 70 }; 70 71 MODULE_DEVICE_TABLE(i2c, rx8025_id); ··· 519 518 } 520 519 521 520 rx8025 = devm_kzalloc(&client->dev, sizeof(*rx8025), GFP_KERNEL); 522 - if (!rx8025) { 521 + if (!rx8025) 523 522 return -ENOMEM; 524 - } 525 523 526 524 rx8025->client = client; 527 525 i2c_set_clientdata(client, rx8025);
+16
drivers/rtc/rtc-s3c.c
··· 302 302 struct s3c_rtc *info = dev_get_drvdata(dev); 303 303 struct rtc_time *tm = &alrm->time; 304 304 unsigned int alrm_en; 305 + int year = tm->tm_year - 100; 305 306 306 307 dev_dbg(dev, "s3c_rtc_setalarm: %d, %04d.%02d.%02d %02d:%02d:%02d\n", 307 308 alrm->enabled, ··· 327 326 if (tm->tm_hour < 24 && tm->tm_hour >= 0) { 328 327 alrm_en |= S3C2410_RTCALM_HOUREN; 329 328 writeb(bin2bcd(tm->tm_hour), info->base + S3C2410_ALMHOUR); 329 + } 330 + 331 + if (year < 100 && year >= 0) { 332 + alrm_en |= S3C2410_RTCALM_YEAREN; 333 + writeb(bin2bcd(year), info->base + S3C2410_ALMYEAR); 334 + } 335 + 336 + if (tm->tm_mon < 12 && tm->tm_mon >= 0) { 337 + alrm_en |= S3C2410_RTCALM_MONEN; 338 + writeb(bin2bcd(tm->tm_mon + 1), info->base + S3C2410_ALMMON); 339 + } 340 + 341 + if (tm->tm_mday <= 31 && tm->tm_mday >= 1) { 342 + alrm_en |= S3C2410_RTCALM_DAYEN; 343 + writeb(bin2bcd(tm->tm_mday), info->base + S3C2410_ALMDATE); 330 344 } 331 345 332 346 dev_dbg(dev, "setting S3C2410_RTCALM to %08x\n", alrm_en);
+13 -14
drivers/rtc/rtc-stmp3xxx.c
··· 32 32 #include <linux/stmp3xxx_rtc_wdt.h> 33 33 34 34 #define STMP3XXX_RTC_CTRL 0x0 35 - #define STMP3XXX_RTC_CTRL_SET 0x4 36 - #define STMP3XXX_RTC_CTRL_CLR 0x8 37 35 #define STMP3XXX_RTC_CTRL_ALARM_IRQ_EN 0x00000001 38 36 #define STMP3XXX_RTC_CTRL_ONEMSEC_IRQ_EN 0x00000002 39 37 #define STMP3XXX_RTC_CTRL_ALARM_IRQ 0x00000004 ··· 50 52 #define STMP3XXX_RTC_WATCHDOG 0x50 51 53 52 54 #define STMP3XXX_RTC_PERSISTENT0 0x60 53 - #define STMP3XXX_RTC_PERSISTENT0_SET 0x64 54 - #define STMP3XXX_RTC_PERSISTENT0_CLR 0x68 55 55 #define STMP3XXX_RTC_PERSISTENT0_CLOCKSOURCE (1 << 0) 56 56 #define STMP3XXX_RTC_PERSISTENT0_ALARM_WAKE_EN (1 << 1) 57 57 #define STMP3XXX_RTC_PERSISTENT0_ALARM_EN (1 << 2) ··· 175 179 176 180 if (status & STMP3XXX_RTC_CTRL_ALARM_IRQ) { 177 181 writel(STMP3XXX_RTC_CTRL_ALARM_IRQ, 178 - rtc_data->io + STMP3XXX_RTC_CTRL_CLR); 182 + rtc_data->io + STMP3XXX_RTC_CTRL + STMP_OFFSET_REG_CLR); 179 183 rtc_update_irq(rtc_data->rtc, 1, RTC_AF | RTC_IRQF); 180 184 return IRQ_HANDLED; 181 185 } ··· 190 194 if (enabled) { 191 195 writel(STMP3XXX_RTC_PERSISTENT0_ALARM_EN | 192 196 STMP3XXX_RTC_PERSISTENT0_ALARM_WAKE_EN, 193 - rtc_data->io + STMP3XXX_RTC_PERSISTENT0_SET); 197 + rtc_data->io + STMP3XXX_RTC_PERSISTENT0 + 198 + STMP_OFFSET_REG_SET); 194 199 writel(STMP3XXX_RTC_CTRL_ALARM_IRQ_EN, 195 - rtc_data->io + STMP3XXX_RTC_CTRL_SET); 200 + rtc_data->io + STMP3XXX_RTC_CTRL + STMP_OFFSET_REG_SET); 196 201 } else { 197 202 writel(STMP3XXX_RTC_PERSISTENT0_ALARM_EN | 198 203 STMP3XXX_RTC_PERSISTENT0_ALARM_WAKE_EN, 199 - rtc_data->io + STMP3XXX_RTC_PERSISTENT0_CLR); 204 + rtc_data->io + STMP3XXX_RTC_PERSISTENT0 + 205 + STMP_OFFSET_REG_CLR); 200 206 writel(STMP3XXX_RTC_CTRL_ALARM_IRQ_EN, 201 - rtc_data->io + STMP3XXX_RTC_CTRL_CLR); 207 + rtc_data->io + STMP3XXX_RTC_CTRL + STMP_OFFSET_REG_CLR); 202 208 } 203 209 return 0; 204 210 } ··· 243 245 return 0; 244 246 245 247 writel(STMP3XXX_RTC_CTRL_ALARM_IRQ_EN, 246 - rtc_data->io + STMP3XXX_RTC_CTRL_CLR); 248 + rtc_data->io + STMP3XXX_RTC_CTRL + STMP_OFFSET_REG_CLR); 247 249 248 250 return 0; 249 251 } ··· 332 334 STMP3XXX_RTC_PERSISTENT0_CLOCKSOURCE; 333 335 } 334 336 335 - writel(pers0_set, rtc_data->io + STMP3XXX_RTC_PERSISTENT0_SET); 337 + writel(pers0_set, rtc_data->io + STMP3XXX_RTC_PERSISTENT0 + 338 + STMP_OFFSET_REG_SET); 336 339 337 340 writel(STMP3XXX_RTC_PERSISTENT0_ALARM_EN | 338 341 STMP3XXX_RTC_PERSISTENT0_ALARM_WAKE_EN | 339 342 STMP3XXX_RTC_PERSISTENT0_ALARM_WAKE | pers0_clr, 340 - rtc_data->io + STMP3XXX_RTC_PERSISTENT0_CLR); 343 + rtc_data->io + STMP3XXX_RTC_PERSISTENT0 + STMP_OFFSET_REG_CLR); 341 344 342 345 writel(STMP3XXX_RTC_CTRL_ONEMSEC_IRQ_EN | 343 346 STMP3XXX_RTC_CTRL_ALARM_IRQ_EN, 344 - rtc_data->io + STMP3XXX_RTC_CTRL_CLR); 347 + rtc_data->io + STMP3XXX_RTC_CTRL + STMP_OFFSET_REG_CLR); 345 348 346 349 rtc_data->rtc = devm_rtc_device_register(&pdev->dev, pdev->name, 347 350 &stmp3xxx_rtc_ops, THIS_MODULE); ··· 375 376 writel(STMP3XXX_RTC_PERSISTENT0_ALARM_EN | 376 377 STMP3XXX_RTC_PERSISTENT0_ALARM_WAKE_EN | 377 378 STMP3XXX_RTC_PERSISTENT0_ALARM_WAKE, 378 - rtc_data->io + STMP3XXX_RTC_PERSISTENT0_CLR); 379 + rtc_data->io + STMP3XXX_RTC_PERSISTENT0 + STMP_OFFSET_REG_CLR); 379 380 return 0; 380 381 } 381 382 #endif
+1 -1
tools/testing/selftests/timers/rtctest.c
··· 61 61 /* Turn on update interrupts (one per second) */ 62 62 retval = ioctl(fd, RTC_UIE_ON, 0); 63 63 if (retval == -1) { 64 - if (errno == ENOTTY) { 64 + if (errno == EINVAL) { 65 65 fprintf(stderr, 66 66 "\n...Update IRQs not supported.\n"); 67 67 goto test_READ;