Received: by 2002:a05:6a10:1a4d:0:0:0:0 with SMTP id nk13csp618181pxb; Tue, 1 Feb 2022 07:06:38 -0800 (PST) X-Google-Smtp-Source: ABdhPJxNnxQ4NpyfLV9l8qFnwQPbZap+TxrQDdnnVziVemEtmqQMRfd8KDlULDmWeRG4Y91DQoMs X-Received: by 2002:a17:907:6d8d:: with SMTP id sb13mr21493797ejc.5.1643727998103; Tue, 01 Feb 2022 07:06:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643727998; cv=none; d=google.com; s=arc-20160816; b=XCwe3HRKfMVMsYZc+aJHipvoIQBsvGkcmM7DTs+trMrF+7zwE1MLW56KguOo8R8mOq 5lxqqWi+ZEMgsxl3kPAKQdCqkdeABgfFtYjoAV+ebeULMEXCjV6yX0cdoE+OVZvzYuZO OSXTqFOTsO9NpY4ymrryftEJ/v5wXvmqFUEapPouOiqIEd5ftMZw6H4w2slp3Tf1MxSN FUkdAaQ6Lw+lXnst9MIjNjA9++uKAJneqQt+/z7rNWRbHrihNGzpMVGEVNuQ5VpAiqOW +QmvtVRrqUP+qAma1gqKeSt8pjqlvLicsO2uNqsB1WOvy6r1YHfFlaGSyob7EOG68EeI tbaA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=pN1FjbLFcDO2d9j5qjlwIbSo+FUqNNS/pElCoMXXvWs=; b=QU9VERTkp+6rDCNiQTKVgMajNB/Gjp4veTLkqFw60SsxlPx9Jo1f9Ucaim02tZ+byw zUlp8tfPNaYcNDCT7z6BcmWUxACoabTQT/qKYMTo+4/Tnh00SMIak1NccxjT5apyOxc7 Xfb0Uhe/TNZO6ZiI1WCs07Esp280SwM17VZv6DnEKy8XDPFyf9vHmGUHjNzsi9uzlx6E zcnpFpiUYNYuljWlAFVNxSHFnOnIMRxxsZ5uL/hfMh0zjLnYmOwQruMkpFx/i9B/bRjR P+1ED5+BI8qgKzX8agaJ6o0Wq9eg6zNn0KiVYHtG4VBPMV5lzxhC+jNYDJNntXAhcr7+ 5RCw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=hhWc5HJj; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id b6si10221020edu.231.2022.02.01.07.06.12; Tue, 01 Feb 2022 07:06:38 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=hhWc5HJj; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1356272AbiA3Urb (ORCPT + 99 others); Sun, 30 Jan 2022 15:47:31 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:27681 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1356235AbiA3UrX (ORCPT ); Sun, 30 Jan 2022 15:47:23 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1643575643; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=pN1FjbLFcDO2d9j5qjlwIbSo+FUqNNS/pElCoMXXvWs=; b=hhWc5HJj0GkOcP/Nm9Su6XwDi/hG9Cf/KM5QTMMzezdnHlJ6fhcOWvNFKaXTDzEghyX3/1 q6ukvluEsSjvGQck7LGB7ZfCR+liqPjTKIqw+hrApIwxRkAqohtUpncrDELOLshxGt/cHQ 2C7RRlubl9oTKx8tL5SoQFwcWj6AD7U= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-97-HpJ_GqnCOTeVCsAeaVwJuQ-1; Sun, 30 Jan 2022 15:47:17 -0500 X-MC-Unique: HpJ_GqnCOTeVCsAeaVwJuQ-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id DA2F4835B4D; Sun, 30 Jan 2022 20:47:14 +0000 (UTC) Received: from shalem.redhat.com (unknown [10.39.192.60]) by smtp.corp.redhat.com (Postfix) with ESMTP id 73E5861093; Sun, 30 Jan 2022 20:47:11 +0000 (UTC) From: Hans de Goede To: "Rafael J . Wysocki" , Mika Westerberg , Mark Gross , Andy Shevchenko , Wolfram Sang , Lee Jones , Sebastian Reichel , MyungJoo Ham , Chanwoo Choi , Ard Biesheuvel Cc: Hans de Goede , Len Brown , linux-acpi@vger.kernel.org, Yauhen Kharuzhy , Tsuchiya Yuto , Fabio Aiuto , platform-driver-x86@vger.kernel.org, linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, linux-efi@vger.kernel.org Subject: [PATCH v4 11/20] power: supply: bq25890: On the bq25892 set the IINLIM based on external charger detection Date: Sun, 30 Jan 2022 21:45:48 +0100 Message-Id: <20220130204557.15662-12-hdegoede@redhat.com> In-Reply-To: <20220130204557.15662-1-hdegoede@redhat.com> References: <20220130204557.15662-1-hdegoede@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The bq25892 does not have builtin charger-type detection like the bq25980, there might be some external charger detection capability, which will be modelled as a power_supply class-device supplying the bq25892. Use the usb_type property value from the supplier psy-device to set the input-current-limit (when available). Signed-off-by: Hans de Goede --- drivers/power/supply/bq25890_charger.c | 33 ++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/drivers/power/supply/bq25890_charger.c b/drivers/power/supply/bq25890_charger.c index 637cdd3b6b11..3de72f0fbf3e 100644 --- a/drivers/power/supply/bq25890_charger.c +++ b/drivers/power/supply/bq25890_charger.c @@ -594,6 +594,38 @@ static int bq25890_power_supply_get_property(struct power_supply *psy, return 0; } +/* On the BQ25892 try to get charger-type info from our supplier */ +static void bq25890_charger_external_power_changed(struct power_supply *psy) +{ + struct bq25890_device *bq = power_supply_get_drvdata(psy); + union power_supply_propval val; + int input_current_limit, ret; + + if (bq->chip_version != BQ25892) + return; + + ret = power_supply_get_property_from_supplier(bq->charger, + POWER_SUPPLY_PROP_USB_TYPE, + &val); + if (ret) + return; + + switch (val.intval) { + case POWER_SUPPLY_USB_TYPE_DCP: + input_current_limit = bq25890_find_idx(2000000, TBL_IINLIM); + break; + case POWER_SUPPLY_USB_TYPE_CDP: + case POWER_SUPPLY_USB_TYPE_ACA: + input_current_limit = bq25890_find_idx(1500000, TBL_IINLIM); + break; + case POWER_SUPPLY_USB_TYPE_SDP: + default: + input_current_limit = bq25890_find_idx(500000, TBL_IINLIM); + } + + bq25890_field_write(bq, F_IINLIM, input_current_limit); +} + static int bq25890_get_chip_state(struct bq25890_device *bq, struct bq25890_state *state) { @@ -818,6 +850,7 @@ static const struct power_supply_desc bq25890_power_supply_desc = { .properties = bq25890_power_supply_props, .num_properties = ARRAY_SIZE(bq25890_power_supply_props), .get_property = bq25890_power_supply_get_property, + .external_power_changed = bq25890_charger_external_power_changed, }; static int bq25890_power_supply_init(struct bq25890_device *bq) -- 2.33.1