From patchwork Mon Dec 6 09:32:59 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans de Goede X-Patchwork-Id: 521064 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8C42CC433FE for ; Mon, 6 Dec 2021 09:33:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240822AbhLFJhI (ORCPT ); Mon, 6 Dec 2021 04:37:08 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:31782 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240806AbhLFJhH (ORCPT ); Mon, 6 Dec 2021 04:37:07 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1638783219; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Y3WcgKJc+zc8rlpyfwZumMsVu/Grjc1H2KQ2Qlorauc=; b=LMBFfnt+JVqm7m79QXhDt5W/ke35sAjSw8qUjTVdJvZqxYqhR3zqFn0APusVINncoTNsNc q2ueSodNLEftfhBC+sP4Pj3P7v2uXlKugxA8SrW5Hc9365btPmlycPoz9x9NsDKjf1NsRI kjTanEwh2xcALPIisFAcPFvGoTbv9Is= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-158-2W13MqhUMKm4G3oQxJvtpw-1; Mon, 06 Dec 2021 04:33:33 -0500 X-MC-Unique: 2W13MqhUMKm4G3oQxJvtpw-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 2B532185302B; Mon, 6 Dec 2021 09:33:31 +0000 (UTC) Received: from x1.localdomain.com (unknown [10.39.194.76]) by smtp.corp.redhat.com (Postfix) with ESMTP id E51055DAA5; Mon, 6 Dec 2021 09:33:24 +0000 (UTC) From: Hans de Goede To: "Rafael J . Wysocki" , Mika Westerberg , Mark Gross , Andy Shevchenko , Wolfram Sang , Lee Jones , Sebastian Reichel , MyungJoo Ham , Chanwoo Choi , Ard Biesheuvel Cc: Hans de Goede , Len Brown , linux-acpi@vger.kernel.org, Yauhen Kharuzhy , Tsuchiya Yuto , platform-driver-x86@vger.kernel.org, linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, linux-efi@vger.kernel.org Subject: [PATCH v4 01/20] power: supply: core: Refactor power_supply_set_input_current_limit_from_supplier() Date: Mon, 6 Dec 2021 10:32:59 +0100 Message-Id: <20211206093318.45214-2-hdegoede@redhat.com> In-Reply-To: <20211206093318.45214-1-hdegoede@redhat.com> References: <20211206093318.45214-1-hdegoede@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 Precedence: bulk List-ID: X-Mailing-List: linux-efi@vger.kernel.org Some (USB) charger ICs have variants with USB D+ and D- pins to do their own builtin charger-type detection, like e.g. the bq24190 and bq25890 and also variants which lack this functionality, e.g. the bq24192 and bq25892. In case the charger-type; and thus the input-current-limit detection is done outside the charger IC then we need some way to communicate this to the charger IC. In the past extcon was used for this, but if the external detection does e.g. full USB PD negotiation then the extcon cable-types do not convey enough information. For these setups it was decided to model the external charging "brick" and the parameters negotiated with it as a power_supply class-device itself; and power_supply_set_input_current_limit_from_supplier() was introduced to allow drivers to get the input-current-limit this way. But in some cases psy drivers may want to know other properties, e.g. the bq25892 can do "quick-charge" negotiation by pulsing its current draw, but this should only be done if the usb_type psy-property of its supplier is set to DCP (and device-properties indicate the board allows higher voltages). Instead of adding extra helper functions for each property which a psy-driver wants to query from its supplier, refactor power_supply_set_input_current_limit_from_supplier() into a more generic power_supply_get_property_from_supplier() function. Signed-off-by: Hans de Goede --- drivers/power/supply/bq24190_charger.c | 10 ++++- drivers/power/supply/power_supply_core.c | 57 +++++++++++++----------- include/linux/power_supply.h | 5 ++- 3 files changed, 42 insertions(+), 30 deletions(-) diff --git a/drivers/power/supply/bq24190_charger.c b/drivers/power/supply/bq24190_charger.c index 35ff0c8fe96f..0c3d5caaef0c 100644 --- a/drivers/power/supply/bq24190_charger.c +++ b/drivers/power/supply/bq24190_charger.c @@ -1206,8 +1206,16 @@ static void bq24190_input_current_limit_work(struct work_struct *work) struct bq24190_dev_info *bdi = container_of(work, struct bq24190_dev_info, input_current_limit_work.work); + union power_supply_propval val; + int ret; - power_supply_set_input_current_limit_from_supplier(bdi->charger); + ret = power_supply_get_property_from_supplier(bdi->charger, + POWER_SUPPLY_PROP_CURRENT_MAX, + &val); + if (ret == 0) + bq24190_charger_set_property(bdi->charger, + POWER_SUPPLY_PROP_INPUT_CURRENT_LIMIT, + &val); } /* Sync the input-current-limit with our parent supply (if we have one) */ diff --git a/drivers/power/supply/power_supply_core.c b/drivers/power/supply/power_supply_core.c index fc12a4f407f4..fb956a9a1827 100644 --- a/drivers/power/supply/power_supply_core.c +++ b/drivers/power/supply/power_supply_core.c @@ -375,46 +375,49 @@ int power_supply_is_system_supplied(void) } EXPORT_SYMBOL_GPL(power_supply_is_system_supplied); -static int __power_supply_get_supplier_max_current(struct device *dev, - void *data) +struct psy_get_supplier_prop_data { + struct power_supply *psy; + enum power_supply_property psp; + union power_supply_propval *val; +}; + +static int __power_supply_get_supplier_property(struct device *dev, void *_data) { - union power_supply_propval ret = {0,}; struct power_supply *epsy = dev_get_drvdata(dev); - struct power_supply *psy = data; + struct psy_get_supplier_prop_data *data = _data; - if (__power_supply_is_supplied_by(epsy, psy)) - if (!epsy->desc->get_property(epsy, - POWER_SUPPLY_PROP_CURRENT_MAX, - &ret)) - return ret.intval; + if (__power_supply_is_supplied_by(epsy, data->psy)) + if (!epsy->desc->get_property(epsy, data->psp, data->val)) + return 1; /* Success */ - return 0; + return 0; /* Continue iterating */ } -int power_supply_set_input_current_limit_from_supplier(struct power_supply *psy) +int power_supply_get_property_from_supplier(struct power_supply *psy, + enum power_supply_property psp, + union power_supply_propval *val) { - union power_supply_propval val = {0,}; - int curr; - - if (!psy->desc->set_property) - return -EINVAL; + struct psy_get_supplier_prop_data data = { + .psy = psy, + .psp = psp, + .val = val, + }; + int ret; /* * This function is not intended for use with a supply with multiple - * suppliers, we simply pick the first supply to report a non 0 - * max-current. + * suppliers, we simply pick the first supply to report the psp. */ - curr = class_for_each_device(power_supply_class, NULL, psy, - __power_supply_get_supplier_max_current); - if (curr <= 0) - return (curr == 0) ? -ENODEV : curr; - - val.intval = curr; + ret = class_for_each_device(power_supply_class, NULL, &data, + __power_supply_get_supplier_property); + if (ret < 0) + return ret; + if (ret == 0) + return -ENODEV; - return psy->desc->set_property(psy, - POWER_SUPPLY_PROP_INPUT_CURRENT_LIMIT, &val); + return 0; } -EXPORT_SYMBOL_GPL(power_supply_set_input_current_limit_from_supplier); +EXPORT_SYMBOL_GPL(power_supply_get_property_from_supplier); int power_supply_set_battery_charged(struct power_supply *psy) { diff --git a/include/linux/power_supply.h b/include/linux/power_supply.h index 9ca1f120a211..0735b8963e0a 100644 --- a/include/linux/power_supply.h +++ b/include/linux/power_supply.h @@ -420,8 +420,9 @@ power_supply_temp2resist_simple(struct power_supply_resistance_temp_table *table int table_len, int temp); extern void power_supply_changed(struct power_supply *psy); extern int power_supply_am_i_supplied(struct power_supply *psy); -extern int power_supply_set_input_current_limit_from_supplier( - struct power_supply *psy); +int power_supply_get_property_from_supplier(struct power_supply *psy, + enum power_supply_property psp, + union power_supply_propval *val); extern int power_supply_set_battery_charged(struct power_supply *psy); #ifdef CONFIG_POWER_SUPPLY From patchwork Mon Dec 6 09:33:01 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Hans de Goede X-Patchwork-Id: 521063 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id AE441C433FE for ; Mon, 6 Dec 2021 09:33:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240899AbhLFJhT (ORCPT ); Mon, 6 Dec 2021 04:37:19 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:22234 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240889AbhLFJhS (ORCPT ); Mon, 6 Dec 2021 04:37:18 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1638783228; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=/NpFdB1bVbDNAo3VG1s0TVH/ohpEAXL05zlAcvCO9sw=; b=URpRsdl+r13NHEwNKFMZmCxzWC66rxmchMLF14ofDT8gzaKkVfi8pNELaU3tF5k7soBQn8 wgV3uePNdRi59TAk946f4ocIkCXKxLqKWALnvF1whQyoDWqDzPU5aM51Xp/YzlqHkfsYsu yivgd2t0SvfdIGmHqp31/SF077UNS4o= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-541-ShiRPCZ1MSOwmElRgz8y4w-1; Mon, 06 Dec 2021 04:33:44 -0500 X-MC-Unique: ShiRPCZ1MSOwmElRgz8y4w-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 44E32101F001; Mon, 6 Dec 2021 09:33:42 +0000 (UTC) Received: from x1.localdomain.com (unknown [10.39.194.76]) by smtp.corp.redhat.com (Postfix) with ESMTP id C3F11ADD6; Mon, 6 Dec 2021 09:33:38 +0000 (UTC) From: Hans de Goede To: "Rafael J . Wysocki" , Mika Westerberg , Mark Gross , Andy Shevchenko , Wolfram Sang , Lee Jones , Sebastian Reichel , MyungJoo Ham , Chanwoo Choi , Ard Biesheuvel Cc: Hans de Goede , Len Brown , linux-acpi@vger.kernel.org, Yauhen Kharuzhy , Tsuchiya Yuto , platform-driver-x86@vger.kernel.org, linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, linux-efi@vger.kernel.org Subject: [PATCH v4 03/20] power: supply: bq25890: Reduce reported CONSTANT_CHARGE_CURRENT_MAX for low temperatures Date: Mon, 6 Dec 2021 10:33:01 +0100 Message-Id: <20211206093318.45214-4-hdegoede@redhat.com> In-Reply-To: <20211206093318.45214-1-hdegoede@redhat.com> References: <20211206093318.45214-1-hdegoede@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 Precedence: bulk List-ID: X-Mailing-List: linux-efi@vger.kernel.org From: Yauhen Kharuzhy Take into account possible current reduction due to low-temperature when reading POWER_SUPPLY_PROP_CONSTANT_CHARGE_CURRENT_MAX. As described in the datasheet in cool (0-20° Celcius) conditions the current limit is decreased to 20% or 50% of ICHG field value depended on JEITA_ISET field. Also add NTC_FAULT field value to the debug message in bq25890_get_chip_state(). Changed by Hans de Goede: - Fix reading F_CHG_FAULT instead of F_NTC_FIELD for state->ntc_fault - Only read JEITA_ISET field if necessary - Tweak commit message a bit Signed-off-by: Yauhen Kharuzhy Co-developed-by: Hans de Goede Signed-off-by: Hans de Goede --- Changes in v3: - Drop chunk adding a F_JEITA_VSET read to bq25890_power_supply_get_property() which accidentally got added to this patch --- drivers/power/supply/bq25890_charger.c | 29 +++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/drivers/power/supply/bq25890_charger.c b/drivers/power/supply/bq25890_charger.c index fb987579d05a..7a3269c06b38 100644 --- a/drivers/power/supply/bq25890_charger.c +++ b/drivers/power/supply/bq25890_charger.c @@ -94,6 +94,7 @@ struct bq25890_state { u8 vsys_status; u8 boost_fault; u8 bat_fault; + u8 ntc_fault; }; struct bq25890_device { @@ -407,6 +408,14 @@ enum bq25890_chrg_fault { CHRG_FAULT_TIMER_EXPIRED, }; +enum bq25890_ntc_fault { + NTC_FAULT_NORMAL = 0, + NTC_FAULT_WARM = 2, + NTC_FAULT_COOL = 3, + NTC_FAULT_COLD = 5, + NTC_FAULT_HOT = 6, +}; + static bool bq25890_is_adc_property(enum power_supply_property psp) { switch (psp) { @@ -499,6 +508,18 @@ static int bq25890_power_supply_get_property(struct power_supply *psy, case POWER_SUPPLY_PROP_CONSTANT_CHARGE_CURRENT_MAX: val->intval = bq25890_find_val(bq->init_data.ichg, TBL_ICHG); + + /* When temperature is too low, charge current is decreased */ + if (bq->state.ntc_fault == NTC_FAULT_COOL) { + ret = bq25890_field_read(bq, F_JEITA_ISET); + if (ret < 0) + return ret; + + if (ret) + val->intval /= 5; + else + val->intval /= 2; + } break; case POWER_SUPPLY_PROP_CONSTANT_CHARGE_VOLTAGE: @@ -583,7 +604,8 @@ static int bq25890_get_chip_state(struct bq25890_device *bq, {F_VSYS_STAT, &state->vsys_status}, {F_BOOST_FAULT, &state->boost_fault}, {F_BAT_FAULT, &state->bat_fault}, - {F_CHG_FAULT, &state->chrg_fault} + {F_CHG_FAULT, &state->chrg_fault}, + {F_NTC_FAULT, &state->ntc_fault} }; for (i = 0; i < ARRAY_SIZE(state_fields); i++) { @@ -594,9 +616,10 @@ static int bq25890_get_chip_state(struct bq25890_device *bq, *state_fields[i].data = ret; } - dev_dbg(bq->dev, "S:CHG/PG/VSYS=%d/%d/%d, F:CHG/BOOST/BAT=%d/%d/%d\n", + dev_dbg(bq->dev, "S:CHG/PG/VSYS=%d/%d/%d, F:CHG/BOOST/BAT/NTC=%d/%d/%d/%d\n", state->chrg_status, state->online, state->vsys_status, - state->chrg_fault, state->boost_fault, state->bat_fault); + state->chrg_fault, state->boost_fault, state->bat_fault, + state->ntc_fault); return 0; } From patchwork Mon Dec 6 09:33:03 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans de Goede X-Patchwork-Id: 521062 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 27DF9C433F5 for ; Mon, 6 Dec 2021 09:33:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240904AbhLFJhZ (ORCPT ); Mon, 6 Dec 2021 04:37:25 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:46194 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240933AbhLFJhZ (ORCPT ); Mon, 6 Dec 2021 04:37:25 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1638783236; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=fANyvle+meUJ4owjhpqvoJKR2AJ1xpjSPkIqPG9nFHk=; b=evGt7nc/WhTlEpzmRThd5t36aSRnFm9T+pmw1i44m9Jghp5fcsi8irx/FEjTSa1swB2U8a N4UK0UMTcIXk2kcYI6UzW8Jk7qT2/BPb9kpYLAU/5rQORM/eYNjMCVbBmTf9O/CfN21UF0 buX4rIaaUvv5oIVAoLkcplNo9eIAmTM= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-422-VDXfFfaVM66dZyl6b79tJQ-1; Mon, 06 Dec 2021 04:33:52 -0500 X-MC-Unique: VDXfFfaVM66dZyl6b79tJQ-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id E981281CCB5; Mon, 6 Dec 2021 09:33:49 +0000 (UTC) Received: from x1.localdomain.com (unknown [10.39.194.76]) by smtp.corp.redhat.com (Postfix) with ESMTP id 679F0ADD6; Mon, 6 Dec 2021 09:33:46 +0000 (UTC) From: Hans de Goede To: "Rafael J . Wysocki" , Mika Westerberg , Mark Gross , Andy Shevchenko , Wolfram Sang , Lee Jones , Sebastian Reichel , MyungJoo Ham , Chanwoo Choi , Ard Biesheuvel Cc: Hans de Goede , Len Brown , linux-acpi@vger.kernel.org, Yauhen Kharuzhy , Tsuchiya Yuto , platform-driver-x86@vger.kernel.org, linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, linux-efi@vger.kernel.org Subject: [PATCH v4 05/20] power: supply: bq25890: Add support to skip reset at probe() / remove() Date: Mon, 6 Dec 2021 10:33:03 +0100 Message-Id: <20211206093318.45214-6-hdegoede@redhat.com> In-Reply-To: <20211206093318.45214-1-hdegoede@redhat.com> References: <20211206093318.45214-1-hdegoede@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 Precedence: bulk List-ID: X-Mailing-List: linux-efi@vger.kernel.org On most x86/ACPI devices the firmware already fully initializes the bq25890 charger at boot, in this case it is best to not reset it at probe() time. At support for a new "linux,skip-reset" boolean property to support this. So far this new property is only used on x86/ACPI (non devicetree) devs, IOW it is not used in actual devicetree files. The devicetree-bindings maintainers have requested properties like these to not be added to the devicetree-bindings, so the new property is deliberately not added to the existing devicetree-bindings. Signed-off-by: Hans de Goede --- Changes in v2: - New patch in v2 of this series, together with the "linux,read-back-settings" patch, this patch replaces the "ti,skip-init" patch from v1 --- drivers/power/supply/bq25890_charger.c | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/drivers/power/supply/bq25890_charger.c b/drivers/power/supply/bq25890_charger.c index eaf0400b632f..cd80d748df92 100644 --- a/drivers/power/supply/bq25890_charger.c +++ b/drivers/power/supply/bq25890_charger.c @@ -110,6 +110,7 @@ struct bq25890_device { struct regmap *rmap; struct regmap_field *rmap_fields[F_MAX_FIELDS]; + bool skip_reset; enum bq25890_chip_version chip_version; struct bq25890_init_data init_data; struct bq25890_state state; @@ -739,10 +740,12 @@ static int bq25890_hw_init(struct bq25890_device *bq) { int ret; - ret = bq25890_chip_reset(bq); - if (ret < 0) { - dev_dbg(bq->dev, "Reset failed %d\n", ret); - return ret; + if (!bq->skip_reset) { + ret = bq25890_chip_reset(bq); + if (ret < 0) { + dev_dbg(bq->dev, "Reset failed %d\n", ret); + return ret; + } } /* disable watchdog */ @@ -977,6 +980,8 @@ static int bq25890_fw_probe(struct bq25890_device *bq) int ret; struct bq25890_init_data *init = &bq->init_data; + bq->skip_reset = device_property_read_bool(bq->dev, "linux,skip-reset"); + ret = bq25890_fw_read_u32_props(bq); if (ret < 0) return ret; @@ -1089,8 +1094,10 @@ static int bq25890_remove(struct i2c_client *client) if (!IS_ERR_OR_NULL(bq->usb_phy)) usb_unregister_notifier(bq->usb_phy, &bq->usb_nb); - /* reset all registers to default values */ - bq25890_chip_reset(bq); + if (!bq->skip_reset) { + /* reset all registers to default values */ + bq25890_chip_reset(bq); + } return 0; } From patchwork Mon Dec 6 09:33:07 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans de Goede X-Patchwork-Id: 521059 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 05CECC43219 for ; Mon, 6 Dec 2021 09:35:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241077AbhLFJit (ORCPT ); Mon, 6 Dec 2021 04:38:49 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:54334 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241000AbhLFJiB (ORCPT ); Mon, 6 Dec 2021 04:38:01 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1638783273; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=rkHMjBM63zGg47ORcfkgLOvjulrZ8Qq0h9KQnMkwKnc=; b=deQNdts0sN1zTKsBke4fcHqKcDo0ZamfIiyP5ABoVxX+ZuLnHdJMYm+zUJZKAkZM9RjQy+ rhW/JruIFY3JMGdfRoUZ2kG1mwLfSCO95gBb2VcWvI/tuwEnpJtUc5KdGW+vuvYJlLbazY hx7FDnTwvebBhpxaWJk0yp1Sg3WyEtk= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-589-cGdrGQugNZ2kBRBMmJDA_g-1; Mon, 06 Dec 2021 04:34:29 -0500 X-MC-Unique: cGdrGQugNZ2kBRBMmJDA_g-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 04BD981CCB6; Mon, 6 Dec 2021 09:34:27 +0000 (UTC) Received: from x1.localdomain.com (unknown [10.39.194.76]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9C5D05ED2C; Mon, 6 Dec 2021 09:34:21 +0000 (UTC) From: Hans de Goede To: "Rafael J . Wysocki" , Mika Westerberg , Mark Gross , Andy Shevchenko , Wolfram Sang , Lee Jones , Sebastian Reichel , MyungJoo Ham , Chanwoo Choi , Ard Biesheuvel Cc: Hans de Goede , Len Brown , linux-acpi@vger.kernel.org, Yauhen Kharuzhy , Tsuchiya Yuto , platform-driver-x86@vger.kernel.org, linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, linux-efi@vger.kernel.org Subject: [PATCH v4 09/20] power: supply: bq25890: Add bq25890_set_otg_cfg() helper Date: Mon, 6 Dec 2021 10:33:07 +0100 Message-Id: <20211206093318.45214-10-hdegoede@redhat.com> In-Reply-To: <20211206093318.45214-1-hdegoede@redhat.com> References: <20211206093318.45214-1-hdegoede@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 Precedence: bulk List-ID: X-Mailing-List: linux-efi@vger.kernel.org Add a bq25890_set_otg_cfg() helper function, this is a preparation patch for adding regulator support. Signed-off-by: Hans de Goede --- drivers/power/supply/bq25890_charger.c | 28 ++++++++++++++------------ 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/drivers/power/supply/bq25890_charger.c b/drivers/power/supply/bq25890_charger.c index 548d1a793e31..162bffb02410 100644 --- a/drivers/power/supply/bq25890_charger.c +++ b/drivers/power/supply/bq25890_charger.c @@ -832,6 +832,17 @@ static int bq25890_power_supply_init(struct bq25890_device *bq) return PTR_ERR_OR_ZERO(bq->charger); } +static int bq25890_set_otg_cfg(struct bq25890_device *bq, u8 val) +{ + int ret; + + ret = bq25890_field_write(bq, F_OTG_CFG, val); + if (ret < 0) + dev_err(bq->dev, "Error switching to boost/charger mode: %d\n", ret); + + return ret; +} + static void bq25890_usb_work(struct work_struct *data) { int ret; @@ -841,25 +852,16 @@ static void bq25890_usb_work(struct work_struct *data) switch (bq->usb_event) { case USB_EVENT_ID: /* Enable boost mode */ - ret = bq25890_field_write(bq, F_OTG_CFG, 1); - if (ret < 0) - goto error; + bq25890_set_otg_cfg(bq, 1); break; case USB_EVENT_NONE: /* Disable boost mode */ - ret = bq25890_field_write(bq, F_OTG_CFG, 0); - if (ret < 0) - goto error; - - power_supply_changed(bq->charger); + ret = bq25890_set_otg_cfg(bq, 0); + if (ret == 0) + power_supply_changed(bq->charger); break; } - - return; - -error: - dev_err(bq->dev, "Error switching to boost/charger mode.\n"); } static int bq25890_usb_notifier(struct notifier_block *nb, unsigned long val, From patchwork Mon Dec 6 09:33:08 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans de Goede X-Patchwork-Id: 521061 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id E816EC43219 for ; Mon, 6 Dec 2021 09:35:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241205AbhLFJie (ORCPT ); Mon, 6 Dec 2021 04:38:34 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:25514 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240935AbhLFJiF (ORCPT ); Mon, 6 Dec 2021 04:38:05 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1638783276; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=RCI/2xm84dyYISbFEC9/hQrlI+8v3ywGqx6ibk46P7M=; b=CIAplBPKbzn2clGUcxcRnXNJfM8SX5kU4OHf6p5p2p3+e9sxaOzKsv7rn4a1UQANuMjHPm pCjxn0qsztFURWskGa+E4cY9EEf8TtvtnVvGEvZCUOtwroxhqryNddje1LObvO4DLqlpcw utEU//kmzhSbdc/CTdC7D+ht6PTopo0= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-58-WjWdzNBbP8KCnhz47pY_0g-1; Mon, 06 Dec 2021 04:34:33 -0500 X-MC-Unique: WjWdzNBbP8KCnhz47pY_0g-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id DDC6D101F004; Mon, 6 Dec 2021 09:34:30 +0000 (UTC) Received: from x1.localdomain.com (unknown [10.39.194.76]) by smtp.corp.redhat.com (Postfix) with ESMTP id 504375E24E; Mon, 6 Dec 2021 09:34:27 +0000 (UTC) From: Hans de Goede To: "Rafael J . Wysocki" , Mika Westerberg , Mark Gross , Andy Shevchenko , Wolfram Sang , Lee Jones , Sebastian Reichel , MyungJoo Ham , Chanwoo Choi , Ard Biesheuvel Cc: Hans de Goede , Len Brown , linux-acpi@vger.kernel.org, Yauhen Kharuzhy , Tsuchiya Yuto , platform-driver-x86@vger.kernel.org, linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, linux-efi@vger.kernel.org, Andy Shevchenko Subject: [PATCH v4 10/20] power: supply: bq25890: Add support for registering the Vbus boost converter as a regulator Date: Mon, 6 Dec 2021 10:33:08 +0100 Message-Id: <20211206093318.45214-11-hdegoede@redhat.com> In-Reply-To: <20211206093318.45214-1-hdegoede@redhat.com> References: <20211206093318.45214-1-hdegoede@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 Precedence: bulk List-ID: X-Mailing-List: linux-efi@vger.kernel.org The bq25890_charger code supports enabling/disabling the boost converter based on usb-phy notifications. But the usb-phy framework is not used on all boards/platforms. At support for registering the Vbus boost converter as a standard regulator when there is no usb-phy on the board. Also add support for providing regulator_init_data through platform_data for use on boards where device-tree is not used and the platform code must thus provide the regulator_init_data. Reviewed-by: Andy Shevchenko Signed-off-by: Hans de Goede --- Changes in v2: - When the usb-phy framework is not used, turn off the Vboost regulator on shutdown - Some minor code-tweaks based on Andy's review --- drivers/power/supply/bq25890_charger.c | 80 ++++++++++++++++++++++++++ include/linux/power/bq25890_charger.h | 15 +++++ 2 files changed, 95 insertions(+) create mode 100644 include/linux/power/bq25890_charger.h diff --git a/drivers/power/supply/bq25890_charger.c b/drivers/power/supply/bq25890_charger.c index 162bffb02410..637cdd3b6b11 100644 --- a/drivers/power/supply/bq25890_charger.c +++ b/drivers/power/supply/bq25890_charger.c @@ -8,7 +8,9 @@ #include #include #include +#include #include +#include #include #include #include @@ -876,6 +878,45 @@ static int bq25890_usb_notifier(struct notifier_block *nb, unsigned long val, return NOTIFY_OK; } +#ifdef CONFIG_REGULATOR +static int bq25890_vbus_enable(struct regulator_dev *rdev) +{ + struct bq25890_device *bq = rdev_get_drvdata(rdev); + + return bq25890_set_otg_cfg(bq, 1); +} + +static int bq25890_vbus_disable(struct regulator_dev *rdev) +{ + struct bq25890_device *bq = rdev_get_drvdata(rdev); + + return bq25890_set_otg_cfg(bq, 0); +} + +static int bq25890_vbus_is_enabled(struct regulator_dev *rdev) +{ + struct bq25890_device *bq = rdev_get_drvdata(rdev); + + return bq25890_field_read(bq, F_OTG_CFG); +} + +static const struct regulator_ops bq25890_vbus_ops = { + .enable = bq25890_vbus_enable, + .disable = bq25890_vbus_disable, + .is_enabled = bq25890_vbus_is_enabled, +}; + +static const struct regulator_desc bq25890_vbus_desc = { + .name = "usb_otg_vbus", + .of_match = "usb-otg-vbus", + .type = REGULATOR_VOLTAGE, + .owner = THIS_MODULE, + .ops = &bq25890_vbus_ops, + .fixed_uV = 5000000, + .n_voltages = 1, +}; +#endif + static int bq25890_get_chip_version(struct bq25890_device *bq) { int id, rev; @@ -1075,6 +1116,22 @@ static int bq25890_probe(struct i2c_client *client, bq->usb_nb.notifier_call = bq25890_usb_notifier; usb_register_notifier(bq->usb_phy, &bq->usb_nb); } +#ifdef CONFIG_REGULATOR + else { + struct bq25890_platform_data *pdata = dev_get_platdata(dev); + struct regulator_config cfg = { }; + struct regulator_dev *reg; + + cfg.dev = dev; + cfg.driver_data = bq; + if (pdata) + cfg.init_data = pdata->regulator_init_data; + + reg = devm_regulator_register(dev, &bq25890_vbus_desc, &cfg); + if (IS_ERR(reg)) + return dev_err_probe(dev, PTR_ERR(reg), "registering regulator"); + } +#endif ret = bq25890_power_supply_init(bq); if (ret < 0) { @@ -1113,6 +1170,28 @@ static int bq25890_remove(struct i2c_client *client) return 0; } +static void bq25890_shutdown(struct i2c_client *client) +{ + struct bq25890_device *bq = i2c_get_clientdata(client); + + /* + * TODO this if + return should probably be removed, but that would + * introduce a function change for boards using the usb-phy framework. + * This needs to be tested on such a board before making this change. + */ + if (!IS_ERR_OR_NULL(bq->usb_phy)) + return; + + /* + * Turn off the 5v Boost regulator which outputs Vbus to the device's + * Micro-USB or Type-C USB port. Leaving this on drains power and + * this avoids the PMIC on some device-models seeing this as Vbus + * getting inserted after shutdown, causing the device to immediately + * power-up again. + */ + bq25890_set_otg_cfg(bq, 0); +} + #ifdef CONFIG_PM_SLEEP static int bq25890_suspend(struct device *dev) { @@ -1192,6 +1271,7 @@ static struct i2c_driver bq25890_driver = { }, .probe = bq25890_probe, .remove = bq25890_remove, + .shutdown = bq25890_shutdown, .id_table = bq25890_i2c_ids, }; module_i2c_driver(bq25890_driver); diff --git a/include/linux/power/bq25890_charger.h b/include/linux/power/bq25890_charger.h new file mode 100644 index 000000000000..c706ddb77a08 --- /dev/null +++ b/include/linux/power/bq25890_charger.h @@ -0,0 +1,15 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* + * Platform data for the TI bq25890 battery charger driver. + */ + +#ifndef _BQ25890_CHARGER_H_ +#define _BQ25890_CHARGER_H_ + +struct regulator_init_data; + +struct bq25890_platform_data { + const struct regulator_init_data *regulator_init_data; +}; + +#endif From patchwork Mon Dec 6 09:33:09 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans de Goede X-Patchwork-Id: 521060 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 584D5C433F5 for ; Mon, 6 Dec 2021 09:35:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241062AbhLFJir (ORCPT ); Mon, 6 Dec 2021 04:38:47 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:48907 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240938AbhLFJiL (ORCPT ); Mon, 6 Dec 2021 04:38:11 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1638783282; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=pN1FjbLFcDO2d9j5qjlwIbSo+FUqNNS/pElCoMXXvWs=; b=Ywj7JT0Xduf9QmBg6YQfQw3i/e6ltGimRnwil6cxRjOLCN6TMKwJg5TnapDBafAF5NKKP3 C9R4sYABr/ZI7nIA8s9f5WMkQnfrYNCeKbXIQ7/2iQBgxDuw4oeSL5JwUJHZroGahllNuy Ylocx1LmkQSrqUObRm1Aacsvz62Noys= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-329-ymKv-1beOEmAn71OtYS7nQ-1; Mon, 06 Dec 2021 04:34:37 -0500 X-MC-Unique: ymKv-1beOEmAn71OtYS7nQ-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id BB8EB81CCBF; Mon, 6 Dec 2021 09:34:34 +0000 (UTC) Received: from x1.localdomain.com (unknown [10.39.194.76]) by smtp.corp.redhat.com (Postfix) with ESMTP id 33BEF5DF4E; Mon, 6 Dec 2021 09:34:31 +0000 (UTC) From: Hans de Goede To: "Rafael J . Wysocki" , Mika Westerberg , Mark Gross , Andy Shevchenko , Wolfram Sang , Lee Jones , Sebastian Reichel , MyungJoo Ham , Chanwoo Choi , Ard Biesheuvel Cc: Hans de Goede , Len Brown , linux-acpi@vger.kernel.org, Yauhen Kharuzhy , Tsuchiya Yuto , platform-driver-x86@vger.kernel.org, linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, linux-efi@vger.kernel.org Subject: [PATCH v4 11/20] power: supply: bq25890: On the bq25892 set the IINLIM based on external charger detection Date: Mon, 6 Dec 2021 10:33:09 +0100 Message-Id: <20211206093318.45214-12-hdegoede@redhat.com> In-Reply-To: <20211206093318.45214-1-hdegoede@redhat.com> References: <20211206093318.45214-1-hdegoede@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 Precedence: bulk List-ID: X-Mailing-List: linux-efi@vger.kernel.org The bq25892 does not have builtin charger-type detection like the bq25980, there might be some external charger detection capability, which will be modelled as a power_supply class-device supplying the bq25892. Use the usb_type property value from the supplier psy-device to set the input-current-limit (when available). Signed-off-by: Hans de Goede --- drivers/power/supply/bq25890_charger.c | 33 ++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/drivers/power/supply/bq25890_charger.c b/drivers/power/supply/bq25890_charger.c index 637cdd3b6b11..3de72f0fbf3e 100644 --- a/drivers/power/supply/bq25890_charger.c +++ b/drivers/power/supply/bq25890_charger.c @@ -594,6 +594,38 @@ static int bq25890_power_supply_get_property(struct power_supply *psy, return 0; } +/* On the BQ25892 try to get charger-type info from our supplier */ +static void bq25890_charger_external_power_changed(struct power_supply *psy) +{ + struct bq25890_device *bq = power_supply_get_drvdata(psy); + union power_supply_propval val; + int input_current_limit, ret; + + if (bq->chip_version != BQ25892) + return; + + ret = power_supply_get_property_from_supplier(bq->charger, + POWER_SUPPLY_PROP_USB_TYPE, + &val); + if (ret) + return; + + switch (val.intval) { + case POWER_SUPPLY_USB_TYPE_DCP: + input_current_limit = bq25890_find_idx(2000000, TBL_IINLIM); + break; + case POWER_SUPPLY_USB_TYPE_CDP: + case POWER_SUPPLY_USB_TYPE_ACA: + input_current_limit = bq25890_find_idx(1500000, TBL_IINLIM); + break; + case POWER_SUPPLY_USB_TYPE_SDP: + default: + input_current_limit = bq25890_find_idx(500000, TBL_IINLIM); + } + + bq25890_field_write(bq, F_IINLIM, input_current_limit); +} + static int bq25890_get_chip_state(struct bq25890_device *bq, struct bq25890_state *state) { @@ -818,6 +850,7 @@ static const struct power_supply_desc bq25890_power_supply_desc = { .properties = bq25890_power_supply_props, .num_properties = ARRAY_SIZE(bq25890_power_supply_props), .get_property = bq25890_power_supply_get_property, + .external_power_changed = bq25890_charger_external_power_changed, }; static int bq25890_power_supply_init(struct bq25890_device *bq) From patchwork Mon Dec 6 09:33:11 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans de Goede X-Patchwork-Id: 521058 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 27050C433FE for ; Mon, 6 Dec 2021 09:35:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241122AbhLFJiv (ORCPT ); Mon, 6 Dec 2021 04:38:51 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:47024 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241022AbhLFJim (ORCPT ); Mon, 6 Dec 2021 04:38:42 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1638783313; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=NSFllL0K7X0KVTucBJnSMumxKusMGygWrLDj1HKAn7A=; b=IqwG6v+Z41nswfRU9oACRkVqlAsq32kJblIVJO03zKldDQU2P7eoCF9GafXmCaBq7WO7Ay SQ0d4WKTaEqZybAA0uyqPq1iwJHT7wSVDfeA6oBAPvzDRZl3nFC6hk6i+AbhAz7KuNurrm 45luCs8ezgD5AkKLTjJyQbmjj5qk1PI= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-11-iD-Zz3iNMzav62Xi_GAH_A-1; Mon, 06 Dec 2021 04:35:07 -0500 X-MC-Unique: iD-Zz3iNMzav62Xi_GAH_A-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id EB7C4101F003; Mon, 6 Dec 2021 09:35:04 +0000 (UTC) Received: from x1.localdomain.com (unknown [10.39.194.76]) by smtp.corp.redhat.com (Postfix) with ESMTP id 309E25DF3F; Mon, 6 Dec 2021 09:34:49 +0000 (UTC) From: Hans de Goede To: "Rafael J . Wysocki" , Mika Westerberg , Mark Gross , Andy Shevchenko , Wolfram Sang , Lee Jones , Sebastian Reichel , MyungJoo Ham , Chanwoo Choi , Ard Biesheuvel Cc: Hans de Goede , Len Brown , linux-acpi@vger.kernel.org, Yauhen Kharuzhy , Tsuchiya Yuto , platform-driver-x86@vger.kernel.org, linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, linux-efi@vger.kernel.org Subject: [PATCH v4 13/20] power: supply: bq25890: Use the devm_regmap_field_bulk_alloc() helper Date: Mon, 6 Dec 2021 10:33:11 +0100 Message-Id: <20211206093318.45214-14-hdegoede@redhat.com> In-Reply-To: <20211206093318.45214-1-hdegoede@redhat.com> References: <20211206093318.45214-1-hdegoede@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 Precedence: bulk List-ID: X-Mailing-List: linux-efi@vger.kernel.org Use the devm_regmap_field_bulk_alloc() helper function instead of open-coding this ourselves. Signed-off-by: Hans de Goede --- Changes in v3: - This is a new patch in v3 of this patch-series --- drivers/power/supply/bq25890_charger.c | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/drivers/power/supply/bq25890_charger.c b/drivers/power/supply/bq25890_charger.c index 179abed92f9b..852a6fec4339 100644 --- a/drivers/power/supply/bq25890_charger.c +++ b/drivers/power/supply/bq25890_charger.c @@ -1165,7 +1165,6 @@ static int bq25890_probe(struct i2c_client *client, struct device *dev = &client->dev; struct bq25890_device *bq; int ret; - int i; bq = devm_kzalloc(dev, sizeof(*bq), GFP_KERNEL); if (!bq) @@ -1182,15 +1181,10 @@ static int bq25890_probe(struct i2c_client *client, return dev_err_probe(dev, PTR_ERR(bq->rmap), "failed to allocate register map\n"); - for (i = 0; i < ARRAY_SIZE(bq25890_reg_fields); i++) { - const struct reg_field *reg_fields = bq25890_reg_fields; - - bq->rmap_fields[i] = devm_regmap_field_alloc(dev, bq->rmap, - reg_fields[i]); - if (IS_ERR(bq->rmap_fields[i])) - return dev_err_probe(dev, PTR_ERR(bq->rmap_fields[i]), - "cannot allocate regmap field\n"); - } + ret = devm_regmap_field_bulk_alloc(dev, bq->rmap, bq->rmap_fields, + bq25890_reg_fields, F_MAX_FIELDS); + if (ret) + return ret; i2c_set_clientdata(client, bq); From patchwork Mon Dec 6 09:33:13 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans de Goede X-Patchwork-Id: 521057 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 85B9DC433EF for ; Mon, 6 Dec 2021 09:35:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240938AbhLFJi6 (ORCPT ); Mon, 6 Dec 2021 04:38:58 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:45825 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241082AbhLFJit (ORCPT ); Mon, 6 Dec 2021 04:38:49 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1638783320; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=JmrPouzyJORqeW8YegyrXzTKKZke8QnXRejNnVcuGaU=; b=afp3LQnSgXHqvLO11EunmBsXq3AfC/Eo//CA9CYegyNcZinv6HhTkpUVUMvQ3IburlUas2 TNPDoejc7e7OfAxwWVD5x7TtpA76eA503VEWMjzERNof5fdycwpdkYz2hO2q4Poo9540lu D8aJ8Xk/T2ywCHj7M16VN9k3EyEBxtw= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-387-ixnkZxx4MDuXoKK2BKFoSQ-1; Mon, 06 Dec 2021 04:35:15 -0500 X-MC-Unique: ixnkZxx4MDuXoKK2BKFoSQ-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id AFAD9185302C; Mon, 6 Dec 2021 09:35:12 +0000 (UTC) Received: from x1.localdomain.com (unknown [10.39.194.76]) by smtp.corp.redhat.com (Postfix) with ESMTP id 130A14EC37; Mon, 6 Dec 2021 09:35:08 +0000 (UTC) From: Hans de Goede To: "Rafael J . Wysocki" , Mika Westerberg , Mark Gross , Andy Shevchenko , Wolfram Sang , Lee Jones , Sebastian Reichel , MyungJoo Ham , Chanwoo Choi , Ard Biesheuvel Cc: Hans de Goede , Len Brown , linux-acpi@vger.kernel.org, Yauhen Kharuzhy , Tsuchiya Yuto , platform-driver-x86@vger.kernel.org, linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, linux-efi@vger.kernel.org, Wolfram Sang Subject: [PATCH v4 15/20] i2c: cht-wc: Make charger i2c-client instantiation board/device-model specific Date: Mon, 6 Dec 2021 10:33:13 +0100 Message-Id: <20211206093318.45214-16-hdegoede@redhat.com> In-Reply-To: <20211206093318.45214-1-hdegoede@redhat.com> References: <20211206093318.45214-1-hdegoede@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 Precedence: bulk List-ID: X-Mailing-List: linux-efi@vger.kernel.org The i2c-controller on the Cherry Trail - Whiskey Cove PMIC is special in that it is always connected to the I2C charger IC of the board on which the PMIC is used; and the charger IC is not described in ACPI, so the i2c-cht-wc code needs to instantiate an i2c-client for it itself. So far this was hardcoded to instantiate an i2c-client for the bq24292i, with all properties, etc. set to match how this charger is used on the GPD win and GPD pocket devices. There is a rudimentary check to make sure the ACPI tables are at least somewhat as expected, but this is far from accurate, leading to a wrong i2c-client being instantiated for the charger on some boards. Switch to the new DMI based intel_cht_wc_get_model() helper which is exported by the MFD driver for the CHT Whiskey Cove PMIC to help PMIC cell drivers like the i2c-cht-wc code reliably detect which board they are running on. And add board_info for the charger ICs as found on the other 2 known boards with a Whisky Cove PMIC. This has been tested on all 3 known boards. Acked-by: Wolfram Sang Signed-off-by: Hans de Goede --- Changes in v3: - Add Wolfram's Ack for taking this upstream through another tree then the i2c tree - Some minor tweaks / spelling fixes based on Andy's review --- drivers/i2c/busses/i2c-cht-wc.c | 120 +++++++++++++++++++++++++++----- 1 file changed, 102 insertions(+), 18 deletions(-) diff --git a/drivers/i2c/busses/i2c-cht-wc.c b/drivers/i2c/busses/i2c-cht-wc.c index 1cf68f85b2e1..54e909f9eab6 100644 --- a/drivers/i2c/busses/i2c-cht-wc.c +++ b/drivers/i2c/busses/i2c-cht-wc.c @@ -18,6 +18,7 @@ #include #include #include +#include #include #define CHT_WC_I2C_CTRL 0x5e24 @@ -270,6 +271,7 @@ static const struct irq_chip cht_wc_i2c_irq_chip = { .name = "cht_wc_ext_chrg_irq_chip", }; +/********** GPD Win / Pocket charger IC settings **********/ static const char * const bq24190_suppliers[] = { "tcpm-source-psy-i2c-fusb302" }; @@ -304,17 +306,92 @@ static struct bq24190_platform_data bq24190_pdata = { .regulator_init_data = &bq24190_vbus_init_data, }; +static struct i2c_board_info gpd_win_board_info = { + .type = "bq24190", + .addr = 0x6b, + .dev_name = "bq24190", + .swnode = &bq24190_node, + .platform_data = &bq24190_pdata, +}; + +/********** Xiaomi Mi Pad 2 charger IC settings **********/ +static struct regulator_consumer_supply bq2589x_vbus_consumer = { + .supply = "vbus", + .dev_name = "cht_wcove_pwrsrc", +}; + +static const struct regulator_init_data bq2589x_vbus_init_data = { + .constraints = { + .valid_ops_mask = REGULATOR_CHANGE_STATUS, + }, + .consumer_supplies = &bq2589x_vbus_consumer, + .num_consumer_supplies = 1, +}; + +static struct bq25890_platform_data bq2589x_pdata = { + .regulator_init_data = &bq2589x_vbus_init_data, +}; + +static const struct property_entry xiaomi_mipad2_props[] = { + PROPERTY_ENTRY_BOOL("linux,skip-reset"), + PROPERTY_ENTRY_BOOL("linux,read-back-settings"), + { } +}; + +static const struct software_node xiaomi_mipad2_node = { + .properties = xiaomi_mipad2_props, +}; + +static struct i2c_board_info xiaomi_mipad2_board_info = { + .type = "bq25890", + .addr = 0x6a, + .dev_name = "bq25890", + .swnode = &xiaomi_mipad2_node, + .platform_data = &bq2589x_pdata, +}; + +/********** Lenovo Yogabook YB1-X90F/-X91F/-X91L charger settings **********/ +static const char * const lenovo_yb1_bq25892_suppliers[] = { "cht_wcove_pwrsrc" }; + +static const struct property_entry lenovo_yb1_bq25892_props[] = { + PROPERTY_ENTRY_STRING_ARRAY("supplied-from", + lenovo_yb1_bq25892_suppliers), + PROPERTY_ENTRY_U32("linux,pump-express-vbus-max", 12000000), + PROPERTY_ENTRY_BOOL("linux,skip-reset"), + /* + * The firmware sets everything to the defaults, which leads to a + * somewhat low charge-current of 2048mA and worse to a battery-voltage + * of 4.2V instead of 4.35V (when booted without a charger connected). + * Use our own values instead of "linux,read-back-settings" to fix this. + */ + PROPERTY_ENTRY_U32("ti,charge-current", 4224000), + PROPERTY_ENTRY_U32("ti,battery-regulation-voltage", 4352000), + PROPERTY_ENTRY_U32("ti,termination-current", 256000), + PROPERTY_ENTRY_U32("ti,precharge-current", 128000), + PROPERTY_ENTRY_U32("ti,minimum-sys-voltage", 3500000), + PROPERTY_ENTRY_U32("ti,boost-voltage", 4998000), + PROPERTY_ENTRY_U32("ti,boost-max-current", 1400000), + PROPERTY_ENTRY_BOOL("ti,use-ilim-pin"), + { } +}; + +static const struct software_node lenovo_yb1_bq25892_node = { + .properties = lenovo_yb1_bq25892_props, +}; + +static struct i2c_board_info lenovo_yogabook1_board_info = { + .type = "bq25892", + .addr = 0x6b, + .dev_name = "bq25892", + .swnode = &lenovo_yb1_bq25892_node, + .platform_data = &bq2589x_pdata, +}; + static int cht_wc_i2c_adap_i2c_probe(struct platform_device *pdev) { struct intel_soc_pmic *pmic = dev_get_drvdata(pdev->dev.parent); + struct i2c_board_info *board_info = NULL; struct cht_wc_i2c_adap *adap; - struct i2c_board_info board_info = { - .type = "bq24190", - .addr = 0x6b, - .dev_name = "bq24190", - .swnode = &bq24190_node, - .platform_data = &bq24190_pdata, - }; int ret, reg, irq; irq = platform_get_irq(pdev, 0); @@ -379,17 +456,24 @@ static int cht_wc_i2c_adap_i2c_probe(struct platform_device *pdev) if (ret) goto remove_irq_domain; - /* - * Normally the Whiskey Cove PMIC is paired with a TI bq24292i charger, - * connected to this i2c bus, and a max17047 fuel-gauge and a fusb302 - * USB Type-C controller connected to another i2c bus. In this setup - * the max17047 and fusb302 devices are enumerated through an INT33FE - * ACPI device. If this device is present register an i2c-client for - * the TI bq24292i charger. - */ - if (acpi_dev_present("INT33FE", NULL, -1)) { - board_info.irq = adap->client_irq; - adap->client = i2c_new_client_device(&adap->adapter, &board_info); + switch (pmic->cht_wc_model) { + case INTEL_CHT_WC_GPD_WIN_POCKET: + board_info = &gpd_win_board_info; + break; + case INTEL_CHT_WC_XIAOMI_MIPAD2: + board_info = &xiaomi_mipad2_board_info; + break; + case INTEL_CHT_WC_LENOVO_YOGABOOK1: + board_info = &lenovo_yogabook1_board_info; + break; + default: + dev_warn(&pdev->dev, "Unknown model, not instantiating charger device\n"); + break; + } + + if (board_info) { + board_info->irq = adap->client_irq; + adap->client = i2c_new_client_device(&adap->adapter, board_info); if (IS_ERR(adap->client)) { ret = PTR_ERR(adap->client); goto del_adapter; From patchwork Mon Dec 6 09:33:16 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans de Goede X-Patchwork-Id: 521056 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5A9B3C433EF for ; Mon, 6 Dec 2021 09:35:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240981AbhLFJjQ (ORCPT ); Mon, 6 Dec 2021 04:39:16 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:49315 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241295AbhLFJjB (ORCPT ); Mon, 6 Dec 2021 04:39:01 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1638783333; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=rJq6tqdBzpqmFgoJbA6IQF9RYULArc1usxXeNF9a/yU=; b=fKOrAcMoV7c/csPUkHhZhPTaPNPyGGqI6L+VdJ7EMfLAyiFWf54A9fKTZCTUzKOI1B8xN7 ybtiUZW3UQ/tvtnyokLIWo1n0SbDH2myfHmnMEbFbAsYXYlVCSD9oq1FCQ7s9uPIVWNReL ey47h5CklzTeF0kUWNGku+zeCBdMx9k= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-233-t2uypRz8MZqtnSTG4Z8T7w-1; Mon, 06 Dec 2021 04:35:30 -0500 X-MC-Unique: t2uypRz8MZqtnSTG4Z8T7w-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 0BD0310144E9; Mon, 6 Dec 2021 09:35:24 +0000 (UTC) Received: from x1.localdomain.com (unknown [10.39.194.76]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8A0EC5E272; Mon, 6 Dec 2021 09:35:20 +0000 (UTC) From: Hans de Goede To: "Rafael J . Wysocki" , Mika Westerberg , Mark Gross , Andy Shevchenko , Wolfram Sang , Lee Jones , Sebastian Reichel , MyungJoo Ham , Chanwoo Choi , Ard Biesheuvel Cc: Hans de Goede , Len Brown , linux-acpi@vger.kernel.org, Yauhen Kharuzhy , Tsuchiya Yuto , platform-driver-x86@vger.kernel.org, linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, linux-efi@vger.kernel.org Subject: [PATCH v4 18/20] extcon: intel-cht-wc: Refactor cht_wc_extcon_get_charger() Date: Mon, 6 Dec 2021 10:33:16 +0100 Message-Id: <20211206093318.45214-19-hdegoede@redhat.com> In-Reply-To: <20211206093318.45214-1-hdegoede@redhat.com> References: <20211206093318.45214-1-hdegoede@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 Precedence: bulk List-ID: X-Mailing-List: linux-efi@vger.kernel.org This is a preparation patch for adding support for registering a power_supply class device. Setting usbsrc to "CHT_WC_USBSRC_TYPE_SDP << CHT_WC_USBSRC_TYPE_SHIFT" will make the following switch-case return EXTCON_CHG_USB_SDP just as before, so there is no functional change. Signed-off-by: Hans de Goede Acked-by: Chanwoo Choi --- Changes in v3: - Reword the commit message --- drivers/extcon/extcon-intel-cht-wc.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/drivers/extcon/extcon-intel-cht-wc.c b/drivers/extcon/extcon-intel-cht-wc.c index edc386937dee..150637bea417 100644 --- a/drivers/extcon/extcon-intel-cht-wc.c +++ b/drivers/extcon/extcon-intel-cht-wc.c @@ -153,14 +153,15 @@ static int cht_wc_extcon_get_charger(struct cht_wc_extcon_data *ext, } while (time_before(jiffies, timeout)); if (status != CHT_WC_USBSRC_STS_SUCCESS) { - if (ignore_errors) - return EXTCON_CHG_USB_SDP; /* Save fallback */ + if (!ignore_errors) { + if (status == CHT_WC_USBSRC_STS_FAIL) + dev_warn(ext->dev, "Could not detect charger type\n"); + else + dev_warn(ext->dev, "Timeout detecting charger type\n"); + } - if (status == CHT_WC_USBSRC_STS_FAIL) - dev_warn(ext->dev, "Could not detect charger type\n"); - else - dev_warn(ext->dev, "Timeout detecting charger type\n"); - return EXTCON_CHG_USB_SDP; /* Save fallback */ + /* Save fallback */ + usbsrc = CHT_WC_USBSRC_TYPE_SDP << CHT_WC_USBSRC_TYPE_SHIFT; } usbsrc = (usbsrc & CHT_WC_USBSRC_TYPE_MASK) >> CHT_WC_USBSRC_TYPE_SHIFT; From patchwork Mon Dec 6 09:33:18 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans de Goede X-Patchwork-Id: 521055 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id CB859C433FE for ; Mon, 6 Dec 2021 09:35:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241114AbhLFJjT (ORCPT ); Mon, 6 Dec 2021 04:39:19 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:36646 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241349AbhLFJjE (ORCPT ); Mon, 6 Dec 2021 04:39:04 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1638783336; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=UJ60w9l5x9z7ezkDeL8gMwQfAMNkzdnrdHE2RsyKQDs=; b=E9v+HzkfYAQrOroHo4geNmshbByKZj4BbChoLtLYhz0zstqJU7DdjarofCZbFfju7zVrbb 40SrLzMjW3kesv6+50wfQ/3UAUfs916qfSj2Keu1xeLZzvupZA9d785m/fJ27+doP1bhEz Sw5u7m8dJcObhg9ANYcRTTFwGFd9ga4= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-215-wAupVm9qOCuQ-sKq7nCHaA-1; Mon, 06 Dec 2021 04:35:34 -0500 X-MC-Unique: wAupVm9qOCuQ-sKq7nCHaA-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 9E585835B47; Mon, 6 Dec 2021 09:35:31 +0000 (UTC) Received: from x1.localdomain.com (unknown [10.39.194.76]) by smtp.corp.redhat.com (Postfix) with ESMTP id 184D75DAA5; Mon, 6 Dec 2021 09:35:27 +0000 (UTC) From: Hans de Goede To: "Rafael J . Wysocki" , Mika Westerberg , Mark Gross , Andy Shevchenko , Wolfram Sang , Lee Jones , Sebastian Reichel , MyungJoo Ham , Chanwoo Choi , Ard Biesheuvel Cc: Hans de Goede , Len Brown , linux-acpi@vger.kernel.org, Yauhen Kharuzhy , Tsuchiya Yuto , platform-driver-x86@vger.kernel.org, linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, linux-efi@vger.kernel.org Subject: [PATCH v4 20/20] extcon: intel-cht-wc: Report RID_A for ACA adapters Date: Mon, 6 Dec 2021 10:33:18 +0100 Message-Id: <20211206093318.45214-21-hdegoede@redhat.com> In-Reply-To: <20211206093318.45214-1-hdegoede@redhat.com> References: <20211206093318.45214-1-hdegoede@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 Precedence: bulk List-ID: X-Mailing-List: linux-efi@vger.kernel.org Make cht_wc_extcon_get_id() report RID_A for ACA adapters, instead of reporting ID_FLOAT. According to the spec. we should read the USB-ID pin ADC value to determine the resistance of the used pull-down resister and then return RID_A / RID_B / RID_C based on this. But all "Accessory Charger Adapter"s (ACAs) which users can actually buy always use a combination of a charging port with one or more USB-A ports, so they should always use a resistor indicating RID_A. But the spec is hard to read / badly-worded so some of them actually indicate they are a RID_B ACA even though they clearly are a RID_A ACA. To workaround this simply always return INTEL_USB_RID_A, which matches all the ACAs which users can actually buy. Signed-off-by: Hans de Goede Acked-by: Chanwoo Choi --- drivers/extcon/extcon-intel-cht-wc.c | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/drivers/extcon/extcon-intel-cht-wc.c b/drivers/extcon/extcon-intel-cht-wc.c index 144cb5d8cd47..2a8d41cbf41c 100644 --- a/drivers/extcon/extcon-intel-cht-wc.c +++ b/drivers/extcon/extcon-intel-cht-wc.c @@ -121,13 +121,21 @@ static int cht_wc_extcon_get_id(struct cht_wc_extcon_data *ext, int pwrsrc_sts) return INTEL_USB_ID_GND; case CHT_WC_PWRSRC_RID_FLOAT: return INTEL_USB_ID_FLOAT; + /* + * According to the spec. we should read the USB-ID pin ADC value here + * to determine the resistance of the used pull-down resister and then + * return RID_A / RID_B / RID_C based on this. But all "Accessory + * Charger Adapter"s (ACAs) which users can actually buy always use + * a combination of a charging port with one or more USB-A ports, so + * they should always use a resistor indicating RID_A. But the spec + * is hard to read / badly-worded so some of them actually indicate + * they are a RID_B ACA evnen though they clearly are a RID_A ACA. + * To workaround this simply always return INTEL_USB_RID_A, which + * matches all the ACAs which users can actually buy. + */ case CHT_WC_PWRSRC_RID_ACA: + return INTEL_USB_RID_A; default: - /* - * Once we have IIO support for the GPADC we should read - * the USBID GPADC channel here and determine ACA role - * based on that. - */ return INTEL_USB_ID_FLOAT; } }