summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorzms123456 <[email protected]>2023-10-18 20:50:30 +0800
committerGitHub <[email protected]>2023-10-18 20:50:30 +0800
commitd01dd05a0cd2107d85e26a445a43957880fd1978 (patch)
treeb6d6f631e427d608b9a09b22e9dbc0e7fb61c084
parentdd33b31c280124526dc7aaf7c11e4b1eadf9d6b3 (diff)
[kernel][dm]适配新的设备驱动模型 (#8075)
-rw-r--r--bsp/fujitsu/mb9x/mb9bf500r/lcd.c2
-rw-r--r--bsp/fujitsu/mb9x/mb9bf506r/drivers/nand.c2
-rw-r--r--bsp/lpc178x/drivers/lpc17xx_lcd.c1
-rw-r--r--bsp/qemu-virt64-aarch64/applications/graphic.c1
-rw-r--r--bsp/raspberry-pi/raspi3-32/driver/drv_fb.c2
-rw-r--r--bsp/raspberry-pi/raspi3-64/driver/drv_fb.c1
-rwxr-xr-xcomponents/drivers/Kconfig20
-rw-r--r--components/drivers/core/dm.c2
-rw-r--r--components/drivers/core/platform.c17
-rw-r--r--components/drivers/include/drivers/classes/block.h42
-rw-r--r--components/drivers/include/drivers/classes/char.h19
-rw-r--r--components/drivers/include/drivers/classes/graphic.h104
-rw-r--r--components/drivers/include/drivers/classes/mtd.h19
-rw-r--r--components/drivers/include/drivers/classes/net.h19
-rw-r--r--components/drivers/include/drivers/core/bus.h2
-rw-r--r--components/drivers/include/drivers/core/device.h89
-rw-r--r--components/drivers/include/drivers/core/driver.h5
-rw-r--r--components/drivers/include/drivers/platform.h10
-rw-r--r--components/drivers/include/rtdevice.h8
-rw-r--r--components/drivers/ofw/base.c3
-rwxr-xr-xcomponents/drivers/ofw/fdt.c3
-rwxr-xr-xcomponents/drivers/ofw/irq.c1
-rwxr-xr-xcomponents/drivers/ofw/ofw.c2
-rw-r--r--components/drivers/spi/spi_msd.h1
-rw-r--r--components/drivers/usb/usbdevice/class/mstorage.c2
-rw-r--r--components/drivers/virtio/virtio_blk.c1
-rw-r--r--components/drivers/virtio/virtio_gpu.c1
-rw-r--r--include/rtdef.h174
-rw-r--r--src/Kconfig64
-rw-r--r--src/SConscript3
30 files changed, 306 insertions, 314 deletions
diff --git a/bsp/fujitsu/mb9x/mb9bf500r/lcd.c b/bsp/fujitsu/mb9x/mb9bf500r/lcd.c
index 8b61abf2e0..b9d4dfbbd4 100644
--- a/bsp/fujitsu/mb9x/mb9bf500r/lcd.c
+++ b/bsp/fujitsu/mb9x/mb9bf500r/lcd.c
@@ -9,6 +9,8 @@
*/
#include <rtthread.h>
+#include <rtdevice.h>
+
#include "lcd.h"
#include "font.h"
diff --git a/bsp/fujitsu/mb9x/mb9bf506r/drivers/nand.c b/bsp/fujitsu/mb9x/mb9bf506r/drivers/nand.c
index 0eb9b418a4..1cf3fcf95e 100644
--- a/bsp/fujitsu/mb9x/mb9bf506r/drivers/nand.c
+++ b/bsp/fujitsu/mb9x/mb9bf506r/drivers/nand.c
@@ -8,6 +8,8 @@
* 2011-05-25 Bernard first version
*/
+#include <rtdevice.h>
+
#include "nand.h"
#include "mb9bf506r.h"
diff --git a/bsp/lpc178x/drivers/lpc17xx_lcd.c b/bsp/lpc178x/drivers/lpc17xx_lcd.c
index f8f405a540..2a84b02633 100644
--- a/bsp/lpc178x/drivers/lpc17xx_lcd.c
+++ b/bsp/lpc178x/drivers/lpc17xx_lcd.c
@@ -7,6 +7,7 @@
* Date Author Notes
*/
#include <rtthread.h>
+#include <rtdevice.h>
#include "LPC177x_8x.h"
#include "lpc177x_8x_pinsel.h"
diff --git a/bsp/qemu-virt64-aarch64/applications/graphic.c b/bsp/qemu-virt64-aarch64/applications/graphic.c
index 7331ebfc65..c54132bb73 100644
--- a/bsp/qemu-virt64-aarch64/applications/graphic.c
+++ b/bsp/qemu-virt64-aarch64/applications/graphic.c
@@ -9,6 +9,7 @@
*/
#include <rtthread.h>
+#include <rtdevice.h>
#include <virtio_gpu.h>
#include <virtio_input.h>
diff --git a/bsp/raspberry-pi/raspi3-32/driver/drv_fb.c b/bsp/raspberry-pi/raspi3-32/driver/drv_fb.c
index 80346de4d8..25c298ce7e 100644
--- a/bsp/raspberry-pi/raspi3-32/driver/drv_fb.c
+++ b/bsp/raspberry-pi/raspi3-32/driver/drv_fb.c
@@ -10,6 +10,8 @@
#include <rthw.h>
#include <rtthread.h>
+#include <rtdevice.h>
+
#include "mbox.h"
#include "drv_fb.h"
#include "mmu.h"
diff --git a/bsp/raspberry-pi/raspi3-64/driver/drv_fb.c b/bsp/raspberry-pi/raspi3-64/driver/drv_fb.c
index 47e04a7b42..06056bf7c1 100644
--- a/bsp/raspberry-pi/raspi3-64/driver/drv_fb.c
+++ b/bsp/raspberry-pi/raspi3-64/driver/drv_fb.c
@@ -11,6 +11,7 @@
#include <rthw.h>
#include <stdint.h>
#include <rtthread.h>
+#include <rtdevice.h>
#include "mbox.h"
#include "drv_fb.h"
#include "mmu.h"
diff --git a/components/drivers/Kconfig b/components/drivers/Kconfig
index 1bb9a07c91..1e661962b7 100755
--- a/components/drivers/Kconfig
+++ b/components/drivers/Kconfig
@@ -1,5 +1,12 @@
menu "Device Drivers"
+config RT_USING_DM
+ bool "Enable device driver model with device tree"
+ default n
+ help
+ Enable device driver model with device tree (FDT). It will use more memory
+ to parse and support device tree feature.
+
config RT_USING_DEVICE_IPC
bool "Using device drivers IPC"
default y
@@ -418,19 +425,6 @@ config RT_USING_PM
endif
endif
-config RT_USING_FDT
- bool "Using fdt interface for device drivers"
- default n
- if RT_USING_FDT
- config RT_USING_FDTLIB
- bool "Using fdt lib for device drivers"
- default y
- config FDT_USING_DEBUG
- bool "Using fdt debug function "
- default n
-
- endif
-
config RT_USING_RTC
bool "Using RTC device drivers"
default n
diff --git a/components/drivers/core/dm.c b/components/drivers/core/dm.c
index 20c2fca1d3..c7e1d29696 100644
--- a/components/drivers/core/dm.c
+++ b/components/drivers/core/dm.c
@@ -27,7 +27,7 @@ INIT_EXPORT(rti_secondary_cpu_end, "7.end");
void rt_dm_secondary_cpu_init(void)
{
-#if RT_DEBUGING_INIT
+#ifdef RT_DEBUGING_INIT
int result;
const struct rt_init_desc *desc;
diff --git a/components/drivers/core/platform.c b/components/drivers/core/platform.c
index 3cbae718ab..e6d62817ab 100644
--- a/components/drivers/core/platform.c
+++ b/components/drivers/core/platform.c
@@ -6,6 +6,7 @@
* Change Logs:
* Date Author Notes
* 2023-04-12 ErikChan the first version
+ * 2023-10-13 zmshahaha distinguish ofw and none-ofw situation
*/
#include <rtthread.h>
@@ -61,10 +62,14 @@ rt_err_t rt_platform_device_register(struct rt_platform_device *pdev)
static rt_bool_t platform_match(rt_driver_t drv, rt_device_t dev)
{
- struct rt_ofw_node *np = dev->ofw_node;
struct rt_platform_driver *pdrv = rt_container_of(drv, struct rt_platform_driver, parent);
struct rt_platform_device *pdev = rt_container_of(dev, struct rt_platform_device, parent);
+#ifdef RT_USING_OFW
+ struct rt_ofw_node *np = dev->ofw_node;
+#endif
+
+#ifdef RT_USING_OFW
if (np)
{
/* 1、match with ofw node */
@@ -72,7 +77,8 @@ static rt_bool_t platform_match(rt_driver_t drv, rt_device_t dev)
return !!pdev->id;
}
- else if (pdev->name && pdrv->name)
+#endif
+ if (pdev->name && pdrv->name)
{
/* 2、match with name */
if (pdev->name == pdrv->name)
@@ -91,12 +97,16 @@ static rt_bool_t platform_match(rt_driver_t drv, rt_device_t dev)
static rt_err_t platform_probe(rt_device_t dev)
{
rt_err_t err;
- struct rt_ofw_node *np = dev->ofw_node;
+
struct rt_platform_driver *pdrv = rt_container_of(dev->drv, struct rt_platform_driver, parent);
struct rt_platform_device *pdev = rt_container_of(dev, struct rt_platform_device, parent);
+#ifdef RT_USING_OFW
+ struct rt_ofw_node *np = dev->ofw_node;
+#endif
err = pdrv->probe(pdev);
+#ifdef RT_USING_OFW
if (!err)
{
if (np)
@@ -111,6 +121,7 @@ static rt_err_t platform_probe(rt_device_t dev)
rt_ofw_data(np) = &pdev->parent;
}
}
+#endif
return err;
}
diff --git a/components/drivers/include/drivers/classes/block.h b/components/drivers/include/drivers/classes/block.h
new file mode 100644
index 0000000000..ccb8bd8c9f
--- /dev/null
+++ b/components/drivers/include/drivers/classes/block.h
@@ -0,0 +1,42 @@
+/*
+ * Copyright (c) 2006-2023, RT-Thread Development Team
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Change Logs:
+ * Date Author Notes
+ * 2023-10-11 zmshahaha move from <rtdef.h>
+ */
+
+#ifndef __BLOCK_H__
+#define __BLOCK_H__
+
+#include <rtdef.h>
+
+/* block device commands*/
+#define RT_DEVICE_CTRL_BLK_GETGEOME (RT_DEVICE_CTRL_BASE(Block) + 1) /**< get geometry information */
+#define RT_DEVICE_CTRL_BLK_SYNC (RT_DEVICE_CTRL_BASE(Block) + 2) /**< flush data to block device */
+#define RT_DEVICE_CTRL_BLK_ERASE (RT_DEVICE_CTRL_BASE(Block) + 3) /**< erase block on block device */
+#define RT_DEVICE_CTRL_BLK_AUTOREFRESH (RT_DEVICE_CTRL_BASE(Block) + 4) /**< block device : enter/exit auto refresh mode */
+#define RT_DEVICE_CTRL_BLK_PARTITION (RT_DEVICE_CTRL_BASE(Block) + 5) /**< get block device partition */
+
+/**
+ * block device geometry structure
+ */
+struct rt_device_blk_geometry
+{
+ rt_uint64_t sector_count; /**< count of sectors */
+ rt_uint32_t bytes_per_sector; /**< number of bytes per sector */
+ rt_uint32_t block_size; /**< number of bytes to erase one block */
+};
+
+/**
+ * sector arrange struct on block device
+ */
+struct rt_device_blk_sectors
+{
+ rt_uint64_t sector_begin; /**< begin sector */
+ rt_uint64_t sector_end; /**< end sector */
+};
+
+#endif /* __BLOCK_H__ */
diff --git a/components/drivers/include/drivers/classes/char.h b/components/drivers/include/drivers/classes/char.h
new file mode 100644
index 0000000000..799e0dd1bf
--- /dev/null
+++ b/components/drivers/include/drivers/classes/char.h
@@ -0,0 +1,19 @@
+/*
+ * Copyright (c) 2006-2023, RT-Thread Development Team
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Change Logs:
+ * Date Author Notes
+ * 2023-10-11 zmshahaha move from <rtdef.h>
+ */
+
+#ifndef __CHAR_H__
+#define __CHAR_H__
+
+#include <rtdef.h>
+
+/* char device commands*/
+#define RT_DEVICE_CTRL_CHAR_STREAM (RT_DEVICE_CTRL_BASE(Char) + 1) /**< stream mode on char device */
+
+#endif /* __CHAR_H__ */
diff --git a/components/drivers/include/drivers/classes/graphic.h b/components/drivers/include/drivers/classes/graphic.h
new file mode 100644
index 0000000000..7e8960db7c
--- /dev/null
+++ b/components/drivers/include/drivers/classes/graphic.h
@@ -0,0 +1,104 @@
+/*
+ * Copyright (c) 2006-2023, RT-Thread Development Team
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Change Logs:
+ * Date Author Notes
+ * 2023-10-11 zmshahaha move from <rtdef.h>
+ */
+
+#ifndef __GRAPHIC_H__
+#define __GRAPHIC_H__
+
+#include <rtdef.h>
+
+/**
+ * cursor control command
+ */
+#define RT_DEVICE_CTRL_CURSOR_SET_POSITION 0x10
+#define RT_DEVICE_CTRL_CURSOR_SET_TYPE 0x11
+
+/**
+ * graphic device control command
+ */
+#define RTGRAPHIC_CTRL_RECT_UPDATE (RT_DEVICE_CTRL_BASE(Graphic) + 0)
+#define RTGRAPHIC_CTRL_POWERON (RT_DEVICE_CTRL_BASE(Graphic) + 1)
+#define RTGRAPHIC_CTRL_POWEROFF (RT_DEVICE_CTRL_BASE(Graphic) + 2)
+#define RTGRAPHIC_CTRL_GET_INFO (RT_DEVICE_CTRL_BASE(Graphic) + 3)
+#define RTGRAPHIC_CTRL_SET_MODE (RT_DEVICE_CTRL_BASE(Graphic) + 4)
+#define RTGRAPHIC_CTRL_GET_EXT (RT_DEVICE_CTRL_BASE(Graphic) + 5)
+#define RTGRAPHIC_CTRL_SET_BRIGHTNESS (RT_DEVICE_CTRL_BASE(Graphic) + 6)
+#define RTGRAPHIC_CTRL_GET_BRIGHTNESS (RT_DEVICE_CTRL_BASE(Graphic) + 7)
+#define RTGRAPHIC_CTRL_GET_MODE (RT_DEVICE_CTRL_BASE(Graphic) + 8)
+#define RTGRAPHIC_CTRL_GET_STATUS (RT_DEVICE_CTRL_BASE(Graphic) + 9)
+#define RTGRAPHIC_CTRL_PAN_DISPLAY (RT_DEVICE_CTRL_BASE(Graphic) + 10)
+#define RTGRAPHIC_CTRL_WAIT_VSYNC (RT_DEVICE_CTRL_BASE(Graphic) + 11)
+
+/* graphic device */
+enum
+{
+ RTGRAPHIC_PIXEL_FORMAT_MONO = 0,
+ RTGRAPHIC_PIXEL_FORMAT_GRAY4,
+ RTGRAPHIC_PIXEL_FORMAT_GRAY16,
+ RTGRAPHIC_PIXEL_FORMAT_RGB332,
+ RTGRAPHIC_PIXEL_FORMAT_RGB444,
+ RTGRAPHIC_PIXEL_FORMAT_RGB565,
+ RTGRAPHIC_PIXEL_FORMAT_RGB565P,
+ RTGRAPHIC_PIXEL_FORMAT_BGR565 = RTGRAPHIC_PIXEL_FORMAT_RGB565P,
+ RTGRAPHIC_PIXEL_FORMAT_RGB666,
+ RTGRAPHIC_PIXEL_FORMAT_RGB888,
+ RTGRAPHIC_PIXEL_FORMAT_BGR888,
+ RTGRAPHIC_PIXEL_FORMAT_ARGB888,
+ RTGRAPHIC_PIXEL_FORMAT_ABGR888,
+ RTGRAPHIC_PIXEL_FORMAT_RESERVED,
+};
+
+/**
+ * build a pixel position according to (x, y) coordinates.
+ */
+#define RTGRAPHIC_PIXEL_POSITION(x, y) ((x << 16) | y)
+
+/**
+ * graphic device information structure
+ */
+struct rt_device_graphic_info
+{
+ rt_uint8_t pixel_format; /**< graphic format */
+ rt_uint8_t bits_per_pixel; /**< bits per pixel */
+ rt_uint16_t pitch; /**< bytes per line */
+
+ rt_uint16_t width; /**< width of graphic device */
+ rt_uint16_t height; /**< height of graphic device */
+
+ rt_uint8_t *framebuffer; /**< frame buffer */
+ rt_uint32_t smem_len; /**< allocated frame buffer size */
+};
+
+/**
+ * rectangle information structure
+ */
+struct rt_device_rect_info
+{
+ rt_uint16_t x; /**< x coordinate */
+ rt_uint16_t y; /**< y coordinate */
+ rt_uint16_t width; /**< width */
+ rt_uint16_t height; /**< height */
+};
+
+/**
+ * graphic operations
+ */
+struct rt_device_graphic_ops
+{
+ void (*set_pixel) (const char *pixel, int x, int y);
+ void (*get_pixel) (char *pixel, int x, int y);
+
+ void (*draw_hline)(const char *pixel, int x1, int x2, int y);
+ void (*draw_vline)(const char *pixel, int x, int y1, int y2);
+
+ void (*blit_line) (const char *pixel, int x, int y, rt_size_t size);
+};
+#define rt_graphix_ops(device) ((struct rt_device_graphic_ops *)(device->user_data))
+
+#endif /* __GRAPHIC_H__ */
diff --git a/components/drivers/include/drivers/classes/mtd.h b/components/drivers/include/drivers/classes/mtd.h
new file mode 100644
index 0000000000..65f9ea90a1
--- /dev/null
+++ b/components/drivers/include/drivers/classes/mtd.h
@@ -0,0 +1,19 @@
+/*
+ * Copyright (c) 2006-2023, RT-Thread Development Team
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Change Logs:
+ * Date Author Notes
+ * 2023-10-11 zmshahaha move from <rtdef.h>
+ */
+
+#ifndef __MTD_H__
+#define __MTD_H__
+
+#include <rtdef.h>
+
+/* mtd interface device*/
+#define RT_DEVICE_CTRL_MTD_FORMAT (RT_DEVICE_CTRL_BASE(MTD) + 1) /**< format a MTD device */
+
+#endif /* __MTD_H__ */
diff --git a/components/drivers/include/drivers/classes/net.h b/components/drivers/include/drivers/classes/net.h
new file mode 100644
index 0000000000..4c0e2944cb
--- /dev/null
+++ b/components/drivers/include/drivers/classes/net.h
@@ -0,0 +1,19 @@
+/*
+ * Copyright (c) 2006-2023, RT-Thread Development Team
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Change Logs:
+ * Date Author Notes
+ * 2023-10-11 zmshahaha move from <rtdef.h>
+ */
+
+#ifndef __NET_H__
+#define __NET_H__
+
+#include <rtdef.h>
+
+/* net interface device*/
+#define RT_DEVICE_CTRL_NETIF_GETMAC (RT_DEVICE_CTRL_BASE(NetIf) + 1) /**< get mac address */
+
+#endif /* __NET_H__ */
diff --git a/components/drivers/include/drivers/core/bus.h b/components/drivers/include/drivers/core/bus.h
index 0f7a9f6e4b..4a010d797d 100644
--- a/components/drivers/include/drivers/core/bus.h
+++ b/components/drivers/include/drivers/core/bus.h
@@ -12,7 +12,7 @@
#define __CORE_BUS_H__
#include <rthw.h>
-#include <drivers/core/device.h>
+#include <rtdef.h>
#include <drivers/core/driver.h>
typedef struct rt_bus *rt_bus_t;
diff --git a/components/drivers/include/drivers/core/device.h b/components/drivers/include/drivers/core/device.h
deleted file mode 100644
index a8d37e2613..0000000000
--- a/components/drivers/include/drivers/core/device.h
+++ /dev/null
@@ -1,89 +0,0 @@
-/*
- * Copyright (c) 2006-2023, RT-Thread Development Team
- *
- * SPDX-License-Identifier: Apache-2.0
- *
- * Change Logs:
- * Date Author Notes
- * 2023-04-12 ErikChan the first version
- */
-
-#ifndef __CORE_DEVICE_H__
-#define __CORE_DEVICE_H__
-
-#include <rtdef.h>
-
-typedef struct rt_driver *rt_driver_t;
-typedef struct rt_device *rt_device_t;
-
-/**
- * Notify structure
- */
-struct rt_device_notify
-{
- void (*notify)(rt_device_t dev);
- struct rt_device *dev;
-};
-
-/**
- * Device structure
- */
-struct rt_device
-{
- struct rt_object parent; /**< inherit from rt_object */
- rt_list_t node;
- struct rt_bus *bus;
- void *priv;
-
-#ifdef RT_USING_DM
- rt_driver_t drv;
- void *ofw_node;
-#endif
- enum rt_device_class_type type; /**< device type */
- rt_uint16_t flag; /**< device flag */
- rt_uint16_t open_flag; /**< device open flag */
-
- rt_uint8_t ref_count; /**< reference count */
- rt_uint8_t device_id; /**< 0 - 255 */
-
- /* device call back */
- rt_err_t (*rx_indicate)(rt_device_t dev, rt_size_t size);
- rt_err_t (*tx_complete)(rt_device_t dev, void *buffer);
-
-#ifdef RT_USING_DEVICE_OPS
- const struct rt_device_ops *ops;
-#else
- /* common device interface */
- rt_err_t (*init) (rt_device_t dev);
- rt_err_t (*open) (rt_device_t dev, rt_uint16_t oflag);
- rt_err_t (*close) (rt_device_t dev);
- rt_ssize_t (*read) (rt_device_t dev, rt_off_t pos, void *buffer, rt_size_t size);
- rt_ssize_t (*write) (rt_device_t dev, rt_off_t pos, const void *buffer, rt_size_t size);
- rt_err_t (*control)(rt_device_t dev, int cmd, void *args);
-#endif /* RT_USING_DEVICE_OPS */
-
-#ifdef RT_USING_POSIX_DEVIO
- const struct dfs_file_ops *fops;
- struct rt_wqueue wait_queue;
-#endif /* RT_USING_POSIX_DEVIO */
-
- void *user_data; /**< device private data */
-};
-
-#ifdef RT_USING_DEVICE_OPS
-/**
- * operations set for device object
- */
-struct rt_device_ops
-{
- /* common device interface */
- rt_err_t (*init) (rt_device_t dev);
- rt_err_t (*open) (rt_device_t dev, rt_uint16_t oflag);
- rt_err_t (*close) (rt_device_t dev);
- rt_ssize_t (*read) (rt_device_t dev, rt_off_t pos, void *buffer, rt_size_t size);
- rt_ssize_t (*write) (rt_device_t dev, rt_off_t pos, const void *buffer, rt_size_t size);
- rt_err_t (*control)(rt_device_t dev, int cmd, void *args);
-};
-#endif /* RT_USING_DEVICE_OPS */
-
-#endif /* __DEVICE_H__ */
diff --git a/components/drivers/include/drivers/core/driver.h b/components/drivers/include/drivers/core/driver.h
index b6d51dd9c3..75608e2732 100644
--- a/components/drivers/include/drivers/core/driver.h
+++ b/components/drivers/include/drivers/core/driver.h
@@ -11,7 +11,9 @@
#ifndef __CORE_DRIVER_H__
#define __CORE_DRIVER_H__
-#include <drivers/core/device.h>
+#include <rtdef.h>
+
+struct rt_bus;
struct rt_driver
{
@@ -39,6 +41,7 @@ struct rt_driver
void *priv;
};
+typedef struct rt_driver* rt_driver_t;
int rt_driver_probe_device(struct rt_driver *drv, struct rt_device *dev);
diff --git a/components/drivers/include/drivers/platform.h b/components/drivers/include/drivers/platform.h
index 3caccabd2d..9ea1c9803a 100644
--- a/components/drivers/include/drivers/platform.h
+++ b/components/drivers/include/drivers/platform.h
@@ -6,12 +6,16 @@
* Change Logs:
* Date Author Notes
* 2023-04-12 ErikChan the first version
+ * 2023-10-13 zmshahaha distinguish ofw and none-ofw situation
*/
#ifndef __PLATFORM_H__
#define __PLATFORM_H__
+#ifdef RT_USING_OFW
#include <drivers/ofw.h>
+#endif
+
#include <drivers/core/driver.h>
struct rt_platform_device
@@ -19,7 +23,10 @@ struct rt_platform_device
struct rt_device parent;
const char *name;
+
+#ifdef RT_USING_OFW
const struct rt_ofw_node_id *id;
+#endif
void *priv;
};
@@ -29,7 +36,10 @@ struct rt_platform_driver
struct rt_driver parent;
const char *name;
+
+#ifdef RT_USING_OFW
const struct rt_ofw_node_id *ids;
+#endif
rt_err_t (*probe)(struct rt_platform_device *pdev);
};
diff --git a/components/drivers/include/rtdevice.h b/components/drivers/include/rtdevice.h
index ebcbbe15bd..840afa8734 100644
--- a/components/drivers/include/rtdevice.h
+++ b/components/drivers/include/rtdevice.h
@@ -12,7 +12,15 @@
#ifndef __RT_DEVICE_H__
#define __RT_DEVICE_H__
+#include <rtdef.h>
#include <rtthread.h>
+#include <drivers/core/driver.h>
+
+#include <drivers/classes/block.h>
+#include <drivers/classes/char.h>
+#include <drivers/classes/graphic.h>
+#include <drivers/classes/mtd.h>
+#include <drivers/classes/net.h>
#include "ipc/ringbuffer.h"
#include "ipc/completion.h"
diff --git a/components/drivers/ofw/base.c b/components/drivers/ofw/base.c
index 6f8f20e806..2e95741e5f 100644
--- a/components/drivers/ofw/base.c
+++ b/components/drivers/ofw/base.c
@@ -8,9 +8,10 @@
* 2022-08-25 GuEe-GUI first version
*/
+#define _GNU_SOURCE
+
#include <rtthread.h>
-#include <string.h>
#include <drivers/ofw.h>
#include <drivers/ofw_io.h>
#include <drivers/ofw_fdt.h>
diff --git a/components/drivers/ofw/fdt.c b/components/drivers/ofw/fdt.c
index d64feec9cd..3fa721b74b 100755
--- a/components/drivers/ofw/fdt.c
+++ b/components/drivers/ofw/fdt.c
@@ -8,10 +8,11 @@
* 2022-08-25 GuEe-GUI first version
*/
+#define _GNU_SOURCE
+
#include <rthw.h>
#include <rtthread.h>
-#include <string.h>
#include <drivers/ofw_fdt.h>
#include <drivers/ofw_raw.h>
#include <drivers/core/dm.h>
diff --git a/components/drivers/ofw/irq.c b/components/drivers/ofw/irq.c
index 97483d8a5e..6460c5e19f 100755
--- a/components/drivers/ofw/irq.c
+++ b/components/drivers/ofw/irq.c
@@ -10,7 +10,6 @@
#include <rtthread.h>
-#include <string.h>
#include <drivers/pic.h>
#include <drivers/ofw.h>
#include <drivers/ofw_io.h>
diff --git a/components/drivers/ofw/ofw.c b/components/drivers/ofw/ofw.c
index 88a5fe963d..cd9532349d 100755
--- a/components/drivers/ofw/ofw.c
+++ b/components/drivers/ofw/ofw.c
@@ -10,6 +10,8 @@
#include <rtthread.h>
#include <rtdevice.h>
+#include <drivers/platform.h>
+#include <drivers/core/bus.h>
#define DBG_TAG "rtdm.ofw"
#define DBG_LVL DBG_INFO
diff --git a/components/drivers/spi/spi_msd.h b/components/drivers/spi/spi_msd.h
index 6b16d3e198..2b66be7d67 100644
--- a/components/drivers/spi/spi_msd.h
+++ b/components/drivers/spi/spi_msd.h
@@ -12,6 +12,7 @@
#define SPI_MSD_H_INCLUDED
#include <stdint.h>
+#include <rtdevice.h>
#include <drivers/spi.h>
/* SD command (SPI mode) */
diff --git a/components/drivers/usb/usbdevice/class/mstorage.c b/components/drivers/usb/usbdevice/class/mstorage.c
index aeb3ccd510..a077988102 100644
--- a/components/drivers/usb/usbdevice/class/mstorage.c
+++ b/components/drivers/usb/usbdevice/class/mstorage.c
@@ -12,6 +12,8 @@
*/
#include <rtthread.h>
+#include <rtdevice.h>
+
#include "drivers/usb_device.h"
#include "mstorage.h"
diff --git a/components/drivers/virtio/virtio_blk.c b/components/drivers/virtio/virtio_blk.c
index 9e047aef92..4161e5907b 100644
--- a/components/drivers/virtio/virtio_blk.c
+++ b/components/drivers/virtio/virtio_blk.c
@@ -12,6 +12,7 @@
#include <rthw.h>
#include <rtthread.h>
#include <cpuport.h>
+#include <rtdevice.h>
#ifdef RT_USING_VIRTIO_BLK
diff --git a/components/drivers/virtio/virtio_gpu.c b/components/drivers/virtio/virtio_gpu.c
index 64e5611942..fa8981e56c 100644
--- a/components/drivers/virtio/virtio_gpu.c
+++ b/components/drivers/virtio/virtio_gpu.c
@@ -11,6 +11,7 @@
#include <rthw.h>
#include <rtthread.h>
#include <cpuport.h>
+#include <rtdevice.h>
#ifdef RT_USING_VIRTIO_GPU
diff --git a/include/rtdef.h b/include/rtdef.h
index 560d4c08c2..9994c67613 100644
--- a/include/rtdef.h
+++ b/include/rtdef.h
@@ -51,6 +51,7 @@
* 2023-05-20 Bernard add stdc atomic detection.
* 2023-09-17 Meco Man add RT_USING_LIBC_ISO_ONLY macro
* 2023-10-10 Chushicheng change version number to v5.1.0
+ * 2023-10-11 zmshahaha move specific devices related and driver to components/drivers
*/
#ifndef __RT_DEF_H__
@@ -1299,22 +1300,6 @@ enum rt_device_class_type
*/
#define RT_DEVICE_CTRL_BASE(Type) ((RT_Device_Class_##Type + 1) * 0x100)
-/**
- * special device commands
- */
-/* character device */
-#define RT_DEVICE_CTRL_CHAR_STREAM (RT_DEVICE_CTRL_BASE(Char) + 1) /**< stream mode on char device */
-/* block device */
-#define RT_DEVICE_CTRL_BLK_GETGEOME (RT_DEVICE_CTRL_BASE(Block) + 1) /**< get geometry information */
-#define RT_DEVICE_CTRL_BLK_SYNC (RT_DEVICE_CTRL_BASE(Block) + 2) /**< flush data to block device */
-#define RT_DEVICE_CTRL_BLK_ERASE (RT_DEVICE_CTRL_BASE(Block) + 3) /**< erase block on block device */
-#define RT_DEVICE_CTRL_BLK_AUTOREFRESH (RT_DEVICE_CTRL_BASE(Block) + 4) /**< block device : enter/exit auto refresh mode */
-#define RT_DEVICE_CTRL_BLK_PARTITION (RT_DEVICE_CTRL_BASE(Block) + 5) /**< get block device partition */
-/* net interface device*/
-#define RT_DEVICE_CTRL_NETIF_GETMAC (RT_DEVICE_CTRL_BASE(NetIf) + 1) /**< get mac address */
-/* mtd interface device*/
-#define RT_DEVICE_CTRL_MTD_FORMAT (RT_DEVICE_CTRL_BASE(MTD) + 1) /**< format a MTD device */
-
typedef struct rt_device *rt_device_t;
#ifdef RT_USING_DEVICE_OPS
@@ -1343,16 +1328,27 @@ struct rt_wqueue
};
typedef struct rt_wqueue rt_wqueue_t;
+#ifdef RT_USING_DM
+struct rt_driver;
+struct rt_bus;
+#endif
+
/**
* Device structure
*/
struct rt_device
{
struct rt_object parent; /**< inherit from rt_object */
+
#ifdef RT_USING_DM
- struct rt_driver *drv;
- void *dtb_node;
+ struct rt_bus *bus; /**< the bus mounting to */
+ rt_list_t node; /**< to mount on bus */
+ struct rt_driver *drv; /**< driver for powering the device */
+#ifdef RT_USING_OFW
+ void *ofw_node; /**< ofw node get from device tree */
#endif
+#endif
+
enum rt_device_class_type type; /**< device type */
rt_uint16_t flag; /**< device flag */
rt_uint16_t open_flag; /**< device open flag */
@@ -1383,40 +1379,7 @@ struct rt_device
void *user_data; /**< device private data */
};
-
-#define RT_DRIVER_MATCH_DTS (1<<0)
-struct rt_device_id
-{
- const char *compatible;
- void *data;
-};
-
-struct rt_driver
-{
-#ifdef RT_USING_DEVICE_OPS
- const struct rt_device_ops *dev_ops;
-#else
- /* common device interface */
- rt_err_t (*init) (rt_device_t dev);
- rt_err_t (*open) (rt_device_t dev, rt_uint16_t oflag);
- rt_err_t (*close) (rt_device_t dev);
- rt_ssize_t (*read) (rt_device_t dev, rt_off_t pos, void *buffer, rt_size_t size);
- rt_ssize_t (*write) (rt_device_t dev, rt_off_t pos, const void *buffer, rt_size_t size);
- rt_err_t (*control)(rt_device_t dev, int cmd, void *args);
-#endif
- const struct filesystem_ops *fops;
- const char *name;
- enum rt_device_class_type dev_type;
- int device_size;
- int flag;
- const struct rt_device_id *dev_match;
- int (*probe)(struct rt_device *dev);
- int (*probe_init)(struct rt_device *dev);
- int (*remove)(struct rt_device *dev);
- const void *ops; /* driver-specific operations */
- void *drv_priv_data;
-};
-typedef struct rt_driver *rt_driver_t;
+typedef struct rt_device *rt_device_t;
/**
* Notify structure
@@ -1441,113 +1404,6 @@ struct rt_channel
typedef struct rt_channel *rt_channel_t;
#endif
-/**
- * block device geometry structure
- */
-struct rt_device_blk_geometry
-{
- rt_uint64_t sector_count; /**< count of sectors */
- rt_uint32_t bytes_per_sector; /**< number of bytes per sector */
- rt_uint32_t block_size; /**< number of bytes to erase one block */
-};
-
-/**
- * sector arrange struct on block device
- */
-struct rt_device_blk_sectors
-{
- rt_uint64_t sector_begin; /**< begin sector */
- rt_uint64_t sector_end; /**< end sector */
-};
-
-/**
- * cursor control command
- */
-#define RT_DEVICE_CTRL_CURSOR_SET_POSITION 0x10
-#define RT_DEVICE_CTRL_CURSOR_SET_TYPE 0x11
-
-/**
- * graphic device control command
- */
-#define RTGRAPHIC_CTRL_RECT_UPDATE (RT_DEVICE_CTRL_BASE(Graphic) + 0)
-#define RTGRAPHIC_CTRL_POWERON (RT_DEVICE_CTRL_BASE(Graphic) + 1)
-#define RTGRAPHIC_CTRL_POWEROFF (RT_DEVICE_CTRL_BASE(Graphic) + 2)
-#define RTGRAPHIC_CTRL_GET_INFO (RT_DEVICE_CTRL_BASE(Graphic) + 3)
-#define RTGRAPHIC_CTRL_SET_MODE (RT_DEVICE_CTRL_BASE(Graphic) + 4)
-#define RTGRAPHIC_CTRL_GET_EXT (RT_DEVICE_CTRL_BASE(Graphic) + 5)
-#define RTGRAPHIC_CTRL_SET_BRIGHTNESS (RT_DEVICE_CTRL_BASE(Graphic) + 6)
-#define RTGRAPHIC_CTRL_GET_BRIGHTNESS (RT_DEVICE_CTRL_BASE(Graphic) + 7)
-#define RTGRAPHIC_CTRL_GET_MODE (RT_DEVICE_CTRL_BASE(Graphic) + 8)
-#define RTGRAPHIC_CTRL_GET_STATUS (RT_DEVICE_CTRL_BASE(Graphic) + 9)
-#define RTGRAPHIC_CTRL_PAN_DISPLAY (RT_DEVICE_CTRL_BASE(Graphic) + 10)
-#define RTGRAPHIC_CTRL_WAIT_VSYNC (RT_DEVICE_CTRL_BASE(Graphic) + 11)
-
-/* graphic device */
-enum
-{
- RTGRAPHIC_PIXEL_FORMAT_MONO = 0,
- RTGRAPHIC_PIXEL_FORMAT_GRAY4,
- RTGRAPHIC_PIXEL_FORMAT_GRAY16,
- RTGRAPHIC_PIXEL_FORMAT_RGB332,
- RTGRAPHIC_PIXEL_FORMAT_RGB444,
- RTGRAPHIC_PIXEL_FORMAT_RGB565,
- RTGRAPHIC_PIXEL_FORMAT_RGB565P,
- RTGRAPHIC_PIXEL_FORMAT_BGR565 = RTGRAPHIC_PIXEL_FORMAT_RGB565P,
- RTGRAPHIC_PIXEL_FORMAT_RGB666,
- RTGRAPHIC_PIXEL_FORMAT_RGB888,
- RTGRAPHIC_PIXEL_FORMAT_BGR888,
- RTGRAPHIC_PIXEL_FORMAT_ARGB888,
- RTGRAPHIC_PIXEL_FORMAT_ABGR888,
- RTGRAPHIC_PIXEL_FORMAT_RESERVED,
-};
-
-/**
- * build a pixel position according to (x, y) coordinates.
- */
-#define RTGRAPHIC_PIXEL_POSITION(x, y) ((x << 16) | y)
-
-/**
- * graphic device information structure
- */
-struct rt_device_graphic_info
-{
- rt_uint8_t pixel_format; /**< graphic format */
- rt_uint8_t bits_per_pixel; /**< bits per pixel */
- rt_uint16_t pitch; /**< bytes per line */
-
- rt_uint16_t width; /**< width of graphic device */
- rt_uint16_t height; /**< height of graphic device */
-
- rt_uint8_t *framebuffer; /**< frame buffer */
- rt_uint32_t smem_len; /**< allocated frame buffer size */
-};
-
-/**
- * rectangle information structure
- */
-struct rt_device_rect_info
-{
- rt_uint16_t x; /**< x coordinate */
- rt_uint16_t y; /**< y coordinate */
- rt_uint16_t width; /**< width */
- rt_uint16_t height; /**< height */
-};
-
-/**
- * graphic operations
- */
-struct rt_device_graphic_ops
-{
- void (*set_pixel) (const char *pixel, int x, int y);
- void (*get_pixel) (char *pixel, int x, int y);
-
- void (*draw_hline)(const char *pixel, int x1, int x2, int y);
- void (*draw_vline)(const char *pixel, int x, int y1, int y2);
-
- void (*blit_line) (const char *pixel, int x, int y, rt_size_t size);
-};
-#define rt_graphix_ops(device) ((struct rt_device_graphic_ops *)(device->user_data))
-
/**@}*/
#endif /* RT_USING_DEVICE */
diff --git a/src/Kconfig b/src/Kconfig
index 49fcf256c0..bb93e76bb7 100644
--- a/src/Kconfig
+++ b/src/Kconfig
@@ -25,6 +25,7 @@ config RT_USING_SMART
select RT_USING_DFS
select RT_USING_LIBC
select RT_USING_POSIX_CLOCKTIME
+ select RT_USING_DEVICE
select RT_USING_TTY
select RT_USING_NULL
select RT_USING_ZERO
@@ -382,52 +383,33 @@ menu "Memory Management"
default y if RT_USING_USERHEAP
endmenu
-menu "Kernel Device Object"
-
- config RT_USING_DEVICE
- bool "Using device object"
- default y
-
- config RT_USING_DEVICE_OPS
- bool "Using ops for each device object"
- default n
-
- config RT_USING_DM
- bool "Enable device driver model with device tree"
- default n
- help
- Enable device driver model with device tree (FDT). It will use more memory
- to parse and support device tree feature.
-
- config RT_USING_DM_FDT
- bool "Enablie builtin libfdt"
- depends on RT_USING_DM
- default y
- help
- libfdt - Flat Device Tree manipulation. If your code already contains the
- libfdt, you can cancel this built-in libfdt to avoid link issue.
+config RT_USING_DEVICE
+ bool "Using device object"
+ default y
- config RT_USING_INTERRUPT_INFO
- bool "Enable additional interrupt trace information"
- default n
- help
- Add name and counter information for interrupt trace.
+config RT_USING_DEVICE_OPS
+ bool "Using ops for each device object"
+ default n
- config RT_USING_CONSOLE
- bool "Using console for rt_kprintf"
- default y
+config RT_USING_INTERRUPT_INFO
+ bool "Enable additional interrupt trace information"
+ default n
+ help
+ Add name and counter information for interrupt trace.
- if RT_USING_CONSOLE
- config RT_CONSOLEBUF_SIZE
- int "the buffer size for console log printf"
- default 128
+config RT_USING_CONSOLE
+ bool "Using console for rt_kprintf"
+ default y
- config RT_CONSOLE_DEVICE_NAME
- string "the device name for console"
- default "uart"
- endif
+if RT_USING_CONSOLE
+ config RT_CONSOLEBUF_SIZE
+ int "the buffer size for console log printf"
+ default 128
-endmenu
+ config RT_CONSOLE_DEVICE_NAME
+ string "the device name for console"
+ default "uart"
+endif
config RT_VER_NUM
hex
diff --git a/src/SConscript b/src/SConscript
index 9d74d6a8e4..7f7098aaab 100644
--- a/src/SConscript
+++ b/src/SConscript
@@ -30,9 +30,6 @@ if GetDepend('RT_USING_SMP') == False:
if GetDepend('RT_USING_SMP') == True:
SrcRemove(src, ['scheduler_up.c'])
-if GetDepend('RT_USING_DM') == False:
- SrcRemove(src, ['driver.c'])
-
group = DefineGroup('Kernel', src, depend = [''], CPPPATH = inc, CPPDEFINES = ['__RTTHREAD__'])
Return('group')