Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.2 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,NICE_REPLY_A,SPF_HELO_NONE,SPF_PASS, USER_AGENT_SANE_1 autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2CC42C4338F for ; Mon, 23 Aug 2021 04:26:21 +0000 (UTC) Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id EB7E56115A for ; Mon, 23 Aug 2021 04:26:19 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org EB7E56115A Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=denx.de Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=lists.denx.de Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 0450182EBB; Mon, 23 Aug 2021 06:26:18 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=denx.de Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=denx.de; s=phobos-20191101; t=1629692778; bh=bOXw774WbUoMUC/X77DvhWMUlF/FpqoFLXFBXtfbWkw=; h=Subject:To:Cc:References:From:Date:In-Reply-To:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: Reply-To:From; b=e6VDXDn2CeFpp0yClUleam4Wrceo+ZDIL6B9pzHI9VTH0ZnBJfn9eUTCWWD06WC5J T8gAhG2F3taS7Sm/lXN0et0G06BTf79lWhilpCMS/xIDOdaEET3ARQr3gJijAO4b+9 JHSZ0OSPnX3VJ+qsQBFbC0pIpyMjzwqm6RathSLV25uqv3KvX8AViAtARgWddd+VOu VNKerkJBRtq0J9363FDLsLIKR8fmCTh3ODFw3GLsf+Cq/cJ+7lwmJNoeXsoahP0udm bfOQSBZhXEw7hUvFRAwt9JVZDdoWvXjC2YUIzcRTq+znkLbOkfDRKnNsirraF33fkP TikgObhdxmlvg== Received: from [192.168.1.107] (82-131-153-206.pool.digikabel.hu [82.131.153.206]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: hs@denx.de) by phobos.denx.de (Postfix) with ESMTPSA id 00E1C82C0C; Mon, 23 Aug 2021 06:26:12 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=denx.de; s=phobos-20191101; t=1629692775; bh=bOXw774WbUoMUC/X77DvhWMUlF/FpqoFLXFBXtfbWkw=; h=Reply-To:Subject:To:Cc:References:From:Date:In-Reply-To:From; b=zuhyD8E5c2R5Ot1jMGDIT1PdcsEC4IoNR1dCIIbqE2t6IPjzB812/LVj+T05ao+aZ jRykjU2Ch7NREfCarPWJc+HIFBO91EzwLTl+rD8Z+4+tVJSkV4usKuoHlCgbHNA9sv mOg8Iw9wYN5L8IEPdzjIVrqrxgaQWRDcMqlZzxZBIehcn4IGonVi4yWTC0kDAHNRKm IjK0vTcqIYCwlNS/YD1QsN/qHB7bD7K81U+8m2MDiihEx+AfB5N0FyqEATFStWLx04 +psxNVmvVmCJpo/vLf5IVBlguQO4iluZFZ8yrtdoRg6tFfpGPJO9puliGKR+p2sSwl TJqpz6BVo/F+w== Subject: Re: [PATCH 01/11] i2c: Add a DM_I2C wrapper for the sun6i_p2wi controller To: Samuel Holland , u-boot@lists.denx.de, Jagan Teki , Andre Przywara Cc: Jaehoon Chung , Anatolij Gustschin , Arnaud Ferraris , Bharat Gooty , Igor Opaniuk , Jernej Skrabec , Minkyu Kang , Rayagonda Kokatanur , Simon Glass , Stephan Gerhold , Tim Harvey , Tom Rini References: <20210821230520.10051-1-samuel@sholland.org> <20210821230520.10051-2-samuel@sholland.org> <81924f0b-8a88-e422-69be-1ca9dc86bfd1@denx.de> <5dc2757c-8536-0ffa-7a87-ff34380da967@sholland.org> From: Heiko Schocher Message-ID: <8520d724-e9e3-9c83-6bfe-aed5d7a753b1@denx.de> Date: Mon, 23 Aug 2021 06:26:11 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.8.1 MIME-Version: 1.0 In-Reply-To: <5dc2757c-8536-0ffa-7a87-ff34380da967@sholland.org> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: hs@denx.de Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.2 at phobos.denx.de X-Virus-Status: Clean Hello Samuel, On 22.08.21 19:19, Samuel Holland wrote: > Hi Heiko, > > On 8/22/21 3:38 AM, Heiko Schocher wrote: >> 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 >>> --- >>> >>> 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? > > I did not remove any config symbol, only moved it to a different file. Yes, and you add "drivers/i2c/sun6i_p2wi.c", and nowhere code is removed, which is enabled by this config symbol... was the config symbol not used before? Ah, I see, you use code from arch/arm/mach-sunxi/p2wi.c... Shouldn;t this be moved than to drivers/i2c too? Only i2c driver use this functions ... or? (Hope it is not to dummy question...) > It sounds like you want me to use a new symbol for the DM_I2C driver > (SYS_I2C_SUN6I_P2WI). So in that case, I would leave the old symbol > alone, and have SYS_I2C_SUN6I_P2WI select it. Hmm.. better to move the whole code to dirvers/i2c ? > >>> 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 >>> #include >>> #include >>> #include >>> @@ -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. > > I was sorting by file name -- this will be fixed by renaming the config > symbol. we sort by config symbol. bye, Heiko > > Regards, > Samuel > >>> 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 >>> +#include >>> +#include >>> +#include >>> + >>> +#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 >>> + >>> #ifdef CONFIG_AXP152_POWER >>> #include >>> #endif >>> @@ -25,6 +27,10 @@ >>> #include >>> #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 >> >> 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