// SPDX-License-Identifier: GPL-2.0-only
/*
 * Sensortek STK8BA50 3-Axis Accelerometer
 *
 * Copyright (c) 2015, Intel Corporation.
 *
 * STK8BA50 7-bit I2C address: 0x18.
 */

#include <linux/i2c.h>
#include <linux/interrupt.h>
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/mod_devicetable.h>
#include <linux/iio/buffer.h>
#include <linux/iio/iio.h>
#include <linux/iio/sysfs.h>
#include <linux/iio/trigger.h>
#include <linux/iio/triggered_buffer.h>
#include <linux/iio/trigger_consumer.h>

#define STK8BA50_REG_XOUT			0x02
#define STK8BA50_REG_YOUT			0x04
#define STK8BA50_REG_ZOUT			0x06
#define STK8BA50_REG_RANGE			0x0F
#define STK8BA50_REG_BWSEL			0x10
#define STK8BA50_REG_POWMODE			0x11
#define STK8BA50_REG_SWRST			0x14
#define STK8BA50_REG_INTEN2			0x17
#define STK8BA50_REG_INTMAP2			0x1A

#define STK8BA50_MODE_NORMAL			0
#define STK8BA50_MODE_SUSPEND			1
#define STK8BA50_MODE_POWERBIT			BIT(7)
#define STK8BA50_DATA_SHIFT			6
#define STK8BA50_RESET_CMD			0xB6
#define STK8BA50_SR_1792HZ_IDX			7
#define STK8BA50_DREADY_INT_MASK		0x10
#define STK8BA50_DREADY_INT_MAP			0x81
#define STK8BA50_ALL_CHANNEL_MASK		7
#define STK8BA50_ALL_CHANNEL_SIZE		6

#define STK8BA50_DRIVER_NAME			"stk8ba50"
#define STK8BA50_IRQ_NAME			"stk8ba50_event"

#define STK8BA50_SCALE_AVAIL			"0.0384 0.0767 0.1534 0.3069"

/*
 * The accelerometer has four measurement ranges:
 * +/-2g; +/-4g; +/-8g; +/-16g
 *
 * Acceleration values are 10-bit, 2's complement.
 * Scales are calculated as following:
 *
 * scale1 = (2 + 2) * 9.81 / (2^10 - 1)   = 0.0384
 * scale2 = (4 + 4) * 9.81 / (2^10 - 1)   = 0.0767
 * etc.
 *
 * Scales are stored in this format:
 * { <register value>, <scale value> }
 *
 * Locally, the range is stored as a table index.
 */
static const struct {
	u8 reg_val;
	u32 scale_val;
} stk8ba50_scale_table[] = {
	{3, 38400}, {5, 76700}, {8, 153400}, {12, 306900}
};

/* Sample rates are stored as { <register value>, <Hz value> } */
static const struct {
	u8 reg_val;
	u16 samp_freq;
} stk8ba50_samp_freq_table[] = {
	{0x08, 14},  {0x09, 25},  {0x0A, 56},  {0x0B, 112},
	{0x0C, 224}, {0x0D, 448}, {0x0E, 896}, {0x0F, 1792}
};

/* Used to map scan mask bits to their corresponding channel register. */
static const int stk8ba50_channel_table[] = {
	STK8BA50_REG_XOUT,
	STK8BA50_REG_YOUT,
	STK8BA50_REG_ZOUT
};

struct stk8ba50_data {
	struct i2c_client *client;
	struct mutex lock;
	int range;
	u8 sample_rate_idx;
	struct iio_trigger *dready_trig;
	bool dready_trigger_on;
	/* Ensure timestamp is naturally aligned */
	struct {
		s16 chans[3];
		s64 timetamp __aligned(8);
	} scan;
};

