linux/drivers/iio/light/us5182d.c

// SPDX-License-Identifier: GPL-2.0-only
/*
 * Copyright (c) 2015 Intel Corporation
 *
 * Driver for UPISEMI us5182d Proximity and Ambient Light Sensor.
 *
 * To do: Interrupt support.
 */

#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/mod_devicetable.h>
#include <linux/delay.h>
#include <linux/i2c.h>
#include <linux/iio/events.h>
#include <linux/iio/iio.h>
#include <linux/interrupt.h>
#include <linux/irq.h>
#include <linux/iio/sysfs.h>
#include <linux/mutex.h>
#include <linux/pm.h>
#include <linux/pm_runtime.h>

#define US5182D_REG_CFG0
#define US5182D_CFG0_ONESHOT_EN
#define US5182D_CFG0_SHUTDOWN_EN
#define US5182D_CFG0_WORD_ENABLE
#define US5182D_CFG0_PROX
#define US5182D_CFG0_PX_IRQ

#define US5182D_REG_CFG1
#define US5182D_CFG1_ALS_RES16
#define US5182D_CFG1_AGAIN_DEFAULT

#define US5182D_REG_CFG2
#define US5182D_CFG2_PX_RES16
#define US5182D_CFG2_PXGAIN_DEFAULT

#define US5182D_REG_CFG3
#define US5182D_CFG3_LED_CURRENT100
#define US5182D_CFG3_INT_SOURCE_PX

#define US5182D_REG_CFG4

/*
 * Registers for tuning the auto dark current cancelling feature.
 * DARK_TH(reg 0x27,0x28) - threshold (counts) for auto dark cancelling.
 * when ALS  > DARK_TH --> ALS_Code = ALS - Upper(0x2A) * Dark
 * when ALS < DARK_TH --> ALS_Code = ALS - Lower(0x29) * Dark
 */
#define US5182D_REG_UDARK_TH
#define US5182D_REG_DARK_AUTO_EN
#define US5182D_REG_AUTO_LDARK_GAIN
#define US5182D_REG_AUTO_HDARK_GAIN

/* Thresholds for events: px low (0x08-l, 0x09-h), px high (0x0a-l 0x0b-h) */
#define US5182D_REG_PXL_TH
#define US5182D_REG_PXH_TH

#define US5182D_REG_PXL_TH_DEFAULT
#define US5182D_REG_PXH_TH_DEFAULT

#define US5182D_OPMODE_ALS
#define US5182D_OPMODE_PX
#define US5182D_OPMODE_SHIFT

#define US5182D_REG_DARK_AUTO_EN_DEFAULT
#define US5182D_REG_AUTO_LDARK_GAIN_DEFAULT
#define US5182D_REG_AUTO_HDARK_GAIN_DEFAULT

#define US5182D_REG_ADL
#define US5182D_REG_PDL

#define US5182D_REG_MODE_STORE
#define US5182D_STORE_MODE

#define US5182D_REG_CHIPID

#define US5182D_OPMODE_MASK
#define US5182D_AGAIN_MASK
#define US5182D_RESET_CHIP

#define US5182D_CHIPID
#define US5182D_DRV_NAME

#define US5182D_GA_RESOLUTION

#define US5182D_READ_BYTE
#define US5182D_READ_WORD
#define US5182D_OPSTORE_SLEEP_TIME
#define US5182D_SLEEP_MS
#define US5182D_PXH_TH_DISABLE
#define US5182D_PXL_TH_DISABLE

/* Available ranges: [12354, 7065, 3998, 2202, 1285, 498, 256, 138] lux */
static const int us5182d_scales[] =;

/*
 * Experimental thresholds that work with US5182D sensor on evaluation board
 * roughly between 12-32 lux
 */
static u16 us5182d_dark_ths_vals[] =;

enum mode {};

enum pmode {};

struct us5182d_data {};

static IIO_CONST_ATTR(in_illuminance_scale_available,
		      "0.0021 0.0039 0.0076 0.0196 0.0336 0.061 0.1078 0.1885");

static struct attribute *us5182d_attrs[] =;

static const struct attribute_group us5182d_attr_group =;

static const struct {} us5182d_regvals[] =;

