cancel
Showing results for 
Search instead for 
Did you mean: 

I am using lis2dw12 on a congnitect chip with linux. How can I set register via sysfs for this device ?

RRath.2
Associate II

I am using lis2dw12 on congnitec board on linux. lis2dw12  is enumerated only as iio device as I do not configure spidev. I have to configure the interrupts 0x3F , CTL_1. How can I set this from sysfs interface ?

9 REPLIES 9
RRath.2
Associate II

Guys any update on this ? I know it might trivial thing I might be missing.

Federica Bossi
ST Employee

Ciao @RRath.2​ ,

Where did you find the driver?

You can find here the repository managed by ST, let me know if it is the one you are using.

In order to give better visibility on the answered topics, please click on 'Accept as Solution' on the reply which solved your issue or answered your question.
RRath.2
Associate II

Hello @Federica Bossi​ 

Thanks for helping me out.

This is the kernel/ version , I am using and I could not see TAP or TAP TAP or gesture events being added to main line kernel from ST.

https://elixir.bootlin.com/linux/v6.2.11/source/drivers/iio/accel/st_accel_core.c

Also even with your repository - https://github.com/STMicroelectronics/st-mems-android-linux-drivers-iio/tree/master/drivers/iio/stm/accel

  1. How do I register for event that free fall happed to user mode vai sysfs or any other means ? Can you point me to a sample code ? For example - User mode application set the orientation threshold as 60 degree and user mode application should be able to notified when this threshold crossed .
  2. Even a different or small sample app code would also help to see if any of the interrupt is being fired and capture in user mode via sysfs.
  3. For example - The following example implements a SW routine for 6D orientation detection:
1. Write 64h in CTRL1 // Turn on the accelerometer
// ODR = 200 Hz, High-Performance
2. Write 04h in CTRL6 // FS ±2 g, LOW_NOISE enabled
3. Write 20h in CTRL7 // Do not use low-pass filter for 6D, enable interrupts
4. Write 40h in TAP_THS_X // Set 6D threshold (6D_THS[1:0] = 10b = 60 degrees)
5. Write 80h in CTRL4_INT1_PAD_CTRL // 6D interrupt driven to INT1 pin

Now how can I configure such this via sysfs. My understanding is that when I configure lis2dw12 like above , I should be able to verify GPIO toggle or read INT1/INT2 pin.

Federica Bossi
ST Employee

Ciao @RRath.2​ ,

Up to now we do not yet support the k6.1 version, we are bringing it, in the previous kernel version (up to 5.15) the TAP and Double TAP types didn't exist as events and for this reason they had to be added in types.h by the patches that are included in the github repository.

In order to receive tap/tap_tap/wu events (some events like free fall, 6d rotation, sleep monitoring etc... are not yet supported by the driver but can be easly added), you must first enable them and then poll the fd relating to the IIO events. An application example can be found in the IIO utils documentation (https://github.com/torvalds/linux/blob/master/tools/iio/iio_event_monitor.c)

As regards the configurability of the thresholds, let's say that the driver we release is a reference code that can be modified according to the customer's needs.

If my replies answered your question, please click on Select as Best at the bottom of this post. This will help other users with the same issue to find the answer faster.

In order to give better visibility on the answered topics, please click on 'Accept as Solution' on the reply which solved your issue or answered your question.
RRath.2
Associate II

@Federica Bossi​ 

Thanks for helping.

Existing Release kernel even version 5.x.x

https://elixir.bootlin.com/linux/v5.19.17/source/drivers/iio/accel/st_accel_core.c

  1. I understand there is no support for events even like tap, double tap etc. How can we use this IIO device from user mode to detect whether there is change in orientation ? I believe this is not possible via sysfs or even IIO libs as driver doesn't have support for it. Please let me know if there is way.
  2. I am wondering how others are using lis2dw12 for such event detections. I believe only way it to user it via SPI dev and set the register directly.
  3. Please suggest , if there is a any way IIO device or SpiDev way to utilize the interrupt functionality at user level. Like any ST libs which wraps around spidev and help with detecting the orientation interrupt change.

With ST IIO Linux Driver

 https://github.com/STMicroelectronics/st-mems-android-linux-drivers-iio/tree/master/drivers/iio/stm/acce

  1. I tried to use it but getting error "failed to request trigger irq" because driver code uses hard coded IRQF_TRIGGER_HIGH | IRQF_ONESHOT.
int st_lis2dw12_fifo_setup(struct st_lis2dw12_hw *hw)
{
	struct iio_dev *iio_dev = hw->iio_devs[ST_LIS2DW12_ID_ACC];
#if LINUX_VERSION_CODE < KERNEL_VERSION(5,13,0)
	struct iio_buffer *buffer;
#endif /* LINUX_VERSION_CODE */
	int ret;
 
	ret = devm_request_threaded_irq(hw->dev, hw->irq,
					st_lis2dw12_handler_irq,
					st_lis2dw12_handler_thread,
					IRQF_TRIGGER_HIGH | IRQF_ONESHOT ,
					"st_lis2dw12", hw);
	if (ret) {
		dev_err(hw->dev, "failed to request trigger irq %d\n",
			hw->irq);
		return ret;
	}

Since my driver interrupt pin can only be configured as  interrupts = <4 IRQ_TYPE_EDGE_RISING>; I am not able to use this driver.

Question is : Why driver code is supporting only IRQF_TRIGGER_HIGH | IRQF_ONESHOT ?

I am still trying to figure out what is preventing my device tree to use as IRQF_TRIGGER_HIGH but somehow it doesn't work. Driver only loads if I use interrupts = <4 IRQ_TYPE_EDGE_RISING> and change the driver code to use this as well

ret = devm_request_threaded_irq(hw->dev, hw->irq,
					st_lis2dw12_handler_irq,
					st_lis2dw12_handler_thread,
					IRQF_TRIGGER_HIGH | IRQF_ONESHOT | IRQF_TRIGGER_RISING ,
					"st_lis2dw12", hw);

but I am not sure what is the implication of this on other parts of driver code.

Regards,

Ravi Rathore

RRath.2
Associate II

@@Federica Boss , please help here

RRath.2
Associate II

@Federica Bossi​ - Is there any official support email id ,which I can send my query to ?

RRath.2
Associate II

@A ST Supporter​ can any one help?

Federica Bossi
ST Employee

Ciao @RRath.2​ ,

We do not recommend using spidev to write to the device's internal registers, rather we can check what your requests are and give you support on the driver we manage here also because for the driver version on mainline kernel the times are obviously longer.

To detect driver events when certain gestures are recognized by the device (such as tap, dtap, wake-up, free fall and 6d), the driver generates an IIO event related to the device that recognized that event, so it is just needed to poll the IIO device descriptor file, for reference you can see the iio_event_monitor test application. You can download it from https://github.com/torvalds/linux/tree/master/tools/iio

Configuring the driver with IRQ_TYPE_EDGE_RISING could risk losing an interrupt when using the FIFO and this would lead to the interruption of reading data from the sensor, generally when using the FIFO it is recommended to use a level interrupt.

If you want more support, you need to open a ticket on the OLS support here.

In order to give better visibility on the answered topics, please click on 'Accept as Solution' on the reply which solved your issue or answered your question.