intel_soc_pmic_bxtwc.c 15 KB

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