summaryrefslogtreecommitdiff
path: root/components/drivers/include
diff options
context:
space:
mode:
Diffstat (limited to 'components/drivers/include')
-rw-r--r--components/drivers/include/drivers/i2c.h32
-rw-r--r--components/drivers/include/drivers/i2c_dm.h51
-rw-r--r--components/drivers/include/rtdevice.h39
3 files changed, 105 insertions, 17 deletions
diff --git a/components/drivers/include/drivers/i2c.h b/components/drivers/include/drivers/i2c.h
index ed87425260..0473a1e8dd 100644
--- a/components/drivers/include/drivers/i2c.h
+++ b/components/drivers/include/drivers/i2c.h
@@ -63,10 +63,42 @@ struct rt_i2c_bus_device
struct rt_i2c_client
{
+#ifdef RT_USING_DM
+ struct rt_device parent;
+
+ const char *name;
+ const struct rt_i2c_device_id *id;
+ const struct rt_ofw_node_id *ofw_id;
+#endif
struct rt_i2c_bus_device *bus;
rt_uint16_t client_addr;
};
+#ifdef RT_USING_DM
+struct rt_i2c_device_id
+{
+ char name[20];
+ void *data;
+};
+
+struct rt_i2c_driver
+{
+ struct rt_driver parent;
+
+ const struct rt_i2c_device_id *ids;
+ const struct rt_ofw_node_id *ofw_ids;
+
+ rt_err_t (*probe)(struct rt_i2c_client *client);
+ rt_err_t (*remove)(struct rt_i2c_client *client);
+ rt_err_t (*shutdown)(struct rt_i2c_client *client);
+};
+
+rt_err_t rt_i2c_driver_register(struct rt_i2c_driver *driver);
+rt_err_t rt_i2c_device_register(struct rt_i2c_client *client);
+
+#define RT_I2C_DRIVER_EXPORT(driver) RT_DRIVER_EXPORT(driver, i2c, BUILIN)
+#endif /* RT_USING_DM */
+
rt_err_t rt_i2c_bus_device_register(struct rt_i2c_bus_device *bus,
const char *bus_name);
struct rt_i2c_bus_device *rt_i2c_bus_device_find(const char *bus_name);
diff --git a/components/drivers/include/drivers/i2c_dm.h b/components/drivers/include/drivers/i2c_dm.h
new file mode 100644
index 0000000000..4f5b251c60
--- /dev/null
+++ b/components/drivers/include/drivers/i2c_dm.h
@@ -0,0 +1,51 @@
+/*
+ * Copyright (c) 2006-2022, RT-Thread Development Team
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Change Logs:
+ * Date Author Notes
+ * 2022-11-26 GuEe-GUI first version
+ */
+
+#ifndef __I2C_DM_H__
+#define __I2C_DM_H__
+
+#include <rthw.h>
+#include <rtthread.h>
+#include <drivers/core/bus.h>
+
+/* I2C Frequency Modes */
+#define I2C_MAX_STANDARD_MODE_FREQ 100000
+#define I2C_MAX_FAST_MODE_FREQ 400000
+#define I2C_MAX_FAST_MODE_PLUS_FREQ 1000000
+#define I2C_MAX_TURBO_MODE_FREQ 1400000
+#define I2C_MAX_HIGH_SPEED_MODE_FREQ 3400000
+#define I2C_MAX_ULTRA_FAST_MODE_FREQ 5000000
+
+struct i2c_timings
+{
+ rt_uint32_t bus_freq_hz; /* the bus frequency in Hz */
+ rt_uint32_t scl_rise_ns; /* time SCL signal takes to rise in ns; t(r) in the I2C specification */
+ rt_uint32_t scl_fall_ns; /* time SCL signal takes to fall in ns; t(f) in the I2C specification */
+ rt_uint32_t scl_int_delay_ns; /* time IP core additionally needs to setup SCL in ns */
+ rt_uint32_t sda_fall_ns; /* time SDA signal takes to fall in ns; t(f) in the I2C specification */
+ rt_uint32_t sda_hold_ns; /* time IP core additionally needs to hold SDA in ns */
+ rt_uint32_t digital_filter_width_ns; /* width in ns of spikes on i2c lines that the IP core digital filter can filter out */
+ rt_uint32_t analog_filter_cutoff_freq_hz; /* threshold frequency for the low pass IP core analog filter */
+};
+
+#ifdef RT_USING_OFW
+rt_err_t i2c_timings_ofw_parse(struct rt_ofw_node *dev_np, struct i2c_timings *timings,
+ rt_bool_t use_defaults);
+#else
+rt_inline rt_err_t i2c_timings_ofw_parse(struct rt_ofw_node *dev_np, struct i2c_timings *timings,
+ rt_bool_t use_defaults)
+{
+ return RT_EOK;
+}
+#endif /* RT_USING_OFW */
+
+void i2c_bus_scan_clients(struct rt_i2c_bus_device *bus);
+
+#endif /* __I2C_DM_H__ */
diff --git a/components/drivers/include/rtdevice.h b/components/drivers/include/rtdevice.h
index 2445a65823..afb5bb2533 100644
--- a/components/drivers/include/rtdevice.h
+++ b/components/drivers/include/rtdevice.h
@@ -15,6 +15,7 @@
#include <rtdef.h>
#include <rtthread.h>
#include <drivers/core/driver.h>
+#include <drivers/core/bus.h>
#include <drivers/classes/block.h>
#include <drivers/classes/char.h>
@@ -38,6 +39,23 @@ extern "C" {
#define RT_DEVICE(device) ((rt_device_t)device)
+#ifdef RT_USING_DM
+#include "drivers/core/dm.h"
+#include "drivers/platform.h"
+
+#ifdef RT_USING_OFW
+#include "drivers/ofw.h"
+#include "drivers/ofw_fdt.h"
+#include "drivers/ofw_io.h"
+#include "drivers/ofw_irq.h"
+#include "drivers/ofw_raw.h"
+#endif /* RT_USING_OFW */
+
+#ifdef RT_USING_PIC
+#include "drivers/pic.h"
+#endif
+#endif /* RT_USING_DM */
+
#ifdef RT_USING_RTC
#include "drivers/rtc.h"
#ifdef RT_USING_ALARM
@@ -80,6 +98,10 @@ extern "C" {
#ifdef RT_USING_I2C_BITOPS
#include "drivers/i2c-bit-ops.h"
#endif /* RT_USING_I2C_BITOPS */
+
+#ifdef RT_USING_DM
+#include "drivers/i2c_dm.h"
+#endif /* RT_USING_DM */
#endif /* RT_USING_I2C */
#ifdef RT_USING_PHY
@@ -182,23 +204,6 @@ extern "C" {
#include "drivers/clk.h"
#endif /* RT_USING_CLK */
-#ifdef RT_USING_DM
-#include "drivers/core/dm.h"
-#include "drivers/platform.h"
-
-#ifdef RT_USING_OFW
-#include "drivers/ofw.h"
-#include "drivers/ofw_fdt.h"
-#include "drivers/ofw_io.h"
-#include "drivers/ofw_irq.h"
-#include "drivers/ofw_raw.h"
-#endif /* RT_USING_OFW */
-
-#ifdef RT_USING_PIC
-#include "drivers/pic.h"
-#endif
-#endif /* RT_USING_DM */
-
#ifdef __cplusplus
}
#endif