Skip to contentSkip to conversation

qe-uart: modify qe-uart to adapt both powerpc and arm

PATCH In review Zhao Qiang 3 participants 4 messages Oct 10, 2014 – Oct 17, 2014

Subsystems (4)
lore
Share & tools
lore

Zhao Qiang

author
#0 lore raw

PATCH 1/3 qe-uart: modify qe-uart to adapt both powerpc and arm

qe has been supported by arm board ls1021, qe-uart need to be supported by ls1021.
modify the code to make qe-uart can work on both powerpc and ls1021.

---
 arch/arm/include/asm/delay.h  |  16 ++++
 arch/arm/include/asm/io.h     |  28 +++++++
 arch/arm/include/asm/irq.h    |   2 +
 arch/arm/kernel/irq.c         |   7 ++
 drivers/soc/qe/Kconfig        |   1 -
 drivers/soc/qe/qe.c           |  63 ++++++++-------
 drivers/soc/qe/qe_common.c    |   2 +-
 drivers/soc/qe/qe_ic.c        |   7 +-
 drivers/soc/qe/qe_io.c        |  53 ++++++-------
 drivers/soc/qe/ucc_slow.c     |  40 +++++-----
 drivers/tty/serial/ucc_uart.c | 176 +++++++++++++++++++++---------------------
 include/linux/fsl/qe.h        |  21 +++++
 12 files changed, 245 insertions(+), 171 deletions(-)
arch/arm/include/asm/delay.h +16 -0
index dff714d..a932f99 100644
@@ -57,6 +57,22 @@ extern void __bad_udelay(void);
 			__const_udelay((n) * UDELAY_MULT)) :		\
 	  __udelay(n))
 
+#define spin_event_timeout(condition, timeout, delay)                          \
+({                                                                             \
+	typeof(condition) __ret;                                               \
+	int i = 0;							       \
+	while (!(__ret = (condition)) && (i++ < timeout)) {		       \
+		if (delay)                                                     \
+			udelay(delay);                                         \
+		else                                                           \
+			cpu_relax();					       \
+		udelay(1);						       \
+	}								       \
+	if (!__ret)                                                            \
+		__ret = (condition);                                           \
+	__ret;		                                                       \
+})
+
 /* Loop-based definitions for assembly code. */
 extern void __loop_delay(unsigned long loops);
 extern void __loop_udelay(unsigned long usecs);
arch/arm/include/asm/io.h +28 -0
index d070741..4bec694 100644
@@ -206,6 +206,34 @@ extern int pci_ioremap_io(unsigned int offset, phys_addr_t phys_addr);
 #endif
 #endif
 
