Luc Verhaegen | 7f2c521 | 2014-08-13 07:55:06 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Display driver for Allwinner SoCs. |
| 3 | * |
| 4 | * (C) Copyright 2013-2014 Luc Verhaegen <libv@skynet.be> |
| 5 | * (C) Copyright 2014 Hans de Goede <hdegoede@redhat.com> |
| 6 | * |
| 7 | * SPDX-License-Identifier: GPL-2.0+ |
| 8 | */ |
| 9 | |
| 10 | #include <common.h> |
| 11 | |
| 12 | #include <asm/arch/clock.h> |
| 13 | #include <asm/arch/display.h> |
Hans de Goede | 2dae800 | 2014-12-21 16:28:32 +0100 | [diff] [blame] | 14 | #include <asm/arch/gpio.h> |
Luc Verhaegen | 7f2c521 | 2014-08-13 07:55:06 +0200 | [diff] [blame] | 15 | #include <asm/global_data.h> |
Hans de Goede | 2dae800 | 2014-12-21 16:28:32 +0100 | [diff] [blame] | 16 | #include <asm/gpio.h> |
Luc Verhaegen | 7f2c521 | 2014-08-13 07:55:06 +0200 | [diff] [blame] | 17 | #include <asm/io.h> |
Hans de Goede | 7548160 | 2014-12-19 16:05:12 +0100 | [diff] [blame] | 18 | #include <errno.h> |
Luc Verhaegen | 2d7a084 | 2014-08-13 07:55:07 +0200 | [diff] [blame] | 19 | #include <fdtdec.h> |
| 20 | #include <fdt_support.h> |
Luc Verhaegen | 7f2c521 | 2014-08-13 07:55:06 +0200 | [diff] [blame] | 21 | #include <video_fb.h> |
Hans de Goede | be8ec63 | 2014-12-19 13:46:33 +0100 | [diff] [blame] | 22 | #include "videomodes.h" |
Luc Verhaegen | 7f2c521 | 2014-08-13 07:55:06 +0200 | [diff] [blame] | 23 | |
| 24 | DECLARE_GLOBAL_DATA_PTR; |
| 25 | |
Hans de Goede | 1c09220 | 2014-12-21 14:37:45 +0100 | [diff] [blame] | 26 | enum sunxi_monitor { |
| 27 | sunxi_monitor_none, |
| 28 | sunxi_monitor_dvi, |
| 29 | sunxi_monitor_hdmi, |
| 30 | sunxi_monitor_lcd, |
| 31 | sunxi_monitor_vga, |
| 32 | }; |
| 33 | #define SUNXI_MONITOR_LAST sunxi_monitor_vga |
| 34 | |
Luc Verhaegen | 7f2c521 | 2014-08-13 07:55:06 +0200 | [diff] [blame] | 35 | struct sunxi_display { |
| 36 | GraphicDevice graphic_device; |
Hans de Goede | 1c09220 | 2014-12-21 14:37:45 +0100 | [diff] [blame] | 37 | enum sunxi_monitor monitor; |
Hans de Goede | 2dae800 | 2014-12-21 16:28:32 +0100 | [diff] [blame] | 38 | unsigned int depth; |
Luc Verhaegen | 7f2c521 | 2014-08-13 07:55:06 +0200 | [diff] [blame] | 39 | } sunxi_display; |
| 40 | |
Hans de Goede | 2fbf091 | 2014-12-23 23:04:35 +0100 | [diff] [blame] | 41 | #ifdef CONFIG_VIDEO_HDMI |
| 42 | |
Hans de Goede | 7548160 | 2014-12-19 16:05:12 +0100 | [diff] [blame] | 43 | /* |
| 44 | * Wait up to 200ms for value to be set in given part of reg. |
| 45 | */ |
| 46 | static int await_completion(u32 *reg, u32 mask, u32 val) |
| 47 | { |
| 48 | unsigned long tmo = timer_get_us() + 200000; |
| 49 | |
| 50 | while ((readl(reg) & mask) != val) { |
| 51 | if (timer_get_us() > tmo) { |
| 52 | printf("DDC: timeout reading EDID\n"); |
| 53 | return -ETIME; |
| 54 | } |
| 55 | } |
| 56 | return 0; |
| 57 | } |
| 58 | |
Hans de Goede | 7fad8a9 | 2014-12-28 09:13:21 +0100 | [diff] [blame] | 59 | static int sunxi_hdmi_hpd_detect(int hpd_delay) |
Luc Verhaegen | 7f2c521 | 2014-08-13 07:55:06 +0200 | [diff] [blame] | 60 | { |
| 61 | struct sunxi_ccm_reg * const ccm = |
| 62 | (struct sunxi_ccm_reg *)SUNXI_CCM_BASE; |
| 63 | struct sunxi_hdmi_reg * const hdmi = |
| 64 | (struct sunxi_hdmi_reg *)SUNXI_HDMI_BASE; |
Hans de Goede | 7fad8a9 | 2014-12-28 09:13:21 +0100 | [diff] [blame] | 65 | unsigned long tmo = timer_get_us() + hpd_delay * 1000; |
Luc Verhaegen | 7f2c521 | 2014-08-13 07:55:06 +0200 | [diff] [blame] | 66 | |
| 67 | /* Set pll3 to 300MHz */ |
| 68 | clock_set_pll3(300000000); |
| 69 | |
| 70 | /* Set hdmi parent to pll3 */ |
| 71 | clrsetbits_le32(&ccm->hdmi_clk_cfg, CCM_HDMI_CTRL_PLL_MASK, |
| 72 | CCM_HDMI_CTRL_PLL3); |
| 73 | |
| 74 | /* Set ahb gating to pass */ |
Hans de Goede | 211717a | 2014-11-14 17:42:14 +0100 | [diff] [blame] | 75 | #ifdef CONFIG_MACH_SUN6I |
| 76 | setbits_le32(&ccm->ahb_reset1_cfg, 1 << AHB_RESET_OFFSET_HDMI); |
| 77 | #endif |
Luc Verhaegen | 7f2c521 | 2014-08-13 07:55:06 +0200 | [diff] [blame] | 78 | setbits_le32(&ccm->ahb_gate1, 1 << AHB_GATE_OFFSET_HDMI); |
| 79 | |
| 80 | /* Clock on */ |
| 81 | setbits_le32(&ccm->hdmi_clk_cfg, CCM_HDMI_CTRL_GATE); |
| 82 | |
| 83 | writel(SUNXI_HDMI_CTRL_ENABLE, &hdmi->ctrl); |
| 84 | writel(SUNXI_HDMI_PAD_CTRL0_HDP, &hdmi->pad_ctrl0); |
| 85 | |
Hans de Goede | 40f1b87 | 2014-12-20 15:15:23 +0100 | [diff] [blame] | 86 | while (timer_get_us() < tmo) { |
| 87 | if (readl(&hdmi->hpd) & SUNXI_HDMI_HPD_DETECT) |
| 88 | return 1; |
| 89 | } |
Luc Verhaegen | 7f2c521 | 2014-08-13 07:55:06 +0200 | [diff] [blame] | 90 | |
Hans de Goede | 40f1b87 | 2014-12-20 15:15:23 +0100 | [diff] [blame] | 91 | return 0; |
Hans de Goede | 518cef2 | 2014-12-19 15:13:57 +0100 | [diff] [blame] | 92 | } |
Luc Verhaegen | 7f2c521 | 2014-08-13 07:55:06 +0200 | [diff] [blame] | 93 | |
Hans de Goede | 518cef2 | 2014-12-19 15:13:57 +0100 | [diff] [blame] | 94 | static void sunxi_hdmi_shutdown(void) |
| 95 | { |
| 96 | struct sunxi_ccm_reg * const ccm = |
| 97 | (struct sunxi_ccm_reg *)SUNXI_CCM_BASE; |
| 98 | struct sunxi_hdmi_reg * const hdmi = |
| 99 | (struct sunxi_hdmi_reg *)SUNXI_HDMI_BASE; |
| 100 | |
Luc Verhaegen | 7f2c521 | 2014-08-13 07:55:06 +0200 | [diff] [blame] | 101 | clrbits_le32(&hdmi->ctrl, SUNXI_HDMI_CTRL_ENABLE); |
| 102 | clrbits_le32(&ccm->hdmi_clk_cfg, CCM_HDMI_CTRL_GATE); |
| 103 | clrbits_le32(&ccm->ahb_gate1, 1 << AHB_GATE_OFFSET_HDMI); |
Hans de Goede | 211717a | 2014-11-14 17:42:14 +0100 | [diff] [blame] | 104 | #ifdef CONFIG_MACH_SUN6I |
| 105 | clrbits_le32(&ccm->ahb_reset1_cfg, 1 << AHB_RESET_OFFSET_HDMI); |
| 106 | #endif |
Luc Verhaegen | 7f2c521 | 2014-08-13 07:55:06 +0200 | [diff] [blame] | 107 | clock_set_pll3(0); |
Luc Verhaegen | 7f2c521 | 2014-08-13 07:55:06 +0200 | [diff] [blame] | 108 | } |
| 109 | |
Hans de Goede | 7548160 | 2014-12-19 16:05:12 +0100 | [diff] [blame] | 110 | static int sunxi_hdmi_ddc_do_command(u32 cmnd, int offset, int n) |
| 111 | { |
| 112 | struct sunxi_hdmi_reg * const hdmi = |
| 113 | (struct sunxi_hdmi_reg *)SUNXI_HDMI_BASE; |
| 114 | |
| 115 | setbits_le32(&hdmi->ddc_fifo_ctrl, SUNXI_HDMI_DDC_FIFO_CTRL_CLEAR); |
| 116 | writel(SUNXI_HMDI_DDC_ADDR_EDDC_SEGMENT(offset >> 8) | |
| 117 | SUNXI_HMDI_DDC_ADDR_EDDC_ADDR | |
| 118 | SUNXI_HMDI_DDC_ADDR_OFFSET(offset) | |
| 119 | SUNXI_HMDI_DDC_ADDR_SLAVE_ADDR, &hdmi->ddc_addr); |
| 120 | #ifndef CONFIG_MACH_SUN6I |
| 121 | writel(n, &hdmi->ddc_byte_count); |
| 122 | writel(cmnd, &hdmi->ddc_cmnd); |
| 123 | #else |
| 124 | writel(n << 16 | cmnd, &hdmi->ddc_cmnd); |
| 125 | #endif |
| 126 | setbits_le32(&hdmi->ddc_ctrl, SUNXI_HMDI_DDC_CTRL_START); |
| 127 | |
| 128 | return await_completion(&hdmi->ddc_ctrl, SUNXI_HMDI_DDC_CTRL_START, 0); |
| 129 | } |
| 130 | |
| 131 | static int sunxi_hdmi_ddc_read(int offset, u8 *buf, int count) |
| 132 | { |
| 133 | struct sunxi_hdmi_reg * const hdmi = |
| 134 | (struct sunxi_hdmi_reg *)SUNXI_HDMI_BASE; |
| 135 | int i, n; |
| 136 | |
| 137 | while (count > 0) { |
| 138 | if (count > 16) |
| 139 | n = 16; |
| 140 | else |
| 141 | n = count; |
| 142 | |
| 143 | if (sunxi_hdmi_ddc_do_command( |
| 144 | SUNXI_HDMI_DDC_CMND_EXPLICIT_EDDC_READ, |
| 145 | offset, n)) |
| 146 | return -ETIME; |
| 147 | |
| 148 | for (i = 0; i < n; i++) |
| 149 | *buf++ = readb(&hdmi->ddc_fifo_data); |
| 150 | |
| 151 | offset += n; |
| 152 | count -= n; |
| 153 | } |
| 154 | |
| 155 | return 0; |
| 156 | } |
| 157 | |
Hans de Goede | 63c5fbd | 2014-12-20 14:01:48 +0100 | [diff] [blame] | 158 | static int sunxi_hdmi_edid_get_block(int block, u8 *buf) |
| 159 | { |
| 160 | int r, retries = 2; |
| 161 | |
| 162 | do { |
| 163 | r = sunxi_hdmi_ddc_read(block * 128, buf, 128); |
| 164 | if (r) |
| 165 | continue; |
| 166 | r = edid_check_checksum(buf); |
| 167 | if (r) { |
| 168 | printf("EDID block %d: checksum error%s\n", |
| 169 | block, retries ? ", retrying" : ""); |
| 170 | } |
| 171 | } while (r && retries--); |
| 172 | |
| 173 | return r; |
| 174 | } |
| 175 | |
Hans de Goede | 1c09220 | 2014-12-21 14:37:45 +0100 | [diff] [blame] | 176 | static int sunxi_hdmi_edid_get_mode(struct ctfb_res_modes *mode) |
Hans de Goede | 7548160 | 2014-12-19 16:05:12 +0100 | [diff] [blame] | 177 | { |
| 178 | struct edid1_info edid1; |
Hans de Goede | f300068 | 2014-12-20 14:31:45 +0100 | [diff] [blame] | 179 | struct edid_cea861_info cea681[4]; |
Hans de Goede | 7548160 | 2014-12-19 16:05:12 +0100 | [diff] [blame] | 180 | struct edid_detailed_timing *t = |
| 181 | (struct edid_detailed_timing *)edid1.monitor_details.timing; |
| 182 | struct sunxi_hdmi_reg * const hdmi = |
| 183 | (struct sunxi_hdmi_reg *)SUNXI_HDMI_BASE; |
| 184 | struct sunxi_ccm_reg * const ccm = |
| 185 | (struct sunxi_ccm_reg *)SUNXI_CCM_BASE; |
Hans de Goede | f300068 | 2014-12-20 14:31:45 +0100 | [diff] [blame] | 186 | int i, r, ext_blocks = 0; |
Hans de Goede | 7548160 | 2014-12-19 16:05:12 +0100 | [diff] [blame] | 187 | |
| 188 | /* SUNXI_HDMI_CTRL_ENABLE & PAD_CTRL0 are already set by hpd_detect */ |
| 189 | writel(SUNXI_HDMI_PAD_CTRL1 | SUNXI_HDMI_PAD_CTRL1_HALVE, |
| 190 | &hdmi->pad_ctrl1); |
| 191 | writel(SUNXI_HDMI_PLL_CTRL | SUNXI_HDMI_PLL_CTRL_DIV(15), |
| 192 | &hdmi->pll_ctrl); |
| 193 | writel(SUNXI_HDMI_PLL_DBG0_PLL3, &hdmi->pll_dbg0); |
| 194 | |
| 195 | /* Reset i2c controller */ |
| 196 | setbits_le32(&ccm->hdmi_clk_cfg, CCM_HDMI_CTRL_DDC_GATE); |
| 197 | writel(SUNXI_HMDI_DDC_CTRL_ENABLE | |
| 198 | SUNXI_HMDI_DDC_CTRL_SDA_ENABLE | |
| 199 | SUNXI_HMDI_DDC_CTRL_SCL_ENABLE | |
| 200 | SUNXI_HMDI_DDC_CTRL_RESET, &hdmi->ddc_ctrl); |
| 201 | if (await_completion(&hdmi->ddc_ctrl, SUNXI_HMDI_DDC_CTRL_RESET, 0)) |
| 202 | return -EIO; |
| 203 | |
| 204 | writel(SUNXI_HDMI_DDC_CLOCK, &hdmi->ddc_clock); |
| 205 | #ifndef CONFIG_MACH_SUN6I |
| 206 | writel(SUNXI_HMDI_DDC_LINE_CTRL_SDA_ENABLE | |
| 207 | SUNXI_HMDI_DDC_LINE_CTRL_SCL_ENABLE, &hdmi->ddc_line_ctrl); |
| 208 | #endif |
| 209 | |
Hans de Goede | 63c5fbd | 2014-12-20 14:01:48 +0100 | [diff] [blame] | 210 | r = sunxi_hdmi_edid_get_block(0, (u8 *)&edid1); |
Hans de Goede | f300068 | 2014-12-20 14:31:45 +0100 | [diff] [blame] | 211 | if (r == 0) { |
| 212 | r = edid_check_info(&edid1); |
| 213 | if (r) { |
| 214 | printf("EDID: invalid EDID data\n"); |
| 215 | r = -EINVAL; |
| 216 | } |
| 217 | } |
| 218 | if (r == 0) { |
| 219 | ext_blocks = edid1.extension_flag; |
| 220 | if (ext_blocks > 4) |
| 221 | ext_blocks = 4; |
| 222 | for (i = 0; i < ext_blocks; i++) { |
| 223 | if (sunxi_hdmi_edid_get_block(1 + i, |
| 224 | (u8 *)&cea681[i]) != 0) { |
| 225 | ext_blocks = i; |
| 226 | break; |
| 227 | } |
| 228 | } |
| 229 | } |
Hans de Goede | 7548160 | 2014-12-19 16:05:12 +0100 | [diff] [blame] | 230 | |
| 231 | /* Disable DDC engine, no longer needed */ |
| 232 | clrbits_le32(&hdmi->ddc_ctrl, SUNXI_HMDI_DDC_CTRL_ENABLE); |
| 233 | clrbits_le32(&ccm->hdmi_clk_cfg, CCM_HDMI_CTRL_DDC_GATE); |
| 234 | |
| 235 | if (r) |
| 236 | return r; |
| 237 | |
Hans de Goede | 7548160 | 2014-12-19 16:05:12 +0100 | [diff] [blame] | 238 | /* We want version 1.3 or 1.2 with detailed timing info */ |
| 239 | if (edid1.version != 1 || (edid1.revision < 3 && |
| 240 | !EDID1_INFO_FEATURE_PREFERRED_TIMING_MODE(edid1))) { |
| 241 | printf("EDID: unsupported version %d.%d\n", |
| 242 | edid1.version, edid1.revision); |
| 243 | return -EINVAL; |
| 244 | } |
| 245 | |
| 246 | /* Take the first usable detailed timing */ |
| 247 | for (i = 0; i < 4; i++, t++) { |
| 248 | r = video_edid_dtd_to_ctfb_res_modes(t, mode); |
| 249 | if (r == 0) |
| 250 | break; |
| 251 | } |
| 252 | if (i == 4) { |
| 253 | printf("EDID: no usable detailed timing found\n"); |
| 254 | return -ENOENT; |
| 255 | } |
| 256 | |
Hans de Goede | f300068 | 2014-12-20 14:31:45 +0100 | [diff] [blame] | 257 | /* Check for basic audio support, if found enable hdmi output */ |
Hans de Goede | 1c09220 | 2014-12-21 14:37:45 +0100 | [diff] [blame] | 258 | sunxi_display.monitor = sunxi_monitor_dvi; |
Hans de Goede | f300068 | 2014-12-20 14:31:45 +0100 | [diff] [blame] | 259 | for (i = 0; i < ext_blocks; i++) { |
| 260 | if (cea681[i].extension_tag != EDID_CEA861_EXTENSION_TAG || |
| 261 | cea681[i].revision < 2) |
| 262 | continue; |
| 263 | |
| 264 | if (EDID_CEA861_SUPPORTS_BASIC_AUDIO(cea681[i])) |
Hans de Goede | 1c09220 | 2014-12-21 14:37:45 +0100 | [diff] [blame] | 265 | sunxi_display.monitor = sunxi_monitor_hdmi; |
Hans de Goede | f300068 | 2014-12-20 14:31:45 +0100 | [diff] [blame] | 266 | } |
| 267 | |
Hans de Goede | 7548160 | 2014-12-19 16:05:12 +0100 | [diff] [blame] | 268 | return 0; |
| 269 | } |
| 270 | |
Hans de Goede | 2fbf091 | 2014-12-23 23:04:35 +0100 | [diff] [blame] | 271 | #endif /* CONFIG_VIDEO_HDMI */ |
| 272 | |
Luc Verhaegen | 7f2c521 | 2014-08-13 07:55:06 +0200 | [diff] [blame] | 273 | /* |
| 274 | * This is the entity that mixes and matches the different layers and inputs. |
| 275 | * Allwinner calls it the back-end, but i like composer better. |
| 276 | */ |
| 277 | static void sunxi_composer_init(void) |
| 278 | { |
| 279 | struct sunxi_ccm_reg * const ccm = |
| 280 | (struct sunxi_ccm_reg *)SUNXI_CCM_BASE; |
| 281 | struct sunxi_de_be_reg * const de_be = |
| 282 | (struct sunxi_de_be_reg *)SUNXI_DE_BE0_BASE; |
| 283 | int i; |
| 284 | |
Hans de Goede | 2fbf091 | 2014-12-23 23:04:35 +0100 | [diff] [blame] | 285 | #if defined CONFIG_MACH_SUN6I || defined CONFIG_MACH_SUN8I |
Hans de Goede | 211717a | 2014-11-14 17:42:14 +0100 | [diff] [blame] | 286 | /* Reset off */ |
| 287 | setbits_le32(&ccm->ahb_reset1_cfg, 1 << AHB_RESET_OFFSET_DE_BE0); |
| 288 | #endif |
| 289 | |
Luc Verhaegen | 7f2c521 | 2014-08-13 07:55:06 +0200 | [diff] [blame] | 290 | /* Clocks on */ |
| 291 | setbits_le32(&ccm->ahb_gate1, 1 << AHB_GATE_OFFSET_DE_BE0); |
| 292 | setbits_le32(&ccm->dram_clk_gate, 1 << CCM_DRAM_GATE_OFFSET_DE_BE0); |
| 293 | clock_set_de_mod_clock(&ccm->be0_clk_cfg, 300000000); |
| 294 | |
| 295 | /* Engine bug, clear registers after reset */ |
| 296 | for (i = 0x0800; i < 0x1000; i += 4) |
| 297 | writel(0, SUNXI_DE_BE0_BASE + i); |
| 298 | |
| 299 | setbits_le32(&de_be->mode, SUNXI_DE_BE_MODE_ENABLE); |
| 300 | } |
| 301 | |
Hans de Goede | be8ec63 | 2014-12-19 13:46:33 +0100 | [diff] [blame] | 302 | static void sunxi_composer_mode_set(const struct ctfb_res_modes *mode, |
Luc Verhaegen | 7f2c521 | 2014-08-13 07:55:06 +0200 | [diff] [blame] | 303 | unsigned int address) |
| 304 | { |
| 305 | struct sunxi_de_be_reg * const de_be = |
| 306 | (struct sunxi_de_be_reg *)SUNXI_DE_BE0_BASE; |
| 307 | |
| 308 | writel(SUNXI_DE_BE_HEIGHT(mode->yres) | SUNXI_DE_BE_WIDTH(mode->xres), |
| 309 | &de_be->disp_size); |
| 310 | writel(SUNXI_DE_BE_HEIGHT(mode->yres) | SUNXI_DE_BE_WIDTH(mode->xres), |
| 311 | &de_be->layer0_size); |
| 312 | writel(SUNXI_DE_BE_LAYER_STRIDE(mode->xres), &de_be->layer0_stride); |
| 313 | writel(address << 3, &de_be->layer0_addr_low32b); |
| 314 | writel(address >> 29, &de_be->layer0_addr_high4b); |
| 315 | writel(SUNXI_DE_BE_LAYER_ATTR1_FMT_XRGB8888, &de_be->layer0_attr1_ctrl); |
| 316 | |
| 317 | setbits_le32(&de_be->mode, SUNXI_DE_BE_MODE_LAYER0_ENABLE); |
| 318 | } |
| 319 | |
Hans de Goede | 0e04521 | 2014-12-21 14:49:34 +0100 | [diff] [blame] | 320 | static void sunxi_composer_enable(void) |
| 321 | { |
| 322 | struct sunxi_de_be_reg * const de_be = |
| 323 | (struct sunxi_de_be_reg *)SUNXI_DE_BE0_BASE; |
| 324 | |
| 325 | setbits_le32(&de_be->reg_ctrl, SUNXI_DE_BE_REG_CTRL_LOAD_REGS); |
| 326 | setbits_le32(&de_be->mode, SUNXI_DE_BE_MODE_START); |
| 327 | } |
| 328 | |
Luc Verhaegen | 7f2c521 | 2014-08-13 07:55:06 +0200 | [diff] [blame] | 329 | /* |
| 330 | * LCDC, what allwinner calls a CRTC, so timing controller and serializer. |
| 331 | */ |
Hans de Goede | 5489ebc | 2014-12-21 16:27:45 +0100 | [diff] [blame] | 332 | static void sunxi_lcdc_pll_set(int tcon, int dotclock, |
| 333 | int *clk_div, int *clk_double) |
Luc Verhaegen | 7f2c521 | 2014-08-13 07:55:06 +0200 | [diff] [blame] | 334 | { |
| 335 | struct sunxi_ccm_reg * const ccm = |
| 336 | (struct sunxi_ccm_reg *)SUNXI_CCM_BASE; |
Hans de Goede | 5489ebc | 2014-12-21 16:27:45 +0100 | [diff] [blame] | 337 | int value, n, m, min_m, max_m, diff; |
Luc Verhaegen | 7f2c521 | 2014-08-13 07:55:06 +0200 | [diff] [blame] | 338 | int best_n = 0, best_m = 0, best_diff = 0x0FFFFFFF; |
| 339 | int best_double = 0; |
| 340 | |
Hans de Goede | 5489ebc | 2014-12-21 16:27:45 +0100 | [diff] [blame] | 341 | if (tcon == 0) { |
Hans de Goede | 213480e | 2015-01-01 22:04:34 +0100 | [diff] [blame] | 342 | #ifdef CONFIG_VIDEO_LCD_IF_PARALLEL |
Hans de Goede | 5489ebc | 2014-12-21 16:27:45 +0100 | [diff] [blame] | 343 | min_m = 6; |
| 344 | max_m = 127; |
Hans de Goede | 213480e | 2015-01-01 22:04:34 +0100 | [diff] [blame] | 345 | #endif |
| 346 | #ifdef CONFIG_VIDEO_LCD_IF_LVDS |
| 347 | min_m = max_m = 7; |
| 348 | #endif |
Hans de Goede | 5489ebc | 2014-12-21 16:27:45 +0100 | [diff] [blame] | 349 | } else { |
| 350 | min_m = 1; |
| 351 | max_m = 15; |
| 352 | } |
| 353 | |
Luc Verhaegen | 7f2c521 | 2014-08-13 07:55:06 +0200 | [diff] [blame] | 354 | /* |
| 355 | * Find the lowest divider resulting in a matching clock, if there |
| 356 | * is no match, pick the closest lower clock, as monitors tend to |
| 357 | * not sync to higher frequencies. |
| 358 | */ |
Hans de Goede | 5489ebc | 2014-12-21 16:27:45 +0100 | [diff] [blame] | 359 | for (m = min_m; m <= max_m; m++) { |
Luc Verhaegen | 7f2c521 | 2014-08-13 07:55:06 +0200 | [diff] [blame] | 360 | n = (m * dotclock) / 3000; |
| 361 | |
| 362 | if ((n >= 9) && (n <= 127)) { |
| 363 | value = (3000 * n) / m; |
| 364 | diff = dotclock - value; |
| 365 | if (diff < best_diff) { |
| 366 | best_diff = diff; |
| 367 | best_m = m; |
| 368 | best_n = n; |
| 369 | best_double = 0; |
| 370 | } |
| 371 | } |
| 372 | |
| 373 | /* These are just duplicates */ |
| 374 | if (!(m & 1)) |
| 375 | continue; |
| 376 | |
| 377 | n = (m * dotclock) / 6000; |
| 378 | if ((n >= 9) && (n <= 127)) { |
| 379 | value = (6000 * n) / m; |
| 380 | diff = dotclock - value; |
| 381 | if (diff < best_diff) { |
| 382 | best_diff = diff; |
| 383 | best_m = m; |
| 384 | best_n = n; |
| 385 | best_double = 1; |
| 386 | } |
| 387 | } |
| 388 | } |
| 389 | |
| 390 | debug("dotclock: %dkHz = %dkHz: (%d * 3MHz * %d) / %d\n", |
| 391 | dotclock, (best_double + 1) * 3000 * best_n / best_m, |
| 392 | best_double + 1, best_n, best_m); |
| 393 | |
| 394 | clock_set_pll3(best_n * 3000000); |
| 395 | |
Hans de Goede | 5489ebc | 2014-12-21 16:27:45 +0100 | [diff] [blame] | 396 | if (tcon == 0) { |
| 397 | writel(CCM_LCD_CH0_CTRL_GATE | CCM_LCD_CH0_CTRL_RST | |
| 398 | (best_double ? CCM_LCD_CH0_CTRL_PLL3_2X : |
| 399 | CCM_LCD_CH0_CTRL_PLL3), |
| 400 | &ccm->lcd0_ch0_clk_cfg); |
| 401 | } else { |
| 402 | writel(CCM_LCD_CH1_CTRL_GATE | |
| 403 | (best_double ? CCM_LCD_CH1_CTRL_PLL3_2X : |
| 404 | CCM_LCD_CH1_CTRL_PLL3) | |
| 405 | CCM_LCD_CH1_CTRL_M(best_m), &ccm->lcd0_ch1_clk_cfg); |
| 406 | } |
Luc Verhaegen | 7f2c521 | 2014-08-13 07:55:06 +0200 | [diff] [blame] | 407 | |
| 408 | *clk_div = best_m; |
| 409 | *clk_double = best_double; |
| 410 | } |
| 411 | |
| 412 | static void sunxi_lcdc_init(void) |
| 413 | { |
| 414 | struct sunxi_ccm_reg * const ccm = |
| 415 | (struct sunxi_ccm_reg *)SUNXI_CCM_BASE; |
| 416 | struct sunxi_lcdc_reg * const lcdc = |
| 417 | (struct sunxi_lcdc_reg *)SUNXI_LCD0_BASE; |
| 418 | |
| 419 | /* Reset off */ |
Hans de Goede | 2fbf091 | 2014-12-23 23:04:35 +0100 | [diff] [blame] | 420 | #if defined CONFIG_MACH_SUN6I || defined CONFIG_MACH_SUN8I |
Hans de Goede | 211717a | 2014-11-14 17:42:14 +0100 | [diff] [blame] | 421 | setbits_le32(&ccm->ahb_reset1_cfg, 1 << AHB_RESET_OFFSET_LCD0); |
| 422 | #else |
Luc Verhaegen | 7f2c521 | 2014-08-13 07:55:06 +0200 | [diff] [blame] | 423 | setbits_le32(&ccm->lcd0_ch0_clk_cfg, CCM_LCD_CH0_CTRL_RST); |
Hans de Goede | 211717a | 2014-11-14 17:42:14 +0100 | [diff] [blame] | 424 | #endif |
Luc Verhaegen | 7f2c521 | 2014-08-13 07:55:06 +0200 | [diff] [blame] | 425 | |
| 426 | /* Clock on */ |
| 427 | setbits_le32(&ccm->ahb_gate1, 1 << AHB_GATE_OFFSET_LCD0); |
Hans de Goede | 213480e | 2015-01-01 22:04:34 +0100 | [diff] [blame] | 428 | #ifdef CONFIG_VIDEO_LCD_IF_LVDS |
| 429 | setbits_le32(&ccm->lvds_clk_cfg, CCM_LVDS_CTRL_RST); |
| 430 | #endif |
Luc Verhaegen | 7f2c521 | 2014-08-13 07:55:06 +0200 | [diff] [blame] | 431 | |
| 432 | /* Init lcdc */ |
| 433 | writel(0, &lcdc->ctrl); /* Disable tcon */ |
| 434 | writel(0, &lcdc->int0); /* Disable all interrupts */ |
| 435 | |
| 436 | /* Disable tcon0 dot clock */ |
| 437 | clrbits_le32(&lcdc->tcon0_dclk, SUNXI_LCDC_TCON0_DCLK_ENABLE); |
| 438 | |
| 439 | /* Set all io lines to tristate */ |
| 440 | writel(0xffffffff, &lcdc->tcon0_io_tristate); |
| 441 | writel(0xffffffff, &lcdc->tcon1_io_tristate); |
| 442 | } |
| 443 | |
Hans de Goede | 0e04521 | 2014-12-21 14:49:34 +0100 | [diff] [blame] | 444 | static void sunxi_lcdc_enable(void) |
| 445 | { |
| 446 | struct sunxi_lcdc_reg * const lcdc = |
| 447 | (struct sunxi_lcdc_reg *)SUNXI_LCD0_BASE; |
| 448 | |
| 449 | setbits_le32(&lcdc->ctrl, SUNXI_LCDC_CTRL_TCON_ENABLE); |
Hans de Goede | 213480e | 2015-01-01 22:04:34 +0100 | [diff] [blame] | 450 | #ifdef CONFIG_VIDEO_LCD_IF_LVDS |
| 451 | setbits_le32(&lcdc->tcon0_lvds_intf, SUNXI_LCDC_TCON0_LVDS_INTF_ENABLE); |
| 452 | setbits_le32(&lcdc->lvds_ana0, SUNXI_LCDC_LVDS_ANA0); |
| 453 | setbits_le32(&lcdc->lvds_ana0, SUNXI_LCDC_LVDS_ANA0_UPDATE); |
| 454 | udelay(2); /* delay at least 1200 ns */ |
| 455 | setbits_le32(&lcdc->lvds_ana1, SUNXI_LCDC_LVDS_ANA1_INIT1); |
| 456 | udelay(1); /* delay at least 120 ns */ |
| 457 | setbits_le32(&lcdc->lvds_ana1, SUNXI_LCDC_LVDS_ANA1_INIT2); |
| 458 | setbits_le32(&lcdc->lvds_ana0, SUNXI_LCDC_LVDS_ANA0_UPDATE); |
| 459 | #endif |
Hans de Goede | 0e04521 | 2014-12-21 14:49:34 +0100 | [diff] [blame] | 460 | } |
| 461 | |
Hans de Goede | 2dae800 | 2014-12-21 16:28:32 +0100 | [diff] [blame] | 462 | static void sunxi_lcdc_panel_enable(void) |
| 463 | { |
| 464 | int pin; |
| 465 | |
| 466 | /* |
| 467 | * Start with backlight disabled to avoid the screen flashing to |
| 468 | * white while the lcd inits. |
| 469 | */ |
| 470 | pin = sunxi_name_to_gpio(CONFIG_VIDEO_LCD_BL_EN); |
| 471 | if (pin != -1) { |
| 472 | gpio_request(pin, "lcd_backlight_enable"); |
| 473 | gpio_direction_output(pin, 0); |
| 474 | } |
| 475 | |
| 476 | pin = sunxi_name_to_gpio(CONFIG_VIDEO_LCD_BL_PWM); |
| 477 | if (pin != -1) { |
| 478 | gpio_request(pin, "lcd_backlight_pwm"); |
| 479 | /* backlight pwm is inverted, set to 1 to disable backlight */ |
| 480 | gpio_direction_output(pin, 1); |
| 481 | } |
| 482 | |
| 483 | /* Give the backlight some time to turn off and power up the panel. */ |
| 484 | mdelay(40); |
| 485 | pin = sunxi_name_to_gpio(CONFIG_VIDEO_LCD_POWER); |
| 486 | if (pin != -1) { |
| 487 | gpio_request(pin, "lcd_power"); |
| 488 | gpio_direction_output(pin, 1); |
| 489 | } |
| 490 | } |
| 491 | |
| 492 | static void sunxi_lcdc_backlight_enable(void) |
| 493 | { |
| 494 | int pin; |
| 495 | |
| 496 | /* |
| 497 | * We want to have scanned out at least one frame before enabling the |
| 498 | * backlight to avoid the screen flashing to white when we enable it. |
| 499 | */ |
| 500 | mdelay(40); |
| 501 | |
| 502 | pin = sunxi_name_to_gpio(CONFIG_VIDEO_LCD_BL_EN); |
| 503 | if (pin != -1) |
| 504 | gpio_direction_output(pin, 1); |
| 505 | |
| 506 | pin = sunxi_name_to_gpio(CONFIG_VIDEO_LCD_BL_PWM); |
| 507 | if (pin != -1) { |
| 508 | /* backlight pwm is inverted, set to 0 to enable backlight */ |
| 509 | gpio_direction_output(pin, 0); |
| 510 | } |
| 511 | } |
| 512 | |
| 513 | static int sunxi_lcdc_get_clk_delay(const struct ctfb_res_modes *mode) |
| 514 | { |
| 515 | int delay; |
| 516 | |
| 517 | delay = mode->lower_margin + mode->vsync_len + mode->upper_margin - 2; |
| 518 | return (delay > 30) ? 30 : delay; |
| 519 | } |
| 520 | |
| 521 | static void sunxi_lcdc_tcon0_mode_set(const struct ctfb_res_modes *mode) |
| 522 | { |
| 523 | struct sunxi_lcdc_reg * const lcdc = |
| 524 | (struct sunxi_lcdc_reg *)SUNXI_LCD0_BASE; |
| 525 | int bp, clk_delay, clk_div, clk_double, pin, total, val; |
| 526 | |
| 527 | for (pin = SUNXI_GPD(0); pin <= SUNXI_GPD(27); pin++) |
Hans de Goede | 213480e | 2015-01-01 22:04:34 +0100 | [diff] [blame] | 528 | #ifdef CONFIG_VIDEO_LCD_IF_PARALLEL |
Hans de Goede | 2dae800 | 2014-12-21 16:28:32 +0100 | [diff] [blame] | 529 | sunxi_gpio_set_cfgpin(pin, SUNXI_GPD0_LCD0); |
Hans de Goede | 213480e | 2015-01-01 22:04:34 +0100 | [diff] [blame] | 530 | #endif |
| 531 | #ifdef CONFIG_VIDEO_LCD_IF_LVDS |
| 532 | sunxi_gpio_set_cfgpin(pin, SUNXI_GPD0_LVDS0); |
| 533 | #endif |
Hans de Goede | 2dae800 | 2014-12-21 16:28:32 +0100 | [diff] [blame] | 534 | |
| 535 | sunxi_lcdc_pll_set(0, mode->pixclock_khz, &clk_div, &clk_double); |
| 536 | |
| 537 | /* Use tcon0 */ |
| 538 | clrsetbits_le32(&lcdc->ctrl, SUNXI_LCDC_CTRL_IO_MAP_MASK, |
| 539 | SUNXI_LCDC_CTRL_IO_MAP_TCON0); |
| 540 | |
| 541 | clk_delay = sunxi_lcdc_get_clk_delay(mode); |
| 542 | writel(SUNXI_LCDC_TCON0_CTRL_ENABLE | |
| 543 | SUNXI_LCDC_TCON0_CTRL_CLK_DELAY(clk_delay), &lcdc->tcon0_ctrl); |
| 544 | |
| 545 | writel(SUNXI_LCDC_TCON0_DCLK_ENABLE | |
| 546 | SUNXI_LCDC_TCON0_DCLK_DIV(clk_div), &lcdc->tcon0_dclk); |
| 547 | |
| 548 | writel(SUNXI_LCDC_X(mode->xres) | SUNXI_LCDC_Y(mode->yres), |
| 549 | &lcdc->tcon0_timing_active); |
| 550 | |
| 551 | bp = mode->hsync_len + mode->left_margin; |
| 552 | total = mode->xres + mode->right_margin + bp; |
| 553 | writel(SUNXI_LCDC_TCON0_TIMING_H_TOTAL(total) | |
| 554 | SUNXI_LCDC_TCON0_TIMING_H_BP(bp), &lcdc->tcon0_timing_h); |
| 555 | |
| 556 | bp = mode->vsync_len + mode->upper_margin; |
| 557 | total = mode->yres + mode->lower_margin + bp; |
| 558 | writel(SUNXI_LCDC_TCON0_TIMING_V_TOTAL(total) | |
| 559 | SUNXI_LCDC_TCON0_TIMING_V_BP(bp), &lcdc->tcon0_timing_v); |
| 560 | |
Hans de Goede | 213480e | 2015-01-01 22:04:34 +0100 | [diff] [blame] | 561 | #ifdef CONFIG_VIDEO_LCD_IF_PARALLEL |
Hans de Goede | 2dae800 | 2014-12-21 16:28:32 +0100 | [diff] [blame] | 562 | writel(SUNXI_LCDC_X(mode->hsync_len) | SUNXI_LCDC_Y(mode->vsync_len), |
| 563 | &lcdc->tcon0_timing_sync); |
| 564 | |
Hans de Goede | 2dae800 | 2014-12-21 16:28:32 +0100 | [diff] [blame] | 565 | writel(0, &lcdc->tcon0_hv_intf); |
| 566 | writel(0, &lcdc->tcon0_cpu_intf); |
Hans de Goede | 213480e | 2015-01-01 22:04:34 +0100 | [diff] [blame] | 567 | #endif |
| 568 | #ifdef CONFIG_VIDEO_LCD_IF_LVDS |
| 569 | val = (sunxi_display.depth == 18) ? 1 : 0; |
| 570 | writel(SUNXI_LCDC_TCON0_LVDS_INTF_BITWIDTH(val), &lcdc->tcon0_lvds_intf); |
| 571 | #endif |
Hans de Goede | 2dae800 | 2014-12-21 16:28:32 +0100 | [diff] [blame] | 572 | |
| 573 | if (sunxi_display.depth == 18 || sunxi_display.depth == 16) { |
| 574 | writel(SUNXI_LCDC_TCON0_FRM_SEED, &lcdc->tcon0_frm_seed[0]); |
| 575 | writel(SUNXI_LCDC_TCON0_FRM_SEED, &lcdc->tcon0_frm_seed[1]); |
| 576 | writel(SUNXI_LCDC_TCON0_FRM_SEED, &lcdc->tcon0_frm_seed[2]); |
| 577 | writel(SUNXI_LCDC_TCON0_FRM_SEED, &lcdc->tcon0_frm_seed[3]); |
| 578 | writel(SUNXI_LCDC_TCON0_FRM_SEED, &lcdc->tcon0_frm_seed[4]); |
| 579 | writel(SUNXI_LCDC_TCON0_FRM_SEED, &lcdc->tcon0_frm_seed[5]); |
| 580 | writel(SUNXI_LCDC_TCON0_FRM_TAB0, &lcdc->tcon0_frm_table[0]); |
| 581 | writel(SUNXI_LCDC_TCON0_FRM_TAB1, &lcdc->tcon0_frm_table[1]); |
| 582 | writel(SUNXI_LCDC_TCON0_FRM_TAB2, &lcdc->tcon0_frm_table[2]); |
| 583 | writel(SUNXI_LCDC_TCON0_FRM_TAB3, &lcdc->tcon0_frm_table[3]); |
| 584 | writel(((sunxi_display.depth == 18) ? |
| 585 | SUNXI_LCDC_TCON0_FRM_CTRL_RGB666 : |
| 586 | SUNXI_LCDC_TCON0_FRM_CTRL_RGB565), |
| 587 | &lcdc->tcon0_frm_ctrl); |
| 588 | } |
| 589 | |
Hans de Goede | 6515032 | 2015-01-13 13:21:46 +0100 | [diff] [blame] | 590 | val = SUNXI_LCDC_TCON0_IO_POL_DCLK_PHASE(CONFIG_VIDEO_LCD_DCLK_PHASE); |
Hans de Goede | 2dae800 | 2014-12-21 16:28:32 +0100 | [diff] [blame] | 591 | if (!(mode->sync & FB_SYNC_HOR_HIGH_ACT)) |
| 592 | val |= SUNXI_LCDC_TCON_HSYNC_MASK; |
| 593 | if (!(mode->sync & FB_SYNC_VERT_HIGH_ACT)) |
| 594 | val |= SUNXI_LCDC_TCON_VSYNC_MASK; |
| 595 | writel(val, &lcdc->tcon0_io_polarity); |
| 596 | |
| 597 | writel(0, &lcdc->tcon0_io_tristate); |
| 598 | } |
| 599 | |
Hans de Goede | d9786d2 | 2014-12-25 13:58:06 +0100 | [diff] [blame] | 600 | #if defined CONFIG_VIDEO_HDMI || defined CONFIG_VIDEO_VGA |
Hans de Goede | 0e04521 | 2014-12-21 14:49:34 +0100 | [diff] [blame] | 601 | static void sunxi_lcdc_tcon1_mode_set(const struct ctfb_res_modes *mode, |
Hans de Goede | 3ffbe47 | 2014-12-27 15:19:23 +0100 | [diff] [blame] | 602 | int *clk_div, int *clk_double, |
| 603 | bool use_portd_hvsync) |
Luc Verhaegen | 7f2c521 | 2014-08-13 07:55:06 +0200 | [diff] [blame] | 604 | { |
| 605 | struct sunxi_lcdc_reg * const lcdc = |
| 606 | (struct sunxi_lcdc_reg *)SUNXI_LCD0_BASE; |
Hans de Goede | 3ffbe47 | 2014-12-27 15:19:23 +0100 | [diff] [blame] | 607 | int bp, clk_delay, total, val; |
Luc Verhaegen | 7f2c521 | 2014-08-13 07:55:06 +0200 | [diff] [blame] | 608 | |
| 609 | /* Use tcon1 */ |
| 610 | clrsetbits_le32(&lcdc->ctrl, SUNXI_LCDC_CTRL_IO_MAP_MASK, |
| 611 | SUNXI_LCDC_CTRL_IO_MAP_TCON1); |
| 612 | |
Hans de Goede | 6741cc7 | 2014-12-24 19:50:11 +0100 | [diff] [blame] | 613 | clk_delay = sunxi_lcdc_get_clk_delay(mode); |
Luc Verhaegen | 7f2c521 | 2014-08-13 07:55:06 +0200 | [diff] [blame] | 614 | writel(SUNXI_LCDC_TCON1_CTRL_ENABLE | |
Hans de Goede | 6741cc7 | 2014-12-24 19:50:11 +0100 | [diff] [blame] | 615 | SUNXI_LCDC_TCON1_CTRL_CLK_DELAY(clk_delay), &lcdc->tcon1_ctrl); |
Luc Verhaegen | 7f2c521 | 2014-08-13 07:55:06 +0200 | [diff] [blame] | 616 | |
| 617 | writel(SUNXI_LCDC_X(mode->xres) | SUNXI_LCDC_Y(mode->yres), |
| 618 | &lcdc->tcon1_timing_source); |
| 619 | writel(SUNXI_LCDC_X(mode->xres) | SUNXI_LCDC_Y(mode->yres), |
| 620 | &lcdc->tcon1_timing_scale); |
| 621 | writel(SUNXI_LCDC_X(mode->xres) | SUNXI_LCDC_Y(mode->yres), |
| 622 | &lcdc->tcon1_timing_out); |
| 623 | |
| 624 | bp = mode->hsync_len + mode->left_margin; |
| 625 | total = mode->xres + mode->right_margin + bp; |
| 626 | writel(SUNXI_LCDC_TCON1_TIMING_H_TOTAL(total) | |
| 627 | SUNXI_LCDC_TCON1_TIMING_H_BP(bp), &lcdc->tcon1_timing_h); |
| 628 | |
| 629 | bp = mode->vsync_len + mode->upper_margin; |
| 630 | total = mode->yres + mode->lower_margin + bp; |
| 631 | writel(SUNXI_LCDC_TCON1_TIMING_V_TOTAL(total) | |
| 632 | SUNXI_LCDC_TCON1_TIMING_V_BP(bp), &lcdc->tcon1_timing_v); |
| 633 | |
| 634 | writel(SUNXI_LCDC_X(mode->hsync_len) | SUNXI_LCDC_Y(mode->vsync_len), |
| 635 | &lcdc->tcon1_timing_sync); |
| 636 | |
Hans de Goede | 3ffbe47 | 2014-12-27 15:19:23 +0100 | [diff] [blame] | 637 | if (use_portd_hvsync) { |
| 638 | sunxi_gpio_set_cfgpin(SUNXI_GPD(26), SUNXI_GPD0_LCD0); |
| 639 | sunxi_gpio_set_cfgpin(SUNXI_GPD(27), SUNXI_GPD0_LCD0); |
| 640 | |
| 641 | val = 0; |
| 642 | if (mode->sync & FB_SYNC_HOR_HIGH_ACT) |
| 643 | val |= SUNXI_LCDC_TCON_HSYNC_MASK; |
| 644 | if (mode->sync & FB_SYNC_VERT_HIGH_ACT) |
| 645 | val |= SUNXI_LCDC_TCON_VSYNC_MASK; |
| 646 | writel(val, &lcdc->tcon1_io_polarity); |
| 647 | |
| 648 | clrbits_le32(&lcdc->tcon1_io_tristate, |
| 649 | SUNXI_LCDC_TCON_VSYNC_MASK | |
| 650 | SUNXI_LCDC_TCON_HSYNC_MASK); |
| 651 | } |
Hans de Goede | 5489ebc | 2014-12-21 16:27:45 +0100 | [diff] [blame] | 652 | sunxi_lcdc_pll_set(1, mode->pixclock_khz, clk_div, clk_double); |
Luc Verhaegen | 7f2c521 | 2014-08-13 07:55:06 +0200 | [diff] [blame] | 653 | } |
Hans de Goede | d9786d2 | 2014-12-25 13:58:06 +0100 | [diff] [blame] | 654 | #endif /* CONFIG_VIDEO_HDMI || defined CONFIG_VIDEO_VGA */ |
| 655 | |
| 656 | #ifdef CONFIG_VIDEO_HDMI |
Luc Verhaegen | 7f2c521 | 2014-08-13 07:55:06 +0200 | [diff] [blame] | 657 | |
Hans de Goede | 5ee0bea | 2014-12-20 13:38:06 +0100 | [diff] [blame] | 658 | static void sunxi_hdmi_setup_info_frames(const struct ctfb_res_modes *mode) |
| 659 | { |
| 660 | struct sunxi_hdmi_reg * const hdmi = |
| 661 | (struct sunxi_hdmi_reg *)SUNXI_HDMI_BASE; |
| 662 | u8 checksum = 0; |
| 663 | u8 avi_info_frame[17] = { |
| 664 | 0x82, 0x02, 0x0d, 0x00, 0x12, 0x00, 0x88, 0x00, |
| 665 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 666 | 0x00 |
| 667 | }; |
| 668 | u8 vendor_info_frame[19] = { |
| 669 | 0x81, 0x01, 0x06, 0x29, 0x03, 0x0c, 0x00, 0x40, |
| 670 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 671 | 0x00, 0x00, 0x00 |
| 672 | }; |
| 673 | int i; |
| 674 | |
| 675 | if (mode->pixclock_khz <= 27000) |
| 676 | avi_info_frame[5] = 0x40; /* SD-modes, ITU601 colorspace */ |
| 677 | else |
| 678 | avi_info_frame[5] = 0x80; /* HD-modes, ITU709 colorspace */ |
| 679 | |
| 680 | if (mode->xres * 100 / mode->yres < 156) |
| 681 | avi_info_frame[5] |= 0x18; /* 4 : 3 */ |
| 682 | else |
| 683 | avi_info_frame[5] |= 0x28; /* 16 : 9 */ |
| 684 | |
| 685 | for (i = 0; i < ARRAY_SIZE(avi_info_frame); i++) |
| 686 | checksum += avi_info_frame[i]; |
| 687 | |
| 688 | avi_info_frame[3] = 0x100 - checksum; |
| 689 | |
| 690 | for (i = 0; i < ARRAY_SIZE(avi_info_frame); i++) |
| 691 | writeb(avi_info_frame[i], &hdmi->avi_info_frame[i]); |
| 692 | |
| 693 | writel(SUNXI_HDMI_QCP_PACKET0, &hdmi->qcp_packet0); |
| 694 | writel(SUNXI_HDMI_QCP_PACKET1, &hdmi->qcp_packet1); |
| 695 | |
| 696 | for (i = 0; i < ARRAY_SIZE(vendor_info_frame); i++) |
| 697 | writeb(vendor_info_frame[i], &hdmi->vendor_info_frame[i]); |
| 698 | |
| 699 | writel(SUNXI_HDMI_PKT_CTRL0, &hdmi->pkt_ctrl0); |
| 700 | writel(SUNXI_HDMI_PKT_CTRL1, &hdmi->pkt_ctrl1); |
| 701 | |
| 702 | setbits_le32(&hdmi->video_ctrl, SUNXI_HDMI_VIDEO_CTRL_HDMI); |
| 703 | } |
| 704 | |
Hans de Goede | be8ec63 | 2014-12-19 13:46:33 +0100 | [diff] [blame] | 705 | static void sunxi_hdmi_mode_set(const struct ctfb_res_modes *mode, |
Hans de Goede | 1c09220 | 2014-12-21 14:37:45 +0100 | [diff] [blame] | 706 | int clk_div, int clk_double) |
Luc Verhaegen | 7f2c521 | 2014-08-13 07:55:06 +0200 | [diff] [blame] | 707 | { |
| 708 | struct sunxi_hdmi_reg * const hdmi = |
| 709 | (struct sunxi_hdmi_reg *)SUNXI_HDMI_BASE; |
| 710 | int x, y; |
| 711 | |
| 712 | /* Write clear interrupt status bits */ |
| 713 | writel(SUNXI_HDMI_IRQ_STATUS_BITS, &hdmi->irq); |
| 714 | |
Hans de Goede | 1c09220 | 2014-12-21 14:37:45 +0100 | [diff] [blame] | 715 | if (sunxi_display.monitor == sunxi_monitor_hdmi) |
Hans de Goede | 5ee0bea | 2014-12-20 13:38:06 +0100 | [diff] [blame] | 716 | sunxi_hdmi_setup_info_frames(mode); |
| 717 | |
Hans de Goede | 876aaaf | 2014-12-20 13:51:16 +0100 | [diff] [blame] | 718 | /* Set input sync enable */ |
| 719 | writel(SUNXI_HDMI_UNKNOWN_INPUT_SYNC, &hdmi->unknown); |
| 720 | |
Luc Verhaegen | 7f2c521 | 2014-08-13 07:55:06 +0200 | [diff] [blame] | 721 | /* Init various registers, select pll3 as clock source */ |
| 722 | writel(SUNXI_HDMI_VIDEO_POL_TX_CLK, &hdmi->video_polarity); |
| 723 | writel(SUNXI_HDMI_PAD_CTRL0_RUN, &hdmi->pad_ctrl0); |
| 724 | writel(SUNXI_HDMI_PAD_CTRL1, &hdmi->pad_ctrl1); |
| 725 | writel(SUNXI_HDMI_PLL_CTRL, &hdmi->pll_ctrl); |
| 726 | writel(SUNXI_HDMI_PLL_DBG0_PLL3, &hdmi->pll_dbg0); |
| 727 | |
| 728 | /* Setup clk div and doubler */ |
| 729 | clrsetbits_le32(&hdmi->pll_ctrl, SUNXI_HDMI_PLL_CTRL_DIV_MASK, |
| 730 | SUNXI_HDMI_PLL_CTRL_DIV(clk_div)); |
| 731 | if (!clk_double) |
| 732 | setbits_le32(&hdmi->pad_ctrl1, SUNXI_HDMI_PAD_CTRL1_HALVE); |
| 733 | |
| 734 | /* Setup timing registers */ |
| 735 | writel(SUNXI_HDMI_Y(mode->yres) | SUNXI_HDMI_X(mode->xres), |
| 736 | &hdmi->video_size); |
| 737 | |
| 738 | x = mode->hsync_len + mode->left_margin; |
| 739 | y = mode->vsync_len + mode->upper_margin; |
| 740 | writel(SUNXI_HDMI_Y(y) | SUNXI_HDMI_X(x), &hdmi->video_bp); |
| 741 | |
| 742 | x = mode->right_margin; |
| 743 | y = mode->lower_margin; |
| 744 | writel(SUNXI_HDMI_Y(y) | SUNXI_HDMI_X(x), &hdmi->video_fp); |
| 745 | |
| 746 | x = mode->hsync_len; |
| 747 | y = mode->vsync_len; |
| 748 | writel(SUNXI_HDMI_Y(y) | SUNXI_HDMI_X(x), &hdmi->video_spw); |
| 749 | |
| 750 | if (mode->sync & FB_SYNC_HOR_HIGH_ACT) |
| 751 | setbits_le32(&hdmi->video_polarity, SUNXI_HDMI_VIDEO_POL_HOR); |
| 752 | |
| 753 | if (mode->sync & FB_SYNC_VERT_HIGH_ACT) |
| 754 | setbits_le32(&hdmi->video_polarity, SUNXI_HDMI_VIDEO_POL_VER); |
| 755 | } |
| 756 | |
Hans de Goede | 0e04521 | 2014-12-21 14:49:34 +0100 | [diff] [blame] | 757 | static void sunxi_hdmi_enable(void) |
| 758 | { |
| 759 | struct sunxi_hdmi_reg * const hdmi = |
| 760 | (struct sunxi_hdmi_reg *)SUNXI_HDMI_BASE; |
| 761 | |
| 762 | udelay(100); |
| 763 | setbits_le32(&hdmi->video_ctrl, SUNXI_HDMI_VIDEO_CTRL_ENABLE); |
| 764 | } |
| 765 | |
Hans de Goede | 2fbf091 | 2014-12-23 23:04:35 +0100 | [diff] [blame] | 766 | #endif /* CONFIG_VIDEO_HDMI */ |
| 767 | |
Hans de Goede | d9786d2 | 2014-12-25 13:58:06 +0100 | [diff] [blame] | 768 | #ifdef CONFIG_VIDEO_VGA |
| 769 | |
| 770 | static void sunxi_vga_mode_set(void) |
| 771 | { |
| 772 | struct sunxi_ccm_reg * const ccm = |
| 773 | (struct sunxi_ccm_reg *)SUNXI_CCM_BASE; |
| 774 | struct sunxi_tve_reg * const tve = |
| 775 | (struct sunxi_tve_reg *)SUNXI_TVE0_BASE; |
| 776 | |
| 777 | /* Clock on */ |
| 778 | setbits_le32(&ccm->ahb_gate1, 1 << AHB_GATE_OFFSET_TVE0); |
| 779 | |
| 780 | /* Set TVE in VGA mode */ |
| 781 | writel(SUNXI_TVE_GCTRL_DAC_INPUT(0, 1) | |
| 782 | SUNXI_TVE_GCTRL_DAC_INPUT(1, 2) | |
| 783 | SUNXI_TVE_GCTRL_DAC_INPUT(2, 3), &tve->gctrl); |
| 784 | writel(SUNXI_TVE_GCTRL_CFG0_VGA, &tve->cfg0); |
| 785 | writel(SUNXI_TVE_GCTRL_DAC_CFG0_VGA, &tve->dac_cfg0); |
| 786 | writel(SUNXI_TVE_GCTRL_UNKNOWN1_VGA, &tve->unknown1); |
| 787 | } |
| 788 | |
| 789 | static void sunxi_vga_enable(void) |
| 790 | { |
| 791 | struct sunxi_tve_reg * const tve = |
| 792 | (struct sunxi_tve_reg *)SUNXI_TVE0_BASE; |
| 793 | |
| 794 | setbits_le32(&tve->gctrl, SUNXI_TVE_GCTRL_ENABLE); |
| 795 | } |
| 796 | |
| 797 | #endif /* CONFIG_VIDEO_VGA */ |
| 798 | |
Hans de Goede | e840079 | 2014-12-23 18:39:52 +0100 | [diff] [blame] | 799 | static void sunxi_drc_init(void) |
| 800 | { |
Hans de Goede | 2fbf091 | 2014-12-23 23:04:35 +0100 | [diff] [blame] | 801 | #if defined CONFIG_MACH_SUN6I || defined CONFIG_MACH_SUN8I |
Hans de Goede | e840079 | 2014-12-23 18:39:52 +0100 | [diff] [blame] | 802 | struct sunxi_ccm_reg * const ccm = |
| 803 | (struct sunxi_ccm_reg *)SUNXI_CCM_BASE; |
| 804 | |
| 805 | /* On sun6i the drc must be clocked even when in pass-through mode */ |
| 806 | setbits_le32(&ccm->ahb_reset1_cfg, 1 << AHB_RESET_OFFSET_DRC0); |
| 807 | clock_set_de_mod_clock(&ccm->iep_drc0_clk_cfg, 300000000); |
| 808 | #endif |
| 809 | } |
| 810 | |
Chen-Yu Tsai | 507e27d | 2015-01-12 18:02:11 +0800 | [diff] [blame] | 811 | #ifdef CONFIG_VIDEO_VGA_VIA_LCD |
| 812 | static void sunxi_vga_external_dac_enable(void) |
| 813 | { |
| 814 | int pin; |
| 815 | |
| 816 | pin = sunxi_name_to_gpio(CONFIG_VIDEO_VGA_EXTERNAL_DAC_EN); |
| 817 | if (pin != -1) { |
| 818 | gpio_request(pin, "vga_enable"); |
| 819 | gpio_direction_output(pin, 1); |
| 820 | } |
| 821 | } |
| 822 | #endif /* CONFIG_VIDEO_VGA_VIA_LCD */ |
| 823 | |
Luc Verhaegen | 7f2c521 | 2014-08-13 07:55:06 +0200 | [diff] [blame] | 824 | static void sunxi_engines_init(void) |
| 825 | { |
| 826 | sunxi_composer_init(); |
| 827 | sunxi_lcdc_init(); |
Hans de Goede | 211717a | 2014-11-14 17:42:14 +0100 | [diff] [blame] | 828 | sunxi_drc_init(); |
Luc Verhaegen | 7f2c521 | 2014-08-13 07:55:06 +0200 | [diff] [blame] | 829 | } |
| 830 | |
Hans de Goede | 1c09220 | 2014-12-21 14:37:45 +0100 | [diff] [blame] | 831 | static void sunxi_mode_set(const struct ctfb_res_modes *mode, |
Hans de Goede | 5ee0bea | 2014-12-20 13:38:06 +0100 | [diff] [blame] | 832 | unsigned int address) |
Luc Verhaegen | 7f2c521 | 2014-08-13 07:55:06 +0200 | [diff] [blame] | 833 | { |
Hans de Goede | d9786d2 | 2014-12-25 13:58:06 +0100 | [diff] [blame] | 834 | int __maybe_unused clk_div, clk_double; |
| 835 | |
Hans de Goede | 0e04521 | 2014-12-21 14:49:34 +0100 | [diff] [blame] | 836 | switch (sunxi_display.monitor) { |
| 837 | case sunxi_monitor_none: |
| 838 | break; |
| 839 | case sunxi_monitor_dvi: |
Hans de Goede | d9786d2 | 2014-12-25 13:58:06 +0100 | [diff] [blame] | 840 | case sunxi_monitor_hdmi: |
Hans de Goede | 2fbf091 | 2014-12-23 23:04:35 +0100 | [diff] [blame] | 841 | #ifdef CONFIG_VIDEO_HDMI |
Hans de Goede | 0e04521 | 2014-12-21 14:49:34 +0100 | [diff] [blame] | 842 | sunxi_composer_mode_set(mode, address); |
Hans de Goede | 3ffbe47 | 2014-12-27 15:19:23 +0100 | [diff] [blame] | 843 | sunxi_lcdc_tcon1_mode_set(mode, &clk_div, &clk_double, 0); |
Hans de Goede | 0e04521 | 2014-12-21 14:49:34 +0100 | [diff] [blame] | 844 | sunxi_hdmi_mode_set(mode, clk_div, clk_double); |
| 845 | sunxi_composer_enable(); |
| 846 | sunxi_lcdc_enable(); |
| 847 | sunxi_hdmi_enable(); |
Hans de Goede | 2fbf091 | 2014-12-23 23:04:35 +0100 | [diff] [blame] | 848 | #endif |
Hans de Goede | 0e04521 | 2014-12-21 14:49:34 +0100 | [diff] [blame] | 849 | break; |
| 850 | case sunxi_monitor_lcd: |
Hans de Goede | 2dae800 | 2014-12-21 16:28:32 +0100 | [diff] [blame] | 851 | sunxi_lcdc_panel_enable(); |
| 852 | sunxi_composer_mode_set(mode, address); |
| 853 | sunxi_lcdc_tcon0_mode_set(mode); |
| 854 | sunxi_composer_enable(); |
| 855 | sunxi_lcdc_enable(); |
| 856 | sunxi_lcdc_backlight_enable(); |
Hans de Goede | 0e04521 | 2014-12-21 14:49:34 +0100 | [diff] [blame] | 857 | break; |
| 858 | case sunxi_monitor_vga: |
Hans de Goede | d9786d2 | 2014-12-25 13:58:06 +0100 | [diff] [blame] | 859 | #ifdef CONFIG_VIDEO_VGA |
| 860 | sunxi_composer_mode_set(mode, address); |
| 861 | sunxi_lcdc_tcon1_mode_set(mode, &clk_div, &clk_double, 1); |
| 862 | sunxi_vga_mode_set(); |
| 863 | sunxi_composer_enable(); |
| 864 | sunxi_lcdc_enable(); |
| 865 | sunxi_vga_enable(); |
| 866 | #elif defined CONFIG_VIDEO_VGA_VIA_LCD |
Hans de Goede | e2bbdfb | 2014-12-24 12:17:07 +0100 | [diff] [blame] | 867 | sunxi_composer_mode_set(mode, address); |
| 868 | sunxi_lcdc_tcon0_mode_set(mode); |
| 869 | sunxi_composer_enable(); |
| 870 | sunxi_lcdc_enable(); |
Chen-Yu Tsai | 507e27d | 2015-01-12 18:02:11 +0800 | [diff] [blame] | 871 | sunxi_vga_external_dac_enable(); |
Hans de Goede | e2bbdfb | 2014-12-24 12:17:07 +0100 | [diff] [blame] | 872 | #endif |
Hans de Goede | 0e04521 | 2014-12-21 14:49:34 +0100 | [diff] [blame] | 873 | break; |
| 874 | } |
Luc Verhaegen | 7f2c521 | 2014-08-13 07:55:06 +0200 | [diff] [blame] | 875 | } |
| 876 | |
Hans de Goede | 1c09220 | 2014-12-21 14:37:45 +0100 | [diff] [blame] | 877 | static const char *sunxi_get_mon_desc(enum sunxi_monitor monitor) |
| 878 | { |
| 879 | switch (monitor) { |
| 880 | case sunxi_monitor_none: return "none"; |
| 881 | case sunxi_monitor_dvi: return "dvi"; |
| 882 | case sunxi_monitor_hdmi: return "hdmi"; |
| 883 | case sunxi_monitor_lcd: return "lcd"; |
| 884 | case sunxi_monitor_vga: return "vga"; |
| 885 | } |
| 886 | return NULL; /* never reached */ |
| 887 | } |
| 888 | |
Luc Verhaegen | 7f2c521 | 2014-08-13 07:55:06 +0200 | [diff] [blame] | 889 | void *video_hw_init(void) |
| 890 | { |
| 891 | static GraphicDevice *graphic_device = &sunxi_display.graphic_device; |
Hans de Goede | 5f33993 | 2014-12-19 14:03:40 +0100 | [diff] [blame] | 892 | const struct ctfb_res_modes *mode; |
Hans de Goede | 2dae800 | 2014-12-21 16:28:32 +0100 | [diff] [blame] | 893 | struct ctfb_res_modes custom; |
Hans de Goede | 5f33993 | 2014-12-19 14:03:40 +0100 | [diff] [blame] | 894 | const char *options; |
Hans de Goede | 2fbf091 | 2014-12-23 23:04:35 +0100 | [diff] [blame] | 895 | #ifdef CONFIG_VIDEO_HDMI |
Hans de Goede | 7fad8a9 | 2014-12-28 09:13:21 +0100 | [diff] [blame] | 896 | int ret, hpd, hpd_delay, edid; |
Hans de Goede | 2fbf091 | 2014-12-23 23:04:35 +0100 | [diff] [blame] | 897 | #endif |
Hans de Goede | 1c09220 | 2014-12-21 14:37:45 +0100 | [diff] [blame] | 898 | char mon[16]; |
Hans de Goede | 2dae800 | 2014-12-21 16:28:32 +0100 | [diff] [blame] | 899 | char *lcd_mode = CONFIG_VIDEO_LCD_MODE; |
Hans de Goede | 2fbf091 | 2014-12-23 23:04:35 +0100 | [diff] [blame] | 900 | int i; |
Luc Verhaegen | 7f2c521 | 2014-08-13 07:55:06 +0200 | [diff] [blame] | 901 | |
| 902 | memset(&sunxi_display, 0, sizeof(struct sunxi_display)); |
| 903 | |
| 904 | printf("Reserved %dkB of RAM for Framebuffer.\n", |
| 905 | CONFIG_SUNXI_FB_SIZE >> 10); |
| 906 | gd->fb_base = gd->ram_top; |
| 907 | |
Hans de Goede | 2dae800 | 2014-12-21 16:28:32 +0100 | [diff] [blame] | 908 | video_get_ctfb_res_modes(RES_MODE_1024x768, 24, &mode, |
| 909 | &sunxi_display.depth, &options); |
Hans de Goede | 2fbf091 | 2014-12-23 23:04:35 +0100 | [diff] [blame] | 910 | #ifdef CONFIG_VIDEO_HDMI |
Hans de Goede | 518cef2 | 2014-12-19 15:13:57 +0100 | [diff] [blame] | 911 | hpd = video_get_option_int(options, "hpd", 1); |
Hans de Goede | 7fad8a9 | 2014-12-28 09:13:21 +0100 | [diff] [blame] | 912 | hpd_delay = video_get_option_int(options, "hpd_delay", 500); |
Hans de Goede | 7548160 | 2014-12-19 16:05:12 +0100 | [diff] [blame] | 913 | edid = video_get_option_int(options, "edid", 1); |
Hans de Goede | 1c09220 | 2014-12-21 14:37:45 +0100 | [diff] [blame] | 914 | sunxi_display.monitor = sunxi_monitor_dvi; |
Hans de Goede | e2bbdfb | 2014-12-24 12:17:07 +0100 | [diff] [blame] | 915 | #elif defined CONFIG_VIDEO_VGA_VIA_LCD |
| 916 | sunxi_display.monitor = sunxi_monitor_vga; |
Hans de Goede | 2fbf091 | 2014-12-23 23:04:35 +0100 | [diff] [blame] | 917 | #else |
| 918 | sunxi_display.monitor = sunxi_monitor_lcd; |
| 919 | #endif |
Hans de Goede | 1c09220 | 2014-12-21 14:37:45 +0100 | [diff] [blame] | 920 | video_get_option_string(options, "monitor", mon, sizeof(mon), |
| 921 | sunxi_get_mon_desc(sunxi_display.monitor)); |
| 922 | for (i = 0; i <= SUNXI_MONITOR_LAST; i++) { |
| 923 | if (strcmp(mon, sunxi_get_mon_desc(i)) == 0) { |
| 924 | sunxi_display.monitor = i; |
| 925 | break; |
| 926 | } |
| 927 | } |
| 928 | if (i > SUNXI_MONITOR_LAST) |
| 929 | printf("Unknown monitor: '%s', falling back to '%s'\n", |
| 930 | mon, sunxi_get_mon_desc(sunxi_display.monitor)); |
Hans de Goede | 5f33993 | 2014-12-19 14:03:40 +0100 | [diff] [blame] | 931 | |
Hans de Goede | 49d2703 | 2014-12-25 13:52:04 +0100 | [diff] [blame] | 932 | #ifdef CONFIG_VIDEO_HDMI |
| 933 | /* If HDMI/DVI is selected do HPD & EDID, and handle fallback */ |
| 934 | if (sunxi_display.monitor == sunxi_monitor_dvi || |
| 935 | sunxi_display.monitor == sunxi_monitor_hdmi) { |
Hans de Goede | 0e04521 | 2014-12-21 14:49:34 +0100 | [diff] [blame] | 936 | /* Always call hdp_detect, as it also enables clocks, etc. */ |
Hans de Goede | 7fad8a9 | 2014-12-28 09:13:21 +0100 | [diff] [blame] | 937 | ret = sunxi_hdmi_hpd_detect(hpd_delay); |
Hans de Goede | 0e04521 | 2014-12-21 14:49:34 +0100 | [diff] [blame] | 938 | if (ret) { |
| 939 | printf("HDMI connected: "); |
Hans de Goede | 2dae800 | 2014-12-21 16:28:32 +0100 | [diff] [blame] | 940 | if (edid && sunxi_hdmi_edid_get_mode(&custom) == 0) |
| 941 | mode = &custom; |
Hans de Goede | 49d2703 | 2014-12-25 13:52:04 +0100 | [diff] [blame] | 942 | } else if (hpd) { |
| 943 | sunxi_hdmi_shutdown(); |
| 944 | /* Fallback to lcd / vga / none */ |
| 945 | if (lcd_mode[0]) { |
| 946 | sunxi_display.monitor = sunxi_monitor_lcd; |
| 947 | } else { |
Hans de Goede | d9786d2 | 2014-12-25 13:58:06 +0100 | [diff] [blame] | 948 | #if defined CONFIG_VIDEO_VGA_VIA_LCD || defined CONFIG_VIDEO_VGA |
Hans de Goede | 49d2703 | 2014-12-25 13:52:04 +0100 | [diff] [blame] | 949 | sunxi_display.monitor = sunxi_monitor_vga; |
| 950 | #else |
| 951 | sunxi_display.monitor = sunxi_monitor_none; |
| 952 | #endif |
| 953 | } |
| 954 | } /* else continue with hdmi/dvi without a cable connected */ |
| 955 | } |
| 956 | #endif |
Hans de Goede | 0e04521 | 2014-12-21 14:49:34 +0100 | [diff] [blame] | 957 | |
Hans de Goede | 49d2703 | 2014-12-25 13:52:04 +0100 | [diff] [blame] | 958 | switch (sunxi_display.monitor) { |
| 959 | case sunxi_monitor_none: |
| 960 | return NULL; |
| 961 | case sunxi_monitor_dvi: |
| 962 | case sunxi_monitor_hdmi: |
| 963 | #ifdef CONFIG_VIDEO_HDMI |
| 964 | break; |
| 965 | #else |
| 966 | printf("HDMI/DVI not supported on this board\n"); |
| 967 | sunxi_display.monitor = sunxi_monitor_none; |
| 968 | return NULL; |
Hans de Goede | 2fbf091 | 2014-12-23 23:04:35 +0100 | [diff] [blame] | 969 | #endif |
Hans de Goede | 0e04521 | 2014-12-21 14:49:34 +0100 | [diff] [blame] | 970 | case sunxi_monitor_lcd: |
Hans de Goede | 2dae800 | 2014-12-21 16:28:32 +0100 | [diff] [blame] | 971 | if (lcd_mode[0]) { |
| 972 | sunxi_display.depth = video_get_params(&custom, lcd_mode); |
| 973 | mode = &custom; |
| 974 | break; |
| 975 | } |
Hans de Goede | 0e04521 | 2014-12-21 14:49:34 +0100 | [diff] [blame] | 976 | printf("LCD not supported on this board\n"); |
Hans de Goede | b98d048 | 2014-12-24 19:47:14 +0100 | [diff] [blame] | 977 | sunxi_display.monitor = sunxi_monitor_none; |
Hans de Goede | 0e04521 | 2014-12-21 14:49:34 +0100 | [diff] [blame] | 978 | return NULL; |
| 979 | case sunxi_monitor_vga: |
Hans de Goede | d9786d2 | 2014-12-25 13:58:06 +0100 | [diff] [blame] | 980 | #if defined CONFIG_VIDEO_VGA_VIA_LCD || defined CONFIG_VIDEO_VGA |
Hans de Goede | e2bbdfb | 2014-12-24 12:17:07 +0100 | [diff] [blame] | 981 | sunxi_display.depth = 18; |
| 982 | break; |
| 983 | #else |
Hans de Goede | 0e04521 | 2014-12-21 14:49:34 +0100 | [diff] [blame] | 984 | printf("VGA not supported on this board\n"); |
Hans de Goede | b98d048 | 2014-12-24 19:47:14 +0100 | [diff] [blame] | 985 | sunxi_display.monitor = sunxi_monitor_none; |
Hans de Goede | 0e04521 | 2014-12-21 14:49:34 +0100 | [diff] [blame] | 986 | return NULL; |
Hans de Goede | e2bbdfb | 2014-12-24 12:17:07 +0100 | [diff] [blame] | 987 | #endif |
Hans de Goede | 7548160 | 2014-12-19 16:05:12 +0100 | [diff] [blame] | 988 | } |
| 989 | |
Hans de Goede | 5f33993 | 2014-12-19 14:03:40 +0100 | [diff] [blame] | 990 | if (mode->vmode != FB_VMODE_NONINTERLACED) { |
| 991 | printf("Only non-interlaced modes supported, falling back to 1024x768\n"); |
| 992 | mode = &res_mode_init[RES_MODE_1024x768]; |
| 993 | } else { |
Hans de Goede | 1c09220 | 2014-12-21 14:37:45 +0100 | [diff] [blame] | 994 | printf("Setting up a %dx%d %s console\n", mode->xres, |
| 995 | mode->yres, sunxi_get_mon_desc(sunxi_display.monitor)); |
Hans de Goede | 5f33993 | 2014-12-19 14:03:40 +0100 | [diff] [blame] | 996 | } |
| 997 | |
Luc Verhaegen | 7f2c521 | 2014-08-13 07:55:06 +0200 | [diff] [blame] | 998 | sunxi_engines_init(); |
Hans de Goede | 1c09220 | 2014-12-21 14:37:45 +0100 | [diff] [blame] | 999 | sunxi_mode_set(mode, gd->fb_base - CONFIG_SYS_SDRAM_BASE); |
Luc Verhaegen | 7f2c521 | 2014-08-13 07:55:06 +0200 | [diff] [blame] | 1000 | |
| 1001 | /* |
| 1002 | * These are the only members of this structure that are used. All the |
| 1003 | * others are driver specific. There is nothing to decribe pitch or |
| 1004 | * stride, but we are lucky with our hw. |
| 1005 | */ |
| 1006 | graphic_device->frameAdrs = gd->fb_base; |
| 1007 | graphic_device->gdfIndex = GDF_32BIT_X888RGB; |
| 1008 | graphic_device->gdfBytesPP = 4; |
Hans de Goede | be8ec63 | 2014-12-19 13:46:33 +0100 | [diff] [blame] | 1009 | graphic_device->winSizeX = mode->xres; |
| 1010 | graphic_device->winSizeY = mode->yres; |
Luc Verhaegen | 7f2c521 | 2014-08-13 07:55:06 +0200 | [diff] [blame] | 1011 | |
| 1012 | return graphic_device; |
| 1013 | } |
Luc Verhaegen | 2d7a084 | 2014-08-13 07:55:07 +0200 | [diff] [blame] | 1014 | |
| 1015 | /* |
| 1016 | * Simplefb support. |
| 1017 | */ |
| 1018 | #if defined(CONFIG_OF_BOARD_SETUP) && defined(CONFIG_VIDEO_DT_SIMPLEFB) |
| 1019 | int sunxi_simplefb_setup(void *blob) |
| 1020 | { |
| 1021 | static GraphicDevice *graphic_device = &sunxi_display.graphic_device; |
| 1022 | int offset, ret; |
Hans de Goede | 2dae800 | 2014-12-21 16:28:32 +0100 | [diff] [blame] | 1023 | const char *pipeline = NULL; |
Luc Verhaegen | 2d7a084 | 2014-08-13 07:55:07 +0200 | [diff] [blame] | 1024 | |
Hans de Goede | 2dae800 | 2014-12-21 16:28:32 +0100 | [diff] [blame] | 1025 | switch (sunxi_display.monitor) { |
| 1026 | case sunxi_monitor_none: |
| 1027 | return 0; |
| 1028 | case sunxi_monitor_dvi: |
| 1029 | case sunxi_monitor_hdmi: |
| 1030 | pipeline = "de_be0-lcd0-hdmi"; |
| 1031 | break; |
| 1032 | case sunxi_monitor_lcd: |
| 1033 | pipeline = "de_be0-lcd0"; |
| 1034 | break; |
| 1035 | case sunxi_monitor_vga: |
Hans de Goede | d9786d2 | 2014-12-25 13:58:06 +0100 | [diff] [blame] | 1036 | #ifdef CONFIG_VIDEO_VGA |
| 1037 | pipeline = "de_be0-lcd0-tve0"; |
| 1038 | #elif defined CONFIG_VIDEO_VGA_VIA_LCD |
Hans de Goede | e2bbdfb | 2014-12-24 12:17:07 +0100 | [diff] [blame] | 1039 | pipeline = "de_be0-lcd0"; |
Hans de Goede | d9786d2 | 2014-12-25 13:58:06 +0100 | [diff] [blame] | 1040 | #endif |
Hans de Goede | 2dae800 | 2014-12-21 16:28:32 +0100 | [diff] [blame] | 1041 | break; |
| 1042 | } |
| 1043 | |
| 1044 | /* Find a prefilled simpefb node, matching out pipeline config */ |
Luc Verhaegen | 2d7a084 | 2014-08-13 07:55:07 +0200 | [diff] [blame] | 1045 | offset = fdt_node_offset_by_compatible(blob, -1, |
| 1046 | "allwinner,simple-framebuffer"); |
| 1047 | while (offset >= 0) { |
| 1048 | ret = fdt_find_string(blob, offset, "allwinner,pipeline", |
Hans de Goede | 2dae800 | 2014-12-21 16:28:32 +0100 | [diff] [blame] | 1049 | pipeline); |
Luc Verhaegen | 2d7a084 | 2014-08-13 07:55:07 +0200 | [diff] [blame] | 1050 | if (ret == 0) |
| 1051 | break; |
| 1052 | offset = fdt_node_offset_by_compatible(blob, offset, |
| 1053 | "allwinner,simple-framebuffer"); |
| 1054 | } |
| 1055 | if (offset < 0) { |
| 1056 | eprintf("Cannot setup simplefb: node not found\n"); |
| 1057 | return 0; /* Keep older kernels working */ |
| 1058 | } |
| 1059 | |
| 1060 | ret = fdt_setup_simplefb_node(blob, offset, gd->fb_base, |
| 1061 | graphic_device->winSizeX, graphic_device->winSizeY, |
| 1062 | graphic_device->winSizeX * graphic_device->gdfBytesPP, |
| 1063 | "x8r8g8b8"); |
| 1064 | if (ret) |
| 1065 | eprintf("Cannot setup simplefb: Error setting properties\n"); |
| 1066 | |
| 1067 | return ret; |
| 1068 | } |
| 1069 | #endif /* CONFIG_OF_BOARD_SETUP && CONFIG_VIDEO_DT_SIMPLEFB */ |