Demand:
Read the value of the embedded temperature sensor.
Known conditions:
* The temperature sensor has been welded on the motherboard.
* Temperature Sensor Model LM75
*linux Drive, in linux-2.6.20.21/drivers/hwmon/lm75.c
* The circuit of the temperature sensor
Questions and Answers:
*linux How to use the drive with its own.
Look at the LM75.C code and find out that this temperature sensor is using a I2C bus.
The code sees the I2C-driven interface defined as follows, unlike a character-driven interface that was previously done.
[CPP] View Plain Copy * * is the driver that'll be inserted/static struct I2c_driver Lm75_driver = {. drive R = {. Name = "Lm75",},. id = i2c_driverid_lm75,. Attach_adapter = Lm75_attach_adapter,. detach_client = Lm75_detach_client,};
Search in this book of Linux Device driver, which is not covered in this book.
Www.linuxjournal.com/article/7136,www.linuxjournal.com/article/7252 said it well. Especially the latter. I2C is used more in the application of the sensor on the motherboard, but it was added in the newer version of the Linux kernel, no wonder ldd the book.
Then look at the data structure of the callback function, specifically what to do is more clear. According to the content of the function, the driver automatically detects the device on the I2C bus when it is loaded, so it automatically discovers the temperature sensor. Lm75_update_device () is a function used for polling readings of temperature sensors.
According to the article guideline, look at the/sys/bus/i2c/of the equipment. The following already has the LM75 sensor data, the direct read has the data, and the data will change, as follows:
root:~# Cat/sys/bus/i2c/devices/0-0048/temp1_input
-31500
* reading is negative. What kind of readings are normal.
Added debug information to the driver code, print out the value of the registers that are read on the sensor, and not read on the file system.
Look at the Linux-2.6.20.21/documentation/hwmon/lm75, understand that Lm75 is an industrial standard. So the Lm75 drive in Linux is supported by a variety of temperature sensors.
Look at the chip on the board, it is lm75a. A datasheet was downloaded on the Internet, showing a total of 9-bit to control readings. The head position is positive or negative, followed by a value of 8-bit.
In the driver code to add debugging information, only print the register value of the 8-bit, put in the temperature test box The results appear to be full of reasonable.
[CPP] View plain copy @drivers/base/sys.c static ssize_t sysdev_show (struct kobject * kobj, struct attribute * attr, char * buffer) {struct Sys_device * Sysdev = To_sysdev (kobj); struct Sysdev_attribute * sysdev_attr = to_sysdev_attr (attr); if (sysdev_attr->show) return sysdev_attr->show (Sysdev, buffer); Return-eio; }
[cpp] View plain copy static device_attr (temp1_input, s_irugo, show_temp_input, NULL); /* that truct device_attribute dev_attr_temp1_input = __attr (temp1_input, s_irugo, show_temp1_input, null) */ /* truct device_attribute dev_attr_temp1_input = { .attr = {.name = __stringify (temp1_input), .mode = S_IRUGO, . owner = this_module }, .show = show_temp1_input, .store = NULL, } */
[CPP] View plain copy/* interface for exporting device attributes/struct Device_attribute {struct attrib Ute attr; ssize_t (*show) (struct device *dev, struct device_attribute, *attr,