All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/7] share sa1100 rtc driver to arch-mmp
@ 2012-02-21  9:04 Haojian Zhuang
  2012-02-21  9:04 ` [PATCH 1/7] rtc: sa1100: remove periodic code Haojian Zhuang
                   ` (9 more replies)
  0 siblings, 10 replies; 40+ messages in thread
From: Haojian Zhuang @ 2012-02-21  9:04 UTC (permalink / raw)
  To: linux-arm-kernel

Remove the hardcode definition of rtc registers, use ioremap() instead.
Append clk support for arch-mmp, so add dummy clk in arch-sa1100/arch-pxa.

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

* [PATCH 1/7] rtc: sa1100: remove periodic code
  2012-02-21  9:04 [PATCH 0/7] share sa1100 rtc driver to arch-mmp Haojian Zhuang
@ 2012-02-21  9:04 ` Haojian Zhuang
  2012-02-21  9:04 ` [PATCH 2/7] rtc: sa1100: remove verification code of alarm Haojian Zhuang
                   ` (8 subsequent siblings)
  9 siblings, 0 replies; 40+ messages in thread
From: Haojian Zhuang @ 2012-02-21  9:04 UTC (permalink / raw)
  To: linux-arm-kernel

Since periodic timer is already supported by hrtimer in rtc interface,
we needn't keep the duplicated code in rtc-sa1100.c any more.

Signed-off-by: Haojian Zhuang <haojian.zhuang@marvell.com>
---
 drivers/rtc/rtc-sa1100.c |   15 ---------------
 1 files changed, 0 insertions(+), 15 deletions(-)

diff --git a/drivers/rtc/rtc-sa1100.c b/drivers/rtc/rtc-sa1100.c
index cb9a585..fef52c8 100644
--- a/drivers/rtc/rtc-sa1100.c
+++ b/drivers/rtc/rtc-sa1100.c
@@ -42,19 +42,8 @@
 #define RTC_DEF_TRIM		0
 
 static const unsigned long RTC_FREQ = 1024;
-static struct rtc_time rtc_alarm;
 static DEFINE_SPINLOCK(sa1100_rtc_lock);
 
-static inline int rtc_periodic_alarm(struct rtc_time *tm)
-{
-	return  (tm->tm_year == -1) ||
-		((unsigned)tm->tm_mon >= 12) ||
-		((unsigned)(tm->tm_mday - 1) >= 31) ||
-		((unsigned)tm->tm_hour > 23) ||
-		((unsigned)tm->tm_min > 59) ||
-		((unsigned)tm->tm_sec > 59);
-}
-
 /*
  * Calculate the next alarm time given the requested alarm time mask
  * and the current time.
@@ -146,9 +135,6 @@ static irqreturn_t sa1100_rtc_interrupt(int irq, void *dev_id)
 
 	rtc_update_irq(rtc, 1, events);
 
-	if (rtsr & RTSR_AL && rtc_periodic_alarm(&rtc_alarm))
-		rtc_update_alarm(&rtc_alarm);
-
 	spin_unlock(&sa1100_rtc_lock);
 
 	return IRQ_HANDLED;
@@ -225,7 +211,6 @@ static int sa1100_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alrm)
 {
 	u32	rtsr;
 
-	memcpy(&alrm->time, &rtc_alarm, sizeof(struct rtc_time));
 	rtsr = RTSR;
 	alrm->enabled = (rtsr & RTSR_ALE) ? 1 : 0;
 	alrm->pending = (rtsr & RTSR_AL) ? 1 : 0;
-- 
1.7.0.4

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

* [PATCH 2/7] rtc: sa1100: remove verification code of alarm
  2012-02-21  9:04 [PATCH 0/7] share sa1100 rtc driver to arch-mmp Haojian Zhuang
  2012-02-21  9:04 ` [PATCH 1/7] rtc: sa1100: remove periodic code Haojian Zhuang
@ 2012-02-21  9:04 ` Haojian Zhuang
  2012-02-21  9:04 ` [PATCH 3/7] rtc: sa1100: use ioremap to map registers Haojian Zhuang
                   ` (7 subsequent siblings)
  9 siblings, 0 replies; 40+ messages in thread
From: Haojian Zhuang @ 2012-02-21  9:04 UTC (permalink / raw)
  To: linux-arm-kernel

Since next alarm time is already calculated in rtc common interface, we
needn't keep this logic in rtc-sa1100.c any more.

Signed-off-by: Haojian Zhuang <haojian.zhuang@marvell.com>
---
 drivers/rtc/rtc-sa1100.c |   66 +++++++--------------------------------------
 1 files changed, 11 insertions(+), 55 deletions(-)

diff --git a/drivers/rtc/rtc-sa1100.c b/drivers/rtc/rtc-sa1100.c
index fef52c8..91d58bd 100644
--- a/drivers/rtc/rtc-sa1100.c
+++ b/drivers/rtc/rtc-sa1100.c
@@ -44,54 +44,6 @@
 static const unsigned long RTC_FREQ = 1024;
 static DEFINE_SPINLOCK(sa1100_rtc_lock);
 
-/*
- * Calculate the next alarm time given the requested alarm time mask
- * and the current time.
- */
-static void rtc_next_alarm_time(struct rtc_time *next, struct rtc_time *now,
-	struct rtc_time *alrm)
-{
-	unsigned long next_time;
-	unsigned long now_time;
-
-	next->tm_year = now->tm_year;
-	next->tm_mon = now->tm_mon;
-	next->tm_mday = now->tm_mday;
-	next->tm_hour = alrm->tm_hour;
-	next->tm_min = alrm->tm_min;
-	next->tm_sec = alrm->tm_sec;
-
-	rtc_tm_to_time(now, &now_time);
-	rtc_tm_to_time(next, &next_time);
-
-	if (next_time < now_time) {
-		/* Advance one day */
-		next_time += 60 * 60 * 24;
-		rtc_time_to_tm(next_time, next);
-	}
-}
-
-static int rtc_update_alarm(struct rtc_time *alrm)
-{
-	struct rtc_time alarm_tm, now_tm;
-	unsigned long now, time;
-	int ret;
-
-	do {
-		now = RCNR;
-		rtc_time_to_tm(now, &now_tm);
-		rtc_next_alarm_time(&alarm_tm, &now_tm, alrm);
-		ret = rtc_tm_to_time(&alarm_tm, &time);
-		if (ret != 0)
-			break;
-
-		RTSR = RTSR & (RTSR_HZE|RTSR_ALE|RTSR_AL);
-		RTAR = time;
-	} while (now != RCNR);
-
-	return ret;
-}
-
 static irqreturn_t sa1100_rtc_interrupt(int irq, void *dev_id)
 {
 	struct platform_device *pdev = to_platform_device(dev_id);
@@ -219,16 +171,20 @@ static int sa1100_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alrm)
 
 static int sa1100_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alrm)
 {
+	unsigned long time;
 	int ret;
 
 	spin_lock_irq(&sa1100_rtc_lock);
-	ret = rtc_update_alarm(&alrm->time);
-	if (ret == 0) {
-		if (alrm->enabled)
-			RTSR |= RTSR_ALE;
-		else
-			RTSR &= ~RTSR_ALE;
-	}
+	ret = rtc_tm_to_time(&alrm->time, &time);
+	if (ret != 0)
+		goto out;
+	RTSR = RTSR & (RTSR_HZE|RTSR_ALE|RTSR_AL);
+	RTAR = time;
+	if (alrm->enabled)
+		RTSR |= RTSR_ALE;
+	else
+		RTSR &= ~RTSR_ALE;
+out:
 	spin_unlock_irq(&sa1100_rtc_lock);
 
 	return ret;
-- 
1.7.0.4

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

* [PATCH 3/7] rtc: sa1100: use ioremap to map registers
  2012-02-21  9:04 [PATCH 0/7] share sa1100 rtc driver to arch-mmp Haojian Zhuang
  2012-02-21  9:04 ` [PATCH 1/7] rtc: sa1100: remove periodic code Haojian Zhuang
  2012-02-21  9:04 ` [PATCH 2/7] rtc: sa1100: remove verification code of alarm Haojian Zhuang
@ 2012-02-21  9:04 ` Haojian Zhuang
  2012-02-22 12:33   ` Arnd Bergmann
                     ` (2 more replies)
  2012-02-21  9:04 ` [PATCH 4/7] ARM: sa1100: clean up of the clock support Haojian Zhuang
                   ` (6 subsequent siblings)
  9 siblings, 3 replies; 40+ messages in thread
From: Haojian Zhuang @ 2012-02-21  9:04 UTC (permalink / raw)
  To: linux-arm-kernel

Add resource definition of sa1100 rtc. And use ioremap to map rtc
registers to avoid including address definition of rtc register.
So the same driver could be shared on sa1100/pxa/mmp series.

Since there's two RTC wrappers on RTC module among PXA27x/PXA3xx/PXA95x,
keep treating the two wrappers as two RTC devices will result issues
of registering platform device. So only keep one RTC wrapper in
these silicons.

Signed-off-by: Haojian Zhuang <haojian.zhuang@marvell.com>
---
 arch/arm/mach-pxa/devices.c    |    6 +-
 arch/arm/mach-pxa/pxa27x.c     |    1 -
 arch/arm/mach-pxa/pxa3xx.c     |    1 -
 arch/arm/mach-pxa/pxa95x.c     |    1 -
 arch/arm/mach-sa1100/generic.c |   20 ++++
 drivers/rtc/Kconfig            |    4 +-
 drivers/rtc/rtc-sa1100.c       |  243 ++++++++++++++++++++++++++++++----------
 7 files changed, 211 insertions(+), 65 deletions(-)

