All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/2] rtc: digicolor: document device tree binding
@ 2015-03-23 13:28 ` Baruch Siach
  0 siblings, 0 replies; 8+ messages in thread
From: Baruch Siach @ 2015-03-23 13:28 UTC (permalink / raw)
  To: Alessandro Zummo, Andrew Morton
  Cc: rtc-linux-/JYPxA39Uh5TLH3MbocFFw,
	linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r,
	devicetree-u79uwXL29TY76Z2rM5mHXA, Baruch Siach

Add a device tree binding documentation to the Real Time Clock hardware block
on the Conexant CX92755 SoC. The CX92755 is from the Digicolor SoCs series.
Other SoCs in that series may share the same hardware block.

Cc: Alessandro Zummo <a.zummo-BfzFCNDTiLLj+vYz1yj4TQ@public.gmane.org>
Signed-off-by: Baruch Siach <baruch-NswTu9S1W3P6gbPvEgmw2w@public.gmane.org>
---
 Documentation/devicetree/bindings/rtc/digicolor-rtc.txt | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/rtc/digicolor-rtc.txt

diff --git a/Documentation/devicetree/bindings/rtc/digicolor-rtc.txt b/Documentation/devicetree/bindings/rtc/digicolor-rtc.txt
new file mode 100644
index 000000000000..d464986012cd
--- /dev/null
+++ b/Documentation/devicetree/bindings/rtc/digicolor-rtc.txt
@@ -0,0 +1,17 @@
+Conexant Digicolor Real Time Clock controller
+
+This binding currently supports the CX92755 SoC.
+
+Required properties:
+- compatible: should be "cnxt,cx92755-rtc"
+- reg: physical base address of the controller and length of memory mapped
+  region.
+- interrupts: rtc alarm interrupt
+
+Example:
+
+	rtc@f0000c30 {
+		compatible = "cnxt,cx92755-rtc";
+		reg = <0xf0000c30 0x18>;
+		interrupts = <25>;
+	};
-- 
2.1.4

--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH 1/2] rtc: digicolor: document device tree binding
@ 2015-03-23 13:28 ` Baruch Siach
  0 siblings, 0 replies; 8+ messages in thread
From: Baruch Siach @ 2015-03-23 13:28 UTC (permalink / raw)
  To: linux-arm-kernel

Add a device tree binding documentation to the Real Time Clock hardware block
on the Conexant CX92755 SoC. The CX92755 is from the Digicolor SoCs series.
Other SoCs in that series may share the same hardware block.

Cc: Alessandro Zummo <a.zummo@towertech.it>
Signed-off-by: Baruch Siach <baruch@tkos.co.il>
---
 Documentation/devicetree/bindings/rtc/digicolor-rtc.txt | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/rtc/digicolor-rtc.txt

diff --git a/Documentation/devicetree/bindings/rtc/digicolor-rtc.txt b/Documentation/devicetree/bindings/rtc/digicolor-rtc.txt
new file mode 100644
index 000000000000..d464986012cd
--- /dev/null
+++ b/Documentation/devicetree/bindings/rtc/digicolor-rtc.txt
@@ -0,0 +1,17 @@
+Conexant Digicolor Real Time Clock controller
+
+This binding currently supports the CX92755 SoC.
+
+Required properties:
+- compatible: should be "cnxt,cx92755-rtc"
+- reg: physical base address of the controller and length of memory mapped
+  region.
+- interrupts: rtc alarm interrupt
+
+Example:
+
+	rtc at f0000c30 {
+		compatible = "cnxt,cx92755-rtc";
+		reg = <0xf0000c30 0x18>;
+		interrupts = <25>;
+	};
-- 
2.1.4

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH 2/2] rtc: driver for Conexant Digicolor CX92755 on-chip RTC
  2015-03-23 13:28 ` Baruch Siach
@ 2015-03-23 13:28     ` Baruch Siach
  -1 siblings, 0 replies; 8+ messages in thread
From: Baruch Siach @ 2015-03-23 13:28 UTC (permalink / raw)
  To: Alessandro Zummo, Andrew Morton
  Cc: rtc-linux-/JYPxA39Uh5TLH3MbocFFw,
	linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r,
	devicetree-u79uwXL29TY76Z2rM5mHXA, Baruch Siach

Add driver for the RTC hardware block on the Conexant CX92755 SoC, from the
Digicolor series of SoCs. Tested on the Equinox evaluation board for the
CX92755 chip.

Cc: Alessandro Zummo <a.zummo-BfzFCNDTiLLj+vYz1yj4TQ@public.gmane.org>
Signed-off-by: Baruch Siach <baruch-NswTu9S1W3P6gbPvEgmw2w@public.gmane.org>
---
 drivers/rtc/Kconfig         |  10 ++
 drivers/rtc/Makefile        |   1 +
 drivers/rtc/rtc-digicolor.c | 227 ++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 238 insertions(+)
 create mode 100644 drivers/rtc/rtc-digicolor.c

diff --git a/drivers/rtc/Kconfig b/drivers/rtc/Kconfig
index b5b5c3d485d6..faeee2d2550b 100644
--- a/drivers/rtc/Kconfig
+++ b/drivers/rtc/Kconfig
@@ -1111,6 +1111,16 @@ config RTC_DRV_DAVINCI
 	  This driver can also be built as a module. If so, the module
 	  will be called rtc-davinci.
 
