Skip to contentSkip to conversation

Define rotation property for camera sensors

PATCH In review Sakari Ailus 4 participants 12 messages May 25, 2018 – May 31, 2018

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

v2 cover Define rotation property for camera sensors

Hi,

Here's an update on my previous patchset adding an "upside-down" property. Instead of dropping the first patch entirely as I first thought, I decided to add documentation for the rotation property for sensors as well. The updates to the patches are related to that.

Sakari Ailus (2):
dt-bindings: media: Define "rotation" property for sensors
smiapp: Support the "upside-down" property

 .../devicetree/bindings/media/i2c/nokia,smia.txt         |  2 ++
 .../devicetree/bindings/media/video-interfaces.txt       |  4 ++++
 drivers/media/i2c/smiapp/smiapp-core.c                   | 16 ++++++++++++++++
 3 files changed, 22 insertions(+)
Signature · 1 line
2.11.0
#1 lore raw

PATCH v2 1/2 dt-bindings: media: Define "rotation" property for sensors

Sensors are occasionally mounted upside down to systems such as mobile phones or tablets. In order to use such a sensor without having to turn every image upside down, most camera sensors support reversing the readout order by setting both horizontal and vertical flipping.

This patch documents the "rotation" property for camera sensors, mirroring what is defined for displays in Documentation/devicetree/bindings/display/panel/panel.txt .

---
 Documentation/devicetree/bindings/media/video-interfaces.txt | 4 ++++
 1 file changed, 4 insertions(+)
Documentation/devicetree/bindings/media/video-interfaces.txt +4 -0
index 258b8dfddf48..52b7c7b57842 100644
@@ -85,6 +85,10 @@ Optional properties
 
 - lens-focus: A phandle to the node of the focus lens controller.
 
+- rotation: The device, typically an image sensor, is not mounted upright,
+  but a number of degrees counter clockwise. Typical values are 0 and 180
+  (upside down).
+
 
 Optional endpoint properties
 ----------------------------
Signature · 1 line
2.11.0
#4 lore raw

PATCH v2 2/2 smiapp: Support the "upside-down" property

In reply to Sakari Ailus

Use the "upside-down" property to tell that the sensor is mounted upside down. This reverses the behaviour of the VFLIP and HFLIP controls as well as the pixel order.

---
 .../devicetree/bindings/media/i2c/nokia,smia.txt         |  2 ++
 drivers/media/i2c/smiapp/smiapp-core.c                   | 16 ++++++++++++++++
 2 files changed, 18 insertions(+)
Documentation/devicetree/bindings/media/i2c/nokia,smia.txt +2 -0
index 33f10a94c381..6f509657470e 100644
@@ -29,6 +29,8 @@ Optional properties
 - reset-gpios: XSHUTDOWN GPIO
 - flash-leds: See ../video-interfaces.txt
 - lens-focus: See ../video-interfaces.txt
+- rotation: Integer property; valid values are 0 (sensor mounted upright)
+	    and 180 (sensor mounted upside down).
 
 
 Endpoint node mandatory properties
drivers/media/i2c/smiapp/smiapp-core.c +16 -0
index e1f8208581aa..32286df6ab43 100644
@@ -2764,6 +2764,7 @@ static struct smiapp_hwconfig *smiapp_get_hwconfig(struct device *dev)
 	struct v4l2_fwnode_endpoint *bus_cfg;
 	struct fwnode_handle *ep;
 	struct fwnode_handle *fwnode = dev_fwnode(dev);
+	u32 rotation;
 	int i;
 	int rval;
 
@@ -2800,6 +2801,21 @@ static struct smiapp_hwconfig *smiapp_get_hwconfig(struct device *dev)
 
 	dev_dbg(dev, "lanes %u\n", hwcfg->lanes);
 
+	rval = fwnode_property_read_u32(fwnode, "upside-down", &rotation);
+	if (!rval) {
+		switch (rotation) {
+		case 180:
+			hwcfg->module_board_orient =
+				SMIAPP_MODULE_BOARD_ORIENT_180;
+			/* Fall through */
+		case 0:
+			break;
+		default:
+			dev_err(dev, "invalid rotation %u\n", rotation);
+			goto out_err;
+		}
+	}
+
 	/* NVM size is not mandatory */
 	fwnode_property_read_u32(fwnode, "nokia,nvm-size", &hwcfg->nvm_size);
 
