summaryrefslogtreecommitdiff
path: root/drivers/regulator/isl9305.c
blob: 0f7560093091a18a93330c903413e55e97c375dd (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
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
// SPDX-License-Identifier: GPL-2.0-or-later
/*
 * isl9305 - Intersil ISL9305 DCDC regulator
 *
 * Copyright 2014 Linaro Ltd
 *
 * Author: Mark Brown <broonie@kernel.org>
 */

#include <linux/module.h>
#include <linux/err.h>
#include <linux/i2c.h>
#include <linux/of.h>
#include <linux/platform_data/isl9305.h>
#include <linux/regmap.h>
#include <linux/regulator/driver.h>
#include <linux/regulator/of_regulator.h>
#include <linux/slab.h>

/*
 * Registers
 */
#define ISL9305_DCD1OUT          0x0
#define ISL9305_DCD2OUT          0x1
#define ISL9305_LDO1OUT          0x2
#define ISL9305_LDO2OUT          0x3
#define ISL9305_DCD_PARAMETER    0x4
#define ISL9305_SYSTEM_PARAMETER 0x5
#define ISL9305_DCD_SRCTL        0x6

#define ISL9305_MAX_REG ISL9305_DCD_SRCTL

/*
 * DCD_PARAMETER
 */
#define ISL9305_DCD_PHASE   0x40
#define ISL9305_DCD2_ULTRA  0x20
#define ISL9305_DCD1_ULTRA  0x10
#define ISL9305_DCD2_BLD    0x08
#define ISL9305_DCD1_BLD    0x04
#define ISL9305_DCD2_MODE   0x02
#define ISL9305_DCD1_MODE   0x01

/*
 * SYSTEM_PARAMETER
 */
#define ISL9305_I2C_EN      0x40
#define ISL9305_DCDPOR_MASK 0x30
#define ISL9305_LDO2_EN     0x08
#define ISL9305_LDO1_EN     0x04
#define ISL9305_DCD2_EN     0x02
#define ISL9305_DCD1_EN     0x01

/*
 * DCD_SRCTL
 */
#define ISL9305_DCD2SR_MASK 0xc0
#define ISL9305_DCD1SR_MASK 0x07

static const struct regulator_ops isl9305_ops = {
	.enable = regulator_enable_regmap,
	.disable = regulator_disable_regmap,
	.is_enabled = regulator_is_enabled_regmap,
	.list_voltage = regulator_list_voltage_linear,
	.get_voltage_sel = regulator_get_voltage_sel_regmap,
	.set_voltage_sel = regulator_set_voltage_sel_regmap,
};

static const struct regulator_desc isl9305_regulators[] = {
	[ISL9305_DCD1] = {
		.name =		"DCD1",
		.of_match =	of_match_ptr("dcd1"),
		.regulators_node = of_match_ptr("regulators"),
		.n_voltages =	0x70,
		.min_uV =	825000,
		.uV_step =	25000,
		.vsel_reg =	ISL9305_DCD1OUT,
		.vsel_mask =	0x7f,
		.enable_reg =	ISL9305_SYSTEM_PARAMETER,
		.enable_mask =	ISL9305_DCD1_EN,
		.supply_name =	"VINDCD1",
		.ops =		&isl9305_ops,
		.owner =	THIS_MODULE,
	},
	[ISL9305_DCD2] = {
		.name =		"DCD2",
		.of_match =	of_match_ptr("dcd2"),
		.regulators_node = of_match_ptr("regulators"),
		.n_voltages =	0x70,
		.min_uV =	825000,
		.uV_step =	25000,
		.vsel_reg =	ISL9305_DCD2OUT,
		.vsel_mask =	0x7f,
		.enable_reg =	ISL9305_SYSTEM_PARAMETER,
		.enable_mask =	ISL9305_DCD2_EN,
		.supply_name =	"VINDCD2",
		.ops =		&isl9305_ops,
		.owner =	THIS_MODULE,
	},
	[ISL9305_LDO1] = {
		.name =		"LDO1",
		.of_match =	of_match_ptr("ldo1"),
		.regulators_node = of_match_ptr("regulators"),
		.n_voltages =	0x37,
		.min_uV =	900000,
		.uV_step =	50000,
		.vsel_reg =	ISL9305_LDO1OUT,
		.vsel_mask =	0x3f,
		.enable_reg =	ISL9305_SYSTEM_PARAMETER,
		.enable_mask =	ISL9305_LDO1_EN,
		.supply_name =	"VINLDO1",
		.ops =		&isl9305_ops,
		.owner =	THIS_MODULE,
	},
	[ISL9305_LDO2] = {
		.name =		"LDO2",
		.of_match =	of_match_ptr("ldo2"),
		.regulators_node = of_match_ptr("regulators"),
		.n_voltages =	0x37,
		.min_uV =	900000,
		.uV_step =	50000,
		.vsel_reg =	ISL9305_LDO2OUT,
		.vsel_mask =	0x3f,
		.enable_reg =	ISL9305_SYSTEM_PARAMETER,
		.enable_mask =	ISL9305_LDO2_EN,
		.supply_name =	"VINLDO2",
		.ops =		&isl9305_ops,
		.owner =	THIS_MODULE,
	},
};

static const struct regmap_config isl9305_regmap = {
	.reg_bits = 8,
	.val_bits = 8,

	.max_register = ISL9305_MAX_REG,
	.cache_type = REGCACHE_RBTREE,
};

static int isl9305_i2c_probe(struct i2c_client *i2c)
{
	struct regulator_config config = { };
	struct isl9305_pdata *pdata = i2c->dev.platform_data;
	struct regulator_dev *rdev;
	struct regmap *regmap;
	int i, ret;

	regmap = devm_regmap_init_i2c(i2c, &isl9305_regmap);
	if (IS_ERR(regmap)) {
		ret = PTR_ERR(regmap);
		dev_err(&i2c->dev, "Failed to create regmap: %d\n", ret);
		return ret;
	}

	config.dev = &i2c->dev;

	for (i = 0; i < ARRAY_SIZE(isl9305_regulators); i++) {
		if (pdata)
			config.init_data = pdata->init_data[i];
		else
			config.init_data = NULL;

		rdev = devm_regulator_register(&i2c->dev,
					       &isl9305_regulators[i],
					       &config);
		if (IS_ERR(rdev)) {
			ret = PTR_ERR(rdev);
			dev_err(&i2c->dev, "Failed to register %s: %d\n",
				isl9305_regulators[i].name, ret);
			return ret;
		}
	}

	return 0;
}

#ifdef CONFIG_OF
static const struct of_device_id isl9305_dt_ids[] = {
	{ .compatible = "isl,isl9305" }, /* for backward compat., don't use */
	{ .compatible = "isil,isl9305" },
	{ .compatible = "isl,isl9305h" }, /* for backward compat., don't use */
	{ .compatible = "isil,isl9305h" },
	{},
};
MODULE_DEVICE_TABLE(of, isl9305_dt_ids);
#endif

static const struct i2c_device_id isl9305_i2c_id[] = {
	{ "isl9305", },
	{ "isl9305h", },
	{ }
};
MODULE_DEVICE_TABLE(i2c, isl9305_i2c_id);

static struct i2c_driver isl9305_regulator_driver = {
	.driver = {
		.name = "isl9305",
		.probe_type = PROBE_PREFER_ASYNCHRONOUS,
		.of_match_table	= of_match_ptr(isl9305_dt_ids),
	},
	.probe = isl9305_i2c_probe,
	.id_table = isl9305_i2c_id,
};

module_i2c_driver(isl9305_regulator_driver);

MODULE_AUTHOR("Mark Brown");
MODULE_DESCRIPTION("Intersil ISL9305 DCDC regulator");
MODULE_LICENSE("GPL");