Source
x
/*
* MEN 14F021P00 Board Management Controller (BMC) hwmon driver.
*
* This is the core hwmon driver of the MEN 14F021P00 BMC.
* The BMC monitors the board voltages which can be access with this
* driver through sysfs.
*
* Copyright (C) 2014 MEN Mikro Elektronik Nuernberg GmbH
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2 of the License, or (at your
* option) any later version.
*/
struct menf21bmc_hwmon {
bool valid;
struct i2c_client *i2c_client;
unsigned long last_update;
int in_val[BMC_VOLT_COUNT];
int in_min[BMC_VOLT_COUNT];
int in_max[BMC_VOLT_COUNT];
};
static const char *const input_names[] = {
[MENF21BMC_V33] = "MON_3_3V",
[MENF21BMC_V5] = "MON_5V",
[MENF21BMC_V12] = "MON_12V",
[MENF21BMC_V5_SB] = "5V_STANDBY",
[MENF21BMC_VBAT] = "VBAT"
};
static struct menf21bmc_hwmon *menf21bmc_hwmon_update(struct device *dev)
{
int i;
int val;
struct menf21bmc_hwmon *drv_data = dev_get_drvdata(dev);
struct menf21bmc_hwmon *data_ret = drv_data;
if (time_after(jiffies, drv_data->last_update + HZ)
|| !drv_data->valid) {
for (i = 0; i < BMC_VOLT_COUNT; i++) {
val = i2c_smbus_read_word_data(drv_data->i2c_client,
IDX_TO_VOLT_INP_CMD(i));
if (val < 0) {
data_ret = ERR_PTR(val);
goto abort;
}
drv_data->in_val[i] = val;
}
drv_data->last_update = jiffies;
drv_data->valid = true;
}
abort:
return data_ret;
}
static int menf21bmc_hwmon_get_volt_limits(struct menf21bmc_hwmon *drv_data)
{
int i, val;
for (i = 0; i < BMC_VOLT_COUNT; i++) {
val = i2c_smbus_read_word_data(drv_data->i2c_client,
IDX_TO_VOLT_MIN_CMD(i));
if (val < 0)
return val;
drv_data->in_min[i] = val;