public inbox for linux-arm-kernel@lists.infradead.org 
 help / color / mirror / Atom feed
From: marex@denx•de (Marek Vasut)
To: linux-arm-kernel@lists•infradead.org
Subject: [PATCH v1 3/7] usb: chipidea: add imx on-soc utmi phy driver
Date: Wed, 16 May 2012 03:20:01 +0200	[thread overview]
Message-ID: <201205160320.01482.marex@denx.de> (raw)
In-Reply-To: <1337090303-16046-4-git-send-email-richard.zhao@freescale.com>

Dear Richard Zhao,

> Signed-off-by: Richard Zhao <richard.zhao@freescale•com>
> ---
>  drivers/usb/chipidea/Makefile       |    4 +
>  drivers/usb/chipidea/phy-imx-utmi.c |  140
> +++++++++++++++++++++++++++++++++++ 2 files changed, 144 insertions(+), 0
> deletions(-)
>  create mode 100644 drivers/usb/chipidea/phy-imx-utmi.c
> 
> diff --git a/drivers/usb/chipidea/Makefile b/drivers/usb/chipidea/Makefile
> index cc34937..0f34c0c 100644
> --- a/drivers/usb/chipidea/Makefile
> +++ b/drivers/usb/chipidea/Makefile
> @@ -12,3 +12,7 @@ endif
>  ifneq ($(CONFIG_ARCH_MSM),)
>  	obj-$(CONFIG_USB_CHIPIDEA)	+= ci13xxx_msm.o
>  endif
> +
> +ifneq ($(CONFIG_ARCH_MXC),)
> +	obj-$(CONFIG_USB_CHIPIDEA)	+= phy-imx-utmi.o
> +endif
> diff --git a/drivers/usb/chipidea/phy-imx-utmi.c
> b/drivers/usb/chipidea/phy-imx-utmi.c new file mode 100644
> index 0000000..f7a0fe7
> --- /dev/null
> +++ b/drivers/usb/chipidea/phy-imx-utmi.c
> @@ -0,0 +1,140 @@
> +/*
> + * Copyright 2012 Freescale Semiconductor, Inc.
> + *
> + * The code contained herein is licensed under the GNU General Public
> + * License. You may obtain a copy of the GNU General Public License
> + * Version 2 or later at the following locations:
> + *
> + * http://www.opensource.org/licenses/gpl-license.html
> + * http://www.gnu.org/copyleft/gpl.html
> + */
> +
> +#include <linux/module.h>
> +#include <linux/kernel.h>
> +#include <linux/platform_device.h>
> +#include <linux/clk.h>
> +#include <linux/usb/otg.h>
> +#include <linux/delay.h>
> +#include <linux/err.h>
> +#include <linux/io.h>
> +
> +#define DRIVER_NAME "imx_utmi"
> +
> +#define HW_USBPHY_PWD	(0x00000000)

Drop the braces here

> +#define HW_USBPHY_CTRL	0x00000030
> +
> +#define BM_USBPHY_CTRL_SFTRST 0x80000000
> +#define BM_USBPHY_CTRL_CLKGATE 0x40000000
> +#define BM_USBPHY_CTRL_ENUTMILEVEL3 0x00008000
> +#define BM_USBPHY_CTRL_ENUTMILEVEL2 0x00004000
> +
> +struct imx_utmi_phy {
> +	struct usb_phy phy;
> +	struct clk *clk;
> +};
> +
> +#define to_imx_phy(p) container_of((p), struct imx_utmi_phy, phy)
> +
> +static int imx_utmi_phy_init(struct usb_phy *phy)
> +{
> +	struct imx_utmi_phy *imx_phy;
> +	u32 reg;
> +
> +	imx_phy = to_imx_phy(phy);
> +
> +	clk_prepare_enable(imx_phy->clk);
> +
> +	reg = readl_relaxed(phy->io_priv + HW_USBPHY_CTRL);
> +	reg &= ~BM_USBPHY_CTRL_CLKGATE;
> +	writel_relaxed(reg, phy->io_priv + HW_USBPHY_CTRL);
> +
> +	/* Reset USBPHY module */
> +	reg = readl_relaxed(phy->io_priv + HW_USBPHY_CTRL);
> +	reg |= BM_USBPHY_CTRL_SFTRST;
> +	writel_relaxed(reg, phy->io_priv + HW_USBPHY_CTRL);
> +	udelay(10);
> +
> +	/* Remove CLKGATE and SFTRST */
> +	reg = readl_relaxed(phy->io_priv + HW_USBPHY_CTRL);
> +	reg &= ~(BM_USBPHY_CTRL_CLKGATE | BM_USBPHY_CTRL_SFTRST);
> +	writel_relaxed(reg, phy->io_priv + HW_USBPHY_CTRL);
> +	udelay(10);

You might want to check my PHY driver for the proper init sequence ... it uses 
mxs_reset_block() (or maybe there's already stmp_reset_block() ? )

> +
> +	/* Power up the PHY */
> +	writel_relaxed(0, phy->io_priv + HW_USBPHY_PWD);
> +	/* enable FS/LS device */
> +	reg = readl_relaxed(phy->io_priv + HW_USBPHY_CTRL);
> +	reg |= BM_USBPHY_CTRL_ENUTMILEVEL2 | BM_USBPHY_CTRL_ENUTMILEVEL3;
> +	writel_relaxed(reg, phy->io_priv + HW_USBPHY_CTRL);

Well, you can retrieve this from my PHY driver ;-)

> +
> +	return 0;
> +}
> +
> +static void imx_utmi_phy_shutdown(struct usb_phy *phy)
> +{
> +	struct imx_utmi_phy *imx_phy;
> +
> +	imx_phy = to_imx_phy(phy);
> +	clk_disable_unprepare(imx_phy->clk);

You forgot to disable the PHY here ... pull it out of my patchset and be done 
with it ;-)

