Re: [PATCH] lis3: add click function

From: Daniel Mack
Date: Fri Jun 12 2009 - 08:32:35 EST


Hi Eric,

On Fri, Jun 12, 2009 at 01:44:52PM +0200, Éric Piel wrote:
> Op 12-06-09 12:37, Daniel Mack schreef:
> > The LIS3 accelerometer chip has a 'click' feature which can be used to
> > detect sudden motion on any of the three axis. Configuration data is
> > passed via spi platform_data and no action is taken if that's not
> > specified, so it won't harm any existing platform.
> >
> > To make the configuration effective, the IRQ lines need to be set up
> > appropriately. This patch also adds a way to do that from board support
> > code.
> >
> > The DD_* definitions were removed because I couldn't find any reference
> > of them in the datasheet and the overlapped with the CLICK_ register
> > space.
> Hello,
> It's not so simple. The driver supports both LIS302xx and LIS3LV02xx.
> The LIS302xx (whoami == 0x3A) has CLICK_* registers, and the LIS3LV02xx
> (whoami == 0x3B) has DD_* registers. So first of all, you should not
> remove the references to DD_*, just add the CLICK_* definitions after
> them. Moreover, the usage of those registers should therefore be
> conditioned to whoami == 0x3A.

Ok, I can split the register definitions.

> Also, I did not follow all the black magic happening with platform_data.
> Could you explain how much would be needed to have the same feature in
> the ACPI side?

It's not so much black magic but follows the standard procedure for
passing device specific data to probed SPI devices. What you find in
board support code for embedded devices is a defintion of an
spi_board_info struct. On my platform, it looks like this for the lis3
device:

static struct lis3lv02d_platform_data lis3_pdata = {
.click_flags = LIS3_CLICK_SINGLE_X |
LIS3_CLICK_SINGLE_Y |
LIS3_CLICK_SINGLE_Z,
.click_thresh_x = 10,
.click_thresh_y = 10,
.click_thresh_z = 10,
.irq_cfg = LIS3_IRQ1_CLICK,
LIS3_IRQ_ACTIVE_HIGH,
};

static struct spi_board_info my_spi_devices[] __initdata = {
{
.modalias = "lis3lv02d_spi",
.max_speed_hz = 1000000,
.bus_num = 0,
.chip_select = 0,
.controller_data = (void *) mfp_to_gpio(GPIO_ACCEL_CS),
.platform_data = &lis3_pdata,
.irq = gpio_to_irq(mfp_to_gpio(GPIO_ACCEL_IRQ)),
},

I don't know ACPI, so I can't say how a similiar abstraction could be
achieved.

> Also, it seems to only set up the "click" feature, without ever using
> it. How do you access this information from userspace? Is it specific to
> SPI? Maybe it could also generate button events in the joystick interface?

We're using the IRQ outputs of that chips directly as source to other
circuity, so there is no userspace logic in the game. If anyone needs
that, a simple callback function would be easy to add at some later
point.

See the updated patch below.

Thanks,
Daniel