RE: [PATCH] serial: sh-sci: remove obsolete latency workaround

2021-04-15 Thread Yoshihiro Shimoda
Hi Ulrich-san,

> From: Ulrich Hecht, Sent: Thursday, April 15, 2021 6:36 PM
> 
> Since the transition to hrtimers there is no more need to set a minimum
> RX timeout to work around latency issues.
> 
> Signed-off-by: Ulrich Hecht 

Thank you for the patch!

Reviewed-by: Yoshihiro Shimoda 

Best regards,
Yoshihiro Shimoda



RE: [PATCH v3 02/14] PCI: rcar: Don't allocate extra memory for the MSI capture address

2021-04-01 Thread Yoshihiro Shimoda
Hi Lorenzo, Marc,

> From: Lorenzo Pieralisi, Sent: Wednesday, March 31, 2021 12:29 AM
> 
> On Tue, Mar 30, 2021 at 04:11:33PM +0100, Marc Zyngier wrote:
> > A long cargo-culted behaviour of PCI drivers is to allocate memory
> > to obtain an address that is fed to the controller as the MSI
> > capture address (i.e. the MSI doorbell).
> >
> > But there is no actual requirement for this address to be RAM.
> > All it needs to be is a suitable aligned address that will
> > *not* be DMA'd to.
> >
> > Since the rcar platform already has a requirement that this
> > address should be in the first 4GB of the physical address space,
> > use the controller's own base address as the capture address.
> >
> > Signed-off-by: Marc Zyngier 
> > ---
> >  drivers/pci/controller/pcie-rcar-host.c | 18 +++---
> >  1 file changed, 7 insertions(+), 11 deletions(-)
> 
> Marek, Yoshihiro,
> 
> can you test this patch please and report back ? It is not fundamental
> for the rest of the series (ie the rest of the series does not depend on
> it) and we can still merge the series without it but it would be good if
> you can review and test anyway.

I reviewed and tested this patch and it worked correctly.
So,

Reviewed-by: Yoshihiro Shimoda 
Tested-by: Yoshihiro Shimoda 

Best regards,
Yoshihiro Shimoda



RE: [PATCH] usb: renesas_usbhs: fix error return code of usbhsf_pkt_handler()

2021-03-09 Thread Yoshihiro Shimoda
> From: Jia-Ju Bai, On 2021/3/10 10:54, Yoshihiro Shimoda wrote:
> >> From: Jia-Ju Bai, Sent: Tuesday, March 9, 2021 10:39 PM
> >> On 2021/3/9 19:59, Yoshihiro Shimoda wrote:
> >>>> From: Jia-Ju Bai, Sent: Sunday, March 7, 2021 6:01 PM
> >>>>
> >>>> When __usbhsf_pkt_get() returns NULL to pkt, no error return code of
> >>>> usbhsf_pkt_handler() is assigned.
> >>> Yes. Also I realized that no error return code of usbhsf_pkt_handler()
> >>> was assigned if the type value was unexpected value. So, I'm thinking
> >>> initial value of ret should be -EINVAL instead of 0.
> >> This is okay to me.
> >> Need I write a new patch for this?
> > Thank you for your reply. I can write such a new patch with your
> > Reported-by for this as minor refactoring of the usbhsf_pkt_handler().
> > May I write such a patch?
> 
> Okay, sure :)

I got it :)

Best regards,
Yoshihiro Shimoda



RE: [PATCH] usb: renesas_usbhs: fix error return code of usbhsf_pkt_handler()

2021-03-09 Thread Yoshihiro Shimoda
Hi Jia-Ju,

> From: Jia-Ju Bai, Sent: Tuesday, March 9, 2021 10:39 PM
> On 2021/3/9 19:59, Yoshihiro Shimoda wrote:
> > Hi Jia-Ju,
> >
> > Thank you for the patch!
> >
> >> From: Jia-Ju Bai, Sent: Sunday, March 7, 2021 6:01 PM
> >>
> >> When __usbhsf_pkt_get() returns NULL to pkt, no error return code of
> >> usbhsf_pkt_handler() is assigned.
> > Yes. Also I realized that no error return code of usbhsf_pkt_handler()
> > was assigned if the type value was unexpected value. So, I'm thinking
> > initial value of ret should be -EINVAL instead of 0.
> 
> This is okay to me.
> Need I write a new patch for this?

Thank you for your reply. I can write such a new patch with your
Reported-by for this as minor refactoring of the usbhsf_pkt_handler().
May I write such a patch?

Best regards,
Yoshihiro Shimoda



RE: [PATCH] usb: renesas_usbhs: fix error return code of usbhsf_pkt_handler()

2021-03-09 Thread Yoshihiro Shimoda
Hi Jia-Ju,

Thank you for the patch!

> From: Jia-Ju Bai, Sent: Sunday, March 7, 2021 6:01 PM
> 
> When __usbhsf_pkt_get() returns NULL to pkt, no error return code of
> usbhsf_pkt_handler() is assigned.

Yes. Also I realized that no error return code of usbhsf_pkt_handler()
was assigned if the type value was unexpected value. So, I'm thinking
initial value of ret should be -EINVAL instead of 0.
---
int ret = 0;  // should be -EINVAL
int is_done = 0;

/  spin lock /
usbhs_lock(priv, flags);

pkt = __usbhsf_pkt_get(pipe);
if (!pkt)
goto __usbhs_pkt_handler_end;

switch (type) {
case USBHSF_PKT_PREPARE:
func = pkt->handler->prepare;
break;
case USBHSF_PKT_TRY_RUN:
func = pkt->handler->try_run;
break;
case USBHSF_PKT_DMA_DONE:
func = pkt->handler->dma_done;
break;
default:
dev_err(dev, "unknown pkt handler\n");
goto __usbhs_pkt_handler_end;/// here
}

if (likely(func))  /// [1]
ret = func(pkt, _done);

[1] This is always true here, so ret is always assigned by the func().
---

> To fix this bug, ret is assigned with -EINVAL in this case.

Just a record: After fixed this, actual behavior is almost the same
except printing error message.

Best regards,
Yoshihiro Shimoda



RE: next/master bisection: baseline.login on r8a77960-ulcb

2021-02-26 Thread Yoshihiro Shimoda
Hi all,

> From: Heiko Thiery, Sent: Thursday, February 25, 2021 10:01 PM
> Am Do., 25. Feb. 2021 um 12:50 Uhr schrieb Thierry Reding:
> > On Thu, Feb 25, 2021 at 11:14:57AM +, Robin Murphy wrote:
> > > On 2021-02-25 11:09, Thierry Reding wrote:
> > > > On Wed, Feb 24, 2021 at 10:39:42PM +0100, Heiko Thiery wrote:
> > > > > Hi Christoph and all,
> > > > >
> > > > > On 23.02.21 10:56, Guillaume Tucker wrote:
> > > > > > Hi Christoph,
> > > > > >
> > > > > > Please see the bisection report below about a boot failure on
> > > > > > r8a77960-ulcb on next-20210222.
> > > > > >
> > > > > > Reports aren't automatically sent to the public while we're
> > > > > > trialing new bisection features on kernelci.org but this one
> > > > > > looks valid.
> > > > > >
> > > > > > The log shows a kernel panic, more details can be found here:

> >
> > Yep, changing max_slots from unsigned int to unsigned long fixes this as
> > well. Thanks for the pointer!
> 
> I also can confirm that changing that to unsigned long fixes the issue.

Thank you for the information! I also confirmed that changing the type of
max_slots fixed the issue on my environment (r8a77951-salvator-xs.dts with 
defconfig).

Best regards,
Yoshihiro Shimoda



RE: linux-next: manual merge of the net-next tree with the arm-soc tree

2021-02-16 Thread Yoshihiro Shimoda
Hi Stephen,