+/* access ports */
+#define setbits32(_addr, _v) iowrite32be(ioread32be(_addr) |  (_v), (_addr))
+#define clrbits32(_addr, _v) iowrite32be(ioread32be(_addr) & ~(_v), (_addr))
+
+#define setbits16(_addr, _v) iowrite16be(ioread16be(_addr) |  (_v), (_addr))
+#define clrbits16(_addr, _v) iowrite16be(ioread16be(_addr) & ~(_v), (_addr))
+
+#define setbits8(_addr, _v) iowrite8(ioread8(_addr) |  (_v), (_addr))
+#define clrbits8(_addr, _v) iowrite8(ioread8(_addr) & ~(_v), (_addr))
+
+/* Clear and set bits in one shot.  These macros can be used to clear and
+ * set multiple bits in a register using a single read-modify-write.  These
+ * macros can also be used to set a multiple-bit bit pattern using a mask,
+ * by specifying the mask in the 'clear' parameter and the new bit pattern
+ * in the 'set' parameter.
+ */
+
+#define clrsetbits_be32(addr, clear, set) \
+	iowrite32be((ioread32be(addr) & ~(clear)) | (set), (addr))
+#define clrsetbits_le32(addr, clear, set) \
+	iowrite32le((ioread32le(addr) & ~(clear)) | (set), (addr))
+#define clrsetbits_be16(addr, clear, set) \
+	iowrite16be((ioread16be(addr) & ~(clear)) | (set), (addr))
+#define clrsetbits_le16(addr, clear, set) \
+	iowrite16le((ioread16le(addr) & ~(clear)) | (set), (addr))
+#define clrsetbits_8(addr, clear, set) \
+	iowrite8((ioread8(addr) & ~(clear)) | (set), (addr))
+
 /*
  *  IO port access primitives
  *  -------------------------
arch/arm/include/asm/irq.h +2 -0
index 53c15de..4358904 100644
@@ -30,6 +30,8 @@ extern void asm_do_IRQ(unsigned int, struct pt_regs *);
 void handle_IRQ(unsigned int, struct pt_regs *);
 void init_IRQ(void);
 
+extern irq_hw_number_t virq_to_hw(unsigned int virq);
+
 #ifdef CONFIG_MULTI_IRQ_HANDLER
 extern void (*handle_arch_irq)(struct pt_regs *);
 extern void set_handle_irq(void (*handle_irq)(struct pt_regs *));
arch/arm/kernel/irq.c +7 -0
index 9723d17..afa204a 100644
@@ -121,6 +121,13 @@ void __init init_IRQ(void)
 		machine_desc->init_irq();
 }
 
+irq_hw_number_t virq_to_hw(unsigned int virq)
+{
+	struct irq_data *irq_data = irq_get_irq_data(virq);
+	return WARN_ON(!irq_data) ? 0 : irq_data->hwirq;
+}
+EXPORT_SYMBOL_GPL(virq_to_hw);
+
 #ifdef CONFIG_MULTI_IRQ_HANDLER
 void __init set_handle_irq(void (*handle_irq)(struct pt_regs *))
 {
drivers/soc/qe/Kconfig +0 -1
index 49118e1..43b984b 100644
@@ -4,7 +4,6 @@
 
 config QUICC_ENGINE
 	bool "Freescale QUICC Engine (QE) Support"
-	depends on FSL_SOC && (PPC32 || PPC64)
 	select LIB_RHEAP
 	select CRC32
 	---help---
drivers/soc/qe/qe.c +31 -32

146 lines not on this page · raw message

drivers/soc/qe/qe_common.c +1 -1
index e7fdd02..1c7afbb 100644
@@ -68,7 +68,7 @@ int qe_muram_init(void)
 		}
 	}
 
-	muram_pbase = of_translate_address(np, zero);
+	muram_pbase = (phys_addr_t)of_translate_address(np, zero);
 	if (muram_pbase == (phys_addr_t)OF_BAD_ADDR) {
 		pr_err("Cannot translate zero through CPM muram node");
 		ret = -ENODEV;
drivers/soc/qe/qe_ic.c +5 -2
index 1968f22..cc1b8d5 100644
@@ -16,7 +16,10 @@
 
 #include <linux/kernel.h>
 #include <linux/init.h>
+#include <linux/irqdomain.h>
 #include <linux/errno.h>
+#include <linux/of_address.h>
+#include <linux/of_irq.h>
 #include <linux/reboot.h>
 #include <linux/slab.h>
 #include <linux/stddef.h>
@@ -177,13 +180,13 @@ static struct qe_ic_info qe_ic_info[] = {
 
 static inline u32 qe_ic_read(__be32  __iomem *base, unsigned int reg)
 {
-	return in_be32(base + (reg >> 2));
+	return ioread32be(base + (reg >> 2));
 }
 
 static inline void qe_ic_write(__be32  __iomem *base, unsigned int reg,
 			       u32 value)
 {
-	out_be32(base + (reg >> 2), value);
+	iowrite32be(value, base + (reg >> 2));
 }
 
 static inline struct qe_ic *qe_ic_from_irq(unsigned int virq)
drivers/soc/qe/qe_io.c +24 -29

110 lines not on this page · raw message

drivers/soc/qe/ucc_slow.c +20 -20
index d023f19..edb1b2e 100644
@@ -46,7 +46,7 @@ EXPORT_SYMBOL(ucc_slow_get_qe_cr_subblock);
 
 void ucc_slow_poll_transmitter_now(struct ucc_slow_private *uccs)
 {
-	out_be16(&uccs->us_regs->utodr, UCC_SLOW_TOD);
+	iowrite16be(UCC_SLOW_TOD, &uccs->us_regs->utodr);
 }
 
 void ucc_slow_graceful_stop_tx(struct ucc_slow_private *uccs)
@@ -88,7 +88,7 @@ void ucc_slow_enable(struct ucc_slow_private *uccs, enum comm_dir mode)
 	us_regs = uccs->us_regs;
 
 	/* Enable reception and/or transmission on this UCC. */
