18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0-only
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci * AFE4404 Heart Rate Monitors and Low-Cost Pulse Oximeters
48c2ecf20Sopenharmony_ci *
58c2ecf20Sopenharmony_ci * Copyright (C) 2015-2016 Texas Instruments Incorporated - https://www.ti.com/
68c2ecf20Sopenharmony_ci *	Andrew F. Davis <afd@ti.com>
78c2ecf20Sopenharmony_ci */
88c2ecf20Sopenharmony_ci
98c2ecf20Sopenharmony_ci#include <linux/device.h>
108c2ecf20Sopenharmony_ci#include <linux/err.h>
118c2ecf20Sopenharmony_ci#include <linux/interrupt.h>
128c2ecf20Sopenharmony_ci#include <linux/i2c.h>
138c2ecf20Sopenharmony_ci#include <linux/kernel.h>
148c2ecf20Sopenharmony_ci#include <linux/module.h>
158c2ecf20Sopenharmony_ci#include <linux/regmap.h>
168c2ecf20Sopenharmony_ci#include <linux/sysfs.h>
178c2ecf20Sopenharmony_ci#include <linux/regulator/consumer.h>
188c2ecf20Sopenharmony_ci
198c2ecf20Sopenharmony_ci#include <linux/iio/iio.h>
208c2ecf20Sopenharmony_ci#include <linux/iio/sysfs.h>
218c2ecf20Sopenharmony_ci#include <linux/iio/buffer.h>
228c2ecf20Sopenharmony_ci#include <linux/iio/trigger.h>
238c2ecf20Sopenharmony_ci#include <linux/iio/triggered_buffer.h>
248c2ecf20Sopenharmony_ci#include <linux/iio/trigger_consumer.h>
258c2ecf20Sopenharmony_ci
268c2ecf20Sopenharmony_ci#include "afe440x.h"
278c2ecf20Sopenharmony_ci
288c2ecf20Sopenharmony_ci#define AFE4404_DRIVER_NAME		"afe4404"
298c2ecf20Sopenharmony_ci
308c2ecf20Sopenharmony_ci/* AFE4404 registers */
318c2ecf20Sopenharmony_ci#define AFE4404_TIA_GAIN_SEP		0x20
328c2ecf20Sopenharmony_ci#define AFE4404_TIA_GAIN		0x21
338c2ecf20Sopenharmony_ci#define AFE4404_PROG_TG_STC		0x34
348c2ecf20Sopenharmony_ci#define AFE4404_PROG_TG_ENDC		0x35
358c2ecf20Sopenharmony_ci#define AFE4404_LED3LEDSTC		0x36
368c2ecf20Sopenharmony_ci#define AFE4404_LED3LEDENDC		0x37
378c2ecf20Sopenharmony_ci#define AFE4404_CLKDIV_PRF		0x39
388c2ecf20Sopenharmony_ci#define AFE4404_OFFDAC			0x3a
398c2ecf20Sopenharmony_ci#define AFE4404_DEC			0x3d
408c2ecf20Sopenharmony_ci#define AFE4404_AVG_LED2_ALED2VAL	0x3f
418c2ecf20Sopenharmony_ci#define AFE4404_AVG_LED1_ALED1VAL	0x40
428c2ecf20Sopenharmony_ci
438c2ecf20Sopenharmony_ci/* AFE4404 CONTROL2 register fields */
448c2ecf20Sopenharmony_ci#define AFE440X_CONTROL2_OSC_ENABLE	BIT(9)
458c2ecf20Sopenharmony_ci
468c2ecf20Sopenharmony_cienum afe4404_fields {
478c2ecf20Sopenharmony_ci	/* Gains */
488c2ecf20Sopenharmony_ci	F_TIA_GAIN_SEP, F_TIA_CF_SEP,
498c2ecf20Sopenharmony_ci	F_TIA_GAIN, TIA_CF,
508c2ecf20Sopenharmony_ci
518c2ecf20Sopenharmony_ci	/* LED Current */
528c2ecf20Sopenharmony_ci	F_ILED1, F_ILED2, F_ILED3,
538c2ecf20Sopenharmony_ci
548c2ecf20Sopenharmony_ci	/* Offset DAC */
558c2ecf20Sopenharmony_ci	F_OFFDAC_AMB2, F_OFFDAC_LED1, F_OFFDAC_AMB1, F_OFFDAC_LED2,
568c2ecf20Sopenharmony_ci
578c2ecf20Sopenharmony_ci	/* sentinel */
588c2ecf20Sopenharmony_ci	F_MAX_FIELDS
598c2ecf20Sopenharmony_ci};
608c2ecf20Sopenharmony_ci
618c2ecf20Sopenharmony_cistatic const struct reg_field afe4404_reg_fields[] = {
628c2ecf20Sopenharmony_ci	/* Gains */
638c2ecf20Sopenharmony_ci	[F_TIA_GAIN_SEP]	= REG_FIELD(AFE4404_TIA_GAIN_SEP, 0, 2),
648c2ecf20Sopenharmony_ci	[F_TIA_CF_SEP]		= REG_FIELD(AFE4404_TIA_GAIN_SEP, 3, 5),
658c2ecf20Sopenharmony_ci	[F_TIA_GAIN]		= REG_FIELD(AFE4404_TIA_GAIN, 0, 2),
668c2ecf20Sopenharmony_ci	[TIA_CF]		= REG_FIELD(AFE4404_TIA_GAIN, 3, 5),
678c2ecf20Sopenharmony_ci	/* LED Current */
688c2ecf20Sopenharmony_ci	[F_ILED1]		= REG_FIELD(AFE440X_LEDCNTRL, 0, 5),
698c2ecf20Sopenharmony_ci	[F_ILED2]		= REG_FIELD(AFE440X_LEDCNTRL, 6, 11),
708c2ecf20Sopenharmony_ci	[F_ILED3]		= REG_FIELD(AFE440X_LEDCNTRL, 12, 17),
718c2ecf20Sopenharmony_ci	/* Offset DAC */
728c2ecf20Sopenharmony_ci	[F_OFFDAC_AMB2]		= REG_FIELD(AFE4404_OFFDAC, 0, 4),
738c2ecf20Sopenharmony_ci	[F_OFFDAC_LED1]		= REG_FIELD(AFE4404_OFFDAC, 5, 9),
748c2ecf20Sopenharmony_ci	[F_OFFDAC_AMB1]		= REG_FIELD(AFE4404_OFFDAC, 10, 14),
758c2ecf20Sopenharmony_ci	[F_OFFDAC_LED2]		= REG_FIELD(AFE4404_OFFDAC, 15, 19),
768c2ecf20Sopenharmony_ci};
778c2ecf20Sopenharmony_ci
788c2ecf20Sopenharmony_ci/**
798c2ecf20Sopenharmony_ci * struct afe4404_data - AFE4404 device instance data
808c2ecf20Sopenharmony_ci * @dev: Device structure
818c2ecf20Sopenharmony_ci * @regmap: Register map of the device
828c2ecf20Sopenharmony_ci * @fields: Register fields of the device
838c2ecf20Sopenharmony_ci * @regulator: Pointer to the regulator for the IC
848c2ecf20Sopenharmony_ci * @trig: IIO trigger for this device
858c2ecf20Sopenharmony_ci * @irq: ADC_RDY line interrupt number
868c2ecf20Sopenharmony_ci * @buffer: Used to construct a scan to push to the iio buffer.
878c2ecf20Sopenharmony_ci */
888c2ecf20Sopenharmony_cistruct afe4404_data {
898c2ecf20Sopenharmony_ci	struct device *dev;
908c2ecf20Sopenharmony_ci	struct regmap *regmap;
918c2ecf20Sopenharmony_ci	struct regmap_field *fields[F_MAX_FIELDS];
928c2ecf20Sopenharmony_ci	struct regulator *regulator;
938c2ecf20Sopenharmony_ci	struct iio_trigger *trig;
948c2ecf20Sopenharmony_ci	int irq;
958c2ecf20Sopenharmony_ci	s32 buffer[10] __aligned(8);
968c2ecf20Sopenharmony_ci};
978c2ecf20Sopenharmony_ci
988c2ecf20Sopenharmony_cienum afe4404_chan_id {
998c2ecf20Sopenharmony_ci	LED2 = 1,
1008c2ecf20Sopenharmony_ci	ALED2,
1018c2ecf20Sopenharmony_ci	LED1,
1028c2ecf20Sopenharmony_ci	ALED1,
1038c2ecf20Sopenharmony_ci	LED2_ALED2,
1048c2ecf20Sopenharmony_ci	LED1_ALED1,
1058c2ecf20Sopenharmony_ci};
1068c2ecf20Sopenharmony_ci
1078c2ecf20Sopenharmony_cistatic const unsigned int afe4404_channel_values[] = {
1088c2ecf20Sopenharmony_ci	[LED2] = AFE440X_LED2VAL,
1098c2ecf20Sopenharmony_ci	[ALED2] = AFE440X_ALED2VAL,
1108c2ecf20Sopenharmony_ci	[LED1] = AFE440X_LED1VAL,
1118c2ecf20Sopenharmony_ci	[ALED1] = AFE440X_ALED1VAL,
1128c2ecf20Sopenharmony_ci	[LED2_ALED2] = AFE440X_LED2_ALED2VAL,
1138c2ecf20Sopenharmony_ci	[LED1_ALED1] = AFE440X_LED1_ALED1VAL,
1148c2ecf20Sopenharmony_ci};
1158c2ecf20Sopenharmony_ci
1168c2ecf20Sopenharmony_cistatic const unsigned int afe4404_channel_leds[] = {
1178c2ecf20Sopenharmony_ci	[LED2] = F_ILED2,
1188c2ecf20Sopenharmony_ci	[ALED2] = F_ILED3,
1198c2ecf20Sopenharmony_ci	[LED1] = F_ILED1,
1208c2ecf20Sopenharmony_ci};
1218c2ecf20Sopenharmony_ci
1228c2ecf20Sopenharmony_cistatic const unsigned int afe4404_channel_offdacs[] = {
1238c2ecf20Sopenharmony_ci	[LED2] = F_OFFDAC_LED2,
1248c2ecf20Sopenharmony_ci	[ALED2] = F_OFFDAC_AMB2,
1258c2ecf20Sopenharmony_ci	[LED1] = F_OFFDAC_LED1,
1268c2ecf20Sopenharmony_ci	[ALED1] = F_OFFDAC_AMB1,
1278c2ecf20Sopenharmony_ci};
1288c2ecf20Sopenharmony_ci
1298c2ecf20Sopenharmony_cistatic const struct iio_chan_spec afe4404_channels[] = {
1308c2ecf20Sopenharmony_ci	/* ADC values */
1318c2ecf20Sopenharmony_ci	AFE440X_INTENSITY_CHAN(LED2, BIT(IIO_CHAN_INFO_OFFSET)),
1328c2ecf20Sopenharmony_ci	AFE440X_INTENSITY_CHAN(ALED2, BIT(IIO_CHAN_INFO_OFFSET)),
1338c2ecf20Sopenharmony_ci	AFE440X_INTENSITY_CHAN(LED1, BIT(IIO_CHAN_INFO_OFFSET)),
1348c2ecf20Sopenharmony_ci	AFE440X_INTENSITY_CHAN(ALED1, BIT(IIO_CHAN_INFO_OFFSET)),
1358c2ecf20Sopenharmony_ci	AFE440X_INTENSITY_CHAN(LED2_ALED2, 0),
1368c2ecf20Sopenharmony_ci	AFE440X_INTENSITY_CHAN(LED1_ALED1, 0),
1378c2ecf20Sopenharmony_ci	/* LED current */
1388c2ecf20Sopenharmony_ci	AFE440X_CURRENT_CHAN(LED2),
1398c2ecf20Sopenharmony_ci	AFE440X_CURRENT_CHAN(ALED2),
1408c2ecf20Sopenharmony_ci	AFE440X_CURRENT_CHAN(LED1),
1418c2ecf20Sopenharmony_ci};
1428c2ecf20Sopenharmony_ci
1438c2ecf20Sopenharmony_cistatic const struct afe440x_val_table afe4404_res_table[] = {
1448c2ecf20Sopenharmony_ci	{ .integer = 500000, .fract = 0 },
1458c2ecf20Sopenharmony_ci	{ .integer = 250000, .fract = 0 },
1468c2ecf20Sopenharmony_ci	{ .integer = 100000, .fract = 0 },
1478c2ecf20Sopenharmony_ci	{ .integer = 50000, .fract = 0 },
1488c2ecf20Sopenharmony_ci	{ .integer = 25000, .fract = 0 },
1498c2ecf20Sopenharmony_ci	{ .integer = 10000, .fract = 0 },
1508c2ecf20Sopenharmony_ci	{ .integer = 1000000, .fract = 0 },
1518c2ecf20Sopenharmony_ci	{ .integer = 2000000, .fract = 0 },
1528c2ecf20Sopenharmony_ci};
1538c2ecf20Sopenharmony_ciAFE440X_TABLE_ATTR(in_intensity_resistance_available, afe4404_res_table);
1548c2ecf20Sopenharmony_ci
1558c2ecf20Sopenharmony_cistatic const struct afe440x_val_table afe4404_cap_table[] = {
1568c2ecf20Sopenharmony_ci	{ .integer = 0, .fract = 5000 },
1578c2ecf20Sopenharmony_ci	{ .integer = 0, .fract = 2500 },
1588c2ecf20Sopenharmony_ci	{ .integer = 0, .fract = 10000 },
1598c2ecf20Sopenharmony_ci	{ .integer = 0, .fract = 7500 },
1608c2ecf20Sopenharmony_ci	{ .integer = 0, .fract = 20000 },
1618c2ecf20Sopenharmony_ci	{ .integer = 0, .fract = 17500 },
1628c2ecf20Sopenharmony_ci	{ .integer = 0, .fract = 25000 },
1638c2ecf20Sopenharmony_ci	{ .integer = 0, .fract = 22500 },
1648c2ecf20Sopenharmony_ci};
1658c2ecf20Sopenharmony_ciAFE440X_TABLE_ATTR(in_intensity_capacitance_available, afe4404_cap_table);
1668c2ecf20Sopenharmony_ci
1678c2ecf20Sopenharmony_cistatic ssize_t afe440x_show_register(struct device *dev,
1688c2ecf20Sopenharmony_ci				     struct device_attribute *attr,
1698c2ecf20Sopenharmony_ci				     char *buf)
1708c2ecf20Sopenharmony_ci{
1718c2ecf20Sopenharmony_ci	struct iio_dev *indio_dev = dev_to_iio_dev(dev);
1728c2ecf20Sopenharmony_ci	struct afe4404_data *afe = iio_priv(indio_dev);
1738c2ecf20Sopenharmony_ci	struct afe440x_attr *afe440x_attr = to_afe440x_attr(attr);
1748c2ecf20Sopenharmony_ci	unsigned int reg_val;
1758c2ecf20Sopenharmony_ci	int vals[2];
1768c2ecf20Sopenharmony_ci	int ret;
1778c2ecf20Sopenharmony_ci
1788c2ecf20Sopenharmony_ci	ret = regmap_field_read(afe->fields[afe440x_attr->field], &reg_val);
1798c2ecf20Sopenharmony_ci	if (ret)
1808c2ecf20Sopenharmony_ci		return ret;
1818c2ecf20Sopenharmony_ci
1828c2ecf20Sopenharmony_ci	if (reg_val >= afe440x_attr->table_size)
1838c2ecf20Sopenharmony_ci		return -EINVAL;
1848c2ecf20Sopenharmony_ci
1858c2ecf20Sopenharmony_ci	vals[0] = afe440x_attr->val_table[reg_val].integer;
1868c2ecf20Sopenharmony_ci	vals[1] = afe440x_attr->val_table[reg_val].fract;
1878c2ecf20Sopenharmony_ci
1888c2ecf20Sopenharmony_ci	return iio_format_value(buf, IIO_VAL_INT_PLUS_MICRO, 2, vals);
1898c2ecf20Sopenharmony_ci}
1908c2ecf20Sopenharmony_ci
1918c2ecf20Sopenharmony_cistatic ssize_t afe440x_store_register(struct device *dev,
1928c2ecf20Sopenharmony_ci				      struct device_attribute *attr,
1938c2ecf20Sopenharmony_ci				      const char *buf, size_t count)
1948c2ecf20Sopenharmony_ci{
1958c2ecf20Sopenharmony_ci	struct iio_dev *indio_dev = dev_to_iio_dev(dev);
1968c2ecf20Sopenharmony_ci	struct afe4404_data *afe = iio_priv(indio_dev);
1978c2ecf20Sopenharmony_ci	struct afe440x_attr *afe440x_attr = to_afe440x_attr(attr);
1988c2ecf20Sopenharmony_ci	int val, integer, fract, ret;
1998c2ecf20Sopenharmony_ci
2008c2ecf20Sopenharmony_ci	ret = iio_str_to_fixpoint(buf, 100000, &integer, &fract);
2018c2ecf20Sopenharmony_ci	if (ret)
2028c2ecf20Sopenharmony_ci		return ret;
2038c2ecf20Sopenharmony_ci
2048c2ecf20Sopenharmony_ci	for (val = 0; val < afe440x_attr->table_size; val++)
2058c2ecf20Sopenharmony_ci		if (afe440x_attr->val_table[val].integer == integer &&
2068c2ecf20Sopenharmony_ci		    afe440x_attr->val_table[val].fract == fract)
2078c2ecf20Sopenharmony_ci			break;
2088c2ecf20Sopenharmony_ci	if (val == afe440x_attr->table_size)
2098c2ecf20Sopenharmony_ci		return -EINVAL;
2108c2ecf20Sopenharmony_ci
2118c2ecf20Sopenharmony_ci	ret = regmap_field_write(afe->fields[afe440x_attr->field], val);
2128c2ecf20Sopenharmony_ci	if (ret)
2138c2ecf20Sopenharmony_ci		return ret;
2148c2ecf20Sopenharmony_ci
2158c2ecf20Sopenharmony_ci	return count;
2168c2ecf20Sopenharmony_ci}
2178c2ecf20Sopenharmony_ci
2188c2ecf20Sopenharmony_cistatic AFE440X_ATTR(in_intensity1_resistance, F_TIA_GAIN_SEP, afe4404_res_table);
2198c2ecf20Sopenharmony_cistatic AFE440X_ATTR(in_intensity1_capacitance, F_TIA_CF_SEP, afe4404_cap_table);
2208c2ecf20Sopenharmony_ci
2218c2ecf20Sopenharmony_cistatic AFE440X_ATTR(in_intensity2_resistance, F_TIA_GAIN_SEP, afe4404_res_table);
2228c2ecf20Sopenharmony_cistatic AFE440X_ATTR(in_intensity2_capacitance, F_TIA_CF_SEP, afe4404_cap_table);
2238c2ecf20Sopenharmony_ci
2248c2ecf20Sopenharmony_cistatic AFE440X_ATTR(in_intensity3_resistance, F_TIA_GAIN, afe4404_res_table);
2258c2ecf20Sopenharmony_cistatic AFE440X_ATTR(in_intensity3_capacitance, TIA_CF, afe4404_cap_table);
2268c2ecf20Sopenharmony_ci
2278c2ecf20Sopenharmony_cistatic AFE440X_ATTR(in_intensity4_resistance, F_TIA_GAIN, afe4404_res_table);
2288c2ecf20Sopenharmony_cistatic AFE440X_ATTR(in_intensity4_capacitance, TIA_CF, afe4404_cap_table);
2298c2ecf20Sopenharmony_ci
2308c2ecf20Sopenharmony_cistatic struct attribute *afe440x_attributes[] = {
2318c2ecf20Sopenharmony_ci	&dev_attr_in_intensity_resistance_available.attr,
2328c2ecf20Sopenharmony_ci	&dev_attr_in_intensity_capacitance_available.attr,
2338c2ecf20Sopenharmony_ci	&afe440x_attr_in_intensity1_resistance.dev_attr.attr,
2348c2ecf20Sopenharmony_ci	&afe440x_attr_in_intensity1_capacitance.dev_attr.attr,
2358c2ecf20Sopenharmony_ci	&afe440x_attr_in_intensity2_resistance.dev_attr.attr,
2368c2ecf20Sopenharmony_ci	&afe440x_attr_in_intensity2_capacitance.dev_attr.attr,
2378c2ecf20Sopenharmony_ci	&afe440x_attr_in_intensity3_resistance.dev_attr.attr,
2388c2ecf20Sopenharmony_ci	&afe440x_attr_in_intensity3_capacitance.dev_attr.attr,
2398c2ecf20Sopenharmony_ci	&afe440x_attr_in_intensity4_resistance.dev_attr.attr,
2408c2ecf20Sopenharmony_ci	&afe440x_attr_in_intensity4_capacitance.dev_attr.attr,
2418c2ecf20Sopenharmony_ci	NULL
2428c2ecf20Sopenharmony_ci};
2438c2ecf20Sopenharmony_ci
2448c2ecf20Sopenharmony_cistatic const struct attribute_group afe440x_attribute_group = {
2458c2ecf20Sopenharmony_ci	.attrs = afe440x_attributes
2468c2ecf20Sopenharmony_ci};
2478c2ecf20Sopenharmony_ci
2488c2ecf20Sopenharmony_cistatic int afe4404_read_raw(struct iio_dev *indio_dev,
2498c2ecf20Sopenharmony_ci			    struct iio_chan_spec const *chan,
2508c2ecf20Sopenharmony_ci			    int *val, int *val2, long mask)
2518c2ecf20Sopenharmony_ci{
2528c2ecf20Sopenharmony_ci	struct afe4404_data *afe = iio_priv(indio_dev);
2538c2ecf20Sopenharmony_ci	unsigned int value_reg, led_field, offdac_field;
2548c2ecf20Sopenharmony_ci	int ret;
2558c2ecf20Sopenharmony_ci
2568c2ecf20Sopenharmony_ci	switch (chan->type) {
2578c2ecf20Sopenharmony_ci	case IIO_INTENSITY:
2588c2ecf20Sopenharmony_ci		switch (mask) {
2598c2ecf20Sopenharmony_ci		case IIO_CHAN_INFO_RAW:
2608c2ecf20Sopenharmony_ci			value_reg = afe4404_channel_values[chan->address];
2618c2ecf20Sopenharmony_ci			ret = regmap_read(afe->regmap, value_reg, val);
2628c2ecf20Sopenharmony_ci			if (ret)
2638c2ecf20Sopenharmony_ci				return ret;
2648c2ecf20Sopenharmony_ci			return IIO_VAL_INT;
2658c2ecf20Sopenharmony_ci		case IIO_CHAN_INFO_OFFSET:
2668c2ecf20Sopenharmony_ci			offdac_field = afe4404_channel_offdacs[chan->address];
2678c2ecf20Sopenharmony_ci			ret = regmap_field_read(afe->fields[offdac_field], val);
2688c2ecf20Sopenharmony_ci			if (ret)
2698c2ecf20Sopenharmony_ci				return ret;
2708c2ecf20Sopenharmony_ci			return IIO_VAL_INT;
2718c2ecf20Sopenharmony_ci		}
2728c2ecf20Sopenharmony_ci		break;
2738c2ecf20Sopenharmony_ci	case IIO_CURRENT:
2748c2ecf20Sopenharmony_ci		switch (mask) {
2758c2ecf20Sopenharmony_ci		case IIO_CHAN_INFO_RAW:
2768c2ecf20Sopenharmony_ci			led_field = afe4404_channel_leds[chan->address];
2778c2ecf20Sopenharmony_ci			ret = regmap_field_read(afe->fields[led_field], val);
2788c2ecf20Sopenharmony_ci			if (ret)
2798c2ecf20Sopenharmony_ci				return ret;
2808c2ecf20Sopenharmony_ci			return IIO_VAL_INT;
2818c2ecf20Sopenharmony_ci		case IIO_CHAN_INFO_SCALE:
2828c2ecf20Sopenharmony_ci			*val = 0;
2838c2ecf20Sopenharmony_ci			*val2 = 800000;
2848c2ecf20Sopenharmony_ci			return IIO_VAL_INT_PLUS_MICRO;
2858c2ecf20Sopenharmony_ci		}
2868c2ecf20Sopenharmony_ci		break;
2878c2ecf20Sopenharmony_ci	default:
2888c2ecf20Sopenharmony_ci		break;
2898c2ecf20Sopenharmony_ci	}
2908c2ecf20Sopenharmony_ci
2918c2ecf20Sopenharmony_ci	return -EINVAL;
2928c2ecf20Sopenharmony_ci}
2938c2ecf20Sopenharmony_ci
2948c2ecf20Sopenharmony_cistatic int afe4404_write_raw(struct iio_dev *indio_dev,
2958c2ecf20Sopenharmony_ci			     struct iio_chan_spec const *chan,
2968c2ecf20Sopenharmony_ci			     int val, int val2, long mask)
2978c2ecf20Sopenharmony_ci{
2988c2ecf20Sopenharmony_ci	struct afe4404_data *afe = iio_priv(indio_dev);
2998c2ecf20Sopenharmony_ci	unsigned int led_field, offdac_field;
3008c2ecf20Sopenharmony_ci
3018c2ecf20Sopenharmony_ci	switch (chan->type) {
3028c2ecf20Sopenharmony_ci	case IIO_INTENSITY:
3038c2ecf20Sopenharmony_ci		switch (mask) {
3048c2ecf20Sopenharmony_ci		case IIO_CHAN_INFO_OFFSET:
3058c2ecf20Sopenharmony_ci			offdac_field = afe4404_channel_offdacs[chan->address];
3068c2ecf20Sopenharmony_ci			return regmap_field_write(afe->fields[offdac_field], val);
3078c2ecf20Sopenharmony_ci		}
3088c2ecf20Sopenharmony_ci		break;
3098c2ecf20Sopenharmony_ci	case IIO_CURRENT:
3108c2ecf20Sopenharmony_ci		switch (mask) {
3118c2ecf20Sopenharmony_ci		case IIO_CHAN_INFO_RAW:
3128c2ecf20Sopenharmony_ci			led_field = afe4404_channel_leds[chan->address];
3138c2ecf20Sopenharmony_ci			return regmap_field_write(afe->fields[led_field], val);
3148c2ecf20Sopenharmony_ci		}
3158c2ecf20Sopenharmony_ci		break;
3168c2ecf20Sopenharmony_ci	default:
3178c2ecf20Sopenharmony_ci		break;
3188c2ecf20Sopenharmony_ci	}
3198c2ecf20Sopenharmony_ci
3208c2ecf20Sopenharmony_ci	return -EINVAL;
3218c2ecf20Sopenharmony_ci}
3228c2ecf20Sopenharmony_ci
3238c2ecf20Sopenharmony_cistatic const struct iio_info afe4404_iio_info = {
3248c2ecf20Sopenharmony_ci	.attrs = &afe440x_attribute_group,
3258c2ecf20Sopenharmony_ci	.read_raw = afe4404_read_raw,
3268c2ecf20Sopenharmony_ci	.write_raw = afe4404_write_raw,
3278c2ecf20Sopenharmony_ci};
3288c2ecf20Sopenharmony_ci
3298c2ecf20Sopenharmony_cistatic irqreturn_t afe4404_trigger_handler(int irq, void *private)
3308c2ecf20Sopenharmony_ci{
3318c2ecf20Sopenharmony_ci	struct iio_poll_func *pf = private;
3328c2ecf20Sopenharmony_ci	struct iio_dev *indio_dev = pf->indio_dev;
3338c2ecf20Sopenharmony_ci	struct afe4404_data *afe = iio_priv(indio_dev);
3348c2ecf20Sopenharmony_ci	int ret, bit, i = 0;
3358c2ecf20Sopenharmony_ci
3368c2ecf20Sopenharmony_ci	for_each_set_bit(bit, indio_dev->active_scan_mask,
3378c2ecf20Sopenharmony_ci			 indio_dev->masklength) {
3388c2ecf20Sopenharmony_ci		ret = regmap_read(afe->regmap, afe4404_channel_values[bit],
3398c2ecf20Sopenharmony_ci				  &afe->buffer[i++]);
3408c2ecf20Sopenharmony_ci		if (ret)
3418c2ecf20Sopenharmony_ci			goto err;
3428c2ecf20Sopenharmony_ci	}
3438c2ecf20Sopenharmony_ci
3448c2ecf20Sopenharmony_ci	iio_push_to_buffers_with_timestamp(indio_dev, afe->buffer,
3458c2ecf20Sopenharmony_ci					   pf->timestamp);
3468c2ecf20Sopenharmony_cierr:
3478c2ecf20Sopenharmony_ci	iio_trigger_notify_done(indio_dev->trig);
3488c2ecf20Sopenharmony_ci
3498c2ecf20Sopenharmony_ci	return IRQ_HANDLED;
3508c2ecf20Sopenharmony_ci}
3518c2ecf20Sopenharmony_ci
3528c2ecf20Sopenharmony_cistatic const struct iio_trigger_ops afe4404_trigger_ops = {
3538c2ecf20Sopenharmony_ci};
3548c2ecf20Sopenharmony_ci
3558c2ecf20Sopenharmony_ci/* Default timings from data-sheet */
3568c2ecf20Sopenharmony_ci#define AFE4404_TIMING_PAIRS			\
3578c2ecf20Sopenharmony_ci	{ AFE440X_PRPCOUNT,	39999	},	\
3588c2ecf20Sopenharmony_ci	{ AFE440X_LED2LEDSTC,	0	},	\
3598c2ecf20Sopenharmony_ci	{ AFE440X_LED2LEDENDC,	398	},	\
3608c2ecf20Sopenharmony_ci	{ AFE440X_LED2STC,	80	},	\
3618c2ecf20Sopenharmony_ci	{ AFE440X_LED2ENDC,	398	},	\
3628c2ecf20Sopenharmony_ci	{ AFE440X_ADCRSTSTCT0,	5600	},	\
3638c2ecf20Sopenharmony_ci	{ AFE440X_ADCRSTENDCT0,	5606	},	\
3648c2ecf20Sopenharmony_ci	{ AFE440X_LED2CONVST,	5607	},	\
3658c2ecf20Sopenharmony_ci	{ AFE440X_LED2CONVEND,	6066	},	\
3668c2ecf20Sopenharmony_ci	{ AFE4404_LED3LEDSTC,	400	},	\
3678c2ecf20Sopenharmony_ci	{ AFE4404_LED3LEDENDC,	798	},	\
3688c2ecf20Sopenharmony_ci	{ AFE440X_ALED2STC,	480	},	\
3698c2ecf20Sopenharmony_ci	{ AFE440X_ALED2ENDC,	798	},	\
3708c2ecf20Sopenharmony_ci	{ AFE440X_ADCRSTSTCT1,	6068	},	\
3718c2ecf20Sopenharmony_ci	{ AFE440X_ADCRSTENDCT1,	6074	},	\
3728c2ecf20Sopenharmony_ci	{ AFE440X_ALED2CONVST,	6075	},	\
3738c2ecf20Sopenharmony_ci	{ AFE440X_ALED2CONVEND,	6534	},	\
3748c2ecf20Sopenharmony_ci	{ AFE440X_LED1LEDSTC,	800	},	\
3758c2ecf20Sopenharmony_ci	{ AFE440X_LED1LEDENDC,	1198	},	\
3768c2ecf20Sopenharmony_ci	{ AFE440X_LED1STC,	880	},	\
3778c2ecf20Sopenharmony_ci	{ AFE440X_LED1ENDC,	1198	},	\
3788c2ecf20Sopenharmony_ci	{ AFE440X_ADCRSTSTCT2,	6536	},	\
3798c2ecf20Sopenharmony_ci	{ AFE440X_ADCRSTENDCT2,	6542	},	\
3808c2ecf20Sopenharmony_ci	{ AFE440X_LED1CONVST,	6543	},	\
3818c2ecf20Sopenharmony_ci	{ AFE440X_LED1CONVEND,	7003	},	\
3828c2ecf20Sopenharmony_ci	{ AFE440X_ALED1STC,	1280	},	\
3838c2ecf20Sopenharmony_ci	{ AFE440X_ALED1ENDC,	1598	},	\
3848c2ecf20Sopenharmony_ci	{ AFE440X_ADCRSTSTCT3,	7005	},	\
3858c2ecf20Sopenharmony_ci	{ AFE440X_ADCRSTENDCT3,	7011	},	\
3868c2ecf20Sopenharmony_ci	{ AFE440X_ALED1CONVST,	7012	},	\
3878c2ecf20Sopenharmony_ci	{ AFE440X_ALED1CONVEND,	7471	},	\
3888c2ecf20Sopenharmony_ci	{ AFE440X_PDNCYCLESTC,	7671	},	\
3898c2ecf20Sopenharmony_ci	{ AFE440X_PDNCYCLEENDC,	39199	}
3908c2ecf20Sopenharmony_ci
3918c2ecf20Sopenharmony_cistatic const struct reg_sequence afe4404_reg_sequences[] = {
3928c2ecf20Sopenharmony_ci	AFE4404_TIMING_PAIRS,
3938c2ecf20Sopenharmony_ci	{ AFE440X_CONTROL1, AFE440X_CONTROL1_TIMEREN },
3948c2ecf20Sopenharmony_ci	{ AFE4404_TIA_GAIN_SEP, AFE440X_TIAGAIN_ENSEPGAIN },
3958c2ecf20Sopenharmony_ci	{ AFE440X_CONTROL2, AFE440X_CONTROL2_OSC_ENABLE	},
3968c2ecf20Sopenharmony_ci};
3978c2ecf20Sopenharmony_ci
3988c2ecf20Sopenharmony_cistatic const struct regmap_range afe4404_yes_ranges[] = {
3998c2ecf20Sopenharmony_ci	regmap_reg_range(AFE440X_LED2VAL, AFE440X_LED1_ALED1VAL),
4008c2ecf20Sopenharmony_ci	regmap_reg_range(AFE4404_AVG_LED2_ALED2VAL, AFE4404_AVG_LED1_ALED1VAL),
4018c2ecf20Sopenharmony_ci};
4028c2ecf20Sopenharmony_ci
4038c2ecf20Sopenharmony_cistatic const struct regmap_access_table afe4404_volatile_table = {
4048c2ecf20Sopenharmony_ci	.yes_ranges = afe4404_yes_ranges,
4058c2ecf20Sopenharmony_ci	.n_yes_ranges = ARRAY_SIZE(afe4404_yes_ranges),
4068c2ecf20Sopenharmony_ci};
4078c2ecf20Sopenharmony_ci
4088c2ecf20Sopenharmony_cistatic const struct regmap_config afe4404_regmap_config = {
4098c2ecf20Sopenharmony_ci	.reg_bits = 8,
4108c2ecf20Sopenharmony_ci	.val_bits = 24,
4118c2ecf20Sopenharmony_ci
4128c2ecf20Sopenharmony_ci	.max_register = AFE4404_AVG_LED1_ALED1VAL,
4138c2ecf20Sopenharmony_ci	.cache_type = REGCACHE_RBTREE,
4148c2ecf20Sopenharmony_ci	.volatile_table = &afe4404_volatile_table,
4158c2ecf20Sopenharmony_ci};
4168c2ecf20Sopenharmony_ci
4178c2ecf20Sopenharmony_cistatic const struct of_device_id afe4404_of_match[] = {
4188c2ecf20Sopenharmony_ci	{ .compatible = "ti,afe4404", },
4198c2ecf20Sopenharmony_ci	{ /* sentinel */ }
4208c2ecf20Sopenharmony_ci};
4218c2ecf20Sopenharmony_ciMODULE_DEVICE_TABLE(of, afe4404_of_match);
4228c2ecf20Sopenharmony_ci
4238c2ecf20Sopenharmony_cistatic int __maybe_unused afe4404_suspend(struct device *dev)
4248c2ecf20Sopenharmony_ci{
4258c2ecf20Sopenharmony_ci	struct iio_dev *indio_dev = i2c_get_clientdata(to_i2c_client(dev));
4268c2ecf20Sopenharmony_ci	struct afe4404_data *afe = iio_priv(indio_dev);
4278c2ecf20Sopenharmony_ci	int ret;
4288c2ecf20Sopenharmony_ci
4298c2ecf20Sopenharmony_ci	ret = regmap_update_bits(afe->regmap, AFE440X_CONTROL2,
4308c2ecf20Sopenharmony_ci				 AFE440X_CONTROL2_PDN_AFE,
4318c2ecf20Sopenharmony_ci				 AFE440X_CONTROL2_PDN_AFE);
4328c2ecf20Sopenharmony_ci	if (ret)
4338c2ecf20Sopenharmony_ci		return ret;
4348c2ecf20Sopenharmony_ci
4358c2ecf20Sopenharmony_ci	ret = regulator_disable(afe->regulator);
4368c2ecf20Sopenharmony_ci	if (ret) {
4378c2ecf20Sopenharmony_ci		dev_err(dev, "Unable to disable regulator\n");
4388c2ecf20Sopenharmony_ci		return ret;
4398c2ecf20Sopenharmony_ci	}
4408c2ecf20Sopenharmony_ci
4418c2ecf20Sopenharmony_ci	return 0;
4428c2ecf20Sopenharmony_ci}
4438c2ecf20Sopenharmony_ci
4448c2ecf20Sopenharmony_cistatic int __maybe_unused afe4404_resume(struct device *dev)
4458c2ecf20Sopenharmony_ci{
4468c2ecf20Sopenharmony_ci	struct iio_dev *indio_dev = i2c_get_clientdata(to_i2c_client(dev));
4478c2ecf20Sopenharmony_ci	struct afe4404_data *afe = iio_priv(indio_dev);
4488c2ecf20Sopenharmony_ci	int ret;
4498c2ecf20Sopenharmony_ci
4508c2ecf20Sopenharmony_ci	ret = regulator_enable(afe->regulator);
4518c2ecf20Sopenharmony_ci	if (ret) {
4528c2ecf20Sopenharmony_ci		dev_err(dev, "Unable to enable regulator\n");
4538c2ecf20Sopenharmony_ci		return ret;
4548c2ecf20Sopenharmony_ci	}
4558c2ecf20Sopenharmony_ci
4568c2ecf20Sopenharmony_ci	ret = regmap_update_bits(afe->regmap, AFE440X_CONTROL2,
4578c2ecf20Sopenharmony_ci				 AFE440X_CONTROL2_PDN_AFE, 0);
4588c2ecf20Sopenharmony_ci	if (ret)
4598c2ecf20Sopenharmony_ci		return ret;
4608c2ecf20Sopenharmony_ci
4618c2ecf20Sopenharmony_ci	return 0;
4628c2ecf20Sopenharmony_ci}
4638c2ecf20Sopenharmony_ci
4648c2ecf20Sopenharmony_cistatic SIMPLE_DEV_PM_OPS(afe4404_pm_ops, afe4404_suspend, afe4404_resume);
4658c2ecf20Sopenharmony_ci
4668c2ecf20Sopenharmony_cistatic int afe4404_probe(struct i2c_client *client,
4678c2ecf20Sopenharmony_ci			 const struct i2c_device_id *id)
4688c2ecf20Sopenharmony_ci{
4698c2ecf20Sopenharmony_ci	struct iio_dev *indio_dev;
4708c2ecf20Sopenharmony_ci	struct afe4404_data *afe;
4718c2ecf20Sopenharmony_ci	int i, ret;
4728c2ecf20Sopenharmony_ci
4738c2ecf20Sopenharmony_ci	indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*afe));
4748c2ecf20Sopenharmony_ci	if (!indio_dev)
4758c2ecf20Sopenharmony_ci		return -ENOMEM;
4768c2ecf20Sopenharmony_ci
4778c2ecf20Sopenharmony_ci	afe = iio_priv(indio_dev);
4788c2ecf20Sopenharmony_ci	i2c_set_clientdata(client, indio_dev);
4798c2ecf20Sopenharmony_ci
4808c2ecf20Sopenharmony_ci	afe->dev = &client->dev;
4818c2ecf20Sopenharmony_ci	afe->irq = client->irq;
4828c2ecf20Sopenharmony_ci
4838c2ecf20Sopenharmony_ci	afe->regmap = devm_regmap_init_i2c(client, &afe4404_regmap_config);
4848c2ecf20Sopenharmony_ci	if (IS_ERR(afe->regmap)) {
4858c2ecf20Sopenharmony_ci		dev_err(afe->dev, "Unable to allocate register map\n");
4868c2ecf20Sopenharmony_ci		return PTR_ERR(afe->regmap);
4878c2ecf20Sopenharmony_ci	}
4888c2ecf20Sopenharmony_ci
4898c2ecf20Sopenharmony_ci	for (i = 0; i < F_MAX_FIELDS; i++) {
4908c2ecf20Sopenharmony_ci		afe->fields[i] = devm_regmap_field_alloc(afe->dev, afe->regmap,
4918c2ecf20Sopenharmony_ci							 afe4404_reg_fields[i]);
4928c2ecf20Sopenharmony_ci		if (IS_ERR(afe->fields[i])) {
4938c2ecf20Sopenharmony_ci			dev_err(afe->dev, "Unable to allocate regmap fields\n");
4948c2ecf20Sopenharmony_ci			return PTR_ERR(afe->fields[i]);
4958c2ecf20Sopenharmony_ci		}
4968c2ecf20Sopenharmony_ci	}
4978c2ecf20Sopenharmony_ci
4988c2ecf20Sopenharmony_ci	afe->regulator = devm_regulator_get(afe->dev, "tx_sup");
4998c2ecf20Sopenharmony_ci	if (IS_ERR(afe->regulator)) {
5008c2ecf20Sopenharmony_ci		dev_err(afe->dev, "Unable to get regulator\n");
5018c2ecf20Sopenharmony_ci		return PTR_ERR(afe->regulator);
5028c2ecf20Sopenharmony_ci	}
5038c2ecf20Sopenharmony_ci	ret = regulator_enable(afe->regulator);
5048c2ecf20Sopenharmony_ci	if (ret) {
5058c2ecf20Sopenharmony_ci		dev_err(afe->dev, "Unable to enable regulator\n");
5068c2ecf20Sopenharmony_ci		return ret;
5078c2ecf20Sopenharmony_ci	}
5088c2ecf20Sopenharmony_ci
5098c2ecf20Sopenharmony_ci	ret = regmap_write(afe->regmap, AFE440X_CONTROL0,
5108c2ecf20Sopenharmony_ci			   AFE440X_CONTROL0_SW_RESET);
5118c2ecf20Sopenharmony_ci	if (ret) {
5128c2ecf20Sopenharmony_ci		dev_err(afe->dev, "Unable to reset device\n");
5138c2ecf20Sopenharmony_ci		goto disable_reg;
5148c2ecf20Sopenharmony_ci	}
5158c2ecf20Sopenharmony_ci
5168c2ecf20Sopenharmony_ci	ret = regmap_multi_reg_write(afe->regmap, afe4404_reg_sequences,
5178c2ecf20Sopenharmony_ci				     ARRAY_SIZE(afe4404_reg_sequences));
5188c2ecf20Sopenharmony_ci	if (ret) {
5198c2ecf20Sopenharmony_ci		dev_err(afe->dev, "Unable to set register defaults\n");
5208c2ecf20Sopenharmony_ci		goto disable_reg;
5218c2ecf20Sopenharmony_ci	}
5228c2ecf20Sopenharmony_ci
5238c2ecf20Sopenharmony_ci	indio_dev->modes = INDIO_DIRECT_MODE;
5248c2ecf20Sopenharmony_ci	indio_dev->channels = afe4404_channels;
5258c2ecf20Sopenharmony_ci	indio_dev->num_channels = ARRAY_SIZE(afe4404_channels);
5268c2ecf20Sopenharmony_ci	indio_dev->name = AFE4404_DRIVER_NAME;
5278c2ecf20Sopenharmony_ci	indio_dev->info = &afe4404_iio_info;
5288c2ecf20Sopenharmony_ci
5298c2ecf20Sopenharmony_ci	if (afe->irq > 0) {
5308c2ecf20Sopenharmony_ci		afe->trig = devm_iio_trigger_alloc(afe->dev,
5318c2ecf20Sopenharmony_ci						   "%s-dev%d",
5328c2ecf20Sopenharmony_ci						   indio_dev->name,
5338c2ecf20Sopenharmony_ci						   indio_dev->id);
5348c2ecf20Sopenharmony_ci		if (!afe->trig) {
5358c2ecf20Sopenharmony_ci			dev_err(afe->dev, "Unable to allocate IIO trigger\n");
5368c2ecf20Sopenharmony_ci			ret = -ENOMEM;
5378c2ecf20Sopenharmony_ci			goto disable_reg;
5388c2ecf20Sopenharmony_ci		}
5398c2ecf20Sopenharmony_ci
5408c2ecf20Sopenharmony_ci		iio_trigger_set_drvdata(afe->trig, indio_dev);
5418c2ecf20Sopenharmony_ci
5428c2ecf20Sopenharmony_ci		afe->trig->ops = &afe4404_trigger_ops;
5438c2ecf20Sopenharmony_ci		afe->trig->dev.parent = afe->dev;
5448c2ecf20Sopenharmony_ci
5458c2ecf20Sopenharmony_ci		ret = iio_trigger_register(afe->trig);
5468c2ecf20Sopenharmony_ci		if (ret) {
5478c2ecf20Sopenharmony_ci			dev_err(afe->dev, "Unable to register IIO trigger\n");
5488c2ecf20Sopenharmony_ci			goto disable_reg;
5498c2ecf20Sopenharmony_ci		}
5508c2ecf20Sopenharmony_ci
5518c2ecf20Sopenharmony_ci		ret = devm_request_threaded_irq(afe->dev, afe->irq,
5528c2ecf20Sopenharmony_ci						iio_trigger_generic_data_rdy_poll,
5538c2ecf20Sopenharmony_ci						NULL, IRQF_ONESHOT,
5548c2ecf20Sopenharmony_ci						AFE4404_DRIVER_NAME,
5558c2ecf20Sopenharmony_ci						afe->trig);
5568c2ecf20Sopenharmony_ci		if (ret) {
5578c2ecf20Sopenharmony_ci			dev_err(afe->dev, "Unable to request IRQ\n");
5588c2ecf20Sopenharmony_ci			goto disable_reg;
5598c2ecf20Sopenharmony_ci		}
5608c2ecf20Sopenharmony_ci	}
5618c2ecf20Sopenharmony_ci
5628c2ecf20Sopenharmony_ci	ret = iio_triggered_buffer_setup(indio_dev, &iio_pollfunc_store_time,
5638c2ecf20Sopenharmony_ci					 afe4404_trigger_handler, NULL);
5648c2ecf20Sopenharmony_ci	if (ret) {
5658c2ecf20Sopenharmony_ci		dev_err(afe->dev, "Unable to setup buffer\n");
5668c2ecf20Sopenharmony_ci		goto unregister_trigger;
5678c2ecf20Sopenharmony_ci	}
5688c2ecf20Sopenharmony_ci
5698c2ecf20Sopenharmony_ci	ret = iio_device_register(indio_dev);
5708c2ecf20Sopenharmony_ci	if (ret) {
5718c2ecf20Sopenharmony_ci		dev_err(afe->dev, "Unable to register IIO device\n");
5728c2ecf20Sopenharmony_ci		goto unregister_triggered_buffer;
5738c2ecf20Sopenharmony_ci	}
5748c2ecf20Sopenharmony_ci
5758c2ecf20Sopenharmony_ci	return 0;
5768c2ecf20Sopenharmony_ci
5778c2ecf20Sopenharmony_ciunregister_triggered_buffer:
5788c2ecf20Sopenharmony_ci	iio_triggered_buffer_cleanup(indio_dev);
5798c2ecf20Sopenharmony_ciunregister_trigger:
5808c2ecf20Sopenharmony_ci	if (afe->irq > 0)
5818c2ecf20Sopenharmony_ci		iio_trigger_unregister(afe->trig);
5828c2ecf20Sopenharmony_cidisable_reg:
5838c2ecf20Sopenharmony_ci	regulator_disable(afe->regulator);
5848c2ecf20Sopenharmony_ci
5858c2ecf20Sopenharmony_ci	return ret;
5868c2ecf20Sopenharmony_ci}
5878c2ecf20Sopenharmony_ci
5888c2ecf20Sopenharmony_cistatic int afe4404_remove(struct i2c_client *client)
5898c2ecf20Sopenharmony_ci{
5908c2ecf20Sopenharmony_ci	struct iio_dev *indio_dev = i2c_get_clientdata(client);
5918c2ecf20Sopenharmony_ci	struct afe4404_data *afe = iio_priv(indio_dev);
5928c2ecf20Sopenharmony_ci	int ret;
5938c2ecf20Sopenharmony_ci
5948c2ecf20Sopenharmony_ci	iio_device_unregister(indio_dev);
5958c2ecf20Sopenharmony_ci
5968c2ecf20Sopenharmony_ci	iio_triggered_buffer_cleanup(indio_dev);
5978c2ecf20Sopenharmony_ci
5988c2ecf20Sopenharmony_ci	if (afe->irq > 0)
5998c2ecf20Sopenharmony_ci		iio_trigger_unregister(afe->trig);
6008c2ecf20Sopenharmony_ci
6018c2ecf20Sopenharmony_ci	ret = regulator_disable(afe->regulator);
6028c2ecf20Sopenharmony_ci	if (ret) {
6038c2ecf20Sopenharmony_ci		dev_err(afe->dev, "Unable to disable regulator\n");
6048c2ecf20Sopenharmony_ci		return ret;
6058c2ecf20Sopenharmony_ci	}
6068c2ecf20Sopenharmony_ci
6078c2ecf20Sopenharmony_ci	return 0;
6088c2ecf20Sopenharmony_ci}
6098c2ecf20Sopenharmony_ci
6108c2ecf20Sopenharmony_cistatic const struct i2c_device_id afe4404_ids[] = {
6118c2ecf20Sopenharmony_ci	{ "afe4404", 0 },
6128c2ecf20Sopenharmony_ci	{ /* sentinel */ }
6138c2ecf20Sopenharmony_ci};
6148c2ecf20Sopenharmony_ciMODULE_DEVICE_TABLE(i2c, afe4404_ids);
6158c2ecf20Sopenharmony_ci
6168c2ecf20Sopenharmony_cistatic struct i2c_driver afe4404_i2c_driver = {
6178c2ecf20Sopenharmony_ci	.driver = {
6188c2ecf20Sopenharmony_ci		.name = AFE4404_DRIVER_NAME,
6198c2ecf20Sopenharmony_ci		.of_match_table = afe4404_of_match,
6208c2ecf20Sopenharmony_ci		.pm = &afe4404_pm_ops,
6218c2ecf20Sopenharmony_ci	},
6228c2ecf20Sopenharmony_ci	.probe = afe4404_probe,
6238c2ecf20Sopenharmony_ci	.remove = afe4404_remove,
6248c2ecf20Sopenharmony_ci	.id_table = afe4404_ids,
6258c2ecf20Sopenharmony_ci};
6268c2ecf20Sopenharmony_cimodule_i2c_driver(afe4404_i2c_driver);
6278c2ecf20Sopenharmony_ci
6288c2ecf20Sopenharmony_ciMODULE_AUTHOR("Andrew F. Davis <afd@ti.com>");
6298c2ecf20Sopenharmony_ciMODULE_DESCRIPTION("TI AFE4404 Heart Rate Monitor and Pulse Oximeter AFE");
6308c2ecf20Sopenharmony_ciMODULE_LICENSE("GPL v2");
631