1 /*
2  * Copyright (c) 2006-2022, RT-Thread Development Team
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  *
6  * Change Logs:
7  * Date           Author       Notes
8  * 2022-10-24     GuEe-GUI     first version
9  */
10 
11 #ifndef __PHYE_H__
12 #define __PHYE_H__
13 
14 #include <rtthread.h>
15 #include <drivers/ofw.h>
16 
17 enum rt_phye_mode
18 {
19     RT_PHYE_MODE_INVALID,
20     RT_PHYE_MODE_USB_HOST,
21     RT_PHYE_MODE_USB_HOST_LS,
22     RT_PHYE_MODE_USB_HOST_FS,
23     RT_PHYE_MODE_USB_HOST_HS,
24     RT_PHYE_MODE_USB_HOST_SS,
25     RT_PHYE_MODE_USB_DEVICE,
26     RT_PHYE_MODE_USB_DEVICE_LS,
27     RT_PHYE_MODE_USB_DEVICE_FS,
28     RT_PHYE_MODE_USB_DEVICE_HS,
29     RT_PHYE_MODE_USB_DEVICE_SS,
30     RT_PHYE_MODE_USB_OTG,
31     RT_PHYE_MODE_UFS_HS_A,
32     RT_PHYE_MODE_UFS_HS_B,
33     RT_PHYE_MODE_PCIE,
34     RT_PHYE_MODE_ETHERNET,
35     RT_PHYE_MODE_MIPI_DPHY,
36     RT_PHYE_MODE_SATA,
37     RT_PHYE_MODE_LVDS,
38     RT_PHYE_MODE_DP,
39 
40     RT_PHYE_MODE_MAX,
41 
42     /* PCIe */
43     RT_PHYE_MODE_PCIE_RC = RT_PHYE_MODE_MAX,
44     RT_PHYE_MODE_PCIE_EP,
45     RT_PHYE_MODE_PCIE_BIFURCATION,
46 };
47 
48 struct rt_phye_ops;
49 
50 struct rt_phye
51 {
52     struct rt_device *dev;
53 
54     const struct rt_phye_ops *ops;
55 
56     int init_count;
57     int power_count;
58     struct rt_spinlock lock;
59 };
60 
61 struct rt_phye_ops
62 {
63     rt_err_t (*init)(struct rt_phye *phye);
64     rt_err_t (*exit)(struct rt_phye *phye);
65     rt_err_t (*reset)(struct rt_phye *phye);
66     rt_err_t (*power_on)(struct rt_phye *phye);
67     rt_err_t (*power_off)(struct rt_phye *phye);
68     rt_err_t (*set_mode)(struct rt_phye *phye, enum rt_phye_mode mode, int submode);
69     rt_err_t (*ofw_parse)(struct rt_phye *phye, struct rt_ofw_cell_args *phye_args);
70 };
71 
72 rt_err_t rt_phye_register(struct rt_phye *phye);
73 rt_err_t rt_phye_unregister(struct rt_phye *phye);
74 
75 rt_err_t rt_phye_init(struct rt_phye *phye);
76 rt_err_t rt_phye_exit(struct rt_phye *phye);
77 rt_err_t rt_phye_reset(struct rt_phye *phye);
78 rt_err_t rt_phye_power_on(struct rt_phye *phye);
79 rt_err_t rt_phye_power_off(struct rt_phye *phye);
80 rt_err_t rt_phye_set_mode(struct rt_phye *phye, enum rt_phye_mode mode, int submode);
81 
rt_phye_set_mode_simple(struct rt_phye * phye,enum rt_phye_mode mode)82 rt_inline rt_err_t rt_phye_set_mode_simple(struct rt_phye *phye, enum rt_phye_mode mode)
83 {
84     return rt_phye_set_mode(phye, mode, RT_PHYE_MODE_INVALID);
85 }
86 
87 struct rt_phye *rt_phye_get_by_index(struct rt_device *dev, int index);
88 struct rt_phye *rt_phye_get_by_name(struct rt_device *dev, const char *id);
89 void rt_phye_put(struct rt_phye *phye);
90 
91 #endif /* __PHYE_H__ */
92