Skip to contentSkip to conversation

ucc_uart: add support for Freescale QUICCEngine UART

PATCH Timur Tabi 4 participants 12 messages Dec 4, 2007 – Dec 5, 2007 1 message not in the archive

Subsystems (2)
lore
Share & tools
lore

Timur Tabi

author
#0 lore raw

Add support for UART serial ports using a Freescale QUICC Engine (found on some MPC83xx and MPC85xx SOCs).

Because of a silicon bug in some QE-enabled SOCs (e.g. 8323 and 8360), a new microcode is required. This microcode implements UART via a work-around, hence it's called "Soft-UART". This driver can use QE firmware upload feature to upload the correct microcode to the QE.

---

This patch is for Kumar's for-2.6.25 branch, and it applies on top of my previous patches, "qe: add ability to upload QE firmware" and "qe: add function qe_clock_source()".

 arch/powerpc/boot/dts/mpc832x_mds.dts |   48 +
 arch/powerpc/sysdev/qe_lib/Kconfig    |    2 +-
 arch/powerpc/sysdev/qe_lib/ucc_slow.c |   10 +-
 drivers/serial/Kconfig                |   32 +
 drivers/serial/Makefile               |    1 +
 drivers/serial/ucc_uart.c             | 1586 +++++++++++++++++++++++++++++++++
 6 files changed, 1677 insertions(+), 2 deletions(-)
 create mode 100644 drivers/serial/ucc_uart.c
arch/powerpc/boot/dts/mpc832x_mds.dts +48 -0
index fe54489..a7605af 100644
@@ -7,6 +7,18 @@
  * under  the terms of  the GNU General  Public License as published by the
  * Free Software Foundation;  either version 2 of the  License, or (at your
  * option) any later version.
+
+ * To enable external serial I/O on a Freescale MPC 8323 SYS/MDS board, do
+ * this:
+ *
+ * 1) On chip U61, lift (disconnect) pins 21 (TXD) and 22 (RXD) from the board.
+ * 2) Solder a wire from U61-21 to P19A-23.  P19 is a grid of pins on the board
+ *    next to the serial ports.
+ * 3) Solder a wire from U61-22 to P19K-22.
+ *
+ * Note that there's a typo in the schematic.  The board labels the last column
+ * of pins "P19K", but in the schematic, that column is called "P19J".  So if
+ * you're going by the schematic, the pin is called "P19J-K22".
  */
 
 / {
@@ -159,6 +171,23 @@
 					1 1e  1  0  1  0 	/* TX_EN */
 					1 1f  2  0  1  0>;/* CRS */
 			};
+			pio5: ucc_pin@05 {
+				pio-map = <
+				/*
+				 *    		      open       has
+				 *   port  pin  dir  drain  sel  irq
+				 */
+					2    0    1      0    2    0  /* TxD5 */
+					2    8    2      0    2    0  /* RxD5 */
+
+					2   1d    2      0    0    0  /* CTS5 */
+					2   1f    1      0    2    0  /* RTS5 */
+
+					2   18    2      0    0    0  /* CD */
+
+				>;
+			};
+
 		};
 	};
 
@@ -250,6 +279,25 @@
 			pio-handle = < &pio4 >;
 		};
 
+		ucc@2400 {
+			device_type = "serial";
+			compatible = "ucc_uart";
+			model = "UCC";
+			device-id = <5>;	/* The UCC number, 1-7*/
+			port-number = <0>;	/* Which ttyQEx device */
+			reg = <2400 200>;
+			interrupts = <28>;	/* From Table 18-12 */
+			interrupt-parent = < &qeic >;
+			/*
+			 * For Soft-UART, we need to set TX to 1X, which
+			 * means specifying separate clock sources.
+			 */
+			rx-clock-name = "brg5";
+			tx-clock-name = "brg6";
+			pio-handle = < &pio5 >;
+		};
+
+
 		mdio@2320 {
 			#address-cells = <1>;
 			#size-cells = <0>;
arch/powerpc/sysdev/qe_lib/Kconfig +1 -1
index f611d34..adc6621 100644
@@ -4,7 +4,7 @@
 
 config UCC_SLOW
 	bool
-	default n
+	default y if SERIAL_QE
 	help
 	  This option provides qe_lib support to UCC slow
 	  protocols: UART, BISYNC, QMC
arch/powerpc/sysdev/qe_lib/ucc_slow.c +9 -1
index 0174b3a..b2870b2 100644
@@ -19,6 +19,7 @@
 #include <linux/stddef.h>
 #include <linux/interrupt.h>
 #include <linux/err.h>
+#include <linux/module.h>
 
 #include <asm/io.h>
 #include <asm/immap_qe.h>
@@ -41,6 +42,7 @@ u32 ucc_slow_get_qe_cr_subblock(int uccs_num)
 	default: return QE_CR_SUBBLOCK_INVALID;
 	}
 }
