Zohaib Alam | b7b677f | 2014-10-24 15:54:42 -0400 | [diff] [blame] | 1 | /* 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 <msm_panel.h> |
| 33 | #include <platform/gpio.h> |
| 34 | #include "qpic.h" |
| 35 | #include "qpic_panel.h" |
| 36 | #include <reg.h> |
| 37 | |
| 38 | static uint32_t panel_is_on; |
| 39 | |
| 40 | static int (*qpic_panel_on)(struct qpic_panel_io_desc *qpic_panel_io); |
| 41 | static void (*qpic_panel_off)(struct qpic_panel_io_desc *qpic_panel_io); |
| 42 | |
| 43 | |
| 44 | /* write a frame of pixels to a MIPI screen */ |
| 45 | uint32_t qpic_send_frame(uint32_t x_start, |
| 46 | uint32_t y_start, |
| 47 | uint32_t x_end, |
| 48 | uint32_t y_end, |
| 49 | uint32_t *data, |
| 50 | uint32_t total_bytes) |
| 51 | { |
| 52 | uint8_t param[4]; |
| 53 | uint32_t status; |
| 54 | uint32_t start_0_7; |
| 55 | uint32_t end_0_7; |
| 56 | uint32_t start_8_15; |
| 57 | uint32_t end_8_15; |
| 58 | |
| 59 | /* convert to 16 bit representation */ |
| 60 | x_start = x_start & 0xffff; |
| 61 | y_start = y_start & 0xffff; |
| 62 | x_end = x_end & 0xffff; |
| 63 | y_end = y_end & 0xffff; |
| 64 | |
| 65 | /* set column/page */ |
| 66 | start_0_7 = x_start & 0xff; |
| 67 | end_0_7 = x_end & 0xff; |
| 68 | start_8_15 = (x_start >> 8) & 0xff; |
| 69 | end_8_15 = (x_end >> 8) & 0xff; |
| 70 | param[0] = start_8_15; |
| 71 | param[1] = start_0_7; |
| 72 | param[2] = end_8_15; |
| 73 | param[3] = end_0_7; |
| 74 | status = qpic_send_pkt(OP_SET_COLUMN_ADDRESS, param, 4); |
| 75 | if (status) { |
| 76 | dprintf(CRITICAL, "Failed to set column address\n"); |
| 77 | return status; |
| 78 | } |
| 79 | |
| 80 | start_0_7 = y_start & 0xff; |
| 81 | end_0_7 = y_end & 0xff; |
| 82 | start_8_15 = (y_start >> 8) & 0xff; |
| 83 | end_8_15 = (y_end >> 8) & 0xff; |
| 84 | param[0] = start_8_15; |
| 85 | param[1] = start_0_7; |
| 86 | param[2] = end_8_15; |
| 87 | param[3] = end_0_7; |
| 88 | status = qpic_send_pkt(OP_SET_PAGE_ADDRESS, param, 4); |
| 89 | if (status) { |
| 90 | dprintf(CRITICAL, "Failed to set page address\n"); |
| 91 | return status; |
| 92 | } |
| 93 | |
| 94 | status = qpic_send_pkt(OP_WRITE_MEMORY_START, (uint8_t *)data, total_bytes); |
| 95 | if (status) { |
| 96 | dprintf(CRITICAL, "Failed to start memory write\n"); |
| 97 | return status; |
| 98 | } |
| 99 | return 0; |
| 100 | } |
| 101 | |
| 102 | int mdss_qpic_panel_on(struct qpic_panel_io_desc *panel_io) |
| 103 | { |
| 104 | int rc = 0; |
| 105 | |
| 106 | if (panel_is_on) |
| 107 | return 0; |
| 108 | mdss_qpic_init(); |
| 109 | |
| 110 | if (qpic_panel_on) |
| 111 | rc = qpic_panel_on(panel_io); |
| 112 | |
| 113 | if (!rc) |
| 114 | panel_is_on = true; |
| 115 | |
| 116 | return rc; |
| 117 | } |
| 118 | |
| 119 | int mdss_qpic_panel_off(struct qpic_panel_io_desc *panel_io) |
| 120 | { |
| 121 | if (qpic_panel_off) |
| 122 | qpic_panel_off(panel_io); |
| 123 | |
| 124 | panel_is_on = false; |
| 125 | return 0; |
| 126 | } |
| 127 | |
| 128 | int mdss_qpic_panel_init(struct qpic_panel_io_desc *panel_io) |
| 129 | { |
Zohaib Alam | f5f1779 | 2014-10-24 15:58:22 -0400 | [diff] [blame] | 130 | qpic_panel_on = ili9341_on; |
| 131 | qpic_panel_off = ili9341_off; |
Zohaib Alam | 929b7fb | 2014-10-24 15:58:22 -0400 | [diff] [blame] | 132 | |
Zohaib Alam | b7b677f | 2014-10-24 15:54:42 -0400 | [diff] [blame] | 133 | return 0; |
| 134 | } |
| 135 | |