# Re: \[PATCH 1/2\] Input: goodix - support gt1151 touchpanel

- List: linux-input
- 5 messages, 4 authors
- Page: https://ratatoskr.run/linux-input/2017/10/8145751/t

## Re: \[PATCH 1/2\] Input: goodix - support gt1151 touchpanel

- From: Bastien Nocera \<hidden\>
- Date: 2017-10-13 16:40:42 
- Message: https://ratatoskr.run/linux-input/2017/10/8145751.md

```text
On Fri, 2017-10-13 at 18:02 +0200, Antonio Ospite wrote:
> On Thu, 12 Oct 2017 17:04:42 +0200
> Marcin Niestroj [ref] wrote:
> 
> > Support was added based on Goodix GitHub repo [1]. There are two
> > major
> > differences between gt1151 and currently supported devices (gt9x):
> >  * CONFIG_DATA register has 0x8050 address instead of 0x8047,
> >  * config data checksum has 16-bit width instead of 8-bit.
> > 
> > Also update goodix_i2c_test() function, so it reads ID register
> > (which
> > has the same address for all devices) instead of CONFIG_DATA
> > (because
> > its address is known only after reading ID of the device).
> > 
> > [1] https://github.com/goodix/gt1x_driver_generic
> > 
> > Signed-off-by: Marcin Niestroj <redacted>
> > ---
> > Patch was developed and tested on top of 4.14-rc4 using custom
> > board.
> > 
> 
> Just a suggestion, you could use a function pointer for the
> device-specific checksum routines and have the check on the device id
> only once in goodix_ts_probe(), see below.

Function pointer is fine, but this is how I'd implement it:

typedef enum {
  GOODIX_CONFIG_TYPE_GT911 = 0,
  GOODIX_CONFIG_TYPE_GT1151
} GoodixConfigType;

static func_pointer config_funcs[] = {
  goodix_gt911_get_config,
  goodix_gt1151_get_config
};

Store the GoodixConfigType in the device structure, and access the
function pointer as:
config_funcs[config_type] (...

That's what I'd prefer, but whatever Dmitry prefers style-wise. This
seems more extensible in case we have different functions needing
similar changes in the future, allowing us to either extend the
function pointer array, or use switch/case statements for smaller
functions.

Cheers
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
```

## Re: \[PATCH 1/2\] Input: goodix - support gt1151 touchpanel

- From: Dmitry Torokhov \<dmitry.torokhov@gmail.com\>
- Date: 2017-10-13 22:58:43 
- Message: https://ratatoskr.run/linux-input/2017/10/8145772.md

```text
On Fri, Oct 13, 2017 at 06:40:42PM +0200, Bastien Nocera wrote:
> On Fri, 2017-10-13 at 18:02 +0200, Antonio Ospite wrote:
> > On Thu, 12 Oct 2017 17:04:42 +0200
> > Marcin Niestroj [ref] wrote:
> > 
> > > Support was added based on Goodix GitHub repo [1]. There are two
> > > major
> > > differences between gt1151 and currently supported devices (gt9x):
> > >  * CONFIG_DATA register has 0x8050 address instead of 0x8047,
> > >  * config data checksum has 16-bit width instead of 8-bit.
> > > 
> > > Also update goodix_i2c_test() function, so it reads ID register
> > > (which
> > > has the same address for all devices) instead of CONFIG_DATA
> > > (because
> > > its address is known only after reading ID of the device).
> > > 
> > > [1] https://github.com/goodix/gt1x_driver_generic
> > > 
> > > Signed-off-by: Marcin Niestroj <redacted>
> > > ---
> > > Patch was developed and tested on top of 4.14-rc4 using custom
> > > board.
> > > 
> > 
> > Just a suggestion, you could use a function pointer for the
> > device-specific checksum routines and have the check on the device id
> > only once in goodix_ts_probe(), see below.
> 
> Function pointer is fine, but this is how I'd implement it:
> 
> typedef enum {
>   GOODIX_CONFIG_TYPE_GT911 = 0,
>   GOODIX_CONFIG_TYPE_GT1151
> } GoodixConfigType;
> 
> static func_pointer config_funcs[] = {
>   goodix_gt911_get_config,
>   goodix_gt1151_get_config
> };
> 
> Store the GoodixConfigType in the device structure, and access the
> function pointer as:
> config_funcs[config_type] (...
> 
> That's what I'd prefer, but whatever Dmitry prefers style-wise. This
> seems more extensible in case we have different functions needing
> similar changes in the future, allowing us to either extend the
> function pointer array, or use switch/case statements for smaller
> functions.

My preference would be to assign constant chip data, such as register,
to the relevant device ID structure (I2C or OF or ACPI) and reference it
form where it is needed.

struct goodix_chip_data {
	u16	config_addr; 
};

...

struct goodix_ts_data {
	...
	const struct goodix_chip_data *chip;
	...
};

...

static const goodix_chip_data gt1x_chip_data = {
	.config_addr	= GOODIX_GT1X_REG_CONFIG_DATA,
};

static const goodix_chip_data gt9x_chip_data = {
	.config_addr	= GOODIX_GT9X_REG_CONFIG_DATA,
};

static const struct of_device_id goodix_of_match[] = {
	{ .compatible = "goodix,gt1151", .data = &gt1x_chip_data },
	...
};

and so on...

Thanks.

-- 
Dmitry
```

## Re: \[PATCH 1/2\] Input: goodix - support gt1151 touchpanel

- From: Bastien Nocera \<hadess@hadess.net\>
- Date: 2017-10-14 04:40:49 
- Message: https://ratatoskr.run/linux-input/2017/10/8145776.md

```text
On Fri, 2017-10-13 at 15:58 -0700, Dmitry Torokhov wrote:
> On Fri, Oct 13, 2017 at 06:40:42PM +0200, Bastien Nocera wrote:
> > On Fri, 2017-10-13 at 18:02 +0200, Antonio Ospite wrote:
> > > On Thu, 12 Oct 2017 17:04:42 +0200
> > > Marcin Niestroj [ref] wrote:
> > > 
> > > > Support was added based on Goodix GitHub repo [1]. There are
> > > > two
> > > > major
> > > > differences between gt1151 and currently supported devices
> > > > (gt9x):
> > > >  * CONFIG_DATA register has 0x8050 address instead of 0x8047,
> > > >  * config data checksum has 16-bit width instead of 8-bit.
> > > > 
> > > > Also update goodix_i2c_test() function, so it reads ID register
> > > > (which
> > > > has the same address for all devices) instead of CONFIG_DATA
> > > > (because
> > > > its address is known only after reading ID of the device).
> > > > 
> > > > [1] https://github.com/goodix/gt1x_driver_generic
> > > > 
> > > > Signed-off-by: Marcin Niestroj <redacted>
> > > > ---
> > > > Patch was developed and tested on top of 4.14-rc4 using custom
> > > > board.
> > > > 
> > > 
> > > Just a suggestion, you could use a function pointer for the
> > > device-specific checksum routines and have the check on the
> > > device id
> > > only once in goodix_ts_probe(), see below.
> > 
> > Function pointer is fine, but this is how I'd implement it:
> > 
> > typedef enum {
> >   GOODIX_CONFIG_TYPE_GT911 = 0,
> >   GOODIX_CONFIG_TYPE_GT1151
> > } GoodixConfigType;
> > 
> > static func_pointer config_funcs[] = {
> >   goodix_gt911_get_config,
> >   goodix_gt1151_get_config
> > };
> > 
> > Store the GoodixConfigType in the device structure, and access the
> > function pointer as:
> > config_funcs[config_type] (...
> > 
> > That's what I'd prefer, but whatever Dmitry prefers style-wise.
> > This
> > seems more extensible in case we have different functions needing
> > similar changes in the future, allowing us to either extend the
> > function pointer array, or use switch/case statements for smaller
> > functions.
> 
> My preference would be to assign constant chip data, such as
> register,
> to the relevant device ID structure (I2C or OF or ACPI) and reference
> it
> form where it is needed.

That's much closer to the kernel style, yes. Thanks.
```

## Re: \[PATCH 1/2\] Input: goodix - support gt1151 touchpanel

- From: Marcin Niestroj \<hidden\>
- Date: 2017-10-17 09:40:01 
- Message: https://ratatoskr.run/linux-input/2017/10/8145860.md

