Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp2895836yba; Mon, 15 Apr 2019 23:42:37 -0700 (PDT) X-Google-Smtp-Source: APXvYqyHRTgTdbZw/aCdQjshpQnV0eEFCuldwJFFCYiPwKwzRDR+5yVIkgzjNL3iOd/afZNleDp9 X-Received: by 2002:a63:751d:: with SMTP id q29mr75617696pgc.215.1555396957789; Mon, 15 Apr 2019 23:42:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1555396957; cv=none; d=google.com; s=arc-20160816; b=P8WrEFNK6ISs69uD/vT7VAAWNze1SDgdACsRajGle56r4a3t7NWeWRmYDAAbF11QAT AElwJiWuLeTF1k/BW7IVWgK3QgEBIEHw2okAmCC3rjXyWBitzGCqB4l/1NoevDM2eq3Q 73oQBFa2bk0iWIBLM+jj5IZ23AASQ2YKHADzNeSq5jHOyfjsgRmyR2/VXxsxUc7z5BUh 8hYKOW0U0rbOZe6HG0g6m48EJFBFhwXfYsmEl6ll2YCEEaxwePWTRxrWclwCAj9kgESH XmOEuxcVOKmRH0NQnK1OqoegXaWv4jD7Y9arRfLsTfSyZwn/P9pDMSe1fPTbf7IGR2iF ia8Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=Nbwzwh/2WSo19Cx/NOf4ONu1zaJ+9VqQg95JHqPrcPQ=; b=aNXh2lGfdeICta0bw2doOYeW/UhTSMiCYgpd1yi2M2xI9V09iCW5qpaBq6QRoyGt4q q3qK7xorQvANkn7dL+mwYlmriIVd5ompfY3ZqzF7QqDg+mXQe8SKOndy6LGvfBur2onc l4ZDRV9XtULla/Q8eiMnGXrRmaRY5se6bNW+mBqWIxbSHP1RnO2BzRAqbMVDjd0JMRVk AVxUMXPpJUyRRS72PSBVQOYkm6Lyygxc+/RP9nwB0zwG1WFjU/TTHcyx1czU/EhAhh+t 8XOu4r56X4OLF7aR/B+ek8LF19BpPcd4bDJzdaHoz0t9OMCTZh1BGUpVYlFfZdVnkH11 CJeg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id i40si28522492plb.177.2019.04.15.23.42.22; Mon, 15 Apr 2019 23:42:37 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728464AbfDPGlE (ORCPT + 99 others); Tue, 16 Apr 2019 02:41:04 -0400 Received: from mirror2.csie.ntu.edu.tw ([140.112.30.76]:34020 "EHLO wens.csie.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728412AbfDPGkb (ORCPT ); Tue, 16 Apr 2019 02:40:31 -0400 Received: by wens.csie.org (Postfix, from userid 1000) id A4108602AD; Tue, 16 Apr 2019 14:40:25 +0800 (CST) From: Chen-Yu Tsai To: Maxime Ripard , Sebastian Reichel Cc: Quentin Schulz , linux-pm@vger.kernel.org, devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-sunxi@googlegroups.com, Hans de Goede , Chen-Yu Tsai Subject: [PATCH v4 5/7] power: supply: axp20x_usb_power: add support for AXP813 Date: Tue, 16 Apr 2019 14:40:22 +0800 Message-Id: <20190416064024.20414-6-wens@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190416064024.20414-1-wens@kernel.org> References: <20190416064024.20414-1-wens@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Quentin Schulz This adds support for AXP813 PMIC. It is almost the same as AXP22X but has a different current limit. Signed-off-by: Quentin Schulz Signed-off-by: Chen-Yu Tsai --- drivers/power/supply/axp20x_usb_power.c | 66 ++++++++++++++++++++++++- 1 file changed, 65 insertions(+), 1 deletion(-) diff --git a/drivers/power/supply/axp20x_usb_power.c b/drivers/power/supply/axp20x_usb_power.c index 04c2cafbe8e6..d2b1255ee1cc 100644 --- a/drivers/power/supply/axp20x_usb_power.c +++ b/drivers/power/supply/axp20x_usb_power.c @@ -42,6 +42,11 @@ #define AXP20X_VBUS_CLIMIT_100mA 2 #define AXP20X_VBUS_CLIMIT_NONE 3 +#define AXP813_VBUS_CLIMIT_900mA 0 +#define AXP813_VBUS_CLIMIT_1500mA 1 +#define AXP813_VBUS_CLIMIT_2000mA 2 +#define AXP813_VBUS_CLIMIT_2500mA 3 + #define AXP20X_ADC_EN1_VBUS_CURR BIT(2) #define AXP20X_ADC_EN1_VBUS_VOLT BIT(3) @@ -131,6 +136,31 @@ static int axp20x_get_current_max(struct axp20x_usb_power *power, int *val) return 0; } +static int axp813_get_current_max(struct axp20x_usb_power *power, int *val) +{ + unsigned int v; + int ret = regmap_read(power->regmap, AXP20X_VBUS_IPSOUT_MGMT, &v); + + if (ret) + return ret; + + switch (v & AXP20X_VBUS_CLIMIT_MASK) { + case AXP813_VBUS_CLIMIT_900mA: + *val = 900000; + break; + case AXP813_VBUS_CLIMIT_1500mA: + *val = 1500000; + break; + case AXP813_VBUS_CLIMIT_2000mA: + *val = 2000000; + break; + case AXP813_VBUS_CLIMIT_2500mA: + *val = 2500000; + break; + } + return 0; +} + static int axp20x_usb_power_get_property(struct power_supply *psy, enum power_supply_property psp, union power_supply_propval *val) { @@ -169,6 +199,8 @@ static int axp20x_usb_power_get_property(struct power_supply *psy, val->intval = ret * 1700; /* 1 step = 1.7 mV */ return 0; case POWER_SUPPLY_PROP_CURRENT_MAX: + if (power->axp20x_id == AXP813_ID) + return axp813_get_current_max(power, &val->intval); return axp20x_get_current_max(power, &val->intval); case POWER_SUPPLY_PROP_CURRENT_NOW: if (IS_ENABLED(CONFIG_AXP20X_ADC)) { @@ -260,6 +292,31 @@ static int axp20x_usb_power_set_voltage_min(struct axp20x_usb_power *power, return -EINVAL; } +static int axp813_usb_power_set_current_max(struct axp20x_usb_power *power, + int intval) +{ + int val; + + switch (intval) { + case 900000: + return regmap_update_bits(power->regmap, + AXP20X_VBUS_IPSOUT_MGMT, + AXP20X_VBUS_CLIMIT_MASK, + AXP813_VBUS_CLIMIT_900mA); + case 1500000: + case 2000000: + case 2500000: + val = (intval - 1000000) / 500000; + return regmap_update_bits(power->regmap, + AXP20X_VBUS_IPSOUT_MGMT, + AXP20X_VBUS_CLIMIT_MASK, val); + default: + return -EINVAL; + } + + return -EINVAL; +} + static int axp20x_usb_power_set_current_max(struct axp20x_usb_power *power, int intval) { @@ -294,6 +351,9 @@ static int axp20x_usb_power_set_property(struct power_supply *psy, return axp20x_usb_power_set_voltage_min(power, val->intval); case POWER_SUPPLY_PROP_CURRENT_MAX: + if (power->axp20x_id == AXP813_ID) + return axp813_usb_power_set_current_max(power, + val->intval); return axp20x_usb_power_set_current_max(power, val->intval); default: @@ -429,7 +489,8 @@ static int axp20x_usb_power_probe(struct platform_device *pdev) usb_power_desc = &axp20x_usb_power_desc; irq_names = axp20x_irq_names; } else if (power->axp20x_id == AXP221_ID || - power->axp20x_id == AXP223_ID) { + power->axp20x_id == AXP223_ID || + power->axp20x_id == AXP813_ID) { usb_power_desc = &axp22x_usb_power_desc; irq_names = axp22x_irq_names; } else { @@ -488,6 +549,9 @@ static const struct of_device_id axp20x_usb_power_match[] = { }, { .compatible = "x-powers,axp223-usb-power-supply", .data = (void *)AXP223_ID, + }, { + .compatible = "x-powers,axp813-usb-power-supply", + .data = (void *)AXP813_ID, }, { /* sentinel */ } }; MODULE_DEVICE_TABLE(of, axp20x_usb_power_match); -- 2.20.1