Linux-ACPI Archive on lore.kernel.org
 help / color / Atom feed
* [PATCH v2] ipu3-cio2: Parse sensor orientation and rotation
       [not found] <2090a4ab-bb07-140a-f794-764f18969854@fabwu.ch>
@ 2021-04-13  6:34 ` Fabian Wüthrich
  2021-04-13 15:15   ` Andy Shevchenko
  2021-04-14  8:30   ` [PATCH v3 0/2] " Fabian Wüthrich
  0 siblings, 2 replies; 7+ messages in thread
From: Fabian Wüthrich @ 2021-04-13  6:34 UTC (permalink / raw)
  To: linux-media, linux-acpi, devel
  Cc: Jacopo Mondi, Yong Zhi, Sakari Ailus, Bingbu Cao, Dan Scally,
	Tianshu Qiu, Mauro Carvalho Chehab, Robert Moore, Erik Kaneda,
	Rafael J . Wysocki, Len Brown, Fabian Wüthrich

The sensor orientation is read from the _PLC ACPI buffer and converted
to a v4l2 format.

See https://uefi.org/sites/default/files/resources/ACPI_6_3_final_Jan30.pdf
page 351 for a definition of the Panel property.

The sensor rotation is read from the SSDB ACPI buffer and converted into
degrees.

Signed-off-by: Fabian Wüthrich <me@fabwu.ch>
Reviewed-by: Daniel Scally <djrscally@gmail.com>
---
Changes in v2:
  - Move ACPI PLD constants to ACPI headers
  - Fix dev_properties size

 drivers/media/pci/intel/ipu3/cio2-bridge.c | 60 ++++++++++++++++++++--
 drivers/media/pci/intel/ipu3/cio2-bridge.h |  9 +++-
 include/acpi/acbuffer.h                    |  9 ++++
 3 files changed, 73 insertions(+), 5 deletions(-)

diff --git a/drivers/media/pci/intel/ipu3/cio2-bridge.c b/drivers/media/pci/intel/ipu3/cio2-bridge.c
index c2199042d3db..926141e9a516 100644
--- a/drivers/media/pci/intel/ipu3/cio2-bridge.c
+++ b/drivers/media/pci/intel/ipu3/cio2-bridge.c
@@ -29,6 +29,7 @@ static const struct cio2_sensor_config cio2_supported_sensors[] = {
 static const struct cio2_property_names prop_names = {
 	.clock_frequency = "clock-frequency",
 	.rotation = "rotation",
+	.orientation = "orientation",
 	.bus_type = "bus-type",
 	.data_lanes = "data-lanes",
 	.remote_endpoint = "remote-endpoint",
@@ -72,11 +73,51 @@ static int cio2_bridge_read_acpi_buffer(struct acpi_device *adev, char *id,
 	return ret;
 }
 
+static u32 cio2_bridge_parse_rotation(struct cio2_sensor *sensor)
+{
+	switch (sensor->ssdb.degree) {
+	case CIO2_SENSOR_ROTATION_NORMAL:
+		return 0;
+	case CIO2_SENSOR_ROTATION_INVERTED:
+		return 180;
+	default:
+		dev_warn(&sensor->adev->dev,
+			 "Unknown rotation %d. Assume 0 degree rotation\n",
+			 sensor->ssdb.degree);
+		return 0;
+	}
+}
+
+static enum v4l2_fwnode_orientation cio2_bridge_parse_orientation(struct cio2_sensor *sensor)
+{
+	switch (sensor->pld->panel) {
+	case ACPI_PLD_PANEL_FRONT:
+		return V4L2_FWNODE_ORIENTATION_FRONT;
+	case ACPI_PLD_PANEL_BACK:
+		return V4L2_FWNODE_ORIENTATION_BACK;
+	case ACPI_PLD_PANEL_TOP:
+	case ACPI_PLD_PANEL_LEFT:
+	case ACPI_PLD_PANEL_RIGHT:
+	case ACPI_PLD_PANEL_UNKNOWN:
+		return V4L2_FWNODE_ORIENTATION_EXTERNAL;
+	default:
+		dev_warn(&sensor->adev->dev, "Unknown _PLD panel value %d\n",
+			 sensor->pld->panel);
+		return V4L2_FWNODE_ORIENTATION_EXTERNAL;
+	}
+}
+
 static void cio2_bridge_create_fwnode_properties(
 	struct cio2_sensor *sensor,
 	struct cio2_bridge *bridge,
 	const struct cio2_sensor_config *cfg)
 {
+	u32 rotation;
+	enum v4l2_fwnode_orientation orientation;
+
+	rotation = cio2_bridge_parse_rotation(sensor);
+	orientation = cio2_bridge_parse_orientation(sensor);
+
 	sensor->prop_names = prop_names;
 
 	sensor->local_ref[0].node = &sensor->swnodes[SWNODE_CIO2_ENDPOINT];
@@ -85,9 +126,12 @@ static void cio2_bridge_create_fwnode_properties(
 	sensor->dev_properties[0] = PROPERTY_ENTRY_U32(
 					sensor->prop_names.clock_frequency,
 					sensor->ssdb.mclkspeed);
-	sensor->dev_properties[1] = PROPERTY_ENTRY_U8(
+	sensor->dev_properties[1] = PROPERTY_ENTRY_U32(
 					sensor->prop_names.rotation,
-					sensor->ssdb.degree);
+					rotation);
+	sensor->dev_properties[2] = PROPERTY_ENTRY_U32(
+					sensor->prop_names.orientation,
+					orientation);
 
 	sensor->ep_properties[0] = PROPERTY_ENTRY_U32(
 					sensor->prop_names.bus_type,
@@ -159,6 +203,7 @@ static void cio2_bridge_unregister_sensors(struct cio2_bridge *bridge)
 	for (i = 0; i < bridge->n_sensors; i++) {
 		sensor = &bridge->sensors[i];
 		software_node_unregister_nodes(sensor->swnodes);
+		ACPI_FREE(sensor->pld);
 		acpi_dev_put(sensor->adev);
 	}
 }
@@ -170,6 +215,7 @@ static int cio2_bridge_connect_sensor(const struct cio2_sensor_config *cfg,
 	struct fwnode_handle *fwnode;
 	struct cio2_sensor *sensor;
 	struct acpi_device *adev;
+	acpi_status status;
 	int ret;
 
 	for_each_acpi_dev_match(adev, cfg->hid, NULL, -1) {
@@ -193,11 +239,15 @@ static int cio2_bridge_connect_sensor(const struct cio2_sensor_config *cfg,
 		if (ret)
 			goto err_put_adev;
 
+		status = acpi_get_physical_device_location(adev->handle, &sensor->pld);
+		if (ACPI_FAILURE(status))
+			goto err_put_adev;
+
 		if (sensor->ssdb.lanes > CIO2_MAX_LANES) {
 			dev_err(&adev->dev,
 				"Number of lanes in SSDB is invalid\n");
 			ret = -EINVAL;
-			goto err_put_adev;
+			goto err_free_pld;
 		}
 
 		cio2_bridge_create_fwnode_properties(sensor, bridge, cfg);
@@ -205,7 +255,7 @@ static int cio2_bridge_connect_sensor(const struct cio2_sensor_config *cfg,
 
 		ret = software_node_register_nodes(sensor->swnodes);
 		if (ret)
-			goto err_put_adev;
+			goto err_free_pld;
 
 		fwnode = software_node_fwnode(&sensor->swnodes[
 						      SWNODE_SENSOR_HID]);
@@ -226,6 +276,8 @@ static int cio2_bridge_connect_sensor(const struct cio2_sensor_config *cfg,
 
 err_free_swnodes:
 	software_node_unregister_nodes(sensor->swnodes);
+err_free_pld:
+	ACPI_FREE(sensor->pld);
 err_put_adev:
 	acpi_dev_put(sensor->adev);
 err_out:
diff --git a/drivers/media/pci/intel/ipu3/cio2-bridge.h b/drivers/media/pci/intel/ipu3/cio2-bridge.h
index dd0ffcafa489..202c7d494f7a 100644
--- a/drivers/media/pci/intel/ipu3/cio2-bridge.h
+++ b/drivers/media/pci/intel/ipu3/cio2-bridge.h
@@ -12,6 +12,10 @@
 #define CIO2_MAX_LANES				4
 #define MAX_NUM_LINK_FREQS			3
 
+/* Values are educated guesses as we don't have a spec */
+#define CIO2_SENSOR_ROTATION_NORMAL		0
+#define CIO2_SENSOR_ROTATION_INVERTED		1
+
 #define CIO2_SENSOR_CONFIG(_HID, _NR, ...)	\
 	(const struct cio2_sensor_config) {	\
 		.hid = _HID,			\
@@ -80,6 +84,7 @@ struct cio2_sensor_ssdb {
 struct cio2_property_names {
 	char clock_frequency[16];
 	char rotation[9];
+	char orientation[12];
 	char bus_type[9];
 	char data_lanes[11];
 	char remote_endpoint[16];
@@ -106,9 +111,11 @@ struct cio2_sensor {
 	struct cio2_node_names node_names;
 
 	struct cio2_sensor_ssdb ssdb;
+	struct acpi_pld_info *pld;
+
 	struct cio2_property_names prop_names;
 	struct property_entry ep_properties[5];
-	struct property_entry dev_properties[3];
+	struct property_entry dev_properties[4];
 	struct property_entry cio2_properties[3];
 	struct software_node_ref_args local_ref[1];
 	struct software_node_ref_args remote_ref[1];
diff --git a/include/acpi/acbuffer.h b/include/acpi/acbuffer.h
index 18197c16149f..d42e82a82852 100644
--- a/include/acpi/acbuffer.h
+++ b/include/acpi/acbuffer.h
@@ -207,4 +207,13 @@ struct acpi_pld_info {
 #define ACPI_PLD_GET_HORIZ_OFFSET(dword)        ACPI_GET_BITS (dword, 16, ACPI_16BIT_MASK)
 #define ACPI_PLD_SET_HORIZ_OFFSET(dword,value)  ACPI_SET_BITS (dword, 16, ACPI_16BIT_MASK, value)	/* Offset 128+16=144, Len 16 */
 
+/* Panel position defined in _PLD section of ACPI Specification 6.3 */
+#define ACPI_PLD_PANEL_TOP			0
+#define ACPI_PLD_PANEL_BOTTOM			1
+#define ACPI_PLD_PANEL_LEFT			2
+#define ACPI_PLD_PANEL_RIGHT			3
+#define ACPI_PLD_PANEL_FRONT			4
+#define ACPI_PLD_PANEL_BACK			5
+#define ACPI_PLD_PANEL_UNKNOWN			6
+
 #endif				/* ACBUFFER_H */
-- 
2.31.1


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

* Re: [PATCH v2] ipu3-cio2: Parse sensor orientation and rotation
  2021-04-13  6:34 ` [PATCH v2] ipu3-cio2: Parse sensor orientation and rotation Fabian Wüthrich
