Skip to contentSkip to conversation

powerpc/512x: add function for CS parameter configuration

PATCH Superseded Anatolij Gustschin 2 participants 6 messages Feb 1, 2013 – Feb 4, 2013

Subsystems (2)
lore
Share & tools
lore

Anatolij Gustschin

author maintainer
#0 lore raw

PATCH 1/1 powerpc/512x: add function for CS parameter configuration

Add ability to configure CS parameters for devices that need different CS parameters setup after their configuration. I.e. an FPGA device on LP bus can require different CS parameters for its bus interface after loading firmware into it. A driver can easily reconfigure the LPC CS parameters using this function.

---
 arch/powerpc/include/asm/mpc5121.h           |   16 +++++++++++++
 arch/powerpc/platforms/512x/mpc512x_shared.c |   30 ++++++++++++++++++++++++++
 2 files changed, 46 insertions(+), 0 deletions(-)
arch/powerpc/include/asm/mpc5121.h +16 -0
index 8c0ab2c..738ebca 100644
@@ -53,4 +53,20 @@ struct mpc512x_ccm {
 	u32	m4ccr;	/* MSCAN4 CCR */
 	u8	res[0x98]; /* Reserved */
 };
+
+/*
+ * LPC Module
+ */
+struct mpc512x_lpc {
+	u32	cs_cfg[8];	/* CS config */
+	u32	cs_ctrl;	/* CS Control Register */
+	u32	cs_status;	/* CS Status Register */
+	u32	burst_ctrl;	/* CS Burst Control Register */
+	u32	deadcycle_ctrl;	/* CS Deadcycle Control Register */
+	u32	holdcycle_ctrl;	/* CS Holdcycle Control Register */
+	u32	alt;		/* Address Latch Timing Register */
+};
+
+int mpc512x_cs_config(int cs, u32 val);
+
 #endif /* __ASM_POWERPC_MPC5121_H__ */
arch/powerpc/platforms/512x/mpc512x_shared.c +30 -0
index c344438..112b4f6 100644
@@ -436,3 +436,33 @@ void __init mpc512x_init(void)
 	mpc512x_restart_init();
 	mpc512x_psc_fifo_init();
 }
+
+/**
+ * mpc512x_cs_config - Setup chip select configuration
+ * @cs: chip select number
+ * @val: chip select configuration value
+ *
+ * Perform chip select configuration for devices on LocalPlus Bus.
+ * Intended to dynamically reconfigure the chip select parameters
+ * for configurable devices on the bus.
+ */
+int mpc512x_cs_config(int cs, u32 val)
+{
+	static struct mpc512x_lpc __iomem *lpc;
+	struct device_node *np;
+
+	if (cs < 0 || cs > 7)
+		return -EINVAL;
+
+	if (!lpc) {
+		np = of_find_compatible_node(NULL, NULL, "fsl,mpc5121-lpc");
+		lpc = of_iomap(np, 0);
+		of_node_put(np);
+		if (!lpc)
+			return -ENOMEM;
+	}
+
+	out_be32(&lpc->cs_cfg[cs], val);
+	return 0;
+}
+EXPORT_SYMBOL_GPL(mpc512x_cs_config);
Signature · 1 line
1.7.5.4
#1 lore raw
Quoted 5 lines · Anatolij Gustschin

Add ability to configure CS parameters for devices that need different CS parameters setup after their configuration. I.e. an FPGA device on LP bus can require different CS parameters for its bus interface after loading firmware into it. A driver can easily reconfigure the LPC CS parameters using this function.

Could you define "CS" somewhere?

arch/powerpc/include/asm/mpc5121.h struct mpc512x_ccm { · line 68

Quoted 9 lines
arch/powerpc/include/asm/mpc5121.h +9 -0
+struct mpc512x_lpc {
+       u32     cs_cfg[8];      /* CS config */
+       u32     cs_ctrl;        /* CS Control Register */
+       u32     cs_status;      /* CS Status Register */
+       u32     burst_ctrl;     /* CS Burst Control Register */
+       u32     deadcycle_ctrl; /* CS Deadcycle Control Register */
+       u32     holdcycle_ctrl; /* CS Holdcycle Control Register */
+       u32     alt;            /* Address Latch Timing Register */
+};

These should be __be32.

Quoted 19 lines
arch/powerpc/include/asm/mpc5121.h +3 -0
+
+int mpc512x_cs_config(int cs, u32 val);
+
 #endif /* __ASM_POWERPC_MPC5121_H__ */
arch/powerpc/platforms/512x/mpc512x_shared.c +7 -0
index c344438..112b4f6 100644
@@ -436,3 +436,33 @@ void __init mpc512x_init(void)
        mpc512x_restart_init();
        mpc512x_psc_fifo_init();
 }
+
+/**
+ * mpc512x_cs_config - Setup chip select configuration
+ * @cs: chip select number
+ * @val: chip select configuration value
+ *
+ * Perform chip select configuration for devices on LocalPlus Bus.

arch/powerpc/platforms/512x/mpc512x_shared.c void __init mpc512x_init(void) · line 455

Quoted 10 lines
arch/powerpc/platforms/512x/mpc512x_shared.c +10 -0
+ * Intended to dynamically reconfigure the chip select parameters
+ * for configurable devices on the bus.
+ */
+int mpc512x_cs_config(int cs, u32 val)
+{
+       static struct mpc512x_lpc __iomem *lpc;
+       struct device_node *np;
+
+       if (cs < 0 || cs > 7)
+               return -EINVAL;

If you make cs an unsigned int, you won't need to test for < 0.

arch/powerpc/platforms/512x/mpc512x_shared.c void __init mpc512x_init(void) · line 465

Quoted 10 lines
arch/powerpc/platforms/512x/mpc512x_shared.c +10 -0
+
+       if (!lpc) {
+               np = of_find_compatible_node(NULL, NULL, "fsl,mpc5121-lpc");
+               lpc = of_iomap(np, 0);
+               of_node_put(np);
+               if (!lpc)
+                       return -ENOMEM;
+       }
+
+       out_be32(&lpc->cs_cfg[cs], val);

You forgot the iounmap() if lpc == NULL.

arch/powerpc/platforms/512x/mpc512x_shared.c void __init mpc512x_init(void) · line 468

Quoted 3 lines
arch/powerpc/platforms/512x/mpc512x_shared.c +3 -0
+       return 0;
+}
+EXPORT_SYMBOL_GPL(mpc512x_cs_config);

EXPORT_SYMBOL, please, to match the rest of the Freescale platforms.

Signature · 2 lines
Timur Tabi
Linux kernel developer at Freescale
author maintainer
#2 lore raw
Quoted 8 lines · On Fri, 1 Feb 2013 22:31:51 -0600 Timur Tabi <[email protected]> wrote:
Quoted 5 lines · Anatolij Gustschin

Add ability to configure CS parameters for devices that need different CS parameters setup after their configuration. I.e. an FPGA device on LP bus can require different CS parameters for its bus interface after loading firmware into it. A driver can easily reconfigure the LPC CS parameters using this function.

Could you define "CS" somewhere?

I'll define it in revised commit log in v2.

Quoted 11 lines

arch/powerpc/include/asm/mpc5121.h struct mpc512x_ccm { · line 68

Quoted 9 lines
arch/powerpc/include/asm/mpc5121.h +9 -0
+struct mpc512x_lpc {
+       u32     cs_cfg[8];      /* CS config */
+       u32     cs_ctrl;        /* CS Control Register */
+       u32     cs_status;      /* CS Status Register */
+       u32     burst_ctrl;     /* CS Burst Control Register */
+       u32     deadcycle_ctrl; /* CS Deadcycle Control Register */
+       u32     holdcycle_ctrl; /* CS Holdcycle Control Register */
+       u32     alt;            /* Address Latch Timing Register */
+};

These should be __be32.

Why? To add a new bunch of sparse warnings?

...

Quoted 4 lines

arch/powerpc/platforms/512x/mpc512x_shared.c void __init mpc512x_init(void) · line 455

Quoted 2 lines
arch/powerpc/platforms/512x/mpc512x_shared.c +2 -0
+       if (cs < 0 || cs > 7)
+               return -EINVAL;

If you make cs an unsigned int, you won't need to test for < 0.

can do that, yes.

Quoted 4 lines
Quoted 4 lines
arch/powerpc/platforms/512x/mpc512x_shared.c +4 -0
+
+       if (!lpc) {
+               np = of_find_compatible_node(NULL, NULL, "fsl,mpc5121-lpc");
+               lpc = of_iomap(np, 0);
Quoted 8 lines

arch/powerpc/platforms/512x/mpc512x_shared.c void __init mpc512x_init(void) · line 465

Quoted 6 lines
arch/powerpc/platforms/512x/mpc512x_shared.c +6 -0
+               of_node_put(np);
+               if (!lpc)
+                       return -ENOMEM;
+       }
+
+       out_be32(&lpc->cs_cfg[cs], val);

You forgot the iounmap() if lpc == NULL.

No, it is intentional, no need to map/unmap again and again for all subsequent calls.

Quoted 5 lines

arch/powerpc/platforms/512x/mpc512x_shared.c void __init mpc512x_init(void) · line 468

Quoted 3 lines
arch/powerpc/platforms/512x/mpc512x_shared.c +3 -0
+       return 0;
+}
+EXPORT_SYMBOL_GPL(mpc512x_cs_config);

EXPORT_SYMBOL, please, to match the rest of the Freescale platforms.

I'll change it in v2. Thanks!

Anatolij

