Skip to contentSkip to conversation

: S3C RTC driver: add support for S3C64xx

PATCH New Maurus Cuelenaere 3 participants 4 messages Nov 10, 2009

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 : S3C RTC driver: add support for S3C64xx

Add support for the S3C64xx SoC to the generic S3C RTC driver.

---
 arch/arm/mach-s3c6400/include/mach/map.h  |    1 +
 arch/arm/plat-s3c/include/plat/regs-rtc.h |    4 ++
 arch/arm/plat-s3c24xx/devs.c              |   14 ++++--
 arch/arm/plat-s3c64xx/Makefile            |    1 +
 drivers/rtc/Kconfig                       |    2 +-
 drivers/rtc/rtc-s3c.c                     |   73 +++++++++++++++++++++++------
 6 files changed, 76 insertions(+), 19 deletions(-)
(quoted diff) +0 -0

b/arch/arm/mach-s3c6400/include/mach/map.h
index b34a5ed..ae7704c 100644

arch/arm/mach-s3c6400/include/mach/map.h +1 -0
@@ -42,6 +42,7 @@
 #define S3C64XX_PA_FB		(0x77100000)
 #define S3C64XX_PA_USB_HSOTG	(0x7C000000)
 #define S3C64XX_PA_WATCHDOG	(0x7E004000)
+#define S3C64XX_PA_RTC		(0x7E005000)
 #define S3C64XX_PA_ADC		(0x7E00B000)
 #define S3C64XX_PA_SYSCON	(0x7E00F000)
 #define S3C64XX_PA_AC97		(0x7F001000)
(quoted diff) +0 -0

b/arch/arm/plat-s3c/include/plat/regs-rtc.h
index d5837cf..65c190d 100644

arch/arm/plat-s3c/include/plat/regs-rtc.h +4 -0
@@ -20,6 +20,10 @@
 #define S3C2410_RTCCON_CLKSEL (1<<1)
 #define S3C2410_RTCCON_CNTSEL (1<<2)
 #define S3C2410_RTCCON_CLKRST (1<<3)
+#define S3C64XX_RTCCON_TICEN  (1<<8)
+
+#define S3C64XX_RTCCON_TICMSK (0xF<<7)
+#define S3C64XX_RTCCON_TICSHT (7)
 
 #define S3C2410_TICNT	      S3C2410_RTCREG(0x44)
 #define S3C2410_TICNT_ENABLE  (1<<7)
arch/arm/plat-s3c24xx/devs.c +10 -4
index f52a92c..7ec1acb 100644
@@ -32,6 +32,7 @@
 
 #include <plat/regs-serial.h>
 #include <plat/udc.h>
+#include <plat/rtc.h>
 
 #include <plat/devs.h>
 #include <plat/cpu.h>
@@ -291,11 +292,16 @@ static struct resource s3c_rtc_resource[] = {
 	}
 };
 
+static struct s3c_rtc_platdata s3c_rtc_pdata = {
+	.rtc_type	= 0,
+};
+
 struct platform_device s3c_device_rtc = {
-	.name		  = "s3c2410-rtc",
-	.id		  = -1,
-	.num_resources	  = ARRAY_SIZE(s3c_rtc_resource),
-	.resource	  = s3c_rtc_resource,
+	.name		  	= "s3c-rtc",
+	.id		  	= -1,
+	.num_resources	  	= ARRAY_SIZE(s3c_rtc_resource),
+	.resource	  	= s3c_rtc_resource,
+	.dev.platform_data	= &s3c_rtc_pdata,
 };
 
 EXPORT_SYMBOL(s3c_device_rtc);
arch/arm/plat-s3c64xx/Makefile +1 -0
index a8c5d17..25d9f6d 100644
@@ -14,6 +14,7 @@ obj-				:=
 
 obj-y				+= dev-uart.o
 obj-y				+= dev-adc.o
+obj-y				+= dev-rtc.o
 obj-y				+= cpu.o
 obj-y				+= irq.o
 obj-y				+= irq-eint.o
drivers/rtc/Kconfig +1 -1
index 3c20dae..1b7a0c7 100644
@@ -585,7 +585,7 @@ config RTC_DRV_OMAP
 
 config RTC_DRV_S3C
 	tristate "Samsung S3C series SoC RTC"
-	depends on ARCH_S3C2410
+	depends on ARCH_S3C2410 || ARCH_S3C64XX
 	help
 	  RTC (Realtime Clock) driver for the clock inbuilt into the
 	  Samsung S3C24XX series of SoCs. This can provide periodic
drivers/rtc/rtc-s3c.c +24 -6
index e0d7b99..03959b6 100644
@@ -27,6 +27,7 @@
 #include <asm/io.h>
 #include <asm/irq.h>
 #include <plat/regs-rtc.h>
+#include <plat/rtc.h>
 
 /* I have yet to find an S3C implementation with more than one
  * of these rtc blocks in */
