Skip to contentSkip to conversation

drm: Prepare to use a GPIO on ti-sn65dsi86 for Hot Plug Detect

PATCH Superseded Douglas Anderson 2 participants 15 messages Apr 21, 2020 – Apr 23, 2020

Subsystems (9)

v2 of 6 Superseded Latest is v6 →

lore
Share & tools
lore

Douglas Anderson

author reviewer
#0 lore raw

v2 cover drm: Prepare to use a GPIO on ti-sn65dsi86 for Hot Plug Detect

As talked about in commit c2bfc223882d ("drm/bridge: ti-sn65dsi86:
Remove the mystery delay"), the normal HPD pin on ti-sn65dsi86 is kinda useless, at least for embedded DisplayPort (eDP). However, despite the fact that the actual HPD pin on the bridge is mostly useless for eDP, the concept of HPD for eDP still makes sense. It allows us to optimize out a hardcoded delay that many panels need if HPD isn't hooked up. Panel timing diagrams show HPD as one of the events to measure timing from and we have to assume the worst case if we can't actually read HPD.

One way to use HPD for eDP without using the mostly useless HPD pin on ti-sn65dsi86 is to route the panel's HPD somewhere else in the system, like to a GPIO. This works great because eDP panels aren't physically hotplugged. That means the debouncing logic that caused us problems wasn't really needed and a raw GPIO works great.

As per the above, a smart board designer would realize the value of HPD and choose to route it to a GPIO somewhere on the board to avoid the silly sn65dsi86 debouncing. While said "smart designer" could theoretically route HPD anywhere on the board, a really smart designer would realize that there are several GPIOs on the bridge itself that are nearly useless for anything but this purpose and route HPD to one of those.

This series of patches is intended to allow the scenario described above.

This patch has been tested on a board that is not yet mainline. On the hardware I have:
- Panel spec says HPD could take up to 200 ms to come up, so without HPD hooked up we need to delay 200 ms.
- On my board the panel is powered by the same rail as the touchscreen. By chance of probe order the touchscreen comes up first. This means by the time we check HPD in ti_sn_bridge_enable() it's already up. Thus we can use the panel on 200 ms earlier.
- If I measure HPD on this pane it comes up ~56 ms after the panel is powered. This means I can save 144 ms of delay.

Side effects (though not main goals) of this series are:
- ti-sn65dsi86 GPIOs are now exported in Linux.
- ti-sn65dsi86 bindings are converted to yaml.
- Common panel bindings now have "hpd-gpios" listed.
- The simple-panel driver in Linux can delay in prepare based on "hpd-gpios"
- ti-sn65dsi86 bindings (and current user) now specifies "no-hpd" if HPD isn't hooked up.

Changes in v2:
- ("Export...GPIOs") is 1/2 of replacement for ("Allow...bridge GPIOs")
- ("dt-bindings: display: Add hpd-gpios to panel-common...") new for v2
- ("simple...hpd-gpios") is 1/2 of replacement for ("Allow...bridge GPIOs")
- specification => specifier.
- power up => power.
- Added back missing suspend-gpios.
- data-lanes and lane-polarities are are the right place now.
- endpoints don't need to be patternProperties.
- Specified more details for data-lanes and lane-polarities.
- Added old example back in, fixing bugs in it.
- Example i2c bus is just called "i2c", not "i2c1" now.
- ("dt-bindings: drm/bridge: ti-sn65dsi86: Document no-hpd") new for v2.
- ("arm64: dts: sdm845: Add "no-hpd" to sn65dsi86 on cheza") new for v2.

Douglas Anderson (6):
drm/bridge: ti-sn65dsi86: Export bridge GPIOs to Linux
dt-bindings: display: Add hpd-gpios to panel-common bindings drm/panel-simple: Support hpd-gpios for delaying prepare()
dt-bindings: drm/bridge: ti-sn65dsi86: Convert to yaml
dt-bindings: drm/bridge: ti-sn65dsi86: Document no-hpd
arm64: dts: sdm845: Add "no-hpd" to sn65dsi86 on cheza

 .../bindings/display/bridge/ti,sn65dsi86.txt  |  87 ------
 .../bindings/display/bridge/ti,sn65dsi86.yaml | 285 ++++++++++++++++++
 .../bindings/display/panel/panel-common.yaml  |   6 +
 arch/arm64/boot/dts/qcom/sdm845-cheza.dtsi    |   2 +
 drivers/gpu/drm/bridge/ti-sn65dsi86.c         | 165 ++++++++++
 drivers/gpu/drm/panel/panel-simple.c          |  53 ++++
 6 files changed, 511 insertions(+), 87 deletions(-)
 delete mode 100644 Documentation/devicetree/bindings/display/bridge/ti,sn65dsi86.txt
 create mode 100644 Documentation/devicetree/bindings/display/bridge/ti,sn65dsi86.yaml
Signature · 6 lines
2.26.1.301.g55bc3eb7cb9-goog

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
author reviewer
#1 lore raw

PATCH v2 1/6 drm/bridge: ti-sn65dsi86: Export bridge GPIOs to Linux

The ti-sn65dsi86 MIPI DSI to eDP bridge chip has 4 pins on it that can be used as GPIOs in a system. Each pin can be configured as input, output, or a special function for the bridge chip. These are:
- GPIO1: SUSPEND Input
- GPIO2: DSIA VSYNC
- GPIO3: DSIA HSYNC or VSYNC
- GPIO4: PWM

Let's expose these pins as GPIOs. A few notes:
- Access to ti-sn65dsi86 is via i2c so we set "can_sleep".
- These pins can't be configured for IRQ.
- There are no programmable pulls or other fancy features.
- Keeping the bridge chip powered might be expensive. The driver is setup such that if all used GPIOs are only inputs we'll power the bridge chip on just long enough to read the GPIO and then power it off again. Setting a GPIO as output will keep the bridge powered.
- If someone releases a GPIO we'll implicitly switch it to an input so we no longer need to keep the bridge powered for it.

Becaue of all of the above limitations we just need to implement a bare-bones GPIO driver. The device tree bindings already account for this device being a GPIO controller so we only need the driver changes for it.

NOTE: Despite the fact that these pins are nominally muxable I don't believe it makes sense to expose them through the pinctrl interface as well as the GPIO interface. The special functions are things that the bridge chip driver itself would care about and it can just configure the pins as needed.

Cc Linus Walleij <[email protected]>
Cc Bartosz Golaszewski <[email protected]>

---

Changes in v2:
- ("Export...GPIOs") is 1/2 of replacement for ("Allow...bridge GPIOs")

 drivers/gpu/drm/bridge/ti-sn65dsi86.c | 165 ++++++++++++++++++++++++++
 1 file changed, 165 insertions(+)
drivers/gpu/drm/bridge/ti-sn65dsi86.c +165 -0
index 6ad688b320ae..d04c2b83d699 100644
@@ -7,6 +7,8 @@
 #include <linux/clk.h>
 #include <linux/debugfs.h>
 #include <linux/gpio/consumer.h>
+#include <linux/gpio/driver.h>
+#include <linux/gpio.h>
 #include <linux/i2c.h>
 #include <linux/iopoll.h>
 #include <linux/module.h>
@@ -54,6 +56,13 @@
 #define  BPP_18_RGB				BIT(0)
 #define SN_HPD_DISABLE_REG			0x5C
 #define  HPD_DISABLE				BIT(0)
+#define SN_GPIO_IO_REG				0x5E
+#define  SN_GPIO_INPUT_SHIFT			4
+#define  SN_GPIO_OUTPUT_SHIFT			0
+#define SN_GPIO_CTRL_REG			0x5F
+#define  SN_GPIO_MUX_INPUT			0
+#define  SN_GPIO_MUX_OUTPUT			1
+#define  SN_GPIO_MUX_SPECIAL			2
 #define SN_AUX_WDATA_REG(x)			(0x64 + (x))
 #define SN_AUX_ADDR_19_16_REG			0x74
 #define SN_AUX_ADDR_15_8_REG			0x75
@@ -102,6 +111,9 @@ struct ti_sn_bridge {
 	struct gpio_desc		*enable_gpio;
 	struct regulator_bulk_data	supplies[SN_REGULATOR_SUPPLY_NUM];
 	int				dp_lanes;
+
+	struct gpio_chip		gchip;
+	atomic_t			gchip_output;
 };
 
 static const struct regmap_range ti_sn_bridge_volatile_ranges[] = {
@@ -874,6 +886,153 @@ static int ti_sn_bridge_parse_dsi_host(struct ti_sn_bridge *pdata)
 	return 0;
 }
 
+static struct ti_sn_bridge *gchip_to_pdata(struct gpio_chip *chip)
+{
+	return container_of(chip, struct ti_sn_bridge, gchip);
+}
+
+static int ti_sn_bridge_gpio_get_direction(struct gpio_chip *chip,
+					   unsigned int offset)
+{
+	struct ti_sn_bridge *pdata = gchip_to_pdata(chip);
+
+	return (atomic_read(&pdata->gchip_output) & BIT(offset)) ?
+		GPIOF_DIR_OUT : GPIOF_DIR_IN;
+}
+
+static int ti_sn_bridge_gpio_get(struct gpio_chip *chip, unsigned int offset)
+{
+	struct ti_sn_bridge *pdata = gchip_to_pdata(chip);
+	unsigned int val;
+	int ret;
+
+	/*
+	 * When the pin is an input we don't forcibly keep the bridge
+	 * powered--we just power it on to read the pin.  NOTE: part of
+	 * the reason this works is that the bridge defaults to all 4
+	 * GPIOs being configured as GPIO input.  Also note that if
+	 * something else is keeping the chip powered the pm_runtime
+	 * functions are lightweight increments of a refcount.
+	 */
+	pm_runtime_get_sync(pdata->dev);
+	ret = regmap_read(pdata->regmap, SN_GPIO_IO_REG, &val);
+	pm_runtime_put(pdata->dev);
+
+	if (ret)
+		return ret;
+
+	return (val >> (SN_GPIO_INPUT_SHIFT + offset)) & 1;
+}
+
+static void ti_sn_bridge_gpio_set(struct gpio_chip *chip, unsigned int offset,
+				  int val)
+{
+	struct ti_sn_bridge *pdata = gchip_to_pdata(chip);
+	int ret;
+
+	if (!(atomic_read(&pdata->gchip_output) & BIT(offset))) {
+		dev_err(pdata->dev, "Ignoring GPIO set while input\n");
+		return;
+	}
+
+	val &= 1;
+	ret = regmap_update_bits(pdata->regmap, SN_GPIO_IO_REG,
+				 BIT(SN_GPIO_OUTPUT_SHIFT + offset),
+				 val << (SN_GPIO_OUTPUT_SHIFT + offset));
+}
+
+static int ti_sn_bridge_gpio_direction_input(struct gpio_chip *chip,
+					     unsigned int offset)
+{
+	struct ti_sn_bridge *pdata = gchip_to_pdata(chip);
+	int shift = offset * 2;
+	int old_gchip_output;
+	int ret;
+
+	old_gchip_output = atomic_fetch_andnot(BIT(offset),
+					       &pdata->gchip_output);
+	if (!(old_gchip_output & BIT(offset)))
+		return 0;
+
+	ret = regmap_update_bits(pdata->regmap, SN_GPIO_CTRL_REG,
+				 0x3 << shift, SN_GPIO_MUX_INPUT << shift);
+	if (ret) {
+		atomic_or(BIT(offset), &pdata->gchip_output);
+		return ret;
+	}
+
+	pm_runtime_put(pdata->dev);
+
+	return 0;
+}
+
+static int ti_sn_bridge_gpio_direction_output(struct gpio_chip *chip,
+					      unsigned int offset, int val)
+{
+	struct ti_sn_bridge *pdata = gchip_to_pdata(chip);
+	int shift = offset * 2;
+	int old_gchip_output;
+	int ret;
+
+	old_gchip_output = atomic_fetch_or(BIT(offset), &pdata->gchip_output);
+	if (old_gchip_output & BIT(offset))
+		return 0;
+
+	pm_runtime_get_sync(pdata->dev);
+
+	/* Set value first to avoid glitching */
+	ti_sn_bridge_gpio_set(chip, offset, val);
+
+	/* Set direction */
+	ret = regmap_update_bits(pdata->regmap, SN_GPIO_CTRL_REG,
+				 0x3 << shift, SN_GPIO_MUX_OUTPUT << shift);
+	if (ret) {
+		atomic_andnot(BIT(offset), &pdata->gchip_output);
+		pm_runtime_put(pdata->dev);
+	}
+
+	return ret;
+}
+
+static void ti_sn_bridge_gpio_free(struct gpio_chip *chip, unsigned int offset)
+{
+	/* We won't keep pm_runtime if we're input, so switch there on free */
+	ti_sn_bridge_gpio_direction_input(chip, offset);
+}
+
+static const char * const ti_sn_bridge_gpio_names[] = {
+	"GPIO1", "GPIO2", "GPIO3", "GPIO4"
+};
+
+static int ti_sn_setup_gpio_controller(struct ti_sn_bridge *pdata)
+{
+	int ret;
+
+	/* Only init if someone is going to use us as a GPIO controller */
+	if (!of_property_read_bool(pdata->dev->of_node, "gpio-controller"))
+		return 0;
+
+	pdata->gchip.label = dev_name(pdata->dev);
+	pdata->gchip.parent = pdata->dev;
+	pdata->gchip.owner = THIS_MODULE;
+	pdata->gchip.free = ti_sn_bridge_gpio_free;
+	pdata->gchip.get_direction = ti_sn_bridge_gpio_get_direction;
+	pdata->gchip.direction_input = ti_sn_bridge_gpio_direction_input;
+	pdata->gchip.direction_output = ti_sn_bridge_gpio_direction_output;
+	pdata->gchip.get = ti_sn_bridge_gpio_get;
+	pdata->gchip.set = ti_sn_bridge_gpio_set;
+	pdata->gchip.can_sleep = true;
+	pdata->gchip.names = ti_sn_bridge_gpio_names;
+	pdata->gchip.ngpio = ARRAY_SIZE(ti_sn_bridge_gpio_names);
+	ret = devm_gpiochip_add_data(pdata->dev, &pdata->gchip, pdata);
+	if (ret) {
+		dev_err(pdata->dev, "can't add gpio chip\n");
+		return ret;
+	}
+
+	return 0;
+}
+
 static int ti_sn_bridge_probe(struct i2c_client *client,
 			      const struct i2c_device_id *id)
 {
@@ -937,6 +1096,12 @@ static int ti_sn_bridge_probe(struct i2c_client *client,
 
 	pm_runtime_enable(pdata->dev);
 
+	ret = ti_sn_setup_gpio_controller(pdata);
+	if (ret) {
+		pm_runtime_disable(pdata->dev);
+		return ret;
+	}
+
 	i2c_set_clientdata(client, pdata);
 
 	pdata->aux.name = "ti-sn65dsi86-aux";
Signature · 1 line
2.26.1.301.g55bc3eb7cb9-goog
author reviewer
#6 lore raw

PATCH v2 2/6 dt-bindings: display: Add hpd-gpios to panel-common bindings

In reply to Douglas Anderson

In the cases where there is no connector in a system there's no great place to put "hpd-gpios". As per discussion [1] the best place to put it is in the panel. Add this to the device tree bindings.

[1] https://lore.kernel.org/r/[email protected]

---

Changes in v2:
- ("dt-bindings: display: Add hpd-gpios to panel-common...") new for v2

 .../devicetree/bindings/display/panel/panel-common.yaml     | 6 ++++++
 1 file changed, 6 insertions(+)
Documentation/devicetree/bindings/display/panel/panel-common.yaml +6 -0
index ed051ba12084..e9a04a3a4f5f 100644
@@ -96,6 +96,12 @@ properties:
       (hot plug detect) signal, but the signal isn't hooked up so we should
       hardcode the max delay from the panel spec when powering up the panel.
 
+  hpd-gpios:
+    maxItems: 1
+    description:
+      If Hot Plug Detect (HPD) is connected to a GPIO in the system rather
+      than a dedicated HPD pin the pin can be specified here.
+
   # Control I/Os
 
   # Many display panels can be controlled through pins driven by GPIOs. The nature
Signature · 6 lines
2.26.1.301.g55bc3eb7cb9-goog

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
author reviewer
#8 lore raw

PATCH v2 3/6 drm/panel-simple: Support hpd-gpios for delaying prepare()

In reply to Douglas Anderson

People use panel-simple when they have panels that are builtin to their device. In these cases the HPD (Hot Plug Detect) signal isn't really used for hotplugging devices but instead is used for power sequencing. Panel timing diagrams (especially for eDP panels) usually have the HPD signal in them and it acts as an indicator that the panel is ready for us to talk to it.

Sometimes the HPD signal is hooked up to a normal GPIO on a system. In this case we need to poll it in the correct place to know that the panel is ready for us. In some system designs the right place for this is panel-simple.

When adding this support, we'll account for the case that there might be a circular dependency between panel-simple and the provider of the GPIO. The case this was designed for was for the "ti-sn65dsi86" bridge chip. If HPD is hooked up to one of the GPIOs provided by the bridge chip then in our probe function we'll always get back -EPROBE_DEFER. Let's handle this by allowing this GPIO to show up late if we saw -EPROBE_DEFER during probe.

---

Changes in v2:
- ("simple...hpd-gpios") is 1/2 of replacement for ("Allow...bridge GPIOs")

 drivers/gpu/drm/panel/panel-simple.c | 53 ++++++++++++++++++++++++++++
 1 file changed, 53 insertions(+)
drivers/gpu/drm/panel/panel-simple.c +53 -0
index 3ad828eaefe1..f816e2aa29cd 100644
@@ -23,6 +23,7 @@
 
 #include <linux/delay.h>
 #include <linux/gpio/consumer.h>
+#include <linux/iopoll.h>
 #include <linux/module.h>
 #include <linux/of_platform.h>
 #include <linux/platform_device.h>
@@ -108,6 +109,7 @@ struct panel_simple {
 	struct i2c_adapter *ddc;
 
 	struct gpio_desc *enable_gpio;
+	struct gpio_desc *hpd_gpio;
 
 	struct drm_display_mode override_mode;
 };
@@ -259,11 +261,37 @@ static int panel_simple_unprepare(struct drm_panel *panel)
 	return 0;
 }
 
+static int panel_simple_get_hpd_gpio(struct device *dev,
+				     struct panel_simple *p, bool from_probe)
+{
+	int err;
+
+	p->hpd_gpio = devm_gpiod_get_optional(dev, "hpd", GPIOD_IN);
+	if (IS_ERR(p->hpd_gpio)) {
+		err = PTR_ERR(p->hpd_gpio);
+
+		/*
+		 * If we're called from probe we won't consider '-EPROBE_DEFER'
+		 * to be an error--we'll leave the error code in "hpd_gpio".
+		 * When we try to use it we'll try again.  This allows for
+		 * circular dependencies where the component providing the
+		 * hpd gpio needs the panel to init before probing.
+		 */
+		if (err != -EPROBE_DEFER || !from_probe) {
+			dev_err(dev, "failed to get 'hpd' GPIO: %d\n", err);
+			return err;
+		}
+	}
+
+	return 0;
+}
+
 static int panel_simple_prepare(struct drm_panel *panel)
 {
 	struct panel_simple *p = to_panel_simple(panel);
 	unsigned int delay;
 	int err;
+	int hpd_asserted;
 
 	if (p->prepared)
 		return 0;
@@ -282,6 +310,26 @@ static int panel_simple_prepare(struct drm_panel *panel)
 	if (delay)
 		msleep(delay);
 
+	if (p->hpd_gpio) {
+		if (IS_ERR(p->hpd_gpio)) {
+			err = panel_simple_get_hpd_gpio(panel->dev, p, false);
+			if (err)
+				return err;
+		}
+
+		err = readx_poll_timeout(gpiod_get_value_cansleep, p->hpd_gpio,
+					 hpd_asserted, hpd_asserted,
+					 1000, 2000000);
+		if (hpd_asserted < 0)
+			err = hpd_asserted;
+
+		if (err) {
+			dev_err(panel->dev,
+				"error waiting for hpd GPIO: %d\n", err);
+			return err;
+		}
+	}
+
 	p->prepared = true;
 
 	return 0;
@@ -462,6 +510,11 @@ static int panel_simple_probe(struct device *dev, const struct panel_desc *desc)
 	panel->desc = desc;
 
 	panel->no_hpd = of_property_read_bool(dev->of_node, "no-hpd");
+	if (!panel->no_hpd) {
+		err = panel_simple_get_hpd_gpio(dev, panel, true);
+		if (err)
+			return err;
+	}
 
 	panel->supply = devm_regulator_get(dev, "power");
 	if (IS_ERR(panel->supply))
Signature · 6 lines
2.26.1.301.g55bc3eb7cb9-goog

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
author reviewer
#11 lore raw

PATCH v2 5/6 dt-bindings: drm/bridge: ti-sn65dsi86: Document no-hpd

In reply to Douglas Anderson

The ti-sn65dsi86 MIPI DSI to eDP bridge chip has a dedicated hardware HPD (Hot Plug Detect) pin on it, but it's mostly useless for eDP because of excessive debouncing in hardware. Specifically there is no way to disable the debouncing and for eDP debouncing hurts you because HPD is just used for knowing when the panel is ready, not for detecting physical plug events.

Currently the driver in Linux just assumes that nobody has HPD hooked up. It relies on folks setting the "no-hpd" property in the panel node to specify that HPD isn't hooked up and then the panel driver using this to add some worst case delays when turning on the panel.

Apparently it's also useful to specify "no-hpd" in the bridge node so that the bridge driver can make sure it's doing the right thing without peeking into the panel [1]. This would be used if anyone ever found it useful implement support for the HW HPD pin on the bridge. Let's add this property to the bindings.

NOTES:
- This is somewhat of a backward-incompatible change. All current known users of ti-sn65dsi86 didn't have "no-hpd" specified in the bridge node yet none of them had HPD hooked up. This worked because the current Linux driver just assumed that HPD was never hooked up. We could make it less incompatible by saying that for this bridge it's assumed HPD isn't hooked up _unless_ a property is defined, but "no-hpd" is much more standard and it's unlikely to matter unless someone quickly goes and implements HPD in the driver.
- It is sensible to specify "no-hpd" at the bridge chip level and specify "hpd-gpios" at the panel level. That would mean HPD is hooked up to some other GPIO in the system, just not the hardware HPD pin on the bridge chip.

[1] https://lore.kernel.org/r/[email protected]

---

Changes in v2:
- ("dt-bindings: drm/bridge: ti-sn65dsi86: Document no-hpd") new for v2.

 .../devicetree/bindings/display/bridge/ti,sn65dsi86.yaml    | 6 ++++++
 1 file changed, 6 insertions(+)
Documentation/devicetree/bindings/display/bridge/ti,sn65dsi86.yaml +6 -0
index 6d7d40ad45ac..5746416b0f73 100644
@@ -28,6 +28,10 @@ properties:
     maxItems: 1
     description: GPIO specifier for GPIO1 pin on bridge (active low).
 
+  no-hpd:
+    type: boolean
+    description: Set if the HPD line on the bridge isn't hooked up to anything.
+
   vccio-supply:
     description: A 1.8V supply that powers the digital IOs.
 
@@ -207,6 +211,8 @@ examples:
         clocks = <&rpmhcc RPMH_LN_BB_CLK2>;
         clock-names = "refclk";
 
+        no-hpd;
+
         ports {
           #address-cells = <1>;
           #size-cells = <0>;
Signature · 1 line
2.26.1.301.g55bc3eb7cb9-goog
author reviewer
#10 lore raw

PATCH v2 4/6 dt-bindings: drm/bridge: ti-sn65dsi86: Convert to yaml

In reply to Douglas Anderson

This moves the bindings over, based a lot on toshiba,tc358768.yaml. Unless there's someone known to be better, I've set the maintainer in the yaml as the first person to submit bindings.

---

Changes in v2:
- specification => specifier.
- power up => power.
- Added back missing suspend-gpios.
- data-lanes and lane-polarities are are the right place now.
- endpoints don't need to be patternProperties.
- Specified more details for data-lanes and lane-polarities.
- Added old example back in, fixing bugs in it.
- Example i2c bus is just called "i2c", not "i2c1" now.

 .../bindings/display/bridge/ti,sn65dsi86.txt  |  87 ------
 .../bindings/display/bridge/ti,sn65dsi86.yaml | 279 ++++++++++++++++++
 2 files changed, 279 insertions(+), 87 deletions(-)
 delete mode 100644 Documentation/devicetree/bindings/display/bridge/ti,sn65dsi86.txt
 create mode 100644 Documentation/devicetree/bindings/display/bridge/ti,sn65dsi86.yaml
Documentation/devicetree/bindings/display/bridge/ti,sn65dsi86.txt deleted +0 -87
deleted file mode 100644
index 8ec4a7f2623a..000000000000
@@ -1,87 +0,0 @@
-SN65DSI86 DSI to eDP bridge chip
---------------------------------
-
-This is the binding for Texas Instruments SN65DSI86 bridge.
-http://www.ti.com/general/docs/lit/getliterature.tsp?genericPartNumber=sn65dsi86&fileType=pdf
-
-Required properties:
-- compatible: Must be "ti,sn65dsi86"
-- reg: i2c address of the chip, 0x2d as per datasheet
-- enable-gpios: gpio specification for bridge_en pin (active high)
-
-- vccio-supply: A 1.8V supply that powers up the digital IOs.
-- vpll-supply: A 1.8V supply that powers up the displayport PLL.
-- vcca-supply: A 1.2V supply that powers up the analog circuits.
-- vcc-supply: A 1.2V supply that powers up the digital core.
-
-Optional properties:
-- interrupts-extended: Specifier for the SN65DSI86 interrupt line.
-
-- gpio-controller: Marks the device has a GPIO controller.
-- #gpio-cells    : Should be two. The first cell is the pin number and
-                   the second cell is used to specify flags.
-                   See ../../gpio/gpio.txt for more information.
-- #pwm-cells : Should be one. See ../../pwm/pwm.yaml for description of
-               the cell formats.
-
-- clock-names: should be "refclk"
-- clocks: Specification for input reference clock. The reference
-	  clock rate must be 12 MHz, 19.2 MHz, 26 MHz, 27 MHz or 38.4 MHz.
-
-- data-lanes: See ../../media/video-interface.txt
-- lane-polarities: See ../../media/video-interface.txt
-
-- suspend-gpios: specification for GPIO1 pin on bridge (active low)
-
-Required nodes:
-This device has two video ports. Their connections are modelled using the
-OF graph bindings specified in Documentation/devicetree/bindings/graph.txt.
-
-- Video port 0 for DSI input
-- Video port 1 for eDP output
-
-Example
--------
-
-edp-bridge@2d {
-	compatible = "ti,sn65dsi86";
-	#address-cells = <1>;
-	#size-cells = <0>;
-	reg = <0x2d>;
-
-	enable-gpios = <&msmgpio 33 GPIO_ACTIVE_HIGH>;
-	suspend-gpios = <&msmgpio 34 GPIO_ACTIVE_LOW>;
-
-	interrupts-extended = <&gpio3 4 IRQ_TYPE_EDGE_FALLING>;
-
-	vccio-supply = <&pm8916_l17>;
-	vcca-supply = <&pm8916_l6>;
-	vpll-supply = <&pm8916_l17>;
-	vcc-supply = <&pm8916_l6>;
-
-	clock-names = "refclk";
-	clocks = <&input_refclk>;
-
-	ports {
-		#address-cells = <1>;
-		#size-cells = <0>;
-
-		port@0 {
-			reg = <0>;
-
-			edp_bridge_in: endpoint {
-				remote-endpoint = <&dsi_out>;
-			};
-		};
-
-		port@1 {
-			reg = <1>;
-
-			edp_bridge_out: endpoint {
-				data-lanes = <2 1 3 0>;
-				lane-polarities = <0 1 0 1>;
-				remote-endpoint = <&edp_panel_in>;
-			};
-		};
-	};
-}
Documentation/devicetree/bindings/display/bridge/ti,sn65dsi86.yaml new file +279 -0

279 lines not on this page · raw message

Signature · 6 lines
2.26.1.301.g55bc3eb7cb9-goog

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
author reviewer
#13 lore raw

PATCH v2 6/6 arm64: dts: sdm845: Add "no-hpd" to sn65dsi86 on cheza

In reply to Douglas Anderson

We don't have the HPD line hooked up to the bridge chip. Add it as suggested in the patch ("dt-bindings: drm/bridge: ti-sn65dsi86:
Document no-hpd").

NOTE: this patch isn't expected to have any effect but just keeps us cleaner for the future. Currently the driver in Linux just assumes that nobody has HPD hooked up. This change allows us to later implement HPD support in the driver without messing up sdm845-cheza.

---

Changes in v2:
- ("arm64: dts: sdm845: Add "no-hpd" to sn65dsi86 on cheza") new for v2.

 arch/arm64/boot/dts/qcom/sdm845-cheza.dtsi | 2 ++
 1 file changed, 2 insertions(+)
arch/arm64/boot/dts/qcom/sdm845-cheza.dtsi +2 -0
index 9070be43a309..5938f8b2aa2f 100644
@@ -548,6 +548,8 @@ sn65dsi86_bridge: bridge@2d {
 		clocks = <&rpmhcc RPMH_LN_BB_CLK2>;
 		clock-names = "refclk";
 
+		no-hpd;
+
 		ports {
 			#address-cells = <1>;
 			#size-cells = <0>;
Signature · 1 line
2.26.1.301.g55bc3eb7cb9-goog
Reviewed-by on v2 6/6
#14 lore raw

Re: [PATCH v2 6/6] arm64: dts: sdm845: Add "no-hpd" to sn65dsi86 on cheza

Quoting Douglas Anderson (2020-04-20 22:06:22)

Quoted 11 lines

We don't have the HPD line hooked up to the bridge chip. Add it as suggested in the patch ("dt-bindings: drm/bridge: ti-sn65dsi86:
Document no-hpd").

NOTE: this patch isn't expected to have any effect but just keeps us cleaner for the future. Currently the driver in Linux just assumes that nobody has HPD hooked up. This change allows us to later implement HPD support in the driver without messing up sdm845-cheza.

---

Reviewed-by on v2 5/6
#12 lore raw

Re: [PATCH v2 5/6] dt-bindings: drm/bridge: ti-sn65dsi86: Document no-hpd

In reply to Douglas Anderson

Quoting Douglas Anderson (2020-04-20 22:06:21)

Quoted 12 lines

The ti-sn65dsi86 MIPI DSI to eDP bridge chip has a dedicated hardware HPD (Hot Plug Detect) pin on it, but it's mostly useless for eDP because of excessive debouncing in hardware. Specifically there is no way to disable the debouncing and for eDP debouncing hurts you because HPD is just used for knowing when the panel is ready, not for detecting physical plug events.

Currently the driver in Linux just assumes that nobody has HPD hooked up. It relies on folks setting the "no-hpd" property in the panel node to specify that HPD isn't hooked up and then the panel driver using this to add some worst case delays when turning on the panel.

Quoted 4 lines

Apparently it's also useful to specify "no-hpd" in the bridge node so that the bridge driver can make sure it's doing the right thing without peeking into the panel [1]. This would be used if anyone ever found it useful implement support for the HW HPD pin on the bridge.

useful to implement?

Quoted 16 lines

Let's add this property to the bindings.

NOTES:
- This is somewhat of a backward-incompatible change. All current known users of ti-sn65dsi86 didn't have "no-hpd" specified in the bridge node yet none of them had HPD hooked up. This worked because the current Linux driver just assumed that HPD was never hooked up. We could make it less incompatible by saying that for this bridge it's assumed HPD isn't hooked up _unless_ a property is defined, but "no-hpd" is much more standard and it's unlikely to matter unless someone quickly goes and implements HPD in the driver.
- It is sensible to specify "no-hpd" at the bridge chip level and specify "hpd-gpios" at the panel level. That would mean HPD is hooked up to some other GPIO in the system, just not the hardware HPD pin on the bridge chip.

Quoted 4 lines

[1] https://lore.kernel.org/r/[email protected]

---

Reviewed-by on v2 2/6
#7 lore raw

Re: [PATCH v2 2/6] dt-bindings: display: Add hpd-gpios to panel-common bindings

In reply to Douglas Anderson

Quoting Douglas Anderson (2020-04-20 22:06:18)

Quoted 8 lines

In the cases where there is no connector in a system there's no great place to put "hpd-gpios". As per discussion [1] the best place to put it is in the panel. Add this to the device tree bindings.

[1] https://lore.kernel.org/r/[email protected]

---

#2 lore raw

Re: [PATCH v2 1/6] drm/bridge: ti-sn65dsi86: Export bridge GPIOs to Linux

In reply to Douglas Anderson

Quoting Douglas Anderson (2020-04-20 22:06:17)

Quoted 19 lines

The ti-sn65dsi86 MIPI DSI to eDP bridge chip has 4 pins on it that can be used as GPIOs in a system. Each pin can be configured as input, output, or a special function for the bridge chip. These are:
- GPIO1: SUSPEND Input
- GPIO2: DSIA VSYNC
- GPIO3: DSIA HSYNC or VSYNC
- GPIO4: PWM

Let's expose these pins as GPIOs. A few notes:
- Access to ti-sn65dsi86 is via i2c so we set "can_sleep".
- These pins can't be configured for IRQ.
- There are no programmable pulls or other fancy features.
- Keeping the bridge chip powered might be expensive. The driver is setup such that if all used GPIOs are only inputs we'll power the bridge chip on just long enough to read the GPIO and then power it off again. Setting a GPIO as output will keep the bridge powered.
- If someone releases a GPIO we'll implicitly switch it to an input so we no longer need to keep the bridge powered for it.

Quoted 1 line

Becaue of all of the above limitations we just need to implement a

Because

Quoted 10 lines

bare-bones GPIO driver. The device tree bindings already account for this device being a GPIO controller so we only need the driver changes for it.

NOTE: Despite the fact that these pins are nominally muxable I don't believe it makes sense to expose them through the pinctrl interface as well as the GPIO interface. The special functions are things that the bridge chip driver itself would care about and it can just configure the pins as needed.

Quoted 5 lines
Cc Linus Walleij <[email protected]>
Cc Bartosz Golaszewski <[email protected]>

---

Cool patch.

Quoted 15 lines

Changes in v2:
- ("Export...GPIOs") is 1/2 of replacement for ("Allow...bridge GPIOs")

 drivers/gpu/drm/bridge/ti-sn65dsi86.c | 165 ++++++++++++++++++++++++++
 1 file changed, 165 insertions(+)
drivers/gpu/drm/bridge/ti-sn65dsi86.c +1 -0
index 6ad688b320ae..d04c2b83d699 100644
@@ -874,6 +886,153 @@ static int ti_sn_bridge_parse_dsi_host(struct ti_sn_bridge *pdata)
        return 0;
 }
 
+static struct ti_sn_bridge *gchip_to_pdata(struct gpio_chip *chip)

drivers/gpu/drm/bridge/ti-sn65dsi86.c static int ti_sn_bridge_parse_dsi_host(struct ti_sn_bridge *pdata) · line 899

Quoted 10 lines
drivers/gpu/drm/bridge/ti-sn65dsi86.c +10 -0
+{
+       return container_of(chip, struct ti_sn_bridge, gchip);
+}
+
+static int ti_sn_bridge_gpio_get_direction(struct gpio_chip *chip,
+                                          unsigned int offset)
+{
+       struct ti_sn_bridge *pdata = gchip_to_pdata(chip);
+
+       return (atomic_read(&pdata->gchip_output) & BIT(offset)) ?

Any reason this isn't a bitmap?

drivers/gpu/drm/bridge/ti-sn65dsi86.c static int ti_sn_bridge_parse_dsi_host(struct ti_sn_bridge *pdata) · line 900

Quoted 1 line
drivers/gpu/drm/bridge/ti-sn65dsi86.c +1 -0
+               GPIOF_DIR_OUT : GPIOF_DIR_IN;

And why can't we read the hardware to figure out if it's in output or input mode?

Quoted 2 lines
drivers/gpu/drm/bridge/ti-sn65dsi86.c +2 -0
+}
+

[...]

drivers/gpu/drm/bridge/ti-sn65dsi86.c static int ti_sn_bridge_parse_dsi_host(struct ti_sn_bridge *pdata) · line 977

Quoted 9 lines
drivers/gpu/drm/bridge/ti-sn65dsi86.c +9 -0
+static int ti_sn_bridge_gpio_direction_output(struct gpio_chip *chip,
+                                             unsigned int offset, int val)
+{
+       struct ti_sn_bridge *pdata = gchip_to_pdata(chip);
+       int shift = offset * 2;
+       int old_gchip_output;
+       int ret;
+
+       old_gchip_output = atomic_fetch_or(BIT(offset), &pdata->gchip_output);

I presume gpiolib is already preventing a gpio from being modified twice at the same time. So is this atomic stuff really necessary?

Quoted 31 lines
drivers/gpu/drm/bridge/ti-sn65dsi86.c +31 -0
+       if (old_gchip_output & BIT(offset))
+               return 0;
+
+       pm_runtime_get_sync(pdata->dev);
+
+       /* Set value first to avoid glitching */
+       ti_sn_bridge_gpio_set(chip, offset, val);
+
+       /* Set direction */
+       ret = regmap_update_bits(pdata->regmap, SN_GPIO_CTRL_REG,
+                                0x3 << shift, SN_GPIO_MUX_OUTPUT << shift);
+       if (ret) {
+               atomic_andnot(BIT(offset), &pdata->gchip_output);
+               pm_runtime_put(pdata->dev);
+       }
+
+       return ret;
+}
+
+static void ti_sn_bridge_gpio_free(struct gpio_chip *chip, unsigned int offset)
+{
+       /* We won't keep pm_runtime if we're input, so switch there on free */
+       ti_sn_bridge_gpio_direction_input(chip, offset);
+}
+
+static const char * const ti_sn_bridge_gpio_names[] = {
+       "GPIO1", "GPIO2", "GPIO3", "GPIO4"
+};
+
+static int ti_sn_setup_gpio_controller(struct ti_sn_bridge *pdata)
+{

[...]

drivers/gpu/drm/bridge/ti-sn65dsi86.c static int ti_sn_bridge_parse_dsi_host(struct ti_sn_bridge *pdata) · line 1033

Quoted 9 lines
drivers/gpu/drm/bridge/ti-sn65dsi86.c +9 -0
+       pdata->gchip.names = ti_sn_bridge_gpio_names;
+       pdata->gchip.ngpio = ARRAY_SIZE(ti_sn_bridge_gpio_names);
+       ret = devm_gpiochip_add_data(pdata->dev, &pdata->gchip, pdata);
+       if (ret) {
+               dev_err(pdata->dev, "can't add gpio chip\n");
+               return ret;
+       }
+
+       return 0;

return ret?

Quoted 5 lines
drivers/gpu/drm/bridge/ti-sn65dsi86.c +2 -0
+}
+
 static int ti_sn_bridge_probe(struct i2c_client *client,
                              const struct i2c_device_id *id)
 {
author reviewer
#3 lore raw

Re: [PATCH v2 1/6] drm/bridge: ti-sn65dsi86: Export bridge GPIOs to Linux

Hi,

Quoted 57 lines · Stephen Boyd

Quoting Douglas Anderson (2020-04-20 22:06:17)

Quoted 19 lines

The ti-sn65dsi86 MIPI DSI to eDP bridge chip has 4 pins on it that can be used as GPIOs in a system. Each pin can be configured as input, output, or a special function for the bridge chip. These are:
- GPIO1: SUSPEND Input
- GPIO2: DSIA VSYNC
- GPIO3: DSIA HSYNC or VSYNC
- GPIO4: PWM

Let's expose these pins as GPIOs. A few notes:
- Access to ti-sn65dsi86 is via i2c so we set "can_sleep".
- These pins can't be configured for IRQ.
- There are no programmable pulls or other fancy features.
- Keeping the bridge chip powered might be expensive. The driver is setup such that if all used GPIOs are only inputs we'll power the bridge chip on just long enough to read the GPIO and then power it off again. Setting a GPIO as output will keep the bridge powered.
- If someone releases a GPIO we'll implicitly switch it to an input so we no longer need to keep the bridge powered for it.

Quoted 1 line

Becaue of all of the above limitations we just need to implement a

Because

Quoted 10 lines

bare-bones GPIO driver. The device tree bindings already account for this device being a GPIO controller so we only need the driver changes for it.

NOTE: Despite the fact that these pins are nominally muxable I don't believe it makes sense to expose them through the pinctrl interface as well as the GPIO interface. The special functions are things that the bridge chip driver itself would care about and it can just configure the pins as needed.

Quoted 5 lines
Cc Linus Walleij <[email protected]>
Cc Bartosz Golaszewski <[email protected]>

---

Cool patch.

Quoted 14 lines

Changes in v2:
- ("Export...GPIOs") is 1/2 of replacement for ("Allow...bridge GPIOs")

 drivers/gpu/drm/bridge/ti-sn65dsi86.c | 165 ++++++++++++++++++++++++++
 1 file changed, 165 insertions(+)
drivers/gpu/drm/bridge/ti-sn65dsi86.c +0 -0
index 6ad688b320ae..d04c2b83d699 100644
@@ -874,6 +886,153 @@ static int ti_sn_bridge_parse_dsi_host(struct ti_sn_bridge *pdata)
        return 0;
 }
 
Quoted 13 lines

drivers/gpu/drm/bridge/ti-sn65dsi86.c static int ti_sn_bridge_parse_dsi_host(struct ti_sn_bridge *pdata) · line 899

Quoted 11 lines
drivers/gpu/drm/bridge/ti-sn65dsi86.c +11 -0
+static struct ti_sn_bridge *gchip_to_pdata(struct gpio_chip *chip)
+{
+       return container_of(chip, struct ti_sn_bridge, gchip);
+}
+
+static int ti_sn_bridge_gpio_get_direction(struct gpio_chip *chip,
+                                          unsigned int offset)
+{
+       struct ti_sn_bridge *pdata = gchip_to_pdata(chip);
+
+       return (atomic_read(&pdata->gchip_output) & BIT(offset)) ?

Any reason this isn't a bitmap?

Don't bitmaps need an external lock to protect against concurrent access? When I looked I wasn't convinced that the GPIO subsystem prevented two callers from changing two GPIOs at the same time. See below for a bigger discussion.

Quoted 4 lines

drivers/gpu/drm/bridge/ti-sn65dsi86.c static int ti_sn_bridge_parse_dsi_host(struct ti_sn_bridge *pdata) · line 900

Quoted 1 line
drivers/gpu/drm/bridge/ti-sn65dsi86.c +1 -0
+               GPIOF_DIR_OUT : GPIOF_DIR_IN;

And why can't we read the hardware to figure out if it's in output or input mode?

A few reasons:

1. If nobody else had the bridge powered on this would be a slow operation involving powering the bridge on, querying via i2c, and then powering the bridge off. Not only would it be slow but you'd be powering the chip up for no really good reason. You didn't need to know anything that only the chip could tell you.

2. If nobody else had the bridge powered on then the bridge loses state and resets to defaults (everything resets to "input"). Yes, we could still power the bridge up and confirm this, but...

3. This bitmap does double-duty of not only knowing whether a pin is input or output but also whether we've incremented the "pm_runtime" refcount in order to keep the output driven. Knowing whether we've already incremented the "pm_runtime" refcount can simplify a bit of the code because we know whether it's powered without having to power it on and query. If we didn't have a cache, then when we changed a pin to input we'd do:

pm_runtime_get() // Make sure we can access
if dir_was_output:
pm_runtime_put() // Not driving anymore
set_to_input();
pm_runtime_put() // Done with access

...basically in some cases we'd do pm_runtime_put() twice in the same function. It'd work, but feels like a worse solution than the one in my patch.

4. When I bootup I see that this call gets made once per GPIO in gpiochip_add_data_with_key(). There's no reason to go through all the slowness when we know these pins are inputs.

In the next version of the patch I'll plan to add a kerneldoc comment to "struct ti_sn_bridge" and add a summary of the above for "gchip_output".

Quoted 15 lines
Quoted 2 lines
drivers/gpu/drm/bridge/ti-sn65dsi86.c +2 -0
+}
+

[...]

drivers/gpu/drm/bridge/ti-sn65dsi86.c static int ti_sn_bridge_parse_dsi_host(struct ti_sn_bridge *pdata) · line 977

Quoted 9 lines
drivers/gpu/drm/bridge/ti-sn65dsi86.c +9 -0
+static int ti_sn_bridge_gpio_direction_output(struct gpio_chip *chip,
+                                             unsigned int offset, int val)
+{
+       struct ti_sn_bridge *pdata = gchip_to_pdata(chip);
+       int shift = offset * 2;
+       int old_gchip_output;
+       int ret;
+
+       old_gchip_output = atomic_fetch_or(BIT(offset), &pdata->gchip_output);

I presume gpiolib is already preventing a gpio from being modified twice at the same time. So is this atomic stuff really necessary?

Right. I've assumed that we're not running two of these functions at the same time for the same GPIO. I'm not convinced that the GPIO core enforces this but it seems like it'd be undefined behavior for a client to be, for instance, setting and changing direction for the same GPIO in two threads at the same time. Where simple I've tried to make it so it wouldn't horribly break if someone did some amount of concurrent access of the same pin but not every corner case is handled. Mostly I focused on making sure that I could never mess up keeping track of whether I incremented the "pm_runtime" refcount for a pin. One thing specifically I didn't handle: if we were midway through ti_sn_bridge_gpio_set(), we context switched out and someone changed us to an input, then we'd possibly do an unpowered regmap_update_bits() and timeout.

What I do think is a sensible case to handle, though, is someone working with two different GPIOs exported by this controller at the same time. IIUC atomic_t allows me to only spend 1 bit per pin, have no lock, and still make sure these different consumers don't stomp on each other.

NOTE: I did a quick trace for the call chain when using the "gpioget" command-line tool. I saw:

- ti_sn_bridge_gpio_get()
- gpio_chip_get_multiple()
- gpiod_get_array_value_complex()
- linehandle_ioctl()

None of these appear to do any locking. There's sorta an implicit lock in that only one client can "request" a given GPIO at the same time so the assumption that we're somewhat protected against two concurrent accesses of the exact same GPIO is a bit justified. ...but nothing appears to protect us from concurrent accesses of different GPIOs.

I also notice that other GPIO drivers seem to grab their own locks. If it makes the patch more palatable, I can get rid of all the atomic stuff and put in a big mutex?

-Doug
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

Reviewed-by on v2 3/6
#9 lore raw

Re: [PATCH v2 3/6] drm/panel-simple: Support hpd-gpios for delaying prepare()

In reply to Douglas Anderson

Quoting Douglas Anderson (2020-04-20 22:06:19)

Quoted 12 lines

People use panel-simple when they have panels that are builtin to their device. In these cases the HPD (Hot Plug Detect) signal isn't really used for hotplugging devices but instead is used for power sequencing. Panel timing diagrams (especially for eDP panels) usually have the HPD signal in them and it acts as an indicator that the panel is ready for us to talk to it.

Sometimes the HPD signal is hooked up to a normal GPIO on a system. In this case we need to poll it in the correct place to know that the panel is ready for us. In some system designs the right place for this is panel-simple.

Quoted 7 lines

When adding this support, we'll account for the case that there might be a circular dependency between panel-simple and the provider of the GPIO. The case this was designed for was for the "ti-sn65dsi86" bridge chip. If HPD is hooked up to one of the GPIOs provided by the bridge chip then in our probe function we'll always get back -EPROBE_DEFER. Let's handle this by allowing this GPIO to show up late if we saw -EPROBE_DEFER during probe.

May be worth mentioning that if there isn't an hpd-gpios property then we only try once during probe and then after that the prepare callback doesn't try again because the gpio_get_optional() APIs are used. I had to think about that for a minute.

Quoted 3 lines

---

author reviewer
#5 lore raw

Re: [PATCH v2 1/6] drm/bridge: ti-sn65dsi86: Export bridge GPIOs to Linux

In reply to Stephen Boyd

Hi,

Quoted 36 lines · Stephen Boyd

Quoting Doug Anderson (2020-04-22 09:09:17)

Quoted 34 lines

Hi,

Quoted 30 lines · Stephen Boyd

Quoting Douglas Anderson (2020-04-20 22:06:17)

Quoted 15 lines

Changes in v2:
- ("Export...GPIOs") is 1/2 of replacement for ("Allow...bridge GPIOs")

 drivers/gpu/drm/bridge/ti-sn65dsi86.c | 165 ++++++++++++++++++++++++++
 1 file changed, 165 insertions(+)
drivers/gpu/drm/bridge/ti-sn65dsi86.c +1 -0
index 6ad688b320ae..d04c2b83d699 100644
@@ -874,6 +886,153 @@ static int ti_sn_bridge_parse_dsi_host(struct ti_sn_bridge *pdata)
        return 0;
 }
 
+static struct ti_sn_bridge *gchip_to_pdata(struct gpio_chip *chip)

drivers/gpu/drm/bridge/ti-sn65dsi86.c static int ti_sn_bridge_parse_dsi_host(struct ti_sn_bridge *pdata) · line 899

Quoted 10 lines
drivers/gpu/drm/bridge/ti-sn65dsi86.c +10 -0
+{
+       return container_of(chip, struct ti_sn_bridge, gchip);
+}
+
+static int ti_sn_bridge_gpio_get_direction(struct gpio_chip *chip,
+                                          unsigned int offset)
+{
+       struct ti_sn_bridge *pdata = gchip_to_pdata(chip);
+
+       return (atomic_read(&pdata->gchip_output) & BIT(offset)) ?

Any reason this isn't a bitmap?

Quoted 7 lines
Quoted 2 lines

Don't bitmaps need an external lock to protect against concurrent access?

Bitmaps are sometimes atomic. See Documentation/atomic_bitops.txt for more info. From what I see here it looks like we can have a bitmap for this and then use set_bit(), test_and_set_bit(), etc. and it will be the same and easier to read.

Hrm. Somehow I found the wrong place when trying to search for this previously. Thanks for pointing me in the right directions. Much nicer.

Quoted 10 lines
Quoted 10 lines

When I looked I wasn't convinced that the GPIO subsystem prevented two callers from changing two GPIOs at the same time. See below for a bigger discussion.

Quoted 4 lines

drivers/gpu/drm/bridge/ti-sn65dsi86.c static int ti_sn_bridge_parse_dsi_host(struct ti_sn_bridge *pdata) · line 900

Quoted 1 line
drivers/gpu/drm/bridge/ti-sn65dsi86.c +1 -0
+               GPIOF_DIR_OUT : GPIOF_DIR_IN;

And why can't we read the hardware to figure out if it's in output or input mode?

Quoted 8 lines

[...]

Quoted 4 lines

In the next version of the patch I'll plan to add a kerneldoc comment to "struct ti_sn_bridge" and add a summary of the above for "gchip_output".

Yeah it deserves a comment in the code indicating why it doesn't read the hardware.

OK, added a whole bunch more comments.

Barring something coming up, I'll plan to send v3 tomorrow morning with all your feedback addressed. If anyone wants me to wait because they think I need some more major change, please yell.

-Doug

#4 lore raw

Re: [PATCH v2 1/6] drm/bridge: ti-sn65dsi86: Export bridge GPIOs to Linux

In reply to Doug Anderson

Quoting Doug Anderson (2020-04-22 09:09:17)

Quoted 34 lines

Hi,

Quoted 17 lines · Stephen Boyd

Quoting Douglas Anderson (2020-04-20 22:06:17)

Quoted 14 lines

Changes in v2:
- ("Export...GPIOs") is 1/2 of replacement for ("Allow...bridge GPIOs")

 drivers/gpu/drm/bridge/ti-sn65dsi86.c | 165 ++++++++++++++++++++++++++
 1 file changed, 165 insertions(+)
drivers/gpu/drm/bridge/ti-sn65dsi86.c +0 -0
index 6ad688b320ae..d04c2b83d699 100644
@@ -874,6 +886,153 @@ static int ti_sn_bridge_parse_dsi_host(struct ti_sn_bridge *pdata)
        return 0;
 }
 
Quoted 13 lines

drivers/gpu/drm/bridge/ti-sn65dsi86.c static int ti_sn_bridge_parse_dsi_host(struct ti_sn_bridge *pdata) · line 899

Quoted 11 lines
drivers/gpu/drm/bridge/ti-sn65dsi86.c +11 -0
+static struct ti_sn_bridge *gchip_to_pdata(struct gpio_chip *chip)
+{
+       return container_of(chip, struct ti_sn_bridge, gchip);
+}
+
+static int ti_sn_bridge_gpio_get_direction(struct gpio_chip *chip,
+                                          unsigned int offset)
+{
+       struct ti_sn_bridge *pdata = gchip_to_pdata(chip);
+
+       return (atomic_read(&pdata->gchip_output) & BIT(offset)) ?

Any reason this isn't a bitmap?

Quoted 2 lines

Don't bitmaps need an external lock to protect against concurrent access?

Bitmaps are sometimes atomic. See Documentation/atomic_bitops.txt for more info. From what I see here it looks like we can have a bitmap for this and then use set_bit(), test_and_set_bit(), etc. and it will be the same and easier to read.

Quoted 10 lines

When I looked I wasn't convinced that the GPIO subsystem prevented two callers from changing two GPIOs at the same time. See below for a bigger discussion.

Quoted 4 lines

drivers/gpu/drm/bridge/ti-sn65dsi86.c static int ti_sn_bridge_parse_dsi_host(struct ti_sn_bridge *pdata) · line 900

Quoted 1 line
drivers/gpu/drm/bridge/ti-sn65dsi86.c +1 -0
+               GPIOF_DIR_OUT : GPIOF_DIR_IN;

And why can't we read the hardware to figure out if it's in output or input mode?

[...]

Quoted 4 lines

In the next version of the patch I'll plan to add a kerneldoc comment to "struct ti_sn_bridge" and add a summary of the above for "gchip_output".

Yeah it deserves a comment in the code indicating why it doesn't read the hardware.

Quoted 17 lines
Quoted 17 lines
Quoted 4 lines
drivers/gpu/drm/bridge/ti-sn65dsi86.c +2 -0
+}
+

[...]

drivers/gpu/drm/bridge/ti-sn65dsi86.c static int ti_sn_bridge_parse_dsi_host(struct ti_sn_bridge *pdata) · line 977

Quoted 9 lines
drivers/gpu/drm/bridge/ti-sn65dsi86.c +9 -0
+static int ti_sn_bridge_gpio_direction_output(struct gpio_chip *chip,
+                                             unsigned int offset, int val)
+{
+       struct ti_sn_bridge *pdata = gchip_to_pdata(chip);
+       int shift = offset * 2;
+       int old_gchip_output;
+       int ret;
+
+       old_gchip_output = atomic_fetch_or(BIT(offset), &pdata->gchip_output);

I presume gpiolib is already preventing a gpio from being modified twice at the same time. So is this atomic stuff really necessary?

[...]

Quoted 10 lines

None of these appear to do any locking. There's sorta an implicit lock in that only one client can "request" a given GPIO at the same time so the assumption that we're somewhat protected against two concurrent accesses of the exact same GPIO is a bit justified. ...but nothing appears to protect us from concurrent accesses of different GPIOs.

I also notice that other GPIO drivers seem to grab their own locks. If it makes the patch more palatable, I can get rid of all the atomic stuff and put in a big mutex?

No. I'd rather see the bitmap APIs used instead of a custom bitmap overlaid on an atomic_t. Otherwise it seems fine to assume a GPIO can't be touched by two entities at once and thus nothing to worry about for locking at the driver level for that.
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel