Skip to content

Commit 4a67afd

Browse files
author
James Hughes
committed
Tidy up of the ft5406 driver to use DT
Driver was using a fixed resolution, this commit adds coordinate size, flip and swap features via device tree. Adds overrides so the VC4 can adjust the DT parameters appropriatley, there is a newer version of the VC4 side driver that can now set up the appropriate DT values if requried.
1 parent c4aadf2 commit 4a67afd

File tree

2 files changed

+68
-14
lines changed

2 files changed

+68
-14
lines changed

arch/arm/boot/dts/overlays/rpi-ft5406-overlay.dts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,20 @@
1111
compatible = "rpi,rpi-ft5406";
1212
firmware = <&firmware>;
1313
status = "okay";
14+
touchscreen-size-x = <800>;
15+
touchscreen-size-y = <600>;
16+
touchscreen-inverted-x = <0>;
17+
touchscreen-inverted-y = <0>;
18+
touchscreen-swapped-x-y = <0>;
1419
};
1520
};
1621
};
22+
23+
__overrides__ {
24+
touchscreen-size-x = <&rpi_ft5406>,"touchscreen-size-x:0";
25+
touchscreen-size-y = <&rpi_ft5406>,"touchscreen-size-y:0";
26+
touchscreen-inverted-x = <&rpi_ft5406>,"touchscreen-inverted-x:0";
27+
touchscreen-inverted-y = <&rpi_ft5406>,"touchscreen-inverted-y:0";
28+
touchscreen-swapped-x-y = <&rpi_ft5406>,"touchscreen-swapped-x-y:0";
29+
};
1730
};

drivers/input/touchscreen/rpi-ft5406.c

Lines changed: 55 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
* Driver for memory based ft5406 touchscreen
33
*
4-
* Copyright (C) 2015 Raspberry Pi
4+
* Copyright (C) 2015, 2017 Raspberry Pi
55
*
66
*
77
* This program is free software; you can redistribute it and/or modify
@@ -26,6 +26,7 @@
2626
#include <soc/bcm2835/raspberrypi-firmware.h>
2727

2828
#define MAXIMUM_SUPPORTED_POINTS 10
29+
2930
struct ft5406_regs {
3031
uint8_t device_mode;
3132
uint8_t gesture_id;
@@ -40,15 +41,22 @@ struct ft5406_regs {
4041
} point[MAXIMUM_SUPPORTED_POINTS];
4142
};
4243

43-
#define SCREEN_WIDTH 800
44-
#define SCREEN_HEIGHT 480
44+
// These are defaults if the DT entries are missing.
45+
#define DEFAULT_SCREEN_WIDTH 800
46+
#define DEFAULT_SCREEN_HEIGHT 480
4547

4648
struct ft5406 {
47-
struct platform_device * pdev;
48-
struct input_dev * input_dev;
49-
void __iomem * ts_base;
50-
dma_addr_t bus_addr;
51-
struct task_struct * thread;
49+
struct platform_device * pdev;
50+
struct input_dev * input_dev;
51+
void __iomem * ts_base;
52+
dma_addr_t bus_addr;
53+
struct task_struct * thread;
54+
55+
uint16_t max_x;
56+
uint16_t max_y;
57+
uint8_t hflip;
58+
uint8_t vflip;
59+
uint8_t xyswap;
5260
};
5361

5462
/* Thread to poll for touchscreen events
@@ -81,12 +89,21 @@ static int ft5406_thread(void *arg)
8189
int x = (((int) regs.point[i].xh & 0xf) << 8) + regs.point[i].xl;
8290
int y = (((int) regs.point[i].yh & 0xf) << 8) + regs.point[i].yl;
8391
int touchid = (regs.point[i].yh >> 4) & 0xf;
84-
92+
8593
modified_ids |= 1 << touchid;
8694

95+
if (ts->hflip)
96+
x = ts->max_x - 1 - x;
97+
98+
if (ts->vflip)
99+
y = ts->max_y - 1 - y;
100+
101+
if (ts->xyswap)
102+
swap(x,y);
103+
87104
if(!((1 << touchid) & known_ids))
88105
dev_dbg(&ts->pdev->dev, "x = %d, y = %d, touchid = %d\n", x, y, touchid);
89-
106+
90107
input_mt_slot(ts->input_dev, touchid);
91108
input_mt_report_slot_state(ts->input_dev, MT_TOOL_FINGER, 1);
92109

@@ -126,6 +143,7 @@ static int ft5406_probe(struct platform_device *pdev)
126143
struct device_node *fw_node;
127144
struct rpi_firmware *fw;
128145
u32 touchbuf;
146+
u32 val;
129147

130148
dev_info(dev, "Probing device\n");
131149

@@ -136,8 +154,10 @@ static int ft5406_probe(struct platform_device *pdev)
136154
}
137155

138156
fw = rpi_firmware_get(fw_node);
139-
if (!fw)
157+
if (!fw) {
158+
dev_err(dev, "No firmware node - deferring\n");
140159
return -EPROBE_DEFER;
160+
}
141161

142162
ts = devm_kzalloc(dev, sizeof(struct ft5406), GFP_KERNEL);
143163
if (!ts) {
@@ -202,15 +222,36 @@ static int ft5406_probe(struct platform_device *pdev)
202222
ts->pdev = pdev;
203223

204224
ts->input_dev->name = "FT5406 memory based driver";
205-
225+
226+
if (of_property_read_u32(np, "touchscreen-size-x", &val) >= 0)
227+
ts->max_x = val;
228+
else
229+
ts->max_x = DEFAULT_SCREEN_WIDTH;
230+
231+
if (of_property_read_u32(np, "touchscreen-size-y", &val) >= 0)
232+
ts->max_y = val;
233+
else
234+
ts->max_y = DEFAULT_SCREEN_HEIGHT;
235+
236+
if (of_property_read_u32(np, "touchscreen-inverted-x", &val) >= 0)
237+
ts->hflip = val;
238+
239+
if (of_property_read_u32(np, "touchscreen-inverted-y", &val) >= 0)
240+
ts->vflip = val;
241+
242+
if (of_property_read_u32(np, "touchscreen-swapped-x-y", &val) >= 0)
243+
ts->xyswap = val;
244+
245+
dev_dbg(dev, "Touchscreen parameters (%d,%d), hflip=%d, vflip=%d, xyswap=%d", ts->max_x, ts->max_y, ts->hflip, ts->vflip, ts->xyswap);
246+
206247
__set_bit(EV_KEY, ts->input_dev->evbit);
207248
__set_bit(EV_SYN, ts->input_dev->evbit);
208249
__set_bit(EV_ABS, ts->input_dev->evbit);
209250

210251
input_set_abs_params(ts->input_dev, ABS_MT_POSITION_X, 0,
211-
SCREEN_WIDTH, 0, 0);
252+
ts->xyswap ? ts->max_y : ts->max_x, 0, 0);
212253
input_set_abs_params(ts->input_dev, ABS_MT_POSITION_Y, 0,
213-
SCREEN_HEIGHT, 0, 0);
254+
ts->xyswap ? ts->max_x : ts->max_y, 0, 0);
214255

215256
input_mt_init_slots(ts->input_dev, MAXIMUM_SUPPORTED_POINTS, INPUT_MT_DIRECT);
216257

0 commit comments

Comments
 (0)