Terence Hampson | afded26 | 2013-06-18 14:48:18 -0400 | [diff] [blame^] | 1 | /* Copyright (c) 2013, 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 <debug.h> |
| 31 | #include <smem.h> |
| 32 | #include <msm_panel.h> |
| 33 | #include <pm8x41.h> |
| 34 | #include <pm8x41_wled.h> |
| 35 | #include <board.h> |
| 36 | #include <platform/gpio.h> |
| 37 | #include <platform/iomap.h> |
| 38 | #include <target/display.h> |
| 39 | |
| 40 | static struct msm_fb_panel_data panel; |
| 41 | static uint8_t display_enable; |
| 42 | |
| 43 | extern int msm_display_init(struct msm_fb_panel_data *pdata); |
| 44 | extern int msm_display_off(); |
| 45 | extern void dsi_phy_init(struct msm_panel_info *pinfo); |
| 46 | |
| 47 | static int msm8610_backlight(uint8_t enable) |
| 48 | { |
| 49 | struct pm8x41_mpp mpp; |
| 50 | mpp.base = PM8x41_MMP3_BASE; |
| 51 | mpp.mode = MPP_HIGH; |
| 52 | mpp.vin = MPP_VIN3; |
| 53 | if (enable) |
| 54 | { |
| 55 | pm8x41_config_output_mpp(&mpp); |
| 56 | pm8x41_enable_mpp(&mpp, MPP_ENABLE); |
| 57 | } else { |
| 58 | pm8x41_enable_mpp(&mpp, MPP_DISABLE); |
| 59 | } |
| 60 | /* Need delay before power on regulators */ |
| 61 | mdelay(20); |
| 62 | return 0; |
| 63 | } |
| 64 | |
| 65 | void dsi_calc_clk_rate(uint32_t *dsiclk_rate, uint32_t *byteclk_rate) |
| 66 | { |
| 67 | uint32_t hbp, hfp, vbp, vfp, hspw, vspw, width, height; |
| 68 | uint32_t bitclk_rate; |
| 69 | int frame_rate, lanes; |
| 70 | |
| 71 | width = panel.panel_info.xres; |
| 72 | height = panel.panel_info.yres; |
| 73 | hbp = panel.panel_info.lcdc.h_back_porch; |
| 74 | hfp = panel.panel_info.lcdc.h_front_porch; |
| 75 | hspw = panel.panel_info.lcdc.h_pulse_width; |
| 76 | vbp = panel.panel_info.lcdc.v_back_porch; |
| 77 | vfp = panel.panel_info.lcdc.v_front_porch; |
| 78 | vspw = panel.panel_info.lcdc.v_pulse_width; |
| 79 | lanes = panel.panel_info.mipi.num_of_lanes; |
| 80 | frame_rate = panel.panel_info.mipi.frame_rate; |
| 81 | |
| 82 | bitclk_rate = (width + hbp + hfp + hspw) * (height + vbp + vfp + vspw); |
| 83 | bitclk_rate *= frame_rate; |
| 84 | bitclk_rate *= panel.panel_info.bpp; |
| 85 | bitclk_rate /= lanes; |
| 86 | |
| 87 | *byteclk_rate = bitclk_rate / 8; |
| 88 | *dsiclk_rate = *byteclk_rate * lanes; |
| 89 | } |
| 90 | |
| 91 | static int msm8610_mdss_dsi_panel_clock(uint8_t enable) |
| 92 | { |
| 93 | uint32_t dsiclk_rate, byteclk_rate; |
| 94 | |
| 95 | if (enable) |
| 96 | { |
| 97 | mdp_clock_enable(); |
| 98 | dsi_calc_clk_rate(&dsiclk_rate, &byteclk_rate); |
| 99 | dsi_clock_enable(dsiclk_rate, byteclk_rate); |
| 100 | } else if(!target_cont_splash_screen()) { |
| 101 | dsi_clock_disable(); |
| 102 | mdp_clock_disable(); |
| 103 | } |
| 104 | |
| 105 | return 0; |
| 106 | } |
| 107 | |
| 108 | static void msm8610_mdss_mipi_panel_reset(int enable) |
| 109 | { |
| 110 | dprintf(SPEW, "msm8610_mdss_mipi_panel_reset, enable = %d\n", enable); |
| 111 | |
| 112 | if (enable) |
| 113 | { |
| 114 | gpio_tlmm_config(41, 0, GPIO_OUTPUT, GPIO_NO_PULL, GPIO_8MA, GPIO_DISABLE); |
| 115 | gpio_tlmm_config(7, 0, GPIO_OUTPUT, GPIO_NO_PULL, GPIO_8MA, GPIO_DISABLE); |
| 116 | |
| 117 | /* reset */ |
| 118 | gpio_set(41, 2); |
| 119 | mdelay(20); |
| 120 | gpio_set(41, 0); |
| 121 | udelay(20); |
| 122 | gpio_set(41, 2); |
| 123 | mdelay(20); |
| 124 | |
| 125 | if (panel.panel_info.type == MIPI_VIDEO_PANEL) |
| 126 | gpio_set(7, 2); |
| 127 | else if (panel.panel_info.type == MIPI_CMD_PANEL) |
| 128 | gpio_set(7, 0); |
| 129 | } else if(!target_cont_splash_screen()) { |
| 130 | gpio_set(7, 0); |
| 131 | gpio_set(41, 0); |
| 132 | } |
| 133 | return; |
| 134 | } |
| 135 | |
| 136 | static int msm8610_mipi_panel_power(uint8_t enable) |
| 137 | { |
| 138 | int ret; |
| 139 | struct pm8x41_ldo ldo4 = LDO(PM8x41_LDO4, NLDO_TYPE); |
| 140 | struct pm8x41_ldo ldo14 = LDO(PM8x41_LDO14, PLDO_TYPE); |
| 141 | struct pm8x41_ldo ldo19 = LDO(PM8x41_LDO19, PLDO_TYPE); |
| 142 | |
| 143 | dprintf(SPEW, "msm8610_mipi_panel_power, enable = %d\n", enable); |
| 144 | if (enable) |
| 145 | { |
| 146 | /* backlight */ |
| 147 | msm8610_backlight(enable); |
| 148 | |
| 149 | /* regulators */ |
| 150 | pm8x41_ldo_set_voltage(&ldo14, 1800000); |
| 151 | pm8x41_ldo_control(&ldo14, enable); |
| 152 | pm8x41_ldo_set_voltage(&ldo19, 2850000); |
| 153 | pm8x41_ldo_control(&ldo19, enable); |
| 154 | pm8x41_ldo_set_voltage(&ldo4, 1200000); |
| 155 | pm8x41_ldo_control(&ldo4, enable); |
| 156 | |
| 157 | /* reset */ |
| 158 | msm8610_mdss_mipi_panel_reset(enable); |
| 159 | } else if(!target_cont_splash_screen()) { |
| 160 | msm8610_backlight(0); |
| 161 | msm8610_mdss_mipi_panel_reset(enable); |
| 162 | |
| 163 | pm8x41_ldo_control(&ldo19, enable); |
| 164 | pm8x41_ldo_control(&ldo14, enable); |
| 165 | pm8x41_ldo_control(&ldo4, enable); |
| 166 | } |
| 167 | return 0; |
| 168 | } |
| 169 | |
| 170 | void display_init(void) |
| 171 | { |
| 172 | uint32_t hw_id = board_hardware_id(); |
| 173 | |
| 174 | dprintf(SPEW, "display_init(),target_id=%d.\n", hw_id); |
| 175 | |
| 176 | switch (hw_id) { |
| 177 | case HW_PLATFORM_QRD: |
| 178 | case HW_PLATFORM_MTP: |
| 179 | case HW_PLATFORM_SURF: |
| 180 | mipi_truly_video_wvga_init(&(panel.panel_info)); |
| 181 | panel.clk_func = msm8610_mdss_dsi_panel_clock; |
| 182 | panel.power_func = msm8610_mipi_panel_power; |
| 183 | panel.fb.base = MIPI_FB_ADDR; |
| 184 | panel.fb.width = panel.panel_info.xres; |
| 185 | panel.fb.height = panel.panel_info.yres; |
| 186 | panel.fb.stride = panel.panel_info.xres; |
| 187 | panel.fb.bpp = panel.panel_info.bpp; |
| 188 | panel.fb.format = FB_FORMAT_RGB888; |
| 189 | panel.mdp_rev = MDP_REV_304; |
| 190 | break; |
| 191 | default: |
| 192 | return; |
| 193 | }; |
| 194 | |
| 195 | if (msm_display_init(&panel)) |
| 196 | { |
| 197 | dprintf(CRITICAL, "Display init failed!\n"); |
| 198 | return; |
| 199 | } |
| 200 | |
| 201 | display_enable = 1; |
| 202 | } |
| 203 | |
| 204 | void display_shutdown(void) |
| 205 | { |
| 206 | if (display_enable) |
| 207 | msm_display_off(); |
| 208 | } |