Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp1859218pxj; Sun, 30 May 2021 05:43:48 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwF3bEO46azBBLDl/nLcZJjfFSY+yCQFm3QmhB7p/jQ0Ga1V+9Y2HL6ipCrb/612j40YPGv X-Received: by 2002:a17:906:56ca:: with SMTP id an10mr5980012ejc.328.1622378628091; Sun, 30 May 2021 05:43:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1622378628; cv=none; d=google.com; s=arc-20160816; b=W6RAzSOvE71ACQ/l4M8q7R2w4TZ47lQC2CxlOynf0oRCPu0KeEiXAC12CZPoWlDnIm cEG+HbUpIXtygG46waMejTXnN/8KEm1fFUM22CZZV93fJP57Ed3mfubCvLgGEvw4jpf1 8JPdBQR+5K2W4uGiMoQLY0/6GmU8kGGKtYrvKSxfh6LxO5KHMQn9Q/xt9Dzgj/48YG8T laRQ4DjIW0eHrDFOIZu3KZvSLmfAeWwErx3gsuJglRJbn3eKbiJdMMfbwCybpPnzU/kP TGIZZtjBq60BnyrorhThY2FIzUchfTkp9LTEtkuKNquU3l2VWl16bNZQlGKcUoMjtCGB 64ow== 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 :message-id:date:subject:cc:to:from:dkim-signature; bh=yEm2IiRLQFheRXp4oiBPyjN0y451oAuF0ZcGpstUmjE=; b=NUofcPdTuB54W1B/lSnI+FT+AbE+CGEL5CIiAEhJywfez8ecNFxzcziLa9Ru/QB8do aE3UvL5cuy2DPjQXcWM+7Dr7HBsL7GCbjR/5RoHzggPWXoz8z7tyQNby5Dl5xjM1vnYC CpZalrdptospKUU8mWYPfLLp6oGabrqL4JWCJHxf46fYhaH78rvA4TDtuP05XG1B4n5q iFexswE6vB6LiXO/GBL0ImES+HmfOcBvdV/GDSU0Drd25cXmp83753y9e+bph364Ujeg 22w2QYzWu96Xr0/RAtLtlLXty/T5Rdvhi8CKnLchyx8PD3yw5bGg1stN6JBkeKzmU/wu 7/rA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ingics-com.20150623.gappssmtp.com header.s=20150623 header.b=GIUgOuAh; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id a6si9463630edk.546.2021.05.30.05.43.24; Sun, 30 May 2021 05:43:48 -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=@ingics-com.20150623.gappssmtp.com header.s=20150623 header.b=GIUgOuAh; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229682AbhE3Mmy (ORCPT + 99 others); Sun, 30 May 2021 08:42:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42446 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229500AbhE3Mmy (ORCPT ); Sun, 30 May 2021 08:42:54 -0400 Received: from mail-pg1-x536.google.com (mail-pg1-x536.google.com [IPv6:2607:f8b0:4864:20::536]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C9B13C061574 for ; Sun, 30 May 2021 05:41:14 -0700 (PDT) Received: by mail-pg1-x536.google.com with SMTP id j12so6265180pgh.7 for ; Sun, 30 May 2021 05:41:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ingics-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=yEm2IiRLQFheRXp4oiBPyjN0y451oAuF0ZcGpstUmjE=; b=GIUgOuAhGj6VnkrYw2OsLR5ggSVOrNMkwUmgiXnzWJFXQgAcFF9vtKgPjNM+yrr8iM OTSHGvJ330awNMzvHTkjP4SDRjZwtRFQ6YI9LAMyLnD51KfhR+ratORXziSzDgnLZet5 ROMe7kCbl8Reh3zm0vvKenDDt6iJfliNpMYEBJwH99E09GQswMlKubpIM5awIp0l6/oH KjqkrcZa+dULo+sSHgDGjpEfpoez2RZk4QKn+6WzBvghqpDe2hk8tOSLI63y85Dmk0TH lMkpDE6qfRuWOQv4GB1BlbNaspqWzoX+m3cRZXOms2M9FI8BQAMlm8jHsNPJHDU/0cKh wuEg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=yEm2IiRLQFheRXp4oiBPyjN0y451oAuF0ZcGpstUmjE=; b=Hfh2ezsPr/cyYDXgDs8fGM/a1zhlajtns/L8uDdMeDXr+DS6iX+k5PMo6HcC2THPTN tXuMf/yeaPcw07IxmbNXqC8Enz9tljw/0JsZb3ohTxOm6iCtd9u0iN6qq7aR2n2cc/tR asbdwnjXRlEzBtz6W8ZrELWyvAPbItnzkXQqYeAbvcROJRUbAJGrHENwxen3HixaNTDn VyhmH33R6VoI12XjS44MLGes631TOIotYh7I3KBQZ8N/A+3uIFD75Waxwl0bDjzbO95C 0xKdknoynnGNyVvaV5Sza2UXRswcpaFX1jc6siXZZ/sVBzX4z9PagT/xmNduxgCkJ+L2 R8cQ== X-Gm-Message-State: AOAM533QTQzOOu5RZsmPmqUYLr/dmn+6/dNrHzx/btjGcq2dYTZQu15d Owj+1vZA7Ge9aNOYwE+d44lY63RMlvJqaHBL X-Received: by 2002:a65:584d:: with SMTP id s13mr18276277pgr.97.1622378473988; Sun, 30 May 2021 05:41:13 -0700 (PDT) Received: from localhost.localdomain (122-117-179-2.HINET-IP.hinet.net. [122.117.179.2]) by smtp.gmail.com with ESMTPSA id c11sm8661658pjr.32.2021.05.30.05.41.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 30 May 2021 05:41:13 -0700 (PDT) From: Axel Lin To: Mark Brown Cc: ChiYuan Huang , Liam Girdwood , linux-kernel@vger.kernel.org, Axel Lin Subject: [PATCH RFT 1/2] regulator: rtmv20: Fix .set_current_limit/.get_current_limit callbacks Date: Sun, 30 May 2021 20:41:00 +0800 Message-Id: <20210530124101.477727-1-axel.lin@ingics.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- Hi ChiYuan, I don't have this h/w to test. Please help to review and test this patch. Thanks, Axel drivers/regulator/rtmv20-regulator.c | 42 ++++++++++++++++++++++++++-- 1 file changed, 40 insertions(+), 2 deletions(-) diff --git a/drivers/regulator/rtmv20-regulator.c b/drivers/regulator/rtmv20-regulator.c index 852fb2596ffd..5adc552dffd5 100644 --- a/drivers/regulator/rtmv20-regulator.c +++ b/drivers/regulator/rtmv20-regulator.c @@ -103,9 +103,47 @@ static int rtmv20_lsw_disable(struct regulator_dev *rdev) 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, -- 2.25.1