1 // SPDX-License-Identifier: GPL-2.0
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>
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 */
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",
33 /* Panel EN/DISABLE */
34 GPIO_LOOKUP("gpio_crystalcove", 94, "panel", GPIO_ACTIVE_HIGH
),
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
;
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");
66 config
= &intel_soc_pmic_config_byt_crc
;
69 config
= &intel_soc_pmic_config_cht_crc
;
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
);
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
);
88 ret
= regmap_add_irq_chip(pmic
->regmap
, pmic
->irq
,
89 config
->irq_flags
| IRQF_ONESHOT
,
91 &pmic
->irq_chip_data
);
95 ret
= enable_irq_wake(pmic
->irq
);
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
));
109 goto err_del_irq_chip
;
114 regmap_del_irq_chip(pmic
->irq
, pmic
->irq_chip_data
);
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
);
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
);
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
);
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
);
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
[] = {
177 MODULE_DEVICE_TABLE(acpi
, intel_soc_pmic_acpi_match
);
180 static struct i2c_driver intel_soc_pmic_i2c_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>");