All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] input: touchscreen: add OF match table for ads7846
@ 2011-06-14  1:45 Barry Song
  2011-06-14  6:15 ` Thomas Chou
  0 siblings, 1 reply; 5+ messages in thread
From: Barry Song @ 2011-06-14  1:45 UTC (permalink / raw)
  To: dmitry.torokhov
  Cc: linux-input, DL-SHA-APBULinux, junyi.zhang, Barry Song,
	Thomas Chou

The current ads7846 has no OF match table. The method used is by applying a heuristic (of_modalias_node) which tries to name the device in a way that will match an existing device driver.
This patch adds explicit OF match table for ads7846, then the normal device tree match behaviour will always work.
It has been tested on PRIMA2 EVB board of CSR with a SPI's child node like the below:
ts@0 {
        compatible = "ti,ads7845";
        reg = <0x0>;
        spi-max-frequency = <31250>;
        interrupts = <90>;
};

Signed-off-by: Barry Song <Baohua.Song@csr.com>
Cc: Thomas Chou <thomas@wytron.com.tw>
Acked-by: Grant Likely <grant.likely@secretlab.ca>
---
 .../devicetree/bindings/input/ads7846.txt          |   20 ++++++++++++++++++++
 drivers/input/touchscreen/ads7846.c                |   14 ++++++++++++++
 2 files changed, 34 insertions(+), 0 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/input/ads7846.txt

diff --git a/Documentation/devicetree/bindings/input/ads7846.txt b/Documentation/devicetree/bindings/input/ads7846.txt
new file mode 100644
index 0000000..36c1fd0
--- /dev/null
+++ b/Documentation/devicetree/bindings/input/ads7846.txt
@@ -0,0 +1,20 @@
+ADS7846/ADS7845/ADS7843 touchscreen connected to a SPI bus
+
+Required properties:
+- compatible : should be "ti,ads7846", "ti,ads7845" or "ti,ads7843"
+- reg : should specify SPI address (chip-select number).
+- spi-max-frequency : maximum frequency for this device (Hz).
+- interrupts : the interrupt of pendown.
+
+Optional properties:
+- interrupt-parent : the phandle for the interrupt controller that
+  services interrupts for this device.
+
+Example:
+
+	ts@0 {
+		compatible = "ti,ads7845",
+		reg = <0>;
+		spi-max-frequency = <31250>;
+		interrupts = <90>;
+	};
diff --git a/drivers/input/touchscreen/ads7846.c b/drivers/input/touchscreen/ads7846.c
index 5196861..fa9345c 100644
--- a/drivers/input/touchscreen/ads7846.c
+++ b/drivers/input/touchscreen/ads7846.c
@@ -28,6 +28,7 @@
 #include <linux/slab.h>
 #include <linux/pm.h>
 #include <linux/gpio.h>
+#include <linux/of.h>
 #include <linux/spi/spi.h>
 #include <linux/spi/ads7846.h>
 #include <linux/regulator/consumer.h>
@@ -1425,12 +1426,25 @@ static int __devexit ads7846_remove(struct spi_device *spi)
 	return 0;
 }
 
+#if defined(CONFIG_OF)
+static struct of_device_id ads7846_spi_of_match_table[] __devinitdata = {
+	{ .compatible = "ti,ads7846", },
+	{ .compatible = "ti,ads7845", },
+	{ .compatible = "ti,ads7843", },
+	{},
+};
+MODULE_DEVICE_TABLE(of, ads7846_spi_of_match_table);
+#else
+#define ads7846_spi_of_match_table NULL
+#endif
+
 static struct spi_driver ads7846_driver = {
 	.driver = {
 		.name	= "ads7846",
 		.bus	= &spi_bus_type,
 		.owner	= THIS_MODULE,
 		.pm	= &ads7846_pm,
+		.of_match_table = ads7846_spi_of_match_table,
 	},
 	.probe		= ads7846_probe,
 	.remove		= __devexit_p(ads7846_remove),
-- 
1.7.1



Member of the CSR plc group of companies. CSR plc registered in England and Wales, registered number 4187346, registered office Churchill House, Cambridge Business Park, Cowley Road, Cambridge, CB4 0WZ, United Kingdom
More information can be found at www.csr.com. Follow CSR on Twitter at http://twitter.com/CSR_PLC and read our blog at www.csr.com/blog

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH v2] input: touchscreen: add OF match table for ads7846
  2011-06-14  1:45 [PATCH v2] input: touchscreen: add OF match table for ads7846 Barry Song
@ 2011-06-14  6:15 ` Thomas Chou
  2011-06-14  6:38   ` Baohua Song
  0 siblings, 1 reply; 5+ messages in thread
From: Thomas Chou @ 2011-06-14  6:15 UTC (permalink / raw)
  To: Barry Song
  Cc: dmitry.torokhov, linux-input, DL-SHA-APBULinux, junyi.zhang,
	Grant Likely

On 06/14/2011 09:45 AM, Barry Song wrote:
> The current ads7846 has no OF match table. The method used is by applying a heuristic (of_modalias_node) which tries to name the device in a way that will match an existing device driver.
> This patch adds explicit OF match table for ads7846, then the normal device tree match behaviour will always work.
> It has been tested on PRIMA2 EVB board of CSR with a SPI's child node like the below:
> ts@0 {
>          compatible = "ti,ads7845";
>          reg =<0x0>;
>          spi-max-frequency =<31250>;
>          interrupts =<90>;
> };
>

Hi Barry,

Thank you very much for your help. Could we add an option for gpio 
pendown, like this?

- gpios : should specify GPIO used for pendown.

If interrupt node is not present in this node, gpio_to_irq of the pen
down GPIO will be used.

Best regards,
Thomas

^ permalink raw reply	[flat|nested] 5+ messages in thread

* RE: [PATCH v2] input: touchscreen: add OF match table for ads7846
  2011-06-14  6:15 ` Thomas Chou
