Currently v4l2_fwnode_device_parse() obtains the orientation and
rotation via fwnode properties.
Extend the function to support as well ACPI devices with _PLD info.
We give a higher priority to fwnode, because it might contain quirks
injected via swnodes.
Reviewed-by: Hans de Goede <hansg@kernel.org>
Signed-off-by: Ricardo Ribalda <ribalda@chromium.org>
---
drivers/media/v4l2-core/v4l2-fwnode.c | 84 ++++++++++++++++++++++++++++++++---
1 file changed, 78 insertions(+), 6 deletions(-)
diff --git a/drivers/media/v4l2-core/v4l2-fwnode.c b/drivers/media/v4l2-core/v4l2-fwnode.c
index cb153ce42c45d69600a3ec4e59a5584d7e791a2a..4110f64d3277e652473f991fb58d191862f98eb0 100644
--- a/drivers/media/v4l2-core/v4l2-fwnode.c
+++ b/drivers/media/v4l2-core/v4l2-fwnode.c
@@ -15,6 +15,7 @@
* Author: Guennadi Liakhovetski <g.liakhovetski@gmx.de>
*/
#include <linux/acpi.h>
+#include <acpi/acpi_bus.h>
#include <linux/kernel.h>
#include <linux/mm.h>
#include <linux/module.h>
@@ -807,16 +808,69 @@ int v4l2_fwnode_connector_add_link(struct fwnode_handle *fwnode,
}
EXPORT_SYMBOL_GPL(v4l2_fwnode_connector_add_link);
-int v4l2_fwnode_device_parse(struct device *dev,
- struct v4l2_fwnode_device_properties *props)
+static int v4l2_fwnode_device_parse_acpi(struct device *dev,
+ struct v4l2_fwnode_device_properties *props)
+{
+ struct acpi_pld_info *pld;
+ int ret = 0;
+
+ if (!is_acpi_device_node(dev_fwnode(dev)))
+ return 0;
+
+ if (!acpi_get_physical_device_location(ACPI_HANDLE(dev), &pld)) {
+ acpi_handle_debug(ACPI_HANDLE(dev), "cannot obtain _PLD\n");
+ return 0;
+ }
+
+ if (props->orientation == V4L2_FWNODE_PROPERTY_UNSET) {
+ switch (pld->panel) {
+ case ACPI_PLD_PANEL_FRONT:
+ props->orientation = V4L2_FWNODE_ORIENTATION_FRONT;
+ break;
+ case ACPI_PLD_PANEL_BACK:
+ props->orientation = V4L2_FWNODE_ORIENTATION_BACK;
+ break;
+ case ACPI_PLD_PANEL_TOP:
+ case ACPI_PLD_PANEL_LEFT:
+ case ACPI_PLD_PANEL_RIGHT:
+ case ACPI_PLD_PANEL_UNKNOWN:
+ props->orientation = V4L2_FWNODE_ORIENTATION_EXTERNAL;
+ break;
+ default:
+ acpi_handle_warn(ACPI_HANDLE(dev),
+ "invalid panel %u in _PLD\n",
+ pld->panel);
+ ret = -EINVAL;
+ goto done;
+ }
+ }
+
+ if (props->rotation == V4L2_FWNODE_PROPERTY_UNSET) {
+ switch (pld->rotation) {
+ case 0 ... 7:
+ props->rotation = pld->rotation * 45;
+ break;
+ default:
+ acpi_handle_warn(ACPI_HANDLE(dev),
+ "invalid rotation %u in _PLD\n",
+ pld->rotation);
+ ret = -EINVAL;
+ goto done;
+ }
+ }
+
+done:
+ ACPI_FREE(pld);
+ return ret;
+}
+
+static int v4l2_fwnode_device_parse_of(struct device *dev,
+ struct v4l2_fwnode_device_properties *props)
{
struct fwnode_handle *fwnode = dev_fwnode(dev);
u32 val;
int ret;
- memset(props, 0, sizeof(*props));
-
- props->orientation = V4L2_FWNODE_PROPERTY_UNSET;
ret = fwnode_property_read_u32(fwnode, "orientation", &val);
if (!ret) {
switch (val) {
@@ -833,7 +887,6 @@ int v4l2_fwnode_device_parse(struct device *dev,
dev_dbg(dev, "device orientation: %u\n", val);
}
- props->rotation = V4L2_FWNODE_PROPERTY_UNSET;
ret = fwnode_property_read_u32(fwnode, "rotation", &val);
if (!ret) {
if (val >= 360) {
@@ -847,6 +900,25 @@ int v4l2_fwnode_device_parse(struct device *dev,
return 0;
}
+
+int v4l2_fwnode_device_parse(struct device *dev,
+ struct v4l2_fwnode_device_properties *props)
+{
+ int ret;
+
+ memset(props, 0, sizeof(*props));
+
+ props->orientation = V4L2_FWNODE_PROPERTY_UNSET;
+ props->rotation = V4L2_FWNODE_PROPERTY_UNSET;
+
+ /* Start by looking into swnodes and DT. */
+ ret = v4l2_fwnode_device_parse_of(dev, props);
+ if (ret)
+ return ret;
+
+ /* Let's check the ACPI table. */
+ return v4l2_fwnode_device_parse_acpi(dev, props);
+}
EXPORT_SYMBOL_GPL(v4l2_fwnode_device_parse);
/*
--
2.51.0.536.g15c5d4f767-goog
Hi Ricardo, kernel test robot noticed the following build errors: [auto build test ERROR on afb100a5ea7a13d7e6937dcd3b36b19dc6cc9328] url: https://github.com/intel-lab-lkp/linux/commits/Ricardo-Ribalda/media-uvcvideo-Always-set-default_value/20250926-211524 base: afb100a5ea7a13d7e6937dcd3b36b19dc6cc9328 patch link: https://lore.kernel.org/r/20250926-uvc-orientation-v3-3-6dc2fa5b4220%40chromium.org patch subject: [PATCH v3 03/12] media: v4l: fwnode: Support ACPI's _PLD for v4l2_fwnode_device_parse config: arm-randconfig-004-20250927 (https://download.01.org/0day-ci/archive/20250927/202509271249.8fIMriJh-lkp@intel.com/config) compiler: arm-linux-gnueabi-gcc (GCC) 10.5.0 reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20250927/202509271249.8fIMriJh-lkp@intel.com/reproduce) If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags | Reported-by: kernel test robot <lkp@intel.com> | Closes: https://lore.kernel.org/oe-kbuild-all/202509271249.8fIMriJh-lkp@intel.com/ All errors (new ones prefixed by >>): In file included from include/linux/printk.h:623, from include/asm-generic/bug.h:22, from arch/arm/include/asm/bug.h:60, from include/linux/bug.h:5, from include/linux/thread_info.h:13, from include/asm-generic/preempt.h:5, from ./arch/arm/include/generated/asm/preempt.h:1, from include/linux/preempt.h:79, from include/linux/spinlock.h:56, from include/linux/mmzone.h:8, from include/linux/gfp.h:7, from include/linux/slab.h:16, from include/linux/resource_ext.h:11, from include/linux/acpi.h:13, from drivers/media/v4l2-core/v4l2-fwnode.c:17: drivers/media/v4l2-core/v4l2-fwnode.c: In function 'v4l2_fwnode_device_parse_acpi': >> include/linux/acpi.h:1268:26: error: implicit declaration of function '__acpi_handle_debug'; did you mean 'acpi_handle_debug'? [-Werror=implicit-function-declaration] 1268 | _dynamic_func_call(fmt, __acpi_handle_debug, \ | ^~~~~~~~~~~~~~~~~~~ include/linux/dynamic_debug.h:224:3: note: in definition of macro '__dynamic_func_call_cls' 224 | func(&id, ##__VA_ARGS__); \ | ^~~~ include/linux/dynamic_debug.h:250:2: note: in expansion of macro '_dynamic_func_call_cls' 250 | _dynamic_func_call_cls(_DPRINTK_CLASS_DFLT, fmt, func, ##__VA_ARGS__) | ^~~~~~~~~~~~~~~~~~~~~~ include/linux/acpi.h:1268:2: note: in expansion of macro '_dynamic_func_call' 1268 | _dynamic_func_call(fmt, __acpi_handle_debug, \ | ^~~~~~~~~~~~~~~~~~ drivers/media/v4l2-core/v4l2-fwnode.c:821:3: note: in expansion of macro 'acpi_handle_debug' 821 | acpi_handle_debug(ACPI_HANDLE(dev), "cannot obtain _PLD\n"); | ^~~~~~~~~~~~~~~~~ cc1: some warnings being treated as errors vim +1268 include/linux/acpi.h 45fef5b88d1f2f Bjørn Mork 2014-05-22 1240 fbfddae696572e Toshi Kani 2012-11-21 1241 /* fbfddae696572e Toshi Kani 2012-11-21 1242 * acpi_handle_<level>: Print message with ACPI prefix and object path fbfddae696572e Toshi Kani 2012-11-21 1243 * fbfddae696572e Toshi Kani 2012-11-21 1244 * These interfaces acquire the global namespace mutex to obtain an object fbfddae696572e Toshi Kani 2012-11-21 1245 * path. In interrupt context, it shows the object path as <n/a>. fbfddae696572e Toshi Kani 2012-11-21 1246 */ fbfddae696572e Toshi Kani 2012-11-21 1247 #define acpi_handle_emerg(handle, fmt, ...) \ fbfddae696572e Toshi Kani 2012-11-21 1248 acpi_handle_printk(KERN_EMERG, handle, fmt, ##__VA_ARGS__) fbfddae696572e Toshi Kani 2012-11-21 1249 #define acpi_handle_alert(handle, fmt, ...) \ fbfddae696572e Toshi Kani 2012-11-21 1250 acpi_handle_printk(KERN_ALERT, handle, fmt, ##__VA_ARGS__) fbfddae696572e Toshi Kani 2012-11-21 1251 #define acpi_handle_crit(handle, fmt, ...) \ fbfddae696572e Toshi Kani 2012-11-21 1252 acpi_handle_printk(KERN_CRIT, handle, fmt, ##__VA_ARGS__) fbfddae696572e Toshi Kani 2012-11-21 1253 #define acpi_handle_err(handle, fmt, ...) \ fbfddae696572e Toshi Kani 2012-11-21 1254 acpi_handle_printk(KERN_ERR, handle, fmt, ##__VA_ARGS__) fbfddae696572e Toshi Kani 2012-11-21 1255 #define acpi_handle_warn(handle, fmt, ...) \ fbfddae696572e Toshi Kani 2012-11-21 1256 acpi_handle_printk(KERN_WARNING, handle, fmt, ##__VA_ARGS__) fbfddae696572e Toshi Kani 2012-11-21 1257 #define acpi_handle_notice(handle, fmt, ...) \ fbfddae696572e Toshi Kani 2012-11-21 1258 acpi_handle_printk(KERN_NOTICE, handle, fmt, ##__VA_ARGS__) fbfddae696572e Toshi Kani 2012-11-21 1259 #define acpi_handle_info(handle, fmt, ...) \ fbfddae696572e Toshi Kani 2012-11-21 1260 acpi_handle_printk(KERN_INFO, handle, fmt, ##__VA_ARGS__) fbfddae696572e Toshi Kani 2012-11-21 1261 45fef5b88d1f2f Bjørn Mork 2014-05-22 1262 #if defined(DEBUG) fbfddae696572e Toshi Kani 2012-11-21 1263 #define acpi_handle_debug(handle, fmt, ...) \ fbfddae696572e Toshi Kani 2012-11-21 1264 acpi_handle_printk(KERN_DEBUG, handle, fmt, ##__VA_ARGS__) fbfddae696572e Toshi Kani 2012-11-21 1265 #else 45fef5b88d1f2f Bjørn Mork 2014-05-22 1266 #if defined(CONFIG_DYNAMIC_DEBUG) 45fef5b88d1f2f Bjørn Mork 2014-05-22 1267 #define acpi_handle_debug(handle, fmt, ...) \ f1ebe04f5ba2f4 Rasmus Villemoes 2019-03-07 @1268 _dynamic_func_call(fmt, __acpi_handle_debug, \ f1ebe04f5ba2f4 Rasmus Villemoes 2019-03-07 1269 handle, pr_fmt(fmt), ##__VA_ARGS__) 45fef5b88d1f2f Bjørn Mork 2014-05-22 1270 #else fbfddae696572e Toshi Kani 2012-11-21 1271 #define acpi_handle_debug(handle, fmt, ...) \ fbfddae696572e Toshi Kani 2012-11-21 1272 ({ \ fbfddae696572e Toshi Kani 2012-11-21 1273 if (0) \ fbfddae696572e Toshi Kani 2012-11-21 1274 acpi_handle_printk(KERN_DEBUG, handle, fmt, ##__VA_ARGS__); \ fbfddae696572e Toshi Kani 2012-11-21 1275 0; \ fbfddae696572e Toshi Kani 2012-11-21 1276 }) fbfddae696572e Toshi Kani 2012-11-21 1277 #endif 45fef5b88d1f2f Bjørn Mork 2014-05-22 1278 #endif fbfddae696572e Toshi Kani 2012-11-21 1279 -- 0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki
© 2016 - 2025 Red Hat, Inc.