* [PATCH] rtc: ds1307: add OF and ACPI entries for Epson RX8130
From: Bastian Stender @ 2017-10-17 12:46 UTC (permalink / raw)
To: rtc-linux
Cc: Marek Vasut, Alexandre Belloni, Arnd Bergmann, Felipe Balbi,
Nishanth Menon, Tony Lindgren, kernel, Bastian Stender
Make Epson RX8130 device tree and ACPI aware.
Fixes: ee0981be7704 ("rtc: ds1307: Add support for Epson RX8130CE")
Signed-off-by: Bastian Stender <bst@pengutronix.de>
---
drivers/rtc/rtc-ds1307.c | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/drivers/rtc/rtc-ds1307.c b/drivers/rtc/rtc-ds1307.c
index e7d9215c9201..8e2cd45a2f96 100644
--- a/drivers/rtc/rtc-ds1307.c
+++ b/drivers/rtc/rtc-ds1307.c
@@ -325,6 +325,10 @@ static const struct of_device_id ds1307_of_match[] = {
.compatible = "isil,isl12057",
.data = (void *)ds_1337
},
+ {
+ .compatible = "epson,rx8130",
+ .data = (void *)rx_8130
+ },
{ }
};
MODULE_DEVICE_TABLE(of, ds1307_of_match);
@@ -348,6 +352,7 @@ static const struct acpi_device_id ds1307_acpi_ids[] = {
{ .id = "PT7C4338", .driver_data = ds_1307 },
{ .id = "RX8025", .driver_data = rx_8025 },
{ .id = "ISL12057", .driver_data = ds_1337 },
+ { .id = "RX8130", .driver_data = rx_8130 },
{ }
};
MODULE_DEVICE_TABLE(acpi, ds1307_acpi_ids);
--
2.11.0
^ permalink raw reply related
* [PATCH v2 1/4] dt-bindings: rtc: mediatek: add bindings for MediaTek SoC based RTC
From: sean.wang @ 2017-10-17 9:40 UTC (permalink / raw)
To: a.zummo, alexandre.belloni, robh+dt, mark.rutland
Cc: linux-rtc, devicetree, linux-mediatek, linux-kernel, Sean Wang
In-Reply-To: <cover.1508231935.git.sean.wang@mediatek.com>
From: Sean Wang <sean.wang@mediatek.com>
Add device-tree binding for MediaTek SoC based RTC
Cc: devicetree@vger.kernel.org
Signed-off-by: Sean Wang <sean.wang@mediatek.com>
Acked-by: Rob Herring <robh@kernel.org>
---
.../devicetree/bindings/rtc/rtc-mediatek.txt | 21 +++++++++++++++++++++
1 file changed, 21 insertions(+)
create mode 100644 Documentation/devicetree/bindings/rtc/rtc-mediatek.txt
diff --git a/Documentation/devicetree/bindings/rtc/rtc-mediatek.txt b/Documentation/devicetree/bindings/rtc/rtc-mediatek.txt
new file mode 100644
index 0000000..09fe8f5
--- /dev/null
+++ b/Documentation/devicetree/bindings/rtc/rtc-mediatek.txt
@@ -0,0 +1,21 @@
+Device-Tree bindings for MediaTek SoC based RTC
+
+Required properties:
+- compatible : Should be
+ "mediatek,mt7622-rtc", "mediatek,soc-rtc" : for MT7622 SoC
+- reg : Specifies base physical address and size of the registers;
+- interrupts : Should contain the interrupt for RTC alarm;
+- clocks : Specifies list of clock specifiers, corresponding to
+ entries in clock-names property;
+- clock-names : Should contain "rtc" entries
+
+Example:
+
+rtc: rtc@10212800 {
+ compatible = "mediatek,mt7622-rtc",
+ "mediatek,soc-rtc";
+ reg = <0 0x10212800 0 0x200>;
+ interrupts = <GIC_SPI 129 IRQ_TYPE_LEVEL_LOW>;
+ clocks = <&topckgen CLK_TOP_RTC>;
+ clock-names = "rtc";
+};
--
2.7.4
^ permalink raw reply related
* [PATCH v2 3/4] rtc: mediatek: enhance the description for MediaTek PMIC based RTC
From: sean.wang @ 2017-10-17 9:40 UTC (permalink / raw)
To: a.zummo, alexandre.belloni, robh+dt, mark.rutland
Cc: linux-rtc, devicetree, linux-mediatek, linux-kernel, Sean Wang,
Eddie Huang
In-Reply-To: <cover.1508231935.git.sean.wang@mediatek.com>
From: Sean Wang <sean.wang@mediatek.com>
Give a better description for original MediaTek RTC driver as PMIC based
RTC in order to distinguish SoC based RTC. Also turning all words with
Mediatek to MediaTek here.
Cc: Eddie Huang <eddie.huang@mediatek.com>
Signed-off-by: Sean Wang <sean.wang@mediatek.com>
Acked-by: Eddie Huang <eddie.huang@mediatek.com>
---
drivers/rtc/Kconfig | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/drivers/rtc/Kconfig b/drivers/rtc/Kconfig
index 4226295..4500f77 100644
--- a/drivers/rtc/Kconfig
+++ b/drivers/rtc/Kconfig
@@ -1716,14 +1716,14 @@ config RTC_DRV_MEDIATEK
will be called rtc-mediatek.
config RTC_DRV_MT6397
- tristate "Mediatek Real Time Clock driver"
+ tristate "MediaTek PMIC based RTC"
depends on MFD_MT6397 || (COMPILE_TEST && IRQ_DOMAIN)
help
- This selects the Mediatek(R) RTC driver. RTC is part of Mediatek
+ This selects the MediaTek(R) RTC driver. RTC is part of MediaTek
MT6397 PMIC. You should enable MT6397 PMIC MFD before select
- Mediatek(R) RTC driver.
+ MediaTek(R) RTC driver.
- If you want to use Mediatek(R) RTC interface, select Y or M here.
+ If you want to use MediaTek(R) RTC interface, select Y or M here.
config RTC_DRV_XGENE
tristate "APM X-Gene RTC"
--
2.7.4
^ permalink raw reply related
* [PATCH v2 4/4] rtc: mediatek: update MAINTAINERS entry with MediaTek RTC driver
From: sean.wang @ 2017-10-17 9:40 UTC (permalink / raw)
To: a.zummo, alexandre.belloni, robh+dt, mark.rutland
Cc: linux-rtc, devicetree, linux-mediatek, linux-kernel, Sean Wang,
Eddie Huang
In-Reply-To: <cover.1508231935.git.sean.wang@mediatek.com>
From: Sean Wang <sean.wang@mediatek.com>
I work for MediaTek on maintaining the MediaTek SoC based RTC driver for
the existing SoCs and keep adding support for the following SoCs in the
future.
Cc: Eddie Huang <eddie.huang@mediatek.com>
Signed-off-by: Sean Wang <sean.wang@mediatek.com>
---
MAINTAINERS | 3 +++
1 file changed, 3 insertions(+)
diff --git a/MAINTAINERS b/MAINTAINERS
index 2281af4..5142029 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -1579,10 +1579,13 @@ F: drivers/rtc/rtc-armada38x.c
ARM/Mediatek RTC DRIVER
M: Eddie Huang <eddie.huang@mediatek.com>
+M: Sean Wang <sean.wang@mediatek.com>
L: linux-arm-kernel@lists.infradead.org (moderated for non-subscribers)
L: linux-mediatek@lists.infradead.org (moderated for non-subscribers)
S: Maintained
+F: Documentation/devicetree/bindings/rtc/rtc-mediatek.txt
F: drivers/rtc/rtc-mt6397.c
+F: drivers/rtc/rtc-mt7622.c
ARM/Mediatek SoC support
M: Matthias Brugger <matthias.bgg@gmail.com>
--
2.7.4
^ permalink raw reply related
* [PATCH v2 2/4] rtc: mediatek: add driver for RTC on MT7622 SoC
From: sean.wang @ 2017-10-17 9:40 UTC (permalink / raw)
To: a.zummo, alexandre.belloni, robh+dt, mark.rutland
Cc: linux-rtc, devicetree, linux-mediatek, linux-kernel, Sean Wang
In-Reply-To: <cover.1508231935.git.sean.wang@mediatek.com>
From: Sean Wang <sean.wang@mediatek.com>
This patch introduces the driver for the RTC on MT7622 SoC.
Signed-off-by: Sean Wang <sean.wang@mediatek.com>
---
drivers/rtc/Kconfig | 10 ++
drivers/rtc/Makefile | 1 +
drivers/rtc/rtc-mt7622.c | 418 +++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 429 insertions(+)
create mode 100644 drivers/rtc/rtc-mt7622.c
diff --git a/drivers/rtc/Kconfig b/drivers/rtc/Kconfig
index e0e58f3..4226295 100644
--- a/drivers/rtc/Kconfig
+++ b/drivers/rtc/Kconfig
@@ -1705,6 +1705,16 @@ config RTC_DRV_MOXART
This driver can also be built as a module. If so, the module
will be called rtc-moxart
+config RTC_DRV_MEDIATEK
+ tristate "MediaTek SoC based RTC"
+ depends on ARCH_MEDIATEK || COMPILE_TEST
+ help
+ This enables support for the real time clock built in the MediaTek
+ SoCs.
+
+ This drive can also be built as a module. If so, the module
+ will be called rtc-mediatek.
+
config RTC_DRV_MT6397
tristate "Mediatek Real Time Clock driver"
depends on MFD_MT6397 || (COMPILE_TEST && IRQ_DOMAIN)
diff --git a/drivers/rtc/Makefile b/drivers/rtc/Makefile
index 7230014..593a02c 100644
--- a/drivers/rtc/Makefile
+++ b/drivers/rtc/Makefile
@@ -101,6 +101,7 @@ obj-$(CONFIG_RTC_DRV_MOXART) += rtc-moxart.o
obj-$(CONFIG_RTC_DRV_MPC5121) += rtc-mpc5121.o
obj-$(CONFIG_RTC_DRV_VRTC) += rtc-mrst.o
obj-$(CONFIG_RTC_DRV_MSM6242) += rtc-msm6242.o
+obj-$(CONFIG_RTC_DRV_MEDIATEK) += rtc-mt7622.o
obj-$(CONFIG_RTC_DRV_MT6397) += rtc-mt6397.o
obj-$(CONFIG_RTC_DRV_MV) += rtc-mv.o
obj-$(CONFIG_RTC_DRV_MXC) += rtc-mxc.o
diff --git a/drivers/rtc/rtc-mt7622.c b/drivers/rtc/rtc-mt7622.c
new file mode 100644
index 0000000..1f00494
--- /dev/null
+++ b/drivers/rtc/rtc-mt7622.c
@@ -0,0 +1,418 @@
+/*
+ * Driver for MediaTek SoC based RTC
+ *
+ * Copyright (C) 2017 Sean Wang <sean.wang@mediatek.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of
+ * the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that 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.
+ */
+
+#include <linux/clk.h>
+#include <linux/interrupt.h>
+#include <linux/module.h>
+#include <linux/of_address.h>
+#include <linux/of_device.h>
+#include <linux/platform_device.h>
+#include <linux/rtc.h>
+
+#define MTK_RTC_DEV KBUILD_MODNAME
+
+#define MTK_RTC_PWRCHK1 0x4
+#define RTC_PWRCHK1_MAGIC 0xc6
+
+#define MTK_RTC_PWRCHK2 0x8
+#define RTC_PWRCHK2_MAGIC 0x9a
+
+#define MTK_RTC_KEY 0xc
+#define RTC_KEY_MAGIC 0x59
+
+#define MTK_RTC_PROT1 0x10
+#define RTC_PROT1_MAGIC 0xa3
+
+#define MTK_RTC_PROT2 0x14
+#define RTC_PROT2_MAGIC 0x57
+
+#define MTK_RTC_PROT3 0x18
+#define RTC_PROT3_MAGIC 0x67
+
+#define MTK_RTC_PROT4 0x1c
+#define RTC_PROT4_MAGIC 0xd2
+
+#define MTK_RTC_CTL 0x20
+#define RTC_RC_STOP BIT(0)
+
+#define MTK_RTC_DEBNCE 0x2c
+#define RTC_DEBNCE_MASK GENMASK(2, 0)
+
+#define MTK_RTC_INT 0x30
+#define RTC_INT_AL_STA BIT(4)
+
+/* Ranges from 0x40 to 0x78 provide RTC time setup for year, month,
+ * day of month, day of week, hour, minute and second.
+ */
+#define MTK_RTC_TREG(_t, _f) (0x40 + (0x4 * (_f)) + ((_t) * 0x20))
+
+#define MTK_RTC_AL_CTL 0x7c
+#define RTC_AL_EN BIT(0)
+#define RTC_AL_ALL GENMASK(7, 0)
+
+#define MTK_RTC_TM_YR_L 100
+
+/* The maximum years the RTC can support is 99, For MT7622 */
+#define MTK_RTC_HW_YR_LIMIT 100
+
+/* Types of the function the RTC provides are time counter and alarm. */
+enum {
+ MTK_TC,
+ MTK_AL,
+ MTK_TYPE_MAX,
+};
+
+/* Indexes are used for the pointer to relevant registers in MTK_RTC_TREG */
+enum {
+ MTK_YEA,
+ MTK_MON,
+ MTK_DOM,
+ MTK_DOW,
+ MTK_HOU,
+ MTK_MIN,
+ MTK_SEC
+};
+
+struct mtk_rtc {
+ struct rtc_device *rtc;
+ void __iomem *base;
+ int irq;
+ struct clk *clk;
+ u32 yr_base[MTK_TYPE_MAX];
+};
+
+static void mtk_w32(struct mtk_rtc *rtc, u32 reg, u32 val)
+{
+ writel_relaxed(val, rtc->base + reg);
+}
+
+static u32 mtk_r32(struct mtk_rtc *rtc, u32 reg)
+{
+ return readl_relaxed(rtc->base + reg);
+}
+
+static void mtk_rmw(struct mtk_rtc *rtc, u32 reg, u32 mask, u32 set)
+{
+ u32 val;
+
+ val = mtk_r32(rtc, reg);
+ val &= ~mask;
+ val |= set;
+ mtk_w32(rtc, reg, val);
+}
+
+static void mtk_set(struct mtk_rtc *rtc, u32 reg, u32 val)
+{
+ mtk_rmw(rtc, reg, 0, val);
+}
+
+static void mtk_clr(struct mtk_rtc *rtc, u32 reg, u32 val)
+{
+ mtk_rmw(rtc, reg, val, 0);
+}
+
+static void mtk_rtc_hw_init(struct mtk_rtc *hw)
+{
+ /* The setup of the init sequence is for allowing RTC got to work */
+ mtk_w32(hw, MTK_RTC_PWRCHK1, RTC_PWRCHK1_MAGIC);
+ mtk_w32(hw, MTK_RTC_PWRCHK2, RTC_PWRCHK2_MAGIC);
+ mtk_w32(hw, MTK_RTC_KEY, RTC_KEY_MAGIC);
+ mtk_w32(hw, MTK_RTC_PROT1, RTC_PROT1_MAGIC);
+ mtk_w32(hw, MTK_RTC_PROT2, RTC_PROT2_MAGIC);
+ mtk_w32(hw, MTK_RTC_PROT3, RTC_PROT3_MAGIC);
+ mtk_w32(hw, MTK_RTC_PROT4, RTC_PROT4_MAGIC);
+ mtk_rmw(hw, MTK_RTC_DEBNCE, RTC_DEBNCE_MASK, 0);
+ mtk_clr(hw, MTK_RTC_CTL, RTC_RC_STOP);
+}
+
+static void mtk_rtc_get_alarm_or_time(struct mtk_rtc *hw, struct rtc_time *tm,
+ int time_alarm)
+{
+ u32 year, mon, mday, wday, hour, min, sec;
+
+ /*
+ * Read again until the field of the second is not changed which
+ * ensures all fields in the consistent state.
+ */
+ do {
+ year = mtk_r32(hw, MTK_RTC_TREG(time_alarm, MTK_YEA));
+ mon = mtk_r32(hw, MTK_RTC_TREG(time_alarm, MTK_MON));
+ wday = mtk_r32(hw, MTK_RTC_TREG(time_alarm, MTK_DOW));
+ mday = mtk_r32(hw, MTK_RTC_TREG(time_alarm, MTK_DOM));
+ hour = mtk_r32(hw, MTK_RTC_TREG(time_alarm, MTK_HOU));
+ min = mtk_r32(hw, MTK_RTC_TREG(time_alarm, MTK_MIN));
+ sec = mtk_r32(hw, MTK_RTC_TREG(time_alarm, MTK_SEC));
+ } while (sec != mtk_r32(hw, MTK_RTC_TREG(time_alarm, MTK_SEC)));
+
+ tm->tm_sec = sec;
+ tm->tm_min = min;
+ tm->tm_hour = hour;
+ tm->tm_wday = wday;
+ tm->tm_mday = mday;
+ tm->tm_mon = mon - 1;
+
+ /* Rebase to the absolute year which userspace requires */
+ tm->tm_year = year + MTK_RTC_TM_YR_L + hw->yr_base[time_alarm];
+}
+
+static void mtk_rtc_set_alarm_or_time(struct mtk_rtc *hw, struct rtc_time *tm,
+ int time_alarm)
+{
+ u32 year;
+
+ /* Rebase to the relative year which RTC hardware requires */
+ year = tm->tm_year - MTK_RTC_TM_YR_L - hw->yr_base[time_alarm];
+
+ mtk_w32(hw, MTK_RTC_TREG(time_alarm, MTK_YEA), year);
+ mtk_w32(hw, MTK_RTC_TREG(time_alarm, MTK_MON), tm->tm_mon + 1);
+ mtk_w32(hw, MTK_RTC_TREG(time_alarm, MTK_DOW), tm->tm_wday);
+ mtk_w32(hw, MTK_RTC_TREG(time_alarm, MTK_DOM), tm->tm_mday);
+ mtk_w32(hw, MTK_RTC_TREG(time_alarm, MTK_HOU), tm->tm_hour);
+ mtk_w32(hw, MTK_RTC_TREG(time_alarm, MTK_MIN), tm->tm_min);
+ mtk_w32(hw, MTK_RTC_TREG(time_alarm, MTK_SEC), tm->tm_sec);
+}
+
+static irqreturn_t mtk_rtc_alarmirq(int irq, void *id)
+{
+ struct mtk_rtc *hw = (struct mtk_rtc *)id;
+ u32 irq_sta;
+
+ irq_sta = mtk_r32(hw, MTK_RTC_INT);
+ if (irq_sta & RTC_INT_AL_STA) {
+ /* Stop alarm also implicitly disables the alarm interrupt */
+ mtk_w32(hw, MTK_RTC_AL_CTL, 0);
+ rtc_update_irq(hw->rtc, 1, RTC_IRQF | RTC_AF);
+
+ /* Ack alarm interrupt status */
+ mtk_w32(hw, MTK_RTC_INT, RTC_INT_AL_STA);
+ return IRQ_HANDLED;
+ }
+
+ return IRQ_NONE;
+}
+
+static int mtk_rtc_gettime(struct device *dev, struct rtc_time *tm)
+{
+ struct mtk_rtc *hw = dev_get_drvdata(dev);
+
+ mtk_rtc_get_alarm_or_time(hw, tm, MTK_TC);
+
+ return rtc_valid_tm(tm);
+}
+
+static int mtk_rtc_settime(struct device *dev, struct rtc_time *tm)
+{
+ struct mtk_rtc *hw = dev_get_drvdata(dev);
+
+ /* Epoch == 1900, and the driver assumes that tm->tm_year has to be
+ * at least MTK_RTC_TM_YR_L.
+ */
+ if (tm->tm_year < MTK_RTC_TM_YR_L)
+ return -EINVAL;
+
+ /* Keep yr_base used to calculate the calculate year when userspace
+ * queries and extend the maximum year the RTC can count.
+ */
+ hw->yr_base[MTK_TC] = tm->tm_year - MTK_RTC_TM_YR_L -
+ (tm->tm_year % MTK_RTC_HW_YR_LIMIT);
+
+ /* Stop time counter before setting a new one*/
+ mtk_set(hw, MTK_RTC_CTL, RTC_RC_STOP);
+
+ mtk_rtc_set_alarm_or_time(hw, tm, MTK_TC);
+
+ /* Restart the time counter */
+ mtk_clr(hw, MTK_RTC_CTL, RTC_RC_STOP);
+
+ return 0;
+}
+
+static int mtk_rtc_getalarm(struct device *dev, struct rtc_wkalrm *wkalrm)
+{
+ struct mtk_rtc *hw = dev_get_drvdata(dev);
+ struct rtc_time *alrm_tm = &wkalrm->time;
+
+ mtk_rtc_get_alarm_or_time(hw, alrm_tm, MTK_AL);
+
+ wkalrm->enabled = !!(mtk_r32(hw, MTK_RTC_AL_CTL) & RTC_AL_EN);
+ wkalrm->pending = !!(mtk_r32(hw, MTK_RTC_INT) & RTC_INT_AL_STA);
+
+ return 0;
+}
+
+static int mtk_rtc_setalarm(struct device *dev, struct rtc_wkalrm *wkalrm)
+{
+ struct mtk_rtc *hw = dev_get_drvdata(dev);
+ struct rtc_time *alrm_tm = &wkalrm->time;
+
+ /* Epoch == 1900, and the driver assumes that alrm_tm->tm_year has to
+ * be at least MTK_RTC_TM_YR_L.
+ */
+ if (alrm_tm->tm_year < MTK_RTC_TM_YR_L)
+ return -EINVAL;
+
+ /* Keep yr_base used to calculate the calculate year when userspace
+ * queries and extend the maximum time the alarm can support.
+ */
+ hw->yr_base[MTK_AL] = alrm_tm->tm_year - MTK_RTC_TM_YR_L -
+ (alrm_tm->tm_year % MTK_RTC_HW_YR_LIMIT);
+
+ /*
+ * Stop the alarm also implicitly including disables interrupt before
+ * setting a new one.
+ */
+ mtk_clr(hw, MTK_RTC_AL_CTL, RTC_AL_EN);
+
+ /*
+ * Avoid contention between mtk_rtc_setalarm and IRQ handler so that
+ * disabling the interrupt and awaiting for pending IRQ handler to
+ * complete.
+ */
+ synchronize_irq(hw->irq);
+
+ mtk_rtc_set_alarm_or_time(hw, alrm_tm, MTK_AL);
+
+ /* Restart the alarm with the new setup */
+ mtk_w32(hw, MTK_RTC_AL_CTL, RTC_AL_ALL);
+
+ return 0;
+}
+
+static const struct rtc_class_ops mtk_rtc_ops = {
+ .read_time = mtk_rtc_gettime,
+ .set_time = mtk_rtc_settime,
+ .read_alarm = mtk_rtc_getalarm,
+ .set_alarm = mtk_rtc_setalarm,
+};
+
+static const struct of_device_id mtk_rtc_match[] = {
+ { .compatible = "mediatek,mt7622-rtc" },
+ { .compatible = "mediatek,soc-rtc" },
+ {},
+};
+
+static int mtk_rtc_probe(struct platform_device *pdev)
+{
+ struct mtk_rtc *hw;
+ struct resource *res;
+ int ret;
+
+ hw = devm_kzalloc(&pdev->dev, sizeof(*hw), GFP_KERNEL);
+ if (!hw)
+ return -ENOMEM;
+
+ platform_set_drvdata(pdev, hw);
+
+ res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+ hw->base = devm_ioremap_resource(&pdev->dev, res);
+ if (IS_ERR(hw->base))
+ return PTR_ERR(hw->base);
+
+ hw->clk = devm_clk_get(&pdev->dev, "rtc");
+ if (IS_ERR(hw->clk)) {
+ dev_err(&pdev->dev, "No clock\n");
+ return PTR_ERR(hw->clk);
+ }
+
+ ret = clk_prepare_enable(hw->clk);
+ if (ret)
+ return ret;
+
+ hw->irq = platform_get_irq(pdev, 0);
+ if (hw->irq < 0) {
+ dev_err(&pdev->dev, "No IRQ resource\n");
+ ret = hw->irq;
+ goto err;
+ }
+
+ ret = devm_request_irq(&pdev->dev, hw->irq, mtk_rtc_alarmirq,
+ 0, dev_name(&pdev->dev), hw);
+ if (ret) {
+ dev_err(&pdev->dev, "Can't request IRQ\n");
+ goto err;
+ }
+
+ mtk_rtc_hw_init(hw);
+
+ device_init_wakeup(&pdev->dev, true);
+
+ hw->rtc = devm_rtc_device_register(&pdev->dev, pdev->name,
+ &mtk_rtc_ops, THIS_MODULE);
+ if (IS_ERR(hw->rtc)) {
+ ret = PTR_ERR(hw->rtc);
+ dev_err(&pdev->dev, "Unable to register device\n");
+ goto err;
+ }
+
+ return 0;
+err:
+ clk_disable_unprepare(hw->clk);
+
+ return ret;
+}
+
+static int mtk_rtc_remove(struct platform_device *pdev)
+{
+ struct mtk_rtc *hw = platform_get_drvdata(pdev);
+
+ clk_disable_unprepare(hw->clk);
+
+ return 0;
+}
+
+#ifdef CONFIG_PM_SLEEP
+static int mtk_rtc_suspend(struct device *dev)
+{
+ struct mtk_rtc *hw = dev_get_drvdata(dev);
+
+ if (device_may_wakeup(dev))
+ enable_irq_wake(hw->irq);
+
+ return 0;
+}
+
+static int mtk_rtc_resume(struct device *dev)
+{
+ struct mtk_rtc *hw = dev_get_drvdata(dev);
+
+ if (device_may_wakeup(dev))
+ disable_irq_wake(hw->irq);
+
+ return 0;
+}
+
+static SIMPLE_DEV_PM_OPS(mtk_rtc_pm_ops, mtk_rtc_suspend, mtk_rtc_resume);
+
+#define MTK_RTC_PM_OPS (&mtk_rtc_pm_ops)
+#else /* CONFIG_PM */
+#define MTK_RTC_PM_OPS NULL
+#endif /* CONFIG_PM */
+
+static struct platform_driver mtk_rtc_driver = {
+ .probe = mtk_rtc_probe,
+ .remove = mtk_rtc_remove,
+ .driver = {
+ .name = MTK_RTC_DEV,
+ .of_match_table = mtk_rtc_match,
+ .pm = MTK_RTC_PM_OPS,
+ },
+};
+
+module_platform_driver(mtk_rtc_driver);
+
+MODULE_DESCRIPTION("MediaTek SoC based RTC Driver");
+MODULE_AUTHOR("Sean Wang <sean.wang@mediatek.com>");
+MODULE_LICENSE("GPL");
--
2.7.4
^ permalink raw reply related
* [PATCH v2 0/4] rtc: mediatek: add support for SoC based RTC on MT7622
From: sean.wang @ 2017-10-17 9:40 UTC (permalink / raw)
To: a.zummo, alexandre.belloni, robh+dt, mark.rutland
Cc: linux-rtc, devicetree, linux-mediatek, linux-kernel, Sean Wang
From: Sean Wang <sean.wang@mediatek.com>
Changes since v1:
- Rename to rtc-mt7622.c from rtc-mediatek.c
- Use [readl,writel]_relaxed instead of __raw_* version
- Remove redundant register reading in mtk_rtc_get_alarm_or_time()
- Stop alarm when alarm is really expired in mtk_rtc_alarmirq()
- Extend the maximum year the RTC/Alarm can count/support using year rebasing
- Remove unnesscary log which is already done in core layer
This patchset introduces support for MediaTek SoC based real time clock
(RTC) Currently, the driver is already tested successfully with hwclock
and wakealarm on MT7622 SoC. And it should also be workable on other
similar MediaTek SoCs. And patch 3 is a distinct patch used to distinguish
between either SoC based or PMIC based RTC to avoid confusion for the RTC
selection for the target SoC.
Sean Wang (4):
dt-bindings: rtc: mediatek: add bindings for MediaTek SoC based RTC
rtc: mediatek: add driver for RTC on MT7622 SoC
rtc: mediatek: enhance the description for MediaTek PMIC based RTC
rtc: mediatek: update MAINTAINERS entry with MediaTek RTC driver
.../devicetree/bindings/rtc/rtc-mediatek.txt | 21 ++
MAINTAINERS | 3 +
drivers/rtc/Kconfig | 18 +-
drivers/rtc/Makefile | 1 +
drivers/rtc/rtc-mt7622.c | 418 +++++++++++++++++++++
5 files changed, 457 insertions(+), 4 deletions(-)
create mode 100644 Documentation/devicetree/bindings/rtc/rtc-mediatek.txt
create mode 100644 drivers/rtc/rtc-mt7622.c
--
2.7.4
^ permalink raw reply
* Re: [PATCH 2/4] rtc: mediatek: add driver for RTC on MT7622 SoC
From: Sean Wang @ 2017-10-17 3:24 UTC (permalink / raw)
To: Alexandre Belloni
Cc: a.zummo, robh+dt, mark.rutland, linux-rtc, devicetree,
linux-mediatek, linux-kernel
In-Reply-To: <1508141876.21840.75.camel@mtkswgap22>
On Mon, 2017-10-16 at 16:17 +0800, Sean Wang wrote:
> Hi Alexandre,
>
> Thanks for your valuable suggestions on the driver.
>
> I added comments inline and will have following-ups in the next version
>
> Sean
>
> On Thu, 2017-10-12 at 23:20 +0200, Alexandre Belloni wrote:
> > Hi,
> >
> > On 22/09/2017 at 11:33:15 +0800, sean.wang@mediatek.com wrote:
> > > diff --git a/drivers/rtc/rtc-mediatek.c b/drivers/rtc/rtc-mediatek.c
> >
> > I'm pretty sure this should be named rtc-mt7622.c instead of
> > rtc-mediatek.c, exactly for the same reason you have patch 3/4.
> >
>
> It's okay for naming with rtc-mt7622.c at this moment. But if more SoCs
> support gets into the driver, I will consider again to give a more
> generic name for the driver.
>
> > > +static void mtk_w32(struct mtk_rtc *rtc, u32 reg, u32 val)
> > > +{
> > > + __raw_writel(val, rtc->base + reg);
> >
> > Do you really need the __raw accessors? What about running your SoC in
> > BE mode? I guess the _relaxed version are fast enough.
> >
>
> SoC runs on LE mode. I also think it's fine and enough to use _relaxed
> version instead of __raw version.
>
> > > +}
> > > +
> > > +static u32 mtk_r32(struct mtk_rtc *rtc, u32 reg)
> > > +{
> > > + return __raw_readl(rtc->base + reg);
> > > +}
> > > +
> >
> >
> > > +static void mtk_rtc_hw_init(struct mtk_rtc *hw)
> > > +{
> > > + /* The setup of the init sequence is for allowing RTC got to work */
> > > + mtk_w32(hw, MTK_RTC_PWRCHK1, RTC_PWRCHK1_MAGIC);
> > > + mtk_w32(hw, MTK_RTC_PWRCHK2, RTC_PWRCHK2_MAGIC);
> > > + mtk_w32(hw, MTK_RTC_KEY, RTC_KEY_MAGIC);
> > > + mtk_w32(hw, MTK_RTC_PROT1, RTC_PROT1_MAGIC);
> > > + mtk_w32(hw, MTK_RTC_PROT2, RTC_PROT2_MAGIC);
> > > + mtk_w32(hw, MTK_RTC_PROT3, RTC_PROT3_MAGIC);
> > > + mtk_w32(hw, MTK_RTC_PROT4, RTC_PROT4_MAGIC);
> > > + mtk_rmw(hw, MTK_RTC_DEBNCE, RTC_DEBNCE_MASK, 0);
> > > + mtk_clr(hw, MTK_RTC_CTL, RTC_RC_STOP);
> > > +}
> > > +
> > > +static void mtk_rtc_get_alarm_or_time(struct mtk_rtc *hw, struct rtc_time *tm,
> > > + int time_alarm)
> > > +{
> > > + u32 year, mon, mday, wday, hour, min, sec;
> > > +
> > > + /*
> > > + * Read again until all fields are not changed for all fields in the
> > > + * consistent state.
> > > + */
> > > + do {
> > > + year = mtk_r32(hw, MTK_RTC_TREG(time_alarm, MTK_YEA));
> > > + mon = mtk_r32(hw, MTK_RTC_TREG(time_alarm, MTK_MON));
> > > + wday = mtk_r32(hw, MTK_RTC_TREG(time_alarm, MTK_DOW));
> > > + mday = mtk_r32(hw, MTK_RTC_TREG(time_alarm, MTK_DOM));
> > > + hour = mtk_r32(hw, MTK_RTC_TREG(time_alarm, MTK_HOU));
> > > + min = mtk_r32(hw, MTK_RTC_TREG(time_alarm, MTK_MIN));
> > > + sec = mtk_r32(hw, MTK_RTC_TREG(time_alarm, MTK_SEC));
> > > + } while (year != mtk_r32(hw, MTK_RTC_TREG(time_alarm, MTK_YEA)) ||
> > > + mon != mtk_r32(hw, MTK_RTC_TREG(time_alarm, MTK_MON)) ||
> > > + mday != mtk_r32(hw, MTK_RTC_TREG(time_alarm, MTK_DOM)) ||
> > > + wday != mtk_r32(hw, MTK_RTC_TREG(time_alarm, MTK_DOW)) ||
> > > + hour != mtk_r32(hw, MTK_RTC_TREG(time_alarm, MTK_HOU)) ||
> > > + min != mtk_r32(hw, MTK_RTC_TREG(time_alarm, MTK_MIN)) ||
> > > + sec != mtk_r32(hw, MTK_RTC_TREG(time_alarm, MTK_SEC))
> > > + );
> >
> > I'm pretty sure only checking sec is enough because it is highly
> > unlikely that 7 reads take a minute.
> >
>
> You're right. I made something stupid here. Only checking on sec is
> enough and will give simpler and better code.
>
> > > +static irqreturn_t mtk_rtc_alarmirq(int irq, void *id)
> > > +{
> > > + struct mtk_rtc *hw = (struct mtk_rtc *)id;
> > > + u32 irq_sta;
> > > +
> > > + /* Stop alarm also implicitly disable the alarm interrupt */
> > > + mtk_w32(hw, MTK_RTC_AL_CTL, 0);
> >
> > You stop the alarm here, before testing whether the alarm really
> > happened.
> >
>
> Okay. I will exchange the order for alarm stopping and the examination
> whether the alarm is really expired.
>
> > > + irq_sta = mtk_r32(hw, MTK_RTC_INT);
> > > + if (irq_sta & RTC_INT_AL_STA) {
> > > + rtc_update_irq(hw->rtc, 1, RTC_IRQF | RTC_AF);
> > > +
> > > + /* Ack alarm interrupt status */
> > > + mtk_w32(hw, MTK_RTredundantC_INT, RTC_INT_AL_STA);
> > > + return IRQ_HANDLED;
> > > + }
> > > +
> > > + return IRQ_NONE;
> > > +}
> > > +
> > > +static int mtk_rtc_gettime(struct device *dev, struct rtc_time *tm)
> > > +{
> > > + struct mtk_rtc *hw = dev_get_drvdata(dev);
> > > +
> > > + mtk_rtc_get_alarm_or_time(hw, tm, MTK_TC);
> > > +
> > > + return rtc_valid_tm(tm);
> > > +}
> > > +
> > > +static int mtk_rtc_settime(struct device *dev, struct rtc_time *tm)
> > > +{
> > > + struct mtk_rtc *hw = dev_get_drvdata(dev);
> > > +
> > > + /* Stop time counter before setting a new one*/
> > > + mtk_set(hw, MTK_RTC_CTL, RTC_RC_STOP);
> > > +
> > > + /* Epoch == 1900 */
> > > + if (tm->tm_year < 100 || tm->tm_year > 199)
> > > + return -EINVAL;
> >
> > Year is a 32 bits register, what makes the RTC fail in 2100? Is it
> > because of the leap year handling?
> >
>
> I made something stupid again here: rtc hardware doesn't have such the
> limitation. I just felt alarm set up prior to 2100 is enough in my
> initial thought, but it seemed I shouldn't do this. I will remove the
> sanity condition.
>
Sorry for that I gave incorrect information for the RTC in the previous
reply: After check again the usage of the register, the maximum number
of the year the RTC can hold is 99 and then wraparound to 0 when
overflow occurs although the year register is a 32 bits register.
Therefore, the sanity for tm->tm_year is still required for the both
setup handler on alarm and rtc to ensure the user input data is valid,
where the current driver assume it's valid when tm->tm_year is between
2000 and 2099. I'll add more comments for the hardware limitation.
Sean
>
> > > +static int mtk_rtc_setalarm(struct device *dev, struct rtc_wkalrm *wkalrm)
> > > +{
> > > + struct mtk_rtc *hw = dev_get_drvdata(dev);
> > > + struct rtc_time *alrm_tm = &wkalrm->time;
> > > +
> > > + /* Epoch == 1900 */
> > > + if (alrm_tm->tm_year < 100 || alrm_tm->tm_year > 199)
> > > + return -EINVAL;
> > > +
> >
> > Ditto.
> >
> Ditto. those condition will be removed.
>
> > > +
> > > + dev_info(&pdev->dev, "MediaTek SoC based RTC enabled\n");
> > > +
> >
> > I think the rtc core is verbose enough that this message is not needed.
> >
>
> Okay. the redundant and specific log prompt would be removed as well.
>
>
> >
>
^ permalink raw reply
* Re: [PATCH 2/4] rtc: mediatek: add driver for RTC on MT7622 SoC
From: Sean Wang @ 2017-10-16 8:17 UTC (permalink / raw)
To: Alexandre Belloni
Cc: a.zummo, robh+dt, mark.rutland, linux-rtc, devicetree,
linux-mediatek, linux-kernel
In-Reply-To: <20171012212052.xkhbgdjrghmnvcfe@piout.net>
Hi Alexandre,
Thanks for your valuable suggestions on the driver.
I added comments inline and will have following-ups in the next version
Sean
On Thu, 2017-10-12 at 23:20 +0200, Alexandre Belloni wrote:
> Hi,
>
> On 22/09/2017 at 11:33:15 +0800, sean.wang@mediatek.com wrote:
> > diff --git a/drivers/rtc/rtc-mediatek.c b/drivers/rtc/rtc-mediatek.c
>
> I'm pretty sure this should be named rtc-mt7622.c instead of
> rtc-mediatek.c, exactly for the same reason you have patch 3/4.
>
It's okay for naming with rtc-mt7622.c at this moment. But if more SoCs
support gets into the driver, I will consider again to give a more
generic name for the driver.
> > +static void mtk_w32(struct mtk_rtc *rtc, u32 reg, u32 val)
> > +{
> > + __raw_writel(val, rtc->base + reg);
>
> Do you really need the __raw accessors? What about running your SoC in
> BE mode? I guess the _relaxed version are fast enough.
>
SoC runs on LE mode. I also think it's fine and enough to use _relaxed
version instead of __raw version.
> > +}
> > +
> > +static u32 mtk_r32(struct mtk_rtc *rtc, u32 reg)
> > +{
> > + return __raw_readl(rtc->base + reg);
> > +}
> > +
>
>
> > +static void mtk_rtc_hw_init(struct mtk_rtc *hw)
> > +{
> > + /* The setup of the init sequence is for allowing RTC got to work */
> > + mtk_w32(hw, MTK_RTC_PWRCHK1, RTC_PWRCHK1_MAGIC);
> > + mtk_w32(hw, MTK_RTC_PWRCHK2, RTC_PWRCHK2_MAGIC);
> > + mtk_w32(hw, MTK_RTC_KEY, RTC_KEY_MAGIC);
> > + mtk_w32(hw, MTK_RTC_PROT1, RTC_PROT1_MAGIC);
> > + mtk_w32(hw, MTK_RTC_PROT2, RTC_PROT2_MAGIC);
> > + mtk_w32(hw, MTK_RTC_PROT3, RTC_PROT3_MAGIC);
> > + mtk_w32(hw, MTK_RTC_PROT4, RTC_PROT4_MAGIC);
> > + mtk_rmw(hw, MTK_RTC_DEBNCE, RTC_DEBNCE_MASK, 0);
> > + mtk_clr(hw, MTK_RTC_CTL, RTC_RC_STOP);
> > +}
> > +
> > +static void mtk_rtc_get_alarm_or_time(struct mtk_rtc *hw, struct rtc_time *tm,
> > + int time_alarm)
> > +{
> > + u32 year, mon, mday, wday, hour, min, sec;
> > +
> > + /*
> > + * Read again until all fields are not changed for all fields in the
> > + * consistent state.
> > + */
> > + do {
> > + year = mtk_r32(hw, MTK_RTC_TREG(time_alarm, MTK_YEA));
> > + mon = mtk_r32(hw, MTK_RTC_TREG(time_alarm, MTK_MON));
> > + wday = mtk_r32(hw, MTK_RTC_TREG(time_alarm, MTK_DOW));
> > + mday = mtk_r32(hw, MTK_RTC_TREG(time_alarm, MTK_DOM));
> > + hour = mtk_r32(hw, MTK_RTC_TREG(time_alarm, MTK_HOU));
> > + min = mtk_r32(hw, MTK_RTC_TREG(time_alarm, MTK_MIN));
> > + sec = mtk_r32(hw, MTK_RTC_TREG(time_alarm, MTK_SEC));
> > + } while (year != mtk_r32(hw, MTK_RTC_TREG(time_alarm, MTK_YEA)) ||
> > + mon != mtk_r32(hw, MTK_RTC_TREG(time_alarm, MTK_MON)) ||
> > + mday != mtk_r32(hw, MTK_RTC_TREG(time_alarm, MTK_DOM)) ||
> > + wday != mtk_r32(hw, MTK_RTC_TREG(time_alarm, MTK_DOW)) ||
> > + hour != mtk_r32(hw, MTK_RTC_TREG(time_alarm, MTK_HOU)) ||
> > + min != mtk_r32(hw, MTK_RTC_TREG(time_alarm, MTK_MIN)) ||
> > + sec != mtk_r32(hw, MTK_RTC_TREG(time_alarm, MTK_SEC))
> > + );
>
> I'm pretty sure only checking sec is enough because it is highly
> unlikely that 7 reads take a minute.
>
You're right. I made something stupid here. Only checking on sec is
enough and will give simpler and better code.
> > +static irqreturn_t mtk_rtc_alarmirq(int irq, void *id)
> > +{
> > + struct mtk_rtc *hw = (struct mtk_rtc *)id;
> > + u32 irq_sta;
> > +
> > + /* Stop alarm also implicitly disable the alarm interrupt */
> > + mtk_w32(hw, MTK_RTC_AL_CTL, 0);
>
> You stop the alarm here, before testing whether the alarm really
> happened.
>
Okay. I will exchange the order for alarm stopping and the examination
whether the alarm is really expired.
> > + irq_sta = mtk_r32(hw, MTK_RTC_INT);
> > + if (irq_sta & RTC_INT_AL_STA) {
> > + rtc_update_irq(hw->rtc, 1, RTC_IRQF | RTC_AF);
> > +
> > + /* Ack alarm interrupt status */
> > + mtk_w32(hw, MTK_RTredundantC_INT, RTC_INT_AL_STA);
> > + return IRQ_HANDLED;
> > + }
> > +
> > + return IRQ_NONE;
> > +}
> > +
> > +static int mtk_rtc_gettime(struct device *dev, struct rtc_time *tm)
> > +{
> > + struct mtk_rtc *hw = dev_get_drvdata(dev);
> > +
> > + mtk_rtc_get_alarm_or_time(hw, tm, MTK_TC);
> > +
> > + return rtc_valid_tm(tm);
> > +}
> > +
> > +static int mtk_rtc_settime(struct device *dev, struct rtc_time *tm)
> > +{
> > + struct mtk_rtc *hw = dev_get_drvdata(dev);
> > +
> > + /* Stop time counter before setting a new one*/
> > + mtk_set(hw, MTK_RTC_CTL, RTC_RC_STOP);
> > +
> > + /* Epoch == 1900 */
> > + if (tm->tm_year < 100 || tm->tm_year > 199)
> > + return -EINVAL;
>
> Year is a 32 bits register, what makes the RTC fail in 2100? Is it
> because of the leap year handling?
>
I made something stupid again here: rtc hardware doesn't have such the
limitation. I just felt alarm set up prior to 2100 is enough in my
initial thought, but it seemed I shouldn't do this. I will remove the
sanity condition.
> > +static int mtk_rtc_setalarm(struct device *dev, struct rtc_wkalrm *wkalrm)
> > +{
> > + struct mtk_rtc *hw = dev_get_drvdata(dev);
> > + struct rtc_time *alrm_tm = &wkalrm->time;
> > +
> > + /* Epoch == 1900 */
> > + if (alrm_tm->tm_year < 100 || alrm_tm->tm_year > 199)
> > + return -EINVAL;
> > +
>
> Ditto.
>
Ditto. those condition will be removed.
> > +
> > + dev_info(&pdev->dev, "MediaTek SoC based RTC enabled\n");
> > +
>
> I think the rtc core is verbose enough that this message is not needed.
>
Okay. the redundant and specific log prompt would be removed as well.
>
^ permalink raw reply
* Introduce clock precision to help time travelers was Re: Extreme time jitter with suspend/resume cycles
From: Pavel Machek @ 2017-10-15 6:39 UTC (permalink / raw)
To: Gabriel Beddingfield, pavel
Cc: LKML, Stephen Boyd, Thomas Gleixner, John Stultz,
Alessandro Zummo, Alexandre Belloni, linux-rtc, Guy Erb, hharte
In-Reply-To: <CAOdF7nvHfh_M3UQDYjbofNOm0-S_-LXHdmsMY7DeEwgOQCmfFA@mail.gmail.com>
H!
> We have been developing a device that has very a very aggressive power
> policy, doing suspend/resume cycles a few times a minute ("echo mem >
> /sys/power/state"). In doing so, we found that the system time
> experiences a lot of jitter (compared to, say, an NTP server). It was
> not uncommon for us to see time corrections of 1s to 4s on a regular
> basis. This didn't happen when the device stayed awake, only when it
> was allowed to do suspend/resume.
Ok, so I have various machines here. It seems only about half of them has
working RTC. That are the boring ones.
And even the boring ones have pretty imprecise RTCs... For example Nokia N9.
I only power it up from time to time, I believe it drifts something like
minute per month... For normal use with SIM card, it can probably correct
from GSM network if you happen to have a cell phone signal, but...
More interesting machines... Old thinkpad is running without CMOS battery.
ARM OLPC has _three_ RTCs, but not a single working one. N900 has working
RTC but no or dead backup battery. On these, RTC driver probably knows
time is not valid, but feeds the garbage into the system time, anyway. Ouch.
Neither Sharp Zaurus SL-5500 nor C-3000 had battery backup on RTC...
Even in new end-user machines, time quality varies a lot. "First boot, please
enter time" is only accurate to seconds, if the user is careful. RTC is usually
not very accurate, either... and noone uses adjtime these days. GSM time and
ntpdate are probably accurate to miliseconds, GPS can provide time down to
picoseconds... And broken systems are so common "swclock" is available in
init system to store time in file, so it at least does not go backwards.
https (and other crypto) depends on time... so it is important to know approximate
month we are in.
Is it time we handle it better?
Could we return both time and log2(expected error) from system calls?
That way we could hide the clock in GUI if time is not available or not precise
to minutes, ignore certificate dates when time is not precise to months, and
you would not have to send me a "Pavel, are you time traveling, again?" message
next time my mailer sends email dated to 1970.
Pavel
PS: And yes, I'm time-travaling again, this time by ~15 hours.
^ permalink raw reply
* Re: [PATCH v1 24/25] kdb: Switch to use %pt
From: Arnd Bergmann @ 2017-10-13 7:42 UTC (permalink / raw)
To: Andy Shevchenko
Cc: Rasmus Villemoes, Greg Kroah-Hartman, Andrew Morton,
Linux Kernel Mailing List, Alessandro Zummo, Alexandre Belloni,
linux-rtc, Jason Wessel, Ingo Molnar
In-Reply-To: <1507827914.16112.449.camel@linux.intel.com>
On Thu, Oct 12, 2017 at 7:05 PM, Andy Shevchenko
<andriy.shevchenko@linux.intel.com> wrote:
> On Thu, 2017-10-12 at 15:31 +0200, Arnd Bergmann wrote:
>> On Thu, Jun 8, 2017 at 3:48 PM, Andy Shevchenko
>> <andriy.shevchenko@linux.intel.com> wrote:
>>
>> > diff --git a/kernel/debug/kdb/kdb_main.c
>> > b/kernel/debug/kdb/kdb_main.c
>> > index c8146d53ca67..2a6f12be79d8 100644
>> > --- a/kernel/debug/kdb/kdb_main.c
>> > +++ b/kernel/debug/kdb/kdb_main.c
>> > @@ -2556,12 +2556,7 @@ static int kdb_summary(int argc, const char
>> > **argv)
>> >
>> > now = __current_kernel_time();
>> > kdb_gmtime(&now, &tm);
>> > - kdb_printf("date %04d-%02d-%02d %02d:%02d:%02d "
>> > - "tz_minuteswest %d\n",
>> > - 1900+tm.tm_year, tm.tm_mon+1, tm.tm_mday,
>> > - tm.tm_hour, tm.tm_min, tm.tm_sec,
>> > - sys_tz.tz_minuteswest);
>> > -
>>
>> I just experimented with a similar change and noticed your version.
>>
>> You forgot to remove the kdb_gmtime() function that is now completely
>> unneeded. My patch takes care of that now.
>
> So, are you going to substitute entire series by your variant?
>
> What did you choose to be format for the %p extension?
My patch doesn't touch printf at all, instead it removes the
__current_kernel_time() function, so it's unrelated but happens
to change the same lines here. Since kdb_gmtime() doesn't
work with 64-bit time_t, I replaced it using the generic
time64_to_tm() helper and removed it here.
Arnd
^ permalink raw reply
* [PATCH 2/2] rtc: omap: switch to rtc_register_device
From: Alexandre Belloni @ 2017-10-12 22:06 UTC (permalink / raw)
To: linux-rtc; +Cc: linux-kernel, Alexandre Belloni
In-Reply-To: <20171012220645.8704-1-alexandre.belloni@free-electrons.com>
This removes a possible race condition and crash and allows for further
improvement of the driver.
Signed-off-by: Alexandre Belloni <alexandre.belloni@free-electrons.com>
---
drivers/rtc/rtc-omap.c | 9 +++++++--
1 file changed, 7 insertions(+), 2 deletions(-)
diff --git a/drivers/rtc/rtc-omap.c b/drivers/rtc/rtc-omap.c
index 3bdc041fc2e9..d56d937966dc 100644
--- a/drivers/rtc/rtc-omap.c
+++ b/drivers/rtc/rtc-omap.c
@@ -797,13 +797,14 @@ static int omap_rtc_probe(struct platform_device *pdev)
device_init_wakeup(&pdev->dev, true);
- rtc->rtc = devm_rtc_device_register(&pdev->dev, pdev->name,
- &omap_rtc_ops, THIS_MODULE);
+ rtc->rtc = devm_rtc_allocate_device(&pdev->dev);
if (IS_ERR(rtc->rtc)) {
ret = PTR_ERR(rtc->rtc);
goto err;
}
+ rtc->rtc->ops = &omap_rtc_ops;
+
/* handle periodic and alarm irqs */
ret = devm_request_irq(&pdev->dev, rtc->irq_timer, rtc_irq, 0,
dev_name(&rtc->rtc->dev), rtc);
@@ -834,6 +835,10 @@ static int omap_rtc_probe(struct platform_device *pdev)
goto err;
}
+ ret = rtc_register_device(rtc->rtc);
+ if (ret)
+ goto err;
+
return 0;
err:
--
2.14.2
^ permalink raw reply related
* [PATCH 1/2] rtc: omap: fix error path when pinctrl_register fails
From: Alexandre Belloni @ 2017-10-12 22:06 UTC (permalink / raw)
To: linux-rtc; +Cc: linux-kernel, Alexandre Belloni
If pinctrl_register() fails probe will return with an error without locking
the RTC and disabling pm_runtime.
Set ret and jump to err instead.
Fixes: 97ea1906b3c2 ("rtc: omap: Support ext_wakeup configuration")
Signed-off-by: Alexandre Belloni <alexandre.belloni@free-electrons.com>
---
drivers/rtc/rtc-omap.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/drivers/rtc/rtc-omap.c b/drivers/rtc/rtc-omap.c
index 13f7cd11c07e..3bdc041fc2e9 100644
--- a/drivers/rtc/rtc-omap.c
+++ b/drivers/rtc/rtc-omap.c
@@ -830,7 +830,8 @@ static int omap_rtc_probe(struct platform_device *pdev)
rtc->pctldev = pinctrl_register(&rtc_pinctrl_desc, &pdev->dev, rtc);
if (IS_ERR(rtc->pctldev)) {
dev_err(&pdev->dev, "Couldn't register pinctrl driver\n");
- return PTR_ERR(rtc->pctldev);
+ ret = PTR_ERR(rtc->pctldev);
+ goto err;
}
return 0;
--
2.14.2
^ permalink raw reply related
* [PATCH 2/3] rtc: ds1511: allow waking platform
From: Alexandre Belloni @ 2017-10-12 22:05 UTC (permalink / raw)
To: linux-rtc; +Cc: linux-kernel, Alexandre Belloni
In-Reply-To: <20171012220529.8142-1-alexandre.belloni@free-electrons.com>
Disabling interrupts when removing the driver is bad practice as this will
prevent some platform from waking up when using that RTC.
Signed-off-by: Alexandre Belloni <alexandre.belloni@free-electrons.com>
---
drivers/rtc/rtc-ds1511.c | 10 +---------
1 file changed, 1 insertion(+), 9 deletions(-)
diff --git a/drivers/rtc/rtc-ds1511.c b/drivers/rtc/rtc-ds1511.c
index d44635178771..eda45358d63a 100644
--- a/drivers/rtc/rtc-ds1511.c
+++ b/drivers/rtc/rtc-ds1511.c
@@ -511,16 +511,8 @@ static int ds1511_rtc_probe(struct platform_device *pdev)
static int ds1511_rtc_remove(struct platform_device *pdev)
{
- struct rtc_plat_data *pdata = platform_get_drvdata(pdev);
-
sysfs_remove_bin_file(&pdev->dev.kobj, &ds1511_nvram_attr);
- if (pdata->irq > 0) {
- /*
- * disable the alarm interrupt
- */
- rtc_write(rtc_read(RTC_CMD) & ~RTC_TIE, RTC_CMD);
- rtc_read(RTC_CMD1);
- }
+
return 0;
}
--
2.14.2
^ permalink raw reply related
* [PATCH 1/3] rtc: ds1511: switch to rtc_register_device
From: Alexandre Belloni @ 2017-10-12 22:05 UTC (permalink / raw)
To: linux-rtc; +Cc: linux-kernel, Alexandre Belloni
This allows for future improvement of the driver.
Signed-off-by: Alexandre Belloni <alexandre.belloni@free-electrons.com>
---
drivers/rtc/rtc-ds1511.c | 9 +++++++--
1 file changed, 7 insertions(+), 2 deletions(-)
diff --git a/drivers/rtc/rtc-ds1511.c b/drivers/rtc/rtc-ds1511.c
index 1b2dcb58c0ab..d44635178771 100644
--- a/drivers/rtc/rtc-ds1511.c
+++ b/drivers/rtc/rtc-ds1511.c
@@ -477,11 +477,16 @@ static int ds1511_rtc_probe(struct platform_device *pdev)
spin_lock_init(&pdata->lock);
platform_set_drvdata(pdev, pdata);
- pdata->rtc = devm_rtc_device_register(&pdev->dev, pdev->name,
- &ds1511_rtc_ops, THIS_MODULE);
+ pdata->rtc = devm_rtc_allocate_device(&pdev->dev);
if (IS_ERR(pdata->rtc))
return PTR_ERR(pdata->rtc);
+ pdata->rtc->ops = &ds1511_rtc_ops;
+
+ ret = rtc_register_device(pdata->rtc);
+ if (ret)
+ return ret;
+
/*
* if the platform has an interrupt in mind for this device,
* then by all means, set it
--
2.14.2
^ permalink raw reply related
* [PATCH 3/3] rtc: ds1511: use generic nvmem
From: Alexandre Belloni @ 2017-10-12 22:05 UTC (permalink / raw)
To: linux-rtc; +Cc: linux-kernel, Alexandre Belloni
In-Reply-To: <20171012220529.8142-1-alexandre.belloni@free-electrons.com>
Instead of adding a binary sysfs attribute from the driver (which suffers
from a race condition as the attribute appears after the device), use the
core to register an nvmem device.
Signed-off-by: Alexandre Belloni <alexandre.belloni@free-electrons.com>
---
drivers/rtc/rtc-ds1511.c | 58 ++++++++++++++++++------------------------------
1 file changed, 22 insertions(+), 36 deletions(-)
diff --git a/drivers/rtc/rtc-ds1511.c b/drivers/rtc/rtc-ds1511.c
index eda45358d63a..1e95312a6f2e 100644
--- a/drivers/rtc/rtc-ds1511.c
+++ b/drivers/rtc/rtc-ds1511.c
@@ -398,42 +398,37 @@ static const struct rtc_class_ops ds1511_rtc_ops = {
.alarm_irq_enable = ds1511_rtc_alarm_irq_enable,
};
-static ssize_t
-ds1511_nvram_read(struct file *filp, struct kobject *kobj,
- struct bin_attribute *ba,
- char *buf, loff_t pos, size_t size)
+static int ds1511_nvram_read(void *priv, unsigned int pos, void *buf,
+ size_t size)
{
- ssize_t count;
+ int i;
rtc_write(pos, DS1511_RAMADDR_LSB);
- for (count = 0; count < size; count++)
- *buf++ = rtc_read(DS1511_RAMDATA);
+ for (i = 0; i < size; i++)
+ *(char *)buf++ = rtc_read(DS1511_RAMDATA);
- return count;
+ return 0;
}
-static ssize_t
-ds1511_nvram_write(struct file *filp, struct kobject *kobj,
- struct bin_attribute *bin_attr,
- char *buf, loff_t pos, size_t size)
+static int ds1511_nvram_write(void *priv, unsigned int pos, void *buf,
+ size_t size)
{
- ssize_t count;
+ int i;
rtc_write(pos, DS1511_RAMADDR_LSB);
- for (count = 0; count < size; count++)
- rtc_write(*buf++, DS1511_RAMDATA);
+ for (i = 0; i < size; i++)
+ rtc_write(*(char *)buf++, DS1511_RAMDATA);
- return count;
+ return 0;
}
-static struct bin_attribute ds1511_nvram_attr = {
- .attr = {
- .name = "nvram",
- .mode = S_IRUGO | S_IWUSR,
- },
+static struct nvmem_config ds1511_nvmem_cfg = {
+ .name = "ds1511_nvram",
+ .word_size = 1,
+ .stride = 1,
.size = DS1511_RAM_MAX,
- .read = ds1511_nvram_read,
- .write = ds1511_nvram_write,
+ .reg_read = ds1511_nvram_read,
+ .reg_write = ds1511_nvram_write,
};
static int ds1511_rtc_probe(struct platform_device *pdev)
@@ -483,6 +478,10 @@ static int ds1511_rtc_probe(struct platform_device *pdev)
pdata->rtc->ops = &ds1511_rtc_ops;
+ ds1511_nvmem_cfg.priv = &pdev->dev;
+ pdata->rtc->nvmem_config = &ds1511_nvmem_cfg;
+ pdata->rtc->nvram_old_abi = true;
+
ret = rtc_register_device(pdata->rtc);
if (ret)
return ret;
@@ -501,18 +500,6 @@ static int ds1511_rtc_probe(struct platform_device *pdev)
}
}
- ret = sysfs_create_bin_file(&pdev->dev.kobj, &ds1511_nvram_attr);
- if (ret)
- dev_err(&pdev->dev, "Unable to create sysfs entry: %s\n",
- ds1511_nvram_attr.attr.name);
-
- return 0;
-}
-
-static int ds1511_rtc_remove(struct platform_device *pdev)
-{
- sysfs_remove_bin_file(&pdev->dev.kobj, &ds1511_nvram_attr);
-
return 0;
}
@@ -521,7 +508,6 @@ MODULE_ALIAS("platform:ds1511");
static struct platform_driver ds1511_rtc_driver = {
.probe = ds1511_rtc_probe,
- .remove = ds1511_rtc_remove,
.driver = {
.name = "ds1511",
},
--
2.14.2
^ permalink raw reply related
* [PATCH 2/2] rtc: abx80x: solve race condition
From: Alexandre Belloni @ 2017-10-12 22:04 UTC (permalink / raw)
To: linux-rtc; +Cc: linux-kernel, Alexandre Belloni
In-Reply-To: <20171012220447.7940-1-alexandre.belloni@free-electrons.com>
There is a race condition that can happen if abx80x_probe() fails after the
rtc registration succeeded. Solve that by moving the registration at the
end of the probe function.
Signed-off-by: Alexandre Belloni <alexandre.belloni@free-electrons.com>
---
drivers/rtc/rtc-abx80x.c | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/drivers/rtc/rtc-abx80x.c b/drivers/rtc/rtc-abx80x.c
index 442e62a3c9a9..b033bc556f5d 100644
--- a/drivers/rtc/rtc-abx80x.c
+++ b/drivers/rtc/rtc-abx80x.c
@@ -620,10 +620,6 @@ static int abx80x_probe(struct i2c_client *client,
rtc->ops = &abx80x_rtc_ops;
- err = rtc_register_device(rtc);
- if (err)
- return err;
-
i2c_set_clientdata(client, rtc);
if (client->irq > 0) {
@@ -650,10 +646,14 @@ static int abx80x_probe(struct i2c_client *client,
err = devm_add_action_or_reset(&client->dev,
rtc_calib_remove_sysfs_group,
&client->dev);
- if (err)
+ if (err) {
dev_err(&client->dev,
"Failed to add sysfs cleanup action: %d\n",
err);
+ return err;
+ }
+
+ err = rtc_register_device(rtc);
return err;
}
--
2.14.2
^ permalink raw reply related
* [PATCH 1/2] rtc: abx80x: switch to rtc_register_device
From: Alexandre Belloni @ 2017-10-12 22:04 UTC (permalink / raw)
To: linux-rtc; +Cc: linux-kernel, Alexandre Belloni
This allows for future improvement of the driver.
Signed-off-by: Alexandre Belloni <alexandre.belloni@free-electrons.com>
---
drivers/rtc/rtc-abx80x.c | 10 +++++++---
1 file changed, 7 insertions(+), 3 deletions(-)
diff --git a/drivers/rtc/rtc-abx80x.c b/drivers/rtc/rtc-abx80x.c
index fea9a60b06cf..442e62a3c9a9 100644
--- a/drivers/rtc/rtc-abx80x.c
+++ b/drivers/rtc/rtc-abx80x.c
@@ -614,12 +614,16 @@ static int abx80x_probe(struct i2c_client *client,
if (err)
return err;
- rtc = devm_rtc_device_register(&client->dev, "abx8xx",
- &abx80x_rtc_ops, THIS_MODULE);
-
+ rtc = devm_rtc_allocate_device(&client->dev);
if (IS_ERR(rtc))
return PTR_ERR(rtc);
+ rtc->ops = &abx80x_rtc_ops;
+
+ err = rtc_register_device(rtc);
+ if (err)
+ return err;
+
i2c_set_clientdata(client, rtc);
if (client->irq > 0) {
--
2.14.2
^ permalink raw reply related
* [PATCH 1/2] rtc: m48t86: switch to rtc_register_device
From: Alexandre Belloni @ 2017-10-12 22:04 UTC (permalink / raw)
To: linux-rtc; +Cc: linux-kernel, Alexandre Belloni
This allows for future improvement of the driver.
Signed-off-by: Alexandre Belloni <alexandre.belloni@free-electrons.com>
---
drivers/rtc/rtc-m48t86.c | 10 ++++++++--
1 file changed, 8 insertions(+), 2 deletions(-)
diff --git a/drivers/rtc/rtc-m48t86.c b/drivers/rtc/rtc-m48t86.c
index 02af045305dd..22656a90cfc5 100644
--- a/drivers/rtc/rtc-m48t86.c
+++ b/drivers/rtc/rtc-m48t86.c
@@ -228,6 +228,7 @@ static int m48t86_rtc_probe(struct platform_device *pdev)
struct m48t86_rtc_info *info;
struct resource *res;
unsigned char reg;
+ int err;
info = devm_kzalloc(&pdev->dev, sizeof(*info), GFP_KERNEL);
if (!info)
@@ -254,11 +255,16 @@ static int m48t86_rtc_probe(struct platform_device *pdev)
return -ENODEV;
}
- info->rtc = devm_rtc_device_register(&pdev->dev, "m48t86",
- &m48t86_rtc_ops, THIS_MODULE);
+ info->rtc = devm_rtc_allocate_device(&pdev->dev);
if (IS_ERR(info->rtc))
return PTR_ERR(info->rtc);
+ info->rtc->ops = &m48t86_rtc_ops;
+
+ err = rtc_register_device(info->rtc);
+ if (err)
+ return err;
+
/* read battery status */
reg = m48t86_readb(&pdev->dev, M48T86_D);
dev_info(&pdev->dev, "battery %s\n",
--
2.14.2
^ permalink raw reply related
* [PATCH 2/2] rtc: m48t86: use generic nvmem
From: Alexandre Belloni @ 2017-10-12 22:04 UTC (permalink / raw)
To: linux-rtc; +Cc: linux-kernel, Alexandre Belloni
In-Reply-To: <20171012220421.7784-1-alexandre.belloni@free-electrons.com>
Instead of adding a binary sysfs attribute from the driver (which suffers
from a race condition as the attribute appears after the device), use the
core to register an nvmem device.
Signed-off-by: Alexandre Belloni <alexandre.belloni@free-electrons.com>
---
drivers/rtc/rtc-m48t86.c | 48 +++++++++++++++++++++++-------------------------
1 file changed, 23 insertions(+), 25 deletions(-)
diff --git a/drivers/rtc/rtc-m48t86.c b/drivers/rtc/rtc-m48t86.c
index 22656a90cfc5..d9aea9b6d9cd 100644
--- a/drivers/rtc/rtc-m48t86.c
+++ b/drivers/rtc/rtc-m48t86.c
@@ -163,35 +163,30 @@ static const struct rtc_class_ops m48t86_rtc_ops = {
.proc = m48t86_rtc_proc,
};
-static ssize_t m48t86_nvram_read(struct file *filp, struct kobject *kobj,
- struct bin_attribute *attr,
- char *buf, loff_t off, size_t count)
+static int m48t86_nvram_read(void *priv, unsigned int off, void *buf,
+ size_t count)
{
- struct device *dev = kobj_to_dev(kobj);
+ struct device *dev = priv;
unsigned int i;
for (i = 0; i < count; i++)
- buf[i] = m48t86_readb(dev, M48T86_NVRAM(off + i));
+ ((u8 *)buf)[i] = m48t86_readb(dev, M48T86_NVRAM(off + i));
- return count;
+ return 0;
}
-static ssize_t m48t86_nvram_write(struct file *filp, struct kobject *kobj,
- struct bin_attribute *attr,
- char *buf, loff_t off, size_t count)
+static int m48t86_nvram_write(void *priv, unsigned int off, void *buf,
+ size_t count)
{
- struct device *dev = kobj_to_dev(kobj);
+ struct device *dev = priv;
unsigned int i;
for (i = 0; i < count; i++)
- m48t86_writeb(dev, buf[i], M48T86_NVRAM(off + i));
+ m48t86_writeb(dev, ((u8 *)buf)[i], M48T86_NVRAM(off + i));
- return count;
+ return 0;
}
-static BIN_ATTR(nvram, 0644, m48t86_nvram_read, m48t86_nvram_write,
- M48T86_NVRAM_LEN);
-
/*
* The RTC is an optional feature at purchase time on some Technologic Systems
* boards. Verify that it actually exists by checking if the last two bytes
@@ -223,6 +218,15 @@ static bool m48t86_verify_chip(struct platform_device *pdev)
return false;
}
+static struct nvmem_config m48t86_nvmem_cfg = {
+ .name = "m48t86_nvram",
+ .word_size = 1,
+ .stride = 1,
+ .size = M48T86_NVRAM_LEN,
+ .reg_read = m48t86_nvram_read,
+ .reg_write = m48t86_nvram_write,
+};
+
static int m48t86_rtc_probe(struct platform_device *pdev)
{
struct m48t86_rtc_info *info;
@@ -261,6 +265,10 @@ static int m48t86_rtc_probe(struct platform_device *pdev)
info->rtc->ops = &m48t86_rtc_ops;
+ m48t86_nvmem_cfg.priv = &pdev->dev;
+ info->rtc->nvmem_config = &m48t86_nvmem_cfg;
+ info->rtc->nvram_old_abi = true;
+
err = rtc_register_device(info->rtc);
if (err)
return err;
@@ -270,15 +278,6 @@ static int m48t86_rtc_probe(struct platform_device *pdev)
dev_info(&pdev->dev, "battery %s\n",
(reg & M48T86_D_VRT) ? "ok" : "exhausted");
- if (device_create_bin_file(&pdev->dev, &bin_attr_nvram))
- dev_err(&pdev->dev, "failed to create nvram sysfs entry\n");
-
- return 0;
-}
-
-static int m48t86_rtc_remove(struct platform_device *pdev)
-{
- device_remove_bin_file(&pdev->dev, &bin_attr_nvram);
return 0;
}
@@ -287,7 +286,6 @@ static struct platform_driver m48t86_rtc_platform_driver = {
.name = "rtc-m48t86",
},
.probe = m48t86_rtc_probe,
- .remove = m48t86_rtc_remove,
};
module_platform_driver(m48t86_rtc_platform_driver);
--
2.14.2
^ permalink raw reply related
* [PATCH 2/2] rtc: ds1305: use generic nvmem
From: Alexandre Belloni @ 2017-10-12 22:03 UTC (permalink / raw)
To: linux-rtc; +Cc: linux-kernel, Alexandre Belloni
In-Reply-To: <20171012220323.7515-1-alexandre.belloni@free-electrons.com>
Instead of adding a binary sysfs attribute from the driver (which suffers
from a race condition as the attribute appears after the device), use the
core to register an nvmem device.
Signed-off-by: Alexandre Belloni <alexandre.belloni@free-electrons.com>
---
drivers/rtc/rtc-ds1305.c | 59 +++++++++++++++++-------------------------------
1 file changed, 21 insertions(+), 38 deletions(-)
diff --git a/drivers/rtc/rtc-ds1305.c b/drivers/rtc/rtc-ds1305.c
index c3232c818e65..d8df2e9e14ad 100644
--- a/drivers/rtc/rtc-ds1305.c
+++ b/drivers/rtc/rtc-ds1305.c
@@ -514,56 +514,43 @@ static void msg_init(struct spi_message *m, struct spi_transfer *x,
spi_message_add_tail(x, m);
}
-static ssize_t
-ds1305_nvram_read(struct file *filp, struct kobject *kobj,
- struct bin_attribute *attr,
- char *buf, loff_t off, size_t count)
+static int ds1305_nvram_read(void *priv, unsigned int off, void *buf,
+ size_t count)
{
- struct spi_device *spi;
+ struct ds1305 *ds1305 = priv;
+ struct spi_device *spi = ds1305->spi;
u8 addr;
struct spi_message m;
struct spi_transfer x[2];
- int status;
-
- spi = to_spi_device(kobj_to_dev(kobj));
addr = DS1305_NVRAM + off;
msg_init(&m, x, &addr, count, NULL, buf);
- status = spi_sync(spi, &m);
- if (status < 0)
- dev_err(&spi->dev, "nvram %s error %d\n", "read", status);
- return (status < 0) ? status : count;
+ return spi_sync(spi, &m);
}
-static ssize_t
-ds1305_nvram_write(struct file *filp, struct kobject *kobj,
- struct bin_attribute *attr,
- char *buf, loff_t off, size_t count)
+static int ds1305_nvram_write(void *priv, unsigned int off, void *buf,
+ size_t count)
{
- struct spi_device *spi;
+ struct ds1305 *ds1305 = priv;
+ struct spi_device *spi = ds1305->spi;
u8 addr;
struct spi_message m;
struct spi_transfer x[2];
- int status;
-
- spi = to_spi_device(kobj_to_dev(kobj));
addr = (DS1305_WRITE | DS1305_NVRAM) + off;
msg_init(&m, x, &addr, count, buf, NULL);
- status = spi_sync(spi, &m);
- if (status < 0)
- dev_err(&spi->dev, "nvram %s error %d\n", "write", status);
- return (status < 0) ? status : count;
+ return spi_sync(spi, &m);
}
-static struct bin_attribute nvram = {
- .attr.name = "nvram",
- .attr.mode = S_IRUGO | S_IWUSR,
- .read = ds1305_nvram_read,
- .write = ds1305_nvram_write,
- .size = DS1305_NVRAM_LEN,
+static struct nvmem_config ds1305_nvmem_cfg = {
+ .name = "ds1305_nvram",
+ .word_size = 1,
+ .stride = 1,
+ .size = DS1305_NVRAM_LEN,
+ .reg_read = ds1305_nvram_read,
+ .reg_write = ds1305_nvram_write,
};
/*----------------------------------------------------------------------*/
@@ -715,6 +702,10 @@ static int ds1305_probe(struct spi_device *spi)
ds1305->rtc->ops = &ds1305_ops;
+ ds1305_nvmem_cfg.priv = ds1305;
+ ds1305->rtc->nvmem_config = &ds1305_nvmem_cfg;
+ ds1305->rtc->nvram_old_abi = true;
+
status = rtc_register_device(ds1305->rtc);
if (status) {
dev_dbg(&spi->dev, "register rtc --> %d\n", status);
@@ -739,12 +730,6 @@ static int ds1305_probe(struct spi_device *spi)
}
}
- /* export NVRAM */
- status = sysfs_create_bin_file(&spi->dev.kobj, &nvram);
- if (status < 0) {
- dev_err(&spi->dev, "register nvram --> %d\n", status);
- }
-
return 0;
}
@@ -752,8 +737,6 @@ static int ds1305_remove(struct spi_device *spi)
{
struct ds1305 *ds1305 = spi_get_drvdata(spi);
- sysfs_remove_bin_file(&spi->dev.kobj, &nvram);
-
/* carefully shut down irq and workqueue, if present */
if (spi->irq) {
set_bit(FLAG_EXITING, &ds1305->flags);
--
2.14.2
^ permalink raw reply related
* [PATCH 1/2] rtc: ds1305: switch to rtc_register_device
From: Alexandre Belloni @ 2017-10-12 22:03 UTC (permalink / raw)
To: linux-rtc; +Cc: linux-kernel, Alexandre Belloni
This allows for future improvement of the driver.
Signed-off-by: Alexandre Belloni <alexandre.belloni@free-electrons.com>
---
drivers/rtc/rtc-ds1305.c | 11 ++++++++---
1 file changed, 8 insertions(+), 3 deletions(-)
diff --git a/drivers/rtc/rtc-ds1305.c b/drivers/rtc/rtc-ds1305.c
index 72b22935eb62..c3232c818e65 100644
--- a/drivers/rtc/rtc-ds1305.c
+++ b/drivers/rtc/rtc-ds1305.c
@@ -708,10 +708,15 @@ static int ds1305_probe(struct spi_device *spi)
dev_dbg(&spi->dev, "AM/PM\n");
/* register RTC ... from here on, ds1305->ctrl needs locking */
- ds1305->rtc = devm_rtc_device_register(&spi->dev, "ds1305",
- &ds1305_ops, THIS_MODULE);
+ ds1305->rtc = devm_rtc_allocate_device(&spi->dev);
if (IS_ERR(ds1305->rtc)) {
- status = PTR_ERR(ds1305->rtc);
+ return PTR_ERR(ds1305->rtc);
+ }
+
+ ds1305->rtc->ops = &ds1305_ops;
+
+ status = rtc_register_device(ds1305->rtc);
+ if (status) {
dev_dbg(&spi->dev, "register rtc --> %d\n", status);
return status;
}
--
2.14.2
^ permalink raw reply related
* Re: [PATCH V2] rtc: add support for NXP PCF85363 real-time clock
From: Fabio Estevam @ 2017-10-12 21:55 UTC (permalink / raw)
To: Eric Nelson
Cc: linux-rtc, Alessandro Zummo, Alexandre Belloni,
robh+dt@kernel.org, Mark Rutland, devicetree@vger.kernel.org,
Otavio Salvador
In-Reply-To: <1507737390-27818-1-git-send-email-eric@nelint.com>
On Wed, Oct 11, 2017 at 12:56 PM, Eric Nelson <eric@nelint.com> wrote:
> Note that alarms are not currently implemented.
>
> 64 bytes of nvmem is supported and exposed in
> sysfs (# is the instance number, starting with 0):
>
> /sys/bus/nvmem/devices/pcf85363-#/nvmem
>
> Signed-off-by: Eric Nelson <eric@nelint.com>
Reviewed-by: Fabio Estevam <fabio.estevam@nxp.com>
^ permalink raw reply
* Re: [PATCH 2/4] rtc: mediatek: add driver for RTC on MT7622 SoC
From: Alexandre Belloni @ 2017-10-12 21:20 UTC (permalink / raw)
To: sean.wang
Cc: a.zummo, robh+dt, mark.rutland, linux-rtc, devicetree,
linux-mediatek, linux-kernel
In-Reply-To: <5b2a7e5c9c5bc179f89e48fb614b2ae789be4254.1506049341.git.sean.wang@mediatek.com>
Hi,
On 22/09/2017 at 11:33:15 +0800, sean.wang@mediatek.com wrote:
> diff --git a/drivers/rtc/rtc-mediatek.c b/drivers/rtc/rtc-mediatek.c
I'm pretty sure this should be named rtc-mt7622.c instead of
rtc-mediatek.c, exactly for the same reason you have patch 3/4.
> +static void mtk_w32(struct mtk_rtc *rtc, u32 reg, u32 val)
> +{
> + __raw_writel(val, rtc->base + reg);
Do you really need the __raw accessors? What about running your SoC in
BE mode? I guess the _relaxed version are fast enough.
> +}
> +
> +static u32 mtk_r32(struct mtk_rtc *rtc, u32 reg)
> +{
> + return __raw_readl(rtc->base + reg);
> +}
> +
> +static void mtk_rtc_hw_init(struct mtk_rtc *hw)
> +{
> + /* The setup of the init sequence is for allowing RTC got to work */
> + mtk_w32(hw, MTK_RTC_PWRCHK1, RTC_PWRCHK1_MAGIC);
> + mtk_w32(hw, MTK_RTC_PWRCHK2, RTC_PWRCHK2_MAGIC);
> + mtk_w32(hw, MTK_RTC_KEY, RTC_KEY_MAGIC);
> + mtk_w32(hw, MTK_RTC_PROT1, RTC_PROT1_MAGIC);
> + mtk_w32(hw, MTK_RTC_PROT2, RTC_PROT2_MAGIC);
> + mtk_w32(hw, MTK_RTC_PROT3, RTC_PROT3_MAGIC);
> + mtk_w32(hw, MTK_RTC_PROT4, RTC_PROT4_MAGIC);
> + mtk_rmw(hw, MTK_RTC_DEBNCE, RTC_DEBNCE_MASK, 0);
> + mtk_clr(hw, MTK_RTC_CTL, RTC_RC_STOP);
> +}
> +
> +static void mtk_rtc_get_alarm_or_time(struct mtk_rtc *hw, struct rtc_time *tm,
> + int time_alarm)
> +{
> + u32 year, mon, mday, wday, hour, min, sec;
> +
> + /*
> + * Read again until all fields are not changed for all fields in the
> + * consistent state.
> + */
> + do {
> + year = mtk_r32(hw, MTK_RTC_TREG(time_alarm, MTK_YEA));
> + mon = mtk_r32(hw, MTK_RTC_TREG(time_alarm, MTK_MON));
> + wday = mtk_r32(hw, MTK_RTC_TREG(time_alarm, MTK_DOW));
> + mday = mtk_r32(hw, MTK_RTC_TREG(time_alarm, MTK_DOM));
> + hour = mtk_r32(hw, MTK_RTC_TREG(time_alarm, MTK_HOU));
> + min = mtk_r32(hw, MTK_RTC_TREG(time_alarm, MTK_MIN));
> + sec = mtk_r32(hw, MTK_RTC_TREG(time_alarm, MTK_SEC));
> + } while (year != mtk_r32(hw, MTK_RTC_TREG(time_alarm, MTK_YEA)) ||
> + mon != mtk_r32(hw, MTK_RTC_TREG(time_alarm, MTK_MON)) ||
> + mday != mtk_r32(hw, MTK_RTC_TREG(time_alarm, MTK_DOM)) ||
> + wday != mtk_r32(hw, MTK_RTC_TREG(time_alarm, MTK_DOW)) ||
> + hour != mtk_r32(hw, MTK_RTC_TREG(time_alarm, MTK_HOU)) ||
> + min != mtk_r32(hw, MTK_RTC_TREG(time_alarm, MTK_MIN)) ||
> + sec != mtk_r32(hw, MTK_RTC_TREG(time_alarm, MTK_SEC))
> + );
I'm pretty sure only checking sec is enough because it is highly
unlikely that 7 reads take a minute.
> +static irqreturn_t mtk_rtc_alarmirq(int irq, void *id)
> +{
> + struct mtk_rtc *hw = (struct mtk_rtc *)id;
> + u32 irq_sta;
> +
> + /* Stop alarm also implicitly disable the alarm interrupt */
> + mtk_w32(hw, MTK_RTC_AL_CTL, 0);
You stop the alarm here, before testing whether the alarm really
happened.
> + irq_sta = mtk_r32(hw, MTK_RTC_INT);
> + if (irq_sta & RTC_INT_AL_STA) {
> + rtc_update_irq(hw->rtc, 1, RTC_IRQF | RTC_AF);
> +
> + /* Ack alarm interrupt status */
> + mtk_w32(hw, MTK_RTC_INT, RTC_INT_AL_STA);
> + return IRQ_HANDLED;
> + }
> +
> + return IRQ_NONE;
> +}
> +
> +static int mtk_rtc_gettime(struct device *dev, struct rtc_time *tm)
> +{
> + struct mtk_rtc *hw = dev_get_drvdata(dev);
> +
> + mtk_rtc_get_alarm_or_time(hw, tm, MTK_TC);
> +
> + return rtc_valid_tm(tm);
> +}
> +
> +static int mtk_rtc_settime(struct device *dev, struct rtc_time *tm)
> +{
> + struct mtk_rtc *hw = dev_get_drvdata(dev);
> +
> + /* Stop time counter before setting a new one*/
> + mtk_set(hw, MTK_RTC_CTL, RTC_RC_STOP);
> +
> + /* Epoch == 1900 */
> + if (tm->tm_year < 100 || tm->tm_year > 199)
> + return -EINVAL;
Year is a 32 bits register, what makes the RTC fail in 2100? Is it
because of the leap year handling?
> +static int mtk_rtc_setalarm(struct device *dev, struct rtc_wkalrm *wkalrm)
> +{
> + struct mtk_rtc *hw = dev_get_drvdata(dev);
> + struct rtc_time *alrm_tm = &wkalrm->time;
> +
> + /* Epoch == 1900 */
> + if (alrm_tm->tm_year < 100 || alrm_tm->tm_year > 199)
> + return -EINVAL;
> +
Ditto.
> +
> + dev_info(&pdev->dev, "MediaTek SoC based RTC enabled\n");
> +
I think the rtc core is verbose enough that this message is not needed.
--
Alexandre Belloni, Free Electrons
Embedded Linux and Kernel engineering
http://free-electrons.com
^ permalink raw reply
* Re: [PATCH v1 24/25] kdb: Switch to use %pt
From: Andy Shevchenko @ 2017-10-12 17:05 UTC (permalink / raw)
To: Arnd Bergmann
Cc: Rasmus Villemoes, Greg Kroah-Hartman, Andrew Morton,
Linux Kernel Mailing List, Alessandro Zummo, Alexandre Belloni,
linux-rtc, Jason Wessel, Ingo Molnar
In-Reply-To: <CAK8P3a3RNAty5T8nR2F3JMJB2zYyeJQ0qvj0gJxa0QB57TcVuQ@mail.gmail.com>
On Thu, 2017-10-12 at 15:31 +0200, Arnd Bergmann wrote:
> On Thu, Jun 8, 2017 at 3:48 PM, Andy Shevchenko
> <andriy.shevchenko@linux.intel.com> wrote:
>
> > diff --git a/kernel/debug/kdb/kdb_main.c
> > b/kernel/debug/kdb/kdb_main.c
> > index c8146d53ca67..2a6f12be79d8 100644
> > --- a/kernel/debug/kdb/kdb_main.c
> > +++ b/kernel/debug/kdb/kdb_main.c
> > @@ -2556,12 +2556,7 @@ static int kdb_summary(int argc, const char
> > **argv)
> >
> > now = __current_kernel_time();
> > kdb_gmtime(&now, &tm);
> > - kdb_printf("date %04d-%02d-%02d %02d:%02d:%02d "
> > - "tz_minuteswest %d\n",
> > - 1900+tm.tm_year, tm.tm_mon+1, tm.tm_mday,
> > - tm.tm_hour, tm.tm_min, tm.tm_sec,
> > - sys_tz.tz_minuteswest);
> > -
>
> I just experimented with a similar change and noticed your version.
>
> You forgot to remove the kdb_gmtime() function that is now completely
> unneeded. My patch takes care of that now.
So, are you going to substitute entire series by your variant?
What did you choose to be format for the %p extension?
--
Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Intel Finland Oy
^ permalink raw reply
* Re: [PATCH v2 0/4] Make PL031 interrupt optional
From: Alexandre Belloni @ 2017-10-12 15:07 UTC (permalink / raw)
To: Russell King - ARM Linux
Cc: Alessandro Zummo, linux-rtc, Linus Walleij, linux-arm-kernel
In-Reply-To: <20170929102116.GX20805@n2100.armlinux.org.uk>
On 29/09/2017 at 11:21:16 +0100, Russell King - ARM Linux wrote:
> There are some boards out there which have a PL031 RTC, but its
> interrupt is not wired up. To support these, we need the PL031
> to support the primecell without interrupts.
>
> When no interrupt is present, there's little point exposing the
> RTC's alarm capabilities, so we omit the alarm-related function
> calls - the RTC merely becomes a source of time-of-day.
>
> This patch series cleans up the pl031 driver a little, and adds
> support for this configuration.
>
> drivers/rtc/rtc-pl031.c | 48 +++++++++++++++++++++++++++---------------------
> 1 file changed, 27 insertions(+), 21 deletions(-)
>
> v2: update patch 2 & 3 for review comment on v1.
>
Applied, thanks.
--
Alexandre Belloni, Free Electrons
Embedded Linux and Kernel engineering
http://free-electrons.com
^ permalink raw reply
page: next (older) | prev (newer) | latest
- recent:[subjects (threaded)|topics (new)|topics (active)]
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox