Skip to content

Commit c2fd564

Browse files
GuEe-GUI1078249029
authored andcommitted
[DM/FEATURE] Support PHY (external) (RT-Thread#9597)
This framework will be of use only to devices that use external PHY (PHY functionality is not embedded within the controller). Use in PCIE, USB, HDMI, DP... Signed-off-by: GuEe-GUI <[email protected]>
1 parent 892bd26 commit c2fd564

File tree

7 files changed

+466
-0
lines changed

7 files changed

+466
-0
lines changed

components/drivers/Kconfig

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ rsource "touch/Kconfig"
2121
rsource "graphic/Kconfig"
2222
rsource "hwcrypto/Kconfig"
2323
rsource "wlan/Kconfig"
24+
rsource "phye/Kconfig"
2425
rsource "block/Kconfig"
2526
rsource "nvme/Kconfig"
2627
rsource "scsi/Kconfig"
+91
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
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+
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__ */
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/*
2+
* Copyright (c) 2006-2022, RT-Thread Development Team
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#ifndef __DT_BINDINGS_PHYE_H__
8+
#define __DT_BINDINGS_PHYE_H__
9+
10+
#define PHY_NONE 0
11+
#define PHY_TYPE_SATA 1
12+
#define PHY_TYPE_PCIE 2
13+
#define PHY_TYPE_USB2 3
14+
#define PHY_TYPE_USB3 4
15+
#define PHY_TYPE_UFS 5
16+
#define PHY_TYPE_DP 6
17+
#define PHY_TYPE_XPCS 7
18+
#define PHY_TYPE_SGMII 8
19+
#define PHY_TYPE_QSGMII 9
20+
#define PHY_TYPE_DPHY 10
21+
#define PHY_TYPE_CPHY 11
22+
#define PHY_TYPE_USXGMII 12
23+
24+
#endif /* __DT_BINDINGS_PHYE_H__ */

components/drivers/include/rtdevice.h

+4
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,10 @@ extern "C" {
6767
#include "drivers/ofw_raw.h"
6868
#endif /* RT_USING_OFW */
6969

70+
#ifdef RT_USING_PHYE
71+
#include "drivers/phye.h"
72+
#endif
73+
7074
#ifdef RT_USING_PIC
7175
#include "drivers/pic.h"
7276
#endif

components/drivers/phye/Kconfig

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
menuconfig RT_USING_PHYE
2+
bool "Using External Port Physical Layer (PHY) device drivers"
3+
depends on RT_USING_DM
4+
default n
5+
help
6+
This framework will be of use only to devices that use
7+
external PHY (PHY functionality is not embedded within the controller).
8+
9+
if RT_USING_PHYE
10+
osource "$(SOC_DM_PHYE_DIR)/Kconfig"
11+
endif

components/drivers/phye/SConscript

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
from building import *
2+
3+
group = []
4+
5+
if not GetDepend(['RT_USING_PHYE']):
6+
Return('group')
7+
8+
cwd = GetCurrentDir()
9+
CPPPATH = [cwd + '/../include']
10+
11+
src = ['phye.c']
12+
13+
group = DefineGroup('DeviceDrivers', src, depend = [''], CPPPATH = CPPPATH)
14+
15+
Return('group')

0 commit comments

Comments
 (0)