2021-08-25 10:29:26

by Enric Balletbo i Serra

[permalink] [raw]
Subject: [PATCH v3 6/7] soc: mediatek: mmsys: Add reset controller support

Among other features the mmsys driver should implement a reset
controller to be able to reset different bits from their space.

Cc: Jitao Shi <[email protected]>
Suggested-by: Chun-Kuang Hu <[email protected]>
Signed-off-by: Enric Balletbo i Serra <[email protected]>
Reviewed-by: Philipp Zabel <[email protected]>
---

(no changes since v1)

drivers/soc/mediatek/mtk-mmsys.c | 69 ++++++++++++++++++++++++++++++++
drivers/soc/mediatek/mtk-mmsys.h | 2 +
2 files changed, 71 insertions(+)

diff --git a/drivers/soc/mediatek/mtk-mmsys.c b/drivers/soc/mediatek/mtk-mmsys.c
index a78e88f27b62..855a3a50840c 100644
--- a/drivers/soc/mediatek/mtk-mmsys.c
+++ b/drivers/soc/mediatek/mtk-mmsys.c
@@ -4,10 +4,12 @@
* Author: James Liao <[email protected]>
*/

+#include <linux/delay.h>
#include <linux/device.h>
#include <linux/io.h>
#include <linux/of_device.h>
#include <linux/platform_device.h>
+#include <linux/reset-controller.h>
#include <linux/soc/mediatek/mtk-mmsys.h>