+config RTC_DRV_DIGICOLOR
+	tristate "Conexant Digicolor RTC"
+	depends on ARCH_DIGICOLOR
+	help
+	  If you say yes here you get support for the RTC on Conexant
+	  Digicolor platforms. This currently includes the CX92755 SoC.
+
+	  This driver can also be built as a module. If so, the module
+	  will be called rtc-digicolor.
+
 config RTC_DRV_IMXDI
 	tristate "Freescale IMX DryIce Real Time Clock"
 	depends on ARCH_MXC
diff --git a/drivers/rtc/Makefile b/drivers/rtc/Makefile
index 69c87062b098..c31731c29762 100644
--- a/drivers/rtc/Makefile
+++ b/drivers/rtc/Makefile
@@ -40,6 +40,7 @@ obj-$(CONFIG_RTC_DRV_DA9052)	+= rtc-da9052.o
 obj-$(CONFIG_RTC_DRV_DA9055)	+= rtc-da9055.o
 obj-$(CONFIG_RTC_DRV_DA9063)	+= rtc-da9063.o
 obj-$(CONFIG_RTC_DRV_DAVINCI)	+= rtc-davinci.o
+obj-$(CONFIG_RTC_DRV_DIGICOLOR)	+= rtc-digicolor.o
 obj-$(CONFIG_RTC_DRV_DM355EVM)	+= rtc-dm355evm.o
 obj-$(CONFIG_RTC_DRV_VRTC)	+= rtc-mrst.o
 obj-$(CONFIG_RTC_DRV_DS1216)	+= rtc-ds1216.o
