Linux Audio

Check our new training course

Loading...
v6.13.7
  1// SPDX-License-Identifier: GPL-2.0+
  2//
  3// arizona-micsupp.c  --  Microphone supply for Arizona devices
  4//
  5// Copyright 2012 Wolfson Microelectronics PLC.
  6//
  7// Author: Mark Brown <broonie@opensource.wolfsonmicro.com>
 
 
 
 
 
  8
  9#include <linux/module.h>
 10#include <linux/moduleparam.h>
 11#include <linux/init.h>
 12#include <linux/bitops.h>
 13#include <linux/err.h>
 14#include <linux/of.h>
 15#include <linux/platform_device.h>
 16#include <linux/regulator/driver.h>
 17#include <linux/regulator/machine.h>
 18#include <linux/regulator/of_regulator.h>
 
 19#include <linux/slab.h>
 20#include <linux/workqueue.h>
 21#include <sound/soc.h>
 22
 23#include <linux/mfd/arizona/core.h>
 24#include <linux/mfd/arizona/pdata.h>
 25#include <linux/mfd/arizona/registers.h>
 26
 27#include <linux/mfd/madera/core.h>
 28#include <linux/mfd/madera/pdata.h>
 29#include <linux/mfd/madera/registers.h>
 30
 31#include <linux/regulator/arizona-micsupp.h>
 32
 33struct arizona_micsupp {
 34	struct regulator_dev *regulator;
 35	struct regmap *regmap;
 36	struct snd_soc_dapm_context **dapm;
 37	const struct regulator_desc *desc;
 38	struct device *dev;
 39
 40	struct regulator_consumer_supply supply;
 41	struct regulator_init_data init_data;
 42
 43	struct work_struct check_cp_work;
 44};
 45
 46static void arizona_micsupp_check_cp(struct work_struct *work)
 47{
 48	struct arizona_micsupp *micsupp =
 49		container_of(work, struct arizona_micsupp, check_cp_work);
 50	struct snd_soc_dapm_context *dapm = *micsupp->dapm;
 51	struct snd_soc_component *component;
 52	const struct regulator_desc *desc = micsupp->desc;
 53	unsigned int val;
 54	int ret;
 55
 56	ret = regmap_read(micsupp->regmap, desc->enable_reg, &val);
 57	if (ret != 0) {
 58		dev_err(micsupp->dev,
 59			"Failed to read CP state: %d\n", ret);
 60		return;
 61	}
 62
 63	if (dapm) {
 64		component = snd_soc_dapm_to_component(dapm);
 65
 66		if ((val & (desc->enable_mask | desc->bypass_mask)) ==
 67		    desc->enable_mask)
 68			snd_soc_component_force_enable_pin(component,
 69							   "MICSUPP");
 70		else
 71			snd_soc_component_disable_pin(component, "MICSUPP");
 72
 73		snd_soc_dapm_sync(dapm);
 74	}
 75}
 76
 77static int arizona_micsupp_enable(struct regulator_dev *rdev)
 78{
 79	struct arizona_micsupp *micsupp = rdev_get_drvdata(rdev);
 80	int ret;
 81
 82	ret = regulator_enable_regmap(rdev);
 83
 84	if (ret == 0)
 85		schedule_work(&micsupp->check_cp_work);
 86
 87	return ret;
 88}
 89
 90static int arizona_micsupp_disable(struct regulator_dev *rdev)
 91{
 92	struct arizona_micsupp *micsupp = rdev_get_drvdata(rdev);
 93	int ret;
 94
 95	ret = regulator_disable_regmap(rdev);
 96	if (ret == 0)
 97		schedule_work(&micsupp->check_cp_work);
 98
 99	return ret;
100}
101
102static int arizona_micsupp_set_bypass(struct regulator_dev *rdev, bool ena)
103{
104	struct arizona_micsupp *micsupp = rdev_get_drvdata(rdev);
105	int ret;
106
107	ret = regulator_set_bypass_regmap(rdev, ena);
108	if (ret == 0)
109		schedule_work(&micsupp->check_cp_work);
110
111	return ret;
112}
113
114static const struct regulator_ops arizona_micsupp_ops = {
115	.enable = arizona_micsupp_enable,
116	.disable = arizona_micsupp_disable,
117	.is_enabled = regulator_is_enabled_regmap,
118
119	.list_voltage = regulator_list_voltage_linear_range,
120	.map_voltage = regulator_map_voltage_linear_range,
121
122	.get_voltage_sel = regulator_get_voltage_sel_regmap,
123	.set_voltage_sel = regulator_set_voltage_sel_regmap,
124
125	.get_bypass = regulator_get_bypass_regmap,
126	.set_bypass = arizona_micsupp_set_bypass,
127};
128
129static const struct linear_range arizona_micsupp_ranges[] = {
130	REGULATOR_LINEAR_RANGE(1700000, 0,    0x1e, 50000),
131	REGULATOR_LINEAR_RANGE(3300000, 0x1f, 0x1f, 0),
132};
133
134static const struct regulator_desc arizona_micsupp = {
135	.name = "MICVDD",
136	.supply_name = "CPVDD",
137	.type = REGULATOR_VOLTAGE,
138	.n_voltages = 32,
139	.ops = &arizona_micsupp_ops,
140
141	.vsel_reg = ARIZONA_LDO2_CONTROL_1,
142	.vsel_mask = ARIZONA_LDO2_VSEL_MASK,
143	.enable_reg = ARIZONA_MIC_CHARGE_PUMP_1,
144	.enable_mask = ARIZONA_CPMIC_ENA,
145	.bypass_reg = ARIZONA_MIC_CHARGE_PUMP_1,
146	.bypass_mask = ARIZONA_CPMIC_BYPASS,
147
148	.linear_ranges = arizona_micsupp_ranges,
149	.n_linear_ranges = ARRAY_SIZE(arizona_micsupp_ranges),
150
151	.enable_time = 3000,
152
153	.owner = THIS_MODULE,
154};
155
156static const struct linear_range arizona_micsupp_ext_ranges[] = {
157	REGULATOR_LINEAR_RANGE(900000,  0,    0x14, 25000),
158	REGULATOR_LINEAR_RANGE(1500000, 0x15, 0x27, 100000),
159};
160
161static const struct regulator_desc arizona_micsupp_ext = {
162	.name = "MICVDD",
163	.supply_name = "CPVDD",
164	.type = REGULATOR_VOLTAGE,
165	.n_voltages = 40,
166	.ops = &arizona_micsupp_ops,
167
168	.vsel_reg = ARIZONA_LDO2_CONTROL_1,
169	.vsel_mask = ARIZONA_LDO2_VSEL_MASK,
170	.enable_reg = ARIZONA_MIC_CHARGE_PUMP_1,
171	.enable_mask = ARIZONA_CPMIC_ENA,
172	.bypass_reg = ARIZONA_MIC_CHARGE_PUMP_1,
173	.bypass_mask = ARIZONA_CPMIC_BYPASS,
174
175	.linear_ranges = arizona_micsupp_ext_ranges,
176	.n_linear_ranges = ARRAY_SIZE(arizona_micsupp_ext_ranges),
177
178	.enable_time = 3000,
179
180	.owner = THIS_MODULE,
181};
182
183static const struct regulator_init_data arizona_micsupp_default = {
184	.constraints = {
185		.valid_ops_mask = REGULATOR_CHANGE_STATUS |
186				REGULATOR_CHANGE_VOLTAGE |
187				REGULATOR_CHANGE_BYPASS,
188		.min_uV = 1700000,
189		.max_uV = 3300000,
190	},
191
192	.num_consumer_supplies = 1,
193};
194
195static const struct regulator_init_data arizona_micsupp_ext_default = {
196	.constraints = {
197		.valid_ops_mask = REGULATOR_CHANGE_STATUS |
198				REGULATOR_CHANGE_VOLTAGE |
199				REGULATOR_CHANGE_BYPASS,
200		.min_uV = 900000,
201		.max_uV = 3300000,
202	},
203
204	.num_consumer_supplies = 1,
205};
206
207static const struct regulator_desc madera_micsupp = {
208	.name = "MICVDD",
209	.supply_name = "CPVDD1",
210	.type = REGULATOR_VOLTAGE,
211	.n_voltages = 40,
212	.ops = &arizona_micsupp_ops,
213	.vsel_reg = MADERA_LDO2_CONTROL_1,
214	.vsel_mask = MADERA_LDO2_VSEL_MASK,
215	.enable_reg = MADERA_MIC_CHARGE_PUMP_1,
216	.enable_mask = MADERA_CPMIC_ENA,
217	.bypass_reg = MADERA_MIC_CHARGE_PUMP_1,
218	.bypass_mask = MADERA_CPMIC_BYPASS,
219
220	.linear_ranges = arizona_micsupp_ext_ranges,
221	.n_linear_ranges = ARRAY_SIZE(arizona_micsupp_ext_ranges),
222
223	.enable_time = 3000,
224
225	.owner = THIS_MODULE,
226};
227
228static int arizona_micsupp_of_get_pdata(struct arizona_micsupp_pdata *pdata,
229					struct regulator_config *config,
230					const struct regulator_desc *desc)
231{
232	struct arizona_micsupp *micsupp = config->driver_data;
233	struct device_node *np;
234	struct regulator_init_data *init_data;
235
236	np = of_get_child_by_name(config->dev->of_node, "micvdd");
237
238	if (np) {
239		config->of_node = np;
240
241		init_data = of_get_regulator_init_data(config->dev, np, desc);
242
243		if (init_data) {
244			init_data->consumer_supplies = &micsupp->supply;
245			init_data->num_consumer_supplies = 1;
246
247			pdata->init_data = init_data;
248		}
249	}
250
251	return 0;
252}
253
254static int arizona_micsupp_common_init(struct platform_device *pdev,
255				       struct arizona_micsupp *micsupp,
256				       const struct regulator_desc *desc,
257				       struct arizona_micsupp_pdata *pdata)
258{
259	struct regulator_config config = { };
260	int ret;
261
262	INIT_WORK(&micsupp->check_cp_work, arizona_micsupp_check_cp);
263
264	micsupp->init_data.consumer_supplies = &micsupp->supply;
 
265	micsupp->supply.dev_name = dev_name(micsupp->dev);
266	micsupp->desc = desc;
267
268	config.dev = micsupp->dev;
269	config.driver_data = micsupp;
270	config.regmap = micsupp->regmap;
271
272	if (IS_ENABLED(CONFIG_OF)) {
273		if (!dev_get_platdata(micsupp->dev)) {
274			ret = arizona_micsupp_of_get_pdata(pdata, &config,
275							   desc);
276			if (ret < 0)
277				return ret;
278		}
279	}
280
281	if (pdata->init_data)
282		config.init_data = pdata->init_data;
283	else
284		config.init_data = &micsupp->init_data;
285
286	/* Default to regulated mode */
287	regmap_update_bits(micsupp->regmap, desc->enable_reg, desc->bypass_mask, 0);
 
288
289	micsupp->regulator = devm_regulator_register(&pdev->dev,
290						     desc,
291						     &config);
292
293	of_node_put(config.of_node);
294
295	if (IS_ERR(micsupp->regulator)) {
296		ret = PTR_ERR(micsupp->regulator);
297		dev_err(micsupp->dev, "Failed to register mic supply: %d\n",
298			ret);
299		return ret;
300	}
301
302	platform_set_drvdata(pdev, micsupp);
303
304	return 0;
305}
306
307static int arizona_micsupp_probe(struct platform_device *pdev)
308{
309	struct arizona *arizona = dev_get_drvdata(pdev->dev.parent);
310	const struct regulator_desc *desc;
311	struct arizona_micsupp *micsupp;
312
313	micsupp = devm_kzalloc(&pdev->dev, sizeof(*micsupp), GFP_KERNEL);
314	if (!micsupp)
315		return -ENOMEM;
316
317	micsupp->regmap = arizona->regmap;
318	micsupp->dapm = &arizona->dapm;
319	micsupp->dev = arizona->dev;
320
321	micsupp->supply.supply = "MICVDD";
322
323	/*
324	 * Since the chip usually supplies itself we provide some
325	 * default init_data for it.  This will be overridden with
326	 * platform data if provided.
327	 */
328	switch (arizona->type) {
329	case WM5110:
330	case WM8280:
331		desc = &arizona_micsupp_ext;
332		micsupp->init_data = arizona_micsupp_ext_default;
333		break;
334	default:
335		desc = &arizona_micsupp;
336		micsupp->init_data = arizona_micsupp_default;
337		break;
338	}
339
340	return arizona_micsupp_common_init(pdev, micsupp, desc,
341					   &arizona->pdata.micvdd);
342}
343
344static int madera_micsupp_probe(struct platform_device *pdev)
345{
346	struct madera *madera = dev_get_drvdata(pdev->dev.parent);
347	struct arizona_micsupp *micsupp;
348
349	micsupp = devm_kzalloc(&pdev->dev, sizeof(*micsupp), GFP_KERNEL);
350	if (!micsupp)
351		return -ENOMEM;
352
353	micsupp->regmap = madera->regmap;
354	micsupp->dapm = &madera->dapm;
355	micsupp->dev = madera->dev;
356	micsupp->init_data = arizona_micsupp_ext_default;
357
358	micsupp->supply.supply = "MICVDD";
359
360	return arizona_micsupp_common_init(pdev, micsupp, &madera_micsupp,
361					   &madera->pdata.micvdd);
362}
363
364static struct platform_driver arizona_micsupp_driver = {
365	.probe = arizona_micsupp_probe,
366	.driver		= {
367		.name	= "arizona-micsupp",
368		.probe_type = PROBE_FORCE_SYNCHRONOUS,
369	},
370};
371
372static struct platform_driver madera_micsupp_driver = {
373	.probe = madera_micsupp_probe,
374	.driver		= {
375		.name	= "madera-micsupp",
376		.probe_type = PROBE_FORCE_SYNCHRONOUS,
377	},
378};
379
380static struct platform_driver * const arizona_micsupp_drivers[] = {
381	&arizona_micsupp_driver,
382	&madera_micsupp_driver,
383};
384
385static int __init arizona_micsupp_init(void)
386{
387	return platform_register_drivers(arizona_micsupp_drivers,
388					 ARRAY_SIZE(arizona_micsupp_drivers));
389}
390module_init(arizona_micsupp_init);
391
392static void __exit arizona_micsupp_exit(void)
393{
394	platform_unregister_drivers(arizona_micsupp_drivers,
395				    ARRAY_SIZE(arizona_micsupp_drivers));
396}
397module_exit(arizona_micsupp_exit);
398
399/* Module information */
400MODULE_AUTHOR("Mark Brown <broonie@opensource.wolfsonmicro.com>");
401MODULE_DESCRIPTION("Arizona microphone supply driver");
402MODULE_LICENSE("GPL");
403MODULE_ALIAS("platform:arizona-micsupp");
404MODULE_ALIAS("platform:madera-micsupp");
v4.17
  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/of.h>
 20#include <linux/platform_device.h>
 21#include <linux/regulator/driver.h>
 22#include <linux/regulator/machine.h>
 23#include <linux/regulator/of_regulator.h>
 24#include <linux/gpio.h>
 25#include <linux/slab.h>
 26#include <linux/workqueue.h>
 27#include <sound/soc.h>
 28
 29#include <linux/mfd/arizona/core.h>
 30#include <linux/mfd/arizona/pdata.h>
 31#include <linux/mfd/arizona/registers.h>
 32
 
 
 
 
 33#include <linux/regulator/arizona-micsupp.h>
 34
 35struct arizona_micsupp {
 36	struct regulator_dev *regulator;
 37	struct regmap *regmap;
 38	struct snd_soc_dapm_context **dapm;
 39	unsigned int enable_reg;
 40	struct device *dev;
 41
 42	struct regulator_consumer_supply supply;
 43	struct regulator_init_data init_data;
 44
 45	struct work_struct check_cp_work;
 46};
 47
 48static void arizona_micsupp_check_cp(struct work_struct *work)
 49{
 50	struct arizona_micsupp *micsupp =
 51		container_of(work, struct arizona_micsupp, check_cp_work);
 52	struct snd_soc_dapm_context *dapm = *micsupp->dapm;
 53	struct snd_soc_component *component;
 
 54	unsigned int val;
 55	int ret;
 56
 57	ret = regmap_read(micsupp->regmap, micsupp->enable_reg, &val);
 58	if (ret != 0) {
 59		dev_err(micsupp->dev,
 60			"Failed to read CP state: %d\n", ret);
 61		return;
 62	}
 63
 64	if (dapm) {
 65		component = snd_soc_dapm_to_component(dapm);
 66
 67		if ((val & (ARIZONA_CPMIC_ENA | ARIZONA_CPMIC_BYPASS)) ==
 68		    ARIZONA_CPMIC_ENA)
 69			snd_soc_component_force_enable_pin(component,
 70							   "MICSUPP");
 71		else
 72			snd_soc_component_disable_pin(component, "MICSUPP");
 73
 74		snd_soc_dapm_sync(dapm);
 75	}
 76}
 77
 78static int arizona_micsupp_enable(struct regulator_dev *rdev)
 79{
 80	struct arizona_micsupp *micsupp = rdev_get_drvdata(rdev);
 81	int ret;
 82
 83	ret = regulator_enable_regmap(rdev);
 84
 85	if (ret == 0)
 86		schedule_work(&micsupp->check_cp_work);
 87
 88	return ret;
 89}
 90
 91static int arizona_micsupp_disable(struct regulator_dev *rdev)
 92{
 93	struct arizona_micsupp *micsupp = rdev_get_drvdata(rdev);
 94	int ret;
 95
 96	ret = regulator_disable_regmap(rdev);
 97	if (ret == 0)
 98		schedule_work(&micsupp->check_cp_work);
 99
100	return ret;
101}
102
103static int arizona_micsupp_set_bypass(struct regulator_dev *rdev, bool ena)
104{
105	struct arizona_micsupp *micsupp = rdev_get_drvdata(rdev);
106	int ret;
107
108	ret = regulator_set_bypass_regmap(rdev, ena);
109	if (ret == 0)
110		schedule_work(&micsupp->check_cp_work);
111
112	return ret;
113}
114
115static const struct regulator_ops arizona_micsupp_ops = {
116	.enable = arizona_micsupp_enable,
117	.disable = arizona_micsupp_disable,
118	.is_enabled = regulator_is_enabled_regmap,
119
120	.list_voltage = regulator_list_voltage_linear_range,
121	.map_voltage = regulator_map_voltage_linear_range,
122
123	.get_voltage_sel = regulator_get_voltage_sel_regmap,
124	.set_voltage_sel = regulator_set_voltage_sel_regmap,
125
126	.get_bypass = regulator_get_bypass_regmap,
127	.set_bypass = arizona_micsupp_set_bypass,
128};
129
130static const struct regulator_linear_range arizona_micsupp_ranges[] = {
131	REGULATOR_LINEAR_RANGE(1700000, 0,    0x1e, 50000),
132	REGULATOR_LINEAR_RANGE(3300000, 0x1f, 0x1f, 0),
133};
134
135static const struct regulator_desc arizona_micsupp = {
136	.name = "MICVDD",
137	.supply_name = "CPVDD",
138	.type = REGULATOR_VOLTAGE,
139	.n_voltages = 32,
140	.ops = &arizona_micsupp_ops,
141
142	.vsel_reg = ARIZONA_LDO2_CONTROL_1,
143	.vsel_mask = ARIZONA_LDO2_VSEL_MASK,
144	.enable_reg = ARIZONA_MIC_CHARGE_PUMP_1,
145	.enable_mask = ARIZONA_CPMIC_ENA,
146	.bypass_reg = ARIZONA_MIC_CHARGE_PUMP_1,
147	.bypass_mask = ARIZONA_CPMIC_BYPASS,
148
149	.linear_ranges = arizona_micsupp_ranges,
150	.n_linear_ranges = ARRAY_SIZE(arizona_micsupp_ranges),
151
152	.enable_time = 3000,
153
154	.owner = THIS_MODULE,
155};
156
157static const struct regulator_linear_range arizona_micsupp_ext_ranges[] = {
158	REGULATOR_LINEAR_RANGE(900000,  0,    0x14, 25000),
159	REGULATOR_LINEAR_RANGE(1500000, 0x15, 0x27, 100000),
160};
161
162static const struct regulator_desc arizona_micsupp_ext = {
163	.name = "MICVDD",
164	.supply_name = "CPVDD",
165	.type = REGULATOR_VOLTAGE,
166	.n_voltages = 40,
167	.ops = &arizona_micsupp_ops,
168
169	.vsel_reg = ARIZONA_LDO2_CONTROL_1,
170	.vsel_mask = ARIZONA_LDO2_VSEL_MASK,
171	.enable_reg = ARIZONA_MIC_CHARGE_PUMP_1,
172	.enable_mask = ARIZONA_CPMIC_ENA,
173	.bypass_reg = ARIZONA_MIC_CHARGE_PUMP_1,
174	.bypass_mask = ARIZONA_CPMIC_BYPASS,
175
176	.linear_ranges = arizona_micsupp_ext_ranges,
177	.n_linear_ranges = ARRAY_SIZE(arizona_micsupp_ext_ranges),
178
179	.enable_time = 3000,
180
181	.owner = THIS_MODULE,
182};
183
184static const struct regulator_init_data arizona_micsupp_default = {
185	.constraints = {
186		.valid_ops_mask = REGULATOR_CHANGE_STATUS |
187				REGULATOR_CHANGE_VOLTAGE |
188				REGULATOR_CHANGE_BYPASS,
189		.min_uV = 1700000,
190		.max_uV = 3300000,
191	},
192
193	.num_consumer_supplies = 1,
194};
195
196static const struct regulator_init_data arizona_micsupp_ext_default = {
197	.constraints = {
198		.valid_ops_mask = REGULATOR_CHANGE_STATUS |
199				REGULATOR_CHANGE_VOLTAGE |
200				REGULATOR_CHANGE_BYPASS,
201		.min_uV = 900000,
202		.max_uV = 3300000,
203	},
204
205	.num_consumer_supplies = 1,
206};
207
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
208static int arizona_micsupp_of_get_pdata(struct arizona_micsupp_pdata *pdata,
209					struct regulator_config *config,
210					const struct regulator_desc *desc)
211{
212	struct arizona_micsupp *micsupp = config->driver_data;
213	struct device_node *np;
214	struct regulator_init_data *init_data;
215
216	np = of_get_child_by_name(config->dev->of_node, "micvdd");
217
218	if (np) {
219		config->of_node = np;
220
221		init_data = of_get_regulator_init_data(config->dev, np, desc);
222
223		if (init_data) {
224			init_data->consumer_supplies = &micsupp->supply;
225			init_data->num_consumer_supplies = 1;
226
227			pdata->init_data = init_data;
228		}
229	}
230
231	return 0;
232}
233
234static int arizona_micsupp_common_init(struct platform_device *pdev,
235				       struct arizona_micsupp *micsupp,
236				       const struct regulator_desc *desc,
237				       struct arizona_micsupp_pdata *pdata)
238{
239	struct regulator_config config = { };
240	int ret;
241
242	INIT_WORK(&micsupp->check_cp_work, arizona_micsupp_check_cp);
243
244	micsupp->init_data.consumer_supplies = &micsupp->supply;
245	micsupp->supply.supply = "MICVDD";
246	micsupp->supply.dev_name = dev_name(micsupp->dev);
247	micsupp->enable_reg = desc->enable_reg;
248
249	config.dev = micsupp->dev;
250	config.driver_data = micsupp;
251	config.regmap = micsupp->regmap;
252
253	if (IS_ENABLED(CONFIG_OF)) {
254		if (!dev_get_platdata(micsupp->dev)) {
255			ret = arizona_micsupp_of_get_pdata(pdata, &config,
256							   desc);
257			if (ret < 0)
258				return ret;
259		}
260	}
261
262	if (pdata->init_data)
263		config.init_data = pdata->init_data;
264	else
265		config.init_data = &micsupp->init_data;
266
267	/* Default to regulated mode */
268	regmap_update_bits(micsupp->regmap, micsupp->enable_reg,
269			   ARIZONA_CPMIC_BYPASS, 0);
270
271	micsupp->regulator = devm_regulator_register(&pdev->dev,
272						     desc,
273						     &config);
274
275	of_node_put(config.of_node);
276
277	if (IS_ERR(micsupp->regulator)) {
278		ret = PTR_ERR(micsupp->regulator);
279		dev_err(micsupp->dev, "Failed to register mic supply: %d\n",
280			ret);
281		return ret;
282	}
283
284	platform_set_drvdata(pdev, micsupp);
285
286	return 0;
287}
288
289static int arizona_micsupp_probe(struct platform_device *pdev)
290{
291	struct arizona *arizona = dev_get_drvdata(pdev->dev.parent);
292	const struct regulator_desc *desc;
293	struct arizona_micsupp *micsupp;
294
295	micsupp = devm_kzalloc(&pdev->dev, sizeof(*micsupp), GFP_KERNEL);
296	if (!micsupp)
297		return -ENOMEM;
298
299	micsupp->regmap = arizona->regmap;
300	micsupp->dapm = &arizona->dapm;
301	micsupp->dev = arizona->dev;
302
 
 
303	/*
304	 * Since the chip usually supplies itself we provide some
305	 * default init_data for it.  This will be overridden with
306	 * platform data if provided.
307	 */
308	switch (arizona->type) {
309	case WM5110:
310	case WM8280:
311		desc = &arizona_micsupp_ext;
312		micsupp->init_data = arizona_micsupp_ext_default;
313		break;
314	default:
315		desc = &arizona_micsupp;
316		micsupp->init_data = arizona_micsupp_default;
317		break;
318	}
319
320	return arizona_micsupp_common_init(pdev, micsupp, desc,
321					   &arizona->pdata.micvdd);
322}
323
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
324static struct platform_driver arizona_micsupp_driver = {
325	.probe = arizona_micsupp_probe,
326	.driver		= {
327		.name	= "arizona-micsupp",
 
 
 
 
 
 
 
 
 
328	},
329};
330
331module_platform_driver(arizona_micsupp_driver);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
332
333/* Module information */
334MODULE_AUTHOR("Mark Brown <broonie@opensource.wolfsonmicro.com>");
335MODULE_DESCRIPTION("Arizona microphone supply driver");
336MODULE_LICENSE("GPL");
337MODULE_ALIAS("platform:arizona-micsupp");