Skip to contentSkip to conversation

arch/ : Platform changes for UCC TDM driver for MPC8323ERDB.Also includes related QE changes.

PATCH In review Poonam_Aggrwal-b10812 5 participants 5 messages Dec 10, 2007 – Dec 17, 2007

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH 2/3 arch/ : Platform changes for UCC TDM driver for MPC8323ERDB.Also includes related QE changes.

From: Poonam Aggrwal <[email protected]>

This patch makes necessary changes in the QE and UCC framework to support TDM. It also adds support to configure the BRG properly through device tree entries. Includes the device tree changes for UCC TDM driver as well. It also includes device tree entries for UCC TDM driver.

Tested on MPC8323ERDB platform.

---
 arch/powerpc/boot/dts/mpc832x_rdb.dts |   58 +++++++
 arch/powerpc/sysdev/qe_lib/qe.c       |  128 ++++++++++++++--
 arch/powerpc/sysdev/qe_lib/ucc.c      |  265 +++++++++++++++++++++++++++++++++
 arch/powerpc/sysdev/qe_lib/ucc_fast.c |   37 +++++
 include/asm-powerpc/qe.h              |    8 +
 include/asm-powerpc/ucc.h             |    4 +
 include/asm-powerpc/ucc_fast.h        |    4 +
 7 files changed, 492 insertions(+), 12 deletions(-)
arch/powerpc/boot/dts/mpc832x_rdb.dts +58 -0
index 388c8a7..333408c 100644
@@ -105,6 +105,17 @@
 			device_type = "par_io";
 			num-ports = <7>;
 
+			ucc1pio:ucc_pin@01 {
+				pio-map = <
+			/* port  pin  dir  open_drain  assignment  has_irq */
+					0  e  2  0  1  0	/* CLK11 */
+					3 16  1  0  2  0	/* BRG9 */
+					3 1b  1  0  2  0	/* BRG3 */
+					0  0  3  0  2  0	/* TDMATxD0 */
+					0  4  3  0  2  0	/* TDMARxD0 */
+					3 1b  2  0  1  0>;	/* CLK1 */
+			};
+
 			ucc2pio:ucc_pin@02 {
 				pio-map = <
 			/* port  pin  dir  open_drain  assignment  has_irq */
@@ -169,6 +180,36 @@
 			};
 		};
 
+		clocks {
+			compatible = "fsl,cpm-clocks";
+			/* clock freqs in Hz(for CLK1~CLK24).
+			 * CLK11 is 1024KHz,
+			 * all other clocks unused
+			 * #clock-cells define number of cells
+			 * used by the clock-frequency.
+			 * right now only #clock cells=1 is
+			 * implemented. Provision is there to
+			 * handle frequencies >4Gig
+			 */
+			#clock-cells = <1>;
+			clock-frequency = <0 0 0 0 0 0
+					   0 0 0 0 d#1024000 0
+					   0 0 0 0 0 0
+					   0 0 0 0 0 0>;
+		};
+
+		brg@640 {
+			compatible = "fsl,cpm-brg";
+			/* input clock sources for all the 16 BRGs.
+			 * 1-24 for CLK1 to CLK24.
+			 * BRG9 uses CLK11,BRG1 and BRG2-8 use
+			 * the QE clock.
+			 */
+			fsl,brg-sources = <0 0 0 0 0 0 0 0
+					   b 0 0 0 0 0 0 0>;
+			reg = <640 7f>;
+		};
+
 		spi@4c0 {
 			device_type = "spi";
 			compatible = "fsl_spi";
@@ -187,6 +228,23 @@
 			mode = "cpu";
 		};
 
