File Index
Files and directories
Sign in
FILE

phy.h

File preview with syntax highlighting.

linux-6.19.14/include/linux/phy/phy.h C
  1/* SPDX-License-Identifier: GPL-2.0-or-later */
  2/*
  3 * phy.h -- generic phy header file
  4 *
  5 * Copyright (C) 2013 Texas Instruments Incorporated - http://www.ti.com
  6 *
  7 * Author: Kishon Vijay Abraham I <kishon@ti.com>
  8 */
  9
 10#ifndef __DRIVERS_PHY_H
 11#define __DRIVERS_PHY_H
 12
 13#include <linux/err.h>
 14#include <linux/of.h>
 15#include <linux/device.h>
 16#include <linux/pm_runtime.h>
 17#include <linux/regulator/consumer.h>
 18
 19#include <linux/phy/phy-dp.h>
 20#include <linux/phy/phy-hdmi.h>
 21#include <linux/phy/phy-lvds.h>
 22#include <linux/phy/phy-mipi-dphy.h>
 23
 24struct phy;
 25
 26enum phy_mode {
 27	PHY_MODE_INVALID,
 28	PHY_MODE_USB_HOST,
 29	PHY_MODE_USB_HOST_LS,
 30	PHY_MODE_USB_HOST_FS,
 31	PHY_MODE_USB_HOST_HS,
 32	PHY_MODE_USB_HOST_SS,
 33	PHY_MODE_USB_DEVICE,
 34	PHY_MODE_USB_DEVICE_LS,
 35	PHY_MODE_USB_DEVICE_FS,
 36	PHY_MODE_USB_DEVICE_HS,
 37	PHY_MODE_USB_DEVICE_SS,
 38	PHY_MODE_USB_OTG,
 39	PHY_MODE_UFS_HS_A,
 40	PHY_MODE_UFS_HS_B,
 41	PHY_MODE_PCIE,
 42	PHY_MODE_ETHERNET,
 43	PHY_MODE_MIPI_DPHY,
 44	PHY_MODE_SATA,
 45	PHY_MODE_LVDS,
 46	PHY_MODE_DP,
 47	PHY_MODE_HDMI,
 48};
 49
 50enum phy_media {
 51	PHY_MEDIA_DEFAULT,
 52	PHY_MEDIA_SR,
 53	PHY_MEDIA_DAC,
 54};
 55
 56enum phy_ufs_state {
 57	PHY_UFS_HIBERN8_ENTER,
 58	PHY_UFS_HIBERN8_EXIT,
 59};
 60
 61union phy_notify {
 62	enum phy_ufs_state ufs_state;
 63};
 64
 65/**
 66 * union phy_configure_opts - Opaque generic phy configuration
 67 *
 68 * @mipi_dphy:	Configuration set applicable for phys supporting
 69 *		the MIPI_DPHY phy mode.
 70 * @dp:		Configuration set applicable for phys supporting
 71 *		the DisplayPort protocol.
 72 * @lvds:	Configuration set applicable for phys supporting
 73 *		the LVDS phy mode.
 74 * @hdmi:	Configuration set applicable for phys supporting
 75 *		the HDMI phy mode.
 76 */
 77union phy_configure_opts {
 78	struct phy_configure_opts_mipi_dphy	mipi_dphy;
 79	struct phy_configure_opts_dp		dp;
 80	struct phy_configure_opts_lvds		lvds;
 81	struct phy_configure_opts_hdmi		hdmi;
 82};
 83
 84/**
 85 * struct phy_ops - set of function pointers for performing phy operations
 86 * @init: operation to be performed for initializing phy
 87 * @exit: operation to be performed while exiting
 88 * @power_on: powering on the phy
 89 * @power_off: powering off the phy
 90 * @set_mode: set the mode of the phy
 91 * @set_media: set the media type of the phy (optional)
 92 * @set_speed: set the speed of the phy (optional)
 93 * @reset: resetting the phy
 94 * @calibrate: calibrate the phy
 95 * @notify_phystate: notify and configure the phy for a particular state
 96 * @release: ops to be performed while the consumer relinquishes the PHY
 97 * @owner: the module owner containing the ops
 98 */
 99struct phy_ops {
100	int	(*init)(struct phy *phy);
101	int	(*exit)(struct phy *phy);
102	int	(*power_on)(struct phy *phy);
103	int	(*power_off)(struct phy *phy);
104	int	(*set_mode)(struct phy *phy, enum phy_mode mode, int submode);
105	int	(*set_media)(struct phy *phy, enum phy_media media);
106	int	(*set_speed)(struct phy *phy, int speed);
107
108	/**
109	 * @configure:
110	 *
111	 * Optional.
112	 *
113	 * Used to change the PHY parameters. phy_init() must have
114	 * been called on the phy.
115	 *
116	 * Returns: 0 if successful, an negative error code otherwise
117	 */
118	int	(*configure)(struct phy *phy, union phy_configure_opts *opts);
119
120	/**
121	 * @validate:
122	 *
123	 * Optional.
124	 *
125	 * Used to check that the current set of parameters can be
126	 * handled by the phy. Implementations are free to tune the
127	 * parameters passed as arguments if needed by some
128	 * implementation detail or constraints. It must not change
129	 * any actual configuration of the PHY, so calling it as many
130	 * times as deemed fit by the consumer must have no side
131	 * effect.
132	 *
133	 * Returns: 0 if the configuration can be applied, an negative
134	 * error code otherwise
135	 */
136	int	(*validate)(struct phy *phy, enum phy_mode mode, int submode,
137			    union phy_configure_opts *opts);
138	int	(*reset)(struct phy *phy);
139	int	(*calibrate)(struct phy *phy);
140
141	/* notify phy connect status change */
142	int	(*connect)(struct phy *phy, int port);
143	int	(*disconnect)(struct phy *phy, int port);
144
145	int	(*notify_phystate)(struct phy *phy, union phy_notify state);
146	void	(*release)(struct phy *phy);
147	struct module *owner;
148};
149
150/**
151 * struct phy_attrs - represents phy attributes
152 * @bus_width: Data path width implemented by PHY
153 * @max_link_rate: Maximum link rate supported by PHY (units to be decided by producer and consumer)
154 * @mode: PHY mode
155 */
156struct phy_attrs {
157	u32			bus_width;
158	u32			max_link_rate;
159	enum phy_mode		mode;
160};
161
162/**
163 * struct phy - represents the phy device
164 * @dev: phy device
165 * @id: id of the phy device
166 * @ops: function pointers for performing phy operations
167 * @mutex: mutex to protect phy_ops
168 * @lockdep_key: lockdep information for this mutex
169 * @init_count: used to protect when the PHY is used by multiple consumers
170 * @power_count: used to protect when the PHY is used by multiple consumers
171 * @attrs: used to specify PHY specific attributes
172 * @pwr: power regulator associated with the phy
173 * @debugfs: debugfs directory
174 */
175struct phy {
176	struct device		dev;
177	int			id;
178	const struct phy_ops	*ops;
179	struct mutex		mutex;
180	struct lock_class_key	lockdep_key;
181	int			init_count;
182	int			power_count;
183	struct phy_attrs	attrs;
184	struct regulator	*pwr;
185	struct dentry		*debugfs;
186};
187
188/**
189 * struct phy_provider - represents the phy provider
190 * @dev: phy provider device
191 * @children: can be used to override the default (dev->of_node) child node
192 * @owner: the module owner having of_xlate
193 * @list: to maintain a linked list of PHY providers
194 * @of_xlate: function pointer to obtain phy instance from phy pointer
195 */
196struct phy_provider {
197	struct device		*dev;
198	struct device_node	*children;
199	struct module		*owner;
200	struct list_head	list;
201	struct phy * (*of_xlate)(struct device *dev,
202				 const struct of_phandle_args *args);
203};
204
205/**
206 * struct phy_lookup - PHY association in list of phys managed by the phy driver
207 * @node: list node
208 * @dev_id: the device of the association
209 * @con_id: connection ID string on device
210 * @phy: the phy of the association
211 */
212struct phy_lookup {
213	struct list_head node;
214	const char *dev_id;
215	const char *con_id;
216	struct phy *phy;
217};
218
219#define	to_phy(a)	(container_of((a), struct phy, dev))
220
221#define	of_phy_provider_register(dev, xlate)	\
222	__of_phy_provider_register((dev), NULL, THIS_MODULE, (xlate))
223
224#define	devm_of_phy_provider_register(dev, xlate)	\
225	__devm_of_phy_provider_register((dev), NULL, THIS_MODULE, (xlate))
226
227#define of_phy_provider_register_full(dev, children, xlate) \
228	__of_phy_provider_register(dev, children, THIS_MODULE, xlate)
229
230#define devm_of_phy_provider_register_full(dev, children, xlate) \
231	__devm_of_phy_provider_register(dev, children, THIS_MODULE, xlate)
232
233static inline void phy_set_drvdata(struct phy *phy, void *data)
234{
235	dev_set_drvdata(&phy->dev, data);
236}
237
238static inline void *phy_get_drvdata(struct phy *phy)
239{
240	return dev_get_drvdata(&phy->dev);
241}
242
243#if IS_ENABLED(CONFIG_GENERIC_PHY)
244int phy_pm_runtime_get(struct phy *phy);
245int phy_pm_runtime_get_sync(struct phy *phy);
246int phy_pm_runtime_put(struct phy *phy);
247int phy_pm_runtime_put_sync(struct phy *phy);
248int phy_init(struct phy *phy);
249int phy_exit(struct phy *phy);
250int phy_power_on(struct phy *phy);
251int phy_power_off(struct phy *phy);
252int phy_set_mode_ext(struct phy *phy, enum phy_mode mode, int submode);
253#define phy_set_mode(phy, mode) \
254	phy_set_mode_ext(phy, mode, 0)
255int phy_set_media(struct phy *phy, enum phy_media media);
256int phy_set_speed(struct phy *phy, int speed);
257int phy_configure(struct phy *phy, union phy_configure_opts *opts);
258int phy_validate(struct phy *phy, enum phy_mode mode, int submode,
259		 union phy_configure_opts *opts);
260
261static inline enum phy_mode phy_get_mode(struct phy *phy)
262{
263	return phy->attrs.mode;
264}
265int phy_reset(struct phy *phy);
266int phy_calibrate(struct phy *phy);
267int phy_notify_connect(struct phy *phy, int port);
268int phy_notify_disconnect(struct phy *phy, int port);
269int phy_notify_state(struct phy *phy, union phy_notify state);
270static inline int phy_get_bus_width(struct phy *phy)
271{
272	return phy->attrs.bus_width;
273}
274static inline void phy_set_bus_width(struct phy *phy, int bus_width)
275{
276	phy->attrs.bus_width = bus_width;
277}
278struct phy *phy_get(struct device *dev, const char *string);
279struct phy *devm_phy_get(struct device *dev, const char *string);
280struct phy *devm_phy_optional_get(struct device *dev, const char *string);
281struct phy *devm_of_phy_get(struct device *dev, struct device_node *np,
282			    const char *con_id);
283struct phy *devm_of_phy_optional_get(struct device *dev, struct device_node *np,
284				     const char *con_id);
285struct phy *devm_of_phy_get_by_index(struct device *dev, struct device_node *np,
286				     int index);
287void of_phy_put(struct phy *phy);
288void phy_put(struct device *dev, struct phy *phy);
289void devm_phy_put(struct device *dev, struct phy *phy);
290struct phy *of_phy_get(struct device_node *np, const char *con_id);
291struct phy *of_phy_simple_xlate(struct device *dev,
292				const struct of_phandle_args *args);
293struct phy *phy_create(struct device *dev, struct device_node *node,
294		       const struct phy_ops *ops);
295struct phy *devm_phy_create(struct device *dev, struct device_node *node,
296			    const struct phy_ops *ops);
297void phy_destroy(struct phy *phy);
298void devm_phy_destroy(struct device *dev, struct phy *phy);
299struct phy_provider *__of_phy_provider_register(struct device *dev,
300	struct device_node *children, struct module *owner,
301	struct phy * (*of_xlate)(struct device *dev,
302				 const struct of_phandle_args *args));
303struct phy_provider *__devm_of_phy_provider_register(struct device *dev,
304	struct device_node *children, struct module *owner,
305	struct phy * (*of_xlate)(struct device *dev,
306				 const struct of_phandle_args *args));
307void of_phy_provider_unregister(struct phy_provider *phy_provider);
308void devm_of_phy_provider_unregister(struct device *dev,
309	struct phy_provider *phy_provider);
310int phy_create_lookup(struct phy *phy, const char *con_id, const char *dev_id);
311void phy_remove_lookup(struct phy *phy, const char *con_id, const char *dev_id);
312#else
313static inline int phy_pm_runtime_get(struct phy *phy)
314{
315	if (!phy)
316		return 0;
317	return -ENOSYS;
318}
319
320static inline int phy_pm_runtime_get_sync(struct phy *phy)
321{
322	if (!phy)
323		return 0;
324	return -ENOSYS;
325}
326
327static inline int phy_pm_runtime_put(struct phy *phy)
328{
329	if (!phy)
330		return 0;
331	return -ENOSYS;
332}
333
334static inline int phy_pm_runtime_put_sync(struct phy *phy)
335{
336	if (!phy)
337		return 0;
338	return -ENOSYS;
339}
340
341static inline int phy_init(struct phy *phy)
342{
343	if (!phy)
344		return 0;
345	return -ENOSYS;
346}
347
348static inline int phy_exit(struct phy *phy)
349{
350	if (!phy)
351		return 0;
352	return -ENOSYS;
353}
354
355static inline int phy_power_on(struct phy *phy)
356{
357	if (!phy)
358		return 0;
359	return -ENOSYS;
360}
361
362static inline int phy_power_off(struct phy *phy)
363{
364	if (!phy)
365		return 0;
366	return -ENOSYS;
367}
368
369static inline int phy_set_mode_ext(struct phy *phy, enum phy_mode mode,
370				   int submode)
371{
372	if (!phy)
373		return 0;
374	return -ENOSYS;
375}
376
377#define phy_set_mode(phy, mode) \
378	phy_set_mode_ext(phy, mode, 0)
379
380static inline int phy_set_media(struct phy *phy, enum phy_media media)
381{
382	if (!phy)
383		return 0;
384	return -ENODEV;
385}
386
387static inline int phy_set_speed(struct phy *phy, int speed)
388{
389	if (!phy)
390		return 0;
391	return -ENODEV;
392}
393
394static inline enum phy_mode phy_get_mode(struct phy *phy)
395{
396	return PHY_MODE_INVALID;
397}
398
399static inline int phy_reset(struct phy *phy)
400{
401	if (!phy)
402		return 0;
403	return -ENOSYS;
404}
405
406static inline int phy_calibrate(struct phy *phy)
407{
408	if (!phy)
409		return 0;
410	return -ENOSYS;
411}
412
413static inline int phy_notify_connect(struct phy *phy, int index)
414{
415	if (!phy)
416		return 0;
417	return -ENOSYS;
418}
419
420static inline int phy_notify_disconnect(struct phy *phy, int index)
421{
422	if (!phy)
423		return 0;
424	return -ENOSYS;
425}
426
427static inline int phy_notify_state(struct phy *phy, union phy_notify state)
428{
429	if (!phy)
430		return 0;
431	return -ENOSYS;
432}
433
434static inline int phy_configure(struct phy *phy,
435				union phy_configure_opts *opts)
436{
437	if (!phy)
438		return 0;
439
440	return -ENOSYS;
441}
442
443static inline int phy_validate(struct phy *phy, enum phy_mode mode, int submode,
444			       union phy_configure_opts *opts)
445{
446	if (!phy)
447		return 0;
448
449	return -ENOSYS;
450}
451
452static inline int phy_get_bus_width(struct phy *phy)
453{
454	return -ENOSYS;
455}
456
457static inline void phy_set_bus_width(struct phy *phy, int bus_width)
458{
459	return;
460}
461
462static inline struct phy *phy_get(struct device *dev, const char *string)
463{
464	return ERR_PTR(-ENOSYS);
465}
466
467static inline struct phy *devm_phy_get(struct device *dev, const char *string)
468{
469	return ERR_PTR(-ENOSYS);
470}
471
472static inline struct phy *devm_phy_optional_get(struct device *dev,
473						const char *string)
474{
475	return NULL;
476}
477
478static inline struct phy *devm_of_phy_get(struct device *dev,
479					  struct device_node *np,
480					  const char *con_id)
481{
482	return ERR_PTR(-ENOSYS);
483}
484
485static inline struct phy *devm_of_phy_optional_get(struct device *dev,
486						   struct device_node *np,
487						   const char *con_id)
488{
489	return NULL;
490}
491
492static inline struct phy *devm_of_phy_get_by_index(struct device *dev,
493						   struct device_node *np,
494						   int index)
495{
496	return ERR_PTR(-ENOSYS);
497}
498
499static inline void of_phy_put(struct phy *phy)
500{
501}
502
503static inline void phy_put(struct device *dev, struct phy *phy)
504{
505}
506
507static inline void devm_phy_put(struct device *dev, struct phy *phy)
508{
509}
510
511static inline struct phy *of_phy_get(struct device_node *np, const char *con_id)
512{
513	return ERR_PTR(-ENOSYS);
514}
515
516static inline struct phy *of_phy_simple_xlate(struct device *dev,
517					      const struct of_phandle_args *args)
518{
519	return ERR_PTR(-ENOSYS);
520}
521
522static inline struct phy *phy_create(struct device *dev,
523				     struct device_node *node,
524				     const struct phy_ops *ops)
525{
526	return ERR_PTR(-ENOSYS);
527}
528
529static inline struct phy *devm_phy_create(struct device *dev,
530					  struct device_node *node,
531					  const struct phy_ops *ops)
532{
533	return ERR_PTR(-ENOSYS);
534}
535
536static inline void phy_destroy(struct phy *phy)
537{
538}
539
540static inline void devm_phy_destroy(struct device *dev, struct phy *phy)
541{
542}
543
544static inline struct phy_provider *__of_phy_provider_register(
545	struct device *dev, struct device_node *children, struct module *owner,
546	struct phy * (*of_xlate)(struct device *dev,
547				 const struct of_phandle_args *args))
548{
549	return ERR_PTR(-ENOSYS);
550}
551
552static inline struct phy_provider *__devm_of_phy_provider_register(struct device
553	*dev, struct device_node *children, struct module *owner,
554	struct phy * (*of_xlate)(struct device *dev,
555				 const struct of_phandle_args *args))
556{
557	return ERR_PTR(-ENOSYS);
558}
559
560static inline void of_phy_provider_unregister(struct phy_provider *phy_provider)
561{
562}
563
564static inline void devm_of_phy_provider_unregister(struct device *dev,
565	struct phy_provider *phy_provider)
566{
567}
568static inline int
569phy_create_lookup(struct phy *phy, const char *con_id, const char *dev_id)
570{
571	return 0;
572}
573static inline void phy_remove_lookup(struct phy *phy, const char *con_id,
574				     const char *dev_id) { }
575#endif
576
577#endif /* __DRIVERS_PHY_H */
~/ Read-only file preview.