All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/2] Input: sun4i-ts: Support touchpanel controller on A31
@ 2015-01-24 14:33 ` Chen-Yu Tsai
  0 siblings, 0 replies; 10+ messages in thread
From: Chen-Yu Tsai @ 2015-01-24 14:33 UTC (permalink / raw)
  To: Dmitry Torokhov, Maxime Ripard
  Cc: Chen-Yu Tsai, linux-input, linux-arm-kernel, Hans de Goede,
	Sugar, Meng Zhang

Hi everyone,

As part of my work to get cpufreq working, this series adds support for the
resistive touch panel controller on A31. It is the same hardware as on older
SoCs, with a few register bits shifted, and a different temperature curve.
I've matched the rest of the registers, and they all seem to fit.

As I do not have a resistive touch screen, I am asking anyone with an A31
board and a touch screen to help test this.

The temperature curve formula was confirmed by Allwinner as correct and
working.

I've yet to fully test the remaining cpufreq bits, so I'm sending out this
first. At least people will have a usable temperature sensor.


Regards,
ChenYu


Chen-Yu Tsai (2):
  Input: sun4i-ts: Add support for touchpanel controller on A31
  ARM: dts: sun6i: Add resistive touchscreen controller node to dtsi

 .../bindings/input/touchscreen/sun4i.txt           |  2 +-
 arch/arm/boot/dts/sun6i-a31.dtsi                   |  7 ++++
 drivers/input/touchscreen/sun4i-ts.c               | 46 ++++++++++++++++------
 3 files changed, 41 insertions(+), 14 deletions(-)

-- 
2.1.4


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

* [PATCH 0/2] Input: sun4i-ts: Support touchpanel controller on A31
@ 2015-01-24 14:33 ` Chen-Yu Tsai
  0 siblings, 0 replies; 10+ messages in thread
From: Chen-Yu Tsai @ 2015-01-24 14:33 UTC (permalink / raw)
  To: linux-arm-kernel

Hi everyone,

As part of my work to get cpufreq working, this series adds support for the
resistive touch panel controller on A31. It is the same hardware as on older
SoCs, with a few register bits shifted, and a different temperature curve.
I've matched the rest of the registers, and they all seem to fit.

As I do not have a resistive touch screen, I am asking anyone with an A31
board and a touch screen to help test this.

The temperature curve formula was confirmed by Allwinner as correct and
working.

I've yet to fully test the remaining cpufreq bits, so I'm sending out this
first. At least people will have a usable temperature sensor.


Regards,
ChenYu


Chen-Yu Tsai (2):
  Input: sun4i-ts: Add support for touchpanel controller on A31
  ARM: dts: sun6i: Add resistive touchscreen controller node to dtsi

 .../bindings/input/touchscreen/sun4i.txt           |  2 +-
 arch/arm/boot/dts/sun6i-a31.dtsi                   |  7 ++++
 drivers/input/touchscreen/sun4i-ts.c               | 46 ++++++++++++++++------
 3 files changed, 41 insertions(+), 14 deletions(-)

-- 
2.1.4

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

* [PATCH 1/2] Input: sun4i-ts: Add support for touchpanel controller on A31
  2015-01-24 14:33 ` Chen-Yu Tsai
@ 2015-01-24 14:33   ` Chen-Yu Tsai
  -1 siblings, 0 replies; 10+ messages in thread
From: Chen-Yu Tsai @ 2015-01-24 14:33 UTC (permalink / raw)
  To: Dmitry Torokhov, Maxime Ripard
  Cc: Chen-Yu Tsai, linux-input, linux-arm-kernel, Hans de Goede,
	Sugar, Meng Zhang

The Allwinner A31 SoC (sun6i) has the same resistive touchpanel
controller as on other sunxi platforms. The only difference between
the variants is the control bits for enabling operations are
left-shifted by 1 on the A31.

This patch adds support for this variant.

Also update the comment for the original temperature sensor with
information from Allwinner.

Signed-off-by: Chen-Yu Tsai <wens@csie.org>
---
 .../bindings/input/touchscreen/sun4i.txt           |  2 +-
 drivers/input/touchscreen/sun4i-ts.c               | 46 ++++++++++++++++------
 2 files changed, 34 insertions(+), 14 deletions(-)

diff --git a/Documentation/devicetree/bindings/input/touchscreen/sun4i.txt b/Documentation/devicetree/bindings/input/touchscreen/sun4i.txt
index a8405bab6c00..433332d3b2ba 100644
--- a/Documentation/devicetree/bindings/input/touchscreen/sun4i.txt
+++ b/Documentation/devicetree/bindings/input/touchscreen/sun4i.txt
@@ -2,7 +2,7 @@ sun4i resistive touchscreen controller
 --------------------------------------
 
 Required properties:
- - compatible: "allwinner,sun4i-a10-ts"
+ - compatible: "allwinner,sun4i-a10-ts" or "allwinner,sun6i-a31-ts"
  - reg: mmio address range of the chip
  - interrupts: interrupt to which the chip is connected
  - #thermal-sensor-cells: shall be 0
diff --git a/drivers/input/touchscreen/sun4i-ts.c b/drivers/input/touchscreen/sun4i-ts.c
index 9ae53d4289fb..b93a28b955fd 100644
--- a/drivers/input/touchscreen/sun4i-ts.c
+++ b/drivers/input/touchscreen/sun4i-ts.c
@@ -72,6 +72,9 @@
 #define TP_ADC_SELECT(x)	((x) << 3)
 #define ADC_CHAN_SELECT(x)	((x) << 0)  /* 3 bits */
 
+/* on sun6i, bits 3~6 are left shifted by 1 to 4~7 */
+#define SUN6I_TP_MODE_EN(x)	((x) << 5)
+
 /* TP_CTRL2 bits */
 #define TP_SENSITIVE_ADJUST(x)	((x) << 28) /* 4 bits */
 #define TP_MODE_SELECT(x)	((x) << 26) /* 2 bits */
@@ -113,6 +116,8 @@ struct sun4i_ts_data {
 	unsigned int irq;
 	bool ignore_fifo_data;
 	int temp_data;
+	int temp_offset;
+	int temp_step;
 };
 
 static void sun4i_ts_irq_handle_input(struct sun4i_ts_data *ts, u32 reg_val)
@@ -188,17 +193,7 @@ static int sun4i_get_temp(const struct sun4i_ts_data *ts, long *temp)
 	if (ts->temp_data == -1)
 		return -EAGAIN;
 
-	/*
-	 * The user manuals do not contain the formula for calculating
-	 * the temperature. The formula used here is from the AXP209,
-	 * which is designed by X-Powers, an affiliate of Allwinner:
-	 *
-	 *     temperature = -144.7 + (value * 0.1)
-	 *
-	 * This should be replaced with the correct one if such information
-	 * becomes available.
-	 */
-	*temp = (ts->temp_data - 1447) * 100;
+	*temp = (ts->temp_data - ts->temp_offset) * ts->temp_step;
 
 	return 0;
 }
@@ -249,6 +244,7 @@ static int sun4i_ts_probe(struct platform_device *pdev)
 	struct device_node *np = dev->of_node;
 	struct device *hwmon;
 	int error;
+	u32 reg;
 	bool ts_attached;
 
 	ts = devm_kzalloc(dev, sizeof(struct sun4i_ts_data), GFP_KERNEL);
@@ -258,6 +254,25 @@ static int sun4i_ts_probe(struct platform_device *pdev)
 	ts->dev = dev;
 	ts->ignore_fifo_data = true;
 	ts->temp_data = -1;
+	if (of_device_is_compatible(np, "allwinner,sun6i-a31-ts")) {
+		/* Allwinner SDK has temperature = -271 + (value / 6) (C) */
+		ts->temp_offset = 1626;
+		ts->temp_step = 167;
+	} else {
+		/*
+		 * The user manuals do not contain the formula for calculating
+		 * the temperature. The formula used here is from the AXP209,
+		 * which is designed by X-Powers, an affiliate of Allwinner:
+		 *
+		 *     temperature = -144.7 + (value * 0.1)
+		 *
+		 * Allwinner does not have any documentation whatsoever for
+		 * this hardware. Moreover, it is claimed that the sensor
+		 * is inaccurate and cannot work properly.
+		 */
+		ts->temp_offset = 1447;
+		ts->temp_step = 100;
+	}
 
 	ts_attached = of_property_read_bool(np, "allwinner,ts-attached");
 	if (ts_attached) {
@@ -314,8 +329,12 @@ static int sun4i_ts_probe(struct platform_device *pdev)
 	 * Set stylus up debounce to aprox 10 ms, enable debounce, and
 	 * finally enable tp mode.
 	 */
-	writel(STYLUS_UP_DEBOUN(5) | STYLUS_UP_DEBOUN_EN(1) | TP_MODE_EN(1),
-	       ts->base + TP_CTRL1);
+	reg = STYLUS_UP_DEBOUN(5) | STYLUS_UP_DEBOUN_EN(1);
+	if (of_device_is_compatible(np, "allwinner,sun4i-a10-ts"))
+		reg |= TP_MODE_EN(1);
+	else
+		reg |= SUN6I_TP_MODE_EN(1);
+	writel(reg, ts->base + TP_CTRL1);
 
 	/*
 	 * The thermal core does not register hwmon devices for DT-based
@@ -364,6 +383,7 @@ static int sun4i_ts_remove(struct platform_device *pdev)
 
 static const struct of_device_id sun4i_ts_of_match[] = {
 	{ .compatible = "allwinner,sun4i-a10-ts", },
+	{ .compatible = "allwinner,sun6i-a31-ts", },
 	{ /* sentinel */ }
 };
 MODULE_DEVICE_TABLE(of, sun4i_ts_of_match);
