* [PATCH v2 0/2] rtc: Add ASPEED RTC driver @ 2019-03-25 13:31 Joel Stanley 2019-03-25 13:31 ` [PATCH v2 1/2] dt-bindings: rtc: Add on-chip ASPEED RTC documentation Joel Stanley 2019-03-25 13:31 ` [PATCH v2 2/2] rtc: Add ASPEED RTC driver Joel Stanley 0 siblings, 2 replies; 8+ messages in thread From: Joel Stanley @ 2019-03-25 13:31 UTC (permalink / raw) To: Alexandre Belloni, Alessandro Zummo, Rob Herring, Mark Rutland Cc: Andrew Jeffery, linux-rtc, linux-aspeed, linux-arm-kernel, devicetree I finally found some time to send a v2 for this one. Thanks Alexandre for the review back in October. v2: Address review from Alexandre Joel Stanley (2): dt-bindings: rtc: Add on-chip ASPEED RTC documentation rtc: Add ASPEED RTC driver .../devicetree/bindings/rtc/rtc-aspeed.txt | 19 +++ drivers/rtc/Kconfig | 10 ++ drivers/rtc/Makefile | 1 + drivers/rtc/rtc-aspeed.c | 152 ++++++++++++++++++ 4 files changed, 182 insertions(+) create mode 100644 Documentation/devicetree/bindings/rtc/rtc-aspeed.txt create mode 100644 drivers/rtc/rtc-aspeed.c -- 2.20.1 _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel ^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH v2 1/2] dt-bindings: rtc: Add on-chip ASPEED RTC documentation 2019-03-25 13:31 [PATCH v2 0/2] rtc: Add ASPEED RTC driver Joel Stanley @ 2019-03-25 13:31 ` Joel Stanley 2019-03-25 13:31 ` [PATCH v2 2/2] rtc: Add ASPEED RTC driver Joel Stanley 1 sibling, 0 replies; 8+ messages in thread From: Joel Stanley @ 2019-03-25 13:31 UTC (permalink / raw) To: Alexandre Belloni, Alessandro Zummo, Rob Herring, Mark Rutland Cc: Andrew Jeffery, linux-rtc, linux-aspeed, linux-arm-kernel, devicetree Describe the RTC as used in the ASPEED BMC SoCs. Signed-off-by: Joel Stanley <joel@jms.id.au> --- .../devicetree/bindings/rtc/rtc-aspeed.txt | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 Documentation/devicetree/bindings/rtc/rtc-aspeed.txt diff --git a/Documentation/devicetree/bindings/rtc/rtc-aspeed.txt b/Documentation/devicetree/bindings/rtc/rtc-aspeed.txt new file mode 100644 index 000000000000..f9f7defd557e --- /dev/null +++ b/Documentation/devicetree/bindings/rtc/rtc-aspeed.txt @@ -0,0 +1,19 @@ +ASPEED BMC RTC +============== + +Required properties: + - compatible: should be one of the following + * aspeed,ast2400-rtc for the ast2400 + * aspeed,ast2500-rtc for the ast2500 + * aspeed,ast2600-rtc for the ast2600 + + - reg: physical base address of the controller and length of memory mapped + region + +Example: + + rtc@1e781000 { + compatible = "aspeed,ast2400-rtc"; + reg = <0x1e781000 0x18>; + status = "disabled"; + }; -- 2.20.1 _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel ^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH v2 2/2] rtc: Add ASPEED RTC driver 2019-03-25 13:31 [PATCH v2 0/2] rtc: Add ASPEED RTC driver Joel Stanley 2019-03-25 13:31 ` [PATCH v2 1/2] dt-bindings: rtc: Add on-chip ASPEED RTC documentation Joel Stanley @ 2019-03-25 13:31 ` Joel Stanley 2019-03-25 14:59 ` Alexandre Belloni 1 sibling, 1 reply; 8+ messages in thread From: Joel Stanley @ 2019-03-25 13:31 UTC (permalink / raw) To: Alexandre Belloni, Alessandro Zummo, Rob Herring, Mark Rutland Cc: Andrew Jeffery, linux-rtc, linux-aspeed, linux-arm-kernel, devicetree Read and writes the time to the non-battery backed RTC in the ASPEED BMC system on chip families. Signed-off-by: Joel Stanley <joel@jms.id.au> --- v2: Address review from Alexandre - Use devm_rtc_allocate_device - Fill in range_min - Direcly fill in tm struct - Return EINVAL when RTC is not enabled v1: https://lore.kernel.org/linux-arm-kernel/20181003133155.27494-2-joel@jms.id.au/ Signed-off-by: Joel Stanley <joel@jms.id.au> --- drivers/rtc/Kconfig | 10 +++ drivers/rtc/Makefile | 1 + drivers/rtc/rtc-aspeed.c | 152 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 163 insertions(+) create mode 100644 drivers/rtc/rtc-aspeed.c diff --git a/drivers/rtc/Kconfig b/drivers/rtc/Kconfig index dc0d66e80038..2d0482bc468b 100644 --- a/drivers/rtc/Kconfig +++ b/drivers/rtc/Kconfig @@ -1841,6 +1841,16 @@ config RTC_DRV_RTD119X If you say yes here, you get support for the RTD1295 SoC Real Time Clock. +config RTC_DRV_ASPEED + tristate "Aspeed RTC" + depends on ARCH_ASPEED || COMPILE_TEST + help + If you say yes here you get support for the ASPEED AST2400 and + AST2500 SoC real time clocks. + + This driver can also be built as a module, if so, the module + will be called "rtc-aspeed". + comment "HID Sensor RTC drivers" config RTC_DRV_HID_SENSOR_TIME diff --git a/drivers/rtc/Makefile b/drivers/rtc/Makefile index fe3962496685..9d997faa2c26 100644 --- a/drivers/rtc/Makefile +++ b/drivers/rtc/Makefile @@ -34,6 +34,7 @@ obj-$(CONFIG_RTC_DRV_AC100) += rtc-ac100.o obj-$(CONFIG_RTC_DRV_ARMADA38X) += rtc-armada38x.o obj-$(CONFIG_RTC_DRV_AS3722) += rtc-as3722.o obj-$(CONFIG_RTC_DRV_ASM9260) += rtc-asm9260.o +obj-$(CONFIG_RTC_DRV_ASPEED) += rtc-aspeed.o obj-$(CONFIG_RTC_DRV_AT91RM9200)+= rtc-at91rm9200.o obj-$(CONFIG_RTC_DRV_AT91SAM9) += rtc-at91sam9.o obj-$(CONFIG_RTC_DRV_AU1XXX) += rtc-au1xxx.o diff --git a/drivers/rtc/rtc-aspeed.c b/drivers/rtc/rtc-aspeed.c new file mode 100644 index 000000000000..9ddb3121b30d --- /dev/null +++ b/drivers/rtc/rtc-aspeed.c @@ -0,0 +1,152 @@ +// SPDX-License-Identifier: GPL-2.0+ +// Copyright 2015 IBM Corp. + +#include <linux/module.h> +#include <linux/of.h> +#include <linux/platform_device.h> +#include <linux/rtc.h> +#include <linux/io.h> + +struct aspeed_rtc { + struct rtc_device *rtc_dev; + void __iomem *base; + spinlock_t lock; +}; + +#define RTC_TIME 0x00 +#define RTC_YEAR 0x04 +#define RTC_CTRL 0x10 + +#define RTC_UNLOCK BIT(1) +#define RTC_ENABLE BIT(0) + +static int aspeed_rtc_read_time(struct device *dev, struct rtc_time *tm) +{ + struct aspeed_rtc *rtc = dev_get_drvdata(dev); + unsigned int cent, year; + unsigned long flags; + u32 reg1, reg2; + + spin_lock_irqsave(&rtc->lock, flags); + + if (!(readl(rtc->base + RTC_CTRL) & RTC_ENABLE)) { + spin_unlock_irqrestore(&rtc->lock, flags); + dev_dbg(dev, "%s failing as rtc disabled\n", __func__); + return -EINVAL; + } + + do { + reg2 = readl(rtc->base + RTC_YEAR); + reg1 = readl(rtc->base + RTC_TIME); + } while (reg2 != readl(rtc->base + RTC_YEAR)); + + tm->tm_mday = (reg1 >> 24) & 0x1f; + tm->tm_hour = (reg1 >> 16) & 0x1f; + tm->tm_min = (reg1 >> 8) & 0x3f; + tm->tm_sec = (reg1 >> 0) & 0x3f; + + cent = (reg2 >> 16) & 0x1f; + year = (reg2 >> 8) & 0x7f; + tm->tm_mon = ((reg2 >> 0) & 0x0f) - 1; + tm->tm_year = year + (cent * 100) - 1900; + + dev_dbg(dev, "%s: %4d-%02d-%02d %02d:%02d:%02d\n", __func__, + 1900 + tm->tm_year, tm->tm_mon + 1, tm->tm_mday, + tm->tm_hour, tm->tm_min, tm->tm_sec); + + spin_unlock_irqrestore(&rtc->lock, flags); + + return 0; +} + +static int aspeed_rtc_set_time(struct device *dev, struct rtc_time *tm) +{ + struct aspeed_rtc *rtc = dev_get_drvdata(dev); + unsigned long flags; + u32 reg1, reg2, ctrl; + int year, cent; + + cent = (tm->tm_year + 1900) / 100; + year = tm->tm_year % 100; + + reg1 = (tm->tm_mday << 24) | (tm->tm_hour << 16) | (tm->tm_min << 8) | + tm->tm_sec; + + reg2 = ((cent & 0x1f) << 16) | ((year & 0x7f) << 8) | + ((tm->tm_mon + 1) & 0xf); + + spin_lock_irqsave(&rtc->lock, flags); + + ctrl = readl(rtc->base + RTC_CTRL); + writel(ctrl | RTC_UNLOCK, rtc->base + RTC_CTRL); + + writel(reg1, rtc->base + RTC_TIME); + writel(reg2, rtc->base + RTC_YEAR); + + /* Re-lock and ensure enable is set now that a time is programmed */ + writel(ctrl | RTC_ENABLE, rtc->base + RTC_CTRL); + + spin_unlock_irqrestore(&rtc->lock, flags); + + return 0; +} + +static const struct rtc_class_ops aspeed_rtc_ops = { + .read_time = aspeed_rtc_read_time, + .set_time = aspeed_rtc_set_time, +}; + +static int aspeed_rtc_probe(struct platform_device *pdev) +{ + struct aspeed_rtc *rtc; + struct resource *res; + int ret; + + rtc = devm_kzalloc(&pdev->dev, sizeof(*rtc), GFP_KERNEL); + if (!rtc) + return -ENOMEM; + + res = platform_get_resource(pdev, IORESOURCE_MEM, 0); + rtc->base = devm_ioremap_resource(&pdev->dev, res); + if (IS_ERR(rtc->base)) + return PTR_ERR(rtc->base); + + rtc->rtc_dev = devm_rtc_allocate_device(&pdev->dev); + if (IS_ERR(rtc->rtc_dev)) + return PTR_ERR(rtc->rtc_dev); + + platform_set_drvdata(pdev, rtc); + + rtc->rtc_dev->ops = &aspeed_rtc_ops; + rtc->rtc_dev->range_min = RTC_TIMESTAMP_BEGIN_1900; + rtc->rtc_dev->range_max = 38814989399LL; /* 3199-12-31 23:59:59 */ + + ret = rtc_register_device(rtc->rtc_dev); + if (ret) + return ret; + + spin_lock_init(&rtc->lock); + + return 0; +} + +static const struct of_device_id aspeed_rtc_match[] = { + { .compatible = "aspeed,ast2400-rtc", }, + { .compatible = "aspeed,ast2500-rtc", }, + { .compatible = "aspeed,ast2600-rtc", }, + {} +}; +MODULE_DEVICE_TABLE(of, aspeed_rtc_match); + +static struct platform_driver aspeed_rtc_driver = { + .driver = { + .name = "aspeed-rtc", + .of_match_table = of_match_ptr(aspeed_rtc_match), + }, +}; + +module_platform_driver_probe(aspeed_rtc_driver, aspeed_rtc_probe); + +MODULE_DESCRIPTION("ASPEED RTC driver"); +MODULE_AUTHOR("Joel Stanley <joel@jms.id.au>"); +MODULE_LICENSE("GPL"); -- 2.20.1 _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel ^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [PATCH v2 2/2] rtc: Add ASPEED RTC driver 2019-03-25 13:31 ` [PATCH v2 2/2] rtc: Add ASPEED RTC driver Joel Stanley @ 2019-03-25 14:59 ` Alexandre Belloni 2019-03-25 15:28 ` Joel Stanley 0 siblings, 1 reply; 8+ messages in thread From: Alexandre Belloni @ 2019-03-25 14:59 UTC (permalink / raw) To: Joel Stanley Cc: Mark Rutland, Alessandro Zummo, linux-aspeed, devicetree, Andrew Jeffery, Rob Herring, linux-arm-kernel, linux-rtc Hi, This seems mostly good to me. On 26/03/2019 00:01:59+1030, Joel Stanley wrote: > + dev_dbg(dev, "%s: %4d-%02d-%02d %02d:%02d:%02d\n", __func__, > + 1900 + tm->tm_year, tm->tm_mon + 1, tm->tm_mday, > + tm->tm_hour, tm->tm_min, tm->tm_sec); > + We now have %ptR, could you use that? > + rtc->rtc_dev->ops = &aspeed_rtc_ops; > + rtc->rtc_dev->range_min = RTC_TIMESTAMP_BEGIN_1900; > + rtc->rtc_dev->range_max = 38814989399LL; /* 3199-12-31 23:59:59 */ > + I'm curious how many RTC have been properly designed, could you run rtc-range? https://git.kernel.org/pub/scm/linux/kernel/git/abelloni/rtc-tools.git/tree/rtc-range.c Thanks! -- Alexandre Belloni, Bootlin Embedded Linux and Kernel engineering https://bootlin.com _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH v2 2/2] rtc: Add ASPEED RTC driver 2019-03-25 14:59 ` Alexandre Belloni @ 2019-03-25 15:28 ` Joel Stanley 2019-03-25 15:43 ` Alexandre Belloni 2019-03-25 16:10 ` Alexandre Belloni 0 siblings, 2 replies; 8+ messages in thread From: Joel Stanley @ 2019-03-25 15:28 UTC (permalink / raw) To: Alexandre Belloni Cc: Mark Rutland, Alessandro Zummo, linux-aspeed, devicetree, Andrew Jeffery, Rob Herring, Linux ARM, linux-rtc On Mon, 25 Mar 2019 at 14:59, Alexandre Belloni <alexandre.belloni@bootlin.com> wrote: > > Hi, > > This seems mostly good to me. > > On 26/03/2019 00:01:59+1030, Joel Stanley wrote: > > + dev_dbg(dev, "%s: %4d-%02d-%02d %02d:%02d:%02d\n", __func__, > > + 1900 + tm->tm_year, tm->tm_mon + 1, tm->tm_mday, > > + tm->tm_hour, tm->tm_min, tm->tm_sec); > > + > > We now have %ptR, could you use that? I tried this: dev_dbg(dev, "%s: %ptR", __func__, tm); Yes, that appears to do the job. Can you make the change when applying? > > > + rtc->rtc_dev->ops = &aspeed_rtc_ops; > > + rtc->rtc_dev->range_min = RTC_TIMESTAMP_BEGIN_1900; > > + rtc->rtc_dev->range_max = 38814989399LL; /* 3199-12-31 23:59:59 */ > > + > > I'm curious how many RTC have been properly designed, could you run > rtc-range? > > https://git.kernel.org/pub/scm/linux/kernel/git/abelloni/rtc-tools.git/tree/rtc-range.c It appears to pass the test: Testing 2000-02-28 23:59:59. OK Testing 2038-01-19 03:14:07. OK Testing 2069-12-31 23:59:59. OK Testing 2099-12-31 23:59:59. OK Testing 2100-02-28 23:59:59. OK Testing 2106-02-07 06:28:15. OK Testing 2262-04-11 23:47:16. OK The qemu model I have for the device failed though. A good test! Are you going to put it in the kernel tree? Cheers, Joel _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH v2 2/2] rtc: Add ASPEED RTC driver 2019-03-25 15:28 ` Joel Stanley @ 2019-03-25 15:43 ` Alexandre Belloni 2019-03-25 16:10 ` Alexandre Belloni 1 sibling, 0 replies; 8+ messages in thread From: Alexandre Belloni @ 2019-03-25 15:43 UTC (permalink / raw) To: Joel Stanley Cc: Mark Rutland, Alessandro Zummo, linux-aspeed, devicetree, Andrew Jeffery, Rob Herring, Linux ARM, linux-rtc On 25/03/2019 15:28:26+0000, Joel Stanley wrote: > On Mon, 25 Mar 2019 at 14:59, Alexandre Belloni > <alexandre.belloni@bootlin.com> wrote: > > On 26/03/2019 00:01:59+1030, Joel Stanley wrote: > > > + dev_dbg(dev, "%s: %4d-%02d-%02d %02d:%02d:%02d\n", __func__, > > > + 1900 + tm->tm_year, tm->tm_mon + 1, tm->tm_mday, > > > + tm->tm_hour, tm->tm_min, tm->tm_sec); > > > + > > > > We now have %ptR, could you use that? > > I tried this: > > dev_dbg(dev, "%s: %ptR", __func__, tm); > > Yes, that appears to do the job. Can you make the change when applying? > Ok, I'll do that. > > > > > + rtc->rtc_dev->ops = &aspeed_rtc_ops; > > > + rtc->rtc_dev->range_min = RTC_TIMESTAMP_BEGIN_1900; > > > + rtc->rtc_dev->range_max = 38814989399LL; /* 3199-12-31 23:59:59 */ > > > + > > > > I'm curious how many RTC have been properly designed, could you run > > rtc-range? > > > > https://git.kernel.org/pub/scm/linux/kernel/git/abelloni/rtc-tools.git/tree/rtc-range.c > > It appears to pass the test: > > Testing 2000-02-28 23:59:59. > OK > > Testing 2038-01-19 03:14:07. > OK > > Testing 2069-12-31 23:59:59. > OK > > Testing 2099-12-31 23:59:59. > OK > > Testing 2100-02-28 23:59:59. > OK > > Testing 2106-02-07 06:28:15. > OK > > Testing 2262-04-11 23:47:16. > OK > > The qemu model I have for the device failed though. A good test! Are > you going to put it in the kernel tree? > I was planning to add more dates to test and detect when the range is properly reported by the rtc (right now, it reports a failure) before doing so. -- Alexandre Belloni, Bootlin Embedded Linux and Kernel engineering https://bootlin.com _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH v2 2/2] rtc: Add ASPEED RTC driver 2019-03-25 15:28 ` Joel Stanley 2019-03-25 15:43 ` Alexandre Belloni @ 2019-03-25 16:10 ` Alexandre Belloni 2019-03-27 1:00 ` Joel Stanley 1 sibling, 1 reply; 8+ messages in thread From: Alexandre Belloni @ 2019-03-25 16:10 UTC (permalink / raw) To: Joel Stanley Cc: Mark Rutland, Alessandro Zummo, linux-aspeed, devicetree, Andrew Jeffery, Rob Herring, Linux ARM, linux-rtc On 25/03/2019 15:28:26+0000, Joel Stanley wrote: > On Mon, 25 Mar 2019 at 14:59, Alexandre Belloni > <alexandre.belloni@bootlin.com> wrote: > > > > Hi, > > > > This seems mostly good to me. > > > > On 26/03/2019 00:01:59+1030, Joel Stanley wrote: > > > + dev_dbg(dev, "%s: %4d-%02d-%02d %02d:%02d:%02d\n", __func__, > > > + 1900 + tm->tm_year, tm->tm_mon + 1, tm->tm_mday, > > > + tm->tm_hour, tm->tm_min, tm->tm_sec); > > > + > > > > We now have %ptR, could you use that? > > I tried this: > > dev_dbg(dev, "%s: %ptR", __func__, tm); > > Yes, that appears to do the job. Can you make the change when applying? > While doing that change, I relaized that the whole locking is probably unnecessary as all the rtc_ops are called with the rtc lock taken. If you are not planning to add alarm support, the lock can be removed. -- Alexandre Belloni, Bootlin Embedded Linux and Kernel engineering https://bootlin.com _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH v2 2/2] rtc: Add ASPEED RTC driver 2019-03-25 16:10 ` Alexandre Belloni @ 2019-03-27 1:00 ` Joel Stanley 0 siblings, 0 replies; 8+ messages in thread From: Joel Stanley @ 2019-03-27 1:00 UTC (permalink / raw) To: Alexandre Belloni Cc: Mark Rutland, Alessandro Zummo, linux-aspeed, devicetree, Andrew Jeffery, Rob Herring, Linux ARM, linux-rtc On Mon, 25 Mar 2019 at 16:10, Alexandre Belloni <alexandre.belloni@bootlin.com> wrote:> > > While doing that change, I relaized that the whole locking is probably > unnecessary as all the rtc_ops are called with the rtc lock taken. If > you are not planning to add alarm support, the lock can be removed. I had a stab at alarm support, but the select() tests in rtctest.c were failing. I will submit a v3 without the locking so we can get that out of the way, and defer adding alarm support for now. Cheers, Joel _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel ^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2019-03-27 1:01 UTC | newest] Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2019-03-25 13:31 [PATCH v2 0/2] rtc: Add ASPEED RTC driver Joel Stanley 2019-03-25 13:31 ` [PATCH v2 1/2] dt-bindings: rtc: Add on-chip ASPEED RTC documentation Joel Stanley 2019-03-25 13:31 ` [PATCH v2 2/2] rtc: Add ASPEED RTC driver Joel Stanley 2019-03-25 14:59 ` Alexandre Belloni 2019-03-25 15:28 ` Joel Stanley 2019-03-25 15:43 ` Alexandre Belloni 2019-03-25 16:10 ` Alexandre Belloni 2019-03-27 1:00 ` Joel Stanley
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for NNTP newsgroup(s).