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