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

Commit 99be0245 authored by Sebastian Reichel's avatar Sebastian Reichel Committed by Lee Jones
Browse files

mfd: twl4030-madc: Cleanup driver



Some style fixes in twl4030-madc driver.

Reported-by: default avatarJonathan Cameron <jic23@kernel.org>
Reported-by: default avatarLee Jones <lee.jones@linaro.org>
Signed-off-by: default avatarSebastian Reichel <sre@debian.org>
Acked-by: default avatarJonathan Cameron <jic23@kernel.org>
Tested-by: default avatarMarek Belisko <marek@goldelico.com>
Signed-off-by: default avatarLee Jones <lee.jones@linaro.org>
parent 2f39b70f
Loading
Loading
Loading
Loading
+72 −73
Original line number Original line Diff line number Diff line
@@ -49,22 +49,22 @@


#include <linux/iio/iio.h>
#include <linux/iio/iio.h>


/*
/**
 * struct twl4030_madc_data - a container for madc info
 * struct twl4030_madc_data - a container for madc info
 * @dev - pointer to device structure for madc
 * @dev:		Pointer to device structure for madc
 * @lock - mutex protecting this data structure
 * @lock:		Mutex protecting this data structure
 * @requests - Array of request struct corresponding to SW1, SW2 and RT
 * @requests:		Array of request struct corresponding to SW1, SW2 and RT
 * @use_second_irq - IRQ selection (main or co-processor)
 * @use_second_irq:	IRQ selection (main or co-processor)
 * @imr - Interrupt mask register of MADC
 * @imr:		Interrupt mask register of MADC
 * @isr - Interrupt status register of MADC
 * @isr:		Interrupt status register of MADC
 */
 */
struct twl4030_madc_data {
struct twl4030_madc_data {
	struct device *dev;
	struct device *dev;
	struct mutex lock;	/* mutex protecting this data structure */
	struct mutex lock;	/* mutex protecting this data structure */
	struct twl4030_madc_request requests[TWL4030_MADC_NUM_METHODS];
	struct twl4030_madc_request requests[TWL4030_MADC_NUM_METHODS];
	bool use_second_irq;
	bool use_second_irq;
	int imr;
	u8 imr;
	int isr;
	u8 isr;
};
};


