arizona-i2c.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. /*
  2. * Arizona-i2c.c -- Arizona I2C bus interface
  3. *
  4. * Copyright 2012 Wolfson Microelectronics plc
  5. *
  6. * Author: Mark Brown <broonie@opensource.wolfsonmicro.com>
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License version 2 as
  10. * published by the Free Software Foundation.
  11. */
  12. #include <linux/err.h>
  13. #include <linux/i2c.h>
  14. #include <linux/module.h>
  15. #include <linux/pm_runtime.h>
  16. #include <linux/regmap.h>
  17. #include <linux/regulator/consumer.h>
  18. #include <linux/slab.h>
  19. #include <linux/of.h>
  20. #include <linux/mfd/arizona/core.h>
  21. #include "arizona.h"
  22. static int arizona_i2c_probe(struct i2c_client *i2c,
  23. const struct i2c_device_id *id)
  24. {
  25. struct arizona *arizona;
  26. const struct regmap_config *regmap_config = NULL;
  27. unsigned long type;
  28. int ret;
  29. if (i2c->dev.of_node)
  30. type = arizona_of_get_type(&i2c->dev);
  31. else
  32. type = id->driver_data;
  33. switch (type) {
  34. case WM5102:
  35. if (IS_ENABLED(CONFIG_MFD_WM5102))
  36. regmap_config = &wm5102_i2c_regmap;
  37. break;
  38. case WM5110:
  39. case WM8280:
  40. if (IS_ENABLED(CONFIG_MFD_WM5110))
  41. regmap_config = &wm5110_i2c_regmap;
  42. break;
  43. case WM8997:
  44. if (IS_ENABLED(CONFIG_MFD_WM8997))
  45. regmap_config = &wm8997_i2c_regmap;
  46. break;
  47. case WM8998:
  48. case WM1814:
  49. if (IS_ENABLED(CONFIG_MFD_WM8998))
  50. regmap_config = &wm8998_i2c_regmap;
  51. break;
  52. default:
  53. dev_err(&i2c->dev, "Unknown device type %ld\n", type);
  54. return -EINVAL;
  55. }
  56. if (!regmap_config) {
  57. dev_err(&i2c->dev,
  58. "No kernel support for device type %ld\n", type);
  59. return -EINVAL;
  60. }
  61. arizona = devm_kzalloc(&i2c->dev, sizeof(*arizona), GFP_KERNEL);
  62. if (arizona == NULL)
  63. return -ENOMEM;
  64. arizona->regmap = devm_regmap_init_i2c(i2c, regmap_config);
  65. if (IS_ERR(arizona->regmap)) {
  66. ret = PTR_ERR(arizona->regmap);
  67. dev_err(&i2c->dev, "Failed to allocate register map: %d\n",
  68. ret);
  69. return ret;
  70. }
  71. arizona->type = type;
  72. arizona->dev = &i2c->dev;
  73. arizona->irq = i2c->irq;
  74. return arizona_dev_init(arizona);
  75. }
  76. static int arizona_i2c_remove(struct i2c_client *i2c)
  77. {
  78. struct arizona *arizona = dev_get_drvdata(&i2c->dev);
  79. arizona_dev_exit(arizona);
  80. return 0;
  81. }
  82. static const struct i2c_device_id arizona_i2c_id[] = {
  83. { "wm5102", WM5102 },
  84. { "wm5110", WM5110 },
  85. { "wm8280", WM8280 },
  86. { "wm8997", WM8997 },
  87. { "wm8998", WM8998 },
  88. { "wm1814", WM1814 },
  89. { }
  90. };
  91. MODULE_DEVICE_TABLE(i2c, arizona_i2c_id);
  92. static struct i2c_driver arizona_i2c_driver = {
  93. .driver = {
  94. .name = "arizona",
  95. .pm = &arizona_pm_ops,
  96. .of_match_table = of_match_ptr(arizona_of_match),
  97. },
  98. .probe = arizona_i2c_probe,
  99. .remove = arizona_i2c_remove,
  100. .id_table = arizona_i2c_id,
  101. };
  102. module_i2c_driver(arizona_i2c_driver);
  103. MODULE_DESCRIPTION("Arizona I2C bus interface");
  104. MODULE_AUTHOR("Mark Brown <broonie@opensource.wolfsonmicro.com>");
  105. MODULE_LICENSE("GPL");