[PATCH v2 4/5] fsl/qe: Add QE TDM lib

2016-06-01 Thread Zhao Qiang
QE has module to support TDM, some other protocols
supported by QE are based on TDM.
add a qe-tdm lib, this lib provides functions to the protocols
using TDM to configurate QE-TDM.

Signed-off-by: Zhao Qiang 
---
Changes for v2:
- delete dead code
- use strcmp instead of strcasecmp
- use of_find_compatible_node instead of of_find_by_name
- use devm_ioremap_resource 
- rename init_si to ucc_tdm_init
- rename of_parse_tdm to ucc_of_parse_tdm
- return err when there is not t1 or e1

 drivers/soc/fsl/qe/Kconfig|   6 +-
 drivers/soc/fsl/qe/Makefile   |   1 +
 drivers/soc/fsl/qe/qe_tdm.c   | 276 ++
 include/soc/fsl/qe/immap_qe.h |   5 +-
 include/soc/fsl/qe/qe_tdm.h   |  94 ++
 5 files changed, 377 insertions(+), 5 deletions(-)
 create mode 100644 drivers/soc/fsl/qe/qe_tdm.c
 create mode 100644 include/soc/fsl/qe/qe_tdm.h

diff --git a/drivers/soc/fsl/qe/Kconfig b/drivers/soc/fsl/qe/Kconfig
index 20978f2..73a2e08 100644
--- a/drivers/soc/fsl/qe/Kconfig
+++ b/drivers/soc/fsl/qe/Kconfig
@@ -22,7 +22,7 @@ config UCC_SLOW
 
 config UCC_FAST
bool
-   default y if UCC_GETH
+   default y if UCC_GETH || QE_TDM
help
  This option provides qe_lib support to UCC fast
  protocols: HDLC, Ethernet, ATM, transparent
@@ -31,6 +31,10 @@ config UCC
bool
default y if UCC_FAST || UCC_SLOW
 
+config QE_TDM
+   bool
+   default y if FSL_UCC_HDLC
+
 config QE_USB
bool
default y if USB_FSL_QE
diff --git a/drivers/soc/fsl/qe/Makefile b/drivers/soc/fsl/qe/Makefile
index ffac541..2031d38 100644
--- a/drivers/soc/fsl/qe/Makefile
+++ b/drivers/soc/fsl/qe/Makefile
@@ -6,5 +6,6 @@ obj-$(CONFIG_CPM)   += qe_common.o
 obj-$(CONFIG_UCC)  += ucc.o
 obj-$(CONFIG_UCC_SLOW) += ucc_slow.o
 obj-$(CONFIG_UCC_FAST) += ucc_fast.o
+obj-$(CONFIG_QE_TDM)   += qe_tdm.o
 obj-$(CONFIG_QE_USB)   += usb.o
 obj-$(CONFIG_QE_GPIO)  += gpio.o
