da9211-regulator.c (10a558374f3751cf4eb55143008975641dfc2cf4) da9211-regulator.c (11da04af0d3b4c24ab057dd17f54dbc854d735de)
1/*
2 * da9211-regulator.c - Regulator device driver for DA9211/DA9212
3 * /DA9213/DA9223/DA9214/DA9224/DA9215/DA9225
4 * Copyright (C) 2015 Dialog Semiconductor Ltd.
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Library General Public License for more details.
15 */
16
17#include <linux/err.h>
1/*
2 * da9211-regulator.c - Regulator device driver for DA9211/DA9212
3 * /DA9213/DA9223/DA9214/DA9224/DA9215/DA9225
4 * Copyright (C) 2015 Dialog Semiconductor Ltd.
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Library General Public License for more details.
15 */
16
17#include <linux/err.h>
18#include <linux/gpio.h>
19#include <linux/i2c.h>
20#include <linux/module.h>
21#include <linux/init.h>
22#include <linux/slab.h>
23#include <linux/regulator/driver.h>
24#include <linux/regulator/machine.h>
25#include <linux/regmap.h>
26#include <linux/irq.h>
27#include <linux/interrupt.h>
18#include <linux/i2c.h>
19#include <linux/module.h>
20#include <linux/init.h>
21#include <linux/slab.h>
22#include <linux/regulator/driver.h>
23#include <linux/regulator/machine.h>
24#include <linux/regmap.h>
25#include <linux/irq.h>
26#include <linux/interrupt.h>
28#include <linux/of_gpio.h>
27#include <linux/gpio/consumer.h>
29#include <linux/regulator/of_regulator.h>
30#include <linux/regulator/da9211.h>
31#include "da9211-regulator.h"
32
33/* DEVICE IDs */
34#define DA9211_DEVICE_ID 0x22
35#define DA9213_DEVICE_ID 0x23
36#define DA9215_DEVICE_ID 0x24

--- 252 unchanged lines hidden (view full) ---

289
290 n = 0;
291 for (i = 0; i < ARRAY_SIZE(da9211_matches); i++) {
292 if (!da9211_matches[i].init_data)
293 continue;
294
295 pdata->init_data[n] = da9211_matches[i].init_data;
296 pdata->reg_node[n] = da9211_matches[i].of_node;
28#include <linux/regulator/of_regulator.h>
29#include <linux/regulator/da9211.h>
30#include "da9211-regulator.h"
31
32/* DEVICE IDs */
33#define DA9211_DEVICE_ID 0x22
34#define DA9213_DEVICE_ID 0x23
35#define DA9215_DEVICE_ID 0x24

--- 252 unchanged lines hidden (view full) ---

288
289 n = 0;
290 for (i = 0; i < ARRAY_SIZE(da9211_matches); i++) {
291 if (!da9211_matches[i].init_data)
292 continue;
293
294 pdata->init_data[n] = da9211_matches[i].init_data;
295 pdata->reg_node[n] = da9211_matches[i].of_node;
297 pdata->gpio_ren[n] =
298 of_get_named_gpio(da9211_matches[i].of_node,
299 "enable-gpios", 0);
296 pdata->gpiod_ren[n] = devm_gpiod_get_from_of_node(dev,
297 da9211_matches[i].of_node,
298 "enable",
299 0,
300 GPIOD_OUT_HIGH,
301 "da9211-enable");
300 n++;
301 }
302
303 return pdata;
304}
305#else
306static struct da9211_pdata *da9211_parse_regulators_dt(
307 struct device *dev)

--- 69 unchanged lines hidden (view full) ---

377
378 for (i = 0; i < chip->num_regulator; i++) {
379 config.init_data = chip->pdata->init_data[i];
380 config.dev = chip->dev;
381 config.driver_data = chip;
382 config.regmap = chip->regmap;
383 config.of_node = chip->pdata->reg_node[i];
384
302 n++;
303 }
304
305 return pdata;
306}
307#else
308static struct da9211_pdata *da9211_parse_regulators_dt(
309 struct device *dev)

--- 69 unchanged lines hidden (view full) ---

379
380 for (i = 0; i < chip->num_regulator; i++) {
381 config.init_data = chip->pdata->init_data[i];
382 config.dev = chip->dev;
383 config.driver_data = chip;
384 config.regmap = chip->regmap;
385 config.of_node = chip->pdata->reg_node[i];
386
385 if (gpio_is_valid(chip->pdata->gpio_ren[i])) {
386 config.ena_gpio = chip->pdata->gpio_ren[i];
387 config.ena_gpio_initialized = true;
388 } else {
389 config.ena_gpio = -EINVAL;
390 config.ena_gpio_initialized = false;
391 }
387 if (chip->pdata->gpiod_ren[i])
388 config.ena_gpiod = chip->pdata->gpiod_ren[i];
389 else
390 config.ena_gpiod = NULL;
392
393 chip->rdev[i] = devm_regulator_register(chip->dev,
394 &da9211_regulators[i], &config);
395 if (IS_ERR(chip->rdev[i])) {
396 dev_err(chip->dev,
397 "Failed to register DA9211 regulator\n");
398 return PTR_ERR(chip->rdev[i]);
399 }

--- 137 unchanged lines hidden ---
391
392 chip->rdev[i] = devm_regulator_register(chip->dev,
393 &da9211_regulators[i], &config);
394 if (IS_ERR(chip->rdev[i])) {
395 dev_err(chip->dev,
396 "Failed to register DA9211 regulator\n");
397 return PTR_ERR(chip->rdev[i]);
398 }

--- 137 unchanged lines hidden ---