]> git.kernelconcepts.de Git - karo-tx-linux.git/blob - drivers/mfd/intel_soc_pmic_core.c
mtd: nand: atmel: Add ->setup_data_interface() hooks
[karo-tx-linux.git] / drivers / mfd / intel_soc_pmic_core.c
1 /*
2  * intel_soc_pmic_core.c - Intel SoC PMIC MFD Driver
3  *
4  * Copyright (C) 2013, 2014 Intel Corporation. All rights reserved.
5  *
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.
9  *
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.
14  *
15  * Author: Yang, Bin <bin.yang@intel.com>
16  * Author: Zhu, Lejun <lejun.zhu@linux.intel.com>
17  */
18
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"
30
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",
35         .table = {
36                 /* Panel EN/DISABLE */
37                 GPIO_LOOKUP("gpio_crystalcove", 94, "panel", GPIO_ACTIVE_HIGH),
38                 { },
39         },
40 };
41
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),
45 };
46
47 static int intel_soc_pmic_i2c_probe(struct i2c_client *i2c,
48                                     const struct i2c_device_id *i2c_id)
49 {
50         struct device *dev = &i2c->dev;
51         const struct acpi_device_id *id;
52         struct intel_soc_pmic_config *config;
53         struct intel_soc_pmic *pmic;
54         int ret;
55
56         id = acpi_match_device(dev->driver->acpi_match_table, dev);
57         if (!id || !id->driver_data)
58                 return -ENODEV;
59
60         config = (struct intel_soc_pmic_config *)id->driver_data;
61
62         pmic = devm_kzalloc(dev, sizeof(*pmic), GFP_KERNEL);
63         if (!pmic)
64                 return -ENOMEM;
65
66         dev_set_drvdata(dev, pmic);
67
68         pmic->regmap = devm_regmap_init_i2c(i2c, config->regmap_config);
69         if (IS_ERR(pmic->regmap))
70                 return PTR_ERR(pmic->regmap);
71
72         pmic->irq = i2c->irq;
73
74         ret = regmap_add_irq_chip(pmic->regmap, pmic->irq,
75                                   config->irq_flags | IRQF_ONESHOT,
76                                   0, config->irq_chip,
77                                   &pmic->irq_chip_data);
78         if (ret)
79                 return ret;
80
81         ret = enable_irq_wake(pmic->irq);
82         if (ret)
83                 dev_warn(dev, "Can't enable IRQ as wake source: %d\n", ret);
84
85         /* Add lookup table binding for Panel Control to the GPIO Chip */
86         gpiod_add_lookup_table(&panel_gpio_table);
87
88         /* Add lookup table for crc-pwm */
89         pwm_add_table(crc_pwm_lookup, ARRAY_SIZE(crc_pwm_lookup));
90
91         ret = mfd_add_devices(dev, -1, config->cell_dev,
92                               config->n_cell_devs, NULL, 0,
93                               regmap_irq_get_domain(pmic->irq_chip_data));
94         if (ret)
95                 goto err_del_irq_chip;
96
97         return 0;
98
99 err_del_irq_chip:
100         regmap_del_irq_chip(pmic->irq, pmic->irq_chip_data);
101         return ret;
102 }
103
104 static int intel_soc_pmic_i2c_remove(struct i2c_client *i2c)
105 {
106         struct intel_soc_pmic *pmic = dev_get_drvdata(&i2c->dev);
107
108         regmap_del_irq_chip(pmic->irq, pmic->irq_chip_data);
109
110         /* Remove lookup table for Panel Control from the GPIO Chip */
111         gpiod_remove_lookup_table(&panel_gpio_table);
112
113         /* remove crc-pwm lookup table */
114         pwm_remove_table(crc_pwm_lookup, ARRAY_SIZE(crc_pwm_lookup));
115
116         mfd_remove_devices(&i2c->dev);
117
118         return 0;
119 }
120
121 static void intel_soc_pmic_shutdown(struct i2c_client *i2c)
122 {
123         struct intel_soc_pmic *pmic = dev_get_drvdata(&i2c->dev);
124
125         disable_irq(pmic->irq);
126
127         return;
128 }
129
130 #if defined(CONFIG_PM_SLEEP)
131 static int intel_soc_pmic_suspend(struct device *dev)
132 {
133         struct intel_soc_pmic *pmic = dev_get_drvdata(dev);
134
135         disable_irq(pmic->irq);
136
137         return 0;
138 }
139
140 static int intel_soc_pmic_resume(struct device *dev)
141 {
142         struct intel_soc_pmic *pmic = dev_get_drvdata(dev);
143
144         enable_irq(pmic->irq);
145
146         return 0;
147 }
148 #endif
149
150 static SIMPLE_DEV_PM_OPS(intel_soc_pmic_pm_ops, intel_soc_pmic_suspend,
151                          intel_soc_pmic_resume);
152
153 static const struct i2c_device_id intel_soc_pmic_i2c_id[] = {
154         { }
155 };
156 MODULE_DEVICE_TABLE(i2c, intel_soc_pmic_i2c_id);
157
158 #if defined(CONFIG_ACPI)
159 static const struct acpi_device_id intel_soc_pmic_acpi_match[] = {
160         {"INT33FD", (kernel_ulong_t)&intel_soc_pmic_config_crc},
161         { },
162 };
163 MODULE_DEVICE_TABLE(acpi, intel_soc_pmic_acpi_match);
164 #endif
165
166 static struct i2c_driver intel_soc_pmic_i2c_driver = {
167         .driver = {
168                 .name = "intel_soc_pmic_i2c",
169                 .pm = &intel_soc_pmic_pm_ops,
170                 .acpi_match_table = ACPI_PTR(intel_soc_pmic_acpi_match),
171         },
172         .probe = intel_soc_pmic_i2c_probe,
173         .remove = intel_soc_pmic_i2c_remove,
174         .id_table = intel_soc_pmic_i2c_id,
175         .shutdown = intel_soc_pmic_shutdown,
176 };
177
178 module_i2c_driver(intel_soc_pmic_i2c_driver);
179
180 MODULE_DESCRIPTION("I2C driver for Intel SoC PMIC");
181 MODULE_LICENSE("GPL v2");
182 MODULE_AUTHOR("Yang, Bin <bin.yang@intel.com>");
183 MODULE_AUTHOR("Zhu, Lejun <lejun.zhu@linux.intel.com>");