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 */ |
Peter Ujfalusi | f9be134 | 2012-10-11 13:55:30 +0200 | [diff] [blame] | 107 | static int twl6040_power_up_manual(struct twl6040 *twl6040) |
Misael Lopez Cruz | f19b282 | 2011-04-27 02:14:07 -0500 | [diff] [blame] | 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 | |
Peter Ujfalusi | f9be134 | 2012-10-11 13:55:30 +0200 | [diff] [blame] | 161 | dev_err(twl6040->dev, "manual power-up failed\n"); |
Misael Lopez Cruz | f19b282 | 2011-04-27 02:14:07 -0500 | [diff] [blame] | 162 | return ret; |
| 163 | } |
| 164 | |
| 165 | /* twl6040 manual power-down sequence */ |
Peter Ujfalusi | f9be134 | 2012-10-11 13:55:30 +0200 | [diff] [blame] | 166 | static void twl6040_power_down_manual(struct twl6040 *twl6040) |
Misael Lopez Cruz | f19b282 | 2011-04-27 02:14:07 -0500 | [diff] [blame] | 167 | { |
| 168 | u8 ncpctl, ldoctl, lppllctl; |
| 169 | |
| 170 | ncpctl = twl6040_reg_read(twl6040, TWL6040_REG_NCPCTL); |
| 171 | ldoctl = twl6040_reg_read(twl6040, TWL6040_REG_LDOCTL); |
| 172 | lppllctl = twl6040_reg_read(twl6040, TWL6040_REG_LPPLLCTL); |
| 173 | |
| 174 | /* enable internal oscillator */ |
| 175 | ldoctl |= TWL6040_OSCENA; |
| 176 | twl6040_reg_write(twl6040, TWL6040_REG_LDOCTL, ldoctl); |
| 177 | usleep_range(1000, 1500); |
| 178 | |
| 179 | /* disable low-power PLL */ |
| 180 | lppllctl &= ~TWL6040_LPLLENA; |
| 181 | twl6040_reg_write(twl6040, TWL6040_REG_LPPLLCTL, lppllctl); |
| 182 | |
| 183 | /* disable low-side LDO */ |
| 184 | ldoctl &= ~TWL6040_LSLDOENA; |
| 185 | twl6040_reg_write(twl6040, TWL6040_REG_LDOCTL, ldoctl); |
| 186 | |
| 187 | /* disable negative charge pump */ |
| 188 | ncpctl &= ~TWL6040_NCPENA; |
| 189 | twl6040_reg_write(twl6040, TWL6040_REG_NCPCTL, ncpctl); |
| 190 | |
| 191 | /* disable high-side LDO, reference system and internal oscillator */ |
| 192 | ldoctl &= ~(TWL6040_HSLDOENA | TWL6040_REFENA | TWL6040_OSCENA); |
| 193 | twl6040_reg_write(twl6040, TWL6040_REG_LDOCTL, ldoctl); |
| 194 | } |
| 195 | |
Peter Ujfalusi | 1ac9626 | 2012-10-11 13:55:31 +0200 | [diff] [blame] | 196 | static irqreturn_t twl6040_readyint_handler(int irq, void *data) |
Misael Lopez Cruz | f19b282 | 2011-04-27 02:14:07 -0500 | [diff] [blame] | 197 | { |
| 198 | struct twl6040 *twl6040 = data; |
Misael Lopez Cruz | f19b282 | 2011-04-27 02:14:07 -0500 | [diff] [blame] | 199 | |
Peter Ujfalusi | 1ac9626 | 2012-10-11 13:55:31 +0200 | [diff] [blame] | 200 | complete(&twl6040->ready); |
Misael Lopez Cruz | f19b282 | 2011-04-27 02:14:07 -0500 | [diff] [blame] | 201 | |
Peter Ujfalusi | 1ac9626 | 2012-10-11 13:55:31 +0200 | [diff] [blame] | 202 | return IRQ_HANDLED; |
| 203 | } |
Misael Lopez Cruz | f19b282 | 2011-04-27 02:14:07 -0500 | [diff] [blame] | 204 | |
Peter Ujfalusi | 1ac9626 | 2012-10-11 13:55:31 +0200 | [diff] [blame] | 205 | static irqreturn_t twl6040_thint_handler(int irq, void *data) |
| 206 | { |
| 207 | struct twl6040 *twl6040 = data; |
| 208 | u8 status; |
| 209 | |
| 210 | status = twl6040_reg_read(twl6040, TWL6040_REG_STATUS); |
| 211 | if (status & TWL6040_TSHUTDET) { |
| 212 | dev_warn(twl6040->dev, "Thermal shutdown, powering-off"); |
| 213 | twl6040_power(twl6040, 0); |
| 214 | } else { |
| 215 | dev_warn(twl6040->dev, "Leaving thermal shutdown, powering-on"); |
| 216 | twl6040_power(twl6040, 1); |
Misael Lopez Cruz | f19b282 | 2011-04-27 02:14:07 -0500 | [diff] [blame] | 217 | } |
| 218 | |
| 219 | return IRQ_HANDLED; |
| 220 | } |
| 221 | |
Peter Ujfalusi | f9be134 | 2012-10-11 13:55:30 +0200 | [diff] [blame] | 222 | static int twl6040_power_up_automatic(struct twl6040 *twl6040) |
Misael Lopez Cruz | f19b282 | 2011-04-27 02:14:07 -0500 | [diff] [blame] | 223 | { |
| 224 | int time_left; |
Peter Ujfalusi | f9be134 | 2012-10-11 13:55:30 +0200 | [diff] [blame] | 225 | |
| 226 | gpio_set_value(twl6040->audpwron, 1); |
Misael Lopez Cruz | f19b282 | 2011-04-27 02:14:07 -0500 | [diff] [blame] | 227 | |
| 228 | time_left = wait_for_completion_timeout(&twl6040->ready, |
| 229 | msecs_to_jiffies(144)); |
| 230 | if (!time_left) { |
Peter Ujfalusi | f9be134 | 2012-10-11 13:55:30 +0200 | [diff] [blame] | 231 | u8 intid; |
| 232 | |
| 233 | dev_warn(twl6040->dev, "timeout waiting for READYINT\n"); |
Misael Lopez Cruz | f19b282 | 2011-04-27 02:14:07 -0500 | [diff] [blame] | 234 | intid = twl6040_reg_read(twl6040, TWL6040_REG_INTID); |
| 235 | if (!(intid & TWL6040_READYINT)) { |
Peter Ujfalusi | f9be134 | 2012-10-11 13:55:30 +0200 | [diff] [blame] | 236 | dev_err(twl6040->dev, "automatic power-up failed\n"); |
| 237 | gpio_set_value(twl6040->audpwron, 0); |
Misael Lopez Cruz | f19b282 | 2011-04-27 02:14:07 -0500 | [diff] [blame] | 238 | return -ETIMEDOUT; |
| 239 | } |
| 240 | } |
| 241 | |
| 242 | return 0; |
| 243 | } |
| 244 | |
| 245 | int twl6040_power(struct twl6040 *twl6040, int on) |
| 246 | { |
Misael Lopez Cruz | f19b282 | 2011-04-27 02:14:07 -0500 | [diff] [blame] | 247 | int ret = 0; |
| 248 | |
| 249 | mutex_lock(&twl6040->mutex); |
| 250 | |
| 251 | if (on) { |
| 252 | /* already powered-up */ |
| 253 | if (twl6040->power_count++) |
| 254 | goto out; |
| 255 | |
Peter Ujfalusi | f9be134 | 2012-10-11 13:55:30 +0200 | [diff] [blame] | 256 | if (gpio_is_valid(twl6040->audpwron)) { |
| 257 | /* use automatic power-up sequence */ |
| 258 | ret = twl6040_power_up_automatic(twl6040); |
Misael Lopez Cruz | f19b282 | 2011-04-27 02:14:07 -0500 | [diff] [blame] | 259 | if (ret) { |
Misael Lopez Cruz | f19b282 | 2011-04-27 02:14:07 -0500 | [diff] [blame] | 260 | twl6040->power_count = 0; |
| 261 | goto out; |
| 262 | } |
| 263 | } else { |
| 264 | /* use manual power-up sequence */ |
Peter Ujfalusi | f9be134 | 2012-10-11 13:55:30 +0200 | [diff] [blame] | 265 | ret = twl6040_power_up_manual(twl6040); |
Misael Lopez Cruz | f19b282 | 2011-04-27 02:14:07 -0500 | [diff] [blame] | 266 | if (ret) { |
Misael Lopez Cruz | f19b282 | 2011-04-27 02:14:07 -0500 | [diff] [blame] | 267 | twl6040->power_count = 0; |
| 268 | goto out; |
| 269 | } |
| 270 | } |
Peter Ujfalusi | cfb7a33 | 2011-07-04 10:28:28 +0300 | [diff] [blame] | 271 | /* Default PLL configuration after power up */ |
| 272 | twl6040->pll = TWL6040_SYSCLK_SEL_LPPLL; |
Misael Lopez Cruz | f19b282 | 2011-04-27 02:14:07 -0500 | [diff] [blame] | 273 | twl6040->sysclk = 19200000; |
Peter Ujfalusi | f8447d6 | 2012-01-14 20:58:43 +0100 | [diff] [blame] | 274 | twl6040->mclk = 32768; |
Misael Lopez Cruz | f19b282 | 2011-04-27 02:14:07 -0500 | [diff] [blame] | 275 | } else { |
| 276 | /* already powered-down */ |
| 277 | if (!twl6040->power_count) { |
Peter Ujfalusi | 2d7c957 | 2011-09-15 15:39:23 +0300 | [diff] [blame] | 278 | dev_err(twl6040->dev, |
Misael Lopez Cruz | f19b282 | 2011-04-27 02:14:07 -0500 | [diff] [blame] | 279 | "device is already powered-off\n"); |
| 280 | ret = -EPERM; |
| 281 | goto out; |
| 282 | } |
| 283 | |
| 284 | if (--twl6040->power_count) |
| 285 | goto out; |
| 286 | |
Peter Ujfalusi | f9be134 | 2012-10-11 13:55:30 +0200 | [diff] [blame] | 287 | if (gpio_is_valid(twl6040->audpwron)) { |
Misael Lopez Cruz | f19b282 | 2011-04-27 02:14:07 -0500 | [diff] [blame] | 288 | /* use AUDPWRON line */ |
Peter Ujfalusi | f9be134 | 2012-10-11 13:55:30 +0200 | [diff] [blame] | 289 | gpio_set_value(twl6040->audpwron, 0); |
Misael Lopez Cruz | f19b282 | 2011-04-27 02:14:07 -0500 | [diff] [blame] | 290 | |
| 291 | /* power-down sequence latency */ |
| 292 | usleep_range(500, 700); |
| 293 | } else { |
| 294 | /* use manual power-down sequence */ |
Peter Ujfalusi | f9be134 | 2012-10-11 13:55:30 +0200 | [diff] [blame] | 295 | twl6040_power_down_manual(twl6040); |
Misael Lopez Cruz | f19b282 | 2011-04-27 02:14:07 -0500 | [diff] [blame] | 296 | } |
Misael Lopez Cruz | f19b282 | 2011-04-27 02:14:07 -0500 | [diff] [blame] | 297 | twl6040->sysclk = 0; |
Peter Ujfalusi | f8447d6 | 2012-01-14 20:58:43 +0100 | [diff] [blame] | 298 | twl6040->mclk = 0; |
Misael Lopez Cruz | f19b282 | 2011-04-27 02:14:07 -0500 | [diff] [blame] | 299 | } |
| 300 | |
| 301 | out: |
| 302 | mutex_unlock(&twl6040->mutex); |
| 303 | return ret; |
| 304 | } |
| 305 | EXPORT_SYMBOL(twl6040_power); |
| 306 | |
Peter Ujfalusi | cfb7a33 | 2011-07-04 10:28:28 +0300 | [diff] [blame] | 307 | int twl6040_set_pll(struct twl6040 *twl6040, int pll_id, |
Misael Lopez Cruz | f19b282 | 2011-04-27 02:14:07 -0500 | [diff] [blame] | 308 | unsigned int freq_in, unsigned int freq_out) |
| 309 | { |
| 310 | u8 hppllctl, lppllctl; |
| 311 | int ret = 0; |
| 312 | |
| 313 | mutex_lock(&twl6040->mutex); |
| 314 | |
| 315 | hppllctl = twl6040_reg_read(twl6040, TWL6040_REG_HPPLLCTL); |
| 316 | lppllctl = twl6040_reg_read(twl6040, TWL6040_REG_LPPLLCTL); |
| 317 | |
Peter Ujfalusi | 2bd05db | 2012-01-14 20:58:44 +0100 | [diff] [blame] | 318 | /* Force full reconfiguration when switching between PLL */ |
| 319 | if (pll_id != twl6040->pll) { |
| 320 | twl6040->sysclk = 0; |
| 321 | twl6040->mclk = 0; |
| 322 | } |
| 323 | |
Peter Ujfalusi | cfb7a33 | 2011-07-04 10:28:28 +0300 | [diff] [blame] | 324 | switch (pll_id) { |
| 325 | case TWL6040_SYSCLK_SEL_LPPLL: |
Misael Lopez Cruz | f19b282 | 2011-04-27 02:14:07 -0500 | [diff] [blame] | 326 | /* low-power PLL divider */ |
Peter Ujfalusi | 2bd05db | 2012-01-14 20:58:44 +0100 | [diff] [blame] | 327 | /* Change the sysclk configuration only if it has been canged */ |
| 328 | if (twl6040->sysclk != freq_out) { |
| 329 | switch (freq_out) { |
| 330 | case 17640000: |
| 331 | lppllctl |= TWL6040_LPLLFIN; |
| 332 | break; |
| 333 | case 19200000: |
| 334 | lppllctl &= ~TWL6040_LPLLFIN; |
| 335 | break; |
| 336 | default: |
| 337 | dev_err(twl6040->dev, |
| 338 | "freq_out %d not supported\n", |
| 339 | freq_out); |
| 340 | ret = -EINVAL; |
| 341 | goto pll_out; |
| 342 | } |
| 343 | twl6040_reg_write(twl6040, TWL6040_REG_LPPLLCTL, |
| 344 | lppllctl); |
Misael Lopez Cruz | f19b282 | 2011-04-27 02:14:07 -0500 | [diff] [blame] | 345 | } |
Peter Ujfalusi | 2bd05db | 2012-01-14 20:58:44 +0100 | [diff] [blame] | 346 | |
| 347 | /* The PLL in use has not been change, we can exit */ |
| 348 | if (twl6040->pll == pll_id) |
| 349 | break; |
Misael Lopez Cruz | f19b282 | 2011-04-27 02:14:07 -0500 | [diff] [blame] | 350 | |
| 351 | switch (freq_in) { |
| 352 | case 32768: |
| 353 | lppllctl |= TWL6040_LPLLENA; |
| 354 | twl6040_reg_write(twl6040, TWL6040_REG_LPPLLCTL, |
| 355 | lppllctl); |
| 356 | mdelay(5); |
| 357 | lppllctl &= ~TWL6040_HPLLSEL; |
| 358 | twl6040_reg_write(twl6040, TWL6040_REG_LPPLLCTL, |
| 359 | lppllctl); |
| 360 | hppllctl &= ~TWL6040_HPLLENA; |
| 361 | twl6040_reg_write(twl6040, TWL6040_REG_HPPLLCTL, |
| 362 | hppllctl); |
| 363 | break; |
| 364 | default: |
Peter Ujfalusi | 2d7c957 | 2011-09-15 15:39:23 +0300 | [diff] [blame] | 365 | dev_err(twl6040->dev, |
Misael Lopez Cruz | f19b282 | 2011-04-27 02:14:07 -0500 | [diff] [blame] | 366 | "freq_in %d not supported\n", freq_in); |
| 367 | ret = -EINVAL; |
| 368 | goto pll_out; |
| 369 | } |
Misael Lopez Cruz | f19b282 | 2011-04-27 02:14:07 -0500 | [diff] [blame] | 370 | break; |
Peter Ujfalusi | cfb7a33 | 2011-07-04 10:28:28 +0300 | [diff] [blame] | 371 | case TWL6040_SYSCLK_SEL_HPPLL: |
Misael Lopez Cruz | f19b282 | 2011-04-27 02:14:07 -0500 | [diff] [blame] | 372 | /* high-performance PLL can provide only 19.2 MHz */ |
| 373 | if (freq_out != 19200000) { |
Peter Ujfalusi | 2d7c957 | 2011-09-15 15:39:23 +0300 | [diff] [blame] | 374 | dev_err(twl6040->dev, |
Misael Lopez Cruz | f19b282 | 2011-04-27 02:14:07 -0500 | [diff] [blame] | 375 | "freq_out %d not supported\n", freq_out); |
| 376 | ret = -EINVAL; |
| 377 | goto pll_out; |
| 378 | } |
| 379 | |
Peter Ujfalusi | 2bd05db | 2012-01-14 20:58:44 +0100 | [diff] [blame] | 380 | if (twl6040->mclk != freq_in) { |
| 381 | hppllctl &= ~TWL6040_MCLK_MSK; |
Misael Lopez Cruz | f19b282 | 2011-04-27 02:14:07 -0500 | [diff] [blame] | 382 | |
Peter Ujfalusi | 2bd05db | 2012-01-14 20:58:44 +0100 | [diff] [blame] | 383 | switch (freq_in) { |
| 384 | case 12000000: |
| 385 | /* PLL enabled, active mode */ |
| 386 | hppllctl |= TWL6040_MCLK_12000KHZ | |
| 387 | TWL6040_HPLLENA; |
| 388 | break; |
| 389 | case 19200000: |
| 390 | /* |
| 391 | * PLL disabled |
| 392 | * (enable PLL if MCLK jitter quality |
| 393 | * doesn't meet specification) |
| 394 | */ |
| 395 | hppllctl |= TWL6040_MCLK_19200KHZ; |
| 396 | break; |
| 397 | case 26000000: |
| 398 | /* PLL enabled, active mode */ |
| 399 | hppllctl |= TWL6040_MCLK_26000KHZ | |
| 400 | TWL6040_HPLLENA; |
| 401 | break; |
| 402 | case 38400000: |
| 403 | /* PLL enabled, active mode */ |
| 404 | hppllctl |= TWL6040_MCLK_38400KHZ | |
| 405 | TWL6040_HPLLENA; |
| 406 | break; |
| 407 | default: |
| 408 | dev_err(twl6040->dev, |
| 409 | "freq_in %d not supported\n", freq_in); |
| 410 | ret = -EINVAL; |
| 411 | goto pll_out; |
| 412 | } |
| 413 | |
Misael Lopez Cruz | f19b282 | 2011-04-27 02:14:07 -0500 | [diff] [blame] | 414 | /* |
Peter Ujfalusi | 2bd05db | 2012-01-14 20:58:44 +0100 | [diff] [blame] | 415 | * enable clock slicer to ensure input waveform is |
| 416 | * square |
Misael Lopez Cruz | f19b282 | 2011-04-27 02:14:07 -0500 | [diff] [blame] | 417 | */ |
Peter Ujfalusi | 2bd05db | 2012-01-14 20:58:44 +0100 | [diff] [blame] | 418 | hppllctl |= TWL6040_HPLLSQRENA; |
| 419 | |
| 420 | twl6040_reg_write(twl6040, TWL6040_REG_HPPLLCTL, |
| 421 | hppllctl); |
| 422 | usleep_range(500, 700); |
| 423 | lppllctl |= TWL6040_HPLLSEL; |
| 424 | twl6040_reg_write(twl6040, TWL6040_REG_LPPLLCTL, |
| 425 | lppllctl); |
| 426 | lppllctl &= ~TWL6040_LPLLENA; |
| 427 | twl6040_reg_write(twl6040, TWL6040_REG_LPPLLCTL, |
| 428 | lppllctl); |
Misael Lopez Cruz | f19b282 | 2011-04-27 02:14:07 -0500 | [diff] [blame] | 429 | } |
Misael Lopez Cruz | f19b282 | 2011-04-27 02:14:07 -0500 | [diff] [blame] | 430 | break; |
| 431 | default: |
Peter Ujfalusi | 2d7c957 | 2011-09-15 15:39:23 +0300 | [diff] [blame] | 432 | dev_err(twl6040->dev, "unknown pll id %d\n", pll_id); |
Misael Lopez Cruz | f19b282 | 2011-04-27 02:14:07 -0500 | [diff] [blame] | 433 | ret = -EINVAL; |
| 434 | goto pll_out; |
| 435 | } |
| 436 | |
| 437 | twl6040->sysclk = freq_out; |
Peter Ujfalusi | f8447d6 | 2012-01-14 20:58:43 +0100 | [diff] [blame] | 438 | twl6040->mclk = freq_in; |
Peter Ujfalusi | cfb7a33 | 2011-07-04 10:28:28 +0300 | [diff] [blame] | 439 | twl6040->pll = pll_id; |
Misael Lopez Cruz | f19b282 | 2011-04-27 02:14:07 -0500 | [diff] [blame] | 440 | |
| 441 | pll_out: |
| 442 | mutex_unlock(&twl6040->mutex); |
| 443 | return ret; |
| 444 | } |
| 445 | EXPORT_SYMBOL(twl6040_set_pll); |
| 446 | |
Peter Ujfalusi | cfb7a33 | 2011-07-04 10:28:28 +0300 | [diff] [blame] | 447 | int twl6040_get_pll(struct twl6040 *twl6040) |
Misael Lopez Cruz | f19b282 | 2011-04-27 02:14:07 -0500 | [diff] [blame] | 448 | { |
Peter Ujfalusi | cfb7a33 | 2011-07-04 10:28:28 +0300 | [diff] [blame] | 449 | if (twl6040->power_count) |
| 450 | return twl6040->pll; |
| 451 | else |
| 452 | return -ENODEV; |
Misael Lopez Cruz | f19b282 | 2011-04-27 02:14:07 -0500 | [diff] [blame] | 453 | } |
| 454 | EXPORT_SYMBOL(twl6040_get_pll); |
| 455 | |
| 456 | unsigned int twl6040_get_sysclk(struct twl6040 *twl6040) |
| 457 | { |
| 458 | return twl6040->sysclk; |
| 459 | } |
| 460 | EXPORT_SYMBOL(twl6040_get_sysclk); |
| 461 | |
Peter Ujfalusi | 70601ec | 2011-10-12 11:57:55 +0300 | [diff] [blame] | 462 | /* Get the combined status of the vibra control register */ |
| 463 | int twl6040_get_vibralr_status(struct twl6040 *twl6040) |
| 464 | { |
| 465 | u8 status; |
| 466 | |
| 467 | status = twl6040->vibra_ctrl_cache[0] | twl6040->vibra_ctrl_cache[1]; |
| 468 | status &= (TWL6040_VIBENA | TWL6040_VIBSEL); |
| 469 | |
| 470 | return status; |
| 471 | } |
| 472 | EXPORT_SYMBOL(twl6040_get_vibralr_status); |
| 473 | |
Peter Ujfalusi | 0f962ae | 2011-07-05 11:40:33 +0300 | [diff] [blame] | 474 | static struct resource twl6040_vibra_rsrc[] = { |
| 475 | { |
| 476 | .flags = IORESOURCE_IRQ, |
| 477 | }, |
| 478 | }; |
| 479 | |
| 480 | static struct resource twl6040_codec_rsrc[] = { |
| 481 | { |
| 482 | .flags = IORESOURCE_IRQ, |
| 483 | }, |
| 484 | }; |
| 485 | |
Peter Ujfalusi | 8eaeb93 | 2012-04-03 11:56:51 +0300 | [diff] [blame] | 486 | static bool twl6040_readable_reg(struct device *dev, unsigned int reg) |
Misael Lopez Cruz | f19b282 | 2011-04-27 02:14:07 -0500 | [diff] [blame] | 487 | { |
Peter Ujfalusi | 8eaeb93 | 2012-04-03 11:56:51 +0300 | [diff] [blame] | 488 | /* Register 0 is not readable */ |
| 489 | if (!reg) |
| 490 | return false; |
| 491 | return true; |
| 492 | } |
| 493 | |
| 494 | static struct regmap_config twl6040_regmap_config = { |
| 495 | .reg_bits = 8, |
| 496 | .val_bits = 8, |
| 497 | .max_register = TWL6040_REG_STATUS, /* 0x2e */ |
| 498 | |
| 499 | .readable_reg = twl6040_readable_reg, |
| 500 | }; |
| 501 | |
Peter Ujfalusi | ab7edb1 | 2012-10-11 13:55:32 +0200 | [diff] [blame^] | 502 | static const struct regmap_irq twl6040_irqs[] = { |
| 503 | { .reg_offset = 0, .mask = TWL6040_THINT, }, |
| 504 | { .reg_offset = 0, .mask = TWL6040_PLUGINT | TWL6040_UNPLUGINT, }, |
| 505 | { .reg_offset = 0, .mask = TWL6040_HOOKINT, }, |
| 506 | { .reg_offset = 0, .mask = TWL6040_HFINT, }, |
| 507 | { .reg_offset = 0, .mask = TWL6040_VIBINT, }, |
| 508 | { .reg_offset = 0, .mask = TWL6040_READYINT, }, |
| 509 | }; |
| 510 | |
| 511 | static struct regmap_irq_chip twl6040_irq_chip = { |
| 512 | .name = "twl6040", |
| 513 | .irqs = twl6040_irqs, |
| 514 | .num_irqs = ARRAY_SIZE(twl6040_irqs), |
| 515 | |
| 516 | .num_regs = 1, |
| 517 | .status_base = TWL6040_REG_INTID, |
| 518 | .mask_base = TWL6040_REG_INTMR, |
| 519 | }; |
| 520 | |
Peter Ujfalusi | 8eaeb93 | 2012-04-03 11:56:51 +0300 | [diff] [blame] | 521 | static int __devinit twl6040_probe(struct i2c_client *client, |
| 522 | const struct i2c_device_id *id) |
| 523 | { |
| 524 | struct twl6040_platform_data *pdata = client->dev.platform_data; |
Peter Ujfalusi | 37e13ce | 2012-05-16 14:11:58 +0300 | [diff] [blame] | 525 | struct device_node *node = client->dev.of_node; |
Misael Lopez Cruz | f19b282 | 2011-04-27 02:14:07 -0500 | [diff] [blame] | 526 | struct twl6040 *twl6040; |
| 527 | struct mfd_cell *cell = NULL; |
Peter Ujfalusi | 1f01d60 | 2012-05-16 14:11:57 +0300 | [diff] [blame] | 528 | int irq, ret, children = 0; |
Misael Lopez Cruz | f19b282 | 2011-04-27 02:14:07 -0500 | [diff] [blame] | 529 | |
Peter Ujfalusi | 37e13ce | 2012-05-16 14:11:58 +0300 | [diff] [blame] | 530 | if (!pdata && !node) { |
Peter Ujfalusi | 8eaeb93 | 2012-04-03 11:56:51 +0300 | [diff] [blame] | 531 | dev_err(&client->dev, "Platform data is missing\n"); |
Misael Lopez Cruz | f19b282 | 2011-04-27 02:14:07 -0500 | [diff] [blame] | 532 | return -EINVAL; |
| 533 | } |
| 534 | |
Peter Ujfalusi | d20e1d2 | 2011-07-04 20:15:19 +0300 | [diff] [blame] | 535 | /* In order to operate correctly we need valid interrupt config */ |
Peter Ujfalusi | 6712419 | 2012-05-16 14:11:56 +0300 | [diff] [blame] | 536 | if (!client->irq) { |
Peter Ujfalusi | 8eaeb93 | 2012-04-03 11:56:51 +0300 | [diff] [blame] | 537 | dev_err(&client->dev, "Invalid IRQ configuration\n"); |
Peter Ujfalusi | d20e1d2 | 2011-07-04 20:15:19 +0300 | [diff] [blame] | 538 | return -EINVAL; |
| 539 | } |
| 540 | |
Peter Ujfalusi | 8eaeb93 | 2012-04-03 11:56:51 +0300 | [diff] [blame] | 541 | twl6040 = devm_kzalloc(&client->dev, sizeof(struct twl6040), |
| 542 | GFP_KERNEL); |
| 543 | if (!twl6040) { |
| 544 | ret = -ENOMEM; |
| 545 | goto err; |
| 546 | } |
Misael Lopez Cruz | f19b282 | 2011-04-27 02:14:07 -0500 | [diff] [blame] | 547 | |
Axel Lin | bbf6adc | 2012-04-25 10:09:46 +0800 | [diff] [blame] | 548 | twl6040->regmap = devm_regmap_init_i2c(client, &twl6040_regmap_config); |
Peter Ujfalusi | 8eaeb93 | 2012-04-03 11:56:51 +0300 | [diff] [blame] | 549 | if (IS_ERR(twl6040->regmap)) { |
| 550 | ret = PTR_ERR(twl6040->regmap); |
| 551 | goto err; |
| 552 | } |
Misael Lopez Cruz | f19b282 | 2011-04-27 02:14:07 -0500 | [diff] [blame] | 553 | |
Peter Ujfalusi | 8eaeb93 | 2012-04-03 11:56:51 +0300 | [diff] [blame] | 554 | i2c_set_clientdata(client, twl6040); |
| 555 | |
Peter Ujfalusi | 5af7df6 | 2012-05-02 16:54:42 +0300 | [diff] [blame] | 556 | twl6040->supplies[0].supply = "vio"; |
| 557 | twl6040->supplies[1].supply = "v2v1"; |
| 558 | ret = regulator_bulk_get(&client->dev, TWL6040_NUM_SUPPLIES, |
| 559 | twl6040->supplies); |
| 560 | if (ret != 0) { |
| 561 | dev_err(&client->dev, "Failed to get supplies: %d\n", ret); |
| 562 | goto regulator_get_err; |
| 563 | } |
| 564 | |
| 565 | ret = regulator_bulk_enable(TWL6040_NUM_SUPPLIES, twl6040->supplies); |
| 566 | if (ret != 0) { |
| 567 | dev_err(&client->dev, "Failed to enable supplies: %d\n", ret); |
| 568 | goto power_err; |
| 569 | } |
| 570 | |
Peter Ujfalusi | 8eaeb93 | 2012-04-03 11:56:51 +0300 | [diff] [blame] | 571 | twl6040->dev = &client->dev; |
| 572 | twl6040->irq = client->irq; |
Misael Lopez Cruz | f19b282 | 2011-04-27 02:14:07 -0500 | [diff] [blame] | 573 | |
| 574 | mutex_init(&twl6040->mutex); |
Misael Lopez Cruz | f19b282 | 2011-04-27 02:14:07 -0500 | [diff] [blame] | 575 | init_completion(&twl6040->ready); |
| 576 | |
| 577 | twl6040->rev = twl6040_reg_read(twl6040, TWL6040_REG_ASICREV); |
| 578 | |
Peter Ujfalusi | 77f63e0 | 2011-09-15 15:39:26 +0300 | [diff] [blame] | 579 | /* ERRATA: Automatic power-up is not possible in ES1.0 */ |
Peter Ujfalusi | 37e13ce | 2012-05-16 14:11:58 +0300 | [diff] [blame] | 580 | if (twl6040_get_revid(twl6040) > TWL6040_REV_ES1_0) { |
| 581 | if (pdata) |
| 582 | twl6040->audpwron = pdata->audpwron_gpio; |
| 583 | else |
| 584 | twl6040->audpwron = of_get_named_gpio(node, |
| 585 | "ti,audpwron-gpio", 0); |
| 586 | } else |
Peter Ujfalusi | 77f63e0 | 2011-09-15 15:39:26 +0300 | [diff] [blame] | 587 | twl6040->audpwron = -EINVAL; |
| 588 | |
Misael Lopez Cruz | f19b282 | 2011-04-27 02:14:07 -0500 | [diff] [blame] | 589 | if (gpio_is_valid(twl6040->audpwron)) { |
Axel Lin | b04edb9 | 2011-12-01 09:55:07 +0800 | [diff] [blame] | 590 | ret = gpio_request_one(twl6040->audpwron, GPIOF_OUT_INIT_LOW, |
| 591 | "audpwron"); |
Misael Lopez Cruz | f19b282 | 2011-04-27 02:14:07 -0500 | [diff] [blame] | 592 | if (ret) |
Peter Ujfalusi | 5af7df6 | 2012-05-02 16:54:42 +0300 | [diff] [blame] | 593 | goto gpio_err; |
Misael Lopez Cruz | f19b282 | 2011-04-27 02:14:07 -0500 | [diff] [blame] | 594 | } |
| 595 | |
Peter Ujfalusi | ab7edb1 | 2012-10-11 13:55:32 +0200 | [diff] [blame^] | 596 | ret = regmap_add_irq_chip(twl6040->regmap, twl6040->irq, |
| 597 | IRQF_ONESHOT, 0, &twl6040_irq_chip, |
| 598 | &twl6040->irq_data); |
| 599 | if (ret < 0) |
Peter Ujfalusi | 5af7df6 | 2012-05-02 16:54:42 +0300 | [diff] [blame] | 600 | goto irq_init_err; |
Misael Lopez Cruz | f19b282 | 2011-04-27 02:14:07 -0500 | [diff] [blame] | 601 | |
Peter Ujfalusi | ab7edb1 | 2012-10-11 13:55:32 +0200 | [diff] [blame^] | 602 | twl6040->irq_ready = regmap_irq_get_virq(twl6040->irq_data, |
| 603 | TWL6040_IRQ_READY); |
| 604 | twl6040->irq_th = regmap_irq_get_virq(twl6040->irq_data, |
| 605 | TWL6040_IRQ_TH); |
| 606 | |
| 607 | ret = request_threaded_irq(twl6040->irq_ready, NULL, |
| 608 | twl6040_readyint_handler, IRQF_ONESHOT, |
Peter Ujfalusi | 1b7c472 | 2011-07-04 20:16:23 +0300 | [diff] [blame] | 609 | "twl6040_irq_ready", twl6040); |
Peter Ujfalusi | d20e1d2 | 2011-07-04 20:15:19 +0300 | [diff] [blame] | 610 | if (ret) { |
Peter Ujfalusi | 1ac9626 | 2012-10-11 13:55:31 +0200 | [diff] [blame] | 611 | dev_err(twl6040->dev, "READY IRQ request failed: %d\n", ret); |
| 612 | goto readyirq_err; |
| 613 | } |
| 614 | |
Peter Ujfalusi | ab7edb1 | 2012-10-11 13:55:32 +0200 | [diff] [blame^] | 615 | ret = request_threaded_irq(twl6040->irq_th, NULL, |
| 616 | twl6040_thint_handler, IRQF_ONESHOT, |
Peter Ujfalusi | 1ac9626 | 2012-10-11 13:55:31 +0200 | [diff] [blame] | 617 | "twl6040_irq_th", twl6040); |
| 618 | if (ret) { |
| 619 | dev_err(twl6040->dev, "Thermal IRQ request failed: %d\n", ret); |
| 620 | goto thirq_err; |
Misael Lopez Cruz | f19b282 | 2011-04-27 02:14:07 -0500 | [diff] [blame] | 621 | } |
| 622 | |
| 623 | /* dual-access registers controlled by I2C only */ |
| 624 | twl6040_set_bits(twl6040, TWL6040_REG_ACCCTL, TWL6040_I2CSEL); |
| 625 | |
Peter Ujfalusi | 1f01d60 | 2012-05-16 14:11:57 +0300 | [diff] [blame] | 626 | /* |
| 627 | * The main functionality of twl6040 to provide audio on OMAP4+ systems. |
| 628 | * We can add the ASoC codec child whenever this driver has been loaded. |
| 629 | * The ASoC codec can work without pdata, pass the platform_data only if |
| 630 | * it has been provided. |
| 631 | */ |
Peter Ujfalusi | ab7edb1 | 2012-10-11 13:55:32 +0200 | [diff] [blame^] | 632 | irq = regmap_irq_get_virq(twl6040->irq_data, TWL6040_IRQ_PLUG); |
Peter Ujfalusi | 1f01d60 | 2012-05-16 14:11:57 +0300 | [diff] [blame] | 633 | cell = &twl6040->cells[children]; |
| 634 | cell->name = "twl6040-codec"; |
| 635 | twl6040_codec_rsrc[0].start = irq; |
| 636 | twl6040_codec_rsrc[0].end = irq; |
| 637 | cell->resources = twl6040_codec_rsrc; |
| 638 | cell->num_resources = ARRAY_SIZE(twl6040_codec_rsrc); |
Peter Ujfalusi | 37e13ce | 2012-05-16 14:11:58 +0300 | [diff] [blame] | 639 | if (pdata && pdata->codec) { |
Peter Ujfalusi | 6c44863 | 2011-06-01 13:05:10 +0300 | [diff] [blame] | 640 | cell->platform_data = pdata->codec; |
| 641 | cell->pdata_size = sizeof(*pdata->codec); |
Misael Lopez Cruz | f19b282 | 2011-04-27 02:14:07 -0500 | [diff] [blame] | 642 | } |
Peter Ujfalusi | 1f01d60 | 2012-05-16 14:11:57 +0300 | [diff] [blame] | 643 | children++; |
Misael Lopez Cruz | f19b282 | 2011-04-27 02:14:07 -0500 | [diff] [blame] | 644 | |
Samuel Ortiz | ca2cad6 | 2012-05-23 16:23:21 +0200 | [diff] [blame] | 645 | if (twl6040_has_vibra(pdata, node)) { |
Peter Ujfalusi | ab7edb1 | 2012-10-11 13:55:32 +0200 | [diff] [blame^] | 646 | irq = regmap_irq_get_virq(twl6040->irq_data, TWL6040_IRQ_VIB); |
Peter Ujfalusi | 0f962ae | 2011-07-05 11:40:33 +0300 | [diff] [blame] | 647 | |
Misael Lopez Cruz | f19b282 | 2011-04-27 02:14:07 -0500 | [diff] [blame] | 648 | cell = &twl6040->cells[children]; |
| 649 | cell->name = "twl6040-vibra"; |
Peter Ujfalusi | 0f962ae | 2011-07-05 11:40:33 +0300 | [diff] [blame] | 650 | twl6040_vibra_rsrc[0].start = irq; |
| 651 | twl6040_vibra_rsrc[0].end = irq; |
| 652 | cell->resources = twl6040_vibra_rsrc; |
| 653 | cell->num_resources = ARRAY_SIZE(twl6040_vibra_rsrc); |
| 654 | |
Peter Ujfalusi | 37e13ce | 2012-05-16 14:11:58 +0300 | [diff] [blame] | 655 | if (pdata && pdata->vibra) { |
| 656 | cell->platform_data = pdata->vibra; |
| 657 | cell->pdata_size = sizeof(*pdata->vibra); |
| 658 | } |
Misael Lopez Cruz | f19b282 | 2011-04-27 02:14:07 -0500 | [diff] [blame] | 659 | children++; |
| 660 | } |
| 661 | |
Peter Ujfalusi | 5cbe786 | 2012-08-16 15:13:14 +0300 | [diff] [blame] | 662 | /* |
| 663 | * Enable the GPO driver in the following cases: |
| 664 | * DT booted kernel or legacy boot with valid gpo platform_data |
| 665 | */ |
| 666 | if (!pdata || (pdata && pdata->gpo)) { |
| 667 | cell = &twl6040->cells[children]; |
| 668 | cell->name = "twl6040-gpo"; |
| 669 | |
| 670 | if (pdata) { |
| 671 | cell->platform_data = pdata->gpo; |
| 672 | cell->pdata_size = sizeof(*pdata->gpo); |
| 673 | } |
| 674 | children++; |
| 675 | } |
| 676 | |
Peter Ujfalusi | 1f01d60 | 2012-05-16 14:11:57 +0300 | [diff] [blame] | 677 | ret = mfd_add_devices(&client->dev, -1, twl6040->cells, children, |
Mark Brown | 55692af | 2012-09-11 15:16:36 +0800 | [diff] [blame] | 678 | NULL, 0, NULL); |
Peter Ujfalusi | 1f01d60 | 2012-05-16 14:11:57 +0300 | [diff] [blame] | 679 | if (ret) |
Misael Lopez Cruz | f19b282 | 2011-04-27 02:14:07 -0500 | [diff] [blame] | 680 | goto mfd_err; |
Misael Lopez Cruz | f19b282 | 2011-04-27 02:14:07 -0500 | [diff] [blame] | 681 | |
| 682 | return 0; |
| 683 | |
| 684 | mfd_err: |
Peter Ujfalusi | ab7edb1 | 2012-10-11 13:55:32 +0200 | [diff] [blame^] | 685 | free_irq(twl6040->irq_th, twl6040); |
Peter Ujfalusi | 1ac9626 | 2012-10-11 13:55:31 +0200 | [diff] [blame] | 686 | thirq_err: |
Peter Ujfalusi | ab7edb1 | 2012-10-11 13:55:32 +0200 | [diff] [blame^] | 687 | free_irq(twl6040->irq_ready, twl6040); |
Peter Ujfalusi | 1ac9626 | 2012-10-11 13:55:31 +0200 | [diff] [blame] | 688 | readyirq_err: |
Peter Ujfalusi | ab7edb1 | 2012-10-11 13:55:32 +0200 | [diff] [blame^] | 689 | regmap_del_irq_chip(twl6040->irq, twl6040->irq_data); |
Peter Ujfalusi | 5af7df6 | 2012-05-02 16:54:42 +0300 | [diff] [blame] | 690 | irq_init_err: |
Misael Lopez Cruz | f19b282 | 2011-04-27 02:14:07 -0500 | [diff] [blame] | 691 | if (gpio_is_valid(twl6040->audpwron)) |
| 692 | gpio_free(twl6040->audpwron); |
Peter Ujfalusi | 5af7df6 | 2012-05-02 16:54:42 +0300 | [diff] [blame] | 693 | gpio_err: |
| 694 | regulator_bulk_disable(TWL6040_NUM_SUPPLIES, twl6040->supplies); |
| 695 | power_err: |
| 696 | regulator_bulk_free(TWL6040_NUM_SUPPLIES, twl6040->supplies); |
| 697 | regulator_get_err: |
Peter Ujfalusi | 8eaeb93 | 2012-04-03 11:56:51 +0300 | [diff] [blame] | 698 | i2c_set_clientdata(client, NULL); |
Peter Ujfalusi | 8eaeb93 | 2012-04-03 11:56:51 +0300 | [diff] [blame] | 699 | err: |
Misael Lopez Cruz | f19b282 | 2011-04-27 02:14:07 -0500 | [diff] [blame] | 700 | return ret; |
| 701 | } |
| 702 | |
Peter Ujfalusi | 8eaeb93 | 2012-04-03 11:56:51 +0300 | [diff] [blame] | 703 | static int __devexit twl6040_remove(struct i2c_client *client) |
Misael Lopez Cruz | f19b282 | 2011-04-27 02:14:07 -0500 | [diff] [blame] | 704 | { |
Peter Ujfalusi | 8eaeb93 | 2012-04-03 11:56:51 +0300 | [diff] [blame] | 705 | struct twl6040 *twl6040 = i2c_get_clientdata(client); |
Misael Lopez Cruz | f19b282 | 2011-04-27 02:14:07 -0500 | [diff] [blame] | 706 | |
| 707 | if (twl6040->power_count) |
| 708 | twl6040_power(twl6040, 0); |
| 709 | |
| 710 | if (gpio_is_valid(twl6040->audpwron)) |
| 711 | gpio_free(twl6040->audpwron); |
| 712 | |
Peter Ujfalusi | ab7edb1 | 2012-10-11 13:55:32 +0200 | [diff] [blame^] | 713 | free_irq(twl6040->irq_ready, twl6040); |
| 714 | free_irq(twl6040->irq_th, twl6040); |
| 715 | regmap_del_irq_chip(twl6040->irq, twl6040->irq_data); |
Misael Lopez Cruz | f19b282 | 2011-04-27 02:14:07 -0500 | [diff] [blame] | 716 | |
Peter Ujfalusi | 8eaeb93 | 2012-04-03 11:56:51 +0300 | [diff] [blame] | 717 | mfd_remove_devices(&client->dev); |
| 718 | i2c_set_clientdata(client, NULL); |
Misael Lopez Cruz | f19b282 | 2011-04-27 02:14:07 -0500 | [diff] [blame] | 719 | |
Peter Ujfalusi | 5af7df6 | 2012-05-02 16:54:42 +0300 | [diff] [blame] | 720 | regulator_bulk_disable(TWL6040_NUM_SUPPLIES, twl6040->supplies); |
| 721 | regulator_bulk_free(TWL6040_NUM_SUPPLIES, twl6040->supplies); |
| 722 | |
Misael Lopez Cruz | f19b282 | 2011-04-27 02:14:07 -0500 | [diff] [blame] | 723 | return 0; |
| 724 | } |
| 725 | |
Peter Ujfalusi | 8eaeb93 | 2012-04-03 11:56:51 +0300 | [diff] [blame] | 726 | static const struct i2c_device_id twl6040_i2c_id[] = { |
| 727 | { "twl6040", 0, }, |
Peter Ujfalusi | 1fc74ae | 2012-07-16 11:49:44 +0200 | [diff] [blame] | 728 | { "twl6041", 0, }, |
Peter Ujfalusi | 8eaeb93 | 2012-04-03 11:56:51 +0300 | [diff] [blame] | 729 | { }, |
| 730 | }; |
| 731 | MODULE_DEVICE_TABLE(i2c, twl6040_i2c_id); |
| 732 | |
| 733 | static struct i2c_driver twl6040_driver = { |
| 734 | .driver = { |
| 735 | .name = "twl6040", |
| 736 | .owner = THIS_MODULE, |
| 737 | }, |
Misael Lopez Cruz | f19b282 | 2011-04-27 02:14:07 -0500 | [diff] [blame] | 738 | .probe = twl6040_probe, |
| 739 | .remove = __devexit_p(twl6040_remove), |
Peter Ujfalusi | 8eaeb93 | 2012-04-03 11:56:51 +0300 | [diff] [blame] | 740 | .id_table = twl6040_i2c_id, |
Misael Lopez Cruz | f19b282 | 2011-04-27 02:14:07 -0500 | [diff] [blame] | 741 | }; |
| 742 | |
Peter Ujfalusi | 8eaeb93 | 2012-04-03 11:56:51 +0300 | [diff] [blame] | 743 | module_i2c_driver(twl6040_driver); |
Misael Lopez Cruz | f19b282 | 2011-04-27 02:14:07 -0500 | [diff] [blame] | 744 | |
| 745 | MODULE_DESCRIPTION("TWL6040 MFD"); |
| 746 | MODULE_AUTHOR("Misael Lopez Cruz <misael.lopez@ti.com>"); |
| 747 | MODULE_AUTHOR("Jorge Eduardo Candelaria <jorge.candelaria@ti.com>"); |
| 748 | MODULE_LICENSE("GPL"); |
| 749 | MODULE_ALIAS("platform:twl6040"); |