Skip to contentSkip to conversation

Porting the fscpos driver to 2.6

DISCUSSION Stefan Ott 2 participants 5 messages May 19, 2005

lore
Share & tools
lore
#1 lore raw
Quoted 3 lines

I've been using the lm_sensors fscpos driver on 2.4 kernels for quite a while. Since I switched to 2.6 I really miss that driver. That's why I decided to just try and port it.

This is good news :)

Quoted 4 lines

I'm not much of a C coder (as in "I hardly know any C") and even less of a kernel hacker. What I did was to see, how the lm78 driver changed from 2.4 to 2.6 and change the fscpos module in more or less the same way (and, of course, I read the porting-clients document).

I would suggest that you base your work on fscher, not lm78. fscher and fscpos have significant similarities, it'll make your work much easier.

Also make sure you read the i2c/sysfs-interface document if you need to add interface files the Hermes chip doesn't have.

Quoted 4 lines

In order to
get started I only tried to implement the temperature sensor. The module I created can now be compiled and loaded and even creates a directory under /sys/bus/i2c/drivers, but there's nothing in there.

I would say that your chip isn't properly detected then. If it were, you would have a new directory in /sys/bus/i2c/devices (as I see no problem in that part of your code). Try adding some printks in the detection function and see where the failure occurs.

If you don't see any message, maybe you have a problem with the bus driver. Which bus driver do you use? Are you able to see the Poseidon chip using i2cdetect, and dump its contents using i2cdump?

Quoted 5 lines

Now, I don't know whether you would be interested in a 2.6 version of said driver, but if so, could you please give me some advice about what I might be missing? The current (very ugly - contains a hell of a lot of commented code) version of what I did is attached to this message.

We are of course interested. As long as a driver still has even only a couple users, it's worth porting it to 2.6. You never know, maybe other people are interested but just don't know what to do.

What you have here looks promising. Take a look at the fscher driver for hints on how you can clean things up (the 2.4 driver might not be exactly clean, the 2.4 version of old drivers like this one rarely are). Once you find what the problem was, adding the next interface files shouldn't be too hard.

Signature · 2 lines
Jean Delvare
http://khali.linux-fr.org/
#3 lore raw
In reply to Stefan Ott

Hi Stefan,

Quoted 7 lines

Well, meanwhile I somehow managed to get a working driver based on the old fscpos code, ported the way lm78 was ported and added a real lot of code from the new fscher driver. It's read-only, as the only write function I implemented crashed my system (maybe I should listen to GCC's warnings) :). I don't think write support is extremely important
- most users only want to see how how their CPU is - but as I get more familiar with C and the sensors world I'll add it.

Write support is important. Sometimes the chip defaults don't fit your needs. Sometimes the BIOS messes with the chip configuration and limits are less than usable.

By looking at how the fscher driver handles writes to the interface files you should be able to get it working in fscpos. It's really the same.

Quoted 5 lines

The code is still messy, especially as I couldn't figure out how to add additional arguments to the functions (eg. a "nr" argument for the show_fan_status in order to have one function for all three fans - not a function per fan). As time passes, I might find out more about C and do it right.

Sysfs callback functions have a fixed propotype, which doesn't include any additional data. This is a significant difference (regression) with the older procfs interface drivers had in Linux 2.4, where you could have one callback function for several files.

This is the reason why you will see an import use of the preprocessor in the newer drivers. It is frequent to define the callback functions as preprocessor macros, which you then call as many times as needed. This duplicates some code, of course. If the callback functions are small and called frequently (typically read functions) we don't care much. If the callback functions are larger and called less frequently (typically write functions) we usually have only one real function with all the code, and an extra parameter, and sysfs callback functions are one-liners calling with one real function with the relevant extra parameter.

You can find example of this in almost all the i2c chip drivers in Linux 2.6.

Quoted 4 lines

There are also some masked bits in the fscher code which were different in the old fscpos driver. I'm going to contact the original fscpos author to find out where he got those values from and then probably use them.

Masks are very chip-dependent. You should keep the masks as they were in the original fscpos driver.

BTW, if you find bugs in the original fscpos driver, please let us know and we'll fix them.

Quoted 6 lines

One issue I couldn't fix is the following: My code seems to get the temperatures right (the temp1_input and temp2_input files contain the correct values) but tools which rely on the sensors library keep getting wrong values ("sensors" shows 0.04?C instead of 39?C - a factor 1000 missing?). As I took that code (TEMP_FROM_REG) from the old fscpos driver I'm really puzzled. Do you have a clue?

I guess you didn't read i2c/sysfs-interface ;)

In Linux 2.6, sysfs files used by the i2c chip drivers use standardized units and integer values (or actually fixed point). In Linux 2.4 we were using floating point and magnitude was driver-dependant.

The units and magnitudes in 2.6 are as follow:
Temperatures: 0.001 degree C / bit (42 degrees C -> 42000)
Voltages: 0.001 V / bit (1.8 V -> 1800)

You have to respect this in your new driver.

Also note that libsensors may need to be instructed about the new fscpos driver, or it might miss some interface files. The library has some code to guess the new names from the old ones, but depending on how standard the old ones were, it might be more or less efficient.

BTW, which 2.6 kernel are you using? There have been changes made to the code very recently, which implied changes (simplifications actually) to all chip drivers. So you would want to base your work on 2.6.10-rc3 if you want us to integrate it in the main tree when you're done. The most significant change I can think of is that normal_i2c_range and normal_isa_range are gone (your driver wouldn't use it but still declare them as empty - these declations must be removed.)

Signature · 2 lines
Jean Delvare
http://khali.linux-fr.org/
author
#4 lore raw
In reply to Stefan Ott

Hi Jean

I've been using kernel 2.6.9 so far - I'll just diff the fscher driver to see what changed.

Thanks for the sysfs information (shame on me for that one :)), the pdf (looks quite helpful!) and your help in general. I'll get back to you in a couple of days - hopefully with a fully-working driver.

Regards

Signature · 12 lines
Stefan Ott
http://www.desire.ch

"Quelli come me si svegliano alle tre e dicono che i giorni sono corti"
  -- Luciano Ligabue
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
Url : http://lists.lm-sensors.org/pipermail/lm-sensors/attachments/20041219/9a8d6198/attachment.bin