arizona-i2c.c 2.4 KB

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