Add device tree support to the cyttsp driver
Subsystems (4)
v5 cover Add device tree support to the cyttsp driver
Implement a number of updates for the cyttsp driver to be able to parse generic ACPI/of/static properties and drop support for platform data (no platform data user is present in the kernel tree).
---
Changes in v5:
Use custom devm action to turn off the chip
Make reset gpio and touchscreen size properties optional
Changes in v4:
Major rework based on Dmitry's review:
- Use device_property_read() functions instead of of_property()
- Use touchscreen_parse_properties to parse common properties
- Drop support for platform data
- Used devres managed allocations
Changes in v3:
- Rework binding names and descriptions
Changes in v2:
- Fix err_cast.cocci warning in patch 2/3
Oreste Salerno (4):
Input: cyttsp - use devres managed resource allocations
Input: cyttsp - check return value of input_mt_init_slots
Input: cyttsp - switch to using device properties
Input: cyttsp - perform hard reset of the chip during probe
.../bindings/input/touchscreen/cyttsp.txt | 95 ++++++++++ drivers/input/touchscreen/cyttsp_core.c | 193 +++++++++++++-------- drivers/input/touchscreen/cyttsp_core.h | 10 +- drivers/input/touchscreen/cyttsp_i2c.c | 10 -- drivers/input/touchscreen/cyttsp_spi.c | 10 -- include/linux/input/cyttsp.h | 15 -- 6 files changed, 228 insertions(+), 105 deletions(-) create mode 100644 Documentation/devicetree/bindings/input/touchscreen/cyttsp.txt
Signature · 6 lines
1.9.1 -- To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
PATCH v5 1/4 Input: cyttsp - use devres managed resource allocations
Use devm_() functions for allocating memory, input device and IRQ.
--- drivers/input/touchscreen/cyttsp_core.c | 65 ++++++++++++++------------------- drivers/input/touchscreen/cyttsp_core.h | 1 - drivers/input/touchscreen/cyttsp_i2c.c | 10 ----- drivers/input/touchscreen/cyttsp_spi.c | 10 ----- 4 files changed, 27 insertions(+), 59 deletions(-)
drivers/input/touchscreen/cyttsp_core.c +27 -38
@@ -528,6 +528,14 @@ static void cyttsp_close(struct input_dev *dev)cyttsp_disable (ts); } +static void cyttsp_platform_exit (void *data) +{ +struct cyttsp *ts = data; + +if (ts->pdata->exit) + ts->pdata->exit (); +} +struct cyttsp *cyttsp_probe (const struct cyttsp_bus_ops *bus_ops,struct device *dev,int irq,size_t xfer_buf_size) {
@@ -536,17 +544,13 @@ struct cyttsp *cyttsp_probe(const struct cyttsp_bus_ops *bus_ops,struct input_dev *input_dev;int error; -if (!pdata || !pdata->name || irq <=0 ) { - error = -EINVAL ; - goto err_out; - } +if (!pdata || !pdata->name || irq <=0 ) +return ERR_PTR (-EINVAL ); - ts =kzalloc (sizeof (*ts) + xfer_buf_size,GFP_KERNEL ); - input_dev =input_allocate_device (); -if (!ts || !input_dev) { - error = -ENOMEM ; - goto err_free_mem; - } + ts =devm_kzalloc (dev,sizeof (*ts) + xfer_buf_size,GFP_KERNEL ); + input_dev =devm_input_allocate_device (dev); +if (!ts || !input_dev) +return ERR_PTR (-ENOMEM ); ts->dev = dev; ts->input = input_dev;
@@ -557,12 +561,18 @@ struct cyttsp *cyttsp_probe(const struct cyttsp_bus_ops *bus_ops,init_completion (&ts->bl_ready);snprintf (ts->phys,sizeof (ts->phys),"%s/input0" ,dev_name (dev)); + error =devm_add_action (dev, cyttsp_platform_exit, ts); +if (error) { +dev_err (dev,"failed to install exit action: %d\n" , error); +return ERR_PTR (error); + } +if (pdata->init) { error = pdata->init ();if (error) {dev_err (ts->dev,"platform init failed, err: %d\n" , error); - goto err_free_mem; +return ERR_PTR (error); } }
@@ -586,53 +596,32 @@ struct cyttsp *cyttsp_probe(const struct cyttsp_bus_ops *bus_ops,input_mt_init_slots (input_dev,CY_MAX_ID ,0 ); - error =request_threaded_irq (ts->irq,NULL , cyttsp_irq, -IRQF_TRIGGER_FALLING |IRQF_ONESHOT , - pdata->name, ts); + error =devm_request_threaded_irq (dev, ts->irq,NULL , cyttsp_irq, +IRQF_TRIGGER_FALLING |IRQF_ONESHOT , + pdata->name, ts);if (error) {dev_err (ts->dev,"failed to request IRQ %d, err: %d\n" , ts->irq, error); - goto err_platform_exit; +return ERR_PTR (error); }disable_irq (ts->irq); error =cyttsp_power_on (ts);if (error) - goto err_free_irq; +return ERR_PTR (error); error =input_register_device (input_dev);if (error) {dev_err (ts->dev,"failed to register input device: %d\n" , error); - goto err_free_irq; +return ERR_PTR (error); }return ts; - -err_free_irq: -free_irq (ts->irq, ts); -err_platform_exit: -if (pdata->exit) - pdata->exit (); -err_free_mem: -input_free_device (input_dev); -kfree (ts); -err_out: -return ERR_PTR (error); }EXPORT_SYMBOL_GPL (cyttsp_probe); -void cyttsp_remove (struct cyttsp *ts) -{ -free_irq (ts->irq, ts); -input_unregister_device (ts->input); -if (ts->pdata->exit) - ts->pdata->exit (); -kfree (ts); -} -EXPORT_SYMBOL_GPL (cyttsp_remove); -MODULE_LICENSE ("GPL" );MODULE_DESCRIPTION ("Cypress TrueTouch(R) Standard touchscreen driver core" );MODULE_AUTHOR ("Cypress" );
drivers/input/touchscreen/cyttsp_core.h +0 -1
@@ -143,7 +143,6 @@ struct cyttsp {struct cyttsp *cyttsp_probe (const struct cyttsp_bus_ops *bus_ops,struct device *dev,int irq,size_t xfer_buf_size); -void cyttsp_remove (struct cyttsp *ts);int cyttsp_i2c_write_block_data (struct device *dev,u8 *xfer_buf,u16 addr,u8 length,const void *values);
drivers/input/touchscreen/cyttsp_i2c.c +0 -10
@@ -56,15 +56,6 @@ static int cyttsp_i2c_probe(struct i2c_client *client,return 0 ; } -static int cyttsp_i2c_remove (struct i2c_client *client) -{ -struct cyttsp *ts =i2c_get_clientdata (client); - -cyttsp_remove (ts); - -return 0 ; -} -static const struct i2c_device_id cyttsp_i2c_id[] = { {CY_I2C_NAME ,0 }, { }
@@ -77,7 +68,6 @@ static struct i2c_driver cyttsp_i2c_driver = { .pm = &cyttsp_pm_ops, }, .probe = cyttsp_i2c_probe, - .remove = cyttsp_i2c_remove, .id_table = cyttsp_i2c_id, };
drivers/input/touchscreen/cyttsp_spi.c +0 -10
@@ -170,22 +170,12 @@ static int cyttsp_spi_probe(struct spi_device *spi)return 0 ; } -static int cyttsp_spi_remove (struct spi_device *spi) -{ -struct cyttsp *ts =spi_get_drvdata (spi); - -cyttsp_remove (ts); - -return 0 ; -} -static struct spi_driver cyttsp_spi_driver = { .driver = { .name =CY_SPI_NAME , .pm = &cyttsp_pm_ops, }, .probe = cyttsp_spi_probe, - .remove = cyttsp_spi_remove, };module_spi_driver (cyttsp_spi_driver);
Signature · 6 lines
1.9.1 -- To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
PATCH v5 2/4 Input: cyttsp - check return value of input_mt_init_slots
In reply to Oreste Salerno--- drivers/input/touchscreen/cyttsp_core.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
drivers/input/touchscreen/cyttsp_core.c +5 -1
@@ -594,7 +594,11 @@ struct cyttsp *cyttsp_probe(const struct cyttsp_bus_ops *bus_ops,input_set_abs_params (input_dev,ABS_MT_TOUCH_MAJOR ,0 ,CY_MAXZ ,0 ,0 ); -input_mt_init_slots (input_dev,CY_MAX_ID ,0 ); + error =input_mt_init_slots (input_dev,CY_MAX_ID ,0 ); +if (error) { +dev_err (dev,"Unable to init MT slots.\n" ); +return ERR_PTR (error); + } error = devm_request_threaded_irq(dev, ts->irq, NULL, cyttsp_irq, IRQF_TRIGGER_FALLING | IRQF_ONESHOT,
Signature · 1 line
1.9.1
PATCH v5 3/4 Input: cyttsp - switch to using device properties
In reply to Oreste SalernoDrop support for platform data passed via a C-structure and switch to device properties instead, which should make the driver compatible with all platforms: OF, ACPI and static boards. Static boards should use property sets to communicate device parameters to the driver.
--- .../bindings/input/touchscreen/cyttsp.txt | 95 ++++++++++++++ drivers/input/touchscreen/cyttsp_core.c | 136 ++++++++++++++------- drivers/input/touchscreen/cyttsp_core.h | 9 +- include/linux/input/cyttsp.h | 15 --- 4 files changed, 197 insertions(+), 58 deletions(-) create mode 100644 Documentation/devicetree/bindings/input/touchscreen/cyttsp.txt
Documentation/devicetree/bindings/input/touchscreen/cyttsp.txt new file +95 -0
@@ -0,0 +1,95 @@ +* Cypress cyttsp touchscreen controller + +Required properties: + - compatible : must be "cypress,cyttsp-i2c" or "cypress,cyttsp-spi" + - reg : Device I2C address or SPI chip select number + - spi-max-frequency : Maximum SPI clocking speed of the device (for cyttsp-spi) + - interrupt-parent : the phandle for the gpio controller + (see interrupt binding[0]). + - interrupts : (gpio) interrupt to which the chip is connected + (see interrupt binding[0]). + - bootloader-key : the 8-byte bootloader key that is required to switch + the chip from bootloader mode (default mode) to + application mode. + This property has to be specified as an array of 8 + '/bits/ 8' values. + +Optional properties: + - reset-gpios : the reset gpio the chip is connected to + (see GPIO binding[1] for more details). + - touchscreen-size-x : horizontal resolution of touchscreen (in pixels) + - touchscreen-size-y : vertical resolution of touchscreen (in pixels) + - touchscreen-fuzz-x : horizontal noise value of the absolute input device + (in pixels) + - touchscreen-fuzz-y : vertical noise value of the absolute input device + (in pixels) + - active-distance : the distance in pixels beyond which a touch must move + before movement is detected and reported by the device. + Valid values: 0-15. + - active-interval-ms : the minimum period in ms between consecutive + scanning/processing cycles when the chip is in active mode. + Valid values: 0-255. + - lowpower-interval-ms : the minimum period in ms between consecutive + scanning/processing cycles when the chip is in low-power mode. + Valid values: 0-2550 + - touch-timeout-ms : minimum time in ms spent in the active power state while no + touches are detected before entering low-power mode. + Valid values: 0-2550 + - use-handshake : enable register-based handshake (boolean). This should + only be used if the chip is configured to use 'blocking + communication with timeout' (in this case the device + generates an interrupt at the end of every + scanning/processing cycle). + +[0]: Documentation/devicetree/bindings/interrupt-controller/interrupts.txt +[1]: Documentation/devicetree/bindings/gpio/gpio.txt + +Example: + &i2c1 { + /* ... */ + cyttsp@a { + compatible = "cypress,cyttsp-i2c"; + reg = <0xa>; + interrupt-parent = <&gpio0>; + interrupts = <28 0>; + reset-gpios = <&gpio3 4 GPIO_ACTIVE_LOW>; + + touchscreen-size-x = <800>; + touchscreen-size-y = <480>; + touchscreen-fuzz-x = <4>; + touchscreen-fuzz-y = <7>; + + bootloader-key = /bits/ 8 <0x01 0x02 0x03 0x04 0x05 0x06 0x07 0x08>; + active-distance = <8>; + active-interval-ms = <0>; + lowpower-interval-ms = <200>; + touch-timeout-ms = <100>; + }; + + /* ... */ + }; + + &mcspi1 { + /* ... */ + cyttsp@0 { + compatible = "cypress,cyttsp-spi"; + spi-max-frequency = <6000000>; + reg = <0>; + interrupt-parent = <&gpio0>; + interrupts = <28 0>; + reset-gpios = <&gpio3 4 GPIO_ACTIVE_LOW>; + + touchscreen-size-x = <800>; + touchscreen-size-y = <480>; + touchscreen-fuzz-x = <4>; + touchscreen-fuzz-y = <7>; + + bootloader-key = /bits/ 8 <0x01 0x02 0x03 0x04 0x05 0x06 0x07 0x08>; + active-distance = <8>; + active-interval-ms = <0>; + lowpower-interval-ms = <200>; + touch-timeout-ms = <100>; + }; + + /* ... */ + };
drivers/input/touchscreen/cyttsp_core.c +94 -42
220 lines not on this page · raw message
drivers/input/touchscreen/cyttsp_core.h +8 -1
@@ -129,7 +129,6 @@ struct cyttsp {int irq;struct input_dev *input;char phys[32 ]; -const struct cyttsp_platform_data *pdata;const struct cyttsp_bus_ops *bus_ops;struct cyttsp_bootloader_data bl_data;struct cyttsp_sysinfo_data sysinfo_data;
@@ -138,6 +137,14 @@ struct cyttsp {enum cyttsp_state state;bool suspended; +struct gpio_desc *reset_gpio; +bool use_hndshk; +u8 act_dist; +u8 act_intrvl; +u8 tch_tmout; +u8 lp_intrvl; +u8 *bl_keys; +u8 xfer_buf[]____cacheline_aligned ; };
include/linux/input/cyttsp.h +0 -15
@@ -40,19 +40,4 @@/* Active distance in pixels for a gesture to be reported */ #define CY_ACT_DIST_DFLT 0xF8/* pixels */ -struct cyttsp_platform_data { -u32 maxx; -u32 maxy; -bool use_hndshk; -u8 act_dist;/* Active distance */ -u8 act_intrvl;/* Active refresh interval; ms */ -u8 tch_tmout;/* Active touch timeout; ms */ -u8 lp_intrvl;/* Low power refresh interval; ms */ -int (*init)(void ); -void (*exit)(void ); -char *name; -s16 irq_gpio; -u8 *bl_keys; -}; -#endif /* _CYTTSP_H_ */
Signature · 1 line
1.9.1
Re: [PATCH v5 3/4] Input: cyttsp - switch to using device properties
Quoted 8 lines · Oreste Salerno
Drop support for platform data passed via a C-structure and switch to device properties instead, which should make the driver compatible with all platforms: OF, ACPI and static boards. Static boards should use property sets to communicate device parameters to the driver.
Signed-off-by Oreste Salerno <[email protected]>--- .../bindings/input/touchscreen/cyttsp.txt | 95 ++++++++++++++
Quoted 5 lines
drivers/input/touchscreen/cyttsp_core.c | 136 ++++++++++++++------- drivers/input/touchscreen/cyttsp_core.h | 9 +- include/linux/input/cyttsp.h | 15 --- 4 files changed, 197 insertions(+), 58 deletions(-) create mode 100644 Documentation/devicetree/bindings/input/touchscreen/cyttsp.txt
PATCH v5 4/4 Input: cyttsp - perform hard reset of the chip during probe
In reply to Oreste SalernoSince we removed support for calling an init() callback from the platform data, introduce a function which initializes the chip by performing a hard reset, using the reset gpio defined in the device properties.
--- drivers/input/touchscreen/cyttsp_core.c | 12 ++++++++++++ 1 file changed, 12 insertions(+)
drivers/input/touchscreen/cyttsp_core.c +12 -0
@@ -240,6 +240,16 @@ static int cyttsp_set_sysinfo_regs(struct cyttsp *ts)return retval; } +static void cyttsp_hard_reset (struct cyttsp *ts) +{ +if (ts->reset_gpio) { +gpiod_set_value_cansleep (ts->reset_gpio,1 ); +msleep (CY_DELAY_DFLT ); +gpiod_set_value_cansleep (ts->reset_gpio,0 ); +msleep (CY_DELAY_DFLT ); + } +} +static int cyttsp_soft_reset (struct cyttsp *ts) {unsigned long timeout;
@@ -663,6 +673,8 @@ struct cyttsp *cyttsp_probe(const struct cyttsp_bus_ops *bus_ops,disable_irq (ts->irq); +cyttsp_hard_reset (ts); + error =cyttsp_power_on (ts);if (error)return ERR_PTR (error);
Signature · 1 line
1.9.1
Quoted 4 lines · Oreste Salerno
Implement a number of updates for the cyttsp driver to be able to parse generic ACPI/of/static properties and drop support for platform data (no platform data user is present in the kernel tree).
Applied all 4, thank you.
Quoted 32 lines
---
Changes in v5:
Use custom devm action to turn off the chip
Make reset gpio and touchscreen size properties optional
Changes in v4:
Major rework based on Dmitry's review:
- Usedevice_property_read()functions instead ofof_property()
- Usetouchscreen_parse_propertiesto parse common properties
- Drop support for platform data
- Used devres managed allocations
Changes in v3:
- Rework binding names and descriptions
Changes in v2:
- Fixerr_cast.cocciwarning in patch 2/3
Oreste Salerno (4):
Input: cyttsp - use devres managed resource allocations
Input: cyttsp - check return value ofinput_mt_init_slots
Input: cyttsp - switch to using device properties
Input: cyttsp - perform hard reset of the chip during probe.../bindings/input/touchscreen/cyttsp.txt | 95 ++++++++++ drivers/input/touchscreen/cyttsp_core.c | 193 +++++++++++++-------- drivers/input/touchscreen/cyttsp_core.h | 10 +- drivers/input/touchscreen/cyttsp_i2c.c | 10 -- drivers/input/touchscreen/cyttsp_spi.c | 10 -- include/linux/input/cyttsp.h | 15 -- 6 files changed, 228 insertions(+), 105 deletions(-) create mode 100644 Documentation/devicetree/bindings/input/touchscreen/cyttsp.txtSignature · 1 line
1.9.1
Signature · 5 lines
Dmitry -- To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html