Linux kernel: using a consumer in a user-space governor
I have some kind of driver in user space:
talk on the phone through the interface (rs232) with the device. Also I have pin (gpio) to turn on / off this device.
I am not coding a specific gpio in my program to make it more portable,
so I change my board tree structure description, and describe the regulator fix, after which I decided to use userpace - a consumer driver to control power on / off, but it looks like it was not expected by the kernel developers (link to a discussion of a similar problem, not mine): http://patchwork.ozlabs.org/patch/374912/
So how do I turn on / off turning my device on / off from user space without adding information to my program about which particular gpio is used to turn the device on / off?
More details : In my dts board, I described my output as follows:
regulator-deviceX {
status = "okay";
compatible = "regulator-fixed";
regulator-name = "DEV_X_ON#";
regulator-min-microvolt = <3300000>;
regulator-max-microvolt = <3300000>;
gpio = <&gpio5 4 GPIO_ACTIVE_LOW>;
};
And of course after loading "gpio = <& gpio5 4 GPIO_ACTIVE_LOW>" it was locked by the kernel and cannot be used through the / sys / class / gpio interface.
Think badly about this approach, it is not possible (or I don’t see how) to change the state of the governor from user space, as you can see the "state" is a read-only file.
root@board:/sys/class/regulator/regulator.1# ls -l
lrwxrwxrwx 1 root root 0 May 3 03:32 device -> ../../../regulator-deviceX
-r--r--r-- 1 root root 4096 May 3 03:32 microvolts
-r--r--r-- 1 root root 4096 May 3 03:32 name
-r--r--r-- 1 root root 4096 May 3 03:32 num_users
drwxr-xr-x 2 root root 0 May 3 03:32 power
-r--r--r-- 1 root root 4096 May 3 03:32 state
lrwxrwxrwx 1 root root 0 May 3 03:25 subsystem -> ../../../../class/regulator
-r--r--r-- 1 root root 4096 May 3 03:32 suspend_disk_state
-r--r--r-- 1 root root 4096 May 3 03:32 suspend_mem_state
-r--r--r-- 1 root root 4096 May 3 03:32 suspend_standby_state
-r--r--r-- 1 root root 4096 May 3 03:32 type
-rw-r--r-- 1 root root 4096 May 3 03:25 uevent
source to share
So the final solution looks like this:
Step 1
Describe the device in the device tree, although you don't need a kernel to handle it, but it looks right to describe it here
gps-reciever {
compatible = "my_company_name,gps_recv_name";
vcc-supply = <&ext_gps_recv_reg>;
comment = "connected via usb<->rs232, port0";
};
where ext_gps_recv_reg is any normal regulator.
Step 2
I wrote a simple platform device driver for linux kernel compatible with the device above and in the probing function for that I call platform_device_register_full which sets the arguments for userpace_consumer.
After that I can find a suitable file by name: cat / sys / bus / platform / devices / reg-userspace-consumer * / name and then disable / enable the regulator via: echo "disabled"> / sys / bus / platform / devices / reg-userspace-consumer * / state
So I am separating the device description from the Linux kernel implementation.
source to share