Signature · 1 line
2.11.0
#5 lore raw

PATCH v2 2/2 smiapp: Support the "rotation" property

Use the "rotation" property to tell that the sensor is mounted upside down. This reverses the behaviour of the VFLIP and HFLIP controls as well as the pixel order.

---
since v2:

- Fix the property name in the commit message

 .../devicetree/bindings/media/i2c/nokia,smia.txt         |  2 ++
 drivers/media/i2c/smiapp/smiapp-core.c                   | 16 ++++++++++++++++
 2 files changed, 18 insertions(+)
Documentation/devicetree/bindings/media/i2c/nokia,smia.txt +2 -0
index 33f10a94c381..6f509657470e 100644
@@ -29,6 +29,8 @@ Optional properties
 - reset-gpios: XSHUTDOWN GPIO
 - flash-leds: See ../video-interfaces.txt
 - lens-focus: See ../video-interfaces.txt
+- rotation: Integer property; valid values are 0 (sensor mounted upright)
+	    and 180 (sensor mounted upside down).
 
 
 Endpoint node mandatory properties
drivers/media/i2c/smiapp/smiapp-core.c +16 -0
index e1f8208581aa..32286df6ab43 100644
@@ -2764,6 +2764,7 @@ static struct smiapp_hwconfig *smiapp_get_hwconfig(struct device *dev)
 	struct v4l2_fwnode_endpoint *bus_cfg;
 	struct fwnode_handle *ep;
 	struct fwnode_handle *fwnode = dev_fwnode(dev);
+	u32 rotation;
 	int i;
 	int rval;
 
@@ -2800,6 +2801,21 @@ static struct smiapp_hwconfig *smiapp_get_hwconfig(struct device *dev)
 
 	dev_dbg(dev, "lanes %u\n", hwcfg->lanes);
 
+	rval = fwnode_property_read_u32(fwnode, "upside-down", &rotation);
+	if (!rval) {
+		switch (rotation) {
+		case 180:
+			hwcfg->module_board_orient =
+				SMIAPP_MODULE_BOARD_ORIENT_180;
+			/* Fall through */
+		case 0:
+			break;
+		default:
+			dev_err(dev, "invalid rotation %u\n", rotation);
+			goto out_err;
+		}
+	}
+
 	/* NVM size is not mandatory */
 	fwnode_property_read_u32(fwnode, "nokia,nvm-size", &hwcfg->nvm_size);
 
Signature · 1 line
2.11.0
#10 lore raw

Re: [PATCH v2 2/2] smiapp: Support the "upside-down" property

In reply to Sakari Ailus

Hi,

Quoted 6 lines · Sakari Ailus

Use the "upside-down" property to tell that the sensor is mounted upside down. This reverses the behaviour of the VFLIP and HFLIP controls as well as the pixel order.

---

Patch subject and description should be s/"upside-down"/"rotation"/g ?

Quoted 30 lines
 .../devicetree/bindings/media/i2c/nokia,smia.txt         |  2 ++
 drivers/media/i2c/smiapp/smiapp-core.c                   | 16 ++++++++++++++++
 2 files changed, 18 insertions(+)
Documentation/devicetree/bindings/media/i2c/nokia,smia.txt +2 -0
index 33f10a94c381..6f509657470e 100644
@@ -29,6 +29,8 @@ Optional properties
 - reset-gpios: XSHUTDOWN GPIO
 - flash-leds: See ../video-interfaces.txt
 - lens-focus: See ../video-interfaces.txt
+- rotation: Integer property; valid values are 0 (sensor mounted upright)
+	    and 180 (sensor mounted upside down).
 
 
 Endpoint node mandatory properties
drivers/media/i2c/smiapp/smiapp-core.c +1 -0
index e1f8208581aa..32286df6ab43 100644
@@ -2764,6 +2764,7 @@ static struct smiapp_hwconfig *smiapp_get_hwconfig(struct device *dev)
 	struct v4l2_fwnode_endpoint *bus_cfg;
 	struct fwnode_handle *ep;
 	struct fwnode_handle *fwnode = dev_fwnode(dev);
