Linux regulator user space consume driver : missing state under sysfs - linux

I'm trying to use the reg-userspace-consumer driver to turn on/off a USB bus supply. Looks like the the driver was back-ported to 4.4.143. All I had to do is to compile the kernel with the driver:
CONFIG_REGULATOR_USERSPACE_CONSUMER=y
and link it with the targeted regulator through the device tree :
vcc_otg_vbus: otg-vbus-regulator {
compatible = "regulator-fixed";
enable-active-high;
gpio = <&gpio0 RK_PC5 GPIO_ACTIVE_HIGH>;
pinctrl-names = "default";
pinctrl-0 = <&otg_vbus_drv>;
regulator-name = "vcc_otg_vbus";
};
vcc_otg_vbus_switch {
status = "okay";
compatible = "reg-userspace-consumer";
regulator-name = "vcc-otg-vbus-consumer";
#regulator-boot-on;
regulator-supplies = "vbus";
vbus-supply = <&vcc_otg_vbus>;
comment = "USB OTG power switch";
};
The sysfs hook does show up but it's missing the state file :
root# ls /sys/devices/platform/vcc_otg_vbus_switch/
driver_override modalias of_node power subsystem uevent
As far as I can see, the driver doesn't provide more control over the regulator from user space than regulator-fixed. Am I missing something? Thanks.

The driver was upstream but the patch as described here wasn't applied.

Related

How to match a Linux driver with a hardware device

I am writing a Linux driver for some custom hardware. My questions is how does Linux match the hardware to my driver. The hardware's DT entry is
nvme_host_sys#43c00000 {
clock-names = "sys_clk_p", "sys_clk_n", "aclk";
clocks = <0x13 0x13 0x13>;
compatible = "xlnx,nvme-host-sys-1.0";
interrupt-names = "intr";
interrupt-parent = <0x4>;
interrupts = <0x0 0x1d 0x4>;
reg = <0x43c00000 0x80000>;
phandle = <0x38>;
};
I can insert my driver using modprobe and that works fine as I can see the printk in the init being written. I can also create an entry in /dev using mknod and that also works fine. But is the driver now associated with the hardware? Do I need to do something else? Thanks
I found the solution. In the driver code we just need to add the following :-
static struct of_device_id nvmedrv_of_match[] = {
{ .compatible = "xlnx,nvme-host-sys-1.0", },
{ /* end of list */ },
};

Reading from uart

I am using am57x micro-controller and plugged my ublox neo-m8n gps to UART6. After putting uart6 in device tree as shown below, how can I know which file to read from? i couldn't find anything in /sys/class/.. how do i know which tty file the gps is writing to? Are there any uart native commands like the iscdetect and i2cget for i2c? Any help is appreciated
From dra7.dtsi:
uart6: serial#48068000 {
compatible = "ti,dra742-uart", "ti,omap4-uart";
reg = <0x48068000 0x100>;
interrupts = <GIC_SPI 101 IRQ_TYPE_LEVEL_HIGH>;
ti,hwmods = "uart6";
clock-frequency = <48000000>;
status = "disabled";
dmas = <&sdma_xbar 79>, <&sdma_xbar 80>;
dma-names = "tx", "rx";
};
From my device tree:
&uart6 {
pinctrl-names = "default";
pinctrl-0 = <&uart6_pins_default>;
status = "okay";
};
Never mind, after a lot of trial, I found out that it was writing to /dev/ttyS5. The link below helped me figure it out:
https://www.technexion.com/support/knowledgebase/using-a-serial-port-from-a-linux-shell/
If you are running linux and your serial device is detected by the kernel. It will print the message in the kernel log buffer where the device is attached.
If the device is not showing in /sys/class check the kernel logs using "dmesg" command after inserting the module. It will show error if kernel not able detect your device properly.

Linux device tree (AD5628)

