[PATCH 1/2] Add the base Ricoh RN5T568 PMIC driver

Sascha Hauer sha at pengutronix.de
Mon Jan 17 02:23:25 PST 2022


On Mon, Jan 17, 2022 at 09:59:07AM +0100, Juergen Borleis wrote:
> ---
>  drivers/mfd/Kconfig   |   6 ++
>  drivers/mfd/Makefile  |   1 +
>  drivers/mfd/rn5t568.c | 165 ++++++++++++++++++++++++++++++++++++++++++
>  3 files changed, 172 insertions(+)
>  create mode 100644 drivers/mfd/rn5t568.c
> 
> diff --git a/drivers/mfd/Kconfig b/drivers/mfd/Kconfig
> index 8468a2d..1602480 100644
> --- a/drivers/mfd/Kconfig
> +++ b/drivers/mfd/Kconfig
> @@ -68,6 +68,12 @@ config MFD_STPMIC1
>  	help
>  	  Select this to support communication with the STPMIC1.
>  
> +config MFD_RN568PMIC
> +	depends on I2C
> +	bool "Ricoh RN5T568 MFD driver"
> +	help
> +	  Select this to support communication with the Ricoh RN5T568 PMIC.
> +
>  config MFD_SUPERIO
>  	bool
>  
> diff --git a/drivers/mfd/Makefile b/drivers/mfd/Makefile
> index 2bcf900..50f54cf 100644
> --- a/drivers/mfd/Makefile
> +++ b/drivers/mfd/Makefile
> @@ -13,6 +13,7 @@ obj-$(CONFIG_MFD_TWL4030)	+= twl4030.o
>  obj-$(CONFIG_MFD_TWL6030)	+= twl6030.o
>  obj-$(CONFIG_RAVE_SP_CORE)	+= rave-sp.o
>  obj-$(CONFIG_MFD_STPMIC1)	+= stpmic1.o
> +obj-$(CONFIG_MFD_RN568PMIC)	+= rn5t568.o
>  obj-$(CONFIG_MFD_SUPERIO)	+= superio.o
>  obj-$(CONFIG_FINTEK_SUPERIO)	+= fintek-superio.o
>  obj-$(CONFIG_SMSC_SUPERIO)	+= smsc-superio.o
> diff --git a/drivers/mfd/rn5t568.c b/drivers/mfd/rn5t568.c
> new file mode 100644
> index 0000000..ad53d7b
> --- /dev/null
> +++ b/drivers/mfd/rn5t568.c
> @@ -0,0 +1,165 @@
> +// SPDX-License-Identifier: GPL-2.0-only
> +/*
> + * MFD core driver for Ricoh RN5T618 PMIC
> + * Note: Manufacturer is now Nisshinbo Micro Devices Inc.
> + *
> + * Copyright (C) 2014 Beniamino Galvani <b.galvani at gmail.com>
> + * Copyright (C) 2016 Toradex AG
> + */
> +
> +#include <common.h>
> +#include <driver.h>
> +#include <errno.h>
> +#include <i2c/i2c.h>
> +#include <init.h>
> +#include <of.h>
> +#include <regmap.h>
> +#include <reset_source.h>
> +#include <restart.h>
> +
> +#define RN5T568_LSIVER 0x00
> +#define RN5T568_OTPVER 0x01
> +#define RN5T568_PONHIS 0x09
> +# define RN5T568_PONHIS_ON_EXTINPON BIT(3)
> +# define RN5T568_PONHIS_ON_REPWRPON BIT(1)
> +# define RN5T568_PONHIS_ON_PWRONPON BIT(0)
> +#define RN5T568_POFFHIS 0x0a
> +# define RN5T568_POFFHIS_N_OEPOFF BIT(7)
> +# define RN5T568_POFFHIS_DCLIMPOFF BIT(6)
> +# define RN5T568_POFFHIS_WDGPOFF BIT(5)
> +# define RN5T568_POFFHIS_CPUPOFF BIT(4)
> +# define RN5T568_POFFHIS_IODETPOFF BIT(3)
> +# define RN5T568_POFFHIS_VINDETPOFF BIT(2)
> +# define RN5T568_POFFHIS_TSHUTPOFF BIT(1)
> +# define RN5T568_POFFHIS_PWRONPOFF BIT(0)
> +#define RN5T568_SLPCNT 0x0e
> +# define RN5T568_SLPCNT_SWPPWROFF BIT(0)
> +#define RN5T568_REPCNT 0x0f
> +# define RN5T568_REPCNT_OFF_RESETO_16MS 0x30
> +# define RN5T568_REPCNT_OFF_REPWRTIM_1000MS 0x06
> +# define RN5T568_REPCNT_OFF_REPWRON BIT(0)
> +#define RN5T568_MAX_REG 0xbc
> +
> +struct rn5t568 {
> +	struct restart_handler restart;
> +	struct regmap *regmap;
> +};
> +
> +static struct rn5t568 single_pmic;

