Graeme Gregory | 2945fbc | 2012-05-15 15:48:56 +0900 | [diff] [blame] | 1 | /* |
| 2 | * TI Palmas MFD Driver |
| 3 | * |
| 4 | * Copyright 2011-2012 Texas Instruments Inc. |
| 5 | * |
| 6 | * Author: Graeme Gregory <gg@slimlogic.co.uk> |
| 7 | * |
| 8 | * This program is free software; you can redistribute it and/or modify it |
| 9 | * under the terms of the GNU General Public License as published by the |
| 10 | * Free Software Foundation; either version 2 of the License, or (at your |
| 11 | * option) any later version. |
| 12 | * |
| 13 | */ |
| 14 | |
| 15 | #include <linux/module.h> |
| 16 | #include <linux/moduleparam.h> |
| 17 | #include <linux/init.h> |
| 18 | #include <linux/slab.h> |
| 19 | #include <linux/i2c.h> |
| 20 | #include <linux/interrupt.h> |
| 21 | #include <linux/irq.h> |
| 22 | #include <linux/regmap.h> |
| 23 | #include <linux/err.h> |
| 24 | #include <linux/mfd/core.h> |
| 25 | #include <linux/mfd/palmas.h> |
J Keerthy | 1ffb0be | 2013-06-19 11:27:48 +0530 | [diff] [blame] | 26 | #include <linux/of_device.h> |
Graeme Gregory | 2945fbc | 2012-05-15 15:48:56 +0900 | [diff] [blame] | 27 | |
Graeme Gregory | 2945fbc | 2012-05-15 15:48:56 +0900 | [diff] [blame] | 28 | static const struct regmap_config palmas_regmap_config[PALMAS_NUM_CLIENTS] = { |
| 29 | { |
| 30 | .reg_bits = 8, |
| 31 | .val_bits = 8, |
| 32 | .max_register = PALMAS_BASE_TO_REG(PALMAS_PU_PD_OD_BASE, |
| 33 | PALMAS_PRIMARY_SECONDARY_PAD3), |
| 34 | }, |
| 35 | { |
| 36 | .reg_bits = 8, |
| 37 | .val_bits = 8, |
| 38 | .max_register = PALMAS_BASE_TO_REG(PALMAS_GPADC_BASE, |
| 39 | PALMAS_GPADC_SMPS_VSEL_MONITORING), |
| 40 | }, |
| 41 | { |
| 42 | .reg_bits = 8, |
| 43 | .val_bits = 8, |
| 44 | .max_register = PALMAS_BASE_TO_REG(PALMAS_TRIM_GPADC_BASE, |
| 45 | PALMAS_GPADC_TRIM16), |
| 46 | }, |
| 47 | }; |
| 48 | |
| 49 | static const struct regmap_irq palmas_irqs[] = { |
| 50 | /* INT1 IRQs */ |
| 51 | [PALMAS_CHARG_DET_N_VBUS_OVV_IRQ] = { |
| 52 | .mask = PALMAS_INT1_STATUS_CHARG_DET_N_VBUS_OVV, |
| 53 | }, |
| 54 | [PALMAS_PWRON_IRQ] = { |
| 55 | .mask = PALMAS_INT1_STATUS_PWRON, |
| 56 | }, |
| 57 | [PALMAS_LONG_PRESS_KEY_IRQ] = { |
| 58 | .mask = PALMAS_INT1_STATUS_LONG_PRESS_KEY, |
| 59 | }, |
| 60 | [PALMAS_RPWRON_IRQ] = { |
| 61 | .mask = PALMAS_INT1_STATUS_RPWRON, |
| 62 | }, |
| 63 | [PALMAS_PWRDOWN_IRQ] = { |
| 64 | .mask = PALMAS_INT1_STATUS_PWRDOWN, |
| 65 | }, |
| 66 | [PALMAS_HOTDIE_IRQ] = { |
| 67 | .mask = PALMAS_INT1_STATUS_HOTDIE, |
| 68 | }, |
| 69 | [PALMAS_VSYS_MON_IRQ] = { |
| 70 | .mask = PALMAS_INT1_STATUS_VSYS_MON, |
| 71 | }, |
| 72 | [PALMAS_VBAT_MON_IRQ] = { |
| 73 | .mask = PALMAS_INT1_STATUS_VBAT_MON, |
| 74 | }, |
| 75 | /* INT2 IRQs*/ |
| 76 | [PALMAS_RTC_ALARM_IRQ] = { |
| 77 | .mask = PALMAS_INT2_STATUS_RTC_ALARM, |
| 78 | .reg_offset = 1, |
| 79 | }, |
| 80 | [PALMAS_RTC_TIMER_IRQ] = { |
| 81 | .mask = PALMAS_INT2_STATUS_RTC_TIMER, |
| 82 | .reg_offset = 1, |
| 83 | }, |
| 84 | [PALMAS_WDT_IRQ] = { |
| 85 | .mask = PALMAS_INT2_STATUS_WDT, |
| 86 | .reg_offset = 1, |
| 87 | }, |
| 88 | [PALMAS_BATREMOVAL_IRQ] = { |
| 89 | .mask = PALMAS_INT2_STATUS_BATREMOVAL, |
| 90 | .reg_offset = 1, |
| 91 | }, |
| 92 | [PALMAS_RESET_IN_IRQ] = { |
| 93 | .mask = PALMAS_INT2_STATUS_RESET_IN, |
| 94 | .reg_offset = 1, |
| 95 | }, |
| 96 | [PALMAS_FBI_BB_IRQ] = { |
| 97 | .mask = PALMAS_INT2_STATUS_FBI_BB, |
| 98 | .reg_offset = 1, |
| 99 | }, |
| 100 | [PALMAS_SHORT_IRQ] = { |
| 101 | .mask = PALMAS_INT2_STATUS_SHORT, |
| 102 | .reg_offset = 1, |
| 103 | }, |
| 104 | [PALMAS_VAC_ACOK_IRQ] = { |
| 105 | .mask = PALMAS_INT2_STATUS_VAC_ACOK, |
| 106 | .reg_offset = 1, |
| 107 | }, |
| 108 | /* INT3 IRQs */ |
| 109 | [PALMAS_GPADC_AUTO_0_IRQ] = { |
| 110 | .mask = PALMAS_INT3_STATUS_GPADC_AUTO_0, |
| 111 | .reg_offset = 2, |
| 112 | }, |
| 113 | [PALMAS_GPADC_AUTO_1_IRQ] = { |
| 114 | .mask = PALMAS_INT3_STATUS_GPADC_AUTO_1, |
| 115 | .reg_offset = 2, |
| 116 | }, |
| 117 | [PALMAS_GPADC_EOC_SW_IRQ] = { |
| 118 | .mask = PALMAS_INT3_STATUS_GPADC_EOC_SW, |
| 119 | .reg_offset = 2, |
| 120 | }, |
| 121 | [PALMAS_GPADC_EOC_RT_IRQ] = { |
| 122 | .mask = PALMAS_INT3_STATUS_GPADC_EOC_RT, |
| 123 | .reg_offset = 2, |
| 124 | }, |
| 125 | [PALMAS_ID_OTG_IRQ] = { |
| 126 | .mask = PALMAS_INT3_STATUS_ID_OTG, |
| 127 | .reg_offset = 2, |
| 128 | }, |
| 129 | [PALMAS_ID_IRQ] = { |
| 130 | .mask = PALMAS_INT3_STATUS_ID, |
| 131 | .reg_offset = 2, |
| 132 | }, |
| 133 | [PALMAS_VBUS_OTG_IRQ] = { |
| 134 | .mask = PALMAS_INT3_STATUS_VBUS_OTG, |
| 135 | .reg_offset = 2, |
| 136 | }, |
| 137 | [PALMAS_VBUS_IRQ] = { |
| 138 | .mask = PALMAS_INT3_STATUS_VBUS, |
| 139 | .reg_offset = 2, |
| 140 | }, |
| 141 | /* INT4 IRQs */ |
| 142 | [PALMAS_GPIO_0_IRQ] = { |
| 143 | .mask = PALMAS_INT4_STATUS_GPIO_0, |
| 144 | .reg_offset = 3, |
| 145 | }, |
| 146 | [PALMAS_GPIO_1_IRQ] = { |
| 147 | .mask = PALMAS_INT4_STATUS_GPIO_1, |
| 148 | .reg_offset = 3, |
| 149 | }, |
| 150 | [PALMAS_GPIO_2_IRQ] = { |
| 151 | .mask = PALMAS_INT4_STATUS_GPIO_2, |
| 152 | .reg_offset = 3, |
| 153 | }, |
| 154 | [PALMAS_GPIO_3_IRQ] = { |
| 155 | .mask = PALMAS_INT4_STATUS_GPIO_3, |
| 156 | .reg_offset = 3, |
| 157 | }, |
| 158 | [PALMAS_GPIO_4_IRQ] = { |
| 159 | .mask = PALMAS_INT4_STATUS_GPIO_4, |
| 160 | .reg_offset = 3, |
| 161 | }, |
| 162 | [PALMAS_GPIO_5_IRQ] = { |
| 163 | .mask = PALMAS_INT4_STATUS_GPIO_5, |
| 164 | .reg_offset = 3, |
| 165 | }, |
| 166 | [PALMAS_GPIO_6_IRQ] = { |
| 167 | .mask = PALMAS_INT4_STATUS_GPIO_6, |
| 168 | .reg_offset = 3, |
| 169 | }, |
| 170 | [PALMAS_GPIO_7_IRQ] = { |
| 171 | .mask = PALMAS_INT4_STATUS_GPIO_7, |
| 172 | .reg_offset = 3, |
| 173 | }, |
| 174 | }; |
| 175 | |
| 176 | static struct regmap_irq_chip palmas_irq_chip = { |
| 177 | .name = "palmas", |
| 178 | .irqs = palmas_irqs, |
| 179 | .num_irqs = ARRAY_SIZE(palmas_irqs), |
| 180 | |
| 181 | .num_regs = 4, |
| 182 | .irq_reg_stride = 5, |
| 183 | .status_base = PALMAS_BASE_TO_REG(PALMAS_INTERRUPT_BASE, |
| 184 | PALMAS_INT1_STATUS), |
| 185 | .mask_base = PALMAS_BASE_TO_REG(PALMAS_INTERRUPT_BASE, |
| 186 | PALMAS_INT1_MASK), |
| 187 | }; |
| 188 | |
Laxman Dewangan | df545d1 | 2013-03-01 20:13:46 +0530 | [diff] [blame] | 189 | static int palmas_set_pdata_irq_flag(struct i2c_client *i2c, |
Graeme Gregory | 9c14ac3 | 2012-08-28 13:47:38 +0200 | [diff] [blame] | 190 | struct palmas_platform_data *pdata) |
| 191 | { |
Laxman Dewangan | df545d1 | 2013-03-01 20:13:46 +0530 | [diff] [blame] | 192 | struct irq_data *irq_data = irq_get_irq_data(i2c->irq); |
| 193 | if (!irq_data) { |
| 194 | dev_err(&i2c->dev, "Invalid IRQ: %d\n", i2c->irq); |
| 195 | return -EINVAL; |
| 196 | } |
| 197 | |
| 198 | pdata->irq_flags = irqd_get_trigger_type(irq_data); |
| 199 | dev_info(&i2c->dev, "Irq flag is 0x%08x\n", pdata->irq_flags); |
| 200 | return 0; |
| 201 | } |
| 202 | |
| 203 | static void palmas_dt_to_pdata(struct i2c_client *i2c, |
| 204 | struct palmas_platform_data *pdata) |
| 205 | { |
| 206 | struct device_node *node = i2c->dev.of_node; |
Graeme Gregory | 9c14ac3 | 2012-08-28 13:47:38 +0200 | [diff] [blame] | 207 | int ret; |
| 208 | u32 prop; |
| 209 | |
J Keerthy | 2154a2b | 2013-02-18 10:42:44 +0530 | [diff] [blame] | 210 | ret = of_property_read_u32(node, "ti,mux-pad1", &prop); |
Graeme Gregory | 9c14ac3 | 2012-08-28 13:47:38 +0200 | [diff] [blame] | 211 | if (!ret) { |
| 212 | pdata->mux_from_pdata = 1; |
| 213 | pdata->pad1 = prop; |
| 214 | } |
| 215 | |
J Keerthy | 2154a2b | 2013-02-18 10:42:44 +0530 | [diff] [blame] | 216 | ret = of_property_read_u32(node, "ti,mux-pad2", &prop); |
Graeme Gregory | 9c14ac3 | 2012-08-28 13:47:38 +0200 | [diff] [blame] | 217 | if (!ret) { |
| 218 | pdata->mux_from_pdata = 1; |
| 219 | pdata->pad2 = prop; |
| 220 | } |
| 221 | |
| 222 | /* The default for this register is all masked */ |
J Keerthy | 2154a2b | 2013-02-18 10:42:44 +0530 | [diff] [blame] | 223 | ret = of_property_read_u32(node, "ti,power-ctrl", &prop); |
Graeme Gregory | 9c14ac3 | 2012-08-28 13:47:38 +0200 | [diff] [blame] | 224 | if (!ret) |
| 225 | pdata->power_ctrl = prop; |
| 226 | else |
| 227 | pdata->power_ctrl = PALMAS_POWER_CTRL_NSLEEP_MASK | |
| 228 | PALMAS_POWER_CTRL_ENABLE1_MASK | |
| 229 | PALMAS_POWER_CTRL_ENABLE2_MASK; |
Laxman Dewangan | df545d1 | 2013-03-01 20:13:46 +0530 | [diff] [blame] | 230 | if (i2c->irq) |
| 231 | palmas_set_pdata_irq_flag(i2c, pdata); |
Bill Huang | b81eec0 | 2013-08-08 04:45:05 -0700 | [diff] [blame^] | 232 | |
| 233 | pdata->pm_off = of_property_read_bool(node, |
| 234 | "ti,system-power-controller"); |
| 235 | } |
| 236 | |
| 237 | static struct palmas *palmas_dev; |
| 238 | static void palmas_power_off(void) |
| 239 | { |
| 240 | unsigned int addr; |
| 241 | int ret, slave; |
| 242 | |
| 243 | if (!palmas_dev) |
| 244 | return; |
| 245 | |
| 246 | slave = PALMAS_BASE_TO_SLAVE(PALMAS_PMU_CONTROL_BASE); |
| 247 | addr = PALMAS_BASE_TO_REG(PALMAS_PMU_CONTROL_BASE, PALMAS_DEV_CTRL); |
| 248 | |
| 249 | ret = regmap_update_bits( |
| 250 | palmas_dev->regmap[slave], |
| 251 | addr, |
| 252 | PALMAS_DEV_CTRL_DEV_ON, |
| 253 | 0); |
| 254 | |
| 255 | if (ret) |
| 256 | pr_err("%s: Unable to write to DEV_CTRL_DEV_ON: %d\n", |
| 257 | __func__, ret); |
Graeme Gregory | 9c14ac3 | 2012-08-28 13:47:38 +0200 | [diff] [blame] | 258 | } |
| 259 | |
J Keerthy | 1ffb0be | 2013-06-19 11:27:48 +0530 | [diff] [blame] | 260 | static unsigned int palmas_features = PALMAS_PMIC_FEATURE_SMPS10_BOOST; |
J Keerthy | 4124e6e | 2013-06-20 16:35:16 +0530 | [diff] [blame] | 261 | static unsigned int tps659038_features; |
J Keerthy | 1ffb0be | 2013-06-19 11:27:48 +0530 | [diff] [blame] | 262 | |
| 263 | static const struct of_device_id of_palmas_match_tbl[] = { |
| 264 | { |
| 265 | .compatible = "ti,palmas", |
| 266 | .data = &palmas_features, |
| 267 | }, |
J Keerthy | 4124e6e | 2013-06-20 16:35:16 +0530 | [diff] [blame] | 268 | { |
| 269 | .compatible = "ti,tps659038", |
| 270 | .data = &tps659038_features, |
| 271 | }, |
J Keerthy | 1ffb0be | 2013-06-19 11:27:48 +0530 | [diff] [blame] | 272 | { }, |
| 273 | }; |
| 274 | |
Bill Pemberton | f791be4 | 2012-11-19 13:23:04 -0500 | [diff] [blame] | 275 | static int palmas_i2c_probe(struct i2c_client *i2c, |
Graeme Gregory | 2945fbc | 2012-05-15 15:48:56 +0900 | [diff] [blame] | 276 | const struct i2c_device_id *id) |
| 277 | { |
| 278 | struct palmas *palmas; |
| 279 | struct palmas_platform_data *pdata; |
Graeme Gregory | 9c14ac3 | 2012-08-28 13:47:38 +0200 | [diff] [blame] | 280 | struct device_node *node = i2c->dev.of_node; |
Graeme Gregory | 2945fbc | 2012-05-15 15:48:56 +0900 | [diff] [blame] | 281 | int ret = 0, i; |
J Keerthy | 1ffb0be | 2013-06-19 11:27:48 +0530 | [diff] [blame] | 282 | unsigned int reg, addr, *features; |
Graeme Gregory | 2945fbc | 2012-05-15 15:48:56 +0900 | [diff] [blame] | 283 | int slave; |
J Keerthy | 1ffb0be | 2013-06-19 11:27:48 +0530 | [diff] [blame] | 284 | const struct of_device_id *match; |
Graeme Gregory | 2945fbc | 2012-05-15 15:48:56 +0900 | [diff] [blame] | 285 | |
| 286 | pdata = dev_get_platdata(&i2c->dev); |
Graeme Gregory | 9c14ac3 | 2012-08-28 13:47:38 +0200 | [diff] [blame] | 287 | |
| 288 | if (node && !pdata) { |
| 289 | pdata = devm_kzalloc(&i2c->dev, sizeof(*pdata), GFP_KERNEL); |
| 290 | |
| 291 | if (!pdata) |
| 292 | return -ENOMEM; |
| 293 | |
Laxman Dewangan | df545d1 | 2013-03-01 20:13:46 +0530 | [diff] [blame] | 294 | palmas_dt_to_pdata(i2c, pdata); |
Graeme Gregory | 9c14ac3 | 2012-08-28 13:47:38 +0200 | [diff] [blame] | 295 | } |
| 296 | |
Graeme Gregory | 2945fbc | 2012-05-15 15:48:56 +0900 | [diff] [blame] | 297 | if (!pdata) |
| 298 | return -EINVAL; |
| 299 | |
| 300 | palmas = devm_kzalloc(&i2c->dev, sizeof(struct palmas), GFP_KERNEL); |
| 301 | if (palmas == NULL) |
| 302 | return -ENOMEM; |
| 303 | |
| 304 | i2c_set_clientdata(i2c, palmas); |
| 305 | palmas->dev = &i2c->dev; |
Graeme Gregory | 2945fbc | 2012-05-15 15:48:56 +0900 | [diff] [blame] | 306 | palmas->irq = i2c->irq; |
| 307 | |
J Keerthy | 1ffb0be | 2013-06-19 11:27:48 +0530 | [diff] [blame] | 308 | match = of_match_device(of_match_ptr(of_palmas_match_tbl), &i2c->dev); |
| 309 | |
| 310 | if (!match) |
| 311 | return -ENODATA; |
| 312 | |
| 313 | features = (unsigned int *)match->data; |
| 314 | palmas->features = *features; |
| 315 | |
Graeme Gregory | 2945fbc | 2012-05-15 15:48:56 +0900 | [diff] [blame] | 316 | for (i = 0; i < PALMAS_NUM_CLIENTS; i++) { |
| 317 | if (i == 0) |
| 318 | palmas->i2c_clients[i] = i2c; |
| 319 | else { |
| 320 | palmas->i2c_clients[i] = |
| 321 | i2c_new_dummy(i2c->adapter, |
| 322 | i2c->addr + i); |
| 323 | if (!palmas->i2c_clients[i]) { |
| 324 | dev_err(palmas->dev, |
| 325 | "can't attach client %d\n", i); |
| 326 | ret = -ENOMEM; |
| 327 | goto err; |
| 328 | } |
Laxman Dewangan | c4fbec3 | 2013-03-19 14:28:20 +0530 | [diff] [blame] | 329 | palmas->i2c_clients[i]->dev.of_node = of_node_get(node); |
Graeme Gregory | 2945fbc | 2012-05-15 15:48:56 +0900 | [diff] [blame] | 330 | } |
| 331 | palmas->regmap[i] = devm_regmap_init_i2c(palmas->i2c_clients[i], |
| 332 | &palmas_regmap_config[i]); |
| 333 | if (IS_ERR(palmas->regmap[i])) { |
| 334 | ret = PTR_ERR(palmas->regmap[i]); |
| 335 | dev_err(palmas->dev, |
| 336 | "Failed to allocate regmap %d, err: %d\n", |
| 337 | i, ret); |
| 338 | goto err; |
| 339 | } |
| 340 | } |
| 341 | |
J Keerthy | ad522f4 | 2013-06-19 11:27:47 +0530 | [diff] [blame] | 342 | if (!palmas->irq) { |
| 343 | dev_warn(palmas->dev, "IRQ missing: skipping irq request\n"); |
| 344 | goto no_irq; |
| 345 | } |
| 346 | |
Laxman Dewangan | df545d1 | 2013-03-01 20:13:46 +0530 | [diff] [blame] | 347 | /* Change interrupt line output polarity */ |
| 348 | if (pdata->irq_flags & IRQ_TYPE_LEVEL_HIGH) |
| 349 | reg = PALMAS_POLARITY_CTRL_INT_POLARITY; |
| 350 | else |
| 351 | reg = 0; |
| 352 | ret = palmas_update_bits(palmas, PALMAS_PU_PD_OD_BASE, |
| 353 | PALMAS_POLARITY_CTRL, PALMAS_POLARITY_CTRL_INT_POLARITY, |
| 354 | reg); |
| 355 | if (ret < 0) { |
| 356 | dev_err(palmas->dev, "POLARITY_CTRL updat failed: %d\n", ret); |
| 357 | goto err; |
| 358 | } |
| 359 | |
Graeme Gregory | b330f85 | 2012-06-22 13:36:19 +0100 | [diff] [blame] | 360 | /* Change IRQ into clear on read mode for efficiency */ |
| 361 | slave = PALMAS_BASE_TO_SLAVE(PALMAS_INTERRUPT_BASE); |
| 362 | addr = PALMAS_BASE_TO_REG(PALMAS_INTERRUPT_BASE, PALMAS_INT_CTRL); |
| 363 | reg = PALMAS_INT_CTRL_INT_CLEAR; |
| 364 | |
| 365 | regmap_write(palmas->regmap[slave], addr, reg); |
| 366 | |
| 367 | ret = regmap_add_irq_chip(palmas->regmap[slave], palmas->irq, |
Laxman Dewangan | df545d1 | 2013-03-01 20:13:46 +0530 | [diff] [blame] | 368 | IRQF_ONESHOT | pdata->irq_flags, 0, &palmas_irq_chip, |
Graeme Gregory | 2945fbc | 2012-05-15 15:48:56 +0900 | [diff] [blame] | 369 | &palmas->irq_data); |
| 370 | if (ret < 0) |
| 371 | goto err; |
| 372 | |
J Keerthy | ad522f4 | 2013-06-19 11:27:47 +0530 | [diff] [blame] | 373 | no_irq: |
Graeme Gregory | 2945fbc | 2012-05-15 15:48:56 +0900 | [diff] [blame] | 374 | slave = PALMAS_BASE_TO_SLAVE(PALMAS_PU_PD_OD_BASE); |
| 375 | addr = PALMAS_BASE_TO_REG(PALMAS_PU_PD_OD_BASE, |
| 376 | PALMAS_PRIMARY_SECONDARY_PAD1); |
| 377 | |
| 378 | if (pdata->mux_from_pdata) { |
| 379 | reg = pdata->pad1; |
| 380 | ret = regmap_write(palmas->regmap[slave], addr, reg); |
| 381 | if (ret) |
Graeme Gregory | 3f78dec | 2012-08-28 13:47:35 +0200 | [diff] [blame] | 382 | goto err_irq; |
Graeme Gregory | 2945fbc | 2012-05-15 15:48:56 +0900 | [diff] [blame] | 383 | } else { |
| 384 | ret = regmap_read(palmas->regmap[slave], addr, ®); |
| 385 | if (ret) |
Graeme Gregory | 3f78dec | 2012-08-28 13:47:35 +0200 | [diff] [blame] | 386 | goto err_irq; |
Graeme Gregory | 2945fbc | 2012-05-15 15:48:56 +0900 | [diff] [blame] | 387 | } |
| 388 | |
| 389 | if (!(reg & PALMAS_PRIMARY_SECONDARY_PAD1_GPIO_0)) |
| 390 | palmas->gpio_muxed |= PALMAS_GPIO_0_MUXED; |
| 391 | if (!(reg & PALMAS_PRIMARY_SECONDARY_PAD1_GPIO_1_MASK)) |
| 392 | palmas->gpio_muxed |= PALMAS_GPIO_1_MUXED; |
| 393 | else if ((reg & PALMAS_PRIMARY_SECONDARY_PAD1_GPIO_1_MASK) == |
| 394 | (2 << PALMAS_PRIMARY_SECONDARY_PAD1_GPIO_1_SHIFT)) |
| 395 | palmas->led_muxed |= PALMAS_LED1_MUXED; |
| 396 | else if ((reg & PALMAS_PRIMARY_SECONDARY_PAD1_GPIO_1_MASK) == |
| 397 | (3 << PALMAS_PRIMARY_SECONDARY_PAD1_GPIO_1_SHIFT)) |
| 398 | palmas->pwm_muxed |= PALMAS_PWM1_MUXED; |
| 399 | if (!(reg & PALMAS_PRIMARY_SECONDARY_PAD1_GPIO_2_MASK)) |
| 400 | palmas->gpio_muxed |= PALMAS_GPIO_2_MUXED; |
| 401 | else if ((reg & PALMAS_PRIMARY_SECONDARY_PAD1_GPIO_2_MASK) == |
| 402 | (2 << PALMAS_PRIMARY_SECONDARY_PAD1_GPIO_2_SHIFT)) |
| 403 | palmas->led_muxed |= PALMAS_LED2_MUXED; |
| 404 | else if ((reg & PALMAS_PRIMARY_SECONDARY_PAD1_GPIO_2_MASK) == |
| 405 | (3 << PALMAS_PRIMARY_SECONDARY_PAD1_GPIO_2_SHIFT)) |
| 406 | palmas->pwm_muxed |= PALMAS_PWM2_MUXED; |
| 407 | if (!(reg & PALMAS_PRIMARY_SECONDARY_PAD1_GPIO_3)) |
| 408 | palmas->gpio_muxed |= PALMAS_GPIO_3_MUXED; |
| 409 | |
| 410 | addr = PALMAS_BASE_TO_REG(PALMAS_PU_PD_OD_BASE, |
| 411 | PALMAS_PRIMARY_SECONDARY_PAD2); |
| 412 | |
| 413 | if (pdata->mux_from_pdata) { |
| 414 | reg = pdata->pad2; |
| 415 | ret = regmap_write(palmas->regmap[slave], addr, reg); |
| 416 | if (ret) |
Graeme Gregory | 3f78dec | 2012-08-28 13:47:35 +0200 | [diff] [blame] | 417 | goto err_irq; |
Graeme Gregory | 2945fbc | 2012-05-15 15:48:56 +0900 | [diff] [blame] | 418 | } else { |
| 419 | ret = regmap_read(palmas->regmap[slave], addr, ®); |
| 420 | if (ret) |
Graeme Gregory | 3f78dec | 2012-08-28 13:47:35 +0200 | [diff] [blame] | 421 | goto err_irq; |
Graeme Gregory | 2945fbc | 2012-05-15 15:48:56 +0900 | [diff] [blame] | 422 | } |
| 423 | |
| 424 | if (!(reg & PALMAS_PRIMARY_SECONDARY_PAD2_GPIO_4)) |
| 425 | palmas->gpio_muxed |= PALMAS_GPIO_4_MUXED; |
| 426 | if (!(reg & PALMAS_PRIMARY_SECONDARY_PAD2_GPIO_5_MASK)) |
| 427 | palmas->gpio_muxed |= PALMAS_GPIO_5_MUXED; |
| 428 | if (!(reg & PALMAS_PRIMARY_SECONDARY_PAD2_GPIO_6)) |
| 429 | palmas->gpio_muxed |= PALMAS_GPIO_6_MUXED; |
| 430 | if (!(reg & PALMAS_PRIMARY_SECONDARY_PAD2_GPIO_7_MASK)) |
| 431 | palmas->gpio_muxed |= PALMAS_GPIO_7_MUXED; |
| 432 | |
| 433 | dev_info(palmas->dev, "Muxing GPIO %x, PWM %x, LED %x\n", |
| 434 | palmas->gpio_muxed, palmas->pwm_muxed, |
| 435 | palmas->led_muxed); |
| 436 | |
| 437 | reg = pdata->power_ctrl; |
| 438 | |
| 439 | slave = PALMAS_BASE_TO_SLAVE(PALMAS_PMU_CONTROL_BASE); |
| 440 | addr = PALMAS_BASE_TO_REG(PALMAS_PMU_CONTROL_BASE, PALMAS_POWER_CTRL); |
| 441 | |
| 442 | ret = regmap_write(palmas->regmap[slave], addr, reg); |
| 443 | if (ret) |
Graeme Gregory | 3f78dec | 2012-08-28 13:47:35 +0200 | [diff] [blame] | 444 | goto err_irq; |
Graeme Gregory | 2945fbc | 2012-05-15 15:48:56 +0900 | [diff] [blame] | 445 | |
Graeme Gregory | 9c14ac3 | 2012-08-28 13:47:38 +0200 | [diff] [blame] | 446 | /* |
| 447 | * If we are probing with DT do this the DT way and return here |
| 448 | * otherwise continue and add devices using mfd helpers. |
| 449 | */ |
| 450 | if (node) { |
| 451 | ret = of_platform_populate(node, NULL, NULL, &i2c->dev); |
Bill Huang | b81eec0 | 2013-08-08 04:45:05 -0700 | [diff] [blame^] | 452 | if (ret < 0) { |
Graeme Gregory | 9c14ac3 | 2012-08-28 13:47:38 +0200 | [diff] [blame] | 453 | goto err_irq; |
Bill Huang | b81eec0 | 2013-08-08 04:45:05 -0700 | [diff] [blame^] | 454 | } else if (pdata->pm_off && !pm_power_off) { |
| 455 | palmas_dev = palmas; |
| 456 | pm_power_off = palmas_power_off; |
Graeme Gregory | 9c14ac3 | 2012-08-28 13:47:38 +0200 | [diff] [blame] | 457 | return ret; |
Bill Huang | b81eec0 | 2013-08-08 04:45:05 -0700 | [diff] [blame^] | 458 | } |
Graeme Gregory | 9c14ac3 | 2012-08-28 13:47:38 +0200 | [diff] [blame] | 459 | } |
| 460 | |
Graeme Gregory | 2945fbc | 2012-05-15 15:48:56 +0900 | [diff] [blame] | 461 | return ret; |
| 462 | |
Graeme Gregory | 3f78dec | 2012-08-28 13:47:35 +0200 | [diff] [blame] | 463 | err_irq: |
| 464 | regmap_del_irq_chip(palmas->irq, palmas->irq_data); |
| 465 | err: |
Graeme Gregory | 2945fbc | 2012-05-15 15:48:56 +0900 | [diff] [blame] | 466 | return ret; |
| 467 | } |
| 468 | |
| 469 | static int palmas_i2c_remove(struct i2c_client *i2c) |
| 470 | { |
| 471 | struct palmas *palmas = i2c_get_clientdata(i2c); |
| 472 | |
| 473 | mfd_remove_devices(palmas->dev); |
| 474 | regmap_del_irq_chip(palmas->irq, palmas->irq_data); |
| 475 | |
| 476 | return 0; |
| 477 | } |
| 478 | |
| 479 | static const struct i2c_device_id palmas_i2c_id[] = { |
| 480 | { "palmas", }, |
| 481 | { "twl6035", }, |
| 482 | { "twl6037", }, |
| 483 | { "tps65913", }, |
Axel Lin | 00ba81c | 2012-05-21 23:33:22 +0800 | [diff] [blame] | 484 | { /* end */ } |
Graeme Gregory | 2945fbc | 2012-05-15 15:48:56 +0900 | [diff] [blame] | 485 | }; |
| 486 | MODULE_DEVICE_TABLE(i2c, palmas_i2c_id); |
| 487 | |
Graeme Gregory | 2945fbc | 2012-05-15 15:48:56 +0900 | [diff] [blame] | 488 | static struct i2c_driver palmas_i2c_driver = { |
| 489 | .driver = { |
| 490 | .name = "palmas", |
| 491 | .of_match_table = of_palmas_match_tbl, |
| 492 | .owner = THIS_MODULE, |
| 493 | }, |
| 494 | .probe = palmas_i2c_probe, |
| 495 | .remove = palmas_i2c_remove, |
| 496 | .id_table = palmas_i2c_id, |
| 497 | }; |
| 498 | |
| 499 | static int __init palmas_i2c_init(void) |
| 500 | { |
| 501 | return i2c_add_driver(&palmas_i2c_driver); |
| 502 | } |
| 503 | /* init early so consumer devices can complete system boot */ |
| 504 | subsys_initcall(palmas_i2c_init); |
| 505 | |
| 506 | static void __exit palmas_i2c_exit(void) |
| 507 | { |
| 508 | i2c_del_driver(&palmas_i2c_driver); |
| 509 | } |
| 510 | module_exit(palmas_i2c_exit); |
| 511 | |
| 512 | MODULE_AUTHOR("Graeme Gregory <gg@slimlogic.co.uk>"); |
| 513 | MODULE_DESCRIPTION("Palmas chip family multi-function driver"); |
| 514 | MODULE_LICENSE("GPL"); |