platform-driver-x86.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v1 1/5] serdev: Split and export serdev_acpi_get_uart_resource()
@ 2021-08-03 19:29 Andy Shevchenko
  2021-08-03 19:29 ` [PATCH v1 2/5] platform/surface: aggregator: Use serdev_acpi_get_uart_resource() helper Andy Shevchenko
                   ` (4 more replies)
  0 siblings, 5 replies; 12+ messages in thread
From: Andy Shevchenko @ 2021-08-03 19:29 UTC (permalink / raw)
  To: Andy Shevchenko, Hans de Goede, Maximilian Luz, Lee Jones,
	Greg Kroah-Hartman, linux-bluetooth, linux-kernel,
	platform-driver-x86, linux-serial
  Cc: Marcel Holtmann, Johan Hedberg, Luiz Augusto von Dentz,
	Mark Gross, Rob Herring, Jiri Slaby

The same as for I²C Serial Bus resource split and export
serdev_acpi_get_uart_resource(). We have already 3 users
one of which is converted here.

Rationale of this is to consolidate parsing UART Serial Bus
resource in one place as it's done, e.g., for I²C Serial Bus.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 drivers/tty/serdev/core.c | 36 +++++++++++++++++++++++++++++-------
 include/linux/serdev.h    | 14 ++++++++++++++
 2 files changed, 43 insertions(+), 7 deletions(-)

diff --git a/drivers/tty/serdev/core.c b/drivers/tty/serdev/core.c
index 92498961fd92..436e3d1ba92c 100644
--- a/drivers/tty/serdev/core.c
+++ b/drivers/tty/serdev/core.c
@@ -562,23 +562,45 @@ struct acpi_serdev_lookup {
 	int index;
 };
 
+/**
+ * serdev_acpi_get_uart_resource - Gets UARTSerialBus resource if type matches
+ * @ares:	ACPI resource
+ * @uart:	Pointer to UARTSerialBus resource will be returned here
+ *
+ * Checks if the given ACPI resource is of type UARTSerialBus.
+ * In this case, returns a pointer to it to the caller.
+ *
+ * Returns true if resource type is of UARTSerialBus, otherwise false.
+ */
+bool serdev_acpi_get_uart_resource(struct acpi_resource *ares,
+				   struct acpi_resource_uart_serialbus **uart)
+{
+	struct acpi_resource_uart_serialbus *sb;
+
+	if (ares->type != ACPI_RESOURCE_TYPE_SERIAL_BUS)
+		return false;
+
+	sb = &ares->data.uart_serial_bus;
+	if (sb->type != ACPI_RESOURCE_SERIAL_TYPE_UART)
+		return false;
+
+	*uart = sb;
+	return true;
+}
+EXPORT_SYMBOL_GPL(serdev_acpi_get_uart_resource);
+
 static int acpi_serdev_parse_resource(struct acpi_resource *ares, void *data)
 {
 	struct acpi_serdev_lookup *lookup = data;
 	struct acpi_resource_uart_serialbus *sb;
 	acpi_status status;
 
-	if (ares->type != ACPI_RESOURCE_TYPE_SERIAL_BUS)
-		return 1;
-
-	if (ares->data.common_serial_bus.type != ACPI_RESOURCE_SERIAL_TYPE_UART)
+	if (!serdev_acpi_get_uart_resource(ares, &sb))
 		return 1;
 
 	if (lookup->index != -1 && lookup->n++ != lookup->index)
 		return 1;
 
-	sb = &ares->data.uart_serial_bus;
-
 	status = acpi_get_handle(lookup->device_handle,
 				 sb->resource_source.string_ptr,
 				 &lookup->controller_handle);
@@ -586,7 +608,7 @@ static int acpi_serdev_parse_resource(struct acpi_resource *ares, void *data)
 		return 1;
 
 	/*
-	 * NOTE: Ideally, we would also want to retreive other properties here,
+	 * NOTE: Ideally, we would also want to retrieve other properties here,
 	 * once setting them before opening the device is supported by serdev.
 	 */
 
diff --git a/include/linux/serdev.h b/include/linux/serdev.h
index 9f14f9c12ec4..3368c261ab62 100644
--- a/include/linux/serdev.h
+++ b/include/linux/serdev.h
@@ -327,4 +327,18 @@ static inline int serdev_tty_port_unregister(struct tty_port *port)
 }
 #endif /* CONFIG_SERIAL_DEV_CTRL_TTYPORT */
 
+struct acpi_resource;
+struct acpi_resource_uart_serialbus;
+
+#ifdef CONFIG_ACPI
+bool serdev_acpi_get_uart_resource(struct acpi_resource *ares,
+				   struct acpi_resource_uart_serialbus **uart);
+#else
+static inline bool serdev_acpi_get_uart_resource(struct acpi_resource *ares,
+						 struct acpi_resource_uart_serialbus **uart)
+{
+	return false;
+}
+#endif /* CONFIG_ACPI */
+
 #endif /*_LINUX_SERDEV_H */
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH v1 2/5] platform/surface: aggregator: Use serdev_acpi_get_uart_resource() helper
  2021-08-03 19:29 [PATCH v1 1/5] serdev: Split and export serdev_acpi_get_uart_resource() Andy Shevchenko
@ 2021-08-03 19:29 ` Andy Shevchenko
  2021-08-03 19:47   ` Maximilian Luz
  2021-08-03 19:29 ` [PATCH v1 3/5] Bluetooth: hci_bcm: " Andy Shevchenko
                   ` (3 subsequent siblings)
  4 siblings, 1 reply; 12+ messages in thread
From: Andy Shevchenko @ 2021-08-03 19:29 UTC (permalink / raw)
  To: Andy Shevchenko, Hans de Goede, Maximilian Luz, Lee Jones,
	Greg Kroah-Hartman, linux-bluetooth, linux-kernel,
	platform-driver-x86, linux-serial
  Cc: Marcel Holtmann, Johan Hedberg, Luiz Augusto von Dentz,
	Mark Gross, Rob Herring, Jiri Slaby

serdev provides a generic helper to get UART Serial Bus resources.
Use it instead of open coded variant.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 drivers/platform/surface/aggregator/core.c | 9 +--------
 1 file changed, 1 insertion(+), 8 deletions(-)

diff --git a/drivers/platform/surface/aggregator/core.c b/drivers/platform/surface/aggregator/core.c
index 279d9df19c01..c61bbeeec2df 100644
--- a/drivers/platform/surface/aggregator/core.c
+++ b/drivers/platform/surface/aggregator/core.c
@@ -301,20 +301,13 @@ static acpi_status ssam_serdev_setup_via_acpi_crs(struct acpi_resource *rsc,
 						  void *ctx)
 {
 	struct serdev_device *serdev = ctx;
-	struct acpi_resource_common_serialbus *serial;
 	struct acpi_resource_uart_serialbus *uart;
 	bool flow_control;
 	int status = 0;
 
-	if (rsc->type != ACPI_RESOURCE_TYPE_SERIAL_BUS)
+	if (!serdev_acpi_get_uart_resource(rsc, &uart))
 		return AE_OK;
 
-	serial = &rsc->data.common_serial_bus;
-	if (serial->type != ACPI_RESOURCE_SERIAL_TYPE_UART)
-		return AE_OK;
-
-	uart = &rsc->data.uart_serial_bus;
-
 	/* Set up serdev device. */
 	serdev_device_set_baudrate(serdev, uart->default_baud_rate);
 
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH v1 3/5] Bluetooth: hci_bcm: Use serdev_acpi_get_uart_resource() helper
  2021-08-03 19:29 [PATCH v1 1/5] serdev: Split and export serdev_acpi_get_uart_resource() Andy Shevchenko
  2021-08-03 19:29 ` [PATCH v1 2/5] platform/surface: aggregator: Use serdev_acpi_get_uart_resource() helper Andy Shevchenko
@ 2021-08-03 19:29 ` Andy Shevchenko
  2021-08-04  8:12   ` Hans de Goede
  2021-08-03 19:29 ` [PATCH v1 4/5] Bluetooth: hci_bcm: Use acpi_gpio_get_*_resource() helpers Andy Shevchenko
                   ` (2 subsequent siblings)
  4 siblings, 1 reply; 12+ messages in thread
From: Andy Shevchenko @ 2021-08-03 19:29 UTC (permalink / raw)
  To: Andy Shevchenko, Hans de Goede, Maximilian Luz, Lee Jones,
	Greg Kroah-Hartman, linux-bluetooth, linux-kernel,
	platform-driver-x86, linux-serial
  Cc: Marcel Holtmann, Johan Hedberg, Luiz Augusto von Dentz,
	Mark Gross, Rob Herring, Jiri Slaby

serdev provides a generic helper to get UART Serial Bus resources.
Use it instead of open coded variant.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 drivers/bluetooth/hci_bcm.c | 15 ++++++---------
 1 file changed, 6 insertions(+), 9 deletions(-)

diff --git a/drivers/bluetooth/hci_bcm.c b/drivers/bluetooth/hci_bcm.c
index 3cd57fc56ade..16f854ac19b6 100644
--- a/drivers/bluetooth/hci_bcm.c
+++ b/drivers/bluetooth/hci_bcm.c
@@ -899,9 +899,9 @@ static const struct acpi_gpio_mapping acpi_bcm_int_first_gpios[] = {
 static int bcm_resource(struct acpi_resource *ares, void *data)
 {
 	struct bcm_device *dev = data;
+	struct acpi_resource_uart_serialbus *uart;
 	struct acpi_resource_extended_irq *irq;
 	struct acpi_resource_gpio *gpio;
-	struct acpi_resource_uart_serialbus *sb;
 
 	switch (ares->type) {
 	case ACPI_RESOURCE_TYPE_EXTENDED_IRQ:
@@ -920,18 +920,15 @@ static int bcm_resource(struct acpi_resource *ares, void *data)
 		dev->gpio_count++;
 		break;
 
-	case ACPI_RESOURCE_TYPE_SERIAL_BUS:
-		sb = &ares->data.uart_serial_bus;
-		if (sb->type == ACPI_RESOURCE_SERIAL_TYPE_UART) {
-			dev->init_speed = sb->default_baud_rate;
-			dev->oper_speed = 4000000;
-		}
-		break;
-
 	default:
 		break;
 	}
 
+	if (serdev_acpi_get_uart_resource(ares, &uart)) {
+		dev->init_speed = uart->default_baud_rate;
+		dev->oper_speed = 4000000;
+	}
+
 	return 0;
 }
 
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH v1 4/5] Bluetooth: hci_bcm: Use acpi_gpio_get_*_resource() helpers
  2021-08-03 19:29 [PATCH v1 1/5] serdev: Split and export serdev_acpi_get_uart_resource() Andy Shevchenko
  2021-08-03 19:29 ` [PATCH v1 2/5] platform/surface: aggregator: Use serdev_acpi_get_uart_resource() helper Andy Shevchenko
  2021-08-03 19:29 ` [PATCH v1 3/5] Bluetooth: hci_bcm: " Andy Shevchenko
@ 2021-08-03 19:29 ` Andy Shevchenko
  2021-08-04  8:04   ` Hans de Goede
  2021-08-03 19:29 ` [PATCH v1 5/5] Bluetooth: hci_bcm: Fix kernel doc comments Andy Shevchenko
  2021-08-04  8:08 ` [PATCH v1 1/5] serdev: Split and export serdev_acpi_get_uart_resource() Hans de Goede
  4 siblings, 1 reply; 12+ messages in thread
From: Andy Shevchenko @ 2021-08-03 19:29 UTC (permalink / raw)
  To: Andy Shevchenko, Hans de Goede, Maximilian Luz, Lee Jones,
	Greg Kroah-Hartman, linux-bluetooth, linux-kernel,
	platform-driver-x86, linux-serial
  Cc: Marcel Holtmann, Johan Hedberg, Luiz Augusto von Dentz,
	Mark Gross, Rob Herring, Jiri Slaby

ACPI provides generic helpers to get GPIO interrupt and IO resources.
Use it instead of open coded variant.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 drivers/bluetooth/hci_bcm.c | 15 ++++++---------
 1 file changed, 6 insertions(+), 9 deletions(-)

diff --git a/drivers/bluetooth/hci_bcm.c b/drivers/bluetooth/hci_bcm.c
index 16f854ac19b6..ed99fcde2523 100644
--- a/drivers/bluetooth/hci_bcm.c
+++ b/drivers/bluetooth/hci_bcm.c
@@ -911,15 +911,6 @@ static int bcm_resource(struct acpi_resource *ares, void *data)
 		dev->irq_active_low = true;
 		break;
 
-	case ACPI_RESOURCE_TYPE_GPIO:
-		gpio = &ares->data.gpio;
-		if (gpio->connection_type == ACPI_RESOURCE_GPIO_TYPE_INT) {
-			dev->gpio_int_idx = dev->gpio_count;
-			dev->irq_active_low = gpio->polarity == ACPI_ACTIVE_LOW;
-		}
-		dev->gpio_count++;
-		break;
-
 	default:
 		break;
 	}
@@ -927,6 +918,12 @@ static int bcm_resource(struct acpi_resource *ares, void *data)
 	if (serdev_acpi_get_uart_resource(ares, &uart)) {
 		dev->init_speed = uart->default_baud_rate;
 		dev->oper_speed = 4000000;
+	} else if (acpi_gpio_get_irq_resource(ares, &gpio)) {
+		dev->gpio_int_idx = dev->gpio_count;
+		dev->irq_active_low = gpio->polarity == ACPI_ACTIVE_LOW;
+		dev->gpio_count++;
+	} else if (acpi_gpio_get_io_resource(ares, &gpio)) {
+		dev->gpio_count++;
 	}
 
 	return 0;
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH v1 5/5] Bluetooth: hci_bcm: Fix kernel doc comments
  2021-08-03 19:29 [PATCH v1 1/5] serdev: Split and export serdev_acpi_get_uart_resource() Andy Shevchenko
                   ` (2 preceding siblings ...)
  2021-08-03 19:29 ` [PATCH v1 4/5] Bluetooth: hci_bcm: Use acpi_gpio_get_*_resource() helpers Andy Shevchenko
@ 2021-08-03 19:29 ` Andy Shevchenko
  2021-08-04  8:08 ` [PATCH v1 1/5] serdev: Split and export serdev_acpi_get_uart_resource() Hans de Goede
  4 siblings, 0 replies; 12+ messages in thread
From: Andy Shevchenko @ 2021-08-03 19:29 UTC (permalink / raw)
  To: Andy Shevchenko, Hans de Goede, Maximilian Luz, Lee Jones,
	Greg Kroah-Hartman, linux-bluetooth, linux-kernel,
	platform-driver-x86, linux-serial
  Cc: Marcel Holtmann, Johan Hedberg, Luiz Augusto von Dentz,
	Mark Gross, Rob Herring, Jiri Slaby

Kernel doc validator complains about few missed parameter descriptions.
Fill the gap by describing them.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 drivers/bluetooth/hci_bcm.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/drivers/bluetooth/hci_bcm.c b/drivers/bluetooth/hci_bcm.c
index ed99fcde2523..fd0acadb9102 100644
--- a/drivers/bluetooth/hci_bcm.c
+++ b/drivers/bluetooth/hci_bcm.c
@@ -51,6 +51,7 @@
 /**
  * struct bcm_device_data - device specific data
  * @no_early_set_baudrate: Disallow set baudrate before driver setup()
+ * @drive_rts_on_open: drive RTS signal on ->open() when platform requires it
  */
 struct bcm_device_data {
 	bool	no_early_set_baudrate;
@@ -77,6 +78,8 @@ struct bcm_device_data {
  * @btlp: Apple ACPI method to toggle BT_WAKE pin ("Bluetooth Low Power")
  * @btpu: Apple ACPI method to drive BT_REG_ON pin high ("Bluetooth Power Up")
  * @btpd: Apple ACPI method to drive BT_REG_ON pin low ("Bluetooth Power Down")
+ * @gpio_count: internal counter for GPIO resources associated with ACPI device
+ * @gpio_int_idx: index in _CRS for GpioInt() resource
  * @txco_clk: external reference frequency clock used by Bluetooth device
  * @lpo_clk: external LPO clock used by Bluetooth device
  * @supplies: VBAT and VDDIO supplies used by Bluetooth device
@@ -88,10 +91,13 @@ struct bcm_device_data {
  *	set to 0 if @init_speed is already the preferred baudrate
  * @irq: interrupt triggered by HOST_WAKE_BT pin
  * @irq_active_low: whether @irq is active low
+ * @irq_acquired: flag to show if IRQ handler has been assigned
  * @hu: pointer to HCI UART controller struct,
  *	used to disable flow control during runtime suspend and system sleep
  * @is_suspended: whether flow control is currently disabled
  * @no_early_set_baudrate: don't set_baudrate before setup()
+ * @drive_rts_on_open: drive RTS signal on ->open() when platform requires it
+ * @pcm_int_params: keep the initial PCM configuration
  */
 struct bcm_device {
 	/* Must be the first member, hci_serdev.c expects this. */
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 12+ messages in thread

* Re: [PATCH v1 2/5] platform/surface: aggregator: Use serdev_acpi_get_uart_resource() helper
  2021-08-03 19:29 ` [PATCH v1 2/5] platform/surface: aggregator: Use serdev_acpi_get_uart_resource() helper Andy Shevchenko
