Linux-RTC Archive on lore.kernel.org
 help / color / Atom feed
* [PATCH 1/3] rts: ds1685: remove not needed fields from private struct
@ 2019-10-11 15:05 Thomas Bogendoerfer
  2019-10-11 15:05 ` [PATCH 2/3] rtc: ds1685: use devm_platform_ioremap_resource helper Thomas Bogendoerfer
                   ` (3 more replies)
  0 siblings, 4 replies; 9+ messages in thread
From: Thomas Bogendoerfer @ 2019-10-11 15:05 UTC (permalink / raw)
  To: Joshua Kinard, Alessandro Zummo, Alexandre Belloni, linux-rtc,
	linux-kernel

A few of the fields in struct ds1685_priv aren't needed at all,
so we can remove it.

Signed-off-by: Thomas Bogendoerfer <tbogendoerfer@suse.de>
---
 drivers/rtc/rtc-ds1685.c   | 3 ---
 include/linux/rtc/ds1685.h | 3 ---
 2 files changed, 6 deletions(-)

diff --git a/drivers/rtc/rtc-ds1685.c b/drivers/rtc/rtc-ds1685.c
index 184e4a3e2bef..51f568473de8 100644
--- a/drivers/rtc/rtc-ds1685.c
+++ b/drivers/rtc/rtc-ds1685.c
@@ -1086,12 +1086,10 @@ ds1685_rtc_probe(struct platform_device *pdev)
 		 * Set the base address for the rtc, and ioremap its
 		 * registers.
 		 */
-		rtc->baseaddr = res->start;
 		rtc->regs = devm_ioremap(&pdev->dev, res->start, rtc->size);
 		if (!rtc->regs)
 			return -ENOMEM;
 	}
-	rtc->alloc_io_resources = pdata->alloc_io_resources;
 
 	/* Get the register step size. */
 	if (pdata->regstep > 0)
@@ -1271,7 +1269,6 @@ ds1685_rtc_probe(struct platform_device *pdev)
 	/* See if the platform doesn't support UIE. */
 	if (pdata->uie_unsupported)
 		rtc_dev->uie_unsupported = 1;
-	rtc->uie_unsupported = pdata->uie_unsupported;
 
 	rtc->dev = rtc_dev;
 
