Mark Brown | 9e50108 | 2010-01-29 18:20:29 +0000 | [diff] [blame] | 1 | /* |
| 2 | * wm8994-core.c -- Device access for Wolfson WM8994 |
| 3 | * |
| 4 | * Copyright 2009 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 | |
| 15 | #include <linux/kernel.h> |
| 16 | #include <linux/module.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 17 | #include <linux/slab.h> |
Mark Brown | 9e50108 | 2010-01-29 18:20:29 +0000 | [diff] [blame] | 18 | #include <linux/i2c.h> |
Mark Brown | d6c645fc | 2011-06-17 13:02:27 +0100 | [diff] [blame] | 19 | #include <linux/err.h> |
Mark Brown | 9e50108 | 2010-01-29 18:20:29 +0000 | [diff] [blame] | 20 | #include <linux/delay.h> |
| 21 | #include <linux/mfd/core.h> |
Mark Brown | 20fb277 | 2013-04-11 18:11:51 +0100 | [diff] [blame] | 22 | #include <linux/of.h> |
| 23 | #include <linux/of_device.h> |
| 24 | #include <linux/of_gpio.h> |
Mark Brown | d450f19 | 2010-11-26 17:19:35 +0000 | [diff] [blame] | 25 | #include <linux/pm_runtime.h> |
Mark Brown | d6c645fc | 2011-06-17 13:02:27 +0100 | [diff] [blame] | 26 | #include <linux/regmap.h> |
Mark Brown | 9e50108 | 2010-01-29 18:20:29 +0000 | [diff] [blame] | 27 | #include <linux/regulator/consumer.h> |
| 28 | #include <linux/regulator/machine.h> |
| 29 | |
| 30 | #include <linux/mfd/wm8994/core.h> |
| 31 | #include <linux/mfd/wm8994/pdata.h> |
| 32 | #include <linux/mfd/wm8994/registers.h> |
| 33 | |
Mark Brown | c3f1386 | 2011-10-25 14:23:53 +0200 | [diff] [blame] | 34 | #include "wm8994.h" |
Mark Brown | 9e50108 | 2010-01-29 18:20:29 +0000 | [diff] [blame] | 35 | |
| 36 | /** |
| 37 | * wm8994_reg_read: Read a single WM8994 register. |
| 38 | * |
| 39 | * @wm8994: Device to read from. |
| 40 | * @reg: Register to read. |
| 41 | */ |
| 42 | int wm8994_reg_read(struct wm8994 *wm8994, unsigned short reg) |
| 43 | { |
Mark Brown | d6c645fc | 2011-06-17 13:02:27 +0100 | [diff] [blame] | 44 | unsigned int val; |
Mark Brown | 9e50108 | 2010-01-29 18:20:29 +0000 | [diff] [blame] | 45 | int ret; |
| 46 | |
Mark Brown | d6c645fc | 2011-06-17 13:02:27 +0100 | [diff] [blame] | 47 | ret = regmap_read(wm8994->regmap, reg, &val); |
Mark Brown | 9e50108 | 2010-01-29 18:20:29 +0000 | [diff] [blame] | 48 | |
| 49 | if (ret < 0) |
| 50 | return ret; |
| 51 | else |
Mark Brown | d6c645fc | 2011-06-17 13:02:27 +0100 | [diff] [blame] | 52 | return val; |
Mark Brown | 9e50108 | 2010-01-29 18:20:29 +0000 | [diff] [blame] | 53 | } |
| 54 | EXPORT_SYMBOL_GPL(wm8994_reg_read); |
| 55 | |
| 56 | /** |
| 57 | * wm8994_bulk_read: Read multiple WM8994 registers |
| 58 | * |
| 59 | * @wm8994: Device to read from |
| 60 | * @reg: First register |
| 61 | * @count: Number of registers |
Mark Brown | 316b6cc | 2011-03-18 12:50:10 +0000 | [diff] [blame] | 62 | * @buf: Buffer to fill. The data will be returned big endian. |
Mark Brown | 9e50108 | 2010-01-29 18:20:29 +0000 | [diff] [blame] | 63 | */ |
| 64 | int wm8994_bulk_read(struct wm8994 *wm8994, unsigned short reg, |
| 65 | int count, u16 *buf) |
| 66 | { |
Mark Brown | d6c645fc | 2011-06-17 13:02:27 +0100 | [diff] [blame] | 67 | return regmap_bulk_read(wm8994->regmap, reg, buf, count); |
Mark Brown | 9e50108 | 2010-01-29 18:20:29 +0000 | [diff] [blame] | 68 | } |
Mark Brown | 9e50108 | 2010-01-29 18:20:29 +0000 | [diff] [blame] | 69 | |
Mark Brown | 9e50108 | 2010-01-29 18:20:29 +0000 | [diff] [blame] | 70 | /** |
| 71 | * wm8994_reg_write: Write a single WM8994 register. |
| 72 | * |
| 73 | * @wm8994: Device to write to. |
| 74 | * @reg: Register to write to. |
| 75 | * @val: Value to write. |
| 76 | */ |
| 77 | int wm8994_reg_write(struct wm8994 *wm8994, unsigned short reg, |
| 78 | unsigned short val) |
| 79 | { |
Mark Brown | d6c645fc | 2011-06-17 13:02:27 +0100 | [diff] [blame] | 80 | return regmap_write(wm8994->regmap, reg, val); |
Mark Brown | 9e50108 | 2010-01-29 18:20:29 +0000 | [diff] [blame] | 81 | } |
| 82 | EXPORT_SYMBOL_GPL(wm8994_reg_write); |
| 83 | |
| 84 | /** |
Mark Brown | e93c538 | 2011-03-10 13:54:07 +0000 | [diff] [blame] | 85 | * wm8994_bulk_write: Write multiple WM8994 registers |
| 86 | * |
| 87 | * @wm8994: Device to write to |
| 88 | * @reg: First register |
| 89 | * @count: Number of registers |
Mark Brown | 4277163 | 2011-03-17 21:42:29 +0000 | [diff] [blame] | 90 | * @buf: Buffer to write from. Data must be big-endian formatted. |
Mark Brown | e93c538 | 2011-03-10 13:54:07 +0000 | [diff] [blame] | 91 | */ |
| 92 | int wm8994_bulk_write(struct wm8994 *wm8994, unsigned short reg, |
Mark Brown | 07e73fb | 2011-03-17 21:42:30 +0000 | [diff] [blame] | 93 | int count, const u16 *buf) |
Mark Brown | e93c538 | 2011-03-10 13:54:07 +0000 | [diff] [blame] | 94 | { |
Mark Brown | d6c645fc | 2011-06-17 13:02:27 +0100 | [diff] [blame] | 95 | return regmap_raw_write(wm8994->regmap, reg, buf, count * sizeof(u16)); |
Mark Brown | e93c538 | 2011-03-10 13:54:07 +0000 | [diff] [blame] | 96 | } |
| 97 | EXPORT_SYMBOL_GPL(wm8994_bulk_write); |
| 98 | |
| 99 | /** |
Mark Brown | 9e50108 | 2010-01-29 18:20:29 +0000 | [diff] [blame] | 100 | * wm8994_set_bits: Set the value of a bitfield in a WM8994 register |
| 101 | * |
| 102 | * @wm8994: Device to write to. |
| 103 | * @reg: Register to write to. |
| 104 | * @mask: Mask of bits to set. |
| 105 | * @val: Value to set (unshifted) |
| 106 | */ |
| 107 | int wm8994_set_bits(struct wm8994 *wm8994, unsigned short reg, |
| 108 | unsigned short mask, unsigned short val) |
| 109 | { |
Mark Brown | d6c645fc | 2011-06-17 13:02:27 +0100 | [diff] [blame] | 110 | return regmap_update_bits(wm8994->regmap, reg, mask, val); |
Mark Brown | 9e50108 | 2010-01-29 18:20:29 +0000 | [diff] [blame] | 111 | } |
| 112 | EXPORT_SYMBOL_GPL(wm8994_set_bits); |
| 113 | |
| 114 | static struct mfd_cell wm8994_regulator_devs[] = { |
Mark Brown | d450f19 | 2010-11-26 17:19:35 +0000 | [diff] [blame] | 115 | { |
| 116 | .name = "wm8994-ldo", |
| 117 | .id = 1, |
| 118 | .pm_runtime_no_callbacks = true, |
| 119 | }, |
| 120 | { |
| 121 | .name = "wm8994-ldo", |
| 122 | .id = 2, |
| 123 | .pm_runtime_no_callbacks = true, |
| 124 | }, |
Mark Brown | 9e50108 | 2010-01-29 18:20:29 +0000 | [diff] [blame] | 125 | }; |
| 126 | |
Mark Brown | c9fbf7e | 2010-03-26 16:49:15 +0000 | [diff] [blame] | 127 | static struct resource wm8994_codec_resources[] = { |
| 128 | { |
| 129 | .start = WM8994_IRQ_TEMP_SHUT, |
| 130 | .end = WM8994_IRQ_TEMP_WARN, |
| 131 | .flags = IORESOURCE_IRQ, |
| 132 | }, |
| 133 | }; |
| 134 | |
| 135 | static struct resource wm8994_gpio_resources[] = { |
| 136 | { |
| 137 | .start = WM8994_IRQ_GPIO(1), |
| 138 | .end = WM8994_IRQ_GPIO(11), |
| 139 | .flags = IORESOURCE_IRQ, |
| 140 | }, |
| 141 | }; |
| 142 | |
Mark Brown | 9e50108 | 2010-01-29 18:20:29 +0000 | [diff] [blame] | 143 | static struct mfd_cell wm8994_devs[] = { |
Mark Brown | c9fbf7e | 2010-03-26 16:49:15 +0000 | [diff] [blame] | 144 | { |
| 145 | .name = "wm8994-codec", |
| 146 | .num_resources = ARRAY_SIZE(wm8994_codec_resources), |
| 147 | .resources = wm8994_codec_resources, |
| 148 | }, |
| 149 | |
| 150 | { |
| 151 | .name = "wm8994-gpio", |
| 152 | .num_resources = ARRAY_SIZE(wm8994_gpio_resources), |
| 153 | .resources = wm8994_gpio_resources, |
Mark Brown | d450f19 | 2010-11-26 17:19:35 +0000 | [diff] [blame] | 154 | .pm_runtime_no_callbacks = true, |
Mark Brown | c9fbf7e | 2010-03-26 16:49:15 +0000 | [diff] [blame] | 155 | }, |
Mark Brown | 9e50108 | 2010-01-29 18:20:29 +0000 | [diff] [blame] | 156 | }; |
| 157 | |
| 158 | /* |
| 159 | * Supplies for the main bulk of CODEC; the LDO supplies are ignored |
| 160 | * and should be handled via the standard regulator API supply |
| 161 | * management. |
| 162 | */ |
Mark Brown | b1f43bf | 2011-05-24 17:35:40 +0800 | [diff] [blame] | 163 | static const char *wm1811_main_supplies[] = { |
| 164 | "DBVDD1", |
| 165 | "DBVDD2", |
| 166 | "DBVDD3", |
| 167 | "DCVDD", |
| 168 | "AVDD1", |
| 169 | "AVDD2", |
| 170 | "CPVDD", |
| 171 | "SPKVDD1", |
| 172 | "SPKVDD2", |
| 173 | }; |
| 174 | |
Mark Brown | 9e50108 | 2010-01-29 18:20:29 +0000 | [diff] [blame] | 175 | static const char *wm8994_main_supplies[] = { |
| 176 | "DBVDD", |
| 177 | "DCVDD", |
| 178 | "AVDD1", |
| 179 | "AVDD2", |
| 180 | "CPVDD", |
| 181 | "SPKVDD1", |
| 182 | "SPKVDD2", |
| 183 | }; |
| 184 | |
Mark Brown | 559e0df | 2010-08-31 19:25:12 +0100 | [diff] [blame] | 185 | static const char *wm8958_main_supplies[] = { |
| 186 | "DBVDD1", |
| 187 | "DBVDD2", |
| 188 | "DBVDD3", |
| 189 | "DCVDD", |
| 190 | "AVDD1", |
| 191 | "AVDD2", |
| 192 | "CPVDD", |
| 193 | "SPKVDD1", |
| 194 | "SPKVDD2", |
| 195 | }; |
| 196 | |
Mark Brown | 6394678 | 2013-03-22 12:40:22 +0100 | [diff] [blame] | 197 | #ifdef CONFIG_PM_RUNTIME |
Mark Brown | d450f19 | 2010-11-26 17:19:35 +0000 | [diff] [blame] | 198 | static int wm8994_suspend(struct device *dev) |
Mark Brown | 9e50108 | 2010-01-29 18:20:29 +0000 | [diff] [blame] | 199 | { |
| 200 | struct wm8994 *wm8994 = dev_get_drvdata(dev); |
| 201 | int ret; |
| 202 | |
Mark Brown | 77bd70e | 2011-02-04 14:57:43 +0000 | [diff] [blame] | 203 | /* Don't actually go through with the suspend if the CODEC is |
| 204 | * still active (eg, for audio passthrough from CP. */ |
| 205 | ret = wm8994_reg_read(wm8994, WM8994_POWER_MANAGEMENT_1); |
| 206 | if (ret < 0) { |
| 207 | dev_err(dev, "Failed to read power status: %d\n", ret); |
| 208 | } else if (ret & WM8994_VMID_SEL_MASK) { |
| 209 | dev_dbg(dev, "CODEC still active, ignoring suspend\n"); |
| 210 | return 0; |
| 211 | } |
| 212 | |
Mark Brown | 5f40c6b | 2011-08-13 14:37:48 +0900 | [diff] [blame] | 213 | ret = wm8994_reg_read(wm8994, WM8994_POWER_MANAGEMENT_4); |
| 214 | if (ret < 0) { |
| 215 | dev_err(dev, "Failed to read power status: %d\n", ret); |
| 216 | } else if (ret & (WM8994_AIF2ADCL_ENA | WM8994_AIF2ADCR_ENA | |
| 217 | WM8994_AIF1ADC2L_ENA | WM8994_AIF1ADC2R_ENA | |
| 218 | WM8994_AIF1ADC1L_ENA | WM8994_AIF1ADC1R_ENA)) { |
| 219 | dev_dbg(dev, "CODEC still active, ignoring suspend\n"); |
| 220 | return 0; |
| 221 | } |
| 222 | |
| 223 | ret = wm8994_reg_read(wm8994, WM8994_POWER_MANAGEMENT_5); |
| 224 | if (ret < 0) { |
| 225 | dev_err(dev, "Failed to read power status: %d\n", ret); |
| 226 | } else if (ret & (WM8994_AIF2DACL_ENA | WM8994_AIF2DACR_ENA | |
| 227 | WM8994_AIF1DAC2L_ENA | WM8994_AIF1DAC2R_ENA | |
| 228 | WM8994_AIF1DAC1L_ENA | WM8994_AIF1DAC1R_ENA)) { |
| 229 | dev_dbg(dev, "CODEC still active, ignoring suspend\n"); |
| 230 | return 0; |
| 231 | } |
| 232 | |
| 233 | switch (wm8994->type) { |
| 234 | case WM8958: |
Mark Brown | b5488b6 | 2011-11-04 23:14:46 +0000 | [diff] [blame] | 235 | case WM1811: |
Mark Brown | 5f40c6b | 2011-08-13 14:37:48 +0900 | [diff] [blame] | 236 | ret = wm8994_reg_read(wm8994, WM8958_MIC_DETECT_1); |
| 237 | if (ret < 0) { |
| 238 | dev_err(dev, "Failed to read power status: %d\n", ret); |
| 239 | } else if (ret & WM8958_MICD_ENA) { |
| 240 | dev_dbg(dev, "CODEC still active, ignoring suspend\n"); |
| 241 | return 0; |
| 242 | } |
| 243 | break; |
| 244 | default: |
| 245 | break; |
| 246 | } |
| 247 | |
Mark Brown | a346249 | 2011-12-01 17:19:44 +0000 | [diff] [blame] | 248 | switch (wm8994->type) { |
| 249 | case WM1811: |
| 250 | ret = wm8994_reg_read(wm8994, WM8994_ANTIPOP_2); |
| 251 | if (ret < 0) { |
| 252 | dev_err(dev, "Failed to read jackdet: %d\n", ret); |
| 253 | } else if (ret & WM1811_JACKDET_MODE_MASK) { |
| 254 | dev_dbg(dev, "CODEC still active, ignoring suspend\n"); |
| 255 | return 0; |
| 256 | } |
| 257 | break; |
| 258 | default: |
| 259 | break; |
| 260 | } |
| 261 | |
Mark Brown | e7c248a | 2012-02-20 21:32:32 +0000 | [diff] [blame] | 262 | switch (wm8994->type) { |
| 263 | case WM1811: |
| 264 | ret = wm8994_reg_read(wm8994, WM8994_ANTIPOP_2); |
| 265 | if (ret < 0) { |
| 266 | dev_err(dev, "Failed to read jackdet: %d\n", ret); |
| 267 | } else if (ret & WM1811_JACKDET_MODE_MASK) { |
| 268 | dev_dbg(dev, "CODEC still active, ignoring suspend\n"); |
| 269 | return 0; |
| 270 | } |
| 271 | break; |
| 272 | default: |
| 273 | break; |
| 274 | } |
| 275 | |
Mark Brown | 881de67 | 2011-08-22 15:43:55 +0200 | [diff] [blame] | 276 | /* Disable LDO pulldowns while the device is suspended if we |
| 277 | * don't know that something will be driving them. */ |
| 278 | if (!wm8994->ldo_ena_always_driven) |
| 279 | wm8994_set_bits(wm8994, WM8994_PULL_CONTROL_2, |
| 280 | WM8994_LDO1ENA_PD | WM8994_LDO2ENA_PD, |
| 281 | WM8994_LDO1ENA_PD | WM8994_LDO2ENA_PD); |
| 282 | |
Mark Brown | f40dff9 | 2011-02-21 18:30:31 +0000 | [diff] [blame] | 283 | /* Explicitly put the device into reset in case regulators |
| 284 | * don't get disabled in order to ensure consistent restart. |
| 285 | */ |
Mark Brown | be79cf2 | 2011-10-25 13:25:43 +0200 | [diff] [blame] | 286 | wm8994_reg_write(wm8994, WM8994_SOFTWARE_RESET, |
| 287 | wm8994_reg_read(wm8994, WM8994_SOFTWARE_RESET)); |
Mark Brown | f40dff9 | 2011-02-21 18:30:31 +0000 | [diff] [blame] | 288 | |
Mark Brown | ed393dc | 2012-06-29 14:55:39 +0100 | [diff] [blame] | 289 | regcache_mark_dirty(wm8994->regmap); |
| 290 | |
Chris Rattray | 78a27cd | 2012-06-12 00:43:35 +0800 | [diff] [blame] | 291 | /* Restore GPIO registers to prevent problems with mismatched |
| 292 | * pin configurations. |
| 293 | */ |
Mark Brown | ed393dc | 2012-06-29 14:55:39 +0100 | [diff] [blame] | 294 | ret = regcache_sync_region(wm8994->regmap, WM8994_GPIO_1, |
| 295 | WM8994_GPIO_11); |
Chris Rattray | 78a27cd | 2012-06-12 00:43:35 +0800 | [diff] [blame] | 296 | if (ret != 0) |
| 297 | dev_err(dev, "Failed to restore GPIO registers: %d\n", ret); |
| 298 | |
Mark Brown | 1a2017b | 2012-06-29 14:55:40 +0100 | [diff] [blame] | 299 | /* In case one of the GPIOs is used as a wake input. */ |
| 300 | ret = regcache_sync_region(wm8994->regmap, |
| 301 | WM8994_INTERRUPT_STATUS_1_MASK, |
| 302 | WM8994_INTERRUPT_STATUS_1_MASK); |
| 303 | if (ret != 0) |
| 304 | dev_err(dev, "Failed to restore interrupt mask: %d\n", ret); |
| 305 | |
Mark Brown | 3befc92 | 2012-01-09 00:36:42 -0800 | [diff] [blame] | 306 | regcache_cache_only(wm8994->regmap, true); |
Mark Brown | 77bd70e | 2011-02-04 14:57:43 +0000 | [diff] [blame] | 307 | wm8994->suspended = true; |
| 308 | |
Mark Brown | 559e0df | 2010-08-31 19:25:12 +0100 | [diff] [blame] | 309 | ret = regulator_bulk_disable(wm8994->num_supplies, |
Mark Brown | 9e50108 | 2010-01-29 18:20:29 +0000 | [diff] [blame] | 310 | wm8994->supplies); |
| 311 | if (ret != 0) { |
| 312 | dev_err(dev, "Failed to disable supplies: %d\n", ret); |
| 313 | return ret; |
| 314 | } |
| 315 | |
| 316 | return 0; |
| 317 | } |
| 318 | |
Mark Brown | d450f19 | 2010-11-26 17:19:35 +0000 | [diff] [blame] | 319 | static int wm8994_resume(struct device *dev) |
Mark Brown | 9e50108 | 2010-01-29 18:20:29 +0000 | [diff] [blame] | 320 | { |
| 321 | struct wm8994 *wm8994 = dev_get_drvdata(dev); |
Mark Brown | c3f1386 | 2011-10-25 14:23:53 +0200 | [diff] [blame] | 322 | int ret; |
Mark Brown | 9e50108 | 2010-01-29 18:20:29 +0000 | [diff] [blame] | 323 | |
Mark Brown | 77bd70e | 2011-02-04 14:57:43 +0000 | [diff] [blame] | 324 | /* We may have lied to the PM core about suspending */ |
| 325 | if (!wm8994->suspended) |
| 326 | return 0; |
| 327 | |
Mark Brown | 559e0df | 2010-08-31 19:25:12 +0100 | [diff] [blame] | 328 | ret = regulator_bulk_enable(wm8994->num_supplies, |
Mark Brown | 9e50108 | 2010-01-29 18:20:29 +0000 | [diff] [blame] | 329 | wm8994->supplies); |
| 330 | if (ret != 0) { |
| 331 | dev_err(dev, "Failed to enable supplies: %d\n", ret); |
| 332 | return ret; |
| 333 | } |
| 334 | |
Mark Brown | 3befc92 | 2012-01-09 00:36:42 -0800 | [diff] [blame] | 335 | regcache_cache_only(wm8994->regmap, false); |
Mark Brown | c3f1386 | 2011-10-25 14:23:53 +0200 | [diff] [blame] | 336 | ret = regcache_sync(wm8994->regmap); |
| 337 | if (ret != 0) { |
| 338 | dev_err(dev, "Failed to restore register map: %d\n", ret); |
| 339 | goto err_enable; |
Mark Brown | 98ae1cc | 2011-06-07 11:49:42 +0100 | [diff] [blame] | 340 | } |
Mark Brown | c9fbf7e | 2010-03-26 16:49:15 +0000 | [diff] [blame] | 341 | |
Mark Brown | 881de67 | 2011-08-22 15:43:55 +0200 | [diff] [blame] | 342 | /* Disable LDO pulldowns while the device is active */ |
| 343 | wm8994_set_bits(wm8994, WM8994_PULL_CONTROL_2, |
| 344 | WM8994_LDO1ENA_PD | WM8994_LDO2ENA_PD, |
| 345 | 0); |
| 346 | |
Mark Brown | 77bd70e | 2011-02-04 14:57:43 +0000 | [diff] [blame] | 347 | wm8994->suspended = false; |
| 348 | |
Mark Brown | 9e50108 | 2010-01-29 18:20:29 +0000 | [diff] [blame] | 349 | return 0; |
Mark Brown | c3f1386 | 2011-10-25 14:23:53 +0200 | [diff] [blame] | 350 | |
| 351 | err_enable: |
| 352 | regulator_bulk_disable(wm8994->num_supplies, wm8994->supplies); |
| 353 | |
| 354 | return ret; |
Mark Brown | 9e50108 | 2010-01-29 18:20:29 +0000 | [diff] [blame] | 355 | } |
| 356 | #endif |
| 357 | |
| 358 | #ifdef CONFIG_REGULATOR |
| 359 | static int wm8994_ldo_in_use(struct wm8994_pdata *pdata, int ldo) |
| 360 | { |
| 361 | struct wm8994_ldo_pdata *ldo_pdata; |
| 362 | |
| 363 | if (!pdata) |
| 364 | return 0; |
| 365 | |
| 366 | ldo_pdata = &pdata->ldo[ldo]; |
| 367 | |
| 368 | if (!ldo_pdata->init_data) |
| 369 | return 0; |
| 370 | |
| 371 | return ldo_pdata->init_data->num_consumer_supplies != 0; |
| 372 | } |
| 373 | #else |
| 374 | static int wm8994_ldo_in_use(struct wm8994_pdata *pdata, int ldo) |
| 375 | { |
| 376 | return 0; |
| 377 | } |
| 378 | #endif |
| 379 | |
Bill Pemberton | a73e5df | 2012-11-19 13:25:09 -0500 | [diff] [blame] | 380 | static const struct reg_default wm8994_revc_patch[] = { |
Mark Brown | 462835e | 2012-01-21 12:11:53 +0000 | [diff] [blame] | 381 | { 0x102, 0x3 }, |
| 382 | { 0x56, 0x3 }, |
| 383 | { 0x817, 0x0 }, |
| 384 | { 0x102, 0x0 }, |
| 385 | }; |
| 386 | |
Bill Pemberton | a73e5df | 2012-11-19 13:25:09 -0500 | [diff] [blame] | 387 | static const struct reg_default wm8958_reva_patch[] = { |
Mark Brown | 462835e | 2012-01-21 12:11:53 +0000 | [diff] [blame] | 388 | { 0x102, 0x3 }, |
| 389 | { 0xcb, 0x81 }, |
| 390 | { 0x817, 0x0 }, |
| 391 | { 0x102, 0x0 }, |
| 392 | }; |
| 393 | |
Bill Pemberton | a73e5df | 2012-11-19 13:25:09 -0500 | [diff] [blame] | 394 | static const struct reg_default wm1811_reva_patch[] = { |
Mark Brown | 462835e | 2012-01-21 12:11:53 +0000 | [diff] [blame] | 395 | { 0x102, 0x3 }, |
Mark Brown | 9282a7b | 2012-08-23 16:10:29 +0100 | [diff] [blame] | 396 | { 0x56, 0xc07 }, |
Mark Brown | 462835e | 2012-01-21 12:11:53 +0000 | [diff] [blame] | 397 | { 0x5d, 0x7e }, |
| 398 | { 0x5e, 0x0 }, |
| 399 | { 0x102, 0x0 }, |
| 400 | }; |
| 401 | |
Mark Brown | 20fb277 | 2013-04-11 18:11:51 +0100 | [diff] [blame] | 402 | #ifdef CONFIG_OF |
| 403 | static int wm8994_set_pdata_from_of(struct wm8994 *wm8994) |
| 404 | { |
| 405 | struct device_node *np = wm8994->dev->of_node; |
| 406 | struct wm8994_pdata *pdata = &wm8994->pdata; |
| 407 | int i; |
| 408 | |
| 409 | if (!np) |
| 410 | return 0; |
| 411 | |
| 412 | if (of_property_read_u32_array(np, "wlf,gpio-cfg", pdata->gpio_defaults, |
| 413 | ARRAY_SIZE(pdata->gpio_defaults)) >= 0) { |
| 414 | for (i = 0; i < ARRAY_SIZE(pdata->gpio_defaults); i++) { |
| 415 | if (wm8994->pdata.gpio_defaults[i] == 0) |
| 416 | pdata->gpio_defaults[i] |
| 417 | = WM8994_CONFIGURE_GPIO; |
| 418 | } |
| 419 | } |
| 420 | |
| 421 | of_property_read_u32_array(np, "wlf,micbias-cfg", pdata->micbias, |
| 422 | ARRAY_SIZE(pdata->micbias)); |
| 423 | |
| 424 | pdata->lineout1_diff = true; |
| 425 | pdata->lineout2_diff = true; |
| 426 | if (of_find_property(np, "wlf,lineout1-se", NULL)) |
| 427 | pdata->lineout1_diff = false; |
| 428 | if (of_find_property(np, "wlf,lineout2-se", NULL)) |
| 429 | pdata->lineout2_diff = false; |
| 430 | |
| 431 | if (of_find_property(np, "wlf,lineout1-feedback", NULL)) |
| 432 | pdata->lineout1fb = true; |
| 433 | if (of_find_property(np, "wlf,lineout2-feedback", NULL)) |
| 434 | pdata->lineout2fb = true; |
| 435 | |
| 436 | if (of_find_property(np, "wlf,ldoena-always-driven", NULL)) |
| 437 | pdata->lineout2fb = true; |
| 438 | |
| 439 | pdata->ldo[0].enable = of_get_named_gpio(np, "wlf,ldo1ena", 0); |
| 440 | if (pdata->ldo[0].enable < 0) |
| 441 | pdata->ldo[0].enable = 0; |
| 442 | |
| 443 | pdata->ldo[1].enable = of_get_named_gpio(np, "wlf,ldo2ena", 0); |
| 444 | if (pdata->ldo[1].enable < 0) |
| 445 | pdata->ldo[1].enable = 0; |
| 446 | |
| 447 | return 0; |
| 448 | } |
| 449 | #else |
| 450 | static int wm8994_set_pdata_from_of(struct wm8994 *wm8994) |
| 451 | { |
| 452 | return 0; |
| 453 | } |
| 454 | #endif |
| 455 | |
Mark Brown | 9e50108 | 2010-01-29 18:20:29 +0000 | [diff] [blame] | 456 | /* |
| 457 | * Instantiate the generic non-control parts of the device. |
| 458 | */ |
Bill Pemberton | f791be4 | 2012-11-19 13:23:04 -0500 | [diff] [blame] | 459 | static int wm8994_device_init(struct wm8994 *wm8994, int irq) |
Mark Brown | 9e50108 | 2010-01-29 18:20:29 +0000 | [diff] [blame] | 460 | { |
Mark Brown | a8a8fc2 | 2012-10-08 11:21:09 +0900 | [diff] [blame] | 461 | struct wm8994_pdata *pdata; |
Mark Brown | 3469789 | 2011-12-03 17:10:32 +0000 | [diff] [blame] | 462 | struct regmap_config *regmap_config; |
Mark Brown | 462835e | 2012-01-21 12:11:53 +0000 | [diff] [blame] | 463 | const struct reg_default *regmap_patch = NULL; |
Mark Brown | 559e0df | 2010-08-31 19:25:12 +0100 | [diff] [blame] | 464 | const char *devname; |
Jingoo Han | 222bc78 | 2013-02-20 11:53:36 +0900 | [diff] [blame] | 465 | int ret, i, patch_regs = 0; |
Mark Brown | 26c34c2 | 2011-11-03 13:20:38 +0000 | [diff] [blame] | 466 | int pulls = 0; |
Mark Brown | 9e50108 | 2010-01-29 18:20:29 +0000 | [diff] [blame] | 467 | |
Mark Brown | a8a8fc2 | 2012-10-08 11:21:09 +0900 | [diff] [blame] | 468 | if (dev_get_platdata(wm8994->dev)) { |
| 469 | pdata = dev_get_platdata(wm8994->dev); |
| 470 | wm8994->pdata = *pdata; |
| 471 | } |
| 472 | pdata = &wm8994->pdata; |
| 473 | |
Mark Brown | 20fb277 | 2013-04-11 18:11:51 +0100 | [diff] [blame] | 474 | ret = wm8994_set_pdata_from_of(wm8994); |
| 475 | if (ret != 0) |
| 476 | return ret; |
| 477 | |
Mark Brown | 9e50108 | 2010-01-29 18:20:29 +0000 | [diff] [blame] | 478 | dev_set_drvdata(wm8994->dev, wm8994); |
| 479 | |
| 480 | /* Add the on-chip regulators first for bootstrapping */ |
| 481 | ret = mfd_add_devices(wm8994->dev, -1, |
| 482 | wm8994_regulator_devs, |
| 483 | ARRAY_SIZE(wm8994_regulator_devs), |
Mark Brown | 55692af | 2012-09-11 15:16:36 +0800 | [diff] [blame] | 484 | NULL, 0, NULL); |
Mark Brown | 9e50108 | 2010-01-29 18:20:29 +0000 | [diff] [blame] | 485 | if (ret != 0) { |
| 486 | dev_err(wm8994->dev, "Failed to add children: %d\n", ret); |
Mark Brown | 9db4249 | 2012-01-30 20:06:05 +0000 | [diff] [blame] | 487 | goto err; |
Mark Brown | 9e50108 | 2010-01-29 18:20:29 +0000 | [diff] [blame] | 488 | } |
| 489 | |
Mark Brown | 559e0df | 2010-08-31 19:25:12 +0100 | [diff] [blame] | 490 | switch (wm8994->type) { |
Mark Brown | b1f43bf | 2011-05-24 17:35:40 +0800 | [diff] [blame] | 491 | case WM1811: |
| 492 | wm8994->num_supplies = ARRAY_SIZE(wm1811_main_supplies); |
| 493 | break; |
Mark Brown | 559e0df | 2010-08-31 19:25:12 +0100 | [diff] [blame] | 494 | case WM8994: |
| 495 | wm8994->num_supplies = ARRAY_SIZE(wm8994_main_supplies); |
| 496 | break; |
| 497 | case WM8958: |
| 498 | wm8994->num_supplies = ARRAY_SIZE(wm8958_main_supplies); |
| 499 | break; |
| 500 | default: |
| 501 | BUG(); |
Mark Brown | 9db4249 | 2012-01-30 20:06:05 +0000 | [diff] [blame] | 502 | goto err; |
Mark Brown | 559e0df | 2010-08-31 19:25:12 +0100 | [diff] [blame] | 503 | } |
| 504 | |
Mark Brown | 2fa3349 | 2011-10-25 13:45:40 +0200 | [diff] [blame] | 505 | wm8994->supplies = devm_kzalloc(wm8994->dev, |
| 506 | sizeof(struct regulator_bulk_data) * |
| 507 | wm8994->num_supplies, GFP_KERNEL); |
Axel Lin | fccbd21 | 2010-08-04 09:44:47 +0800 | [diff] [blame] | 508 | if (!wm8994->supplies) { |
| 509 | ret = -ENOMEM; |
Mark Brown | 9db4249 | 2012-01-30 20:06:05 +0000 | [diff] [blame] | 510 | goto err; |
Axel Lin | fccbd21 | 2010-08-04 09:44:47 +0800 | [diff] [blame] | 511 | } |
Mark Brown | 9e50108 | 2010-01-29 18:20:29 +0000 | [diff] [blame] | 512 | |
Mark Brown | 559e0df | 2010-08-31 19:25:12 +0100 | [diff] [blame] | 513 | switch (wm8994->type) { |
Mark Brown | b1f43bf | 2011-05-24 17:35:40 +0800 | [diff] [blame] | 514 | case WM1811: |
| 515 | for (i = 0; i < ARRAY_SIZE(wm1811_main_supplies); i++) |
| 516 | wm8994->supplies[i].supply = wm1811_main_supplies[i]; |
| 517 | break; |
Mark Brown | 559e0df | 2010-08-31 19:25:12 +0100 | [diff] [blame] | 518 | case WM8994: |
| 519 | for (i = 0; i < ARRAY_SIZE(wm8994_main_supplies); i++) |
| 520 | wm8994->supplies[i].supply = wm8994_main_supplies[i]; |
| 521 | break; |
| 522 | case WM8958: |
| 523 | for (i = 0; i < ARRAY_SIZE(wm8958_main_supplies); i++) |
| 524 | wm8994->supplies[i].supply = wm8958_main_supplies[i]; |
| 525 | break; |
| 526 | default: |
| 527 | BUG(); |
Mark Brown | 9db4249 | 2012-01-30 20:06:05 +0000 | [diff] [blame] | 528 | goto err; |
Mark Brown | 559e0df | 2010-08-31 19:25:12 +0100 | [diff] [blame] | 529 | } |
| 530 | |
Sachin Kamat | f1c68e4 | 2013-01-08 14:01:22 +0530 | [diff] [blame] | 531 | ret = devm_regulator_bulk_get(wm8994->dev, wm8994->num_supplies, |
Mark Brown | 9e50108 | 2010-01-29 18:20:29 +0000 | [diff] [blame] | 532 | wm8994->supplies); |
| 533 | if (ret != 0) { |
| 534 | dev_err(wm8994->dev, "Failed to get supplies: %d\n", ret); |
Mark Brown | 9db4249 | 2012-01-30 20:06:05 +0000 | [diff] [blame] | 535 | goto err; |
Mark Brown | 9e50108 | 2010-01-29 18:20:29 +0000 | [diff] [blame] | 536 | } |
| 537 | |
Mark Brown | 559e0df | 2010-08-31 19:25:12 +0100 | [diff] [blame] | 538 | ret = regulator_bulk_enable(wm8994->num_supplies, |
Mark Brown | 9e50108 | 2010-01-29 18:20:29 +0000 | [diff] [blame] | 539 | wm8994->supplies); |
| 540 | if (ret != 0) { |
| 541 | dev_err(wm8994->dev, "Failed to enable supplies: %d\n", ret); |
Sachin Kamat | f1c68e4 | 2013-01-08 14:01:22 +0530 | [diff] [blame] | 542 | goto err; |
Mark Brown | 9e50108 | 2010-01-29 18:20:29 +0000 | [diff] [blame] | 543 | } |
| 544 | |
| 545 | ret = wm8994_reg_read(wm8994, WM8994_SOFTWARE_RESET); |
| 546 | if (ret < 0) { |
| 547 | dev_err(wm8994->dev, "Failed to read ID register\n"); |
| 548 | goto err_enable; |
| 549 | } |
Mark Brown | 559e0df | 2010-08-31 19:25:12 +0100 | [diff] [blame] | 550 | switch (ret) { |
Mark Brown | b1f43bf | 2011-05-24 17:35:40 +0800 | [diff] [blame] | 551 | case 0x1811: |
| 552 | devname = "WM1811"; |
| 553 | if (wm8994->type != WM1811) |
| 554 | dev_warn(wm8994->dev, "Device registered as type %d\n", |
| 555 | wm8994->type); |
| 556 | wm8994->type = WM1811; |
| 557 | break; |
Mark Brown | 559e0df | 2010-08-31 19:25:12 +0100 | [diff] [blame] | 558 | case 0x8994: |
| 559 | devname = "WM8994"; |
| 560 | if (wm8994->type != WM8994) |
| 561 | dev_warn(wm8994->dev, "Device registered as type %d\n", |
| 562 | wm8994->type); |
| 563 | wm8994->type = WM8994; |
| 564 | break; |
| 565 | case 0x8958: |
| 566 | devname = "WM8958"; |
| 567 | if (wm8994->type != WM8958) |
| 568 | dev_warn(wm8994->dev, "Device registered as type %d\n", |
| 569 | wm8994->type); |
| 570 | wm8994->type = WM8958; |
| 571 | break; |
| 572 | default: |
Mark Brown | 9e50108 | 2010-01-29 18:20:29 +0000 | [diff] [blame] | 573 | dev_err(wm8994->dev, "Device is not a WM8994, ID is %x\n", |
| 574 | ret); |
| 575 | ret = -EINVAL; |
| 576 | goto err_enable; |
| 577 | } |
| 578 | |
| 579 | ret = wm8994_reg_read(wm8994, WM8994_CHIP_REVISION); |
| 580 | if (ret < 0) { |
| 581 | dev_err(wm8994->dev, "Failed to read revision register: %d\n", |
| 582 | ret); |
| 583 | goto err_enable; |
| 584 | } |
Mark Brown | cc7a727 | 2012-05-07 10:03:22 +0100 | [diff] [blame] | 585 | wm8994->revision = ret & WM8994_CHIP_REV_MASK; |
| 586 | wm8994->cust_id = (ret & WM8994_CUST_ID_MASK) >> WM8994_CUST_ID_SHIFT; |
Mark Brown | 9e50108 | 2010-01-29 18:20:29 +0000 | [diff] [blame] | 587 | |
Mark Brown | a2495bc | 2011-06-02 19:18:55 +0100 | [diff] [blame] | 588 | switch (wm8994->type) { |
| 589 | case WM8994: |
Mark Brown | 7ed5849 | 2011-12-01 13:55:49 +0000 | [diff] [blame] | 590 | switch (wm8994->revision) { |
Mark Brown | a2495bc | 2011-06-02 19:18:55 +0100 | [diff] [blame] | 591 | case 0: |
| 592 | case 1: |
Mark Brown | 559e0df | 2010-08-31 19:25:12 +0100 | [diff] [blame] | 593 | dev_warn(wm8994->dev, |
| 594 | "revision %c not fully supported\n", |
Mark Brown | 7ed5849 | 2011-12-01 13:55:49 +0000 | [diff] [blame] | 595 | 'A' + wm8994->revision); |
Mark Brown | a2495bc | 2011-06-02 19:18:55 +0100 | [diff] [blame] | 596 | break; |
Mark Brown | 462835e | 2012-01-21 12:11:53 +0000 | [diff] [blame] | 597 | case 2: |
| 598 | case 3: |
Mark Brown | d54e17f | 2012-11-27 15:23:30 +0000 | [diff] [blame] | 599 | default: |
Mark Brown | 462835e | 2012-01-21 12:11:53 +0000 | [diff] [blame] | 600 | regmap_patch = wm8994_revc_patch; |
| 601 | patch_regs = ARRAY_SIZE(wm8994_revc_patch); |
| 602 | break; |
Mark Brown | a2495bc | 2011-06-02 19:18:55 +0100 | [diff] [blame] | 603 | } |
Mark Brown | 9e50108 | 2010-01-29 18:20:29 +0000 | [diff] [blame] | 604 | break; |
Mark Brown | 462835e | 2012-01-21 12:11:53 +0000 | [diff] [blame] | 605 | |
| 606 | case WM8958: |
| 607 | switch (wm8994->revision) { |
| 608 | case 0: |
| 609 | regmap_patch = wm8958_reva_patch; |
| 610 | patch_regs = ARRAY_SIZE(wm8958_reva_patch); |
| 611 | break; |
| 612 | default: |
| 613 | break; |
| 614 | } |
| 615 | break; |
| 616 | |
Mark Brown | 443e67e | 2011-11-30 16:51:04 +0000 | [diff] [blame] | 617 | case WM1811: |
| 618 | /* Revision C did not change the relevant layer */ |
Mark Brown | 7ed5849 | 2011-12-01 13:55:49 +0000 | [diff] [blame] | 619 | if (wm8994->revision > 1) |
| 620 | wm8994->revision++; |
Mark Brown | d54e17f | 2012-11-27 15:23:30 +0000 | [diff] [blame] | 621 | |
| 622 | regmap_patch = wm1811_reva_patch; |
| 623 | patch_regs = ARRAY_SIZE(wm1811_reva_patch); |
Mark Brown | 443e67e | 2011-11-30 16:51:04 +0000 | [diff] [blame] | 624 | break; |
Mark Brown | 462835e | 2012-01-21 12:11:53 +0000 | [diff] [blame] | 625 | |
Mark Brown | 9e50108 | 2010-01-29 18:20:29 +0000 | [diff] [blame] | 626 | default: |
Mark Brown | 9e50108 | 2010-01-29 18:20:29 +0000 | [diff] [blame] | 627 | break; |
| 628 | } |
| 629 | |
Mark Brown | cc7a727 | 2012-05-07 10:03:22 +0100 | [diff] [blame] | 630 | dev_info(wm8994->dev, "%s revision %c CUST_ID %02x\n", devname, |
| 631 | 'A' + wm8994->revision, wm8994->cust_id); |
Mark Brown | 9e50108 | 2010-01-29 18:20:29 +0000 | [diff] [blame] | 632 | |
Mark Brown | 3469789 | 2011-12-03 17:10:32 +0000 | [diff] [blame] | 633 | switch (wm8994->type) { |
| 634 | case WM1811: |
| 635 | regmap_config = &wm1811_regmap_config; |
| 636 | break; |
| 637 | case WM8994: |
| 638 | regmap_config = &wm8994_regmap_config; |
| 639 | break; |
| 640 | case WM8958: |
| 641 | regmap_config = &wm8958_regmap_config; |
| 642 | break; |
| 643 | default: |
| 644 | dev_err(wm8994->dev, "Unknown device type %d\n", wm8994->type); |
| 645 | return -EINVAL; |
| 646 | } |
| 647 | |
| 648 | ret = regmap_reinit_cache(wm8994->regmap, regmap_config); |
| 649 | if (ret != 0) { |
| 650 | dev_err(wm8994->dev, "Failed to reinit register cache: %d\n", |
| 651 | ret); |
| 652 | return ret; |
| 653 | } |
Mark Brown | 9e50108 | 2010-01-29 18:20:29 +0000 | [diff] [blame] | 654 | |
Mark Brown | 462835e | 2012-01-21 12:11:53 +0000 | [diff] [blame] | 655 | if (regmap_patch) { |
| 656 | ret = regmap_register_patch(wm8994->regmap, regmap_patch, |
| 657 | patch_regs); |
| 658 | if (ret != 0) { |
| 659 | dev_err(wm8994->dev, "Failed to register patch: %d\n", |
| 660 | ret); |
Mark Brown | 9db4249 | 2012-01-30 20:06:05 +0000 | [diff] [blame] | 661 | goto err; |
Mark Brown | 462835e | 2012-01-21 12:11:53 +0000 | [diff] [blame] | 662 | } |
| 663 | } |
| 664 | |
Mark Brown | a8a8fc2 | 2012-10-08 11:21:09 +0900 | [diff] [blame] | 665 | wm8994->irq_base = pdata->irq_base; |
| 666 | wm8994->gpio_base = pdata->gpio_base; |
Mark Brown | 9e50108 | 2010-01-29 18:20:29 +0000 | [diff] [blame] | 667 | |
Mark Brown | a8a8fc2 | 2012-10-08 11:21:09 +0900 | [diff] [blame] | 668 | /* GPIO configuration is only applied if it's non-zero */ |
| 669 | for (i = 0; i < ARRAY_SIZE(pdata->gpio_defaults); i++) { |
| 670 | if (pdata->gpio_defaults[i]) { |
| 671 | wm8994_set_bits(wm8994, WM8994_GPIO_1 + i, |
| 672 | 0xffff, pdata->gpio_defaults[i]); |
Mark Brown | 9e50108 | 2010-01-29 18:20:29 +0000 | [diff] [blame] | 673 | } |
| 674 | } |
| 675 | |
Mark Brown | a8a8fc2 | 2012-10-08 11:21:09 +0900 | [diff] [blame] | 676 | wm8994->ldo_ena_always_driven = pdata->ldo_ena_always_driven; |
| 677 | |
| 678 | if (pdata->spkmode_pu) |
| 679 | pulls |= WM8994_SPKMODE_PU; |
| 680 | |
Mark Brown | 26c34c2 | 2011-11-03 13:20:38 +0000 | [diff] [blame] | 681 | /* Disable unneeded pulls */ |
Mark Brown | 881de67 | 2011-08-22 15:43:55 +0200 | [diff] [blame] | 682 | wm8994_set_bits(wm8994, WM8994_PULL_CONTROL_2, |
Mark Brown | 26c34c2 | 2011-11-03 13:20:38 +0000 | [diff] [blame] | 683 | WM8994_LDO1ENA_PD | WM8994_LDO2ENA_PD | |
| 684 | WM8994_SPKMODE_PU | WM8994_CSNADDR_PD, |
| 685 | pulls); |
Mark Brown | 881de67 | 2011-08-22 15:43:55 +0200 | [diff] [blame] | 686 | |
Mark Brown | 9e50108 | 2010-01-29 18:20:29 +0000 | [diff] [blame] | 687 | /* In some system designs where the regulators are not in use, |
| 688 | * we can achieve a small reduction in leakage currents by |
| 689 | * floating LDO outputs. This bit makes no difference if the |
| 690 | * LDOs are enabled, it only affects cases where the LDOs were |
| 691 | * in operation and are then disabled. |
| 692 | */ |
| 693 | for (i = 0; i < WM8994_NUM_LDO_REGS; i++) { |
| 694 | if (wm8994_ldo_in_use(pdata, i)) |
| 695 | wm8994_set_bits(wm8994, WM8994_LDO_1 + i, |
| 696 | WM8994_LDO1_DISCH, WM8994_LDO1_DISCH); |
| 697 | else |
| 698 | wm8994_set_bits(wm8994, WM8994_LDO_1 + i, |
| 699 | WM8994_LDO1_DISCH, 0); |
| 700 | } |
| 701 | |
Mark Brown | c9fbf7e | 2010-03-26 16:49:15 +0000 | [diff] [blame] | 702 | wm8994_irq_init(wm8994); |
| 703 | |
Mark Brown | 9e50108 | 2010-01-29 18:20:29 +0000 | [diff] [blame] | 704 | ret = mfd_add_devices(wm8994->dev, -1, |
| 705 | wm8994_devs, ARRAY_SIZE(wm8994_devs), |
Mark Brown | 55692af | 2012-09-11 15:16:36 +0800 | [diff] [blame] | 706 | NULL, 0, NULL); |
Mark Brown | 9e50108 | 2010-01-29 18:20:29 +0000 | [diff] [blame] | 707 | if (ret != 0) { |
| 708 | dev_err(wm8994->dev, "Failed to add children: %d\n", ret); |
Mark Brown | c9fbf7e | 2010-03-26 16:49:15 +0000 | [diff] [blame] | 709 | goto err_irq; |
Mark Brown | 9e50108 | 2010-01-29 18:20:29 +0000 | [diff] [blame] | 710 | } |
| 711 | |
Mark Brown | d450f19 | 2010-11-26 17:19:35 +0000 | [diff] [blame] | 712 | pm_runtime_enable(wm8994->dev); |
Mark Brown | ee67b0c | 2012-02-06 18:47:37 +0000 | [diff] [blame] | 713 | pm_runtime_idle(wm8994->dev); |
Mark Brown | d450f19 | 2010-11-26 17:19:35 +0000 | [diff] [blame] | 714 | |
Mark Brown | 9e50108 | 2010-01-29 18:20:29 +0000 | [diff] [blame] | 715 | return 0; |
| 716 | |
Mark Brown | c9fbf7e | 2010-03-26 16:49:15 +0000 | [diff] [blame] | 717 | err_irq: |
| 718 | wm8994_irq_exit(wm8994); |
Mark Brown | 9e50108 | 2010-01-29 18:20:29 +0000 | [diff] [blame] | 719 | err_enable: |
Mark Brown | 559e0df | 2010-08-31 19:25:12 +0100 | [diff] [blame] | 720 | regulator_bulk_disable(wm8994->num_supplies, |
Mark Brown | 9e50108 | 2010-01-29 18:20:29 +0000 | [diff] [blame] | 721 | wm8994->supplies); |
Mark Brown | 9db4249 | 2012-01-30 20:06:05 +0000 | [diff] [blame] | 722 | err: |
Mark Brown | 9e50108 | 2010-01-29 18:20:29 +0000 | [diff] [blame] | 723 | mfd_remove_devices(wm8994->dev); |
Mark Brown | 9e50108 | 2010-01-29 18:20:29 +0000 | [diff] [blame] | 724 | return ret; |
| 725 | } |
| 726 | |
Bill Pemberton | 4740f73 | 2012-11-19 13:26:01 -0500 | [diff] [blame] | 727 | static void wm8994_device_exit(struct wm8994 *wm8994) |
Mark Brown | 9e50108 | 2010-01-29 18:20:29 +0000 | [diff] [blame] | 728 | { |
Mark Brown | d450f19 | 2010-11-26 17:19:35 +0000 | [diff] [blame] | 729 | pm_runtime_disable(wm8994->dev); |
Mark Brown | 9e50108 | 2010-01-29 18:20:29 +0000 | [diff] [blame] | 730 | mfd_remove_devices(wm8994->dev); |
Mark Brown | c9fbf7e | 2010-03-26 16:49:15 +0000 | [diff] [blame] | 731 | wm8994_irq_exit(wm8994); |
Mark Brown | 559e0df | 2010-08-31 19:25:12 +0100 | [diff] [blame] | 732 | regulator_bulk_disable(wm8994->num_supplies, |
Mark Brown | 9e50108 | 2010-01-29 18:20:29 +0000 | [diff] [blame] | 733 | wm8994->supplies); |
Mark Brown | 9e50108 | 2010-01-29 18:20:29 +0000 | [diff] [blame] | 734 | } |
| 735 | |
Mark Brown | cf763c2 | 2011-11-22 18:22:29 +0000 | [diff] [blame] | 736 | static const struct of_device_id wm8994_of_match[] = { |
Mark Brown | 39aa3b5 | 2013-04-11 18:11:50 +0100 | [diff] [blame] | 737 | { .compatible = "wlf,wm1811", .data = (void *)WM1811 }, |
| 738 | { .compatible = "wlf,wm8994", .data = (void *)WM8994 }, |
| 739 | { .compatible = "wlf,wm8958", .data = (void *)WM8958 }, |
Mark Brown | cf763c2 | 2011-11-22 18:22:29 +0000 | [diff] [blame] | 740 | { } |
| 741 | }; |
| 742 | MODULE_DEVICE_TABLE(of, wm8994_of_match); |
| 743 | |
Bill Pemberton | f791be4 | 2012-11-19 13:23:04 -0500 | [diff] [blame] | 744 | static int wm8994_i2c_probe(struct i2c_client *i2c, |
Mark Brown | 027d676 | 2012-02-17 15:57:01 -0800 | [diff] [blame] | 745 | const struct i2c_device_id *id) |
Mark Brown | 9e50108 | 2010-01-29 18:20:29 +0000 | [diff] [blame] | 746 | { |
Mark Brown | 20fb277 | 2013-04-11 18:11:51 +0100 | [diff] [blame] | 747 | const struct of_device_id *of_id; |
Mark Brown | 9e50108 | 2010-01-29 18:20:29 +0000 | [diff] [blame] | 748 | struct wm8994 *wm8994; |
Mark Brown | d6c645fc | 2011-06-17 13:02:27 +0100 | [diff] [blame] | 749 | int ret; |
Mark Brown | 9e50108 | 2010-01-29 18:20:29 +0000 | [diff] [blame] | 750 | |
Mark Brown | 2fa3349 | 2011-10-25 13:45:40 +0200 | [diff] [blame] | 751 | wm8994 = devm_kzalloc(&i2c->dev, sizeof(struct wm8994), GFP_KERNEL); |
Axel Lin | d0a1169 | 2010-08-09 14:52:16 +0800 | [diff] [blame] | 752 | if (wm8994 == NULL) |
Mark Brown | 9e50108 | 2010-01-29 18:20:29 +0000 | [diff] [blame] | 753 | return -ENOMEM; |
Mark Brown | 9e50108 | 2010-01-29 18:20:29 +0000 | [diff] [blame] | 754 | |
| 755 | i2c_set_clientdata(i2c, wm8994); |
| 756 | wm8994->dev = &i2c->dev; |
Mark Brown | c9fbf7e | 2010-03-26 16:49:15 +0000 | [diff] [blame] | 757 | wm8994->irq = i2c->irq; |
Mark Brown | 20fb277 | 2013-04-11 18:11:51 +0100 | [diff] [blame] | 758 | |
| 759 | if (i2c->dev.of_node) { |
| 760 | of_id = of_match_device(wm8994_of_match, &i2c->dev); |
| 761 | if (of_id) |
| 762 | wm8994->type = (int)of_id->data; |
| 763 | } else { |
| 764 | wm8994->type = id->driver_data; |
| 765 | } |
Mark Brown | 9e50108 | 2010-01-29 18:20:29 +0000 | [diff] [blame] | 766 | |
Mark Brown | 9db4249 | 2012-01-30 20:06:05 +0000 | [diff] [blame] | 767 | wm8994->regmap = devm_regmap_init_i2c(i2c, &wm8994_base_regmap_config); |
Mark Brown | d6c645fc | 2011-06-17 13:02:27 +0100 | [diff] [blame] | 768 | if (IS_ERR(wm8994->regmap)) { |
| 769 | ret = PTR_ERR(wm8994->regmap); |
| 770 | dev_err(wm8994->dev, "Failed to allocate register map: %d\n", |
| 771 | ret); |
Mark Brown | d6c645fc | 2011-06-17 13:02:27 +0100 | [diff] [blame] | 772 | return ret; |
| 773 | } |
| 774 | |
Mark Brown | 559e0df | 2010-08-31 19:25:12 +0100 | [diff] [blame] | 775 | return wm8994_device_init(wm8994, i2c->irq); |
Mark Brown | 9e50108 | 2010-01-29 18:20:29 +0000 | [diff] [blame] | 776 | } |
| 777 | |
Bill Pemberton | 4740f73 | 2012-11-19 13:26:01 -0500 | [diff] [blame] | 778 | static int wm8994_i2c_remove(struct i2c_client *i2c) |
Mark Brown | 9e50108 | 2010-01-29 18:20:29 +0000 | [diff] [blame] | 779 | { |
| 780 | struct wm8994 *wm8994 = i2c_get_clientdata(i2c); |
| 781 | |
| 782 | wm8994_device_exit(wm8994); |
| 783 | |
| 784 | return 0; |
| 785 | } |
| 786 | |
Mark Brown | 9e50108 | 2010-01-29 18:20:29 +0000 | [diff] [blame] | 787 | static const struct i2c_device_id wm8994_i2c_id[] = { |
Mark Brown | b1f43bf | 2011-05-24 17:35:40 +0800 | [diff] [blame] | 788 | { "wm1811", WM1811 }, |
Mark Brown | 71d1718 | 2011-11-30 20:16:42 +0000 | [diff] [blame] | 789 | { "wm1811a", WM1811 }, |
Mark Brown | 559e0df | 2010-08-31 19:25:12 +0100 | [diff] [blame] | 790 | { "wm8994", WM8994 }, |
| 791 | { "wm8958", WM8958 }, |
Mark Brown | 9e50108 | 2010-01-29 18:20:29 +0000 | [diff] [blame] | 792 | { } |
| 793 | }; |
| 794 | MODULE_DEVICE_TABLE(i2c, wm8994_i2c_id); |
| 795 | |
Mark Brown | 6394678 | 2013-03-22 12:40:22 +0100 | [diff] [blame] | 796 | static const struct dev_pm_ops wm8994_pm_ops = { |
| 797 | SET_RUNTIME_PM_OPS(wm8994_suspend, wm8994_resume, NULL) |
| 798 | }; |
Mark Brown | d450f19 | 2010-11-26 17:19:35 +0000 | [diff] [blame] | 799 | |
Mark Brown | 9e50108 | 2010-01-29 18:20:29 +0000 | [diff] [blame] | 800 | static struct i2c_driver wm8994_i2c_driver = { |
| 801 | .driver = { |
Mark Brown | d450f19 | 2010-11-26 17:19:35 +0000 | [diff] [blame] | 802 | .name = "wm8994", |
| 803 | .owner = THIS_MODULE, |
| 804 | .pm = &wm8994_pm_ops, |
Mark Brown | 20fb277 | 2013-04-11 18:11:51 +0100 | [diff] [blame] | 805 | .of_match_table = of_match_ptr(wm8994_of_match), |
Mark Brown | 9e50108 | 2010-01-29 18:20:29 +0000 | [diff] [blame] | 806 | }, |
| 807 | .probe = wm8994_i2c_probe, |
Bill Pemberton | 8444921 | 2012-11-19 13:20:24 -0500 | [diff] [blame] | 808 | .remove = wm8994_i2c_remove, |
Mark Brown | 9e50108 | 2010-01-29 18:20:29 +0000 | [diff] [blame] | 809 | .id_table = wm8994_i2c_id, |
| 810 | }; |
| 811 | |
Mark Brown | ceb57d2 | 2012-05-07 10:03:23 +0100 | [diff] [blame] | 812 | module_i2c_driver(wm8994_i2c_driver); |
Mark Brown | 9e50108 | 2010-01-29 18:20:29 +0000 | [diff] [blame] | 813 | |
| 814 | MODULE_DESCRIPTION("Core support for the WM8994 audio CODEC"); |
| 815 | MODULE_LICENSE("GPL"); |
| 816 | MODULE_AUTHOR("Mark Brown <broonie@opensource.wolfsonmicro.com>"); |