+	u32 rotation;
 	int i;
 	int rval;
 

drivers/media/i2c/smiapp/smiapp-core.c static struct smiapp_hwconfig *smiapp_get_hwconfig(struct device *dev) · line 2804

Quoted 4 lines
drivers/media/i2c/smiapp/smiapp-core.c +1 -0
@@ -2800,6 +2801,21 @@ static struct smiapp_hwconfig *smiapp_get_hwconfig(struct device *dev)
 
 	dev_dbg(dev, "lanes %u\n", hwcfg->lanes);
 
+	rval = fwnode_property_read_u32(fwnode, "upside-down", &rotation);

"rotation"

Quoted 6 lines
drivers/media/i2c/smiapp/smiapp-core.c +6 -0
+	if (!rval) {
+		switch (rotation) {
+		case 180:
+			hwcfg->module_board_orient =
+				SMIAPP_MODULE_BOARD_ORIENT_180;
+			/* Fall through */

drivers/media/i2c/smiapp/smiapp-core.c static struct smiapp_hwconfig *smiapp_get_hwconfig(struct device *dev) · line 2820

Quoted 10 lines
drivers/media/i2c/smiapp/smiapp-core.c +8 -0
+		case 0:
+			break;
+		default:
+			dev_err(dev, "invalid rotation %u\n", rotation);
+			goto out_err;
+		}
+	}
+
 	/* NVM size is not mandatory */
 	fwnode_property_read_u32(fwnode, "nokia,nvm-size", &hwcfg->nvm_size);

-- Sebastian

#6 lore raw

PATCH v2 2/2 smiapp: Support the "rotation" property

In reply to Sakari Ailus

Use the "rotation" property to tell that the sensor is mounted upside down. This reverses the behaviour of the VFLIP and HFLIP controls as well as the pixel order.

---
since v2.2:

- Fix property name in code.

 .../devicetree/bindings/media/i2c/nokia,smia.txt         |  2 ++
 drivers/media/i2c/smiapp/smiapp-core.c                   | 16 ++++++++++++++++
 2 files changed, 18 insertions(+)
Documentation/devicetree/bindings/media/i2c/nokia,smia.txt +2 -0
index 33f10a94c381..6f509657470e 100644
@@ -29,6 +29,8 @@ Optional properties
 - reset-gpios: XSHUTDOWN GPIO
 - flash-leds: See ../video-interfaces.txt
 - lens-focus: See ../video-interfaces.txt
+- rotation: Integer property; valid values are 0 (sensor mounted upright)
+	    and 180 (sensor mounted upside down).
 
 
 Endpoint node mandatory properties
drivers/media/i2c/smiapp/smiapp-core.c +16 -0
index e1f8208581aa..e9e0f21efc2a 100644
@@ -2764,6 +2764,7 @@ static struct smiapp_hwconfig *smiapp_get_hwconfig(struct device *dev)
 	struct v4l2_fwnode_endpoint *bus_cfg;
 	struct fwnode_handle *ep;
 	struct fwnode_handle *fwnode = dev_fwnode(dev);
+	u32 rotation;
 	int i;
 	int rval;
 
@@ -2800,6 +2801,21 @@ static struct smiapp_hwconfig *smiapp_get_hwconfig(struct device *dev)
 
 	dev_dbg(dev, "lanes %u\n", hwcfg->lanes);
 
+	rval = fwnode_property_read_u32(fwnode, "rotation", &rotation);
+	if (!rval) {
+		switch (rotation) {
+		case 180:
+			hwcfg->module_board_orient =
+				SMIAPP_MODULE_BOARD_ORIENT_180;
+			/* Fall through */
+		case 0:
+			break;
+		default:
+			dev_err(dev, "invalid rotation %u\n", rotation);
+			goto out_err;
+		}
+	}
+
 	/* NVM size is not mandatory */
 	fwnode_property_read_u32(fwnode, "nokia,nvm-size", &hwcfg->nvm_size);
 
