From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933140AbcGIEqk (ORCPT ); Sat, 9 Jul 2016 00:46:40 -0400 Received: from mail-bl2nam02on0040.outbound.protection.outlook.com ([104.47.38.40]:52000 "EHLO NAM02-BL2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S933019AbcGIEqh (ORCPT ); Sat, 9 Jul 2016 00:46:37 -0400 Authentication-Results: spf=none (sender IP is 192.88.168.50) smtp.mailfrom=lvd4224.freescale.com; vger.kernel.org; dkim=none (message not signed) header.d=none;vger.kernel.org; dmarc=fail action=none header.from=nxp.com; From: Rajesh Bhagat To: , , CC: , , , , , , Rajesh Bhagat Subject: [PATCH v2 1/5] drivers: usb: chipidea: Add qoriq platform driver Date: Sat, 9 Jul 2016 10:00:52 +0530 Message-ID: <1468038656-10345-2-git-send-email-rajesh.bhagat@nxp.com> X-Mailer: git-send-email 1.7.7.4 In-Reply-To: <1468038656-10345-1-git-send-email-rajesh.bhagat@nxp.com> References: <1468038656-10345-1-git-send-email-rajesh.bhagat@nxp.com> X-EOPAttributedMessage: 0 X-Matching-Connectors: 131125122600307785;(91ab9b29-cfa4-454e-5278-08d120cd25b8);() X-Forefront-Antispam-Report: CIP:192.88.168.50;IPV:NLI;CTRY:US;EFV:NLI;SFV:NSPM;SFS:(10009020)(6039001)(6009001)(7916002)(2980300002)(428002)(189002)(199003)(7846002)(8676002)(33646002)(305945005)(48376002)(47776003)(2950100001)(2201001)(4326007)(960300001)(42186005)(8666005)(2906002)(11100500001)(106466001)(103686003)(90966002)(105586002)(68736007)(19580405001)(16796002)(6806005)(87936001)(92566002)(5003940100001)(50466002)(8936002)(76176999)(36756003)(81166006)(81156014)(50986999)(52956003)(356003)(86372001)(45336002)(101416001)(19580395003)(97736004)(5001770100001)(46386002)(229853001)(189998001)(50226002)(586003)(7059030)(2004002)(42882005)(4720700001);DIR:OUT;SFP:1101;SCL:1;SRVR:BY1PR03MB1498;H:tx30smr01.am.freescale.net;FPR:;SPF:None;PTR:InfoDomainNonexistent;MX:1;A:0;LANG:en; X-Microsoft-Exchange-Diagnostics: 1;BN1BFFO11FD029;1:ekttcvINDIMklwKlGvfVEQJHWq+lktnaR+4qKqwSjW5/6RZ6t0J257lsB900RyhMG2woRuszEUX3sUqUwst/j8/EcSSo9obPpF+S1VoP7oMig9303d2I7JdRcSdRKbJaUzbzceRIsT9B+d1xvWm7/qHJcu/LghSqUgRUkj2ZUCY087LUVO7kOjlYB07BTMO/sTN23L+U3UIlax75BWfsnOTMDS9ejZCGPYIsdKoxm5/GRReyLaUbFuFSsXkTegBs6pYEsjkuPXgOzwZFvRi6T2LoRXGbCkzrN15b2+CwxGLNOX19UlgZ1+JkU+nmUkVVpncv5Hk9olquobLO8G4D5Irf8hpz6NxW5YDTJXiS/6moMqQtLPccyG7Rfxy6TvT+n9xSGuBoj/uhRaPm4R03ahnKL4w32QBb6dvpsAd5y31/JKw6hjJBCxR/eF10mMutmW+44B2+v/x/Sqvm3TGKwmseA1iZShj5d+yBb5Svy2bEih4DFOyg8J/+LgWYeGzbbV3zrexhfWfvxesXWF49qrl+p+KNpkMUnRdhYGMTD59NmHsEXApSQFkfZy5gujANVD54YC/ZJ6fSIodS2Dc+NVzUPR4F0hVhwuCzTOWzYKQ= MIME-Version: 1.0 Content-Type: text/plain X-MS-Office365-Filtering-Correlation-Id: ed7694be-6671-4097-2aea-08d3a7b1d42d X-Microsoft-Exchange-Diagnostics: 1;BY1PR03MB1498;2:3eN0tdFcC6tSzBBFiWvSIsF1fu7fK2+mQsLP7e42YQgLRwCPovCJOpT4EUtPm9bS5m4lv6jva0Ck1/9km8skRjg9TNN+iH7uOqnAUjN5kUurjT+nEcQAfd6/4Rm8rRTgtobEPCdktMklqTJ+qAinmpXRTvW2R00EF+sBHoxY176JONtMhoSqoicDbkvlHhJj;3:d+7xcOxb24cSui4BYsOH6wgj7+yiNsY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pl9dUizM+sjUbS15s9HvqfBreR34iJLv0xU+ZEzo5R/SUv73mlxfhgR6Bk4sTv4VR8KHltuy9FeCngTn2oSk4vPpot4/QjMmkckwzknlXLt55jfAjjq4P5cbt9kce8ebe2GLWe/IXWJJ+CM1XY+vlYGHB7quZ3bSKPRAhjz+zLL6jTcywYOBaYwFx49BVmAwJILysKW1tvGLKjhyqLIoBNr2e3JjCK439ti0zxssr7V/3v0uGWEjKXC9rQci9YB9hRyFEKehh/3ifH8feBJ+PWQh6C7hR4aXcxl7NeW+TFSCKqjisdW8xpZiiekFwaHZXNMK1MEORb487rK5YWUEVUlod9s8rLF/TPMhErWPsRfOwJeepvxPwmQCUxSrl1HGOVSAvSoKxz9vifQ== X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(185117386973197); X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(601004)(2401047)(5005006)(13023025)(13017025)(8121501046)(13018025)(13015025)(13024025)(3002001)(10201501046)(6055026);SRVR:BY1PR03MB1498;BCL:0;PCL:0;RULEID:(400006);SRVR:BY1PR03MB1498; X-Forefront-PRVS: 0998671D02 X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1;BY1PR03MB1498;23:HRxReViFapvk/7xf/xGqtKp75xEu9ok8Yh6rerJpO?= =?us-ascii?Q?uxbsZh5uHsm4EZAhJ3Kq7UyRs3cKmLkSTjMiWIYEqyoVqhHtW6wR/1y/jEfP?= =?us-ascii?Q?AlzTGEp/WYhTH9OCSMYl5vXTyFfnf4h2Dbhwx8NTP5T6q1vNczVfL4CG1PWO?= =?us-ascii?Q?F3ph5eT9oAR+cpIUjzuWlfDQtx8saKQa+mu4qjvmfB4LDICJeshhANf330BL?= =?us-ascii?Q?TpKnpY7uzBXU7oFemUwuGlxFbGl1uWjeqpWyjsodPYaouwReRpIoszbx2Trg?= =?us-ascii?Q?WGDubnHiE9EV7aMXrrMlChsYK+OgPt9v3S/JUQZaDJ5/sVhVsHh6tjEfNSmG?= =?us-ascii?Q?8V1jxlgh5x0I8w3NdcYvW/RGjDr3ouYOmqNSZHhFeEzNuIKBharm2sP6lDVj?= =?us-ascii?Q?UAYESSkda2XHquV+3khc6bT+Bklo9BBIf1PywjJkqh9WeyEaOKSjh4Hz/Ti6?= =?us-ascii?Q?53bob0patVaxjX99oluTC61++0TGVr6cvgvuAvg1o8Q7piVWL2J3g1a5BpaK?= =?us-ascii?Q?e9wB4ZQB0waxERA8JSXigyx+Rjx5kNBuaoAGrytxesLxLVEWNYIyUDJzw0uY?= =?us-ascii?Q?eTdBIdmY7fzwsYG55tliQVT0E3f+gw939C17arokW3d16/p3wyCIfA0AS4DL?= =?us-ascii?Q?SqQm7980oH/myFLdZGvZPRcDv88AGvy13w1a05woMNlxhVkkSEENsh+WXZCG?= =?us-ascii?Q?53HwNOYSwB0QRCogBDT8fvhUljZqqxk678FLRzqOOcpYjowYPni5uClANmAI?= =?us-ascii?Q?pnWIaZXKYdgpwgZXCJbpLNkjhb0IeBIHlA/AAnou0U9pm02HbRDRJfrkRtjT?= =?us-ascii?Q?j7OGFbAwLKKyNz/timlWD1WjiciWJDJ/E64qoB4lyS2vszQ0I9n2d1cELPcE?= =?us-ascii?Q?rSwN/5fREtN+kWISiCI3Mng+ZF2vuC0wrbjZYlE/tzzSI8ELSz053thmoztA?= =?us-ascii?Q?yKdbEK1/W8o7Ozo8ok3XkIq76pDHxMeORaOu+5RQWVn8b4DVMYBIWC3Xgd8J?= =?us-ascii?Q?ozU7goTueFiw7ji0YvKLpYmlwrhOioX0obOBnwn7blsTKhj9OhVXcqfpMmI9?= =?us-ascii?Q?qAO1XSbkuhEzQ/xfEzocJSj9kynwCgqT9K4onWk83mco3Uxn9dUkMD8opF6A?= =?us-ascii?Q?2LhXhyzozDFKWNHWW0ArSDWsaqc7VW6wvBi97VjGiptMmgPtKgKPzM2dj1gR?= =?us-ascii?Q?G2ordWtFZlxcR+9ae5tzVyBW2WnTiWsxprzbYuw2C4PzdzF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Exchange-CrossTenant-OriginalArrivalTime: 09 Jul 2016 04:30:59.7499 (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: BY1PR03MB1498 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Adds qoriq platform driver for chipidea controller, verfied on LS1021A and LS1012A platforms. Signed-off-by: Rajesh Bhagat --- Changes in v2: - Replaced Freescale with QorIQ in comments section - Added macros to remove hardcoding while programming registers - Changed the compatible string to fsl,ci-qoriq-usb2 and added version - Removed calls to devm free/release calls drivers/usb/chipidea/Makefile | 2 + drivers/usb/chipidea/ci_hdrc_qoriq.c | 237 +++++++++++++++++++++++++++++++++++ drivers/usb/chipidea/ci_hdrc_qoriq.h | 65 ++++++++++ 3 files changed, 304 insertions(+) create mode 100644 drivers/usb/chipidea/ci_hdrc_qoriq.c create mode 100644 drivers/usb/chipidea/ci_hdrc_qoriq.h diff --git a/drivers/usb/chipidea/Makefile b/drivers/usb/chipidea/Makefile index 518e445..3122b86b 100644 --- a/drivers/usb/chipidea/Makefile +++ b/drivers/usb/chipidea/Makefile @@ -14,3 +14,5 @@ obj-$(CONFIG_USB_CHIPIDEA) += ci_hdrc_zevio.o obj-$(CONFIG_USB_CHIPIDEA_PCI) += ci_hdrc_pci.o obj-$(CONFIG_USB_CHIPIDEA_OF) += usbmisc_imx.o ci_hdrc_imx.o + +obj-$(CONFIG_USB_CHIPIDEA) += ci_hdrc_qoriq.o diff --git a/drivers/usb/chipidea/ci_hdrc_qoriq.c b/drivers/usb/chipidea/ci_hdrc_qoriq.c new file mode 100644 index 0000000..3f478c6 --- /dev/null +++ b/drivers/usb/chipidea/ci_hdrc_qoriq.c @@ -0,0 +1,237 @@ +/* + * QorIQ SoC USB 2.0 Controller driver + * + * Copyright 2016 Freescale Semiconductor, Inc. + * Author: Rajesh Bhagat + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + */ +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "ci.h" +#include "ci_hdrc_qoriq.h" + +struct ci_hdrc_qoriq_data { + struct phy *phy; + struct clk *clk; + void __iomem *qoriq_regs; + struct platform_device *ci_pdev; + enum usb_phy_interface phy_mode; +}; + +/* + * clock helper functions + */ +static int ci_hdrc_qoriq_get_clks(struct platform_device *pdev) +{ + int ret; + struct device *dev = &pdev->dev; + struct ci_hdrc_qoriq_data *data = platform_get_drvdata(pdev); + + data->clk = devm_clk_get(dev, "usb2-clock"); + if (IS_ERR(data->clk)) { + dev_err(dev, "failed to get clk, err=%ld\n", + PTR_ERR(data->clk)); + return ret; + } + return 0; +} + +static int ci_hdrc_qoriq_prepare_enable_clks(struct platform_device *pdev) +{ + int ret; + struct device *dev = &pdev->dev; + struct ci_hdrc_qoriq_data *data = platform_get_drvdata(pdev); + + ret = clk_prepare_enable(data->clk); + if (ret) { + dev_err(dev, "failed to prepare/enable clk, err=%d\n", ret); + return ret; + } + return 0; +} + +static void ci_hdrc_qoriq_disable_unprepare_clks(struct platform_device *pdev) +{ + struct ci_hdrc_qoriq_data *data = platform_get_drvdata(pdev); + + clk_disable_unprepare(data->clk); +} + +static int ci_hdrc_qoriq_usb_setup(struct platform_device *pdev) +{ + u32 reg; + struct resource *res; + struct device *dev = &pdev->dev; + struct ci_hdrc_qoriq_data *data = platform_get_drvdata(pdev); + + res = platform_get_resource(pdev, IORESOURCE_MEM, 0); + if (!res) { + dev_err(dev, "failed to get I/O memory\n"); + return -ENOENT; + } + + dev_dbg(dev, "res->start %llx, resource_size(res) %llx\n", res->start, + resource_size(res)); + data->qoriq_regs = devm_ioremap(dev, res->start, resource_size(res)); + if (IS_ERR(data->qoriq_regs)) { + dev_err(dev, "failed to remap I/O memory\n"); + return -ENOMEM; + } + + data->phy_mode = of_usb_get_phy_mode(pdev->dev.of_node); + dev_dbg(dev, "phy_mode %d\n", data->phy_mode); + + reg = ioread32be(data->qoriq_regs + QORIQ_SOC_USB_CTRL); + switch (data->phy_mode) { + case USBPHY_INTERFACE_MODE_ULPI: + iowrite32be(reg | ~UTMI_PHY_EN, + data->qoriq_regs + QORIQ_SOC_USB_CTRL); + reg = ioread32be(data->qoriq_regs + QORIQ_SOC_USB_CTRL); + iowrite32be(reg | USB_CTRL_USB_EN, + data->qoriq_regs + QORIQ_SOC_USB_CTRL); + break; + default: + dev_err(dev, "unsupported phy_mode %d\n", data->phy_mode); + return -EINVAL; + } + + /* Setup Snooping for all the 4GB space */ + /* SNOOP1 starts from 0x0, size 2G */ + iowrite32be(SNOOP_SIZE_2GB, data->qoriq_regs + QORIQ_SOC_USB_SNOOP1); + /* SNOOP2 starts from 0x80000000, size 2G */ + iowrite32be(SNOOP_SIZE_2GB | 0x80000000, + data->qoriq_regs + QORIQ_SOC_USB_SNOOP2); + + iowrite32be(PRICTRL_PRI_LVL, data->qoriq_regs + QORIQ_SOC_USB_PRICTRL); + iowrite32be(AGECNTTHRSH_THRESHOLD, data->qoriq_regs + + QORIQ_SOC_USB_AGECNTTHRSH); + iowrite32be(SICTRL_RD_PREFETCH_32_BYTE, data->qoriq_regs + + QORIQ_SOC_USB_SICTRL); + + devm_iounmap(dev, data->qoriq_regs); + return 0; +} + +static int ci_hdrc_qoriq_probe(struct platform_device *pdev) +{ + int ret; + struct device *dev = &pdev->dev; + struct ci_hdrc_qoriq_data *data; + struct ci_hdrc_platform_data pdata = { + .name = dev_name(dev), + .capoffset = DEF_CAPOFFSET, + .flags = CI_HDRC_DISABLE_STREAMING, + }; + + data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL); + if (!data) + return -ENOMEM; + + platform_set_drvdata(pdev, data); + + ret = ci_hdrc_qoriq_get_clks(pdev); + if (ret) + goto err_out; + + ret = ci_hdrc_qoriq_prepare_enable_clks(pdev); + if (ret) + goto err_out; + + ret = dma_coerce_mask_and_coherent(dev, DMA_BIT_MASK(32)); + if (ret) { + dev_err(dev, "failed to set coherent dma mask, err=%d\n", ret); + goto err_clks; + } + + ret = ci_hdrc_qoriq_usb_setup(pdev); + if (ret) { + dev_err(dev, "failed to perform qoriq_usb2 setup, err=%d\n", + ret); + goto err_clks; + } + + data->phy = devm_phy_get(dev, "usb2-phy"); + if (IS_ERR(data->phy)) { + ret = PTR_ERR(data->phy); + /* Return -EINVAL if no usbphy is available */ + if (ret == -ENODEV) + ret = -EINVAL; + dev_err(dev, "failed get phy device, err=%d\n", ret); + goto err_clks; + } + pdata.phy = data->phy; + + data->ci_pdev = ci_hdrc_add_device(dev, + pdev->resource, pdev->num_resources, + &pdata); + if (IS_ERR(data->ci_pdev)) { + ret = PTR_ERR(data->ci_pdev); + dev_err(dev, + "failed to register ci_hdrc platform device, err=%d\n", + ret); + goto err_clks; + } + + pm_runtime_no_callbacks(dev); + pm_runtime_enable(dev); + + dev_dbg(dev, "initialized\n"); + return 0; + +err_clks: + ci_hdrc_qoriq_disable_unprepare_clks(pdev); +err_out: + return ret; +} + +static int ci_hdrc_qoriq_remove(struct platform_device *pdev) +{ + struct device *dev = &pdev->dev; + struct ci_hdrc_qoriq_data *data = platform_get_drvdata(pdev); + + pm_runtime_disable(dev); + ci_hdrc_remove_device(data->ci_pdev); + ci_hdrc_qoriq_disable_unprepare_clks(pdev); + dev_dbg(dev, "de-initialized\n"); + return 0; +} + +static void ci_hdrc_qoriq_shutdown(struct platform_device *pdev) +{ + ci_hdrc_qoriq_remove(pdev); +} + +static const struct of_device_id ci_hdrc_qoriq_dt_ids[] = { + { .compatible = "fsl,ci-qoriq-usb2"}, + { /* sentinel */ } +}; +MODULE_DEVICE_TABLE(of, ci_hdrc_qoriq_dt_ids); + +static struct platform_driver ci_hdrc_qoriq_driver = { + .probe = ci_hdrc_qoriq_probe, + .remove = ci_hdrc_qoriq_remove, + .shutdown = ci_hdrc_qoriq_shutdown, + .driver = { + .name = "ci_qoriq_usb2", + .of_match_table = ci_hdrc_qoriq_dt_ids, + }, +}; + +module_platform_driver(ci_hdrc_qoriq_driver); + +MODULE_ALIAS("platform:ci-qoriq-usb2"); +MODULE_LICENSE("GPL v2"); +MODULE_DESCRIPTION("CI HDRC QORIQ USB binding"); +MODULE_AUTHOR("Rajesh Bhagat "); diff --git a/drivers/usb/chipidea/ci_hdrc_qoriq.h b/drivers/usb/chipidea/ci_hdrc_qoriq.h new file mode 100644 index 0000000..afd29442 --- /dev/null +++ b/drivers/usb/chipidea/ci_hdrc_qoriq.h @@ -0,0 +1,65 @@ +/* + * QorIQ SoC USB 2.0 Controller driver + * + * Copyright 2016 Freescale Semiconductor, Inc. + * Author: Rajesh Bhagat + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + */ +#ifndef __DRIVER_USB_CHIPIDEA_CI_HDRC_QORIQ_H +#define __DRIVER_USB_CHIPIDEA_CI_HDRC_QORIQ_H + +/* offsets for the non-ehci registers in the QORIQ SOC USB controller */ +#define QORIQ_SOC_USB_SBUSCFG 0x90 +#define SBUSCFG_INCR8 0x02 /* INCR8, specified */ +#define QORIQ_SOC_USB_ULPIVP 0x170 +#define QORIQ_SOC_USB_PORTSC1 0x184 +#define PORT_PTS_MSK (3<<30) +#define PORT_PTS_UTMI (0<<30) +#define PORT_PTS_ULPI (2<<30) +#define PORT_PTS_SERIAL (3<<30) +#define PORT_PTS_PTW (1<<28) +#define QORIQ_SOC_USB_PORTSC2 0x188 +#define QORIQ_SOC_USB_USBMODE 0x1a8 +#define USBMODE_CM_MASK (3 << 0) /* controller mode mask */ +#define USBMODE_CM_HOST (3 << 0) /* controller mode: host */ +#define USBMODE_ES (1 << 2) /* (Big) Endian Select */ + +#define QORIQ_SOC_USB_USBGENCTRL 0x200 +#define USBGENCTRL_PPP (1 << 3) +#define USBGENCTRL_PFP (1 << 2) +#define QORIQ_SOC_USB_ISIPHYCTRL 0x204 +#define ISIPHYCTRL_PXE (1) +#define ISIPHYCTRL_PHYE (1 << 4) + +#define QORIQ_SOC_USB_SNOOP1 0x400 /* NOTE: big-endian */ +#define QORIQ_SOC_USB_SNOOP2 0x404 /* NOTE: big-endian */ +#define QORIQ_SOC_USB_AGECNTTHRSH 0x408 /* NOTE: big-endian */ +#define AGECNTTHRSH_THRESHOLD 0x40 +#define QORIQ_SOC_USB_PRICTRL 0x40c /* NOTE: big-endian */ +#define PRICTRL_PRI_LVL 0xc +#define QORIQ_SOC_USB_SICTRL 0x410 /* NOTE: big-endian */ +#define SICTRL_RD_PREFETCH_32_BYTE (0x1) +#define SICTRL_RD_PREFETCH_64_BYTE (0x0) +#define QORIQ_SOC_USB_CTRL 0x500 /* NOTE: big-endian */ +#define CTRL_UTMI_PHY_EN (1 << 9) +#define CTRL_PHY_CLK_VALID (1 << 17) +#define SNOOP_SIZE_2GB 0x1e + +/* control Register Bit Masks */ +#define CONTROL_REGISTER_W1C_MASK 0x00020000 /* W1C: PHY_CLK_VALID */ +#define ULPI_INT_EN (1<<0) +#define WU_INT_EN (1<<1) +#define USB_CTRL_USB_EN (1<<2) +#define LINE_STATE_FILTER__EN (1<<3) +#define KEEP_OTG_ON (1<<4) +#define OTG_PORT (1<<5) +#define PLL_RESET (1<<8) +#define UTMI_PHY_EN (1<<9) +#define ULPI_PHY_CLK_SEL (1<<10) +#define PHY_CLK_VALID (1<<17) + +#endif /* __DRIVER_USB_CHIPIDEA_CI_HDRC_QORIQ_H */ -- 2.6.2.198.g614a2ac From mboxrd@z Thu Jan 1 00:00:00 1970 From: Rajesh Bhagat Subject: [PATCH v2 1/5] drivers: usb: chipidea: Add qoriq platform driver Date: Sat, 9 Jul 2016 10:00:52 +0530 Message-ID: <1468038656-10345-2-git-send-email-rajesh.bhagat@nxp.com> References: <1468038656-10345-1-git-send-email-rajesh.bhagat@nxp.com> Mime-Version: 1.0 Content-Type: text/plain Return-path: In-Reply-To: <1468038656-10345-1-git-send-email-rajesh.bhagat-3arQi8VN3Tc@public.gmane.org> Sender: devicetree-owner-u79uwXL29TY76Z2rM5mHXA@public.gmane.org To: linux-usb-u79uwXL29TY76Z2rM5mHXA@public.gmane.org, linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org, devicetree-u79uwXL29TY76Z2rM5mHXA@public.gmane.org Cc: Peter.Chen-3arQi8VN3Tc@public.gmane.org, gregkh-hQyY1W1yCW8ekmWlsbkhG0B+6BGkLq7r@public.gmane.org, kishon-l0cyMroinI0@public.gmane.org, robh+dt-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org, shawnguo-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org, linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org, Rajesh Bhagat List-Id: devicetree@vger.kernel.org Adds qoriq platform driver for chipidea controller, verfied on LS1021A and LS1012A platforms. Signed-off-by: Rajesh Bhagat --- Changes in v2: - Replaced Freescale with QorIQ in comments section - Added macros to remove hardcoding while programming registers - Changed the compatible string to fsl,ci-qoriq-usb2 and added version - Removed calls to devm free/release calls drivers/usb/chipidea/Makefile | 2 + drivers/usb/chipidea/ci_hdrc_qoriq.c | 237 +++++++++++++++++++++++++++++++++++ drivers/usb/chipidea/ci_hdrc_qoriq.h | 65 ++++++++++ 3 files changed, 304 insertions(+) create mode 100644 drivers/usb/chipidea/ci_hdrc_qoriq.c create mode 100644 drivers/usb/chipidea/ci_hdrc_qoriq.h diff --git a/drivers/usb/chipidea/Makefile b/drivers/usb/chipidea/Makefile index 518e445..3122b86b 100644 --- a/drivers/usb/chipidea/Makefile +++ b/drivers/usb/chipidea/Makefile @@ -14,3 +14,5 @@ obj-$(CONFIG_USB_CHIPIDEA) += ci_hdrc_zevio.o obj-$(CONFIG_USB_CHIPIDEA_PCI) += ci_hdrc_pci.o obj-$(CONFIG_USB_CHIPIDEA_OF) += usbmisc_imx.o ci_hdrc_imx.o + +obj-$(CONFIG_USB_CHIPIDEA) += ci_hdrc_qoriq.o diff --git a/drivers/usb/chipidea/ci_hdrc_qoriq.c b/drivers/usb/chipidea/ci_hdrc_qoriq.c new file mode 100644 index 0000000..3f478c6 --- /dev/null +++ b/drivers/usb/chipidea/ci_hdrc_qoriq.c @@ -0,0 +1,237 @@ +/* + * QorIQ SoC USB 2.0 Controller driver + * + * Copyright 2016 Freescale Semiconductor, Inc. + * Author: Rajesh Bhagat + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + */ +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "ci.h" +#include "ci_hdrc_qoriq.h" + +struct ci_hdrc_qoriq_data { + struct phy *phy; + struct clk *clk; + void __iomem *qoriq_regs; + struct platform_device *ci_pdev; + enum usb_phy_interface phy_mode; +}; + +/* + * clock helper functions + */ +static int ci_hdrc_qoriq_get_clks(struct platform_device *pdev) +{ + int ret; + struct device *dev = &pdev->dev; + struct ci_hdrc_qoriq_data *data = platform_get_drvdata(pdev); + + data->clk = devm_clk_get(dev, "usb2-clock"); + if (IS_ERR(data->clk)) { + dev_err(dev, "failed to get clk, err=%ld\n", + PTR_ERR(data->clk)); + return ret; + } + return 0; +} + +static int ci_hdrc_qoriq_prepare_enable_clks(struct platform_device *pdev) +{ + int ret; + struct device *dev = &pdev->dev; + struct ci_hdrc_qoriq_data *data = platform_get_drvdata(pdev); + + ret = clk_prepare_enable(data->clk); + if (ret) { + dev_err(dev, "failed to prepare/enable clk, err=%d\n", ret); + return ret; + } + return 0; +} + +static void ci_hdrc_qoriq_disable_unprepare_clks(struct platform_device *pdev) +{ + struct ci_hdrc_qoriq_data *data = platform_get_drvdata(pdev); + + clk_disable_unprepare(data->clk); +} + +static int ci_hdrc_qoriq_usb_setup(struct platform_device *pdev) +{ + u32 reg; + struct resource *res; + struct device *dev = &pdev->dev; + struct ci_hdrc_qoriq_data *data = platform_get_drvdata(pdev); + + res = platform_get_resource(pdev, IORESOURCE_MEM, 0); + if (!res) { + dev_err(dev, "failed to get I/O memory\n"); + return -ENOENT; + } + + dev_dbg(dev, "res->start %llx, resource_size(res) %llx\n", res->start, + resource_size(res)); + data->qoriq_regs = devm_ioremap(dev, res->start, resource_size(res)); + if (IS_ERR(data->qoriq_regs)) { + dev_err(dev, "failed to remap I/O memory\n"); + return -ENOMEM; + } + + data->phy_mode = of_usb_get_phy_mode(pdev->dev.of_node); + dev_dbg(dev, "phy_mode %d\n", data->phy_mode); + + reg = ioread32be(data->qoriq_regs + QORIQ_SOC_USB_CTRL); + switch (data->phy_mode) { + case USBPHY_INTERFACE_MODE_ULPI: + iowrite32be(reg | ~UTMI_PHY_EN, + data->qoriq_regs + QORIQ_SOC_USB_CTRL); + reg = ioread32be(data->qoriq_regs + QORIQ_SOC_USB_CTRL); + iowrite32be(reg | USB_CTRL_USB_EN, + data->qoriq_regs + QORIQ_SOC_USB_CTRL); + break; + default: + dev_err(dev, "unsupported phy_mode %d\n", data->phy_mode); + return -EINVAL; + } + + /* Setup Snooping for all the 4GB space */ + /* SNOOP1 starts from 0x0, size 2G */ + iowrite32be(SNOOP_SIZE_2GB, data->qoriq_regs + QORIQ_SOC_USB_SNOOP1); + /* SNOOP2 starts from 0x80000000, size 2G */ + iowrite32be(SNOOP_SIZE_2GB | 0x80000000, + data->qoriq_regs + QORIQ_SOC_USB_SNOOP2); + + iowrite32be(PRICTRL_PRI_LVL, data->qoriq_regs + QORIQ_SOC_USB_PRICTRL); + iowrite32be(AGECNTTHRSH_THRESHOLD, data->qoriq_regs + + QORIQ_SOC_USB_AGECNTTHRSH); + iowrite32be(SICTRL_RD_PREFETCH_32_BYTE, data->qoriq_regs + + QORIQ_SOC_USB_SICTRL); + + devm_iounmap(dev, data->qoriq_regs); + return 0; +} + +static int ci_hdrc_qoriq_probe(struct platform_device *pdev) +{ + int ret; + struct device *dev = &pdev->dev; + struct ci_hdrc_qoriq_data *data; + struct ci_hdrc_platform_data pdata = { + .name = dev_name(dev), + .capoffset = DEF_CAPOFFSET, + .flags = CI_HDRC_DISABLE_STREAMING, + }; + + data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL); + if (!data) + return -ENOMEM; + + platform_set_drvdata(pdev, data); + + ret = ci_hdrc_qoriq_get_clks(pdev); + if (ret) + goto err_out; + + ret = ci_hdrc_qoriq_prepare_enable_clks(pdev); + if (ret) + goto err_out; + + ret = dma_coerce_mask_and_coherent(dev, DMA_BIT_MASK(32)); + if (ret) { + dev_err(dev, "failed to set coherent dma mask, err=%d\n", ret); + goto err_clks; + } + + ret = ci_hdrc_qoriq_usb_setup(pdev); + if (ret) { + dev_err(dev, "failed to perform qoriq_usb2 setup, err=%d\n", + ret); + goto err_clks; + } + + data->phy = devm_phy_get(dev, "usb2-phy"); + if (IS_ERR(data->phy)) { + ret = PTR_ERR(data->phy); + /* Return -EINVAL if no usbphy is available */ + if (ret == -ENODEV) + ret = -EINVAL; + dev_err(dev, "failed get phy device, err=%d\n", ret); + goto err_clks; + } + pdata.phy = data->phy; + + data->ci_pdev = ci_hdrc_add_device(dev, + pdev->resource, pdev->num_resources, + &pdata); + if (IS_ERR(data->ci_pdev)) { + ret = PTR_ERR(data->ci_pdev); + dev_err(dev, + "failed to register ci_hdrc platform device, err=%d\n", + ret); + goto err_clks; + } + + pm_runtime_no_callbacks(dev); + pm_runtime_enable(dev); + + dev_dbg(dev, "initialized\n"); + return 0; + +err_clks: + ci_hdrc_qoriq_disable_unprepare_clks(pdev); +err_out: + return ret; +} + +static int ci_hdrc_qoriq_remove(struct platform_device *pdev) +{ + struct device *dev = &pdev->dev; + struct ci_hdrc_qoriq_data *data = platform_get_drvdata(pdev); + + pm_runtime_disable(dev); + ci_hdrc_remove_device(data->ci_pdev); + ci_hdrc_qoriq_disable_unprepare_clks(pdev); + dev_dbg(dev, "de-initialized\n"); + return 0; +} + +static void ci_hdrc_qoriq_shutdown(struct platform_device *pdev) +{ + ci_hdrc_qoriq_remove(pdev); +} + +static const struct of_device_id ci_hdrc_qoriq_dt_ids[] = { + { .compatible = "fsl,ci-qoriq-usb2"}, + { /* sentinel */ } +}; +MODULE_DEVICE_TABLE(of, ci_hdrc_qoriq_dt_ids); + +static struct platform_driver ci_hdrc_qoriq_driver = { + .probe = ci_hdrc_qoriq_probe, + .remove = ci_hdrc_qoriq_remove, + .shutdown = ci_hdrc_qoriq_shutdown, + .driver = { + .name = "ci_qoriq_usb2", + .of_match_table = ci_hdrc_qoriq_dt_ids, + }, +}; + +module_platform_driver(ci_hdrc_qoriq_driver); + +MODULE_ALIAS("platform:ci-qoriq-usb2"); +MODULE_LICENSE("GPL v2"); +MODULE_DESCRIPTION("CI HDRC QORIQ USB binding"); +MODULE_AUTHOR("Rajesh Bhagat "); diff --git a/drivers/usb/chipidea/ci_hdrc_qoriq.h b/drivers/usb/chipidea/ci_hdrc_qoriq.h new file mode 100644 index 0000000..afd29442 --- /dev/null +++ b/drivers/usb/chipidea/ci_hdrc_qoriq.h @@ -0,0 +1,65 @@ +/* + * QorIQ SoC USB 2.0 Controller driver + * + * Copyright 2016 Freescale Semiconductor, Inc. + * Author: Rajesh Bhagat + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + */ +#ifndef __DRIVER_USB_CHIPIDEA_CI_HDRC_QORIQ_H +#define __DRIVER_USB_CHIPIDEA_CI_HDRC_QORIQ_H + +/* offsets for the non-ehci registers in the QORIQ SOC USB controller */ +#define QORIQ_SOC_USB_SBUSCFG 0x90 +#define SBUSCFG_INCR8 0x02 /* INCR8, specified */ +#define QORIQ_SOC_USB_ULPIVP 0x170 +#define QORIQ_SOC_USB_PORTSC1 0x184 +#define PORT_PTS_MSK (3<<30) +#define PORT_PTS_UTMI (0<<30) +#define PORT_PTS_ULPI (2<<30) +#define PORT_PTS_SERIAL (3<<30) +#define PORT_PTS_PTW (1<<28) +#define QORIQ_SOC_USB_PORTSC2 0x188 +#define QORIQ_SOC_USB_USBMODE 0x1a8 +#define USBMODE_CM_MASK (3 << 0) /* controller mode mask */ +#define USBMODE_CM_HOST (3 << 0) /* controller mode: host */ +#define USBMODE_ES (1 << 2) /* (Big) Endian Select */ + +#define QORIQ_SOC_USB_USBGENCTRL 0x200 +#define USBGENCTRL_PPP (1 << 3) +#define USBGENCTRL_PFP (1 << 2) +#define QORIQ_SOC_USB_ISIPHYCTRL 0x204 +#define ISIPHYCTRL_PXE (1) +#define ISIPHYCTRL_PHYE (1 << 4) + +#define QORIQ_SOC_USB_SNOOP1 0x400 /* NOTE: big-endian */ +#define QORIQ_SOC_USB_SNOOP2 0x404 /* NOTE: big-endian */ +#define QORIQ_SOC_USB_AGECNTTHRSH 0x408 /* NOTE: big-endian */ +#define AGECNTTHRSH_THRESHOLD 0x40 +#define QORIQ_SOC_USB_PRICTRL 0x40c /* NOTE: big-endian */ +#define PRICTRL_PRI_LVL 0xc +#define QORIQ_SOC_USB_SICTRL 0x410 /* NOTE: big-endian */ +#define SICTRL_RD_PREFETCH_32_BYTE (0x1) +#define SICTRL_RD_PREFETCH_64_BYTE (0x0) +#define QORIQ_SOC_USB_CTRL 0x500 /* NOTE: big-endian */ +#define CTRL_UTMI_PHY_EN (1 << 9) +#define CTRL_PHY_CLK_VALID (1 << 17) +#define SNOOP_SIZE_2GB 0x1e + +/* control Register Bit Masks */ +#define CONTROL_REGISTER_W1C_MASK 0x00020000 /* W1C: PHY_CLK_VALID */ +#define ULPI_INT_EN (1<<0) +#define WU_INT_EN (1<<1) +#define USB_CTRL_USB_EN (1<<2) +#define LINE_STATE_FILTER__EN (1<<3) +#define KEEP_OTG_ON (1<<4) +#define OTG_PORT (1<<5) +#define PLL_RESET (1<<8) +#define UTMI_PHY_EN (1<<9) +#define ULPI_PHY_CLK_SEL (1<<10) +#define PHY_CLK_VALID (1<<17) + +#endif /* __DRIVER_USB_CHIPIDEA_CI_HDRC_QORIQ_H */ -- 2.6.2.198.g614a2ac -- To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org More majordomo info at http://vger.kernel.org/majordomo-info.html