summaryrefslogtreecommitdiff
path: root/bsp/raspberry-pi/dm/input
diff options
context:
space:
mode:
authorGuEe-GUI <[email protected]>2026-08-15 22:36:46 +0800
committerRbb666 <[email protected]>2026-08-16 19:56:03 +0800
commitf7258a6bb80d9be12e73675ab35a04651e32eda3 (patch)
tree050411e5f5e9990179a554bc8d0608762fabfa05 /bsp/raspberry-pi/dm/input
parent2bcc47d418a4aed421d9750569a565a954daf045 (diff)
[bsp/raspberry-pi] update DM support
- reorganize common Raspberry Pi drivers under the device framework - add the Raspberry Pi 5 BSP, configuration and documentation - add BCM2712 and DesignWare AXI DMA controller support - distinguish BCM2712 DMA32 and DMA40 channels by channel mask - restore DesignWare AXI DMA enable bits after controller reset - support a shared AXI maximum burst length across DMA channels Signed-off-by: GuEe-GUI <[email protected]>
Diffstat (limited to 'bsp/raspberry-pi/dm/input')
-rwxr-xr-xbsp/raspberry-pi/dm/input/SConscript13
-rwxr-xr-xbsp/raspberry-pi/dm/input/joystick/Kconfig5
-rwxr-xr-xbsp/raspberry-pi/dm/input/joystick/SConscript13
-rwxr-xr-xbsp/raspberry-pi/dm/input/joystick/js-rpisense.c154
-rwxr-xr-xbsp/raspberry-pi/dm/input/touchscreen/Kconfig9
-rwxr-xr-xbsp/raspberry-pi/dm/input/touchscreen/SConscript13
-rwxr-xr-xbsp/raspberry-pi/dm/input/touchscreen/ts-raspberrypi.c264
7 files changed, 471 insertions, 0 deletions
diff --git a/bsp/raspberry-pi/dm/input/SConscript b/bsp/raspberry-pi/dm/input/SConscript
new file mode 100755
index 0000000000..3d15055d62
--- /dev/null
+++ b/bsp/raspberry-pi/dm/input/SConscript
@@ -0,0 +1,13 @@
+import os
+from building import *
+
+cwd = GetCurrentDir()
+objs = []
+list = os.listdir(cwd)
+
+for d in list:
+ path = os.path.join(cwd, d)
+ if os.path.isfile(os.path.join(path, 'SConscript')):
+ objs = objs + SConscript(os.path.join(d, 'SConscript'))
+
+Return('objs')
diff --git a/bsp/raspberry-pi/dm/input/joystick/Kconfig b/bsp/raspberry-pi/dm/input/joystick/Kconfig
new file mode 100755
index 0000000000..b5be7b9cc7
--- /dev/null
+++ b/bsp/raspberry-pi/dm/input/joystick/Kconfig
@@ -0,0 +1,5 @@
+config RT_INPUT_JOYSTICK_RPISENSE
+ bool "Raspberry Pi Sense HAT joystick"
+ depends on RT_INPUT_JOYSTICK
+ depends on RT_MFD_RPI_SENSE
+ default n
diff --git a/bsp/raspberry-pi/dm/input/joystick/SConscript b/bsp/raspberry-pi/dm/input/joystick/SConscript
new file mode 100755
index 0000000000..4061a05e44
--- /dev/null
+++ b/bsp/raspberry-pi/dm/input/joystick/SConscript
@@ -0,0 +1,13 @@
+from building import *
+
+group = []
+src = []
+cwd = GetCurrentDir()
+CPPPATH = [cwd + '/../../include']
+
+if GetDepend(['RT_INPUT_JOYSTICK_RPISENSE']):
+ src += ['js-rpisense.c']
+
+group = DefineGroup('DeviceDrivers', src, depend = [''], CPPPATH = CPPPATH)
+
+Return('group')
diff --git a/bsp/raspberry-pi/dm/input/joystick/js-rpisense.c b/bsp/raspberry-pi/dm/input/joystick/js-rpisense.c
new file mode 100755
index 0000000000..9bfeaea847
--- /dev/null
+++ b/bsp/raspberry-pi/dm/input/joystick/js-rpisense.c
@@ -0,0 +1,154 @@
+/*
+ * Copyright (c) 2006-2023, RT-Thread Development Team
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Change Logs:
+ * Date Author Notes
+ * 2023-02-25 GuEe-GUI the first version
+ */
+
+#include <rtthread.h>
+#include <rtdevice.h>
+
+#include <rpi-sense.h>
+
+struct rpisense_joystick
+{
+ struct rt_input_device parent;
+ struct rpisense *rpisense;
+
+ rt_base_t pin;
+ rt_uint8_t active_val;
+ rt_int32_t prev_keys;
+
+ struct rt_thread *keys_task;
+};
+
+static rt_uint8_t keymap[5] =
+{
+ KEY_DOWN, KEY_RIGHT, KEY_UP, KEY_ENTER, KEY_LEFT
+};
+
+static void rpisense_keys_task(void *param)
+{
+ rt_int32_t keys, changes;
+ struct rpisense_joystick *rpisense_js = param;
+
+ while (RT_TRUE)
+ {
+ rt_thread_suspend(rpisense_js->keys_task);
+ rt_schedule();
+
+ keys = rpisense_reg_read(rpisense_js->rpisense, RPISENSE_KEYS);
+ changes = keys ^ rpisense_js->prev_keys;
+ rpisense_js->prev_keys = keys;
+
+ for (int i = 0; i < RT_ARRAY_SIZE(keymap); ++i)
+ {
+ if (changes & 1)
+ {
+ rt_input_report_key(&rpisense_js->parent, keymap[i], keys & 1);
+ }
+
+ changes >>= 1;
+ keys >>= 1;
+ }
+
+ rt_input_sync(&rpisense_js->parent);
+ }
+}
+
+static void rpisense_isr(void *args)
+{
+ struct rpisense_joystick *rpisense_js = args;
+
+ rt_thread_resume(rpisense_js->keys_task);
+}
+
+static rt_err_t rpisense_js_probe(struct rt_platform_device *pdev)
+{
+ rt_err_t err;
+ struct rpisense *rpisense = pdev->priv;
+ struct rpisense_joystick *rpisense_js = rt_calloc(1, sizeof(*rpisense_js));
+
+ if (!rpisense_js)
+ {
+ return -RT_ENOMEM;
+ }
+
+ rpisense_js->rpisense = rpisense;
+ rpisense_js->pin = rt_pin_get_named_pin(&rpisense->i2c_client->parent,
+ "keys-int", 0, RT_NULL, &rpisense_js->active_val);
+
+ if (rpisense_js->pin < 0)
+ {
+ err = rpisense_js->pin;
+ goto _fail;
+ }
+
+ rt_pin_write(rpisense_js->pin, rpisense_js->active_val);
+ rt_pin_mode(rpisense_js->pin, PIN_MODE_INPUT);
+ rt_pin_attach_irq(rpisense_js->pin, PIN_IRQ_MODE_RISING, rpisense_isr, rpisense_js);
+ rt_pin_irq_enable(rpisense_js->pin, RT_TRUE);
+
+ for (int i = 0; i < RT_ARRAY_SIZE(keymap); ++i)
+ {
+ rt_input_set_capability(&rpisense_js->parent, EV_KEY, keymap[i]);
+ }
+
+ if ((err = rt_input_device_register(&rpisense_js->parent)))
+ {
+ goto _fail;
+ }
+
+ rpisense_js->keys_task = rt_thread_create("rpisense-js", &rpisense_keys_task,
+ rpisense_js, DM_THREAD_STACK_SIZE, RT_THREAD_PRIORITY_MAX / 2, 10);
+
+ if (!rpisense_js->keys_task)
+ {
+ rt_input_device_unregister(&rpisense_js->parent);
+ goto _fail;
+ }
+
+ pdev->parent.user_data = rpisense_js;
+
+ rt_thread_startup(rpisense_js->keys_task);
+
+ return RT_EOK;
+
+_fail:
+ if (rpisense_js->pin >= 0)
+ {
+ rt_pin_detach_irq(rpisense_js->pin);
+ }
+
+ rt_free(rpisense_js);
+
+ return err;
+}
+
+static rt_err_t rpisense_js_remove(struct rt_platform_device *pdev)
+{
+ struct rpisense_joystick *rpisense_js = pdev->parent.user_data;
+
+ rt_pin_irq_enable(rpisense_js->pin, RT_FALSE);
+ rt_pin_detach_irq(rpisense_js->pin);
+
+ rt_thread_delete(rpisense_js->keys_task);
+
+ rt_input_device_unregister(&rpisense_js->parent);
+
+ rt_free(rpisense_js);
+
+ return RT_EOK;
+}
+
+static struct rt_platform_driver rpisense_js_driver =
+{
+ .name = "rpi-sense-js",
+
+ .probe = rpisense_js_probe,
+ .remove = rpisense_js_remove,
+};
+RT_PLATFORM_DRIVER_EXPORT(rpisense_js_driver);
diff --git a/bsp/raspberry-pi/dm/input/touchscreen/Kconfig b/bsp/raspberry-pi/dm/input/touchscreen/Kconfig
new file mode 100755
index 0000000000..9766216f38
--- /dev/null
+++ b/bsp/raspberry-pi/dm/input/touchscreen/Kconfig
@@ -0,0 +1,9 @@
+config RT_INPUT_TOUCHSCREEN_RASPBERRYPI_FW
+ bool "Raspberry Pi's firmware base touch screen support"
+ depends on RT_INPUT_TOUCHSCREEN
+ depends on RT_USING_OFW
+ depends on RT_USING_DMA
+ depends on RT_FIRMWARE_RASPBERRYPI
+ depends on RT_USING_ADT
+ depends on RT_USING_ADT_BITMAP
+ default n
diff --git a/bsp/raspberry-pi/dm/input/touchscreen/SConscript b/bsp/raspberry-pi/dm/input/touchscreen/SConscript
new file mode 100755
index 0000000000..0b95fd9d21
--- /dev/null
+++ b/bsp/raspberry-pi/dm/input/touchscreen/SConscript
@@ -0,0 +1,13 @@
+from building import *
+
+group = []
+src = []
+cwd = GetCurrentDir()
+CPPPATH = [cwd + '/../../include']
+
+if GetDepend(['RT_INPUT_TOUCHSCREEN_RASPBERRYPI_FW']):
+ src += ['ts-raspberrypi.c']
+
+group = DefineGroup('DeviceDrivers', src, depend = [''], CPPPATH = CPPPATH)
+
+Return('group')
diff --git a/bsp/raspberry-pi/dm/input/touchscreen/ts-raspberrypi.c b/bsp/raspberry-pi/dm/input/touchscreen/ts-raspberrypi.c
new file mode 100755
index 0000000000..0e2da82d4c
--- /dev/null
+++ b/bsp/raspberry-pi/dm/input/touchscreen/ts-raspberrypi.c
@@ -0,0 +1,264 @@
+/*
+ * 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
+ */
+
+#include <rthw.h>
+#include <rtthread.h>
+#include <rtdevice.h>
+
+#define DBG_TAG "input.touchscreen.rpi-ts"
+#define DBG_LVL DBG_INFO
+#include <rtdbg.h>
+
+#include <firmware-raspberrypi.h>
+
+#define RPI_TS_DEFAULT_WIDTH 800
+#define RPI_TS_DEFAULT_HEIGHT 480
+
+#define RPI_TS_MAX_SUPPORTED_POINTS 10
+
+#define RPI_TS_FTS_TOUCH_DOWN 0
+#define RPI_TS_FTS_TOUCH_CONTACT 2
+
+#define RPI_TS_POLL_INTERVAL 17 /* 60fps */
+
+#define RPI_TS_NPOINTS_REG_INVALIDATE 99
+
+struct rpi_ts_regs
+{
+ rt_uint8_t device_mode;
+ rt_uint8_t gesture_id;
+ rt_uint8_t num_points;
+
+ struct rpi_ts_touch
+ {
+ rt_uint8_t xh;
+ rt_uint8_t xl;
+ rt_uint8_t yh;
+ rt_uint8_t yl;
+ rt_uint8_t pressure; /* Not supported */
+ rt_uint8_t area; /* Not supported */
+ } point[RPI_TS_MAX_SUPPORTED_POINTS];
+};
+
+struct rpi_ts
+{
+ struct rt_input_device parent;
+
+ void *fw_regs;
+ rt_ubase_t fw_regs_phys;
+
+ int known_ids;
+ struct rpi_ts_regs ts_regs;
+};
+
+#define raw_to_rpi_ts(raw) rt_container_of(raw, struct rpi_ts, parent)
+
+static void rpi_ts_poll(struct rt_input_device *idev)
+{
+ int touchid;
+ int event_type;
+ int modified_ids = 0;
+ int x, y, bit = 0;
+ rt_bitmap_t released_ids;
+ struct rpi_ts *rts = raw_to_rpi_ts(idev);
+ struct rpi_ts_regs *regs = &rts->ts_regs;
+
+ rt_memcpy(regs, rts->fw_regs, sizeof(*regs));
+
+ /*
+ * We poll the memory based register copy of the touchscreen chip using
+ * the number of points register to know whether the copy has been
+ * updated (we write 99 to the memory copy, the GPU will write between
+ * 0 - 10 points)
+ */
+ HWREG8(rts->fw_regs + (rt_size_t)&((struct rpi_ts_regs *)0)->num_points) =
+ RPI_TS_NPOINTS_REG_INVALIDATE;
+
+ if (regs->num_points == RPI_TS_NPOINTS_REG_INVALIDATE ||
+ (regs->num_points == 0 && rts->known_ids == 0))
+ {
+ return;
+ }
+
+ for (int i = 0; i < regs->num_points; ++i)
+ {
+ x = (((int)regs->point[i].xh & 0xf) << 8) + regs->point[i].xl;
+ y = (((int)regs->point[i].yh & 0xf) << 8) + regs->point[i].yl;
+ touchid = (regs->point[i].yh >> 4) & 0xf;
+ event_type = (regs->point[i].xh >> 6) & 0x03;
+
+ modified_ids |= RT_BIT(touchid);
+
+ if (event_type == RPI_TS_FTS_TOUCH_DOWN ||
+ event_type == RPI_TS_FTS_TOUCH_CONTACT)
+ {
+ rt_input_report_touch_slot(idev, touchid);
+ rt_input_report_touch_inactive(idev, RT_TRUE);
+ rt_input_report_touch_position(idev, x, y, RT_TRUE);
+ }
+ }
+
+ released_ids = rts->known_ids & ~modified_ids;
+ rt_bitmap_for_each_set_bit(&released_ids, bit, RPI_TS_MAX_SUPPORTED_POINTS)
+ {
+ rt_input_report_touch_slot(idev, bit);
+ rt_input_report_touch_inactive(idev, RT_FALSE);
+ modified_ids &= ~RT_BIT(bit);
+ }
+
+ rts->known_ids = modified_ids;
+ rt_input_sync(idev);
+}
+
+static rt_err_t rpi_ts_probe(struct rt_platform_device *pdev)
+{
+ rt_err_t err = RT_EOK;
+ rt_uint32_t touchbuf;
+ struct rt_touch_info touch_info = {};
+ struct rpi_firmware *rpi_fw = RT_NULL;
+ struct rt_device *dev = &pdev->parent;
+ struct rt_ofw_node *np = dev->ofw_node, *fw_np;
+ struct rpi_ts *rts = rt_calloc(1, sizeof(*rts));
+
+ if (!rts)
+ {
+ return -RT_ENOMEM;
+ }
+ rts->parent.parent.ofw_node = np;
+
+ fw_np = rt_ofw_parse_phandle(np, "firmware", 0);
+
+ if (!fw_np)
+ {
+ err = -RT_EINVAL;
+ goto _fail;
+ }
+
+ rpi_fw = rpi_firmware_get(fw_np);
+ rt_ofw_node_put(fw_np);
+
+ if (!rpi_fw)
+ {
+ err = -RT_EINVAL;
+ goto _fail;
+ }
+
+ rts->fw_regs = rt_dma_alloc_coherent(dev, ARCH_PAGE_SIZE, &rts->fw_regs_phys);
+
+ if (!rts->fw_regs)
+ {
+ LOG_E("Failed to dma buffer");
+
+ goto _fail;
+ }
+
+ if (rts->fw_regs_phys > RT_UINT32_MAX)
+ {
+ LOG_E("64 bits dma buffer is not support");
+
+ goto _fail;
+ }
+
+ touchbuf = (rt_uint32_t)rts->fw_regs_phys;
+
+ if ((err = rpi_firmware_property(rpi_fw, RPI_FIRMWARE_FRAMEBUFFER_SET_TOUCHBUF,
+ &touchbuf, sizeof(touchbuf))))
+ {
+ LOG_E("Set touchbuf from firmware error = %s", rt_strerror(err));
+
+ goto _fail;
+ }
+
+ if ((err = rt_input_set_capability(&rts->parent, EV_ABS, ABS_MT_POSITION_X)) ||
+ (err = rt_input_set_capability(&rts->parent, EV_ABS, ABS_MT_POSITION_Y)))
+ {
+ goto _fail;
+ }
+
+ rt_input_set_absinfo(&rts->parent,
+ ABS_MT_POSITION_X, 0, RPI_TS_DEFAULT_WIDTH, 0, 0);
+
+ rt_input_set_absinfo(&rts->parent,
+ ABS_MT_POSITION_Y, 0, RPI_TS_DEFAULT_HEIGHT, 0, 0);
+
+ if ((err = rt_input_setup_polling(&rts->parent, rpi_ts_poll)))
+ {
+ goto _fail;
+ }
+
+ rt_input_set_poll_interval(&rts->parent, RPI_TS_POLL_INTERVAL);
+
+ touch_info.type = RT_TOUCH_TYPE_RESISTANCE;
+ touch_info.vendor = RT_TOUCH_VENDOR_UNKNOWN;
+
+ if ((err = rt_input_setup_touch(&rts->parent,
+ RPI_TS_MAX_SUPPORTED_POINTS, &touch_info)))
+ {
+ goto _fail;
+ }
+
+ if ((err = rt_input_device_register(&rts->parent)))
+ {
+ goto _fail;
+ }
+
+ rt_dm_dev_bind_fwdata(dev, RT_NULL, &rts->parent);
+ dev->user_data = rts;
+
+ return RT_EOK;
+
+_fail:
+ rt_input_remove_config(&rts->parent);
+
+ if (rts->fw_regs)
+ {
+ rt_dma_free_coherent(dev, ARCH_PAGE_SIZE, rts->fw_regs, rts->fw_regs_phys);
+ }
+
+ if (rpi_fw)
+ {
+ rpi_firmware_put(rpi_fw);
+ }
+
+ rt_free(rts);
+
+ return err;
+}
+
+static rt_err_t rpi_ts_remove(struct rt_platform_device *pdev)
+{
+ struct rt_device *dev = &pdev->parent;
+ struct rpi_ts *rts = dev->user_data;
+
+ rt_dm_dev_unbind_fwdata(dev, RT_NULL);
+ rt_input_device_unregister(&rts->parent);
+
+ rt_dma_free_coherent(dev, ARCH_PAGE_SIZE, rts->fw_regs, rts->fw_regs_phys);
+
+ rt_free(rts);
+
+ return RT_EOK;
+}
+
+static const struct rt_ofw_node_id rpi_ts_ofw_ids[] =
+{
+ { .compatible = "raspberrypi,firmware-ts" },
+ { /* sentinel */ }
+};
+
+static struct rt_platform_driver rpi_ts_driver =
+{
+ .name = "touchscreen-rpi",
+ .ids = rpi_ts_ofw_ids,
+
+ .probe = rpi_ts_probe,
+ .remove = rpi_ts_remove,
+};
+RT_PLATFORM_DRIVER_EXPORT(rpi_ts_driver);