+EXPORT_SYMBOL(ucc_slow_get_qe_cr_subblock);
 
 void ucc_slow_poll_transmitter_now(struct ucc_slow_private * uccs)
 {
@@ -56,6 +58,7 @@ void ucc_slow_graceful_stop_tx(struct ucc_slow_private * uccs)
 	qe_issue_cmd(QE_GRACEFUL_STOP_TX, id,
 			 QE_CR_PROTOCOL_UNSPECIFIED, 0);
 }
+EXPORT_SYMBOL(ucc_slow_graceful_stop_tx);
 
 void ucc_slow_stop_tx(struct ucc_slow_private * uccs)
 {
@@ -65,6 +68,7 @@ void ucc_slow_stop_tx(struct ucc_slow_private * uccs)
 	id = ucc_slow_get_qe_cr_subblock(us_info->ucc_num);
 	qe_issue_cmd(QE_STOP_TX, id, QE_CR_PROTOCOL_UNSPECIFIED, 0);
 }
+EXPORT_SYMBOL(ucc_slow_stop_tx);
 
 void ucc_slow_restart_tx(struct ucc_slow_private * uccs)
 {
@@ -74,6 +78,7 @@ void ucc_slow_restart_tx(struct ucc_slow_private * uccs)
 	id = ucc_slow_get_qe_cr_subblock(us_info->ucc_num);
 	qe_issue_cmd(QE_RESTART_TX, id, QE_CR_PROTOCOL_UNSPECIFIED, 0);
 }
+EXPORT_SYMBOL(ucc_slow_restart_tx);
 
 void ucc_slow_enable(struct ucc_slow_private * uccs, enum comm_dir mode)
 {
@@ -94,6 +99,7 @@ void ucc_slow_enable(struct ucc_slow_private * uccs, enum comm_dir mode)
 	}
 	out_be32(&us_regs->gumr_l, gumr_l);
 }
+EXPORT_SYMBOL(ucc_slow_enable);
 
 void ucc_slow_disable(struct ucc_slow_private * uccs, enum comm_dir mode)
 {
@@ -114,6 +120,7 @@ void ucc_slow_disable(struct ucc_slow_private * uccs, enum comm_dir mode)
 	}
 	out_be32(&us_regs->gumr_l, gumr_l);
 }
