From patchwork Tue May 23 19:27:59 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Doug Anderson X-Patchwork-Id: 98151 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp2375584vqo; Tue, 23 May 2023 12:38:26 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7az0qlcAeS69Ozsqt6SriR7PSLONvkhBIoupkwmFbq+NFZo0vJJ0bjpgacVAGbmx7Egi4y X-Received: by 2002:a17:902:d4d0:b0:1ac:3d1c:83c9 with SMTP id o16-20020a170902d4d000b001ac3d1c83c9mr21808971plg.13.1684870706027; Tue, 23 May 2023 12:38:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684870706; cv=none; d=google.com; s=arc-20160816; b=SA/XMfKf/RCAMfwweGWub5IFIvDBVJj5D4SVRZXGoqPGjm3JIPfcURcjnQKqX+B5PW BoBPBI9mojFPwBzhKSgSEvVcCzD426c+gtwRWvo4xRSfHb9POc2FzLSowqRhiyhEYc6l 0oLsyCnGqFVz+JuHLFCrba/M1qsEzMRX1vv+RUkJupQSpLD0o9JKhCD1313vgkyVOGFL LrK5ICX9TbZsmcAnOOT8mMsYg0UoV8W0sU3XzmBB+vN2qzSZ0gv1H8pEEWbRanfOs4Z+ sAQLpfpbtEz9KJ+4CFXuPLvdN686tMtaV9fyVinsrC1kkLVo0j00QghHH+NPCJAaN+HR YjXQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=DBMR6TdRsWjCzYNnqd6Lk8wDD7DSuTiZG2Mp89E0ajw=; b=OeaaCfs2wn9WIQ75gpAFpi+cyN6iQtQWJhmnTFEhSo4aoP5BBFr9QlVuLi5N+Ee/Mu nRvyEKtN7KTIMVOhngt6Fb80Htasc0ZNVt8wf3vaSsizxi9O9QryHWwuZH83F211i123 LgnzQHXb474OE076MnZv5IGshF3YMwqgMRcGsEC/8dEUhBZBq2d1htx08BNEFziM8iKR HOXlR9sPMqBY6UcWH9ReFioU5AbDFQ8HoWNsg2YbHC5x5YlKVsDPmQvMUyoIC2ZWSqFe tbSHgci1faBC8IsuA7BtfY3OFwyQcK68mtIeDqPuZqh6bTOInYqmM01K7OQrQ3gq4X93 Oc5A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=k81iI0VY; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id m5-20020a170902db8500b001ae6a0cd3d2si6606631pld.606.2023.05.23.12.38.13; Tue, 23 May 2023 12:38:25 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=k81iI0VY; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238420AbjEWTcB (ORCPT + 99 others); Tue, 23 May 2023 15:32:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37698 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238381AbjEWTbo (ORCPT ); Tue, 23 May 2023 15:31:44 -0400 Received: from mail-pl1-x629.google.com (mail-pl1-x629.google.com [IPv6:2607:f8b0:4864:20::629]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AB46018E for ; Tue, 23 May 2023 12:31:21 -0700 (PDT) Received: by mail-pl1-x629.google.com with SMTP id d9443c01a7336-1ae615d5018so370415ad.1 for ; Tue, 23 May 2023 12:31:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1684870281; x=1687462281; 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=DBMR6TdRsWjCzYNnqd6Lk8wDD7DSuTiZG2Mp89E0ajw=; b=k81iI0VYz+G1SgESSaCQ3eJJpdE8iDQRZba3GHZUCers6Y8qPLAdBfxLa0L57Gx/J7 2OvlsTn4vfd2rmyRQSyyob2a+zTuTN+LOyR3UAFXuYie2fQBW9YS6ksmF1M4vrr2nfup VCXdQVUOUgdrWmLDOQm+gBi8EXXg47LqFkse8= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684870281; x=1687462281; 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=DBMR6TdRsWjCzYNnqd6Lk8wDD7DSuTiZG2Mp89E0ajw=; b=gbJqIue1CvpviouEm7ZHnK240HQ/hxFRSX2A7tli54ra6pyRZXvgIbfQHh2p+OtUav 7UL62GZ2qAYOuLw7JCl+s07Cz3Wkv49s0lZHK+Rgo6vaheynhTL4dO8sBx6m9QJdMJpp UNgLqyIAxH0oxkW9mn5l+fFccCKj5Wk52VjZkdhwkBs5UMRNGLx6qJ5aE9Aw/8oVUaie DCcJLJ1aFDSEXmfCycZLujZsFFJADKDg4Zi5cNHX7TY+Mo7eLQQ2zEfy3woCNPlrEL5q I1UpbKlqHiSPXsqzosGC8T9WInzoVmvGQX9HL/z0drZab2iIOKDDNBzuB5WPuqP38KW7 Rp0Q== X-Gm-Message-State: AC+VfDz8vWH38iF2DXysBsplIfUmU1NGaPGiznUXa01WdY0aVPFXnqW9 7bMnylVBTA4fvg+h3qB35Qtgjg== X-Received: by 2002:a17:902:fe18:b0:1aa:e5cd:6478 with SMTP id g24-20020a170902fe1800b001aae5cd6478mr14599077plj.58.1684870281004; Tue, 23 May 2023 12:31:21 -0700 (PDT) Received: from tictac2.mtv.corp.google.com ([2620:15c:9d:2:af98:af9d:ed15:f8b3]) by smtp.gmail.com with ESMTPSA id y18-20020a170902b49200b001aaef9d0102sm7109947plr.197.2023.05.23.12.31.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 May 2023 12:31:19 -0700 (PDT) From: Douglas Anderson To: Jiri Kosina , Benjamin Tissoires , Bjorn Andersson , Konrad Dybcio , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Neil Armstrong , Sam Ravnborg , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann Cc: dri-devel@lists.freedesktop.org, linux-input@vger.kernel.org, Dmitry Torokhov , hsinyi@google.com, devicetree@vger.kernel.org, yangcong5@huaqin.corp-partner.google.com, linux-kernel@vger.kernel.org, Daniel Vetter , linux-arm-msm@vger.kernel.org, cros-qcom-dts-watchers@chromium.org, Douglas Anderson Subject: [PATCH 5/9] HID: i2c-hid: Rearrange probe() to power things up later Date: Tue, 23 May 2023 12:27:59 -0700 Message-ID: <20230523122802.5.Ifcc9b0a44895d164788966f9b9511fe094ca8cf9@changeid> X-Mailer: git-send-email 2.40.1.698.g37aff9b760-goog In-Reply-To: <20230523193017.4109557-1-dianders@chromium.org> References: <20230523193017.4109557-1-dianders@chromium.org> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1766714985409814585?= X-GMAIL-MSGID: =?utf-8?q?1766714985409814585?= 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 --- 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-hid-core.c index 19d985c20a5c..fb5ebf3ca739 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 = IRQF_TRIGGER_LOW; ret = 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 = %d," @@ -940,6 +941,72 @@ static void i2c_hid_core_shutdown_tail(struct i2c_hid *ihid) ihid->ops->shutdown_tail(ihid->ops); } +/** + * i2c_hid_core_initial_power_up() - First time power up of the i2c-hid device. + * @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 device + * exists, where we fetch the HID descriptor, and where we create the actual + * HID devices. + * + * Return: 0 or error code. + */ +int i2c_hid_core_initial_power_up(struct i2c_hid *ihid) +{ + struct i2c_client *client = ihid->client; + struct hid_device *hid = ihid->hid; + int ret; + + ret = i2c_hid_core_power_up(ihid); + if (ret) + return ret; + + /* Make sure there is something at this address */ + ret = i2c_smbus_read_byte(client); + if (ret < 0) { + i2c_hid_dbg(ihid, "nothing at this address: %d\n", ret); + ret = -ENXIO; + goto err; + } + + ret = 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 = le16_to_cpu(ihid->hdesc.bcdVersion); + hid->vendor = le16_to_cpu(ihid->hdesc.wVendorID); + hid->product = le16_to_cpu(ihid->hdesc.wProductID); + + hid->initial_quirks |= 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 = i2c_hid_lookup_quirk(hid->vendor, hid->product); + + ret = hid_add_device(hid); + if (ret) { + if (ret != -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, struct i2chid_ops *ops, if (!ihid) return -ENOMEM; - ihid->ops = ops; - - ret = i2c_hid_core_power_up(ihid); - if (ret) - return ret; - i2c_set_clientdata(client, ihid); + ihid->ops = ops; ihid->client = client; - ihid->wHIDDescRegister = cpu_to_le16(hid_descriptor_address); init_waitqueue_head(&ihid->wait); @@ -986,28 +1047,12 @@ int i2c_hid_core_probe(struct i2c_client *client, struct i2chid_ops *ops, * real computation later. */ ret = i2c_hid_alloc_buffers(ihid, HID_MIN_BUFFER_SIZE); if (ret < 0) - goto err_powered; - + return ret; device_enable_async_suspend(&client->dev); - /* Make sure there is something at this address */ - ret = i2c_smbus_read_byte(client); - if (ret < 0) { - i2c_hid_dbg(ihid, "nothing at this address: %d\n", ret); - ret = -ENXIO; - goto err_powered; - } - - ret = i2c_hid_fetch_hid_descriptor(ihid); - if (ret < 0) { - dev_err(&client->dev, - "Failed to fetch the HID Descriptor\n"); - goto err_powered; - } - ret = i2c_hid_init_irq(client); if (ret < 0) - goto err_powered; + goto err_buffers_allocated; hid = hid_allocate_device(); if (IS_ERR(hid)) { @@ -1021,26 +1066,11 @@ int i2c_hid_core_probe(struct i2c_client *client, struct i2chid_ops *ops, hid->ll_driver = &i2c_hid_ll_driver; hid->dev.parent = &client->dev; hid->bus = BUS_I2C; - hid->version = le16_to_cpu(ihid->hdesc.bcdVersion); - hid->vendor = le16_to_cpu(ihid->hdesc.wVendorID); - hid->product = le16_to_cpu(ihid->hdesc.wProductID); - hid->initial_quirks = quirks; - hid->initial_quirks |= 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 = i2c_hid_lookup_quirk(hid->vendor, hid->product); - ret = hid_add_device(hid); - if (ret) { - if (ret != -ENODEV) - hid_err(client, "can't add hid device: %d\n", ret); + ret = i2c_hid_core_initial_power_up(ihid); + if (ret) goto err_mem_free; - } return 0; @@ -1050,9 +1080,9 @@ int i2c_hid_core_probe(struct i2c_client *client, struct i2chid_ops *ops, err_irq: free_irq(client->irq, ihid); -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 = i2c_get_clientdata(client); struct hid_device *hid; + i2c_hid_core_power_down(ihid); + hid = ihid->hid; hid_destroy_device(hid); @@ -1069,8 +1101,6 @@ void i2c_hid_core_remove(struct i2c_client *client) if (ihid->bufsize) i2c_hid_free_buffers(ihid); - - i2c_hid_core_power_down(ihid); } EXPORT_SYMBOL_GPL(i2c_hid_core_remove);