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