Linux Audio

Check our new training course

Loading...
v6.13.7
  1// SPDX-License-Identifier: GPL-2.0-or-later
  2/*
  3 * isl9305 - Intersil ISL9305 DCDC regulator
  4 *
  5 * Copyright 2014 Linaro Ltd
  6 *
  7 * Author: Mark Brown <broonie@kernel.org>
 
 
 
 
 
  8 */
  9
 10#include <linux/module.h>
 11#include <linux/err.h>
 12#include <linux/i2c.h>
 13#include <linux/of.h>
 14#include <linux/platform_data/isl9305.h>
 15#include <linux/regmap.h>
 16#include <linux/regulator/driver.h>
 17#include <linux/regulator/of_regulator.h>
 18#include <linux/slab.h>
 19
 20/*
 21 * Registers
 22 */
 23#define ISL9305_DCD1OUT          0x0
 24#define ISL9305_DCD2OUT          0x1
 25#define ISL9305_LDO1OUT          0x2
 26#define ISL9305_LDO2OUT          0x3
 27#define ISL9305_DCD_PARAMETER    0x4
 28#define ISL9305_SYSTEM_PARAMETER 0x5
 29#define ISL9305_DCD_SRCTL        0x6
 30
 31#define ISL9305_MAX_REG ISL9305_DCD_SRCTL
 32
 33/*
 34 * DCD_PARAMETER
 35 */
 36#define ISL9305_DCD_PHASE   0x40
 37#define ISL9305_DCD2_ULTRA  0x20
 38#define ISL9305_DCD1_ULTRA  0x10
 39#define ISL9305_DCD2_BLD    0x08
 40#define ISL9305_DCD1_BLD    0x04
 41#define ISL9305_DCD2_MODE   0x02
 42#define ISL9305_DCD1_MODE   0x01
 43
 44/*
 45 * SYSTEM_PARAMETER
 46 */
 47#define ISL9305_I2C_EN      0x40
 48#define ISL9305_DCDPOR_MASK 0x30
 49#define ISL9305_LDO2_EN     0x08
 50#define ISL9305_LDO1_EN     0x04
 51#define ISL9305_DCD2_EN     0x02
 52#define ISL9305_DCD1_EN     0x01
 53
 54/*
 55 * DCD_SRCTL
 56 */
 57#define ISL9305_DCD2SR_MASK 0xc0
 58#define ISL9305_DCD1SR_MASK 0x07
 59
 60static const struct regulator_ops isl9305_ops = {
 61	.enable = regulator_enable_regmap,
 62	.disable = regulator_disable_regmap,
 63	.is_enabled = regulator_is_enabled_regmap,
 64	.list_voltage = regulator_list_voltage_linear,
 65	.get_voltage_sel = regulator_get_voltage_sel_regmap,
 66	.set_voltage_sel = regulator_set_voltage_sel_regmap,
 67};
 68
 69static const struct regulator_desc isl9305_regulators[] = {
 70	[ISL9305_DCD1] = {
 71		.name =		"DCD1",
 72		.of_match =	of_match_ptr("dcd1"),
 73		.regulators_node = of_match_ptr("regulators"),
 74		.n_voltages =	0x70,
 75		.min_uV =	825000,
 76		.uV_step =	25000,
 77		.vsel_reg =	ISL9305_DCD1OUT,
 78		.vsel_mask =	0x7f,
 79		.enable_reg =	ISL9305_SYSTEM_PARAMETER,
 80		.enable_mask =	ISL9305_DCD1_EN,
 81		.supply_name =	"VINDCD1",
 82		.ops =		&isl9305_ops,
 83		.owner =	THIS_MODULE,
 84	},
 85	[ISL9305_DCD2] = {
 86		.name =		"DCD2",
 87		.of_match =	of_match_ptr("dcd2"),
 88		.regulators_node = of_match_ptr("regulators"),
 89		.n_voltages =	0x70,
 90		.min_uV =	825000,
 91		.uV_step =	25000,
 92		.vsel_reg =	ISL9305_DCD2OUT,
 93		.vsel_mask =	0x7f,
 94		.enable_reg =	ISL9305_SYSTEM_PARAMETER,
 95		.enable_mask =	ISL9305_DCD2_EN,
 96		.supply_name =	"VINDCD2",
 97		.ops =		&isl9305_ops,
 98		.owner =	THIS_MODULE,
 99	},
100	[ISL9305_LDO1] = {
101		.name =		"LDO1",
102		.of_match =	of_match_ptr("ldo1"),
103		.regulators_node = of_match_ptr("regulators"),
104		.n_voltages =	0x37,
105		.min_uV =	900000,
106		.uV_step =	50000,
107		.vsel_reg =	ISL9305_LDO1OUT,
108		.vsel_mask =	0x3f,
109		.enable_reg =	ISL9305_SYSTEM_PARAMETER,
110		.enable_mask =	ISL9305_LDO1_EN,
111		.supply_name =	"VINLDO1",
112		.ops =		&isl9305_ops,
113		.owner =	THIS_MODULE,
114	},
115	[ISL9305_LDO2] = {
116		.name =		"LDO2",
117		.of_match =	of_match_ptr("ldo2"),
118		.regulators_node = of_match_ptr("regulators"),
119		.n_voltages =	0x37,
120		.min_uV =	900000,
121		.uV_step =	50000,
122		.vsel_reg =	ISL9305_LDO2OUT,
123		.vsel_mask =	0x3f,
124		.enable_reg =	ISL9305_SYSTEM_PARAMETER,
125		.enable_mask =	ISL9305_LDO2_EN,
126		.supply_name =	"VINLDO2",
127		.ops =		&isl9305_ops,
128		.owner =	THIS_MODULE,
129	},
130};
131
132static const struct regmap_config isl9305_regmap = {
133	.reg_bits = 8,
134	.val_bits = 8,
135
136	.max_register = ISL9305_MAX_REG,
137	.cache_type = REGCACHE_MAPLE,
138};
139
140static int isl9305_i2c_probe(struct i2c_client *i2c)
 