@ 2021-04-13 15:15   ` Andy Shevchenko
  2021-04-14  8:30   ` [PATCH v3 0/2] " Fabian Wüthrich
  1 sibling, 0 replies; 7+ messages in thread
From: Andy Shevchenko @ 2021-04-13 15:15 UTC (permalink / raw)
  To: Fabian Wüthrich
  Cc: Linux Media Mailing List, ACPI Devel Maling List,
	open list:ACPI COMPONENT ARCHITECTURE (ACPICA),
	Jacopo Mondi, Yong Zhi, Sakari Ailus, Bingbu Cao, Dan Scally,
	Tianshu Qiu, Mauro Carvalho Chehab, Robert Moore, Erik Kaneda,
	Rafael J . Wysocki, Len Brown

On Tue, Apr 13, 2021 at 12:02 PM Fabian Wüthrich <me@fabwu.ch> wrote:
>
> The sensor orientation is read from the _PLC ACPI buffer and converted
> to a v4l2 format.
>
> See https://uefi.org/sites/default/files/resources/ACPI_6_3_final_Jan30.pdf
> page 351 for a definition of the Panel property.

Better to refer to the version, chapter number and title, like]

  ACPI specification v6.3 defines that in the chapter 6.1.8 "_PLD
(Physical Location of Device)"

