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