Thomas Gleixner | 2874c5f | 2019-05-27 08:55:01 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-or-later |
Mark Brown | 89b4012 | 2008-10-10 15:58:10 +0100 | [diff] [blame] | 2 | /* |
| 3 | * wm8350-core.c -- Device access for Wolfson WM8350 |
| 4 | * |
| 5 | * Copyright 2007, 2008 Wolfson Microelectronics PLC. |
| 6 | * |
| 7 | * Author: Liam Girdwood, Mark Brown |
Mark Brown | 89b4012 | 2008-10-10 15:58:10 +0100 | [diff] [blame] | 8 | */ |
| 9 | |
| 10 | #include <linux/kernel.h> |
Paul Gortmaker | 0db88688 | 2019-01-13 13:36:48 -0500 | [diff] [blame] | 11 | #include <linux/init.h> |
| 12 | #include <linux/export.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 13 | #include <linux/slab.h> |
Mark Brown | ebccec0 | 2008-10-10 15:58:14 +0100 | [diff] [blame] | 14 | #include <linux/bug.h> |
Mark Brown | 89b4012 | 2008-10-10 15:58:10 +0100 | [diff] [blame] | 15 | #include <linux/device.h> |
| 16 | #include <linux/delay.h> |
| 17 | #include <linux/interrupt.h> |
Mark Brown | b7b142d | 2012-05-07 10:03:21 +0100 | [diff] [blame] | 18 | #include <linux/regmap.h> |
Mark Brown | ebccec0 | 2008-10-10 15:58:14 +0100 | [diff] [blame] | 19 | #include <linux/workqueue.h> |
Mark Brown | 89b4012 | 2008-10-10 15:58:10 +0100 | [diff] [blame] | 20 | |
| 21 | #include <linux/mfd/wm8350/core.h> |
| 22 | #include <linux/mfd/wm8350/audio.h> |
Mark Brown | ebccec0 | 2008-10-10 15:58:14 +0100 | [diff] [blame] | 23 | #include <linux/mfd/wm8350/comparator.h> |
Mark Brown | 89b4012 | 2008-10-10 15:58:10 +0100 | [diff] [blame] | 24 | #include <linux/mfd/wm8350/gpio.h> |
| 25 | #include <linux/mfd/wm8350/pmic.h> |
Mark Brown | ebccec0 | 2008-10-10 15:58:14 +0100 | [diff] [blame] | 26 | #include <linux/mfd/wm8350/rtc.h> |
Mark Brown | 89b4012 | 2008-10-10 15:58:10 +0100 | [diff] [blame] | 27 | #include <linux/mfd/wm8350/supply.h> |
Mark Brown | ebccec0 | 2008-10-10 15:58:14 +0100 | [diff] [blame] | 28 | #include <linux/mfd/wm8350/wdt.h> |
Mark Brown | 89b4012 | 2008-10-10 15:58:10 +0100 | [diff] [blame] | 29 | |
Mark Brown | 89b4012 | 2008-10-10 15:58:10 +0100 | [diff] [blame] | 30 | #define WM8350_CLOCK_CONTROL_1 0x28 |
| 31 | #define WM8350_AIF_TEST 0x74 |
| 32 | |
| 33 | /* debug */ |
| 34 | #define WM8350_BUS_DEBUG 0 |
| 35 | #if WM8350_BUS_DEBUG |
| 36 | #define dump(regs, src) do { \ |
| 37 | int i_; \ |
| 38 | u16 *src_ = src; \ |
| 39 | printk(KERN_DEBUG); \ |
| 40 | for (i_ = 0; i_ < regs; i_++) \ |
| 41 | printk(" 0x%4.4x", *src_++); \ |
| 42 | printk("\n"); \ |
| 43 | } while (0); |
| 44 | #else |
| 45 | #define dump(bytes, src) |
| 46 | #endif |
| 47 | |
| 48 | #define WM8350_LOCK_DEBUG 0 |
| 49 | #if WM8350_LOCK_DEBUG |
| 50 | #define ldbg(format, arg...) printk(format, ## arg) |
| 51 | #else |
| 52 | #define ldbg(format, arg...) |
| 53 | #endif |
| 54 | |
| 55 | /* |
| 56 | * WM8350 Device IO |
| 57 | */ |
Mark Brown | 89b4012 | 2008-10-10 15:58:10 +0100 | [diff] [blame] | 58 | static DEFINE_MUTEX(reg_lock_mutex); |
Mark Brown | 89b4012 | 2008-10-10 15:58:10 +0100 | [diff] [blame] | 59 | |
Mark Brown | 89b4012 | 2008-10-10 15:58:10 +0100 | [diff] [blame] | 60 | /* |
| 61 | * Safe read, modify, write methods |
| 62 | */ |
| 63 | int wm8350_clear_bits(struct wm8350 *wm8350, u16 reg, u16 mask) |
| 64 | { |
Mark Brown | 19d57ed | 2012-06-03 13:37:24 +0100 | [diff] [blame] | 65 | return regmap_update_bits(wm8350->regmap, reg, mask, 0); |
Mark Brown | 89b4012 | 2008-10-10 15:58:10 +0100 | [diff] [blame] | 66 | } |
| 67 | EXPORT_SYMBOL_GPL(wm8350_clear_bits); |
| 68 | |
| 69 | int wm8350_set_bits(struct wm8350 *wm8350, u16 reg, u16 mask) |
| 70 | { |
Mark Brown | 19d57ed | 2012-06-03 13:37:24 +0100 | [diff] [blame] | 71 | return regmap_update_bits(wm8350->regmap, reg, mask, mask); |
Mark Brown | 89b4012 | 2008-10-10 15:58:10 +0100 | [diff] [blame] | 72 | } |
| 73 | EXPORT_SYMBOL_GPL(wm8350_set_bits); |
| 74 | |
| 75 | u16 wm8350_reg_read(struct wm8350 *wm8350, int reg) |
| 76 | { |
Mark Brown | 19d57ed | 2012-06-03 13:37:24 +0100 | [diff] [blame] | 77 | unsigned int data; |
Mark Brown | 89b4012 | 2008-10-10 15:58:10 +0100 | [diff] [blame] | 78 | int err; |
| 79 | |
Mark Brown | 19d57ed | 2012-06-03 13:37:24 +0100 | [diff] [blame] | 80 | err = regmap_read(wm8350->regmap, reg, &data); |
Mark Brown | 89b4012 | 2008-10-10 15:58:10 +0100 | [diff] [blame] | 81 | if (err) |
| 82 | dev_err(wm8350->dev, "read from reg R%d failed\n", reg); |
| 83 | |
Mark Brown | 89b4012 | 2008-10-10 15:58:10 +0100 | [diff] [blame] | 84 | return data; |
| 85 | } |
| 86 | EXPORT_SYMBOL_GPL(wm8350_reg_read); |
| 87 | |
| 88 | int wm8350_reg_write(struct wm8350 *wm8350, int reg, u16 val) |
| 89 | { |
| 90 | int ret; |
Mark Brown | 89b4012 | 2008-10-10 15:58:10 +0100 | [diff] [blame] | 91 | |
Mark Brown | 19d57ed | 2012-06-03 13:37:24 +0100 | [diff] [blame] | 92 | ret = regmap_write(wm8350->regmap, reg, val); |
| 93 | |
Mark Brown | 89b4012 | 2008-10-10 15:58:10 +0100 | [diff] [blame] | 94 | if (ret) |
| 95 | dev_err(wm8350->dev, "write to reg R%d failed\n", reg); |
Mark Brown | 89b4012 | 2008-10-10 15:58:10 +0100 | [diff] [blame] | 96 | return ret; |
| 97 | } |
| 98 | EXPORT_SYMBOL_GPL(wm8350_reg_write); |
| 99 | |
| 100 | int wm8350_block_read(struct wm8350 *wm8350, int start_reg, int regs, |
| 101 | u16 *dest) |
| 102 | { |
| 103 | int err = 0; |
| 104 | |
Mark Brown | 19d57ed | 2012-06-03 13:37:24 +0100 | [diff] [blame] | 105 | err = regmap_bulk_read(wm8350->regmap, start_reg, dest, regs); |
Mark Brown | 89b4012 | 2008-10-10 15:58:10 +0100 | [diff] [blame] | 106 | if (err) |
| 107 | dev_err(wm8350->dev, "block read starting from R%d failed\n", |
| 108 | start_reg); |
Mark Brown | 19d57ed | 2012-06-03 13:37:24 +0100 | [diff] [blame] | 109 | |
Mark Brown | 89b4012 | 2008-10-10 15:58:10 +0100 | [diff] [blame] | 110 | return err; |
| 111 | } |
| 112 | EXPORT_SYMBOL_GPL(wm8350_block_read); |
| 113 | |
| 114 | int wm8350_block_write(struct wm8350 *wm8350, int start_reg, int regs, |
| 115 | u16 *src) |
| 116 | { |
| 117 | int ret = 0; |
| 118 | |
Mark Brown | 19d57ed | 2012-06-03 13:37:24 +0100 | [diff] [blame] | 119 | ret = regmap_bulk_write(wm8350->regmap, start_reg, src, regs); |
Mark Brown | 89b4012 | 2008-10-10 15:58:10 +0100 | [diff] [blame] | 120 | if (ret) |
| 121 | dev_err(wm8350->dev, "block write starting at R%d failed\n", |
| 122 | start_reg); |
Mark Brown | 19d57ed | 2012-06-03 13:37:24 +0100 | [diff] [blame] | 123 | |
Mark Brown | 89b4012 | 2008-10-10 15:58:10 +0100 | [diff] [blame] | 124 | return ret; |
| 125 | } |
| 126 | EXPORT_SYMBOL_GPL(wm8350_block_write); |
| 127 | |
Mark Brown | 858e674 | 2008-11-08 00:57:33 +0100 | [diff] [blame] | 128 | /** |
| 129 | * wm8350_reg_lock() |
| 130 | * |
| 131 | * The WM8350 has a hardware lock which can be used to prevent writes to |
| 132 | * some registers (generally those which can cause particularly serious |
| 133 | * problems if misused). This function enables that lock. |
| 134 | */ |
Mark Brown | 89b4012 | 2008-10-10 15:58:10 +0100 | [diff] [blame] | 135 | int wm8350_reg_lock(struct wm8350 *wm8350) |
| 136 | { |
Mark Brown | 89b4012 | 2008-10-10 15:58:10 +0100 | [diff] [blame] | 137 | int ret; |
| 138 | |
Mark Brown | 52b461b | 2012-06-03 13:37:22 +0100 | [diff] [blame] | 139 | mutex_lock(®_lock_mutex); |
| 140 | |
Mark Brown | 89b4012 | 2008-10-10 15:58:10 +0100 | [diff] [blame] | 141 | ldbg(__func__); |
Mark Brown | 52b461b | 2012-06-03 13:37:22 +0100 | [diff] [blame] | 142 | |
| 143 | ret = wm8350_reg_write(wm8350, WM8350_SECURITY, WM8350_LOCK_KEY); |
Mark Brown | 89b4012 | 2008-10-10 15:58:10 +0100 | [diff] [blame] | 144 | if (ret) |
| 145 | dev_err(wm8350->dev, "lock failed\n"); |
Mark Brown | 52b461b | 2012-06-03 13:37:22 +0100 | [diff] [blame] | 146 | |
| 147 | wm8350->unlocked = false; |
| 148 | |
| 149 | mutex_unlock(®_lock_mutex); |
| 150 | |
Mark Brown | 89b4012 | 2008-10-10 15:58:10 +0100 | [diff] [blame] | 151 | return ret; |
| 152 | } |
| 153 | EXPORT_SYMBOL_GPL(wm8350_reg_lock); |
| 154 | |
Mark Brown | 858e674 | 2008-11-08 00:57:33 +0100 | [diff] [blame] | 155 | /** |
| 156 | * wm8350_reg_unlock() |
| 157 | * |
| 158 | * The WM8350 has a hardware lock which can be used to prevent writes to |
| 159 | * some registers (generally those which can cause particularly serious |
| 160 | * problems if misused). This function disables that lock so updates |
| 161 | * can be performed. For maximum safety this should be done only when |
| 162 | * required. |
| 163 | */ |
Mark Brown | 89b4012 | 2008-10-10 15:58:10 +0100 | [diff] [blame] | 164 | int wm8350_reg_unlock(struct wm8350 *wm8350) |
| 165 | { |
Mark Brown | 89b4012 | 2008-10-10 15:58:10 +0100 | [diff] [blame] | 166 | int ret; |
| 167 | |
Mark Brown | 52b461b | 2012-06-03 13:37:22 +0100 | [diff] [blame] | 168 | mutex_lock(®_lock_mutex); |
| 169 | |
Mark Brown | 89b4012 | 2008-10-10 15:58:10 +0100 | [diff] [blame] | 170 | ldbg(__func__); |
Mark Brown | 52b461b | 2012-06-03 13:37:22 +0100 | [diff] [blame] | 171 | |
| 172 | ret = wm8350_reg_write(wm8350, WM8350_SECURITY, WM8350_UNLOCK_KEY); |
Mark Brown | 89b4012 | 2008-10-10 15:58:10 +0100 | [diff] [blame] | 173 | if (ret) |
| 174 | dev_err(wm8350->dev, "unlock failed\n"); |
Mark Brown | 52b461b | 2012-06-03 13:37:22 +0100 | [diff] [blame] | 175 | |
| 176 | wm8350->unlocked = true; |
| 177 | |
| 178 | mutex_unlock(®_lock_mutex); |
| 179 | |
Mark Brown | 89b4012 | 2008-10-10 15:58:10 +0100 | [diff] [blame] | 180 | return ret; |
| 181 | } |
| 182 | EXPORT_SYMBOL_GPL(wm8350_reg_unlock); |
| 183 | |
Mark Brown | 6748852 | 2008-11-08 01:10:21 +0100 | [diff] [blame] | 184 | int wm8350_read_auxadc(struct wm8350 *wm8350, int channel, int scale, int vref) |
| 185 | { |
| 186 | u16 reg, result = 0; |
Mark Brown | 6748852 | 2008-11-08 01:10:21 +0100 | [diff] [blame] | 187 | |
| 188 | if (channel < WM8350_AUXADC_AUX1 || channel > WM8350_AUXADC_TEMP) |
| 189 | return -EINVAL; |
| 190 | if (channel >= WM8350_AUXADC_USB && channel <= WM8350_AUXADC_TEMP |
| 191 | && (scale != 0 || vref != 0)) |
| 192 | return -EINVAL; |
| 193 | |
| 194 | mutex_lock(&wm8350->auxadc_mutex); |
| 195 | |
| 196 | /* Turn on the ADC */ |
| 197 | reg = wm8350_reg_read(wm8350, WM8350_POWER_MGMT_5); |
| 198 | wm8350_reg_write(wm8350, WM8350_POWER_MGMT_5, reg | WM8350_AUXADC_ENA); |
| 199 | |
| 200 | if (scale || vref) { |
| 201 | reg = scale << 13; |
| 202 | reg |= vref << 12; |
| 203 | wm8350_reg_write(wm8350, WM8350_AUX1_READBACK + channel, reg); |
| 204 | } |
| 205 | |
| 206 | reg = wm8350_reg_read(wm8350, WM8350_DIGITISER_CONTROL_1); |
| 207 | reg |= 1 << channel | WM8350_AUXADC_POLL; |
| 208 | wm8350_reg_write(wm8350, WM8350_DIGITISER_CONTROL_1, reg); |
| 209 | |
Mark Brown | 5051d41 | 2010-04-02 13:08:39 +0100 | [diff] [blame] | 210 | /* If a late IRQ left the completion signalled then consume |
| 211 | * the completion. */ |
| 212 | try_wait_for_completion(&wm8350->auxadc_done); |
| 213 | |
Mark Brown | d19663a | 2010-02-23 11:08:05 +0000 | [diff] [blame] | 214 | /* We ignore the result of the completion and just check for a |
| 215 | * conversion result, allowing us to soldier on if the IRQ |
| 216 | * infrastructure is not set up for the chip. */ |
| 217 | wait_for_completion_timeout(&wm8350->auxadc_done, msecs_to_jiffies(5)); |
Mark Brown | 6748852 | 2008-11-08 01:10:21 +0100 | [diff] [blame] | 218 | |
Mark Brown | d19663a | 2010-02-23 11:08:05 +0000 | [diff] [blame] | 219 | reg = wm8350_reg_read(wm8350, WM8350_DIGITISER_CONTROL_1); |
| 220 | if (reg & WM8350_AUXADC_POLL) |
Mark Brown | 6748852 | 2008-11-08 01:10:21 +0100 | [diff] [blame] | 221 | dev_err(wm8350->dev, "adc chn %d read timeout\n", channel); |
| 222 | else |
| 223 | result = wm8350_reg_read(wm8350, |
| 224 | WM8350_AUX1_READBACK + channel); |
| 225 | |
| 226 | /* Turn off the ADC */ |
| 227 | reg = wm8350_reg_read(wm8350, WM8350_POWER_MGMT_5); |
| 228 | wm8350_reg_write(wm8350, WM8350_POWER_MGMT_5, |
| 229 | reg & ~WM8350_AUXADC_ENA); |
| 230 | |
| 231 | mutex_unlock(&wm8350->auxadc_mutex); |
| 232 | |
| 233 | return result & WM8350_AUXADC_DATA1_MASK; |
| 234 | } |
| 235 | EXPORT_SYMBOL_GPL(wm8350_read_auxadc); |
| 236 | |
Mark Brown | d19663a | 2010-02-23 11:08:05 +0000 | [diff] [blame] | 237 | static irqreturn_t wm8350_auxadc_irq(int irq, void *irq_data) |
| 238 | { |
| 239 | struct wm8350 *wm8350 = irq_data; |
| 240 | |
| 241 | complete(&wm8350->auxadc_done); |
| 242 | |
| 243 | return IRQ_HANDLED; |
| 244 | } |
| 245 | |
Mark Brown | 89b4012 | 2008-10-10 15:58:10 +0100 | [diff] [blame] | 246 | /* |
Mark Brown | 9201d38 | 2008-10-10 15:58:16 +0100 | [diff] [blame] | 247 | * Register a client device. This is non-fatal since there is no need to |
| 248 | * fail the entire device init due to a single platform device failing. |
| 249 | */ |
| 250 | static void wm8350_client_dev_register(struct wm8350 *wm8350, |
| 251 | const char *name, |
| 252 | struct platform_device **pdev) |
| 253 | { |
| 254 | int ret; |
| 255 | |
| 256 | *pdev = platform_device_alloc(name, -1); |
Dan Carpenter | cb9b224 | 2009-11-21 10:13:48 +0200 | [diff] [blame] | 257 | if (*pdev == NULL) { |
Mark Brown | 9201d38 | 2008-10-10 15:58:16 +0100 | [diff] [blame] | 258 | dev_err(wm8350->dev, "Failed to allocate %s\n", name); |
| 259 | return; |
| 260 | } |
| 261 | |
| 262 | (*pdev)->dev.parent = wm8350->dev; |
| 263 | platform_set_drvdata(*pdev, wm8350); |
| 264 | ret = platform_device_add(*pdev); |
| 265 | if (ret != 0) { |
| 266 | dev_err(wm8350->dev, "Failed to register %s: %d\n", name, ret); |
| 267 | platform_device_put(*pdev); |
| 268 | *pdev = NULL; |
| 269 | } |
| 270 | } |
| 271 | |
Mark Brown | ebccec0 | 2008-10-10 15:58:14 +0100 | [diff] [blame] | 272 | int wm8350_device_init(struct wm8350 *wm8350, int irq, |
Mark Brown | bcdd4ef | 2008-10-10 15:58:13 +0100 | [diff] [blame] | 273 | struct wm8350_platform_data *pdata) |
Mark Brown | 89b4012 | 2008-10-10 15:58:10 +0100 | [diff] [blame] | 274 | { |
Mark Brown | 85c93ea | 2009-02-04 21:09:38 +0100 | [diff] [blame] | 275 | int ret; |
Mark Brown | b7b142d | 2012-05-07 10:03:21 +0100 | [diff] [blame] | 276 | unsigned int id1, id2, mask_rev; |
| 277 | unsigned int cust_id, mode, chip_rev; |
Mark Brown | 89b4012 | 2008-10-10 15:58:10 +0100 | [diff] [blame] | 278 | |
Mark Brown | 18bf50a | 2011-12-08 10:55:21 +0800 | [diff] [blame] | 279 | dev_set_drvdata(wm8350->dev, wm8350); |
| 280 | |
Mark Brown | 89b4012 | 2008-10-10 15:58:10 +0100 | [diff] [blame] | 281 | /* get WM8350 revision and config mode */ |
Mark Brown | b7b142d | 2012-05-07 10:03:21 +0100 | [diff] [blame] | 282 | ret = regmap_read(wm8350->regmap, WM8350_RESET_ID, &id1); |
Mark Brown | 85c93ea | 2009-02-04 21:09:38 +0100 | [diff] [blame] | 283 | if (ret != 0) { |
| 284 | dev_err(wm8350->dev, "Failed to read ID: %d\n", ret); |
| 285 | goto err; |
| 286 | } |
| 287 | |
Mark Brown | b7b142d | 2012-05-07 10:03:21 +0100 | [diff] [blame] | 288 | ret = regmap_read(wm8350->regmap, WM8350_ID, &id2); |
Mark Brown | 85c93ea | 2009-02-04 21:09:38 +0100 | [diff] [blame] | 289 | if (ret != 0) { |
| 290 | dev_err(wm8350->dev, "Failed to read ID: %d\n", ret); |
| 291 | goto err; |
| 292 | } |
| 293 | |
Mark Brown | b7b142d | 2012-05-07 10:03:21 +0100 | [diff] [blame] | 294 | ret = regmap_read(wm8350->regmap, WM8350_REVISION, &mask_rev); |
Mark Brown | 85c93ea | 2009-02-04 21:09:38 +0100 | [diff] [blame] | 295 | if (ret != 0) { |
| 296 | dev_err(wm8350->dev, "Failed to read revision: %d\n", ret); |
| 297 | goto err; |
| 298 | } |
Mark Brown | 89b4012 | 2008-10-10 15:58:10 +0100 | [diff] [blame] | 299 | |
Mark Brown | b797a55 | 2008-11-24 20:22:58 +0100 | [diff] [blame] | 300 | if (id1 != 0x6143) { |
| 301 | dev_err(wm8350->dev, |
| 302 | "Device with ID %x is not a WM8350\n", id1); |
Mark Brown | 89b4012 | 2008-10-10 15:58:10 +0100 | [diff] [blame] | 303 | ret = -ENODEV; |
| 304 | goto err; |
| 305 | } |
| 306 | |
Joe Perches | 1753b40 | 2014-10-26 22:25:02 -0700 | [diff] [blame] | 307 | mode = (id2 & WM8350_CONF_STS_MASK) >> 10; |
Mark Brown | b797a55 | 2008-11-24 20:22:58 +0100 | [diff] [blame] | 308 | cust_id = id2 & WM8350_CUST_ID_MASK; |
| 309 | chip_rev = (id2 & WM8350_CHIP_REV_MASK) >> 12; |
| 310 | dev_info(wm8350->dev, |
| 311 | "CONF_STS %d, CUST_ID %d, MASK_REV %d, CHIP_REV %d\n", |
| 312 | mode, cust_id, mask_rev, chip_rev); |
| 313 | |
| 314 | if (cust_id != 0) { |
| 315 | dev_err(wm8350->dev, "Unsupported CUST_ID\n"); |
| 316 | ret = -ENODEV; |
| 317 | goto err; |
| 318 | } |
| 319 | |
| 320 | switch (mask_rev) { |
| 321 | case 0: |
Mark Brown | 645524a | 2008-12-18 23:12:16 +0100 | [diff] [blame] | 322 | wm8350->pmic.max_dcdc = WM8350_DCDC_6; |
| 323 | wm8350->pmic.max_isink = WM8350_ISINK_B; |
| 324 | |
Mark Brown | b797a55 | 2008-11-24 20:22:58 +0100 | [diff] [blame] | 325 | switch (chip_rev) { |
| 326 | case WM8350_REV_E: |
| 327 | dev_info(wm8350->dev, "WM8350 Rev E\n"); |
| 328 | break; |
| 329 | case WM8350_REV_F: |
| 330 | dev_info(wm8350->dev, "WM8350 Rev F\n"); |
| 331 | break; |
| 332 | case WM8350_REV_G: |
| 333 | dev_info(wm8350->dev, "WM8350 Rev G\n"); |
| 334 | wm8350->power.rev_g_coeff = 1; |
| 335 | break; |
| 336 | case WM8350_REV_H: |
| 337 | dev_info(wm8350->dev, "WM8350 Rev H\n"); |
| 338 | wm8350->power.rev_g_coeff = 1; |
| 339 | break; |
| 340 | default: |
| 341 | /* For safety we refuse to run on unknown hardware */ |
| 342 | dev_err(wm8350->dev, "Unknown WM8350 CHIP_REV\n"); |
| 343 | ret = -ENODEV; |
| 344 | goto err; |
| 345 | } |
| 346 | break; |
| 347 | |
Mark Brown | ca23f8c | 2008-12-18 23:12:28 +0100 | [diff] [blame] | 348 | case 1: |
| 349 | wm8350->pmic.max_dcdc = WM8350_DCDC_4; |
| 350 | wm8350->pmic.max_isink = WM8350_ISINK_A; |
| 351 | |
| 352 | switch (chip_rev) { |
| 353 | case 0: |
| 354 | dev_info(wm8350->dev, "WM8351 Rev A\n"); |
| 355 | wm8350->power.rev_g_coeff = 1; |
| 356 | break; |
| 357 | |
Mark Brown | 02d46e0 | 2009-03-12 14:31:36 -0700 | [diff] [blame] | 358 | case 1: |
| 359 | dev_info(wm8350->dev, "WM8351 Rev B\n"); |
| 360 | wm8350->power.rev_g_coeff = 1; |
| 361 | break; |
| 362 | |
Mark Brown | ca23f8c | 2008-12-18 23:12:28 +0100 | [diff] [blame] | 363 | default: |
| 364 | dev_err(wm8350->dev, "Unknown WM8351 CHIP_REV\n"); |
| 365 | ret = -ENODEV; |
| 366 | goto err; |
| 367 | } |
| 368 | break; |
| 369 | |
Mark Brown | 9692063 | 2008-12-18 23:09:50 +0100 | [diff] [blame] | 370 | case 2: |
Mark Brown | 645524a | 2008-12-18 23:12:16 +0100 | [diff] [blame] | 371 | wm8350->pmic.max_dcdc = WM8350_DCDC_6; |
| 372 | wm8350->pmic.max_isink = WM8350_ISINK_B; |
| 373 | |
Mark Brown | 9692063 | 2008-12-18 23:09:50 +0100 | [diff] [blame] | 374 | switch (chip_rev) { |
| 375 | case 0: |
| 376 | dev_info(wm8350->dev, "WM8352 Rev A\n"); |
| 377 | wm8350->power.rev_g_coeff = 1; |
| 378 | break; |
| 379 | |
| 380 | default: |
| 381 | dev_err(wm8350->dev, "Unknown WM8352 CHIP_REV\n"); |
| 382 | ret = -ENODEV; |
| 383 | goto err; |
| 384 | } |
| 385 | break; |
| 386 | |
Mark Brown | b797a55 | 2008-11-24 20:22:58 +0100 | [diff] [blame] | 387 | default: |
| 388 | dev_err(wm8350->dev, "Unknown MASK_REV\n"); |
| 389 | ret = -ENODEV; |
| 390 | goto err; |
| 391 | } |
Mark Brown | 89b4012 | 2008-10-10 15:58:10 +0100 | [diff] [blame] | 392 | |
Mark Brown | 6748852 | 2008-11-08 01:10:21 +0100 | [diff] [blame] | 393 | mutex_init(&wm8350->auxadc_mutex); |
Mark Brown | d19663a | 2010-02-23 11:08:05 +0000 | [diff] [blame] | 394 | init_completion(&wm8350->auxadc_done); |
Mark Brown | 3206450 | 2009-02-06 15:27:13 +0100 | [diff] [blame] | 395 | |
Mark Brown | e0a3389 | 2009-10-12 16:15:09 +0100 | [diff] [blame] | 396 | ret = wm8350_irq_init(wm8350, irq, pdata); |
| 397 | if (ret < 0) |
Mark Brown | 19d57ed | 2012-06-03 13:37:24 +0100 | [diff] [blame] | 398 | goto err; |
Mark Brown | ebccec0 | 2008-10-10 15:58:14 +0100 | [diff] [blame] | 399 | |
Mark Brown | d19663a | 2010-02-23 11:08:05 +0000 | [diff] [blame] | 400 | if (wm8350->irq_base) { |
| 401 | ret = request_threaded_irq(wm8350->irq_base + |
| 402 | WM8350_IRQ_AUXADC_DATARDY, |
Fabio Estevam | b3c8c82 | 2015-05-16 15:42:14 -0300 | [diff] [blame] | 403 | NULL, wm8350_auxadc_irq, |
| 404 | IRQF_ONESHOT, |
Mark Brown | d19663a | 2010-02-23 11:08:05 +0000 | [diff] [blame] | 405 | "auxadc", wm8350); |
| 406 | if (ret < 0) |
| 407 | dev_warn(wm8350->dev, |
| 408 | "Failed to request AUXADC IRQ: %d\n", ret); |
| 409 | } |
| 410 | |
Mark Brown | 62571c29 | 2009-02-04 20:49:52 +0100 | [diff] [blame] | 411 | if (pdata && pdata->init) { |
| 412 | ret = pdata->init(wm8350); |
| 413 | if (ret != 0) { |
| 414 | dev_err(wm8350->dev, "Platform init() failed: %d\n", |
| 415 | ret); |
Mark Brown | e0a3389 | 2009-10-12 16:15:09 +0100 | [diff] [blame] | 416 | goto err_irq; |
Mark Brown | 62571c29 | 2009-02-04 20:49:52 +0100 | [diff] [blame] | 417 | } |
| 418 | } |
| 419 | |
Mark Brown | ebccec0 | 2008-10-10 15:58:14 +0100 | [diff] [blame] | 420 | wm8350_reg_write(wm8350, WM8350_SYSTEM_INTERRUPTS_MASK, 0x0); |
| 421 | |
Mark Brown | add41cb | 2008-10-13 15:45:22 +0100 | [diff] [blame] | 422 | wm8350_client_dev_register(wm8350, "wm8350-codec", |
| 423 | &(wm8350->codec.pdev)); |
| 424 | wm8350_client_dev_register(wm8350, "wm8350-gpio", |
| 425 | &(wm8350->gpio.pdev)); |
Mark Brown | fb6c023 | 2009-07-20 12:43:45 +0100 | [diff] [blame] | 426 | wm8350_client_dev_register(wm8350, "wm8350-hwmon", |
| 427 | &(wm8350->hwmon.pdev)); |
Mark Brown | add41cb | 2008-10-13 15:45:22 +0100 | [diff] [blame] | 428 | wm8350_client_dev_register(wm8350, "wm8350-power", |
| 429 | &(wm8350->power.pdev)); |
| 430 | wm8350_client_dev_register(wm8350, "wm8350-rtc", &(wm8350->rtc.pdev)); |
| 431 | wm8350_client_dev_register(wm8350, "wm8350-wdt", &(wm8350->wdt.pdev)); |
| 432 | |
Mark Brown | 89b4012 | 2008-10-10 15:58:10 +0100 | [diff] [blame] | 433 | return 0; |
| 434 | |
Mark Brown | e0a3389 | 2009-10-12 16:15:09 +0100 | [diff] [blame] | 435 | err_irq: |
| 436 | wm8350_irq_exit(wm8350); |
Axel Lin | 8c46cf3 | 2010-08-04 09:54:21 +0800 | [diff] [blame] | 437 | err: |
Mark Brown | 89b4012 | 2008-10-10 15:58:10 +0100 | [diff] [blame] | 438 | return ret; |
| 439 | } |
| 440 | EXPORT_SYMBOL_GPL(wm8350_device_init); |