From: Serge Semin <Sergey.Semin@baikalelectronics.ru>
To: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Cc: Serge Semin <fancer.lancer@gmail.com>,
Jarkko Nikula <jarkko.nikula@linux.intel.com>,
Wolfram Sang <wsa@the-dreams.de>,
Mika Westerberg <mika.westerberg@linux.intel.com>,
Alexey Malahov <Alexey.Malahov@baikalelectronics.ru>,
Thomas Bogendoerfer <tsbogend@alpha.franken.de>,
Rob Herring <robh+dt@kernel.org>, <linux-mips@vger.kernel.org>,
<devicetree@vger.kernel.org>, <linux-i2c@vger.kernel.org>,
<linux-kernel@vger.kernel.org>
Subject: Re: [PATCH v4 11/11] i2c: designware: Add Baikal-T1 System I2C support
Date: Wed, 27 May 2020 18:04:31 +0300 [thread overview]
Message-ID: <20200527150431.z25aibkn6edplneh@mobilestation> (raw)
In-Reply-To: <20200527140303.GC1634618@smile.fi.intel.com>
On Wed, May 27, 2020 at 05:03:03PM +0300, Andy Shevchenko wrote:
> On Wed, May 27, 2020 at 03:01:11PM +0300, Serge Semin wrote:
> > Baikal-T1 System Controller is equipped with a dedicated I2C Controller
> > which functionality is based on the DW APB I2C IP-core, the only
> > difference in a way it' registers are accessed. There are three access
> > register provided in the System Controller registers map, which indirectly
> > address the normal DW APB I2C registers space. So in order to have the
> > Baikal-T1 System I2C Controller supported by the common DW APB I2C driver
> > we created a dedicated Dw I2C controller model quirk, which retrieves the
> > syscon regmap from the parental dt node and creates a new regmap based on
> > it.
>
> Yes, you see how cool it is now! FWIW,
Well, solution with glue-layers I liked more than this one. If your were
talking regarding the regmap conversion itself. I admit, it's neater.)
-Sergey
> Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
>
> > Signed-off-by: Serge Semin <Sergey.Semin@baikalelectronics.ru>
> > Cc: Alexey Malahov <Alexey.Malahov@baikalelectronics.ru>
> > Cc: Thomas Bogendoerfer <tsbogend@alpha.franken.de>
> > Cc: Rob Herring <robh+dt@kernel.org>
> > Cc: linux-mips@vger.kernel.org
> > Cc: devicetree@vger.kernel.org
> >
> > ---
> >
> > Changelog v3:
> > - This is a new patch, which has been created due to declining the
> > glue-layer approach.
> >
> > Changelog v4:
> > - Use PTR_ERR_OR_ZERO() helper in the bt1_i2c_request_regs() method.
> > ---
> > drivers/i2c/busses/Kconfig | 3 +-
> > drivers/i2c/busses/i2c-designware-core.h | 3 +
> > drivers/i2c/busses/i2c-designware-platdrv.c | 78 ++++++++++++++++++++-
> > 3 files changed, 81 insertions(+), 3 deletions(-)
> >
> > diff --git a/drivers/i2c/busses/Kconfig b/drivers/i2c/busses/Kconfig
> > index 259e2325712a..0cf7aea30138 100644
> > --- a/drivers/i2c/busses/Kconfig
> > +++ b/drivers/i2c/busses/Kconfig
> > @@ -541,8 +541,9 @@ config I2C_DESIGNWARE_SLAVE
> >
> > config I2C_DESIGNWARE_PLATFORM
> > tristate "Synopsys DesignWare Platform"
> > - select I2C_DESIGNWARE_CORE
> > depends on (ACPI && COMMON_CLK) || !ACPI
> > + select I2C_DESIGNWARE_CORE
> > + select MFD_SYSCON if MIPS_BAIKAL_T1
> > help
> > If you say yes to this option, support will be included for the
> > Synopsys DesignWare I2C adapter.
> > diff --git a/drivers/i2c/busses/i2c-designware-core.h b/drivers/i2c/busses/i2c-designware-core.h
> > index f5bbe3d6bcf8..556673a1f61b 100644
> > --- a/drivers/i2c/busses/i2c-designware-core.h
> > +++ b/drivers/i2c/busses/i2c-designware-core.h
> > @@ -183,6 +183,7 @@ struct reset_control;
> > * struct dw_i2c_dev - private i2c-designware data
> > * @dev: driver model device node
> > * @map: IO registers map
> > + * @sysmap: System controller registers map
> > * @base: IO registers pointer
> > * @ext: Extended IO registers pointer
> > * @cmd_complete: tx completion indicator
> > @@ -235,6 +236,7 @@ struct reset_control;
> > struct dw_i2c_dev {
> > struct device *dev;
> > struct regmap *map;
> > + struct regmap *sysmap;
> > void __iomem *base;
> > void __iomem *ext;
> > struct completion cmd_complete;
> > @@ -290,6 +292,7 @@ struct dw_i2c_dev {
> > #define ACCESS_NO_IRQ_SUSPEND 0x00000002
> >
> > #define MODEL_MSCC_OCELOT 0x00000100
> > +#define MODEL_BAIKAL_BT1 0x00000200
> > #define MODEL_MASK 0x00000f00
> >
> > int i2c_dw_init_regmap(struct dw_i2c_dev *dev);
> > diff --git a/drivers/i2c/busses/i2c-designware-platdrv.c b/drivers/i2c/busses/i2c-designware-platdrv.c
> > index 061c8d506c7c..d9c5337bb22b 100644
> > --- a/drivers/i2c/busses/i2c-designware-platdrv.c
> > +++ b/drivers/i2c/busses/i2c-designware-platdrv.c
> > @@ -18,6 +18,7 @@
> > #include <linux/interrupt.h>
> > #include <linux/io.h>
> > #include <linux/kernel.h>
> > +#include <linux/mfd/syscon.h>
> > #include <linux/module.h>
> > #include <linux/of.h>
> > #include <linux/platform_data/i2c-designware.h>
> > @@ -25,6 +26,7 @@
> > #include <linux/pm.h>
> > #include <linux/pm_runtime.h>
> > #include <linux/property.h>
> > +#include <linux/regmap.h>
> > #include <linux/reset.h>
> > #include <linux/sched.h>
> > #include <linux/slab.h>
> > @@ -58,6 +60,63 @@ MODULE_DEVICE_TABLE(acpi, dw_i2c_acpi_match);
> > #endif
> >
> > #ifdef CONFIG_OF
> > +#define BT1_I2C_CTL 0x100
> > +#define BT1_I2C_CTL_ADDR_MASK GENMASK(7, 0)
> > +#define BT1_I2C_CTL_WR BIT(8)
> > +#define BT1_I2C_CTL_GO BIT(31)
> > +#define BT1_I2C_DI 0x104
> > +#define BT1_I2C_DO 0x108
> > +
> > +static int bt1_i2c_read(void *context, unsigned int reg, unsigned int *val)
> > +{
> > + struct dw_i2c_dev *dev = context;
> > + int ret;
> > +
> > + /*
> > + * Note these methods shouldn't ever fail because the system controller
> > + * registers are memory mapped. We check the return value just in case.
> > + */
> > + ret = regmap_write(dev->sysmap, BT1_I2C_CTL,
> > + BT1_I2C_CTL_GO | (reg & BT1_I2C_CTL_ADDR_MASK));
> > + if (ret)
> > + return ret;
> > +
> > + return regmap_read(dev->sysmap, BT1_I2C_DO, val);
> > +}
> > +
> > +static int bt1_i2c_write(void *context, unsigned int reg, unsigned int val)
> > +{
> > + struct dw_i2c_dev *dev = context;
> > + int ret;
> > +
> > + ret = regmap_write(dev->sysmap, BT1_I2C_DI, val);
> > + if (ret)
> > + return ret;
> > +
> > + return regmap_write(dev->sysmap, BT1_I2C_CTL,
> > + BT1_I2C_CTL_GO | BT1_I2C_CTL_WR | (reg & BT1_I2C_CTL_ADDR_MASK));
> > +}
> > +
> > +static struct regmap_config bt1_i2c_cfg = {
> > + .reg_bits = 32,
> > + .val_bits = 32,
> > + .reg_stride = 4,
> > + .fast_io = true,
> > + .reg_read = bt1_i2c_read,
> > + .reg_write = bt1_i2c_write,
> > + .max_register = DW_IC_COMP_TYPE
> > +};
> > +
> > +static int bt1_i2c_request_regs(struct dw_i2c_dev *dev)
> > +{
> > + dev->sysmap = syscon_node_to_regmap(dev->dev->of_node->parent);
> > + if (IS_ERR(dev->sysmap))
> > + return PTR_ERR(dev->sysmap);
> > +
> > + dev->map = devm_regmap_init(dev->dev, NULL, dev, &bt1_i2c_cfg);
> > + return PTR_ERR_OR_ZERO(dev->map);
> > +}
> > +
> > #define MSCC_ICPU_CFG_TWI_DELAY 0x0
> > #define MSCC_ICPU_CFG_TWI_DELAY_ENABLE BIT(0)
> > #define MSCC_ICPU_CFG_TWI_SPIKE_FILTER 0x4
> > @@ -90,10 +149,16 @@ static int dw_i2c_of_configure(struct platform_device *pdev)
> > static const struct of_device_id dw_i2c_of_match[] = {
> > { .compatible = "snps,designware-i2c", },
> > { .compatible = "mscc,ocelot-i2c", .data = (void *)MODEL_MSCC_OCELOT },
> > + { .compatible = "baikal,bt1-sys-i2c", .data = (void *)MODEL_BAIKAL_BT1 },
> > {},
> > };
> > MODULE_DEVICE_TABLE(of, dw_i2c_of_match);
> > #else
> > +static int bt1_i2c_request_regs(struct dw_i2c_dev *dev)
> > +{
> > + return -ENODEV;
> > +}
> > +
> > static inline int dw_i2c_of_configure(struct platform_device *pdev)
> > {
> > return -ENODEV;
> > @@ -111,10 +176,19 @@ static void dw_i2c_plat_pm_cleanup(struct dw_i2c_dev *dev)
> > static int dw_i2c_plat_request_regs(struct dw_i2c_dev *dev)
> > {
> > struct platform_device *pdev = to_platform_device(dev->dev);
> > + int ret;
> >
> > - dev->base = devm_platform_ioremap_resource(pdev, 0);
> > + switch (dev->flags & MODEL_MASK) {
> > + case MODEL_BAIKAL_BT1:
> > + ret = bt1_i2c_request_regs(dev);
> > + break;
> > + default:
> > + dev->base = devm_platform_ioremap_resource(pdev, 0);
> > + ret = PTR_ERR_OR_ZERO(dev->base);
> > + break;
> > + }
> >
> > - return PTR_ERR_OR_ZERO(dev->base);
> > + return ret;
> > }
> >
> > static int dw_i2c_plat_probe(struct platform_device *pdev)
> > --
> > 2.26.2
> >
>
> --
> With Best Regards,
> Andy Shevchenko
>
>
next prev parent reply other threads:[~2020-05-27 15:04 UTC|newest]
Thread overview: 33+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-05-27 12:01 [PATCH v4 00/11] i2c: designeware: Add Baikal-T1 System I2C support Serge Semin
2020-05-27 12:01 ` [PATCH v4 01/11] dt-bindings: i2c: Convert DW I2C binding to DT schema Serge Semin
2020-05-27 12:01 ` [PATCH v4 02/11] dt-bindings: i2c: Discard i2c-slave flag from the DW I2C example Serge Semin
2020-05-27 17:12 ` Rob Herring
2020-05-27 17:18 ` Serge Semin
2020-05-27 17:56 ` Andy Shevchenko
2020-05-28 8:39 ` Serge Semin
2020-05-28 10:00 ` Andy Shevchenko
2020-05-27 12:01 ` [PATCH v4 03/11] dt-bindings: i2c: dw: Add Baikal-T1 SoC I2C controller Serge Semin
2020-05-27 12:01 ` [PATCH v4 04/11] i2c: designware: Use `-y` to build multi-object modules Serge Semin
2020-05-27 12:01 ` [PATCH v4 05/11] i2c: designware: slave: Set DW I2C core module dependency Serge Semin
2020-05-27 12:01 ` [PATCH v4 06/11] i2c: designware: Add Baytrail sem config DW I2C platform dependency Serge Semin
2020-05-27 13:42 ` Andy Shevchenko
2020-05-27 14:24 ` Serge Semin
2020-05-27 15:46 ` Andy Shevchenko
2020-05-27 16:00 ` Serge Semin
2020-05-27 16:43 ` Andy Shevchenko
2020-05-27 12:01 ` [PATCH v4 07/11] i2c: designware: Discard Cherry Trail model flag Serge Semin
2020-05-27 13:43 ` Andy Shevchenko
2020-05-27 14:29 ` Serge Semin
2020-05-27 15:48 ` Andy Shevchenko
2020-05-27 12:01 ` [PATCH v4 08/11] i2c: designware: Convert driver to using regmap API Serge Semin
2020-05-27 13:50 ` Andy Shevchenko
2020-05-27 14:39 ` Serge Semin
2020-05-27 12:01 ` [PATCH v4 09/11] i2c: designware: Retrieve quirk flags as early as possible Serge Semin
2020-05-27 13:51 ` Andy Shevchenko
2020-05-27 12:01 ` [PATCH v4 10/11] i2c: designware: Move reg-space remapping into a dedicated function Serge Semin
2020-05-27 13:58 ` Andy Shevchenko
2020-05-27 14:54 ` Serge Semin
2020-05-27 12:01 ` [PATCH v4 11/11] i2c: designware: Add Baikal-T1 System I2C support Serge Semin
2020-05-27 14:03 ` Andy Shevchenko
2020-05-27 15:04 ` Serge Semin [this message]
2020-05-27 15:52 ` Andy Shevchenko
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=20200527150431.z25aibkn6edplneh@mobilestation \
--to=sergey.semin@baikalelectronics.ru \
--cc=Alexey.Malahov@baikalelectronics.ru \
--cc=andriy.shevchenko@linux.intel.com \
--cc=devicetree@vger.kernel.org \
--cc=fancer.lancer@gmail.com \
--cc=jarkko.nikula@linux.intel.com \
--cc=linux-i2c@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mips@vger.kernel.org \
--cc=mika.westerberg@linux.intel.com \
--cc=robh+dt@kernel.org \
--cc=tsbogend@alpha.franken.de \
--cc=wsa@the-dreams.de \
/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;
as well as URLs for NNTP newsgroup(s).