```text
Hi,
Thanks everyone for review!

On 14.10.2017 00:58, Dmitry Torokhov wrote:
> <...snip...>
> My preference would be to assign constant chip data, such as register,
> to the relevant device ID structure (I2C or OF or ACPI) and reference it
> form where it is needed.
>
> struct goodix_chip_data {
> 	u16	config_addr;
> };
>
> ...
>
> struct goodix_ts_data {
> 	...
> 	const struct goodix_chip_data *chip;
> 	...
> };
>
> ...
>
> static const goodix_chip_data gt1x_chip_data = {
> 	.config_addr	= GOODIX_GT1X_REG_CONFIG_DATA,
> };
>
> static const goodix_chip_data gt9x_chip_data = {
> 	.config_addr	= GOODIX_GT9X_REG_CONFIG_DATA,
> };
>
> static const struct of_device_id goodix_of_match[] = {
> 	{ .compatible = "goodix,gt1151", .data = &gt1x_chip_data },
> 	...
> };
>
> and so on...
>
> Thanks.
>

This looks good to me. Together with config_addr I would put config_len
to struct goodix_chip_data (and remove cfg_len member from struct
goodix_ts_data).

The main problem I have is how to assign goodix_chip_data to a ACPI
device (I have very little knowledge about ACPI). I do not know from
where comes 'GDIX1001' ACPI ID and how it corresponds to OF compatible
strings. Can you help me with that?

I have something like that so far:

struct goodix_chip_data {
        u16 config_addr;
        int config_len;
        int config_checksum_len;
};

...

static const goodix_chip_data gt1x_chip_data = {
	.config_addr		= GOODIX_GT1X_REG_CONFIG_DATA,
	.config_len		= GOODIX_CONFIG_MAX_LENGTH,
	.config_checksum_len	= 2,
};

static const goodix_chip_data gt911_chip_data = {
	.config_addr		= GOODIX_GT9X_REG_CONFIG_DATA,
	.config_len		= GOODIX_CONFIG_911_LENGTH,
	.config_checksum_len	= 1,
};

static const goodix_chip_data gt967_chip_data = {
	.config_addr		= GOODIX_GT9X_REG_CONFIG_DATA,
	.config_len		= GOODIX_CONFIG_967_LENGTH,
	.config_checksum_len	= 1,
};

...

static const struct of_device_id goodix_of_match[] = {
	{ .compatible = "goodix,gt1151", .data = &gt1x_chip_data },
	{ .compatible = "goodix,gt911",  .data = &gt911_chip_data },
	{ .compatible = "goodix,gt9110", .data = &gt911_chip_data },
	{ .compatible = "goodix,gt912",  .data = &gt967_chip_data },
	{ .compatible = "goodix,gt927",  .data = &gt911_chip_data },
	{ .compatible = "goodix,gt9271", .data = &gt911_chip_data },
	{ .compatible = "goodix,gt928",  .data = &gt911_chip_data },
	{ .compatible = "goodix,gt967",  .data = &gt967_chip_data },
	{ }
};

-- 
Marcin Niestroj
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
```

## Re: \[PATCH 1/2\] Input: goodix - support gt1151 touchpanel

- From: Dmitry Torokhov \<dmitry.torokhov@gmail.com\>
- Date: 2017-10-19 00:47:41 
- Message: https://ratatoskr.run/linux-input/2017/10/8146009.md

```text
On Tue, Oct 17, 2017 at 11:40:01AM +0200, Marcin Niestroj wrote:
> Hi,
> Thanks everyone for review!
> 
> On 14.10.2017 00:58, Dmitry Torokhov wrote:
> > <...snip...>
> > My preference would be to assign constant chip data, such as register,
> > to the relevant device ID structure (I2C or OF or ACPI) and reference it
> > form where it is needed.
> > 
> > struct goodix_chip_data {
> > 	u16	config_addr;
> > };
> > 
> > ...
> > 
> > struct goodix_ts_data {
> > 	...
> > 	const struct goodix_chip_data *chip;
> > 	...
> > };
> > 
> > ...
> > 
> > static const goodix_chip_data gt1x_chip_data = {
> > 	.config_addr	= GOODIX_GT1X_REG_CONFIG_DATA,
> > };
> > 
> > static const goodix_chip_data gt9x_chip_data = {
> > 	.config_addr	= GOODIX_GT9X_REG_CONFIG_DATA,
> > };
> > 
> > static const struct of_device_id goodix_of_match[] = {
> > 	{ .compatible = "goodix,gt1151", .data = &gt1x_chip_data },
> > 	...
> > };
> > 
> > and so on...
> > 
> > Thanks.
> > 
> 
> This looks good to me. Together with config_addr I would put config_len
> to struct goodix_chip_data (and remove cfg_len member from struct
> goodix_ts_data).
> 
> The main problem I have is how to assign goodix_chip_data to a ACPI
> device (I have very little knowledge about ACPI). I do not know from
> where comes 'GDIX1001' ACPI ID and how it corresponds to OF compatible
> strings. Can you help me with that?

Hmm, wait a second... Looking at the driver we can fetch the product ID
form the chip, so we do not really need to put this into OF or ACPI
tables, but rather set up the "chip" pointer dynamically when we probe
the device.

Thanks.

-- 
Dmitry
```
