arizona-i2c.c 2.5 KB

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