drm/bridge: ti-sn65dsi86: fix REFCLK setting
Subsystems (4)
PATCH 1/1 drm/bridge: ti-sn65dsi86: fix REFCLK setting
The bridge has three bootstrap pins which are sampled to determine the frequency of the external reference clock. The driver will also (over)write that setting. But it seems this is racy after the bridge is enabled. It was observed that although the driver write the correct value (by sniffing on the I2C bus), the register has the wrong value. The datasheet states that the GPIO lines have to be stable for at least 5us after asserting the EN signal. Thus, there seems to be some logic which samples the GPIO lines and this logic appears to overwrite the register value which was set by the driver. Waiting 20us after asserting the EN line resolves this issue.
---
I couldn't find a good commit for a Fixes: tag and I'm not sure how fixes are handled in drm.
drivers/gpu/drm/bridge/ti-sn65dsi86.c | 11 +++++++++++ 1 file changed, 11 insertions(+)
drivers/gpu/drm/bridge/ti-sn65dsi86.c +11 -0
@@ -386,6 +386,17 @@ static int __maybe_unused ti_sn65dsi86_resume(struct device *dev)gpiod_set_value_cansleep (pdata->enable_gpio,1 ); +/* +* After EN is deasserted and an external clock is detected, the bridge +* will sample GPIO3:1 to determine its frequency. The driver will +* overwrite this setting. But this is racy. Thus we have to wait a +* couple of us. According to the datasheet the GPIO lines has to be +* stable at least 5 us (td5) but it seems that is not enough and the +* refclk frequency value is lost/overwritten by the bridge itself. +* Waiting for 20us seems to work. +*/ +usleep_range (20 ,30 ); +/* * If we have a reference clock we can enable communication w/ the * panel (including the aux channel) w/out any need for an input clock
Signature · 1 line
2.39.5
Hi,
Quoted 11 lines · Michael Walle
The bridge has three bootstrap pins which are sampled to determine the frequency of the external reference clock. The driver will also (over)write that setting. But it seems this is racy after the bridge is enabled. It was observed that although the driver write the correct value (by sniffing on the I2C bus), the register has the wrong value. The datasheet states that the GPIO lines have to be stable for at least 5us after asserting the EN signal. Thus, there seems to be some logic which samples the GPIO lines and this logic appears to overwrite the register value which was set by the driver. Waiting 20us after asserting the EN line resolves this issue.
+Jayesh might have some insight?
Quoted 16 lines
Signed-off-by Michael Walle <[email protected]>---
I couldn't find a good commit for a Fixes: tag and I'm not sure how fixes are handled in drm.drivers/gpu/drm/bridge/ti-sn65dsi86.c | 11 +++++++++++ 1 file changed, 11 insertions(+)drivers/gpu/drm/bridge/ti-sn65dsi86.c +0
-0@@ -386,6 +386,17 @@ static int __maybe_unused ti_sn65dsi86_resume(struct device *dev)gpiod_set_value_cansleep (pdata->enable_gpio,1 );
drivers/gpu/drm/bridge/ti-sn65dsi86.c static int __maybe_unused ti_sn65dsi86_resume(struct device *dev) · line 398
Quoted 10 lines
drivers/gpu/drm/bridge/ti-sn65dsi86.c +10
-0+/* +* After EN is deasserted and an external clock is detected, the bridge +* will sample GPIO3:1 to determine its frequency. The driver will +* overwrite this setting. But this is racy. Thus we have to wait a +* couple of us. According to the datasheet the GPIO lines has to be +* stable at least 5 us (td5) but it seems that is not enough and the +* refclk frequency value is lost/overwritten by the bridge itself. +* Waiting for 20us seems to work. +*/ +usleep_range (20 ,30 );
It might be worth pointing at _where_ the driver overwrites this setting, or maybe at least pointing to something that makes it easy to find which exact bits you're talking about.
This looks reasonable to me, though.
Hello Michael, Doug,
Quoted 50 lines · Doug Anderson
Hi,
Quoted 11 lines · Michael Walle
The bridge has three bootstrap pins which are sampled to determine the frequency of the external reference clock. The driver will also (over)write that setting. But it seems this is racy after the bridge is enabled. It was observed that although the driver write the correct value (by sniffing on the I2C bus), the register has the wrong value. The datasheet states that the GPIO lines have to be stable for at least 5us after asserting the EN signal. Thus, there seems to be some logic which samples the GPIO lines and this logic appears to overwrite the register value which was set by the driver. Waiting 20us after asserting the EN line resolves this issue.
+Jayesh might have some insight?
Quoted 16 lines
Signed-off-by Michael Walle <[email protected]>---
I couldn't find a good commit for a Fixes: tag and I'm not sure how fixes are handled in drm.drivers/gpu/drm/bridge/ti-sn65dsi86.c | 11 +++++++++++ 1 file changed, 11 insertions(+)drivers/gpu/drm/bridge/ti-sn65dsi86.c +0
-0@@ -386,6 +386,17 @@ static int __maybe_unused ti_sn65dsi86_resume(struct device *dev)gpiod_set_value_cansleep (pdata->enable_gpio,1 );drivers/gpu/drm/bridge/ti-sn65dsi86.c static int __maybe_unused ti_sn65dsi86_resume(struct device *dev) · line 398
Quoted 10 lines
drivers/gpu/drm/bridge/ti-sn65dsi86.c +10
-0+/* +* After EN is deasserted and an external clock is detected, the bridge +* will sample GPIO3:1 to determine its frequency. The driver will +* overwrite this setting. But this is racy. Thus we have to wait a +* couple of us. According to the datasheet the GPIO lines has to be +* stable at least 5 us (td5) but it seems that is not enough and the +* refclk frequency value is lost/overwritten by the bridge itself. +* Waiting for 20us seems to work. +*/ +usleep_range (20 ,30 );It might be worth pointing at _where_ the driver overwrites this setting, or maybe at least pointing to something that makes it easy to find which exact bits you're talking about.
Quoted 1 line
This looks reasonable to me, though.
I think we are talking about SN_DPPLL_SRC_REG[3:1] bits? What exact mismatch are you observing in register value?
I am assuming that you have a clock at REFCLK pin. For that:
If refclk is described in devicetree node, then I see that the driver modifies it in every resume call based solely on the clock value in dts.
If refclk is not described in dts, then this register is modified by the driver only when pre_enable() calls enable_comms(). Here also, the value depends on crtc_mode and the refclk_rate often would not be equal to the values in "ti_sn_bridge_dsiclk_lut" (supported frequencies), and you would fallback to "001" register value.
Rest of time, I guess it depends on reading the status from GPIO and changing the register.
Is the latter one your usecase?
- Jayesh
Quoted 2 lines
Reviewed-by Douglas Anderson <[email protected]>
Hi Jayesh,
Quoted 17 lines
Quoted 17 lines
Quoted 16 lines
(quoted diff) +2
-0+ /* + * After EN is deasserted and an external clock is detected,the bridge
+ * will sample GPIO3:1 to determine its frequency. The driver
will
+ * overwrite this setting. But this is racy. Thus we have to
wait a
+ * couple of us. According to the datasheet the GPIO lines
has to be
+ * stable at least 5 us (td5) but it seems that is not enough
and the
+ * refclk frequency value is lost/overwritten by the bridge
itself.drivers/gpu/drm/bridge/ti-sn65dsi86.c +3
-0+* Waiting for 20us seems to work. +*/ +usleep_range (20 ,30 );
Quoted 3 lines
Quoted 3 lines
It might be worth pointing at _where_ the driver overwrites this setting, or maybe at least pointing to something that makes it easy to find which exact bits you're talking about.
Yeah, Jayesh just pointed that out below. I'll add add it to the comment.
Quoted 3 lines
Quoted 1 line
This looks reasonable to me, though.
I think we are talking about SN_DPPLL_SRC_REG[3:1] bits?
Yes.
Quoted 1 line
What exact mismatch are you observing in register value?
The one set by the chip itself vs the one from the driver, see below.
Quoted 1 line
I am assuming that you have a clock at REFCLK pin. For that:
Yes, I'm using an external clock.
Quoted 3 lines
If refclk is described in devicetree node, then I see that the driver modifies it in every resume call based solely on the clock value in dts.
Exactly. But that is racy with what the chip itself is doing. I.e. if you don't have that usleep() above, the chip will win the race and the refclk frequency setting will be set according to the external GPIOs (which is poorly described in the datasheet, btw), regardless what the linux driver is setting (because that I2C write happens too early).
Quoted 8 lines
If refclk is not described in dts, then this register is modified by the driver only when
pre_enable()callsenable_comms(). Here also, the value depends oncrtc_modeand therefclk_rateoften would not be equal to the values in "ti_sn_bridge_dsiclk_lut" (supported frequencies), and you would fallback to "001" register value.Rest of time, I guess it depends on reading the status from GPIO and changing the register.
Not "rest of the time", the reading of the strapping option from the GPIO always happens if an external refclk is detected. It's part of the chip after all. It will just sometimes be overwritten by the linux driver.
Quoted 1 line
Is the latter one your usecase?
My use case is that the GPIO setting is wrong on my board (it's really non-existent) and I'm relying on the linux driver to set the correct frequency.
HTH,
-michael
Hello Michael,
Quoted 43 lines · Michael Walle
Hi Jayesh,
Quoted 17 lines
Quoted 17 lines
Quoted 16 lines
+ /*
+ * After EN is deasserted and an external clock is detected, the bridge
+ * will sample GPIO3:1 to determine its frequency. The driver will
+ * overwrite this setting. But this is racy. Thus we have to wait a
+ * couple of us. According to the datasheet the GPIO lines has to be
+ * stable at least 5 us (td5) but it seems that is not enough and the
+ * refclk frequency value is lost/overwritten by the bridge itself.
+ * Waiting for 20us seems to work.
+ */
+usleep_range(20, 30);Quoted 3 lines
Quoted 3 lines
It might be worth pointing at _where_ the driver overwrites this setting, or maybe at least pointing to something that makes it easy to find which exact bits you're talking about.
Yeah, Jayesh just pointed that out below. I'll add add it to the comment.
Quoted 3 lines
Quoted 1 line
This looks reasonable to me, though.
I think we are talking about SN_DPPLL_SRC_REG[3:1] bits?
Yes.
Quoted 1 line
What exact mismatch are you observing in register value?
The one set by the chip itself vs the one from the driver, see below.
Quoted 1 line
I am assuming that you have a clock at REFCLK pin. For that:
Yes, I'm using an external clock.
Quoted 3 lines
If refclk is described in devicetree node, then I see that the driver modifies it in every resume call based solely on the clock value in dts.
Quoted 6 lines
Exactly. But that is racy with what the chip itself is doing. I.e. if you don't have that
usleep()above, the chip will win the race and the refclk frequency setting will be set according to the external GPIOs (which is poorly described in the datasheet, btw), regardless what the linux driver is setting (because that I2C write happens too early).
I am a little confused here.
Won't it be opposite?
If we have this delay here, GPIO will stabilize and set the register accordingly?
In the driver, I came across the case when we do not have refclk. (My platform does have a refclk, I am just removing the property from the dts node to check the affect of GPIO[3:1] in question because clock is not a required property for the bridge as per the bindings)
In the ti_sn65dsi86_probe(), before we read SN_DEVICE_ID_REGS, when we go to resume(), we do not do enable_comms() that calls ti_sn_bridge_set_refclk_freq() to set SN_DPPLL_SRC_REG. I see that register read for SN_DEVICE_ID_REGS fails in that case.
Adding this delay fixes that issue. This made me think that we need the delay for GPIO to stabilize and set the refclk.
Is my understanding incorrect?
I am totally on board with your change especially after observing the above but is my understanding incorrect somewhere?
Warm Regards,
Jayesh
Quoted 23 lines
Quoted 9 lines
If refclk is not described in dts, then this register is modified by the driver only when
pre_enable()callsenable_comms(). Here also, the value depends oncrtc_modeand therefclk_rateoften would not be equal to the values in "ti_sn_bridge_dsiclk_lut" (supported frequencies), and you would fallback to "001" register value.Rest of time, I guess it depends on reading the status from GPIO and changing the register.
Not "rest of the time", the reading of the strapping option from the GPIO always happens if an external refclk is detected. It's part of the chip after all. It will just sometimes be overwritten by the linux driver.
Quoted 1 line
Is the latter one your usecase?
My use case is that the GPIO setting is wrong on my board (it's really non-existent) and I'm relying on the linux driver to set the correct frequency.
HTH,
-michael
Hi Jayesh,
Quoted 48 lines
Quoted 41 lines
Quoted 17 lines
Quoted 17 lines
Quoted 16 lines
+ /*
+ * After EN is deasserted and an external clock is detected, the bridge
+ * will sample GPIO3:1 to determine its frequency. The driver will
+ * overwrite this setting. But this is racy. Thus we have to wait a
+ * couple of us. According to the datasheet the GPIO lines has to be
+ * stable at least 5 us (td5) but it seems that is not enough and the
+ * refclk frequency value is lost/overwritten by the bridge itself.
+ * Waiting for 20us seems to work.
+ */
+usleep_range(20, 30);Quoted 3 lines
Quoted 3 lines
It might be worth pointing at _where_ the driver overwrites this setting, or maybe at least pointing to something that makes it easy to find which exact bits you're talking about.
Yeah, Jayesh just pointed that out below. I'll add add it to the comment.
Quoted 3 lines
Quoted 1 line
This looks reasonable to me, though.
I think we are talking about SN_DPPLL_SRC_REG[3:1] bits?
Yes.
Quoted 1 line
What exact mismatch are you observing in register value?
The one set by the chip itself vs the one from the driver, see below.
Quoted 1 line
I am assuming that you have a clock at REFCLK pin. For that:
Yes, I'm using an external clock.
Quoted 3 lines
If refclk is described in devicetree node, then I see that the driver modifies it in every resume call based solely on the clock value in dts.
Quoted 6 lines
Exactly. But that is racy with what the chip itself is doing. I.e. if you don't have that
usleep()above, the chip will win the race and the refclk frequency setting will be set according to the external GPIOs (which is poorly described in the datasheet, btw), regardless what the linux driver is setting (because that I2C write happens too early).
Quoted 4 lines
I am a little confused here.
Won't it be opposite?
If we have this delay here, GPIO will stabilize and set the register accordingly?
What do you mean by GPIO? Maybe we are talking about the very same thing. From my understanding there are two "parties" involved here:
(1) the linux driver
(2) the bridge IC that comes out of reset when EN is asserted
And both are trying to write to the same setting.
From what I understand, is that (2) is running some kind of state machine or even firmware that will figure out if there is a refclk present. If so it will sample the GPIOs and set the refclk frequency setting accordingly. This happens autonomously after EN is asserted.
Now there is also (1) which will assert the EN signal and shortly after trying to write the refclk frequency setting.
With this patch we will delay the register write from (1) to a point after (2) updated its refclk setting. Thus (1) will win.
Quoted 4 lines
In the driver, I came across the case when we do not have refclk. (My platform does have a refclk, I am just removing the property from the dts node to check the affect of GPIO[3:1] in question because clock is not a required property for the bridge as per the bindings)
I'd expect that in this case the refclk is set according to the GPIO strapping. Correct?
Quoted 4 lines
In the
ti_sn65dsi86_probe(), before we readSN_DEVICE_ID_REGS, when we go toresume(), we do not doenable_comms()that callsti_sn_bridge_set_refclk_freq()to setSN_DPPLL_SRC_REG. I see that register read forSN_DEVICE_ID_REGSfails in that case.
Does it work with the property still in the device tree? I might try that on my board later.
Quoted 4 lines
Adding this delay fixes that issue. This made me think that we need the delay for GPIO to stabilize and set the refclk.
Is my understanding incorrect?
Unfortunately, the datasheet is really sparse on details here, but maybe the bridge needs some time after EN is assert to respond on the I2C bus in general. I'm basing my guesswork on the td5 timing with the vague description "GPIO[3:1] stable after EN assertion". I assume that somewhere during that time the chip will sample the GPIOs and do something with that setting (presumable setting its internal refclk frequency setting). FWIW there is also a td4 ("GPIO[3:1] stable before EN assertion"). Both td4 and td5, makes me believe that this is not some setting which is sampled (and hold) at reset, otherwise td5 wouldn't make much sense.
Quoted 29 lines
I am totally on board with your change especially after observing the above but is my understanding incorrect somewhere?
Warm Regards,
JayeshQuoted 23 lines
Quoted 9 lines
If refclk is not described in dts, then this register is modified by the driver only when
pre_enable()callsenable_comms(). Here also, the value depends oncrtc_modeand therefclk_rateoften would not be equal to the values in "ti_sn_bridge_dsiclk_lut" (supported frequencies), and you would fallback to "001" register value.Rest of time, I guess it depends on reading the status from GPIO and changing the register.
Not "rest of the time", the reading of the strapping option from the GPIO always happens if an external refclk is detected. It's part of the chip after all. It will just sometimes be overwritten by the linux driver.
Quoted 1 line
Is the latter one your usecase?
My use case is that the GPIO setting is wrong on my board (it's really non-existent) and I'm relying on the linux driver to set the correct frequency.
HTH,
-michael
Doug Anderson
reviewerHi,
Quoted 22 lines · Jayesh Choudhary
Quoted 11 lines
Quoted 4 lines
If refclk is described in devicetree node, then I see that the driver modifies it in every resume call based solely on the clock value in dts.
Exactly. But that is racy with what the chip itself is doing. I.e. if you don't have that
usleep()above, the chip will win the race and the refclk frequency setting will be set according to the external GPIOs (which is poorly described in the datasheet, btw), regardless what the linux driver is setting (because that I2C write happens too early).I am a little confused here.
Won't it be opposite?
If we have this delay here, GPIO will stabilize and set the register accordingly?In the driver, I came across the case when we do not have refclk. (My platform does have a refclk, I am just removing the property from the dts node to check the affect of GPIO[3:1] in question because clock is not a required property for the bridge as per the bindings)
Quoted 7 lines
In the
ti_sn65dsi86_probe(), before we readSN_DEVICE_ID_REGS, when we go toresume(), we do not doenable_comms()that callsti_sn_bridge_set_refclk_freq()to setSN_DPPLL_SRC_REG. I see that register read forSN_DEVICE_ID_REGSfails in that case.Adding this delay fixes that issue. This made me think that we need the delay for GPIO to stabilize and set the refclk.
FWIW, it's been on my plate for a while to delete the "no refclk" support. The chip is really hard to use properly without a refclk and I'm not at all convinced that the current code actually works properly without a refclk. I'm not aware of any current hardware working this way. I know we had some very early prototype hardware ages ago that tried it and we got it limping along at one point, but the driver looked _very_ different then. I believe someone on the lists once mentioned trying to do something without a refclk and it didn't work and I strongly encouraged them to add a refclk.
-Doug
Doug Anderson
reviewerHi,
Quoted 34 lines · Doug Anderson
Hi,
Quoted 22 lines · Jayesh Choudhary
Quoted 11 lines
Quoted 4 lines
If refclk is described in devicetree node, then I see that the driver modifies it in every resume call based solely on the clock value in dts.
Exactly. But that is racy with what the chip itself is doing. I.e. if you don't have that
usleep()above, the chip will win the race and the refclk frequency setting will be set according to the external GPIOs (which is poorly described in the datasheet, btw), regardless what the linux driver is setting (because that I2C write happens too early).I am a little confused here.
Won't it be opposite?
If we have this delay here, GPIO will stabilize and set the register accordingly?In the driver, I came across the case when we do not have refclk. (My platform does have a refclk, I am just removing the property from the dts node to check the affect of GPIO[3:1] in question because clock is not a required property for the bridge as per the bindings)
Quoted 7 lines
In the
ti_sn65dsi86_probe(), before we readSN_DEVICE_ID_REGS, when we go toresume(), we do not doenable_comms()that callsti_sn_bridge_set_refclk_freq()to setSN_DPPLL_SRC_REG. I see that register read forSN_DEVICE_ID_REGSfails in that case.Adding this delay fixes that issue. This made me think that we need the delay for GPIO to stabilize and set the refclk.
Quoted 9 lines
FWIW, it's been on my plate for a while to delete the "no refclk" support. The chip is really hard to use properly without a refclk and I'm not at all convinced that the current code actually works properly without a refclk. I'm not aware of any current hardware working this way. I know we had some very early prototype hardware ages ago that tried it and we got it limping along at one point, but the driver looked _very_ different then. I believe someone on the lists once mentioned trying to do something without a refclk and it didn't work and I strongly encouraged them to add a refclk.
Actually, I may have to eat my words here. I double-checked the dts and I see there's at least two mainline users ("meson-g12b-bananapi-cm4-mnt-reform2.dts" and "/imx8mq-mnt-reform2.dts") that don't seem to be specifying a refclk to ti,sn65dsi86.
Neil / Lucas: is that correct? ...and it actually works?
-Doug
Am Donnerstag, dem 12.06.2025 um 15:31 -0700 schrieb Doug Anderson:
Quoted 47 lines
Hi,
Quoted 34 lines · Doug Anderson
Hi,
Quoted 22 lines · Jayesh Choudhary
Quoted 11 lines
Quoted 4 lines
If refclk is described in devicetree node, then I see that the driver modifies it in every resume call based solely on the clock value in dts.
Exactly. But that is racy with what the chip itself is doing. I.e. if you don't have that
usleep()above, the chip will win the race and the refclk frequency setting will be set according to the external GPIOs (which is poorly described in the datasheet, btw), regardless what the linux driver is setting (because that I2C write happens too early).I am a little confused here.
Won't it be opposite?
If we have this delay here, GPIO will stabilize and set the register accordingly?In the driver, I came across the case when we do not have refclk. (My platform does have a refclk, I am just removing the property from the dts node to check the affect of GPIO[3:1] in question because clock is not a required property for the bridge as per the bindings)
Quoted 7 lines
In the
ti_sn65dsi86_probe(), before we readSN_DEVICE_ID_REGS, when we go toresume(), we do not doenable_comms()that callsti_sn_bridge_set_refclk_freq()to setSN_DPPLL_SRC_REG. I see that register read forSN_DEVICE_ID_REGSfails in that case.Adding this delay fixes that issue. This made me think that we need the delay for GPIO to stabilize and set the refclk.
Quoted 9 lines
FWIW, it's been on my plate for a while to delete the "no refclk" support. The chip is really hard to use properly without a refclk and I'm not at all convinced that the current code actually works properly without a refclk. I'm not aware of any current hardware working this way. I know we had some very early prototype hardware ages ago that tried it and we got it limping along at one point, but the driver looked _very_ different then. I believe someone on the lists once mentioned trying to do something without a refclk and it didn't work and I strongly encouraged them to add a refclk.
Quoted 8 lines
Actually, I may have to eat my words here. I double-checked the dts and I see there's at least two mainline users ("
meson-g12b-bananapi-cm4-mnt-reform2.dts" and "/imx8mq-mnt-reform2.dts") that don't seem to be specifying arefclktoti,sn65dsi86.Neil / Lucas: is that correct? ...and it actually works?
The description is correct, the refclock is not connected on the reform baseboard.
It sort of works, as-in AUX channel is not working before the display link is up to provide a reference clock and I guess that also means HPD is broken. On the reform the connected panel is described as a simple panel with a fixed mode, not using the EDID from panel.
Regards,
Lucas