From 89b3452be1e800022bb3e7e1d7021ac52a2e2f05 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Stelmach?= Date: Wed, 21 Dec 2022 15:42:13 +0100 Subject: [PATCH] starfive: Add support for reset command MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Ɓukasz Stelmach --- board/starfive/jh7100/jh7100.c | 45 ++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/board/starfive/jh7100/jh7100.c b/board/starfive/jh7100/jh7100.c index bf59cc32dc6..98c1d67597e 100644 --- a/board/starfive/jh7100/jh7100.c +++ b/board/starfive/jh7100/jh7100.c @@ -15,6 +15,7 @@ #include #include #include +#include #include #include @@ -1533,3 +1534,47 @@ int board_init(void) return ret; } + +/* + * Platform reset via TPS65086 PMIC + */ + +#define TPS65086_FORCESHUTDN 0x91 +#define TPS65086_I2C_ADDR 0x5e +#define TPS65086_I2C_BUS 0 + +void reset_misc(void) +{ + u_char one = 1; + struct udevice *dev; + struct udevice *bus; + struct dm_i2c_chip *i2c_chip; + int ret; + + ret = uclass_get_device_by_seq(UCLASS_I2C, TPS65086_I2C_BUS, &bus); + if (ret) { + debug("%s: No bus %d\n", __func__, TPS65086_I2C_BUS); + return; + } + + ret = i2c_get_chip(bus, TPS65086_I2C_ADDR, 1, &dev); + if (!ret) + ret = i2c_set_chip_offset_len(dev, 1); + if (ret) { + printf("Error writing the chip: %d", ret); + return; + } + + i2c_chip = dev_get_parent_plat(dev); + if (!i2c_chip){ + printf("Error writing the chip: %d", ret); + return; + } + + i2c_chip->flags &= ~DM_I2C_CHIP_WR_ADDRESS; + ret = dm_i2c_write(dev, TPS65086_FORCESHUTDN, &one, 1); + if (ret) { + printf("Error writing the chip: %d", ret); + return; + } +}