Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

regulator: arizona-micsupp: Enable SYSCLK for charge pump

If we are in non-bypass mode then the SYSCLK is required for full charge
pump operation, otherwise we will fall back to bypass mode. Use the DAPM
context exposed by the ASoC driver to manage this.

Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>

+73 -3
+1
drivers/regulator/Kconfig
··· 91 91 config REGULATOR_ARIZONA 92 92 tristate "Wolfson Arizona class devices" 93 93 depends on MFD_ARIZONA 94 + depends on SND_SOC 94 95 help 95 96 Support for the regulators found on Wolfson Arizona class 96 97 devices.
+72 -3
drivers/regulator/arizona-micsupp.c
··· 21 21 #include <linux/regulator/machine.h> 22 22 #include <linux/gpio.h> 23 23 #include <linux/slab.h> 24 + #include <linux/workqueue.h> 25 + #include <sound/soc.h> 24 26 25 27 #include <linux/mfd/arizona/core.h> 26 28 #include <linux/mfd/arizona/pdata.h> ··· 36 34 37 35 struct regulator_consumer_supply supply; 38 36 struct regulator_init_data init_data; 37 + 38 + struct work_struct check_cp_work; 39 39 }; 40 40 41 41 static int arizona_micsupp_list_voltage(struct regulator_dev *rdev, ··· 76 72 return selector; 77 73 } 78 74 75 + static void arizona_micsupp_check_cp(struct work_struct *work) 76 + { 77 + struct arizona_micsupp *micsupp = 78 + container_of(work, struct arizona_micsupp, check_cp_work); 79 + struct snd_soc_dapm_context *dapm = micsupp->arizona->dapm; 80 + struct arizona *arizona = micsupp->arizona; 81 + struct regmap *regmap = arizona->regmap; 82 + unsigned int reg; 83 + int ret; 84 + 85 + ret = regmap_read(regmap, ARIZONA_MIC_CHARGE_PUMP_1, &reg); 86 + if (ret != 0) { 87 + dev_err(arizona->dev, "Failed to read CP state: %d\n", ret); 88 + return; 89 + } 90 + 91 + if (dapm) { 92 + if ((reg & (ARIZONA_CPMIC_ENA | ARIZONA_CPMIC_BYPASS)) == 93 + ARIZONA_CPMIC_ENA) 94 + snd_soc_dapm_force_enable_pin(dapm, "MICSUPP"); 95 + else 96 + snd_soc_dapm_disable_pin(dapm, "MICSUPP"); 97 + 98 + snd_soc_dapm_sync(dapm); 99 + } 100 + } 101 + 102 + static int arizona_micsupp_enable(struct regulator_dev *rdev) 103 + { 104 + struct arizona_micsupp *micsupp = rdev_get_drvdata(rdev); 105 + int ret; 106 + 107 + ret = regulator_enable_regmap(rdev); 108 + 109 + if (ret == 0) 110 + schedule_work(&micsupp->check_cp_work); 111 + 112 + return ret; 113 + } 114 + 115 + static int arizona_micsupp_disable(struct regulator_dev *rdev) 116 + { 117 + struct arizona_micsupp *micsupp = rdev_get_drvdata(rdev); 118 + int ret; 119 + 120 + ret = regulator_disable_regmap(rdev); 121 + if (ret == 0) 122 + schedule_work(&micsupp->check_cp_work); 123 + 124 + return ret; 125 + } 126 + 127 + static int arizona_micsupp_set_bypass(struct regulator_dev *rdev, bool ena) 128 + { 129 + struct arizona_micsupp *micsupp = rdev_get_drvdata(rdev); 130 + int ret; 131 + 132 + ret = regulator_set_bypass_regmap(rdev, ena); 133 + if (ret == 0) 134 + schedule_work(&micsupp->check_cp_work); 135 + 136 + return ret; 137 + } 138 + 79 139 static struct regulator_ops arizona_micsupp_ops = { 80 - .enable = regulator_enable_regmap, 81 - .disable = regulator_disable_regmap, 140 + .enable = arizona_micsupp_enable, 141 + .disable = arizona_micsupp_disable, 82 142 .is_enabled = regulator_is_enabled_regmap, 83 143 84 144 .list_voltage = arizona_micsupp_list_voltage, ··· 152 84 .set_voltage_sel = regulator_set_voltage_sel_regmap, 153 85 154 86 .get_bypass = regulator_get_bypass_regmap, 155 - .set_bypass = regulator_set_bypass_regmap, 87 + .set_bypass = arizona_micsupp_set_bypass, 156 88 }; 157 89 158 90 static const struct regulator_desc arizona_micsupp = { ··· 199 131 } 200 132 201 133 micsupp->arizona = arizona; 134 + INIT_WORK(&micsupp->check_cp_work, arizona_micsupp_check_cp); 202 135 203 136 /* 204 137 * Since the chip usually supplies itself we provide some