blob: 39f7be8dc9223d62ead1bbd71f6e09f92fcef877 [file] [log] [blame]
Wadim Egorovf3edaf22024-05-22 09:55:04 +02001/* SPDX-License-Identifier: GPL-2.0-or-later */
2/*
3 * Copyright (C) 2024 PHYTEC Messtechnik GmbH
4 * Author: Wadim Egorov <w.egorov@phytec.de>
5 */
6
7#include "k3_ddrss_patch.h"
8
9#include <fdt_support.h>
10#include <linux/errno.h>
11
12#ifdef CONFIG_K3_AM64_DDRSS
13#define LPDDR4_INTR_CTL_REG_COUNT (423U)
14#define LPDDR4_INTR_PHY_INDEP_REG_COUNT (345U)
15#endif
16
17static int fdt_setprop_inplace_idx_u32(void *fdt, int nodeoffset,
18 const char *name, uint32_t idx, u32 val)
19{
20 val = cpu_to_be32(val);
21 return fdt_setprop_inplace_namelen_partial(fdt, nodeoffset, name,
22 strlen(name),
23 idx * sizeof(val), &val,
24 sizeof(val));
25}
26
27int fdt_apply_ddrss_timings_patch(void *fdt, struct ddrss *ddrss)
28{
29 int i, j;
30 int ret;
31 int mem_offset;
32
33 mem_offset = fdt_path_offset(fdt, "/memorycontroller@f300000");
34 if (mem_offset < 0)
35 return -ENODEV;
36
37 for (i = 0; i < LPDDR4_INTR_CTL_REG_COUNT; i++)
38 for (j = 0; j < ddrss->ctl_regs_num; j++)
39 if (i == ddrss->ctl_regs[j].off) {
40 ret = fdt_setprop_inplace_idx_u32(fdt,
41 mem_offset, "ti,ctl-data", i,
42 ddrss->ctl_regs[j].val);
43 if (ret)
44 return ret;
45 }
46
47 for (i = 0; i < LPDDR4_INTR_PHY_INDEP_REG_COUNT; i++)
48 for (j = 0; j < ddrss->pi_regs_num; j++)
49 if (i == ddrss->pi_regs[j].off) {
50 ret = fdt_setprop_inplace_idx_u32(fdt,
51 mem_offset, "ti,pi-data", i,
52 ddrss->pi_regs[j].val);
53 if (ret)
54 return ret;
55 }
56
57 for (i = 0; i < LPDDR4_INTR_PHY_INDEP_REG_COUNT; i++)
58 for (j = 0; j < ddrss->phy_regs_num; j++)
59 if (i == ddrss->phy_regs[j].off) {
60 ret = fdt_setprop_inplace_idx_u32(fdt,
61 mem_offset, "ti,phy-data", i,
62 ddrss->phy_regs[j].val);
63 if (ret)
64 return ret;
65 }
66
67 return 0;
68}