#define STK8BA50_ACCEL_CHANNEL(index, reg, axis) {			\
	.type = IIO_ACCEL,						\
	.address = reg,							\
	.modified = 1,							\
	.channel2 = IIO_MOD_##axis,					\
	.info_mask_separate = BIT(IIO_CHAN_INFO_RAW),			\
	.info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE),		\
				    BIT(IIO_CHAN_INFO_SAMP_FREQ),	\
	.scan_index = index,						\
	.scan_type = {							\
		.sign = 's',						\
		.realbits = 10,						\
		.storagebits = 16,					\
		.shift = STK8BA50_DATA_SHIFT,				\
		.endianness = IIO_CPU,					\
	},								\
}

static const struct iio_chan_spec stk8ba50_channels[] = {
	STK8BA50_ACCEL_CHANNEL(0, STK8BA50_REG_XOUT, X),
	STK8BA50_ACCEL_CHANNEL(1, STK8BA50_REG_YOUT, Y),
	STK8BA50_ACCEL_CHANNEL(2, STK8BA50_REG_ZOUT, Z),
	IIO_CHAN_SOFT_TIMESTAMP(3),
};

static IIO_CONST_ATTR(in_accel_scale_available, STK8BA50_SCALE_AVAIL);

static IIO_CONST_ATTR_SAMP_FREQ_AVAIL("14 25 56 112 224 448 896 1792");

static struct attribute *stk8ba50_attributes[] = {
	&iio_const_attr_in_accel_scale_available.dev_attr.attr,
	&iio_const_attr_sampling_frequency_available.dev_attr.attr,
	NULL,
};

static const struct attribute_group stk8ba50_attribute_group = {
	.attrs = stk8ba50_attributes
};

static int stk8ba50_read_accel(struct stk8ba50_data *data, u8 reg)
{
	int ret;
	struct i2c_client *client = data->client;

	ret = i2c_smbus_read_word_data(client, reg);
	if (ret < 0) {
		dev_err(&client->dev, "register read failed\n");
		return ret;
	}

	return ret;
}

static int stk8ba50_data_rdy_trigger_set_state(struct iio_trigger *trig,
					       bool state)
{
	struct iio_dev *indio_dev = iio_trigger_get_drvdata(trig);
	struct stk8ba50_data *data = iio_priv(indio_dev);
	int ret;

	if (state)
		ret = i2c_smbus_write_byte_data(data->client,
			STK8BA50_REG_INTEN2, STK8BA50_DREADY_INT_MASK);
	else
		ret = i2c_smbus_write_byte_data(data->client,
			STK8BA50_REG_INTEN2, 0x00);

	if (ret < 0)
		dev_err(&data->client->dev, "failed to set trigger state\n");
	else
		data->dready_trigger_on = state;

	return ret;
}

static const struct iio_trigger_ops stk8ba50_trigger_ops = {
	.set_trigger_state = stk8ba50_data_rdy_trigger_set_state,
};

static int stk8ba50_set_power(struct stk8ba50_data *data, bool mode)
{
	int ret;
	u8 masked_reg;
	struct i2c_client *client = data->client;

	ret = i2c_smbus_read_byte_data(client, STK8BA50_REG_POWMODE);
	if (ret < 0)
		goto exit_err;

	if (mode)
		masked_reg = ret | STK8BA50_MODE_POWERBIT;
	else
		masked_reg = ret & (~STK8BA50_MODE_POWERBIT);

	ret = i2c_smbus_write_byte_data(client, STK8BA50_REG_POWMODE,
					masked_reg);
	if (ret < 0)
		goto exit_err;

	return ret;

exit_err:
	dev_err(&client->dev, "failed to change sensor mode\n");
	return ret;
}

