bcm590xx.c 3.0 KB

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