Linux Audio

Check our new training course

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