static int stk8ba50_read_raw(struct iio_dev *indio_dev,
			     struct iio_chan_spec const *chan,
			     int *val, int *val2, long mask)
{
	struct stk8ba50_data *data = iio_priv(indio_dev);
	int ret;

	switch (mask) {
	case IIO_CHAN_INFO_RAW:
		if (iio_buffer_enabled(indio_dev))
			return -EBUSY;
		mutex_lock(&data->lock);
		ret = stk8ba50_set_power(data, STK8BA50_MODE_NORMAL);
		if (ret < 0) {
			mutex_unlock(&data->lock);
			return -EINVAL;
		}
		ret = stk8ba50_read_accel(data, chan->address);
		if (ret < 0) {
			stk8ba50_set_power(data, STK8BA50_MODE_SUSPEND);
			mutex_unlock(&data->lock);
			return -EINVAL;
		}
		*val = sign_extend32(ret >> chan->scan_type.shift,
				     chan->scan_type.realbits - 1);
		stk8ba50_set_power(data, STK8BA50_MODE_SUSPEND);
		mutex_unlock(&data->lock);
		return IIO_VAL_INT;
	case IIO_CHAN_INFO_SCALE:
		*val = 0;
		*val2 = stk8ba50_scale_table[data->range].scale_val;
		return IIO_VAL_INT_PLUS_MICRO;
	case IIO_CHAN_INFO_SAMP_FREQ:
		*val = stk8ba50_samp_freq_table
				[data->sample_rate_idx].samp_freq;
		*val2 = 0;
		return IIO_VAL_INT;
	}

	return -EINVAL;
}

static int stk8ba50_write_raw(struct iio_dev *indio_dev,
			      struct iio_chan_spec const *chan,
			      int val, int val2, long mask)
{
	int ret;
	int i;
	int index = -1;
	struct stk8ba50_data *data = iio_priv(indio_dev);

	switch (mask) {
	case IIO_CHAN_INFO_SCALE:
		if (val != 0)
			return -EINVAL;

		for (i = 0; i < ARRAY_SIZE(stk8ba50_scale_table); i++)
			if (val2 == stk8ba50_scale_table[i].scale_val) {
				index = i;
				break;
			}
		if (index < 0)
			return -EINVAL;

		ret = i2c_smbus_write_byte_data(data->client,
				STK8BA50_REG_RANGE,
				stk8ba50_scale_table[index].reg_val);
		if (ret < 0)
			dev_err(&data->client->dev,
					"failed to set measurement range\n");
		else
			data->range = index;

		return ret;
	case IIO_CHAN_INFO_SAMP_FREQ:
		for (i = 0; i < ARRAY_SIZE(stk8ba50_samp_freq_table); i++)
			if (val == stk8ba50_samp_freq_table[i].samp_freq) {
				index = i;
				break;
			}
		if (index < 0)
			return -EINVAL;

		ret = i2c_smbus_write_byte_data(data->client,
				STK8BA50_REG_BWSEL,
				stk8ba50_samp_freq_table[index].reg_val);
		if (ret < 0)
			dev_err(&data->client->dev,
					"failed to set sampling rate\n");
		else
			data->sample_rate_idx = index;

		return ret;
	}

	return -EINVAL;
}

static const struct iio_info stk8ba50_info = {
	.read_raw		= stk8ba50_read_raw,
	.write_raw		= stk8ba50_write_raw,
	.attrs			= &stk8ba50_attribute_group,
};

static irqreturn_t stk8ba50_trigger_handler(int irq, void *p)
{
	struct iio_poll_func *pf = p;
	struct iio_dev *indio_dev = pf->indio_dev;
	struct stk8ba50_data *data = iio_priv(indio_dev);
	int bit, ret, i = 0;

	mutex_lock(&data->lock);
	/*
	 * Do a bulk read if all channels are requested,
	 * from 0x02 (XOUT1) to 0x07 (ZOUT2)
	 */
	if (*(indio_dev->active_scan_mask) == STK8BA50_ALL_CHANNEL_MASK) {
		ret = i2c_smbus_read_i2c_block_data(data->client,
						    STK8BA50_REG_XOUT,
						    STK8BA50_ALL_CHANNEL_SIZE,
						    (u8 *)data->scan.chans);
		if (ret < STK8BA50_ALL_CHANNEL_SIZE) {
			dev_err(&data->client->dev, "register read failed\n");
			goto err;
		}
	} else {
		iio_for_each_active_channel(indio_dev, bit) {
			ret = stk8ba50_read_accel(data,
						  stk8ba50_channel_table[bit]);
			if (ret < 0)
				goto err;

			data->scan.chans[i++] = ret;
		}
	}
	iio_push_to_buffers_with_timestamp(indio_dev, &data->scan,
					   pf->timestamp);
err:
	mutex_unlock(&data->lock);
	iio_trigger_notify_done(indio_dev->trig);

	return IRQ_HANDLED;
}

