From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wm1-f48.google.com (mail-wm1-f48.google.com [209.85.128.48]) (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 3399B3DC4C1 for ; Fri, 12 Jun 2026 07:23:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.48 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781249037; cv=none; b=tLbHuUn5VTHrUp/5Ik6CH3GqNb3uSQsSxICfWMLyHDBjV5LO0AUr5IfJ/dEHDf2upV01i2U7I2s+2UqytGikfd1tE89z1O2RBdRyTCdRfkpLOAZT2XHKojhlguGh2q+SgbziGoaw8nlfhpNGkZk7EnEnbU2+FccTCJXunYcahDE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781249037; c=relaxed/simple; bh=V3fVADudkUgfW9W8kxlseng+KfGlx0PhN4tl8YNByfI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=hn9t6rXtLjGr59CL+YR/R8wZBMfcyD1U8/lrLp+5Saw4u6p9IV+FZjUxi6Yhp+MLXqkA0Bf9DcOJ6J8udZetinsLT/pNHDOUah7wm0OSs8QVMwsxy0a4ZyU00NcJecb7lOvzKDunlcFmKWRuY+l4oyXyQ/xGSYVAiiVtZu/GpgI= 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=DGkxCuQ8; arc=none smtp.client-ip=209.85.128.48 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="DGkxCuQ8" Received: by mail-wm1-f48.google.com with SMTP id 5b1f17b1804b1-490b8a97b11so7360875e9.0 for ; Fri, 12 Jun 2026 00:23:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1781249034; x=1781853834; 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=jR431f9K+bXO1tvKG0cOPvpIj8IvID0B5a8VmWlfHKs=; b=DGkxCuQ8sygpwUm9Yv77SUfSuM4OYI1kxlVNGpDC4MFcyFDyfOBaBa8AgrgFueQM25 Lqhz0pDC29t+UgxlSQO4CDBRdfnFulEY0x3oR+9LUD/6iY5m1F6kawhDSSaZyrHRLkAH gV3ibH9fMovK0ljUuH1ty9Ls904LMMz2yziwwqUvSUiSitunYmTCF/o4cboR5fdcA4C0 04f8eML7RYY3mHVS9ImJJc7qhFZdf94kNf5VQa+6vjnMoWiANMpLn4Hf8VNRhR5FITSg yf299NxGQRAri6VM7vmotLsNT3HPCa6lqKmsbIsMFJGD4wDGH2Dk5u2IuiBOt1a2Hpxl K32Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1781249034; x=1781853834; 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=jR431f9K+bXO1tvKG0cOPvpIj8IvID0B5a8VmWlfHKs=; b=Jhbsbg+dt9OmbhpZByWxArvFyLNhGKWcF3TMInYu3j8mmTxCkWHbpakrG1kABG8gV8 amzgc4rqUCPf8fQk85nLmPIva5QkFs9N0Pd22I+nzK9fxO+AREd8n9p5OUmVaMfdHv1R O7loUtAbeUf9nDUH2iIM45/EDE0QNcGaESEnwzVSElvOLM60gGk7Cj7zdl8FuGICxHZ/ Gt/wkLvuhX4DH/HjOxy/cCwuM8j+PnaVj3NWaVo+u4Bz6uvxBbTwE9svgaz0IOc49y1I Bme4kpe5rCuHPS4kWUYNp4Ad6MKoPy/kpYjw5Kw5on7QAwaG0fxQRDD3yx66FmewIVYa Tdjw== X-Forwarded-Encrypted: i=1; AFNElJ8eLNC7DHdbG/eHk+MDqj4KW4NxUx9q/Crs/B7TxLjMOvz5fB1IzV3y2DlbY17YtIvSxoJBznpPpq86rEQ=@vger.kernel.org X-Gm-Message-State: AOJu0YwxWAafBAAjNox7Dz2A2mC2kt1ryjDjEcsXkGuqyq1uD3m+X6gS tdKYo82SBwViEvEAC2iDx49wxEBjI62BQqCMvd2MW+L5pNkPWjenlziW X-Gm-Gg: Acq92OEy773bbh/ghW5LGkNdkbtAzDVCzMqFFmcHbSXfFduxkHnmNoN19K1R5Sc9VDN 6WVGrI3I8sHrLUZR/V9apNSN+v2kwEz6ogkQrB5GuyIC59ceDaL6Hci+gAgTx64tK1+aRRSQZyW rQtJJUdsO3ySbGAOFREZpJgJYnfzQ1HnW2Mac1o+Jawnl7HIoO9b0rKTuR0k/DyanDih4GU8J2m dJXT9dfzNC69AxM6wrjGMUERYK/5D+GZnQBZNH7Myyw4PPKycuFSWp/6/gSqNDEviIKFm8n4o5v CnqZJYtyTgZhSNC5H/aehjhRkWCUIMCYArbjEMJkFg7jHRTmp58N1tRxJxMAV4uPKFleSS1u0vm lIOq2VTgURp8Dr1TkjOAs8Ep3qwXLTxDAUUpoBAOnM7CkWCK8eEgFVZB236x4zTq1N5DdnVqjl5 v84LaRJ9wBbOx4SosDRt5WDOWhh/pEmK0JyqzdbqdzsgOM9UoiuA== X-Received: by 2002:a05:600c:5292:b0:490:b4e5:ce7e with SMTP id 5b1f17b1804b1-490ec4fe3bfmr19052895e9.25.1781249034415; Fri, 12 Jun 2026 00:23:54 -0700 (PDT) Received: from arch.localdomain ([2409:8a28:a54:e741:3a5a:3245:d3dc:4b5d]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-490ea963cf8sm28715245e9.2.2026.06.12.00.23.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 12 Jun 2026 00:23:54 -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 v2 7/9] Input: cap11xx - refactor code for better CAP1114 support. Date: Fri, 12 Jun 2026 15:22:13 +0800 Message-ID: <20260612072237.1177304-8-jerrysteve1101@gmail.com> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260612072237.1177304-1-jerrysteve1101@gmail.com> References: <20260612072237.1177304-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 75746a8a2233..d45bb231d7a1 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(num_leds - 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; @@ -554,41 +564,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