linux-input.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v3 1/2] input: adp5589: Add default platform data
@ 2019-10-31  9:03 Alexandru Ardelean
  2019-10-31  9:03 ` [PATCH v3 2/2] input: adp5589: Add basic devicetree support Alexandru Ardelean
  2019-12-05  8:16 ` [PATCH v3 1/2] input: adp5589: Add default platform data Ardelean, Alexandru
  0 siblings, 2 replies; 3+ messages in thread
From: Alexandru Ardelean @ 2019-10-31  9:03 UTC (permalink / raw)
  To: linux-input, linux-kernel; +Cc: dmitry.torokhov, lars, Alexandru Ardelean

From: Lars-Peter Clausen <lars@metafoo.de>

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 <lars@metafoo.de>
Signed-off-by: Alexandru Ardelean <alexandru.ardelean@analog.com>
---

Changelog v2 -> v3:
* fix `-Wpointer-to-int-cast` warnings for patch `input: adp5589: Add basic
  devicetree support` ; warnings shows up on 64 bit ARCHs

Changelog v1 -> v2:
* adjusted patch `input: adp5589: Add default platform data` by
  introducting a `adp5589_kpad_pdata_get()` helper, which returns the
  platform-data; the previos patch was based on an older version of the
  kernel from the ADI kernel-tree; the driver was sync-ed with the upstream
  version

 drivers/input/keyboard/adp5589-keys.c | 36 +++++++++++++++++++--------
 1 file changed, 26 insertions(+), 10 deletions(-)

diff --git a/drivers/input/keyboard/adp5589-keys.c b/drivers/input/keyboard/adp5589-keys.c
index e7d58e7f0257..c6a801bcdf90 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;
 
@@ -553,7 +573,8 @@ static int adp5589_gpio_add(struct adp5589_kpad *kpad)
 static void adp5589_gpio_remove(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 error;
 
@@ -656,7 +677,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;
@@ -861,7 +882,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;
@@ -992,7 +1013,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;
 
@@ -1002,11 +1023,6 @@ static int adp5589_probe(struct i2c_client *client,
 		return -EIO;
 	}
 
-	if (!pdata) {
-		dev_err(&client->dev, "no platform data?\n");
-		return -EINVAL;
-	}
-
 	kpad = kzalloc(sizeof(*kpad), GFP_KERNEL);
 	if (!kpad)
 		return -ENOMEM;
-- 
2.20.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [PATCH v3 2/2] input: adp5589: Add basic devicetree support
  2019-10-31  9:03 [PATCH v3 1/2] input: adp5589: Add default platform data Alexandru Ardelean
@ 2019-10-31  9:03 ` Alexandru Ardelean
  2019-12-05  8:16 ` [PATCH v3 1/2] input: adp5589: Add default platform data Ardelean, Alexandru
  1 sibling, 0 replies; 3+ messages in thread
From: Alexandru Ardelean @ 2019-10-31  9:03 UTC (permalink / raw)
  To: linux-input, linux-kernel; +Cc: dmitry.torokhov, lars, Alexandru Ardelean

From: Lars-Peter Clausen <lars@metafoo.de>

Add very basic devicetree suppport to the adp5589 allowing the device to be
registered from devicetree.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
Signed-off-by: Alexandru Ardelean <alexandru.ardelean@analog.com>
---

Changelog v2 -> v3:
* fix `-Wpointer-to-int-cast` warnings for patch `input: adp5589: Add basic
  devicetree support` ; warnings shows up on 64 bit ARCHs

Changelog v1 -> v2:
* adjusted patch `input: adp5589: Add default platform data` by
  introducting a `adp5589_kpad_pdata_get()` helper, which returns the
  platform-data; the previos patch was based on an older version of the
  kernel from the ADI kernel-tree; the driver was sync-ed with the upstream
  version

 drivers/input/keyboard/adp5589-keys.c | 33 ++++++++++++++++++++++++++-
 1 file changed, 32 insertions(+), 1 deletion(-)

diff --git a/drivers/input/keyboard/adp5589-keys.c b/drivers/input/keyboard/adp5589-keys.c
index c6a801bcdf90..56f4ff7fa9c3 100644
--- a/drivers/input/keyboard/adp5589-keys.c
+++ b/drivers/input/keyboard/adp5589-keys.c
@@ -1008,6 +1008,25 @@ static void adp5589_keypad_remove(struct adp5589_kpad *kpad)
 	}
 }
 
