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