Skip to content

Commit 3566a73

Browse files
lumaggregkh
authored andcommitted
nvmem: qfprom: switch to 4-byte aligned reads
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 <[email protected]> Signed-off-by: Srinivas Kandagatla <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 6786484 commit 3566a73

File tree

1 file changed

+20
-6
lines changed

1 file changed

+20
-6
lines changed

drivers/nvmem/qfprom.c

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -321,19 +321,32 @@ static int qfprom_reg_read(void *context,
321321
unsigned int reg, void *_val, size_t bytes)
322322
{
323323
struct qfprom_priv *priv = context;
324-
u8 *val = _val;
325-
int i = 0, words = bytes;
324+
u32 *val = _val;
326325
void __iomem *base = priv->qfpcorrected;
326+
int words = DIV_ROUND_UP(bytes, sizeof(u32));
327+
int i;
327328

328329
if (read_raw_data && priv->qfpraw)
329330
base = priv->qfpraw;
330331

331-
while (words--)
332-
*val++ = readb(base + reg + i++);
332+
for (i = 0; i < words; i++)
333+
*val++ = readl(base + reg + i * sizeof(u32));
333334

334335
return 0;
335336
}
336337

338+
/* Align reads to word boundary */
339+
static void qfprom_fixup_dt_cell_info(struct nvmem_device *nvmem,
340+
struct nvmem_cell_info *cell)
341+
{
342+
unsigned int byte_offset = cell->offset % sizeof(u32);
343+
344+
cell->bit_offset += byte_offset * BITS_PER_BYTE;
345+
cell->offset -= byte_offset;
346+
if (byte_offset && !cell->nbits)
347+
cell->nbits = cell->bytes * BITS_PER_BYTE;
348+
}
349+
337350
static void qfprom_runtime_disable(void *data)
338351
{
339352
pm_runtime_disable(data);
@@ -358,10 +371,11 @@ static int qfprom_probe(struct platform_device *pdev)
358371
struct nvmem_config econfig = {
359372
.name = "qfprom",
360373
.add_legacy_fixed_of_cells = true,
361-
.stride = 1,
362-
.word_size = 1,
374+
.stride = 4,
375+
.word_size = 4,
363376
.id = NVMEM_DEVID_AUTO,
364377
.reg_read = qfprom_reg_read,
378+
.fixup_dt_cell_info = qfprom_fixup_dt_cell_info,
365379
};
366380
struct device *dev = &pdev->dev;
367381
struct resource *res;

0 commit comments

Comments
 (0)