From patchwork Wed Mar 30 08:50:29 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qiang Zhao X-Patchwork-Id: 603289 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3qZhpq5qvpz9sBg for ; Wed, 30 Mar 2016 20:16:35 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932803AbcC3JQd (ORCPT ); Wed, 30 Mar 2016 05:16:33 -0400 Received: from mail-bn1on0056.outbound.protection.outlook.com ([157.56.110.56]:59952 "EHLO na01-bn1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S932510AbcC3JQa (ORCPT ); Wed, 30 Mar 2016 05:16:30 -0400 X-Greylist: delayed 978 seconds by postgrey-1.27 at vger.kernel.org; Wed, 30 Mar 2016 05:16:30 EDT Received: from BY2PR03CA005.namprd03.prod.outlook.com (10.255.93.22) by BN1PR0301MB0705.namprd03.prod.outlook.com (10.160.78.12) with Microsoft SMTP Server (TLS) id 15.1.443.12; Wed, 30 Mar 2016 09:00:19 +0000 Received: from BN1BFFO11FD015.protection.gbl (10.255.93.4) by BY2PR03CA005.outlook.office365.com (10.255.93.22) with Microsoft SMTP Server (TLS) id 15.1.434.16 via Frontend Transport; Wed, 30 Mar 2016 09:00:18 +0000 Authentication-Results: spf=fail (sender IP is 192.88.168.50) smtp.mailfrom=nxp.com; nxp.com; dkim=none (message not signed) header.d=none;nxp.com; dmarc=none action=none header.from=nxp.com; Received-SPF: Fail (protection.outlook.com: domain of nxp.com does not designate 192.88.168.50 as permitted sender) receiver=protection.outlook.com; client-ip=192.88.168.50; helo=tx30smr01.am.freescale.net; Received: from tx30smr01.am.freescale.net (192.88.168.50) by BN1BFFO11FD015.mail.protection.outlook.com (10.58.144.78) with Microsoft SMTP Server (TLS) id 15.1.453.6 via Frontend Transport; Wed, 30 Mar 2016 09:00:17 +0000 Received: from titan.ap.freescale.net ([10.192.208.233]) by tx30smr01.am.freescale.net (8.14.3/8.14.0) with ESMTP id u2U8xxwL009345; Wed, 30 Mar 2016 02:00:14 -0700 From: Zhao Qiang To: CC: , , , , , , , Zhao Qiang Subject: [PATCH 4/5] fsl/qe: Add QE TDM lib Date: Wed, 30 Mar 2016 16:50:29 +0800 Message-ID: <1459327830-19829-4-git-send-email-qiang.zhao@nxp.com> X-Mailer: git-send-email 2.1.0.27.g96db324 In-Reply-To: <1459327830-19829-1-git-send-email-qiang.zhao@nxp.com> References: <1459327830-19829-1-git-send-email-qiang.zhao@nxp.com> X-EOPAttributedMessage: 0 X-Matching-Connectors: 131038020180199801; (91ab9b29-cfa4-454e-5278-08d120cd25b8); () X-Forefront-Antispam-Report: CIP:192.88.168.50; IPV:NLI; CTRY:US; EFV:NLI; SFV:NSPM; SFS:(10009020)(6009001)(2980300002)(1109001)(1110001)(339900001)(199003)(50944005)(189002)(104016004)(575784001)(86362001)(36756003)(50226001)(5008740100001)(50466002)(2950100001)(6806005)(87936001)(19580395003)(76176999)(50986999)(19580405001)(5003940100001)(77096005)(189998001)(110136002)(92566002)(85426001)(105606002)(1096002)(48376002)(106466001)(2906002)(33646002)(1220700001)(4326007)(81166005)(586003)(47776003)(229853001)(2351001)(7059030); DIR:OUT; SFP:1101; SCL:1; SRVR:BN1PR0301MB0705; H:tx30smr01.am.freescale.net; FPR:; SPF:Fail; MLV:sfv; A:1; MX:1; LANG:en; X-Microsoft-Exchange-Diagnostics: 1; BN1BFFO11FD015; 1:SKV5pc8tdelSjqA1WdSk2hZm6ceFEFjSBjQ241iMbMJJAeecT1FU9Fy9tJg5MrPgsUk4LPTqAwwqAUT8O3gnfgKRv1yR47Hcu1bBn+lk6A9Q0iO3bvFxmwhUZPTPHCnxTRa+MuTgQ1cuCwIPNr6F3MhvgYf83thQWZvSl9D7s1rClrEqN5hrChRHGP6+KcKM8buOol1UqqgPrdU4mAZxpGJJMaSoojheJCZXAPOQFaDDFT6IgZuGtRYdo4fNRH9gGOrX0tUF6lkyK+KCDUsKKX+YsVSrKu13vL1Q3pTKJu/BXJuw7QXa6+0AYcxhyDWaQzU0U55JZ5/VwxMMO8dwJGIp7EjNagT9R/ZLRln4o5WZCdHLlx/XdB/E/oGaFfGJmrvF8P54S1DDnSKrRPM5dgkPvXWxg8h/oJQg+grgFY1OMeTuC+bg2LNfitC2pz2vSHVjMUaTEH/UvcfyUw7VeuraGIzwSztIMODGeQA94xxRqzHlj/EER5MaoCe/nmEe6fc5RmZ+aQBy9q97DgpAfvpio1bUpgTHt2pJA3cVSjYZ1PUpL6kviurbIXNz4ddpxc1ZzQlNQn/dmFHICMhHp/x+ZZ8lLwIQxdMWk12c5o2GFp02DADjqOe9/mN4KL4e MIME-Version: 1.0 X-MS-Office365-Filtering-Correlation-Id: 77ea4648-d831-4d5d-e818-08d35879b75d X-Microsoft-Exchange-Diagnostics: 1; BN1PR0301MB0705; 2:OEHYVsBqAyBWFXsq5bUZRV+RCYhcj/kxYAjRVHME1RjVNPBbZ7W/WGAUH8NqzJ9Gd47s069FK91KX62N4MXr+sAe8I0dlyY+S9NeAt2Zv5ngQoin3n+hXQj0ETJapMaiK4um/rc5nySwNYPrR4Ge1mfn27R1C3ieVgMO8XTOKYNc2FrIYuHplT3wGvXMLc3f; 3:LZN/8cJ/oYRFiWZlKNbY1exeGxZPgB86Hsgwgd78n5ywBtkjYOHgD13cAz2Qx2qn3PsSw8EMy9tDV5Mqwi7P9SpCOHUmuN7dlyVrg+as22DUx7e9akC/yI9vcEe8VzgikC495AgIJOtVAnX8AMj15bO80Tili78X56r8oXHrq3rsm0eOpMKus8JlPbRnWvEpGhnZaQvHwDnuDKKgnQoPLUG02tjk4IjExQkl8CCjGhw= X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:BN1PR0301MB0705; X-Microsoft-Exchange-Diagnostics: 1; BN1PR0301MB0705; 25:aMsU+8a0iN8Y0aYuBwrFpyUJSwl899yN9nFo2G+TG03A/YC1Zi0fdOky1vs/aybwoV9/l8Jwyjn3LabbmDb2Nf+Jy4yw+AzJsIJc+VRCkPtKNzWvyoDbcMaMcWfXqIeQHJI6jetkOFOrw3LtKYloJTLAHS9XizCVOF+QN2my8vF6oLdeFAO11JhZAR0nVKuKuxPTMukllDkY9TCCJ1l4AFZmM8bERmgijvEnQfuuB9FN6Bj3R80UXl4aU9o+Cs6LUXRRriMA839V6JbOgE1Kg6/DM9ePSiEcbo4OYPm85EzHF23PhCG/Y8loCg/twu8fvspElEr43EXX0WFd2aSXXrjKWbwiCRbtNTo73KBi/zrpa91nAvz0CX5QCXDv5yy2XnkKzpBSZgqzk3lSxo5lS5NhBF8xYo0qwCI6RfO2NVzki0ITJNmda16mz+ZL+Sq8ghdPRq6ABPszgGJ4ceVP4/gfS33u4v61poFQxEJe7UnODTf1xHQvccYbDTmcEioz0j0iZ9c0tfgjt13SYDfpjh5TbZ0PzvGTY6mJUeu/GqrMEWyR4KyLguj91GdDPxL1 X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(601004)(2401047)(13015025)(13023025)(5005006)(13018025)(13024025)(8121501046)(13017025)(3002001)(10201501046); SRVR:BN1PR0301MB0705; BCL:0; PCL:0; RULEID:(400006); SRVR:BN1PR0301MB0705; X-Microsoft-Exchange-Diagnostics: 1; BN1PR0301MB0705; 4:zoiyUr3OhlZ9CbyiKFG/k/A6/NPMbILQi2FnHl/9LAoS4S/tYEJz3IE+TJVV38/sleHKmvIqYtFdzOrKI9T0XHdbOdnwh8HytSe2t8Bz0ZIqPFgVjcn1pIpgcf0JwYHSQ7nhgWtPoed6DbgKcuslgtQ6Wy21HtvMd0ouIQ7fruZ3GtOhotWtSCo6aiGhBU1QQExLiQlJqnrx3H5AEGtijkGeg7fKI2dJVlMHdNIIPWAvNQMAS0ZpOpilz5dmdcAtE1h7Wo0uPwQDAY4r6N7bneBjKhPgs41PeK3Fi1dqzyzW+WHE3SfcbO+KWOOtYKOfA4Ousk0mztOvmFYf0M8mNFZFEfG5tXyioMGLKFXZdv2TSeoKIs9wjYDDArgRpVeH20cLzraYhIJnmT4UerY9qKImaLZd14AQDzCINaJ9MnDaZ5QBFXWesaBRAc/aM7cgyrAfa8Z5t+4+bvBAoAY1Og== X-Forefront-PRVS: 08978A8F5C X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; BN1PR0301MB0705; 23:RaljRP2Tas5T+htIIylQui+F5Ht+DSTsTOVX+Fs?= =?us-ascii?Q?lcUw9pUGiB3DDMJjiw2T7zxSyUaV+VXz4wf95NxANtScDZH6rMbypsat+Znf?= =?us-ascii?Q?qbH6sqs4RkzeNw/pOpagCcUo2Jrdc5NkmqKknUMgwDAHoTmKqpiKYYzF/OLh?= =?us-ascii?Q?r3DAJdfbW0rvsQmFFVuiiwQGbU9nEkzA1qOHvRE51SaZ9osey4F4CsvTwfHP?= =?us-ascii?Q?Us9SyRsINH7qCYdc6HX2L5A10UaeBfXqx7trBsfbx8owdE3vs5cfQWWp24N8?= =?us-ascii?Q?bX/ace+8rAAMXUAYzKckVmOw/pAWiL3g5hbK1Q0W+YxynTOSHBwuusEIkOtC?= =?us-ascii?Q?m2xQ7IzCxlDrc67tgHT3uDsFj4kNET9C7qo6i+DwN7GPmsFvOF3sODG5VZ5t?= =?us-ascii?Q?qwMufW/rro+CjC6tH6fKLKQiWd4wBLE0U5wrcSGb12Ce+akJdpSPkE9/3mHQ?= =?us-ascii?Q?Ve90cJEUVRuGHsRMRQ1mqBr06SsZjVZups4TgUKEDiN6mUMJ3DZ6dVXZmdMb?= =?us-ascii?Q?SSwS+nmIOWW9z8fSWZ1lD2T/zn01LWrhTF2dT/+oabOex4dHgNpimQTQWyEX?= =?us-ascii?Q?5/1f4qHBjD2GmBHmwDUJJ3eNabun0H+MdJoDUmZVBsybPfWHRUFF0aclQ+VT?= =?us-ascii?Q?quyXRX9Q2q0LSFBhlQ5DQRFHBm+egQ+mwsvu/Svsa9Fz19UFtmy1Cvz+ZjHM?= =?us-ascii?Q?BTlYWehwAd9CaNWKH0zsVQm8t7I0rW869R3Rma1YTAeRwMMMoMt4oGhCvhpp?= =?us-ascii?Q?lJzlOyuT9BwlXahW9k18ox0A/FLt4Sd4DL+pa57uWRGOQmtjHQk70znpVmrG?= =?us-ascii?Q?OrtQwK9fHiBOlRHe0G859I+7J+/LJ2iis8/EYAbc19LGBYGPkzEkd349NrWE?= =?us-ascii?Q?xw0/aWjywfEyCH9YsbeKq+DHXWAFrd092pknxZ72UZURIE72sL6EmBTtboM2?= =?us-ascii?Q?MNzRvrtIK/WuCPgeUT2QLZ856MvK8lE6tXBAxEe/aMWyxR+RCqWkPFz9FMyY?= =?us-ascii?Q?+sE6sbYF1RN4tuVhOiEmbIpftxQYUiuAAGpqJI2oiHlx51pJCXzFMdzxutbi?= =?us-ascii?Q?PgTVTXkBqaSoNaZ+0y2lg2Lx1ye0u?= X-Microsoft-Exchange-Diagnostics: 1; BN1PR0301MB0705; 5:bfKHpSWcxO+bQOZ68QzNZ86QY1fvKBk5HF9FJn0mEqqBcj+PFsR+Z0sFd4wXIXSdEbyhevmlMxU/Hhd5G/nTIdpmUOi4OvSRZW9fVc1efwtiXsd1lnZ44y44jxlo+uoOoT/5IrfOnUeO6yr+6ZXxyGdk/2KmvaNmME7/F+yTGwc=; 24:FM3Q6fFOzPrZPVODhqzlH3kHxR5FLYa74lyg4i4jKOHoz+0ApV6ZqKXPe8v8+p9Ov5/WM2oX03nbE5BF6531oJN8tjKw/z+gOd797UZgLZ0= SpamDiagnosticOutput: 1:23 SpamDiagnosticMetadata: NSPM X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Mar 2016 09:00:17.8327 (UTC) X-MS-Exchange-CrossTenant-Id: 5afe0b00-7697-4969-b663-5eab37d5f47e X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=5afe0b00-7697-4969-b663-5eab37d5f47e; Ip=[192.88.168.50]; Helo=[tx30smr01.am.freescale.net] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN1PR0301MB0705 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org 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 --- drivers/soc/fsl/qe/Kconfig | 4 + drivers/soc/fsl/qe/Makefile | 1 + drivers/soc/fsl/qe/qe_tdm.c | 271 ++++++++++++++++++++++++++++++++++++++++++ include/soc/fsl/qe/immap_qe.h | 5 +- include/soc/fsl/qe/qe_tdm.h | 94 +++++++++++++++ 5 files changed, 371 insertions(+), 4 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..463cf29 100644 --- a/drivers/soc/fsl/qe/Kconfig +++ b/drivers/soc/fsl/qe/Kconfig @@ -31,6 +31,10 @@ config UCC bool default y if UCC_FAST || UCC_SLOW +config QE_TDM + bool + select UCC_FAST + 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 0000000..9a2374d --- /dev/null +++ b/drivers/soc/fsl/qe/qe_tdm.c @@ -0,0 +1,271 @@ +/* + * 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 enum tdm_framer_t set_tdm_framer(const char *tdm_framer_type) +{ + if (strcmp(tdm_framer_type, "e1") == 0) + return TDM_FRAMER_E1; + else + return TDM_FRAMER_T1; +} + +static void set_si_param(struct ucc_tdm *utdm, struct ucc_tdm_info *ut_info) +{ + struct si_mode_info *si_info = &ut_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, &val); + 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, "fsl,rx-timeslot-mask", 0, &val); + if (ret) { + ret = -EINVAL; + pr_err("QE-TDM: Invalid rx-timeslot-mask property\n"); + return ret; + } + utdm->rx_ts_mask = val; + + ret = of_property_read_u32_index(np, "fsl,tdm-id", 0, &val); + if (ret) { + ret = -EINVAL; + pr_err("QE-TDM: No fsl,tdm-id property for this UCC\n"); + return ret; + } + utdm->tdm_port = val; + ut_info->uf_info.tdm_num = utdm->tdm_port; + + if (of_get_property(np, "fsl,tdm-internal-loopback", NULL)) + utdm->tdm_mode = TDM_INTERNAL_LOOPBACK; + else + utdm->tdm_mode = TDM_NORMAL; + + sprop = of_get_property(np, "fsl,tdm-framer-type", NULL); + if (!sprop) { + ret = -EINVAL; + pr_err("QE-TDM: No tdm-framer-type property for UCC\n"); + return ret; + } + utdm->tdm_framer_type = set_tdm_framer(sprop); + + ret = of_property_read_u32_index(np, "fsl,siram-entry-id", 0, &val); + if (ret) { + ret = -EINVAL; + pr_err("QE-TDM: No siram entry id for UCC\n"); + return ret; + } + utdm->siram_entry_id = val; + + set_si_param(utdm, ut_info); + + np2 = of_find_compatible_node(NULL, NULL, "fsl,t1040-qe-si"); + if (!np2) + return -EINVAL; + + pdev = of_find_device_by_node(np2); + if (!pdev) { + pr_err("%s: failed to lookup pdev\n", np2->name); + of_node_put(np2); + return -EINVAL; + } + + of_node_put(np2); + res = platform_get_resource(pdev, IORESOURCE_MEM, 0); + utdm->si_regs = devm_ioremap_resource(&pdev->dev, res); + if (IS_ERR(utdm->si_regs)) { + ret = PTR_ERR(utdm->si_regs); + goto err_miss_siram_property; + } + + np2 = of_find_compatible_node(NULL, NULL, "fsl,t1040-qe-siram"); + if (!np2) { + ret = -EINVAL; + goto err_miss_siram_property; + } + + pdev = of_find_device_by_node(np2); + if (!pdev) { + ret = -EINVAL; + pr_err("%s: failed to lookup pdev\n", np2->name); + of_node_put(np2); + goto err_miss_siram_property; + } + + of_node_put(np2); + res = platform_get_resource(pdev, IORESOURCE_MEM, 0); + utdm->siram = devm_ioremap_resource(&pdev->dev, res); + if (IS_ERR(utdm->siram)) { + ret = PTR_ERR(utdm->siram); + goto err_miss_siram_property; + } + + if (siram_init_flag == 0) { + memset_io(utdm->siram, 0, res->end - res->start + 1); + siram_init_flag = 1; + } + + return ret; + +err_miss_siram_property: + devm_iounmap(&pdev->dev, utdm->si_regs); + return ret; +} + +void ucc_tdm_init(struct ucc_tdm *utdm, struct ucc_tdm_info *ut_info) +{ + struct si1 __iomem *si_regs; + u16 __iomem *siram; + u16 siram_entry_valid; + u16 siram_entry_closed; + u16 ucc_num; + u8 csel; + u16 sixmr; + u16 tdm_port; + u32 siram_entry_id; + u32 mask; + int i; + + si_regs = utdm->si_regs; + siram = utdm->siram; + ucc_num = ut_info->uf_info.ucc_num; + tdm_port = utdm->tdm_port; + siram_entry_id = utdm->siram_entry_id; + + if (utdm->tdm_framer_type == TDM_FRAMER_T1) + utdm->num_of_ts = 24; + if (utdm->tdm_framer_type == TDM_FRAMER_E1) + utdm->num_of_ts = 32; + + /* set siram table */ + csel = (ucc_num < 4) ? ucc_num + 9 : ucc_num - 3; + + siram_entry_valid = SIR_CSEL(csel) | SIR_BYTE | SIR_CNT(0); + siram_entry_closed = SIR_IDLE | SIR_BYTE | SIR_CNT(0); + + for (i = 0; i < utdm->num_of_ts; i++) { + mask = 0x01 << i; + + if (utdm->tx_ts_mask & mask) + iowrite16be(siram_entry_valid, + &siram[siram_entry_id * 32 + i]); + else + iowrite16be(siram_entry_closed, + &siram[siram_entry_id * 32 + i]); + + if (utdm->rx_ts_mask & mask) + iowrite16be(siram_entry_valid, + &siram[siram_entry_id * 32 + 0x200 + i]); + else + iowrite16be(siram_entry_closed, + &siram[siram_entry_id * 32 + 0x200 + i]); + } + + setbits16(&siram[(siram_entry_id * 32) + (utdm->num_of_ts - 1)], + SIR_LAST); + setbits16(&siram[(siram_entry_id * 32) + 0x200 + (utdm->num_of_ts - 1)], + SIR_LAST); + + /* Set SIxMR register */ + sixmr = SIMR_SAD(siram_entry_id); + + sixmr &= ~SIMR_SDM_MASK; + + if (utdm->tdm_mode == TDM_INTERNAL_LOOPBACK) + sixmr |= SIMR_SDM_INTERNAL_LOOPBACK; + else + sixmr |= SIMR_SDM_NORMAL; + + sixmr |= SIMR_RFSD(ut_info->si_info.simr_rfsd) | + SIMR_TFSD(ut_info->si_info.simr_tfsd); + + if (ut_info->si_info.simr_crt) + sixmr |= SIMR_CRT; + if (ut_info->si_info.simr_sl) + sixmr |= SIMR_SL; + if (ut_info->si_info.simr_ce) + sixmr |= SIMR_CE; + if (ut_info->si_info.simr_fe) + sixmr |= SIMR_FE; + if (ut_info->si_info.simr_gm) + sixmr |= SIMR_GM; + + switch (tdm_port) { + case 0: + iowrite16be(sixmr, &si_regs->sixmr1[0]); + break; + case 1: + iowrite16be(sixmr, &si_regs->sixmr1[1]); + break; + case 2: + iowrite16be(sixmr, &si_regs->sixmr1[2]); + break; + case 3: + iowrite16be(sixmr, &si_regs->sixmr1[3]); + break; + default: + pr_err("QE-TDM: can not find tdm sixmr reg\n"); + break; + } +} diff --git a/include/soc/fsl/qe/immap_qe.h b/include/soc/fsl/qe/immap_qe.h index bedbff8..c76ef30 100644 --- a/include/soc/fsl/qe/immap_qe.h +++ b/include/soc/fsl/qe/immap_qe.h @@ -159,10 +159,7 @@ struct spi { /* SI */ struct si1 { - __be16 siamr1; /* SI1 TDMA mode register */ - __be16 sibmr1; /* SI1 TDMB mode register */ - __be16 sicmr1; /* SI1 TDMC mode register */ - __be16 sidmr1; /* SI1 TDMD mode register */ + __be16 sixmr1[4]; /* SI1 TDMx (x = A B C D) mode register */ u8 siglmr1_h; /* SI1 global mode register high */ u8 res0[0x1]; u8 sicmdr1_h; /* SI1 command register high */ diff --git a/include/soc/fsl/qe/qe_tdm.h b/include/soc/fsl/qe/qe_tdm.h new file mode 100644 index 0000000..e7ae93a --- /dev/null +++ b/include/soc/fsl/qe/qe_tdm.h @@ -0,0 +1,94 @@ +/* + * Internal header file for QE TDM mode routines. + * + * Copyright (C) 2015 Freescale Semiconductor, Inc. All rights reserved. + * + * Authors: Zhao Qiang + * + * 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 + */ + +#ifndef CONFIG_QE_TDM_H +#define CONFIG_QE_TDM_H + +#include +#include + +#include +#include + +#include +#include + +/* SI RAM entries */ +#define SIR_LAST 0x0001 +#define SIR_BYTE 0x0002 +#define SIR_CNT(x) ((x) << 2) +#define SIR_CSEL(x) ((x) << 5) +#define SIR_SGS 0x0200 +#define SIR_SWTR 0x4000 +#define SIR_MCC 0x8000 +#define SIR_IDLE 0 + +/* SIxMR fields */ +#define SIMR_SAD(x) ((x) << 12) +#define SIMR_SDM_NORMAL 0x0000 +#define SIMR_SDM_INTERNAL_LOOPBACK 0x0800 +#define SIMR_SDM_MASK 0x0c00 +#define SIMR_CRT 0x0040 +#define SIMR_SL 0x0020 +#define SIMR_CE 0x0010 +#define SIMR_FE 0x0008 +#define SIMR_GM 0x0004 +#define SIMR_TFSD(n) (n) +#define SIMR_RFSD(n) ((n) << 8) + +enum tdm_ts_t { + TDM_TX_TS, + TDM_RX_TS +}; + +enum tdm_framer_t { + TDM_FRAMER_T1, + TDM_FRAMER_E1 +}; + +enum tdm_mode_t { + TDM_INTERNAL_LOOPBACK, + TDM_NORMAL +}; + +struct si_mode_info { + u8 simr_rfsd; + u8 simr_tfsd; + u8 simr_crt; + u8 simr_sl; + u8 simr_ce; + u8 simr_fe; + u8 simr_gm; +}; + +struct ucc_tdm_info { + struct ucc_fast_info uf_info; + struct si_mode_info si_info; +}; + +struct ucc_tdm { + u16 tdm_port; /* port for this tdm:TDMA,TDMB */ + u32 siram_entry_id; + u16 __iomem *siram; + struct si1 __iomem *si_regs; + enum tdm_framer_t tdm_framer_type; + enum tdm_mode_t tdm_mode; + u8 num_of_ts; /* the number of timeslots in this tdm frame */ + u32 tx_ts_mask; /* tx time slot mask */ + u32 rx_ts_mask; /* rx time slot mask */ +}; + +int ucc_of_parse_tdm(struct device_node *np, struct ucc_tdm *utdm, + struct ucc_tdm_info *ut_info); +void ucc_tdm_init(struct ucc_tdm *utdm, struct ucc_tdm_info *ut_info); +#endif