patch: sm8250: current: add Retroid Pocket SM8250 Patch series

Signed-off-by: CodeChenL <2540735020@qq.com>
This commit is contained in:
Jiali Chen 2026-01-14 13:46:04 +00:00 committed by Igor
parent 7a2b090888
commit 446fdd8bfa
7 changed files with 3966 additions and 0 deletions

View File

@ -0,0 +1,53 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Teguh Sobirin <teguh@sobir.in>
Date: Wed, 20 Nov 2024 22:58:09 +0700
Subject: arm64: dts: qcom: sm8250: add uart16 Signed-off-by: Teguh Sobirin
<teguh@sobir.in>
---
arch/arm64/boot/dts/qcom/sm8250.dtsi | 22 ++++++++++
1 file changed, 22 insertions(+)
diff --git a/arch/arm64/boot/dts/qcom/sm8250.dtsi b/arch/arm64/boot/dts/qcom/sm8250.dtsi
index 111111111111..222222222222 100644
--- a/arch/arm64/boot/dts/qcom/sm8250.dtsi
+++ b/arch/arm64/boot/dts/qcom/sm8250.dtsi
@@ -1153,6 +1153,23 @@ spi16: spi@888000 {
status = "disabled";
};
+ uart16: serial@888000 {
+ compatible = "qcom,geni-uart";
+ reg = <0 0x00888000 0 0x4000>;
+ clock-names = "se";
+ clocks = <&gcc GCC_QUPV3_WRAP2_S2_CLK>;
+ pinctrl-names = "default";
+ pinctrl-0 = <&qup_uart16_default>;
+ interrupts = <GIC_SPI 584 IRQ_TYPE_LEVEL_HIGH>;
+ power-domains = <&rpmhpd RPMHPD_CX>;
+ operating-points-v2 = <&qup_opp_table>;
+ interconnects = <&qup_virt MASTER_QUP_CORE_2 0 &qup_virt SLAVE_QUP_CORE_2 0>,
+ <&gem_noc MASTER_AMPSS_M0 0 &config_noc SLAVE_QUP_2 0>;
+ interconnect-names = "qup-core",
+ "qup-config";
+ status = "disabled";
+ };
+
i2c17: i2c@88c000 {
compatible = "qcom,geni-i2c";
reg = <0 0x0088c000 0 0x4000>;
@@ -5725,6 +5742,11 @@ qup_uart12_default: qup-uart12-default-state {
function = "qup12";
};
+ qup_uart16_default: qup-uart16-default-state {
+ pins = "gpio50", "gpio51";
+ function = "qup16";
+ };
+
qup_uart17_default: qup-uart17-default-state {
pins = "gpio52", "gpio53", "gpio54", "gpio55";
function = "qup17";
--
Armbian

View File

@ -0,0 +1,396 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Teguh Sobirin <teguh@sobir.in>
Date: Wed, 20 Nov 2024 23:04:35 +0700
Subject: drm: panel: Add DDIC CH13726A panel Signed-off-by: Teguh Sobirin
<teguh@sobir.in>
---
drivers/gpu/drm/panel/Kconfig | 11 +
drivers/gpu/drm/panel/Makefile | 1 +
drivers/gpu/drm/panel/panel-ddic-ch13726a.c | 341 ++++++++++
3 files changed, 353 insertions(+)
diff --git a/drivers/gpu/drm/panel/Kconfig b/drivers/gpu/drm/panel/Kconfig
index 111111111111..222222222222 100644
--- a/drivers/gpu/drm/panel/Kconfig
+++ b/drivers/gpu/drm/panel/Kconfig
@@ -87,6 +87,17 @@ config DRM_PANEL_BOE_TV101WUM_NL6
Say Y here if you want to support for BOE TV101WUM and AUO KD101N80
45NA WUXGA PANEL DSI Video Mode panel
+config DRM_PANEL_DDIC_CH13726A
+ tristate "DDIC CH13726A-based DSI panel"
+ depends on OF
+ depends on DRM_MIPI_DSI
+ depends on BACKLIGHT_CLASS_DEVICE
+ select DRM_DISPLAY_DP_HELPER
+ select DRM_DISPLAY_HELPER
+ help
+ Say Y here if you want to enable support for DDIC CH13726A-based
+ display panels.
+
config DRM_PANEL_BOE_TV101WUM_LL2
tristate "BOE TV101WUM LL2 1200x1920 panel"
depends on OF
diff --git a/drivers/gpu/drm/panel/Makefile b/drivers/gpu/drm/panel/Makefile
index 111111111111..222222222222 100644
--- a/drivers/gpu/drm/panel/Makefile
+++ b/drivers/gpu/drm/panel/Makefile
@@ -8,6 +8,7 @@ obj-$(CONFIG_DRM_PANEL_BOE_HIMAX8279D) += panel-boe-himax8279d.o
obj-$(CONFIG_DRM_PANEL_BOE_TH101MB31UIG002_28A) += panel-boe-th101mb31ig002-28a.o
obj-$(CONFIG_DRM_PANEL_BOE_TV101WUM_LL2) += panel-boe-tv101wum-ll2.o
obj-$(CONFIG_DRM_PANEL_BOE_TV101WUM_NL6) += panel-boe-tv101wum-nl6.o
+obj-$(CONFIG_DRM_PANEL_DDIC_CH13726A) += panel-ddic-ch13726a.o
obj-$(CONFIG_DRM_PANEL_DSI_CM) += panel-dsi-cm.o
obj-$(CONFIG_DRM_PANEL_LVDS) += panel-lvds.o
obj-$(CONFIG_DRM_PANEL_SIMPLE) += panel-simple.o
diff --git a/drivers/gpu/drm/panel/panel-ddic-ch13726a.c b/drivers/gpu/drm/panel/panel-ddic-ch13726a.c
new file mode 100644
index 000000000000..111111111111
--- /dev/null
+++ b/drivers/gpu/drm/panel/panel-ddic-ch13726a.c
@@ -0,0 +1,341 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * DDIC CH13726A MIPI-DSI panel driver
+ * Copyright (c) 2024, Teguh Sobirin <teguh@sobir.in>.
+ */
+
+#include <linux/backlight.h>
+#include <linux/delay.h>
+#include <linux/gpio/consumer.h>
+#include <linux/module.h>
+#include <linux/of.h>
+#include <linux/regulator/consumer.h>
+
+#include <drm/drm_mipi_dsi.h>
+#include <drm/drm_modes.h>
+#include <drm/drm_panel.h>
+
+#include <video/mipi_display.h>
+
+struct ch13726a_panel {
+ struct drm_panel panel;
+ struct mipi_dsi_device *dsi;
+ struct regulator_bulk_data supplies[4];
+ struct gpio_desc *reset_gpio;
+ const struct drm_display_mode *display_mode;
+ enum drm_panel_orientation orientation;
+ bool prepared;
+};
+
+static inline struct ch13726a_panel *to_ch13726a_panel(struct drm_panel *panel)
+{
+ return container_of(panel, struct ch13726a_panel, panel);
+}
+
+static void ch13726a_reset(struct ch13726a_panel *ctx)
+{
+ gpiod_set_value_cansleep(ctx->reset_gpio, 1);
+ usleep_range(10000, 11000);
+ gpiod_set_value_cansleep(ctx->reset_gpio, 0);
+ usleep_range(10000, 11000);
+ gpiod_set_value_cansleep(ctx->reset_gpio, 1);
+ usleep_range(10000, 11000);
+}
+
+static int ch13726a_on(struct ch13726a_panel *ctx)
+{
+ struct mipi_dsi_device *dsi = ctx->dsi;
+ struct device *dev = &dsi->dev;
+ int ret;
+
+ dsi->mode_flags |= MIPI_DSI_MODE_LPM;
+
+ ret = mipi_dsi_dcs_exit_sleep_mode(dsi);
+ if (ret < 0) {
+ dev_err(dev, "Failed to exit sleep mode: %d\n", ret);
+ return ret;
+ }
+ msleep(120);
+
+ ret = mipi_dsi_dcs_set_display_on(dsi);
+ if (ret < 0) {
+ dev_err(dev, "Failed to set display on: %d\n", ret);
+ return ret;
+ }
+ msleep(20);
+
+ return 0;
+}
+
+static int ch13726a_disable(struct drm_panel *panel)
+{
+ struct ch13726a_panel *ctx = to_ch13726a_panel(panel);
+ struct mipi_dsi_device *dsi = ctx->dsi;
+ struct device *dev = &dsi->dev;
+ int ret;
+
+ dsi->mode_flags &= ~MIPI_DSI_MODE_LPM;
+
+ ret = mipi_dsi_dcs_set_display_off(dsi);
+ if (ret < 0) {
+ dev_err(dev, "Failed to set display off: %d\n", ret);
+ return ret;
+ }
+
+ ret = mipi_dsi_dcs_enter_sleep_mode(dsi);
+ if (ret < 0) {
+ dev_err(dev, "Failed to enter sleep mode: %d\n", ret);
+ return ret;
+ }
+
+ msleep(100);
+
+ return 0;
+}
+
+static int ch13726a_prepare(struct drm_panel *panel)
+{
+ struct ch13726a_panel *ctx = to_ch13726a_panel(panel);
+ struct device *dev = &ctx->dsi->dev;
+ int ret;
+
+ if (ctx->prepared)
+ return 0;
+
+ ret = regulator_bulk_enable(ARRAY_SIZE(ctx->supplies), ctx->supplies);
+ if (ret < 0) {
+ dev_err(dev, "Failed to enable regulators: %d\n", ret);
+ return ret;
+ }
+
+ ch13726a_reset(ctx);
+
+ ret = ch13726a_on(ctx);
+ if (ret < 0) {
+ dev_err(dev, "Failed to initialize panel: %d\n", ret);
+ gpiod_set_value_cansleep(ctx->reset_gpio, 0);
+ regulator_bulk_disable(ARRAY_SIZE(ctx->supplies), ctx->supplies);
+ return ret;
+ }
+
+ msleep(28);
+
+ ctx->prepared = true;
+
+ return 0;
+}
+
+static int ch13726a_unprepare(struct drm_panel *panel)
+{
+ struct ch13726a_panel *ctx = to_ch13726a_panel(panel);
+
+ if (!ctx->prepared)
+ return 0;
+
+ gpiod_set_value_cansleep(ctx->reset_gpio, 0);
+ regulator_bulk_disable(ARRAY_SIZE(ctx->supplies), ctx->supplies);
+
+ ctx->prepared = false;
+ return 0;
+}
+
+static const struct drm_display_mode rpmini_display_mode = {
+ .clock = (960 + 28 + 4 + 36) * (1280 + 16 + 4 + 8) * 60 / 1000,
+ .hdisplay = 960,
+ .hsync_start = 960 + 28,
+ .hsync_end = 960 + 28 + 4,
+ .htotal = 960 + 28 + 4 + 36,
+ .vdisplay = 1280,
+ .vsync_start = 1280 + 16,
+ .vsync_end = 1280 + 16 + 4,
+ .vtotal = 1280 + 16 + 4 + 8,
+ .width_mm = 65,
+ .height_mm = 75,
+};
+
+static const struct drm_display_mode rp5_display_mode = {
+ .clock = (1080 + 12 + 4 + 12) * (1920 + 12 + 4 + 12) * 60 / 1000,
+ .hdisplay = 1080,
+ .hsync_start = 1080 + 12,
+ .hsync_end = 1080 + 12 + 4,
+ .htotal = 1080 + 12 + 4 + 12,
+ .vdisplay = 1920,
+ .vsync_start = 1920 + 12,
+ .vsync_end = 1920 + 12 + 4,
+ .vtotal = 1920 + 12 + 4 + 12,
+ .width_mm = 68,
+ .height_mm = 121,
+};
+
+static int ch13726a_get_modes(struct drm_panel *panel,
+ struct drm_connector *connector)
+{
+ struct ch13726a_panel *ctx = to_ch13726a_panel(panel);
+ struct drm_display_mode *mode;
+
+ mode = drm_mode_duplicate(connector->dev, ctx->display_mode);
+ if (!mode)
+ return -ENOMEM;
+
+ drm_mode_set_name(mode);
+
+ mode->type = DRM_MODE_TYPE_DRIVER | DRM_MODE_TYPE_PREFERRED;
+ connector->display_info.width_mm = mode->width_mm;
+ connector->display_info.height_mm = mode->height_mm;
+ drm_mode_probed_add(connector, mode);
+
+ return 1;
+}
+
+static enum drm_panel_orientation ch13726a_get_orientation(struct drm_panel *panel)
+{
+ struct ch13726a_panel *ctx = to_ch13726a_panel(panel);
+
+ return ctx->orientation;
+}
+
+static const struct drm_panel_funcs ch13726a_panel_funcs = {
+ .prepare = ch13726a_prepare,
+ .unprepare = ch13726a_unprepare,
+ .disable = ch13726a_disable,
+ .get_modes = ch13726a_get_modes,
+ .get_orientation = ch13726a_get_orientation,
+};
+
+static int ch13726a_bl_update_status(struct backlight_device *bl)
+{
+ struct mipi_dsi_device *dsi = bl_get_data(bl);
+ u16 brightness = backlight_get_brightness(bl);
+ int ret;
+
+ dsi->mode_flags &= ~MIPI_DSI_MODE_LPM;
+
+ ret = mipi_dsi_dcs_set_display_brightness(dsi, brightness);
+ if (ret < 0)
+ return ret;
+
+ dsi->mode_flags |= MIPI_DSI_MODE_LPM;
+
+ return 0;
+}
+
+static const struct backlight_ops ch13726a_bl_ops = {
+ .update_status = ch13726a_bl_update_status,
+};
+
+static struct backlight_device *
+ch13726a_create_backlight(struct mipi_dsi_device *dsi)
+{
+ struct device *dev = &dsi->dev;
+ const struct backlight_properties props = {
+ .type = BACKLIGHT_RAW,
+ .brightness = 255,
+ .max_brightness = 255,
+ };
+
+ return devm_backlight_device_register(dev, dev_name(dev), dev, dsi,
+ &ch13726a_bl_ops, &props);
+}
+
+static int ch13726a_probe(struct mipi_dsi_device *dsi)
+{
+ struct device *dev = &dsi->dev;
+ struct ch13726a_panel *ctx;
+ int rotation;
+ int ret;
+
+ ctx = devm_kzalloc(dev, sizeof(*ctx), GFP_KERNEL);
+ if (!ctx)
+ return -ENOMEM;
+
+ ctx->display_mode = of_device_get_match_data(dev);
+
+ ctx->supplies[0].supply = "vdd1v2";
+ ctx->supplies[1].supply = "vddio";
+ ctx->supplies[2].supply = "vdd";
+ ctx->supplies[3].supply = "avdd";
+
+ ret = devm_regulator_bulk_get(dev, ARRAY_SIZE(ctx->supplies),
+ ctx->supplies);
+ if (ret < 0)
+ return dev_err_probe(dev, ret, "Failed to get regulators\n");
+
+ ctx->reset_gpio = devm_gpiod_get(dev, "reset", GPIOD_OUT_LOW);
+ if (IS_ERR(ctx->reset_gpio))
+ return dev_err_probe(dev, PTR_ERR(ctx->reset_gpio),
+ "Failed to get reset-gpios\n");
+
+ ret = of_property_read_u32(dev->of_node, "rotation", &rotation);
+ if (ret == -EINVAL) {
+ ctx->orientation = DRM_MODE_PANEL_ORIENTATION_UNKNOWN;
+ }
+
+ if (rotation == 0)
+ ctx->orientation = DRM_MODE_PANEL_ORIENTATION_NORMAL;
+ else if (rotation == 90)
+ ctx->orientation = DRM_MODE_PANEL_ORIENTATION_RIGHT_UP;
+ else if (rotation == 180)
+ ctx->orientation = DRM_MODE_PANEL_ORIENTATION_BOTTOM_UP;
+ else if (rotation == 270)
+ ctx->orientation = DRM_MODE_PANEL_ORIENTATION_LEFT_UP;
+
+ ctx->dsi = dsi;
+ mipi_dsi_set_drvdata(dsi, ctx);
+
+ dsi->lanes = 4;
+ dsi->format = MIPI_DSI_FMT_RGB888;
+ dsi->mode_flags = MIPI_DSI_MODE_VIDEO_BURST |
+ MIPI_DSI_CLOCK_NON_CONTINUOUS;
+
+ drm_panel_init(&ctx->panel, dev, &ch13726a_panel_funcs,
+ DRM_MODE_CONNECTOR_DSI);
+ ctx->panel.prepare_prev_first = true;
+
+ ctx->panel.backlight = ch13726a_create_backlight(dsi);
+ if (IS_ERR(ctx->panel.backlight))
+ return dev_err_probe(dev, PTR_ERR(ctx->panel.backlight),
+ "Failed to create backlight\n");
+
+ drm_panel_add(&ctx->panel);
+
+ ret = mipi_dsi_attach(dsi);
+ if (ret < 0) {
+ dev_err(dev, "Failed to attach to DSI host: %d\n", ret);
+ drm_panel_remove(&ctx->panel);
+ return ret;
+ }
+
+ return 0;
+}
+
+static void ch13726a_remove(struct mipi_dsi_device *dsi)
+{
+ struct ch13726a_panel *ctx = mipi_dsi_get_drvdata(dsi);
+ int ret;
+
+ ret = mipi_dsi_detach(dsi);
+ if (ret < 0)
+ dev_err(&dsi->dev, "Failed to detach from DSI host: %d\n", ret);
+
+ drm_panel_remove(&ctx->panel);
+}
+
+static const struct of_device_id ch13726a_of_match[] = {
+ { .compatible = "ch13726a,rpmini", .data = &rpmini_display_mode },
+ { .compatible = "ch13726a,rp5", .data = &rp5_display_mode },
+ { /* sentinel */ }
+};
+MODULE_DEVICE_TABLE(of, ch13726a_of_match);
+
+static struct mipi_dsi_driver ch13726a_driver = {
+ .probe = ch13726a_probe,
+ .remove = ch13726a_remove,
+ .driver = {
+ .name = "panel-ch13726a-amoled",
+ .of_match_table = ch13726a_of_match,
+ },
+};
+module_mipi_dsi_driver(ch13726a_driver);
+
+MODULE_DESCRIPTION("DRM driver for CH13726A DSI panels");
+MODULE_LICENSE("GPL");
--
Armbian

View File

@ -0,0 +1,352 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Teguh Sobirin <teguh@sobir.in>
Date: Thu, 21 Nov 2024 00:16:42 +0700
Subject: leds: Add driver for HEROIC HTR3212 Signed-off-by: Teguh Sobirin
<teguh@sobir.in>
---
drivers/leds/Kconfig | 10 +
drivers/leds/Makefile | 1 +
drivers/leds/leds-htr3212.c | 298 ++++++++++
3 files changed, 309 insertions(+)
diff --git a/drivers/leds/Kconfig b/drivers/leds/Kconfig
index 111111111111..222222222222 100644
--- a/drivers/leds/Kconfig
+++ b/drivers/leds/Kconfig
@@ -211,6 +211,16 @@ config LEDS_EXPRESSWIRE
bool
depends on GPIOLIB
+config LEDS_HTR3212
+ tristate "HEROIC HTR3212 LED driver"
+ depends on LEDS_CLASS && I2C
+ select REGMAP_I2C
+ help
+ Driver for HEROIC HTR3212 LED controller.
+
+ To compile this driver as a module, choose M here: the module
+ will be called leds-htr3212.
+
config LEDS_TURRIS_OMNIA
tristate "LED support for CZ.NIC's Turris Omnia"
depends on LEDS_CLASS_MULTICOLOR
diff --git a/drivers/leds/Makefile b/drivers/leds/Makefile
index 111111111111..222222222222 100644
--- a/drivers/leds/Makefile
+++ b/drivers/leds/Makefile
@@ -32,6 +32,7 @@ obj-$(CONFIG_LEDS_DA9052) += leds-da9052.o
obj-$(CONFIG_LEDS_GPIO) += leds-gpio.o
obj-$(CONFIG_LEDS_GPIO_REGISTER) += leds-gpio-register.o
obj-$(CONFIG_LEDS_HP6XX) += leds-hp6xx.o
+obj-$(CONFIG_LEDS_HTR3212) += leds-htr3212.o
obj-$(CONFIG_LEDS_INTEL_SS4200) += leds-ss4200.o
obj-$(CONFIG_LEDS_IP30) += leds-ip30.o
obj-$(CONFIG_LEDS_IPAQ_MICRO) += leds-ipaq-micro.o
diff --git a/drivers/leds/leds-htr3212.c b/drivers/leds/leds-htr3212.c
new file mode 100644
index 000000000000..111111111111
--- /dev/null
+++ b/drivers/leds/leds-htr3212.c
@@ -0,0 +1,298 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * Driver for HEROIC HTR3212 12-channel 8-bit PWM LED controller
+ *
+ * Copyright (c) 2024 Teguh Sobirin <teguh@sobir.in>
+ *
+ */
+
+#include <linux/delay.h>
+#include <linux/device.h>
+#include <linux/gpio/consumer.h>
+#include <linux/i2c.h>
+#include <linux/kernel.h>
+#include <linux/leds.h>
+#include <linux/module.h>
+#include <linux/of.h>
+
+#define HTR3212_CHANNELS 12
+#define HTR3212_ENABLE_BIT 1
+#define HTR3212_SHUTDOWN 0x00
+#define HTR3212_PWM_REGISTER_BASE 0x0d
+#define HTR3212_PWM_UPDATE 0x25
+#define HTR3212_LED_CONTROL_BASE 0x32
+#define HTR3212_GLOBAL_CONTROL 0x4a
+#define HTR3212_OUTPUT_FREQ 0x4b
+#define HTR3212_RESET 0x4f
+
+struct htr3212_priv;
+
+struct htr3212_led_data {
+ struct led_classdev cdev;
+ struct htr3212_priv *priv;
+ u8 channel;
+};
+
+struct htr3212_priv {
+ struct i2c_client *client;
+ unsigned int num_leds;
+ struct gpio_desc *sdb;
+ struct regulator *vdd;
+ struct htr3212_led_data leds[];
+};
+
+static int htr3212_write(struct htr3212_priv *priv, u8 reg, u8 val)
+{
+ int ret;
+
+ dev_dbg(&priv->client->dev, "writing register 0x%02X=0x%02X", reg, val);
+
+ ret = i2c_smbus_write_byte_data(priv->client, reg, val);
+ if (ret) {
+ dev_err(&priv->client->dev,
+ "register write to 0x%02X failed (error %d)",
+ reg, ret);
+ }
+ return ret;
+}
+
+static int htr3212_brightness_set(struct led_classdev *led_cdev,
+ enum led_brightness brightness)
+{
+ const struct htr3212_led_data *led_data =
+ container_of(led_cdev, struct htr3212_led_data, cdev);
+ u8 pwm_register_offset;
+ int ret;
+
+ dev_dbg(led_cdev->dev, "%s: %d\n", __func__, brightness);
+
+ pwm_register_offset = led_data->channel - 1;
+
+ ret = htr3212_write(led_data->priv,
+ HTR3212_PWM_REGISTER_BASE + pwm_register_offset,
+ brightness);
+ if (ret)
+ return ret;
+
+ return htr3212_write(led_data->priv, HTR3212_PWM_UPDATE, 0x00);
+}
+
+static int htr3212_reset_regs(struct htr3212_priv *priv)
+{
+ int ret;
+
+ ret = htr3212_write(priv, HTR3212_RESET, 0x00);
+ if (ret)
+ return ret;
+
+ return 0;
+}
+
+static int htr3212_init_regs(struct htr3212_priv *priv)
+{
+ int ret;
+
+ ret = htr3212_reset_regs(priv);
+ if (ret)
+ return ret;
+
+ u8 value = GENMASK(HTR3212_ENABLE_BIT, 0);
+ u8 num_regs = HTR3212_CHANNELS / HTR3212_ENABLE_BIT;
+
+ int i;
+
+ for (i = 0; i < num_regs; i++) {
+ ret = htr3212_write(priv,
+ HTR3212_LED_CONTROL_BASE + i, value);
+ if (ret)
+ return ret;
+ }
+
+ ret = htr3212_write(priv, HTR3212_SHUTDOWN, 0x01);
+ if (ret)
+ return ret;
+
+ ret = htr3212_write(priv, HTR3212_OUTPUT_FREQ, 0x01);
+ if (ret)
+ return ret;
+
+ ret = htr3212_write(priv, HTR3212_GLOBAL_CONTROL, 0x00);
+ if (ret)
+ return ret;
+
+ return 0;
+}
+
+static int htr3212_parse_child_dt(const struct device *dev,
+ const struct device_node *child,
+ struct htr3212_led_data *led_data)
+{
+ struct led_classdev *cdev = &led_data->cdev;
+ int ret = 0;
+ u32 reg;
+
+ ret = of_property_read_u32(child, "reg", &reg);
+ if (ret || reg < 1 || reg > HTR3212_CHANNELS) {
+ dev_err(dev,
+ "Child node %pOF does not have a valid reg property\n",
+ child);
+ return -EINVAL;
+ }
+ led_data->channel = reg;
+
+ cdev->brightness_set_blocking = htr3212_brightness_set;
+
+ if (!device_property_read_bool(dev, "always-on"))
+ cdev->flags |= LED_CORE_SUSPENDRESUME;
+
+ return 0;
+}
+
+static struct htr3212_led_data *htr3212_find_led_data(
+ struct htr3212_priv *priv,
+ u8 channel)
+{
+ size_t i;
+
+ for (i = 0; i < priv->num_leds; i++) {
+ if (priv->leds[i].channel == channel)
+ return &priv->leds[i];
+ }
+
+ return NULL;
+}
+
+static int htr3212_parse_dt(struct device *dev,
+ struct htr3212_priv *priv)
+{
+ int ret = 0;
+
+ for_each_available_child_of_node_scoped(dev_of_node(dev), child) {
+ struct led_init_data init_data = {};
+ struct htr3212_led_data *led_data =
+ &priv->leds[priv->num_leds];
+ const struct htr3212_led_data *other_led_data;
+
+ led_data->priv = priv;
+
+ ret = htr3212_parse_child_dt(dev, child, led_data);
+ if (ret)
+ return ret;
+
+ other_led_data = htr3212_find_led_data(priv,
+ led_data->channel);
+ if (other_led_data) {
+ dev_err(dev,
+ "Node %pOF 'reg' conflicts with another LED\n",
+ child);
+ return -EINVAL;
+ }
+
+ init_data.fwnode = of_fwnode_handle(child);
+
+ ret = devm_led_classdev_register_ext(dev, &led_data->cdev,
+ &init_data);
+ if (ret) {
+ dev_err(dev, "Failed to register LED for %pOF: %d\n",
+ child, ret);
+ return ret;
+ }
+
+ priv->num_leds++;
+ }
+
+ return 0;
+}
+
+static const struct of_device_id of_htr3212_match[] = {
+ { .compatible = "heroic,htr3212", },
+ { /* sentinel */ }
+};
+
+MODULE_DEVICE_TABLE(of, of_htr3212_match);
+
+static int htr3212_probe(struct i2c_client *client)
+{
+ struct device *dev = &client->dev;
+ struct htr3212_priv *priv;
+ int count;
+ int ret = 0;
+
+ count = of_get_available_child_count(dev_of_node(dev));
+ if (!count)
+ return -EINVAL;
+
+ priv = devm_kzalloc(dev, struct_size(priv, leds, count),
+ GFP_KERNEL);
+ if (!priv)
+ return -ENOMEM;
+
+ priv->sdb = devm_gpiod_get(dev, "sdb", GPIOD_OUT_HIGH);
+ if (PTR_ERR(priv->sdb) == -EPROBE_DEFER)
+ return -EPROBE_DEFER;
+
+ priv->vdd = devm_regulator_get(dev, "vdd");
+ if (IS_ERR(priv->vdd)) {
+ ret = PTR_ERR(priv->vdd);
+ return ret;
+ }
+
+ ret = regulator_enable(priv->vdd);
+ if (ret < 0) {
+ return ret;
+ }
+
+ gpiod_set_value_cansleep(priv->sdb, 1);
+ usleep_range(10000, 11000);
+
+ priv->client = client;
+ i2c_set_clientdata(client, priv);
+
+ ret = htr3212_init_regs(priv);
+ if (ret)
+ return ret;
+
+ ret = htr3212_parse_dt(dev, priv);
+ if (ret)
+ return ret;
+
+ return 0;
+}
+
+static void htr3212_remove(struct i2c_client *client)
+{
+ struct htr3212_priv *priv = i2c_get_clientdata(client);
+ int ret;
+
+ ret = htr3212_reset_regs(priv);
+ if (ret)
+ dev_err(&client->dev, "Failed to reset registers on removal (%pe)\n",
+ ERR_PTR(ret));
+
+ gpiod_set_value_cansleep(priv->sdb, 0);
+
+ regulator_disable(priv->vdd);
+}
+
+static const struct i2c_device_id htr3212_id[] = {
+ { "htr3212" },
+ {},
+};
+
+MODULE_DEVICE_TABLE(i2c, htr3212_id);
+
+static struct i2c_driver htr3212_driver = {
+ .driver = {
+ .name = "htr3212",
+ .of_match_table = of_htr3212_match,
+ },
+ .probe = htr3212_probe,
+ .remove = htr3212_remove,
+ .id_table = htr3212_id,
+};
+
+module_i2c_driver(htr3212_driver);
+
+MODULE_AUTHOR("Teguh Sobirin <teguh@sobir.in");
+MODULE_DESCRIPTION("HEROIC HTR3212 LED Driver");
+MODULE_LICENSE("GPL v2");
--
Armbian

View File

@ -0,0 +1,362 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Teguh Sobirin <teguh@sobir.in>
Date: Wed, 20 Nov 2024 23:13:18 +0700
Subject: Input: driver for AYN Odin2 Gamepad
There have been improvements from the original Odin 2 Gamepad driver
Signed-off-by: Teguh Sobirin <teguh@sobir.in>
---
drivers/input/joystick/Kconfig | 4 +
drivers/input/joystick/Makefile | 1 +
drivers/input/joystick/odin2.c | 313 ++++++++++
3 files changed, 318 insertions(+)
diff --git a/drivers/input/joystick/Kconfig b/drivers/input/joystick/Kconfig
index 111111111111..222222222222 100644
--- a/drivers/input/joystick/Kconfig
+++ b/drivers/input/joystick/Kconfig
@@ -344,6 +344,10 @@ config JOYSTICK_MAPLE
To compile this as a module choose M here: the module will be called
maplecontrol.
+config JOYSTICK_ODIN2
+ tristate "AYN Odin2 gamepad"
+ depends on SERIAL_DEV_BUS
+
config JOYSTICK_PSXPAD_SPI
tristate "PlayStation 1/2 joypads via SPI interface"
depends on SPI
diff --git a/drivers/input/joystick/Makefile b/drivers/input/joystick/Makefile
index 111111111111..222222222222 100644
--- a/drivers/input/joystick/Makefile
+++ b/drivers/input/joystick/Makefile
@@ -25,6 +25,7 @@ obj-$(CONFIG_JOYSTICK_JOYDUMP) += joydump.o
obj-$(CONFIG_JOYSTICK_MAGELLAN) += magellan.o
obj-$(CONFIG_JOYSTICK_MAPLE) += maplecontrol.o
obj-$(CONFIG_JOYSTICK_N64) += n64joy.o
+obj-$(CONFIG_JOYSTICK_ODIN2) += odin2.o
obj-$(CONFIG_JOYSTICK_PSXPAD_SPI) += psxpad-spi.o
obj-$(CONFIG_JOYSTICK_PXRC) += pxrc.o
obj-$(CONFIG_JOYSTICK_QWIIC) += qwiic-joystick.o
diff --git a/drivers/input/joystick/odin2.c b/drivers/input/joystick/odin2.c
new file mode 100644
index 000000000000..111111111111
--- /dev/null
+++ b/drivers/input/joystick/odin2.c
@@ -0,0 +1,313 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * Driver for Ayn Odin 2 Gamepad
+ *
+ * Copyright (C) 2024 Molly Sophia <mollysophia379@gmail.com>
+ * Copyright (C) 2024 BigfootACA <bigfoot@classfun.cn>
+ * Copyright (C) 2024 Teguh Sobirin <teguh@sobir.in>
+ *
+ */
+
+#include <linux/delay.h>
+#include <linux/errno.h>
+#include <linux/gpio/consumer.h>
+#include <linux/init.h>
+#include <linux/input.h>
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/of.h>
+#include <linux/serdev.h>
+#include <linux/slab.h>
+#include <uapi/linux/sched/types.h>
+
+#define DRIVER_NAME "odin2-gamepad"
+#define MAX_DATA_LEN 64
+
+#define gamepad_serdev_write_seq(serdev, seq...) \
+ do { \
+ static const u8 d[] = { seq }; \
+ struct device *dev = &serdev->dev; \
+ int ret; \
+ ret = serdev_device_write_buf(serdev, d, ARRAY_SIZE(d)); \
+ if (ret < 0 || ret < ARRAY_SIZE(d)) { \
+ dev_warn_ratelimited(dev, "Unable to write data: %d", \
+ ret); \
+ return; \
+ } \
+ } while (0)
+
+static const unsigned int keymap[] = {
+ BTN_DPAD_UP, BTN_DPAD_DOWN, BTN_DPAD_LEFT, BTN_DPAD_RIGHT,
+ BTN_NORTH, BTN_WEST, BTN_EAST, BTN_SOUTH,
+ BTN_TL, BTN_TR, BTN_SELECT, BTN_START,
+ BTN_THUMBL, BTN_THUMBR, BTN_MODE, BTN_BACK
+};
+
+struct gamepad_data {
+ u8 header[4];
+ u8 frame_number;
+ u8 command;
+ u16 data_len;
+ u8 data[MAX_DATA_LEN];
+};
+
+struct gamepad_device {
+ struct device *dev;
+ struct gpio_desc *boot_gpio;
+ struct gpio_desc *enable_gpio;
+ struct gpio_desc *reset_gpio;
+ struct input_dev *dev_input;
+};
+
+static u8 gamepad_data_checksum(const u8 *data, size_t count)
+{
+ const u8 *ptr = data;
+ u8 ret = data[4];
+
+ for (int i = 5; i < count - 1; i++)
+ ret ^= ptr[i];
+
+ return ret;
+}
+
+static void gamepad_send_init_sequence(struct serdev_device *serdev)
+{
+ gamepad_serdev_write_seq(serdev, 0xA5, 0xD3, 0x5A, 0x3D, 0x0, 0x1, 0x2,
+ 0x0, 0x7, 0x1, 0x5);
+ msleep(100);
+ gamepad_serdev_write_seq(serdev, 0xA5, 0xD3, 0x5A, 0x3D, 0x1, 0x1, 0x1,
+ 0x0, 0x6, 0x7);
+ msleep(100);
+ gamepad_serdev_write_seq(serdev, 0xA5, 0xD3, 0x5A, 0x3D, 0x2, 0x1, 0x1, 0x0, 0x2, 0x0);
+ msleep(100);
+ gamepad_serdev_write_seq(serdev, 0xa5, 0xd3, 0x5a, 0x3d, 0x3, 0x01,
+ 0x0a, 0x00, 0x05, 0x01, 0x00, 0x00, 0x00, 0x28,
+ 0x00, 0x00, 0x00, 0x07, 0x23);
+ msleep(100);
+ gamepad_serdev_write_seq(serdev, 0xA5, 0xD3, 0x5A, 0x3D, 0x4, 0x1, 0x1,
+ 0x0, 0x6, 0x2);
+ msleep(100);
+ gamepad_serdev_write_seq(serdev, 0xA5, 0xD3, 0x5A, 0x3D, 0x5, 0x1, 0x1,
+ 0x0, 0x2, 0x7);
+ msleep(100);
+}
+
+static void gamepad_input_handler(struct gamepad_device *dev,
+ struct gamepad_data *data)
+{
+ static unsigned long prev_states;
+ unsigned long keys = data->data[0] | (data->data[1] << 8);
+ unsigned long current_states = keys, changes;
+ int i;
+ struct input_dev *indev;
+
+ indev = dev->dev_input;
+ if (!indev)
+ return;
+
+ bitmap_xor(&changes, &current_states, &prev_states, ARRAY_SIZE(keymap));
+
+ for_each_set_bit(i, &changes, ARRAY_SIZE(keymap)) {
+ input_report_key(indev, keymap[i], (current_states & BIT(i)));
+ }
+
+ input_report_abs(indev, ABS_HAT2X,
+ 0x755 - (data->data[2] | (data->data[3] << 8)));
+ input_report_abs(indev, ABS_HAT2Y,
+ 0x755 - (data->data[4] | (data->data[5] << 8)));
+ input_report_abs(indev, ABS_X,
+ -(int16_t)(data->data[6] | (data->data[7] << 8)));
+ input_report_abs(indev, ABS_Y,
+ -(int16_t)(data->data[8] | (data->data[9] << 8)));
+ input_report_abs(indev, ABS_RX,
+ -(int16_t)(data->data[10] | (data->data[11] << 8)));
+ input_report_abs(indev, ABS_RY,
+ -(int16_t)(data->data[12] | (data->data[13] << 8)));
+
+ input_sync(indev);
+ prev_states = keys;
+}
+
+static void gamepad_data_handler(struct serdev_device *serdev,
+ struct gamepad_data *data)
+{
+ struct gamepad_device *dev = serdev_device_get_drvdata(serdev);
+
+ switch (data->command) {
+ case 0x2:
+ gamepad_input_handler(dev, data);
+ break;
+ default:
+ break;
+ }
+}
+
+static size_t gamepad_mcu_uart_rx_bytes(struct serdev_device *serdev,
+ const u8 *data, size_t count)
+{
+ struct device *dev = &serdev->dev;
+ struct gamepad_data recv_data_buffer;
+ u8 checksum;
+
+ if (!data || count < 7) {
+ dev_warn_ratelimited(dev, "invalid packet");
+ return count;
+ }
+
+ checksum = gamepad_data_checksum(data, count);
+ if (checksum != *(data + count - 1)) {
+ dev_warn_ratelimited(dev, "packet checksum failed");
+ return count;
+ }
+
+ memcpy(recv_data_buffer.header, data, 4);
+ recv_data_buffer.frame_number = *(data + 4);
+ recv_data_buffer.command = *(data + 5);
+ recv_data_buffer.data_len = *(data + 6) | (*(data + 7) << 8);
+
+ if (recv_data_buffer.data_len) {
+ memset(&recv_data_buffer.data[0], 0,
+ sizeof(recv_data_buffer.data));
+ memcpy(&recv_data_buffer.data[0], data + 8,
+ recv_data_buffer.data_len);
+ }
+
+ gamepad_data_handler(serdev, &recv_data_buffer);
+
+ return count;
+}
+
+static const struct serdev_device_ops gamepad_mcu_uart_client_ops = {
+ .receive_buf = gamepad_mcu_uart_rx_bytes,
+};
+
+static int gamepad_mcu_uart_probe(struct serdev_device *serdev)
+{
+ struct device *dev = &serdev->dev;
+ struct gamepad_device *gamepad_dev;
+ u32 gamepad_bus = 0;
+ u32 gamepad_vid = 0;
+ u32 gamepad_pid = 0;
+ u32 gamepad_rev = 0;
+ int ret;
+
+ gamepad_dev = devm_kzalloc(dev, sizeof(*gamepad_dev), GFP_KERNEL);
+ if (!gamepad_dev)
+ return dev_err_probe(dev, -ENOMEM, "could not allocate memory for device data\n");
+
+ gamepad_dev->boot_gpio =
+ devm_gpiod_get_optional(dev, "boot", GPIOD_OUT_HIGH);
+ if (IS_ERR(gamepad_dev->boot_gpio)) {
+ ret = PTR_ERR(gamepad_dev->boot_gpio);
+ dev_warn(dev, "Unable to get boot gpio: %d\n", ret);
+ }
+
+ gamepad_dev->enable_gpio =
+ devm_gpiod_get_optional(dev, "enable", GPIOD_OUT_HIGH);
+ if (IS_ERR(gamepad_dev->enable_gpio)) {
+ ret = PTR_ERR(gamepad_dev->enable_gpio);
+ dev_warn(dev, "Unable to get enable gpio: %d\n", ret);
+ }
+
+ gamepad_dev->reset_gpio =
+ devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_HIGH);
+ if (IS_ERR(gamepad_dev->reset_gpio)) {
+ ret = PTR_ERR(gamepad_dev->reset_gpio);
+ dev_warn(dev, "Unable to get reset gpio: %d\n", ret);
+ }
+
+ if (gamepad_dev->boot_gpio)
+ gpiod_set_value_cansleep(gamepad_dev->boot_gpio, 0);
+
+ if (gamepad_dev->reset_gpio)
+ gpiod_set_value_cansleep(gamepad_dev->reset_gpio, 0);
+
+ msleep(100);
+
+ if (gamepad_dev->enable_gpio)
+ gpiod_set_value_cansleep(gamepad_dev->enable_gpio, 1);
+
+ if (gamepad_dev->reset_gpio)
+ gpiod_set_value_cansleep(gamepad_dev->reset_gpio, 1);
+
+ msleep(100);
+
+ ret = devm_serdev_device_open(dev, serdev);
+ if (ret)
+ return dev_err_probe(dev, ret, "Unable to open UART device\n");
+ gamepad_dev->dev = dev;
+
+ serdev_device_set_drvdata(serdev, gamepad_dev);
+
+ ret = serdev_device_set_baudrate(serdev, 115200);
+ if (ret < 0)
+ return dev_err_probe(dev, ret, "Failed to set up host baud rate\n");
+
+ serdev_device_set_flow_control(serdev, false);
+
+ gamepad_dev->dev_input = devm_input_allocate_device(dev);
+ if (!gamepad_dev->dev_input)
+ return dev_err_probe(dev, -ENOMEM, "Not enough memory for input device\n");
+
+ gamepad_dev->dev_input->phys = DRIVER_NAME"/input0";
+
+ ret = device_property_read_string(dev, "gamepad-name", &gamepad_dev->dev_input->name);
+ if (ret) {
+ gamepad_dev->dev_input->name = "Ayn Odin2 Gamepad";
+ }
+
+ device_property_read_u32(dev, "gamepad-bus", &gamepad_bus);
+ device_property_read_u32(dev, "gamepad-vid", &gamepad_vid);
+ device_property_read_u32(dev, "gamepad-pid", &gamepad_pid);
+ device_property_read_u32(dev, "gamepad-rev", &gamepad_rev);
+
+ gamepad_dev->dev_input->id.bustype = (u16)gamepad_bus;
+ gamepad_dev->dev_input->id.vendor = (u16)gamepad_vid;
+ gamepad_dev->dev_input->id.product = (u16)gamepad_pid;
+ gamepad_dev->dev_input->id.version = (u16)gamepad_rev;
+
+ __set_bit(EV_KEY, gamepad_dev->dev_input->evbit);
+ for (int i = 0; i < ARRAY_SIZE(keymap); i++)
+ input_set_capability(gamepad_dev->dev_input, EV_KEY, keymap[i]);
+
+ __set_bit(EV_ABS, gamepad_dev->dev_input->evbit);
+ for (int i = ABS_X; i <= ABS_RZ; i++)
+ input_set_abs_params(gamepad_dev->dev_input, i, -0x580, 0x580,
+ 0, 0);
+
+ input_set_abs_params(gamepad_dev->dev_input, ABS_HAT2X, 0, 1830, 0, 30);
+ input_set_abs_params(gamepad_dev->dev_input, ABS_HAT2Y, 0, 1830, 0, 30);
+
+ ret = input_register_device(gamepad_dev->dev_input);
+ if (ret)
+ return dev_err_probe(dev, ret, "Could not register input device\n");
+
+ serdev_device_set_client_ops(serdev, &gamepad_mcu_uart_client_ops);
+
+ gamepad_send_init_sequence(serdev);
+
+ return 0;
+}
+
+static const struct of_device_id gamepad_mcu_uart_of_match[] = {
+ { .compatible = "ayn,odin2-gamepad" },
+ {}
+};
+MODULE_DEVICE_TABLE(of, gamepad_mcu_uart_of_match);
+
+static struct serdev_device_driver gamepad_mcu_uart_driver = {
+ .driver = {
+ .name = DRIVER_NAME,
+ .of_match_table = gamepad_mcu_uart_of_match,
+ },
+ .probe = gamepad_mcu_uart_probe,
+};
+
+module_serdev_device_driver(gamepad_mcu_uart_driver);
+
+MODULE_LICENSE("GPL");
+MODULE_DESCRIPTION("Gamepad driver for Ayn Odin2");
+MODULE_AUTHOR("Molly Sophia <mollysophia379@gmail.com>");
+MODULE_AUTHOR("BigfootACA <bigfoot@classfun.cn>");
+MODULE_AUTHOR("Teguh Sobirin <teguh@sobir.in>");
+MODULE_ALIAS("platform:" DRIVER_NAME);
--
Armbian

View File

@ -0,0 +1,47 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Teguh Sobirin <teguh@sobir.in>
Date: Mon, 25 Nov 2024 02:17:47 +0700
Subject: arm64: dts: qcom: pm8150b: introduce spmi haptics
Add bindings for Qualcomm SPMI haptics on platforms using pm8150b.
Signed-off-by: Teguh Sobirin <teguh@sobir.in>
---
arch/arm64/boot/dts/qcom/pm8150b.dtsi | 16 ++++++++++
1 file changed, 16 insertions(+)
diff --git a/arch/arm64/boot/dts/qcom/pm8150b.dtsi b/arch/arm64/boot/dts/qcom/pm8150b.dtsi
index 111111111111..222222222222 100644
--- a/arch/arm64/boot/dts/qcom/pm8150b.dtsi
+++ b/arch/arm64/boot/dts/qcom/pm8150b.dtsi
@@ -5,6 +5,7 @@
*/
#include <dt-bindings/iio/qcom,spmi-vadc.h>
+#include <dt-bindings/input/qcom,spmi-haptics.h>
#include <dt-bindings/interrupt-controller/irq.h>
#include <dt-bindings/spmi/spmi.h>
@@ -216,5 +217,20 @@ pm8150b_lpg: pwm {
status = "disabled";
};
+
+ pm8150b_haptics: haptics@c000 {
+ compatible = "qcom,pmi8998-haptics", "qcom,spmi-haptics";
+ reg = <0xc000>;
+
+ interrupts = <0x3 0xc0 0x0 IRQ_TYPE_EDGE_BOTH>,
+ <0x3 0xc0 0x1 IRQ_TYPE_EDGE_BOTH>;
+ interrupt-names = "short", "play";
+
+ qcom,wave-shape = <HAP_WAVE_SINE>;
+ qcom,play-mode = <HAP_PLAY_BUFFER>;
+ qcom,brake-pattern = <0x3 0x3 0x2 0x1>;
+
+ status = "disabled";
+ };
};
};
--
Armbian