-- 
2.1.4


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

* [PATCH 1/2] Input: sun4i-ts: Add support for touchpanel controller on A31
@ 2015-01-24 14:33   ` Chen-Yu Tsai
  0 siblings, 0 replies; 10+ messages in thread
From: Chen-Yu Tsai @ 2015-01-24 14:33 UTC (permalink / raw)
  To: linux-arm-kernel

The Allwinner A31 SoC (sun6i) has the same resistive touchpanel
controller as on other sunxi platforms. The only difference between
the variants is the control bits for enabling operations are
left-shifted by 1 on the A31.

This patch adds support for this variant.

Also update the comment for the original temperature sensor with
information from Allwinner.

Signed-off-by: Chen-Yu Tsai <wens@csie.org>
---
 .../bindings/input/touchscreen/sun4i.txt           |  2 +-
 drivers/input/touchscreen/sun4i-ts.c               | 46 ++++++++++++++++------
 2 files changed, 34 insertions(+), 14 deletions(-)

diff --git a/Documentation/devicetree/bindings/input/touchscreen/sun4i.txt b/Documentation/devicetree/bindings/input/touchscreen/sun4i.txt
index a8405bab6c00..433332d3b2ba 100644
--- a/Documentation/devicetree/bindings/input/touchscreen/sun4i.txt
+++ b/Documentation/devicetree/bindings/input/touchscreen/sun4i.txt
@@ -2,7 +2,7 @@ sun4i resistive touchscreen controller
 --------------------------------------
 
 Required properties:
- - compatible: "allwinner,sun4i-a10-ts"
+ - compatible: "allwinner,sun4i-a10-ts" or "allwinner,sun6i-a31-ts"
  - reg: mmio address range of the chip
  - interrupts: interrupt to which the chip is connected
  - #thermal-sensor-cells: shall be 0
diff --git a/drivers/input/touchscreen/sun4i-ts.c b/drivers/input/touchscreen/sun4i-ts.c
index 9ae53d4289fb..b93a28b955fd 100644
--- a/drivers/input/touchscreen/sun4i-ts.c
+++ b/drivers/input/touchscreen/sun4i-ts.c
@@ -72,6 +72,9 @@
 #define TP_ADC_SELECT(x)	((x) << 3)
 #define ADC_CHAN_SELECT(x)	((x) << 0)  /* 3 bits */
 
+/* on sun6i, bits 3~6 are left shifted by 1 to 4~7 */
+#define SUN6I_TP_MODE_EN(x)	((x) << 5)
+
 /* TP_CTRL2 bits */
 #define TP_SENSITIVE_ADJUST(x)	((x) << 28) /* 4 bits */
 #define TP_MODE_SELECT(x)	((x) << 26) /* 2 bits */
@@ -113,6 +116,8 @@ struct sun4i_ts_data {
 	unsigned int irq;
 	bool ignore_fifo_data;
 	int temp_data;
+	int temp_offset;
+	int temp_step;
 };
 
 static void sun4i_ts_irq_handle_input(struct sun4i_ts_data *ts, u32 reg_val)
@@ -188,17 +193,7 @@ static int sun4i_get_temp(const struct sun4i_ts_data *ts, long *temp)
 	if (ts->temp_data == -1)
 		return -EAGAIN;
 
-	/*
-	 * The user manuals do not contain the formula for calculating
-	 * the temperature. The formula used here is from the AXP209,
-	 * which is designed by X-Powers, an affiliate of Allwinner:
-	 *
-	 *     temperature = -144.7 + (value * 0.1)
-	 *
-	 * This should be replaced with the correct one if such information
-	 * becomes available.
-	 */
-	*temp = (ts->temp_data - 1447) * 100;
+	*temp = (ts->temp_data - ts->temp_offset) * ts->temp_step;
 
 	return 0;
 }
@@ -249,6 +244,7 @@ static int sun4i_ts_probe(struct platform_device *pdev)
 	struct device_node *np = dev->of_node;
 	struct device *hwmon;
 	int error;
+	u32 reg;
 	bool ts_attached;
 
 	ts = devm_kzalloc(dev, sizeof(struct sun4i_ts_data), GFP_KERNEL);
@@ -258,6 +254,25 @@ static int sun4i_ts_probe(struct platform_device *pdev)
 	ts->dev = dev;
 	ts->ignore_fifo_data = true;
 	ts->temp_data = -1;
+	if (of_device_is_compatible(np, "allwinner,sun6i-a31-ts")) {
+		/* Allwinner SDK has temperature = -271 + (value / 6) (C) */
+		ts->temp_offset = 1626;
+		ts->temp_step = 167;
+	} else {
+		/*
+		 * The user manuals do not contain the formula for calculating
+		 * the temperature. The formula used here is from the AXP209,
+		 * which is designed by X-Powers, an affiliate of Allwinner:
+		 *
+		 *     temperature = -144.7 + (value * 0.1)
+		 *
+		 * Allwinner does not have any documentation whatsoever for
+		 * this hardware. Moreover, it is claimed that the sensor
+		 * is inaccurate and cannot work properly.
+		 */
+		ts->temp_offset = 1447;
+		ts->temp_step = 100;
+	}
 
 	ts_attached = of_property_read_bool(np, "allwinner,ts-attached");
 	if (ts_attached) {
@@ -314,8 +329,12 @@ static int sun4i_ts_probe(struct platform_device *pdev)
 	 * Set stylus up debounce to aprox 10 ms, enable debounce, and
 	 * finally enable tp mode.
 	 */
-	writel(STYLUS_UP_DEBOUN(5) | STYLUS_UP_DEBOUN_EN(1) | TP_MODE_EN(1),
-	       ts->base + TP_CTRL1);
+	reg = STYLUS_UP_DEBOUN(5) | STYLUS_UP_DEBOUN_EN(1);
+	if (of_device_is_compatible(np, "allwinner,sun4i-a10-ts"))
+		reg |= TP_MODE_EN(1);
+	else
+		reg |= SUN6I_TP_MODE_EN(1);
+	writel(reg, ts->base + TP_CTRL1);
 
 	/*
 	 * The thermal core does not register hwmon devices for DT-based
@@ -364,6 +383,7 @@ static int sun4i_ts_remove(struct platform_device *pdev)
 
 static const struct of_device_id sun4i_ts_of_match[] = {
 	{ .compatible = "allwinner,sun4i-a10-ts", },
+	{ .compatible = "allwinner,sun6i-a31-ts", },
 	{ /* sentinel */ }
 };
 MODULE_DEVICE_TABLE(of, sun4i_ts_of_match);
-- 
2.1.4

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

* [PATCH 2/2] ARM: dts: sun6i: Add resistive touchscreen controller node to dtsi
  2015-01-24 14:33 ` Chen-Yu Tsai
