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