+static int adp5589_i2c_get_driver_data(struct i2c_client *i2c,
+				       const struct i2c_device_id *id)
+{
+	const struct of_device_id *match;
+
+	if (id)
+		return id->driver_data;
+
+	if (!IS_ENABLED(CONFIG_OF) || !i2c->dev.of_node)
+		return -ENODEV;
+
+	match = of_match_node(i2c->dev.driver->of_match_table,
+			      i2c->dev.of_node);
+	if (match)
+		return (uintptr_t)match->data;
+
+	return -ENODEV;
+}
+
 static int adp5589_probe(struct i2c_client *client,
 			 const struct i2c_device_id *id)
 {
@@ -1029,7 +1048,11 @@ static int adp5589_probe(struct i2c_client *client,
 
 	kpad->client = client;
 
-	switch (id->driver_data) {
+	ret = adp5589_i2c_get_driver_data(client, id);
+	if (ret < 0)
+		return ret;
+
+	switch (ret) {
 	case ADP5585_02:
 		kpad->support_row5 = true;
 		/* fall through */
@@ -1129,6 +1152,13 @@ static int 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 = (void *)ADP5585_01 },
+	{ .compatible = "adi,adp5585-02", .data = (void *)ADP5585_02 },
+	{ .compatible = "adi,adp5589", .data = (void *)ADP5589 },
+	{}
+};
+
 static const struct i2c_device_id adp5589_id[] = {
 	{"adp5589-keys", ADP5589},
 	{"adp5585-keys", ADP5585_01},
@@ -1142,6 +1172,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,
 	.remove = adp5589_remove,
-- 
2.20.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH v3 1/2] input: adp5589: Add default platform data
  2019-10-31  9:03 [PATCH v3 1/2] input: adp5589: Add default platform data Alexandru Ardelean
  2019-10-31  9:03 ` [PATCH v3 2/2] input: adp5589: Add basic devicetree support Alexandru Ardelean
@ 2019-12-05  8:16 ` Ardelean, Alexandru
  1 sibling, 0 replies; 3+ messages in thread
From: Ardelean, Alexandru @ 2019-12-05  8:16 UTC (permalink / raw)
  To: linux-input, linux-kernel; +Cc: dmitry.torokhov, lars

On Thu, 2019-10-31 at 11:03 +0200, Alexandru Ardelean wrote:
> From: Lars-Peter Clausen <lars@metafoo.de>
> 
> 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.
> 

ping here

> Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
> Signed-off-by: Alexandru Ardelean <alexandru.ardelean@analog.com>
> ---
> 
> Changelog v2 -> v3:
> * fix `-Wpointer-to-int-cast` warnings for patch `input: adp5589: Add
> basic
>   devicetree support` ; warnings shows up on 64 bit ARCHs
> 
> Changelog v1 -> v2:
> * adjusted patch `input: adp5589: Add default platform data` by
>   introducting a `adp5589_kpad_pdata_get()` helper, which returns the
>   platform-data; the previos patch was based on an older version of the
>   kernel from the ADI kernel-tree; the driver was sync-ed with the
> upstream
>   version
> 
>  drivers/input/keyboard/adp5589-keys.c | 36 +++++++++++++++++++--------
>  1 file changed, 26 insertions(+), 10 deletions(-)
> 
> diff --git a/drivers/input/keyboard/adp5589-keys.c
> b/drivers/input/keyboard/adp5589-keys.c
> index e7d58e7f0257..c6a801bcdf90 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;
>  
> @@ -553,7 +573,8 @@ static int adp5589_gpio_add(struct adp5589_kpad
> *kpad)
>  static void adp5589_gpio_remove(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 error;
>  
> @@ -656,7 +677,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;
> @@ -861,7 +882,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;
> @@ -992,7 +1013,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;
>  
> @@ -1002,11 +1023,6 @@ static int adp5589_probe(struct i2c_client
> *client,
>  		return -EIO;
>  	}
>  
> -	if (!pdata) {
> -		dev_err(&client->dev, "no platform data?\n");
> -		return -EINVAL;
> -	}
> -
>  	kpad = kzalloc(sizeof(*kpad), GFP_KERNEL);
>  	if (!kpad)
>  		return -ENOMEM;

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2019-12-05  8:16 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-10-31  9:03 [PATCH v3 1/2] input: adp5589: Add default platform data Alexandru Ardelean
2019-10-31  9:03 ` [PATCH v3 2/2] input: adp5589: Add basic devicetree support Alexandru Ardelean
2019-12-05  8:16 ` [PATCH v3 1/2] input: adp5589: Add default platform data Ardelean, Alexandru

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).