mirror of
https://github.com/RT-Thread/rt-thread.git
synced 2026-09-21 02:06:14 +08:00
[kernel][dm]适配新的设备驱动模型 (#8075)
This commit is contained in:
@@ -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__ */
|
||||
@@ -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__ */
|
||||
@@ -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__ */
|
||||
@@ -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__ */
|
||||
@@ -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__ */
|
||||
@@ -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;
|
||||
|
||||
@@ -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__ */
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user