Skip to contentSkip to conversation

OMAP3: Fix McBSP poll read and write for 32bit reg access

PATCH Superseded [email protected] 4 participants 4 messages Oct 14, 2009

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 OMAP3: Fix McBSP poll read and write for 32bit reg access

omap_mcbsp_pollwrite and omap_mcbsp_pollread functions access McBSP registers as 16-bit registers.

The McBSP registers (DRR_REG and DXR_REG) are limited to 32-bit data accesses (L4 Interconnect). 16-bit and 8-bit is not allowed and can corrupt register content.

This patch modifies omap_mcbsp_pollwrite and omap_mcbsp_pollread functions to do 32 bit access for above mentioned McBSP registers. Data accepted by these functions is also modified to 32-bit.

---
 arch/arm/plat-omap/include/mach/mcbsp.h |    4 +-
 arch/arm/plat-omap/mcbsp.c              |   46 ++++++++++++++-----------------
 2 files changed, 23 insertions(+), 27 deletions(-)
arch/arm/plat-omap/include/mach/mcbsp.h +2 -2
index 7e9cae3..05b0d8d 100644
@@ -455,8 +455,8 @@ int omap_mcbsp_spi_master_recv_word_poll(unsigned int id, u32 * word);
 void omap_mcbsp_set_spi_mode(unsigned int id, const struct omap_mcbsp_spi_cfg * spi_cfg);
 
 /* Polled read/write functions */
-int omap_mcbsp_pollread(unsigned int id, u16 * buf);
-int omap_mcbsp_pollwrite(unsigned int id, u16 buf);
+int omap_mcbsp_pollread(unsigned int id, u32 *buf);
+int omap_mcbsp_pollwrite(unsigned int id, u32 buf);
 int omap_mcbsp_set_io_type(unsigned int id, omap_mcbsp_io_type_t io_type);
 
 #endif
arch/arm/plat-omap/mcbsp.c +21 -25

92 lines not on this page · raw message

Signature · 1 line
1.6.0.4
#1 lore raw
Quoted 50 lines · On Wed, Oct 14, 2009 at 3:00 PM, <[email protected]> wrote:

omap_mcbsp_pollwrite and omap_mcbsp_pollread functions access McBSP registers as 16-bit registers.

The McBSP registers (DRR_REG and DXR_REG) are limited to 32-bit data accesses (L4 Interconnect). 16-bit and 8-bit is not allowed and can corrupt register content.

This patch modifies omap_mcbsp_pollwrite and omap_mcbsp_pollread functions to do 32 bit access for above mentioned McBSP registers. Data accepted by these functions is also modified to 32-bit.

---
 arch/arm/plat-omap/include/mach/mcbsp.h |    4 +- arch/arm/plat-omap/mcbsp.c              |   46 ++++++++++++++-----------------

 2 files changed, 23 insertions(+), 27 deletions(-)
arch/arm/plat-omap/include/mach/mcbsp.h +2 -2
index 7e9cae3..05b0d8d 100644
@@ -455,8 +455,8 @@ int omap_mcbsp_spi_master_recv_word_poll(unsigned int id, u32 * word);
  void omap_mcbsp_set_spi_mode(unsigned int id, const struct omap_mcbsp_spi_cfg * spi_cfg);
 
  /* Polled read/write functions */
-int omap_mcbsp_pollread(unsigned int id, u16 * buf);
-int omap_mcbsp_pollwrite(unsigned int id, u16 buf);
+int omap_mcbsp_pollread(unsigned int id, u32 *buf);
+int omap_mcbsp_pollwrite(unsigned int id, u32 buf);
  int omap_mcbsp_set_io_type(unsigned int id, omap_mcbsp_io_type_t io_type);
 
  #endif
arch/arm/plat-omap/mcbsp.c +1 -1
index 88ac976..1f278a2 100644
@@ -613,7 +613,7 @@ void omap_mcbsp_stop(unsigned int id, int tx, int rx)
  EXPORT_SYMBOL(omap_mcbsp_stop);
 
  /* polled mcbsp i/o operations */
