linux/drivers/usb/chipidea/ci_hdrc_usb2.c
<<
>>
Prefs
   1/*
   2 * Copyright (C) 2014 Marvell Technology Group Ltd.
   3 *
   4 * Antoine Tenart <antoine.tenart@free-electrons.com>
   5 *
   6 * This file is licensed under the terms of the GNU General Public
   7 * License version 2. This program is licensed "as is" without any
   8 * warranty of any kind, whether express or implied.
   9 */
  10
  11#include <linux/clk.h>
  12#include <linux/dma-mapping.h>
  13#include <linux/module.h>
  14#include <linux/of.h>
  15#include <linux/of_platform.h>
  16#include <linux/phy/phy.h>
  17#include <linux/platform_device.h>
  18#include <linux/usb/chipidea.h>
  19#include <linux/usb/hcd.h>
  20#include <linux/usb/ulpi.h>
  21
  22#include "ci.h"
  23
  24struct ci_hdrc_usb2_priv {
  25        struct platform_device  *ci_pdev;
  26        struct clk              *clk;
  27};
  28
  29static const struct ci_hdrc_platform_data ci_default_pdata = {
  30        .capoffset      = DEF_CAPOFFSET,
  31        .flags          = CI_HDRC_DISABLE_STREAMING,
  32};
  33
  34static struct ci_hdrc_platform_data ci_zynq_pdata = {
  35        .capoffset      = DEF_CAPOFFSET,
  36        .flags          = CI_HDRC_PHY_VBUS_CONTROL,
  37};
  38
  39static const struct of_device_id ci_hdrc_usb2_of_match[] = {
  40        { .compatible = "chipidea,usb2"},
  41        { .compatible = "xlnx,zynq-usb-2.20a", .data = &ci_zynq_pdata},
  42        { }
  43};
  44MODULE_DEVICE_TABLE(of, ci_hdrc_usb2_of_match);
  45
  46static int ci_hdrc_usb2_probe(struct platform_device *pdev)
  47{
  48        struct device *dev = &pdev->dev;
  49        struct ci_hdrc_usb2_priv *priv;
  50        struct ci_hdrc_platform_data *ci_pdata = dev_get_platdata(dev);
  51        int ret;
  52        const struct of_device_id *match;
  53
  54        if (!ci_pdata) {
  55                ci_pdata = devm_kmalloc(dev, sizeof(*ci_pdata), GFP_KERNEL);
  56                *ci_pdata = ci_default_pdata;   /* struct copy */
  57        }
  58
  59        match = of_match_device(ci_hdrc_usb2_of_match, &pdev->dev);
  60        if (match && match->data) {
  61                /* struct copy */
  62                *ci_pdata = *(struct ci_hdrc_platform_data *)match->data;
  63                ci_pdata->usb_phy = devm_usb_get_phy_by_phandle(dev, "usb-phy",
  64                                         0);
  65                if (IS_ERR(ci_pdata->usb_phy))
  66                        return PTR_ERR(ci_pdata->usb_phy);
  67        }
  68
  69        priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
  70        if (!priv)
  71                return -ENOMEM;
  72
  73        priv->clk = devm_clk_get(dev, NULL);
  74        if (!IS_ERR(priv->clk)) {
  75                ret = clk_prepare_enable(priv->clk);
  76                if (ret) {
  77                        dev_err(dev, "failed to enable the clock: %d\n", ret);
  78                        return ret;
  79                }
  80        }
  81
  82        ret = dma_set_mask_and_coherent(dev, DMA_BIT_MASK(32));
  83        if (ret)
  84                goto clk_err;
  85
  86        ci_pdata->name = dev_name(dev);
  87
  88        priv->ci_pdev = ci_hdrc_add_device(dev, pdev->resource,
  89                                           pdev->num_resources, ci_pdata);
  90        if (IS_ERR(priv->ci_pdev)) {
  91                ret = PTR_ERR(priv->ci_pdev);
  92                if (ret != -EPROBE_DEFER)
  93                        dev_err(dev,
  94                                "failed to register ci_hdrc platform device: %d\n",
  95                                ret);
  96                goto clk_err;
  97        }
  98
  99        platform_set_drvdata(pdev, priv);
 100
 101        pm_runtime_no_callbacks(dev);
 102        pm_runtime_enable(dev);
 103
 104        return 0;
 105
 106clk_err:
 107        if (!IS_ERR(priv->clk))
 108                clk_disable_unprepare(priv->clk);
 109        return ret;
 110}
 111
 112static int ci_hdrc_usb2_remove(struct platform_device *pdev)
 113{
 114        struct ci_hdrc_usb2_priv *priv = platform_get_drvdata(pdev);
 115
 116        pm_runtime_disable(&pdev->dev);
 117        ci_hdrc_remove_device(priv->ci_pdev);
 118        clk_disable_unprepare(priv->clk);
 119
 120        return 0;
 121}
 122
 123static struct platform_driver ci_hdrc_usb2_driver = {
 124        .probe  = ci_hdrc_usb2_probe,
 125        .remove = ci_hdrc_usb2_remove,
 126        .driver = {
 127                .name           = "chipidea-usb2",
 128                .of_match_table = of_match_ptr(ci_hdrc_usb2_of_match),
 129        },
 130};
 131module_platform_driver(ci_hdrc_usb2_driver);
 132
 133MODULE_DESCRIPTION("ChipIdea HDRC USB2 binding for ci13xxx");
 134MODULE_AUTHOR("Antoine Tenart <antoine.tenart@free-electrons.com>");
 135MODULE_LICENSE("GPL");
 136