diff mbox series

[v1,3/3] Input: ili210x - optionally hide calibrate sysfs attribute

Message ID 20191112164429.11225-3-TheSven73@gmail.com (mailing list archive)
State New, archived
Delegated to: Dmitry Torokhov
Headers show
Series [v1,1/3] Input: ili210x - do not retrieve/print chip firmware version | expand

Commit Message

Sven Van Asbroeck Nov. 12, 2019, 4:44 p.m. UTC
Only show the 'calibrate' sysfs attribute on chip flavours
which support calibration by writing to a calibration register.

Do this by adding a flag to the chip operations structure.

Link: https://lore.kernel.org/lkml/20191111181657.GA57214@dtor-ws/
Cc: Marek Vasut <marex@denx.de>
Cc: Adam Ford <aford173@gmail.com>
Cc: <linux-kernel@vger.kernel.org>
Cc: linux-input@vger.kernel.org
Tree: https://git.kernel.org/pub/scm/linux/kernel/git/dtor/input.git/log/?h=next
Signed-off-by: Sven Van Asbroeck <TheSven73@gmail.com>
---
 drivers/input/touchscreen/ili210x.c | 13 +++++++++++++
 1 file changed, 13 insertions(+)

Comments

Dmitry Torokhov Nov. 12, 2019, 7:38 p.m. UTC | #1
On Tue, Nov 12, 2019 at 11:44:29AM -0500, Sven Van Asbroeck wrote:
> Only show the 'calibrate' sysfs attribute on chip flavours
> which support calibration by writing to a calibration register.
> 
> Do this by adding a flag to the chip operations structure.
> 
> Link: https://lore.kernel.org/lkml/20191111181657.GA57214@dtor-ws/
> Cc: Marek Vasut <marex@denx.de>
> Cc: Adam Ford <aford173@gmail.com>
> Cc: <linux-kernel@vger.kernel.org>
> Cc: linux-input@vger.kernel.org
> Tree: https://git.kernel.org/pub/scm/linux/kernel/git/dtor/input.git/log/?h=next
> Signed-off-by: Sven Van Asbroeck <TheSven73@gmail.com>
> ---
>  drivers/input/touchscreen/ili210x.c | 13 +++++++++++++
>  1 file changed, 13 insertions(+)
> 
> diff --git a/drivers/input/touchscreen/ili210x.c b/drivers/input/touchscreen/ili210x.c
> index 4321f0d676cc..810770ad02e2 100644
> --- a/drivers/input/touchscreen/ili210x.c
> +++ b/drivers/input/touchscreen/ili210x.c
> @@ -32,6 +32,7 @@ struct ili2xxx_chip {
>  	bool (*continue_polling)(const u8 *data, bool touch);
>  	unsigned int max_touches;
>  	unsigned int resolution;
> +	bool no_calibrate_reg;

Please use positive logic and have chips opt-in into the calibration.

>  };
>  
>  struct ili210x {
> @@ -162,6 +163,7 @@ static const struct ili2xxx_chip ili211x_chip = {
>  	.continue_polling	= ili211x_decline_polling,
>  	.max_touches		= 10,
>  	.resolution		= 2048,
> +	.no_calibrate_reg	= true,
>  };
>  
>  static int ili251x_read_reg(struct i2c_client *client,
> @@ -310,8 +312,19 @@ static struct attribute *ili210x_attributes[] = {
>  	NULL,
>  };
>  
> +static umode_t ili210x_calibrate_visible(struct kobject *kobj,
> +					  struct attribute *attr, int index)
> +{
> +	struct device *dev = kobj_to_dev(kobj);
> +	struct i2c_client *client = to_i2c_client(dev);
> +	struct ili210x *priv = i2c_get_clientdata(client);
> +
> +	return !priv->chip->no_calibrate_reg;
> +}
> +
>  static const struct attribute_group ili210x_attr_group = {
>  	.attrs = ili210x_attributes,
> +	.is_visible = ili210x_calibrate_visible,
>  };
>  
>  static void ili210x_power_down(void *data)
> -- 
> 2.17.1
>
diff mbox series

Patch

diff --git a/drivers/input/touchscreen/ili210x.c b/drivers/input/touchscreen/ili210x.c
index 4321f0d676cc..810770ad02e2 100644
--- a/drivers/input/touchscreen/ili210x.c
+++ b/drivers/input/touchscreen/ili210x.c
@@ -32,6 +32,7 @@  struct ili2xxx_chip {
 	bool (*continue_polling)(const u8 *data, bool touch);
 	unsigned int max_touches;
 	unsigned int resolution;
+	bool no_calibrate_reg;
 };
 
 struct ili210x {
@@ -162,6 +163,7 @@  static const struct ili2xxx_chip ili211x_chip = {
 	.continue_polling	= ili211x_decline_polling,
 	.max_touches		= 10,
 	.resolution		= 2048,
+	.no_calibrate_reg	= true,
 };
 
 static int ili251x_read_reg(struct i2c_client *client,
@@ -310,8 +312,19 @@  static struct attribute *ili210x_attributes[] = {
 	NULL,
 };
 
+static umode_t ili210x_calibrate_visible(struct kobject *kobj,
+					  struct attribute *attr, int index)
+{
+	struct device *dev = kobj_to_dev(kobj);
+	struct i2c_client *client = to_i2c_client(dev);
+	struct ili210x *priv = i2c_get_clientdata(client);
+
+	return !priv->chip->no_calibrate_reg;
+}
+
 static const struct attribute_group ili210x_attr_group = {
 	.attrs = ili210x_attributes,
+	.is_visible = ili210x_calibrate_visible,
 };
 
 static void ili210x_power_down(void *data)