brcm2708: update 4.1 patches
[openwrt.git] / target / linux / brcm2708 / patches-4.1 / 0139-rpi-ft5406-Use-firmware-API.patch
1 From 1c445d2c28dcbd90be62624bd9ae9bd88e564b96 Mon Sep 17 00:00:00 2001
2 From: =?UTF-8?q?Noralf=20Tr=C3=B8nnes?= <noralf@tronnes.org>
3 Date: Tue, 21 Jul 2015 19:09:39 +0200
4 Subject: [PATCH 139/171] rpi-ft5406: Use firmware API
5 MIME-Version: 1.0
6 Content-Type: text/plain; charset=UTF-8
7 Content-Transfer-Encoding: 8bit
8
9 Signed-off-by: Noralf Trønnes <noralf@tronnes.org>
10 ---
11  arch/arm/boot/dts/overlays/rpi-ft5406-overlay.dts |  1 +
12  drivers/input/touchscreen/rpi-ft5406.c            | 74 ++++++++++-------------
13  2 files changed, 32 insertions(+), 43 deletions(-)
14
15 --- a/arch/arm/boot/dts/overlays/rpi-ft5406-overlay.dts
16 +++ b/arch/arm/boot/dts/overlays/rpi-ft5406-overlay.dts
17 @@ -9,6 +9,7 @@
18                 __overlay__ {
19                         rpi_ft5406: rpi_ft5406 {
20                                 compatible = "rpi,rpi-ft5406";
21 +                               firmware = <&firmware>;
22                                 status = "okay";
23                         };
24                 };
25 --- a/drivers/input/touchscreen/rpi-ft5406.c
26 +++ b/drivers/input/touchscreen/rpi-ft5406.c
27 @@ -21,7 +21,7 @@
28  #include <linux/kthread.h>
29  #include <linux/platform_device.h>
30  #include <asm/io.h>
31 -#include <linux/platform_data/mailbox-bcm2708.h>
32 +#include <soc/bcm2835/raspberrypi-firmware.h>
33  
34  #define MAXIMUM_SUPPORTED_POINTS 10
35  struct ft5406_regs {
36 @@ -49,23 +49,6 @@ struct ft5406 {
37         struct task_struct     * thread;
38  };
39  
40 -
41 -/* tag part of the message */
42 -struct vc_msg_tag {
43 -       uint32_t tag_id;                /* the message id */
44 -       uint32_t buffer_size;   /* size of the buffer (which in this case is always 8 bytes) */
45 -       uint32_t data_size;             /* amount of data being sent or received */
46 -       uint32_t val;           /* data buffer */
47 -};
48 -
49 -/* message structure to be sent to videocore */
50 -struct vc_msg {
51 -       uint32_t msg_size;              /* simply, sizeof(struct vc_msg) */
52 -       uint32_t request_code;  /* holds various information like the success and number of bytes returned (refer to mailboxes wiki) */
53 -       struct vc_msg_tag tag;  /* the tag structure above to make */
54 -       uint32_t end_tag;               /* an end identifier, should be set to NULL */
55 -};
56 -
57  /* Thread to poll for touchscreen events
58   * 
59   * This thread polls the memory based register copy of the ft5406 registers
60 @@ -136,11 +119,37 @@ static int ft5406_probe(struct platform_
61  {
62         int ret;
63         struct input_dev * input_dev = input_allocate_device();
64 -       struct vc_msg request;
65         struct ft5406 * ts;
66 +       struct device_node *fw_node;
67 +       struct rpi_firmware *fw;
68 +       u32 touchbuf;
69         
70         dev_info(&pdev->dev, "Probing device\n");
71         
72 +       fw_node = of_parse_phandle(pdev->dev.of_node, "firmware", 0);
73 +       if (!fw_node) {
74 +               dev_err(&pdev->dev, "Missing firmware node\n");
75 +               return -ENOENT;
76 +       }
77 +
78 +       fw = rpi_firmware_get(fw_node);
79 +       if (!fw)
80 +               return -EPROBE_DEFER;
81 +
82 +       ret = rpi_firmware_property(fw, RPI_FIRMWARE_FRAMEBUFFER_GET_TOUCHBUF,
83 +                                   &touchbuf, sizeof(touchbuf));
84 +       if (ret) {
85 +               dev_err(&pdev->dev, "Failed to get touch buffer\n");
86 +               return ret;
87 +       }
88 +
89 +       if (!touchbuf) {
90 +               dev_err(&pdev->dev, "Touchscreen not detected\n");
91 +               return -ENODEV;
92 +       }
93 +
94 +       dev_dbg(&pdev->dev, "Got TS buffer 0x%x\n", touchbuf);
95 +
96         ts = kzalloc(sizeof(struct ft5406), GFP_KERNEL);
97  
98         if (!ts || !input_dev) {
99 @@ -174,36 +183,15 @@ static int ft5406_probe(struct platform_
100                 return ret;
101         }
102         
103 -       memset(&request, 0, sizeof request);
104 -
105 -       request.msg_size = sizeof request;
106 -       request.request_code = VCMSG_PROCESS_REQUEST;
107 -       request.tag.tag_id = VCMSG_GET_TOUCHBUF;
108 -       request.tag.buffer_size = 4;
109 -       request.tag.data_size = 4;
110 -       
111 -       bcm_mailbox_property(&request, sizeof(request));
112 -       
113 -       if(request.request_code == VCMSG_REQUEST_SUCCESSFUL && request.tag.val != 0)
114 -       {
115 -               dev_dbg(&pdev->dev, "Got TS buffer 0x%x\n", request.tag.val);
116 -       }
117 -       else
118 -       {
119 -               input_unregister_device(input_dev);
120 -               kzfree(ts);
121 -               return -1;
122 -       }
123 -       
124         // mmap the physical memory
125 -       request.tag.val &= ~0xc0000000;
126 -       ts->ts_base = ioremap(request.tag.val, sizeof(*ts->regs));
127 +       touchbuf &= ~0xc0000000;
128 +       ts->ts_base = ioremap(touchbuf, sizeof(*ts->regs));
129         if(ts->ts_base == NULL)
130         {
131                 dev_err(&pdev->dev, "Failed to map physical address\n");
132                 input_unregister_device(input_dev);
133                 kzfree(ts);
134 -               return -1;      
135 +               return -ENOMEM;
136         }
137         
138         ts->regs = (struct ft5406_regs *) ts->ts_base;