From nobody Mon Feb 9 11:51:13 2026 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 45BB3EB64DD for ; Tue, 25 Jul 2023 20:37:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231229AbjGYUhe (ORCPT ); Tue, 25 Jul 2023 16:37:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34938 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230500AbjGYUhV (ORCPT ); Tue, 25 Jul 2023 16:37:21 -0400 Received: from mail-pj1-x102c.google.com (mail-pj1-x102c.google.com [IPv6:2607:f8b0:4864:20::102c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 94108268B for ; Tue, 25 Jul 2023 13:37:10 -0700 (PDT) Received: by mail-pj1-x102c.google.com with SMTP id 98e67ed59e1d1-26813478800so1586332a91.1 for ; Tue, 25 Jul 2023 13:37:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1690317429; x=1690922229; 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=TpzMl+hQ1ZFKADkTA6+giANmnh0KSfYRxfLW5dMWSJw=; b=nRURIRJwmt7wFoCuQYM1uZzf9MGtZsG5Bho2gKdWg+wAlJuwE5Vh9eeZWFn86FqOhD PaGpjOy3OaPwjjOseSuaywGZBg/VmDc10evbQ4F3D+enyMTScqxyrVNVyJwfZD2iNVRX /M7VjtZ+GAq3ABUFSrGtvW8BB92y4ibITyKnw= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690317429; x=1690922229; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=TpzMl+hQ1ZFKADkTA6+giANmnh0KSfYRxfLW5dMWSJw=; b=JIATm9XrAxcjh/ZQYqEUzpkMg23N9aYC2JHn06hvzEdfy9o2079DtxyQc/iBAAuDJc OYFvXNV6Vsl6jF/KOL+PR4xpOS0ylnOsSCYAazpWmVfTm6E5H38/SnJLZJSacAldaU0D hMadKjgHL/Xal0phemhC6S8ysGhbTYGHDeRND2+SxpTQ35pooAEWm1FY4ibk2ACrQxqH JL3Z0IGrjGMQT0OcKieW+vhyuNfwnnGElk9oj4fYyg5C3AmvYFh3kFzFsCweW28l2YDC rQpSFhQrEOKaULanSkOuzbe9qysQgcS/R/L5WFqQcwSBBIe2Kz5yKNxXqCXdzBchPd2C sZ3Q== X-Gm-Message-State: ABy/qLbJ0hY2qP5V8wJVQa8TZcwPJzVGwFEyi4sEMrFwABmpqdhMI1Ow JEsaocUxoS63nex24bHD5igwsQ== X-Google-Smtp-Source: APBJJlFmEjRKJoMuLY7gsv1K5TkBafrLyOOsaMbf8NUogJ97ehlUnPDGgKd8SRoI7uUdSNv9+0wXjw== X-Received: by 2002:a17:90a:f988:b0:268:273e:b75d with SMTP id cq8-20020a17090af98800b00268273eb75dmr242482pjb.20.1690317429623; Tue, 25 Jul 2023 13:37:09 -0700 (PDT) Received: from tictac2.mtv.corp.google.com ([2620:15c:9d:2:c363:4681:f5b8:301]) by smtp.gmail.com with ESMTPSA id bg1-20020a17090b0d8100b002676e961261sm1396951pjb.1.2023.07.25.13.37.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 25 Jul 2023 13:37:08 -0700 (PDT) From: Douglas Anderson To: Jiri Kosina , Benjamin Tissoires , Bjorn Andersson , Konrad Dybcio , Rob Herring , Frank Rowand , Krzysztof Kozlowski , Conor Dooley , Neil Armstrong , Sam Ravnborg , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann Cc: cros-qcom-dts-watchers@chromium.org, Chris Morgan , linux-input@vger.kernel.org, hsinyi@google.com, linux-arm-msm@vger.kernel.org, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, Dmitry Torokhov , devicetree@vger.kernel.org, Daniel Vetter , yangcong5@huaqin.corp-partner.google.com, Douglas Anderson Subject: [PATCH v3 06/10] HID: i2c-hid: Rearrange probe() to power things up later Date: Tue, 25 Jul 2023 13:34:41 -0700 Message-ID: <20230725133443.v3.6.Ifcc9b0a44895d164788966f9b9511fe094ca8cf9@changeid> X-Mailer: git-send-email 2.41.0.487.g6d72f3e995-goog In-Reply-To: <20230725203545.2260506-1-dianders@chromium.org> References: <20230725203545.2260506-1-dianders@chromium.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" In a future patch, we want to change i2c-hid not to necessarily power up the touchscreen during probe. In preparation for that, rearrange the probe function so that we put as much stuff _before_ powering up the device as possible. This change is expected to have no functional effect. Signed-off-by: Douglas Anderson --- (no changes since v2) Changes in v2: - i2c_hid_core_initial_power_up() is now static. drivers/hid/i2c-hid/i2c-hid-core.c | 124 ++++++++++++++++++----------- 1 file changed, 77 insertions(+), 47 deletions(-) diff --git a/drivers/hid/i2c-hid/i2c-hid-core.c b/drivers/hid/i2c-hid/i2c-h= id-core.c index 19d985c20a5c..d29e6421ecba 100644 --- a/drivers/hid/i2c-hid/i2c-hid-core.c +++ b/drivers/hid/i2c-hid/i2c-hid-core.c @@ -855,7 +855,8 @@ static int i2c_hid_init_irq(struct i2c_client *client) irqflags =3D IRQF_TRIGGER_LOW; =20 ret =3D request_threaded_irq(client->irq, NULL, i2c_hid_irq, - irqflags | IRQF_ONESHOT, client->name, ihid); + irqflags | IRQF_ONESHOT | IRQF_NO_AUTOEN, + client->name, ihid); if (ret < 0) { dev_warn(&client->dev, "Could not register for %s interrupt, irq =3D %d," @@ -940,6 +941,72 @@ static void i2c_hid_core_shutdown_tail(struct i2c_hid = *ihid) ihid->ops->shutdown_tail(ihid->ops); } =20 +/** + * i2c_hid_core_initial_power_up() - First time power up of the i2c-hid de= vice. + * @ihid: The ihid object created during probe. + * + * This function is called at probe time. + * + * The initial power on is where we do some basic validation that the devi= ce + * exists, where we fetch the HID descriptor, and where we create the actu= al + * HID devices. + * + * Return: 0 or error code. + */ +static int i2c_hid_core_initial_power_up(struct i2c_hid *ihid) +{ + struct i2c_client *client =3D ihid->client; + struct hid_device *hid =3D ihid->hid; + int ret; + + ret =3D i2c_hid_core_power_up(ihid); + if (ret) + return ret; + + /* Make sure there is something at this address */ + ret =3D i2c_smbus_read_byte(client); + if (ret < 0) { + i2c_hid_dbg(ihid, "nothing at this address: %d\n", ret); + ret =3D -ENXIO; + goto err; + } + + ret =3D i2c_hid_fetch_hid_descriptor(ihid); + if (ret < 0) { + dev_err(&client->dev, + "Failed to fetch the HID Descriptor\n"); + goto err; + } + + enable_irq(client->irq); + + hid->version =3D le16_to_cpu(ihid->hdesc.bcdVersion); + hid->vendor =3D le16_to_cpu(ihid->hdesc.wVendorID); + hid->product =3D le16_to_cpu(ihid->hdesc.wProductID); + + hid->initial_quirks |=3D i2c_hid_get_dmi_quirks(hid->vendor, + hid->product); + + snprintf(hid->name, sizeof(hid->name), "%s %04X:%04X", + client->name, (u16)hid->vendor, (u16)hid->product); + strscpy(hid->phys, dev_name(&client->dev), sizeof(hid->phys)); + + ihid->quirks =3D i2c_hid_lookup_quirk(hid->vendor, hid->product); + + ret =3D hid_add_device(hid); + if (ret) { + if (ret !=3D -ENODEV) + hid_err(client, "can't add hid device: %d\n", ret); + goto err; + } + + return 0; + +err: + i2c_hid_core_power_down(ihid); + return ret; +} + int i2c_hid_core_probe(struct i2c_client *client, struct i2chid_ops *ops, u16 hid_descriptor_address, u32 quirks) { @@ -966,16 +1033,10 @@ int i2c_hid_core_probe(struct i2c_client *client, st= ruct i2chid_ops *ops, if (!ihid) return -ENOMEM; =20 - ihid->ops =3D ops; - - ret =3D i2c_hid_core_power_up(ihid); - if (ret) - return ret; - i2c_set_clientdata(client, ihid); =20 + ihid->ops =3D ops; ihid->client =3D client; - ihid->wHIDDescRegister =3D cpu_to_le16(hid_descriptor_address); =20 init_waitqueue_head(&ihid->wait); @@ -986,28 +1047,12 @@ int i2c_hid_core_probe(struct i2c_client *client, st= ruct i2chid_ops *ops, * real computation later. */ ret =3D i2c_hid_alloc_buffers(ihid, HID_MIN_BUFFER_SIZE); if (ret < 0) - goto err_powered; - + return ret; device_enable_async_suspend(&client->dev); =20 - /* Make sure there is something at this address */ - ret =3D i2c_smbus_read_byte(client); - if (ret < 0) { - i2c_hid_dbg(ihid, "nothing at this address: %d\n", ret); - ret =3D -ENXIO; - goto err_powered; - } - - ret =3D i2c_hid_fetch_hid_descriptor(ihid); - if (ret < 0) { - dev_err(&client->dev, - "Failed to fetch the HID Descriptor\n"); - goto err_powered; - } - ret =3D i2c_hid_init_irq(client); if (ret < 0) - goto err_powered; + goto err_buffers_allocated; =20 hid =3D hid_allocate_device(); if (IS_ERR(hid)) { @@ -1021,26 +1066,11 @@ int i2c_hid_core_probe(struct i2c_client *client, s= truct i2chid_ops *ops, hid->ll_driver =3D &i2c_hid_ll_driver; hid->dev.parent =3D &client->dev; hid->bus =3D BUS_I2C; - hid->version =3D le16_to_cpu(ihid->hdesc.bcdVersion); - hid->vendor =3D le16_to_cpu(ihid->hdesc.wVendorID); - hid->product =3D le16_to_cpu(ihid->hdesc.wProductID); - hid->initial_quirks =3D quirks; - hid->initial_quirks |=3D i2c_hid_get_dmi_quirks(hid->vendor, - hid->product); - - snprintf(hid->name, sizeof(hid->name), "%s %04X:%04X", - client->name, (u16)hid->vendor, (u16)hid->product); - strscpy(hid->phys, dev_name(&client->dev), sizeof(hid->phys)); - - ihid->quirks =3D i2c_hid_lookup_quirk(hid->vendor, hid->product); =20 - ret =3D hid_add_device(hid); - if (ret) { - if (ret !=3D -ENODEV) - hid_err(client, "can't add hid device: %d\n", ret); + ret =3D i2c_hid_core_initial_power_up(ihid); + if (ret) goto err_mem_free; - } =20 return 0; =20 @@ -1050,9 +1080,9 @@ int i2c_hid_core_probe(struct i2c_client *client, str= uct i2chid_ops *ops, err_irq: free_irq(client->irq, ihid); =20 -err_powered: - i2c_hid_core_power_down(ihid); +err_buffers_allocated: i2c_hid_free_buffers(ihid); + return ret; } EXPORT_SYMBOL_GPL(i2c_hid_core_probe); @@ -1062,6 +1092,8 @@ void i2c_hid_core_remove(struct i2c_client *client) struct i2c_hid *ihid =3D i2c_get_clientdata(client); struct hid_device *hid; =20 + i2c_hid_core_power_down(ihid); + hid =3D ihid->hid; hid_destroy_device(hid); =20 @@ -1069,8 +1101,6 @@ void i2c_hid_core_remove(struct i2c_client *client) =20 if (ihid->bufsize) i2c_hid_free_buffers(ihid); - - i2c_hid_core_power_down(ihid); } EXPORT_SYMBOL_GPL(i2c_hid_core_remove); =20 --=20 2.41.0.487.g6d72f3e995-goog