I am trying to use AD5628 Digital to analog converter on my raspberry Pi 3 board . I have enabled the driver for that (http://lxr.free-electrons.com/source/drivers/iio/dac/ad5064.c) in the Yocto kernel .
But when i opened the path /sys/bus/iio/devices/
Mentioned in (https://wiki.analog.com/resources/tools-software/linux-drivers/iio-dac/ad5446) i am not getting any device0.
I got to know that it is a Device tree issue , So i refereed some web sites (https://patchwork.kernel.org/patch/7374261/) and came to know that i need to add the following Device tree details
ad5628-1#4 {
compatible = "adi,ad5628-1";
reg = <4>;
spi-max-frequency = <10000000>;
adi,use-external-reference;
};
But i am not able to find where to add this information in the linux kernel . and how to enable the device tree for this so that my DAC device should be detected by Linux .
Any help regarding this issue will be greatly appreciated
How is the DAC connected to your RPi board ? (SPI/i2c.. ??), so you need to add the dac as part of that device.
For example, in the link which you mentioned the dac is connected to the SPI, so similarly on those lines you need add the DT nodes and also enable the driver in the kernel.
axi_spi_1: spi#42040000 {
#address-cells = <1>;
#size-cells = <0>;
compatible = "xlnx,axi-spi-1.02.a", "xlnx,xps-spi-2.00.a";
...
ad5446#0 {
compatible = "adi,ad5446";
reg = <0>;
spi-max-frequency = <1000000>;
spi-cpha;
spi-cpol;
vcc-supply = <&dac_vcc>;
};
};

Device interfacing using SMBus on Beaglebone Black

I am using ADM1032ARMZ-2R temperature sensor (as a beginner I am not allowed to post more than 2 links here, I have already posted 2 links for the images below - For datasheet please google ADM1032ARMZ-2R) with Beaglebone Black Rev C having pre-installed Debian (kernel - 3.8.13) . The datasheet of ADM1032 says that chip is available for communication at address 0x4D via SMBus Protocol. I have never worked on SMbus before but found that I2C is compatible with SMBus for 100 KHz and less. I tried doing following things
I wrote a device tree overlay. It looks like following (I have kept the frequency as 100 KHz)
// Device Tree Overlay for I2C1 uses Pins P9.17(SCLK) & P9.18(SDA)
/dts-v1/;
/plugin/;
/ {
compatible = "ti,beaglebone", "ti,beaglebone-black";
part-number = "BBB-I2C1-4D";
version = "00A0";
exclusive-use =
"P9.18", /* i2c1_sda */
"P9.17", /* i2c1_scl */
/* the hardware ip uses */
fragment#0 {
target = <&am33xx_pinmux>;
__overlay__ {
bb_i2c1_pins: pinmux_bb_i2c1_pins {
pinctrl-single,pins = <
0x158 0x72 /* spi0_d1.i2c1_sda, SLEWCTRL_SLOW | INPUT_PULLUP | MODE2 */
0x15c 0x72 /* spi0_cs0.i2c1_scl, SLEWCTRL_SLOW | INPUT_PULLUP | MODE2 */
>;
};
};
};
fragment#1 {
target = <&i2c1>;
__overlay__ {
status = "okay";
pinctrl-names = "default";
pinctrl-0 = <&bb_i2c1_pins>;
clock-frequency = <100000>;
#address-cells = <1>;
#size-cells = <0>;
/* adding adm1032 as i2c child device on the bus here */
tempsense: tempsense#4d {
compatible = "onsemi,adm1032";
reg = <0x4d>;
};
};
};
};
Compiled this file, copied the resultant .dtbo file in the /lib/firmware directory and successfully inserted it as a virtual cape in the /sys/devices/bone_capemgr.9/slots using echo command. It looks like this
I tried to observe the correctness of the above work using the following command
dtc -f -I fs /proc/device-tree | less
Intended things are happening and it looks like this (Please note that, for i2c1, the "ti,hwmods" field in the image shows "i2c2", but its actually i2c1 so please don't worry about it. I have read about it made sure that whatever it's showing is correct)
Now I am trying to do
i2cdetect -r 1
But I am not able to detect anything
at 0x02, there is a Status register available for reading
i2cget -y -f 0x4d 0x02
I get Read failed response
Where am I going wrong ? Please help.

Modifying the device tree for the Beaglebone Black

