diff mbox series

[v2,2/2] usb: typec: qcom-pmic-typec: register drm_bridge

Message ID 20230709201309.274306-3-dmitry.baryshkov@linaro.org
State Superseded
Headers show
Series usb: typec: qcom-pmic-typec: enable DP support | expand

Commit Message

Dmitry Baryshkov July 9, 2023, 8:13 p.m. UTC
The current approach to handling DP on bridge-enabled platforms requires
a chain of DP bridges up to the USB-C connector. Register a last DRM
bridge for such chain.

Signed-off-by: Dmitry Baryshkov <dmitry.baryshkov@linaro.org>
---
 drivers/usb/typec/tcpm/Kconfig                |  1 +
 drivers/usb/typec/tcpm/qcom/qcom_pmic_typec.c | 39 +++++++++++++++++++
 2 files changed, 40 insertions(+)

Comments

Bryan O'Donoghue July 10, 2023, 10:02 a.m. UTC | #1
On 09/07/2023 21:13, Dmitry Baryshkov wrote:
> The current approach to handling DP on bridge-enabled platforms requires
> a chain of DP bridges up to the USB-C connector. Register a last DRM
> bridge for such chain.
> 
> Signed-off-by: Dmitry Baryshkov <dmitry.baryshkov@linaro.org>
> ---
>   drivers/usb/typec/tcpm/Kconfig                |  1 +
>   drivers/usb/typec/tcpm/qcom/qcom_pmic_typec.c | 39 +++++++++++++++++++
>   2 files changed, 40 insertions(+)
> 
> diff --git a/drivers/usb/typec/tcpm/Kconfig b/drivers/usb/typec/tcpm/Kconfig
> index 5d393f520fc2..0b2993fef564 100644
> --- a/drivers/usb/typec/tcpm/Kconfig
> +++ b/drivers/usb/typec/tcpm/Kconfig
> @@ -79,6 +79,7 @@ config TYPEC_WCOVE
>   config TYPEC_QCOM_PMIC
>   	tristate "Qualcomm PMIC USB Type-C Port Controller Manager driver"
>   	depends on ARCH_QCOM || COMPILE_TEST
> +	depends on DRM || DRM=n
>   	help
>   	  A Type-C port and Power Delivery driver which aggregates two
>   	  discrete pieces of silicon in the PM8150b PMIC block: the
> diff --git a/drivers/usb/typec/tcpm/qcom/qcom_pmic_typec.c b/drivers/usb/typec/tcpm/qcom/qcom_pmic_typec.c
> index a905160dd860..0722fb8d75c4 100644
> --- a/drivers/usb/typec/tcpm/qcom/qcom_pmic_typec.c
> +++ b/drivers/usb/typec/tcpm/qcom/qcom_pmic_typec.c
> @@ -17,6 +17,9 @@
>   #include <linux/usb/role.h>
>   #include <linux/usb/tcpm.h>
>   #include <linux/usb/typec_mux.h>
> +
> +#include <drm/drm_bridge.h>
> +
>   #include "qcom_pmic_typec_pdphy.h"
>   #include "qcom_pmic_typec_port.h"
>   
> @@ -33,6 +36,9 @@ struct pmic_typec {
>   	struct pmic_typec_port	*pmic_typec_port;
>   	bool			vbus_enabled;
>   	struct mutex		lock;		/* VBUS state serialization */
> +#ifdef CONFIG_DRM
> +	struct drm_bridge	bridge;
> +#endif

IMO there's no reason to ifdef the structure. Its up to you if you want 
to change it nor not, I have no strong feelings about it.

Acked-by: Bryan O'Donoghue <bryan.odonoghue@linaro.org>

---
bod
Konrad Dybcio July 10, 2023, 10:04 a.m. UTC | #2
On 10.07.2023 12:02, Bryan O'Donoghue wrote:
> On 09/07/2023 21:13, Dmitry Baryshkov wrote:
>> The current approach to handling DP on bridge-enabled platforms requires
>> a chain of DP bridges up to the USB-C connector. Register a last DRM
>> bridge for such chain.
>>
>> Signed-off-by: Dmitry Baryshkov <dmitry.baryshkov@linaro.org>
>> ---
>>   drivers/usb/typec/tcpm/Kconfig                |  1 +
>>   drivers/usb/typec/tcpm/qcom/qcom_pmic_typec.c | 39 +++++++++++++++++++
>>   2 files changed, 40 insertions(+)
>>
>> diff --git a/drivers/usb/typec/tcpm/Kconfig b/drivers/usb/typec/tcpm/Kconfig
>> index 5d393f520fc2..0b2993fef564 100644
>> --- a/drivers/usb/typec/tcpm/Kconfig
>> +++ b/drivers/usb/typec/tcpm/Kconfig
>> @@ -79,6 +79,7 @@ config TYPEC_WCOVE
>>   config TYPEC_QCOM_PMIC
>>       tristate "Qualcomm PMIC USB Type-C Port Controller Manager driver"
>>       depends on ARCH_QCOM || COMPILE_TEST
>> +    depends on DRM || DRM=n
>>       help
>>         A Type-C port and Power Delivery driver which aggregates two
>>         discrete pieces of silicon in the PM8150b PMIC block: the
>> diff --git a/drivers/usb/typec/tcpm/qcom/qcom_pmic_typec.c b/drivers/usb/typec/tcpm/qcom/qcom_pmic_typec.c
>> index a905160dd860..0722fb8d75c4 100644
>> --- a/drivers/usb/typec/tcpm/qcom/qcom_pmic_typec.c
>> +++ b/drivers/usb/typec/tcpm/qcom/qcom_pmic_typec.c
>> @@ -17,6 +17,9 @@
>>   #include <linux/usb/role.h>
>>   #include <linux/usb/tcpm.h>
>>   #include <linux/usb/typec_mux.h>
>> +
>> +#include <drm/drm_bridge.h>
>> +
>>   #include "qcom_pmic_typec_pdphy.h"
>>   #include "qcom_pmic_typec_port.h"
>>   @@ -33,6 +36,9 @@ struct pmic_typec {
>>       struct pmic_typec_port    *pmic_typec_port;
>>       bool            vbus_enabled;
>>       struct mutex        lock;        /* VBUS state serialization */
>> +#ifdef CONFIG_DRM
>> +    struct drm_bridge    bridge;
>> +#endif
> 
> IMO there's no reason to ifdef the structure. Its up to you if you want to change it nor not, I have no strong feelings about it.
+1, there's no ifdefs in the drm_bridge.h header that would make this not compile

Konrad
> 
> Acked-by: Bryan O'Donoghue <bryan.odonoghue@linaro.org>
> 
> ---
> bod
Dmitry Baryshkov July 10, 2023, 10:57 a.m. UTC | #3
On Mon, 10 Jul 2023 at 13:04, Konrad Dybcio <konrad.dybcio@linaro.org> wrote:
>
> On 10.07.2023 12:02, Bryan O'Donoghue wrote:
> > On 09/07/2023 21:13, Dmitry Baryshkov wrote:
> >> The current approach to handling DP on bridge-enabled platforms requires
> >> a chain of DP bridges up to the USB-C connector. Register a last DRM
> >> bridge for such chain.
> >>
> >> Signed-off-by: Dmitry Baryshkov <dmitry.baryshkov@linaro.org>
> >> ---
> >>   drivers/usb/typec/tcpm/Kconfig                |  1 +
> >>   drivers/usb/typec/tcpm/qcom/qcom_pmic_typec.c | 39 +++++++++++++++++++
> >>   2 files changed, 40 insertions(+)
> >>
> >> diff --git a/drivers/usb/typec/tcpm/Kconfig b/drivers/usb/typec/tcpm/Kconfig
> >> index 5d393f520fc2..0b2993fef564 100644
> >> --- a/drivers/usb/typec/tcpm/Kconfig
> >> +++ b/drivers/usb/typec/tcpm/Kconfig
> >> @@ -79,6 +79,7 @@ config TYPEC_WCOVE
> >>   config TYPEC_QCOM_PMIC
> >>       tristate "Qualcomm PMIC USB Type-C Port Controller Manager driver"
> >>       depends on ARCH_QCOM || COMPILE_TEST
> >> +    depends on DRM || DRM=n
> >>       help
> >>         A Type-C port and Power Delivery driver which aggregates two
> >>         discrete pieces of silicon in the PM8150b PMIC block: the
> >> diff --git a/drivers/usb/typec/tcpm/qcom/qcom_pmic_typec.c b/drivers/usb/typec/tcpm/qcom/qcom_pmic_typec.c
> >> index a905160dd860..0722fb8d75c4 100644
> >> --- a/drivers/usb/typec/tcpm/qcom/qcom_pmic_typec.c
> >> +++ b/drivers/usb/typec/tcpm/qcom/qcom_pmic_typec.c
> >> @@ -17,6 +17,9 @@
> >>   #include <linux/usb/role.h>
> >>   #include <linux/usb/tcpm.h>
> >>   #include <linux/usb/typec_mux.h>
> >> +
> >> +#include <drm/drm_bridge.h>
> >> +
> >>   #include "qcom_pmic_typec_pdphy.h"
> >>   #include "qcom_pmic_typec_port.h"
> >>   @@ -33,6 +36,9 @@ struct pmic_typec {
> >>       struct pmic_typec_port    *pmic_typec_port;
> >>       bool            vbus_enabled;
> >>       struct mutex        lock;        /* VBUS state serialization */
> >> +#ifdef CONFIG_DRM
> >> +    struct drm_bridge    bridge;
> >> +#endif
> >
> > IMO there's no reason to ifdef the structure. Its up to you if you want to change it nor not, I have no strong feelings about it.
> +1, there's no ifdefs in the drm_bridge.h header that would make this not compile

It is quite typical to idef unused structure fields. For example
OF-related fields are frequently ifdef'ed.
Let's see what the maintainers will say.

>
> Konrad
> >
> > Acked-by: Bryan O'Donoghue <bryan.odonoghue@linaro.org>
> >
> > ---
> > bod
Greg KH July 10, 2023, 1:31 p.m. UTC | #4
On Mon, Jul 10, 2023 at 01:57:06PM +0300, Dmitry Baryshkov wrote:
> On Mon, 10 Jul 2023 at 13:04, Konrad Dybcio <konrad.dybcio@linaro.org> wrote:
> >
> > On 10.07.2023 12:02, Bryan O'Donoghue wrote:
> > > On 09/07/2023 21:13, Dmitry Baryshkov wrote:
> > >> The current approach to handling DP on bridge-enabled platforms requires
> > >> a chain of DP bridges up to the USB-C connector. Register a last DRM
> > >> bridge for such chain.
> > >>
> > >> Signed-off-by: Dmitry Baryshkov <dmitry.baryshkov@linaro.org>
> > >> ---
> > >>   drivers/usb/typec/tcpm/Kconfig                |  1 +
> > >>   drivers/usb/typec/tcpm/qcom/qcom_pmic_typec.c | 39 +++++++++++++++++++
> > >>   2 files changed, 40 insertions(+)
> > >>
> > >> diff --git a/drivers/usb/typec/tcpm/Kconfig b/drivers/usb/typec/tcpm/Kconfig
> > >> index 5d393f520fc2..0b2993fef564 100644
> > >> --- a/drivers/usb/typec/tcpm/Kconfig
> > >> +++ b/drivers/usb/typec/tcpm/Kconfig
> > >> @@ -79,6 +79,7 @@ config TYPEC_WCOVE
> > >>   config TYPEC_QCOM_PMIC
> > >>       tristate "Qualcomm PMIC USB Type-C Port Controller Manager driver"
> > >>       depends on ARCH_QCOM || COMPILE_TEST
> > >> +    depends on DRM || DRM=n
> > >>       help
> > >>         A Type-C port and Power Delivery driver which aggregates two
> > >>         discrete pieces of silicon in the PM8150b PMIC block: the
> > >> diff --git a/drivers/usb/typec/tcpm/qcom/qcom_pmic_typec.c b/drivers/usb/typec/tcpm/qcom/qcom_pmic_typec.c
> > >> index a905160dd860..0722fb8d75c4 100644
> > >> --- a/drivers/usb/typec/tcpm/qcom/qcom_pmic_typec.c
> > >> +++ b/drivers/usb/typec/tcpm/qcom/qcom_pmic_typec.c
> > >> @@ -17,6 +17,9 @@
> > >>   #include <linux/usb/role.h>
> > >>   #include <linux/usb/tcpm.h>
> > >>   #include <linux/usb/typec_mux.h>
> > >> +
> > >> +#include <drm/drm_bridge.h>
> > >> +
> > >>   #include "qcom_pmic_typec_pdphy.h"
> > >>   #include "qcom_pmic_typec_port.h"
> > >>   @@ -33,6 +36,9 @@ struct pmic_typec {
> > >>       struct pmic_typec_port    *pmic_typec_port;
> > >>       bool            vbus_enabled;
> > >>       struct mutex        lock;        /* VBUS state serialization */
> > >> +#ifdef CONFIG_DRM
> > >> +    struct drm_bridge    bridge;
> > >> +#endif
> > >
> > > IMO there's no reason to ifdef the structure. Its up to you if you want to change it nor not, I have no strong feelings about it.
> > +1, there's no ifdefs in the drm_bridge.h header that would make this not compile
> 
> It is quite typical to idef unused structure fields. For example
> OF-related fields are frequently ifdef'ed.
> Let's see what the maintainers will say.

Please do not put #ifdef in .c files.

If it's not needed, please remove.

thanks,

greg k-h
diff mbox series

Patch

diff --git a/drivers/usb/typec/tcpm/Kconfig b/drivers/usb/typec/tcpm/Kconfig
index 5d393f520fc2..0b2993fef564 100644
--- a/drivers/usb/typec/tcpm/Kconfig
+++ b/drivers/usb/typec/tcpm/Kconfig
@@ -79,6 +79,7 @@  config TYPEC_WCOVE
 config TYPEC_QCOM_PMIC
 	tristate "Qualcomm PMIC USB Type-C Port Controller Manager driver"
 	depends on ARCH_QCOM || COMPILE_TEST
+	depends on DRM || DRM=n
 	help
 	  A Type-C port and Power Delivery driver which aggregates two
 	  discrete pieces of silicon in the PM8150b PMIC block: the
diff --git a/drivers/usb/typec/tcpm/qcom/qcom_pmic_typec.c b/drivers/usb/typec/tcpm/qcom/qcom_pmic_typec.c
index a905160dd860..0722fb8d75c4 100644
--- a/drivers/usb/typec/tcpm/qcom/qcom_pmic_typec.c
+++ b/drivers/usb/typec/tcpm/qcom/qcom_pmic_typec.c
@@ -17,6 +17,9 @@ 
 #include <linux/usb/role.h>
 #include <linux/usb/tcpm.h>
 #include <linux/usb/typec_mux.h>
+
+#include <drm/drm_bridge.h>
+
 #include "qcom_pmic_typec_pdphy.h"
 #include "qcom_pmic_typec_port.h"
 
@@ -33,6 +36,9 @@  struct pmic_typec {
 	struct pmic_typec_port	*pmic_typec_port;
 	bool			vbus_enabled;
 	struct mutex		lock;		/* VBUS state serialization */
+#ifdef CONFIG_DRM
+	struct drm_bridge	bridge;
+#endif
 };
 
 #define tcpc_to_tcpm(_tcpc_) container_of(_tcpc_, struct pmic_typec, tcpc)
@@ -146,6 +152,35 @@  static int qcom_pmic_typec_init(struct tcpc_dev *tcpc)
 	return 0;
 }
 
+#ifdef CONFIG_DRM
+static int qcom_pmic_typec_attach(struct drm_bridge *bridge,
+				     enum drm_bridge_attach_flags flags)
+{
+	return flags & DRM_BRIDGE_ATTACH_NO_CONNECTOR ? 0 : -EINVAL;
+}
+
+static const struct drm_bridge_funcs qcom_pmic_typec_bridge_funcs = {
+	.attach = qcom_pmic_typec_attach,
+};
+
+static int qcom_pmic_typec_init_drm(struct pmic_typec *tcpm)
+{
+	tcpm->bridge.funcs = &qcom_pmic_typec_bridge_funcs;
+#if CONFIG_OF
+	tcpm->bridge.of_node = of_get_child_by_name(tcpm->dev->of_node, "connector");
+#endif
+	tcpm->bridge.ops = DRM_BRIDGE_OP_HPD;
+	tcpm->bridge.type = DRM_MODE_CONNECTOR_USB;
+
+	return devm_drm_bridge_add(tcpm->dev, &tcpm->bridge);
+}
+#else
+static int qcom_pmic_typec_init_drm(struct pmic_typec *tcpm)
+{
+	return 0;
+}
+#endif
+
 static int qcom_pmic_typec_probe(struct platform_device *pdev)
 {
 	struct pmic_typec *tcpm;
@@ -208,6 +243,10 @@  static int qcom_pmic_typec_probe(struct platform_device *pdev)
 	mutex_init(&tcpm->lock);
 	platform_set_drvdata(pdev, tcpm);
 
+	ret = qcom_pmic_typec_init_drm(tcpm);
+	if (ret)
+		return ret;
+
 	tcpm->tcpc.fwnode = device_get_named_child_node(tcpm->dev, "connector");
 	if (IS_ERR(tcpm->tcpc.fwnode))
 		return PTR_ERR(tcpm->tcpc.fwnode);