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 |
Mark Brown | ebe38f8 | 2013-07-17 13:16:09 +0100 | [diff] [blame] | 204 | * still active for accessory detect. */ |
Mark Brown | 5f40c6b | 2011-08-13 14:37:48 +0900 | [diff] [blame] | 205 | switch (wm8994->type) { |
| 206 | case WM8958: |
Mark Brown | b5488b6 | 2011-11-04 23:14:46 +0000 | [diff] [blame] | 207 | case WM1811: |
Mark Brown | 5f40c6b | 2011-08-13 14:37:48 +0900 | [diff] [blame] | 208 | ret = wm8994_reg_read(wm8994, WM8958_MIC_DETECT_1); |
| 209 | if (ret < 0) { |
| 210 | dev_err(dev, "Failed to read power status: %d\n", ret); |
| 211 | } else if (ret & WM8958_MICD_ENA) { |
| 212 | dev_dbg(dev, "CODEC still active, ignoring suspend\n"); |
| 213 | return 0; |
| 214 | } |
| 215 | break; |
| 216 | default: |
| 217 | break; |
| 218 | } |
| 219 | |
Mark Brown | 881de67 | 2011-08-22 15:43:55 +0200 | [diff] [blame] | 220 | /* Disable LDO pulldowns while the device is suspended if we |
| 221 | * don't know that something will be driving them. */ |
| 222 | if (!wm8994->ldo_ena_always_driven) |
| 223 | wm8994_set_bits(wm8994, WM8994_PULL_CONTROL_2, |
| 224 | WM8994_LDO1ENA_PD | WM8994_LDO2ENA_PD, |
| 225 | WM8994_LDO1ENA_PD | WM8994_LDO2ENA_PD); |
| 226 | |
Mark Brown | f40dff9 | 2011-02-21 18:30:31 +0000 | [diff] [blame] | 227 | /* Explicitly put the device into reset in case regulators |
| 228 | * don't get disabled in order to ensure consistent restart. |
| 229 | */ |
Mark Brown | be79cf2 | 2011-10-25 13:25:43 +0200 | [diff] [blame] | 230 | wm8994_reg_write(wm8994, WM8994_SOFTWARE_RESET, |
| 231 | wm8994_reg_read(wm8994, WM8994_SOFTWARE_RESET)); |
Mark Brown | f40dff9 | 2011-02-21 18:30:31 +0000 | [diff] [blame] | 232 | |
Mark Brown | ed393dc | 2012-06-29 14:55:39 +0100 | [diff] [blame] | 233 | regcache_mark_dirty(wm8994->regmap); |
| 234 | |
Chris Rattray | 78a27cd | 2012-06-12 00:43:35 +0800 | [diff] [blame] | 235 | /* Restore GPIO registers to prevent problems with mismatched |
| 236 | * pin configurations. |
| 237 | */ |
Mark Brown | ed393dc | 2012-06-29 14:55:39 +0100 | [diff] [blame] | 238 | ret = regcache_sync_region(wm8994->regmap, WM8994_GPIO_1, |
| 239 | WM8994_GPIO_11); |
Chris Rattray | 78a27cd | 2012-06-12 00:43:35 +0800 | [diff] [blame] | 240 | if (ret != 0) |
| 241 | dev_err(dev, "Failed to restore GPIO registers: %d\n", ret); |
| 242 | |
Mark Brown | 1a2017b | 2012-06-29 14:55:40 +0100 | [diff] [blame] | 243 | /* In case one of the GPIOs is used as a wake input. */ |
| 244 | ret = regcache_sync_region(wm8994->regmap, |
| 245 | WM8994_INTERRUPT_STATUS_1_MASK, |
| 246 | WM8994_INTERRUPT_STATUS_1_MASK); |
| 247 | if (ret != 0) |
| 248 | dev_err(dev, "Failed to restore interrupt mask: %d\n", ret); |
| 249 | |
Mark Brown | 3befc92 | 2012-01-09 00:36:42 -0800 | [diff] [blame] | 250 | regcache_cache_only(wm8994->regmap, true); |
Mark Brown | 77bd70e | 2011-02-04 14:57:43 +0000 | [diff] [blame] | 251 | wm8994->suspended = true; |
| 252 | |
Mark Brown | 559e0df | 2010-08-31 19:25:12 +0100 | [diff] [blame] | 253 | ret = regulator_bulk_disable(wm8994->num_supplies, |
Mark Brown | 9e50108 | 2010-01-29 18:20:29 +0000 | [diff] [blame] | 254 | wm8994->supplies); |
| 255 | if (ret != 0) { |
| 256 | dev_err(dev, "Failed to disable supplies: %d\n", ret); |
| 257 | return ret; |
| 258 | } |
| 259 | |
| 260 | return 0; |
| 261 | } |
| 262 | |
Mark Brown | d450f19 | 2010-11-26 17:19:35 +0000 | [diff] [blame] | 263 | static int wm8994_resume(struct device *dev) |
Mark Brown | 9e50108 | 2010-01-29 18:20:29 +0000 | [diff] [blame] | 264 | { |
| 265 | struct wm8994 *wm8994 = dev_get_drvdata(dev); |
Mark Brown | c3f1386 | 2011-10-25 14:23:53 +0200 | [diff] [blame] | 266 | int ret; |
Mark Brown | 9e50108 | 2010-01-29 18:20:29 +0000 | [diff] [blame] | 267 | |
Mark Brown | 77bd70e | 2011-02-04 14:57:43 +0000 | [diff] [blame] | 268 | /* We may have lied to the PM core about suspending */ |
| 269 | if (!wm8994->suspended) |
| 270 | return 0; |
| 271 | |
Mark Brown | 559e0df | 2010-08-31 19:25:12 +0100 | [diff] [blame] | 272 | ret = regulator_bulk_enable(wm8994->num_supplies, |
Mark Brown | 9e50108 | 2010-01-29 18:20:29 +0000 | [diff] [blame] | 273 | wm8994->supplies); |
| 274 | if (ret != 0) { |
| 275 | dev_err(dev, "Failed to enable supplies: %d\n", ret); |
| 276 | return ret; |
| 277 | } |
| 278 | |
Mark Brown | 3befc92 | 2012-01-09 00:36:42 -0800 | [diff] [blame] | 279 | regcache_cache_only(wm8994->regmap, false); |
Mark Brown | c3f1386 | 2011-10-25 14:23:53 +0200 | [diff] [blame] | 280 | ret = regcache_sync(wm8994->regmap); |
| 281 | if (ret != 0) { |
| 282 | dev_err(dev, "Failed to restore register map: %d\n", ret); |
| 283 | goto err_enable; |
Mark Brown | 98ae1cc | 2011-06-07 11:49:42 +0100 | [diff] [blame] | 284 | } |
Mark Brown | c9fbf7e | 2010-03-26 16:49:15 +0000 | [diff] [blame] | 285 | |
Mark Brown | 881de67 | 2011-08-22 15:43:55 +0200 | [diff] [blame] | 286 | /* Disable LDO pulldowns while the device is active */ |
| 287 | wm8994_set_bits(wm8994, WM8994_PULL_CONTROL_2, |
| 288 | WM8994_LDO1ENA_PD | WM8994_LDO2ENA_PD, |
| 289 | 0); |
| 290 | |
Mark Brown | 77bd70e | 2011-02-04 14:57:43 +0000 | [diff] [blame] | 291 | wm8994->suspended = false; |
| 292 | |
Mark Brown | 9e50108 | 2010-01-29 18:20:29 +0000 | [diff] [blame] | 293 | return 0; |
Mark Brown | c3f1386 | 2011-10-25 14:23:53 +0200 | [diff] [blame] | 294 | |
| 295 | err_enable: |
| 296 | regulator_bulk_disable(wm8994->num_supplies, wm8994->supplies); |
| 297 | |
| 298 | return ret; |
Mark Brown | 9e50108 | 2010-01-29 18:20:29 +0000 | [diff] [blame] | 299 | } |
| 300 | #endif |
| 301 | |
| 302 | #ifdef CONFIG_REGULATOR |
| 303 | static int wm8994_ldo_in_use(struct wm8994_pdata *pdata, int ldo) |
| 304 | { |
| 305 | struct wm8994_ldo_pdata *ldo_pdata; |
| 306 | |
| 307 | if (!pdata) |
| 308 | return 0; |
| 309 | |
| 310 | ldo_pdata = &pdata->ldo[ldo]; |
| 311 | |
| 312 | if (!ldo_pdata->init_data) |
| 313 | return 0; |
| 314 | |
| 315 | return ldo_pdata->init_data->num_consumer_supplies != 0; |
| 316 | } |
| 317 | #else |
| 318 | static int wm8994_ldo_in_use(struct wm8994_pdata *pdata, int ldo) |
| 319 | { |
| 320 | return 0; |
| 321 | } |
| 322 | #endif |
| 323 | |
Bill Pemberton | a73e5df | 2012-11-19 13:25:09 -0500 | [diff] [blame] | 324 | static const struct reg_default wm8994_revc_patch[] = { |
Mark Brown | 462835e | 2012-01-21 12:11:53 +0000 | [diff] [blame] | 325 | { 0x102, 0x3 }, |
| 326 | { 0x56, 0x3 }, |
| 327 | { 0x817, 0x0 }, |
| 328 | { 0x102, 0x0 }, |
| 329 | }; |
| 330 | |
Bill Pemberton | a73e5df | 2012-11-19 13:25:09 -0500 | [diff] [blame] | 331 | static const struct reg_default wm8958_reva_patch[] = { |
Mark Brown | 462835e | 2012-01-21 12:11:53 +0000 | [diff] [blame] | 332 | { 0x102, 0x3 }, |
| 333 | { 0xcb, 0x81 }, |
| 334 | { 0x817, 0x0 }, |
| 335 | { 0x102, 0x0 }, |
| 336 | }; |
| 337 | |
Bill Pemberton | a73e5df | 2012-11-19 13:25:09 -0500 | [diff] [blame] | 338 | static const struct reg_default wm1811_reva_patch[] = { |
Mark Brown | 462835e | 2012-01-21 12:11:53 +0000 | [diff] [blame] | 339 | { 0x102, 0x3 }, |
Mark Brown | 9282a7b | 2012-08-23 16:10:29 +0100 | [diff] [blame] | 340 | { 0x56, 0xc07 }, |
Mark Brown | 462835e | 2012-01-21 12:11:53 +0000 | [diff] [blame] | 341 | { 0x5d, 0x7e }, |
| 342 | { 0x5e, 0x0 }, |
| 343 | { 0x102, 0x0 }, |
| 344 | }; |
| 345 | |
Mark Brown | 20fb277 | 2013-04-11 18:11:51 +0100 | [diff] [blame] | 346 | #ifdef CONFIG_OF |
| 347 | static int wm8994_set_pdata_from_of(struct wm8994 *wm8994) |
| 348 | { |
| 349 | struct device_node *np = wm8994->dev->of_node; |
| 350 | struct wm8994_pdata *pdata = &wm8994->pdata; |
| 351 | int i; |
| 352 | |
| 353 | if (!np) |
| 354 | return 0; |
| 355 | |
| 356 | if (of_property_read_u32_array(np, "wlf,gpio-cfg", pdata->gpio_defaults, |
| 357 | ARRAY_SIZE(pdata->gpio_defaults)) >= 0) { |
| 358 | for (i = 0; i < ARRAY_SIZE(pdata->gpio_defaults); i++) { |
| 359 | if (wm8994->pdata.gpio_defaults[i] == 0) |
| 360 | pdata->gpio_defaults[i] |
| 361 | = WM8994_CONFIGURE_GPIO; |
| 362 | } |
| 363 | } |
| 364 | |
| 365 | of_property_read_u32_array(np, "wlf,micbias-cfg", pdata->micbias, |
| 366 | ARRAY_SIZE(pdata->micbias)); |
| 367 | |
| 368 | pdata->lineout1_diff = true; |
| 369 | pdata->lineout2_diff = true; |
| 370 | if (of_find_property(np, "wlf,lineout1-se", NULL)) |
| 371 | pdata->lineout1_diff = false; |
| 372 | if (of_find_property(np, "wlf,lineout2-se", NULL)) |
| 373 | pdata->lineout2_diff = false; |
| 374 | |
| 375 | if (of_find_property(np, "wlf,lineout1-feedback", NULL)) |
| 376 | pdata->lineout1fb = true; |
| 377 | if (of_find_property(np, "wlf,lineout2-feedback", NULL)) |
| 378 | pdata->lineout2fb = true; |
| 379 | |
| 380 | if (of_find_property(np, "wlf,ldoena-always-driven", NULL)) |
| 381 | pdata->lineout2fb = true; |
| 382 | |
| 383 | pdata->ldo[0].enable = of_get_named_gpio(np, "wlf,ldo1ena", 0); |
| 384 | if (pdata->ldo[0].enable < 0) |
| 385 | pdata->ldo[0].enable = 0; |
| 386 | |
| 387 | pdata->ldo[1].enable = of_get_named_gpio(np, "wlf,ldo2ena", 0); |
| 388 | if (pdata->ldo[1].enable < 0) |
| 389 | pdata->ldo[1].enable = 0; |
| 390 | |
| 391 | return 0; |
| 392 | } |
| 393 | #else |
| 394 | static int wm8994_set_pdata_from_of(struct wm8994 *wm8994) |
| 395 | { |
| 396 | return 0; |
| 397 | } |
| 398 | #endif |
| 399 | |
Mark Brown | 9e50108 | 2010-01-29 18:20:29 +0000 | [diff] [blame] | 400 | /* |
| 401 | * Instantiate the generic non-control parts of the device. |
| 402 | */ |
Bill Pemberton | f791be4 | 2012-11-19 13:23:04 -0500 | [diff] [blame] | 403 | static int wm8994_device_init(struct wm8994 *wm8994, int irq) |
Mark Brown | 9e50108 | 2010-01-29 18:20:29 +0000 | [diff] [blame] | 404 | { |
Mark Brown | a8a8fc2 | 2012-10-08 11:21:09 +0900 | [diff] [blame] | 405 | struct wm8994_pdata *pdata; |
Mark Brown | 3469789 | 2011-12-03 17:10:32 +0000 | [diff] [blame] | 406 | struct regmap_config *regmap_config; |
Mark Brown | 462835e | 2012-01-21 12:11:53 +0000 | [diff] [blame] | 407 | const struct reg_default *regmap_patch = NULL; |
Mark Brown | 559e0df | 2010-08-31 19:25:12 +0100 | [diff] [blame] | 408 | const char *devname; |
Jingoo Han | 222bc78 | 2013-02-20 11:53:36 +0900 | [diff] [blame] | 409 | int ret, i, patch_regs = 0; |
Mark Brown | 26c34c2 | 2011-11-03 13:20:38 +0000 | [diff] [blame] | 410 | int pulls = 0; |
Mark Brown | 9e50108 | 2010-01-29 18:20:29 +0000 | [diff] [blame] | 411 | |
Mark Brown | a8a8fc2 | 2012-10-08 11:21:09 +0900 | [diff] [blame] | 412 | if (dev_get_platdata(wm8994->dev)) { |
| 413 | pdata = dev_get_platdata(wm8994->dev); |
| 414 | wm8994->pdata = *pdata; |
| 415 | } |
| 416 | pdata = &wm8994->pdata; |
| 417 | |
Mark Brown | 20fb277 | 2013-04-11 18:11:51 +0100 | [diff] [blame] | 418 | ret = wm8994_set_pdata_from_of(wm8994); |
| 419 | if (ret != 0) |
| 420 | return ret; |
| 421 | |
Mark Brown | 9e50108 | 2010-01-29 18:20:29 +0000 | [diff] [blame] | 422 | dev_set_drvdata(wm8994->dev, wm8994); |
| 423 | |
| 424 | /* Add the on-chip regulators first for bootstrapping */ |
| 425 | ret = mfd_add_devices(wm8994->dev, -1, |
| 426 | wm8994_regulator_devs, |
| 427 | ARRAY_SIZE(wm8994_regulator_devs), |
Mark Brown | 55692af | 2012-09-11 15:16:36 +0800 | [diff] [blame] | 428 | NULL, 0, NULL); |
Mark Brown | 9e50108 | 2010-01-29 18:20:29 +0000 | [diff] [blame] | 429 | if (ret != 0) { |
| 430 | dev_err(wm8994->dev, "Failed to add children: %d\n", ret); |
Mark Brown | 9db4249 | 2012-01-30 20:06:05 +0000 | [diff] [blame] | 431 | goto err; |
Mark Brown | 9e50108 | 2010-01-29 18:20:29 +0000 | [diff] [blame] | 432 | } |
| 433 | |
Mark Brown | 559e0df | 2010-08-31 19:25:12 +0100 | [diff] [blame] | 434 | switch (wm8994->type) { |
Mark Brown | b1f43bf | 2011-05-24 17:35:40 +0800 | [diff] [blame] | 435 | case WM1811: |
| 436 | wm8994->num_supplies = ARRAY_SIZE(wm1811_main_supplies); |
| 437 | break; |
Mark Brown | 559e0df | 2010-08-31 19:25:12 +0100 | [diff] [blame] | 438 | case WM8994: |
| 439 | wm8994->num_supplies = ARRAY_SIZE(wm8994_main_supplies); |
| 440 | break; |
| 441 | case WM8958: |
| 442 | wm8994->num_supplies = ARRAY_SIZE(wm8958_main_supplies); |
| 443 | break; |
| 444 | default: |
| 445 | BUG(); |
Mark Brown | 9db4249 | 2012-01-30 20:06:05 +0000 | [diff] [blame] | 446 | goto err; |
Mark Brown | 559e0df | 2010-08-31 19:25:12 +0100 | [diff] [blame] | 447 | } |
| 448 | |
Mark Brown | 2fa3349 | 2011-10-25 13:45:40 +0200 | [diff] [blame] | 449 | wm8994->supplies = devm_kzalloc(wm8994->dev, |
| 450 | sizeof(struct regulator_bulk_data) * |
| 451 | wm8994->num_supplies, GFP_KERNEL); |
Axel Lin | fccbd21 | 2010-08-04 09:44:47 +0800 | [diff] [blame] | 452 | if (!wm8994->supplies) { |
| 453 | ret = -ENOMEM; |
Mark Brown | 9db4249 | 2012-01-30 20:06:05 +0000 | [diff] [blame] | 454 | goto err; |
Axel Lin | fccbd21 | 2010-08-04 09:44:47 +0800 | [diff] [blame] | 455 | } |
Mark Brown | 9e50108 | 2010-01-29 18:20:29 +0000 | [diff] [blame] | 456 | |
Mark Brown | 559e0df | 2010-08-31 19:25:12 +0100 | [diff] [blame] | 457 | switch (wm8994->type) { |
Mark Brown | b1f43bf | 2011-05-24 17:35:40 +0800 | [diff] [blame] | 458 | case WM1811: |
| 459 | for (i = 0; i < ARRAY_SIZE(wm1811_main_supplies); i++) |
| 460 | wm8994->supplies[i].supply = wm1811_main_supplies[i]; |
| 461 | break; |
Mark Brown | 559e0df | 2010-08-31 19:25:12 +0100 | [diff] [blame] | 462 | case WM8994: |
| 463 | for (i = 0; i < ARRAY_SIZE(wm8994_main_supplies); i++) |
| 464 | wm8994->supplies[i].supply = wm8994_main_supplies[i]; |
| 465 | break; |
| 466 | case WM8958: |
| 467 | for (i = 0; i < ARRAY_SIZE(wm8958_main_supplies); i++) |
| 468 | wm8994->supplies[i].supply = wm8958_main_supplies[i]; |
| 469 | break; |
| 470 | default: |
| 471 | BUG(); |
Mark Brown | 9db4249 | 2012-01-30 20:06:05 +0000 | [diff] [blame] | 472 | goto err; |
Mark Brown | 559e0df | 2010-08-31 19:25:12 +0100 | [diff] [blame] | 473 | } |
| 474 | |
Sachin Kamat | f1c68e4 | 2013-01-08 14:01:22 +0530 | [diff] [blame] | 475 | ret = devm_regulator_bulk_get(wm8994->dev, wm8994->num_supplies, |
Mark Brown | 9e50108 | 2010-01-29 18:20:29 +0000 | [diff] [blame] | 476 | wm8994->supplies); |
| 477 | if (ret != 0) { |
| 478 | dev_err(wm8994->dev, "Failed to get supplies: %d\n", ret); |
Mark Brown | 9db4249 | 2012-01-30 20:06:05 +0000 | [diff] [blame] | 479 | goto err; |
Mark Brown | 9e50108 | 2010-01-29 18:20:29 +0000 | [diff] [blame] | 480 | } |
| 481 | |
Mark Brown | 559e0df | 2010-08-31 19:25:12 +0100 | [diff] [blame] | 482 | ret = regulator_bulk_enable(wm8994->num_supplies, |
Mark Brown | 9e50108 | 2010-01-29 18:20:29 +0000 | [diff] [blame] | 483 | wm8994->supplies); |
| 484 | if (ret != 0) { |
| 485 | dev_err(wm8994->dev, "Failed to enable supplies: %d\n", ret); |
Sachin Kamat | f1c68e4 | 2013-01-08 14:01:22 +0530 | [diff] [blame] | 486 | goto err; |
Mark Brown | 9e50108 | 2010-01-29 18:20:29 +0000 | [diff] [blame] | 487 | } |
| 488 | |
| 489 | ret = wm8994_reg_read(wm8994, WM8994_SOFTWARE_RESET); |
| 490 | if (ret < 0) { |
| 491 | dev_err(wm8994->dev, "Failed to read ID register\n"); |
| 492 | goto err_enable; |
| 493 | } |
Mark Brown | 559e0df | 2010-08-31 19:25:12 +0100 | [diff] [blame] | 494 | switch (ret) { |
Mark Brown | b1f43bf | 2011-05-24 17:35:40 +0800 | [diff] [blame] | 495 | case 0x1811: |
| 496 | devname = "WM1811"; |
| 497 | if (wm8994->type != WM1811) |
| 498 | dev_warn(wm8994->dev, "Device registered as type %d\n", |
| 499 | wm8994->type); |
| 500 | wm8994->type = WM1811; |
| 501 | break; |
Mark Brown | 559e0df | 2010-08-31 19:25:12 +0100 | [diff] [blame] | 502 | case 0x8994: |
| 503 | devname = "WM8994"; |
| 504 | if (wm8994->type != WM8994) |
| 505 | dev_warn(wm8994->dev, "Device registered as type %d\n", |
| 506 | wm8994->type); |
| 507 | wm8994->type = WM8994; |
| 508 | break; |
| 509 | case 0x8958: |
| 510 | devname = "WM8958"; |
| 511 | if (wm8994->type != WM8958) |
| 512 | dev_warn(wm8994->dev, "Device registered as type %d\n", |
| 513 | wm8994->type); |
| 514 | wm8994->type = WM8958; |
| 515 | break; |
| 516 | default: |
Mark Brown | 9e50108 | 2010-01-29 18:20:29 +0000 | [diff] [blame] | 517 | dev_err(wm8994->dev, "Device is not a WM8994, ID is %x\n", |
| 518 | ret); |
| 519 | ret = -EINVAL; |
| 520 | goto err_enable; |
| 521 | } |
| 522 | |
| 523 | ret = wm8994_reg_read(wm8994, WM8994_CHIP_REVISION); |
| 524 | if (ret < 0) { |
| 525 | dev_err(wm8994->dev, "Failed to read revision register: %d\n", |
| 526 | ret); |
| 527 | goto err_enable; |
| 528 | } |
Mark Brown | cc7a727 | 2012-05-07 10:03:22 +0100 | [diff] [blame] | 529 | wm8994->revision = ret & WM8994_CHIP_REV_MASK; |
| 530 | wm8994->cust_id = (ret & WM8994_CUST_ID_MASK) >> WM8994_CUST_ID_SHIFT; |
Mark Brown | 9e50108 | 2010-01-29 18:20:29 +0000 | [diff] [blame] | 531 | |
Mark Brown | a2495bc | 2011-06-02 19:18:55 +0100 | [diff] [blame] | 532 | switch (wm8994->type) { |
| 533 | case WM8994: |
Mark Brown | 7ed5849 | 2011-12-01 13:55:49 +0000 | [diff] [blame] | 534 | switch (wm8994->revision) { |
Mark Brown | a2495bc | 2011-06-02 19:18:55 +0100 | [diff] [blame] | 535 | case 0: |
| 536 | case 1: |
Mark Brown | 559e0df | 2010-08-31 19:25:12 +0100 | [diff] [blame] | 537 | dev_warn(wm8994->dev, |
| 538 | "revision %c not fully supported\n", |
Mark Brown | 7ed5849 | 2011-12-01 13:55:49 +0000 | [diff] [blame] | 539 | 'A' + wm8994->revision); |
Mark Brown | a2495bc | 2011-06-02 19:18:55 +0100 | [diff] [blame] | 540 | break; |
Mark Brown | 462835e | 2012-01-21 12:11:53 +0000 | [diff] [blame] | 541 | case 2: |
| 542 | case 3: |
Mark Brown | d54e17f | 2012-11-27 15:23:30 +0000 | [diff] [blame] | 543 | default: |
Mark Brown | 462835e | 2012-01-21 12:11:53 +0000 | [diff] [blame] | 544 | regmap_patch = wm8994_revc_patch; |
| 545 | patch_regs = ARRAY_SIZE(wm8994_revc_patch); |
| 546 | break; |
Mark Brown | a2495bc | 2011-06-02 19:18:55 +0100 | [diff] [blame] | 547 | } |
Mark Brown | 9e50108 | 2010-01-29 18:20:29 +0000 | [diff] [blame] | 548 | break; |
Mark Brown | 462835e | 2012-01-21 12:11:53 +0000 | [diff] [blame] | 549 | |
| 550 | case WM8958: |
| 551 | switch (wm8994->revision) { |
| 552 | case 0: |
| 553 | regmap_patch = wm8958_reva_patch; |
| 554 | patch_regs = ARRAY_SIZE(wm8958_reva_patch); |
| 555 | break; |
| 556 | default: |
| 557 | break; |
| 558 | } |
| 559 | break; |
| 560 | |
Mark Brown | 443e67e | 2011-11-30 16:51:04 +0000 | [diff] [blame] | 561 | case WM1811: |
| 562 | /* Revision C did not change the relevant layer */ |
Mark Brown | 7ed5849 | 2011-12-01 13:55:49 +0000 | [diff] [blame] | 563 | if (wm8994->revision > 1) |
| 564 | wm8994->revision++; |
Mark Brown | d54e17f | 2012-11-27 15:23:30 +0000 | [diff] [blame] | 565 | |
| 566 | regmap_patch = wm1811_reva_patch; |
| 567 | patch_regs = ARRAY_SIZE(wm1811_reva_patch); |
Mark Brown | 443e67e | 2011-11-30 16:51:04 +0000 | [diff] [blame] | 568 | break; |
Mark Brown | 462835e | 2012-01-21 12:11:53 +0000 | [diff] [blame] | 569 | |
Mark Brown | 9e50108 | 2010-01-29 18:20:29 +0000 | [diff] [blame] | 570 | default: |
Mark Brown | 9e50108 | 2010-01-29 18:20:29 +0000 | [diff] [blame] | 571 | break; |
| 572 | } |
| 573 | |
Mark Brown | cc7a727 | 2012-05-07 10:03:22 +0100 | [diff] [blame] | 574 | dev_info(wm8994->dev, "%s revision %c CUST_ID %02x\n", devname, |
| 575 | 'A' + wm8994->revision, wm8994->cust_id); |
Mark Brown | 9e50108 | 2010-01-29 18:20:29 +0000 | [diff] [blame] | 576 | |
Mark Brown | 3469789 | 2011-12-03 17:10:32 +0000 | [diff] [blame] | 577 | switch (wm8994->type) { |
| 578 | case WM1811: |
| 579 | regmap_config = &wm1811_regmap_config; |
| 580 | break; |
| 581 | case WM8994: |
| 582 | regmap_config = &wm8994_regmap_config; |
| 583 | break; |
| 584 | case WM8958: |
| 585 | regmap_config = &wm8958_regmap_config; |
| 586 | break; |
| 587 | default: |
| 588 | dev_err(wm8994->dev, "Unknown device type %d\n", wm8994->type); |
| 589 | return -EINVAL; |
| 590 | } |
| 591 | |
| 592 | ret = regmap_reinit_cache(wm8994->regmap, regmap_config); |
| 593 | if (ret != 0) { |
| 594 | dev_err(wm8994->dev, "Failed to reinit register cache: %d\n", |
| 595 | ret); |
| 596 | return ret; |
| 597 | } |
Mark Brown | 9e50108 | 2010-01-29 18:20:29 +0000 | [diff] [blame] | 598 | |
Mark Brown | f3799e9 | 2013-05-17 13:25:21 +0100 | [diff] [blame] | 599 | /* Explicitly put the device into reset in case regulators |
| 600 | * don't get disabled in order to ensure we know the device |
| 601 | * state. |
| 602 | */ |
| 603 | ret = wm8994_reg_write(wm8994, WM8994_SOFTWARE_RESET, |
| 604 | wm8994_reg_read(wm8994, WM8994_SOFTWARE_RESET)); |
| 605 | if (ret != 0) { |
| 606 | dev_err(wm8994->dev, "Failed to reset device: %d\n", ret); |
| 607 | return ret; |
| 608 | } |
| 609 | |
Mark Brown | 462835e | 2012-01-21 12:11:53 +0000 | [diff] [blame] | 610 | if (regmap_patch) { |
| 611 | ret = regmap_register_patch(wm8994->regmap, regmap_patch, |
| 612 | patch_regs); |
| 613 | if (ret != 0) { |
| 614 | dev_err(wm8994->dev, "Failed to register patch: %d\n", |
| 615 | ret); |
Mark Brown | 9db4249 | 2012-01-30 20:06:05 +0000 | [diff] [blame] | 616 | goto err; |
Mark Brown | 462835e | 2012-01-21 12:11:53 +0000 | [diff] [blame] | 617 | } |
| 618 | } |
| 619 | |
Mark Brown | a8a8fc2 | 2012-10-08 11:21:09 +0900 | [diff] [blame] | 620 | wm8994->irq_base = pdata->irq_base; |
| 621 | wm8994->gpio_base = pdata->gpio_base; |
Mark Brown | 9e50108 | 2010-01-29 18:20:29 +0000 | [diff] [blame] | 622 | |
Mark Brown | a8a8fc2 | 2012-10-08 11:21:09 +0900 | [diff] [blame] | 623 | /* GPIO configuration is only applied if it's non-zero */ |
| 624 | for (i = 0; i < ARRAY_SIZE(pdata->gpio_defaults); i++) { |
| 625 | if (pdata->gpio_defaults[i]) { |
| 626 | wm8994_set_bits(wm8994, WM8994_GPIO_1 + i, |
| 627 | 0xffff, pdata->gpio_defaults[i]); |
Mark Brown | 9e50108 | 2010-01-29 18:20:29 +0000 | [diff] [blame] | 628 | } |
| 629 | } |
| 630 | |
Mark Brown | a8a8fc2 | 2012-10-08 11:21:09 +0900 | [diff] [blame] | 631 | wm8994->ldo_ena_always_driven = pdata->ldo_ena_always_driven; |
| 632 | |
| 633 | if (pdata->spkmode_pu) |
| 634 | pulls |= WM8994_SPKMODE_PU; |
| 635 | |
Mark Brown | 26c34c2 | 2011-11-03 13:20:38 +0000 | [diff] [blame] | 636 | /* Disable unneeded pulls */ |
Mark Brown | 881de67 | 2011-08-22 15:43:55 +0200 | [diff] [blame] | 637 | wm8994_set_bits(wm8994, WM8994_PULL_CONTROL_2, |
Mark Brown | 26c34c2 | 2011-11-03 13:20:38 +0000 | [diff] [blame] | 638 | WM8994_LDO1ENA_PD | WM8994_LDO2ENA_PD | |
| 639 | WM8994_SPKMODE_PU | WM8994_CSNADDR_PD, |
| 640 | pulls); |
Mark Brown | 881de67 | 2011-08-22 15:43:55 +0200 | [diff] [blame] | 641 | |
Mark Brown | 9e50108 | 2010-01-29 18:20:29 +0000 | [diff] [blame] | 642 | /* In some system designs where the regulators are not in use, |
| 643 | * we can achieve a small reduction in leakage currents by |
| 644 | * floating LDO outputs. This bit makes no difference if the |
| 645 | * LDOs are enabled, it only affects cases where the LDOs were |
| 646 | * in operation and are then disabled. |
| 647 | */ |
| 648 | for (i = 0; i < WM8994_NUM_LDO_REGS; i++) { |
| 649 | if (wm8994_ldo_in_use(pdata, i)) |
| 650 | wm8994_set_bits(wm8994, WM8994_LDO_1 + i, |
| 651 | WM8994_LDO1_DISCH, WM8994_LDO1_DISCH); |
| 652 | else |
| 653 | wm8994_set_bits(wm8994, WM8994_LDO_1 + i, |
| 654 | WM8994_LDO1_DISCH, 0); |
| 655 | } |
| 656 | |
Mark Brown | c9fbf7e | 2010-03-26 16:49:15 +0000 | [diff] [blame] | 657 | wm8994_irq_init(wm8994); |
| 658 | |
Mark Brown | 9e50108 | 2010-01-29 18:20:29 +0000 | [diff] [blame] | 659 | ret = mfd_add_devices(wm8994->dev, -1, |
| 660 | wm8994_devs, ARRAY_SIZE(wm8994_devs), |
Mark Brown | 55692af | 2012-09-11 15:16:36 +0800 | [diff] [blame] | 661 | NULL, 0, NULL); |
Mark Brown | 9e50108 | 2010-01-29 18:20:29 +0000 | [diff] [blame] | 662 | if (ret != 0) { |
| 663 | dev_err(wm8994->dev, "Failed to add children: %d\n", ret); |
Mark Brown | c9fbf7e | 2010-03-26 16:49:15 +0000 | [diff] [blame] | 664 | goto err_irq; |
Mark Brown | 9e50108 | 2010-01-29 18:20:29 +0000 | [diff] [blame] | 665 | } |
| 666 | |
Mark Brown | d450f19 | 2010-11-26 17:19:35 +0000 | [diff] [blame] | 667 | pm_runtime_enable(wm8994->dev); |
Mark Brown | ee67b0c | 2012-02-06 18:47:37 +0000 | [diff] [blame] | 668 | pm_runtime_idle(wm8994->dev); |
Mark Brown | d450f19 | 2010-11-26 17:19:35 +0000 | [diff] [blame] | 669 | |
Mark Brown | 9e50108 | 2010-01-29 18:20:29 +0000 | [diff] [blame] | 670 | return 0; |
| 671 | |
Mark Brown | c9fbf7e | 2010-03-26 16:49:15 +0000 | [diff] [blame] | 672 | err_irq: |
| 673 | wm8994_irq_exit(wm8994); |
Mark Brown | 9e50108 | 2010-01-29 18:20:29 +0000 | [diff] [blame] | 674 | err_enable: |
Mark Brown | 559e0df | 2010-08-31 19:25:12 +0100 | [diff] [blame] | 675 | regulator_bulk_disable(wm8994->num_supplies, |
Mark Brown | 9e50108 | 2010-01-29 18:20:29 +0000 | [diff] [blame] | 676 | wm8994->supplies); |
Mark Brown | 9db4249 | 2012-01-30 20:06:05 +0000 | [diff] [blame] | 677 | err: |
Mark Brown | 9e50108 | 2010-01-29 18:20:29 +0000 | [diff] [blame] | 678 | mfd_remove_devices(wm8994->dev); |
Mark Brown | 9e50108 | 2010-01-29 18:20:29 +0000 | [diff] [blame] | 679 | return ret; |
| 680 | } |
| 681 | |
Bill Pemberton | 4740f73 | 2012-11-19 13:26:01 -0500 | [diff] [blame] | 682 | static void wm8994_device_exit(struct wm8994 *wm8994) |
Mark Brown | 9e50108 | 2010-01-29 18:20:29 +0000 | [diff] [blame] | 683 | { |
Mark Brown | d450f19 | 2010-11-26 17:19:35 +0000 | [diff] [blame] | 684 | pm_runtime_disable(wm8994->dev); |
Mark Brown | 9e50108 | 2010-01-29 18:20:29 +0000 | [diff] [blame] | 685 | mfd_remove_devices(wm8994->dev); |
Mark Brown | c9fbf7e | 2010-03-26 16:49:15 +0000 | [diff] [blame] | 686 | wm8994_irq_exit(wm8994); |
Mark Brown | 559e0df | 2010-08-31 19:25:12 +0100 | [diff] [blame] | 687 | regulator_bulk_disable(wm8994->num_supplies, |
Mark Brown | 9e50108 | 2010-01-29 18:20:29 +0000 | [diff] [blame] | 688 | wm8994->supplies); |
Mark Brown | 9e50108 | 2010-01-29 18:20:29 +0000 | [diff] [blame] | 689 | } |
| 690 | |
Mark Brown | cf763c2 | 2011-11-22 18:22:29 +0000 | [diff] [blame] | 691 | static const struct of_device_id wm8994_of_match[] = { |
Mark Brown | 39aa3b5 | 2013-04-11 18:11:50 +0100 | [diff] [blame] | 692 | { .compatible = "wlf,wm1811", .data = (void *)WM1811 }, |
| 693 | { .compatible = "wlf,wm8994", .data = (void *)WM8994 }, |
| 694 | { .compatible = "wlf,wm8958", .data = (void *)WM8958 }, |
Mark Brown | cf763c2 | 2011-11-22 18:22:29 +0000 | [diff] [blame] | 695 | { } |
| 696 | }; |
| 697 | MODULE_DEVICE_TABLE(of, wm8994_of_match); |
| 698 | |
Bill Pemberton | f791be4 | 2012-11-19 13:23:04 -0500 | [diff] [blame] | 699 | static int wm8994_i2c_probe(struct i2c_client *i2c, |
Mark Brown | 027d676 | 2012-02-17 15:57:01 -0800 | [diff] [blame] | 700 | const struct i2c_device_id *id) |
Mark Brown | 9e50108 | 2010-01-29 18:20:29 +0000 | [diff] [blame] | 701 | { |
Mark Brown | 20fb277 | 2013-04-11 18:11:51 +0100 | [diff] [blame] | 702 | const struct of_device_id *of_id; |
Mark Brown | 9e50108 | 2010-01-29 18:20:29 +0000 | [diff] [blame] | 703 | struct wm8994 *wm8994; |
Mark Brown | d6c645fc | 2011-06-17 13:02:27 +0100 | [diff] [blame] | 704 | int ret; |
Mark Brown | 9e50108 | 2010-01-29 18:20:29 +0000 | [diff] [blame] | 705 | |
Mark Brown | 2fa3349 | 2011-10-25 13:45:40 +0200 | [diff] [blame] | 706 | wm8994 = devm_kzalloc(&i2c->dev, sizeof(struct wm8994), GFP_KERNEL); |
Axel Lin | d0a1169 | 2010-08-09 14:52:16 +0800 | [diff] [blame] | 707 | if (wm8994 == NULL) |
Mark Brown | 9e50108 | 2010-01-29 18:20:29 +0000 | [diff] [blame] | 708 | return -ENOMEM; |
Mark Brown | 9e50108 | 2010-01-29 18:20:29 +0000 | [diff] [blame] | 709 | |
| 710 | i2c_set_clientdata(i2c, wm8994); |
| 711 | wm8994->dev = &i2c->dev; |
Mark Brown | c9fbf7e | 2010-03-26 16:49:15 +0000 | [diff] [blame] | 712 | wm8994->irq = i2c->irq; |
Mark Brown | 20fb277 | 2013-04-11 18:11:51 +0100 | [diff] [blame] | 713 | |
| 714 | if (i2c->dev.of_node) { |
| 715 | of_id = of_match_device(wm8994_of_match, &i2c->dev); |
| 716 | if (of_id) |
| 717 | wm8994->type = (int)of_id->data; |
| 718 | } else { |
| 719 | wm8994->type = id->driver_data; |
| 720 | } |
Mark Brown | 9e50108 | 2010-01-29 18:20:29 +0000 | [diff] [blame] | 721 | |
Mark Brown | 9db4249 | 2012-01-30 20:06:05 +0000 | [diff] [blame] | 722 | wm8994->regmap = devm_regmap_init_i2c(i2c, &wm8994_base_regmap_config); |
Mark Brown | d6c645fc | 2011-06-17 13:02:27 +0100 | [diff] [blame] | 723 | if (IS_ERR(wm8994->regmap)) { |
| 724 | ret = PTR_ERR(wm8994->regmap); |
| 725 | dev_err(wm8994->dev, "Failed to allocate register map: %d\n", |
| 726 | ret); |
Mark Brown | d6c645fc | 2011-06-17 13:02:27 +0100 | [diff] [blame] | 727 | return ret; |
| 728 | } |
| 729 | |
Mark Brown | 559e0df | 2010-08-31 19:25:12 +0100 | [diff] [blame] | 730 | return wm8994_device_init(wm8994, i2c->irq); |
Mark Brown | 9e50108 | 2010-01-29 18:20:29 +0000 | [diff] [blame] | 731 | } |
| 732 | |
Bill Pemberton | 4740f73 | 2012-11-19 13:26:01 -0500 | [diff] [blame] | 733 | static int wm8994_i2c_remove(struct i2c_client *i2c) |
Mark Brown | 9e50108 | 2010-01-29 18:20:29 +0000 | [diff] [blame] | 734 | { |
| 735 | struct wm8994 *wm8994 = i2c_get_clientdata(i2c); |
| 736 | |
| 737 | wm8994_device_exit(wm8994); |
| 738 | |
| 739 | return 0; |
| 740 | } |
| 741 | |
Mark Brown | 9e50108 | 2010-01-29 18:20:29 +0000 | [diff] [blame] | 742 | static const struct i2c_device_id wm8994_i2c_id[] = { |
Mark Brown | b1f43bf | 2011-05-24 17:35:40 +0800 | [diff] [blame] | 743 | { "wm1811", WM1811 }, |
Mark Brown | 71d1718 | 2011-11-30 20:16:42 +0000 | [diff] [blame] | 744 | { "wm1811a", WM1811 }, |
Mark Brown | 559e0df | 2010-08-31 19:25:12 +0100 | [diff] [blame] | 745 | { "wm8994", WM8994 }, |
| 746 | { "wm8958", WM8958 }, |
Mark Brown | 9e50108 | 2010-01-29 18:20:29 +0000 | [diff] [blame] | 747 | { } |
| 748 | }; |
| 749 | MODULE_DEVICE_TABLE(i2c, wm8994_i2c_id); |
| 750 | |
Mark Brown | 6394678 | 2013-03-22 12:40:22 +0100 | [diff] [blame] | 751 | static const struct dev_pm_ops wm8994_pm_ops = { |
| 752 | SET_RUNTIME_PM_OPS(wm8994_suspend, wm8994_resume, NULL) |
| 753 | }; |
Mark Brown | d450f19 | 2010-11-26 17:19:35 +0000 | [diff] [blame] | 754 | |
Mark Brown | 9e50108 | 2010-01-29 18:20:29 +0000 | [diff] [blame] | 755 | static struct i2c_driver wm8994_i2c_driver = { |
| 756 | .driver = { |
Mark Brown | d450f19 | 2010-11-26 17:19:35 +0000 | [diff] [blame] | 757 | .name = "wm8994", |
| 758 | .owner = THIS_MODULE, |
| 759 | .pm = &wm8994_pm_ops, |
Mark Brown | 20fb277 | 2013-04-11 18:11:51 +0100 | [diff] [blame] | 760 | .of_match_table = of_match_ptr(wm8994_of_match), |
Mark Brown | 9e50108 | 2010-01-29 18:20:29 +0000 | [diff] [blame] | 761 | }, |
| 762 | .probe = wm8994_i2c_probe, |
Bill Pemberton | 8444921 | 2012-11-19 13:20:24 -0500 | [diff] [blame] | 763 | .remove = wm8994_i2c_remove, |
Mark Brown | 9e50108 | 2010-01-29 18:20:29 +0000 | [diff] [blame] | 764 | .id_table = wm8994_i2c_id, |
| 765 | }; |
| 766 | |
Mark Brown | ceb57d2 | 2012-05-07 10:03:23 +0100 | [diff] [blame] | 767 | module_i2c_driver(wm8994_i2c_driver); |
Mark Brown | 9e50108 | 2010-01-29 18:20:29 +0000 | [diff] [blame] | 768 | |
| 769 | MODULE_DESCRIPTION("Core support for the WM8994 audio CODEC"); |
| 770 | MODULE_LICENSE("GPL"); |
| 771 | MODULE_AUTHOR("Mark Brown <broonie@opensource.wolfsonmicro.com>"); |