Jernej Skrabec | fbd37d8 | 2021-01-11 21:11:33 +0100 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
| 2 | /* |
| 3 | * AXP305 driver |
| 4 | * |
| 5 | * (C) Copyright 2020 Jernej Skrabec <jernej.skrabec@siol.net> |
| 6 | * |
| 7 | * Based on axp221.c |
| 8 | * (C) Copyright 2014 Hans de Goede <hdegoede@redhat.com> |
| 9 | * (C) Copyright 2013 Oliver Schinagl <oliver@schinagl.nl> |
| 10 | */ |
| 11 | |
| 12 | #include <common.h> |
| 13 | #include <command.h> |
| 14 | #include <errno.h> |
| 15 | #include <asm/arch/pmic_bus.h> |
| 16 | #include <axp_pmic.h> |
| 17 | |
| 18 | #define AXP305_DCDC4_1600MV_OFFSET 46 |
| 19 | |
| 20 | static u8 axp305_mvolt_to_cfg(int mvolt, int min, int max, int div) |
| 21 | { |
| 22 | if (mvolt < min) |
| 23 | mvolt = min; |
| 24 | else if (mvolt > max) |
| 25 | mvolt = max; |
| 26 | |
| 27 | return (mvolt - min) / div; |
| 28 | } |
| 29 | |
| 30 | int axp_set_dcdc4(unsigned int mvolt) |
| 31 | { |
| 32 | int ret; |
| 33 | u8 cfg; |
| 34 | |
| 35 | if (mvolt >= 1600) |
| 36 | cfg = AXP305_DCDC4_1600MV_OFFSET + |
| 37 | axp305_mvolt_to_cfg(mvolt, 1600, 3300, 100); |
| 38 | else |
| 39 | cfg = axp305_mvolt_to_cfg(mvolt, 600, 1500, 20); |
| 40 | |
| 41 | if (mvolt == 0) |
| 42 | return pmic_bus_clrbits(AXP305_OUTPUT_CTRL1, |
| 43 | AXP305_OUTPUT_CTRL1_DCDCD_EN); |
| 44 | |
| 45 | ret = pmic_bus_write(AXP305_DCDCD_VOLTAGE, cfg); |
| 46 | if (ret) |
| 47 | return ret; |
| 48 | |
| 49 | return pmic_bus_setbits(AXP305_OUTPUT_CTRL1, |
| 50 | AXP305_OUTPUT_CTRL1_DCDCD_EN); |
| 51 | } |
| 52 | |
| 53 | int axp_init(void) |
| 54 | { |
| 55 | u8 axp_chip_id; |
| 56 | int ret; |
| 57 | |
| 58 | ret = pmic_bus_init(); |
| 59 | if (ret) |
| 60 | return ret; |
| 61 | |
| 62 | ret = pmic_bus_read(AXP305_CHIP_VERSION, &axp_chip_id); |
| 63 | if (ret) |
| 64 | return ret; |
| 65 | |
| 66 | if ((axp_chip_id & AXP305_CHIP_VERSION_MASK) != 0x40) |
| 67 | return -ENODEV; |
| 68 | |
| 69 | return ret; |
| 70 | } |
| 71 | |
Samuel Holland | 830e161 | 2021-08-22 18:18:05 -0500 | [diff] [blame] | 72 | #if !CONFIG_IS_ENABLED(ARM_PSCI_FW) && !IS_ENABLED(CONFIG_SYSRESET_CMD_POWEROFF) |
Jernej Skrabec | fbd37d8 | 2021-01-11 21:11:33 +0100 | [diff] [blame] | 73 | int do_poweroff(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) |
| 74 | { |
| 75 | pmic_bus_write(AXP305_SHUTDOWN, AXP305_POWEROFF); |
| 76 | |
| 77 | /* infinite loop during shutdown */ |
| 78 | while (1) {} |
| 79 | |
| 80 | /* not reached */ |
| 81 | return 0; |
| 82 | } |
| 83 | #endif |