Linux 4.14.51
[linux/fpc-iii.git] / drivers / usb / chipidea / ci_hdrc_tegra.c
blobbfcee2702d50360b04e698d97a083bb55a6b9346
1 /*
2 * Copyright (c) 2016, NVIDIA Corporation
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms and conditions of the GNU General Public License,
6 * version 2, as published by the Free Software Foundation.
7 */
9 #include <linux/clk.h>
10 #include <linux/module.h>
11 #include <linux/of_device.h>
12 #include <linux/reset.h>
14 #include <linux/usb/chipidea.h>
16 #include "ci.h"
18 struct tegra_udc {
19 struct ci_hdrc_platform_data data;
20 struct platform_device *dev;
22 struct usb_phy *phy;
23 struct clk *clk;
26 struct tegra_udc_soc_info {
27 unsigned long flags;
30 static const struct tegra_udc_soc_info tegra20_udc_soc_info = {
31 .flags = CI_HDRC_REQUIRES_ALIGNED_DMA,
34 static const struct tegra_udc_soc_info tegra30_udc_soc_info = {
35 .flags = 0,
38 static const struct tegra_udc_soc_info tegra114_udc_soc_info = {
39 .flags = 0,
42 static const struct tegra_udc_soc_info tegra124_udc_soc_info = {
43 .flags = 0,
46 static const struct of_device_id tegra_udc_of_match[] = {
48 .compatible = "nvidia,tegra20-udc",
49 .data = &tegra20_udc_soc_info,
50 }, {
51 .compatible = "nvidia,tegra30-udc",
52 .data = &tegra30_udc_soc_info,
53 }, {
54 .compatible = "nvidia,tegra114-udc",
55 .data = &tegra114_udc_soc_info,
56 }, {
57 .compatible = "nvidia,tegra124-udc",
58 .data = &tegra124_udc_soc_info,
59 }, {
60 /* sentinel */
63 MODULE_DEVICE_TABLE(of, tegra_udc_of_match);
65 static int tegra_udc_probe(struct platform_device *pdev)
67 const struct tegra_udc_soc_info *soc;
68 struct tegra_udc *udc;
69 int err;
71 udc = devm_kzalloc(&pdev->dev, sizeof(*udc), GFP_KERNEL);
72 if (!udc)
73 return -ENOMEM;
75 soc = of_device_get_match_data(&pdev->dev);
76 if (!soc) {
77 dev_err(&pdev->dev, "failed to match OF data\n");
78 return -EINVAL;
81 udc->phy = devm_usb_get_phy_by_phandle(&pdev->dev, "nvidia,phy", 0);
82 if (IS_ERR(udc->phy)) {
83 err = PTR_ERR(udc->phy);
84 dev_err(&pdev->dev, "failed to get PHY: %d\n", err);
85 return err;
88 udc->clk = devm_clk_get(&pdev->dev, NULL);
89 if (IS_ERR(udc->clk)) {
90 err = PTR_ERR(udc->clk);
91 dev_err(&pdev->dev, "failed to get clock: %d\n", err);
92 return err;
95 err = clk_prepare_enable(udc->clk);
96 if (err < 0) {
97 dev_err(&pdev->dev, "failed to enable clock: %d\n", err);
98 return err;
102 * Tegra's USB PHY driver doesn't implement optional phy_init()
103 * hook, so we have to power on UDC controller before ChipIdea
104 * driver initialization kicks in.
106 usb_phy_set_suspend(udc->phy, 0);
108 /* setup and register ChipIdea HDRC device */
109 udc->data.name = "tegra-udc";
110 udc->data.flags = soc->flags;
111 udc->data.usb_phy = udc->phy;
112 udc->data.capoffset = DEF_CAPOFFSET;
114 udc->dev = ci_hdrc_add_device(&pdev->dev, pdev->resource,
115 pdev->num_resources, &udc->data);
116 if (IS_ERR(udc->dev)) {
117 err = PTR_ERR(udc->dev);
118 dev_err(&pdev->dev, "failed to add HDRC device: %d\n", err);
119 goto fail_power_off;
122 platform_set_drvdata(pdev, udc);
124 return 0;
126 fail_power_off:
127 usb_phy_set_suspend(udc->phy, 1);
128 clk_disable_unprepare(udc->clk);
129 return err;
132 static int tegra_udc_remove(struct platform_device *pdev)
134 struct tegra_udc *udc = platform_get_drvdata(pdev);
136 usb_phy_set_suspend(udc->phy, 1);
137 clk_disable_unprepare(udc->clk);
139 return 0;
142 static struct platform_driver tegra_udc_driver = {
143 .driver = {
144 .name = "tegra-udc",
145 .of_match_table = tegra_udc_of_match,
147 .probe = tegra_udc_probe,
148 .remove = tegra_udc_remove,
150 module_platform_driver(tegra_udc_driver);
152 MODULE_DESCRIPTION("NVIDIA Tegra USB device mode driver");
153 MODULE_AUTHOR("Thierry Reding <treding@nvidia.com>");
154 MODULE_ALIAS("platform:tegra-udc");
155 MODULE_LICENSE("GPL v2");