@ 2015-01-24 14:33   ` Chen-Yu Tsai
  -1 siblings, 0 replies; 10+ messages in thread
From: Chen-Yu Tsai @ 2015-01-24 14:33 UTC (permalink / raw)
  To: Dmitry Torokhov, Maxime Ripard
  Cc: Chen-Yu Tsai, linux-input, linux-arm-kernel, Hans de Goede,
	Sugar, Meng Zhang

Now that we support the sun6i variant of the touchscreen controller,
add the device node to the dtsi so we can use it.

Signed-off-by: Chen-Yu Tsai <wens@csie.org>
---
 arch/arm/boot/dts/sun6i-a31.dtsi | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/arch/arm/boot/dts/sun6i-a31.dtsi b/arch/arm/boot/dts/sun6i-a31.dtsi
index 188f59e558bc..ec70454b0add 100644
--- a/arch/arm/boot/dts/sun6i-a31.dtsi
+++ b/arch/arm/boot/dts/sun6i-a31.dtsi
@@ -664,6 +664,13 @@
 			reg = <0x01c20ca0 0x20>;
 		};
 
+		rtp: rtp@01c25000 {
+			compatible = "allwinner,sun6i-a31-ts";
+			reg = <0x01c25000 0x100>;
+			interrupts = <GIC_SPI 28 IRQ_TYPE_LEVEL_HIGH>;
+			#thermal-sensor-cells = <0>;
+		};
+
 		uart0: serial@01c28000 {
 			compatible = "snps,dw-apb-uart";
 			reg = <0x01c28000 0x400>;
-- 
2.1.4


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

* [PATCH 2/2] ARM: dts: sun6i: Add resistive touchscreen controller node to dtsi
@ 2015-01-24 14:33   ` Chen-Yu Tsai
  0 siblings, 0 replies; 10+ messages in thread
From: Chen-Yu Tsai @ 2015-01-24 14:33 UTC (permalink / raw)
  To: linux-arm-kernel

