2

I recently found a driver for an IC I need: https://github.com/skelton/s7300B_common_3050/blob/master/customer/drivers/misc/lsm303d.c It is an accelerometer with a magnetometer, and is spoken to via i^2c.

I added this .c to my kernel under <kernel>/drivers/compass/, and .h to <kernel>/include/linux/ I had to add some defines to make it compile, but nothing spectacular.

My Makefile resides together with the .c file, and contains

obj-$(CONFIG_LSM303D)   += lsm303d.o

My Kconfig:

config LSM303D
tristate "LSM303D compass driver"  
depends on ARM
default y if ARM
help
  lsm303d driver.

I also added

obj-y += compass/ 

to the <kernel>/drivers/Makefile

I compile with

make CROSS_COMPILE=arm-linux-gnueabihf- ARCH=arm distclean
make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- my_defconfig
make ARCH=arm -j 4 CROSS_COMPILE=arm-linux-gnueabihf- uImage
make ARCH=arm -j 4 CROSS_COMPILE=arm-linux-gnueabihf- modules
make ARCH=arm -j 4 CROSS_COMPILE=arm-linux-gnueabihf- modules_install

I am not sure if the last 2 lines are necessary for me.

What I am trying to do is to use this driver to read the data from it. But I don't find any starting points on how to use its API, and what functionality it gives me.

I find the folder called lsm303d on my test machine: $ ls /sys/bus/i2c/drivers/lsm303d bind uevent unbind

I read here: https://www.kernel.org/doc/Documentation/console/console.txt what these files are. This does not help me much, as I am just starting with the whole kernel/driver/module experimenting.

So, my question: How do I use this driver to e.g. read out something over i2c from it?

Any help would be appreciated.

Paul
  • 26,170
  • 12
  • 85
  • 119
Irfo S.
  • 21
  • 2
  • Maybe [How do the files in *dev* match linux's model of a device](http://stackoverflow.com/questions/14972584/how-do-the-files-in-dev-match-linuxs-model-of-a-device/) helps some. Trees of buses are possible. The *i2c* will match a device ID and then probe the driver. You need to have *i2c* working and connected (IOMUX, clocks, etc). This is an older style *platform data* driver. You need to register an i2c bus with platform data from [lsm303d.h](https://github.com/skelton/s7300B_common_3050/blob/master/customer/include/linux/lsm303d.h) in your machine file. Find your machine file. – artless noise May 13 '15 at 13:20

0 Answers0