mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Colin Foster <colin.foster@in-advantage.com>
To: linux-kernel@vger.kernel.org
Cc: "Rafael J. Wysocki" <rafael@kernel.org>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Mark Brown <broonie@kernel.org>
Subject: [RFC v1 0/2] Add more detailed regmap formatting capabilities
Date: Sun, 13 Mar 2022 15:45:22 -0700	[thread overview]
Message-ID: <20220313224524.399947-1-colin.foster@in-advantage.com> (raw)

The Ocelot chips (specifically the VSC7512 I'm using) have a method of
accessing their registers internally via MMIO, or externally via SPI.
When accessing these registers externally, a 24-bit address is used and
downshifted by two. The manual references it as:

SI_ADDR = (REG_ADDR & 0x00FFFFFF) >> 2;

By adding this configurable downshift, and a configurable register base
address, the regmap definitions can be shared between MMIO and SPI
configurations.

This also allows regmap to be used in a bus configuration. My initial
testing shows that even at a much slower bus speed of 500KHz, I'm seeing
an improvement of 10ms (was 14... now 4) to perform bulk read operations.

The relevant MMIO code can be found in drivers/net/mscc/ocelot_io.c:

static struct regmap_config ocelot_regmap_config = {
        .reg_bits       = 32,
        .val_bits       = 32,
        .reg_stride     = 4,
};

struct regmap *ocelot_regmap_init(struct ocelot *ocelot, struct resource *res)
{
        void __iomem *regs;

        regs = devm_ioremap_resource(ocelot->dev, res);
        if (IS_ERR(regs))
                return ERR_CAST(regs);

        ocelot_regmap_config.name = res->name;

        return devm_regmap_init_mmio(ocelot->dev, regs, &ocelot_regmap_config);
}


And the SPI counterpart is slightly more complex:


static const struct regmap_config ocelot_spi_regmap_config = {
        .reg_bits = 24,
        .reg_stride = 4,
        .reg_downshift = 2,
        .val_bits = 32,

        .write_flag_mask = 0x80,

        .max_register = 0xffffffff,
        .use_single_write = true,
        .can_multi_write = false,

        .reg_format_endian = REGMAP_ENDIAN_BIG,
        .val_format_endian = REGMAP_ENDIAN_NATIVE,
};

static const struct regmap_bus ocelot_spi_regmap_bus = {
       .write = ocelot_spi_regmap_bus_write,
       .read = ocelot_spi_regmap_bus_read,
};

struct regmap *
ocelot_spi_devm_get_regmap(struct ocelot_core *core, struct device *child,
                           const struct resource *res)
{
        struct regmap_config regmap_config;

        memcpy(&regmap_config, &ocelot_spi_regmap_config,
               sizeof(ocelot_spi_regmap_config));

        regmap_config.name = res->name;
        regmap_config.max_register = res->end - res->start;
        regmap_config.reg_base = res->start;

        return devm_regmap_init(child, &ocelot_spi_regmap_bus, core,
                                &regmap_config);
}


If there's anything I missed, or if there's a different way to go about
this, please let me know. I can also drag this along with my VSC7512
development or I can send this patch (or whatever it might become) after
the merge window.


Colin Foster (2):
  regmap: add configurable downshift for addresses
  regmap: allow a defined reg_base to be added to every address

 drivers/base/regmap/internal.h |  2 ++
 drivers/base/regmap/regmap.c   | 11 +++++++++++
 include/linux/regmap.h         |  6 ++++++
 3 files changed, 19 insertions(+)

-- 
2.25.1


             reply	other threads:[~2022-03-13 22:45 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-03-13 22:45 Colin Foster [this message]
2022-03-13 22:45 ` [RFC v1 1/2] regmap: add configurable downshift for addresses Colin Foster
2022-03-13 22:45 ` [RFC v1 2/2] regmap: allow a defined reg_base to be added to every address Colin Foster
2022-03-14  8:28   ` Mark Brown
2022-03-14 15:37     ` Colin Foster
2022-03-18 20:57 ` [RFC v1 0/2] Add more detailed regmap formatting capabilities Mark Brown
2022-03-19  0:13   ` Colin Foster

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=20220313224524.399947-1-colin.foster@in-advantage.com \
    --to=colin.foster@in-advantage.com \
    --cc=broonie@kernel.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=rafael@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

all inboxes | Powered by JetHome®