adm1275.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. /*
  2. * Hardware monitoring driver for Analog Devices ADM1275 Hot-Swap Controller
  3. * and Digital Power Monitor
  4. *
  5. * Copyright (c) 2011 Ericsson AB.
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. */
  17. #include <linux/kernel.h>
  18. #include <linux/module.h>
  19. #include <linux/init.h>
  20. #include <linux/err.h>
  21. #include <linux/slab.h>
  22. #include <linux/i2c.h>
  23. #include "pmbus.h"
  24. #define ADM1275_PMON_CONFIG 0xd4
  25. #define ADM1275_VIN_VOUT_SELECT (1 << 6)
  26. #define ADM1275_VRANGE (1 << 5)
  27. static int adm1275_probe(struct i2c_client *client,
  28. const struct i2c_device_id *id)
  29. {
  30. int config;
  31. int ret;
  32. struct pmbus_driver_info *info;
  33. if (!i2c_check_functionality(client->adapter,
  34. I2C_FUNC_SMBUS_READ_BYTE_DATA))
  35. return -ENODEV;
  36. info = kzalloc(sizeof(struct pmbus_driver_info), GFP_KERNEL);
  37. if (!info)
  38. return -ENOMEM;
  39. config = i2c_smbus_read_byte_data(client, ADM1275_PMON_CONFIG);
  40. if (config < 0) {
  41. ret = config;
  42. goto err_mem;
  43. }
  44. info->pages = 1;
  45. info->direct[PSC_VOLTAGE_IN] = true;
  46. info->direct[PSC_VOLTAGE_OUT] = true;
  47. info->direct[PSC_CURRENT_OUT] = true;
  48. info->m[PSC_CURRENT_OUT] = 807;
  49. info->b[PSC_CURRENT_OUT] = 20475;
  50. info->R[PSC_CURRENT_OUT] = -1;
  51. info->func[0] = PMBUS_HAVE_IOUT | PMBUS_HAVE_STATUS_IOUT;
  52. if (config & ADM1275_VRANGE) {
  53. info->m[PSC_VOLTAGE_IN] = 19199;
  54. info->b[PSC_VOLTAGE_IN] = 0;
  55. info->R[PSC_VOLTAGE_IN] = -2;
  56. info->m[PSC_VOLTAGE_OUT] = 19199;
  57. info->b[PSC_VOLTAGE_OUT] = 0;
  58. info->R[PSC_VOLTAGE_OUT] = -2;
  59. } else {
  60. info->m[PSC_VOLTAGE_IN] = 6720;
  61. info->b[PSC_VOLTAGE_IN] = 0;
  62. info->R[PSC_VOLTAGE_IN] = -1;
  63. info->m[PSC_VOLTAGE_OUT] = 6720;
  64. info->b[PSC_VOLTAGE_OUT] = 0;
  65. info->R[PSC_VOLTAGE_OUT] = -1;
  66. }
  67. if (config & ADM1275_VIN_VOUT_SELECT)
  68. info->func[0] |= PMBUS_HAVE_VOUT | PMBUS_HAVE_STATUS_VOUT;
  69. else
  70. info->func[0] |= PMBUS_HAVE_VIN | PMBUS_HAVE_STATUS_INPUT;
  71. ret = pmbus_do_probe(client, id, info);
  72. if (ret)
  73. goto err_mem;
  74. return 0;
  75. err_mem:
  76. kfree(info);
  77. return ret;
  78. }
  79. static int adm1275_remove(struct i2c_client *client)
  80. {
  81. const struct pmbus_driver_info *info = pmbus_get_driver_info(client);
  82. int ret;
  83. ret = pmbus_do_remove(client);
  84. kfree(info);
  85. return ret;
  86. }
  87. static const struct i2c_device_id adm1275_id[] = {
  88. {"adm1275", 0},
  89. { }
  90. };
  91. MODULE_DEVICE_TABLE(i2c, adm1275_id);
  92. static struct i2c_driver adm1275_driver = {
  93. .driver = {
  94. .name = "adm1275",
  95. },
  96. .probe = adm1275_probe,
  97. .remove = adm1275_remove,
  98. .id_table = adm1275_id,
  99. };
  100. static int __init adm1275_init(void)
  101. {
  102. return i2c_add_driver(&adm1275_driver);
  103. }
  104. static void __exit adm1275_exit(void)
  105. {
  106. i2c_del_driver(&adm1275_driver);
  107. }
  108. MODULE_AUTHOR("Guenter Roeck");
  109. MODULE_DESCRIPTION("PMBus driver for Analog Devices ADM1275");
  110. MODULE_LICENSE("GPL");
  111. module_init(adm1275_init);
  112. module_exit(adm1275_exit);