diff --git a/arch/arm/mach-pxa/devices.c b/arch/arm/mach-pxa/devices.c
index 5bc1312..9fe7d6a 100644
--- a/arch/arm/mach-pxa/devices.c
+++ b/arch/arm/mach-pxa/devices.c
@@ -406,18 +406,22 @@ static struct resource pxa_rtc_resources[] = {
 	[1] = {
 		.start  = IRQ_RTC1Hz,
 		.end    = IRQ_RTC1Hz,
+		.name	= "rtc 1Hz",
 		.flags  = IORESOURCE_IRQ,
 	},
 	[2] = {
 		.start  = IRQ_RTCAlrm,
 		.end    = IRQ_RTCAlrm,
+		.name	= "rtc alarm",
 		.flags  = IORESOURCE_IRQ,
 	},
 };
 
 struct platform_device sa1100_device_rtc = {
-	.name		= "sa1100-rtc",
+	.name		= "pxa25x-rtc",
 	.id		= -1,
+	.num_resources	= ARRAY_SIZE(pxa_rtc_resources),
+	.resource	= pxa_rtc_resources,
 };
 
 struct platform_device pxa_device_rtc = {
diff --git a/arch/arm/mach-pxa/pxa27x.c b/arch/arm/mach-pxa/pxa27x.c
index aed6cbc..345fa7b 100644
--- a/arch/arm/mach-pxa/pxa27x.c
+++ b/arch/arm/mach-pxa/pxa27x.c
@@ -431,7 +431,6 @@ static struct platform_device *devices[] __initdata = {
 	&pxa_device_asoc_ssp3,
 	&pxa_device_asoc_platform,
 	&sa1100_device_rtc,
-	&pxa_device_rtc,
 	&pxa27x_device_ssp1,
 	&pxa27x_device_ssp2,
 	&pxa27x_device_ssp3,
diff --git a/arch/arm/mach-pxa/pxa3xx.c b/arch/arm/mach-pxa/pxa3xx.c
index 4f402af..d2437a8 100644
--- a/arch/arm/mach-pxa/pxa3xx.c
+++ b/arch/arm/mach-pxa/pxa3xx.c
@@ -428,7 +428,6 @@ static struct platform_device *devices[] __initdata = {
 	&pxa_device_asoc_ssp4,
 	&pxa_device_asoc_platform,
 	&sa1100_device_rtc,
-	&pxa_device_rtc,
 	&pxa27x_device_ssp1,
 	&pxa27x_device_ssp2,
 	&pxa27x_device_ssp3,
diff --git a/arch/arm/mach-pxa/pxa95x.c b/arch/arm/mach-pxa/pxa95x.c
index d082a58..b41e9f3 100644
--- a/arch/arm/mach-pxa/pxa95x.c
+++ b/arch/arm/mach-pxa/pxa95x.c
@@ -249,7 +249,6 @@ void __init pxa95x_set_i2c_power_info(struct i2c_pxa_platform_data *info)
 
 static struct platform_device *devices[] __initdata = {
 	&pxa_device_gpio,
-	&sa1100_device_rtc,
 	&pxa_device_rtc,
 	&pxa27x_device_ssp1,
 	&pxa27x_device_ssp2,
diff --git a/arch/arm/mach-sa1100/generic.c b/arch/arm/mach-sa1100/generic.c
index bb10ee2..04a62a3 100644
--- a/arch/arm/mach-sa1100/generic.c
+++ b/arch/arm/mach-sa1100/generic.c
@@ -345,9 +345,29 @@ void sa11x0_register_irda(struct irda_platform_data *irda)
 	sa11x0_register_device(&sa11x0ir_device, irda);
 }
 
+static struct resource sa1100_rtc_resources[] = {
+	{
+		.start	= 0x90010000,
+		.end	= 0x9001003f,
+		.flags	= IORESOURCE_MEM,
+	}, {
+		.start  = IRQ_RTC1Hz,
+		.end    = IRQ_RTC1Hz,
+		.name	= "rtc 1Hz",
+		.flags  = IORESOURCE_IRQ,
+	}, {
+		.start  = IRQ_RTCAlrm,
+		.end    = IRQ_RTCAlrm,
+		.name	= "rtc alarm",
+		.flags  = IORESOURCE_IRQ,
+	},
+};
+
 static struct platform_device sa11x0rtc_device = {
 	.name		= "sa1100-rtc",
 	.id		= -1,
+	.num_resources	= ARRAY_SIZE(sa1100_rtc_resources),
+	.resource	= sa1100_rtc_resources,
 };
 
 static struct platform_device *sa11x0_devices[] __initdata = {
diff --git a/drivers/rtc/Kconfig b/drivers/rtc/Kconfig
index 3a125b8..59efc63 100644
--- a/drivers/rtc/Kconfig
+++ b/drivers/rtc/Kconfig
@@ -773,8 +773,8 @@ config RTC_DRV_EP93XX
 	  will be called rtc-ep93xx.
 
 config RTC_DRV_SA1100
-	tristate "SA11x0/PXA2xx"
-	depends on ARCH_SA1100 || ARCH_PXA
+	tristate "SA11x0/PXA2xx/PXA910"
+	depends on ARCH_SA1100 || ARCH_PXA || ARCH_MMP
 	help
 	  If you say Y here you will get access to the real time clock
 	  built into your SA11x0 or PXA2xx CPU.
diff --git a/drivers/rtc/rtc-sa1100.c b/drivers/rtc/rtc-sa1100.c
index 91d58bd..90425ce 100644
--- a/drivers/rtc/rtc-sa1100.c
+++ b/drivers/rtc/rtc-sa1100.c
@@ -25,44 +25,101 @@
 #include <linux/module.h>
 #include <linux/rtc.h>
 #include <linux/init.h>
+#include <linux/io.h>
 #include <linux/fs.h>
 #include <linux/interrupt.h>
+#include <linux/slab.h>
 #include <linux/string.h>
 #include <linux/pm.h>
 #include <linux/bitops.h>
 
-#include <mach/hardware.h>
-#include <asm/irq.h>
-
-#ifdef CONFIG_ARCH_PXA
-#include <mach/regs-rtc.h>
-#endif
-
 #define RTC_DEF_DIVIDER		(32768 - 1)
 #define RTC_DEF_TRIM		0
+#define RTC_FREQ		1024
+
+#define RTSR_HZE		(1 << 3)	/* HZ interrupt enable */
+#define RTSR_ALE		(1 << 2)	/* RTC alarm interrupt enable */
+#define RTSR_HZ			(1 << 1)	/* HZ rising-edge detected */
+#define RTSR_AL			(1 << 0)	/* RTC alarm detected */
 
-static const unsigned long RTC_FREQ = 1024;
-static DEFINE_SPINLOCK(sa1100_rtc_lock);
+struct sa1100_reg_layout {
+	unsigned int	rcnr;			/* RTC Count Register */
+	unsigned int	rtar;			/* RTC Alarm Register */
+	unsigned int	rtsr;			/* RTC Status Register */
+	unsigned int	rttr;			/* RTC Timer Trim Register */
+
+};
+
+enum sa1100_rtc_types {
+	REGS_SA1100,
+	REGS_PXA25X,
+	REGS_PXA910,
+};
+
+struct sa1100_rtc {
+	spinlock_t		lock;
+	unsigned long		iobase;
+	unsigned long		iosize;
+	int			irq_1hz;
+	int			irq_alarm;
+	struct rtc_device	*rtc;
+
+	void __iomem		*reg_base;
+	void __iomem		*reg_rcnr;
+	void __iomem		*reg_rtar;
+	void __iomem		*reg_rtsr;
+	void __iomem		*reg_rttr;
+};
+
+static struct sa1100_reg_layout sa1100_layout[] = {
+	[REGS_SA1100] = {
+		.rcnr = 0x04,
+		.rtar = 0x00,
+		.rtsr = 0x10,
+		.rttr = 0x08,
+	},
+	[REGS_PXA25X] = {
+		.rcnr = 0x00,
+		.rtar = 0x04,
+		.rtsr = 0x08,
+		.rttr = 0x10,
+	},
+	[REGS_PXA910] = {
+		.rcnr = 0x00,
+		.rtar = 0x04,
+		.rtsr = 0x08,
+		.rttr = 0x0C,
+	},
+};
+
+static const struct platform_device_id sa1100_rtc_id_table[] = {
+	{ "sa1100-rtc",		REGS_SA1100 },
+	{ "pxa25x-rtc",		REGS_PXA25X },
+	{ "pxa910-rtc",		REGS_PXA910 },
+	{ },
+};
+MODULE_DEVICE_TABLE(platform, sa1100_rtc_id_table);
 
 static irqreturn_t sa1100_rtc_interrupt(int irq, void *dev_id)
 {
-	struct platform_device *pdev = to_platform_device(dev_id);
-	struct rtc_device *rtc = platform_get_drvdata(pdev);
+	struct sa1100_rtc *info = dev_get_drvdata(dev_id);
+	struct rtc_device *rtc = info->rtc;
 	unsigned int rtsr;
 	unsigned long events = 0;
 
-	spin_lock(&sa1100_rtc_lock);
+	spin_lock(&info->lock);
 
-	rtsr = RTSR;
+	rtsr = readl_relaxed(info->reg_rtsr);
 	/* clear interrupt sources */
-	RTSR = 0;
+	writel_relaxed(0, info->reg_rtsr);
+
 	/* Fix for a nasty initialization problem the in SA11xx RTSR register.
 	 * See also the comments in sa1100_rtc_probe(). */
 	if (rtsr & (RTSR_ALE | RTSR_HZE)) {
 		/* This is the original code, before there was the if test
 		 * above. This code does not clear interrupts that were not
 		 * enabled. */
-		RTSR = (RTSR_AL | RTSR_HZ) & (rtsr >> 2);
+		writel_relaxed((RTSR_AL|RTSR_HZ) & (rtsr >> 2), info->reg_rtsr);
 	} else {
 		/* For some reason, it is possible to enter this routine
 		 * without interruptions enabled, it has been tested with
@@ -71,13 +128,13 @@ static irqreturn_t sa1100_rtc_interrupt(int irq, void *dev_id)
 		 * This situation leads to an infinite "loop" of interrupt
 		 * routine calling and as a result the processor seems to
 		 * lock on its first call to open(). */
-		RTSR = RTSR_AL | RTSR_HZ;
+		writel_relaxed(RTSR_AL | RTSR_HZ, info->reg_rtsr);
 	}
 
 	/* clear alarm interrupt if it has occurred */
 	if (rtsr & RTSR_AL)
 		rtsr &= ~RTSR_ALE;
-	RTSR = rtsr & (RTSR_ALE | RTSR_HZE);
+	writel_relaxed(rtsr & (RTSR_ALE | RTSR_HZE), info->reg_rtsr);
 
 	/* update irq data & counter */
 	if (rtsr & RTSR_AL)
@@ -87,27 +144,27 @@ static irqreturn_t sa1100_rtc_interrupt(int irq, void *dev_id)
 
 	rtc_update_irq(rtc, 1, events);
 
-	spin_unlock(&sa1100_rtc_lock);
+	spin_unlock(&info->lock);
 
 	return IRQ_HANDLED;
 }
 
 static int sa1100_rtc_open(struct device *dev)
 {
+	struct sa1100_rtc *info = dev_get_drvdata(dev);
+	struct rtc_device *rtc = info->rtc;
 	int ret;
-	struct platform_device *plat_dev = to_platform_device(dev);
-	struct rtc_device *rtc = platform_get_drvdata(plat_dev);
 
-	ret = request_irq(IRQ_RTC1Hz, sa1100_rtc_interrupt, IRQF_DISABLED,
+	ret = request_irq(info->irq_1hz, sa1100_rtc_interrupt, IRQF_DISABLED,
 		"rtc 1Hz", dev);
 	if (ret) {
-		dev_err(dev, "IRQ %d already in use.\n", IRQ_RTC1Hz);
+		dev_err(dev, "IRQ %d already in use.\n", info->irq_1hz);
 		goto fail_ui;
 	}
-	ret = request_irq(IRQ_RTCAlrm, sa1100_rtc_interrupt, IRQF_DISABLED,
+	ret = request_irq(info->irq_alarm, sa1100_rtc_interrupt, IRQF_DISABLED,
 		"rtc Alrm", dev);
 	if (ret) {
-		dev_err(dev, "IRQ %d already in use.\n", IRQ_RTCAlrm);
+		dev_err(dev, "IRQ %d already in use.\n", info->irq_alarm);
 		goto fail_ai;
 	}
 	rtc->max_user_freq = RTC_FREQ;
@@ -116,54 +173,66 @@ static int sa1100_rtc_open(struct device *dev)
 	return 0;
 
  fail_ai:
-	free_irq(IRQ_RTC1Hz, dev);
+	free_irq(info->irq_1hz, dev);
  fail_ui:
 	return ret;
 }
 
 static void sa1100_rtc_release(struct device *dev)
 {
-	spin_lock_irq(&sa1100_rtc_lock);
-	RTSR = 0;
-	spin_unlock_irq(&sa1100_rtc_lock);
+	struct sa1100_rtc *info = dev_get_drvdata(dev);
+
+	spin_lock_irq(&info->lock);
+	writel_relaxed(0, info->reg_rtsr);
+	spin_unlock_irq(&info->lock);
 
-	free_irq(IRQ_RTCAlrm, dev);
-	free_irq(IRQ_RTC1Hz, dev);
+	free_irq(info->irq_alarm, dev);
+	free_irq(info->irq_1hz, dev);
 }
 
 static int sa1100_rtc_alarm_irq_enable(struct device *dev, unsigned int enabled)
 {
-	spin_lock_irq(&sa1100_rtc_lock);
+	struct sa1100_rtc *info = dev_get_drvdata(dev);
+	unsigned long rtsr;
+	spin_lock_irq(&info->lock);
+	rtsr = readl_relaxed(info->reg_rtsr);
 	if (enabled)
-		RTSR |= RTSR_ALE;
+		rtsr |= RTSR_ALE;
 	else
-		RTSR &= ~RTSR_ALE;
-	spin_unlock_irq(&sa1100_rtc_lock);
+		rtsr &= ~RTSR_ALE;
+	writel_relaxed(rtsr, info->reg_rtsr);
+	spin_unlock_irq(&info->lock);
 	return 0;
 }
 
 static int sa1100_rtc_read_time(struct device *dev, struct rtc_time *tm)
 {
-	rtc_time_to_tm(RCNR, tm);
+	struct sa1100_rtc *info = dev_get_drvdata(dev);
+	unsigned long rcnr;
+
+	rcnr = readl_relaxed(info->reg_rcnr);
+	rtc_time_to_tm(rcnr, tm);
 	return 0;
 }
 
 static int sa1100_rtc_set_time(struct device *dev, struct rtc_time *tm)
 {
+	struct sa1100_rtc *info = dev_get_drvdata(dev);
 	unsigned long time;
 	int ret;
 
 	ret = rtc_tm_to_time(tm, &time);
 	if (ret == 0)
-		RCNR = time;
+		writel_relaxed(time, info->reg_rcnr);
 	return ret;
 }
 
 static int sa1100_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alrm)
 {
+	struct sa1100_rtc *info = dev_get_drvdata(dev);
 	u32	rtsr;
 
-	rtsr = RTSR;
+	rtsr = readl_relaxed(info->reg_rtsr);
 	alrm->enabled = (rtsr & RTSR_ALE) ? 1 : 0;
 	alrm->pending = (rtsr & RTSR_AL) ? 1 : 0;
 	return 0;
@@ -171,29 +240,38 @@ static int sa1100_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alrm)
 
 static int sa1100_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alrm)
 {
-	unsigned long time;
+	struct sa1100_rtc *info = dev_get_drvdata(dev);
+	unsigned long time, rtsr;
 	int ret;
 
-	spin_lock_irq(&sa1100_rtc_lock);
+	spin_lock_irq(&info->lock);
 	ret = rtc_tm_to_time(&alrm->time, &time);
 	if (ret != 0)
 		goto out;
-	RTSR = RTSR & (RTSR_HZE|RTSR_ALE|RTSR_AL);
-	RTAR = time;
+	rtsr = readl_relaxed(info->reg_rtsr);
+	rtsr &= RTSR_HZE | RTSR_ALE | RTSR_AL;
+	writel_relaxed(rtsr, info->reg_rtsr);
+	writel_relaxed(time, info->reg_rtar);
 	if (alrm->enabled)
-		RTSR |= RTSR_ALE;
+		rtsr |= RTSR_ALE;
 	else
-		RTSR &= ~RTSR_ALE;
+		rtsr &= ~RTSR_ALE;
+	writel_relaxed(rtsr, info->reg_rtsr);
 out:
-	spin_unlock_irq(&sa1100_rtc_lock);
+	spin_unlock_irq(&info->lock);
 
 	return ret;
 }
 
 static int sa1100_rtc_proc(struct device *dev, struct seq_file *seq)
 {
-	seq_printf(seq, "trim/divider\t\t: 0x%08x\n", (u32) RTTR);
-	seq_printf(seq, "RTSR\t\t\t: 0x%08x\n", (u32)RTSR);
+	struct sa1100_rtc *info = dev_get_drvdata(dev);
+	unsigned long rttr, rtsr;
+
+	rttr = readl_relaxed(info->reg_rttr);
+	rtsr = readl_relaxed(info->reg_rtsr);
+	seq_printf(seq, "trim/divider\t\t: 0x%08x\n", (u32)rttr);
+	seq_printf(seq, "RTSR\t\t\t: 0x%08x\n", (u32)rtsr);
 
 	return 0;
 }
@@ -211,7 +289,39 @@ static const struct rtc_class_ops sa1100_rtc_ops = {
 
 static int sa1100_rtc_probe(struct platform_device *pdev)
 {
+	const struct platform_device_id *id = platform_get_device_id(pdev);
+	enum sa1100_rtc_types rtc_type = id->driver_data;
 	struct rtc_device *rtc;
+	struct resource *res;
+	struct sa1100_rtc *info;
+	int irq_1hz, irq_alarm, ret = 0;
+
+	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+	irq_1hz = platform_get_irq_byname(pdev, "rtc 1Hz");
+	irq_alarm = platform_get_irq_byname(pdev, "rtc alarm");
+	if (res == NULL || irq_1hz < 0 || irq_alarm < 0)
+		return -ENODEV;
+
+	info = kzalloc(sizeof(struct sa1100_rtc), GFP_KERNEL);
+	if (!info)
+		return -ENOMEM;
+
+	info->iobase = res->start;
+	info->iosize = resource_size(res);
+	info->irq_1hz = irq_1hz;
+	info->irq_alarm = irq_alarm;
+	spin_lock_init(&info->lock);
+	platform_set_drvdata(pdev, info);
+
+	info->reg_base = ioremap(info->iobase, info->iosize);
+	if (!info->reg_base) {
+		ret = -EIO;
+		goto err_map;
+	}
+	info->reg_rcnr = info->reg_base + sa1100_layout[rtc_type].rcnr;
+	info->reg_rtar = info->reg_base + sa1100_layout[rtc_type].rtar;
+	info->reg_rtsr = info->reg_base + sa1100_layout[rtc_type].rtsr;
+	info->reg_rttr = info->reg_base + sa1100_layout[rtc_type].rttr;
 
 	/*
 	 * According to the manual we should be able to let RTTR be zero
@@ -220,12 +330,13 @@ static int sa1100_rtc_probe(struct platform_device *pdev)
 	 * If the clock divider is uninitialized then reset it to the
 	 * default value to get the 1Hz clock.
 	 */
-	if (RTTR == 0) {
-		RTTR = RTC_DEF_DIVIDER + (RTC_DEF_TRIM << 16);
+	if (readl_relaxed(info->reg_rttr) == 0) {
+		writel_relaxed(RTC_DEF_DIVIDER + (RTC_DEF_TRIM << 16),
+				info->reg_rttr);
 		dev_warn(&pdev->dev, "warning: "
 			"initializing default clock divider/trim value\n");
 		/* The current RTC value probably doesn't make sense either */
-		RCNR = 0;
+		writel_relaxed(0, info->reg_rcnr);
 	}
 
 	device_init_wakeup(&pdev->dev, 1);
@@ -233,10 +344,11 @@ static int sa1100_rtc_probe(struct platform_device *pdev)
 	rtc = rtc_device_register(pdev->name, &pdev->dev, &sa1100_rtc_ops,
 		THIS_MODULE);
 
-	if (IS_ERR(rtc))
-		return PTR_ERR(rtc);
-
-	platform_set_drvdata(pdev, rtc);
+	if (IS_ERR(rtc)) {
+		ret = PTR_ERR(rtc);
+		goto err_dev;
+	}
+	info->rtc = rtc;
 
 	/* Fix for a nasty initialization problem the in SA11xx RTSR register.
 	 * See also the comments in sa1100_rtc_interrupt().
@@ -260,17 +372,27 @@ static int sa1100_rtc_probe(struct platform_device *pdev)
 	 *
 	 * Notice that clearing bit 1 and 0 is accomplished by writting ONES to
 	 * the corresponding bits in RTSR. */
-	RTSR = RTSR_AL | RTSR_HZ;
+	writel_relaxed(RTSR_AL | RTSR_HZ, info->reg_rtsr);
 
 	return 0;
+err_dev:
+	iounmap(info->reg_base);
+err_map:
+	platform_set_drvdata(pdev, NULL);
+	kfree(info);
+	return ret;
 }
 
 static int sa1100_rtc_remove(struct platform_device *pdev)
 {
-	struct rtc_device *rtc = platform_get_drvdata(pdev);
+	struct sa1100_rtc *info = platform_get_drvdata(pdev);
 
-	if (rtc)
-		rtc_device_unregister(rtc);
+	if (info) {
+		rtc_device_unregister(info->rtc);
+		platform_set_drvdata(pdev, NULL);
+		iounmap(info->reg_base);
+		kfree(info);
+	}
 
 	return 0;
 }
@@ -278,15 +400,17 @@ static int sa1100_rtc_remove(struct platform_device *pdev)
 #ifdef CONFIG_PM
 static int sa1100_rtc_suspend(struct device *dev)
 {
+	struct sa1100_rtc *info = dev_get_drvdata(dev);
 	if (device_may_wakeup(dev))
-		enable_irq_wake(IRQ_RTCAlrm);
+		enable_irq_wake(info->irq_alarm);
 	return 0;
 }
 
 static int sa1100_rtc_resume(struct device *dev)
 {
+	struct sa1100_rtc *info = dev_get_drvdata(dev);
 	if (device_may_wakeup(dev))
-		disable_irq_wake(IRQ_RTCAlrm);
+		disable_irq_wake(info->irq_alarm);
 	return 0;
 }
 
@@ -305,6 +429,7 @@ static struct platform_driver sa1100_rtc_driver = {
 		.pm	= &sa1100_rtc_pm_ops,
 #endif
 	},
+	.id_table	= sa1100_rtc_id_table,
 };
 
 module_platform_driver(sa1100_rtc_driver);
-- 
1.7.0.4

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

* [PATCH 4/7] ARM: sa1100: clean up of the clock support
  2012-02-21  9:04 [PATCH 0/7] share sa1100 rtc driver to arch-mmp Haojian Zhuang
                   ` (2 preceding siblings ...)
  2012-02-21  9:04 ` [PATCH 3/7] rtc: sa1100: use ioremap to map registers Haojian Zhuang
@ 2012-02-21  9:04 ` Haojian Zhuang
  2012-02-22 12:31   ` Arnd Bergmann
  2012-02-23 10:32   ` Russell King - ARM Linux
  2012-02-21  9:04 ` [PATCH 5/7] ARM: pxa: add rtc dummy clock Haojian Zhuang
                   ` (5 subsequent siblings)
  9 siblings, 2 replies; 40+ messages in thread
From: Haojian Zhuang @ 2012-02-21  9:04 UTC (permalink / raw)
  To: linux-arm-kernel

From: Jett.Zhou <jtzhou@marvell.com>

Signed-off-by: Jett.Zhou <jtzhou@marvell.com>
signed-off-by: Haojian Zhuang <haojian.zhuang@marvell.com>
---
 arch/arm/Kconfig             |    2 +-
 arch/arm/mach-sa1100/clock.c |   91 ++++++++++++++++++++++++++++++-----------
 2 files changed, 67 insertions(+), 26 deletions(-)

diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig
index a48aecc..6e40039 100644
--- a/arch/arm/Kconfig
+++ b/arch/arm/Kconfig
@@ -754,7 +754,7 @@ config ARCH_SA1100
 	select ARCH_HAS_CPUFREQ
 	select CPU_FREQ
 	select GENERIC_CLOCKEVENTS
-	select HAVE_CLK
+	select CLKDEV_LOOKUP
 	select HAVE_SCHED_CLOCK
 	select TICK_ONESHOT
 	select ARCH_REQUIRE_GPIOLIB
diff --git a/arch/arm/mach-sa1100/clock.c b/arch/arm/mach-sa1100/clock.c
index dab3c63..d6df9f6 100644
--- a/arch/arm/mach-sa1100/clock.c
+++ b/arch/arm/mach-sa1100/clock.c
@@ -11,17 +11,39 @@
 #include <linux/clk.h>
 #include <linux/spinlock.h>
 #include <linux/mutex.h>
+#include <linux/io.h>
+#include <linux/clkdev.h>
 
 #include <mach/hardware.h>
 
-/*
- * Very simple clock implementation - we only have one clock to deal with.
- */
+struct clkops {
+	void			(*enable)(struct clk *);
+	void			(*disable)(struct clk *);
+	unsigned long		(*getrate)(struct clk *);
+};
+
 struct clk {
+	const struct clkops	*ops;
+	unsigned long		rate;
 	unsigned int		enabled;
 };
 
-static void clk_gpio27_enable(void)
+#define INIT_CLKREG(_clk, _devname, _conname)		\
+	{						\
+		.clk		= _clk,			\
+		.dev_id		= _devname,		\
+		.con_id		= _conname,		\
+	}
+
+#define DEFINE_CLK(_name, _ops, _rate)			\
+struct clk clk_##_name = {				\
+		.ops	= _ops,				\
+		.rate	= _rate,			\
+	}
+
+static DEFINE_SPINLOCK(clocks_lock);
+
+static void clk_gpio27_enable(struct clk *clk)
 {
 	/*
 	 * First, set up the 3.6864MHz clock on GPIO 27 for the SA-1111:
@@ -32,38 +54,22 @@ static void clk_gpio27_enable(void)
 	TUCR = TUCR_3_6864MHz;
 }
 
-static void clk_gpio27_disable(void)
+static void clk_gpio27_disable(struct clk *clk)
 {
 	TUCR = 0;
 	GPDR &= ~GPIO_32_768kHz;
 	GAFR &= ~GPIO_32_768kHz;
 }
 
-static struct clk clk_gpio27;
-
-static DEFINE_SPINLOCK(clocks_lock);
-
-struct clk *clk_get(struct device *dev, const char *id)
-{
-	const char *devname = dev_name(dev);
-
-	return strcmp(devname, "sa1111.0") ? ERR_PTR(-ENOENT) : &clk_gpio27;
-}
-EXPORT_SYMBOL(clk_get);
-
-void clk_put(struct clk *clk)
-{
-}
-EXPORT_SYMBOL(clk_put);
-
 int clk_enable(struct clk *clk)
 {
 	unsigned long flags;
 
 	spin_lock_irqsave(&clocks_lock, flags);
 	if (clk->enabled++ == 0)
-		clk_gpio27_enable();
+		clk->ops->enable(clk);
 	spin_unlock_irqrestore(&clocks_lock, flags);
+
 	return 0;
 }
 EXPORT_SYMBOL(clk_enable);
@@ -76,13 +82,48 @@ void clk_disable(struct clk *clk)
 
 	spin_lock_irqsave(&clocks_lock, flags);
 	if (--clk->enabled == 0)
-		clk_gpio27_disable();
+		clk->ops->disable(clk);
 	spin_unlock_irqrestore(&clocks_lock, flags);
 }
 EXPORT_SYMBOL(clk_disable);
 
 unsigned long clk_get_rate(struct clk *clk)
 {
-	return 3686400;
+	unsigned long rate;
+
+	rate = clk->rate;
+	if (clk->ops->getrate)
+		rate = clk->ops->getrate(clk);
+
+	return rate;
 }
 EXPORT_SYMBOL(clk_get_rate);
+
+const struct clkops clk_gpio27_ops = {
+	.enable		= clk_gpio27_enable,
+	.disable	= clk_gpio27_disable,
+};
+
+static void clk_dummy_enable(struct clk *clk) { }
+static void clk_dummy_disable(struct clk *clk) { }
+
+const struct clkops clk_dummy_ops = {
+	.enable		= clk_dummy_enable,
+	.disable	= clk_dummy_disable,
+};
+
+static DEFINE_CLK(gpio27, &clk_gpio27_ops, 3686400);
+static DEFINE_CLK(dummy, &clk_dummy_ops, 0);
+
+static struct clk_lookup sa11xx_clkregs[] = {
+	INIT_CLKREG(&clk_gpio27, "sa1111.0", NULL),
+	INIT_CLKREG(&clk_dummy, "sa1100-rtc", NULL),
+};
+
+static int __init sa11xx_clk_init(void)
+{
+	clkdev_add_table(sa11xx_clkregs, ARRAY_SIZE(sa11xx_clkregs));
+	return 0;
+}
+
+postcore_initcall(sa11xx_clk_init);
-- 
1.7.0.4

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

* [PATCH 5/7] ARM: pxa: add rtc dummy clock
  2012-02-21  9:04 [PATCH 0/7] share sa1100 rtc driver to arch-mmp Haojian Zhuang
                   ` (3 preceding siblings ...)
  2012-02-21  9:04 ` [PATCH 4/7] ARM: sa1100: clean up of the clock support Haojian Zhuang
@ 2012-02-21  9:04 ` Haojian Zhuang
  2012-02-21  9:04 ` [PATCH 6/7] rtc: sa1100: enable clk support Haojian Zhuang
                   ` (4 subsequent siblings)
  9 siblings, 0 replies; 40+ messages in thread
From: Haojian Zhuang @ 2012-02-21  9:04 UTC (permalink / raw)
  To: linux-arm-kernel

sa1100-rtc driver could be shared among sa1100/pxa/mmp series silicon.
Since clk is used in mmp series silicon, add dummy clock support in
pxa also.

Signed-off-by: Haojian Zhuang <haojian.zhuang@marvell.com>
---
 arch/arm/mach-pxa/pxa25x.c |    1 +
 arch/arm/mach-pxa/pxa27x.c |    1 +
 arch/arm/mach-pxa/pxa3xx.c |    1 +
 arch/arm/mach-pxa/pxa95x.c |    1 +
 4 files changed, 4 insertions(+), 0 deletions(-)

diff --git a/arch/arm/mach-pxa/pxa25x.c b/arch/arm/mach-pxa/pxa25x.c
index 91e4f6c..8d8c3ef 100644
--- a/arch/arm/mach-pxa/pxa25x.c
+++ b/arch/arm/mach-pxa/pxa25x.c
@@ -209,6 +209,7 @@ static struct clk_lookup pxa25x_clkregs[] = {
 	INIT_CLKREG(&clk_pxa25x_gpio11, NULL, "GPIO11_CLK"),
 	INIT_CLKREG(&clk_pxa25x_gpio12, NULL, "GPIO12_CLK"),
 	INIT_CLKREG(&clk_pxa25x_mem, "pxa2xx-pcmcia", NULL),
+	INIT_CLKREG(&clk_dummy, "pxa25x-rtc", NULL),
 };
 
 static struct clk_lookup pxa25x_hwuart_clkreg =
diff --git a/arch/arm/mach-pxa/pxa27x.c b/arch/arm/mach-pxa/pxa27x.c
index 345fa7b..f95977f 100644
--- a/arch/arm/mach-pxa/pxa27x.c
+++ b/arch/arm/mach-pxa/pxa27x.c
@@ -230,6 +230,7 @@ static struct clk_lookup pxa27x_clkregs[] = {
 	INIT_CLKREG(&clk_pxa27x_im, NULL, "IMCLK"),
 	INIT_CLKREG(&clk_pxa27x_memc, NULL, "MEMCLK"),
 	INIT_CLKREG(&clk_pxa27x_mem, "pxa2xx-pcmcia", NULL),
+	INIT_CLKREG(&clk_dummy, "pxa25x-rtc", NULL),
 };
 
 #ifdef CONFIG_PM
diff --git a/arch/arm/mach-pxa/pxa3xx.c b/arch/arm/mach-pxa/pxa3xx.c
index d2437a8..4b01eee 100644
--- a/arch/arm/mach-pxa/pxa3xx.c
+++ b/arch/arm/mach-pxa/pxa3xx.c
@@ -89,6 +89,7 @@ static struct clk_lookup pxa3xx_clkregs[] = {
 	INIT_CLKREG(&clk_pxa3xx_mmc2, "pxa2xx-mci.1", NULL),
 	INIT_CLKREG(&clk_pxa3xx_smemc, "pxa2xx-pcmcia", NULL),
 	INIT_CLKREG(&clk_pxa3xx_gpio, "pxa-gpio", NULL),
+	INIT_CLKREG(&clk_dummy, "pxa25x-rtc", NULL),
 };
 
 #ifdef CONFIG_PM
diff --git a/arch/arm/mach-pxa/pxa95x.c b/arch/arm/mach-pxa/pxa95x.c
index b41e9f3..0273801 100644
--- a/arch/arm/mach-pxa/pxa95x.c
+++ b/arch/arm/mach-pxa/pxa95x.c
@@ -231,6 +231,7 @@ static struct clk_lookup pxa95x_clkregs[] = {
 	INIT_CLKREG(&clk_pxa95x_pwm0, "pxa27x-pwm.0", NULL),
 	INIT_CLKREG(&clk_pxa95x_pwm1, "pxa27x-pwm.1", NULL),
 	INIT_CLKREG(&clk_pxa95x_gpio, "pxa-gpio", NULL),
+	INIT_CLKREG(&clk_dummy, "pxa25x-rtc", NULL),
 };
 
 void __init pxa95x_init_irq(void)
-- 
1.7.0.4

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

* [PATCH 6/7] rtc: sa1100: enable clk support
  2012-02-21  9:04 [PATCH 0/7] share sa1100 rtc driver to arch-mmp Haojian Zhuang
                   ` (4 preceding siblings ...)
  2012-02-21  9:04 ` [PATCH 5/7] ARM: pxa: add rtc dummy clock Haojian Zhuang
@ 2012-02-21  9:04 ` Haojian Zhuang
  2012-02-22 12:29   ` Arnd Bergmann
  2012-02-23 10:34   ` Russell King - ARM Linux
  2012-02-21  9:04 ` [PATCH 7/7] ARM: mmp: enable rtc Haojian Zhuang
                   ` (3 subsequent siblings)
  9 siblings, 2 replies; 40+ messages in thread
From: Haojian Zhuang @ 2012-02-21  9:04 UTC (permalink / raw)
  To: linux-arm-kernel

Add clk support in sa1100 rtc.

Signed-off-by: Haojian Zhuang <haojian.zhuang@marvell.com>
---
 drivers/rtc/rtc-sa1100.c |   14 ++++++++++++++
 1 files changed, 14 insertions(+), 0 deletions(-)

diff --git a/drivers/rtc/rtc-sa1100.c b/drivers/rtc/rtc-sa1100.c
index 90425ce..f031f4d 100644
--- a/drivers/rtc/rtc-sa1100.c
+++ b/drivers/rtc/rtc-sa1100.c
@@ -23,6 +23,7 @@
 
 #include <linux/platform_device.h>
 #include <linux/module.h>
+#include <linux/clk.h>
 #include <linux/rtc.h>
 #include <linux/init.h>
 #include <linux/io.h>
@@ -63,6 +64,7 @@ struct sa1100_rtc {
 	int			irq_1hz;
 	int			irq_alarm;
 	struct rtc_device	*rtc;
+	struct clk		*clk;
 
 	void __iomem		*reg_base;
 	void __iomem		*reg_rcnr;
@@ -306,6 +308,13 @@ static int sa1100_rtc_probe(struct platform_device *pdev)
 	if (!info)
 		return -ENOMEM;
 
+	info->clk = clk_get(&pdev->dev, NULL);
+	if (IS_ERR(info->clk)) {
+		dev_err(&pdev->dev, "failed to find rtc clock source\n");
+		ret = PTR_ERR(info->clk);
+		goto err_clk;
+	}
+	clk_prepare_enable(info->clk);
 	info->iobase = res->start;
 	info->iosize = resource_size(res);
 	info->irq_1hz = irq_1hz;
@@ -379,6 +388,9 @@ err_dev:
 	iounmap(info->reg_base);
 err_map:
 	platform_set_drvdata(pdev, NULL);
+	clk_disable_unprepare(info->clk);
+	clk_put(info->clk);
+err_clk:
 	kfree(info);
 	return ret;
 }
@@ -391,6 +403,8 @@ static int sa1100_rtc_remove(struct platform_device *pdev)
 		rtc_device_unregister(info->rtc);
 		platform_set_drvdata(pdev, NULL);
 		iounmap(info->reg_base);
+		clk_disable_unprepare(info->clk);
+		clk_put(info->clk);
 		kfree(info);
 	}
 
-- 
1.7.0.4

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

* [PATCH 7/7] ARM: mmp: enable rtc
  2012-02-21  9:04 [PATCH 0/7] share sa1100 rtc driver to arch-mmp Haojian Zhuang
                   ` (5 preceding siblings ...)
  2012-02-21  9:04 ` [PATCH 6/7] rtc: sa1100: enable clk support Haojian Zhuang
@ 2012-02-21  9:04 ` Haojian Zhuang
       [not found]   ` <1329815642.22876.YahooMailNeo@web162001.mail.bf1.yahoo.com>
  2012-02-21 15:37 ` [PATCH 0/7] share sa1100 rtc driver to arch-mmp Jean-Christophe PLAGNIOL-VILLARD
                   ` (2 subsequent siblings)
  9 siblings, 1 reply; 40+ messages in thread
From: Haojian Zhuang @ 2012-02-21  9:04 UTC (permalink / raw)
  To: linux-arm-kernel

Enable sa1100 rtc driver on pxa910.

Signed-off-by: Haojian Zhuang <haojian.zhuang@marvell.com>
---
 arch/arm/mach-mmp/include/mach/pxa910.h    |    1 +
 arch/arm/mach-mmp/include/mach/regs-apbc.h |    1 +
 arch/arm/mach-mmp/pxa910.c                 |   27 +++++++++++++++++++++++++++
 arch/arm/mach-mmp/ttc_dkb.c                |    1 +
 4 files changed, 30 insertions(+), 0 deletions(-)

diff --git a/arch/arm/mach-mmp/include/mach/pxa910.h b/arch/arm/mach-mmp/include/mach/pxa910.h
index 4de13ab..e2e1f1e 100644
--- a/arch/arm/mach-mmp/include/mach/pxa910.h
+++ b/arch/arm/mach-mmp/include/mach/pxa910.h
@@ -22,6 +22,7 @@ extern struct pxa_device_desc pxa910_device_pwm4;
 extern struct pxa_device_desc pxa910_device_nand;
 
 extern struct platform_device pxa910_device_gpio;
+extern struct platform_device pxa910_device_rtc;
 
 static inline int pxa910_add_uart(int id)
 {
diff --git a/arch/arm/mach-mmp/include/mach/regs-apbc.h b/arch/arm/mach-mmp/include/mach/regs-apbc.h
index 1a96585..8a37fb0 100644
--- a/arch/arm/mach-mmp/include/mach/regs-apbc.h
+++ b/arch/arm/mach-mmp/include/mach/regs-apbc.h
@@ -57,6 +57,7 @@
 #define APBC_PXA910_SSP1	APBC_REG(0x01c)
 #define APBC_PXA910_SSP2	APBC_REG(0x020)
 #define APBC_PXA910_IPC		APBC_REG(0x024)
+#define APBC_PXA910_RTC		APBC_REG(0x028)
 #define APBC_PXA910_TWSI0	APBC_REG(0x02c)
 #define APBC_PXA910_KPC		APBC_REG(0x030)
 #define APBC_PXA910_TIMERS	APBC_REG(0x034)
diff --git a/arch/arm/mach-mmp/pxa910.c b/arch/arm/mach-mmp/pxa910.c
index 3241a25..d147265 100644
--- a/arch/arm/mach-mmp/pxa910.c
+++ b/arch/arm/mach-mmp/pxa910.c
@@ -92,6 +92,7 @@ static APBC_CLK(pwm2, PXA910_PWM2, 1, 13000000);
 static APBC_CLK(pwm3, PXA910_PWM3, 1, 13000000);
 static APBC_CLK(pwm4, PXA910_PWM4, 1, 13000000);
 static APBC_CLK(gpio, PXA910_GPIO, 0, 13000000);
+static APBC_CLK(rtc, PXA910_RTC, 8, 32768);
 
 static APMU_CLK(nand, NAND, 0x19b, 156000000);
 static APMU_CLK(u2o, USB, 0x1b, 480000000);
@@ -109,6 +110,7 @@ static struct clk_lookup pxa910_clkregs[] = {
 	INIT_CLKREG(&clk_nand, "pxa3xx-nand", NULL),
 	INIT_CLKREG(&clk_gpio, "pxa-gpio", NULL),
 	INIT_CLKREG(&clk_u2o, "pxa-u2o", "U2OCLK"),
+	INIT_CLKREG(&clk_rtc, "pxa910-rtc", NULL),
 };
 
 static int __init pxa910_init(void)
@@ -183,3 +185,28 @@ struct platform_device pxa910_device_gpio = {
 	.num_resources	= ARRAY_SIZE(pxa910_resource_gpio),
 	.resource	= pxa910_resource_gpio,
 };
+
+static struct resource pxa910_resource_rtc[] = {
+	{
+		.start	= 0xd4010000,
+		.end	= 0xd401003f,
+		.flags	= IORESOURCE_MEM,
+	}, {
+		.start	= IRQ_PXA910_RTC_INT,
+		.end	= IRQ_PXA910_RTC_INT,
+		.name	= "rtc 1Hz",
+		.flags	= IORESOURCE_IRQ,
+	}, {
+		.start	= IRQ_PXA910_RTC_ALARM,
+		.end	= IRQ_PXA910_RTC_ALARM,
+		.name	= "rtc alarm",
+		.flags	= IORESOURCE_IRQ,
+	},
+};
+
+struct platform_device pxa910_device_rtc = {
+	.name		= "pxa910-rtc",
+	.id		= -1,
+	.num_resources	= ARRAY_SIZE(pxa910_resource_rtc),
+	.resource	= pxa910_resource_rtc,
+};
diff --git a/arch/arm/mach-mmp/ttc_dkb.c b/arch/arm/mach-mmp/ttc_dkb.c
index 5ac5d58..e72c709 100644
--- a/arch/arm/mach-mmp/ttc_dkb.c
+++ b/arch/arm/mach-mmp/ttc_dkb.c
@@ -124,6 +124,7 @@ static struct platform_device ttc_dkb_device_onenand = {
 
 static struct platform_device *ttc_dkb_devices[] = {
 	&pxa910_device_gpio,
+	&pxa910_device_rtc,
 	&ttc_dkb_device_onenand,
 };
 
-- 
1.7.0.4

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

* [HELP REQUIRED] : Andorid FIQ Debugger Porting issue on Kernel2.6.36
       [not found]   ` <1329815642.22876.YahooMailNeo@web162001.mail.bf1.yahoo.com>
@ 2012-02-21  9:15     ` PINTU KUMAR
  0 siblings, 0 replies; 40+ messages in thread
From: PINTU KUMAR @ 2012-02-21  9:15 UTC (permalink / raw)
  To: linux-arm-kernel

?
Dear All,

This is regarding Android FIQ Debugger porting for another Linux mobile with kernel2.6.36.
I have successfully ported the fiq_debugger.c, fiq_glue.S and others and resolved the compilation issues.
I have enabled all the configs as below:
CONFIG_FIQ=y
CONFIG_FIQ_GLUE=y
CONFIG_FIQ_DEBUGGER=y
CONFIG_FIQ_DEBUGGER_NO_SLEEP=y
CONFIG_FIQ_DEBUGGER_WAKEUP_IRQ_ALWAYS_ON=y
CONFIG_FIQ_DEBUGGER_CONSOLE=y

But when I load the kernel on the device, the fiq handler is not getting called after I press ENTER?key many times during the following prompt.
<hit enter to activate fiq debugger>
---
---

What could be the problem?

Can anybody provide some pointers to debug further?



Thanks, Regards,
Pintu

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

* [PATCH 0/7] share sa1100 rtc driver to arch-mmp
  2012-02-21  9:04 [PATCH 0/7] share sa1100 rtc driver to arch-mmp Haojian Zhuang
                   ` (6 preceding siblings ...)
  2012-02-21  9:04 ` [PATCH 7/7] ARM: mmp: enable rtc Haojian Zhuang
@ 2012-02-21 15:37 ` Jean-Christophe PLAGNIOL-VILLARD
  2012-02-21 15:54   ` Nicolas Ferre
  2012-02-22 12:39 ` Arnd Bergmann
  2012-02-23  0:01 ` Russell King - ARM Linux
  9 siblings, 1 reply; 40+ messages in thread
From: Jean-Christophe PLAGNIOL-VILLARD @ 2012-02-21 15:37 UTC (permalink / raw)
  To: linux-arm-kernel

On 17:04 Tue 21 Feb     , Haojian Zhuang wrote:
> Remove the hardcode definition of rtc registers, use ioremap() instead.
> Append clk support for arch-mmp, so add dummy clk in arch-sa1100/arch-pxa.
looks gine 

Best Regards,
J.

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

* [PATCH 0/7] share sa1100 rtc driver to arch-mmp
  2012-02-21 15:37 ` [PATCH 0/7] share sa1100 rtc driver to arch-mmp Jean-Christophe PLAGNIOL-VILLARD
@ 2012-02-21 15:54   ` Nicolas Ferre
  0 siblings, 0 replies; 40+ messages in thread
From: Nicolas Ferre @ 2012-02-21 15:54 UTC (permalink / raw)
  To: linux-arm-kernel

On 02/21/2012 04:37 PM, Jean-Christophe PLAGNIOL-VILLARD :
> On 17:04 Tue 21 Feb     , Haojian Zhuang wrote:
>> Remove the hardcode definition of rtc registers, use ioremap() instead.
>> Append clk support for arch-mmp, so add dummy clk in arch-sa1100/arch-pxa.
> looks gine 

gine, or fone, maybe?...

> Best Regards,
> J.
> 
> _______________________________________________
> linux-arm-kernel mailing list
> linux-arm-kernel at lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
> 


-- 
Nicolas Ferre

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

* [PATCH 6/7] rtc: sa1100: enable clk support
  2012-02-21  9:04 ` [PATCH 6/7] rtc: sa1100: enable clk support Haojian Zhuang
@ 2012-02-22 12:29   ` Arnd Bergmann
  2012-02-22 13:16     ` Haojian Zhuang
  2012-02-22 13:20     ` Russell King - ARM Linux
  2012-02-23 10:34   ` Russell King - ARM Linux
  1 sibling, 2 replies; 40+ messages in thread
From: Arnd Bergmann @ 2012-02-22 12:29 UTC (permalink / raw)
  To: linux-arm-kernel

On Tuesday 21 February 2012, Haojian Zhuang wrote:
> @@ -306,6 +308,13 @@ static int sa1100_rtc_probe(struct platform_device *pdev)
>         if (!info)
>                 return -ENOMEM;
>  
> +       info->clk = clk_get(&pdev->dev, NULL);
> +       if (IS_ERR(info->clk)) {
> +               dev_err(&pdev->dev, "failed to find rtc clock source\n");
> +               ret = PTR_ERR(info->clk);
> +               goto err_clk;
> +       }
> +       clk_prepare_enable(info->clk);
>         info->iobase = res->start;
>         info->iosize = resource_size(res);
>         info->irq_1hz = irq_1hz;
> @@ -379,6 +388,9 @@ err_dev:
>         iounmap(info->reg_base);
>  err_map:
>         platform_set_drvdata(pdev, NULL);
> +       clk_disable_unprepare(info->clk);
> +       clk_put(info->clk);
> +err_clk:
>         kfree(info);
>         return ret;

I wonder whether it would be easier to just make the clk handling
conditional here, like

	info->clk = clk_get(&pdev->dev, NULL);
	if (PTR_ERR(info->clk) == -ENOENT)
		info->clk = NULL;
	if (IS_ERR(info->clk)) {
		ret =  PTR_ERR(info->clk);
		goto err_clk;
	}

	if (info->clk)
		clk_prepare_enable(info->clk);
	...
	if (info->clk) {
		clk_disable_unprepare(info->clk);
		clk_put(info->clk);
	}
		
With this, you would no longer need to add dummy clocks in platforms
that really have no clock handling.

	Arnd

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

* [PATCH 4/7] ARM: sa1100: clean up of the clock support
  2012-02-21  9:04 ` [PATCH 4/7] ARM: sa1100: clean up of the clock support Haojian Zhuang
@ 2012-02-22 12:31   ` Arnd Bergmann
  2012-02-23 10:32   ` Russell King - ARM Linux
  1 sibling, 0 replies; 40+ messages in thread
From: Arnd Bergmann @ 2012-02-22 12:31 UTC (permalink / raw)
  To: linux-arm-kernel

On Tuesday 21 February 2012, Haojian Zhuang wrote:
> From: Jett.Zhou <jtzhou@marvell.com>
> 
> Signed-off-by: Jett.Zhou <jtzhou@marvell.com>
> signed-off-by: Haojian Zhuang <haojian.zhuang@marvell.com>
> ---
>  arch/arm/Kconfig             |    2 +-
>  arch/arm/mach-sa1100/clock.c |   91 ++++++++++++++++++++++++++++++-----------
>  2 files changed, 67 insertions(+), 26 deletions(-)

I don't see anything wrong with the patch, but you really need to add a
description here, because it's anything but obvious why a "cleanup" would
add three times the lines it removes.

	Arnd

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

* [PATCH 3/7] rtc: sa1100: use ioremap to map registers
  2012-02-21  9:04 ` [PATCH 3/7] rtc: sa1100: use ioremap to map registers Haojian Zhuang
@ 2012-02-22 12:33   ` Arnd Bergmann
  2012-02-22 23:58   ` Russell King - ARM Linux
  2012-02-23  3:28   ` [PATCH v2 " Haojian Zhuang
  2 siblings, 0 replies; 40+ messages in thread
From: Arnd Bergmann @ 2012-02-22 12:33 UTC (permalink / raw)
  To: linux-arm-kernel

On Tuesday 21 February 2012, Haojian Zhuang wrote:
> 
> Add resource definition of sa1100 rtc. And use ioremap to map rtc
> registers to avoid including address definition of rtc register.
> So the same driver could be shared on sa1100/pxa/mmp series.
> 
> Since there's two RTC wrappers on RTC module among PXA27x/PXA3xx/PXA95x,
> keep treating the two wrappers as two RTC devices will result issues
> of registering platform device. So only keep one RTC wrapper in
> these silicons.
> 
> Signed-off-by: Haojian Zhuang <haojian.zhuang@marvell.com>

I believe I reviewed this in the past and it looks good to me in its
present version, so

Reviewed-by: Arnd Bergmann <arnd@arndb.de>

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

* [PATCH 0/7] share sa1100 rtc driver to arch-mmp
  2012-02-21  9:04 [PATCH 0/7] share sa1100 rtc driver to arch-mmp Haojian Zhuang
                   ` (7 preceding siblings ...)
  2012-02-21 15:37 ` [PATCH 0/7] share sa1100 rtc driver to arch-mmp Jean-Christophe PLAGNIOL-VILLARD
@ 2012-02-22 12:39 ` Arnd Bergmann
  2012-02-22 13:22   ` Haojian Zhuang
  2012-02-23  0:01 ` Russell King - ARM Linux
  9 siblings, 1 reply; 40+ messages in thread
From: Arnd Bergmann @ 2012-02-22 12:39 UTC (permalink / raw)
  To: linux-arm-kernel

On Tuesday 21 February 2012, Haojian Zhuang wrote:
> Remove the hardcode definition of rtc registers, use ioremap() instead.
> Append clk support for arch-mmp, so add dummy clk in arch-sa1100/arch-pxa.

What is the status of the drivers/rtc/rtc-pxa.c driver after this series?
Is is still required for some pxa machines or can it get removed now?
It seems a little strange to register two platform devices for the
rtc on each pxa machine, with the same resources.

	Arnd

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

* [PATCH 6/7] rtc: sa1100: enable clk support
  2012-02-22 12:29   ` Arnd Bergmann
@ 2012-02-22 13:16     ` Haojian Zhuang
  2012-02-22 13:20     ` Russell King - ARM Linux
  1 sibling, 0 replies; 40+ messages in thread
From: Haojian Zhuang @ 2012-02-22 13:16 UTC (permalink / raw)
  To: linux-arm-kernel

On Wed, Feb 22, 2012 at 8:29 PM, Arnd Bergmann <arnd@arndb.de> wrote:
> On Tuesday 21 February 2012, Haojian Zhuang wrote:
>> @@ -306,6 +308,13 @@ static int sa1100_rtc_probe(struct platform_device *pdev)
>> ? ? ? ? if (!info)
>> ? ? ? ? ? ? ? ? return -ENOMEM;
>>
>> + ? ? ? info->clk = clk_get(&pdev->dev, NULL);
>> + ? ? ? if (IS_ERR(info->clk)) {
>> + ? ? ? ? ? ? ? dev_err(&pdev->dev, "failed to find rtc clock source\n");
>> + ? ? ? ? ? ? ? ret = PTR_ERR(info->clk);
>> + ? ? ? ? ? ? ? goto err_clk;
>> + ? ? ? }
>> + ? ? ? clk_prepare_enable(info->clk);
>> ? ? ? ? info->iobase = res->start;
>> ? ? ? ? info->iosize = resource_size(res);
>> ? ? ? ? info->irq_1hz = irq_1hz;
>> @@ -379,6 +388,9 @@ err_dev:
>> ? ? ? ? iounmap(info->reg_base);
>> ?err_map:
>> ? ? ? ? platform_set_drvdata(pdev, NULL);
>> + ? ? ? clk_disable_unprepare(info->clk);
>> + ? ? ? clk_put(info->clk);
>> +err_clk:
>> ? ? ? ? kfree(info);
>> ? ? ? ? return ret;
>
> I wonder whether it would be easier to just make the clk handling
> conditional here, like
>
> ? ? ? ?info->clk = clk_get(&pdev->dev, NULL);
> ? ? ? ?if (PTR_ERR(info->clk) == -ENOENT)
> ? ? ? ? ? ? ? ?info->clk = NULL;
> ? ? ? ?if (IS_ERR(info->clk)) {
> ? ? ? ? ? ? ? ?ret = ?PTR_ERR(info->clk);
> ? ? ? ? ? ? ? ?goto err_clk;
> ? ? ? ?}
>
> ? ? ? ?if (info->clk)
> ? ? ? ? ? ? ? ?clk_prepare_enable(info->clk);
> ? ? ? ?...
> ? ? ? ?if (info->clk) {
> ? ? ? ? ? ? ? ?clk_disable_unprepare(info->clk);
> ? ? ? ? ? ? ? ?clk_put(info->clk);
> ? ? ? ?}
>
> With this, you would no longer need to add dummy clocks in platforms
> that really have no clock handling.
>
> ? ? ? ?Arnd

It sounds good. I'll update it.

Thanks
Haojian

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

* [PATCH 6/7] rtc: sa1100: enable clk support
  2012-02-22 12:29   ` Arnd Bergmann
  2012-02-22 13:16     ` Haojian Zhuang
@ 2012-02-22 13:20     ` Russell King - ARM Linux
  2012-02-22 13:47       ` Arnd Bergmann
  1 sibling, 1 reply; 40+ messages in thread
From: Russell King - ARM Linux @ 2012-02-22 13:20 UTC (permalink / raw)
  To: linux-arm-kernel

On Wed, Feb 22, 2012 at 12:29:17PM +0000, Arnd Bergmann wrote:
> On Tuesday 21 February 2012, Haojian Zhuang wrote:
> > @@ -306,6 +308,13 @@ static int sa1100_rtc_probe(struct platform_device *pdev)
> >         if (!info)
> >                 return -ENOMEM;
> >  
> > +       info->clk = clk_get(&pdev->dev, NULL);
> > +       if (IS_ERR(info->clk)) {
> > +               dev_err(&pdev->dev, "failed to find rtc clock source\n");
> > +               ret = PTR_ERR(info->clk);
> > +               goto err_clk;
> > +       }
> > +       clk_prepare_enable(info->clk);
> >         info->iobase = res->start;
> >         info->iosize = resource_size(res);
> >         info->irq_1hz = irq_1hz;
> > @@ -379,6 +388,9 @@ err_dev:
> >         iounmap(info->reg_base);
> >  err_map:
> >         platform_set_drvdata(pdev, NULL);
> > +       clk_disable_unprepare(info->clk);
> > +       clk_put(info->clk);
> > +err_clk:
> >         kfree(info);
> >         return ret;
> 
> I wonder whether it would be easier to just make the clk handling
> conditional here, like

Eww.  No, just keep this hidden beneath the clk API.  Return a NULL
clock for this device, and ensure that all the standard clk API
functions know internally that that means 'no action required'.

There's no need to pollute drivers with this platform specific knowledge.

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

* [PATCH 0/7] share sa1100 rtc driver to arch-mmp
  2012-02-22 12:39 ` Arnd Bergmann
@ 2012-02-22 13:22   ` Haojian Zhuang
  2012-02-22 13:49     ` Arnd Bergmann
  0 siblings, 1 reply; 40+ messages in thread
From: Haojian Zhuang @ 2012-02-22 13:22 UTC (permalink / raw)
  To: linux-arm-kernel

On Wed, Feb 22, 2012 at 8:39 PM, Arnd Bergmann <arnd@arndb.de> wrote:
> On Tuesday 21 February 2012, Haojian Zhuang wrote:
>> Remove the hardcode definition of rtc registers, use ioremap() instead.
>> Append clk support for arch-mmp, so add dummy clk in arch-sa1100/arch-pxa.
>
> What is the status of the drivers/rtc/rtc-pxa.c driver after this series?
> Is is still required for some pxa machines or can it get removed now?
> It seems a little strange to register two platform devices for the
> rtc on each pxa machine, with the same resources.
>
> ? ? ? ?Arnd

Yes, it's very strange to support two RTC wrappers at the same time.
So rtc-pxa is removed in pxa27x/pxa3xx after this patch series. It
only exists in pxa95x.

Thanks
Haojian

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

* [PATCH 6/7] rtc: sa1100: enable clk support
  2012-02-22 13:20     ` Russell King - ARM Linux
@ 2012-02-22 13:47       ` Arnd Bergmann
  0 siblings, 0 replies; 40+ messages in thread
From: Arnd Bergmann @ 2012-02-22 13:47 UTC (permalink / raw)
  To: linux-arm-kernel

On Wednesday 22 February 2012, Russell King - ARM Linux wrote:
> Eww.  No, just keep this hidden beneath the clk API.  Return a NULL
> clock for this device, and ensure that all the standard clk API
> functions know internally that that means 'no action required'.
> 
> There's no need to pollute drivers with this platform specific knowledge.

Good point, that does sound much cleaner than my suggestion.

Thanks,

	Arnd

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

* [PATCH 0/7] share sa1100 rtc driver to arch-mmp
  2012-02-22 13:22   ` Haojian Zhuang
@ 2012-02-22 13:49     ` Arnd Bergmann
  2012-02-22 15:37       ` Haojian Zhuang
  0 siblings, 1 reply; 40+ messages in thread
From: Arnd Bergmann @ 2012-02-22 13:49 UTC (permalink / raw)
  To: linux-arm-kernel

On Wednesday 22 February 2012, Haojian Zhuang wrote:
> On Wed, Feb 22, 2012 at 8:39 PM, Arnd Bergmann <arnd@arndb.de> wrote:
> > On Tuesday 21 February 2012, Haojian Zhuang wrote:
> >> Remove the hardcode definition of rtc registers, use ioremap() instead.
> >> Append clk support for arch-mmp, so add dummy clk in arch-sa1100/arch-pxa.
> >
> > What is the status of the drivers/rtc/rtc-pxa.c driver after this series?
> > Is is still required for some pxa machines or can it get removed now?
> > It seems a little strange to register two platform devices for the
> > rtc on each pxa machine, with the same resources.
> 
> Yes, it's very strange to support two RTC wrappers at the same time.
> So rtc-pxa is removed in pxa27x/pxa3xx after this patch series. It
> only exists in pxa95x.

What is the reason for this? Wouldn't it be easier to move pxa95x over
to use the same driver as well? I guess that can be a series for another
time, but it seems like you are almost at the point where you can
remove the other driver entirely.

	Arnd

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

* [PATCH 0/7] share sa1100 rtc driver to arch-mmp
  2012-02-22 13:49     ` Arnd Bergmann
@ 2012-02-22 15:37       ` Haojian Zhuang
  2012-02-22 16:38         ` Robert Jarzmik
  0 siblings, 1 reply; 40+ messages in thread
From: Haojian Zhuang @ 2012-02-22 15:37 UTC (permalink / raw)
  To: linux-arm-kernel

On Wed, Feb 22, 2012 at 9:49 PM, Arnd Bergmann <arnd@arndb.de> wrote:
> On Wednesday 22 February 2012, Haojian Zhuang wrote:
>> On Wed, Feb 22, 2012 at 8:39 PM, Arnd Bergmann <arnd@arndb.de> wrote:
>> > On Tuesday 21 February 2012, Haojian Zhuang wrote:
>> >> Remove the hardcode definition of rtc registers, use ioremap() instead.
>> >> Append clk support for arch-mmp, so add dummy clk in arch-sa1100/arch-pxa.
>> >
>> > What is the status of the drivers/rtc/rtc-pxa.c driver after this series?
>> > Is is still required for some pxa machines or can it get removed now?
>> > It seems a little strange to register two platform devices for the
>> > rtc on each pxa machine, with the same resources.
>>
>> Yes, it's very strange to support two RTC wrappers at the same time.
>> So rtc-pxa is removed in pxa27x/pxa3xx after this patch series. It
>> only exists in pxa95x.
>
> What is the reason for this? Wouldn't it be easier to move pxa95x over
> to use the same driver as well? I guess that can be a series for another
> time, but it seems like you are almost at the point where you can
> remove the other driver entirely.
>
> ? ? ? ?Arnd

I can remove the rtc-pxa support entirely. I still want to leave this
since this may be the only one choice in the future silicons.

Since some boards with pxa27x/pxa3xx are accessing RCNR (the old rtc
wrapper) directly, I use rtc-sa1100 to keep consistently. In pxa95x,
nobody is using the old rtc wrapper directly. So I only use it in
pxa95x.

>From another view, there're more features in new wrapper. It should be
better to overcome the overflow of RTC time.

Best Regards
Haojian

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

* [PATCH 0/7] share sa1100 rtc driver to arch-mmp
  2012-02-22 15:37       ` Haojian Zhuang
@ 2012-02-22 16:38         ` Robert Jarzmik
  2012-02-23  0:51           ` Haojian Zhuang
  0 siblings, 1 reply; 40+ messages in thread
From: Robert Jarzmik @ 2012-02-22 16:38 UTC (permalink / raw)
  To: linux-arm-kernel

Haojian Zhuang <haojian.zhuang@gmail.com> writes:

> I can remove the rtc-pxa support entirely. I still want to leave this
> since this may be the only one choice in the future silicons.
>
> Since some boards with pxa27x/pxa3xx are accessing RCNR (the old rtc
> wrapper) directly, I use rtc-sa1100 to keep consistently. In pxa95x,
> nobody is using the old rtc wrapper directly. So I only use it in
> pxa95x.

No, I don't agree there.

The PXA RTC silicon support 2 different set of registers to access time :
 - RCNR (rtc-sa1100)
 - RYCR/RDCR (rtc-pxa)

The rtc-pxa driver was created to provide support for boards using the RYCR/RDCR
rather than RCNR.

Therefore I'm against removing rtc-pxa, unless there is a driver for pxa, which
provides RTC using RYCR/RDCR registers.

We had that discussion a long time ago, in [1].

Cheers.

--
Robert

[1] Linux Arm Kernel Mailing List, 2008/09/30
    http://lists.arm.linux.org.uk/lurker/message/20080930.193554.96feb95f.en.html

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

* [PATCH 3/7] rtc: sa1100: use ioremap to map registers
  2012-02-21  9:04 ` [PATCH 3/7] rtc: sa1100: use ioremap to map registers Haojian Zhuang
  2012-02-22 12:33   ` Arnd Bergmann
@ 2012-02-22 23:58   ` Russell King - ARM Linux
  2012-02-23  0:55     ` Haojian Zhuang
  2012-02-23  3:28   ` [PATCH v2 " Haojian Zhuang
  2 siblings, 1 reply; 40+ messages in thread
From: Russell King - ARM Linux @ 2012-02-22 23:58 UTC (permalink / raw)
  To: linux-arm-kernel

On Tue, Feb 21, 2012 at 05:04:52PM +0800, Haojian Zhuang wrote:
> diff --git a/arch/arm/mach-sa1100/generic.c b/arch/arm/mach-sa1100/generic.c
> index bb10ee2..04a62a3 100644
> --- a/arch/arm/mach-sa1100/generic.c
> +++ b/arch/arm/mach-sa1100/generic.c
> @@ -345,9 +345,29 @@ void sa11x0_register_irda(struct irda_platform_data *irda)
>  	sa11x0_register_device(&sa11x0ir_device, irda);
>  }
>  
> +static struct resource sa1100_rtc_resources[] = {
> +	{
> +		.start	= 0x90010000,
> +		.end	= 0x9001003f,
> +		.flags	= IORESOURCE_MEM,
> +	}, {
> +		.start  = IRQ_RTC1Hz,
> +		.end    = IRQ_RTC1Hz,
> +		.name	= "rtc 1Hz",
> +		.flags  = IORESOURCE_IRQ,
> +	}, {
> +		.start  = IRQ_RTCAlrm,
> +		.end    = IRQ_RTCAlrm,
> +		.name	= "rtc alarm",
> +		.flags  = IORESOURCE_IRQ,
> +	},
> +};

As I've converted all resources in this file to use the DEFINE_RES_foo()
macros, it would be a shame to have this initialization reintroduced.
Please use DEFINE_RES_foo() here.

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

* [PATCH 0/7] share sa1100 rtc driver to arch-mmp
  2012-02-21  9:04 [PATCH 0/7] share sa1100 rtc driver to arch-mmp Haojian Zhuang
                   ` (8 preceding siblings ...)
  2012-02-22 12:39 ` Arnd Bergmann
@ 2012-02-23  0:01 ` Russell King - ARM Linux
  9 siblings, 0 replies; 40+ messages in thread
From: Russell King - ARM Linux @ 2012-02-23  0:01 UTC (permalink / raw)
  To: linux-arm-kernel

On Tue, Feb 21, 2012 at 05:04:49PM +0800, Haojian Zhuang wrote:
> Remove the hardcode definition of rtc registers, use ioremap() instead.
> Append clk support for arch-mmp, so add dummy clk in arch-sa1100/arch-pxa.

One final comment: we need to get this sorted, because as things currently
stand, my builds for PXA are failing:

http://www.arm.linux.org.uk/developer/build/result.php?type=build&idx=185

drivers/rtc/rtc-sa1100.c: In function 'sa1100_rtc_open':
drivers/rtc/rtc-sa1100.c:163: error: 'IRQ_RTC1Hz' undeclared (first use in this function)
drivers/rtc/rtc-sa1100.c:163: error: (Each undeclared identifier is reported only once
drivers/rtc/rtc-sa1100.c:163: error: for each function it appears in.)
drivers/rtc/rtc-sa1100.c:169: error: 'IRQ_RTCAlrm' undeclared (first use in this function)
drivers/rtc/rtc-sa1100.c: In function 'sa1100_rtc_release':
drivers/rtc/rtc-sa1100.c:192: error: 'IRQ_RTCAlrm' undeclared (first use in this function)
drivers/rtc/rtc-sa1100.c:193: error: 'IRQ_RTC1Hz' undeclared (first use in this function)
drivers/rtc/rtc-sa1100.c: In function 'sa1100_rtc_suspend':
drivers/rtc/rtc-sa1100.c:341: error: 'IRQ_RTCAlrm' undeclared (first use in this function)
drivers/rtc/rtc-sa1100.c: In function 'sa1100_rtc_resume':
drivers/rtc/rtc-sa1100.c:348: error: 'IRQ_RTCAlrm' undeclared (first use in this function)

which means PXA will be broken in the next merge window.  As that's
mostly down to Rob's IRQ stuff, the simple solution is to get the
conversion to use platform resources in place ASAP, and then start
worrying about the differences between the various SoCs.

What I don't want to be doing is going into the next merge window
with this in its current state.

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

* [PATCH 0/7] share sa1100 rtc driver to arch-mmp
  2012-02-22 16:38         ` Robert Jarzmik
@ 2012-02-23  0:51           ` Haojian Zhuang
  2012-02-23  8:52             ` Robert Jarzmik
  0 siblings, 1 reply; 40+ messages in thread
From: Haojian Zhuang @ 2012-02-23  0:51 UTC (permalink / raw)
  To: linux-arm-kernel

On Thu, Feb 23, 2012 at 12:38 AM, Robert Jarzmik <robert.jarzmik@free.fr> wrote:
> Haojian Zhuang <haojian.zhuang@gmail.com> writes:
>
>> I can remove the rtc-pxa support entirely. I still want to leave this
>> since this may be the only one choice in the future silicons.
>>
>> Since some boards with pxa27x/pxa3xx are accessing RCNR (the old rtc
>> wrapper) directly, I use rtc-sa1100 to keep consistently. In pxa95x,
>> nobody is using the old rtc wrapper directly. So I only use it in
>> pxa95x.
>
> No, I don't agree there.
>
> The PXA RTC silicon support 2 different set of registers to access time :
> ?- RCNR (rtc-sa1100)
> ?- RYCR/RDCR (rtc-pxa)
>
> The rtc-pxa driver was created to provide support for boards using the RYCR/RDCR
> rather than RCNR.
>
> Therefore I'm against removing rtc-pxa, unless there is a driver for pxa, which
> provides RTC using RYCR/RDCR registers.
>
> We had that discussion a long time ago, in [1].
>
Hi Robert,

rtc-sa1100 driver is the only one choice on sa1100/pxa25x/pxa910/mmp2.
And it's optional to pxa27x/pxa3xx/pxa95x.

Whatever we use RCNR or RDYR registers, they're in the same I/O range.
It's impossible to define same resource range for two rtc device. We
have to make a choice between rtc-sa1100 or rtc-pxa on
pxa27x/pxa3xx/pxa95x.

I hadn't any plan to remove rtc-pxa driver. I only disabled it for
pxa27x/pxa3xx. Please check the code of
arch/arm/mach-pxa/sharpsl_pm.c. If we only enable rtc-pxa on pxa27x,
we'll break the behavior on sharpsl since it's using rtc-sa1100. In
order to keep code consistently, I disable rtc-pxa on pxa27x/pxa3xx.
And use it on pxa95x since there's no legacy code issue.

Best Regards
Haojian

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

* [PATCH 3/7] rtc: sa1100: use ioremap to map registers
  2012-02-22 23:58   ` Russell King - ARM Linux
@ 2012-02-23  0:55     ` Haojian Zhuang
  0 siblings, 0 replies; 40+ messages in thread
From: Haojian Zhuang @ 2012-02-23  0:55 UTC (permalink / raw)
  To: linux-arm-kernel

On Thu, Feb 23, 2012 at 7:58 AM, Russell King - ARM Linux
<linux@arm.linux.org.uk> wrote:
> On Tue, Feb 21, 2012 at 05:04:52PM +0800, Haojian Zhuang wrote:
>> diff --git a/arch/arm/mach-sa1100/generic.c b/arch/arm/mach-sa1100/generic.c
>> index bb10ee2..04a62a3 100644
>> --- a/arch/arm/mach-sa1100/generic.c
>> +++ b/arch/arm/mach-sa1100/generic.c
>> @@ -345,9 +345,29 @@ void sa11x0_register_irda(struct irda_platform_data *irda)
>> ? ? ? sa11x0_register_device(&sa11x0ir_device, irda);
>> ?}
>>
>> +static struct resource sa1100_rtc_resources[] = {
>> + ? ? {
>> + ? ? ? ? ? ? .start ?= 0x90010000,
>> + ? ? ? ? ? ? .end ? ?= 0x9001003f,
>> + ? ? ? ? ? ? .flags ?= IORESOURCE_MEM,
>> + ? ? }, {
>> + ? ? ? ? ? ? .start ?= IRQ_RTC1Hz,
>> + ? ? ? ? ? ? .end ? ?= IRQ_RTC1Hz,
>> + ? ? ? ? ? ? .name ? = "rtc 1Hz",
>> + ? ? ? ? ? ? .flags ?= IORESOURCE_IRQ,
>> + ? ? }, {
>> + ? ? ? ? ? ? .start ?= IRQ_RTCAlrm,
>> + ? ? ? ? ? ? .end ? ?= IRQ_RTCAlrm,
>> + ? ? ? ? ? ? .name ? = "rtc alarm",
>> + ? ? ? ? ? ? .flags ?= IORESOURCE_IRQ,
>> + ? ? },
>> +};
>
> As I've converted all resources in this file to use the DEFINE_RES_foo()
> macros, it would be a shame to have this initialization reintroduced.
> Please use DEFINE_RES_foo() here.
>
Sure. I'll update it right now.

Thanks
Haojian

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

* [PATCH v2 3/7] rtc: sa1100: use ioremap to map registers
  2012-02-21  9:04 ` [PATCH 3/7] rtc: sa1100: use ioremap to map registers Haojian Zhuang
  2012-02-22 12:33   ` Arnd Bergmann
  2012-02-22 23:58   ` Russell King - ARM Linux
@ 2012-02-23  3:28   ` Haojian Zhuang
  2012-02-23 10:26     ` Russell King - ARM Linux
  2 siblings, 1 reply; 40+ messages in thread
From: Haojian Zhuang @ 2012-02-23  3:28 UTC (permalink / raw)
  To: linux-arm-kernel

Add resource definition of sa1100 rtc. And use ioremap to map rtc
registers to avoid including address definition of rtc register.
So the same driver could be shared on sa1100/pxa/mmp series.

Since there's two RTC wrappers on RTC module among PXA27x/PXA3xx/PXA95x,
keep treating the two wrappers as two RTC devices will result issues
of registering platform device. So only keep one RTC wrapper in
these silicons.

Signed-off-by: Haojian Zhuang <haojian.zhuang@marvell.com>
Reviewed-by: Arnd Bergmann <arnd@arndb.de>
---
 arch/arm/mach-pxa/devices.c    |    6 +-
 arch/arm/mach-pxa/pxa27x.c     |    1 -
 arch/arm/mach-pxa/pxa3xx.c     |    1 -
 arch/arm/mach-pxa/pxa95x.c     |    1 -
 arch/arm/mach-sa1100/generic.c |    8 ++
 drivers/rtc/Kconfig            |    4 +-
 drivers/rtc/rtc-sa1100.c       |  243 ++++++++++++++++++++++++++++++----------
 7 files changed, 199 insertions(+), 65 deletions(-)

diff --git a/arch/arm/mach-pxa/devices.c b/arch/arm/mach-pxa/devices.c
index 5bc1312..9fe7d6a 100644
--- a/arch/arm/mach-pxa/devices.c
+++ b/arch/arm/mach-pxa/devices.c
@@ -406,18 +406,22 @@ static struct resource pxa_rtc_resources[] = {
 	[1] = {
 		.start  = IRQ_RTC1Hz,
 		.end    = IRQ_RTC1Hz,
+		.name	= "rtc 1Hz",
 		.flags  = IORESOURCE_IRQ,
 	},
 	[2] = {
 		.start  = IRQ_RTCAlrm,
 		.end    = IRQ_RTCAlrm,
+		.name	= "rtc alarm",
 		.flags  = IORESOURCE_IRQ,
 	},
 };
 
 struct platform_device sa1100_device_rtc = {
-	.name		= "sa1100-rtc",
+	.name		= "pxa25x-rtc",
 	.id		= -1,
+	.num_resources	= ARRAY_SIZE(pxa_rtc_resources),
+	.resource	= pxa_rtc_resources,
 };
 
 struct platform_device pxa_device_rtc = {
diff --git a/arch/arm/mach-pxa/pxa27x.c b/arch/arm/mach-pxa/pxa27x.c
index aed6cbc..345fa7b 100644
--- a/arch/arm/mach-pxa/pxa27x.c
+++ b/arch/arm/mach-pxa/pxa27x.c
@@ -431,7 +431,6 @@ static struct platform_device *devices[] __initdata = {
 	&pxa_device_asoc_ssp3,
 	&pxa_device_asoc_platform,
 	&sa1100_device_rtc,
-	&pxa_device_rtc,
 	&pxa27x_device_ssp1,
 	&pxa27x_device_ssp2,
 	&pxa27x_device_ssp3,
diff --git a/arch/arm/mach-pxa/pxa3xx.c b/arch/arm/mach-pxa/pxa3xx.c
index 4f402af..d2437a8 100644
--- a/arch/arm/mach-pxa/pxa3xx.c
+++ b/arch/arm/mach-pxa/pxa3xx.c
@@ -428,7 +428,6 @@ static struct platform_device *devices[] __initdata = {
 	&pxa_device_asoc_ssp4,
 	&pxa_device_asoc_platform,
 	&sa1100_device_rtc,
-	&pxa_device_rtc,
 	&pxa27x_device_ssp1,
 	&pxa27x_device_ssp2,
 	&pxa27x_device_ssp3,
diff --git a/arch/arm/mach-pxa/pxa95x.c b/arch/arm/mach-pxa/pxa95x.c
index d082a58..b41e9f3 100644
--- a/arch/arm/mach-pxa/pxa95x.c
+++ b/arch/arm/mach-pxa/pxa95x.c
@@ -249,7 +249,6 @@ void __init pxa95x_set_i2c_power_info(struct i2c_pxa_platform_data *info)
 
 static struct platform_device *devices[] __initdata = {
 	&pxa_device_gpio,
-	&sa1100_device_rtc,
 	&pxa_device_rtc,
 	&pxa27x_device_ssp1,
 	&pxa27x_device_ssp2,
diff --git a/arch/arm/mach-sa1100/generic.c b/arch/arm/mach-sa1100/generic.c
index bb10ee2..7c1ebf4 100644
--- a/arch/arm/mach-sa1100/generic.c
+++ b/arch/arm/mach-sa1100/generic.c
@@ -345,9 +345,17 @@ void sa11x0_register_irda(struct irda_platform_data *irda)
 	sa11x0_register_device(&sa11x0ir_device, irda);
 }
 
+static struct resource sa1100_rtc_resources[] = {
+	DEFINE_RES_MEM(0x90010000, 0x9001003f),
+	DEFINE_RES_IRQ_NAMED(IRQ_RTC1Hz, "rtc 1Hz"),
+	DEFINE_RES_IRQ_NAMED(IRQ_RTCAlrm, "rtc alarm"),
+};
+
 static struct platform_device sa11x0rtc_device = {
 	.name		= "sa1100-rtc",
 	.id		= -1,
+	.num_resources	= ARRAY_SIZE(sa1100_rtc_resources),
+	.resource	= sa1100_rtc_resources,
 };
 
 static struct platform_device *sa11x0_devices[] __initdata = {
diff --git a/drivers/rtc/Kconfig b/drivers/rtc/Kconfig
index 3a125b8..59efc63 100644
--- a/drivers/rtc/Kconfig
+++ b/drivers/rtc/Kconfig
@@ -773,8 +773,8 @@ config RTC_DRV_EP93XX
 	  will be called rtc-ep93xx.
 
 config RTC_DRV_SA1100
-	tristate "SA11x0/PXA2xx"
-	depends on ARCH_SA1100 || ARCH_PXA
+	tristate "SA11x0/PXA2xx/PXA910"
+	depends on ARCH_SA1100 || ARCH_PXA || ARCH_MMP
 	help
 	  If you say Y here you will get access to the real time clock
 	  built into your SA11x0 or PXA2xx CPU.
diff --git a/drivers/rtc/rtc-sa1100.c b/drivers/rtc/rtc-sa1100.c
index 91d58bd..90425ce 100644
--- a/drivers/rtc/rtc-sa1100.c
+++ b/drivers/rtc/rtc-sa1100.c
@@ -25,44 +25,101 @@
 #include <linux/module.h>
 #include <linux/rtc.h>
 #include <linux/init.h>
+#include <linux/io.h>
 #include <linux/fs.h>
 #include <linux/interrupt.h>
+#include <linux/slab.h>
 #include <linux/string.h>
 #include <linux/pm.h>
 #include <linux/bitops.h>
 
-#include <mach/hardware.h>
-#include <asm/irq.h>
-
-#ifdef CONFIG_ARCH_PXA
-#include <mach/regs-rtc.h>
-#endif
-
 #define RTC_DEF_DIVIDER		(32768 - 1)
 #define RTC_DEF_TRIM		0
+#define RTC_FREQ		1024
+
+#define RTSR_HZE		(1 << 3)	/* HZ interrupt enable */
+#define RTSR_ALE		(1 << 2)	/* RTC alarm interrupt enable */
+#define RTSR_HZ			(1 << 1)	/* HZ rising-edge detected */
+#define RTSR_AL			(1 << 0)	/* RTC alarm detected */
 
-static const unsigned long RTC_FREQ = 1024;
-static DEFINE_SPINLOCK(sa1100_rtc_lock);
+struct sa1100_reg_layout {
+	unsigned int	rcnr;			/* RTC Count Register */
+	unsigned int	rtar;			/* RTC Alarm Register */
+	unsigned int	rtsr;			/* RTC Status Register */
+	unsigned int	rttr;			/* RTC Timer Trim Register */
+
+};
+
+enum sa1100_rtc_types {
+	REGS_SA1100,
+	REGS_PXA25X,
+	REGS_PXA910,
+};
+
+struct sa1100_rtc {
+	spinlock_t		lock;
+	unsigned long		iobase;
+	unsigned long		iosize;
+	int			irq_1hz;
+	int			irq_alarm;
+	struct rtc_device	*rtc;
+
+	void __iomem		*reg_base;
+	void __iomem		*reg_rcnr;
+	void __iomem		*reg_rtar;
+	void __iomem		*reg_rtsr;
+	void __iomem		*reg_rttr;
+};
+
+static struct sa1100_reg_layout sa1100_layout[] = {
+	[REGS_SA1100] = {
+		.rcnr = 0x04,
+		.rtar = 0x00,
+		.rtsr = 0x10,
+		.rttr = 0x08,
+	},
+	[REGS_PXA25X] = {
+		.rcnr = 0x00,
+		.rtar = 0x04,
+		.rtsr = 0x08,
+		.rttr = 0x10,
+	},
+	[REGS_PXA910] = {
+		.rcnr = 0x00,
+		.rtar = 0x04,
+		.rtsr = 0x08,
+		.rttr = 0x0C,
+	},
+};
+
+static const struct platform_device_id sa1100_rtc_id_table[] = {
+	{ "sa1100-rtc",		REGS_SA1100 },
+	{ "pxa25x-rtc",		REGS_PXA25X },
+	{ "pxa910-rtc",		REGS_PXA910 },
+	{ },
+};
+MODULE_DEVICE_TABLE(platform, sa1100_rtc_id_table);
 
 static irqreturn_t sa1100_rtc_interrupt(int irq, void *dev_id)
 {
-	struct platform_device *pdev = to_platform_device(dev_id);
-	struct rtc_device *rtc = platform_get_drvdata(pdev);
+	struct sa1100_rtc *info = dev_get_drvdata(dev_id);
+	struct rtc_device *rtc = info->rtc;
 	unsigned int rtsr;
 	unsigned long events = 0;
 
-	spin_lock(&sa1100_rtc_lock);
+	spin_lock(&info->lock);
 
-	rtsr = RTSR;
+	rtsr = readl_relaxed(info->reg_rtsr);
 	/* clear interrupt sources */
-	RTSR = 0;
+	writel_relaxed(0, info->reg_rtsr);
+
 	/* Fix for a nasty initialization problem the in SA11xx RTSR register.
 	 * See also the comments in sa1100_rtc_probe(). */
 	if (rtsr & (RTSR_ALE | RTSR_HZE)) {
 		/* This is the original code, before there was the if test
 		 * above. This code does not clear interrupts that were not
 		 * enabled. */
-		RTSR = (RTSR_AL | RTSR_HZ) & (rtsr >> 2);
+		writel_relaxed((RTSR_AL|RTSR_HZ) & (rtsr >> 2), info->reg_rtsr);
 	} else {
 		/* For some reason, it is possible to enter this routine
 		 * without interruptions enabled, it has been tested with
@@ -71,13 +128,13 @@ static irqreturn_t sa1100_rtc_interrupt(int irq, void *dev_id)
 		 * This situation leads to an infinite "loop" of interrupt
 		 * routine calling and as a result the processor seems to
 		 * lock on its first call to open(). */
-		RTSR = RTSR_AL | RTSR_HZ;
+		writel_relaxed(RTSR_AL | RTSR_HZ, info->reg_rtsr);
 	}
 
 	/* clear alarm interrupt if it has occurred */
 	if (rtsr & RTSR_AL)
 		rtsr &= ~RTSR_ALE;
-	RTSR = rtsr & (RTSR_ALE | RTSR_HZE);
+	writel_relaxed(rtsr & (RTSR_ALE | RTSR_HZE), info->reg_rtsr);
 
 	/* update irq data & counter */
 	if (rtsr & RTSR_AL)
@@ -87,27 +144,27 @@ static irqreturn_t sa1100_rtc_interrupt(int irq, void *dev_id)
 
 	rtc_update_irq(rtc, 1, events);
 
-	spin_unlock(&sa1100_rtc_lock);
+	spin_unlock(&info->lock);
 
 	return IRQ_HANDLED;
 }
 
 static int sa1100_rtc_open(struct device *dev)
 {
+	struct sa1100_rtc *info = dev_get_drvdata(dev);
+	struct rtc_device *rtc = info->rtc;
 	int ret;
-	struct platform_device *plat_dev = to_platform_device(dev);
-	struct rtc_device *rtc = platform_get_drvdata(plat_dev);
 
-	ret = request_irq(IRQ_RTC1Hz, sa1100_rtc_interrupt, IRQF_DISABLED,
+	ret = request_irq(info->irq_1hz, sa1100_rtc_interrupt, IRQF_DISABLED,
 		"rtc 1Hz", dev);
 	if (ret) {
-		dev_err(dev, "IRQ %d already in use.\n", IRQ_RTC1Hz);
+		dev_err(dev, "IRQ %d already in use.\n", info->irq_1hz);
 		goto fail_ui;
 	}
-	ret = request_irq(IRQ_RTCAlrm, sa1100_rtc_interrupt, IRQF_DISABLED,
+	ret = request_irq(info->irq_alarm, sa1100_rtc_interrupt, IRQF_DISABLED,
 		"rtc Alrm", dev);
 	if (ret) {
-		dev_err(dev, "IRQ %d already in use.\n", IRQ_RTCAlrm);
+		dev_err(dev, "IRQ %d already in use.\n", info->irq_alarm);
 		goto fail_ai;
 	}
 	rtc->max_user_freq = RTC_FREQ;
@@ -116,54 +173,66 @@ static int sa1100_rtc_open(struct device *dev)
 	return 0;
 
  fail_ai:
-	free_irq(IRQ_RTC1Hz, dev);
+	free_irq(info->irq_1hz, dev);
  fail_ui:
 	return ret;
 }
 
 static void sa1100_rtc_release(struct device *dev)
 {
-	spin_lock_irq(&sa1100_rtc_lock);
-	RTSR = 0;
-	spin_unlock_irq(&sa1100_rtc_lock);
+	struct sa1100_rtc *info = dev_get_drvdata(dev);
+
+	spin_lock_irq(&info->lock);
+	writel_relaxed(0, info->reg_rtsr);
+	spin_unlock_irq(&info->lock);
 
-	free_irq(IRQ_RTCAlrm, dev);
-	free_irq(IRQ_RTC1Hz, dev);
+	free_irq(info->irq_alarm, dev);
+	free_irq(info->irq_1hz, dev);
 }
 
 static int sa1100_rtc_alarm_irq_enable(struct device *dev, unsigned int enabled)
 {
-	spin_lock_irq(&sa1100_rtc_lock);
+	struct sa1100_rtc *info = dev_get_drvdata(dev);
+	unsigned long rtsr;
+	spin_lock_irq(&info->lock);
+	rtsr = readl_relaxed(info->reg_rtsr);
 	if (enabled)
-		RTSR |= RTSR_ALE;
+		rtsr |= RTSR_ALE;
 	else
-		RTSR &= ~RTSR_ALE;
-	spin_unlock_irq(&sa1100_rtc_lock);
+		rtsr &= ~RTSR_ALE;
+	writel_relaxed(rtsr, info->reg_rtsr);
+	spin_unlock_irq(&info->lock);
 	return 0;
 }
 
 static int sa1100_rtc_read_time(struct device *dev, struct rtc_time *tm)
 {
-	rtc_time_to_tm(RCNR, tm);
+	struct sa1100_rtc *info = dev_get_drvdata(dev);
+	unsigned long rcnr;
+
+	rcnr = readl_relaxed(info->reg_rcnr);
+	rtc_time_to_tm(rcnr, tm);
 	return 0;
 }
 
 static int sa1100_rtc_set_time(struct device *dev, struct rtc_time *tm)
 {
+	struct sa1100_rtc *info = dev_get_drvdata(dev);
 	unsigned long time;
 	int ret;
 
 	ret = rtc_tm_to_time(tm, &time);
 	if (ret == 0)
-		RCNR = time;
+		writel_relaxed(time, info->reg_rcnr);
 	return ret;
 }
 
 static int sa1100_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alrm)
 {
+	struct sa1100_rtc *info = dev_get_drvdata(dev);
 	u32	rtsr;
 
-	rtsr = RTSR;
+	rtsr = readl_relaxed(info->reg_rtsr);
 	alrm->enabled = (rtsr & RTSR_ALE) ? 1 : 0;
 	alrm->pending = (rtsr & RTSR_AL) ? 1 : 0;
 	return 0;
@@ -171,29 +240,38 @@ static int sa1100_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alrm)
 
 static int sa1100_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alrm)
 {
-	unsigned long time;
+	struct sa1100_rtc *info = dev_get_drvdata(dev);
+	unsigned long time, rtsr;
 	int ret;
 
-	spin_lock_irq(&sa1100_rtc_lock);
+	spin_lock_irq(&info->lock);
 	ret = rtc_tm_to_time(&alrm->time, &time);
 	if (ret != 0)
 		goto out;
-	RTSR = RTSR & (RTSR_HZE|RTSR_ALE|RTSR_AL);
-	RTAR = time;
+	rtsr = readl_relaxed(info->reg_rtsr);
+	rtsr &= RTSR_HZE | RTSR_ALE | RTSR_AL;
+	writel_relaxed(rtsr, info->reg_rtsr);
+	writel_relaxed(time, info->reg_rtar);
 	if (alrm->enabled)
-		RTSR |= RTSR_ALE;
+		rtsr |= RTSR_ALE;
 	else
-		RTSR &= ~RTSR_ALE;
+		rtsr &= ~RTSR_ALE;
+	writel_relaxed(rtsr, info->reg_rtsr);
 out:
-	spin_unlock_irq(&sa1100_rtc_lock);
+	spin_unlock_irq(&info->lock);
 
 	return ret;
 }
 
 static int sa1100_rtc_proc(struct device *dev, struct seq_file *seq)
 {
-	seq_printf(seq, "trim/divider\t\t: 0x%08x\n", (u32) RTTR);
-	seq_printf(seq, "RTSR\t\t\t: 0x%08x\n", (u32)RTSR);
+	struct sa1100_rtc *info = dev_get_drvdata(dev);
+	unsigned long rttr, rtsr;
+
+	rttr = readl_relaxed(info->reg_rttr);
+	rtsr = readl_relaxed(info->reg_rtsr);
+	seq_printf(seq, "trim/divider\t\t: 0x%08x\n", (u32)rttr);
+	seq_printf(seq, "RTSR\t\t\t: 0x%08x\n", (u32)rtsr);
 
 	return 0;
 }
@@ -211,7 +289,39 @@ static const struct rtc_class_ops sa1100_rtc_ops = {
 
 static int sa1100_rtc_probe(struct platform_device *pdev)
 {
+	const struct platform_device_id *id = platform_get_device_id(pdev);
+	enum sa1100_rtc_types rtc_type = id->driver_data;
 	struct rtc_device *rtc;
+	struct resource *res;
+	struct sa1100_rtc *info;
+	int irq_1hz, irq_alarm, ret = 0;
+
+	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+	irq_1hz = platform_get_irq_byname(pdev, "rtc 1Hz");
+	irq_alarm = platform_get_irq_byname(pdev, "rtc alarm");
+	if (res == NULL || irq_1hz < 0 || irq_alarm < 0)
+		return -ENODEV;
+
+	info = kzalloc(sizeof(struct sa1100_rtc), GFP_KERNEL);
+	if (!info)
+		return -ENOMEM;
+
+	info->iobase = res->start;
+	info->iosize = resource_size(res);
+	info->irq_1hz = irq_1hz;
+	info->irq_alarm = irq_alarm;
+	spin_lock_init(&info->lock);
+	platform_set_drvdata(pdev, info);
+
+	info->reg_base = ioremap(info->iobase, info->iosize);
+	if (!info->reg_base) {
+		ret = -EIO;
+		goto err_map;
+	}
+	info->reg_rcnr = info->reg_base + sa1100_layout[rtc_type].rcnr;
+	info->reg_rtar = info->reg_base + sa1100_layout[rtc_type].rtar;
+	info->reg_rtsr = info->reg_base + sa1100_layout[rtc_type].rtsr;
+	info->reg_rttr = info->reg_base + sa1100_layout[rtc_type].rttr;
 
 	/*
 	 * According to the manual we should be able to let RTTR be zero
@@ -220,12 +330,13 @@ static int sa1100_rtc_probe(struct platform_device *pdev)
 	 * If the clock divider is uninitialized then reset it to the
 	 * default value to get the 1Hz clock.
 	 */
-	if (RTTR == 0) {
-		RTTR = RTC_DEF_DIVIDER + (RTC_DEF_TRIM << 16);
+	if (readl_relaxed(info->reg_rttr) == 0) {
+		writel_relaxed(RTC_DEF_DIVIDER + (RTC_DEF_TRIM << 16),
+				info->reg_rttr);
 		dev_warn(&pdev->dev, "warning: "
 			"initializing default clock divider/trim value\n");
 		/* The current RTC value probably doesn't make sense either */
-		RCNR = 0;
+		writel_relaxed(0, info->reg_rcnr);
 	}
 
 	device_init_wakeup(&pdev->dev, 1);
@@ -233,10 +344,11 @@ static int sa1100_rtc_probe(struct platform_device *pdev)
 	rtc = rtc_device_register(pdev->name, &pdev->dev, &sa1100_rtc_ops,
 		THIS_MODULE);
 
-	if (IS_ERR(rtc))
-		return PTR_ERR(rtc);
-
-	platform_set_drvdata(pdev, rtc);
+	if (IS_ERR(rtc)) {
+		ret = PTR_ERR(rtc);
+		goto err_dev;
+	}
+	info->rtc = rtc;
 
 	/* Fix for a nasty initialization problem the in SA11xx RTSR register.
 	 * See also the comments in sa1100_rtc_interrupt().
@@ -260,17 +372,27 @@ static int sa1100_rtc_probe(struct platform_device *pdev)
 	 *
 	 * Notice that clearing bit 1 and 0 is accomplished by writting ONES to
 	 * the corresponding bits in RTSR. */
-	RTSR = RTSR_AL | RTSR_HZ;
+	writel_relaxed(RTSR_AL | RTSR_HZ, info->reg_rtsr);
 
 	return 0;
+err_dev:
+	iounmap(info->reg_base);
+err_map:
+	platform_set_drvdata(pdev, NULL);
+	kfree(info);
+	return ret;
 }
 
 static int sa1100_rtc_remove(struct platform_device *pdev)
 {
-	struct rtc_device *rtc = platform_get_drvdata(pdev);
+	struct sa1100_rtc *info = platform_get_drvdata(pdev);
 
-	if (rtc)
-		rtc_device_unregister(rtc);
+	if (info) {
+		rtc_device_unregister(info->rtc);
+		platform_set_drvdata(pdev, NULL);
+		iounmap(info->reg_base);
+		kfree(info);
+	}
 
 	return 0;
 }
@@ -278,15 +400,17 @@ static int sa1100_rtc_remove(struct platform_device *pdev)
 #ifdef CONFIG_PM
 static int sa1100_rtc_suspend(struct device *dev)
 {
+	struct sa1100_rtc *info = dev_get_drvdata(dev);
 	if (device_may_wakeup(dev))
-		enable_irq_wake(IRQ_RTCAlrm);
+		enable_irq_wake(info->irq_alarm);
 	return 0;
 }
 
 static int sa1100_rtc_resume(struct device *dev)
 {
+	struct sa1100_rtc *info = dev_get_drvdata(dev);
 	if (device_may_wakeup(dev))
-		disable_irq_wake(IRQ_RTCAlrm);
+		disable_irq_wake(info->irq_alarm);
 	return 0;
 }
 
@@ -305,6 +429,7 @@ static struct platform_driver sa1100_rtc_driver = {
 		.pm	= &sa1100_rtc_pm_ops,
 #endif
 	},
+	.id_table	= sa1100_rtc_id_table,
 };
 
 module_platform_driver(sa1100_rtc_driver);
-- 
1.7.0.4

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

* [PATCH 0/7] share sa1100 rtc driver to arch-mmp
  2012-02-23  0:51           ` Haojian Zhuang
@ 2012-02-23  8:52             ` Robert Jarzmik
  2012-02-23  9:45               ` Haojian Zhuang
  0 siblings, 1 reply; 40+ messages in thread
From: Robert Jarzmik @ 2012-02-23  8:52 UTC (permalink / raw)
  To: linux-arm-kernel

Haojian Zhuang <haojian.zhuang@gmail.com> writes:

> Hi Robert,
>
> I hadn't any plan to remove rtc-pxa driver. I only disabled it for
> pxa27x/pxa3xx. Please check the code of
> arch/arm/mach-pxa/sharpsl_pm.c. If we only enable rtc-pxa on pxa27x,
> we'll break the behavior on sharpsl since it's using rtc-sa1100. In
> order to keep code consistently, I disable rtc-pxa on pxa27x/pxa3xx.

Then you'll break mioa701 board, which is pxa270 based. The RYCR/RDCR were
introduced on PXA27x chips, so the rtc-pxa driver should work on pxa27x SoCs.

The behaviour should be as before, the config should be able to choose between
rtc-pxa and rtc-sa1100 for a pxa27x based board. For sharpsl_pm, I suppose the
rtc-sa1100 will be chosen in the .config, and for mioa701, it will be
rtc-pxa.

Just to clear, I'm against removing "resources, clock" from pxa27x platform code
which would break rtc-pxa driver on pxa27x. Now I don't care if you're talking
about changing some "defconfigs".

Cheers.

-- 
Robert

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

* [PATCH 0/7] share sa1100 rtc driver to arch-mmp
  2012-02-23  8:52             ` Robert Jarzmik
@ 2012-02-23  9:45               ` Haojian Zhuang
  2012-02-23 10:00                 ` Russell King - ARM Linux
  0 siblings, 1 reply; 40+ messages in thread
From: Haojian Zhuang @ 2012-02-23  9:45 UTC (permalink / raw)
  To: linux-arm-kernel

On Thu, Feb 23, 2012 at 4:52 PM, Robert Jarzmik <robert.jarzmik@free.fr> wrote:
> Haojian Zhuang <haojian.zhuang@gmail.com> writes:
>
>> Hi Robert,
>>
>> I hadn't any plan to remove rtc-pxa driver. I only disabled it for
>> pxa27x/pxa3xx. Please check the code of
>> arch/arm/mach-pxa/sharpsl_pm.c. If we only enable rtc-pxa on pxa27x,
>> we'll break the behavior on sharpsl since it's using rtc-sa1100. In
>> order to keep code consistently, I disable rtc-pxa on pxa27x/pxa3xx.
>
> Then you'll break mioa701 board, which is pxa270 based. The RYCR/RDCR were
> introduced on PXA27x chips, so the rtc-pxa driver should work on pxa27x SoCs.
>
> The behaviour should be as before, the config should be able to choose between
> rtc-pxa and rtc-sa1100 for a pxa27x based board. For sharpsl_pm, I suppose the
> rtc-sa1100 will be chosen in the .config, and for mioa701, it will be
> rtc-pxa.
>
> Just to clear, I'm against removing "resources, clock" from pxa27x platform code
> which would break rtc-pxa driver on pxa27x. Now I don't care if you're talking
> about changing some "defconfigs".
>

How about to move the rtc-sa1100 or rtc-pxa device register from
pxa27x.c to board file? Then we'll be both happy.

Thanks
Haojian

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

* [PATCH 0/7] share sa1100 rtc driver to arch-mmp
  2012-02-23  9:45               ` Haojian Zhuang
@ 2012-02-23 10:00                 ` Russell King - ARM Linux
  2012-02-23 10:22                   ` Haojian Zhuang
  0 siblings, 1 reply; 40+ messages in thread
From: Russell King - ARM Linux @ 2012-02-23 10:00 UTC (permalink / raw)
  To: linux-arm-kernel

On Thu, Feb 23, 2012 at 05:45:20PM +0800, Haojian Zhuang wrote:
> On Thu, Feb 23, 2012 at 4:52 PM, Robert Jarzmik <robert.jarzmik@free.fr> wrote:
> > The behaviour should be as before, the config should be able to choose between
> > rtc-pxa and rtc-sa1100 for a pxa27x based board. For sharpsl_pm, I suppose the
> > rtc-sa1100 will be chosen in the .config, and for mioa701, it will be
> > rtc-pxa.
> >
> > Just to clear, I'm against removing "resources, clock" from pxa27x platform code
> > which would break rtc-pxa driver on pxa27x. Now I don't care if you're talking
> > about changing some "defconfigs".
> >
> 
> How about to move the rtc-sa1100 or rtc-pxa device register from
> pxa27x.c to board file? Then we'll be both happy.

How about stopping thinking about "one or other" and start thinking "both" ?
The RTC library can and does cope with more than one RTC, and each RTC is
exposed uniquely to userspace.  So there shouldn't be any problem in keeping
both around, or even registering both together.

You just have to make sure you don't use both of them together as their
open functions will want to claim the same IRQ.  That's not really a
problem because that should provide exclusivity between the two.

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

* [PATCH 0/7] share sa1100 rtc driver to arch-mmp
  2012-02-23 10:00                 ` Russell King - ARM Linux
@ 2012-02-23 10:22                   ` Haojian Zhuang
  2012-02-23 10:49                     ` Russell King - ARM Linux
  0 siblings, 1 reply; 40+ messages in thread
From: Haojian Zhuang @ 2012-02-23 10:22 UTC (permalink / raw)
  To: linux-arm-kernel

On Thu, Feb 23, 2012 at 6:00 PM, Russell King - ARM Linux
<linux@arm.linux.org.uk> wrote:
> On Thu, Feb 23, 2012 at 05:45:20PM +0800, Haojian Zhuang wrote:
>> On Thu, Feb 23, 2012 at 4:52 PM, Robert Jarzmik <robert.jarzmik@free.fr> wrote:
>> > The behaviour should be as before, the config should be able to choose between
>> > rtc-pxa and rtc-sa1100 for a pxa27x based board. For sharpsl_pm, I suppose the
>> > rtc-sa1100 will be chosen in the .config, and for mioa701, it will be
>> > rtc-pxa.
>> >
>> > Just to clear, I'm against removing "resources, clock" from pxa27x platform code
>> > which would break rtc-pxa driver on pxa27x. Now I don't care if you're talking
>> > about changing some "defconfigs".
>> >
>>
>> How about to move the rtc-sa1100 or rtc-pxa device register from
>> pxa27x.c to board file? Then we'll be both happy.
>
> How about stopping thinking about "one or other" and start thinking "both" ?
> The RTC library can and does cope with more than one RTC, and each RTC is
> exposed uniquely to userspace. ?So there shouldn't be any problem in keeping
> both around, or even registering both together.
>
> You just have to make sure you don't use both of them together as their
> open functions will want to claim the same IRQ. ?That's not really a
> problem because that should provide exclusivity between the two.

Resource is bind with platform device. We'll meet resource conflict if
we register them both.

Thanks
Haojian

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

* [PATCH v2 3/7] rtc: sa1100: use ioremap to map registers
  2012-02-23  3:28   ` [PATCH v2 " Haojian Zhuang
@ 2012-02-23 10:26     ` Russell King - ARM Linux
  0 siblings, 0 replies; 40+ messages in thread
From: Russell King - ARM Linux @ 2012-02-23 10:26 UTC (permalink / raw)
  To: linux-arm-kernel

On Thu, Feb 23, 2012 at 11:28:29AM +0800, Haojian Zhuang wrote:
>  static int sa1100_rtc_read_time(struct device *dev, struct rtc_time *tm)
>  {
> -	rtc_time_to_tm(RCNR, tm);
> +	struct sa1100_rtc *info = dev_get_drvdata(dev);
> +	unsigned long rcnr;
> +
> +	rcnr = readl_relaxed(info->reg_rcnr);
> +	rtc_time_to_tm(rcnr, tm);

Just one nit - this could be:

	struct sa1100_rtc *info = dev_get_drvdata(dev);

	rtc_time_to_tm(readl_relaxed(info->reg_rcnr), tm);

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

* [PATCH 4/7] ARM: sa1100: clean up of the clock support
  2012-02-21  9:04 ` [PATCH 4/7] ARM: sa1100: clean up of the clock support Haojian Zhuang
  2012-02-22 12:31   ` Arnd Bergmann
@ 2012-02-23 10:32   ` Russell King - ARM Linux
  1 sibling, 0 replies; 40+ messages in thread
From: Russell King - ARM Linux @ 2012-02-23 10:32 UTC (permalink / raw)
  To: linux-arm-kernel

On Tue, Feb 21, 2012 at 05:04:53PM +0800, Haojian Zhuang wrote:
> From: Jett.Zhou <jtzhou@marvell.com>
> 
> Signed-off-by: Jett.Zhou <jtzhou@marvell.com>
> signed-off-by: Haojian Zhuang <haojian.zhuang@marvell.com>
> ---
>  arch/arm/Kconfig             |    2 +-
>  arch/arm/mach-sa1100/clock.c |   91 ++++++++++++++++++++++++++++++-----------
>  2 files changed, 67 insertions(+), 26 deletions(-)
> 
> diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig
> index a48aecc..6e40039 100644
> --- a/arch/arm/Kconfig
> +++ b/arch/arm/Kconfig
> @@ -754,7 +754,7 @@ config ARCH_SA1100
>  	select ARCH_HAS_CPUFREQ
>  	select CPU_FREQ
>  	select GENERIC_CLOCKEVENTS
> -	select HAVE_CLK
> +	select CLKDEV_LOOKUP
>  	select HAVE_SCHED_CLOCK
>  	select TICK_ONESHOT
>  	select ARCH_REQUIRE_GPIOLIB
> diff --git a/arch/arm/mach-sa1100/clock.c b/arch/arm/mach-sa1100/clock.c
> index dab3c63..d6df9f6 100644
> --- a/arch/arm/mach-sa1100/clock.c
> +++ b/arch/arm/mach-sa1100/clock.c
> @@ -11,17 +11,39 @@
>  #include <linux/clk.h>
>  #include <linux/spinlock.h>
>  #include <linux/mutex.h>
> +#include <linux/io.h>
> +#include <linux/clkdev.h>
>  
>  #include <mach/hardware.h>
>  
> -/*
> - * Very simple clock implementation - we only have one clock to deal with.
> - */
> +struct clkops {
> +	void			(*enable)(struct clk *);
> +	void			(*disable)(struct clk *);
> +	unsigned long		(*getrate)(struct clk *);

Is getrate() used?  If not, please get rid of it.

> +};
> +
>  struct clk {
> +	const struct clkops	*ops;
> +	unsigned long		rate;
>  	unsigned int		enabled;
>  };
>  
> -static void clk_gpio27_enable(void)
> +#define INIT_CLKREG(_clk, _devname, _conname)		\
> +	{						\
> +		.clk		= _clk,			\
> +		.dev_id		= _devname,		\
> +		.con_id		= _conname,		\
> +	}

This should use CLKDEV_INIT() rather than defining its own.

> +
> +#define DEFINE_CLK(_name, _ops, _rate)			\
> +struct clk clk_##_name = {				\
> +		.ops	= _ops,				\
> +		.rate	= _rate,			\
> +	}
> +
> +static DEFINE_SPINLOCK(clocks_lock);
> +
> +static void clk_gpio27_enable(struct clk *clk)
>  {
>  	/*
>  	 * First, set up the 3.6864MHz clock on GPIO 27 for the SA-1111:
> @@ -32,38 +54,22 @@ static void clk_gpio27_enable(void)
>  	TUCR = TUCR_3_6864MHz;
>  }
>  
> -static void clk_gpio27_disable(void)
> +static void clk_gpio27_disable(struct clk *clk)
>  {
>  	TUCR = 0;
>  	GPDR &= ~GPIO_32_768kHz;
>  	GAFR &= ~GPIO_32_768kHz;
>  }
>  
> -static struct clk clk_gpio27;
> -
> -static DEFINE_SPINLOCK(clocks_lock);
> -
> -struct clk *clk_get(struct device *dev, const char *id)
> -{
> -	const char *devname = dev_name(dev);
> -
> -	return strcmp(devname, "sa1111.0") ? ERR_PTR(-ENOENT) : &clk_gpio27;
> -}
> -EXPORT_SYMBOL(clk_get);
> -
> -void clk_put(struct clk *clk)
> -{
> -}
> -EXPORT_SYMBOL(clk_put);
> -
>  int clk_enable(struct clk *clk)
>  {
>  	unsigned long flags;
>  

	if (clk) {

>  	spin_lock_irqsave(&clocks_lock, flags);
>  	if (clk->enabled++ == 0)
> -		clk_gpio27_enable();
> +		clk->ops->enable(clk);
>  	spin_unlock_irqrestore(&clocks_lock, flags);

	}

> +
>  	return 0;
>  }
>  EXPORT_SYMBOL(clk_enable);
> @@ -76,13 +82,48 @@ void clk_disable(struct clk *clk)
>  

	if (clk) {

>  	spin_lock_irqsave(&clocks_lock, flags);
>  	if (--clk->enabled == 0)
> -		clk_gpio27_disable();
> +		clk->ops->disable(clk);
>  	spin_unlock_irqrestore(&clocks_lock, flags);

	}

>  }
>  EXPORT_SYMBOL(clk_disable);
>  
>  unsigned long clk_get_rate(struct clk *clk)
>  {
> -	return 3686400;
> +	unsigned long rate;
> +

	unsigned long rate = 0;
	if (clk) {

> +	rate = clk->rate;
> +	if (clk->ops->getrate)
> +		rate = clk->ops->getrate(clk);

	}

> +
> +	return rate;
>  }
>  EXPORT_SYMBOL(clk_get_rate);
> +
> +const struct clkops clk_gpio27_ops = {
> +	.enable		= clk_gpio27_enable,
> +	.disable	= clk_gpio27_disable,
> +};
> +
> +static void clk_dummy_enable(struct clk *clk) { }
> +static void clk_dummy_disable(struct clk *clk) { }
> +
> +const struct clkops clk_dummy_ops = {
> +	.enable		= clk_dummy_enable,
> +	.disable	= clk_dummy_disable,
> +};
> +
> +static DEFINE_CLK(gpio27, &clk_gpio27_ops, 3686400);
> +static DEFINE_CLK(dummy, &clk_dummy_ops, 0);

Get rid of the dummy clock...

> +
> +static struct clk_lookup sa11xx_clkregs[] = {
> +	INIT_CLKREG(&clk_gpio27, "sa1111.0", NULL),
> +	INIT_CLKREG(&clk_dummy, "sa1100-rtc", NULL),

	CLKDEV_INIT("sa1100-rtc", NULL, NULL),

> +};
> +
> +static int __init sa11xx_clk_init(void)
> +{
> +	clkdev_add_table(sa11xx_clkregs, ARRAY_SIZE(sa11xx_clkregs));
> +	return 0;
> +}
> +
> +postcore_initcall(sa11xx_clk_init);

Why postcore?  There's nothing stopping this being done earlier.

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

* [PATCH 6/7] rtc: sa1100: enable clk support
  2012-02-21  9:04 ` [PATCH 6/7] rtc: sa1100: enable clk support Haojian Zhuang
  2012-02-22 12:29   ` Arnd Bergmann
@ 2012-02-23 10:34   ` Russell King - ARM Linux
  2012-02-23 10:40     ` Haojian Zhuang
  1 sibling, 1 reply; 40+ messages in thread
From: Russell King - ARM Linux @ 2012-02-23 10:34 UTC (permalink / raw)
  To: linux-arm-kernel

On Tue, Feb 21, 2012 at 05:04:55PM +0800, Haojian Zhuang wrote:
> @@ -306,6 +308,13 @@ static int sa1100_rtc_probe(struct platform_device *pdev)
>  	if (!info)
>  		return -ENOMEM;
>  
> +	info->clk = clk_get(&pdev->dev, NULL);
> +	if (IS_ERR(info->clk)) {
> +		dev_err(&pdev->dev, "failed to find rtc clock source\n");
> +		ret = PTR_ERR(info->clk);
> +		goto err_clk;
> +	}
> +	clk_prepare_enable(info->clk);

What about checking for errors from clk_prepare_enable() ?

I assume that this is the clock required to access the peripheral, rather
than the timekeeping clock?  If so, does it need to be kept enabled all
the time the driver is probed, or can the clock be prepared & enabled and
disabled & unprepared when the device is opened/closed ?

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

* [PATCH 6/7] rtc: sa1100: enable clk support
  2012-02-23 10:34   ` Russell King - ARM Linux
@ 2012-02-23 10:40     ` Haojian Zhuang
  2012-02-23 10:54       ` Russell King - ARM Linux
  0 siblings, 1 reply; 40+ messages in thread
From: Haojian Zhuang @ 2012-02-23 10:40 UTC (permalink / raw)
  To: linux-arm-kernel

On Thu, Feb 23, 2012 at 6:34 PM, Russell King - ARM Linux
<linux@arm.linux.org.uk> wrote:
> On Tue, Feb 21, 2012 at 05:04:55PM +0800, Haojian Zhuang wrote:
>> @@ -306,6 +308,13 @@ static int sa1100_rtc_probe(struct platform_device *pdev)
>> ? ? ? if (!info)
>> ? ? ? ? ? ? ? return -ENOMEM;
>>
>> + ? ? info->clk = clk_get(&pdev->dev, NULL);
>> + ? ? if (IS_ERR(info->clk)) {
>> + ? ? ? ? ? ? dev_err(&pdev->dev, "failed to find rtc clock source\n");
>> + ? ? ? ? ? ? ret = PTR_ERR(info->clk);
>> + ? ? ? ? ? ? goto err_clk;
>> + ? ? }
>> + ? ? clk_prepare_enable(info->clk);
>
> What about checking for errors from clk_prepare_enable() ?
>
> I assume that this is the clock required to access the peripheral, rather
> than the timekeeping clock? ?If so, does it need to be kept enabled all
> the time the driver is probed, or can the clock be prepared & enabled and
> disabled & unprepared when the device is opened/closed ?
>
Since some platform code is using RTC register in their suspend/resume
routine, I have to always enable the clock of rtc module.

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

* [PATCH 0/7] share sa1100 rtc driver to arch-mmp
  2012-02-23 10:22                   ` Haojian Zhuang
@ 2012-02-23 10:49                     ` Russell King - ARM Linux
  2012-02-23 10:59                       ` Russell King - ARM Linux
  2012-02-23 13:32                       ` Haojian Zhuang
  0 siblings, 2 replies; 40+ messages in thread
From: Russell King - ARM Linux @ 2012-02-23 10:49 UTC (permalink / raw)
  To: linux-arm-kernel

On Thu, Feb 23, 2012 at 06:22:23PM +0800, Haojian Zhuang wrote:
> On Thu, Feb 23, 2012 at 6:00 PM, Russell King - ARM Linux
> <linux@arm.linux.org.uk> wrote:
> > On Thu, Feb 23, 2012 at 05:45:20PM +0800, Haojian Zhuang wrote:
> >> On Thu, Feb 23, 2012 at 4:52 PM, Robert Jarzmik <robert.jarzmik@free.fr> wrote:
> >> > The behaviour should be as before, the config should be able to choose between
> >> > rtc-pxa and rtc-sa1100 for a pxa27x based board. For sharpsl_pm, I suppose the
> >> > rtc-sa1100 will be chosen in the .config, and for mioa701, it will be
> >> > rtc-pxa.
> >> >
> >> > Just to clear, I'm against removing "resources, clock" from pxa27x platform code
> >> > which would break rtc-pxa driver on pxa27x. Now I don't care if you're talking
> >> > about changing some "defconfigs".
> >> >
> >>
> >> How about to move the rtc-sa1100 or rtc-pxa device register from
> >> pxa27x.c to board file? Then we'll be both happy.
> >
> > How about stopping thinking about "one or other" and start thinking "both" ?
> > The RTC library can and does cope with more than one RTC, and each RTC is
> > exposed uniquely to userspace. ?So there shouldn't be any problem in keeping
> > both around, or even registering both together.
> >
> > You just have to make sure you don't use both of them together as their
> > open functions will want to claim the same IRQ. ?That's not really a
> > problem because that should provide exclusivity between the two.
> 
> Resource is bind with platform device. We'll meet resource conflict if
> we register them both.

Ok, in that case we need patch 3 split up such that we can move forward
and get some of the build errors fixed.

That probably means that the first half of patch 3 should be providing the
IRQs and only the IRQs to the driver, and the driver making use of that
information.  Nothing more than that - not even the differing register
offsets.

The next stage would be to introduce the different device names, and use
that to chose the different register layouts - but still using a hard coded
base address.  That will involve adding a new define for this to both
arch/arm/mach-sa1100/include/mach/SA-1100.h and
arch/arm/mach-pxa/include/mach/regs-rtc.h.  At the same time, this patch
should move the register definitions from those headers into the sa1100 RTC
driver, and get rid of the virtual address definitions for these registers.

The clocking issues can also be sorted out as well without solving the base
address issue - and that gets most of this patch set ready for merging
without causing Robert any problems.

I would like to see this ASAP so that the current build regression with
PXA can be fixed.

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

* [PATCH 6/7] rtc: sa1100: enable clk support
  2012-02-23 10:40     ` Haojian Zhuang
@ 2012-02-23 10:54       ` Russell King - ARM Linux
  0 siblings, 0 replies; 40+ messages in thread
From: Russell King - ARM Linux @ 2012-02-23 10:54 UTC (permalink / raw)
  To: linux-arm-kernel

On Thu, Feb 23, 2012 at 06:40:40PM +0800, Haojian Zhuang wrote:
> On Thu, Feb 23, 2012 at 6:34 PM, Russell King - ARM Linux
> <linux@arm.linux.org.uk> wrote:
> > On Tue, Feb 21, 2012 at 05:04:55PM +0800, Haojian Zhuang wrote:
> >> @@ -306,6 +308,13 @@ static int sa1100_rtc_probe(struct platform_device *pdev)
> >> ? ? ? if (!info)
> >> ? ? ? ? ? ? ? return -ENOMEM;
> >>
> >> + ? ? info->clk = clk_get(&pdev->dev, NULL);
> >> + ? ? if (IS_ERR(info->clk)) {
> >> + ? ? ? ? ? ? dev_err(&pdev->dev, "failed to find rtc clock source\n");
> >> + ? ? ? ? ? ? ret = PTR_ERR(info->clk);
> >> + ? ? ? ? ? ? goto err_clk;
> >> + ? ? }
> >> + ? ? clk_prepare_enable(info->clk);
> >
> > What about checking for errors from clk_prepare_enable() ?
> >
> > I assume that this is the clock required to access the peripheral, rather
> > than the timekeeping clock? ?If so, does it need to be kept enabled all
> > the time the driver is probed, or can the clock be prepared & enabled and
> > disabled & unprepared when the device is opened/closed ?
> >
> Since some platform code is using RTC register in their suspend/resume
> routine, I have to always enable the clock of rtc module.

So what happens if they don't have the RTC module loaded in their kernel?
The proper solution to this is that they need to take care of that clock
themselves and stop relying on a module being loaded or built-in.

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

* [PATCH 0/7] share sa1100 rtc driver to arch-mmp
  2012-02-23 10:49                     ` Russell King - ARM Linux
@ 2012-02-23 10:59                       ` Russell King - ARM Linux
  2012-02-23 13:32                       ` Haojian Zhuang
  1 sibling, 0 replies; 40+ messages in thread
From: Russell King - ARM Linux @ 2012-02-23 10:59 UTC (permalink / raw)
  To: linux-arm-kernel

On Thu, Feb 23, 2012 at 10:49:37AM +0000, Russell King - ARM Linux wrote:
> On Thu, Feb 23, 2012 at 06:22:23PM +0800, Haojian Zhuang wrote:
> > On Thu, Feb 23, 2012 at 6:00 PM, Russell King - ARM Linux
> > <linux@arm.linux.org.uk> wrote:
> > > On Thu, Feb 23, 2012 at 05:45:20PM +0800, Haojian Zhuang wrote:
> > >> On Thu, Feb 23, 2012 at 4:52 PM, Robert Jarzmik <robert.jarzmik@free.fr> wrote:
> > >> > The behaviour should be as before, the config should be able to choose between
> > >> > rtc-pxa and rtc-sa1100 for a pxa27x based board. For sharpsl_pm, I suppose the
> > >> > rtc-sa1100 will be chosen in the .config, and for mioa701, it will be
> > >> > rtc-pxa.
> > >> >
> > >> > Just to clear, I'm against removing "resources, clock" from pxa27x platform code
> > >> > which would break rtc-pxa driver on pxa27x. Now I don't care if you're talking
> > >> > about changing some "defconfigs".
> > >> >
> > >>
> > >> How about to move the rtc-sa1100 or rtc-pxa device register from
> > >> pxa27x.c to board file? Then we'll be both happy.
> > >
> > > How about stopping thinking about "one or other" and start thinking "both" ?
> > > The RTC library can and does cope with more than one RTC, and each RTC is
> > > exposed uniquely to userspace. ?So there shouldn't be any problem in keeping
> > > both around, or even registering both together.
> > >
> > > You just have to make sure you don't use both of them together as their
> > > open functions will want to claim the same IRQ. ?That's not really a
> > > problem because that should provide exclusivity between the two.
> > 
> > Resource is bind with platform device. We'll meet resource conflict if
> > we register them both.
> 
> Ok, in that case we need patch 3 split up such that we can move forward
> and get some of the build errors fixed.
> 
> That probably means that the first half of patch 3 should be providing the
> IRQs and only the IRQs to the driver, and the driver making use of that
> information.  Nothing more than that - not even the differing register
> offsets.
> 
> The next stage would be to introduce the different device names, and use
> that to chose the different register layouts - but still using a hard coded
> base address.  That will involve adding a new define for this to both
> arch/arm/mach-sa1100/include/mach/SA-1100.h and
> arch/arm/mach-pxa/include/mach/regs-rtc.h.  At the same time, this patch
> should move the register definitions from those headers into the sa1100 RTC
> driver, and get rid of the virtual address definitions for these registers.

Note: I think that should be done even though sharpsl_pm and miao both
access the RTC registers directly, even though it means duplicating the
definitions.

In the long run, someone needs to look at whether sharpsl_pm can be made
to use the alarmtimer stuff (kernel/time/alarmtimer.c) but that's a
project for someone with a Zaurus to do.  No one else can do it.

> The clocking issues can also be sorted out as well without solving the base
> address issue - and that gets most of this patch set ready for merging
> without causing Robert any problems.
> 
> I would like to see this ASAP so that the current build regression with
> PXA can be fixed.
> 
> _______________________________________________
> linux-arm-kernel mailing list
> linux-arm-kernel at lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* [PATCH 0/7] share sa1100 rtc driver to arch-mmp
  2012-02-23 10:49                     ` Russell King - ARM Linux
  2012-02-23 10:59                       ` Russell King - ARM Linux
@ 2012-02-23 13:32                       ` Haojian Zhuang
  2012-02-23 14:04                         ` Russell King - ARM Linux
  1 sibling, 1 reply; 40+ messages in thread
From: Haojian Zhuang @ 2012-02-23 13:32 UTC (permalink / raw)
  To: linux-arm-kernel

On Thu, Feb 23, 2012 at 6:49 PM, Russell King - ARM Linux
<linux@arm.linux.org.uk> wrote:
> On Thu, Feb 23, 2012 at 06:22:23PM +0800, Haojian Zhuang wrote:
>> On Thu, Feb 23, 2012 at 6:00 PM, Russell King - ARM Linux
>> <linux@arm.linux.org.uk> wrote:
>> > On Thu, Feb 23, 2012 at 05:45:20PM +0800, Haojian Zhuang wrote:
>> >> On Thu, Feb 23, 2012 at 4:52 PM, Robert Jarzmik <robert.jarzmik@free.fr> wrote:
>> >> > The behaviour should be as before, the config should be able to choose between
>> >> > rtc-pxa and rtc-sa1100 for a pxa27x based board. For sharpsl_pm, I suppose the
>> >> > rtc-sa1100 will be chosen in the .config, and for mioa701, it will be
>> >> > rtc-pxa.
>> >> >
>> >> > Just to clear, I'm against removing "resources, clock" from pxa27x platform code
>> >> > which would break rtc-pxa driver on pxa27x. Now I don't care if you're talking
>> >> > about changing some "defconfigs".
>> >> >
>> >>
>> >> How about to move the rtc-sa1100 or rtc-pxa device register from
>> >> pxa27x.c to board file? Then we'll be both happy.
>> >
>> > How about stopping thinking about "one or other" and start thinking "both" ?
>> > The RTC library can and does cope with more than one RTC, and each RTC is
>> > exposed uniquely to userspace. ?So there shouldn't be any problem in keeping
>> > both around, or even registering both together.
>> >
>> > You just have to make sure you don't use both of them together as their
>> > open functions will want to claim the same IRQ. ?That's not really a
>> > problem because that should provide exclusivity between the two.
>>
>> Resource is bind with platform device. We'll meet resource conflict if
>> we register them both.
>
> Ok, in that case we need patch 3 split up such that we can move forward
> and get some of the build errors fixed.
>
> That probably means that the first half of patch 3 should be providing the
> IRQs and only the IRQs to the driver, and the driver making use of that
> information. ?Nothing more than that - not even the differing register
> offsets.
>
> The next stage would be to introduce the different device names, and use
> that to chose the different register layouts - but still using a hard coded
> base address. ?That will involve adding a new define for this to both
> arch/arm/mach-sa1100/include/mach/SA-1100.h and
> arch/arm/mach-pxa/include/mach/regs-rtc.h. ?At the same time, this patch
> should move the register definitions from those headers into the sa1100 RTC
> driver, and get rid of the virtual address definitions for these registers.

OK. I can keep the hard coded register definition and format patch right now.
The rtc register base of arch-sa1100, arch-pxa, arch-mmp are
different. It means
that I need use #ifdef CONFIG_ARCH to distinguish different arch. But I have a
question that removing #ifdef CONFIG_ARCH in driver code is our
target, isn't it?

>
> The clocking issues can also be sorted out as well without solving the base
> address issue - and that gets most of this patch set ready for merging
> without causing Robert any problems.
>
> I would like to see this ASAP so that the current build regression with
> PXA can be fixed.

OK. I'll move the clock operation in open()/close() function.

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

* [PATCH 0/7] share sa1100 rtc driver to arch-mmp
  2012-02-23 13:32                       ` Haojian Zhuang
@ 2012-02-23 14:04                         ` Russell King - ARM Linux
  0 siblings, 0 replies; 40+ messages in thread
From: Russell King - ARM Linux @ 2012-02-23 14:04 UTC (permalink / raw)
  To: linux-arm-kernel

On Thu, Feb 23, 2012 at 09:32:30PM +0800, Haojian Zhuang wrote:
> OK. I can keep the hard coded register definition and format patch right now.
> The rtc register base of arch-sa1100, arch-pxa, arch-mmp are
> different. It means
> that I need use #ifdef CONFIG_ARCH to distinguish different arch. But I have a
> question that removing #ifdef CONFIG_ARCH in driver code is our
> target, isn't it?

Yes, but we can't do that until the pxa-rtc vs sa1100-rtc issue is
resolved.

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

end of thread, other threads:[~2012-02-23 14:04 UTC | newest]

Thread overview: 40+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-02-21  9:04 [PATCH 0/7] share sa1100 rtc driver to arch-mmp Haojian Zhuang
2012-02-21  9:04 ` [PATCH 1/7] rtc: sa1100: remove periodic code Haojian Zhuang
2012-02-21  9:04 ` [PATCH 2/7] rtc: sa1100: remove verification code of alarm Haojian Zhuang
2012-02-21  9:04 ` [PATCH 3/7] rtc: sa1100: use ioremap to map registers Haojian Zhuang
2012-02-22 12:33   ` Arnd Bergmann
2012-02-22 23:58   ` Russell King - ARM Linux
2012-02-23  0:55     ` Haojian Zhuang
2012-02-23  3:28   ` [PATCH v2 " Haojian Zhuang
2012-02-23 10:26     ` Russell King - ARM Linux
2012-02-21  9:04 ` [PATCH 4/7] ARM: sa1100: clean up of the clock support Haojian Zhuang
2012-02-22 12:31   ` Arnd Bergmann
2012-02-23 10:32   ` Russell King - ARM Linux
2012-02-21  9:04 ` [PATCH 5/7] ARM: pxa: add rtc dummy clock Haojian Zhuang
2012-02-21  9:04 ` [PATCH 6/7] rtc: sa1100: enable clk support Haojian Zhuang
2012-02-22 12:29   ` Arnd Bergmann
2012-02-22 13:16     ` Haojian Zhuang
2012-02-22 13:20     ` Russell King - ARM Linux
2012-02-22 13:47       ` Arnd Bergmann
2012-02-23 10:34   ` Russell King - ARM Linux
2012-02-23 10:40     ` Haojian Zhuang
2012-02-23 10:54       ` Russell King - ARM Linux
2012-02-21  9:04 ` [PATCH 7/7] ARM: mmp: enable rtc Haojian Zhuang
     [not found]   ` <1329815642.22876.YahooMailNeo@web162001.mail.bf1.yahoo.com>
2012-02-21  9:15     ` [HELP REQUIRED] : Andorid FIQ Debugger Porting issue on Kernel2.6.36 PINTU KUMAR
2012-02-21 15:37 ` [PATCH 0/7] share sa1100 rtc driver to arch-mmp Jean-Christophe PLAGNIOL-VILLARD
2012-02-21 15:54   ` Nicolas Ferre
2012-02-22 12:39 ` Arnd Bergmann
2012-02-22 13:22   ` Haojian Zhuang
2012-02-22 13:49     ` Arnd Bergmann
2012-02-22 15:37       ` Haojian Zhuang
2012-02-22 16:38         ` Robert Jarzmik
2012-02-23  0:51           ` Haojian Zhuang
2012-02-23  8:52             ` Robert Jarzmik
2012-02-23  9:45               ` Haojian Zhuang
2012-02-23 10:00                 ` Russell King - ARM Linux
2012-02-23 10:22                   ` Haojian Zhuang
2012-02-23 10:49                     ` Russell King - ARM Linux
2012-02-23 10:59                       ` Russell King - ARM Linux
2012-02-23 13:32                       ` Haojian Zhuang
2012-02-23 14:04                         ` Russell King - ARM Linux
2012-02-23  0:01 ` Russell King - ARM Linux

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.