/*
* Copyright (C) 2013 Samsung Electronics Co., Ltd.
* Author: Jacek Anaszewski <j.anaszewski@samsung.com>
*
* IIO features supported by the driver:
*
* Read-only raw channels:
* - illuminance_clear [lux]
* - illuminance_ir
* - proximity
*
* Triggered buffer:
* - illuminance_clear
* - illuminance_ir
* - proximity
*
* Events:
* - illuminance_clear (rising and falling)
* - proximity (rising and falling)
* - both falling and rising thresholds for the proximity events
* must be set to the values greater than 0.
*
* The driver supports triggered buffers for all the three
* channels as well as high and low threshold events for the
* illuminance_clear and proxmimity channels. Triggers
* can be enabled simultaneously with both illuminance_clear
* events. Proximity events cannot be enabled simultaneously
* with any triggers or illuminance events. Enabling/disabling
* one of the proximity events automatically enables/disables
* the other one.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2, as
* published by the Free Software Foundation.
*/
#include <linux/debugfs.h>
#include <linux/delay.h>
#include <linux/i2c.h>
#include <linux/interrupt.h>
#include <linux/irq.h>
#include <linux/irq_work.h>
#include <linux/module.h>
#include <linux/mutex.h>
#include <linux/of.h>
#include <linux/regmap.h>
#include <linux/regulator/consumer.h>
#include <linux/slab.h>
#include <asm/unaligned.h>
#include <linux/iio/buffer.h>
#include <linux/iio/events.h>
#include <linux/iio/iio.h>
#include <linux/iio/sysfs.h>
#include <linux/iio/trigger.h>
#include <linux/iio/trigger_consumer.h>
#include <linux/iio/triggered_buffer.h>
#define GP2A_I2C_NAME "gp2ap020a00f"
/* Registers */
#define GP2AP020A00F_OP_REG 0x00 /* Basic operations */
#define GP2AP020A00F_ALS_REG 0x01 /* ALS related settings */
#define GP2AP020A00F_PS_REG 0x02 /* PS related settings */
#define GP2AP020A00F_LED_REG 0x03 /* LED reg */
#define GP2AP020A00F_TL_L_REG 0x04 /* ALS: Threshold low LSB */
#define GP2AP020A00F_TL_H_REG 0x05 /* ALS: Threshold low MSB */
#define GP2AP020A00F_TH_L_REG 0x06 /* ALS: Threshold high LSB */
#define GP2AP020A00F_TH_H_REG 0x07 /* ALS: Threshold high MSB */
#define GP2AP020A00F_PL_L_REG 0x08 /* PS: Threshold low LSB */
#define GP2AP020A00F_PL_H_REG 0x09 /* PS: Threshold low MSB */
#define GP2AP020A00F_PH_L_REG 0x0a /* PS: Threshold high LSB */
#define GP2AP020A00F_PH_H_REG 0x0b /* PS: Threshold high MSB */
#define GP2AP020A00F_D0_L_REG 0x0c /* ALS result: Clear/Illuminance LSB */
#define GP2AP020A00F_D0_H_REG 0x0d /* ALS result: Clear/Illuminance MSB */
#define GP