Qipeng Zha | 39d047c | 2015-09-15 00:39:19 +0800 | [diff] [blame] | 1 | /* |
| 2 | * MFD core driver for Intel Broxton Whiskey Cove PMIC |
| 3 | * |
| 4 | * Copyright (C) 2015 Intel Corporation. All rights reserved. |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify it |
| 7 | * under the terms and conditions of the GNU General Public License, |
| 8 | * version 2, as published by the Free Software Foundation. |
| 9 | * |
| 10 | * This program is distributed in the hope it will be useful, but WITHOUT |
| 11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
| 13 | * more details. |
| 14 | */ |
| 15 | |
| 16 | #include <linux/module.h> |
| 17 | #include <linux/acpi.h> |
| 18 | #include <linux/err.h> |
| 19 | #include <linux/delay.h> |
| 20 | #include <linux/interrupt.h> |
| 21 | #include <linux/kernel.h> |
| 22 | #include <linux/mfd/core.h> |
Andy Shevchenko | f1e34ad | 2017-03-17 17:37:14 +0200 | [diff] [blame] | 23 | #include <linux/mfd/intel_soc_pmic.h> |
Andy Shevchenko | 0c227c5 | 2017-03-17 17:37:15 +0200 | [diff] [blame] | 24 | #include <linux/mfd/intel_soc_pmic_bxtwc.h> |
Qipeng Zha | 39d047c | 2015-09-15 00:39:19 +0800 | [diff] [blame] | 25 | #include <asm/intel_pmc_ipc.h> |
| 26 | |
| 27 | /* PMIC device registers */ |
| 28 | #define REG_ADDR_MASK 0xFF00 |
| 29 | #define REG_ADDR_SHIFT 8 |
| 30 | #define REG_OFFSET_MASK 0xFF |
| 31 | |
| 32 | /* Interrupt Status Registers */ |
| 33 | #define BXTWC_IRQLVL1 0x4E02 |
| 34 | #define BXTWC_PWRBTNIRQ 0x4E03 |
| 35 | |
| 36 | #define BXTWC_THRM0IRQ 0x4E04 |
| 37 | #define BXTWC_THRM1IRQ 0x4E05 |
| 38 | #define BXTWC_THRM2IRQ 0x4E06 |
| 39 | #define BXTWC_BCUIRQ 0x4E07 |
| 40 | #define BXTWC_ADCIRQ 0x4E08 |
| 41 | #define BXTWC_CHGR0IRQ 0x4E09 |
| 42 | #define BXTWC_CHGR1IRQ 0x4E0A |
| 43 | #define BXTWC_GPIOIRQ0 0x4E0B |
| 44 | #define BXTWC_GPIOIRQ1 0x4E0C |
| 45 | #define BXTWC_CRITIRQ 0x4E0D |
Nilesh Bacchewar | 957ae50 | 2016-11-07 12:11:47 -0800 | [diff] [blame] | 46 | #define BXTWC_TMUIRQ 0x4FB6 |
Qipeng Zha | 39d047c | 2015-09-15 00:39:19 +0800 | [diff] [blame] | 47 | |
| 48 | /* Interrupt MASK Registers */ |
| 49 | #define BXTWC_MIRQLVL1 0x4E0E |
| 50 | #define BXTWC_MPWRTNIRQ 0x4E0F |
| 51 | |
Bin Gao | 9c6235c | 2016-07-20 17:33:56 -0700 | [diff] [blame] | 52 | #define BXTWC_MIRQLVL1_MCHGR BIT(5) |
| 53 | |
Qipeng Zha | 39d047c | 2015-09-15 00:39:19 +0800 | [diff] [blame] | 54 | #define BXTWC_MTHRM0IRQ 0x4E12 |
| 55 | #define BXTWC_MTHRM1IRQ 0x4E13 |
| 56 | #define BXTWC_MTHRM2IRQ 0x4E14 |
| 57 | #define BXTWC_MBCUIRQ 0x4E15 |
| 58 | #define BXTWC_MADCIRQ 0x4E16 |
| 59 | #define BXTWC_MCHGR0IRQ 0x4E17 |
| 60 | #define BXTWC_MCHGR1IRQ 0x4E18 |
| 61 | #define BXTWC_MGPIO0IRQ 0x4E19 |
| 62 | #define BXTWC_MGPIO1IRQ 0x4E1A |
| 63 | #define BXTWC_MCRITIRQ 0x4E1B |
Nilesh Bacchewar | 957ae50 | 2016-11-07 12:11:47 -0800 | [diff] [blame] | 64 | #define BXTWC_MTMUIRQ 0x4FB7 |
Qipeng Zha | 39d047c | 2015-09-15 00:39:19 +0800 | [diff] [blame] | 65 | |
| 66 | /* Whiskey Cove PMIC share same ACPI ID between different platforms */ |
| 67 | #define BROXTON_PMIC_WC_HRV 4 |
| 68 | |
| 69 | /* Manage in two IRQ chips since mask registers are not consecutive */ |
| 70 | enum bxtwc_irqs { |
| 71 | /* Level 1 */ |
| 72 | BXTWC_PWRBTN_LVL1_IRQ = 0, |
| 73 | BXTWC_TMU_LVL1_IRQ, |
| 74 | BXTWC_THRM_LVL1_IRQ, |
| 75 | BXTWC_BCU_LVL1_IRQ, |
| 76 | BXTWC_ADC_LVL1_IRQ, |
| 77 | BXTWC_CHGR_LVL1_IRQ, |
| 78 | BXTWC_GPIO_LVL1_IRQ, |
| 79 | BXTWC_CRIT_LVL1_IRQ, |
| 80 | |
| 81 | /* Level 2 */ |
| 82 | BXTWC_PWRBTN_IRQ, |
| 83 | }; |
| 84 | |
| 85 | enum bxtwc_irqs_level2 { |
| 86 | /* Level 2 */ |
Kuppuswamy Sathyanarayanan | c494963 | 2017-06-05 12:08:02 -0700 | [diff] [blame] | 87 | BXTWC_BCU_IRQ = 0, |
Qipeng Zha | 39d047c | 2015-09-15 00:39:19 +0800 | [diff] [blame] | 88 | BXTWC_ADC_IRQ, |
Heikki Krogerus | 96007020 | 2016-10-17 10:32:13 +0300 | [diff] [blame] | 89 | BXTWC_USBC_IRQ, |
Qipeng Zha | 39d047c | 2015-09-15 00:39:19 +0800 | [diff] [blame] | 90 | BXTWC_CHGR0_IRQ, |
| 91 | BXTWC_CHGR1_IRQ, |
Qipeng Zha | 39d047c | 2015-09-15 00:39:19 +0800 | [diff] [blame] | 92 | BXTWC_CRIT_IRQ, |
Kuppuswamy Sathyanarayanan | 4533d85 | 2017-06-05 12:08:01 -0700 | [diff] [blame] | 93 | }; |
| 94 | |
| 95 | enum bxtwc_irqs_tmu { |
| 96 | BXTWC_TMU_IRQ = 0, |
Qipeng Zha | 39d047c | 2015-09-15 00:39:19 +0800 | [diff] [blame] | 97 | }; |
| 98 | |
| 99 | static const struct regmap_irq bxtwc_regmap_irqs[] = { |
| 100 | REGMAP_IRQ_REG(BXTWC_PWRBTN_LVL1_IRQ, 0, BIT(0)), |
| 101 | REGMAP_IRQ_REG(BXTWC_TMU_LVL1_IRQ, 0, BIT(1)), |
| 102 | REGMAP_IRQ_REG(BXTWC_THRM_LVL1_IRQ, 0, BIT(2)), |
| 103 | REGMAP_IRQ_REG(BXTWC_BCU_LVL1_IRQ, 0, BIT(3)), |
| 104 | REGMAP_IRQ_REG(BXTWC_ADC_LVL1_IRQ, 0, BIT(4)), |
| 105 | REGMAP_IRQ_REG(BXTWC_CHGR_LVL1_IRQ, 0, BIT(5)), |
| 106 | REGMAP_IRQ_REG(BXTWC_GPIO_LVL1_IRQ, 0, BIT(6)), |
| 107 | REGMAP_IRQ_REG(BXTWC_CRIT_LVL1_IRQ, 0, BIT(7)), |
| 108 | REGMAP_IRQ_REG(BXTWC_PWRBTN_IRQ, 1, 0x03), |
| 109 | }; |
| 110 | |
| 111 | static const struct regmap_irq bxtwc_regmap_irqs_level2[] = { |
Kuppuswamy Sathyanarayanan | c494963 | 2017-06-05 12:08:02 -0700 | [diff] [blame] | 112 | REGMAP_IRQ_REG(BXTWC_BCU_IRQ, 0, 0x1f), |
| 113 | REGMAP_IRQ_REG(BXTWC_ADC_IRQ, 1, 0xff), |
| 114 | REGMAP_IRQ_REG(BXTWC_USBC_IRQ, 2, BIT(5)), |
| 115 | REGMAP_IRQ_REG(BXTWC_CHGR0_IRQ, 2, 0x1f), |
| 116 | REGMAP_IRQ_REG(BXTWC_CHGR1_IRQ, 3, 0x1f), |
Kuppuswamy Sathyanarayanan | c494963 | 2017-06-05 12:08:02 -0700 | [diff] [blame] | 117 | REGMAP_IRQ_REG(BXTWC_CRIT_IRQ, 6, 0x03), |
Qipeng Zha | 39d047c | 2015-09-15 00:39:19 +0800 | [diff] [blame] | 118 | }; |
| 119 | |
Nilesh Bacchewar | 957ae50 | 2016-11-07 12:11:47 -0800 | [diff] [blame] | 120 | static const struct regmap_irq bxtwc_regmap_irqs_tmu[] = { |
| 121 | REGMAP_IRQ_REG(BXTWC_TMU_IRQ, 0, 0x06), |
| 122 | }; |
| 123 | |
Qipeng Zha | 39d047c | 2015-09-15 00:39:19 +0800 | [diff] [blame] | 124 | static struct regmap_irq_chip bxtwc_regmap_irq_chip = { |
| 125 | .name = "bxtwc_irq_chip", |
| 126 | .status_base = BXTWC_IRQLVL1, |
| 127 | .mask_base = BXTWC_MIRQLVL1, |
| 128 | .irqs = bxtwc_regmap_irqs, |
| 129 | .num_irqs = ARRAY_SIZE(bxtwc_regmap_irqs), |
| 130 | .num_regs = 2, |
| 131 | }; |
| 132 | |
| 133 | static struct regmap_irq_chip bxtwc_regmap_irq_chip_level2 = { |
| 134 | .name = "bxtwc_irq_chip_level2", |
Kuppuswamy Sathyanarayanan | c494963 | 2017-06-05 12:08:02 -0700 | [diff] [blame] | 135 | .status_base = BXTWC_BCUIRQ, |
| 136 | .mask_base = BXTWC_MBCUIRQ, |
Qipeng Zha | 39d047c | 2015-09-15 00:39:19 +0800 | [diff] [blame] | 137 | .irqs = bxtwc_regmap_irqs_level2, |
| 138 | .num_irqs = ARRAY_SIZE(bxtwc_regmap_irqs_level2), |
| 139 | .num_regs = 10, |
| 140 | }; |
| 141 | |
Nilesh Bacchewar | 957ae50 | 2016-11-07 12:11:47 -0800 | [diff] [blame] | 142 | static struct regmap_irq_chip bxtwc_regmap_irq_chip_tmu = { |
| 143 | .name = "bxtwc_irq_chip_tmu", |
| 144 | .status_base = BXTWC_TMUIRQ, |
| 145 | .mask_base = BXTWC_MTMUIRQ, |
| 146 | .irqs = bxtwc_regmap_irqs_tmu, |
| 147 | .num_irqs = ARRAY_SIZE(bxtwc_regmap_irqs_tmu), |
| 148 | .num_regs = 1, |
| 149 | }; |
| 150 | |
Qipeng Zha | 39d047c | 2015-09-15 00:39:19 +0800 | [diff] [blame] | 151 | static struct resource gpio_resources[] = { |
Kuppuswamy Sathyanarayanan | a1d28c59 | 2017-06-05 12:08:03 -0700 | [diff] [blame] | 152 | DEFINE_RES_IRQ_NAMED(BXTWC_GPIO_LVL1_IRQ, "GPIO"), |
Qipeng Zha | 39d047c | 2015-09-15 00:39:19 +0800 | [diff] [blame] | 153 | }; |
| 154 | |
| 155 | static struct resource adc_resources[] = { |
| 156 | DEFINE_RES_IRQ_NAMED(BXTWC_ADC_IRQ, "ADC"), |
| 157 | }; |
| 158 | |
Bin Gao | 9c6235c | 2016-07-20 17:33:56 -0700 | [diff] [blame] | 159 | static struct resource usbc_resources[] = { |
Heikki Krogerus | 96007020 | 2016-10-17 10:32:13 +0300 | [diff] [blame] | 160 | DEFINE_RES_IRQ(BXTWC_USBC_IRQ), |
Bin Gao | 9c6235c | 2016-07-20 17:33:56 -0700 | [diff] [blame] | 161 | }; |
| 162 | |
Qipeng Zha | 39d047c | 2015-09-15 00:39:19 +0800 | [diff] [blame] | 163 | static struct resource charger_resources[] = { |
| 164 | DEFINE_RES_IRQ_NAMED(BXTWC_CHGR0_IRQ, "CHARGER"), |
| 165 | DEFINE_RES_IRQ_NAMED(BXTWC_CHGR1_IRQ, "CHARGER1"), |
| 166 | }; |
| 167 | |
| 168 | static struct resource thermal_resources[] = { |
Kuppuswamy Sathyanarayanan | c494963 | 2017-06-05 12:08:02 -0700 | [diff] [blame] | 169 | DEFINE_RES_IRQ(BXTWC_THRM_LVL1_IRQ), |
Qipeng Zha | 39d047c | 2015-09-15 00:39:19 +0800 | [diff] [blame] | 170 | }; |
| 171 | |
| 172 | static struct resource bcu_resources[] = { |
| 173 | DEFINE_RES_IRQ_NAMED(BXTWC_BCU_IRQ, "BCU"), |
| 174 | }; |
| 175 | |
Nilesh Bacchewar | 957ae50 | 2016-11-07 12:11:47 -0800 | [diff] [blame] | 176 | static struct resource tmu_resources[] = { |
| 177 | DEFINE_RES_IRQ_NAMED(BXTWC_TMU_IRQ, "TMU"), |
| 178 | }; |
| 179 | |
Qipeng Zha | 39d047c | 2015-09-15 00:39:19 +0800 | [diff] [blame] | 180 | static struct mfd_cell bxt_wc_dev[] = { |
| 181 | { |
| 182 | .name = "bxt_wcove_gpadc", |
| 183 | .num_resources = ARRAY_SIZE(adc_resources), |
| 184 | .resources = adc_resources, |
| 185 | }, |
| 186 | { |
| 187 | .name = "bxt_wcove_thermal", |
| 188 | .num_resources = ARRAY_SIZE(thermal_resources), |
| 189 | .resources = thermal_resources, |
| 190 | }, |
| 191 | { |
Bin Gao | 9c6235c | 2016-07-20 17:33:56 -0700 | [diff] [blame] | 192 | .name = "bxt_wcove_usbc", |
| 193 | .num_resources = ARRAY_SIZE(usbc_resources), |
| 194 | .resources = usbc_resources, |
| 195 | }, |
| 196 | { |
Qipeng Zha | 39d047c | 2015-09-15 00:39:19 +0800 | [diff] [blame] | 197 | .name = "bxt_wcove_ext_charger", |
| 198 | .num_resources = ARRAY_SIZE(charger_resources), |
| 199 | .resources = charger_resources, |
| 200 | }, |
| 201 | { |
| 202 | .name = "bxt_wcove_bcu", |
| 203 | .num_resources = ARRAY_SIZE(bcu_resources), |
| 204 | .resources = bcu_resources, |
| 205 | }, |
| 206 | { |
Nilesh Bacchewar | 957ae50 | 2016-11-07 12:11:47 -0800 | [diff] [blame] | 207 | .name = "bxt_wcove_tmu", |
| 208 | .num_resources = ARRAY_SIZE(tmu_resources), |
| 209 | .resources = tmu_resources, |
| 210 | }, |
| 211 | |
| 212 | { |
Qipeng Zha | 39d047c | 2015-09-15 00:39:19 +0800 | [diff] [blame] | 213 | .name = "bxt_wcove_gpio", |
| 214 | .num_resources = ARRAY_SIZE(gpio_resources), |
| 215 | .resources = gpio_resources, |
| 216 | }, |
| 217 | { |
| 218 | .name = "bxt_wcove_region", |
| 219 | }, |
| 220 | }; |
| 221 | |
| 222 | static int regmap_ipc_byte_reg_read(void *context, unsigned int reg, |
| 223 | unsigned int *val) |
| 224 | { |
| 225 | int ret; |
| 226 | int i2c_addr; |
| 227 | u8 ipc_in[2]; |
| 228 | u8 ipc_out[4]; |
| 229 | struct intel_soc_pmic *pmic = context; |
| 230 | |
Kuppuswamy Sathyanarayanan | b4ccc4d | 2017-03-30 16:35:40 -0700 | [diff] [blame] | 231 | if (!pmic) |
| 232 | return -EINVAL; |
| 233 | |
Qipeng Zha | 39d047c | 2015-09-15 00:39:19 +0800 | [diff] [blame] | 234 | if (reg & REG_ADDR_MASK) |
| 235 | i2c_addr = (reg & REG_ADDR_MASK) >> REG_ADDR_SHIFT; |
Kuppuswamy Sathyanarayanan | b4ccc4d | 2017-03-30 16:35:40 -0700 | [diff] [blame] | 236 | else |
Qipeng Zha | 39d047c | 2015-09-15 00:39:19 +0800 | [diff] [blame] | 237 | i2c_addr = BXTWC_DEVICE1_ADDR; |
Kuppuswamy Sathyanarayanan | b4ccc4d | 2017-03-30 16:35:40 -0700 | [diff] [blame] | 238 | |
Qipeng Zha | 39d047c | 2015-09-15 00:39:19 +0800 | [diff] [blame] | 239 | reg &= REG_OFFSET_MASK; |
| 240 | |
| 241 | ipc_in[0] = reg; |
| 242 | ipc_in[1] = i2c_addr; |
| 243 | ret = intel_pmc_ipc_command(PMC_IPC_PMIC_ACCESS, |
| 244 | PMC_IPC_PMIC_ACCESS_READ, |
| 245 | ipc_in, sizeof(ipc_in), (u32 *)ipc_out, 1); |
| 246 | if (ret) { |
| 247 | dev_err(pmic->dev, "Failed to read from PMIC\n"); |
| 248 | return ret; |
| 249 | } |
| 250 | *val = ipc_out[0]; |
| 251 | |
| 252 | return 0; |
| 253 | } |
| 254 | |
| 255 | static int regmap_ipc_byte_reg_write(void *context, unsigned int reg, |
| 256 | unsigned int val) |
| 257 | { |
| 258 | int ret; |
| 259 | int i2c_addr; |
| 260 | u8 ipc_in[3]; |
| 261 | struct intel_soc_pmic *pmic = context; |
| 262 | |
Kuppuswamy Sathyanarayanan | b4ccc4d | 2017-03-30 16:35:40 -0700 | [diff] [blame] | 263 | if (!pmic) |
| 264 | return -EINVAL; |
| 265 | |
Qipeng Zha | 39d047c | 2015-09-15 00:39:19 +0800 | [diff] [blame] | 266 | if (reg & REG_ADDR_MASK) |
| 267 | i2c_addr = (reg & REG_ADDR_MASK) >> REG_ADDR_SHIFT; |
Kuppuswamy Sathyanarayanan | b4ccc4d | 2017-03-30 16:35:40 -0700 | [diff] [blame] | 268 | else |
Qipeng Zha | 39d047c | 2015-09-15 00:39:19 +0800 | [diff] [blame] | 269 | i2c_addr = BXTWC_DEVICE1_ADDR; |
Kuppuswamy Sathyanarayanan | b4ccc4d | 2017-03-30 16:35:40 -0700 | [diff] [blame] | 270 | |
Qipeng Zha | 39d047c | 2015-09-15 00:39:19 +0800 | [diff] [blame] | 271 | reg &= REG_OFFSET_MASK; |
| 272 | |
| 273 | ipc_in[0] = reg; |
| 274 | ipc_in[1] = i2c_addr; |
| 275 | ipc_in[2] = val; |
| 276 | ret = intel_pmc_ipc_command(PMC_IPC_PMIC_ACCESS, |
| 277 | PMC_IPC_PMIC_ACCESS_WRITE, |
| 278 | ipc_in, sizeof(ipc_in), NULL, 0); |
| 279 | if (ret) { |
| 280 | dev_err(pmic->dev, "Failed to write to PMIC\n"); |
| 281 | return ret; |
| 282 | } |
| 283 | |
| 284 | return 0; |
| 285 | } |
| 286 | |
| 287 | /* sysfs interfaces to r/w PMIC registers, required by initial script */ |
| 288 | static unsigned long bxtwc_reg_addr; |
| 289 | static ssize_t bxtwc_reg_show(struct device *dev, |
| 290 | struct device_attribute *attr, char *buf) |
| 291 | { |
| 292 | return sprintf(buf, "0x%lx\n", bxtwc_reg_addr); |
| 293 | } |
| 294 | |
| 295 | static ssize_t bxtwc_reg_store(struct device *dev, |
| 296 | struct device_attribute *attr, const char *buf, size_t count) |
| 297 | { |
| 298 | if (kstrtoul(buf, 0, &bxtwc_reg_addr)) { |
| 299 | dev_err(dev, "Invalid register address\n"); |
| 300 | return -EINVAL; |
| 301 | } |
| 302 | return (ssize_t)count; |
| 303 | } |
| 304 | |
| 305 | static ssize_t bxtwc_val_show(struct device *dev, |
| 306 | struct device_attribute *attr, char *buf) |
| 307 | { |
| 308 | int ret; |
| 309 | unsigned int val; |
| 310 | struct intel_soc_pmic *pmic = dev_get_drvdata(dev); |
| 311 | |
| 312 | ret = regmap_read(pmic->regmap, bxtwc_reg_addr, &val); |
| 313 | if (ret < 0) { |
| 314 | dev_err(dev, "Failed to read 0x%lx\n", bxtwc_reg_addr); |
| 315 | return -EIO; |
| 316 | } |
| 317 | |
| 318 | return sprintf(buf, "0x%02x\n", val); |
| 319 | } |
| 320 | |
| 321 | static ssize_t bxtwc_val_store(struct device *dev, |
| 322 | struct device_attribute *attr, const char *buf, size_t count) |
| 323 | { |
| 324 | int ret; |
| 325 | unsigned int val; |
| 326 | struct intel_soc_pmic *pmic = dev_get_drvdata(dev); |
| 327 | |
Dan Carpenter | f3a654c | 2015-09-28 12:56:36 +0300 | [diff] [blame] | 328 | ret = kstrtouint(buf, 0, &val); |
| 329 | if (ret) |
| 330 | return ret; |
Qipeng Zha | 39d047c | 2015-09-15 00:39:19 +0800 | [diff] [blame] | 331 | |
| 332 | ret = regmap_write(pmic->regmap, bxtwc_reg_addr, val); |
| 333 | if (ret) { |
| 334 | dev_err(dev, "Failed to write value 0x%02x to address 0x%lx", |
| 335 | val, bxtwc_reg_addr); |
| 336 | return -EIO; |
| 337 | } |
| 338 | return count; |
| 339 | } |
| 340 | |
| 341 | static DEVICE_ATTR(addr, S_IWUSR | S_IRUSR, bxtwc_reg_show, bxtwc_reg_store); |
| 342 | static DEVICE_ATTR(val, S_IWUSR | S_IRUSR, bxtwc_val_show, bxtwc_val_store); |
| 343 | static struct attribute *bxtwc_attrs[] = { |
| 344 | &dev_attr_addr.attr, |
| 345 | &dev_attr_val.attr, |
| 346 | NULL |
| 347 | }; |
| 348 | |
| 349 | static const struct attribute_group bxtwc_group = { |
| 350 | .attrs = bxtwc_attrs, |
| 351 | }; |
| 352 | |
| 353 | static const struct regmap_config bxtwc_regmap_config = { |
| 354 | .reg_bits = 16, |
| 355 | .val_bits = 8, |
| 356 | .reg_write = regmap_ipc_byte_reg_write, |
| 357 | .reg_read = regmap_ipc_byte_reg_read, |
| 358 | }; |
| 359 | |
| 360 | static int bxtwc_probe(struct platform_device *pdev) |
| 361 | { |
| 362 | int ret; |
| 363 | acpi_handle handle; |
| 364 | acpi_status status; |
| 365 | unsigned long long hrv; |
| 366 | struct intel_soc_pmic *pmic; |
| 367 | |
| 368 | handle = ACPI_HANDLE(&pdev->dev); |
| 369 | status = acpi_evaluate_integer(handle, "_HRV", NULL, &hrv); |
| 370 | if (ACPI_FAILURE(status)) { |
| 371 | dev_err(&pdev->dev, "Failed to get PMIC hardware revision\n"); |
| 372 | return -ENODEV; |
| 373 | } |
| 374 | if (hrv != BROXTON_PMIC_WC_HRV) { |
| 375 | dev_err(&pdev->dev, "Invalid PMIC hardware revision: %llu\n", |
| 376 | hrv); |
| 377 | return -ENODEV; |
| 378 | } |
| 379 | |
| 380 | pmic = devm_kzalloc(&pdev->dev, sizeof(*pmic), GFP_KERNEL); |
| 381 | if (!pmic) |
| 382 | return -ENOMEM; |
| 383 | |
| 384 | ret = platform_get_irq(pdev, 0); |
| 385 | if (ret < 0) { |
| 386 | dev_err(&pdev->dev, "Invalid IRQ\n"); |
| 387 | return ret; |
| 388 | } |
| 389 | pmic->irq = ret; |
| 390 | |
| 391 | dev_set_drvdata(&pdev->dev, pmic); |
| 392 | pmic->dev = &pdev->dev; |
| 393 | |
| 394 | pmic->regmap = devm_regmap_init(&pdev->dev, NULL, pmic, |
| 395 | &bxtwc_regmap_config); |
| 396 | if (IS_ERR(pmic->regmap)) { |
| 397 | ret = PTR_ERR(pmic->regmap); |
| 398 | dev_err(&pdev->dev, "Failed to initialise regmap: %d\n", ret); |
| 399 | return ret; |
| 400 | } |
| 401 | |
Kuppuswamy Sathyanarayanan | 5131f07 | 2017-06-05 12:08:04 -0700 | [diff] [blame^] | 402 | ret = devm_regmap_add_irq_chip(&pdev->dev, pmic->regmap, pmic->irq, |
| 403 | IRQF_ONESHOT | IRQF_SHARED, |
| 404 | 0, &bxtwc_regmap_irq_chip, |
| 405 | &pmic->irq_chip_data); |
Qipeng Zha | 39d047c | 2015-09-15 00:39:19 +0800 | [diff] [blame] | 406 | if (ret) { |
| 407 | dev_err(&pdev->dev, "Failed to add IRQ chip\n"); |
| 408 | return ret; |
| 409 | } |
| 410 | |
Kuppuswamy Sathyanarayanan | 5131f07 | 2017-06-05 12:08:04 -0700 | [diff] [blame^] | 411 | ret = devm_regmap_add_irq_chip(&pdev->dev, pmic->regmap, pmic->irq, |
| 412 | IRQF_ONESHOT | IRQF_SHARED, |
| 413 | 0, &bxtwc_regmap_irq_chip_level2, |
| 414 | &pmic->irq_chip_data_level2); |
Qipeng Zha | 39d047c | 2015-09-15 00:39:19 +0800 | [diff] [blame] | 415 | if (ret) { |
| 416 | dev_err(&pdev->dev, "Failed to add secondary IRQ chip\n"); |
Kuppuswamy Sathyanarayanan | 5131f07 | 2017-06-05 12:08:04 -0700 | [diff] [blame^] | 417 | return ret; |
Qipeng Zha | 39d047c | 2015-09-15 00:39:19 +0800 | [diff] [blame] | 418 | } |
| 419 | |
Kuppuswamy Sathyanarayanan | 5131f07 | 2017-06-05 12:08:04 -0700 | [diff] [blame^] | 420 | ret = devm_regmap_add_irq_chip(&pdev->dev, pmic->regmap, pmic->irq, |
| 421 | IRQF_ONESHOT | IRQF_SHARED, |
| 422 | 0, &bxtwc_regmap_irq_chip_tmu, |
| 423 | &pmic->irq_chip_data_tmu); |
Nilesh Bacchewar | 957ae50 | 2016-11-07 12:11:47 -0800 | [diff] [blame] | 424 | if (ret) { |
| 425 | dev_err(&pdev->dev, "Failed to add TMU IRQ chip\n"); |
Kuppuswamy Sathyanarayanan | 5131f07 | 2017-06-05 12:08:04 -0700 | [diff] [blame^] | 426 | return ret; |
Nilesh Bacchewar | 957ae50 | 2016-11-07 12:11:47 -0800 | [diff] [blame] | 427 | } |
| 428 | |
Kuppuswamy Sathyanarayanan | 5131f07 | 2017-06-05 12:08:04 -0700 | [diff] [blame^] | 429 | ret = devm_mfd_add_devices(&pdev->dev, PLATFORM_DEVID_NONE, bxt_wc_dev, |
| 430 | ARRAY_SIZE(bxt_wc_dev), NULL, 0, NULL); |
Qipeng Zha | 39d047c | 2015-09-15 00:39:19 +0800 | [diff] [blame] | 431 | if (ret) { |
| 432 | dev_err(&pdev->dev, "Failed to add devices\n"); |
Kuppuswamy Sathyanarayanan | 5131f07 | 2017-06-05 12:08:04 -0700 | [diff] [blame^] | 433 | return ret; |
Qipeng Zha | 39d047c | 2015-09-15 00:39:19 +0800 | [diff] [blame] | 434 | } |
| 435 | |
| 436 | ret = sysfs_create_group(&pdev->dev.kobj, &bxtwc_group); |
| 437 | if (ret) { |
| 438 | dev_err(&pdev->dev, "Failed to create sysfs group %d\n", ret); |
Kuppuswamy Sathyanarayanan | 5131f07 | 2017-06-05 12:08:04 -0700 | [diff] [blame^] | 439 | return ret; |
Qipeng Zha | 39d047c | 2015-09-15 00:39:19 +0800 | [diff] [blame] | 440 | } |
| 441 | |
Bin Gao | 9c6235c | 2016-07-20 17:33:56 -0700 | [diff] [blame] | 442 | /* |
| 443 | * There is known hw bug. Upon reset BIT 5 of register |
| 444 | * BXTWC_CHGR_LVL1_IRQ is 0 which is the expected value. However, |
| 445 | * later it's set to 1(masked) automatically by hardware. So we |
| 446 | * have the software workaround here to unmaksed it in order to let |
| 447 | * charger interrutp work. |
| 448 | */ |
| 449 | regmap_update_bits(pmic->regmap, BXTWC_MIRQLVL1, |
| 450 | BXTWC_MIRQLVL1_MCHGR, 0); |
| 451 | |
Qipeng Zha | 39d047c | 2015-09-15 00:39:19 +0800 | [diff] [blame] | 452 | return 0; |
Qipeng Zha | 39d047c | 2015-09-15 00:39:19 +0800 | [diff] [blame] | 453 | } |
| 454 | |
| 455 | static int bxtwc_remove(struct platform_device *pdev) |
| 456 | { |
Qipeng Zha | 39d047c | 2015-09-15 00:39:19 +0800 | [diff] [blame] | 457 | sysfs_remove_group(&pdev->dev.kobj, &bxtwc_group); |
Qipeng Zha | 39d047c | 2015-09-15 00:39:19 +0800 | [diff] [blame] | 458 | |
| 459 | return 0; |
| 460 | } |
| 461 | |
| 462 | static void bxtwc_shutdown(struct platform_device *pdev) |
| 463 | { |
| 464 | struct intel_soc_pmic *pmic = dev_get_drvdata(&pdev->dev); |
| 465 | |
| 466 | disable_irq(pmic->irq); |
| 467 | } |
| 468 | |
| 469 | #ifdef CONFIG_PM_SLEEP |
| 470 | static int bxtwc_suspend(struct device *dev) |
| 471 | { |
| 472 | struct intel_soc_pmic *pmic = dev_get_drvdata(dev); |
| 473 | |
| 474 | disable_irq(pmic->irq); |
| 475 | |
| 476 | return 0; |
| 477 | } |
| 478 | |
| 479 | static int bxtwc_resume(struct device *dev) |
| 480 | { |
| 481 | struct intel_soc_pmic *pmic = dev_get_drvdata(dev); |
| 482 | |
| 483 | enable_irq(pmic->irq); |
| 484 | return 0; |
| 485 | } |
| 486 | #endif |
| 487 | static SIMPLE_DEV_PM_OPS(bxtwc_pm_ops, bxtwc_suspend, bxtwc_resume); |
| 488 | |
| 489 | static const struct acpi_device_id bxtwc_acpi_ids[] = { |
| 490 | { "INT34D3", }, |
| 491 | { } |
| 492 | }; |
Wei Yongjun | f57576e | 2016-11-01 15:59:50 +0000 | [diff] [blame] | 493 | MODULE_DEVICE_TABLE(acpi, bxtwc_acpi_ids); |
Qipeng Zha | 39d047c | 2015-09-15 00:39:19 +0800 | [diff] [blame] | 494 | |
| 495 | static struct platform_driver bxtwc_driver = { |
| 496 | .probe = bxtwc_probe, |
| 497 | .remove = bxtwc_remove, |
| 498 | .shutdown = bxtwc_shutdown, |
| 499 | .driver = { |
| 500 | .name = "BXTWC PMIC", |
| 501 | .pm = &bxtwc_pm_ops, |
| 502 | .acpi_match_table = ACPI_PTR(bxtwc_acpi_ids), |
| 503 | }, |
| 504 | }; |
| 505 | |
| 506 | module_platform_driver(bxtwc_driver); |
| 507 | |
| 508 | MODULE_LICENSE("GPL v2"); |
| 509 | MODULE_AUTHOR("Qipeng Zha<qipeng.zha@intel.com>"); |