Thread (20 messages) 20 messages, 3 authors, 2024-08-21

Re: [PATCH v4 5/6] platform/chrome: Introduce device tree hardware prober

From: Chen-Yu Tsai <wenst@chromium.org>
Date: 2024-08-14 10:10:17
Also in: chrome-platform, linux-devicetree, linux-i2c, linux-mediatek, lkml

On Tue, Aug 13, 2024 at 7:46 PM Andy Shevchenko
[off-list ref] wrote:
On Thu, Aug 08, 2024 at 05:59:28PM +0800, Chen-Yu Tsai wrote:
quoted
Some devices are designed and manufactured with some components having
multiple drop-in replacement options. These components are often
connected to the mainboard via ribbon cables, having the same signals
and pin assignments across all options. These may include the display
panel and touchscreen on laptops and tablets, and the trackpad on
laptops. Sometimes which component option is used in a particular device
can be detected by some firmware provided identifier, other times that
information is not available, and the kernel has to try to probe each
device.

This change attempts to make the "probe each device" case cleaner. The
current approach is to have all options added and enabled in the device
tree. The kernel would then bind each device and run each driver's probe
function. This works, but has been broken before due to the introduction
of asynchronous probing, causing multiple instances requesting "shared"
resources, such as pinmuxes, GPIO pins, interrupt lines, at the same
time, with only one instance succeeding. Work arounds for these include
moving the pinmux to the parent I2C controller, using GPIO hogs or
pinmux settings to keep the GPIO pins in some fixed configuration, and
requesting the interrupt line very late. Such configurations can be seen
on the MT8183 Krane Chromebook tablets, and the Qualcomm sc8280xp-based
Lenovo Thinkpad 13S.

Instead of this delicate dance between drivers and device tree quirks,
this change introduces a simple I2C component prober. For any given
class of devices on the same I2C bus, it will go through all of them,
doing a simple I2C read transfer and see which one of them responds.
It will then enable the device that responds.

This requires some minor modifications in the existing device tree.
The status for all the device nodes for the component options must be
set to "failed-needs-probe". This makes it clear that some mechanism is
needed to enable one of them, and also prevents the prober and device
drivers running at the same time.
...
quoted
+ * Copyright (c) 2023 Google LLC
At bare minimum we are in 2024 now.
Ack.
...
quoted
+#include <linux/array_size.h>
+#include <linux/i2c.h>
+#include <linux/module.h>
quoted
+#include <linux/of.h>
Why?
Might have been left over from previous work and squashed into the wrong
commit. Will remove.
quoted
+#include <linux/platform_device.h>
...
quoted
+     for (size_t i = 0; i < ARRAY_SIZE(hw_prober_platforms); i++) {
+             if (!of_machine_is_compatible(hw_prober_platforms[i].compatible))
+                     continue;
quoted
+             int ret;
I didn't know we allow this kind of definition mix besides for-loop and
__free()... Can you point me out where this style change was discussed?
Will move to the top of the for loop block.
quoted
+             ret = hw_prober_platforms[i].prober(&pdev->dev, hw_prober_platforms[i].data);
+             /* Ignore unrecoverable errors and keep going through other probers */
+             if (ret == -EPROBE_DEFER)
+                     return ret;
+     }
...
quoted
+static void chromeos_of_hw_prober_driver_exit(void)
+{
+     if (!chromeos_of_hw_prober_pdev)
+             return;
First of all, this is dup for the next call, second, when may this conditional
be true?
When the module is loaded on a machine that doesn't match any entry,
neither the driver nor the device are registered. Hence the check.

Or maybe the proper way to handle it is to return -ENODEV or something?
I'll work towards that.

Thanks
ChenYu
quoted
+     platform_device_unregister(chromeos_of_hw_prober_pdev);
+     platform_driver_unregister(&chromeos_of_hw_prober_driver);
+}
+module_exit(chromeos_of_hw_prober_driver_exit);
--
With Best Regards,
Andy Shevchenko
  
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help