+		ucc@2000 {
+			device_type = "tdm";
+			compatible = "fsl,ucc-tdm";
+			model = "UCC";
+			device-id = <1>;
+			fsl,tdm-num = <1>;
+			fsl,si-num = <1>;
+			fsl,tdm-tx-clk = "CLK1";
+			fsl,tdm-rx-clk = "CLK1";
+			fsl,tdm-tx-sync = "BRG9";
+			fsl,tdm-rx-sync = "BRG9";
+			reg = <2000 200>;
+			interrupts = <20>;
+			interrupt-parent = <&qeic>;
+			pio-handle = <&ucc1pio>;
+		};
+
 		ucc@3000 {
 			device_type = "network";
 			compatible = "ucc_geth";
arch/powerpc/sysdev/qe_lib/qe.c +116 -12

157 lines not on this page · raw message

arch/powerpc/sysdev/qe_lib/ucc.c +265 -0

268 lines not on this page · raw message

arch/powerpc/sysdev/qe_lib/ucc_fast.c +37 -0
index 3223acb..9c8559f 100644
@@ -327,6 +327,43 @@ int ucc_fast_init(struct ucc_fast_info * uf_info, struct ucc_fast_private ** ucc
 			ucc_fast_free(uccf);
 			return -EINVAL;
 		}
+	} else {
+		/* TDM Rx clock routing */
+		if ((uf_info->tdm_rx_clk != NULL) &&
+			ucc_set_tdm_rxtx_clk(uf_info->ucc_num,
+				uf_info->tdm_rx_clk, COMM_DIR_RX)) {
+			printk(KERN_ERR "%s: illegal value for TDM RX clock",
+				__FUNCTION__);
+			ucc_fast_free(uccf);
+			return -EINVAL;
+		}
+		/* TDM Tx clock routing */
+		if ((uf_info->tdm_tx_clk != NULL) &&
+			ucc_set_tdm_rxtx_clk(uf_info->ucc_num,
+				uf_info->tdm_tx_clk, COMM_DIR_TX)) {
+			printk(KERN_ERR "%s: illegal value for TDM TX clock",
+				__FUNCTION__);
+			ucc_fast_free(uccf);
+			return -EINVAL;
+		}
+		/* TDM Rx sync routing */
+		if ((uf_info->tdm_rx_sync != NULL) &&
+			ucc_set_tdm_rxtx_sync(uf_info->ucc_num,
+				uf_info->tdm_rx_sync, COMM_DIR_RX)) {
+			printk(KERN_ERR "%s: illegal value for TDM RX"
+				"Frame sync", __FUNCTION__);
+			ucc_fast_free(uccf);
+			return -EINVAL;
+		}
+		/* TDM Tx sync routing */
+		if ((uf_info->tdm_tx_sync != NULL) &&
+			ucc_set_tdm_rxtx_sync(uf_info->ucc_num,
+				uf_info->tdm_tx_sync, COMM_DIR_TX)) {
+			printk(KERN_ERR "%s: illegal value for TDM TX"
+					"Frame sync", __FUNCTION__);
+			ucc_fast_free(uccf);
+			return -EINVAL;
+		}
 	}
 
 	/* Set interrupt mask register at UCC level. */
