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