Re: [PATCH v9] iio: acpi: Add support for ACPI0008 Ambient Light Sensor

2015-05-09 Thread Daniel Baluta
On Sat, May 9, 2015 at 9:45 PM, Gabriele Mazzotta
 wrote:
> On Saturday 02 May 2015 14:30:57 Gabriele Mazzotta wrote:
>> This driver adds the initial support for the ACPI Ambient Light Sensor
>> as defined in Section 9.2 of the ACPI specification (Revision 5.0) [1].
>>
>> Sensors complying with the standard are exposed as ACPI devices with
>> ACPI0008 as hardware ID and provide standard methods by which the OS
>> can query properties of the ambient light environment the system is
>> currently operating in.
>>
>> This driver currently allows only to get the current ambient light
>> illuminance reading through the _ALI method, but is ready to be
>> extended extended to handle _ALC, _ALT and _ALP as well.
>>
>> [1] http://www.acpi.info/DOWNLOADS/ACPIspec50.pdf
>>
>> Signed-off-by: Martin Liska 
>> Signed-off-by: Marek Vasut 
>> Signed-off-by: Gabriele Mazzotta 
>> Cc: Zhang Rui 
>> ---
>> Changes since v8:
>>  - Set realbits to 32
>>  - Fix license mismatch (using GPL v2 or later)
>>  - Drop iio_device_unregister() in favor of devm_iio_device_register()
>>
>>  drivers/iio/light/Kconfig|  12 +++
>>  drivers/iio/light/Makefile   |   1 +
>>  drivers/iio/light/acpi-als.c | 232 
>> +++
>>  3 files changed, 245 insertions(+)
>>  create mode 100644 drivers/iio/light/acpi-als.c
>>
>> diff --git a/drivers/iio/light/Kconfig b/drivers/iio/light/Kconfig
>> index 01a1a16..898b2b5 100644
>> --- a/drivers/iio/light/Kconfig
>> +++ b/drivers/iio/light/Kconfig
>> @@ -5,6 +5,18 @@
>>
>>  menu "Light sensors"
>>
>> +config ACPI_ALS
>> + tristate "ACPI Ambient Light Sensor"
>> + depends on ACPI
>
> I'm sorry, but I've just noticed that here there should also be
>
> select IIO_BUFFER
>
> I hope it's not too late and I can resend this patch if needed.

You can send a patch on top of the previous one. Eventually, Jonathan
will squash them.

Daniel.
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH v9] iio: acpi: Add support for ACPI0008 Ambient Light Sensor

2015-05-09 Thread Gabriele Mazzotta
On Saturday 02 May 2015 14:30:57 Gabriele Mazzotta wrote:
> This driver adds the initial support for the ACPI Ambient Light Sensor
> as defined in Section 9.2 of the ACPI specification (Revision 5.0) [1].
> 
> Sensors complying with the standard are exposed as ACPI devices with
> ACPI0008 as hardware ID and provide standard methods by which the OS
> can query properties of the ambient light environment the system is
> currently operating in.
> 
> This driver currently allows only to get the current ambient light
> illuminance reading through the _ALI method, but is ready to be
> extended extended to handle _ALC, _ALT and _ALP as well.
> 
> [1] http://www.acpi.info/DOWNLOADS/ACPIspec50.pdf
> 
> Signed-off-by: Martin Liska 
> Signed-off-by: Marek Vasut 
> Signed-off-by: Gabriele Mazzotta 
> Cc: Zhang Rui 
> ---
> Changes since v8:
>  - Set realbits to 32
>  - Fix license mismatch (using GPL v2 or later)
>  - Drop iio_device_unregister() in favor of devm_iio_device_register()
> 
>  drivers/iio/light/Kconfig|  12 +++
>  drivers/iio/light/Makefile   |   1 +
>  drivers/iio/light/acpi-als.c | 232 
> +++
>  3 files changed, 245 insertions(+)
>  create mode 100644 drivers/iio/light/acpi-als.c
> 
> diff --git a/drivers/iio/light/Kconfig b/drivers/iio/light/Kconfig
> index 01a1a16..898b2b5 100644
> --- a/drivers/iio/light/Kconfig
> +++ b/drivers/iio/light/Kconfig
> @@ -5,6 +5,18 @@
>  
>  menu "Light sensors"
>  
> +config ACPI_ALS
> + tristate "ACPI Ambient Light Sensor"
> + depends on ACPI