diff --git a/drivers/rtc/rtc-digicolor.c b/drivers/rtc/rtc-digicolor.c
new file mode 100644
index 000000000000..658aeab0c161
--- /dev/null
+++ b/drivers/rtc/rtc-digicolor.c
@@ -0,0 +1,227 @@
+/*
+ * Real Time Clock driver for Conexant Digicolor
+ *
+ * Copyright (C) 2015 Paradox Innovation Ltd.
+ *
+ * Author: Baruch Siach <baruch-NswTu9S1W3P6gbPvEgmw2w@public.gmane.org>
+ *
+ * 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.
+ */
+
+#include <linux/io.h>
+#include <linux/iopoll.h>
+#include <linux/delay.h>
+#include <linux/module.h>
+#include <linux/platform_device.h>
+#include <linux/rtc.h>
+#include <linux/of.h>
+
+#define DC_RTC_CONTROL		0x0
+#define DC_RTC_TIME		0x8
+#define DC_RTC_REFERENCE	0xc
+#define DC_RTC_ALARM		0x10
+#define DC_RTC_INTFLAG_CLEAR	0x14
+#define DC_RTC_INTENABLE	0x16
+
+#define DC_RTC_CMD_MASK		0xf
+#define DC_RTC_GO_BUSY		BIT(7)
+
+#define CMD_NOP			0
+#define CMD_RESET		1
+#define CMD_WRITE		3
+#define CMD_READ		4
+
+#define CMD_DELAY_US		(10*1000)
+#define CMD_TIMEOUT_US		(500*CMD_DELAY_US)
+
+struct dc_rtc {
+	struct rtc_device	*rtc_dev;
+	void __iomem		*regs;
+};
+
+static int dc_rtc_cmds(struct dc_rtc *rtc, u8 *cmds, int len)
+{
+	u8 val;
+	int i, ret;
+
+	for (i = 0; i < len; i++) {
+		writeb_relaxed((cmds[i] & DC_RTC_CMD_MASK) | DC_RTC_GO_BUSY,
+			       rtc->regs + DC_RTC_CONTROL);
+		ret = readb_relaxed_poll_timeout(
+			rtc->regs + DC_RTC_CONTROL, val,
+			!(val & DC_RTC_GO_BUSY), CMD_DELAY_US, CMD_TIMEOUT_US);
+		if (ret < 0)
+			return ret;
+	}
+
+	return 0;
+}
+
+static int dc_rtc_read(struct dc_rtc *rtc, unsigned long *val)
+{
+	u8 read_cmds[] = {CMD_READ, CMD_NOP};
+	u32 reference, time1, time2;
+	int ret;
+
+	ret = dc_rtc_cmds(rtc, read_cmds, ARRAY_SIZE(read_cmds));
+	if (ret < 0)
+		return ret;
+
+	reference = readl_relaxed(rtc->regs + DC_RTC_REFERENCE);
+	time1 = readl_relaxed(rtc->regs + DC_RTC_TIME);
+	/* Read twice to ensure consistency */
+	while (1) {
+		time2 = readl_relaxed(rtc->regs + DC_RTC_TIME);
+		if (time1 == time2)
+			break;
+		time1 = time2;
+	}
+
+	*val = reference + time1;
+	return 0;
+}
+
+static int dc_rtc_write(struct dc_rtc *rtc, u32 val)
+{
+	u8 write_cmds[] = {CMD_WRITE, CMD_NOP, CMD_RESET, CMD_NOP};
+
+	writel_relaxed(val, rtc->regs + DC_RTC_REFERENCE);
+	return dc_rtc_cmds(rtc, write_cmds, ARRAY_SIZE(write_cmds));
+}
+
+static int dc_rtc_read_time(struct device *dev, struct rtc_time *tm)
+{
+	struct dc_rtc *rtc = dev_get_drvdata(dev);
+	unsigned long now;
+	int ret;
+
+	ret = dc_rtc_read(rtc, &now);
+	if (ret < 0)
+		return ret;
+	rtc_time64_to_tm(now, tm);
+
+	return 0;
+}
+
+static int dc_rtc_set_mmss(struct device *dev, unsigned long secs)
+{
+	struct dc_rtc *rtc = dev_get_drvdata(dev);
+
+	return dc_rtc_write(rtc, secs);
+}
+
+static int dc_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alarm)
+{
+	struct dc_rtc *rtc = dev_get_drvdata(dev);
+	u32 alarm_reg, reference;
+	unsigned long now;
+	int ret;
+
+	alarm_reg = readl_relaxed(rtc->regs + DC_RTC_ALARM);
+	reference = readl_relaxed(rtc->regs + DC_RTC_REFERENCE);
+	rtc_time64_to_tm(reference + alarm_reg, &alarm->time);
+
+	ret = dc_rtc_read(rtc, &now);
+	if (ret < 0)
+		return ret;
+
+	alarm->pending = alarm_reg + reference > now;
+	alarm->enabled = readl_relaxed(rtc->regs + DC_RTC_INTENABLE);
+
+	return 0;
+}
+
+static int dc_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alarm)
+{
+	struct dc_rtc *rtc = dev_get_drvdata(dev);
+	time64_t alarm_time;
+	u32 reference;
+
+	alarm_time = rtc_tm_to_time64(&alarm->time);
+
+	reference = readl_relaxed(rtc->regs + DC_RTC_REFERENCE);
+	writel_relaxed(alarm_time - reference, rtc->regs + DC_RTC_ALARM);
+
+	writeb_relaxed(!!alarm->enabled, rtc->regs + DC_RTC_INTENABLE);
+
+	return 0;
+}
+
+static int dc_rtc_alarm_irq_enable(struct device *dev, unsigned int enabled)
+{
+	struct dc_rtc *rtc = dev_get_drvdata(dev);
+
+	writeb_relaxed(!!enabled, rtc->regs + DC_RTC_INTENABLE);
+
+	return 0;
+}
+
+static struct rtc_class_ops dc_rtc_ops = {
+	.read_time		= dc_rtc_read_time,
+	.set_mmss		= dc_rtc_set_mmss,
+	.read_alarm		= dc_rtc_read_alarm,
+	.set_alarm		= dc_rtc_set_alarm,
+	.alarm_irq_enable	= dc_rtc_alarm_irq_enable,
+};
+
+static irqreturn_t dc_rtc_irq(int irq, void *dev_id)
+{
+	struct dc_rtc *rtc = dev_id;
+
+	writeb_relaxed(1, rtc->regs + DC_RTC_INTFLAG_CLEAR);
+	rtc_update_irq(rtc->rtc_dev, 1, RTC_AF | RTC_IRQF);
+
+	return IRQ_HANDLED;
+}
+
+static int __init dc_rtc_probe(struct platform_device *pdev)
+{
+	struct resource *res;
+	struct dc_rtc *rtc;
+	int irq, ret;
+
+	rtc = devm_kzalloc(&pdev->dev, sizeof(*rtc), GFP_KERNEL);
+	if (!rtc)
+		return -ENOMEM;
+
+	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+	rtc->regs = devm_ioremap_resource(&pdev->dev, res);
+	if (IS_ERR(rtc->regs))
+		return PTR_ERR(rtc->regs);
+
+	irq = platform_get_irq(pdev, 0);
+	if (irq < 0)
+		return irq;
+	ret = devm_request_irq(&pdev->dev, irq, dc_rtc_irq, 0, pdev->name, rtc);
+	if (ret < 0)
+		return ret;
+
+	platform_set_drvdata(pdev, rtc);
+	rtc->rtc_dev = devm_rtc_device_register(&pdev->dev, pdev->name,
+						&dc_rtc_ops, THIS_MODULE);
+	if (IS_ERR(rtc->rtc_dev))
+		return PTR_ERR(rtc->rtc_dev);
+
+	return 0;
+}
+
+static const struct of_device_id dc_dt_ids[] = {
+	{ .compatible = "cnxt,cx92755-rtc" },
+	{ /* sentinel */ }
+};
+MODULE_DEVICE_TABLE(of, dc_dt_ids);
+
+static struct platform_driver dc_rtc_driver = {
+	.driver = {
+		.name = "digicolor_rtc",
+		.of_match_table = of_match_ptr(dc_dt_ids),
+	},
+};
+module_platform_driver_probe(dc_rtc_driver, dc_rtc_probe);
+
+MODULE_AUTHOR("Baruch Siach <baruch-NswTu9S1W3P6gbPvEgmw2w@public.gmane.org>");
+MODULE_DESCRIPTION("Conexant Digicolor Realtime Clock Driver (RTC)");
+MODULE_LICENSE("GPL");
-- 
2.1.4

