All of lore.kernel.org
 help / color / mirror / Atom feed
From: Heiko Schocher <hs@denx.de>
To: Samuel Holland <samuel@sholland.org>,
	u-boot@lists.denx.de, Jagan Teki <jagan@amarulasolutions.com>,
	Andre Przywara <andre.przywara@arm.com>
Cc: Jaehoon Chung <jh80.chung@samsung.com>,
	Anatolij Gustschin <agust@denx.de>,
	Arnaud Ferraris <arnaud.ferraris@gmail.com>,
	Bharat Gooty <bharat.gooty@broadcom.com>,
	Igor Opaniuk <igor.opaniuk@gmail.com>,
	Jernej Skrabec <jernej.skrabec@siol.net>,
	Minkyu Kang <mk7.kang@samsung.com>,
	Rayagonda Kokatanur <rayagonda.kokatanur@broadcom.com>,
	Simon Glass <sjg@chromium.org>,
	Stephan Gerhold <stephan@gerhold.net>,
	Tim Harvey <tharvey@gateworks.com>, Tom Rini <trini@konsulko.com>
Subject: Re: [PATCH 01/11] i2c: Add a DM_I2C wrapper for the sun6i_p2wi controller
Date: Sun, 22 Aug 2021 10:38:50 +0200	[thread overview]
Message-ID: <81924f0b-8a88-e422-69be-1ca9dc86bfd1@denx.de> (raw)
In-Reply-To: <20210821230520.10051-2-samuel@sholland.org>

Hello Samuel,

On 22.08.21 01:05, Samuel Holland wrote:
> This bus controller is used to communicate with an X-Powers AXP PMIC.
> Currently, various drivers access PMIC registers through a platform-
> specific non-DM "pmic_bus" interface, which depends on the legacy I2C
> framework. In order to convert those drivers to use DM_PMIC, this bus
> needs a DM_I2C driver.
> 
> Since the non-DM bus controller driver is still needed in SPL, the quick
> solution is to implement the DM_I2C ops using the existing functions.
> 
> The register for switching between I2C/P2WI/RSB mode is the same across
> all PMIC variants, so move that to the common header.
> 
> Signed-off-by: Samuel Holland <samuel@sholland.org>
> ---
> 
>  arch/arm/mach-sunxi/Kconfig    | 11 ------
>  arch/arm/mach-sunxi/pmic_bus.c |  7 ++--
>  drivers/i2c/Kconfig            |  8 +++++
>  drivers/i2c/Makefile           |  1 +
>  drivers/i2c/sun6i_p2wi.c       | 66 ++++++++++++++++++++++++++++++++++

I wonder, as this config symbol gets also removed, that there
is no remove of driver code?

>  include/axp_pmic.h             |  6 ++++
>  6 files changed, 84 insertions(+), 15 deletions(-)
>  create mode 100644 drivers/i2c/sun6i_p2wi.c
> 
> diff --git a/arch/arm/mach-sunxi/Kconfig b/arch/arm/mach-sunxi/Kconfig
> index 79c669a4813..37076c2dfb3 100644
> --- a/arch/arm/mach-sunxi/Kconfig
> +++ b/arch/arm/mach-sunxi/Kconfig
> @@ -88,17 +88,6 @@ config DRAM_SUN50I_H616_UNKNOWN_FEATURE
>  	  feature.
>  endif
>  
> -config SUN6I_P2WI
> -	bool "Allwinner sun6i internal P2WI controller"
> -	help
> -	  If you say yes to this option, support will be included for the
> -	  P2WI (Push/Pull 2 Wire Interface) controller embedded in some sunxi
> -	  SOCs.
> -	  The P2WI looks like an SMBus controller (which supports only byte
> -	  accesses), except that it only supports one slave device.
> -	  This interface is used to connect to specific PMIC devices (like the
> -	  AXP221).
> -
>  config SUN6I_PRCM
>  	bool
>  	help
> diff --git a/arch/arm/mach-sunxi/pmic_bus.c b/arch/arm/mach-sunxi/pmic_bus.c
> index 0394ce85644..673a05fdd16 100644
> --- a/arch/arm/mach-sunxi/pmic_bus.c
> +++ b/arch/arm/mach-sunxi/pmic_bus.c
> @@ -8,6 +8,7 @@
>   * axp223 uses the rsb bus, these functions abstract this.
>   */
>  
> +#include <axp_pmic.h>
>  #include <common.h>
>  #include <asm/arch/p2wi.h>
>  #include <asm/arch/rsb.h>
> @@ -21,8 +22,6 @@
>  #define AXP305_I2C_ADDR			0x36
>  
>  #define AXP221_CHIP_ADDR		0x68
> -#define AXP221_CTRL_ADDR		0x3e
> -#define AXP221_INIT_DATA		0x3e
>  
>  /* AXP818 device and runtime addresses are same as AXP223 */
>  #define AXP223_DEVICE_ADDR		0x3a3
> @@ -40,8 +39,8 @@ int pmic_bus_init(void)
>  #if defined CONFIG_AXP221_POWER || defined CONFIG_AXP809_POWER || defined CONFIG_AXP818_POWER
>  # ifdef CONFIG_MACH_SUN6I
>  	p2wi_init();
> -	ret = p2wi_change_to_p2wi_mode(AXP221_CHIP_ADDR, AXP221_CTRL_ADDR,
> -				       AXP221_INIT_DATA);
> +	ret = p2wi_change_to_p2wi_mode(AXP221_CHIP_ADDR, AXP_PMIC_MODE_REG,
> +				       AXP_PMIC_MODE_P2WI);
>  # elif defined CONFIG_MACH_SUN8I_R40
>  	/* Nothing. R40 uses the AXP221s in I2C mode */
>  	ret = 0;
> diff --git a/drivers/i2c/Kconfig b/drivers/i2c/Kconfig
> index 5d27f503bfc..d082676c4b2 100644
> --- a/drivers/i2c/Kconfig
> +++ b/drivers/i2c/Kconfig
> @@ -577,6 +577,14 @@ config SYS_I2C_STM32F7
>  	   _ Optional clock stretching
>  	   _ Software reset
>  
> +config SUN6I_P2WI

Could you please use "SYS_I2C_" ?

> +	bool "Allwinner sun6i P2WI controller"
> +	depends on ARCH_SUNXI
> +	help
> +	  Support for the P2WI (Push/Pull 2 Wire Interface) controller embedded
> +	  in the Allwinner A31 and A31s SOCs. This interface is used to connect
> +	  to specific devices like the X-Powers AXP221 PMIC.
> +
>  config SYNQUACER
>  	bool "Socionext SynQuacer I2C controller"
>  	depends on ARCH_SYNQUACER && DM_I2C
> diff --git a/drivers/i2c/Makefile b/drivers/i2c/Makefile
> index 3a7ecd9274b..2461f0a2db8 100644
> --- a/drivers/i2c/Makefile
> +++ b/drivers/i2c/Makefile
> @@ -43,6 +43,7 @@ obj-$(CONFIG_SYS_I2C_SANDBOX) += sandbox_i2c.o i2c-emul-uclass.o
>  obj-$(CONFIG_SYS_I2C_SH) += sh_i2c.o
>  obj-$(CONFIG_SYS_I2C_SOFT) += soft_i2c.o
>  obj-$(CONFIG_SYS_I2C_STM32F7) += stm32f7_i2c.o
> +obj-$(CONFIG_SUN6I_P2WI) += sun6i_p2wi.o

please sort alphabetical.

>  obj-$(CONFIG_SYS_I2C_SYNQUACER) += synquacer_i2c.o
>  obj-$(CONFIG_SYS_I2C_TEGRA) += tegra_i2c.o
>  obj-$(CONFIG_SYS_I2C_UNIPHIER) += i2c-uniphier.o
> diff --git a/drivers/i2c/sun6i_p2wi.c b/drivers/i2c/sun6i_p2wi.c
> new file mode 100644
> index 00000000000..f1e8e5ed107
> --- /dev/null
> +++ b/drivers/i2c/sun6i_p2wi.c
> @@ -0,0 +1,66 @@
> +// SPDX-License-Identifier: GPL-2.0+
> +
> +#include <axp_pmic.h>
> +#include <dm.h>
> +#include <i2c.h>
> +#include <asm/arch/p2wi.h>
> +
> +#if CONFIG_IS_ENABLED(DM_I2C)
> +
> +static int sun6i_p2wi_xfer(struct udevice *bus, struct i2c_msg *msg, int nmsgs)
> +{
> +	/* The hardware only supports SMBus-style transfers. */
> +	if (nmsgs == 2 && msg[1].flags == I2C_M_RD && msg[1].len == 1)
> +		return p2wi_read(msg[0].buf[0], msg[1].buf);
> +
> +	if (nmsgs == 1 && msg[0].len == 2)
> +		return p2wi_write(msg[0].buf[0], msg[0].buf[1]);
> +
> +	return -EINVAL;
> +}
> +
> +static int sun6i_p2wi_probe_chip(struct udevice *bus, uint chip_addr,
> +				 uint chip_flags)
> +{
> +	return p2wi_change_to_p2wi_mode(chip_addr,
> +					AXP_PMIC_MODE_REG,
> +					AXP_PMIC_MODE_P2WI);
> +}
> +
> +static int sun6i_p2wi_probe(struct udevice *bus)
> +{
> +	p2wi_init();
> +
> +	return 0;
> +}
> +
> +static int sun6i_p2wi_child_pre_probe(struct udevice *child)
> +{
> +	struct dm_i2c_chip *chip = dev_get_parent_plat(child);
> +
> +	/* Ensure each transfer is for a single register. */
> +	chip->flags |= DM_I2C_CHIP_RD_ADDRESS | DM_I2C_CHIP_WR_ADDRESS;
> +
> +	return 0;
> +}
> +
> +static const struct dm_i2c_ops sun6i_p2wi_ops = {
> +	.xfer		= sun6i_p2wi_xfer,
> +	.probe_chip	= sun6i_p2wi_probe_chip,
> +};
> +
> +static const struct udevice_id sun6i_p2wi_ids[] = {
> +	{ .compatible = "allwinner,sun6i-a31-p2wi" },
> +	{ /* sentinel */ }
> +};
> +
> +U_BOOT_DRIVER(sun6i_p2wi) = {
> +	.name			= "sun6i_p2wi",
> +	.id			= UCLASS_I2C,
> +	.of_match		= sun6i_p2wi_ids,
> +	.probe			= sun6i_p2wi_probe,
> +	.child_pre_probe	= sun6i_p2wi_child_pre_probe,
> +	.ops			= &sun6i_p2wi_ops,
> +};
> +
> +#endif /* CONFIG_IS_ENABLED(DM_I2C) */
> diff --git a/include/axp_pmic.h b/include/axp_pmic.h
> index 405044c3a32..0db3e143eda 100644
> --- a/include/axp_pmic.h
> +++ b/include/axp_pmic.h
> @@ -6,6 +6,8 @@
>   */
>  #ifndef _AXP_PMIC_H_
>  
> +#include <stdbool.h>
> +
>  #ifdef CONFIG_AXP152_POWER
>  #include <axp152.h>
>  #endif
> @@ -25,6 +27,10 @@
>  #include <axp818.h>
>  #endif
>  
> +#define AXP_PMIC_MODE_REG		0x3e
> +#define AXP_PMIC_MODE_I2C		0x00
> +#define AXP_PMIC_MODE_P2WI		0x3e
> +
>  int axp_set_dcdc1(unsigned int mvolt);
>  int axp_set_dcdc2(unsigned int mvolt);
>  int axp_set_dcdc3(unsigned int mvolt);
> 

