创建,添加sdram
This commit is contained in:
commit
90c74bc31a
2944 files changed
+1430509
No files matched your search
@@ -0,0 +1,54 @@
|
||||
/*
|
||||
* 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_BUS_H__
|
||||
#define __CORE_BUS_H__
|
||||
|
||||
#include <rthw.h>
|
||||
#include <rtdef.h>
|
||||
#include <drivers/core/driver.h>
|
||||
|
||||
typedef struct rt_bus *rt_bus_t;
|
||||
|
||||
struct rt_bus
|
||||
{
|
||||
struct rt_object parent; /**< inherit from rt_object */
|
||||
|
||||
const char *name;
|
||||
|
||||
rt_list_t list;
|
||||
rt_list_t dev_list;
|
||||
rt_list_t drv_list;
|
||||
|
||||
struct rt_spinlock dev_lock;
|
||||
struct rt_spinlock drv_lock;
|
||||
|
||||
rt_bool_t (*match)(rt_driver_t drv, rt_device_t dev);
|
||||
rt_err_t (*probe)(rt_device_t dev);
|
||||
rt_err_t (*remove)(rt_device_t dev);
|
||||
rt_err_t (*shutdown)(rt_device_t dev);
|
||||
};
|
||||
|
||||
rt_err_t rt_bus_for_each_dev(rt_bus_t bus, void *data, int (*fn)(rt_device_t dev, void *));
|
||||
rt_err_t rt_bus_for_each_drv(rt_bus_t bus, void *data, int (*fn)(rt_driver_t drv, void *));
|
||||
|
||||
rt_err_t rt_bus_add_driver(rt_bus_t bus, rt_driver_t drv);
|
||||
rt_err_t rt_bus_add_device(rt_bus_t bus, rt_device_t dev);
|
||||
rt_err_t rt_bus_remove_driver(rt_driver_t drv);
|
||||
rt_err_t rt_bus_remove_device(rt_device_t dev);
|
||||
|
||||
rt_err_t rt_bus_shutdown(void);
|
||||
|
||||
rt_bus_t rt_bus_find_by_name(const char *name);
|
||||
rt_err_t rt_bus_reload_driver_device(rt_bus_t new_bus, rt_device_t dev);
|
||||
|
||||
rt_err_t rt_bus_register(rt_bus_t bus);
|
||||
|
||||
#endif /* __BUS_H__ */
|
||||
@@ -0,0 +1,165 @@
|
||||
/*
|
||||
* Copyright (c) 2006-2021, RT-Thread Development Team
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2023-04-20 ErikChan the first version
|
||||
*/
|
||||
|
||||
#ifndef __CORE_DM_H__
|
||||
#define __CORE_DM_H__
|
||||
|
||||
#include <rthw.h>
|
||||
#include <rtdef.h>
|
||||
#include <ioremap.h>
|
||||
#include <drivers/misc.h>
|
||||
#include <drivers/byteorder.h>
|
||||
|
||||
#ifndef RT_CPUS_NR
|
||||
#define RT_CPUS_NR 1
|
||||
#endif
|
||||
|
||||
#ifndef RT_USING_SMP
|
||||
extern int rt_hw_cpu_id(void);
|
||||
#endif
|
||||
|
||||
void rt_dm_secondary_cpu_init(void);
|
||||
|
||||
int rt_dm_dev_set_name_auto(rt_device_t dev, const char *prefix);
|
||||
int rt_dm_dev_get_name_id(rt_device_t dev);
|
||||
|
||||
int rt_dm_dev_set_name(rt_device_t dev, const char *format, ...);
|
||||
const char *rt_dm_dev_get_name(rt_device_t dev);
|
||||
|
||||
int rt_dm_dev_get_address_count(rt_device_t dev);
|
||||
rt_err_t rt_dm_dev_get_address(rt_device_t dev, int index,
|
||||
rt_uint64_t *out_address, rt_uint64_t *out_size);
|
||||
rt_err_t rt_dm_dev_get_address_by_name(rt_device_t dev, const char *name,
|
||||
rt_uint64_t *out_address, rt_uint64_t *out_size);
|
||||
int rt_dm_dev_get_address_array(rt_device_t dev, int nr, rt_uint64_t *out_regs);
|
||||
|
||||
void *rt_dm_dev_iomap(rt_device_t dev, int index);
|
||||
void *rt_dm_dev_iomap_by_name(rt_device_t dev, const char *name);
|
||||
|
||||
int rt_dm_dev_get_irq_count(rt_device_t dev);
|
||||
int rt_dm_dev_get_irq(rt_device_t dev, int index);
|
||||
int rt_dm_dev_get_irq_by_name(rt_device_t dev, const char *name);
|
||||
|
||||
void rt_dm_dev_bind_fwdata(rt_device_t dev, void *fw_np, void *data);
|
||||
void rt_dm_dev_unbind_fwdata(rt_device_t dev, void *fw_np);
|
||||
|
||||
int rt_dm_dev_prop_read_u8_array_index(rt_device_t dev, const char *propname,
|
||||
int index, int nr, rt_uint8_t *out_values);
|
||||
int rt_dm_dev_prop_read_u16_array_index(rt_device_t dev, const char *propname,
|
||||
int index, int nr, rt_uint16_t *out_values);
|
||||
int rt_dm_dev_prop_read_u32_array_index(rt_device_t dev, const char *propname,
|
||||
int index, int nr, rt_uint32_t *out_values);
|
||||
int rt_dm_dev_prop_read_u64_array_index(rt_device_t dev, const char *propname,
|
||||
int index, int nr, rt_uint64_t *out_values);
|
||||
int rt_dm_dev_prop_read_string_array_index(rt_device_t dev, const char *propname,
|
||||
int index, int nr, const char **out_strings);
|
||||
|
||||
int rt_dm_dev_prop_count_of_size(rt_device_t dev, const char *propname, int size);
|
||||
int rt_dm_dev_prop_index_of_string(rt_device_t dev, const char *propname, const char *string);
|
||||
|
||||
rt_bool_t rt_dm_dev_prop_read_bool(rt_device_t dev, const char *propname);
|
||||
|
||||
rt_inline rt_err_t rt_dm_dev_prop_read_u8_index(rt_device_t dev, const char *propname,
|
||||
int index, rt_uint8_t *out_value)
|
||||
{
|
||||
int nr = rt_dm_dev_prop_read_u8_array_index(dev, propname, index, 1, out_value);
|
||||
|
||||
return nr > 0 ? RT_EOK : (rt_err_t)nr;
|
||||
}
|
||||
|
||||
rt_inline rt_err_t rt_dm_dev_prop_read_u16_index(rt_device_t dev, const char *propname,
|
||||
int index, rt_uint16_t *out_value)
|
||||
{
|
||||
int nr = rt_dm_dev_prop_read_u16_array_index(dev, propname, index, 1, out_value);
|
||||
|
||||
return nr > 0 ? RT_EOK : (rt_err_t)nr;
|
||||
}
|
||||
|
||||
rt_inline rt_err_t rt_dm_dev_prop_read_u32_index(rt_device_t dev, const char *propname,
|
||||
int index, rt_uint32_t *out_value)
|
||||
{
|
||||
int nr = rt_dm_dev_prop_read_u32_array_index(dev, propname, index, 1, out_value);
|
||||
|
||||
return nr > 0 ? RT_EOK : (rt_err_t)nr;
|
||||
}
|
||||
|
||||
rt_inline rt_err_t rt_dm_dev_prop_read_u64_index(rt_device_t dev, const char *propname,
|
||||
int index, rt_uint64_t *out_value)
|
||||
{
|
||||
int nr = rt_dm_dev_prop_read_u64_array_index(dev, propname, index, 1, out_value);
|
||||
|
||||
return nr > 0 ? RT_EOK : (rt_err_t)nr;
|
||||
}
|
||||
|
||||
rt_inline rt_err_t rt_dm_dev_prop_read_string_index(rt_device_t dev, const char *propname,
|
||||
int index, const char **out_string)
|
||||
{
|
||||
int nr = rt_dm_dev_prop_read_string_array_index(dev, propname, index, 1, out_string);
|
||||
|
||||
return nr > 0 ? RT_EOK : (rt_err_t)nr;
|
||||
}
|
||||
|
||||
rt_inline rt_err_t rt_dm_dev_prop_read_u8(rt_device_t dev, const char *propname,
|
||||
rt_uint8_t *out_value)
|
||||
{
|
||||
return rt_dm_dev_prop_read_u8_index(dev, propname, 0, out_value);
|
||||
}
|
||||
|
||||
rt_inline rt_err_t rt_dm_dev_prop_read_u16(rt_device_t dev, const char *propname,
|
||||
rt_uint16_t *out_value)
|
||||
{
|
||||
return rt_dm_dev_prop_read_u16_index(dev, propname, 0, out_value);
|
||||
}
|
||||
|
||||
rt_inline rt_err_t rt_dm_dev_prop_read_u32(rt_device_t dev, const char *propname,
|
||||
rt_uint32_t *out_value)
|
||||
{
|
||||
return rt_dm_dev_prop_read_u32_index(dev, propname, 0, out_value);
|
||||
}
|
||||
|
||||
rt_inline rt_err_t rt_dm_dev_prop_read_s32(rt_device_t dev, const char *propname,
|
||||
rt_int32_t *out_value)
|
||||
{
|
||||
return rt_dm_dev_prop_read_u32_index(dev, propname, 0, (rt_uint32_t *)out_value);
|
||||
}
|
||||
|
||||
rt_inline rt_err_t rt_dm_dev_prop_read_u64(rt_device_t dev, const char *propname,
|
||||
rt_uint64_t *out_value)
|
||||
{
|
||||
return rt_dm_dev_prop_read_u64_index(dev, propname, 0, out_value);
|
||||
}
|
||||
|
||||
rt_inline rt_err_t rt_dm_dev_prop_read_string(rt_device_t dev, const char *propname,
|
||||
const char **out_string)
|
||||
{
|
||||
return rt_dm_dev_prop_read_string_index(dev, propname, 0, out_string);
|
||||
}
|
||||
|
||||
rt_inline int rt_dm_dev_prop_count_of_u8(rt_device_t dev, const char *propname)
|
||||
{
|
||||
return rt_dm_dev_prop_count_of_size(dev, propname, sizeof(rt_uint8_t));
|
||||
}
|
||||
|
||||
rt_inline int rt_dm_dev_prop_count_of_u16(rt_device_t dev, const char *propname)
|
||||
{
|
||||
return rt_dm_dev_prop_count_of_size(dev, propname, sizeof(rt_uint16_t));
|
||||
}
|
||||
|
||||
rt_inline int rt_dm_dev_prop_count_of_u32(rt_device_t dev, const char *propname)
|
||||
{
|
||||
return rt_dm_dev_prop_count_of_size(dev, propname, sizeof(rt_uint32_t));
|
||||
}
|
||||
|
||||
rt_inline int rt_dm_dev_prop_count_of_u64(rt_device_t dev, const char *propname)
|
||||
{
|
||||
return rt_dm_dev_prop_count_of_size(dev, propname, sizeof(rt_uint64_t));
|
||||
}
|
||||
|
||||
#endif /* __RT_DM_H__ */
|
||||
@@ -0,0 +1,54 @@
|
||||
/*
|
||||
* 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_DRIVER_H__
|
||||
#define __CORE_DRIVER_H__
|
||||
|
||||
#include <rtdef.h>
|
||||
|
||||
struct rt_driver
|
||||
{
|
||||
struct rt_object parent;
|
||||
struct rt_bus *bus;
|
||||
rt_list_t node;
|
||||
|
||||
rt_uint32_t ref_count;
|
||||
|
||||
#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;
|
||||
|
||||
int (*probe)(struct rt_device *dev);
|
||||
int (*remove)(struct rt_device *dev);
|
||||
int (*shutdown)(struct rt_device *dev);
|
||||
};
|
||||
|
||||
rt_err_t rt_driver_register(rt_driver_t drv);
|
||||
rt_err_t rt_driver_unregister(rt_driver_t drv);
|
||||
|
||||
#define RT_DRIVER_EXPORT(driver, bus_name, mode) \
|
||||
static int ___##driver##_register(void) \
|
||||
{ \
|
||||
rt_##bus_name##_driver_register(&driver); \
|
||||
return 0; \
|
||||
} \
|
||||
INIT_DEVICE_EXPORT(___##driver##_register); \
|
||||
|
||||
#endif /* __DRIVER_H__ */
|
||||
Reference in new issue
Block a user