0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011 #include <linux/acpi.h>
0012 #include <linux/i2c.h>
0013 #include <linux/interrupt.h>
0014 #include <linux/module.h>
0015 #include <linux/mfd/core.h>
0016 #include <linux/mfd/intel_soc_pmic.h>
0017 #include <linux/platform_data/x86/soc.h>
0018 #include <linux/pwm.h>
0019 #include <linux/regmap.h>
0020
0021 #include "intel_soc_pmic_core.h"
0022
0023
0024 static struct pwm_lookup crc_pwm_lookup[] = {
0025 PWM_LOOKUP("crystal_cove_pwm", 0, "0000:00:02.0", "pwm_pmic_backlight", 0, PWM_POLARITY_NORMAL),
0026 };
0027
0028 static int intel_soc_pmic_i2c_probe(struct i2c_client *i2c,
0029 const struct i2c_device_id *i2c_id)
0030 {
0031 struct device *dev = &i2c->dev;
0032 struct intel_soc_pmic_config *config;
0033 struct intel_soc_pmic *pmic;
0034 int ret;
0035
0036 if (soc_intel_is_byt())
0037 config = &intel_soc_pmic_config_byt_crc;
0038 else
0039 config = &intel_soc_pmic_config_cht_crc;
0040
0041 pmic = devm_kzalloc(dev, sizeof(*pmic), GFP_KERNEL);
0042 if (!pmic)
0043 return -ENOMEM;
0044
0045 dev_set_drvdata(dev, pmic);
0046
0047 pmic->regmap = devm_regmap_init_i2c(i2c, config->regmap_config);
0048 if (IS_ERR(pmic->regmap))
0049 return PTR_ERR(pmic->regmap);
0050
0051 pmic->irq = i2c->irq;
0052
0053 ret = regmap_add_irq_chip(pmic->regmap, pmic->irq,
0054 config->irq_flags | IRQF_ONESHOT,
0055 0, config->irq_chip,
0056 &pmic->irq_chip_data);
0057 if (ret)
0058 return ret;
0059
0060 ret = enable_irq_wake(pmic->irq);
0061 if (ret)
0062 dev_warn(dev, "Can't enable IRQ as wake source: %d\n", ret);
0063
0064
0065 pwm_add_table(crc_pwm_lookup, ARRAY_SIZE(crc_pwm_lookup));
0066
0067
0068 irq_domain_update_bus_token(regmap_irq_get_domain(pmic->irq_chip_data),
0069 DOMAIN_BUS_NEXUS);
0070
0071 ret = mfd_add_devices(dev, -1, config->cell_dev,
0072 config->n_cell_devs, NULL, 0,
0073 regmap_irq_get_domain(pmic->irq_chip_data));
0074 if (ret)
0075 goto err_del_irq_chip;
0076
0077 return 0;
0078
0079 err_del_irq_chip:
0080 regmap_del_irq_chip(pmic->irq, pmic->irq_chip_data);
0081 return ret;
0082 }
0083
0084 static int intel_soc_pmic_i2c_remove(struct i2c_client *i2c)
0085 {
0086 struct intel_soc_pmic *pmic = dev_get_drvdata(&i2c->dev);
0087
0088 regmap_del_irq_chip(pmic->irq, pmic->irq_chip_data);
0089
0090
0091 pwm_remove_table(crc_pwm_lookup, ARRAY_SIZE(crc_pwm_lookup));
0092
0093 mfd_remove_devices(&i2c->dev);
0094
0095 return 0;
0096 }
0097
0098 static void intel_soc_pmic_shutdown(struct i2c_client *i2c)
0099 {
0100 struct intel_soc_pmic *pmic = dev_get_drvdata(&i2c->dev);
0101
0102 disable_irq(pmic->irq);
0103
0104 return;
0105 }
0106
0107 #if defined(CONFIG_PM_SLEEP)
0108 static int intel_soc_pmic_suspend(struct device *dev)
0109 {
0110 struct intel_soc_pmic *pmic = dev_get_drvdata(dev);
0111
0112 disable_irq(pmic->irq);
0113
0114 return 0;
0115 }
0116
0117 static int intel_soc_pmic_resume(struct device *dev)
0118 {
0119 struct intel_soc_pmic *pmic = dev_get_drvdata(dev);
0120
0121 enable_irq(pmic->irq);
0122
0123 return 0;
0124 }
0125 #endif
0126
0127 static SIMPLE_DEV_PM_OPS(intel_soc_pmic_pm_ops, intel_soc_pmic_suspend,
0128 intel_soc_pmic_resume);
0129
0130 static const struct i2c_device_id intel_soc_pmic_i2c_id[] = {
0131 { }
0132 };
0133 MODULE_DEVICE_TABLE(i2c, intel_soc_pmic_i2c_id);
0134
0135 #if defined(CONFIG_ACPI)
0136 static const struct acpi_device_id intel_soc_pmic_acpi_match[] = {
0137 { "INT33FD" },
0138 { },
0139 };
0140 MODULE_DEVICE_TABLE(acpi, intel_soc_pmic_acpi_match);
0141 #endif
0142
0143 static struct i2c_driver intel_soc_pmic_i2c_driver = {
0144 .driver = {
0145 .name = "intel_soc_pmic_i2c",
0146 .pm = &intel_soc_pmic_pm_ops,
0147 .acpi_match_table = ACPI_PTR(intel_soc_pmic_acpi_match),
0148 },
0149 .probe = intel_soc_pmic_i2c_probe,
0150 .remove = intel_soc_pmic_i2c_remove,
0151 .id_table = intel_soc_pmic_i2c_id,
0152 .shutdown = intel_soc_pmic_shutdown,
0153 };
0154
0155 module_i2c_driver(intel_soc_pmic_i2c_driver);
0156
0157 MODULE_DESCRIPTION("I2C driver for Intel SoC PMIC");
0158 MODULE_LICENSE("GPL v2");
0159 MODULE_AUTHOR("Yang, Bin <bin.yang@intel.com>");
0160 MODULE_AUTHOR("Zhu, Lejun <lejun.zhu@linux.intel.com>");