--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH 2/2] rtc: driver for Conexant Digicolor CX92755 on-chip RTC
@ 2015-03-23 13:28     ` Baruch Siach
  0 siblings, 0 replies; 8+ messages in thread
From: Baruch Siach @ 2015-03-23 13:28 UTC (permalink / raw)
  To: linux-arm-kernel

Add driver for the RTC hardware block on the Conexant CX92755 SoC, from the
Digicolor series of SoCs. Tested on the Equinox evaluation board for the
CX92755 chip.

Cc: Alessandro Zummo <a.zummo@towertech.it>
Signed-off-by: Baruch Siach <baruch@tkos.co.il>
---
 drivers/rtc/Kconfig         |  10 ++
 drivers/rtc/Makefile        |   1 +
 drivers/rtc/rtc-digicolor.c | 227 ++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 238 insertions(+)
 create mode 100644 drivers/rtc/rtc-digicolor.c

diff --git a/drivers/rtc/Kconfig b/drivers/rtc/Kconfig
index b5b5c3d485d6..faeee2d2550b 100644
--- a/drivers/rtc/Kconfig
+++ b/drivers/rtc/Kconfig
@@ -1111,6 +1111,16 @@ config RTC_DRV_DAVINCI
 	  This driver can also be built as a module. If so, the module
 	  will be called rtc-davinci.
 
+config RTC_DRV_DIGICOLOR
+	tristate "Conexant Digicolor RTC"
+	depends on ARCH_DIGICOLOR
+	help
+	  If you say yes here you get support for the RTC on Conexant
+	  Digicolor platforms. This currently includes the CX92755 SoC.
+
+	  This driver can also be built as a module. If so, the module
+	  will be called rtc-digicolor.
+
 config RTC_DRV_IMXDI
 	tristate "Freescale IMX DryIce Real Time Clock"
 	depends on ARCH_MXC
diff --git a/drivers/rtc/Makefile b/drivers/rtc/Makefile
index 69c87062b098..c31731c29762 100644
--- a/drivers/rtc/Makefile
+++ b/drivers/rtc/Makefile
@@ -40,6 +40,7 @@ obj-$(CONFIG_RTC_DRV_DA9052)	+= rtc-da9052.o
 obj-$(CONFIG_RTC_DRV_DA9055)	+= rtc-da9055.o
 obj-$(CONFIG_RTC_DRV_DA9063)	+= rtc-da9063.o
 obj-$(CONFIG_RTC_DRV_DAVINCI)	+= rtc-davinci.o
+obj-$(CONFIG_RTC_DRV_DIGICOLOR)	+= rtc-digicolor.o
 obj-$(CONFIG_RTC_DRV_DM355EVM)	+= rtc-dm355evm.o
 obj-$(CONFIG_RTC_DRV_VRTC)	+= rtc-mrst.o
 obj-$(CONFIG_RTC_DRV_DS1216)	+= rtc-ds1216.o
diff --git a/drivers/rtc/rtc-digicolor.c b/drivers/rtc/rtc-digicolor.c
new file mode 100644
index 000000000000..658aeab0c161
--- /dev/null
+++ b/drivers/rtc/rtc-digicolor.c
@@ -0,0 +1,227 @@
+/*
+ * Real Time Clock driver for Conexant Digicolor
+ *
+ * Copyright (C) 2015 Paradox Innovation Ltd.
+ *
+ * Author: Baruch Siach <baruch@tkos.co.il>
+ *
+ * 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.
+ */
+
+#include <linux/io.h>
+#include <linux/iopoll.h>
+#include <linux/delay.h>
+#include <linux/module.h>
+#include <linux/platform_device.h>
+#include <linux/rtc.h>
+#include <linux/of.h>
+
+#define DC_RTC_CONTROL		0x0
+#define DC_RTC_TIME		0x8
+#define DC_RTC_REFERENCE	0xc
+#define DC_RTC_ALARM		0x10
+#define DC_RTC_INTFLAG_CLEAR	0x14
+#define DC_RTC_INTENABLE	0x16
+
+#define DC_RTC_CMD_MASK		0xf
+#define DC_RTC_GO_BUSY		BIT(7)
+
+#define CMD_NOP			0
+#define CMD_RESET		1
+#define CMD_WRITE		3
+#define CMD_READ		4
+
+#define CMD_DELAY_US		(10*1000)
+#define CMD_TIMEOUT_US		(500*CMD_DELAY_US)
+
+struct dc_rtc {
+	struct rtc_device	*rtc_dev;
+	void __iomem		*regs;
+};
+
+static int dc_rtc_cmds(struct dc_rtc *rtc, u8 *cmds, int len)
+{
+	u8 val;
+	int i, ret;
+
+	for (i = 0; i < len; i++) {
+		writeb_relaxed((cmds[i] & DC_RTC_CMD_MASK) | DC_RTC_GO_BUSY,
+			       rtc->regs + DC_RTC_CONTROL);
+		ret = readb_relaxed_poll_timeout(
+			rtc->regs + DC_RTC_CONTROL, val,
+			!(val & DC_RTC_GO_BUSY), CMD_DELAY_US, CMD_TIMEOUT_US);
+		if (ret < 0)
+			return ret;
+	}
+
+	return 0;
+}
+
+static int dc_rtc_read(struct dc_rtc *rtc, unsigned long *val)
+{
+	u8 read_cmds[] = {CMD_READ, CMD_NOP};
+	u32 reference, time1, time2;
+	int ret;
+
+	ret = dc_rtc_cmds(rtc, read_cmds, ARRAY_SIZE(read_cmds));
+	if (ret < 0)
+		return ret;
+
+	reference = readl_relaxed(rtc->regs + DC_RTC_REFERENCE);
+	time1 = readl_relaxed(rtc->regs + DC_RTC_TIME);
+	/* Read twice to ensure consistency */
+	while (1) {
+		time2 = readl_relaxed(rtc->regs + DC_RTC_TIME);
+		if (time1 == time2)
+			break;
+		time1 = time2;
+	}
+
+	*val = reference + time1;
+	return 0;
+}
+
+static int dc_rtc_write(struct dc_rtc *rtc, u32 val)
+{
+	u8 write_cmds[] = {CMD_WRITE, CMD_NOP, CMD_RESET, CMD_NOP};
+
+	writel_relaxed(val, rtc->regs + DC_RTC_REFERENCE);
+	return dc_rtc_cmds(rtc, write_cmds, ARRAY_SIZE(write_cmds));
+}
+
+static int dc_rtc_read_time(struct device *dev, struct rtc_time *tm)
+{
+	struct dc_rtc *rtc = dev_get_drvdata(dev);
+	unsigned long now;
+	int ret;
+
+	ret = dc_rtc_read(rtc, &now);
+	if (ret < 0)
+		return ret;
+	rtc_time64_to_tm(now, tm);
+
+	return 0;
+}
+
+static int dc_rtc_set_mmss(struct device *dev, unsigned long secs)
+{
+	struct dc_rtc *rtc = dev_get_drvdata(dev);
+
+	return dc_rtc_write(rtc, secs);
+}
+
+static int dc_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alarm)
+{
+	struct dc_rtc *rtc = dev_get_drvdata(dev);
+	u32 alarm_reg, reference;
+	unsigned long now;
+	int ret;
+
+	alarm_reg = readl_relaxed(rtc->regs + DC_RTC_ALARM);
+	reference = readl_relaxed(rtc->regs + DC_RTC_REFERENCE);
+	rtc_time64_to_tm(reference + alarm_reg, &alarm->time);
+
+	ret = dc_rtc_read(rtc, &now);
+	if (ret < 0)
+		return ret;
+
+	alarm->pending = alarm_reg + reference > now;
+	alarm->enabled = readl_relaxed(rtc->regs + DC_RTC_INTENABLE);
+
+	return 0;
+}
+
+static int dc_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alarm)
+{
+	struct dc_rtc *rtc = dev_get_drvdata(dev);
+	time64_t alarm_time;
+	u32 reference;
+
+	alarm_time = rtc_tm_to_time64(&alarm->time);
+
+	reference = readl_relaxed(rtc->regs + DC_RTC_REFERENCE);
+	writel_relaxed(alarm_time - reference, rtc->regs + DC_RTC_ALARM);
+
+	writeb_relaxed(!!alarm->enabled, rtc->regs + DC_RTC_INTENABLE);
+
+	return 0;
+}
+
+static int dc_rtc_alarm_irq_enable(struct device *dev, unsigned int enabled)
+{
+	struct dc_rtc *rtc = dev_get_drvdata(dev);
+
+	writeb_relaxed(!!enabled, rtc->regs + DC_RTC_INTENABLE);
+
+	return 0;
+}
+
+static struct rtc_class_ops dc_rtc_ops = {
+	.read_time		= dc_rtc_read_time,
+	.set_mmss		= dc_rtc_set_mmss,
+	.read_alarm		= dc_rtc_read_alarm,
+	.set_alarm		= dc_rtc_set_alarm,
+	.alarm_irq_enable	= dc_rtc_alarm_irq_enable,
+};
+
+static irqreturn_t dc_rtc_irq(int irq, void *dev_id)
+{
+	struct dc_rtc *rtc = dev_id;
+
+	writeb_relaxed(1, rtc->regs + DC_RTC_INTFLAG_CLEAR);
+	rtc_update_irq(rtc->rtc_dev, 1, RTC_AF | RTC_IRQF);
+
+	return IRQ_HANDLED;
+}
+
+static int __init dc_rtc_probe(struct platform_device *pdev)
+{
+	struct resource *res;
+	struct dc_rtc *rtc;
+	int irq, ret;
+
+	rtc = devm_kzalloc(&pdev->dev, sizeof(*rtc), GFP_KERNEL);
+	if (!rtc)
+		return -ENOMEM;
+
+	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+	rtc->regs = devm_ioremap_resource(&pdev->dev, res);
+	if (IS_ERR(rtc->regs))
+		return PTR_ERR(rtc->regs);
+
+	irq = platform_get_irq(pdev, 0);
+	if (irq < 0)
+		return irq;
+	ret = devm_request_irq(&pdev->dev, irq, dc_rtc_irq, 0, pdev->name, rtc);
+	if (ret < 0)
+		return ret;
+
+	platform_set_drvdata(pdev, rtc);
+	rtc->rtc_dev = devm_rtc_device_register(&pdev->dev, pdev->name,
+						&dc_rtc_ops, THIS_MODULE);
+	if (IS_ERR(rtc->rtc_dev))
+		return PTR_ERR(rtc->rtc_dev);
+
+	return 0;
+}
+
+static const struct of_device_id dc_dt_ids[] = {
+	{ .compatible = "cnxt,cx92755-rtc" },
+	{ /* sentinel */ }
+};
+MODULE_DEVICE_TABLE(of, dc_dt_ids);
+
+static struct platform_driver dc_rtc_driver = {
+	.driver = {
+		.name = "digicolor_rtc",
+		.of_match_table = of_match_ptr(dc_dt_ids),
+	},
+};
+module_platform_driver_probe(dc_rtc_driver, dc_rtc_probe);
+
+MODULE_AUTHOR("Baruch Siach <baruch@tkos.co.il>");
+MODULE_DESCRIPTION("Conexant Digicolor Realtime Clock Driver (RTC)");
+MODULE_LICENSE("GPL");
-- 
2.1.4

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [PATCH 2/2] rtc: driver for Conexant Digicolor CX92755 on-chip RTC
  2015-03-23 13:28     ` Baruch Siach
