Re: [PATCH 1/4] Input/ARM: ads7846: Get pendown IRQ from descriptors

2023-05-03 Thread Dmitry Torokhov
On Sun, Apr 30, 2023 at 11:22:16AM +0200, Linus Walleij wrote:
> The ADS7846 has some limited support for using GPIO descriptors,
> let's convert it over completely and fix all users to provide
> GPIOs in descriptor tables.
> 
> The Nokia 770 now has dynamic allocation of IRQ numbers, so this
> needs to be fixed for it to work.
> 
> Fixes: 92bf78b33b0b ("gpio: omap: use dynamic allocation of base")
> Signed-off-by: Linus Walleij 
> ---
>  arch/arm/mach-omap1/board-nokia770.c | 12 +++-
>  arch/arm/mach-pxa/spitz.c| 11 ++-
>  arch/mips/alchemy/devboards/db1000.c | 11 ++-
>  drivers/input/touchscreen/ads7846.c  | 32 
>  include/linux/spi/ads7846.h  |  2 --
>  5 files changed, 39 insertions(+), 29 deletions(-)
> 
> diff --git a/arch/arm/mach-omap1/board-nokia770.c 
> b/arch/arm/mach-omap1/board-nokia770.c
> index a501a473ffd6..eb7652670447 100644
> --- a/arch/arm/mach-omap1/board-nokia770.c
> +++ b/arch/arm/mach-omap1/board-nokia770.c
> @@ -118,7 +118,16 @@ static struct ads7846_platform_data 
> nokia770_ads7846_platform_data __initdata =
>   .debounce_max   = 10,
>   .debounce_tol   = 3,
>   .debounce_rep   = 1,
> - .gpio_pendown   = ADS7846_PENDOWN_GPIO,
> +};
> +
> +static struct gpiod_lookup_table nokia770_ads7846_gpio_table = {
> + /* SPI bus 2, device with chip select 0 */
> + .dev_id = "spi2.0",
> + .table = {
> + GPIO_LOOKUP("gpio-0-15", ADS7846_PENDOWN_GPIO,
> + "pendown", GPIO_ACTIVE_HIGH),
> + { }
> + },
>  };

I would like to eventually get rid of GPIO_LOOKUP in favor of
PROPERTY_ENTRY_GPIO. Can we try something like the draft below (just
typed, not even compiled):

diff --git a/arch/arm/mach-omap1/board-nokia770.c 
b/arch/arm/mach-omap1/board-nokia770.c
index a501a473ffd6..34b8e392b917 100644
--- a/arch/arm/mach-omap1/board-nokia770.c
+++ b/arch/arm/mach-omap1/board-nokia770.c
@@ -12,6 +12,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 
@@ -35,6 +36,24 @@
 #include "clock.h"
 #include "mmc.h"
 
