linux/drivers/iio/light/max44000.c

// SPDX-License-Identifier: GPL-2.0-only
/*
 * MAX44000 Ambient and Infrared Proximity Sensor
 *
 * Copyright (c) 2016, Intel Corporation.
 *
 * Data sheet: https://datasheets.maximintegrated.com/en/ds/MAX44000.pdf
 *
 * 7-bit I2C slave address 0x4a
 */

#include <linux/module.h>
#include <linux/mod_devicetable.h>
#include <linux/init.h>
#include <linux/i2c.h>
#include <linux/regmap.h>
#include <linux/util_macros.h>
#include <linux/iio/iio.h>
#include <linux/iio/sysfs.h>
#include <linux/iio/buffer.h>
#include <linux/iio/trigger_consumer.h>
#include <linux/iio/triggered_buffer.h>

#define MAX44000_DRV_NAME

/* Registers in datasheet order */
#define MAX44000_REG_STATUS
#define MAX44000_REG_CFG_MAIN
#define MAX44000_REG_CFG_RX
#define MAX44000_REG_CFG_TX
#define MAX44000_REG_ALS_DATA_HI
#define MAX44000_REG_ALS_DATA_LO
#define MAX44000_REG_PRX_DATA
#define MAX44000_REG_ALS_UPTHR_HI
#define MAX44000_REG_ALS_UPTHR_LO
#define MAX44000_REG_ALS_LOTHR_HI
#define MAX44000_REG_ALS_LOTHR_LO
#define MAX44000_REG_PST
#define MAX44000_REG_PRX_IND
#define MAX44000_REG_PRX_THR
#define MAX44000_REG_TRIM_GAIN_GREEN
#define MAX44000_REG_TRIM_GAIN_IR

/* REG_CFG bits */
#define MAX44000_CFG_ALSINTE
#define MAX44000_CFG_PRXINTE
#define MAX44000_CFG_MASK
#define MAX44000_CFG_MODE_SHUTDOWN
#define MAX44000_CFG_MODE_ALS_GIR
#define MAX44000_CFG_MODE_ALS_G
#define MAX44000_CFG_MODE_ALS_IR
#define MAX44000_CFG_MODE_ALS_PRX
#define MAX44000_CFG_MODE_PRX
#define MAX44000_CFG_TRIM

/*
 * Upper 4 bits are not documented but start as 1 on powerup
 * Setting them to 0 causes proximity to misbehave so set them to 1
 */
#define MAX44000_REG_CFG_RX_DEFAULT

/* REG_RX bits */
#define MAX44000_CFG_RX_ALSTIM_MASK
#define MAX44000_CFG_RX_ALSTIM_SHIFT
#define MAX44000_CFG_RX_ALSPGA_MASK
#define MAX44000_CFG_RX_ALSPGA_SHIFT

/* REG_TX bits */
#define MAX44000_LED_CURRENT_MASK
#define MAX44000_LED_CURRENT_MAX
#define MAX44000_LED_CURRENT_DEFAULT

#define MAX44000_ALSDATA_OVERFLOW

struct max44000_data {};

/* Default scale is set to the minimum of 0.03125 or 1 / (1 << 5) lux */
#define MAX44000_ALS_TO_LUX_DEFAULT_FRACTION_LOG2

/* Scale can be multiplied by up to 128x via ALSPGA for measurement gain */
static const int max44000_alspga_shift[] =;
#define MAX44000_ALSPGA_MAX_SHIFT

/*
 * Scale can be multiplied by up to 64x via ALSTIM because of lost resolution
 *
 * This scaling factor is hidden from userspace and instead accounted for when
 * reading raw values from the device.
 *
 * This makes it possible to cleanly expose ALSPGA as IIO_CHAN_INFO_SCALE and
 * ALSTIM as IIO_CHAN_INFO_INT_TIME without the values affecting each other.
 *
 * Handling this internally is also required for buffer support because the
 * channel's scan_type can't be modified dynamically.
 */
#define MAX44000_ALSTIM_SHIFT(alstim)

/* Available integration times with pretty manual alignment: */
static const int max44000_int_time_avail_ns_array[] =;
static const char max44000_int_time_avail_str[] =;

/* Available scales (internal to ulux) with pretty manual alignment: */
static const int max44000_scale_avail_ulux_array[] =;
static const char max44000_scale_avail_str[] =;

#define MAX44000_SCAN_INDEX_ALS
#define MAX44000_SCAN_INDEX_PRX

static const struct iio_chan_spec max44000_channels[] =;

static int max44000_read_alstim(struct max44000_data *data)
{}

static int max44000_write_alstim(struct max44000_data *data, int val)
{}

static int max44000_read_alspga(struct max44000_data *data)
{}

static int max44000_write_alspga(struct max44000_data *data, int val)
{}

static int max44000_read_alsval(struct max44000_data *data)
{}

static int max44000_write_led_current_raw(struct max44000_data *data, int val)
{}

static int max44000_read_led_current_raw(struct max44000_data *data)
{}

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

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

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

static IIO_CONST_ATTR(illuminance_integration_time_available, max44000_int_time_avail_str);
static IIO_CONST_ATTR(illuminance_scale_available, max44000_scale_avail_str);

static struct attribute *max44000_attributes[] =;

static const struct attribute_group max44000_attribute_group =;

static const struct iio_info max44000_info =;

static bool max44000_readable_reg(struct device *dev, unsigned int reg)
{}

static bool max44000_writeable_reg(struct device *dev, unsigned int reg)
{}

static bool max44000_volatile_reg(struct device *dev, unsigned int reg)
{}

static bool max44000_precious_reg(struct device *dev, unsigned int reg)
{}

static const struct regmap_config max44000_regmap_config =;

static irqreturn_t max44000_trigger_handler(int irq, void *p)
{}

static int max44000_probe(struct i2c_client *client)
{}

static const struct i2c_device_id max44000_id[] =;
MODULE_DEVICE_TABLE(i2c, max44000_id);

static const struct acpi_device_id max44000_acpi_match[] =;
MODULE_DEVICE_TABLE(acpi, max44000_acpi_match);

static struct i2c_driver max44000_driver =;

module_i2c_driver();

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