-	gumr_l = in_be32(&us_regs->gumr_l);
+	gumr_l = ioread32be(&us_regs->gumr_l);
 	if (mode & COMM_DIR_TX) {
 		gumr_l |= UCC_SLOW_GUMR_L_ENT;
 		uccs->enabled_tx = 1;
@@ -97,7 +97,7 @@ void ucc_slow_enable(struct ucc_slow_private *uccs, enum comm_dir mode)
 		gumr_l |= UCC_SLOW_GUMR_L_ENR;
 		uccs->enabled_rx = 1;
 	}
-	out_be32(&us_regs->gumr_l, gumr_l);
+	iowrite32be(gumr_l, &us_regs->gumr_l);
 }
 EXPORT_SYMBOL(ucc_slow_enable);
 
@@ -109,7 +109,7 @@ void ucc_slow_disable(struct ucc_slow_private *uccs, enum comm_dir mode)
 	us_regs = uccs->us_regs;
 
 	/* Disable reception and/or transmission on this UCC. */
-	gumr_l = in_be32(&us_regs->gumr_l);
+	gumr_l = ioread32be(&us_regs->gumr_l);
 	if (mode & COMM_DIR_TX) {
 		gumr_l &= ~UCC_SLOW_GUMR_L_ENT;
 		uccs->enabled_tx = 0;
@@ -118,7 +118,7 @@ void ucc_slow_disable(struct ucc_slow_private *uccs, enum comm_dir mode)
 		gumr_l &= ~UCC_SLOW_GUMR_L_ENR;
 		uccs->enabled_rx = 0;
 	}
-	out_be32(&us_regs->gumr_l, gumr_l);
+	iowrite32be(gumr_l, &us_regs->gumr_l);
 }
 EXPORT_SYMBOL(ucc_slow_disable);
 
@@ -209,7 +209,7 @@ int ucc_slow_init(struct ucc_slow_info *us_info,
 		return ret;
 	}
 
-	out_be16(&uccs->us_pram->mrblr, us_info->max_rx_buf_length);
+	iowrite16be(us_info->max_rx_buf_length, &uccs->us_pram->mrblr);
 
 	INIT_LIST_HEAD(&uccs->confQ);
 
