of: property: Make sure child dependencies don't block probing of parent
[linux/fpc-iii.git] / drivers / mfd / intel_soc_pmic_core.c
blobc9f35378d39180d2f966c6a2fb4510824c2c6cf0
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3 * Intel SoC PMIC MFD Driver
5 * Copyright (C) 2013, 2014 Intel Corporation. All rights reserved.
7 * Author: Yang, Bin <bin.yang@intel.com>
8 * Author: Zhu, Lejun <lejun.zhu@linux.intel.com>
9 */
11 #include <linux/acpi.h>
12 #include <linux/gpio/consumer.h>
13 #include <linux/gpio/machine.h>
14 #include <linux/i2c.h>
15 #include <linux/interrupt.h>
16 #include <linux/module.h>
17 #include <linux/mfd/core.h>
18 #include <linux/mfd/intel_soc_pmic.h>
19 #include <linux/pwm.h>
20 #include <linux/regmap.h>
22 #include "intel_soc_pmic_core.h"
24 /* Crystal Cove PMIC shares same ACPI ID between different platforms */
25 #define BYT_CRC_HRV 2
26 #define CHT_CRC_HRV 3
28 /* Lookup table for the Panel Enable/Disable line as GPIO signals */
29 static struct gpiod_lookup_table panel_gpio_table = {
30 /* Intel GFX is consumer */
31 .dev_id = "0000:00:02.0",
32 .table = {
33 /* Panel EN/DISABLE */
34 GPIO_LOOKUP("gpio_crystalcove", 94, "panel", GPIO_ACTIVE_HIGH),
35 { },
39 /* PWM consumed by the Intel GFX */
40 static struct pwm_lookup crc_pwm_lookup[] = {
41 PWM_LOOKUP("crystal_cove_pwm", 0, "0000:00:02.0", "pwm_backlight", 0, PWM_POLARITY_NORMAL),
44 static int intel_soc_pmic_i2c_probe(struct i2c_client *i2c,
45 const struct i2c_device_id *i2c_id)
47 struct device *dev = &i2c->dev;
48 struct intel_soc_pmic_config *config;
49 struct intel_soc_pmic *pmic;
50 unsigned long long hrv;
51 acpi_status status;
52 int ret;
55 * There are 2 different Crystal Cove PMICs a Bay Trail and Cherry
56 * Trail version, use _HRV to differentiate between the 2.
58 status = acpi_evaluate_integer(ACPI_HANDLE(dev), "_HRV", NULL, &hrv);
59 if (ACPI_FAILURE(status)) {
60 dev_err(dev, "Failed to get PMIC hardware revision\n");
61 return -ENODEV;
64 switch (hrv) {
65 case BYT_CRC_HRV:
66 config = &intel_soc_pmic_config_byt_crc;
67 break;
68 case CHT_CRC_HRV:
69 config = &intel_soc_pmic_config_cht_crc;
70 break;
71 default:
72 dev_warn(dev, "Unknown hardware rev %llu, assuming BYT\n", hrv);
73 config = &intel_soc_pmic_config_byt_crc;
76 pmic = devm_kzalloc(dev, sizeof(*pmic), GFP_KERNEL);
77 if (!pmic)
78 return -ENOMEM;
80 dev_set_drvdata(dev, pmic);
82 pmic->regmap = devm_regmap_init_i2c(i2c, config->regmap_config);
83 if (IS_ERR(pmic->regmap))
84 return PTR_ERR(pmic->regmap);
86 pmic->irq = i2c->irq;
88 ret = regmap_add_irq_chip(pmic->regmap, pmic->irq,
89 config->irq_flags | IRQF_ONESHOT,
90 0, config->irq_chip,
91 &pmic->irq_chip_data);
92 if (ret)
93 return ret;
95 ret = enable_irq_wake(pmic->irq);
96 if (ret)
97 dev_warn(dev, "Can't enable IRQ as wake source: %d\n", ret);
99 /* Add lookup table binding for Panel Control to the GPIO Chip */
100 gpiod_add_lookup_table(&panel_gpio_table);
102 /* Add lookup table for crc-pwm */
103 pwm_add_table(crc_pwm_lookup, ARRAY_SIZE(crc_pwm_lookup));
105 ret = mfd_add_devices(dev, -1, config->cell_dev,
106 config->n_cell_devs, NULL, 0,
107 regmap_irq_get_domain(pmic->irq_chip_data));
108 if (ret)
109 goto err_del_irq_chip;
111 return 0;
113 err_del_irq_chip:
114 regmap_del_irq_chip(pmic->irq, pmic->irq_chip_data);
115 return ret;
118 static int intel_soc_pmic_i2c_remove(struct i2c_client *i2c)
120 struct intel_soc_pmic *pmic = dev_get_drvdata(&i2c->dev);
122 regmap_del_irq_chip(pmic->irq, pmic->irq_chip_data);
124 /* Remove lookup table for Panel Control from the GPIO Chip */
125 gpiod_remove_lookup_table(&panel_gpio_table);
127 /* remove crc-pwm lookup table */
128 pwm_remove_table(crc_pwm_lookup, ARRAY_SIZE(crc_pwm_lookup));
130 mfd_remove_devices(&i2c->dev);
132 return 0;
135 static void intel_soc_pmic_shutdown(struct i2c_client *i2c)
137 struct intel_soc_pmic *pmic = dev_get_drvdata(&i2c->dev);
139 disable_irq(pmic->irq);
141 return;
144 #if defined(CONFIG_PM_SLEEP)
145 static int intel_soc_pmic_suspend(struct device *dev)
147 struct intel_soc_pmic *pmic = dev_get_drvdata(dev);
149 disable_irq(pmic->irq);
151 return 0;
154 static int intel_soc_pmic_resume(struct device *dev)
156 struct intel_soc_pmic *pmic = dev_get_drvdata(dev);
158 enable_irq(pmic->irq);
160 return 0;
162 #endif
164 static SIMPLE_DEV_PM_OPS(intel_soc_pmic_pm_ops, intel_soc_pmic_suspend,
165 intel_soc_pmic_resume);
167 static const struct i2c_device_id intel_soc_pmic_i2c_id[] = {
170 MODULE_DEVICE_TABLE(i2c, intel_soc_pmic_i2c_id);
172 #if defined(CONFIG_ACPI)
173 static const struct acpi_device_id intel_soc_pmic_acpi_match[] = {
174 { "INT33FD" },
175 { },
177 MODULE_DEVICE_TABLE(acpi, intel_soc_pmic_acpi_match);
178 #endif
180 static struct i2c_driver intel_soc_pmic_i2c_driver = {
181 .driver = {
182 .name = "intel_soc_pmic_i2c",
183 .pm = &intel_soc_pmic_pm_ops,
184 .acpi_match_table = ACPI_PTR(intel_soc_pmic_acpi_match),
186 .probe = intel_soc_pmic_i2c_probe,
187 .remove = intel_soc_pmic_i2c_remove,
188 .id_table = intel_soc_pmic_i2c_id,
189 .shutdown = intel_soc_pmic_shutdown,
192 module_i2c_driver(intel_soc_pmic_i2c_driver);
194 MODULE_DESCRIPTION("I2C driver for Intel SoC PMIC");
195 MODULE_LICENSE("GPL v2");
196 MODULE_AUTHOR("Yang, Bin <bin.yang@intel.com>");
197 MODULE_AUTHOR("Zhu, Lejun <lejun.zhu@linux.intel.com>");