From nobody Fri Oct 3 23:08:16 2025 Received: from smtpout-02.galae.net (smtpout-02.galae.net [185.246.84.56]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E651F2DCF64 for ; Sun, 24 Aug 2025 11:58:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.246.84.56 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756036712; cv=none; b=bAtlK85QBZ4q2b3hzB2C6NXxlF1jUvLUI1nQOK7WQj1DWuAqLQEuP1MmpcibAmUCcab5v6AdR+fEei6co4ZYL/+p3KLH1MGCVPx3GMrj1V5TuYqJ+A73i/DgZHbMHDILXUTgHa8XH6Q4M3qM05LaY7rs3exAiaJmOcd/9tELoZc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756036712; c=relaxed/simple; bh=BO0UHDtr7pSNWhL5eLvAfXpLX1izwh+f5++BPpnTsAQ=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=o+c/Mlc6kWiLTWVgWdFqLtcuZIIMUr7eBVtqV6xdJXZ+hxttCYh3EGZhbIOY+V0U6+W8U/2mg6sJEt9D0adbZSR/KU4Swh4DgzaJJ5YUSUM0nzrDz26gw08L4GNyQA0zZ9nkk/X15q2i0oZSNq+ZTaqxCyeUHCglM9sZmGclyKc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com; spf=pass smtp.mailfrom=bootlin.com; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b=SyStqqpw; arc=none smtp.client-ip=185.246.84.56 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bootlin.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b="SyStqqpw" Received: from smtpout-01.galae.net (smtpout-01.galae.net [212.83.139.233]) by smtpout-02.galae.net (Postfix) with ESMTPS id 76B501A0DA4; Sun, 24 Aug 2025 11:58:27 +0000 (UTC) Received: from mail.galae.net (mail.galae.net [212.83.136.155]) by smtpout-01.galae.net (Postfix) with ESMTPS id 50376605F1; Sun, 24 Aug 2025 11:58:27 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id 67CBF1C22AB0F; Sun, 24 Aug 2025 13:58:23 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=dkim; t=1756036706; h=from:subject:date:message-id:to:cc:mime-version:content-type: content-transfer-encoding:in-reply-to:references; bh=0HLUha8z27dTrKx5/1HKwWyi33BxVl7LpPldqBPQcRY=; b=SyStqqpwwi9OIV78Esi2SQtX6Vgtbqjv3JRn97IzheZltYViJC8/1dC7+4gdng6LZymH/V IRfx7BCpe9pME4uKMUzBaF9FbePKZMjHjFEi/IfMuhQ298ygydhd5Z/1rpfsoI+sYn3jWv Om1NHBJZoDgWkleoP2Le8U60nwsU/FsjU8IHRxl3xp4UQd8YQkDcisGRxTlqJxWs9EVcoB SPVsnWR+GNvLJLB1uGclA+X7dQ9EYWe9bcDVSnjIY8haDdFMj/D/edQLY40vRdqQl9EIz6 IJX85JjTy7o4y9WDeGrlIwUZpuJk6Be+8AtgOx/TzpqM1488Ai/RJf7E4mFswA== From: Mathieu Dubois-Briand Date: Sun, 24 Aug 2025 13:57:28 +0200 Subject: [PATCH v14 09/10] input: misc: Add support for MAX7360 rotary Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250824-mdb-max7360-support-v14-9-435cfda2b1ea@bootlin.com> References: <20250824-mdb-max7360-support-v14-0-435cfda2b1ea@bootlin.com> In-Reply-To: <20250824-mdb-max7360-support-v14-0-435cfda2b1ea@bootlin.com> To: Lee Jones , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Kamel Bouhara , Linus Walleij , Bartosz Golaszewski , Dmitry Torokhov , =?utf-8?q?Uwe_Kleine-K=C3=B6nig?= , Michael Walle , Mark Brown , Greg Kroah-Hartman , "Rafael J. Wysocki" , Danilo Krummrich Cc: devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-gpio@vger.kernel.org, linux-input@vger.kernel.org, linux-pwm@vger.kernel.org, andriy.shevchenko@intel.com, =?utf-8?q?Gr=C3=A9gory_Clement?= , Thomas Petazzoni , Mathieu Dubois-Briand X-Mailer: b4 0.14.1 X-Developer-Signature: v=1; a=ed25519-sha256; t=1756036647; l=7729; i=mathieu.dubois-briand@bootlin.com; s=20241219; h=from:subject:message-id; bh=BO0UHDtr7pSNWhL5eLvAfXpLX1izwh+f5++BPpnTsAQ=; b=hKz7/tI+/XmbFORfcm+zBzS5VnI2UNjS9c5wFnCaUTAtJvB4TyXKcoJqoDuj36yT8L/NRnMze 9coqQlbbz/XAfQZG4Dlg3TPX7JhcT5GH4VOhQRAbJgQlycMcXmpVI6+ X-Developer-Key: i=mathieu.dubois-briand@bootlin.com; a=ed25519; pk=1PVTmzPXfKvDwcPUzG0aqdGoKZJA3b9s+3DqRlm0Lww= X-Last-TLS-Session-Version: TLSv1.3 Add driver for Maxim Integrated MAX7360 rotary encoder controller, supporting a single rotary switch. Acked-by: Dmitry Torokhov Signed-off-by: Mathieu Dubois-Briand --- drivers/input/misc/Kconfig | 10 ++ drivers/input/misc/Makefile | 1 + drivers/input/misc/max7360-rotary.c | 192 ++++++++++++++++++++++++++++++++= ++++ 3 files changed, 203 insertions(+) diff --git a/drivers/input/misc/Kconfig b/drivers/input/misc/Kconfig index 0fb21c99a5e3..d604aad90a89 100644 --- a/drivers/input/misc/Kconfig +++ b/drivers/input/misc/Kconfig @@ -230,6 +230,16 @@ config INPUT_M68K_BEEP tristate "M68k Beeper support" depends on M68K =20 +config INPUT_MAX7360_ROTARY + tristate "Maxim MAX7360 Rotary Encoder" + depends on MFD_MAX7360 + help + If you say yes here you get support for the rotary encoder on the + Maxim MAX7360 I/O Expander. + + To compile this driver as a module, choose M here: the module will be + called max7360_rotary. + config INPUT_MAX77650_ONKEY tristate "Maxim MAX77650 ONKEY support" depends on MFD_MAX77650 diff --git a/drivers/input/misc/Makefile b/drivers/input/misc/Makefile index d468c8140b93..ac45cb9b5c99 100644 --- a/drivers/input/misc/Makefile +++ b/drivers/input/misc/Makefile @@ -51,6 +51,7 @@ obj-$(CONFIG_INPUT_IQS7222) +=3D iqs7222.o obj-$(CONFIG_INPUT_KEYSPAN_REMOTE) +=3D keyspan_remote.o obj-$(CONFIG_INPUT_KXTJ9) +=3D kxtj9.o obj-$(CONFIG_INPUT_M68K_BEEP) +=3D m68kspkr.o +obj-$(CONFIG_INPUT_MAX7360_ROTARY) +=3D max7360-rotary.o obj-$(CONFIG_INPUT_MAX77650_ONKEY) +=3D max77650-onkey.o obj-$(CONFIG_INPUT_MAX77693_HAPTIC) +=3D max77693-haptic.o obj-$(CONFIG_INPUT_MAX8925_ONKEY) +=3D max8925_onkey.o diff --git a/drivers/input/misc/max7360-rotary.c b/drivers/input/misc/max73= 60-rotary.c new file mode 100644 index 000000000000..385831ef34b6 --- /dev/null +++ b/drivers/input/misc/max7360-rotary.c @@ -0,0 +1,192 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * Copyright 2025 Bootlin + * + * Author: Mathieu Dubois-Briand + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define MAX7360_ROTARY_DEFAULT_STEPS 24 + +struct max7360_rotary { + struct input_dev *input; + struct regmap *regmap; + unsigned int debounce_ms; + + unsigned int pos; + + u32 steps; + u32 axis; + bool relative_axis; + bool rollover; +}; + +static void max7360_rotary_report_event(struct max7360_rotary *max7360_rot= ary, int steps) +{ + if (max7360_rotary->relative_axis) { + input_report_rel(max7360_rotary->input, max7360_rotary->axis, steps); + } else { + int pos =3D max7360_rotary->pos; + int maxval =3D max7360_rotary->steps; + + /* + * Add steps to the position. + * Make sure added steps are always in ]-maxval; maxval[ + * interval, so (pos + maxval) is always >=3D 0. + * Then set back pos to the [0; maxval[ interval. + */ + pos +=3D steps % maxval; + if (max7360_rotary->rollover) + pos =3D (pos + maxval) % maxval; + else + pos =3D clamp(pos, 0, maxval - 1); + + max7360_rotary->pos =3D pos; + input_report_abs(max7360_rotary->input, max7360_rotary->axis, max7360_ro= tary->pos); + } + + input_sync(max7360_rotary->input); +} + +static irqreturn_t max7360_rotary_irq(int irq, void *data) +{ + struct max7360_rotary *max7360_rotary =3D data; + struct device *dev =3D max7360_rotary->input->dev.parent; + unsigned int val; + int error; + + error =3D regmap_read(max7360_rotary->regmap, MAX7360_REG_RTR_CNT, &val); + if (error < 0) { + dev_err(dev, "Failed to read rotary counter\n"); + return IRQ_NONE; + } + + if (val =3D=3D 0) + return IRQ_NONE; + + max7360_rotary_report_event(max7360_rotary, sign_extend32(val, 7)); + + return IRQ_HANDLED; +} + +static int max7360_rotary_hw_init(struct max7360_rotary *max7360_rotary) +{ + struct device *dev =3D max7360_rotary->input->dev.parent; + int val; + int error; + + val =3D FIELD_PREP(MAX7360_ROT_DEBOUNCE, max7360_rotary->debounce_ms) | + FIELD_PREP(MAX7360_ROT_INTCNT, 1) | MAX7360_ROT_INTCNT_DLY; + error =3D regmap_write(max7360_rotary->regmap, MAX7360_REG_RTRCFG, val); + if (error) + dev_err(dev, "Failed to set max7360 rotary encoder configuration\n"); + + return error; +} + +static int max7360_rotary_probe(struct platform_device *pdev) +{ + struct max7360_rotary *max7360_rotary; + struct device *dev =3D &pdev->dev; + struct input_dev *input; + struct regmap *regmap; + int irq; + int error; + + regmap =3D dev_get_regmap(dev->parent, NULL); + if (!regmap) + return dev_err_probe(dev, -ENODEV, "Could not get parent regmap\n"); + + irq =3D fwnode_irq_get_byname(dev_fwnode(dev->parent), "inti"); + if (irq < 0) + return dev_err_probe(dev, irq, "Failed to get IRQ\n"); + + max7360_rotary =3D devm_kzalloc(dev, sizeof(*max7360_rotary), GFP_KERNEL); + if (!max7360_rotary) + return -ENOMEM; + + max7360_rotary->regmap =3D regmap; + + device_property_read_u32(dev->parent, "linux,axis", &max7360_rotary->axis= ); + max7360_rotary->rollover =3D device_property_read_bool(dev->parent, + "rotary-encoder,rollover"); + max7360_rotary->relative_axis =3D + device_property_read_bool(dev->parent, "rotary-encoder,relative-axis"); + + error =3D device_property_read_u32(dev->parent, "rotary-encoder,steps", + &max7360_rotary->steps); + if (error) + max7360_rotary->steps =3D MAX7360_ROTARY_DEFAULT_STEPS; + + device_property_read_u32(dev->parent, "rotary-debounce-delay-ms", + &max7360_rotary->debounce_ms); + if (max7360_rotary->debounce_ms > MAX7360_ROT_DEBOUNCE_MAX) + return dev_err_probe(dev, -EINVAL, "Invalid debounce timing: %u\n", + max7360_rotary->debounce_ms); + + input =3D devm_input_allocate_device(dev); + if (!input) + return -ENOMEM; + + max7360_rotary->input =3D input; + + input->id.bustype =3D BUS_I2C; + input->name =3D pdev->name; + + if (max7360_rotary->relative_axis) + input_set_capability(input, EV_REL, max7360_rotary->axis); + else + input_set_abs_params(input, max7360_rotary->axis, 0, max7360_rotary->ste= ps, 0, 1); + + error =3D devm_request_threaded_irq(dev, irq, NULL, max7360_rotary_irq, + IRQF_ONESHOT | IRQF_SHARED, + "max7360-rotary", max7360_rotary); + if (error) + return dev_err_probe(dev, error, "Failed to register interrupt\n"); + + error =3D input_register_device(input); + if (error) + return dev_err_probe(dev, error, "Could not register input device\n"); + + error =3D max7360_rotary_hw_init(max7360_rotary); + if (error) + return dev_err_probe(dev, error, "Failed to initialize max7360 rotary\n"= ); + + device_init_wakeup(dev, true); + error =3D dev_pm_set_wake_irq(dev, irq); + if (error) + dev_warn(dev, "Failed to set up wakeup irq: %d\n", error); + + return 0; +} + +static void max7360_rotary_remove(struct platform_device *pdev) +{ + dev_pm_clear_wake_irq(&pdev->dev); + device_init_wakeup(&pdev->dev, false); +} + +static struct platform_driver max7360_rotary_driver =3D { + .driver =3D { + .name =3D "max7360-rotary", + }, + .probe =3D max7360_rotary_probe, + .remove =3D max7360_rotary_remove, +}; +module_platform_driver(max7360_rotary_driver); + +MODULE_DESCRIPTION("MAX7360 Rotary driver"); +MODULE_AUTHOR("Mathieu Dubois-Briand "); +MODULE_LICENSE("GPL"); --=20 2.39.5