blob: 8be252f81b091c88282123d37c13a52a5007927e [file] [log] [blame]
Thomas Gleixnerd2912cb2019-06-04 10:11:33 +02001// SPDX-License-Identifier: GPL-2.0-only
Marek Szyprowski0cbdf7b2009-05-19 07:33:55 +02002/*
3 * Regulator driver for National Semiconductors LP3971 PMIC chip
4 *
5 * Copyright (C) 2009 Samsung Electronics
6 * Author: Marek Szyprowski <m.szyprowski@samsung.com>
7 *
8 * Based on wm8350.c
Marek Szyprowski0cbdf7b2009-05-19 07:33:55 +02009 */
10
11#include <linux/bug.h>
12#include <linux/err.h>
13#include <linux/i2c.h>
14#include <linux/kernel.h>
Paul Gortmaker65602c32011-07-17 16:28:23 -040015#include <linux/module.h>
Marek Szyprowski0cbdf7b2009-05-19 07:33:55 +020016#include <linux/regulator/driver.h>
17#include <linux/regulator/lp3971.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090018#include <linux/slab.h>
Marek Szyprowski0cbdf7b2009-05-19 07:33:55 +020019
20struct lp3971 {
21 struct device *dev;
22 struct mutex io_lock;
23 struct i2c_client *i2c;
Marek Szyprowski0cbdf7b2009-05-19 07:33:55 +020024};
25
26static u8 lp3971_reg_read(struct lp3971 *lp3971, u8 reg);
27static int lp3971_set_bits(struct lp3971 *lp3971, u8 reg, u16 mask, u16 val);
28
29#define LP3971_SYS_CONTROL1_REG 0x07
30
31/* System control register 1 initial value,
32 bits 4 and 5 are EPROM programmable */
33#define SYS_CONTROL1_INIT_VAL 0x40
34#define SYS_CONTROL1_INIT_MASK 0xCF
35
36#define LP3971_BUCK_VOL_ENABLE_REG 0x10
37#define LP3971_BUCK_VOL_CHANGE_REG 0x20
38
39/* Voltage control registers shift:
40 LP3971_BUCK1 -> 0
41 LP3971_BUCK2 -> 4
42 LP3971_BUCK3 -> 6
43*/
Axel Lin451a73cd2010-03-11 09:50:07 +080044#define BUCK_VOL_CHANGE_SHIFT(x) (((!!x) << 2) | (x & ~0x01))
Marek Szyprowski0cbdf7b2009-05-19 07:33:55 +020045#define BUCK_VOL_CHANGE_FLAG_GO 0x01
46#define BUCK_VOL_CHANGE_FLAG_TARGET 0x02
47#define BUCK_VOL_CHANGE_FLAG_MASK 0x03
48
49#define LP3971_BUCK1_BASE 0x23
50#define LP3971_BUCK2_BASE 0x29
51#define LP3971_BUCK3_BASE 0x32
52
Tobias Klauser6faa7e02009-12-23 14:13:17 +010053static const int buck_base_addr[] = {
Marek Szyprowski0cbdf7b2009-05-19 07:33:55 +020054 LP3971_BUCK1_BASE,
55 LP3971_BUCK2_BASE,
56 LP3971_BUCK3_BASE,
57};
58
59#define LP3971_BUCK_TARGET_VOL1_REG(x) (buck_base_addr[x])
60#define LP3971_BUCK_TARGET_VOL2_REG(x) (buck_base_addr[x]+1)
61
Axel Lincad8d762012-05-20 13:30:28 +080062static const unsigned int buck_voltage_map[] = {
63 0, 800000, 850000, 900000, 950000, 1000000, 1050000, 1100000,
64 1150000, 1200000, 1250000, 1300000, 1350000, 1400000, 1450000, 1500000,
65 1550000, 1600000, 1650000, 1700000, 1800000, 1900000, 2500000, 2800000,
66 3000000, 3300000,
Marek Szyprowski0cbdf7b2009-05-19 07:33:55 +020067};
68
69#define BUCK_TARGET_VOL_MASK 0x3f
Marek Szyprowski0cbdf7b2009-05-19 07:33:55 +020070
71#define LP3971_BUCK_RAMP_REG(x) (buck_base_addr[x]+2)
72
73#define LP3971_LDO_ENABLE_REG 0x12
74#define LP3971_LDO_VOL_CONTR_BASE 0x39
75
76/* Voltage control registers:
77 LP3971_LDO1 -> LP3971_LDO_VOL_CONTR_BASE + 0
78 LP3971_LDO2 -> LP3971_LDO_VOL_CONTR_BASE + 0
79 LP3971_LDO3 -> LP3971_LDO_VOL_CONTR_BASE + 1
80 LP3971_LDO4 -> LP3971_LDO_VOL_CONTR_BASE + 1
81 LP3971_LDO5 -> LP3971_LDO_VOL_CONTR_BASE + 2
82*/
83#define LP3971_LDO_VOL_CONTR_REG(x) (LP3971_LDO_VOL_CONTR_BASE + (x >> 1))
84
85/* Voltage control registers shift:
86 LP3971_LDO1 -> 0, LP3971_LDO2 -> 4
87 LP3971_LDO3 -> 0, LP3971_LDO4 -> 4
88 LP3971_LDO5 -> 0
89*/
90#define LDO_VOL_CONTR_SHIFT(x) ((x & 1) << 2)
91#define LDO_VOL_CONTR_MASK 0x0f
92
Axel Lincad8d762012-05-20 13:30:28 +080093static const unsigned int ldo45_voltage_map[] = {
94 1000000, 1050000, 1100000, 1150000, 1200000, 1250000, 1300000, 1350000,
95 1400000, 1500000, 1800000, 1900000, 2500000, 2800000, 3000000, 3300000,
Marek Szyprowski0cbdf7b2009-05-19 07:33:55 +020096};
97
Axel Lincad8d762012-05-20 13:30:28 +080098static const unsigned int ldo123_voltage_map[] = {
99 1800000, 1900000, 2000000, 2100000, 2200000, 2300000, 2400000, 2500000,
100 2600000, 2700000, 2800000, 2900000, 3000000, 3100000, 3200000, 3300000,
Marek Szyprowski0cbdf7b2009-05-19 07:33:55 +0200101};
102
Marek Szyprowski0cbdf7b2009-05-19 07:33:55 +0200103#define LDO_VOL_MIN_IDX 0x00
104#define LDO_VOL_MAX_IDX 0x0f
105
Marek Szyprowski0cbdf7b2009-05-19 07:33:55 +0200106static int lp3971_ldo_is_enabled(struct regulator_dev *dev)
107{
108 struct lp3971 *lp3971 = rdev_get_drvdata(dev);
109 int ldo = rdev_get_id(dev) - LP3971_LDO1;
110 u16 mask = 1 << (1 + ldo);
111 u16 val;
112
113 val = lp3971_reg_read(lp3971, LP3971_LDO_ENABLE_REG);
114 return (val & mask) != 0;
115}
116
117static int lp3971_ldo_enable(struct regulator_dev *dev)
118{
119 struct lp3971 *lp3971 = rdev_get_drvdata(dev);
120 int ldo = rdev_get_id(dev) - LP3971_LDO1;
121 u16 mask = 1 << (1 + ldo);
122
123 return lp3971_set_bits(lp3971, LP3971_LDO_ENABLE_REG, mask, mask);
124}
125
126static int lp3971_ldo_disable(struct regulator_dev *dev)
127{
128 struct lp3971 *lp3971 = rdev_get_drvdata(dev);
129 int ldo = rdev_get_id(dev) - LP3971_LDO1;
130 u16 mask = 1 << (1 + ldo);
131
132 return lp3971_set_bits(lp3971, LP3971_LDO_ENABLE_REG, mask, 0);
133}
134
Axel Linf38482f2012-12-10 19:46:52 +0800135static int lp3971_ldo_get_voltage_sel(struct regulator_dev *dev)
Marek Szyprowski0cbdf7b2009-05-19 07:33:55 +0200136{
137 struct lp3971 *lp3971 = rdev_get_drvdata(dev);
138 int ldo = rdev_get_id(dev) - LP3971_LDO1;
139 u16 val, reg;
140
141 reg = lp3971_reg_read(lp3971, LP3971_LDO_VOL_CONTR_REG(ldo));
142 val = (reg >> LDO_VOL_CONTR_SHIFT(ldo)) & LDO_VOL_CONTR_MASK;
143
Axel Linf38482f2012-12-10 19:46:52 +0800144 return val;
Marek Szyprowski0cbdf7b2009-05-19 07:33:55 +0200145}
146
Axel Lindd8e2312012-03-23 10:49:54 +0800147static int lp3971_ldo_set_voltage_sel(struct regulator_dev *dev,
148 unsigned int selector)
Marek Szyprowski0cbdf7b2009-05-19 07:33:55 +0200149{
150 struct lp3971 *lp3971 = rdev_get_drvdata(dev);
151 int ldo = rdev_get_id(dev) - LP3971_LDO1;
Mark Brown3a93f2a2010-11-10 14:38:29 +0000152
Marek Szyprowski0cbdf7b2009-05-19 07:33:55 +0200153 return lp3971_set_bits(lp3971, LP3971_LDO_VOL_CONTR_REG(ldo),
Axel Lincdb868f2010-03-09 16:53:59 +0800154 LDO_VOL_CONTR_MASK << LDO_VOL_CONTR_SHIFT(ldo),
Axel Lindd8e2312012-03-23 10:49:54 +0800155 selector << LDO_VOL_CONTR_SHIFT(ldo));
Marek Szyprowski0cbdf7b2009-05-19 07:33:55 +0200156}
157
Axel Lin93b84ea2019-01-26 11:39:00 +0800158static const struct regulator_ops lp3971_ldo_ops = {
Axel Lincad8d762012-05-20 13:30:28 +0800159 .list_voltage = regulator_list_voltage_table,
Axel Lin3e655612013-04-21 00:35:31 +0800160 .map_voltage = regulator_map_voltage_ascend,
Marek Szyprowski0cbdf7b2009-05-19 07:33:55 +0200161 .is_enabled = lp3971_ldo_is_enabled,
162 .enable = lp3971_ldo_enable,
163 .disable = lp3971_ldo_disable,
Axel Linf38482f2012-12-10 19:46:52 +0800164 .get_voltage_sel = lp3971_ldo_get_voltage_sel,
Axel Lindd8e2312012-03-23 10:49:54 +0800165 .set_voltage_sel = lp3971_ldo_set_voltage_sel,
Marek Szyprowski0cbdf7b2009-05-19 07:33:55 +0200166};
167
Marek Szyprowski0cbdf7b2009-05-19 07:33:55 +0200168static int lp3971_dcdc_is_enabled(struct regulator_dev *dev)
169{
170 struct lp3971 *lp3971 = rdev_get_drvdata(dev);
171 int buck = rdev_get_id(dev) - LP3971_DCDC1;
172 u16 mask = 1 << (buck * 2);
173 u16 val;
174
175 val = lp3971_reg_read(lp3971, LP3971_BUCK_VOL_ENABLE_REG);
176 return (val & mask) != 0;
177}
178
179static int lp3971_dcdc_enable(struct regulator_dev *dev)
180{
181 struct lp3971 *lp3971 = rdev_get_drvdata(dev);
182 int buck = rdev_get_id(dev) - LP3971_DCDC1;
183 u16 mask = 1 << (buck * 2);
184
185 return lp3971_set_bits(lp3971, LP3971_BUCK_VOL_ENABLE_REG, mask, mask);
186}
187
188static int lp3971_dcdc_disable(struct regulator_dev *dev)
189{
190 struct lp3971 *lp3971 = rdev_get_drvdata(dev);
191 int buck = rdev_get_id(dev) - LP3971_DCDC1;
192 u16 mask = 1 << (buck * 2);
193
194 return lp3971_set_bits(lp3971, LP3971_BUCK_VOL_ENABLE_REG, mask, 0);
195}
196
Axel Linf38482f2012-12-10 19:46:52 +0800197static int lp3971_dcdc_get_voltage_sel(struct regulator_dev *dev)
Marek Szyprowski0cbdf7b2009-05-19 07:33:55 +0200198{
199 struct lp3971 *lp3971 = rdev_get_drvdata(dev);
200 int buck = rdev_get_id(dev) - LP3971_DCDC1;
201 u16 reg;
Marek Szyprowski0cbdf7b2009-05-19 07:33:55 +0200202
203 reg = lp3971_reg_read(lp3971, LP3971_BUCK_TARGET_VOL1_REG(buck));
204 reg &= BUCK_TARGET_VOL_MASK;
205
Axel Linf38482f2012-12-10 19:46:52 +0800206 return reg;
Marek Szyprowski0cbdf7b2009-05-19 07:33:55 +0200207}
208
Axel Lindd8e2312012-03-23 10:49:54 +0800209static int lp3971_dcdc_set_voltage_sel(struct regulator_dev *dev,
210 unsigned int selector)
Marek Szyprowski0cbdf7b2009-05-19 07:33:55 +0200211{
212 struct lp3971 *lp3971 = rdev_get_drvdata(dev);
213 int buck = rdev_get_id(dev) - LP3971_DCDC1;
Marek Szyprowski0cbdf7b2009-05-19 07:33:55 +0200214 int ret;
215
Marek Szyprowski0cbdf7b2009-05-19 07:33:55 +0200216 ret = lp3971_set_bits(lp3971, LP3971_BUCK_TARGET_VOL1_REG(buck),
Axel Lindd8e2312012-03-23 10:49:54 +0800217 BUCK_TARGET_VOL_MASK, selector);
Marek Szyprowski0cbdf7b2009-05-19 07:33:55 +0200218 if (ret)
219 return ret;
220
221 ret = lp3971_set_bits(lp3971, LP3971_BUCK_VOL_CHANGE_REG,
222 BUCK_VOL_CHANGE_FLAG_MASK << BUCK_VOL_CHANGE_SHIFT(buck),
223 BUCK_VOL_CHANGE_FLAG_GO << BUCK_VOL_CHANGE_SHIFT(buck));
224 if (ret)
225 return ret;
226
227 return lp3971_set_bits(lp3971, LP3971_BUCK_VOL_CHANGE_REG,
228 BUCK_VOL_CHANGE_FLAG_MASK << BUCK_VOL_CHANGE_SHIFT(buck),
229 0 << BUCK_VOL_CHANGE_SHIFT(buck));
230}
231
Axel Lin93b84ea2019-01-26 11:39:00 +0800232static const struct regulator_ops lp3971_dcdc_ops = {
Axel Lincad8d762012-05-20 13:30:28 +0800233 .list_voltage = regulator_list_voltage_table,
Axel Lin3e655612013-04-21 00:35:31 +0800234 .map_voltage = regulator_map_voltage_ascend,
Marek Szyprowski0cbdf7b2009-05-19 07:33:55 +0200235 .is_enabled = lp3971_dcdc_is_enabled,
236 .enable = lp3971_dcdc_enable,
237 .disable = lp3971_dcdc_disable,
Axel Linf38482f2012-12-10 19:46:52 +0800238 .get_voltage_sel = lp3971_dcdc_get_voltage_sel,
Axel Lindd8e2312012-03-23 10:49:54 +0800239 .set_voltage_sel = lp3971_dcdc_set_voltage_sel,
Marek Szyprowski0cbdf7b2009-05-19 07:33:55 +0200240};
241
Axel Lin14add4f2012-04-05 11:59:20 +0800242static const struct regulator_desc regulators[] = {
Marek Szyprowski0cbdf7b2009-05-19 07:33:55 +0200243 {
244 .name = "LDO1",
245 .id = LP3971_LDO1,
246 .ops = &lp3971_ldo_ops,
247 .n_voltages = ARRAY_SIZE(ldo123_voltage_map),
Axel Lincad8d762012-05-20 13:30:28 +0800248 .volt_table = ldo123_voltage_map,
Marek Szyprowski0cbdf7b2009-05-19 07:33:55 +0200249 .type = REGULATOR_VOLTAGE,
250 .owner = THIS_MODULE,
251 },
252 {
253 .name = "LDO2",
254 .id = LP3971_LDO2,
255 .ops = &lp3971_ldo_ops,
256 .n_voltages = ARRAY_SIZE(ldo123_voltage_map),
Axel Lincad8d762012-05-20 13:30:28 +0800257 .volt_table = ldo123_voltage_map,
Marek Szyprowski0cbdf7b2009-05-19 07:33:55 +0200258 .type = REGULATOR_VOLTAGE,
259 .owner = THIS_MODULE,
260 },
261 {
262 .name = "LDO3",
263 .id = LP3971_LDO3,
264 .ops = &lp3971_ldo_ops,
265 .n_voltages = ARRAY_SIZE(ldo123_voltage_map),
Axel Lincad8d762012-05-20 13:30:28 +0800266 .volt_table = ldo123_voltage_map,
Marek Szyprowski0cbdf7b2009-05-19 07:33:55 +0200267 .type = REGULATOR_VOLTAGE,
268 .owner = THIS_MODULE,
269 },
270 {
271 .name = "LDO4",
272 .id = LP3971_LDO4,
273 .ops = &lp3971_ldo_ops,
274 .n_voltages = ARRAY_SIZE(ldo45_voltage_map),
Axel Lincad8d762012-05-20 13:30:28 +0800275 .volt_table = ldo45_voltage_map,
Marek Szyprowski0cbdf7b2009-05-19 07:33:55 +0200276 .type = REGULATOR_VOLTAGE,
277 .owner = THIS_MODULE,
278 },
279 {
280 .name = "LDO5",
281 .id = LP3971_LDO5,
282 .ops = &lp3971_ldo_ops,
283 .n_voltages = ARRAY_SIZE(ldo45_voltage_map),
Axel Lincad8d762012-05-20 13:30:28 +0800284 .volt_table = ldo45_voltage_map,
Marek Szyprowski0cbdf7b2009-05-19 07:33:55 +0200285 .type = REGULATOR_VOLTAGE,
286 .owner = THIS_MODULE,
287 },
288 {
289 .name = "DCDC1",
290 .id = LP3971_DCDC1,
291 .ops = &lp3971_dcdc_ops,
292 .n_voltages = ARRAY_SIZE(buck_voltage_map),
Axel Lincad8d762012-05-20 13:30:28 +0800293 .volt_table = buck_voltage_map,
Marek Szyprowski0cbdf7b2009-05-19 07:33:55 +0200294 .type = REGULATOR_VOLTAGE,
295 .owner = THIS_MODULE,
296 },
297 {
298 .name = "DCDC2",
299 .id = LP3971_DCDC2,
300 .ops = &lp3971_dcdc_ops,
301 .n_voltages = ARRAY_SIZE(buck_voltage_map),
Axel Lincad8d762012-05-20 13:30:28 +0800302 .volt_table = buck_voltage_map,
Marek Szyprowski0cbdf7b2009-05-19 07:33:55 +0200303 .type = REGULATOR_VOLTAGE,
304 .owner = THIS_MODULE,
305 },
306 {
307 .name = "DCDC3",
308 .id = LP3971_DCDC3,
309 .ops = &lp3971_dcdc_ops,
310 .n_voltages = ARRAY_SIZE(buck_voltage_map),
Axel Lincad8d762012-05-20 13:30:28 +0800311 .volt_table = buck_voltage_map,
Marek Szyprowski0cbdf7b2009-05-19 07:33:55 +0200312 .type = REGULATOR_VOLTAGE,
313 .owner = THIS_MODULE,
314 },
315};
316
317static int lp3971_i2c_read(struct i2c_client *i2c, char reg, int count,
318 u16 *dest)
319{
320 int ret;
321
322 if (count != 1)
323 return -EIO;
324 ret = i2c_smbus_read_byte_data(i2c, reg);
Axel Lin27ef7f02010-08-06 08:09:14 +0800325 if (ret < 0)
Sachin Kamata1985d42014-02-18 16:11:03 +0530326 return ret;
Marek Szyprowski0cbdf7b2009-05-19 07:33:55 +0200327
328 *dest = ret;
329 return 0;
330}
331
332static int lp3971_i2c_write(struct i2c_client *i2c, char reg, int count,
333 const u16 *src)
334{
Marek Szyprowski0cbdf7b2009-05-19 07:33:55 +0200335 if (count != 1)
336 return -EIO;
Axel Lin1bddc2f2010-08-09 17:01:21 +0800337 return i2c_smbus_write_byte_data(i2c, reg, *src);
Marek Szyprowski0cbdf7b2009-05-19 07:33:55 +0200338}
339
340static u8 lp3971_reg_read(struct lp3971 *lp3971, u8 reg)
341{
342 u16 val = 0;
343
344 mutex_lock(&lp3971->io_lock);
345
346 lp3971_i2c_read(lp3971->i2c, reg, 1, &val);
347
348 dev_dbg(lp3971->dev, "reg read 0x%02x -> 0x%02x\n", (int)reg,
349 (unsigned)val&0xff);
350
351 mutex_unlock(&lp3971->io_lock);
352
353 return val & 0xff;
354}
355
356static int lp3971_set_bits(struct lp3971 *lp3971, u8 reg, u16 mask, u16 val)
357{
358 u16 tmp;
359 int ret;
360
361 mutex_lock(&lp3971->io_lock);
362
363 ret = lp3971_i2c_read(lp3971->i2c, reg, 1, &tmp);
Marek Szyprowski0cbdf7b2009-05-19 07:33:55 +0200364 if (ret == 0) {
Dan Carpenter40e1d792016-04-14 12:34:41 +0300365 tmp = (tmp & ~mask) | val;
Marek Szyprowski0cbdf7b2009-05-19 07:33:55 +0200366 ret = lp3971_i2c_write(lp3971->i2c, reg, 1, &tmp);
367 dev_dbg(lp3971->dev, "reg write 0x%02x -> 0x%02x\n", (int)reg,
368 (unsigned)val&0xff);
369 }
370 mutex_unlock(&lp3971->io_lock);
371
372 return ret;
373}
374
Bill Pembertona5023572012-11-19 13:22:22 -0500375static int setup_regulators(struct lp3971 *lp3971,
Dmitry Torokhovebbed042010-02-23 23:38:17 -0800376 struct lp3971_platform_data *pdata)
Marek Szyprowski0cbdf7b2009-05-19 07:33:55 +0200377{
378 int i, err;
Dmitry Torokhovebbed042010-02-23 23:38:17 -0800379
Marek Szyprowski0cbdf7b2009-05-19 07:33:55 +0200380 /* Instantiate the regulators */
Dmitry Torokhovebbed042010-02-23 23:38:17 -0800381 for (i = 0; i < pdata->num_regulators; i++) {
Mark Brownc172708d2012-04-04 00:50:22 +0100382 struct regulator_config config = { };
Dmitry Torokhovebbed042010-02-23 23:38:17 -0800383 struct lp3971_regulator_subdev *reg = &pdata->regulators[i];
Axel Lin56dde802013-11-13 14:52:26 +0800384 struct regulator_dev *rdev;
Marek Szyprowski0cbdf7b2009-05-19 07:33:55 +0200385
Mark Brownc172708d2012-04-04 00:50:22 +0100386 config.dev = lp3971->dev;
387 config.init_data = reg->initdata;
388 config.driver_data = lp3971;
389
Axel Lin56dde802013-11-13 14:52:26 +0800390 rdev = devm_regulator_register(lp3971->dev,
391 &regulators[reg->id], &config);
392 if (IS_ERR(rdev)) {
393 err = PTR_ERR(rdev);
Marek Szyprowski0cbdf7b2009-05-19 07:33:55 +0200394 dev_err(lp3971->dev, "regulator init failed: %d\n",
395 err);
Axel Lin56dde802013-11-13 14:52:26 +0800396 return err;
Marek Szyprowski0cbdf7b2009-05-19 07:33:55 +0200397 }
398 }
399
400 return 0;
Marek Szyprowski0cbdf7b2009-05-19 07:33:55 +0200401}
402
Axel Lin77e29592020-01-09 23:58:08 +0800403static int lp3971_i2c_probe(struct i2c_client *i2c)
Marek Szyprowski0cbdf7b2009-05-19 07:33:55 +0200404{
405 struct lp3971 *lp3971;
Jingoo Handff91d02013-07-30 17:20:47 +0900406 struct lp3971_platform_data *pdata = dev_get_platdata(&i2c->dev);
Marek Szyprowski0cbdf7b2009-05-19 07:33:55 +0200407 int ret;
408 u16 val;
409
Dmitry Torokhovebbed042010-02-23 23:38:17 -0800410 if (!pdata) {
411 dev_dbg(&i2c->dev, "No platform init data supplied\n");
412 return -ENODEV;
Marek Szyprowski0cbdf7b2009-05-19 07:33:55 +0200413 }
414
Nikolay Balandin2af0af62013-05-25 14:50:40 -0700415 lp3971 = devm_kzalloc(&i2c->dev, sizeof(struct lp3971), GFP_KERNEL);
Dmitry Torokhovebbed042010-02-23 23:38:17 -0800416 if (lp3971 == NULL)
417 return -ENOMEM;
418
Marek Szyprowski0cbdf7b2009-05-19 07:33:55 +0200419 lp3971->i2c = i2c;
420 lp3971->dev = &i2c->dev;
Marek Szyprowski0cbdf7b2009-05-19 07:33:55 +0200421
422 mutex_init(&lp3971->io_lock);
423
424 /* Detect LP3971 */
425 ret = lp3971_i2c_read(i2c, LP3971_SYS_CONTROL1_REG, 1, &val);
426 if (ret == 0 && (val & SYS_CONTROL1_INIT_MASK) != SYS_CONTROL1_INIT_VAL)
427 ret = -ENODEV;
428 if (ret < 0) {
429 dev_err(&i2c->dev, "failed to detect device\n");
Nikolay Balandin2af0af62013-05-25 14:50:40 -0700430 return ret;
Marek Szyprowski0cbdf7b2009-05-19 07:33:55 +0200431 }
432
Dmitry Torokhovebbed042010-02-23 23:38:17 -0800433 ret = setup_regulators(lp3971, pdata);
434 if (ret < 0)
Nikolay Balandin2af0af62013-05-25 14:50:40 -0700435 return ret;
Marek Szyprowski0cbdf7b2009-05-19 07:33:55 +0200436
Dmitry Torokhovebbed042010-02-23 23:38:17 -0800437 i2c_set_clientdata(i2c, lp3971);
Marek Szyprowski0cbdf7b2009-05-19 07:33:55 +0200438 return 0;
Marek Szyprowski0cbdf7b2009-05-19 07:33:55 +0200439}
440
Marek Szyprowski0cbdf7b2009-05-19 07:33:55 +0200441static const struct i2c_device_id lp3971_i2c_id[] = {
Jingoo Han0a3ee932013-10-14 17:47:31 +0900442 { "lp3971", 0 },
443 { }
Marek Szyprowski0cbdf7b2009-05-19 07:33:55 +0200444};
445MODULE_DEVICE_TABLE(i2c, lp3971_i2c_id);
446
447static struct i2c_driver lp3971_i2c_driver = {
448 .driver = {
449 .name = "LP3971",
Marek Szyprowski0cbdf7b2009-05-19 07:33:55 +0200450 },
Axel Lin77e29592020-01-09 23:58:08 +0800451 .probe_new = lp3971_i2c_probe,
Marek Szyprowski0cbdf7b2009-05-19 07:33:55 +0200452 .id_table = lp3971_i2c_id,
453};
454
Mark Brown5af34e62012-04-03 23:33:10 +0100455module_i2c_driver(lp3971_i2c_driver);
Marek Szyprowski0cbdf7b2009-05-19 07:33:55 +0200456
457MODULE_LICENSE("GPL");
458MODULE_AUTHOR("Marek Szyprowski <m.szyprowski@samsung.com>");
459MODULE_DESCRIPTION("LP3971 PMIC driver");