phy: core: Fix of_phy_provider_lookup to return PHY provider for sub node
[deliverable/linux.git] / include / linux / phy / phy.h
CommitLineData
ff764963
KVA
1/*
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>
3be88125 21#include <linux/regulator/consumer.h>
ff764963
KVA
22
23struct phy;
24
25/**
26 * struct phy_ops - set of function pointers for performing phy operations
27 * @init: operation to be performed for initializing phy
28 * @exit: operation to be performed while exiting
29 * @power_on: powering on the phy
30 * @power_off: powering off the phy
31 * @owner: the module owner containing the ops
32 */
33struct phy_ops {
34 int (*init)(struct phy *phy);
35 int (*exit)(struct phy *phy);
36 int (*power_on)(struct phy *phy);
37 int (*power_off)(struct phy *phy);
38 struct module *owner;
39};
40
8feed347
MP
41/**
42 * struct phy_attrs - represents phy attributes
43 * @bus_width: Data path width implemented by PHY
44 */
45struct phy_attrs {
46 u32 bus_width;
47};
48
ff764963
KVA
49/**
50 * struct phy - represents the phy device
51 * @dev: phy device
52 * @id: id of the phy device
53 * @ops: function pointers for performing phy operations
54 * @init_data: list of PHY consumers (non-dt only)
55 * @mutex: mutex to protect phy_ops
56 * @init_count: used to protect when the PHY is used by multiple consumers
57 * @power_count: used to protect when the PHY is used by multiple consumers
8feed347 58 * @phy_attrs: used to specify PHY specific attributes
ff764963
KVA
59 */
60struct phy {
61 struct device dev;
62 int id;
63 const struct phy_ops *ops;
64 struct phy_init_data *init_data;
65 struct mutex mutex;
66 int init_count;
67 int power_count;
8feed347 68 struct phy_attrs attrs;
3be88125 69 struct regulator *pwr;
ff764963
KVA
70};
71
72/**
73 * struct phy_provider - represents the phy provider
74 * @dev: phy provider device
75 * @owner: the module owner having of_xlate
76 * @of_xlate: function pointer to obtain phy instance from phy pointer
77 * @list: to maintain a linked list of PHY providers
78 */
79struct phy_provider {
80 struct device *dev;
81 struct module *owner;
82 struct list_head list;
83 struct phy * (*of_xlate)(struct device *dev,
84 struct of_phandle_args *args);
85};
86
87/**
88 * struct phy_consumer - represents the phy consumer
89 * @dev_name: the device name of the controller that will use this PHY device
90 * @port: name given to the consumer port
91 */
92struct phy_consumer {
93 const char *dev_name;
94 const char *port;
95};
96
97/**
98 * struct phy_init_data - contains the list of PHY consumers
99 * @num_consumers: number of consumers for this PHY device
100 * @consumers: list of PHY consumers
101 */
102struct phy_init_data {
103 unsigned int num_consumers;
104 struct phy_consumer *consumers;
105};
106
107#define PHY_CONSUMER(_dev_name, _port) \
108{ \
109 .dev_name = _dev_name, \
110 .port = _port, \
111}
112
113#define to_phy(dev) (container_of((dev), struct phy, dev))
114
115#define of_phy_provider_register(dev, xlate) \
116 __of_phy_provider_register((dev), THIS_MODULE, (xlate))
117
118#define devm_of_phy_provider_register(dev, xlate) \
119 __devm_of_phy_provider_register((dev), THIS_MODULE, (xlate))
120
121static inline void phy_set_drvdata(struct phy *phy, void *data)
122{
123 dev_set_drvdata(&phy->dev, data);
124}
125
126static inline void *phy_get_drvdata(struct phy *phy)
127{
128 return dev_get_drvdata(&phy->dev);
129}
130
131#if IS_ENABLED(CONFIG_GENERIC_PHY)
132int phy_pm_runtime_get(struct phy *phy);
133int phy_pm_runtime_get_sync(struct phy *phy);
134int phy_pm_runtime_put(struct phy *phy);
135int phy_pm_runtime_put_sync(struct phy *phy);
136void phy_pm_runtime_allow(struct phy *phy);
137void phy_pm_runtime_forbid(struct phy *phy);
138int phy_init(struct phy *phy);
139int phy_exit(struct phy *phy);
140int phy_power_on(struct phy *phy);
141int phy_power_off(struct phy *phy);
8feed347
MP
142static inline int phy_get_bus_width(struct phy *phy)
143{
144 return phy->attrs.bus_width;
145}
146static inline void phy_set_bus_width(struct phy *phy, int bus_width)
147{
148 phy->attrs.bus_width = bus_width;
149}
ff764963 150struct phy *phy_get(struct device *dev, const char *string);
788a4d56 151struct phy *phy_optional_get(struct device *dev, const char *string);
ff764963 152struct phy *devm_phy_get(struct device *dev, const char *string);
788a4d56 153struct phy *devm_phy_optional_get(struct device *dev, const char *string);
b5d682f4
KD
154struct phy *devm_of_phy_get(struct device *dev, struct device_node *np,
155 const char *con_id);
ff764963
KVA
156void phy_put(struct phy *phy);
157void devm_phy_put(struct device *dev, struct phy *phy);
0b3f3b2c 158struct phy *of_phy_get(struct device_node *np, const char *con_id);
ff764963
KVA
159struct phy *of_phy_simple_xlate(struct device *dev,
160 struct of_phandle_args *args);
161struct phy *phy_create(struct device *dev, const struct phy_ops *ops,
162 struct phy_init_data *init_data);
163struct phy *devm_phy_create(struct device *dev,
164 const struct phy_ops *ops, struct phy_init_data *init_data);
165void phy_destroy(struct phy *phy);
166void devm_phy_destroy(struct device *dev, struct phy *phy);
167struct phy_provider *__of_phy_provider_register(struct device *dev,
168 struct module *owner, struct phy * (*of_xlate)(struct device *dev,
169 struct of_phandle_args *args));
170struct phy_provider *__devm_of_phy_provider_register(struct device *dev,
171 struct module *owner, struct phy * (*of_xlate)(struct device *dev,
172 struct of_phandle_args *args));
173void of_phy_provider_unregister(struct phy_provider *phy_provider);
174void devm_of_phy_provider_unregister(struct device *dev,
175 struct phy_provider *phy_provider);
176#else
177static inline int phy_pm_runtime_get(struct phy *phy)
178{
2b97789f
GS
179 if (!phy)
180 return 0;
ff764963
KVA
181 return -ENOSYS;
182}
183
184static inline int phy_pm_runtime_get_sync(struct phy *phy)
185{
2b97789f
GS
186 if (!phy)
187 return 0;
ff764963
KVA
188 return -ENOSYS;
189}
190
191static inline int phy_pm_runtime_put(struct phy *phy)
192{
2b97789f
GS
193 if (!phy)
194 return 0;
ff764963
KVA
195 return -ENOSYS;
196}
197
198static inline int phy_pm_runtime_put_sync(struct phy *phy)
199{
2b97789f
GS
200 if (!phy)
201 return 0;
ff764963
KVA
202 return -ENOSYS;
203}
204
205static inline void phy_pm_runtime_allow(struct phy *phy)
206{
207 return;
208}
209
210static inline void phy_pm_runtime_forbid(struct phy *phy)
211{
212 return;
213}
214
215static inline int phy_init(struct phy *phy)
216{
2b97789f
GS
217 if (!phy)
218 return 0;
ff764963
KVA
219 return -ENOSYS;
220}
221
222static inline int phy_exit(struct phy *phy)
223{
2b97789f
GS
224 if (!phy)
225 return 0;
ff764963
KVA
226 return -ENOSYS;
227}
228
229static inline int phy_power_on(struct phy *phy)
230{
2b97789f
GS
231 if (!phy)
232 return 0;
ff764963
KVA
233 return -ENOSYS;
234}
235
236static inline int phy_power_off(struct phy *phy)
237{
2b97789f
GS
238 if (!phy)
239 return 0;
ff764963
KVA
240 return -ENOSYS;
241}
242
8feed347
MP
243static inline int phy_get_bus_width(struct phy *phy)
244{
245 return -ENOSYS;
246}
247
248static inline void phy_set_bus_width(struct phy *phy, int bus_width)
249{
250 return;
251}
252
ff764963
KVA
253static inline struct phy *phy_get(struct device *dev, const char *string)
254{
255 return ERR_PTR(-ENOSYS);
256}
257
788a4d56
AL
258static inline struct phy *phy_optional_get(struct device *dev,
259 const char *string)
260{
261 return ERR_PTR(-ENOSYS);
262}
263
ff764963
KVA
264static inline struct phy *devm_phy_get(struct device *dev, const char *string)
265{
266 return ERR_PTR(-ENOSYS);
267}
268
788a4d56
AL
269static inline struct phy *devm_phy_optional_get(struct device *dev,
270 const char *string)
271{
272 return ERR_PTR(-ENOSYS);
273}
274
b5d682f4
KD
275static inline struct phy *devm_of_phy_get(struct device *dev,
276 struct device_node *np,
277 const char *con_id)
278{
279 return ERR_PTR(-ENOSYS);
280}
281
ff764963
KVA
282static inline void phy_put(struct phy *phy)
283{
284}
285
286static inline void devm_phy_put(struct device *dev, struct phy *phy)
287{
288}
289
0b3f3b2c
KD
290static inline struct phy *of_phy_get(struct device_node *np, const char *con_id)
291{
292 return ERR_PTR(-ENOSYS);
293}
294
ff764963
KVA
295static inline struct phy *of_phy_simple_xlate(struct device *dev,
296 struct of_phandle_args *args)
297{
298 return ERR_PTR(-ENOSYS);
299}
300
301static inline struct phy *phy_create(struct device *dev,
302 const struct phy_ops *ops, struct phy_init_data *init_data)
303{
304 return ERR_PTR(-ENOSYS);
305}
306
307static inline struct phy *devm_phy_create(struct device *dev,
308 const struct phy_ops *ops, struct phy_init_data *init_data)
309{
310 return ERR_PTR(-ENOSYS);
311}
312
313static inline void phy_destroy(struct phy *phy)
314{
315}
316
317static inline void devm_phy_destroy(struct device *dev, struct phy *phy)
318{
319}
320
321static inline struct phy_provider *__of_phy_provider_register(
322 struct device *dev, struct module *owner, struct phy * (*of_xlate)(
323 struct device *dev, struct of_phandle_args *args))
324{
325 return ERR_PTR(-ENOSYS);
326}
327
328static inline struct phy_provider *__devm_of_phy_provider_register(struct device
329 *dev, struct module *owner, struct phy * (*of_xlate)(struct device *dev,
330 struct of_phandle_args *args))
331{
332 return ERR_PTR(-ENOSYS);
333}
334
335static inline void of_phy_provider_unregister(struct phy_provider *phy_provider)
336{
337}
338
339static inline void devm_of_phy_provider_unregister(struct device *dev,
340 struct phy_provider *phy_provider)
341{
342}
343#endif
344
345#endif /* __DRIVERS_PHY_H */
This page took 0.154725 seconds and 5 git commands to generate.