Jay Chokshi | 9d36a3d | 2011-10-26 15:57:51 -0700 | [diff] [blame] | 1 | /* |
David Keitel | b0f4036 | 2012-01-16 13:29:29 -0800 | [diff] [blame] | 2 | * Copyright (c) 2011-2012, Code Aurora Forum. All rights reserved. |
Jay Chokshi | 9d36a3d | 2011-10-26 15:57:51 -0700 | [diff] [blame] | 3 | * |
| 4 | * This program is free software; you can redistribute it and/or modify |
| 5 | * it under the terms of the GNU General Public License version 2 and |
| 6 | * only version 2 as published by the Free Software Foundation. |
| 7 | * |
| 8 | * This program is distributed in the hope that it will be useful, |
| 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 11 | * GNU General Public License for more details. |
| 12 | */ |
| 13 | |
| 14 | #define pr_fmt(fmt) "%s: " fmt, __func__ |
| 15 | |
| 16 | #include <linux/kernel.h> |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 17 | #include <linux/module.h> |
Jay Chokshi | 9d36a3d | 2011-10-26 15:57:51 -0700 | [diff] [blame] | 18 | #include <linux/platform_device.h> |
| 19 | #include <linux/slab.h> |
| 20 | #include <linux/err.h> |
David Collins | 045a76e | 2011-12-06 11:35:28 -0800 | [diff] [blame] | 21 | #include <linux/string.h> |
Jay Chokshi | 9d36a3d | 2011-10-26 15:57:51 -0700 | [diff] [blame] | 22 | #include <linux/msm_ssbi.h> |
| 23 | #include <linux/mfd/core.h> |
| 24 | #include <linux/mfd/pm8xxx/pm8038.h> |
David Keitel | b0f4036 | 2012-01-16 13:29:29 -0800 | [diff] [blame] | 25 | #include <linux/mfd/pm8xxx/pm8921.h> |
Jay Chokshi | 9d36a3d | 2011-10-26 15:57:51 -0700 | [diff] [blame] | 26 | #include <linux/mfd/pm8xxx/core.h> |
David Collins | 045a76e | 2011-12-06 11:35:28 -0800 | [diff] [blame] | 27 | #include <linux/mfd/pm8xxx/regulator.h> |
Jay Chokshi | 9d36a3d | 2011-10-26 15:57:51 -0700 | [diff] [blame] | 28 | |
| 29 | #define REG_HWREV 0x002 /* PMIC4 revision */ |
| 30 | #define REG_HWREV_2 0x0E8 /* PMIC4 revision 2 */ |
| 31 | |
| 32 | #define REG_MPP_BASE 0x050 |
| 33 | #define REG_RTC_BASE 0x11D |
| 34 | #define REG_IRQ_BASE 0x1BB |
| 35 | |
Asish Bhattacharya | dfe0f57 | 2012-03-19 02:45:03 -0700 | [diff] [blame] | 36 | #define REG_SPK_BASE 0x253 |
| 37 | #define REG_SPK_REGISTERS 3 |
| 38 | |
David Collins | eff4bd5 | 2012-06-21 15:31:13 -0700 | [diff] [blame] | 39 | #define REG_TEMP_ALARM_CTRL 0x01B |
| 40 | #define REG_TEMP_ALARM_PWM 0x09B |
| 41 | |
Jay Chokshi | 9d36a3d | 2011-10-26 15:57:51 -0700 | [diff] [blame] | 42 | #define PM8038_VERSION_MASK 0xFFF0 |
| 43 | #define PM8038_VERSION_VALUE 0x09F0 |
| 44 | #define PM8038_REVISION_MASK 0x000F |
| 45 | |
| 46 | #define REG_PM8038_PON_CNTRL_3 0x01D |
Jay Chokshi | 9d36a3d | 2011-10-26 15:57:51 -0700 | [diff] [blame] | 47 | |
| 48 | #define SINGLE_IRQ_RESOURCE(_name, _irq) \ |
| 49 | { \ |
| 50 | .name = _name, \ |
| 51 | .start = _irq, \ |
| 52 | .end = _irq, \ |
| 53 | .flags = IORESOURCE_IRQ, \ |
| 54 | } |
| 55 | |
| 56 | struct pm8038 { |
David Collins | 045a76e | 2011-12-06 11:35:28 -0800 | [diff] [blame] | 57 | struct device *dev; |
| 58 | struct pm_irq_chip *irq_chip; |
| 59 | struct mfd_cell *mfd_regulators; |
| 60 | struct pm8xxx_regulator_core_platform_data *regulator_cdata; |
| 61 | u32 rev_registers; |
Abhijeet Dharmapurikar | a4ed55c | 2012-08-28 15:07:43 -0700 | [diff] [blame^] | 62 | u8 restart_reason; |
Jay Chokshi | 9d36a3d | 2011-10-26 15:57:51 -0700 | [diff] [blame] | 63 | }; |
| 64 | |
| 65 | static int pm8038_readb(const struct device *dev, u16 addr, u8 *val) |
| 66 | { |
| 67 | const struct pm8xxx_drvdata *pm8038_drvdata = dev_get_drvdata(dev); |
| 68 | const struct pm8038 *pmic = pm8038_drvdata->pm_chip_data; |
| 69 | |
| 70 | return msm_ssbi_read(pmic->dev->parent, addr, val, 1); |
| 71 | } |
| 72 | |
| 73 | static int pm8038_writeb(const struct device *dev, u16 addr, u8 val) |
| 74 | { |
| 75 | const struct pm8xxx_drvdata *pm8038_drvdata = dev_get_drvdata(dev); |
| 76 | const struct pm8038 *pmic = pm8038_drvdata->pm_chip_data; |
| 77 | |
| 78 | return msm_ssbi_write(pmic->dev->parent, addr, &val, 1); |
| 79 | } |
| 80 | |
| 81 | static int pm8038_read_buf(const struct device *dev, u16 addr, u8 *buf, |
| 82 | int cnt) |
| 83 | { |
| 84 | const struct pm8xxx_drvdata *pm8038_drvdata = dev_get_drvdata(dev); |
| 85 | const struct pm8038 *pmic = pm8038_drvdata->pm_chip_data; |
| 86 | |
| 87 | return msm_ssbi_read(pmic->dev->parent, addr, buf, cnt); |
| 88 | } |
| 89 | |
| 90 | static int pm8038_write_buf(const struct device *dev, u16 addr, u8 *buf, |
| 91 | int cnt) |
| 92 | { |
| 93 | const struct pm8xxx_drvdata *pm8038_drvdata = dev_get_drvdata(dev); |
| 94 | const struct pm8038 *pmic = pm8038_drvdata->pm_chip_data; |
| 95 | |
| 96 | return msm_ssbi_write(pmic->dev->parent, addr, buf, cnt); |
| 97 | } |
| 98 | |
| 99 | static int pm8038_read_irq_stat(const struct device *dev, int irq) |
| 100 | { |
| 101 | const struct pm8xxx_drvdata *pm8038_drvdata = dev_get_drvdata(dev); |
| 102 | const struct pm8038 *pmic = pm8038_drvdata->pm_chip_data; |
| 103 | |
| 104 | return pm8xxx_get_irq_stat(pmic->irq_chip, irq); |
| 105 | } |
| 106 | |
| 107 | static enum pm8xxx_version pm8038_get_version(const struct device *dev) |
| 108 | { |
| 109 | const struct pm8xxx_drvdata *pm8038_drvdata = dev_get_drvdata(dev); |
| 110 | const struct pm8038 *pmic = pm8038_drvdata->pm_chip_data; |
| 111 | enum pm8xxx_version version = -ENODEV; |
| 112 | |
| 113 | if ((pmic->rev_registers & PM8038_VERSION_MASK) == PM8038_VERSION_VALUE) |
| 114 | version = PM8XXX_VERSION_8038; |
| 115 | |
| 116 | return version; |
| 117 | } |
| 118 | |
| 119 | static int pm8038_get_revision(const struct device *dev) |
| 120 | { |
| 121 | const struct pm8xxx_drvdata *pm8038_drvdata = dev_get_drvdata(dev); |
| 122 | const struct pm8038 *pmic = pm8038_drvdata->pm_chip_data; |
| 123 | |
| 124 | return pmic->rev_registers & PM8038_REVISION_MASK; |
| 125 | } |
| 126 | |
Abhijeet Dharmapurikar | a4ed55c | 2012-08-28 15:07:43 -0700 | [diff] [blame^] | 127 | static u8 pm8038_restart_reason(const struct device *dev) |
| 128 | { |
| 129 | const struct pm8xxx_drvdata *pm8038_drvdata = dev_get_drvdata(dev); |
| 130 | const struct pm8038 *pmic = pm8038_drvdata->pm_chip_data; |
| 131 | |
| 132 | return pmic->restart_reason; |
| 133 | } |
| 134 | |
Jay Chokshi | 9d36a3d | 2011-10-26 15:57:51 -0700 | [diff] [blame] | 135 | static struct pm8xxx_drvdata pm8038_drvdata = { |
| 136 | .pmic_readb = pm8038_readb, |
| 137 | .pmic_writeb = pm8038_writeb, |
| 138 | .pmic_read_buf = pm8038_read_buf, |
| 139 | .pmic_write_buf = pm8038_write_buf, |
| 140 | .pmic_read_irq_stat = pm8038_read_irq_stat, |
| 141 | .pmic_get_version = pm8038_get_version, |
| 142 | .pmic_get_revision = pm8038_get_revision, |
Abhijeet Dharmapurikar | a4ed55c | 2012-08-28 15:07:43 -0700 | [diff] [blame^] | 143 | .pmic_restart_reason = pm8038_restart_reason, |
Jay Chokshi | 9d36a3d | 2011-10-26 15:57:51 -0700 | [diff] [blame] | 144 | }; |
| 145 | |
| 146 | static const struct resource gpio_cell_resources[] __devinitconst = { |
| 147 | [0] = { |
| 148 | .start = PM8038_IRQ_BLOCK_BIT(PM8038_GPIO_BLOCK_START, 0), |
| 149 | .end = PM8038_IRQ_BLOCK_BIT(PM8038_GPIO_BLOCK_START, 0) |
| 150 | + PM8038_NR_GPIOS - 1, |
| 151 | .flags = IORESOURCE_IRQ, |
| 152 | }, |
| 153 | }; |
| 154 | |
| 155 | static struct mfd_cell gpio_cell __devinitdata = { |
| 156 | .name = PM8XXX_GPIO_DEV_NAME, |
| 157 | .id = -1, |
| 158 | .resources = gpio_cell_resources, |
| 159 | .num_resources = ARRAY_SIZE(gpio_cell_resources), |
| 160 | }; |
| 161 | |
Siddartha Mohanadoss | ef10213 | 2011-12-19 11:30:32 -0800 | [diff] [blame] | 162 | static const struct resource adc_cell_resources[] __devinitconst = { |
| 163 | SINGLE_IRQ_RESOURCE(NULL, PM8038_ADC_EOC_USR_IRQ), |
| 164 | SINGLE_IRQ_RESOURCE(NULL, PM8038_ADC_BATT_TEMP_WARM_IRQ), |
| 165 | SINGLE_IRQ_RESOURCE(NULL, PM8038_ADC_BATT_TEMP_COLD_IRQ), |
| 166 | }; |
| 167 | |
| 168 | static struct mfd_cell adc_cell __devinitdata = { |
| 169 | .name = PM8XXX_ADC_DEV_NAME, |
| 170 | .id = -1, |
| 171 | .resources = adc_cell_resources, |
| 172 | .num_resources = ARRAY_SIZE(adc_cell_resources), |
| 173 | }; |
| 174 | |
David Keitel | b0f4036 | 2012-01-16 13:29:29 -0800 | [diff] [blame] | 175 | static const struct resource charger_cell_resources[] __devinitconst = { |
| 176 | SINGLE_IRQ_RESOURCE("USBIN_VALID_IRQ", PM8921_USBIN_VALID_IRQ), |
| 177 | SINGLE_IRQ_RESOURCE("USBIN_OV_IRQ", PM8921_USBIN_OV_IRQ), |
| 178 | SINGLE_IRQ_RESOURCE("BATT_INSERTED_IRQ", PM8921_BATT_INSERTED_IRQ), |
| 179 | SINGLE_IRQ_RESOURCE("VBATDET_LOW_IRQ", PM8921_VBATDET_LOW_IRQ), |
| 180 | SINGLE_IRQ_RESOURCE("USBIN_UV_IRQ", PM8921_USBIN_UV_IRQ), |
| 181 | SINGLE_IRQ_RESOURCE("VBAT_OV_IRQ", PM8921_VBAT_OV_IRQ), |
| 182 | SINGLE_IRQ_RESOURCE("CHGWDOG_IRQ", PM8921_CHGWDOG_IRQ), |
| 183 | SINGLE_IRQ_RESOURCE("VCP_IRQ", PM8921_VCP_IRQ), |
| 184 | SINGLE_IRQ_RESOURCE("ATCDONE_IRQ", PM8921_ATCDONE_IRQ), |
| 185 | SINGLE_IRQ_RESOURCE("ATCFAIL_IRQ", PM8921_ATCFAIL_IRQ), |
| 186 | SINGLE_IRQ_RESOURCE("CHGDONE_IRQ", PM8921_CHGDONE_IRQ), |
| 187 | SINGLE_IRQ_RESOURCE("CHGFAIL_IRQ", PM8921_CHGFAIL_IRQ), |
| 188 | SINGLE_IRQ_RESOURCE("CHGSTATE_IRQ", PM8921_CHGSTATE_IRQ), |
| 189 | SINGLE_IRQ_RESOURCE("LOOP_CHANGE_IRQ", PM8921_LOOP_CHANGE_IRQ), |
| 190 | SINGLE_IRQ_RESOURCE("FASTCHG_IRQ", PM8921_FASTCHG_IRQ), |
| 191 | SINGLE_IRQ_RESOURCE("TRKLCHG_IRQ", PM8921_TRKLCHG_IRQ), |
| 192 | SINGLE_IRQ_RESOURCE("BATT_REMOVED_IRQ", PM8921_BATT_REMOVED_IRQ), |
| 193 | SINGLE_IRQ_RESOURCE("BATTTEMP_HOT_IRQ", PM8921_BATTTEMP_HOT_IRQ), |
| 194 | SINGLE_IRQ_RESOURCE("CHGHOT_IRQ", PM8921_CHGHOT_IRQ), |
| 195 | SINGLE_IRQ_RESOURCE("BATTTEMP_COLD_IRQ", PM8921_BATTTEMP_COLD_IRQ), |
| 196 | SINGLE_IRQ_RESOURCE("CHG_GONE_IRQ", PM8921_CHG_GONE_IRQ), |
| 197 | SINGLE_IRQ_RESOURCE("BAT_TEMP_OK_IRQ", PM8921_BAT_TEMP_OK_IRQ), |
| 198 | SINGLE_IRQ_RESOURCE("COARSE_DET_LOW_IRQ", PM8921_COARSE_DET_LOW_IRQ), |
| 199 | SINGLE_IRQ_RESOURCE("VDD_LOOP_IRQ", PM8921_VDD_LOOP_IRQ), |
| 200 | SINGLE_IRQ_RESOURCE("VREG_OV_IRQ", PM8921_VREG_OV_IRQ), |
| 201 | SINGLE_IRQ_RESOURCE("VBATDET_IRQ", PM8921_VBATDET_IRQ), |
| 202 | SINGLE_IRQ_RESOURCE("BATFET_IRQ", PM8921_BATFET_IRQ), |
| 203 | SINGLE_IRQ_RESOURCE("PSI_IRQ", PM8921_PSI_IRQ), |
| 204 | SINGLE_IRQ_RESOURCE("DCIN_VALID_IRQ", PM8921_DCIN_VALID_IRQ), |
| 205 | SINGLE_IRQ_RESOURCE("DCIN_OV_IRQ", PM8921_DCIN_OV_IRQ), |
| 206 | SINGLE_IRQ_RESOURCE("DCIN_UV_IRQ", PM8921_DCIN_UV_IRQ), |
| 207 | }; |
| 208 | |
| 209 | static const struct resource bms_cell_resources[] __devinitconst = { |
| 210 | SINGLE_IRQ_RESOURCE("PM8921_BMS_SBI_WRITE_OK", PM8921_BMS_SBI_WRITE_OK), |
| 211 | SINGLE_IRQ_RESOURCE("PM8921_BMS_CC_THR", PM8921_BMS_CC_THR), |
| 212 | SINGLE_IRQ_RESOURCE("PM8921_BMS_VSENSE_THR", PM8921_BMS_VSENSE_THR), |
| 213 | SINGLE_IRQ_RESOURCE("PM8921_BMS_VSENSE_FOR_R", PM8921_BMS_VSENSE_FOR_R), |
| 214 | SINGLE_IRQ_RESOURCE("PM8921_BMS_OCV_FOR_R", PM8921_BMS_OCV_FOR_R), |
| 215 | SINGLE_IRQ_RESOURCE("PM8921_BMS_GOOD_OCV", PM8921_BMS_GOOD_OCV), |
| 216 | SINGLE_IRQ_RESOURCE("PM8921_BMS_VSENSE_AVG", PM8921_BMS_VSENSE_AVG), |
| 217 | }; |
| 218 | |
| 219 | static struct mfd_cell charger_cell __devinitdata = { |
| 220 | .name = PM8921_CHARGER_DEV_NAME, |
| 221 | .id = -1, |
| 222 | .resources = charger_cell_resources, |
| 223 | .num_resources = ARRAY_SIZE(charger_cell_resources), |
| 224 | }; |
| 225 | |
| 226 | static struct mfd_cell bms_cell __devinitdata = { |
| 227 | .name = PM8921_BMS_DEV_NAME, |
| 228 | .id = -1, |
| 229 | .resources = bms_cell_resources, |
| 230 | .num_resources = ARRAY_SIZE(bms_cell_resources), |
| 231 | }; |
Jay Chokshi | 9d36a3d | 2011-10-26 15:57:51 -0700 | [diff] [blame] | 232 | static const struct resource mpp_cell_resources[] __devinitconst = { |
| 233 | { |
| 234 | .start = PM8038_IRQ_BLOCK_BIT(PM8038_MPP_BLOCK_START, 0), |
| 235 | .end = PM8038_IRQ_BLOCK_BIT(PM8038_MPP_BLOCK_START, 0) |
| 236 | + PM8038_NR_MPPS - 1, |
| 237 | .flags = IORESOURCE_IRQ, |
| 238 | }, |
| 239 | }; |
| 240 | |
| 241 | static struct mfd_cell mpp_cell __devinitdata = { |
| 242 | .name = PM8XXX_MPP_DEV_NAME, |
| 243 | .id = 1, |
| 244 | .resources = mpp_cell_resources, |
| 245 | .num_resources = ARRAY_SIZE(mpp_cell_resources), |
| 246 | }; |
| 247 | |
| 248 | static const struct resource rtc_cell_resources[] __devinitconst = { |
| 249 | [0] = SINGLE_IRQ_RESOURCE(NULL, PM8038_RTC_ALARM_IRQ), |
| 250 | [1] = { |
| 251 | .name = "pmic_rtc_base", |
| 252 | .start = REG_RTC_BASE, |
| 253 | .end = REG_RTC_BASE, |
| 254 | .flags = IORESOURCE_IO, |
| 255 | }, |
| 256 | }; |
| 257 | |
| 258 | static struct mfd_cell rtc_cell __devinitdata = { |
| 259 | .name = PM8XXX_RTC_DEV_NAME, |
| 260 | .id = -1, |
| 261 | .resources = rtc_cell_resources, |
| 262 | .num_resources = ARRAY_SIZE(rtc_cell_resources), |
| 263 | }; |
| 264 | |
| 265 | static const struct resource resources_pwrkey[] __devinitconst = { |
| 266 | SINGLE_IRQ_RESOURCE(NULL, PM8038_PWRKEY_REL_IRQ), |
| 267 | SINGLE_IRQ_RESOURCE(NULL, PM8038_PWRKEY_PRESS_IRQ), |
| 268 | }; |
| 269 | |
| 270 | static struct mfd_cell pwrkey_cell __devinitdata = { |
| 271 | .name = PM8XXX_PWRKEY_DEV_NAME, |
| 272 | .id = -1, |
| 273 | .num_resources = ARRAY_SIZE(resources_pwrkey), |
| 274 | .resources = resources_pwrkey, |
| 275 | }; |
| 276 | |
| 277 | static struct mfd_cell pwm_cell __devinitdata = { |
| 278 | .name = PM8XXX_PWM_DEV_NAME, |
| 279 | .id = -1, |
| 280 | }; |
| 281 | |
| 282 | static struct mfd_cell misc_cell __devinitdata = { |
| 283 | .name = PM8XXX_MISC_DEV_NAME, |
| 284 | .id = -1, |
| 285 | }; |
| 286 | |
Amy Maloche | 8950101 | 2012-01-27 14:11:29 -0800 | [diff] [blame] | 287 | static struct mfd_cell leds_cell __devinitdata = { |
| 288 | .name = PM8XXX_LEDS_DEV_NAME, |
| 289 | .id = -1, |
| 290 | }; |
| 291 | |
Asish Bhattacharya | dfe0f57 | 2012-03-19 02:45:03 -0700 | [diff] [blame] | 292 | static const struct resource resources_spk[] __devinitconst = { |
| 293 | [0] = { |
| 294 | .name = PM8XXX_SPK_DEV_NAME, |
| 295 | .start = REG_SPK_BASE, |
| 296 | .end = REG_SPK_BASE + REG_SPK_REGISTERS, |
| 297 | .flags = IORESOURCE_IO, |
| 298 | }, |
| 299 | }; |
| 300 | |
| 301 | static struct mfd_cell spk_cell __devinitdata = { |
| 302 | .name = PM8XXX_SPK_DEV_NAME, |
| 303 | .id = -1, |
| 304 | .num_resources = ARRAY_SIZE(resources_spk), |
| 305 | .resources = resources_spk, |
| 306 | }; |
| 307 | |
Jay Chokshi | 9d36a3d | 2011-10-26 15:57:51 -0700 | [diff] [blame] | 308 | static struct mfd_cell debugfs_cell __devinitdata = { |
| 309 | .name = "pm8xxx-debug", |
| 310 | .id = 0, |
| 311 | .platform_data = "pm8038-dbg", |
| 312 | .pdata_size = sizeof("pm8038-dbg"), |
| 313 | }; |
| 314 | |
David Collins | eff4bd5 | 2012-06-21 15:31:13 -0700 | [diff] [blame] | 315 | static const struct resource thermal_alarm_cell_resources[] __devinitconst = { |
| 316 | SINGLE_IRQ_RESOURCE("pm8038_tempstat_irq", PM8038_TEMPSTAT_IRQ), |
| 317 | SINGLE_IRQ_RESOURCE("pm8038_overtemp_irq", PM8038_OVERTEMP_IRQ), |
| 318 | }; |
| 319 | |
| 320 | static struct pm8xxx_tm_core_data thermal_alarm_cdata = { |
| 321 | .adc_channel = CHANNEL_DIE_TEMP, |
| 322 | .adc_type = PM8XXX_TM_ADC_PM8XXX_ADC, |
| 323 | .reg_addr_temp_alarm_ctrl = REG_TEMP_ALARM_CTRL, |
| 324 | .reg_addr_temp_alarm_pwm = REG_TEMP_ALARM_PWM, |
| 325 | .tm_name = "pm8038_tz", |
| 326 | .irq_name_temp_stat = "pm8038_tempstat_irq", |
| 327 | .irq_name_over_temp = "pm8038_overtemp_irq", |
| 328 | }; |
| 329 | |
| 330 | static struct mfd_cell thermal_alarm_cell __devinitdata = { |
| 331 | .name = PM8XXX_TM_DEV_NAME, |
| 332 | .id = -1, |
| 333 | .resources = thermal_alarm_cell_resources, |
| 334 | .num_resources = ARRAY_SIZE(thermal_alarm_cell_resources), |
| 335 | .platform_data = &thermal_alarm_cdata, |
| 336 | .pdata_size = sizeof(struct pm8xxx_tm_core_data), |
| 337 | }; |
| 338 | |
Abhijeet Dharmapurikar | 1cda0f5 | 2012-06-21 15:39:41 -0700 | [diff] [blame] | 339 | static const struct resource ccadc_cell_resources[] __devinitconst = { |
| 340 | SINGLE_IRQ_RESOURCE("PM8921_BMS_CCADC_EOC", PM8921_BMS_CCADC_EOC), |
| 341 | }; |
| 342 | |
| 343 | static struct mfd_cell ccadc_cell __devinitdata = { |
| 344 | .name = PM8XXX_CCADC_DEV_NAME, |
| 345 | .id = -1, |
| 346 | .resources = ccadc_cell_resources, |
| 347 | .num_resources = ARRAY_SIZE(ccadc_cell_resources), |
| 348 | }; |
| 349 | |
David Collins | 045a76e | 2011-12-06 11:35:28 -0800 | [diff] [blame] | 350 | static struct pm8xxx_vreg regulator_data[] = { |
| 351 | /* name pc_name ctrl test hpm_min */ |
| 352 | NLDO1200("8038_l1", 0x0AE, 0x0AF, LDO_1200), |
| 353 | NLDO("8038_l2", "8038_l2_pc", 0x0B0, 0x0B1, LDO_150), |
| 354 | PLDO("8038_l3", "8038_l3_pc", 0x0B2, 0x0B3, LDO_50), |
| 355 | PLDO("8038_l4", "8038_l4_pc", 0x0B4, 0x0B5, LDO_50), |
| 356 | PLDO("8038_l5", "8038_l5_pc", 0x0B6, 0x0B7, LDO_600), |
| 357 | PLDO("8038_l6", "8038_l6_pc", 0x0B8, 0x0B9, LDO_600), |
| 358 | PLDO("8038_l7", "8038_l7_pc", 0x0BA, 0x0BB, LDO_600), |
| 359 | PLDO("8038_l8", "8038_l8_pc", 0x0BC, 0x0BD, LDO_300), |
| 360 | PLDO("8038_l9", "8038_l9_pc", 0x0BE, 0x0BF, LDO_300), |
| 361 | PLDO("8038_l10", "8038_l10_pc", 0x0C0, 0x0C1, LDO_600), |
| 362 | PLDO("8038_l11", "8038_l11_pc", 0x0C2, 0x0C3, LDO_600), |
| 363 | NLDO("8038_l12", "8038_l12_pc", 0x0C4, 0x0C5, LDO_300), |
| 364 | PLDO("8038_l14", "8038_l14_pc", 0x0C8, 0x0C9, LDO_50), |
| 365 | PLDO("8038_l15", "8038_l15_pc", 0x0CA, 0x0CB, LDO_150), |
| 366 | NLDO1200("8038_l16", 0x0CC, 0x0CD, LDO_1200), |
| 367 | PLDO("8038_l17", "8038_l17_pc", 0x0CE, 0x0CF, LDO_150), |
| 368 | PLDO("8038_l18", "8038_l18_pc", 0x0D0, 0x0D1, LDO_50), |
| 369 | NLDO1200("8038_l19", 0x0D2, 0x0D3, LDO_1200), |
| 370 | NLDO1200("8038_l20", 0x0D4, 0x0D5, LDO_1200), |
| 371 | PLDO("8038_l21", "8038_l21_pc", 0x0D6, 0x0D7, LDO_150), |
| 372 | PLDO("8038_l22", "8038_l22_pc", 0x0D8, 0x0D9, LDO_50), |
| 373 | PLDO("8038_l23", "8038_l23_pc", 0x0DA, 0x0DB, LDO_50), |
| 374 | NLDO1200("8038_l24", 0x0DC, 0x0DD, LDO_1200), |
| 375 | NLDO("8038_l26", "8038_l26_pc", 0x0E0, 0x0E1, LDO_150), |
| 376 | NLDO1200("8038_l27", 0x0E2, 0x0E3, LDO_1200), |
| 377 | |
| 378 | /* name pc_name ctrl test2 clk sleep hpm_min */ |
| 379 | SMPS("8038_s1", "8038_s1_pc", 0x1E0, 0x1E5, 0x009, 0x1E2, SMPS_1500), |
| 380 | SMPS("8038_s2", "8038_s2_pc", 0x1D8, 0x1DD, 0x00A, 0x1DA, SMPS_1500), |
| 381 | SMPS("8038_s3", "8038_s3_pc", 0x1D0, 0x1D5, 0x00B, 0x1D2, SMPS_1500), |
| 382 | SMPS("8038_s4", "8038_s4_pc", 0x1E8, 0x1ED, 0x00C, 0x1EA, SMPS_1500), |
| 383 | |
| 384 | /* name ctrl fts_cnfg1 pfm pwr_cnfg hpm_min */ |
| 385 | FTSMPS("8038_s5", 0x025, 0x02E, 0x026, 0x032, SMPS_2000), |
| 386 | FTSMPS("8038_s6", 0x036, 0x03F, 0x037, 0x043, SMPS_2000), |
| 387 | |
David Collins | 1b570d2 | 2012-01-30 15:40:55 -0800 | [diff] [blame] | 388 | /* name pc_name ctrl test */ |
| 389 | VS("8038_lvs1", "8038_lvs1_pc", 0x060, 0x061), |
| 390 | VS("8038_lvs2", "8038_lvs2_pc", 0x062, 0x063), |
David Collins | 045a76e | 2011-12-06 11:35:28 -0800 | [diff] [blame] | 391 | }; |
| 392 | |
| 393 | #define MAX_NAME_COMPARISON_LEN 32 |
| 394 | |
| 395 | static int __devinit match_regulator( |
Mark Brown | 5d028cd | 2011-10-14 13:36:04 +0100 | [diff] [blame] | 396 | struct pm8xxx_regulator_core_platform_data *core_data, const char *name) |
David Collins | 045a76e | 2011-12-06 11:35:28 -0800 | [diff] [blame] | 397 | { |
| 398 | int found = 0; |
| 399 | int i; |
| 400 | |
| 401 | for (i = 0; i < ARRAY_SIZE(regulator_data); i++) { |
| 402 | if (regulator_data[i].rdesc.name |
| 403 | && strncmp(regulator_data[i].rdesc.name, name, |
| 404 | MAX_NAME_COMPARISON_LEN) == 0) { |
| 405 | core_data->is_pin_controlled = false; |
| 406 | core_data->vreg = ®ulator_data[i]; |
| 407 | found = 1; |
| 408 | break; |
| 409 | } else if (regulator_data[i].rdesc_pc.name |
| 410 | && strncmp(regulator_data[i].rdesc_pc.name, name, |
| 411 | MAX_NAME_COMPARISON_LEN) == 0) { |
| 412 | core_data->is_pin_controlled = true; |
| 413 | core_data->vreg = ®ulator_data[i]; |
| 414 | found = 1; |
| 415 | break; |
| 416 | } |
| 417 | } |
| 418 | |
| 419 | if (!found) |
| 420 | pr_err("could not find a match for regulator: %s\n", name); |
| 421 | |
| 422 | return found; |
| 423 | } |
| 424 | |
| 425 | static int __devinit |
| 426 | pm8038_add_regulators(const struct pm8038_platform_data *pdata, |
| 427 | struct pm8038 *pmic, int irq_base) |
| 428 | { |
| 429 | int ret = 0; |
| 430 | struct mfd_cell *mfd_regulators; |
| 431 | struct pm8xxx_regulator_core_platform_data *cdata; |
| 432 | int i; |
| 433 | |
| 434 | /* Add one device for each regulator used by the board. */ |
| 435 | mfd_regulators = kzalloc(sizeof(struct mfd_cell) |
| 436 | * (pdata->num_regulators), GFP_KERNEL); |
| 437 | if (!mfd_regulators) { |
| 438 | pr_err("Cannot allocate %d bytes for pm8038 regulator " |
| 439 | "mfd cells\n", sizeof(struct mfd_cell) |
| 440 | * (pdata->num_regulators)); |
| 441 | return -ENOMEM; |
| 442 | } |
| 443 | cdata = kzalloc(sizeof(struct pm8xxx_regulator_core_platform_data) |
| 444 | * pdata->num_regulators, GFP_KERNEL); |
| 445 | if (!cdata) { |
| 446 | pr_err("Cannot allocate %d bytes for pm8038 regulator " |
| 447 | "core data\n", pdata->num_regulators |
| 448 | * sizeof(struct pm8xxx_regulator_core_platform_data)); |
| 449 | kfree(mfd_regulators); |
| 450 | return -ENOMEM; |
| 451 | } |
| 452 | for (i = 0; i < ARRAY_SIZE(regulator_data); i++) |
| 453 | mutex_init(®ulator_data[i].pc_lock); |
| 454 | |
| 455 | for (i = 0; i < pdata->num_regulators; i++) { |
| 456 | if (!pdata->regulator_pdatas[i].init_data.constraints.name) { |
| 457 | pr_err("name missing for regulator %d\n", i); |
| 458 | ret = -EINVAL; |
| 459 | goto bail; |
| 460 | } |
| 461 | if (!match_regulator(&cdata[i], |
| 462 | pdata->regulator_pdatas[i].init_data.constraints.name)) { |
| 463 | ret = -ENODEV; |
| 464 | goto bail; |
| 465 | } |
| 466 | cdata[i].pdata = &(pdata->regulator_pdatas[i]); |
| 467 | mfd_regulators[i].name = PM8XXX_REGULATOR_DEV_NAME; |
| 468 | mfd_regulators[i].id = cdata[i].pdata->id; |
| 469 | mfd_regulators[i].platform_data = &cdata[i]; |
| 470 | mfd_regulators[i].pdata_size = |
| 471 | sizeof(struct pm8xxx_regulator_core_platform_data); |
| 472 | } |
| 473 | ret = mfd_add_devices(pmic->dev, 0, mfd_regulators, |
| 474 | pdata->num_regulators, NULL, irq_base); |
| 475 | if (ret) |
| 476 | goto bail; |
| 477 | |
| 478 | pmic->mfd_regulators = mfd_regulators; |
| 479 | pmic->regulator_cdata = cdata; |
| 480 | return ret; |
| 481 | |
| 482 | bail: |
| 483 | for (i = 0; i < ARRAY_SIZE(regulator_data); i++) |
| 484 | mutex_destroy(®ulator_data[i].pc_lock); |
| 485 | kfree(mfd_regulators); |
| 486 | kfree(cdata); |
| 487 | return ret; |
| 488 | } |
Jay Chokshi | 9d36a3d | 2011-10-26 15:57:51 -0700 | [diff] [blame] | 489 | |
| 490 | static int __devinit |
| 491 | pm8038_add_subdevices(const struct pm8038_platform_data *pdata, |
| 492 | struct pm8038 *pmic) |
| 493 | { |
| 494 | int ret = 0, irq_base = 0; |
| 495 | struct pm_irq_chip *irq_chip; |
| 496 | |
| 497 | if (pdata->irq_pdata) { |
| 498 | pdata->irq_pdata->irq_cdata.nirqs = PM8038_NR_IRQS; |
| 499 | pdata->irq_pdata->irq_cdata.base_addr = REG_IRQ_BASE; |
| 500 | irq_base = pdata->irq_pdata->irq_base; |
| 501 | irq_chip = pm8xxx_irq_init(pmic->dev, pdata->irq_pdata); |
| 502 | |
| 503 | if (IS_ERR(irq_chip)) { |
| 504 | pr_err("Failed to init interrupts ret=%ld\n", |
| 505 | PTR_ERR(irq_chip)); |
| 506 | return PTR_ERR(irq_chip); |
| 507 | } |
| 508 | pmic->irq_chip = irq_chip; |
| 509 | } |
| 510 | |
| 511 | if (pdata->gpio_pdata) { |
| 512 | pdata->gpio_pdata->gpio_cdata.ngpios = PM8038_NR_GPIOS; |
| 513 | gpio_cell.platform_data = pdata->gpio_pdata; |
| 514 | gpio_cell.pdata_size = sizeof(struct pm8xxx_gpio_platform_data); |
| 515 | ret = mfd_add_devices(pmic->dev, 0, &gpio_cell, 1, |
| 516 | NULL, irq_base); |
| 517 | if (ret) { |
| 518 | pr_err("Failed to add gpio subdevice ret=%d\n", ret); |
| 519 | goto bail; |
| 520 | } |
| 521 | } |
| 522 | |
| 523 | if (pdata->mpp_pdata) { |
| 524 | pdata->mpp_pdata->core_data.nmpps = PM8038_NR_MPPS; |
| 525 | pdata->mpp_pdata->core_data.base_addr = REG_MPP_BASE; |
| 526 | mpp_cell.platform_data = pdata->mpp_pdata; |
| 527 | mpp_cell.pdata_size = sizeof(struct pm8xxx_mpp_platform_data); |
| 528 | ret = mfd_add_devices(pmic->dev, 0, &mpp_cell, 1, NULL, |
| 529 | irq_base); |
| 530 | if (ret) { |
| 531 | pr_err("Failed to add mpp subdevice ret=%d\n", ret); |
| 532 | goto bail; |
| 533 | } |
| 534 | } |
| 535 | |
| 536 | if (pdata->rtc_pdata) { |
| 537 | rtc_cell.platform_data = pdata->rtc_pdata; |
| 538 | rtc_cell.pdata_size = sizeof(struct pm8xxx_rtc_platform_data); |
| 539 | ret = mfd_add_devices(pmic->dev, 0, &rtc_cell, 1, NULL, |
| 540 | irq_base); |
| 541 | if (ret) { |
| 542 | pr_err("Failed to add rtc subdevice ret=%d\n", ret); |
| 543 | goto bail; |
| 544 | } |
| 545 | } |
| 546 | |
| 547 | if (pdata->pwrkey_pdata) { |
| 548 | pwrkey_cell.platform_data = pdata->pwrkey_pdata; |
| 549 | pwrkey_cell.pdata_size = |
| 550 | sizeof(struct pm8xxx_pwrkey_platform_data); |
| 551 | ret = mfd_add_devices(pmic->dev, 0, &pwrkey_cell, 1, NULL, |
| 552 | irq_base); |
| 553 | if (ret) { |
| 554 | pr_err("Failed to add pwrkey subdevice ret=%d\n", ret); |
| 555 | goto bail; |
| 556 | } |
| 557 | } |
| 558 | |
| 559 | ret = mfd_add_devices(pmic->dev, 0, &pwm_cell, 1, NULL, 0); |
| 560 | if (ret) { |
| 561 | pr_err("Failed to add pwm subdevice ret=%d\n", ret); |
| 562 | goto bail; |
| 563 | } |
| 564 | |
| 565 | if (pdata->misc_pdata) { |
| 566 | misc_cell.platform_data = pdata->misc_pdata; |
| 567 | misc_cell.pdata_size = sizeof(struct pm8xxx_misc_platform_data); |
| 568 | ret = mfd_add_devices(pmic->dev, 0, &misc_cell, 1, NULL, |
| 569 | irq_base); |
| 570 | if (ret) { |
| 571 | pr_err("Failed to add misc subdevice ret=%d\n", ret); |
| 572 | goto bail; |
| 573 | } |
| 574 | } |
| 575 | |
Amy Maloche | 8950101 | 2012-01-27 14:11:29 -0800 | [diff] [blame] | 576 | if (pdata->leds_pdata) { |
| 577 | leds_cell.platform_data = pdata->leds_pdata; |
| 578 | leds_cell.pdata_size = sizeof(struct pm8xxx_led_platform_data); |
| 579 | ret = mfd_add_devices(pmic->dev, 0, &leds_cell, 1, NULL, 0); |
| 580 | if (ret) { |
| 581 | pr_err("Failed to add leds subdevice ret=%d\n", ret); |
| 582 | goto bail; |
| 583 | } |
| 584 | } |
| 585 | |
Asish Bhattacharya | dfe0f57 | 2012-03-19 02:45:03 -0700 | [diff] [blame] | 586 | if (pdata->spk_pdata) { |
| 587 | spk_cell.platform_data = pdata->spk_pdata; |
| 588 | spk_cell.pdata_size = sizeof(struct pm8xxx_spk_platform_data); |
| 589 | ret = mfd_add_devices(pmic->dev, 0, &spk_cell, 1, NULL, 0); |
| 590 | if (ret) { |
| 591 | pr_err("Failed to add spk subdevice ret=%d\n", ret); |
| 592 | goto bail; |
| 593 | } |
| 594 | } |
| 595 | |
David Collins | 045a76e | 2011-12-06 11:35:28 -0800 | [diff] [blame] | 596 | if (pdata->num_regulators > 0 && pdata->regulator_pdatas) { |
| 597 | ret = pm8038_add_regulators(pdata, pmic, irq_base); |
| 598 | if (ret) { |
| 599 | pr_err("Failed to add regulator subdevices ret=%d\n", |
| 600 | ret); |
| 601 | goto bail; |
| 602 | } |
| 603 | } |
| 604 | |
Jay Chokshi | 9d36a3d | 2011-10-26 15:57:51 -0700 | [diff] [blame] | 605 | ret = mfd_add_devices(pmic->dev, 0, &debugfs_cell, 1, NULL, irq_base); |
| 606 | if (ret) { |
| 607 | pr_err("Failed to add debugfs subdevice ret=%d\n", ret); |
| 608 | goto bail; |
| 609 | } |
| 610 | |
Siddartha Mohanadoss | ef10213 | 2011-12-19 11:30:32 -0800 | [diff] [blame] | 611 | if (pdata->adc_pdata) { |
| 612 | adc_cell.platform_data = pdata->adc_pdata; |
| 613 | adc_cell.pdata_size = |
| 614 | sizeof(struct pm8xxx_adc_platform_data); |
| 615 | ret = mfd_add_devices(pmic->dev, 0, &adc_cell, 1, NULL, |
| 616 | irq_base); |
| 617 | if (ret) { |
| 618 | pr_err("Failed to add adc subdevices ret=%d\n", |
| 619 | ret); |
| 620 | } |
| 621 | } |
| 622 | |
David Keitel | b0f4036 | 2012-01-16 13:29:29 -0800 | [diff] [blame] | 623 | if (pdata->charger_pdata) { |
| 624 | pdata->charger_pdata->charger_cdata.vbat_channel = CHANNEL_VBAT; |
| 625 | pdata->charger_pdata->charger_cdata.batt_temp_channel |
| 626 | = CHANNEL_BATT_THERM; |
| 627 | pdata->charger_pdata->charger_cdata.batt_id_channel |
| 628 | = CHANNEL_BATT_ID; |
| 629 | charger_cell.platform_data = pdata->charger_pdata; |
| 630 | charger_cell.pdata_size = |
| 631 | sizeof(struct pm8921_charger_platform_data); |
| 632 | ret = mfd_add_devices(pmic->dev, 0, &charger_cell, 1, NULL, |
| 633 | irq_base); |
| 634 | if (ret) { |
| 635 | pr_err("Failed to add charger subdevice ret=%d\n", ret); |
| 636 | goto bail; |
| 637 | } |
| 638 | } |
| 639 | |
| 640 | if (pdata->bms_pdata) { |
| 641 | pdata->bms_pdata->bms_cdata.batt_temp_channel |
| 642 | = CHANNEL_BATT_THERM; |
| 643 | pdata->bms_pdata->bms_cdata.vbat_channel = CHANNEL_VBAT; |
| 644 | pdata->bms_pdata->bms_cdata.ref625mv_channel = CHANNEL_625MV; |
| 645 | pdata->bms_pdata->bms_cdata.ref1p25v_channel = CHANNEL_125V; |
| 646 | pdata->bms_pdata->bms_cdata.batt_id_channel = CHANNEL_BATT_ID; |
| 647 | bms_cell.platform_data = pdata->bms_pdata; |
| 648 | bms_cell.pdata_size = sizeof(struct pm8921_bms_platform_data); |
| 649 | ret = mfd_add_devices(pmic->dev, 0, &bms_cell, 1, NULL, |
| 650 | irq_base); |
| 651 | if (ret) { |
| 652 | pr_err("Failed to add bms subdevice ret=%d\n", ret); |
| 653 | goto bail; |
| 654 | } |
| 655 | } |
David Collins | eff4bd5 | 2012-06-21 15:31:13 -0700 | [diff] [blame] | 656 | |
| 657 | ret = mfd_add_devices(pmic->dev, 0, &thermal_alarm_cell, 1, NULL, |
| 658 | irq_base); |
| 659 | if (ret) { |
| 660 | pr_err("Failed to add thermal alarm subdevice ret=%d\n", ret); |
| 661 | goto bail; |
| 662 | } |
| 663 | |
Abhijeet Dharmapurikar | 1cda0f5 | 2012-06-21 15:39:41 -0700 | [diff] [blame] | 664 | if (pdata->ccadc_pdata) { |
| 665 | ccadc_cell.platform_data = pdata->ccadc_pdata; |
| 666 | ccadc_cell.pdata_size = |
| 667 | sizeof(struct pm8xxx_ccadc_platform_data); |
| 668 | |
| 669 | ret = mfd_add_devices(pmic->dev, 0, &ccadc_cell, 1, NULL, |
| 670 | irq_base); |
| 671 | if (ret) { |
| 672 | pr_err("Failed to add ccadc subdevice ret=%d\n", ret); |
| 673 | goto bail; |
| 674 | } |
| 675 | } |
| 676 | |
Jay Chokshi | 9d36a3d | 2011-10-26 15:57:51 -0700 | [diff] [blame] | 677 | return 0; |
| 678 | bail: |
| 679 | if (pmic->irq_chip) { |
| 680 | pm8xxx_irq_exit(pmic->irq_chip); |
| 681 | pmic->irq_chip = NULL; |
| 682 | } |
| 683 | return ret; |
| 684 | } |
| 685 | |
Jay Chokshi | 9d36a3d | 2011-10-26 15:57:51 -0700 | [diff] [blame] | 686 | static const char * const pm8038_rev_names[] = { |
| 687 | [PM8XXX_REVISION_8038_TEST] = "test", |
| 688 | [PM8XXX_REVISION_8038_1p0] = "1.0", |
| 689 | [PM8XXX_REVISION_8038_2p0] = "2.0", |
| 690 | [PM8XXX_REVISION_8038_2p1] = "2.1", |
| 691 | }; |
| 692 | |
| 693 | static int __devinit pm8038_probe(struct platform_device *pdev) |
| 694 | { |
| 695 | const struct pm8038_platform_data *pdata = pdev->dev.platform_data; |
| 696 | const char *revision_name = "unknown"; |
| 697 | struct pm8038 *pmic; |
| 698 | enum pm8xxx_version version; |
| 699 | int revision; |
| 700 | int rc; |
| 701 | u8 val; |
| 702 | |
| 703 | if (!pdata) { |
| 704 | pr_err("missing platform data\n"); |
| 705 | return -EINVAL; |
| 706 | } |
| 707 | |
| 708 | pmic = kzalloc(sizeof(struct pm8038), GFP_KERNEL); |
| 709 | if (!pmic) { |
| 710 | pr_err("Cannot alloc pm8038 struct\n"); |
| 711 | return -ENOMEM; |
| 712 | } |
| 713 | |
| 714 | /* Read PMIC chip revision */ |
| 715 | rc = msm_ssbi_read(pdev->dev.parent, REG_HWREV, &val, sizeof(val)); |
| 716 | if (rc) { |
| 717 | pr_err("Failed to read hw rev reg %d:rc=%d\n", REG_HWREV, rc); |
| 718 | goto err_read_rev; |
| 719 | } |
| 720 | pr_info("PMIC revision 1: PM8038 rev %02X\n", val); |
| 721 | pmic->rev_registers = val; |
| 722 | |
| 723 | /* Read PMIC chip revision 2 */ |
| 724 | rc = msm_ssbi_read(pdev->dev.parent, REG_HWREV_2, &val, sizeof(val)); |
| 725 | if (rc) { |
| 726 | pr_err("Failed to read hw rev 2 reg %d:rc=%d\n", |
| 727 | REG_HWREV_2, rc); |
| 728 | goto err_read_rev; |
| 729 | } |
| 730 | pr_info("PMIC revision 2: PM8038 rev %02X\n", val); |
| 731 | pmic->rev_registers |= val << BITS_PER_BYTE; |
| 732 | |
| 733 | pmic->dev = &pdev->dev; |
| 734 | pm8038_drvdata.pm_chip_data = pmic; |
| 735 | platform_set_drvdata(pdev, &pm8038_drvdata); |
| 736 | |
| 737 | /* Print out human readable version and revision names. */ |
| 738 | version = pm8xxx_get_version(pmic->dev); |
| 739 | if (version == PM8XXX_VERSION_8038) { |
| 740 | revision = pm8xxx_get_revision(pmic->dev); |
| 741 | if (revision >= 0 && revision < ARRAY_SIZE(pm8038_rev_names)) |
| 742 | revision_name = pm8038_rev_names[revision]; |
| 743 | pr_info("PMIC version: PM8038 ver %s\n", revision_name); |
| 744 | } else { |
| 745 | WARN_ON(version != PM8XXX_VERSION_8038); |
| 746 | } |
| 747 | |
| 748 | /* Log human readable restart reason */ |
| 749 | rc = msm_ssbi_read(pdev->dev.parent, REG_PM8038_PON_CNTRL_3, &val, 1); |
| 750 | if (rc) { |
| 751 | pr_err("Cannot read restart reason rc=%d\n", rc); |
| 752 | goto err_read_rev; |
| 753 | } |
Abhijeet Dharmapurikar | a4ed55c | 2012-08-28 15:07:43 -0700 | [diff] [blame^] | 754 | val &= PM8XXX_RESTART_REASON_MASK; |
| 755 | pr_info("PMIC Restart Reason: %s\n", pm8xxx_restart_reason_str[val]); |
| 756 | pmic->restart_reason = val; |
Jay Chokshi | 9d36a3d | 2011-10-26 15:57:51 -0700 | [diff] [blame] | 757 | |
| 758 | rc = pm8038_add_subdevices(pdata, pmic); |
| 759 | if (rc) { |
| 760 | pr_err("Cannot add subdevices rc=%d\n", rc); |
| 761 | goto err; |
| 762 | } |
| 763 | |
| 764 | return 0; |
| 765 | |
| 766 | err: |
| 767 | mfd_remove_devices(pmic->dev); |
| 768 | platform_set_drvdata(pdev, NULL); |
David Collins | 045a76e | 2011-12-06 11:35:28 -0800 | [diff] [blame] | 769 | kfree(pmic->mfd_regulators); |
| 770 | kfree(pmic->regulator_cdata); |
Jay Chokshi | 9d36a3d | 2011-10-26 15:57:51 -0700 | [diff] [blame] | 771 | err_read_rev: |
| 772 | kfree(pmic); |
| 773 | return rc; |
| 774 | } |
| 775 | |
| 776 | static int __devexit pm8038_remove(struct platform_device *pdev) |
| 777 | { |
| 778 | struct pm8xxx_drvdata *drvdata; |
| 779 | struct pm8038 *pmic = NULL; |
David Collins | 045a76e | 2011-12-06 11:35:28 -0800 | [diff] [blame] | 780 | int i; |
Jay Chokshi | 9d36a3d | 2011-10-26 15:57:51 -0700 | [diff] [blame] | 781 | |
| 782 | drvdata = platform_get_drvdata(pdev); |
| 783 | |
| 784 | if (drvdata) |
| 785 | pmic = drvdata->pm_chip_data; |
| 786 | |
| 787 | if (pmic) { |
| 788 | if (pmic->dev) |
| 789 | mfd_remove_devices(pmic->dev); |
| 790 | |
| 791 | if (pmic->irq_chip) { |
| 792 | pm8xxx_irq_exit(pmic->irq_chip); |
| 793 | pmic->irq_chip = NULL; |
| 794 | } |
David Collins | 045a76e | 2011-12-06 11:35:28 -0800 | [diff] [blame] | 795 | if (pmic->mfd_regulators) { |
| 796 | for (i = 0; i < ARRAY_SIZE(regulator_data); i++) |
| 797 | mutex_destroy(®ulator_data[i].pc_lock); |
| 798 | } |
| 799 | kfree(pmic->mfd_regulators); |
| 800 | kfree(pmic->regulator_cdata); |
Jay Chokshi | 9d36a3d | 2011-10-26 15:57:51 -0700 | [diff] [blame] | 801 | kfree(pmic); |
| 802 | } |
| 803 | |
| 804 | platform_set_drvdata(pdev, NULL); |
| 805 | |
| 806 | return 0; |
| 807 | } |
| 808 | |
| 809 | static struct platform_driver pm8038_driver = { |
| 810 | .probe = pm8038_probe, |
| 811 | .remove = __devexit_p(pm8038_remove), |
| 812 | .driver = { |
| 813 | .name = PM8038_CORE_DEV_NAME, |
| 814 | .owner = THIS_MODULE, |
| 815 | }, |
| 816 | }; |
| 817 | |
| 818 | static int __init pm8038_init(void) |
| 819 | { |
| 820 | return platform_driver_register(&pm8038_driver); |
| 821 | } |
| 822 | postcore_initcall(pm8038_init); |
| 823 | |
| 824 | static void __exit pm8038_exit(void) |
| 825 | { |
| 826 | platform_driver_unregister(&pm8038_driver); |
| 827 | } |
| 828 | module_exit(pm8038_exit); |
| 829 | |
| 830 | MODULE_LICENSE("GPL v2"); |
| 831 | MODULE_DESCRIPTION("PMIC 8038 core driver"); |
| 832 | MODULE_VERSION("1.0"); |
| 833 | MODULE_ALIAS("platform:pm8038-core"); |