static const struct iio_event_spec us5182d_events[] =;

static const struct iio_chan_spec us5182d_channels[] =;

static int us5182d_oneshot_en(struct us5182d_data *data)
{}

static int us5182d_set_opmode(struct us5182d_data *data, u8 mode)
{}

static int us5182d_als_enable(struct us5182d_data *data)
{}

static int us5182d_px_enable(struct us5182d_data *data)
{}

static int us5182d_get_als(struct us5182d_data *data)
{}

static int us5182d_get_px(struct us5182d_data *data)
{}

static int us5182d_shutdown_en(struct us5182d_data *data, u8 state)
{}


static int us5182d_set_power_state(struct us5182d_data *data, bool on)
{}

static int us5182d_read_value(struct us5182d_data *data,
			      struct iio_chan_spec const *chan)
{}

static int us5182d_read_raw(struct iio_dev *indio_dev,
			    struct iio_chan_spec const *chan, int *val,
			    int *val2, long mask)
{}

/**
 * us5182d_update_dark_th - update Darh_Th registers
 * @data:	us5182d_data structure
 * @index:	index in us5182d_dark_ths array to use for the updated value
 *
 * Function needs to be called with a lock held because it needs two i2c write
 * byte operations as these registers (0x27 0x28) don't work in word mode
 * accessing.
 */
static int us5182d_update_dark_th(struct us5182d_data *data, int index)
{}

/**
 * us5182d_apply_scale - update the ALS scale
 * @data:	us5182d_data structure
 * @index:	index in us5182d_scales array to use for the updated value
 *
 * Function needs to be called with a lock held as we're having more than one
 * i2c operation.
 */
static int us5182d_apply_scale(struct us5182d_data *data, int index)
{}

static int us5182d_write_raw(struct iio_dev *indio_dev,
			     struct iio_chan_spec const *chan, int val,
			     int val2, long mask)
{}

static int us5182d_setup_prox(struct iio_dev *indio_dev,
			      enum iio_event_direction dir, u16 val)
{}

static int us5182d_read_thresh(struct iio_dev *indio_dev,
	const struct iio_chan_spec *chan, enum iio_event_type type,
	enum iio_event_direction dir, enum iio_event_info info, int *val,
	int *val2)
{}

static int us5182d_write_thresh(struct iio_dev *indio_dev,
	const struct iio_chan_spec *chan, enum iio_event_type type,
	enum iio_event_direction dir, enum iio_event_info info, int val,
	int val2)
{}

static int us5182d_read_event_config(struct iio_dev *indio_dev,
	const struct iio_chan_spec *chan, enum iio_event_type type,
	enum iio_event_direction dir)
{}

static int us5182d_write_event_config(struct iio_dev *indio_dev,
	const struct iio_chan_spec *chan, enum iio_event_type type,
	enum iio_event_direction dir, int state)
{}

static const struct iio_info us5182d_info =;

static int us5182d_reset(struct iio_dev *indio_dev)
{}

static int us5182d_init(struct iio_dev *indio_dev)
{}

static void us5182d_get_platform_data(struct iio_dev *indio_dev)
{}

static int  us5182d_dark_gain_config(struct iio_dev *indio_dev)
{}

static irqreturn_t us5182d_irq_thread_handler(int irq, void *private)
{}

static int us5182d_probe(struct i2c_client *client)
{}

static void us5182d_remove(struct i2c_client *client)
{}

static int us5182d_suspend(struct device *dev)
{}

static int us5182d_resume(struct device *dev)
{}

static const struct dev_pm_ops us5182d_pm_ops =;

static const struct acpi_device_id us5182d_acpi_match[] =;

MODULE_DEVICE_TABLE(acpi, us5182d_acpi_match);

static const struct i2c_device_id us5182d_id[] =;

MODULE_DEVICE_TABLE(i2c, us5182d_id);

static const struct of_device_id us5182d_of_match[] =;
MODULE_DEVICE_TABLE(of, us5182d_of_match);

static struct i2c_driver us5182d_driver =;
module_i2c_driver();

MODULE_AUTHOR();
MODULE_DESCRIPTION();
MODULE_LICENSE();