blob: 4cd5d4b5709d56b79adfb65b31661ad54a92d524 [file] [log] [blame]
Wenjun Zhange9647e22018-02-01 03:42:29 -05001/* Copyright (c) 2017-2018 The Linux Foundation. All rights reserved.
2 *
3 * Redistribution and use in source and binary forms, with or without
4 * modification, are permitted provided that the following conditions are
5 * met:
6 * * Redistributions of source code must retain the above copyright
7 * notice, this list of conditions and the following disclaimer.
8 * * Redistributions in binary form must reproduce the above
9 * copyright notice, this list of conditions and the following
10 * disclaimer in the documentation and/or other materials provided
11 * with the distribution.
12 * * Neither the name of The Linux Foundation nor the names of its
13 * contributors may be used to endorse or promote products derived
14 * from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
17 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
18 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
20 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
23 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
24 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
25 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
26 * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 *
28 */
29
30#include <spi_qup.h>
31#include <msm_panel.h>
32#include <target/display.h>
33#include <platform/gpio.h>
34
35#define SUCCESS 0
36#define FAIL 1
37
38static struct qup_spi_dev *dev = NULL;
39
40static int mdss_spi_write_cmd(const char *buf)
41{
42 int ret = 0;
43
44 if (!dev) {
45 dprintf(CRITICAL, "SPI has not been initialized\n");
46 return -ENODEV;
47 }
48
49 dev->bytes_per_word = 1;
50 dev->bit_shift_en = 1;
51
52 gpio_set(spi_dc_gpio.pin_id, 0);
53 ret = spi_qup_transfer(dev, buf, 1);
54 gpio_set(spi_dc_gpio.pin_id, 2);
55 if (ret)
56 dprintf(CRITICAL, "Send SPI command to panel failed\n");
57
58 return ret;
59}
60
61static int mdss_spi_write_data(const char *buf, size_t len)
62{
63 int ret = 0;
64
65 if (!dev) {
66 dprintf(CRITICAL, "SPI has not been initialized\n");
67 return -ENODEV;
68 }
69
70 dev->bytes_per_word = 1;
71 dev->bit_shift_en = 1;
72
73 gpio_set(spi_dc_gpio.pin_id, 2);
74 ret = spi_qup_transfer(dev, buf, len);
75 if (ret)
76 dprintf(CRITICAL, "Send SPI parameters to panel failed\n");
77
78 return ret;
79}
80
81static int mdss_spi_write_frame(const char *buf, size_t len)
82{
83 int ret = 0;
84
85 if (!dev) {
86 dprintf(CRITICAL, "SPI has not been initialized\n");
87 return -ENODEV;
88 }
89
90 dev->bytes_per_word = 2;
91 dev->bit_shift_en = 1;
92 dev->unpack_en = 0;
93
94 gpio_set(spi_dc_gpio.pin_id, 2);
95 ret = spi_qup_transfer(dev, buf, len);
96
97 return ret;
98}
99
100static void spi_read_panel_data(unsigned char *buf, int len)
101{
102 int ret = 0;
103
104 if (!dev) {
105 dprintf(CRITICAL, "SPI has not been initialized\n");
106 return -ENODEV;
107 }
108 dev->bytes_per_word = 1;
109 dev->bit_shift_en = 1;
110
111 gpio_set(spi_dc_gpio.pin_id, 0);
112 ret = spi_qup_transfer(dev, buf, len);
113 gpio_set(spi_dc_gpio.pin_id, 2);
114
115 if (ret)
116 dprintf(CRITICAL, "Send SPI command to panel failed\n");
117
118 return;
119}
120
121int mdss_spi_init(void)
122{
123 if (!dev) {
124 dev = qup_blsp_spi_init(SPI_BLSP_ID, SPI_QUP_ID);
125 if (!dev) {
126 dprintf(CRITICAL, "Failed initializing SPI\n");
127 return -ENODEV;
128 }
129 }
130
131 gpio_tlmm_config(spi_dc_gpio.pin_id, 0, spi_dc_gpio.pin_direction,
132 spi_dc_gpio.pin_pull, spi_dc_gpio.pin_strength,
133 spi_dc_gpio.pin_state);
134 return SUCCESS;
135}
136
137int mdss_spi_panel_init(struct msm_panel_info *pinfo)
138{
139 int cmd_count = 0;
140 int ret = 0;
141
142 while (cmd_count < pinfo->spi.num_of_panel_cmds) {
143 if (pinfo->spi.panel_cmds[cmd_count].cmds_post_tg){
144 cmd_count ++;
145 continue;
146 }
147
148 mdss_spi_write_cmd(pinfo->spi.panel_cmds[cmd_count].payload);
149 if (pinfo->spi.panel_cmds[cmd_count].size > 1)
150 mdss_spi_write_data(
151 pinfo->spi.panel_cmds[cmd_count].payload + 1,
152 pinfo->spi.panel_cmds[cmd_count].size - 1);
153
154 if (pinfo->spi.panel_cmds[cmd_count].wait)
155 mdelay(pinfo->spi.panel_cmds[cmd_count].wait);
156
157 cmd_count ++;
158 }
159 return SUCCESS;
160}
161
162int mdss_spi_on(struct msm_panel_info *pinfo, struct fbcon_config *fb)
163{
164 int buf_size = 0;
165 int ret = 0;
166
167 buf_size = fb->width * fb->height * (fb->bpp / 8);
168 ret = mdss_spi_write_frame(fb->base, buf_size);
169 if (ret)
170 dprintf(CRITICAL, "Send SPI frame data to panel failed\n");
171
172 return ret;
173}
Wenjun Zhang150a0cd2018-03-07 01:48:21 -0500174
175int mdss_spi_cmd_post_on(struct msm_panel_info *pinfo)
176{
177 int cmd_count = 0;
178 char *payload;
179
180 if (!dev) {
181 dprintf(CRITICAL, "SPI has not been initialized\n");
182 return -ENODEV;
183 }
184
185 while (cmd_count < pinfo->spi.num_of_panel_cmds) {
186 if (pinfo->spi.panel_cmds[cmd_count].cmds_post_tg){
187 payload = pinfo->spi.panel_cmds[cmd_count].payload;
188 mdss_spi_write_cmd(payload);
189 if (pinfo->spi.panel_cmds[cmd_count].size > 1)
190 mdss_spi_write_data(payload + 1,
191 pinfo->spi.panel_cmds[cmd_count].size
192 - 1);
193
194 if (pinfo->spi.panel_cmds[cmd_count].wait)
195 mdelay(pinfo->spi.panel_cmds[cmd_count].wait);
196 }
197
198 cmd_count ++;
199 }
200
201 return SUCCESS;
202}