Giter Club home page Giter Club logo

w1-gpio-cl's Introduction

w1-gpio-cl

This is a Linux kernel-mode driver, intended as an enhancement/substitution of the standard Linux w1-gpio 1-wire bus master driver. Contrary to the standard driver, w1-gpio-cl is not a platform device driver, therefore doesn't need any specific device-tree overlay nor preconfigured kernel (except usual 1-wire support via the wire module). Moreover, there is possible coexistence between w1-gpio and w1-gpio-cl, provided no GPIOs conflict exists.

Module Configuration

w1-gpio-cl is fully configured via its command line parameters while loading the driver. The configuration allows to launch many 1-wire bus masters controlling different GPIO pins. For parasite powering support, it is possible to choose the type of the strong pull-up to be used.

General configuration syntax is:

modprobe w1-gpio-cl m1="gdt:num[,od][,bpu|gpu:num[,rev]]" [m2="..." ...]

NOTE: : and , syntax tokens may be replaced by = and ; respectively, so m1="gdt:4,od" is equivalent to m1="gdt:4;od", m1="gdt=4,od" or m1="gdt=4;od".

m1, m2, ... mN - configure up to N (where N=5 for the standard module compilation) bus masters, each one controlling different 1-wire bus connected to its GPIO pin (specified in gdt). At least one bus master specification (that is m1) must be provided. It's worth to note, the X index in mX parameter specifies an order in which bus masters are registered in the 1-wire subsystem. The index doesn't need to correspond to the bus master id assigned by the kernel.

Each of bus master configurations consist of set of parameters listed below:

  • gdt - specifies GPIO number associated with the 1-wire data wire (the 1-wire bus). This parameter is obligatory for each bus master specification.

  • od - if specified, the data wire GPIO (gdt) is of an open drain type. This parameter is deprecated and its support has been removed for kernels >= v6.5.

  • bpu - if specified, parasite powering is enabled via the data wire strong pull-up bit-banging. This type of strong pull-up is possible only for non open-drain type of the data wire GPIO (gdt).

  • gpu - specifies GPIO number used for controlling strong pull-up for parasite powering. The GPIO is working in the output mode and is set to the low state if the strong pull-up is active, and to the high state otherwise.

    The strong pull-up controlled by the gpu GPIO is the only possibility for an open-drain type of the data wire GPIO (gdt). In this case the gpu GPIO may be connected to a P-channel MOSFET gate controlling the Vcc strong pull-up as presented on the following figure.

    External GPIO strong pull-up

    NOTE: In place of the MOSFET it's possible to use a PNP bipolar transistor with its emitter connected to Vcc, collector to the data wire and base to the controlling GPIO (gpu). Current reducing resistor shall be placed between the transistor's base and gpu pin.

  • rev - if specified and the gpu parameter is provided, the gpu GPIO logic is reversed for the strong pull-up activation: GPIO in the high state if the strong pull-up is active, low state - otherwise.

NOTE: Strong pull-up along with parasite powering support is effectively disabled if no bpu nor gpu is specified.

Example of Usage

Example

In this example, there have been configured three bus masters:

  • 1st one on GPIO1 controlling non-parasitically powered thermometers.

  • 2nd one on GPIO2 controlling parasitically powered thermometers. Strong pull-up is performed via the data wire bit-banging (non open-drain data GPIO).

  • 3nd one devoted to handle iButton reader(s) only. Using separate 1-wire bus in this case is justified by the performance reason. The iButton bus is empty for most of its time, and is scanned/searched much more often than other buses for presence of authorized iButtons existence.

NOTE: GPIO1, GPIO2, GPIO3 are numbers specifying actual GPIO pins.

Compilation and Loading

The driver module may be compiled directly on the target machine or cross-compiled and the result to be copied into the target machine. If you are not familiar with the Linux kernel building process please refer to this link first. It provides good introduction to the topic of kernel compilation/cross-compilation for Raspberry Pi boards.