diff --git a/include/linux/rtc/ds1685.h b/include/linux/rtc/ds1685.h
index 43aec568ba7c..b9671d00d964 100644
--- a/include/linux/rtc/ds1685.h
+++ b/include/linux/rtc/ds1685.h
@@ -43,13 +43,10 @@ struct ds1685_priv {
 	struct rtc_device *dev;
 	void __iomem *regs;
 	u32 regstep;
-	resource_size_t baseaddr;
 	size_t size;
 	int irq_num;
 	bool bcd_mode;
 	bool no_irq;
-	bool uie_unsupported;
-	bool alloc_io_resources;
 	u8 (*read)(struct ds1685_priv *, int);
 	void (*write)(struct ds1685_priv *, int, u8);
 	void (*prepare_poweroff)(void);
-- 
2.16.4


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

* [PATCH 2/3] rtc: ds1685: use devm_platform_ioremap_resource helper
  2019-10-11 15:05 [PATCH 1/3] rts: ds1685: remove not needed fields from private struct Thomas Bogendoerfer
@ 2019-10-11 15:05 ` Thomas Bogendoerfer
  2019-10-12 22:49   ` Joshua Kinard
  2019-10-14 15:51   ` Alexandre Belloni
  2019-10-11 15:05 ` [PATCH 3/3] rtc: ds1685: add indirect access method and remove plat_read/plat_write Thomas Bogendoerfer
                   ` (2 subsequent siblings)
  3 siblings, 2 replies; 9+ messages in thread
From: Thomas Bogendoerfer @ 2019-10-11 15:05 UTC (permalink / raw)
  To: Joshua Kinard, Alessandro Zummo, Alexandre Belloni, linux-rtc,
	linux-kernel

Simplify ioremapping of registers by using devm_platform_ioremap_resource.

Signed-off-by: Thomas Bogendoerfer <tbogendoerfer@suse.de>
---
 drivers/rtc/rtc-ds1685.c   | 23 +++--------------------
 include/linux/rtc/ds1685.h |  1 -
 2 files changed, 3 insertions(+), 21 deletions(-)

diff --git a/drivers/rtc/rtc-ds1685.c b/drivers/rtc/rtc-ds1685.c
index 51f568473de8..349a8d1caca1 100644
--- a/drivers/rtc/rtc-ds1685.c
+++ b/drivers/rtc/rtc-ds1685.c
@@ -1040,7 +1040,6 @@ static int
 ds1685_rtc_probe(struct platform_device *pdev)
 {
 	struct rtc_device *rtc_dev;
-	struct resource *res;
 	struct ds1685_priv *rtc;
 	struct ds1685_rtc_platform_data *pdata;
 	u8 ctrla, ctrlb, hours;
@@ -1070,25 +1069,9 @@ ds1685_rtc_probe(struct platform_device *pdev)
 	 * that sits behind the IOC3 PCI metadevice.
 	 */
 	if (pdata->alloc_io_resources) {
-		/* Get the platform resources. */
-		res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
-		if (!res)
-			return -ENXIO;
-		rtc->size = resource_size(res);
-
-		/* Request a memory region. */
-		/* XXX: mmio-only for now. */
-		if (!devm_request_mem_region(&pdev->dev, res->start, rtc->size,
-					     pdev->name))
-			return -EBUSY;
-
-		/*
-		 * Set the base address for the rtc, and ioremap its
-		 * registers.
-		 */
-		rtc->regs = devm_ioremap(&pdev->dev, res->start, rtc->size);
-		if (!rtc->regs)
-			return -ENOMEM;
+		rtc->regs = devm_platform_ioremap_resource(pdev, 0);
+		if (IS_ERR(rtc->regs))
+			return PTR_ERR(rtc->regs);
 	}
 
 	/* Get the register step size. */
diff --git a/include/linux/rtc/ds1685.h b/include/linux/rtc/ds1685.h
index b9671d00d964..101c7adc05a2 100644
--- a/include/linux/rtc/ds1685.h
+++ b/include/linux/rtc/ds1685.h
@@ -43,7 +43,6 @@ struct ds1685_priv {
 	struct rtc_device *dev;
 	void __iomem *regs;
 	u32 regstep;
-	size_t size;
 	int irq_num;
 	bool bcd_mode;
 	bool no_irq;
-- 
2.16.4


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

* [PATCH 3/3] rtc: ds1685: add indirect access method and remove plat_read/plat_write
  2019-10-11 15:05 [PATCH 1/3] rts: ds1685: remove not needed fields from private struct Thomas Bogendoerfer
  2019-10-11 15:05 ` [PATCH 2/3] rtc: ds1685: use devm_platform_ioremap_resource helper Thomas Bogendoerfer
@ 2019-10-11 15:05 ` Thomas Bogendoerfer
  2019-10-12 23:22   ` Joshua Kinard
  2019-10-12 22:41 ` [PATCH 1/3] rts: ds1685: remove not needed fields from private struct Joshua Kinard
  2019-10-14 15:50 ` Alexandre Belloni
  3 siblings, 1 reply; 9+ messages in thread
From: Thomas Bogendoerfer @ 2019-10-11 15:05 UTC (permalink / raw)
  To: Joshua Kinard, Alessandro Zummo, Alexandre Belloni, linux-rtc,
	linux-kernel, Ralf Baechle, Paul Burton, James Hogan, linux-mips

Use of provided plat_read/plat_write introduces the problem of possible
different lifetime of rtc driver and plat_XXX function provider. As
this was only intended for SGI Octane (IP30) this patchset implements
a register indirect access method for IP30 and introduces an
access_type field in platform data to select how registers are
accessed. And since there are no resource allocating stunts needed
anymore it also gets rid of alloc_io_resources from platform data.

Signed-off-by: Thomas Bogendoerfer <tbogendoerfer@suse.de>
---
 arch/mips/sgi-ip32/ip32-platform.c |  2 +-
 drivers/rtc/rtc-ds1685.c           | 67 ++++++++++++++++++++++++--------------
 include/linux/rtc/ds1685.h         |  8 +++--
 3 files changed, 48 insertions(+), 29 deletions(-)

diff --git a/arch/mips/sgi-ip32/ip32-platform.c b/arch/mips/sgi-ip32/ip32-platform.c
index 5a2a82148d8d..c3909bd8dd1a 100644
--- a/arch/mips/sgi-ip32/ip32-platform.c
+++ b/arch/mips/sgi-ip32/ip32-platform.c
@@ -115,7 +115,7 @@ ip32_rtc_platform_data[] = {
 		.bcd_mode = true,
 		.no_irq = false,
 		.uie_unsupported = false,
-		.alloc_io_resources = true,
+		.access_type = ds1685_reg_direct,
 		.plat_prepare_poweroff = ip32_prepare_poweroff,
 	},
 };
