2 * Copyright (C) 2015 Freescale Semiconductor, Inc. All rights reserved.
4 * Authors: Zhao Qiang <qiang.zhao@nxp.com>
7 * QE TDM API Set - TDM specific routines implementations.
9 * This program is free software; you can redistribute it and/or modify it
10 * under the terms of the GNU General Public License as published by the
11 * Free Software Foundation; either version 2 of the License, or (at your
12 * option) any later version.
15 #include <linux/kernel.h>
16 #include <linux/of_address.h>
17 #include <linux/of_irq.h>
18 #include <linux/of_platform.h>
19 #include <soc/fsl/qe/qe_tdm.h>
21 static int set_tdm_framer(const char *tdm_framer_type)
23 if (strcmp(tdm_framer_type, "e1") == 0)
25 else if (strcmp(tdm_framer_type, "t1") == 0)
31 static void set_si_param(struct ucc_tdm *utdm, struct ucc_tdm_info *ut_info)
33 struct si_mode_info *si_info = &ut_info->si_info;
35 if (utdm->tdm_mode == TDM_INTERNAL_LOOPBACK) {
36 si_info->simr_crt = 1;
37 si_info->simr_rfsd = 0;
41 int ucc_of_parse_tdm(struct device_node *np, struct ucc_tdm *utdm,
42 struct ucc_tdm_info *ut_info)
48 sprop = of_get_property(np, "fsl,rx-sync-clock", NULL);
50 ut_info->uf_info.rx_sync = qe_clock_source(sprop);
51 if ((ut_info->uf_info.rx_sync < QE_CLK_NONE) ||
52 (ut_info->uf_info.rx_sync > QE_RSYNC_PIN)) {
53 pr_err("QE-TDM: Invalid rx-sync-clock property\n");
57 pr_err("QE-TDM: Invalid rx-sync-clock property\n");
61 sprop = of_get_property(np, "fsl,tx-sync-clock", NULL);
63 ut_info->uf_info.tx_sync = qe_clock_source(sprop);
64 if ((ut_info->uf_info.tx_sync < QE_CLK_NONE) ||
65 (ut_info->uf_info.tx_sync > QE_TSYNC_PIN)) {
66 pr_err("QE-TDM: Invalid tx-sync-clock property\n");
70 pr_err("QE-TDM: Invalid tx-sync-clock property\n");
74 ret = of_property_read_u32_index(np, "fsl,tx-timeslot-mask", 0, &val);
76 pr_err("QE-TDM: Invalid tx-timeslot-mask property\n");
79 utdm->tx_ts_mask = val;
81 ret = of_property_read_u32_index(np, "fsl,rx-timeslot-mask", 0, &val);
84 pr_err("QE-TDM: Invalid rx-timeslot-mask property\n");
87 utdm->rx_ts_mask = val;
89 ret = of_property_read_u32_index(np, "fsl,tdm-id", 0, &val);
92 pr_err("QE-TDM: No fsl,tdm-id property for this UCC\n");
96 ut_info->uf_info.tdm_num = utdm->tdm_port;
98 if (of_property_read_bool(np, "fsl,tdm-internal-loopback"))
99 utdm->tdm_mode = TDM_INTERNAL_LOOPBACK;
101 utdm->tdm_mode = TDM_NORMAL;
103 sprop = of_get_property(np, "fsl,tdm-framer-type", NULL);
106 pr_err("QE-TDM: No tdm-framer-type property for UCC\n");
109 ret = set_tdm_framer(sprop);
112 utdm->tdm_framer_type = ret;
114 ret = of_property_read_u32_index(np, "fsl,siram-entry-id", 0, &val);
117 pr_err("QE-TDM: No siram entry id for UCC\n");
120 utdm->siram_entry_id = val;
122 set_si_param(utdm, ut_info);
125 EXPORT_SYMBOL(ucc_of_parse_tdm);
127 void ucc_tdm_init(struct ucc_tdm *utdm, struct ucc_tdm_info *ut_info)
129 struct si1 __iomem *si_regs;
131 u16 siram_entry_valid;
132 u16 siram_entry_closed;
141 si_regs = utdm->si_regs;
143 ucc_num = ut_info->uf_info.ucc_num;
144 tdm_port = utdm->tdm_port;
145 siram_entry_id = utdm->siram_entry_id;
147 if (utdm->tdm_framer_type == TDM_FRAMER_T1)
148 utdm->num_of_ts = 24;
149 if (utdm->tdm_framer_type == TDM_FRAMER_E1)
150 utdm->num_of_ts = 32;
152 /* set siram table */
153 csel = (ucc_num < 4) ? ucc_num + 9 : ucc_num - 3;
155 siram_entry_valid = SIR_CSEL(csel) | SIR_BYTE | SIR_CNT(0);
156 siram_entry_closed = SIR_IDLE | SIR_BYTE | SIR_CNT(0);
158 for (i = 0; i < utdm->num_of_ts; i++) {
161 if (utdm->tx_ts_mask & mask)
162 iowrite16be(siram_entry_valid,
163 &siram[siram_entry_id * 32 + i]);
165 iowrite16be(siram_entry_closed,
166 &siram[siram_entry_id * 32 + i]);
168 if (utdm->rx_ts_mask & mask)
169 iowrite16be(siram_entry_valid,
170 &siram[siram_entry_id * 32 + 0x200 + i]);
172 iowrite16be(siram_entry_closed,
173 &siram[siram_entry_id * 32 + 0x200 + i]);
176 setbits16(&siram[(siram_entry_id * 32) + (utdm->num_of_ts - 1)],
178 setbits16(&siram[(siram_entry_id * 32) + 0x200 + (utdm->num_of_ts - 1)],
181 /* Set SIxMR register */
182 sixmr = SIMR_SAD(siram_entry_id);
184 sixmr &= ~SIMR_SDM_MASK;
186 if (utdm->tdm_mode == TDM_INTERNAL_LOOPBACK)
187 sixmr |= SIMR_SDM_INTERNAL_LOOPBACK;
189 sixmr |= SIMR_SDM_NORMAL;
191 sixmr |= SIMR_RFSD(ut_info->si_info.simr_rfsd) |
192 SIMR_TFSD(ut_info->si_info.simr_tfsd);
194 if (ut_info->si_info.simr_crt)
196 if (ut_info->si_info.simr_sl)
198 if (ut_info->si_info.simr_ce)
200 if (ut_info->si_info.simr_fe)
202 if (ut_info->si_info.simr_gm)
207 iowrite16be(sixmr, &si_regs->sixmr1[0]);
210 iowrite16be(sixmr, &si_regs->sixmr1[1]);
213 iowrite16be(sixmr, &si_regs->sixmr1[2]);
216 iowrite16be(sixmr, &si_regs->sixmr1[3]);
219 pr_err("QE-TDM: can not find tdm sixmr reg\n");
223 EXPORT_SYMBOL(ucc_tdm_init);