From: Jerome Brunet <jbrunet@baylibre.com>
To: Philipp Zabel <p.zabel@pengutronix.de>
Cc: Stephen Boyd <sboyd@kernel.org>,
Neil Armstrong <neil.armstrong@linaro.org>,
Kevin Hilman <khilman@baylibre.com>,
Martin Blumenstingl <martin.blumenstingl@googlemail.com>,
Jiucheng Xu <jiucheng.xu@amlogic.com>,
linux-arm-kernel@lists.infradead.org,
linux-amlogic@lists.infradead.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v4 1/9] reset: amlogic: convert driver to regmap
Date: Fri, 06 Sep 2024 16:46:36 +0200 [thread overview]
Message-ID: <1jfrqcrgab.fsf@starbuckisacylon.baylibre.com> (raw)
In-Reply-To: <984d928a37b3db11ae53c07da672ccae0d79734f.camel@pengutronix.de> (Philipp Zabel's message of "Fri, 06 Sep 2024 16:19:00 +0200")
On Fri 06 Sep 2024 at 16:19, Philipp Zabel <p.zabel@pengutronix.de> wrote:
> On Fr, 2024-09-06 at 15:34 +0200, Jerome Brunet wrote:
>> To allow using the same driver for the main reset controller and the
>> auxiliary ones embedded in the clock controllers, convert the
>> the Amlogic reset driver to regmap.
>>
>> Reviewed-by: Neil Armstrong <neil.armstrong@linaro.org>
>> Signed-off-by: Jerome Brunet <jbrunet@baylibre.com>
>> ---
>> drivers/reset/reset-meson.c | 79 ++++++++++++++++++++++++---------------------
>
> This patch should also make RESET_MESON select REGMAP.
Indeed
>
>> 1 file changed, 43 insertions(+), 36 deletions(-)
>>
>> diff --git a/drivers/reset/reset-meson.c b/drivers/reset/reset-meson.c
>> index 1e9fca3e30e8..9dd38cc209e2 100644
>> --- a/drivers/reset/reset-meson.c
>> +++ b/drivers/reset/reset-meson.c
>> @@ -11,36 +11,43 @@
>> #include <linux/of.h>
>> #include <linux/module.h>
>> #include <linux/platform_device.h>
>> +#include <linux/regmap.h>
>> #include <linux/reset-controller.h>
>> #include <linux/slab.h>
>> #include <linux/types.h>
>>
>> -#define BITS_PER_REG 32
>> -
>> struct meson_reset_param {
>> int reg_count;
>> int level_offset;
>> };
>>
>> struct meson_reset {
>> - void __iomem *reg_base;
>> const struct meson_reset_param *param;
>> struct reset_controller_dev rcdev;
>> - spinlock_t lock;
>> + struct regmap *map;
>> };
>>
>> +static void meson_reset_offset_and_bit(struct meson_reset *data,
>> + unsigned long id,
>> + unsigned int *offset,
>> + unsigned int *bit)
>> +{
>> + unsigned int stride = regmap_get_reg_stride(data->map);
>
> You know this is always 4. Having a #define for this (that is also used
> to initialize regmap_config.reg_stride, and for now nr_resets, below)
> instead of going through an exported function would allow the compiler
> to optimize this all away:
Yes, for now. However, with the auxiliary you may get a regmap with
different value. I've seen example with stride = 1.
I'll admit is very unlikely but I does not really worth it considering
how often we'll get through this and how difficult it will be to debug
if stride ever get different.
>
>> +
>> + *offset = (id / (stride * BITS_PER_BYTE)) * stride;
>> + *bit = id % (stride * BITS_PER_BYTE);
>> +}
>> +
>> static int meson_reset_reset(struct reset_controller_dev *rcdev,
>> - unsigned long id)
>> + unsigned long id)
>> {
>> struct meson_reset *data =
>> container_of(rcdev, struct meson_reset, rcdev);
>> - unsigned int bank = id / BITS_PER_REG;
>> - unsigned int offset = id % BITS_PER_REG;
>> - void __iomem *reg_addr = data->reg_base + (bank << 2);
>> + unsigned int offset, bit;
>>
>> - writel(BIT(offset), reg_addr);
>> + meson_reset_offset_and_bit(data, id, &offset, &bit);
>>
>> - return 0;
>> + return regmap_write(data->map, offset, BIT(bit));
>> }
>>
>> static int meson_reset_level(struct reset_controller_dev *rcdev,
>> @@ -48,25 +55,13 @@ static int meson_reset_level(struct reset_controller_dev *rcdev,
>> {
>> struct meson_reset *data =
>> container_of(rcdev, struct meson_reset, rcdev);
>> - unsigned int bank = id / BITS_PER_REG;
>> - unsigned int offset = id % BITS_PER_REG;
>> - void __iomem *reg_addr;
>> - unsigned long flags;
>> - u32 reg;
>> + unsigned int offset, bit;
>>
>> - reg_addr = data->reg_base + data->param->level_offset + (bank << 2);
>> + meson_reset_offset_and_bit(data, id, &offset, &bit);
>> + offset += data->param->level_offset;
>>
>> - spin_lock_irqsave(&data->lock, flags);
>> -
>> - reg = readl(reg_addr);
>> - if (assert)
>> - writel(reg & ~BIT(offset), reg_addr);
>> - else
>> - writel(reg | BIT(offset), reg_addr);
>> -
>> - spin_unlock_irqrestore(&data->lock, flags);
>> -
>> - return 0;
>> + return regmap_update_bits(data->map, offset,
>> + BIT(bit), assert ? 0 : BIT(bit));
>
> Matter of taste, perhaps, but the BIT() could be moved into
> meson_reset_offset_and_bit().
It's not really related to this particular patch which is about moving
to regmap.
I can add it to another patch if you want
>
>> }
>>
>> static int meson_reset_assert(struct reset_controller_dev *rcdev,
>> @@ -119,30 +114,42 @@ static const struct of_device_id meson_reset_dt_ids[] = {
>> };
>> MODULE_DEVICE_TABLE(of, meson_reset_dt_ids);
>>
>> +static const struct regmap_config regmap_config = {
>> + .reg_bits = 32,
>> + .val_bits = 32,
>> + .reg_stride = 4,
>> +};
>> +
>> static int meson_reset_probe(struct platform_device *pdev)
>> {
>> + struct device *dev = &pdev->dev;
>> struct meson_reset *data;
>> + void __iomem *base;
>>
>> - data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL);
>> + data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL);
>> if (!data)
>> return -ENOMEM;
>>
>> - data->reg_base = devm_platform_ioremap_resource(pdev, 0);
>> - if (IS_ERR(data->reg_base))
>> - return PTR_ERR(data->reg_base);
>> + base = devm_platform_ioremap_resource(pdev, 0);
>> + if (IS_ERR(base))
>> + return PTR_ERR(base);
>>
>> - data->param = of_device_get_match_data(&pdev->dev);
>> + data->param = of_device_get_match_data(dev);
>> if (!data->param)
>> return -ENODEV;
>>
>> - spin_lock_init(&data->lock);
>> + data->map = devm_regmap_init_mmio(dev, base, ®map_config);
>> + if (IS_ERR(data->map))
>> + return dev_err_probe(dev, PTR_ERR(data->map),
>> + "can't init regmap mmio region\n");
>>
>> data->rcdev.owner = THIS_MODULE;
>> - data->rcdev.nr_resets = data->param->reg_count * BITS_PER_REG;
>> + data->rcdev.nr_resets = data->param->reg_count * BITS_PER_BYTE
>> + * regmap_config.reg_stride;
>> data->rcdev.ops = &meson_reset_ops;
>> - data->rcdev.of_node = pdev->dev.of_node;
>> + data->rcdev.of_node = dev->of_node;
>>
>> - return devm_reset_controller_register(&pdev->dev, &data->rcdev);
>> + return devm_reset_controller_register(dev, &data->rcdev);
>> }
>>
>> static struct platform_driver meson_reset_driver = {
>
> regards
> Philipp
--
Jerome
_______________________________________________
linux-amlogic mailing list
linux-amlogic@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-amlogic
next prev parent reply other threads:[~2024-09-06 14:47 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-09-06 13:34 [PATCH v4 0/9] reset: amlogic: move audio reset drivers out of CCF Jerome Brunet
2024-09-06 13:34 ` [PATCH v4 1/9] reset: amlogic: convert driver to regmap Jerome Brunet
2024-09-06 14:19 ` Philipp Zabel
2024-09-06 14:46 ` Jerome Brunet [this message]
2024-09-10 8:20 ` Philipp Zabel
2024-09-06 13:34 ` [PATCH v4 2/9] reset: amlogic: use generic data matching function Jerome Brunet
2024-09-06 13:34 ` [PATCH v4 3/9] reset: amlogic: make parameters unsigned Jerome Brunet
2024-09-06 13:34 ` [PATCH v4 4/9] reset: amlogic: add driver parameters Jerome Brunet
2024-09-06 13:34 ` [PATCH v4 5/9] reset: amlogic: use reset number instead of register count Jerome Brunet
2024-09-06 13:34 ` [PATCH v4 6/9] reset: amlogic: add reset status support Jerome Brunet
2024-09-06 13:34 ` [PATCH v4 7/9] reset: amlogic: move drivers to a dedicated directory Jerome Brunet
2024-09-06 13:34 ` [PATCH v4 8/9] reset: amlogic: split the device core and platform probe Jerome Brunet
2024-09-06 13:34 ` [PATCH v4 9/9] reset: amlogic: add auxiliary reset driver support Jerome Brunet
2024-09-09 16:42 ` kernel test robot
2024-09-09 17:31 ` Jerome Brunet
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1jfrqcrgab.fsf@starbuckisacylon.baylibre.com \
--to=jbrunet@baylibre.com \
--cc=jiucheng.xu@amlogic.com \
--cc=khilman@baylibre.com \
--cc=linux-amlogic@lists.infradead.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=martin.blumenstingl@googlemail.com \
--cc=neil.armstrong@linaro.org \
--cc=p.zabel@pengutronix.de \
--cc=sboyd@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox