intel_soc_pmic_core.c (3948B)
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 <bin.yang@intel.com> 8 * Author: Zhu, Lejun <lejun.zhu@linux.intel.com> 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 */ 24static 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 28static 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 /* To distuingish this domain from the GPIO/charger's irqchip domains */ 68 irq_domain_update_bus_token(regmap_irq_get_domain(pmic->irq_chip_data), 69 DOMAIN_BUS_NEXUS); 70 71 ret = mfd_add_devices(dev, -1, config->cell_dev, 72 config->n_cell_devs, NULL, 0, 73 regmap_irq_get_domain(pmic->irq_chip_data)); 74 if (ret) 75 goto err_del_irq_chip; 76 77 return 0; 78 79err_del_irq_chip: 80 regmap_del_irq_chip(pmic->irq, pmic->irq_chip_data); 81 return ret; 82} 83 84static int intel_soc_pmic_i2c_remove(struct i2c_client *i2c) 85{ 86 struct intel_soc_pmic *pmic = dev_get_drvdata(&i2c->dev); 87 88 regmap_del_irq_chip(pmic->irq, pmic->irq_chip_data); 89 90 /* remove crc-pwm lookup table */ 91 pwm_remove_table(crc_pwm_lookup, ARRAY_SIZE(crc_pwm_lookup)); 92 93 mfd_remove_devices(&i2c->dev); 94 95 return 0; 96} 97 98static void intel_soc_pmic_shutdown(struct i2c_client *i2c) 99{ 100 struct intel_soc_pmic *pmic = dev_get_drvdata(&i2c->dev); 101 102 disable_irq(pmic->irq); 103 104 return; 105} 106 107#if defined(CONFIG_PM_SLEEP) 108static int intel_soc_pmic_suspend(struct device *dev) 109{ 110 struct intel_soc_pmic *pmic = dev_get_drvdata(dev); 111 112 disable_irq(pmic->irq); 113 114 return 0; 115} 116 117static int intel_soc_pmic_resume(struct device *dev) 118{ 119 struct intel_soc_pmic *pmic = dev_get_drvdata(dev); 120 121 enable_irq(pmic->irq); 122 123 return 0; 124} 125#endif 126 127static SIMPLE_DEV_PM_OPS(intel_soc_pmic_pm_ops, intel_soc_pmic_suspend, 128 intel_soc_pmic_resume); 129 130static const struct i2c_device_id intel_soc_pmic_i2c_id[] = { 131 { } 132}; 133MODULE_DEVICE_TABLE(i2c, intel_soc_pmic_i2c_id); 134 135#if defined(CONFIG_ACPI) 136static const struct acpi_device_id intel_soc_pmic_acpi_match[] = { 137 { "INT33FD" }, 138 { }, 139}; 140MODULE_DEVICE_TABLE(acpi, intel_soc_pmic_acpi_match); 141#endif 142 143static struct i2c_driver intel_soc_pmic_i2c_driver = { 144 .driver = { 145 .name = "intel_soc_pmic_i2c", 146 .pm = &intel_soc_pmic_pm_ops, 147 .acpi_match_table = ACPI_PTR(intel_soc_pmic_acpi_match), 148 }, 149 .probe = intel_soc_pmic_i2c_probe, 150 .remove = intel_soc_pmic_i2c_remove, 151 .id_table = intel_soc_pmic_i2c_id, 152 .shutdown = intel_soc_pmic_shutdown, 153}; 154 155module_i2c_driver(intel_soc_pmic_i2c_driver); 156 157MODULE_DESCRIPTION("I2C driver for Intel SoC PMIC"); 158MODULE_LICENSE("GPL v2"); 159MODULE_AUTHOR("Yang, Bin <bin.yang@intel.com>"); 160MODULE_AUTHOR("Zhu, Lejun <lejun.zhu@linux.intel.com>");