From patchwork Sun Nov 14 17:03: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: 1554871 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=ScubVLsF; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=linux-i2c-owner@vger.kernel.org; receiver=) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by bilbo.ozlabs.org (Postfix) with ESMTP id 4Hsdvk6XbKz9sWJ for ; Mon, 15 Nov 2021 04:04:02 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236075AbhKNRGu (ORCPT ); Sun, 14 Nov 2021 12:06:50 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:32515 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236127AbhKNRGo (ORCPT ); Sun, 14 Nov 2021 12:06:44 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1636909430; 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=eg2H4G7V9ZNmK2Jp+bEJQsTlWgnhn2mX1SomKvQeFUk=; b=ScubVLsFyBns2CtK7IJtuRfA9h+iunieXubf8DHnr2pMtKLGCMSX1QuibNe4Mo4mJep5rP M7lYcTu6CcHP8MVjWZhOvZm7EL4+vDdm4YaXP9S/1xGt3jjH2p5728TiwyaM5Ta5ZfYJ1B FgMPOVgmQYqc+5mp+X9ZZasUdXVHX5g= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-595-5s0RtsNYPR6fllyd9xOyOQ-1; Sun, 14 Nov 2021 12:03:46 -0500 X-MC-Unique: 5s0RtsNYPR6fllyd9xOyOQ-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 33504102CB34; Sun, 14 Nov 2021 17:03:44 +0000 (UTC) Received: from x1.localdomain (unknown [10.39.192.93]) by smtp.corp.redhat.com (Postfix) with ESMTP id A389F1346F; Sun, 14 Nov 2021 17:03:40 +0000 (UTC) From: Hans de Goede To: "Rafael J . Wysocki" , Mika Westerberg , Mark Gross , Andy Shevchenko , Wolfram Sang , 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-i2c@vger.kernel.org, linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, linux-efi@vger.kernel.org Subject: [PATCH v2 01/20] power: supply: core: Refactor power_supply_set_input_current_limit_from_supplier() Date: Sun, 14 Nov 2021 18:03:16 +0100 Message-Id: <20211114170335.66994-2-hdegoede@redhat.com> In-Reply-To: <20211114170335.66994-1-hdegoede@redhat.com> References: <20211114170335.66994-1-hdegoede@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 Precedence: bulk List-ID: X-Mailing-List: linux-i2c@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 Sun Nov 14 17:03:17 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: 1554872 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=cZNwU1wH; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=linux-i2c-owner@vger.kernel.org; receiver=) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by bilbo.ozlabs.org (Postfix) with ESMTP id 4Hsdvp4qkMz9sWJ for ; Mon, 15 Nov 2021 04:04:06 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236127AbhKNRGx (ORCPT ); Sun, 14 Nov 2021 12:06:53 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:46567 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236164AbhKNRGr (ORCPT ); Sun, 14 Nov 2021 12:06:47 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1636909433; 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=bTWy3HJQpYvzRyfsaErdnWf1xMgihw+VSeibJZSjgWk=; b=cZNwU1wHv5AqO0Tg/6RWdm41NCEOX5yGSPVkEYG0lJ3HCyYxli89lVOXGhGjNZV8Kxiz8l hrPjjWcliIbz1kAzghVRGC+G6Hp97QN0pFFfam6cw1caY4jL5LnYQseaDRQcNB76muZa90 R7HvRkfGiaKFskNKa4TT/aOH+BTMwIU= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-196-NxFz69XDPFm8PsfKvwWukw-1; Sun, 14 Nov 2021 12:03:50 -0500 X-MC-Unique: NxFz69XDPFm8PsfKvwWukw-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id E8E7A802E65; Sun, 14 Nov 2021 17:03:47 +0000 (UTC) Received: from x1.localdomain (unknown [10.39.192.93]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7C2741346F; Sun, 14 Nov 2021 17:03:44 +0000 (UTC) From: Hans de Goede To: "Rafael J . Wysocki" , Mika Westerberg , Mark Gross , Andy Shevchenko , Wolfram Sang , 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-i2c@vger.kernel.org, linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, linux-efi@vger.kernel.org Subject: [PATCH v2 02/20] power: supply: bq25890: Fix ADC continuous conversion setting when charging Date: Sun, 14 Nov 2021 18:03:17 +0100 Message-Id: <20211114170335.66994-3-hdegoede@redhat.com> In-Reply-To: <20211114170335.66994-1-hdegoede@redhat.com> References: <20211114170335.66994-1-hdegoede@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 Precedence: bulk List-ID: X-Mailing-List: linux-i2c@vger.kernel.org From: Yauhen Kharuzhy Instead of one shot run of ADC at beginning of charging, run continuous conversion to ensure that all charging-related values are monitored properly (input voltage, input current, themperature etc.). Fixes: 4aeae9cb0dad ("power_supply: Add support for TI BQ25890 charger chip") Signed-off-by: Yauhen Kharuzhy Reviewed-by: Hans de Goede Signed-off-by: Hans de Goede --- drivers/power/supply/bq25890_charger.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/power/supply/bq25890_charger.c b/drivers/power/supply/bq25890_charger.c index 34ec186a2e9a..b7eac5428083 100644 --- a/drivers/power/supply/bq25890_charger.c +++ b/drivers/power/supply/bq25890_charger.c @@ -581,12 +581,12 @@ static irqreturn_t __bq25890_handle_irq(struct bq25890_device *bq) if (!new_state.online && bq->state.online) { /* power removed */ /* disable ADC */ - ret = bq25890_field_write(bq, F_CONV_START, 0); + ret = bq25890_field_write(bq, F_CONV_RATE, 0); if (ret < 0) goto error; } else if (new_state.online && !bq->state.online) { /* power inserted */ /* enable ADC, to have control of charge current/voltage */ - ret = bq25890_field_write(bq, F_CONV_START, 1); + ret = bq25890_field_write(bq, F_CONV_RATE, 1); if (ret < 0) goto error; } From patchwork Sun Nov 14 17:03: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: 1554873 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=ahoOMvEr; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=linux-i2c-owner@vger.kernel.org; receiver=) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by bilbo.ozlabs.org (Postfix) with ESMTP id 4Hsdvx47Qfz9sWJ for ; Mon, 15 Nov 2021 04:04:13 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236209AbhKNRHB (ORCPT ); Sun, 14 Nov 2021 12:07:01 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:41709 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236180AbhKNRGw (ORCPT ); Sun, 14 Nov 2021 12:06:52 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1636909437; 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=6OsrSqIS8dRf7JRKcuWamIO8LFYSgkzTf71ZkiaHlxY=; b=ahoOMvErycTIcuZgD/yqL1cSNE8B51GdTbkNnGk3vSJeTIvxAqiC2LitSp4hLJi57x1vCJ DLs3kIjejsf3LDXnPA0CajoQtpIEoNK/KH+IeeT62NgxwpK5dPz82PpBgSfGaVXYaMoKKt 5sEBJsNBxdKUN0BDtcb/qupsi195AVI= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-311-1pxDy5bLNS6uSzOaqv-_Aw-1; Sun, 14 Nov 2021 12:03:54 -0500 X-MC-Unique: 1pxDy5bLNS6uSzOaqv-_Aw-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id C6F1D802B7A; Sun, 14 Nov 2021 17:03:51 +0000 (UTC) Received: from x1.localdomain (unknown [10.39.192.93]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3D1A61346F; Sun, 14 Nov 2021 17:03:48 +0000 (UTC) From: Hans de Goede To: "Rafael J . Wysocki" , Mika Westerberg , Mark Gross , Andy Shevchenko , Wolfram Sang , 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-i2c@vger.kernel.org, linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, linux-efi@vger.kernel.org Subject: [PATCH v2 03/20] power: supply: bq25890: Rename IILIM field to IINLIM Date: Sun, 14 Nov 2021 18:03:18 +0100 Message-Id: <20211114170335.66994-4-hdegoede@redhat.com> In-Reply-To: <20211114170335.66994-1-hdegoede@redhat.com> References: <20211114170335.66994-1-hdegoede@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 Precedence: bulk List-ID: X-Mailing-List: linux-i2c@vger.kernel.org From: Yauhen Kharuzhy Rename the Input Current Limit field in the REG00 from IILIM to IINLIM accordingly with the bq2589x datasheet. This is just cosmetical change to reduce confusion. Signed-off-by: Yauhen Kharuzhy Reviewed-by: Hans de Goede Signed-off-by: Hans de Goede --- drivers/power/supply/bq25890_charger.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/drivers/power/supply/bq25890_charger.c b/drivers/power/supply/bq25890_charger.c index b7eac5428083..b208cc2193b8 100644 --- a/drivers/power/supply/bq25890_charger.c +++ b/drivers/power/supply/bq25890_charger.c @@ -40,7 +40,7 @@ static const char *const bq25890_chip_name[] = { }; enum bq25890_fields { - F_EN_HIZ, F_EN_ILIM, F_IILIM, /* Reg00 */ + F_EN_HIZ, F_EN_ILIM, F_IINLIM, /* Reg00 */ F_BHOT, F_BCOLD, F_VINDPM_OFS, /* Reg01 */ F_CONV_START, F_CONV_RATE, F_BOOSTF, F_ICO_EN, F_HVDCP_EN, F_MAXC_EN, F_FORCE_DPM, F_AUTO_DPDM_EN, /* Reg02 */ @@ -153,7 +153,7 @@ static const struct reg_field bq25890_reg_fields[] = { /* REG00 */ [F_EN_HIZ] = REG_FIELD(0x00, 7, 7), [F_EN_ILIM] = REG_FIELD(0x00, 6, 6), - [F_IILIM] = REG_FIELD(0x00, 0, 5), + [F_IINLIM] = REG_FIELD(0x00, 0, 5), /* REG01 */ [F_BHOT] = REG_FIELD(0x01, 6, 7), [F_BCOLD] = REG_FIELD(0x01, 5, 5), @@ -256,7 +256,7 @@ enum bq25890_table_ids { /* range tables */ TBL_ICHG, TBL_ITERM, - TBL_IILIM, + TBL_IINLIM, TBL_VREG, TBL_BOOSTV, TBL_SYSVMIN, @@ -299,7 +299,7 @@ static const union { /* TODO: BQ25896 has max ICHG 3008 mA */ [TBL_ICHG] = { .rt = {0, 5056000, 64000} }, /* uA */ [TBL_ITERM] = { .rt = {64000, 1024000, 64000} }, /* uA */ - [TBL_IILIM] = { .rt = {100000, 3250000, 50000} }, /* uA */ + [TBL_IINLIM] = { .rt = {100000, 3250000, 50000} }, /* uA */ [TBL_VREG] = { .rt = {3840000, 4608000, 16000} }, /* uV */ [TBL_BOOSTV] = { .rt = {4550000, 5510000, 64000} }, /* uV */ [TBL_SYSVMIN] = { .rt = {3000000, 3700000, 100000} }, /* uV */ @@ -503,11 +503,11 @@ static int bq25890_power_supply_get_property(struct power_supply *psy, break; case POWER_SUPPLY_PROP_INPUT_CURRENT_LIMIT: - ret = bq25890_field_read(bq, F_IILIM); + ret = bq25890_field_read(bq, F_IINLIM); if (ret < 0) return ret; - val->intval = bq25890_find_val(ret, TBL_IILIM); + val->intval = bq25890_find_val(ret, TBL_IINLIM); break; case POWER_SUPPLY_PROP_VOLTAGE_NOW: From patchwork Sun Nov 14 17:03:19 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: 1554877 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=a3TvO5Ed; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=linux-i2c-owner@vger.kernel.org; receiver=) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by bilbo.ozlabs.org (Postfix) with ESMTP id 4Hsdwf6l4gz9sWJ for ; Mon, 15 Nov 2021 04:04:50 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236206AbhKNRHn (ORCPT ); Sun, 14 Nov 2021 12:07:43 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:46261 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236187AbhKNRGz (ORCPT ); Sun, 14 Nov 2021 12:06:55 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1636909441; 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=FfVMrmBQBfsg/z794ziYgV346QpjZYdALcF2KlNGNYI=; b=a3TvO5Ed2oRO4Yjwi8K+VHDzIdUGTN+D+QFsuSMSlTufKd8z+JAz8er4qU1qaawF/eKmHt qVLfLw2/X66D+qA20DT4BhMyLIQk2lfTHFJuwJjck6E0/7fDo9dmnnZMpt8FtCu7bQUAUQ VRlfSUxn98TJ8JJx0SwjY6taoSbG+H4= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-312-MpC3RtzdPF6YFM1zYo7_4w-1; Sun, 14 Nov 2021 12:03:57 -0500 X-MC-Unique: MpC3RtzdPF6YFM1zYo7_4w-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 7C38C15722; Sun, 14 Nov 2021 17:03:55 +0000 (UTC) Received: from x1.localdomain (unknown [10.39.192.93]) by smtp.corp.redhat.com (Postfix) with ESMTP id 15B441346F; Sun, 14 Nov 2021 17:03:51 +0000 (UTC) From: Hans de Goede To: "Rafael J . Wysocki" , Mika Westerberg , Mark Gross , Andy Shevchenko , Wolfram Sang , 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-i2c@vger.kernel.org, linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, linux-efi@vger.kernel.org Subject: [PATCH v2 04/20] power: supply: bq25890: Reduce reported CONSTANT_CHARGE_CURRENT_MAX for low temperatures Date: Sun, 14 Nov 2021 18:03:19 +0100 Message-Id: <20211114170335.66994-5-hdegoede@redhat.com> In-Reply-To: <20211114170335.66994-1-hdegoede@redhat.com> References: <20211114170335.66994-1-hdegoede@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 Precedence: bulk List-ID: X-Mailing-List: linux-i2c@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 Signed-off-by: Hans de Goede --- drivers/power/supply/bq25890_charger.c | 33 +++++++++++++++++++++++--- 1 file changed, 30 insertions(+), 3 deletions(-) diff --git a/drivers/power/supply/bq25890_charger.c b/drivers/power/supply/bq25890_charger.c index b208cc2193b8..617a653221ab 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 { @@ -383,6 +384,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) { @@ -474,6 +483,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: @@ -486,6 +507,10 @@ static int bq25890_power_supply_get_property(struct power_supply *psy, if (ret < 0) return ret; + ret = bq25890_field_read(bq, F_JEITA_VSET); + if (ret < 0) + return ret; + /* converted_val = 2.304V + ADC_val * 20mV (table 10.3.15) */ val->intval = 2304000 + ret * 20000; break; @@ -549,7 +574,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++) { @@ -560,9 +586,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 Sun Nov 14 17:03:20 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: 1554876 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=iddJ1v1F; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=linux-i2c-owner@vger.kernel.org; receiver=) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by bilbo.ozlabs.org (Postfix) with ESMTP id 4Hsdwf1Nh6z9sX3 for ; Mon, 15 Nov 2021 04:04:50 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236203AbhKNRHm (ORCPT ); Sun, 14 Nov 2021 12:07:42 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:51632 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236202AbhKNRG7 (ORCPT ); Sun, 14 Nov 2021 12:06:59 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1636909444; 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=ucF228jFI8hX14C5XbTWy8Mnb7M46z5j9PY+ksDxCRY=; b=iddJ1v1FDGpD55lcLoljRmeeT7ZVECjWc3lYJQrPzrsqx4ZVwd51WEr6zlbYq7vvQI2EFO WtKImqYPeYrGakGm/QrALF/DRsshXdDYC+DhAUdJ/ysQYsvYodfWHGx8YaUo788WK0Kek+ kjLW2b9OmnFkFM45y7tmWCIH438/nfs= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-458--14cuePZOXCrPuth4CaN8Q-1; Sun, 14 Nov 2021 12:04:01 -0500 X-MC-Unique: -14cuePZOXCrPuth4CaN8Q-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 387C3102CB29; Sun, 14 Nov 2021 17:03:59 +0000 (UTC) Received: from x1.localdomain (unknown [10.39.192.93]) by smtp.corp.redhat.com (Postfix) with ESMTP id C3C0C19EF9; Sun, 14 Nov 2021 17:03:55 +0000 (UTC) From: Hans de Goede To: "Rafael J . Wysocki" , Mika Westerberg , Mark Gross , Andy Shevchenko , Wolfram Sang , 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-i2c@vger.kernel.org, linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, linux-efi@vger.kernel.org Subject: [PATCH v2 05/20] power: supply: bq25890: Add a bq25890_rw_init_data() helper Date: Sun, 14 Nov 2021 18:03:20 +0100 Message-Id: <20211114170335.66994-6-hdegoede@redhat.com> In-Reply-To: <20211114170335.66994-1-hdegoede@redhat.com> References: <20211114170335.66994-1-hdegoede@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 Precedence: bulk List-ID: X-Mailing-List: linux-i2c@vger.kernel.org On most X86/ACPI devices there is no devicetree to supply the necessary init-data. Instead the firmware already fully initializes the bq25890 charger at boot. Factor out the current code to write all the init_data from devicetree into a new bq25890_rw_init_data() helper which can both write the data to the charger (the current behavior) as well as read it back from the charger into the init_data struct. This is a preparation patch for adding support for X86/ACPI device's where the init_data must be read back from the bq25890 charger. Signed-off-by: Hans de Goede --- drivers/power/supply/bq25890_charger.c | 62 +++++++++++++++++--------- 1 file changed, 40 insertions(+), 22 deletions(-) diff --git a/drivers/power/supply/bq25890_charger.c b/drivers/power/supply/bq25890_charger.c index 617a653221ab..704cc15b4403 100644 --- a/drivers/power/supply/bq25890_charger.c +++ b/drivers/power/supply/bq25890_charger.c @@ -663,29 +663,52 @@ static int bq25890_chip_reset(struct bq25890_device *bq) return 0; } -static int bq25890_hw_init(struct bq25890_device *bq) +static int bq25890_rw_init_data(struct bq25890_device *bq) { + bool write = true; int ret; int i; const struct { enum bq25890_fields id; - u32 value; + u8 *value; } init_data[] = { - {F_ICHG, bq->init_data.ichg}, - {F_VREG, bq->init_data.vreg}, - {F_ITERM, bq->init_data.iterm}, - {F_IPRECHG, bq->init_data.iprechg}, - {F_SYSVMIN, bq->init_data.sysvmin}, - {F_BOOSTV, bq->init_data.boostv}, - {F_BOOSTI, bq->init_data.boosti}, - {F_BOOSTF, bq->init_data.boostf}, - {F_EN_ILIM, bq->init_data.ilim_en}, - {F_TREG, bq->init_data.treg}, - {F_BATCMP, bq->init_data.rbatcomp}, - {F_VCLAMP, bq->init_data.vclamp}, + {F_ICHG, &bq->init_data.ichg}, + {F_VREG, &bq->init_data.vreg}, + {F_ITERM, &bq->init_data.iterm}, + {F_IPRECHG, &bq->init_data.iprechg}, + {F_SYSVMIN, &bq->init_data.sysvmin}, + {F_BOOSTV, &bq->init_data.boostv}, + {F_BOOSTI, &bq->init_data.boosti}, + {F_BOOSTF, &bq->init_data.boostf}, + {F_EN_ILIM, &bq->init_data.ilim_en}, + {F_TREG, &bq->init_data.treg}, + {F_BATCMP, &bq->init_data.rbatcomp}, + {F_VCLAMP, &bq->init_data.vclamp}, }; + for (i = 0; i < ARRAY_SIZE(init_data); i++) { + if (write) { + ret = bq25890_field_write(bq, init_data[i].id, + *init_data[i].value); + } else { + ret = bq25890_field_read(bq, init_data[i].id); + if (ret >= 0) + *init_data[i].value = ret; + } + if (ret < 0) { + dev_dbg(bq->dev, "Accessing init data failed %d\n", ret); + return ret; + } + } + + return 0; +} + +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); @@ -700,14 +723,9 @@ static int bq25890_hw_init(struct bq25890_device *bq) } /* initialize currents/voltages and other parameters */ - for (i = 0; i < ARRAY_SIZE(init_data); i++) { - ret = bq25890_field_write(bq, init_data[i].id, - init_data[i].value); - if (ret < 0) { - dev_dbg(bq->dev, "Writing init data failed %d\n", ret); - return ret; - } - } + ret = bq25890_rw_init_data(bq); + if (ret) + return ret; ret = bq25890_get_chip_state(bq, &bq->state); if (ret < 0) { From patchwork Sun Nov 14 17:03:21 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: 1554875 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=YuvfkLwQ; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=linux-i2c-owner@vger.kernel.org; receiver=) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by bilbo.ozlabs.org (Postfix) with ESMTP id 4Hsdwd4WJmz9sWJ for ; Mon, 15 Nov 2021 04:04:49 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236234AbhKNRHl (ORCPT ); Sun, 14 Nov 2021 12:07:41 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:53713 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236220AbhKNRHC (ORCPT ); Sun, 14 Nov 2021 12:07:02 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1636909448; 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=fmkSKT7i6NigRzb1gtGRMw1mBsx212ar52Z2zF7M4mE=; b=YuvfkLwQp4pmFjng4EKcg7LtGPIr+V3UYW7czeNZSyBCN2W+HxlnL1ZMTmHrjZ8DGSMqjL W4qKHbSGoP/2sJ2tKBYaR5jfve5+ORGUm/YdXQMD5Enkz1+tW8u3urStTSX+oy6Zi13mU9 3gQpBQ2NanNU35GIRT2aZ9zONWNmVjI= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-368-LnszWwGHNFW0URkrqpH3Yg-1; Sun, 14 Nov 2021 12:04:05 -0500 X-MC-Unique: LnszWwGHNFW0URkrqpH3Yg-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 0F8401808324; Sun, 14 Nov 2021 17:04:03 +0000 (UTC) Received: from x1.localdomain (unknown [10.39.192.93]) by smtp.corp.redhat.com (Postfix) with ESMTP id 837FC19EF9; Sun, 14 Nov 2021 17:03:59 +0000 (UTC) From: Hans de Goede To: "Rafael J . Wysocki" , Mika Westerberg , Mark Gross , Andy Shevchenko , Wolfram Sang , 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-i2c@vger.kernel.org, linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, linux-efi@vger.kernel.org Subject: [PATCH v2 06/20] power: supply: bq25890: Add support to skip reset at probe() / remove() Date: Sun, 14 Nov 2021 18:03:21 +0100 Message-Id: <20211114170335.66994-7-hdegoede@redhat.com> In-Reply-To: <20211114170335.66994-1-hdegoede@redhat.com> References: <20211114170335.66994-1-hdegoede@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 Precedence: bulk List-ID: X-Mailing-List: linux-i2c@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 704cc15b4403..864904d7eaeb 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; @@ -709,10 +710,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 */ @@ -946,6 +949,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; @@ -1058,8 +1063,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 Sun Nov 14 17:03:22 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: 1554874 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=h1gej2NA; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=linux-i2c-owner@vger.kernel.org; receiver=) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by bilbo.ozlabs.org (Postfix) with ESMTP id 4HsdwD2MrJz9sWJ for ; Mon, 15 Nov 2021 04:04:28 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236176AbhKNRHJ (ORCPT ); Sun, 14 Nov 2021 12:07:09 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:26543 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236184AbhKNRHH (ORCPT ); Sun, 14 Nov 2021 12:07:07 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1636909452; 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=z0PtzQUpE4e+rg3mkfPABfZsN9EZ2U/8QQiDQfDb9rE=; b=h1gej2NAtE87Uk6FpkHgZbHr7X5nah5xMNBwOCMU2y8d7MoGTGS6WxyDE7fSi5OSCUkp2C MR13uGgUPYvG3H/ZGASMguJlhJ8fp4g5/pXWWo7qmrRk6TbUIBEKLCMRRnW1TVNTaHd17H DQ8/QWqkxJ0tFVJwjX9B6+fWi1ZA2nY= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-199-spOxP1pDOqWTG9O659uzYg-1; Sun, 14 Nov 2021 12:04:09 -0500 X-MC-Unique: spOxP1pDOqWTG9O659uzYg-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id DABA98005A2; Sun, 14 Nov 2021 17:04:06 +0000 (UTC) Received: from x1.localdomain (unknown [10.39.192.93]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5723B1346F; Sun, 14 Nov 2021 17:04:03 +0000 (UTC) From: Hans de Goede To: "Rafael J . Wysocki" , Mika Westerberg , Mark Gross , Andy Shevchenko , Wolfram Sang , 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-i2c@vger.kernel.org, linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, linux-efi@vger.kernel.org Subject: [PATCH v2 07/20] power: supply: bq25890: Add support to read back the settings from the chip Date: Sun, 14 Nov 2021 18:03:22 +0100 Message-Id: <20211114170335.66994-8-hdegoede@redhat.com> In-Reply-To: <20211114170335.66994-1-hdegoede@redhat.com> References: <20211114170335.66994-1-hdegoede@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 Precedence: bulk List-ID: X-Mailing-List: linux-i2c@vger.kernel.org On most X86/ACPI devices there is no devicetree to supply the necessary init-data. Instead the firmware already fully initializes the bq25890 charger at boot. To support this, add support for reading back the settings from the chip through a new "linux,read-back-settings" boolean. 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,skip-reset" patch this patch replaces the "ti,skip-init" patch from v1 --- drivers/power/supply/bq25890_charger.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/drivers/power/supply/bq25890_charger.c b/drivers/power/supply/bq25890_charger.c index 864904d7eaeb..b7c38d2c5ede 100644 --- a/drivers/power/supply/bq25890_charger.c +++ b/drivers/power/supply/bq25890_charger.c @@ -111,6 +111,7 @@ struct bq25890_device { struct regmap_field *rmap_fields[F_MAX_FIELDS]; bool skip_reset; + bool read_back_init_data; enum bq25890_chip_version chip_version; struct bq25890_init_data init_data; struct bq25890_state state; @@ -666,7 +667,7 @@ static int bq25890_chip_reset(struct bq25890_device *bq) static int bq25890_rw_init_data(struct bq25890_device *bq) { - bool write = true; + bool write = !bq->read_back_init_data; int ret; int i; @@ -950,6 +951,10 @@ static int bq25890_fw_probe(struct bq25890_device *bq) struct bq25890_init_data *init = &bq->init_data; bq->skip_reset = device_property_read_bool(bq->dev, "linux,skip-reset"); + bq->read_back_init_data = device_property_read_bool(bq->dev, + "linux,read-back-settings"); + if (bq->read_back_init_data) + return 0; ret = bq25890_fw_read_u32_props(bq); if (ret < 0) From patchwork Sun Nov 14 17:03:23 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: 1554878 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=BT8Jwdm7; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=linux-i2c-owner@vger.kernel.org; receiver=) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by bilbo.ozlabs.org (Postfix) with ESMTP id 4Hsdwn3MC7z9sWJ for ; Mon, 15 Nov 2021 04:04:57 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236367AbhKNRHo (ORCPT ); Sun, 14 Nov 2021 12:07:44 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:56759 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236264AbhKNRHM (ORCPT ); Sun, 14 Nov 2021 12:07:12 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1636909458; 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=hbo3H69E27X3xdtb6FN9nDkX51ICU4AEhWEkpawIJNY=; b=BT8Jwdm7nGOGEUjlfjirmRRb+TSXErXFvA9VsHg6n9BCnEGFYJAQmyqt2nEcWA9gg7vsjR i0+BoSzbg47bnJf0xuXDa/xmj4/KaL7zaP07hLgC9ZEt1c+BY39XemAfd8vblgth3tmDJs z7rKMaqEFCxiZWgvTpYBTngaj6jI28k= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-527-H7tedUprPKi7WQNDbL-MAw-1; Sun, 14 Nov 2021 12:04:13 -0500 X-MC-Unique: H7tedUprPKi7WQNDbL-MAw-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id AF8B415720; Sun, 14 Nov 2021 17:04:10 +0000 (UTC) Received: from x1.localdomain (unknown [10.39.192.93]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2DA2E19EF9; Sun, 14 Nov 2021 17:04:07 +0000 (UTC) From: Hans de Goede To: "Rafael J . Wysocki" , Mika Westerberg , Mark Gross , Andy Shevchenko , Wolfram Sang , 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-i2c@vger.kernel.org, linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, linux-efi@vger.kernel.org Subject: [PATCH v2 08/20] power: supply: bq25890: Enable charging on boards where we skip reset Date: Sun, 14 Nov 2021 18:03:23 +0100 Message-Id: <20211114170335.66994-9-hdegoede@redhat.com> In-Reply-To: <20211114170335.66994-1-hdegoede@redhat.com> References: <20211114170335.66994-1-hdegoede@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 Precedence: bulk List-ID: X-Mailing-List: linux-i2c@vger.kernel.org On boards where the "linux,skip-reset" boolean property is set we don't reset the charger; and on some boards where the fw takes care of initalizition F_CHG_CFG is set to 0 before handing control over to the OS. Explicitly set F_CHG_CFG to 1 on boards where we don't reset the charger, so that charging is always enabled on these boards, like it is always enabled on boards where we do reset the charger. Signed-off-by: Hans de Goede --- drivers/power/supply/bq25890_charger.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/drivers/power/supply/bq25890_charger.c b/drivers/power/supply/bq25890_charger.c index b7c38d2c5ede..a69a2173e31a 100644 --- a/drivers/power/supply/bq25890_charger.c +++ b/drivers/power/supply/bq25890_charger.c @@ -717,6 +717,17 @@ static int bq25890_hw_init(struct bq25890_device *bq) dev_dbg(bq->dev, "Reset failed %d\n", ret); return ret; } + } else { + /* + * Ensure charging is enabled, on some boards where the fw + * takes care of initalizition F_CHG_CFG is set to 0 before + * handing control over to the OS. + */ + ret = bq25890_field_write(bq, F_CHG_CFG, 1); + if (ret < 0) { + dev_dbg(bq->dev, "Enabling charging failed %d\n", ret); + return ret; + } } /* disable watchdog */ From patchwork Sun Nov 14 17:03:24 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: 1554879 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=NvKdtLln; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=linux-i2c-owner@vger.kernel.org; receiver=) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by bilbo.ozlabs.org (Postfix) with ESMTP id 4Hsdx63F0gz9sWJ for ; Mon, 15 Nov 2021 04:05:14 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236274AbhKNRIE (ORCPT ); Sun, 14 Nov 2021 12:08:04 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:33762 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233073AbhKNRHO (ORCPT ); Sun, 14 Nov 2021 12:07:14 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1636909460; 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=nS6oXu9q+npj9BQ/P9zA52LX0msdRKmILAqmJy+h9e8=; b=NvKdtLlnkrBuB2xKDUvteBViUyflKfTGHn9M4H8ujM807xVJsPMo8PfUYmyTwyEMf9f7f+ o+Da0r+SVj4po+Dgc7LlJpEG6a+Q0gHzHwN/7uMwnySwkAY9Cpsdhonc9ACphGQa4/6Nbd C5FB8kSJvDr4MywXPt0vlHOVU0Kw6Dc= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-567-A3Prny0RMyCo6pBpU9DoeA-1; Sun, 14 Nov 2021 12:04:17 -0500 X-MC-Unique: A3Prny0RMyCo6pBpU9DoeA-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 87D4A1080865; Sun, 14 Nov 2021 17:04:14 +0000 (UTC) Received: from x1.localdomain (unknown [10.39.192.93]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0449219EF9; Sun, 14 Nov 2021 17:04:10 +0000 (UTC) From: Hans de Goede To: "Rafael J . Wysocki" , Mika Westerberg , Mark Gross , Andy Shevchenko , Wolfram Sang , 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-i2c@vger.kernel.org, linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, linux-efi@vger.kernel.org Subject: [PATCH v2 09/20] power: supply: bq25890: Drop dev->platform_data == NULL check Date: Sun, 14 Nov 2021 18:03:24 +0100 Message-Id: <20211114170335.66994-10-hdegoede@redhat.com> In-Reply-To: <20211114170335.66994-1-hdegoede@redhat.com> References: <20211114170335.66994-1-hdegoede@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 Precedence: bulk List-ID: X-Mailing-List: linux-i2c@vger.kernel.org Drop the "if (!dev->platform_data)" check, this seems to be an attempt for allowing loading the driver on devices without devicetree stemming from the initial commit of the driver (with the presumed intention being the "return -ENODEV" else branch getting replaced with something else). With the new "linux,skip-init" and "linux,read-back-settings" properties the driver can actually supports devices without devicetree and this check no longer makes sense. While at it also switch to dev_err_probe(), which is already used in various other places in the driver. Signed-off-by: Hans de Goede Reviewed-by: Andy Shevchenko --- drivers/power/supply/bq25890_charger.c | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/drivers/power/supply/bq25890_charger.c b/drivers/power/supply/bq25890_charger.c index a69a2173e31a..2bdfb58cda75 100644 --- a/drivers/power/supply/bq25890_charger.c +++ b/drivers/power/supply/bq25890_charger.c @@ -1017,16 +1017,9 @@ static int bq25890_probe(struct i2c_client *client, return ret; } - if (!dev->platform_data) { - ret = bq25890_fw_probe(bq); - if (ret < 0) { - dev_err(dev, "Cannot read device properties: %d\n", - ret); - return ret; - } - } else { - return -ENODEV; - } + ret = bq25890_fw_probe(bq); + if (ret < 0) + return dev_err_probe(dev, ret, "reading device properties\n"); ret = bq25890_hw_init(bq); if (ret < 0) { From patchwork Sun Nov 14 17:03:25 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: 1554882 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=AfwmnmQp; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=linux-i2c-owner@vger.kernel.org; receiver=) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by bilbo.ozlabs.org (Postfix) with ESMTP id 4Hsdy20lTVz9sWJ for ; Mon, 15 Nov 2021 04:06:02 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236300AbhKNRIx (ORCPT ); Sun, 14 Nov 2021 12:08:53 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:42967 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236293AbhKNRHS (ORCPT ); Sun, 14 Nov 2021 12:07:18 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1636909464; 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=8ZwGtdlc85THTd5OwQWqXkWR69/kUF2qMVHBRX0Ls8Y=; b=AfwmnmQpRhWIxoHypi0HRSD/CjOllerw3Bn3/qOpCmGNfIa2HlhbaOpz12XkDZz0FNL7uV QkeQkZaH2eBir/qP6XV9UNyPeVm/q5GV9A47eywLRzqufHsQ6BJBXladzZXd7+FEMD/zo+ t7RehwVkByC/RVLAMMOXpVOVjGX3LDU= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-30-vKCbXiWAOaasvMZS-b2ZTw-1; Sun, 14 Nov 2021 12:04:20 -0500 X-MC-Unique: vKCbXiWAOaasvMZS-b2ZTw-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 6B617802575; Sun, 14 Nov 2021 17:04:18 +0000 (UTC) Received: from x1.localdomain (unknown [10.39.192.93]) by smtp.corp.redhat.com (Postfix) with ESMTP id CF6301346F; Sun, 14 Nov 2021 17:04:14 +0000 (UTC) From: Hans de Goede To: "Rafael J . Wysocki" , Mika Westerberg , Mark Gross , Andy Shevchenko , Wolfram Sang , 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-i2c@vger.kernel.org, linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, linux-efi@vger.kernel.org Subject: [PATCH v2 10/20] power: supply: bq25890: Add bq25890_set_otg_cfg() helper Date: Sun, 14 Nov 2021 18:03:25 +0100 Message-Id: <20211114170335.66994-11-hdegoede@redhat.com> In-Reply-To: <20211114170335.66994-1-hdegoede@redhat.com> References: <20211114170335.66994-1-hdegoede@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 Precedence: bulk List-ID: X-Mailing-List: linux-i2c@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 2bdfb58cda75..3c41fe86b3d3 100644 --- a/drivers/power/supply/bq25890_charger.c +++ b/drivers/power/supply/bq25890_charger.c @@ -801,6 +801,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; @@ -810,25 +821,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 Sun Nov 14 17:03:26 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: 1554880 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=WhVi63H9; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=linux-i2c-owner@vger.kernel.org; receiver=) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by bilbo.ozlabs.org (Postfix) with ESMTP id 4Hsdxk27gLz9sWJ for ; Mon, 15 Nov 2021 04:05:46 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236284AbhKNRI3 (ORCPT ); Sun, 14 Nov 2021 12:08:29 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:45374 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236247AbhKNRHY (ORCPT ); Sun, 14 Nov 2021 12:07:24 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1636909470; 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=eQMG15WrD+SpaKEYHtpgquyp9rViWR4bcOU93QQhbm0=; b=WhVi63H9PxkQ1wlnotu7B2KY92e6WGxCyMBSVHwEwA4yk9AvpmpUUwhKD6WnQa03Qapu2T iFKBFIbpGGgqYGIJAMSM1XAITsvt0x2KMpVyx/th+fV5tg5yF0wmHMlFTESk7CWwYzGpJv 410vcs0rSrr2Gx67yNQsC7JpbhZw/1w= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-364-A12mLeL2MYuSc6VUlOazAw-1; Sun, 14 Nov 2021 12:04:24 -0500 X-MC-Unique: A12mLeL2MYuSc6VUlOazAw-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 65DAD180831E; Sun, 14 Nov 2021 17:04:22 +0000 (UTC) Received: from x1.localdomain (unknown [10.39.192.93]) by smtp.corp.redhat.com (Postfix) with ESMTP id B5B301346F; Sun, 14 Nov 2021 17:04:18 +0000 (UTC) From: Hans de Goede To: "Rafael J . Wysocki" , Mika Westerberg , Mark Gross , Andy Shevchenko , Wolfram Sang , 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-i2c@vger.kernel.org, linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, linux-efi@vger.kernel.org Subject: [PATCH v2 11/20] power: supply: bq25890: Add support for registering the Vbus boost converter as a regulator Date: Sun, 14 Nov 2021 18:03:26 +0100 Message-Id: <20211114170335.66994-12-hdegoede@redhat.com> In-Reply-To: <20211114170335.66994-1-hdegoede@redhat.com> References: <20211114170335.66994-1-hdegoede@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 Precedence: bulk List-ID: X-Mailing-List: linux-i2c@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. Signed-off-by: Hans de Goede Reviewed-by: Andy Shevchenko --- 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 3c41fe86b3d3..e06ca7b0eb3e 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 @@ -845,6 +847,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; @@ -1044,6 +1085,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) { @@ -1082,6 +1139,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) { @@ -1161,6 +1240,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 Sun Nov 14 17:03:27 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: 1554881 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=QP5mHwMe; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=linux-i2c-owner@vger.kernel.org; receiver=) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by bilbo.ozlabs.org (Postfix) with ESMTP id 4Hsdxy4nxQz9sWJ for ; Mon, 15 Nov 2021 04:05:58 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236302AbhKNRIq (ORCPT ); Sun, 14 Nov 2021 12:08:46 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:36515 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236318AbhKNRH0 (ORCPT ); Sun, 14 Nov 2021 12:07:26 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1636909471; 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=IdxwmnlmBPdqk9J2W0qKJTJXaLjrLyAPUqGoZc8Jy8Y=; b=QP5mHwMeKBePavpoAMb9DryJ9oqCYKNQrsUHb8FU1OzNaRMFl1uoFUWfsYtH9pTsbMbNql E40HDHEUMTLezJzysy0Hbhh6e+8ieigwGy1vT5RIQKmq+9TRkP23IApRzvXSfVhYtstQVS X1yQgv9NM2F8VfaCduoM3awu3NGsj2k= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-56-Oky9LtFgNb-p0HeP-eFpYQ-1; Sun, 14 Nov 2021 12:04:28 -0500 X-MC-Unique: Oky9LtFgNb-p0HeP-eFpYQ-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 444A215721; Sun, 14 Nov 2021 17:04:26 +0000 (UTC) Received: from x1.localdomain (unknown [10.39.192.93]) by smtp.corp.redhat.com (Postfix) with ESMTP id ADC6E1346F; Sun, 14 Nov 2021 17:04:22 +0000 (UTC) From: Hans de Goede To: "Rafael J . Wysocki" , Mika Westerberg , Mark Gross , Andy Shevchenko , Wolfram Sang , 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-i2c@vger.kernel.org, linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, linux-efi@vger.kernel.org Subject: [PATCH v2 12/20] power: supply: bq25890: On the bq25892 set the IINLIM based on external charger detection Date: Sun, 14 Nov 2021 18:03:27 +0100 Message-Id: <20211114170335.66994-13-hdegoede@redhat.com> In-Reply-To: <20211114170335.66994-1-hdegoede@redhat.com> References: <20211114170335.66994-1-hdegoede@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 Precedence: bulk List-ID: X-Mailing-List: linux-i2c@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 e06ca7b0eb3e..57e4034bc9cd 100644 --- a/drivers/power/supply/bq25890_charger.c +++ b/drivers/power/supply/bq25890_charger.c @@ -564,6 +564,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) { @@ -787,6 +819,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 Sun Nov 14 17:03:28 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: 1554883 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=BOT8xVAy; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=linux-i2c-owner@vger.kernel.org; receiver=) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by bilbo.ozlabs.org (Postfix) with ESMTP id 4Hsdy4378Hz9sWJ for ; Mon, 15 Nov 2021 04:06:04 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236338AbhKNRIz (ORCPT ); Sun, 14 Nov 2021 12:08:55 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:53144 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236333AbhKNRHa (ORCPT ); Sun, 14 Nov 2021 12:07:30 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1636909476; 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=akLRSyR4rRlzFV7t4NJgs51HAGeXI584Jkm7WZHluk0=; b=BOT8xVAyWT8lpoZj2xmnBj4gVHHG0k63DNA+/fbHSO6gt70ZHydgG7Pu48+rOuj2FOD1Kq dxtnVlt3ldmtqxo/VGUf+4fomI607KDrNSTtrYoY1m8Mbyje13fYsTppbmAfmGM+j8rK4Y WnUyfU99irqiuhDeJ2H+XXplB6F/xyQ= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-495-HryNMEGlNrSAqSAJFh4LEQ-1; Sun, 14 Nov 2021 12:04:32 -0500 X-MC-Unique: HryNMEGlNrSAqSAJFh4LEQ-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id ED5271080865; Sun, 14 Nov 2021 17:04:29 +0000 (UTC) Received: from x1.localdomain (unknown [10.39.192.93]) by smtp.corp.redhat.com (Postfix) with ESMTP id 89F0419EF9; Sun, 14 Nov 2021 17:04:26 +0000 (UTC) From: Hans de Goede To: "Rafael J . Wysocki" , Mika Westerberg , Mark Gross , Andy Shevchenko , Wolfram Sang , 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-i2c@vger.kernel.org, linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, linux-efi@vger.kernel.org Subject: [PATCH v2 13/20] power: supply: bq25890: Support higher charging voltages through Pump Express+ protocol Date: Sun, 14 Nov 2021 18:03:28 +0100 Message-Id: <20211114170335.66994-14-hdegoede@redhat.com> In-Reply-To: <20211114170335.66994-1-hdegoede@redhat.com> References: <20211114170335.66994-1-hdegoede@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 Precedence: bulk List-ID: X-Mailing-List: linux-i2c@vger.kernel.org From: Yauhen Kharuzhy Add a "linux,pump-express-vbus-max" property which indicates if the Pump Express+ protocol should be used to increase the charging protocol. If this new property is set and a DCP charger is detected then request a higher charging voltage through the Pump Express+ protocol. 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. Changes by Hans de Goede: - Port to my bq25890 patch-series + various cleanups - Make behavior configurable through a new "linux,pump-express-vbus-max" device-property - Sleep 1 second before re-checking the Vbus voltage after requesting it to be raised, to ensure that the ADC has time to sampled the new Vbus - Add VBUSV bq25890_tables[] entry and use it in bq25890_get_vbus_voltage() - Tweak commit message Signed-off-by: Yauhen Kharuzhy Signed-off-by: Hans de Goede --- drivers/power/supply/bq25890_charger.c | 74 ++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) diff --git a/drivers/power/supply/bq25890_charger.c b/drivers/power/supply/bq25890_charger.c index 57e4034bc9cd..1c59d4f71389 100644 --- a/drivers/power/supply/bq25890_charger.c +++ b/drivers/power/supply/bq25890_charger.c @@ -27,6 +27,10 @@ #define BQ25895_ID 7 #define BQ25896_ID 0 +#define PUMP_EXPRESS_START_DELAY (5 * HZ) +#define PUMP_EXPRESS_MAX_TRIES 6 +#define PUMP_EXPRESS_VBUS_MARGIN 1000000 + enum bq25890_chip_version { BQ25890, BQ25892, @@ -107,6 +111,7 @@ struct bq25890_device { struct usb_phy *usb_phy; struct notifier_block usb_nb; struct work_struct usb_work; + struct delayed_work pump_express_work; unsigned long usb_event; struct regmap *rmap; @@ -114,6 +119,7 @@ struct bq25890_device { bool skip_reset; bool read_back_init_data; + u32 pump_express_vbus_max; enum bq25890_chip_version chip_version; struct bq25890_init_data init_data; struct bq25890_state state; @@ -265,6 +271,7 @@ enum bq25890_table_ids { TBL_VREG, TBL_BOOSTV, TBL_SYSVMIN, + TBL_VBUSV, TBL_VBATCOMP, TBL_RBATCOMP, @@ -308,6 +315,7 @@ static const union { [TBL_VREG] = { .rt = {3840000, 4608000, 16000} }, /* uV */ [TBL_BOOSTV] = { .rt = {4550000, 5510000, 64000} }, /* uV */ [TBL_SYSVMIN] = { .rt = {3000000, 3700000, 100000} }, /* uV */ + [TBL_VBUSV] = { .rt = {2600000,15300000, 100000} }, /* uV */ [TBL_VBATCOMP] ={ .rt = {0, 224000, 32000} }, /* uV */ [TBL_RBATCOMP] ={ .rt = {0, 140000, 20000} }, /* uOhm */ @@ -410,6 +418,17 @@ static bool bq25890_is_adc_property(enum power_supply_property psp) static irqreturn_t __bq25890_handle_irq(struct bq25890_device *bq); +static int bq25890_get_vbus_voltage(struct bq25890_device *bq) +{ + int ret; + + ret = bq25890_field_read(bq, F_VBUSV); + if (ret < 0) + return ret; + + return bq25890_find_val(ret, TBL_VBUSV); +} + static int bq25890_power_supply_get_property(struct power_supply *psy, enum power_supply_property psp, union power_supply_propval *val) @@ -583,6 +602,11 @@ static void bq25890_charger_external_power_changed(struct power_supply *psy) switch (val.intval) { case POWER_SUPPLY_USB_TYPE_DCP: input_current_limit = bq25890_find_idx(2000000, TBL_IINLIM); + if (bq->pump_express_vbus_max) { + queue_delayed_work(system_power_efficient_wq, + &bq->pump_express_work, + PUMP_EXPRESS_START_DELAY); + } break; case POWER_SUPPLY_USB_TYPE_CDP: case POWER_SUPPLY_USB_TYPE_ACA: @@ -847,6 +871,50 @@ static int bq25890_set_otg_cfg(struct bq25890_device *bq, u8 val) return ret; } +static void bq25890_pump_express_work(struct work_struct *data) +{ + struct bq25890_device *bq = + container_of(data, struct bq25890_device, pump_express_work.work); + int voltage, i, ret; + + dev_dbg(bq->dev, "Start to request input voltage increasing\n"); + + /* Enable current pulse voltage control protocol */ + ret = bq25890_field_write(bq, F_PUMPX_EN, 1); + if (ret < 0) + goto error; + + for (i = 0; i < PUMP_EXPRESS_MAX_TRIES; i++) { + voltage = bq25890_get_vbus_voltage(bq); + if (voltage < 0) + goto error; + dev_dbg(bq->dev, "input voltage = %d mV\n", voltage); + + if ((voltage + PUMP_EXPRESS_VBUS_MARGIN) > + bq->pump_express_vbus_max) + break; + + ret = bq25890_field_write(bq, F_PUMPX_UP, 1); + if (ret < 0) + goto error; + + while (bq25890_field_read(bq, F_PUMPX_UP) == 1) + msleep(100); + + /* Make sure ADC has sampled Vbus before checking again */ + msleep(1000); + } + + bq25890_field_write(bq, F_PUMPX_EN, 0); + + dev_info(bq->dev, "Hi-voltage charging requested, input voltage is %d mV\n", + voltage); + + return; +error: + dev_err(bq->dev, "Failed to request hi-voltage charging\n"); +} + static void bq25890_usb_work(struct work_struct *data) { int ret; @@ -1037,6 +1105,11 @@ static int bq25890_fw_probe(struct bq25890_device *bq) int ret; struct bq25890_init_data *init = &bq->init_data; + ret = device_property_read_u32(bq->dev, "linux,pump-express-vbus-max", + &bq->pump_express_vbus_max); + if (ret < 0) + bq->pump_express_vbus_max = 0; + bq->skip_reset = device_property_read_bool(bq->dev, "linux,skip-reset"); bq->read_back_init_data = device_property_read_bool(bq->dev, "linux,read-back-settings"); @@ -1069,6 +1142,7 @@ static int bq25890_probe(struct i2c_client *client, bq->dev = dev; mutex_init(&bq->lock); + INIT_DELAYED_WORK(&bq->pump_express_work, bq25890_pump_express_work); bq->rmap = devm_regmap_init_i2c(client, &bq25890_regmap_config); if (IS_ERR(bq->rmap)) From patchwork Sun Nov 14 17:03:29 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: 1554884 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=R/o3HniA; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=linux-i2c-owner@vger.kernel.org; receiver=) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by bilbo.ozlabs.org (Postfix) with ESMTP id 4HsdyG2P1pz9sWJ for ; Mon, 15 Nov 2021 04:06:14 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236496AbhKNRI6 (ORCPT ); Sun, 14 Nov 2021 12:08:58 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:42905 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236346AbhKNRHg (ORCPT ); Sun, 14 Nov 2021 12:07:36 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1636909481; 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=fVv8YUteH9MirfaKYfDD1ToB/iZr9iQujBoD/v0QeWk=; b=R/o3HniABhzAGpKl140fM+9+1gMFws37WvNjrZHr95aSegEt93mAodJ30+Axg/fm9whm+n GCTBTIVoGx92e/VOBfMHv2j6qXloKIEKx668YtZCJNlYwt1kr5mqfCNlf6qAJyzhU4/S3H wt/HMaIs6gAxKMTqYJsWaYqcp1Ho1mU= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-520-7R6Re83DPDGuJ3SoplgHRQ-1; Sun, 14 Nov 2021 12:04:36 -0500 X-MC-Unique: 7R6Re83DPDGuJ3SoplgHRQ-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id BA9281808303; Sun, 14 Nov 2021 17:04:33 +0000 (UTC) Received: from x1.localdomain (unknown [10.39.192.93]) by smtp.corp.redhat.com (Postfix) with ESMTP id 41D951346F; Sun, 14 Nov 2021 17:04:30 +0000 (UTC) From: Hans de Goede To: "Rafael J . Wysocki" , Mika Westerberg , Mark Gross , Andy Shevchenko , Wolfram Sang , 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-i2c@vger.kernel.org, linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, linux-efi@vger.kernel.org Subject: [PATCH v2 14/20] mfd: intel_soc_pmic_chtwc: Add intel_cht_wc_get_model() helper function Date: Sun, 14 Nov 2021 18:03:29 +0100 Message-Id: <20211114170335.66994-15-hdegoede@redhat.com> In-Reply-To: <20211114170335.66994-1-hdegoede@redhat.com> References: <20211114170335.66994-1-hdegoede@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 Precedence: bulk List-ID: X-Mailing-List: linux-i2c@vger.kernel.org Tablet / laptop designs using an Intel Cherry Trail x86 main SoC with an Intel Whiskey Cove PMIC do not use a single standard setup for the charger, fuel-gauge and other chips surrounding the PMIC / charging+data USB port. Unlike what is normal on X86 this diversity in designs is not handled by the ACPI tables. On 2 of the 3 known designs there are no standard (PNP0C0A) ACPI battery devices and on the 3th design the ACPI battery device does not work under Linux due to it requiring non-standard and undocumented ACPI behavior. So to make things work under Linux we use native charger and fuel-gauge drivers on these devices, re-using the native drivers used on ARM boards with the same charger / fuel-gauge ICs. This requires various MFD-cell drivers for the CHT-WC PMIC cells to know which model they are exactly running on so that they can e.g. instantiate an I2C-client for the right model charger-IC (the charger is connected to an I2C-controller which is part of the PMIC). Rather then duplicating DMI-id matching to check which model we are running on in each MFD-cell driver add a helper function for this and make this id all 3 known models: 1. The GPD Win and GPD Pocket mini-laptops, these are really 2 models but the Pocket re-uses the GPD Win's design in a different housing: The WC PMIC is connected to a TI BQ24292i charger, paired with a Maxim MAX17047 fuelgauge + a FUSB302 USB Type-C Controller + a PI3USB30532 USB switch, for a fully functional Type-C port. 2. The Xiaomi Mi Pad 2: The WC PMIC is connected to a TI BQ25890 charger, paired with a TI BQ27520 fuelgauge, using the TI BQ25890 for BC1.2 charger type detection, for a USB-2 only Type-C port without PD. 3. The Lenovo Yoga Book YB1-X90 / Lenovo Yoga Book YB1-X91 series: The WC PMIC is connected to a TI BQ25892 charger, paired with a TI BQ27542 fuelgauge, using the WC PMIC for BC1.2 charger type detection and using the BQ25892's Mediatek Pump Express+ (1.0) support to enable charging with up to 12V through a micro-USB port. Signed-off-by: Hans de Goede --- drivers/mfd/intel_soc_pmic_chtwc.c | 46 ++++++++++++++++++++++++++++++ include/linux/mfd/intel_soc_pmic.h | 9 ++++++ 2 files changed, 55 insertions(+) diff --git a/drivers/mfd/intel_soc_pmic_chtwc.c b/drivers/mfd/intel_soc_pmic_chtwc.c index 49c5f71664bc..3432bd18f5d0 100644 --- a/drivers/mfd/intel_soc_pmic_chtwc.c +++ b/drivers/mfd/intel_soc_pmic_chtwc.c @@ -10,6 +10,7 @@ #include #include +#include #include #include #include @@ -134,6 +135,51 @@ static const struct regmap_irq_chip cht_wc_regmap_irq_chip = { .num_regs = 1, }; +static const struct dmi_system_id cht_wc_model_dmi_ids[] = { + { /* GPD win / GPD pocket mini laptops */ + .driver_data = (void *)(long)INTEL_CHT_WC_GPD_WIN_POCKET, + /* + * Note this may not seem like a very unique match, but in the + * 24000+ DMI decode dumps from linux-hardware.org only 42 have + * a board_vendor value of "AMI Corporation" and of those 42 + * only 1 (the GPD win/pocket entry) has a board_name of + * "Default string". Also very few devices have both board_ and + * product_name not set. + */ + .matches = { + DMI_MATCH(DMI_BOARD_VENDOR, "AMI Corporation"), + DMI_MATCH(DMI_BOARD_NAME, "Default string"), + DMI_MATCH(DMI_BOARD_SERIAL, "Default string"), + DMI_MATCH(DMI_PRODUCT_NAME, "Default string"), + }, + }, { /* Xiaomi Mi Pad 2 */ + .driver_data = (void *)(long)INTEL_CHT_WC_XIAOMI_MIPAD2, + .matches = { + DMI_MATCH(DMI_SYS_VENDOR, "Xiaomi Inc"), + DMI_MATCH(DMI_PRODUCT_NAME, "Mipad2"), + }, + }, { /* Lenovo Yoga Book X90F / X91F / X91L */ + .driver_data = (void *)(long)INTEL_CHT_WC_LENOVO_YOGABOOK1, + .matches = { + /* Non exact match to match all versions */ + DMI_MATCH(DMI_PRODUCT_NAME, "Lenovo YB1-X9"), + }, + }, + { } /* Terminating empty */ +}; + +enum intel_cht_wc_models intel_cht_wc_get_model(void) +{ + const struct dmi_system_id *id; + + id = dmi_first_match(cht_wc_model_dmi_ids); + if (!id) + return INTEL_CHT_WC_UNKNOWN; + + return (long)id->driver_data; +} +EXPORT_SYMBOL_GPL(intel_cht_wc_get_model); + static int cht_wc_probe(struct i2c_client *client) { struct device *dev = &client->dev; diff --git a/include/linux/mfd/intel_soc_pmic.h b/include/linux/mfd/intel_soc_pmic.h index 6a88e34cb955..dd17d7f82434 100644 --- a/include/linux/mfd/intel_soc_pmic.h +++ b/include/linux/mfd/intel_soc_pmic.h @@ -41,7 +41,16 @@ struct intel_soc_pmic { struct intel_scu_ipc_dev *scu; }; +enum intel_cht_wc_models { + INTEL_CHT_WC_UNKNOWN, + INTEL_CHT_WC_GPD_WIN_POCKET, + INTEL_CHT_WC_XIAOMI_MIPAD2, + INTEL_CHT_WC_LENOVO_YOGABOOK1, +}; + int intel_soc_pmic_exec_mipi_pmic_seq_element(u16 i2c_address, u32 reg_address, u32 value, u32 mask); +enum intel_cht_wc_models intel_cht_wc_get_model(void); + #endif /* __INTEL_SOC_PMIC_H__ */ From patchwork Sun Nov 14 17:03:30 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: 1554890 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=KnLVgGja; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=linux-i2c-owner@vger.kernel.org; receiver=) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by bilbo.ozlabs.org (Postfix) with ESMTP id 4Hsf4v2kdkz9sWJ for ; Mon, 15 Nov 2021 04:11:59 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236243AbhKNROp (ORCPT ); Sun, 14 Nov 2021 12:14:45 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:48154 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236356AbhKNRHh (ORCPT ); Sun, 14 Nov 2021 12:07:37 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1636909483; 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=2e9rLIVxP/XfpfOWUukUdN+7FQrdvef2m+/BSxyecVw=; b=KnLVgGjaE4q+eYYJxpGuhkpXGL7jdkJt24S81/iY5k3QTlXMopkCOL9mSsqtqYTswD3/EC 96TNjBzqNpAXw+kOQi8urMCfNOPU3kS+bvKzycxmhfMYTqN1JRs+nhd5DlDEgEHMNUs5C1 Q1AKqEjNBgUY03AwwEf2zmtc7H2/e+4= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-410-Jl1B_W7FOq2gVyF9yp1Z8g-1; Sun, 14 Nov 2021 12:04:39 -0500 X-MC-Unique: Jl1B_W7FOq2gVyF9yp1Z8g-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 9B5AC1006AA0; Sun, 14 Nov 2021 17:04:37 +0000 (UTC) Received: from x1.localdomain (unknown [10.39.192.93]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0F8361346F; Sun, 14 Nov 2021 17:04:33 +0000 (UTC) From: Hans de Goede To: "Rafael J . Wysocki" , Mika Westerberg , Mark Gross , Andy Shevchenko , Wolfram Sang , 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-i2c@vger.kernel.org, linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, linux-efi@vger.kernel.org Subject: [PATCH v2 15/20] i2c: cht-wc: Make charger i2c-client instantiation board/device-model specific Date: Sun, 14 Nov 2021 18:03:30 +0100 Message-Id: <20211114170335.66994-16-hdegoede@redhat.com> In-Reply-To: <20211114170335.66994-1-hdegoede@redhat.com> References: <20211114170335.66994-1-hdegoede@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 Precedence: bulk List-ID: X-Mailing-List: linux-i2c@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 pcoket 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. Signed-off-by: Hans de Goede Acked-by: Wolfram Sang --- 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..e700373bf388 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,93 @@ 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 batter-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 +457,23 @@ 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 (intel_cht_wc_get_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"); + } + + 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 Sun Nov 14 17:03:31 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: 1554885 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=iUw2v1+6; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=linux-i2c-owner@vger.kernel.org; receiver=) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by bilbo.ozlabs.org (Postfix) with ESMTP id 4HsdzT6905z9sWJ for ; Mon, 15 Nov 2021 04:07:17 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236491AbhKNRJu (ORCPT ); Sun, 14 Nov 2021 12:09:50 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:23614 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236363AbhKNRHl (ORCPT ); Sun, 14 Nov 2021 12:07:41 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1636909487; 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=VkrzRyLpI/vm0BtNuQueusLpeyS5Qzu5q0EpoAb3tQo=; b=iUw2v1+612eLMS67+AZMyp6s+L5ev88xQo124YGVPSR+xeLS8DIplFZj7gwoTi5IHeRzn5 W5NO3VFERxjgOHfdSVnDHGz2aH5+3qybzdIrFhVXx+KN3KrmCbQCpUmOJLdVxs6ZQgEevp 9C9CzPbthVgtmpBGGvtzBnZYMJ3fz50= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-219-zDr9d-1sPKOZe8rtTdVxDQ-1; Sun, 14 Nov 2021 12:04:44 -0500 X-MC-Unique: zDr9d-1sPKOZe8rtTdVxDQ-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 58C5D1080865; Sun, 14 Nov 2021 17:04:41 +0000 (UTC) Received: from x1.localdomain (unknown [10.39.192.93]) by smtp.corp.redhat.com (Postfix) with ESMTP id E49291346F; Sun, 14 Nov 2021 17:04:37 +0000 (UTC) From: Hans de Goede To: "Rafael J . Wysocki" , Mika Westerberg , Mark Gross , Andy Shevchenko , Wolfram Sang , 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-i2c@vger.kernel.org, linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, linux-efi@vger.kernel.org Subject: [PATCH v2 16/20] extcon: intel-cht-wc: Use new intel_cht_wc_get_model() helper Date: Sun, 14 Nov 2021 18:03:31 +0100 Message-Id: <20211114170335.66994-17-hdegoede@redhat.com> In-Reply-To: <20211114170335.66994-1-hdegoede@redhat.com> References: <20211114170335.66994-1-hdegoede@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 Precedence: bulk List-ID: X-Mailing-List: linux-i2c@vger.kernel.org The CHT_WC_VBUS_GPIO_CTLO GPIO actually driving an external 5V Vboost converter for Vbus depends on the board on which the Cherry Trail - Whiskey Cove PMIC is actually used. Since the information about the exact PMIC setup is necessary in other places too, the drivers/mfd/intel_soc_pmic_chtwc.c code now has a new intel_cht_wc_get_model() helper. Only poke the CHT_WC_VBUS_GPIO_CTLO GPIO if this new helper returns INTEL_CHT_WC_GPD_WIN_POCKET, which indicates the Type-C (with PD and DP-altmode) setup used on the GPD pocket and GPD win; and on which this GPIO actually controls an external 5V Vboost converter. Signed-off-by: Hans de Goede --- drivers/extcon/extcon-intel-cht-wc.c | 35 +++++++++++++++++----------- 1 file changed, 21 insertions(+), 14 deletions(-) diff --git a/drivers/extcon/extcon-intel-cht-wc.c b/drivers/extcon/extcon-intel-cht-wc.c index 771f6f4cf92e..a5aeeecc44fb 100644 --- a/drivers/extcon/extcon-intel-cht-wc.c +++ b/drivers/extcon/extcon-intel-cht-wc.c @@ -14,6 +14,7 @@ #include #include #include +#include #include #include @@ -358,20 +359,26 @@ static int cht_wc_extcon_probe(struct platform_device *pdev) if (IS_ERR(ext->edev)) return PTR_ERR(ext->edev); - /* - * When a host-cable is detected the BIOS enables an external 5v boost - * converter to power connected devices there are 2 problems with this: - * 1) This gets seen by the external battery charger as a valid Vbus - * supply and it then tries to feed Vsys from this creating a - * feedback loop which causes aprox. 300 mA extra battery drain - * (and unless we drive the external-charger-disable pin high it - * also tries to charge the battery causing even more feedback). - * 2) This gets seen by the pwrsrc block as a SDP USB Vbus supply - * Since the external battery charger has its own 5v boost converter - * which does not have these issues, we simply turn the separate - * external 5v boost converter off and leave it off entirely. - */ - cht_wc_extcon_set_5v_boost(ext, false); + switch (intel_cht_wc_get_model()) { + case INTEL_CHT_WC_GPD_WIN_POCKET: + /* + * When a host-cable is detected the BIOS enables an external 5v boost + * converter to power connected devices there are 2 problems with this: + * 1) This gets seen by the external battery charger as a valid Vbus + * supply and it then tries to feed Vsys from this creating a + * feedback loop which causes aprox. 300 mA extra battery drain + * (and unless we drive the external-charger-disable pin high it + * also tries to charge the battery causing even more feedback). + * 2) This gets seen by the pwrsrc block as a SDP USB Vbus supply + * Since the external battery charger has its own 5v boost converter + * which does not have these issues, we simply turn the separate + * external 5v boost converter off and leave it off entirely. + */ + cht_wc_extcon_set_5v_boost(ext, false); + break; + default: + break; + } /* Enable sw control */ ret = cht_wc_extcon_sw_control(ext, true); From patchwork Sun Nov 14 17:03:32 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: 1554889 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=FYaJjrgY; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=linux-i2c-owner@vger.kernel.org; receiver=) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by bilbo.ozlabs.org (Postfix) with ESMTP id 4Hsf4p3mtJz9sWJ for ; Mon, 15 Nov 2021 04:11:54 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235621AbhKNROg (ORCPT ); Sun, 14 Nov 2021 12:14:36 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:40973 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236378AbhKNRHq (ORCPT ); Sun, 14 Nov 2021 12:07:46 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1636909492; 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=3N6Zcm6U2hRyuCD4vVxiq15MirS56+YkWGxtbdJNdv8=; b=FYaJjrgYDZsNdKxoCjeXLIlFwfTSTeS8zF/fBESCFR8czZT5MU2pMTP1DNuXzIbLk6L8pi 7y4E2jPGLhfvdg/I7/EnAiwZFmq6gITvwbMt/zasaMD5w/FavCQNbg2Wn6FW4mt6XzcBOy Z2UJbGkNo9eqLBdj0a+toWFeYcTnYlM= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-214-iWttP9EDOIOE08zyEnURTg-1; Sun, 14 Nov 2021 12:04:47 -0500 X-MC-Unique: iWttP9EDOIOE08zyEnURTg-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 115CB802E62; Sun, 14 Nov 2021 17:04:45 +0000 (UTC) Received: from x1.localdomain (unknown [10.39.192.93]) by smtp.corp.redhat.com (Postfix) with ESMTP id A1E9019EF9; Sun, 14 Nov 2021 17:04:41 +0000 (UTC) From: Hans de Goede To: "Rafael J . Wysocki" , Mika Westerberg , Mark Gross , Andy Shevchenko , Wolfram Sang , 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-i2c@vger.kernel.org, linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, linux-efi@vger.kernel.org Subject: [PATCH v2 17/20] extcon: intel-cht-wc: Support devs with Micro-B / USB-2 only Type-C connectors Date: Sun, 14 Nov 2021 18:03:32 +0100 Message-Id: <20211114170335.66994-18-hdegoede@redhat.com> In-Reply-To: <20211114170335.66994-1-hdegoede@redhat.com> References: <20211114170335.66994-1-hdegoede@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 Precedence: bulk List-ID: X-Mailing-List: linux-i2c@vger.kernel.org So far the extcon-intel-cht-wc code has only been tested on devices with a Type-C connector with USB-PD, USB3 (superspeed) and DP-altmode support through a FUSB302 Type-C controller. Some devices with the intel-cht-wc PMIC however come with an USB-micro-B connector, or an USB-2 only Type-C connector without USB-PD. Which device-model we are running on can be identified with the new intel_cht_wc_get_model() helper and on models without a Type-C controller the extcon code must control the Vbus 5V boost converter and the USB role switch depending on the detected cable-type. Signed-off-by: Hans de Goede --- drivers/extcon/Kconfig | 3 +- drivers/extcon/extcon-intel-cht-wc.c | 91 ++++++++++++++++++++++++++++ 2 files changed, 93 insertions(+), 1 deletion(-) diff --git a/drivers/extcon/Kconfig b/drivers/extcon/Kconfig index c69d40ae5619..fc733689cfad 100644 --- a/drivers/extcon/Kconfig +++ b/drivers/extcon/Kconfig @@ -60,7 +60,8 @@ config EXTCON_INTEL_INT3496 config EXTCON_INTEL_CHT_WC tristate "Intel Cherrytrail Whiskey Cove PMIC extcon driver" - depends on INTEL_SOC_PMIC_CHTWC + depends on INTEL_SOC_PMIC_CHTWC && USB_SUPPORT + select USB_ROLE_SWITCH help Say Y here to enable extcon support for charger detection / control on the Intel Cherrytrail Whiskey Cove PMIC. diff --git a/drivers/extcon/extcon-intel-cht-wc.c b/drivers/extcon/extcon-intel-cht-wc.c index a5aeeecc44fb..119b83793123 100644 --- a/drivers/extcon/extcon-intel-cht-wc.c +++ b/drivers/extcon/extcon-intel-cht-wc.c @@ -16,7 +16,9 @@ #include #include #include +#include #include +#include #include "extcon-intel.h" @@ -102,8 +104,11 @@ struct cht_wc_extcon_data { struct device *dev; struct regmap *regmap; struct extcon_dev *edev; + struct usb_role_switch *role_sw; + struct regulator *vbus_boost; unsigned int previous_cable; bool usb_host; + bool vbus_boost_enabled; }; static int cht_wc_extcon_get_id(struct cht_wc_extcon_data *ext, int pwrsrc_sts) @@ -217,6 +222,18 @@ static void cht_wc_extcon_set_otgmode(struct cht_wc_extcon_data *ext, CHT_WC_CHGRCTRL1_OTGMODE, val); if (ret) dev_err(ext->dev, "Error updating CHGRCTRL1 reg: %d\n", ret); + + if (ext->vbus_boost && ext->vbus_boost_enabled != enable) { + if (enable) + ret = regulator_enable(ext->vbus_boost); + else + ret = regulator_disable(ext->vbus_boost); + + if (ret == 0) + ext->vbus_boost_enabled = enable; + else + dev_err(ext->dev, "Error updating Vbus boost regulator: %d\n", ret); + } } static void cht_wc_extcon_enable_charging(struct cht_wc_extcon_data *ext, @@ -246,6 +263,7 @@ static void cht_wc_extcon_pwrsrc_event(struct cht_wc_extcon_data *ext) unsigned int cable = EXTCON_NONE; /* Ignore errors in host mode, as the 5v boost converter is on then */ bool ignore_get_charger_errors = ext->usb_host; + enum usb_role role; ret = regmap_read(ext->regmap, CHT_WC_PWRSRC_STS, &pwrsrc_sts); if (ret) { @@ -289,6 +307,18 @@ static void cht_wc_extcon_pwrsrc_event(struct cht_wc_extcon_data *ext) ext->usb_host = ((id == INTEL_USB_ID_GND) || (id == INTEL_USB_RID_A)); extcon_set_state_sync(ext->edev, EXTCON_USB_HOST, ext->usb_host); + + if (ext->usb_host) + role = USB_ROLE_HOST; + else if (pwrsrc_sts & CHT_WC_PWRSRC_VBUS) + role = USB_ROLE_DEVICE; + else + role = USB_ROLE_NONE; + + /* Note: this is a no-op when ext->role_sw is NULL */ + ret = usb_role_switch_set_role(ext->role_sw, role); + if (ret) + dev_err(ext->dev, "Error setting USB-role: %d\n", ret); } static irqreturn_t cht_wc_extcon_isr(int irq, void *data) @@ -334,6 +364,61 @@ static int cht_wc_extcon_sw_control(struct cht_wc_extcon_data *ext, bool enable) return ret; } +static int cht_wc_extcon_find_role_sw(struct cht_wc_extcon_data *ext) +{ + const struct software_node *swnode; + struct fwnode_handle *fwnode; + + swnode = software_node_find_by_name(NULL, "intel-xhci-usb-sw"); + if (!swnode) + return -EPROBE_DEFER; + + fwnode = software_node_fwnode(swnode); + ext->role_sw = usb_role_switch_find_by_fwnode(fwnode); + fwnode_handle_put(fwnode); + + return ext->role_sw ? 0 : -EPROBE_DEFER; +} + +static void cht_wc_extcon_put_role_sw(void *data) +{ + struct cht_wc_extcon_data *ext = data; + + usb_role_switch_put(ext->role_sw); +} + +/* Some boards require controlling the role-sw and vbus based on the id-pin */ +static int cht_wc_extcon_get_role_sw_and_regulator(struct cht_wc_extcon_data *ext) +{ + int ret; + + ret = cht_wc_extcon_find_role_sw(ext); + if (ret) + return ret; + + ret = devm_add_action_or_reset(ext->dev, cht_wc_extcon_put_role_sw, ext); + if (ret) + return ret; + + /* + * On x86/ACPI platforms the regulator <-> consumer link is provided + * by platform_data passed to the regulator driver. This means that + * this info is not available before the regulator driver has bound. + * Use devm_regulator_get_optional() to avoid getting a dummy + * regulator and wait for the regulator to show up if necessary. + */ + ext->vbus_boost = devm_regulator_get_optional(ext->dev, "vbus"); + if (IS_ERR(ext->vbus_boost)) { + ret = PTR_ERR(ext->vbus_boost); + if (ret == -ENODEV) + ret = -EPROBE_DEFER; + + return dev_err_probe(ext->dev, ret, "getting vbus regulator"); + } + + return 0; +} + static int cht_wc_extcon_probe(struct platform_device *pdev) { struct intel_soc_pmic *pmic = dev_get_drvdata(pdev->dev.parent); @@ -376,6 +461,12 @@ static int cht_wc_extcon_probe(struct platform_device *pdev) */ cht_wc_extcon_set_5v_boost(ext, false); break; + case INTEL_CHT_WC_LENOVO_YOGABOOK1: + case INTEL_CHT_WC_XIAOMI_MIPAD2: + ret = cht_wc_extcon_get_role_sw_and_regulator(ext); + if (ret) + return ret; + break; default: break; } From patchwork Sun Nov 14 17:03:33 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: 1554888 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=WlnSwh/W; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=linux-i2c-owner@vger.kernel.org; receiver=) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by bilbo.ozlabs.org (Postfix) with ESMTP id 4Hsf482bvZz9sWJ for ; Mon, 15 Nov 2021 04:11:20 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236138AbhKNROH (ORCPT ); Sun, 14 Nov 2021 12:14:07 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:57287 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236391AbhKNRHt (ORCPT ); Sun, 14 Nov 2021 12:07:49 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1636909494; 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=shJ57dElBm4RG/R44dnCJ2w5WNB/dQYTx2QpI9Dvl2I=; b=WlnSwh/Wdjnx+3aIe8WAPgoa0Py/3c2qpnzGNTSBIinC/vXCxmVPlb4kx0nE7cDuvA6lVK uF8f/Zqp5q/AvdINhF88d13F5/5PgDwuj8+f1zv4w2f5oLW6U+44xCQmRdNsohOrqT77OE qNfznEwe4HeWeltLFZfcnJ1+z+ZwrnU= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-313-U42T4QZaOx-imQHISHXUlA-1; Sun, 14 Nov 2021 12:04:51 -0500 X-MC-Unique: U42T4QZaOx-imQHISHXUlA-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id C3BE315720; Sun, 14 Nov 2021 17:04:48 +0000 (UTC) Received: from x1.localdomain (unknown [10.39.192.93]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5A1861346F; Sun, 14 Nov 2021 17:04:45 +0000 (UTC) From: Hans de Goede To: "Rafael J . Wysocki" , Mika Westerberg , Mark Gross , Andy Shevchenko , Wolfram Sang , 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-i2c@vger.kernel.org, linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, linux-efi@vger.kernel.org Subject: [PATCH v2 18/20] extcon: intel-cht-wc: Refactor cht_wc_extcon_get_charger() Date: Sun, 14 Nov 2021 18:03:33 +0100 Message-Id: <20211114170335.66994-19-hdegoede@redhat.com> In-Reply-To: <20211114170335.66994-1-hdegoede@redhat.com> References: <20211114170335.66994-1-hdegoede@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 Precedence: bulk List-ID: X-Mailing-List: linux-i2c@vger.kernel.org Refactor cht_wc_extcon_get_charger() to have all the returns are in the "switch (usbsrc)" cases. This is a preparation patch for adding support for registering a power_supply class device. Signed-off-by: Hans de Goede --- 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 119b83793123..f2b93a99a625 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 Sun Nov 14 17:03:34 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: 1554887 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=EfMelp21; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=linux-i2c-owner@vger.kernel.org; receiver=) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by bilbo.ozlabs.org (Postfix) with ESMTP id 4Hsf434MxGz9sWJ for ; Mon, 15 Nov 2021 04:11:15 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236320AbhKNROG (ORCPT ); Sun, 14 Nov 2021 12:14:06 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:38096 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236403AbhKNRHw (ORCPT ); Sun, 14 Nov 2021 12:07:52 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1636909498; 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=wJdz9MtN1bBCcch4KVzv6dYyQUDVZl1JcuGCIVkgNK8=; b=EfMelp21snti9/ELHW1rROqtgso0R9vZkSshrqvr1gJq4Y6NoKZpwiNSeHz3zO48gwUFMd yO0rYVFIPDqzotxUjH95H+FttP3MkL4ANu8VDUULBAUJgg0rtgZvNN6fHg69vD4of3WLyj EAc0kBugoIZ6SMBHah/k1utqmMNdbOA= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-549-Vdfvd3GMNaykdOutfwSrHA-1; Sun, 14 Nov 2021 12:04:55 -0500 X-MC-Unique: Vdfvd3GMNaykdOutfwSrHA-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 88219106B3A3; Sun, 14 Nov 2021 17:04:52 +0000 (UTC) Received: from x1.localdomain (unknown [10.39.192.93]) by smtp.corp.redhat.com (Postfix) with ESMTP id 181F41346F; Sun, 14 Nov 2021 17:04:48 +0000 (UTC) From: Hans de Goede To: "Rafael J . Wysocki" , Mika Westerberg , Mark Gross , Andy Shevchenko , Wolfram Sang , 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-i2c@vger.kernel.org, linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, linux-efi@vger.kernel.org Subject: [PATCH v2 19/20] extcon: intel-cht-wc: Add support for registering a power_supply class-device Date: Sun, 14 Nov 2021 18:03:34 +0100 Message-Id: <20211114170335.66994-20-hdegoede@redhat.com> In-Reply-To: <20211114170335.66994-1-hdegoede@redhat.com> References: <20211114170335.66994-1-hdegoede@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 Precedence: bulk List-ID: X-Mailing-List: linux-i2c@vger.kernel.org The bq25890 used on the Yogabook YB1-X90 / -X91 models relies on the extcon-driver's BC-1.2 charger detection, and the bq25890 driver expect this info to be available through a parent power_supply class-device which models the detected charger (idem to how the Type-C TCPM code registers a power_supply classdev for the connected charger). Add support for registering the power_supply class-device expected by this setup. Signed-off-by: Hans de Goede --- drivers/extcon/extcon-intel-cht-wc.c | 83 ++++++++++++++++++++++++++++ 1 file changed, 83 insertions(+) diff --git a/drivers/extcon/extcon-intel-cht-wc.c b/drivers/extcon/extcon-intel-cht-wc.c index f2b93a99a625..1030610a3494 100644 --- a/drivers/extcon/extcon-intel-cht-wc.c +++ b/drivers/extcon/extcon-intel-cht-wc.c @@ -14,6 +14,7 @@ #include #include #include +#include #include #include #include @@ -106,6 +107,8 @@ struct cht_wc_extcon_data { struct extcon_dev *edev; struct usb_role_switch *role_sw; struct regulator *vbus_boost; + struct power_supply *psy; + enum power_supply_usb_type usb_type; unsigned int previous_cable; bool usb_host; bool vbus_boost_enabled; @@ -170,18 +173,23 @@ static int cht_wc_extcon_get_charger(struct cht_wc_extcon_data *ext, dev_warn(ext->dev, "Unhandled charger type %d, defaulting to SDP\n", ret); + ext->usb_type = POWER_SUPPLY_USB_TYPE_SDP; return EXTCON_CHG_USB_SDP; case CHT_WC_USBSRC_TYPE_SDP: case CHT_WC_USBSRC_TYPE_FLOATING: case CHT_WC_USBSRC_TYPE_OTHER: + ext->usb_type = POWER_SUPPLY_USB_TYPE_SDP; return EXTCON_CHG_USB_SDP; case CHT_WC_USBSRC_TYPE_CDP: + ext->usb_type = POWER_SUPPLY_USB_TYPE_CDP; return EXTCON_CHG_USB_CDP; case CHT_WC_USBSRC_TYPE_DCP: case CHT_WC_USBSRC_TYPE_DCP_EXTPHY: case CHT_WC_USBSRC_TYPE_MHL: /* MHL2+ delivers upto 2A, treat as DCP */ + ext->usb_type = POWER_SUPPLY_USB_TYPE_DCP; return EXTCON_CHG_USB_DCP; case CHT_WC_USBSRC_TYPE_ACA: + ext->usb_type = POWER_SUPPLY_USB_TYPE_ACA; return EXTCON_CHG_USB_ACA; } } @@ -266,6 +274,8 @@ static void cht_wc_extcon_pwrsrc_event(struct cht_wc_extcon_data *ext) bool ignore_get_charger_errors = ext->usb_host; enum usb_role role; + ext->usb_type = POWER_SUPPLY_USB_TYPE_UNKNOWN; + ret = regmap_read(ext->regmap, CHT_WC_PWRSRC_STS, &pwrsrc_sts); if (ret) { dev_err(ext->dev, "Error reading pwrsrc status: %d\n", ret); @@ -320,6 +330,9 @@ static void cht_wc_extcon_pwrsrc_event(struct cht_wc_extcon_data *ext) ret = usb_role_switch_set_role(ext->role_sw, role); if (ret) dev_err(ext->dev, "Error setting USB-role: %d\n", ret); + + if (ext->psy) + power_supply_changed(ext->psy); } static irqreturn_t cht_wc_extcon_isr(int irq, void *data) @@ -420,6 +433,61 @@ static int cht_wc_extcon_get_role_sw_and_regulator(struct cht_wc_extcon_data *ex return 0; } +static int cht_wc_extcon_psy_get_prop(struct power_supply *psy, + enum power_supply_property psp, + union power_supply_propval *val) +{ + struct cht_wc_extcon_data *ext = power_supply_get_drvdata(psy); + int ret = 0; + + switch (psp) { + case POWER_SUPPLY_PROP_USB_TYPE: + val->intval = ext->usb_type; + break; + case POWER_SUPPLY_PROP_ONLINE: + val->intval = ext->usb_type ? 1 : 0; + break; + default: + ret = -EINVAL; + break; + } + + return ret; +} + +static const enum power_supply_usb_type cht_wc_extcon_psy_usb_types[] = { + POWER_SUPPLY_USB_TYPE_SDP, + POWER_SUPPLY_USB_TYPE_CDP, + POWER_SUPPLY_USB_TYPE_DCP, + POWER_SUPPLY_USB_TYPE_ACA, + POWER_SUPPLY_USB_TYPE_UNKNOWN, +}; + +static const enum power_supply_property cht_wc_extcon_psy_props[] = { + POWER_SUPPLY_PROP_USB_TYPE, + POWER_SUPPLY_PROP_ONLINE, +}; + +static const struct power_supply_desc cht_wc_extcon_psy_desc = { + .name = "cht_wcove_pwrsrc", + .type = POWER_SUPPLY_TYPE_USB, + .usb_types = cht_wc_extcon_psy_usb_types, + .num_usb_types = ARRAY_SIZE(cht_wc_extcon_psy_usb_types), + .properties = cht_wc_extcon_psy_props, + .num_properties = ARRAY_SIZE(cht_wc_extcon_psy_props), + .get_property = cht_wc_extcon_psy_get_prop, +}; + +static int cht_wc_extcon_register_psy(struct cht_wc_extcon_data *ext) +{ + struct power_supply_config psy_cfg = { .drv_data = ext }; + + ext->psy = devm_power_supply_register(ext->dev, + &cht_wc_extcon_psy_desc, + &psy_cfg); + return PTR_ERR_OR_ZERO(ext->psy); +} + static int cht_wc_extcon_probe(struct platform_device *pdev) { struct intel_soc_pmic *pmic = dev_get_drvdata(pdev->dev.parent); @@ -463,6 +531,21 @@ static int cht_wc_extcon_probe(struct platform_device *pdev) cht_wc_extcon_set_5v_boost(ext, false); break; case INTEL_CHT_WC_LENOVO_YOGABOOK1: + /* Do this first, as it may very well return -EPROBE_DEFER. */ + ret = cht_wc_extcon_get_role_sw_and_regulator(ext); + if (ret) + return ret; + /* + * The bq25890 used here relies on this driver's BC-1.2 charger + * detection, and the bq25890 driver expect this info to be + * available through a parent power_supply class device which + * models the detected charger (idem to how the Type-C TCPM code + * registers a power_supply classdev for the connected charger). + */ + ret = cht_wc_extcon_register_psy(ext); + if (ret) + return ret; + break; case INTEL_CHT_WC_XIAOMI_MIPAD2: ret = cht_wc_extcon_get_role_sw_and_regulator(ext); if (ret) From patchwork Sun Nov 14 17:03:35 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: 1554886 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=MLOg2iwm; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=linux-i2c-owner@vger.kernel.org; receiver=) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by bilbo.ozlabs.org (Postfix) with ESMTP id 4Hsf075zC8z9sWJ for ; Mon, 15 Nov 2021 04:07:51 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236241AbhKNRKe (ORCPT ); Sun, 14 Nov 2021 12:10:34 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:49067 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236426AbhKNRH7 (ORCPT ); Sun, 14 Nov 2021 12:07:59 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1636909505; 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=HKhlJl6L8XG/e1kTNa2zkugX2OC5+vLBLiGtbBb04F8=; b=MLOg2iwmBd3QCJ0ICb+PAK2bXOOoOhxNfBGmcZPkD2xoOKuOKSHkj/eZQtrddDe94xlEOK KhbL/PLnQrt92GbXvyAiYMumcw5c+KEwkSXQsTCrnH725w6HcqjkGItmpBy5etwRk0kRCS Q3tmUMYMgc2cRTAnItnGdPGqQ1JQTUk= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-512-sStz62q6NCWVIasF6iVnTA-1; Sun, 14 Nov 2021 12:04:58 -0500 X-MC-Unique: sStz62q6NCWVIasF6iVnTA-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 4C7E2809864; Sun, 14 Nov 2021 17:04:56 +0000 (UTC) Received: from x1.localdomain (unknown [10.39.192.93]) by smtp.corp.redhat.com (Postfix) with ESMTP id CFF3819EF9; Sun, 14 Nov 2021 17:04:52 +0000 (UTC) From: Hans de Goede To: "Rafael J . Wysocki" , Mika Westerberg , Mark Gross , Andy Shevchenko , Wolfram Sang , 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-i2c@vger.kernel.org, linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, linux-efi@vger.kernel.org Subject: [PATCH v2 20/20] extcon: intel-cht-wc: Report RID_A for ACA adapters Date: Sun, 14 Nov 2021 18:03:35 +0100 Message-Id: <20211114170335.66994-21-hdegoede@redhat.com> In-Reply-To: <20211114170335.66994-1-hdegoede@redhat.com> References: <20211114170335.66994-1-hdegoede@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 Precedence: bulk List-ID: X-Mailing-List: linux-i2c@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 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. Signed-off-by: Hans de Goede --- 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 1030610a3494..c92bc98cb428 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; } }