Merge tag 'xfs-for-linus-4.2-rc4' of git://git.kernel.org/pub/scm/linux/kernel/git...
[linux-2.6-block.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;
ff764963
KVA
64 struct mutex mutex;
65 int init_count;
66 int power_count;
8feed347 67 struct phy_attrs attrs;
3be88125 68 struct regulator *pwr;
ff764963
KVA
69};
70
71/**
72 * struct phy_provider - represents the phy provider
73 * @dev: phy provider device
74 * @owner: the module owner having of_xlate
75 * @of_xlate: function pointer to obtain phy instance from phy pointer
76 * @list: to maintain a linked list of PHY providers
77 */
78struct phy_provider {
79 struct device *dev;
80 struct module *owner;
81 struct list_head list;
82 struct phy * (*of_xlate)(struct device *dev,
83 struct of_phandle_args *args);
84};
85
b7bc15b9
HK
86struct phy_lookup {
87 struct list_head node;
88 const char *dev_id;
89 const char *con_id;
90 struct phy *phy;
91};
92
d4510574 93#define to_phy(a) (container_of((a), struct phy, dev))
ff764963
KVA
94
95#define of_phy_provider_register(dev, xlate) \
96 __of_phy_provider_register((dev), THIS_MODULE, (xlate))
97
98#define devm_of_phy_provider_register(dev, xlate) \
99 __devm_of_phy_provider_register((dev), THIS_MODULE, (xlate))
100
101static inline void phy_set_drvdata(struct phy *phy, void *data)
102{
103 dev_set_drvdata(&phy->dev, data);
104}
105
106static inline void *phy_get_drvdata(struct phy *phy)
107{
108 return dev_get_drvdata(&phy->dev);
109}
110
111#if IS_ENABLED(CONFIG_GENERIC_PHY)
112int phy_pm_runtime_get(struct phy *phy);
113int phy_pm_runtime_get_sync(struct phy *phy);
114int phy_pm_runtime_put(struct phy *phy);
115int phy_pm_runtime_put_sync(struct phy *phy);
116void phy_pm_runtime_allow(struct phy *phy);
117void phy_pm_runtime_forbid(struct phy *phy);
118int phy_init(struct phy *phy);
119int phy_exit(struct phy *phy);
120int phy_power_on(struct phy *phy);
121int phy_power_off(struct phy *phy);
8feed347
MP
122static inline int phy_get_bus_width(struct phy *phy)
123{
124 return phy->attrs.bus_width;
125}
126static inline void phy_set_bus_width(struct phy *phy, int bus_width)
127{
128 phy->attrs.bus_width = bus_width;
129}
ff764963 130struct phy *phy_get(struct device *dev, const char *string);
788a4d56 131struct phy *phy_optional_get(struct device *dev, const char *string);
ff764963 132struct phy *devm_phy_get(struct device *dev, const char *string);
788a4d56 133struct phy *devm_phy_optional_get(struct device *dev, const char *string);
b5d682f4
KD
134struct phy *devm_of_phy_get(struct device *dev, struct device_node *np,
135 const char *con_id);
6be109b3
AR
136struct phy *devm_of_phy_get_by_index(struct device *dev, struct device_node *np,
137 int index);
ff764963
KVA
138void phy_put(struct phy *phy);
139void devm_phy_put(struct device *dev, struct phy *phy);
0b3f3b2c 140struct phy *of_phy_get(struct device_node *np, const char *con_id);
ff764963
KVA
141struct phy *of_phy_simple_xlate(struct device *dev,
142 struct of_phandle_args *args);
f0ed8176 143struct phy *phy_create(struct device *dev, struct device_node *node,
dbc98635 144 const struct phy_ops *ops);
f0ed8176 145struct phy *devm_phy_create(struct device *dev, struct device_node *node,
dbc98635 146 const struct phy_ops *ops);
ff764963
KVA
147void phy_destroy(struct phy *phy);
148void devm_phy_destroy(struct device *dev, struct phy *phy);
149struct phy_provider *__of_phy_provider_register(struct device *dev,
150 struct module *owner, struct phy * (*of_xlate)(struct device *dev,
151 struct of_phandle_args *args));
152struct phy_provider *__devm_of_phy_provider_register(struct device *dev,
153 struct module *owner, struct phy * (*of_xlate)(struct device *dev,
154 struct of_phandle_args *args));
155void of_phy_provider_unregister(struct phy_provider *phy_provider);
156void devm_of_phy_provider_unregister(struct device *dev,
157 struct phy_provider *phy_provider);
b7bc15b9
HK
158int phy_create_lookup(struct phy *phy, const char *con_id, const char *dev_id);
159void phy_remove_lookup(struct phy *phy, const char *con_id, const char *dev_id);
ff764963
KVA
160#else
161static inline int phy_pm_runtime_get(struct phy *phy)
162{
2b97789f
GS
163 if (!phy)
164 return 0;
ff764963
KVA
165 return -ENOSYS;
166}
167
168static inline int phy_pm_runtime_get_sync(struct phy *phy)
169{
2b97789f
GS
170 if (!phy)
171 return 0;
ff764963
KVA
172 return -ENOSYS;
173}
174
175static inline int phy_pm_runtime_put(struct phy *phy)
176{
2b97789f
GS
177 if (!phy)
178 return 0;
ff764963
KVA
179 return -ENOSYS;
180}
181
182static inline int phy_pm_runtime_put_sync(struct phy *phy)
183{
2b97789f
GS
184 if (!phy)
185 return 0;
ff764963
KVA
186 return -ENOSYS;
187}
188
189static inline void phy_pm_runtime_allow(struct phy *phy)
190{
191 return;
192}
193
194static inline void phy_pm_runtime_forbid(struct phy *phy)
195{
196 return;
197}
198
199static inline int phy_init(struct phy *phy)
200{
2b97789f
GS
201 if (!phy)
202 return 0;
ff764963
KVA
203 return -ENOSYS;
204}
205
206static inline int phy_exit(struct phy *phy)
207{
2b97789f
GS
208 if (!phy)
209 return 0;
ff764963
KVA
210 return -ENOSYS;
211}
212
213static inline int phy_power_on(struct phy *phy)
214{
2b97789f
GS
215 if (!phy)
216 return 0;
ff764963
KVA
217 return -ENOSYS;
218}
219
220static inline int phy_power_off(struct phy *phy)
221{
2b97789f
GS
222 if (!phy)
223 return 0;
ff764963
KVA
224 return -ENOSYS;
225}
226
8feed347
MP
227static inline int phy_get_bus_width(struct phy *phy)
228{
229 return -ENOSYS;
230}
231
232static inline void phy_set_bus_width(struct phy *phy, int bus_width)
233{
234 return;
235}
236
ff764963
KVA
237static inline struct phy *phy_get(struct device *dev, const char *string)
238{
239 return ERR_PTR(-ENOSYS);
240}
241
788a4d56
AL
242static inline struct phy *phy_optional_get(struct device *dev,
243 const char *string)
244{
245 return ERR_PTR(-ENOSYS);
246}
247
ff764963
KVA
248static inline struct phy *devm_phy_get(struct device *dev, const char *string)
249{
250 return ERR_PTR(-ENOSYS);
251}
252
788a4d56
AL
253static inline struct phy *devm_phy_optional_get(struct device *dev,
254 const char *string)
255{
256 return ERR_PTR(-ENOSYS);
257}
258
b5d682f4
KD
259static inline struct phy *devm_of_phy_get(struct device *dev,
260 struct device_node *np,
261 const char *con_id)
262{
263 return ERR_PTR(-ENOSYS);
264}
265
6be109b3
AR
266static inline struct phy *devm_of_phy_get_by_index(struct device *dev,
267 struct device_node *np,
268 int index)
269{
270 return ERR_PTR(-ENOSYS);
271}
272
ff764963
KVA
273static inline void phy_put(struct phy *phy)
274{
275}
276
277static inline void devm_phy_put(struct device *dev, struct phy *phy)
278{
279}
280
0b3f3b2c
KD
281static inline struct phy *of_phy_get(struct device_node *np, const char *con_id)
282{
283 return ERR_PTR(-ENOSYS);
284}
285
ff764963
KVA
286static inline struct phy *of_phy_simple_xlate(struct device *dev,
287 struct of_phandle_args *args)
288{
289 return ERR_PTR(-ENOSYS);
290}
291
292static inline struct phy *phy_create(struct device *dev,
f0ed8176 293 struct device_node *node,
dbc98635 294 const struct phy_ops *ops)
ff764963
KVA
295{
296 return ERR_PTR(-ENOSYS);
297}
298
299static inline struct phy *devm_phy_create(struct device *dev,
f0ed8176 300 struct device_node *node,
dbc98635 301 const struct phy_ops *ops)
ff764963
KVA
302{
303 return ERR_PTR(-ENOSYS);
304}
305
306static inline void phy_destroy(struct phy *phy)
307{
308}
309
310static inline void devm_phy_destroy(struct device *dev, struct phy *phy)
311{
312}
313
314static inline struct phy_provider *__of_phy_provider_register(
315 struct device *dev, struct module *owner, struct phy * (*of_xlate)(
316 struct device *dev, struct of_phandle_args *args))
317{
318 return ERR_PTR(-ENOSYS);
319}
320
321static inline struct phy_provider *__devm_of_phy_provider_register(struct device
322 *dev, struct module *owner, struct phy * (*of_xlate)(struct device *dev,
323 struct of_phandle_args *args))
324{
325 return ERR_PTR(-ENOSYS);
326}
327
328static inline void of_phy_provider_unregister(struct phy_provider *phy_provider)
329{
330}
331
332static inline void devm_of_phy_provider_unregister(struct device *dev,
333 struct phy_provider *phy_provider)
334{
335}
b7bc15b9
HK
336static inline int
337phy_create_lookup(struct phy *phy, const char *con_id, const char *dev_id)
338{
339 return 0;
340}
341static inline void phy_remove_lookup(struct phy *phy, const char *con_id,
342 const char *dev_id) { }
ff764963
KVA
343#endif
344
345#endif /* __DRIVERS_PHY_H */