Skip to contentSkip to conversation

Input: ads7846 - allow specifying irq trigger type in platform data

PATCH Applied Anatolij Gustschin 2 participants 12 messages Apr 30, 2010 – Jul 1, 2010

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/2 Input: ads7846 - allow specifying irq trigger type in platform data

On some platforms, for example with GPIO interrupts on mpc5121, it is not possible to configure falling edge interrupts.

Specifying irq trigger type in platform data structure allows using ads7846 driver on such platforms.

---
 drivers/input/touchscreen/ads7846.c |    5 ++++-
 include/linux/spi/ads7846.h         |    1 +
 2 files changed, 5 insertions(+), 1 deletions(-)
drivers/input/touchscreen/ads7846.c +4 -1
index 532279c..9cfc865 100644
@@ -1174,7 +1174,10 @@ static int __devinit ads7846_probe(struct spi_device *spi)
 		goto err_put_regulator;
 	}
 
-	if (request_irq(spi->irq, ads7846_irq, IRQF_TRIGGER_FALLING,
+	if (!pdata->irq_trigger)
+		pdata->irq_trigger = IRQF_TRIGGER_FALLING;
+
+	if (request_irq(spi->irq, ads7846_irq, pdata->irq_trigger,
 			spi->dev.driver->name, ts)) {
 		dev_info(&spi->dev,
 			"trying pin change workaround on irq %d\n", spi->irq);
include/linux/spi/ads7846.h +1 -0
index b4ae570..32e34ba 100644
@@ -54,5 +54,6 @@ struct ads7846_platform_data {
 	void	(*filter_cleanup)(void *filter_data);
 	void	(*wait_for_sync)(void);
 	bool	wakeup;
+	u8	irq_trigger;
 };
 
Signature · 1 line
1.6.3.3
#1 lore raw

PATCH 2/2 Input: ads7846 - extend the driver for ads7845 controller support

---
 drivers/input/touchscreen/ads7846.c |  173 +++++++++++++++++++++++++++--------
 1 files changed, 136 insertions(+), 37 deletions(-)
drivers/input/touchscreen/ads7846.c +136 -37
index 9cfc865..1dd5c79 100644
@@ -68,6 +68,8 @@ struct ts_event {
 	u16	y;
 	u16	z1, z2;
 	int	ignore;
+	u8	x_buf[3];
+	u8	y_buf[3];
 };
 
 /*
@@ -79,6 +81,8 @@ struct ads7846_packet {
 	u8			read_x, read_y, read_z1, read_z2, pwrdown;
 	u16			dummy;		/* for the pwrdown read */
 	struct ts_event		tc;
+	/* for ads7845 with mpc5121 psc spi we use 3-byte buffers */
+	u8			read_x_cmd[3], read_y_cmd[3], pwrdown_cmd[3];
 };
 
 struct ads7846 {
@@ -207,6 +211,14 @@ struct ser_req {
 	struct spi_transfer	xfer[6];
 };
 
+struct ads7845_ser_req {
+	u8			command[3];
+	u8			pwrdown[3];
+	u8			sample[3];
+	struct spi_message	msg;
+	struct spi_transfer	xfer[2];
+};
+
 static void ads7846_enable(struct ads7846 *ts);
 static void ads7846_disable(struct ads7846 *ts);
 
@@ -287,6 +299,41 @@ static int ads7846_read12_ser(struct device *dev, unsigned command)
 	return status;
 }
 
+static int ads7845_read12_ser(struct device *dev, unsigned command)
+{
+	struct spi_device	*spi = to_spi_device(dev);
+	struct ads7846		*ts = dev_get_drvdata(dev);
+	struct ads7845_ser_req	*req = kzalloc(sizeof *req, GFP_KERNEL);
+	int			status;
+
+	if (!req)
+		return -ENOMEM;
+
+	spi_message_init(&req->msg);
+
+	req->command[0] = (u8) command;
+	req->xfer[0].tx_buf = req->command;
+	req->xfer[0].rx_buf = req->sample;
+	req->xfer[0].len = 3;
+	spi_message_add_tail(&req->xfer[0], &req->msg);
+
+	ts->irq_disabled = 1;
+	disable_irq(spi->irq);
+	status = spi_sync(spi, &req->msg);
+	ts->irq_disabled = 0;
+	enable_irq(spi->irq);
+
+	if (status == 0) {
+		/* BE12 value, then padding */
+		status = be16_to_cpu(*((u16 *)&req->sample[1]));
+		status = status >> 3;
+		status &= 0x0fff;
+	}
+
+	kfree(req);
+	return status;
+}
+
 #if defined(CONFIG_HWMON) || defined(CONFIG_HWMON_MODULE)
 
 #define SHOW(name, var, adjust) static ssize_t \
@@ -540,10 +587,17 @@ static void ads7846_rx(void *ads)
 	/* ads7846_rx_val() did in-place conversion (including byteswap) from
 	 * on-the-wire format as part of debouncing to get stable readings.
 	 */
-	x = packet->tc.x;
-	y = packet->tc.y;
-	z1 = packet->tc.z1;
-	z2 = packet->tc.z2;
+	if (ts->model == 7845) {
+		x = *(u16 *)packet->tc.x_buf;
+		y = *(u16 *)packet->tc.y_buf;
+		z1 = 0;
+		z2 = 0;
+	} else {
+		x = packet->tc.x;
+		y = packet->tc.y;
+		z1 = packet->tc.z1;
+		z2 = packet->tc.z2;
+	}
 
 	/* range filtering */
 	if (x == MAX_12BIT)
@@ -551,6 +605,12 @@ static void ads7846_rx(void *ads)
 
 	if (ts->model == 7843) {
 		Rt = ts->pressure_max / 2;
+	} else if (ts->model == 7845) {
+		if (get_pendown_state(ts))
+			Rt = ts->pressure_max / 2;
+		else
+			Rt = 0;
+		dev_vdbg(&ts->spi->dev, "x/y: %d/%d, PD %d\n", x, y, Rt);
 	} else if (likely(x && z1)) {
 		/* compute touch pressure resistance using equation #2 */
 		Rt = z2;
@@ -671,10 +731,14 @@ static void ads7846_rx_val(void *ads)
 	m = &ts->msg[ts->msg_idx];
 	t = list_entry(m->transfers.prev, struct spi_transfer, transfer_list);
 
-	/* adjust:  on-wire is a must-ignore bit, a BE12 value, then padding;
-	 * built from two 8 bit values written msb-first.
-	 */
-	val = be16_to_cpup((__be16 *)t->rx_buf) >> 3;
+	if (ts->model == 7845) {
+		val = be16_to_cpup((__be16 *)&(((char*)t->rx_buf)[1])) >> 3;
+	} else {
+		/* adjust:  on-wire is a must-ignore bit, a BE12 value, then padding;
+		 * built from two 8 bit values written msb-first.
+		 */
+		val = be16_to_cpup((__be16 *)t->rx_buf) >> 3;
+	}
 
 	action = ts->filter(ts->filter_data, ts->msg_idx, &val);
 	switch (action) {
@@ -1008,16 +1072,26 @@ static int __devinit ads7846_probe(struct spi_device *spi)
 
 	spi_message_init(m);
 
-	/* y- still on; turn on only y+ (and ADC) */
-	packet->read_y = READ_Y(vref);
-	x->tx_buf = &packet->read_y;
-	x->len = 1;
-	spi_message_add_tail(x, m);
+	if (ts->model == 7845) {
+		packet->read_y_cmd[0] = READ_Y(vref);
+		packet->read_y_cmd[1] = 0;
+		packet->read_y_cmd[2] = 0;
+		x->tx_buf = &packet->read_y_cmd[0];
+		x->rx_buf = &packet->tc.y_buf[0];
+		x->len = 3;
+		spi_message_add_tail(x, m);
+	} else {
+		/* y- still on; turn on only y+ (and ADC) */
+		packet->read_y = READ_Y(vref);
+		x->tx_buf = &packet->read_y;
+		x->len = 1;
+		spi_message_add_tail(x, m);
 
-	x++;
-	x->rx_buf = &packet->tc.y;
-	x->len = 2;
-	spi_message_add_tail(x, m);
+		x++;
+		x->rx_buf = &packet->tc.y;
+		x->len = 2;
+		spi_message_add_tail(x, m);
+	}
 
 	/* the first sample after switching drivers can be low quality;
 	 * optionally discard it, using a second one after the signals
@@ -1043,17 +1117,28 @@ static int __devinit ads7846_probe(struct spi_device *spi)
 	m++;
 	spi_message_init(m);
 
-	/* turn y- off, x+ on, then leave in lowpower */
-	x++;
-	packet->read_x = READ_X(vref);
-	x->tx_buf = &packet->read_x;
-	x->len = 1;
-	spi_message_add_tail(x, m);
+	if (ts->model == 7845) {
+		x++;
+		packet->read_x_cmd[0] = READ_X(vref);
+		packet->read_x_cmd[1] = 0;
+		packet->read_x_cmd[2] = 0;
+		x->tx_buf = &packet->read_x_cmd[0];
+		x->rx_buf = &packet->tc.x_buf[0];
+		x->len = 3;
+		spi_message_add_tail(x, m);
+	} else {
+		/* turn y- off, x+ on, then leave in lowpower */
+		x++;
+		packet->read_x = READ_X(vref);
+		x->tx_buf = &packet->read_x;
+		x->len = 1;
+		spi_message_add_tail(x, m);
 
-	x++;
-	x->rx_buf = &packet->tc.x;
-	x->len = 2;
-	spi_message_add_tail(x, m);
+		x++;
+		x->rx_buf = &packet->tc.x;
+		x->len = 2;
+		spi_message_add_tail(x, m);
+	}
 
 	/* ... maybe discard first sample ... */
 	if (pdata->settle_delay_usecs) {
@@ -1144,15 +1229,25 @@ static int __devinit ads7846_probe(struct spi_device *spi)
 	m++;
 	spi_message_init(m);
 
-	x++;
-	packet->pwrdown = PWRDOWN;
-	x->tx_buf = &packet->pwrdown;
-	x->len = 1;
-	spi_message_add_tail(x, m);
+	if (ts->model == 7845) {
+		x++;
+		packet->pwrdown_cmd[0] = PWRDOWN;
+		packet->pwrdown_cmd[1] = 0;
+		packet->pwrdown_cmd[2] = 0;
+		x->tx_buf = &packet->pwrdown_cmd[0];
+		x->len = 3;
+	} else {
+		x++;
+		packet->pwrdown = PWRDOWN;
+		x->tx_buf = &packet->pwrdown;
+		x->len = 1;
+		spi_message_add_tail(x, m);
+
+		x++;
+		x->rx_buf = &packet->dummy;
+		x->len = 2;
+	}
 
-	x++;
-	x->rx_buf = &packet->dummy;
-	x->len = 2;
 	CS_CHANGE(*x);
 	spi_message_add_tail(x, m);
 
@@ -1199,8 +1294,12 @@ static int __devinit ads7846_probe(struct spi_device *spi)
 	/* take a first sample, leaving nPENIRQ active and vREF off; avoid
 	 * the touchscreen, in case it's not connected.
 	 */
-	(void) ads7846_read12_ser(&spi->dev,
-			  READ_12BIT_SER(vaux) | ADS_PD10_ALL_ON);
+	if (ts->model == 7845) {
+		ads7845_read12_ser(&spi->dev, PWRDOWN);
+	} else {
+		(void) ads7846_read12_ser(&spi->dev,
+				READ_12BIT_SER(vaux) | ADS_PD10_ALL_ON);
+	}
 
 	err = sysfs_create_group(&spi->dev.kobj, &ads784x_attr_group);
 	if (err)
Signature · 1 line
1.6.3.3
#2 lore raw

PATCH v2 2/2 Input: ads7846 - extend the driver for ads7845 controller support

ADS7845 is a controller for 5-wire touch screens and somewhat different from 7846. It requires three serial communications to accomplish one complete conversion. Unlike 7846 it doesn't allow Z1-/Z2- position measurement.

The patch extends the ads7846 driver to also support ads7845. The packet struct is extended to contain needed command and conversion buffers. ads7846_rx() and ads7846_rx_val() now differentiate between 7845 and 7846 case. ads7846_probe() is modified to setup ads7845 specific command and conversion messages and to switch ads7845 into power-down mode, since this is needed to be prepared to respond to pendown interrupts.

---
Changes since first version:
- provide better changelog as requested by Dmitry
- fix to long comment line (it was over 80 characters)

 drivers/input/touchscreen/ads7846.c |  173 +++++++++++++++++++++++++++--------
 1 files changed, 136 insertions(+), 37 deletions(-)
drivers/input/touchscreen/ads7846.c +136 -37
index 69210cb..8ab90dd 100644
@@ -68,6 +68,8 @@ struct ts_event {
 	u16	y;
 	u16	z1, z2;
 	int	ignore;
+	u8	x_buf[3];
+	u8	y_buf[3];
 };
 
 /*
@@ -79,6 +81,8 @@ struct ads7846_packet {
 	u8			read_x, read_y, read_z1, read_z2, pwrdown;
 	u16			dummy;		/* for the pwrdown read */
 	struct ts_event		tc;
+	/* for ads7845 with mpc5121 psc spi we use 3-byte buffers */
+	u8			read_x_cmd[3], read_y_cmd[3], pwrdown_cmd[3];
 };
 
 struct ads7846 {
@@ -207,6 +211,14 @@ struct ser_req {
 	struct spi_transfer	xfer[6];
 };
 
+struct ads7845_ser_req {
+	u8			command[3];
+	u8			pwrdown[3];
+	u8			sample[3];
+	struct spi_message	msg;
+	struct spi_transfer	xfer[2];
+};
+
 static void ads7846_enable(struct ads7846 *ts);
 static void ads7846_disable(struct ads7846 *ts);
 
@@ -287,6 +299,41 @@ static int ads7846_read12_ser(struct device *dev, unsigned command)
 	return status;
 }
 
+static int ads7845_read12_ser(struct device *dev, unsigned command)
+{
+	struct spi_device	*spi = to_spi_device(dev);
+	struct ads7846		*ts = dev_get_drvdata(dev);
+	struct ads7845_ser_req	*req = kzalloc(sizeof *req, GFP_KERNEL);
+	int			status;
+
+	if (!req)
+		return -ENOMEM;
+
+	spi_message_init(&req->msg);
+
+	req->command[0] = (u8) command;
+	req->xfer[0].tx_buf = req->command;
+	req->xfer[0].rx_buf = req->sample;
+	req->xfer[0].len = 3;
+	spi_message_add_tail(&req->xfer[0], &req->msg);
+
+	ts->irq_disabled = 1;
+	disable_irq(spi->irq);
+	status = spi_sync(spi, &req->msg);
+	ts->irq_disabled = 0;
+	enable_irq(spi->irq);
+
+	if (status == 0) {
+		/* BE12 value, then padding */
+		status = be16_to_cpu(*((u16 *)&req->sample[1]));
+		status = status >> 3;
+		status &= 0x0fff;
+	}
+
+	kfree(req);
+	return status;
+}
+
 #if defined(CONFIG_HWMON) || defined(CONFIG_HWMON_MODULE)
 
 #define SHOW(name, var, adjust) static ssize_t \
@@ -540,10 +587,17 @@ static void ads7846_rx(void *ads)
 	/* ads7846_rx_val() did in-place conversion (including byteswap) from
 	 * on-the-wire format as part of debouncing to get stable readings.
 	 */
-	x = packet->tc.x;
-	y = packet->tc.y;
-	z1 = packet->tc.z1;
-	z2 = packet->tc.z2;
+	if (ts->model == 7845) {
+		x = *(u16 *)packet->tc.x_buf;
+		y = *(u16 *)packet->tc.y_buf;
+		z1 = 0;
+		z2 = 0;
+	} else {
+		x = packet->tc.x;
+		y = packet->tc.y;
+		z1 = packet->tc.z1;
+		z2 = packet->tc.z2;
+	}
 
 	/* range filtering */
 	if (x == MAX_12BIT)
@@ -551,6 +605,12 @@ static void ads7846_rx(void *ads)
 
 	if (ts->model == 7843) {
 		Rt = ts->pressure_max / 2;
+	} else if (ts->model == 7845) {
+		if (get_pendown_state(ts))
+			Rt = ts->pressure_max / 2;
+		else
+			Rt = 0;
+		dev_vdbg(&ts->spi->dev, "x/y: %d/%d, PD %d\n", x, y, Rt);
 	} else if (likely(x && z1)) {
 		/* compute touch pressure resistance using equation #2 */
 		Rt = z2;
@@ -671,10 +731,14 @@ static void ads7846_rx_val(void *ads)
 	m = &ts->msg[ts->msg_idx];
 	t = list_entry(m->transfers.prev, struct spi_transfer, transfer_list);
 
-	/* adjust:  on-wire is a must-ignore bit, a BE12 value, then padding;
-	 * built from two 8 bit values written msb-first.
-	 */
-	val = be16_to_cpup((__be16 *)t->rx_buf) >> 3;
+	if (ts->model == 7845) {
+		val = be16_to_cpup((__be16 *)&(((char*)t->rx_buf)[1])) >> 3;
+	} else {
+		/* adjust:  on-wire is a must-ignore bit, a BE12 value, then
+		 * padding; built from two 8 bit values written msb-first.
+		 */
+		val = be16_to_cpup((__be16 *)t->rx_buf) >> 3;
+	}
 
 	action = ts->filter(ts->filter_data, ts->msg_idx, &val);
 	switch (action) {
@@ -1008,16 +1072,26 @@ static int __devinit ads7846_probe(struct spi_device *spi)
 
 	spi_message_init(m);
 
-	/* y- still on; turn on only y+ (and ADC) */
-	packet->read_y = READ_Y(vref);
-	x->tx_buf = &packet->read_y;
-	x->len = 1;
-	spi_message_add_tail(x, m);
+	if (ts->model == 7845) {
+		packet->read_y_cmd[0] = READ_Y(vref);
+		packet->read_y_cmd[1] = 0;
+		packet->read_y_cmd[2] = 0;
+		x->tx_buf = &packet->read_y_cmd[0];
+		x->rx_buf = &packet->tc.y_buf[0];
+		x->len = 3;
+		spi_message_add_tail(x, m);
+	} else {
+		/* y- still on; turn on only y+ (and ADC) */
+		packet->read_y = READ_Y(vref);
+		x->tx_buf = &packet->read_y;
+		x->len = 1;
+		spi_message_add_tail(x, m);
 
-	x++;
-	x->rx_buf = &packet->tc.y;
-	x->len = 2;
-	spi_message_add_tail(x, m);
+		x++;
+		x->rx_buf = &packet->tc.y;
+		x->len = 2;
+		spi_message_add_tail(x, m);
+	}
 
 	/* the first sample after switching drivers can be low quality;
 	 * optionally discard it, using a second one after the signals
@@ -1043,17 +1117,28 @@ static int __devinit ads7846_probe(struct spi_device *spi)
 	m++;
 	spi_message_init(m);
 
-	/* turn y- off, x+ on, then leave in lowpower */
-	x++;
-	packet->read_x = READ_X(vref);
-	x->tx_buf = &packet->read_x;
-	x->len = 1;
-	spi_message_add_tail(x, m);
+	if (ts->model == 7845) {
+		x++;
+		packet->read_x_cmd[0] = READ_X(vref);
+		packet->read_x_cmd[1] = 0;
+		packet->read_x_cmd[2] = 0;
+		x->tx_buf = &packet->read_x_cmd[0];
+		x->rx_buf = &packet->tc.x_buf[0];
+		x->len = 3;
+		spi_message_add_tail(x, m);
+	} else {
+		/* turn y- off, x+ on, then leave in lowpower */
+		x++;
+		packet->read_x = READ_X(vref);
+		x->tx_buf = &packet->read_x;
+		x->len = 1;
+		spi_message_add_tail(x, m);
 
-	x++;
-	x->rx_buf = &packet->tc.x;
-	x->len = 2;
-	spi_message_add_tail(x, m);
+		x++;
+		x->rx_buf = &packet->tc.x;
+		x->len = 2;
+		spi_message_add_tail(x, m);
+	}
 
 	/* ... maybe discard first sample ... */
 	if (pdata->settle_delay_usecs) {
@@ -1144,15 +1229,25 @@ static int __devinit ads7846_probe(struct spi_device *spi)
 	m++;
 	spi_message_init(m);
 
-	x++;
-	packet->pwrdown = PWRDOWN;
-	x->tx_buf = &packet->pwrdown;
-	x->len = 1;
-	spi_message_add_tail(x, m);
+	if (ts->model == 7845) {
+		x++;
+		packet->pwrdown_cmd[0] = PWRDOWN;
+		packet->pwrdown_cmd[1] = 0;
+		packet->pwrdown_cmd[2] = 0;
+		x->tx_buf = &packet->pwrdown_cmd[0];
+		x->len = 3;
+	} else {
+		x++;
+		packet->pwrdown = PWRDOWN;
+		x->tx_buf = &packet->pwrdown;
+		x->len = 1;
+		spi_message_add_tail(x, m);
+
+		x++;
+		x->rx_buf = &packet->dummy;
+		x->len = 2;
+	}
 
-	x++;
-	x->rx_buf = &packet->dummy;
-	x->len = 2;
 	CS_CHANGE(*x);
 	spi_message_add_tail(x, m);
 
@@ -1199,8 +1294,12 @@ static int __devinit ads7846_probe(struct spi_device *spi)
 	/* take a first sample, leaving nPENIRQ active and vREF off; avoid
 	 * the touchscreen, in case it's not connected.
 	 */
-	(void) ads7846_read12_ser(&spi->dev,
-			  READ_12BIT_SER(vaux) | ADS_PD10_ALL_ON);
+	if (ts->model == 7845) {
+		ads7845_read12_ser(&spi->dev, PWRDOWN);
+	} else {
+		(void) ads7846_read12_ser(&spi->dev,
+				READ_12BIT_SER(vaux) | ADS_PD10_ALL_ON);
+	}
 
 	err = sysfs_create_group(&spi->dev.kobj, &ads784x_attr_group);
 	if (err)
Signature · 1 line
1.7.0.4
maintainer
#3 lore raw

Re: [PATCH v2 2/2] Input: ads7846 - extend the driver for ads7845 controller support

Quoted 5 lines · Anatolij Gustschin

ADS7845 is a controller for 5-wire touch screens and somewhat different from 7846. It requires three serial communications to accomplish one complete conversion. Unlike 7846 it doesn't allow Z1-/Z2- position measurement.

Quoted 9 lines

The patch extends the ads7846 driver to also support ads7845. The packet struct is extended to contain needed command and conversion buffers. ads7846_rx() and ads7846_rx_val() now differentiate between 7845 and 7846 case. ads7846_probe() is modified to setup ads7845 specific command and conversion messages and to switch ads7845 into power-down mode, since this is needed to be prepared to respond to pendown interrupts.

Thank you for making changes Anatolij, I iwll be applying the patch to my 2.6.36 queue.

I just noticed that your previous patch alters pdata which I belive is wrong thing to do. Could you please try the following patch and let me know if I broke anything?

Thanks!

Signature · 12 lines
Dmitry

Input: ads7846 - do not allow altering platform data

From: Dmitry Torokhov <[email protected]>

Signed-off-by: Dmitry Torokhov <[email protected]>
---

 drivers/input/touchscreen/ads7846.c |   35 +++++++++++++++++++----------------
 include/linux/spi/ads7846.h         |    2 +-
 2 files changed, 20 insertions(+), 17 deletions(-)
drivers/input/touchscreen/ads7846.c +19 -16
index 69210cb..8c9b316 100644
@@ -878,14 +878,15 @@ static int __devinit setup_pendown(struct spi_device *spi, struct ads7846 *ts)
 
 static int __devinit ads7846_probe(struct spi_device *spi)
 {
-	struct ads7846			*ts;
-	struct ads7846_packet		*packet;
-	struct input_dev		*input_dev;
-	struct ads7846_platform_data	*pdata = spi->dev.platform_data;
-	struct spi_message		*m;
-	struct spi_transfer		*x;
-	int				vref;
-	int				err;
+	struct ads7846 *ts;
+	struct ads7846_packet *packet;
+	struct input_dev *input_dev;
+	const struct ads7846_platform_data *pdata = spi->dev.platform_data;
+	struct spi_message *m;
+	struct spi_transfer *x;
+	unsigned long irq_flags;
+	int vref;
+	int err;
 
 	if (!spi->irq) {
 		dev_dbg(&spi->dev, "no IRQ?\n");
@@ -1174,20 +1175,22 @@ static int __devinit ads7846_probe(struct spi_device *spi)
 		goto err_put_regulator;
 	}
 
-	if (!pdata->irq_flags)
-		pdata->irq_flags = IRQF_TRIGGER_FALLING;
+	irq_flags = pdata->irq_flags ? : IRQF_TRIGGER_FALLING;
 
-	if (request_irq(spi->irq, ads7846_irq, pdata->irq_flags,
-			spi->dev.driver->name, ts)) {
+	err = request_irq(spi->irq, ads7846_irq, pdata->irq_flags,
+			  spi->dev.driver->name, ts);
+
+	if (err && !pdata->irq_flags) {
 		dev_info(&spi->dev,
 			"trying pin change workaround on irq %d\n", spi->irq);
 		err = request_irq(spi->irq, ads7846_irq,
 				  IRQF_TRIGGER_FALLING | IRQF_TRIGGER_RISING,
 				  spi->dev.driver->name, ts);
-		if (err) {
-			dev_dbg(&spi->dev, "irq %d busy?\n", spi->irq);
-			goto err_disable_regulator;
-		}
+	}
+
+	if (err) {
+		dev_dbg(&spi->dev, "irq %d busy?\n", spi->irq);
+		goto err_disable_regulator;
 	}
 
 	err = ads784x_hwmon_register(spi, ts);
include/linux/spi/ads7846.h +1 -1
index 95d36bf..92bd083 100644
@@ -48,7 +48,7 @@ struct ads7846_platform_data {
 					 * state if get_pendown_state == NULL
 					 */
 	int	(*get_pendown_state)(void);
-	int	(*filter_init)	(struct ads7846_platform_data *pdata,
+	int	(*filter_init)	(const struct ads7846_platform_data *pdata,
 				 void **filter_data);
 	int	(*filter)	(void *filter_data, int data_idx, int *val);
 	void	(*filter_cleanup)(void *filter_data);
#4 lore raw

Re: [PATCH v2 2/2] Input: ads7846 - extend the driver for ads7845 controller support

On Wed, 30 Jun 2010 01:18:05 -0700
Dmitry Torokhov <[email protected]> wrote:
...

Quoted 3 lines

I just noticed that your previous patch alters pdata which I belive is wrong thing to do. Could you please try the following patch and let me know if I broke anything?

Yes, altering pdata isn't a good idea. I can't try the patch just now but will test it this evening.

Thanks,

Anatolij

#5 lore raw

Re: [PATCH v2 2/2] Input: ads7846 - extend the driver for ads7845 controller support

In reply to Dmitry Torokhov
Quoted 16 lines · On Wed, 30 Jun 2010 01:18:05 -0700 Dmitry Torokhov <[email protected]>…
Quoted 5 lines · Anatolij Gustschin

ADS7845 is a controller for 5-wire touch screens and somewhat different from 7846. It requires three serial communications to accomplish one complete conversion. Unlike 7846 it doesn't allow Z1-/Z2- position measurement.

Quoted 9 lines

The patch extends the ads7846 driver to also support ads7845. The packet struct is extended to contain needed command and conversion buffers. ads7846_rx() and ads7846_rx_val() now differentiate between 7845 and 7846 case. ads7846_probe() is modified to setup ads7845 specific command and conversion messages and to switch ads7845 into power-down mode, since this is needed to be prepared to respond to pendown interrupts.

Quoted 6 lines

Thank you for making changes Anatolij, I iwll be applying the patch to my 2.6.36 queue.

I just noticed that your previous patch alters pdata which I belive is wrong thing to do. Could you please try the following patch and let me know if I broke anything?

The patch needs a small fix, please see below.

...

drivers/input/touchscreen/ads7846.c static int __devinit ads7846_probe(struct spi_device *spi) · line 1181

Quoted 8 lines
drivers/input/touchscreen/ads7846.c +3 -4
-	if (!pdata->irq_flags)
-		pdata->irq_flags = IRQF_TRIGGER_FALLING;
+	irq_flags = pdata->irq_flags ? : IRQF_TRIGGER_FALLING;
 
-	if (request_irq(spi->irq, ads7846_irq, pdata->irq_flags,
-			spi->dev.driver->name, ts)) {
+	err = request_irq(spi->irq, ads7846_irq, pdata->irq_flags,
+			  spi->dev.driver->name, ts);

We should pass previously obtained 'irq_flags' to request_irq(), not the original 'pdata->irq_flags'. I fixed this and tested the corrected patch with ads7845, it is okay now. I'll submit the corrected patch shortly.

Thanks,
Anatolij

#6 lore raw

PATCH 1/1 Input: ads7846 - do not allow altering platform data

In reply to Dmitry Torokhov

From: Dmitry Torokhov <[email protected]>

---
 drivers/input/touchscreen/ads7846.c |   35 +++++++++++++++++++----------------
 include/linux/spi/ads7846.h         |    2 +-
 2 files changed, 20 insertions(+), 17 deletions(-)
drivers/input/touchscreen/ads7846.c +19 -16
index 8ab90dd..82290ff 100644
@@ -942,14 +942,15 @@ static int __devinit setup_pendown(struct spi_device *spi, struct ads7846 *ts)
 
 static int __devinit ads7846_probe(struct spi_device *spi)
 {
-	struct ads7846			*ts;
-	struct ads7846_packet		*packet;
-	struct input_dev		*input_dev;
-	struct ads7846_platform_data	*pdata = spi->dev.platform_data;
-	struct spi_message		*m;
-	struct spi_transfer		*x;
-	int				vref;
-	int				err;
+	struct ads7846 *ts;
+	struct ads7846_packet *packet;
+	struct input_dev *input_dev;
+	const struct ads7846_platform_data *pdata = spi->dev.platform_data;
+	struct spi_message *m;
+	struct spi_transfer *x;
+	unsigned long irq_flags;
+	int vref;
+	int err;
 
 	if (!spi->irq) {
 		dev_dbg(&spi->dev, "no IRQ?\n");
@@ -1269,20 +1270,22 @@ static int __devinit ads7846_probe(struct spi_device *spi)
 		goto err_put_regulator;
 	}
 
-	if (!pdata->irq_flags)
-		pdata->irq_flags = IRQF_TRIGGER_FALLING;
+	irq_flags = pdata->irq_flags ? : IRQF_TRIGGER_FALLING;
 
-	if (request_irq(spi->irq, ads7846_irq, pdata->irq_flags,
-			spi->dev.driver->name, ts)) {
+	err = request_irq(spi->irq, ads7846_irq, irq_flags,
+			  spi->dev.driver->name, ts);
+
+	if (err && !pdata->irq_flags) {
 		dev_info(&spi->dev,
 			"trying pin change workaround on irq %d\n", spi->irq);
 		err = request_irq(spi->irq, ads7846_irq,
 				  IRQF_TRIGGER_FALLING | IRQF_TRIGGER_RISING,
 				  spi->dev.driver->name, ts);
-		if (err) {
-			dev_dbg(&spi->dev, "irq %d busy?\n", spi->irq);
-			goto err_disable_regulator;
-		}
+	}
+
+	if (err) {
+		dev_dbg(&spi->dev, "irq %d busy?\n", spi->irq);
+		goto err_disable_regulator;
 	}
 
 	err = ads784x_hwmon_register(spi, ts);
include/linux/spi/ads7846.h +1 -1
index 95d36bf..92bd083 100644
@@ -48,7 +48,7 @@ struct ads7846_platform_data {
 					 * state if get_pendown_state == NULL
 					 */
 	int	(*get_pendown_state)(void);
-	int	(*filter_init)	(struct ads7846_platform_data *pdata,
+	int	(*filter_init)	(const struct ads7846_platform_data *pdata,
 				 void **filter_data);
 	int	(*filter)	(void *filter_data, int data_idx, int *val);
 	void	(*filter_cleanup)(void *filter_data);
Signature · 1 line
1.7.0.4
#8 lore raw
In reply to Anatolij Gustschin

Hi Dmitry,

Quoted 4 lines · On Fri, 30 Apr 2010 14:23:00 +0200 Anatolij Gustschin <[email protected]> wrote:

On some platforms, for example with GPIO interrupts on mpc5121, it is not possible to configure falling edge interrupts.

Quoted 8 lines

Specifying irq trigger type in platform data structure allows using ads7846 driver on such platforms.

---
 drivers/input/touchscreen/ads7846.c |    5 ++++-
 include/linux/spi/ads7846.h         |    1 +
 2 files changed, 5 insertions(+), 1 deletions(-)

Any comments on these patches?

Thanks,
Anatolij

#9 lore raw
Quoted 12 lines · On Mon, 31 May 2010 21:28:20 +0200 Anatolij Gustschin <[email protected]> wrote:

Hi Dmitry,

Quoted 7 lines · On Fri, 30 Apr 2010 14:23:00 +0200 Anatolij Gustschin <[email protected]> wrote:

On some platforms, for example with GPIO interrupts on mpc5121, it is not possible to configure falling edge interrupts.

Specifying irq trigger type in platform data structure allows using ads7846 driver on such platforms.

Quoted 7 lines
Quoted 5 lines
---
 drivers/input/touchscreen/ads7846.c |    5 ++++-
 include/linux/spi/ads7846.h         |    1 +
 2 files changed, 5 insertions(+), 1 deletions(-)

Any comments on these patches?

Ping? The patches still apply on top of the input.git/next branch.

Thanks,
Anatolij

maintainer Applied
#10 lore raw
Quoted 21 lines · Anatolij Gustschin
Quoted 18 lines · On Mon, 31 May 2010 21:28:20 +0200 Anatolij Gustschin <[email protected]> wrote:

Hi Dmitry,

Quoted 12 lines · On Fri, 30 Apr 2010 14:23:00 +0200 Anatolij Gustschin <[email protected]> wrote:

On some platforms, for example with GPIO interrupts on mpc5121, it is not possible to configure falling edge interrupts.

Specifying irq trigger type in platform data structure allows using ads7846 driver on such platforms.

---
 drivers/input/touchscreen/ads7846.c |    5 ++++-
 include/linux/spi/ads7846.h         |    1 +
 2 files changed, 5 insertions(+), 1 deletions(-)
Quoted 4 lines
Quoted 1 line

Any comments on these patches?

Ping? The patches still apply on top of the input.git/next branch.

I applied the first one (however changed irq_trigger to be unsigned long) however I'd like better changelog for 7845 changes.

Thanks.

Signature · 1 line
Dmitry
#11 lore raw
Quoted 22 lines · On Mon, 28 Jun 2010 01:32:08 -0700 Dmitry Torokhov <[email protected]>…
Quoted 21 lines · Anatolij Gustschin
Quoted 18 lines · On Mon, 31 May 2010 21:28:20 +0200 Anatolij Gustschin <[email protected]> wrote:

Hi Dmitry,

Quoted 12 lines · On Fri, 30 Apr 2010 14:23:00 +0200 Anatolij Gustschin <[email protected]> wrote:

On some platforms, for example with GPIO interrupts on mpc5121, it is not possible to configure falling edge interrupts.

Specifying irq trigger type in platform data structure allows using ads7846 driver on such platforms.

---
 drivers/input/touchscreen/ads7846.c |    5 ++++-
 include/linux/spi/ads7846.h         |    1 +
 2 files changed, 5 insertions(+), 1 deletions(-)
Quoted 7 lines
Quoted 4 lines
Quoted 1 line

Any comments on these patches?

Ping? The patches still apply on top of the input.git/next branch.

I applied the first one (however changed irq_trigger to be unsigned long) however I'd like better changelog for 7845 changes.

Thanks. I'll submit v2 patch for 7845 changes with a better changelog soon.

Anatolij