menf21bmc.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. /*
  2. * MEN 14F021P00 Board Management Controller (BMC) MFD Core Driver.
  3. *
  4. * Copyright (C) 2014 MEN Mikro Elektronik Nuernberg GmbH
  5. *
  6. * This program is free software; you can redistribute it and/or modify it
  7. * under the terms of the GNU General Public License as published by the
  8. * Free Software Foundation; either version 2 of the License, or (at your
  9. * option) any later version.
  10. */
  11. #include <linux/kernel.h>
  12. #include <linux/device.h>
  13. #include <linux/module.h>
  14. #include <linux/i2c.h>
  15. #include <linux/mfd/core.h>
  16. #define BMC_CMD_WDT_EXIT_PROD 0x18
  17. #define BMC_CMD_WDT_PROD_STAT 0x19
  18. #define BMC_CMD_REV_MAJOR 0x80
  19. #define BMC_CMD_REV_MINOR 0x81
  20. #define BMC_CMD_REV_MAIN 0x82
  21. static struct mfd_cell menf21bmc_cell[] = {
  22. { .name = "menf21bmc_wdt", },
  23. { .name = "menf21bmc_led", },
  24. { .name = "menf21bmc_hwmon", }
  25. };
  26. static int menf21bmc_wdt_exit_prod_mode(struct i2c_client *client)
  27. {
  28. int val, ret;
  29. val = i2c_smbus_read_byte_data(client, BMC_CMD_WDT_PROD_STAT);
  30. if (val < 0)
  31. return val;
  32. /*
  33. * Production mode should be not active after delivery of the Board.
  34. * To be sure we check it, inform the user and exit the mode
  35. * if active.
  36. */
  37. if (val == 0x00) {
  38. dev_info(&client->dev,
  39. "BMC in production mode. Exit production mode\n");
  40. ret = i2c_smbus_write_byte(client, BMC_CMD_WDT_EXIT_PROD);
  41. if (ret < 0)
  42. return ret;
  43. }
  44. return 0;
  45. }
  46. static int
  47. menf21bmc_probe(struct i2c_client *client, const struct i2c_device_id *ids)
  48. {
  49. int rev_major, rev_minor, rev_main;
  50. int ret;
  51. ret = i2c_check_functionality(client->adapter,
  52. I2C_FUNC_SMBUS_BYTE_DATA |
  53. I2C_FUNC_SMBUS_WORD_DATA |
  54. I2C_FUNC_SMBUS_BYTE);
  55. if (!ret)
  56. return -ENODEV;
  57. rev_major = i2c_smbus_read_word_data(client, BMC_CMD_REV_MAJOR);
  58. if (rev_major < 0) {
  59. dev_err(&client->dev, "failed to get BMC major revision\n");
  60. return rev_major;
  61. }
  62. rev_minor = i2c_smbus_read_word_data(client, BMC_CMD_REV_MINOR);
  63. if (rev_minor < 0) {
  64. dev_err(&client->dev, "failed to get BMC minor revision\n");
  65. return rev_minor;
  66. }
  67. rev_main = i2c_smbus_read_word_data(client, BMC_CMD_REV_MAIN);
  68. if (rev_main < 0) {
  69. dev_err(&client->dev, "failed to get BMC main revision\n");
  70. return rev_main;
  71. }
  72. dev_info(&client->dev, "FW Revision: %02d.%02d.%02d\n",
  73. rev_major, rev_minor, rev_main);
  74. /*
  75. * We have to exit the Production Mode of the BMC to activate the
  76. * Watchdog functionality and the BIOS life sign monitoring.
  77. */
  78. ret = menf21bmc_wdt_exit_prod_mode(client);
  79. if (ret < 0) {
  80. dev_err(&client->dev, "failed to leave production mode\n");
  81. return ret;
  82. }
  83. ret = mfd_add_devices(&client->dev, 0, menf21bmc_cell,
  84. ARRAY_SIZE(menf21bmc_cell), NULL, 0, NULL);
  85. if (ret < 0) {
  86. dev_err(&client->dev, "failed to add BMC sub-devices\n");
  87. return ret;
  88. }
  89. return 0;
  90. }
  91. static int menf21bmc_remove(struct i2c_client *client)
  92. {
  93. mfd_remove_devices(&client->dev);
  94. return 0;
  95. }
  96. static const struct i2c_device_id menf21bmc_id_table[] = {
  97. { "menf21bmc" },
  98. { }
  99. };
  100. MODULE_DEVICE_TABLE(i2c, menf21bmc_id_table);
  101. static struct i2c_driver menf21bmc_driver = {
  102. .driver.name = "menf21bmc",
  103. .id_table = menf21bmc_id_table,
  104. .probe = menf21bmc_probe,
  105. .remove = menf21bmc_remove,
  106. };
  107. module_i2c_driver(menf21bmc_driver);
  108. MODULE_DESCRIPTION("MEN 14F021P00 BMC mfd core driver");
  109. MODULE_AUTHOR("Andreas Werner <andreas.werner@men.de>");
  110. MODULE_LICENSE("GPL v2");