> From: Stephen Rothwell, Sent: Wednesday, February 17, 2021 6:18 AM
> On Tue, 16 Feb 2021 11:53:56 + Yoshihiro Shimoda 
>  wrote:
> >
> > > From: Stephen Rothwell, Sent: Tuesday, February 16, 2021 11:05 AM
> > 
> > > diff --cc arch/arm64/boot/dts/toshiba/tmpv7708-rm-mbrc.dts
> > > index 2407b2d89c1e,48fa8776e36f..
> > > --- a/arch/arm64/boot/dts/toshiba/tmpv7708-rm-mbrc.dts
> > > +++ b/arch/arm64/boot/dts/toshiba/tmpv7708-rm-mbrc.dts
> > > @@@ -42,11 -42,20 +42,29 @@@
> > >   clock-names = "apb_pclk";
> > >   };
> > >
> > >  + {
> > >  +status = "okay";
> > >  +clocks = <_clk>;
> > >  +};
> > >  +
> > >  + {
> > >  +status = "okay";
> > > ++};`
> >
> > This ` causes the following build error on the next-20210216.
> >
> >   DTC arch/arm64/boot/dts/toshiba/tmpv7708-rm-mbrc.dtb
> > Error: arch/arm64/boot/dts/toshiba/tmpv7708-rm-mbrc.dts:52.3-4 syntax error
> > FATAL ERROR: Unable to parse input tree
> > scripts/Makefile.lib:336: recipe for target 
> > 'arch/arm64/boot/dts/toshiba/tmpv7708-rm-mbrc.dtb' failed
> > make[2]: *** [arch/arm64/boot/dts/toshiba/tmpv7708-rm-mbrc.dtb] Error 1
> > scripts/Makefile.build:530: recipe for target 'arch/arm64/boot/dts/toshiba' 
> > failed
> 
> Sorry about that ( ` is nect to ESC on my keyboard) it will be fixed up
> in today's resolution.

Thank you for the reply! I understood it.

Best regards,
Yoshihiro Shimoda



RE: linux-next: manual merge of the net-next tree with the arm-soc tree

2021-02-16 Thread Yoshihiro Shimoda
Hi,

> From: Stephen Rothwell, Sent: Tuesday, February 16, 2021 11:05 AM

> diff --cc arch/arm64/boot/dts/toshiba/tmpv7708-rm-mbrc.dts
> index 2407b2d89c1e,48fa8776e36f..
> --- a/arch/arm64/boot/dts/toshiba/tmpv7708-rm-mbrc.dts
> +++ b/arch/arm64/boot/dts/toshiba/tmpv7708-rm-mbrc.dts
> @@@ -42,11 -42,20 +42,29 @@@
>   clock-names = "apb_pclk";
>   };
> 
>  + {
>  +status = "okay";
>  +clocks = <_clk>;
>  +};
>  +
>  + {
>  +status = "okay";
> ++};`

This ` causes the following build error on the next-20210216.

  DTC arch/arm64/boot/dts/toshiba/tmpv7708-rm-mbrc.dtb
Error: arch/arm64/boot/dts/toshiba/tmpv7708-rm-mbrc.dts:52.3-4 syntax error
FATAL ERROR: Unable to parse input tree
scripts/Makefile.lib:336: recipe for target 
'arch/arm64/boot/dts/toshiba/tmpv7708-rm-mbrc.dtb' failed
make[2]: *** [arch/arm64/boot/dts/toshiba/tmpv7708-rm-mbrc.dtb] Error 1
scripts/Makefile.build:530: recipe for target 'arch/arm64/boot/dts/toshiba' 
failed

Best regards,
Yoshihiro Shimoda



RE: [PATCH 2/3] dt-bindings: iommu: renesas,ipmmu-vmsa: Make 'power-domains' conditionally required

2021-02-03 Thread Yoshihiro Shimoda
Hi Rob,

> From: Rob Herring, Sent: Wednesday, February 3, 2021 5:56 AM
> 
> Fixing the compatible string typos results in an error in the example:
> 
> Documentation/devicetree/bindings/iommu/renesas,ipmmu-vmsa.example.dt.yaml:
>   iommu@fe951000: 'power-domains' is a required property
> 
> Based on the dts files, a 'power-domains' property only exists on Gen 3
> which can be conditioned on !renesas,ipmmu-vmsa.
> 
> Cc: Joerg Roedel 
> Cc: Will Deacon 
> Cc: Yoshihiro Shimoda 
> Cc: io...@lists.linux-foundation.org
> Signed-off-by: Rob Herring 

Thank you for the patch!

Reviewed-by: Yoshihiro Shimoda 

Best regards,
Yoshihiro Shimoda



RE: [PATCH 1/3] dt-bindings: Fix undocumented compatible strings in examples

2021-02-03 Thread Yoshihiro Shimoda
Hi Rob,

> From: Rob Herring, Sent: Wednesday, February 3, 2021 5:56 AM
> 
> Running 'dt-validate -m' will flag any compatible strings missing a schema.
> Fix all the errors found in DT binding examples. Most of these are just
> typos.
> 
> Cc: Stephen Boyd 
> Cc: Maxime Ripard 
> Cc: Chen-Yu Tsai 
> Cc: Linus Walleij 
> Cc: Herbert Xu 
> Cc: "David S. Miller" 
> Cc: Daniel Palmer 
> Cc: Bartosz Golaszewski 
> Cc: Avi Fishman 
> Cc: Tomer Maimon 
> Cc: Tali Perry 
> Cc: Joerg Roedel 
> Cc: Will Deacon 
> Cc: Andrew Jeffery 
> Cc: Joel Stanley 
> Cc: Wim Van Sebroeck 
> Cc: Guenter Roeck 
> Cc: Yoshihiro Shimoda 
> Cc: Vincent Cheng 
> Cc: linux-...@vger.kernel.org
> Cc: linux-cry...@vger.kernel.org
> Cc: linux-g...@vger.kernel.org
> Cc: linux-...@vger.kernel.org
> Cc: io...@lists.linux-foundation.org
> Cc: linux-watch...@vger.kernel.org
> Signed-off-by: Rob Herring 

> diff --git a/Documentation/devicetree/bindings/iommu/renesas,ipmmu-vmsa.yaml
> b/Documentation/devicetree/bindings/iommu/renesas,ipmmu-vmsa.yaml
> index cde1afa8dfd6..349633108bbd 100644
> --- a/Documentation/devicetree/bindings/iommu/renesas,ipmmu-vmsa.yaml
> +++ b/Documentation/devicetree/bindings/iommu/renesas,ipmmu-vmsa.yaml
> @@ -93,7 +93,7 @@ examples:
>  #include 
> 
>  ipmmu_mx: iommu@fe951000 {
> -compatible = "renasas,ipmmu-r8a7791", "renasas,ipmmu-vmsa";
> +    compatible = "renesas,ipmmu-r8a7791", "renesas,ipmmu-vmsa";

Oops. Thank you for fixing this.

Reviewed-by: Yoshihiro Shimoda 

Best regards,
Yoshihiro Shimoda



RE: [PATCH v2] usb: host: xhci: mvebu: make USB 3.0 PHY optional for Armada 3720

2021-02-01 Thread Yoshihiro Shimoda
Hi Pali,

> From: Pali Rohár, Sent: Tuesday, February 2, 2021 12:08 AM
> 
> Older ATF does not provide SMC call for USB 3.0 phy power on functionality
> and therefore initialization of xhci-hcd is failing when older version of
> ATF is used. In this case phy_power_on() function returns -EOPNOTSUPP.
> 
> [3.108467] mvebu-a3700-comphy d0018300.phy: unsupported SMC call, try 
> updating your firmware
> [3.117250] phy phy-d0018300.phy.0: phy poweron failed --> -95
> [3.123465] xhci-hcd: probe of d0058000.usb failed with error -95
> 
> This patch introduces a new plat_setup callback for xhci platform drivers
> which is called prior calling usb_add_hcd() function. This function at its
> beginning skips PHY init if hcd->skip_phy_initialization is set.
> 
> Current init_quirk callback for xhci platform drivers is called from
> xhci_plat_setup() function which is called after chip reset completes.
> It happens in the middle of the usb_add_hcd() function and therefore this
> callback cannot be used for setting if PHY init should be skipped or not.
> 
> For Armada 3720 this patch introduce a new xhci_mvebu_a3700_plat_setup()
> function configured as a xhci platform plat_setup callback. This new
> function calls phy_power_on() and in case it returns -EOPNOTSUPP then
> XHCI_SKIP_PHY_INIT quirk is set to instruct xhci-plat to skip PHY
> initialization.
> 
> This patch fixes above failure by ignoring 'not supported' error in
> xhci-hcd driver. In this case it is expected that phy is already power on.
> 
> It fixes initialization of xhci-hcd on Espressobin boards where is older
> Marvell's Arm Trusted Firmware without SMC call for USB 3.0 phy power.
> 
> This is regression introduced in commit bd3d25b07342 ("arm64: dts: marvell:
> armada-37xx: link USB hosts with their PHYs") where USB 3.0 phy was defined
> and therefore xhci-hcd on Espressobin with older ATF started failing.
> 
> Signed-off-by: Pali Rohár 
> Tested-by: Tomasz Maciej Nowak 
> Fixes: bd3d25b07342 ("arm64: dts: marvell: armada-37xx: link USB hosts with 
> their PHYs")
> Cc:  # 5.1+: ea17a0f153af: phy: marvell: comphy: 
> Convert internal SMCC firmware return codes to
> errno
> Cc:  # 5.1+: f768e718911e: usb: host: xhci-plat: add 
> priv quirk for skip PHY initialization

Thank you for the patch!

Reviewed-by: Yoshihiro Shimoda  # xhci-plat

Also, I tested on my environment and didn't cause any regression.
So,

Tested-by: Yoshihiro Shimoda  # On R-Car

Best regards,
Yoshihiro Shimoda



RE: [PATCH v2] usb: host: xhci-plat: fix support for XHCI_SKIP_PHY_INIT quirk

2021-02-01 Thread Yoshihiro Shimoda
> From: Pali Rohár, Sent: Tuesday, February 2, 2021 12:12 AM
> On Tuesday 26 January 2021 10:06:06 Pali Rohár wrote:
> > On Tuesday 26 January 2021 04:27:37 Yoshihiro Shimoda wrote:
> > > Hi Pali,
> > > > > I can see the benefit in this.
> > > > > In the xhci-plat case usb_create_hcd and usb_add_hcd are separate 
> > > > > steps, and
> > > > > we could both copy the xhci_plat_priv .quirks and run the .init_qurks 
> > > > > before
> > > > > adding the hcd.
> > > > > I guess the current way is inherited from pci case where the earliest 
> > > > > place
> > > > > to do this after hcd is created is the hcd->driver->reset callback 
> > > > > (which is
> > > > > set to xhci_pci_setup() or xhci_plat_setup()).
> > > > >
> > > > > xhci-rcar.c is using the .init_quirk to load firmware, we need to 
> > > > > check with
> > > > > them if this change is ok. (added Yoshihiro Shimoda to cc)
> > > >
> > > > Yoshihiro, is this change OK?
> > > >
> > > > Can we move forward? I really need to now how to handle regression in
> > > > xhci-mvebu driver. And one option is with this patch...
> > >
> > > Thank you for asking me about this topic. I tested the patch, but 
> > > unfortunately,
> > > this patch is possible to break a rcar platform because a phy 
> > > initialization is
> > > needed before the firmware loading if the platform uses the phy. (Note 
> > > that
> > > upstream code (salvator-common.dtsi) doesn't use the phy for xhci. But,
> > > if we use the phy on other board with this patch, the xhci will not work.)
> > >
> > > So, I think we need to add a new function pointer for your case.
> >
> > Ok, thank you for testing! I will try to come up with other solution to
> > mentioned mvebu-xhci issue.
> 
> Hello! New version of this patch is in following thread, please review it:
> "[PATCH v2] usb: host: xhci: mvebu: make USB 3.0 PHY optional for Armada 3720"

Thanks! I'll review it.

Best regards,
Yoshihiro Shimoda



RE: [PATCH v2] usb: host: xhci-plat: fix support for XHCI_SKIP_PHY_INIT quirk

2021-01-26 Thread Yoshihiro Shimoda
Hi Pali,

> From: Pali Rohár, Sent: Monday, January 25, 2021 11:20 PM
> On Friday 15 January 2021 15:32:30 Mathias Nyman wrote:
> > On 14.1.2021 1.20, Pali Rohár wrote:
> > > On Thursday 24 December 2020 05:59:05 Peter Chen wrote:
> > >> On 20-12-23 17:18:47, Pali Rohár wrote:
> > >>> Currently init_quirk callbacks for xhci platform drivers are called
> > >>> xhci_plat_setup() function which is called after chip reset completes.
> > >>> It happens in the middle of the usb_add_hcd() function.
> > >>>
> > >>> But XHCI_SKIP_PHY_INIT quirk is checked in the xhci_plat_probe() 
> > >>> function
> > >>> prior calling usb_add_hcd() function. Therefore this XHCI_SKIP_PHY_INIT
> > >>> currently does nothing as prior xhci_plat_setup() it is not set.
> > >>>
> > >>> Quirk XHCI_SKIP_PHY_INIT is only setting hcd->skip_phy_initialization 
> > >>> value
> > >>> which really needs to be set prior calling usb_add_hcd() as this 
> > >>> function
> > >>> at its beginning skips PHY init if this member is set.
> > >>>
> > >>> This patch fixes implementation of the XHCI_SKIP_PHY_INIT quirk by 
> > >>> calling
> > >>> init_quirk callbacks (via xhci_priv_init_quirk()) prior checking if
> > >>> XHCI_SKIP_PHY_INIT is set. Also checking if either xhci->quirks or
> > >>> priv->quirks contains this XHCI_SKIP_PHY_INIT quirk.
> > >>>
> > >>> Signed-off-by: Pali Rohár 
> > >>>
> > >>> ---
> > >>> Changes in v2:
> > >>> * Check also xhci->quirks as xhci_priv_init_quirk() callbacks are 
> > >>> setting xhci->quirks
> > >>> * Tested with "usb: host: xhci: mvebu: make USB 3.0 PHY optional for 
> > >>> Armada 3720" patch
> > >>> * Removed Fixes: line
> > >>> ---
> > >>>  drivers/usb/host/xhci-plat.c | 16 
> > >>>  1 file changed, 8 insertions(+), 8 deletions(-)
> > >>>
> > >>> diff --git a/drivers/usb/host/xhci-plat.c b/drivers/usb/host/xhci-plat.c
> > >>> index 4d34f6005381..0eab7cb5a767 100644
> > >>> --- a/drivers/usb/host/xhci-plat.c
> > >>> +++ b/drivers/usb/host/xhci-plat.c
> > >>> @@ -89,13 +89,6 @@ static void xhci_plat_quirks(struct device *dev, 
> > >>> struct xhci_hcd *xhci)
> > >>>  /* called during probe() after chip reset completes */
> > >>>  static int xhci_plat_setup(struct usb_hcd *hcd)
> > >>>  {
> > >>> -   int ret;
> > >>> -
> > >>> -
> > >>> -   ret = xhci_priv_init_quirk(hcd);
> > >>> -   if (ret)
> > >>> -   return ret;
> > >>> -
> > >>> return xhci_gen_setup(hcd, xhci_plat_quirks);
> > >>>  }
> > >>>
> > >>> @@ -330,7 +323,14 @@ static int xhci_plat_probe(struct platform_device 
> > >>> *pdev)
> > >>>
> > >>> hcd->tpl_support = of_usb_host_tpl_support(sysdev->of_node);
> > >>> xhci->shared_hcd->tpl_support = hcd->tpl_support;
> > >>> -   if (priv && (priv->quirks & XHCI_SKIP_PHY_INIT))
> > >>> +
> > >>> +   if (priv) {
> > >>> +   ret = xhci_priv_init_quirk(hcd);
> > >>> +   if (ret)
> > >>> +   goto disable_usb_phy;
> > >>> +   }
> > >>> +
> > >>> +   if ((xhci->quirks & XHCI_SKIP_PHY_INIT) || (priv && 
> > >>> (priv->quirks & XHCI_SKIP_PHY_INIT)))
> > >>> hcd->skip_phy_initialization = 1;
> > >>
> > >> I am not sure if others agree with you move the position of
> > >> xhci_priv_init_quirk, Let's see Mathias opinion.
> > >
> > > Hello! Do you have an opinion how to handle this issue? As currently it
> > > is needed for another patch which is fixing issue/regression in 
> > > xhci-mvebu:
> > >

> > >
> >
> > I can see the benefit in this.
> > In the xhci-plat case usb_create_hcd and usb_add_hcd are separate steps, and
> > we could both copy the xhci_plat_priv .quirks and run the .init_qurks before
> > adding the hcd.
> > I guess the current way is inherited from pci case where the earliest place
> > to do this after hcd is created is the hcd->driver->reset callback (which is
> > set to xhci_pci_setup() or xhci_plat_setup()).
> >
> > xhci-rcar.c is using the .init_quirk to load firmware, we need to check with
> > them if this change is ok. (added Yoshihiro Shimoda to cc)
> 
> Yoshihiro, is this change OK?
> 
> Can we move forward? I really need to now how to handle regression in
> xhci-mvebu driver. And one option is with this patch...

Thank you for asking me about this topic. I tested the patch, but unfortunately,
this patch is possible to break a rcar platform because a phy initialization is
needed before the firmware loading if the platform uses the phy. (Note that
upstream code (salvator-common.dtsi) doesn't use the phy for xhci. But,
if we use the phy on other board with this patch, the xhci will not work.)

So, I think we need to add a new function pointer for your case.

Best regards,
Yoshihiro Shimoda

> > Their firmware would be loaded before phy parts are initialized, usb bus
> > registered, or roothub device allocated.
> >
> > Thanks
> > -Mathias


[PATCH v9 03/12] mfd: rohm-generic: Add BD9571 and BD9574

2021-01-12 Thread Yoshihiro Shimoda
Add chip IDs for BD9571MWV and BD9574MWF.

Signed-off-by: Yoshihiro Shimoda 
Reviewed-by: Matti Vaittinen 
Acked-for-MFD-by: Lee Jones 
---
 include/linux/mfd/rohm-generic.h | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/include/linux/mfd/rohm-generic.h b/include/linux/mfd/rohm-generic.h
index 4283b5b..affacf8 100644
--- a/include/linux/mfd/rohm-generic.h
+++ b/include/linux/mfd/rohm-generic.h
@@ -12,6 +12,8 @@ enum rohm_chip_type {
ROHM_CHIP_TYPE_BD71847,
ROHM_CHIP_TYPE_BD70528,
ROHM_CHIP_TYPE_BD71828,
+   ROHM_CHIP_TYPE_BD9571,
+   ROHM_CHIP_TYPE_BD9574,
ROHM_CHIP_TYPE_AMOUNT
 };
 
-- 
2.7.4



[PATCH v9 00/12] treewide: bd9571mwv: Add support for BD9574MWF

2021-01-12 Thread Yoshihiro Shimoda
Add BD9574MWF support into bd9571mwv gpio, mfd and regulator drivers.
Latest Ebisu-4D boards has this chip instead of BD9571MWV so that
we need this patch series to detect this chip at runtime.

Note that the patch [1/12] is a bug-fix patch for mfd driver.

Hello Lee,

Now I got Acked-by from maintainers of gpio and regulator. So,
would you apply this series to your repo?

Changes from v8:
 - Add Acked-by from maintainers of regulator and gpio in patch 4 to 8.
 https://patchwork.kernel.org/project/linux-renesas-soc/list/?series=406323

Changes from v7:
 - Fix typo in the patch 10.
 - Add "Acked-for-MFD-by" in patch 2 and 11.
 https://patchwork.kernel.org/project/linux-renesas-soc/list/?series=406091

Changes from v6:
 - Remove "struct bd957x_ddata" because this is not used after probed.
 - Add "Acked-for-MFD-by" in patch 12.
 https://patchwork.kernel.org/project/linux-renesas-soc/list/?series=405725

Changes from v5:
 - Fix typo in the patch 5 and 8.
 https://patchwork.kernel.org/project/linux-renesas-soc/list/?series=405263

Changes from v4:
 - Add Reviwed-by in patch 1, 10, 11 and 12.
 - Keep bd9571mwv_id_table[] as-is because unused in patch 12.
 https://patchwork.kernel.org/project/linux-renesas-soc/list/?series=404657

Changes from v3:
 - Add "Acked-for-MFD-by" in patch 1, 3, 9 and 10.
 - Use "Co-developed-by" instead in patch 11.
 - In patch 11:
 -- Remove abusing kernel-doc formatting in patch.
 -- Rename bd957x_data with bd957x_ddata in patch.
 -- Remove product name printk.
 -- Rename bd9571mwv_identify() with bd957x_identify().
 -- Remove argument "part_name" from bd957x_identify().
 -- Modify dev_err() string.
 -- Rename BD9571MWV_PRODUCT_CODE_VAL with BD9571MWV_PRODUCT_CODE_BD9571MWV.
 -- Fix errno from -ENOENT to -ENODEV.
 - In patch 12:
 -- Rename "MFD driver" to "core driver".
 -- Remove unnecessary comments.
 -- Rename BD9574MWF_PRODUCT_CODE_VAL with BD9571MWV_PRODUCT_CODE_BD9574MWF.
 https://patchwork.kernel.org/project/linux-renesas-soc/list/?series=402719

Changes from v2:
 - Use devm_mfd_add_devices() to remove the mfd device in unload.
 - Update commit descriptions in patch 4 and 8.
 - Use regmap_get_device() to simplify in patch 4.
 - Remove "struct bd9571mwv" and bd9571mwv_remove().
 - Add Reviewed-by in patch 3 to 9.
 - Use devm_regmap_add_irq_chip() to simplify in patch 10.
 https://patchwork.kernel.org/project/linux-renesas-soc/list/?series=400477

Changes from v1:
 - Document BD9574MWF on the dt-binding.
 - Add ROHM_CHIP_TYPE_BD957[14] into rohm-generic.h.
 - To simplify gpio and regulator drivers, using regmap instead of
   using struct bd9571mwv.
 - Remove BD9574MWF definitions to make gpio and regulator driver
   simple to support for BD9574MWF.
 - Add BD9574MWF support for gpio and regulator drivers.
 - Add missing regmap ranges for BD9574MWF.
 - Rename "part_number" with "part_name".
 https://patchwork.kernel.org/project/linux-renesas-soc/list/?series=398059


Khiem Nguyen (2):
  mfd: bd9571mwv: Make the driver more generic
  mfd: bd9571mwv: Add support for BD9574MWF

Yoshihiro Shimoda (10):
  mfd: bd9571mwv: Use devm_mfd_add_devices()
  dt-bindings: mfd: bd9571mwv: Document BD9574MWF
  mfd: rohm-generic: Add BD9571 and BD9574
  regulator: bd9571mwv: rid of using struct bd9571mwv
  regulator: bd9571mwv: Add BD9574MWF support
  gpio: bd9571mwv: Use the SPDX license identifier
  gpio: bd9571mwv: rid of using struct bd9571mwv
  gpio: bd9571mwv: Add BD9574MWF support
  mfd: bd9571mwv: Use the SPDX license identifier
  mfd: bd9571mwv: Use devm_regmap_add_irq_chip()

 .../devicetree/bindings/mfd/bd9571mwv.txt  |   4 +-
 drivers/gpio/gpio-bd9571mwv.c  |  35 ++--
 drivers/mfd/bd9571mwv.c| 178 ++---
 drivers/regulator/bd9571mwv-regulator.c|  59 ---
 include/linux/mfd/bd9571mwv.h  |  45 ++
 include/linux/mfd/rohm-generic.h   |   2 +
 6 files changed, 186 insertions(+), 137 deletions(-)

-- 
2.7.4



[PATCH v9 01/12] mfd: bd9571mwv: Use devm_mfd_add_devices()

2021-01-12 Thread Yoshihiro Shimoda
To remove mfd devices when unload this driver, should use
devm_mfd_add_devices() instead.

Fixes: d3ea21272094 ("mfd: Add ROHM BD9571MWV-M MFD PMIC driver")
Signed-off-by: Yoshihiro Shimoda 
Acked-for-MFD-by: Lee Jones 
Reviewed-by: Geert Uytterhoeven 
Reviewed-by: Matti Vaittinen 
---
 drivers/mfd/bd9571mwv.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/mfd/bd9571mwv.c b/drivers/mfd/bd9571mwv.c
index fab3cdc..19d57a4 100644
--- a/drivers/mfd/bd9571mwv.c
+++ b/drivers/mfd/bd9571mwv.c
@@ -185,9 +185,9 @@ static int bd9571mwv_probe(struct i2c_client *client,
return ret;
}
 
-   ret = mfd_add_devices(bd->dev, PLATFORM_DEVID_AUTO, bd9571mwv_cells,
- ARRAY_SIZE(bd9571mwv_cells), NULL, 0,
- regmap_irq_get_domain(bd->irq_data));
+   ret = devm_mfd_add_devices(bd->dev, PLATFORM_DEVID_AUTO,
+  bd9571mwv_cells, ARRAY_SIZE(bd9571mwv_cells),
+  NULL, 0, 
regmap_irq_get_domain(bd->irq_data));
if (ret) {
regmap_del_irq_chip(bd->irq, bd->irq_data);
return ret;
-- 
2.7.4



[PATCH v9 05/12] regulator: bd9571mwv: Add BD9574MWF support

2021-01-12 Thread Yoshihiro Shimoda
Add support for BD9574MWF which is similar chip with BD9571MWV.
Note that we don't support voltage rails VD{09,18,25,33} by this
driver on BD9574. The VD09 voltage could be read from PMIC but that
is not supported by this commit.

Signed-off-by: Yoshihiro Shimoda 
Reviewed-by: Matti Vaittinen 
Acked-by: Mark Brown 
---
 drivers/regulator/bd9571mwv-regulator.c | 10 --
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/drivers/regulator/bd9571mwv-regulator.c 
b/drivers/regulator/bd9571mwv-regulator.c
index 42b6a70..7b0cd08 100644
--- a/drivers/regulator/bd9571mwv-regulator.c
+++ b/drivers/regulator/bd9571mwv-regulator.c
@@ -1,6 +1,6 @@
 // SPDX-License-Identifier: GPL-2.0
 /*
- * ROHM BD9571MWV-M regulator driver
+ * ROHM BD9571MWV-M and BD9574MWF-M regulator driver
  *
  * Copyright (C) 2017 Marek Vasut 
  *
@@ -9,6 +9,7 @@
  * NOTE: VD09 is missing
  */
 
+#include 
 #include 
 #include 
 #include 
@@ -277,6 +278,7 @@ static int bd9571mwv_regulator_probe(struct platform_device 
*pdev)
struct regulator_dev *rdev;
unsigned int val;
int i;
+   enum rohm_chip_type chip = platform_get_device_id(pdev)->driver_data;
 
bdreg = devm_kzalloc(>dev, sizeof(*bdreg), GFP_KERNEL);
if (!bdreg)
@@ -292,6 +294,9 @@ static int bd9571mwv_regulator_probe(struct platform_device 
*pdev)
config.regmap = bdreg->regmap;
 
for (i = 0; i < ARRAY_SIZE(regulators); i++) {
+   /* BD9574MWF supports DVFS only */
+   if (chip == ROHM_CHIP_TYPE_BD9574 && regulators[i].id != DVFS)
+   continue;
rdev = devm_regulator_register(>dev, [i],
   );
if (IS_ERR(rdev)) {
@@ -339,7 +344,8 @@ static int bd9571mwv_regulator_probe(struct platform_device 
*pdev)
 }
 
 static const struct platform_device_id bd9571mwv_regulator_id_table[] = {
-   { "bd9571mwv-regulator", },
+   { "bd9571mwv-regulator", ROHM_CHIP_TYPE_BD9571 },
+   { "bd9574mwf-regulator", ROHM_CHIP_TYPE_BD9574 },
{ /* sentinel */ }
 };
 MODULE_DEVICE_TABLE(platform, bd9571mwv_regulator_id_table);
-- 
2.7.4



[PATCH v9 06/12] gpio: bd9571mwv: Use the SPDX license identifier

2021-01-12 Thread Yoshihiro Shimoda
Use the SPDX license identifier instead of a local description.

Signed-off-by: Yoshihiro Shimoda 
Reviewed-by: Geert Uytterhoeven 
Reviewed-by: Linus Walleij 
Acked-by: Bartosz Golaszewski 
---
 drivers/gpio/gpio-bd9571mwv.c | 10 +-
 1 file changed, 1 insertion(+), 9 deletions(-)

diff --git a/drivers/gpio/gpio-bd9571mwv.c b/drivers/gpio/gpio-bd9571mwv.c
index c0abc9c..abb622c 100644
--- a/drivers/gpio/gpio-bd9571mwv.c
+++ b/drivers/gpio/gpio-bd9571mwv.c
@@ -1,17 +1,9 @@
+// SPDX-License-Identifier: GPL-2.0-only
 /*
  * ROHM BD9571MWV-M GPIO driver
  *
  * Copyright (C) 2017 Marek Vasut 
  *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License version 2 as
- * published by the Free Software Foundation.
- *
- * This program is distributed "as is" WITHOUT ANY WARRANTY of any
- * kind, whether expressed or implied; without even the implied warranty
- * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License version 2 for more details.
- *
  * Based on the TPS65086 driver
  *
  * NOTE: Interrupts are not supported yet.
-- 
2.7.4



[PATCH v9 09/12] mfd: bd9571mwv: Use the SPDX license identifier

2021-01-12 Thread Yoshihiro Shimoda
Use the SPDX license identifier instead of a local description.

Signed-off-by: Yoshihiro Shimoda 
Reviewed-by: Geert Uytterhoeven 
Acked-for-MFD-by: Lee Jones 
---
 drivers/mfd/bd9571mwv.c   | 10 +-
 include/linux/mfd/bd9571mwv.h | 10 +-
 2 files changed, 2 insertions(+), 18 deletions(-)

diff --git a/drivers/mfd/bd9571mwv.c b/drivers/mfd/bd9571mwv.c
index 19d57a4..e68c3fa 100644
--- a/drivers/mfd/bd9571mwv.c
+++ b/drivers/mfd/bd9571mwv.c
@@ -1,17 +1,9 @@
+// SPDX-License-Identifier: GPL-2.0-only
 /*
  * ROHM BD9571MWV-M MFD driver
  *
  * Copyright (C) 2017 Marek Vasut 
  *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License version 2 as
- * published by the Free Software Foundation.
- *
- * This program is distributed "as is" WITHOUT ANY WARRANTY of any
- * kind, whether expressed or implied; without even the implied warranty
- * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License version 2 for more details.
- *
  * Based on the TPS65086 driver
  */
 
diff --git a/include/linux/mfd/bd9571mwv.h b/include/linux/mfd/bd9571mwv.h
index eb05569..bcc7092 100644
--- a/include/linux/mfd/bd9571mwv.h
+++ b/include/linux/mfd/bd9571mwv.h
@@ -1,17 +1,9 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
 /*
  * ROHM BD9571MWV-M driver
  *
  * Copyright (C) 2017 Marek Vasut 
  *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License version 2 as
- * published by the Free Software Foundation.
- *
- * This program is distributed "as is" WITHOUT ANY WARRANTY of any
- * kind, whether expressed or implied; without even the implied warranty
- * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License version 2 for more details.
- *
  * Based on the TPS65086 driver
  */
 
-- 
2.7.4



[PATCH v9 10/12] mfd: bd9571mwv: Use devm_regmap_add_irq_chip()

2021-01-12 Thread Yoshihiro Shimoda
Use devm_regmap_add_irq_chip() to simplify the code.

Signed-off-by: Yoshihiro Shimoda 
Acked-for-MFD-by: Lee Jones 
Reviewed-by: Matti Vaittinen 
Reviewed-by: Geert Uytterhoeven 
---
 drivers/mfd/bd9571mwv.c | 27 ++-
 1 file changed, 6 insertions(+), 21 deletions(-)

diff --git a/drivers/mfd/bd9571mwv.c b/drivers/mfd/bd9571mwv.c
index e68c3fa..49e968e 100644
--- a/drivers/mfd/bd9571mwv.c
+++ b/drivers/mfd/bd9571mwv.c
@@ -170,31 +170,17 @@ static int bd9571mwv_probe(struct i2c_client *client,
if (ret)
return ret;
 
-   ret = regmap_add_irq_chip(bd->regmap, bd->irq, IRQF_ONESHOT, 0,
- _irq_chip, >irq_data);
+   ret = devm_regmap_add_irq_chip(bd->dev, bd->regmap, bd->irq,
+  IRQF_ONESHOT, 0, _irq_chip,
+  >irq_data);
if (ret) {
dev_err(bd->dev, "Failed to register IRQ chip\n");
return ret;
}
 
-   ret = devm_mfd_add_devices(bd->dev, PLATFORM_DEVID_AUTO,
-  bd9571mwv_cells, ARRAY_SIZE(bd9571mwv_cells),
-  NULL, 0, 
regmap_irq_get_domain(bd->irq_data));
-   if (ret) {
-   regmap_del_irq_chip(bd->irq, bd->irq_data);
-   return ret;
-   }
-
-   return 0;
-}
-
-static int bd9571mwv_remove(struct i2c_client *client)
-{
-   struct bd9571mwv *bd = i2c_get_clientdata(client);
-
-   regmap_del_irq_chip(bd->irq, bd->irq_data);
-
-   return 0;
+   return devm_mfd_add_devices(bd->dev, PLATFORM_DEVID_AUTO,
+   bd9571mwv_cells, 
ARRAY_SIZE(bd9571mwv_cells),
+   NULL, 0, 
regmap_irq_get_domain(bd->irq_data));
 }
 
 static const struct of_device_id bd9571mwv_of_match_table[] = {
@@ -215,7 +201,6 @@ static struct i2c_driver bd9571mwv_driver = {
.of_match_table = bd9571mwv_of_match_table,
},
.probe  = bd9571mwv_probe,
-   .remove = bd9571mwv_remove,
.id_table   = bd9571mwv_id_table,
 };
 module_i2c_driver(bd9571mwv_driver);
-- 
2.7.4



[PATCH v9 12/12] mfd: bd9571mwv: Add support for BD9574MWF

2021-01-12 Thread Yoshihiro Shimoda
From: Khiem Nguyen 

The new PMIC BD9574MWF inherits features from BD9571MWV.
Add the support of new PMIC to existing bd9571mwv driver.

Signed-off-by: Khiem Nguyen 
Co-developed-by: Yoshihiro Shimoda 
Signed-off-by: Yoshihiro Shimoda 
Reviewed-by: Matti Vaittinen 
Acked-for-MFD-by: Lee Jones 
---
 drivers/mfd/bd9571mwv.c   | 76 ++-
 include/linux/mfd/bd9571mwv.h | 17 --
 2 files changed, 89 insertions(+), 4 deletions(-)

diff --git a/drivers/mfd/bd9571mwv.c b/drivers/mfd/bd9571mwv.c
index 2c1fcbb..e15b1ac 100644
--- a/drivers/mfd/bd9571mwv.c
+++ b/drivers/mfd/bd9571mwv.c
@@ -1,6 +1,6 @@
 // SPDX-License-Identifier: GPL-2.0-only
 /*
- * ROHM BD9571MWV-M MFD driver
+ * ROHM BD9571MWV-M and BD9574MVF-M core driver
  *
  * Copyright (C) 2017 Marek Vasut 
  * Copyright (C) 2020 Renesas Electronics Corporation
@@ -11,6 +11,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 
 #include 
@@ -103,6 +104,72 @@ static struct regmap_irq_chip bd9571mwv_irq_chip = {
.num_irqs   = ARRAY_SIZE(bd9571mwv_irqs),
 };
 
+static const struct mfd_cell bd9574mwf_cells[] = {
+   { .name = "bd9574mwf-regulator", },
+   { .name = "bd9574mwf-gpio", },
+};
+
+static const struct regmap_range bd9574mwf_readable_yes_ranges[] = {
+   regmap_reg_range(BD9571MWV_VENDOR_CODE, BD9571MWV_PRODUCT_REVISION),
+   regmap_reg_range(BD9571MWV_BKUP_MODE_CNT, BD9571MWV_BKUP_MODE_CNT),
+   regmap_reg_range(BD9571MWV_DVFS_VINIT, BD9571MWV_DVFS_SETVMAX),
+   regmap_reg_range(BD9571MWV_DVFS_SETVID, BD9571MWV_DVFS_MONIVDAC),
+   regmap_reg_range(BD9571MWV_GPIO_IN, BD9571MWV_GPIO_IN),
+   regmap_reg_range(BD9571MWV_GPIO_INT, BD9571MWV_GPIO_INTMASK),
+   regmap_reg_range(BD9571MWV_INT_INTREQ, BD9571MWV_INT_INTMASK),
+};
+
+static const struct regmap_access_table bd9574mwf_readable_table = {
+   .yes_ranges = bd9574mwf_readable_yes_ranges,
+   .n_yes_ranges   = ARRAY_SIZE(bd9574mwf_readable_yes_ranges),
+};
+
+static const struct regmap_range bd9574mwf_writable_yes_ranges[] = {
+   regmap_reg_range(BD9571MWV_BKUP_MODE_CNT, BD9571MWV_BKUP_MODE_CNT),
+   regmap_reg_range(BD9571MWV_DVFS_SETVID, BD9571MWV_DVFS_SETVID),
+   regmap_reg_range(BD9571MWV_GPIO_DIR, BD9571MWV_GPIO_OUT),
+   regmap_reg_range(BD9571MWV_GPIO_INT_SET, BD9571MWV_GPIO_INTMASK),
+   regmap_reg_range(BD9571MWV_INT_INTREQ, BD9571MWV_INT_INTMASK),
+};
+
+static const struct regmap_access_table bd9574mwf_writable_table = {
+   .yes_ranges = bd9574mwf_writable_yes_ranges,
+   .n_yes_ranges   = ARRAY_SIZE(bd9574mwf_writable_yes_ranges),
+};
+
+static const struct regmap_range bd9574mwf_volatile_yes_ranges[] = {
+   regmap_reg_range(BD9571MWV_DVFS_MONIVDAC, BD9571MWV_DVFS_MONIVDAC),
+   regmap_reg_range(BD9571MWV_GPIO_IN, BD9571MWV_GPIO_IN),
+   regmap_reg_range(BD9571MWV_GPIO_INT, BD9571MWV_GPIO_INT),
+   regmap_reg_range(BD9571MWV_INT_INTREQ, BD9571MWV_INT_INTREQ),
+};
+
+static const struct regmap_access_table bd9574mwf_volatile_table = {
+   .yes_ranges = bd9574mwf_volatile_yes_ranges,
+   .n_yes_ranges   = ARRAY_SIZE(bd9574mwf_volatile_yes_ranges),
+};
+
+static const struct regmap_config bd9574mwf_regmap_config = {
+   .reg_bits   = 8,
+   .val_bits   = 8,
+   .cache_type = REGCACHE_RBTREE,
+   .rd_table   = _readable_table,
+   .wr_table   = _writable_table,
+   .volatile_table = _volatile_table,
+   .max_register   = 0xff,
+};
+
+static struct regmap_irq_chip bd9574mwf_irq_chip = {
+   .name   = "bd9574mwf",
+   .status_base= BD9571MWV_INT_INTREQ,
+   .mask_base  = BD9571MWV_INT_INTMASK,
+   .ack_base   = BD9571MWV_INT_INTREQ,
+   .init_ack_masked = true,
+   .num_regs   = 1,
+   .irqs   = bd9571mwv_irqs,
+   .num_irqs   = ARRAY_SIZE(bd9571mwv_irqs),
+};
+
 static int bd957x_identify(struct device *dev, struct regmap *regmap)
 {
unsigned int value;
@@ -162,6 +229,12 @@ static int bd9571mwv_probe(struct i2c_client *client,
cells = bd9571mwv_cells;
num_cells = ARRAY_SIZE(bd9571mwv_cells);
break;
+   case BD9571MWV_PRODUCT_CODE_BD9574MWF:
+   regmap_config = _regmap_config;
+   irq_chip = _irq_chip;
+   cells = bd9574mwf_cells;
+   num_cells = ARRAY_SIZE(bd9574mwf_cells);
+   break;
default:
dev_err(dev, "Unsupported device 0x%x\n", ret);
return -ENODEV;
@@ -190,6 +263,7 @@ static int bd9571mwv_probe(struct i2c_client *client,
 
 static const struct of_device_id bd9571mwv_of_match_table[] = {
{ .compatible = "rohm,bd9571mwv", },
+   { .compatible = "rohm,bd9574mwf", },
{ /* sentinel */ }
 };
 MODULE_DEVICE_TABLE(of, bd9571mwv_of_match_table);
diff --git a/include

[PATCH v9 11/12] mfd: bd9571mwv: Make the driver more generic

2021-01-12 Thread Yoshihiro Shimoda
From: Khiem Nguyen 

Since the driver supports BD9571MWV PMIC only, this patch makes
the functions and data structure become more generic so that
it can support other PMIC variants as well. Also remove printing
part name which Lee Jones suggested.

Signed-off-by: Khiem Nguyen 
Co-developed-by: Yoshihiro Shimoda 
Signed-off-by: Yoshihiro Shimoda 
Reviewed-by: Matti Vaittinen 
Acked-for-MFD-by: Lee Jones 
---
 drivers/mfd/bd9571mwv.c   | 77 +++
 include/linux/mfd/bd9571mwv.h | 18 ++
 2 files changed, 43 insertions(+), 52 deletions(-)

diff --git a/drivers/mfd/bd9571mwv.c b/drivers/mfd/bd9571mwv.c
index 49e968e..2c1fcbb 100644
--- a/drivers/mfd/bd9571mwv.c
+++ b/drivers/mfd/bd9571mwv.c
@@ -3,6 +3,7 @@
  * ROHM BD9571MWV-M MFD driver
  *
  * Copyright (C) 2017 Marek Vasut 
+ * Copyright (C) 2020 Renesas Electronics Corporation
  *
  * Based on the TPS65086 driver
  */
@@ -102,13 +103,12 @@ static struct regmap_irq_chip bd9571mwv_irq_chip = {
.num_irqs   = ARRAY_SIZE(bd9571mwv_irqs),
 };
 
-static int bd9571mwv_identify(struct bd9571mwv *bd)
+static int bd957x_identify(struct device *dev, struct regmap *regmap)
 {
-   struct device *dev = bd->dev;
unsigned int value;
int ret;
 
-   ret = regmap_read(bd->regmap, BD9571MWV_VENDOR_CODE, );
+   ret = regmap_read(regmap, BD9571MWV_VENDOR_CODE, );
if (ret) {
dev_err(dev, "Failed to read vendor code register (ret=%i)\n",
ret);
@@ -121,66 +121,71 @@ static int bd9571mwv_identify(struct bd9571mwv *bd)
return -EINVAL;
}
 
-   ret = regmap_read(bd->regmap, BD9571MWV_PRODUCT_CODE, );
+   ret = regmap_read(regmap, BD9571MWV_PRODUCT_CODE, );
if (ret) {
dev_err(dev, "Failed to read product code register (ret=%i)\n",
ret);
return ret;
}
-
-   if (value != BD9571MWV_PRODUCT_CODE_VAL) {
-   dev_err(dev, "Invalid product code ID %02x (expected %02x)\n",
-   value, BD9571MWV_PRODUCT_CODE_VAL);
-   return -EINVAL;
-   }
-
-   ret = regmap_read(bd->regmap, BD9571MWV_PRODUCT_REVISION, );
+   ret = regmap_read(regmap, BD9571MWV_PRODUCT_REVISION, );
if (ret) {
dev_err(dev, "Failed to read revision register (ret=%i)\n",
ret);
return ret;
}
 
-   dev_info(dev, "Device: BD9571MWV rev. %d\n", value & 0xff);
-
return 0;
 }
 
 static int bd9571mwv_probe(struct i2c_client *client,
- const struct i2c_device_id *ids)
+  const struct i2c_device_id *ids)
 {
-   struct bd9571mwv *bd;
-   int ret;
-
-   bd = devm_kzalloc(>dev, sizeof(*bd), GFP_KERNEL);
-   if (!bd)
-   return -ENOMEM;
+   const struct regmap_config *regmap_config;
+   const struct regmap_irq_chip *irq_chip;
+   const struct mfd_cell *cells;
+   struct device *dev = >dev;
+   struct regmap *regmap;
+   struct regmap_irq_chip_data *irq_data;
+   int ret, num_cells, irq = client->irq;
+
+   /* Read the PMIC product code */
+   ret = i2c_smbus_read_byte_data(client, BD9571MWV_PRODUCT_CODE);
+   if (ret < 0) {
+   dev_err(dev, "Failed to read product code\n");
+   return ret;
+   }
 
-   i2c_set_clientdata(client, bd);
-   bd->dev = >dev;
-   bd->irq = client->irq;
+   switch (ret) {
+   case BD9571MWV_PRODUCT_CODE_BD9571MWV:
+   regmap_config = _regmap_config;
+   irq_chip = _irq_chip;
+   cells = bd9571mwv_cells;
+   num_cells = ARRAY_SIZE(bd9571mwv_cells);
+   break;
+   default:
+   dev_err(dev, "Unsupported device 0x%x\n", ret);
+   return -ENODEV;
+   }
 
-   bd->regmap = devm_regmap_init_i2c(client, _regmap_config);
-   if (IS_ERR(bd->regmap)) {
-   dev_err(bd->dev, "Failed to initialize register map\n");
-   return PTR_ERR(bd->regmap);
+   regmap = devm_regmap_init_i2c(client, regmap_config);
+   if (IS_ERR(regmap)) {
+   dev_err(dev, "Failed to initialize register map\n");
+   return PTR_ERR(regmap);
}
 
-   ret = bd9571mwv_identify(bd);
+   ret = bd957x_identify(dev, regmap);
if (ret)
return ret;
 
-   ret = devm_regmap_add_irq_chip(bd->dev, bd->regmap, bd->irq,
-  IRQF_ONESHOT, 0, _irq_chip,
-  >irq_data);
+   ret = devm_regmap_add_irq_chip(dev, regmap, irq, IRQF_ONESHOT, 0,
+  irq_chip, _data);
if (ret) {
- 

[PATCH v9 08/12] gpio: bd9571mwv: Add BD9574MWF support

2021-01-12 Thread Yoshihiro Shimoda
Add support for BD9574MWF which is similar chip with BD9571MWV.
Note that BD9574MWF has additional features "RECOV_GPOUT",
"FREQSEL" and "RTC_IN", but supports GPIO function only.

Signed-off-by: Yoshihiro Shimoda 
Reviewed-by: Matti Vaittinen 
Acked-by: Linus Walleij 
Acked-by: Bartosz Golaszewski 
---
 drivers/gpio/gpio-bd9571mwv.c | 6 --
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/drivers/gpio/gpio-bd9571mwv.c b/drivers/gpio/gpio-bd9571mwv.c
index 0e5395f..df6102b 100644
--- a/drivers/gpio/gpio-bd9571mwv.c
+++ b/drivers/gpio/gpio-bd9571mwv.c
@@ -1,6 +1,6 @@
 // SPDX-License-Identifier: GPL-2.0-only
 /*
- * ROHM BD9571MWV-M GPIO driver
+ * ROHM BD9571MWV-M and BD9574MWF-M GPIO driver
  *
  * Copyright (C) 2017 Marek Vasut 
  *
@@ -10,6 +10,7 @@
  */
 
 #include 
+#include 
 #include 
 #include 
 
@@ -118,7 +119,8 @@ static int bd9571mwv_gpio_probe(struct platform_device 
*pdev)
 }
 
 static const struct platform_device_id bd9571mwv_gpio_id_table[] = {
-   { "bd9571mwv-gpio", },
+   { "bd9571mwv-gpio", ROHM_CHIP_TYPE_BD9571 },
+   { "bd9574mwf-gpio", ROHM_CHIP_TYPE_BD9574 },
{ /* sentinel */ }
 };
 MODULE_DEVICE_TABLE(platform, bd9571mwv_gpio_id_table);
-- 
2.7.4



[PATCH v9 04/12] regulator: bd9571mwv: rid of using struct bd9571mwv

2021-01-12 Thread Yoshihiro Shimoda
To simplify this driver, use dev_get_regmap() and
rid of using struct bd9571mwv.

Signed-off-by: Yoshihiro Shimoda 
Reviewed-by: Matti Vaittinen 
Acked-by: Mark Brown 
---
 drivers/regulator/bd9571mwv-regulator.c | 49 +
 1 file changed, 26 insertions(+), 23 deletions(-)

diff --git a/drivers/regulator/bd9571mwv-regulator.c 
b/drivers/regulator/bd9571mwv-regulator.c
index e690c2c..42b6a70 100644
--- a/drivers/regulator/bd9571mwv-regulator.c
+++ b/drivers/regulator/bd9571mwv-regulator.c
@@ -17,7 +17,7 @@
 #include 
 
 struct bd9571mwv_reg {
-   struct bd9571mwv *bd;
+   struct regmap *regmap;
 
/* DDR Backup Power */
u8 bkup_mode_cnt_keepon;/* from "rohm,ddr-backup-power" */
@@ -137,26 +137,30 @@ static const struct regulator_desc regulators[] = {
 };
 
 #ifdef CONFIG_PM_SLEEP
-static int bd9571mwv_bkup_mode_read(struct bd9571mwv *bd, unsigned int *mode)
+static int bd9571mwv_bkup_mode_read(struct bd9571mwv_reg *bdreg,
+   unsigned int *mode)
 {
int ret;
 
-   ret = regmap_read(bd->regmap, BD9571MWV_BKUP_MODE_CNT, mode);
+   ret = regmap_read(bdreg->regmap, BD9571MWV_BKUP_MODE_CNT, mode);
if (ret) {
-   dev_err(bd->dev, "failed to read backup mode (%d)\n", ret);
+   dev_err(regmap_get_device(bdreg->regmap),
+   "failed to read backup mode (%d)\n", ret);
return ret;
}
 
return 0;
 }
 
-static int bd9571mwv_bkup_mode_write(struct bd9571mwv *bd, unsigned int mode)
+static int bd9571mwv_bkup_mode_write(struct bd9571mwv_reg *bdreg,
+unsigned int mode)
 {
int ret;
 
-   ret = regmap_write(bd->regmap, BD9571MWV_BKUP_MODE_CNT, mode);
+   ret = regmap_write(bdreg->regmap, BD9571MWV_BKUP_MODE_CNT, mode);
if (ret) {
-   dev_err(bd->dev, "failed to configure backup mode 0x%x (%d)\n",
+   dev_err(regmap_get_device(bdreg->regmap),
+   "failed to configure backup mode 0x%x (%d)\n",
mode, ret);
return ret;
}
@@ -194,7 +198,7 @@ static ssize_t backup_mode_store(struct device *dev,
 * Configure DDR Backup Mode, to change the role of the accessory power
 * switch from a power switch to a wake-up switch, or vice versa
 */
-   ret = bd9571mwv_bkup_mode_read(bdreg->bd, );
+   ret = bd9571mwv_bkup_mode_read(bdreg, );
if (ret)
return ret;
 
@@ -202,7 +206,7 @@ static ssize_t backup_mode_store(struct device *dev,
if (bdreg->bkup_mode_enabled)
mode |= bdreg->bkup_mode_cnt_keepon;
 
-   ret = bd9571mwv_bkup_mode_write(bdreg->bd, mode);
+   ret = bd9571mwv_bkup_mode_write(bdreg, mode);
if (ret)
return ret;
 
@@ -221,7 +225,7 @@ static int bd9571mwv_suspend(struct device *dev)
return 0;
 
/* Save DDR Backup Mode */
-   ret = bd9571mwv_bkup_mode_read(bdreg->bd, );
+   ret = bd9571mwv_bkup_mode_read(bdreg, );
if (ret)
return ret;
 
@@ -235,7 +239,7 @@ static int bd9571mwv_suspend(struct device *dev)
mode |= bdreg->bkup_mode_cnt_keepon;
 
if (mode != bdreg->bkup_mode_cnt_saved)
-   return bd9571mwv_bkup_mode_write(bdreg->bd, mode);
+   return bd9571mwv_bkup_mode_write(bdreg, mode);
 
return 0;
 }
@@ -248,7 +252,7 @@ static int bd9571mwv_resume(struct device *dev)
return 0;
 
/* Restore DDR Backup Mode */
-   return bd9571mwv_bkup_mode_write(bdreg->bd, bdreg->bkup_mode_cnt_saved);
+   return bd9571mwv_bkup_mode_write(bdreg, bdreg->bkup_mode_cnt_saved);
 }
 
 static const struct dev_pm_ops bd9571mwv_pm  = {
@@ -268,7 +272,6 @@ static int bd9571mwv_regulator_remove(struct 
platform_device *pdev)
 
 static int bd9571mwv_regulator_probe(struct platform_device *pdev)
 {
-   struct bd9571mwv *bd = dev_get_drvdata(pdev->dev.parent);
struct regulator_config config = { };
struct bd9571mwv_reg *bdreg;
struct regulator_dev *rdev;
@@ -279,40 +282,40 @@ static int bd9571mwv_regulator_probe(struct 
platform_device *pdev)
if (!bdreg)
return -ENOMEM;
 
-   bdreg->bd = bd;
+   bdreg->regmap = dev_get_regmap(pdev->dev.parent, NULL);
 
platform_set_drvdata(pdev, bdreg);
 
config.dev = >dev;
-   config.dev->of_node = bd->dev->of_node;
-   config.driver_data = bd;
-   config.regmap = bd->regmap;
+   config.dev->of_node = pdev->dev.parent->of_node;
+   config.driver_data = bdreg;
+   config.regmap = bdreg->regmap;
 
for (i = 0; i < ARRAY_SIZE(regulators); i++) {
rdev = devm_regulator_register(>dev, [i

[PATCH v9 07/12] gpio: bd9571mwv: rid of using struct bd9571mwv

2021-01-12 Thread Yoshihiro Shimoda
To simplify this driver, use dev_get_regmap() and
rid of using struct bd9571mwv.

Signed-off-by: Yoshihiro Shimoda 
Reviewed-by: Matti Vaittinen 
Acked-by: Linus Walleij 
Acked-by: Bartosz Golaszewski 
---
 drivers/gpio/gpio-bd9571mwv.c | 19 +--
 1 file changed, 9 insertions(+), 10 deletions(-)

diff --git a/drivers/gpio/gpio-bd9571mwv.c b/drivers/gpio/gpio-bd9571mwv.c
index abb622c..0e5395f 100644
--- a/drivers/gpio/gpio-bd9571mwv.c
+++ b/drivers/gpio/gpio-bd9571mwv.c
@@ -16,8 +16,8 @@
 #include 
 
 struct bd9571mwv_gpio {
+   struct regmap *regmap;
struct gpio_chip chip;
-   struct bd9571mwv *bd;
 };
 
 static int bd9571mwv_gpio_get_direction(struct gpio_chip *chip,
@@ -26,7 +26,7 @@ static int bd9571mwv_gpio_get_direction(struct gpio_chip 
*chip,
struct bd9571mwv_gpio *gpio = gpiochip_get_data(chip);
int ret, val;
 
-   ret = regmap_read(gpio->bd->regmap, BD9571MWV_GPIO_DIR, );
+   ret = regmap_read(gpio->regmap, BD9571MWV_GPIO_DIR, );
if (ret < 0)
return ret;
if (val & BIT(offset))
@@ -40,8 +40,7 @@ static int bd9571mwv_gpio_direction_input(struct gpio_chip 
*chip,
 {
struct bd9571mwv_gpio *gpio = gpiochip_get_data(chip);
 
-   regmap_update_bits(gpio->bd->regmap, BD9571MWV_GPIO_DIR,
-  BIT(offset), 0);
+   regmap_update_bits(gpio->regmap, BD9571MWV_GPIO_DIR, BIT(offset), 0);
 
return 0;
 }
@@ -52,9 +51,9 @@ static int bd9571mwv_gpio_direction_output(struct gpio_chip 
*chip,
struct bd9571mwv_gpio *gpio = gpiochip_get_data(chip);
 
/* Set the initial value */
-   regmap_update_bits(gpio->bd->regmap, BD9571MWV_GPIO_OUT,
+   regmap_update_bits(gpio->regmap, BD9571MWV_GPIO_OUT,
   BIT(offset), value ? BIT(offset) : 0);
-   regmap_update_bits(gpio->bd->regmap, BD9571MWV_GPIO_DIR,
+   regmap_update_bits(gpio->regmap, BD9571MWV_GPIO_DIR,
   BIT(offset), BIT(offset));
 
return 0;
@@ -65,7 +64,7 @@ static int bd9571mwv_gpio_get(struct gpio_chip *chip, 
unsigned int offset)
struct bd9571mwv_gpio *gpio = gpiochip_get_data(chip);
int ret, val;
 
-   ret = regmap_read(gpio->bd->regmap, BD9571MWV_GPIO_IN, );
+   ret = regmap_read(gpio->regmap, BD9571MWV_GPIO_IN, );
if (ret < 0)
return ret;
 
@@ -77,7 +76,7 @@ static void bd9571mwv_gpio_set(struct gpio_chip *chip, 
unsigned int offset,
 {
struct bd9571mwv_gpio *gpio = gpiochip_get_data(chip);
 
-   regmap_update_bits(gpio->bd->regmap, BD9571MWV_GPIO_OUT,
+   regmap_update_bits(gpio->regmap, BD9571MWV_GPIO_OUT,
   BIT(offset), value ? BIT(offset) : 0);
 }
 
@@ -105,9 +104,9 @@ static int bd9571mwv_gpio_probe(struct platform_device 
*pdev)
 
platform_set_drvdata(pdev, gpio);
 
-   gpio->bd = dev_get_drvdata(pdev->dev.parent);
+   gpio->regmap = dev_get_regmap(pdev->dev.parent, NULL);
gpio->chip = template_chip;
-   gpio->chip.parent = gpio->bd->dev;
+   gpio->chip.parent = pdev->dev.parent;
 
ret = devm_gpiochip_add_data(>dev, >chip, gpio);
if (ret < 0) {
-- 
2.7.4



[PATCH v9 02/12] dt-bindings: mfd: bd9571mwv: Document BD9574MWF

2021-01-12 Thread Yoshihiro Shimoda
Document other similar specification chip BD9574MWF.

Signed-off-by: Yoshihiro Shimoda 
Acked-for-MFD-by: Lee Jones 
---
 Documentation/devicetree/bindings/mfd/bd9571mwv.txt | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/Documentation/devicetree/bindings/mfd/bd9571mwv.txt 
b/Documentation/devicetree/bindings/mfd/bd9571mwv.txt
index 8c46786..1d6413e 100644
--- a/Documentation/devicetree/bindings/mfd/bd9571mwv.txt
+++ b/Documentation/devicetree/bindings/mfd/bd9571mwv.txt
@@ -1,7 +1,7 @@
-* ROHM BD9571MWV Power Management Integrated Circuit (PMIC) bindings
+* ROHM BD9571MWV/BD9574MWF Power Management Integrated Circuit (PMIC) bindings
 
 Required properties:
- - compatible  : Should be "rohm,bd9571mwv".
+ - compatible  : Should be "rohm,bd9571mwv" or "rohm,bd9574mwf".
  - reg : I2C slave address.
  - interrupts  : The interrupt line the device is connected to.
  - interrupt-controller: Marks the device node as an interrupt 
controller.
-- 
2.7.4



RE: [PATCH v6 08/12] gpio: bd9571mwv: Add BD9574MWF support

2021-01-11 Thread Yoshihiro Shimoda
Hi Linus,

> From: Linus Walleij, Sent: Monday, December 28, 2020 6:16 AM
> 
> > Add support for BD9574MWF which is similar chip with BD9571MWV.
> > Note that BD9574MWF has additional features "RECOV_GPOUT",
> > "FREQSEL" and "RTC_IN", but supports GPIO function only.
> >
> > Signed-off-by: Yoshihiro Shimoda 
> > Reviewed-by: Matti Vaittinen 
> 
> Acked-by: Linus Walleij 

Thank you for your Acked-by! I'll add your Acked-by in the next patch version 
as v9.

> This looks like it compile-time depends on the other patches right?

You're correct.

Best regards,
Yoshihiro Shimoda



[PATCH v8 03/12] mfd: rohm-generic: Add BD9571 and BD9574

2020-12-25 Thread Yoshihiro Shimoda
Add chip IDs for BD9571MWV and BD9574MWF.

Signed-off-by: Yoshihiro Shimoda 
Reviewed-by: Matti Vaittinen 
Acked-for-MFD-by: Lee Jones 
---
 include/linux/mfd/rohm-generic.h | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/include/linux/mfd/rohm-generic.h b/include/linux/mfd/rohm-generic.h
index 4283b5b..affacf8 100644
--- a/include/linux/mfd/rohm-generic.h
+++ b/include/linux/mfd/rohm-generic.h
@@ -12,6 +12,8 @@ enum rohm_chip_type {
ROHM_CHIP_TYPE_BD71847,
ROHM_CHIP_TYPE_BD70528,
ROHM_CHIP_TYPE_BD71828,
+   ROHM_CHIP_TYPE_BD9571,
+   ROHM_CHIP_TYPE_BD9574,
ROHM_CHIP_TYPE_AMOUNT
 };
 
-- 
2.7.4



[PATCH v8 02/12] dt-bindings: mfd: bd9571mwv: Document BD9574MWF

2020-12-25 Thread Yoshihiro Shimoda
Document other similar specification chip BD9574MWF.

Signed-off-by: Yoshihiro Shimoda 
Acked-for-MFD-by: Lee Jones 
---
 Documentation/devicetree/bindings/mfd/bd9571mwv.txt | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/Documentation/devicetree/bindings/mfd/bd9571mwv.txt 
b/Documentation/devicetree/bindings/mfd/bd9571mwv.txt
index 8c46786..1d6413e 100644
--- a/Documentation/devicetree/bindings/mfd/bd9571mwv.txt
+++ b/Documentation/devicetree/bindings/mfd/bd9571mwv.txt
@@ -1,7 +1,7 @@
-* ROHM BD9571MWV Power Management Integrated Circuit (PMIC) bindings
+* ROHM BD9571MWV/BD9574MWF Power Management Integrated Circuit (PMIC) bindings
 
 Required properties:
- - compatible  : Should be "rohm,bd9571mwv".
+ - compatible  : Should be "rohm,bd9571mwv" or "rohm,bd9574mwf".
  - reg : I2C slave address.
  - interrupts  : The interrupt line the device is connected to.
  - interrupt-controller: Marks the device node as an interrupt 
controller.
-- 
2.7.4



[PATCH v8 08/12] gpio: bd9571mwv: Add BD9574MWF support

2020-12-25 Thread Yoshihiro Shimoda
Add support for BD9574MWF which is similar chip with BD9571MWV.
Note that BD9574MWF has additional features "RECOV_GPOUT",
"FREQSEL" and "RTC_IN", but supports GPIO function only.

Signed-off-by: Yoshihiro Shimoda 
Reviewed-by: Matti Vaittinen 
---
 drivers/gpio/gpio-bd9571mwv.c | 6 --
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/drivers/gpio/gpio-bd9571mwv.c b/drivers/gpio/gpio-bd9571mwv.c
index 0e5395f..df6102b 100644
--- a/drivers/gpio/gpio-bd9571mwv.c
+++ b/drivers/gpio/gpio-bd9571mwv.c
@@ -1,6 +1,6 @@
 // SPDX-License-Identifier: GPL-2.0-only
 /*
- * ROHM BD9571MWV-M GPIO driver
+ * ROHM BD9571MWV-M and BD9574MWF-M GPIO driver
  *
  * Copyright (C) 2017 Marek Vasut 
  *
@@ -10,6 +10,7 @@
  */
 
 #include 
+#include 
 #include 
 #include 
 
@@ -118,7 +119,8 @@ static int bd9571mwv_gpio_probe(struct platform_device 
*pdev)
 }
 
 static const struct platform_device_id bd9571mwv_gpio_id_table[] = {
-   { "bd9571mwv-gpio", },
+   { "bd9571mwv-gpio", ROHM_CHIP_TYPE_BD9571 },
+   { "bd9574mwf-gpio", ROHM_CHIP_TYPE_BD9574 },
{ /* sentinel */ }
 };
 MODULE_DEVICE_TABLE(platform, bd9571mwv_gpio_id_table);
-- 
2.7.4



[PATCH v8 05/12] regulator: bd9571mwv: Add BD9574MWF support

2020-12-25 Thread Yoshihiro Shimoda
Add support for BD9574MWF which is similar chip with BD9571MWV.
Note that we don't support voltage rails VD{09,18,25,33} by this
driver on BD9574. The VD09 voltage could be read from PMIC but that
is not supported by this commit.

Signed-off-by: Yoshihiro Shimoda 
Reviewed-by: Matti Vaittinen 
---
 drivers/regulator/bd9571mwv-regulator.c | 10 --
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/drivers/regulator/bd9571mwv-regulator.c 
b/drivers/regulator/bd9571mwv-regulator.c
index 42b6a70..7b0cd08 100644
--- a/drivers/regulator/bd9571mwv-regulator.c
+++ b/drivers/regulator/bd9571mwv-regulator.c
@@ -1,6 +1,6 @@
 // SPDX-License-Identifier: GPL-2.0
 /*
- * ROHM BD9571MWV-M regulator driver
+ * ROHM BD9571MWV-M and BD9574MWF-M regulator driver
  *
  * Copyright (C) 2017 Marek Vasut 
  *
@@ -9,6 +9,7 @@
  * NOTE: VD09 is missing
  */
 
+#include 
 #include 
 #include 
 #include 
@@ -277,6 +278,7 @@ static int bd9571mwv_regulator_probe(struct platform_device 
*pdev)
struct regulator_dev *rdev;
unsigned int val;
int i;
+   enum rohm_chip_type chip = platform_get_device_id(pdev)->driver_data;
 
bdreg = devm_kzalloc(>dev, sizeof(*bdreg), GFP_KERNEL);
if (!bdreg)
@@ -292,6 +294,9 @@ static int bd9571mwv_regulator_probe(struct platform_device 
*pdev)
config.regmap = bdreg->regmap;
 
for (i = 0; i < ARRAY_SIZE(regulators); i++) {
+   /* BD9574MWF supports DVFS only */
+   if (chip == ROHM_CHIP_TYPE_BD9574 && regulators[i].id != DVFS)
+   continue;
rdev = devm_regulator_register(>dev, [i],
   );
if (IS_ERR(rdev)) {
@@ -339,7 +344,8 @@ static int bd9571mwv_regulator_probe(struct platform_device 
*pdev)
 }
 
 static const struct platform_device_id bd9571mwv_regulator_id_table[] = {
-   { "bd9571mwv-regulator", },
+   { "bd9571mwv-regulator", ROHM_CHIP_TYPE_BD9571 },
+   { "bd9574mwf-regulator", ROHM_CHIP_TYPE_BD9574 },
{ /* sentinel */ }
 };
 MODULE_DEVICE_TABLE(platform, bd9571mwv_regulator_id_table);
-- 
2.7.4



[PATCH v8 11/12] mfd: bd9571mwv: Make the driver more generic

2020-12-25 Thread Yoshihiro Shimoda
From: Khiem Nguyen 

Since the driver supports BD9571MWV PMIC only, this patch makes
the functions and data structure become more generic so that
it can support other PMIC variants as well. Also remove printing
part name which Lee Jones suggested.

Signed-off-by: Khiem Nguyen 
Co-developed-by: Yoshihiro Shimoda 
Signed-off-by: Yoshihiro Shimoda 
Reviewed-by: Matti Vaittinen 
Acked-for-MFD-by: Lee Jones 
---
 drivers/mfd/bd9571mwv.c   | 77 +++
 include/linux/mfd/bd9571mwv.h | 18 ++
 2 files changed, 43 insertions(+), 52 deletions(-)

diff --git a/drivers/mfd/bd9571mwv.c b/drivers/mfd/bd9571mwv.c
index 49e968e..2c1fcbb 100644
--- a/drivers/mfd/bd9571mwv.c
+++ b/drivers/mfd/bd9571mwv.c
@@ -3,6 +3,7 @@
  * ROHM BD9571MWV-M MFD driver
  *
  * Copyright (C) 2017 Marek Vasut 
+ * Copyright (C) 2020 Renesas Electronics Corporation
  *
  * Based on the TPS65086 driver
  */
@@ -102,13 +103,12 @@ static struct regmap_irq_chip bd9571mwv_irq_chip = {
.num_irqs   = ARRAY_SIZE(bd9571mwv_irqs),
 };
 
-static int bd9571mwv_identify(struct bd9571mwv *bd)
+static int bd957x_identify(struct device *dev, struct regmap *regmap)
 {
-   struct device *dev = bd->dev;
unsigned int value;
int ret;
 
-   ret = regmap_read(bd->regmap, BD9571MWV_VENDOR_CODE, );
+   ret = regmap_read(regmap, BD9571MWV_VENDOR_CODE, );
if (ret) {
dev_err(dev, "Failed to read vendor code register (ret=%i)\n",
ret);
@@ -121,66 +121,71 @@ static int bd9571mwv_identify(struct bd9571mwv *bd)
return -EINVAL;
}
 
-   ret = regmap_read(bd->regmap, BD9571MWV_PRODUCT_CODE, );
+   ret = regmap_read(regmap, BD9571MWV_PRODUCT_CODE, );
if (ret) {
dev_err(dev, "Failed to read product code register (ret=%i)\n",
ret);
return ret;
}
-
-   if (value != BD9571MWV_PRODUCT_CODE_VAL) {
-   dev_err(dev, "Invalid product code ID %02x (expected %02x)\n",
-   value, BD9571MWV_PRODUCT_CODE_VAL);
-   return -EINVAL;
-   }
-
-   ret = regmap_read(bd->regmap, BD9571MWV_PRODUCT_REVISION, );
+   ret = regmap_read(regmap, BD9571MWV_PRODUCT_REVISION, );
if (ret) {
dev_err(dev, "Failed to read revision register (ret=%i)\n",
ret);
return ret;
}
 
-   dev_info(dev, "Device: BD9571MWV rev. %d\n", value & 0xff);
-
return 0;
 }
 
 static int bd9571mwv_probe(struct i2c_client *client,
- const struct i2c_device_id *ids)
+  const struct i2c_device_id *ids)
 {
-   struct bd9571mwv *bd;
-   int ret;
-
-   bd = devm_kzalloc(>dev, sizeof(*bd), GFP_KERNEL);
-   if (!bd)
-   return -ENOMEM;
+   const struct regmap_config *regmap_config;
+   const struct regmap_irq_chip *irq_chip;
+   const struct mfd_cell *cells;
+   struct device *dev = >dev;
+   struct regmap *regmap;
+   struct regmap_irq_chip_data *irq_data;
+   int ret, num_cells, irq = client->irq;
+
+   /* Read the PMIC product code */
+   ret = i2c_smbus_read_byte_data(client, BD9571MWV_PRODUCT_CODE);
+   if (ret < 0) {
+   dev_err(dev, "Failed to read product code\n");
+   return ret;
+   }
 
-   i2c_set_clientdata(client, bd);
-   bd->dev = >dev;
-   bd->irq = client->irq;
+   switch (ret) {
+   case BD9571MWV_PRODUCT_CODE_BD9571MWV:
+   regmap_config = _regmap_config;
+   irq_chip = _irq_chip;
+   cells = bd9571mwv_cells;
+   num_cells = ARRAY_SIZE(bd9571mwv_cells);
+   break;
+   default:
+   dev_err(dev, "Unsupported device 0x%x\n", ret);
+   return -ENODEV;
+   }
 
-   bd->regmap = devm_regmap_init_i2c(client, _regmap_config);
-   if (IS_ERR(bd->regmap)) {
-   dev_err(bd->dev, "Failed to initialize register map\n");
-   return PTR_ERR(bd->regmap);
+   regmap = devm_regmap_init_i2c(client, regmap_config);
+   if (IS_ERR(regmap)) {
+   dev_err(dev, "Failed to initialize register map\n");
+   return PTR_ERR(regmap);
}
 
-   ret = bd9571mwv_identify(bd);
+   ret = bd957x_identify(dev, regmap);
if (ret)
return ret;
 
-   ret = devm_regmap_add_irq_chip(bd->dev, bd->regmap, bd->irq,
-  IRQF_ONESHOT, 0, _irq_chip,
-  >irq_data);
+   ret = devm_regmap_add_irq_chip(dev, regmap, irq, IRQF_ONESHOT, 0,
+  irq_chip, _data);
if (ret) {
- 

[PATCH v8 09/12] mfd: bd9571mwv: Use the SPDX license identifier

2020-12-25 Thread Yoshihiro Shimoda
Use the SPDX license identifier instead of a local description.

Signed-off-by: Yoshihiro Shimoda 
Reviewed-by: Geert Uytterhoeven 
Acked-for-MFD-by: Lee Jones 
---
 drivers/mfd/bd9571mwv.c   | 10 +-
 include/linux/mfd/bd9571mwv.h | 10 +-
 2 files changed, 2 insertions(+), 18 deletions(-)

diff --git a/drivers/mfd/bd9571mwv.c b/drivers/mfd/bd9571mwv.c
index 19d57a4..e68c3fa 100644
--- a/drivers/mfd/bd9571mwv.c
+++ b/drivers/mfd/bd9571mwv.c
@@ -1,17 +1,9 @@
+// SPDX-License-Identifier: GPL-2.0-only
 /*
  * ROHM BD9571MWV-M MFD driver
  *
  * Copyright (C) 2017 Marek Vasut 
  *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License version 2 as
- * published by the Free Software Foundation.
- *
- * This program is distributed "as is" WITHOUT ANY WARRANTY of any
- * kind, whether expressed or implied; without even the implied warranty
- * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License version 2 for more details.
- *
  * Based on the TPS65086 driver
  */
 
diff --git a/include/linux/mfd/bd9571mwv.h b/include/linux/mfd/bd9571mwv.h
index eb05569..bcc7092 100644
--- a/include/linux/mfd/bd9571mwv.h
+++ b/include/linux/mfd/bd9571mwv.h
@@ -1,17 +1,9 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
 /*
  * ROHM BD9571MWV-M driver
  *
  * Copyright (C) 2017 Marek Vasut 
  *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License version 2 as
- * published by the Free Software Foundation.
- *
- * This program is distributed "as is" WITHOUT ANY WARRANTY of any
- * kind, whether expressed or implied; without even the implied warranty
- * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License version 2 for more details.
- *
  * Based on the TPS65086 driver
  */
 
-- 
2.7.4



[PATCH v8 10/12] mfd: bd9571mwv: Use devm_regmap_add_irq_chip()

2020-12-25 Thread Yoshihiro Shimoda
Use devm_regmap_add_irq_chip() to simplify the code.

Signed-off-by: Yoshihiro Shimoda 
Acked-for-MFD-by: Lee Jones 
Reviewed-by: Matti Vaittinen 
Reviewed-by: Geert Uytterhoeven 
---
 drivers/mfd/bd9571mwv.c | 27 ++-
 1 file changed, 6 insertions(+), 21 deletions(-)

diff --git a/drivers/mfd/bd9571mwv.c b/drivers/mfd/bd9571mwv.c
index e68c3fa..49e968e 100644
--- a/drivers/mfd/bd9571mwv.c
+++ b/drivers/mfd/bd9571mwv.c
@@ -170,31 +170,17 @@ static int bd9571mwv_probe(struct i2c_client *client,
if (ret)
return ret;
 
-   ret = regmap_add_irq_chip(bd->regmap, bd->irq, IRQF_ONESHOT, 0,
- _irq_chip, >irq_data);
+   ret = devm_regmap_add_irq_chip(bd->dev, bd->regmap, bd->irq,
+  IRQF_ONESHOT, 0, _irq_chip,
+  >irq_data);
if (ret) {
dev_err(bd->dev, "Failed to register IRQ chip\n");
return ret;
}
 
-   ret = devm_mfd_add_devices(bd->dev, PLATFORM_DEVID_AUTO,
-  bd9571mwv_cells, ARRAY_SIZE(bd9571mwv_cells),
-  NULL, 0, 
regmap_irq_get_domain(bd->irq_data));
-   if (ret) {
-   regmap_del_irq_chip(bd->irq, bd->irq_data);
-   return ret;
-   }
-
-   return 0;
-}
-
-static int bd9571mwv_remove(struct i2c_client *client)
-{
-   struct bd9571mwv *bd = i2c_get_clientdata(client);
-
-   regmap_del_irq_chip(bd->irq, bd->irq_data);
-
-   return 0;
+   return devm_mfd_add_devices(bd->dev, PLATFORM_DEVID_AUTO,
+   bd9571mwv_cells, 
ARRAY_SIZE(bd9571mwv_cells),
+   NULL, 0, 
regmap_irq_get_domain(bd->irq_data));
 }
 
 static const struct of_device_id bd9571mwv_of_match_table[] = {
@@ -215,7 +201,6 @@ static struct i2c_driver bd9571mwv_driver = {
.of_match_table = bd9571mwv_of_match_table,
},
.probe  = bd9571mwv_probe,
-   .remove = bd9571mwv_remove,
.id_table   = bd9571mwv_id_table,
 };
 module_i2c_driver(bd9571mwv_driver);
-- 
2.7.4



[PATCH v8 12/12] mfd: bd9571mwv: Add support for BD9574MWF

2020-12-25 Thread Yoshihiro Shimoda
From: Khiem Nguyen 

The new PMIC BD9574MWF inherits features from BD9571MWV.
Add the support of new PMIC to existing bd9571mwv driver.

Signed-off-by: Khiem Nguyen 
Co-developed-by: Yoshihiro Shimoda 
Signed-off-by: Yoshihiro Shimoda 
Reviewed-by: Matti Vaittinen 
Acked-for-MFD-by: Lee Jones 
---
 drivers/mfd/bd9571mwv.c   | 76 ++-
 include/linux/mfd/bd9571mwv.h | 17 --
 2 files changed, 89 insertions(+), 4 deletions(-)

diff --git a/drivers/mfd/bd9571mwv.c b/drivers/mfd/bd9571mwv.c
index 2c1fcbb..e15b1ac 100644
--- a/drivers/mfd/bd9571mwv.c
+++ b/drivers/mfd/bd9571mwv.c
@@ -1,6 +1,6 @@
 // SPDX-License-Identifier: GPL-2.0-only
 /*
- * ROHM BD9571MWV-M MFD driver
+ * ROHM BD9571MWV-M and BD9574MVF-M core driver
  *
  * Copyright (C) 2017 Marek Vasut 
  * Copyright (C) 2020 Renesas Electronics Corporation
@@ -11,6 +11,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 
 #include 
@@ -103,6 +104,72 @@ static struct regmap_irq_chip bd9571mwv_irq_chip = {
.num_irqs   = ARRAY_SIZE(bd9571mwv_irqs),
 };
 
+static const struct mfd_cell bd9574mwf_cells[] = {
+   { .name = "bd9574mwf-regulator", },
+   { .name = "bd9574mwf-gpio", },
+};
+
+static const struct regmap_range bd9574mwf_readable_yes_ranges[] = {
+   regmap_reg_range(BD9571MWV_VENDOR_CODE, BD9571MWV_PRODUCT_REVISION),
+   regmap_reg_range(BD9571MWV_BKUP_MODE_CNT, BD9571MWV_BKUP_MODE_CNT),
+   regmap_reg_range(BD9571MWV_DVFS_VINIT, BD9571MWV_DVFS_SETVMAX),
+   regmap_reg_range(BD9571MWV_DVFS_SETVID, BD9571MWV_DVFS_MONIVDAC),
+   regmap_reg_range(BD9571MWV_GPIO_IN, BD9571MWV_GPIO_IN),
+   regmap_reg_range(BD9571MWV_GPIO_INT, BD9571MWV_GPIO_INTMASK),
+   regmap_reg_range(BD9571MWV_INT_INTREQ, BD9571MWV_INT_INTMASK),
+};
+
+static const struct regmap_access_table bd9574mwf_readable_table = {
+   .yes_ranges = bd9574mwf_readable_yes_ranges,
+   .n_yes_ranges   = ARRAY_SIZE(bd9574mwf_readable_yes_ranges),
+};
+
+static const struct regmap_range bd9574mwf_writable_yes_ranges[] = {
+   regmap_reg_range(BD9571MWV_BKUP_MODE_CNT, BD9571MWV_BKUP_MODE_CNT),
+   regmap_reg_range(BD9571MWV_DVFS_SETVID, BD9571MWV_DVFS_SETVID),
+   regmap_reg_range(BD9571MWV_GPIO_DIR, BD9571MWV_GPIO_OUT),
+   regmap_reg_range(BD9571MWV_GPIO_INT_SET, BD9571MWV_GPIO_INTMASK),
+   regmap_reg_range(BD9571MWV_INT_INTREQ, BD9571MWV_INT_INTMASK),
+};
+
+static const struct regmap_access_table bd9574mwf_writable_table = {
+   .yes_ranges = bd9574mwf_writable_yes_ranges,
+   .n_yes_ranges   = ARRAY_SIZE(bd9574mwf_writable_yes_ranges),
+};
+
+static const struct regmap_range bd9574mwf_volatile_yes_ranges[] = {
+   regmap_reg_range(BD9571MWV_DVFS_MONIVDAC, BD9571MWV_DVFS_MONIVDAC),
+   regmap_reg_range(BD9571MWV_GPIO_IN, BD9571MWV_GPIO_IN),
+   regmap_reg_range(BD9571MWV_GPIO_INT, BD9571MWV_GPIO_INT),
+   regmap_reg_range(BD9571MWV_INT_INTREQ, BD9571MWV_INT_INTREQ),
+};
+
+static const struct regmap_access_table bd9574mwf_volatile_table = {
+   .yes_ranges = bd9574mwf_volatile_yes_ranges,
+   .n_yes_ranges   = ARRAY_SIZE(bd9574mwf_volatile_yes_ranges),
+};
+
+static const struct regmap_config bd9574mwf_regmap_config = {
+   .reg_bits   = 8,
+   .val_bits   = 8,
+   .cache_type = REGCACHE_RBTREE,
+   .rd_table   = _readable_table,
+   .wr_table   = _writable_table,
+   .volatile_table = _volatile_table,
+   .max_register   = 0xff,
+};
+
+static struct regmap_irq_chip bd9574mwf_irq_chip = {
+   .name   = "bd9574mwf",
+   .status_base= BD9571MWV_INT_INTREQ,
+   .mask_base  = BD9571MWV_INT_INTMASK,
+   .ack_base   = BD9571MWV_INT_INTREQ,
+   .init_ack_masked = true,
+   .num_regs   = 1,
+   .irqs   = bd9571mwv_irqs,
+   .num_irqs   = ARRAY_SIZE(bd9571mwv_irqs),
+};
+
 static int bd957x_identify(struct device *dev, struct regmap *regmap)
 {
unsigned int value;
@@ -162,6 +229,12 @@ static int bd9571mwv_probe(struct i2c_client *client,
cells = bd9571mwv_cells;
num_cells = ARRAY_SIZE(bd9571mwv_cells);
break;
+   case BD9571MWV_PRODUCT_CODE_BD9574MWF:
+   regmap_config = _regmap_config;
+   irq_chip = _irq_chip;
+   cells = bd9574mwf_cells;
+   num_cells = ARRAY_SIZE(bd9574mwf_cells);
+   break;
default:
dev_err(dev, "Unsupported device 0x%x\n", ret);
return -ENODEV;
@@ -190,6 +263,7 @@ static int bd9571mwv_probe(struct i2c_client *client,
 
 static const struct of_device_id bd9571mwv_of_match_table[] = {
{ .compatible = "rohm,bd9571mwv", },
+   { .compatible = "rohm,bd9574mwf", },
{ /* sentinel */ }
 };
 MODULE_DEVICE_TABLE(of, bd9571mwv_of_match_table);
diff --git a/include

[PATCH v8 04/12] regulator: bd9571mwv: rid of using struct bd9571mwv

2020-12-25 Thread Yoshihiro Shimoda
To simplify this driver, use dev_get_regmap() and
rid of using struct bd9571mwv.

Signed-off-by: Yoshihiro Shimoda 
Reviewed-by: Matti Vaittinen 
---
 drivers/regulator/bd9571mwv-regulator.c | 49 +
 1 file changed, 26 insertions(+), 23 deletions(-)

diff --git a/drivers/regulator/bd9571mwv-regulator.c 
b/drivers/regulator/bd9571mwv-regulator.c
index e690c2c..42b6a70 100644
--- a/drivers/regulator/bd9571mwv-regulator.c
+++ b/drivers/regulator/bd9571mwv-regulator.c
@@ -17,7 +17,7 @@
 #include 
 
 struct bd9571mwv_reg {
-   struct bd9571mwv *bd;
+   struct regmap *regmap;
 
/* DDR Backup Power */
u8 bkup_mode_cnt_keepon;/* from "rohm,ddr-backup-power" */
@@ -137,26 +137,30 @@ static const struct regulator_desc regulators[] = {
 };
 
 #ifdef CONFIG_PM_SLEEP
-static int bd9571mwv_bkup_mode_read(struct bd9571mwv *bd, unsigned int *mode)
+static int bd9571mwv_bkup_mode_read(struct bd9571mwv_reg *bdreg,
+   unsigned int *mode)
 {
int ret;
 
-   ret = regmap_read(bd->regmap, BD9571MWV_BKUP_MODE_CNT, mode);
+   ret = regmap_read(bdreg->regmap, BD9571MWV_BKUP_MODE_CNT, mode);
if (ret) {
-   dev_err(bd->dev, "failed to read backup mode (%d)\n", ret);
+   dev_err(regmap_get_device(bdreg->regmap),
+   "failed to read backup mode (%d)\n", ret);
return ret;
}
 
return 0;
 }
 
-static int bd9571mwv_bkup_mode_write(struct bd9571mwv *bd, unsigned int mode)
+static int bd9571mwv_bkup_mode_write(struct bd9571mwv_reg *bdreg,
+unsigned int mode)
 {
int ret;
 
-   ret = regmap_write(bd->regmap, BD9571MWV_BKUP_MODE_CNT, mode);
+   ret = regmap_write(bdreg->regmap, BD9571MWV_BKUP_MODE_CNT, mode);
if (ret) {
-   dev_err(bd->dev, "failed to configure backup mode 0x%x (%d)\n",
+   dev_err(regmap_get_device(bdreg->regmap),
+   "failed to configure backup mode 0x%x (%d)\n",
mode, ret);
return ret;
}
@@ -194,7 +198,7 @@ static ssize_t backup_mode_store(struct device *dev,
 * Configure DDR Backup Mode, to change the role of the accessory power
 * switch from a power switch to a wake-up switch, or vice versa
 */
-   ret = bd9571mwv_bkup_mode_read(bdreg->bd, );
+   ret = bd9571mwv_bkup_mode_read(bdreg, );
if (ret)
return ret;
 
@@ -202,7 +206,7 @@ static ssize_t backup_mode_store(struct device *dev,
if (bdreg->bkup_mode_enabled)
mode |= bdreg->bkup_mode_cnt_keepon;
 
-   ret = bd9571mwv_bkup_mode_write(bdreg->bd, mode);
+   ret = bd9571mwv_bkup_mode_write(bdreg, mode);
if (ret)
return ret;
 
@@ -221,7 +225,7 @@ static int bd9571mwv_suspend(struct device *dev)
return 0;
 
/* Save DDR Backup Mode */
-   ret = bd9571mwv_bkup_mode_read(bdreg->bd, );
+   ret = bd9571mwv_bkup_mode_read(bdreg, );
if (ret)
return ret;
 
@@ -235,7 +239,7 @@ static int bd9571mwv_suspend(struct device *dev)
mode |= bdreg->bkup_mode_cnt_keepon;
 
if (mode != bdreg->bkup_mode_cnt_saved)
-   return bd9571mwv_bkup_mode_write(bdreg->bd, mode);
+   return bd9571mwv_bkup_mode_write(bdreg, mode);
 
return 0;
 }
@@ -248,7 +252,7 @@ static int bd9571mwv_resume(struct device *dev)
return 0;
 
/* Restore DDR Backup Mode */
-   return bd9571mwv_bkup_mode_write(bdreg->bd, bdreg->bkup_mode_cnt_saved);
+   return bd9571mwv_bkup_mode_write(bdreg, bdreg->bkup_mode_cnt_saved);
 }
 
 static const struct dev_pm_ops bd9571mwv_pm  = {
@@ -268,7 +272,6 @@ static int bd9571mwv_regulator_remove(struct 
platform_device *pdev)
 
 static int bd9571mwv_regulator_probe(struct platform_device *pdev)
 {
-   struct bd9571mwv *bd = dev_get_drvdata(pdev->dev.parent);
struct regulator_config config = { };
struct bd9571mwv_reg *bdreg;
struct regulator_dev *rdev;
@@ -279,40 +282,40 @@ static int bd9571mwv_regulator_probe(struct 
platform_device *pdev)
if (!bdreg)
return -ENOMEM;
 
-   bdreg->bd = bd;
+   bdreg->regmap = dev_get_regmap(pdev->dev.parent, NULL);
 
platform_set_drvdata(pdev, bdreg);
 
config.dev = >dev;
-   config.dev->of_node = bd->dev->of_node;
-   config.driver_data = bd;
-   config.regmap = bd->regmap;
+   config.dev->of_node = pdev->dev.parent->of_node;
+   config.driver_data = bdreg;
+   config.regmap = bdreg->regmap;
 
for (i = 0; i < ARRAY_SIZE(regulators); i++) {
rdev = devm_regulator_register(>dev, [i],
 

[PATCH v8 06/12] gpio: bd9571mwv: Use the SPDX license identifier

2020-12-25 Thread Yoshihiro Shimoda
Use the SPDX license identifier instead of a local description.

Signed-off-by: Yoshihiro Shimoda 
Reviewed-by: Geert Uytterhoeven 
---
 drivers/gpio/gpio-bd9571mwv.c | 10 +-
 1 file changed, 1 insertion(+), 9 deletions(-)

diff --git a/drivers/gpio/gpio-bd9571mwv.c b/drivers/gpio/gpio-bd9571mwv.c
index c0abc9c..abb622c 100644
--- a/drivers/gpio/gpio-bd9571mwv.c
+++ b/drivers/gpio/gpio-bd9571mwv.c
@@ -1,17 +1,9 @@
+// SPDX-License-Identifier: GPL-2.0-only
 /*
  * ROHM BD9571MWV-M GPIO driver
  *
  * Copyright (C) 2017 Marek Vasut 
  *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License version 2 as
- * published by the Free Software Foundation.
- *
- * This program is distributed "as is" WITHOUT ANY WARRANTY of any
- * kind, whether expressed or implied; without even the implied warranty
- * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License version 2 for more details.
- *
  * Based on the TPS65086 driver
  *
  * NOTE: Interrupts are not supported yet.
-- 
2.7.4



[PATCH v8 07/12] gpio: bd9571mwv: rid of using struct bd9571mwv

2020-12-25 Thread Yoshihiro Shimoda
To simplify this driver, use dev_get_regmap() and
rid of using struct bd9571mwv.

Signed-off-by: Yoshihiro Shimoda 
Reviewed-by: Matti Vaittinen 
---
 drivers/gpio/gpio-bd9571mwv.c | 19 +--
 1 file changed, 9 insertions(+), 10 deletions(-)

diff --git a/drivers/gpio/gpio-bd9571mwv.c b/drivers/gpio/gpio-bd9571mwv.c
index abb622c..0e5395f 100644
--- a/drivers/gpio/gpio-bd9571mwv.c
+++ b/drivers/gpio/gpio-bd9571mwv.c
@@ -16,8 +16,8 @@
 #include 
 
 struct bd9571mwv_gpio {
+   struct regmap *regmap;
struct gpio_chip chip;
-   struct bd9571mwv *bd;
 };
 
 static int bd9571mwv_gpio_get_direction(struct gpio_chip *chip,
@@ -26,7 +26,7 @@ static int bd9571mwv_gpio_get_direction(struct gpio_chip 
*chip,
struct bd9571mwv_gpio *gpio = gpiochip_get_data(chip);
int ret, val;
 
-   ret = regmap_read(gpio->bd->regmap, BD9571MWV_GPIO_DIR, );
+   ret = regmap_read(gpio->regmap, BD9571MWV_GPIO_DIR, );
if (ret < 0)
return ret;
if (val & BIT(offset))
@@ -40,8 +40,7 @@ static int bd9571mwv_gpio_direction_input(struct gpio_chip 
*chip,
 {
struct bd9571mwv_gpio *gpio = gpiochip_get_data(chip);
 
-   regmap_update_bits(gpio->bd->regmap, BD9571MWV_GPIO_DIR,
-  BIT(offset), 0);
+   regmap_update_bits(gpio->regmap, BD9571MWV_GPIO_DIR, BIT(offset), 0);
 
return 0;
 }
@@ -52,9 +51,9 @@ static int bd9571mwv_gpio_direction_output(struct gpio_chip 
*chip,
struct bd9571mwv_gpio *gpio = gpiochip_get_data(chip);
 
/* Set the initial value */
-   regmap_update_bits(gpio->bd->regmap, BD9571MWV_GPIO_OUT,
+   regmap_update_bits(gpio->regmap, BD9571MWV_GPIO_OUT,
   BIT(offset), value ? BIT(offset) : 0);
-   regmap_update_bits(gpio->bd->regmap, BD9571MWV_GPIO_DIR,
+   regmap_update_bits(gpio->regmap, BD9571MWV_GPIO_DIR,
   BIT(offset), BIT(offset));
 
return 0;
@@ -65,7 +64,7 @@ static int bd9571mwv_gpio_get(struct gpio_chip *chip, 
unsigned int offset)
struct bd9571mwv_gpio *gpio = gpiochip_get_data(chip);
int ret, val;
 
-   ret = regmap_read(gpio->bd->regmap, BD9571MWV_GPIO_IN, );
+   ret = regmap_read(gpio->regmap, BD9571MWV_GPIO_IN, );
if (ret < 0)
return ret;
 
@@ -77,7 +76,7 @@ static void bd9571mwv_gpio_set(struct gpio_chip *chip, 
unsigned int offset,
 {
struct bd9571mwv_gpio *gpio = gpiochip_get_data(chip);
 
-   regmap_update_bits(gpio->bd->regmap, BD9571MWV_GPIO_OUT,
+   regmap_update_bits(gpio->regmap, BD9571MWV_GPIO_OUT,
   BIT(offset), value ? BIT(offset) : 0);
 }
 
@@ -105,9 +104,9 @@ static int bd9571mwv_gpio_probe(struct platform_device 
*pdev)
 
platform_set_drvdata(pdev, gpio);
 
-   gpio->bd = dev_get_drvdata(pdev->dev.parent);
+   gpio->regmap = dev_get_regmap(pdev->dev.parent, NULL);
gpio->chip = template_chip;
-   gpio->chip.parent = gpio->bd->dev;
+   gpio->chip.parent = pdev->dev.parent;
 
ret = devm_gpiochip_add_data(>dev, >chip, gpio);
if (ret < 0) {
-- 
2.7.4



[PATCH v8 00/12] treewide: bd9571mwv: Add support for BD9574MWF

2020-12-25 Thread Yoshihiro Shimoda
Add BD9574MWF support into bd9571mwv gpio, mfd and regulator drivers.
Latest Ebisu-4D boards has this chip instead of BD9571MWV so that
we need this patch series to detect this chip at runtime.

Note that the patch [1/12] is a bug-fix patch for mfd driver.

Changes from v6:
 - Fix typo in the patch 10.
 - Add "Acked-for-MFD-by" in patch 2 and 11.
 https://patchwork.kernel.org/project/linux-renesas-soc/list/?series=406091

Changes from v6:
 - Remove "struct bd957x_ddata" because this is not used after probed.
 - Add "Acked-for-MFD-by" in patch 12.
 https://patchwork.kernel.org/project/linux-renesas-soc/list/?series=405725

Changes from v5:
 - Fix typo in the patch 5 and 8.
 https://patchwork.kernel.org/project/linux-renesas-soc/list/?series=405263

Changes from v4:
 - Add Reviwed-by in patch 1, 10, 11 and 12.
 - Keep bd9571mwv_id_table[] as-is because unused in patch 12.
 https://patchwork.kernel.org/project/linux-renesas-soc/list/?series=404657

Changes from v3:
 - Add "Acked-for-MFD-by" in patch 1, 3, 9 and 10.
 - Use "Co-developed-by" instead in patch 11.
 - In patch 11:
 -- Remove abusing kernel-doc formatting in patch.
 -- Rename bd957x_data with bd957x_ddata in patch.
 -- Remove product name printk.
 -- Rename bd9571mwv_identify() with bd957x_identify().
 -- Remove argument "part_name" from bd957x_identify().
 -- Modify dev_err() string.
 -- Rename BD9571MWV_PRODUCT_CODE_VAL with BD9571MWV_PRODUCT_CODE_BD9571MWV.
 -- Fix errno from -ENOENT to -ENODEV.
 - In patch 12:
 -- Rename "MFD driver" to "core driver".
 -- Remove unnecessary comments.
 -- Rename BD9574MWF_PRODUCT_CODE_VAL with BD9571MWV_PRODUCT_CODE_BD9574MWF.
 https://patchwork.kernel.org/project/linux-renesas-soc/list/?series=402719

Changes from v2:
 - Use devm_mfd_add_devices() to remove the mfd device in unload.
 - Update commit descriptions in patch 4 and 8.
 - Use regmap_get_device() to simplify in patch 4.
 - Remove "struct bd9571mwv" and bd9571mwv_remove().
 - Add Reviewed-by in patch 3 to 9.
 - Use devm_regmap_add_irq_chip() to simplify in patch 10.
 https://patchwork.kernel.org/project/linux-renesas-soc/list/?series=400477

Changes from v1:
 - Document BD9574MWF on the dt-binding.
 - Add ROHM_CHIP_TYPE_BD957[14] into rohm-generic.h.
 - To simplify gpio and regulator drivers, using regmap instead of
   using struct bd9571mwv.
 - Remove BD9574MWF definitions to make gpio and regulator driver
   simple to support for BD9574MWF.
 - Add BD9574MWF support for gpio and regulator drivers.
 - Add missing regmap ranges for BD9574MWF.
 - Rename "part_number" with "part_name".
 https://patchwork.kernel.org/project/linux-renesas-soc/list/?series=398059

Khiem Nguyen (2):
  mfd: bd9571mwv: Make the driver more generic
  mfd: bd9571mwv: Add support for BD9574MWF

Yoshihiro Shimoda (10):
  mfd: bd9571mwv: Use devm_mfd_add_devices()
  dt-bindings: mfd: bd9571mwv: Document BD9574MWF
  mfd: rohm-generic: Add BD9571 and BD9574
  regulator: bd9571mwv: rid of using struct bd9571mwv
  regulator: bd9571mwv: Add BD9574MWF support
  gpio: bd9571mwv: Use the SPDX license identifier
  gpio: bd9571mwv: rid of using struct bd9571mwv
  gpio: bd9571mwv: Add BD9574MWF support
  mfd: bd9571mwv: Use the SPDX license identifier
  mfd: bd9571mwv: Use devm_regmap_add_irq_chip()

 .../devicetree/bindings/mfd/bd9571mwv.txt  |   4 +-
 drivers/gpio/gpio-bd9571mwv.c  |  35 ++--
 drivers/mfd/bd9571mwv.c| 178 ++---
 drivers/regulator/bd9571mwv-regulator.c|  59 ---
 include/linux/mfd/bd9571mwv.h  |  45 ++
 include/linux/mfd/rohm-generic.h   |   2 +
 6 files changed, 186 insertions(+), 137 deletions(-)

-- 
2.7.4



[PATCH v8 01/12] mfd: bd9571mwv: Use devm_mfd_add_devices()

2020-12-25 Thread Yoshihiro Shimoda
To remove mfd devices when unload this driver, should use
devm_mfd_add_devices() instead.

Fixes: d3ea21272094 ("mfd: Add ROHM BD9571MWV-M MFD PMIC driver")
Signed-off-by: Yoshihiro Shimoda 
Acked-for-MFD-by: Lee Jones 
Reviewed-by: Geert Uytterhoeven 
Reviewed-by: Matti Vaittinen 
---
 drivers/mfd/bd9571mwv.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/mfd/bd9571mwv.c b/drivers/mfd/bd9571mwv.c
index fab3cdc..19d57a4 100644
--- a/drivers/mfd/bd9571mwv.c
+++ b/drivers/mfd/bd9571mwv.c
@@ -185,9 +185,9 @@ static int bd9571mwv_probe(struct i2c_client *client,
return ret;
}
 
-   ret = mfd_add_devices(bd->dev, PLATFORM_DEVID_AUTO, bd9571mwv_cells,
- ARRAY_SIZE(bd9571mwv_cells), NULL, 0,
- regmap_irq_get_domain(bd->irq_data));
+   ret = devm_mfd_add_devices(bd->dev, PLATFORM_DEVID_AUTO,
+  bd9571mwv_cells, ARRAY_SIZE(bd9571mwv_cells),
+  NULL, 0, 
regmap_irq_get_domain(bd->irq_data));
if (ret) {
regmap_del_irq_chip(bd->irq, bd->irq_data);
return ret;
-- 
2.7.4



RE: [PATCH v7 10/12] mfd: bd9571mwv: Use devm_regmap_add_irq_chip()

2020-12-25 Thread Yoshihiro Shimoda
Hello Sergei,

> From: Sergei Shtylyov, Sent: Thursday, December 24, 2020 5:50 PM
> On 24.12.2020 10:04, Yoshihiro Shimoda wrote:
> 
> > Use dev_regmap_add_irq_chip() to simplify the code.
> 
> devm_?

Thank you for the pointed it out.
I'll fix it.

Best regards,
Yoshihiro Shimoda



RE: [PATCH v6 11/12] mfd: bd9571mwv: Make the driver more generic

2020-12-24 Thread Yoshihiro Shimoda
Hi Lee,

> From: Lee Jones, Sent: Thursday, December 24, 2020 4:34 PM
> > Hi Lee,
> >
> > > From: Lee Jones, Sent: Thursday, December 24, 2020 12:39 AM
> > > On Wed, 23 Dec 2020, Yoshihiro Shimoda wrote:
> > > > From: Khiem Nguyen 

> > > > +   switch (ret) {
> > > > +   case BD9571MWV_PRODUCT_CODE_BD9571MWV:
> > > > +   ddata = _ddata;
> > >
> > > Simply declare 'const struct mfd_cell *cells' locally in probe and
> > > assign it here instead.
> >
> > I got it. I'll also add "const struct regmap_config *regmap_config;"
> > and "const struct regmap_irq_chip *irq_chip;" locally in probe.
> 
> If you only use them there, then yes, that's correct.

Thank you for the reply. Yes, I only use them there.
So, I have submitted v7 patches which have such implementation.

Best regards,
Yoshihiro Shimoda



[PATCH v7 01/12] mfd: bd9571mwv: Use devm_mfd_add_devices()

2020-12-23 Thread Yoshihiro Shimoda
To remove mfd devices when unload this driver, should use
devm_mfd_add_devices() instead.

Fixes: d3ea21272094 ("mfd: Add ROHM BD9571MWV-M MFD PMIC driver")
Signed-off-by: Yoshihiro Shimoda 
Acked-for-MFD-by: Lee Jones 
Reviewed-by: Geert Uytterhoeven 
Reviewed-by: Matti Vaittinen 
---
 drivers/mfd/bd9571mwv.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/mfd/bd9571mwv.c b/drivers/mfd/bd9571mwv.c
index fab3cdc..19d57a4 100644
--- a/drivers/mfd/bd9571mwv.c
+++ b/drivers/mfd/bd9571mwv.c
@@ -185,9 +185,9 @@ static int bd9571mwv_probe(struct i2c_client *client,
return ret;
}
 
-   ret = mfd_add_devices(bd->dev, PLATFORM_DEVID_AUTO, bd9571mwv_cells,
- ARRAY_SIZE(bd9571mwv_cells), NULL, 0,
- regmap_irq_get_domain(bd->irq_data));
+   ret = devm_mfd_add_devices(bd->dev, PLATFORM_DEVID_AUTO,
+  bd9571mwv_cells, ARRAY_SIZE(bd9571mwv_cells),
+  NULL, 0, 
regmap_irq_get_domain(bd->irq_data));
if (ret) {
regmap_del_irq_chip(bd->irq, bd->irq_data);
return ret;
-- 
2.7.4



[PATCH v7 03/12] mfd: rohm-generic: Add BD9571 and BD9574

2020-12-23 Thread Yoshihiro Shimoda
Add chip IDs for BD9571MWV and BD9574MWF.

Signed-off-by: Yoshihiro Shimoda 
Reviewed-by: Matti Vaittinen 
Acked-for-MFD-by: Lee Jones 
---
 include/linux/mfd/rohm-generic.h | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/include/linux/mfd/rohm-generic.h b/include/linux/mfd/rohm-generic.h
index 4283b5b..affacf8 100644
--- a/include/linux/mfd/rohm-generic.h
+++ b/include/linux/mfd/rohm-generic.h
@@ -12,6 +12,8 @@ enum rohm_chip_type {
ROHM_CHIP_TYPE_BD71847,
ROHM_CHIP_TYPE_BD70528,
ROHM_CHIP_TYPE_BD71828,
+   ROHM_CHIP_TYPE_BD9571,
+   ROHM_CHIP_TYPE_BD9574,
ROHM_CHIP_TYPE_AMOUNT
 };
 
-- 
2.7.4



[PATCH v7 04/12] regulator: bd9571mwv: rid of using struct bd9571mwv

2020-12-23 Thread Yoshihiro Shimoda
To simplify this driver, use dev_get_regmap() and
rid of using struct bd9571mwv.

Signed-off-by: Yoshihiro Shimoda 
Reviewed-by: Matti Vaittinen 
---
 drivers/regulator/bd9571mwv-regulator.c | 49 +
 1 file changed, 26 insertions(+), 23 deletions(-)

diff --git a/drivers/regulator/bd9571mwv-regulator.c 
b/drivers/regulator/bd9571mwv-regulator.c
index e690c2c..42b6a70 100644
--- a/drivers/regulator/bd9571mwv-regulator.c
+++ b/drivers/regulator/bd9571mwv-regulator.c
@@ -17,7 +17,7 @@
 #include 
 
 struct bd9571mwv_reg {
-   struct bd9571mwv *bd;
+   struct regmap *regmap;
 
/* DDR Backup Power */
u8 bkup_mode_cnt_keepon;/* from "rohm,ddr-backup-power" */
@@ -137,26 +137,30 @@ static const struct regulator_desc regulators[] = {
 };
 
 #ifdef CONFIG_PM_SLEEP
-static int bd9571mwv_bkup_mode_read(struct bd9571mwv *bd, unsigned int *mode)
+static int bd9571mwv_bkup_mode_read(struct bd9571mwv_reg *bdreg,
+   unsigned int *mode)
 {
int ret;
 
-   ret = regmap_read(bd->regmap, BD9571MWV_BKUP_MODE_CNT, mode);
+   ret = regmap_read(bdreg->regmap, BD9571MWV_BKUP_MODE_CNT, mode);
if (ret) {
-   dev_err(bd->dev, "failed to read backup mode (%d)\n", ret);
+   dev_err(regmap_get_device(bdreg->regmap),
+   "failed to read backup mode (%d)\n", ret);
return ret;
}
 
return 0;
 }
 
-static int bd9571mwv_bkup_mode_write(struct bd9571mwv *bd, unsigned int mode)
+static int bd9571mwv_bkup_mode_write(struct bd9571mwv_reg *bdreg,
+unsigned int mode)
 {
int ret;
 
-   ret = regmap_write(bd->regmap, BD9571MWV_BKUP_MODE_CNT, mode);
+   ret = regmap_write(bdreg->regmap, BD9571MWV_BKUP_MODE_CNT, mode);
if (ret) {
-   dev_err(bd->dev, "failed to configure backup mode 0x%x (%d)\n",
+   dev_err(regmap_get_device(bdreg->regmap),
+   "failed to configure backup mode 0x%x (%d)\n",
mode, ret);
return ret;
}
@@ -194,7 +198,7 @@ static ssize_t backup_mode_store(struct device *dev,
 * Configure DDR Backup Mode, to change the role of the accessory power
 * switch from a power switch to a wake-up switch, or vice versa
 */
-   ret = bd9571mwv_bkup_mode_read(bdreg->bd, );
+   ret = bd9571mwv_bkup_mode_read(bdreg, );
if (ret)
return ret;
 
@@ -202,7 +206,7 @@ static ssize_t backup_mode_store(struct device *dev,
if (bdreg->bkup_mode_enabled)
mode |= bdreg->bkup_mode_cnt_keepon;
 
-   ret = bd9571mwv_bkup_mode_write(bdreg->bd, mode);
+   ret = bd9571mwv_bkup_mode_write(bdreg, mode);
if (ret)
return ret;
 
@@ -221,7 +225,7 @@ static int bd9571mwv_suspend(struct device *dev)
return 0;
 
/* Save DDR Backup Mode */
-   ret = bd9571mwv_bkup_mode_read(bdreg->bd, );
+   ret = bd9571mwv_bkup_mode_read(bdreg, );
if (ret)
return ret;
 
@@ -235,7 +239,7 @@ static int bd9571mwv_suspend(struct device *dev)
mode |= bdreg->bkup_mode_cnt_keepon;
 
if (mode != bdreg->bkup_mode_cnt_saved)
-   return bd9571mwv_bkup_mode_write(bdreg->bd, mode);
+   return bd9571mwv_bkup_mode_write(bdreg, mode);
 
return 0;
 }
@@ -248,7 +252,7 @@ static int bd9571mwv_resume(struct device *dev)
return 0;
 
/* Restore DDR Backup Mode */
-   return bd9571mwv_bkup_mode_write(bdreg->bd, bdreg->bkup_mode_cnt_saved);
+   return bd9571mwv_bkup_mode_write(bdreg, bdreg->bkup_mode_cnt_saved);
 }
 
 static const struct dev_pm_ops bd9571mwv_pm  = {
@@ -268,7 +272,6 @@ static int bd9571mwv_regulator_remove(struct 
platform_device *pdev)
 
 static int bd9571mwv_regulator_probe(struct platform_device *pdev)
 {
-   struct bd9571mwv *bd = dev_get_drvdata(pdev->dev.parent);
struct regulator_config config = { };
struct bd9571mwv_reg *bdreg;
struct regulator_dev *rdev;
@@ -279,40 +282,40 @@ static int bd9571mwv_regulator_probe(struct 
platform_device *pdev)
if (!bdreg)
return -ENOMEM;
 
-   bdreg->bd = bd;
+   bdreg->regmap = dev_get_regmap(pdev->dev.parent, NULL);
 
platform_set_drvdata(pdev, bdreg);
 
config.dev = >dev;
-   config.dev->of_node = bd->dev->of_node;
-   config.driver_data = bd;
-   config.regmap = bd->regmap;
+   config.dev->of_node = pdev->dev.parent->of_node;
+   config.driver_data = bdreg;
+   config.regmap = bdreg->regmap;
 
for (i = 0; i < ARRAY_SIZE(regulators); i++) {
rdev = devm_regulator_register(>dev, [i],
 

[PATCH v7 07/12] gpio: bd9571mwv: rid of using struct bd9571mwv

2020-12-23 Thread Yoshihiro Shimoda
To simplify this driver, use dev_get_regmap() and
rid of using struct bd9571mwv.

Signed-off-by: Yoshihiro Shimoda 
Reviewed-by: Matti Vaittinen 
---
 drivers/gpio/gpio-bd9571mwv.c | 19 +--
 1 file changed, 9 insertions(+), 10 deletions(-)

diff --git a/drivers/gpio/gpio-bd9571mwv.c b/drivers/gpio/gpio-bd9571mwv.c
index abb622c..0e5395f 100644
--- a/drivers/gpio/gpio-bd9571mwv.c
+++ b/drivers/gpio/gpio-bd9571mwv.c
@@ -16,8 +16,8 @@
 #include 
 
 struct bd9571mwv_gpio {
+   struct regmap *regmap;
struct gpio_chip chip;
-   struct bd9571mwv *bd;
 };
 
 static int bd9571mwv_gpio_get_direction(struct gpio_chip *chip,
@@ -26,7 +26,7 @@ static int bd9571mwv_gpio_get_direction(struct gpio_chip 
*chip,
struct bd9571mwv_gpio *gpio = gpiochip_get_data(chip);
int ret, val;
 
-   ret = regmap_read(gpio->bd->regmap, BD9571MWV_GPIO_DIR, );
+   ret = regmap_read(gpio->regmap, BD9571MWV_GPIO_DIR, );
if (ret < 0)
return ret;
if (val & BIT(offset))
@@ -40,8 +40,7 @@ static int bd9571mwv_gpio_direction_input(struct gpio_chip 
*chip,
 {
struct bd9571mwv_gpio *gpio = gpiochip_get_data(chip);
 
-   regmap_update_bits(gpio->bd->regmap, BD9571MWV_GPIO_DIR,
-  BIT(offset), 0);
+   regmap_update_bits(gpio->regmap, BD9571MWV_GPIO_DIR, BIT(offset), 0);
 
return 0;
 }
@@ -52,9 +51,9 @@ static int bd9571mwv_gpio_direction_output(struct gpio_chip 
*chip,
struct bd9571mwv_gpio *gpio = gpiochip_get_data(chip);
 
/* Set the initial value */
-   regmap_update_bits(gpio->bd->regmap, BD9571MWV_GPIO_OUT,
+   regmap_update_bits(gpio->regmap, BD9571MWV_GPIO_OUT,
   BIT(offset), value ? BIT(offset) : 0);
-   regmap_update_bits(gpio->bd->regmap, BD9571MWV_GPIO_DIR,
+   regmap_update_bits(gpio->regmap, BD9571MWV_GPIO_DIR,
   BIT(offset), BIT(offset));
 
return 0;
@@ -65,7 +64,7 @@ static int bd9571mwv_gpio_get(struct gpio_chip *chip, 
unsigned int offset)
struct bd9571mwv_gpio *gpio = gpiochip_get_data(chip);
int ret, val;
 
-   ret = regmap_read(gpio->bd->regmap, BD9571MWV_GPIO_IN, );
+   ret = regmap_read(gpio->regmap, BD9571MWV_GPIO_IN, );
if (ret < 0)
return ret;
 
@@ -77,7 +76,7 @@ static void bd9571mwv_gpio_set(struct gpio_chip *chip, 
unsigned int offset,
 {
struct bd9571mwv_gpio *gpio = gpiochip_get_data(chip);
 
-   regmap_update_bits(gpio->bd->regmap, BD9571MWV_GPIO_OUT,
+   regmap_update_bits(gpio->regmap, BD9571MWV_GPIO_OUT,
   BIT(offset), value ? BIT(offset) : 0);
 }
 
@@ -105,9 +104,9 @@ static int bd9571mwv_gpio_probe(struct platform_device 
*pdev)
 
platform_set_drvdata(pdev, gpio);
 
-   gpio->bd = dev_get_drvdata(pdev->dev.parent);
+   gpio->regmap = dev_get_regmap(pdev->dev.parent, NULL);
gpio->chip = template_chip;
-   gpio->chip.parent = gpio->bd->dev;
+   gpio->chip.parent = pdev->dev.parent;
 
ret = devm_gpiochip_add_data(>dev, >chip, gpio);
if (ret < 0) {
-- 
2.7.4



[PATCH v7 08/12] gpio: bd9571mwv: Add BD9574MWF support

2020-12-23 Thread Yoshihiro Shimoda
Add support for BD9574MWF which is similar chip with BD9571MWV.
Note that BD9574MWF has additional features "RECOV_GPOUT",
"FREQSEL" and "RTC_IN", but supports GPIO function only.

Signed-off-by: Yoshihiro Shimoda 
Reviewed-by: Matti Vaittinen 
---
 drivers/gpio/gpio-bd9571mwv.c | 6 --
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/drivers/gpio/gpio-bd9571mwv.c b/drivers/gpio/gpio-bd9571mwv.c
index 0e5395f..df6102b 100644
--- a/drivers/gpio/gpio-bd9571mwv.c
+++ b/drivers/gpio/gpio-bd9571mwv.c
@@ -1,6 +1,6 @@
 // SPDX-License-Identifier: GPL-2.0-only
 /*
- * ROHM BD9571MWV-M GPIO driver
+ * ROHM BD9571MWV-M and BD9574MWF-M GPIO driver
  *
  * Copyright (C) 2017 Marek Vasut 
  *
@@ -10,6 +10,7 @@
  */
 
 #include 
+#include 
 #include 
 #include 
 
@@ -118,7 +119,8 @@ static int bd9571mwv_gpio_probe(struct platform_device 
*pdev)
 }
 
 static const struct platform_device_id bd9571mwv_gpio_id_table[] = {
-   { "bd9571mwv-gpio", },
+   { "bd9571mwv-gpio", ROHM_CHIP_TYPE_BD9571 },
+   { "bd9574mwf-gpio", ROHM_CHIP_TYPE_BD9574 },
{ /* sentinel */ }
 };
 MODULE_DEVICE_TABLE(platform, bd9571mwv_gpio_id_table);
-- 
2.7.4



[PATCH v7 12/12] mfd: bd9571mwv: Add support for BD9574MWF

2020-12-23 Thread Yoshihiro Shimoda
From: Khiem Nguyen 

The new PMIC BD9574MWF inherits features from BD9571MWV.
Add the support of new PMIC to existing bd9571mwv driver.

Signed-off-by: Khiem Nguyen 
Co-developed-by: Yoshihiro Shimoda 
Signed-off-by: Yoshihiro Shimoda 
Reviewed-by: Matti Vaittinen 
Acked-for-MFD-by: Lee Jones 
---
 drivers/mfd/bd9571mwv.c   | 76 ++-
 include/linux/mfd/bd9571mwv.h | 17 --
 2 files changed, 89 insertions(+), 4 deletions(-)

diff --git a/drivers/mfd/bd9571mwv.c b/drivers/mfd/bd9571mwv.c
index 2c1fcbb..e15b1ac 100644
--- a/drivers/mfd/bd9571mwv.c
+++ b/drivers/mfd/bd9571mwv.c
@@ -1,6 +1,6 @@
 // SPDX-License-Identifier: GPL-2.0-only
 /*
- * ROHM BD9571MWV-M MFD driver
+ * ROHM BD9571MWV-M and BD9574MVF-M core driver
  *
  * Copyright (C) 2017 Marek Vasut 
  * Copyright (C) 2020 Renesas Electronics Corporation
@@ -11,6 +11,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 
 #include 
@@ -103,6 +104,72 @@ static struct regmap_irq_chip bd9571mwv_irq_chip = {
.num_irqs   = ARRAY_SIZE(bd9571mwv_irqs),
 };
 
+static const struct mfd_cell bd9574mwf_cells[] = {
+   { .name = "bd9574mwf-regulator", },
+   { .name = "bd9574mwf-gpio", },
+};
+
+static const struct regmap_range bd9574mwf_readable_yes_ranges[] = {
+   regmap_reg_range(BD9571MWV_VENDOR_CODE, BD9571MWV_PRODUCT_REVISION),
+   regmap_reg_range(BD9571MWV_BKUP_MODE_CNT, BD9571MWV_BKUP_MODE_CNT),
+   regmap_reg_range(BD9571MWV_DVFS_VINIT, BD9571MWV_DVFS_SETVMAX),
+   regmap_reg_range(BD9571MWV_DVFS_SETVID, BD9571MWV_DVFS_MONIVDAC),
+   regmap_reg_range(BD9571MWV_GPIO_IN, BD9571MWV_GPIO_IN),
+   regmap_reg_range(BD9571MWV_GPIO_INT, BD9571MWV_GPIO_INTMASK),
+   regmap_reg_range(BD9571MWV_INT_INTREQ, BD9571MWV_INT_INTMASK),
+};
+
+static const struct regmap_access_table bd9574mwf_readable_table = {
+   .yes_ranges = bd9574mwf_readable_yes_ranges,
+   .n_yes_ranges   = ARRAY_SIZE(bd9574mwf_readable_yes_ranges),
+};
+
+static const struct regmap_range bd9574mwf_writable_yes_ranges[] = {
+   regmap_reg_range(BD9571MWV_BKUP_MODE_CNT, BD9571MWV_BKUP_MODE_CNT),
+   regmap_reg_range(BD9571MWV_DVFS_SETVID, BD9571MWV_DVFS_SETVID),
+   regmap_reg_range(BD9571MWV_GPIO_DIR, BD9571MWV_GPIO_OUT),
+   regmap_reg_range(BD9571MWV_GPIO_INT_SET, BD9571MWV_GPIO_INTMASK),
+   regmap_reg_range(BD9571MWV_INT_INTREQ, BD9571MWV_INT_INTMASK),
+};
+
+static const struct regmap_access_table bd9574mwf_writable_table = {
+   .yes_ranges = bd9574mwf_writable_yes_ranges,
+   .n_yes_ranges   = ARRAY_SIZE(bd9574mwf_writable_yes_ranges),
+};
+
+static const struct regmap_range bd9574mwf_volatile_yes_ranges[] = {
+   regmap_reg_range(BD9571MWV_DVFS_MONIVDAC, BD9571MWV_DVFS_MONIVDAC),
+   regmap_reg_range(BD9571MWV_GPIO_IN, BD9571MWV_GPIO_IN),
+   regmap_reg_range(BD9571MWV_GPIO_INT, BD9571MWV_GPIO_INT),
+   regmap_reg_range(BD9571MWV_INT_INTREQ, BD9571MWV_INT_INTREQ),
+};
+
+static const struct regmap_access_table bd9574mwf_volatile_table = {
+   .yes_ranges = bd9574mwf_volatile_yes_ranges,
+   .n_yes_ranges   = ARRAY_SIZE(bd9574mwf_volatile_yes_ranges),
+};
+
+static const struct regmap_config bd9574mwf_regmap_config = {
+   .reg_bits   = 8,
+   .val_bits   = 8,
+   .cache_type = REGCACHE_RBTREE,
+   .rd_table   = _readable_table,
+   .wr_table   = _writable_table,
+   .volatile_table = _volatile_table,
+   .max_register   = 0xff,
+};
+
+static struct regmap_irq_chip bd9574mwf_irq_chip = {
+   .name   = "bd9574mwf",
+   .status_base= BD9571MWV_INT_INTREQ,
+   .mask_base  = BD9571MWV_INT_INTMASK,
+   .ack_base   = BD9571MWV_INT_INTREQ,
+   .init_ack_masked = true,
+   .num_regs   = 1,
+   .irqs   = bd9571mwv_irqs,
+   .num_irqs   = ARRAY_SIZE(bd9571mwv_irqs),
+};
+
 static int bd957x_identify(struct device *dev, struct regmap *regmap)
 {
unsigned int value;
@@ -162,6 +229,12 @@ static int bd9571mwv_probe(struct i2c_client *client,
cells = bd9571mwv_cells;
num_cells = ARRAY_SIZE(bd9571mwv_cells);
break;
+   case BD9571MWV_PRODUCT_CODE_BD9574MWF:
+   regmap_config = _regmap_config;
+   irq_chip = _irq_chip;
+   cells = bd9574mwf_cells;
+   num_cells = ARRAY_SIZE(bd9574mwf_cells);
+   break;
default:
dev_err(dev, "Unsupported device 0x%x\n", ret);
return -ENODEV;
@@ -190,6 +263,7 @@ static int bd9571mwv_probe(struct i2c_client *client,
 
 static const struct of_device_id bd9571mwv_of_match_table[] = {
{ .compatible = "rohm,bd9571mwv", },
+   { .compatible = "rohm,bd9574mwf", },
{ /* sentinel */ }
 };
 MODULE_DEVICE_TABLE(of, bd9571mwv_of_match_table);
diff --git a/include

[PATCH v7 10/12] mfd: bd9571mwv: Use devm_regmap_add_irq_chip()

2020-12-23 Thread Yoshihiro Shimoda
Use dev_regmap_add_irq_chip() to simplify the code.

Signed-off-by: Yoshihiro Shimoda 
Acked-for-MFD-by: Lee Jones 
Reviewed-by: Matti Vaittinen 
Reviewed-by: Geert Uytterhoeven 
---
 drivers/mfd/bd9571mwv.c | 27 ++-
 1 file changed, 6 insertions(+), 21 deletions(-)

diff --git a/drivers/mfd/bd9571mwv.c b/drivers/mfd/bd9571mwv.c
index e68c3fa..49e968e 100644
--- a/drivers/mfd/bd9571mwv.c
+++ b/drivers/mfd/bd9571mwv.c
@@ -170,31 +170,17 @@ static int bd9571mwv_probe(struct i2c_client *client,
if (ret)
return ret;
 
-   ret = regmap_add_irq_chip(bd->regmap, bd->irq, IRQF_ONESHOT, 0,
- _irq_chip, >irq_data);
+   ret = devm_regmap_add_irq_chip(bd->dev, bd->regmap, bd->irq,
+  IRQF_ONESHOT, 0, _irq_chip,
+  >irq_data);
if (ret) {
dev_err(bd->dev, "Failed to register IRQ chip\n");
return ret;
}
 
-   ret = devm_mfd_add_devices(bd->dev, PLATFORM_DEVID_AUTO,
-  bd9571mwv_cells, ARRAY_SIZE(bd9571mwv_cells),
-  NULL, 0, 
regmap_irq_get_domain(bd->irq_data));
-   if (ret) {
-   regmap_del_irq_chip(bd->irq, bd->irq_data);
-   return ret;
-   }
-
-   return 0;
-}
-
-static int bd9571mwv_remove(struct i2c_client *client)
-{
-   struct bd9571mwv *bd = i2c_get_clientdata(client);
-
-   regmap_del_irq_chip(bd->irq, bd->irq_data);
-
-   return 0;
+   return devm_mfd_add_devices(bd->dev, PLATFORM_DEVID_AUTO,
+   bd9571mwv_cells, 
ARRAY_SIZE(bd9571mwv_cells),
+   NULL, 0, 
regmap_irq_get_domain(bd->irq_data));
 }
 
 static const struct of_device_id bd9571mwv_of_match_table[] = {
@@ -215,7 +201,6 @@ static struct i2c_driver bd9571mwv_driver = {
.of_match_table = bd9571mwv_of_match_table,
},
.probe  = bd9571mwv_probe,
-   .remove = bd9571mwv_remove,
.id_table   = bd9571mwv_id_table,
 };
 module_i2c_driver(bd9571mwv_driver);
-- 
2.7.4



[PATCH v7 11/12] mfd: bd9571mwv: Make the driver more generic

2020-12-23 Thread Yoshihiro Shimoda
From: Khiem Nguyen 

Since the driver supports BD9571MWV PMIC only, this patch makes
the functions and data structure become more generic so that
it can support other PMIC variants as well. Also remove printing
part name which Lee Jones suggested.

Signed-off-by: Khiem Nguyen 
Co-developed-by: Yoshihiro Shimoda 
Signed-off-by: Yoshihiro Shimoda 
Reviewed-by: Matti Vaittinen 
---
 drivers/mfd/bd9571mwv.c   | 77 +++
 include/linux/mfd/bd9571mwv.h | 18 ++
 2 files changed, 43 insertions(+), 52 deletions(-)

diff --git a/drivers/mfd/bd9571mwv.c b/drivers/mfd/bd9571mwv.c
index 49e968e..2c1fcbb 100644
--- a/drivers/mfd/bd9571mwv.c
+++ b/drivers/mfd/bd9571mwv.c
@@ -3,6 +3,7 @@
  * ROHM BD9571MWV-M MFD driver
  *
  * Copyright (C) 2017 Marek Vasut 
+ * Copyright (C) 2020 Renesas Electronics Corporation
  *
  * Based on the TPS65086 driver
  */
@@ -102,13 +103,12 @@ static struct regmap_irq_chip bd9571mwv_irq_chip = {
.num_irqs   = ARRAY_SIZE(bd9571mwv_irqs),
 };
 
-static int bd9571mwv_identify(struct bd9571mwv *bd)
+static int bd957x_identify(struct device *dev, struct regmap *regmap)
 {
-   struct device *dev = bd->dev;
unsigned int value;
int ret;
 
-   ret = regmap_read(bd->regmap, BD9571MWV_VENDOR_CODE, );
+   ret = regmap_read(regmap, BD9571MWV_VENDOR_CODE, );
if (ret) {
dev_err(dev, "Failed to read vendor code register (ret=%i)\n",
ret);
@@ -121,66 +121,71 @@ static int bd9571mwv_identify(struct bd9571mwv *bd)
return -EINVAL;
}
 
-   ret = regmap_read(bd->regmap, BD9571MWV_PRODUCT_CODE, );
+   ret = regmap_read(regmap, BD9571MWV_PRODUCT_CODE, );
if (ret) {
dev_err(dev, "Failed to read product code register (ret=%i)\n",
ret);
return ret;
}
-
-   if (value != BD9571MWV_PRODUCT_CODE_VAL) {
-   dev_err(dev, "Invalid product code ID %02x (expected %02x)\n",
-   value, BD9571MWV_PRODUCT_CODE_VAL);
-   return -EINVAL;
-   }
-
-   ret = regmap_read(bd->regmap, BD9571MWV_PRODUCT_REVISION, );
+   ret = regmap_read(regmap, BD9571MWV_PRODUCT_REVISION, );
if (ret) {
dev_err(dev, "Failed to read revision register (ret=%i)\n",
ret);
return ret;
}
 
-   dev_info(dev, "Device: BD9571MWV rev. %d\n", value & 0xff);
-
return 0;
 }
 
 static int bd9571mwv_probe(struct i2c_client *client,
- const struct i2c_device_id *ids)
+  const struct i2c_device_id *ids)
 {
-   struct bd9571mwv *bd;
-   int ret;
-
-   bd = devm_kzalloc(>dev, sizeof(*bd), GFP_KERNEL);
-   if (!bd)
-   return -ENOMEM;
+   const struct regmap_config *regmap_config;
+   const struct regmap_irq_chip *irq_chip;
+   const struct mfd_cell *cells;
+   struct device *dev = >dev;
+   struct regmap *regmap;
+   struct regmap_irq_chip_data *irq_data;
+   int ret, num_cells, irq = client->irq;
+
+   /* Read the PMIC product code */
+   ret = i2c_smbus_read_byte_data(client, BD9571MWV_PRODUCT_CODE);
+   if (ret < 0) {
+   dev_err(dev, "Failed to read product code\n");
+   return ret;
+   }
 
-   i2c_set_clientdata(client, bd);
-   bd->dev = >dev;
-   bd->irq = client->irq;
+   switch (ret) {
+   case BD9571MWV_PRODUCT_CODE_BD9571MWV:
+   regmap_config = _regmap_config;
+   irq_chip = _irq_chip;
+   cells = bd9571mwv_cells;
+   num_cells = ARRAY_SIZE(bd9571mwv_cells);
+   break;
+   default:
+   dev_err(dev, "Unsupported device 0x%x\n", ret);
+   return -ENODEV;
+   }
 
-   bd->regmap = devm_regmap_init_i2c(client, _regmap_config);
-   if (IS_ERR(bd->regmap)) {
-   dev_err(bd->dev, "Failed to initialize register map\n");
-   return PTR_ERR(bd->regmap);
+   regmap = devm_regmap_init_i2c(client, regmap_config);
+   if (IS_ERR(regmap)) {
+   dev_err(dev, "Failed to initialize register map\n");
+   return PTR_ERR(regmap);
}
 
-   ret = bd9571mwv_identify(bd);
+   ret = bd957x_identify(dev, regmap);
if (ret)
return ret;
 
-   ret = devm_regmap_add_irq_chip(bd->dev, bd->regmap, bd->irq,
-  IRQF_ONESHOT, 0, _irq_chip,
-  >irq_data);
+   ret = devm_regmap_add_irq_chip(dev, regmap, irq, IRQF_ONESHOT, 0,
+  irq_chip, _data);
if (ret) {
-   dev_err(bd->

[PATCH v7 09/12] mfd: bd9571mwv: Use the SPDX license identifier

2020-12-23 Thread Yoshihiro Shimoda
Use the SPDX license identifier instead of a local description.

Signed-off-by: Yoshihiro Shimoda 
Reviewed-by: Geert Uytterhoeven 
Acked-for-MFD-by: Lee Jones 
---
 drivers/mfd/bd9571mwv.c   | 10 +-
 include/linux/mfd/bd9571mwv.h | 10 +-
 2 files changed, 2 insertions(+), 18 deletions(-)

diff --git a/drivers/mfd/bd9571mwv.c b/drivers/mfd/bd9571mwv.c
index 19d57a4..e68c3fa 100644
--- a/drivers/mfd/bd9571mwv.c
+++ b/drivers/mfd/bd9571mwv.c
@@ -1,17 +1,9 @@
+// SPDX-License-Identifier: GPL-2.0-only
 /*
  * ROHM BD9571MWV-M MFD driver
  *
  * Copyright (C) 2017 Marek Vasut 
  *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License version 2 as
- * published by the Free Software Foundation.
- *
- * This program is distributed "as is" WITHOUT ANY WARRANTY of any
- * kind, whether expressed or implied; without even the implied warranty
- * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License version 2 for more details.
- *
  * Based on the TPS65086 driver
  */
 
diff --git a/include/linux/mfd/bd9571mwv.h b/include/linux/mfd/bd9571mwv.h
index eb05569..bcc7092 100644
--- a/include/linux/mfd/bd9571mwv.h
+++ b/include/linux/mfd/bd9571mwv.h
@@ -1,17 +1,9 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
 /*
  * ROHM BD9571MWV-M driver
  *
  * Copyright (C) 2017 Marek Vasut 
  *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License version 2 as
- * published by the Free Software Foundation.
- *
- * This program is distributed "as is" WITHOUT ANY WARRANTY of any
- * kind, whether expressed or implied; without even the implied warranty
- * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License version 2 for more details.
- *
  * Based on the TPS65086 driver
  */
 
-- 
2.7.4



[PATCH v7 02/12] dt-bindings: mfd: bd9571mwv: Document BD9574MWF

2020-12-23 Thread Yoshihiro Shimoda
Document other similar specification chip BD9574MWF.

Signed-off-by: Yoshihiro Shimoda 
---
 Documentation/devicetree/bindings/mfd/bd9571mwv.txt | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/Documentation/devicetree/bindings/mfd/bd9571mwv.txt 
b/Documentation/devicetree/bindings/mfd/bd9571mwv.txt
index 8c46786..1d6413e 100644
--- a/Documentation/devicetree/bindings/mfd/bd9571mwv.txt
+++ b/Documentation/devicetree/bindings/mfd/bd9571mwv.txt
@@ -1,7 +1,7 @@
-* ROHM BD9571MWV Power Management Integrated Circuit (PMIC) bindings
+* ROHM BD9571MWV/BD9574MWF Power Management Integrated Circuit (PMIC) bindings
 
 Required properties:
- - compatible  : Should be "rohm,bd9571mwv".
+ - compatible  : Should be "rohm,bd9571mwv" or "rohm,bd9574mwf".
  - reg : I2C slave address.
  - interrupts  : The interrupt line the device is connected to.
  - interrupt-controller: Marks the device node as an interrupt 
controller.
-- 
2.7.4



[PATCH v7 06/12] gpio: bd9571mwv: Use the SPDX license identifier

2020-12-23 Thread Yoshihiro Shimoda
Use the SPDX license identifier instead of a local description.

Signed-off-by: Yoshihiro Shimoda 
Reviewed-by: Geert Uytterhoeven 
---
 drivers/gpio/gpio-bd9571mwv.c | 10 +-
 1 file changed, 1 insertion(+), 9 deletions(-)

diff --git a/drivers/gpio/gpio-bd9571mwv.c b/drivers/gpio/gpio-bd9571mwv.c
index c0abc9c..abb622c 100644
--- a/drivers/gpio/gpio-bd9571mwv.c
+++ b/drivers/gpio/gpio-bd9571mwv.c
@@ -1,17 +1,9 @@
+// SPDX-License-Identifier: GPL-2.0-only
 /*
  * ROHM BD9571MWV-M GPIO driver
  *
  * Copyright (C) 2017 Marek Vasut 
  *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License version 2 as
- * published by the Free Software Foundation.
- *
- * This program is distributed "as is" WITHOUT ANY WARRANTY of any
- * kind, whether expressed or implied; without even the implied warranty
- * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License version 2 for more details.
- *
  * Based on the TPS65086 driver
  *
  * NOTE: Interrupts are not supported yet.
-- 
2.7.4



[PATCH v7 05/12] regulator: bd9571mwv: Add BD9574MWF support

2020-12-23 Thread Yoshihiro Shimoda
Add support for BD9574MWF which is similar chip with BD9571MWV.
Note that we don't support voltage rails VD{09,18,25,33} by this
driver on BD9574. The VD09 voltage could be read from PMIC but that
is not supported by this commit.

Signed-off-by: Yoshihiro Shimoda 
Reviewed-by: Matti Vaittinen 
---
 drivers/regulator/bd9571mwv-regulator.c | 10 --
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/drivers/regulator/bd9571mwv-regulator.c 
b/drivers/regulator/bd9571mwv-regulator.c
index 42b6a70..7b0cd08 100644
--- a/drivers/regulator/bd9571mwv-regulator.c
+++ b/drivers/regulator/bd9571mwv-regulator.c
@@ -1,6 +1,6 @@
 // SPDX-License-Identifier: GPL-2.0
 /*
- * ROHM BD9571MWV-M regulator driver
+ * ROHM BD9571MWV-M and BD9574MWF-M regulator driver
  *
  * Copyright (C) 2017 Marek Vasut 
  *
@@ -9,6 +9,7 @@
  * NOTE: VD09 is missing
  */
 
+#include 
 #include 
 #include 
 #include 
@@ -277,6 +278,7 @@ static int bd9571mwv_regulator_probe(struct platform_device 
*pdev)
struct regulator_dev *rdev;
unsigned int val;
int i;
+   enum rohm_chip_type chip = platform_get_device_id(pdev)->driver_data;
 
bdreg = devm_kzalloc(>dev, sizeof(*bdreg), GFP_KERNEL);
if (!bdreg)
@@ -292,6 +294,9 @@ static int bd9571mwv_regulator_probe(struct platform_device 
*pdev)
config.regmap = bdreg->regmap;
 
for (i = 0; i < ARRAY_SIZE(regulators); i++) {
+   /* BD9574MWF supports DVFS only */
+   if (chip == ROHM_CHIP_TYPE_BD9574 && regulators[i].id != DVFS)
+   continue;
rdev = devm_regulator_register(>dev, [i],
   );
if (IS_ERR(rdev)) {
@@ -339,7 +344,8 @@ static int bd9571mwv_regulator_probe(struct platform_device 
*pdev)
 }
 
 static const struct platform_device_id bd9571mwv_regulator_id_table[] = {
-   { "bd9571mwv-regulator", },
+   { "bd9571mwv-regulator", ROHM_CHIP_TYPE_BD9571 },
+   { "bd9574mwf-regulator", ROHM_CHIP_TYPE_BD9574 },
{ /* sentinel */ }
 };
 MODULE_DEVICE_TABLE(platform, bd9571mwv_regulator_id_table);
-- 
2.7.4



[PATCH v7 00/12] treewide: bd9571mwv: Add support for BD9574MWF

2020-12-23 Thread Yoshihiro Shimoda
Add BD9574MWF support into bd9571mwv gpio, mfd and regulator drivers.
Latest Ebisu-4D boards has this chip instead of BD9571MWV so that
we need this patch series to detect this chip at runtime.

Note that the patch [1/12] is a bug-fix patch for mfd driver.

Changes from v6:
 - Remove "struct bd957x_ddata" because this is not used after probed.
 - Add "Acked-for-MFD-by" in patch 12.
 https://patchwork.kernel.org/project/linux-renesas-soc/list/?series=405725

Changes from v5:
 - Fix typo in the patch 5 and 8.
 https://patchwork.kernel.org/project/linux-renesas-soc/list/?series=405263

Changes from v4:
 - Add Reviwed-by in patch 1, 10, 11 and 12.
 - Keep bd9571mwv_id_table[] as-is because unused in patch 12.
 https://patchwork.kernel.org/project/linux-renesas-soc/list/?series=404657

Changes from v3:
 - Add "Acked-for-MFD-by" in patch 1, 3, 9 and 10.
 - Use "Co-developed-by" instead in patch 11.
 - In patch 11:
 -- Remove abusing kernel-doc formatting in patch.
 -- Rename bd957x_data with bd957x_ddata in patch.
 -- Remove product name printk.
 -- Rename bd9571mwv_identify() with bd957x_identify().
 -- Remove argument "part_name" from bd957x_identify().
 -- Modify dev_err() string.
 -- Rename BD9571MWV_PRODUCT_CODE_VAL with BD9571MWV_PRODUCT_CODE_BD9571MWV.
 -- Fix errno from -ENOENT to -ENODEV.
 - In patch 12:
 -- Rename "MFD driver" to "core driver".
 -- Remove unnecessary comments.
 -- Rename BD9574MWF_PRODUCT_CODE_VAL with BD9571MWV_PRODUCT_CODE_BD9574MWF.
 https://patchwork.kernel.org/project/linux-renesas-soc/list/?series=402719

Changes from v2:
 - Use devm_mfd_add_devices() to remove the mfd device in unload.
 - Update commit descriptions in patch 4 and 8.
 - Use regmap_get_device() to simplify in patch 4.
 - Remove "struct bd9571mwv" and bd9571mwv_remove().
 - Add Reviewed-by in patch 3 to 9.
 - Use devm_regmap_add_irq_chip() to simplify in patch 10.
 https://patchwork.kernel.org/project/linux-renesas-soc/list/?series=400477

Changes from v1:
 - Document BD9574MWF on the dt-binding.
 - Add ROHM_CHIP_TYPE_BD957[14] into rohm-generic.h.
 - To simplify gpio and regulator drivers, using regmap instead of
   using struct bd9571mwv.
 - Remove BD9574MWF definitions to make gpio and regulator driver
   simple to support for BD9574MWF.
 - Add BD9574MWF support for gpio and regulator drivers.
 - Add missing regmap ranges for BD9574MWF.
 - Rename "part_number" with "part_name".
 https://patchwork.kernel.org/project/linux-renesas-soc/list/?series=398059

Khiem Nguyen (2):
  mfd: bd9571mwv: Make the driver more generic
  mfd: bd9571mwv: Add support for BD9574MWF

Yoshihiro Shimoda (10):
  mfd: bd9571mwv: Use devm_mfd_add_devices()
  dt-bindings: mfd: bd9571mwv: Document BD9574MWF
  mfd: rohm-generic: Add BD9571 and BD9574
  regulator: bd9571mwv: rid of using struct bd9571mwv
  regulator: bd9571mwv: Add BD9574MWF support
  gpio: bd9571mwv: Use the SPDX license identifier
  gpio: bd9571mwv: rid of using struct bd9571mwv
  gpio: bd9571mwv: Add BD9574MWF support
  mfd: bd9571mwv: Use the SPDX license identifier
  mfd: bd9571mwv: Use devm_regmap_add_irq_chip()

 .../devicetree/bindings/mfd/bd9571mwv.txt  |   4 +-
 drivers/gpio/gpio-bd9571mwv.c  |  35 ++--
 drivers/mfd/bd9571mwv.c| 178 ++---
 drivers/regulator/bd9571mwv-regulator.c|  59 ---
 include/linux/mfd/bd9571mwv.h  |  45 ++
 include/linux/mfd/rohm-generic.h   |   2 +
 6 files changed, 186 insertions(+), 137 deletions(-)

-- 
2.7.4



RE: [PATCH v6 11/12] mfd: bd9571mwv: Make the driver more generic

2020-12-23 Thread Yoshihiro Shimoda
Hi Lee,

> From: Lee Jones, Sent: Thursday, December 24, 2020 12:39 AM
> On Wed, 23 Dec 2020, Yoshihiro Shimoda wrote:
> > From: Khiem Nguyen 
> >
> > Since the driver supports BD9571MWV PMIC only, this patch makes
> > the functions and data structure become more generic so that
> > it can support other PMIC variants as well. Also remove printing
> > part name which Lee Jones suggested.
> >
> > Signed-off-by: Khiem Nguyen 
> > Co-developed-by: Yoshihiro Shimoda 
> > Signed-off-by: Yoshihiro Shimoda 
> > Reviewed-by: Matti Vaittinen 
> > ---
> >  drivers/mfd/bd9571mwv.c   | 89 
> > +--
> >  include/linux/mfd/bd9571mwv.h | 18 +
> >  2 files changed, 54 insertions(+), 53 deletions(-)
> 
> Couple of small points.
> 
> Remainder looks good.

Thank you for your review!

> > diff --git a/drivers/mfd/bd9571mwv.c b/drivers/mfd/bd9571mwv.c
> > index 49e968e..c905ab4 100644
> > --- a/drivers/mfd/bd9571mwv.c
> > +++ b/drivers/mfd/bd9571mwv.c
> > @@ -3,6 +3,7 @@
> >   * ROHM BD9571MWV-M MFD driver
> >   *
> >   * Copyright (C) 2017 Marek Vasut 
> > + * Copyright (C) 2020 Renesas Electronics Corporation
> >   *
> >   * Based on the TPS65086 driver
> >   */
> > @@ -14,6 +15,14 @@
> >
> >  #include 
> >
> > +/* Driver data to distinguish bd957x variants */
> > +struct bd957x_ddata {
> > +   const struct regmap_config *regmap_config;
> > +   const struct regmap_irq_chip *irq_chip;
> 
> > +   const struct mfd_cell *cells;
> > +   int num_cells;
> 
> Are you using these post-probe?
> 
> If not, they're not ddata.

I'm not using all these members post-probe.
So, I'll remove ddata.


> >  static int bd9571mwv_probe(struct i2c_client *client,
> > - const struct i2c_device_id *ids)
> > +  const struct i2c_device_id *ids)
> >  {
> > -   struct bd9571mwv *bd;
> > -   int ret;
> > -
> > -   bd = devm_kzalloc(>dev, sizeof(*bd), GFP_KERNEL);
> > -   if (!bd)
> > -   return -ENOMEM;
> > -
> > -   i2c_set_clientdata(client, bd);
> > -   bd->dev = >dev;
> > -   bd->irq = client->irq;
> > +   const struct bd957x_ddata *ddata;
> > +   struct device *dev = >dev;
> > +   struct regmap *regmap;
> > +   struct regmap_irq_chip_data *irq_data;
> > +   int ret, irq = client->irq;
> > +
> > +   /* Read the PMIC product code */
> > +   ret = i2c_smbus_read_byte_data(client, BD9571MWV_PRODUCT_CODE);
> > +   if (ret < 0) {
> > +   dev_err(dev, "Failed to read product code\n");
> > +       return ret;
> > +   }
> 
> Nit: '\n' here.

I got it. I'll add a blank line here.

> > +   switch (ret) {
> > +   case BD9571MWV_PRODUCT_CODE_BD9571MWV:
> > +   ddata = _ddata;
> 
> Simply declare 'const struct mfd_cell *cells' locally in probe and
> assign it here instead.

I got it. I'll also add "const struct regmap_config *regmap_config;"
and "const struct regmap_irq_chip *irq_chip;" locally in probe.

Best regards,
Yoshihiro Shimoda



[PATCH v6 00/12] treewide: bd9571mwv: Add support for BD9574MWF

2020-12-23 Thread Yoshihiro Shimoda
Add BD9574MWF support into bd9571mwv gpio, mfd and regulator drivers.
Latest Ebisu-4D boards has this chip instead of BD9571MWV so that
we need this patch series to detect this chip at runtime.

Note that the patch [1/12] is a bug-fix patch for mfd driver.

Changes from v5:
 - Fix typo in the patch 5 and 8.
 https://patchwork.kernel.org/project/linux-renesas-soc/list/?series=405263

Changes from v4:
 - Add Reviwed-by in patch 1, 10, 11 and 12.
 - Keep bd9571mwv_id_table[] as-is because unused in patch 12.
 https://patchwork.kernel.org/project/linux-renesas-soc/list/?series=404657

Changes from v3:
 - Add "Acked-for-MFD-by" in patch 1, 3, 9 and 10.
 - Use "Co-developed-by" instead in patch 11.
 - In patch 11:
 -- Remove abusing kernel-doc formatting in patch.
 -- Rename bd957x_data with bd957x_ddata in patch.
 -- Remove product name printk.
 -- Rename bd9571mwv_identify() with bd957x_identify().
 -- Remove argument "part_name" from bd957x_identify().
 -- Modify dev_err() string.
 -- Rename BD9571MWV_PRODUCT_CODE_VAL with BD9571MWV_PRODUCT_CODE_BD9571MWV.
 -- Fix errno from -ENOENT to -ENODEV.
 - In patch 12:
 -- Rename "MFD driver" to "core driver".
 -- Remove unnecessary comments.
 -- Rename BD9574MWF_PRODUCT_CODE_VAL with BD9571MWV_PRODUCT_CODE_BD9574MWF.
 https://patchwork.kernel.org/project/linux-renesas-soc/list/?series=402719

Changes from v2:
 - Use devm_mfd_add_devices() to remove the mfd device in unload.
 - Update commit descriptions in patch 4 and 8.
 - Use regmap_get_device() to simplify in patch 4.
 - Remove "struct bd9571mwv" and bd9571mwv_remove().
 - Add Reviewed-by in patch 3 to 9.
 - Use devm_regmap_add_irq_chip() to simplify in patch 10.
 https://patchwork.kernel.org/project/linux-renesas-soc/list/?series=400477

Changes from v1:
 - Document BD9574MWF on the dt-binding.
 - Add ROHM_CHIP_TYPE_BD957[14] into rohm-generic.h.
 - To simplify gpio and regulator drivers, using regmap instead of
   using struct bd9571mwv.
 - Remove BD9574MWF definitions to make gpio and regulator driver
   simple to support for BD9574MWF.
 - Add BD9574MWF support for gpio and regulator drivers.
 - Add missing regmap ranges for BD9574MWF.
 - Rename "part_number" with "part_name".
 https://patchwork.kernel.org/project/linux-renesas-soc/list/?series=398059

Khiem Nguyen (2):
  mfd: bd9571mwv: Make the driver more generic
  mfd: bd9571mwv: Add support for BD9574MWF

Yoshihiro Shimoda (10):
  mfd: bd9571mwv: Use devm_mfd_add_devices()
  dt-bindings: mfd: bd9571mwv: Document BD9574MWF
  mfd: rohm-generic: Add BD9571 and BD9574
  regulator: bd9571mwv: rid of using struct bd9571mwv
  regulator: bd9571mwv: Add BD9574MWF support
  gpio: bd9571mwv: Use the SPDX license identifier
  gpio: bd9571mwv: rid of using struct bd9571mwv
  gpio: bd9571mwv: Add BD9574MWF support
  mfd: bd9571mwv: Use the SPDX license identifier
  mfd: bd9571mwv: Use devm_regmap_add_irq_chip()

 .../devicetree/bindings/mfd/bd9571mwv.txt  |   4 +-
 drivers/gpio/gpio-bd9571mwv.c  |  35 ++--
 drivers/mfd/bd9571mwv.c| 194 ++---
 drivers/regulator/bd9571mwv-regulator.c|  59 ---
 include/linux/mfd/bd9571mwv.h  |  45 ++---
 include/linux/mfd/rohm-generic.h   |   2 +
 6 files changed, 201 insertions(+), 138 deletions(-)

-- 
2.7.4



[PATCH v6 02/12] dt-bindings: mfd: bd9571mwv: Document BD9574MWF

2020-12-23 Thread Yoshihiro Shimoda
Document other similar specification chip BD9574MWF.

Signed-off-by: Yoshihiro Shimoda 
---
 Documentation/devicetree/bindings/mfd/bd9571mwv.txt | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/Documentation/devicetree/bindings/mfd/bd9571mwv.txt 
b/Documentation/devicetree/bindings/mfd/bd9571mwv.txt
index 8c46786..1d6413e 100644
--- a/Documentation/devicetree/bindings/mfd/bd9571mwv.txt
+++ b/Documentation/devicetree/bindings/mfd/bd9571mwv.txt
@@ -1,7 +1,7 @@
-* ROHM BD9571MWV Power Management Integrated Circuit (PMIC) bindings
+* ROHM BD9571MWV/BD9574MWF Power Management Integrated Circuit (PMIC) bindings
 
 Required properties:
- - compatible  : Should be "rohm,bd9571mwv".
+ - compatible  : Should be "rohm,bd9571mwv" or "rohm,bd9574mwf".
  - reg : I2C slave address.
  - interrupts  : The interrupt line the device is connected to.
  - interrupt-controller: Marks the device node as an interrupt 
controller.
-- 
2.7.4



[PATCH v6 03/12] mfd: rohm-generic: Add BD9571 and BD9574

2020-12-23 Thread Yoshihiro Shimoda
Add chip IDs for BD9571MWV and BD9574MWF.

Signed-off-by: Yoshihiro Shimoda 
Reviewed-by: Matti Vaittinen 
Acked-for-MFD-by: Lee Jones 
---
 include/linux/mfd/rohm-generic.h | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/include/linux/mfd/rohm-generic.h b/include/linux/mfd/rohm-generic.h
index 4283b5b..affacf8 100644
--- a/include/linux/mfd/rohm-generic.h
+++ b/include/linux/mfd/rohm-generic.h
@@ -12,6 +12,8 @@ enum rohm_chip_type {
ROHM_CHIP_TYPE_BD71847,
ROHM_CHIP_TYPE_BD70528,
ROHM_CHIP_TYPE_BD71828,
+   ROHM_CHIP_TYPE_BD9571,
+   ROHM_CHIP_TYPE_BD9574,
ROHM_CHIP_TYPE_AMOUNT
 };
 
-- 
2.7.4



[PATCH v6 09/12] mfd: bd9571mwv: Use the SPDX license identifier

2020-12-23 Thread Yoshihiro Shimoda
Use the SPDX license identifier instead of a local description.

Signed-off-by: Yoshihiro Shimoda 
Reviewed-by: Geert Uytterhoeven 
Acked-for-MFD-by: Lee Jones 
---
 drivers/mfd/bd9571mwv.c   | 10 +-
 include/linux/mfd/bd9571mwv.h | 10 +-
 2 files changed, 2 insertions(+), 18 deletions(-)

diff --git a/drivers/mfd/bd9571mwv.c b/drivers/mfd/bd9571mwv.c
index 19d57a4..e68c3fa 100644
--- a/drivers/mfd/bd9571mwv.c
+++ b/drivers/mfd/bd9571mwv.c
@@ -1,17 +1,9 @@
+// SPDX-License-Identifier: GPL-2.0-only
 /*
  * ROHM BD9571MWV-M MFD driver
  *
  * Copyright (C) 2017 Marek Vasut 
  *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License version 2 as
- * published by the Free Software Foundation.
- *
- * This program is distributed "as is" WITHOUT ANY WARRANTY of any
- * kind, whether expressed or implied; without even the implied warranty
- * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License version 2 for more details.
- *
  * Based on the TPS65086 driver
  */
 
diff --git a/include/linux/mfd/bd9571mwv.h b/include/linux/mfd/bd9571mwv.h
index eb05569..bcc7092 100644
--- a/include/linux/mfd/bd9571mwv.h
+++ b/include/linux/mfd/bd9571mwv.h
@@ -1,17 +1,9 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
 /*
  * ROHM BD9571MWV-M driver
  *
  * Copyright (C) 2017 Marek Vasut 
  *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License version 2 as
- * published by the Free Software Foundation.
- *
- * This program is distributed "as is" WITHOUT ANY WARRANTY of any
- * kind, whether expressed or implied; without even the implied warranty
- * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License version 2 for more details.
- *
  * Based on the TPS65086 driver
  */
 
-- 
2.7.4



[PATCH v6 11/12] mfd: bd9571mwv: Make the driver more generic

2020-12-23 Thread Yoshihiro Shimoda
From: Khiem Nguyen 

Since the driver supports BD9571MWV PMIC only, this patch makes
the functions and data structure become more generic so that
it can support other PMIC variants as well. Also remove printing
part name which Lee Jones suggested.

Signed-off-by: Khiem Nguyen 
Co-developed-by: Yoshihiro Shimoda 
Signed-off-by: Yoshihiro Shimoda 
Reviewed-by: Matti Vaittinen 
---
 drivers/mfd/bd9571mwv.c   | 89 +--
 include/linux/mfd/bd9571mwv.h | 18 +
 2 files changed, 54 insertions(+), 53 deletions(-)

diff --git a/drivers/mfd/bd9571mwv.c b/drivers/mfd/bd9571mwv.c
index 49e968e..c905ab4 100644
--- a/drivers/mfd/bd9571mwv.c
+++ b/drivers/mfd/bd9571mwv.c
@@ -3,6 +3,7 @@
  * ROHM BD9571MWV-M MFD driver
  *
  * Copyright (C) 2017 Marek Vasut 
+ * Copyright (C) 2020 Renesas Electronics Corporation
  *
  * Based on the TPS65086 driver
  */
@@ -14,6 +15,14 @@
 
 #include 
 
+/* Driver data to distinguish bd957x variants */
+struct bd957x_ddata {
+   const struct regmap_config *regmap_config;
+   const struct regmap_irq_chip *irq_chip;
+   const struct mfd_cell *cells;
+   int num_cells;
+};
+
 static const struct mfd_cell bd9571mwv_cells[] = {
{ .name = "bd9571mwv-regulator", },
{ .name = "bd9571mwv-gpio", },
@@ -102,13 +111,19 @@ static struct regmap_irq_chip bd9571mwv_irq_chip = {
.num_irqs   = ARRAY_SIZE(bd9571mwv_irqs),
 };
 
-static int bd9571mwv_identify(struct bd9571mwv *bd)
+static const struct bd957x_ddata bd9571mwv_ddata = {
+   .regmap_config = _regmap_config,
+   .irq_chip = _irq_chip,
+   .cells = bd9571mwv_cells,
+   .num_cells = ARRAY_SIZE(bd9571mwv_cells),
+};
+
+static int bd957x_identify(struct device *dev, struct regmap *regmap)
 {
-   struct device *dev = bd->dev;
unsigned int value;
int ret;
 
-   ret = regmap_read(bd->regmap, BD9571MWV_VENDOR_CODE, );
+   ret = regmap_read(regmap, BD9571MWV_VENDOR_CODE, );
if (ret) {
dev_err(dev, "Failed to read vendor code register (ret=%i)\n",
ret);
@@ -121,66 +136,66 @@ static int bd9571mwv_identify(struct bd9571mwv *bd)
return -EINVAL;
}
 
-   ret = regmap_read(bd->regmap, BD9571MWV_PRODUCT_CODE, );
+   ret = regmap_read(regmap, BD9571MWV_PRODUCT_CODE, );
if (ret) {
dev_err(dev, "Failed to read product code register (ret=%i)\n",
ret);
return ret;
}
-
-   if (value != BD9571MWV_PRODUCT_CODE_VAL) {
-   dev_err(dev, "Invalid product code ID %02x (expected %02x)\n",
-   value, BD9571MWV_PRODUCT_CODE_VAL);
-   return -EINVAL;
-   }
-
-   ret = regmap_read(bd->regmap, BD9571MWV_PRODUCT_REVISION, );
+   ret = regmap_read(regmap, BD9571MWV_PRODUCT_REVISION, );
if (ret) {
dev_err(dev, "Failed to read revision register (ret=%i)\n",
ret);
return ret;
}
 
-   dev_info(dev, "Device: BD9571MWV rev. %d\n", value & 0xff);
-
return 0;
 }
 
 static int bd9571mwv_probe(struct i2c_client *client,
- const struct i2c_device_id *ids)
+  const struct i2c_device_id *ids)
 {
-   struct bd9571mwv *bd;
-   int ret;
-
-   bd = devm_kzalloc(>dev, sizeof(*bd), GFP_KERNEL);
-   if (!bd)
-   return -ENOMEM;
-
-   i2c_set_clientdata(client, bd);
-   bd->dev = >dev;
-   bd->irq = client->irq;
+   const struct bd957x_ddata *ddata;
+   struct device *dev = >dev;
+   struct regmap *regmap;
+   struct regmap_irq_chip_data *irq_data;
+   int ret, irq = client->irq;
+
+   /* Read the PMIC product code */
+   ret = i2c_smbus_read_byte_data(client, BD9571MWV_PRODUCT_CODE);
+   if (ret < 0) {
+   dev_err(dev, "Failed to read product code\n");
+   return ret;
+   }
+   switch (ret) {
+   case BD9571MWV_PRODUCT_CODE_BD9571MWV:
+   ddata = _ddata;
+   break;
+   default:
+   dev_err(dev, "Unsupported device 0x%x\n", ret);
+   return -ENODEV;
+   }
 
-   bd->regmap = devm_regmap_init_i2c(client, _regmap_config);
-   if (IS_ERR(bd->regmap)) {
-   dev_err(bd->dev, "Failed to initialize register map\n");
-   return PTR_ERR(bd->regmap);
+   regmap = devm_regmap_init_i2c(client, ddata->regmap_config);
+   if (IS_ERR(regmap)) {
+   dev_err(dev, "Failed to initialize register map\n");
+   return PTR_ERR(regmap);
}
 
-   ret = bd9571mwv_identify(bd);
+   ret = bd957x_identify(dev, regmap);
if (ret)

[PATCH v6 05/12] regulator: bd9571mwv: Add BD9574MWF support

2020-12-23 Thread Yoshihiro Shimoda
Add support for BD9574MWF which is similar chip with BD9571MWV.
Note that we don't support voltage rails VD{09,18,25,33} by this
driver on BD9574. The VD09 voltage could be read from PMIC but that
is not supported by this commit.

Signed-off-by: Yoshihiro Shimoda 
Reviewed-by: Matti Vaittinen 
---
 drivers/regulator/bd9571mwv-regulator.c | 10 --
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/drivers/regulator/bd9571mwv-regulator.c 
b/drivers/regulator/bd9571mwv-regulator.c
index 42b6a70..7b0cd08 100644
--- a/drivers/regulator/bd9571mwv-regulator.c
+++ b/drivers/regulator/bd9571mwv-regulator.c
@@ -1,6 +1,6 @@
 // SPDX-License-Identifier: GPL-2.0
 /*
- * ROHM BD9571MWV-M regulator driver
+ * ROHM BD9571MWV-M and BD9574MWF-M regulator driver
  *
  * Copyright (C) 2017 Marek Vasut 
  *
@@ -9,6 +9,7 @@
  * NOTE: VD09 is missing
  */
 
+#include 
 #include 
 #include 
 #include 
@@ -277,6 +278,7 @@ static int bd9571mwv_regulator_probe(struct platform_device 
*pdev)
struct regulator_dev *rdev;
unsigned int val;
int i;
+   enum rohm_chip_type chip = platform_get_device_id(pdev)->driver_data;
 
bdreg = devm_kzalloc(>dev, sizeof(*bdreg), GFP_KERNEL);
if (!bdreg)
@@ -292,6 +294,9 @@ static int bd9571mwv_regulator_probe(struct platform_device 
*pdev)
config.regmap = bdreg->regmap;
 
for (i = 0; i < ARRAY_SIZE(regulators); i++) {
+   /* BD9574MWF supports DVFS only */
+   if (chip == ROHM_CHIP_TYPE_BD9574 && regulators[i].id != DVFS)
+   continue;
rdev = devm_regulator_register(>dev, [i],
   );
if (IS_ERR(rdev)) {
@@ -339,7 +344,8 @@ static int bd9571mwv_regulator_probe(struct platform_device 
*pdev)
 }
 
 static const struct platform_device_id bd9571mwv_regulator_id_table[] = {
-   { "bd9571mwv-regulator", },
+   { "bd9571mwv-regulator", ROHM_CHIP_TYPE_BD9571 },
+   { "bd9574mwf-regulator", ROHM_CHIP_TYPE_BD9574 },
{ /* sentinel */ }
 };
 MODULE_DEVICE_TABLE(platform, bd9571mwv_regulator_id_table);
-- 
2.7.4



[PATCH v6 08/12] gpio: bd9571mwv: Add BD9574MWF support

2020-12-23 Thread Yoshihiro Shimoda
Add support for BD9574MWF which is similar chip with BD9571MWV.
Note that BD9574MWF has additional features "RECOV_GPOUT",
"FREQSEL" and "RTC_IN", but supports GPIO function only.

Signed-off-by: Yoshihiro Shimoda 
Reviewed-by: Matti Vaittinen 
---
 drivers/gpio/gpio-bd9571mwv.c | 6 --
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/drivers/gpio/gpio-bd9571mwv.c b/drivers/gpio/gpio-bd9571mwv.c
index 0e5395f..df6102b 100644
--- a/drivers/gpio/gpio-bd9571mwv.c
+++ b/drivers/gpio/gpio-bd9571mwv.c
@@ -1,6 +1,6 @@
 // SPDX-License-Identifier: GPL-2.0-only
 /*
- * ROHM BD9571MWV-M GPIO driver
+ * ROHM BD9571MWV-M and BD9574MWF-M GPIO driver
  *
  * Copyright (C) 2017 Marek Vasut 
  *
@@ -10,6 +10,7 @@
  */
 
 #include 
+#include 
 #include 
 #include 
 
@@ -118,7 +119,8 @@ static int bd9571mwv_gpio_probe(struct platform_device 
*pdev)
 }
 
 static const struct platform_device_id bd9571mwv_gpio_id_table[] = {
-   { "bd9571mwv-gpio", },
+   { "bd9571mwv-gpio", ROHM_CHIP_TYPE_BD9571 },
+   { "bd9574mwf-gpio", ROHM_CHIP_TYPE_BD9574 },
{ /* sentinel */ }
 };
 MODULE_DEVICE_TABLE(platform, bd9571mwv_gpio_id_table);
-- 
2.7.4



[PATCH v6 10/12] mfd: bd9571mwv: Use devm_regmap_add_irq_chip()

2020-12-23 Thread Yoshihiro Shimoda
Use dev_regmap_add_irq_chip() to simplify the code.

Signed-off-by: Yoshihiro Shimoda 
Acked-for-MFD-by: Lee Jones 
Reviewed-by: Matti Vaittinen 
Reviewed-by: Geert Uytterhoeven 
---
 drivers/mfd/bd9571mwv.c | 27 ++-
 1 file changed, 6 insertions(+), 21 deletions(-)

diff --git a/drivers/mfd/bd9571mwv.c b/drivers/mfd/bd9571mwv.c
index e68c3fa..49e968e 100644
--- a/drivers/mfd/bd9571mwv.c
+++ b/drivers/mfd/bd9571mwv.c
@@ -170,31 +170,17 @@ static int bd9571mwv_probe(struct i2c_client *client,
if (ret)
return ret;
 
-   ret = regmap_add_irq_chip(bd->regmap, bd->irq, IRQF_ONESHOT, 0,
- _irq_chip, >irq_data);
+   ret = devm_regmap_add_irq_chip(bd->dev, bd->regmap, bd->irq,
+  IRQF_ONESHOT, 0, _irq_chip,
+  >irq_data);
if (ret) {
dev_err(bd->dev, "Failed to register IRQ chip\n");
return ret;
}
 
-   ret = devm_mfd_add_devices(bd->dev, PLATFORM_DEVID_AUTO,
-  bd9571mwv_cells, ARRAY_SIZE(bd9571mwv_cells),
-  NULL, 0, 
regmap_irq_get_domain(bd->irq_data));
-   if (ret) {
-   regmap_del_irq_chip(bd->irq, bd->irq_data);
-   return ret;
-   }
-
-   return 0;
-}
-
-static int bd9571mwv_remove(struct i2c_client *client)
-{
-   struct bd9571mwv *bd = i2c_get_clientdata(client);
-
-   regmap_del_irq_chip(bd->irq, bd->irq_data);
-
-   return 0;
+   return devm_mfd_add_devices(bd->dev, PLATFORM_DEVID_AUTO,
+   bd9571mwv_cells, 
ARRAY_SIZE(bd9571mwv_cells),
+   NULL, 0, 
regmap_irq_get_domain(bd->irq_data));
 }
 
 static const struct of_device_id bd9571mwv_of_match_table[] = {
@@ -215,7 +201,6 @@ static struct i2c_driver bd9571mwv_driver = {
.of_match_table = bd9571mwv_of_match_table,
},
.probe  = bd9571mwv_probe,
-   .remove = bd9571mwv_remove,
.id_table   = bd9571mwv_id_table,
 };
 module_i2c_driver(bd9571mwv_driver);
-- 
2.7.4



[PATCH v6 06/12] gpio: bd9571mwv: Use the SPDX license identifier

2020-12-23 Thread Yoshihiro Shimoda
Use the SPDX license identifier instead of a local description.

Signed-off-by: Yoshihiro Shimoda 
Reviewed-by: Geert Uytterhoeven 
---
 drivers/gpio/gpio-bd9571mwv.c | 10 +-
 1 file changed, 1 insertion(+), 9 deletions(-)

diff --git a/drivers/gpio/gpio-bd9571mwv.c b/drivers/gpio/gpio-bd9571mwv.c
index c0abc9c..abb622c 100644
--- a/drivers/gpio/gpio-bd9571mwv.c
+++ b/drivers/gpio/gpio-bd9571mwv.c
@@ -1,17 +1,9 @@
+// SPDX-License-Identifier: GPL-2.0-only
 /*
  * ROHM BD9571MWV-M GPIO driver
  *
  * Copyright (C) 2017 Marek Vasut 
  *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License version 2 as
- * published by the Free Software Foundation.
- *
- * This program is distributed "as is" WITHOUT ANY WARRANTY of any
- * kind, whether expressed or implied; without even the implied warranty
- * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License version 2 for more details.
- *
  * Based on the TPS65086 driver
  *
  * NOTE: Interrupts are not supported yet.
-- 
2.7.4



[PATCH v6 12/12] mfd: bd9571mwv: Add support for BD9574MWF

2020-12-23 Thread Yoshihiro Shimoda
From: Khiem Nguyen 

The new PMIC BD9574MWF inherits features from BD9571MWV.
Add the support of new PMIC to existing bd9571mwv driver.

Signed-off-by: Khiem Nguyen 
Co-developed-by: Yoshihiro Shimoda 
Signed-off-by: Yoshihiro Shimoda 
Reviewed-by: Matti Vaittinen 
---
 drivers/mfd/bd9571mwv.c   | 80 ++-
 include/linux/mfd/bd9571mwv.h | 17 +++--
 2 files changed, 93 insertions(+), 4 deletions(-)

diff --git a/drivers/mfd/bd9571mwv.c b/drivers/mfd/bd9571mwv.c
index c905ab4..b1e7ae9 100644
--- a/drivers/mfd/bd9571mwv.c
+++ b/drivers/mfd/bd9571mwv.c
@@ -1,6 +1,6 @@
 // SPDX-License-Identifier: GPL-2.0-only
 /*
- * ROHM BD9571MWV-M MFD driver
+ * ROHM BD9571MWV-M and BD9574MVF-M core driver
  *
  * Copyright (C) 2017 Marek Vasut 
  * Copyright (C) 2020 Renesas Electronics Corporation
@@ -11,6 +11,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 
 #include 
@@ -118,6 +119,79 @@ static const struct bd957x_ddata bd9571mwv_ddata = {
.num_cells = ARRAY_SIZE(bd9571mwv_cells),
 };
 
+static const struct mfd_cell bd9574mwf_cells[] = {
+   { .name = "bd9574mwf-regulator", },
+   { .name = "bd9574mwf-gpio", },
+};
+
+static const struct regmap_range bd9574mwf_readable_yes_ranges[] = {
+   regmap_reg_range(BD9571MWV_VENDOR_CODE, BD9571MWV_PRODUCT_REVISION),
+   regmap_reg_range(BD9571MWV_BKUP_MODE_CNT, BD9571MWV_BKUP_MODE_CNT),
+   regmap_reg_range(BD9571MWV_DVFS_VINIT, BD9571MWV_DVFS_SETVMAX),
+   regmap_reg_range(BD9571MWV_DVFS_SETVID, BD9571MWV_DVFS_MONIVDAC),
+   regmap_reg_range(BD9571MWV_GPIO_IN, BD9571MWV_GPIO_IN),
+   regmap_reg_range(BD9571MWV_GPIO_INT, BD9571MWV_GPIO_INTMASK),
+   regmap_reg_range(BD9571MWV_INT_INTREQ, BD9571MWV_INT_INTMASK),
+};
+
+static const struct regmap_access_table bd9574mwf_readable_table = {
+   .yes_ranges = bd9574mwf_readable_yes_ranges,
+   .n_yes_ranges   = ARRAY_SIZE(bd9574mwf_readable_yes_ranges),
+};
+
+static const struct regmap_range bd9574mwf_writable_yes_ranges[] = {
+   regmap_reg_range(BD9571MWV_BKUP_MODE_CNT, BD9571MWV_BKUP_MODE_CNT),
+   regmap_reg_range(BD9571MWV_DVFS_SETVID, BD9571MWV_DVFS_SETVID),
+   regmap_reg_range(BD9571MWV_GPIO_DIR, BD9571MWV_GPIO_OUT),
+   regmap_reg_range(BD9571MWV_GPIO_INT_SET, BD9571MWV_GPIO_INTMASK),
+   regmap_reg_range(BD9571MWV_INT_INTREQ, BD9571MWV_INT_INTMASK),
+};
+
+static const struct regmap_access_table bd9574mwf_writable_table = {
+   .yes_ranges = bd9574mwf_writable_yes_ranges,
+   .n_yes_ranges   = ARRAY_SIZE(bd9574mwf_writable_yes_ranges),
+};
+
+static const struct regmap_range bd9574mwf_volatile_yes_ranges[] = {
+   regmap_reg_range(BD9571MWV_DVFS_MONIVDAC, BD9571MWV_DVFS_MONIVDAC),
+   regmap_reg_range(BD9571MWV_GPIO_IN, BD9571MWV_GPIO_IN),
+   regmap_reg_range(BD9571MWV_GPIO_INT, BD9571MWV_GPIO_INT),
+   regmap_reg_range(BD9571MWV_INT_INTREQ, BD9571MWV_INT_INTREQ),
+};
+
+static const struct regmap_access_table bd9574mwf_volatile_table = {
+   .yes_ranges = bd9574mwf_volatile_yes_ranges,
+   .n_yes_ranges   = ARRAY_SIZE(bd9574mwf_volatile_yes_ranges),
+};
+
+static const struct regmap_config bd9574mwf_regmap_config = {
+   .reg_bits   = 8,
+   .val_bits   = 8,
+   .cache_type = REGCACHE_RBTREE,
+   .rd_table   = _readable_table,
+   .wr_table   = _writable_table,
+   .volatile_table = _volatile_table,
+   .max_register   = 0xff,
+};
+
+static struct regmap_irq_chip bd9574mwf_irq_chip = {
+   .name   = "bd9574mwf",
+   .status_base= BD9571MWV_INT_INTREQ,
+   .mask_base  = BD9571MWV_INT_INTMASK,
+   .ack_base   = BD9571MWV_INT_INTREQ,
+   .init_ack_masked = true,
+   .num_regs   = 1,
+   .irqs   = bd9571mwv_irqs,
+   .num_irqs   = ARRAY_SIZE(bd9571mwv_irqs),
+};
+
+static const struct bd957x_ddata bd9574mwf_ddata = {
+   .regmap_config = _regmap_config,
+   .irq_chip = _irq_chip,
+   .cells = bd9574mwf_cells,
+   .num_cells = ARRAY_SIZE(bd9574mwf_cells),
+};
+
 static int bd957x_identify(struct device *dev, struct regmap *regmap)
 {
unsigned int value;
@@ -171,6 +245,9 @@ static int bd9571mwv_probe(struct i2c_client *client,
case BD9571MWV_PRODUCT_CODE_BD9571MWV:
ddata = _ddata;
break;
+   case BD9571MWV_PRODUCT_CODE_BD9574MWF:
+   ddata = _ddata;
+   break;
default:
dev_err(dev, "Unsupported device 0x%x\n", ret);
return -ENODEV;
@@ -200,6 +277,7 @@ static int bd9571mwv_probe(struct i2c_client *client,
 
 static const struct of_device_id bd9571mwv_of_match_table[] = {
{ .compatible = "rohm,bd9571mwv", },
+   { .compatible = "rohm,bd9574mwf", },
{ /* sentinel */ }
 };
 MODULE_DEVICE_TABLE(of, bd9571mwv_of_match_table);
di

[PATCH v6 07/12] gpio: bd9571mwv: rid of using struct bd9571mwv

2020-12-23 Thread Yoshihiro Shimoda
To simplify this driver, use dev_get_regmap() and
rid of using struct bd9571mwv.

Signed-off-by: Yoshihiro Shimoda 
Reviewed-by: Matti Vaittinen 
---
 drivers/gpio/gpio-bd9571mwv.c | 19 +--
 1 file changed, 9 insertions(+), 10 deletions(-)

diff --git a/drivers/gpio/gpio-bd9571mwv.c b/drivers/gpio/gpio-bd9571mwv.c
index abb622c..0e5395f 100644
--- a/drivers/gpio/gpio-bd9571mwv.c
+++ b/drivers/gpio/gpio-bd9571mwv.c
@@ -16,8 +16,8 @@
 #include 
 
 struct bd9571mwv_gpio {
+   struct regmap *regmap;
struct gpio_chip chip;
-   struct bd9571mwv *bd;
 };
 
 static int bd9571mwv_gpio_get_direction(struct gpio_chip *chip,
@@ -26,7 +26,7 @@ static int bd9571mwv_gpio_get_direction(struct gpio_chip 
*chip,
struct bd9571mwv_gpio *gpio = gpiochip_get_data(chip);
int ret, val;
 
-   ret = regmap_read(gpio->bd->regmap, BD9571MWV_GPIO_DIR, );
+   ret = regmap_read(gpio->regmap, BD9571MWV_GPIO_DIR, );
if (ret < 0)
return ret;
if (val & BIT(offset))
@@ -40,8 +40,7 @@ static int bd9571mwv_gpio_direction_input(struct gpio_chip 
*chip,
 {
struct bd9571mwv_gpio *gpio = gpiochip_get_data(chip);
 
-   regmap_update_bits(gpio->bd->regmap, BD9571MWV_GPIO_DIR,
-  BIT(offset), 0);
+   regmap_update_bits(gpio->regmap, BD9571MWV_GPIO_DIR, BIT(offset), 0);
 
return 0;
 }
@@ -52,9 +51,9 @@ static int bd9571mwv_gpio_direction_output(struct gpio_chip 
*chip,
struct bd9571mwv_gpio *gpio = gpiochip_get_data(chip);
 
/* Set the initial value */
-   regmap_update_bits(gpio->bd->regmap, BD9571MWV_GPIO_OUT,
+   regmap_update_bits(gpio->regmap, BD9571MWV_GPIO_OUT,
   BIT(offset), value ? BIT(offset) : 0);
-   regmap_update_bits(gpio->bd->regmap, BD9571MWV_GPIO_DIR,
+   regmap_update_bits(gpio->regmap, BD9571MWV_GPIO_DIR,
   BIT(offset), BIT(offset));
 
return 0;
@@ -65,7 +64,7 @@ static int bd9571mwv_gpio_get(struct gpio_chip *chip, 
unsigned int offset)
struct bd9571mwv_gpio *gpio = gpiochip_get_data(chip);
int ret, val;
 
-   ret = regmap_read(gpio->bd->regmap, BD9571MWV_GPIO_IN, );
+   ret = regmap_read(gpio->regmap, BD9571MWV_GPIO_IN, );
if (ret < 0)
return ret;
 
@@ -77,7 +76,7 @@ static void bd9571mwv_gpio_set(struct gpio_chip *chip, 
unsigned int offset,
 {
struct bd9571mwv_gpio *gpio = gpiochip_get_data(chip);
 
-   regmap_update_bits(gpio->bd->regmap, BD9571MWV_GPIO_OUT,
+   regmap_update_bits(gpio->regmap, BD9571MWV_GPIO_OUT,
   BIT(offset), value ? BIT(offset) : 0);
 }
 
@@ -105,9 +104,9 @@ static int bd9571mwv_gpio_probe(struct platform_device 
*pdev)
 
platform_set_drvdata(pdev, gpio);
 
-   gpio->bd = dev_get_drvdata(pdev->dev.parent);
+   gpio->regmap = dev_get_regmap(pdev->dev.parent, NULL);
gpio->chip = template_chip;
-   gpio->chip.parent = gpio->bd->dev;
+   gpio->chip.parent = pdev->dev.parent;
 
ret = devm_gpiochip_add_data(>dev, >chip, gpio);
if (ret < 0) {
-- 
2.7.4



[PATCH v6 01/12] mfd: bd9571mwv: Use devm_mfd_add_devices()

2020-12-23 Thread Yoshihiro Shimoda
To remove mfd devices when unload this driver, should use
devm_mfd_add_devices() instead.

Fixes: d3ea21272094 ("mfd: Add ROHM BD9571MWV-M MFD PMIC driver")
Signed-off-by: Yoshihiro Shimoda 
Acked-for-MFD-by: Lee Jones 
Reviewed-by: Geert Uytterhoeven 
Reviewed-by: Matti Vaittinen 
---
 drivers/mfd/bd9571mwv.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/mfd/bd9571mwv.c b/drivers/mfd/bd9571mwv.c
index fab3cdc..19d57a4 100644
--- a/drivers/mfd/bd9571mwv.c
+++ b/drivers/mfd/bd9571mwv.c
@@ -185,9 +185,9 @@ static int bd9571mwv_probe(struct i2c_client *client,
return ret;
}
 
-   ret = mfd_add_devices(bd->dev, PLATFORM_DEVID_AUTO, bd9571mwv_cells,
- ARRAY_SIZE(bd9571mwv_cells), NULL, 0,
- regmap_irq_get_domain(bd->irq_data));
+   ret = devm_mfd_add_devices(bd->dev, PLATFORM_DEVID_AUTO,
+  bd9571mwv_cells, ARRAY_SIZE(bd9571mwv_cells),
+  NULL, 0, 
regmap_irq_get_domain(bd->irq_data));
if (ret) {
regmap_del_irq_chip(bd->irq, bd->irq_data);
return ret;
-- 
2.7.4



[PATCH v6 04/12] regulator: bd9571mwv: rid of using struct bd9571mwv

2020-12-23 Thread Yoshihiro Shimoda
To simplify this driver, use dev_get_regmap() and
rid of using struct bd9571mwv.

Signed-off-by: Yoshihiro Shimoda 
Reviewed-by: Matti Vaittinen 
---
 drivers/regulator/bd9571mwv-regulator.c | 49 +
 1 file changed, 26 insertions(+), 23 deletions(-)

diff --git a/drivers/regulator/bd9571mwv-regulator.c 
b/drivers/regulator/bd9571mwv-regulator.c
index e690c2c..42b6a70 100644
--- a/drivers/regulator/bd9571mwv-regulator.c
+++ b/drivers/regulator/bd9571mwv-regulator.c
@@ -17,7 +17,7 @@
 #include 
 
 struct bd9571mwv_reg {
-   struct bd9571mwv *bd;
+   struct regmap *regmap;
 
/* DDR Backup Power */
u8 bkup_mode_cnt_keepon;/* from "rohm,ddr-backup-power" */
@@ -137,26 +137,30 @@ static const struct regulator_desc regulators[] = {
 };
 
 #ifdef CONFIG_PM_SLEEP
-static int bd9571mwv_bkup_mode_read(struct bd9571mwv *bd, unsigned int *mode)
+static int bd9571mwv_bkup_mode_read(struct bd9571mwv_reg *bdreg,
+   unsigned int *mode)
 {
int ret;
 
-   ret = regmap_read(bd->regmap, BD9571MWV_BKUP_MODE_CNT, mode);
+   ret = regmap_read(bdreg->regmap, BD9571MWV_BKUP_MODE_CNT, mode);
if (ret) {
-   dev_err(bd->dev, "failed to read backup mode (%d)\n", ret);
+   dev_err(regmap_get_device(bdreg->regmap),
+   "failed to read backup mode (%d)\n", ret);
return ret;
}
 
return 0;
 }
 
-static int bd9571mwv_bkup_mode_write(struct bd9571mwv *bd, unsigned int mode)
+static int bd9571mwv_bkup_mode_write(struct bd9571mwv_reg *bdreg,
+unsigned int mode)
 {
int ret;
 
-   ret = regmap_write(bd->regmap, BD9571MWV_BKUP_MODE_CNT, mode);
+   ret = regmap_write(bdreg->regmap, BD9571MWV_BKUP_MODE_CNT, mode);
if (ret) {
-   dev_err(bd->dev, "failed to configure backup mode 0x%x (%d)\n",
+   dev_err(regmap_get_device(bdreg->regmap),
+   "failed to configure backup mode 0x%x (%d)\n",
mode, ret);
return ret;
}
@@ -194,7 +198,7 @@ static ssize_t backup_mode_store(struct device *dev,
 * Configure DDR Backup Mode, to change the role of the accessory power
 * switch from a power switch to a wake-up switch, or vice versa
 */
-   ret = bd9571mwv_bkup_mode_read(bdreg->bd, );
+   ret = bd9571mwv_bkup_mode_read(bdreg, );
if (ret)
return ret;
 
@@ -202,7 +206,7 @@ static ssize_t backup_mode_store(struct device *dev,
if (bdreg->bkup_mode_enabled)
mode |= bdreg->bkup_mode_cnt_keepon;
 
-   ret = bd9571mwv_bkup_mode_write(bdreg->bd, mode);
+   ret = bd9571mwv_bkup_mode_write(bdreg, mode);
if (ret)
return ret;
 
@@ -221,7 +225,7 @@ static int bd9571mwv_suspend(struct device *dev)
return 0;
 
/* Save DDR Backup Mode */
-   ret = bd9571mwv_bkup_mode_read(bdreg->bd, );
+   ret = bd9571mwv_bkup_mode_read(bdreg, );
if (ret)
return ret;
 
@@ -235,7 +239,7 @@ static int bd9571mwv_suspend(struct device *dev)
mode |= bdreg->bkup_mode_cnt_keepon;
 
if (mode != bdreg->bkup_mode_cnt_saved)
-   return bd9571mwv_bkup_mode_write(bdreg->bd, mode);
+   return bd9571mwv_bkup_mode_write(bdreg, mode);
 
return 0;
 }
@@ -248,7 +252,7 @@ static int bd9571mwv_resume(struct device *dev)
return 0;
 
/* Restore DDR Backup Mode */
-   return bd9571mwv_bkup_mode_write(bdreg->bd, bdreg->bkup_mode_cnt_saved);
+   return bd9571mwv_bkup_mode_write(bdreg, bdreg->bkup_mode_cnt_saved);
 }
 
 static const struct dev_pm_ops bd9571mwv_pm  = {
@@ -268,7 +272,6 @@ static int bd9571mwv_regulator_remove(struct 
platform_device *pdev)
 
 static int bd9571mwv_regulator_probe(struct platform_device *pdev)
 {
-   struct bd9571mwv *bd = dev_get_drvdata(pdev->dev.parent);
struct regulator_config config = { };
struct bd9571mwv_reg *bdreg;
struct regulator_dev *rdev;
@@ -279,40 +282,40 @@ static int bd9571mwv_regulator_probe(struct 
platform_device *pdev)
if (!bdreg)
return -ENOMEM;
 
-   bdreg->bd = bd;
+   bdreg->regmap = dev_get_regmap(pdev->dev.parent, NULL);
 
platform_set_drvdata(pdev, bdreg);
 
config.dev = >dev;
-   config.dev->of_node = bd->dev->of_node;
-   config.driver_data = bd;
-   config.regmap = bd->regmap;
+   config.dev->of_node = pdev->dev.parent->of_node;
+   config.driver_data = bdreg;
+   config.regmap = bdreg->regmap;
 
for (i = 0; i < ARRAY_SIZE(regulators); i++) {
rdev = devm_regulator_register(>dev, [i],
 

RE: [PATCH v5 05/12] regulator: bd9571mwv: Add BD9574MWF support

2020-12-23 Thread Yoshihiro Shimoda
Hi Sergei,

> From: Sergei Shtylyov, Sent: Wednesday, December 23, 2020 6:15 PM
> 
> On 22.12.2020 14:22, Yoshihiro Shimoda wrote:
> 
> > Add support for BD9574MWF which is silimar chip with BD9571MWV.
> 
> Similar (again)? :-)

Thank you for pointed it out! I'll fix this and patch 8/12.

Best regards,
Yoshihiro Shimoda



[PATCH v5 00/12] treewide: bd9571mwv: Add support for BD9574MWF

2020-12-22 Thread Yoshihiro Shimoda
Add BD9574MWF support into bd9571mwv gpio, mfd and regulator drivers.
Latest Ebisu-4D boards has this chip instead of BD9571MWV so that
we need this patch series to detect this chip at runtime.

Note that the patch [1/12] is a bug-fix patch for mfd driver.

Changes from v4:
 - Add Reviwed-by in patch 1, 10, 11 and 12.
 - Keep bd9571mwv_id_table[] as-is because unused in patch 12.
 https://patchwork.kernel.org/project/linux-renesas-soc/list/?series=404657

Changes from v3:
 - Add "Acked-for-MFD-by" in patch 1, 3, 9 and 10.
 - Use "Co-developed-by" instead in patch 11.
 - In patch 11:
 -- Remove abusing kernel-doc formatting in patch.
 -- Rename bd957x_data with bd957x_ddata in patch.
 -- Remove product name printk.
 -- Rename bd9571mwv_identify() with bd957x_identify().
 -- Remove argument "part_name" from bd957x_identify().
 -- Modify dev_err() string.
 -- Rename BD9571MWV_PRODUCT_CODE_VAL with BD9571MWV_PRODUCT_CODE_BD9571MWV.
 -- Fix errno from -ENOENT to -ENODEV.
 - In patch 12:
 -- Rename "MFD driver" to "core driver".
 -- Remove unnecessary comments.
 -- Rename BD9574MWF_PRODUCT_CODE_VAL with BD9571MWV_PRODUCT_CODE_BD9574MWF.
 https://patchwork.kernel.org/project/linux-renesas-soc/list/?series=402719

Changes from v2:
 - Use devm_mfd_add_devices() to remove the mfd device in unload.
 - Update commit descriptions in patch 4 and 8.
 - Use regmap_get_device() to simplify in patch 4.
 - Remove "struct bd9571mwv" and bd9571mwv_remove().
 - Add Reviewed-by in patch 3 to 9.
 - Use devm_regmap_add_irq_chip() to simplify in patch 10.
 https://patchwork.kernel.org/project/linux-renesas-soc/list/?series=400477

Changes from v1:
 - Document BD9574MWF on the dt-binding.
 - Add ROHM_CHIP_TYPE_BD957[14] into rohm-generic.h.
 - To simplify gpio and regulator drivers, using regmap instead of
   using struct bd9571mwv.
 - Remove BD9574MWF definitions to make gpio and regulator driver
   simple to support for BD9574MWF.
 - Add BD9574MWF support for gpio and regulator drivers.
 - Add missing regmap ranges for BD9574MWF.
 - Rename "part_number" with "part_name".
 https://patchwork.kernel.org/project/linux-renesas-soc/list/?series=398059

Khiem Nguyen (2):
  mfd: bd9571mwv: Make the driver more generic
  mfd: bd9571mwv: Add support for BD9574MWF

Yoshihiro Shimoda (10):
  mfd: bd9571mwv: Use devm_mfd_add_devices()
  dt-bindings: mfd: bd9571mwv: Document BD9574MWF
  mfd: rohm-generic: Add BD9571 and BD9574
  regulator: bd9571mwv: rid of using struct bd9571mwv
  regulator: bd9571mwv: Add BD9574MWF support
  gpio: bd9571mwv: Use the SPDX license identifier
  gpio: bd9571mwv: rid of using struct bd9571mwv
  gpio: bd9571mwv: Add BD9574MWF support
  mfd: bd9571mwv: Use the SPDX license identifier
  mfd: bd9571mwv: Use devm_regmap_add_irq_chip()

 .../devicetree/bindings/mfd/bd9571mwv.txt  |   4 +-
 drivers/gpio/gpio-bd9571mwv.c  |  35 ++--
 drivers/mfd/bd9571mwv.c| 194 ++---
 drivers/regulator/bd9571mwv-regulator.c|  59 ---
 include/linux/mfd/bd9571mwv.h  |  45 ++---
 include/linux/mfd/rohm-generic.h   |   2 +
 6 files changed, 201 insertions(+), 138 deletions(-)

-- 
2.7.4



[PATCH v5 04/12] regulator: bd9571mwv: rid of using struct bd9571mwv

2020-12-22 Thread Yoshihiro Shimoda
To simplify this driver, use dev_get_regmap() and
rid of using struct bd9571mwv.

Signed-off-by: Yoshihiro Shimoda 
Reviewed-by: Matti Vaittinen 
---
 drivers/regulator/bd9571mwv-regulator.c | 49 +
 1 file changed, 26 insertions(+), 23 deletions(-)

diff --git a/drivers/regulator/bd9571mwv-regulator.c 
b/drivers/regulator/bd9571mwv-regulator.c
index e690c2c..42b6a70 100644
--- a/drivers/regulator/bd9571mwv-regulator.c
+++ b/drivers/regulator/bd9571mwv-regulator.c
@@ -17,7 +17,7 @@
 #include 
 
 struct bd9571mwv_reg {
-   struct bd9571mwv *bd;
+   struct regmap *regmap;
 
/* DDR Backup Power */
u8 bkup_mode_cnt_keepon;/* from "rohm,ddr-backup-power" */
@@ -137,26 +137,30 @@ static const struct regulator_desc regulators[] = {
 };
 
 #ifdef CONFIG_PM_SLEEP
-static int bd9571mwv_bkup_mode_read(struct bd9571mwv *bd, unsigned int *mode)
+static int bd9571mwv_bkup_mode_read(struct bd9571mwv_reg *bdreg,
+   unsigned int *mode)
 {
int ret;
 
-   ret = regmap_read(bd->regmap, BD9571MWV_BKUP_MODE_CNT, mode);
+   ret = regmap_read(bdreg->regmap, BD9571MWV_BKUP_MODE_CNT, mode);
if (ret) {
-   dev_err(bd->dev, "failed to read backup mode (%d)\n", ret);
+   dev_err(regmap_get_device(bdreg->regmap),
+   "failed to read backup mode (%d)\n", ret);
return ret;
}
 
return 0;
 }
 
-static int bd9571mwv_bkup_mode_write(struct bd9571mwv *bd, unsigned int mode)
+static int bd9571mwv_bkup_mode_write(struct bd9571mwv_reg *bdreg,
+unsigned int mode)
 {
int ret;
 
-   ret = regmap_write(bd->regmap, BD9571MWV_BKUP_MODE_CNT, mode);
+   ret = regmap_write(bdreg->regmap, BD9571MWV_BKUP_MODE_CNT, mode);
if (ret) {
-   dev_err(bd->dev, "failed to configure backup mode 0x%x (%d)\n",
+   dev_err(regmap_get_device(bdreg->regmap),
+   "failed to configure backup mode 0x%x (%d)\n",
mode, ret);
return ret;
}
@@ -194,7 +198,7 @@ static ssize_t backup_mode_store(struct device *dev,
 * Configure DDR Backup Mode, to change the role of the accessory power
 * switch from a power switch to a wake-up switch, or vice versa
 */
-   ret = bd9571mwv_bkup_mode_read(bdreg->bd, );
+   ret = bd9571mwv_bkup_mode_read(bdreg, );
if (ret)
return ret;
 
@@ -202,7 +206,7 @@ static ssize_t backup_mode_store(struct device *dev,
if (bdreg->bkup_mode_enabled)
mode |= bdreg->bkup_mode_cnt_keepon;
 
-   ret = bd9571mwv_bkup_mode_write(bdreg->bd, mode);
+   ret = bd9571mwv_bkup_mode_write(bdreg, mode);
if (ret)
return ret;
 
@@ -221,7 +225,7 @@ static int bd9571mwv_suspend(struct device *dev)
return 0;
 
/* Save DDR Backup Mode */
-   ret = bd9571mwv_bkup_mode_read(bdreg->bd, );
+   ret = bd9571mwv_bkup_mode_read(bdreg, );
if (ret)
return ret;
 
@@ -235,7 +239,7 @@ static int bd9571mwv_suspend(struct device *dev)
mode |= bdreg->bkup_mode_cnt_keepon;
 
if (mode != bdreg->bkup_mode_cnt_saved)
-   return bd9571mwv_bkup_mode_write(bdreg->bd, mode);
+   return bd9571mwv_bkup_mode_write(bdreg, mode);
 
return 0;
 }
@@ -248,7 +252,7 @@ static int bd9571mwv_resume(struct device *dev)
return 0;
 
/* Restore DDR Backup Mode */
-   return bd9571mwv_bkup_mode_write(bdreg->bd, bdreg->bkup_mode_cnt_saved);
+   return bd9571mwv_bkup_mode_write(bdreg, bdreg->bkup_mode_cnt_saved);
 }
 
 static const struct dev_pm_ops bd9571mwv_pm  = {
@@ -268,7 +272,6 @@ static int bd9571mwv_regulator_remove(struct 
platform_device *pdev)
 
 static int bd9571mwv_regulator_probe(struct platform_device *pdev)
 {
-   struct bd9571mwv *bd = dev_get_drvdata(pdev->dev.parent);
struct regulator_config config = { };
struct bd9571mwv_reg *bdreg;
struct regulator_dev *rdev;
@@ -279,40 +282,40 @@ static int bd9571mwv_regulator_probe(struct 
platform_device *pdev)
if (!bdreg)
return -ENOMEM;
 
-   bdreg->bd = bd;
+   bdreg->regmap = dev_get_regmap(pdev->dev.parent, NULL);
 
platform_set_drvdata(pdev, bdreg);
 
config.dev = >dev;
-   config.dev->of_node = bd->dev->of_node;
-   config.driver_data = bd;
-   config.regmap = bd->regmap;
+   config.dev->of_node = pdev->dev.parent->of_node;
+   config.driver_data = bdreg;
+   config.regmap = bdreg->regmap;
 
for (i = 0; i < ARRAY_SIZE(regulators); i++) {
rdev = devm_regulator_register(>dev, [i],
 

[PATCH v5 03/12] mfd: rohm-generic: Add BD9571 and BD9574

2020-12-22 Thread Yoshihiro Shimoda
Add chip IDs for BD9571MWV and BD9574MWF.

Signed-off-by: Yoshihiro Shimoda 
Reviewed-by: Matti Vaittinen 
Acked-for-MFD-by: Lee Jones 
---
 include/linux/mfd/rohm-generic.h | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/include/linux/mfd/rohm-generic.h b/include/linux/mfd/rohm-generic.h
index 4283b5b..affacf8 100644
--- a/include/linux/mfd/rohm-generic.h
+++ b/include/linux/mfd/rohm-generic.h
@@ -12,6 +12,8 @@ enum rohm_chip_type {
ROHM_CHIP_TYPE_BD71847,
ROHM_CHIP_TYPE_BD70528,
ROHM_CHIP_TYPE_BD71828,
+   ROHM_CHIP_TYPE_BD9571,
+   ROHM_CHIP_TYPE_BD9574,
ROHM_CHIP_TYPE_AMOUNT
 };
 
-- 
2.7.4



[PATCH v5 12/12] mfd: bd9571mwv: Add support for BD9574MWF

2020-12-22 Thread Yoshihiro Shimoda
From: Khiem Nguyen 

The new PMIC BD9574MWF inherits features from BD9571MWV.
Add the support of new PMIC to existing bd9571mwv driver.

Signed-off-by: Khiem Nguyen 
Co-developed-by: Yoshihiro Shimoda 
Signed-off-by: Yoshihiro Shimoda 
Reviewed-by: Matti Vaittinen 
---
 drivers/mfd/bd9571mwv.c   | 80 ++-
 include/linux/mfd/bd9571mwv.h | 17 +++--
 2 files changed, 93 insertions(+), 4 deletions(-)

diff --git a/drivers/mfd/bd9571mwv.c b/drivers/mfd/bd9571mwv.c
index c905ab4..b1e7ae9 100644
--- a/drivers/mfd/bd9571mwv.c
+++ b/drivers/mfd/bd9571mwv.c
@@ -1,6 +1,6 @@
 // SPDX-License-Identifier: GPL-2.0-only
 /*
- * ROHM BD9571MWV-M MFD driver
+ * ROHM BD9571MWV-M and BD9574MVF-M core driver
  *
  * Copyright (C) 2017 Marek Vasut 
  * Copyright (C) 2020 Renesas Electronics Corporation
@@ -11,6 +11,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 
 #include 
@@ -118,6 +119,79 @@ static const struct bd957x_ddata bd9571mwv_ddata = {
.num_cells = ARRAY_SIZE(bd9571mwv_cells),
 };
 
+static const struct mfd_cell bd9574mwf_cells[] = {
+   { .name = "bd9574mwf-regulator", },
+   { .name = "bd9574mwf-gpio", },
+};
+
+static const struct regmap_range bd9574mwf_readable_yes_ranges[] = {
+   regmap_reg_range(BD9571MWV_VENDOR_CODE, BD9571MWV_PRODUCT_REVISION),
+   regmap_reg_range(BD9571MWV_BKUP_MODE_CNT, BD9571MWV_BKUP_MODE_CNT),
+   regmap_reg_range(BD9571MWV_DVFS_VINIT, BD9571MWV_DVFS_SETVMAX),
+   regmap_reg_range(BD9571MWV_DVFS_SETVID, BD9571MWV_DVFS_MONIVDAC),
+   regmap_reg_range(BD9571MWV_GPIO_IN, BD9571MWV_GPIO_IN),
+   regmap_reg_range(BD9571MWV_GPIO_INT, BD9571MWV_GPIO_INTMASK),
+   regmap_reg_range(BD9571MWV_INT_INTREQ, BD9571MWV_INT_INTMASK),
+};
+
+static const struct regmap_access_table bd9574mwf_readable_table = {
+   .yes_ranges = bd9574mwf_readable_yes_ranges,
+   .n_yes_ranges   = ARRAY_SIZE(bd9574mwf_readable_yes_ranges),
+};
+
+static const struct regmap_range bd9574mwf_writable_yes_ranges[] = {
+   regmap_reg_range(BD9571MWV_BKUP_MODE_CNT, BD9571MWV_BKUP_MODE_CNT),
+   regmap_reg_range(BD9571MWV_DVFS_SETVID, BD9571MWV_DVFS_SETVID),
+   regmap_reg_range(BD9571MWV_GPIO_DIR, BD9571MWV_GPIO_OUT),
+   regmap_reg_range(BD9571MWV_GPIO_INT_SET, BD9571MWV_GPIO_INTMASK),
+   regmap_reg_range(BD9571MWV_INT_INTREQ, BD9571MWV_INT_INTMASK),
+};
+
+static const struct regmap_access_table bd9574mwf_writable_table = {
+   .yes_ranges = bd9574mwf_writable_yes_ranges,
+   .n_yes_ranges   = ARRAY_SIZE(bd9574mwf_writable_yes_ranges),
+};
+
+static const struct regmap_range bd9574mwf_volatile_yes_ranges[] = {
+   regmap_reg_range(BD9571MWV_DVFS_MONIVDAC, BD9571MWV_DVFS_MONIVDAC),
+   regmap_reg_range(BD9571MWV_GPIO_IN, BD9571MWV_GPIO_IN),
+   regmap_reg_range(BD9571MWV_GPIO_INT, BD9571MWV_GPIO_INT),
+   regmap_reg_range(BD9571MWV_INT_INTREQ, BD9571MWV_INT_INTREQ),
+};
+
+static const struct regmap_access_table bd9574mwf_volatile_table = {
+   .yes_ranges = bd9574mwf_volatile_yes_ranges,
+   .n_yes_ranges   = ARRAY_SIZE(bd9574mwf_volatile_yes_ranges),
+};
+
+static const struct regmap_config bd9574mwf_regmap_config = {
+   .reg_bits   = 8,
+   .val_bits   = 8,
+   .cache_type = REGCACHE_RBTREE,
+   .rd_table   = _readable_table,
+   .wr_table   = _writable_table,
+   .volatile_table = _volatile_table,
+   .max_register   = 0xff,
+};
+
+static struct regmap_irq_chip bd9574mwf_irq_chip = {
+   .name   = "bd9574mwf",
+   .status_base= BD9571MWV_INT_INTREQ,
+   .mask_base  = BD9571MWV_INT_INTMASK,
+   .ack_base   = BD9571MWV_INT_INTREQ,
+   .init_ack_masked = true,
+   .num_regs   = 1,
+   .irqs   = bd9571mwv_irqs,
+   .num_irqs   = ARRAY_SIZE(bd9571mwv_irqs),
+};
+
+static const struct bd957x_ddata bd9574mwf_ddata = {
+   .regmap_config = _regmap_config,
+   .irq_chip = _irq_chip,
+   .cells = bd9574mwf_cells,
+   .num_cells = ARRAY_SIZE(bd9574mwf_cells),
+};
+
 static int bd957x_identify(struct device *dev, struct regmap *regmap)
 {
unsigned int value;
@@ -171,6 +245,9 @@ static int bd9571mwv_probe(struct i2c_client *client,
case BD9571MWV_PRODUCT_CODE_BD9571MWV:
ddata = _ddata;
break;
+   case BD9571MWV_PRODUCT_CODE_BD9574MWF:
+   ddata = _ddata;
+   break;
default:
dev_err(dev, "Unsupported device 0x%x\n", ret);
return -ENODEV;
@@ -200,6 +277,7 @@ static int bd9571mwv_probe(struct i2c_client *client,
 
 static const struct of_device_id bd9571mwv_of_match_table[] = {
{ .compatible = "rohm,bd9571mwv", },
+   { .compatible = "rohm,bd9574mwf", },
{ /* sentinel */ }
 };
 MODULE_DEVICE_TABLE(of, bd9571mwv_of_match_table);
di

[PATCH v5 05/12] regulator: bd9571mwv: Add BD9574MWF support

2020-12-22 Thread Yoshihiro Shimoda
Add support for BD9574MWF which is silimar chip with BD9571MWV.
Note that we don't support voltage rails VD{09,18,25,33} by this
driver on BD9574. The VD09 voltage could be read from PMIC but that
is not supported by this commit.

Signed-off-by: Yoshihiro Shimoda 
Reviewed-by: Matti Vaittinen 
---
 drivers/regulator/bd9571mwv-regulator.c | 10 --
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/drivers/regulator/bd9571mwv-regulator.c 
b/drivers/regulator/bd9571mwv-regulator.c
index 42b6a70..7b0cd08 100644
--- a/drivers/regulator/bd9571mwv-regulator.c
+++ b/drivers/regulator/bd9571mwv-regulator.c
@@ -1,6 +1,6 @@
 // SPDX-License-Identifier: GPL-2.0
 /*
- * ROHM BD9571MWV-M regulator driver
+ * ROHM BD9571MWV-M and BD9574MWF-M regulator driver
  *
  * Copyright (C) 2017 Marek Vasut 
  *
@@ -9,6 +9,7 @@
  * NOTE: VD09 is missing
  */
 
+#include 
 #include 
 #include 
 #include 
@@ -277,6 +278,7 @@ static int bd9571mwv_regulator_probe(struct platform_device 
*pdev)
struct regulator_dev *rdev;
unsigned int val;
int i;
+   enum rohm_chip_type chip = platform_get_device_id(pdev)->driver_data;
 
bdreg = devm_kzalloc(>dev, sizeof(*bdreg), GFP_KERNEL);
if (!bdreg)
@@ -292,6 +294,9 @@ static int bd9571mwv_regulator_probe(struct platform_device 
*pdev)
config.regmap = bdreg->regmap;
 
for (i = 0; i < ARRAY_SIZE(regulators); i++) {
+   /* BD9574MWF supports DVFS only */
+   if (chip == ROHM_CHIP_TYPE_BD9574 && regulators[i].id != DVFS)
+   continue;
rdev = devm_regulator_register(>dev, [i],
   );
if (IS_ERR(rdev)) {
@@ -339,7 +344,8 @@ static int bd9571mwv_regulator_probe(struct platform_device 
*pdev)
 }
 
 static const struct platform_device_id bd9571mwv_regulator_id_table[] = {
-   { "bd9571mwv-regulator", },
+   { "bd9571mwv-regulator", ROHM_CHIP_TYPE_BD9571 },
+   { "bd9574mwf-regulator", ROHM_CHIP_TYPE_BD9574 },
{ /* sentinel */ }
 };
 MODULE_DEVICE_TABLE(platform, bd9571mwv_regulator_id_table);
-- 
2.7.4



[PATCH v5 06/12] gpio: bd9571mwv: Use the SPDX license identifier

2020-12-22 Thread Yoshihiro Shimoda
Use the SPDX license identifier instead of a local description.

Signed-off-by: Yoshihiro Shimoda 
Reviewed-by: Geert Uytterhoeven 
---
 drivers/gpio/gpio-bd9571mwv.c | 10 +-
 1 file changed, 1 insertion(+), 9 deletions(-)

diff --git a/drivers/gpio/gpio-bd9571mwv.c b/drivers/gpio/gpio-bd9571mwv.c
index c0abc9c..abb622c 100644
--- a/drivers/gpio/gpio-bd9571mwv.c
+++ b/drivers/gpio/gpio-bd9571mwv.c
@@ -1,17 +1,9 @@
+// SPDX-License-Identifier: GPL-2.0-only
 /*
  * ROHM BD9571MWV-M GPIO driver
  *
  * Copyright (C) 2017 Marek Vasut 
  *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License version 2 as
- * published by the Free Software Foundation.
- *
- * This program is distributed "as is" WITHOUT ANY WARRANTY of any
- * kind, whether expressed or implied; without even the implied warranty
- * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License version 2 for more details.
- *
  * Based on the TPS65086 driver
  *
  * NOTE: Interrupts are not supported yet.
-- 
2.7.4



[PATCH v5 07/12] gpio: bd9571mwv: rid of using struct bd9571mwv

2020-12-22 Thread Yoshihiro Shimoda
To simplify this driver, use dev_get_regmap() and
rid of using struct bd9571mwv.

Signed-off-by: Yoshihiro Shimoda 
Reviewed-by: Matti Vaittinen 
---
 drivers/gpio/gpio-bd9571mwv.c | 19 +--
 1 file changed, 9 insertions(+), 10 deletions(-)

diff --git a/drivers/gpio/gpio-bd9571mwv.c b/drivers/gpio/gpio-bd9571mwv.c
index abb622c..0e5395f 100644
--- a/drivers/gpio/gpio-bd9571mwv.c
+++ b/drivers/gpio/gpio-bd9571mwv.c
@@ -16,8 +16,8 @@
 #include 
 
 struct bd9571mwv_gpio {
+   struct regmap *regmap;
struct gpio_chip chip;
-   struct bd9571mwv *bd;
 };
 
 static int bd9571mwv_gpio_get_direction(struct gpio_chip *chip,
@@ -26,7 +26,7 @@ static int bd9571mwv_gpio_get_direction(struct gpio_chip 
*chip,
struct bd9571mwv_gpio *gpio = gpiochip_get_data(chip);
int ret, val;
 
-   ret = regmap_read(gpio->bd->regmap, BD9571MWV_GPIO_DIR, );
+   ret = regmap_read(gpio->regmap, BD9571MWV_GPIO_DIR, );
if (ret < 0)
return ret;
if (val & BIT(offset))
@@ -40,8 +40,7 @@ static int bd9571mwv_gpio_direction_input(struct gpio_chip 
*chip,
 {
struct bd9571mwv_gpio *gpio = gpiochip_get_data(chip);
 
-   regmap_update_bits(gpio->bd->regmap, BD9571MWV_GPIO_DIR,
-  BIT(offset), 0);
+   regmap_update_bits(gpio->regmap, BD9571MWV_GPIO_DIR, BIT(offset), 0);
 
return 0;
 }
@@ -52,9 +51,9 @@ static int bd9571mwv_gpio_direction_output(struct gpio_chip 
*chip,
struct bd9571mwv_gpio *gpio = gpiochip_get_data(chip);
 
/* Set the initial value */
-   regmap_update_bits(gpio->bd->regmap, BD9571MWV_GPIO_OUT,
+   regmap_update_bits(gpio->regmap, BD9571MWV_GPIO_OUT,
   BIT(offset), value ? BIT(offset) : 0);
-   regmap_update_bits(gpio->bd->regmap, BD9571MWV_GPIO_DIR,
+   regmap_update_bits(gpio->regmap, BD9571MWV_GPIO_DIR,
   BIT(offset), BIT(offset));
 
return 0;
@@ -65,7 +64,7 @@ static int bd9571mwv_gpio_get(struct gpio_chip *chip, 
unsigned int offset)
struct bd9571mwv_gpio *gpio = gpiochip_get_data(chip);
int ret, val;
 
-   ret = regmap_read(gpio->bd->regmap, BD9571MWV_GPIO_IN, );
+   ret = regmap_read(gpio->regmap, BD9571MWV_GPIO_IN, );
if (ret < 0)
return ret;
 
@@ -77,7 +76,7 @@ static void bd9571mwv_gpio_set(struct gpio_chip *chip, 
unsigned int offset,
 {
struct bd9571mwv_gpio *gpio = gpiochip_get_data(chip);
 
-   regmap_update_bits(gpio->bd->regmap, BD9571MWV_GPIO_OUT,
+   regmap_update_bits(gpio->regmap, BD9571MWV_GPIO_OUT,
   BIT(offset), value ? BIT(offset) : 0);
 }
 
@@ -105,9 +104,9 @@ static int bd9571mwv_gpio_probe(struct platform_device 
*pdev)
 
platform_set_drvdata(pdev, gpio);
 
-   gpio->bd = dev_get_drvdata(pdev->dev.parent);
+   gpio->regmap = dev_get_regmap(pdev->dev.parent, NULL);
gpio->chip = template_chip;
-   gpio->chip.parent = gpio->bd->dev;
+   gpio->chip.parent = pdev->dev.parent;
 
ret = devm_gpiochip_add_data(>dev, >chip, gpio);
if (ret < 0) {
-- 
2.7.4



[PATCH v5 10/12] mfd: bd9571mwv: Use devm_regmap_add_irq_chip()

2020-12-22 Thread Yoshihiro Shimoda
Use dev_regmap_add_irq_chip() to simplify the code.

Signed-off-by: Yoshihiro Shimoda 
Acked-for-MFD-by: Lee Jones 
Reviewed-by: Matti Vaittinen 
Reviewed-by: Geert Uytterhoeven 
---
 drivers/mfd/bd9571mwv.c | 27 ++-
 1 file changed, 6 insertions(+), 21 deletions(-)

diff --git a/drivers/mfd/bd9571mwv.c b/drivers/mfd/bd9571mwv.c
index e68c3fa..49e968e 100644
--- a/drivers/mfd/bd9571mwv.c
+++ b/drivers/mfd/bd9571mwv.c
@@ -170,31 +170,17 @@ static int bd9571mwv_probe(struct i2c_client *client,
if (ret)
return ret;
 
-   ret = regmap_add_irq_chip(bd->regmap, bd->irq, IRQF_ONESHOT, 0,
- _irq_chip, >irq_data);
+   ret = devm_regmap_add_irq_chip(bd->dev, bd->regmap, bd->irq,
+  IRQF_ONESHOT, 0, _irq_chip,
+  >irq_data);
if (ret) {
dev_err(bd->dev, "Failed to register IRQ chip\n");
return ret;
}
 
-   ret = devm_mfd_add_devices(bd->dev, PLATFORM_DEVID_AUTO,
-  bd9571mwv_cells, ARRAY_SIZE(bd9571mwv_cells),
-  NULL, 0, 
regmap_irq_get_domain(bd->irq_data));
-   if (ret) {
-   regmap_del_irq_chip(bd->irq, bd->irq_data);
-   return ret;
-   }
-
-   return 0;
-}
-
-static int bd9571mwv_remove(struct i2c_client *client)
-{
-   struct bd9571mwv *bd = i2c_get_clientdata(client);
-
-   regmap_del_irq_chip(bd->irq, bd->irq_data);
-
-   return 0;
+   return devm_mfd_add_devices(bd->dev, PLATFORM_DEVID_AUTO,
+   bd9571mwv_cells, 
ARRAY_SIZE(bd9571mwv_cells),
+   NULL, 0, 
regmap_irq_get_domain(bd->irq_data));
 }
 
 static const struct of_device_id bd9571mwv_of_match_table[] = {
@@ -215,7 +201,6 @@ static struct i2c_driver bd9571mwv_driver = {
.of_match_table = bd9571mwv_of_match_table,
},
.probe  = bd9571mwv_probe,
-   .remove = bd9571mwv_remove,
.id_table   = bd9571mwv_id_table,
 };
 module_i2c_driver(bd9571mwv_driver);
-- 
2.7.4



[PATCH v5 11/12] mfd: bd9571mwv: Make the driver more generic

2020-12-22 Thread Yoshihiro Shimoda
From: Khiem Nguyen 

Since the driver supports BD9571MWV PMIC only, this patch makes
the functions and data structure become more generic so that
it can support other PMIC variants as well. Also remove printing
part name which Lee Jones suggested.

Signed-off-by: Khiem Nguyen 
Co-developed-by: Yoshihiro Shimoda 
Signed-off-by: Yoshihiro Shimoda 
Reviewed-by: Matti Vaittinen 
---
 drivers/mfd/bd9571mwv.c   | 89 +--
 include/linux/mfd/bd9571mwv.h | 18 +
 2 files changed, 54 insertions(+), 53 deletions(-)

diff --git a/drivers/mfd/bd9571mwv.c b/drivers/mfd/bd9571mwv.c
index 49e968e..c905ab4 100644
--- a/drivers/mfd/bd9571mwv.c
+++ b/drivers/mfd/bd9571mwv.c
@@ -3,6 +3,7 @@
  * ROHM BD9571MWV-M MFD driver
  *
  * Copyright (C) 2017 Marek Vasut 
+ * Copyright (C) 2020 Renesas Electronics Corporation
  *
  * Based on the TPS65086 driver
  */
@@ -14,6 +15,14 @@
 
 #include 
 
+/* Driver data to distinguish bd957x variants */
+struct bd957x_ddata {
+   const struct regmap_config *regmap_config;
+   const struct regmap_irq_chip *irq_chip;
+   const struct mfd_cell *cells;
+   int num_cells;
+};
+
 static const struct mfd_cell bd9571mwv_cells[] = {
{ .name = "bd9571mwv-regulator", },
{ .name = "bd9571mwv-gpio", },
@@ -102,13 +111,19 @@ static struct regmap_irq_chip bd9571mwv_irq_chip = {
.num_irqs   = ARRAY_SIZE(bd9571mwv_irqs),
 };
 
-static int bd9571mwv_identify(struct bd9571mwv *bd)
+static const struct bd957x_ddata bd9571mwv_ddata = {
+   .regmap_config = _regmap_config,
+   .irq_chip = _irq_chip,
+   .cells = bd9571mwv_cells,
+   .num_cells = ARRAY_SIZE(bd9571mwv_cells),
+};
+
+static int bd957x_identify(struct device *dev, struct regmap *regmap)
 {
-   struct device *dev = bd->dev;
unsigned int value;
int ret;
 
-   ret = regmap_read(bd->regmap, BD9571MWV_VENDOR_CODE, );
+   ret = regmap_read(regmap, BD9571MWV_VENDOR_CODE, );
if (ret) {
dev_err(dev, "Failed to read vendor code register (ret=%i)\n",
ret);
@@ -121,66 +136,66 @@ static int bd9571mwv_identify(struct bd9571mwv *bd)
return -EINVAL;
}
 
-   ret = regmap_read(bd->regmap, BD9571MWV_PRODUCT_CODE, );
+   ret = regmap_read(regmap, BD9571MWV_PRODUCT_CODE, );
if (ret) {
dev_err(dev, "Failed to read product code register (ret=%i)\n",
ret);
return ret;
}
-
-   if (value != BD9571MWV_PRODUCT_CODE_VAL) {
-   dev_err(dev, "Invalid product code ID %02x (expected %02x)\n",
-   value, BD9571MWV_PRODUCT_CODE_VAL);
-   return -EINVAL;
-   }
-
-   ret = regmap_read(bd->regmap, BD9571MWV_PRODUCT_REVISION, );
+   ret = regmap_read(regmap, BD9571MWV_PRODUCT_REVISION, );
if (ret) {
dev_err(dev, "Failed to read revision register (ret=%i)\n",
ret);
return ret;
}
 
-   dev_info(dev, "Device: BD9571MWV rev. %d\n", value & 0xff);
-
return 0;
 }
 
 static int bd9571mwv_probe(struct i2c_client *client,
- const struct i2c_device_id *ids)
+  const struct i2c_device_id *ids)
 {
-   struct bd9571mwv *bd;
-   int ret;
-
-   bd = devm_kzalloc(>dev, sizeof(*bd), GFP_KERNEL);
-   if (!bd)
-   return -ENOMEM;
-
-   i2c_set_clientdata(client, bd);
-   bd->dev = >dev;
-   bd->irq = client->irq;
+   const struct bd957x_ddata *ddata;
+   struct device *dev = >dev;
+   struct regmap *regmap;
+   struct regmap_irq_chip_data *irq_data;
+   int ret, irq = client->irq;
+
+   /* Read the PMIC product code */
+   ret = i2c_smbus_read_byte_data(client, BD9571MWV_PRODUCT_CODE);
+   if (ret < 0) {
+   dev_err(dev, "Failed to read product code\n");
+   return ret;
+   }
+   switch (ret) {
+   case BD9571MWV_PRODUCT_CODE_BD9571MWV:
+   ddata = _ddata;
+   break;
+   default:
+   dev_err(dev, "Unsupported device 0x%x\n", ret);
+   return -ENODEV;
+   }
 
-   bd->regmap = devm_regmap_init_i2c(client, _regmap_config);
-   if (IS_ERR(bd->regmap)) {
-   dev_err(bd->dev, "Failed to initialize register map\n");
-   return PTR_ERR(bd->regmap);
+   regmap = devm_regmap_init_i2c(client, ddata->regmap_config);
+   if (IS_ERR(regmap)) {
+   dev_err(dev, "Failed to initialize register map\n");
+   return PTR_ERR(regmap);
}
 
-   ret = bd9571mwv_identify(bd);
+   ret = bd957x_identify(dev, regmap);
if (ret)

[PATCH v5 08/12] gpio: bd9571mwv: Add BD9574MWF support

2020-12-22 Thread Yoshihiro Shimoda
Add support for BD9574MWF which is silimar chip with BD9571MWV.
Note that BD9574MWF has additional features "RECOV_GPOUT",
"FREQSEL" and "RTC_IN", but supports GPIO function only.

Signed-off-by: Yoshihiro Shimoda 
Reviewed-by: Matti Vaittinen 
---
 drivers/gpio/gpio-bd9571mwv.c | 6 --
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/drivers/gpio/gpio-bd9571mwv.c b/drivers/gpio/gpio-bd9571mwv.c
index 0e5395f..df6102b 100644
--- a/drivers/gpio/gpio-bd9571mwv.c
+++ b/drivers/gpio/gpio-bd9571mwv.c
@@ -1,6 +1,6 @@
 // SPDX-License-Identifier: GPL-2.0-only
 /*
- * ROHM BD9571MWV-M GPIO driver
+ * ROHM BD9571MWV-M and BD9574MWF-M GPIO driver
  *
  * Copyright (C) 2017 Marek Vasut 
  *
@@ -10,6 +10,7 @@
  */
 
 #include 
+#include 
 #include 
 #include 
 
@@ -118,7 +119,8 @@ static int bd9571mwv_gpio_probe(struct platform_device 
*pdev)
 }
 
 static const struct platform_device_id bd9571mwv_gpio_id_table[] = {
-   { "bd9571mwv-gpio", },
+   { "bd9571mwv-gpio", ROHM_CHIP_TYPE_BD9571 },
+   { "bd9574mwf-gpio", ROHM_CHIP_TYPE_BD9574 },
{ /* sentinel */ }
 };
 MODULE_DEVICE_TABLE(platform, bd9571mwv_gpio_id_table);
-- 
2.7.4



[PATCH v5 09/12] mfd: bd9571mwv: Use the SPDX license identifier

2020-12-22 Thread Yoshihiro Shimoda
Use the SPDX license identifier instead of a local description.

Signed-off-by: Yoshihiro Shimoda 
Reviewed-by: Geert Uytterhoeven 
Acked-for-MFD-by: Lee Jones 
---
 drivers/mfd/bd9571mwv.c   | 10 +-
 include/linux/mfd/bd9571mwv.h | 10 +-
 2 files changed, 2 insertions(+), 18 deletions(-)

diff --git a/drivers/mfd/bd9571mwv.c b/drivers/mfd/bd9571mwv.c
index 19d57a4..e68c3fa 100644
--- a/drivers/mfd/bd9571mwv.c
+++ b/drivers/mfd/bd9571mwv.c
@@ -1,17 +1,9 @@
+// SPDX-License-Identifier: GPL-2.0-only
 /*
  * ROHM BD9571MWV-M MFD driver
  *
  * Copyright (C) 2017 Marek Vasut 
  *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License version 2 as
- * published by the Free Software Foundation.
- *
- * This program is distributed "as is" WITHOUT ANY WARRANTY of any
- * kind, whether expressed or implied; without even the implied warranty
- * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License version 2 for more details.
- *
  * Based on the TPS65086 driver
  */
 
diff --git a/include/linux/mfd/bd9571mwv.h b/include/linux/mfd/bd9571mwv.h
index eb05569..bcc7092 100644
--- a/include/linux/mfd/bd9571mwv.h
+++ b/include/linux/mfd/bd9571mwv.h
@@ -1,17 +1,9 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
 /*
  * ROHM BD9571MWV-M driver
  *
  * Copyright (C) 2017 Marek Vasut 
  *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License version 2 as
- * published by the Free Software Foundation.
- *
- * This program is distributed "as is" WITHOUT ANY WARRANTY of any
- * kind, whether expressed or implied; without even the implied warranty
- * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License version 2 for more details.
- *
  * Based on the TPS65086 driver
  */
 
-- 
2.7.4



[PATCH v5 02/12] dt-bindings: mfd: bd9571mwv: Document BD9574MWF

2020-12-22 Thread Yoshihiro Shimoda
Document other similar specification chip BD9574MWF.

Signed-off-by: Yoshihiro Shimoda 
---
 Documentation/devicetree/bindings/mfd/bd9571mwv.txt | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/Documentation/devicetree/bindings/mfd/bd9571mwv.txt 
b/Documentation/devicetree/bindings/mfd/bd9571mwv.txt
index 8c46786..1d6413e 100644
--- a/Documentation/devicetree/bindings/mfd/bd9571mwv.txt
+++ b/Documentation/devicetree/bindings/mfd/bd9571mwv.txt
@@ -1,7 +1,7 @@
-* ROHM BD9571MWV Power Management Integrated Circuit (PMIC) bindings
+* ROHM BD9571MWV/BD9574MWF Power Management Integrated Circuit (PMIC) bindings
 
 Required properties:
- - compatible  : Should be "rohm,bd9571mwv".
+ - compatible  : Should be "rohm,bd9571mwv" or "rohm,bd9574mwf".
  - reg : I2C slave address.
  - interrupts  : The interrupt line the device is connected to.
  - interrupt-controller: Marks the device node as an interrupt 
controller.
-- 
2.7.4



[PATCH v5 01/12] mfd: bd9571mwv: Use devm_mfd_add_devices()

2020-12-22 Thread Yoshihiro Shimoda
To remove mfd devices when unload this driver, should use
devm_mfd_add_devices() instead.

Fixes: d3ea21272094 ("mfd: Add ROHM BD9571MWV-M MFD PMIC driver")
Signed-off-by: Yoshihiro Shimoda 
Acked-for-MFD-by: Lee Jones 
Reviewed-by: Geert Uytterhoeven 
Reviewed-by: Matti Vaittinen 
---
 drivers/mfd/bd9571mwv.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/mfd/bd9571mwv.c b/drivers/mfd/bd9571mwv.c
index fab3cdc..19d57a4 100644
--- a/drivers/mfd/bd9571mwv.c
+++ b/drivers/mfd/bd9571mwv.c
@@ -185,9 +185,9 @@ static int bd9571mwv_probe(struct i2c_client *client,
return ret;
}
 
-   ret = mfd_add_devices(bd->dev, PLATFORM_DEVID_AUTO, bd9571mwv_cells,
- ARRAY_SIZE(bd9571mwv_cells), NULL, 0,
- regmap_irq_get_domain(bd->irq_data));
+   ret = devm_mfd_add_devices(bd->dev, PLATFORM_DEVID_AUTO,
+  bd9571mwv_cells, ARRAY_SIZE(bd9571mwv_cells),
+  NULL, 0, 
regmap_irq_get_domain(bd->irq_data));
if (ret) {
regmap_del_irq_chip(bd->irq, bd->irq_data);
return ret;
-- 
2.7.4



RE: [PATCH v4 10/12] mfd: bd9571mwv: Use devm_regmap_add_irq_chip()

2020-12-22 Thread Yoshihiro Shimoda
Hi Matti-san,

> From: Vaittinen, Matti, Sent: Tuesday, December 22, 2020 6:39 PM
> 
> On Tue, 2020-12-22 at 09:25 +, Yoshihiro Shimoda wrote:
> > Hi Matti-san,
> >
> > > From: Vaittinen, Matti, Sent: Tuesday, December 22, 2020 6:15 PM
> > >
> > > On Tue, 2020-12-22 at 09:49 +0100, Geert Uytterhoeven wrote:
> > > > On Mon, Dec 21, 2020 at 3:57 AM Yoshihiro Shimoda
> > > >  wrote:

> > > I thought I did review this earlier...
> >
> > You're correct. I'm sorry, I completely overlooked your Reviewed-by
> > tag in previous.
> 
> It happens :) But of you re-spin the series, please revise the tags for
> patches. I think I did review almost all of them (except the SPDX-
> patches as I am not competent on licenses...)

I got it. I'll add your Reviewed-by tags.

Best regards,
Yoshihiro Shimoda



RE: [PATCH v4 12/12] mfd: bd9571mwv: Add support for BD9574MWF

2020-12-22 Thread Yoshihiro Shimoda
Hi Matti-san,

> From: Vaittinen, Matti, Sent: Tuesday, December 22, 2020 6:39 PM

> > Also, I think I should remove the following patch.
> >
> > [PATCH v4 08/12] gpio: bd9571mwv: Add BD9574MWF support
> 
> I think this depends on whether you wish to add support for the
> 
> > "RECOV_GPOUT", "FREQSEL" and "RTC_IN",
> 
> which you mention in GPIO commit message. If you plan on adding the
> support, then you need to differentiate the ICs on GPIO driver, right?

Thank you for the reply.
As I replied to Geert-san, at least this MFD driver uses "bd9574mwf-gpio"
for probing. So, I'll keep that patch as-is.

Best regards,
Yoshihiro Shimoda



RE: [PATCH v4 12/12] mfd: bd9571mwv: Add support for BD9574MWF

2020-12-22 Thread Yoshihiro Shimoda
Hi Geert-san,

> From: Geert Uytterhoeven, Sent: Tuesday, December 22, 2020 6:32 PM

> > Also, I think I should remove the following patch.
> >
> > [PATCH v4 08/12] gpio: bd9571mwv: Add BD9574MWF support
> 
> You mean removing the chip types from bd9571mwv_gpio_id_table[]?
> You still need the "bd9574mwf-gpio" entry, don't you?

You're correct. The MFD driver uses "bd9574mwf-gpio". And,
"bd9574mwf-gpio" with 0 is not good. So, I'll keep this patch.
Thank you for the point it out.

Best regards,
Yoshihiro Shimoda



RE: [PATCH v4 10/12] mfd: bd9571mwv: Use devm_regmap_add_irq_chip()

2020-12-22 Thread Yoshihiro Shimoda
Hi Matti-san,

> From: Vaittinen, Matti, Sent: Tuesday, December 22, 2020 6:15 PM
> 
> On Tue, 2020-12-22 at 09:49 +0100, Geert Uytterhoeven wrote:
> > On Mon, Dec 21, 2020 at 3:57 AM Yoshihiro Shimoda
> >  wrote:
> > > Use dev_regmap_add_irq_chip() to simplify the code.
> > >
> > > Signed-off-by: Yoshihiro Shimoda 
> > > Acked-for-MFD-by: Lee Jones 
> >
> > Reviewed-by: Geert Uytterhoeven 
> Reviewed-by: Matti Vaittinen 

Thank you for your review!

> I thought I did review this earlier...

You're correct. I'm sorry, I completely overlooked your Reviewed-by
tag in previous.

Best regards,
Yoshihiro Shimoda



RE: [PATCH v4 12/12] mfd: bd9571mwv: Add support for BD9574MWF

2020-12-22 Thread Yoshihiro Shimoda
Hi Geert-san,

Thank you for your review!

> From: Geert Uytterhoeven, Sent: Tuesday, December 22, 2020 5:53 PM
> On Mon, Dec 21, 2020 at 3:56 AM Yoshihiro Shimoda
>  wrote:

> > --- a/drivers/mfd/bd9571mwv.c
> > +++ b/drivers/mfd/bd9571mwv.c
> 
> > @@ -200,12 +277,14 @@ static int bd9571mwv_probe(struct i2c_client *client,
> >
> >  static const struct of_device_id bd9571mwv_of_match_table[] = {
> > { .compatible = "rohm,bd9571mwv", },
> > +   { .compatible = "rohm,bd9574mwf", },
> > { /* sentinel */ }
> >  };
> >  MODULE_DEVICE_TABLE(of, bd9571mwv_of_match_table);
> >
> >  static const struct i2c_device_id bd9571mwv_id_table[] = {
> > -   { "bd9571mwv", 0 },
> > +   { "bd9571mwv", ROHM_CHIP_TYPE_BD9571 },
> > +   { "bd9574mwf", ROHM_CHIP_TYPE_BD9574 },
> 
> Why add the chip types?  These are unused, and the driver uses
> autodetection of the chip variant anyway.

I just added the chip types in the future use. As you said,
these are unused and we should not add a future use in general.
So, I'll remove this change.

Also, I think I should remove the following patch.

[PATCH v4 08/12] gpio: bd9571mwv: Add BD9574MWF support

Best regards,
Yoshihiro Shimoda



[PATCH v4 03/12] mfd: rohm-generic: Add BD9571 and BD9574

2020-12-20 Thread Yoshihiro Shimoda
Add chip IDs for BD9571MWV and BD9574MWF.

Signed-off-by: Yoshihiro Shimoda 
Reviewed-by: Matti Vaittinen 
Acked-for-MFD-by: Lee Jones 
---
 include/linux/mfd/rohm-generic.h | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/include/linux/mfd/rohm-generic.h b/include/linux/mfd/rohm-generic.h
index 4283b5b..affacf8 100644
--- a/include/linux/mfd/rohm-generic.h
+++ b/include/linux/mfd/rohm-generic.h
@@ -12,6 +12,8 @@ enum rohm_chip_type {
ROHM_CHIP_TYPE_BD71847,
ROHM_CHIP_TYPE_BD70528,
ROHM_CHIP_TYPE_BD71828,
+   ROHM_CHIP_TYPE_BD9571,
+   ROHM_CHIP_TYPE_BD9574,
ROHM_CHIP_TYPE_AMOUNT
 };
 
-- 
2.7.4



[PATCH v4 05/12] regulator: bd9571mwv: Add BD9574MWF support

2020-12-20 Thread Yoshihiro Shimoda
Add support for BD9574MWF which is silimar chip with BD9571MWV.
Note that we don't support voltage rails VD{09,18,25,33} by this
driver on BD9574. The VD09 voltage could be read from PMIC but that
is not supported by this commit.

Signed-off-by: Yoshihiro Shimoda 
Reviewed-by: Matti Vaittinen 
---
 drivers/regulator/bd9571mwv-regulator.c | 10 --
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/drivers/regulator/bd9571mwv-regulator.c 
b/drivers/regulator/bd9571mwv-regulator.c
index 42b6a70..7b0cd08 100644
--- a/drivers/regulator/bd9571mwv-regulator.c
+++ b/drivers/regulator/bd9571mwv-regulator.c
@@ -1,6 +1,6 @@
 // SPDX-License-Identifier: GPL-2.0
 /*
- * ROHM BD9571MWV-M regulator driver
+ * ROHM BD9571MWV-M and BD9574MWF-M regulator driver
  *
  * Copyright (C) 2017 Marek Vasut 
  *
@@ -9,6 +9,7 @@
  * NOTE: VD09 is missing
  */
 
+#include 
 #include 
 #include 
 #include 
@@ -277,6 +278,7 @@ static int bd9571mwv_regulator_probe(struct platform_device 
*pdev)
struct regulator_dev *rdev;
unsigned int val;
int i;
+   enum rohm_chip_type chip = platform_get_device_id(pdev)->driver_data;
 
bdreg = devm_kzalloc(>dev, sizeof(*bdreg), GFP_KERNEL);
if (!bdreg)
@@ -292,6 +294,9 @@ static int bd9571mwv_regulator_probe(struct platform_device 
*pdev)
config.regmap = bdreg->regmap;
 
for (i = 0; i < ARRAY_SIZE(regulators); i++) {
+   /* BD9574MWF supports DVFS only */
+   if (chip == ROHM_CHIP_TYPE_BD9574 && regulators[i].id != DVFS)
+   continue;
rdev = devm_regulator_register(>dev, [i],
   );
if (IS_ERR(rdev)) {
@@ -339,7 +344,8 @@ static int bd9571mwv_regulator_probe(struct platform_device 
*pdev)
 }
 
 static const struct platform_device_id bd9571mwv_regulator_id_table[] = {
-   { "bd9571mwv-regulator", },
+   { "bd9571mwv-regulator", ROHM_CHIP_TYPE_BD9571 },
+   { "bd9574mwf-regulator", ROHM_CHIP_TYPE_BD9574 },
{ /* sentinel */ }
 };
 MODULE_DEVICE_TABLE(platform, bd9571mwv_regulator_id_table);
-- 
2.7.4



[PATCH v4 02/12] dt-bindings: mfd: bd9571mwv: Document BD9574MWF

2020-12-20 Thread Yoshihiro Shimoda
Document other similar specification chip BD9574MWF.

Signed-off-by: Yoshihiro Shimoda 
---
 Documentation/devicetree/bindings/mfd/bd9571mwv.txt | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/Documentation/devicetree/bindings/mfd/bd9571mwv.txt 
b/Documentation/devicetree/bindings/mfd/bd9571mwv.txt
index 8c46786..1d6413e 100644
--- a/Documentation/devicetree/bindings/mfd/bd9571mwv.txt
+++ b/Documentation/devicetree/bindings/mfd/bd9571mwv.txt
@@ -1,7 +1,7 @@
-* ROHM BD9571MWV Power Management Integrated Circuit (PMIC) bindings
+* ROHM BD9571MWV/BD9574MWF Power Management Integrated Circuit (PMIC) bindings
 
 Required properties:
- - compatible  : Should be "rohm,bd9571mwv".
+ - compatible  : Should be "rohm,bd9571mwv" or "rohm,bd9574mwf".
  - reg : I2C slave address.
  - interrupts  : The interrupt line the device is connected to.
  - interrupt-controller: Marks the device node as an interrupt 
controller.
-- 
2.7.4



[PATCH v4 12/12] mfd: bd9571mwv: Add support for BD9574MWF

2020-12-20 Thread Yoshihiro Shimoda
From: Khiem Nguyen 

The new PMIC BD9574MWF inherits features from BD9571MWV.
Add the support of new PMIC to existing bd9571mwv driver.

Signed-off-by: Khiem Nguyen 
Co-developed-by: Yoshihiro Shimoda 
Signed-off-by: Yoshihiro Shimoda 
---
 drivers/mfd/bd9571mwv.c   | 83 +--
 include/linux/mfd/bd9571mwv.h | 17 +++--
 2 files changed, 95 insertions(+), 5 deletions(-)

diff --git a/drivers/mfd/bd9571mwv.c b/drivers/mfd/bd9571mwv.c
index c905ab4..ab753a9 100644
--- a/drivers/mfd/bd9571mwv.c
+++ b/drivers/mfd/bd9571mwv.c
@@ -1,6 +1,6 @@
 // SPDX-License-Identifier: GPL-2.0-only
 /*
- * ROHM BD9571MWV-M MFD driver
+ * ROHM BD9571MWV-M and BD9574MVF-M core driver
  *
  * Copyright (C) 2017 Marek Vasut 
  * Copyright (C) 2020 Renesas Electronics Corporation
@@ -11,6 +11,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 
 #include 
@@ -118,6 +119,79 @@ static const struct bd957x_ddata bd9571mwv_ddata = {
.num_cells = ARRAY_SIZE(bd9571mwv_cells),
 };
 
+static const struct mfd_cell bd9574mwf_cells[] = {
+   { .name = "bd9574mwf-regulator", },
+   { .name = "bd9574mwf-gpio", },
+};
+
+static const struct regmap_range bd9574mwf_readable_yes_ranges[] = {
+   regmap_reg_range(BD9571MWV_VENDOR_CODE, BD9571MWV_PRODUCT_REVISION),
+   regmap_reg_range(BD9571MWV_BKUP_MODE_CNT, BD9571MWV_BKUP_MODE_CNT),
+   regmap_reg_range(BD9571MWV_DVFS_VINIT, BD9571MWV_DVFS_SETVMAX),
+   regmap_reg_range(BD9571MWV_DVFS_SETVID, BD9571MWV_DVFS_MONIVDAC),
+   regmap_reg_range(BD9571MWV_GPIO_IN, BD9571MWV_GPIO_IN),
+   regmap_reg_range(BD9571MWV_GPIO_INT, BD9571MWV_GPIO_INTMASK),
+   regmap_reg_range(BD9571MWV_INT_INTREQ, BD9571MWV_INT_INTMASK),
+};
+
+static const struct regmap_access_table bd9574mwf_readable_table = {
+   .yes_ranges = bd9574mwf_readable_yes_ranges,
+   .n_yes_ranges   = ARRAY_SIZE(bd9574mwf_readable_yes_ranges),
+};
+
+static const struct regmap_range bd9574mwf_writable_yes_ranges[] = {
+   regmap_reg_range(BD9571MWV_BKUP_MODE_CNT, BD9571MWV_BKUP_MODE_CNT),
+   regmap_reg_range(BD9571MWV_DVFS_SETVID, BD9571MWV_DVFS_SETVID),
+   regmap_reg_range(BD9571MWV_GPIO_DIR, BD9571MWV_GPIO_OUT),
+   regmap_reg_range(BD9571MWV_GPIO_INT_SET, BD9571MWV_GPIO_INTMASK),
+   regmap_reg_range(BD9571MWV_INT_INTREQ, BD9571MWV_INT_INTMASK),
+};
+
+static const struct regmap_access_table bd9574mwf_writable_table = {
+   .yes_ranges = bd9574mwf_writable_yes_ranges,
+   .n_yes_ranges   = ARRAY_SIZE(bd9574mwf_writable_yes_ranges),
+};
+
+static const struct regmap_range bd9574mwf_volatile_yes_ranges[] = {
+   regmap_reg_range(BD9571MWV_DVFS_MONIVDAC, BD9571MWV_DVFS_MONIVDAC),
+   regmap_reg_range(BD9571MWV_GPIO_IN, BD9571MWV_GPIO_IN),
+   regmap_reg_range(BD9571MWV_GPIO_INT, BD9571MWV_GPIO_INT),
+   regmap_reg_range(BD9571MWV_INT_INTREQ, BD9571MWV_INT_INTREQ),
+};
+
+static const struct regmap_access_table bd9574mwf_volatile_table = {
+   .yes_ranges = bd9574mwf_volatile_yes_ranges,
+   .n_yes_ranges   = ARRAY_SIZE(bd9574mwf_volatile_yes_ranges),
+};
+
+static const struct regmap_config bd9574mwf_regmap_config = {
+   .reg_bits   = 8,
+   .val_bits   = 8,
+   .cache_type = REGCACHE_RBTREE,
+   .rd_table   = _readable_table,
+   .wr_table   = _writable_table,
+   .volatile_table = _volatile_table,
+   .max_register   = 0xff,
+};
+
+static struct regmap_irq_chip bd9574mwf_irq_chip = {
+   .name   = "bd9574mwf",
+   .status_base= BD9571MWV_INT_INTREQ,
+   .mask_base  = BD9571MWV_INT_INTMASK,
+   .ack_base   = BD9571MWV_INT_INTREQ,
+   .init_ack_masked = true,
+   .num_regs   = 1,
+   .irqs   = bd9571mwv_irqs,
+   .num_irqs   = ARRAY_SIZE(bd9571mwv_irqs),
+};
+
+static const struct bd957x_ddata bd9574mwf_ddata = {
+   .regmap_config = _regmap_config,
+   .irq_chip = _irq_chip,
+   .cells = bd9574mwf_cells,
+   .num_cells = ARRAY_SIZE(bd9574mwf_cells),
+};
+
 static int bd957x_identify(struct device *dev, struct regmap *regmap)
 {
unsigned int value;
@@ -171,6 +245,9 @@ static int bd9571mwv_probe(struct i2c_client *client,
case BD9571MWV_PRODUCT_CODE_BD9571MWV:
ddata = _ddata;
break;
+   case BD9571MWV_PRODUCT_CODE_BD9574MWF:
+   ddata = _ddata;
+   break;
default:
dev_err(dev, "Unsupported device 0x%x\n", ret);
return -ENODEV;
@@ -200,12 +277,14 @@ static int bd9571mwv_probe(struct i2c_client *client,
 
 static const struct of_device_id bd9571mwv_of_match_table[] = {
{ .compatible = "rohm,bd9571mwv", },
+   { .compatible = "rohm,bd9574mwf", },
{ /* sentinel */ }
 };
 MODULE_DEVICE_TABLE(of, bd9571mwv_of_match_table);
 
 static const struct i2c

[PATCH v4 08/12] gpio: bd9571mwv: Add BD9574MWF support

2020-12-20 Thread Yoshihiro Shimoda
Add support for BD9574MWF which is silimar chip with BD9571MWV.
Note that BD9574MWF has additional features "RECOV_GPOUT",
"FREQSEL" and "RTC_IN", but supports GPIO function only.

Signed-off-by: Yoshihiro Shimoda 
Reviewed-by: Matti Vaittinen 
---
 drivers/gpio/gpio-bd9571mwv.c | 6 --
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/drivers/gpio/gpio-bd9571mwv.c b/drivers/gpio/gpio-bd9571mwv.c
index 0e5395f..df6102b 100644
--- a/drivers/gpio/gpio-bd9571mwv.c
+++ b/drivers/gpio/gpio-bd9571mwv.c
@@ -1,6 +1,6 @@
 // SPDX-License-Identifier: GPL-2.0-only
 /*
- * ROHM BD9571MWV-M GPIO driver
+ * ROHM BD9571MWV-M and BD9574MWF-M GPIO driver
  *
  * Copyright (C) 2017 Marek Vasut 
  *
@@ -10,6 +10,7 @@
  */
 
 #include 
+#include 
 #include 
 #include 
 
@@ -118,7 +119,8 @@ static int bd9571mwv_gpio_probe(struct platform_device 
*pdev)
 }
 
 static const struct platform_device_id bd9571mwv_gpio_id_table[] = {
-   { "bd9571mwv-gpio", },
+   { "bd9571mwv-gpio", ROHM_CHIP_TYPE_BD9571 },
+   { "bd9574mwf-gpio", ROHM_CHIP_TYPE_BD9574 },
{ /* sentinel */ }
 };
 MODULE_DEVICE_TABLE(platform, bd9571mwv_gpio_id_table);
-- 
2.7.4



[PATCH v4 11/12] mfd: bd9571mwv: Make the driver more generic

2020-12-20 Thread Yoshihiro Shimoda
From: Khiem Nguyen 

Since the driver supports BD9571MWV PMIC only, this patch makes
the functions and data structure become more generic so that
it can support other PMIC variants as well. Also remove printing
part name which Lee Jones suggested.

Signed-off-by: Khiem Nguyen 
Co-developed-by: Yoshihiro Shimoda 
Signed-off-by: Yoshihiro Shimoda 
---
 drivers/mfd/bd9571mwv.c   | 89 +--
 include/linux/mfd/bd9571mwv.h | 18 +
 2 files changed, 54 insertions(+), 53 deletions(-)

diff --git a/drivers/mfd/bd9571mwv.c b/drivers/mfd/bd9571mwv.c
index 49e968e..c905ab4 100644
--- a/drivers/mfd/bd9571mwv.c
+++ b/drivers/mfd/bd9571mwv.c
@@ -3,6 +3,7 @@
  * ROHM BD9571MWV-M MFD driver
  *
  * Copyright (C) 2017 Marek Vasut 
+ * Copyright (C) 2020 Renesas Electronics Corporation
  *
  * Based on the TPS65086 driver
  */
@@ -14,6 +15,14 @@
 
 #include 
 
+/* Driver data to distinguish bd957x variants */
+struct bd957x_ddata {
+   const struct regmap_config *regmap_config;
+   const struct regmap_irq_chip *irq_chip;
+   const struct mfd_cell *cells;
+   int num_cells;
+};
+
 static const struct mfd_cell bd9571mwv_cells[] = {
{ .name = "bd9571mwv-regulator", },
{ .name = "bd9571mwv-gpio", },
@@ -102,13 +111,19 @@ static struct regmap_irq_chip bd9571mwv_irq_chip = {
.num_irqs   = ARRAY_SIZE(bd9571mwv_irqs),
 };
 
-static int bd9571mwv_identify(struct bd9571mwv *bd)
+static const struct bd957x_ddata bd9571mwv_ddata = {
+   .regmap_config = _regmap_config,
+   .irq_chip = _irq_chip,
+   .cells = bd9571mwv_cells,
+   .num_cells = ARRAY_SIZE(bd9571mwv_cells),
+};
+
+static int bd957x_identify(struct device *dev, struct regmap *regmap)
 {
-   struct device *dev = bd->dev;
unsigned int value;
int ret;
 
-   ret = regmap_read(bd->regmap, BD9571MWV_VENDOR_CODE, );
+   ret = regmap_read(regmap, BD9571MWV_VENDOR_CODE, );
if (ret) {
dev_err(dev, "Failed to read vendor code register (ret=%i)\n",
ret);
@@ -121,66 +136,66 @@ static int bd9571mwv_identify(struct bd9571mwv *bd)
return -EINVAL;
}
 
-   ret = regmap_read(bd->regmap, BD9571MWV_PRODUCT_CODE, );
+   ret = regmap_read(regmap, BD9571MWV_PRODUCT_CODE, );
if (ret) {
dev_err(dev, "Failed to read product code register (ret=%i)\n",
ret);
return ret;
}
-
-   if (value != BD9571MWV_PRODUCT_CODE_VAL) {
-   dev_err(dev, "Invalid product code ID %02x (expected %02x)\n",
-   value, BD9571MWV_PRODUCT_CODE_VAL);
-   return -EINVAL;
-   }
-
-   ret = regmap_read(bd->regmap, BD9571MWV_PRODUCT_REVISION, );
+   ret = regmap_read(regmap, BD9571MWV_PRODUCT_REVISION, );
if (ret) {
dev_err(dev, "Failed to read revision register (ret=%i)\n",
ret);
return ret;
}
 
-   dev_info(dev, "Device: BD9571MWV rev. %d\n", value & 0xff);
-
return 0;
 }
 
 static int bd9571mwv_probe(struct i2c_client *client,
- const struct i2c_device_id *ids)
+  const struct i2c_device_id *ids)
 {
-   struct bd9571mwv *bd;
-   int ret;
-
-   bd = devm_kzalloc(>dev, sizeof(*bd), GFP_KERNEL);
-   if (!bd)
-   return -ENOMEM;
-
-   i2c_set_clientdata(client, bd);
-   bd->dev = >dev;
-   bd->irq = client->irq;
+   const struct bd957x_ddata *ddata;
+   struct device *dev = >dev;
+   struct regmap *regmap;
+   struct regmap_irq_chip_data *irq_data;
+   int ret, irq = client->irq;
+
+   /* Read the PMIC product code */
+   ret = i2c_smbus_read_byte_data(client, BD9571MWV_PRODUCT_CODE);
+   if (ret < 0) {
+   dev_err(dev, "Failed to read product code\n");
+   return ret;
+   }
+   switch (ret) {
+   case BD9571MWV_PRODUCT_CODE_BD9571MWV:
+   ddata = _ddata;
+   break;
+   default:
+   dev_err(dev, "Unsupported device 0x%x\n", ret);
+   return -ENODEV;
+   }
 
-   bd->regmap = devm_regmap_init_i2c(client, _regmap_config);
-   if (IS_ERR(bd->regmap)) {
-   dev_err(bd->dev, "Failed to initialize register map\n");
-   return PTR_ERR(bd->regmap);
+   regmap = devm_regmap_init_i2c(client, ddata->regmap_config);
+   if (IS_ERR(regmap)) {
+   dev_err(dev, "Failed to initialize register map\n");
+   return PTR_ERR(regmap);
}
 
-   ret = bd9571mwv_identify(bd);
+   ret = bd957x_identify(dev, regmap);
if (ret)
return ret;
 
-   ret = devm_

[PATCH v4 07/12] gpio: bd9571mwv: rid of using struct bd9571mwv

2020-12-20 Thread Yoshihiro Shimoda
To simplify this driver, use dev_get_regmap() and
rid of using struct bd9571mwv.

Signed-off-by: Yoshihiro Shimoda 
Reviewed-by: Matti Vaittinen 
---
 drivers/gpio/gpio-bd9571mwv.c | 19 +--
 1 file changed, 9 insertions(+), 10 deletions(-)

diff --git a/drivers/gpio/gpio-bd9571mwv.c b/drivers/gpio/gpio-bd9571mwv.c
index abb622c..0e5395f 100644
--- a/drivers/gpio/gpio-bd9571mwv.c
+++ b/drivers/gpio/gpio-bd9571mwv.c
@@ -16,8 +16,8 @@
 #include 
 
 struct bd9571mwv_gpio {
+   struct regmap *regmap;
struct gpio_chip chip;
-   struct bd9571mwv *bd;
 };
 
 static int bd9571mwv_gpio_get_direction(struct gpio_chip *chip,
@@ -26,7 +26,7 @@ static int bd9571mwv_gpio_get_direction(struct gpio_chip 
*chip,
struct bd9571mwv_gpio *gpio = gpiochip_get_data(chip);
int ret, val;
 
-   ret = regmap_read(gpio->bd->regmap, BD9571MWV_GPIO_DIR, );
+   ret = regmap_read(gpio->regmap, BD9571MWV_GPIO_DIR, );
if (ret < 0)
return ret;
if (val & BIT(offset))
@@ -40,8 +40,7 @@ static int bd9571mwv_gpio_direction_input(struct gpio_chip 
*chip,
 {
struct bd9571mwv_gpio *gpio = gpiochip_get_data(chip);
 
-   regmap_update_bits(gpio->bd->regmap, BD9571MWV_GPIO_DIR,
-  BIT(offset), 0);
+   regmap_update_bits(gpio->regmap, BD9571MWV_GPIO_DIR, BIT(offset), 0);
 
return 0;
 }
@@ -52,9 +51,9 @@ static int bd9571mwv_gpio_direction_output(struct gpio_chip 
*chip,
struct bd9571mwv_gpio *gpio = gpiochip_get_data(chip);
 
/* Set the initial value */
-   regmap_update_bits(gpio->bd->regmap, BD9571MWV_GPIO_OUT,
+   regmap_update_bits(gpio->regmap, BD9571MWV_GPIO_OUT,
   BIT(offset), value ? BIT(offset) : 0);
-   regmap_update_bits(gpio->bd->regmap, BD9571MWV_GPIO_DIR,
+   regmap_update_bits(gpio->regmap, BD9571MWV_GPIO_DIR,
   BIT(offset), BIT(offset));
 
return 0;
@@ -65,7 +64,7 @@ static int bd9571mwv_gpio_get(struct gpio_chip *chip, 
unsigned int offset)
struct bd9571mwv_gpio *gpio = gpiochip_get_data(chip);
int ret, val;
 
-   ret = regmap_read(gpio->bd->regmap, BD9571MWV_GPIO_IN, );
+   ret = regmap_read(gpio->regmap, BD9571MWV_GPIO_IN, );
if (ret < 0)
return ret;
 
@@ -77,7 +76,7 @@ static void bd9571mwv_gpio_set(struct gpio_chip *chip, 
unsigned int offset,
 {
struct bd9571mwv_gpio *gpio = gpiochip_get_data(chip);
 
-   regmap_update_bits(gpio->bd->regmap, BD9571MWV_GPIO_OUT,
+   regmap_update_bits(gpio->regmap, BD9571MWV_GPIO_OUT,
   BIT(offset), value ? BIT(offset) : 0);
 }
 
@@ -105,9 +104,9 @@ static int bd9571mwv_gpio_probe(struct platform_device 
*pdev)
 
platform_set_drvdata(pdev, gpio);
 
-   gpio->bd = dev_get_drvdata(pdev->dev.parent);
+   gpio->regmap = dev_get_regmap(pdev->dev.parent, NULL);
gpio->chip = template_chip;
-   gpio->chip.parent = gpio->bd->dev;
+   gpio->chip.parent = pdev->dev.parent;
 
ret = devm_gpiochip_add_data(>dev, >chip, gpio);
if (ret < 0) {
-- 
2.7.4



[PATCH v4 09/12] mfd: bd9571mwv: Use the SPDX license identifier

2020-12-20 Thread Yoshihiro Shimoda
Use the SPDX license identifier instead of a local description.

Signed-off-by: Yoshihiro Shimoda 
Reviewed-by: Geert Uytterhoeven 
Acked-for-MFD-by: Lee Jones 
---
 drivers/mfd/bd9571mwv.c   | 10 +-
 include/linux/mfd/bd9571mwv.h | 10 +-
 2 files changed, 2 insertions(+), 18 deletions(-)

diff --git a/drivers/mfd/bd9571mwv.c b/drivers/mfd/bd9571mwv.c
index 19d57a4..e68c3fa 100644
--- a/drivers/mfd/bd9571mwv.c
+++ b/drivers/mfd/bd9571mwv.c
@@ -1,17 +1,9 @@
+// SPDX-License-Identifier: GPL-2.0-only
 /*
  * ROHM BD9571MWV-M MFD driver
  *
  * Copyright (C) 2017 Marek Vasut 
  *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License version 2 as
- * published by the Free Software Foundation.
- *
- * This program is distributed "as is" WITHOUT ANY WARRANTY of any
- * kind, whether expressed or implied; without even the implied warranty
- * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License version 2 for more details.
- *
  * Based on the TPS65086 driver
  */
 
diff --git a/include/linux/mfd/bd9571mwv.h b/include/linux/mfd/bd9571mwv.h
index eb05569..bcc7092 100644
--- a/include/linux/mfd/bd9571mwv.h
+++ b/include/linux/mfd/bd9571mwv.h
@@ -1,17 +1,9 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
 /*
  * ROHM BD9571MWV-M driver
  *
  * Copyright (C) 2017 Marek Vasut 
  *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License version 2 as
- * published by the Free Software Foundation.
- *
- * This program is distributed "as is" WITHOUT ANY WARRANTY of any
- * kind, whether expressed or implied; without even the implied warranty
- * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License version 2 for more details.
- *
  * Based on the TPS65086 driver
  */
 
-- 
2.7.4



[PATCH v4 06/12] gpio: bd9571mwv: Use the SPDX license identifier

2020-12-20 Thread Yoshihiro Shimoda
Use the SPDX license identifier instead of a local description.

Signed-off-by: Yoshihiro Shimoda 
Reviewed-by: Geert Uytterhoeven 
---
 drivers/gpio/gpio-bd9571mwv.c | 10 +-
 1 file changed, 1 insertion(+), 9 deletions(-)

diff --git a/drivers/gpio/gpio-bd9571mwv.c b/drivers/gpio/gpio-bd9571mwv.c
index c0abc9c..abb622c 100644
--- a/drivers/gpio/gpio-bd9571mwv.c
+++ b/drivers/gpio/gpio-bd9571mwv.c
@@ -1,17 +1,9 @@
+// SPDX-License-Identifier: GPL-2.0-only
 /*
  * ROHM BD9571MWV-M GPIO driver
  *
  * Copyright (C) 2017 Marek Vasut 
  *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License version 2 as
- * published by the Free Software Foundation.
- *
- * This program is distributed "as is" WITHOUT ANY WARRANTY of any
- * kind, whether expressed or implied; without even the implied warranty
- * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License version 2 for more details.
- *
  * Based on the TPS65086 driver
  *
  * NOTE: Interrupts are not supported yet.
-- 
2.7.4



[PATCH v4 10/12] mfd: bd9571mwv: Use devm_regmap_add_irq_chip()

2020-12-20 Thread Yoshihiro Shimoda
Use dev_regmap_add_irq_chip() to simplify the code.

Signed-off-by: Yoshihiro Shimoda 
Acked-for-MFD-by: Lee Jones 
---
 drivers/mfd/bd9571mwv.c | 27 ++-
 1 file changed, 6 insertions(+), 21 deletions(-)

diff --git a/drivers/mfd/bd9571mwv.c b/drivers/mfd/bd9571mwv.c
index e68c3fa..49e968e 100644
--- a/drivers/mfd/bd9571mwv.c
+++ b/drivers/mfd/bd9571mwv.c
@@ -170,31 +170,17 @@ static int bd9571mwv_probe(struct i2c_client *client,
if (ret)
return ret;
 
-   ret = regmap_add_irq_chip(bd->regmap, bd->irq, IRQF_ONESHOT, 0,
- _irq_chip, >irq_data);
+   ret = devm_regmap_add_irq_chip(bd->dev, bd->regmap, bd->irq,
+  IRQF_ONESHOT, 0, _irq_chip,
+  >irq_data);
if (ret) {
dev_err(bd->dev, "Failed to register IRQ chip\n");
return ret;
}
 
-   ret = devm_mfd_add_devices(bd->dev, PLATFORM_DEVID_AUTO,
-  bd9571mwv_cells, ARRAY_SIZE(bd9571mwv_cells),
-  NULL, 0, 
regmap_irq_get_domain(bd->irq_data));
-   if (ret) {
-   regmap_del_irq_chip(bd->irq, bd->irq_data);
-   return ret;
-   }
-
-   return 0;
-}
-
-static int bd9571mwv_remove(struct i2c_client *client)
-{
-   struct bd9571mwv *bd = i2c_get_clientdata(client);
-
-   regmap_del_irq_chip(bd->irq, bd->irq_data);
-
-   return 0;
+   return devm_mfd_add_devices(bd->dev, PLATFORM_DEVID_AUTO,
+   bd9571mwv_cells, 
ARRAY_SIZE(bd9571mwv_cells),
+   NULL, 0, 
regmap_irq_get_domain(bd->irq_data));
 }
 
 static const struct of_device_id bd9571mwv_of_match_table[] = {
@@ -215,7 +201,6 @@ static struct i2c_driver bd9571mwv_driver = {
.of_match_table = bd9571mwv_of_match_table,
},
.probe  = bd9571mwv_probe,
-   .remove = bd9571mwv_remove,
.id_table   = bd9571mwv_id_table,
 };
 module_i2c_driver(bd9571mwv_driver);
-- 
2.7.4



[PATCH v4 04/12] regulator: bd9571mwv: rid of using struct bd9571mwv

2020-12-20 Thread Yoshihiro Shimoda
To simplify this driver, use dev_get_regmap() and
rid of using struct bd9571mwv.

Signed-off-by: Yoshihiro Shimoda 
Reviewed-by: Matti Vaittinen 
---
 drivers/regulator/bd9571mwv-regulator.c | 49 +
 1 file changed, 26 insertions(+), 23 deletions(-)

diff --git a/drivers/regulator/bd9571mwv-regulator.c 
b/drivers/regulator/bd9571mwv-regulator.c
index e690c2c..42b6a70 100644
--- a/drivers/regulator/bd9571mwv-regulator.c
+++ b/drivers/regulator/bd9571mwv-regulator.c
@@ -17,7 +17,7 @@
 #include 
 
 struct bd9571mwv_reg {
-   struct bd9571mwv *bd;
+   struct regmap *regmap;
 
/* DDR Backup Power */
u8 bkup_mode_cnt_keepon;/* from "rohm,ddr-backup-power" */
@@ -137,26 +137,30 @@ static const struct regulator_desc regulators[] = {
 };
 
 #ifdef CONFIG_PM_SLEEP
-static int bd9571mwv_bkup_mode_read(struct bd9571mwv *bd, unsigned int *mode)
+static int bd9571mwv_bkup_mode_read(struct bd9571mwv_reg *bdreg,
+   unsigned int *mode)
 {
int ret;
 
-   ret = regmap_read(bd->regmap, BD9571MWV_BKUP_MODE_CNT, mode);
+   ret = regmap_read(bdreg->regmap, BD9571MWV_BKUP_MODE_CNT, mode);
if (ret) {
-   dev_err(bd->dev, "failed to read backup mode (%d)\n", ret);
+   dev_err(regmap_get_device(bdreg->regmap),
+   "failed to read backup mode (%d)\n", ret);
return ret;
}
 
return 0;
 }
 
-static int bd9571mwv_bkup_mode_write(struct bd9571mwv *bd, unsigned int mode)
+static int bd9571mwv_bkup_mode_write(struct bd9571mwv_reg *bdreg,
+unsigned int mode)
 {
int ret;
 
-   ret = regmap_write(bd->regmap, BD9571MWV_BKUP_MODE_CNT, mode);
+   ret = regmap_write(bdreg->regmap, BD9571MWV_BKUP_MODE_CNT, mode);
if (ret) {
-   dev_err(bd->dev, "failed to configure backup mode 0x%x (%d)\n",
+   dev_err(regmap_get_device(bdreg->regmap),
+   "failed to configure backup mode 0x%x (%d)\n",
mode, ret);
return ret;
}
@@ -194,7 +198,7 @@ static ssize_t backup_mode_store(struct device *dev,
 * Configure DDR Backup Mode, to change the role of the accessory power
 * switch from a power switch to a wake-up switch, or vice versa
 */
-   ret = bd9571mwv_bkup_mode_read(bdreg->bd, );
+   ret = bd9571mwv_bkup_mode_read(bdreg, );
if (ret)
return ret;
 
@@ -202,7 +206,7 @@ static ssize_t backup_mode_store(struct device *dev,
if (bdreg->bkup_mode_enabled)
mode |= bdreg->bkup_mode_cnt_keepon;
 
-   ret = bd9571mwv_bkup_mode_write(bdreg->bd, mode);
+   ret = bd9571mwv_bkup_mode_write(bdreg, mode);
if (ret)
return ret;
 
@@ -221,7 +225,7 @@ static int bd9571mwv_suspend(struct device *dev)
return 0;
 
/* Save DDR Backup Mode */
-   ret = bd9571mwv_bkup_mode_read(bdreg->bd, );
+   ret = bd9571mwv_bkup_mode_read(bdreg, );
if (ret)
return ret;
 
@@ -235,7 +239,7 @@ static int bd9571mwv_suspend(struct device *dev)
mode |= bdreg->bkup_mode_cnt_keepon;
 
if (mode != bdreg->bkup_mode_cnt_saved)
-   return bd9571mwv_bkup_mode_write(bdreg->bd, mode);
+   return bd9571mwv_bkup_mode_write(bdreg, mode);
 
return 0;
 }
@@ -248,7 +252,7 @@ static int bd9571mwv_resume(struct device *dev)
return 0;
 
/* Restore DDR Backup Mode */
-   return bd9571mwv_bkup_mode_write(bdreg->bd, bdreg->bkup_mode_cnt_saved);
+   return bd9571mwv_bkup_mode_write(bdreg, bdreg->bkup_mode_cnt_saved);
 }
 
 static const struct dev_pm_ops bd9571mwv_pm  = {
@@ -268,7 +272,6 @@ static int bd9571mwv_regulator_remove(struct 
platform_device *pdev)
 
 static int bd9571mwv_regulator_probe(struct platform_device *pdev)
 {
-   struct bd9571mwv *bd = dev_get_drvdata(pdev->dev.parent);
struct regulator_config config = { };
struct bd9571mwv_reg *bdreg;
struct regulator_dev *rdev;
@@ -279,40 +282,40 @@ static int bd9571mwv_regulator_probe(struct 
platform_device *pdev)
if (!bdreg)
return -ENOMEM;
 
-   bdreg->bd = bd;
+   bdreg->regmap = dev_get_regmap(pdev->dev.parent, NULL);
 
platform_set_drvdata(pdev, bdreg);
 
config.dev = >dev;
-   config.dev->of_node = bd->dev->of_node;
-   config.driver_data = bd;
-   config.regmap = bd->regmap;
+   config.dev->of_node = pdev->dev.parent->of_node;
+   config.driver_data = bdreg;
+   config.regmap = bdreg->regmap;
 
for (i = 0; i < ARRAY_SIZE(regulators); i++) {
rdev = devm_regulator_register(>dev, [i],
 

[PATCH v4 01/12] mfd: bd9571mwv: Use devm_mfd_add_devices()

2020-12-20 Thread Yoshihiro Shimoda
To remove mfd devices when unload this driver, should use
devm_mfd_add_devices() instead.

Fixes: d3ea21272094 ("mfd: Add ROHM BD9571MWV-M MFD PMIC driver")
Signed-off-by: Yoshihiro Shimoda 
Acked-for-MFD-by: Lee Jones 
---
 drivers/mfd/bd9571mwv.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/mfd/bd9571mwv.c b/drivers/mfd/bd9571mwv.c
index fab3cdc..19d57a4 100644
--- a/drivers/mfd/bd9571mwv.c
+++ b/drivers/mfd/bd9571mwv.c
@@ -185,9 +185,9 @@ static int bd9571mwv_probe(struct i2c_client *client,
return ret;
}
 
-   ret = mfd_add_devices(bd->dev, PLATFORM_DEVID_AUTO, bd9571mwv_cells,
- ARRAY_SIZE(bd9571mwv_cells), NULL, 0,
- regmap_irq_get_domain(bd->irq_data));
+   ret = devm_mfd_add_devices(bd->dev, PLATFORM_DEVID_AUTO,
+  bd9571mwv_cells, ARRAY_SIZE(bd9571mwv_cells),
+  NULL, 0, 
regmap_irq_get_domain(bd->irq_data));
if (ret) {
regmap_del_irq_chip(bd->irq, bd->irq_data);
return ret;
-- 
2.7.4



  1   2   3   4   5   6   7   >