diff --git a/drivers/rtc/rtc-ds1685.c b/drivers/rtc/rtc-ds1685.c
index 349a8d1caca1..9c5d064ebb6c 100644
--- a/drivers/rtc/rtc-ds1685.c
+++ b/drivers/rtc/rtc-ds1685.c
@@ -59,6 +59,32 @@ ds1685_write(struct ds1685_priv *rtc, int reg, u8 value)
 }
 /* ----------------------------------------------------------------------- */
 
+/* Indirect read/write functions */
+
+/**
+ * ds1685_indir_read - read a value from an rtc register.
+ * @rtc: pointer to the ds1685 rtc structure.
+ * @reg: the register address to read.
+ */
+static u8
+ds1685_indir_read(struct ds1685_priv *rtc, int reg)
+{
+	writeb(reg, rtc->regs);
+	return readb(rtc->data);
+}
+
+/**
+ * ds1685_indir_write - write a value to an rtc register.
+ * @rtc: pointer to the ds1685 rtc structure.
+ * @reg: the register address to write.
+ * @value: value to write to the register.
+ */
+static void
+ds1685_indir_write(struct ds1685_priv *rtc, int reg, u8 value)
+{
+	writeb(reg, rtc->regs);
+	writeb(value, rtc->data);
+}
 
 /* ----------------------------------------------------------------------- */
 /* Inlined functions */
@@ -1062,16 +1088,25 @@ ds1685_rtc_probe(struct platform_device *pdev)
 	if (!rtc)
 		return -ENOMEM;
 
-	/*
-	 * Allocate/setup any IORESOURCE_MEM resources, if required.  Not all
-	 * platforms put the RTC in an easy-access place.  Like the SGI Octane,
-	 * which attaches the RTC to a "ByteBus", hooked to a SuperIO chip
-	 * that sits behind the IOC3 PCI metadevice.
-	 */
-	if (pdata->alloc_io_resources) {
+	/* Setup resources and access functions */
+	switch (pdata->access_type) {
+	case ds1685_reg_direct:
+		rtc->regs = devm_platform_ioremap_resource(pdev, 0);
+		if (IS_ERR(rtc->regs))
+			return PTR_ERR(rtc->regs);
+		rtc->read = ds1685_read;
+		rtc->write = ds1685_write;
+		break;
+	case ds1685_reg_indirect:
 		rtc->regs = devm_platform_ioremap_resource(pdev, 0);
 		if (IS_ERR(rtc->regs))
 			return PTR_ERR(rtc->regs);
+		rtc->data = devm_platform_ioremap_resource(pdev, 1);
+		if (IS_ERR(rtc->data))
+			return PTR_ERR(rtc->data);
+		rtc->read = ds1685_indir_read;
+		rtc->write = ds1685_indir_write;
+		break;
 	}
 
 	/* Get the register step size. */
@@ -1080,24 +1115,6 @@ ds1685_rtc_probe(struct platform_device *pdev)
 	else
 		rtc->regstep = 1;
 
-	/* Platform read function, else default if mmio setup */
-	if (pdata->plat_read)
-		rtc->read = pdata->plat_read;
-	else
-		if (pdata->alloc_io_resources)
-			rtc->read = ds1685_read;
-		else
-			return -ENXIO;
-
-	/* Platform write function, else default if mmio setup */
-	if (pdata->plat_write)
-		rtc->write = pdata->plat_write;
-	else
-		if (pdata->alloc_io_resources)
-			rtc->write = ds1685_write;
-		else
-			return -ENXIO;
-
 	/* Platform pre-shutdown function, if defined. */
 	if (pdata->plat_prepare_poweroff)
 		rtc->prepare_poweroff = pdata->plat_prepare_poweroff;
diff --git a/include/linux/rtc/ds1685.h b/include/linux/rtc/ds1685.h
index 101c7adc05a2..67ee9d20cc5a 100644
--- a/include/linux/rtc/ds1685.h
+++ b/include/linux/rtc/ds1685.h
@@ -42,6 +42,7 @@
 struct ds1685_priv {
 	struct rtc_device *dev;
 	void __iomem *regs;
+	void __iomem *data;
 	u32 regstep;
 	int irq_num;
 	bool bcd_mode;
@@ -70,12 +71,13 @@ struct ds1685_rtc_platform_data {
 	const bool bcd_mode;
 	const bool no_irq;
 	const bool uie_unsupported;
-	const bool alloc_io_resources;
-	u8 (*plat_read)(struct ds1685_priv *, int);
-	void (*plat_write)(struct ds1685_priv *, int, u8);
 	void (*plat_prepare_poweroff)(void);
 	void (*plat_wake_alarm)(void);
 	void (*plat_post_ram_clear)(void);
+	enum {
+		ds1685_reg_direct,
+		ds1685_reg_indirect
+	} access_type;
 };
 
 
-- 
2.16.4


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

* Re: [PATCH 1/3] rts: ds1685: remove not needed fields from private struct
  2019-10-11 15:05 [PATCH 1/3] rts: ds1685: remove not needed fields from private struct Thomas Bogendoerfer
  2019-10-11 15:05 ` [PATCH 2/3] rtc: ds1685: use devm_platform_ioremap_resource helper Thomas Bogendoerfer
  2019-10-11 15:05 ` [PATCH 3/3] rtc: ds1685: add indirect access method and remove plat_read/plat_write Thomas Bogendoerfer
@ 2019-10-12 22:41 ` Joshua Kinard
  2019-10-14 15:50 ` Alexandre Belloni
  3 siblings, 0 replies; 9+ messages in thread
From: Joshua Kinard @ 2019-10-12 22:41 UTC (permalink / raw)
  To: Thomas Bogendoerfer, Alessandro Zummo, Alexandre Belloni,
	linux-rtc, linux-kernel

On 10/11/2019 11:05, Thomas Bogendoerfer wrote:
> A few of the fields in struct ds1685_priv aren't needed at all,
> so we can remove it.
> 
> Signed-off-by: Thomas Bogendoerfer <tbogendoerfer@suse.de>
> ---
>  drivers/rtc/rtc-ds1685.c   | 3 ---
>  include/linux/rtc/ds1685.h | 3 ---
>  2 files changed, 6 deletions(-)
> 
> diff --git a/drivers/rtc/rtc-ds1685.c b/drivers/rtc/rtc-ds1685.c
> index 184e4a3e2bef..51f568473de8 100644
> --- a/drivers/rtc/rtc-ds1685.c
> +++ b/drivers/rtc/rtc-ds1685.c
> @@ -1086,12 +1086,10 @@ ds1685_rtc_probe(struct platform_device *pdev)
>  		 * Set the base address for the rtc, and ioremap its
>  		 * registers.
>  		 */
> -		rtc->baseaddr = res->start;
>  		rtc->regs = devm_ioremap(&pdev->dev, res->start, rtc->size);
>  		if (!rtc->regs)
>  			return -ENOMEM;
>  	}
> -	rtc->alloc_io_resources = pdata->alloc_io_resources;
>  
>  	/* Get the register step size. */
>  	if (pdata->regstep > 0)
> @@ -1271,7 +1269,6 @@ ds1685_rtc_probe(struct platform_device *pdev)
>  	/* See if the platform doesn't support UIE. */
>  	if (pdata->uie_unsupported)
>  		rtc_dev->uie_unsupported = 1;
> -	rtc->uie_unsupported = pdata->uie_unsupported;
>  
>  	rtc->dev = rtc_dev;
>  
> diff --git a/include/linux/rtc/ds1685.h b/include/linux/rtc/ds1685.h
> index 43aec568ba7c..b9671d00d964 100644
> --- a/include/linux/rtc/ds1685.h
> +++ b/include/linux/rtc/ds1685.h
> @@ -43,13 +43,10 @@ struct ds1685_priv {
>  	struct rtc_device *dev;
>  	void __iomem *regs;
>  	u32 regstep;
> -	resource_size_t baseaddr;
>  	size_t size;
>  	int irq_num;
>  	bool bcd_mode;
>  	bool no_irq;
> -	bool uie_unsupported;
> -	bool alloc_io_resources;
>  	u8 (*read)(struct ds1685_priv *, int);
>  	void (*write)(struct ds1685_priv *, int, u8);
>  	void (*prepare_poweroff)(void);
> 

Acked-by: Joshua Kinard <kumba@gentoo.org>


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

* Re: [PATCH 2/3] rtc: ds1685: use devm_platform_ioremap_resource helper
  2019-10-11 15:05 ` [PATCH 2/3] rtc: ds1685: use devm_platform_ioremap_resource helper Thomas Bogendoerfer
@ 2019-10-12 22:49   ` Joshua Kinard
  2019-10-14 15:51   ` Alexandre Belloni
  1 sibling, 0 replies; 9+ messages in thread
From: Joshua Kinard @ 2019-10-12 22:49 UTC (permalink / raw)
  To: Thomas Bogendoerfer, Alessandro Zummo, Alexandre Belloni,
	linux-rtc, linux-kernel

On 10/11/2019 11:05, Thomas Bogendoerfer wrote:
> Simplify ioremapping of registers by using devm_platform_ioremap_resource.
> 
> Signed-off-by: Thomas Bogendoerfer <tbogendoerfer@suse.de>
> ---
>  drivers/rtc/rtc-ds1685.c   | 23 +++--------------------
>  include/linux/rtc/ds1685.h |  1 -
>  2 files changed, 3 insertions(+), 21 deletions(-)
> 
> diff --git a/drivers/rtc/rtc-ds1685.c b/drivers/rtc/rtc-ds1685.c
> index 51f568473de8..349a8d1caca1 100644
> --- a/drivers/rtc/rtc-ds1685.c
> +++ b/drivers/rtc/rtc-ds1685.c
> @@ -1040,7 +1040,6 @@ static int
>  ds1685_rtc_probe(struct platform_device *pdev)
>  {
>  	struct rtc_device *rtc_dev;
> -	struct resource *res;
>  	struct ds1685_priv *rtc;
>  	struct ds1685_rtc_platform_data *pdata;
>  	u8 ctrla, ctrlb, hours;
> @@ -1070,25 +1069,9 @@ ds1685_rtc_probe(struct platform_device *pdev)
>  	 * that sits behind the IOC3 PCI metadevice.
>  	 */
>  	if (pdata->alloc_io_resources) {
> -		/* Get the platform resources. */
> -		res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
> -		if (!res)
> -			return -ENXIO;
> -		rtc->size = resource_size(res);
> -
> -		/* Request a memory region. */
> -		/* XXX: mmio-only for now. */
> -		if (!devm_request_mem_region(&pdev->dev, res->start, rtc->size,
> -					     pdev->name))
> -			return -EBUSY;
> -
> -		/*
> -		 * Set the base address for the rtc, and ioremap its
> -		 * registers.
> -		 */
> -		rtc->regs = devm_ioremap(&pdev->dev, res->start, rtc->size);
> -		if (!rtc->regs)
> -			return -ENOMEM;
> +		rtc->regs = devm_platform_ioremap_resource(pdev, 0);
> +		if (IS_ERR(rtc->regs))
> +			return PTR_ERR(rtc->regs);
>  	}
>  
>  	/* Get the register step size. */
> diff --git a/include/linux/rtc/ds1685.h b/include/linux/rtc/ds1685.h
> index b9671d00d964..101c7adc05a2 100644
> --- a/include/linux/rtc/ds1685.h
> +++ b/include/linux/rtc/ds1685.h
> @@ -43,7 +43,6 @@ struct ds1685_priv {
>  	struct rtc_device *dev;
>  	void __iomem *regs;
>  	u32 regstep;
> -	size_t size;
>  	int irq_num;
>  	bool bcd_mode;
>  	bool no_irq;
> 


Acked-by: Joshua Kinard <kumba@gentoo.org>

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

* Re: [PATCH 3/3] rtc: ds1685: add indirect access method and remove plat_read/plat_write
  2019-10-11 15:05 ` [PATCH 3/3] rtc: ds1685: add indirect access method and remove plat_read/plat_write Thomas Bogendoerfer
@ 2019-10-12 23:22   ` Joshua Kinard
  2019-10-14 21:20     ` Thomas Bogendoerfer
  0 siblings, 1 reply; 9+ messages in thread
From: Joshua Kinard @ 2019-10-12 23:22 UTC (permalink / raw)
  To: Thomas Bogendoerfer, Alessandro Zummo, Alexandre Belloni,
	linux-rtc, linux-kernel, Ralf Baechle, Paul Burton, James Hogan,
	linux-mips

On 10/11/2019 11:05, Thomas Bogendoerfer wrote:
> Use of provided plat_read/plat_write introduces the problem of possible
> different lifetime of rtc driver and plat_XXX function provider. As
> this was only intended for SGI Octane (IP30) this patchset implements
> a register indirect access method for IP30 and introduces an
> access_type field in platform data to select how registers are
> accessed. And since there are no resource allocating stunts needed
> anymore it also gets rid of alloc_io_resources from platform data.
> 

Actually, I did it this way because IP32 was already in-tree, and IP30 was
not.  So the default ds1685_{read,write} functions were geared for the
in-tree machine, and IP30 brought along its own versions.  If IP30 support
gets merged into the kernel, this isn't needed anymore, but I don't think
this explanation accurately captures that.

The chief difference between IP32 and IP30's manner of accessing the RTC
is that IP32 has a 256-byte gap between each RTC register for unknown
reasons (this is documented in the IP32 hardware data sheets I have), and
access has to be MMIO'ed, since the RTC is hanging off of the MACE PCI
structs, like every other device in IP32's code.  IP30 doesn't have this
register gap to worry about, and it accesses the RTC registers via PIO.


> Signed-off-by: Thomas Bogendoerfer <tbogendoerfer@suse.de>
> ---
>  arch/mips/sgi-ip32/ip32-platform.c |  2 +-
>  drivers/rtc/rtc-ds1685.c           | 67 ++++++++++++++++++++++++--------------
>  include/linux/rtc/ds1685.h         |  8 +++--
>  3 files changed, 48 insertions(+), 29 deletions(-)
> 
> diff --git a/arch/mips/sgi-ip32/ip32-platform.c b/arch/mips/sgi-ip32/ip32-platform.c
> index 5a2a82148d8d..c3909bd8dd1a 100644
> --- a/arch/mips/sgi-ip32/ip32-platform.c
> +++ b/arch/mips/sgi-ip32/ip32-platform.c
> @@ -115,7 +115,7 @@ ip32_rtc_platform_data[] = {
>  		.bcd_mode = true,
>  		.no_irq = false,
>  		.uie_unsupported = false,
> -		.alloc_io_resources = true,
> +		.access_type = ds1685_reg_direct,
>  		.plat_prepare_poweroff = ip32_prepare_poweroff,
>  	},
>  };
> diff --git a/drivers/rtc/rtc-ds1685.c b/drivers/rtc/rtc-ds1685.c
> index 349a8d1caca1..9c5d064ebb6c 100644
> --- a/drivers/rtc/rtc-ds1685.c
> +++ b/drivers/rtc/rtc-ds1685.c
> @@ -59,6 +59,32 @@ ds1685_write(struct ds1685_priv *rtc, int reg, u8 value)
>  }
>  /* ----------------------------------------------------------------------- */
>  
> +/* Indirect read/write functions */
> +
> +/**
> + * ds1685_indir_read - read a value from an rtc register.
> + * @rtc: pointer to the ds1685 rtc structure.
> + * @reg: the register address to read.
> + */
> +static u8
> +ds1685_indir_read(struct ds1685_priv *rtc, int reg)
> +{
> +	writeb(reg, rtc->regs);
> +	return readb(rtc->data);
> +}
> +
> +/**
> + * ds1685_indir_write - write a value to an rtc register.
> + * @rtc: pointer to the ds1685 rtc structure.
> + * @reg: the register address to write.
> + * @value: value to write to the register.
> + */
> +static void
> +ds1685_indir_write(struct ds1685_priv *rtc, int reg, u8 value)
> +{
> +	writeb(reg, rtc->regs);
> +	writeb(value, rtc->data);
> +}

