// SPDX-License-Identifier: GPL-2.0-or-later /* * mcp3021.c - driver for Microchip MCP3021 and MCP3221 * * Copyright (C) 2008-2009, 2012 Freescale Semiconductor, Inc. * Author: Mingkai Hu <Mingkai.hu@freescale.com> * Reworked by Sven Schuchmann <schuchmann@schleissheimer.de> * DT support added by Clemens Gruber <clemens.gruber@pqgruber.com> * * This driver exports the value of analog input voltage to sysfs, the * voltage unit is mV. Through the sysfs interface, lm-sensors tool * can also display the input voltage.
*/
staticint mcp3021_read(struct device *dev, enum hwmon_sensor_types type,
u32 attr, int channel, long *val)
{ struct mcp3021_data *data = dev_get_drvdata(dev); struct i2c_client *client = data->client;
__be16 buf;
u16 reg; int ret;
if (type != hwmon_in) return -EOPNOTSUPP;
ret = i2c_master_recv(client, (char *)&buf, 2); if (ret < 0) return ret; if (ret != 2) return -EIO;
/* The output code of the MCP3021 is transmitted with MSB first. */
reg = be16_to_cpu(buf);
/* * The ten-bit output code is composed of the lower 4-bit of the * first byte and the upper 6-bit of the second byte.
*/
reg = (reg >> data->sar_shift) & data->sar_mask;
*val = volts_from_reg(data, reg);
return 0;
}
static umode_t mcp3021_is_visible(constvoid *_data, enum hwmon_sensor_types type,
u32 attr, int channel)
{ if (type != hwmon_in) return 0;
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.