Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp2661819pxj; Mon, 14 Jun 2021 04:19:04 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzjsqmXLSkcFR0y46VjBHi6L6C+z3XtzOwhMnmHa5nDK6zFb3yuyYA3QD9DDh6xZqhNGQ8/ X-Received: by 2002:a17:906:35db:: with SMTP id p27mr14709724ejb.391.1623669543783; Mon, 14 Jun 2021 04:19:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623669543; cv=none; d=google.com; s=arc-20160816; b=XqBJK/wKhNx+uUcUq9lVz2D4XI1b5UBkjUbGWkkRwH2/inyYzqHWRRI7G2/tXmeZAB 1WVQFKUdsjh5aWKp6zKDB1ouj29VdnoZvjaxZGiaj/zAJdz7gndIbPHkui51WS98PDai LrZhtWoWXCsQ3R4ZnZV9YWkDzGyhYQHOTD1AyJVBEkNFC5CC8Rz3jQmsMKlUDP2HMGLe 5KD9Uzy7hpdBl0+J7PZwyUjWN7MTgAzse4ui1AzZmbHVcT2O9ZzJtJdcJglL2LRYXMoZ MBYm0Etzaj0gMgDMV/cw2mu1c25MBob2OHRGNLFInvCIdynbAAgrA7vBT73bWJfEJPQR aXCA== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=vUm3erlPUR0p+d4hLlNg+133FTk8jgq4YGGxXF7Samc=; b=b4WxTQIBP50fo9tIiO7aMtbBvlApCngPZELKWUyrm9zgQeX0GLeHekRjKdy+56iO0w hkuWSTTNkV98XAgf9mr7T+HgEOPRzMEtotMtUElQ02XIEdnD4/NJ6ZAYoj6TYoHpT6Fy YF8IKNv38UcfCu8Hri9TmguntFQE3HsqRB3/vbYuL64OkprB0QsFi2AskoeekaQX6/9f M4V89fqpoICb4MjbuNGHXsyHO25DVzhqUjDH21FS4tzDAp1x8uUFzFtZK5O1HUtJDjmZ WShM+nY1sbHeD/ZciIN5rcExM5u1XXaNAjq0xli7JxESthPrs/lOV8zJAPU8UutfmEuU 760A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="HppALu/7"; 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=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id l5si11281079ejg.306.2021.06.14.04.18.39; Mon, 14 Jun 2021 04:19:03 -0700 (PDT) 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=@linuxfoundation.org header.s=korg header.b="HppALu/7"; 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=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235345AbhFNLRs (ORCPT + 99 others); Mon, 14 Jun 2021 07:17:48 -0400 Received: from mail.kernel.org ([198.145.29.99]:39058 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235190AbhFNLFD (ORCPT ); Mon, 14 Jun 2021 07:05:03 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 513F26191D; Mon, 14 Jun 2021 10:44:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1623667496; bh=WzbHPJH1jThMmcmFAYZbvNRc1O1KAViqzOLf2jjuhcE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=HppALu/7vNoz/BaHQTyBdqZAh2MR/QrrcfvnSiH4UT/AV0YHhk9YtssJf1g6WcJrQ P8CviZ0hF/f/sHduF573mkZwwQKWnRhP7mH9P/FlV2pEOvBjXUKkpalwHA+o1YATZl AyRjRWh0A4+MGJm7AjO+m/yo5+JuHnWNCpMw6aRw= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Axel Lin , ChiYuan Huang , Mark Brown Subject: [PATCH 5.10 095/131] regulator: rtmv20: Fix .set_current_limit/.get_current_limit callbacks Date: Mon, 14 Jun 2021 12:27:36 +0200 Message-Id: <20210614102656.227724095@linuxfoundation.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210614102652.964395392@linuxfoundation.org> References: <20210614102652.964395392@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Axel Lin commit 86ab21cc39e6b99b7065ab9008c90bec5dec535a upstream. Current code does not set .curr_table and .n_linear_ranges settings, so it cannot use the regulator_get/set_current_limit_regmap helpers. If we setup the curr_table, it will has 200 entries. Implement customized .set_current_limit/.get_current_limit callbacks instead. Fixes: b8c054a5eaf0 ("regulator: rtmv20: Adds support for Richtek RTMV20 load switch regulator") Signed-off-by: Axel Lin Reviewed-by: ChiYuan Huang Link: https://lore.kernel.org/r/20210530124101.477727-1-axel.lin@ingics.com Signed-off-by: Mark Brown Signed-off-by: Greg Kroah-Hartman --- drivers/regulator/rtmv20-regulator.c | 42 +++++++++++++++++++++++++++++++++-- 1 file changed, 40 insertions(+), 2 deletions(-) --- a/drivers/regulator/rtmv20-regulator.c +++ b/drivers/regulator/rtmv20-regulator.c @@ -103,9 +103,47 @@ static int rtmv20_lsw_disable(struct reg return 0; } +static int rtmv20_lsw_set_current_limit(struct regulator_dev *rdev, int min_uA, + int max_uA) +{ + int sel; + + if (min_uA > RTMV20_LSW_MAXUA || max_uA < RTMV20_LSW_MINUA) + return -EINVAL; + + if (max_uA > RTMV20_LSW_MAXUA) + max_uA = RTMV20_LSW_MAXUA; + + sel = (max_uA - RTMV20_LSW_MINUA) / RTMV20_LSW_STEPUA; + + /* Ensure the selected setting is still in range */ + if ((sel * RTMV20_LSW_STEPUA + RTMV20_LSW_MINUA) < min_uA) + return -EINVAL; + + sel <<= ffs(rdev->desc->csel_mask) - 1; + + return regmap_update_bits(rdev->regmap, rdev->desc->csel_reg, + rdev->desc->csel_mask, sel); +} + +static int rtmv20_lsw_get_current_limit(struct regulator_dev *rdev) +{ + unsigned int val; + int ret; + + ret = regmap_read(rdev->regmap, rdev->desc->csel_reg, &val); + if (ret) + return ret; + + val &= rdev->desc->csel_mask; + val >>= ffs(rdev->desc->csel_mask) - 1; + + return val * RTMV20_LSW_STEPUA + RTMV20_LSW_MINUA; +} + static const struct regulator_ops rtmv20_regulator_ops = { - .set_current_limit = regulator_set_current_limit_regmap, - .get_current_limit = regulator_get_current_limit_regmap, + .set_current_limit = rtmv20_lsw_set_current_limit, + .get_current_limit = rtmv20_lsw_get_current_limit, .enable = rtmv20_lsw_enable, .disable = rtmv20_lsw_disable, .is_enabled = regulator_is_enabled_regmap,