Received: by 2002:a25:683:0:0:0:0:0 with SMTP id 125csp326493ybg; Mon, 1 Jun 2020 02:22:05 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxkjrfOrHCT5ZjKlAow9DsxYOx2P9Rb/jBi1Wdejzv0yuYYz8LVgGbrEcbE4h+d9u/XhoWr X-Received: by 2002:a50:cfc4:: with SMTP id i4mr20288592edk.252.1591003324714; Mon, 01 Jun 2020 02:22:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1591003324; cv=none; d=google.com; s=arc-20160816; b=udyO8eegNyZ9KLEJRngsft52Wz/TQqW4gvJPRJqv1vK8QQN5cqh2Q0MUo5kWs1yorZ dPFsA1k8GgxwpBpiliyP/y+QA4a51eYqoX/1AOzIMs2duT8ED8aVvR0uBUMq2iQBUh4R OBBQFeDoCqz+k6acmu+opoZasZZYUtDCY6XPr7GvLR5F9ZLLHHahJlslp2I5CBquSsCO U6dwtY6LXVdA+NSmOt7jFdd4a4cU0yXZxboneTElOO7kDxrNnBggtDi62JeEFqHukQNj nVwL4MlJjNDrbSculbpaSMTRxJXbifYl1NWQw8ml7R1BboKpiig9s0anIcVoA/skuc2O W52g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from; bh=L1rBsNpE5T6/D/FIDDHckYD4420vXpFVeavnU49V9Kw=; b=Bb22tXTdMER/8wiwRtfeHZyEABQfykcvMoiTMhb8kPcDCtISxS7qW8Y944CR9GvVrF IArQy40Jh5ruTBOEHfxUPA6yankkdp08SX9l34TW+FrMp3mViOb8JmzkjCxfQMl0niwV x1NOG/9KDSNgD23Xt47vmzbUq52dRf1k5Xt4RIBn9uXTDRGE7uPOKC7H/C/Ge2eaPWJJ MYkRGbOpzqFzRC/15YnULXCgVQeBV9fEWbs+EQGImkDZoE2D/Lj2S7KzT1eZ612dF41x eeo5Bp0GF9AEObwzyTRWN94s3YwwE/wtE5na9lKsIi0qBixcabsJqlwbom7fJwHvm/w2 pkpQ== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=mellanox.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id c18si10737230ejr.84.2020.06.01.02.21.41; Mon, 01 Jun 2020 02:22:04 -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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=mellanox.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727802AbgFAJTV (ORCPT + 99 others); Mon, 1 Jun 2020 05:19:21 -0400 Received: from mail-il-dmz.mellanox.com ([193.47.165.129]:51578 "EHLO mellanox.co.il" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727935AbgFAJTM (ORCPT ); Mon, 1 Jun 2020 05:19:12 -0400 Received: from Internal Mail-Server by MTLPINE2 (envelope-from vadimp@mellanox.com) with ESMTPS (AES256-SHA encrypted); 1 Jun 2020 12:19:05 +0300 Received: from r-build-lowlevel.mtr.labs.mlnx. (r-build-lowlevel.mtr.labs.mlnx [10.209.0.190]) by labmailer.mlnx (8.13.8/8.13.8) with ESMTP id 0519IsSt003135; Mon, 1 Jun 2020 12:19:05 +0300 From: Vadim Pasternak To: andy@infradead.org, dvhart@infradead.org Cc: platform-driver-x86@vger.kernel.org, linux-kernel@vger.kernel.org, Vadim Pasternak Subject: [PATCH platform-next v1 5/8] platform/mellanox: mlxreg-io: Add support for complex attributes Date: Mon, 1 Jun 2020 12:18:48 +0300 Message-Id: <20200601091851.5491-6-vadimp@mellanox.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20200601091851.5491-1-vadimp@mellanox.com> References: <20200601091851.5491-1-vadimp@mellanox.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Add support for attributes composed from few registers. Such attributes could occupy from 2 to 4 sequential registers. For word size register space complex attribute can occupy up to two register, for byte size - up to four. These attributes can carry, for example, CPLD or FPGA versioning, power consuming info, etcetera. Such registers contain read only data. Signed-off-by: Vadim Pasternak --- drivers/platform/mellanox/mlxreg-io.c | 47 ++++++++++++++++++++++++++--------- 1 file changed, 35 insertions(+), 12 deletions(-) diff --git a/drivers/platform/mellanox/mlxreg-io.c b/drivers/platform/mellanox/mlxreg-io.c index acfaf64ffde6..93dbbe381bc4 100644 --- a/drivers/platform/mellanox/mlxreg-io.c +++ b/drivers/platform/mellanox/mlxreg-io.c @@ -30,6 +30,7 @@ * @mlxreg_io_dev_attr: sysfs sensor device attribute array; * @group: sysfs attribute group; * @groups: list of sysfs attribute group for hwmon registration; + * @regsize: size of a register value; */ struct mlxreg_io_priv_data { struct platform_device *pdev; @@ -39,27 +40,30 @@ struct mlxreg_io_priv_data { struct sensor_device_attribute mlxreg_io_dev_attr[MLXREG_IO_ATT_NUM]; struct attribute_group group; const struct attribute_group *groups[2]; + int regsize; }; static int mlxreg_io_get_reg(void *regmap, struct mlxreg_core_data *data, u32 in_val, - bool rw_flag, u32 *regval) + bool rw_flag, int regsize, u32 *regval) { - int ret; + int i, val, ret; ret = regmap_read(regmap, data->reg, regval); if (ret) goto access_error; /* - * There are three kinds of attributes: single bit, full register's - * bits and bit sequence. For the first kind field mask indicates which - * bits are not related and field bit is set zero. For the second kind - * field mask is set to zero and field bit is set with all bits one. - * No special handling for such kind of attributes - pass value as is. - * For the third kind, field mask indicates which bits are related and - * field bit is set to the first bit number (from 1 to 32) is the bit - * sequence. + * There are four kinds of attributes: single bit, full register's + * bits, bit sequence, bits in few registers For the first kind field + * mask indicates which bits are not related and field bit is set zero. + * For the second kind field mask is set to zero and field bit is set + * with all bits one. No special handling for such kind of attributes - + * pass value as is. For the third kind, field mask indicates which + * bits are related and field bit is set to the first bit number (from + * 1 to 32) is the bit sequence. For the fourth kind - the number of + * registers which should be read for getting an attribute are specified + * through 'data->regnum' field. */ if (!data->bit) { /* Single bit. */ @@ -83,6 +87,21 @@ mlxreg_io_get_reg(void *regmap, struct mlxreg_core_data *data, u32 in_val, /* Clear relevant bits and set them to new value. */ *regval = (*regval & ~data->mask) | in_val; } + } else { + /* + * Some attributes could occupied few registers in case regmap + * bit size is 8 or 16. Compose such attribute from 'regnum' + * registers. Such attributes contain read only data. + */ + if (data->regnum > 1 && !rw_flag) + return -EINVAL; + for (i = 1; i < data->regnum; i++) { + ret = regmap_read(regmap, data->reg + i, &val); + if (ret) + goto access_error; + + *regval |= rol32(val, regsize * i); + } } access_error: @@ -99,7 +118,8 @@ mlxreg_io_attr_show(struct device *dev, struct device_attribute *attr, u32 regval = 0; int ret; - ret = mlxreg_io_get_reg(priv->pdata->regmap, data, 0, true, ®val); + ret = mlxreg_io_get_reg(priv->pdata->regmap, data, 0, true, + priv->regsize, ®val); if (ret) goto access_error; @@ -128,7 +148,7 @@ mlxreg_io_attr_store(struct device *dev, struct device_attribute *attr, return ret; ret = mlxreg_io_get_reg(priv->pdata->regmap, data, input_val, false, - ®val); + priv->regsize, ®val); if (ret) goto access_error; @@ -207,6 +227,9 @@ static int mlxreg_io_probe(struct platform_device *pdev) } priv->pdev = pdev; + priv->regsize = regmap_get_val_bytes(priv->pdata->regmap); + if (priv->regsize < 0) + return priv->regsize; err = mlxreg_io_attr_init(priv); if (err) { -- 2.11.0