141{
142	struct regulator_config config = { };
143	struct isl9305_pdata *pdata = i2c->dev.platform_data;
144	struct regulator_dev *rdev;
145	struct regmap *regmap;
146	int i, ret;
147
148	regmap = devm_regmap_init_i2c(i2c, &isl9305_regmap);
149	if (IS_ERR(regmap)) {
150		ret = PTR_ERR(regmap);
151		dev_err(&i2c->dev, "Failed to create regmap: %d\n", ret);
152		return ret;
153	}
154
155	config.dev = &i2c->dev;
156
157	for (i = 0; i < ARRAY_SIZE(isl9305_regulators); i++) {
158		if (pdata)
159			config.init_data = pdata->init_data[i];
160		else
161			config.init_data = NULL;
162
163		rdev = devm_regulator_register(&i2c->dev,
164					       &isl9305_regulators[i],
165					       &config);
166		if (IS_ERR(rdev)) {
167			ret = PTR_ERR(rdev);
168			dev_err(&i2c->dev, "Failed to register %s: %d\n",
169				isl9305_regulators[i].name, ret);
170			return ret;
171		}
172	}
173
174	return 0;
175}
176
177#ifdef CONFIG_OF
178static const struct of_device_id isl9305_dt_ids[] = {
179	{ .compatible = "isl,isl9305" }, /* for backward compat., don't use */
180	{ .compatible = "isil,isl9305" },
181	{ .compatible = "isl,isl9305h" }, /* for backward compat., don't use */
182	{ .compatible = "isil,isl9305h" },
183	{},
184};
185MODULE_DEVICE_TABLE(of, isl9305_dt_ids);
186#endif
187
188static const struct i2c_device_id isl9305_i2c_id[] = {
189	{ "isl9305", },
190	{ "isl9305h", },
191	{ }
192};
193MODULE_DEVICE_TABLE(i2c, isl9305_i2c_id);
194
195static struct i2c_driver isl9305_regulator_driver = {
196	.driver = {
197		.name = "isl9305",
198		.probe_type = PROBE_PREFER_ASYNCHRONOUS,
199		.of_match_table	= of_match_ptr(isl9305_dt_ids),
200	},
201	.probe = isl9305_i2c_probe,
202	.id_table = isl9305_i2c_id,
203};
204
205module_i2c_driver(isl9305_regulator_driver);
206
207MODULE_AUTHOR("Mark Brown");
208MODULE_DESCRIPTION("Intersil ISL9305 DCDC regulator");
209MODULE_LICENSE("GPL");
v4.10.11
 
  1/*
  2 * isl9305 - Intersil ISL9305 DCDC regulator
  3 *
  4 * Copyright 2014 Linaro Ltd
  5 *
  6 * Author: Mark Brown <broonie@kernel.org>
  7 *
  8 *  This program is free software; you can redistribute  it and/or modify it
  9 *  under  the terms of  the GNU General  Public License as published by the
 10 *  Free Software Foundation;  either version 2 of the  License, or (at your
 11 *  option) any later version.
 12 */
 13
 14#include <linux/module.h>
 15#include <linux/err.h>
 16#include <linux/i2c.h>
 17#include <linux/of.h>
 18#include <linux/platform_data/isl9305.h>
 19#include <linux/regmap.h>
 20#include <linux/regulator/driver.h>
 21#include <linux/regulator/of_regulator.h>
 22#include <linux/slab.h>
 23
 24/*
 25 * Registers
 26 */
 27#define ISL9305_DCD1OUT          0x0
 28#define ISL9305_DCD2OUT          0x1
 29#define ISL9305_LDO1OUT          0x2
 30#define ISL9305_LDO2OUT          0x3
 31#define ISL9305_DCD_PARAMETER    0x4
 32#define ISL9305_SYSTEM_PARAMETER 0x5
 33#define ISL9305_DCD_SRCTL        0x6
 34
 35#define ISL9305_MAX_REG ISL9305_DCD_SRCTL
 36
 37/*
 38 * DCD_PARAMETER
 39 */
 40#define ISL9305_DCD_PHASE   0x40
 41#define ISL9305_DCD2_ULTRA  0x20
 42#define ISL9305_DCD1_ULTRA  0x10
 43#define ISL9305_DCD2_BLD    0x08
 44#define ISL9305_DCD1_BLD    0x04
 45#define ISL9305_DCD2_MODE   0x02
 46#define ISL9305_DCD1_MODE   0x01
 47
 48/*
 49 * SYSTEM_PARAMETER
 50 */
 51#define ISL9305_I2C_EN      0x40
 52#define ISL9305_DCDPOR_MASK 0x30
 53#define ISL9305_LDO2_EN     0x08
 54#define ISL9305_LDO1_EN     0x04
 55#define ISL9305_DCD2_EN     0x02
 56#define ISL9305_DCD1_EN     0x01
 57
 58/*
 59 * DCD_SRCTL
 60 */
 61#define ISL9305_DCD2SR_MASK 0xc0
 62#define ISL9305_DCD1SR_MASK 0x07
 63
 64static const struct regulator_ops isl9305_ops = {
 65	.enable = regulator_enable_regmap,
 66	.disable = regulator_disable_regmap,
 67	.is_enabled = regulator_is_enabled_regmap,
 68	.list_voltage = regulator_list_voltage_linear,
 69	.get_voltage_sel = regulator_get_voltage_sel_regmap,
 70	.set_voltage_sel = regulator_set_voltage_sel_regmap,
 71};
 72
 73static const struct regulator_desc isl9305_regulators[] = {
 74	[ISL9305_DCD1] = {
 75		.name =		"DCD1",
 76		.of_match =	of_match_ptr("dcd1"),
 77		.regulators_node = of_match_ptr("regulators"),
 78		.n_voltages =	0x70,
 79		.min_uV =	825000,
 80		.uV_step =	25000,
 81		.vsel_reg =	ISL9305_DCD1OUT,
 82		.vsel_mask =	0x7f,
 83		.enable_reg =	ISL9305_SYSTEM_PARAMETER,
 84		.enable_mask =	ISL9305_DCD1_EN,
 85		.supply_name =	"VINDCD1",
 86		.ops =		&isl9305_ops,
 
 87	},
 88	[ISL9305_DCD2] = {
 89		.name =		"DCD2",
 90		.of_match =	of_match_ptr("dcd2"),
 91		.regulators_node = of_match_ptr("regulators"),
 92		.n_voltages =	0x70,
 93		.min_uV =	825000,
 94		.uV_step =	25000,
 95		.vsel_reg =	ISL9305_DCD2OUT,
 96		.vsel_mask =	0x7f,
 97		.enable_reg =	ISL9305_SYSTEM_PARAMETER,
 98		.enable_mask =	ISL9305_DCD2_EN,
 99		.supply_name =	"VINDCD2",
100		.ops =		&isl9305_ops,
 
101	},
102	[ISL9305_LDO1] = {
103		.name =		"LDO1",
104		.of_match =	of_match_ptr("ldo1"),
105		.regulators_node = of_match_ptr("regulators"),
106		.n_voltages =	0x37,
107		.min_uV =	900000,
108		.uV_step =	50000,
109		.vsel_reg =	ISL9305_LDO1OUT,
110		.vsel_mask =	0x3f,
111		.enable_reg =	ISL9305_SYSTEM_PARAMETER,
112		.enable_mask =	ISL9305_LDO1_EN,
113		.supply_name =	"VINLDO1",
114		.ops =		&isl9305_ops,
 
115	},
116	[ISL9305_LDO2] = {
117		.name =		"LDO2",
118		.of_match =	of_match_ptr("ldo2"),
119		.regulators_node = of_match_ptr("regulators"),
120		.n_voltages =	0x37,
121		.min_uV =	900000,
122		.uV_step =	50000,
123		.vsel_reg =	ISL9305_LDO2OUT,
124		.vsel_mask =	0x3f,
125		.enable_reg =	ISL9305_SYSTEM_PARAMETER,
126		.enable_mask =	ISL9305_LDO2_EN,
127		.supply_name =	"VINLDO2",
128		.ops =		&isl9305_ops,
 
129	},
130};
131
132static const struct regmap_config isl9305_regmap = {
133	.reg_bits = 8,
134	.val_bits = 8,
135
136	.max_register = ISL9305_MAX_REG,
137	.cache_type = REGCACHE_RBTREE,
138};
139
140static int isl9305_i2c_probe(struct i2c_client *i2c,
141			     const struct i2c_device_id *id)
142{
143	struct regulator_config config = { };
144	struct isl9305_pdata *pdata = i2c->dev.platform_data;
145	struct regulator_dev *rdev;
146	struct regmap *regmap;
147	int i, ret;
148
149	regmap = devm_regmap_init_i2c(i2c, &isl9305_regmap);
150	if (IS_ERR(regmap)) {
151		ret = PTR_ERR(regmap);
152		dev_err(&i2c->dev, "Failed to create regmap: %d\n", ret);
153		return ret;
154	}
155
156	config.dev = &i2c->dev;
157
158	for (i = 0; i < ARRAY_SIZE(isl9305_regulators); i++) {
159		if (pdata)
160			config.init_data = pdata->init_data[i];
161		else
162			config.init_data = NULL;
163
164		rdev = devm_regulator_register(&i2c->dev,
165					       &isl9305_regulators[i],
166					       &config);
167		if (IS_ERR(rdev)) {
168			ret = PTR_ERR(rdev);
169			dev_err(&i2c->dev, "Failed to register %s: %d\n",
170				isl9305_regulators[i].name, ret);
171			return ret;
172		}
173	}
174
175	return 0;
176}
177
178#ifdef CONFIG_OF
179static const struct of_device_id isl9305_dt_ids[] = {
180	{ .compatible = "isl,isl9305" }, /* for backward compat., don't use */
181	{ .compatible = "isil,isl9305" },
182	{ .compatible = "isl,isl9305h" }, /* for backward compat., don't use */
183	{ .compatible = "isil,isl9305h" },
184	{},
185};
186MODULE_DEVICE_TABLE(of, isl9305_dt_ids);
187#endif
188
189static const struct i2c_device_id isl9305_i2c_id[] = {
190	{ "isl9305", },
191	{ "isl9305h", },
192	{ }
193};
194MODULE_DEVICE_TABLE(i2c, isl9305_i2c_id);
195
196static struct i2c_driver isl9305_regulator_driver = {
197	.driver = {
198		.name = "isl9305",
 
199		.of_match_table	= of_match_ptr(isl9305_dt_ids),
200	},
201	.probe = isl9305_i2c_probe,
202	.id_table = isl9305_i2c_id,
203};
204
205module_i2c_driver(isl9305_regulator_driver);
206
207MODULE_AUTHOR("Mark Brown");
208MODULE_DESCRIPTION("Intersil ISL9305 DCDC regulator");
209MODULE_LICENSE("GPL");