2 * intel_soc_pmic_core.c - Intel SoC PMIC MFD Driver
4 * Copyright (C) 2013, 2014 Intel Corporation. All rights reserved.
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License version
8 * 2 as published by the Free Software Foundation.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * Author: Yang, Bin <bin.yang@intel.com>
16 * Author: Zhu, Lejun <lejun.zhu@linux.intel.com>
19 #include <linux/module.h>
20 #include <linux/mfd/core.h>
21 #include <linux/i2c.h>
22 #include <linux/interrupt.h>
23 #include <linux/gpio/consumer.h>
24 #include <linux/acpi.h>
25 #include <linux/regmap.h>
26 #include <linux/mfd/intel_soc_pmic.h>
27 #include <linux/gpio/machine.h>
28 #include <linux/pwm.h>
29 #include "intel_soc_pmic_core.h"
31 /* Lookup table for the Panel Enable/Disable line as GPIO signals */
32 static struct gpiod_lookup_table panel_gpio_table
= {
33 /* Intel GFX is consumer */
34 .dev_id
= "0000:00:02.0",
36 /* Panel EN/DISABLE */
37 GPIO_LOOKUP("gpio_crystalcove", 94, "panel", GPIO_ACTIVE_HIGH
),
42 /* PWM consumed by the Intel GFX */
43 static struct pwm_lookup crc_pwm_lookup
[] = {
44 PWM_LOOKUP("crystal_cove_pwm", 0, "0000:00:02.0", "pwm_backlight", 0, PWM_POLARITY_NORMAL
),
47 static int intel_soc_pmic_find_gpio_irq(struct device
*dev
)
49 struct gpio_desc
*desc
;
52 desc
= devm_gpiod_get_index(dev
, "intel_soc_pmic", 0, GPIOD_IN
);
56 irq
= gpiod_to_irq(desc
);
58 dev_warn(dev
, "Can't get irq: %d\n", irq
);
63 static int intel_soc_pmic_i2c_probe(struct i2c_client
*i2c
,
64 const struct i2c_device_id
*i2c_id
)
66 struct device
*dev
= &i2c
->dev
;
67 const struct acpi_device_id
*id
;
68 struct intel_soc_pmic_config
*config
;
69 struct intel_soc_pmic
*pmic
;
73 id
= acpi_match_device(dev
->driver
->acpi_match_table
, dev
);
74 if (!id
|| !id
->driver_data
)
77 config
= (struct intel_soc_pmic_config
*)id
->driver_data
;
79 pmic
= devm_kzalloc(dev
, sizeof(*pmic
), GFP_KERNEL
);
83 dev_set_drvdata(dev
, pmic
);
85 pmic
->regmap
= devm_regmap_init_i2c(i2c
, config
->regmap_config
);
88 * On some boards the PMIC interrupt may come from a GPIO line. Try to
89 * lookup the ACPI table for a such connection and setup a GPIO
90 * interrupt if it exists. Otherwise use the IRQ provided by I2C
92 irq
= intel_soc_pmic_find_gpio_irq(dev
);
93 pmic
->irq
= (irq
< 0) ? i2c
->irq
: irq
;
95 ret
= regmap_add_irq_chip(pmic
->regmap
, pmic
->irq
,
96 config
->irq_flags
| IRQF_ONESHOT
,
98 &pmic
->irq_chip_data
);
102 ret
= enable_irq_wake(pmic
->irq
);
104 dev_warn(dev
, "Can't enable IRQ as wake source: %d\n", ret
);
106 /* Add lookup table binding for Panel Control to the GPIO Chip */
107 gpiod_add_lookup_table(&panel_gpio_table
);
109 /* Add lookup table for crc-pwm */
110 pwm_add_table(crc_pwm_lookup
, ARRAY_SIZE(crc_pwm_lookup
));
112 ret
= mfd_add_devices(dev
, -1, config
->cell_dev
,
113 config
->n_cell_devs
, NULL
, 0,
114 regmap_irq_get_domain(pmic
->irq_chip_data
));
116 goto err_del_irq_chip
;
121 regmap_del_irq_chip(pmic
->irq
, pmic
->irq_chip_data
);
125 static int intel_soc_pmic_i2c_remove(struct i2c_client
*i2c
)
127 struct intel_soc_pmic
*pmic
= dev_get_drvdata(&i2c
->dev
);
129 regmap_del_irq_chip(pmic
->irq
, pmic
->irq_chip_data
);
131 /* Remove lookup table for Panel Control from the GPIO Chip */
132 gpiod_remove_lookup_table(&panel_gpio_table
);
134 /* remove crc-pwm lookup table */
135 pwm_remove_table(crc_pwm_lookup
, ARRAY_SIZE(crc_pwm_lookup
));
137 mfd_remove_devices(&i2c
->dev
);
142 static void intel_soc_pmic_shutdown(struct i2c_client
*i2c
)
144 struct intel_soc_pmic
*pmic
= dev_get_drvdata(&i2c
->dev
);
146 disable_irq(pmic
->irq
);
151 #if defined(CONFIG_PM_SLEEP)
152 static int intel_soc_pmic_suspend(struct device
*dev
)
154 struct intel_soc_pmic
*pmic
= dev_get_drvdata(dev
);
156 disable_irq(pmic
->irq
);
161 static int intel_soc_pmic_resume(struct device
*dev
)
163 struct intel_soc_pmic
*pmic
= dev_get_drvdata(dev
);
165 enable_irq(pmic
->irq
);
171 static SIMPLE_DEV_PM_OPS(intel_soc_pmic_pm_ops
, intel_soc_pmic_suspend
,
172 intel_soc_pmic_resume
);
174 static const struct i2c_device_id intel_soc_pmic_i2c_id
[] = {
177 MODULE_DEVICE_TABLE(i2c
, intel_soc_pmic_i2c_id
);
179 #if defined(CONFIG_ACPI)
180 static const struct acpi_device_id intel_soc_pmic_acpi_match
[] = {
181 {"INT33FD", (kernel_ulong_t
)&intel_soc_pmic_config_crc
},
184 MODULE_DEVICE_TABLE(acpi
, intel_soc_pmic_acpi_match
);
187 static struct i2c_driver intel_soc_pmic_i2c_driver
= {
189 .name
= "intel_soc_pmic_i2c",
190 .pm
= &intel_soc_pmic_pm_ops
,
191 .acpi_match_table
= ACPI_PTR(intel_soc_pmic_acpi_match
),
193 .probe
= intel_soc_pmic_i2c_probe
,
194 .remove
= intel_soc_pmic_i2c_remove
,
195 .id_table
= intel_soc_pmic_i2c_id
,
196 .shutdown
= intel_soc_pmic_shutdown
,
199 module_i2c_driver(intel_soc_pmic_i2c_driver
);
201 MODULE_DESCRIPTION("I2C driver for Intel SoC PMIC");
202 MODULE_LICENSE("GPL v2");
203 MODULE_AUTHOR("Yang, Bin <bin.yang@intel.com>");
204 MODULE_AUTHOR("Zhu, Lejun <lejun.zhu@linux.intel.com>");