Misael Lopez Cruz | f19b282 | 2011-04-27 02:14:07 -0500 | [diff] [blame] | 1 | /* |
| 2 | * MFD driver for TWL6040 audio device |
| 3 | * |
| 4 | * Authors: Misael Lopez Cruz <misael.lopez@ti.com> |
| 5 | * Jorge Eduardo Candelaria <jorge.candelaria@ti.com> |
| 6 | * Peter Ujfalusi <peter.ujfalusi@ti.com> |
| 7 | * |
| 8 | * Copyright: (C) 2011 Texas Instruments, Inc. |
| 9 | * |
| 10 | * This program is free software; you can redistribute it and/or modify |
| 11 | * it under the terms of the GNU General Public License version 2 as |
| 12 | * published by the Free Software Foundation. |
| 13 | * |
| 14 | * This program is distributed in the hope that it will be useful, but |
| 15 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 17 | * General Public License for more details. |
| 18 | * |
| 19 | * You should have received a copy of the GNU General Public License |
| 20 | * along with this program; if not, write to the Free Software |
| 21 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA |
| 22 | * 02110-1301 USA |
| 23 | * |
| 24 | */ |
| 25 | |
| 26 | #include <linux/module.h> |
| 27 | #include <linux/types.h> |
| 28 | #include <linux/slab.h> |
| 29 | #include <linux/kernel.h> |
Peter Ujfalusi | 5af7df6 | 2012-05-02 16:54:42 +0300 | [diff] [blame] | 30 | #include <linux/err.h> |
Misael Lopez Cruz | f19b282 | 2011-04-27 02:14:07 -0500 | [diff] [blame] | 31 | #include <linux/platform_device.h> |
Peter Ujfalusi | 37e13ce | 2012-05-16 14:11:58 +0300 | [diff] [blame] | 32 | #include <linux/of.h> |
| 33 | #include <linux/of_irq.h> |
| 34 | #include <linux/of_gpio.h> |
| 35 | #include <linux/of_platform.h> |
Misael Lopez Cruz | f19b282 | 2011-04-27 02:14:07 -0500 | [diff] [blame] | 36 | #include <linux/gpio.h> |
| 37 | #include <linux/delay.h> |
Peter Ujfalusi | 8eaeb93 | 2012-04-03 11:56:51 +0300 | [diff] [blame] | 38 | #include <linux/i2c.h> |
| 39 | #include <linux/regmap.h> |
| 40 | #include <linux/err.h> |
Misael Lopez Cruz | f19b282 | 2011-04-27 02:14:07 -0500 | [diff] [blame] | 41 | #include <linux/mfd/core.h> |
| 42 | #include <linux/mfd/twl6040.h> |
Peter Ujfalusi | 5af7df6 | 2012-05-02 16:54:42 +0300 | [diff] [blame] | 43 | #include <linux/regulator/consumer.h> |
Misael Lopez Cruz | f19b282 | 2011-04-27 02:14:07 -0500 | [diff] [blame] | 44 | |
Peter Ujfalusi | 31b402e | 2011-10-12 11:57:54 +0300 | [diff] [blame] | 45 | #define VIBRACTRL_MEMBER(reg) ((reg == TWL6040_REG_VIBCTLL) ? 0 : 1) |
Peter Ujfalusi | 5af7df6 | 2012-05-02 16:54:42 +0300 | [diff] [blame] | 46 | #define TWL6040_NUM_SUPPLIES (2) |
Peter Ujfalusi | 31b402e | 2011-10-12 11:57:54 +0300 | [diff] [blame] | 47 | |
Samuel Ortiz | ca2cad6 | 2012-05-23 16:23:21 +0200 | [diff] [blame] | 48 | static bool twl6040_has_vibra(struct twl6040_platform_data *pdata, |
| 49 | struct device_node *node) |
| 50 | { |
| 51 | if (pdata && pdata->vibra) |
| 52 | return true; |
| 53 | |
| 54 | #ifdef CONFIG_OF |
| 55 | if (of_find_node_by_name(node, "vibra")) |
| 56 | return true; |
| 57 | #endif |
| 58 | |
| 59 | return false; |
| 60 | } |
| 61 | |
Misael Lopez Cruz | f19b282 | 2011-04-27 02:14:07 -0500 | [diff] [blame] | 62 | int twl6040_reg_read(struct twl6040 *twl6040, unsigned int reg) |
| 63 | { |
| 64 | int ret; |
Peter Ujfalusi | 8eaeb93 | 2012-04-03 11:56:51 +0300 | [diff] [blame] | 65 | unsigned int val; |
Misael Lopez Cruz | f19b282 | 2011-04-27 02:14:07 -0500 | [diff] [blame] | 66 | |
Peter Ujfalusi | 31b402e | 2011-10-12 11:57:54 +0300 | [diff] [blame] | 67 | /* Vibra control registers from cache */ |
| 68 | if (unlikely(reg == TWL6040_REG_VIBCTLL || |
| 69 | reg == TWL6040_REG_VIBCTLR)) { |
| 70 | val = twl6040->vibra_ctrl_cache[VIBRACTRL_MEMBER(reg)]; |
| 71 | } else { |
Peter Ujfalusi | 8eaeb93 | 2012-04-03 11:56:51 +0300 | [diff] [blame] | 72 | ret = regmap_read(twl6040->regmap, reg, &val); |
Axel Lin | c600040 | 2012-07-11 10:06:34 +0800 | [diff] [blame] | 73 | if (ret < 0) |
Peter Ujfalusi | 31b402e | 2011-10-12 11:57:54 +0300 | [diff] [blame] | 74 | return ret; |
Misael Lopez Cruz | f19b282 | 2011-04-27 02:14:07 -0500 | [diff] [blame] | 75 | } |
Misael Lopez Cruz | f19b282 | 2011-04-27 02:14:07 -0500 | [diff] [blame] | 76 | |
| 77 | return val; |
| 78 | } |
| 79 | EXPORT_SYMBOL(twl6040_reg_read); |
| 80 | |
| 81 | int twl6040_reg_write(struct twl6040 *twl6040, unsigned int reg, u8 val) |
| 82 | { |
| 83 | int ret; |
| 84 | |
Peter Ujfalusi | 8eaeb93 | 2012-04-03 11:56:51 +0300 | [diff] [blame] | 85 | ret = regmap_write(twl6040->regmap, reg, val); |
Peter Ujfalusi | 31b402e | 2011-10-12 11:57:54 +0300 | [diff] [blame] | 86 | /* Cache the vibra control registers */ |
| 87 | if (reg == TWL6040_REG_VIBCTLL || reg == TWL6040_REG_VIBCTLR) |
| 88 | twl6040->vibra_ctrl_cache[VIBRACTRL_MEMBER(reg)] = val; |
Misael Lopez Cruz | f19b282 | 2011-04-27 02:14:07 -0500 | [diff] [blame] | 89 | |
| 90 | return ret; |
| 91 | } |
| 92 | EXPORT_SYMBOL(twl6040_reg_write); |
| 93 | |
| 94 | int twl6040_set_bits(struct twl6040 *twl6040, unsigned int reg, u8 mask) |
| 95 | { |
Axel Lin | c600040 | 2012-07-11 10:06:34 +0800 | [diff] [blame] | 96 | return regmap_update_bits(twl6040->regmap, reg, mask, mask); |
Misael Lopez Cruz | f19b282 | 2011-04-27 02:14:07 -0500 | [diff] [blame] | 97 | } |
| 98 | EXPORT_SYMBOL(twl6040_set_bits); |
| 99 | |
| 100 | int twl6040_clear_bits(struct twl6040 *twl6040, unsigned int reg, u8 mask) |
| 101 | { |
Axel Lin | c600040 | 2012-07-11 10:06:34 +0800 | [diff] [blame] | 102 | return regmap_update_bits(twl6040->regmap, reg, mask, 0); |
Misael Lopez Cruz | f19b282 | 2011-04-27 02:14:07 -0500 | [diff] [blame] | 103 | } |
| 104 | EXPORT_SYMBOL(twl6040_clear_bits); |
| 105 | |
| 106 | /* twl6040 codec manual power-up sequence */ |
| 107 | static int twl6040_power_up(struct twl6040 *twl6040) |
| 108 | { |
| 109 | u8 ldoctl, ncpctl, lppllctl; |
| 110 | int ret; |
| 111 | |
| 112 | /* enable high-side LDO, reference system and internal oscillator */ |
| 113 | ldoctl = TWL6040_HSLDOENA | TWL6040_REFENA | TWL6040_OSCENA; |
| 114 | ret = twl6040_reg_write(twl6040, TWL6040_REG_LDOCTL, ldoctl); |
| 115 | if (ret) |
| 116 | return ret; |
| 117 | usleep_range(10000, 10500); |
| 118 | |
| 119 | /* enable negative charge pump */ |
| 120 | ncpctl = TWL6040_NCPENA; |
| 121 | ret = twl6040_reg_write(twl6040, TWL6040_REG_NCPCTL, ncpctl); |
| 122 | if (ret) |
| 123 | goto ncp_err; |
| 124 | usleep_range(1000, 1500); |
| 125 | |
| 126 | /* enable low-side LDO */ |
| 127 | ldoctl |= TWL6040_LSLDOENA; |
| 128 | ret = twl6040_reg_write(twl6040, TWL6040_REG_LDOCTL, ldoctl); |
| 129 | if (ret) |
| 130 | goto lsldo_err; |
| 131 | usleep_range(1000, 1500); |
| 132 | |
| 133 | /* enable low-power PLL */ |
| 134 | lppllctl = TWL6040_LPLLENA; |
| 135 | ret = twl6040_reg_write(twl6040, TWL6040_REG_LPPLLCTL, lppllctl); |
| 136 | if (ret) |
| 137 | goto lppll_err; |
| 138 | usleep_range(5000, 5500); |
| 139 | |
| 140 | /* disable internal oscillator */ |
| 141 | ldoctl &= ~TWL6040_OSCENA; |
| 142 | ret = twl6040_reg_write(twl6040, TWL6040_REG_LDOCTL, ldoctl); |
| 143 | if (ret) |
| 144 | goto osc_err; |
| 145 | |
| 146 | return 0; |
| 147 | |
| 148 | osc_err: |
| 149 | lppllctl &= ~TWL6040_LPLLENA; |
| 150 | twl6040_reg_write(twl6040, TWL6040_REG_LPPLLCTL, lppllctl); |
| 151 | lppll_err: |
| 152 | ldoctl &= ~TWL6040_LSLDOENA; |
| 153 | twl6040_reg_write(twl6040, TWL6040_REG_LDOCTL, ldoctl); |
| 154 | lsldo_err: |
| 155 | ncpctl &= ~TWL6040_NCPENA; |
| 156 | twl6040_reg_write(twl6040, TWL6040_REG_NCPCTL, ncpctl); |
| 157 | ncp_err: |
| 158 | ldoctl &= ~(TWL6040_HSLDOENA | TWL6040_REFENA | TWL6040_OSCENA); |
| 159 | twl6040_reg_write(twl6040, TWL6040_REG_LDOCTL, ldoctl); |
| 160 | |
| 161 | return ret; |
| 162 | } |
| 163 | |
| 164 | /* twl6040 manual power-down sequence */ |
| 165 | static void twl6040_power_down(struct twl6040 *twl6040) |
| 166 | { |
| 167 | u8 ncpctl, ldoctl, lppllctl; |
| 168 | |
| 169 | ncpctl = twl6040_reg_read(twl6040, TWL6040_REG_NCPCTL); |
| 170 | ldoctl = twl6040_reg_read(twl6040, TWL6040_REG_LDOCTL); |
| 171 | lppllctl = twl6040_reg_read(twl6040, TWL6040_REG_LPPLLCTL); |
| 172 | |
| 173 | /* enable internal oscillator */ |
| 174 | ldoctl |= TWL6040_OSCENA; |
| 175 | twl6040_reg_write(twl6040, TWL6040_REG_LDOCTL, ldoctl); |
| 176 | usleep_range(1000, 1500); |
| 177 | |
| 178 | /* disable low-power PLL */ |
| 179 | lppllctl &= ~TWL6040_LPLLENA; |
| 180 | twl6040_reg_write(twl6040, TWL6040_REG_LPPLLCTL, lppllctl); |
| 181 | |
| 182 | /* disable low-side LDO */ |
| 183 | ldoctl &= ~TWL6040_LSLDOENA; |
| 184 | twl6040_reg_write(twl6040, TWL6040_REG_LDOCTL, ldoctl); |
| 185 | |
| 186 | /* disable negative charge pump */ |
| 187 | ncpctl &= ~TWL6040_NCPENA; |
| 188 | twl6040_reg_write(twl6040, TWL6040_REG_NCPCTL, ncpctl); |
| 189 | |
| 190 | /* disable high-side LDO, reference system and internal oscillator */ |
| 191 | ldoctl &= ~(TWL6040_HSLDOENA | TWL6040_REFENA | TWL6040_OSCENA); |
| 192 | twl6040_reg_write(twl6040, TWL6040_REG_LDOCTL, ldoctl); |
| 193 | } |
| 194 | |
| 195 | static irqreturn_t twl6040_naudint_handler(int irq, void *data) |
| 196 | { |
| 197 | struct twl6040 *twl6040 = data; |
| 198 | u8 intid, status; |
| 199 | |
| 200 | intid = twl6040_reg_read(twl6040, TWL6040_REG_INTID); |
| 201 | |
| 202 | if (intid & TWL6040_READYINT) |
| 203 | complete(&twl6040->ready); |
| 204 | |
| 205 | if (intid & TWL6040_THINT) { |
| 206 | status = twl6040_reg_read(twl6040, TWL6040_REG_STATUS); |
| 207 | if (status & TWL6040_TSHUTDET) { |
Peter Ujfalusi | 2d7c957 | 2011-09-15 15:39:23 +0300 | [diff] [blame] | 208 | dev_warn(twl6040->dev, |
Misael Lopez Cruz | f19b282 | 2011-04-27 02:14:07 -0500 | [diff] [blame] | 209 | "Thermal shutdown, powering-off"); |
| 210 | twl6040_power(twl6040, 0); |
| 211 | } else { |
Peter Ujfalusi | 2d7c957 | 2011-09-15 15:39:23 +0300 | [diff] [blame] | 212 | dev_warn(twl6040->dev, |
Misael Lopez Cruz | f19b282 | 2011-04-27 02:14:07 -0500 | [diff] [blame] | 213 | "Leaving thermal shutdown, powering-on"); |
| 214 | twl6040_power(twl6040, 1); |
| 215 | } |
| 216 | } |
| 217 | |
| 218 | return IRQ_HANDLED; |
| 219 | } |
| 220 | |
| 221 | static int twl6040_power_up_completion(struct twl6040 *twl6040, |
| 222 | int naudint) |
| 223 | { |
| 224 | int time_left; |
| 225 | u8 intid; |
| 226 | |
| 227 | time_left = wait_for_completion_timeout(&twl6040->ready, |
| 228 | msecs_to_jiffies(144)); |
| 229 | if (!time_left) { |
| 230 | intid = twl6040_reg_read(twl6040, TWL6040_REG_INTID); |
| 231 | if (!(intid & TWL6040_READYINT)) { |
Peter Ujfalusi | 2d7c957 | 2011-09-15 15:39:23 +0300 | [diff] [blame] | 232 | dev_err(twl6040->dev, |
Misael Lopez Cruz | f19b282 | 2011-04-27 02:14:07 -0500 | [diff] [blame] | 233 | "timeout waiting for READYINT\n"); |
| 234 | return -ETIMEDOUT; |
| 235 | } |
| 236 | } |
| 237 | |
| 238 | return 0; |
| 239 | } |
| 240 | |
| 241 | int twl6040_power(struct twl6040 *twl6040, int on) |
| 242 | { |
| 243 | int audpwron = twl6040->audpwron; |
| 244 | int naudint = twl6040->irq; |
| 245 | int ret = 0; |
| 246 | |
| 247 | mutex_lock(&twl6040->mutex); |
| 248 | |
| 249 | if (on) { |
| 250 | /* already powered-up */ |
| 251 | if (twl6040->power_count++) |
| 252 | goto out; |
| 253 | |
| 254 | if (gpio_is_valid(audpwron)) { |
| 255 | /* use AUDPWRON line */ |
| 256 | gpio_set_value(audpwron, 1); |
| 257 | /* wait for power-up completion */ |
| 258 | ret = twl6040_power_up_completion(twl6040, naudint); |
| 259 | if (ret) { |
Peter Ujfalusi | 2d7c957 | 2011-09-15 15:39:23 +0300 | [diff] [blame] | 260 | dev_err(twl6040->dev, |
Misael Lopez Cruz | f19b282 | 2011-04-27 02:14:07 -0500 | [diff] [blame] | 261 | "automatic power-down failed\n"); |
| 262 | twl6040->power_count = 0; |
| 263 | goto out; |
| 264 | } |
| 265 | } else { |
| 266 | /* use manual power-up sequence */ |
| 267 | ret = twl6040_power_up(twl6040); |
| 268 | if (ret) { |
Peter Ujfalusi | 2d7c957 | 2011-09-15 15:39:23 +0300 | [diff] [blame] | 269 | dev_err(twl6040->dev, |
Misael Lopez Cruz | f19b282 | 2011-04-27 02:14:07 -0500 | [diff] [blame] | 270 | "manual power-up failed\n"); |
| 271 | twl6040->power_count = 0; |
| 272 | goto out; |
| 273 | } |
| 274 | } |
Peter Ujfalusi | cfb7a33 | 2011-07-04 10:28:28 +0300 | [diff] [blame] | 275 | /* Default PLL configuration after power up */ |
| 276 | twl6040->pll = TWL6040_SYSCLK_SEL_LPPLL; |
Misael Lopez Cruz | f19b282 | 2011-04-27 02:14:07 -0500 | [diff] [blame] | 277 | twl6040->sysclk = 19200000; |
Peter Ujfalusi | f8447d6 | 2012-01-14 20:58:43 +0100 | [diff] [blame] | 278 | twl6040->mclk = 32768; |
Misael Lopez Cruz | f19b282 | 2011-04-27 02:14:07 -0500 | [diff] [blame] | 279 | } else { |
| 280 | /* already powered-down */ |
| 281 | if (!twl6040->power_count) { |
Peter Ujfalusi | 2d7c957 | 2011-09-15 15:39:23 +0300 | [diff] [blame] | 282 | dev_err(twl6040->dev, |
Misael Lopez Cruz | f19b282 | 2011-04-27 02:14:07 -0500 | [diff] [blame] | 283 | "device is already powered-off\n"); |
| 284 | ret = -EPERM; |
| 285 | goto out; |
| 286 | } |
| 287 | |
| 288 | if (--twl6040->power_count) |
| 289 | goto out; |
| 290 | |
| 291 | if (gpio_is_valid(audpwron)) { |
| 292 | /* use AUDPWRON line */ |
| 293 | gpio_set_value(audpwron, 0); |
| 294 | |
| 295 | /* power-down sequence latency */ |
| 296 | usleep_range(500, 700); |
| 297 | } else { |
| 298 | /* use manual power-down sequence */ |
| 299 | twl6040_power_down(twl6040); |
| 300 | } |
Misael Lopez Cruz | f19b282 | 2011-04-27 02:14:07 -0500 | [diff] [blame] | 301 | twl6040->sysclk = 0; |
Peter Ujfalusi | f8447d6 | 2012-01-14 20:58:43 +0100 | [diff] [blame] | 302 | twl6040->mclk = 0; |
Misael Lopez Cruz | f19b282 | 2011-04-27 02:14:07 -0500 | [diff] [blame] | 303 | } |
| 304 | |
| 305 | out: |
| 306 | mutex_unlock(&twl6040->mutex); |
| 307 | return ret; |
| 308 | } |
| 309 | EXPORT_SYMBOL(twl6040_power); |
| 310 | |
Peter Ujfalusi | cfb7a33 | 2011-07-04 10:28:28 +0300 | [diff] [blame] | 311 | int twl6040_set_pll(struct twl6040 *twl6040, int pll_id, |
Misael Lopez Cruz | f19b282 | 2011-04-27 02:14:07 -0500 | [diff] [blame] | 312 | unsigned int freq_in, unsigned int freq_out) |
| 313 | { |
| 314 | u8 hppllctl, lppllctl; |
| 315 | int ret = 0; |
| 316 | |
| 317 | mutex_lock(&twl6040->mutex); |
| 318 | |
| 319 | hppllctl = twl6040_reg_read(twl6040, TWL6040_REG_HPPLLCTL); |
| 320 | lppllctl = twl6040_reg_read(twl6040, TWL6040_REG_LPPLLCTL); |
| 321 | |
Peter Ujfalusi | 2bd05db | 2012-01-14 20:58:44 +0100 | [diff] [blame] | 322 | /* Force full reconfiguration when switching between PLL */ |
| 323 | if (pll_id != twl6040->pll) { |
| 324 | twl6040->sysclk = 0; |
| 325 | twl6040->mclk = 0; |
| 326 | } |
| 327 | |
Peter Ujfalusi | cfb7a33 | 2011-07-04 10:28:28 +0300 | [diff] [blame] | 328 | switch (pll_id) { |
| 329 | case TWL6040_SYSCLK_SEL_LPPLL: |
Misael Lopez Cruz | f19b282 | 2011-04-27 02:14:07 -0500 | [diff] [blame] | 330 | /* low-power PLL divider */ |
Peter Ujfalusi | 2bd05db | 2012-01-14 20:58:44 +0100 | [diff] [blame] | 331 | /* Change the sysclk configuration only if it has been canged */ |
| 332 | if (twl6040->sysclk != freq_out) { |
| 333 | switch (freq_out) { |
| 334 | case 17640000: |
| 335 | lppllctl |= TWL6040_LPLLFIN; |
| 336 | break; |
| 337 | case 19200000: |
| 338 | lppllctl &= ~TWL6040_LPLLFIN; |
| 339 | break; |
| 340 | default: |
| 341 | dev_err(twl6040->dev, |
| 342 | "freq_out %d not supported\n", |
| 343 | freq_out); |
| 344 | ret = -EINVAL; |
| 345 | goto pll_out; |
| 346 | } |
| 347 | twl6040_reg_write(twl6040, TWL6040_REG_LPPLLCTL, |
| 348 | lppllctl); |
Misael Lopez Cruz | f19b282 | 2011-04-27 02:14:07 -0500 | [diff] [blame] | 349 | } |
Peter Ujfalusi | 2bd05db | 2012-01-14 20:58:44 +0100 | [diff] [blame] | 350 | |
| 351 | /* The PLL in use has not been change, we can exit */ |
| 352 | if (twl6040->pll == pll_id) |
| 353 | break; |
Misael Lopez Cruz | f19b282 | 2011-04-27 02:14:07 -0500 | [diff] [blame] | 354 | |
| 355 | switch (freq_in) { |
| 356 | case 32768: |
| 357 | lppllctl |= TWL6040_LPLLENA; |
| 358 | twl6040_reg_write(twl6040, TWL6040_REG_LPPLLCTL, |
| 359 | lppllctl); |
| 360 | mdelay(5); |
| 361 | lppllctl &= ~TWL6040_HPLLSEL; |
| 362 | twl6040_reg_write(twl6040, TWL6040_REG_LPPLLCTL, |
| 363 | lppllctl); |
| 364 | hppllctl &= ~TWL6040_HPLLENA; |
| 365 | twl6040_reg_write(twl6040, TWL6040_REG_HPPLLCTL, |
| 366 | hppllctl); |
| 367 | break; |
| 368 | default: |
Peter Ujfalusi | 2d7c957 | 2011-09-15 15:39:23 +0300 | [diff] [blame] | 369 | dev_err(twl6040->dev, |
Misael Lopez Cruz | f19b282 | 2011-04-27 02:14:07 -0500 | [diff] [blame] | 370 | "freq_in %d not supported\n", freq_in); |
| 371 | ret = -EINVAL; |
| 372 | goto pll_out; |
| 373 | } |
Misael Lopez Cruz | f19b282 | 2011-04-27 02:14:07 -0500 | [diff] [blame] | 374 | break; |
Peter Ujfalusi | cfb7a33 | 2011-07-04 10:28:28 +0300 | [diff] [blame] | 375 | case TWL6040_SYSCLK_SEL_HPPLL: |
Misael Lopez Cruz | f19b282 | 2011-04-27 02:14:07 -0500 | [diff] [blame] | 376 | /* high-performance PLL can provide only 19.2 MHz */ |
| 377 | if (freq_out != 19200000) { |
Peter Ujfalusi | 2d7c957 | 2011-09-15 15:39:23 +0300 | [diff] [blame] | 378 | dev_err(twl6040->dev, |
Misael Lopez Cruz | f19b282 | 2011-04-27 02:14:07 -0500 | [diff] [blame] | 379 | "freq_out %d not supported\n", freq_out); |
| 380 | ret = -EINVAL; |
| 381 | goto pll_out; |
| 382 | } |
| 383 | |
Peter Ujfalusi | 2bd05db | 2012-01-14 20:58:44 +0100 | [diff] [blame] | 384 | if (twl6040->mclk != freq_in) { |
| 385 | hppllctl &= ~TWL6040_MCLK_MSK; |
Misael Lopez Cruz | f19b282 | 2011-04-27 02:14:07 -0500 | [diff] [blame] | 386 | |
Peter Ujfalusi | 2bd05db | 2012-01-14 20:58:44 +0100 | [diff] [blame] | 387 | switch (freq_in) { |
| 388 | case 12000000: |
| 389 | /* PLL enabled, active mode */ |
| 390 | hppllctl |= TWL6040_MCLK_12000KHZ | |
| 391 | TWL6040_HPLLENA; |
| 392 | break; |
| 393 | case 19200000: |
| 394 | /* |
| 395 | * PLL disabled |
| 396 | * (enable PLL if MCLK jitter quality |
| 397 | * doesn't meet specification) |
| 398 | */ |
| 399 | hppllctl |= TWL6040_MCLK_19200KHZ; |
| 400 | break; |
| 401 | case 26000000: |
| 402 | /* PLL enabled, active mode */ |
| 403 | hppllctl |= TWL6040_MCLK_26000KHZ | |
| 404 | TWL6040_HPLLENA; |
| 405 | break; |
| 406 | case 38400000: |
| 407 | /* PLL enabled, active mode */ |
| 408 | hppllctl |= TWL6040_MCLK_38400KHZ | |
| 409 | TWL6040_HPLLENA; |
| 410 | break; |
| 411 | default: |
| 412 | dev_err(twl6040->dev, |
| 413 | "freq_in %d not supported\n", freq_in); |
| 414 | ret = -EINVAL; |
| 415 | goto pll_out; |
| 416 | } |
| 417 | |
Misael Lopez Cruz | f19b282 | 2011-04-27 02:14:07 -0500 | [diff] [blame] | 418 | /* |
Peter Ujfalusi | 2bd05db | 2012-01-14 20:58:44 +0100 | [diff] [blame] | 419 | * enable clock slicer to ensure input waveform is |
| 420 | * square |
Misael Lopez Cruz | f19b282 | 2011-04-27 02:14:07 -0500 | [diff] [blame] | 421 | */ |
Peter Ujfalusi | 2bd05db | 2012-01-14 20:58:44 +0100 | [diff] [blame] | 422 | hppllctl |= TWL6040_HPLLSQRENA; |
| 423 | |
| 424 | twl6040_reg_write(twl6040, TWL6040_REG_HPPLLCTL, |
| 425 | hppllctl); |
| 426 | usleep_range(500, 700); |
| 427 | lppllctl |= TWL6040_HPLLSEL; |
| 428 | twl6040_reg_write(twl6040, TWL6040_REG_LPPLLCTL, |
| 429 | lppllctl); |
| 430 | lppllctl &= ~TWL6040_LPLLENA; |
| 431 | twl6040_reg_write(twl6040, TWL6040_REG_LPPLLCTL, |
| 432 | lppllctl); |
Misael Lopez Cruz | f19b282 | 2011-04-27 02:14:07 -0500 | [diff] [blame] | 433 | } |
Misael Lopez Cruz | f19b282 | 2011-04-27 02:14:07 -0500 | [diff] [blame] | 434 | break; |
| 435 | default: |
Peter Ujfalusi | 2d7c957 | 2011-09-15 15:39:23 +0300 | [diff] [blame] | 436 | dev_err(twl6040->dev, "unknown pll id %d\n", pll_id); |
Misael Lopez Cruz | f19b282 | 2011-04-27 02:14:07 -0500 | [diff] [blame] | 437 | ret = -EINVAL; |
| 438 | goto pll_out; |
| 439 | } |
| 440 | |
| 441 | twl6040->sysclk = freq_out; |
Peter Ujfalusi | f8447d6 | 2012-01-14 20:58:43 +0100 | [diff] [blame] | 442 | twl6040->mclk = freq_in; |
Peter Ujfalusi | cfb7a33 | 2011-07-04 10:28:28 +0300 | [diff] [blame] | 443 | twl6040->pll = pll_id; |
Misael Lopez Cruz | f19b282 | 2011-04-27 02:14:07 -0500 | [diff] [blame] | 444 | |
| 445 | pll_out: |
| 446 | mutex_unlock(&twl6040->mutex); |
| 447 | return ret; |
| 448 | } |
| 449 | EXPORT_SYMBOL(twl6040_set_pll); |
| 450 | |
Peter Ujfalusi | cfb7a33 | 2011-07-04 10:28:28 +0300 | [diff] [blame] | 451 | int twl6040_get_pll(struct twl6040 *twl6040) |
Misael Lopez Cruz | f19b282 | 2011-04-27 02:14:07 -0500 | [diff] [blame] | 452 | { |
Peter Ujfalusi | cfb7a33 | 2011-07-04 10:28:28 +0300 | [diff] [blame] | 453 | if (twl6040->power_count) |
| 454 | return twl6040->pll; |
| 455 | else |
| 456 | return -ENODEV; |
Misael Lopez Cruz | f19b282 | 2011-04-27 02:14:07 -0500 | [diff] [blame] | 457 | } |
| 458 | EXPORT_SYMBOL(twl6040_get_pll); |
| 459 | |
| 460 | unsigned int twl6040_get_sysclk(struct twl6040 *twl6040) |
| 461 | { |
| 462 | return twl6040->sysclk; |
| 463 | } |
| 464 | EXPORT_SYMBOL(twl6040_get_sysclk); |
| 465 | |
Peter Ujfalusi | 70601ec | 2011-10-12 11:57:55 +0300 | [diff] [blame] | 466 | /* Get the combined status of the vibra control register */ |
| 467 | int twl6040_get_vibralr_status(struct twl6040 *twl6040) |
| 468 | { |
| 469 | u8 status; |
| 470 | |
| 471 | status = twl6040->vibra_ctrl_cache[0] | twl6040->vibra_ctrl_cache[1]; |
| 472 | status &= (TWL6040_VIBENA | TWL6040_VIBSEL); |
| 473 | |
| 474 | return status; |
| 475 | } |
| 476 | EXPORT_SYMBOL(twl6040_get_vibralr_status); |
| 477 | |
Peter Ujfalusi | 0f962ae | 2011-07-05 11:40:33 +0300 | [diff] [blame] | 478 | static struct resource twl6040_vibra_rsrc[] = { |
| 479 | { |
| 480 | .flags = IORESOURCE_IRQ, |
| 481 | }, |
| 482 | }; |
| 483 | |
| 484 | static struct resource twl6040_codec_rsrc[] = { |
| 485 | { |
| 486 | .flags = IORESOURCE_IRQ, |
| 487 | }, |
| 488 | }; |
| 489 | |
Peter Ujfalusi | 8eaeb93 | 2012-04-03 11:56:51 +0300 | [diff] [blame] | 490 | static bool twl6040_readable_reg(struct device *dev, unsigned int reg) |
Misael Lopez Cruz | f19b282 | 2011-04-27 02:14:07 -0500 | [diff] [blame] | 491 | { |
Peter Ujfalusi | 8eaeb93 | 2012-04-03 11:56:51 +0300 | [diff] [blame] | 492 | /* Register 0 is not readable */ |
| 493 | if (!reg) |
| 494 | return false; |
| 495 | return true; |
| 496 | } |
| 497 | |
| 498 | static struct regmap_config twl6040_regmap_config = { |
| 499 | .reg_bits = 8, |
| 500 | .val_bits = 8, |
| 501 | .max_register = TWL6040_REG_STATUS, /* 0x2e */ |
| 502 | |
| 503 | .readable_reg = twl6040_readable_reg, |
| 504 | }; |
| 505 | |
| 506 | static int __devinit twl6040_probe(struct i2c_client *client, |
| 507 | const struct i2c_device_id *id) |
| 508 | { |
| 509 | struct twl6040_platform_data *pdata = client->dev.platform_data; |
Peter Ujfalusi | 37e13ce | 2012-05-16 14:11:58 +0300 | [diff] [blame] | 510 | struct device_node *node = client->dev.of_node; |
Misael Lopez Cruz | f19b282 | 2011-04-27 02:14:07 -0500 | [diff] [blame] | 511 | struct twl6040 *twl6040; |
| 512 | struct mfd_cell *cell = NULL; |
Peter Ujfalusi | 1f01d60 | 2012-05-16 14:11:57 +0300 | [diff] [blame] | 513 | int irq, ret, children = 0; |
Misael Lopez Cruz | f19b282 | 2011-04-27 02:14:07 -0500 | [diff] [blame] | 514 | |
Peter Ujfalusi | 37e13ce | 2012-05-16 14:11:58 +0300 | [diff] [blame] | 515 | if (!pdata && !node) { |
Peter Ujfalusi | 8eaeb93 | 2012-04-03 11:56:51 +0300 | [diff] [blame] | 516 | dev_err(&client->dev, "Platform data is missing\n"); |
Misael Lopez Cruz | f19b282 | 2011-04-27 02:14:07 -0500 | [diff] [blame] | 517 | return -EINVAL; |
| 518 | } |
| 519 | |
Peter Ujfalusi | d20e1d2 | 2011-07-04 20:15:19 +0300 | [diff] [blame] | 520 | /* In order to operate correctly we need valid interrupt config */ |
Peter Ujfalusi | 6712419 | 2012-05-16 14:11:56 +0300 | [diff] [blame] | 521 | if (!client->irq) { |
Peter Ujfalusi | 8eaeb93 | 2012-04-03 11:56:51 +0300 | [diff] [blame] | 522 | dev_err(&client->dev, "Invalid IRQ configuration\n"); |
Peter Ujfalusi | d20e1d2 | 2011-07-04 20:15:19 +0300 | [diff] [blame] | 523 | return -EINVAL; |
| 524 | } |
| 525 | |
Peter Ujfalusi | 8eaeb93 | 2012-04-03 11:56:51 +0300 | [diff] [blame] | 526 | twl6040 = devm_kzalloc(&client->dev, sizeof(struct twl6040), |
| 527 | GFP_KERNEL); |
| 528 | if (!twl6040) { |
| 529 | ret = -ENOMEM; |
| 530 | goto err; |
| 531 | } |
Misael Lopez Cruz | f19b282 | 2011-04-27 02:14:07 -0500 | [diff] [blame] | 532 | |
Axel Lin | bbf6adc | 2012-04-25 10:09:46 +0800 | [diff] [blame] | 533 | twl6040->regmap = devm_regmap_init_i2c(client, &twl6040_regmap_config); |
Peter Ujfalusi | 8eaeb93 | 2012-04-03 11:56:51 +0300 | [diff] [blame] | 534 | if (IS_ERR(twl6040->regmap)) { |
| 535 | ret = PTR_ERR(twl6040->regmap); |
| 536 | goto err; |
| 537 | } |
Misael Lopez Cruz | f19b282 | 2011-04-27 02:14:07 -0500 | [diff] [blame] | 538 | |
Peter Ujfalusi | 8eaeb93 | 2012-04-03 11:56:51 +0300 | [diff] [blame] | 539 | i2c_set_clientdata(client, twl6040); |
| 540 | |
Peter Ujfalusi | 5af7df6 | 2012-05-02 16:54:42 +0300 | [diff] [blame] | 541 | twl6040->supplies[0].supply = "vio"; |
| 542 | twl6040->supplies[1].supply = "v2v1"; |
| 543 | ret = regulator_bulk_get(&client->dev, TWL6040_NUM_SUPPLIES, |
| 544 | twl6040->supplies); |
| 545 | if (ret != 0) { |
| 546 | dev_err(&client->dev, "Failed to get supplies: %d\n", ret); |
| 547 | goto regulator_get_err; |
| 548 | } |
| 549 | |
| 550 | ret = regulator_bulk_enable(TWL6040_NUM_SUPPLIES, twl6040->supplies); |
| 551 | if (ret != 0) { |
| 552 | dev_err(&client->dev, "Failed to enable supplies: %d\n", ret); |
| 553 | goto power_err; |
| 554 | } |
| 555 | |
Peter Ujfalusi | 8eaeb93 | 2012-04-03 11:56:51 +0300 | [diff] [blame] | 556 | twl6040->dev = &client->dev; |
| 557 | twl6040->irq = client->irq; |
Misael Lopez Cruz | f19b282 | 2011-04-27 02:14:07 -0500 | [diff] [blame] | 558 | |
| 559 | mutex_init(&twl6040->mutex); |
Misael Lopez Cruz | f19b282 | 2011-04-27 02:14:07 -0500 | [diff] [blame] | 560 | init_completion(&twl6040->ready); |
| 561 | |
| 562 | twl6040->rev = twl6040_reg_read(twl6040, TWL6040_REG_ASICREV); |
| 563 | |
Peter Ujfalusi | 77f63e0 | 2011-09-15 15:39:26 +0300 | [diff] [blame] | 564 | /* ERRATA: Automatic power-up is not possible in ES1.0 */ |
Peter Ujfalusi | 37e13ce | 2012-05-16 14:11:58 +0300 | [diff] [blame] | 565 | if (twl6040_get_revid(twl6040) > TWL6040_REV_ES1_0) { |
| 566 | if (pdata) |
| 567 | twl6040->audpwron = pdata->audpwron_gpio; |
| 568 | else |
| 569 | twl6040->audpwron = of_get_named_gpio(node, |
| 570 | "ti,audpwron-gpio", 0); |
| 571 | } else |
Peter Ujfalusi | 77f63e0 | 2011-09-15 15:39:26 +0300 | [diff] [blame] | 572 | twl6040->audpwron = -EINVAL; |
| 573 | |
Misael Lopez Cruz | f19b282 | 2011-04-27 02:14:07 -0500 | [diff] [blame] | 574 | if (gpio_is_valid(twl6040->audpwron)) { |
Axel Lin | b04edb9 | 2011-12-01 09:55:07 +0800 | [diff] [blame] | 575 | ret = gpio_request_one(twl6040->audpwron, GPIOF_OUT_INIT_LOW, |
| 576 | "audpwron"); |
Misael Lopez Cruz | f19b282 | 2011-04-27 02:14:07 -0500 | [diff] [blame] | 577 | if (ret) |
Peter Ujfalusi | 5af7df6 | 2012-05-02 16:54:42 +0300 | [diff] [blame] | 578 | goto gpio_err; |
Misael Lopez Cruz | f19b282 | 2011-04-27 02:14:07 -0500 | [diff] [blame] | 579 | } |
| 580 | |
Peter Ujfalusi | d20e1d2 | 2011-07-04 20:15:19 +0300 | [diff] [blame] | 581 | /* codec interrupt */ |
| 582 | ret = twl6040_irq_init(twl6040); |
| 583 | if (ret) |
Peter Ujfalusi | 5af7df6 | 2012-05-02 16:54:42 +0300 | [diff] [blame] | 584 | goto irq_init_err; |
Misael Lopez Cruz | f19b282 | 2011-04-27 02:14:07 -0500 | [diff] [blame] | 585 | |
Peter Ujfalusi | 1b7c472 | 2011-07-04 20:16:23 +0300 | [diff] [blame] | 586 | ret = request_threaded_irq(twl6040->irq_base + TWL6040_IRQ_READY, |
Fengguang Wu | 09e0906 | 2012-09-19 09:32:38 +0800 | [diff] [blame] | 587 | NULL, twl6040_naudint_handler, IRQF_ONESHOT, |
Peter Ujfalusi | 1b7c472 | 2011-07-04 20:16:23 +0300 | [diff] [blame] | 588 | "twl6040_irq_ready", twl6040); |
Peter Ujfalusi | d20e1d2 | 2011-07-04 20:15:19 +0300 | [diff] [blame] | 589 | if (ret) { |
| 590 | dev_err(twl6040->dev, "READY IRQ request failed: %d\n", |
| 591 | ret); |
| 592 | goto irq_err; |
Misael Lopez Cruz | f19b282 | 2011-04-27 02:14:07 -0500 | [diff] [blame] | 593 | } |
| 594 | |
| 595 | /* dual-access registers controlled by I2C only */ |
| 596 | twl6040_set_bits(twl6040, TWL6040_REG_ACCCTL, TWL6040_I2CSEL); |
| 597 | |
Peter Ujfalusi | 1f01d60 | 2012-05-16 14:11:57 +0300 | [diff] [blame] | 598 | /* |
| 599 | * The main functionality of twl6040 to provide audio on OMAP4+ systems. |
| 600 | * We can add the ASoC codec child whenever this driver has been loaded. |
| 601 | * The ASoC codec can work without pdata, pass the platform_data only if |
| 602 | * it has been provided. |
| 603 | */ |
| 604 | irq = twl6040->irq_base + TWL6040_IRQ_PLUG; |
| 605 | cell = &twl6040->cells[children]; |
| 606 | cell->name = "twl6040-codec"; |
| 607 | twl6040_codec_rsrc[0].start = irq; |
| 608 | twl6040_codec_rsrc[0].end = irq; |
| 609 | cell->resources = twl6040_codec_rsrc; |
| 610 | cell->num_resources = ARRAY_SIZE(twl6040_codec_rsrc); |
Peter Ujfalusi | 37e13ce | 2012-05-16 14:11:58 +0300 | [diff] [blame] | 611 | if (pdata && pdata->codec) { |
Peter Ujfalusi | 6c44863 | 2011-06-01 13:05:10 +0300 | [diff] [blame] | 612 | cell->platform_data = pdata->codec; |
| 613 | cell->pdata_size = sizeof(*pdata->codec); |
Misael Lopez Cruz | f19b282 | 2011-04-27 02:14:07 -0500 | [diff] [blame] | 614 | } |
Peter Ujfalusi | 1f01d60 | 2012-05-16 14:11:57 +0300 | [diff] [blame] | 615 | children++; |
Misael Lopez Cruz | f19b282 | 2011-04-27 02:14:07 -0500 | [diff] [blame] | 616 | |
Samuel Ortiz | ca2cad6 | 2012-05-23 16:23:21 +0200 | [diff] [blame] | 617 | if (twl6040_has_vibra(pdata, node)) { |
Peter Ujfalusi | 1f01d60 | 2012-05-16 14:11:57 +0300 | [diff] [blame] | 618 | irq = twl6040->irq_base + TWL6040_IRQ_VIB; |
Peter Ujfalusi | 0f962ae | 2011-07-05 11:40:33 +0300 | [diff] [blame] | 619 | |
Misael Lopez Cruz | f19b282 | 2011-04-27 02:14:07 -0500 | [diff] [blame] | 620 | cell = &twl6040->cells[children]; |
| 621 | cell->name = "twl6040-vibra"; |
Peter Ujfalusi | 0f962ae | 2011-07-05 11:40:33 +0300 | [diff] [blame] | 622 | twl6040_vibra_rsrc[0].start = irq; |
| 623 | twl6040_vibra_rsrc[0].end = irq; |
| 624 | cell->resources = twl6040_vibra_rsrc; |
| 625 | cell->num_resources = ARRAY_SIZE(twl6040_vibra_rsrc); |
| 626 | |
Peter Ujfalusi | 37e13ce | 2012-05-16 14:11:58 +0300 | [diff] [blame] | 627 | if (pdata && pdata->vibra) { |
| 628 | cell->platform_data = pdata->vibra; |
| 629 | cell->pdata_size = sizeof(*pdata->vibra); |
| 630 | } |
Misael Lopez Cruz | f19b282 | 2011-04-27 02:14:07 -0500 | [diff] [blame] | 631 | children++; |
| 632 | } |
| 633 | |
Peter Ujfalusi | 5cbe786 | 2012-08-16 15:13:14 +0300 | [diff] [blame] | 634 | /* |
| 635 | * Enable the GPO driver in the following cases: |
| 636 | * DT booted kernel or legacy boot with valid gpo platform_data |
| 637 | */ |
| 638 | if (!pdata || (pdata && pdata->gpo)) { |
| 639 | cell = &twl6040->cells[children]; |
| 640 | cell->name = "twl6040-gpo"; |
| 641 | |
| 642 | if (pdata) { |
| 643 | cell->platform_data = pdata->gpo; |
| 644 | cell->pdata_size = sizeof(*pdata->gpo); |
| 645 | } |
| 646 | children++; |
| 647 | } |
| 648 | |
Peter Ujfalusi | 1f01d60 | 2012-05-16 14:11:57 +0300 | [diff] [blame] | 649 | ret = mfd_add_devices(&client->dev, -1, twl6040->cells, children, |
Mark Brown | 55692af | 2012-09-11 15:16:36 +0800 | [diff] [blame] | 650 | NULL, 0, NULL); |
Peter Ujfalusi | 1f01d60 | 2012-05-16 14:11:57 +0300 | [diff] [blame] | 651 | if (ret) |
Misael Lopez Cruz | f19b282 | 2011-04-27 02:14:07 -0500 | [diff] [blame] | 652 | goto mfd_err; |
Misael Lopez Cruz | f19b282 | 2011-04-27 02:14:07 -0500 | [diff] [blame] | 653 | |
| 654 | return 0; |
| 655 | |
| 656 | mfd_err: |
Peter Ujfalusi | 1b7c472 | 2011-07-04 20:16:23 +0300 | [diff] [blame] | 657 | free_irq(twl6040->irq_base + TWL6040_IRQ_READY, twl6040); |
Misael Lopez Cruz | f19b282 | 2011-04-27 02:14:07 -0500 | [diff] [blame] | 658 | irq_err: |
Peter Ujfalusi | d20e1d2 | 2011-07-04 20:15:19 +0300 | [diff] [blame] | 659 | twl6040_irq_exit(twl6040); |
Peter Ujfalusi | 5af7df6 | 2012-05-02 16:54:42 +0300 | [diff] [blame] | 660 | irq_init_err: |
Misael Lopez Cruz | f19b282 | 2011-04-27 02:14:07 -0500 | [diff] [blame] | 661 | if (gpio_is_valid(twl6040->audpwron)) |
| 662 | gpio_free(twl6040->audpwron); |
Peter Ujfalusi | 5af7df6 | 2012-05-02 16:54:42 +0300 | [diff] [blame] | 663 | gpio_err: |
| 664 | regulator_bulk_disable(TWL6040_NUM_SUPPLIES, twl6040->supplies); |
| 665 | power_err: |
| 666 | regulator_bulk_free(TWL6040_NUM_SUPPLIES, twl6040->supplies); |
| 667 | regulator_get_err: |
Peter Ujfalusi | 8eaeb93 | 2012-04-03 11:56:51 +0300 | [diff] [blame] | 668 | i2c_set_clientdata(client, NULL); |
Peter Ujfalusi | 8eaeb93 | 2012-04-03 11:56:51 +0300 | [diff] [blame] | 669 | err: |
Misael Lopez Cruz | f19b282 | 2011-04-27 02:14:07 -0500 | [diff] [blame] | 670 | return ret; |
| 671 | } |
| 672 | |
Peter Ujfalusi | 8eaeb93 | 2012-04-03 11:56:51 +0300 | [diff] [blame] | 673 | static int __devexit twl6040_remove(struct i2c_client *client) |
Misael Lopez Cruz | f19b282 | 2011-04-27 02:14:07 -0500 | [diff] [blame] | 674 | { |
Peter Ujfalusi | 8eaeb93 | 2012-04-03 11:56:51 +0300 | [diff] [blame] | 675 | struct twl6040 *twl6040 = i2c_get_clientdata(client); |
Misael Lopez Cruz | f19b282 | 2011-04-27 02:14:07 -0500 | [diff] [blame] | 676 | |
| 677 | if (twl6040->power_count) |
| 678 | twl6040_power(twl6040, 0); |
| 679 | |
| 680 | if (gpio_is_valid(twl6040->audpwron)) |
| 681 | gpio_free(twl6040->audpwron); |
| 682 | |
Peter Ujfalusi | 1b7c472 | 2011-07-04 20:16:23 +0300 | [diff] [blame] | 683 | free_irq(twl6040->irq_base + TWL6040_IRQ_READY, twl6040); |
Peter Ujfalusi | d20e1d2 | 2011-07-04 20:15:19 +0300 | [diff] [blame] | 684 | twl6040_irq_exit(twl6040); |
Misael Lopez Cruz | f19b282 | 2011-04-27 02:14:07 -0500 | [diff] [blame] | 685 | |
Peter Ujfalusi | 8eaeb93 | 2012-04-03 11:56:51 +0300 | [diff] [blame] | 686 | mfd_remove_devices(&client->dev); |
| 687 | i2c_set_clientdata(client, NULL); |
Misael Lopez Cruz | f19b282 | 2011-04-27 02:14:07 -0500 | [diff] [blame] | 688 | |
Peter Ujfalusi | 5af7df6 | 2012-05-02 16:54:42 +0300 | [diff] [blame] | 689 | regulator_bulk_disable(TWL6040_NUM_SUPPLIES, twl6040->supplies); |
| 690 | regulator_bulk_free(TWL6040_NUM_SUPPLIES, twl6040->supplies); |
| 691 | |
Misael Lopez Cruz | f19b282 | 2011-04-27 02:14:07 -0500 | [diff] [blame] | 692 | return 0; |
| 693 | } |
| 694 | |
Peter Ujfalusi | 8eaeb93 | 2012-04-03 11:56:51 +0300 | [diff] [blame] | 695 | static const struct i2c_device_id twl6040_i2c_id[] = { |
| 696 | { "twl6040", 0, }, |
Peter Ujfalusi | 1fc74ae | 2012-07-16 11:49:44 +0200 | [diff] [blame] | 697 | { "twl6041", 0, }, |
Peter Ujfalusi | 8eaeb93 | 2012-04-03 11:56:51 +0300 | [diff] [blame] | 698 | { }, |
| 699 | }; |
| 700 | MODULE_DEVICE_TABLE(i2c, twl6040_i2c_id); |
| 701 | |
| 702 | static struct i2c_driver twl6040_driver = { |
| 703 | .driver = { |
| 704 | .name = "twl6040", |
| 705 | .owner = THIS_MODULE, |
| 706 | }, |
Misael Lopez Cruz | f19b282 | 2011-04-27 02:14:07 -0500 | [diff] [blame] | 707 | .probe = twl6040_probe, |
| 708 | .remove = __devexit_p(twl6040_remove), |
Peter Ujfalusi | 8eaeb93 | 2012-04-03 11:56:51 +0300 | [diff] [blame] | 709 | .id_table = twl6040_i2c_id, |
Misael Lopez Cruz | f19b282 | 2011-04-27 02:14:07 -0500 | [diff] [blame] | 710 | }; |
| 711 | |
Peter Ujfalusi | 8eaeb93 | 2012-04-03 11:56:51 +0300 | [diff] [blame] | 712 | module_i2c_driver(twl6040_driver); |
Misael Lopez Cruz | f19b282 | 2011-04-27 02:14:07 -0500 | [diff] [blame] | 713 | |
| 714 | MODULE_DESCRIPTION("TWL6040 MFD"); |
| 715 | MODULE_AUTHOR("Misael Lopez Cruz <misael.lopez@ti.com>"); |
| 716 | MODULE_AUTHOR("Jorge Eduardo Candelaria <jorge.candelaria@ti.com>"); |
| 717 | MODULE_LICENSE("GPL"); |
| 718 | MODULE_ALIAS("platform:twl6040"); |