#include "mtk-mmsys.h"
@@ -62,6 +64,8 @@ static const struct mtk_mmsys_driver_data mt8365_mmsys_driver_data = {
struct mtk_mmsys {
void __iomem *regs;
const struct mtk_mmsys_driver_data *data;
+ spinlock_t lock; /* protects mmsys_sw_rst_b reg */
+ struct reset_controller_dev rcdev;
};

void mtk_mmsys_ddp_connect(struct device *dev,
@@ -101,6 +105,59 @@ void mtk_mmsys_ddp_disconnect(struct device *dev,
}
EXPORT_SYMBOL_GPL(mtk_mmsys_ddp_disconnect);

+static int mtk_mmsys_reset_update(struct reset_controller_dev *rcdev, unsigned long id,
+ bool assert)
+{
+ struct mtk_mmsys *mmsys = container_of(rcdev, struct mtk_mmsys, rcdev);
+ unsigned long flags;
+ u32 reg;
+ int i;
+
+ spin_lock_irqsave(&mmsys->lock, flags);
+
+ reg = readl_relaxed(mmsys->regs + MMSYS_SW0_RST_B);
+
+ if (assert)
+ reg &= ~BIT(id);
+ else
+ reg |= BIT(id);
+
+ writel_relaxed(reg, mmsys->regs + MMSYS_SW0_RST_B);
+
+ spin_unlock_irqrestore(&mmsys->lock, flags);
+
+ return 0;
+}
+
+static int mtk_mmsys_reset_assert(struct reset_controller_dev *rcdev, unsigned long id)
+{
+ return mtk_mmsys_reset_update(rcdev, id, true);
+}
+
+static int mtk_mmsys_reset_deassert(struct reset_controller_dev *rcdev, unsigned long id)
+{
+ return mtk_mmsys_reset_update(rcdev, id, false);
+}
+
+static int mtk_mmsys_reset(struct reset_controller_dev *rcdev, unsigned long id)
+{
+ int ret;
+
+ ret = mtk_mmsys_reset_assert(rcdev, id);
+ if (ret)
+ return ret;
+
+ usleep_range(1000, 1100);
+
+ return mtk_mmsys_reset_deassert(rcdev, id);
+}
+
+static const struct reset_control_ops mtk_mmsys_reset_ops = {
+ .assert = mtk_mmsys_reset_assert,
+ .deassert = mtk_mmsys_reset_deassert,
+ .reset = mtk_mmsys_reset,
+};
+
static int mtk_mmsys_probe(struct platform_device *pdev)
{
struct device *dev = &pdev->dev;
@@ -120,6 +177,18 @@ static int mtk_mmsys_probe(struct platform_device *pdev)
return ret;
}

+ spin_lock_init(&mmsys->lock);
+
+ mmsys->rcdev.owner = THIS_MODULE;
+ mmsys->rcdev.nr_resets = 32;
+ mmsys->rcdev.ops = &mtk_mmsys_reset_ops;
+ mmsys->rcdev.of_node = pdev->dev.of_node;
+ ret = devm_reset_controller_register(&pdev->dev, &mmsys->rcdev);
+ if (ret) {
+ dev_err(&pdev->dev, "Couldn't register mmsys reset controller: %d\n", ret);
+ return ret;
+ }
+
mmsys->data = of_device_get_match_data(&pdev->dev);
platform_set_drvdata(pdev, mmsys);

diff --git a/drivers/soc/mediatek/mtk-mmsys.h b/drivers/soc/mediatek/mtk-mmsys.h
index 9e2b81bd38db..8b0ed05117ea 100644
--- a/drivers/soc/mediatek/mtk-mmsys.h
+++ b/drivers/soc/mediatek/mtk-mmsys.h
@@ -78,6 +78,8 @@
#define DSI_SEL_IN_RDMA 0x1
#define DSI_SEL_IN_MASK 0x1

+#define MMSYS_SW0_RST_B 0x140
+
struct mtk_mmsys_routes {
u32 from_comp;
u32 to_comp;
--
2.30.2


2021-08-25 10:52:19

by Philipp Zabel

[permalink] [raw]
Subject: Re: [PATCH v3 6/7] soc: mediatek: mmsys: Add reset controller support

On Wed, 2021-08-25 at 12:26 +0200, Enric Balletbo i Serra wrote:
> Among other features the mmsys driver should implement a reset
> controller to be able to reset different bits from their space.
>
> Cc: Jitao Shi <[email protected]>
> Suggested-by: Chun-Kuang Hu <[email protected]>
> Signed-off-by: Enric Balletbo i Serra <[email protected]>
> Reviewed-by: Philipp Zabel <[email protected]>
> ---
>
> (no changes since v1)
>
> drivers/soc/mediatek/mtk-mmsys.c | 69 ++++++++++++++++++++++++++++++++
> drivers/soc/mediatek/mtk-mmsys.h | 2 +

Cc: Nancy - this patch clashes with [1], please coordinate.

[1] https://lore.kernel.org/linux-arm-kernel/[email protected]/

regards
Philipp

2021-08-26 00:35:47

by Chun-Kuang Hu

[permalink] [raw]
Subject: Re: [PATCH v3 6/7] soc: mediatek: mmsys: Add reset controller support

Philipp Zabel <[email protected]> 於 2021年8月25日 週三 下午6:46寫道:
>
> On Wed, 2021-08-25 at 12:26 +0200, Enric Balletbo i Serra wrote:
> > Among other features the mmsys driver should implement a reset
> > controller to be able to reset different bits from their space.
> >
> > Cc: Jitao Shi <[email protected]>
> > Suggested-by: Chun-Kuang Hu <[email protected]>
> > Signed-off-by: Enric Balletbo i Serra <[email protected]>
> > Reviewed-by: Philipp Zabel <[email protected]>
> > ---
> >
> > (no changes since v1)
> >
> > drivers/soc/mediatek/mtk-mmsys.c | 69 ++++++++++++++++++++++++++++++++
> > drivers/soc/mediatek/mtk-mmsys.h | 2 +
>
> Cc: Nancy - this patch clashes with [1], please coordinate.
>
> [1] https://lore.kernel.org/linux-arm-kernel/[email protected]/

Enric's series is all reviewed or acked, so I think Nancy's series
should base on Enric's series.

Regards,
Chun-Kuang.

>
> regards
> Philipp

2021-09-03 14:13:15

by Enric Balletbo i Serra

[permalink] [raw]
Subject: Re: [PATCH v3 6/7] soc: mediatek: mmsys: Add reset controller support

Hi Nancy,

(again in plain text, sorry for the noise)

On 26/8/21 2:33, Chun-Kuang Hu wrote:
> Philipp Zabel <[email protected]> 於 2021年8月25日 週三 下午6:46寫道:
>>
>> On Wed, 2021-08-25 at 12:26 +0200, Enric Balletbo i Serra wrote:
>>> Among other features the mmsys driver should implement a reset
>>> controller to be able to reset different bits from their space.
>>>
>>> Cc: Jitao Shi <[email protected]>
>>> Suggested-by: Chun-Kuang Hu <[email protected]>
>>> Signed-off-by: Enric Balletbo i Serra <[email protected]>
>>> Reviewed-by: Philipp Zabel <[email protected]>
>>> ---
>>>
>>> (no changes since v1)
>>>
>>> drivers/soc/mediatek/mtk-mmsys.c | 69 ++++++++++++++++++++++++++++++++
>>> drivers/soc/mediatek/mtk-mmsys.h | 2 +
>>
>> Cc: Nancy - this patch clashes with [1], please coordinate.
>>
>> [1] https://lore.kernel.org/linux-arm-kernel/[email protected]/
>
> Enric's series is all reviewed or acked, so I think Nancy's series
> should base on Enric's series.
>

Is it fine with you to base you patches on top of this patchset?

Thanks,
Enric


> Regards,
> Chun-Kuang.
>
>>
>> regards
>> Philipp
>

2021-09-16 06:09:40

by Hsin-Yi Wang

[permalink] [raw]
Subject: Re: [PATCH v3 6/7] soc: mediatek: mmsys: Add reset controller support

On Wed, Aug 25, 2021 at 6:26 PM Enric Balletbo i Serra
<[email protected]> wrote:
>
> Among other features the mmsys driver should implement a reset
> controller to be able to reset different bits from their space.
>
> Cc: Jitao Shi <[email protected]>
> Suggested-by: Chun-Kuang Hu <[email protected]>
> Signed-off-by: Enric Balletbo i Serra <[email protected]>
> Reviewed-by: Philipp Zabel <[email protected]>
> ---
>
> (no changes since v1)
>
<snip>
> +static int mtk_mmsys_reset_update(struct reset_controller_dev *rcdev, unsigned long id,
> + bool assert)
> +{
> + struct mtk_mmsys *mmsys = container_of(rcdev, struct mtk_mmsys, rcdev);
> + unsigned long flags;
> + u32 reg;
> + int i;
This variable is not used.

> +
> + spin_lock_irqsave(&mmsys->lock, flags);
> +
> + reg = readl_relaxed(mmsys->regs + MMSYS_SW0_RST_B);
> +
> + if (assert)
> + reg &= ~BIT(id);
> + else
> + reg |= BIT(id);
> +
> + writel_relaxed(reg, mmsys->regs + MMSYS_SW0_RST_B);
> +
> + spin_unlock_irqrestore(&mmsys->lock, flags);
> +
> + return 0;
> +}
> +
<snip>