+EXPORT_SYMBOL(ucc_slow_disable);
 
 /* Initialize the UCC for Slow operations
  *
@@ -347,6 +354,7 @@ int ucc_slow_init(struct ucc_slow_info * us_info, struct ucc_slow_private ** ucc
 	*uccs_ret = uccs;
 	return 0;
 }
+EXPORT_SYMBOL(ucc_slow_init);
 
 void ucc_slow_free(struct ucc_slow_private * uccs)
 {
@@ -366,5 +374,5 @@ void ucc_slow_free(struct ucc_slow_private * uccs)
 
 	kfree(uccs);
 }
-
+EXPORT_SYMBOL(ucc_slow_free);
 
drivers/serial/Kconfig +32 -0
index d7e1996..5087b58 100644
@@ -1284,4 +1284,36 @@ config SERIAL_OF_PLATFORM
 	  Currently, only 8250 compatible ports are supported, but
 	  others can easily be added.
 
+config SERIAL_QE
+	tristate "Freescale QUICC Engine serial port support"
+	depends on QUICC_ENGINE
+	select SERIAL_CORE
+	default n
+	help
+	  This driver supports the QE serial ports on Freescale embedded
+	  PowerPC that contain a QUICC Engine.
+
+config SERIAL_QE_SOFT_UART
+	bool "Use Soft-UART Mode"
+	depends on SERIAL_QE
+	default n
+	help
+	  Enable this option if you want to load and use a microcode that
+	  implements a "Soft-UART".  The Soft-UART emulates a UART using the
+	  QMC hardware.  It is necessary on older QE revisions that have broken
+	  UART hardware.  To access the Soft-UART microcode upload option,
+	  enable "Userspace firmware loading support".
+
+config SERIAL_QE_SOFT_UART_UPLOAD
+	bool "Upload Soft-UART microcode"
+	depends on SERIAL_QE_SOFT_UART && FW_LOADER
+	default SERIAL_QE_SOFT_UART
+	help
+	  Enable this option to have the driver upload request and upload
+	  the Soft-UART microcode upon initialization.  Otherwise, the driver
+	  will assume that the Soft-UART microcode has been uploaded by some
+	  other means, such as the boot loader.  The hotplug interface will be
+	  used to make the microcode available to the driver.  The driver will
+	  not allow any ports to be opened until the microcode is loaded.
+
 endmenu
drivers/serial/Makefile +1 -0
index af6377d..7eb4553 100644
@@ -64,3 +64,4 @@ obj-$(CONFIG_SERIAL_UARTLITE) += uartlite.o
 obj-$(CONFIG_SERIAL_NETX) += netx-serial.o
 obj-$(CONFIG_SERIAL_OF_PLATFORM) += of_serial.o
 obj-$(CONFIG_SERIAL_KS8695) += serial_ks8695.o
+obj-$(CONFIG_SERIAL_QE) += ucc_uart.o
drivers/serial/ucc_uart.c new file +1586 -0

1,586 lines not on this page · raw message

Signature · 1 line
1.5.2.4
#1 lore raw
Quoted 7 lines · Timur Tabi

Add support for UART serial ports using a Freescale QUICC Engine (found on some MPC83xx and MPC85xx SOCs).

Because of a silicon bug in some QE-enabled SOCs (e.g. 8323 and 8360), a new microcode is required. This microcode implements UART via a work-around, hence it's called "Soft-UART". This driver can use QE firmware upload feature to upload the correct microcode to the QE.

Can you use the driver on CPUs without this particular bug when it's built in Soft-UART mode?

Quoted 10 lines
drivers/serial/ucc_uart.c new file +10 -0
+
+#ifdef CONFIG_SERIAL_QE_SOFT_UART_UPLOAD
+#include <linux/firmware.h>
+#include <asm/reg.h>
+#endif
+
+#ifdef CONFIG_SERIAL_QE_SOFT_UART
+/*
+ * The GUMR flag for Soft UART.  This would normally be defined in qe.h,
+ * but Soft-UART is a hack and we want to keep everything related to it in

drivers/serial/ucc_uart.c line 49

Quoted 10 lines
drivers/serial/ucc_uart.c new file +10 -0
+ * this file.
+ */
+#define UCC_SLOW_GUMR_H_SUART   	0x00004000      /* Soft UART */
+
+/*
+ * firmware_loaded is 1 if the firmware has been loaded, 0 otherwise.
+ */
+#ifdef CONFIG_SERIAL_QE_SOFT_UART_UPLOAD
+static int firmware_loaded;
+#endif

Try to reduce the number of #ifdefs in your code. In particular, you should not do conditional #includes and #defines, as they often lead to subtle bugs.

