lkml.org 
[lkml]   [2020]   [Nov]   [2]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
From
Date
SubjectRe: [PATCH v3 2/3] HID: i2c-hid: Allow subclasses of i2c-hid for power sequencing
On Mon, Nov 2, 2020 at 6:13 PM Douglas Anderson <dianders@chromium.org> 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 <dianders@chromium.org>
> ---
>
> 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 <linux/i2c.h>
> #include <linux/interrupt.h>
> #include <linux/input.h>
> +#include <linux/input/i2c-hid-core.h>
> #include <linux/irq.h>
> #include <linux/delay.h>
> #include <linux/slab.h>
> @@ -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

\
 
 \ /
  Last update: 2020-11-03 02:47    [W:0.064 / U:1.128 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site