diff --git a/drivers/soc/fsl/qe/qe_tdm.c b/drivers/soc/fsl/qe/qe_tdm.c
new file mode 100644
index 000..5e48b14
--- /dev/null
+++ b/drivers/soc/fsl/qe/qe_tdm.c
@@ -0,0 +1,276 @@
+/*
+ * Copyright (C) 2015 Freescale Semiconductor, Inc. All rights reserved.
+ *
+ * Authors:Zhao Qiang 
+ *
+ * Description:
+ * QE TDM API Set - TDM specific routines implementations.
+ *
+ * This program is free software; you can redistribute  it and/or modify it
+ * 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.
+ */
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+static int set_tdm_framer(const char *tdm_framer_type)
+{
+   if (strcmp(tdm_framer_type, "e1") == 0)
+   return TDM_FRAMER_E1;
+   else if (strcmp(tdm_framer_type, "t1") == 0)
+   return TDM_FRAMER_T1;
+   else
+   return -EINVAL;
+}
+
+static void set_si_param(struct ucc_tdm *utdm, struct ucc_tdm_info *ut_info)
+{
+   struct si_mode_info *si_info = _info->si_info;
+
+   if (utdm->tdm_mode == TDM_INTERNAL_LOOPBACK) {
+   si_info->simr_crt = 1;
+   si_info->simr_rfsd = 0;
+   }
+}
+
+int ucc_of_parse_tdm(struct device_node *np, struct ucc_tdm *utdm,
+struct ucc_tdm_info *ut_info)
+{
+   const char *sprop;
+   int ret = 0;
+   u32 val;
+   struct resource *res;
+   struct device_node *np2;
+   static int siram_init_flag;
+   struct platform_device *pdev;
+
+   sprop = of_get_property(np, "fsl,rx-sync-clock", NULL);
+   if (sprop) {
+   ut_info->uf_info.rx_sync = qe_clock_source(sprop);
+   if ((ut_info->uf_info.rx_sync < QE_CLK_NONE) ||
+   (ut_info->uf_info.rx_sync > QE_RSYNC_PIN)) {
+   pr_err("QE-TDM: Invalid rx-sync-clock property\n");
+   return -EINVAL;
+   }
+   } else {
+   pr_err("QE-TDM: Invalid rx-sync-clock property\n");
+   return -EINVAL;
+   }
+
+   sprop = of_get_property(np, "fsl,tx-sync-clock", NULL);
+   if (sprop) {
+   ut_info->uf_info.tx_sync = qe_clock_source(sprop);
+   if ((ut_info->uf_info.tx_sync < QE_CLK_NONE) ||
+   (ut_info->uf_info.tx_sync > QE_TSYNC_PIN)) {
+   pr_err("QE-TDM: Invalid tx-sync-clock property\n");
+   return -EINVAL;
+   }
+   } else {
+   pr_err("QE-TDM: Invalid tx-sync-clock property\n");
+   return -EINVAL;
+   }
+
+   ret = of_property_read_u32_index(np, "fsl,tx-timeslot-mask", 0, );
+   if (ret) {
+   pr_err("QE-TDM: Invalid tx-timeslot-mask property\n");
+   return -EINVAL;
+   }
+   utdm->tx_ts_mask = val;
+
+   ret = 

[PATCH v2 4/5] fsl/qe: Add QE TDM lib

2016-06-01 Thread Zhao Qiang
QE has module to support TDM, some other protocols
supported by QE are based on TDM.
add a qe-tdm lib, this lib provides functions to the protocols
using TDM to configurate QE-TDM.

Signed-off-by: Zhao Qiang 
---
Changes for v2:
- delete dead code
- use strcmp instead of strcasecmp
- use of_find_compatible_node instead of of_find_by_name
- use devm_ioremap_resource 
- rename init_si to ucc_tdm_init
- rename of_parse_tdm to ucc_of_parse_tdm
- return err when there is not t1 or e1

 drivers/soc/fsl/qe/Kconfig|   6 +-
 drivers/soc/fsl/qe/Makefile   |   1 +
 drivers/soc/fsl/qe/qe_tdm.c   | 276 ++
 include/soc/fsl/qe/immap_qe.h |   5 +-
 include/soc/fsl/qe/qe_tdm.h   |  94 ++
 5 files changed, 377 insertions(+), 5 deletions(-)
 create mode 100644 drivers/soc/fsl/qe/qe_tdm.c
 create mode 100644 include/soc/fsl/qe/qe_tdm.h

diff --git a/drivers/soc/fsl/qe/Kconfig b/drivers/soc/fsl/qe/Kconfig
index 20978f2..73a2e08 100644
--- a/drivers/soc/fsl/qe/Kconfig
+++ b/drivers/soc/fsl/qe/Kconfig
@@ -22,7 +22,7 @@ config UCC_SLOW
 
 config UCC_FAST
bool
-   default y if UCC_GETH
+   default y if UCC_GETH || QE_TDM
help
  This option provides qe_lib support to UCC fast
  protocols: HDLC, Ethernet, ATM, transparent
@@ -31,6 +31,10 @@ config UCC
bool
default y if UCC_FAST || UCC_SLOW
 
+config QE_TDM
+   bool
+   default y if FSL_UCC_HDLC
+
 config QE_USB
bool
default y if USB_FSL_QE
diff --git a/drivers/soc/fsl/qe/Makefile b/drivers/soc/fsl/qe/Makefile
index ffac541..2031d38 100644
--- a/drivers/soc/fsl/qe/Makefile
+++ b/drivers/soc/fsl/qe/Makefile
@@ -6,5 +6,6 @@ obj-$(CONFIG_CPM)   += qe_common.o
 obj-$(CONFIG_UCC)  += ucc.o
 obj-$(CONFIG_UCC_SLOW) += ucc_slow.o
 obj-$(CONFIG_UCC_FAST) += ucc_fast.o
+obj-$(CONFIG_QE_TDM)   += qe_tdm.o
 obj-$(CONFIG_QE_USB)   += usb.o
 obj-$(CONFIG_QE_GPIO)  += gpio.o
diff --git a/drivers/soc/fsl/qe/qe_tdm.c b/drivers/soc/fsl/qe/qe_tdm.c
new file mode 100644
index 000..5e48b14
--- /dev/null
+++ b/drivers/soc/fsl/qe/qe_tdm.c
@@ -0,0 +1,276 @@
+/*
+ * Copyright (C) 2015 Freescale Semiconductor, Inc. All rights reserved.
+ *
+ * Authors:Zhao Qiang 
+ *
+ * Description:
+ * QE TDM API Set - TDM specific routines implementations.
+ *
+ * This program is free software; you can redistribute  it and/or modify it
+ * 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.
+ */
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+static int set_tdm_framer(const char *tdm_framer_type)
+{
+   if (strcmp(tdm_framer_type, "e1") == 0)
+   return TDM_FRAMER_E1;
+   else if (strcmp(tdm_framer_type, "t1") == 0)
+   return TDM_FRAMER_T1;
+   else
+   return -EINVAL;
+}
+
+static void set_si_param(struct ucc_tdm *utdm, struct ucc_tdm_info *ut_info)
+{
+   struct si_mode_info *si_info = _info->si_info;
+
+   if (utdm->tdm_mode == TDM_INTERNAL_LOOPBACK) {
+   si_info->simr_crt = 1;
+   si_info->simr_rfsd = 0;
+   }
+}
+
+int ucc_of_parse_tdm(struct device_node *np, struct ucc_tdm *utdm,
+struct ucc_tdm_info *ut_info)
+{
+   const char *sprop;
+   int ret = 0;
+   u32 val;
+   struct resource *res;
+   struct device_node *np2;
+   static int siram_init_flag;
+   struct platform_device *pdev;
+
+   sprop = of_get_property(np, "fsl,rx-sync-clock", NULL);
+   if (sprop) {
+   ut_info->uf_info.rx_sync = qe_clock_source(sprop);
+   if ((ut_info->uf_info.rx_sync < QE_CLK_NONE) ||
+   (ut_info->uf_info.rx_sync > QE_RSYNC_PIN)) {
+   pr_err("QE-TDM: Invalid rx-sync-clock property\n");
+   return -EINVAL;
+   }
+   } else {
+   pr_err("QE-TDM: Invalid rx-sync-clock property\n");
+   return -EINVAL;
+   }
+
+   sprop = of_get_property(np, "fsl,tx-sync-clock", NULL);
+   if (sprop) {
+   ut_info->uf_info.tx_sync = qe_clock_source(sprop);
+   if ((ut_info->uf_info.tx_sync < QE_CLK_NONE) ||
+   (ut_info->uf_info.tx_sync > QE_TSYNC_PIN)) {
+   pr_err("QE-TDM: Invalid tx-sync-clock property\n");
+   return -EINVAL;
+   }
+   } else {
+   pr_err("QE-TDM: Invalid tx-sync-clock property\n");
+   return -EINVAL;
+   }
+
+   ret = of_property_read_u32_index(np, "fsl,tx-timeslot-mask", 0, );
+   if (ret) {
+   pr_err("QE-TDM: Invalid tx-timeslot-mask property\n");
+   return -EINVAL;
+   }
+   utdm->tx_ts_mask = val;
+
+   ret = of_property_read_u32_index(np,