IP30 applied a mask of 0x7f on the 'reg' parameter on both of its
read/write functions, which was from Stan's original code.  Is this mask
not needed any more with the other changes you made to the IP30 code?  I
remember trying to do without this mask once long ago, and something broke,
so I have left it in ever since.

>  
>  /* ----------------------------------------------------------------------- */
>  /* Inlined functions */
> @@ -1062,16 +1088,25 @@ ds1685_rtc_probe(struct platform_device *pdev)
>  	if (!rtc)
>  		return -ENOMEM;
>  
> -	/*
> -	 * Allocate/setup any IORESOURCE_MEM resources, if required.  Not all
> -	 * platforms put the RTC in an easy-access place.  Like the SGI Octane,
> -	 * which attaches the RTC to a "ByteBus", hooked to a SuperIO chip
> -	 * that sits behind the IOC3 PCI metadevice.
> -	 */
> -	if (pdata->alloc_io_resources) {
> +	/* Setup resources and access functions */
> +	switch (pdata->access_type) {
> +	case ds1685_reg_direct:
> +		rtc->regs = devm_platform_ioremap_resource(pdev, 0);
> +		if (IS_ERR(rtc->regs))
> +			return PTR_ERR(rtc->regs);
> +		rtc->read = ds1685_read;
> +		rtc->write = ds1685_write;
> +		break;
> +	case ds1685_reg_indirect:
>  		rtc->regs = devm_platform_ioremap_resource(pdev, 0);
>  		if (IS_ERR(rtc->regs))
>  			return PTR_ERR(rtc->regs);
> +		rtc->data = devm_platform_ioremap_resource(pdev, 1);
> +		if (IS_ERR(rtc->data))
> +			return PTR_ERR(rtc->data);
> +		rtc->read = ds1685_indir_read;
> +		rtc->write = ds1685_indir_write;
> +		break;
>  	}

I believe there should be a default case in the switch statement to catch
and return -ENXIO so that we don't wind up with rtc->{read,write} being
NULL.

I also think the "indir" name isn't really descriptive of why IP32 and
IP30 effectively have different read/write mechanisms.  Might want to add
some comments to explain that IP32 uses MMIO and can just directly
read/write the registers, while IP30 uses PIO and has to go the route of
writing to an 'addr' register, then reading the result from a 'data'
register.


>  
>  	/* Get the register step size. */
> @@ -1080,24 +1115,6 @@ ds1685_rtc_probe(struct platform_device *pdev)
>  	else
>  		rtc->regstep = 1;
>  
> -	/* Platform read function, else default if mmio setup */
> -	if (pdata->plat_read)
> -		rtc->read = pdata->plat_read;
> -	else
> -		if (pdata->alloc_io_resources)
> -			rtc->read = ds1685_read;
> -		else
> -			return -ENXIO;
> -
> -	/* Platform write function, else default if mmio setup */
> -	if (pdata->plat_write)
> -		rtc->write = pdata->plat_write;
> -	else
> -		if (pdata->alloc_io_resources)
> -			rtc->write = ds1685_write;
> -		else
> -			return -ENXIO;
> -
>  	/* Platform pre-shutdown function, if defined. */
>  	if (pdata->plat_prepare_poweroff)
>  		rtc->prepare_poweroff = pdata->plat_prepare_poweroff;
> diff --git a/include/linux/rtc/ds1685.h b/include/linux/rtc/ds1685.h
> index 101c7adc05a2..67ee9d20cc5a 100644
> --- a/include/linux/rtc/ds1685.h
> +++ b/include/linux/rtc/ds1685.h
> @@ -42,6 +42,7 @@
>  struct ds1685_priv {
>  	struct rtc_device *dev;
>  	void __iomem *regs;
> +	void __iomem *data;
>  	u32 regstep;
>  	int irq_num;
>  	bool bcd_mode;
> @@ -70,12 +71,13 @@ struct ds1685_rtc_platform_data {
>  	const bool bcd_mode;
>  	const bool no_irq;
>  	const bool uie_unsupported;
> -	const bool alloc_io_resources;
> -	u8 (*plat_read)(struct ds1685_priv *, int);
> -	void (*plat_write)(struct ds1685_priv *, int, u8);
>  	void (*plat_prepare_poweroff)(void);
>  	void (*plat_wake_alarm)(void);
>  	void (*plat_post_ram_clear)(void);
> +	enum {
> +		ds1685_reg_direct,
> +		ds1685_reg_indirect
> +	} access_type;
>  };
>  
>  
> -- 2.16.4

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

* Re: [PATCH 1/3] rts: ds1685: remove not needed fields from private struct
  2019-10-11 15:05 [PATCH 1/3] rts: ds1685: remove not needed fields from private struct Thomas Bogendoerfer
                   ` (2 preceding siblings ...)
  2019-10-12 22:41 ` [PATCH 1/3] rts: ds1685: remove not needed fields from private struct Joshua Kinard
@ 2019-10-14 15:50 ` Alexandre Belloni
  3 siblings, 0 replies; 9+ messages in thread
From: Alexandre Belloni @ 2019-10-14 15:50 UTC (permalink / raw)
  To: Thomas Bogendoerfer
  Cc: Joshua Kinard, Alessandro Zummo, linux-rtc, linux-kernel

On 11/10/2019 17:05:43+0200, Thomas Bogendoerfer wrote:
> A few of the fields in struct ds1685_priv aren't needed at all,
> so we can remove it.
> 
> Signed-off-by: Thomas Bogendoerfer <tbogendoerfer@suse.de>
> ---
>  drivers/rtc/rtc-ds1685.c   | 3 ---
>  include/linux/rtc/ds1685.h | 3 ---
>  2 files changed, 6 deletions(-)
> 
Applied, thanks.

-- 
Alexandre Belloni, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com

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

* Re: [PATCH 2/3] rtc: ds1685: use devm_platform_ioremap_resource helper
  2019-10-11 15:05 ` [PATCH 2/3] rtc: ds1685: use devm_platform_ioremap_resource helper Thomas Bogendoerfer
  2019-10-12 22:49   ` Joshua Kinard
@ 2019-10-14 15:51   ` Alexandre Belloni
  1 sibling, 0 replies; 9+ messages in thread
From: Alexandre Belloni @ 2019-10-14 15:51 UTC (permalink / raw)
  To: Thomas Bogendoerfer
  Cc: Joshua Kinard, Alessandro Zummo, linux-rtc, linux-kernel

On 11/10/2019 17:05:44+0200, Thomas Bogendoerfer wrote:
> Simplify ioremapping of registers by using devm_platform_ioremap_resource.
> 
> Signed-off-by: Thomas Bogendoerfer <tbogendoerfer@suse.de>
> ---
>  drivers/rtc/rtc-ds1685.c   | 23 +++--------------------
>  include/linux/rtc/ds1685.h |  1 -
>  2 files changed, 3 insertions(+), 21 deletions(-)
> 
Applied, thanks.

-- 
Alexandre Belloni, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com

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

* Re: [PATCH 3/3] rtc: ds1685: add indirect access method and remove plat_read/plat_write
  2019-10-12 23:22   ` Joshua Kinard
@ 2019-10-14 21:20     ` Thomas Bogendoerfer
  0 siblings, 0 replies; 9+ messages in thread
From: Thomas Bogendoerfer @ 2019-10-14 21:20 UTC (permalink / raw)
  To: Joshua Kinard
  Cc: Alessandro Zummo, Alexandre Belloni, linux-rtc, linux-kernel,
	Ralf Baechle, Paul Burton, James Hogan, linux-mips

On Sat, 12 Oct 2019 19:22:01 -0400
Joshua Kinard <kumba@gentoo.org> wrote:

> On 10/11/2019 11:05, Thomas Bogendoerfer wrote:
> > +static void
> > +ds1685_indir_write(struct ds1685_priv *rtc, int reg, u8 value)
> > +{
> > +	writeb(reg, rtc->regs);
> > +	writeb(value, rtc->data);
> > +}
> 
> IP30 applied a mask of 0x7f on the 'reg' parameter on both of its
> read/write functions, which was from Stan's original code.  Is this mask
> not needed any more with the other changes you made to the IP30 code? 

reg is always < 0x80, so I didn't see a point in masking it.

> > +	switch (pdata->access_type) {
> > +	case ds1685_reg_direct:
> > +		rtc->regs = devm_platform_ioremap_resource(pdev, 0);
> > +		if (IS_ERR(rtc->regs))
> > +			return PTR_ERR(rtc->regs);
> > +		rtc->read = ds1685_read;
> > +		rtc->write = ds1685_write;
> > +		break;
> > +	case ds1685_reg_indirect:
> >  		rtc->regs = devm_platform_ioremap_resource(pdev, 0);
> >  		if (IS_ERR(rtc->regs))
> >  			return PTR_ERR(rtc->regs);
> > +		rtc->data = devm_platform_ioremap_resource(pdev, 1);
> > +		if (IS_ERR(rtc->data))
> > +			return PTR_ERR(rtc->data);
> > +		rtc->read = ds1685_indir_read;
> > +		rtc->write = ds1685_indir_write;
> > +		break;
> >  	}
> 
> I believe there should be a default case in the switch statement to catch
> and return -ENXIO so that we don't wind up with rtc->{read,write} being
> NULL.

access_type is an enum and all possible values are covered with cases.
But I'll add a safe guart to check that read/write is set to cover garbled
platform_data. If you want to keep plat_read/plat_write I could add an
additional access_type (which could also be done later, when there is a
real use case).

> I also think the "indir" name isn't really descriptive of why IP32 and
> IP30 effectively have different read/write mechanisms.

IP32 accesses register directly and IP30 indirectly via an address register.
I'll use indirect in function name and some comment to explain.

> Might want to add
> some comments to explain that IP32 uses MMIO and can just directly
> read/write the registers, while IP30 uses PIO and has to go the route of

what's PIO here for you ? RTC address and data register are mapped MMIO
as part of the IOC3 register bar on IP30.

Thomas.

-- 
SUSE Software Solutions Germany GmbH
HRB 247165 (AG München)
Geschäftsführer: Felix Imendörffer

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

end of thread, back to index

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-10-11 15:05 [PATCH 1/3] rts: ds1685: remove not needed fields from private struct Thomas Bogendoerfer
2019-10-11 15:05 ` [PATCH 2/3] rtc: ds1685: use devm_platform_ioremap_resource helper Thomas Bogendoerfer
2019-10-12 22:49   ` Joshua Kinard
2019-10-14 15:51   ` Alexandre Belloni
2019-10-11 15:05 ` [PATCH 3/3] rtc: ds1685: add indirect access method and remove plat_read/plat_write Thomas Bogendoerfer
2019-10-12 23:22   ` Joshua Kinard
2019-10-14 21:20     ` Thomas Bogendoerfer
2019-10-12 22:41 ` [PATCH 1/3] rts: ds1685: remove not needed fields from private struct Joshua Kinard
2019-10-14 15:50 ` Alexandre Belloni

Linux-RTC Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-rtc/0 linux-rtc/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-rtc linux-rtc/ https://lore.kernel.org/linux-rtc \
		linux-rtc@vger.kernel.org
	public-inbox-index linux-rtc

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-rtc


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git