Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp175362pxb; Mon, 2 Nov 2020 17:50:50 -0800 (PST) X-Google-Smtp-Source: ABdhPJys0DvN+ExfeTu/ZisRjSWd6DqmvtW03dS6jj9nDWDKt9YZVSM63w6UcAeKiiszs0F+Oml0 X-Received: by 2002:a05:6402:17b4:: with SMTP id j20mr7654727edy.24.1604368250354; Mon, 02 Nov 2020 17:50:50 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1604368250; cv=none; d=google.com; s=arc-20160816; b=BiLfbmozuygZDyFmr1mEcEM6+Jvx9brsTBtzBazhK/kWT1H8Q7vR8wbuIuq8rW8D4k Mj0PGTYFIokk+Vdob+uPV4CYJONFc7WAgxRrh+xg1HAZSPQnEbtMdkEupOwTbt4HEM5n NlHb8K/GeCmgZQwGdhOveXa7N0y8p/6b+tfaAPFwfs1UI90kIHKSQfkcCve5QW43lyql 9TbRup5N1l4NZsRbXOYi0FuR5ZJZjQL8PiKVpZtD2BfsEQ9Fm8j+IVABkraJhyPfnkaH FPhlQodH8UmPihmkDtKkLAV2hkGM5wEn9+u9n2VB2wgBXESdZkTS2Nltkuc0hE3+nrrA IztQ== 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=G6Lx+jdRZ/feRnk/hCh17jXK7aLZFjMwJ0eK0cy7Mx4=; b=MGjsaYvVd2E6xcS5tnCMxWID2ecgM5wgTMKlche9q+TG5e2DzUdX8D+iYGxD/WxKnw EKO9HWL5O0Gjq6I7z2uB5qX4Ws4Pbw0E9nO8sIB80xRLs0tXJGFUyZuvQdn2kp2cRt1D k5x20mB3X5ULRYYePtkabOqpF5rsgMum/eNQKA8Nb56IWZyMO8bGHVeKIqEbr7rNMLRD snQDdkzP3XzHGDjS0N5M70EPFGyvsx5+QQIsWNrpQHvja2uwCDJyt9xiqr9s2j9LWiCY Rn4PB9jTZ/8iXcFMrT9d+hlntj7dmyO03ZF4dG1QvzngVmR+wEUU3qe9uzeS8pK5NJZn ja8w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=bgHBPpOS; 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=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id b6si13085739ejb.204.2020.11.02.17.50.28; Mon, 02 Nov 2020 17:50:50 -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=@kernel.org header.s=default header.b=bgHBPpOS; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726447AbgKCBqr (ORCPT + 99 others); Mon, 2 Nov 2020 20:46:47 -0500 Received: from mail.kernel.org ([198.145.29.99]:48922 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726026AbgKCBqr (ORCPT ); Mon, 2 Nov 2020 20:46:47 -0500 Received: from mail-oi1-f172.google.com (mail-oi1-f172.google.com [209.85.167.172]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 1471F2225E; Tue, 3 Nov 2020 01:46:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1604368006; bh=lFAmU5IXg1kHYasHCHzUpOggTZlRW+fdNCnl96GoreI=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=bgHBPpOSrIR8Way5hq4iemLrDf0Z69MedsvnQgedXMg2vtcw+iAox1yZUTrQLWTvU MYN++J3X3Ab6gb9NQL0dL4W4VRysUtEaSrfgzNakmR9SKUK1uIZ/fO20JpQfTLtrXM d9rrlnuHz+Lwv5F03R+K1VZ0aVi1YPMmpgbqj3BU= Received: by mail-oi1-f172.google.com with SMTP id u127so16782481oib.6; Mon, 02 Nov 2020 17:46:46 -0800 (PST) X-Gm-Message-State: AOAM5332xzfECIkBemzElGnd2wjOG3kvP3jt/87o6lHOOGsks8AmfPeX Mv+mudC0PD/Aq7NC4syhUHLhQBMacFcMmTWjmw== X-Received: by 2002:a54:4588:: with SMTP id z8mr622587oib.147.1604368005136; Mon, 02 Nov 2020 17:46:45 -0800 (PST) MIME-Version: 1.0 References: <20201102161210.v3.1.Ibb28033c81d87fcc13a6ba28c6ea7ac154d65f93@changeid> <20201102161210.v3.2.Ied4ce10d229cd7c69abf13a0361ba0b8d82eb9c4@changeid> In-Reply-To: <20201102161210.v3.2.Ied4ce10d229cd7c69abf13a0361ba0b8d82eb9c4@changeid> From: Rob Herring Date: Mon, 2 Nov 2020 19:46:34 -0600 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH v3 2/3] HID: i2c-hid: Allow subclasses of i2c-hid for power sequencing To: Douglas Anderson Cc: Jiri Kosina , Benjamin Tissoires , Greg Kroah-Hartman , Dmitry Torokhov , Linux Input , Hans de Goede , 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 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? Rob