summaryrefslogtreecommitdiff
path: root/drivers/power/pmic/axp80x.c
blob: 727e4214332f312e67a3770dad9f4f3058f19c87 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
/*
 * (C) Copyright 2016 Theobroma Systems Design und Consulting GmbH
 * Written by Philipp Tomsich <philipp.tomsich@theobroma-systems.com>
 *
 * SPDX-License-Identifier:	GPL-2.0+
 */

#include <common.h>
#include <dm.h>
#include <i2c.h>
#include <errno.h>
#include <fdtdec.h>
#include <libfdt.h>
#include <power/axp806_pmic.h>
#include <power/pmic.h>
#include <asm/arch/rsb.h>

#ifndef CONFIG_SPL_BUILD

DECLARE_GLOBAL_DATA_PTR;


#if 0
/* TODO: implement me */
static const struct pmic_child_info pmic_children_info[] = {
	{ .prefix = "DCDC_REG", .driver = "rk808_buck"},
	{ .prefix = "LDO_REG", .driver = "rk808_ldo"},
	{ .prefix = "SWITCH_REG", .driver = "rk808_switch"},
	{ },
};
#endif

static int axp806_reg_count(struct udevice *dev)
{
	return AXP806_NUM_OF_REGS;
}

static int axp808_reg_count(struct udevice *dev)
{
	return 0xff;   /* TODO */
}

static int axp80x_write(struct udevice *dev,
			uint reg, const uint8_t *buff, int len)
{
	int ret;

	ret = dm_i2c_write(dev, reg, buff, len);
	if (ret) {
		debug("write error to device: %p register: %#x!", dev, reg);
		return ret;
	}

	return 0;
}

static int axp80x_read(struct udevice *dev, uint reg, uint8_t *buff, int len)
{
	int ret;

	ret = dm_i2c_read(dev, reg, buff, len);
	if (ret) {
		debug("read error from device: %p register: %#x!", dev, reg);
		return ret;
	}

	return 0;
}

#if CONFIG_IS_ENABLED(PMIC_CHILDREN)
static int axp80x_bind(struct udevice *dev, const struct pmic_child_info* pmic_children)
{
	const void *blob = gd->fdt_blob;
	int regulators_node;
	int children;

	regulators_node = fdt_subnode_offset(blob, dev->of_offset,
					     "regulators");
	if (regulators_node <= 0) {
		debug("%s: %s regulators subnode not found!", __func__,
		      dev->name);
		return -ENXIO;
	}

	debug("%s: '%s' - found regulators subnode\n", __func__, dev->name);

	children = pmic_bind_children(dev, regulators_node, pmic_children_info);
	if (!children)
		debug("%s: %s - no child found\n", __func__, dev->name);

	/* Always return success for this device */
	return 0;
}

static int axp806_bind(struct udevice *dev)
{
	return axp80x_bind(dev, axp806_children_info);
}

static int axp808_bind(struct udevice *dev)
{
	return axp80x_bind(dev, axp808_children_info);
}
#endif

static void axp80x_set_name(struct udevice *dev, const char* prefix)
{
	struct dm_i2c_chip *chip = dev_get_parent_platdata(dev);
	char                devname[16];

	snprintf(devname, sizeof(devname), "%s@%x", prefix, chip->chip_addr);
	device_set_name(dev, devname);
}

static int axp806_probe(struct udevice *dev)
{
	/* Perform chip-specific initialisation */
	axp80x_set_name(dev, "axp806");
	/* The AXP806 needs to write to the 'register address
	   extension' register to fully initialise it for
	   communication using this driver.  */
	dm_i2c_write(dev, AXP806_REGADDR_EXT, (const uint8_t*)"\x10", 1);

	return 0;
}

static int axp808_probe(struct udevice *dev)
{
	/* Perform chip-specific initialisation */
	axp80x_set_name(dev, "axp808");

	return 0;
}

static struct dm_pmic_ops axp806_ops = {
	.reg_count = axp806_reg_count,
	.read = axp80x_read,
	.write = axp80x_write,
};

static struct dm_pmic_ops axp808_ops = {
	.reg_count = axp808_reg_count,
	.read = axp80x_read,
	.write = axp80x_write,
};

static const struct udevice_id axp806_ids[] = {
	{ .compatible = "x-powers,axp806" },
	{ }
};

static const struct udevice_id axp808_ids[] = {
	{ .compatible = "x-powers,axp808" },
	{ }
};

U_BOOT_DRIVER(pmic_axp806) = {
	.name = "AXP806 PMIC",
	.id = UCLASS_PMIC,
	.probe = axp806_probe,
	.of_match = axp806_ids,
#if CONFIG_IS_ENABLED(PMIC_CHILDREN)
	.bind = axp806_bind,
#endif
	.ops = &axp806_ops,
};

U_BOOT_DRIVER(pmic_axp808) = {
	.name = "AXP808 PMIC",
	.id = UCLASS_PMIC,
	.probe = axp808_probe,
	.of_match = axp808_ids,
#if CONFIG_IS_ENABLED(PMIC_CHILDREN)
	.bind = axp808_bind,
#endif
	.ops = &axp808_ops,
};

#endif