intel_soc_pmic_core.c 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  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. #include <linux/module.h>
  19. #include <linux/mfd/core.h>
  20. #include <linux/i2c.h>
  21. #include <linux/interrupt.h>
  22. #include <linux/gpio/consumer.h>
  23. #include <linux/acpi.h>
  24. #include <linux/regmap.h>
  25. #include <linux/mfd/intel_soc_pmic.h>
  26. #include <linux/gpio/machine.h>
  27. #include <linux/pwm.h>
  28. #include "intel_soc_pmic_core.h"
  29. /* Crystal Cove PMIC shares same ACPI ID between different platforms */
  30. #define BYT_CRC_HRV 2
  31. #define CHT_CRC_HRV 3
  32. /* Lookup table for the Panel Enable/Disable line as GPIO signals */
  33. static struct gpiod_lookup_table panel_gpio_table = {
  34. /* Intel GFX is consumer */
  35. .dev_id = "0000:00:02.0",
  36. .table = {
  37. /* Panel EN/DISABLE */
  38. GPIO_LOOKUP("gpio_crystalcove", 94, "panel", GPIO_ACTIVE_HIGH),
  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. static int intel_soc_pmic_i2c_probe(struct i2c_client *i2c,
  47. const struct i2c_device_id *i2c_id)
  48. {
  49. struct device *dev = &i2c->dev;
  50. struct intel_soc_pmic_config *config;
  51. struct intel_soc_pmic *pmic;
  52. unsigned long long hrv;
  53. acpi_status status;
  54. int ret;
  55. /*
  56. * There are 2 different Crystal Cove PMICs a Bay Trail and Cherry
  57. * Trail version, use _HRV to differentiate between the 2.
  58. */
  59. status = acpi_evaluate_integer(ACPI_HANDLE(dev), "_HRV", NULL, &hrv);
  60. if (ACPI_FAILURE(status)) {
  61. dev_err(dev, "Failed to get PMIC hardware revision\n");
  62. return -ENODEV;
  63. }
  64. switch (hrv) {
  65. case BYT_CRC_HRV:
  66. config = &intel_soc_pmic_config_byt_crc;
  67. break;
  68. case CHT_CRC_HRV:
  69. config = &intel_soc_pmic_config_cht_crc;
  70. break;
  71. default:
  72. dev_warn(dev, "Unknown hardware rev %llu, assuming BYT\n", hrv);
  73. config = &intel_soc_pmic_config_byt_crc;
  74. }
  75. pmic = devm_kzalloc(dev, sizeof(*pmic), GFP_KERNEL);
  76. if (!pmic)
  77. return -ENOMEM;
  78. dev_set_drvdata(dev, pmic);
  79. pmic->regmap = devm_regmap_init_i2c(i2c, config->regmap_config);
  80. if (IS_ERR(pmic->regmap))
  81. return PTR_ERR(pmic->regmap);
  82. pmic->irq = i2c->irq;
  83. ret = regmap_add_irq_chip(pmic->regmap, pmic->irq,
  84. config->irq_flags | IRQF_ONESHOT,
  85. 0, config->irq_chip,
  86. &pmic->irq_chip_data);
  87. if (ret)
  88. return ret;
  89. ret = enable_irq_wake(pmic->irq);
  90. if (ret)
  91. dev_warn(dev, "Can't enable IRQ as wake source: %d\n", ret);
  92. /* Add lookup table binding for Panel Control to the GPIO Chip */
  93. gpiod_add_lookup_table(&panel_gpio_table);
  94. /* Add lookup table for crc-pwm */
  95. pwm_add_table(crc_pwm_lookup, ARRAY_SIZE(crc_pwm_lookup));
  96. ret = mfd_add_devices(dev, -1, config->cell_dev,
  97. config->n_cell_devs, NULL, 0,
  98. regmap_irq_get_domain(pmic->irq_chip_data));
  99. if (ret)
  100. goto err_del_irq_chip;
  101. return 0;
  102. err_del_irq_chip:
  103. regmap_del_irq_chip(pmic->irq, pmic->irq_chip_data);
  104. return ret;
  105. }
  106. static int intel_soc_pmic_i2c_remove(struct i2c_client *i2c)
  107. {
  108. struct intel_soc_pmic *pmic = dev_get_drvdata(&i2c->dev);
  109. regmap_del_irq_chip(pmic->irq, pmic->irq_chip_data);
  110. /* Remove lookup table for Panel Control from the GPIO Chip */
  111. gpiod_remove_lookup_table(&panel_gpio_table);
  112. /* remove crc-pwm lookup table */
  113. pwm_remove_table(crc_pwm_lookup, ARRAY_SIZE(crc_pwm_lookup));
  114. mfd_remove_devices(&i2c->dev);
  115. return 0;
  116. }
  117. static void intel_soc_pmic_shutdown(struct i2c_client *i2c)
  118. {
  119. struct intel_soc_pmic *pmic = dev_get_drvdata(&i2c->dev);
  120. disable_irq(pmic->irq);
  121. return;
  122. }
  123. #if defined(CONFIG_PM_SLEEP)
  124. static int intel_soc_pmic_suspend(struct device *dev)
  125. {
  126. struct intel_soc_pmic *pmic = dev_get_drvdata(dev);
  127. disable_irq(pmic->irq);
  128. return 0;
  129. }
  130. static int intel_soc_pmic_resume(struct device *dev)
  131. {
  132. struct intel_soc_pmic *pmic = dev_get_drvdata(dev);
  133. enable_irq(pmic->irq);
  134. return 0;
  135. }
  136. #endif
  137. static SIMPLE_DEV_PM_OPS(intel_soc_pmic_pm_ops, intel_soc_pmic_suspend,
  138. intel_soc_pmic_resume);
  139. static const struct i2c_device_id intel_soc_pmic_i2c_id[] = {
  140. { }
  141. };
  142. MODULE_DEVICE_TABLE(i2c, intel_soc_pmic_i2c_id);
  143. #if defined(CONFIG_ACPI)
  144. static const struct acpi_device_id intel_soc_pmic_acpi_match[] = {
  145. { "INT33FD" },
  146. { },
  147. };
  148. MODULE_DEVICE_TABLE(acpi, intel_soc_pmic_acpi_match);
  149. #endif
  150. static struct i2c_driver intel_soc_pmic_i2c_driver = {
  151. .driver = {
  152. .name = "intel_soc_pmic_i2c",
  153. .pm = &intel_soc_pmic_pm_ops,
  154. .acpi_match_table = ACPI_PTR(intel_soc_pmic_acpi_match),
  155. },
  156. .probe = intel_soc_pmic_i2c_probe,
  157. .remove = intel_soc_pmic_i2c_remove,
  158. .id_table = intel_soc_pmic_i2c_id,
  159. .shutdown = intel_soc_pmic_shutdown,
  160. };
  161. module_i2c_driver(intel_soc_pmic_i2c_driver);
  162. MODULE_DESCRIPTION("I2C driver for Intel SoC PMIC");
  163. MODULE_LICENSE("GPL v2");
  164. MODULE_AUTHOR("Yang, Bin <bin.yang@intel.com>");
  165. MODULE_AUTHOR("Zhu, Lejun <lejun.zhu@linux.intel.com>");