From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pj1-f45.google.com (mail-pj1-f45.google.com [209.85.216.45]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AFEF33FCB22 for ; Mon, 15 Jun 2026 14:21:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.45 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781533324; cv=none; b=MhGYtylzws35T8wHNqRkJo4+WQTw3JRTlyGhAkGO5axSYGK2Z3aVAIbfJn9kqmfX1HNdRPPio2aJ551THb2PY8kW2+MEe6CE3I4T1nhFe6Mgkj4IzqFVFt3mo7qArv+HCjoWpgo0qM1h8t9mSR1y9UVvKPZN7D8PXP2K22J77dg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781533324; c=relaxed/simple; bh=qfK3SKX6U5kDYSvYsmzi2QUd5YPBvw5DVn0OKZsUIIE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ALo+VDv9E7CWUaBffZmEWDZN6jWS5JeDUBxB6XkPRf7KxCl/r+ahsOLuv/F+GMTX+BqQ+kuoyfen3eIn3FpJ2KeVJFci3JkCAX5f2e5tTYEfSpFKxhpuQX6SX5xAnX36I8N6yZrAVS/NlJPwiIJWrKPoHq1mV0heRl3/ackMbO4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=iI5qDT09; arc=none smtp.client-ip=209.85.216.45 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="iI5qDT09" Received: by mail-pj1-f45.google.com with SMTP id 98e67ed59e1d1-372b4330deeso2220182a91.0 for ; Mon, 15 Jun 2026 07:21:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1781533313; x=1782138113; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=m+lG/D10H+WbBBEJPWpqjE1Xy7NGrC7DoYpfX8RmnS0=; b=iI5qDT091vFfqdtnVDzBsZnwNP4YaCkVkjvE5t6XRNenHEeNo3rKOk9NQ16xZY8rEU cnkRk/zW0T7pDKVhEupveOkFErUqJ1lbUoxORf5Rd2wR6Tjh6uUT4IZt04ldo/XcOlM1 vf4Teyiy8gBrc1EQ6poS8GYVequId1xz5xFLDTXm37gzIfHMQAx2dnQTNcluuxWFLftF eBFCMn+qJSg94F8rHEZJwomSWB/KvUMyUlIvXxcXfJz2CUzF5vLfjiAKEuhripFRIhrd c/cr8ZnIJ9EV39Cl15jRO2eBSxDKFVRFrddgyI6pLbY8xYlGAILznR0JnJGLTFCdFxBb ud7g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1781533313; x=1782138113; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=m+lG/D10H+WbBBEJPWpqjE1Xy7NGrC7DoYpfX8RmnS0=; b=hhwf/VeJ/eDwjyWaFG1ger0+eEb1qBor0uQfknbxHXKC8ZTgO7KLB2/tJTV/JIf6gq FmOzywd9APO6LDJDYW5Cg+ke7iy5cJy1fMPVp60u3n8JeSyWTOBo/3/tqkeP+xafl10t 7T93QJlMR50vAbKV67CAbPlBxKV1P9hDaqFCZfsNOAH3h+q+fk+Mu4bfj8G5YDjcqcl/ /ktZWkrUhiNO/YrNFWvw0p6scu0TO6oqFFdi4MQpu1x7jD2Jx5OeFaM9vdtWWvokfC9q aVY8UPJDfeXp0ZYs/ZkD1v7b80fN3ZpmuaBbmD8uBMS/H8ss88b3LK/nrqpmUR3uJy9q P0PA== X-Forwarded-Encrypted: i=1; AFNElJ8mF3WM912ok5xsumZ1JFI3MamCgSknMJax1nOunM9epK4XiRaPNm1d8DoPNMFRqKEZiKsLf6PTYQrB+q0=@vger.kernel.org X-Gm-Message-State: AOJu0YylXlZr2oyXKIBdk5uRnGDBoj71mV+3NDN/Sscfn9MzeLBk29Du t4kjz/09iK6nWCGsp0RAyHlKXKGa8WSgLCkB6U1fbJ+Umbk+ZvZgZ/Vd X-Gm-Gg: Acq92OGaCKNAA/Swsbx6p0fXyGgpVpX9MPKDDrR9cndwFm0qTIx28JcFEd9hJOJ+gON Gx6lRnXyCJKtwdKXM8L/jZhjFRAr2iKk0a04vtutCeNwJfTcnxSHq8HfuGsX9Rum0bJHV+tst3E 4A3lTxurR3DwGfnSGnRR+bHZMA/EnpXBgv7IX0ZR9bna4YG2TiasN8/yYjDt8r2YPRvl1f5QcB5 1SfLV6zonsG50wxuYeISe1tdCIKsF8zUAA6LTUSOslmmOyuNC8KXA5GdzcSPe0kopI/kv0pabDa cS3+0Yx+DJ8mVuisl1UNtZsTM/IzmbnDvcRnS33zlQe+y2y9MlkeiPV07Y4tdXiuu4fCYuaeZQs VFEJxoce1hzTsdOwIX2uG6PiN3r/2QklZFQqWgaIUSFlLmmCGJuSLrxVCL6DmY0J+jBprFg95j0 Xs8Golpqm54UI+hCh06le6 X-Received: by 2002:a17:90a:e70d:b0:36b:9798:4f67 with SMTP id 98e67ed59e1d1-37c2bc73c79mr11726358a91.8.1781533312731; Mon, 15 Jun 2026 07:21:52 -0700 (PDT) Received: from arch.localdomain ([2409:8a28:a52:c491::1002]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-379e8cc467csm7178233a91.2.2026.06.15.07.21.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 Jun 2026 07:21:52 -0700 (PDT) From: Jun Yan To: Dmitry Torokhov , Rob Herring , Krzysztof Kozlowski , Conor Dooley Cc: Jun Yan , linux-input@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v3 07/10] Input: cap11xx - refactor code for better CAP1114 support. Date: Mon, 15 Jun 2026 22:20:33 +0800 Message-ID: <20260615142103.352163-8-jerrysteve1101@gmail.com> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260615142103.352163-1-jerrysteve1101@gmail.com> References: <20260615142103.352163-1-jerrysteve1101@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Extend cap11xx_hw_model structure to support CAP1114 with different register offsets and hardware characteristics: - led_output_control_reg_base: different address on CAP1114 - sensor_input_reg_base: different address on CAP1114 - num_sensor_thresholds: separate value from num_channels for CAP1114 - has_repeat_en: repeat enable support, disabled by default on CAP1114 Include linux/bits.h, update the register operations related to LEDs. Signed-off-by: Jun Yan --- drivers/input/keyboard/cap11xx.c | 73 +++++++++++++++++++++++--------- 1 file changed, 53 insertions(+), 20 deletions(-) diff --git a/drivers/input/keyboard/cap11xx.c b/drivers/input/keyboard/cap11xx.c index 3d75c0f90752..2e9382a721e9 100644 --- a/drivers/input/keyboard/cap11xx.c +++ b/drivers/input/keyboard/cap11xx.c @@ -5,6 +5,7 @@ * (c) 2014 Daniel Mack */ +#include #include #include #include @@ -35,7 +36,6 @@ #define CAP11XX_REG_LED_DUTY_CYCLE_4 0x93 #define CAP11XX_REG_LED_DUTY_MAX_MASK (0xf0) -#define CAP11XX_REG_LED_DUTY_MAX_MASK_SHIFT (4) #define CAP11XX_REG_LED_DUTY_MAX_VALUE (15) #define CAP11XX_REG_PRODUCT_ID 0xfd @@ -76,10 +76,14 @@ struct cap11xx_priv { struct cap11xx_hw_model { u8 product_id; + u8 led_output_control_reg_base; + u8 sensor_input_reg_base; unsigned int num_channels; unsigned int num_leds; + unsigned int num_sensor_thresholds; bool has_gain; bool has_irq_config; + bool has_repeat_en; bool has_sensitivity_control; bool has_signal_guard; }; @@ -204,8 +208,8 @@ static int cap11xx_init_keys(struct cap11xx_priv *priv) } if (!of_property_read_u32_array(node, "microchip,input-threshold", - priv->thresholds, priv->model->num_channels)) { - for (i = 0; i < priv->model->num_channels; i++) { + priv->thresholds, priv->model->num_sensor_thresholds)) { + for (i = 0; i < priv->model->num_sensor_thresholds; i++) { if (priv->thresholds[i] > 127) { dev_err(dev, "Invalid input-threshold value %u\n", priv->thresholds[i]); @@ -279,10 +283,12 @@ static int cap11xx_init_keys(struct cap11xx_priv *priv) of_property_read_u32_array(node, "linux,keycodes", priv->keycodes, priv->model->num_channels); - /* Disable autorepeat. The Linux input system has its own handling. */ - error = regmap_write(priv->regmap, CAP11XX_REG_REPEAT_RATE, 0); - if (error) - return error; + if (priv->model->has_repeat_en) { + /* Disable autorepeat. The Linux input system has its own handling. */ + error = regmap_write(priv->regmap, CAP11XX_REG_REPEAT_RATE, 0); + if (error) + return error; + } return 0; } @@ -301,7 +307,7 @@ static irqreturn_t cap11xx_thread_func(int irq_num, void *data) if (ret < 0) goto out; - ret = regmap_read(priv->regmap, CAP11XX_REG_SENSOR_INPUT, &status); + ret = regmap_read(priv->regmap, priv->model->sensor_input_reg_base, &status); if (ret < 0) goto out; @@ -355,7 +361,7 @@ static int cap11xx_led_set(struct led_classdev *cdev, * 0 (OFF) and 1 (ON). */ return regmap_update_bits(priv->regmap, - CAP11XX_REG_LED_OUTPUT_CONTROL, + priv->model->led_output_control_reg_base, BIT(led->reg), value ? BIT(led->reg) : 0); } @@ -367,6 +373,7 @@ static int cap11xx_init_leds(struct device *dev, struct cap11xx_led *led; int cnt = of_get_child_count(node); int error; + u32 duty_val; if (!num_leds || !cnt) return 0; @@ -380,15 +387,18 @@ static int cap11xx_init_leds(struct device *dev, priv->leds = led; + /* Set all LEDs to off */ error = regmap_update_bits(priv->regmap, - CAP11XX_REG_LED_OUTPUT_CONTROL, 0xff, 0); + priv->model->led_output_control_reg_base, + GENMASK(min(num_leds, 8) - 1, 0), 0); if (error) return error; + duty_val = FIELD_PREP(CAP11XX_REG_LED_DUTY_MAX_MASK, + CAP11XX_REG_LED_DUTY_MAX_VALUE); + error = regmap_update_bits(priv->regmap, CAP11XX_REG_LED_DUTY_CYCLE_4, - CAP11XX_REG_LED_DUTY_MAX_MASK, - CAP11XX_REG_LED_DUTY_MAX_VALUE << - CAP11XX_REG_LED_DUTY_MAX_MASK_SHIFT); + CAP11XX_REG_LED_DUTY_MAX_MASK, duty_val); if (error) return error; @@ -553,41 +563,64 @@ static int cap11xx_i2c_probe(struct i2c_client *i2c_client) } static const struct cap11xx_hw_model cap1106_model = { - .product_id = 0x55, .num_channels = 6, .num_leds = 0, + .product_id = 0x55, + .num_channels = 6, .num_leds = 0, .num_sensor_thresholds = 6, + .sensor_input_reg_base = CAP11XX_REG_SENSOR_INPUT, .has_gain = true, .has_irq_config = true, + .has_repeat_en = true, }; static const struct cap11xx_hw_model cap1126_model = { - .product_id = 0x53, .num_channels = 6, .num_leds = 2, + .product_id = 0x53, + .num_channels = 6, .num_leds = 2, .num_sensor_thresholds = 6, + .led_output_control_reg_base = CAP11XX_REG_LED_OUTPUT_CONTROL, + .sensor_input_reg_base = CAP11XX_REG_SENSOR_INPUT, .has_gain = true, .has_irq_config = true, + .has_repeat_en = true, }; static const struct cap11xx_hw_model cap1188_model = { - .product_id = 0x50, .num_channels = 8, .num_leds = 8, + .product_id = 0x50, + .num_channels = 8, .num_leds = 8, .num_sensor_thresholds = 8, + .led_output_control_reg_base = CAP11XX_REG_LED_OUTPUT_CONTROL, + .sensor_input_reg_base = CAP11XX_REG_SENSOR_INPUT, .has_gain = true, .has_irq_config = true, + .has_repeat_en = true, }; static const struct cap11xx_hw_model cap1203_model = { - .product_id = 0x6d, .num_channels = 3, .num_leds = 0, + .product_id = 0x6d, + .num_channels = 3, .num_leds = 0, .num_sensor_thresholds = 3, + .sensor_input_reg_base = CAP11XX_REG_SENSOR_INPUT, + .has_repeat_en = true, }; static const struct cap11xx_hw_model cap1206_model = { - .product_id = 0x67, .num_channels = 6, .num_leds = 0, + .product_id = 0x67, + .num_channels = 6, .num_leds = 0, .num_sensor_thresholds = 6, + .sensor_input_reg_base = CAP11XX_REG_SENSOR_INPUT, + .has_repeat_en = true, }; static const struct cap11xx_hw_model cap1293_model = { - .product_id = 0x6f, .num_channels = 3, .num_leds = 0, + .product_id = 0x6f, + .num_channels = 3, .num_leds = 0, .num_sensor_thresholds = 3, + .sensor_input_reg_base = CAP11XX_REG_SENSOR_INPUT, .has_gain = true, + .has_repeat_en = true, .has_sensitivity_control = true, .has_signal_guard = true, }; static const struct cap11xx_hw_model cap1298_model = { - .product_id = 0x71, .num_channels = 8, .num_leds = 0, + .product_id = 0x71, + .num_channels = 8, .num_leds = 0, .num_sensor_thresholds = 8, + .sensor_input_reg_base = CAP11XX_REG_SENSOR_INPUT, .has_gain = true, + .has_repeat_en = true, .has_sensitivity_control = true, .has_signal_guard = true, }; -- 2.54.0