1 // SPDX-License-Identifier: GPL-2.0
3 * Intel SoC PMIC MFD Driver
5 * Copyright (C) 2013, 2014 Intel Corporation. All rights reserved.
11 #include <linux/acpi.h>
12 #include <linux/i2c.h>
13 #include <linux/interrupt.h>
14 #include <linux/module.h>
15 #include <linux/mfd/core.h>
16 #include <linux/mfd/intel_soc_pmic.h>
17 #include <linux/platform_data/x86/soc.h>
18 #include <linux/pwm.h>
19 #include <linux/regmap.h>
21 #include "intel_soc_pmic_core.h"
23 /* PWM consumed by the Intel GFX */
24 static struct pwm_lookup crc_pwm_lookup[] = {
25 PWM_LOOKUP("crystal_cove_pwm", 0, "0000:00:02.0", "pwm_pmic_backlight", 0, PWM_POLARITY_NORMAL),
28 static int intel_soc_pmic_i2c_probe(struct i2c_client *i2c,
29 const struct i2c_device_id *i2c_id)
31 struct device *dev = &i2c->dev;
32 struct intel_soc_pmic_config *config;
33 struct intel_soc_pmic *pmic;
36 if (soc_intel_is_byt())
37 config = &intel_soc_pmic_config_byt_crc;
39 config = &intel_soc_pmic_config_cht_crc;
41 pmic = devm_kzalloc(dev, sizeof(*pmic), GFP_KERNEL);
45 dev_set_drvdata(dev, pmic);
47 pmic->regmap = devm_regmap_init_i2c(i2c, config->regmap_config);
48 if (IS_ERR(pmic->regmap))
49 return PTR_ERR(pmic->regmap);
53 ret = regmap_add_irq_chip(pmic->regmap, pmic->irq,
54 config->irq_flags | IRQF_ONESHOT,
56 &pmic->irq_chip_data);
60 ret = enable_irq_wake(pmic->irq);
62 dev_warn(dev, "Can't enable IRQ as wake source: %d\n", ret);
64 /* Add lookup table for crc-pwm */
65 pwm_add_table(crc_pwm_lookup, ARRAY_SIZE(crc_pwm_lookup));
67 ret = mfd_add_devices(dev, -1, config->cell_dev,
68 config->n_cell_devs, NULL, 0,
69 regmap_irq_get_domain(pmic->irq_chip_data));
71 goto err_del_irq_chip;
76 regmap_del_irq_chip(pmic->irq, pmic->irq_chip_data);
80 static int intel_soc_pmic_i2c_remove(struct i2c_client *i2c)
82 struct intel_soc_pmic *pmic = dev_get_drvdata(&i2c->dev);
84 regmap_del_irq_chip(pmic->irq, pmic->irq_chip_data);
86 /* remove crc-pwm lookup table */
87 pwm_remove_table(crc_pwm_lookup, ARRAY_SIZE(crc_pwm_lookup));
89 mfd_remove_devices(&i2c->dev);
94 static void intel_soc_pmic_shutdown(struct i2c_client *i2c)
96 struct intel_soc_pmic *pmic = dev_get_drvdata(&i2c->dev);
98 disable_irq(pmic->irq);
103 #if defined(CONFIG_PM_SLEEP)
104 static int intel_soc_pmic_suspend(struct device *dev)
106 struct intel_soc_pmic *pmic = dev_get_drvdata(dev);
108 disable_irq(pmic->irq);
113 static int intel_soc_pmic_resume(struct device *dev)
115 struct intel_soc_pmic *pmic = dev_get_drvdata(dev);
117 enable_irq(pmic->irq);
123 static SIMPLE_DEV_PM_OPS(intel_soc_pmic_pm_ops, intel_soc_pmic_suspend,
124 intel_soc_pmic_resume);
126 static const struct i2c_device_id intel_soc_pmic_i2c_id[] = {
129 MODULE_DEVICE_TABLE(i2c, intel_soc_pmic_i2c_id);
131 #if defined(CONFIG_ACPI)
132 static const struct acpi_device_id intel_soc_pmic_acpi_match[] = {
136 MODULE_DEVICE_TABLE(acpi, intel_soc_pmic_acpi_match);
139 static struct i2c_driver intel_soc_pmic_i2c_driver = {
141 .name = "intel_soc_pmic_i2c",
142 .pm = &intel_soc_pmic_pm_ops,
143 .acpi_match_table = ACPI_PTR(intel_soc_pmic_acpi_match),
145 .probe = intel_soc_pmic_i2c_probe,
146 .remove = intel_soc_pmic_i2c_remove,
147 .id_table = intel_soc_pmic_i2c_id,
148 .shutdown = intel_soc_pmic_shutdown,
151 module_i2c_driver(intel_soc_pmic_i2c_driver);
153 MODULE_DESCRIPTION("I2C driver for Intel SoC PMIC");
154 MODULE_LICENSE("GPL v2");