arizona-i2c.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Arizona-i2c.c -- Arizona I2C bus interface
  4. *
  5. * Copyright 2012 Wolfson Microelectronics plc
  6. *
  7. * Author: Mark Brown <[email protected]>
  8. */
  9. #include <linux/err.h>
  10. #include <linux/i2c.h>
  11. #include <linux/module.h>
  12. #include <linux/pm_runtime.h>
  13. #include <linux/regmap.h>
  14. #include <linux/regulator/consumer.h>
  15. #include <linux/slab.h>
  16. #include <linux/of.h>
  17. #include <linux/mfd/arizona/core.h>
  18. #include "arizona.h"
  19. static int arizona_i2c_probe(struct i2c_client *i2c,
  20. const struct i2c_device_id *id)
  21. {
  22. const void *match_data;
  23. struct arizona *arizona;
  24. const struct regmap_config *regmap_config = NULL;
  25. unsigned long type = 0;
  26. int ret;
  27. match_data = device_get_match_data(&i2c->dev);
  28. if (match_data)
  29. type = (unsigned long)match_data;
  30. else if (id)
  31. type = id->driver_data;
  32. switch (type) {
  33. case WM5102:
  34. if (IS_ENABLED(CONFIG_MFD_WM5102))
  35. regmap_config = &wm5102_i2c_regmap;
  36. break;
  37. case WM5110:
  38. case WM8280:
  39. if (IS_ENABLED(CONFIG_MFD_WM5110))
  40. regmap_config = &wm5110_i2c_regmap;
  41. break;
  42. case WM8997:
  43. if (IS_ENABLED(CONFIG_MFD_WM8997))
  44. regmap_config = &wm8997_i2c_regmap;
  45. break;
  46. case WM8998:
  47. case WM1814:
  48. if (IS_ENABLED(CONFIG_MFD_WM8998))
  49. regmap_config = &wm8998_i2c_regmap;
  50. break;
  51. default:
  52. dev_err(&i2c->dev, "Unknown device type %ld\n", type);
  53. return -EINVAL;
  54. }
  55. if (!regmap_config) {
  56. dev_err(&i2c->dev,
  57. "No kernel support for device type %ld\n", type);
  58. return -EINVAL;
  59. }
  60. arizona = devm_kzalloc(&i2c->dev, sizeof(*arizona), GFP_KERNEL);
  61. if (arizona == NULL)
  62. return -ENOMEM;
  63. arizona->regmap = devm_regmap_init_i2c(i2c, regmap_config);
  64. if (IS_ERR(arizona->regmap)) {
  65. ret = PTR_ERR(arizona->regmap);
  66. dev_err(&i2c->dev, "Failed to allocate register map: %d\n",
  67. ret);
  68. return ret;
  69. }
  70. arizona->type = type;
  71. arizona->dev = &i2c->dev;
  72. arizona->irq = i2c->irq;
  73. return arizona_dev_init(arizona);
  74. }
  75. static void arizona_i2c_remove(struct i2c_client *i2c)
  76. {
  77. struct arizona *arizona = dev_get_drvdata(&i2c->dev);
  78. arizona_dev_exit(arizona);
  79. }
  80. static const struct i2c_device_id arizona_i2c_id[] = {
  81. { "wm5102", WM5102 },
  82. { "wm5110", WM5110 },
  83. { "wm8280", WM8280 },
  84. { "wm8997", WM8997 },
  85. { "wm8998", WM8998 },
  86. { "wm1814", WM1814 },
  87. { }
  88. };
  89. MODULE_DEVICE_TABLE(i2c, arizona_i2c_id);
  90. #ifdef CONFIG_OF
  91. static const struct of_device_id arizona_i2c_of_match[] = {
  92. { .compatible = "wlf,wm5102", .data = (void *)WM5102 },
  93. { .compatible = "wlf,wm5110", .data = (void *)WM5110 },
  94. { .compatible = "wlf,wm8280", .data = (void *)WM8280 },
  95. { .compatible = "wlf,wm8997", .data = (void *)WM8997 },
  96. { .compatible = "wlf,wm8998", .data = (void *)WM8998 },
  97. { .compatible = "wlf,wm1814", .data = (void *)WM1814 },
  98. {},
  99. };
  100. #endif
  101. static struct i2c_driver arizona_i2c_driver = {
  102. .driver = {
  103. .name = "arizona",
  104. .pm = &arizona_pm_ops,
  105. .of_match_table = of_match_ptr(arizona_i2c_of_match),
  106. },
  107. .probe = arizona_i2c_probe,
  108. .remove = arizona_i2c_remove,
  109. .id_table = arizona_i2c_id,
  110. };
  111. module_i2c_driver(arizona_i2c_driver);
  112. MODULE_SOFTDEP("pre: arizona_ldo1");
  113. MODULE_DESCRIPTION("Arizona I2C bus interface");
  114. MODULE_AUTHOR("Mark Brown <[email protected]>");
  115. MODULE_LICENSE("GPL");