Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp475055pxb; Tue, 3 Nov 2020 04:45:27 -0800 (PST) X-Google-Smtp-Source: ABdhPJwYxQFbYpxZ7Vu376EmsSyApGmjQiByMze5AzhzDvWqVwMF9eoUXtL0g3pct3BBNuGmdzwH X-Received: by 2002:a17:906:444:: with SMTP id e4mr21108386eja.218.1604407526930; Tue, 03 Nov 2020 04:45:26 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1604407526; cv=none; d=google.com; s=arc-20160816; b=wkMf2AkW2EJs5ym+UZTBZ3gjNBFQarJ6K006WzPrS7JuURUlYGJ89T8M+WJqXeYoqc OuiON/Kurt4dAO459Mj2yWFTFM9Q2qMRhM8uQglpRCX9KDbQmjUQJwFBMecQ4qT4EweF ZQ2MhoRTi41Dij3dENUDpWz+NhrQ7xjeHLCbpx6ZtwQtTi2UFP9NAsgSH4RWkmjk45NA D4PoCwfdUje63pvXCJcmlnmZpLfgkdLbnAFHZ6GLrXpUcDQKEotpZg9meKxXFRKm2wwJ rLSyjiNDzB333Ak30Ef51lDJmaZOS9QdMaUeGr2HIF0edOIp23g8On4Stda6/4nCc9TH KgnQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=F84fRXLZfMfvouZKtilNzMebEPZg/rkOtWVtPorkAYY=; b=mavIjNMFU4W2y7XmqrnLzKG7Dq2uTGSqo4XxwdMjMERkxEcoR/6V8kIOV9IlGAtcPz Kv9UyzyTUMg5u8RiH1tuOGVAGKvrMxpGqFnxBVugLU/T+N+HoOq3l/MSSoBVgl+J8Gsl 9fU2aeB59u2FXnmTlffQRDGJzLDoMjsyHkBInRlt/CZKKrQv4B3492z09U3zcTQeBHJL ChAcEJTdklD3J4lUzN1t34LueeQLfpLjHo25v02vsnRM98lgUFfmPBppLFzHtbYmhTHc cIKBsiTzp8KXHU0vzwHyyvRHRee+WI8CkWCGJ/Ogw8uM1J7ds8g27SCBRJ9iPbBcC9fw Tq6w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=Lf2GMiRp; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id i6si9038930ejo.223.2020.11.03.04.45.04; Tue, 03 Nov 2020 04:45:26 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=Lf2GMiRp; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728729AbgKCMnF (ORCPT + 99 others); Tue, 3 Nov 2020 07:43:05 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:23746 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726581AbgKCMnE (ORCPT ); Tue, 3 Nov 2020 07:43:04 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1604407382; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=F84fRXLZfMfvouZKtilNzMebEPZg/rkOtWVtPorkAYY=; b=Lf2GMiRpgypbHM38xaSgVNd46VJMn7tfQ2ttZ2FxgqInE1mnMusixWrzKMk+eqKaWphlh3 F3zuDBpR0evMJNJTjGgn38yAwc+Uf5koiE5bN37RPphU4L9tDwl/bzM/jx+RHyaivduHWj iGL1Wx6AjcVtzJ/gD8+Y7H4c7Kg+9cY= Received: from mail-pf1-f197.google.com (mail-pf1-f197.google.com [209.85.210.197]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-428-gRJ46luiPjmq2aMgUallZA-1; Tue, 03 Nov 2020 07:43:00 -0500 X-MC-Unique: gRJ46luiPjmq2aMgUallZA-1 Received: by mail-pf1-f197.google.com with SMTP id a27so12027234pfl.17 for ; Tue, 03 Nov 2020 04:43:00 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=F84fRXLZfMfvouZKtilNzMebEPZg/rkOtWVtPorkAYY=; b=N1ElG/Q00EP9sg6foOJ+JDIqyFxbVx/zeayqPApEdagSDA/n0ZI8GvwwyeTaA8RaO/ ElSmM7W4nKadcioU7hu7WFr2e/+2+AYsjfz+tgTtVBYXpjvSS6cMyNpiGH4L2r3GbYZr 4h4l0ah0gkpLoraMd+eMvu9RTHCKbL8q/hBimrBrJhnuwVdZQn3R83W6BP0UAarek8LD 3ZOiDH49AVM5Ja5w1abMX4DXbha7CyTj5Ewt9jofWvSiM2ulccLm37qs19313gZw/tcV sRYo6FiPUiGnhcthmWQdpdFMxNEDtQeYBkI47WNTPEcopYJAUpochvpprJTgrI1uMMmO Yoyw== X-Gm-Message-State: AOAM533vt6+sWs9bEXVOEkJ03HF07/pD4lFfY+XIsalxy8usAMKBGnJ/ ISTPLFBgiRsVQ1IwXeMlqeYFdZpiiqWjou7L6Lb1h3XtftVSKKhGBQdhdlQVma7SbtWACYiJm+H LT8CSSPK7SZQH9mKA+tSqcAKLEAZJcyH+T7PjHbmx X-Received: by 2002:a17:902:8341:b029:d4:e3fa:e464 with SMTP id z1-20020a1709028341b02900d4e3fae464mr25504381pln.66.1604407378927; Tue, 03 Nov 2020 04:42:58 -0800 (PST) X-Received: by 2002:a17:902:8341:b029:d4:e3fa:e464 with SMTP id z1-20020a1709028341b02900d4e3fae464mr25504358pln.66.1604407378497; Tue, 03 Nov 2020 04:42:58 -0800 (PST) MIME-Version: 1.0 References: <20201102161210.v3.1.Ibb28033c81d87fcc13a6ba28c6ea7ac154d65f93@changeid> <20201102161210.v3.2.Ied4ce10d229cd7c69abf13a0361ba0b8d82eb9c4@changeid> <28e75d51-28d8-5a9a-adf9-71f107e94dfb@redhat.com> In-Reply-To: <28e75d51-28d8-5a9a-adf9-71f107e94dfb@redhat.com> From: Benjamin Tissoires Date: Tue, 3 Nov 2020 13:42:47 +0100 Message-ID: Subject: Re: [PATCH v3 2/3] HID: i2c-hid: Allow subclasses of i2c-hid for power sequencing To: Hans de Goede Cc: Rob Herring , Douglas Anderson , Jiri Kosina , Greg Kroah-Hartman , Dmitry Torokhov , Linux Input , Stephen Boyd , Kai Heng Feng , andrea@borgia.bo.it, Aaron Ma , Daniel Playfair Cal , Jiri Kosina , Pavel Balan , You-Sheng Yang , "linux-kernel@vger.kernel.org" Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi, On Tue, Nov 3, 2020 at 10:09 AM Hans de Goede wrote: > > Hi, > > On 11/3/20 2:46 AM, Rob Herring wrote: > > On Mon, Nov 2, 2020 at 6:13 PM Douglas Anderson wrote: > >> > >> This exports some things from i2c-hid so that we can have a driver > >> that's effectively a subclass of it and that can do its own power > >> sequencing. > >> > >> Signed-off-by: Douglas Anderson > >> --- > >> > >> Changes in v3: > >> - Rework to use subclassing. > >> > >> Changes in v2: > >> - Use a separate compatible string for this new touchscreen. > >> - Get timings based on the compatible string. > >> > >> drivers/hid/i2c-hid/i2c-hid-core.c | 78 +++++++++++++++++---------- > >> include/linux/input/i2c-hid-core.h | 19 +++++++ > >> include/linux/platform_data/i2c-hid.h | 9 ++++ > >> 3 files changed, 79 insertions(+), 27 deletions(-) > >> create mode 100644 include/linux/input/i2c-hid-core.h > >> > >> diff --git a/drivers/hid/i2c-hid/i2c-hid-core.c b/drivers/hid/i2c-hid/i2c-hid-core.c > >> index 786e3e9af1c9..910e9089fcf8 100644 > >> --- a/drivers/hid/i2c-hid/i2c-hid-core.c > >> +++ b/drivers/hid/i2c-hid/i2c-hid-core.c > >> @@ -22,6 +22,7 @@ > >> #include > >> #include > >> #include > >> +#include > >> #include > >> #include > >> #include > >> @@ -1007,8 +1008,33 @@ static void i2c_hid_fwnode_probe(struct i2c_client *client, > >> pdata->post_power_delay_ms = val; > >> } > >> > >> -static int i2c_hid_probe(struct i2c_client *client, > >> - const struct i2c_device_id *dev_id) > >> +static int i2c_hid_power_up_device(struct i2c_hid_platform_data *pdata) > >> +{ > >> + struct i2c_hid *ihid = container_of(pdata, struct i2c_hid, pdata); > >> + struct hid_device *hid = ihid->hid; > >> + int ret; > >> + > >> + ret = regulator_bulk_enable(ARRAY_SIZE(pdata->supplies), > >> + pdata->supplies); > >> + if (ret) { > >> + if (hid) > >> + hid_warn(hid, "Failed to enable supplies: %d\n", ret); > >> + return ret; > >> + } > >> + > >> + if (pdata->post_power_delay_ms) > >> + msleep(pdata->post_power_delay_ms); > >> + > >> + return 0; > >> +} > >> + > >> +static void i2c_hid_power_down_device(struct i2c_hid_platform_data *pdata) > >> +{ > >> + regulator_bulk_disable(ARRAY_SIZE(pdata->supplies), pdata->supplies); > >> +} > >> + > >> +int i2c_hid_probe(struct i2c_client *client, > >> + const struct i2c_device_id *dev_id) > >> { > >> int ret; > >> struct i2c_hid *ihid; > >> @@ -1035,6 +1061,9 @@ static int i2c_hid_probe(struct i2c_client *client, > >> if (!ihid) > >> return -ENOMEM; > >> > >> + if (platform_data) > >> + ihid->pdata = *platform_data; > >> + > >> if (client->dev.of_node) { > >> ret = i2c_hid_of_probe(client, &ihid->pdata); > >> if (ret) > >> @@ -1043,13 +1072,16 @@ static int i2c_hid_probe(struct i2c_client *client, > >> ret = i2c_hid_acpi_pdata(client, &ihid->pdata); > >> if (ret) > >> return ret; > >> - } else { > >> - ihid->pdata = *platform_data; > >> } > >> > >> /* Parse platform agnostic common properties from ACPI / device tree */ > >> i2c_hid_fwnode_probe(client, &ihid->pdata); > >> > >> + if (!ihid->pdata.power_up_device) > >> + ihid->pdata.power_up_device = i2c_hid_power_up_device; > >> + if (!ihid->pdata.power_down_device) > >> + ihid->pdata.power_down_device = i2c_hid_power_down_device; > >> + > >> ihid->pdata.supplies[0].supply = "vdd"; > >> ihid->pdata.supplies[1].supply = "vddl"; > >> > >> @@ -1059,14 +1091,10 @@ static int i2c_hid_probe(struct i2c_client *client, > >> if (ret) > >> return ret; > >> > >> - ret = regulator_bulk_enable(ARRAY_SIZE(ihid->pdata.supplies), > >> - ihid->pdata.supplies); > >> - if (ret < 0) > >> + ret = ihid->pdata.power_up_device(&ihid->pdata); > >> + if (ret) > > > > This is an odd driver structure IMO. I guess platform data is already > > there, but that's not what we'd use for any new driver. > > > > Why not export i2c_hid_probe, i2c_hid_remove, etc. and then just call > > them from the goodix driver and possibly make it handle all DT > > platforms? > > > > Who else needs regulators besides DT platforms? I thought with ACPI > > it's all wonderfully abstracted away? > > Right with ACPI we do not need the regulators, actually not checking > for them with ACPI would be preferable, if only to suppress kernel > messages like these: > > [ 3.515658] i2c_hid i2c-SYNA8007:00: supply vdd not found, using dummy regulator > [ 3.515848] i2c_hid i2c-SYNA8007:00: supply vddl not found, using dummy regulator > > To be fair the i2c-hid-core.c code does have some acpi specific handling too. > > With the latest fixes from: > https://git.kernel.org/pub/scm/linux/kernel/git/hid/hid.git/log/?h=for-5.10/upstream-fixes > taken into account we have the following acpi specific functions being called > from various places: > > i2c_hid_acpi_fix_up_power (called on probe) > i2c_hid_acpi_enable_wakeup (called on probe) > i2c_hid_acpi_shutdown (called on shutdown) > > Not I'm not Benjamin / not the MAINTAINER of this code, but I think that > splitting out both the ACPI *and* the of/dt handling might make sense. Yep, fully agree. > > Maybe even turn drivers/hid/i2c-hid/i2c-hid-core.c into a library > and have 2 separate: > > drivers/hid/i2c-hid/i2c-hid-acpi.c > drivers/hid/i2c-hid/i2c-hid-of.c > > drivers using that library. > > That would change the kernel-module name, but there only is the debug > module parameter which is affected by that from a userspace API point > of break, so I think that changing the kernel-module name is fine. Ack, this is a small downside compared to a better extensibility of the driver. Also, we could then delete entirely the platform_data as the register of the hid_descriptor_address could simply be added as an argument to i2c_hid_probe. Though that would force me to rewrite my testing patch with custom i2c-hid devices over an USB<->I2C adapter. > > So you would have 2 i2c drivers, one with an acpi_match_table and one > with an of_match_table. And then either also have 2 separate probe > functions, or have a probe helper which gets passed some platform_data > given by the acpi/of probe function + some extra callbacks (either > as extra arguments or inside the pdata). > > Having a separate drivers/hid/i2c-hid/i2c-hid-of.c file also allows > for a separate MAINTAINER entry where someone else then Benjamin > becomes responsible for reviewing DT related changes... I like that :) > > Anyways just my 2 cents, it is probably wise to wait what Benjamin > has to say before sinking time in implementing my suggestion :) I also want to say that I like the general idea of Doug's patch. Having a separate driver that handles the specific use case of goodix is really nice, as it allows to just load this driver without touching the core of i2c-hid. I believe this is in line with what Google tries to do with their kernel that OEMs can not touch, but only add overlays to it. The implementation is not polished (I don't think this new driver belongs to the input subsystem), but I like the general idea of having the "subclassing". Maybe we can make it prettier with Hans' suggestion, given that this mainly means we are transforming i2c-hid-core.c into a library. As for where this new goodix driver goes, it can stay in drivers/hid/i2c-hid IMO. Cheers, Benjamin