Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1704846
| From | Guenter Roeck <linux@roeck-us.net> |
|---|---|
| Newsgroups | linux.kernel |
| Subject | Re: [PATCH 02/18] staging: typec: tcpm: Add extcon helper functions for USB2 current limit detect |
| Date | 2017-08-06 16:10 +0200 |
| Message-ID | <ubupI-3f0-5@gated-at.bofh.it> (permalink) |
| References | <ubt0C-2al-7@gated-at.bofh.it> <ubtai-2e3-19@gated-at.bofh.it> |
| Organization | linux.* mail to news gateway |
On 08/06/2017 05:35 AM, Hans de Goede wrote:
> Some type-c port-controllers, such as the fusb302 port-controller, rely
> on an external device doing USB2 charger-type detection.
>
> Existing PMIC (and charger) drivers already use extcon to communicate the
> detected charger-type from the PMIC (extcon) driver to the charger driver.
>
> Rather then inventing a new API for USB2 charger-type detection
> specifically for use with the tcpm code, lets simply re-use the existing
> support. This will also allow re-using existing PMIC extcon drivers such
> as the axp288 and Intel Whiskey Cove drivers as is on devices where these
> are combined with a fusb302 (or in the future another port-controller
> which relies on external USB2 charger-type detection).
>
> This commit adds a helper function which tcpc drivers can use to easily
> hook into existing PMIC extcon drivers for USB2 charger-type detection:
>
> int tcpm_get_usb2_current_limit_extcon(struct tcpc_dev *tcpc);
>
> Signed-off-by: Hans de Goede <hdegoede@redhat.com>
> ---
> drivers/staging/typec/tcpm.c | 40 ++++++++++++++++++++++++++++++++++++++++
> drivers/staging/typec/tcpm.h | 6 ++++++
> 2 files changed, 46 insertions(+)
>
> diff --git a/drivers/staging/typec/tcpm.c b/drivers/staging/typec/tcpm.c
> index 9f5adace4309..06bb0e640bcf 100644
> --- a/drivers/staging/typec/tcpm.c
> +++ b/drivers/staging/typec/tcpm.c
> @@ -16,6 +16,7 @@
>
> #include <linux/completion.h>
> #include <linux/debugfs.h>
> +#include <linux/delay.h>
> #include <linux/device.h>
> #include <linux/kernel.h>
> #include <linux/module.h>
> @@ -3532,6 +3533,45 @@ void tcpm_unregister_port(struct tcpm_port *port)
> }
> EXPORT_SYMBOL_GPL(tcpm_unregister_port);
>
> +/* Generic (helper) implementations for some tcpc_dev callbacks */
> +int tcpm_get_usb2_current_limit_extcon(struct tcpc_dev *tcpc)
> +{
> + struct extcon_dev *extcon = tcpc->usb2_extcon;
> + int current_limit = 0;
> + unsigned long timeout;
> +
> + if (!extcon)
> + return 0;
> +
> + /*
> + * USB2 Charger detection may still be in progress when we get here,
> + * this can take upto 600ms, wait 800ms max.
> + */
> + timeout = jiffies + msecs_to_jiffies(800);
> + do {
> + if (extcon_get_state(extcon, EXTCON_CHG_USB_SDP) == 1) {
> + current_limit = 500;
> + break;
> + }
> +
> + if (extcon_get_state(extcon, EXTCON_CHG_USB_CDP) == 1 ||
> + extcon_get_state(extcon, EXTCON_CHG_USB_ACA) == 1) {
> + current_limit = 1500;
> + break;
> + }
> +
> + if (extcon_get_state(extcon, EXTCON_CHG_USB_DCP) == 1) {
> + current_limit = 2000;
> + break;
> + }
> +
> + msleep(50);
> + } while (time_before(jiffies, timeout));
> +
> + return current_limit;
> +}
> +EXPORT_SYMBOL_GPL(tcpm_get_usb2_current_limit_extcon);
> +
Not really sure about this one. Should it be part of low level drivers ?
Guenter
> MODULE_AUTHOR("Guenter Roeck <groeck@chromium.org>");
> MODULE_DESCRIPTION("USB Type-C Port Manager");
> MODULE_LICENSE("GPL");
> diff --git a/drivers/staging/typec/tcpm.h b/drivers/staging/typec/tcpm.h
> index 01b7d89379a3..35e8c1e7dba0 100644
> --- a/drivers/staging/typec/tcpm.h
> +++ b/drivers/staging/typec/tcpm.h
> @@ -16,6 +16,7 @@
> #define __LINUX_USB_TCPM_H
>
> #include <linux/bitops.h>
> +#include <linux/extcon.h>
> #include <linux/usb/typec.h>
> #include "pd.h"
>
> @@ -126,6 +127,8 @@ struct tcpc_dev {
> int (*pd_transmit)(struct tcpc_dev *dev, enum tcpm_transmit_type type,
> const struct pd_message *msg);
> struct tcpc_mux_dev *mux;
> + /* Used by tcpm_get_usb2_current_limit_extcon helpers */
> + struct extcon_dev *usb2_extcon;
> };
>
> struct tcpm_port;
> @@ -151,4 +154,7 @@ void tcpm_pd_transmit_complete(struct tcpm_port *port,
> void tcpm_pd_hard_reset(struct tcpm_port *port);
> void tcpm_tcpc_reset(struct tcpm_port *port);
>
> +/* Generic (helper) implementations for some tcpc_dev callbacks */
> +int tcpm_get_usb2_current_limit_extcon(struct tcpc_dev *tcpc);
> +
> #endif /* __LINUX_USB_TCPM_H */
>
Back to linux.kernel | Previous | Next — Previous in thread | Find similar | Unroll thread
[PATCH 00/18] Hookup typec power-negotation to the PMIC and charger Hans de Goede <hdegoede@redhat.com> - 2017-08-06 14:40 +0200
[PATCH 12/18] power: supply: Add power_supply_set_input_current_limit_from_supplier helper Hans de Goede <hdegoede@redhat.com> - 2017-08-06 14:40 +0200
[PATCH 13/18] power: supply: bq24190_charger: Export 5V boost converter as regulator Hans de Goede <hdegoede@redhat.com> - 2017-08-06 14:40 +0200
Re: [PATCH 13/18] power: supply: bq24190_charger: Export 5V boost converter as regulator Tony Lindgren <tony@atomide.com> - 2017-08-08 06:20 +0200
Re: [PATCH 13/18] power: supply: bq24190_charger: Export 5V boost converter as regulator Liam Breck <liam@networkimprov.net> - 2017-08-08 10:50 +0200
Re: [PATCH 13/18] power: supply: bq24190_charger: Export 5V boost converter as regulator Hans de Goede <hdegoede@redhat.com> - 2017-08-08 11:10 +0200
Re: [PATCH 13/18] power: supply: bq24190_charger: Export 5V boost converter as regulator Liam Breck <liam@networkimprov.net> - 2017-08-08 21:00 +0200
Re: [PATCH 13/18] power: supply: bq24190_charger: Export 5V boost converter as regulator Hans de Goede <hdegoede@redhat.com> - 2017-08-08 23:10 +0200
[PATCH 10/18] staging: typec: fusb302: Add support for fcs,vbus-regulator-name device-property Hans de Goede <hdegoede@redhat.com> - 2017-08-06 14:40 +0200
Re: [PATCH 10/18] staging: typec: fusb302: Add support for fcs,vbus-regulator-name device-property Guenter Roeck <linux@roeck-us.net> - 2017-08-06 16:40 +0200
Re: [PATCH 10/18] staging: typec: fusb302: Add support for fcs,vbus-regulator-name device-property Hans de Goede <hdegoede@redhat.com> - 2017-08-06 17:00 +0200
Re: [PATCH 10/18] staging: typec: fusb302: Add support for fcs,vbus-regulator-name device-property Guenter Roeck <linux@roeck-us.net> - 2017-08-06 17:30 +0200
Re: [PATCH 10/18] staging: typec: fusb302: Add support for fcs,vbus-regulator-name device-property Hans de Goede <hdegoede@redhat.com> - 2017-08-06 17:50 +0200
Re: [PATCH 10/18] staging: typec: fusb302: Add support for fcs,vbus-regulator-name device-property Mark Brown <broonie@kernel.org> - 2017-08-07 13:20 +0200
Re: [PATCH 10/18] staging: typec: fusb302: Add support for fcs,vbus-regulator-name device-property Hans de Goede <hdegoede@redhat.com> - 2017-08-07 16:50 +0200
Re: [PATCH 10/18] staging: typec: fusb302: Add support for fcs,vbus-regulator-name device-property Mark Brown <broonie@kernel.org> - 2017-08-07 17:50 +0200
Re: [PATCH 10/18] staging: typec: fusb302: Add support for fcs,vbus-regulator-name device-property Hans de Goede <hdegoede@redhat.com> - 2017-08-07 21:30 +0200
Re: [PATCH 10/18] staging: typec: fusb302: Add support for fcs,vbus-regulator-name device-property Mark Brown <broonie@kernel.org> - 2017-08-08 11:50 +0200
Re: [PATCH 10/18] staging: typec: fusb302: Add support for fcs,vbus-regulator-name device-property Hans de Goede <hdegoede@redhat.com> - 2017-08-08 23:00 +0200
[PATCH 14/18] power: supply: bq24190_charger: Add input_current_limit property Hans de Goede <hdegoede@redhat.com> - 2017-08-06 14:40 +0200
[PATCH 09/18] staging: typec: fusb302: Use tcpm_set_current_limit_psy Hans de Goede <hdegoede@redhat.com> - 2017-08-06 14:40 +0200
Re: [PATCH 09/18] staging: typec: fusb302: Use tcpm_set_current_limit_psy Guenter Roeck <linux@roeck-us.net> - 2017-08-06 16:30 +0200
[PATCH 05/18] staging: typec: fusb302: Set max supply voltage to 5V Hans de Goede <hdegoede@redhat.com> - 2017-08-06 14:40 +0200
[PATCH 03/18] staging: typec: tcpm: Split tcpm code into tcpm-core.c and tcpm-helpers.c Hans de Goede <hdegoede@redhat.com> - 2017-08-06 14:40 +0200
[PATCH 02/18] staging: typec: tcpm: Add extcon helper functions for USB2 current limit detect Hans de Goede <hdegoede@redhat.com> - 2017-08-06 14:50 +0200
Re: [PATCH 02/18] staging: typec: tcpm: Add extcon helper functions for USB2 current limit detect Guenter Roeck <linux@roeck-us.net> - 2017-08-06 16:10 +0200
csiph-web