Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753247AbbGWKwT (ORCPT ); Thu, 23 Jul 2015 06:52:19 -0400 Received: from mail-bn1on0093.outbound.protection.outlook.com ([157.56.110.93]:1248 "EHLO na01-bn1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751874AbbGWKwK (ORCPT ); Thu, 23 Jul 2015 06:52:10 -0400 Authentication-Results: spf=pass (sender IP is 149.199.60.83) smtp.mailfrom=xilinx.com; towertech.it; dkim=none (message not signed) header.d=none; From: Suneel Garapati To: , , CC: , , Alessandro Zummo , Suneel Garapati Subject: [PATCH 2/2] drivers: rtc: add xilinx zynqmp rtc driver Date: Thu, 23 Jul 2015 16:21:50 +0530 Message-ID: <1437648710-6857-2-git-send-email-suneel.garapati@xilinx.com> X-Mailer: git-send-email 2.1.2 In-Reply-To: <1437648710-6857-1-git-send-email-suneel.garapati@xilinx.com> References: <1437648710-6857-1-git-send-email-suneel.garapati@xilinx.com> X-RCIS-Action: ALLOW X-TM-AS-Product-Ver: IMSS-7.1.0.1224-8.0.0.1202-21698.005 X-TM-AS-User-Approved-Sender: Yes;Yes X-EOPAttributedMessage: 0 X-Microsoft-Exchange-Diagnostics: 1;BL2FFO11FD037;1:V/geWIZeRL9U0Dgj4egU6YUgZfy7Z3TUYv0pLfPNKxvdl0MQ7VOSfde8HNjau+fJpsjvuwC4xp4+zJahvLxSJU6yMw1GkvC+xkkkVhOMxWKnisYjxXf15VxFmmi7afoD3+OFGXuZVxphAOmUZiAHi0HndQEPShFGad/26JluW9rl9oFJFkl9NnS1DOwZ1z4RetwTh8LoSYz2CeOrZmYM/1kgX3TfYHuRtnqz0H20zBxtDo13CenDrieqjiOCjkMDmxP1U7Z2EvdKioiCRD76T7YXwhHxvRlY5UB6aBPwrIlTRJIP6NUGcUK+RoaxW9PsQXt0OGbBOPJNIdw/bRyxROHLm7eOpGVfnnTKywNKhatzjAaAIyio+owA77+QeGNpW6CrZZzBdaON4BaZDjkqOAze/Z34ie/aGCgxA0jEZCc= X-Forefront-Antispam-Report: CIP:149.199.60.83;CTRY:US;IPV:NLI;EFV:NLI;SFV:NSPM;SFS:(10009020)(6009001)(2980300002)(438002)(199003)(189002)(33646002)(2201001)(86362001)(87936001)(106466001)(575784001)(63266004)(47776003)(19580405001)(46102003)(50986999)(62966003)(6806004)(77156002)(229853001)(19580395003)(50226001)(5003600100002)(77096005)(76176999)(15975445007)(36756003)(36386004)(5001960100002)(5001920100001)(107886002)(189998001)(2950100001)(48376002)(50466002)(5003940100001)(92566002)(107986001)(2101003)(4001430100001);DIR:OUT;SFP:1101;SCL:1;SRVR:BL2FFO11HUB030;H:xsj-pvapsmtpgw01;FPR:;SPF:Pass;MLV:sfv;A:1;MX:1;LANG:en; MIME-Version: 1.0 Content-Type: text/plain X-Microsoft-Exchange-Diagnostics: 1;BL2FFO11HUB030;2:Y9Jc0tbxtcmTecMvFSKhfUPN+ACs4/tfSSK1obLYMS2xMEXpacEDmrLH4jS0zTVrU9QfpHyz3eIS6wNyW/uz2rvfGmJv0xJEaN2sFeEVcq16H0w9e/QGT5DBt2kLW5SknMQIEHT2X9yfmwVkjerRAzH8O0Q9ZtHaTfN+ST6dvdg=;3:wECZamdEFZ5r4Xs7OMLn8mXBSkC7sdlJjtcN8j9nOOAY4kaKe+KOesXxxzaA2dXkfJHQVcw7SYnm4we/97803Fan4vqbxynmU8PksoSQrW23C4LurKJj1IdvpUdUwHak6LobCboGo5wBwPcy2Im6tvgnnNEYjacf39T7IJOeA3BOK9OnKEgl+EjhrUTyP3l7mtYrTyWXldpb3VVXdWlHq7SRggLKhAu5HgIHqgdnB8o=;25:yDojFpkgmT1ooxZ4BrVt+s38hSoxiKIUS5uZrXCLkp/4n/qbC2g4FUwBNiqplFWvjgGEv1oEd5KhWVdilC0WE8dInqhfeubgiFwbGxORIidC0myFcHRlkvoEZaPw77oB631iBUziLZrlkRyxkA852rSGi/zxLn35nyfaul6LdBQtYkStuqQVpal8Ri3eHBcbty2RvzqVVfvXuSn/LPjAb4FNNMjQeYa+LcoAWY/TfVWFfcXzrvsdsk6w0+gNqIS0U/bOHdrXHoxAblNZh5B/tw== X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:BL2FFO11HUB030; X-Microsoft-Exchange-Diagnostics: 1;BL2FFO11HUB030;20:yKdB0g0w1dCKRfmhfcJfee9qaR0q9hG+66MNGUT3RCwXygkxCLINBgfOYFbdJpNXfuv+PxbjImjzJn6EWA8/QMHY7lu9YvOa3olPggWUgnII9G+7cd6dasp/VYKv43BI5hJDtSqN2MKuK0A8S13gOaXbwx89L3pfAB7mlY1X9MndmWJHM6hE1hjb/2yJJPiTi3rJyomndBpZshCwCJrA9Uw+lLBTuW4M6dk2k9jsAK5bJn/AbzRvuQU2+xOs1AurZhFaM9ohtNwhJH4se3MqVSlNcds0AXpOV61rxujyC3tVfA8rX5CXDLJ/hhj18PS0NWhR5BJhaSq68ltD/1TOET3XVHmFRa6nFNDRIqkOe53ieiyGPU9HEewm5aa3L8k4x0pm0M7JIvfDUHUJzm+D8wf5Urw8pqP8xIdiJ733YEt8wnXg6e6hjyWY1dMTayJO7OKyA7s1CyVleOIzHRCYe+LrCDgPqDbAsEIHj63xAbhALyTdkFxUC9PIEllBi46g;4:ova6I319QPwNA8X4iJtWtT4VxYO+BNVSPE7KJVoIc31KpCS5FLU5ogCrurt33yKokUY6OyIvm68CmtSoYXEq+hp7LvvHniTSnjseTodhrSHZx8CzjMlF7ddPIbOjfS5tRWlEQmqAL/NLSjyIbkjeLWU1KS2Ore7dzsCXlysmH+7NSSo34B1mb+bEfjh09tcf3IQDWNh9jRmp38oAqnY8TJY+TfoQcPlnLaDQ5yq8Xl6HM27OON5q0FBJNv8SF+pPbgIwDq/CYgdqvjTxeJ3YwgUwieP53uHnU9Zj9ntnoqM= BL2FFO11HUB030: X-MS-Exchange-Organization-RulesExecuted X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(601004)(5005006)(3002001);SRVR:BL2FFO11HUB030;BCL:0;PCL:0;RULEID:;SRVR:BL2FFO11HUB030; X-Forefront-PRVS: 06469BCC91 X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1;BL2FFO11HUB030;23:Ze6nAGZ1WO10awf+gkn1WjqttzQk2cR/jSmc+xa9?= =?us-ascii?Q?CHQqRsB+XFxhOHmyQNvzmBpbM9QUCJrr76q9C4FKr4aGp5OV+OtpE4Ax8tj7?= =?us-ascii?Q?7Glu1nlVz4z46HhAiJ2pFZtzZEjlabxoqod8DvgeHof5iV5GkhAoxU33dwBE?= =?us-ascii?Q?1LAflWGQitzr7C1dTkvYOXVYZg1B2rQH1K+l/Tw5qz515vU1m0em9xdmtShx?= =?us-ascii?Q?CQYFJw5G5OmfaW1qCNKnjS3f+bL2nTsi+KOgiUzsma7rBS43xPipe68+fNHY?= =?us-ascii?Q?3C9/QNcqBKlEnX08QnTOn21C9RW6zHzv7RUVJApBqJq/4j2irDaj4DTgKYdd?= =?us-ascii?Q?wjBc4GTHRMXA9QYzFLwNnQfpslplhcOki3P+CEIWY+6YA+XbA0bXfmxxUnhT?= =?us-ascii?Q?iQiDIdroooGFTCN11uH+niKaGr8zeXI4YKpPjb4Yp8F8UUedPm2MLiaZzv1o?= =?us-ascii?Q?6E/mjz4SteVj0cVegOA3RdA+Xo0FhayKPfKf/rhq6UMzZ1KhpB0NjgHrQ1s8?= =?us-ascii?Q?gSBPQaSYxqFAxx21JVCP/mNgRkZVnyGmqUeaMX8mQb5bYj4vgFLKZFRbgrBl?= =?us-ascii?Q?1IClqMIm7E9i6MLl7o8in5XlnmDaQ8n8heA0MqoxkaLpUYUV8TJqUyc/enKu?= =?us-ascii?Q?G/Cuv213xqvOvctzHN/IUKK64+k4Za0op+IkADV/GC0BbOEHwBr0gXc+uZuQ?= =?us-ascii?Q?ttIlhkjviDjSr82/HT2yZNmLG7FxQiKSluuu96r+ZJ/AHEja9YyhWQCLgpTy?= =?us-ascii?Q?SQegg9LRi6Qg55qDQCyqsULjE3q0Giu/Of8aC/JSVTtA5BmnEET4bhRoCQtt?= =?us-ascii?Q?IDpbN9dNbTsogvgszpMq24iTXOfamn+Zp2Z0BDCkha+FE5j1MJst9mMobGse?= =?us-ascii?Q?zpH3PDhqtkN0ohLUp+c+o9pBdJD5s4X4ZArkY7hMsb8MeXyPC5Y2H44vuCvo?= =?us-ascii?Q?iM3KDfmdLkJp5L1Q0jr5XAF7QAb6HB4NW2HVt/c2RqUQCHj2SX3l46JcEfCq?= =?us-ascii?Q?OXdGKQ4XJng4z4f6PFjr+pQdnxhp0XLgVUeH5gdOl29+RYDD7kOctDD2it2t?= =?us-ascii?Q?U+vpGw0nFo+Fgzotof5TUmzvoo5k?= X-Microsoft-Exchange-Diagnostics: 1;BL2FFO11HUB030;5:MZzU3DcS1ey1Ztp34RTXpl/BVHBRadrnmsd+fpWcUEZ7Z19bM/0siqehbXr86yRK899xD4UHfAVQGlubPXLz+oS7BNzAi88k1H5VcrZDJXU6FItYd4RVkCe4RH3Z8i/b5EA+66CWJXH3eh+4DDdpdg==;24:NH/zMw3gTpfytoNQa4NzOUFf4mwbFiW2kO3n3Z3KWTFNBWRvVEec8r3guNopJsbBJY7GMBkzDUJ7nCtv785rOivrtLcAFdaQkjBYc6NAgLM= X-OriginatorOrg: xilinx.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 Jul 2015 10:52:07.1989 (UTC) X-MS-Exchange-CrossTenant-Id: 657af505-d5df-48d0-8300-c31994686c5c X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=657af505-d5df-48d0-8300-c31994686c5c;Ip=[149.199.60.83];Helo=[xsj-pvapsmtpgw01] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL2FFO11HUB030 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 9110 Lines: 329 adds support for RTC controller found on Xilinx Zynq Ultrascale+ MPSoC platform. Signed-off-by: Suneel Garapati --- drivers/rtc/Kconfig | 7 ++ drivers/rtc/Makefile | 1 + drivers/rtc/rtc-zynqmp.c | 278 +++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 286 insertions(+) create mode 100644 drivers/rtc/rtc-zynqmp.c diff --git a/drivers/rtc/Kconfig b/drivers/rtc/Kconfig index e132ccb..e44705b 100644 --- a/drivers/rtc/Kconfig +++ b/drivers/rtc/Kconfig @@ -1116,6 +1116,13 @@ config RTC_DRV_OPAL This driver can also be built as a module. If so, the module will be called rtc-opal. +config RTC_DRV_ZYNQMP + tristate "Xilinx Zynq Ultrascale+ MPSoC RTC" + depends on OF + help + If you say yes here you get support for the RTC controller found on + Xilinx Zynq Ultrascale+ MPSoC. + comment "on-CPU RTC drivers" config RTC_DRV_DAVINCI diff --git a/drivers/rtc/Makefile b/drivers/rtc/Makefile index 2797384..e491eb5 100644 --- a/drivers/rtc/Makefile +++ b/drivers/rtc/Makefile @@ -159,3 +159,4 @@ obj-$(CONFIG_RTC_DRV_WM831X) += rtc-wm831x.o obj-$(CONFIG_RTC_DRV_WM8350) += rtc-wm8350.o obj-$(CONFIG_RTC_DRV_X1205) += rtc-x1205.o obj-$(CONFIG_RTC_DRV_XGENE) += rtc-xgene.o +obj-$(CONFIG_RTC_DRV_ZYNQMP) += rtc-zynqmp.o diff --git a/drivers/rtc/rtc-zynqmp.c b/drivers/rtc/rtc-zynqmp.c new file mode 100644 index 0000000..59018b7 --- /dev/null +++ b/drivers/rtc/rtc-zynqmp.c @@ -0,0 +1,278 @@ +/* + * Xilinx Zynq Ultrascale+ MPSoC Real Time Clock Driver + * + * Copyright (C) 2015 Xilinx, Inc. + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along with + * this program. If not, see . + * + */ + +#include +#include +#include +#include +#include +#include +#include + +/* RTC Registers */ +#define RTC_SET_TM_WR 0x00 +#define RTC_SET_TM_RD 0x04 +#define RTC_CALIB_WR 0x08 +#define RTC_CALIB_RD 0x0C +#define RTC_CUR_TM 0x10 +#define RTC_CUR_TICK 0x14 +#define RTC_ALRM 0x18 +#define RTC_INT_STS 0x20 +#define RTC_INT_MASK 0x24 +#define RTC_INT_EN 0x28 +#define RTC_INT_DIS 0x2C +#define RTC_CTRL 0x40 + +#define RTC_FR_EN BIT(20) +#define RTC_FR_DATSHIFT 16 +#define RTC_TICK_MASK 0xFFFF +#define RTC_INT_SEC BIT(0) +#define RTC_INT_ALRM BIT(1) +#define RTC_OSC_EN BIT(24) + +#define RTC_CALIB_DEF 0x198233 +#define RTC_CALIB_MASK 0x1FFFFF + +struct xlnx_rtc_dev { + struct rtc_device *rtc; + void __iomem *reg_base; + int alm_irq; + int sec_irq; +}; + +static int xlnx_rtc_set_time(struct device *dev, struct rtc_time *tm) +{ + struct xlnx_rtc_dev *xrtcdev = dev_get_drvdata(dev); + unsigned long new_time; + + rtc_tm_to_time(tm, &new_time); + writel(new_time, xrtcdev->reg_base + RTC_SET_TM_WR); + + return 0; +} + +static int xlnx_rtc_read_time(struct device *dev, struct rtc_time *tm) +{ + struct xlnx_rtc_dev *xrtcdev = dev_get_drvdata(dev); + + rtc_time_to_tm(readl(xrtcdev->reg_base + RTC_CUR_TM), tm); + + return rtc_valid_tm(tm); +} + +static int xlnx_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alrm) +{ + struct xlnx_rtc_dev *xrtcdev = dev_get_drvdata(dev); + + rtc_time_to_tm(readl(xrtcdev->reg_base + RTC_ALRM), &alrm->time); + alrm->enabled = readl(xrtcdev->reg_base + RTC_INT_MASK) & RTC_INT_ALRM; + + return 0; +} + +static int xlnx_rtc_alarm_irq_enable(struct device *dev, u32 enabled) +{ + struct xlnx_rtc_dev *xrtcdev = dev_get_drvdata(dev); + + if (enabled) + writel(RTC_INT_ALRM, xrtcdev->reg_base + RTC_INT_EN); + else + writel(RTC_INT_ALRM, xrtcdev->reg_base + RTC_INT_DIS); + + return 0; +} + +static int xlnx_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alrm) +{ + struct xlnx_rtc_dev *xrtcdev = dev_get_drvdata(dev); + unsigned long alarm_time; + + rtc_tm_to_time(&alrm->time, &alarm_time); + + writel((u32) alarm_time, (xrtcdev->reg_base + RTC_ALRM)); + + xlnx_rtc_alarm_irq_enable(dev, alrm->enabled); + + return 0; +} + +static void xlnx_init_rtc(struct xlnx_rtc_dev *xrtcdev, u32 calibval) +{ + /* + * Based on crystal freq of 33.330 KHz + * set the secounds counter and enable, set fractions counter + * to default value suggested as per design spec + * to correct RTC delay in frequency over period of time. + */ + calibval &= RTC_CALIB_MASK; + writel(calibval, (xrtcdev->reg_base + RTC_CALIB_WR)); +} + +static const struct rtc_class_ops xlnx_rtc_ops = { + .set_time = xlnx_rtc_set_time, + .read_time = xlnx_rtc_read_time, + .read_alarm = xlnx_rtc_read_alarm, + .set_alarm = xlnx_rtc_set_alarm, + .alarm_irq_enable = xlnx_rtc_alarm_irq_enable, +}; + +static irqreturn_t xlnx_rtc_interrupt(int irq, void *id) +{ + struct xlnx_rtc_dev *xrtcdev = (struct xlnx_rtc_dev *) id; + unsigned int status; + + status = readl(xrtcdev->reg_base + RTC_INT_STS); + /* Check if interrupt asserted */ + if (!(status & (RTC_INT_SEC | RTC_INT_ALRM))) + return IRQ_NONE; + + /* Clear interrupt */ + writel(status, xrtcdev->reg_base + RTC_INT_STS); + + if (status & RTC_INT_SEC) + rtc_update_irq(xrtcdev->rtc, 1, RTC_IRQF | RTC_UF); + if (status & RTC_INT_ALRM) + rtc_update_irq(xrtcdev->rtc, 1, RTC_IRQF | RTC_AF); + if (status & RTC_INT_ALRM) + printk("alarm interrupt\n"); + return IRQ_HANDLED; +} + +static int xlnx_rtc_probe(struct platform_device *pdev) +{ + struct xlnx_rtc_dev *xrtcdev; + struct resource *res; + int ret; + unsigned int calibvalue; + + xrtcdev = devm_kzalloc(&pdev->dev, sizeof(*xrtcdev), GFP_KERNEL); + if (!xrtcdev) + return -ENOMEM; + + platform_set_drvdata(pdev, xrtcdev); + + res = platform_get_resource(pdev, IORESOURCE_MEM, 0); + + xrtcdev->reg_base = devm_ioremap_resource(&pdev->dev, res); + if (IS_ERR(xrtcdev->reg_base)) + return PTR_ERR(xrtcdev->reg_base); + + xrtcdev->alm_irq = platform_get_irq_byname(pdev, "alm"); + if (xrtcdev->alm_irq < 0) { + dev_err(&pdev->dev, "no irq resource\n"); + return xrtcdev->alm_irq; + } + ret = devm_request_irq(&pdev->dev, xrtcdev->alm_irq, + xlnx_rtc_interrupt, 0, + dev_name(&pdev->dev), xrtcdev); + if (ret) { + dev_err(&pdev->dev, "request irq failed\n"); + return ret; + } + + xrtcdev->sec_irq = platform_get_irq_byname(pdev, "sec"); + if (xrtcdev->sec_irq < 0) { + dev_err(&pdev->dev, "no irq resource\n"); + return xrtcdev->sec_irq; + } + ret = devm_request_irq(&pdev->dev, xrtcdev->sec_irq, + xlnx_rtc_interrupt, 0, + dev_name(&pdev->dev), xrtcdev); + if (ret) { + dev_err(&pdev->dev, "request irq failed\n"); + return ret; + } + + ret = of_property_read_u32(pdev->dev.of_node, "calibration", + &calibvalue); + if (ret) + calibvalue = RTC_CALIB_DEF; + + xlnx_init_rtc(xrtcdev, calibvalue); + + device_init_wakeup(&pdev->dev, 1); + + xrtcdev->rtc = devm_rtc_device_register(&pdev->dev, pdev->name, + &xlnx_rtc_ops, THIS_MODULE); + if (IS_ERR(xrtcdev->rtc)) { + return PTR_ERR(xrtcdev->rtc); + } + + return 0; +} + +static int xlnx_rtc_remove(struct platform_device *pdev) +{ + xlnx_rtc_alarm_irq_enable(&pdev->dev, 0); + device_init_wakeup(&pdev->dev, 0); + + return 0; +} + +static int __maybe_unused xlnx_rtc_suspend(struct device *dev) +{ + struct platform_device *pdev = to_platform_device(dev); + struct xlnx_rtc_dev *xrtcdev = platform_get_drvdata(pdev); + + if (device_may_wakeup(&pdev->dev)) { + enable_irq_wake(xrtcdev->alm_irq); + } else { + xlnx_rtc_alarm_irq_enable(dev, 0); + } + + return 0; +} + +static int __maybe_unused xlnx_rtc_resume(struct device *dev) +{ + struct platform_device *pdev = to_platform_device(dev); + struct xlnx_rtc_dev *xrtcdev = platform_get_drvdata(pdev); + + if (device_may_wakeup(&pdev->dev)) { + disable_irq_wake(xrtcdev->alm_irq); + } else { + xlnx_rtc_alarm_irq_enable(dev, 1); + } + + return 0; +} + +static SIMPLE_DEV_PM_OPS(xlnx_rtc_pm_ops, xlnx_rtc_suspend, xlnx_rtc_resume); + +static const struct of_device_id xlnx_rtc_of_match[] = { + {.compatible = "xlnx,zynqmp-rtc" }, + { } +}; +MODULE_DEVICE_TABLE(of, xlnx_rtc_of_match); + +static struct platform_driver xlnx_rtc_driver = { + .probe = xlnx_rtc_probe, + .remove = xlnx_rtc_remove, + .driver = { + .name = KBUILD_MODNAME, + .pm = &xlnx_rtc_pm_ops, + .of_match_table = xlnx_rtc_of_match, + }, +}; + +module_platform_driver(xlnx_rtc_driver); + +MODULE_DESCRIPTION("Xilinx Zynq MPSoC RTC driver"); +MODULE_AUTHOR("Xilinx Inc."); +MODULE_LICENSE("GPL v2"); -- 2.1.2 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/