2020-11-25 01:57:01

by Alexandru Ardelean

[permalink] [raw]
Subject: [PATCH v2 1/3] Input: adp5589-keys - add default platform data

From: Lars-Peter Clausen <[email protected]>

If no platform data is supplied use a dummy platform data that configures
the device in GPIO only mode. This change adds a adp5589_kpad_pdata_get()
helper that returns the default platform-data. This can be later extended
to load configuration from device-trees or ACPI.

Signed-off-by: Lars-Peter Clausen <[email protected]>
Signed-off-by: Alexandru Ardelean <[email protected]>
---

Changelog v1 -> v2:
* rebased on newer input/next tree; a conflict appeared for this
patchset https://lore.kernel.org/r/20201119072440.GA116840@dtor-ws

drivers/input/keyboard/adp5589-keys.c | 33 +++++++++++++++++++--------
1 file changed, 24 insertions(+), 9 deletions(-)

diff --git a/drivers/input/keyboard/adp5589-keys.c b/drivers/input/keyboard/adp5589-keys.c
index e2cdf14d90cd..742bf4b97dbb 100644
--- a/drivers/input/keyboard/adp5589-keys.c
+++ b/drivers/input/keyboard/adp5589-keys.c
@@ -369,6 +369,25 @@ static const struct adp_constants const_adp5585 = {
.reg = adp5585_reg,
};

