Register a listener for the cros-usbpd-notifier, and update port state
when a notification comes in.
Signed-off-by: Prashant Malani <[email protected]>
---
drivers/platform/chrome/cros_ec_typec.c | 25 +++++++++++++++++++++++++
1 file changed, 25 insertions(+)
diff --git a/drivers/platform/chrome/cros_ec_typec.c b/drivers/platform/chrome/cros_ec_typec.c
index 874269c070739..cf7c2652a1d6d 100644
--- a/drivers/platform/chrome/cros_ec_typec.c
+++ b/drivers/platform/chrome/cros_ec_typec.c
@@ -11,6 +11,7 @@
#include <linux/of.h>
#include <linux/platform_data/cros_ec_commands.h>
#include <linux/platform_data/cros_ec_proto.h>
+#include <linux/platform_data/cros_usbpd_notify.h>
#include <linux/platform_device.h>
#include <linux/usb/typec.h>
@@ -26,6 +27,7 @@ struct cros_typec_data {
struct typec_port *ports[EC_USB_PD_MAX_PORTS];
/* Initial capabilities for each port. */
struct typec_capability *caps[EC_USB_PD_MAX_PORTS];
+ struct notifier_block nb;
};
static int cros_typec_parse_port_props(struct typec_capability *cap,
@@ -272,6 +274,22 @@ static int cros_typec_get_cmd_version(struct cros_typec_data *typec)
return 0;
}
+static int cros_ec_typec_event(struct notifier_block *nb,
+ unsigned long host_event, void *_notify)
+{
+ struct cros_typec_data *typec = container_of(nb, struct cros_typec_data,
+ nb);
+ int ret, i;
+
+ for (i = 0; i < typec->num_ports; i++) {
+ ret = cros_typec_port_update(typec, i);
+ if (ret < 0)
+ dev_warn(typec->dev, "Update failed for port:%d\n", i);
+ }
+
+ return NOTIFY_OK;
+}
+
#ifdef CONFIG_ACPI
static const struct acpi_device_id cros_typec_acpi_id[] = {
{ "GOOG0014", 0 },
@@ -332,6 +350,13 @@ static int cros_typec_probe(struct platform_device *pdev)
goto unregister_ports;
}
+ typec->nb.notifier_call = cros_ec_typec_event;
+ ret = cros_usbpd_register_notify(&typec->nb);
+ if (ret < 0) {
+ dev_err(dev, "Failed to register notifier\n");
+ goto unregister_ports;
+ }
+
return 0;
unregister_ports:
--
2.26.0.292.g33ef6b2f38-goog
Hi Prashant,
Thank you for the patch.
On 7/4/20 3:09, Prashant Malani wrote:
> Register a listener for the cros-usbpd-notifier, and update port state
> when a notification comes in.
>
> Signed-off-by: Prashant Malani <[email protected]>
> ---
> drivers/platform/chrome/cros_ec_typec.c | 25 +++++++++++++++++++++++++
> 1 file changed, 25 insertions(+)
>
> diff --git a/drivers/platform/chrome/cros_ec_typec.c b/drivers/platform/chrome/cros_ec_typec.c
> index 874269c070739..cf7c2652a1d6d 100644
> --- a/drivers/platform/chrome/cros_ec_typec.c
> +++ b/drivers/platform/chrome/cros_ec_typec.c
> @@ -11,6 +11,7 @@
> #include <linux/of.h>
> #include <linux/platform_data/cros_ec_commands.h>
> #include <linux/platform_data/cros_ec_proto.h>
> +#include <linux/platform_data/cros_usbpd_notify.h>
I think you need to add a kconfig dependency/selection in order to don't have
build problems.
> #include <linux/platform_device.h>
> #include <linux/usb/typec.h>
>
> @@ -26,6 +27,7 @@ struct cros_typec_data {
> struct typec_port *ports[EC_USB_PD_MAX_PORTS];
> /* Initial capabilities for each port. */
> struct typec_capability *caps[EC_USB_PD_MAX_PORTS];
> + struct notifier_block nb;
> };
>
> static int cros_typec_parse_port_props(struct typec_capability *cap,
> @@ -272,6 +274,22 @@ static int cros_typec_get_cmd_version(struct cros_typec_data *typec)
> return 0;
> }
>
> +static int cros_ec_typec_event(struct notifier_block *nb,
> + unsigned long host_event, void *_notify)
> +{
> + struct cros_typec_data *typec = container_of(nb, struct cros_typec_data,
> + nb);
> + int ret, i;
> +
> + for (i = 0; i < typec->num_ports; i++) {
> + ret = cros_typec_port_update(typec, i);
> + if (ret < 0)
> + dev_warn(typec->dev, "Update failed for port:%d\n", i);
nit: space between : and %d
> + }
> +
> + return NOTIFY_OK;
> +}
> +
> #ifdef CONFIG_ACPI
> static const struct acpi_device_id cros_typec_acpi_id[] = {
> { "GOOG0014", 0 },
> @@ -332,6 +350,13 @@ static int cros_typec_probe(struct platform_device *pdev)
> goto unregister_ports;
> }
>
> + typec->nb.notifier_call = cros_ec_typec_event;
> + ret = cros_usbpd_register_notify(&typec->nb);
> + if (ret < 0) {
> + dev_err(dev, "Failed to register notifier\n");
Currently cros_usbpd_register_notfity calls blocking_notifier_chain_register
that always return zero. Is fine to check the error but the print is unneded. If
probe fails will report the error.
> + goto unregister_ports;
> + }
> +
> return 0;
>
> unregister_ports:
>
Hi Enric,
Thanks for the reviews, as always. Kindly see inline:
On Thu, Apr 09, 2020 at 11:01:42PM +0200, Enric Balletbo i Serra wrote:
> Hi Prashant,
>
> Thank you for the patch.
>
> On 7/4/20 3:09, Prashant Malani wrote:
> > Register a listener for the cros-usbpd-notifier, and update port state
> > when a notification comes in.
> >
> > Signed-off-by: Prashant Malani <[email protected]>
> > ---
> > drivers/platform/chrome/cros_ec_typec.c | 25 +++++++++++++++++++++++++
> > 1 file changed, 25 insertions(+)
> >
> > diff --git a/drivers/platform/chrome/cros_ec_typec.c b/drivers/platform/chrome/cros_ec_typec.c
> > index 874269c070739..cf7c2652a1d6d 100644
> > --- a/drivers/platform/chrome/cros_ec_typec.c
> > +++ b/drivers/platform/chrome/cros_ec_typec.c
> > @@ -11,6 +11,7 @@
> > #include <linux/of.h>
> > #include <linux/platform_data/cros_ec_commands.h>
> > #include <linux/platform_data/cros_ec_proto.h>
> > +#include <linux/platform_data/cros_usbpd_notify.h>
>
> I think you need to add a kconfig dependency/selection in order to don't have
> build problems.
Thanks, will make the change.
>
> > #include <linux/platform_device.h>
> > #include <linux/usb/typec.h>
> >
> > @@ -26,6 +27,7 @@ struct cros_typec_data {
> > struct typec_port *ports[EC_USB_PD_MAX_PORTS];
> > /* Initial capabilities for each port. */
> > struct typec_capability *caps[EC_USB_PD_MAX_PORTS];
> > + struct notifier_block nb;
> > };
> >
> > static int cros_typec_parse_port_props(struct typec_capability *cap,
> > @@ -272,6 +274,22 @@ static int cros_typec_get_cmd_version(struct cros_typec_data *typec)
> > return 0;
> > }
> >
> > +static int cros_ec_typec_event(struct notifier_block *nb,
> > + unsigned long host_event, void *_notify)
> > +{
> > + struct cros_typec_data *typec = container_of(nb, struct cros_typec_data,
> > + nb);
> > + int ret, i;
> > +
> > + for (i = 0; i < typec->num_ports; i++) {
> > + ret = cros_typec_port_update(typec, i);
> > + if (ret < 0)
> > + dev_warn(typec->dev, "Update failed for port:%d\n", i);
>
> nit: space between : and %d
>
Done.
> > + }
> > +
> > + return NOTIFY_OK;
> > +}
> > +
> > #ifdef CONFIG_ACPI
> > static const struct acpi_device_id cros_typec_acpi_id[] = {
> > { "GOOG0014", 0 },
> > @@ -332,6 +350,13 @@ static int cros_typec_probe(struct platform_device *pdev)
> > goto unregister_ports;
> > }
> >
> > + typec->nb.notifier_call = cros_ec_typec_event;
> > + ret = cros_usbpd_register_notify(&typec->nb);
> > + if (ret < 0) {
> > + dev_err(dev, "Failed to register notifier\n");
>
> Currently cros_usbpd_register_notfity calls blocking_notifier_chain_register
> that always return zero. Is fine to check the error but the print is unneded. If
> probe fails will report the error.
>
Done.
> > + goto unregister_ports;
> > + }
> > +
> > return 0;
> >
> > unregister_ports:
> >
Best regards,
-Prashant