-int omap_mcbsp_pollwrite(unsigned int id, u16 buf)
+int omap_mcbsp_pollwrite(unsigned int id, u32 buf)
  {
        struct omap_mcbsp *mcbsp;
        void __iomem *base;
@@ -626,26 +626,24 @@ int omap_mcbsp_pollwrite(unsigned int id, u16 buf)
        mcbsp = id_to_mcbsp_ptr(id);
        base = mcbsp->io_base;

arch/arm/plat-omap/mcbsp.c int omap_mcbsp_pollwrite(unsigned int id, u16 buf) · line 633

Quoted 10 lines
arch/arm/plat-omap/mcbsp.c +3 -4
 
-       writew(buf, base + OMAP_MCBSP_REG_DXR1);
+       OMAP_MCBSP_WRITE(base, DXR, buf);
        /* if frame sync error - clear the error */
-       if (readw(base + OMAP_MCBSP_REG_SPCR2) & XSYNC_ERR) {
+       if (OMAP_MCBSP_READ(base, SPCR2) & XSYNC_ERR) {
                /* clear error */
-               writew(readw(base + OMAP_MCBSP_REG_SPCR2) & (~XSYNC_ERR),
-                      base + OMAP_MCBSP_REG_SPCR2);
+               OMAP_MCBSP_WRITE(base, SPCR2, OMAP_MCBSP_READ(base , SPCR2)

remove extra space: 'base ,'
checkpatch.pl should catch these kind of issues.

-vimal

Quoted 83 lines
arch/arm/plat-omap/mcbsp.c +6 -7
+                                       & (~XSYNC_ERR));
                /* resend */
                return -1;
        } else {
                /* wait for transmit confirmation */
                int attemps = 0;
-               while (!(readw(base + OMAP_MCBSP_REG_SPCR2) & XRDY)) {
+               while (!(OMAP_MCBSP_READ(base, SPCR2) & XRDY)) {
                        if (attemps++ > 1000) {
-                               writew(readw(base + OMAP_MCBSP_REG_SPCR2) &
-                                      (~XRST),
-                                      base + OMAP_MCBSP_REG_SPCR2);
+                               OMAP_MCBSP_WRITE(base, SPCR2,
+                                       OMAP_MCBSP_READ(base, SPCR2) & (~XRST));
                                udelay(10);
-                               writew(readw(base + OMAP_MCBSP_REG_SPCR2) |
-                                      (XRST),
-                                      base + OMAP_MCBSP_REG_SPCR2);
+                               OMAP_MCBSP_WRITE(base, SPCR2,
+                                       OMAP_MCBSP_READ(base, SPCR2) | (XRST));
                                udelay(10);

                               dev_err(mcbsp->dev, "Could not write to" " McBSP%d Register\n", mcbsp->id);

arch/arm/plat-omap/mcbsp.c +10 -12
@@ -658,7 +656,7 @@ int omap_mcbsp_pollwrite(unsigned int id, u16 buf)
  }
  EXPORT_SYMBOL(omap_mcbsp_pollwrite);
 
-int omap_mcbsp_pollread(unsigned int id, u16 *buf)
+int omap_mcbsp_pollread(unsigned int id, u32 *buf)
  {
        struct omap_mcbsp *mcbsp;
        void __iomem *base;
@@ -671,24 +669,22 @@ int omap_mcbsp_pollread(unsigned int id, u16 *buf)
 
        base = mcbsp->io_base;
        /* if frame sync error - clear the error */
-       if (readw(base + OMAP_MCBSP_REG_SPCR1) & RSYNC_ERR) {
+       if (OMAP_MCBSP_READ(base, SPCR1) & RSYNC_ERR) {
                /* clear error */
-               writew(readw(base + OMAP_MCBSP_REG_SPCR1) & (~RSYNC_ERR),
-                      base + OMAP_MCBSP_REG_SPCR1);
+               OMAP_MCBSP_WRITE(base, SPCR1, OMAP_MCBSP_READ(base, SPCR1)
+                                       & (~RSYNC_ERR));
                /* resend */
                return -1;
        } else {
                /* wait for recieve confirmation */
                int attemps = 0;
-               while (!(readw(base + OMAP_MCBSP_REG_SPCR1) & RRDY)) {
-                       if (attemps++ > 1000) {
-                               writew(readw(base + OMAP_MCBSP_REG_SPCR1) &
-                                      (~RRST),
-                                      base + OMAP_MCBSP_REG_SPCR1);
+               while (!(OMAP_MCBSP_READ(base, SPCR1) & RRDY)) {
+                       if (attemps++ > 10000) {
+                               OMAP_MCBSP_WRITE(base, SPCR1,
+                                       OMAP_MCBSP_READ(base, SPCR1) & (~RRST));
                                udelay(10);
-                               writew(readw(base + OMAP_MCBSP_REG_SPCR1) |
-                                      (RRST),
-                                      base + OMAP_MCBSP_REG_SPCR1);
+                               OMAP_MCBSP_WRITE(base, SPCR1,
+                                       OMAP_MCBSP_READ(base, SPCR1) | (RRST));
                                udelay(10);

                               dev_err(mcbsp->dev, "Could not read from" " McBSP%d Register\n", mcbsp->id);

arch/arm/plat-omap/mcbsp.c +1 -2
@@ -696,7 +692,7 @@ int omap_mcbsp_pollread(unsigned int id, u16 *buf)
                        }
                }
        }
-       *buf = readw(base + OMAP_MCBSP_REG_DRR1);
+       *buf = OMAP_MCBSP_READ(base, DRR);
 
        return 0;
  }
--

1.6.0.4

--
To unsubscribe from this list: send the line "unsubscribe linux-omap" in the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Signature · 6 lines
Regards,
Vimal Singh
--
To unsubscribe from this list: send the line "unsubscribe linux-omap" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#2 lore raw
Quoted 18 lines

-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf Of vimal singh
Sent: Wednesday, October 14, 2009 3:23 PM
To: Varadarajan, Charu Latha
Cc: [email protected]; Syed, Rafiuddin
Subject: Re: [PATCH] OMAP3: Fix McBSP poll read and write for 32bit reg access

Quoted 7 lines

       base = mcbsp->io_base;
       /* if frame sync error - clear the error */
-       if (readw(base + OMAP_MCBSP_REG_SPCR1) & RSYNC_ERR) {
+       if (OMAP_MCBSP_READ(base, SPCR1) & RSYNC_ERR) { /* clear error */
-               writew(readw(base + OMAP_MCBSP_REG_SPCR1) &

Quoted 7 lines

(~RSYNC_ERR),

Quoted 2 lines

-                      base + OMAP_MCBSP_REG_SPCR1);
+               OMAP_MCBSP_WRITE(base, SPCR1,

OMAP_MCBSP_READ(base, SPCR1)

Quoted 3 lines

+                                       & (~RSYNC_ERR)); /* resend */
               return -1;

Return value can be a meaningful macro with proper value?

Quoted 4 lines
Quoted 4 lines

       } else {
               /* wait for recieve confirmation */ int attemps = 0;
-               while (!(readw(base + OMAP_MCBSP_REG_SPCR1)

Quoted 10 lines

& RRDY)) {

Quoted 2 lines

-                       if (attemps++ > 1000) {
-                               writew(readw(base +

OMAP_MCBSP_REG_SPCR1) &

Quoted 6 lines

-                                      (~RRST),
-                                      base + OMAP_MCBSP_REG_SPCR1);
+               while (!(OMAP_MCBSP_READ(base, SPCR1) & RRDY)) {
+                       if (attemps++ > 10000) {
+                               OMAP_MCBSP_WRITE(base, SPCR1, +


Why attemps changed from 1000 to 10000?

-Manjunath

--
To unsubscribe from this list: send the line "unsubscribe linux-omap" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#3 lore raw
In reply to [email protected]

Charu,

Quoted 34 lines

-----Original Message-----
From: [email protected] [mailto:linux-omap- [email protected]] On Behalf Of Varadarajan, Charu Latha
Sent: Wednesday, October 14, 2009 3:00 PM
To: [email protected]
Cc: Varadarajan, Charu Latha; Syed, Rafiuddin
Subject: [PATCH] OMAP3: Fix McBSP poll read and write for 32bit reg access

omap_mcbsp_pollwrite and omap_mcbsp_pollread functions access McBSP registers as 16-bit registers.

The McBSP registers (DRR_REG and DXR_REG) are limited to 32-bit data accesses (L4 Interconnect). 16-bit and 8-bit is not allowed and can corrupt register content.

This patch modifies omap_mcbsp_pollwrite and omap_mcbsp_pollread functions to do 32 bit access for above mentioned McBSP registers. Data accepted by these functions is also modified to 32-bit.

---
 arch/arm/plat-omap/include/mach/mcbsp.h |    4 +-
 arch/arm/plat-omap/mcbsp.c              |   46 ++++++++++++++------------
-----
 2 files changed, 23 insertions(+), 27 deletions(-)
arch/arm/plat- renamed from arch/arm/plat-omap/include/mach/mcbsp.h +0 -0

omap/include/mach/mcbsp.h
index 7e9cae3..05b0d8d 100644

arch/arm/plat-omap/include/mach/mcbsp.h int omap_mcbsp_spi_master_recv_word_poll(unsigned int · line 461

Quoted 9 lines
arch/arm/plat-omap/include/mach/mcbsp.h +2 -2
@@ -455,8 +455,8 @@ int omap_mcbsp_spi_master_recv_word_poll(unsigned int
 id, u32 * word);
 void omap_mcbsp_set_spi_mode(unsigned int id, const struct
 omap_mcbsp_spi_cfg * spi_cfg);
 
 /* Polled read/write functions */
-int omap_mcbsp_pollread(unsigned int id, u16 * buf);
-int omap_mcbsp_pollwrite(unsigned int id, u16 buf);
+int omap_mcbsp_pollread(unsigned int id, u32 *buf);
+int omap_mcbsp_pollwrite(unsigned int id, u32 buf);

If the issue is with DRR_REG and DXR_REG, why are you changing the signature of the generic API. You can handle these registers as a exceptions in the code.

Quoted 18 lines
arch/arm/plat-omap/include/mach/mcbsp.h +0 -0
 int omap_mcbsp_set_io_type(unsigned int id, omap_mcbsp_io_type_t

io_type);

#endif

arch/arm/plat-omap/mcbsp.c +1 -1
index 88ac976..1f278a2 100644
@@ -613,7 +613,7 @@ void omap_mcbsp_stop(unsigned int id, int tx, int rx)
 EXPORT_SYMBOL(omap_mcbsp_stop);
 
 /* polled mcbsp i/o operations */
-int omap_mcbsp_pollwrite(unsigned int id, u16 buf)
+int omap_mcbsp_pollwrite(unsigned int id, u32 buf)
 {
 	struct omap_mcbsp *mcbsp;
 	void __iomem *base;

arch/arm/plat-omap/mcbsp.c int omap_mcbsp_pollwrite(unsigned int id, u16 buf) · line 629

Quoted 5 lines
arch/arm/plat-omap/mcbsp.c +1 -1
@@ -626,26 +626,24 @@ int omap_mcbsp_pollwrite(unsigned int id, u16 buf)
 	mcbsp = id_to_mcbsp_ptr(id);
 	base = mcbsp->io_base;
 
-	writew(buf, base + OMAP_MCBSP_REG_DXR1);
+	OMAP_MCBSP_WRITE(base, DXR, buf);

Why do you need this? Is writew()/readw() not doing 16 bit operations ?

Quoted 83 lines
arch/arm/plat-omap/mcbsp.c +19 -24
 	/* if frame sync error - clear the error */
-	if (readw(base + OMAP_MCBSP_REG_SPCR2) & XSYNC_ERR) {
+	if (OMAP_MCBSP_READ(base, SPCR2) & XSYNC_ERR) {
 		/* clear error */
-		writew(readw(base + OMAP_MCBSP_REG_SPCR2) & (~XSYNC_ERR),
-		       base + OMAP_MCBSP_REG_SPCR2);
+		OMAP_MCBSP_WRITE(base, SPCR2, OMAP_MCBSP_READ(base , SPCR2)
+					& (~XSYNC_ERR));
 		/* resend */
 		return -1;
 	} else {
 		/* wait for transmit confirmation */
 		int attemps = 0;
-		while (!(readw(base + OMAP_MCBSP_REG_SPCR2) & XRDY)) {
+		while (!(OMAP_MCBSP_READ(base, SPCR2) & XRDY)) {
 			if (attemps++ > 1000) {
-				writew(readw(base + OMAP_MCBSP_REG_SPCR2) &
-				       (~XRST),
-				       base + OMAP_MCBSP_REG_SPCR2);
+				OMAP_MCBSP_WRITE(base, SPCR2,
+					OMAP_MCBSP_READ(base, SPCR2) & (~XRST));
 				udelay(10);
-				writew(readw(base + OMAP_MCBSP_REG_SPCR2) |
-				       (XRST),
-				       base + OMAP_MCBSP_REG_SPCR2);
+				OMAP_MCBSP_WRITE(base, SPCR2,
+					OMAP_MCBSP_READ(base, SPCR2) | (XRST));
 				udelay(10);
 				dev_err(mcbsp->dev, "Could not write to"
 					" McBSP%d Register\n", mcbsp->id);
@@ -658,7 +656,7 @@ int omap_mcbsp_pollwrite(unsigned int id, u16 buf)
 }
 EXPORT_SYMBOL(omap_mcbsp_pollwrite);
 
-int omap_mcbsp_pollread(unsigned int id, u16 *buf)
+int omap_mcbsp_pollread(unsigned int id, u32 *buf)
 {
 	struct omap_mcbsp *mcbsp;
 	void __iomem *base;
@@ -671,24 +669,22 @@ int omap_mcbsp_pollread(unsigned int id, u16 *buf)
 
 	base = mcbsp->io_base;
 	/* if frame sync error - clear the error */
-	if (readw(base + OMAP_MCBSP_REG_SPCR1) & RSYNC_ERR) {
+	if (OMAP_MCBSP_READ(base, SPCR1) & RSYNC_ERR) {
 		/* clear error */
-		writew(readw(base + OMAP_MCBSP_REG_SPCR1) & (~RSYNC_ERR),
-		       base + OMAP_MCBSP_REG_SPCR1);
+		OMAP_MCBSP_WRITE(base, SPCR1, OMAP_MCBSP_READ(base, SPCR1)
+					& (~RSYNC_ERR));
 		/* resend */
 		return -1;
 	} else {
 		/* wait for recieve confirmation */
 		int attemps = 0;
-		while (!(readw(base + OMAP_MCBSP_REG_SPCR1) & RRDY)) {
-			if (attemps++ > 1000) {
-				writew(readw(base + OMAP_MCBSP_REG_SPCR1) &
-				       (~RRST),
-				       base + OMAP_MCBSP_REG_SPCR1);
+		while (!(OMAP_MCBSP_READ(base, SPCR1) & RRDY)) {
+			if (attemps++ > 10000) {
+				OMAP_MCBSP_WRITE(base, SPCR1,
+					OMAP_MCBSP_READ(base, SPCR1) & (~RRST));
 				udelay(10);
-				writew(readw(base + OMAP_MCBSP_REG_SPCR1) |
-				       (RRST),
-				       base + OMAP_MCBSP_REG_SPCR1);
+				OMAP_MCBSP_WRITE(base, SPCR1,
+					OMAP_MCBSP_READ(base, SPCR1) | (RRST));
 				udelay(10);
 				dev_err(mcbsp->dev, "Could not read from"
 					" McBSP%d Register\n", mcbsp->id);
@@ -696,7 +692,7 @@ int omap_mcbsp_pollread(unsigned int id, u16 *buf)
 			}
 		}
 	}
-	*buf = readw(base + OMAP_MCBSP_REG_DRR1);
+	*buf = OMAP_MCBSP_READ(base, DRR);
 
 	return 0;
 }
--
Quoted 1 line

1.6.0.4

Regards,
Santosh