static int twl4030_madc_read(struct iio_dev *iio_dev,
static int twl4030_madc_read(struct iio_dev *iio_dev,
@@ -155,17 +155,16 @@ twl4030_divider_ratios[16] = {
};
};




/*
/* Conversion table from -3 to 55 degrees Celcius */
 * Conversion table from -3 to 55 degree Celcius
static int twl4030_therm_tbl[] = {
 */
static int therm_tbl[] = {
	30800,	29500,	28300,	27100,
	30800,	29500,	28300,	27100,
26000,	24900,	23900,	22900,	22000,	21100,	20300,	19400,	18700,	17900,
	26000,	24900,	23900,	22900,	22000,	21100,	20300,	19400,	18700,
17200,	16500,	15900,	15300,	14700,	14100,	13600,	13100,	12600,	12100,
	17900,	17200,	16500,	15900,	15300,	14700,	14100,	13600,	13100,
11600,	11200,	10800,	10400,	10000,	9630,	9280,	8950,	8620,	8310,
	12600,	12100,	11600,	11200,	10800,	10400,	10000,	9630,	9280,
8020,	7730,	7460,	7200,	6950,	6710,	6470,	6250,	6040,	5830,
	8950,	8620,	8310,	8020,	7730,	7460,	7200,	6950,	6710,
5640,	5450,	5260,	5090,	4920,	4760,	4600,	4450,	4310,	4170,
	6470,	6250,	6040,	5830,	5640,	5450,	5260,	5090,	4920,
4040,	3910,	3790,	3670,	3550
	4760,	4600,	4450,	4310,	4170,	4040,	3910,	3790,	3670,
	3550
};
};


/*
/*
@@ -197,11 +196,12 @@ const struct twl4030_madc_conversion_method twl4030_conversion_methods[] = {
			      },
			      },
};
};


/*
/**
 * Function to read a particular channel value.
 * twl4030_madc_channel_raw_read() - Function to read a particular channel value
 * @madc - pointer to struct twl4030_madc_data
 * @madc:	pointer to struct twl4030_madc_data
 * @reg - lsb of ADC Channel
 * @reg:	lsb of ADC Channel
 * If the i2c read fails it returns an error else returns 0.
 *
 * Return: 0 on success, an error code otherwise.
 */
 */
static int twl4030_madc_channel_raw_read(struct twl4030_madc_data *madc, u8 reg)
static int twl4030_madc_channel_raw_read(struct twl4030_madc_data *madc, u8 reg)
{
{
@@ -227,7 +227,7 @@ static int twl4030_madc_channel_raw_read(struct twl4030_madc_data *madc, u8 reg)
}
}


/*
/*
 * Return battery temperature
 * Return battery temperature in degrees Celsius
 * Or < 0 on failure.
 * Or < 0 on failure.
 */
 */
static int twl4030battery_temperature(int raw_volt)
static int twl4030battery_temperature(int raw_volt)
@@ -236,18 +236,18 @@ static int twl4030battery_temperature(int raw_volt)
	int temp, curr, volt, res, ret;
	int temp, curr, volt, res, ret;


	volt = (raw_volt * TEMP_STEP_SIZE) / TEMP_PSR_R;
	volt = (raw_volt * TEMP_STEP_SIZE) / TEMP_PSR_R;
	/* Getting and calculating the supply current in micro ampers */
	/* Getting and calculating the supply current in micro amperes */
	ret = twl_i2c_read_u8(TWL_MODULE_MAIN_CHARGE, &val,
	ret = twl_i2c_read_u8(TWL_MODULE_MAIN_CHARGE, &val,
		REG_BCICTL2);
		REG_BCICTL2);
	if (ret < 0)
	if (ret < 0)
		return ret;
		return ret;

	curr = ((val & TWL4030_BCI_ITHEN) + 1) * 10;
	curr = ((val & TWL4030_BCI_ITHEN) + 1) * 10;
	/* Getting and calculating the thermistor resistance in ohms */
	/* Getting and calculating the thermistor resistance in ohms */
	res = volt * 1000 / curr;
	res = volt * 1000 / curr;
	/* calculating temperature */
	/* calculating temperature */
	for (temp = 58; temp >= 0; temp--) {
	for (temp = 58; temp >= 0; temp--) {
		int actual = therm_tbl[temp];
		int actual = twl4030_therm_tbl[temp];

		if ((actual - res) >= 0)
		if ((actual - res) >= 0)
			break;
			break;
	}
	}
@@ -269,11 +269,12 @@ static int twl4030battery_current(int raw_volt)
	else /* slope of 0.88 mV/mA */
	else /* slope of 0.88 mV/mA */
		return (raw_volt * CURR_STEP_SIZE) / CURR_PSR_R2;
		return (raw_volt * CURR_STEP_SIZE) / CURR_PSR_R2;
}
}

