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