Quoted 40 lines
drivers/serial/ucc_uart.c new file +40 -0
+struct ucc_uart_pram {
+	struct ucc_slow_pram common;
+	u8 res1[8];     	/* reserved */
+	__be16 maxidl;  	/* Maximum idle chars */
+	__be16 idlc;    	/* temp idle counter */
+	__be16 brkcr;   	/* Break count register */
+	__be16 parec;   	/* receive parity error counter */
+	__be16 frmec;   	/* receive framing error counter */
+	__be16 nosec;   	/* receive noise counter */
+	__be16 brkec;   	/* receive break condition counter */
+	__be16 brkln;   	/* last received break length */
+	__be16 uaddr[2];	/* UART address character 1 & 2 */
+	__be16 rtemp;   	/* Temp storage */
+	__be16 toseq;   	/* Transmit out of sequence char */
+	__be16 cchars[8];       /* control characters 1-8 */
+	__be16 rccm;    	/* receive control character mask */
+	__be16 rccr;    	/* receive control character register */
+	__be16 rlbc;    	/* receive last break character */
+	__be16 res2;    	/* reserved */
+	__be32 res3;    	/* reserved, should be cleared */
+	u8 res4;		/* reserved, should be cleared */
+	u8 res5[3];     	/* reserved, should be cleared */
+	__be32 res6;    	/* reserved, should be cleared */
+	__be32 res7;    	/* reserved, should be cleared */
+	__be32 res8;    	/* reserved, should be cleared */
+	__be32 res9;    	/* reserved, should be cleared */
+	__be32 res10;   	/* reserved, should be cleared */
+	__be32 res11;   	/* reserved, should be cleared */
+	__be32 res12;   	/* reserved, should be cleared */
+	__be32 res13;   	/* reserved, should be cleared */
+#ifdef CONFIG_SERIAL_QE_SOFT_UART
+	__be16 supsmr;  	/* 0x90, Shadow UPSMR */
+	__be16 res92;   	/* 0x92, reserved, initialize to 0 */
+	__be32 rx_state;	/* 0x94, RX state, initialize to 0 */
+	__be32 rx_cnt;  	/* 0x98, RX count, initialize to 0 */
+	u8 rx_length;   	/* 0x9C, Char length, set to 1+CL+PEN+1+SL */
+	u8 rx_bitmark;  	/* 0x9D, reserved, initialize to 0 */
+	u8 rx_temp_dlst_qe;     /* 0x9E, reserved, initialize to 0 */
+	u8 res14[0xBC - 0x9F];  /* reserved */
+	__be32 dump_ptr;	/* 0xBC, Dump pointer */

drivers/serial/ucc_uart.c line 132

Quoted 10 lines
drivers/serial/ucc_uart.c new file +10 -0
+	__be32 rx_frame_rem;    /* 0xC0, reserved, initialize to 0 */
+	u8 rx_frame_rem_size;   /* 0xC4, reserved, initialize to 0 */
+	u8 tx_mode;     	/* 0xC5, mode, 0=AHDLC, 1=UART */
+	u16 tx_state;   	/* 0xC6, TX state */
+	u8 res15[0xD0 - 0xC8];  /* reserved */
+	__be32 resD0;   	/* 0xD0, reserved, initialize to 0 */
+	u8 resD4;       	/* 0xD4, reserved, initialize to 0 */
+	__be16 resD5;   	/* 0xD5, reserved, initialize to 0 */
+#endif
+} __attribute__ ((packed));

The structure is perfectly packed even without your __attribute__ ((packed)), so you should leave out the attribute in order to get more efficient code accessing it.

drivers/serial/ucc_uart.c line 137

