From: Przemyslaw Marczak Date: Fri, 7 Aug 2015 10:01:07 +0000 (+0200) Subject: pmic: max77686: adjust operation mode names to match documentation X-Git-Tag: accepted/tizen/unified/20191107.062134~199 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=8853d7af3de6881fa2de1ddffbc3dea3fcd38f9f;p=platform%2Fkernel%2Fu-boot.git pmic: max77686: adjust operation mode names to match documentation The MAX77686 PMIC's operation modes defined in the header were quite misleading, because in the defined STANDBY mode, the output were off, instead of staying in low power mode. This commit correct this issue, and now the operation modes are consistent with the PMIC's documentation. Rename results: - MAX77686_LDO_MODE_STANDBY -> MAX77686_LDO_MODE_ON_AUTO_OFF - MAX77686_LDO_MODE_STANDBY_LPM -> MAX77686_LDO_MODE_ON_AUTO_LPM - MAX77686_BUCK_MODE_STANDBY -> MAX77686_BUCK_MODE_ON_AUTO_OFF For both modes, the output state is controlled by PMIC's PWRREQ external signal used by SoC. In normal operation mode, when PWRREQ signal is HIGH, the output is ON, amd for LOW signal, the output is OFF or LPM (Low Power Mode). As a result, this commit updates the Trats2 regulator settings. Change-Id: Ibcb86e0c1ed50530930fbabab88bc374eedc4161 Signed-off-by: Przemyslaw Marczak --- diff --git a/drivers/power/pmic/pmic_max77686.c b/drivers/power/pmic/pmic_max77686.c new file mode 100644 index 0000000..cad2c56 --- /dev/null +++ b/drivers/power/pmic/pmic_max77686.c @@ -0,0 +1,307 @@ +/* + * Copyright (C) 2012 Samsung Electronics + * Rajeshwari Shinde + * + * SPDX-License-Identifier: GPL-2.0+ + */ + +#include +#include +#include +#include +#include +#include + +DECLARE_GLOBAL_DATA_PTR; + +static const char max77686_buck_addr[] = { + 0xff, 0x10, 0x12, 0x1c, 0x26, 0x30, 0x32, 0x34, 0x36, 0x38 +}; + +static unsigned int max77686_ldo_volt2hex(int ldo, ulong uV) +{ + unsigned int hex = 0; + + switch (ldo) { + case 1: + case 2: + case 6: + case 7: + case 8: + case 15: + hex = (uV - 800000) / 25000; + break; + default: + hex = (uV - 800000) / 50000; + } + + if (hex >= 0 && hex <= MAX77686_LDO_VOLT_MAX_HEX) + return hex; + + debug("%s: %ld is wrong voltage value for LDO%d\n", __func__, uV, ldo); + return 0; +} + +static int max77686_buck_volt2hex(int buck, ulong uV) +{ + int hex = 0; + + if (buck < 5 || buck > 9) { + debug("%s: buck %d is not supported\n", __func__, buck); + return -EINVAL; + } + + hex = (uV - 750000) / 50000; + + if (hex >= 0 && hex <= MAX77686_BUCK_VOLT_MAX_HEX) + return hex; + + debug("%s: %ld is wrong voltage value for BUCK%d\n", + __func__, uV, buck); + return -EINVAL; +} + +int max77686_set_ldo_voltage(struct pmic *p, int ldo, ulong uV) +{ + unsigned int val, ret, hex, adr; + + if (ldo < 1 || ldo > 26) { + printf("%s: %d is wrong ldo number\n", __func__, ldo); + return -EINVAL; + } + + adr = MAX77686_REG_PMIC_LDO1CTRL1 + ldo - 1; + hex = max77686_ldo_volt2hex(ldo, uV); + + if (!hex) + return -EINVAL; + + ret = pmic_reg_read(p, adr, &val); + if (ret) + return ret; + + val &= ~MAX77686_LDO_VOLT_MASK; + val |= hex; + ret |= pmic_reg_write(p, adr, val); + + return ret; +} + +int max77686_set_buck_voltage(struct pmic *p, int buck, ulong uV) +{ + unsigned int val, adr; + int hex, ret; + + if (buck < 5 || buck > 9) { + printf("%s: %d is an unsupported bucket number\n", + __func__, buck); + return -EINVAL; + } + + adr = max77686_buck_addr[buck] + 1; + hex = max77686_buck_volt2hex(buck, uV); + + if (hex < 0) + return hex; + + ret = pmic_reg_read(p, adr, &val); + if (ret) + return ret; + + val &= ~MAX77686_BUCK_VOLT_MASK; + ret |= pmic_reg_write(p, adr, val | hex); + + return ret; +} + +int max77686_set_ldo_mode(struct pmic *p, int ldo, char opmode) +{ + unsigned int val, ret, adr, mode; + + if (ldo < 1 || 26 < ldo) { + printf("%s: %d is wrong ldo number\n", __func__, ldo); + return -EINVAL; + } + + adr = MAX77686_REG_PMIC_LDO1CTRL1 + ldo - 1; + + /* mode */ + switch (opmode) { + case OPMODE_OFF: + mode = MAX77686_LDO_MODE_OFF; + break; + case OPMODE_LPM: + mode = MAX77686_LDO_MODE_LPM; + break; + case OPMODE_ON_AUTO_OFF: + switch (ldo) { + case 2: + case 6: + case 7: + case 8: + case 10: + case 11: + case 12: + case 14: + case 15: + case 16: + mode = MAX77686_LDO_MODE_ON_AUTO_OFF; + break; + default: + mode = 0xff; + } + break; + case OPMODE_ON_AUTO_LPM: + mode = MAX77686_LDO_MODE_ON_AUTO_LPM; + break; + case OPMODE_ON: + mode = MAX77686_LDO_MODE_ON; + break; + default: + mode = 0xff; + } + + if (mode == 0xff) { + printf("%s: %d is not supported on LDO%d\n", + __func__, opmode, ldo); + return -ENOTSUPP; + } + + ret = pmic_reg_read(p, adr, &val); + if (ret) + return ret; + + val &= ~MAX77686_LDO_MODE_MASK; + val |= mode; + ret |= pmic_reg_write(p, adr, val); + + return ret; +} + +int max77686_set_buck_mode(struct pmic *p, int buck, char opmode) +{ + unsigned int val, ret, mask, adr, size, mode, mode_shift; + + size = ARRAY_SIZE(max77686_buck_addr); + if (buck >= size) { + printf("%s: %d is wrong buck number\n", __func__, buck); + return -EINVAL; + } + + adr = max77686_buck_addr[buck]; + + /* mask */ + switch (buck) { + case 2: + case 3: + case 4: + mode_shift = MAX77686_BUCK_MODE_SHIFT_2; + break; + default: + mode_shift = MAX77686_BUCK_MODE_SHIFT_1; + } + + mask = MAX77686_BUCK_MODE_MASK << mode_shift; + + /* mode */ + switch (opmode) { + case OPMODE_OFF: + mode = MAX77686_BUCK_MODE_OFF << mode_shift; + break; + case OPMODE_ON_AUTO_OFF: + switch (buck) { + case 1: + case 2: + case 3: + case 4: + mode = MAX77686_BUCK_MODE_ON_AUTO_OFF << mode_shift; + break; + default: + mode = 0xff; + } + break; + case OPMODE_LPM: + switch (buck) { + case 2: + case 3: + case 4: + mode = MAX77686_BUCK_MODE_LPM << mode_shift; + break; + default: + mode = 0xff; + } + break; + case OPMODE_ON: + mode = MAX77686_BUCK_MODE_ON << mode_shift; + break; + default: + mode = 0xff; + } + + if (mode == 0xff) { + printf("%s: %d is not supported on BUCK%d\n", + __func__, opmode, buck); + return -ENOTSUPP; + } + + ret = pmic_reg_read(p, adr, &val); + if (ret) + return ret; + + val &= ~mask; + val |= mode; + ret |= pmic_reg_write(p, adr, val); + + return ret; +} + +int pmic_init(unsigned char bus) +{ + static const char name[] = "MAX77686_PMIC"; + struct pmic *p = pmic_alloc(); +#if CONFIG_IS_ENABLED(OF_CONTROL) + const void *blob = gd->fdt_blob; + int node, parent, tmp; +#endif + + if (!p) { + printf("%s: POWER allocation error!\n", __func__); + return -ENOMEM; + } + +#if CONFIG_IS_ENABLED(OF_CONTROL) + node = fdtdec_next_compatible(blob, 0, COMPAT_MAXIM_MAX77686_PMIC); + if (node < 0) { + debug("PMIC: No node for PMIC Chip in device tree\n"); + debug("node = %d\n", node); + return -ENODEV; + } + + parent = fdt_parent_offset(blob, node); + if (parent < 0) { + debug("%s: Cannot find node parent\n", __func__); + return -ENODEV; + } + + /* tmp since p->bus is unsigned */ + tmp = i2c_get_bus_num_fdt(parent); + if (tmp < 0) { + debug("%s: Cannot find I2C bus\n", __func__); + return -ENODEV; + } + p->bus = tmp; + p->hw.i2c.addr = fdtdec_get_int(blob, node, "reg", 9); +#else + p->bus = bus; + p->hw.i2c.addr = MAX77686_I2C_ADDR; +#endif + + p->name = name; + p->interface = PMIC_I2C; + p->number_of_regs = MAX77686_NUM_OF_REGS; + p->hw.i2c.tx_num = 1; + + puts("Board PMIC init\n"); + + return 0; +} diff --git a/drivers/power/regulator/max77686.c b/drivers/power/regulator/max77686.c index 752dc88..d52f872 100644 --- a/drivers/power/regulator/max77686.c +++ b/drivers/power/regulator/max77686.c @@ -25,29 +25,29 @@ static struct dm_regulator_mode max77686_ldo_mode_standby1[] = { MODE(OPMODE_OFF, MAX77686_LDO_MODE_OFF, "OFF"), MODE(OPMODE_LPM, MAX77686_LDO_MODE_LPM, "LPM"), - MODE(OPMODE_STANDBY_LPM, MAX77686_LDO_MODE_STANDBY_LPM, "ON/LPM"), + MODE(OPMODE_ON_AUTO_LPM, MAX77686_LDO_MODE_ON_AUTO_LPM, "ON/LPM"), MODE(OPMODE_ON, MAX77686_LDO_MODE_ON, "ON"), }; /* LDO: 2,6,7,8,10,11,12,14,15,16 */ static struct dm_regulator_mode max77686_ldo_mode_standby2[] = { MODE(OPMODE_OFF, MAX77686_LDO_MODE_OFF, "OFF"), - MODE(OPMODE_STANDBY, MAX77686_LDO_MODE_STANDBY, "ON/OFF"), - MODE(OPMODE_STANDBY_LPM, MAX77686_LDO_MODE_STANDBY_LPM, "ON/LPM"), + MODE(OPMODE_ON_AUTO_OFF, MAX77686_LDO_MODE_ON_AUTO_OFF, "ON/OFF"), + MODE(OPMODE_ON_AUTO_LPM, MAX77686_LDO_MODE_ON_AUTO_LPM, "ON/LPM"), MODE(OPMODE_ON, MAX77686_LDO_MODE_ON, "ON"), }; /* Buck: 1 */ static struct dm_regulator_mode max77686_buck_mode_standby[] = { MODE(OPMODE_OFF, MAX77686_BUCK_MODE_OFF, "OFF"), - MODE(OPMODE_STANDBY, MAX77686_BUCK_MODE_STANDBY, "ON/OFF"), + MODE(OPMODE_ON_AUTO_OFF, MAX77686_BUCK_MODE_ON_AUTO_OFF, "ON/OFF"), MODE(OPMODE_ON, MAX77686_BUCK_MODE_ON, "ON"), }; /* Buck: 2,3,4 */ static struct dm_regulator_mode max77686_buck_mode_lpm[] = { MODE(OPMODE_OFF, MAX77686_BUCK_MODE_OFF, "OFF"), - MODE(OPMODE_STANDBY, MAX77686_BUCK_MODE_STANDBY, "ON/OFF"), + MODE(OPMODE_ON_AUTO_OFF, MAX77686_BUCK_MODE_ON_AUTO_OFF, "ON/OFF"), MODE(OPMODE_LPM, MAX77686_BUCK_MODE_LPM, "LPM"), MODE(OPMODE_ON, MAX77686_BUCK_MODE_ON, "ON"), }; @@ -198,7 +198,7 @@ static int max77686_ldo_hex2mode(int ldo, int hex) switch (hex) { case MAX77686_LDO_MODE_OFF: return OPMODE_OFF; - case MAX77686_LDO_MODE_LPM: /* == MAX77686_LDO_MODE_STANDBY: */ + case MAX77686_LDO_MODE_LPM: /* == MAX77686_LDO_MODE_ON_AUTO_OFF: */ /* The same mode values but different meaning for each ldo */ switch (ldo) { case 2: @@ -211,12 +211,12 @@ static int max77686_ldo_hex2mode(int ldo, int hex) case 14: case 15: case 16: - return OPMODE_STANDBY; + return OPMODE_ON_AUTO_OFF; default: return OPMODE_LPM; } - case MAX77686_LDO_MODE_STANDBY_LPM: - return OPMODE_STANDBY_LPM; + case MAX77686_LDO_MODE_ON_AUTO_LPM: + return OPMODE_ON_AUTO_LPM; case MAX77686_LDO_MODE_ON: return OPMODE_ON; default: @@ -234,13 +234,13 @@ static int max77686_buck_hex2mode(int buck, int hex) return OPMODE_OFF; case MAX77686_BUCK_MODE_ON: return OPMODE_ON; - case MAX77686_BUCK_MODE_STANDBY: + case MAX77686_BUCK_MODE_ON_AUTO_OFF: switch (buck) { case 1: case 2: case 3: case 4: - return OPMODE_STANDBY; + return OPMODE_ON_AUTO_OFF; default: return -EINVAL; } @@ -461,7 +461,7 @@ static int max77686_ldo_mode(struct udevice *dev, int op, int *opmode) mode = MAX77686_LDO_MODE_LPM; } break; - case OPMODE_STANDBY: + case OPMODE_ON_AUTO_OFF: switch (ldo) { case 2: case 6: @@ -473,14 +473,14 @@ static int max77686_ldo_mode(struct udevice *dev, int op, int *opmode) case 14: case 15: case 16: - mode = MAX77686_LDO_MODE_STANDBY; + mode = MAX77686_LDO_MODE_ON_AUTO_OFF; break; default: return -EINVAL; } break; - case OPMODE_STANDBY_LPM: - mode = MAX77686_LDO_MODE_STANDBY_LPM; + case OPMODE_ON_AUTO_LPM: + mode = MAX77686_LDO_MODE_ON_AUTO_LPM; break; case OPMODE_ON: mode = MAX77686_LDO_MODE_ON; @@ -580,13 +580,13 @@ static int max77686_buck_mode(struct udevice *dev, int op, int *opmode) case OPMODE_OFF: mode = MAX77686_BUCK_MODE_OFF; break; - case OPMODE_STANDBY: + case OPMODE_ON_AUTO_OFF: switch (buck) { case 1: case 2: case 3: case 4: - mode = MAX77686_BUCK_MODE_STANDBY << mode_shift; + mode = MAX77686_BUCK_MODE_ON_AUTO_OFF << mode_shift; break; default: mode = 0xff; diff --git a/include/power/max77686_pmic.h b/include/power/max77686_pmic.h index 82fe350..d4c89b9 100644 --- a/include/power/max77686_pmic.h +++ b/include/power/max77686_pmic.h @@ -149,9 +149,9 @@ enum { enum { OPMODE_OFF = 0, OPMODE_LPM, - OPMODE_STANDBY, - OPMODE_STANDBY_LPM, OPMODE_ON, + OPMODE_ON_AUTO_OFF, + OPMODE_ON_AUTO_LPM, }; #ifdef CONFIG_POWER @@ -164,11 +164,11 @@ int max77686_set_buck_mode(struct pmic *p, int buck, char opmode); #define MAX77686_LDO_VOLT_MAX_HEX 0x3f #define MAX77686_LDO_VOLT_MASK 0x3f #define MAX77686_LDO_MODE_MASK 0xc0 -#define MAX77686_LDO_MODE_OFF (0x00 << 0x06) -#define MAX77686_LDO_MODE_LPM (0x01 << 0x06) -#define MAX77686_LDO_MODE_STANDBY (0x01 << 0x06) -#define MAX77686_LDO_MODE_STANDBY_LPM (0x02 << 0x06) -#define MAX77686_LDO_MODE_ON (0x03 << 0x06) +#define MAX77686_LDO_MODE_OFF (0x0 << 6) +#define MAX77686_LDO_MODE_LPM (0x1 << 6) /* ldo1 compatible */ +#define MAX77686_LDO_MODE_ON_AUTO_OFF (0x1 << 6) /* ldo2 compatible */ +#define MAX77686_LDO_MODE_ON_AUTO_LPM (0x2 << 6) +#define MAX77686_LDO_MODE_ON (0x3 << 6) #define MAX77686_BUCK234_VOLT_MAX_HEX 0xff #define MAX77686_BUCK234_VOLT_MASK 0xff #define MAX77686_BUCK_VOLT_MAX_HEX 0x3f @@ -177,7 +177,7 @@ int max77686_set_buck_mode(struct pmic *p, int buck, char opmode); #define MAX77686_BUCK_MODE_SHIFT_1 0x00 #define MAX77686_BUCK_MODE_SHIFT_2 0x04 #define MAX77686_BUCK_MODE_OFF 0x00 -#define MAX77686_BUCK_MODE_STANDBY 0x01 +#define MAX77686_BUCK_MODE_ON_AUTO_OFF 0x01 #define MAX77686_BUCK_MODE_LPM 0x02 #define MAX77686_BUCK_MODE_ON 0x03