Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0+ */ |
Henrik Nordstrom | aa382ad | 2014-06-13 22:55:50 +0200 | [diff] [blame] | 2 | /* |
| 3 | * (C) Copyright 2012 Henrik Nordstrom <henrik@henriknordstrom.net> |
Henrik Nordstrom | aa382ad | 2014-06-13 22:55:50 +0200 | [diff] [blame] | 4 | */ |
| 5 | |
Olliver Schinagl | cba2a7c3 | 2018-11-21 20:05:27 +0200 | [diff] [blame] | 6 | #include <linux/bitops.h> |
| 7 | |
Paul Kocialkowski | cb189b7 | 2015-03-22 18:08:21 +0100 | [diff] [blame] | 8 | enum axp209_reg { |
| 9 | AXP209_POWER_STATUS = 0x00, |
| 10 | AXP209_CHIP_VERSION = 0x03, |
Hans de Goede | 84a8b79 | 2015-10-04 12:01:17 +0200 | [diff] [blame] | 11 | AXP209_OUTPUT_CTRL = 0x12, |
Paul Kocialkowski | cb189b7 | 2015-03-22 18:08:21 +0100 | [diff] [blame] | 12 | AXP209_DCDC2_VOLTAGE = 0x23, |
Olliver Schinagl | 353b4cf | 2018-11-21 20:05:30 +0200 | [diff] [blame] | 13 | AXP209_VRC_DCDC2_LDO3 = 0x25, |
Paul Kocialkowski | cb189b7 | 2015-03-22 18:08:21 +0100 | [diff] [blame] | 14 | AXP209_DCDC3_VOLTAGE = 0x27, |
| 15 | AXP209_LDO24_VOLTAGE = 0x28, |
| 16 | AXP209_LDO3_VOLTAGE = 0x29, |
| 17 | AXP209_IRQ_ENABLE1 = 0x40, |
| 18 | AXP209_IRQ_ENABLE2 = 0x41, |
| 19 | AXP209_IRQ_ENABLE3 = 0x42, |
| 20 | AXP209_IRQ_ENABLE4 = 0x43, |
| 21 | AXP209_IRQ_ENABLE5 = 0x44, |
| 22 | AXP209_IRQ_STATUS5 = 0x4c, |
| 23 | AXP209_SHUTDOWN = 0x32, |
Paul Kocialkowski | cb189b7 | 2015-03-22 18:08:21 +0100 | [diff] [blame] | 24 | }; |
| 25 | |
Olliver Schinagl | cba2a7c3 | 2018-11-21 20:05:27 +0200 | [diff] [blame] | 26 | #define AXP209_POWER_STATUS_ON_BY_DC BIT(0) |
| 27 | #define AXP209_POWER_STATUS_VBUS_USABLE BIT(4) |
Paul Kocialkowski | cb189b7 | 2015-03-22 18:08:21 +0100 | [diff] [blame] | 28 | |
Olliver Schinagl | 185210d | 2018-11-21 20:05:28 +0200 | [diff] [blame] | 29 | #define AXP209_CHIP_VERSION_MASK 0x0f |
| 30 | |
Olliver Schinagl | cba2a7c3 | 2018-11-21 20:05:27 +0200 | [diff] [blame] | 31 | #define AXP209_OUTPUT_CTRL_EXTEN BIT(0) |
| 32 | #define AXP209_OUTPUT_CTRL_DCDC3 BIT(1) |
| 33 | #define AXP209_OUTPUT_CTRL_LDO2 BIT(2) |
| 34 | #define AXP209_OUTPUT_CTRL_LDO4 BIT(3) |
| 35 | #define AXP209_OUTPUT_CTRL_DCDC2 BIT(4) |
| 36 | #define AXP209_OUTPUT_CTRL_LDO3 BIT(6) |
Hans de Goede | 84a8b79 | 2015-10-04 12:01:17 +0200 | [diff] [blame] | 37 | |
Olliver Schinagl | 353b4cf | 2018-11-21 20:05:30 +0200 | [diff] [blame] | 38 | /* |
| 39 | * AXP209 datasheet contains wrong information about LDO3 VRC: |
| 40 | * - VRC is actually enabled when BIT(1) is True |
| 41 | * - VRC is actually not enabled by default (BIT(3) = 0 after reset) |
| 42 | */ |
| 43 | #define AXP209_VRC_LDO3_EN BIT(3) |
| 44 | #define AXP209_VRC_DCDC2_EN BIT(2) |
| 45 | #define AXP209_VRC_LDO3_800uV_uS (BIT(1) | AXP209_VRC_LDO3_EN) |
| 46 | #define AXP209_VRC_LDO3_1600uV_uS AXP209_VRC_LDO3_EN |
| 47 | #define AXP209_VRC_DCDC2_800uV_uS (BIT(0) | AXP209_VRC_DCDC2_EN) |
| 48 | #define AXP209_VRC_DCDC2_1600uV_uS AXP209_VRC_DCDC2_EN |
| 49 | #define AXP209_VRC_LDO3_MASK 0xa |
| 50 | #define AXP209_VRC_DCDC2_MASK 0x5 |
| 51 | #define AXP209_VRC_DCDC2_SLOPE_SET(reg, cfg) \ |
| 52 | (((reg) & ~AXP209_VRC_DCDC2_MASK) | \ |
| 53 | ((cfg) & AXP209_VRC_DCDC2_MASK)) |
| 54 | #define AXP209_VRC_LDO3_SLOPE_SET(reg, cfg) \ |
| 55 | (((reg) & ~AXP209_VRC_LDO3_MASK) | \ |
| 56 | ((cfg) & AXP209_VRC_LDO3_MASK)) |
| 57 | |
Olliver Schinagl | 9238249 | 2018-11-21 20:05:29 +0200 | [diff] [blame] | 58 | #define AXP209_LDO24_LDO2_MASK 0xf0 |
| 59 | #define AXP209_LDO24_LDO4_MASK 0x0f |
| 60 | #define AXP209_LDO24_LDO2_SET(reg, cfg) \ |
| 61 | (((reg) & ~AXP209_LDO24_LDO2_MASK) | \ |
| 62 | (((cfg) << 4) & AXP209_LDO24_LDO2_MASK)) |
| 63 | #define AXP209_LDO24_LDO4_SET(reg, cfg) \ |
| 64 | (((reg) & ~AXP209_LDO24_LDO4_MASK) | \ |
| 65 | (((cfg) << 0) & AXP209_LDO24_LDO4_MASK)) |
| 66 | |
| 67 | #define AXP209_LDO3_VOLTAGE_FROM_LDO3IN BIT(7) |
| 68 | #define AXP209_LDO3_VOLTAGE_MASK 0x7f |
| 69 | #define AXP209_LDO3_VOLTAGE_SET(x) ((x) & AXP209_LDO3_VOLTAGE_MASK) |
| 70 | |
Olliver Schinagl | cba2a7c3 | 2018-11-21 20:05:27 +0200 | [diff] [blame] | 71 | #define AXP209_IRQ5_PEK_UP BIT(6) |
| 72 | #define AXP209_IRQ5_PEK_DOWN BIT(5) |
Paul Kocialkowski | cb189b7 | 2015-03-22 18:08:21 +0100 | [diff] [blame] | 73 | |
Olliver Schinagl | cba2a7c3 | 2018-11-21 20:05:27 +0200 | [diff] [blame] | 74 | #define AXP209_POWEROFF BIT(7) |
Paul Kocialkowski | cb189b7 | 2015-03-22 18:08:21 +0100 | [diff] [blame] | 75 | |
Hans de Goede | 3ae1d13 | 2015-04-25 17:25:14 +0200 | [diff] [blame] | 76 | /* For axp_gpio.c */ |
Samuel Holland | 41c1ed4 | 2021-08-22 18:18:04 -0500 | [diff] [blame] | 77 | #ifdef CONFIG_AXP209_POWER |
Hans de Goede | 3ae1d13 | 2015-04-25 17:25:14 +0200 | [diff] [blame] | 78 | #define AXP_POWER_STATUS 0x00 |
Andre Przywara | 910bea4 | 2022-01-21 13:37:31 +0000 | [diff] [blame] | 79 | #define AXP_POWER_STATUS_ALDO_IN BIT(0) |
Hans de Goede | 3ae1d13 | 2015-04-25 17:25:14 +0200 | [diff] [blame] | 80 | #define AXP_GPIO0_CTRL 0x90 |
| 81 | #define AXP_GPIO1_CTRL 0x92 |
| 82 | #define AXP_GPIO2_CTRL 0x93 |
Olliver Schinagl | cba2a7c3 | 2018-11-21 20:05:27 +0200 | [diff] [blame] | 83 | #define AXP_GPIO_CTRL_OUTPUT_LOW 0x00 /* Drive pin low */ |
| 84 | #define AXP_GPIO_CTRL_OUTPUT_HIGH 0x01 /* Drive pin high */ |
| 85 | #define AXP_GPIO_CTRL_INPUT 0x02 /* Input */ |
Hans de Goede | 3ae1d13 | 2015-04-25 17:25:14 +0200 | [diff] [blame] | 86 | #define AXP_GPIO_STATE 0x94 |
Olliver Schinagl | cba2a7c3 | 2018-11-21 20:05:27 +0200 | [diff] [blame] | 87 | #define AXP_GPIO_STATE_OFFSET 4 |
Samuel Holland | 41c1ed4 | 2021-08-22 18:18:04 -0500 | [diff] [blame] | 88 | #endif |