From patchwork Thu Jan 9 04:35:45 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Baryshkov X-Patchwork-Id: 13932029 Received: from mail-lf1-f42.google.com (mail-lf1-f42.google.com [209.85.167.42]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 087B32080C9 for ; Thu, 9 Jan 2025 04:35:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.42 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736397356; cv=none; b=REmVCzS6DPRGoIicxScJzkmgiwjXIThiRYGC1qC9ngrnaAMGbBCsNNs43UaKzOuXeZBJQe8X64I2C6IRn6n+S4OhXBarHgyXCdzcc7m+4lU9AewyMmoJxbn57LkZnPGH5pI1QG3Hpf8cL/Pdq2qk1o3AvRvcrQpfKqME6rf1vug= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736397356; c=relaxed/simple; bh=28lfeP0elk+tC/FtwJpVo5ll99ssX0YY1tno5A6BThw=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=hXt5ruE0MQboMOjgdGCjZTI7l+Z0IH/UNn2co+ZpfrWw1hTkKinZDvx0djpK8hjTHC2yRDFW5usvJ5EzxiiRaZlbW85OIzfqZ8DKidOhCjVdZljtIwVz7IViCNlOI7jEey7qNIchfuiVbf79+afjuqmWD7Em0idQ7WhetRsa34k= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=nuBlyRML; arc=none smtp.client-ip=209.85.167.42 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="nuBlyRML" Received: by mail-lf1-f42.google.com with SMTP id 2adb3069b0e04-540215984f0so543159e87.1 for ; Wed, 08 Jan 2025 20:35:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1736397353; x=1737002153; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=eQ7Ey0366JcxuGYyhKacm3wyhGFkT3OGK/0czjEyhxY=; b=nuBlyRMLiarLwassnGCzdJAh+bF7sO3ZQjdH5C+6tpvQ18dH0SlFt61fFqn/Rapk16 I8+1zVMK3Gl2CuOaR8EmSUnamLbRGRT1Rqg3f25TgFy5BjfvF4qjQgg3h/d6E0KzM7cG g5gxbAZkJis2QPe5iHameL2NZP7zY1IiPnG+786wufRaS2T1NBf/00L22z34qj5yzmAJ 12/CRuJPOCOZtog1if5/kPw2gt/MpJTmKG7LRQJvPpqFyCrYDbM3Hl4/oDaOif4GOehN amSTVEub5WQzJl5ANEJDNe69YfhCivaL1OISwvJkk0PuJjA3XgRlNxAc4UBsbuLNKrRB DyAg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736397353; x=1737002153; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=eQ7Ey0366JcxuGYyhKacm3wyhGFkT3OGK/0czjEyhxY=; b=BnSCuX4Y7sOvfuLSertAAbWsqCoS5QksifzC+rJKitzfw0AifPhSNoDQHPYfvFzeTk Hj9yBPCT8n+ZuNTCrg6bpvTuRk0ldA+sixhIEfUvRKbAWBhAcW22vzpNIceEgO8E+FZa QlAZmhTfQ7iVEws6Z/SF1CxH0c8pJGiSwIqyD9Too0EVhrzRrcR5XimFF4ZfNF6FeFOY Dh/KxIIJrALvGxVE/xj1qhZk430CmCstx9slFww8XVQGtuYZ5At3oEe+tv27TdmIwfBF 21FmVG2vRH5atMBHMNrbnQe28nwSSrQtETHfeX0SPyBA+KPECaRbRCB4fkhd98HhuKGU svPA== X-Forwarded-Encrypted: i=1; AJvYcCV85N+05aj04x0t9M+XeuSc3ZAg0lPqncqZiGp3+0hKLPV7P+RCpT2DN7rDhYITC2/kGp6K5oFSQeOHwhiR@vger.kernel.org X-Gm-Message-State: AOJu0Yy6pjXUNLKYy0U6FFPo1ydHxzGK68m8V37BK2Q9JDze2C4V1d50 qqyuSfaVu1Ia7wcEuMIJ0p22jpJSCHbslBrUjD2xkc33LTpsaPyD4SKHa+8laIQ= X-Gm-Gg: ASbGncuoGLEFX+zVb2TZ4EeuQ72YY3lN0GtWK4/Y4RtOehGOdzzKFn63nvD8wb6Ad4R 6D5C9iDthSHFzQNicCPdvjPTCjD9dD4PUXuUiqeXTjRwK1HzyVBtwh6fQEfClzg01sxLsRPZjkJ Ie238WjyNyVLzZblBhCnLrBB/ABQj85bcJ8upLV9m2x6YAl+OeA75tpk8HcPtTWaHSAJmMAn6z2 8VDAP0E+MdI+u0MVZJPRhyvnAoTAUUXRxMBF3STNs/LQSiLqp41aNSZpsuePUpU+btZO+af4NH6 Ed0VUNKHizuveoiMI6FOomj9 X-Google-Smtp-Source: AGHT+IG9P/BrUEzkdO3YjTFb4jKbXMe/fdiSuMkgWi8w/KxHUDnAYQ26vw2dH69lK6mbTLmORDlxjA== X-Received: by 2002:a05:6512:3192:b0:53e:335e:7756 with SMTP id 2adb3069b0e04-54284815d10mr1450834e87.46.1736397353005; Wed, 08 Jan 2025 20:35:53 -0800 (PST) Received: from [127.0.1.1] (2001-14ba-a0c3-3a00--782.rev.dnainternet.fi. [2001:14ba:a0c3:3a00::782]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-5428bec06e1sm73866e87.191.2025.01.08.20.35.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Jan 2025 20:35:52 -0800 (PST) From: Dmitry Baryshkov Date: Thu, 09 Jan 2025 06:35:45 +0200 Subject: [PATCH v4 1/5] nvmem: core: fix bit offsets of more than one byte Precedence: bulk X-Mailing-List: linux-arm-msm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20250109-sar2130p-nvmem-v4-1-633739fe5f11@linaro.org> References: <20250109-sar2130p-nvmem-v4-0-633739fe5f11@linaro.org> In-Reply-To: <20250109-sar2130p-nvmem-v4-0-633739fe5f11@linaro.org> To: Srinivas Kandagatla , Rob Herring , Krzysztof Kozlowski , Conor Dooley Cc: Akhil P Oommen , linux-arm-msm@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=2178; i=dmitry.baryshkov@linaro.org; h=from:subject:message-id; bh=28lfeP0elk+tC/FtwJpVo5ll99ssX0YY1tno5A6BThw=; b=owEBbQKS/ZANAwAKARTbcu2+gGW4AcsmYgBnf1IjOYS2hG2FXUXbR7hTDfuUum1vNcR6hSs2u 0caXs+FDT2JAjMEAAEKAB0WIQRdB85SOKWMgfgVe+4U23LtvoBluAUCZ39SIwAKCRAU23LtvoBl uHVeD/9UumRB6poWTUCyfIZtKnmWF+AJy9MH2f3Do2WizXmDzFk4eUe+J4CIiqGvAIC4TXLRkkd EhK1+bETRA2IZKUvIjpwVj4j90Ee9DM6PKfH7UMIr3qH7nSibGnDoVeqF0zHs2OOT8fPzPIRkc1 NazeYfz2O0RsIRUyEkp/ExPbargr2iYPg+rT7/MLa2k52S0OQh+KcjJ2Py5gatggYzBHEC348gx eENbyNOmrHC4PqEBzf4eBh1caw8jcDacmQJo/ueWp9NNbIHaR2OX0jkH4JWZ2Z4zkOdXpa9s3Pg OFrIcGjW6sOrWVfDw/YtCEwLgrO2B2s+m6AkdrvTMjk9rzIi27FQ3cM9WA5doFyguC5fYCeM4Op WLtIbzjNawxE3XUJDfTKpRGQWyKHXuCojiQ5C6T277EbWjC61hwrw6jsedr8nbz0fvsEIH/OymX aXdFeGlFQXfqh8uNkYxsGxeyfeBqs+OohHDqmPQbzlySYG22kVKG9P2MEf9l1I+2UB9NbQyRJYA hYykNLoMVrIbCi9tR/9wLorq2KeKJbySZvU3sCOp7dWbfZyGgXRNmJgFxGfQaeXO9c7KsjAgc5s A5JXCguP2ou5fwaxuZXazHPl48xSkZCgJNT1h0+tqtr54nJz1ZwKyd1luMy+r73xXV909Tl9j4K FcoxU8hCJfgWanA== X-Developer-Key: i=dmitry.baryshkov@linaro.org; a=openpgp; fpr=8F88381DD5C873E4AE487DA5199BF1243632046A If the NVMEM specifies a stride to access data, reading particular cell might require bit offset that is bigger than one byte. Rework NVMEM core code to support bit offsets of more than 8 bits. Signed-off-by: Dmitry Baryshkov --- drivers/nvmem/core.c | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c index d6494dfc20a7324bde6415776dcabbb0bfdd334b..7fa85b0804db360035d7471002dbf79658d5830b 100644 --- a/drivers/nvmem/core.c +++ b/drivers/nvmem/core.c @@ -834,7 +834,9 @@ static int nvmem_add_cells_from_dt(struct nvmem_device *nvmem, struct device_nod if (addr && len == (2 * sizeof(u32))) { info.bit_offset = be32_to_cpup(addr++); info.nbits = be32_to_cpup(addr); - if (info.bit_offset >= BITS_PER_BYTE || info.nbits < 1) { + if (info.bit_offset >= BITS_PER_BYTE * info.bytes || + info.nbits < 1 || + info.bit_offset + info.nbits > BITS_PER_BYTE * info.bytes) { dev_err(dev, "nvmem: invalid bits on %pOF\n", child); of_node_put(child); return -EINVAL; @@ -1627,21 +1629,29 @@ EXPORT_SYMBOL_GPL(nvmem_cell_put); static void nvmem_shift_read_buffer_in_place(struct nvmem_cell_entry *cell, void *buf) { u8 *p, *b; - int i, extra, bit_offset = cell->bit_offset; + int i, extra, bytes_offset; + int bit_offset = cell->bit_offset; p = b = buf; - if (bit_offset) { + + bytes_offset = bit_offset / BITS_PER_BYTE; + b += bytes_offset; + bit_offset %= BITS_PER_BYTE; + + if (bit_offset % BITS_PER_BYTE) { /* First shift */ - *b++ >>= bit_offset; + *p = *b++ >> bit_offset; /* setup rest of the bytes if any */ for (i = 1; i < cell->bytes; i++) { /* Get bits from next byte and shift them towards msb */ - *p |= *b << (BITS_PER_BYTE - bit_offset); + *p++ |= *b << (BITS_PER_BYTE - bit_offset); - p = b; - *b++ >>= bit_offset; + *p = *b++ >> bit_offset; } + } else if (p != b) { + memmove(p, b, cell->bytes - bytes_offset); + p += cell->bytes - 1; } else { /* point to the msb */ p += cell->bytes - 1; From patchwork Thu Jan 9 04:35:46 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Baryshkov X-Patchwork-Id: 13932030 Received: from mail-lf1-f52.google.com (mail-lf1-f52.google.com [209.85.167.52]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3AC69214205 for ; Thu, 9 Jan 2025 04:35:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.52 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736397359; cv=none; b=cbYqGzDFI/On8qSzag8ixqCWvlX4UbcT3KkKt37ECpJQf5Teva2DaYG8EFjDl6gygt2mPJF38YVkQ1ifqKf3pRGQBbwcdkVA+xjK7Nma3b9ZJ+H25f4hoSDHVkAI2M97QNTwGJuQEkJjgTpM/2eb96hh45OH41P7J+TpHOGbgxE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736397359; c=relaxed/simple; bh=2bskNibEbXqxfl2Ilmpmi+d9e6SD72hHz1dhkLTsXqw=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=UFo2YRZ7sCGG09gDKoPWWKDSf8V830Uv0PxFLw5ajmK6akSnQzujNbxq6xh1Of1sXHuhgR0/NA6br0q0khDMITuuWLLC06lziIT+zRNI//eHuMJmaG1vHd8OXQ7UaLSIDxcjQlc7S3gOyY/IXFnGmHAb6tIZTjPBYsI7JtaK8JQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=R4tDzsiX; arc=none smtp.client-ip=209.85.167.52 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="R4tDzsiX" Received: by mail-lf1-f52.google.com with SMTP id 2adb3069b0e04-54252789365so577501e87.0 for ; Wed, 08 Jan 2025 20:35:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1736397355; x=1737002155; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=3aosplTLYhtpWTLaU5zR4iQWyyRW0YdWxTgdnKv+OWI=; b=R4tDzsiXiVcjWQKxwcpcuwZrpeVI0iiJvTQvP0gNdHs8m8TYq4b9CLao+x33dOEn1f u5kiV3grxKUVzRUQ+mj5zwoQAXd7hDeRJg5Y6MTVv4Lbz9JA95P0WdWEVtesj7B8b5cI H/cMZQ0OKv+Oz2HpjJ9n0SFhXs+NBw3jL3oT3BKcigg5Wgo1Mgkys9dPkiuU3WyPhmhn IuQHNUPXNgvJS5EdGmNLGT9u5rn2JupIBfBlDgO3wqh7pMURG1B9+d5edFlOIocDQXh8 2D0Xiq8RsYP8rDf8SEDZo62tho16CnW69KM2p2E8ouyE4AqUBy8eEYYbM9dhPxPXtYZO PJdw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736397355; x=1737002155; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=3aosplTLYhtpWTLaU5zR4iQWyyRW0YdWxTgdnKv+OWI=; b=P+OSbBRA9QgE1ucFxVcMhQiMiMaFLW8ma09KzDLSKXKBIMPanNpJHESh2tEp3KRX9V ildi3S8LghhxW4aP4phKXWcGhtJr4fiifmAVC4XEOgQUg3I5wJohhvxte63JwR0g2Zcq m7Vf32Y5VJqYwdQtCq7Xbcloie7VkAOzMYlvZ2r3T700hNDWIpoKExQOZy3On9siRyRS SYceqDin0/DH0DGef5MWXy5McRFhToMyGSO91JBIfux/jUAh+iwg15B6pfEakzSUDzfY C5THjgzGeXddJ1gggcdrLH80X8OENJgIAraXIIhAfM5TD3sKNUZnaNYSZX7oI6PNHs/9 GYfQ== X-Forwarded-Encrypted: i=1; AJvYcCVCAq0nRSmYN/QCXlwSRTyEDDqzw2v3Hu/SArcLJOd+h+KZGCsJoULfis4S5QPvArwJuewWYRtyjBLZ5deX@vger.kernel.org X-Gm-Message-State: AOJu0YzaLRTM3CvKY7rBxJ2tITFmEGDI9+ZaqJGOGVFsbGaKrBBoQuMq C9Arzembqs2qqrEaupLs7nuaigzDh5ion4YfLOixS4zFhgUkLdyefdWEsElwJhk= X-Gm-Gg: ASbGncvp5Kb2kNxVcxw3jp3EZAN9Bj3zZjQee3vqK+ruSATNEUexnAu+yxQUUnwT2lf OlpuRUO9a4r5LyB3NllqWa3jeYrSZFSXc7zAdubGha+9e6rEq+4Jifi6vN3ceWLOix7cJsL3Tp+ bSH/Fh1efqerrGTmFMWH7N9DdAKCSfDX+3kLXcZoJ4SDy3WgTpHamnOCPfNxfW5zmiX3IzDyyii 0q+z9aLM+HC3rrq9nZaR+cJYzPlJ8SnDankjcTwO4gfSY1BTPbKwd23vrvybeRfGw25W57lqE1O r4Y225n2YLByR4/CB/t8whiR X-Google-Smtp-Source: AGHT+IFurU+4fRGqLM1kG2UuFsjtR9sjwM9mtjisWHOKw7E/cc5bFihShsVmoDxew3v7KstsiFz9KA== X-Received: by 2002:a05:6512:e83:b0:541:1c49:26a with SMTP id 2adb3069b0e04-54284815d5amr1743053e87.43.1736397355392; Wed, 08 Jan 2025 20:35:55 -0800 (PST) Received: from [127.0.1.1] (2001-14ba-a0c3-3a00--782.rev.dnainternet.fi. [2001:14ba:a0c3:3a00::782]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-5428bec06e1sm73866e87.191.2025.01.08.20.35.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Jan 2025 20:35:54 -0800 (PST) From: Dmitry Baryshkov Date: Thu, 09 Jan 2025 06:35:46 +0200 Subject: [PATCH v4 2/5] nvmem: core: verify cell's raw_len Precedence: bulk X-Mailing-List: linux-arm-msm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20250109-sar2130p-nvmem-v4-2-633739fe5f11@linaro.org> References: <20250109-sar2130p-nvmem-v4-0-633739fe5f11@linaro.org> In-Reply-To: <20250109-sar2130p-nvmem-v4-0-633739fe5f11@linaro.org> To: Srinivas Kandagatla , Rob Herring , Krzysztof Kozlowski , Conor Dooley Cc: Akhil P Oommen , linux-arm-msm@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=930; i=dmitry.baryshkov@linaro.org; h=from:subject:message-id; bh=2bskNibEbXqxfl2Ilmpmi+d9e6SD72hHz1dhkLTsXqw=; b=owEBbQKS/ZANAwAKARTbcu2+gGW4AcsmYgBnf1Ij5AW+SyAZq3O9yagXEl8p5JuqiY9aKUHLG RhBU+zo8rKJAjMEAAEKAB0WIQRdB85SOKWMgfgVe+4U23LtvoBluAUCZ39SIwAKCRAU23LtvoBl uNSdEACYA0FlOl7h1SRtSGwI1DheVcZK27ynUAsZws+LY5hBTSfVsSnavmFZpuWQxmXmnYwnqWF wIL45e9gI3wZJUt4+PAJAuQIpJe2Gpc5V7boWVMEZiAryCZsZ+miWj3w1EfhvSXu2gbSSK0OURo rFBZAz6bRY/2V9OiZmmLOr2fUlLNxuIIIXXW1yF8HddBS54LUKQxPoz3UIvDUAI5lGXez/X2JWL AmJjyp84ID6JLdNWOfrxRzjRL9/PCua/5dnzWQe+Yr6SMW97qZ+QMvfTK/xnVcA/yazIGF9h29j jFDz/cYQqtt9I0Qk+bdMfdHv1zX7euOEQNdJFDCRrGJdkzgClGYovR0SeIaCOdv+vBQSe7NhZiq rJfjfVJHr8RH4EuQaY7dMPZ3PqfTMnSbL4WJWFWra6WQchwUpd/MxWF8UI6UQjfWAwPuChEwdVQ z4R7UHXcLbqWTb6FoekugjEbAwLTZrHeqsXmLi9meHUq7WTbaTjCj7Nhea/doW0WTQvZLVABbWD QZ8kAVuJwEZXYNUgSS/TzFOovX1B8Y0S2pPJ5zJJldJfBgDsktM40QpdUTAcN0rEEwJwsPZZMW2 s0XCU9fL+tcK7bPER+AOb8OPDJO+mD20yOuVvxr5G1NEnSSv3+ae4Ak5YSnBhzUmhrvFxxWtuez 2Tuv0hX+VSiecGw== X-Developer-Key: i=dmitry.baryshkov@linaro.org; a=openpgp; fpr=8F88381DD5C873E4AE487DA5199BF1243632046A Check that the NVMEM cell's raw_len is a aligned to word_size. Otherwise Otherwise drivers might face incomplete read while accessing the last part of the NVMEM cell. Signed-off-by: Dmitry Baryshkov --- drivers/nvmem/core.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c index 7fa85b0804db360035d7471002dbf79658d5830b..59885d8b6a19d01f50759f09d453b092d1ec44bb 100644 --- a/drivers/nvmem/core.c +++ b/drivers/nvmem/core.c @@ -602,6 +602,14 @@ static int nvmem_cell_info_to_nvmem_cell_entry_nodup(struct nvmem_device *nvmem, return -EINVAL; } + if (!IS_ALIGNED(cell->raw_len, nvmem->word_size)) { + dev_err(&nvmem->dev, + "cell %s raw len %zd unaligned to nvmem word size %d\n", + cell->name ?: "", cell->raw_len, + nvmem->word_size); + return -EINVAL; + } + return 0; } From patchwork Thu Jan 9 04:35:47 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Baryshkov X-Patchwork-Id: 13932031 Received: from mail-lf1-f45.google.com (mail-lf1-f45.google.com [209.85.167.45]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A5E23214233 for ; Thu, 9 Jan 2025 04:35:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.45 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736397361; cv=none; b=iAIEV9IRBseimpKbqE1jV3g7dxDfyxMSvxrXSfF5dO2s9/PY8d2wNxLPhcDOxh69jfXrB8yI+40TmQ0wYWY58gzlBE4Xcxfg45EJw7wsd7xLF0a0hknfEGZtmDKj7B+v/dcbwH46SD3VqyRViBpaLaAxRbtNZwMzpBsukOqFZ3Y= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736397361; c=relaxed/simple; bh=KYi944Ng8PZyQOwpW6lInP7e9H63rwgPuemV1qM3aN0=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=Ydsf1x3Uo9hdJPXQ2ptqH5i2CKaNnLg6oEWJYY1hOKp2eVeCnFdG2VRW17l8nCy9/5WQqUMnciH5JqwWaWOepcbn1lKtbnU6UK1tkG68ad0aWC1vOFMcXs/rylRejcsCvm0Tw+jOrF4kE9cvmWp0X/8I4H4zCcbJ68T8U9lVAdE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=tQFIJH4R; arc=none smtp.client-ip=209.85.167.45 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="tQFIJH4R" Received: by mail-lf1-f45.google.com with SMTP id 2adb3069b0e04-54252789365so577516e87.0 for ; Wed, 08 Jan 2025 20:35:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1736397358; x=1737002158; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=jpXKuQIMgaAXMlwh5+Z08XtwvgtpNR7jrbvfEWHNUTA=; b=tQFIJH4RX5Dc+XQMqP3emA+DZzTKbRh0VysW8qMsLkPvFpiv1rbiBu/4YIbQ0yp06T LwZcD4YpqjAzFLaWjMMifj9GmwpfoshiDoABmmZSb231jRGFOUc4BOvE4np0f6YcGAYF HcvNgduPMC5DeA8aSNAuN8SI469KcQ4D9TLE+OZr2Haricn92adsmjoNvrkU/B4JiuI3 G/0dUNL8BkA+ckZppr8alUHcuNkfai4nlhfhgNMI70A9Q4guI/21rwA2Y9hrAqYZx2wE Z8vlcScLPJJMw/uWE7dvSnguvAEr/i4Xwt+sA4CiRxhj0qMcWN4X0AROPVUmo2xbeioj aU+Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736397358; x=1737002158; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=jpXKuQIMgaAXMlwh5+Z08XtwvgtpNR7jrbvfEWHNUTA=; b=qpHCuqth+uveznEu7Hv2cTgnJ2FLDpxvkZ8g71/Nd+jfQ30pdB8ugBg5HFOsm8PMyP eOdOSuTnPUpid10BDb66i5sSpkVSK/ZohVITEZIOrmhs1nN+4itg3TXyrKzsQwaZaLCm 8DzLXjO8wO+dbiLGFo8BwIyujg+dpt2//16aqD97OeIa5NDxZYTHTQAwmrAO29KB7aLR +067sLbI0ULRPclxJGx3dYtbhcFROOH6etbWVApsSdgDDfhTe95KQwjB1pTLgpsJf/TY EqQmFb0aAVoM8HCYeVtoWg1xJayIfWYBFXL6Rn+LTLFvNvmJ+SnqAuLIlpb2ATlW5A1D MLVg== X-Forwarded-Encrypted: i=1; AJvYcCUNCa7uKszA2t892Iy5ogN3sh4IgHFCv7em1XQhyZDsNyuKaJrLRjqlk6PsPbZsM4NnXoULr3SEpbkygC+H@vger.kernel.org X-Gm-Message-State: AOJu0Ywz6LS1fd+LETZTZImKSs+ERn0XUbwp6vnrrLntqPaPttV948Fc t19+FZefN2rKlsWp/JUCJj8pZAohUJTVWJmAeaA9yGEWK0YUnwrULPPRIpH13jw= X-Gm-Gg: ASbGnctimbRvQk8647EX8pHusFouIdvQ93lGY0qOH1jCDGD5CLi8cRpBakgDuOLtpgX rhfNzVXvIwzYb0+98v+i9rU1rcLl0/BvxNCI6pGzVDvHWk5VbOG7Malsv/ojpyeqv5X4UUdPyeN wdHRFu7l/xz/VUtEhecQxslCPtj4C3eQA5HDfMfodRgQ9nzkASUYVXqDzqnA12YiuGmsX5mg9G2 iMrqJ378pZpG9R5Y20morK4gkgB+mmDnW6g6s8jyRxLw2HWwJ/ZU8sb2TIaODK5+bvXKtmsMH1Z DJ4Gry5OB4zXRbh45jEaIYy/ X-Google-Smtp-Source: AGHT+IHXvspid5uO57Ne/VYe04P/EGSy1AstqW/FydRu5FaZnAbabC9adB3YHkCwunnYN9qNMQViJw== X-Received: by 2002:a05:6512:10cd:b0:540:1c16:f2f7 with SMTP id 2adb3069b0e04-542845bdd1amr1369272e87.14.1736397357757; Wed, 08 Jan 2025 20:35:57 -0800 (PST) Received: from [127.0.1.1] (2001-14ba-a0c3-3a00--782.rev.dnainternet.fi. [2001:14ba:a0c3:3a00::782]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-5428bec06e1sm73866e87.191.2025.01.08.20.35.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Jan 2025 20:35:56 -0800 (PST) From: Dmitry Baryshkov Date: Thu, 09 Jan 2025 06:35:47 +0200 Subject: [PATCH v4 3/5] nvmem: core: update raw_len if the bit reading is required Precedence: bulk X-Mailing-List: linux-arm-msm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20250109-sar2130p-nvmem-v4-3-633739fe5f11@linaro.org> References: <20250109-sar2130p-nvmem-v4-0-633739fe5f11@linaro.org> In-Reply-To: <20250109-sar2130p-nvmem-v4-0-633739fe5f11@linaro.org> To: Srinivas Kandagatla , Rob Herring , Krzysztof Kozlowski , Conor Dooley Cc: Akhil P Oommen , linux-arm-msm@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=988; i=dmitry.baryshkov@linaro.org; h=from:subject:message-id; bh=KYi944Ng8PZyQOwpW6lInP7e9H63rwgPuemV1qM3aN0=; b=owEBbQKS/ZANAwAKARTbcu2+gGW4AcsmYgBnf1IkutU4e8r41NLfSbrBUzZ8YhmPvzTOQ2v+k Ebwskduq6eJAjMEAAEKAB0WIQRdB85SOKWMgfgVe+4U23LtvoBluAUCZ39SJAAKCRAU23LtvoBl uEmUEACY4IBr5uLswWnHYFyhg1g9Jv/h+36nARGMzYvaAdq06riHGrGkSeNY15J6smUaQ8ho8i0 3ZBzap2sIOcnn3cHWhwki1KnoCzFY7R0T+xGkSY1fINkuWkpQ4CobR+61qdCU20r9DdtMbXyqIT BvofAxA5dr2/BtFd8nxf4C4SP3d7HqnxbLRu6zeVS0HDwBnVwkumtZqrKCBFcXiSjtq0OXrMO47 97LHuw9Ie9WlxyXW6tu51MIZZtS3+raU7spdjuhNBaVfxDUIpbH70Drv0oOyN3LxwQ1h07bM16a tGrSLdv4XM/U7d8uZf+/HqolAg3NeTIwtdp8rX3Ux8jiuYPWTnIiaTUR1rUaYlJj9NgIPGRx3Kl gIy/0Kf+guZjuGbEmcM9Dvwy4JE4Olbq805+R9ccpqm8GsjvCTprCV7Z2tcxUq0rK5aI3ShDCJf VIaVQKYqn85zZs+40w+/6VbZ3L7QLurh/fy+XXCKNArGfU2fRC/nK5Ziil1NglBR9DzWgRVe/jd q5GNyBuCwq3x4hsM/cp1gucxopI++vtoCboRHvqa6B3uL1XmFO4F3gTdnUD9B7Ob5HXFwefYsMo 7KxUlwOilzZLiOnxdcc0XwXgKE+xDnElwmv7oKOL6l7OIVKLMWTUlQ3iO49eTG5xfZ7CzmlUgbS 2QHgdnLPs1j8DPg== X-Developer-Key: i=dmitry.baryshkov@linaro.org; a=openpgp; fpr=8F88381DD5C873E4AE487DA5199BF1243632046A If NVMEM cell uses bit offset or specifies bit truncation, update raw_len manually (following the cell->bytes update), ensuring that the NVMEM access is still word-aligned. Signed-off-by: Dmitry Baryshkov --- drivers/nvmem/core.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c index 59885d8b6a19d01f50759f09d453b092d1ec44bb..d3c2e6917ed32ace30844faaab27c41779b5bbf6 100644 --- a/drivers/nvmem/core.c +++ b/drivers/nvmem/core.c @@ -591,9 +591,11 @@ static int nvmem_cell_info_to_nvmem_cell_entry_nodup(struct nvmem_device *nvmem, cell->nbits = info->nbits; cell->np = info->np; - if (cell->nbits) + if (cell->nbits) { cell->bytes = DIV_ROUND_UP(cell->nbits + cell->bit_offset, BITS_PER_BYTE); + cell->raw_len = ALIGN(cell->bytes, nvmem->word_size); + } if (!IS_ALIGNED(cell->offset, nvmem->stride)) { dev_err(&nvmem->dev, From patchwork Thu Jan 9 04:35:48 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Baryshkov X-Patchwork-Id: 13932032 Received: from mail-lf1-f54.google.com (mail-lf1-f54.google.com [209.85.167.54]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0220B2144B6 for ; Thu, 9 Jan 2025 04:36:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.54 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736397364; cv=none; b=dAFXBnp+NZQsCU6j9TjGLtmNiFuZW4KVrtuNgInjBlcQkWpzcx4Ezeub8S1ipwDhNkO3m9FiF/HDbJ4IzE3rzJ92oquIEjse0PIrcxOpSld4pQDrG1GwocBiRhlF6kn010Arf0dc8lPszkEqkyrd3fVW8E8ikTTo+tMIC15FoZ8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736397364; c=relaxed/simple; bh=Weli6Ud1pnhnVMQNhXbarzN29phyH4B6NUF7IDp6kk8=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=kHZjLWm8ld39lDKP9GZG8WieqlNdFgXw/YBbRew/KbO5rCXT7D6KASocixL5ZdkMWf5wpPDFTDAY7q27UTDagXO18sqXBbOWYast/2lebDbY0U6IzNFHhZtFfb2GIQx3rjVZ9ewi7PzHMxwygG7iwV8WRInhuaeCuxAvGnhKAEQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=cDnBa5KN; arc=none smtp.client-ip=209.85.167.54 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="cDnBa5KN" Received: by mail-lf1-f54.google.com with SMTP id 2adb3069b0e04-53ff1f7caaeso509574e87.0 for ; Wed, 08 Jan 2025 20:36:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1736397360; x=1737002160; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=lOzuf/LkISp9KTJoorQzqPXBIv79BHB/w9fYq6gMhqs=; b=cDnBa5KN9Z0q3M7Vf2CiIOCBxwkmQg/Z9fMDEhiQBW4ZJ0/4H8i0Txh5OID1ibvoqM VlVyljmnVf/0v+VSK0IrgD6Jy0PBq84Vo/5mvMdRA0O7HUY2mxr6cIcKVJEVxXZCjT7o mx+3qQW6QPL3cadZ3RJfPgp7OHLbBIy+J+zTu2F2dmmJq/INtCbt5yU4H7gkuvpRXQHj /AsQLuVlPxFKmWusu7sFP5uyyjBwQPJhuY4SdRJEARtxpGdZhmCHlqQIl9Wa5dlafrRa IWebD6rZKAJDyHrEDziImCh3HoJZrss+4A9JFY5sKFgixNBv3HgFMZmZ+fdKPR5IlsNx f/aQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736397360; x=1737002160; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=lOzuf/LkISp9KTJoorQzqPXBIv79BHB/w9fYq6gMhqs=; b=h+M68MX+eKKXoqz2dbSCqStHeGe8wKKZMsC4jWR4vGwvvF9yhB1MRikfWZjHy25ZL3 o04fKQQthYzgk7GBqYtaDak7NJlwN/vs8DVqIBycT+eMjW+2lB+9mV4vYx0th8t7yGoC ayoQRnucW8GaFAlEQ6v8f995zYzsdO7cdSjNfAv8aJlHZGCVmprxCXjsbTsW6vd0Xe0K zWGLqrhSH/D14b3lLmAr54qHssemNI7moBIGfe73blk9wgTX1v1yAe4kc5o11PWq2xbf aaAQ8BE5adgdtqvup/x8fZx1jW+A+Q6fn9DBGWJaEU1gvuTtFEP1kabO4Ml2eKQcQ/PG 0vuQ== X-Forwarded-Encrypted: i=1; AJvYcCXZOgSb7twLceTHxUxVMajz2cHHSgQrYDddbI5bwIJiv/9eH7/kWmUizVzE+VvzschkGmCVSselsCN0u7F3@vger.kernel.org X-Gm-Message-State: AOJu0YwVp8aVNrhYpyrEI8WojhUGKbCXAgJzb+hC80D99B9CPy0IjJip D8PmcxmQswn5aHWWCMX5GpcGy0YJhbJNtBSHlfVlB3CnOjxKzvpT37eyE6YiHqM= X-Gm-Gg: ASbGnctlYuJhCfpilrPf4AsJvgLnU3swZQiBvmJ9CKaEEetJ4NcDqdZLB7AU5KTjNsA XSBjU/IYeZG7fBqu4XoXiITMrDuZf12MRYMUnP3kE6+qnPnk+xf7/NCEuhDuDpxLXJzNfuqpsD2 d8S5LnOMD3cIcPU971ybEKEiUW7vHixpYU0poQ8i5qVoot7p39uNlqMNruUOTxRwR2BaUe0M6p/ Wjc/KBlYJLBaJ6NWokI4AZQdo8WvWLlr+b/3qCnmos00XurCCXWmLO8fogrzA4GJmQQJt8ojhKC xHGxAh8ycPkN5+z7MEkmQKJM X-Google-Smtp-Source: AGHT+IHs3R+5B1+LBttE+o7iirut3LHPZTq8vF+yRZe/KNbZaBYwfnKQ9/7DTDyxEbPDhjk7vysLQQ== X-Received: by 2002:a05:6512:690:b0:53d:e5c0:b9bc with SMTP id 2adb3069b0e04-542845c05f5mr1136490e87.50.1736397360155; Wed, 08 Jan 2025 20:36:00 -0800 (PST) Received: from [127.0.1.1] (2001-14ba-a0c3-3a00--782.rev.dnainternet.fi. [2001:14ba:a0c3:3a00::782]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-5428bec06e1sm73866e87.191.2025.01.08.20.35.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Jan 2025 20:35:58 -0800 (PST) From: Dmitry Baryshkov Date: Thu, 09 Jan 2025 06:35:48 +0200 Subject: [PATCH v4 4/5] nvmem: qfprom: switch to 4-byte aligned reads Precedence: bulk X-Mailing-List: linux-arm-msm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20250109-sar2130p-nvmem-v4-4-633739fe5f11@linaro.org> References: <20250109-sar2130p-nvmem-v4-0-633739fe5f11@linaro.org> In-Reply-To: <20250109-sar2130p-nvmem-v4-0-633739fe5f11@linaro.org> To: Srinivas Kandagatla , Rob Herring , Krzysztof Kozlowski , Conor Dooley Cc: Akhil P Oommen , linux-arm-msm@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=2302; i=dmitry.baryshkov@linaro.org; h=from:subject:message-id; bh=Weli6Ud1pnhnVMQNhXbarzN29phyH4B6NUF7IDp6kk8=; b=owEBbQKS/ZANAwAKARTbcu2+gGW4AcsmYgBnf1IkACTJK3+cbEVvQiLITbU/iuCdV9QIf923Z +4gR8kMz82JAjMEAAEKAB0WIQRdB85SOKWMgfgVe+4U23LtvoBluAUCZ39SJAAKCRAU23LtvoBl uCbOD/9y3o9U+3IKjSZHvf0PVEnBIh5ablg36IJ6zcIvPqMEWb9e/IrHB9i/hxb+Ndi5oOxY96A a+o0PchHna8jfEfQOdlO4sX1ZFDR4rXEN9vlq3js96XRsbeyE6Qj0uD+4Z6wkmDmi0Ux19uAGkd zaHC8mfrito3xE9Rke3bivnJz620TW0eTAWBHOiICk7NjV4KpVXYK6b1vpLoiAAT60JDdihI69A ZaYdPtj61kHUVrhD0+Z1WNixvu4pfropDa7qA1gSpdn+GChXJONzjKrq2SZCPkhRmhcm6SRJ1vc mQTQMILV9ZQzc3Apqn82tZKXwQ/0amgx2fOxQngAPQW1YsloCmN8Zq/PY19mtrDH7uwMIE8h9PC nzhkXRumB61iQVYiKbZ1MzHPv1xGX8oB8zzT2XuLBNDnF2anv6GG9Km2ucqC7tCaYXSu2lQBejB hJkVsmm3JNVwiGkNQ4GnU3FdWly0eLEItkFC9IGM61wTITSCa7QV5dDpaYaJpl7lzYz61oABBct 5RTQkxajL9rDkpdZ0vFEycIpfQbWVGs3KDZ3J/sprYSJlZAljWVrgqpkvHstnAZpVqzN+PQMtTp SX3834e1v1is/rP1Lndu+/hQR8MOEUnyBMlCRXbrhqBSMZdCR3DNZpsHFl/X8ElvGlOrTLMKA7u xF5aUi3mvdjawDw== X-Developer-Key: i=dmitry.baryshkov@linaro.org; a=openpgp; fpr=8F88381DD5C873E4AE487DA5199BF1243632046A All platforms since Snapdragon 8 Gen1 (SM8450) require using 4-byte reads to access QFPROM data. While older platforms were more than happy with 1-byte reads, change the qfprom driver to use 4-byte reads for all the platforms. Specify stride and word size of 4 bytes. To retain compatibility with the existing DT and to simplify porting data from vendor kernels, use fixup_dt_cell_info in order to bump alignment requirements. Signed-off-by: Dmitry Baryshkov --- drivers/nvmem/qfprom.c | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/drivers/nvmem/qfprom.c b/drivers/nvmem/qfprom.c index 116a39e804c70b4a0374f8ea3ac6ba1dd612109d..a872c640b8c5a558da9ea00e3804c904f8987247 100644 --- a/drivers/nvmem/qfprom.c +++ b/drivers/nvmem/qfprom.c @@ -321,19 +321,32 @@ static int qfprom_reg_read(void *context, unsigned int reg, void *_val, size_t bytes) { struct qfprom_priv *priv = context; - u8 *val = _val; - int i = 0, words = bytes; + u32 *val = _val; void __iomem *base = priv->qfpcorrected; + int words = DIV_ROUND_UP(bytes, sizeof(u32)); + int i; if (read_raw_data && priv->qfpraw) base = priv->qfpraw; - while (words--) - *val++ = readb(base + reg + i++); + for (i = 0; i < words; i++) + *val++ = readl(base + reg + i * sizeof(u32)); return 0; } +/* Align reads to word boundary */ +static void qfprom_fixup_dt_cell_info(struct nvmem_device *nvmem, + struct nvmem_cell_info *cell) +{ + unsigned int byte_offset = cell->offset % sizeof(u32); + + cell->bit_offset += byte_offset * BITS_PER_BYTE; + cell->offset -= byte_offset; + if (byte_offset && !cell->nbits) + cell->nbits = cell->bytes * BITS_PER_BYTE; +} + static void qfprom_runtime_disable(void *data) { pm_runtime_disable(data); @@ -358,10 +371,11 @@ static int qfprom_probe(struct platform_device *pdev) struct nvmem_config econfig = { .name = "qfprom", .add_legacy_fixed_of_cells = true, - .stride = 1, - .word_size = 1, + .stride = 4, + .word_size = 4, .id = NVMEM_DEVID_AUTO, .reg_read = qfprom_reg_read, + .fixup_dt_cell_info = qfprom_fixup_dt_cell_info, }; struct device *dev = &pdev->dev; struct resource *res; From patchwork Thu Jan 9 04:35:49 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Baryshkov X-Patchwork-Id: 13932033 Received: from mail-lf1-f50.google.com (mail-lf1-f50.google.com [209.85.167.50]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 59B692147E6 for ; Thu, 9 Jan 2025 04:36:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.50 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736397366; cv=none; b=gkNPQYWLGvX6UN8ntzxkxN5cYm1bHesaYxXJkrakaeL9CiTj06jiOP9TRJwuvI3wqLqnL0iObWUsDcC4uCwGWTTD0Jy/x1Rllxgboe54SUZc1k35/clentXUs6Wt8SOeRde7HHoN8SiCNv/si8LlE2GI8NYLppeHaYfPa8lXKBc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736397366; c=relaxed/simple; bh=bFoUxd13xqGzTL8i0Uke1VWxv8nz0uckVKpDL5fYKp4=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=lazKRYmjMRq05M293xNzH3rnlydQnsFIcqpTpoZ3T3fEymgFNPTn4CRDG/kNrIWgJK6p5YIfaSnvCuAT/3/pZNPKl2Ptp2JF/KtbQ6y6PIugtRM0PY7Rsqo0VDSVoCExEu88uDczg7UiM65oqL9bmlXaHVRwVB/7i8L/m90J7MA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=Pj0tpkKH; arc=none smtp.client-ip=209.85.167.50 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="Pj0tpkKH" Received: by mail-lf1-f50.google.com with SMTP id 2adb3069b0e04-53e3a227b82so419770e87.0 for ; Wed, 08 Jan 2025 20:36:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1736397362; x=1737002162; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=tBnHSa/ei6D2pomsNrU1v/8n3usXWfC08yobzI09Jro=; b=Pj0tpkKHWmRfq9IupCpqdtxOrU0ZJnk2tNicleGk3isY33BEPZ132l/2UyX9xB4K1f TAMOUjd++y+/sG1gxLgptuQiGOP3nT91i+ZGa+cPcQGGNg3KrU6+4nuZx8svAPveyWNY BUNWYn1aYTlR7/5wsngTB6teLEqyUq55jOL1XurX5i9o1hNKatMQXFpib4RkgRpa6Qmx pqmevoBglaIgbeQG23sNyGOVcw0mbMU7ytuR8DZvVxXhNC0uOn2zgJ4f2qipC1a2ofOq c9UlfbyIBuHMNzDFuP9YyzxeJuT7TLeZs/eUOe5QKpBqvYq3uRmOg2FzWhyn7aclciyy U/6g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736397362; x=1737002162; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=tBnHSa/ei6D2pomsNrU1v/8n3usXWfC08yobzI09Jro=; b=pPxOmyWkXvICWWFyhFhkrSpaN6cTMzXaFP2m6MCjqtbd9g8nGzQGby682LK9yRCTMK VuCk3XE5zBnsaINvoBvLVL3d71ujn3hkeD9DF06Fen4nRFsT1gjupoNQ2pdyN0v2XcwQ LkdxNM7ZVO9B3sdc84BGb7dWTZmRpLk8DqLqYF/L6jYWKZsoqGXVvLa4hpQNJ4CYTGoi 6CMRvoweT4tVpO6GwQ4Ubzy24chFczPe2NP3NV95snUnhwLjx3JWh6bFRLqMbRbjDBiO Ts88kZIwLBiAVRaJfKhw0WODy8YZzHwyBwmM80us8UgzzrqGiaTshZD547Dwo7qNWHgX QMdg== X-Forwarded-Encrypted: i=1; AJvYcCW4Mpz8s54lQ0BqiCqyp9/KeCkl6S2zxU5DOpjMwBeHABVOxKet2pgVhdSJTuokQeQ3WW8U1sXjKAoWQ2Ce@vger.kernel.org X-Gm-Message-State: AOJu0YyeIh6l91XgfaAQ3mnJn2FKfMdnwbYMOQNt6VBXeQBGqd8OsDNn 1aqWzfiNVkJQ7wBIleOMJwikiBOonuW8IJRv6m63yCfWjb3VPnLGceNY0DGlGiHQyUbwQN5O2Vz o X-Gm-Gg: ASbGncta4w02jS872Oshnh3cE15e36k+bIBZs/YUx6RI7sbTkgtCqTwLPvltUKsSWsD /lJQ+4/xaYRRfPICI9uq6gBbdtW4yS7yTWUdRNjPjLc200m71DLS1DdlwRhXISPyzhYTD+P7fCb mEtuzMS63cvKDXWwppcoyQ/XTHnsf7pjw8HJZtEQ/bnAyjoyatHyuyf4YzDV8nQUsDjDAGPnMiP LrIZdaPDK1xM+jodVxYorMk6x4QIbre/1WUuhFsc83KYdx5zHiJKx/+WksL3Ma/E72we0BMOygn Mg7FU8h7+z/F6XGltZZriP+u X-Google-Smtp-Source: AGHT+IHNpliUbCzShTHU3YELA4A2kOZ8c3cc6bdarZT0RN/YgBassMDYaqQENO1wTf98MuMXuQ9xwg== X-Received: by 2002:a05:6512:220b:b0:540:1dca:52bb with SMTP id 2adb3069b0e04-542845c52a3mr1607860e87.28.1736397362546; Wed, 08 Jan 2025 20:36:02 -0800 (PST) Received: from [127.0.1.1] (2001-14ba-a0c3-3a00--782.rev.dnainternet.fi. [2001:14ba:a0c3:3a00::782]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-5428bec06e1sm73866e87.191.2025.01.08.20.36.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Jan 2025 20:36:01 -0800 (PST) From: Dmitry Baryshkov Date: Thu, 09 Jan 2025 06:35:49 +0200 Subject: [PATCH v4 5/5] dt-bindings: nvmem: qcom,qfprom: Add SAR2130P compatible Precedence: bulk X-Mailing-List: linux-arm-msm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20250109-sar2130p-nvmem-v4-5-633739fe5f11@linaro.org> References: <20250109-sar2130p-nvmem-v4-0-633739fe5f11@linaro.org> In-Reply-To: <20250109-sar2130p-nvmem-v4-0-633739fe5f11@linaro.org> To: Srinivas Kandagatla , Rob Herring , Krzysztof Kozlowski , Conor Dooley Cc: Akhil P Oommen , linux-arm-msm@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=866; i=dmitry.baryshkov@linaro.org; h=from:subject:message-id; bh=bFoUxd13xqGzTL8i0Uke1VWxv8nz0uckVKpDL5fYKp4=; b=owEBbQKS/ZANAwAKARTbcu2+gGW4AcsmYgBnf1IkEzuENDcUEcO0yq8IH9HJSBlZNlZ96P5un s4G2pMI+vyJAjMEAAEKAB0WIQRdB85SOKWMgfgVe+4U23LtvoBluAUCZ39SJAAKCRAU23LtvoBl uK/UEACfZKDyD2ZRlKrK0nQ7XUI4Xg0II/U+NjC//mQGfymuOwLzxtzekZ76kaNWGnUtcnbmvIQ 7byw02C76jPzUi+g9MLHcFllLdEYRX2o4JTveJo5ZfOTNGe7bkVdJpsAcFr5rcLUhdUsmL3ex+k Olj3xZ4gGDGy2c6RNiM5EdLfIwgeO795TpSK1UanTuE2vi2OJz9ZCDjrczsw5Fw3hS/8R+NGMby XDnv9a9WIEdZdx6QX+CPF2Z2Bffg1pELrm5lupfLMakBoqKfBeVxx+Aul9/xDxPWctGoSsg2puz +0Sn4RdLOCv7UX1M7kNR1HXlyhnAvxgw31cGrGXqgXhrrY+WTqChJf6LqK6VZi8+H0jdIFTQfX8 kWEgJt0sOj/K3PKEZoTYxshnv+nQNxAS8H5isSDoybOqQlqDdFNpoqXtVvg9W4cNysNZbBtpqHc dw5/PQVJEJn8nS4vzkR1txVQ0oKV0rfEdMtNQG8LRNud8nxqwjolYU4HAChN6xj6fC8SdVpHlQG n+Wg6zpQ25LJmvkqFnwSxl6D3lO0gWkwsfU8oj2z2HLzm1HBMbuS3p4nc2aPLP9JhFIol4/FcxG e+2IAnE8NAPgaIR61l04tbHdNlQyAKVPJe3jLerCltmW3lTRROUHo7tLftXKGvkHnucY+Rw5Oi1 cKfwlasmdca2hRw== X-Developer-Key: i=dmitry.baryshkov@linaro.org; a=openpgp; fpr=8F88381DD5C873E4AE487DA5199BF1243632046A Document compatible for the QFPROM on SAR2130P platform. Signed-off-by: Dmitry Baryshkov --- Documentation/devicetree/bindings/nvmem/qcom,qfprom.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/Documentation/devicetree/bindings/nvmem/qcom,qfprom.yaml b/Documentation/devicetree/bindings/nvmem/qcom,qfprom.yaml index 80845c722ae46611c722effeaaf014a0caf76e4a..9755b31946bf9d4c1055a993145d06c274b61a37 100644 --- a/Documentation/devicetree/bindings/nvmem/qcom,qfprom.yaml +++ b/Documentation/devicetree/bindings/nvmem/qcom,qfprom.yaml @@ -32,6 +32,7 @@ properties: - qcom,msm8998-qfprom - qcom,qcm2290-qfprom - qcom,qcs404-qfprom + - qcom,sar2130p-qfprom - qcom,sc7180-qfprom - qcom,sc7280-qfprom - qcom,sc8280xp-qfprom