blob: 50c7629b5860f3471e99415acfa9fd16295435c3 [file] [log] [blame]
Kishon Vijay Abraham Iff764962013-09-27 11:53:25 +05301/*
2 * phy.h -- generic phy header file
3 *
4 * Copyright (C) 2013 Texas Instruments Incorporated - http://www.ti.com
5 *
6 * Author: Kishon Vijay Abraham I <kishon@ti.com>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 */
13
14#ifndef __DRIVERS_PHY_H
15#define __DRIVERS_PHY_H
16
17#include <linux/err.h>
18#include <linux/of.h>
19#include <linux/device.h>
20#include <linux/pm_runtime.h>
21
22struct phy;
23
24/**
25 * struct phy_ops - set of function pointers for performing phy operations
26 * @init: operation to be performed for initializing phy
27 * @exit: operation to be performed while exiting
28 * @power_on: powering on the phy
29 * @power_off: powering off the phy
30 * @owner: the module owner containing the ops
31 */
32struct phy_ops {
33 int (*init)(struct phy *phy);
34 int (*exit)(struct phy *phy);
35 int (*power_on)(struct phy *phy);
36 int (*power_off)(struct phy *phy);
37 struct module *owner;
38};
39
40/**
Matt Porter8feed342013-12-19 09:23:02 -050041 * struct phy_attrs - represents phy attributes
42 * @bus_width: Data path width implemented by PHY
43 */
44struct phy_attrs {
45 u32 bus_width;
46};
47
48/**
Kishon Vijay Abraham Iff764962013-09-27 11:53:25 +053049 * struct phy - represents the phy device
50 * @dev: phy device
51 * @id: id of the phy device
52 * @ops: function pointers for performing phy operations
53 * @init_data: list of PHY consumers (non-dt only)
54 * @mutex: mutex to protect phy_ops
55 * @init_count: used to protect when the PHY is used by multiple consumers
56 * @power_count: used to protect when the PHY is used by multiple consumers
Matt Porter8feed342013-12-19 09:23:02 -050057 * @phy_attrs: used to specify PHY specific attributes
Kishon Vijay Abraham Iff764962013-09-27 11:53:25 +053058 */
59struct phy {
60 struct device dev;
61 int id;
62 const struct phy_ops *ops;
63 struct phy_init_data *init_data;
64 struct mutex mutex;
65 int init_count;
66 int power_count;
Matt Porter8feed342013-12-19 09:23:02 -050067 struct phy_attrs attrs;
Kishon Vijay Abraham Iff764962013-09-27 11:53:25 +053068};
69
70/**
71 * struct phy_provider - represents the phy provider
72 * @dev: phy provider device
73 * @owner: the module owner having of_xlate
74 * @of_xlate: function pointer to obtain phy instance from phy pointer
75 * @list: to maintain a linked list of PHY providers
76 */
77struct phy_provider {
78 struct device *dev;
79 struct module *owner;
80 struct list_head list;
81 struct phy * (*of_xlate)(struct device *dev,
82 struct of_phandle_args *args);
83};
84
85/**
86 * struct phy_consumer - represents the phy consumer
87 * @dev_name: the device name of the controller that will use this PHY device
88 * @port: name given to the consumer port
89 */
90struct phy_consumer {
91 const char *dev_name;
92 const char *port;
93};
94
95/**
96 * struct phy_init_data - contains the list of PHY consumers
97 * @num_consumers: number of consumers for this PHY device
98 * @consumers: list of PHY consumers
99 */
100struct phy_init_data {
101 unsigned int num_consumers;
102 struct phy_consumer *consumers;
103};
104
105#define PHY_CONSUMER(_dev_name, _port) \
106{ \
107 .dev_name = _dev_name, \
108 .port = _port, \
109}
110
111#define to_phy(dev) (container_of((dev), struct phy, dev))
112
113#define of_phy_provider_register(dev, xlate) \
114 __of_phy_provider_register((dev), THIS_MODULE, (xlate))
115
116#define devm_of_phy_provider_register(dev, xlate) \
117 __devm_of_phy_provider_register((dev), THIS_MODULE, (xlate))
118
119static inline void phy_set_drvdata(struct phy *phy, void *data)
120{
121 dev_set_drvdata(&phy->dev, data);
122}
123
124static inline void *phy_get_drvdata(struct phy *phy)
125{
126 return dev_get_drvdata(&phy->dev);
127}
128
129#if IS_ENABLED(CONFIG_GENERIC_PHY)
130int phy_pm_runtime_get(struct phy *phy);
131int phy_pm_runtime_get_sync(struct phy *phy);
132int phy_pm_runtime_put(struct phy *phy);
133int phy_pm_runtime_put_sync(struct phy *phy);
134void phy_pm_runtime_allow(struct phy *phy);
135void phy_pm_runtime_forbid(struct phy *phy);
136int phy_init(struct phy *phy);
137int phy_exit(struct phy *phy);
138int phy_power_on(struct phy *phy);
139int phy_power_off(struct phy *phy);
Matt Porter8feed342013-12-19 09:23:02 -0500140static inline int phy_get_bus_width(struct phy *phy)
141{
142 return phy->attrs.bus_width;
143}
144static inline void phy_set_bus_width(struct phy *phy, int bus_width)
145{
146 phy->attrs.bus_width = bus_width;
147}
Kishon Vijay Abraham Iff764962013-09-27 11:53:25 +0530148struct phy *phy_get(struct device *dev, const char *string);
Andrew Lunn788a4d52014-02-04 18:33:12 +0100149struct phy *phy_optional_get(struct device *dev, const char *string);
Kishon Vijay Abraham Iff764962013-09-27 11:53:25 +0530150struct phy *devm_phy_get(struct device *dev, const char *string);
Andrew Lunn788a4d52014-02-04 18:33:12 +0100151struct phy *devm_phy_optional_get(struct device *dev, const char *string);
Kishon Vijay Abraham Iff764962013-09-27 11:53:25 +0530152void phy_put(struct phy *phy);
153void devm_phy_put(struct device *dev, struct phy *phy);
Kamil Debski0b3f3b22014-03-06 12:16:46 +0100154struct phy *of_phy_get(struct device_node *np, const char *con_id);
Kishon Vijay Abraham Iff764962013-09-27 11:53:25 +0530155struct phy *of_phy_simple_xlate(struct device *dev,
156 struct of_phandle_args *args);
157struct phy *phy_create(struct device *dev, const struct phy_ops *ops,
158 struct phy_init_data *init_data);
159struct phy *devm_phy_create(struct device *dev,
160 const struct phy_ops *ops, struct phy_init_data *init_data);
161void phy_destroy(struct phy *phy);
162void devm_phy_destroy(struct device *dev, struct phy *phy);
163struct phy_provider *__of_phy_provider_register(struct device *dev,
164 struct module *owner, struct phy * (*of_xlate)(struct device *dev,
165 struct of_phandle_args *args));
166struct phy_provider *__devm_of_phy_provider_register(struct device *dev,
167 struct module *owner, struct phy * (*of_xlate)(struct device *dev,
168 struct of_phandle_args *args));
169void of_phy_provider_unregister(struct phy_provider *phy_provider);
170void devm_of_phy_provider_unregister(struct device *dev,
171 struct phy_provider *phy_provider);
172#else
173static inline int phy_pm_runtime_get(struct phy *phy)
174{
175 return -ENOSYS;
176}
177
178static inline int phy_pm_runtime_get_sync(struct phy *phy)
179{
180 return -ENOSYS;
181}
182
183static inline int phy_pm_runtime_put(struct phy *phy)
184{
185 return -ENOSYS;
186}
187
188static inline int phy_pm_runtime_put_sync(struct phy *phy)
189{
190 return -ENOSYS;
191}
192
193static inline void phy_pm_runtime_allow(struct phy *phy)
194{
195 return;
196}
197
198static inline void phy_pm_runtime_forbid(struct phy *phy)
199{
200 return;
201}
202
203static inline int phy_init(struct phy *phy)
204{
205 return -ENOSYS;
206}
207
208static inline int phy_exit(struct phy *phy)
209{
210 return -ENOSYS;
211}
212
213static inline int phy_power_on(struct phy *phy)
214{
215 return -ENOSYS;
216}
217
218static inline int phy_power_off(struct phy *phy)
219{
220 return -ENOSYS;
221}
222
Matt Porter8feed342013-12-19 09:23:02 -0500223static inline int phy_get_bus_width(struct phy *phy)
224{
225 return -ENOSYS;
226}
227
228static inline void phy_set_bus_width(struct phy *phy, int bus_width)
229{
230 return;
231}
232
Kishon Vijay Abraham Iff764962013-09-27 11:53:25 +0530233static inline struct phy *phy_get(struct device *dev, const char *string)
234{
235 return ERR_PTR(-ENOSYS);
236}
237
Andrew Lunn788a4d52014-02-04 18:33:12 +0100238static inline struct phy *phy_optional_get(struct device *dev,
239 const char *string)
240{
241 return ERR_PTR(-ENOSYS);
242}
243
Kishon Vijay Abraham Iff764962013-09-27 11:53:25 +0530244static inline struct phy *devm_phy_get(struct device *dev, const char *string)
245{
246 return ERR_PTR(-ENOSYS);
247}
248
Andrew Lunn788a4d52014-02-04 18:33:12 +0100249static inline struct phy *devm_phy_optional_get(struct device *dev,
250 const char *string)
251{
252 return ERR_PTR(-ENOSYS);
253}
254
Kishon Vijay Abraham Iff764962013-09-27 11:53:25 +0530255static inline void phy_put(struct phy *phy)
256{
257}
258
259static inline void devm_phy_put(struct device *dev, struct phy *phy)
260{
261}
262
Kamil Debski0b3f3b22014-03-06 12:16:46 +0100263static inline struct phy *of_phy_get(struct device_node *np, const char *con_id)
264{
265 return ERR_PTR(-ENOSYS);
266}
267
Kishon Vijay Abraham Iff764962013-09-27 11:53:25 +0530268static inline struct phy *of_phy_simple_xlate(struct device *dev,
269 struct of_phandle_args *args)
270{
271 return ERR_PTR(-ENOSYS);
272}
273
274static inline struct phy *phy_create(struct device *dev,
275 const struct phy_ops *ops, struct phy_init_data *init_data)
276{
277 return ERR_PTR(-ENOSYS);
278}
279
280static inline struct phy *devm_phy_create(struct device *dev,
281 const struct phy_ops *ops, struct phy_init_data *init_data)
282{
283 return ERR_PTR(-ENOSYS);
284}
285
286static inline void phy_destroy(struct phy *phy)
287{
288}
289
290static inline void devm_phy_destroy(struct device *dev, struct phy *phy)
291{
292}
293
294static inline struct phy_provider *__of_phy_provider_register(
295 struct device *dev, struct module *owner, struct phy * (*of_xlate)(
296 struct device *dev, struct of_phandle_args *args))
297{
298 return ERR_PTR(-ENOSYS);
299}
300
301static inline struct phy_provider *__devm_of_phy_provider_register(struct device
302 *dev, struct module *owner, struct phy * (*of_xlate)(struct device *dev,
303 struct of_phandle_args *args))
304{
305 return ERR_PTR(-ENOSYS);
306}
307
308static inline void of_phy_provider_unregister(struct phy_provider *phy_provider)
309{
310}
311
312static inline void devm_of_phy_provider_unregister(struct device *dev,
313 struct phy_provider *phy_provider)
314{
315}
316#endif
317
318#endif /* __DRIVERS_PHY_H */