// SPDX-License-Identifier: GPL-2.0+ /* * Driver for the ADC on Freescale Semiconductor MC13783 and MC13892 PMICs. * * Copyright 2004-2007 Freescale Semiconductor, Inc. All Rights Reserved. * Copyright (C) 2009 Sascha Hauer, Pengutronix
*/
if (driver_data & MC13783_ADC_BPDIV2)
val = DIV_ROUND_CLOSEST(val * 9, 2); else /* * BP (channel 2) reports with offset 2.4V to the actual value * to fit the input range of the ADC. unit = 2.25mV = 9/4 mV.
*/
val = DIV_ROUND_CLOSEST(val * 9, 4) + 2400;
return sprintf(buf, "%u\n", val);
}
static ssize_t mc13783_adc_gp_show(struct device *dev, struct device_attribute *devattr, char *buf)
{ unsigned val; int ret = mc13783_adc_read(dev, devattr, &val);
if (ret) return ret;
/* * input range is [0, 2.3V], val has 10 bits, so each bit * is worth 9/4 mV.
*/
val = DIV_ROUND_CLOSEST(val * 9, 4);
if (driver_data & MC13783_ADC_BPDIV2) /* MC13892 have 1/2 divider, input range is [0, 4.800V] */
val = DIV_ROUND_CLOSEST(val * 4800, 1024); else /* MC13783 have 0.9 divider, input range is [0, 2.555V] */
val = DIV_ROUND_CLOSEST(val * 2555, 1024);
if (driver_data & MC13783_ADC_BPDIV2) { /* * MC13892: * Die Temperature Read Out Code at 25C 680 * Temperature change per LSB +0.4244C
*/
ret = DIV_ROUND_CLOSEST(-2635920 + val * 4244, 10);
} else { /* * MC13783: * Die Temperature Read Out Code at 25C 282 * Temperature change per LSB -1.14C
*/
ret = 346480 - 1140 * val;
}
/* these are only used if MC13783_ADC_16CHANS is provided in driver data */ staticstruct attribute *mc13783_attr_16chans[] = {
&sensor_dev_attr_in8_input.dev_attr.attr,
&sensor_dev_attr_in9_input.dev_attr.attr,
&sensor_dev_attr_in10_input.dev_attr.attr,
&sensor_dev_attr_in11_input.dev_attr.attr,
NULL
};
/* last four channels may be occupied by the touchscreen */ staticstruct attribute *mc13783_attr_ts[] = {
&sensor_dev_attr_in12_input.dev_attr.attr,
&sensor_dev_attr_in13_input.dev_attr.attr,
&sensor_dev_attr_in14_input.dev_attr.attr,
&sensor_dev_attr_in15_input.dev_attr.attr,
NULL
};
/* Register sysfs hooks */
ret = sysfs_create_group(&pdev->dev.kobj, &mc13783_group_base); if (ret) return ret;
if (id->driver_data & MC13783_ADC_16CHANS) {
ret = sysfs_create_group(&pdev->dev.kobj,
&mc13783_group_16chans); if (ret) goto out_err_create_16chans;
}
if (!mc13783_adc_use_touchscreen(pdev)) {
ret = sysfs_create_group(&pdev->dev.kobj, &mc13783_group_ts); if (ret) goto out_err_create_ts;
}
priv->hwmon_dev = hwmon_device_register(&pdev->dev); if (IS_ERR(priv->hwmon_dev)) {
ret = PTR_ERR(priv->hwmon_dev);
dev_err(&pdev->dev, "hwmon_device_register failed with %d.\n", ret); goto out_err_register;
}
return 0;
out_err_register:
if (!mc13783_adc_use_touchscreen(pdev))
sysfs_remove_group(&pdev->dev.kobj, &mc13783_group_ts);
out_err_create_ts:
if (id->driver_data & MC13783_ADC_16CHANS)
sysfs_remove_group(&pdev->dev.kobj, &mc13783_group_16chans);
out_err_create_16chans:
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.