Accelerometer, Gyros and ADC's etc within the kernel.
This email is basically a request for opinions on how and where such sensors should be integrated into the kernel.
To set the scene...
Increasing numbers of embedded devices are being supplied attached MEMS devices (www.xbow.com imote2 etc). Along with more traditional sensors such as ADC's not being used for hardware monitoring, these do not really seem to
fit with in an particular subsystem of the kernel. A previous discussion on
lkml in 2006 considered the accelerometers to be found within some laptop hard drives, but I haven't been able to track down any more general discussions
of such non hardware monitoring sensors.
The obvious possibilities are:
* To place the various drivers within the spi / i2c etc subsystems as relevant.
* To place within the hwmon subsystem as this is probably closest. (there is already at least one straight ADC driver in hwmon)
* To create a new subsystem, or perhaps merely sysfs class to contain these elements.
Typical requirements within an application include simply polling for current
readings, and using device triggered interrupts to grab data continuously to a
ring buffer, for collection by suitable userspace code. Obviously it would be
desirable to standardize sysfs controls for various calibration parameters as
much as possible across the various devices.
Any other suggestions welcome!
To illustrate the sort of devices here are a few I have drivers written for or will
shortly be writing (some submitted to hwmon and spi mailing lists, some not
finished as of yet)
ST Micro LIS3L02DQ 3D accelerometer. SPI device, no buffering, interrupt pin
raised high on new data being available. Currently the driver assumes, if interrupts are enabled, that this is connected to a specified gpio.
(http://www.st.com/stonline/books/pdf/docs/10175.pdf)
VTI SCA3000 E05 3D accelerometer equiped with substantial ring buffer. SPI device. Can operate either in buffered or direct mode. In buffered mode, interrupts
can be used to indicate when the ring buffer is 3/4 full triggering a download to
a larger ring buffer in the kernel if necessary.
(http://www.vti.fi/en/products-solutions/products/accelerometers/sca3000-accelerometers/)
Analog Devices ADIS16350 combined 3D accelerometer and gyro unit. SPI device.
(http://www.analog.com/en/prod/0,,764_801_ADIS16350%2C00.html)
Maxim MAX1363, MAX1238 ADC's. I2C devices. Some SPI ADC's (www.analog.com for
examples)
Would be nice if practical to allow the framework to include RS232 devices such
as those from www.xsens.com, www.isense.com and others.
--
Jonathan Cameron
-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
Hi Jonathan,
Quoted 16 lines · Jonathan Cameron
This email is basically a request for opinions on how and where such sensors should be integrated into the kernel.
To set the scene...
Increasing numbers of embedded devices are being supplied attached MEMS devices (www.xbow.com imote2 etc). Along with more traditional sensors such as ADC's not being used for hardware monitoring, these do not really seem to
fit with in an particular subsystem of the kernel. A previous discussion on
lkml in 2006 considered the accelerometers to be found within some laptop hard drives, but I haven't been able to track down any more general discussions
of such non hardware monitoring sensors.
Quoted 4 lines
The obvious possibilities are:
* To place the various drivers within the spi / i2c etc subsystems as relevant.
Bad idea. Grouping drivers by connectivity is almost always the wrong thing to do, as it means that different persons will maintain them and they have all chances to diverge. You really want to group drivers by functionality. On top of that, I am busy enough maintaining the i2c core and bus drivers without having more i2c device drivers added to my plate. These days I am trying to _empty_ drivers/i2c/chips, if anything.
Quoted 2 lines
* To place within the hwmon subsystem as this is probably closest. (there is already at least one straight ADC driver in hwmon)
Probably not the wisest choice, if nothing else, because the hwmon maintainer is already overloaded. And I don't think that these devices have much in common with the traditional hardware monitoring components anyway.
I'm not sure what "straight ADC driver" you are referring to, but anything which measures a voltage and exports the reading to user-space is, well, a voltage sensor, and thus fix within hwmon. If the same chip is used for a higher-level, dedicated function then we would probably have a separate driver for it, outside of hwmon.
Quoted 2 lines
* To create a new subsystem, or perhaps merely sysfs class to contain these elements.
Would be OK. Or:
* Place these within the input subsystem. You might want to discuss this with the input subsystem maintainer Dmitry Torokhov (Cc'd). The Wii remote is essentially a joystick, and joysticks belong to the input subsystem.
Quoted 11 lines
Typical requirements within an application include simply polling for current
readings, and using device triggered interrupts to grab data continuously to a
ring buffer, for collection by suitable userspace code. Obviously it would be
desirable to standardize sysfs controls for various calibration parameters as
much as possible across the various devices.Any other suggestions welcome!
This all sounds quite different from our hwmon drivers. Our hwmon drivers read all the sensor values at once and cache the readings for a couple seconds, so you can't get an instant reading at any time, and they also don't support interrupts in general.
Signature · 1 line
Jean Delvare
Quoted 46 lines · Jonathan Cameron
This email is basically a request for opinions on how and where such sensors
should be integrated into the kernel.To set the scene...
Increasing numbers of embedded devices are being supplied attached MEMS devices (www.xbow.com imote2 etc). Along with more traditional sensors such as ADC's not being used for hardware monitoring, these do not really seem to
fit with in an particular subsystem of the kernel. A previous discussion on
lkml in 2006 considered the accelerometers to be found within some laptop hard drives, but I haven't been able to track down any more general discussions
of such non hardware monitoring sensors.The obvious possibilities are:
* To place the various drivers within the spi / i2c etc subsystems as relevant.
* To place within the hwmon subsystem as this is probably closest. (there is already at least one straight ADC driver in hwmon)
* To create a new subsystem, or perhaps merely sysfs class to contain these elements.
Typical requirements within an application include simply polling for current
readings, and using device triggered interrupts to grab data continuously to a
ring buffer, for collection by suitable userspace code. Obviously it would be
desirable to standardize sysfs controls for various calibration parameters as
much as possible across the various devices.Any other suggestions welcome!
To illustrate the sort of devices here are a few I have drivers written for or will
shortly be writing (some submitted to hwmon and spi mailing lists, some not
finished as of yet)
Quoted 5 lines
ST Micro LIS3L02DQ 3D accelerometer. SPI device, no buffering, interrupt pin
raised high on new data being available. Currently the driver assumes, if interrupts are enabled, that this is connected to a specified gpio.
(http://www.st.com/stonline/books/pdf/docs/10175.pdf)
FWIW: I have this device talking to a PIC-18 and pushing the results over the serial port.
WRT linux support, I can't think of a generalized way to create a driver that would be able to be used with this device in Linux. You need to know witch IRQ line the DR line is connected too, and if you are bit-banging the SPI data off the thing, then you need to know which GPIO's of the host CPU you'll be using. If you have SPI hardware then you need to know where to pull the data from. The problem doesn't seem to generalize well.
Also, If you are playing with accelerometer data, you likely need some real time support or at lest a reliable time stamping of the data to do anything interesting.
Another problem area is around SPI itself. There are variations of device implementations around chip select polarity, clock biasing (rising,falling, or midpoint) sampling from one SPI part to the next.
Quoted 8 lines
VTI SCA3000 E05 3D accelerometer equiped with substantial ring buffer. SPI device. Can operate either in buffered or direct mode. In buffered mode, interrupts
can be used to indicate when the ring buffer is 3/4 full triggering a download to
a larger ring buffer in the kernel if necessary.
(http://www.vti.fi/en/products-solutions/products/accelerometers/sca3000-accelerometers/)
ring buffered data can make RT applications harder...
Quoted 11 lines
Analog Devices ADIS16350 combined 3D accelerometer and gyro unit. SPI device.
(http://www.analog.com/en/prod/0,,764_801_ADIS16350%2C00.html)Maxim MAX1363, MAX1238 ADC's. I2C devices. Some SPI ADC's (www.analog.com for
examples)Would be nice if practical to allow the framework to include RS232 devices such
as those from www.xsens.com, www.isense.com and others.
I'm not sure what you are asking for, you started off with SPI driver for interfacing a handful of accelerometer devices. Now your talking about the serial port.
Besides the consumer of accelerometer data is user space applications (mine attempt to be somewhat RT applications)
--mgross
Quoted 24 lines · Jean Delvare
Hi Jonathan,
Quoted 16 lines · Jonathan Cameron
This email is basically a request for opinions on how and where such sensors should be integrated into the kernel.
To set the scene...
Increasing numbers of embedded devices are being supplied attached MEMS devices (www.xbow.com imote2 etc). Along with more traditional sensors such as ADC's not being used for hardware monitoring, these do not really seem to
fit with in an particular subsystem of the kernel. A previous discussion on
lkml in 2006 considered the accelerometers to be found within some laptop hard drives, but I haven't been able to track down any more general discussions
of such non hardware monitoring sensors.Quoted 4 lines
The obvious possibilities are:
* To place the various drivers within the spi / i2c etc subsystems as relevant.
Quoted 6 lines
Bad idea. Grouping drivers by connectivity is almost always the wrong thing to do, as it means that different persons will maintain them and they have all chances to diverge. You really want to group drivers by functionality. On top of that, I am busy enough maintaining the i2c core and bus drivers without having more i2c device drivers added to my plate. These days I am trying to _empty_
drivers/i2c/chips, if anything.
100% ACK. And the functionality here is something like "industrial control" or "automation I/O". If this sort of hardware appears as device with mappable memory, we can handle it with UIO, but for SPI, I2C, USB, serial, we should have a new subsystem. It should handle not only input, but also similar output devices. It doesn't make sense to have ADCs in one subsystem, and DACs in a different one.
Quoted 8 lines
Quoted 3 lines
* To place within the hwmon subsystem as this is probably closest. (there is already at least one straight ADC driver in hwmon)
Probably not the wisest choice, if nothing else, because the hwmon maintainer is already overloaded. And I don't think that these devices have much in common with the traditional hardware monitoring components anyway.
Agreed, hwmon devices are not really tuned for maximum performance, for example. Performance is often critical in automation control applications.
Quoted 11 lines
I'm not sure what "straight ADC driver" you are referring to, but anything which measures a voltage and exports the reading to user-space is, well, a voltage sensor, and thus fix within hwmon. If the same chip is used for a higher-level, dedicated function then we would probably have a separate driver for it, outside of hwmon.
Quoted 2 lines
* To create a new subsystem, or perhaps merely sysfs class to contain these elements.
Would be OK.
Definitely.
Quoted 6 lines
Or:
* Place these within the input subsystem. You might want to discuss this with the input subsystem maintainer Dmitry Torokhov (Cc'd). The Wii remote is essentially a joystick, and joysticks belong to the input subsystem.
This might apply to some devices, but not all. And the requirements are quite different, I think.
Quoted 5 lines
This all sounds quite different from our hwmon drivers. Our hwmon drivers read all the sensor values at once and cache the readings for a couple seconds, so you can't get an instant reading at any time, and they also don't support interrupts in general.
Exactly.
Thanks,
Hans
-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
Hi Mark,
Quoted 8 lines
Quoted 5 lines
ST Micro LIS3L02DQ 3D accelerometer. SPI device, no buffering, interrupt pin
raised high on new data being available. Currently the driver assumes, if interrupts are enabled, that this is connected to a specified gpio.
(http://www.st.com/stonline/books/pdf/docs/10175.pdf)FWIW: I have this device talking to a PIC-18 and pushing the results over the serial port.
That's certainly interesting and I guess one of the easiest ways of getting data from spi to a desktop machine. I'll admit my interest is more with embedded machines.
Quoted 5 lines
WRT linux support, I can't think of a generalized way to create a driver that would be able to be used with this device in Linux. You need to know witch IRQ line the DR line is connected too, and if you are bit-banging the SPI data off the thing, then you need to know which GPIO's of the host CPU you'll be using.
Yes, and that means we would use the delights of platform data and the generic gpio subsystem. Although I believe generic gpio isn't available on every platform as yet, it is getting there and is certainly in place for ARM (and cleans up an awful lot of hardware interfaces!)
Quoted 3 lines
If you have SPI hardware then
you need to know where to pull the data from. The problem doesn't seem to generalize well.
Yes, the intention would not be to generalize the hardware comms, but rather the interface on the user side. This is similar to a number of other subsystems such as hwmon, where you share functionality as much as possible, but allow very different approaches to things like actual hardware register reads as and when they are necessary.
Quoted 3 lines
Also, If you are playing with accelerometer data, you likely need some real time support or at lest a reliable time stamping of the data to do anything interesting.
Definitely. Obviously the accuracy of this time stamp is going to be limited by the variable nature of when an interrupt handler picks it up, but knowledge of the device specs can allow filtering of this timing data. This is certainly something we would want to consider at a later date although it may well be more sensible to leave this to userspace applications.
Quoted 3 lines
Another problem area is around SPI itself. There are variations of device implementations around chip select polarity, clock biasing (rising,falling, or midpoint) sampling from one SPI part to the next.
Indeed. This is well handled by the SPI subsystem. I've spent far too much time with a scope recently fiddling with these parameters for badly documented chips!
Quoted 10 lines
Quoted 8 lines
VTI SCA3000 E05 3D accelerometer equiped with substantial ring buffer. SPI device. Can operate either in buffered or direct mode. In buffered mode, interrupts
can be used to indicate when the ring buffer is 3/4 full triggering a download to
a larger ring buffer in the kernel if necessary.
(http://www.vti.fi/en/products-solutions/products/accelerometers/sca3000-accelerometers/)ring buffered data can make RT applications harder...
Agreed. With this sort of device two modes would be needed (and are supported by the hardware). The first gives direct data access and the second uses the ring buffer. Which you use would obviously be dependent on the application. Some applications want the most recent data on all occasions, whilst some will be more interested in ensuring that all data is captured.
Quoted 9 lines
Quoted 4 lines
Would be nice if practical to allow the framework to include RS232 devices such
as those from www.xsens.com, www.isense.com and others.I'm not sure what you are asking for, you started off with SPI driver for interfacing a handful of accelerometer devices. Now your talking about the serial port.
The question here is concerned with standardising mainly the userspace interfaces (and hardware interfaces only when appropriate). Some of these devices (the ST accel above for example) support multiple hardware interfaces specs (I2C and SPI for that one). So in a similar way to it making sense to group all TV adapters irrespective of how they are interfaced to the computer, in order to ensure a consistent interface to user space, it makes sense to share these interfaces amongst drivers talking to these devices irrespective of what their hardware interface is.
Quoted 3 lines
Besides the consumer of accelerometer data is user space applications (mine attempt to be somewhat RT applications)
Thanks,
--
Jonathan Cameron
-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
Hi Hans and Jean,
Thanks for your responses.
Quoted 23 lines · Jean Delvare
Quoted 22 lines
Hi Jonathan,
Quoted 17 lines · Jonathan Cameron
This email is basically a request for opinions on how and where such sensors should be integrated into the kernel.
To set the scene...
Increasing numbers of embedded devices are being supplied attached MEMS devices (www.xbow.com imote2 etc). Along with more traditional sensors such as ADC's not being used for hardware monitoring, these do not really seem to fit with in an particular subsystem of the kernel. A previous discussion on lkml in 2006 considered the accelerometers to be found within some laptop hard drives, but I haven't been able to track down any more general discussions of such non hardware monitoring sensors.
The obvious possibilities are:
* To place the various drivers within the spi / i2c etc subsystems as relevant.
Quoted 7 lines
Quoted 7 lines
Bad idea. Grouping drivers by connectivity is almost always the wrong thing to do, as it means that different persons will maintain them and they have all chances to diverge. You really want to group drivers by functionality. On top of that, I am busy enough maintaining the i2c core and bus drivers without having more i2c device drivers added to my plate. These days I am trying to _empty_
drivers/i2c/chips, if anything.
I can certainly see your point there.
Quoted 3 lines
100% ACK. And the functionality here is something like "industrial control" or "automation I/O".
Hmm.. Going to be interesting coming up with a name! Guess that can come at a
later stage anyway.
Quoted 6 lines
If this sort of hardware appears as device
with mappable memory, we can handle it with UIO, but for SPI, I2C, USB, serial, we should have a new subsystem. It should handle not only input, but also similar output devices. It doesn't make sense to have ADCs in one subsystem, and DACs in a different one.
Definitely agreed that it makes sense to put DACs and ADCs in the same general place and obviously there are plenty of devices out there that do both.
Quoted 9 lines
Quoted 8 lines
Quoted 3 lines
* To place within the hwmon subsystem as this is probably closest. (there is already at least one straight ADC driver in hwmon)
Probably not the wisest choice, if nothing else, because the hwmon maintainer is already overloaded. And I don't think that these devices have much in common with the traditional hardware monitoring components anyway.
Quoted 4 lines
Agreed, hwmon devices are not really tuned for maximum performance, for example. Performance is often critical in automation control applications.
It would indeed by stretching the point to make drivers in that subsystem have more performance critical drivers! We seem to have a consensus that neither hwmon or i2c/chips is good idea.
Quoted 17 lines
Quoted 7 lines
I'm not sure what "straight ADC driver" you are referring to, but anything which measures a voltage and exports the reading to user-space is, well, a voltage sensor, and thus fix within hwmon. If the same chip is used for a higher-level, dedicated function then we would probably have a separate driver for it, outside of hwmon.
Quoted 5 lines
Quoted 3 lines
* To create a new subsystem, or perhaps merely sysfs class to contain these elements.
Would be OK.
Definitely.
Quoted 2 lines
Or:
Quoted 9 lines
Quoted 5 lines
* Place these within the input subsystem. You might want to discuss this with the input subsystem maintainer Dmitry Torokhov (Cc'd). The Wii remote is essentially a joystick, and joysticks belong to the input subsystem.
This might apply to some devices, but not all. And the requirements are quite different, I think.
Although I don't know much about the input subsystem it doesn't seem likely that all the devices we are considering would share all that much functionality with the devices in there, particularly if as you have suggested, we include DACs.
Quoted 8 lines
Quoted 5 lines
This all sounds quite different from our hwmon drivers. Our hwmon drivers read all the sensor values at once and cache the readings for a couple seconds, so you can't get an instant reading at any time, and they also don't support interrupts in general.
Exactly.
Ok, so the consensus so far is we are looking at a new subsystem. Will give this a few more days on the lists, then if the consensus is still heading that way, I'll have a think about exact functionality this would need. I guess it would be something that would probably evolve for some time, centered around an initial half dozen or so drivers.
Thanks for all your comments,
--
Jonathan Cameron
Quoted 3 lines · Jonathan Cameron
Definitely agreed that it makes sense to put DACs and ADCs in the same general place and obviously there are plenty of devices out there that do both.
Note that hardware monitoring chips can include ADCs and DACs: the former to monitor system voltages, and the later to control fans (most chips use PWM for that but a few use DACs.) ADCs and DACs are, much like GPIOs, usable for a variety of different purposes. I doubt that there would be any benefit in abstracting DACs and ADCs the way we did for GPIOs, but the important point here is that we really want to group the drivers according to their functionality and not technical implementation details.
Signature · 1 line
Jean Delvare
Quoted 48 lines · Jean Delvare
Hi Jonathan,
Quoted 16 lines · Jonathan Cameron
This email is basically a request for opinions on how and where such sensors should be integrated into the kernel.
To set the scene...
Increasing numbers of embedded devices are being supplied attached MEMS devices (www.xbow.com imote2 etc). Along with more traditional sensors such as ADC's not being used for hardware monitoring, these do not really seem to
fit with in an particular subsystem of the kernel. A previous discussion on
lkml in 2006 considered the accelerometers to be found within some laptop hard drives, but I haven't been able to track down any more general discussions
of such non hardware monitoring sensors.Quoted 4 lines
The obvious possibilities are:
* To place the various drivers within the spi / i2c etc subsystems as relevant.
Bad idea. Grouping drivers by connectivity is almost always the wrong thing to do, as it means that different persons will maintain them and they have all chances to diverge. You really want to group drivers by functionality. On top of that, I am busy enough maintaining the i2c core and bus drivers without having more i2c device drivers added to my plate. These days I am trying to _empty_
drivers/i2c/chips, if anything.Quoted 2 lines
* To place within the hwmon subsystem as this is probably closest. (there is already at least one straight ADC driver in hwmon)
Probably not the wisest choice, if nothing else, because the hwmon maintainer is already overloaded. And I don't think that these devices have much in common with the traditional hardware monitoring components anyway.
I'm not sure what "straight ADC driver" you are referring to, but anything which measures a voltage and exports the reading to user-space is, well, a voltage sensor, and thus fix within hwmon. If the same chip is used for a higher-level, dedicated function then we would probably have a separate driver for it, outside of hwmon.
Quoted 2 lines
* To create a new subsystem, or perhaps merely sysfs class to contain these elements.
Quoted 7 lines
Would be OK. Or:
* Place these within the input subsystem. You might want to discuss this with the input subsystem maintainer Dmitry Torokhov (Cc'd). The Wii remote is essentially a joystick, and joysticks belong to the input subsystem.
I don't think that input subsystem woudl be the best choice. While we do support the event-driven mechanism for delivering information to userspace input is mostly oriented for human interface devices, not general data acquisition. If anything input_dev is too fat. Another thing is that input layer anonymizes input devices, makes them capability-oriented. I.e. we dont really care what model of joystick we have, we want something that reports ABS_X, ABS_Y, BTN_FIRE and userpsace can use it whether it a simple analog joystick or something fancy and USB connected. For your purposes you probably do want to know what the device is and what exactly being sampled/measured.
I'd go with a lean and mean new subsytem.
Signature · 6 lines
Dmitry ------------------------------------------------------------------------- This SF.net email is sponsored by: Microsoft Defy all challenges. Microsoft(R) Visual Studio 2008. http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
Quoted 11 lines · Dmitry Torokhov
I don't think that input subsystem woudl be the best choice. While we do support the event-driven mechanism for delivering information to userspace input is mostly oriented for human interface devices, not general data acquisition. If anything
input_devis too fat. Another thing is that input layer anonymizes input devices, makes them capability-oriented. I.e. we dont really care what model of joystick we have, we want something that reportsABS_X,ABS_Y,BTN_FIREand userpsace can use it whether it a simple analog joystick or something fancy and USB connected. For your purposes you probably do want to know what the device is and what exactly being sampled/measured.
Quoted 1 line
I'd go with a lean and mean new subsytem.
Agreed. I have put some thought on it in the past, and while the input subsystem is the only thing even remotely usable for this *right now*, a new subsystem for data acquisition would be the best way forward.
Signature · 4 lines
"One disk to rule them all, One disk to find them. One disk to bring them all and in the darkness grind them. In the Land of Redmond where the shadows lie." -- The Silicon Valley Tarot Henrique Holschuh
Quoted 4 lines · Jean Delvare
This all sounds quite different from our hwmon drivers. Our hwmon drivers read all the sensor values at once and cache the readings for a couple seconds, so you can't get an instant reading at any time, and they also don't support interrupts in general.
That's something of an issue when the hardware monitor triggers alarms though, right? I couldn't figure out how to get a TMP75 alert out to any userspace code that would care, to pick one example, even after teaching the i2c core how to handle SMBus alerts. ;)
I suppose this just emphasizes the point made by Hans that we kind of need (industrial) "control" components (or "data acquisition"?) not just "monitoring" ones.
Such alarms are of course different from the "data ready" signals of an accelerometer.
- Dave
-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
Quoted 4 lines · mark gross
Quoted 1 line
ST Micro LIS3L02DQ 3D accelerometer. ...
FWIW: I have this device talking to a PIC-18 and pushing the results over the serial port.
Jonathan neglected to mention that he's already sent a driver for this to the SPI list. ;)
Which is part of the reason for asking this question. Right now that driver sits in drivers/spi/lis3l02dq.c but that is probably not its best long-term domicile.
Quoted 7 lines
WRT linux support, I can't think of a generalized way to create a driver that would be able to be used with this device in Linux. You need to know witch IRQ line the DR line is connected too, and if you are bit-banging the SPI data off the thing, then you need to know which GPIO's of the host CPU you'll be using. If you have SPI hardware then you need to know where to pull the data from. The problem doesn't seem to generalize well.
I guess I don't follow. The SPI framework handles all that stuff already, even if you're bitbanging. Though to be sure, if you're bitbanging SPI you want your platform to be able to inline those GPIO calls so those inner loops only take a few instructions per bit ... also solved! :)
Quoted 3 lines
Also, If you are playing with accelerometer data, you likely need some real time support or at lest a reliable time stamping of the data to do anything interesting.
True. I imagine a few other such issues will appear once more folk than Jonathan are using these sorts of sensors on Linux. I'd expect the sample stream to have internal timestamps for truly critical systems, unless variability in when the host makes timestamps is not really an issue.
Quoted 3 lines
Another problem area is around SPI itself. There are variations of device implementations around chip select polarity, clock biasing (rising,falling, or midpoint) sampling from one SPI part to the next.
Midpoint? That's not one I've come across before. All four standard SPI clock/sample/shift modes are already supported in the SPI framework though. Ditto active-high chipselects (vs normal active-low) etc.
- Dave
-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
Hi David,
Quoted 12 lines · Jean Delvare
Quoted 4 lines
This all sounds quite different from our hwmon drivers. Our hwmon drivers read all the sensor values at once and cache the readings for a couple seconds, so you can't get an instant reading at any time, and they also don't support interrupts in general.
That's something of an issue when the hardware monitor triggers alarms though, right? I couldn't figure out how to get a TMP75 alert out to any userspace code that would care, to pick one example, even after teaching the i2c core how to handle SMBus alerts. ;)
Quoted 3 lines
I suppose this just emphasizes the point made by Hans that we kind of need (industrial) "control" components (or "data acquisition"?) not just "monitoring" ones.
I get the feeling even the name is going to evolve for some time to come, getting broader as and when we add more classes of device.
Quoted 2 lines
Such alarms are of course different from the "data ready" signals of an accelerometer.
Whilst this is true, most accelerometers also have "alarm" triggers, for example the ST LIS3L02DQ will raise a pin on configurable conditions such as thresholds and even a double click detector (though I've never tried them!). I suppose we will ideally support this functionality as well.
--
Jonathan Cameron
-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
Dear All,
This email is intended to summarize the results of the discussions over the last week or so and to open up to further comments on the way foward.
The original question was related to garnering opinions on how and where to support devices such as accelerometers, gyros, general purpose ADCs (and possibly DACs). Typical interfaces are SPI and I2C, rates varying from 10Hz to many kHz. Real time and buffered access needed depending on application.
Conclusions:
1. The hwmon subsystem is unsuitable as it is intended to provide
relatively low frequency cached updates of sensor readings.
2. Definitely a bad idea to simply put such drivers in the relevant bus subsystems due to unmaintainability and probable long term interface divergence due to differing maintainers.
3. Whilst input subsystem is probably the only place that these sorts of device could be currently included this would come at the cost of input_dev being too fat and undesirable anonymization of the devices
4. Some stuff to be learned from comedi project (www.comedi.org). Based on a quick browse of their documentation it looks like there may be stuff to learn on what sort of userspace interfaces are interesting but the drivers themselves are (as Matt originally stated) io-port based.
5. General consensus seems to be on a new subsytem (we'll bash out a suitable name later - for now I don't want a name effectively guiding the functionality!)
What's next
Obviously the exact functionality of this subsystem is going to be somewhat up in the air until we have a wide range of devices supported.
The minimum needed seems to be a control interface to configure the devices and some level of event interface (similar to input subsystem) to indicate to
userspace programs that something of interest to them has occured. As configuration of the devices is a relatively infrequent event (at least in the applications I work with), it seems to me that a suitable sys
interface, under a new class would provide this.
Types of parameter:
Chip related:
read/write -- Offsets, gains, sensor biases.
read only -- Factory set versions of the above, version numbers etc.
Mode related:
Some chips will operative in buffered and unbuffered modes. Things like single ended vs differential modes on ADCs.
Interface related:
Like the input subsystem, things like parameters of an associated character device, and the type of events this may return. This would allow different complexities of event depending on what is going on. Down the line this may
allow the turning off and on of individual events as appropriate. For example,
if no-one is interested in an interrupt event such as freefall detection of an
accelerometer then depending on hardware support we may be a) able to turn it off and free the relevant interrupt, or b) simply free the relevant interrupt
and ignore the event.
Simple read of current value:
As the devices will not always be generating interrupts, it probably also makes
sense to have interfaces here to get the current values of readings. Either this
will be from a cached value in an interrupt providing device, or actually initialise
a read from the device if appropriate.
The other interface element would be a stripped down /dev/ device similar to those
used by the input subsystem. However, it may make sense to have an independent one
of these for each and every chip present? Does it make sense to ever aggregate these,
or should this effectively be left to select calls in the userspace code? There is also an
issue here of whether we want to group similar devices. I.e. should we group all
accelerometers? My personal view is, not at the moment as it would complicate the
handling of devices combining several types of sensor.
The fun bit of this subsystem will be in how buffering of incoming data is accomplished.
As an example, lets say we want a 100Hz set of readings from the device. Several
possibilities exist:
a) The device itself has a ring buffer (the VTI accelerometers are an example of this).
If this is the case, how would people suggest we go about reading from the ring buffer in
the event of an interrupt (typically 3/4 full). We could have a the kernel module interpret
this interrupt and effectively fill a ring buffer in the kernel from the hardware one. This
is efficient on interrupts and the kernel based ring buffer could have a size controllable
through the sys interface.
b) The device triggers an interrupt on each 'data ready' after sampling some analog
measurement. Do we generate an event on each of these? (seems like overkill to me)
or again use a ring buffer in the kernel to store the results and perhaps send an event
out after a (sysfs interface controlled) number of readings. If a near real-time app is
wanting the data, then this would be set to zero to indicate need to send an event on each
reading. The ST LIS3L02DQ accelerometer falls into this category. Complexities here
are concerned with the need to look directly at the relevant gpio value in order to establish
whether another even has occured before the bottom half of the interrupt has run. See
the LIS3L02DQ driver I posted to the spi-devel mailing list for an example.
c) The device samples only on a request over the bus. Either these could only be read
from via the sysfs interface or an event sent through the dev character device.
Also feasible would be a board specific element of the platform_data, perhaps specifying
functions to initialize a hardware periodic clock interrupt or similar (I've done this before, but it was clunky - at high rates you frequently miss interrupts.)
The MAX123x and MAX1363 ADCs fall into this category.
Obviously the challenge in all this is to keep the number of interrupts and indeed events (in
the input subsystem sense of sending to userspace via a char device) to a minimum.
For other issues such as time stamping, whilst vital, to a certain extent may need to be
handled within largely within the individual drivers (due to the different types of read above).
Clearly the subsystem should provide helper functions for this wherever possible.
All comments welcome and thanks to everyone who contributed to the original discussion.
--
Jonathan Cameron
-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
On Wed, May 21, 2008 at 10:40:50AM +0100, Jonathan Cameron wrote:
First I'm sorry for not checking my email for a week and the late reply.
Quoted 26 lines
Hi Mark,
Quoted 7 lines
Quoted 5 lines
ST Micro LIS3L02DQ 3D accelerometer. SPI device, no buffering, interrupt pin
raised high on new data being available. Currently the driver assumes, if interrupts are enabled, that this is connected to a specified gpio.
(http://www.st.com/stonline/books/pdf/docs/10175.pdf)FWIW: I have this device talking to a PIC-18 and pushing the results over the serial port.
That's certainly interesting and I guess one of the easiest ways of getting data from spi to a desktop machine. I'll admit my interest is more with embedded machines.
Quoted 5 lines
WRT linux support, I can't think of a generalized way to create a driver that would be able to be used with this device in Linux. You need to know witch IRQ line the DR line is connected too, and if you are bit-banging the SPI data off the thing, then you need to know which GPIO's of the host CPU you'll be using.
Yes, and that means we would use the delights of platform data and the generic gpio subsystem. Although I believe generic gpio isn't available on every platform as yet, it is getting there and is certainly in place for ARM (and cleans up an awful lot of hardware interfaces!)
Quoted 3 lines
If you have SPI hardware then
you need to know where to pull the data from. The problem doesn't seem to generalize well.
Quoted 6 lines
Yes, the intention would not be to generalize the hardware comms, but rather the
interface on the user side. This is similar to a number of other subsystems such as hwmon, where you share functionality as much as possible, but allow very different approaches to things like actual hardware register reads as and when they are necessary.
Ok, say the HW SPI is pushed down to some lower level driver. These things send streaming data, and sometimes signals (free-fall detect) out of band WRT the SPI comms.
I would like to see how a higher level API could encapsulate the generalization of a class of such devices.
Also, I'm not sure how one could generalize SPI communications at a high level given its bi-directional nature.
I guess I need to see some header files showing what you are thinking about.
Keep in mind that one abstraction of these devices is they are simply streaming A2D 16 bit data values over SPI (or I2C). The size of the data set is a function of the sensor axes.
Quoted 43 lines
Quoted 4 lines
Also, If you are playing with accelerometer data, you likely need some real time support or at lest a reliable time stamping of the data to do anything interesting.
Definitely. Obviously the accuracy of this time stamp is going to be limited by
the variable nature of when an interrupt handler picks it up, but knowledge of the device specs can allow filtering of this timing data. This is certainly something we would want to consider at a later date although it may well be more sensible to leave this to userspace applications.Quoted 3 lines
Another problem area is around SPI itself. There are variations of device implementations around chip select polarity, clock biasing (rising,falling, or midpoint) sampling from one SPI part to the next.
Indeed. This is well handled by the SPI subsystem. I've spent far too much time with a scope recently fiddling with these parameters for badly documented chips!
Quoted 10 lines
Quoted 9 lines
VTI SCA3000 E05 3D accelerometer equiped with substantial ring buffer. SPI
device. Can operate either in buffered or direct mode. In buffered mode, interrupts
can be used to indicate when the ring buffer is 3/4 full triggering a download to
a larger ring buffer in the kernel if necessary.
(http://www.vti.fi/en/products-solutions/products/accelerometers/sca3000-accelerometers/)ring buffered data can make RT applications harder...
Agreed. With this sort of device two modes would be needed (and are supported by the hardware). The first gives direct data access and the second uses the ring buffer. Which you use would obviously be dependent on the application. Some applications want the most recent data on all occasions, whilst some will be more interested in ensuring that all data is captured.
Quoted 7 lines
Quoted 4 lines
Would be nice if practical to allow the framework to include RS232 devices such
as those from www.xsens.com, www.isense.com and others.I'm not sure what you are asking for, you started off with SPI driver for interfacing a handful of accelerometer devices. Now your talking about the serial port.
Quoted 8 lines
The question here is concerned with standardising mainly the userspace interfaces (and hardware interfaces only when appropriate). Some of these devices (the ST accel above for example) support multiple hardware interfaces specs (I2C and SPI for that one). So in a similar way to it making sense to group all TV adapters irrespective of how they are interfaced to the computer, in order to ensure a consistent interface to user space, it makes sense to share these interfaces amongst drivers talking to these devices irrespective of what their hardware interface is.
I guess I need to see some header files to see where you are going with this idea. To be useful you'll also need to handle rotation sensors and communicate the temperature bias's up the stack too.
good luck keep me posted on where your going with this, it is interesting to me.
--mgross
Quoted 7 lines
Quoted 2 lines
Besides the consumer of accelerometer data is user space applications (mine attempt to be somewhat RT applications)
Thanks,
--
Jonathan Cameron
Quoted 22 lines · David Brownell
Quoted 4 lines · mark gross
Quoted 1 line
ST Micro LIS3L02DQ 3D accelerometer. ...
FWIW: I have this device talking to a PIC-18 and pushing the results over the serial port.
Jonathan neglected to mention that he's already sent a driver for this to the SPI list. ;)
Which is part of the reason for asking this question. Right now that driver sits in
drivers/spi/lis3l02dq.cbut that is probably not its best long-term domicile.Quoted 7 lines
WRT linux support, I can't think of a generalized way to create a driver that would be able to be used with this device in Linux. You need to know witch IRQ line the DR line is connected too, and if you are bit-banging the SPI data off the thing, then you need to know which GPIO's of the host CPU you'll be using. If you have SPI hardware then you need to know where to pull the data from. The problem doesn't seem to generalize well.
Quoted 6 lines
I guess I don't follow. The SPI framework handles all that stuff already, even if you're bitbanging. Though to be sure, if you're bitbanging SPI you want your platform to be able to inline those GPIO calls so those inner loops only take a few instructions per bit ... also solved! :)
I'll take a look sometime soon.
Quoted 11 lines
Quoted 4 lines
Also, If you are playing with accelerometer data, you likely need some real time support or at lest a reliable time stamping of the data to do anything interesting.
True. I imagine a few other such issues will appear once more folk than Jonathan are using these sorts of sensors on Linux. I'd expect the sample stream to have internal timestamps for truly critical systems, unless variability in when the host makes timestamps is not really an issue.
Its on my list of things to do..
Quoted 9 lines
Quoted 4 lines
Another problem area is around SPI itself. There are variations of device implementations around chip select polarity, clock biasing (rising,falling, or midpoint) sampling from one SPI part to the next.
Midpoint? That's not one I've come across before. All four standard SPI clock/sample/shift modes are already supported in the SPI framework though. Ditto active-high chipselects (vs normal active-low) etc.
Yeah, its one of the sampling modes for the PIC18F4455 its one of the master mode sampling options (see page 194 of
http://ww1.microchip.com/downloads/en/DeviceDoc/39632D.pdf )
--mgross
Hi Jonathan,
Quoted 27 lines · Jonathan Cameron
This email is basically a request for opinions on how and where such sensors should be integrated into the kernel.
To set the scene...
Increasing numbers of embedded devices are being supplied attached MEMS devices (www.xbow.com imote2 etc). Along with more traditional sensors such as ADC's not being used for hardware monitoring, these do not really seem to
fit with in an particular subsystem of the kernel. A previous discussion on
lkml in 2006 considered the accelerometers to be found within some laptop hard drives, but I haven't been able to track down any more general discussions
of such non hardware monitoring sensors.The obvious possibilities are:
* To place the various drivers within the spi / i2c etc subsystems as relevant.
* To place within the hwmon subsystem as this is probably closest. (there is already at least one straight ADC driver in hwmon)
* To create a new subsystem, or perhaps merely sysfs class to contain these elements.
Quoted 9 lines
Typical requirements within an application include simply polling for current
readings, and using device triggered interrupts to grab data continuously to a
ring buffer, for collection by suitable userspace code. Obviously it would be
desirable to standardize sysfs controls for various calibration parameters as
much as possible across the various devices.
Also, I'd mention that most ADC devices could report in "bunched" mode, i.e.
1. Request ADC readings from pins X, Y, Z1, Z2.
2. Wait for single IRQ
3. Read all the results
At handhelds.org, we've wrote quite good (I think) ADC subsystem, that keeps in mind ADC capabilities. It implements two interfaces:
in-kernel (e.g. for touchscreen drivers), and userspace interface via sysfs. I was planning to implement drivers/input/ interface too.
I always don't find time to clean it up and submit, though.
Here is ADC subsystem itself:
http://handhelds.org/cgi-bin/cvsweb.cgi/~checkout~/linux/kernel26/drivers/misc/adc/adc.c
http://handhelds.org/cgi-bin/cvsweb.cgi/~checkout~/linux/kernel26/include/linux/adc.h
^ It is in drivers/misc/, but I think better placement would be
drivers/adc.
Some drivers for this subsystem:
http://handhelds.org/cgi-bin/cvsweb.cgi/~checkout~/linux/kernel26/drivers/misc/adc/ads7846_adc_ssp.c
^ ADC driver for ADS7846 chips (HP iPaq hx4700 and some HTC phones, the
driver is using SSP subsystem, switching it to the SPI is still in my enless TODO list).
http://handhelds.org/cgi-bin/cvsweb.cgi/~checkout~/linux/kernel26/drivers/misc/adc/samcop_adc.c
^ SAMCOP (HP iPaq H5xxx) ADC driver.
http://handhelds.org/cgi-bin/cvsweb.cgi/~checkout~/linux/kernel26/drivers/misc/adc/tsc2200_adc_ssp.c
^ TSC2200 ADC driver (used AFAIK in some HTC phones, or ASUS handhelds).
http://handhelds.org/cgi-bin/cvsweb.cgi/~checkout~/linux/kernel26/drivers/misc/adc/ad7877.c
^ AD7877 ADC driver (HTC phones too, IIRC).
Now, The Generic ADC Touchscreen Driver (tested to work quite good with all above ADC drivers on appropriate hardware):
http://handhelds.org/cgi-bin/cvsweb.cgi/~checkout~/linux/kernel26/drivers/input/touchscreen/ts-adc.c
And finally, ADC Battery driver ("backup" batteries in the iPaq devices usually report their voltage via ADC chip, the same used by the touchscreen).
http://handhelds.org/cgi-bin/cvsweb.cgi/~checkout~/linux/kernel26/drivers/power/adc_battery.c
p.s.
I have more recent (for current Linus' tree) code for ADC subsystem, but it still needs some love to be submittable.
Signature · 8 lines
Anton Vorontsov email: [email protected] irc://irc.freenode.net/bd2 ------------------------------------------------------------------------- This SF.net email is sponsored by: Microsoft Defy all challenges. Microsoft(R) Visual Studio 2008. http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
Quoted 39 lines · Anton Vorontsov
Hi Jonathan,
Quoted 36 lines · Jonathan Cameron
This email is basically a request for opinions on how and where such sensors should be integrated into the kernel.
To set the scene...
Increasing numbers of embedded devices are being supplied attached MEMS devices (www.xbow.com imote2 etc). Along with more traditional sensors such as ADC's not being used for hardware monitoring, these do not really seem to
fit with in an particular subsystem of the kernel. A previous discussion on
lkml in 2006 considered the accelerometers to be found within some laptop hard drives, but I haven't been able to track down any more general discussions
of such non hardware monitoring sensors.The obvious possibilities are:
* To place the various drivers within the spi / i2c etc subsystems as relevant.
* To place within the hwmon subsystem as this is probably closest. (there is already at least one straight ADC driver in hwmon)
* To create a new subsystem, or perhaps merely sysfs class to contain these elements.
Typical requirements within an application include simply polling for current
readings, and using device triggered interrupts to grab data continuously to a
ring buffer, for collection by suitable userspace code. Obviously it would be
desirable to standardize sysfs controls for various calibration parameters as
much as possible across the various devices.
The two drivers i've seen so far use the input subsystem to report their data to the user. I'm working on an driver for the SMB380 which can be both i2c and spi.
Quoted 11 lines
Also, I'd mention that most ADC devices could report in "bunched" mode, i.e.
1. Request ADC readings from pins X, Y, Z1, Z2.
2. Wait for single IRQ
3. Read all the resultsAt handhelds.org, we've wrote quite good (I think) ADC subsystem, that keeps in mind ADC capabilities. It implements two interfaces:
in-kernel (e.g. for touchscreen drivers), and userspace interface via sysfs. I was planning to implementdrivers/input/interface too.
handhelds.org's track history of getting things into the kernel is poor.
Signature · 5 lines
-- Ben Q: What's a light-year? A: One-third less calories than a regular year.
Quoted 52 lines · Ben Dooks
Quoted 39 lines · Anton Vorontsov
Hi Jonathan,
Quoted 36 lines · Jonathan Cameron
This email is basically a request for opinions on how and where such sensors should be integrated into the kernel.
To set the scene...
Increasing numbers of embedded devices are being supplied attached MEMS devices (www.xbow.com imote2 etc). Along with more traditional sensors such as ADC's not being used for hardware monitoring, these do not really seem to
fit with in an particular subsystem of the kernel. A previous discussion on
lkml in 2006 considered the accelerometers to be found within some laptop hard drives, but I haven't been able to track down any more general discussions
of such non hardware monitoring sensors.The obvious possibilities are:
* To place the various drivers within the spi / i2c etc subsystems as relevant.
* To place within the hwmon subsystem as this is probably closest. (there is already at least one straight ADC driver in hwmon)
* To create a new subsystem, or perhaps merely sysfs class to contain these elements.
Typical requirements within an application include simply polling for current
readings, and using device triggered interrupts to grab data continuously to a
ring buffer, for collection by suitable userspace code. Obviously it would be
desirable to standardize sysfs controls for various calibration parameters as
much as possible across the various devices.The two drivers i've seen so far use the input subsystem to report their data to the user. I'm working on an driver for the SMB380 which can be both i2c and spi.
Quoted 7 lines
Also, I'd mention that most ADC devices could report in "bunched" mode, i.e.
1. Request ADC readings from pins X, Y, Z1, Z2.
2. Wait for single IRQ
3. Read all the results
Quoted 7 lines
Quoted 4 lines
At handhelds.org, we've wrote quite good (I think) ADC subsystem, that keeps in mind ADC capabilities. It implements two interfaces:
in-kernel (e.g. for touchscreen drivers), and userspace interface via sysfs. I was planning to implementdrivers/input/interface too.handhelds.org's track history of getting things into the kernel is poor.
Yes, mostly. Because lack of human resources. But something gets done anyway, e.g. drivers/power/ is already in the mainline. Philipp Zabel is doing great work for the HTC Magician support (already in mainline, too).
I think there are only few of us who think that mainlining is important, this is bad. But the thinking improves as times goes by.
So, don't be so pessimistic. :-)
Signature · 3 lines
Anton Vorontsov email: [email protected] irc://irc.freenode.net/bd2
Quoted 25 lines · Dmitry Torokhov
Quoted 24 lines · Jean Delvare
Hi Jonathan,
Quoted 20 lines · Jonathan Cameron
This email is basically a request for opinions on how and where such sensors should be integrated into the kernel.
To set the scene...
Increasing numbers of embedded devices are being supplied attached MEMS devices (www.xbow.com imote2 etc). Along with more traditional sensors such as ADC's not being used for hardware monitoring, these do not really seem to
fit with in an particular subsystem of the kernel. A previous discussion on
lkml in 2006 considered the accelerometers to be found within some laptop hard drives, but I haven't been able to track down any more general discussions
of such non hardware monitoring sensors.The obvious possibilities are:
* To place the various drivers within the spi / i2c etc subsystems as relevant.
Quoted 6 lines
Quoted 6 lines
Bad idea. Grouping drivers by connectivity is almost always the wrong thing to do, as it means that different persons will maintain them and they have all chances to diverge. You really want to group drivers by functionality. On top of that, I am busy enough maintaining the i2c core and bus drivers without having more i2c device drivers added to my plate. These days I am trying to _empty_
drivers/i2c/chips, if anything.
I concur for these sorts of devices, where the connectivity to the device is quite an easy part of the driver, thus you end up with tiny little bus drivers all over the place, and a main core driver. The kernel build system should allow easy selection of interface depending on what is available without huge #ifdef hacks. An example could be:
Makefile:
mysensor-y := mysensor-core.o
mysensor-$(CONFIG_SPI) += mysensor-spi.o
mysensor-$(CONFIG_I2C) += mysensor-i2c.o
obj-$(CONFIG_MYSENSOR) += mysensor.o
Quoted 25 lines
Quoted 17 lines
Quoted 2 lines
* To place within the hwmon subsystem as this is probably closest. (there is already at least one straight ADC driver in hwmon)
Probably not the wisest choice, if nothing else, because the hwmon maintainer is already overloaded. And I don't think that these devices have much in common with the traditional hardware monitoring components anyway.
I'm not sure what "straight ADC driver" you are referring to, but anything which measures a voltage and exports the reading to user-space is, well, a voltage sensor, and thus fix within hwmon. If the same chip is used for a higher-level, dedicated function then we would probably have a separate driver for it, outside of hwmon.
Quoted 2 lines
* To create a new subsystem, or perhaps merely sysfs class to contain these elements.
Quoted 7 lines
Would be OK. Or:
* Place these within the input subsystem. You might want to discuss this with the input subsystem maintainer Dmitry Torokhov (Cc'd). The Wii remote is essentially a joystick, and joysticks belong to the input subsystem.
Quoted 10 lines
I don't think that input subsystem woudl be the best choice. While we do support the event-driven mechanism for delivering information to userspace input is mostly oriented for human interface devices, not general data acquisition. If anything
input_devis too fat. Another thing is that input layer anonymizes input devices, makes them capability-oriented. I.e. we dont really care what model of joystick we have, we want something that reportsABS_X,ABS_Y,BTN_FIREand userpsace can use it whether it a simple analog joystick or something fancy and USB connected. For your purposes you probably do want to know what the device is and what exactly being sampled/measured.
Can you explain to me how the input system anonymizes things? I thought it was quite easy to read the name of the device? You could easily add a symlink from the driver's device binding in sysfs to the relevant input device as well.
Also, why would you not want all your accelerometers grouped into a set of accelerometers? If your application software just searches all input devices for anything reporting itself as an accelerometer, then it would get the right result...
Signature · 4 lines
Ben Q: What's a light-year? A: One-third less calories than a regular year.
Hi Anton
Quoted 11 lines
Quoted 10 lines
Typical requirements within an application include simply polling for current
readings, and using device triggered interrupts to grab data continuously to a
ring buffer, for collection by suitable userspace code. Obviously it would be
desirable to standardize sysfs controls for various calibration parameters as
much as possible across the various devices.
Quoted 7 lines
Also, I'd mention that most ADC devices could report in "bunched" mode, i.e.
1. Request ADC readings from pins X, Y, Z1, Z2.
2. Wait for single IRQ
3. Read all the results
Good point. I guess it's going to be a while before we work out an anywhere near
exhaustive list of such events that we might want to be able to control.
Quoted 6 lines
At handhelds.org, we've wrote quite good (I think) ADC subsystem, that keeps in mind ADC capabilities. It implements two interfaces:
in-kernel (e.g. for touchscreen drivers), and userspace interface via sysfs. I was planning to implementdrivers/input/interface too. I always don't find time to clean it up and submit, though.
I know that feeling!
Quoted 6 lines
Here is ADC subsystem itself:
http://handhelds.org/cgi-bin/cvsweb.cgi/~checkout~/linux/kernel26/drivers/misc/adc/adc.c
http://handhelds.org/cgi-bin/cvsweb.cgi/~checkout~/linux/kernel26/include/linux/adc.h
^ It is indrivers/misc/, but I think better placement would be
drivers/adc.
Looking at the code (briefly admittedly, I'll have a closer look tomorrow) it looks like a nice simple and
effective interface.
The question here, is what functionality of the system under discussion does it fulfill. Again we are in the
territory of possibly having multiple drivers for a device depending on how it is being used in the kernel.
Not ideal, but may in fact be more maintainable in the long run.
The sysfs interface looks similar to that I was intending to implement, but obviously for your application you
don't need any of the buffering support etc and it makes sense to keep everything as simple as possible.
Perhaps if we aim to keep in mind the possibility of combining your ADC system with a more general
input device system, it may make sense to do so at a later stage.
Anything I write is certainly going to share a considerable amount of functionality and approach with your code.
Quoted 6 lines
Some drivers for this subsystem:
http://handhelds.org/cgi-bin/cvsweb.cgi/~checkout~/linux/kernel26/drivers/misc/adc/ads7846_adc_ssp.c
^ ADC driver for ADS7846 chips (HP iPaq hx4700 and some HTC phones, the
driver is using SSP subsystem, switching it to the SPI is still in my enless TODO list).
I'll keep these part in mind, as a the moment adding any component for testing involves me getting my soldering iron out
and I hate soldering!
Quoted 13 lines
http://handhelds.org/cgi-bin/cvsweb.cgi/~checkout~/linux/kernel26/drivers/misc/adc/samcop_adc.c
^ SAMCOP (HP iPaq H5xxx) ADC driver.http://handhelds.org/cgi-bin/cvsweb.cgi/~checkout~/linux/kernel26/drivers/misc/adc/tsc2200_adc_ssp.c
^ TSC2200 ADC driver (used AFAIK in some HTC phones, or ASUS handhelds).http://handhelds.org/cgi-bin/cvsweb.cgi/~checkout~/linux/kernel26/drivers/misc/adc/ad7877.c
^ AD7877 ADC driver (HTC phones too, IIRC).Now, The Generic ADC Touchscreen Driver (tested to work quite good with all above ADC drivers on appropriate hardware):
http://handhelds.org/cgi-bin/cvsweb.cgi/~checkout~/linux/kernel26/drivers/input/touchscreen/ts-adc.c
Quoted 9 lines
And finally, ADC Battery driver ("backup" batteries in the iPaq devices usually report their voltage via ADC chip, the same used by the touchscreen).
http://handhelds.org/cgi-bin/cvsweb.cgi/~checkout~/linux/kernel26/drivers/power/adc_battery.cp.s.
I have more recent (for current Linus' tree) code for ADC subsystem, but it still needs some love to be submittable.
Thanks. I'll have a look at the stuff above and pester you if I need a more recent version.
Jonathan
-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
Quoted 5 lines
The two drivers i've seen so far use the input subsystem to report their data to the user. I'm working on an driver for the SMB380 which can be both i2c and spi.
Yes, the ST accel I'm using (LIS3L02DQ) is like that as well, so we definitely need
to implement the ability to do this cleanly!
-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
Quoted 8 lines · Jonathan Cameron
Quoted 5 lines
The two drivers i've seen so far use the input subsystem to report their data to the user. I'm working on an driver for the SMB380 which can be both i2c and spi.
Yes, the ST accel I'm using (LIS3L02DQ) is like that as well, so we definitely need
to implement the ability to do this cleanly!
this would be so much easier to read if word-wrapped to 77 characters per line.
Signature · 10 lines
Ben Q: What's a light-year? A: One-third less calories than a regular year. ------------------------------------------------------------------------- This SF.net email is sponsored by: Microsoft Defy all challenges. Microsoft(R) Visual Studio 2008. http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
Hi Ben,
Quoted 12 lines · Ben Dooks
Quoted 11 lines
I don't think that input subsystem woudl be the best choice. While we do support the event-driven mechanism for delivering information to userspace input is mostly oriented for human interface devices, not general data acquisition. If anything
input_devis too fat. Another thing is that input layer anonymizes input devices, makes them capability-oriented. I.e. we dont really care what model of joystick we have, we want something that reportsABS_X,ABS_Y,BTN_FIREand userpsace can use it whether it a simple analog joystick or something fancy and USB connected. For your purposes you probably do want to know what the device is and what exactly being sampled/measured.
Quoted 5 lines
Can you explain to me how the input system anonymizes things? I thought it was quite easy to read the name of the device? You could easily add a symlink from the driver's device binding in sysfs to the relevant input device as well.
Yes, it is possible to read the name of the device, but I could see with names like "Thermal probe blah" it may not be unique enough. Of course input core also exports phys, sysfs and uniq attributes so there are certainly possibilities for using it.
OTOH input_dev is quite fat and oriented for human interface. It could made work if you create one device per sensor but devices with X sensorts per one device (that provide related readings, like a generic state) would be cludgy... Accelerometers could use ABS_X, ABS_Y.. but what about other devices? ABS_RAW1, ABS_RAW2? And here we run into the conceptual problem, as I see it - in input we try to keep meaning of the event independent from the device it generated. We dont care what generated ABS_X, ABS_Y, BTN_FIRE - it could be a joystick, gamepad, something similar. A program can use it if it knows how handle the above events. The ABS_RAWx would mean different things for every sensor... That's what I meant by anonymizing - the application does not really care about the particular device and where and how it is connected, but only about its capabilities.
Another thing is that (at least now) input supresses duplicate events, which may be undesirable for generic data acquisition device.
I suppose it could be made work. I guess the size of input_dev is my main concern. If you hyave something with hundreds of sensors input_dev might be too expensive.
Quoted 4 lines
Also, why would you not want all your accelerometers grouped into a set of accelerometers? If your application software just searches all input devices for anything reporting itself as an accelerometer, then it would get the right result...
I never said I would not want them to be grouped together.
Signature · 6 lines
Dmitry ------------------------------------------------------------------------- This SF.net email is sponsored by: Microsoft Defy all challenges. Microsoft(R) Visual Studio 2008. http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
Quoted 5 lines · mark gross
Quoted 5 lines
Quoted 4 lines
Another problem area is around SPI itself. There are variations of device implementations around chip select polarity, clock biasing (rising,falling, or midpoint) sampling from one SPI part to the next.
Quoted 8 lines
Quoted 4 lines
Midpoint? That's not one I've come across before. All four standard SPI clock/sample/shift modes are already supported in the SPI framework though. Ditto active-high chipselects (vs normal active-low) etc.
Yeah, its one of the sampling modes for the PIC18F4455 its one of the master mode sampling options (see page 194 of
http://ww1.microchip.com/downloads/en/DeviceDoc/39632D.pdf )
Actually figure 19-3 (p. 198) may be a bit more clear.
Curious. That PIC18F controller has *three* bits ... equivalents of CPOL and CPHA, plus a bit saying whether to wait a whole or half clock after the leading clock edge before sampling it.
A quick survey of some other SPI chips suggests that the most conventional interpretation is to sample on the trailing edge of the clock, and not presume long hold times.
I would surely hope the SPI interface spec doesn't have to get into the mess of timing variations which typify anyone trying to make memory controllers do the Right thing ... *shudder* ...
- Dave
-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
Quoted 5 lines
Ok, say the HW SPI is pushed down to some lower level driver. These things send streaming data, and sometimes signals (free-fall detect) out of band WRT the SPI comms.
Indeed. This would have to handled using interrupts based on the generic gpio interface. (see the LIS3L02DQ driver on the SPI-devel mailing list for an example of how this might work.)
Quoted 8 lines
I would like to see how a higher level API could encapsulate the generalization of a class of such devices.
Also, I'm not sure how one could generalize SPI communications at a high level given its bi-directional nature.
I guess I need to see some header files showing what you are thinking about.
Sure. I'll get something put together and sent out asap. The general form of this is going to look like a combination of the hwmon interface via sysfs and something similar to the input subsystems approach of using events sent over character devices. The interesting bit is going to be working out how to provide fairly generic interface to ring buffers, whether these reside in the kernel or on the device itself.
Quoted 4 lines
Keep in mind that one abstraction of these devices is they are simply streaming A2D 16 bit data values over SPI (or I2C). The size of the data set is a function of the sensor axes.
This is of course true, but there still seem to be some advantages in providing some common interfaces for these devices. Almost all digital interfaced accelerometers share a number of common elements not typically found in ADC's. These include bias and gain as well as commonly found alarm signals.
Actually, on this point, it may well make sense to provide an accelerometer driver that is designed to run on top of any generic ADC driver, thus providing (based on a suitable board specific configuration) userspace access to analog accelerometers connected in this fashion. This is definitely one for some way down the line!
Quoted 50 lines
Quoted 41 lines
Quoted 4 lines
Also, If you are playing with accelerometer data, you likely need some real time support or at lest a reliable time stamping of the data to do anything interesting.
Definitely. Obviously the accuracy of this time stamp is going to be limited by
the variable nature of when an interrupt handler picks it up, but knowledge of the device specs can allow filtering of this timing data. This is certainly something we would want to consider at a later date although it may well be more sensible to leave this to userspace applications.Quoted 3 lines
Another problem area is around SPI itself. There are variations of device implementations around chip select polarity, clock biasing (rising,falling, or midpoint) sampling from one SPI part to the next.
Indeed. This is well handled by the SPI subsystem. I've spent far too much time with a scope recently fiddling with these parameters for badly documented chips!
Quoted 10 lines
Quoted 9 lines
VTI SCA3000 E05 3D accelerometer equiped with substantial ring buffer. SPI
device. Can operate either in buffered or direct mode. In buffered mode, interrupts
can be used to indicate when the ring buffer is 3/4 full triggering a download to
a larger ring buffer in the kernel if necessary.
(http://www.vti.fi/en/products-solutions/products/accelerometers/sca3000-accelerometers/)ring buffered data can make RT applications harder...
Agreed. With this sort of device two modes would be needed (and are supported by the hardware). The first gives direct data access and the second uses the ring buffer. Which you use would obviously be dependent on the application. Some applications want the most recent data on all occasions, whilst some will be more interested in ensuring that all data is captured.
Quoted 6 lines
Quoted 3 lines
Would be nice if practical to allow the framework to include RS232 devices such
as those from www.xsens.com, www.isense.com and others.I'm not sure what you are asking for, you started off with SPI driver for interfacing a handful of accelerometer devices. Now your talking about the serial port.
Quoted 8 lines
The question here is concerned with standardising mainly the userspace interfaces (and hardware interfaces only when appropriate). Some of these devices (the ST accel above for example) support multiple hardware interfaces specs (I2C and SPI for that one). So in a similar way to it making sense to group all TV adapters irrespective of how they are interfaced to the computer, in order to ensure a consistent interface to user space, it makes sense to share these interfaces amongst drivers talking to these devices irrespective of what their hardware interface is.
Quoted 3 lines
I guess I need to see some header files to see where you are going with this idea. To be useful you'll also need to handle rotation sensors and communicate the temperature bias's up the stack too.
Definitely, although to get a reasonable number of devices integrated quickly they may not all support access to everything we would like initially.
Quoted 3 lines
good luck keep me posted on where your going with this, it is interesting to me.
Will do,
--
Jonathan Cameron
Re: Accelerometer etc subsystem (Update on progress)
In reply to Jean DelvareDear All,
This email is mainly to give people an idea of current progress towards a new
subsystem as discussed in the thread starting with
http://lkml.org/lkml/2008/5/20/135
Sorry for the mass list bombardment, but clearly some elements of this discussion
will end up in various different territories.
Some elements of a prototype subsystem are in place. It draws very heavily on parts of the input and hwmon subsystems diverging only where necessary.
The only test driver currently integrated is for an ST LIS3L02DQ accelerometer
which has more than a few quirks to make it tricky to handle (and some what sketchy documentation.) More chips will follow over next week or so but hopefully the driver for this chip gives enough of an idea of how I envision the system working to encourage discussion / advice.
Note that I haven't dealt with anywhere near all the possible locking issues etc and am well aware that this needs to be done. Other cleanups that will need to be done include working out the layout in sysfs to make it more intuitive. Also sorry for the somewhat rough and ready nature of the attached
patch (against 2.6.26-rc4)
Ring buffer design is a large part of the attached patch. I'm not sure if I am going about this the right way. Basically, we need ring buffers with almost no write latency but can waste plenty of time reading from them (in general case - we do however want reading the last available value to be fast). What is there works, but probably has at least a few nasty corner cases that I haven't prevented.
Interfaces (these are per device) - at somepoint a procfs interface similar
to that used in the input subsystem would make device querying simpler.
Sysfs - Parameter Control - gain / offsets etc
State control, turn interrupts on and off etc. Interrupt control parameters (threshold etc)
Ring buffer parameters as relevant (currently fixed) Individual input reading (acceleration values here) Minor numbers for various chrdevs associated with this device.
chrdev- 3 types of chrdev at the moment
Ring buffer events
Ring buffer access (currently ripping data off the buffer only) Interrupt events - for lis3l02dq these are only threshold breaks
Functionality yet to be implemented.
Polled based capture (use a peroidic timer if available)
Hardware ring buffering for devices that support it (two level ring
buffer -
hard and soft may be appropriate)
A chrdev for polling of whole device (with timestamps etc).
Composite interrupt handling (some devices allow logical combinations of different interrupt signals to be used as the trigger condition).
Documenation ;)
Cleaner solution to data alignment in the ring buffer (currently I'm
cheating
and manually doing it)
Lots lots more....
Anyhow, all comments welcome. Can anyone think of a better name? (I'm not keen on industrialio. It's too long if nothing else!
It will do as a working title for now)
Thanks,
--
Jonathan Cameron
drivers/industrialio/Kconfig +27 -0
@@ -0,0 +1,27 @@ +# +# Industrial I/O subsytem configuration +# + +menuconfig INDUSTRIALIO + tristate "Industrial I/O support" + ---help--- + The industrial IO subsystem provides a unified framework for drivers + for many different types of embedded sensors using a number of + different phyiscal interfaces (i2c, spi etc). + + This documentation will need some work! + +if INDUSTRIALIO + +source drivers/industrialio/accelerometer/Kconfig +#source drivers/industrialio/adc/Kconfig +#source drivers/industrialio/misc/Kconfig + +config INDUSTRIALIO_DEBUG_CORE + bool "Industrial I/O Core debugging messages" + help + Say yes here if you want the Industrial I/O core to producte a bunch + of debug messages to the system log. Select this if you are having a + problem with industrial io support and want to see mor eof what is + going on. +endif
drivers/industrialio/Makefile +11 -0
@@ -0,0 +1,11 @@ +# +# Makefile for the industrial I/O core. +# + +obj-$(CONFIG_INDUSTRIALIO) += industrial.o + +obj-y += accelerometer/ + +ifeq ($(CONFIG_INDUSTRIALIO_DEBUG_CORE),y) +EXTRA_CFLAGS += -DDEBUG +endif
drivers/industrialio/accelerometer/Kconfig +24 -0
@@ -0,0 +1,24 @@ +# +# Accelerometer drivers +# + +config LIS3L02DQ + tristate "ST Microelectronics LIS3L02DQ Accelerometer Driver" + help + Say yes here to build generic support for the ST microelectronics + accelerometer. You will also need to one or more of the bus specific + elements below. + +config LIS3L02DQ_SPI + depends on LIS3L02DQ && SPI + tristate "SPI support" + help + Say yes here to build support for the ST LIS3L02DQ accelerometer via + an SPI bus. + +config LIS3L02DQ_I2C + depends on LIS3L02DQ && I2C + tristate "I2C support" + help + Say yes here to build support for the ST LIS3L02DQ accelerometer via + an I2C bus.
drivers/industrialio/accelerometer/Makefile +5 -0
@@ -0,0 +1,5 @@ +# +# Makefile for industrial I/O accelerometer drivers +# + +obj-$(CONFIG_LIS3L02DQ_SPI) += lis3l02dq.o
drivers/industrialio/accelerometer/lis3l02dq.c +1305 -0
1,305 lines not on this page · raw message
drivers/industrialio/accelerometer/lis3l02dq.c_oldfuncs +265 -0
266 lines not on this page · raw message
drivers/industrialio/accelerometer/lis3l02dq.h +183 -0
183 lines not on this page · raw message
drivers/industrialio/adc/Makefile +3 -0
@@ -0,0 +1,3 @@ + +# Makefile for industrial I/O ADC drivers +#
drivers/industrialio/industrial.c +1172 -0
1,172 lines not on this page · raw message
drivers/industrialio/misc/Makefile +3 -0
@@ -0,0 +1,3 @@ +# +# Makefile for industrial I/O misc drivers
Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
Part of the diff is not shown here. View the raw message.
Re: Accelerometer etc subsystem (Update on progress)
Sorry, forgot to include the headers in the original patch. Obviously these are very rough and ready at the moment and if nothing else their overall layout isn't particularly logical.
Quoted 75 lines
Dear All,
This email is mainly to give people an idea of current progress towards a new
subsystem as discussed in the thread starting with
http://lkml.org/lkml/2008/5/20/135Sorry for the mass list bombardment, but clearly some elements of this discussion
will end up in various different territories.Some elements of a prototype subsystem are in place. It draws very heavily on parts of the input and hwmon subsystems diverging only where necessary.
The only test driver currently integrated is for an ST LIS3L02DQ accelerometer
which has more than a few quirks to make it tricky to handle (and some what sketchy documentation.) More chips will follow over next week or so but hopefully the driver for this chip gives enough of an idea of how I envision the system working to encourage discussion / advice.Note that I haven't dealt with anywhere near all the possible locking issues etc and am well aware that this needs to be done. Other cleanups that will need to be done include working out the layout in sysfs to make it more intuitive. Also sorry for the somewhat rough and ready nature of the attached
patch (against 2.6.26-rc4)Ring buffer design is a large part of the attached patch. I'm not sure if I am going about this the right way. Basically, we need ring buffers with almost no write latency but can waste plenty of time reading from them (in general case - we do however want reading the last available value to be fast). What is there works, but probably has at least a few nasty corner cases that I haven't prevented.
Interfaces (these are per device) - at somepoint a procfs interface similar
to that used in the input subsystem would make device querying simpler.Sysfs - Parameter Control - gain / offsets etc
State control, turn interrupts on and off etc. Interrupt control parameters (threshold etc)
Ring buffer parameters as relevant (currently fixed) Individual input reading (acceleration values here) Minor numbers for various chrdevs associated with this device.chrdev- 3 types of chrdev at the moment
Ring buffer events
Ring buffer access (currently ripping data off the buffer only) Interrupt events - for lis3l02dq these are only threshold breaksFunctionality yet to be implemented.
Polled based capture (use a peroidic timer if available)Hardware ring buffering for devices that support it (two level ring
buffer -
hard and soft may be appropriate)A chrdev for polling of whole device (with timestamps etc).
Composite interrupt handling (some devices allow logical combinations of different interrupt signals to be used as the trigger condition).
Documenation ;)
Cleaner solution to data alignment in the ring buffer (currently I'm
cheating
and manually doing it)Lots lots more....
Anyhow, all comments welcome. Can anyone think of a better name? (I'm not keen on industrialio. It's too long if nothing else!
It will do as a working title for now)
Quoted 6 lines
Thanks,
--
Jonathan Cameron
include/linux/industrialio.h +275 -0
@@ -0,0 +1,275 @@ +/* The industrial I/O core +* +* Copyright (c) 2008 Jonathan Cameron +* +* This program is free software; you can redistribute it and/or modify it +* under the terms of the GNU General Public License version 2 as published by +* the Free Software Foundation. +*/ + +#ifndef _INDUSTRIAL_IO_H_ +#define _INDUSTRIAL_IO_H_ + +#include <linux/device.h> +#include <linux/industrialio_sysfs.h> + +/* TODO LIST */ +/* Initial test drivers to implement +SCA3000 VTI Accelerometers (hardware ring buffers) +MAX1363 ADC (polled only for ring buffer ) + +Static device specific elements (conversion factors etc) should be exported via sysfs + +Finish writing ring buffer character interface +Write general event character interfaces +Another type of chardev to allow direct reading (typically in response to data ready events) + + +Opinions sought on: +Shared interrupt lines. Worth dealing with? (very time consuming to check +whether some devices caused an interrupt or not - in some states anyway) +Limiting length of event lists. Could get silly numbers of them otherwise. +*/ + + +/* Event interface flags */ +#define INDUSTRIALIO_BUSY_BIT_POS 1 + + +/* Could maintain a list of these for rapid clean up purposes, +but it doesn't exactly take long to scan the array */ +struct industrialio_handler { +const struct file_operations *fops; +int id; +unsigned long flags; +void *private; +}; + + +/* The actual event being pushed ot userspace */ +struct industrialio_event_data { +int id; +s64 timestamp; +}; + +/* FIXME -WORK ON NAMING*/ +struct industrialio_detected_event_list { +struct list_head list; +struct industrialio_event_data ev; +/* Part of shared event handling - (typicaly ring buffers) */ +struct industrialio_shared_ev_pointer *shared_pointer; +}; + + +/* Requires high resolution timers */ +static inline s64 industrialio_get_time_ns (void ) +{ +struct timespec ts; +ktime_get_ts (&ts); +return timespec_to_ns (&ts); +} + +struct industrialio_dev ; +/* Each device has one of these per interrupt */ +struct industrialio_event_handler_list { +struct list_head list; +int (*handler)(struct industrialio_dev *dev_io,int index,s64 timestamp,int no_test); +/* This element may be shared */ +int refcount; +}; +/* wraps adding to lists and does reference counting to allowed shared handlers */ +/* FIXME CONFUSING NAMING */ +int industrialio_add_event_to_list (struct industrialio_event_handler_list *list, +struct industrialio_event_handler_list *el); + +int industrialio_remove_event_from_list (struct industrialio_event_handler_list *el); + + + +/* This means that interrupts can be turned off when no events are being generated, +and also provides the interrupt handler the means to identify the incoming event */ +//int industrialio_register_event_list_to_interrupt(int interrupt, industrialio_event_list *list); + +/* Want this to be as transparrent as possible from the point of view of the driver! */ + +/* JIC23: This is my first serious attempt at a lock free ring buffer for this sort of +situation so all suggestions on this code particularly welcome! */ + + + + +struct industrialio_ring_buffer ; +#define INIT_INDUSTRIALIO_RING_BUFFER (ring, _dim, _bytes, _length) { \ + (ring)->size = _dim*_bytes; \ + (ring)->skip = (ring)->size + sizeof(s64); \ + (ring)->length = _length; \ + (ring)->dimension = _dim; \ + (ring)->bytes = _bytes; \ + (ring)->read_p = 0; \ + (ring)->write_p = 0; \ + (ring)->last_written_p = 0; \ + (ring)->loopcount = 0; \ + (ring)->data \ + = (unsigned char*) \ + (kmalloc(_length*(ring)->skip, \ + GFP_KERNEL)); \ + (ring)->shared_ev_pointer.ev_p =0; \ + (ring)->shared_ev_pointer.lock = \ + __SPIN_LOCK_UNLOCKED((ring)->shared_ev_pointer->loc); \ +} + +#define FREE_INDUSTRIALIO_RING_BUFFER (ring) \ + kfree((ring)->data) + +int industrialio_store_to_ring (struct industrialio_ring_buffer *ring, +unsigned char * data, +s64 timestamp); + +/* Edge cases : +1) data at last_p is no longer valid - requires complete wrap around. +To detect, loop count has changed - if only by 1 then problem only +if current_lastp is equal to or greater than copy made at start. +If we have wrapped an entire int in this time (loopcount) then +something very very weird has occured! +*/ +int industrialio_read_last_from_ring (struct industrialio_ring_buffer *ring, +unsigned char * data); +/* Dump the ring */ + +int +industrialio_request_ring_buffer (int dimension, +int bytes_per_reading, +int length, +struct industrialio_ring_buffer **ring, +int id, +struct module *owner, +struct device *dev ); + + +void industrialio_free_ring_buffer (struct industrialio_ring_buffer * ring,struct device *dev); +/* Device operating modes */ +#define INDIO_DIRECT_MODE 0x01 +#define INDIO_RING_POLLED 0x02 +#define INDIO_RING_DATA_RDY 0x04 +#define INDIO_RING_HARDWARE_BUFFER 0x08 + + + +struct industrialio_event_interface { +struct industrialio_handler handler; +wait_queue_head_t wait; +struct industrialio_detected_event_list det_events; +int max_events; +int current_events; +/* Integer id, used to differentiate this one form any others */ +int id; +struct industrialio_chrdev_minor_attr attr; +struct module *owner; +void *private; +}; + + +struct industrialio_shared_ev_pointer { +struct industrialio_detected_event_list *ev_p; +spinlock_t lock; +}; +/* A general ring buffer structure +Intended to be completely lock free as we always want fills from the interrupt +handler to not have to wait. This obviously increases the possible time required +to read from the buffer. */ +struct industrialio_ring_buffer +{ +unsigned char * data; +int length; +int dimension; +int bytes; +int size; +int skip; +unsigned char *read_p; +unsigned char *write_p; +unsigned char *last_written_p; +/* used to act as a point at which to signal an event */ +unsigned char *half_p; +int loopcount; +/* accessing the ring buffer */ +char * access_minor_name; +struct industrialio_chrdev_minor_attr access_minor_attr; +struct industrialio_handler access_handler; +/* events triggered by the ring buffer */ +char * event_minor_name; +struct industrialio_event_interface ev_int; +/* a fully shared output event */ +struct industrialio_shared_ev_pointer shared_ev_pointer; +}; +/* Seperate registration functions were leading to very messy driver init */ +/* Vast majority of this is set by the industrialio subsystem. +* FIXME: Add a macro to set only the relevant stuff within a chip driver +*/ +struct industrialio_dev { +/* generic handling data used by ind io */ +int id; +/* device specific data */ +void *dev_data; + +/* Modes the drivers supports */ +int modes;/* Driver Set */ +int currentmode; +/* Direct sysfs related functionality */ +struct device *sysfs_dev; +struct device *dev;/* Driver Set */ +/* General attributes */ +const struct attribute_group *attrs; + +/* Interrupt handling related */ +/* FIXME: GETTING MESSY! */ +struct module *driver_module; +int num_interrupt_lines;/* Driver Set */ + +struct industrialio_interrupt **interrupts; + + +/* Event control attributes */ +const struct attribute_group *event_attrs; +/* The character device related elements */ +struct industrialio_event_interface *event_interfaces; + +/* Software Ring Buffer - for now assuming only makes sense to have a single ring */ +int ring_dimension; +int ring_bytes_per_reading; +int ring_length; +struct industrialio_ring_buffer *ring; +struct attribute_group *ring_attrs_group; +struct industrialio_ring_attr *ring_attrs; +}; + +int industrialio_device_register (struct industrialio_dev *dev_info); + +void industrialio_device_unregister (struct industrialio_dev *dev_info); + +/* Wrapper class used to allow easy specification of different line numbers */ +struct industrialio_interrupt { +struct industrialio_dev *dev_info; +int line_number; +int irq; +struct industrialio_event_handler_list ev_list; +}; + +irqreturn_t industrialio_interrupt_handler (int irq,void *_int_info); + +int industrialio_register_interrupt_line (unsigned int irq, +struct industrialio_dev *dev_info, +int line_number, +unsigned long type, +const char *name); + +void industrialio_unregister_interrupt_line (struct industrialio_dev *dev_info, +int line_number); + + +/* Used to try inserting an event into the list for userspace reading via +* chrdev */ +int industrialio_put_event (struct industrialio_dev *dev_info, +int ev_line, +int ev_code, +s64 timestamp); +#endif /* _INDUSTRIAL_IO_H_ */
include/linux/industrialio_sysfs.h +207 -0
207 lines not on this page · raw message
include/linux/spi/lis3l02dq.h +6 -0
@@ -0,0 +1,6 @@ + + +struct LIS3L02DQ_platform_data { +unsigned data_ready_gpio; +}; +
-------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://sourceforge.net/services/buy/index.php
_______________________________________________
spi-devel-general mailing list spi-devel-general-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org
https://lists.sourceforge.net/lists/listinfo/spi-devel-general
Re: Accelerometer etc subsystem (Update on progress)
In reply to Jonathan CameronQuoted 1 line · On Thu, 26 Jun 2008 19:01:30 +0100 Jonathan Cameron wrote:
Documenation ;)
and Documentation ;)
Ugh. Attachment. Please send patches inline so that they can be reviewed without having to do tons of copy-and-paste. Possibly Documentation/email-clients.txt can help you with thunderbird.
There are several typos in the Kconfig text parts... and in source code comments.
Quoted 1 line
From
Documentation/CodingStyle:
The preferred style for long (multi-line) comments is:
/*
* This is the preferred style for multi-line
* comments in the Linux kernel source code.
* Please use it consistently.
*
* Description: A column of asterisks on the left side,
* with beginning and ending almost-blank lines. */
Please review/use Documentation/CodingStyle.
This Makefile (drivers/industrialio/misc/Makefile) doesn't seem to do anything.
---
~Randy
Linux Plumbers Conference, 17-19 September 2008, Portland, Oregon USA
http://linuxplumbersconf.org/
Re: Accelerometer etc subsystem (Update on progress)
In reply to Jonathan CameronQuoted 2 lines · Jonathan Cameron
Sysfs - Parameter Control - gain / offsets etc
State control, turn interrupts on and off etc.
As in turn userspace [interrupt] event notification on and off? I would have thought it'd be the kernel driver's responsibility to turn the device's interrupt generation on and off according to needs for data/events etc.
I know this is in a rough state but a few comments anyway. First, there are heaps of casts-of-void-pointers (eg casts of kmalloc returns) which are superfluous and hard readability 'coz you have to split the line to fit in 80cols.
And hardcoded type-size assumptions everywhere. Don't be scared of sizeof ;-)
Quoted 3 lines
Anyhow, all comments welcome. Can anyone think of a better name? (I'm not keen on industrialio. It's too long if nothing else!
It will do as a working title for now)
I don't mind industrial io but as a function prefix, iio works better. I can't see it being used elsewhere.
also:
+/* As the ring buffer contents are device dependent this functionality
+ * must remain part of the driver and not the ring buffer subsystem */ +static ssize_t
+lis3l02dq_read_accel_from_ring(struct industrialio_ring_buffer *ring,
+ int element, char *buf)
+{
+ int val, ret, len;
+ uint16_t temp;
+ char *data, *datalock;
+
+ data = kmalloc(8, GFP_KERNEL);
+ if (data == NULL) {
+ ret = -ENOMEM;
+ goto error_ret;
+ }
+ ret = industrialio_read_last_from_ring(ring, data);
+ datalock = data + 2*element;
I haven't looked deeply at the ringbuffer code but can you guarantee that later elements are at higher addresses than the lower ones? As in, can one datum in the the ring buffer wrap to the beginning again?
+ kfree(data);
You free the data before you use it? Though you are using it through a different pointer below. I wouldn't be scared of allocating 8 bytes on the stack rather than kmalloc'ing (unless you expect this to be called in a deep callchain)
+ temp = (((uint16_t)((datalock[1]))) << 8)
+ | (uint16_t)(datalock[0]);
+ val = *((int16_t *)(&temp));
All this data/datalock/bitshuffle nonsense would be nicer if you just used structs and unions, yeah?
union channel {
char data[2];
int16_t val;
}struct datum {
union channel elements[3];
}or something.
+ len = sprintf(buf, "ring %d\n", val);
+
+ return len;
+error_ret:
+ return ret;
+}
Incidentally, is there much that your ringbuffer can do which kfifo can't? Apart from having a bunch of extra nice accessor-helpers sitting on the top.
Overall looking good and useful, can't wait 'till it's done :-)
--Ben.
Re: [lm-sensors] Accelerometer etc subsystem (Update on progress)
Quoted 9 lines · Ben Nizette
Quoted 2 lines · Jonathan Cameron
Sysfs - Parameter Control - gain / offsets etc
State control, turn interrupts on and off etc.As in turn userspace [interrupt] event notification on and off? I would have thought it'd be the kernel driver's responsibility to turn the device's interrupt generation on and off according to needs for data/events etc.
Ok, there is a division here between interrupt handling on the host side which indeed should be turned on and off transparently by the driver and actually telling the sensor which interrupts to generate. In a sense this is simply a case of terminology and what is actually being requested is event notifications (which then match with those sent up to userspace).
Quoted 5 lines
I know this is in a rough state but a few comments anyway. First, there are heaps of casts-of-void-pointers (eg casts of kmalloc returns) which are superfluous and hard readability 'coz you have to split the line to fit in 80cols.
Oops, silly habit that one - I'll clean those out.
Quoted 2 lines
And hardcoded type-size assumptions everywhere. Don't be scared of sizeof ;-)
Yup, definitely need to clean them up.
Quoted 6 lines
Quoted 3 lines
Anyhow, all comments welcome. Can anyone think of a better name? (I'm not keen on industrialio. It's too long if nothing else!
It will do as a working title for now)I don't mind industrial io but as a function prefix, iio works better. I can't see it being used elsewhere.
Good point - I'd droped to indio in some cases but iio will make those 80 character limits even easier ;)
Quoted 20 lines
also:
drivers/industrialio/accelerometer/lis3l02dq.c +17
-0+/* As the ring buffer contents are device dependent this functionality +* must remain part of the driver and not the ring buffer subsystem */ +static ssize_t +lis3l02dq_read_accel_from_ring (struct industrialio_ring_buffer *ring, +int element,char *buf) +{ +int val, ret, len; +uint16_t temp; +char *data, *datalock; + + data =kmalloc (8 ,GFP_KERNEL ); +if (data ==NULL ) { + ret = -ENOMEM ; + goto error_ret; + } + ret =industrialio_read_last_from_ring (ring, data); + datalock = data +2 *element;
Quoted 3 lines
I haven't looked deeply at the ringbuffer code but can you guarantee that later elements are at higher addresses than the lower ones? As in, can one datum in the the ring buffer wrap to the beginning again?
At the moment the ring buffer has to be a whole number of datums big. I'm inclined to keep it way and move more towards dynamic allocation such that it is true than to try handling split data reading sets.
Quoted 6 lines
drivers/industrialio/accelerometer/lis3l02dq.c +1
-0+kfree (data);You free the data before you use it? Though you are using it through a different pointer below. I wouldn't be scared of allocating 8 bytes on the stack rather than kmalloc'ing (unless you expect this to be called in a deep callchain)
Ouch. That's an out and out bug!
Quoted 5 lines
drivers/industrialio/accelerometer/lis3l02dq.c +3
-0+ temp = (((uint16_t )((datalock[1 ]))) <<8 ) + | (uint16_t )(datalock[0 ]); + val = *((int16_t *)(&temp));
Quoted 7 lines
All this data/datalock/bitshuffle nonsense would be nicer if you just used structs and unions, yeah?
union channel { char data[2]; int16_t val; }
Good point, I'd forgotten you could do that with unions.
drivers/industrialio/accelerometer/lis3l02dq.c line 468
Quoted 13 lines
struct datum { union channel elements[3]; }or something.
drivers/industrialio/accelerometer/lis3l02dq.c +6
-0+ len =sprintf (buf,"ring %d\n" , val); + +return len; +error_ret: +return ret; +}
Good approach, I'll switch to that.
Quoted 4 lines
Incidentally, is there much that your ringbuffer can do which kfifo can't? Apart from having a bunch of extra nice accessor-helpers sitting on the top.
Not sure, I'll look into it.
Quoted 2 lines
Overall looking good and useful, can't wait 'till it's done :-)
Thanks for the comments.
Jonathan
-------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://sourceforge.net/services/buy/index.php
Re: [lm-sensors] Accelerometer etc subsystem (Update on progress)
Quoted 10 lines · Jonathan Cameron
Quoted 9 lines · Ben Nizette
Quoted 2 lines · Jonathan Cameron
Sysfs - Parameter Control - gain / offsets etc
State control, turn interrupts on and off etc.As in turn userspace [interrupt] event notification on and off? I would have thought it'd be the kernel driver's responsibility to turn the device's interrupt generation on and off according to needs for data/events etc.
Quoted 5 lines
Ok, there is a division here between interrupt handling on the host side which indeed should be turned on and off transparently by the driver and actually telling the sensor which interrupts to generate. In a sense this is simply a case of terminology and what is actually being requested is event notifications (which then match with those sent up to userspace).
Righteo, I suspected as much :-)
< snip good replies :-) >
Quoted 21 lines
Quoted 21 lines
also:
drivers/industrialio/accelerometer/lis3l02dq.c +17
-0+/* As the ring buffer contents are device dependent this functionality +* must remain part of the driver and not the ring buffer subsystem */ +static ssize_t +lis3l02dq_read_accel_from_ring (struct industrialio_ring_buffer *ring, +int element,char *buf) +{ +int val, ret, len; +uint16_t temp; +char *data, *datalock; + + data =kmalloc (8 ,GFP_KERNEL ); +if (data ==NULL ) { + ret = -ENOMEM ; + goto error_ret; + } + ret =industrialio_read_last_from_ring (ring, data); + datalock = data +2 *element;
Quoted 6 lines
Quoted 3 lines
I haven't looked deeply at the ringbuffer code but can you guarantee that later elements are at higher addresses than the lower ones? As in, can one datum in the the ring buffer wrap to the beginning again?
At the moment the ring buffer has to be a whole number of datums big. I'm inclined to keep it way and move more towards dynamic allocation such that it is true than to try handling split data reading sets.
Yup, agreed. Just so long as your code thinks about :-)
Quoted 13 lines
Quoted 7 lines
drivers/industrialio/accelerometer/lis3l02dq.c +1
-0+kfree (data);You free the data before you use it? Though you are using it through a different pointer below. I wouldn't be scared of allocating 8 bytes on the stack rather than kmalloc'ing (unless you expect this to be called in a deep callchain)
Ouch. That's an out and out bug!
Quoted 5 lines
drivers/industrialio/accelerometer/lis3l02dq.c +3
-0+ temp = (((uint16_t )((datalock[1 ]))) <<8 ) + | (uint16_t )(datalock[0 ]); + val = *((int16_t *)(&temp));
Quoted 8 lines
Quoted 7 lines
All this data/datalock/bitshuffle nonsense would be nicer if you just used structs and unions, yeah?
union channel { char data[2]; int16_t val; }Good point, I'd forgotten you could do that with unions.
Cool, just watch endianness of course :-)
Quoted 16 lines
drivers/industrialio/accelerometer/lis3l02dq.c line 468
Quoted 13 lines
struct datum { union channel elements[3]; }or something.
drivers/industrialio/accelerometer/lis3l02dq.c +6
-0+ len =sprintf (buf,"ring %d\n" , val); + +return len; +error_ret: +return ret; +}Good approach, I'll switch to that.
Quoted 1 line
Quoted 4 lines
Quoted 3 lines
Incidentally, is there much that your ringbuffer can do which kfifo can't? Apart from having a bunch of extra nice accessor-helpers sitting on the top.
Not sure, I'll look into it.
kfifo won't be a drop in replacement, it's just a very simple ring fifo. I suspect your higher level ring buffer accessors and allocators could live on top of it though.
Quoted 5 lines
Quoted 2 lines
Overall looking good and useful, can't wait 'till it's done :-)
Thanks for the comments.
Jonathan
np,
--Ben.
-------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://sourceforge.net/services/buy/index.php
Re: [lm-sensors] Accelerometer etc subsystem (Update on progress)
Hi Ben,
Quoted 8 lines
Quoted 5 lines
Quoted 4 lines
union channel { char data[2]; int16_t val; }Good point, I'd forgotten you could do that with unions.
Cool, just watch endianness of course :-)
That and the annoyance of alignment issues making that approach taking way more space that you'd think.
Quoted 8 lines
Quoted 4 lines
Quoted 3 lines
Incidentally, is there much that your ringbuffer can do which kfifo can't? Apart from having a bunch of extra nice accessor-helpers sitting on the top.
Not sure, I'll look into it.
kfifo won't be a drop in replacement, it's just a very simple ring fifo. I suspect your higher level ring buffer accessors and allocators could live on top of it though.
Sure, but from my understanding of kfifo it takes a much more symmetric approach to reading and writing with locking used to prevent them occuring concurrently. You obviously can use it without locking but I don't believe that it provide any facility for coping with the nasty case, (buffer full and hence during read attempts a certain amount of what is copied out may have become invalid). It maybe the case that, as you say suitable high level functions on top of a kfifo would be a good way to proceed (afterall, kfifo is well tested etc), but I fear, given how little of kfifo's code would actually be used it would be more likely to cause problems than not.
It might be best to leave this decision until the exact requirements of the ring buffer are actually known.
Jonathan