Signature · 1 line
2.11.0
#11 lore raw

Re: [PATCH v2 2/2] smiapp: Support the "upside-down" property

In reply to Sebastian Reichel
Quoted 41 lines · Sebastian Reichel

Hi,

Quoted 6 lines · Sakari Ailus

Use the "upside-down" property to tell that the sensor is mounted upside down. This reverses the behaviour of the VFLIP and HFLIP controls as well as the pixel order.

---

Patch subject and description should be s/"upside-down"/"rotation"/g ?

Quoted 29 lines
 .../devicetree/bindings/media/i2c/nokia,smia.txt         |  2 ++
 drivers/media/i2c/smiapp/smiapp-core.c                   | 16 ++++++++++++++++
 2 files changed, 18 insertions(+)
Documentation/devicetree/bindings/media/i2c/nokia,smia.txt +2 -0
index 33f10a94c381..6f509657470e 100644
@@ -29,6 +29,8 @@ Optional properties
 - reset-gpios: XSHUTDOWN GPIO
 - flash-leds: See ../video-interfaces.txt
 - lens-focus: See ../video-interfaces.txt
+- rotation: Integer property; valid values are 0 (sensor mounted upright)
+	    and 180 (sensor mounted upside down).
 
 
 Endpoint node mandatory properties
drivers/media/i2c/smiapp/smiapp-core.c +1 -0
index e1f8208581aa..32286df6ab43 100644
@@ -2764,6 +2764,7 @@ static struct smiapp_hwconfig *smiapp_get_hwconfig(struct device *dev)
 	struct v4l2_fwnode_endpoint *bus_cfg;
 	struct fwnode_handle *ep;
 	struct fwnode_handle *fwnode = dev_fwnode(dev);
+	u32 rotation;
 	int i;
 	int rval;
 
Quoted 7 lines

drivers/media/i2c/smiapp/smiapp-core.c static struct smiapp_hwconfig *smiapp_get_hwconfig(struct device *dev) · line 2804

Quoted 5 lines
drivers/media/i2c/smiapp/smiapp-core.c +1 -0
@@ -2800,6 +2801,21 @@ static struct smiapp_hwconfig *smiapp_get_hwconfig(struct device *dev)
 
 	dev_dbg(dev, "lanes %u\n", hwcfg->lanes);
 
+	rval = fwnode_property_read_u32(fwnode, "upside-down", &rotation);

"rotation"

Thanks. Both fixed in v2.2.

Signature · 2 lines
Sakari Ailus
e-mail: [email protected]
Reviewed-by on v2 1/2
#2 lore raw

Re: [PATCH v2 1/2] dt-bindings: media: Define "rotation" property for sensors

In reply to Sakari Ailus

Hi,

Quoted 11 lines · Sakari Ailus

Sensors are occasionally mounted upside down to systems such as mobile phones or tablets. In order to use such a sensor without having to turn every image upside down, most camera sensors support reversing the readout order by setting both horizontal and vertical flipping.

This patch documents the "rotation" property for camera sensors, mirroring what is defined for displays in Documentation/devicetree/bindings/display/panel/panel.txt .

---

-- Sebastian

Quoted 21 lines
 Documentation/devicetree/bindings/media/video-interfaces.txt | 4 ++++
 1 file changed, 4 insertions(+)
Documentation/devicetree/bindings/media/video-interfaces.txt +4 -0
index 258b8dfddf48..52b7c7b57842 100644
@@ -85,6 +85,10 @@ Optional properties
 
 - lens-focus: A phandle to the node of the focus lens controller.
 
+- rotation: The device, typically an image sensor, is not mounted upright,
+  but a number of degrees counter clockwise. Typical values are 0 and 180
+  (upside down).
+
 
 Optional endpoint properties
 ----------------------------
Signature · 1 line
2.11.0
Reviewed-by on v2 2/2
#7 lore raw

Re: [PATCH v2.2 2/2] smiapp: Support the "rotation" property

In reply to Sakari Ailus

Hi,

Quoted 6 lines · Sakari Ailus

Use the "rotation" property to tell that the sensor is mounted upside down. This reverses the behaviour of the VFLIP and HFLIP controls as well as the pixel order.

