]> Git Repo - linux.git/blob - drivers/mfd/intel_soc_pmic_core.c
RISC-V: Improve /proc/cpuinfo output for ISA extensions
[linux.git] / drivers / mfd / intel_soc_pmic_core.c
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3  * Intel SoC PMIC MFD Driver
4  *
5  * Copyright (C) 2013, 2014 Intel Corporation. All rights reserved.
6  *
7  * Author: Yang, Bin <[email protected]>
8  * Author: Zhu, Lejun <[email protected]>
9  */
10
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>
20
21 #include "intel_soc_pmic_core.h"
22
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),
26 };
27
28 static int intel_soc_pmic_i2c_probe(struct i2c_client *i2c,
29                                     const struct i2c_device_id *i2c_id)
30 {
31         struct device *dev = &i2c->dev;
32         struct intel_soc_pmic_config *config;
33         struct intel_soc_pmic *pmic;
34         int ret;
35
36         if (soc_intel_is_byt())
37                 config = &intel_soc_pmic_config_byt_crc;
38         else
39                 config = &intel_soc_pmic_config_cht_crc;
40
41         pmic = devm_kzalloc(dev, sizeof(*pmic), GFP_KERNEL);
42         if (!pmic)
43                 return -ENOMEM;
44
45         dev_set_drvdata(dev, pmic);
46
47         pmic->regmap = devm_regmap_init_i2c(i2c, config->regmap_config);
48         if (IS_ERR(pmic->regmap))
49                 return PTR_ERR(pmic->regmap);
50
51         pmic->irq = i2c->irq;
52
53         ret = regmap_add_irq_chip(pmic->regmap, pmic->irq,
54                                   config->irq_flags | IRQF_ONESHOT,
55                                   0, config->irq_chip,
56                                   &pmic->irq_chip_data);
57         if (ret)
58                 return ret;
59
60         ret = enable_irq_wake(pmic->irq);
61         if (ret)
62                 dev_warn(dev, "Can't enable IRQ as wake source: %d\n", ret);
63
64         /* Add lookup table for crc-pwm */
65         pwm_add_table(crc_pwm_lookup, ARRAY_SIZE(crc_pwm_lookup));
66
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));
70         if (ret)
71                 goto err_del_irq_chip;
72
73         return 0;
74
75 err_del_irq_chip:
76         regmap_del_irq_chip(pmic->irq, pmic->irq_chip_data);
77         return ret;
78 }
79
80 static int intel_soc_pmic_i2c_remove(struct i2c_client *i2c)
81 {
82         struct intel_soc_pmic *pmic = dev_get_drvdata(&i2c->dev);
83
84         regmap_del_irq_chip(pmic->irq, pmic->irq_chip_data);
85
86         /* remove crc-pwm lookup table */
87         pwm_remove_table(crc_pwm_lookup, ARRAY_SIZE(crc_pwm_lookup));
88
89         mfd_remove_devices(&i2c->dev);
90
91         return 0;
92 }
93
94 static void intel_soc_pmic_shutdown(struct i2c_client *i2c)
95 {
96         struct intel_soc_pmic *pmic = dev_get_drvdata(&i2c->dev);
97
98         disable_irq(pmic->irq);
99
100         return;
101 }
102
103 #if defined(CONFIG_PM_SLEEP)
104 static int intel_soc_pmic_suspend(struct device *dev)
105 {
106         struct intel_soc_pmic *pmic = dev_get_drvdata(dev);
107
108         disable_irq(pmic->irq);
109
110         return 0;
111 }
112
113 static int intel_soc_pmic_resume(struct device *dev)
114 {
115         struct intel_soc_pmic *pmic = dev_get_drvdata(dev);
116
117         enable_irq(pmic->irq);
118
119         return 0;
120 }
121 #endif
122
123 static SIMPLE_DEV_PM_OPS(intel_soc_pmic_pm_ops, intel_soc_pmic_suspend,
124                          intel_soc_pmic_resume);
125
126 static const struct i2c_device_id intel_soc_pmic_i2c_id[] = {
127         { }
128 };
129 MODULE_DEVICE_TABLE(i2c, intel_soc_pmic_i2c_id);
130
131 #if defined(CONFIG_ACPI)
132 static const struct acpi_device_id intel_soc_pmic_acpi_match[] = {
133         { "INT33FD" },
134         { },
135 };
136 MODULE_DEVICE_TABLE(acpi, intel_soc_pmic_acpi_match);
137 #endif
138
139 static struct i2c_driver intel_soc_pmic_i2c_driver = {
140         .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),
144         },
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,
149 };
150
151 module_i2c_driver(intel_soc_pmic_i2c_driver);
152
153 MODULE_DESCRIPTION("I2C driver for Intel SoC PMIC");
154 MODULE_LICENSE("GPL v2");
155 MODULE_AUTHOR("Yang, Bin <[email protected]>");
156 MODULE_AUTHOR("Zhu, Lejun <[email protected]>");
This page took 0.041516 seconds and 4 git commands to generate.