From: wefu@redhat.com
To: jszhang@kernel.org, alexandre.belloni@bootlin.com,
robh@kernel.org, krzysztof.kozlowski+dt@linaro.org,
conor+dt@kernel.org, guoren@kernel.org, paul.walmsley@sifive.com,
palmer@dabbelt.com, aou@eecs.berkeley.edu
Cc: linux-riscv@lists.infradead.org, devicetree@vger.kernel.org,
linux-kernel@vger.kernel.org, linux-rtc@vger.kernel.org,
Wei Fu <wefu@redhat.com>
Subject: [PATCH 1/5] drivers/rtc/rtc-xgene: Add prescaler support in APM X-Gene RTC driver
Date: Fri, 12 Apr 2024 16:01:43 +0800 [thread overview]
Message-ID: <20240412080238.134191-2-wefu@redhat.com> (raw)
In-Reply-To: <20240412080238.134191-1-wefu@redhat.com>
From: Wei Fu <wefu@redhat.com>
This patch add Counter Prescaler support in APM X-Gene RTC driver by
getting prescaler (Optional) property value from dtb.
Signed-off-by: Wei Fu <wefu@redhat.com>
---
drivers/rtc/Kconfig | 10 ++++++++++
drivers/rtc/rtc-xgene.c | 31 +++++++++++++++++++++++++++++++
2 files changed, 41 insertions(+)
diff --git a/drivers/rtc/Kconfig b/drivers/rtc/Kconfig
index c63e32d012f2..3a89f1e6095d 100644
--- a/drivers/rtc/Kconfig
+++ b/drivers/rtc/Kconfig
@@ -1888,6 +1888,16 @@ config RTC_DRV_XGENE
This driver can also be built as a module, if so, the module
will be called "rtc-xgene".
+config RTC_DRV_XGENE_PRESCALER
+ bool "Pre-scaler Counter support for APM X-Gene RTC driver"
+ depends on RTC_DRV_XGENE
+ depends on ARCH_THEAD
+ default y
+ help
+ Say Y here if your Soc has Pre-scaler Counter support on rtc-xgene.
+
+ This hardware support can only be found in DW_apb_rtc after v2.06a.
+
config RTC_DRV_PIC32
tristate "Microchip PIC32 RTC"
depends on MACH_PIC32
diff --git a/drivers/rtc/rtc-xgene.c b/drivers/rtc/rtc-xgene.c
index f78efc9760c0..4d6f1629b973 100644
--- a/drivers/rtc/rtc-xgene.c
+++ b/drivers/rtc/rtc-xgene.c
@@ -26,11 +26,13 @@
#define RTC_CCR_MASK BIT(1)
#define RTC_CCR_EN BIT(2)
#define RTC_CCR_WEN BIT(3)
+#define RTC_CCR_PSCLR_EN BIT(4)
#define RTC_STAT 0x10
#define RTC_STAT_BIT BIT(0)
#define RTC_RSTAT 0x14
#define RTC_EOI 0x18
#define RTC_VER 0x1C
+#define RTC_CPSR 0x20
struct xgene_rtc_dev {
struct rtc_device *rtc;
@@ -40,6 +42,33 @@ struct xgene_rtc_dev {
unsigned int irq_enabled;
};
+static void xgene_rtc_set_prescaler(struct device *dev)
+{
+#ifdef CONFIG_RTC_DRV_XGENE_PRESCALER
+ u32 ccr;
+ u32 prescaler;
+ struct xgene_rtc_dev *pdata = dev_get_drvdata(dev);
+
+ if (device_property_read_u32(dev, "prescaler", &prescaler)) {
+ dev_warn(dev, "Missing the pre-scaler config for RTC.\n");
+ dev_warn(dev, "The current pre-scaler config is 0x%x.\n",
+ readl(pdata->csr_base + RTC_CPSR));
+ return;
+ }
+
+ /* The clock source on some platform to RTC is NOT 1HZ,
+ * so we need to prescale the clock to make the input clock become 1HZ,
+ * like (clock_source/prescaler) = 1HZ
+ */
+ writel(prescaler, pdata->csr_base + RTC_CPSR);
+
+ /* enable RTC Prescaler feature in CCR register */
+ ccr = readl(pdata->csr_base + RTC_CCR);
+ ccr |= RTC_CCR_PSCLR_EN;
+ writel(ccr, pdata->csr_base + RTC_CCR);
+#endif /* CONFIG_RTC_DRV_XGENE_PRESCALER */
+}
+
static int xgene_rtc_read_time(struct device *dev, struct rtc_time *tm)
{
struct xgene_rtc_dev *pdata = dev_get_drvdata(dev);
@@ -174,6 +203,8 @@ static int xgene_rtc_probe(struct platform_device *pdev)
/* Turn on the clock and the crystal */
writel(RTC_CCR_EN, pdata->csr_base + RTC_CCR);
+ xgene_rtc_set_prescaler(&pdev->dev);
+
ret = device_init_wakeup(&pdev->dev, 1);
if (ret) {
clk_disable_unprepare(pdata->clk);
--
2.44.0
WARNING: multiple messages have this Message-ID (diff)
From: wefu@redhat.com
To: jszhang@kernel.org, alexandre.belloni@bootlin.com,
robh@kernel.org, krzysztof.kozlowski+dt@linaro.org,
conor+dt@kernel.org, guoren@kernel.org, paul.walmsley@sifive.com,
palmer@dabbelt.com, aou@eecs.berkeley.edu
Cc: linux-riscv@lists.infradead.org, devicetree@vger.kernel.org,
linux-kernel@vger.kernel.org, linux-rtc@vger.kernel.org,
Wei Fu <wefu@redhat.com>
Subject: [PATCH 1/5] drivers/rtc/rtc-xgene: Add prescaler support in APM X-Gene RTC driver
Date: Fri, 12 Apr 2024 16:01:43 +0800 [thread overview]
Message-ID: <20240412080238.134191-2-wefu@redhat.com> (raw)
In-Reply-To: <20240412080238.134191-1-wefu@redhat.com>
From: Wei Fu <wefu@redhat.com>
This patch add Counter Prescaler support in APM X-Gene RTC driver by
getting prescaler (Optional) property value from dtb.
Signed-off-by: Wei Fu <wefu@redhat.com>
---
drivers/rtc/Kconfig | 10 ++++++++++
drivers/rtc/rtc-xgene.c | 31 +++++++++++++++++++++++++++++++
2 files changed, 41 insertions(+)
diff --git a/drivers/rtc/Kconfig b/drivers/rtc/Kconfig
index c63e32d012f2..3a89f1e6095d 100644
--- a/drivers/rtc/Kconfig
+++ b/drivers/rtc/Kconfig
@@ -1888,6 +1888,16 @@ config RTC_DRV_XGENE
This driver can also be built as a module, if so, the module
will be called "rtc-xgene".
+config RTC_DRV_XGENE_PRESCALER
+ bool "Pre-scaler Counter support for APM X-Gene RTC driver"
+ depends on RTC_DRV_XGENE
+ depends on ARCH_THEAD
+ default y
+ help
+ Say Y here if your Soc has Pre-scaler Counter support on rtc-xgene.
+
+ This hardware support can only be found in DW_apb_rtc after v2.06a.
+
config RTC_DRV_PIC32
tristate "Microchip PIC32 RTC"
depends on MACH_PIC32
diff --git a/drivers/rtc/rtc-xgene.c b/drivers/rtc/rtc-xgene.c
index f78efc9760c0..4d6f1629b973 100644
--- a/drivers/rtc/rtc-xgene.c
+++ b/drivers/rtc/rtc-xgene.c
@@ -26,11 +26,13 @@
#define RTC_CCR_MASK BIT(1)
#define RTC_CCR_EN BIT(2)
#define RTC_CCR_WEN BIT(3)
+#define RTC_CCR_PSCLR_EN BIT(4)
#define RTC_STAT 0x10
#define RTC_STAT_BIT BIT(0)
#define RTC_RSTAT 0x14
#define RTC_EOI 0x18
#define RTC_VER 0x1C
+#define RTC_CPSR 0x20
struct xgene_rtc_dev {
struct rtc_device *rtc;
@@ -40,6 +42,33 @@ struct xgene_rtc_dev {
unsigned int irq_enabled;
};
+static void xgene_rtc_set_prescaler(struct device *dev)
+{
+#ifdef CONFIG_RTC_DRV_XGENE_PRESCALER
+ u32 ccr;
+ u32 prescaler;
+ struct xgene_rtc_dev *pdata = dev_get_drvdata(dev);
+
+ if (device_property_read_u32(dev, "prescaler", &prescaler)) {
+ dev_warn(dev, "Missing the pre-scaler config for RTC.\n");
+ dev_warn(dev, "The current pre-scaler config is 0x%x.\n",
+ readl(pdata->csr_base + RTC_CPSR));
+ return;
+ }
+
+ /* The clock source on some platform to RTC is NOT 1HZ,
+ * so we need to prescale the clock to make the input clock become 1HZ,
+ * like (clock_source/prescaler) = 1HZ
+ */
+ writel(prescaler, pdata->csr_base + RTC_CPSR);
+
+ /* enable RTC Prescaler feature in CCR register */
+ ccr = readl(pdata->csr_base + RTC_CCR);
+ ccr |= RTC_CCR_PSCLR_EN;
+ writel(ccr, pdata->csr_base + RTC_CCR);
+#endif /* CONFIG_RTC_DRV_XGENE_PRESCALER */
+}
+
static int xgene_rtc_read_time(struct device *dev, struct rtc_time *tm)
{
struct xgene_rtc_dev *pdata = dev_get_drvdata(dev);
@@ -174,6 +203,8 @@ static int xgene_rtc_probe(struct platform_device *pdev)
/* Turn on the clock and the crystal */
writel(RTC_CCR_EN, pdata->csr_base + RTC_CCR);
+ xgene_rtc_set_prescaler(&pdev->dev);
+
ret = device_init_wakeup(&pdev->dev, 1);
if (ret) {
clk_disable_unprepare(pdata->clk);
--
2.44.0
_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv
next prev parent reply other threads:[~2024-04-12 8:02 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-04-12 8:01 [PATCH 0/5] RTC: update APM X-Gene RTC driver by adding the pre-scaler support wefu
2024-04-12 8:01 ` wefu
2024-04-12 8:01 ` wefu [this message]
2024-04-12 8:01 ` [PATCH 1/5] drivers/rtc/rtc-xgene: Add prescaler support in APM X-Gene RTC driver wefu
2024-04-12 8:23 ` Alexandre Belloni
2024-04-12 8:23 ` Alexandre Belloni
2024-04-12 8:01 ` [PATCH 2/5] dt-bindings: rtc: Add optional property "prescaler" in APM X-Gene RTC Document wefu
2024-04-12 8:01 ` wefu
2024-04-12 8:20 ` Alexandre Belloni
2024-04-12 8:20 ` Alexandre Belloni
2024-04-12 8:01 ` [PATCH 3/5] drivers/rtc/rtc-xgene: Add "snps,dw-apb-rtc" into the "compatible" wefu
2024-04-12 8:01 ` wefu
2024-04-12 9:17 ` Krzysztof Kozlowski
2024-04-12 9:17 ` Krzysztof Kozlowski
2024-04-12 9:39 ` Conor Dooley
2024-04-12 9:39 ` Conor Dooley
2024-04-12 8:01 ` [PATCH 4/5] Kconfig: Enable APM X-Gene RTC for XuanTie TH1520 wefu
2024-04-12 8:01 ` wefu
2024-04-12 9:47 ` Conor Dooley
2024-04-12 9:47 ` Conor Dooley
2024-04-12 8:01 ` [PATCH 5/5] riscv: dts: thead: Add XuanTie TH1520 RTC device node wefu
2024-04-12 8:01 ` wefu
2024-04-12 8:21 ` Alexandre Belloni
2024-04-12 8:21 ` Alexandre Belloni
2024-04-12 9:19 ` Krzysztof Kozlowski
2024-04-12 9:19 ` Krzysztof Kozlowski
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240412080238.134191-2-wefu@redhat.com \
--to=wefu@redhat.com \
--cc=alexandre.belloni@bootlin.com \
--cc=aou@eecs.berkeley.edu \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=guoren@kernel.org \
--cc=jszhang@kernel.org \
--cc=krzysztof.kozlowski+dt@linaro.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-riscv@lists.infradead.org \
--cc=linux-rtc@vger.kernel.org \
--cc=palmer@dabbelt.com \
--cc=paul.walmsley@sifive.com \
--cc=robh@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.