> +}
> +
> +static int imx_utmi_probe(struct platform_device *pdev)
> +{
> +	struct resource *res;
> +	void __iomem *base;
> +	struct clk *clk;
> +	struct imx_utmi_phy *imx_phy;
> +
> +	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
> +	if (!res) {
> +		dev_err(&pdev->dev, "can't get device resources\n");
> +		return -ENOENT;
> +	}
> +
> +	base = devm_request_and_ioremap(&pdev->dev, res);
> +	if (!base)
> +		return -EBUSY;
> +
> +	clk = devm_clk_get(&pdev->dev, NULL);
> +	if (IS_ERR(clk))
> +		return PTR_ERR(clk);
> +
> +	imx_phy = devm_kzalloc(&pdev->dev, sizeof(*imx_phy), GFP_KERNEL);
> +	if (!imx_phy)
> +		return -ENOMEM;
> +
> +	imx_phy->phy.io_priv = base;
> +	imx_phy->phy.dev = &pdev->dev;
> +	imx_phy->phy.label = DRIVER_NAME;
> +	imx_phy->phy.init = imx_utmi_phy_init;
> +	imx_phy->phy.shutdown = imx_utmi_phy_shutdown;
> +	imx_phy->clk = clk;
> +	platform_set_drvdata(pdev, &imx_phy->phy);
> +
> +	return 0;
> +}
> +
> +static const struct of_device_id imx_utmi_dt_ids[] = {
> +	{ .compatible = "fsl,imx6q-usbphy", },
> +	{ /* sentinel */ }
> +};
> +
> +static struct platform_driver imx_utmi_driver = {
> +	.probe = imx_utmi_probe,
> +	.driver = {
> +		.name = DRIVER_NAME,
> +		.of_match_table = imx_utmi_dt_ids,
> +	 },
> +};
> +
> +static int __init imx_utmi_init(void)
> +{
> +	return platform_driver_register(&imx_utmi_driver);
> +}
> +postcore_initcall(imx_utmi_init);
> +
> +static void __exit imx_utmi_exit(void)
> +{
> +	platform_driver_unregister(&imx_utmi_driver);
> +}

module_platform_driver() will make this clearer ... check my ci13xxx_mxs.c 
binding glue for usage.

> +module_exit(imx_utmi_exit);

  reply	other threads:[~2012-05-16  1:20 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-05-15 13:58 [PATCH v1 0/7] preliminary work for adding imx6q_sabrelite usb support Richard Zhao
2012-05-15 13:58 ` [PATCH v1 1/7] usb: chipidea: permit user select USB_EHCI_ROOT_HUB_TT Richard Zhao
2012-05-15 14:27   ` Marek Vasut
2012-05-15 15:19     ` Greg KH
2012-05-16  1:03   ` Marek Vasut
2012-05-15 13:58 ` [PATCH v1 2/7] usb: chipidea: remove zero check of hw_ep_max Richard Zhao
2012-05-16  1:11   ` Marek Vasut
2012-05-16  1:14   ` [PATCH] usb: chipidea: improve the validation of endpoint count Marek Vasut
2012-05-16 11:11     ` Alexander Shishkin
2012-05-16  5:32   ` [PATCH v1 2/7] usb: chipidea: remove zero check of hw_ep_max Peter Chen
2012-05-16  5:46     ` Richard Zhao
2012-05-16 10:48     ` Alexander Shishkin
2012-05-15 13:58 ` [PATCH v1 3/7] usb: chipidea: add imx on-soc utmi phy driver Richard Zhao
2012-05-16  1:20   ` Marek Vasut [this message]
2012-05-15 13:58 ` [PATCH v1 4/7] usb: chipidea: add imx driver binding Richard Zhao
2012-05-15 14:03   ` Russell King - ARM Linux
2012-05-15 14:12     ` Richard Zhao
2012-05-16  8:36     ` Richard Zhao
2012-05-16  1:22   ` Marek Vasut
2012-05-16 11:38   ` Alexander Shishkin
2012-05-16 11:58     ` Felipe Balbi
2012-05-16 13:08     ` Richard Zhao
2012-05-16 14:18       ` Alexander Shishkin
2012-05-17  2:41         ` Richard Zhao
2012-05-15 13:58 ` [PATCH v1 5/7] ARM: imx6q: correct device name of usbphy and usboh3 clock export Richard Zhao
2012-05-15 13:58 ` [PATCH v1 6/7] ARM: imx6q: add anatop initialization for usb controllers Richard Zhao
2012-05-15 13:58 ` [PATCH v1 7/7] ARM: dts: imx6q-sabrelite: add usb devices Richard Zhao
2012-05-15 14:28 ` [PATCH v1 0/7] preliminary work for adding imx6q_sabrelite usb support Marek Vasut
2012-05-15 15:21   ` Greg KH
2012-05-15 16:30     ` Marek Vasut
2012-05-16  0:37       ` Richard Zhao
2012-05-16  8:34         ` Peter Chen
2012-05-16 13:22           ` Marek Vasut
2012-05-16 15:05             ` Shawn Guo

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=201205160320.01482.marex@denx.de \
    --to=marex@denx$(echo .)de \
    --cc=linux-arm-kernel@lists$(echo .)infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox