diff mbox series

[v9,1/4] memory: tegra: Add memory controller channels support

Message ID 20220426073827.25506-2-amhetre@nvidia.com
State Accepted
Headers show
Series memory: tegra: Add MC channels and error logging | expand

Commit Message

Ashish Mhetre April 26, 2022, 7:38 a.m. UTC
From tegra186 onwards, memory controller support multiple channels.
Add support for mapping address spaces of these channels.
Add number of channels supported by tegra186, tegra194 and tegra234.
In case of old bindings, channels won't be present. If channels are not
present then print warning and continue so that backward compatibility
will be preserved in driver.
During error interrupts from memory controller, appropriate registers
from these channels need to be accessed for logging error info.

Reviewed-by: Dmitry Osipenko <dmitry.osipenko@collabora.com>
Signed-off-by: Ashish Mhetre <amhetre@nvidia.com>
---
 drivers/memory/tegra/mc.c       |  6 ++++++
 drivers/memory/tegra/tegra186.c | 34 +++++++++++++++++++++++++++++++++
 drivers/memory/tegra/tegra194.c |  1 +
 drivers/memory/tegra/tegra234.c |  1 +
 include/soc/tegra/mc.h          |  4 ++++
 5 files changed, 46 insertions(+)

Comments

Krzysztof Kozlowski April 29, 2022, 7:11 a.m. UTC | #1
On 26/04/2022 09:38, Ashish Mhetre wrote:
> From tegra186 onwards, memory controller support multiple channels.
> Add support for mapping address spaces of these channels.
> Add number of channels supported by tegra186, tegra194 and tegra234.
> In case of old bindings, channels won't be present. If channels are not
> present then print warning and continue so that backward compatibility
> will be preserved in driver.
> During error interrupts from memory controller, appropriate registers
> from these channels need to be accessed for logging error info.
> 
> Reviewed-by: Dmitry Osipenko <dmitry.osipenko@collabora.com>
> Signed-off-by: Ashish Mhetre <amhetre@nvidia.com>
> ---
>  drivers/memory/tegra/mc.c       |  6 ++++++
>  drivers/memory/tegra/tegra186.c | 34 +++++++++++++++++++++++++++++++++
>  drivers/memory/tegra/tegra194.c |  1 +
>  drivers/memory/tegra/tegra234.c |  1 +

This does not apply, neither on my mem-ctrl-next, nor on master.
Probably because tegra234 is somewhere else (Thierry?). Either you send
it without tegra234 or it goes via Thierry's tree.

Best regards,
Krzysztof
Thierry Reding April 29, 2022, 8:30 a.m. UTC | #2
On Fri, Apr 29, 2022 at 09:11:59AM +0200, Krzysztof Kozlowski wrote:
> On 26/04/2022 09:38, Ashish Mhetre wrote:
> > From tegra186 onwards, memory controller support multiple channels.
> > Add support for mapping address spaces of these channels.
> > Add number of channels supported by tegra186, tegra194 and tegra234.
> > In case of old bindings, channels won't be present. If channels are not
> > present then print warning and continue so that backward compatibility
> > will be preserved in driver.
> > During error interrupts from memory controller, appropriate registers
> > from these channels need to be accessed for logging error info.
> > 
> > Reviewed-by: Dmitry Osipenko <dmitry.osipenko@collabora.com>
> > Signed-off-by: Ashish Mhetre <amhetre@nvidia.com>
> > ---
> >  drivers/memory/tegra/mc.c       |  6 ++++++
> >  drivers/memory/tegra/tegra186.c | 34 +++++++++++++++++++++++++++++++++
> >  drivers/memory/tegra/tegra194.c |  1 +
> >  drivers/memory/tegra/tegra234.c |  1 +
> 
> This does not apply, neither on my mem-ctrl-next, nor on master.
> Probably because tegra234 is somewhere else (Thierry?). Either you send
> it without tegra234 or it goes via Thierry's tree.

Yeah, I can apply these on top of my tree and then forward the whole
batch to you or ARM SoC next week.

Thierry
Dmitry Osipenko April 29, 2022, 8:50 a.m. UTC | #3
On 4/26/22 10:38, Ashish Mhetre wrote:
> +static int tegra186_mc_map_regs(struct tegra_mc *mc)
> +{
> +	struct platform_device *pdev = to_platform_device(mc->dev);
> +	unsigned int i;
> +
> +	mc->bcast_ch_regs = devm_platform_ioremap_resource_byname(pdev, "broadcast");
> +	if (IS_ERR(mc->bcast_ch_regs)) {
> +		if (PTR_ERR(mc->bcast_ch_regs) == -EINVAL) {
> +			dev_warn(&pdev->dev, "Broadcast channel is missing, please update your device-tree\n");
> +			mc->bcast_ch_regs = NULL;
> +			return 0;
> +		}
> +		return PTR_ERR(mc->bcast_ch_regs);
> +	}
> +
> +	mc->ch_regs = devm_kcalloc(mc->dev, mc->soc->num_channels,
> +				   sizeof(*mc->ch_regs), GFP_KERNEL);
> +	if (!mc->ch_regs)
> +		return -ENOMEM;
> +
> +	for (i = 0; i < mc->soc->num_channels; i++) {
> +		char name[5];
> +
> +		snprintf(name, sizeof(name), "ch%u", i);
> +		mc->ch_regs[i] = devm_platform_ioremap_resource_byname(pdev, name);
> +		if (IS_ERR(mc->ch_regs[i]))
> +			return PTR_ERR(mc->ch_regs[i]);
> +	}
> +
> +	return 0;
> +}
> +
>  const struct tegra_mc_ops tegra186_mc_ops = {
>  	.probe = tegra186_mc_probe,
>  	.remove = tegra186_mc_remove,
>  	.resume = tegra186_mc_resume,
>  	.probe_device = tegra186_mc_probe_device,
> +	.map_regs = tegra186_mc_map_regs,
>  };

Do we really need the map_regs() callback? Could you please move it to
the tegra186_mc_probe()? .. Sorry, I haven't noticed this previously.
Ashish Mhetre April 29, 2022, 10:47 a.m. UTC | #4
On 4/29/2022 2:20 PM, Dmitry Osipenko wrote:
> External email: Use caution opening links or attachments
> 
> 
> On 4/26/22 10:38, Ashish Mhetre wrote:
>> +static int tegra186_mc_map_regs(struct tegra_mc *mc)
>> +{
>> +     struct platform_device *pdev = to_platform_device(mc->dev);
>> +     unsigned int i;
>> +
>> +     mc->bcast_ch_regs = devm_platform_ioremap_resource_byname(pdev, "broadcast");
>> +     if (IS_ERR(mc->bcast_ch_regs)) {
>> +             if (PTR_ERR(mc->bcast_ch_regs) == -EINVAL) {
>> +                     dev_warn(&pdev->dev, "Broadcast channel is missing, please update your device-tree\n");
>> +                     mc->bcast_ch_regs = NULL;
>> +                     return 0;
>> +             }
>> +             return PTR_ERR(mc->bcast_ch_regs);
>> +     }
>> +
>> +     mc->ch_regs = devm_kcalloc(mc->dev, mc->soc->num_channels,
>> +                                sizeof(*mc->ch_regs), GFP_KERNEL);
>> +     if (!mc->ch_regs)
>> +             return -ENOMEM;
>> +
>> +     for (i = 0; i < mc->soc->num_channels; i++) {
>> +             char name[5];
>> +
>> +             snprintf(name, sizeof(name), "ch%u", i);
>> +             mc->ch_regs[i] = devm_platform_ioremap_resource_byname(pdev, name);
>> +             if (IS_ERR(mc->ch_regs[i]))
>> +                     return PTR_ERR(mc->ch_regs[i]);
>> +     }
>> +
>> +     return 0;
>> +}
>> +
>>   const struct tegra_mc_ops tegra186_mc_ops = {
>>        .probe = tegra186_mc_probe,
>>        .remove = tegra186_mc_remove,
>>        .resume = tegra186_mc_resume,
>>        .probe_device = tegra186_mc_probe_device,
>> +     .map_regs = tegra186_mc_map_regs,
>>   };
> 
> Do we really need the map_regs() callback? Could you please move it to
> the tegra186_mc_probe()? .. Sorry, I haven't noticed this previously.

Okay, I'll update this.
diff mbox series

Patch

diff --git a/drivers/memory/tegra/mc.c b/drivers/memory/tegra/mc.c
index bf3abb6d8354..c1dd24542093 100644
--- a/drivers/memory/tegra/mc.c
+++ b/drivers/memory/tegra/mc.c
@@ -749,6 +749,12 @@  static int tegra_mc_probe(struct platform_device *pdev)
 	if (IS_ERR(mc->regs))
 		return PTR_ERR(mc->regs);
 
+	if (mc->soc->ops && mc->soc->ops->map_regs) {
+		err = mc->soc->ops->map_regs(mc);
+		if (err < 0)
+			return err;
+	}
+
 	mc->debugfs.root = debugfs_create_dir("mc", NULL);
 
 	if (mc->soc->ops && mc->soc->ops->probe) {
diff --git a/drivers/memory/tegra/tegra186.c b/drivers/memory/tegra/tegra186.c
index 3d153881abc1..e20ea38d5f35 100644
--- a/drivers/memory/tegra/tegra186.c
+++ b/drivers/memory/tegra/tegra186.c
@@ -139,11 +139,44 @@  static int tegra186_mc_probe_device(struct tegra_mc *mc, struct device *dev)
 	return 0;
 }
 
+static int tegra186_mc_map_regs(struct tegra_mc *mc)
+{
+	struct platform_device *pdev = to_platform_device(mc->dev);
+	unsigned int i;
+
+	mc->bcast_ch_regs = devm_platform_ioremap_resource_byname(pdev, "broadcast");
+	if (IS_ERR(mc->bcast_ch_regs)) {
+		if (PTR_ERR(mc->bcast_ch_regs) == -EINVAL) {
+			dev_warn(&pdev->dev, "Broadcast channel is missing, please update your device-tree\n");
+			mc->bcast_ch_regs = NULL;
+			return 0;
+		}
+		return PTR_ERR(mc->bcast_ch_regs);
+	}
+
+	mc->ch_regs = devm_kcalloc(mc->dev, mc->soc->num_channels,
+				   sizeof(*mc->ch_regs), GFP_KERNEL);
+	if (!mc->ch_regs)
+		return -ENOMEM;
+
+	for (i = 0; i < mc->soc->num_channels; i++) {
+		char name[5];
+
+		snprintf(name, sizeof(name), "ch%u", i);
+		mc->ch_regs[i] = devm_platform_ioremap_resource_byname(pdev, name);
+		if (IS_ERR(mc->ch_regs[i]))
+			return PTR_ERR(mc->ch_regs[i]);
+	}
+
+	return 0;
+}
+
 const struct tegra_mc_ops tegra186_mc_ops = {
 	.probe = tegra186_mc_probe,
 	.remove = tegra186_mc_remove,
 	.resume = tegra186_mc_resume,
 	.probe_device = tegra186_mc_probe_device,
+	.map_regs = tegra186_mc_map_regs,
 };
 
 #if defined(CONFIG_ARCH_TEGRA_186_SOC)
@@ -875,6 +908,7 @@  const struct tegra_mc_soc tegra186_mc_soc = {
 	.num_clients = ARRAY_SIZE(tegra186_mc_clients),
 	.clients = tegra186_mc_clients,
 	.num_address_bits = 40,
+	.num_channels = 4,
 	.ops = &tegra186_mc_ops,
 };
 #endif
diff --git a/drivers/memory/tegra/tegra194.c b/drivers/memory/tegra/tegra194.c
index cab998b8bd5c..94001174deaf 100644
--- a/drivers/memory/tegra/tegra194.c
+++ b/drivers/memory/tegra/tegra194.c
@@ -1347,5 +1347,6 @@  const struct tegra_mc_soc tegra194_mc_soc = {
 	.num_clients = ARRAY_SIZE(tegra194_mc_clients),
 	.clients = tegra194_mc_clients,
 	.num_address_bits = 40,
+	.num_channels = 16,
 	.ops = &tegra186_mc_ops,
 };
diff --git a/drivers/memory/tegra/tegra234.c b/drivers/memory/tegra/tegra234.c
index e22824a79f45..6335a132be2d 100644
--- a/drivers/memory/tegra/tegra234.c
+++ b/drivers/memory/tegra/tegra234.c
@@ -97,5 +97,6 @@  const struct tegra_mc_soc tegra234_mc_soc = {
 	.num_clients = ARRAY_SIZE(tegra234_mc_clients),
 	.clients = tegra234_mc_clients,
 	.num_address_bits = 40,
+	.num_channels = 16,
 	.ops = &tegra186_mc_ops,
 };
diff --git a/include/soc/tegra/mc.h b/include/soc/tegra/mc.h
index 1066b1194a5a..42b9c509773e 100644
--- a/include/soc/tegra/mc.h
+++ b/include/soc/tegra/mc.h
@@ -181,6 +181,7 @@  struct tegra_mc_ops {
 	int (*resume)(struct tegra_mc *mc);
 	irqreturn_t (*handle_irq)(int irq, void *data);
 	int (*probe_device)(struct tegra_mc *mc, struct device *dev);
+	int (*map_regs)(struct tegra_mc *mc);
 };
 
 struct tegra_mc_soc {
@@ -194,6 +195,7 @@  struct tegra_mc_soc {
 	unsigned int atom_size;
 
 	u8 client_id_mask;
+	u8 num_channels;
 
 	const struct tegra_smmu_soc *smmu;
 
@@ -212,6 +214,8 @@  struct tegra_mc {
 	struct tegra_smmu *smmu;
 	struct gart_device *gart;
 	void __iomem *regs;
+	void __iomem *bcast_ch_regs;
+	void __iomem **ch_regs;
 	struct clk *clk;
 	int irq;