blob: c5a7c20be5e589abfd05aae0e84a8aba00211fe7 [file] [log] [blame]
Zohaib Alam929b7fb2014-10-24 15:58:22 -04001/* Copyright (c) 2014, 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
5 * are 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 copyright
9 * notice, this list of conditions and the following disclaimer in
10 * the documentation and/or other materials provided with the
11 * 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 BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
19 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
20 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
22 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
23 * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
24 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
25 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
26 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 * SUCH DAMAGE.
28 */
29
30#include <debug.h>
31#include <err.h>
32#include <endian.h>
33#include <platform/gpio.h>
34#include <platform/clock.h>
35#include <regulator.h>
36#include <rpm-smd.h>
37#include <platform/timer.h>
38
39#include "qpic.h"
40#include "qpic_panel.h"
41
42#define GPIOMUX_FUNC_1 1
43#define GPIOMUX_FUNC_GPIO 0
44
45#define RST_GPIO_ID 23
46#define CS_GPIO_ID 21
47#define AD8_GPIO_ID 20
48#define TE_GPIO_ID 22
49#define BL_GPIO_ID 84
50
51#define MEM_ACCESS_MODE 0x48
52#define MEM_ACCESS_FORMAT 0x66
53
54static uint32_t ldo6[][11] = {
55 {
56 LDOA_RES_TYPE, 6,
57 KEY_SOFTWARE_ENABLE, 4, GENERIC_DISABLE,
58 KEY_LDO_SOFTWARE_MODE, 4, SW_MODE_LDO_IPEAK,
59 KEY_MICRO_VOLT, 4, 0,
60 },
61 {
62 LDOA_RES_TYPE, 6,
63 KEY_SOFTWARE_ENABLE, 4, GENERIC_ENABLE,
64 KEY_LDO_SOFTWARE_MODE, 4, SW_MODE_LDO_IPEAK,
65 KEY_MICRO_VOLT, 4, 1800000,
66 },
67};
68
69static uint32_t ldo12[][11] = {
70 {
71 LDOA_RES_TYPE, 12,
72 KEY_SOFTWARE_ENABLE, 4, GENERIC_DISABLE,
73 KEY_LDO_SOFTWARE_MODE, 4, SW_MODE_LDO_IPEAK,
74 KEY_MICRO_VOLT, 4, 0,
75 },
76 {
77 LDOA_RES_TYPE, 12,
78 KEY_SOFTWARE_ENABLE, 4, GENERIC_ENABLE,
79 KEY_LDO_SOFTWARE_MODE, 4, SW_MODE_LDO_IPEAK,
80 KEY_MICRO_VOLT, 4, 2700000,
81 },
82};
83
84static void panel_io_off(struct qpic_panel_io_desc *qpic_panel_io)
85{
86 /* Turning off all gpios */
87 gpio_tlmm_config(RST_GPIO_ID, GPIOMUX_FUNC_1, GPIO_INPUT, GPIO_NO_PULL,
88 GPIO_10MA, GPIO_DISABLE);
89 gpio_tlmm_config(CS_GPIO_ID, GPIOMUX_FUNC_1, GPIO_INPUT, GPIO_NO_PULL,
90 GPIO_10MA, GPIO_DISABLE);
91 gpio_tlmm_config(AD8_GPIO_ID, GPIOMUX_FUNC_1, GPIO_INPUT, GPIO_NO_PULL,
92 GPIO_10MA, GPIO_DISABLE);
93 gpio_tlmm_config(TE_GPIO_ID, GPIOMUX_FUNC_1, GPIO_INPUT, GPIO_NO_PULL,
94 GPIO_10MA, GPIO_DISABLE);
95 gpio_tlmm_config(BL_GPIO_ID, GPIOMUX_FUNC_GPIO, GPIO_INPUT, GPIO_NO_PULL,
96 GPIO_10MA, GPIO_ENABLE);
97 gpio_set(BL_GPIO_ID, 0x0);
98
99 /* Disabling vdd & avdd voltage */
100 rpm_send_data(&ldo6[GENERIC_DISABLE][0], 36, RPM_REQUEST_TYPE);
101 rpm_send_data(&ldo12[GENERIC_DISABLE][0], 36, RPM_REQUEST_TYPE);
102
103 /* uninitializing smd */
104 rpm_smd_uninit();
105
106 return;
107}
108
Zohaib Alamf5f17792014-10-24 15:58:22 -0400109void ili9341_off(struct qpic_panel_io_desc *qpic_panel_io)
Zohaib Alam929b7fb2014-10-24 15:58:22 -0400110{
111 panel_io_off(qpic_panel_io);
112}
113
114static int panel_io_on(struct qpic_panel_io_desc *qpic_panel_io)
115{
116 int rc = 0;
117
118 /* Setting vdd & avdd voltage */
119 rpm_send_data(&ldo6[GENERIC_ENABLE][0], 36, RPM_REQUEST_TYPE);
120 rpm_send_data(&ldo12[GENERIC_ENABLE][0], 36, RPM_REQUEST_TYPE);
121
122 /* Turning on all gpios */
123 gpio_tlmm_config(RST_GPIO_ID, GPIOMUX_FUNC_1, GPIO_INPUT,GPIO_NO_PULL,
124 GPIO_10MA, GPIO_ENABLE);
125 gpio_tlmm_config(CS_GPIO_ID, GPIOMUX_FUNC_1, GPIO_INPUT,GPIO_NO_PULL,
126 GPIO_10MA, GPIO_ENABLE);
127 gpio_tlmm_config(AD8_GPIO_ID, GPIOMUX_FUNC_1, GPIO_INPUT,GPIO_NO_PULL,
128 GPIO_10MA, GPIO_ENABLE);
129 gpio_tlmm_config(TE_GPIO_ID, GPIOMUX_FUNC_1, GPIO_INPUT,GPIO_NO_PULL,
130 GPIO_10MA, GPIO_ENABLE);
131 gpio_tlmm_config(BL_GPIO_ID, GPIOMUX_FUNC_GPIO, GPIO_INPUT, GPIO_NO_PULL,
132 GPIO_10MA, GPIO_DISABLE);
133 gpio_set(BL_GPIO_ID, 0x2);
134
135 mdelay(20);
136 return rc;
137}
138
Zohaib Alamf5f17792014-10-24 15:58:22 -0400139int ili9341_on(struct qpic_panel_io_desc *qpic_panel_io)
Zohaib Alam929b7fb2014-10-24 15:58:22 -0400140{
141 uint8_t param[4];
142 int ret;
143
144 ret = panel_io_on(qpic_panel_io);
145 if (ret)
146 return ret;
Zohaib Alam929b7fb2014-10-24 15:58:22 -0400147 qpic_send_pkt(OP_SOFT_RESET, NULL, 0);
Zohaib Alamf5f17792014-10-24 15:58:22 -0400148 /* wait for 120 ms after reset as panel spec suggests */
149 mdelay(120);
150 qpic_send_pkt(OP_SET_DISPLAY_OFF, NULL, 0);
151 /* wait for 20 ms after disply off */
152 mdelay(20);
153
154 /* set memory access control */
155 param[0] = MEM_ACCESS_MODE;
156 qpic_send_pkt(OP_SET_ADDRESS_MODE, param, 1);
157 /* wait for 20 ms after command sent as panel spec suggests */
158 mdelay(20);
159
160 param[0] = MEM_ACCESS_FORMAT;
161 qpic_send_pkt(OP_SET_PIXEL_FORMAT, param, 1);
162 mdelay(20);
163
164 /* set interface */
165 param[0] = 1;
166 param[1] = 0;
167 param[2] = 0;
168 qpic_send_pkt(OP_ILI9341_INTERFACE_CONTROL, param, 3);
169 mdelay(20);
170
171 qpic_send_pkt(OP_EXIT_SLEEP_MODE, NULL, 0);
172 mdelay(20);
173
174 qpic_send_pkt(OP_ENTER_NORMAL_MODE, NULL, 0);
175 mdelay(20);
176
177 qpic_send_pkt(OP_SET_DISPLAY_ON, NULL, 0);
178 mdelay(20);
179
180 param[0] = 0;
181 qpic_send_pkt(OP_ILI9341_TEARING_EFFECT_LINE_ON, param, 1);
182
Zohaib Alam929b7fb2014-10-24 15:58:22 -0400183 param[0] = qpic_read_data(OP_GET_PIXEL_FORMAT, 1);
Zohaib Alamf5f17792014-10-24 15:58:22 -0400184
Zohaib Alam929b7fb2014-10-24 15:58:22 -0400185 return 0;
186}