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