@@ -75,16 +76,28 @@ static void s3c_rtc_setaie(int to)
 static int s3c_rtc_setpie(struct device *dev, int enabled)
 {
 	unsigned int tmp;
+	struct s3c_rtc_platdata* pdata = dev->platform_data;
 
 	pr_debug("%s: pie=%d\n", __func__, enabled);
 
 	spin_lock_irq(&s3c_rtc_pie_lock);
-	tmp = readb(s3c_rtc_base + S3C2410_TICNT) & ~S3C2410_TICNT_ENABLE;
 
-	if (enabled)
-		tmp |= S3C2410_TICNT_ENABLE;
+	if (pdata->rtc_type == 1) {
+		tmp = readb(s3c_rtc_base + S3C2410_RTCCON) & ~S3C64XX_RTCCON_TICEN;
+
+		if (enabled)
+			tmp |= S3C64XX_RTCCON_TICEN;
+
+		writeb(tmp, s3c_rtc_base + S3C2410_RTCCON);
+	} else {
+		tmp = readb(s3c_rtc_base + S3C2410_TICNT) & ~S3C2410_TICNT_ENABLE;
+
+		if (enabled)
+			tmp |= S3C2410_TICNT_ENABLE;
+
+		writeb(tmp, s3c_rtc_base + S3C2410_TICNT);
+	}
 
-	writeb(tmp, s3c_rtc_base + S3C2410_TICNT);
 	spin_unlock_irq(&s3c_rtc_pie_lock);
 
 	return 0;
@@ -93,14 +106,19 @@ static int s3c_rtc_setpie(struct device *dev, int enabled)
 static int s3c_rtc_setfreq(struct device *dev, int freq)
 {
 	unsigned int tmp;
+	struct s3c_rtc_platdata* pdata = dev->platform_data;
 
 	if (!is_power_of_2(freq))
 		return -EINVAL;
 
 	spin_lock_irq(&s3c_rtc_pie_lock);
 
-	tmp = readb(s3c_rtc_base + S3C2410_TICNT) & S3C2410_TICNT_ENABLE;
-	tmp |= (128 / freq)-1;
+	if (pdata->rtc_type == 1) {
+		tmp = (32768 / freq)-1;
+	} else {
+		tmp = readb(s3c_rtc_base + S3C2410_TICNT) & S3C2410_TICNT_ENABLE;
+		tmp |= (128 / freq)-1;
+	}
 
 	writeb(tmp, s3c_rtc_base + S3C2410_TICNT);
 	spin_unlock_irq(&s3c_rtc_pie_lock);
@@ -282,10 +300,15 @@ static int s3c_rtc_setalarm(struct device *dev,

struct rtc_wkalrm *alrm)

static int s3c_rtc_proc(struct device *dev, struct seq_file *seq) {
- unsigned int ticnt = readb(s3c_rtc_base + S3C2410_TICNT);
+ unsigned int ticnt;
+ struct s3c_rtc_platdata* pdata = dev->platform_data;

- seq_printf(seq, "periodic_IRQ\t: %s\n",
- (ticnt & S3C2410_TICNT_ENABLE) ? "yes" : "no" );
+ if (pdata->rtc_type == 1)
+ ticnt = readb(s3c_rtc_base + S3C2410_RTCCON) & S3C64XX_RTCCON_TICEN;
+ else
+ ticnt = readb(s3c_rtc_base + S3C2410_TICNT) & S3C2410_TICNT_ENABLE;
+
+ seq_printf(seq, "periodic_IRQ\t: %s\n", ticnt ? "yes" : "no" );
return 0;
}

@@ -346,16 +369,21 @@ static void s3c_rtc_enable(struct platform_device *pdev, int en)
{
void __iomem *base = s3c_rtc_base; unsigned int tmp;
+ struct s3c_rtc_platdata* pdata = pdev->dev.platform_data;

if (s3c_rtc_base == NULL)
return;

if (!en) {
tmp = readb(base + S3C2410_RTCCON);
+ if (pdata->rtc_type == 1)
+ tmp &= ~S3C64XX_RTCCON_TICEN;
writeb(tmp & ~S3C2410_RTCCON_RTCEN, base + S3C2410_RTCCON);

- tmp = readb(base + S3C2410_TICNT);
- writeb(tmp & ~S3C2410_TICNT_ENABLE, base + S3C2410_TICNT);
+ if (pdata->rtc_type == 0) {
+ tmp = readb(base + S3C2410_TICNT);
+ writeb(tmp & ~S3C2410_TICNT_ENABLE, base + S3C2410_TICNT);
+ }
} else {
/* re-enable the device, and check it is ok */

@@ -403,6 +431,7 @@ static int __devinit s3c_rtc_probe(struct platform_device *pdev)
{
struct rtc_device *rtc;
struct resource *res;
+ struct s3c_rtc_platdata* pdata = pdev->dev.platform_data;
int ret;

pr_debug("%s: probe=%p\n", __func__, pdev);
@@ -471,7 +500,10 @@ static int __devinit s3c_rtc_probe(struct platform_device *pdev)
goto err_nortc;
}

- rtc->max_user_freq = 128;
+ if (pdata->rtc_type == 1)
+ rtc->max_user_freq = 32768;
+ else
+ rtc->max_user_freq = 128;

platform_set_drvdata(pdev, rtc);
return 0;
@@ -491,20 +523,33 @@ static int __devinit s3c_rtc_probe(struct platform_device *pdev)

/* RTC Power management control */

-static int ticnt_save;
+static int ticnt_save, ticnt_en_save;

static int s3c_rtc_suspend(struct platform_device *pdev, pm_message_t state) {
+ struct s3c_rtc_platdata* pdata = pdev->dev.platform_data;
+
/* save TICNT for anyone using periodic interrupts */ ticnt_save = readb(s3c_rtc_base + S3C2410_TICNT);
+ if (pdata->rtc_type == 1) {
+ ticnt_en_save = readb(s3c_rtc_base + S3C2410_RTCCON)
+ & S3C64XX_RTCCON_TICEN;
+ }
s3c_rtc_enable(pdev, 0);
return 0;
}

static int s3c_rtc_resume(struct platform_device *pdev)
{
+ struct s3c_rtc_platdata* pdata = pdev->dev.platform_data;
+ unsigned int tmp;
+
s3c_rtc_enable(pdev, 1);
writeb(ticnt_save, s3c_rtc_base + S3C2410_TICNT);
+ if (pdata->rtc_type == 1 && ticnt_en_save) {
+ tmp = readb(s3c_rtc_base + S3C2410_RTCCON);
+ writeb(tmp | ticnt_en_save, s3c_rtc_base + S3C2410_RTCCON);
+ }
return 0;
}
#else
@@ -518,7 +563,7 @@ static struct platform_driver s3c2410_rtc_driver = {
.suspend = s3c_rtc_suspend,
.resume = s3c_rtc_resume,
.driver = {
- .name = "s3c2410-rtc",
+ .name = "s3c-rtc",
.owner = THIS_MODULE,
},
};

Signature · 1 line
1.6.3.3
#1 lore raw

PATCH 1/1 : S3C RTC driver: add support for S3C64xx

Quoted 113 lines · Maurus Cuelenaere

Add support for the S3C64xx SoC to the generic S3C RTC driver.

---
 arch/arm/mach-s3c6400/include/mach/map.h  |    1 +
 arch/arm/plat-s3c/include/plat/regs-rtc.h |    4 ++
 arch/arm/plat-s3c24xx/devs.c              |   14 ++++--
 arch/arm/plat-s3c64xx/Makefile            |    1 +
 drivers/rtc/Kconfig                       |    2 +-
 drivers/rtc/rtc-s3c.c                     |   73 +++++++++++++++++++++++------
 6 files changed, 76 insertions(+), 19 deletions(-)
arch/arm/mach-s3c6400/include/mach/map.h +1 -0
index b34a5ed..ae7704c 100644
@@ -42,6 +42,7 @@
 #define S3C64XX_PA_FB		(0x77100000)
 #define S3C64XX_PA_USB_HSOTG	(0x7C000000)
 #define S3C64XX_PA_WATCHDOG	(0x7E004000)
+#define S3C64XX_PA_RTC		(0x7E005000)
 #define S3C64XX_PA_ADC		(0x7E00B000)
 #define S3C64XX_PA_SYSCON	(0x7E00F000)
 #define S3C64XX_PA_AC97		(0x7F001000)
arch/arm/plat-s3c/include/plat/regs-rtc.h +4 -0
index d5837cf..65c190d 100644
@@ -20,6 +20,10 @@
 #define S3C2410_RTCCON_CLKSEL (1<<1)
 #define S3C2410_RTCCON_CNTSEL (1<<2)
 #define S3C2410_RTCCON_CLKRST (1<<3)
+#define S3C64XX_RTCCON_TICEN  (1<<8)
+
+#define S3C64XX_RTCCON_TICMSK (0xF<<7)
+#define S3C64XX_RTCCON_TICSHT (7)
 
 #define S3C2410_TICNT	      S3C2410_RTCREG(0x44)
 #define S3C2410_TICNT_ENABLE  (1<<7)
arch/arm/plat-s3c24xx/devs.c +10 -4
index f52a92c..7ec1acb 100644
@@ -32,6 +32,7 @@
 
 #include <plat/regs-serial.h>
 #include <plat/udc.h>
+#include <plat/rtc.h>
 
 #include <plat/devs.h>
 #include <plat/cpu.h>
@@ -291,11 +292,16 @@ static struct resource s3c_rtc_resource[] = {
 	}
 };
 
+static struct s3c_rtc_platdata s3c_rtc_pdata = {
+	.rtc_type	= 0,
+};
+
 struct platform_device s3c_device_rtc = {
-	.name		  = "s3c2410-rtc",
-	.id		  = -1,
-	.num_resources	  = ARRAY_SIZE(s3c_rtc_resource),
-	.resource	  = s3c_rtc_resource,
+	.name		  	= "s3c-rtc",
+	.id		  	= -1,
+	.num_resources	  	= ARRAY_SIZE(s3c_rtc_resource),
+	.resource	  	= s3c_rtc_resource,
+	.dev.platform_data	= &s3c_rtc_pdata,
 };
 
 EXPORT_SYMBOL(s3c_device_rtc);
arch/arm/plat-s3c64xx/Makefile +1 -0
index a8c5d17..25d9f6d 100644
@@ -14,6 +14,7 @@ obj-				:=
 
 obj-y				+= dev-uart.o
 obj-y				+= dev-adc.o
+obj-y				+= dev-rtc.o
 obj-y				+= cpu.o
 obj-y				+= irq.o
 obj-y				+= irq-eint.o
drivers/rtc/Kconfig +1 -1
index 3c20dae..1b7a0c7 100644
@@ -585,7 +585,7 @@ config RTC_DRV_OMAP
 
 config RTC_DRV_S3C
 	tristate "Samsung S3C series SoC RTC"
-	depends on ARCH_S3C2410
+	depends on ARCH_S3C2410 || ARCH_S3C64XX
 	help
 	  RTC (Realtime Clock) driver for the clock inbuilt into the
 	  Samsung S3C24XX series of SoCs. This can provide periodic
drivers/rtc/rtc-s3c.c +1 -0
index e0d7b99..03959b6 100644
@@ -27,6 +27,7 @@
 #include <asm/io.h>
 #include <asm/irq.h>
 #include <plat/regs-rtc.h>
+#include <plat/rtc.h>
 
 /* I have yet to find an S3C implementation with more than one
  * of these rtc blocks in */

drivers/rtc/rtc-s3c.c static void s3c_rtc_setaie(int to) · line 79

Quoted 4 lines
drivers/rtc/rtc-s3c.c +1 -0
@@ -75,16 +76,28 @@ static void s3c_rtc_setaie(int to)
 static int s3c_rtc_setpie(struct device *dev, int enabled)
 {
 	unsigned int tmp;
+	struct s3c_rtc_platdata* pdata = dev->platform_data;

style wise, I prefer the larger items ot be first, so:

      struct s3c_rtc_platdata* pdata = dev->platform_data;
      unsigned int tmp;
Quoted 34 lines
drivers/rtc/rtc-s3c.c +16 -4
 	pr_debug("%s: pie=%d\n", __func__, enabled);
 
 	spin_lock_irq(&s3c_rtc_pie_lock);
-	tmp = readb(s3c_rtc_base + S3C2410_TICNT) & ~S3C2410_TICNT_ENABLE;
 
-	if (enabled)
-		tmp |= S3C2410_TICNT_ENABLE;
+	if (pdata->rtc_type == 1) {
+		tmp = readb(s3c_rtc_base + S3C2410_RTCCON) & ~S3C64XX_RTCCON_TICEN;
+
+		if (enabled)
+			tmp |= S3C64XX_RTCCON_TICEN;
+
+		writeb(tmp, s3c_rtc_base + S3C2410_RTCCON);
+	} else {
+		tmp = readb(s3c_rtc_base + S3C2410_TICNT) & ~S3C2410_TICNT_ENABLE;
+
+		if (enabled)
+			tmp |= S3C2410_TICNT_ENABLE;
+
+		writeb(tmp, s3c_rtc_base + S3C2410_TICNT);
+	}
 
-	writeb(tmp, s3c_rtc_base + S3C2410_TICNT);
 	spin_unlock_irq(&s3c_rtc_pie_lock);
 
 	return 0;
@@ -93,14 +106,19 @@ static int s3c_rtc_setpie(struct device *dev, int enabled)
 static int s3c_rtc_setfreq(struct device *dev, int freq)
 {
 	unsigned int tmp;
+	struct s3c_rtc_platdata* pdata = dev->platform_data;
 
 	if (!is_power_of_2(freq))

drivers/rtc/rtc-s3c.c static int s3c_rtc_setpie(struct device *dev, int enabled) · line 119

Quoted 10 lines
drivers/rtc/rtc-s3c.c +4 -2
 		return -EINVAL;
 
 	spin_lock_irq(&s3c_rtc_pie_lock);
 
-	tmp = readb(s3c_rtc_base + S3C2410_TICNT) & S3C2410_TICNT_ENABLE;
-	tmp |= (128 / freq)-1;
+	if (pdata->rtc_type == 1) {
+		tmp = (32768 / freq)-1;
+	} else {
+		tmp = readb(s3c_rtc_base + S3C2410_TICNT) & S3C2410_TICNT_ENABLE;

this is now wrapping, please split the & to an &= on the next line.

Quoted 26 lines
drivers/rtc/rtc-s3c.c +10 -3
+		tmp |= (128 / freq)-1;
+	}
 
 	writeb(tmp, s3c_rtc_base + S3C2410_TICNT);
 	spin_unlock_irq(&s3c_rtc_pie_lock);
@@ -282,10 +300,15 @@ static int s3c_rtc_setalarm(struct device *dev,
 struct rtc_wkalrm *alrm)
 
 static int s3c_rtc_proc(struct device *dev, struct seq_file *seq)
 {
-	unsigned int ticnt = readb(s3c_rtc_base + S3C2410_TICNT);
+	unsigned int ticnt;
+	struct s3c_rtc_platdata* pdata = dev->platform_data;
 
-	seq_printf(seq, "periodic_IRQ\t: %s\n",
-		     (ticnt & S3C2410_TICNT_ENABLE) ? "yes" : "no" );
+	if (pdata->rtc_type == 1)
+		ticnt = readb(s3c_rtc_base + S3C2410_RTCCON) & S3C64XX_RTCCON_TICEN;
+	else
+		ticnt = readb(s3c_rtc_base + S3C2410_TICNT) & S3C2410_TICNT_ENABLE;
+
+	seq_printf(seq, "periodic_IRQ\t: %s\n", ticnt  ? "yes" : "no" );
 	return 0;
 }

drivers/rtc/rtc-s3c.c static void s3c_rtc_enable(struct · line 373

Quoted 5 lines
drivers/rtc/rtc-s3c.c +1 -0
@@ -346,16 +369,21 @@ static void s3c_rtc_enable(struct
 platform_device *pdev, int en)
 {
 	void __iomem *base = s3c_rtc_base;
 	unsigned int tmp;
+	struct s3c_rtc_platdata* pdata = pdev->dev.platform_data;

see style note above.

Quoted 19 lines
drivers/rtc/rtc-s3c.c +6 -2
 	if (s3c_rtc_base == NULL)
 		return;
 
 	if (!en) {
 		tmp = readb(base + S3C2410_RTCCON);
+		if (pdata->rtc_type == 1)
+			tmp &= ~S3C64XX_RTCCON_TICEN;
 		writeb(tmp & ~S3C2410_RTCCON_RTCEN, base + S3C2410_RTCCON);
 
-		tmp = readb(base + S3C2410_TICNT);
-		writeb(tmp & ~S3C2410_TICNT_ENABLE, base + S3C2410_TICNT);
+		if (pdata->rtc_type == 0) {
+			tmp = readb(base + S3C2410_TICNT);
+			writeb(tmp & ~S3C2410_TICNT_ENABLE, base + S3C2410_TICNT);
+		}
 	} else {
 		/* re-enable the device, and check it is ok */
 

drivers/rtc/rtc-s3c.c static int __devinit s3c_rtc_probe(struct · line 436

Quoted 6 lines
drivers/rtc/rtc-s3c.c +1 -0
@@ -403,6 +431,7 @@ static int __devinit s3c_rtc_probe(struct
 platform_device *pdev)
 {
 	struct rtc_device *rtc;
 	struct resource *res;
+	struct s3c_rtc_platdata* pdata = pdev->dev.platform_data;
 	int ret;

and see the style note again.

Quoted 51 lines
drivers/rtc/rtc-s3c.c +4 -1
 	pr_debug("%s: probe=%p\n", __func__, pdev);
@@ -471,7 +500,10 @@ static int __devinit s3c_rtc_probe(struct
 platform_device *pdev)
 		goto err_nortc;
 	}
 
-	rtc->max_user_freq = 128;
+	if (pdata->rtc_type == 1)
+		rtc->max_user_freq = 32768;
+	else
+		rtc->max_user_freq = 128;
 
 	platform_set_drvdata(pdev, rtc);
drivers/rtc/rtc-s3c.c +14 -1
 	return 0;
@@ -491,20 +523,33 @@ static int __devinit s3c_rtc_probe(struct
 platform_device *pdev)
 
 /* RTC Power management control */
 
-static int ticnt_save;
+static int ticnt_save, ticnt_en_save;
 
 static int s3c_rtc_suspend(struct platform_device *pdev, pm_message_t state)
 {
+	struct s3c_rtc_platdata* pdata = pdev->dev.platform_data;
+
 	/* save TICNT for anyone using periodic interrupts */
 	ticnt_save = readb(s3c_rtc_base + S3C2410_TICNT);
+	if (pdata->rtc_type == 1) {
+		ticnt_en_save = readb(s3c_rtc_base + S3C2410_RTCCON)
+							& S3C64XX_RTCCON_TICEN;
+	}
 	s3c_rtc_enable(pdev, 0);
 	return 0;
 }
 
 static int s3c_rtc_resume(struct platform_device *pdev)
 {
+	struct s3c_rtc_platdata* pdata = pdev->dev.platform_data;
+	unsigned int tmp;
+
 	s3c_rtc_enable(pdev, 1);
 	writeb(ticnt_save, s3c_rtc_base + S3C2410_TICNT);
+	if (pdata->rtc_type == 1 && ticnt_en_save) {
+		tmp = readb(s3c_rtc_base + S3C2410_RTCCON);
+		writeb(tmp | ticnt_en_save, s3c_rtc_base + S3C2410_RTCCON);
+	}
 	return 0;
 }

#else

drivers/rtc/rtc-s3c.c static struct platform_driver s3c2410_rtc_driver = { · line 567

Quoted 6 lines
drivers/rtc/rtc-s3c.c +1 -1
@@ -518,7 +563,7 @@ static struct platform_driver s3c2410_rtc_driver = {
 	.suspend	= s3c_rtc_suspend,
 	.resume		= s3c_rtc_resume,
 	.driver		= {
-		.name	= "s3c2410-rtc",
+		.name	= "s3c-rtc",
 		.owner	= THIS_MODULE,

Please add a new device name and leave the s3c2410-rtc alone. s3c-rtc-v2 would be an acceptable name for the new rtc device.

Signature · 4 lines
Ben

Q:      What's a light-year?
A:      One-third less calories than a regular year.
#2 lore raw

PATCH 1/1 : S3C RTC driver: add support for S3C64xx

In reply to Maurus Cuelenaere
Quoted 55 lines · Maurus Cuelenaere

Add support for the S3C64xx SoC to the generic S3C RTC driver.

---

?arch/arm/mach-s3c6400/include/mach/map.h ?| ? ?1 +
?arch/arm/plat-s3c/include/plat/regs-rtc.h | ? ?4 ++
?arch/arm/plat-s3c24xx/devs.c ? ? ? ? ? ? ?| ? 14 ++++--
?arch/arm/plat-s3c64xx/Makefile ? ? ? ? ? ?| ? ?1 +
?drivers/rtc/Kconfig ? ? ? ? ? ? ? ? ? ? ? | ? ?2 +-
?drivers/rtc/rtc-s3c.c ? ? ? ? ? ? ? ? ? ? | ? 73 +++++++++++++++++++++++------

?6 files changed, 76 insertions(+), 19 deletions(-)

arch/arm/mach-s3c6400/include/mach/map.h +1 -0
index b34a5ed..ae7704c 100644
@@ -42,6 +42,7 @@
 ?#define S3C64XX_PA_FB ? ? ? ? ?(0x77100000)
 ?#define S3C64XX_PA_USB_HSOTG ? (0x7C000000)
 ?#define S3C64XX_PA_WATCHDOG ? ?(0x7E004000)
+#define S3C64XX_PA_RTC ? ? ? ? (0x7E005000)
 ?#define S3C64XX_PA_ADC ? ? ? ? (0x7E00B000)
 ?#define S3C64XX_PA_SYSCON ? ? ?(0x7E00F000)
 ?#define S3C64XX_PA_AC97 ? ? ? ? ? ? ? ?(0x7F001000)
arch/arm/plat-s3c/include/plat/regs-rtc.h +4 -0
index d5837cf..65c190d 100644
@@ -20,6 +20,10 @@
 ?#define S3C2410_RTCCON_CLKSEL (1<<1)
 ?#define S3C2410_RTCCON_CNTSEL (1<<2)
 ?#define S3C2410_RTCCON_CLKRST (1<<3)
+#define S3C64XX_RTCCON_TICEN ?(1<<8)
+
+#define S3C64XX_RTCCON_TICMSK (0xF<<7)
+#define S3C64XX_RTCCON_TICSHT (7)
 
 ?#define S3C2410_TICNT ? ? ? ?S3C2410_RTCREG(0x44)
 ?#define S3C2410_TICNT_ENABLE ?(1<<7)
arch/arm/plat-s3c24xx/devs.c +0 -0
index f52a92c..7ec1acb 100644
@@ -32,6 +32,7 @@
 

?#include <plat/regs-serial.h>
?#include <plat/udc.h>
+#include <plat/rtc.h>

?#include <plat/devs.h>
?#include <plat/cpu.h>

arch/arm/plat-s3c24xx/devs.c static struct resource s3c_rtc_resource[] = { · line 297

Quoted 6 lines
arch/arm/plat-s3c24xx/devs.c +3 -0
@@ -291,11 +292,16 @@ static struct resource s3c_rtc_resource[] = {
 ? ? ? ?}
 ?};
 
+static struct s3c_rtc_platdata s3c_rtc_pdata = {
+ ? ? ? .rtc_type ? ? ? = 0,
+};

1) where is this structure defined?
Perhaps u forgot to share the plat/rtc.h
2) rtc_type isn't very neat. Runtime CPU detection is better. Even better, if you manage to segregate the differences between
two versions and pass them via platform data somehow. For, example, driver could assume resolution as pdata->resolution instead of 128 or 32768 or whatever for future SoCs.

Quoted 208 lines
arch/arm/plat-s3c24xx/devs.c +5 -4
 ?struct platform_device s3c_device_rtc = {
- ? ? ? .name ? ? ? ? ? ? = "s3c2410-rtc",
- ? ? ? .id ? ? ? ? ? ? ? = -1,
- ? ? ? .num_resources ? ?= ARRAY_SIZE(s3c_rtc_resource),
- ? ? ? .resource ? ? ? ? = s3c_rtc_resource,
+ ? ? ? .name ? ? ? ? ? ? ? ? ? = "s3c-rtc",
+ ? ? ? .id ? ? ? ? ? ? ? ? ? ? = -1,
+ ? ? ? .num_resources ? ? ? ? ?= ARRAY_SIZE(s3c_rtc_resource),
+ ? ? ? .resource ? ? ? ? ? ? ? = s3c_rtc_resource,
+ ? ? ? .dev.platform_data ? ? ?= &s3c_rtc_pdata,
 ?};
 ?EXPORT_SYMBOL(s3c_device_rtc);
arch/arm/plat-s3c64xx/Makefile +0 -0
index a8c5d17..25d9f6d 100644
@@ -14,6 +14,7 @@ obj- ? ? ? ? ? ? ? ? ? ? ? ? ?:=
 

?obj-y ? ? ? ? ? ? ? ? ? ? ? ? ?+= dev-uart.o
?obj-y ? ? ? ? ? ? ? ? ? ? ? ? ?+= dev-adc.o
+obj-y ? ? ? ? ? ? ? ? ? ? ? ? ?+= dev-rtc.o
?obj-y ? ? ? ? ? ? ? ? ? ? ? ? ?+= cpu.o
?obj-y ? ? ? ? ? ? ? ? ? ? ? ? ?+= irq.o
?obj-y ? ? ? ? ? ? ? ? ? ? ? ? ?+= irq-eint.o

drivers/rtc/Kconfig +0 -0
index 3c20dae..1b7a0c7 100644
@@ -585,7 +585,7 @@ config RTC_DRV_OMAP
 

?config RTC_DRV_S3C
? ? ? ?tristate "Samsung S3C series SoC RTC"
- ? ? ? depends on ARCH_S3C2410
+ ? ? ? depends on ARCH_S3C2410 || ARCH_S3C64XX
? ? ? ?help
? ? ? ? ?RTC (Realtime Clock) driver for the clock inbuilt into the ? ? ? ? ?Samsung S3C24XX series of SoCs. This can provide periodic

drivers/rtc/rtc-s3c.c +0 -0
index e0d7b99..03959b6 100644
@@ -27,6 +27,7 @@

?#include <asm/io.h>
?#include <asm/irq.h>
?#include <plat/regs-rtc.h>
+#include <plat/rtc.h>

?/* I have yet to find an S3C implementation with more than one ?* of these rtc blocks in */

drivers/rtc/rtc-s3c.c +38 -11
@@ -75,16 +76,28 @@ static void s3c_rtc_setaie(int to)
 ?static int s3c_rtc_setpie(struct device *dev, int enabled)
 ?{
 ? ? ? ?unsigned int tmp;
+ ? ? ? struct s3c_rtc_platdata* pdata = dev->platform_data;
 
 ? ? ? ?pr_debug("%s: pie=%d\n", __func__, enabled);
 
 ? ? ? ?spin_lock_irq(&s3c_rtc_pie_lock);
- ? ? ? tmp = readb(s3c_rtc_base + S3C2410_TICNT) & ~S3C2410_TICNT_ENABLE;
 
- ? ? ? if (enabled)
- ? ? ? ? ? ? ? tmp |= S3C2410_TICNT_ENABLE;
+ ? ? ? if (pdata->rtc_type == 1) {
+ ? ? ? ? ? ? ? tmp = readb(s3c_rtc_base + S3C2410_RTCCON) & ~S3C64XX_RTCCON_TICEN;
+
+ ? ? ? ? ? ? ? if (enabled)
+ ? ? ? ? ? ? ? ? ? ? ? tmp |= S3C64XX_RTCCON_TICEN;
+
+ ? ? ? ? ? ? ? writeb(tmp, s3c_rtc_base + S3C2410_RTCCON);
+ ? ? ? } else {
+ ? ? ? ? ? ? ? tmp = readb(s3c_rtc_base + S3C2410_TICNT) & ~S3C2410_TICNT_ENABLE;
+
+ ? ? ? ? ? ? ? if (enabled)
+ ? ? ? ? ? ? ? ? ? ? ? tmp |= S3C2410_TICNT_ENABLE;
+
+ ? ? ? ? ? ? ? writeb(tmp, s3c_rtc_base + S3C2410_TICNT);
+ ? ? ? }
 
- ? ? ? writeb(tmp, s3c_rtc_base + S3C2410_TICNT);
 ? ? ? ?spin_unlock_irq(&s3c_rtc_pie_lock);
 
 ? ? ? ?return 0;
@@ -93,14 +106,19 @@ static int s3c_rtc_setpie(struct device *dev, int enabled)
 ?static int s3c_rtc_setfreq(struct device *dev, int freq)
 ?{
 ? ? ? ?unsigned int tmp;
+ ? ? ? struct s3c_rtc_platdata* pdata = dev->platform_data;
 
 ? ? ? ?if (!is_power_of_2(freq))
 ? ? ? ? ? ? ? ?return -EINVAL;
 
 ? ? ? ?spin_lock_irq(&s3c_rtc_pie_lock);
 
- ? ? ? tmp = readb(s3c_rtc_base + S3C2410_TICNT) & S3C2410_TICNT_ENABLE;
- ? ? ? tmp |= (128 / freq)-1;
+ ? ? ? if (pdata->rtc_type == 1) {
+ ? ? ? ? ? ? ? tmp = (32768 / freq)-1;
+ ? ? ? } else {
+ ? ? ? ? ? ? ? tmp = readb(s3c_rtc_base + S3C2410_TICNT) & S3C2410_TICNT_ENABLE;
+ ? ? ? ? ? ? ? tmp |= (128 / freq)-1;
+ ? ? ? }
 
 ? ? ? ?writeb(tmp, s3c_rtc_base + S3C2410_TICNT);
 ? ? ? ?spin_unlock_irq(&s3c_rtc_pie_lock);
@@ -282,10 +300,15 @@ static int s3c_rtc_setalarm(struct device *dev,
 struct rtc_wkalrm *alrm)
 
 ?static int s3c_rtc_proc(struct device *dev, struct seq_file *seq)
 ?{
- ? ? ? unsigned int ticnt = readb(s3c_rtc_base + S3C2410_TICNT);
+ ? ? ? unsigned int ticnt;
+ ? ? ? struct s3c_rtc_platdata* pdata = dev->platform_data;
 
- ? ? ? seq_printf(seq, "periodic_IRQ\t: %s\n",
- ? ? ? ? ? ? ? ? ? ?(ticnt & S3C2410_TICNT_ENABLE) ? "yes" : "no" );
+ ? ? ? if (pdata->rtc_type == 1)
+ ? ? ? ? ? ? ? ticnt = readb(s3c_rtc_base + S3C2410_RTCCON) & S3C64XX_RTCCON_TICEN;
+ ? ? ? else
+ ? ? ? ? ? ? ? ticnt = readb(s3c_rtc_base + S3C2410_TICNT) & S3C2410_TICNT_ENABLE;
+
+ ? ? ? seq_printf(seq, "periodic_IRQ\t: %s\n", ticnt ?? "yes" : "no" );
 ? ? ? ?return 0;
 ?}
@@ -346,16 +369,21 @@ static void s3c_rtc_enable(struct
 platform_device *pdev, int en)
 ?{
 ? ? ? ?void __iomem *base = s3c_rtc_base;
 ? ? ? ?unsigned int tmp;
+ ? ? ? struct s3c_rtc_platdata* pdata = pdev->dev.platform_data;
 
 ? ? ? ?if (s3c_rtc_base == NULL)
 ? ? ? ? ? ? ? ?return;
 
 ? ? ? ?if (!en) {
 ? ? ? ? ? ? ? ?tmp = readb(base + S3C2410_RTCCON);
+ ? ? ? ? ? ? ? if (pdata->rtc_type == 1)
+ ? ? ? ? ? ? ? ? ? ? ? tmp &= ~S3C64XX_RTCCON_TICEN;
 ? ? ? ? ? ? ? ?writeb(tmp & ~S3C2410_RTCCON_RTCEN, base + S3C2410_RTCCON);
 
- ? ? ? ? ? ? ? tmp = readb(base + S3C2410_TICNT);
- ? ? ? ? ? ? ? writeb(tmp & ~S3C2410_TICNT_ENABLE, base + S3C2410_TICNT);
+ ? ? ? ? ? ? ? if (pdata->rtc_type == 0) {
+ ? ? ? ? ? ? ? ? ? ? ? tmp = readb(base + S3C2410_TICNT);
+ ? ? ? ? ? ? ? ? ? ? ? writeb(tmp & ~S3C2410_TICNT_ENABLE, base + S3C2410_TICNT);
+ ? ? ? ? ? ? ? }
 ? ? ? ?} else {

? ? ? ? ? ? ? ?/* re-enable the device, and check it is ok */

drivers/rtc/rtc-s3c.c +1 -0
@@ -403,6 +431,7 @@ static int __devinit s3c_rtc_probe(struct
 platform_device *pdev)
 ?{
 ? ? ? ?struct rtc_device *rtc;
 ? ? ? ?struct resource *res;
+ ? ? ? struct s3c_rtc_platdata* pdata = pdev->dev.platform_data;
 ? ? ? ?int ret;
 

? ? ? ?pr_debug("%s: probe=%p\n", __func__, pdev);

drivers/rtc/rtc-s3c.c +4 -1
@@ -471,7 +500,10 @@ static int __devinit s3c_rtc_probe(struct
 platform_device *pdev)
 ? ? ? ? ? ? ? ?goto err_nortc;
 ? ? ? ?}
 
- ? ? ? rtc->max_user_freq = 128;
+ ? ? ? if (pdata->rtc_type == 1)
+ ? ? ? ? ? ? ? rtc->max_user_freq = 32768;
+ ? ? ? else
+ ? ? ? ? ? ? ? rtc->max_user_freq = 128;
 
 ? ? ? ?platform_set_drvdata(pdev, rtc);

? ? ? ?return 0;

drivers/rtc/rtc-s3c.c +0 -0
@@ -491,20 +523,33 @@ static int __devinit s3c_rtc_probe(struct
 platform_device *pdev)
 

?/* RTC Power management control */

drivers/rtc/rtc-s3c.c +1 -1
-static int ticnt_save;
+static int ticnt_save, ticnt_en_save;

?static int s3c_rtc_suspend(struct platform_device *pdev, pm_message_t state) ?{
+ ? ? ? struct s3c_rtc_platdata* pdata = pdev->dev.platform_data; +
? ? ? ?/* save TICNT for anyone using periodic interrupts */
? ? ? ?ticnt_save = readb(s3c_rtc_base + S3C2410_TICNT);
+ ? ? ? if (pdata->rtc_type == 1) {
+ ? ? ? ? ? ? ? ticnt_en_save = readb(s3c_rtc_base + S3C2410_RTCCON)
+ ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? & S3C64XX_RTCCON_TICEN;
+ ? ? ? }
? ? ? ?s3c_rtc_enable(pdev, 0);
? ? ? ?return 0;
?}

?static int s3c_rtc_resume(struct platform_device *pdev)
?{
+ ? ? ? struct s3c_rtc_platdata* pdata = pdev->dev.platform_data;
+ ? ? ? unsigned int tmp;
+
? ? ? ?s3c_rtc_enable(pdev, 1);
? ? ? ?writeb(ticnt_save, s3c_rtc_base + S3C2410_TICNT);
+ ? ? ? if (pdata->rtc_type == 1 && ticnt_en_save) {
+ ? ? ? ? ? ? ? tmp = readb(s3c_rtc_base + S3C2410_RTCCON);
+ ? ? ? ? ? ? ? writeb(tmp | ticnt_en_save, s3c_rtc_base + S3C2410_RTCCON);
+ ? ? ? }
? ? ? ?return 0;
?}
?#else

drivers/rtc/rtc-s3c.c static struct platform_driver s3c2410_rtc_driver = { · line 569

Quoted 8 lines
drivers/rtc/rtc-s3c.c +1 -1
@@ -518,7 +563,7 @@ static struct platform_driver s3c2410_rtc_driver = {
 ? ? ? ?.suspend ? ? ? ?= s3c_rtc_suspend,
 ? ? ? ?.resume ? ? ? ? = s3c_rtc_resume,
 ? ? ? ?.driver ? ? ? ? = {
- ? ? ? ? ? ? ? .name ? = "s3c2410-rtc",
+ ? ? ? ? ? ? ? .name ? = "s3c-rtc",
 ? ? ? ? ? ? ? ?.owner ?= THIS_MODULE,
 ? ? ? ?},
 ?};

why not use platform_device_id ?

#3 lore raw

PATCH 1/1 : S3C RTC driver: add support for S3C64xx

Op 10-11-09 14:53, jassi brar schreef:

Quoted 12 lines

arch/arm/plat-s3c24xx/devs.c static struct resource s3c_rtc_resource[] = { · line 297

Quoted 6 lines · Maurus Cuelenaere

<snip>

arch/arm/plat-s3c24xx/devs.c +3 -0
+static struct s3c_rtc_platdata s3c_rtc_pdata = {
+       .rtc_type       = 0,
+};

1) where is this structure defined?
Perhaps u forgot to share the plat/rtc.h

Hmm seems I did forgot to include plat/rtc.h ..

Quoted 6 lines

2) rtc_type isn't very neat. Runtime CPU detection is better. Even better, if you manage to segregate the differences between
two versions and pass them via platform data somehow. For, example, driver could assume resolution as pdata->resolution instead of 128 or 32768 or whatever for future SoCs.

pdata->resolution sounds like a good idea.

Quoted 5 lines
Quoted 5 lines

<snip>
#else

(quoted diff) +0 -0
@@ -518,7 +563,7 @@ static struct platform_driver s3c2410_rtc_driver = {
        .suspend        = s3c_rtc_suspend,
        .resume         = s3c_rtc_resume,
Quoted 9 lines

arch/arm/plat-s3c24xx/devs.c static struct resource s3c_rtc_resource[] = { · line 305

Quoted 7 lines
arch/arm/plat-s3c24xx/devs.c +1 -1
        .driver         = {
-               .name   = "s3c2410-rtc",
+               .name   = "s3c-rtc",
                .owner  = THIS_MODULE,
        },
  };

why not use platform_device_id ?

I didn't know of platform_device_id, looks like a clean(er) solution for this.

I'll post an updated patch with Jassi's and Ben's remarks in mind.

Regards,
Maurus Cuelenaere