diff mbox series

[v3,1/4] Input: adp5589-keys - add default platform data

Message ID 20201127111420.96500-1-alexandru.ardelean@analog.com
State New
Headers show
Series [v3,1/4] Input: adp5589-keys - add default platform data | expand

Commit Message

Alexandru Ardelean Nov. 27, 2020, 11:14 a.m. UTC
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:
* https://lore.kernel.org/linux-input/20201124082255.13427-1-alexandru.ardelean@analog.com/
* added patch 'dt-bindings: add ADP5585/ADP5589 entries to trivial-devices'

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

Comments

Alexandru Ardelean Dec. 9, 2020, 7:01 a.m. UTC | #1
> -----Original Message-----

> From: Alexandru Ardelean <alexandru.ardelean@analog.com>

> Sent: Friday, November 27, 2020 1:14 PM

> To: linux-input@vger.kernel.org; linux-kernel@vger.kernel.org;

> devicetree@vger.kernel.org

> Cc: lars@metafoo.de; dmitry.torokhov@gmail.com; robh+dt@kernel.org;

> Ardelean, Alexandru <alexandru.Ardelean@analog.com>

> Subject: [PATCH v3 1/4] Input: adp5589-keys - add default platform data

> 

> 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 on this for the input subsystem.
Since patch 4 was applied by Rob, maybe for input, only the first 3 should be applied.
Or, should I re-send just the first 3?

Thanks
Alex

> Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>

> Signed-off-by: Alexandru Ardelean <alexandru.ardelean@analog.com>

> ---

> 

> Changelog v2 - v3:

> * https://lore.kernel.org/linux-input/20201124082255.13427-1-

> alexandru.ardelean@analog.com/

> * added patch 'dt-bindings: add ADP5585/ADP5589 entries to trivial-devices'

> 

>  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.27.0
Dmitry Torokhov Dec. 10, 2020, 7:20 a.m. UTC | #2
Hi Alexandru, Lars-Peter,

On Fri, Nov 27, 2020 at 01:14:17PM +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.


I was looking at this and I do not think it is a good idea, as later we
will need to add negation if someone does nor want use GPIO mode. We
should use the standard "gpio-controller" property from the beginning.

Thanks.

-- 
Dmitry
diff mbox series

Patch

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;