@ 2021-08-03 19:47   ` Maximilian Luz
  0 siblings, 0 replies; 12+ messages in thread
From: Maximilian Luz @ 2021-08-03 19:47 UTC (permalink / raw)
  To: Andy Shevchenko, Hans de Goede, Lee Jones, Greg Kroah-Hartman,
	linux-bluetooth, linux-kernel, platform-driver-x86, linux-serial
  Cc: Marcel Holtmann, Johan Hedberg, Luiz Augusto von Dentz,
	Mark Gross, Rob Herring, Jiri Slaby

On 8/3/21 9:29 PM, Andy Shevchenko wrote:
> serdev provides a generic helper to get UART Serial Bus resources.
> Use it instead of open coded variant.
> 
> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>

Thanks! Looks good to me.

Reviewed-by: Maximilian Luz <luzmaximilian@gmail.com>

> ---
>   drivers/platform/surface/aggregator/core.c | 9 +--------
>   1 file changed, 1 insertion(+), 8 deletions(-)
> 
> diff --git a/drivers/platform/surface/aggregator/core.c b/drivers/platform/surface/aggregator/core.c
> index 279d9df19c01..c61bbeeec2df 100644
> --- a/drivers/platform/surface/aggregator/core.c
> +++ b/drivers/platform/surface/aggregator/core.c
> @@ -301,20 +301,13 @@ static acpi_status ssam_serdev_setup_via_acpi_crs(struct acpi_resource *rsc,
>   						  void *ctx)
>   {
>   	struct serdev_device *serdev = ctx;
> -	struct acpi_resource_common_serialbus *serial;
>   	struct acpi_resource_uart_serialbus *uart;
>   	bool flow_control;
>   	int status = 0;
>   
> -	if (rsc->type != ACPI_RESOURCE_TYPE_SERIAL_BUS)
> +	if (!serdev_acpi_get_uart_resource(rsc, &uart))
>   		return AE_OK;
>   
> -	serial = &rsc->data.common_serial_bus;
> -	if (serial->type != ACPI_RESOURCE_SERIAL_TYPE_UART)
> -		return AE_OK;
> -
> -	uart = &rsc->data.uart_serial_bus;
> -
>   	/* Set up serdev device. */
>   	serdev_device_set_baudrate(serdev, uart->default_baud_rate);
>   
> 

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH v1 4/5] Bluetooth: hci_bcm: Use acpi_gpio_get_*_resource() helpers
  2021-08-03 19:29 ` [PATCH v1 4/5] Bluetooth: hci_bcm: Use acpi_gpio_get_*_resource() helpers Andy Shevchenko