Beside of the nitpicks:
Reviewed-by: Heiko Schocher <hs@denx.de>

Thanks!

bye,
Heiko
-- 
DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: +49-8142-66989-52   Fax: +49-8142-66989-80   Email: hs@denx.de

  reply	other threads:[~2021-08-22  8:38 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-08-21 23:05 [PATCH 00/11] sunxi: Migrate to DM_I2C Samuel Holland
2021-08-21 23:05 ` [PATCH 01/11] i2c: Add a DM_I2C wrapper for the sun6i_p2wi controller Samuel Holland
2021-08-22  8:38   ` Heiko Schocher [this message]
2021-08-22 17:19     ` Samuel Holland
2021-08-23  4:26       ` Heiko Schocher
2021-08-21 23:05 ` [PATCH 02/11] i2c: Add a DM_I2C wrapper for the sun8i_rsb controller Samuel Holland
2021-08-22  8:40   ` Heiko Schocher
2021-08-21 23:05 ` [PATCH 03/11] power: pmic: Consistently depend on DM_PMIC Samuel Holland
2021-09-02 23:12   ` Jaehoon Chung
2021-09-15 16:08   ` Igor Opaniuk
2021-08-21 23:05 ` [PATCH 04/11] power: pmic: Make the uclass optional in SPL Samuel Holland
2021-09-02 23:13   ` Jaehoon Chung
2021-08-21 23:05 ` [PATCH 05/11] power: pmic: Add a driver for X-Powers AXP PMICs Samuel Holland
2021-09-02 23:17   ` Jaehoon Chung
2021-09-02 23:23     ` Samuel Holland
2021-08-21 23:05 ` [PATCH 06/11] sunxi: Select SUN8I_RSB more carefully Samuel Holland
2021-10-07 16:13   ` Andre Przywara
2021-08-21 23:05 ` [PATCH 07/11] sunxi: pmic_bus: Fix Kconfig dependencies Samuel Holland
2021-09-02 23:17   ` Jaehoon Chung
2021-08-21 23:05 ` [PATCH 08/11] sunxi: pmic_bus: Clean up preprocessor conditions Samuel Holland
2021-08-21 23:05 ` [PATCH 09/11] sunxi: pmic_bus: Use the DM PMIC interface when possible Samuel Holland
2021-08-21 23:05 ` [PATCH 10/11] sunxi: video: Convert panel I2C to use DM_I2C Samuel Holland
2021-08-22  8:41   ` Heiko Schocher
2021-08-21 23:05 ` [PATCH 11/11] sunxi: Enable DM_I2C for all sunxi boards Samuel Holland
2021-08-22  8:42   ` Heiko Schocher

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=81924f0b-8a88-e422-69be-1ca9dc86bfd1@denx.de \
    --to=hs@denx.de \
    --cc=agust@denx.de \
    --cc=andre.przywara@arm.com \
    --cc=arnaud.ferraris@gmail.com \
    --cc=bharat.gooty@broadcom.com \
    --cc=igor.opaniuk@gmail.com \
    --cc=jagan@amarulasolutions.com \
    --cc=jernej.skrabec@siol.net \
    --cc=jh80.chung@samsung.com \
    --cc=mk7.kang@samsung.com \
    --cc=rayagonda.kokatanur@broadcom.com \
    --cc=samuel@sholland.org \
    --cc=sjg@chromium.org \
    --cc=stephan@gerhold.net \
    --cc=tharvey@gateworks.com \
    --cc=trini@konsulko.com \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.