Re: [PATCH 10/12] platform/chrome: chromeos_laptop - Prepare complete software nodes

2021-03-30 Thread Enric Balletbo i Serra
Hi Heikki,

Thank you for your patch.

On 29/3/21 12:50, Heikki Krogerus wrote:
> The older device property API is going to be removed soon
> and that will affect also I2C subystem. Supplying complete
> software nodes instead of only the properties in them for
> the I2C devices.
> 
> Signed-off-by: Heikki Krogerus 
> Cc: Benson Leung 
> Cc: Enric Balletbo i Serra 

Acked-by: Enric Balletbo i Serra 

> ---
>  drivers/platform/chrome/chromeos_laptop.c | 100 +-
>  1 file changed, 60 insertions(+), 40 deletions(-)
> 
> diff --git a/drivers/platform/chrome/chromeos_laptop.c 
> b/drivers/platform/chrome/chromeos_laptop.c
> index 472a03daa8693..4e14b4d6635d7 100644
> --- a/drivers/platform/chrome/chromeos_laptop.c
> +++ b/drivers/platform/chrome/chromeos_laptop.c
> @@ -52,12 +52,15 @@ struct i2c_peripheral {
>   enum i2c_adapter_type type;
>   u32 pci_devid;
>  
> + const struct property_entry *properties;
> +
>   struct i2c_client *client;
>  };
>  
>  struct acpi_peripheral {
>   char hid[ACPI_ID_LEN];
> - const struct property_entry *properties;
> + struct software_node swnode;
> + struct i2c_client *client;
>  };
>  
>  struct chromeos_laptop {
> @@ -68,7 +71,7 @@ struct chromeos_laptop {
>   struct i2c_peripheral *i2c_peripherals;
>   unsigned int num_i2c_peripherals;
>  
> - const struct acpi_peripheral *acpi_peripherals;
> + struct acpi_peripheral *acpi_peripherals;
>   unsigned int num_acpi_peripherals;
>  };
>  
> @@ -161,7 +164,7 @@ static void chromeos_laptop_check_adapter(struct 
> i2c_adapter *adapter)
>  
>  static bool chromeos_laptop_adjust_client(struct i2c_client *client)
>  {
> - const struct acpi_peripheral *acpi_dev;
> + struct acpi_peripheral *acpi_dev;
>   struct acpi_device_id acpi_ids[2] = { };
>   int i;
>   int error;
> @@ -175,8 +178,7 @@ static bool chromeos_laptop_adjust_client(struct 
> i2c_client *client)
>   memcpy(acpi_ids[0].id, acpi_dev->hid, ACPI_ID_LEN);
>  
>   if (acpi_match_device(acpi_ids, >dev)) {
> - error = device_add_properties(>dev,
> -   acpi_dev->properties);
> + error = device_add_software_node(>dev, 
> _dev->swnode);
>   if (error) {
>   dev_err(>dev,
>   "failed to add properties: %d\n",
> @@ -184,6 +186,8 @@ static bool chromeos_laptop_adjust_client(struct 
> i2c_client *client)
>   break;
>   }
>  
> + acpi_dev->client = client;
> +
>   return true;
>   }
>   }
> @@ -193,15 +197,28 @@ static bool chromeos_laptop_adjust_client(struct 
> i2c_client *client)
>  
>  static void chromeos_laptop_detach_i2c_client(struct i2c_client *client)
>  {
> + struct acpi_peripheral *acpi_dev;
>   struct i2c_peripheral *i2c_dev;
>   int i;
>  
> - for (i = 0; i < cros_laptop->num_i2c_peripherals; i++) {
> - i2c_dev = _laptop->i2c_peripherals[i];
> + if (has_acpi_companion(>dev))
> + for (i = 0; i < cros_laptop->num_acpi_peripherals; i++) {
> + acpi_dev = _laptop->acpi_peripherals[i];
>  
> - if (i2c_dev->client == client)
> - i2c_dev->client = NULL;
> - }
> + if (acpi_dev->client == client) {
> + acpi_dev->client = NULL;
> + return;
> + }
> + }
> + else
> + for (i = 0; i < cros_laptop->num_i2c_peripherals; i++) {
> + i2c_dev = _laptop->i2c_peripherals[i];
> +
> + if (i2c_dev->client == client) {
> + i2c_dev->client = NULL;
> + return;
> + }
> + }
>  }
>  
>  static int chromeos_laptop_i2c_notifier_call(struct notifier_block *nb,
> @@ -302,28 +319,26 @@ static struct i2c_peripheral 
> chromebook_pixel_peripherals[] __initdata = {
>   .board_info = {
>   I2C_BOARD_INFO("atmel_mxt_ts",
>   ATMEL_TS_I2C_ADDR),
> - .properties =
> - chromebook_atmel_touchscreen_props,
>   .flags  = I2C_CLIENT_WAKE,
>   },
>   .dmi_name   = "touchscreen",
>   .irqflags   = IRQF_TRIGGER_FALLING,
>   .type   = I2C_ADAPTER_PANEL,
>   .alt_addr   = ATMEL_TS_I2C_BL_ADDR,
> + .properties = chromebook_atmel_touchscreen_props,
>   },
>   /* Touchpad. */
>   {
>   .board_info = {
>   I2C_BOARD_INFO("atmel_mxt_tp",
>   ATMEL_TP_I2C_ADDR),
> - 

[PATCH 10/12] platform/chrome: chromeos_laptop - Prepare complete software nodes

2021-03-29 Thread Heikki Krogerus
The older device property API is going to be removed soon
and that will affect also I2C subystem. Supplying complete
software nodes instead of only the properties in them for
the I2C devices.

Signed-off-by: Heikki Krogerus 
Cc: Benson Leung 
Cc: Enric Balletbo i Serra 
---
 drivers/platform/chrome/chromeos_laptop.c | 100 +-
 1 file changed, 60 insertions(+), 40 deletions(-)

diff --git a/drivers/platform/chrome/chromeos_laptop.c 
b/drivers/platform/chrome/chromeos_laptop.c
index 472a03daa8693..4e14b4d6635d7 100644
--- a/drivers/platform/chrome/chromeos_laptop.c
+++ b/drivers/platform/chrome/chromeos_laptop.c
@@ -52,12 +52,15 @@ struct i2c_peripheral {
enum i2c_adapter_type type;
u32 pci_devid;
 
+   const struct property_entry *properties;
+
struct i2c_client *client;
 };
 
 struct acpi_peripheral {
char hid[ACPI_ID_LEN];
-   const struct property_entry *properties;
+   struct software_node swnode;
+   struct i2c_client *client;
 };
 
 struct chromeos_laptop {
@@ -68,7 +71,7 @@ struct chromeos_laptop {
struct i2c_peripheral *i2c_peripherals;
unsigned int num_i2c_peripherals;
 
-   const struct acpi_peripheral *acpi_peripherals;
+   struct acpi_peripheral *acpi_peripherals;
unsigned int num_acpi_peripherals;
 };
 
@@ -161,7 +164,7 @@ static void chromeos_laptop_check_adapter(struct 
i2c_adapter *adapter)
 
 static bool chromeos_laptop_adjust_client(struct i2c_client *client)
 {
-   const struct acpi_peripheral *acpi_dev;
+   struct acpi_peripheral *acpi_dev;
struct acpi_device_id acpi_ids[2] = { };
int i;
int error;
@@ -175,8 +178,7 @@ static bool chromeos_laptop_adjust_client(struct i2c_client 
*client)
memcpy(acpi_ids[0].id, acpi_dev->hid, ACPI_ID_LEN);
 
if (acpi_match_device(acpi_ids, >dev)) {
-   error = device_add_properties(>dev,
- acpi_dev->properties);
+   error = device_add_software_node(>dev, 
_dev->swnode);
if (error) {
dev_err(>dev,
"failed to add properties: %d\n",
@@ -184,6 +186,8 @@ static bool chromeos_laptop_adjust_client(struct i2c_client 
*client)
break;
}
 
+   acpi_dev->client = client;
+
return true;
}
}
@@ -193,15 +197,28 @@ static bool chromeos_laptop_adjust_client(struct 
i2c_client *client)
 
 static void chromeos_laptop_detach_i2c_client(struct i2c_client *client)
 {
+   struct acpi_peripheral *acpi_dev;
struct i2c_peripheral *i2c_dev;
int i;
 
-   for (i = 0; i < cros_laptop->num_i2c_peripherals; i++) {
-   i2c_dev = _laptop->i2c_peripherals[i];
+   if (has_acpi_companion(>dev))
+   for (i = 0; i < cros_laptop->num_acpi_peripherals; i++) {
+   acpi_dev = _laptop->acpi_peripherals[i];
 
-   if (i2c_dev->client == client)
-   i2c_dev->client = NULL;
-   }
+   if (acpi_dev->client == client) {
+   acpi_dev->client = NULL;
+   return;
+   }
+   }
+   else
+   for (i = 0; i < cros_laptop->num_i2c_peripherals; i++) {
+   i2c_dev = _laptop->i2c_peripherals[i];
+
+   if (i2c_dev->client == client) {
+   i2c_dev->client = NULL;
+   return;
+   }
+   }
 }
 
 static int chromeos_laptop_i2c_notifier_call(struct notifier_block *nb,
@@ -302,28 +319,26 @@ static struct i2c_peripheral 
chromebook_pixel_peripherals[] __initdata = {
.board_info = {
I2C_BOARD_INFO("atmel_mxt_ts",
ATMEL_TS_I2C_ADDR),
-   .properties =
-   chromebook_atmel_touchscreen_props,
.flags  = I2C_CLIENT_WAKE,
},
.dmi_name   = "touchscreen",
.irqflags   = IRQF_TRIGGER_FALLING,
.type   = I2C_ADAPTER_PANEL,
.alt_addr   = ATMEL_TS_I2C_BL_ADDR,
+   .properties = chromebook_atmel_touchscreen_props,
},
/* Touchpad. */
{
.board_info = {
I2C_BOARD_INFO("atmel_mxt_tp",
ATMEL_TP_I2C_ADDR),
-   .properties =
-   chromebook_pixel_trackpad_props,
.flags  = I2C_CLIENT_WAKE,
},
.dmi_name   = "trackpad",