arizona-i2c.c 2.5 KB

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