+static const struct adp5589_gpio_platform_data adp5589_default_gpio_pdata = {
+ .gpio_start = -1,
+};
+
+static const struct adp5589_kpad_platform_data adp5589_default_pdata = {
+ .gpio_data = &adp5589_default_gpio_pdata,
+};
+
+static const struct adp5589_kpad_platform_data *adp5589_kpad_pdata_get(
+ struct device *dev)
+{
+ const struct adp5589_kpad_platform_data *pdata = dev_get_platdata(dev);
+
+ if (!pdata)
+ pdata = &adp5589_default_pdata;
+
+ return pdata;
+}
+
static int adp5589_read(struct i2c_client *client, u8 reg)
{
int ret = i2c_smbus_read_byte_data(client, reg);
@@ -498,7 +517,8 @@ static int adp5589_build_gpiomap(struct adp5589_kpad *kpad,
static int adp5589_gpio_add(struct adp5589_kpad *kpad)
{
struct device *dev = &kpad->client->dev;
- const struct adp5589_kpad_platform_data *pdata = dev_get_platdata(dev);
+ const struct adp5589_kpad_platform_data *pdata =
+ adp5589_kpad_pdata_get(dev);
const struct adp5589_gpio_platform_data *gpio_data = pdata->gpio_data;
int i, error;

@@ -619,7 +639,7 @@ static int adp5589_setup(struct adp5589_kpad *kpad)
{
struct i2c_client *client = kpad->client;
const struct adp5589_kpad_platform_data *pdata =
- dev_get_platdata(&client->dev);
+ adp5589_kpad_pdata_get(&client->dev);
u8 (*reg) (u8) = kpad->var->reg;
unsigned char evt_mode1 = 0, evt_mode2 = 0, evt_mode3 = 0;
unsigned char pull_mask = 0;
@@ -824,7 +844,7 @@ static int adp5589_keypad_add(struct adp5589_kpad *kpad, unsigned int revid)
{
struct i2c_client *client = kpad->client;
const struct adp5589_kpad_platform_data *pdata =
- dev_get_platdata(&client->dev);
+ adp5589_kpad_pdata_get(&client->dev);
struct input_dev *input;
unsigned int i;
int error;
@@ -948,7 +968,7 @@ static int adp5589_probe(struct i2c_client *client,
{
struct adp5589_kpad *kpad;
const struct adp5589_kpad_platform_data *pdata =
- dev_get_platdata(&client->dev);
+ adp5589_kpad_pdata_get(&client->dev);
unsigned int revid;
int error, ret;

@@ -958,11 +978,6 @@ static int adp5589_probe(struct i2c_client *client,
return -EIO;
}

- if (!pdata) {
- dev_err(&client->dev, "no platform data?\n");
- return -EINVAL;
- }
-
kpad = devm_kzalloc(&client->dev, sizeof(*kpad), GFP_KERNEL);
if (!kpad)
return -ENOMEM;
--
2.17.1


2020-11-25 01:58:16

by Alexandru Ardelean

[permalink] [raw]
Subject: [PATCH v2 3/3] Input: adp5589-keys - add basic devicetree support

From: Lars-Peter Clausen <[email protected]>

Add very basic devicetree suppport to the adp5589 allowing the device to be
registered from devicetree and ACPI via PRP0001.

Signed-off-by: Lars-Peter Clausen <[email protected]>
Signed-off-by: Alexandru Ardelean <[email protected]>
---
drivers/input/keyboard/adp5589-keys.c | 30 ++++++++++++++++++++++++++-
1 file changed, 29 insertions(+), 1 deletion(-)

diff --git a/drivers/input/keyboard/adp5589-keys.c b/drivers/input/keyboard/adp5589-keys.c
index 6cb93ee3b97c..8ff18ff18b75 100644
--- a/drivers/input/keyboard/adp5589-keys.c
+++ b/drivers/input/keyboard/adp5589-keys.c
@@ -986,9 +986,25 @@ static void adp5589_clear_config(void *data)
adp5589_write(client, kpad->var->reg(ADP5589_GENERAL_CFG), 0);
}

+static const struct adp5589_chip_info *adp5589_get_chip_info(struct device *dev,
+ const struct i2c_device_id *id)
+{
+ const struct adp5589_chip_info *info;
+
+ info = device_get_match_data(dev);
+ if (info)
+ return info;
+
+ if (id)
+ return &adp5589_chip_info_tbl[id->driver_data];
+
+ return NULL;
+}
+
static int adp5589_probe(struct i2c_client *client,
const struct i2c_device_id *id)
{
+ const struct adp5589_chip_info *info;
struct adp5589_kpad *kpad;
const struct adp5589_kpad_platform_data *pdata =
adp5589_kpad_pdata_get(&client->dev);
@@ -1001,13 +1017,17 @@ static int adp5589_probe(struct i2c_client *client,
return -EIO;
}

+ info = adp5589_get_chip_info(&client->dev, id);
+ if (!info)
+ return -ENODEV;
+
kpad = devm_kzalloc(&client->dev, sizeof(*kpad), GFP_KERNEL);
if (!kpad)
return -ENOMEM;

kpad->client = client;

- kpad->info = &adp5589_chip_info_tbl[id->driver_data];
+ kpad->info = info;
kpad->var = kpad->info->constants;

error = devm_add_action_or_reset(&client->dev, adp5589_clear_config,
@@ -1078,6 +1098,13 @@ static int __maybe_unused adp5589_resume(struct device *dev)

static SIMPLE_DEV_PM_OPS(adp5589_dev_pm_ops, adp5589_suspend, adp5589_resume);

+static const struct of_device_id adp5589_of_match[] = {
+ { .compatible = "adi,adp5585", .data = &adp5589_chip_info_tbl[ADP5585_01] },
+ { .compatible = "adi,adp5585-02", .data = &adp5589_chip_info_tbl[ADP5585_02] },
+ { .compatible = "adi,adp5589", .data = &adp5589_chip_info_tbl[ADP5589] },
+ {}
+};
+
static const struct i2c_device_id adp5589_id[] = {
{"adp5589-keys", ADP5589},
{"adp5585-keys", ADP5585_01},
@@ -1091,6 +1118,7 @@ static struct i2c_driver adp5589_driver = {
.driver = {
.name = KBUILD_MODNAME,
.pm = &adp5589_dev_pm_ops,
+ .of_match_table = adp5589_of_match,
},
.probe = adp5589_probe,
.id_table = adp5589_id,
--
2.17.1

2020-11-25 01:59:10

by Lars-Peter Clausen

[permalink] [raw]
Subject: Re: [PATCH v2 3/3] Input: adp5589-keys - add basic devicetree support

On 11/24/20 9:22 AM, Alexandru Ardelean wrote:
> error = devm_add_action_or_reset(&client->dev, adp5589_clear_config,
> @@ -1078,6 +1098,13 @@ static int __maybe_unused adp5589_resume(struct device *dev)
>
> static SIMPLE_DEV_PM_OPS(adp5589_dev_pm_ops, adp5589_suspend, adp5589_resume);
>
> +static const struct of_device_id adp5589_of_match[] = {
> + { .compatible = "adi,adp5585", .data = &adp5589_chip_info_tbl[ADP5585_01] },
> + { .compatible = "adi,adp5585-02", .data = &adp5589_chip_info_tbl[ADP5585_02] },
> + { .compatible = "adi,adp5589", .data = &adp5589_chip_info_tbl[ADP5589] },

I think we need to add these to
Documentation/devicetree/bindings/trivial-devices.yaml


2020-11-25 05:32:21

by Alexandru Ardelean

[permalink] [raw]
Subject: RE: [PATCH v2 3/3] Input: adp5589-keys - add basic devicetree support



> -----Original Message-----
> From: Lars-Peter Clausen <[email protected]>
> Sent: Tuesday, November 24, 2020 10:43 AM
> To: Ardelean, Alexandru <[email protected]>; linux-
> [email protected]; [email protected]
> Cc: [email protected]
> Subject: Re: [PATCH v2 3/3] Input: adp5589-keys - add basic devicetree support
>
> [External]
>
> On 11/24/20 9:22 AM, Alexandru Ardelean wrote:
> > error = devm_add_action_or_reset(&client->dev,
> > adp5589_clear_config, @@ -1078,6 +1098,13 @@ static int __maybe_unused
> > adp5589_resume(struct device *dev)
> >
> > static SIMPLE_DEV_PM_OPS(adp5589_dev_pm_ops, adp5589_suspend,
> > adp5589_resume);
> >
> > +static const struct of_device_id adp5589_of_match[] = {
> > + { .compatible = "adi,adp5585", .data =
> &adp5589_chip_info_tbl[ADP5585_01] },
> > + { .compatible = "adi,adp5585-02", .data =
> &adp5589_chip_info_tbl[ADP5585_02] },
> > + { .compatible = "adi,adp5589", .data =
> > +&adp5589_chip_info_tbl[ADP5589] },
>
> I think we need to add these to
> Documentation/devicetree/bindings/trivial-devices.yaml
>

Ack
Will send a V3 in the next few days.