static irqreturn_t stk8ba50_data_rdy_trig_poll(int irq, void *private)
{
	struct iio_dev *indio_dev = private;
	struct stk8ba50_data *data = iio_priv(indio_dev);

	if (data->dready_trigger_on)
		iio_trigger_poll(data->dready_trig);

	return IRQ_HANDLED;
}

static int stk8ba50_buffer_preenable(struct iio_dev *indio_dev)
{
	struct stk8ba50_data *data = iio_priv(indio_dev);

	return stk8ba50_set_power(data, STK8BA50_MODE_NORMAL);
}

static int stk8ba50_buffer_postdisable(struct iio_dev *indio_dev)
{
	struct stk8ba50_data *data = iio_priv(indio_dev);

	return stk8ba50_set_power(data, STK8BA50_MODE_SUSPEND);
}

static const struct iio_buffer_setup_ops stk8ba50_buffer_setup_ops = {
	.preenable   = stk8ba50_buffer_preenable,
	.postdisable = stk8ba50_buffer_postdisable,
};

static int stk8ba50_probe(struct i2c_client *client)
{
	int ret;
	struct iio_dev *indio_dev;
	struct stk8ba50_data *data;

	indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*data));
	if (!indio_dev) {
		dev_err(&client->dev, "iio allocation failed!\n");
		return -ENOMEM;
	}

	data = iio_priv(indio_dev);
	data->client = client;
	i2c_set_clientdata(client, indio_dev);
	mutex_init(&data->lock);

	indio_dev->info = &stk8ba50_info;
	indio_dev->name = STK8BA50_DRIVER_NAME;
	indio_dev->modes = INDIO_DIRECT_MODE;
	indio_dev->channels = stk8ba50_channels;
	indio_dev->num_channels = ARRAY_SIZE(stk8ba50_channels);

	/* Reset all registers on startup */
	ret = i2c_smbus_write_byte_data(client,
			STK8BA50_REG_SWRST, STK8BA50_RESET_CMD);
	if (ret < 0) {
		dev_err(&client->dev, "failed to reset sensor\n");
		goto err_power_off;
	}

	/* The default range is +/-2g */
	data->range = 0;

	/* The default sampling rate is 1792 Hz (maximum) */
	data->sample_rate_idx = STK8BA50_SR_1792HZ_IDX;

	/* Set up interrupts */
	ret = i2c_smbus_write_byte_data(client,
			STK8BA50_REG_INTEN2, STK8BA50_DREADY_INT_MASK);
	if (ret < 0) {
		dev_err(&client->dev, "failed to set up interrupts\n");
		goto err_power_off;
	}
	ret = i2c_smbus_write_byte_data(client,
			STK8BA50_REG_INTMAP2, STK8BA50_DREADY_INT_MAP);
	if (ret < 0) {
		dev_err(&client->dev, "failed to set up interrupts\n");
		goto err_power_off;
	}

	if (client->irq > 0) {
		ret = devm_request_threaded_irq(&client->dev, client->irq,
						stk8ba50_data_rdy_trig_poll,
						NULL,
						IRQF_TRIGGER_RISING |
						IRQF_ONESHOT,
						STK8BA50_IRQ_NAME,
						indio_dev);
		if (ret < 0) {
			dev_err(&client->dev, "request irq %d failed\n",
				client->irq);
			goto err_power_off;
		}

		data->dready_trig = devm_iio_trigger_alloc(&client->dev,
							   "%s-dev%d",
							   indio_dev->name,
							   iio_device_id(indio_dev));
		if (!data->dready_trig) {
			ret = -ENOMEM;
			goto err_power_off;
		}

		data->dready_trig->ops = &stk8ba50_trigger_ops;
		iio_trigger_set_drvdata(data->dready_trig, indio_dev);
		ret = iio_trigger_register(data->dready_trig);
		if (ret) {
			dev_err(&client->dev, "iio trigger register failed\n");
			goto err_power_off;
		}
	}

	ret = iio_triggered_buffer_setup(indio_dev,
					 iio_pollfunc_store_time,
					 stk8ba50_trigger_handler,
					 &stk8ba50_buffer_setup_ops);
	if (ret < 0) {
		dev_err(&client->dev, "iio triggered buffer setup failed\n");
		goto err_trigger_unregister;
	}

	ret = iio_device_register(indio_dev);
	if (ret < 0) {
		dev_err(&client->dev, "device_register failed\n");
		goto err_buffer_cleanup;
	}

	return ret;