Prerequisites

  • Building tool-set.

    • For compilation on the target machine Linux kernel building tools may be installed by (for Debian based systems):

      sudo apt-get install build-essential bc bison flex libssl-dev
      
    • For cross-compilation appropriate target system tool-chain need to be installed on the compiling machine (e.g. package crossbuild-essential-armhf for 32-bit or crossbuild-essential-arm64 for 64-bit ARM). Remaining tools to be installed on the compiling machine:

      sudo apt-get install make bc bison flex libssl-dev
      
  • Kernel headers and kbuild scripts corresponding to the target kernel.

    • For compilation on the target machine the required headers may be installed by:

      sudo apt-get install linux-headers-KERNEL_RELEASE
      

      where KERNEL_RELEASE corresponds to the kernel release version on the target (to be checked by uname -r). In case the package repository contains kernel headers corresponding to the current kernel image the following command will install appropriate headers on the target machine:

      sudo apt-get install linux-headers-`uname -r`
      

      In case the target's system package repository doesn't contain kernel headers package in a required version (usually the case for Raspberry Pi Raspbian OS) there is a need to use kernel sources as described in the subsequent point.

    • For cross-compilation it's recommended to use Linux kernel sources corresponding to the kernel version installed on the target machine. The kernel sources need to be prepared via proper configuration and modules_prepare as follows (launched from the kernel sources directory on the compiling machine):

      ARCH=... CROSS_COMPILE=... make CONFIG_TARGET modules_prepare
      

      where CONFIG_TARGET is a specific kernel target configuration (e.g. for Raspberry Pi boards the configuration shall be set to bcmrpi_defconfig, bcm2709_defconfig, bcm2711_defconfig or bcmrpi3_defconfig depending on the platform version). ARCH and CROSS_COMPILE are required to indicate target architecture and cross-compiling tool-chain.

      NOTE 1: When using kernel sources while compiling on the target machine, there is no need to set ARCH and CROSS_COMPILE, since the local tool-set is used for compilation.

      NOTE 2: When compiling for Raspberry Pi, search_kernel_commit.sh script may be used to find commit on the official RPi kernel repository for target's kernel version.

Compilation

General compilation command syntax is as follows (launched from the w1-gpio-cl project directory):

[KERNEL_SRC=...] [ARCH=...] [CROSS_COMPILE=...] [CONFIG_W1_MAST_MAX=...] make

The result is w1-gpio-cl.ko driver module located in the project directory. All compilation definitions (KERNEL_SRC, ARCH, ...) are optional, with the following meaning:

  • KERNEL_SRC: specifies kernel sources directory in case they are used instead of the pre-installed kernel headers (see above).

  • ARCH, CROSS_COMPILE: are used for module cross-compilation exactly as for the Linux kernel.

  • CONFIG_W1_MAST_MAX: by default the module is compiled to support up to 5 bus masters. This may be changed by setting this definition.

Installation

If the module was compiled on the target machine it's possible to install it into the destination directory by:

sudo make install

and uninstall by:

sudo make uninstall

If the module was cross-compiled, copy w1-gpio-cl.ko module into its destination location on the target machine (/lib/modules/KERNEL_RELEASE/kernel/drivers/w1/masters) and remake the kernel modules dependencies by sudo depmod.

Loading

sudo modprobe w1-gpio-cl MODULE_CONFIG

where the MODULE_CONFIG specifies 1-wire bus master(s) configuration as described above.

If you need to load the module automatically create the following files:

  • /etc/modules-load.d/w1-gpio-cl.conf with content:
w1-gpio-cl
  • /etc/modprobe.d/w1-gpio-cl.conf with content:
options w1-gpio-cl MODULE_CONFIG

where the MODULE_CONFIG specifies 1-wire bus master(s) configuration.

DKMS

The module may be installed as part of DKMS system. To install w1-gpio-cl as DKMS module launch the following commands from the module source directory:

sudo dkms add .
sudo dkms install w1-gpio-cl/MODULE_VER

