in slaves/w1_therm.c [1525:1575]
static ssize_t w1_slave_show(struct device *device,
struct device_attribute *attr, char *buf)
{
struct w1_slave *sl = dev_to_w1_slave(device);
struct therm_info info;
u8 *family_data = sl->family_data;
int ret, i;
ssize_t c = PAGE_SIZE;
if (bulk_read_support(sl)) {
if (SLAVE_CONVERT_TRIGGERED(sl) < 0) {
dev_dbg(device,
"%s: Conversion in progress, retry later\n",
__func__);
return 0;
} else if (SLAVE_CONVERT_TRIGGERED(sl) > 0) {
/* A bulk read has been issued, read the device RAM */
ret = read_scratchpad(sl, &info);
SLAVE_CONVERT_TRIGGERED(sl) = 0;
} else
ret = convert_t(sl, &info);
} else
ret = convert_t(sl, &info);
if (ret < 0) {
dev_dbg(device,
"%s: Temperature data may be corrupted. err=%d\n",
__func__, ret);
return 0;
}
for (i = 0; i < 9; ++i)
c -= snprintf(buf + PAGE_SIZE - c, c, "%02x ", info.rom[i]);
c -= snprintf(buf + PAGE_SIZE - c, c, ": crc=%02x %s\n",
info.crc, (info.verdict) ? "YES" : "NO");
if (info.verdict)
memcpy(family_data, info.rom, sizeof(info.rom));
else
dev_warn(device, "%s:Read failed CRC check\n", __func__);
for (i = 0; i < 9; ++i)
c -= snprintf(buf + PAGE_SIZE - c, c, "%02x ",
((u8 *)family_data)[i]);
c -= snprintf(buf + PAGE_SIZE - c, c, "t=%d\n",
temperature_from_RAM(sl, info.rom));
ret = PAGE_SIZE - c;
return ret;
}