@ 2015-03-23 22:33         ` Andrew Morton
  -1 siblings, 0 replies; 8+ messages in thread
From: Andrew Morton @ 2015-03-23 22:33 UTC (permalink / raw)
  To: Baruch Siach
  Cc: Alessandro Zummo, rtc-linux-/JYPxA39Uh5TLH3MbocFFw,
	linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r,
	devicetree-u79uwXL29TY76Z2rM5mHXA

On Mon, 23 Mar 2015 15:28:54 +0200 Baruch Siach <baruch-NswTu9S1W3P6gbPvEgmw2w@public.gmane.org> wrote:

> Add driver for the RTC hardware block on the Conexant CX92755 SoC, from the
> Digicolor series of SoCs. Tested on the Equinox evaluation board for the
> CX92755 chip.
> 
> ...
>
> +static int dc_rtc_read(struct dc_rtc *rtc, unsigned long *val)
> +{
> +	u8 read_cmds[] = {CMD_READ, CMD_NOP};
> +	u32 reference, time1, time2;
> +	int ret;
> +
> +	ret = dc_rtc_cmds(rtc, read_cmds, ARRAY_SIZE(read_cmds));

This is asking the compiler to build read_cmds[] on the stack each time
dc_rtc_read() is called.

If we instead create the array at compile time:

+++ a/drivers/rtc/rtc-digicolor.c
@@ -42,7 +42,7 @@ struct dc_rtc {
 	void __iomem		*regs;
 };
 
-static int dc_rtc_cmds(struct dc_rtc *rtc, u8 *cmds, int len)
+static int dc_rtc_cmds(struct dc_rtc *rtc, const u8 *cmds, int len)
 {
 	u8 val;
 	int i, ret;
@@ -62,7 +62,7 @@ static int dc_rtc_cmds(struct dc_rtc *rt
 
 static int dc_rtc_read(struct dc_rtc *rtc, unsigned long *val)
 {
-	u8 read_cmds[] = {CMD_READ, CMD_NOP};
+	static const u8 read_cmds[] = {CMD_READ, CMD_NOP};
 	u32 reference, time1, time2;
 	int ret;
 
@@ -86,7 +86,7 @@ static int dc_rtc_read(struct dc_rtc *rt
 
 static int dc_rtc_write(struct dc_rtc *rtc, u32 val)
 {
-	u8 write_cmds[] = {CMD_WRITE, CMD_NOP, CMD_RESET, CMD_NOP};
+	static const u8 write_cmds[] = {CMD_WRITE, CMD_NOP, CMD_RESET, CMD_NOP};
 
 	writel_relaxed(val, rtc->regs + DC_RTC_REFERENCE);
 	return dc_rtc_cmds(rtc, write_cmds, ARRAY_SIZE(write_cmds));

The code gets a bit smaller and faster:

   text    data     bss     dec     hex filename
   1628     400     512    2540     9ec drivers/rtc/rtc-digicolor.o-before
   1593     400     536    2529     9e1 drivers/rtc/rtc-digicolor.o-after


--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH 2/2] rtc: driver for Conexant Digicolor CX92755 on-chip RTC
@ 2015-03-23 22:33         ` Andrew Morton
  0 siblings, 0 replies; 8+ messages in thread