I have used Yocto to create a small linux image for the Beaglebone Black. I think I have most everything working like I want it, except I need access to UARTs 2 and 4. When I was using the standard Debian image, I did this with device tree overlays and capemgr. However, I found that the kernel built with Yocto doesn't have capemgr.
My options seem to be:
get the kernel to build with capemgr, or
modify the device tree file with the necessary changes.
Option 2 seems much easier.
The device tree overlays for the UARTs are here and here. I have gone about trying to include those in a couple ways.
I decompiled the device tree blob I had been using and tried to
include these files from there.
I downloaded the full set of dts files and tried to include the
UART device tree overlays in am335x-boneblack.dts.
Both approaches yield an error something like this:
Error: am335x-boneblack.dts:1.1-2 syntax error
FATAL ERROR: Unable to parse input tree
However, I noticed that I get a similar error when trying to compile am335x-boneblack.dts even without modifying it, so I'm likely not even doing that right. (Using the command dtc -I dts -O dtb -o result.dtb am335x-boneblack.dts)
Obviously I don't know what I'm doing. I suspect the device tree overlays have to be modified in some way to be used in the way I'm trying to use them. Or maybe I'm not doing the include right (just adding a #include to the top of the file).
Does anybody have any ideas what I might be doing wrong? Is what I'm trying to do even possible?
So I got this working by taking my device tree blob, decompiling it, and merging in sections from the device tree overlay files, and recompiling. I realized I needed uarts 1 and 2 instead of 2 and 4, so this is slightly different than my original problem.
To decompile the device tree blob:
dtc -I dtb -O dts -o am335x-boneblack.dts am335x-boneblack.dtb
I used the existing uart0 as an example to show me the right sections to work in.
I added a section for uart1 and uart2 in the pinmux section under the section for uart0. It now looks like this:
pinmux_uart0_pins {
pinctrl-single,pins = <0x170 0x30 0x174 0x0>;
linux,phandle = <0x27>;
phandle = <0x27>;
};
bb_uart1_pins: pinmux_bb_uart1_pins {
pinctrl-single,pins = <
0x184 0x20 /* P9.24 uart1_txd.uart1_txd OUTPUT */
0x180 0x20 /* P9.26 uart1_rxd.uart1_rxd INPUT */
>;
};
bb_uart2_pins: pinmux_bb_uart2_pins {
pinctrl-single,pins = <
0x150 0x21 /okay* spi0_sclk.uart2_rxd | MODE1 */
0x154 0x01 /* spi0_d0.uart2_txd | MODE1 */
>;
};
Then later, the serial sections need to be enabled and told what pins to use. I modified existing uart sections, and it now looks like this:
serial#44e09000 {
compatible = "ti,omap3-uart";
ti,hwmods = "uart1";
clock-frequency = <0x2dc6c00>;
reg = <0x44e09000 0x2000>;
interrupts = <0x48>;
status = "okay";
dmas = <0x26 0x1a 0x26 0x1b>;
dma-names = "tx", "rx";
pinctrl-names = "default";
pinctrl-0 = <0x27>;
};
serial#48022000 {
compatible = "ti,omap3-uart";
ti,hwmods = "uart2";
clock-frequency = <0x2dc6c00>;
reg = <0x48022000 0x2000>;
interrupts = <0x49>;
status = "okay";
dmas = <0x26 0x1c 0x26 0x1d>;
dma-names = "tx", "rx";
pinctrl-names = "default";
pinctrl-0 = <&bb_uart1_pins>;
};
serial#48024000 {
compatible = "ti,omap3-uart";
ti,hwmods = "uart3";
clock-frequency = <0x2dc6c00>;
reg = <0x48024000 0x2000>;
interrupts = <0x4a>;
status = "okay";
dmas = <0x26 0x1e 0x26 0x1f>;
dma-names = "tx", "rx";
pinctrl-names = "default";
pinctrl-0 = <&bb_uart2_pins>;
}
To recompile the device tree:
dtc -I dts -O dtb -o am335x-boneblack.dtb am335x-boneblack.dts
In short, I managed to get this working despite having little to no idea how device trees work.
I also needed to disable hdmi which I did by setting status equal to "disabled" in the hdmi section.

Resources