Ravishankar Sarawadi | 839fcf3 | 2012-11-14 12:13:00 -0800 | [diff] [blame] | 1 | /* Copyright (c) 2011-2013, The Linux Foundation. All rights reserved. |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 2 | * |
| 3 | * This program is free software; you can redistribute it and/or modify |
| 4 | * it under the terms of the GNU General Public License version 2 and |
| 5 | * only version 2 as published by the Free Software Foundation. |
| 6 | * |
| 7 | * This program is distributed in the hope that it will be useful, |
| 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 10 | * GNU General Public License for more details. |
| 11 | */ |
| 12 | |
| 13 | #include <linux/kernel.h> |
| 14 | #include <linux/module.h> |
Kiran Kandi | 725f849 | 2012-08-06 13:45:16 -0700 | [diff] [blame] | 15 | #include <linux/of_gpio.h> |
Joonwoo Park | f6574c7 | 2012-10-10 17:29:57 -0700 | [diff] [blame] | 16 | #include <linux/of_irq.h> |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 17 | #include <linux/slab.h> |
Joonwoo Park | 7bd7d84 | 2013-04-09 18:10:25 -0700 | [diff] [blame] | 18 | #include <linux/ratelimit.h> |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 19 | #include <linux/mfd/core.h> |
| 20 | #include <linux/mfd/wcd9xxx/wcd9xxx-slimslave.h> |
| 21 | #include <linux/mfd/wcd9xxx/core.h> |
| 22 | #include <linux/mfd/wcd9xxx/pdata.h> |
| 23 | #include <linux/mfd/wcd9xxx/wcd9xxx_registers.h> |
| 24 | |
| 25 | #include <linux/delay.h> |
| 26 | #include <linux/gpio.h> |
| 27 | #include <linux/debugfs.h> |
| 28 | #include <linux/regulator/consumer.h> |
| 29 | #include <linux/i2c.h> |
| 30 | #include <sound/soc.h> |
| 31 | |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 32 | #define WCD9XXX_REGISTER_START_OFFSET 0x800 |
| 33 | #define WCD9XXX_SLIM_RW_MAX_TRIES 3 |
Joonwoo Park | 3c5b2df | 2012-08-28 15:36:55 -0700 | [diff] [blame] | 34 | #define SLIMBUS_PRESENT_TIMEOUT 100 |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 35 | |
| 36 | #define MAX_WCD9XXX_DEVICE 4 |
Venkat Sudhir | a41630a | 2012-10-27 00:57:31 -0700 | [diff] [blame] | 37 | #define CODEC_DT_MAX_PROP_SIZE 40 |
| 38 | #define WCD9XXX_I2C_GSBI_SLAVE_ID "3-000d" |
Venkat Sudhir | a50a376 | 2012-11-26 12:12:15 -0800 | [diff] [blame] | 39 | #define WCD9XXX_I2C_TOP_SLAVE_ADDR 0x0d |
| 40 | #define WCD9XXX_ANALOG_I2C_SLAVE_ADDR 0x77 |
| 41 | #define WCD9XXX_DIGITAL1_I2C_SLAVE_ADDR 0x66 |
| 42 | #define WCD9XXX_DIGITAL2_I2C_SLAVE_ADDR 0x55 |
| 43 | #define WCD9XXX_I2C_TOP_LEVEL 0 |
| 44 | #define WCD9XXX_I2C_ANALOG 1 |
| 45 | #define WCD9XXX_I2C_DIGITAL_1 2 |
| 46 | #define WCD9XXX_I2C_DIGITAL_2 3 |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 47 | |
Bhalchandra Gajare | 8e3c09f | 2013-08-23 11:58:35 -0700 | [diff] [blame^] | 48 | #define ONDEMAND_REGULATOR true |
| 49 | #define STATIC_REGULATOR (!ONDEMAND_REGULATOR) |
| 50 | |
Banajit Goswami | 4d6d891b | 2012-12-12 23:59:07 -0800 | [diff] [blame] | 51 | /* Number of return values needs to be checked for each |
| 52 | * registration of Slimbus of I2C bus for each codec |
| 53 | */ |
| 54 | #define NUM_WCD9XXX_REG_RET 8 |
| 55 | |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 56 | struct wcd9xxx_i2c { |
| 57 | struct i2c_client *client; |
| 58 | struct i2c_msg xfer_msg[2]; |
| 59 | struct mutex xfer_lock; |
| 60 | int mod_id; |
| 61 | }; |
| 62 | |
Venkat Sudhir | a41630a | 2012-10-27 00:57:31 -0700 | [diff] [blame] | 63 | static int wcd9xxx_dt_parse_vreg_info(struct device *dev, |
Joonwoo Park | 5d170a4 | 2013-04-10 15:16:36 -0700 | [diff] [blame] | 64 | struct wcd9xxx_regulator *vreg, |
| 65 | const char *vreg_name, bool ondemand); |
Venkat Sudhir | a41630a | 2012-10-27 00:57:31 -0700 | [diff] [blame] | 66 | static int wcd9xxx_dt_parse_micbias_info(struct device *dev, |
| 67 | struct wcd9xxx_micbias_setting *micbias); |
| 68 | static struct wcd9xxx_pdata *wcd9xxx_populate_dt_pdata(struct device *dev); |
| 69 | |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 70 | struct wcd9xxx_i2c wcd9xxx_modules[MAX_WCD9XXX_DEVICE]; |
Venkat Sudhir | db7aa2b | 2012-05-15 15:06:14 -0700 | [diff] [blame] | 71 | static int wcd9xxx_intf = -1; |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 72 | |
| 73 | static int wcd9xxx_read(struct wcd9xxx *wcd9xxx, unsigned short reg, |
| 74 | int bytes, void *dest, bool interface_reg) |
| 75 | { |
Joonwoo Park | f35b607 | 2013-04-25 13:26:38 -0700 | [diff] [blame] | 76 | int i, ret; |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 77 | |
| 78 | if (bytes <= 0) { |
| 79 | dev_err(wcd9xxx->dev, "Invalid byte read length %d\n", bytes); |
| 80 | return -EINVAL; |
| 81 | } |
| 82 | |
| 83 | ret = wcd9xxx->read_dev(wcd9xxx, reg, bytes, dest, interface_reg); |
| 84 | if (ret < 0) { |
| 85 | dev_err(wcd9xxx->dev, "Codec read failed\n"); |
| 86 | return ret; |
Joonwoo Park | f35b607 | 2013-04-25 13:26:38 -0700 | [diff] [blame] | 87 | } else { |
| 88 | for (i = 0; i < bytes; i++) |
| 89 | dev_dbg(wcd9xxx->dev, "Read 0x%02x from 0x%x\n", |
| 90 | ((u8 *)dest)[i], reg + i); |
| 91 | } |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 92 | |
| 93 | return 0; |
| 94 | } |
| 95 | int wcd9xxx_reg_read(struct wcd9xxx *wcd9xxx, unsigned short reg) |
| 96 | { |
| 97 | u8 val; |
| 98 | int ret; |
| 99 | |
| 100 | mutex_lock(&wcd9xxx->io_lock); |
| 101 | ret = wcd9xxx_read(wcd9xxx, reg, 1, &val, false); |
| 102 | mutex_unlock(&wcd9xxx->io_lock); |
| 103 | |
| 104 | if (ret < 0) |
| 105 | return ret; |
| 106 | else |
| 107 | return val; |
| 108 | } |
| 109 | EXPORT_SYMBOL_GPL(wcd9xxx_reg_read); |
| 110 | |
| 111 | static int wcd9xxx_write(struct wcd9xxx *wcd9xxx, unsigned short reg, |
| 112 | int bytes, void *src, bool interface_reg) |
| 113 | { |
Joonwoo Park | f35b607 | 2013-04-25 13:26:38 -0700 | [diff] [blame] | 114 | int i; |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 115 | |
| 116 | if (bytes <= 0) { |
| 117 | pr_err("%s: Error, invalid write length\n", __func__); |
| 118 | return -EINVAL; |
| 119 | } |
| 120 | |
Joonwoo Park | f35b607 | 2013-04-25 13:26:38 -0700 | [diff] [blame] | 121 | for (i = 0; i < bytes; i++) |
| 122 | dev_dbg(wcd9xxx->dev, "Write %02x to 0x%x\n", ((u8 *)src)[i], |
| 123 | reg + i); |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 124 | |
| 125 | return wcd9xxx->write_dev(wcd9xxx, reg, bytes, src, interface_reg); |
| 126 | } |
| 127 | |
| 128 | int wcd9xxx_reg_write(struct wcd9xxx *wcd9xxx, unsigned short reg, |
| 129 | u8 val) |
| 130 | { |
| 131 | int ret; |
| 132 | |
| 133 | mutex_lock(&wcd9xxx->io_lock); |
| 134 | ret = wcd9xxx_write(wcd9xxx, reg, 1, &val, false); |
| 135 | mutex_unlock(&wcd9xxx->io_lock); |
| 136 | |
| 137 | return ret; |
| 138 | } |
| 139 | EXPORT_SYMBOL_GPL(wcd9xxx_reg_write); |
| 140 | |
| 141 | static u8 wcd9xxx_pgd_la; |
| 142 | static u8 wcd9xxx_inf_la; |
| 143 | |
| 144 | int wcd9xxx_interface_reg_read(struct wcd9xxx *wcd9xxx, unsigned short reg) |
| 145 | { |
| 146 | u8 val; |
| 147 | int ret; |
| 148 | |
| 149 | mutex_lock(&wcd9xxx->io_lock); |
| 150 | ret = wcd9xxx_read(wcd9xxx, reg, 1, &val, true); |
| 151 | mutex_unlock(&wcd9xxx->io_lock); |
| 152 | |
| 153 | if (ret < 0) |
| 154 | return ret; |
| 155 | else |
| 156 | return val; |
| 157 | } |
| 158 | EXPORT_SYMBOL_GPL(wcd9xxx_interface_reg_read); |
| 159 | |
| 160 | int wcd9xxx_interface_reg_write(struct wcd9xxx *wcd9xxx, unsigned short reg, |
| 161 | u8 val) |
| 162 | { |
| 163 | int ret; |
| 164 | |
| 165 | mutex_lock(&wcd9xxx->io_lock); |
| 166 | ret = wcd9xxx_write(wcd9xxx, reg, 1, &val, true); |
| 167 | mutex_unlock(&wcd9xxx->io_lock); |
| 168 | |
| 169 | return ret; |
| 170 | } |
| 171 | EXPORT_SYMBOL_GPL(wcd9xxx_interface_reg_write); |
| 172 | |
| 173 | int wcd9xxx_bulk_read(struct wcd9xxx *wcd9xxx, unsigned short reg, |
| 174 | int count, u8 *buf) |
| 175 | { |
| 176 | int ret; |
| 177 | |
| 178 | mutex_lock(&wcd9xxx->io_lock); |
| 179 | |
| 180 | ret = wcd9xxx_read(wcd9xxx, reg, count, buf, false); |
| 181 | |
| 182 | mutex_unlock(&wcd9xxx->io_lock); |
| 183 | |
| 184 | return ret; |
| 185 | } |
| 186 | EXPORT_SYMBOL_GPL(wcd9xxx_bulk_read); |
| 187 | |
| 188 | int wcd9xxx_bulk_write(struct wcd9xxx *wcd9xxx, unsigned short reg, |
| 189 | int count, u8 *buf) |
| 190 | { |
| 191 | int ret; |
| 192 | |
| 193 | mutex_lock(&wcd9xxx->io_lock); |
| 194 | |
| 195 | ret = wcd9xxx_write(wcd9xxx, reg, count, buf, false); |
| 196 | |
| 197 | mutex_unlock(&wcd9xxx->io_lock); |
| 198 | |
| 199 | return ret; |
| 200 | } |
| 201 | EXPORT_SYMBOL_GPL(wcd9xxx_bulk_write); |
| 202 | |
| 203 | static int wcd9xxx_slim_read_device(struct wcd9xxx *wcd9xxx, unsigned short reg, |
| 204 | int bytes, void *dest, bool interface) |
| 205 | { |
| 206 | int ret; |
| 207 | struct slim_ele_access msg; |
| 208 | int slim_read_tries = WCD9XXX_SLIM_RW_MAX_TRIES; |
| 209 | msg.start_offset = WCD9XXX_REGISTER_START_OFFSET + reg; |
| 210 | msg.num_bytes = bytes; |
| 211 | msg.comp = NULL; |
| 212 | |
| 213 | while (1) { |
| 214 | mutex_lock(&wcd9xxx->xfer_lock); |
| 215 | ret = slim_request_val_element(interface ? |
| 216 | wcd9xxx->slim_slave : wcd9xxx->slim, |
| 217 | &msg, dest, bytes); |
| 218 | mutex_unlock(&wcd9xxx->xfer_lock); |
| 219 | if (likely(ret == 0) || (--slim_read_tries == 0)) |
| 220 | break; |
| 221 | usleep_range(5000, 5000); |
| 222 | } |
| 223 | |
| 224 | if (ret) |
| 225 | pr_err("%s: Error, Codec read failed (%d)\n", __func__, ret); |
| 226 | |
| 227 | return ret; |
| 228 | } |
| 229 | /* Interface specifies whether the write is to the interface or general |
| 230 | * registers. |
| 231 | */ |
| 232 | static int wcd9xxx_slim_write_device(struct wcd9xxx *wcd9xxx, |
| 233 | unsigned short reg, int bytes, void *src, bool interface) |
| 234 | { |
| 235 | int ret; |
| 236 | struct slim_ele_access msg; |
| 237 | int slim_write_tries = WCD9XXX_SLIM_RW_MAX_TRIES; |
| 238 | msg.start_offset = WCD9XXX_REGISTER_START_OFFSET + reg; |
| 239 | msg.num_bytes = bytes; |
| 240 | msg.comp = NULL; |
| 241 | |
| 242 | while (1) { |
| 243 | mutex_lock(&wcd9xxx->xfer_lock); |
| 244 | ret = slim_change_val_element(interface ? |
| 245 | wcd9xxx->slim_slave : wcd9xxx->slim, |
| 246 | &msg, src, bytes); |
| 247 | mutex_unlock(&wcd9xxx->xfer_lock); |
| 248 | if (likely(ret == 0) || (--slim_write_tries == 0)) |
| 249 | break; |
| 250 | usleep_range(5000, 5000); |
| 251 | } |
| 252 | |
| 253 | if (ret) |
| 254 | pr_err("%s: Error, Codec write failed (%d)\n", __func__, ret); |
| 255 | |
| 256 | return ret; |
| 257 | } |
| 258 | |
| 259 | static struct mfd_cell tabla1x_devs[] = { |
| 260 | { |
| 261 | .name = "tabla1x_codec", |
| 262 | }, |
| 263 | }; |
| 264 | |
| 265 | static struct mfd_cell tabla_devs[] = { |
| 266 | { |
| 267 | .name = "tabla_codec", |
| 268 | }, |
| 269 | }; |
| 270 | |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 271 | static struct mfd_cell sitar_devs[] = { |
| 272 | { |
| 273 | .name = "sitar_codec", |
| 274 | }, |
| 275 | }; |
| 276 | |
Joonwoo Park | a717211 | 2012-07-23 16:03:49 -0700 | [diff] [blame] | 277 | static struct mfd_cell taiko_devs[] = { |
| 278 | { |
| 279 | .name = "taiko_codec", |
| 280 | }, |
| 281 | }; |
| 282 | |
Banajit Goswami | 4d6d891b | 2012-12-12 23:59:07 -0800 | [diff] [blame] | 283 | static struct mfd_cell tapan_devs[] = { |
| 284 | { |
| 285 | .name = "tapan_codec", |
| 286 | }, |
| 287 | }; |
| 288 | |
Joonwoo Park | 1277cb6 | 2013-03-19 14:16:51 -0700 | [diff] [blame] | 289 | static const struct wcd9xxx_codec_type wcd9xxx_codecs[] = { |
Joonwoo Park | 3cf3a94 | 2013-02-13 14:18:22 -0800 | [diff] [blame] | 290 | { |
Joonwoo Park | 1277cb6 | 2013-03-19 14:16:51 -0700 | [diff] [blame] | 291 | TABLA_MAJOR, cpu_to_le16(0x1), tabla1x_devs, |
| 292 | ARRAY_SIZE(tabla1x_devs), TABLA_NUM_IRQS, -1, |
| 293 | WCD9XXX_SLIM_SLAVE_ADDR_TYPE_TABLA, 0x03, |
Joonwoo Park | 3cf3a94 | 2013-02-13 14:18:22 -0800 | [diff] [blame] | 294 | }, |
| 295 | { |
Joonwoo Park | 1277cb6 | 2013-03-19 14:16:51 -0700 | [diff] [blame] | 296 | TABLA_MAJOR, cpu_to_le16(0x2), tabla_devs, |
| 297 | ARRAY_SIZE(tabla_devs), TABLA_NUM_IRQS, -1, |
| 298 | WCD9XXX_SLIM_SLAVE_ADDR_TYPE_TABLA, 0x03 |
Joonwoo Park | 559a5bf | 2013-02-15 14:46:36 -0800 | [diff] [blame] | 299 | }, |
Joonwoo Park | 3cf3a94 | 2013-02-13 14:18:22 -0800 | [diff] [blame] | 300 | { |
Joonwoo Park | 1277cb6 | 2013-03-19 14:16:51 -0700 | [diff] [blame] | 301 | /* Siter version 1 has same major chip id with Tabla */ |
| 302 | TABLA_MAJOR, cpu_to_le16(0x0), sitar_devs, |
| 303 | ARRAY_SIZE(sitar_devs), SITAR_NUM_IRQS, -1, |
| 304 | WCD9XXX_SLIM_SLAVE_ADDR_TYPE_TABLA, 0x01 |
Joonwoo Park | 3cf3a94 | 2013-02-13 14:18:22 -0800 | [diff] [blame] | 305 | }, |
| 306 | { |
Joonwoo Park | 1277cb6 | 2013-03-19 14:16:51 -0700 | [diff] [blame] | 307 | SITAR_MAJOR, cpu_to_le16(0x1), sitar_devs, |
| 308 | ARRAY_SIZE(sitar_devs), SITAR_NUM_IRQS, -1, |
| 309 | WCD9XXX_SLIM_SLAVE_ADDR_TYPE_TABLA, 0x01 |
Bhalchandra Gajare | 750d12d | 2013-03-01 20:56:36 -0800 | [diff] [blame] | 310 | }, |
| 311 | { |
Joonwoo Park | 1277cb6 | 2013-03-19 14:16:51 -0700 | [diff] [blame] | 312 | SITAR_MAJOR, cpu_to_le16(0x2), sitar_devs, |
| 313 | ARRAY_SIZE(sitar_devs), SITAR_NUM_IRQS, -1, |
| 314 | WCD9XXX_SLIM_SLAVE_ADDR_TYPE_TABLA, 0x01 |
Joonwoo Park | 3cf3a94 | 2013-02-13 14:18:22 -0800 | [diff] [blame] | 315 | }, |
| 316 | { |
Joonwoo Park | 1277cb6 | 2013-03-19 14:16:51 -0700 | [diff] [blame] | 317 | TAIKO_MAJOR, cpu_to_le16(0x0), taiko_devs, |
| 318 | ARRAY_SIZE(taiko_devs), TAIKO_NUM_IRQS, 1, |
| 319 | WCD9XXX_SLIM_SLAVE_ADDR_TYPE_TAIKO, 0x01 |
Joonwoo Park | 3cf3a94 | 2013-02-13 14:18:22 -0800 | [diff] [blame] | 320 | }, |
| 321 | { |
Joonwoo Park | 1277cb6 | 2013-03-19 14:16:51 -0700 | [diff] [blame] | 322 | TAIKO_MAJOR, cpu_to_le16(0x1), taiko_devs, |
| 323 | ARRAY_SIZE(taiko_devs), TAIKO_NUM_IRQS, 2, |
| 324 | WCD9XXX_SLIM_SLAVE_ADDR_TYPE_TAIKO, 0x01 |
| 325 | }, |
| 326 | { |
| 327 | TAPAN_MAJOR, cpu_to_le16(0x0), tapan_devs, |
| 328 | ARRAY_SIZE(tapan_devs), TAPAN_NUM_IRQS, -1, |
| 329 | WCD9XXX_SLIM_SLAVE_ADDR_TYPE_TAIKO, 0x03 |
| 330 | }, |
| 331 | { |
| 332 | TAPAN_MAJOR, cpu_to_le16(0x1), tapan_devs, |
| 333 | ARRAY_SIZE(tapan_devs), TAPAN_NUM_IRQS, -1, |
| 334 | WCD9XXX_SLIM_SLAVE_ADDR_TYPE_TAIKO, 0x03 |
Joonwoo Park | 3cf3a94 | 2013-02-13 14:18:22 -0800 | [diff] [blame] | 335 | }, |
Venkat Sudhir | ee6c500 | 2012-09-06 11:27:32 -0700 | [diff] [blame] | 336 | }; |
| 337 | |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 338 | static void wcd9xxx_bring_up(struct wcd9xxx *wcd9xxx) |
| 339 | { |
| 340 | wcd9xxx_reg_write(wcd9xxx, WCD9XXX_A_LEAKAGE_CTL, 0x4); |
| 341 | wcd9xxx_reg_write(wcd9xxx, WCD9XXX_A_CDC_CTL, 0); |
| 342 | usleep_range(5000, 5000); |
| 343 | wcd9xxx_reg_write(wcd9xxx, WCD9XXX_A_CDC_CTL, 3); |
| 344 | wcd9xxx_reg_write(wcd9xxx, WCD9XXX_A_LEAKAGE_CTL, 3); |
| 345 | } |
| 346 | |
| 347 | static void wcd9xxx_bring_down(struct wcd9xxx *wcd9xxx) |
| 348 | { |
| 349 | wcd9xxx_reg_write(wcd9xxx, WCD9XXX_A_LEAKAGE_CTL, 0x7); |
| 350 | wcd9xxx_reg_write(wcd9xxx, WCD9XXX_A_LEAKAGE_CTL, 0x6); |
| 351 | wcd9xxx_reg_write(wcd9xxx, WCD9XXX_A_LEAKAGE_CTL, 0xe); |
| 352 | wcd9xxx_reg_write(wcd9xxx, WCD9XXX_A_LEAKAGE_CTL, 0x8); |
| 353 | } |
| 354 | |
| 355 | static int wcd9xxx_reset(struct wcd9xxx *wcd9xxx) |
| 356 | { |
| 357 | int ret; |
| 358 | |
Ravishankar Sarawadi | 839fcf3 | 2012-11-14 12:13:00 -0800 | [diff] [blame] | 359 | if (wcd9xxx->reset_gpio && wcd9xxx->slim_device_bootup) { |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 360 | ret = gpio_request(wcd9xxx->reset_gpio, "CDC_RESET"); |
| 361 | if (ret) { |
| 362 | pr_err("%s: Failed to request gpio %d\n", __func__, |
| 363 | wcd9xxx->reset_gpio); |
| 364 | wcd9xxx->reset_gpio = 0; |
| 365 | return ret; |
| 366 | } |
Ravishankar Sarawadi | 839fcf3 | 2012-11-14 12:13:00 -0800 | [diff] [blame] | 367 | } |
| 368 | if (wcd9xxx->reset_gpio) { |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 369 | gpio_direction_output(wcd9xxx->reset_gpio, 0); |
| 370 | msleep(20); |
| 371 | gpio_direction_output(wcd9xxx->reset_gpio, 1); |
| 372 | msleep(20); |
| 373 | } |
| 374 | return 0; |
| 375 | } |
| 376 | |
| 377 | static void wcd9xxx_free_reset(struct wcd9xxx *wcd9xxx) |
| 378 | { |
| 379 | if (wcd9xxx->reset_gpio) { |
| 380 | gpio_free(wcd9xxx->reset_gpio); |
| 381 | wcd9xxx->reset_gpio = 0; |
| 382 | } |
| 383 | } |
Joonwoo Park | 1277cb6 | 2013-03-19 14:16:51 -0700 | [diff] [blame] | 384 | |
| 385 | static const struct wcd9xxx_codec_type |
| 386 | *wcd9xxx_check_codec_type(struct wcd9xxx *wcd9xxx, u8 *version) |
Venkat Sudhir | ee6c500 | 2012-09-06 11:27:32 -0700 | [diff] [blame] | 387 | { |
Joonwoo Park | 1277cb6 | 2013-03-19 14:16:51 -0700 | [diff] [blame] | 388 | int i, rc; |
| 389 | const struct wcd9xxx_codec_type *c, *d = NULL; |
| 390 | |
| 391 | rc = wcd9xxx_bulk_read(wcd9xxx, WCD9XXX_A_CHIP_ID_BYTE_0, |
| 392 | sizeof(wcd9xxx->id_minor), |
| 393 | (u8 *)&wcd9xxx->id_minor); |
| 394 | if (rc < 0) |
| 395 | goto exit; |
| 396 | |
| 397 | rc = wcd9xxx_bulk_read(wcd9xxx, WCD9XXX_A_CHIP_ID_BYTE_2, |
| 398 | sizeof(wcd9xxx->id_major), |
| 399 | (u8 *)&wcd9xxx->id_major); |
| 400 | if (rc < 0) |
| 401 | goto exit; |
| 402 | dev_dbg(wcd9xxx->dev, "%s: wcd9xxx chip id major 0x%x, minor 0x%x\n", |
| 403 | __func__, wcd9xxx->id_major, wcd9xxx->id_minor); |
| 404 | |
| 405 | for (i = 0, c = &wcd9xxx_codecs[0]; i < ARRAY_SIZE(wcd9xxx_codecs); |
| 406 | i++, c++) { |
| 407 | if (c->id_major == wcd9xxx->id_major) { |
| 408 | if (c->id_minor == wcd9xxx->id_minor) { |
| 409 | d = c; |
| 410 | dev_dbg(wcd9xxx->dev, |
| 411 | "%s: exact match %s\n", __func__, |
| 412 | d->dev->name); |
| 413 | break; |
| 414 | } else if (!d) { |
| 415 | d = c; |
| 416 | } else { |
| 417 | if ((d->id_minor < c->id_minor) || |
| 418 | (d->id_minor == c->id_minor && |
| 419 | d->version < c->version)) |
| 420 | d = c; |
| 421 | } |
| 422 | dev_dbg(wcd9xxx->dev, |
| 423 | "%s: best match %s, major 0x%x, minor 0x%x\n", |
| 424 | __func__, d->dev->name, d->id_major, |
| 425 | d->id_minor); |
| 426 | } |
Venkat Sudhir | ee6c500 | 2012-09-06 11:27:32 -0700 | [diff] [blame] | 427 | } |
| 428 | |
Joonwoo Park | 1277cb6 | 2013-03-19 14:16:51 -0700 | [diff] [blame] | 429 | if (!d) { |
| 430 | dev_warn(wcd9xxx->dev, |
| 431 | "%s: driver for id major 0x%x, minor 0x%x not found\n", |
| 432 | __func__, wcd9xxx->id_major, wcd9xxx->id_minor); |
| 433 | } else { |
| 434 | if (d->version > -1) { |
| 435 | *version = d->version; |
| 436 | } else { |
| 437 | rc = wcd9xxx_reg_read(wcd9xxx, WCD9XXX_A_CHIP_VERSION); |
| 438 | if (rc < 0) { |
| 439 | d = NULL; |
| 440 | goto exit; |
| 441 | } |
| 442 | *version = (u8)rc & 0x1F; |
Venkat Sudhir | ee6c500 | 2012-09-06 11:27:32 -0700 | [diff] [blame] | 443 | } |
Joonwoo Park | 1277cb6 | 2013-03-19 14:16:51 -0700 | [diff] [blame] | 444 | dev_info(wcd9xxx->dev, |
| 445 | "%s: detected %s, major 0x%x, minor 0x%x, ver 0x%x\n", |
| 446 | __func__, d->dev->name, d->id_major, d->id_minor, |
| 447 | *version); |
Venkat Sudhir | ee6c500 | 2012-09-06 11:27:32 -0700 | [diff] [blame] | 448 | } |
Venkat Sudhir | ee6c500 | 2012-09-06 11:27:32 -0700 | [diff] [blame] | 449 | exit: |
Joonwoo Park | 1277cb6 | 2013-03-19 14:16:51 -0700 | [diff] [blame] | 450 | return d; |
Venkat Sudhir | ee6c500 | 2012-09-06 11:27:32 -0700 | [diff] [blame] | 451 | } |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 452 | |
Joonwoo Park | f6574c7 | 2012-10-10 17:29:57 -0700 | [diff] [blame] | 453 | static int wcd9xxx_device_init(struct wcd9xxx *wcd9xxx) |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 454 | { |
| 455 | int ret; |
Joonwoo Park | 1277cb6 | 2013-03-19 14:16:51 -0700 | [diff] [blame] | 456 | u8 version; |
| 457 | const struct wcd9xxx_codec_type *found; |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 458 | |
| 459 | mutex_init(&wcd9xxx->io_lock); |
| 460 | mutex_init(&wcd9xxx->xfer_lock); |
| 461 | |
| 462 | mutex_init(&wcd9xxx->pm_lock); |
| 463 | wcd9xxx->wlock_holders = 0; |
| 464 | wcd9xxx->pm_state = WCD9XXX_PM_SLEEPABLE; |
| 465 | init_waitqueue_head(&wcd9xxx->pm_wq); |
Stephen Boyd | 2fcabf9 | 2012-05-30 10:41:11 -0700 | [diff] [blame] | 466 | pm_qos_add_request(&wcd9xxx->pm_qos_req, PM_QOS_CPU_DMA_LATENCY, |
| 467 | PM_QOS_DEFAULT_VALUE); |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 468 | |
| 469 | dev_set_drvdata(wcd9xxx->dev, wcd9xxx); |
| 470 | |
| 471 | wcd9xxx_bring_up(wcd9xxx); |
| 472 | |
Joonwoo Park | 1277cb6 | 2013-03-19 14:16:51 -0700 | [diff] [blame] | 473 | found = wcd9xxx_check_codec_type(wcd9xxx, &version); |
| 474 | if (!found) { |
| 475 | ret = -ENODEV; |
Gopikrishnaiah Anandan | 7d62cfd | 2013-07-25 15:46:50 -0400 | [diff] [blame] | 476 | goto err; |
Joonwoo Park | 1277cb6 | 2013-03-19 14:16:51 -0700 | [diff] [blame] | 477 | } else { |
| 478 | wcd9xxx->codec_type = found; |
| 479 | wcd9xxx->version = version; |
| 480 | } |
Joonwoo Park | f6574c7 | 2012-10-10 17:29:57 -0700 | [diff] [blame] | 481 | |
Kiran Kandi | 725f849 | 2012-08-06 13:45:16 -0700 | [diff] [blame] | 482 | if (wcd9xxx->irq != -1) { |
| 483 | ret = wcd9xxx_irq_init(wcd9xxx); |
| 484 | if (ret) { |
| 485 | pr_err("IRQ initialization failed\n"); |
| 486 | goto err; |
| 487 | } |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 488 | } |
| 489 | |
Joonwoo Park | 1277cb6 | 2013-03-19 14:16:51 -0700 | [diff] [blame] | 490 | ret = mfd_add_devices(wcd9xxx->dev, -1, found->dev, found->size, |
Joonwoo Park | a717211 | 2012-07-23 16:03:49 -0700 | [diff] [blame] | 491 | NULL, 0); |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 492 | if (ret != 0) { |
| 493 | dev_err(wcd9xxx->dev, "Failed to add children: %d\n", ret); |
| 494 | goto err_irq; |
| 495 | } |
| 496 | return ret; |
| 497 | err_irq: |
| 498 | wcd9xxx_irq_exit(wcd9xxx); |
| 499 | err: |
| 500 | wcd9xxx_bring_down(wcd9xxx); |
Stephen Boyd | 2fcabf9 | 2012-05-30 10:41:11 -0700 | [diff] [blame] | 501 | pm_qos_remove_request(&wcd9xxx->pm_qos_req); |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 502 | mutex_destroy(&wcd9xxx->pm_lock); |
| 503 | mutex_destroy(&wcd9xxx->io_lock); |
| 504 | mutex_destroy(&wcd9xxx->xfer_lock); |
| 505 | return ret; |
| 506 | } |
| 507 | |
| 508 | static void wcd9xxx_device_exit(struct wcd9xxx *wcd9xxx) |
| 509 | { |
| 510 | wcd9xxx_irq_exit(wcd9xxx); |
| 511 | wcd9xxx_bring_down(wcd9xxx); |
| 512 | wcd9xxx_free_reset(wcd9xxx); |
| 513 | mutex_destroy(&wcd9xxx->pm_lock); |
Stephen Boyd | 2fcabf9 | 2012-05-30 10:41:11 -0700 | [diff] [blame] | 514 | pm_qos_remove_request(&wcd9xxx->pm_qos_req); |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 515 | mutex_destroy(&wcd9xxx->io_lock); |
| 516 | mutex_destroy(&wcd9xxx->xfer_lock); |
Venkat Sudhir | db7aa2b | 2012-05-15 15:06:14 -0700 | [diff] [blame] | 517 | if (wcd9xxx_intf == WCD9XXX_INTERFACE_TYPE_SLIMBUS) |
| 518 | slim_remove_device(wcd9xxx->slim_slave); |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 519 | kfree(wcd9xxx); |
| 520 | } |
| 521 | |
| 522 | |
| 523 | #ifdef CONFIG_DEBUG_FS |
| 524 | struct wcd9xxx *debugCodec; |
| 525 | |
| 526 | static struct dentry *debugfs_wcd9xxx_dent; |
| 527 | static struct dentry *debugfs_peek; |
| 528 | static struct dentry *debugfs_poke; |
| 529 | |
| 530 | static unsigned char read_data; |
| 531 | |
| 532 | static int codec_debug_open(struct inode *inode, struct file *file) |
| 533 | { |
| 534 | file->private_data = inode->i_private; |
| 535 | return 0; |
| 536 | } |
| 537 | |
| 538 | static int get_parameters(char *buf, long int *param1, int num_of_par) |
| 539 | { |
| 540 | char *token; |
| 541 | int base, cnt; |
| 542 | |
| 543 | token = strsep(&buf, " "); |
| 544 | |
| 545 | for (cnt = 0; cnt < num_of_par; cnt++) { |
| 546 | if (token != NULL) { |
| 547 | if ((token[1] == 'x') || (token[1] == 'X')) |
| 548 | base = 16; |
| 549 | else |
| 550 | base = 10; |
| 551 | |
| 552 | if (strict_strtoul(token, base, ¶m1[cnt]) != 0) |
| 553 | return -EINVAL; |
| 554 | |
| 555 | token = strsep(&buf, " "); |
| 556 | } else |
| 557 | return -EINVAL; |
| 558 | } |
| 559 | return 0; |
| 560 | } |
| 561 | |
| 562 | static ssize_t codec_debug_read(struct file *file, char __user *ubuf, |
| 563 | size_t count, loff_t *ppos) |
| 564 | { |
| 565 | char lbuf[8]; |
| 566 | |
| 567 | snprintf(lbuf, sizeof(lbuf), "0x%x\n", read_data); |
| 568 | return simple_read_from_buffer(ubuf, count, ppos, lbuf, |
| 569 | strnlen(lbuf, 7)); |
| 570 | } |
| 571 | |
| 572 | |
| 573 | static ssize_t codec_debug_write(struct file *filp, |
| 574 | const char __user *ubuf, size_t cnt, loff_t *ppos) |
| 575 | { |
| 576 | char *access_str = filp->private_data; |
| 577 | char lbuf[32]; |
| 578 | int rc; |
| 579 | long int param[5]; |
| 580 | |
| 581 | if (cnt > sizeof(lbuf) - 1) |
| 582 | return -EINVAL; |
| 583 | |
| 584 | rc = copy_from_user(lbuf, ubuf, cnt); |
| 585 | if (rc) |
| 586 | return -EFAULT; |
| 587 | |
| 588 | lbuf[cnt] = '\0'; |
| 589 | |
| 590 | if (!strncmp(access_str, "poke", 6)) { |
| 591 | /* write */ |
| 592 | rc = get_parameters(lbuf, param, 2); |
| 593 | if ((param[0] <= 0x3FF) && (param[1] <= 0xFF) && |
| 594 | (rc == 0)) |
| 595 | wcd9xxx_interface_reg_write(debugCodec, param[0], |
| 596 | param[1]); |
| 597 | else |
| 598 | rc = -EINVAL; |
| 599 | } else if (!strncmp(access_str, "peek", 6)) { |
| 600 | /* read */ |
| 601 | rc = get_parameters(lbuf, param, 1); |
| 602 | if ((param[0] <= 0x3FF) && (rc == 0)) |
| 603 | read_data = wcd9xxx_interface_reg_read(debugCodec, |
| 604 | param[0]); |
| 605 | else |
| 606 | rc = -EINVAL; |
| 607 | } |
| 608 | |
| 609 | if (rc == 0) |
| 610 | rc = cnt; |
| 611 | else |
| 612 | pr_err("%s: rc = %d\n", __func__, rc); |
| 613 | |
| 614 | return rc; |
| 615 | } |
| 616 | |
| 617 | static const struct file_operations codec_debug_ops = { |
| 618 | .open = codec_debug_open, |
| 619 | .write = codec_debug_write, |
| 620 | .read = codec_debug_read |
| 621 | }; |
| 622 | #endif |
| 623 | |
Joonwoo Park | 5d170a4 | 2013-04-10 15:16:36 -0700 | [diff] [blame] | 624 | static int wcd9xxx_init_supplies(struct wcd9xxx *wcd9xxx, |
| 625 | struct wcd9xxx_pdata *pdata) |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 626 | { |
| 627 | int ret; |
| 628 | int i; |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 629 | wcd9xxx->supplies = kzalloc(sizeof(struct regulator_bulk_data) * |
| 630 | ARRAY_SIZE(pdata->regulator), |
| 631 | GFP_KERNEL); |
| 632 | if (!wcd9xxx->supplies) { |
| 633 | ret = -ENOMEM; |
| 634 | goto err; |
| 635 | } |
| 636 | |
Kiran Kandi | 725f849 | 2012-08-06 13:45:16 -0700 | [diff] [blame] | 637 | wcd9xxx->num_of_supplies = 0; |
Simmi Pateriya | 4fd6993 | 2012-10-26 00:57:06 +0530 | [diff] [blame] | 638 | |
Joonwoo Park | 5d170a4 | 2013-04-10 15:16:36 -0700 | [diff] [blame] | 639 | if (ARRAY_SIZE(pdata->regulator) > WCD9XXX_MAX_REGULATOR) { |
Simmi Pateriya | 4fd6993 | 2012-10-26 00:57:06 +0530 | [diff] [blame] | 640 | pr_err("%s: Array Size out of bound\n", __func__); |
| 641 | ret = -EINVAL; |
| 642 | goto err; |
| 643 | } |
| 644 | |
Kiran Kandi | 725f849 | 2012-08-06 13:45:16 -0700 | [diff] [blame] | 645 | for (i = 0; i < ARRAY_SIZE(pdata->regulator); i++) { |
| 646 | if (pdata->regulator[i].name) { |
| 647 | wcd9xxx->supplies[i].supply = pdata->regulator[i].name; |
| 648 | wcd9xxx->num_of_supplies++; |
| 649 | } |
| 650 | } |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 651 | |
Kiran Kandi | 725f849 | 2012-08-06 13:45:16 -0700 | [diff] [blame] | 652 | ret = regulator_bulk_get(wcd9xxx->dev, wcd9xxx->num_of_supplies, |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 653 | wcd9xxx->supplies); |
| 654 | if (ret != 0) { |
| 655 | dev_err(wcd9xxx->dev, "Failed to get supplies: err = %d\n", |
| 656 | ret); |
| 657 | goto err_supplies; |
| 658 | } |
| 659 | |
Kiran Kandi | 725f849 | 2012-08-06 13:45:16 -0700 | [diff] [blame] | 660 | for (i = 0; i < wcd9xxx->num_of_supplies; i++) { |
Joonwoo Park | 5d170a4 | 2013-04-10 15:16:36 -0700 | [diff] [blame] | 661 | if (regulator_count_voltages(wcd9xxx->supplies[i].consumer) <= |
| 662 | 0) |
| 663 | continue; |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 664 | ret = regulator_set_voltage(wcd9xxx->supplies[i].consumer, |
Joonwoo Park | 5d170a4 | 2013-04-10 15:16:36 -0700 | [diff] [blame] | 665 | pdata->regulator[i].min_uV, |
| 666 | pdata->regulator[i].max_uV); |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 667 | if (ret) { |
| 668 | pr_err("%s: Setting regulator voltage failed for " |
| 669 | "regulator %s err = %d\n", __func__, |
| 670 | wcd9xxx->supplies[i].supply, ret); |
| 671 | goto err_get; |
| 672 | } |
| 673 | |
| 674 | ret = regulator_set_optimum_mode(wcd9xxx->supplies[i].consumer, |
Joonwoo Park | 5d170a4 | 2013-04-10 15:16:36 -0700 | [diff] [blame] | 675 | pdata->regulator[i].optimum_uA); |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 676 | if (ret < 0) { |
| 677 | pr_err("%s: Setting regulator optimum mode failed for " |
| 678 | "regulator %s err = %d\n", __func__, |
| 679 | wcd9xxx->supplies[i].supply, ret); |
| 680 | goto err_get; |
Joonwoo Park | 5d170a4 | 2013-04-10 15:16:36 -0700 | [diff] [blame] | 681 | } else { |
| 682 | ret = 0; |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 683 | } |
| 684 | } |
| 685 | |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 686 | return ret; |
| 687 | |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 688 | err_get: |
Kiran Kandi | 725f849 | 2012-08-06 13:45:16 -0700 | [diff] [blame] | 689 | regulator_bulk_free(wcd9xxx->num_of_supplies, wcd9xxx->supplies); |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 690 | err_supplies: |
| 691 | kfree(wcd9xxx->supplies); |
| 692 | err: |
| 693 | return ret; |
| 694 | } |
| 695 | |
Joonwoo Park | 5d170a4 | 2013-04-10 15:16:36 -0700 | [diff] [blame] | 696 | static int wcd9xxx_enable_static_supplies(struct wcd9xxx *wcd9xxx, |
| 697 | struct wcd9xxx_pdata *pdata) |
| 698 | { |
| 699 | int i; |
| 700 | int ret = 0; |
| 701 | |
| 702 | for (i = 0; i < wcd9xxx->num_of_supplies; i++) { |
| 703 | if (pdata->regulator[i].ondemand) |
| 704 | continue; |
| 705 | ret = regulator_enable(wcd9xxx->supplies[i].consumer); |
| 706 | if (ret) { |
| 707 | pr_err("%s: Failed to enable %s\n", __func__, |
| 708 | wcd9xxx->supplies[i].supply); |
| 709 | break; |
| 710 | } else { |
| 711 | pr_debug("%s: Enabled regulator %s\n", __func__, |
| 712 | wcd9xxx->supplies[i].supply); |
| 713 | } |
| 714 | } |
| 715 | |
| 716 | while (ret && --i) |
| 717 | if (!pdata->regulator[i].ondemand) |
| 718 | regulator_disable(wcd9xxx->supplies[i].consumer); |
| 719 | |
| 720 | return ret; |
| 721 | } |
| 722 | |
Venkat Sudhir | 4920386 | 2012-05-21 14:29:13 -0700 | [diff] [blame] | 723 | static void wcd9xxx_disable_supplies(struct wcd9xxx *wcd9xxx, |
| 724 | struct wcd9xxx_pdata *pdata) |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 725 | { |
| 726 | int i; |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 727 | |
Kiran Kandi | 725f849 | 2012-08-06 13:45:16 -0700 | [diff] [blame] | 728 | regulator_bulk_disable(wcd9xxx->num_of_supplies, |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 729 | wcd9xxx->supplies); |
Kiran Kandi | 725f849 | 2012-08-06 13:45:16 -0700 | [diff] [blame] | 730 | for (i = 0; i < wcd9xxx->num_of_supplies; i++) { |
Joonwoo Park | 5d170a4 | 2013-04-10 15:16:36 -0700 | [diff] [blame] | 731 | if (regulator_count_voltages(wcd9xxx->supplies[i].consumer) <= |
| 732 | 0) |
| 733 | continue; |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 734 | regulator_set_voltage(wcd9xxx->supplies[i].consumer, 0, |
Joonwoo Park | 5d170a4 | 2013-04-10 15:16:36 -0700 | [diff] [blame] | 735 | pdata->regulator[i].max_uV); |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 736 | regulator_set_optimum_mode(wcd9xxx->supplies[i].consumer, 0); |
| 737 | } |
Kiran Kandi | 725f849 | 2012-08-06 13:45:16 -0700 | [diff] [blame] | 738 | regulator_bulk_free(wcd9xxx->num_of_supplies, wcd9xxx->supplies); |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 739 | kfree(wcd9xxx->supplies); |
| 740 | } |
| 741 | |
Venkat Sudhir | a50a376 | 2012-11-26 12:12:15 -0800 | [diff] [blame] | 742 | enum wcd9xxx_intf_status wcd9xxx_get_intf_type(void) |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 743 | { |
| 744 | return wcd9xxx_intf; |
| 745 | } |
Venkat Sudhir | a50a376 | 2012-11-26 12:12:15 -0800 | [diff] [blame] | 746 | |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 747 | EXPORT_SYMBOL_GPL(wcd9xxx_get_intf_type); |
| 748 | |
| 749 | struct wcd9xxx_i2c *get_i2c_wcd9xxx_device_info(u16 reg) |
| 750 | { |
| 751 | u16 mask = 0x0f00; |
| 752 | int value = 0; |
| 753 | struct wcd9xxx_i2c *wcd9xxx = NULL; |
| 754 | value = ((reg & mask) >> 8) & 0x000f; |
| 755 | switch (value) { |
| 756 | case 0: |
| 757 | wcd9xxx = &wcd9xxx_modules[0]; |
| 758 | break; |
| 759 | case 1: |
| 760 | wcd9xxx = &wcd9xxx_modules[1]; |
| 761 | break; |
| 762 | case 2: |
| 763 | wcd9xxx = &wcd9xxx_modules[2]; |
| 764 | break; |
| 765 | case 3: |
| 766 | wcd9xxx = &wcd9xxx_modules[3]; |
| 767 | break; |
| 768 | default: |
| 769 | break; |
| 770 | } |
| 771 | return wcd9xxx; |
| 772 | } |
| 773 | |
| 774 | int wcd9xxx_i2c_write_device(u16 reg, u8 *value, |
| 775 | u32 bytes) |
| 776 | { |
| 777 | |
| 778 | struct i2c_msg *msg; |
| 779 | int ret = 0; |
| 780 | u8 reg_addr = 0; |
| 781 | u8 data[bytes + 1]; |
| 782 | struct wcd9xxx_i2c *wcd9xxx; |
| 783 | |
| 784 | wcd9xxx = get_i2c_wcd9xxx_device_info(reg); |
| 785 | if (wcd9xxx == NULL || wcd9xxx->client == NULL) { |
| 786 | pr_err("failed to get device info\n"); |
| 787 | return -ENODEV; |
| 788 | } |
| 789 | reg_addr = (u8)reg; |
| 790 | msg = &wcd9xxx->xfer_msg[0]; |
| 791 | msg->addr = wcd9xxx->client->addr; |
| 792 | msg->len = bytes + 1; |
| 793 | msg->flags = 0; |
| 794 | data[0] = reg; |
| 795 | data[1] = *value; |
| 796 | msg->buf = data; |
| 797 | ret = i2c_transfer(wcd9xxx->client->adapter, wcd9xxx->xfer_msg, 1); |
| 798 | /* Try again if the write fails */ |
| 799 | if (ret != 1) { |
| 800 | ret = i2c_transfer(wcd9xxx->client->adapter, |
| 801 | wcd9xxx->xfer_msg, 1); |
| 802 | if (ret != 1) { |
| 803 | pr_err("failed to write the device\n"); |
| 804 | return ret; |
| 805 | } |
| 806 | } |
| 807 | pr_debug("write sucess register = %x val = %x\n", reg, data[1]); |
| 808 | return 0; |
| 809 | } |
| 810 | |
| 811 | |
| 812 | int wcd9xxx_i2c_read_device(unsigned short reg, |
| 813 | int bytes, unsigned char *dest) |
| 814 | { |
| 815 | struct i2c_msg *msg; |
| 816 | int ret = 0; |
| 817 | u8 reg_addr = 0; |
| 818 | struct wcd9xxx_i2c *wcd9xxx; |
| 819 | u8 i = 0; |
| 820 | |
| 821 | wcd9xxx = get_i2c_wcd9xxx_device_info(reg); |
| 822 | if (wcd9xxx == NULL || wcd9xxx->client == NULL) { |
| 823 | pr_err("failed to get device info\n"); |
| 824 | return -ENODEV; |
| 825 | } |
| 826 | for (i = 0; i < bytes; i++) { |
| 827 | reg_addr = (u8)reg++; |
| 828 | msg = &wcd9xxx->xfer_msg[0]; |
| 829 | msg->addr = wcd9xxx->client->addr; |
| 830 | msg->len = 1; |
| 831 | msg->flags = 0; |
| 832 | msg->buf = ®_addr; |
| 833 | |
| 834 | msg = &wcd9xxx->xfer_msg[1]; |
| 835 | msg->addr = wcd9xxx->client->addr; |
| 836 | msg->len = 1; |
| 837 | msg->flags = I2C_M_RD; |
| 838 | msg->buf = dest++; |
| 839 | ret = i2c_transfer(wcd9xxx->client->adapter, |
| 840 | wcd9xxx->xfer_msg, 2); |
| 841 | |
| 842 | /* Try again if read fails first time */ |
| 843 | if (ret != 2) { |
| 844 | ret = i2c_transfer(wcd9xxx->client->adapter, |
| 845 | wcd9xxx->xfer_msg, 2); |
| 846 | if (ret != 2) { |
| 847 | pr_err("failed to read wcd9xxx register\n"); |
| 848 | return ret; |
| 849 | } |
| 850 | } |
| 851 | } |
| 852 | return 0; |
| 853 | } |
| 854 | |
| 855 | int wcd9xxx_i2c_read(struct wcd9xxx *wcd9xxx, unsigned short reg, |
| 856 | int bytes, void *dest, bool interface_reg) |
| 857 | { |
| 858 | return wcd9xxx_i2c_read_device(reg, bytes, dest); |
| 859 | } |
| 860 | |
| 861 | int wcd9xxx_i2c_write(struct wcd9xxx *wcd9xxx, unsigned short reg, |
| 862 | int bytes, void *src, bool interface_reg) |
| 863 | { |
| 864 | return wcd9xxx_i2c_write_device(reg, src, bytes); |
| 865 | } |
| 866 | |
Venkat Sudhir | a50a376 | 2012-11-26 12:12:15 -0800 | [diff] [blame] | 867 | static int wcd9xxx_i2c_get_client_index(struct i2c_client *client, |
| 868 | int *wcd9xx_index) |
| 869 | { |
| 870 | int ret = 0; |
| 871 | switch (client->addr) { |
| 872 | case WCD9XXX_I2C_TOP_SLAVE_ADDR: |
| 873 | *wcd9xx_index = WCD9XXX_I2C_TOP_LEVEL; |
| 874 | break; |
| 875 | case WCD9XXX_ANALOG_I2C_SLAVE_ADDR: |
| 876 | *wcd9xx_index = WCD9XXX_I2C_ANALOG; |
| 877 | break; |
| 878 | case WCD9XXX_DIGITAL1_I2C_SLAVE_ADDR: |
| 879 | *wcd9xx_index = WCD9XXX_I2C_DIGITAL_1; |
| 880 | break; |
| 881 | case WCD9XXX_DIGITAL2_I2C_SLAVE_ADDR: |
| 882 | *wcd9xx_index = WCD9XXX_I2C_DIGITAL_2; |
| 883 | break; |
| 884 | default: |
| 885 | ret = -EINVAL; |
| 886 | break; |
| 887 | } |
| 888 | return ret; |
| 889 | } |
| 890 | |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 891 | static int __devinit wcd9xxx_i2c_probe(struct i2c_client *client, |
| 892 | const struct i2c_device_id *id) |
| 893 | { |
Venkat Sudhir | a50a376 | 2012-11-26 12:12:15 -0800 | [diff] [blame] | 894 | struct wcd9xxx *wcd9xxx = NULL; |
| 895 | struct wcd9xxx_pdata *pdata = NULL; |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 896 | int val = 0; |
| 897 | int ret = 0; |
Venkat Sudhir | a50a376 | 2012-11-26 12:12:15 -0800 | [diff] [blame] | 898 | int wcd9xx_index = 0; |
Venkat Sudhir | a41630a | 2012-10-27 00:57:31 -0700 | [diff] [blame] | 899 | struct device *dev; |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 900 | |
Venkat Sudhir | a50a376 | 2012-11-26 12:12:15 -0800 | [diff] [blame] | 901 | pr_debug("%s: interface status %d\n", __func__, wcd9xxx_intf); |
Venkat Sudhir | db7aa2b | 2012-05-15 15:06:14 -0700 | [diff] [blame] | 902 | if (wcd9xxx_intf == WCD9XXX_INTERFACE_TYPE_SLIMBUS) { |
Venkat Sudhir | a41630a | 2012-10-27 00:57:31 -0700 | [diff] [blame] | 903 | dev_dbg(&client->dev, "%s:Codec is detected in slimbus mode\n", |
Venkat Sudhir | a50a376 | 2012-11-26 12:12:15 -0800 | [diff] [blame] | 904 | __func__); |
Venkat Sudhir | db7aa2b | 2012-05-15 15:06:14 -0700 | [diff] [blame] | 905 | return -ENODEV; |
Venkat Sudhir | a50a376 | 2012-11-26 12:12:15 -0800 | [diff] [blame] | 906 | } else if (wcd9xxx_intf == WCD9XXX_INTERFACE_TYPE_I2C) { |
| 907 | ret = wcd9xxx_i2c_get_client_index(client, &wcd9xx_index); |
| 908 | if (ret != 0) |
| 909 | dev_err(&client->dev, "%s: I2C set codec I2C\n" |
| 910 | "client failed\n", __func__); |
| 911 | else { |
| 912 | dev_err(&client->dev, "%s:probe for other slaves\n" |
| 913 | "devices of codec I2C slave Addr = %x\n", |
| 914 | __func__, client->addr); |
| 915 | wcd9xxx_modules[wcd9xx_index].client = client; |
| 916 | } |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 917 | return ret; |
Venkat Sudhir | a50a376 | 2012-11-26 12:12:15 -0800 | [diff] [blame] | 918 | } else if (wcd9xxx_intf == WCD9XXX_INTERFACE_TYPE_PROBING) { |
| 919 | dev = &client->dev; |
| 920 | if (client->dev.of_node) { |
| 921 | dev_dbg(&client->dev, "%s:Platform data\n" |
| 922 | "from device tree\n", __func__); |
| 923 | pdata = wcd9xxx_populate_dt_pdata(&client->dev); |
| 924 | client->dev.platform_data = pdata; |
| 925 | } else { |
| 926 | dev_dbg(&client->dev, "%s:Platform data from\n" |
| 927 | "board file\n", __func__); |
| 928 | pdata = client->dev.platform_data; |
| 929 | } |
| 930 | wcd9xxx = kzalloc(sizeof(struct wcd9xxx), GFP_KERNEL); |
| 931 | if (wcd9xxx == NULL) { |
| 932 | pr_err("%s: error, allocation failed\n", __func__); |
| 933 | ret = -ENOMEM; |
| 934 | goto fail; |
| 935 | } |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 936 | |
Venkat Sudhir | a50a376 | 2012-11-26 12:12:15 -0800 | [diff] [blame] | 937 | if (!pdata) { |
| 938 | dev_dbg(&client->dev, "no platform data?\n"); |
| 939 | ret = -EINVAL; |
| 940 | goto fail; |
| 941 | } |
| 942 | if (i2c_check_functionality(client->adapter, |
| 943 | I2C_FUNC_I2C) == 0) { |
| 944 | dev_dbg(&client->dev, "can't talk I2C?\n"); |
| 945 | ret = -EIO; |
| 946 | goto fail; |
| 947 | } |
| 948 | dev_set_drvdata(&client->dev, wcd9xxx); |
| 949 | wcd9xxx->dev = &client->dev; |
| 950 | wcd9xxx->reset_gpio = pdata->reset_gpio; |
Ravishankar Sarawadi | 2293efe | 2013-01-11 16:37:23 -0800 | [diff] [blame] | 951 | wcd9xxx->slim_device_bootup = true; |
Venkat Sudhir | a50a376 | 2012-11-26 12:12:15 -0800 | [diff] [blame] | 952 | if (client->dev.of_node) |
| 953 | wcd9xxx->mclk_rate = pdata->mclk_rate; |
Joonwoo Park | 5d170a4 | 2013-04-10 15:16:36 -0700 | [diff] [blame] | 954 | |
| 955 | ret = wcd9xxx_init_supplies(wcd9xxx, pdata); |
Venkat Sudhir | a50a376 | 2012-11-26 12:12:15 -0800 | [diff] [blame] | 956 | if (ret) { |
| 957 | pr_err("%s: Fail to enable Codec supplies\n", |
| 958 | __func__); |
| 959 | goto err_codec; |
| 960 | } |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 961 | |
Joonwoo Park | 5d170a4 | 2013-04-10 15:16:36 -0700 | [diff] [blame] | 962 | ret = wcd9xxx_enable_static_supplies(wcd9xxx, pdata); |
| 963 | if (ret) { |
| 964 | pr_err("%s: Fail to enable Codec pre-reset supplies\n", |
| 965 | __func__); |
| 966 | goto err_codec; |
| 967 | } |
Venkat Sudhir | a50a376 | 2012-11-26 12:12:15 -0800 | [diff] [blame] | 968 | usleep_range(5, 5); |
Joonwoo Park | 5d170a4 | 2013-04-10 15:16:36 -0700 | [diff] [blame] | 969 | |
Venkat Sudhir | a50a376 | 2012-11-26 12:12:15 -0800 | [diff] [blame] | 970 | ret = wcd9xxx_reset(wcd9xxx); |
| 971 | if (ret) { |
| 972 | pr_err("%s: Resetting Codec failed\n", __func__); |
Joonwoo Park | 5d170a4 | 2013-04-10 15:16:36 -0700 | [diff] [blame] | 973 | goto err_supplies; |
Venkat Sudhir | a50a376 | 2012-11-26 12:12:15 -0800 | [diff] [blame] | 974 | } |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 975 | |
Venkat Sudhir | a50a376 | 2012-11-26 12:12:15 -0800 | [diff] [blame] | 976 | ret = wcd9xxx_i2c_get_client_index(client, &wcd9xx_index); |
| 977 | if (ret != 0) { |
| 978 | pr_err("%s:Set codec I2C client failed\n", __func__); |
| 979 | goto err_supplies; |
| 980 | } |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 981 | |
Venkat Sudhir | a50a376 | 2012-11-26 12:12:15 -0800 | [diff] [blame] | 982 | wcd9xxx_modules[wcd9xx_index].client = client; |
| 983 | wcd9xxx->read_dev = wcd9xxx_i2c_read; |
| 984 | wcd9xxx->write_dev = wcd9xxx_i2c_write; |
| 985 | if (!wcd9xxx->dev->of_node) { |
| 986 | wcd9xxx->irq = pdata->irq; |
| 987 | wcd9xxx->irq_base = pdata->irq_base; |
| 988 | } |
Asish Bhattacharya | 6dd4cb5 | 2012-07-05 19:47:42 +0530 | [diff] [blame] | 989 | |
Venkat Sudhir | a50a376 | 2012-11-26 12:12:15 -0800 | [diff] [blame] | 990 | ret = wcd9xxx_device_init(wcd9xxx); |
| 991 | if (ret) { |
| 992 | pr_err("%s: error, initializing device failed\n", |
| 993 | __func__); |
| 994 | goto err_device_init; |
| 995 | } |
Asish Bhattacharya | 6dd4cb5 | 2012-07-05 19:47:42 +0530 | [diff] [blame] | 996 | |
Venkat Sudhir | a50a376 | 2012-11-26 12:12:15 -0800 | [diff] [blame] | 997 | ret = wcd9xxx_read(wcd9xxx, WCD9XXX_A_CHIP_STATUS, 1, &val, 0); |
Joonwoo Park | 1277cb6 | 2013-03-19 14:16:51 -0700 | [diff] [blame] | 998 | if (ret < 0) |
| 999 | pr_err("%s: failed to read the wcd9xxx status (%d)\n", |
| 1000 | __func__, ret); |
| 1001 | if (val != wcd9xxx->codec_type->i2c_chip_status) |
| 1002 | pr_err("%s: unknown chip status 0x%x\n", __func__, val); |
Venkat Sudhir | a50a376 | 2012-11-26 12:12:15 -0800 | [diff] [blame] | 1003 | |
Joonwoo Park | 1277cb6 | 2013-03-19 14:16:51 -0700 | [diff] [blame] | 1004 | wcd9xxx_intf = WCD9XXX_INTERFACE_TYPE_I2C; |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 1005 | |
Venkat Sudhir | a50a376 | 2012-11-26 12:12:15 -0800 | [diff] [blame] | 1006 | return ret; |
| 1007 | } else |
| 1008 | pr_err("%s: I2C probe in wrong state\n", __func__); |
| 1009 | |
| 1010 | |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 1011 | err_device_init: |
| 1012 | wcd9xxx_free_reset(wcd9xxx); |
| 1013 | err_supplies: |
Venkat Sudhir | 4920386 | 2012-05-21 14:29:13 -0700 | [diff] [blame] | 1014 | wcd9xxx_disable_supplies(wcd9xxx, pdata); |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 1015 | err_codec: |
| 1016 | kfree(wcd9xxx); |
| 1017 | fail: |
| 1018 | return ret; |
| 1019 | } |
| 1020 | |
| 1021 | static int __devexit wcd9xxx_i2c_remove(struct i2c_client *client) |
| 1022 | { |
| 1023 | struct wcd9xxx *wcd9xxx; |
Venkat Sudhir | 4920386 | 2012-05-21 14:29:13 -0700 | [diff] [blame] | 1024 | struct wcd9xxx_pdata *pdata = client->dev.platform_data; |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 1025 | pr_debug("exit\n"); |
| 1026 | wcd9xxx = dev_get_drvdata(&client->dev); |
Venkat Sudhir | 4920386 | 2012-05-21 14:29:13 -0700 | [diff] [blame] | 1027 | wcd9xxx_disable_supplies(wcd9xxx, pdata); |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 1028 | wcd9xxx_device_exit(wcd9xxx); |
| 1029 | return 0; |
| 1030 | } |
| 1031 | |
Kiran Kandi | 725f849 | 2012-08-06 13:45:16 -0700 | [diff] [blame] | 1032 | static int wcd9xxx_dt_parse_vreg_info(struct device *dev, |
Joonwoo Park | 5d170a4 | 2013-04-10 15:16:36 -0700 | [diff] [blame] | 1033 | struct wcd9xxx_regulator *vreg, |
| 1034 | const char *vreg_name, |
| 1035 | bool ondemand) |
Kiran Kandi | 725f849 | 2012-08-06 13:45:16 -0700 | [diff] [blame] | 1036 | { |
| 1037 | int len, ret = 0; |
| 1038 | const __be32 *prop; |
| 1039 | char prop_name[CODEC_DT_MAX_PROP_SIZE]; |
| 1040 | struct device_node *regnode = NULL; |
| 1041 | u32 prop_val; |
| 1042 | |
| 1043 | snprintf(prop_name, CODEC_DT_MAX_PROP_SIZE, "%s-supply", |
| 1044 | vreg_name); |
| 1045 | regnode = of_parse_phandle(dev->of_node, prop_name, 0); |
| 1046 | |
| 1047 | if (!regnode) { |
| 1048 | dev_err(dev, "Looking up %s property in node %s failed", |
| 1049 | prop_name, dev->of_node->full_name); |
| 1050 | return -ENODEV; |
| 1051 | } |
| 1052 | vreg->name = vreg_name; |
Joonwoo Park | 5d170a4 | 2013-04-10 15:16:36 -0700 | [diff] [blame] | 1053 | vreg->ondemand = ondemand; |
Kiran Kandi | 725f849 | 2012-08-06 13:45:16 -0700 | [diff] [blame] | 1054 | |
| 1055 | snprintf(prop_name, CODEC_DT_MAX_PROP_SIZE, |
| 1056 | "qcom,%s-voltage", vreg_name); |
| 1057 | prop = of_get_property(dev->of_node, prop_name, &len); |
| 1058 | |
| 1059 | if (!prop || (len != (2 * sizeof(__be32)))) { |
| 1060 | dev_err(dev, "%s %s property\n", |
| 1061 | prop ? "invalid format" : "no", prop_name); |
Joonwoo Park | 5d170a4 | 2013-04-10 15:16:36 -0700 | [diff] [blame] | 1062 | return -EINVAL; |
Kiran Kandi | 725f849 | 2012-08-06 13:45:16 -0700 | [diff] [blame] | 1063 | } else { |
| 1064 | vreg->min_uV = be32_to_cpup(&prop[0]); |
| 1065 | vreg->max_uV = be32_to_cpup(&prop[1]); |
| 1066 | } |
| 1067 | |
| 1068 | snprintf(prop_name, CODEC_DT_MAX_PROP_SIZE, |
| 1069 | "qcom,%s-current", vreg_name); |
| 1070 | |
| 1071 | ret = of_property_read_u32(dev->of_node, prop_name, &prop_val); |
| 1072 | if (ret) { |
| 1073 | dev_err(dev, "Looking up %s property in node %s failed", |
| 1074 | prop_name, dev->of_node->full_name); |
Joonwoo Park | 5d170a4 | 2013-04-10 15:16:36 -0700 | [diff] [blame] | 1075 | return -EFAULT; |
Kiran Kandi | 725f849 | 2012-08-06 13:45:16 -0700 | [diff] [blame] | 1076 | } |
| 1077 | vreg->optimum_uA = prop_val; |
| 1078 | |
Joonwoo Park | 5d170a4 | 2013-04-10 15:16:36 -0700 | [diff] [blame] | 1079 | dev_info(dev, "%s: vol=[%d %d]uV, curr=[%d]uA, ond %d\n", vreg->name, |
| 1080 | vreg->min_uV, vreg->max_uV, vreg->optimum_uA, vreg->ondemand); |
Kiran Kandi | 725f849 | 2012-08-06 13:45:16 -0700 | [diff] [blame] | 1081 | return 0; |
| 1082 | } |
| 1083 | |
Banajit Goswami | 4d6d891b | 2012-12-12 23:59:07 -0800 | [diff] [blame] | 1084 | static int wcd9xxx_read_of_property_u32(struct device *dev, |
| 1085 | const char *name, u32 *val) |
| 1086 | { |
| 1087 | int ret = 0; |
| 1088 | ret = of_property_read_u32(dev->of_node, name, val); |
| 1089 | if (ret) |
| 1090 | dev_err(dev, "Looking up %s property in node %s failed", |
| 1091 | name, dev->of_node->full_name); |
| 1092 | return ret; |
| 1093 | } |
| 1094 | |
Kiran Kandi | 725f849 | 2012-08-06 13:45:16 -0700 | [diff] [blame] | 1095 | static int wcd9xxx_dt_parse_micbias_info(struct device *dev, |
| 1096 | struct wcd9xxx_micbias_setting *micbias) |
| 1097 | { |
Kiran Kandi | 725f849 | 2012-08-06 13:45:16 -0700 | [diff] [blame] | 1098 | u32 prop_val; |
| 1099 | |
Banajit Goswami | 4d6d891b | 2012-12-12 23:59:07 -0800 | [diff] [blame] | 1100 | if (!(wcd9xxx_read_of_property_u32(dev, "qcom,cdc-micbias-ldoh-v", |
| 1101 | &prop_val))) |
| 1102 | micbias->ldoh_v = (u8)prop_val; |
Kiran Kandi | 725f849 | 2012-08-06 13:45:16 -0700 | [diff] [blame] | 1103 | |
Banajit Goswami | 4d6d891b | 2012-12-12 23:59:07 -0800 | [diff] [blame] | 1104 | wcd9xxx_read_of_property_u32(dev, "qcom,cdc-micbias-cfilt1-mv", |
| 1105 | &micbias->cfilt1_mv); |
Kiran Kandi | 725f849 | 2012-08-06 13:45:16 -0700 | [diff] [blame] | 1106 | |
Banajit Goswami | 4d6d891b | 2012-12-12 23:59:07 -0800 | [diff] [blame] | 1107 | wcd9xxx_read_of_property_u32(dev, "qcom,cdc-micbias-cfilt2-mv", |
| 1108 | &micbias->cfilt2_mv); |
Kiran Kandi | 725f849 | 2012-08-06 13:45:16 -0700 | [diff] [blame] | 1109 | |
Banajit Goswami | 4d6d891b | 2012-12-12 23:59:07 -0800 | [diff] [blame] | 1110 | wcd9xxx_read_of_property_u32(dev, "qcom,cdc-micbias-cfilt3-mv", |
| 1111 | &micbias->cfilt3_mv); |
Kiran Kandi | 725f849 | 2012-08-06 13:45:16 -0700 | [diff] [blame] | 1112 | |
Banajit Goswami | 4d6d891b | 2012-12-12 23:59:07 -0800 | [diff] [blame] | 1113 | /* Read micbias values for codec. Does not matter even if a few |
| 1114 | * micbias values are not defined in the Device Tree. Codec will |
| 1115 | * anyway not use those values |
| 1116 | */ |
| 1117 | if (!(wcd9xxx_read_of_property_u32(dev, "qcom,cdc-micbias1-cfilt-sel", |
| 1118 | &prop_val))) |
| 1119 | micbias->bias1_cfilt_sel = (u8)prop_val; |
Kiran Kandi | 725f849 | 2012-08-06 13:45:16 -0700 | [diff] [blame] | 1120 | |
Banajit Goswami | 4d6d891b | 2012-12-12 23:59:07 -0800 | [diff] [blame] | 1121 | if (!(wcd9xxx_read_of_property_u32(dev, "qcom,cdc-micbias2-cfilt-sel", |
| 1122 | &prop_val))) |
| 1123 | micbias->bias2_cfilt_sel = (u8)prop_val; |
Kiran Kandi | 725f849 | 2012-08-06 13:45:16 -0700 | [diff] [blame] | 1124 | |
Banajit Goswami | 4d6d891b | 2012-12-12 23:59:07 -0800 | [diff] [blame] | 1125 | if (!(wcd9xxx_read_of_property_u32(dev, "qcom,cdc-micbias3-cfilt-sel", |
| 1126 | &prop_val))) |
| 1127 | micbias->bias3_cfilt_sel = (u8)prop_val; |
Kiran Kandi | 725f849 | 2012-08-06 13:45:16 -0700 | [diff] [blame] | 1128 | |
Banajit Goswami | 4d6d891b | 2012-12-12 23:59:07 -0800 | [diff] [blame] | 1129 | if (!(wcd9xxx_read_of_property_u32(dev, "qcom,cdc-micbias4-cfilt-sel", |
| 1130 | &prop_val))) |
| 1131 | micbias->bias4_cfilt_sel = (u8)prop_val; |
Kiran Kandi | 725f849 | 2012-08-06 13:45:16 -0700 | [diff] [blame] | 1132 | |
Joonwoo Park | adf2597 | 2012-10-18 13:18:08 -0700 | [diff] [blame] | 1133 | /* micbias external cap */ |
| 1134 | micbias->bias1_cap_mode = |
| 1135 | (of_property_read_bool(dev->of_node, "qcom,cdc-micbias1-ext-cap") ? |
| 1136 | MICBIAS_EXT_BYP_CAP : MICBIAS_NO_EXT_BYP_CAP); |
| 1137 | micbias->bias2_cap_mode = |
| 1138 | (of_property_read_bool(dev->of_node, "qcom,cdc-micbias2-ext-cap") ? |
| 1139 | MICBIAS_EXT_BYP_CAP : MICBIAS_NO_EXT_BYP_CAP); |
| 1140 | micbias->bias3_cap_mode = |
| 1141 | (of_property_read_bool(dev->of_node, "qcom,cdc-micbias3-ext-cap") ? |
| 1142 | MICBIAS_EXT_BYP_CAP : MICBIAS_NO_EXT_BYP_CAP); |
| 1143 | micbias->bias4_cap_mode = |
| 1144 | (of_property_read_bool(dev->of_node, "qcom,cdc-micbias4-ext-cap") ? |
| 1145 | MICBIAS_EXT_BYP_CAP : MICBIAS_NO_EXT_BYP_CAP); |
| 1146 | |
Joonwoo Park | 88bfa84 | 2013-04-15 16:59:21 -0700 | [diff] [blame] | 1147 | micbias->bias2_is_headset_only = |
| 1148 | of_property_read_bool(dev->of_node, |
| 1149 | "qcom,cdc-micbias2-headset-only"); |
| 1150 | |
Kiran Kandi | 725f849 | 2012-08-06 13:45:16 -0700 | [diff] [blame] | 1151 | dev_dbg(dev, "ldoh_v %u cfilt1_mv %u cfilt2_mv %u cfilt3_mv %u", |
| 1152 | (u32)micbias->ldoh_v, (u32)micbias->cfilt1_mv, |
| 1153 | (u32)micbias->cfilt2_mv, (u32)micbias->cfilt3_mv); |
| 1154 | |
| 1155 | dev_dbg(dev, "bias1_cfilt_sel %u bias2_cfilt_sel %u\n", |
| 1156 | (u32)micbias->bias1_cfilt_sel, (u32)micbias->bias2_cfilt_sel); |
| 1157 | |
| 1158 | dev_dbg(dev, "bias3_cfilt_sel %u bias4_cfilt_sel %u\n", |
| 1159 | (u32)micbias->bias3_cfilt_sel, (u32)micbias->bias4_cfilt_sel); |
| 1160 | |
Joonwoo Park | adf2597 | 2012-10-18 13:18:08 -0700 | [diff] [blame] | 1161 | dev_dbg(dev, "bias1_ext_cap %d bias2_ext_cap %d\n", |
| 1162 | micbias->bias1_cap_mode, micbias->bias2_cap_mode); |
| 1163 | dev_dbg(dev, "bias3_ext_cap %d bias4_ext_cap %d\n", |
| 1164 | micbias->bias3_cap_mode, micbias->bias4_cap_mode); |
| 1165 | |
Joonwoo Park | 88bfa84 | 2013-04-15 16:59:21 -0700 | [diff] [blame] | 1166 | dev_dbg(dev, "bias2_is_headset_only %d\n", |
| 1167 | micbias->bias2_is_headset_only); |
Kiran Kandi | 725f849 | 2012-08-06 13:45:16 -0700 | [diff] [blame] | 1168 | return 0; |
| 1169 | } |
| 1170 | |
| 1171 | static int wcd9xxx_dt_parse_slim_interface_dev_info(struct device *dev, |
| 1172 | struct slim_device *slim_ifd) |
| 1173 | { |
| 1174 | int ret = 0; |
| 1175 | struct property *prop; |
| 1176 | |
| 1177 | ret = of_property_read_string(dev->of_node, "qcom,cdc-slim-ifd", |
| 1178 | &slim_ifd->name); |
| 1179 | if (ret) { |
| 1180 | dev_err(dev, "Looking up %s property in node %s failed", |
| 1181 | "qcom,cdc-slim-ifd-dev", dev->of_node->full_name); |
| 1182 | return -ENODEV; |
| 1183 | } |
| 1184 | prop = of_find_property(dev->of_node, |
| 1185 | "qcom,cdc-slim-ifd-elemental-addr", NULL); |
| 1186 | if (!prop) { |
| 1187 | dev_err(dev, "Looking up %s property in node %s failed", |
| 1188 | "qcom,cdc-slim-ifd-elemental-addr", |
| 1189 | dev->of_node->full_name); |
| 1190 | return -ENODEV; |
| 1191 | } else if (prop->length != 6) { |
| 1192 | dev_err(dev, "invalid codec slim ifd addr. addr length = %d\n", |
| 1193 | prop->length); |
| 1194 | return -ENODEV; |
| 1195 | } |
| 1196 | memcpy(slim_ifd->e_addr, prop->value, 6); |
| 1197 | |
| 1198 | return 0; |
| 1199 | } |
| 1200 | |
Bhalchandra Gajare | add903b | 2013-07-03 14:32:38 -0700 | [diff] [blame] | 1201 | static int wcd9xxx_process_supplies(struct device *dev, |
| 1202 | struct wcd9xxx_pdata *pdata, const char *supply_list, |
| 1203 | int supply_cnt, bool is_ondemand, int index) |
| 1204 | { |
| 1205 | int idx, ret = 0; |
| 1206 | const char *name; |
| 1207 | |
| 1208 | if (supply_cnt == 0) { |
| 1209 | dev_dbg(dev, "%s: no supplies defined for %s\n", __func__, |
| 1210 | supply_list); |
| 1211 | return 0; |
| 1212 | } |
| 1213 | |
| 1214 | for (idx = 0; idx < supply_cnt; idx++) { |
| 1215 | ret = of_property_read_string_index(dev->of_node, |
| 1216 | supply_list, idx, |
| 1217 | &name); |
| 1218 | if (ret) { |
| 1219 | dev_err(dev, "%s: of read string %s idx %d error %d\n", |
| 1220 | __func__, supply_list, idx, ret); |
| 1221 | goto err; |
| 1222 | } |
| 1223 | |
| 1224 | dev_dbg(dev, "%s: Found cdc supply %s as part of %s\n", |
| 1225 | __func__, name, supply_list); |
| 1226 | ret = wcd9xxx_dt_parse_vreg_info(dev, |
| 1227 | &pdata->regulator[index + idx], |
| 1228 | name, is_ondemand); |
| 1229 | if (ret) |
| 1230 | goto err; |
| 1231 | } |
| 1232 | |
| 1233 | return 0; |
| 1234 | |
| 1235 | err: |
| 1236 | return ret; |
| 1237 | |
| 1238 | } |
| 1239 | |
Kiran Kandi | 725f849 | 2012-08-06 13:45:16 -0700 | [diff] [blame] | 1240 | static struct wcd9xxx_pdata *wcd9xxx_populate_dt_pdata(struct device *dev) |
| 1241 | { |
| 1242 | struct wcd9xxx_pdata *pdata; |
Bhalchandra Gajare | add903b | 2013-07-03 14:32:38 -0700 | [diff] [blame] | 1243 | int ret, static_cnt, ond_cnt, cp_supplies_cnt; |
Venkat Sudhir | a50a376 | 2012-11-26 12:12:15 -0800 | [diff] [blame] | 1244 | u32 mclk_rate = 0; |
Damir Didjusto | 1a353ce | 2013-04-02 11:45:47 -0700 | [diff] [blame] | 1245 | u32 dmic_sample_rate = 0; |
Joonwoo Park | 7323921 | 2013-04-10 15:11:06 -0700 | [diff] [blame] | 1246 | const char *static_prop_name = "qcom,cdc-static-supplies"; |
Joonwoo Park | 5d170a4 | 2013-04-10 15:16:36 -0700 | [diff] [blame] | 1247 | const char *ond_prop_name = "qcom,cdc-on-demand-supplies"; |
Bhalchandra Gajare | add903b | 2013-07-03 14:32:38 -0700 | [diff] [blame] | 1248 | const char *cp_supplies_name = "qcom,cdc-cp-supplies"; |
Kiran Kandi | 725f849 | 2012-08-06 13:45:16 -0700 | [diff] [blame] | 1249 | |
| 1250 | pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL); |
| 1251 | if (!pdata) { |
Venkat Sudhir | a41630a | 2012-10-27 00:57:31 -0700 | [diff] [blame] | 1252 | dev_err(dev, "could not allocate memory for platform data\n"); |
Kiran Kandi | 725f849 | 2012-08-06 13:45:16 -0700 | [diff] [blame] | 1253 | return NULL; |
| 1254 | } |
Joonwoo Park | 7323921 | 2013-04-10 15:11:06 -0700 | [diff] [blame] | 1255 | |
| 1256 | static_cnt = of_property_count_strings(dev->of_node, static_prop_name); |
| 1257 | if (IS_ERR_VALUE(static_cnt)) { |
| 1258 | dev_err(dev, "%s: Failed to get static supplies %d\n", __func__, |
| 1259 | static_cnt); |
Kiran Kandi | 725f849 | 2012-08-06 13:45:16 -0700 | [diff] [blame] | 1260 | goto err; |
| 1261 | } |
| 1262 | |
Joonwoo Park | 5d170a4 | 2013-04-10 15:16:36 -0700 | [diff] [blame] | 1263 | /* On-demand supply list is an optional property */ |
| 1264 | ond_cnt = of_property_count_strings(dev->of_node, ond_prop_name); |
| 1265 | if (IS_ERR_VALUE(ond_cnt)) |
| 1266 | ond_cnt = 0; |
| 1267 | |
Bhalchandra Gajare | add903b | 2013-07-03 14:32:38 -0700 | [diff] [blame] | 1268 | /* cp-supplies list is an optional property */ |
| 1269 | cp_supplies_cnt = of_property_count_strings(dev->of_node, |
| 1270 | cp_supplies_name); |
| 1271 | if (IS_ERR_VALUE(cp_supplies_cnt)) |
| 1272 | cp_supplies_cnt = 0; |
| 1273 | |
| 1274 | BUG_ON(static_cnt <= 0 || ond_cnt < 0 || cp_supplies_cnt < 0); |
| 1275 | if ((static_cnt + ond_cnt + cp_supplies_cnt) |
| 1276 | > ARRAY_SIZE(pdata->regulator)) { |
Kiran Kandi | 725f849 | 2012-08-06 13:45:16 -0700 | [diff] [blame] | 1277 | dev_err(dev, "%s: Num of supplies %u > max supported %u\n", |
Joonwoo Park | 7323921 | 2013-04-10 15:11:06 -0700 | [diff] [blame] | 1278 | __func__, static_cnt, ARRAY_SIZE(pdata->regulator)); |
Kiran Kandi | 725f849 | 2012-08-06 13:45:16 -0700 | [diff] [blame] | 1279 | goto err; |
| 1280 | } |
| 1281 | |
Bhalchandra Gajare | add903b | 2013-07-03 14:32:38 -0700 | [diff] [blame] | 1282 | ret = wcd9xxx_process_supplies(dev, pdata, static_prop_name, |
Bhalchandra Gajare | 8e3c09f | 2013-08-23 11:58:35 -0700 | [diff] [blame^] | 1283 | static_cnt, STATIC_REGULATOR, 0); |
Bhalchandra Gajare | add903b | 2013-07-03 14:32:38 -0700 | [diff] [blame] | 1284 | if (ret) |
| 1285 | goto err; |
Joonwoo Park | 7323921 | 2013-04-10 15:11:06 -0700 | [diff] [blame] | 1286 | |
Bhalchandra Gajare | add903b | 2013-07-03 14:32:38 -0700 | [diff] [blame] | 1287 | ret = wcd9xxx_process_supplies(dev, pdata, ond_prop_name, |
Bhalchandra Gajare | 8e3c09f | 2013-08-23 11:58:35 -0700 | [diff] [blame^] | 1288 | ond_cnt, ONDEMAND_REGULATOR, static_cnt); |
Bhalchandra Gajare | add903b | 2013-07-03 14:32:38 -0700 | [diff] [blame] | 1289 | if (ret) |
| 1290 | goto err; |
Joonwoo Park | 5d170a4 | 2013-04-10 15:16:36 -0700 | [diff] [blame] | 1291 | |
Bhalchandra Gajare | add903b | 2013-07-03 14:32:38 -0700 | [diff] [blame] | 1292 | ret = wcd9xxx_process_supplies(dev, pdata, cp_supplies_name, |
Bhalchandra Gajare | 8e3c09f | 2013-08-23 11:58:35 -0700 | [diff] [blame^] | 1293 | cp_supplies_cnt, ONDEMAND_REGULATOR, |
| 1294 | static_cnt + ond_cnt); |
Bhalchandra Gajare | add903b | 2013-07-03 14:32:38 -0700 | [diff] [blame] | 1295 | if (ret) |
| 1296 | goto err; |
Kiran Kandi | 725f849 | 2012-08-06 13:45:16 -0700 | [diff] [blame] | 1297 | |
| 1298 | ret = wcd9xxx_dt_parse_micbias_info(dev, &pdata->micbias); |
| 1299 | if (ret) |
| 1300 | goto err; |
| 1301 | |
| 1302 | pdata->reset_gpio = of_get_named_gpio(dev->of_node, |
| 1303 | "qcom,cdc-reset-gpio", 0); |
| 1304 | if (pdata->reset_gpio < 0) { |
| 1305 | dev_err(dev, "Looking up %s property in node %s failed %d\n", |
| 1306 | "qcom, cdc-reset-gpio", dev->of_node->full_name, |
| 1307 | pdata->reset_gpio); |
| 1308 | goto err; |
| 1309 | } |
Venkat Sudhir | a41630a | 2012-10-27 00:57:31 -0700 | [diff] [blame] | 1310 | dev_dbg(dev, "%s: reset gpio %d", __func__, pdata->reset_gpio); |
Venkat Sudhir | a50a376 | 2012-11-26 12:12:15 -0800 | [diff] [blame] | 1311 | ret = of_property_read_u32(dev->of_node, |
| 1312 | "qcom,cdc-mclk-clk-rate", |
| 1313 | &mclk_rate); |
| 1314 | if (ret) { |
| 1315 | dev_err(dev, "Looking up %s property in\n" |
| 1316 | "node %s failed", |
| 1317 | "qcom,cdc-mclk-clk-rate", |
| 1318 | dev->of_node->full_name); |
| 1319 | devm_kfree(dev, pdata); |
| 1320 | ret = -EINVAL; |
| 1321 | goto err; |
| 1322 | } |
| 1323 | pdata->mclk_rate = mclk_rate; |
Damir Didjusto | 1a353ce | 2013-04-02 11:45:47 -0700 | [diff] [blame] | 1324 | |
| 1325 | ret = of_property_read_u32(dev->of_node, |
| 1326 | "qcom,cdc-dmic-sample-rate", |
| 1327 | &dmic_sample_rate); |
| 1328 | if (ret) { |
| 1329 | dev_err(dev, "Looking up %s property in node %s failed", |
| 1330 | "qcom,cdc-dmic-sample-rate", |
| 1331 | dev->of_node->full_name); |
| 1332 | dmic_sample_rate = TAIKO_DMIC_SAMPLE_RATE_UNDEFINED; |
| 1333 | } |
| 1334 | if (pdata->mclk_rate == TAIKO_MCLK_CLK_9P6HZ) { |
| 1335 | if ((dmic_sample_rate != TAIKO_DMIC_SAMPLE_RATE_2P4MHZ) && |
| 1336 | (dmic_sample_rate != TAIKO_DMIC_SAMPLE_RATE_3P2MHZ) && |
| 1337 | (dmic_sample_rate != TAIKO_DMIC_SAMPLE_RATE_4P8MHZ) && |
| 1338 | (dmic_sample_rate != TAIKO_DMIC_SAMPLE_RATE_UNDEFINED)) { |
| 1339 | dev_err(dev, "Invalid dmic rate %d for mclk %d\n", |
| 1340 | dmic_sample_rate, pdata->mclk_rate); |
| 1341 | ret = -EINVAL; |
| 1342 | goto err; |
| 1343 | } |
| 1344 | } else if (pdata->mclk_rate == TAIKO_MCLK_CLK_12P288MHZ) { |
| 1345 | if ((dmic_sample_rate != TAIKO_DMIC_SAMPLE_RATE_3P072MHZ) && |
| 1346 | (dmic_sample_rate != TAIKO_DMIC_SAMPLE_RATE_4P096MHZ) && |
| 1347 | (dmic_sample_rate != TAIKO_DMIC_SAMPLE_RATE_6P144MHZ) && |
| 1348 | (dmic_sample_rate != TAIKO_DMIC_SAMPLE_RATE_UNDEFINED)) { |
| 1349 | dev_err(dev, "Invalid dmic rate %d for mclk %d\n", |
| 1350 | dmic_sample_rate, pdata->mclk_rate); |
| 1351 | ret = -EINVAL; |
| 1352 | goto err; |
| 1353 | } |
| 1354 | } |
| 1355 | pdata->dmic_sample_rate = dmic_sample_rate; |
Kiran Kandi | 725f849 | 2012-08-06 13:45:16 -0700 | [diff] [blame] | 1356 | return pdata; |
| 1357 | err: |
| 1358 | devm_kfree(dev, pdata); |
| 1359 | return NULL; |
| 1360 | } |
| 1361 | |
Joonwoo Park | 3c5b2df | 2012-08-28 15:36:55 -0700 | [diff] [blame] | 1362 | static int wcd9xxx_slim_get_laddr(struct slim_device *sb, |
| 1363 | const u8 *e_addr, u8 e_len, u8 *laddr) |
| 1364 | { |
| 1365 | int ret; |
| 1366 | const unsigned long timeout = jiffies + |
| 1367 | msecs_to_jiffies(SLIMBUS_PRESENT_TIMEOUT); |
| 1368 | |
| 1369 | do { |
| 1370 | ret = slim_get_logical_addr(sb, e_addr, e_len, laddr); |
| 1371 | if (!ret) |
| 1372 | break; |
| 1373 | /* Give SLIMBUS time to report present and be ready. */ |
| 1374 | usleep_range(1000, 1000); |
| 1375 | pr_debug_ratelimited("%s: retyring get logical addr\n", |
| 1376 | __func__); |
| 1377 | } while time_before(jiffies, timeout); |
| 1378 | |
| 1379 | return ret; |
| 1380 | } |
| 1381 | |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 1382 | static int wcd9xxx_slim_probe(struct slim_device *slim) |
| 1383 | { |
| 1384 | struct wcd9xxx *wcd9xxx; |
| 1385 | struct wcd9xxx_pdata *pdata; |
| 1386 | int ret = 0; |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 1387 | |
Venkat Sudhir | a50a376 | 2012-11-26 12:12:15 -0800 | [diff] [blame] | 1388 | if (wcd9xxx_intf == WCD9XXX_INTERFACE_TYPE_I2C) { |
| 1389 | dev_dbg(&slim->dev, "%s:Codec is detected in I2C mode\n", |
| 1390 | __func__); |
| 1391 | return -ENODEV; |
| 1392 | } |
Kiran Kandi | 725f849 | 2012-08-06 13:45:16 -0700 | [diff] [blame] | 1393 | if (slim->dev.of_node) { |
| 1394 | dev_info(&slim->dev, "Platform data from device tree\n"); |
| 1395 | pdata = wcd9xxx_populate_dt_pdata(&slim->dev); |
Venkat Sudhir | a41630a | 2012-10-27 00:57:31 -0700 | [diff] [blame] | 1396 | ret = wcd9xxx_dt_parse_slim_interface_dev_info(&slim->dev, |
| 1397 | &pdata->slimbus_slave_device); |
| 1398 | if (ret) { |
| 1399 | dev_err(&slim->dev, "Error, parsing slim interface\n"); |
| 1400 | devm_kfree(&slim->dev, pdata); |
| 1401 | ret = -EINVAL; |
| 1402 | goto err; |
| 1403 | } |
Kiran Kandi | 725f849 | 2012-08-06 13:45:16 -0700 | [diff] [blame] | 1404 | slim->dev.platform_data = pdata; |
| 1405 | |
| 1406 | } else { |
| 1407 | dev_info(&slim->dev, "Platform data from board file\n"); |
| 1408 | pdata = slim->dev.platform_data; |
| 1409 | } |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 1410 | |
| 1411 | if (!pdata) { |
| 1412 | dev_err(&slim->dev, "Error, no platform data\n"); |
| 1413 | ret = -EINVAL; |
| 1414 | goto err; |
| 1415 | } |
| 1416 | |
| 1417 | wcd9xxx = kzalloc(sizeof(struct wcd9xxx), GFP_KERNEL); |
| 1418 | if (wcd9xxx == NULL) { |
| 1419 | pr_err("%s: error, allocation failed\n", __func__); |
| 1420 | ret = -ENOMEM; |
| 1421 | goto err; |
| 1422 | } |
| 1423 | if (!slim->ctrl) { |
| 1424 | pr_err("Error, no SLIMBUS control data\n"); |
| 1425 | ret = -EINVAL; |
| 1426 | goto err_codec; |
| 1427 | } |
| 1428 | wcd9xxx->slim = slim; |
| 1429 | slim_set_clientdata(slim, wcd9xxx); |
| 1430 | wcd9xxx->reset_gpio = pdata->reset_gpio; |
| 1431 | wcd9xxx->dev = &slim->dev; |
Venkat Sudhir | a50a376 | 2012-11-26 12:12:15 -0800 | [diff] [blame] | 1432 | wcd9xxx->mclk_rate = pdata->mclk_rate; |
Ravishankar Sarawadi | 839fcf3 | 2012-11-14 12:13:00 -0800 | [diff] [blame] | 1433 | wcd9xxx->slim_device_bootup = true; |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 1434 | |
Joonwoo Park | 5d170a4 | 2013-04-10 15:16:36 -0700 | [diff] [blame] | 1435 | ret = wcd9xxx_init_supplies(wcd9xxx, pdata); |
| 1436 | if (ret) { |
| 1437 | pr_err("%s: Fail to init Codec supplies %d\n", __func__, ret); |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 1438 | goto err_codec; |
Joonwoo Park | 5d170a4 | 2013-04-10 15:16:36 -0700 | [diff] [blame] | 1439 | } |
| 1440 | ret = wcd9xxx_enable_static_supplies(wcd9xxx, pdata); |
| 1441 | if (ret) { |
| 1442 | pr_err("%s: Fail to enable Codec pre-reset supplies\n", |
| 1443 | __func__); |
| 1444 | goto err_codec; |
| 1445 | } |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 1446 | usleep_range(5, 5); |
| 1447 | |
| 1448 | ret = wcd9xxx_reset(wcd9xxx); |
| 1449 | if (ret) { |
| 1450 | pr_err("%s: Resetting Codec failed\n", __func__); |
| 1451 | goto err_supplies; |
| 1452 | } |
| 1453 | |
Joonwoo Park | 3c5b2df | 2012-08-28 15:36:55 -0700 | [diff] [blame] | 1454 | ret = wcd9xxx_slim_get_laddr(wcd9xxx->slim, wcd9xxx->slim->e_addr, |
| 1455 | ARRAY_SIZE(wcd9xxx->slim->e_addr), |
| 1456 | &wcd9xxx->slim->laddr); |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 1457 | if (ret) { |
Joonwoo Park | 3c5b2df | 2012-08-28 15:36:55 -0700 | [diff] [blame] | 1458 | pr_err("%s: failed to get slimbus %s logical address: %d\n", |
| 1459 | __func__, wcd9xxx->slim->name, ret); |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 1460 | goto err_reset; |
| 1461 | } |
| 1462 | wcd9xxx->read_dev = wcd9xxx_slim_read_device; |
| 1463 | wcd9xxx->write_dev = wcd9xxx_slim_write_device; |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 1464 | wcd9xxx_pgd_la = wcd9xxx->slim->laddr; |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 1465 | wcd9xxx->slim_slave = &pdata->slimbus_slave_device; |
Joonwoo Park | f6574c7 | 2012-10-10 17:29:57 -0700 | [diff] [blame] | 1466 | if (!wcd9xxx->dev->of_node) { |
| 1467 | wcd9xxx->irq = pdata->irq; |
| 1468 | wcd9xxx->irq_base = pdata->irq_base; |
| 1469 | } |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 1470 | |
| 1471 | ret = slim_add_device(slim->ctrl, wcd9xxx->slim_slave); |
| 1472 | if (ret) { |
| 1473 | pr_err("%s: error, adding SLIMBUS device failed\n", __func__); |
| 1474 | goto err_reset; |
| 1475 | } |
| 1476 | |
Joonwoo Park | 3c5b2df | 2012-08-28 15:36:55 -0700 | [diff] [blame] | 1477 | ret = wcd9xxx_slim_get_laddr(wcd9xxx->slim_slave, |
| 1478 | wcd9xxx->slim_slave->e_addr, |
| 1479 | ARRAY_SIZE(wcd9xxx->slim_slave->e_addr), |
| 1480 | &wcd9xxx->slim_slave->laddr); |
| 1481 | if (ret) { |
| 1482 | pr_err("%s: failed to get slimbus %s logical address: %d\n", |
| 1483 | __func__, wcd9xxx->slim->name, ret); |
| 1484 | goto err_slim_add; |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 1485 | } |
| 1486 | wcd9xxx_inf_la = wcd9xxx->slim_slave->laddr; |
| 1487 | wcd9xxx_intf = WCD9XXX_INTERFACE_TYPE_SLIMBUS; |
| 1488 | |
Joonwoo Park | f6574c7 | 2012-10-10 17:29:57 -0700 | [diff] [blame] | 1489 | ret = wcd9xxx_device_init(wcd9xxx); |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 1490 | if (ret) { |
| 1491 | pr_err("%s: error, initializing device failed\n", __func__); |
| 1492 | goto err_slim_add; |
| 1493 | } |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 1494 | #ifdef CONFIG_DEBUG_FS |
| 1495 | debugCodec = wcd9xxx; |
| 1496 | |
| 1497 | debugfs_wcd9xxx_dent = debugfs_create_dir |
| 1498 | ("wcd9310_slimbus_interface_device", 0); |
| 1499 | if (!IS_ERR(debugfs_wcd9xxx_dent)) { |
| 1500 | debugfs_peek = debugfs_create_file("peek", |
| 1501 | S_IFREG | S_IRUGO, debugfs_wcd9xxx_dent, |
| 1502 | (void *) "peek", &codec_debug_ops); |
| 1503 | |
| 1504 | debugfs_poke = debugfs_create_file("poke", |
| 1505 | S_IFREG | S_IRUGO, debugfs_wcd9xxx_dent, |
| 1506 | (void *) "poke", &codec_debug_ops); |
| 1507 | } |
| 1508 | #endif |
| 1509 | |
| 1510 | return ret; |
| 1511 | |
| 1512 | err_slim_add: |
| 1513 | slim_remove_device(wcd9xxx->slim_slave); |
| 1514 | err_reset: |
| 1515 | wcd9xxx_free_reset(wcd9xxx); |
| 1516 | err_supplies: |
Venkat Sudhir | 4920386 | 2012-05-21 14:29:13 -0700 | [diff] [blame] | 1517 | wcd9xxx_disable_supplies(wcd9xxx, pdata); |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 1518 | err_codec: |
| 1519 | kfree(wcd9xxx); |
| 1520 | err: |
| 1521 | return ret; |
| 1522 | } |
| 1523 | static int wcd9xxx_slim_remove(struct slim_device *pdev) |
| 1524 | { |
| 1525 | struct wcd9xxx *wcd9xxx; |
Venkat Sudhir | 4920386 | 2012-05-21 14:29:13 -0700 | [diff] [blame] | 1526 | struct wcd9xxx_pdata *pdata = pdev->dev.platform_data; |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 1527 | |
| 1528 | #ifdef CONFIG_DEBUG_FS |
| 1529 | debugfs_remove(debugfs_peek); |
| 1530 | debugfs_remove(debugfs_poke); |
| 1531 | debugfs_remove(debugfs_wcd9xxx_dent); |
| 1532 | #endif |
| 1533 | wcd9xxx = slim_get_devicedata(pdev); |
| 1534 | wcd9xxx_deinit_slimslave(wcd9xxx); |
| 1535 | slim_remove_device(wcd9xxx->slim_slave); |
Venkat Sudhir | 4920386 | 2012-05-21 14:29:13 -0700 | [diff] [blame] | 1536 | wcd9xxx_disable_supplies(wcd9xxx, pdata); |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 1537 | wcd9xxx_device_exit(wcd9xxx); |
| 1538 | return 0; |
| 1539 | } |
| 1540 | |
| 1541 | static int wcd9xxx_resume(struct wcd9xxx *wcd9xxx) |
| 1542 | { |
| 1543 | int ret = 0; |
| 1544 | |
| 1545 | pr_debug("%s: enter\n", __func__); |
| 1546 | mutex_lock(&wcd9xxx->pm_lock); |
| 1547 | if (wcd9xxx->pm_state == WCD9XXX_PM_ASLEEP) { |
| 1548 | pr_debug("%s: resuming system, state %d, wlock %d\n", __func__, |
| 1549 | wcd9xxx->pm_state, wcd9xxx->wlock_holders); |
| 1550 | wcd9xxx->pm_state = WCD9XXX_PM_SLEEPABLE; |
| 1551 | } else { |
| 1552 | pr_warn("%s: system is already awake, state %d wlock %d\n", |
| 1553 | __func__, wcd9xxx->pm_state, wcd9xxx->wlock_holders); |
| 1554 | } |
| 1555 | mutex_unlock(&wcd9xxx->pm_lock); |
| 1556 | wake_up_all(&wcd9xxx->pm_wq); |
| 1557 | |
| 1558 | return ret; |
| 1559 | } |
| 1560 | |
Ravishankar Sarawadi | 839fcf3 | 2012-11-14 12:13:00 -0800 | [diff] [blame] | 1561 | static int wcd9xxx_device_up(struct wcd9xxx *wcd9xxx) |
| 1562 | { |
| 1563 | int ret = 0; |
| 1564 | |
| 1565 | if (wcd9xxx->slim_device_bootup) { |
| 1566 | wcd9xxx->slim_device_bootup = false; |
| 1567 | return 0; |
| 1568 | } |
| 1569 | ret = wcd9xxx_reset(wcd9xxx); |
| 1570 | if (ret) |
| 1571 | pr_err("%s: Resetting Codec failed\n", __func__); |
| 1572 | |
| 1573 | wcd9xxx_bring_up(wcd9xxx); |
| 1574 | wcd9xxx->post_reset(wcd9xxx); |
| 1575 | return ret; |
| 1576 | } |
| 1577 | |
| 1578 | static int wcd9xxx_slim_device_up(struct slim_device *sldev) |
| 1579 | { |
| 1580 | struct wcd9xxx *wcd9xxx = slim_get_devicedata(sldev); |
| 1581 | return wcd9xxx_device_up(wcd9xxx); |
| 1582 | } |
| 1583 | |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 1584 | static int wcd9xxx_slim_resume(struct slim_device *sldev) |
| 1585 | { |
| 1586 | struct wcd9xxx *wcd9xxx = slim_get_devicedata(sldev); |
| 1587 | return wcd9xxx_resume(wcd9xxx); |
| 1588 | } |
| 1589 | |
| 1590 | static int wcd9xxx_i2c_resume(struct i2c_client *i2cdev) |
| 1591 | { |
| 1592 | struct wcd9xxx *wcd9xxx = dev_get_drvdata(&i2cdev->dev); |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 1593 | if (wcd9xxx) |
| 1594 | return wcd9xxx_resume(wcd9xxx); |
| 1595 | else |
| 1596 | return 0; |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 1597 | } |
| 1598 | |
| 1599 | static int wcd9xxx_suspend(struct wcd9xxx *wcd9xxx, pm_message_t pmesg) |
| 1600 | { |
| 1601 | int ret = 0; |
| 1602 | |
| 1603 | pr_debug("%s: enter\n", __func__); |
Stephen Boyd | 2fcabf9 | 2012-05-30 10:41:11 -0700 | [diff] [blame] | 1604 | /* |
| 1605 | * pm_qos_update_request() can be called after this suspend chain call |
| 1606 | * started. thus suspend can be called while lock is being held |
| 1607 | */ |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 1608 | mutex_lock(&wcd9xxx->pm_lock); |
| 1609 | if (wcd9xxx->pm_state == WCD9XXX_PM_SLEEPABLE) { |
| 1610 | pr_debug("%s: suspending system, state %d, wlock %d\n", |
| 1611 | __func__, wcd9xxx->pm_state, wcd9xxx->wlock_holders); |
| 1612 | wcd9xxx->pm_state = WCD9XXX_PM_ASLEEP; |
| 1613 | } else if (wcd9xxx->pm_state == WCD9XXX_PM_AWAKE) { |
| 1614 | /* unlock to wait for pm_state == WCD9XXX_PM_SLEEPABLE |
| 1615 | * then set to WCD9XXX_PM_ASLEEP */ |
| 1616 | pr_debug("%s: waiting to suspend system, state %d, wlock %d\n", |
| 1617 | __func__, wcd9xxx->pm_state, wcd9xxx->wlock_holders); |
| 1618 | mutex_unlock(&wcd9xxx->pm_lock); |
| 1619 | if (!(wait_event_timeout(wcd9xxx->pm_wq, |
| 1620 | wcd9xxx_pm_cmpxchg(wcd9xxx, |
| 1621 | WCD9XXX_PM_SLEEPABLE, |
| 1622 | WCD9XXX_PM_ASLEEP) == |
| 1623 | WCD9XXX_PM_SLEEPABLE, |
| 1624 | HZ))) { |
| 1625 | pr_debug("%s: suspend failed state %d, wlock %d\n", |
| 1626 | __func__, wcd9xxx->pm_state, |
| 1627 | wcd9xxx->wlock_holders); |
| 1628 | ret = -EBUSY; |
| 1629 | } else { |
| 1630 | pr_debug("%s: done, state %d, wlock %d\n", __func__, |
| 1631 | wcd9xxx->pm_state, wcd9xxx->wlock_holders); |
| 1632 | } |
| 1633 | mutex_lock(&wcd9xxx->pm_lock); |
| 1634 | } else if (wcd9xxx->pm_state == WCD9XXX_PM_ASLEEP) { |
| 1635 | pr_warn("%s: system is already suspended, state %d, wlock %dn", |
| 1636 | __func__, wcd9xxx->pm_state, wcd9xxx->wlock_holders); |
| 1637 | } |
| 1638 | mutex_unlock(&wcd9xxx->pm_lock); |
| 1639 | |
| 1640 | return ret; |
| 1641 | } |
| 1642 | |
| 1643 | static int wcd9xxx_slim_suspend(struct slim_device *sldev, pm_message_t pmesg) |
| 1644 | { |
| 1645 | struct wcd9xxx *wcd9xxx = slim_get_devicedata(sldev); |
| 1646 | return wcd9xxx_suspend(wcd9xxx, pmesg); |
| 1647 | } |
| 1648 | |
| 1649 | static int wcd9xxx_i2c_suspend(struct i2c_client *i2cdev, pm_message_t pmesg) |
| 1650 | { |
| 1651 | struct wcd9xxx *wcd9xxx = dev_get_drvdata(&i2cdev->dev); |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 1652 | if (wcd9xxx) |
| 1653 | return wcd9xxx_suspend(wcd9xxx, pmesg); |
| 1654 | else |
| 1655 | return 0; |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 1656 | } |
| 1657 | |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 1658 | static const struct slim_device_id sitar_slimtest_id[] = { |
| 1659 | {"sitar-slim", 0}, |
| 1660 | {} |
| 1661 | }; |
| 1662 | static struct slim_driver sitar_slim_driver = { |
| 1663 | .driver = { |
| 1664 | .name = "sitar-slim", |
| 1665 | .owner = THIS_MODULE, |
| 1666 | }, |
| 1667 | .probe = wcd9xxx_slim_probe, |
| 1668 | .remove = wcd9xxx_slim_remove, |
| 1669 | .id_table = sitar_slimtest_id, |
| 1670 | .resume = wcd9xxx_slim_resume, |
| 1671 | .suspend = wcd9xxx_slim_suspend, |
| 1672 | }; |
| 1673 | |
Bhalchandra Gajare | 83c81f6 | 2012-05-18 16:09:05 -0700 | [diff] [blame] | 1674 | static const struct slim_device_id sitar1p1_slimtest_id[] = { |
| 1675 | {"sitar1p1-slim", 0}, |
| 1676 | {} |
| 1677 | }; |
| 1678 | static struct slim_driver sitar1p1_slim_driver = { |
| 1679 | .driver = { |
| 1680 | .name = "sitar1p1-slim", |
| 1681 | .owner = THIS_MODULE, |
| 1682 | }, |
| 1683 | .probe = wcd9xxx_slim_probe, |
| 1684 | .remove = wcd9xxx_slim_remove, |
| 1685 | .id_table = sitar1p1_slimtest_id, |
| 1686 | .resume = wcd9xxx_slim_resume, |
| 1687 | .suspend = wcd9xxx_slim_suspend, |
| 1688 | }; |
| 1689 | |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 1690 | static const struct slim_device_id slimtest_id[] = { |
| 1691 | {"tabla-slim", 0}, |
| 1692 | {} |
| 1693 | }; |
| 1694 | |
| 1695 | static struct slim_driver tabla_slim_driver = { |
| 1696 | .driver = { |
| 1697 | .name = "tabla-slim", |
| 1698 | .owner = THIS_MODULE, |
| 1699 | }, |
| 1700 | .probe = wcd9xxx_slim_probe, |
| 1701 | .remove = wcd9xxx_slim_remove, |
| 1702 | .id_table = slimtest_id, |
| 1703 | .resume = wcd9xxx_slim_resume, |
| 1704 | .suspend = wcd9xxx_slim_suspend, |
| 1705 | }; |
| 1706 | |
| 1707 | static const struct slim_device_id slimtest2x_id[] = { |
| 1708 | {"tabla2x-slim", 0}, |
| 1709 | {} |
| 1710 | }; |
| 1711 | |
| 1712 | static struct slim_driver tabla2x_slim_driver = { |
| 1713 | .driver = { |
| 1714 | .name = "tabla2x-slim", |
| 1715 | .owner = THIS_MODULE, |
| 1716 | }, |
| 1717 | .probe = wcd9xxx_slim_probe, |
| 1718 | .remove = wcd9xxx_slim_remove, |
| 1719 | .id_table = slimtest2x_id, |
| 1720 | .resume = wcd9xxx_slim_resume, |
| 1721 | .suspend = wcd9xxx_slim_suspend, |
| 1722 | }; |
| 1723 | |
Joonwoo Park | a717211 | 2012-07-23 16:03:49 -0700 | [diff] [blame] | 1724 | static const struct slim_device_id taiko_slimtest_id[] = { |
Kiran Kandi | 725f849 | 2012-08-06 13:45:16 -0700 | [diff] [blame] | 1725 | {"taiko-slim-pgd", 0}, |
Joonwoo Park | a717211 | 2012-07-23 16:03:49 -0700 | [diff] [blame] | 1726 | {} |
| 1727 | }; |
| 1728 | |
| 1729 | static struct slim_driver taiko_slim_driver = { |
| 1730 | .driver = { |
| 1731 | .name = "taiko-slim", |
| 1732 | .owner = THIS_MODULE, |
| 1733 | }, |
| 1734 | .probe = wcd9xxx_slim_probe, |
| 1735 | .remove = wcd9xxx_slim_remove, |
| 1736 | .id_table = taiko_slimtest_id, |
| 1737 | .resume = wcd9xxx_slim_resume, |
| 1738 | .suspend = wcd9xxx_slim_suspend, |
Ravishankar Sarawadi | 839fcf3 | 2012-11-14 12:13:00 -0800 | [diff] [blame] | 1739 | .device_up = wcd9xxx_slim_device_up, |
Joonwoo Park | a717211 | 2012-07-23 16:03:49 -0700 | [diff] [blame] | 1740 | }; |
| 1741 | |
Banajit Goswami | 4d6d891b | 2012-12-12 23:59:07 -0800 | [diff] [blame] | 1742 | static const struct slim_device_id tapan_slimtest_id[] = { |
| 1743 | {"tapan-slim-pgd", 0}, |
| 1744 | {} |
| 1745 | }; |
| 1746 | |
| 1747 | static struct slim_driver tapan_slim_driver = { |
| 1748 | .driver = { |
| 1749 | .name = "tapan-slim", |
| 1750 | .owner = THIS_MODULE, |
| 1751 | }, |
| 1752 | .probe = wcd9xxx_slim_probe, |
| 1753 | .remove = wcd9xxx_slim_remove, |
| 1754 | .id_table = tapan_slimtest_id, |
| 1755 | .resume = wcd9xxx_slim_resume, |
| 1756 | .suspend = wcd9xxx_slim_suspend, |
Ravishankar Sarawadi | d627321 | 2013-05-07 15:08:27 -0700 | [diff] [blame] | 1757 | .device_up = wcd9xxx_slim_device_up, |
Banajit Goswami | 4d6d891b | 2012-12-12 23:59:07 -0800 | [diff] [blame] | 1758 | }; |
| 1759 | |
Venkat Sudhir | a41630a | 2012-10-27 00:57:31 -0700 | [diff] [blame] | 1760 | static struct i2c_device_id wcd9xxx_id_table[] = { |
| 1761 | {"wcd9xxx-i2c", WCD9XXX_I2C_TOP_LEVEL}, |
| 1762 | {"wcd9xxx-i2c", WCD9XXX_I2C_ANALOG}, |
| 1763 | {"wcd9xxx-i2c", WCD9XXX_I2C_DIGITAL_1}, |
| 1764 | {"wcd9xxx-i2c", WCD9XXX_I2C_DIGITAL_2}, |
| 1765 | {} |
| 1766 | }; |
| 1767 | |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 1768 | static struct i2c_device_id tabla_id_table[] = { |
Asish Bhattacharya | 2b709d4 | 2011-11-15 10:39:23 +0530 | [diff] [blame] | 1769 | {"tabla top level", WCD9XXX_I2C_TOP_LEVEL}, |
| 1770 | {"tabla analog", WCD9XXX_I2C_ANALOG}, |
| 1771 | {"tabla digital1", WCD9XXX_I2C_DIGITAL_1}, |
| 1772 | {"tabla digital2", WCD9XXX_I2C_DIGITAL_2}, |
| 1773 | {} |
| 1774 | }; |
| 1775 | MODULE_DEVICE_TABLE(i2c, tabla_id_table); |
| 1776 | |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 1777 | static struct i2c_driver tabla_i2c_driver = { |
| 1778 | .driver = { |
| 1779 | .owner = THIS_MODULE, |
| 1780 | .name = "tabla-i2c-core", |
| 1781 | }, |
| 1782 | .id_table = tabla_id_table, |
| 1783 | .probe = wcd9xxx_i2c_probe, |
| 1784 | .remove = __devexit_p(wcd9xxx_i2c_remove), |
| 1785 | .resume = wcd9xxx_i2c_resume, |
| 1786 | .suspend = wcd9xxx_i2c_suspend, |
| 1787 | }; |
| 1788 | |
Venkat Sudhir | a41630a | 2012-10-27 00:57:31 -0700 | [diff] [blame] | 1789 | static struct i2c_driver wcd9xxx_i2c_driver = { |
| 1790 | .driver = { |
| 1791 | .owner = THIS_MODULE, |
| 1792 | .name = "wcd9xxx-i2c-core", |
| 1793 | }, |
| 1794 | .id_table = wcd9xxx_id_table, |
| 1795 | .probe = wcd9xxx_i2c_probe, |
| 1796 | .remove = __devexit_p(wcd9xxx_i2c_remove), |
| 1797 | .resume = wcd9xxx_i2c_resume, |
| 1798 | .suspend = wcd9xxx_i2c_suspend, |
| 1799 | }; |
| 1800 | |
| 1801 | |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 1802 | static int __init wcd9xxx_init(void) |
| 1803 | { |
Banajit Goswami | 4d6d891b | 2012-12-12 23:59:07 -0800 | [diff] [blame] | 1804 | int ret[NUM_WCD9XXX_REG_RET]; |
| 1805 | int i = 0; |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 1806 | |
Venkat Sudhir | a50a376 | 2012-11-26 12:12:15 -0800 | [diff] [blame] | 1807 | wcd9xxx_intf = WCD9XXX_INTERFACE_TYPE_PROBING; |
| 1808 | |
Banajit Goswami | 4d6d891b | 2012-12-12 23:59:07 -0800 | [diff] [blame] | 1809 | ret[0] = slim_driver_register(&tabla_slim_driver); |
| 1810 | if (ret[0]) |
| 1811 | pr_err("Failed to register tabla SB driver: %d\n", ret[0]); |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 1812 | |
Banajit Goswami | 4d6d891b | 2012-12-12 23:59:07 -0800 | [diff] [blame] | 1813 | ret[1] = slim_driver_register(&tabla2x_slim_driver); |
| 1814 | if (ret[1]) |
| 1815 | pr_err("Failed to register tabla2x SB driver: %d\n", ret[1]); |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 1816 | |
Banajit Goswami | 4d6d891b | 2012-12-12 23:59:07 -0800 | [diff] [blame] | 1817 | ret[2] = i2c_add_driver(&tabla_i2c_driver); |
| 1818 | if (ret[2]) |
| 1819 | pr_err("failed to add the tabla2x I2C driver: %d\n", ret[2]); |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 1820 | |
Banajit Goswami | 4d6d891b | 2012-12-12 23:59:07 -0800 | [diff] [blame] | 1821 | ret[3] = slim_driver_register(&sitar_slim_driver); |
| 1822 | if (ret[3]) |
| 1823 | pr_err("Failed to register sitar SB driver: %d\n", ret[3]); |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 1824 | |
Banajit Goswami | 4d6d891b | 2012-12-12 23:59:07 -0800 | [diff] [blame] | 1825 | ret[4] = slim_driver_register(&sitar1p1_slim_driver); |
| 1826 | if (ret[4]) |
| 1827 | pr_err("Failed to register sitar SB driver: %d\n", ret[4]); |
Bhalchandra Gajare | 83c81f6 | 2012-05-18 16:09:05 -0700 | [diff] [blame] | 1828 | |
Banajit Goswami | 4d6d891b | 2012-12-12 23:59:07 -0800 | [diff] [blame] | 1829 | ret[5] = slim_driver_register(&taiko_slim_driver); |
| 1830 | if (ret[5]) |
| 1831 | pr_err("Failed to register taiko SB driver: %d\n", ret[5]); |
Joonwoo Park | a717211 | 2012-07-23 16:03:49 -0700 | [diff] [blame] | 1832 | |
Banajit Goswami | 4d6d891b | 2012-12-12 23:59:07 -0800 | [diff] [blame] | 1833 | ret[6] = i2c_add_driver(&wcd9xxx_i2c_driver); |
| 1834 | if (ret[6]) |
| 1835 | pr_err("failed to add the wcd9xxx I2C driver: %d\n", ret[6]); |
Venkat Sudhir | a41630a | 2012-10-27 00:57:31 -0700 | [diff] [blame] | 1836 | |
Banajit Goswami | 4d6d891b | 2012-12-12 23:59:07 -0800 | [diff] [blame] | 1837 | ret[7] = slim_driver_register(&tapan_slim_driver); |
| 1838 | if (ret[7]) |
| 1839 | pr_err("Failed to register tapan SB driver: %d\n", ret[7]); |
| 1840 | |
| 1841 | for (i = 0; i < NUM_WCD9XXX_REG_RET; i++) { |
| 1842 | if (ret[i]) |
| 1843 | return ret[i]; |
| 1844 | } |
| 1845 | return 0; |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 1846 | } |
| 1847 | module_init(wcd9xxx_init); |
| 1848 | |
| 1849 | static void __exit wcd9xxx_exit(void) |
| 1850 | { |
| 1851 | } |
| 1852 | module_exit(wcd9xxx_exit); |
| 1853 | |
| 1854 | MODULE_DESCRIPTION("Codec core driver"); |
| 1855 | MODULE_VERSION("1.0"); |
| 1856 | MODULE_LICENSE("GPL v2"); |