@@ -239,27 +239,27 @@ int ucc_slow_init(struct ucc_slow_info *us_info,
 	bd = uccs->confBd = uccs->tx_bd = qe_muram_addr(uccs->tx_base_offset);
 	for (i = 0; i < us_info->tx_bd_ring_len - 1; i++) {
 		/* clear bd buffer */
-		out_be32(&bd->buf, 0);
+		iowrite32be(0, &bd->buf);
 		/* set bd status and length */
-		out_be32((u32 *) bd, 0);
+		iowrite32be(0, (u32 *) bd);
 		bd++;
 	}
 	/* for last BD set Wrap bit */
-	out_be32(&bd->buf, 0);
-	out_be32((u32 *) bd, cpu_to_be32(T_W));
+	iowrite32be(0, &bd->buf);
+	iowrite32be(T_W, (u32 *) bd);
 
 	/* Init Rx bds */
 	bd = uccs->rx_bd = qe_muram_addr(uccs->rx_base_offset);
 	for (i = 0; i < us_info->rx_bd_ring_len - 1; i++) {
 		/* set bd status and length */
-		out_be32((u32 *)bd, 0);
+		iowrite32be(0, (u32 *)bd);
 		/* clear bd buffer */
-		out_be32(&bd->buf, 0);
+		iowrite32be(0, &bd->buf);
 		bd++;
 	}
 	/* for last BD set Wrap bit */
-	out_be32((u32 *)bd, cpu_to_be32(R_W));
-	out_be32(&bd->buf, 0);
+	iowrite32be(R_W, (u32 *)bd);
+	iowrite32be(0, &bd->buf);
 
 	/* Set GUMR (For more details see the hardware spec.). */
 	/* gumr_h */
@@ -280,7 +280,7 @@ int ucc_slow_init(struct ucc_slow_info *us_info,
 		gumr |= UCC_SLOW_GUMR_H_TXSY;
 	if (us_info->rtsm)
 		gumr |= UCC_SLOW_GUMR_H_RTSM;
-	out_be32(&us_regs->gumr_h, gumr);
+	iowrite32be(gumr, &us_regs->gumr_h);
 
 	/* gumr_l */
 	gumr = us_info->tdcr | us_info->rdcr | us_info->tenc | us_info->renc |
@@ -293,7 +293,7 @@ int ucc_slow_init(struct ucc_slow_info *us_info,
 		gumr |= UCC_SLOW_GUMR_L_TINV;
 	if (us_info->tend)
 		gumr |= UCC_SLOW_GUMR_L_TEND;
-	out_be32(&us_regs->gumr_l, gumr);
+	iowrite32be(gumr, &us_regs->gumr_l);
 
 	/* Function code registers */
 
@@ -303,8 +303,8 @@ int ucc_slow_init(struct ucc_slow_info *us_info,
 	uccs->us_pram->rbmr = UCC_BMR_BO_BE;
 
 	/* rbase, tbase are offsets from MURAM base */
-	out_be16(&uccs->us_pram->rbase, uccs->rx_base_offset);
-	out_be16(&uccs->us_pram->tbase, uccs->tx_base_offset);
+	iowrite16be(uccs->rx_base_offset, &uccs->us_pram->rbase);
+	iowrite16be(uccs->tx_base_offset, &uccs->us_pram->tbase);
 
 	/* Mux clocking */
 	/* Grant Support */
@@ -334,14 +334,14 @@ int ucc_slow_init(struct ucc_slow_info *us_info,
 	}
 
 	/* Set interrupt mask register at UCC level. */
-	out_be16(&us_regs->uccm, us_info->uccm_mask);
+	iowrite16be(us_info->uccm_mask, &us_regs->uccm);
 
 	/* First, clear anything pending at UCC level,
 	 * otherwise, old garbage may come through
 	 * as soon as the dam is opened. */
 
 	/* Writing '1' clears */
-	out_be16(&us_regs->ucce, 0xffff);
+	iowrite16be(0xffff, &us_regs->ucce);
 
 	/* Issue QE Init command */
 	if (us_info->init_tx && us_info->init_rx)
drivers/tty/serial/ucc_uart.c +90 -86

386 lines not on this page · raw message

include/linux/fsl/qe.h +21 -0
index 5a6a647..ef4422c 100644
@@ -306,6 +306,27 @@ struct qe_bd {
 #define BD_STATUS_MASK	0xffff0000
 #define BD_LENGTH_MASK	0x0000ffff
 
+/* Buffer descriptor control/status used by serial
+ */
+
+#define BD_SC_EMPTY	(0x8000)	/* Receive is empty */
+#define BD_SC_READY	(0x8000)	/* Transmit is ready */
+#define BD_SC_WRAP	(0x2000)	/* Last buffer descriptor */
+#define BD_SC_INTRPT	(0x1000)	/* Interrupt on change */
+#define BD_SC_LAST	(0x0800)	/* Last buffer in frame */
+#define BD_SC_TC	(0x0400)	/* Transmit CRC */
+#define BD_SC_CM	(0x0200)	/* Continuous mode */
+#define BD_SC_ID	(0x0100)	/* Rec'd too many idles */
+#define BD_SC_P		(0x0100)	/* xmt preamble */
+#define BD_SC_BR	(0x0020)	/* Break received */
+#define BD_SC_FR	(0x0010)	/* Framing error */
+#define BD_SC_PR	(0x0008)	/* Parity error */
+#define BD_SC_NAK	(0x0004)	/* NAK - did not respond */
+#define BD_SC_OV	(0x0002)	/* Overrun */
+#define BD_SC_UN	(0x0002)	/* Underrun */
+#define BD_SC_CD	(0x0001)	/* */
+#define BD_SC_CL	(0x0001)	/* Collision */
+
 /* Alignment */
 #define QE_INTR_TABLE_ALIGN	16	/* ??? */
 #define QE_ALIGNMENT_OF_BD	8
Signature · 1 line
2.1.0.27.g96db324
#1 lore raw

PATCH 1/3 qe-uart: modify qe-uart to adapt both powerpc and arm

Quoted 6 lines · Zhao Qiang

qe has been supported by arm board ls1021, qe-uart need to be supported by ls1021.
modify the code to make qe-uart can work on both powerpc and ls1021.

Quoted 14 lines
---
 arch/arm/include/asm/delay.h  |  16 ++++
 arch/arm/include/asm/io.h     |  28 +++++++
 arch/arm/include/asm/irq.h    |   2 +
 arch/arm/kernel/irq.c         |   7 ++
 drivers/soc/qe/Kconfig        |   1 -
 drivers/soc/qe/qe.c           |  63 ++++++++-------
 drivers/soc/qe/qe_common.c    |   2 +-
 drivers/soc/qe/qe_ic.c        |   7 +-
 drivers/soc/qe/qe_io.c        |  53 ++++++-------
 drivers/soc/qe/ucc_slow.c     |  40 +++++-----
 drivers/tty/serial/ucc_uart.c | 176 +++++++++++++++++++++---------------------
 include/linux/fsl/qe.h        |  21 +++++
 12 files changed, 245 insertions(+), 171 deletions(-)

This patch obviously depends on the patches to relocate QE support, but there's no mention of that dependency above.

There are many changes in here that ought to be separate patches with separate justification.

Also, some of the QE changes seem to be reasonable cleanup, but not related to making the code work on ARM.

Quoted 9 lines
arch/arm/include/asm/delay.h +1 -0
index dff714d..a932f99 100644
@@ -57,6 +57,22 @@ extern void __bad_udelay(void);
 			__const_udelay((n) * UDELAY_MULT)) :		\
 	  __udelay(n))
 
+#define spin_event_timeout(condition, timeout, delay)                          \

arch/arm/include/asm/delay.h extern void __bad_udelay(void); · line 70

Quoted 10 lines
arch/arm/include/asm/delay.h +10 -0
+({                                                                             \
+	typeof(condition) __ret;                                               \
+	int i = 0;							       \
+	while (!(__ret = (condition)) && (i++ < timeout)) {		       \
+		if (delay)                                                     \
+			udelay(delay);                                         \
+		else                                                           \
+			cpu_relax();					       \
+		udelay(1);						       \
+	}								       \

This will delay too long if "delay" is used.

How about:

	delay = delay ? delay : 1;			\
	while (!(__ret = (condition))) {		\
		if (i < timeout)			\
			break;				\
		i += delay;				\
		udelay(delay);				\
	}						\

Also, once the dependency on timebase is removed, how about making this generic rather than just PPC+ARM?

arch/arm/include/asm/delay.h extern void __bad_udelay(void); · line 73

Quoted 3 lines
arch/arm/include/asm/delay.h +3 -0
+	if (!__ret)                                                            \
+		__ret = (condition);                                           \
+	__ret;		                                                       \

Timur, do you remember why that final "if (!__ret) __ret = (condition);" is needed?

Quoted 12 lines
arch/arm/include/asm/delay.h +2 -0
+})
+
 /* Loop-based definitions for assembly code. */
 extern void __loop_delay(unsigned long loops);
 extern void __loop_udelay(unsigned long usecs);
arch/arm/include/asm/io.h +0 -0
index d070741..4bec694 100644
@@ -206,6 +206,34 @@ extern int pci_ioremap_io(unsigned int offset, phys_addr_t phys_addr);
 #endif
 #endif

arch/arm/include/asm/io.h extern int pci_ioremap_io(unsigned int offset, phys_addr_t phys_addr); · line 217

Quoted 10 lines
arch/arm/include/asm/io.h +9 -0
 
+/* access ports */
+#define setbits32(_addr, _v) iowrite32be(ioread32be(_addr) |  (_v), (_addr))
+#define clrbits32(_addr, _v) iowrite32be(ioread32be(_addr) & ~(_v), (_addr))
+
+#define setbits16(_addr, _v) iowrite16be(ioread16be(_addr) |  (_v), (_addr))
+#define clrbits16(_addr, _v) iowrite16be(ioread16be(_addr) & ~(_v), (_addr))
+
+#define setbits8(_addr, _v) iowrite8(ioread8(_addr) |  (_v), (_addr))
+#define clrbits8(_addr, _v) iowrite8(ioread8(_addr) & ~(_v), (_addr))

This should also be a separate patch, though I don't think implicit big endian is going to fly in arch/arm (it was a mistake in arch/powerpc). Rename to setbits_be32 etc as is used in U-Boot.

Quoted 39 lines
arch/arm/include/asm/io.h +18 -0
+/* Clear and set bits in one shot.  These macros can be used to clear and
+ * set multiple bits in a register using a single read-modify-write.  These
+ * macros can also be used to set a multiple-bit bit pattern using a mask,
+ * by specifying the mask in the 'clear' parameter and the new bit pattern
+ * in the 'set' parameter.
+ */
+
+#define clrsetbits_be32(addr, clear, set) \
+	iowrite32be((ioread32be(addr) & ~(clear)) | (set), (addr))
+#define clrsetbits_le32(addr, clear, set) \
+	iowrite32le((ioread32le(addr) & ~(clear)) | (set), (addr))
+#define clrsetbits_be16(addr, clear, set) \
+	iowrite16be((ioread16be(addr) & ~(clear)) | (set), (addr))
+#define clrsetbits_le16(addr, clear, set) \
+	iowrite16le((ioread16le(addr) & ~(clear)) | (set), (addr))
+#define clrsetbits_8(addr, clear, set) \
+	iowrite8((ioread8(addr) & ~(clear)) | (set), (addr))
+
 /*
  *  IO port access primitives
  *  -------------------------
arch/arm/include/asm/irq.h +2 -0
index 53c15de..4358904 100644
@@ -30,6 +30,8 @@ extern void asm_do_IRQ(unsigned int, struct pt_regs *);
 void handle_IRQ(unsigned int, struct pt_regs *);
 void init_IRQ(void);
 
+extern irq_hw_number_t virq_to_hw(unsigned int virq);
+
 #ifdef CONFIG_MULTI_IRQ_HANDLER
 extern void (*handle_arch_irq)(struct pt_regs *);
 extern void set_handle_irq(void (*handle_irq)(struct pt_regs *));
arch/arm/kernel/irq.c +0 -0
index 9723d17..afa204a 100644

arch/arm/kernel/irq.c void __init init_IRQ(void) · line 129

Quoted 9 lines
arch/arm/kernel/irq.c +6 -0
@@ -121,6 +121,13 @@ void __init init_IRQ(void)
 		machine_desc->init_irq();
 }
 
+irq_hw_number_t virq_to_hw(unsigned int virq)
+{
+	struct irq_data *irq_data = irq_get_irq_data(virq);
+	return WARN_ON(!irq_data) ? 0 : irq_data->hwirq;
+}
+EXPORT_SYMBOL_GPL(virq_to_hw);

Can this be moved to generic code? Or just open-coded in the caller?

drivers/soc/qe/Kconfig line 7

Quoted 12 lines
arch/arm/kernel/irq.c +0 -0
 #ifdef CONFIG_MULTI_IRQ_HANDLER
 void __init set_handle_irq(void (*handle_irq)(struct pt_regs *))
 {
drivers/soc/qe/Kconfig +0 -1
index 49118e1..43b984b 100644
@@ -4,7 +4,6 @@
 
 config QUICC_ENGINE
 	bool "Freescale QUICC Engine (QE) Support"
-	depends on FSL_SOC && (PPC32 || PPC64)

Are you sure there are no build dependencies? What about OF?

Quoted 18 lines
include/linux/fsl/qe.h +10 -0
index 5a6a647..ef4422c 100644
@@ -306,6 +306,27 @@ struct qe_bd {
 #define BD_STATUS_MASK	0xffff0000
 #define BD_LENGTH_MASK	0x0000ffff
 
+/* Buffer descriptor control/status used by serial
+ */
+
+#define BD_SC_EMPTY	(0x8000)	/* Receive is empty */
+#define BD_SC_READY	(0x8000)	/* Transmit is ready */
+#define BD_SC_WRAP	(0x2000)	/* Last buffer descriptor */
+#define BD_SC_INTRPT	(0x1000)	/* Interrupt on change */
+#define BD_SC_LAST	(0x0800)	/* Last buffer in frame */
+#define BD_SC_TC	(0x0400)	/* Transmit CRC */
+#define BD_SC_CM	(0x0200)	/* Continuous mode */

include/linux/fsl/qe.h struct qe_bd { · line 328

Quoted 10 lines
include/linux/fsl/qe.h +10 -0
+#define BD_SC_ID	(0x0100)	/* Rec'd too many idles */
+#define BD_SC_P		(0x0100)	/* xmt preamble */
+#define BD_SC_BR	(0x0020)	/* Break received */
+#define BD_SC_FR	(0x0010)	/* Framing error */
+#define BD_SC_PR	(0x0008)	/* Parity error */
+#define BD_SC_NAK	(0x0004)	/* NAK - did not respond */
+#define BD_SC_OV	(0x0002)	/* Overrun */
+#define BD_SC_UN	(0x0002)	/* Underrun */
+#define BD_SC_CD	(0x0001)	/* */
+#define BD_SC_CL	(0x0001)	/* Collision */

Please move this rather than copying it.

-Scott

#2 lore raw

PATCH 1/3 qe-uart: modify qe-uart to adapt both powerpc and arm

Quoted 5 lines · Scott Wood

There are many changes in here that ought to be separate patches with separate justification.

Also, some of the QE changes seem to be reasonable cleanup, but not related to making the code work on ARM.

I agree with Scott. This patch already makes significant code changes, so you should have one patch that just makes the out_be32->iowrite32be changes. Changes to the QE library should NOT be in the same patch as changes to ucc_uart.c.

In addition, changes like this:

-       iprop = of_get_property(np, "port-number", NULL);
-       if (!iprop) {
+       ret = of_property_read_u32_index(np, "port-number", 0, &val);
+       if (ret) {

should be changed to remove the OF dependency. If you're going to replace of_get_property, replace it with device_property_read_u32(), to remove the OF dependency.

Quoted 8 lines
Quoted 8 lines
arch/arm/include/asm/delay.h +0 -0
index dff714d..a932f99 100644
@@ -57,6 +57,22 @@ extern void __bad_udelay(void);
                      __const_udelay((n) * UDELAY_MULT)) :            \
        __udelay(n))
 
Quoted 13 lines

arch/arm/include/asm/delay.h extern void __bad_udelay(void); · line 70

Quoted 11 lines
arch/arm/include/asm/delay.h +11 -0
+#define spin_event_timeout(condition, timeout, delay)                          \
+({                                                                             \
+     typeof(condition) __ret;                                               \
+     int i = 0;                                                             \
+     while (!(__ret = (condition)) && (i++ < timeout)) {                    \
+             if (delay)                                                     \
+                     udelay(delay);                                         \
+             else                                                           \
+                     cpu_relax();                                           \
+             udelay(1);                                                     \
+     }                                                                      \

This will delay too long if "delay" is used.

Shouldn't ARM have a version of tb_ticks_since() by now?

Quoted 6 lines

arch/arm/include/asm/delay.h extern void __bad_udelay(void); · line 73

Quoted 3 lines
arch/arm/include/asm/delay.h +3 -0
+     if (!__ret)                                                            \
+             __ret = (condition);                                           \
+     __ret;                                                                 \

Timur, do you remember why that final "if (!__ret) __ret = (condition);" is needed?

powerpc: Fix spin_event_timeout() to be robust over context switches

Current implementation of spin_event_timeout can be interrupted by an IRQ or context switch after testing the condition, but before checking the timeout. This can cause the loop to report a timeout when the condition actually became true in the middle.

This patch adds one final check of the condition upon exit of the loop if the last test of the condition was still false.

#3 lore raw

PATCH 1/3 qe-uart: modify qe-uart to adapt both powerpc and arm

Quoted 45 lines · Timur Tabi
Quoted 5 lines · Scott Wood

There are many changes in here that ought to be separate patches with separate justification.

Also, some of the QE changes seem to be reasonable cleanup, but not related to making the code work on ARM.

I agree with Scott. This patch already makes significant code changes, so you should have one patch that just makes the out_be32->iowrite32be changes. Changes to the QE library should NOT be in the same patch as changes to ucc_uart.c.

In addition, changes like this:

drivers/tty/serial/ucc_uart.c +2 -2
-       iprop = of_get_property(np, "port-number", NULL);
-       if (!iprop) {
+       ret = of_property_read_u32_index(np, "port-number", 0, &val);
+       if (ret) {

should be changed to remove the OF dependency. If you're going to replace of_get_property, replace it with device_property_read_u32(), to remove the OF dependency.

Quoted 8 lines
Quoted 8 lines
arch/arm/include/asm/delay.h +0 -0
index dff714d..a932f99 100644
@@ -57,6 +57,22 @@ extern void __bad_udelay(void);
                      __const_udelay((n) * UDELAY_MULT)) :            \
        __udelay(n))
 
Quoted 13 lines

arch/arm/include/asm/delay.h extern void __bad_udelay(void); · line 70

Quoted 11 lines
arch/arm/include/asm/delay.h +11 -0
+#define spin_event_timeout(condition, timeout, delay)                          \
+({                                                                             \
+     typeof(condition) __ret;                                               \
+     int i = 0;                                                             \
+     while (!(__ret = (condition)) && (i++ < timeout)) {                    \
+             if (delay)                                                     \
+                     udelay(delay);                                         \
+             else                                                           \
+                     cpu_relax();                                           \
+             udelay(1);                                                     \
+     }                                                                      \

This will delay too long if "delay" is used.

Quoted 1 line

Shouldn't ARM have a version of tb_ticks_since() by now?

There's get_cycles(), but it's not clear to me whether loops_per_jiffy is OK to use with get_cycles() on 32-bit ARM. Is avoiding the udelay worth making this non-generic?

Quoted 10 lines
Quoted 7 lines

arch/arm/include/asm/delay.h extern void __bad_udelay(void); · line 73

Quoted 4 lines
arch/arm/include/asm/delay.h +3 -0
+     if (!__ret)                                                            \
+             __ret = (condition);                                           \
+     __ret;                                                                 \

Timur, do you remember why that final "if (!__ret) __ret = (condition);" is needed?

powerpc: Fix spin_event_timeout() to be robust over context switches

Quoted 7 lines

Current implementation of spin_event_timeout can be interrupted by an IRQ or context switch after testing the condition, but before checking the timeout. This can cause the loop to report a timeout when the condition actually became true in the middle.

This patch adds one final check of the condition upon exit of the loop if the last test of the condition was still false.

OK, so this shouldn't be needed in the udelay version, since an interrupt shouldn't cause a significant difference in the timeout count.

-Scott