/*
/*
 * Function to read channel values
 * Function to read channel values
 * @madc - pointer to twl4030_madc_data struct
 * @madc - pointer to twl4030_madc_data struct
 * @reg_base - Base address of the first channel
 * @reg_base - Base address of the first channel
 * @Channels - 16 bit bitmap. If the bit is set, channel value is read
 * @Channels - 16 bit bitmap. If the bit is set, channel's value is read
 * @buf - The channel values are stored here. if read fails error
 * @buf - The channel values are stored here. if read fails error
 * @raw - Return raw values without conversion
 * @raw - Return raw values without conversion
 * value is stored
 * value is stored
@@ -284,17 +285,17 @@ static int twl4030_madc_read_channels(struct twl4030_madc_data *madc,
				      long channels, int *buf,
				      long channels, int *buf,
				      bool raw)
				      bool raw)
{
{
	int count = 0, count_req = 0, i;
	int count = 0;
	int i;
	u8 reg;
	u8 reg;


	for_each_set_bit(i, &channels, TWL4030_MADC_MAX_CHANNELS) {
	for_each_set_bit(i, &channels, TWL4030_MADC_MAX_CHANNELS) {
		reg = reg_base + 2 * i;
		reg = reg_base + (2 * i);
		buf[i] = twl4030_madc_channel_raw_read(madc, reg);
		buf[i] = twl4030_madc_channel_raw_read(madc, reg);
		if (buf[i] < 0) {
		if (buf[i] < 0) {
			dev_err(madc->dev,
			dev_err(madc->dev, "Unable to read register 0x%X\n",
				"Unable to read register 0x%X\n", reg);
				reg);
			count_req++;
			return buf[i];
			continue;
		}
		}
		if (raw) {
		if (raw) {
			count++;
			count++;
@@ -305,7 +306,7 @@ static int twl4030_madc_read_channels(struct twl4030_madc_data *madc,
			buf[i] = twl4030battery_current(buf[i]);
			buf[i] = twl4030battery_current(buf[i]);
			if (buf[i] < 0) {
			if (buf[i] < 0) {
				dev_err(madc->dev, "err reading current\n");
				dev_err(madc->dev, "err reading current\n");
				count_req++;
				return buf[i];
			} else {
			} else {
				count++;
				count++;
				buf[i] = buf[i] - 750;
				buf[i] = buf[i] - 750;
@@ -315,7 +316,7 @@ static int twl4030_madc_read_channels(struct twl4030_madc_data *madc,
			buf[i] = twl4030battery_temperature(buf[i]);
			buf[i] = twl4030battery_temperature(buf[i]);
			if (buf[i] < 0) {
			if (buf[i] < 0) {
				dev_err(madc->dev, "err reading temperature\n");
				dev_err(madc->dev, "err reading temperature\n");
				count_req++;
				return buf[i];
			} else {
			} else {
				buf[i] -= 3;
				buf[i] -= 3;
				count++;
				count++;
@@ -336,8 +337,6 @@ static int twl4030_madc_read_channels(struct twl4030_madc_data *madc,
				twl4030_divider_ratios[i].numerator);
				twl4030_divider_ratios[i].numerator);
		}
		}
	}
	}
	if (count_req)
		dev_err(madc->dev, "%d channel conversion failed\n", count_req);


	return count;
	return count;
}
}
@@ -361,13 +360,13 @@ static int twl4030_madc_enable_irq(struct twl4030_madc_data *madc, u8 id)
			madc->imr);
			madc->imr);
		return ret;
		return ret;
	}
	}

	val &= ~(1 << id);
	val &= ~(1 << id);
	ret = twl_i2c_write_u8(TWL4030_MODULE_MADC, val, madc->imr);
	ret = twl_i2c_write_u8(TWL4030_MODULE_MADC, val, madc->imr);
	if (ret) {
	if (ret) {
		dev_err(madc->dev,
		dev_err(madc->dev,
			"unable to write imr register 0x%X\n", madc->imr);
			"unable to write imr register 0x%X\n", madc->imr);
		return ret;
		return ret;

	}
	}


	return 0;
	return 0;
@@ -512,22 +511,18 @@ static int twl4030_madc_start_conversion(struct twl4030_madc_data *madc,
{
{
	const struct twl4030_madc_conversion_method *method;
	const struct twl4030_madc_conversion_method *method;
	int ret = 0;
	int ret = 0;

	if (conv_method != TWL4030_MADC_SW1 && conv_method != TWL4030_MADC_SW2)
		return -ENOTSUPP;

	method = &twl4030_conversion_methods[conv_method];
	method = &twl4030_conversion_methods[conv_method];
	switch (conv_method) {
	ret = twl_i2c_write_u8(TWL4030_MODULE_MADC, TWL4030_MADC_SW_START,
	case TWL4030_MADC_SW1:
			       method->ctrl);
	case TWL4030_MADC_SW2:
		ret = twl_i2c_write_u8(TWL4030_MODULE_MADC,
				       TWL4030_MADC_SW_START, method->ctrl);
	if (ret) {
	if (ret) {
			dev_err(madc->dev,
		dev_err(madc->dev, "unable to write ctrl register 0x%X\n",
				"unable to write ctrl register 0x%X\n",
			method->ctrl);
			method->ctrl);
		return ret;
		return ret;
	}
	}
		break;
	default:
		break;
	}


	return 0;
	return 0;
}
}
@@ -623,8 +618,8 @@ int twl4030_madc_conversion(struct twl4030_madc_request *req)
				       ch_lsb, method->avg);
				       ch_lsb, method->avg);
		if (ret) {
		if (ret) {
			dev_err(twl4030_madc->dev,
			dev_err(twl4030_madc->dev,
				"unable to write sel reg 0x%X\n",
				"unable to write avg reg 0x%X\n",
				method->sel + 1);
				method->avg);
			goto out;
			goto out;
		}
		}
	}
	}
@@ -665,10 +660,6 @@ int twl4030_madc_conversion(struct twl4030_madc_request *req)
}
}
EXPORT_SYMBOL_GPL(twl4030_madc_conversion);
EXPORT_SYMBOL_GPL(twl4030_madc_conversion);


/*
 * Return channel value
 * Or < 0 on failure.
 */