Quoted 5 lines
drivers/serial/ucc_uart.c new file +5 -0
+
+#ifdef DEBUG
+static void dump_ucc_uart_pram(struct ucc_uart_pram __iomem *uccup)
+{
+	unsigned int i;

Do you really need the debugging function like this in the code? Usually they are rather pointless once the code works, and will suffer from bitrot because nobody enables the code.

drivers/serial/ucc_uart.c line 234

Quoted 6 lines
drivers/serial/ucc_uart.c new file +6 -0
+
+#ifdef CONFIG_SERIAL_QE_SOFT_UART
+#define UCC_UART_SUPSMR_SL      	0x8000
+#define UCC_UART_SUPSMR_RPM_MASK	0x6000
+#define UCC_UART_SUPSMR_RPM_ODD 	0x0000
+#define UCC_UART_SUPSMR_RPM_LOW 	0x2000

again, the #ifdef should be left out if it can.

Quoted 4 lines

+ * Given the virtual address for a character buffer, this function returns
+ * the physical (DMA) equivalent.
+ */

drivers/serial/ucc_uart.c new file +1 -0
+static inline dma_addr_t cpu2qe_addr(void *addr, struct uart_qe_port *qe_port)

drivers/serial/ucc_uart.c line 317

Quoted 10 lines
drivers/serial/ucc_uart.c new file +10 -0
+{
+	if (likely((addr >= qe_port->bd_virt)) &&
+	    (addr < (qe_port->bd_virt + qe_port->bd_size)))
+		return qe_port->bd_phys + (addr - qe_port->bd_virt);
+
+	/* something nasty happened */
+	printk(KERN_ERR "%s: addr=%p\n", __FUNCTION__, addr);
+	BUG();
+	return 0;
+}

I'm guessing that you don't really mean dma_addr_t here, but rather phys_addr_t, which is something different.

drivers/serial/ucc_uart.c line 325

Quoted 8 lines
drivers/serial/ucc_uart.c new file +8 -0
+
+/*
+ * Physical to virtual address translation.
+ *
+ * Given the physical (DMA) address for a character buffer, this function
+ * returns the virtual equivalent.
+ */
+static inline void *qe2cpu_addr(dma_addr_t addr, struct uart_qe_port *qe_port)

same here.

	Arnd <><
author
#2 lore raw
Quoted 2 lines · Arnd Bergmann

Can you use the driver on CPUs without this particular bug when it's built in Soft-UART mode?

No, you have to build with Soft-UART mode turned off. Soft-UART mode actually uses the HMC mode of the QE and hacks it up to act like a UART.

The only way to know at runtime whether Soft-UART is required is to check the SOC model/revision and compare it to a list.

I could add code to check this list and enable Soft-UART if when there's a known CPU with the problem. However, I can't know whether I need to upload the microcode. I also have a U-Boot version of qe_upload_firmware(), so it's conceivable that U-Boot could have uploaded the microcode but I still need the Linux driver to use Soft-UART.

I also have no control over which Soft-UART microcodes are available. It's possible that some SOCs could have this bug but Freescale won't produce a microcode to fix it.

Quoted 2 lines

Try to reduce the number of #ifdefs in your code. In particular, you should not do conditional #includes and #defines, as they often lead to subtle bugs.

Ok, I can remove those #defines, but my main concern was to clearly isolate the Soft-UART code, since it is an ugly hack. I didn't want to mesh the Soft-UART code with the normal UART code. I don't know what more I could do to limit the number of #ifdefs.

Quoted 46 lines
Quoted 46 lines
drivers/serial/ucc_uart.c new file +46 -0
+struct ucc_uart_pram {
+	struct ucc_slow_pram common;
+	u8 res1[8];     	/* reserved */
+	__be16 maxidl;  	/* Maximum idle chars */
+	__be16 idlc;    	/* temp idle counter */
+	__be16 brkcr;   	/* Break count register */
+	__be16 parec;   	/* receive parity error counter */
+	__be16 frmec;   	/* receive framing error counter */
+	__be16 nosec;   	/* receive noise counter */
+	__be16 brkec;   	/* receive break condition counter */
+	__be16 brkln;   	/* last received break length */
+	__be16 uaddr[2];	/* UART address character 1 & 2 */
+	__be16 rtemp;   	/* Temp storage */
+	__be16 toseq;   	/* Transmit out of sequence char */
+	__be16 cchars[8];       /* control characters 1-8 */
+	__be16 rccm;    	/* receive control character mask */
+	__be16 rccr;    	/* receive control character register */
+	__be16 rlbc;    	/* receive last break character */
+	__be16 res2;    	/* reserved */
+	__be32 res3;    	/* reserved, should be cleared */
+	u8 res4;		/* reserved, should be cleared */
+	u8 res5[3];     	/* reserved, should be cleared */
+	__be32 res6;    	/* reserved, should be cleared */
+	__be32 res7;    	/* reserved, should be cleared */
+	__be32 res8;    	/* reserved, should be cleared */
+	__be32 res9;    	/* reserved, should be cleared */
+	__be32 res10;   	/* reserved, should be cleared */
+	__be32 res11;   	/* reserved, should be cleared */
+	__be32 res12;   	/* reserved, should be cleared */
+	__be32 res13;   	/* reserved, should be cleared */
+#ifdef CONFIG_SERIAL_QE_SOFT_UART
+	__be16 supsmr;  	/* 0x90, Shadow UPSMR */
+	__be16 res92;   	/* 0x92, reserved, initialize to 0 */
+	__be32 rx_state;	/* 0x94, RX state, initialize to 0 */
+	__be32 rx_cnt;  	/* 0x98, RX count, initialize to 0 */
+	u8 rx_length;   	/* 0x9C, Char length, set to 1+CL+PEN+1+SL */
+	u8 rx_bitmark;  	/* 0x9D, reserved, initialize to 0 */
+	u8 rx_temp_dlst_qe;     /* 0x9E, reserved, initialize to 0 */
+	u8 res14[0xBC - 0x9F];  /* reserved */
+	__be32 dump_ptr;	/* 0xBC, Dump pointer */
+	__be32 rx_frame_rem;    /* 0xC0, reserved, initialize to 0 */
+	u8 rx_frame_rem_size;   /* 0xC4, reserved, initialize to 0 */
+	u8 tx_mode;     	/* 0xC5, mode, 0=AHDLC, 1=UART */
+	u16 tx_state;   	/* 0xC6, TX state */
+	u8 res15[0xD0 - 0xC8];  /* reserved */
+	__be32 resD0;   	/* 0xD0, reserved, initialize to 0 */
Quoted 8 lines

drivers/serial/ucc_uart.c line 132

Quoted 4 lines
drivers/serial/ucc_uart.c new file +4 -0
+	u8 resD4;       	/* 0xD4, reserved, initialize to 0 */
+	__be16 resD5;   	/* 0xD5, reserved, initialize to 0 */
+#endif
+} __attribute__ ((packed));

The structure is perfectly packed even without your __attribute__ ((packed)), so you should leave out the attribute in order to get more efficient code accessing it.

If the structure is packed either way, why would the code differ? I don't see how the code would be more efficient if I removed "__attribute__ ((packed))". If gcc does something differently, that's news to me.

Quoted 3 lines

Do you really need the debugging function like this in the code? Usually they are rather pointless once the code works, and will suffer from bitrot because nobody enables the code.

Well, I'm hesitant to remove it because I have a feeling that if I do, the next day I'll want it.

Quoted 7 lines

drivers/serial/ucc_uart.c line 234

Quoted 5 lines
drivers/serial/ucc_uart.c new file +5 -0
+#ifdef CONFIG_SERIAL_QE_SOFT_UART
+#define UCC_UART_SUPSMR_SL      	0x8000
+#define UCC_UART_SUPSMR_RPM_MASK	0x6000
+#define UCC_UART_SUPSMR_RPM_ODD 	0x0000
+#define UCC_UART_SUPSMR_RPM_LOW 	0x2000

again, the #ifdef should be left out if it can.

Alright.

Quoted 10 lines
Quoted 10 lines

+ * Given the virtual address for a character buffer, this function returns
+ * the physical (DMA) equivalent.
+ */

drivers/serial/ucc_uart.c new file +6 -0
+static inline dma_addr_t cpu2qe_addr(void *addr, struct uart_qe_port *qe_port)
+{
+	if (likely((addr >= qe_port->bd_virt)) &&
+	    (addr < (qe_port->bd_virt + qe_port->bd_size)))
+		return qe_port->bd_phys + (addr - qe_port->bd_virt);
+
Quoted 8 lines

drivers/serial/ucc_uart.c line 317

Quoted 5 lines
drivers/serial/ucc_uart.c new file +5 -0
+	/* something nasty happened */
+	printk(KERN_ERR "%s: addr=%p\n", __FUNCTION__, addr);
+	BUG();
+	return 0;
+}

I'm guessing that you don't really mean dma_addr_t here, but rather phys_addr_t, which is something different.

Now that I think about it, I think I really mean unsigned, since the returned value is just an offset. I need to think about that.

Signature · 2 lines
Timur Tabi
Linux kernel developer at Freescale
author
#5 lore raw
In reply to Arnd Bergmann
Quoted 2 lines · Arnd Bergmann

I'm guessing that you don't really mean dma_addr_t here, but rather phys_addr_t, which is something different.

Now that I think about it, I don't know which is correct. The value is plugged into the pointer register of a buffer descriptor, and the QE performs a DMA-like memory transfer from that address into its local memory. I don't know if the QE is considered "external" enough that the address is a DMA address or a physical address.

When I program the DMA controller, I give it a dma_addr_t. And yet, the DMA controller and the QE are both devices on the SoC. So if the DMA controller takes a dma_addr_t, then shouldn't the QE also take one?

Signature · 2 lines
Timur Tabi
Linux kernel developer at Freescale
#6 lore raw
Quoted 1 line · Timur Tabi

When I program the DMA controller, I give it a dma_addr_t. =A0And yet, th=

e DMA=20

Quoted 1 line

controller and the QE are both devices on the SoC. =A0So if the DMA contr=

oller=20

Quoted 2 lines

takes a dma_addr_t, then shouldn't the QE also take one? =20

=46rom a code clarity perspective, the interesting point is that dma_addr_t=
is
what comes back from the functions in dma-mapping.h. If you don't use them, a physical address is phys_addr_t.

You can argue that the QS is really a DMA device, but in that case you should convert the driver to use the DMA mapping interfaces correctly, which I would consider overkill.

	Arnd <><
#7 lore raw
Quoted 7 lines · Arnd Bergmann

From a code clarity perspective, the interesting point is that dma_addr_t is what comes back from the functions in dma-mapping.h. If you don't use them, a physical address is phys_addr_t.

You can argue that the QS is really a DMA device, but in that case you should convert the driver to use the DMA mapping interfaces correctly, which I would consider overkill.

Why is it overkill?

-Scott

#8 lore raw
Quoted 7 lines · Scott Wood
Quoted 4 lines

You can argue that the QS is really a DMA device, but in that case you should convert the driver to use the DMA mapping interfaces correctly, which I would consider overkill.

Why is it overkill?

Well, if the QE can never be used with an IOMMU anyway, you don't lose any functionality by considering it a physical address instead of a DMA address.

The DMA mapping API is meant for the cases where physical and dma addresses can be different in the first place.

	Arnd <><
#9 lore raw
Quoted 8 lines · Arnd Bergmann
Quoted 5 lines · Scott Wood
Quoted 3 lines

You can argue that the QS is really a DMA device, but in that case you should convert the driver to use the DMA mapping interfaces correctly, which I would consider overkill.

Why is it overkill?

Well, if the QE can never be used with an IOMMU anyway,

I'm unconvinced that that will always be the case.

Quoted 1 line

The DMA mapping API is meant for the cases where physical and dma addresses can be different in the first place.

It's also used for noncoherent DMA; while it's unlikely Freescale will come out with a QE 8xx chip any time soon, there could be hardware bugs or performance considerations that make it desireable to treat it as non-coherent.

-Scott

author
#10 lore raw
In reply to Arnd Bergmann
Quoted 3 lines · Arnd Bergmann

You can argue that the QS is really a DMA device, but in that case you should convert the driver to use the DMA mapping interfaces correctly, which I would consider overkill.

I'm confused. I'm already calling dma_alloc_coherent() and getting a dma_addr_t back. Why do I need to use mapping functions to convert between virtual and physical/bus addresses?

Signature · 2 lines
Timur Tabi
Linux kernel developer at Freescale
#11 lore raw
Quoted 7 lines · Timur Tabi

Arnd Bergmann wrote:
=20

Quoted 3 lines

You can argue that the QS is really a DMA device, but in that case you should convert the driver to use the DMA mapping interfaces correctly, which I would consider overkill.

=20
I'm confused. =A0I'm already calling dma_alloc_coherent() and getting a d=

ma_addr_t=20

Quoted 1 line

back. =A0Why do I need to use mapping functions to convert between virtua=

l and=20

Quoted 1 line

physical/bus addresses?

No, I'm sorry but I'm the one who was confused. The problem I saw was that you return something offset from "bd_phys" as a dma_addr_t. This would be a lot easier if you had called it bd_bus or bd_dma instead of bd_phys, but your code looks absolutely correct upon closer inspection.

	Arnd <><
#12 lore raw
Quoted 10 lines · On Wed, 5 Dec 2007 00:56:39 +0100 Arnd Bergmann wrote:
Quoted 9 lines · Timur Tabi

Arnd Bergmann wrote:
=20

Quoted 3 lines

You can argue that the QS is really a DMA device, but in that case you should convert the driver to use the DMA mapping interfaces correctly, which I would consider overkill.

=20
I'm confused. =C2=A0I'm already calling dma_alloc_coherent() and getting a dma_addr_t back. =C2=A0Why do I need to use mapping functions to convert between virtual and physical/bus addresses?

Quoted 7 lines

=20
No, I'm sorry but I'm the one who was confused. The problem I saw was that you return something offset from "bd_phys" as a dma_addr_t. This would be a lot easier if you had called it bd_bus or bd_dma instead of bd_phys, but your code looks absolutely correct upon closer inspection.
=20

Adding my 2 cents, we already have very similar thing in cpm_uart driver...

Quoted 5 lines
	Arnd <><

_______________________________________________
Linuxppc-dev mailing list
[email protected]
https://ozlabs.org/mailman/listinfo/linuxppc-dev

--=20
Sincerely, Vitaly

author
#4 lore raw
In reply to a message not in the archive
Quoted 5 lines · Arnd Bergmann

In that case, I think the right solution would be to have different properties in the device tree, depending on whether or not you have a soft-uart and whether you need to download the microcode.
Having only a compile time option is very bad because it prevents you from using the driver on a multi-platform kernel.

I can see putting the option to need Soft-UART in the device, because this is an attribute of the hardware. The silicon is broken and UART functionality is provided via a secondary mechanism.

I'm not so crazy about an option to tell the driver to upload the firmware. So look at this:

		ucc@2400 {
			device_type = "serial";
			compatible = "ucc_uart";
			model = "UCC";
			device-id = <5>;	/* The UCC number, 1-7*/
			port-number = <0>;	/* Which ttyQEx device */
			soft-uart;		/* We need Soft-UART */
			upload-firmware;	/* Driver should upload FW */
			...

In a sense, this is just a message from U-Boot to the driver. It's not really an attribute of the hardware.

One thing I could do is create a new node under the QE node that describes any uploaded microcode. The nature of the QE microcode is that only one can be present at any time. So I could do this:

	qe@e0100000 {
		#address-cells = <1>;
		#size-cells = <1>;
		device_type = "qe";
		model = "QE";
		ranges = <0 e0100000 00100000>;
		...

		microcode@100 {	/* 100 is offset within I-RAM where the microcode was uploaded */
			name = "Soft-UART";
			extended_modes = <0 0>;
			vtraps = <0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0>;
		}

The extended_modes and vtraps are data that the driver needs any way (for Soft-UART, it's all zeros, but not for other microcodes). I currently don't have a way to pass this information from U-Boot to the kernel. The driver could then look for this node, and if it finds it, it would know *not* to try to upload the microcode itself. And it would also have the extended_modes and vtraps information that it might need.

This would solve your problem and mine.

Quoted 2 lines

gcc tries to use only aligned accesses, depending on the the target CPU, so you may end up accessing a member as bytes instead of words.

Would it do that even if the member were naturally aligned? I find that hard to believe, since the compiler always knows the alignment of its members.

OTOH, if this

Quoted 2 lines

structure is always in __iomem and you use in_be32() and the like, there is no problem at all.

I do. I generally only pack structures that are defined by external hardware, and this is one.

Signature · 2 lines
Timur Tabi
Linux kernel developer at Freescale