Please do not artificially limit the driver to a single instance only.

> +
> +static void rn5t568_restart(struct restart_handler *rst)
> +{
> +	struct rn5t568 *rn5t568 = container_of(rst, struct rn5t568, restart);
> +
> +	regmap_write(rn5t568->regmap, RN5T568_SLPCNT, RN5T568_SLPCNT_SWPPWROFF);
> +}
> +
> +static int rn5t568_reset_reason_detect(struct device_d *dev, struct regmap *regmap)
> +{
> +	unsigned int reg;
> +	int ret;
> +
> +	ret = regmap_read(regmap, RN5T568_PONHIS, &reg);
> +	if (ret)
> +		return ret;
> +
> +	dev_dbg(dev, "Power-on history: %x\n", reg);
> +
> +	if (reg == 0) {
> +		dev_info(dev, "No power-on reason available\n");
> +		return 0;
> +	}
> +
> +	if (reg & RN5T568_PONHIS_ON_EXTINPON) {
> +		reset_source_set_device(dev, RESET_POR);
> +		return 0;
> +	} else if (reg & RN5T568_PONHIS_ON_PWRONPON) {
> +		reset_source_set_device(dev, RESET_POR);
> +		return 0;
> +	} else if (!(reg & RN5T568_PONHIS_ON_REPWRPON))
> +		return -EINVAL;
> +
> +	ret = regmap_read(regmap, RN5T568_POFFHIS, &reg);
> +	if (ret)
> +		return ret;
> +
> +	dev_dbg(dev, "Power-off history: %x\n", reg);
> +
> +	if (reg & RN5T568_POFFHIS_PWRONPOFF)
> +		reset_source_set_device(dev, RESET_POR);
> +	else if (reg & RN5T568_POFFHIS_TSHUTPOFF)
> +		reset_source_set_device(dev, RESET_THERM);
> +	else if (reg & RN5T568_POFFHIS_VINDETPOFF)
> +		reset_source_set_device(dev, RESET_BROWNOUT);
> +	else if (reg & RN5T568_POFFHIS_IODETPOFF)
> +		reset_source_set_device(dev, RESET_UKWN);
> +	else if (reg & RN5T568_POFFHIS_CPUPOFF)
> +		reset_source_set_device(dev, RESET_RST);
> +	else if (reg & RN5T568_POFFHIS_WDGPOFF)
> +		reset_source_set_device(dev, RESET_WDG);
> +	else if (reg & RN5T568_POFFHIS_DCLIMPOFF)
> +		reset_source_set_device(dev, RESET_BROWNOUT);
> +	else if (reg & RN5T568_POFFHIS_N_OEPOFF)
> +		reset_source_set_device(dev, RESET_EXT);
> +	else
> +		return -EINVAL;
> +
> +	return 0;
> +}
> +
> +static const struct regmap_config rn5t568_regmap_config = {
> +	.reg_bits	= 8,
> +	.val_bits	= 8,
> +	.max_register	= RN5T568_MAX_REG,
> +};
> +
> +static int __init rn5t568_i2c_probe(struct device_d *dev)
> +{
> +	static const unsigned int val = RN5T568_REPCNT_OFF_RESETO_16MS | RN5T568_REPCNT_OFF_REPWRTIM_1000MS | RN5T568_REPCNT_OFF_REPWRON;

val is used only once. Maybe drop the variable and use the value
directly?

> +	unsigned char reg[4];

reg[2] should be enough. This doesn't matter much but might be a bit
confusing otherwise.

Sascha


-- 
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |



More information about the barebox mailing list