int twl4030_get_madc_conversion(int channel_no)
int twl4030_get_madc_conversion(int channel_no)
{
{
	struct twl4030_madc_request req;
	struct twl4030_madc_request req;
@@ -689,20 +680,25 @@ int twl4030_get_madc_conversion(int channel_no)
}
}
EXPORT_SYMBOL_GPL(twl4030_get_madc_conversion);
EXPORT_SYMBOL_GPL(twl4030_get_madc_conversion);


/*
/**
 * twl4030_madc_set_current_generator() - setup bias current
 *
 * @madc:	pointer to twl4030_madc_data struct
 * @chan:	can be one of the two values:
 *		TWL4030_BCI_ITHEN
 *		Enables bias current for main battery type reading
 *		TWL4030_BCI_TYPEN
 *		Enables bias current for main battery temperature sensing
 * @on:		enable or disable chan.
 *
 * Function to enable or disable bias current for
 * Function to enable or disable bias current for
 * main battery type reading or temperature sensing
 * main battery type reading or temperature sensing
 * @madc - pointer to twl4030_madc_data struct
 * @chan - can be one of the two values
 * TWL4030_BCI_ITHEN - Enables bias current for main battery type reading
 * TWL4030_BCI_TYPEN - Enables bias current for main battery temperature
 * sensing
 * @on - enable or disable chan.
 */
 */
static int twl4030_madc_set_current_generator(struct twl4030_madc_data *madc,
static int twl4030_madc_set_current_generator(struct twl4030_madc_data *madc,
					      int chan, int on)
					      int chan, int on)
{
{
	int ret;
	int ret;
	int regmask;
	u8 regval;
	u8 regval;


	ret = twl_i2c_read_u8(TWL_MODULE_MAIN_CHARGE,
	ret = twl_i2c_read_u8(TWL_MODULE_MAIN_CHARGE,
@@ -712,10 +708,13 @@ static int twl4030_madc_set_current_generator(struct twl4030_madc_data *madc,
			TWL4030_BCI_BCICTL1);
			TWL4030_BCI_BCICTL1);
		return ret;
		return ret;
	}
	}

	regmask = chan ? TWL4030_BCI_ITHEN : TWL4030_BCI_TYPEN;
	if (on)
	if (on)
		regval |= chan ? TWL4030_BCI_ITHEN : TWL4030_BCI_TYPEN;
		regval |= regmask;
	else
	else
		regval &= chan ? ~TWL4030_BCI_ITHEN : ~TWL4030_BCI_TYPEN;
		regval &= ~regmask;

	ret = twl_i2c_write_u8(TWL_MODULE_MAIN_CHARGE,
	ret = twl_i2c_write_u8(TWL_MODULE_MAIN_CHARGE,
			       regval, TWL4030_BCI_BCICTL1);
			       regval, TWL4030_BCI_BCICTL1);
	if (ret) {
	if (ret) {
@@ -730,7 +729,7 @@ static int twl4030_madc_set_current_generator(struct twl4030_madc_data *madc,
/*
/*
 * Function that sets MADC software power on bit to enable MADC
 * Function that sets MADC software power on bit to enable MADC
 * @madc - pointer to twl4030_madc_data struct
 * @madc - pointer to twl4030_madc_data struct
 * @on - Enable or disable MADC software powen on bit.
 * @on - Enable or disable MADC software power on bit.
 * returns error if i2c read/write fails else 0
 * returns error if i2c read/write fails else 0
 */
 */
static int twl4030_madc_set_power(struct twl4030_madc_data *madc, int on)
static int twl4030_madc_set_power(struct twl4030_madc_data *madc, int on)
+1 −1
Original line number Original line Diff line number Diff line
@@ -44,7 +44,7 @@ struct twl4030_madc_conversion_method {


struct twl4030_madc_request {
struct twl4030_madc_request {
	unsigned long channels;
	unsigned long channels;
	u16 do_avg;
	bool do_avg;
	u16 method;
	u16 method;
	u16 type;
	u16 type;
	bool active;
	bool active;