From: Andrew Morton @ 2015-03-23 22:33 UTC (permalink / raw)
  To: linux-arm-kernel

On Mon, 23 Mar 2015 15:28:54 +0200 Baruch Siach <baruch@tkos.co.il> wrote:

> Add driver for the RTC hardware block on the Conexant CX92755 SoC, from the
> Digicolor series of SoCs. Tested on the Equinox evaluation board for the
> CX92755 chip.
> 
> ...
>
> +static int dc_rtc_read(struct dc_rtc *rtc, unsigned long *val)
> +{
> +	u8 read_cmds[] = {CMD_READ, CMD_NOP};
> +	u32 reference, time1, time2;
> +	int ret;
> +
> +	ret = dc_rtc_cmds(rtc, read_cmds, ARRAY_SIZE(read_cmds));

This is asking the compiler to build read_cmds[] on the stack each time
dc_rtc_read() is called.

If we instead create the array at compile time:

+++ a/drivers/rtc/rtc-digicolor.c
@@ -42,7 +42,7 @@ struct dc_rtc {
 	void __iomem		*regs;
 };
 
-static int dc_rtc_cmds(struct dc_rtc *rtc, u8 *cmds, int len)
+static int dc_rtc_cmds(struct dc_rtc *rtc, const u8 *cmds, int len)
 {
 	u8 val;
 	int i, ret;
@@ -62,7 +62,7 @@ static int dc_rtc_cmds(struct dc_rtc *rt
 
 static int dc_rtc_read(struct dc_rtc *rtc, unsigned long *val)
 {
-	u8 read_cmds[] = {CMD_READ, CMD_NOP};
+	static const u8 read_cmds[] = {CMD_READ, CMD_NOP};
 	u32 reference, time1, time2;
 	int ret;
 
@@ -86,7 +86,7 @@ static int dc_rtc_read(struct dc_rtc *rt
 
 static int dc_rtc_write(struct dc_rtc *rtc, u32 val)
 {
-	u8 write_cmds[] = {CMD_WRITE, CMD_NOP, CMD_RESET, CMD_NOP};
+	static const u8 write_cmds[] = {CMD_WRITE, CMD_NOP, CMD_RESET, CMD_NOP};
 
 	writel_relaxed(val, rtc->regs + DC_RTC_REFERENCE);
 	return dc_rtc_cmds(rtc, write_cmds, ARRAY_SIZE(write_cmds));

The code gets a bit smaller and faster:

   text    data     bss     dec     hex filename
   1628     400     512    2540     9ec drivers/rtc/rtc-digicolor.o-before
   1593     400     536    2529     9e1 drivers/rtc/rtc-digicolor.o-after

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH 2/2] rtc: driver for Conexant Digicolor CX92755 on-chip RTC
  2015-03-23 22:33         ` Andrew Morton
@ 2015-03-24  5:31             ` Baruch Siach
  -1 siblings, 0 replies; 8+ messages in thread
From: Baruch Siach @ 2015-03-24  5:31 UTC (permalink / raw)
  To: Andrew Morton
  Cc: Alessandro Zummo, rtc-linux-/JYPxA39Uh5TLH3MbocFFw,
	linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r,
	devicetree-u79uwXL29TY76Z2rM5mHXA

Hi Andrew,

On Mon, Mar 23, 2015 at 03:33:34PM -0700, Andrew Morton wrote:
> On Mon, 23 Mar 2015 15:28:54 +0200 Baruch Siach <baruch-NswTu9S1W3P6gbPvEgmw2w@public.gmane.org> wrote:
> > Add driver for the RTC hardware block on the Conexant CX92755 SoC, from 
> > the
> > Digicolor series of SoCs. Tested on the Equinox evaluation board for the
> > CX92755 chip.
> > 
> > ...
> >
> > +static int dc_rtc_read(struct dc_rtc *rtc, unsigned long *val)
> > +{
> > +	u8 read_cmds[] = {CMD_READ, CMD_NOP};
> > +	u32 reference, time1, time2;
> > +	int ret;
> > +
> > +	ret = dc_rtc_cmds(rtc, read_cmds, ARRAY_SIZE(read_cmds));
> 
> This is asking the compiler to build read_cmds[] on the stack each time
> dc_rtc_read() is called.
> 
> If we instead create the array at compile time:
> 
> +++ a/drivers/rtc/rtc-digicolor.c
> @@ -42,7 +42,7 @@ struct dc_rtc {
>  	void __iomem		*regs;
>  };
>  
> -static int dc_rtc_cmds(struct dc_rtc *rtc, u8 *cmds, int len)
> +static int dc_rtc_cmds(struct dc_rtc *rtc, const u8 *cmds, int len)
>  {
>  	u8 val;
>  	int i, ret;
> @@ -62,7 +62,7 @@ static int dc_rtc_cmds(struct dc_rtc *rt
>  
>  static int dc_rtc_read(struct dc_rtc *rtc, unsigned long *val)
>  {
> -	u8 read_cmds[] = {CMD_READ, CMD_NOP};
> +	static const u8 read_cmds[] = {CMD_READ, CMD_NOP};
>  	u32 reference, time1, time2;
>  	int ret;
>  
> @@ -86,7 +86,7 @@ static int dc_rtc_read(struct dc_rtc *rt
>  
>  static int dc_rtc_write(struct dc_rtc *rtc, u32 val)
>  {
> -	u8 write_cmds[] = {CMD_WRITE, CMD_NOP, CMD_RESET, CMD_NOP};
> +	static const u8 write_cmds[] = {CMD_WRITE, CMD_NOP, CMD_RESET, CMD_NOP};
>  
>  	writel_relaxed(val, rtc->regs + DC_RTC_REFERENCE);
>  	return dc_rtc_cmds(rtc, write_cmds, ARRAY_SIZE(write_cmds));
> 
> The code gets a bit smaller and faster:
> 
>    text    data     bss     dec     hex filename
>    1628     400     512    2540     9ec drivers/rtc/rtc-digicolor.o-before
>    1593     400     536    2529     9e1 drivers/rtc/rtc-digicolor.o-after

Thanks for the tip, and for taking the driver through your tree.

baruch

-- 
     http://baruch.siach.name/blog/                  ~. .~   Tk Open Systems
=}------------------------------------------------ooO--U--Ooo------------{=
   - baruch-NswTu9S1W3P6gbPvEgmw2w@public.gmane.org - tel: +972.2.679.5364, http://www.tkos.co.il -
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH 2/2] rtc: driver for Conexant Digicolor CX92755 on-chip RTC
@ 2015-03-24  5:31             ` Baruch Siach
  0 siblings, 0 replies; 8+ messages in thread
From: Baruch Siach @ 2015-03-24  5:31 UTC (permalink / raw)
  To: linux-arm-kernel

Hi Andrew,

On Mon, Mar 23, 2015 at 03:33:34PM -0700, Andrew Morton wrote:
> On Mon, 23 Mar 2015 15:28:54 +0200 Baruch Siach <baruch@tkos.co.il> wrote:
> > Add driver for the RTC hardware block on the Conexant CX92755 SoC, from 
> > the
> > Digicolor series of SoCs. Tested on the Equinox evaluation board for the
> > CX92755 chip.
> > 
> > ...
> >
> > +static int dc_rtc_read(struct dc_rtc *rtc, unsigned long *val)
> > +{
> > +	u8 read_cmds[] = {CMD_READ, CMD_NOP};
> > +	u32 reference, time1, time2;
> > +	int ret;
> > +
> > +	ret = dc_rtc_cmds(rtc, read_cmds, ARRAY_SIZE(read_cmds));
> 
> This is asking the compiler to build read_cmds[] on the stack each time
> dc_rtc_read() is called.
> 
> If we instead create the array at compile time:
> 
> +++ a/drivers/rtc/rtc-digicolor.c
> @@ -42,7 +42,7 @@ struct dc_rtc {
>  	void __iomem		*regs;
>  };
>  
> -static int dc_rtc_cmds(struct dc_rtc *rtc, u8 *cmds, int len)
> +static int dc_rtc_cmds(struct dc_rtc *rtc, const u8 *cmds, int len)
>  {
>  	u8 val;
>  	int i, ret;
> @@ -62,7 +62,7 @@ static int dc_rtc_cmds(struct dc_rtc *rt
>  
>  static int dc_rtc_read(struct dc_rtc *rtc, unsigned long *val)
>  {
> -	u8 read_cmds[] = {CMD_READ, CMD_NOP};
> +	static const u8 read_cmds[] = {CMD_READ, CMD_NOP};
>  	u32 reference, time1, time2;
>  	int ret;
>  
> @@ -86,7 +86,7 @@ static int dc_rtc_read(struct dc_rtc *rt
>  
>  static int dc_rtc_write(struct dc_rtc *rtc, u32 val)
>  {
> -	u8 write_cmds[] = {CMD_WRITE, CMD_NOP, CMD_RESET, CMD_NOP};
> +	static const u8 write_cmds[] = {CMD_WRITE, CMD_NOP, CMD_RESET, CMD_NOP};
>  
>  	writel_relaxed(val, rtc->regs + DC_RTC_REFERENCE);
>  	return dc_rtc_cmds(rtc, write_cmds, ARRAY_SIZE(write_cmds));
> 
> The code gets a bit smaller and faster:
> 
>    text    data     bss     dec     hex filename
>    1628     400     512    2540     9ec drivers/rtc/rtc-digicolor.o-before
>    1593     400     536    2529     9e1 drivers/rtc/rtc-digicolor.o-after

Thanks for the tip, and for taking the driver through your tree.

baruch

-- 
     http://baruch.siach.name/blog/                  ~. .~   Tk Open Systems
=}------------------------------------------------ooO--U--Ooo------------{=
   - baruch at tkos.co.il - tel: +972.2.679.5364, http://www.tkos.co.il -

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2015-03-24  5:31 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-03-23 13:28 [PATCH 1/2] rtc: digicolor: document device tree binding Baruch Siach
2015-03-23 13:28 ` Baruch Siach
     [not found] ` <fa36a31a1d58d626ca0cb01ca0dece85aa2dfcb9.1427117334.git.baruch-NswTu9S1W3P6gbPvEgmw2w@public.gmane.org>
2015-03-23 13:28   ` [PATCH 2/2] rtc: driver for Conexant Digicolor CX92755 on-chip RTC Baruch Siach
2015-03-23 13:28     ` Baruch Siach
     [not found]     ` <374ef109005ed14c3a0052a9da5226b87f8dc215.1427117334.git.baruch-NswTu9S1W3P6gbPvEgmw2w@public.gmane.org>
2015-03-23 22:33       ` Andrew Morton
2015-03-23 22:33         ` Andrew Morton
     [not found]         ` <20150323153334.a373431dd5af6b669f716d83-de/tnXTf+JLsfHDXvbKv3WD2FQJk+8+b@public.gmane.org>
2015-03-24  5:31           ` Baruch Siach
2015-03-24  5:31             ` Baruch Siach

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.