@ 2021-08-04  8:04   ` Hans de Goede
  0 siblings, 0 replies; 12+ messages in thread
From: Hans de Goede @ 2021-08-04  8:04 UTC (permalink / raw)
  To: Andy Shevchenko, Maximilian Luz, Lee Jones, Greg Kroah-Hartman,
	linux-bluetooth, linux-kernel, platform-driver-x86, linux-serial
  Cc: Marcel Holtmann, Johan Hedberg, Luiz Augusto von Dentz,
	Mark Gross, Rob Herring, Jiri Slaby

Hi,

On 8/3/21 9:29 PM, Andy Shevchenko wrote:
> ACPI provides generic helpers to get GPIO interrupt and IO resources.
> Use it instead of open coded variant.
> 
> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>

As explained in my reply to 3/5 this makes the code a lot harder
to read with little to no gain, so NACK from me for this one.

Regards,

Hans

> ---
>  drivers/bluetooth/hci_bcm.c | 15 ++++++---------
>  1 file changed, 6 insertions(+), 9 deletions(-)
> 
> diff --git a/drivers/bluetooth/hci_bcm.c b/drivers/bluetooth/hci_bcm.c
> index 16f854ac19b6..ed99fcde2523 100644
> --- a/drivers/bluetooth/hci_bcm.c
> +++ b/drivers/bluetooth/hci_bcm.c
> @@ -911,15 +911,6 @@ static int bcm_resource(struct acpi_resource *ares, void *data)
>  		dev->irq_active_low = true;
>  		break;
>  
> -	case ACPI_RESOURCE_TYPE_GPIO:
> -		gpio = &ares->data.gpio;
> -		if (gpio->connection_type == ACPI_RESOURCE_GPIO_TYPE_INT) {
> -			dev->gpio_int_idx = dev->gpio_count;
> -			dev->irq_active_low = gpio->polarity == ACPI_ACTIVE_LOW;
> -		}
> -		dev->gpio_count++;
> -		break;
> -
>  	default:
>  		break;
>  	}
> @@ -927,6 +918,12 @@ static int bcm_resource(struct acpi_resource *ares, void *data)
>  	if (serdev_acpi_get_uart_resource(ares, &uart)) {
>  		dev->init_speed = uart->default_baud_rate;
>  		dev->oper_speed = 4000000;
> +	} else if (acpi_gpio_get_irq_resource(ares, &gpio)) {
> +		dev->gpio_int_idx = dev->gpio_count;
> +		dev->irq_active_low = gpio->polarity == ACPI_ACTIVE_LOW;
> +		dev->gpio_count++;
> +	} else if (acpi_gpio_get_io_resource(ares, &gpio)) {
> +		dev->gpio_count++;
>  	}
>  
>  	return 0;
> 


^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH v1 1/5] serdev: Split and export serdev_acpi_get_uart_resource()
  2021-08-03 19:29 [PATCH v1 1/5] serdev: Split and export serdev_acpi_get_uart_resource() Andy Shevchenko
                   ` (3 preceding siblings ...)
  2021-08-03 19:29 ` [PATCH v1 5/5] Bluetooth: hci_bcm: Fix kernel doc comments Andy Shevchenko
@ 2021-08-04  8:08 ` Hans de Goede
  2021-08-04 12:07   ` Andy Shevchenko
  4 siblings, 1 reply; 12+ messages in thread
From: Hans de Goede @ 2021-08-04  8:08 UTC (permalink / raw)
  To: Andy Shevchenko, Maximilian Luz, Lee Jones, Greg Kroah-Hartman,
	linux-bluetooth, linux-kernel, platform-driver-x86, linux-serial
  Cc: Marcel Holtmann, Johan Hedberg, Luiz Augusto von Dentz,
	Mark Gross, Rob Herring, Jiri Slaby

Hi,

On 8/3/21 9:29 PM, Andy Shevchenko wrote:
> The same as for I²C Serial Bus resource split and export
> serdev_acpi_get_uart_resource(). We have already 3 users
> one of which is converted here.
> 
> Rationale of this is to consolidate parsing UART Serial Bus
> resource in one place as it's done, e.g., for I²C Serial Bus.
> 
> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>

Thanks, patch looks good to me:

Reviewed-by: Hans de Goede <hdegoede@redhat.com>

*for this patch*

We do need to talk about how to merge this series, I've
NACK-ed patches 3/5 and 4/5 (see my reply there) so that
leaves just 2/5  as depending on this one. I believe it
would be easiest to just merge 1/5 + 2/5 to the tree
which caries serdev patches, which I guess is Greg's
tty tree ?

Greg can you pick up 1/5 and 2/5 ?

Regards,

Hans



> ---
>  drivers/tty/serdev/core.c | 36 +++++++++++++++++++++++++++++-------
>  include/linux/serdev.h    | 14 ++++++++++++++
>  2 files changed, 43 insertions(+), 7 deletions(-)
> 
> diff --git a/drivers/tty/serdev/core.c b/drivers/tty/serdev/core.c
> index 92498961fd92..436e3d1ba92c 100644
> --- a/drivers/tty/serdev/core.c
> +++ b/drivers/tty/serdev/core.c
> @@ -562,23 +562,45 @@ struct acpi_serdev_lookup {
>  	int index;
>  };
>  
> +/**
> + * serdev_acpi_get_uart_resource - Gets UARTSerialBus resource if type matches
> + * @ares:	ACPI resource
> + * @uart:	Pointer to UARTSerialBus resource will be returned here
> + *
> + * Checks if the given ACPI resource is of type UARTSerialBus.
> + * In this case, returns a pointer to it to the caller.
> + *
> + * Returns true if resource type is of UARTSerialBus, otherwise false.
> + */
> +bool serdev_acpi_get_uart_resource(struct acpi_resource *ares,
> +				   struct acpi_resource_uart_serialbus **uart)
> +{
> +	struct acpi_resource_uart_serialbus *sb;
> +
> +	if (ares->type != ACPI_RESOURCE_TYPE_SERIAL_BUS)
> +		return false;
> +
> +	sb = &ares->data.uart_serial_bus;
> +	if (sb->type != ACPI_RESOURCE_SERIAL_TYPE_UART)
> +		return false;
> +
> +	*uart = sb;
> +	return true;
> +}
> +EXPORT_SYMBOL_GPL(serdev_acpi_get_uart_resource);
> +
>  static int acpi_serdev_parse_resource(struct acpi_resource *ares, void *data)
>  {
>  	struct acpi_serdev_lookup *lookup = data;
>  	struct acpi_resource_uart_serialbus *sb;
>  	acpi_status status;
>  
> -	if (ares->type != ACPI_RESOURCE_TYPE_SERIAL_BUS)
> -		return 1;
> -
> -	if (ares->data.common_serial_bus.type != ACPI_RESOURCE_SERIAL_TYPE_UART)
> +	if (!serdev_acpi_get_uart_resource(ares, &sb))
>  		return 1;
>  
>  	if (lookup->index != -1 && lookup->n++ != lookup->index)
>  		return 1;
>  
> -	sb = &ares->data.uart_serial_bus;
> -
>  	status = acpi_get_handle(lookup->device_handle,
>  				 sb->resource_source.string_ptr,
>  				 &lookup->controller_handle);
> @@ -586,7 +608,7 @@ static int acpi_serdev_parse_resource(struct acpi_resource *ares, void *data)
>  		return 1;
>  
>  	/*
> -	 * NOTE: Ideally, we would also want to retreive other properties here,
> +	 * NOTE: Ideally, we would also want to retrieve other properties here,
>  	 * once setting them before opening the device is supported by serdev.
>  	 */
>  
> diff --git a/include/linux/serdev.h b/include/linux/serdev.h
> index 9f14f9c12ec4..3368c261ab62 100644
> --- a/include/linux/serdev.h
> +++ b/include/linux/serdev.h
> @@ -327,4 +327,18 @@ static inline int serdev_tty_port_unregister(struct tty_port *port)
>  }
>  #endif /* CONFIG_SERIAL_DEV_CTRL_TTYPORT */
>  
> +struct acpi_resource;
> +struct acpi_resource_uart_serialbus;
> +
> +#ifdef CONFIG_ACPI
> +bool serdev_acpi_get_uart_resource(struct acpi_resource *ares,
> +				   struct acpi_resource_uart_serialbus **uart);
> +#else
> +static inline bool serdev_acpi_get_uart_resource(struct acpi_resource *ares,
> +						 struct acpi_resource_uart_serialbus **uart)
> +{
> +	return false;
> +}
> +#endif /* CONFIG_ACPI */
> +
>  #endif /*_LINUX_SERDEV_H */
> 


^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH v1 3/5] Bluetooth: hci_bcm: Use serdev_acpi_get_uart_resource() helper
  2021-08-03 19:29 ` [PATCH v1 3/5] Bluetooth: hci_bcm: " Andy Shevchenko
