From: Lee Jones <lee@kernel.org>
To: Artur Weber <aweber.kernel@gmail.com>
Cc: Krzysztof Kozlowski <krzk@kernel.org>,
Chanwoo Choi <cw00.choi@samsung.com>,
Sebastian Reichel <sre@kernel.org>, Rob Herring <robh@kernel.org>,
Conor Dooley <conor+dt@kernel.org>,
Krzysztof Kozlowski <krzk+dt@kernel.org>,
Alim Akhtar <alim.akhtar@samsung.com>,
linux-pm@vger.kernel.org, devicetree@vger.kernel.org,
linux-kernel@vger.kernel.org,
linux-arm-kernel@lists.infradead.org,
linux-samsung-soc@vger.kernel.org,
~postmarketos/upstreaming@lists.sr.ht,
Henrik Grimler <henrik@grimler.se>,
Wolfgang Wiedmeyer <wolfgit@wiedmeyer.de>,
Denis 'GNUtoo' Carikli <GNUtoo@cyberdimension.org>
Subject: Re: [PATCH v2 7/9] power: supply: max77693: Add support for detecting and enabling OTG
Date: Thu, 25 Jul 2024 16:38:56 +0100 [thread overview]
Message-ID: <20240725153856.GH501857@google.com> (raw)
In-Reply-To: <20240715-max77693-charger-extcon-v2-7-0838ffbb18c3@gmail.com>
On Mon, 15 Jul 2024, Artur Weber wrote:
> Building upon the newly added extcon detection support, add detection
> for USB OTG cables (EXTCON_USB_HOST type), and enable/disable the OTG
> bits as needed.
>
> Signed-off-by: Artur Weber <aweber.kernel@gmail.com>
> ---
> Changes in v2:
> - Added CHGIN OTG current limit value
> - Squashed MFD header register changes into this commit
> ---
> drivers/power/supply/max77693_charger.c | 103 +++++++++++++++++++++++++++-----
> include/linux/mfd/max77693-private.h | 5 ++
Acked-by: Lee Jones <lee@kernel.org>
> 2 files changed, 94 insertions(+), 14 deletions(-)
>
> diff --git a/drivers/power/supply/max77693_charger.c b/drivers/power/supply/max77693_charger.c
> index 2dc273dd96ee..34d68b1050d4 100644
> --- a/drivers/power/supply/max77693_charger.c
> +++ b/drivers/power/supply/max77693_charger.c
> @@ -669,6 +669,16 @@ static int max77693_reg_init(struct max77693_charger *chg)
> if (ret)
> return ret;
>
> + /* Set OTG current limit to 900 mA */
> + data = (0x1 << CHG_CNFG_02_OTG_ILIM_SHIFT);
> + ret = regmap_update_bits(chg->max77693->regmap,
> + MAX77693_CHG_REG_CHG_CNFG_02,
> + CHG_CNFG_02_OTG_ILIM_MASK, data);
> + if (ret) {
> + dev_err(chg->dev, "Error setting OTG current limit: %d\n", ret);
> + return ret;
> + }
> +
> return max77693_set_charge_input_threshold_volt(chg,
> chg->charge_input_threshold_volt);
> }
> @@ -690,11 +700,42 @@ static int max77693_set_charging(struct max77693_charger *chg, bool enable)
> return ret;
> }
>
> +static int max77693_set_otg(struct max77693_charger *chg, bool enable)
> +{
> + struct regmap *regmap = chg->max77693->regmap;
> + unsigned int data;
> + bool is_enabled;
> + int ret;
> +
> + ret = regmap_read(regmap, MAX77693_CHG_REG_CHG_CNFG_00, &data);
> + if (ret)
> + return ret;
> +
> + is_enabled = !!(data & CHG_CNFG_00_OTG_MASK);
> +
> + if (enable && !is_enabled) {
> + /* OTG on, boost on, DIS_MUIC_CTRL on */
> + data |= CHG_CNFG_00_OTG_MASK | CHG_CNFG_00_BOOST_MASK \
> + | CHG_CNFG_00_DIS_MUIC_CTRL_MASK;
> +
> + } else if (!enable && is_enabled) {
> + /* OTG off, boost off, DIS_MUIC_CTRL off */
> + data &= ~(CHG_CNFG_00_OTG_MASK | CHG_CNFG_00_BOOST_MASK \
> + | CHG_CNFG_00_DIS_MUIC_CTRL_MASK);
> + }
> +
> + return regmap_write(chg->max77693->regmap,
> + MAX77693_CHG_REG_CHG_CNFG_00,
> + data);
> +}
> +
> static void max77693_charger_extcon_work(struct work_struct *work)
> {
> struct max77693_charger *chg = container_of(work, struct max77693_charger,
> cable.work);
> struct extcon_dev *edev = chg->cable.edev;
> + bool set_charging, set_otg;
> + unsigned int current_limit;
> int connector, state;
> int ret;
>
> @@ -707,31 +748,61 @@ static void max77693_charger_extcon_work(struct work_struct *work)
>
> switch (connector) {
> case EXTCON_CHG_USB_SDP:
> - case EXTCON_CHG_USB_DCP:
> case EXTCON_CHG_USB_CDP:
> + case EXTCON_CHG_USB_SLOW:
> + current_limit = 500000; /* 500 mA */
> + set_charging = true;
> + set_otg = false;
> +
> + dev_info(chg->dev, "slow charging. connector type: %d\n",
> + connector);
> + break;
> + case EXTCON_CHG_USB_DCP:
> case EXTCON_CHG_USB_ACA:
> case EXTCON_CHG_USB_FAST:
> - case EXTCON_CHG_USB_SLOW:
> case EXTCON_CHG_USB_PD:
> - ret = max77693_set_charging(chg, true);
> - if (ret) {
> - dev_err(chg->dev, "failed to enable charging\n");
> - break;
> - }
> - dev_info(chg->dev, "charging. connector type: %d\n",
> + current_limit = chg->fast_charge_current;
> + set_charging = true;
> + set_otg = false;
> +
> + dev_info(chg->dev, "fast charging. connector type: %d\n",
> + connector);
> + break;
> + case EXTCON_USB_HOST:
> + current_limit = 500000; /* 500 mA */
> + set_charging = false;
> + set_otg = true;
> +
> + dev_info(chg->dev, "USB host. connector type: %d\n",
> connector);
> break;
> default:
> - ret = max77693_set_charging(chg, false);
> - if (ret) {
> - dev_err(chg->dev, "failed to disable charging\n");
> - break;
> - }
> - dev_info(chg->dev, "charging. connector type: %d\n",
> + current_limit = 500000; /* 500 mA */
> + set_charging = false;
> + set_otg = false;
> +
> + dev_info(chg->dev, "disconnected. connector type: %d\n",
> connector);
> break;
> }
>
> + ret = max77693_set_current_limit(chg, current_limit);
> + if (ret) {
> + dev_err(chg->dev, "failed to set current limit (%d)\n", ret);
> + goto out;
> + }
> +
> + ret = max77693_set_charging(chg, set_charging);
> + if (ret) {
> + dev_err(chg->dev, "failed to set charging (%d)\n", ret);
> + goto out;
> + }
> +
> + ret = max77693_set_otg(chg, set_otg);
> + if (ret)
> + dev_err(chg->dev, "failed to set OTG (%d)\n", ret);
> +
> +out:
> power_supply_changed(chg->charger);
> }
>
> @@ -793,6 +864,10 @@ static int max77693_dt_init(struct device *dev, struct max77693_charger *chg)
> &chg->batttery_overcurrent))
> chg->batttery_overcurrent = DEFAULT_BATTERY_OVERCURRENT;
>
> + if (of_property_read_u32(np, "maxim,fast-charge-current-microamp",
> + &chg->fast_charge_current))
> + chg->fast_charge_current = DEFAULT_FAST_CHARGE_CURRENT;
> +
> if (of_property_read_u32(np, "maxim,charge-input-threshold-microvolt",
> &chg->charge_input_threshold_volt))
> chg->charge_input_threshold_volt =
> diff --git a/include/linux/mfd/max77693-private.h b/include/linux/mfd/max77693-private.h
> index 4570646e2f33..313fcc3173f9 100644
> --- a/include/linux/mfd/max77693-private.h
> +++ b/include/linux/mfd/max77693-private.h
> @@ -209,7 +209,10 @@ enum max77693_charger_battery_state {
>
> /* MAX77693 CHG_CNFG_00 register */
> #define CHG_CNFG_00_CHG_MASK 0x1
> +#define CHG_CNFG_00_OTG_MASK 0x2
> #define CHG_CNFG_00_BUCK_MASK 0x4
> +#define CHG_CNFG_00_BOOST_MASK 0x8
> +#define CHG_CNFG_00_DIS_MUIC_CTRL_MASK 0x20
>
> /* MAX77693_CHG_REG_CHG_CNFG_01 register */
> #define CHG_CNFG_01_FCHGTIME_SHIFT 0
> @@ -222,6 +225,8 @@ enum max77693_charger_battery_state {
> /* MAX77693_CHG_REG_CHG_CNFG_02 register */
> #define CHG_CNFG_02_CC_SHIFT 0
> #define CHG_CNFG_02_CC_MASK 0x3F
> +#define CHG_CNFG_02_OTG_ILIM_SHIFT 7
> +#define CHG_CNFG_02_OTG_ILIM_MASK 0x80
>
> /* MAX77693_CHG_REG_CHG_CNFG_03 register */
> #define CHG_CNFG_03_TOITH_SHIFT 0
>
> --
> 2.45.2
>
--
Lee Jones [李琼斯]
next prev parent reply other threads:[~2024-07-25 15:39 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-07-15 12:55 [PATCH v2 0/9] power: supply: max77693: Toggle charging/OTG based on extcon status Artur Weber
2024-07-15 12:55 ` [PATCH v2 1/9] dt-bindings: power: supply: max77693: Add monitored-battery property Artur Weber
2024-07-22 5:48 ` Krzysztof Kozlowski
2024-07-15 12:55 ` [PATCH v2 2/9] dt-bindings: power: supply: max77693: Add maxim,usb-connector property Artur Weber
2024-07-22 5:49 ` Krzysztof Kozlowski
2024-07-15 12:55 ` [PATCH v2 3/9] regulator: max77693: Set fast charge current in MAX77693 CHARGER regulator Artur Weber
2024-07-15 12:55 ` [PATCH v2 4/9] power: supply: max77693: Expose CURRENT_MAX property Artur Weber
2024-07-15 12:55 ` [PATCH v2 5/9] power: supply: max77693: Set charge current limits during init Artur Weber
2024-07-25 15:37 ` Lee Jones
2024-07-15 12:55 ` [PATCH v2 6/9] power: supply: max77693: Add USB extcon detection for enabling charging Artur Weber
2024-07-20 20:59 ` Artur Weber
2024-07-15 12:55 ` [PATCH v2 7/9] power: supply: max77693: Add support for detecting and enabling OTG Artur Weber
2024-07-25 15:38 ` Lee Jones [this message]
2024-07-15 12:55 ` [PATCH v2 8/9] ARM: dts: samsung: exynos4212-tab3: Add battery node with charge current value Artur Weber
2024-07-15 12:55 ` [PATCH v2 9/9] ARM: dts: samsung: exynos4212-tab3: Add USB connector node Artur Weber
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240725153856.GH501857@google.com \
--to=lee@kernel.org \
--cc=GNUtoo@cyberdimension.org \
--cc=alim.akhtar@samsung.com \
--cc=aweber.kernel@gmail.com \
--cc=conor+dt@kernel.org \
--cc=cw00.choi@samsung.com \
--cc=devicetree@vger.kernel.org \
--cc=henrik@grimler.se \
--cc=krzk+dt@kernel.org \
--cc=krzk@kernel.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pm@vger.kernel.org \
--cc=linux-samsung-soc@vger.kernel.org \
--cc=robh@kernel.org \
--cc=sre@kernel.org \
--cc=wolfgit@wiedmeyer.de \
--cc=~postmarketos/upstreaming@lists.sr.ht \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).