Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp38214973rwd; Wed, 12 Jul 2023 04:56:01 -0700 (PDT) X-Google-Smtp-Source: APBJJlH56SzLJU7Yx2B5frrcLI8cC1iXsYFoGmUuLlQrUqUt/OBXFLFMGjGDzqklg5s/EJls43vy X-Received: by 2002:a17:906:3f44:b0:992:3897:1985 with SMTP id f4-20020a1709063f4400b0099238971985mr15643921ejj.43.1689162961655; Wed, 12 Jul 2023 04:56:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689162961; cv=none; d=google.com; s=arc-20160816; b=CbIfx1utkEAPuwQMv75eZ5L3CYfR/99LdB3YCb8KgpZCBOpS1v4jcT4vNbeb4JCJMD SKTYUTLnu/8Afh/avyxTrMRNznnXVRHS7OkuVELvhhxSth85unYO0STI8PfoCb+uNXxI ojFa47Qtt5MKX/Da3yNe8NKEUqcnLefRv6rlRP7OGvx/E/P8maXtX3xyHzswY8jV238t Jzf2QjA+wTD8HhlqobH0nb5zm+10x+2tg9l6uTLYUEUtFifoe6suC8NQSaIXP6jxyQML w5LNRPWzyV2ec8IWHePgNzjS6Jk/cnkyxoR5MoQkLS7OHmY5mrVXl3GtC8RVx83+2KTM Qx0g== 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=dQ6ZilaXIbXVvZQf4zwkqGWFB61+kWs1K8oV/rSXRlI=; fh=JUrxmAGZpf2um0PJXMa+5wJ3JrTNc+xhv0SKeec5FHw=; b=Ax6JwrBGKjx7//ygZDgMxvcWyPhrX+Prnv6BfEkFOQVJQ9Bt1WrRCGdxInL6F5PfWP CQSSreXuAgxBH88Hb5a9E6eH0A9LYdbP3GlxTJfgVeyqUjrOrhBI5FLHi7wacvQP6x6W 8tRSVfM4ye4rur1BqEg98CDgHZo5w1OXkGIrtYDul/Mk9FSZQGFH+sUhHci900UqBECz kx4kfZouzvoZPnz/4YN+ZIMngLtbT50TDaFwZgd1Mr5SWewncfX6FQrohX5xKqj9iolD Rl3j/OgE948qy+3GM2BVQKFrHN49u5u0bFyyYLJh3dPXjq3yvJe/w8i4/qE8EmMUvyXr EXNA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@9elements.com header.s=google header.b=XOpzP0vY; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=9elements.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id l10-20020a17090612ca00b00992ee6da8e7si4449294ejb.740.2023.07.12.04.55.37; Wed, 12 Jul 2023 04:56:01 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@9elements.com header.s=google header.b=XOpzP0vY; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=9elements.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232650AbjGLLuB (ORCPT + 99 others); Wed, 12 Jul 2023 07:50:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38452 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233270AbjGLLtG (ORCPT ); Wed, 12 Jul 2023 07:49:06 -0400 Received: from mail-wr1-x432.google.com (mail-wr1-x432.google.com [IPv6:2a00:1450:4864:20::432]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 057E82115 for ; Wed, 12 Jul 2023 04:48:24 -0700 (PDT) Received: by mail-wr1-x432.google.com with SMTP id ffacd0b85a97d-3159d75606dso3164441f8f.1 for ; Wed, 12 Jul 2023 04:48:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=9elements.com; s=google; t=1689162499; x=1691754499; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=dQ6ZilaXIbXVvZQf4zwkqGWFB61+kWs1K8oV/rSXRlI=; b=XOpzP0vYSGIErNEX8B6llRYPeraEJcKzdS/EX9s5HRTGB71CQnA/5+MiaJwWc3+b2+ +F85ToEAhR8B0ke0RQMa2P8gg7phxnD2jDFISVC9pdYWzyXqiziUbOi98tPjXpbTPCQg 7KNjyA0YhWhIPHE+rK+IQMNo4l+n/yMysGcu6g24JozD2Ulf3rwhi9Mox8srl1P2Ao9G kBPPF+WRUR7IHxOSdBw11V0xDqbkKJJ+GQlN27pw2RSk+9dVtuDxjAmodIHEJQyXxnJ+ iFJPvsi6HJYgjfBn5Z4WlN6YYIIzg0Y4Cm2fn4pQQ3CeKwiGQvq8bmMG+vOKDimsE5l3 eJGw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689162499; x=1691754499; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=dQ6ZilaXIbXVvZQf4zwkqGWFB61+kWs1K8oV/rSXRlI=; b=gxjAwSbl9/L6yzbIKXQt33MwuleuDb7LZ6fwzh1KCngwAOICBKTTxPtmnnHqyykQNm STjFGhrVqKEq4sQjdUZTU5N9ui00eMQSZ1X6zB/hwzkFDhe+8B9znQcb0j7ECffVc/vf bIXxnc2bgqM1LPPPgqRFRDBNVC+WVxOUa5vCiP+DuKNzFb2MLDIJ0w5tRXjvIq4IMX3m evsY+hHHp1LTlaKT/+ucEL+f1Guba5MbwoG007EkPx+iCaMS1uIdmen9KWIKr5ybgJ78 bZ8KG3EKuxk1+vOG50COiDGp7yc+6DdxnKDmwal3cWuhYX+RwvHGkGy/7CKdYYS0q81q ZpfA== X-Gm-Message-State: ABy/qLboUUYJxcPQYc4xW/lNmmaO+2Yk++WQlJLmgStkWnZZvWgLbTt2 JDpy5NzHSfPkcJ8zXnf11eFtZbMWytV6ytxOVAko6A== X-Received: by 2002:a05:6000:4c5:b0:314:1d7f:a69 with SMTP id h5-20020a05600004c500b003141d7f0a69mr17088296wri.67.1689162499157; Wed, 12 Jul 2023 04:48:19 -0700 (PDT) Received: from stroh80.sec.9e.network (ip-078-094-000-051.um19.pools.vodafone-ip.de. [78.94.0.51]) by smtp.gmail.com with ESMTPSA id j2-20020a5d4482000000b003143867d2ebsm4867463wrq.63.2023.07.12.04.48.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Jul 2023 04:48:18 -0700 (PDT) From: Naresh Solanki X-Google-Original-From: Naresh Solanki To: devicetree@vger.kernel.org, Guenter Roeck , Jean Delvare Cc: linux-kernel@vger.kernel.org, linux-hwmon@vger.kernel.org, Patrick Rudolph , Naresh Solanki Subject: [PATCH 5/8] hwmon: (pmbus/mp2975) Make phase count variable Date: Wed, 12 Jul 2023 13:47:46 +0200 Message-ID: <20230712114754.500477-5-Naresh.Solanki@9elements.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230712114754.500477-1-Naresh.Solanki@9elements.com> References: <20230712114754.500477-1-Naresh.Solanki@9elements.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Patrick Rudolph In order to add support for MP2973 and MP2971 replace hardcoded phase count for both channels by a variable. Signed-off-by: Patrick Rudolph Signed-off-by: Naresh Solanki --- drivers/hwmon/pmbus/mp2975.c | 33 ++++++++++++++++++++------------- 1 file changed, 20 insertions(+), 13 deletions(-) diff --git a/drivers/hwmon/pmbus/mp2975.c b/drivers/hwmon/pmbus/mp2975.c index ebc9a84b8ad3..13d8b95eb992 100644 --- a/drivers/hwmon/pmbus/mp2975.c +++ b/drivers/hwmon/pmbus/mp2975.c @@ -61,10 +61,15 @@ enum chips { mp2975 }; +static const int mp2975_max_phases[][MP2975_PAGE_NUM] = { + [mp2975] = { MP2975_MAX_PHASE_RAIL1, MP2975_MAX_PHASE_RAIL2 }, +}; + struct mp2975_data { struct pmbus_driver_info info; enum chips chip_id; int vout_scale; + int max_phases[MP2975_PAGE_NUM]; int vid_step[MP2975_PAGE_NUM]; int vref[MP2975_PAGE_NUM]; int vref_off[MP2975_PAGE_NUM]; @@ -304,25 +309,25 @@ static int mp2975_read_word_data(struct i2c_client *client, int page, return ret; } -static int mp2975_identify_multiphase_rail2(struct i2c_client *client) +static int mp2975_identify_multiphase_rail2(struct i2c_client *client, + struct mp2975_data *data) { int ret; /* - * Identify multiphase for rail 2 - could be from 0 to 4. + * Identify multiphase for rail 2 - could be from 0 to data->max_phases[1]. * In case phase number is zero – only page zero is supported */ ret = i2c_smbus_write_byte_data(client, PMBUS_PAGE, 2); if (ret < 0) return ret; - /* Identify multiphase for rail 2 - could be from 0 to 4. */ ret = i2c_smbus_read_word_data(client, MP2975_MFR_VR_MULTI_CONFIG_R2); if (ret < 0) return ret; ret &= GENMASK(2, 0); - return (ret >= 4) ? 4 : ret; + return (ret >= data->max_phases[1]) ? data->max_phases[1] : ret; } static void mp2975_set_phase_rail1(struct pmbus_driver_info *info) @@ -353,7 +358,7 @@ mp2975_identify_multiphase(struct i2c_client *client, struct mp2975_data *data, if (ret < 0) return ret; - /* Identify multiphase for rail 1 - could be from 1 to 8. */ + /* Identify multiphase for rail 1 - could be from 1 to data->max_phases[0]. */ ret = i2c_smbus_read_word_data(client, MP2975_MFR_VR_MULTI_CONFIG_R1); if (ret <= 0) return ret; @@ -361,19 +366,19 @@ mp2975_identify_multiphase(struct i2c_client *client, struct mp2975_data *data, info->phases[0] = ret & GENMASK(3, 0); /* - * The device provides a total of 8 PWM pins, and can be configured + * The device provides a total of $n PWM pins, and can be configured * to different phase count applications for rail 1 and rail 2. - * Rail 1 can be set to 8 phases, while rail 2 can only be set to 4 - * phases at most. When rail 1’s phase count is configured as 0, rail + * Rail 1 can be set to $n phases, while rail 2 can be set to less than + * that. When rail 1’s phase count is configured as 0, rail * 1 operates with 1-phase DCM. When rail 2 phase count is configured * as 0, rail 2 is disabled. */ - if (info->phases[0] > MP2975_MAX_PHASE_RAIL1) + if (info->phases[0] > data->max_phases[0]) return -EINVAL; mp2975_set_phase_rail1(info); - num_phases2 = min(MP2975_MAX_PHASE_RAIL1 - info->phases[0], - MP2975_MAX_PHASE_RAIL2); + num_phases2 = min(data->max_phases[0] - info->phases[0], + data->max_phases[1]); if (info->phases[1] && info->phases[1] <= num_phases2) mp2975_set_phase_rail2(info, num_phases2); @@ -671,11 +676,13 @@ static int mp2975_probe(struct i2c_client *client) else data->chip_id = i2c_match_id(mp2975_id, client)->driver_data; - memcpy(&data->info, &mp2975_info, sizeof(*info)); + memcpy(data->max_phases, mp2975_max_phases[data->chip_id], + sizeof(data->max_phases)); + info = &data->info; /* Identify multiphase configuration for rail 2. */ - ret = mp2975_identify_multiphase_rail2(client); + ret = mp2975_identify_multiphase_rail2(client, data); if (ret < 0) return ret; -- 2.41.0