summaryrefslogtreecommitdiff
path: root/components/drivers/phy
diff options
context:
space:
mode:
authoryangjie11 <[email protected]>2020-11-18 09:56:35 +0800
committerGitHub <[email protected]>2020-11-18 09:56:35 +0800
commitd4a682e8d97fa131e5a8d795f8c5451d55cdd5b0 (patch)
tree4773b40cb012475c5daf74bfd55707e141477669 /components/drivers/phy
parent2b98f4720c827ae1850df78299f6b273d568c8c7 (diff)
parent2ef3c9d861f55253620996a94831a4be31ca6620 (diff)
Merge pull request #3 from RT-Thread/master
sync
Diffstat (limited to 'components/drivers/phy')
-rw-r--r--components/drivers/phy/SConscript8
-rw-r--r--components/drivers/phy/phy.c78
2 files changed, 86 insertions, 0 deletions
diff --git a/components/drivers/phy/SConscript b/components/drivers/phy/SConscript
new file mode 100644
index 0000000000..ec12ed24c2
--- /dev/null
+++ b/components/drivers/phy/SConscript
@@ -0,0 +1,8 @@
+from building import *
+
+cwd = GetCurrentDir()
+src = Glob('*.c')
+CPPPATH = [cwd + '/../include']
+group = DefineGroup('DeviceDrivers', src, depend = ['RT_USING_PHY'], CPPPATH = CPPPATH)
+
+Return('group')
diff --git a/components/drivers/phy/phy.c b/components/drivers/phy/phy.c
new file mode 100644
index 0000000000..3ed4a1a265
--- /dev/null
+++ b/components/drivers/phy/phy.c
@@ -0,0 +1,78 @@
+
+/*
+ * Copyright (c) 2006-2020, RT-Thread Development Team
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Change Logs:
+ * Date Author Notes
+ * 2020-09-27 wangqiang first version
+ */
+
+#include <rthw.h>
+#include <rtthread.h>
+#include <rtdevice.h>
+
+#define DBG_TAG "PHY"
+#define DBG_LVL DBG_INFO
+#include <rtdbg.h>
+
+
+static rt_size_t phy_device_read(rt_device_t dev, rt_off_t pos, void *buffer, rt_size_t count)
+{
+ struct rt_phy_device *phy = (struct rt_phy_device *)dev->user_data;
+ struct rt_phy_msg *msg = (struct rt_phy_msg *)buffer;
+ return phy->bus->ops->read(phy->bus, phy->addr, msg->reg, &(msg->value), 4);
+}
+static rt_size_t phy_device_write(rt_device_t dev, rt_off_t pos, const void *buffer, rt_size_t count)
+{
+ struct rt_phy_device *phy = (struct rt_phy_device *)dev->user_data;
+ struct rt_phy_msg *msg = (struct rt_phy_msg *)buffer;
+ return phy->bus->ops->write(phy->bus, phy->addr, msg->reg, &(msg->value), 4);
+}
+
+
+
+#ifdef RT_USING_DEVICE_OPS
+const static struct rt_device_ops phy_ops =
+{
+ RT_NULL,
+ RT_NULL,
+ RT_NULL,
+ phy_device_read,
+ phy_device_write,
+ RT_NULL,
+};
+#endif
+
+/*
+* phy device register
+*/
+rt_err_t rt_hw_phy_register(struct rt_phy_device *phy, const char *name)
+{
+ rt_err_t ret;
+ struct rt_device *device;
+
+ device = &(phy->parent);
+
+ device->type = RT_Device_Class_PHY;
+ device->rx_indicate = RT_NULL;
+ device->tx_complete = RT_NULL;
+
+#ifdef RT_USING_DEVICE_OPS
+ device->ops = phy_ops;
+#else
+ device->init = NULL;
+ device->open = NULL;
+ device->close = NULL;
+ device->read = phy_device_read;
+ device->write = phy_device_write;
+ device->control = NULL;
+#endif
+ device->user_data = phy;
+
+ /* register a character device */
+ ret = rt_device_register(device, name, RT_DEVICE_FLAG_RDWR);
+
+ return ret;
+}