include/asm-powerpc/qe.h +8 -0
index bcf60be..51de236 100644
@@ -497,6 +497,14 @@ struct ucc_slow_pram {
 #define UCC_GETH_UCCE_RXF1      0x00000002
 #define UCC_GETH_UCCE_RXF0      0x00000001
 
+/* Transparent UCC Event Register (UCCE) */
+#define UCC_TRANS_UCCE_GRA	0x0080
+#define UCC_TRANS_UCCE_TXE	0x0010
+#define UCC_TRANS_UCCE_RXF	0x0008
+#define UCC_TRANS_UCCE_BSY	0x0004
+#define UCC_TRANS_UCCE_TXB	0x0002
+#define UCC_TRANS_UCCE_RXB	0x0001
+
 /* UPSMR, when used as a UART */
 #define UCC_UART_UPSMR_FLC		0x8000
 #define UCC_UART_UPSMR_SL		0x4000
include/asm-powerpc/ucc.h +4 -0
index 46b09ba..153db97 100644
@@ -42,6 +42,10 @@ int ucc_set_qe_mux_mii_mng(unsigned int ucc_num);
 int ucc_set_qe_mux_rxtx(unsigned int ucc_num, enum qe_clock clock,
 	enum comm_dir mode);
 
+int ucc_set_tdm_rxtx_clk(int tdm_num, char *clk_src, enum comm_dir mode);
+
+int ucc_set_tdm_rxtx_sync(int tdm_num, char *clk_src, enum comm_dir mode);
+
 int ucc_mux_set_grant_tsa_bkpt(unsigned int ucc_num, int set, u32 mask);
 
 /* QE MUX clock routing for UCC
include/asm-powerpc/ucc_fast.h +4 -0
index f529f70..d267983 100644
@@ -152,6 +152,10 @@ struct ucc_fast_info {
 	enum ucc_fast_rx_decoding_method renc;
 	enum ucc_fast_transparent_tcrc tcrc;
 	enum ucc_fast_sync_len synl;
+	char *tdm_rx_clk;
+	char *tdm_tx_clk;
+	char *tdm_rx_sync;
+	char *tdm_tx_sync;
 };
 
 struct ucc_fast_private {
Signature · 1 line
1.5.2.4
#1 lore raw

arch/powerpc/sysdev/qe_lib/qe.c EXPORT_SYMBOL(qe_issue_cmd); · line 184

Quoted 9 lines · Poonam_Aggrwal-b10812 wrote:
arch/powerpc/sysdev/qe_lib/qe.c +9 -0
+			qe = of_find_node_by_type(NULL, "qe");
+			if (qe) {
+				unsigned int size;
+				prop = of_get_property
+						(qe, "brg-frequency", &size);
+				of_node_put(qe);
+				of_node_put(brg);
+				return *prop;
+			}

Only very recent versions of U-Boot set the brg-frequency property, so you need to check for situations where "*prop" is 0. If it is, then you need to take the QE's bus-frequency property and divide it by two. See my ucc_uart driver for an example.

And PowerPC-specific patches should not be cross-posted to linux-kernel.

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

Thanx Tabi for your comments.
Sorry I was on leave for the last week, so could not reply in time.

Shall make the changes you suggested and repost the patch.

Regards
Poonam

Quoted 32 lines · Timur Tabi

arch/powerpc/sysdev/qe_lib/qe.c EXPORT_SYMBOL(qe_issue_cmd);

Quoted 5 lines · Poonam_Aggrwal-b10812 wrote:
arch/powerpc/sysdev/qe_lib/qe.c +5 -0
+                     qe = of_find_node_by_type(NULL, "qe");
+                     if (qe) {
+                             unsigned int size;
+                             prop = of_get_property
+                                             (qe, "brg-frequency",

&size);

arch/powerpc/sysdev/qe_lib/qe.c EXPORT_SYMBOL(qe_issue_cmd); · line 184

Quoted 4 lines
arch/powerpc/sysdev/qe_lib/qe.c +4 -0
+                             of_node_put(qe);
+                             of_node_put(brg);
+                             return *prop;
+                     }

Only very recent versions of U-Boot set the brg-frequency property, so you need
to check for situations where "*prop" is 0. If it is, then you need to take the
QE's bus-frequency property and divide it by two. See my ucc_uart driver for an
example.

And PowerPC-specific patches should not be cross-posted to linux-kernel.

--
Timur Tabi
Linux kernel developer at Freescale
_______________________________________________
Linuxppc-dev mailing list
[email protected]
https://ozlabs.org/mailman/listinfo/linuxppc-dev

#3 lore raw
In reply to Poonam_Aggrwal-b10812
Quoted 24 lines · On Mon, 10 Dec 2007 17:39:22 +0530 (IST) Poonam_Aggrwal-b10812…

+++ b/arch/powerpc/sysdev/qe_lib/qe.c

arch/powerpc/sysdev/qe_lib/qe.c +10 -6
@@ -149,22 +149,116 @@ EXPORT_SYMBOL(qe_issue_cmd);
  */
 static unsigned int brg_clk = 0;
 
-unsigned int get_brg_clk(void)
+u32 get_brg_clk(enum qe_clock brgclk, enum qe_clock *brg_source)
 {
-	struct device_node *qe;
-	if (brg_clk)
-		return brg_clk;
+	struct device_node *qe, *brg, *clocks;
+	enum qe_clock brg_src;
+	u32 brg_input_freq = 0;
+	u32 brg_num;
+	const unsigned int *prop;
 
-	qe = of_find_node_by_type(NULL, "qe");
-	if (qe) {
+	*brg_source = 0;
+
+	brg_num = brgclk - QE_BRG1;
+	brg = of_find_compatible_node(NULL, NULL, "fsl,cpm-brg");

arch/powerpc/sysdev/qe_lib/qe.c EXPORT_SYMBOL(qe_issue_cmd); · line 169

Quoted 10 lines
arch/powerpc/sysdev/qe_lib/qe.c +5 -4
+	if (brg) {
 		unsigned int size;
-		const u32 *prop = of_get_property(qe, "brg-frequency", &size);
-		brg_clk = *prop;
-		of_node_put(qe);
-	};
+		prop = of_get_property(brg,
+					"fsl,brg-sources", &size);
+
+		brg_src = *(prop + brg_num);

You should probably sanity check that prop is not NULL and points to something large enough.

You don't use brg after here, so the "of_node_put(brg)" could go here to save putting it in multiple places later. Also, currently there are paths through the following code that do not do the of_node_put(brg).

Quoted 4 lines
arch/powerpc/sysdev/qe_lib/qe.c +4 -0
+		if (brg_src == 0) {
+			*brg_source = 0;
+			if (brg_clk > 0) {
+				of_node_put(brg);

arch/powerpc/sysdev/qe_lib/qe.c EXPORT_SYMBOL(qe_issue_cmd); · line 183

Quoted 10 lines
arch/powerpc/sysdev/qe_lib/qe.c +10 -0
+				return brg_clk;
+			}
+			qe = of_find_node_by_type(NULL, "qe");
+			if (qe) {
+				unsigned int size;
+				prop = of_get_property
+						(qe, "brg-frequency", &size);
+				of_node_put(qe);
+				of_node_put(brg);
+				return *prop;

NULL check here (yes, I know that the old code didn't check).

arch/powerpc/sysdev/qe_lib/qe.c EXPORT_SYMBOL(qe_issue_cmd); · line 194

Quoted 11 lines
arch/powerpc/sysdev/qe_lib/qe.c +11 -0
+			}
+		} else {
+			*brg_source = brg_src + QE_CLK1 - 1;
+			clocks = of_find_compatible_node(NULL, NULL,
+							"fsl,cpm-clocks");
+			prop = of_get_property(clocks,
+						"#clock-cells", &size);
+			/*
+			 * clock-cells = 1 only supported right now.
+			 */
+			if (*prop != 1)

Again check for NULL (and possibly size).

arch/powerpc/sysdev/qe_lib/qe.c EXPORT_SYMBOL(qe_issue_cmd); · line 199

Quoted 5 lines
arch/powerpc/sysdev/qe_lib/qe.c +5 -0
+				return 0;
+			prop = of_get_property(clocks,
+						"clock-frequency", &size);
+
+			brg_input_freq = *(prop+(brg_src - 1));

And again.

Quoted 7 lines
arch/powerpc/sysdev/qe_lib/qe.c +5 -0
+			of_node_put(clocks);
+			of_node_put(brg);
+			return brg_input_freq;
+		}
+	}
 	return brg_clk;
 }
Signature · 3 lines
Cheers,
Stephen Rothwell                    [email protected]
http://www.canb.auug.org.au/~sfr/
#4 lore raw

Thanks Stephen for your comments.
I have gone through them.
Shall incorporate them and repost the patch.

Sorry for late reply as I was on leave for the last week.

With Regards
Poonam

-----Original Message-----
From: Stephen Rothwell [mailto:[email protected]]
Sent: Tuesday, December 11, 2007 5:49 AM
To: Aggrwal Poonam
Cc: [email protected]; [email protected]; [email protected]; Gala Kumar; [email protected]; Barkowski Michael; Cutler Richard; Kalra Ashish
Subject: Re: [PATCH 2/3] arch/ : Platform changes for UCC TDM driver for MPC8323ERDB.Also includes related QE changes.

Quoted 17 lines · On Mon, 10 Dec 2007 17:39:22 +0530 (IST) Poonam_Aggrwal-b10812…

+++ b/arch/powerpc/sysdev/qe_lib/qe.c

arch/powerpc/sysdev/qe_lib/qe.c +6 -4
@@ -149,22 +149,116 @@ EXPORT_SYMBOL(qe_issue_cmd);
  */
 static unsigned int brg_clk = 0;
 
-unsigned int get_brg_clk(void)
+u32 get_brg_clk(enum qe_clock brgclk, enum qe_clock *brg_source)
 {
-	struct device_node *qe;
-	if (brg_clk)
-		return brg_clk;
+	struct device_node *qe, *brg, *clocks;
+	enum qe_clock brg_src;
+	u32 brg_input_freq = 0;
+	u32 brg_num;
+	const unsigned int *prop;

arch/powerpc/sysdev/qe_lib/qe.c EXPORT_SYMBOL(qe_issue_cmd); · line 161

Quoted 10 lines
arch/powerpc/sysdev/qe_lib/qe.c +5 -3
 
-	qe = of_find_node_by_type(NULL, "qe");
-	if (qe) {
+	*brg_source = 0;
+
+	brg_num = brgclk - QE_BRG1;
+	brg = of_find_compatible_node(NULL, NULL, "fsl,cpm-brg");
+	if (brg) {
 		unsigned int size;
-		const u32 *prop = of_get_property(qe, "brg-frequency",

&size);

arch/powerpc/sysdev/qe_lib/qe.c EXPORT_SYMBOL(qe_issue_cmd); · line 169

Quoted 7 lines
arch/powerpc/sysdev/qe_lib/qe.c +4 -3
-		brg_clk = *prop;
-		of_node_put(qe);
-	};
+		prop = of_get_property(brg,
+					"fsl,brg-sources", &size);
+
+		brg_src = *(prop + brg_num);

You should probably sanity check that prop is not NULL and points to something large enough.

You don't use brg after here, so the "of_node_put(brg)" could go here to save putting it in multiple places later. Also, currently there are paths through the following code that do not do the of_node_put(brg).

arch/powerpc/sysdev/qe_lib/qe.c EXPORT_SYMBOL(qe_issue_cmd);

Quoted 11 lines
arch/powerpc/sysdev/qe_lib/qe.c +11 -0
+		if (brg_src == 0) {
+			*brg_source = 0;
+			if (brg_clk > 0) {
+				of_node_put(brg);
+				return brg_clk;
+			}
+			qe = of_find_node_by_type(NULL, "qe");
+			if (qe) {
+				unsigned int size;
+				prop = of_get_property
+						(qe, "brg-frequency",

&size);

arch/powerpc/sysdev/qe_lib/qe.c EXPORT_SYMBOL(qe_issue_cmd); · line 183

Quoted 3 lines
arch/powerpc/sysdev/qe_lib/qe.c +3 -0
+				of_node_put(qe);
+				of_node_put(brg);
+				return *prop;

NULL check here (yes, I know that the old code didn't check).

arch/powerpc/sysdev/qe_lib/qe.c EXPORT_SYMBOL(qe_issue_cmd); · line 198

Quoted 5 lines
arch/powerpc/sysdev/qe_lib/qe.c +5 -0
+			}
+		} else {
+			*brg_source = brg_src + QE_CLK1 - 1;
+			clocks = of_find_compatible_node(NULL, NULL,
+

"fsl,cpm-clocks");

arch/powerpc/sysdev/qe_lib/qe.c EXPORT_SYMBOL(qe_issue_cmd); · line 194

Quoted 6 lines
arch/powerpc/sysdev/qe_lib/qe.c +6 -0
+			prop = of_get_property(clocks,
+						"#clock-cells", &size);
+			/*
+			 * clock-cells = 1 only supported right now.
+			 */
+			if (*prop != 1)

Again check for NULL (and possibly size).

arch/powerpc/sysdev/qe_lib/qe.c EXPORT_SYMBOL(qe_issue_cmd);

Quoted 3 lines
arch/powerpc/sysdev/qe_lib/qe.c +3 -0
+				return 0;
+			prop = of_get_property(clocks,
+						"clock-frequency",

&size);

Review EXPORT_SYMBOL(qe_issue_cmd); · line 199

Quoted 2 lines
(quoted diff) +2 -0
+
+			brg_input_freq = *(prop+(brg_src - 1));

And again.

arch/powerpc/sysdev/qe_lib/qe.c EXPORT_SYMBOL(qe_issue_cmd); · line 206

Quoted 7 lines
arch/powerpc/sysdev/qe_lib/qe.c +5 -0
+			of_node_put(clocks);
+			of_node_put(brg);
+			return brg_input_freq;
+		}
+	}
 	return brg_clk;
 }

--
Cheers,
Stephen Rothwell [email protected]
http://www.canb.auug.org.au/~sfr/