aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/regulator/arizona-micsupp.c
diff options
context:
space:
mode:
authorMark Brown <broonie@opensource.wolfsonmicro.com>2012-06-14 13:14:00 -0400
committerMark Brown <broonie@opensource.wolfsonmicro.com>2012-06-20 06:46:19 -0400
commitb667a45d9f8ed98d4da2bbbd1c9083aade0f3237 (patch)
treee375aef63f1b402f4edc1853fcd6a30a4588a694 /drivers/regulator/arizona-micsupp.c
parentbaf73e2c4e25aa57a7bd5df90a93e65be0542c74 (diff)
regulator: arizona: Add support for microphone supplies on Arizona devices
The Wolfson Arizona platform is used for a range of low power audio hub CODECs. Many of these devices feature an integrated power supply for the microphone which is supported by this driver. Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
Diffstat (limited to 'drivers/regulator/arizona-micsupp.c')
-rw-r--r--drivers/regulator/arizona-micsupp.c184
1 files changed, 184 insertions, 0 deletions
diff --git a/drivers/regulator/arizona-micsupp.c b/drivers/regulator/arizona-micsupp.c
new file mode 100644
index 000000000000..97d85b09a940
--- /dev/null
+++ b/drivers/regulator/arizona-micsupp.c
@@ -0,0 +1,184 @@
1/*
2 * arizona-micsupp.c -- Microphone supply for Arizona devices
3 *
4 * Copyright 2012 Wolfson Microelectronics PLC.
5 *
6 * Author: Mark Brown <broonie@opensource.wolfsonmicro.com>
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/moduleparam.h>
16#include <linux/init.h>
17#include <linux/bitops.h>
18#include <linux/err.h>
19#include <linux/platform_device.h>
20#include <linux/regulator/driver.h>
21#include <linux/regulator/machine.h>
22#include <linux/gpio.h>
23#include <linux/slab.h>
24
25#include <linux/mfd/arizona/core.h>
26#include <linux/mfd/arizona/pdata.h>
27#include <linux/mfd/arizona/registers.h>
28
29#define ARIZONA_MICSUPP_MAX_SELECTOR 0x1f
30
31struct arizona_micsupp {
32 struct regulator_dev *regulator;
33 struct arizona *arizona;
34
35 struct regulator_consumer_supply supply;
36 struct regulator_init_data init_data;
37};
38
39static int arizona_micsupp_list_voltage(struct regulator_dev *rdev,
40 unsigned int selector)
41{
42 if (selector > ARIZONA_MICSUPP_MAX_SELECTOR)
43 return -EINVAL;
44
45 if (selector == ARIZONA_MICSUPP_MAX_SELECTOR)
46 return 3300000;
47 else
48 return (selector * 50000) + 1700000;
49}
50
51static int arizona_micsupp_map_voltage(struct regulator_dev *rdev,
52 int min_uV, int max_uV)
53{
54 unsigned int voltage;
55 int selector;
56
57 if (min_uV < 1700000)
58 min_uV = 1700000;
59
60 if (min_uV >= 3300000)
61 selector = ARIZONA_MICSUPP_MAX_SELECTOR;
62 else
63 selector = DIV_ROUND_UP(min_uV - 1700000, 50000);
64
65 if (selector < 0)
66 return -EINVAL;
67
68 voltage = arizona_micsupp_list_voltage(rdev, selector);
69 if (voltage < min_uV || voltage > max_uV)
70 return -EINVAL;
71
72 return selector;
73}
74
75static struct regulator_ops arizona_micsupp_ops = {
76 .enable = regulator_enable_regmap,
77 .disable = regulator_disable_regmap,
78 .is_enabled = regulator_is_enabled_regmap,
79
80 .list_voltage = arizona_micsupp_list_voltage,
81 .map_voltage = arizona_micsupp_map_voltage,
82
83 .get_voltage_sel = regulator_get_voltage_sel_regmap,
84 .set_voltage_sel = regulator_set_voltage_sel_regmap,
85};
86
87static const struct regulator_desc arizona_micsupp = {
88 .name = "MICVDD",
89 .supply_name = "CPVDD",
90 .type = REGULATOR_VOLTAGE,
91 .n_voltages = ARIZONA_MICSUPP_MAX_SELECTOR + 1,
92 .ops = &arizona_micsupp_ops,
93
94 .vsel_reg = ARIZONA_LDO2_CONTROL_1,
95 .vsel_mask = ARIZONA_LDO2_VSEL_MASK,
96 .enable_reg = ARIZONA_MIC_CHARGE_PUMP_1,
97 .enable_mask = ARIZONA_CPMIC_ENA,
98
99 .owner = THIS_MODULE,
100};
101
102static const struct regulator_init_data arizona_micsupp_default = {
103 .constraints = {
104 .valid_ops_mask = REGULATOR_CHANGE_STATUS |
105 REGULATOR_CHANGE_VOLTAGE,
106 .min_uV = 1700000,
107 .max_uV = 3300000,
108 },
109
110 .num_consumer_supplies = 1,
111};
112
113static __devinit int arizona_micsupp_probe(struct platform_device *pdev)
114{
115 struct arizona *arizona = dev_get_drvdata(pdev->dev.parent);
116 struct regulator_config config = { };
117 struct arizona_micsupp *micsupp;
118 int ret;
119
120 micsupp = devm_kzalloc(&pdev->dev, sizeof(*micsupp), GFP_KERNEL);
121 if (micsupp == NULL) {
122 dev_err(&pdev->dev, "Unable to allocate private data\n");
123 return -ENOMEM;
124 }
125
126 micsupp->arizona = arizona;
127
128 /*
129 * Since the chip usually supplies itself we provide some
130 * default init_data for it. This will be overridden with
131 * platform data if provided.
132 */
133 micsupp->init_data = arizona_micsupp_default;
134 micsupp->init_data.consumer_supplies = &micsupp->supply;
135 micsupp->supply.supply = "MICVDD";
136 micsupp->supply.dev_name = dev_name(arizona->dev);
137
138 config.dev = arizona->dev;
139 config.driver_data = micsupp;
140 config.regmap = arizona->regmap;
141
142 if (arizona->pdata.micvdd)
143 config.init_data = arizona->pdata.micvdd;
144 else
145 config.init_data = &micsupp->init_data;
146
147 micsupp->regulator = regulator_register(&arizona_micsupp, &config);
148 if (IS_ERR(micsupp->regulator)) {
149 ret = PTR_ERR(micsupp->regulator);
150 dev_err(arizona->dev, "Failed to register mic supply: %d\n",
151 ret);
152 return ret;
153 }
154
155 platform_set_drvdata(pdev, micsupp);
156
157 return 0;
158}
159
160static __devexit int arizona_micsupp_remove(struct platform_device *pdev)
161{
162 struct arizona_micsupp *micsupp = platform_get_drvdata(pdev);
163
164 regulator_unregister(micsupp->regulator);
165
166 return 0;
167}
168
169static struct platform_driver arizona_micsupp_driver = {
170 .probe = arizona_micsupp_probe,
171 .remove = __devexit_p(arizona_micsupp_remove),
172 .driver = {
173 .name = "arizona-micsupp",
174 .owner = THIS_MODULE,
175 },
176};
177
178module_platform_driver(arizona_micsupp_driver);
179
180/* Module information */
181MODULE_AUTHOR("Mark Brown <broonie@opensource.wolfsonmicro.com>");
182MODULE_DESCRIPTION("Arizona microphone supply driver");
183MODULE_LICENSE("GPL");
184MODULE_ALIAS("platform:arizona-micsupp");