> The sensor rotation is read from the SSDB ACPI buffer and converted into
> degrees.

After splitting to two patches, take my
Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com>

> Signed-off-by: Fabian Wüthrich <me@fabwu.ch>
> Reviewed-by: Daniel Scally <djrscally@gmail.com>
> ---
> Changes in v2:
>   - Move ACPI PLD constants to ACPI headers
>   - Fix dev_properties size
>
>  drivers/media/pci/intel/ipu3/cio2-bridge.c | 60 ++++++++++++++++++++--
>  drivers/media/pci/intel/ipu3/cio2-bridge.h |  9 +++-
>  include/acpi/acbuffer.h                    |  9 ++++
>  3 files changed, 73 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/media/pci/intel/ipu3/cio2-bridge.c b/drivers/media/pci/intel/ipu3/cio2-bridge.c
> index c2199042d3db..926141e9a516 100644
> --- a/drivers/media/pci/intel/ipu3/cio2-bridge.c
> +++ b/drivers/media/pci/intel/ipu3/cio2-bridge.c
> @@ -29,6 +29,7 @@ static const struct cio2_sensor_config cio2_supported_sensors[] = {
>  static const struct cio2_property_names prop_names = {
>         .clock_frequency = "clock-frequency",
>         .rotation = "rotation",
> +       .orientation = "orientation",
>         .bus_type = "bus-type",
>         .data_lanes = "data-lanes",
>         .remote_endpoint = "remote-endpoint",
> @@ -72,11 +73,51 @@ static int cio2_bridge_read_acpi_buffer(struct acpi_device *adev, char *id,
>         return ret;
>  }
>
> +static u32 cio2_bridge_parse_rotation(struct cio2_sensor *sensor)
> +{
> +       switch (sensor->ssdb.degree) {
> +       case CIO2_SENSOR_ROTATION_NORMAL:
> +               return 0;
> +       case CIO2_SENSOR_ROTATION_INVERTED:
> +               return 180;
> +       default:
> +               dev_warn(&sensor->adev->dev,
> +                        "Unknown rotation %d. Assume 0 degree rotation\n",
> +                        sensor->ssdb.degree);
> +               return 0;
> +       }
> +}
> +
> +static enum v4l2_fwnode_orientation cio2_bridge_parse_orientation(struct cio2_sensor *sensor)
> +{
> +       switch (sensor->pld->panel) {
> +       case ACPI_PLD_PANEL_FRONT:
> +               return V4L2_FWNODE_ORIENTATION_FRONT;
> +       case ACPI_PLD_PANEL_BACK:
> +               return V4L2_FWNODE_ORIENTATION_BACK;
> +       case ACPI_PLD_PANEL_TOP:
> +       case ACPI_PLD_PANEL_LEFT:
> +       case ACPI_PLD_PANEL_RIGHT:
> +       case ACPI_PLD_PANEL_UNKNOWN:
> +               return V4L2_FWNODE_ORIENTATION_EXTERNAL;
> +       default:
> +               dev_warn(&sensor->adev->dev, "Unknown _PLD panel value %d\n",
> +                        sensor->pld->panel);
> +               return V4L2_FWNODE_ORIENTATION_EXTERNAL;
> +       }
> +}
> +
>  static void cio2_bridge_create_fwnode_properties(
>         struct cio2_sensor *sensor,
>         struct cio2_bridge *bridge,
>         const struct cio2_sensor_config *cfg)
>  {
> +       u32 rotation;
> +       enum v4l2_fwnode_orientation orientation;
> +
> +       rotation = cio2_bridge_parse_rotation(sensor);
> +       orientation = cio2_bridge_parse_orientation(sensor);
> +
>         sensor->prop_names = prop_names;
>
>         sensor->local_ref[0].node = &sensor->swnodes[SWNODE_CIO2_ENDPOINT];
> @@ -85,9 +126,12 @@ static void cio2_bridge_create_fwnode_properties(
>         sensor->dev_properties[0] = PROPERTY_ENTRY_U32(
>                                         sensor->prop_names.clock_frequency,
>                                         sensor->ssdb.mclkspeed);
> -       sensor->dev_properties[1] = PROPERTY_ENTRY_U8(
> +       sensor->dev_properties[1] = PROPERTY_ENTRY_U32(
>                                         sensor->prop_names.rotation,
> -                                       sensor->ssdb.degree);
> +                                       rotation);
> +       sensor->dev_properties[2] = PROPERTY_ENTRY_U32(
> +                                       sensor->prop_names.orientation,
> +                                       orientation);
>
>         sensor->ep_properties[0] = PROPERTY_ENTRY_U32(
>                                         sensor->prop_names.bus_type,
> @@ -159,6 +203,7 @@ static void cio2_bridge_unregister_sensors(struct cio2_bridge *bridge)
>         for (i = 0; i < bridge->n_sensors; i++) {
>                 sensor = &bridge->sensors[i];
>                 software_node_unregister_nodes(sensor->swnodes);
> +               ACPI_FREE(sensor->pld);
>                 acpi_dev_put(sensor->adev);
>         }
>  }
> @@ -170,6 +215,7 @@ static int cio2_bridge_connect_sensor(const struct cio2_sensor_config *cfg,
>         struct fwnode_handle *fwnode;
>         struct cio2_sensor *sensor;
>         struct acpi_device *adev;
> +       acpi_status status;
>         int ret;
>
>         for_each_acpi_dev_match(adev, cfg->hid, NULL, -1) {
> @@ -193,11 +239,15 @@ static int cio2_bridge_connect_sensor(const struct cio2_sensor_config *cfg,
>                 if (ret)
>                         goto err_put_adev;
>
> +               status = acpi_get_physical_device_location(adev->handle, &sensor->pld);
> +               if (ACPI_FAILURE(status))
> +                       goto err_put_adev;
> +
>                 if (sensor->ssdb.lanes > CIO2_MAX_LANES) {
>                         dev_err(&adev->dev,
>                                 "Number of lanes in SSDB is invalid\n");
>                         ret = -EINVAL;
> -                       goto err_put_adev;
> +                       goto err_free_pld;
>                 }
>
>                 cio2_bridge_create_fwnode_properties(sensor, bridge, cfg);
> @@ -205,7 +255,7 @@ static int cio2_bridge_connect_sensor(const struct cio2_sensor_config *cfg,
>
>                 ret = software_node_register_nodes(sensor->swnodes);
>                 if (ret)
> -                       goto err_put_adev;
> +                       goto err_free_pld;
>
>                 fwnode = software_node_fwnode(&sensor->swnodes[
>                                                       SWNODE_SENSOR_HID]);
> @@ -226,6 +276,8 @@ static int cio2_bridge_connect_sensor(const struct cio2_sensor_config *cfg,
>
>  err_free_swnodes:
>         software_node_unregister_nodes(sensor->swnodes);
> +err_free_pld:
> +       ACPI_FREE(sensor->pld);
>  err_put_adev:
>         acpi_dev_put(sensor->adev);
>  err_out:
> diff --git a/drivers/media/pci/intel/ipu3/cio2-bridge.h b/drivers/media/pci/intel/ipu3/cio2-bridge.h
> index dd0ffcafa489..202c7d494f7a 100644
> --- a/drivers/media/pci/intel/ipu3/cio2-bridge.h
> +++ b/drivers/media/pci/intel/ipu3/cio2-bridge.h
> @@ -12,6 +12,10 @@
>  #define CIO2_MAX_LANES                         4
>  #define MAX_NUM_LINK_FREQS                     3
>
> +/* Values are educated guesses as we don't have a spec */
> +#define CIO2_SENSOR_ROTATION_NORMAL            0
> +#define CIO2_SENSOR_ROTATION_INVERTED          1
> +
>  #define CIO2_SENSOR_CONFIG(_HID, _NR, ...)     \
>         (const struct cio2_sensor_config) {     \
>                 .hid = _HID,                    \
> @@ -80,6 +84,7 @@ struct cio2_sensor_ssdb {
>  struct cio2_property_names {
>         char clock_frequency[16];
>         char rotation[9];
> +       char orientation[12];
>         char bus_type[9];
>         char data_lanes[11];
>         char remote_endpoint[16];
> @@ -106,9 +111,11 @@ struct cio2_sensor {
>         struct cio2_node_names node_names;
>
>         struct cio2_sensor_ssdb ssdb;
> +       struct acpi_pld_info *pld;
> +
>         struct cio2_property_names prop_names;
>         struct property_entry ep_properties[5];
> -       struct property_entry dev_properties[3];
> +       struct property_entry dev_properties[4];
>         struct property_entry cio2_properties[3];
>         struct software_node_ref_args local_ref[1];
>         struct software_node_ref_args remote_ref[1];

...

> --- a/include/acpi/acbuffer.h
> +++ b/include/acpi/acbuffer.h
> @@ -207,4 +207,13 @@ struct acpi_pld_info {
>  #define ACPI_PLD_GET_HORIZ_OFFSET(dword)        ACPI_GET_BITS (dword, 16, ACPI_16BIT_MASK)
>  #define ACPI_PLD_SET_HORIZ_OFFSET(dword,value)  ACPI_SET_BITS (dword, 16, ACPI_16BIT_MASK, value)      /* Offset 128+16=144, Len 16 */
>
> +/* Panel position defined in _PLD section of ACPI Specification 6.3 */
> +#define ACPI_PLD_PANEL_TOP                     0
> +#define ACPI_PLD_PANEL_BOTTOM                  1
> +#define ACPI_PLD_PANEL_LEFT                    2
> +#define ACPI_PLD_PANEL_RIGHT                   3
> +#define ACPI_PLD_PANEL_FRONT                   4
> +#define ACPI_PLD_PANEL_BACK                    5
> +#define ACPI_PLD_PANEL_UNKNOWN                 6
> +
>  #endif                         /* ACBUFFER_H */

I assume this is a separate patch against ACPICA.

-- 
With Best Regards,
Andy Shevchenko

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

* [PATCH v3 0/2] ipu3-cio2: Parse sensor orientation and rotation
  2021-04-13  6:34 ` [PATCH v2] ipu3-cio2: Parse sensor orientation and rotation Fabian Wüthrich
  2021-04-13 15:15   ` Andy Shevchenko
@ 2021-04-14  8:30   ` Fabian Wüthrich
  2021-04-14  8:30     ` [PATCH v3 1/2] ACPI: Add _PLD panel positions Fabian Wüthrich
  2021-04-14  8:30     ` [PATCH v3 2/2] ipu3-cio2: Parse sensor orientation and rotation Fabian Wüthrich
  1 sibling, 2 replies; 7+ messages in thread
From: Fabian Wüthrich @ 2021-04-14  8:30 UTC (permalink / raw)
  To: linux-media, linux-acpi, devel
  Cc: Jacopo Mondi, Yong Zhi, Sakari Ailus, Bingbu Cao, Dan Scally,
	Tianshu Qiu, Mauro Carvalho Chehab, Robert Moore, Erik Kaneda,
	Rafael J . Wysocki, Len Brown, Andy Shevchenko,
	Fabian Wüthrich

This set exposes the orientation and rotation of a camera sensor
attached to ipu3-cio2 as fwnodes properties. Individual drivers can use
v4l2_fwnode_device_parse() to pick up these properties and expose them
as v4l2 controls using v4l2_ctrl_new_fwnode_properties().

Changes in v2:
  - Move ACPI PLD constants to ACPI headers
  - Fix dev_properties size

Changes in v3:
  - Split patch into patch for ipu3 and patch for ACPICA

Fabian Wüthrich (2):
  ACPI: Add _PLD panel positions
  ipu3-cio2: Parse sensor orientation and rotation

 drivers/media/pci/intel/ipu3/cio2-bridge.c | 60 ++++++++++++++++++++--
 drivers/media/pci/intel/ipu3/cio2-bridge.h |  9 +++-
 include/acpi/acbuffer.h                    |  9 ++++
 3 files changed, 73 insertions(+), 5 deletions(-)

-- 
2.31.1


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

* [PATCH v3 1/2] ACPI: Add _PLD panel positions
  2021-04-14  8:30   ` [PATCH v3 0/2] " Fabian Wüthrich
@ 2021-04-14  8:30     ` Fabian Wüthrich
  2021-04-14 13:50       ` Rafael J. Wysocki
  2021-04-14  8:30     ` [PATCH v3 2/2] ipu3-cio2: Parse sensor orientation and rotation Fabian Wüthrich
  1 sibling, 1 reply; 7+ messages in thread
From: Fabian Wüthrich @ 2021-04-14  8:30 UTC (permalink / raw)
  To: linux-media, linux-acpi, devel
  Cc: Jacopo Mondi, Yong Zhi, Sakari Ailus, Bingbu Cao, Dan Scally,
	Tianshu Qiu, Mauro Carvalho Chehab, Robert Moore, Erik Kaneda,
	Rafael J . Wysocki, Len Brown, Andy Shevchenko,
	Fabian Wüthrich

The ACPI specification v6.3 defines the panel positions in chapter 6.1.8
"_PLD (Physical Location of Device)"

Signed-off-by: Fabian Wüthrich <me@fabwu.ch>
Reviewed-by: Daniel Scally <djrscally@gmail.com>
Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com>
---
 include/acpi/acbuffer.h | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/include/acpi/acbuffer.h b/include/acpi/acbuffer.h
index 18197c16149f..d42e82a82852 100644
--- a/include/acpi/acbuffer.h
+++ b/include/acpi/acbuffer.h
@@ -207,4 +207,13 @@ struct acpi_pld_info {
 #define ACPI_PLD_GET_HORIZ_OFFSET(dword)        ACPI_GET_BITS (dword, 16, ACPI_16BIT_MASK)
 #define ACPI_PLD_SET_HORIZ_OFFSET(dword,value)  ACPI_SET_BITS (dword, 16, ACPI_16BIT_MASK, value)	/* Offset 128+16=144, Len 16 */
 
+/* Panel position defined in _PLD section of ACPI Specification 6.3 */
+#define ACPI_PLD_PANEL_TOP			0
+#define ACPI_PLD_PANEL_BOTTOM			1
+#define ACPI_PLD_PANEL_LEFT			2
+#define ACPI_PLD_PANEL_RIGHT			3
+#define ACPI_PLD_PANEL_FRONT			4
+#define ACPI_PLD_PANEL_BACK			5
+#define ACPI_PLD_PANEL_UNKNOWN			6
+
 #endif				/* ACBUFFER_H */
-- 
2.31.1


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

* [PATCH v3 2/2] ipu3-cio2: Parse sensor orientation and rotation
  2021-04-14  8:30   ` [PATCH v3 0/2] " Fabian Wüthrich
  2021-04-14  8:30     ` [PATCH v3 1/2] ACPI: Add _PLD panel positions Fabian Wüthrich
@ 2021-04-14  8:30     ` Fabian Wüthrich
  1 sibling, 0 replies; 7+ messages in thread
From: Fabian Wüthrich @ 2021-04-14  8:30 UTC (permalink / raw)
  To: linux-media, linux-acpi, devel
  Cc: Jacopo Mondi, Yong Zhi, Sakari Ailus, Bingbu Cao, Dan Scally,
	Tianshu Qiu, Mauro Carvalho Chehab, Robert Moore, Erik Kaneda,
	Rafael J . Wysocki, Len Brown, Andy Shevchenko,
	Fabian Wüthrich

The sensor orientation is read from the _PLC ACPI buffer and converted to a v4l2
format.

The sensor rotation is read from the SSDB ACPI buffer and converted into
degrees.

Signed-off-by: Fabian Wüthrich <me@fabwu.ch>
Reviewed-by: Daniel Scally <djrscally@gmail.com>
Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com>
---
 drivers/media/pci/intel/ipu3/cio2-bridge.c | 60 ++++++++++++++++++++--
 drivers/media/pci/intel/ipu3/cio2-bridge.h |  9 +++-
 2 files changed, 64 insertions(+), 5 deletions(-)

diff --git a/drivers/media/pci/intel/ipu3/cio2-bridge.c b/drivers/media/pci/intel/ipu3/cio2-bridge.c
index c2199042d3db..926141e9a516 100644
--- a/drivers/media/pci/intel/ipu3/cio2-bridge.c
+++ b/drivers/media/pci/intel/ipu3/cio2-bridge.c
@@ -29,6 +29,7 @@ static const struct cio2_sensor_config cio2_supported_sensors[] = {
 static const struct cio2_property_names prop_names = {
 	.clock_frequency = "clock-frequency",
 	.rotation = "rotation",
+	.orientation = "orientation",
 	.bus_type = "bus-type",
 	.data_lanes = "data-lanes",
 	.remote_endpoint = "remote-endpoint",
@@ -72,11 +73,51 @@ static int cio2_bridge_read_acpi_buffer(struct acpi_device *adev, char *id,
 	return ret;
 }
 
+static u32 cio2_bridge_parse_rotation(struct cio2_sensor *sensor)
+{
+	switch (sensor->ssdb.degree) {
+	case CIO2_SENSOR_ROTATION_NORMAL:
+		return 0;
+	case CIO2_SENSOR_ROTATION_INVERTED:
+		return 180;
+	default:
+		dev_warn(&sensor->adev->dev,
+			 "Unknown rotation %d. Assume 0 degree rotation\n",
+			 sensor->ssdb.degree);
+		return 0;
+	}
+}
+
+static enum v4l2_fwnode_orientation cio2_bridge_parse_orientation(struct cio2_sensor *sensor)
+{
+	switch (sensor->pld->panel) {
+	case ACPI_PLD_PANEL_FRONT:
+		return V4L2_FWNODE_ORIENTATION_FRONT;
+	case ACPI_PLD_PANEL_BACK:
+		return V4L2_FWNODE_ORIENTATION_BACK;
+	case ACPI_PLD_PANEL_TOP:
+	case ACPI_PLD_PANEL_LEFT:
+	case ACPI_PLD_PANEL_RIGHT:
+	case ACPI_PLD_PANEL_UNKNOWN:
+		return V4L2_FWNODE_ORIENTATION_EXTERNAL;
+	default:
+		dev_warn(&sensor->adev->dev, "Unknown _PLD panel value %d\n",
+			 sensor->pld->panel);
+		return V4L2_FWNODE_ORIENTATION_EXTERNAL;
+	}
+}
+
 static void cio2_bridge_create_fwnode_properties(
 	struct cio2_sensor *sensor,
 	struct cio2_bridge *bridge,
 	const struct cio2_sensor_config *cfg)
 {
+	u32 rotation;
+	enum v4l2_fwnode_orientation orientation;
+
+	rotation = cio2_bridge_parse_rotation(sensor);
+	orientation = cio2_bridge_parse_orientation(sensor);
+
 	sensor->prop_names = prop_names;
 
 	sensor->local_ref[0].node = &sensor->swnodes[SWNODE_CIO2_ENDPOINT];
@@ -85,9 +126,12 @@ static void cio2_bridge_create_fwnode_properties(
 	sensor->dev_properties[0] = PROPERTY_ENTRY_U32(
 					sensor->prop_names.clock_frequency,
 					sensor->ssdb.mclkspeed);
-	sensor->dev_properties[1] = PROPERTY_ENTRY_U8(
+	sensor->dev_properties[1] = PROPERTY_ENTRY_U32(
 					sensor->prop_names.rotation,
-					sensor->ssdb.degree);
+					rotation);
+	sensor->dev_properties[2] = PROPERTY_ENTRY_U32(
+					sensor->prop_names.orientation,
+					orientation);
 
 	sensor->ep_properties[0] = PROPERTY_ENTRY_U32(
 					sensor->prop_names.bus_type,
@@ -159,6 +203,7 @@ static void cio2_bridge_unregister_sensors(struct cio2_bridge *bridge)
 	for (i = 0; i < bridge->n_sensors; i++) {
 		sensor = &bridge->sensors[i];
 		software_node_unregister_nodes(sensor->swnodes);
+		ACPI_FREE(sensor->pld);
 		acpi_dev_put(sensor->adev);
 	}
 }
@@ -170,6 +215,7 @@ static int cio2_bridge_connect_sensor(const struct cio2_sensor_config *cfg,
 	struct fwnode_handle *fwnode;
 	struct cio2_sensor *sensor;
 	struct acpi_device *adev;
+	acpi_status status;
 	int ret;
 
 	for_each_acpi_dev_match(adev, cfg->hid, NULL, -1) {
@@ -193,11 +239,15 @@ static int cio2_bridge_connect_sensor(const struct cio2_sensor_config *cfg,
 		if (ret)
 			goto err_put_adev;
 
+		status = acpi_get_physical_device_location(adev->handle, &sensor->pld);
+		if (ACPI_FAILURE(status))
+			goto err_put_adev;
+
 		if (sensor->ssdb.lanes > CIO2_MAX_LANES) {
 			dev_err(&adev->dev,
 				"Number of lanes in SSDB is invalid\n");
 			ret = -EINVAL;
-			goto err_put_adev;
+			goto err_free_pld;
 		}
 
 		cio2_bridge_create_fwnode_properties(sensor, bridge, cfg);
@@ -205,7 +255,7 @@ static int cio2_bridge_connect_sensor(const struct cio2_sensor_config *cfg,
 
 		ret = software_node_register_nodes(sensor->swnodes);
 		if (ret)
-			goto err_put_adev;
+			goto err_free_pld;
 
 		fwnode = software_node_fwnode(&sensor->swnodes[
 						      SWNODE_SENSOR_HID]);
@@ -226,6 +276,8 @@ static int cio2_bridge_connect_sensor(const struct cio2_sensor_config *cfg,
 
 err_free_swnodes:
 	software_node_unregister_nodes(sensor->swnodes);
+err_free_pld:
+	ACPI_FREE(sensor->pld);
 err_put_adev:
 	acpi_dev_put(sensor->adev);
 err_out:
diff --git a/drivers/media/pci/intel/ipu3/cio2-bridge.h b/drivers/media/pci/intel/ipu3/cio2-bridge.h
index dd0ffcafa489..202c7d494f7a 100644
--- a/drivers/media/pci/intel/ipu3/cio2-bridge.h
+++ b/drivers/media/pci/intel/ipu3/cio2-bridge.h
@@ -12,6 +12,10 @@
 #define CIO2_MAX_LANES				4
 #define MAX_NUM_LINK_FREQS			3
 
+/* Values are educated guesses as we don't have a spec */
+#define CIO2_SENSOR_ROTATION_NORMAL		0
+#define CIO2_SENSOR_ROTATION_INVERTED		1
+
 #define CIO2_SENSOR_CONFIG(_HID, _NR, ...)	\
 	(const struct cio2_sensor_config) {	\
 		.hid = _HID,			\
@@ -80,6 +84,7 @@ struct cio2_sensor_ssdb {
 struct cio2_property_names {
 	char clock_frequency[16];
 	char rotation[9];
+	char orientation[12];
 	char bus_type[9];
 	char data_lanes[11];
 	char remote_endpoint[16];
@@ -106,9 +111,11 @@ struct cio2_sensor {
 	struct cio2_node_names node_names;
 
 	struct cio2_sensor_ssdb ssdb;
+	struct acpi_pld_info *pld;
+
 	struct cio2_property_names prop_names;
 	struct property_entry ep_properties[5];
-	struct property_entry dev_properties[3];
+	struct property_entry dev_properties[4];
 	struct property_entry cio2_properties[3];
 	struct software_node_ref_args local_ref[1];
 	struct software_node_ref_args remote_ref[1];
-- 
2.31.1


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

* Re: [PATCH v3 1/2] ACPI: Add _PLD panel positions
  2021-04-14  8:30     ` [PATCH v3 1/2] ACPI: Add _PLD panel positions Fabian Wüthrich
@ 2021-04-14 13:50       ` Rafael J. Wysocki
  2021-05-09 16:29         ` Fabian Wüthrich
  0 siblings, 1 reply; 7+ messages in thread
From: Rafael J. Wysocki @ 2021-04-14 13:50 UTC (permalink / raw)
  To: Fabian Wüthrich, Erik Kaneda
  Cc: Linux Media Mailing List, ACPI Devel Maling List,
	open list:ACPI COMPONENT ARCHITECTURE (ACPICA),
	Jacopo Mondi, Yong Zhi, Sakari Ailus, Bingbu Cao, Dan Scally,
	Tianshu Qiu, Mauro Carvalho Chehab, Robert Moore,
	Rafael J . Wysocki, Len Brown, Andy Shevchenko

On Wed, Apr 14, 2021 at 10:30 AM Fabian Wüthrich <me@fabwu.ch> wrote:
>
> The ACPI specification v6.3 defines the panel positions in chapter 6.1.8
> "_PLD (Physical Location of Device)"
>
> Signed-off-by: Fabian Wüthrich <me@fabwu.ch>
> Reviewed-by: Daniel Scally <djrscally@gmail.com>
> Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com>

This is ACPICA material.

Erik, can you pick up this one, please?

> ---
>  include/acpi/acbuffer.h | 9 +++++++++
>  1 file changed, 9 insertions(+)
>
> diff --git a/include/acpi/acbuffer.h b/include/acpi/acbuffer.h
> index 18197c16149f..d42e82a82852 100644
> --- a/include/acpi/acbuffer.h
> +++ b/include/acpi/acbuffer.h
> @@ -207,4 +207,13 @@ struct acpi_pld_info {
>  #define ACPI_PLD_GET_HORIZ_OFFSET(dword)        ACPI_GET_BITS (dword, 16, ACPI_16BIT_MASK)
>  #define ACPI_PLD_SET_HORIZ_OFFSET(dword,value)  ACPI_SET_BITS (dword, 16, ACPI_16BIT_MASK, value)      /* Offset 128+16=144, Len 16 */
>
> +/* Panel position defined in _PLD section of ACPI Specification 6.3 */
> +#define ACPI_PLD_PANEL_TOP                     0
> +#define ACPI_PLD_PANEL_BOTTOM                  1
> +#define ACPI_PLD_PANEL_LEFT                    2
> +#define ACPI_PLD_PANEL_RIGHT                   3
> +#define ACPI_PLD_PANEL_FRONT                   4
> +#define ACPI_PLD_PANEL_BACK                    5
> +#define ACPI_PLD_PANEL_UNKNOWN                 6
> +
>  #endif                         /* ACBUFFER_H */
> --
> 2.31.1
>

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

* Re: [PATCH v3 1/2] ACPI: Add _PLD panel positions
  2021-04-14 13:50       ` Rafael J. Wysocki
@ 2021-05-09 16:29         ` Fabian Wüthrich
  0 siblings, 0 replies; 7+ messages in thread
From: Fabian Wüthrich @ 2021-05-09 16:29 UTC (permalink / raw)
  To: Erik Kaneda
  Cc: Linux Media Mailing List, ACPI Devel Maling List,
	open list:ACPI COMPONENT ARCHITECTURE (ACPICA),
	Jacopo Mondi, Yong Zhi, Sakari Ailus, Bingbu Cao, Dan Scally,
	Tianshu Qiu, Mauro Carvalho Chehab, Robert Moore,
	Rafael J . Wysocki, Len Brown, Andy Shevchenko,
	Rafael J. Wysocki

Hi Erik,

Do I need to add anything to this patch or is it fine like that?

Thanks,
Fabian

On 14.04.21 15:50, Rafael J. Wysocki wrote:
> On Wed, Apr 14, 2021 at 10:30 AM Fabian Wüthrich <me@fabwu.ch> wrote:
>>
>> The ACPI specification v6.3 defines the panel positions in chapter 6.1.8
>> "_PLD (Physical Location of Device)"
>>
>> Signed-off-by: Fabian Wüthrich <me@fabwu.ch>
>> Reviewed-by: Daniel Scally <djrscally@gmail.com>
>> Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com>
> 
> This is ACPICA material.
> 
> Erik, can you pick up this one, please?
> 
>> ---
>>  include/acpi/acbuffer.h | 9 +++++++++
>>  1 file changed, 9 insertions(+)
>>
>> diff --git a/include/acpi/acbuffer.h b/include/acpi/acbuffer.h
>> index 18197c16149f..d42e82a82852 100644
>> --- a/include/acpi/acbuffer.h
>> +++ b/include/acpi/acbuffer.h
>> @@ -207,4 +207,13 @@ struct acpi_pld_info {
>>  #define ACPI_PLD_GET_HORIZ_OFFSET(dword)        ACPI_GET_BITS (dword, 16, ACPI_16BIT_MASK)
>>  #define ACPI_PLD_SET_HORIZ_OFFSET(dword,value)  ACPI_SET_BITS (dword, 16, ACPI_16BIT_MASK, value)      /* Offset 128+16=144, Len 16 */
>>
>> +/* Panel position defined in _PLD section of ACPI Specification 6.3 */
>> +#define ACPI_PLD_PANEL_TOP                     0
>> +#define ACPI_PLD_PANEL_BOTTOM                  1
>> +#define ACPI_PLD_PANEL_LEFT                    2
>> +#define ACPI_PLD_PANEL_RIGHT                   3
>> +#define ACPI_PLD_PANEL_FRONT                   4
>> +#define ACPI_PLD_PANEL_BACK                    5
>> +#define ACPI_PLD_PANEL_UNKNOWN                 6
>> +
>>  #endif                         /* ACBUFFER_H */
>> --
>> 2.31.1
>>

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

end of thread, back to index

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <2090a4ab-bb07-140a-f794-764f18969854@fabwu.ch>
2021-04-13  6:34 ` [PATCH v2] ipu3-cio2: Parse sensor orientation and rotation Fabian Wüthrich
2021-04-13 15:15   ` Andy Shevchenko
2021-04-14  8:30   ` [PATCH v3 0/2] " Fabian Wüthrich
2021-04-14  8:30     ` [PATCH v3 1/2] ACPI: Add _PLD panel positions Fabian Wüthrich
2021-04-14 13:50       ` Rafael J. Wysocki
2021-05-09 16:29         ` Fabian Wüthrich
2021-04-14  8:30     ` [PATCH v3 2/2] ipu3-cio2: Parse sensor orientation and rotation Fabian Wüthrich

Linux-ACPI Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-acpi/0 linux-acpi/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-acpi linux-acpi/ https://lore.kernel.org/linux-acpi \
		linux-acpi@vger.kernel.org
	public-inbox-index linux-acpi

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-acpi


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git