+static const struct software_node nokia770_mpuio_gpiochip_node = {
+   .name = "mpuio",
+};
+
+static const struct software_node nokia770_gpiochip1_node = {
+   .name = "gpio-0-15",
+};
+
+static const struct software_node nokia770_gpiochip2_node = {
+   .name = "gpio-16-31",
+};
+
+static const struct software_node nokia770_gpiochip_nodes[] = {
+   _mpuio_gpiochip_node
+   _gpiochip1_node,
+   _gpiochip2_node,
+};
+
 #define ADS7846_PENDOWN_GPIO   15
 
 static const unsigned int nokia770_keymap[] = {
@@ -102,6 +121,17 @@ static const struct omap_lcd_config nokia770_lcd_config 
__initconst = {
.ctrl_name  = "hwa742",
 };
 
+static const struct property_entry nokia770_mipid_props[] = {
+   PROPERTY_ENTRY_GPIO("reset-gpios", _gpiochip1_node,
+   13, GPIO_ACTIVE_LOW),
+   { }
+};
+
+static const struct software_node nokia770_mipid_swnode = {
+   .name = "lcd_mipid",
+   .properties = nokia770_mipid_props,
+};
+
 static void __init mipid_dev_init(void)
 {
nokia770_mipid_platform_data.nreset_gpio = 13;
@@ -110,15 +140,22 @@ static void __init mipid_dev_init(void)
omapfb_set_lcd_config(_lcd_config);
 }
 
-static struct ads7846_platform_data nokia770_ads7846_platform_data __initdata 
= {
-   .x_max  = 0x0fff,
-   .y_max  = 0x0fff,
-   .x_plate_ohms   = 180,
-   .pressure_max   = 255,
-   .debounce_max   = 10,
-   .debounce_tol   = 3,
-   .debounce_rep   = 1,
-   .gpio_pendown   = ADS7846_PENDOWN_GPIO,
+static const struct property_entry nokia770_ads7846_props[] = {
+   PROPERTY_ENTRY_U32("touchscreen-size-x", 4096),
+   PROPERTY_ENTRY_U32("touchscreen-size-y", 4096),
+   PROPERTY_ENTRY_U32("touchscreen-max-pressure", 256),
+   PROPERTY_ENTRY_U32("touchscreen-average-samples", 10),
+   PROPERTY_ENTRY_U16("ti,x-plate-ohms", 180),
+   PROPERTY_ENTRY_U16("ti,debounce-tol", 3),
+   PROPERTY_ENTRY_U16("ti,debounce-rep", 1),
+   PROPERTY_ENTRY_GPIO("pendown-gpios", _gpiochip1_node,
+   ADS7846_PENDOWN_GPIO, GPIO_ACTIVE_HIGH),
+   { }
+};
+
+static const struct software_node nokia770_ads7846_swnode = {
+   .name = "ads7846",
+   .properties = nokia770_ads7846_props,
 };
 
 static struct spi_board_info nokia770_spi_board_info[] __initdata = {
@@ -128,13 +165,14 @@ static struct spi_board_info nokia770_spi_board_info[] 
__initdata = {
.chip_select= 3,
.max_speed_hz   = 1200,
.platform_data  = _mipid_platform_data,
+   .swnode = _mipid_swnode,
},
[1] = {
.modalias   = "ads7846",
.bus_num= 2,
.chip_select= 0,
.max_speed_hz   = 250,
-   .platform_data  = 

[PATCH 1/4] Input/ARM: ads7846: Get pendown IRQ from descriptors

2023-04-30 Thread Linus Walleij
The ADS7846 has some limited support for using GPIO descriptors,
let's convert it over completely and fix all users to provide
GPIOs in descriptor tables.

The Nokia 770 now has dynamic allocation of IRQ numbers, so this
needs to be fixed for it to work.

Fixes: 92bf78b33b0b ("gpio: omap: use dynamic allocation of base")
Signed-off-by: Linus Walleij 
---
 arch/arm/mach-omap1/board-nokia770.c | 12 +++-
 arch/arm/mach-pxa/spitz.c| 11 ++-
 arch/mips/alchemy/devboards/db1000.c | 11 ++-
 drivers/input/touchscreen/ads7846.c  | 32 
 include/linux/spi/ads7846.h  |  2 --
 5 files changed, 39 insertions(+), 29 deletions(-)

diff --git a/arch/arm/mach-omap1/board-nokia770.c 
b/arch/arm/mach-omap1/board-nokia770.c
index a501a473ffd6..eb7652670447 100644
--- a/arch/arm/mach-omap1/board-nokia770.c
+++ b/arch/arm/mach-omap1/board-nokia770.c
@@ -118,7 +118,16 @@ static struct ads7846_platform_data 
nokia770_ads7846_platform_data __initdata =
.debounce_max   = 10,
.debounce_tol   = 3,
.debounce_rep   = 1,
-   .gpio_pendown   = ADS7846_PENDOWN_GPIO,
+};
+
+static struct gpiod_lookup_table nokia770_ads7846_gpio_table = {
+   /* SPI bus 2, device with chip select 0 */
+   .dev_id = "spi2.0",
+   .table = {
+   GPIO_LOOKUP("gpio-0-15", ADS7846_PENDOWN_GPIO,
+   "pendown", GPIO_ACTIVE_HIGH),
+   { }
+   },
 };
 
 static struct spi_board_info nokia770_spi_board_info[] __initdata = {
@@ -274,6 +283,7 @@ static void __init omap_nokia770_init(void)
omap_writew((omap_readw(0xfffb5004) & ~2), 0xfffb5004);
 
platform_add_devices(nokia770_devices, ARRAY_SIZE(nokia770_devices));
+   gpiod_add_lookup_table(_ads7846_gpio_table);
nokia770_spi_board_info[1].irq = gpio_to_irq(15);
spi_register_board_info(nokia770_spi_board_info,
ARRAY_SIZE(nokia770_spi_board_info));
diff --git a/arch/arm/mach-pxa/spitz.c b/arch/arm/mach-pxa/spitz.c
index 26f0ebc4d136..4d2a72804495 100644
--- a/arch/arm/mach-pxa/spitz.c
+++ b/arch/arm/mach-pxa/spitz.c
@@ -505,10 +505,18 @@ static struct ads7846_platform_data spitz_ads7846_info = {
.x_plate_ohms   = 419,
.y_plate_ohms   = 486,
.pressure_max   = 1024,
-   .gpio_pendown   = SPITZ_GPIO_TP_INT,
.wait_for_sync  = spitz_ads7846_wait_for_hsync,
 };
 
+static struct gpiod_lookup_table spitz_ads7846_gpio_table = {
+   .dev_id = "spi2.0",
+   .table = {
+   GPIO_LOOKUP("gpio-pxa", SPITZ_GPIO_TP_INT,
+   "pendown", GPIO_ACTIVE_HIGH),
+   { },
+   },
+};
+
 static void spitz_bl_kick_battery(void)
 {
void (*kick_batt)(void);
@@ -593,6 +601,7 @@ static void __init spitz_spi_init(void)
else
gpiod_add_lookup_table(_lcdcon_gpio_table);
 
+   gpiod_add_lookup_table(_ads7846_gpio_table);
gpiod_add_lookup_table(_spi_gpio_table);
pxa2xx_set_spi_info(2, _spi_info);
spi_register_board_info(ARRAY_AND_SIZE(spitz_spi_devices));
diff --git a/arch/mips/alchemy/devboards/db1000.c 
b/arch/mips/alchemy/devboards/db1000.c
index 2c52ee27b4f2..f37644859f89 100644
--- a/arch/mips/alchemy/devboards/db1000.c
+++ b/arch/mips/alchemy/devboards/db1000.c
@@ -381,13 +381,21 @@ static struct platform_device db1100_mmc1_dev = {
 static struct ads7846_platform_data db1100_touch_pd = {
.model  = 7846,
.vref_mv= 3300,
-   .gpio_pendown   = 21,
 };
 
 static struct spi_gpio_platform_data db1100_spictl_pd = {
.num_chipselect = 1,
 };
 
+static struct gpiod_lookup_table db1100_touch_gpio_table = {
+   .dev_id = "spi0.0",
+   .table = {
+   GPIO_LOOKUP("alchemy-gpio2", 21,
+   "pendown", GPIO_ACTIVE_HIGH),
+   { },
+   },
+};
+
 static struct spi_board_info db1100_spi_info[] __initdata = {
[0] = {
.modalias= "ads7846",
@@ -474,6 +482,7 @@ int __init db1000_dev_setup(void)
pfc |= (1 << 0);/* SSI0 pins as GPIOs */
alchemy_wrsys(pfc, AU1000_SYS_PINFUNC);
 
+   gpiod_add_lookup_table(_touch_gpio_table);
spi_register_board_info(db1100_spi_info,
ARRAY_SIZE(db1100_spi_info));
 
diff --git a/drivers/input/touchscreen/ads7846.c 
b/drivers/input/touchscreen/ads7846.c
index bb1058b1e7fd..a3c623009247 100644
--- a/drivers/input/touchscreen/ads7846.c
+++ b/drivers/input/touchscreen/ads7846.c
@@ -25,10 +25,8 @@
 #include 
 #include 
 #include 
-#include 
 #include 
 #include 
-#include 
 #include 
 #include 
 #include 
@@ -140,7 +138,7 @@ struct ads7846 {
int (*filter)(void *data, int data_idx, int *val);
void*filter_data;
int