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.