Now that we support the sun6i variant of the touchscreen controller,
add the device node to the dtsi so we can use it.

Signed-off-by: Chen-Yu Tsai <wens@csie.org>
---
 arch/arm/boot/dts/sun6i-a31.dtsi | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/arch/arm/boot/dts/sun6i-a31.dtsi b/arch/arm/boot/dts/sun6i-a31.dtsi
index 188f59e558bc..ec70454b0add 100644
--- a/arch/arm/boot/dts/sun6i-a31.dtsi
+++ b/arch/arm/boot/dts/sun6i-a31.dtsi
@@ -664,6 +664,13 @@
 			reg = <0x01c20ca0 0x20>;
 		};
 
+		rtp: rtp at 01c25000 {
+			compatible = "allwinner,sun6i-a31-ts";
+			reg = <0x01c25000 0x100>;
+			interrupts = <GIC_SPI 28 IRQ_TYPE_LEVEL_HIGH>;
+			#thermal-sensor-cells = <0>;
+		};
+
 		uart0: serial at 01c28000 {
 			compatible = "snps,dw-apb-uart";
 			reg = <0x01c28000 0x400>;
-- 
2.1.4

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

* Re: [PATCH 2/2] ARM: dts: sun6i: Add resistive touchscreen controller node to dtsi
  2015-01-24 14:33   ` Chen-Yu Tsai
@ 2015-01-24 14:37     ` Maxime Ripard
  -1 siblings, 0 replies; 10+ messages in thread
From: Maxime Ripard @ 2015-01-24 14:37 UTC (permalink / raw)
  To: Chen-Yu Tsai
  Cc: Dmitry Torokhov, linux-input, linux-arm-kernel, Hans de Goede,
	Sugar, Meng Zhang

[-- Attachment #1: Type: text/plain, Size: 382 bytes --]

On Sat, Jan 24, 2015 at 10:33:48PM +0800, Chen-Yu Tsai wrote:
> Now that we support the sun6i variant of the touchscreen controller,
> add the device node to the dtsi so we can use it.
> 
> Signed-off-by: Chen-Yu Tsai <wens@csie.org>

Applied, thanks,

Maxime

-- 
Maxime Ripard, Free Electrons
Embedded Linux, Kernel and Android engineering
http://free-electrons.com

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 819 bytes --]

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

* [PATCH 2/2] ARM: dts: sun6i: Add resistive touchscreen controller node to dtsi
@ 2015-01-24 14:37     ` Maxime Ripard
  0 siblings, 0 replies; 10+ messages in thread
From: Maxime Ripard @ 2015-01-24 14:37 UTC (permalink / raw)
  To: linux-arm-kernel

On Sat, Jan 24, 2015 at 10:33:48PM +0800, Chen-Yu Tsai wrote:
> Now that we support the sun6i variant of the touchscreen controller,
> add the device node to the dtsi so we can use it.
> 
> Signed-off-by: Chen-Yu Tsai <wens@csie.org>

Applied, thanks,

Maxime

-- 
Maxime Ripard, Free Electrons
Embedded Linux, Kernel and Android engineering
http://free-electrons.com
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: Digital signature
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20150124/d89d02be/attachment.sig>

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

* Re: [PATCH 1/2] Input: sun4i-ts: Add support for touchpanel controller on A31
  2015-01-24 14:33   ` Chen-Yu Tsai
@ 2015-01-27  7:59     ` Dmitry Torokhov
  -1 siblings, 0 replies; 10+ messages in thread
From: Dmitry Torokhov @ 2015-01-27  7:59 UTC (permalink / raw)
  To: Chen-Yu Tsai
  Cc: Maxime Ripard, linux-input, linux-arm-kernel, Hans de Goede,
	Sugar, Meng Zhang

On Sat, Jan 24, 2015 at 10:33:47PM +0800, Chen-Yu Tsai wrote:
> The Allwinner A31 SoC (sun6i) has the same resistive touchpanel
> controller as on other sunxi platforms. The only difference between
> the variants is the control bits for enabling operations are
> left-shifted by 1 on the A31.
> 
> This patch adds support for this variant.
> 
> Also update the comment for the original temperature sensor with
> information from Allwinner.
> 
> Signed-off-by: Chen-Yu Tsai <wens@csie.org>

Applied, thank you.

> ---
>  .../bindings/input/touchscreen/sun4i.txt           |  2 +-
>  drivers/input/touchscreen/sun4i-ts.c               | 46 ++++++++++++++++------
>  2 files changed, 34 insertions(+), 14 deletions(-)
> 
> diff --git a/Documentation/devicetree/bindings/input/touchscreen/sun4i.txt b/Documentation/devicetree/bindings/input/touchscreen/sun4i.txt
> index a8405bab6c00..433332d3b2ba 100644
> --- a/Documentation/devicetree/bindings/input/touchscreen/sun4i.txt
> +++ b/Documentation/devicetree/bindings/input/touchscreen/sun4i.txt
> @@ -2,7 +2,7 @@ sun4i resistive touchscreen controller
>  --------------------------------------
>  
>  Required properties:
> - - compatible: "allwinner,sun4i-a10-ts"
> + - compatible: "allwinner,sun4i-a10-ts" or "allwinner,sun6i-a31-ts"
>   - reg: mmio address range of the chip
>   - interrupts: interrupt to which the chip is connected
>   - #thermal-sensor-cells: shall be 0
> diff --git a/drivers/input/touchscreen/sun4i-ts.c b/drivers/input/touchscreen/sun4i-ts.c
> index 9ae53d4289fb..b93a28b955fd 100644
> --- a/drivers/input/touchscreen/sun4i-ts.c
> +++ b/drivers/input/touchscreen/sun4i-ts.c
> @@ -72,6 +72,9 @@
>  #define TP_ADC_SELECT(x)	((x) << 3)
>  #define ADC_CHAN_SELECT(x)	((x) << 0)  /* 3 bits */
>  
> +/* on sun6i, bits 3~6 are left shifted by 1 to 4~7 */
> +#define SUN6I_TP_MODE_EN(x)	((x) << 5)
> +
>  /* TP_CTRL2 bits */
>  #define TP_SENSITIVE_ADJUST(x)	((x) << 28) /* 4 bits */
>  #define TP_MODE_SELECT(x)	((x) << 26) /* 2 bits */
> @@ -113,6 +116,8 @@ struct sun4i_ts_data {
>  	unsigned int irq;
>  	bool ignore_fifo_data;
>  	int temp_data;
> +	int temp_offset;
> +	int temp_step;
>  };
>  
>  static void sun4i_ts_irq_handle_input(struct sun4i_ts_data *ts, u32 reg_val)
> @@ -188,17 +193,7 @@ static int sun4i_get_temp(const struct sun4i_ts_data *ts, long *temp)
>  	if (ts->temp_data == -1)
>  		return -EAGAIN;
>  
> -	/*
> -	 * The user manuals do not contain the formula for calculating
> -	 * the temperature. The formula used here is from the AXP209,
> -	 * which is designed by X-Powers, an affiliate of Allwinner:
> -	 *
> -	 *     temperature = -144.7 + (value * 0.1)
> -	 *
> -	 * This should be replaced with the correct one if such information
> -	 * becomes available.
> -	 */
> -	*temp = (ts->temp_data - 1447) * 100;
> +	*temp = (ts->temp_data - ts->temp_offset) * ts->temp_step;
>  
>  	return 0;
>  }
> @@ -249,6 +244,7 @@ static int sun4i_ts_probe(struct platform_device *pdev)
>  	struct device_node *np = dev->of_node;
>  	struct device *hwmon;
>  	int error;
> +	u32 reg;
>  	bool ts_attached;
>  
>  	ts = devm_kzalloc(dev, sizeof(struct sun4i_ts_data), GFP_KERNEL);
> @@ -258,6 +254,25 @@ static int sun4i_ts_probe(struct platform_device *pdev)
>  	ts->dev = dev;
>  	ts->ignore_fifo_data = true;
>  	ts->temp_data = -1;
> +	if (of_device_is_compatible(np, "allwinner,sun6i-a31-ts")) {
> +		/* Allwinner SDK has temperature = -271 + (value / 6) (C) */
> +		ts->temp_offset = 1626;
> +		ts->temp_step = 167;
> +	} else {
> +		/*
> +		 * The user manuals do not contain the formula for calculating
> +		 * the temperature. The formula used here is from the AXP209,
> +		 * which is designed by X-Powers, an affiliate of Allwinner:
> +		 *
> +		 *     temperature = -144.7 + (value * 0.1)
> +		 *
> +		 * Allwinner does not have any documentation whatsoever for
> +		 * this hardware. Moreover, it is claimed that the sensor
> +		 * is inaccurate and cannot work properly.
> +		 */
> +		ts->temp_offset = 1447;
> +		ts->temp_step = 100;
> +	}
>  
>  	ts_attached = of_property_read_bool(np, "allwinner,ts-attached");
>  	if (ts_attached) {
> @@ -314,8 +329,12 @@ static int sun4i_ts_probe(struct platform_device *pdev)
>  	 * Set stylus up debounce to aprox 10 ms, enable debounce, and
>  	 * finally enable tp mode.
>  	 */
> -	writel(STYLUS_UP_DEBOUN(5) | STYLUS_UP_DEBOUN_EN(1) | TP_MODE_EN(1),
> -	       ts->base + TP_CTRL1);
> +	reg = STYLUS_UP_DEBOUN(5) | STYLUS_UP_DEBOUN_EN(1);
> +	if (of_device_is_compatible(np, "allwinner,sun4i-a10-ts"))
> +		reg |= TP_MODE_EN(1);
> +	else
> +		reg |= SUN6I_TP_MODE_EN(1);
> +	writel(reg, ts->base + TP_CTRL1);
>  
>  	/*
>  	 * The thermal core does not register hwmon devices for DT-based
> @@ -364,6 +383,7 @@ static int sun4i_ts_remove(struct platform_device *pdev)
>  
>  static const struct of_device_id sun4i_ts_of_match[] = {
>  	{ .compatible = "allwinner,sun4i-a10-ts", },
> +	{ .compatible = "allwinner,sun6i-a31-ts", },
>  	{ /* sentinel */ }
>  };
>  MODULE_DEVICE_TABLE(of, sun4i_ts_of_match);
> -- 
> 2.1.4
> 

-- 
Dmitry

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

* [PATCH 1/2] Input: sun4i-ts: Add support for touchpanel controller on A31
@ 2015-01-27  7:59     ` Dmitry Torokhov
  0 siblings, 0 replies; 10+ messages in thread
From: Dmitry Torokhov @ 2015-01-27  7:59 UTC (permalink / raw)
  To: linux-arm-kernel

On Sat, Jan 24, 2015 at 10:33:47PM +0800, Chen-Yu Tsai wrote:
> The Allwinner A31 SoC (sun6i) has the same resistive touchpanel
> controller as on other sunxi platforms. The only difference between
> the variants is the control bits for enabling operations are
> left-shifted by 1 on the A31.
> 
> This patch adds support for this variant.
> 
> Also update the comment for the original temperature sensor with
> information from Allwinner.
> 
> Signed-off-by: Chen-Yu Tsai <wens@csie.org>

Applied, thank you.

> ---
>  .../bindings/input/touchscreen/sun4i.txt           |  2 +-
>  drivers/input/touchscreen/sun4i-ts.c               | 46 ++++++++++++++++------
>  2 files changed, 34 insertions(+), 14 deletions(-)
> 
> diff --git a/Documentation/devicetree/bindings/input/touchscreen/sun4i.txt b/Documentation/devicetree/bindings/input/touchscreen/sun4i.txt
> index a8405bab6c00..433332d3b2ba 100644
> --- a/Documentation/devicetree/bindings/input/touchscreen/sun4i.txt
> +++ b/Documentation/devicetree/bindings/input/touchscreen/sun4i.txt
> @@ -2,7 +2,7 @@ sun4i resistive touchscreen controller
>  --------------------------------------
>  
>  Required properties:
> - - compatible: "allwinner,sun4i-a10-ts"
> + - compatible: "allwinner,sun4i-a10-ts" or "allwinner,sun6i-a31-ts"
>   - reg: mmio address range of the chip
>   - interrupts: interrupt to which the chip is connected
>   - #thermal-sensor-cells: shall be 0
> diff --git a/drivers/input/touchscreen/sun4i-ts.c b/drivers/input/touchscreen/sun4i-ts.c
> index 9ae53d4289fb..b93a28b955fd 100644
> --- a/drivers/input/touchscreen/sun4i-ts.c
> +++ b/drivers/input/touchscreen/sun4i-ts.c
> @@ -72,6 +72,9 @@
>  #define TP_ADC_SELECT(x)	((x) << 3)
>  #define ADC_CHAN_SELECT(x)	((x) << 0)  /* 3 bits */
>  
> +/* on sun6i, bits 3~6 are left shifted by 1 to 4~7 */
> +#define SUN6I_TP_MODE_EN(x)	((x) << 5)
> +
>  /* TP_CTRL2 bits */
>  #define TP_SENSITIVE_ADJUST(x)	((x) << 28) /* 4 bits */
>  #define TP_MODE_SELECT(x)	((x) << 26) /* 2 bits */
> @@ -113,6 +116,8 @@ struct sun4i_ts_data {
>  	unsigned int irq;
>  	bool ignore_fifo_data;
>  	int temp_data;
> +	int temp_offset;
> +	int temp_step;
>  };
>  
>  static void sun4i_ts_irq_handle_input(struct sun4i_ts_data *ts, u32 reg_val)
> @@ -188,17 +193,7 @@ static int sun4i_get_temp(const struct sun4i_ts_data *ts, long *temp)
>  	if (ts->temp_data == -1)
>  		return -EAGAIN;
>  
> -	/*
> -	 * The user manuals do not contain the formula for calculating
> -	 * the temperature. The formula used here is from the AXP209,
> -	 * which is designed by X-Powers, an affiliate of Allwinner:
> -	 *
> -	 *     temperature = -144.7 + (value * 0.1)
> -	 *
> -	 * This should be replaced with the correct one if such information
> -	 * becomes available.
> -	 */
> -	*temp = (ts->temp_data - 1447) * 100;
> +	*temp = (ts->temp_data - ts->temp_offset) * ts->temp_step;
>  
>  	return 0;
>  }
> @@ -249,6 +244,7 @@ static int sun4i_ts_probe(struct platform_device *pdev)
>  	struct device_node *np = dev->of_node;
>  	struct device *hwmon;
>  	int error;
> +	u32 reg;
>  	bool ts_attached;
>  
>  	ts = devm_kzalloc(dev, sizeof(struct sun4i_ts_data), GFP_KERNEL);
> @@ -258,6 +254,25 @@ static int sun4i_ts_probe(struct platform_device *pdev)
>  	ts->dev = dev;
>  	ts->ignore_fifo_data = true;
>  	ts->temp_data = -1;
> +	if (of_device_is_compatible(np, "allwinner,sun6i-a31-ts")) {
> +		/* Allwinner SDK has temperature = -271 + (value / 6) (C) */
> +		ts->temp_offset = 1626;
> +		ts->temp_step = 167;
> +	} else {
> +		/*
> +		 * The user manuals do not contain the formula for calculating
> +		 * the temperature. The formula used here is from the AXP209,
> +		 * which is designed by X-Powers, an affiliate of Allwinner:
> +		 *
> +		 *     temperature = -144.7 + (value * 0.1)
> +		 *
> +		 * Allwinner does not have any documentation whatsoever for
> +		 * this hardware. Moreover, it is claimed that the sensor
> +		 * is inaccurate and cannot work properly.
> +		 */
> +		ts->temp_offset = 1447;
> +		ts->temp_step = 100;
> +	}
>  
>  	ts_attached = of_property_read_bool(np, "allwinner,ts-attached");
>  	if (ts_attached) {
> @@ -314,8 +329,12 @@ static int sun4i_ts_probe(struct platform_device *pdev)
>  	 * Set stylus up debounce to aprox 10 ms, enable debounce, and
>  	 * finally enable tp mode.
>  	 */
> -	writel(STYLUS_UP_DEBOUN(5) | STYLUS_UP_DEBOUN_EN(1) | TP_MODE_EN(1),
> -	       ts->base + TP_CTRL1);
> +	reg = STYLUS_UP_DEBOUN(5) | STYLUS_UP_DEBOUN_EN(1);
> +	if (of_device_is_compatible(np, "allwinner,sun4i-a10-ts"))
> +		reg |= TP_MODE_EN(1);
> +	else
> +		reg |= SUN6I_TP_MODE_EN(1);
> +	writel(reg, ts->base + TP_CTRL1);
>  
>  	/*
>  	 * The thermal core does not register hwmon devices for DT-based
> @@ -364,6 +383,7 @@ static int sun4i_ts_remove(struct platform_device *pdev)
>  
>  static const struct of_device_id sun4i_ts_of_match[] = {
>  	{ .compatible = "allwinner,sun4i-a10-ts", },
> +	{ .compatible = "allwinner,sun6i-a31-ts", },
>  	{ /* sentinel */ }
>  };
>  MODULE_DEVICE_TABLE(of, sun4i_ts_of_match);
> -- 
> 2.1.4
> 

-- 
Dmitry

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

end of thread, other threads:[~2015-01-27  7:59 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-01-24 14:33 [PATCH 0/2] Input: sun4i-ts: Support touchpanel controller on A31 Chen-Yu Tsai
2015-01-24 14:33 ` Chen-Yu Tsai
2015-01-24 14:33 ` [PATCH 1/2] Input: sun4i-ts: Add support for " Chen-Yu Tsai
2015-01-24 14:33   ` Chen-Yu Tsai
2015-01-27  7:59   ` Dmitry Torokhov
2015-01-27  7:59     ` Dmitry Torokhov
2015-01-24 14:33 ` [PATCH 2/2] ARM: dts: sun6i: Add resistive touchscreen controller node to dtsi Chen-Yu Tsai
2015-01-24 14:33   ` Chen-Yu Tsai
2015-01-24 14:37   ` Maxime Ripard
2015-01-24 14:37     ` Maxime Ripard

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.