Add Novatek NT36xxx touchscreen driver
Subsystems (3)
v5 cover Add Novatek NT36xxx touchscreen driver
From: AngeloGioacchino Del Regno <[email protected]>
This patch series adds support for the Novatek NT36xxx Series' In-Cell touchscreen (integrated into the DriverIC).
This patch series has been tested against the following devices:
- Sony Xperia 10 (SDM630 Ganges Kirin)
- Sony Xperia 10 Plus (SDM636 Ganges Mermaid)
Changes in v2:
- Fixed sparse warnings from lkp kernel test robot
Changes in v3 (as requested by Dmitry Torokhov):
- Using shorthand u16/u32 (sorry for the overlook!)
- Now using more input and touchscreen APIs
- Fixed useless workqueue involvements
- Removed useless locking
- Switched reads and writes to use regmap
- Moved header contents to nt36xxx.c
- Fixed reset gpio handling
- Other cleanups
- P.S.: Thanks, Dmitry!
Changes in v4:
- Fixed regmap read length for CRC_ERR_FLAG final check
- Fixed YAML binding, as requested by Krzysztof Kozlowski
Changes in v5:
- Replaced subsystem maintainer's name with .. mine, usage of additionalProperties to unevaluatedProperties and a typo fix for reset-gpios as per Rob Herring's review
- Changed compatible string as per Krzysztof K. request
- Renamed the novatek,nt36xxx.yaml file to just nt36xxx.yaml in order to now reflect the driver name instead of the DT compatible
- Fixed blank line at EOF
AngeloGioacchino Del Regno (3):
dt-bindings: Add vendor prefix for Novatek Microelectronics Corp.
Input: Add Novatek NT36xxx touchscreen driver
dt-bindings: touchscreen: Add binding for Novatek NT36xxx series
driver
.../bindings/input/touchscreen/nt36xxx.yaml | 59 ++ .../devicetree/bindings/vendor-prefixes.yaml | 2 + drivers/input/touchscreen/Kconfig | 12 + drivers/input/touchscreen/Makefile | 1 + drivers/input/touchscreen/nt36xxx.c | 815 ++++++++++++++++++ 5 files changed, 889 insertions(+) create mode 100644 Documentation/devicetree/bindings/input/touchscreen/nt36xxx.yaml create mode 100644 drivers/input/touchscreen/nt36xxx.c
Signature · 1 line
2.28.0
PATCH v5 1/3 dt-bindings: Add vendor prefix for Novatek Microelectronics Corp.
From: AngeloGioacchino Del Regno <[email protected]>
Add prefix for Novatek Microelectronics Corp.
--- Documentation/devicetree/bindings/vendor-prefixes.yaml | 2 ++ 1 file changed, 2 insertions(+)
Documentation/devicetree/bindings/vendor-prefixes.yaml +2 -0
@@ -740,6 +740,8 @@ patternProperties: description: Nokia "^nordic,.*": description: Nordic Semiconductor + "^novatek,.*": + description: Novatek Microelectronics Corp. "^novtech,.*": description: NovTech, Inc. "^nutsboard,.*":
Signature · 1 line
2.28.0
Re: [PATCH v5 1/3] dt-bindings: Add vendor prefix for Novatek Microelectronics Corp.
Quoted 8 lines · On Sat, Oct 17, 2020 at 09:01:50PM +0200, [email protected] wrote:
From: AngeloGioacchino Del Regno <[email protected]>
Add prefix for Novatek Microelectronics Corp.
Signed-off-by AngeloGioacchino Del Regno <[email protected]>--- Documentation/devicetree/bindings/vendor-prefixes.yaml | 2 ++ 1 file changed, 2 insertions(+)
You dropped here Rob's ack. Once received, you need to add it on next versions of your patchses (unless there are important changes).
Best regards,
Krzysztof
PATCH v5 2/3 Input: Add Novatek NT36xxx touchscreen driver
In reply to [email protected]From: AngeloGioacchino Del Regno <[email protected]>
This is a driver for the Novatek in-cell touch controller and supports various chips from the NT36xxx family, currently including NT36525, NT36672A, NT36676F, NT36772 and NT36870.
Functionality like wake gestures and firmware flashing is not
included: I am not aware of any of these DrIC+Touch combo chips not including a non-volatile memory and it should be highly unlikely to find one, since the touch firmware is embedded into the DriverIC one, which is obviously necessary to drive the display unit.
However, the necessary address for the firmware update procedure was included into the address table in this driver so, in the event that someone finds the need to implement it for a reason or another, it will be pretty straightforward to.
This driver is lightly based on the downstream implementation [1].
[1] https://github.com/Rasenkai/caf-tsoft-Novatek-nt36xxx
--- drivers/input/touchscreen/Kconfig | 12 + drivers/input/touchscreen/Makefile | 1 + drivers/input/touchscreen/nt36xxx.c | 815 ++++++++++++++++++++++++++++ 3 files changed, 828 insertions(+) create mode 100644 drivers/input/touchscreen/nt36xxx.c
drivers/input/touchscreen/Kconfig +12 -0
@@ -605,6 +605,18 @@ config TOUCHSCREEN_MTOUCH To compile this driver as a module, choose M here: the module will be called mtouch. +config TOUCHSCREEN_NT36XXX + tristate "Novatek NT36XXX In-Cell I2C touchscreen controller" + depends on I2C + help + Say Y here if you have a Novatek NT36xxx series In-Cell + touchscreen connected to your system over I2C. + + If unsure, say N. + + To compile this driver as a module, choose M here: the + module will be called nt36xxx. + config TOUCHSCREEN_IMX6UL_TSC tristate "Freescale i.MX6UL touchscreen controller" depends on (OF && GPIOLIB) || COMPILE_TEST
drivers/input/touchscreen/Makefile +1 -0
@@ -61,6 +61,7 @@ obj-$(CONFIG_TOUCHSCREEN_MIGOR) += migor_ts.o obj-$(CONFIG_TOUCHSCREEN_MMS114) += mms114.o obj-$(CONFIG_TOUCHSCREEN_MTOUCH) += mtouch.o obj-$(CONFIG_TOUCHSCREEN_MK712) += mk712.o +obj-$(CONFIG_TOUCHSCREEN_NT36XXX) += nt36xxx.o obj-$(CONFIG_TOUCHSCREEN_HP600) += hp680_ts_input.o obj-$(CONFIG_TOUCHSCREEN_HP7XX) += jornada720_ts.o obj-$(CONFIG_TOUCHSCREEN_IPAQ_MICRO) += ipaq-micro-ts.o
drivers/input/touchscreen/nt36xxx.c new file +815 -0
815 lines not on this page · raw message
Signature · 1 line
2.28.0
Re: [PATCH v5 2/3] Input: Add Novatek NT36xxx touchscreen driver
Quoted 21 lines · On Sun, Oct 18, 2020 at 12:40 AM <[email protected]> wrote:
From: AngeloGioacchino Del Regno <[email protected]>
This is a driver for the Novatek in-cell touch controller and supports various chips from the NT36xxx family, currently including NT36525, NT36672A, NT36676F, NT36772 and NT36870.
Functionality like wake gestures and firmware flashing is not
included: I am not aware of any of these DrIC+Touch combo chips not including a non-volatile memory and it should be highly unlikely to find one, since the touch firmware is embedded into the DriverIC one, which is obviously necessary to drive the display unit.However, the necessary address for the firmware update procedure was included into the address table in this driver so, in the event that someone finds the need to implement it for a reason or another, it will be pretty straightforward to.
This driver is lightly based on the downstream implementation [1].
[1] https://github.com/Rasenkai/caf-tsoft-Novatek-nt36xxx
...
drivers/input/touchscreen/nt36xxx.c line 12
Quoted 7 lines
drivers/input/touchscreen/nt36xxx.c new file +6
-0+#include <linux/delay.h> +#include <linux/i2c.h> +#include <linux/interrupt.h> +#include <linux/module.h> +#include <linux/regmap.h> +#include <linux/of_gpio.h>
I haven't found evidence you need this header.
But mod_devicetable.h along with gpio/consumer.h seem missed.
Quoted 3 lines
drivers/input/touchscreen/nt36xxx.c new file +3
-0+#include <linux/input/mt.h> +#include <linux/input/touchscreen.h> +#include <linux/regulator/consumer.h>
...
drivers/input/touchscreen/nt36xxx.c line 114
Quoted 7 lines
drivers/input/touchscreen/nt36xxx.c new file +7
-0+enum nt36xxx_fw_state { +NT36XXX_STATE_INIT =0xa0 ,/* IC reset */ +NT36XXX_STATE_REK ,/* ReK baseline */ +NT36XXX_STATE_REK_FINISH ,/* Baseline is ready */ +NT36XXX_STATE_NORMAL_RUN ,/* Normal run */ +NT36XXX_STATE_MAX =0xaf +};
Perhaps kernel doc?
...
drivers/input/touchscreen/nt36xxx.c line 208
Quoted 12 lines
drivers/input/touchscreen/nt36xxx.c new file +11
-0+static int nt36xxx_set_page (struct nt36xxx_i2c *ts,u32 pageaddr) +{ +u32 data =cpu_to_be32 (pageaddr) >>8 ; +int ret; + + ret =regmap_noinc_write (ts->fw_regmap,NT36XXX_CMD_SET_PAGE , + &data,sizeof (data)); +if (ret ==0 ) +usleep_range (100 ,200 ); + +return ret;
Can you use traditional pattern, i.e.
if (ret)
return ret;
...
return 0;
?
drivers/input/touchscreen/nt36xxx.c line 218
Quoted 11 lines
drivers/input/touchscreen/nt36xxx.c new file +10
-0+} + +static int nt36xxx_sw_reset_idle (struct nt36xxx_i2c *ts) +{ +int ret; + + ret =regmap_write (ts->regmap, ts->hw_client->addr, +NT36XXX_CMD_SW_RESET ); + +usleep_range (15000 ,16000 );
Even in error case? Also, can you explain the value of delay?
drivers/input/touchscreen/nt36xxx.c line 229
Quoted 12 lines
drivers/input/touchscreen/nt36xxx.c new file +11
-0+return ret; +} + +static int nt36xxx_bootloader_reset (struct nt36xxx_i2c *ts) +{ +int ret; + + ret =regmap_write (ts->regmap, ts->hw_client->addr, +NT36XXX_CMD_BOOTLOADER_RESET ); + +msleep (35 );
Same as above, esp. taking into account quite a long delay.
Quoted 16 lines
drivers/input/touchscreen/nt36xxx.c new file +16
-0+return ret; +} + +static int nt36xxx_check_reset_state (struct nt36xxx_i2c *ts, +enum nt36xxx_fw_state fw_state) +{ +u8 buf[2 ] = {0 }; +int ret, retry =NT36XXX_MAX_FW_RST_RETRY ; + + do { + ret = regmap_noinc_read(ts->fw_regmap, + NT36XXX_EVT_RESET_COMPLETE, + buf, sizeof(buf)); + if (likely(ret == 0) && + (buf[0] >= fw_state) && + (buf[0] <= NT36XXX_STATE_MAX)) {
drivers/input/touchscreen/nt36xxx.c line 255
Quoted 10 lines
drivers/input/touchscreen/nt36xxx.c new file +10
-0+ ret =0 ; +break ; + } +usleep_range (10000 ,11000 ); + }while (--retry); + +if (!retry) { +dev_err (&ts->hw_client->dev,"Firmware reset failed.\n" ); + ret = -EBUSY ; + }
This sounds like it should be a part of regmap API, such as regmap_read_poll_timeout().
drivers/input/touchscreen/nt36xxx.c line 263
Quoted 8 lines
drivers/input/touchscreen/nt36xxx.c new file +8
-0+ +return ret; +} + +static int nt36xxx_read_pid (struct nt36xxx_i2c *ts) +{ +u8 buf[2 ] = {0 }; +int ret =0 ;
Redundant assignments.
drivers/input/touchscreen/nt36xxx.c line 274
Quoted 11 lines
drivers/input/touchscreen/nt36xxx.c new file +10
-0+ ret =nt36xxx_set_page (ts, ts->mmap->evtbuf_addr); +if (unlikely (ret <0 )) +return ret; + + ret =regmap_noinc_read (ts->fw_regmap,NT36XXX_EVT_PROJECTID , + buf,sizeof (buf)); +if (unlikely (ret <0 )) +return ret; + + ts->fw_info.nvt_pid = (buf[1 ] <<8 ) + buf[0 ];
Define buf as __le16 and use le16_to_cpu().
Quoted 14 lines
drivers/input/touchscreen/nt36xxx.c new file +14
-0+ +return 0 ; +} + +static int __nt36xxx_get_fw_info (struct nt36xxx_i2c *ts) +{ +struct nt36xxx_fw_info *fwi = &ts->fw_info; +u8 buf[11 ] = {0 }; +int ret =0 ; + + ret =nt36xxx_set_page (ts, ts->mmap->evtbuf_addr); +if (unlikely (ret <0 )) +return ret; +
drivers/input/touchscreen/nt36xxx.c line 298
Quoted 10 lines
drivers/input/touchscreen/nt36xxx.c new file +10
-0+ ret =regmap_noinc_read (ts->fw_regmap,NT36XXX_EVT_FWINFO , + buf,sizeof (buf)); +if (ret) +return ret; + + fwi->fw_ver = buf[0 ]; + fwi->x_num = buf[2 ]; + fwi->y_num = buf[3 ]; + fwi->abs_x_max = (u16)((buf[4 ] <<8 ) | buf[5 ]); + fwi->abs_y_max = (u16)((buf[6 ] <<8 ) | buf[7 ]);
be16_to_cpu() or get_unaligned_be16(), though here it's aligned.
Quoted 19 lines
drivers/input/touchscreen/nt36xxx.c new file +19
-0+ fwi->max_buttons = buf[10 ]; + +/* Check fw info integrity and clear x_num, y_num if broken */ +if ((buf[0 ] + buf[1 ]) !=0xFF ) { +dev_err (&ts->hw_client->dev, +"FW info is broken! fw_ver=0x%02X, ~fw_ver=0x%02X\n" , + buf[0 ], buf[1 ]); + fwi->fw_ver =0 ; + fwi->x_num =18 ; + fwi->y_num =32 ; + fwi->abs_x_max =TOUCH_DEFAULT_MAX_WIDTH ; + fwi->abs_y_max =TOUCH_DEFAULT_MAX_HEIGHT ; + fwi->max_buttons =0 ; +return -EINVAL ; + } + +/* Get Novatek ProjectID */ +return nt36xxx_read_pid (ts); +}
...
Quoted 14 lines
drivers/input/touchscreen/nt36xxx.c new file +14
-0+static int nvt_stop_crc_reboot (struct nt36xxx_i2c *ts) +{ +u8 buf[3 ] = {0 }; +u8 val; +int ret, retry =NT36XXX_MAX_RETRIES ; + +/* Read dummy buffer to check CRC fail reboot is happening or not */ + +/* Change I2C index to prevent getting 0xFF, but not 0xFC */ + ret =nt36xxx_set_page (ts,NT36XXX_PAGE_CHIP_INFO ); +if (ret) { +dev_dbg (&ts->hw_client->dev, +"CRC reset failed: Cannot select page.\n" ); +return ret;
drivers/input/touchscreen/nt36xxx.c line 441
Quoted 10 lines
drivers/input/touchscreen/nt36xxx.c new file +10
-0+ } + +/* If ChipID command returns 0xFC or 0xFF, the MCU is in CRC reboot */ + ret =regmap_noinc_read (ts->fw_regmap,NT36XXX_EVT_CHIPID , + buf,sizeof (buf)); +if (ret) +return ret; + +if (((buf[0 ] ==0xFC ) && (buf[1 ] ==0xFC ) && (buf[2 ] ==0xFC )) || + ((buf[0 ] ==0xFF ) && (buf[1 ] ==0xFF ) && (buf[2 ] ==0xFF ))) {
You may decrese indentation by switching above to be negative conditional.
drivers/input/touchscreen/nt36xxx.c line 448
Quoted 8 lines
drivers/input/touchscreen/nt36xxx.c new file +7
-0+/* IC is in CRC fail reboot loop, needs to be stopped! */ + do { + /* Special reset-idle sequence for CRC failure */ + ret = regmap_write(ts->regmap, ts->hw_client->addr, + NT36XXX_CMD_SW_RESET); + ret += regmap_write(ts->regmap, ts->hw_client->addr, + NT36XXX_CMD_SW_RESET);
It's not good practice to sum error codes.
Quoted 24 lines
drivers/input/touchscreen/nt36xxx.c new file +24
-0+if (ret) +dev_dbg (&ts->hw_client->dev, +"SW Reset failed: may not recover\n" ); +usleep_range (1000 ,1100 ); + +/* Clear CRC_ERR_FLAG */ + ret =nt36xxx_set_page (ts,NT36XXX_PAGE_CRC ); +if (ret) +continue ; + + val =0xA5 ; + ret =regmap_raw_write (ts->fw_regmap,NT36XXX_EVT_CRC , + &val,sizeof (val)); +if (ret) +continue ; + +/* Check CRC_ERR_FLAG */ + ret =nt36xxx_set_page (ts,NT36XXX_PAGE_CRC ); +if (ret) +continue ; + + ret =regmap_noinc_read (ts->fw_regmap,NT36XXX_EVT_CRC , + &buf,sizeof (buf)); +if (ret)
drivers/input/touchscreen/nt36xxx.c line 482
Quoted 10 lines
drivers/input/touchscreen/nt36xxx.c new file +10
-0+continue ; + +if (buf[0 ] ==0xA5 ) +break ; + }while (--retry); + +if (retry ==0 ) { +dev_err (&ts->hw_client->dev, +"CRC reset failed: buf=0x%02x%02x\n" , + buf[0 ], buf[1 ]);
%2ph
Quoted 53 lines
drivers/input/touchscreen/nt36xxx.c new file +53
-0+ } + } + +return 0 ; +} + +static int nt36xxx_i2c_chip_version_init (struct nt36xxx_i2c *ts) +{ +u8 buf[7 ] = {0 }; +int retry =NT36XXX_MAX_RETRIES ; +int sz =sizeof (trim_id_table) /sizeof (struct nt36xxx_trim_table ); +int i, list, mapid, ret; + + ret =nt36xxx_bootloader_reset (ts); +if (ret <0 ) { +dev_err (&ts->hw_client->dev,"Can't reset the nvt IC\n" ); +return ret; + } + + do { + ret = nt36xxx_sw_reset_idle(ts); + if (ret < 0) + continue; + + ret = regmap_write(ts->regmap, ts->hw_client->addr, NT36XXX_CMD_UNLOCK); + if (ret) + continue; + usleep_range(10000, 11000); + + ret = nt36xxx_set_page(ts, NT36XXX_PAGE_CHIP_INFO); + if (ret) + continue; + + memset(buf, 0, ARRAY_SIZE(buf)); + ret = regmap_noinc_read(ts->fw_regmap, NT36XXX_EVT_CHIPID, + buf, sizeof(buf)); + if (ret) + continue; + + /* Compare read chip id with trim list */ + for (list = 0; list < sz; list++) { + /* Compare each not masked byte */ + for (i = 0; i < NT36XXX_ID_LEN_MAX; i++) { + if (trim_id_table[list].mask[i] && + buf[i] != trim_id_table[list].id[i]) + break; + } + + if (i == NT36XXX_ID_LEN_MAX) { + mapid = trim_id_table[list].mapid; + ts->mmap = &nt36xxx_memory_maps[mapid]; + return 0; + }
drivers/input/touchscreen/nt36xxx.c line 545
Quoted 10 lines
drivers/input/touchscreen/nt36xxx.c new file +10
-0+ + ts->mmap =NULL ; + ret = -ENOENT ; + } + +/* Stop CRC check to prevent IC auto reboot */ +if (((buf[1 ] ==0xFC ) && (buf[2 ] ==0xFC ) && + (buf[3 ] ==0xFC )) || + ((buf[1 ] ==0xFF ) && (buf[2 ] ==0xFF ) && + (buf[3 ] ==0xFF ))) {
You already have the same code above. Perhaps helper is good to have for this.
Quoted 72 lines
drivers/input/touchscreen/nt36xxx.c new file +72
-0+ ret =nvt_stop_crc_reboot (ts); +if (ret <0 ) +continue ; + } + +usleep_range (10000 ,11000 ); + }while (--retry); + +return ret; +} + +static const struct regmap_config nt36xxx_i2c_regmap_hw_config = { + .name ="nt36xxx_i2c_hw" , + .reg_bits =8 , + .val_bits =8 , + .cache_type =REGCACHE_NONE , +}; + +static const struct regmap_config nt36xxx_i2c_regmap_fw_config = { + .name ="nt36xxx_i2c_fw" , + .reg_bits =8 , + .val_bits =8 , + .cache_type =REGCACHE_NONE , +}; + +static void nt36xxx_disable_regulators (void *data) +{ +struct nt36xxx_i2c *ts = data; + +regulator_bulk_disable (NT36XXX_NUM_SUPPLIES , ts->supplies); +} + +static int nt36xxx_i2c_probe (struct i2c_client *hw_client, +const struct i2c_device_id *id) +{ +struct nt36xxx_i2c *ts; +struct input_dev *input; +int ret; + +if (!i2c_check_functionality (hw_client->adapter,I2C_FUNC_I2C )) { +dev_err (&hw_client->dev,"i2c_check_functionality error\n" ); +return -EIO ; + } + +if (!hw_client->irq) { +dev_err (&hw_client->dev,"No irq specified\n" ); +return -EINVAL ; + } + + ts =devm_kzalloc (&hw_client->dev,sizeof (struct nt36xxx_i2c ),GFP_KERNEL ); +if (!ts) +return -ENOMEM ; + + ts->supplies =devm_kcalloc (&hw_client->dev, +NT36XXX_NUM_SUPPLIES , +sizeof (struct regulator_bulk_data ), +GFP_KERNEL ); +if (!ts->supplies) +return -ENOMEM ; + + input =devm_input_allocate_device (&hw_client->dev); +if (!input) +return -ENOMEM ; + + ts->fw_client =i2c_new_dummy_device (hw_client->adapter, +NT36XXX_FW_ADDR ); +if (IS_ERR (ts->fw_client)) { +dev_err (&hw_client->dev,"Cannot add FW I2C device\n" ); +return PTR_ERR (ts->fw_client); + } + + ts->hw_client = hw_client;
drivers/input/touchscreen/nt36xxx.c line 626
Quoted 10 lines
drivers/input/touchscreen/nt36xxx.c new file +9
-0+ ts->input = input; +i2c_set_clientdata (ts->hw_client, ts); +i2c_set_clientdata (ts->fw_client, ts); + + ts->reset_gpio =devm_gpiod_get_optional (&hw_client->dev,"reset" , +GPIOD_OUT_HIGH ); +if (IS_ERR (ts->reset_gpio)) +return PTR_ERR (ts->reset_gpio); +if (ts->reset_gpio)
Redundant. If you mark GPIO as optional all those checks should not be here.
drivers/input/touchscreen/nt36xxx.c line 635
Quoted 9 lines
drivers/input/touchscreen/nt36xxx.c new file +9
-0+gpiod_set_consumer_name (ts->reset_gpio,"nt36xxx reset" ); + +/* These supplies are optional */ + ts->supplies[0 ].supply ="vdd" ; + ts->supplies[1 ].supply ="vio" ; + ret =devm_regulator_bulk_get (&hw_client->dev, +NT36XXX_NUM_SUPPLIES , + ts->supplies); +if (ret !=0 ) {
if (ret)
drivers/input/touchscreen/nt36xxx.c line 639
Quoted 4 lines
drivers/input/touchscreen/nt36xxx.c new file +4
-0+if (ret != -EPROBE_DEFER ) +dev_err (&hw_client->dev, +"Cannot get supplies: %d\n" , ret); +return ret;
I think there is no return dev_err_probe() here b/c Dmitry is against it?
Quoted 11 lines
drivers/input/touchscreen/nt36xxx.c new file +11
-0+ } + + ts->regmap =devm_regmap_init_i2c (ts->hw_client, + &nt36xxx_i2c_regmap_hw_config); +if (IS_ERR (ts->regmap)) { +dev_err (&hw_client->dev,"regmap (hw-addr) init failed\n" ); +return PTR_ERR (ts->regmap); + } + + ts->fw_regmap =devm_regmap_init_i2c (ts->fw_client, + &nt36xxx_i2c_regmap_fw_config);
drivers/input/touchscreen/nt36xxx.c line 660
Quoted 10 lines
drivers/input/touchscreen/nt36xxx.c new file +9
-0+if (IS_ERR (ts->fw_regmap)) { +dev_err (&hw_client->dev,"regmap (fw-addr) init failed\n" ); +return PTR_ERR (ts->fw_regmap); + } + + ret =regulator_bulk_enable (NT36XXX_NUM_SUPPLIES , ts->supplies); +if (ret) +return ret; +usleep_range (10000 ,11000 );
Why?
Quoted 8 lines
drivers/input/touchscreen/nt36xxx.c new file +8
-0+ ret =devm_add_action_or_reset (&hw_client->dev, + nt36xxx_disable_regulators, ts); +if (ret) +return ret; + +mutex_init (&ts->lock); + +/* Set memory maps for the specific chip version */
drivers/input/touchscreen/nt36xxx.c line 678
Quoted 10 lines
drivers/input/touchscreen/nt36xxx.c new file +9
-0+ ret =nt36xxx_i2c_chip_version_init (ts); +if (ret) { +dev_err (&hw_client->dev,"Failed to check chip version\n" ); +return ret; + } + +/* Reset the MCU */ + ret =nt36xxx_bootloader_reset (ts); +if (unlikely (ret <0 ))
All these unlikely() calls are unlikely needed. Please, drop them for the sake of readability.
Quoted 51 lines
drivers/input/touchscreen/nt36xxx.c new file +51
-0+return ret; + +/* Check and eventually wait until the MCU goes in reset state */ + ret =nt36xxx_check_reset_state (ts,NT36XXX_STATE_INIT ); +if (unlikely (ret <0 )) +return ret; + +/* Get informations from the TS firmware */ + ret =nt36xxx_get_fw_info (ts); +if (unlikely (ret <0 )) +return ret; + + input->phys =devm_kasprintf (&hw_client->dev,GFP_KERNEL , +"%s/input0" ,dev_name (&hw_client->dev)); + + input->name ="Novatek NT36XXX Touchscreen" ; + input->id.bustype =BUS_I2C ; + input->dev.parent = &hw_client->dev; + +__set_bit (EV_KEY , input->evbit); +__set_bit (EV_ABS , input->evbit); +input_set_capability (input,EV_KEY ,BTN_TOUCH ); + + ret =input_mt_init_slots (input,TOUCH_MAX_FINGER_NUM , +INPUT_MT_DIRECT |INPUT_MT_DROP_UNUSED ); +if (ret) { +dev_err (&hw_client->dev,"Cannot init MT slots (%d)\n" , ret); +return ret; + } + +input_set_abs_params (input,ABS_MT_PRESSURE ,0 , +TOUCH_MAX_PRESSURE ,0 ,0 ); +input_set_abs_params (input,ABS_MT_TOUCH_MAJOR ,0 ,255 ,0 ,0 ); + +input_set_abs_params (input,ABS_MT_POSITION_X ,0 , + ts->fw_info.abs_x_max -1 ,0 ,0 ); +input_set_abs_params (input,ABS_MT_POSITION_Y ,0 , + ts->fw_info.abs_y_max -1 ,0 ,0 ); + +/* Override the firmware defaults, if needed */ +touchscreen_parse_properties (input, true, &ts->prop); + +input_set_drvdata (input, ts); + + ret =input_register_device (ts->input); +if (ret) { +dev_err (&hw_client->dev,"Failed to register input device: %d\n" , + ret); +return ret; + } +
drivers/input/touchscreen/nt36xxx.c line 738
Quoted 10 lines
drivers/input/touchscreen/nt36xxx.c new file +9
-0+ ret =devm_request_threaded_irq (&hw_client->dev, hw_client->irq,NULL , + nt36xxx_i2c_irq_handler,IRQF_ONESHOT , + hw_client->name, ts); +if (ret) { +dev_err (&hw_client->dev,"request irq failed: %d\n" , ret); +return ret; + } + +return 0 ;
return ret; ?
Quoted 7 lines
drivers/input/touchscreen/nt36xxx.c new file +7
-0+} + +static int __maybe_unused nt36xxx_i2c_suspend (struct device *dev) +{ +struct nt36xxx_i2c *ts =i2c_get_clientdata (to_i2c_client (dev)); +int ret; +
drivers/input/touchscreen/nt36xxx.c line 755
Quoted 10 lines
drivers/input/touchscreen/nt36xxx.c new file +9
-0+disable_irq (ts->hw_client->irq); + + ret =regmap_write (ts->fw_regmap,NT36XXX_EVT_HOST_CMD , +NT36XXX_CMD_ENTER_SLEEP ); +if (unlikely (ret)) { +dev_err (&ts->hw_client->dev,"Cannot enter suspend!!\n" ); +return ret; + } +if (ts->reset_gpio)
Redundant.
drivers/input/touchscreen/nt36xxx.c line 768
Quoted 13 lines
drivers/input/touchscreen/nt36xxx.c new file +12
-0+gpiod_set_value (ts->reset_gpio,1 ); + +return 0 ; +} + +static int __maybe_unused nt36xxx_i2c_resume (struct device *dev) +{ +struct nt36xxx_i2c *ts =i2c_get_clientdata (to_i2c_client (dev)); +int ret; + +mutex_lock (&ts->lock); +if (ts->reset_gpio)
Redundant.
Quoted 30 lines
drivers/input/touchscreen/nt36xxx.c new file +29
-0+gpiod_set_value (ts->reset_gpio,0 ); +/* Reboot the MCU (also recalibrates the TS) */ + ret =nt36xxx_bootloader_reset (ts); +if (ret <0 ) + goto end; + + ret =nt36xxx_check_reset_state (ts,NT36XXX_STATE_REK ); +if (ret <0 ) + goto end; + +enable_irq (ts->hw_client->irq); +end: +mutex_unlock (&ts->lock); +return ret; +} + +static SIMPLE_DEV_PM_OPS(nt36xxx_i2c_pm, + nt36xxx_i2c_suspend, nt36xxx_i2c_resume); + +#ifdef CONFIG_OF +static const struct of_device_id nt36xxx_of_match[] = { + { .compatible ="novatek,nt36525" }, + { } +}; +MODULE_DEVICE_TABLE (of, nt36xxx_of_match); +#endif + +static const struct i2c_device_id nt36xxx_i2c_ts_id[] = { + {"NVT-ts" ,0 },
drivers/input/touchscreen/nt36xxx.c line 807
Quoted 10 lines
drivers/input/touchscreen/nt36xxx.c new file +9
-0+ { } +}; +MODULE_DEVICE_TABLE (i2c, nt36xxx_i2c_ts_id); + +static struct i2c_driver nt36xxx_i2c_ts_driver = { + .driver = { + .name ="nt36xxx_ts" , + .pm = &nt36xxx_i2c_pm, + .of_match_table =of_match_ptr (nt36xxx_of_match),
You may do a good job by dropping these of_match_ptr() along with ugly ifdeffery above. It will allow to use it on ACPI-enabled platforms.
Quoted 1 line
+ },
--
With Best Regards,
Andy Shevchenko
[email protected]
maintainerRe: [PATCH v5 2/3] Input: Add Novatek NT36xxx touchscreen driver
In reply to [email protected]Hi AngeloGioacchino,
[obviously not a complete review, but wanted to call out regmap concern]
drivers/input/touchscreen/nt36xxx.c line 262
Quoted 3 lines · On Sat, Oct 17, 2020 at 09:01:51PM +0200, [email protected] wrote:
drivers/input/touchscreen/nt36xxx.c new file +3
-0+static int nt36xxx_read_pid (struct nt36xxx_i2c *ts) +{ +u8 buf[2 ] = {0 };
__be16 pid;
drivers/input/touchscreen/nt36xxx.c line 267
Quoted 5 lines
drivers/input/touchscreen/nt36xxx.c new file +5
-0+int ret =0 ; + + ret =nt36xxx_set_page (ts, ts->mmap->evtbuf_addr); +if (unlikely (ret <0 )) +return ret;
regmap is supposed to help with the paged registers, that is why I recommended using it.
drivers/input/touchscreen/nt36xxx.c line 274
Quoted 7 lines
drivers/input/touchscreen/nt36xxx.c new file +7
-0+ + ret =regmap_noinc_read (ts->fw_regmap,NT36XXX_EVT_PROJECTID , + buf,sizeof (buf)); +if (unlikely (ret <0 )) +return ret; + + ts->fw_info.nvt_pid = (buf[1 ] <<8 ) + buf[0 ];
ts->fw_info.nvt_pid = be16_to_cpu(pid);
Thanks.
Signature · 1 line
Dmitry
PATCH v5 3/3 dt-bindings: touchscreen: Add binding for Novatek NT36xxx series driver
In reply to [email protected]From: AngeloGioacchino Del Regno <[email protected]>
Add binding for the Novatek NT36xxx series touchscreen driver.
--- .../bindings/input/touchscreen/nt36xxx.yaml | 59 +++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 Documentation/devicetree/bindings/input/touchscreen/nt36xxx.yaml
Documentation/devicetree/bindings/input/touchscreen/nt36xxx.yaml new file +59 -0
@@ -0,0 +1,59 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/input/touchscreen/nt36xxx.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Novatek NT36xxx series touchscreen controller Bindings + +maintainers: + - AngeloGioacchino Del Regno <[email protected]> + +allOf: + - $ref: touchscreen.yaml# + +properties: + compatible: + const: novatek,nt36525 + + reg: + maxItems: 1 + + interrupts: + maxItems: 1 + + reset-gpios: + maxItems: 1 + + vdd-supply: + description: Power supply regulator for VDD pin + + vio-supply: + description: Power supply regulator on VDD-IO pin + +unevaluatedProperties: false + +required: + - compatible + - reg + - interrupts + +examples: + - | + #include <dt-bindings/interrupt-controller/irq.h> + #include <dt-bindings/gpio/gpio.h> + + i2c { + #address-cells = <1>; + #size-cells = <0>; + + touchscreen@62 { + compatible = "novatek,nt36525"; + reg = <0x62>; + interrupt-parent = <&tlmm>; + interrupts = <45 IRQ_TYPE_EDGE_RISING>; + reset-gpio = <&tlmm 102 GPIO_ACTIVE_HIGH>; + }; + }; + +...
Signature · 1 line
2.28.0
Re: [PATCH v5 3/3] dt-bindings: touchscreen: Add binding for Novatek NT36xxx series driver
Quoted 61 lines · On Sat, Oct 17, 2020 at 09:01:52PM +0200, [email protected] wrote:
From: AngeloGioacchino Del Regno <[email protected]>
Add binding for the Novatek NT36xxx series touchscreen driver.
Signed-off-by AngeloGioacchino Del Regno <[email protected]>--- .../bindings/input/touchscreen/nt36xxx.yaml | 59 +++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 Documentation/devicetree/bindings/input/touchscreen/nt36xxx.yamlDocumentation/devicetree/bindings/input/touchscreen/nt36xxx.yaml new file +45
-0@@ -0,0 +1,59 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/input/touchscreen/nt36xxx.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Novatek NT36xxx series touchscreen controller Bindings + +maintainers: + - AngeloGioacchino Del Regno <[email protected]> + +allOf: + - $ref: touchscreen.yaml# + +properties: + compatible: + const: novatek,nt36525 + + reg: + maxItems: 1 + + interrupts: + maxItems: 1 + + reset-gpios: + maxItems: 1 + + vdd-supply: + description: Power supply regulator for VDD pin + + vio-supply: + description: Power supply regulator on VDD-IO pin + +unevaluatedProperties: false + +required: + - compatible + - reg + - interrupts + +examples: + - | + #include <dt-bindings/interrupt-controller/irq.h> + #include <dt-bindings/gpio/gpio.h> +
Documentation/devicetree/bindings/input/touchscreen/nt36xxx.yaml line 55
Quoted 10 lines
Documentation/devicetree/bindings/input/touchscreen/nt36xxx.yaml new file +10
-0+ i2c { + #address-cells = <1>; + #size-cells = <0>; + + touchscreen@62 { + compatible = "novatek,nt36525"; + reg = <0x62>; + interrupt-parent = <&tlmm>; + interrupts = <45 IRQ_TYPE_EDGE_RISING>; + reset-gpio = <&tlmm 102 GPIO_ACTIVE_HIGH>;
reset-gpios
Best regards,
Krzysztof