bcm590xx.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. /*
  2. * Broadcom BCM590xx PMU
  3. *
  4. * Copyright 2014 Linaro Limited
  5. * Author: Matt Porter <mporter@linaro.org>
  6. *
  7. * This program is free software; you can redistribute it and/or modify it
  8. * under the terms of the GNU General Public License as published by the
  9. * Free Software Foundation; either version 2 of the License, or (at your
  10. * option) any later version.
  11. */
  12. #include <linux/err.h>
  13. #include <linux/i2c.h>
  14. #include <linux/init.h>
  15. #include <linux/mfd/bcm590xx.h>
  16. #include <linux/mfd/core.h>
  17. #include <linux/module.h>
  18. #include <linux/moduleparam.h>
  19. #include <linux/of.h>
  20. #include <linux/of_device.h>
  21. #include <linux/regmap.h>
  22. #include <linux/slab.h>
  23. static const struct mfd_cell bcm590xx_devs[] = {
  24. {
  25. .name = "bcm590xx-vregs",
  26. },
  27. };
  28. static const struct regmap_config bcm590xx_regmap_config_pri = {
  29. .reg_bits = 8,
  30. .val_bits = 8,
  31. .max_register = BCM590XX_MAX_REGISTER_PRI,
  32. .cache_type = REGCACHE_RBTREE,
  33. };
  34. static const struct regmap_config bcm590xx_regmap_config_sec = {
  35. .reg_bits = 8,
  36. .val_bits = 8,
  37. .max_register = BCM590XX_MAX_REGISTER_SEC,
  38. .cache_type = REGCACHE_RBTREE,
  39. };
  40. static int bcm590xx_i2c_probe(struct i2c_client *i2c_pri,
  41. const struct i2c_device_id *id)
  42. {
  43. struct bcm590xx *bcm590xx;
  44. int ret;
  45. bcm590xx = devm_kzalloc(&i2c_pri->dev, sizeof(*bcm590xx), GFP_KERNEL);
  46. if (!bcm590xx)
  47. return -ENOMEM;
  48. i2c_set_clientdata(i2c_pri, bcm590xx);
  49. bcm590xx->dev = &i2c_pri->dev;
  50. bcm590xx->i2c_pri = i2c_pri;
  51. bcm590xx->regmap_pri = devm_regmap_init_i2c(i2c_pri,
  52. &bcm590xx_regmap_config_pri);
  53. if (IS_ERR(bcm590xx->regmap_pri)) {
  54. ret = PTR_ERR(bcm590xx->regmap_pri);
  55. dev_err(&i2c_pri->dev, "primary regmap init failed: %d\n", ret);
  56. return ret;
  57. }
  58. /* Secondary I2C slave address is the base address with A(2) asserted */
  59. bcm590xx->i2c_sec = i2c_new_dummy(i2c_pri->adapter,
  60. i2c_pri->addr | BIT(2));
  61. if (IS_ERR_OR_NULL(bcm590xx->i2c_sec)) {
  62. dev_err(&i2c_pri->dev, "failed to add secondary I2C device\n");
  63. return -ENODEV;
  64. }
  65. i2c_set_clientdata(bcm590xx->i2c_sec, bcm590xx);
  66. bcm590xx->regmap_sec = devm_regmap_init_i2c(bcm590xx->i2c_sec,
  67. &bcm590xx_regmap_config_sec);
  68. if (IS_ERR(bcm590xx->regmap_sec)) {
  69. ret = PTR_ERR(bcm590xx->regmap_sec);
  70. dev_err(&bcm590xx->i2c_sec->dev,
  71. "secondary regmap init failed: %d\n", ret);
  72. goto err;
  73. }
  74. ret = mfd_add_devices(&i2c_pri->dev, -1, bcm590xx_devs,
  75. ARRAY_SIZE(bcm590xx_devs), NULL, 0, NULL);
  76. if (ret < 0) {
  77. dev_err(&i2c_pri->dev, "failed to add sub-devices: %d\n", ret);
  78. goto err;
  79. }
  80. return 0;
  81. err:
  82. i2c_unregister_device(bcm590xx->i2c_sec);
  83. return ret;
  84. }
  85. static int bcm590xx_i2c_remove(struct i2c_client *i2c)
  86. {
  87. mfd_remove_devices(&i2c->dev);
  88. return 0;
  89. }
  90. static const struct of_device_id bcm590xx_of_match[] = {
  91. { .compatible = "brcm,bcm59056" },
  92. { }
  93. };
  94. MODULE_DEVICE_TABLE(of, bcm590xx_of_match);
  95. static const struct i2c_device_id bcm590xx_i2c_id[] = {
  96. { "bcm59056" },
  97. { }
  98. };
  99. MODULE_DEVICE_TABLE(i2c, bcm590xx_i2c_id);
  100. static struct i2c_driver bcm590xx_i2c_driver = {
  101. .driver = {
  102. .name = "bcm590xx",
  103. .of_match_table = of_match_ptr(bcm590xx_of_match),
  104. },
  105. .probe = bcm590xx_i2c_probe,
  106. .remove = bcm590xx_i2c_remove,
  107. .id_table = bcm590xx_i2c_id,
  108. };
  109. module_i2c_driver(bcm590xx_i2c_driver);
  110. MODULE_AUTHOR("Matt Porter <mporter@linaro.org>");
  111. MODULE_DESCRIPTION("BCM590xx multi-function driver");
  112. MODULE_LICENSE("GPL v2");