summaryrefslogtreecommitdiffstats
path: root/drivers/phy/qualcomm/phy-qcom-ipq4019-usb.c
blob: b8ef331e154516b5fd5dd9be0aee4902325920eb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
// SPDX-License-Identifier: GPL-2.0-or-later
/*
 * Copyright (C) 2018 John Crispin <john@phrozen.org>
 *
 * Based on code from
 * Allwinner Technology Co., Ltd. <www.allwinnertech.com>
 *
 */

#include <linux/delay.h>
#include <linux/err.h>
#include <linux/io.h>
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/mutex.h>
#include <linux/of_platform.h>
#include <linux/of_device.h>
#include <linux/phy/phy.h>
#include <linux/platform_device.h>
#include <linux/reset.h>

struct ipq4019_usb_phy {
	struct device		*dev;
	struct phy		*phy;
	void __iomem		*base;
	struct reset_control	*por_rst;
	struct reset_control	*srif_rst;
};

static int ipq4019_ss_phy_power_off(struct phy *_phy)
{
	struct ipq4019_usb_phy *phy = phy_get_drvdata(_phy);

	reset_control_assert(phy->por_rst);
	msleep(10);

	return 0;
}

static int ipq4019_ss_phy_power_on(struct phy *_phy)
{
	struct ipq4019_usb_phy *phy = phy_get_drvdata(_phy);

	ipq4019_ss_phy_power_off(_phy);

	reset_control_deassert(phy->por_rst);

	return 0;
}

static struct phy_ops ipq4019_usb_ss_phy_ops = {
	.power_on	= ipq4019_ss_phy_power_on,
	.power_off	= ipq4019_ss_phy_power_off,
};

static int ipq4019_hs_phy_power_off(struct phy *_phy)
{
	struct ipq4019_usb_phy *phy = phy_get_drvdata(_phy);

	reset_control_assert(phy->por_rst);
	msleep(10);

	reset_control_assert(phy->srif_rst);
	msleep(10);

	return 0;
}

static int ipq4019_hs_phy_power_on(struct phy *_phy)
{
	struct ipq4019_usb_phy *phy = phy_get_drvdata(_phy);

	ipq4019_hs_phy_power_off(_phy);

	reset_control_deassert(phy->srif_rst);
	msleep(10);

	reset_control_deassert(phy->por_rst);

	return 0;
}

static struct phy_ops ipq4019_usb_hs_phy_ops = {
	.power_on	= ipq4019_hs_phy_power_on,
	.power_off	= ipq4019_hs_phy_power_off,
};

static const struct of_device_id ipq4019_usb_phy_of_match[] = {
	{ .compatible = "qcom,usb-hs-ipq4019-phy", .data = &ipq4019_usb_hs_phy_ops},
	{ .compatible = "qcom,usb-ss-ipq4019-phy", .data = &ipq4019_usb_ss_phy_ops},
	{ },
};
MODULE_DEVICE_TABLE(of, ipq4019_usb_phy_of_match);

static int ipq4019_usb_phy_probe(struct platform_device *pdev)
{
	struct device *dev = &pdev->dev;
	struct resource *res;
	struct phy_provider *phy_provider;
	struct ipq4019_usb_phy *phy;

	phy = devm_kzalloc(dev, sizeof(*phy), GFP_KERNEL);
	if (!phy)
		return -ENOMEM;

	phy->dev = &pdev->dev;
	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
	phy->base = devm_ioremap_resource(&pdev->dev, res);
	if (IS_ERR(phy->base)) {
		dev_err(dev, "failed to remap register memory\n");
		return PTR_ERR(phy->base);
	}

	phy->por_rst = devm_reset_control_get(phy->dev, "por_rst");
	if (IS_ERR(phy->por_rst)) {
		if (PTR_ERR(phy->por_rst) != -EPROBE_DEFER)
			dev_err(dev, "POR reset is missing\n");
		return PTR_ERR(phy->por_rst);
	}

	phy->srif_rst = devm_reset_control_get_optional(phy->dev, "srif_rst");
	if (IS_ERR(phy->srif_rst))
		return PTR_ERR(phy->srif_rst);

	phy->phy = devm_phy_create(dev, NULL, of_device_get_match_data(dev));
	if (IS_ERR(phy->phy)) {
		dev_err(dev, "failed to create PHY\n");
		return PTR_ERR(phy->phy);
	}
	phy_set_drvdata(phy->phy, phy);

	phy_provider = devm_of_phy_provider_register(dev, of_phy_simple_xlate);

	return PTR_ERR_OR_ZERO(phy_provider);
}

static struct platform_driver ipq4019_usb_phy_driver = {
	.probe	= ipq4019_usb_phy_probe,
	.driver = {
		.of_match_table	= ipq4019_usb_phy_of_match,
		.name  = "ipq4019-usb-phy",
	}
};
module_platform_driver(ipq4019_usb_phy_driver);

MODULE_DESCRIPTION("QCOM/IPQ4019 USB phy driver");
MODULE_AUTHOR("John Crispin <john@phrozen.org>");
MODULE_LICENSE("GPL v2");