arizona-i2c.c 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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/mfd/arizona/core.h>
  20. #include "arizona.h"
  21. static int arizona_i2c_probe(struct i2c_client *i2c,
  22. const struct i2c_device_id *id)
  23. {
  24. struct arizona *arizona;
  25. const struct regmap_config *regmap_config;
  26. int ret, type;
  27. if (i2c->dev.of_node)
  28. type = arizona_of_get_type(&i2c->dev);
  29. else
  30. type = id->driver_data;
  31. switch (type) {
  32. #ifdef CONFIG_MFD_WM5102
  33. case WM5102:
  34. regmap_config = &wm5102_i2c_regmap;
  35. break;
  36. #endif
  37. #ifdef CONFIG_MFD_WM5110
  38. case WM5110:
  39. regmap_config = &wm5110_i2c_regmap;
  40. break;
  41. #endif
  42. #ifdef CONFIG_MFD_WM8997
  43. case WM8997:
  44. regmap_config = &wm8997_i2c_regmap;
  45. break;
  46. #endif
  47. default:
  48. dev_err(&i2c->dev, "Unknown device type %ld\n",
  49. id->driver_data);
  50. return -EINVAL;
  51. }
  52. arizona = devm_kzalloc(&i2c->dev, sizeof(*arizona), GFP_KERNEL);
  53. if (arizona == NULL)
  54. return -ENOMEM;
  55. arizona->regmap = devm_regmap_init_i2c(i2c, regmap_config);
  56. if (IS_ERR(arizona->regmap)) {
  57. ret = PTR_ERR(arizona->regmap);
  58. dev_err(&i2c->dev, "Failed to allocate register map: %d\n",
  59. ret);
  60. return ret;
  61. }
  62. arizona->type = id->driver_data;
  63. arizona->dev = &i2c->dev;
  64. arizona->irq = i2c->irq;
  65. return arizona_dev_init(arizona);
  66. }
  67. static int arizona_i2c_remove(struct i2c_client *i2c)
  68. {
  69. struct arizona *arizona = dev_get_drvdata(&i2c->dev);
  70. arizona_dev_exit(arizona);
  71. return 0;
  72. }
  73. static const struct i2c_device_id arizona_i2c_id[] = {
  74. { "wm5102", WM5102 },
  75. { "wm5110", WM5110 },
  76. { "wm8997", WM8997 },
  77. { }
  78. };
  79. MODULE_DEVICE_TABLE(i2c, arizona_i2c_id);
  80. static struct i2c_driver arizona_i2c_driver = {
  81. .driver = {
  82. .name = "arizona",
  83. .owner = THIS_MODULE,
  84. .pm = &arizona_pm_ops,
  85. .of_match_table = of_match_ptr(arizona_of_match),
  86. },
  87. .probe = arizona_i2c_probe,
  88. .remove = arizona_i2c_remove,
  89. .id_table = arizona_i2c_id,
  90. };
  91. module_i2c_driver(arizona_i2c_driver);
  92. MODULE_DESCRIPTION("Arizona I2C bus interface");
  93. MODULE_AUTHOR("Mark Brown <broonie@opensource.wolfsonmicro.com>");
  94. MODULE_LICENSE("GPL");