err_buffer_cleanup:
	iio_triggered_buffer_cleanup(indio_dev);
err_trigger_unregister:
	if (data->dready_trig)
		iio_trigger_unregister(data->dready_trig);
err_power_off:
	stk8ba50_set_power(data, STK8BA50_MODE_SUSPEND);
	return ret;
}

static void stk8ba50_remove(struct i2c_client *client)
{
	struct iio_dev *indio_dev = i2c_get_clientdata(client);
	struct stk8ba50_data *data = iio_priv(indio_dev);

	iio_device_unregister(indio_dev);
	iio_triggered_buffer_cleanup(indio_dev);

	if (data->dready_trig)
		iio_trigger_unregister(data->dready_trig);

	stk8ba50_set_power(data, STK8BA50_MODE_SUSPEND);
}

static int stk8ba50_suspend(struct device *dev)
{
	struct stk8ba50_data *data;

	data = iio_priv(i2c_get_clientdata(to_i2c_client(dev)));

	return stk8ba50_set_power(data, STK8BA50_MODE_SUSPEND);
}

static int stk8ba50_resume(struct device *dev)
{
	struct stk8ba50_data *data;

	data = iio_priv(i2c_get_clientdata(to_i2c_client(dev)));

	return stk8ba50_set_power(data, STK8BA50_MODE_NORMAL);
}

static DEFINE_SIMPLE_DEV_PM_OPS(stk8ba50_pm_ops, stk8ba50_suspend,
				stk8ba50_resume);

static const struct i2c_device_id stk8ba50_i2c_id[] = {
	{ "stk8ba50" },
	{}
};
MODULE_DEVICE_TABLE(i2c, stk8ba50_i2c_id);

static const struct acpi_device_id stk8ba50_acpi_id[] = {
	{"STK8BA50", 0},
	{}
};

MODULE_DEVICE_TABLE(acpi, stk8ba50_acpi_id);

static struct i2c_driver stk8ba50_driver = {
	.driver = {
		.name = "stk8ba50",
		.pm = pm_sleep_ptr(&stk8ba50_pm_ops),
		.acpi_match_table = stk8ba50_acpi_id,
	},
	.probe =        stk8ba50_probe,
	.remove =           stk8ba50_remove,
	.id_table =         stk8ba50_i2c_id,
};

module_i2c_driver(stk8ba50_driver);

MODULE_AUTHOR("Tiberiu Breana <tiberiu.a.breana@intel.com>");
MODULE_DESCRIPTION("STK8BA50 3-Axis Accelerometer driver");
MODULE_LICENSE("GPL v2");
