Re: [PATCH v3 06/10] soc: qcom: Add LLCC support for multi channel DDR

From: Komal Bajaj
Date: Wed Jun 14 2023 - 02:32:21 EST




On 6/13/2023 10:41 PM, Bjorn Andersson wrote:
On Fri, May 12, 2023 at 05:51:30PM +0530, Komal Bajaj wrote:
Add LLCC support for multi channel DDR configuration
based on a feature register.

Signed-off-by: Komal Bajaj <quic_kbajaj@xxxxxxxxxxx>
---
drivers/soc/qcom/llcc-qcom.c | 32 +++++++++++++++++++++++++++++---
1 file changed, 29 insertions(+), 3 deletions(-)

diff --git a/drivers/soc/qcom/llcc-qcom.c b/drivers/soc/qcom/llcc-qcom.c
index 6cf373da5df9..1da337e7a378 100644
--- a/drivers/soc/qcom/llcc-qcom.c
+++ b/drivers/soc/qcom/llcc-qcom.c
@@ -12,6 +12,7 @@
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/mutex.h>
+#include <linux/nvmem-consumer.h>
#include <linux/of.h>
#include <linux/of_device.h>
#include <linux/regmap.h>
@@ -943,6 +944,19 @@ static int qcom_llcc_cfg_program(struct platform_device *pdev,
return ret;
}

+static int qcom_llcc_get_cfg_index(struct platform_device *pdev, u8 *cfg_index)
+{
+ int ret = 0;
First use is an assignment, no need to initialize here.

Noted.


+
+ ret = nvmem_cell_read_u8(&pdev->dev, "multi_chan_ddr", cfg_index);
+ if (ret == -ENOENT) {
+ *cfg_index = 0;
Does nvmem_cell_read_u8() cahnge cfg_index when it fails with -ENOENT?

No, if nvmem_cell_read_u8() fails with any error, cfg_index will not be changed.

Thanks
Komal
+ return 0;
+ }
+
+ return ret;
+}
+
static int qcom_llcc_remove(struct platform_device *pdev)
{
/* Set the global pointer to a error code to avoid referencing it */
@@ -975,11 +989,13 @@ static int qcom_llcc_probe(struct platform_device *pdev)
struct device *dev = &pdev->dev;
int ret, i;
struct platform_device *llcc_edac;
- const struct qcom_llcc_config *cfg;
+ const struct qcom_llcc_config *cfg, *entry;
const struct llcc_slice_config *llcc_cfg;
u32 sz;
+ u8 cfg_index;
u32 version;
struct regmap *regmap;
+ u32 num_entries = 0;

drv_data = devm_kzalloc(dev, sizeof(*drv_data), GFP_KERNEL);
if (!drv_data) {
@@ -1040,8 +1056,18 @@ static int qcom_llcc_probe(struct platform_device *pdev)

drv_data->version = version;

- llcc_cfg = cfg[0]->sct_data;
- sz = cfg[0]->size;
+ ret = qcom_llcc_get_cfg_index(pdev, &cfg_index);
+ if (ret)
+ goto err;
+
+ for (entry = cfg; entry->sct_data; entry++, num_entries++);
This is not readable, move the increment of num_entries out of there.

+ if (cfg_index >= num_entries || cfg_index < 0) {
How can cfg_index be negative?

Regards,
Bjorn

+ ret = -EINVAL;
+ goto err;
+ }
+
+ llcc_cfg = cfg[cfg_index].sct_data;
+ sz = cfg[cfg_index].size;

for (i = 0; i < sz; i++)
if (llcc_cfg[i].slice_id > drv_data->max_slices)
--
2.17.1