Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Unverified Commit e91b5321 authored by derfelot's avatar derfelot
Browse files

misc: Add AMS TCS3490 sensor driver from Sony kernel

Taken from Sony 47.2.A.10.107 stock kernel
parent 0968cc98
Loading
Loading
Loading
Loading
+9 −0
Original line number Diff line number Diff line
@@ -666,6 +666,15 @@ config TOF_SENSOR
	  To compile this driver as a module, choose M here: the
	  module will be called tof_sensor.

config SENSORS_TCS3490
	tristate "AMS TCS3490 Sensor Driver"
	depends on I2C
	default n
	help
	  If you say yes here you get support for the AMS tcs3490,
	  ALS and color light sensors.
	  This driver can also be build as module.

config SIM_DETECT
	tristate "SIM_DETECT driver support"
	default n
+1 −0
Original line number Diff line number Diff line
@@ -73,6 +73,7 @@ obj-$(CONFIG_QPNP_MISC) += qpnp-misc.o
obj-$(CONFIG_MEMORY_STATE_TIME) += memory_state_time.o
obj-$(CONFIG_LDO_VIBRATOR) += ldo_vibrator.o
obj-$(CONFIG_TOF_SENSOR) += tof_sensor.o
obj-$(CONFIG_SENSORS_TCS3490) += tcs3490.o
obj-$(CONFIG_RAMDUMP_TAGS) += rdtags.o
obj-$(CONFIG_RAMDUMP_MEMDESC) += ramdump_mem_desc.o
obj-$(CONFIG_POWERKEY_FORCECRASH) += powerkey_forcecrash.o

drivers/misc/tcs3490.c

0 → 100644
+1654 −0

File added.

Preview size limit exceeded, changes collapsed.

drivers/misc/tcs3490.h

0 → 100644
+101 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2016 Sony Mobile Communications Inc.
 *
 * 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.
 */
/*
 * Device driver for monitoring ambient light intensity in (lux), RGB, and
 * color temperature (in kelvin) within the AMS-TAOS TCS family of devices.
 *
 * Copyright (c) 2016, AMS-TAOS USA, Inc.
 *
 * 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.,
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 */

#ifndef __TCS3490_H
#define __TCS3490_H

#include <linux/types.h>

/* Max number of segments allowable in LUX table */
#define TCS3490_MAX_LUX_TABLE_SIZE		9
#define MAX_DEFAULT_TABLE_BYTES (sizeof(int) * TCS3490_MAX_LUX_TABLE_SIZE)

/* Default LUX and Color coefficients */

#define D_Factor	304
#define R_Coef		205
#define G_Coef		1024
#define B_Coef		(-184)
#define CT_Coef		(4659)
#define CT_Offset	(1023)

#define D_Factor1	304
#define R_Coef1		205
#define G_Coef1		1024
#define B_Coef1		(-184)
#define CT_Coef1	(4659)
#define CT_Offset1	(1023)

struct device;

enum tcs3490_pwr_state {
	POWER_ON,
	POWER_OFF,
	POWER_STANDBY,
};

enum tcs3490_ctrl_reg {
	AGAIN_1        = (0 << 0),
	AGAIN_4        = (1 << 0),
	AGAIN_16       = (2 << 0),
	AGAIN_64       = (3 << 0),
};

#define ALS_PERSIST(p) (((p) & 0xf) << 3)

struct tcs3490_parameters {
	u8 als_time;
	u16 als_deltaP;
	u8 als_gain;
	u8 persist;
};

struct lux_segment {
	int d_factor;
	int r_coef;
	int g_coef;
	int b_coef;
	int ct_coef;
	int ct_offset;
};


struct tcs3490_i2c_platform_data {
	/* The following callback for power events received and handled by
	   the driver.  Currently only for SUSPEND and RESUME */
	int (*platform_power)(struct device *dev, enum tcs3490_pwr_state state);
	int (*platform_init)(void);
	void (*platform_teardown)(struct device *dev);
	char const *als_name;
	struct tcs3490_parameters parameters;
	bool als_can_wake;
	struct lux_segment *segment;
	int segment_num;
};

#endif /* __TCS3490_H */