---

-- Sebastian

Quoted 58 lines

since v2.2:

- Fix property name in code.

 .../devicetree/bindings/media/i2c/nokia,smia.txt         |  2 ++
 drivers/media/i2c/smiapp/smiapp-core.c                   | 16 ++++++++++++++++
 2 files changed, 18 insertions(+)
Documentation/devicetree/bindings/media/i2c/nokia,smia.txt +2 -0
index 33f10a94c381..6f509657470e 100644
@@ -29,6 +29,8 @@ Optional properties
 - reset-gpios: XSHUTDOWN GPIO
 - flash-leds: See ../video-interfaces.txt
 - lens-focus: See ../video-interfaces.txt
+- rotation: Integer property; valid values are 0 (sensor mounted upright)
+	    and 180 (sensor mounted upside down).
 
 
 Endpoint node mandatory properties
drivers/media/i2c/smiapp/smiapp-core.c +16 -0
index e1f8208581aa..e9e0f21efc2a 100644
@@ -2764,6 +2764,7 @@ static struct smiapp_hwconfig *smiapp_get_hwconfig(struct device *dev)
 	struct v4l2_fwnode_endpoint *bus_cfg;
 	struct fwnode_handle *ep;
 	struct fwnode_handle *fwnode = dev_fwnode(dev);
+	u32 rotation;
 	int i;
 	int rval;
 
@@ -2800,6 +2801,21 @@ static struct smiapp_hwconfig *smiapp_get_hwconfig(struct device *dev)
 
 	dev_dbg(dev, "lanes %u\n", hwcfg->lanes);
 
+	rval = fwnode_property_read_u32(fwnode, "rotation", &rotation);
+	if (!rval) {
+		switch (rotation) {
+		case 180:
+			hwcfg->module_board_orient =
+				SMIAPP_MODULE_BOARD_ORIENT_180;
+			/* Fall through */
+		case 0:
+			break;
+		default:
+			dev_err(dev, "invalid rotation %u\n", rotation);
+			goto out_err;
+		}
+	}
+
 	/* NVM size is not mandatory */
 	fwnode_property_read_u32(fwnode, "nokia,nvm-size", &hwcfg->nvm_size);
 
Signature · 1 line
2.11.0
#8 lore raw

Re: [PATCH v2.2 2/2] smiapp: Support the "rotation" property

Quoted 11 lines · Sebastian Reichel

Hi,

Quoted 6 lines · Sakari Ailus

Use the "rotation" property to tell that the sensor is mounted upside down. This reverses the behaviour of the VFLIP and HFLIP controls as well as the pixel order.

---

Danke sch�n!

Signature · 2 lines
Sakari Ailus
[email protected]
maintainer Reviewed-by on v2 1/2
#3 lore raw

Re: [PATCH v2 1/2] dt-bindings: media: Define "rotation" property for sensors

In reply to Sakari Ailus
Quoted 5 lines · Sakari Ailus

Sensors are occasionally mounted upside down to systems such as mobile phones or tablets. In order to use such a sensor without having to turn every image upside down, most camera sensors support reversing the readout order by setting both horizontal and vertical flipping.

Quoted 8 lines

This patch documents the "rotation" property for camera sensors, mirroring what is defined for displays in Documentation/devicetree/bindings/display/panel/panel.txt .

---
 Documentation/devicetree/bindings/media/video-interfaces.txt | 4 ++++
 1 file changed, 4 insertions(+)
maintainer Acked-by on v2 2/2
#9 lore raw

Re: [PATCH v2.2 2/2] smiapp: Support the "rotation" property

In reply to Sakari Ailus
Quoted 11 lines · Sakari Ailus

Use the "rotation" property to tell that the sensor is mounted upside down. This reverses the behaviour of the VFLIP and HFLIP controls as well as the pixel order.

---
since v2.2:

- Fix property name in code.

 .../devicetree/bindings/media/i2c/nokia,smia.txt         |  2 ++
Quoted 2 lines
 drivers/media/i2c/smiapp/smiapp-core.c                   | 16 ++++++++++++++++
 2 files changed, 18 insertions(+)