where MODULE_VER denotes module version. From now any kernel updates on the target machine will precompile w1-gpio-cl module accordingly.

License

GNU GENERAL PUBLIC LICENSE v2. See LICENSE file for details.

w1-gpio-cl's People

Contributors

krzysztofosuch avatar pstolarz avatar robertfchapman avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

w1-gpio-cl's Issues

Modify timeout value for 1W device scan

Hey,

I'm using this driver on my Jetson Nano computer to work with W1 devices. It has w1_master_timeout value set to 10 s by default. It is too little, and I would like to change this value to 1 s. Could you pls tell me how to configure it?

Build error on Fedora kernel 6.6

Running Fedora on kernel 6.6 and I'm getting the following error:

# /usr/bin/gmake all NUM_THREADS=4
NOTE: ./w1 symlink is already set and will not be updated. Remove it and restart the compilation process in case you want to re-run the kernel sources examination.
NOTE: gen-mast.h was generated
/usr/bin/gmake -C /lib/modules/6.6.14-200.fc39.aarch64/build M=/usr/local/src/w1-gpio-cl modules
gmake[1]: Entering directory '/usr/src/kernels/6.6.14-200.fc39.aarch64'
  CC [M]  /usr/local/src/w1-gpio-cl/w1-gpio-cl.o
/usr/local/src/w1-gpio-cl/w1-gpio-cl.c: In function ‘init_module’:
/usr/local/src/w1-gpio-cl/w1-gpio-cl.c:497:46: error: ‘GPIOF_OPEN_DRAIN’ undeclared (first use in this function)
  497 |                         GPIOF_IN | (mdt.od ? GPIOF_OPEN_DRAIN : 0),
      |                                   

Looks like GPIOF_OPEN_DRAIN was removed in 6.5

Compilation Prerequisite Details?

Hi, This 1-wire bus driver looks exceptionally usefull, if I can get it to work!
I'm trying to get two 1-wire interfaces to run on a Pi Zero without major re-work of the operating system, and your work here looks like exactly whats required.
I tried to run the following via terminal on a freshly installed copy of the latest Rasbian jessie (25/11/16) on a raspberry pi zero;

sudo git clone https://github.com/pstolarz/w1-gpio-cl.git
cd w1-gpio-cl
modprobe wire
sudo make
insmod ./w1-gpio-cl.ko m1="gdt:GPIO1"

However as you can see from the log below, the Make process failed, and w1-gpio-cl.ko was not produced. I guess that this is because I've not provided the prerequisites you mention in the README. Assuming this is the case, any chance that you could include a more step by step guide in the README? or point out the thing I'm doing wrong?
Many thanks in anticipation!
Richard

log
pi@raspberrypi:~ $ sudo git clone https://github.com/pstolarz/w1-gpio-cl.git
Cloning into 'w1-gpio-cl'...
remote: Counting objects: 63, done.
remote: Total 63 (delta 0), reused 0 (delta 0), pack-reused 63
Unpacking objects: 100% (63/63), done.
Checking connectivity... done.
pi@raspberrypi:~ $ cd w1-gpio-cl
pi@raspberrypi:/w1-gpio-cl $ modprobe wire
pi@raspberrypi:~/w1-gpio-cl $ sudo make
`gen-mast.h' has been generated.

NOTE: The compiled module needs w1 set of headers, which is a part of the internal
(not the public) part of the w1 API. The headers are contained in the full Linux
kernel source tree.
Since the kernel sources has not been detected on this platform, the compilation
process will use headers which are part of this source bundle (included in
./w1-internal directory). Linux kernel API is not persistent across versions, so
it is STRONGLY recommended to set ./w1 symbolic link to `drivers/w1' subdirectory
of the target kernel sources. This way proper w1 headers will be used.

Press ENTER to continue...
make -C /lib/modules/4.4.34+/build M= modules
make[1]: *** /lib/modules/4.4.34+/build: No such file or directory. Stop.
Makefile:13: recipe for target 'all' failed
make: *** [all] Error 2

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.