NCT5104D GPIO Linux Driver
you should have the following packages installed:
- linux-headers-$(uname -r)
- build-essential
- make
- git (you can also download the repo as zip)
apt-get install -y linux-headers-$(uname -r) build-essential make git
git clone <this repo url>
run make
in the driver folder on the target machine
(otherwise your driver gets compiled for a different kernel version)
You can also provide the custom kernel directory (to compile for different kernel than installed on host. E.g.:
make KDIR=../linux-4.9.0
Kernel has to be prepared first to build the external modules:
make modules_prepare
Install dkms, debhelper and git package on the build machine:
apt-get install -y dkms debhelper
Clone this repository:
git clone <this repo url>
Run dpkg-buildpackage
in the driver directory.
Install dkms on the target machine:
apt-get install -y dkms
Copy the built deb file (e.g. gpio-nct5104d-dkms_0.20171115-0_all.deb
)
to the target machine and install it:
dpkg -i gpio-nct5104d-dkms_0.20171115-0_all.deb
Now at every kernel package update gpio-nct5104d module will be automatically rebuilt and installed.
insmod gpio-nct5104d.ko
unexport all the used GPIO Pins first, then run
rmmod gpio-nct5104d.ko
echo 0 > /sys/class/gpio/export
will export/reserve/setup the gpio pin 0
echo 0 > /sys/class/gpio/unexport
will unexport/free the gpio pin 0
echo out > /sys/class/gpio/gpio0/direction
echo 1 > /sys/class/gpio/gpio0/value
cat /sys/class/gpio/gpio0/value
echo 1 > /sys/class/gpio/gpio0/active_low
NCT5104D does not provide interrupts for GPIOs.
cat /sys/kernel/debug/gpio
this has to be enabled in your kernel
see those pages for some c-code examples:
- http://wiki.gnublin.org/index.php/GPIO
- http://falsinsoft.blogspot.de/2012/11/access-gpio-from-linux-user-space.html
see the Kernel documentation for more details:
- https://www.kernel.org/doc/Documentation/gpio/sysfs.txt
- https://www.kernel.org/doc/Documentation/gpio/gpio-legacy.txt
and so on...