#3 lore raw
Quoted 12 lines · Anatolij Gustschin
Quoted 11 lines

arch/powerpc/include/asm/mpc5121.h struct mpc512x_ccm { · line 68

Quoted 9 lines
arch/powerpc/include/asm/mpc5121.h +9 -0
+struct mpc512x_lpc {
+       u32     cs_cfg[8];      /* CS config */
+       u32     cs_ctrl;        /* CS Control Register */
+       u32     cs_status;      /* CS Status Register */
+       u32     burst_ctrl;     /* CS Burst Control Register */
+       u32     deadcycle_ctrl; /* CS Deadcycle Control Register */
+       u32     holdcycle_ctrl; /* CS Holdcycle Control Register */
+       u32     alt;            /* Address Latch Timing Register */
+};

These should be __be32.

Quoted 1 line

Why? To add a new bunch of sparse warnings?

Hmm... I thought that making them __be32 will *avoid* sparse warnings.

Quoted 4 lines
Quoted 1 line

You forgot the iounmap() if lpc == NULL.

No, it is intentional, no need to map/unmap again and again for all subsequent calls.

Sorry, for some reason I thought that lpc was a parameter that you passed in.

Signature · 1 line
Timur Tabi
author maintainer
#4 lore raw

PATCH v2 1/1 powerpc/512x: add function for chip select parameter configuration

In reply to Anatolij Gustschin

Add ability to configure chip select (CS) parameters for devices that need different CS parameters setup after their configuration. I.e. an FPGA device on LP bus can require different CS parameters for its bus interface after loading firmware into it. A driver can easily reconfigure the LPC CS parameters using this function.

---
v2:
- define CS in commit log
- use unsigned int type for cs argument to simplify valid CS range check
- use EXPORT_SYMBOL

 arch/powerpc/include/asm/mpc5121.h           |   16 +++++++++++++
 arch/powerpc/platforms/512x/mpc512x_shared.c |   30 ++++++++++++++++++++++++++
 2 files changed, 46 insertions(+), 0 deletions(-)
arch/powerpc/include/asm/mpc5121.h +16 -0
index 8c0ab2c..8ae133e 100644
@@ -53,4 +53,20 @@ struct mpc512x_ccm {
 	u32	m4ccr;	/* MSCAN4 CCR */
 	u8	res[0x98]; /* Reserved */
 };
+
+/*
+ * LPC Module
+ */
+struct mpc512x_lpc {
+	u32	cs_cfg[8];	/* CS config */
+	u32	cs_ctrl;	/* CS Control Register */
+	u32	cs_status;	/* CS Status Register */
+	u32	burst_ctrl;	/* CS Burst Control Register */
+	u32	deadcycle_ctrl;	/* CS Deadcycle Control Register */
+	u32	holdcycle_ctrl;	/* CS Holdcycle Control Register */
+	u32	alt;		/* Address Latch Timing Register */
+};
+
+int mpc512x_cs_config(unsigned int cs, u32 val);
+
 #endif /* __ASM_POWERPC_MPC5121_H__ */
arch/powerpc/platforms/512x/mpc512x_shared.c +30 -0
index 39d5630..8e2bde9 100644
@@ -456,3 +456,33 @@ void __init mpc512x_init(void)
 	mpc512x_restart_init();
 	mpc512x_psc_fifo_init();
 }
+
+/**
+ * mpc512x_cs_config - Setup chip select configuration
+ * @cs: chip select number
+ * @val: chip select configuration value
+ *
+ * Perform chip select configuration for devices on LocalPlus Bus.
+ * Intended to dynamically reconfigure the chip select parameters
+ * for configurable devices on the bus.
+ */
+int mpc512x_cs_config(unsigned int cs, u32 val)
+{
+	static struct mpc512x_lpc __iomem *lpc;
+	struct device_node *np;
+
+	if (cs > 7)
+		return -EINVAL;
+
+	if (!lpc) {
+		np = of_find_compatible_node(NULL, NULL, "fsl,mpc5121-lpc");
+		lpc = of_iomap(np, 0);
+		of_node_put(np);
+		if (!lpc)
+			return -ENOMEM;
+	}
+
+	out_be32(&lpc->cs_cfg[cs], val);
+	return 0;
+}
+EXPORT_SYMBOL(mpc512x_cs_config);
Signature · 1 line
1.7.5.4
Acked-by on v2 1/1
#5 lore raw

Re: [PATCH v2] powerpc/512x: add function for chip select parameter configuration

Quoted 8 lines · Anatolij Gustschin

Add ability to configure chip select (CS) parameters for devices that need different CS parameters setup after their configuration. I.e. an FPGA device on LP bus can require different CS parameters for its bus interface after loading firmware into it. A driver can easily reconfigure the LPC CS parameters using this function.

---

Signature · 2 lines
Timur Tabi
Linux kernel developer at Freescale