I'm sorry, but I've just noticed that here there should also be

select IIO_BUFFER

I hope it's not too late and I can resend this patch if needed.

Gabriele

> + select IIO_TRIGGERED_BUFFER
> + select IIO_KFIFO_BUF
> + help
> +  Say Y here if you want to build a driver for the ACPI0008
> +  Ambient Light Sensor.
> +
> +  To compile this driver as a module, choose M here: the module will
> +  be called acpi-als.
> +
>  config ADJD_S311
>   tristate "ADJD-S311-CR999 digital color sensor"
>   select IIO_BUFFER
> diff --git a/drivers/iio/light/Makefile b/drivers/iio/light/Makefile
> index ad7c30f..d9aad52a 100644
> --- a/drivers/iio/light/Makefile
> +++ b/drivers/iio/light/Makefile
> @@ -3,6 +3,7 @@
>  #
>  
>  # When adding new entries keep the list in alphabetical order
> +obj-$(CONFIG_ACPI_ALS)   += acpi-als.o
>  obj-$(CONFIG_ADJD_S311)  += adjd_s311.o
>  obj-$(CONFIG_AL3320A)+= al3320a.o
>  obj-$(CONFIG_APDS9300)   += apds9300.o
> diff --git a/drivers/iio/light/acpi-als.c b/drivers/iio/light/acpi-als.c
> new file mode 100644
> index 000..9839c9a
> --- /dev/null
> +++ b/drivers/iio/light/acpi-als.c
> @@ -0,0 +1,232 @@
> +/*
> + * ACPI Ambient Light Sensor Driver
> + *
> + * Based on ALS driver:
> + * Copyright (C) 2009 Zhang Rui 
> + *
> + * Rework for IIO subsystem:
> + * Copyright (C) 2012-2013 Martin Liska 
> + *
> + * Final cleanup and debugging:
> + * Copyright (C) 2013-2014 Marek Vasut 
> + * Copyright (C) 2015 Gabriele Mazzotta 
> + *
> + * This program is free software; you can redistribute it and/or modify it
> + * under the terms of the GNU General Public License as published by the
> + * Free Software Foundation; either version 2 of the License, or (at your
> + * option) any later version.
> + *
> + * This program is distributed in the hope that it will be useful, but
> + * WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
> + * General Public License for more details.
> + *
> + * You should have received a copy of the GNU General Public License along
> + * with this program; if not, write to the Free Software Foundation, Inc.,
> + * 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
> + */
> +
> +#include 
> +#include 
> +#include 
> +#include 
> +
> +#include 
> +#include 
> +#include 
> +
> +#define ACPI_ALS_CLASS   "als"
> +#define ACPI_ALS_DEVICE_NAME "acpi-als"
> +#define ACPI_ALS_NOTIFY_ILLUMINANCE  0x80
> +
> +ACPI_MODULE_NAME("acpi-als");
> +
> +/*
> + * So far, there's only one channel in here, but the specification for
> + * ACPI0008 says there can be more to what the block can report. Like
> + * chromaticity and such. We are ready for incoming additions!
> + */
> +static const struct iio_chan_spec acpi_als_channels[] = {
> + {
> + .type   = IIO_LIGHT,
> + .scan_type  = {
> + .sign   = 's',
> + .realbits   = 32,
> + .storagebits= 32,
> + },
> + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
> + },
> +};
> +
> +/*
> + * The event buffer contains timestamp and all the data from
> + * the ACPI0008 block. There are multiple, but so far we only
> + * support _ALI (illuminance). Once someone adds new chann

Re: [PATCH v9] iio: acpi: Add support for ACPI0008 Ambient Light Sensor

2015-05-08 Thread Marek Vasut
On Friday, May 08, 2015 at 11:34:35 PM, Jonathan Cameron wrote:
> On 8 May 2015 20:20:33 BST, Gabriele Mazzotta  wrote:
> >On Friday 08 May 2015 10:58:29 Jonathan Cameron wrote:
> >> On 02/05/15 08:30, Gabriele Mazzotta wrote:
> >> > This driver adds the initial support for the ACPI Ambient Light
> >
> >Sensor
> >
> >> > as defined in Section 9.2 of the ACPI specification (Revision 5.0)
> >
> >[1].
> >
> >> > Sensors complying with the standard are exposed as ACPI devices
> >
> >with
> >
> >> > ACPI0008 as hardware ID and provide standard methods by which the
> >
> >OS
> >
> >> > can query properties of the ambient light environment the system is
> >> > currently operating in.
> >> > 
> >> > This driver currently allows only to get the current ambient light
> >> > illuminance reading through the _ALI method, but is ready to be
> >> > extended extended to handle _ALC, _ALT and _ALP as well.
> >> > 
> >> > [1] http://www.acpi.info/DOWNLOADS/ACPIspec50.pdf
> >> > 
> >> > Signed-off-by: Martin Liska 
> >> > Signed-off-by: Marek Vasut 
> >> > Signed-off-by: Gabriele Mazzotta 
> >> > Cc: Zhang Rui 

Thank you guys for finally getting this mainline :)

Best regards,
Marek Vasut
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH v9] iio: acpi: Add support for ACPI0008 Ambient Light Sensor

2015-05-08 Thread Jonathan Cameron


On 8 May 2015 20:20:33 BST, Gabriele Mazzotta  wrote:
>On Friday 08 May 2015 10:58:29 Jonathan Cameron wrote:
>> On 02/05/15 08:30, Gabriele Mazzotta wrote:
>> > This driver adds the initial support for the ACPI Ambient Light
>Sensor
>> > as defined in Section 9.2 of the ACPI specification (Revision 5.0)
>[1].
>> > 
>> > Sensors complying with the standard are exposed as ACPI devices
>with
>> > ACPI0008 as hardware ID and provide standard methods by which the
>OS
>> > can query properties of the ambient light environment the system is
>> > currently operating in.
>> > 
>> > This driver currently allows only to get the current ambient light
>> > illuminance reading through the _ALI method, but is ready to be
>> > extended extended to handle _ALC, _ALT and _ALP as well.
>> > 
>> > [1] http://www.acpi.info/DOWNLOADS/ACPIspec50.pdf
>> > 
>> > Signed-off-by: Martin Liska 
>> > Signed-off-by: Marek Vasut 
>> > Signed-off-by: Gabriele Mazzotta 
>> > Cc: Zhang Rui 
>> Sorry, one last point inline that I missed before!
>> 
>> (just noticed it when taking a last glance before applying the
>patch).
>> 
>> Jonathan
>> > ---
>> > Changes since v8:
>> >  - Set realbits to 32
>> >  - Fix license mismatch (using GPL v2 or later)
>> >  - Drop iio_device_unregister() in favor of
>devm_iio_device_register()
>> > 
>> >  drivers/iio/light/Kconfig|  12 +++
>> >  drivers/iio/light/Makefile   |   1 +
>> >  drivers/iio/light/acpi-als.c | 232
>+++
>> >  3 files changed, 245 insertions(+)
>> >  create mode 100644 drivers/iio/light/acpi-als.c
>> > 
>> > diff --git a/drivers/iio/light/Kconfig b/drivers/iio/light/Kconfig
>> > index 01a1a16..898b2b5 100644
>> > --- a/drivers/iio/light/Kconfig
>> > +++ b/drivers/iio/light/Kconfig
>> > @@ -5,6 +5,18 @@
>> >  
>> >  menu "Light sensors"
>> >  
>> > +config ACPI_ALS
>> > +  tristate "ACPI Ambient Light Sensor"
>> > +  depends on ACPI
>> > +  select IIO_TRIGGERED_BUFFER
>> > +  select IIO_KFIFO_BUF
>> > +  help
>> > +   Say Y here if you want to build a driver for the ACPI0008
>> > +   Ambient Light Sensor.
>> > +
>> > +   To compile this driver as a module, choose M here: the module
>will
>> > +   be called acpi-als.
>> > +
>> >  config ADJD_S311
>> >tristate "ADJD-S311-CR999 digital color sensor"
>> >select IIO_BUFFER
>> > diff --git a/drivers/iio/light/Makefile
>b/drivers/iio/light/Makefile
>> > index ad7c30f..d9aad52a 100644
>> > --- a/drivers/iio/light/Makefile
>> > +++ b/drivers/iio/light/Makefile
>> > @@ -3,6 +3,7 @@
>> >  #
>> >  
>> >  # When adding new entries keep the list in alphabetical order
>> > +obj-$(CONFIG_ACPI_ALS)+= acpi-als.o
>> >  obj-$(CONFIG_ADJD_S311)   += adjd_s311.o
>> >  obj-$(CONFIG_AL3320A) += al3320a.o
>> >  obj-$(CONFIG_APDS9300)+= apds9300.o
>> > diff --git a/drivers/iio/light/acpi-als.c
>b/drivers/iio/light/acpi-als.c
>> > new file mode 100644
>> > index 000..9839c9a
>> > --- /dev/null
>> > +++ b/drivers/iio/light/acpi-als.c
>> > @@ -0,0 +1,232 @@
>> > +/*
>> > + * ACPI Ambient Light Sensor Driver
>> > + *
>> > + * Based on ALS driver:
>> > + * Copyright (C) 2009 Zhang Rui 
>> > + *
>> > + * Rework for IIO subsystem:
>> > + * Copyright (C) 2012-2013 Martin Liska 
>> > + *
>> > + * Final cleanup and debugging:
>> > + * Copyright (C) 2013-2014 Marek Vasut 
>> > + * Copyright (C) 2015 Gabriele Mazzotta 
>> > + *
>> > + * This program is free software; you can redistribute it and/or
>modify it
>> > + * under the terms of the GNU General Public License as published
>by the
>> > + * Free Software Foundation; either version 2 of the License, or
>(at your
>> > + * option) any later version.
>> > + *
>> > + * This program is distributed in the hope that it will be useful,
>but
>> > + * WITHOUT ANY WARRANTY; without even the implied warranty of
>> > + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
>GNU
>> > + * General Public License for more details.
>> > + *
>> > + * You should have received a copy of the GNU General Public
>License along
>> > + * with this program; if not, write to the Free Software
>Foundation, Inc.,
>> > + * 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
>> > + */
>> > +
>> > +#include 
>> > +#include 
>> > +#include 
>> > +#include 
>> > +
>> > +#include 
>> > +#include 
>> > +#include 
>> > +
>> > +#define ACPI_ALS_CLASS"als"
>> > +#define ACPI_ALS_DEVICE_NAME  "acpi-als"
>> > +#define ACPI_ALS_NOTIFY_ILLUMINANCE   0x80
>> > +
>> > +ACPI_MODULE_NAME("acpi-als");
>> > +
>> > +/*
>> > + * So far, there's only one channel in here, but the specification
>for
>> > + * ACPI0008 says there can be more to what the block can report.
>Like
>> > + * chromaticity and such. We are ready for incoming additions!
>> > + */
>> > +static const struct iio_chan_spec acpi_als_channels[] = {
>> > +  {
>> > +  .type   = IIO_LIGHT,
>> > +  .scan_type  = {
>> > +

Re: [PATCH v9] iio: acpi: Add support for ACPI0008 Ambient Light Sensor

2015-05-08 Thread Gabriele Mazzotta
On Friday 08 May 2015 10:58:29 Jonathan Cameron wrote:
> On 02/05/15 08:30, Gabriele Mazzotta wrote:
> > This driver adds the initial support for the ACPI Ambient Light Sensor
> > as defined in Section 9.2 of the ACPI specification (Revision 5.0) [1].
> > 
> > Sensors complying with the standard are exposed as ACPI devices with
> > ACPI0008 as hardware ID and provide standard methods by which the OS
> > can query properties of the ambient light environment the system is
> > currently operating in.
> > 
> > This driver currently allows only to get the current ambient light
> > illuminance reading through the _ALI method, but is ready to be
> > extended extended to handle _ALC, _ALT and _ALP as well.
> > 
> > [1] http://www.acpi.info/DOWNLOADS/ACPIspec50.pdf
> > 
> > Signed-off-by: Martin Liska 
> > Signed-off-by: Marek Vasut 
> > Signed-off-by: Gabriele Mazzotta 
> > Cc: Zhang Rui 
> Sorry, one last point inline that I missed before!
> 
> (just noticed it when taking a last glance before applying the patch).
> 
> Jonathan
> > ---
> > Changes since v8:
> >  - Set realbits to 32
> >  - Fix license mismatch (using GPL v2 or later)
> >  - Drop iio_device_unregister() in favor of devm_iio_device_register()
> > 
> >  drivers/iio/light/Kconfig|  12 +++
> >  drivers/iio/light/Makefile   |   1 +
> >  drivers/iio/light/acpi-als.c | 232 
> > +++
> >  3 files changed, 245 insertions(+)
> >  create mode 100644 drivers/iio/light/acpi-als.c
> > 
> > diff --git a/drivers/iio/light/Kconfig b/drivers/iio/light/Kconfig
> > index 01a1a16..898b2b5 100644
> > --- a/drivers/iio/light/Kconfig
> > +++ b/drivers/iio/light/Kconfig
> > @@ -5,6 +5,18 @@
> >  
> >  menu "Light sensors"
> >  
> > +config ACPI_ALS
> > +   tristate "ACPI Ambient Light Sensor"
> > +   depends on ACPI
> > +   select IIO_TRIGGERED_BUFFER
> > +   select IIO_KFIFO_BUF
> > +   help
> > +Say Y here if you want to build a driver for the ACPI0008
> > +Ambient Light Sensor.
> > +
> > +To compile this driver as a module, choose M here: the module will
> > +be called acpi-als.
> > +
> >  config ADJD_S311
> > tristate "ADJD-S311-CR999 digital color sensor"
> > select IIO_BUFFER
> > diff --git a/drivers/iio/light/Makefile b/drivers/iio/light/Makefile
> > index ad7c30f..d9aad52a 100644
> > --- a/drivers/iio/light/Makefile
> > +++ b/drivers/iio/light/Makefile
> > @@ -3,6 +3,7 @@
> >  #
> >  
> >  # When adding new entries keep the list in alphabetical order
> > +obj-$(CONFIG_ACPI_ALS) += acpi-als.o
> >  obj-$(CONFIG_ADJD_S311)+= adjd_s311.o
> >  obj-$(CONFIG_AL3320A)  += al3320a.o
> >  obj-$(CONFIG_APDS9300) += apds9300.o
> > diff --git a/drivers/iio/light/acpi-als.c b/drivers/iio/light/acpi-als.c
> > new file mode 100644
> > index 000..9839c9a
> > --- /dev/null
> > +++ b/drivers/iio/light/acpi-als.c
> > @@ -0,0 +1,232 @@
> > +/*
> > + * ACPI Ambient Light Sensor Driver
> > + *
> > + * Based on ALS driver:
> > + * Copyright (C) 2009 Zhang Rui 
> > + *
> > + * Rework for IIO subsystem:
> > + * Copyright (C) 2012-2013 Martin Liska 
> > + *
> > + * Final cleanup and debugging:
> > + * Copyright (C) 2013-2014 Marek Vasut 
> > + * Copyright (C) 2015 Gabriele Mazzotta 
> > + *
> > + * This program is free software; you can redistribute it and/or modify it
> > + * under the terms of the GNU General Public License as published by the
> > + * Free Software Foundation; either version 2 of the License, or (at your
> > + * option) any later version.
> > + *
> > + * This program is distributed in the hope that it will be useful, but
> > + * WITHOUT ANY WARRANTY; without even the implied warranty of
> > + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
> > + * General Public License for more details.
> > + *
> > + * You should have received a copy of the GNU General Public License along
> > + * with this program; if not, write to the Free Software Foundation, Inc.,
> > + * 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
> > + */
> > +
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +
> > +#include 
> > +#include 
> > +#include 
> > +
> > +#define ACPI_ALS_CLASS "als"
> > +#define ACPI_ALS_DEVICE_NAME   "acpi-als"
> > +#define ACPI_ALS_NOTIFY_ILLUMINANCE0x80
> > +
> > +ACPI_MODULE_NAME("acpi-als");
> > +
> > +/*
> > + * So far, there's only one channel in here, but the specification for
> > + * ACPI0008 says there can be more to what the block can report. Like
> > + * chromaticity and such. We are ready for incoming additions!
> > + */
> > +static const struct iio_chan_spec acpi_als_channels[] = {
> > +   {
> > +   .type   = IIO_LIGHT,
> > +   .scan_type  = {
> > +   .sign   = 's',
> > +   .realbits   = 32,
> > +   .storagebits= 32,
> > +   },
> > +   .info_mask_separate = B

Re: [PATCH v9] iio: acpi: Add support for ACPI0008 Ambient Light Sensor

2015-05-08 Thread Jonathan Cameron
On 02/05/15 08:30, Gabriele Mazzotta wrote:
> This driver adds the initial support for the ACPI Ambient Light Sensor
> as defined in Section 9.2 of the ACPI specification (Revision 5.0) [1].
> 
> Sensors complying with the standard are exposed as ACPI devices with
> ACPI0008 as hardware ID and provide standard methods by which the OS
> can query properties of the ambient light environment the system is
> currently operating in.
> 
> This driver currently allows only to get the current ambient light
> illuminance reading through the _ALI method, but is ready to be
> extended extended to handle _ALC, _ALT and _ALP as well.
> 
> [1] http://www.acpi.info/DOWNLOADS/ACPIspec50.pdf
> 
> Signed-off-by: Martin Liska 
> Signed-off-by: Marek Vasut 
> Signed-off-by: Gabriele Mazzotta 
> Cc: Zhang Rui 
Sorry, one last point inline that I missed before!

(just noticed it when taking a last glance before applying the patch).

Jonathan
> ---
> Changes since v8:
>  - Set realbits to 32
>  - Fix license mismatch (using GPL v2 or later)
>  - Drop iio_device_unregister() in favor of devm_iio_device_register()
> 
>  drivers/iio/light/Kconfig|  12 +++
>  drivers/iio/light/Makefile   |   1 +
>  drivers/iio/light/acpi-als.c | 232 
> +++
>  3 files changed, 245 insertions(+)
>  create mode 100644 drivers/iio/light/acpi-als.c
> 
> diff --git a/drivers/iio/light/Kconfig b/drivers/iio/light/Kconfig
> index 01a1a16..898b2b5 100644
> --- a/drivers/iio/light/Kconfig
> +++ b/drivers/iio/light/Kconfig
> @@ -5,6 +5,18 @@
>  
>  menu "Light sensors"
>  
> +config ACPI_ALS
> + tristate "ACPI Ambient Light Sensor"
> + depends on ACPI
> + select IIO_TRIGGERED_BUFFER
> + select IIO_KFIFO_BUF
> + help
> +  Say Y here if you want to build a driver for the ACPI0008
> +  Ambient Light Sensor.
> +
> +  To compile this driver as a module, choose M here: the module will
> +  be called acpi-als.
> +
>  config ADJD_S311
>   tristate "ADJD-S311-CR999 digital color sensor"
>   select IIO_BUFFER
> diff --git a/drivers/iio/light/Makefile b/drivers/iio/light/Makefile
> index ad7c30f..d9aad52a 100644
> --- a/drivers/iio/light/Makefile
> +++ b/drivers/iio/light/Makefile
> @@ -3,6 +3,7 @@
>  #
>  
>  # When adding new entries keep the list in alphabetical order
> +obj-$(CONFIG_ACPI_ALS)   += acpi-als.o
>  obj-$(CONFIG_ADJD_S311)  += adjd_s311.o
>  obj-$(CONFIG_AL3320A)+= al3320a.o
>  obj-$(CONFIG_APDS9300)   += apds9300.o
> diff --git a/drivers/iio/light/acpi-als.c b/drivers/iio/light/acpi-als.c
> new file mode 100644
> index 000..9839c9a
> --- /dev/null
> +++ b/drivers/iio/light/acpi-als.c
> @@ -0,0 +1,232 @@
> +/*
> + * ACPI Ambient Light Sensor Driver
> + *
> + * Based on ALS driver:
> + * Copyright (C) 2009 Zhang Rui 
> + *
> + * Rework for IIO subsystem:
> + * Copyright (C) 2012-2013 Martin Liska 
> + *
> + * Final cleanup and debugging:
> + * Copyright (C) 2013-2014 Marek Vasut 
> + * Copyright (C) 2015 Gabriele Mazzotta 
> + *
> + * This program is free software; you can redistribute it and/or modify it
> + * under the terms of the GNU General Public License as published by the
> + * Free Software Foundation; either version 2 of the License, or (at your
> + * option) any later version.
> + *
> + * This program is distributed in the hope that it will be useful, but
> + * WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
> + * General Public License for more details.
> + *
> + * You should have received a copy of the GNU General Public License along
> + * with this program; if not, write to the Free Software Foundation, Inc.,
> + * 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
> + */
> +
> +#include 
> +#include 
> +#include 
> +#include 
> +
> +#include 
> +#include 
> +#include 
> +
> +#define ACPI_ALS_CLASS   "als"
> +#define ACPI_ALS_DEVICE_NAME "acpi-als"
> +#define ACPI_ALS_NOTIFY_ILLUMINANCE  0x80
> +
> +ACPI_MODULE_NAME("acpi-als");
> +
> +/*
> + * So far, there's only one channel in here, but the specification for
> + * ACPI0008 says there can be more to what the block can report. Like
> + * chromaticity and such. We are ready for incoming additions!
> + */
> +static const struct iio_chan_spec acpi_als_channels[] = {
> + {
> + .type   = IIO_LIGHT,
> + .scan_type  = {
> + .sign   = 's',
> + .realbits   = 32,
> + .storagebits= 32,
> + },
> + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
> + },
> +};
> +
> +/*
> + * The event buffer contains timestamp and all the data from
> + * the ACPI0008 block. There are multiple, but so far we only
> + * support _ALI (illuminance). Once someone adds new channels
> + * to acpi_als_channels[], the evt_buffer 

[PATCH v9] iio: acpi: Add support for ACPI0008 Ambient Light Sensor

2015-05-02 Thread Gabriele Mazzotta
This driver adds the initial support for the ACPI Ambient Light Sensor
as defined in Section 9.2 of the ACPI specification (Revision 5.0) [1].

Sensors complying with the standard are exposed as ACPI devices with
ACPI0008 as hardware ID and provide standard methods by which the OS
can query properties of the ambient light environment the system is
currently operating in.

This driver currently allows only to get the current ambient light
illuminance reading through the _ALI method, but is ready to be
extended extended to handle _ALC, _ALT and _ALP as well.

[1] http://www.acpi.info/DOWNLOADS/ACPIspec50.pdf

Signed-off-by: Martin Liska 
Signed-off-by: Marek Vasut 
Signed-off-by: Gabriele Mazzotta 
Cc: Zhang Rui 
---
Changes since v8:
 - Set realbits to 32
 - Fix license mismatch (using GPL v2 or later)
 - Drop iio_device_unregister() in favor of devm_iio_device_register()

 drivers/iio/light/Kconfig|  12 +++
 drivers/iio/light/Makefile   |   1 +
 drivers/iio/light/acpi-als.c | 232 +++
 3 files changed, 245 insertions(+)
 create mode 100644 drivers/iio/light/acpi-als.c

diff --git a/drivers/iio/light/Kconfig b/drivers/iio/light/Kconfig
index 01a1a16..898b2b5 100644
--- a/drivers/iio/light/Kconfig
+++ b/drivers/iio/light/Kconfig
@@ -5,6 +5,18 @@
 
 menu "Light sensors"
 
+config ACPI_ALS
+   tristate "ACPI Ambient Light Sensor"
+   depends on ACPI
+   select IIO_TRIGGERED_BUFFER
+   select IIO_KFIFO_BUF
+   help
+Say Y here if you want to build a driver for the ACPI0008
+Ambient Light Sensor.
+
+To compile this driver as a module, choose M here: the module will
+be called acpi-als.
+
 config ADJD_S311
tristate "ADJD-S311-CR999 digital color sensor"
select IIO_BUFFER
diff --git a/drivers/iio/light/Makefile b/drivers/iio/light/Makefile
index ad7c30f..d9aad52a 100644
--- a/drivers/iio/light/Makefile
+++ b/drivers/iio/light/Makefile
@@ -3,6 +3,7 @@
 #
 
 # When adding new entries keep the list in alphabetical order
+obj-$(CONFIG_ACPI_ALS) += acpi-als.o
 obj-$(CONFIG_ADJD_S311)+= adjd_s311.o
 obj-$(CONFIG_AL3320A)  += al3320a.o
 obj-$(CONFIG_APDS9300) += apds9300.o
diff --git a/drivers/iio/light/acpi-als.c b/drivers/iio/light/acpi-als.c
new file mode 100644
index 000..9839c9a
--- /dev/null
+++ b/drivers/iio/light/acpi-als.c
@@ -0,0 +1,232 @@
+/*
+ * ACPI Ambient Light Sensor Driver
+ *
+ * Based on ALS driver:
+ * Copyright (C) 2009 Zhang Rui 
+ *
+ * Rework for IIO subsystem:
+ * Copyright (C) 2012-2013 Martin Liska 
+ *
+ * Final cleanup and debugging:
+ * Copyright (C) 2013-2014 Marek Vasut 
+ * Copyright (C) 2015 Gabriele Mazzotta 
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; either version 2 of the License, or (at your
+ * option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+ */
+
+#include 
+#include 
+#include 
+#include 
+
+#include 
+#include 
+#include 
+
+#define ACPI_ALS_CLASS "als"
+#define ACPI_ALS_DEVICE_NAME   "acpi-als"
+#define ACPI_ALS_NOTIFY_ILLUMINANCE0x80
+
+ACPI_MODULE_NAME("acpi-als");
+
+/*
+ * So far, there's only one channel in here, but the specification for
+ * ACPI0008 says there can be more to what the block can report. Like
+ * chromaticity and such. We are ready for incoming additions!
+ */
+static const struct iio_chan_spec acpi_als_channels[] = {
+   {
+   .type   = IIO_LIGHT,
+   .scan_type  = {
+   .sign   = 's',
+   .realbits   = 32,
+   .storagebits= 32,
+   },
+   .info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
+   },
+};
+
+/*
+ * The event buffer contains timestamp and all the data from
+ * the ACPI0008 block. There are multiple, but so far we only
+ * support _ALI (illuminance). Once someone adds new channels
+ * to acpi_als_channels[], the evt_buffer below will grow
+ * automatically.
+ */
+#define EVT_NR_SOURCES ARRAY_SIZE(acpi_als_channels)
+#define EVT_BUFFER_SIZE\
+   (sizeof(s64) + (EVT_NR_SOURCES * sizeof(s32)))
+
+struct acpi_als {
+   struct acpi_device  *device;
+   struct mutexlock;
+
+   s32 evt_buffer[EVT_BUFFER_SIZE];
+};
+
+/*
+ * All types of properties the ACPI0008 block can report.