@ 2011-06-14  6:38   ` Baohua Song
  2011-06-15  4:01     ` Thomas Chou
  0 siblings, 1 reply; 5+ messages in thread
From: Baohua Song @ 2011-06-14  6:38 UTC (permalink / raw)
  To: Thomas Chou
  Cc: dmitry.torokhov@gmail.com, linux-input@vger.kernel.org,
	DL-SHA-APBU Linux, Junyi Zhang, Grant Likely

Hi Thomas,
Thanks.

> -----Original Message-----
> From: Thomas Chou [mailto:thomas@wytron.com.tw]
> Sent: 2011年6月14日 14:15
> To: Baohua Song
> Cc: dmitry.torokhov@gmail.com; linux-input@vger.kernel.org; DL-SHA-APBU
> Linux; Junyi Zhang; Grant Likely
> Subject: Re: [PATCH v2] input: touchscreen: add OF match table for ads7846
> 
> On 06/14/2011 09:45 AM, Barry Song wrote:
> > The current ads7846 has no OF match table. The method used is by applying a
> heuristic (of_modalias_node) which tries to name the device in a way that will
> match an existing device driver.
> > This patch adds explicit OF match table for ads7846, then the normal device
> tree match behaviour will always work.
> > It has been tested on PRIMA2 EVB board of CSR with a SPI's child node like
> the below:
> > ts@0 {
> >          compatible = "ti,ads7845";
> >          reg =<0x0>;
> >          spi-max-frequency =<31250>;
> >          interrupts =<90>;
> > };
> >
> 
> Hi Barry,
> 
> Thank you very much for your help. 

You are welcome :-)

>Could we add an option for gpio
> pendown, like this?
> 
> - gpios : should specify GPIO used for pendown.
> 
> If interrupt node is not present in this node, gpio_to_irq of the pen
> down GPIO will be used.

I disagree... An optional gpio node doesn't make sense here. The result of gpio_to_irq is still an interrupt, then we can place the result in interrupt node.
And the ads7846 driver required an interrupt node but not a gpio node since we don't find any of_get_gpio() in this driver. 
BTW, it even doesn’t make sense to call function gpio_to_irq in a driver like ads7846. on the contrary, drivers/input/keyboard/gpio_keys.c is really an good user of gpio_to_irq.

> 
> Best regards,
> Thomas

-barry


Member of the CSR plc group of companies. CSR plc registered in England and Wales, registered number 4187346, registered office Churchill House, Cambridge Business Park, Cowley Road, Cambridge, CB4 0WZ, United Kingdom
More information can be found at www.csr.com. Follow CSR on Twitter at http://twitter.com/CSR_PLC and read our blog at www.csr.com/blog

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v2] input: touchscreen: add OF match table for ads7846
  2011-06-14  6:38   ` Baohua Song
@ 2011-06-15  4:01     ` Thomas Chou
  2011-06-15  5:20       ` Baohua Song
  0 siblings, 1 reply; 5+ messages in thread
From: Thomas Chou @ 2011-06-15  4:01 UTC (permalink / raw)
  To: Baohua Song
  Cc: dmitry.torokhov@gmail.com, linux-input@vger.kernel.org,
	DL-SHA-APBU Linux, Junyi Zhang, Grant Likely

On 06/14/2011 02:38 PM, Baohua Song wrote:
>> Could we add an option for gpio
>> pendown, like this?
>>
>> - gpios : should specify GPIO used for pendown.
>>
>> If interrupt node is not present in this node, gpio_to_irq of the pen
>> down GPIO will be used.
> 
> I disagree... An optional gpio node doesn't make sense here. The result of gpio_to_irq is still an interrupt, then we can place the result in interrupt node.
> And the ads7846 driver required an interrupt node but not a gpio node since we don't find any of_get_gpio() in this driver.
> BTW, it even doesn’t make sense to call function gpio_to_irq in a driver like ads7846. on the contrary, drivers/input/keyboard/gpio_keys.c is really an good user of gpio_to_irq.

Hi Barry,

The classical platform data is seldom used when device tree is passed.
So it would be better to disable platform data passing to verify device
tree support.

Without platform data passing, we don't have pdata and
pdata->get_pendown_state func for ads7846_setup_pendown(). The
ads7846_probe() will need updates on this.

Passing gpio for pendown might be a possible solution, as device tree
supports "gpios" node. We could use of_get_gpio_flags() to retrieve it.

I sent an earlier work of mine on this back in Feb. to you.

Best regards,
Thomas

--
To unsubscribe from this list: send the line "unsubscribe linux-input" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 5+ messages in thread

* RE: [PATCH v2] input: touchscreen: add OF match table for ads7846
  2011-06-15  4:01     ` Thomas Chou