@ 2021-08-04  8:12   ` Hans de Goede
  2021-08-04  8:42     ` Andy Shevchenko
  0 siblings, 1 reply; 12+ messages in thread
From: Hans de Goede @ 2021-08-04  8:12 UTC (permalink / raw)
  To: Andy Shevchenko, Maximilian Luz, Lee Jones, Greg Kroah-Hartman,
	linux-bluetooth, linux-kernel, platform-driver-x86, linux-serial
  Cc: Marcel Holtmann, Johan Hedberg, Luiz Augusto von Dentz,
	Mark Gross, Rob Herring, Jiri Slaby

Hi,

On 8/3/21 9:29 PM, Andy Shevchenko wrote:
> serdev provides a generic helper to get UART Serial Bus resources.
> Use it instead of open coded variant.
> 
> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> ---
>  drivers/bluetooth/hci_bcm.c | 15 ++++++---------
>  1 file changed, 6 insertions(+), 9 deletions(-)
> 
> diff --git a/drivers/bluetooth/hci_bcm.c b/drivers/bluetooth/hci_bcm.c
> index 3cd57fc56ade..16f854ac19b6 100644
> --- a/drivers/bluetooth/hci_bcm.c
> +++ b/drivers/bluetooth/hci_bcm.c
> @@ -899,9 +899,9 @@ static const struct acpi_gpio_mapping acpi_bcm_int_first_gpios[] = {
>  static int bcm_resource(struct acpi_resource *ares, void *data)
>  {
>  	struct bcm_device *dev = data;
> +	struct acpi_resource_uart_serialbus *uart;
>  	struct acpi_resource_extended_irq *irq;
>  	struct acpi_resource_gpio *gpio;
> -	struct acpi_resource_uart_serialbus *sb;
>  
>  	switch (ares->type) {
>  	case ACPI_RESOURCE_TYPE_EXTENDED_IRQ:
> @@ -920,18 +920,15 @@ static int bcm_resource(struct acpi_resource *ares, void *data)
>  		dev->gpio_count++;
>  		break;
>  
> -	case ACPI_RESOURCE_TYPE_SERIAL_BUS:
> -		sb = &ares->data.uart_serial_bus;
> -		if (sb->type == ACPI_RESOURCE_SERIAL_TYPE_UART) {
> -			dev->init_speed = sb->default_baud_rate;
> -			dev->oper_speed = 4000000;
> -		}
> -		break;
> -
>  	default:
>  		break;
>  	}
>  
> +	if (serdev_acpi_get_uart_resource(ares, &uart)) {
> +		dev->init_speed = uart->default_baud_rate;
> +		dev->oper_speed = 4000000;
> +	}
> +

You are replacing a nice switch-case which handles all relevant resource
types with still having a switch-case + a separate if .. else if .. else if ...
(also taking patch 4/5 into account).

This does not help the readability of this code at all IMHO, so NACK
from me for this patch as well as for 4/5.

Regards,

Hans


^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH v1 3/5] Bluetooth: hci_bcm: Use serdev_acpi_get_uart_resource() helper
  2021-08-04  8:12   ` Hans de Goede
@ 2021-08-04  8:42     ` Andy Shevchenko
  2021-08-04  9:35       ` Hans de Goede
  0 siblings, 1 reply; 12+ messages in thread
From: Andy Shevchenko @ 2021-08-04  8:42 UTC (permalink / raw)
  To: Hans de Goede
  Cc: Andy Shevchenko, Maximilian Luz, Lee Jones, Greg Kroah-Hartman,
	linux-bluetooth, Linux Kernel Mailing List, Platform Driver,
	open list:SERIAL DRIVERS, Marcel Holtmann, Johan Hedberg,
	Luiz Augusto von Dentz, Mark Gross, Rob Herring, Jiri Slaby

On Wed, Aug 4, 2021 at 11:13 AM Hans de Goede <hdegoede@redhat.com> wrote:
> On 8/3/21 9:29 PM, Andy Shevchenko wrote:
> > serdev provides a generic helper to get UART Serial Bus resources.
> > Use it instead of open coded variant.

...

> > +     if (serdev_acpi_get_uart_resource(ares, &uart)) {
> > +             dev->init_speed = uart->default_baud_rate;
> > +             dev->oper_speed = 4000000;
> > +     }
> > +
>
> You are replacing a nice switch-case which handles all relevant resource
> types with still having a switch-case + a separate if .. else if .. else if ...
> (also taking patch 4/5 into account).
>
> This does not help the readability of this code at all IMHO, so NACK
> from me for this patch as well as for 4/5.

I guess it's a matter of style. The main idea is to try avoiding the
spreading of the customized ACPI resource extraction here and there.
Probably I should have started with cleaning up the EXTENDED_IRQ case,
which seems not needed here in the current form.

-- 
With Best Regards,
Andy Shevchenko

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH v1 3/5] Bluetooth: hci_bcm: Use serdev_acpi_get_uart_resource() helper
  2021-08-04  8:42     ` Andy Shevchenko
@ 2021-08-04  9:35       ` Hans de Goede
  0 siblings, 0 replies; 12+ messages in thread
From: Hans de Goede @ 2021-08-04  9:35 UTC (permalink / raw)
  To: Andy Shevchenko
  Cc: Andy Shevchenko, Maximilian Luz, Lee Jones, Greg Kroah-Hartman,
	linux-bluetooth, Linux Kernel Mailing List, Platform Driver,
	open list:SERIAL DRIVERS, Marcel Holtmann, Johan Hedberg,
	Luiz Augusto von Dentz, Mark Gross, Rob Herring, Jiri Slaby

Hi,

On 8/4/21 10:42 AM, Andy Shevchenko wrote:
> On Wed, Aug 4, 2021 at 11:13 AM Hans de Goede <hdegoede@redhat.com> wrote:
>> On 8/3/21 9:29 PM, Andy Shevchenko wrote:
>>> serdev provides a generic helper to get UART Serial Bus resources.
>>> Use it instead of open coded variant.
> 
> ...
> 
>>> +     if (serdev_acpi_get_uart_resource(ares, &uart)) {
>>> +             dev->init_speed = uart->default_baud_rate;
>>> +             dev->oper_speed = 4000000;
>>> +     }
>>> +
>>
>> You are replacing a nice switch-case which handles all relevant resource
>> types with still having a switch-case + a separate if .. else if .. else if ...
>> (also taking patch 4/5 into account).
>>
>> This does not help the readability of this code at all IMHO, so NACK
>> from me for this patch as well as for 4/5.
> 
> I guess it's a matter of style. The main idea is to try avoiding the
> spreading of the customized ACPI resource extraction here and there.

I agree that the helpers make sense for drivers which care about 1
specific type of resource like an I2cSerialBus resource.

But in cases like this where the driver cares about all the resources
in the resource-list just doing a switch-case on the resource-type
directly in the driver just seems cleaner and it certainly is
easier to read. Helpers are nice, but every level of indirection
also means that a developer needs to go and find the function and
lookup what it does when they want to know what is exactly happening.

So lining up all these factors then just sticking with the
switch-case here seems best IMHO.

Also when there is doubt if a cleanup actually makes things
better, which there seems to be here, then it is best to simply
stick with what we have since every code-change may introduce
regressions, may make backporting fixes later more difficult, etc.

Regards,

Hans


^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH v1 1/5] serdev: Split and export serdev_acpi_get_uart_resource()
  2021-08-04  8:08 ` [PATCH v1 1/5] serdev: Split and export serdev_acpi_get_uart_resource() Hans de Goede
@ 2021-08-04 12:07   ` Andy Shevchenko
  0 siblings, 0 replies; 12+ messages in thread
From: Andy Shevchenko @ 2021-08-04 12:07 UTC (permalink / raw)
  To: Hans de Goede
  Cc: Maximilian Luz, Lee Jones, Greg Kroah-Hartman, linux-bluetooth,
	linux-kernel, platform-driver-x86, linux-serial, Marcel Holtmann,
	Johan Hedberg, Luiz Augusto von Dentz, Mark Gross, Rob Herring,
	Jiri Slaby

On Wed, Aug 04, 2021 at 10:08:01AM +0200, Hans de Goede wrote:
> Hi,
> 
> On 8/3/21 9:29 PM, Andy Shevchenko wrote:
> > The same as for I²C Serial Bus resource split and export
> > serdev_acpi_get_uart_resource(). We have already 3 users
> > one of which is converted here.
> > 
> > Rationale of this is to consolidate parsing UART Serial Bus
> > resource in one place as it's done, e.g., for I²C Serial Bus.
> > 
> > Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> 
> Thanks, patch looks good to me:
> 
> Reviewed-by: Hans de Goede <hdegoede@redhat.com>
> 
> *for this patch*
> 
> We do need to talk about how to merge this series, I've
> NACK-ed patches 3/5 and 4/5 (see my reply there) so that
> leaves just 2/5  as depending on this one. I believe it
> would be easiest to just merge 1/5 + 2/5 to the tree
> which caries serdev patches, which I guess is Greg's
> tty tree ?

I can resend a v2 with tags and dropped mentioned patches.
I think it will be easier to everyone to handle.

-- 
With Best Regards,
Andy Shevchenko



^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2021-08-04 12:07 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-08-03 19:29 [PATCH v1 1/5] serdev: Split and export serdev_acpi_get_uart_resource() Andy Shevchenko
2021-08-03 19:29 ` [PATCH v1 2/5] platform/surface: aggregator: Use serdev_acpi_get_uart_resource() helper Andy Shevchenko
2021-08-03 19:47   ` Maximilian Luz
2021-08-03 19:29 ` [PATCH v1 3/5] Bluetooth: hci_bcm: " Andy Shevchenko
2021-08-04  8:12   ` Hans de Goede
2021-08-04  8:42     ` Andy Shevchenko
2021-08-04  9:35       ` Hans de Goede
2021-08-03 19:29 ` [PATCH v1 4/5] Bluetooth: hci_bcm: Use acpi_gpio_get_*_resource() helpers Andy Shevchenko
2021-08-04  8:04   ` Hans de Goede
2021-08-03 19:29 ` [PATCH v1 5/5] Bluetooth: hci_bcm: Fix kernel doc comments Andy Shevchenko
2021-08-04  8:08 ` [PATCH v1 1/5] serdev: Split and export serdev_acpi_get_uart_resource() Hans de Goede
2021-08-04 12:07   ` Andy Shevchenko

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).