Linux kernel mirror (for testing)
git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel
os
linux
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>
21#include <linux/regulator/consumer.h>
22
23struct phy;
24
25enum phy_mode {
26 PHY_MODE_INVALID,
27 PHY_MODE_USB_HOST,
28 PHY_MODE_USB_DEVICE,
29 PHY_MODE_USB_OTG,
30};
31
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
38 * @set_mode: set the mode of the phy
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);
46 int (*set_mode)(struct phy *phy, enum phy_mode mode);
47 struct module *owner;
48};
49
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
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
67 * @phy_attrs: used to specify PHY specific attributes
68 */
69struct phy {
70 struct device dev;
71 int id;
72 const struct phy_ops *ops;
73 struct mutex mutex;
74 int init_count;
75 int power_count;
76 struct phy_attrs attrs;
77 struct regulator *pwr;
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;
89 struct device_node *children;
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
96struct phy_lookup {
97 struct list_head node;
98 const char *dev_id;
99 const char *con_id;
100 struct phy *phy;
101};
102
103#define to_phy(a) (container_of((a), struct phy, dev))
104
105#define of_phy_provider_register(dev, xlate) \
106 __of_phy_provider_register((dev), NULL, THIS_MODULE, (xlate))
107
108#define devm_of_phy_provider_register(dev, xlate) \
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)
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);
138int phy_set_mode(struct phy *phy, enum phy_mode mode);
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}
147struct phy *phy_get(struct device *dev, const char *string);
148struct phy *phy_optional_get(struct device *dev, const char *string);
149struct phy *devm_phy_get(struct device *dev, const char *string);
150struct phy *devm_phy_optional_get(struct device *dev, const char *string);
151struct phy *devm_of_phy_get(struct device *dev, struct device_node *np,
152 const char *con_id);
153struct phy *devm_of_phy_get_by_index(struct device *dev, struct device_node *np,
154 int index);
155void phy_put(struct phy *phy);
156void devm_phy_put(struct device *dev, struct phy *phy);
157struct phy *of_phy_get(struct device_node *np, const char *con_id);
158struct phy *of_phy_simple_xlate(struct device *dev,
159 struct of_phandle_args *args);
160struct phy *phy_create(struct device *dev, struct device_node *node,
161 const struct phy_ops *ops);
162struct phy *devm_phy_create(struct device *dev, struct device_node *node,
163 const struct phy_ops *ops);
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,
167 struct device_node *children, struct module *owner,
168 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 device_node *children, struct module *owner,
172 struct phy * (*of_xlate)(struct device *dev,
173 struct of_phandle_args *args));
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);
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);
179#else
180static inline int phy_pm_runtime_get(struct phy *phy)
181{
182 if (!phy)
183 return 0;
184 return -ENOSYS;
185}
186
187static inline int phy_pm_runtime_get_sync(struct phy *phy)
188{
189 if (!phy)
190 return 0;
191 return -ENOSYS;
192}
193
194static inline int phy_pm_runtime_put(struct phy *phy)
195{
196 if (!phy)
197 return 0;
198 return -ENOSYS;
199}
200
201static inline int phy_pm_runtime_put_sync(struct phy *phy)
202{
203 if (!phy)
204 return 0;
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{
220 if (!phy)
221 return 0;
222 return -ENOSYS;
223}
224
225static inline int phy_exit(struct phy *phy)
226{
227 if (!phy)
228 return 0;
229 return -ENOSYS;
230}
231
232static inline int phy_power_on(struct phy *phy)
233{
234 if (!phy)
235 return 0;
236 return -ENOSYS;
237}
238
239static inline int phy_power_off(struct phy *phy)
240{
241 if (!phy)
242 return 0;
243 return -ENOSYS;
244}
245
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
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
263static inline struct phy *phy_get(struct device *dev, const char *string)
264{
265 return ERR_PTR(-ENOSYS);
266}
267
268static inline struct phy *phy_optional_get(struct device *dev,
269 const char *string)
270{
271 return ERR_PTR(-ENOSYS);
272}
273
274static inline struct phy *devm_phy_get(struct device *dev, const char *string)
275{
276 return ERR_PTR(-ENOSYS);
277}
278
279static inline struct phy *devm_phy_optional_get(struct device *dev,
280 const char *string)
281{
282 return ERR_PTR(-ENOSYS);
283}
284
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
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
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
307static inline struct phy *of_phy_get(struct device_node *np, const char *con_id)
308{
309 return ERR_PTR(-ENOSYS);
310}
311
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,
319 struct device_node *node,
320 const struct phy_ops *ops)
321{
322 return ERR_PTR(-ENOSYS);
323}
324
325static inline struct phy *devm_phy_create(struct device *dev,
326 struct device_node *node,
327 const struct phy_ops *ops)
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(
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))
344{
345 return ERR_PTR(-ENOSYS);
346}
347
348static inline struct phy_provider *__devm_of_phy_provider_register(struct device
349 *dev, struct device_node *children, struct module *owner,
350 struct phy * (*of_xlate)(struct device *dev,
351 struct of_phandle_args *args))
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}
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) { }
371#endif
372
373#endif /* __DRIVERS_PHY_H */