@ 2011-06-15  5:20       ` Baohua Song
  0 siblings, 0 replies; 5+ messages in thread
From: Baohua Song @ 2011-06-15  5:20 UTC (permalink / raw)
  To: Thomas Chou
  Cc: dmitry.torokhov@gmail.com, linux-input@vger.kernel.org,
	DL-SHA-APBU Linux, Junyi Zhang, Grant Likely

Hi Thomas,

> -----Original Message-----
> From: linux-input-owner@vger.kernel.org
> [mailto:linux-input-owner@vger.kernel.org] On Behalf Of Thomas Chou
> Sent: 2011年6月15日 12:02
> To: Baohua Song
> Cc: dmitry.torokhov@gmail.com; linux-input@vger.kernel.org; DL-SHA-APBU
> Linux; Junyi Zhang; Grant Likely
> Subject: Re: [PATCH v2] input: touchscreen: add OF match table for ads7846
> 
> On 06/14/2011 02:38 PM, Baohua Song wrote:
> >> Could we add an option for gpio
> >> pendown, like this?
> >>
> >> - gpios : should specify GPIO used for pendown.
> >>
> >> If interrupt node is not present in this node, gpio_to_irq of the pen
> >> down GPIO will be used.
> >
> > I disagree... An optional gpio node doesn't make sense here. The result of
> gpio_to_irq is still an interrupt, then we can place the result in interrupt node.
> > And the ads7846 driver required an interrupt node but not a gpio node since
> we don't find any of_get_gpio() in this driver.
> > BTW, it even doesn’t make sense to call function gpio_to_irq in a driver like
> ads7846. on the contrary, drivers/input/keyboard/gpio_keys.c is really an good
> user of gpio_to_irq.
> 
> Hi Barry,
> 
> The classical platform data is seldom used when device tree is passed.
> So it would be better to disable platform data passing to verify device
> tree support.
> 
> Without platform data passing, we don't have pdata and
> pdata->get_pendown_state func for ads7846_setup_pendown(). The
> ads7846_probe() will need updates on this.

Now the pdata has many fields and several hardware-special callback functions. Non-callback fields can be OF property but callbacks are difficult to be handled in DT. 
So for the moment, we use notifier_block to set pdata in board file as below

static int prima2_touchscreen_notifier_call(struct notifier_block *nb,
                                        unsigned long event, void *__dev)
{
        struct device *dev = __dev;
        struct spi_device *spi = to_spi_device(dev);

        if ((event == BUS_NOTIFY_ADD_DEVICE) &&
            of_device_is_compatible(dev->of_node, "ti,ads7845")) {
                spi->controller_data = &ads7845_ctrldata;
                dev->platform_data = &prima2_ads7845_pdata;
                return NOTIFY_OK;
        }   
        return NOTIFY_DONE;
}

static struct notifier_block prima2_touchscreen_nb = { 
        .notifier_call = prima2_touchscreen_notifier_call,
};

static void __init prima2_touchscreen_init(void)
{
        bus_register_notifier(&spi_bus_type, &prima2_touchscreen_nb);
}

> 
> Passing gpio for pendown might be a possible solution, as device tree
> supports "gpios" node. We could use of_get_gpio_flags() to retrieve it.

Yes. Since ads7846 must read pendown gpio to get pendown status, gpio is necessary to ads7846 and interrupt is probably repeated copy of gpio since we can get it by gpio_to_irq().
gpio field in pdata may be deleted and moved to DT. that can be another patch after this one is merged. I maybe send it later

> 
> I sent an earlier work of mine on this back in Feb. to you.
> 
> Best regards,
> Thomas
-barry



Member of the CSR plc group of companies. CSR plc registered in England and Wales, registered number 4187346, registered office Churchill House, Cambridge Business Park, Cowley Road, Cambridge, CB4 0WZ, United Kingdom
More information can be found at www.csr.com. Follow CSR on Twitter at http://twitter.com/CSR_PLC and read our blog at www.csr.com/blog

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2011-06-15  5:21 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-06-14  1:45 [PATCH v2] input: touchscreen: add OF match table for ads7846 Barry Song
2011-06-14  6:15 ` Thomas Chou
2011-06-14  6:38   ` Baohua Song
2011-06-15  4:01     ` Thomas Chou
2011-06-15  5:20       ` Baohua Song

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.