Duy Truong | 790f06d | 2013-02-13 16:38:12 -0800 | [diff] [blame] | 1 | /* Copyright (c) 2010-2012, The Linux Foundation. All rights reserved. |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2 | * |
| 3 | * This program is free software; you can redistribute it and/or modify |
| 4 | * it under the terms of the GNU General Public License version 2 and |
| 5 | * only version 2 as published by the Free Software Foundation. |
| 6 | * |
| 7 | * This program is distributed in the hope that it will be useful, |
| 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 10 | * GNU General Public License for more details. |
| 11 | */ |
| 12 | |
| 13 | #include <linux/interrupt.h> |
Anirudh Ghayal | 9f77e96 | 2011-12-06 12:38:21 +0530 | [diff] [blame] | 14 | #include <linux/platform_device.h> |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 15 | #include <linux/slab.h> |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 16 | #include <linux/mfd/core.h> |
Anirudh Ghayal | c8051a8 | 2011-11-17 09:28:24 +0530 | [diff] [blame] | 17 | #include <linux/msm_ssbi.h> |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 18 | #include <linux/mfd/pmic8901.h> |
Anirudh Ghayal | 9f77e96 | 2011-12-06 12:38:21 +0530 | [diff] [blame] | 19 | #include <linux/mfd/pm8xxx/core.h> |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 20 | #include <linux/module.h> |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 21 | |
| 22 | /* PMIC8901 Revision */ |
Anirudh Ghayal | 9f77e96 | 2011-12-06 12:38:21 +0530 | [diff] [blame] | 23 | #define PM8901_REG_REV 0x002 |
| 24 | #define PM8901_VERSION_MASK 0xF0 |
| 25 | #define PM8901_REVISION_MASK 0x0F |
| 26 | #define PM8901_VERSION_VALUE 0xF0 |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 27 | |
Anirudh Ghayal | 9f77e96 | 2011-12-06 12:38:21 +0530 | [diff] [blame] | 28 | #define REG_IRQ_BASE 0xD5 |
| 29 | #define REG_MPP_BASE 0x27 |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 30 | |
Anirudh Ghayal | 9f77e96 | 2011-12-06 12:38:21 +0530 | [diff] [blame] | 31 | #define REG_TEMP_ALRM_CTRL 0x23 |
| 32 | #define REG_TEMP_ALRM_PWM 0x24 |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 33 | |
Anirudh Ghayal | 9f77e96 | 2011-12-06 12:38:21 +0530 | [diff] [blame] | 34 | #define SINGLE_IRQ_RESOURCE(_name, _irq) \ |
| 35 | { \ |
| 36 | .name = _name, \ |
| 37 | .start = _irq, \ |
| 38 | .end = _irq, \ |
| 39 | .flags = IORESOURCE_IRQ, \ |
| 40 | } |
| 41 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 42 | struct pm8901_chip { |
| 43 | struct pm8901_platform_data pdata; |
Anirudh Ghayal | c8051a8 | 2011-11-17 09:28:24 +0530 | [diff] [blame] | 44 | struct device *dev; |
Anirudh Ghayal | 9f77e96 | 2011-12-06 12:38:21 +0530 | [diff] [blame] | 45 | struct pm_irq_chip *irq_chip; |
| 46 | struct mfd_cell *mfd_regulators; |
| 47 | u8 revision; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 48 | }; |
| 49 | |
Anirudh Ghayal | 9f77e96 | 2011-12-06 12:38:21 +0530 | [diff] [blame] | 50 | static int pm8901_readb(const struct device *dev, u16 addr, u8 *val) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 51 | { |
Anirudh Ghayal | 9f77e96 | 2011-12-06 12:38:21 +0530 | [diff] [blame] | 52 | const struct pm8xxx_drvdata *pm8901_drvdata = dev_get_drvdata(dev); |
| 53 | const struct pm8901_chip *pmic = pm8901_drvdata->pm_chip_data; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 54 | |
Anirudh Ghayal | 9f77e96 | 2011-12-06 12:38:21 +0530 | [diff] [blame] | 55 | return msm_ssbi_read(pmic->dev->parent, addr, val, 1); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 56 | } |
| 57 | |
Anirudh Ghayal | 9f77e96 | 2011-12-06 12:38:21 +0530 | [diff] [blame] | 58 | static int pm8901_writeb(const struct device *dev, u16 addr, u8 val) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 59 | { |
Anirudh Ghayal | 9f77e96 | 2011-12-06 12:38:21 +0530 | [diff] [blame] | 60 | const struct pm8xxx_drvdata *pm8901_drvdata = dev_get_drvdata(dev); |
| 61 | const struct pm8901_chip *pmic = pm8901_drvdata->pm_chip_data; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 62 | |
Anirudh Ghayal | 9f77e96 | 2011-12-06 12:38:21 +0530 | [diff] [blame] | 63 | return msm_ssbi_write(pmic->dev->parent, addr, &val, 1); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 64 | } |
| 65 | |
Anirudh Ghayal | 9f77e96 | 2011-12-06 12:38:21 +0530 | [diff] [blame] | 66 | static int pm8901_read_buf(const struct device *dev, u16 addr, u8 *buf, |
| 67 | int cnt) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 68 | { |
Anirudh Ghayal | 9f77e96 | 2011-12-06 12:38:21 +0530 | [diff] [blame] | 69 | const struct pm8xxx_drvdata *pm8901_drvdata = dev_get_drvdata(dev); |
| 70 | const struct pm8901_chip *pmic = pm8901_drvdata->pm_chip_data; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 71 | |
Anirudh Ghayal | 9f77e96 | 2011-12-06 12:38:21 +0530 | [diff] [blame] | 72 | return msm_ssbi_read(pmic->dev->parent, addr, buf, cnt); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 73 | } |
| 74 | |
Anirudh Ghayal | 9f77e96 | 2011-12-06 12:38:21 +0530 | [diff] [blame] | 75 | static int pm8901_write_buf(const struct device *dev, u16 addr, u8 *buf, |
| 76 | int cnt) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 77 | { |
Anirudh Ghayal | 9f77e96 | 2011-12-06 12:38:21 +0530 | [diff] [blame] | 78 | const struct pm8xxx_drvdata *pm8901_drvdata = dev_get_drvdata(dev); |
| 79 | const struct pm8901_chip *pmic = pm8901_drvdata->pm_chip_data; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 80 | |
Anirudh Ghayal | 9f77e96 | 2011-12-06 12:38:21 +0530 | [diff] [blame] | 81 | return msm_ssbi_write(pmic->dev->parent, addr, buf, cnt); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 82 | } |
| 83 | |
Anirudh Ghayal | 9f77e96 | 2011-12-06 12:38:21 +0530 | [diff] [blame] | 84 | static int pm8901_read_irq_stat(const struct device *dev, int irq) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 85 | { |
Anirudh Ghayal | 9f77e96 | 2011-12-06 12:38:21 +0530 | [diff] [blame] | 86 | const struct pm8xxx_drvdata *pm8901_drvdata = dev_get_drvdata(dev); |
| 87 | const struct pm8901_chip *pmic = pm8901_drvdata->pm_chip_data; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 88 | |
Anirudh Ghayal | 9f77e96 | 2011-12-06 12:38:21 +0530 | [diff] [blame] | 89 | return pm8xxx_get_irq_stat(pmic->irq_chip, irq); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 90 | |
| 91 | return 0; |
| 92 | } |
| 93 | |
Anirudh Ghayal | 9f77e96 | 2011-12-06 12:38:21 +0530 | [diff] [blame] | 94 | static enum pm8xxx_version pm8901_get_version(const struct device *dev) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 95 | { |
Anirudh Ghayal | 9f77e96 | 2011-12-06 12:38:21 +0530 | [diff] [blame] | 96 | const struct pm8xxx_drvdata *pm8901_drvdata = dev_get_drvdata(dev); |
| 97 | const struct pm8901_chip *pmic = pm8901_drvdata->pm_chip_data; |
| 98 | enum pm8xxx_version version = -ENODEV; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 99 | |
Anirudh Ghayal | 9f77e96 | 2011-12-06 12:38:21 +0530 | [diff] [blame] | 100 | if ((pmic->revision & PM8901_VERSION_MASK) == PM8901_VERSION_VALUE) |
| 101 | version = PM8XXX_VERSION_8901; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 102 | |
Anirudh Ghayal | 9f77e96 | 2011-12-06 12:38:21 +0530 | [diff] [blame] | 103 | return version; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 104 | } |
| 105 | |
Anirudh Ghayal | 9f77e96 | 2011-12-06 12:38:21 +0530 | [diff] [blame] | 106 | static int pm8901_get_revision(const struct device *dev) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 107 | { |
Anirudh Ghayal | 9f77e96 | 2011-12-06 12:38:21 +0530 | [diff] [blame] | 108 | const struct pm8xxx_drvdata *pm8901_drvdata = dev_get_drvdata(dev); |
| 109 | const struct pm8901_chip *pmic = pm8901_drvdata->pm_chip_data; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 110 | |
Anirudh Ghayal | 9f77e96 | 2011-12-06 12:38:21 +0530 | [diff] [blame] | 111 | return pmic->revision & PM8901_REVISION_MASK; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 112 | } |
| 113 | |
Anirudh Ghayal | 9f77e96 | 2011-12-06 12:38:21 +0530 | [diff] [blame] | 114 | static struct pm8xxx_drvdata pm8901_drvdata = { |
| 115 | .pmic_readb = pm8901_readb, |
| 116 | .pmic_writeb = pm8901_writeb, |
| 117 | .pmic_read_buf = pm8901_read_buf, |
| 118 | .pmic_write_buf = pm8901_write_buf, |
| 119 | .pmic_read_irq_stat = pm8901_read_irq_stat, |
| 120 | .pmic_get_version = pm8901_get_version, |
| 121 | .pmic_get_revision = pm8901_get_revision, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 122 | }; |
| 123 | |
Anirudh Ghayal | 934b271 | 2011-12-13 12:49:51 +0530 | [diff] [blame] | 124 | static struct mfd_cell misc_cell = { |
| 125 | .name = PM8XXX_MISC_DEV_NAME, |
| 126 | .id = 1, |
| 127 | }; |
| 128 | |
Anirudh Ghayal | 9f77e96 | 2011-12-06 12:38:21 +0530 | [diff] [blame] | 129 | static struct mfd_cell debugfs_cell = { |
| 130 | .name = "pm8xxx-debug", |
| 131 | .id = 1, |
| 132 | .platform_data = "pm8901-dbg", |
| 133 | .pdata_size = sizeof("pm8901-dbg"), |
| 134 | }; |
| 135 | |
| 136 | static const struct resource thermal_alarm_cell_resources[] = { |
| 137 | SINGLE_IRQ_RESOURCE("pm8901_tempstat_irq", PM8901_TEMPSTAT_IRQ), |
| 138 | SINGLE_IRQ_RESOURCE("pm8901_overtemp_irq", PM8901_OVERTEMP_IRQ), |
| 139 | }; |
| 140 | |
| 141 | static struct pm8xxx_tm_core_data thermal_alarm_cdata = { |
| 142 | .adc_type = PM8XXX_TM_ADC_NONE, |
| 143 | .reg_addr_temp_alarm_ctrl = REG_TEMP_ALRM_CTRL, |
| 144 | .reg_addr_temp_alarm_pwm = REG_TEMP_ALRM_PWM, |
| 145 | .tm_name = "pm8901_tz", |
| 146 | .irq_name_temp_stat = "pm8901_tempstat_irq", |
| 147 | .irq_name_over_temp = "pm8901_overtemp_irq", |
| 148 | }; |
| 149 | |
| 150 | static struct mfd_cell thermal_alarm_cell = { |
| 151 | .name = PM8XXX_TM_DEV_NAME, |
| 152 | .id = 1, |
| 153 | .resources = thermal_alarm_cell_resources, |
| 154 | .num_resources = ARRAY_SIZE(thermal_alarm_cell_resources), |
| 155 | .platform_data = &thermal_alarm_cdata, |
| 156 | .pdata_size = sizeof(struct pm8xxx_tm_core_data), |
| 157 | }; |
| 158 | |
| 159 | static const struct resource mpp_cell_resources[] = { |
| 160 | { |
| 161 | .start = PM8901_IRQ_BLOCK_BIT(PM8901_MPP_BLOCK_START, 0), |
| 162 | .end = PM8901_IRQ_BLOCK_BIT(PM8901_MPP_BLOCK_START, 0) |
| 163 | + PM8901_MPPS - 1, |
| 164 | .flags = IORESOURCE_IRQ, |
| 165 | }, |
| 166 | }; |
| 167 | |
| 168 | static struct mfd_cell mpp_cell = { |
| 169 | .name = PM8XXX_MPP_DEV_NAME, |
| 170 | .id = 1, |
| 171 | .resources = mpp_cell_resources, |
| 172 | .num_resources = ARRAY_SIZE(mpp_cell_resources), |
| 173 | }; |
| 174 | |
| 175 | static int __devinit |
| 176 | pm8901_add_subdevices(const struct pm8901_platform_data *pdata, |
| 177 | struct pm8901_chip *pmic) |
| 178 | { |
| 179 | int rc = 0, irq_base = 0, i; |
| 180 | struct pm_irq_chip *irq_chip; |
| 181 | static struct mfd_cell *mfd_regulators; |
| 182 | |
| 183 | if (pdata->irq_pdata) { |
| 184 | pdata->irq_pdata->irq_cdata.nirqs = PM8901_NR_IRQS; |
| 185 | pdata->irq_pdata->irq_cdata.base_addr = REG_IRQ_BASE; |
| 186 | irq_base = pdata->irq_pdata->irq_base; |
| 187 | irq_chip = pm8xxx_irq_init(pmic->dev, pdata->irq_pdata); |
| 188 | |
| 189 | if (IS_ERR(irq_chip)) { |
| 190 | pr_err("Failed to init interrupts ret=%ld\n", |
| 191 | PTR_ERR(irq_chip)); |
| 192 | return PTR_ERR(irq_chip); |
| 193 | } |
| 194 | pmic->irq_chip = irq_chip; |
| 195 | } |
| 196 | |
| 197 | if (pdata->mpp_pdata) { |
| 198 | pdata->mpp_pdata->core_data.nmpps = PM8901_MPPS; |
| 199 | pdata->mpp_pdata->core_data.base_addr = REG_MPP_BASE; |
| 200 | mpp_cell.platform_data = pdata->mpp_pdata; |
| 201 | mpp_cell.pdata_size = sizeof(struct pm8xxx_mpp_platform_data); |
| 202 | rc = mfd_add_devices(pmic->dev, 0, &mpp_cell, 1, NULL, |
| 203 | irq_base); |
| 204 | if (rc) { |
| 205 | pr_err("Failed to add mpp subdevice ret=%d\n", rc); |
| 206 | goto bail; |
| 207 | } |
| 208 | } |
| 209 | |
| 210 | if (pdata->num_regulators > 0 && pdata->regulator_pdatas) { |
| 211 | mfd_regulators = kzalloc(sizeof(struct mfd_cell) |
| 212 | * (pdata->num_regulators), GFP_KERNEL); |
| 213 | if (!mfd_regulators) { |
| 214 | pr_err("Cannot allocate %d bytes for pm8901 regulator " |
| 215 | "mfd cells\n", sizeof(struct mfd_cell) |
| 216 | * (pdata->num_regulators)); |
| 217 | rc = -ENOMEM; |
| 218 | goto bail; |
| 219 | } |
| 220 | for (i = 0; i < pdata->num_regulators; i++) { |
| 221 | mfd_regulators[i].name = "pm8901-regulator"; |
| 222 | mfd_regulators[i].id = pdata->regulator_pdatas[i].id; |
| 223 | mfd_regulators[i].platform_data = |
| 224 | &(pdata->regulator_pdatas[i]); |
| 225 | mfd_regulators[i].pdata_size = |
| 226 | sizeof(struct pm8901_vreg_pdata); |
| 227 | } |
| 228 | rc = mfd_add_devices(pmic->dev, 0, mfd_regulators, |
| 229 | pdata->num_regulators, NULL, irq_base); |
| 230 | if (rc) { |
| 231 | pr_err("Failed to add regulator subdevices ret=%d\n", |
| 232 | rc); |
| 233 | kfree(mfd_regulators); |
| 234 | goto bail; |
| 235 | } |
| 236 | pmic->mfd_regulators = mfd_regulators; |
| 237 | } |
| 238 | |
| 239 | rc = mfd_add_devices(pmic->dev, 0, &thermal_alarm_cell, 1, NULL, |
| 240 | irq_base); |
| 241 | if (rc) { |
| 242 | pr_err("Failed to add thermal alarm subdevice ret=%d\n", |
| 243 | rc); |
| 244 | goto bail; |
| 245 | } |
| 246 | |
| 247 | rc = mfd_add_devices(pmic->dev, 0, &debugfs_cell, 1, NULL, irq_base); |
| 248 | if (rc) { |
| 249 | pr_err("Failed to add debugfs subdevice ret=%d\n", rc); |
| 250 | goto bail; |
| 251 | } |
| 252 | |
Anirudh Ghayal | 934b271 | 2011-12-13 12:49:51 +0530 | [diff] [blame] | 253 | if (pdata->misc_pdata) { |
| 254 | misc_cell.platform_data = pdata->misc_pdata; |
| 255 | misc_cell.pdata_size = sizeof(struct pm8xxx_misc_platform_data); |
| 256 | rc = mfd_add_devices(pmic->dev, 0, &misc_cell, 1, NULL, |
| 257 | irq_base); |
| 258 | if (rc) { |
| 259 | pr_err("Failed to add misc subdevice ret=%d\n", rc); |
| 260 | goto bail; |
| 261 | } |
| 262 | } |
| 263 | |
Anirudh Ghayal | 9f77e96 | 2011-12-06 12:38:21 +0530 | [diff] [blame] | 264 | return rc; |
| 265 | |
| 266 | bail: |
| 267 | if (pmic->irq_chip) { |
| 268 | pm8xxx_irq_exit(pmic->irq_chip); |
| 269 | pmic->irq_chip = NULL; |
| 270 | } |
| 271 | return rc; |
| 272 | } |
| 273 | |
David Collins | e41d1db | 2012-04-05 10:08:10 -0700 | [diff] [blame] | 274 | static const char * const pm8901_rev_names[] = { |
| 275 | [PM8XXX_REVISION_8901_TEST] = "test", |
| 276 | [PM8XXX_REVISION_8901_1p0] = "1.0", |
| 277 | [PM8XXX_REVISION_8901_1p1] = "1.1", |
| 278 | [PM8XXX_REVISION_8901_2p0] = "2.0", |
| 279 | [PM8XXX_REVISION_8901_2p1] = "2.1", |
| 280 | [PM8XXX_REVISION_8901_2p2] = "2.2", |
| 281 | [PM8XXX_REVISION_8901_2p3] = "2.3", |
| 282 | }; |
| 283 | |
Stephen Boyd | 9a8f4eb | 2012-02-21 23:51:00 -0800 | [diff] [blame] | 284 | static int __devinit pm8901_probe(struct platform_device *pdev) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 285 | { |
Anirudh Ghayal | 9f77e96 | 2011-12-06 12:38:21 +0530 | [diff] [blame] | 286 | int rc; |
Anirudh Ghayal | c8051a8 | 2011-11-17 09:28:24 +0530 | [diff] [blame] | 287 | struct pm8901_platform_data *pdata = pdev->dev.platform_data; |
David Collins | e41d1db | 2012-04-05 10:08:10 -0700 | [diff] [blame] | 288 | const char *revision_name = "unknown"; |
Anirudh Ghayal | 9f77e96 | 2011-12-06 12:38:21 +0530 | [diff] [blame] | 289 | struct pm8901_chip *pmic; |
David Collins | e41d1db | 2012-04-05 10:08:10 -0700 | [diff] [blame] | 290 | int revision; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 291 | |
Anirudh Ghayal | 9f77e96 | 2011-12-06 12:38:21 +0530 | [diff] [blame] | 292 | if (pdata == NULL) { |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 293 | pr_err("%s: No platform_data or IRQ.\n", __func__); |
| 294 | return -ENODEV; |
| 295 | } |
| 296 | |
Anirudh Ghayal | 9f77e96 | 2011-12-06 12:38:21 +0530 | [diff] [blame] | 297 | pmic = kzalloc(sizeof *pmic, GFP_KERNEL); |
| 298 | if (pmic == NULL) { |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 299 | pr_err("%s: kzalloc() failed.\n", __func__); |
| 300 | return -ENOMEM; |
| 301 | } |
| 302 | |
Anirudh Ghayal | 9f77e96 | 2011-12-06 12:38:21 +0530 | [diff] [blame] | 303 | pmic->dev = &pdev->dev; |
| 304 | |
| 305 | pm8901_drvdata.pm_chip_data = pmic; |
| 306 | platform_set_drvdata(pdev, &pm8901_drvdata); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 307 | |
| 308 | /* Read PMIC chip revision */ |
Anirudh Ghayal | 9f77e96 | 2011-12-06 12:38:21 +0530 | [diff] [blame] | 309 | rc = pm8901_readb(pmic->dev, PM8901_REG_REV, &pmic->revision); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 310 | if (rc) |
Anirudh Ghayal | 9f77e96 | 2011-12-06 12:38:21 +0530 | [diff] [blame] | 311 | pr_err("%s: Failed reading version register rc=%d.\n", |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 312 | __func__, rc); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 313 | |
David Collins | e41d1db | 2012-04-05 10:08:10 -0700 | [diff] [blame] | 314 | pr_info("%s: PMIC revision reg: %02X\n", __func__, pmic->revision); |
| 315 | revision = pm8xxx_get_revision(pmic->dev); |
| 316 | if (revision >= 0 && revision < ARRAY_SIZE(pm8901_rev_names)) |
| 317 | revision_name = pm8901_rev_names[revision]; |
| 318 | pr_info("%s: PMIC version: PM8901 rev %s\n", __func__, revision_name); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 319 | |
Anirudh Ghayal | 9f77e96 | 2011-12-06 12:38:21 +0530 | [diff] [blame] | 320 | (void) memcpy((void *)&pmic->pdata, (const void *)pdata, |
| 321 | sizeof(pmic->pdata)); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 322 | |
Anirudh Ghayal | 9f77e96 | 2011-12-06 12:38:21 +0530 | [diff] [blame] | 323 | rc = pm8901_add_subdevices(pdata, pmic); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 324 | if (rc) { |
Anirudh Ghayal | 9f77e96 | 2011-12-06 12:38:21 +0530 | [diff] [blame] | 325 | pr_err("Cannot add subdevices rc=%d\n", rc); |
| 326 | goto err; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 327 | } |
| 328 | |
Anirudh Ghayal | 9f77e96 | 2011-12-06 12:38:21 +0530 | [diff] [blame] | 329 | return 0; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 330 | |
Anirudh Ghayal | 9f77e96 | 2011-12-06 12:38:21 +0530 | [diff] [blame] | 331 | err: |
| 332 | platform_set_drvdata(pdev, NULL); |
| 333 | kfree(pmic); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 334 | return rc; |
| 335 | } |
| 336 | |
Anirudh Ghayal | c8051a8 | 2011-11-17 09:28:24 +0530 | [diff] [blame] | 337 | static int __devexit pm8901_remove(struct platform_device *pdev) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 338 | { |
Anirudh Ghayal | 9f77e96 | 2011-12-06 12:38:21 +0530 | [diff] [blame] | 339 | struct pm8xxx_drvdata *drvdata; |
| 340 | struct pm8901_chip *pmic = NULL; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 341 | |
Anirudh Ghayal | 9f77e96 | 2011-12-06 12:38:21 +0530 | [diff] [blame] | 342 | drvdata = platform_get_drvdata(pdev); |
| 343 | if (drvdata) |
| 344 | pmic = drvdata->pm_chip_data; |
| 345 | if (pmic) { |
| 346 | if (pmic->dev) |
| 347 | mfd_remove_devices(pmic->dev); |
| 348 | if (pmic->irq_chip) |
| 349 | pm8xxx_irq_exit(pmic->irq_chip); |
| 350 | kfree(pmic->mfd_regulators); |
| 351 | kfree(pmic); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 352 | } |
Anirudh Ghayal | 9f77e96 | 2011-12-06 12:38:21 +0530 | [diff] [blame] | 353 | platform_set_drvdata(pdev, NULL); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 354 | |
| 355 | return 0; |
| 356 | } |
| 357 | |
Anirudh Ghayal | c8051a8 | 2011-11-17 09:28:24 +0530 | [diff] [blame] | 358 | static struct platform_driver pm8901_driver = { |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 359 | .probe = pm8901_probe, |
| 360 | .remove = __devexit_p(pm8901_remove), |
Anirudh Ghayal | c8051a8 | 2011-11-17 09:28:24 +0530 | [diff] [blame] | 361 | .driver = { |
| 362 | .name = "pm8901-core", |
| 363 | .owner = THIS_MODULE, |
| 364 | }, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 365 | }; |
| 366 | |
| 367 | static int __init pm8901_init(void) |
| 368 | { |
Anirudh Ghayal | c8051a8 | 2011-11-17 09:28:24 +0530 | [diff] [blame] | 369 | return platform_driver_register(&pm8901_driver); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 370 | } |
Anirudh Ghayal | 9f77e96 | 2011-12-06 12:38:21 +0530 | [diff] [blame] | 371 | postcore_initcall(pm8901_init); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 372 | |
| 373 | static void __exit pm8901_exit(void) |
| 374 | { |
Anirudh Ghayal | c8051a8 | 2011-11-17 09:28:24 +0530 | [diff] [blame] | 375 | platform_driver_unregister(&pm8901_driver); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 376 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 377 | module_exit(pm8901_exit); |
| 378 | |
| 379 | MODULE_LICENSE("GPL v2"); |
| 380 | MODULE_DESCRIPTION("PMIC8901 core driver"); |
| 381 | MODULE_VERSION("1.0"); |
| 382 | MODULE_ALIAS("platform:pmic8901-core"); |