From nobody Thu Dec 18 14:26:21 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id D4B7BC4332F for ; Wed, 13 Dec 2023 05:38:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232859AbjLMFd6 (ORCPT ); Wed, 13 Dec 2023 00:33:58 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55910 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229906AbjLMFd4 (ORCPT ); Wed, 13 Dec 2023 00:33:56 -0500 Received: from mail-io1-xd2c.google.com (mail-io1-xd2c.google.com [IPv6:2607:f8b0:4864:20::d2c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 41476D5; Tue, 12 Dec 2023 21:34:02 -0800 (PST) Received: by mail-io1-xd2c.google.com with SMTP id ca18e2360f4ac-7b7418bea02so150576339f.0; Tue, 12 Dec 2023 21:34:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1702445641; x=1703050441; darn=vger.kernel.org; h=content-disposition:mime-version:message-id:subject:cc:to:from:date :from:to:cc:subject:date:message-id:reply-to; bh=c/JrKjOoGP7gnAW/2hayVFApp9MtzrX02np9XSoQbBs=; b=nqxEpvmbdAaM7gL4kpfKkOUHlndgYXx4lwB3BiFV0QEnuf6rD800HSN+spbX4O8Dko qItMtd3+ySu1292uNg0zIFXuLCjwse69XcNGSkmOEIDtNQX0YGOep0zhMS2Ct++PiONb pu9mtBtuma2v2BvkpiSo+vuBh2b1VcufFgzTss1++eWUikjaLTEv/1MyM4pv/O0kd+Bh yv+7J14VmV8d9POG/1ylL8DpIBNvyJzOrlB106V3Hwcrl1/H9YYOVsFqB6VYE0vyo31R AS1emi/fk26BwaXmjtbLCC5ocbrigt6bledUV2kLGrRiMsOvfZsvmHWNmV+BqVyvVMHY fTVA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702445641; x=1703050441; h=content-disposition:mime-version:message-id:subject:cc:to:from:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=c/JrKjOoGP7gnAW/2hayVFApp9MtzrX02np9XSoQbBs=; b=F+We7PnLwOgdKm+gbhb/RyAXbOWHsc/0jhp3Oo1X7e94yL49x0txWc3OAsdxgIKHio OL/Ru2NDYYOIOmoRaf4d5hMpynAIp0Mt/8do+3/NdvEcIGfz7i7qH6dJ3YeHBaMyrIgJ SbuGfodIXSLkht2WczRo6db14ZxsSinIzD8Osft99+wwhuTFF9G/CVkwqAX5UdrgxVaD zugC8h/RgVEf/vTR4zv1kF26uR5xcmwqpQICeyy86I9soCOpCPP7joeyhfnqtMkf9zZg 7YqzeyOb+B+q0jUDeLib4WUsMVrfPYz7SdNoNkOZO6X6OiNNuxMUFwSIoagJDBgEnVfj OEJw== X-Gm-Message-State: AOJu0Yz8IwJNOvLaUheWqbIRd2xsryflOe/gylWCPtozx05uMEJXgqTV Ibo17Yfz/Mypt5TAXodXjnXbsUMIm1pxdw== X-Google-Smtp-Source: AGHT+IEtxE/Z4iLLZWF+/OhcY31GjYgq9y16doBw1qYzS4Jx0WCAy5u3ieDQHXcjk1RfpXpiVsq9OQ== X-Received: by 2002:a92:c565:0:b0:35d:69c8:8d61 with SMTP id b5-20020a92c565000000b0035d69c88d61mr11925470ilj.14.1702445641069; Tue, 12 Dec 2023 21:34:01 -0800 (PST) Received: from google.com ([2620:15c:9d:2:96c1:256f:67e0:c0db]) by smtp.gmail.com with ESMTPSA id q5-20020a170902bd8500b001c9d011581dsm9534384pls.164.2023.12.12.21.34.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Dec 2023 21:34:00 -0800 (PST) Date: Tue, 12 Dec 2023 21:33:58 -0800 From: Dmitry Torokhov To: linux-input@vger.kernel.org Cc: Jiri Valek - 2N , linux-kernel@vger.kernel.org Subject: [PATCH] Input: cap11xx - stop using chip ID when configuring it Message-ID: MIME-Version: 1.0 Content-Disposition: inline Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" struct cap11xx_hw_model is supposed to describe the chip capabilities, however later code changes introduced checks against chip ID. Introduce new capabilities in cap11xx_hw_model and use them when applying chip configuration, and remove the enum for chip ID. While at it, rename no_gain to has_gain to match the rest of the new capabilities. Signed-off-by: Dmitry Torokhov Reviewed-by: Jiri Valek - 2N --- drivers/input/keyboard/cap11xx.c | 125 +++++++++++++++++-------------- 1 file changed, 70 insertions(+), 55 deletions(-) diff --git a/drivers/input/keyboard/cap11xx.c b/drivers/input/keyboard/cap1= 1xx.c index ebcbc00d2059..c85bb0ca0e39 100644 --- a/drivers/input/keyboard/cap11xx.c +++ b/drivers/input/keyboard/cap11xx.c @@ -86,7 +86,6 @@ struct cap11xx_priv { struct device *dev; struct input_dev *idev; const struct cap11xx_hw_model *model; - u8 id; =20 struct cap11xx_led *leds; int num_leds; @@ -104,27 +103,10 @@ struct cap11xx_hw_model { u8 product_id; unsigned int num_channels; unsigned int num_leds; - bool no_gain; -}; - -enum { - CAP1106, - CAP1126, - CAP1188, - CAP1203, - CAP1206, - CAP1293, - CAP1298 -}; - -static const struct cap11xx_hw_model cap11xx_devices[] =3D { - [CAP1106] =3D { .product_id =3D 0x55, .num_channels =3D 6, .num_leds =3D = 0, .no_gain =3D false }, - [CAP1126] =3D { .product_id =3D 0x53, .num_channels =3D 6, .num_leds =3D = 2, .no_gain =3D false }, - [CAP1188] =3D { .product_id =3D 0x50, .num_channels =3D 8, .num_leds =3D = 8, .no_gain =3D false }, - [CAP1203] =3D { .product_id =3D 0x6d, .num_channels =3D 3, .num_leds =3D = 0, .no_gain =3D true }, - [CAP1206] =3D { .product_id =3D 0x67, .num_channels =3D 6, .num_leds =3D = 0, .no_gain =3D true }, - [CAP1293] =3D { .product_id =3D 0x6f, .num_channels =3D 3, .num_leds =3D = 0, .no_gain =3D false }, - [CAP1298] =3D { .product_id =3D 0x71, .num_channels =3D 8, .num_leds =3D = 0, .no_gain =3D false }, + bool has_gain; + bool has_irq_config; + bool has_sensitivity_control; + bool has_signal_guard; }; =20 static const struct reg_default cap11xx_reg_defaults[] =3D { @@ -227,7 +209,7 @@ static int cap11xx_init_keys(struct cap11xx_priv *priv) } =20 if (!of_property_read_u32(node, "microchip,sensor-gain", &u32_val)) { - if (priv->model->no_gain) { + if (!priv->model->has_gain) { dev_warn(dev, "This model doesn't support 'sensor-gain'\n"); } else if (is_power_of_2(u32_val) && u32_val <=3D 8) { @@ -246,9 +228,7 @@ static int cap11xx_init_keys(struct cap11xx_priv *priv) } =20 if (of_property_read_bool(node, "microchip,irq-active-high")) { - if (priv->id =3D=3D CAP1106 || - priv->id =3D=3D CAP1126 || - priv->id =3D=3D CAP1188) { + if (priv->model->has_irq_config) { error =3D regmap_update_bits(priv->regmap, CAP11XX_REG_CONFIG2, CAP11XX_REG_CONFIG2_ALT_POL, @@ -299,7 +279,7 @@ static int cap11xx_init_keys(struct cap11xx_priv *priv) if (!of_property_read_u32_array(node, "microchip,calib-sensitivity", priv->calib_sensitivities, priv->model->num_channels)) { - if (priv->id =3D=3D CAP1293 || priv->id =3D=3D CAP1298) { + if (priv->model->has_sensitivity_control) { for (i =3D 0; i < priv->model->num_channels; i++) { if (!is_power_of_2(priv->calib_sensitivities[i]) || priv->calib_sensitivities[i] > 4) { @@ -314,7 +294,7 @@ static int cap11xx_init_keys(struct cap11xx_priv *priv) if (error) return error; =20 - if (priv->id =3D=3D CAP1298) { + if (priv->model->num_channels > 4) { error =3D cap11xx_write_calib_sens_config_2(priv); if (error) return error; @@ -336,7 +316,7 @@ static int cap11xx_init_keys(struct cap11xx_priv *priv) } =20 if (priv->signal_guard_inputs_mask) { - if (priv->id =3D=3D CAP1293 || priv->id =3D=3D CAP1298) { + if (priv->model->has_signal_guard) { error =3D regmap_write(priv->regmap, CAP11XX_REG_SIGNAL_GUARD_ENABLE, priv->signal_guard_inputs_mask); @@ -511,20 +491,16 @@ static int cap11xx_init_leds(struct device *dev, =20 static int cap11xx_i2c_probe(struct i2c_client *i2c_client) { - const struct i2c_device_id *id =3D i2c_client_get_device_id(i2c_client); + const struct i2c_device_id *id; + const struct cap11xx_hw_model *cap; struct device *dev =3D &i2c_client->dev; struct cap11xx_priv *priv; - const struct cap11xx_hw_model *cap; int i, error; unsigned int val, rev; =20 - if (id->driver_data >=3D ARRAY_SIZE(cap11xx_devices)) { - dev_err(dev, "Invalid device ID %lu\n", id->driver_data); - return -EINVAL; - } - - cap =3D &cap11xx_devices[id->driver_data]; - if (!cap || !cap->num_channels) { + id =3D i2c_client_get_device_id(i2c_client); + cap =3D i2c_get_match_data(i2c_client); + if (!id || !cap || !cap->num_channels) { dev_err(dev, "Invalid device configuration\n"); return -EINVAL; } @@ -569,7 +545,6 @@ static int cap11xx_i2c_probe(struct i2c_client *i2c_cli= ent) id->name, rev); =20 priv->model =3D cap; - priv->id =3D id->driver_data; =20 dev_info(dev, "CAP11XX device detected, model %s, revision 0x%02x\n", id->name, rev); @@ -630,27 +605,67 @@ static int cap11xx_i2c_probe(struct i2c_client *i2c_c= lient) return 0; } =20 +static const struct cap11xx_hw_model cap1106_model =3D { + .product_id =3D 0x55, .num_channels =3D 6, .num_leds =3D 0, + .has_gain =3D true, + .has_irq_config =3D true, +}; + +static const struct cap11xx_hw_model cap1126_model =3D { + .product_id =3D 0x53, .num_channels =3D 6, .num_leds =3D 2, + .has_gain =3D true, + .has_irq_config =3D true, +}; + +static const struct cap11xx_hw_model cap1188_model =3D { + .product_id =3D 0x50, .num_channels =3D 8, .num_leds =3D 8, + .has_gain =3D true, + .has_irq_config =3D true, +}; + +static const struct cap11xx_hw_model cap1203_model =3D { + .product_id =3D 0x6d, .num_channels =3D 3, .num_leds =3D 0, +}; + +static const struct cap11xx_hw_model cap1206_model =3D { + .product_id =3D 0x67, .num_channels =3D 6, .num_leds =3D 0, +}; + +static const struct cap11xx_hw_model cap1293_model =3D { + .product_id =3D 0x6f, .num_channels =3D 3, .num_leds =3D 0, + .has_gain =3D true, + .has_sensitivity_control =3D true, + .has_signal_guard =3D true, +}; + +static const struct cap11xx_hw_model cap1298_model =3D { + .product_id =3D 0x71, .num_channels =3D 8, .num_leds =3D 0, + .has_gain =3D true, + .has_sensitivity_control =3D true, + .has_signal_guard =3D true, +}; + static const struct of_device_id cap11xx_dt_ids[] =3D { - { .compatible =3D "microchip,cap1106", }, - { .compatible =3D "microchip,cap1126", }, - { .compatible =3D "microchip,cap1188", }, - { .compatible =3D "microchip,cap1203", }, - { .compatible =3D "microchip,cap1206", }, - { .compatible =3D "microchip,cap1293", }, - { .compatible =3D "microchip,cap1298", }, - {} + { .compatible =3D "microchip,cap1106", .data =3D &cap1106_model }, + { .compatible =3D "microchip,cap1126", .data =3D &cap1126_model }, + { .compatible =3D "microchip,cap1188", .data =3D &cap1188_model }, + { .compatible =3D "microchip,cap1203", .data =3D &cap1203_model }, + { .compatible =3D "microchip,cap1206", .data =3D &cap1206_model }, + { .compatible =3D "microchip,cap1293", .data =3D &cap1293_model }, + { .compatible =3D "microchip,cap1298", .data =3D &cap1298_model }, + { } }; MODULE_DEVICE_TABLE(of, cap11xx_dt_ids); =20 static const struct i2c_device_id cap11xx_i2c_ids[] =3D { - { "cap1106", CAP1106 }, - { "cap1126", CAP1126 }, - { "cap1188", CAP1188 }, - { "cap1203", CAP1203 }, - { "cap1206", CAP1206 }, - { "cap1293", CAP1293 }, - { "cap1298", CAP1298 }, - {} + { "cap1106", (kernel_ulong_t)&cap1106_model }, + { "cap1126", (kernel_ulong_t)&cap1126_model }, + { "cap1188", (kernel_ulong_t)&cap1188_model }, + { "cap1203", (kernel_ulong_t)&cap1203_model }, + { "cap1206", (kernel_ulong_t)&cap1206_model }, + { "cap1293", (kernel_ulong_t)&cap1293_model }, + { "cap1298", (kernel_ulong_t)&cap1298_model }, + { } }; MODULE_DEVICE_TABLE(i2c, cap11xx_i2c_ids); =20 --=20 2.43.0.472.g3155946c3a-goog --=20 Dmitry