2 * (C) Copyright 2015 Hans de Goede <hdegoede@redhat.com>
4 * Sunxi PMIC bus access helpers
6 * The axp152 & axp209 use an i2c bus, the axp221 uses the p2wi bus and the
7 * axp223 uses the rsb bus, these functions abstract this.
9 * SPDX-License-Identifier: GPL-2.0+
13 #include <asm/arch/p2wi.h>
14 #include <asm/arch/rsb.h>
15 #include <asm/arch/pmic_bus.h>
17 #define AXP221_CHIP_ADDR 0x68
18 #define AXP221_CTRL_ADDR 0x3e
19 #define AXP221_INIT_DATA 0x3e
21 #define AXP223_DEVICE_ADDR 0x3a3
22 #define AXP223_RUNTIME_ADDR 0x2d
24 int pmic_bus_init(void)
26 /* This cannot be 0 because it is used in SPL before BSS is ready */
27 static int needs_init = 1;
33 #ifdef CONFIG_MACH_SUN6I
35 ret = p2wi_change_to_p2wi_mode(AXP221_CHIP_ADDR, AXP221_CTRL_ADDR,
42 ret = rsb_set_device_address(AXP223_DEVICE_ADDR, AXP223_RUNTIME_ADDR);
51 int pmic_bus_read(u8 reg, u8 *data)
53 #ifdef CONFIG_MACH_SUN6I
54 return p2wi_read(reg, data);
56 return rsb_read(AXP223_RUNTIME_ADDR, reg, data);
60 int pmic_bus_write(u8 reg, u8 data)
62 #ifdef CONFIG_MACH_SUN6I
63 return p2wi_write(reg, data);
65 return rsb_write(AXP223_RUNTIME_ADDR, reg, data);
69 int pmic_bus_setbits(u8 reg, u8 bits)
74 ret = pmic_bus_read(reg, &val);
79 return pmic_bus_write(reg, val);
82 int pmic_bus_clrbits(u8 reg, u8 bits)
87 ret = pmic_bus_read(reg, &val);
92 return pmic_bus_write(reg, val);