Path: blob/master/arch/arm/mach-rpc/include/mach/acornfb.h
15162 views
/*1* arch/arm/mach-rpc/include/mach/acornfb.h2*3* Copyright (C) 1999 Russell King4*5* This program is free software; you can redistribute it and/or modify6* it under the terms of the GNU General Public License version 2 as7* published by the Free Software Foundation.8*9* AcornFB architecture specific code10*/1112#define acornfb_bandwidth(var) ((var)->pixclock * 8 / (var)->bits_per_pixel)1314static inline int15acornfb_valid_pixrate(struct fb_var_screeninfo *var)16{17u_long limit;1819if (!var->pixclock)20return 0;2122/*23* Limits below are taken from RISC OS bandwidthlimit file24*/25if (current_par.using_vram) {26if (current_par.vram_half_sam == 2048)27limit = 6578;28else29limit = 13157;30} else {31limit = 26315;32}3334return acornfb_bandwidth(var) >= limit;35}3637/*38* Try to find the best PLL parameters for the pixel clock.39* This algorithm seems to give best predictable results,40* and produces the same values as detailed in the VIDC2041* data sheet.42*/43static inline u_int44acornfb_vidc20_find_pll(u_int pixclk)45{46u_int r, best_r = 2, best_v = 2;47int best_d = 0x7fffffff;4849for (r = 2; r <= 32; r++) {50u_int rr, v, p;51int d;5253rr = 41667 * r;5455v = (rr + pixclk / 2) / pixclk;5657if (v > 32 || v < 2)58continue;5960p = (rr + v / 2) / v;6162d = pixclk - p;6364if (d < 0)65d = -d;6667if (d < best_d) {68best_d = d;69best_v = v - 1;70best_r = r - 1;71}7273if (d == 0)74break;75}7677return best_v << 8 | best_r;78}7980static inline void81acornfb_vidc20_find_rates(struct vidc_timing *vidc,82struct fb_var_screeninfo *var)83{84u_int div;8586/* Select pixel-clock divisor to keep PLL in range */87div = var->pixclock / 9090; /*9921*/8889/* Limit divisor */90if (div == 0)91div = 1;92if (div > 8)93div = 8;9495/* Encode divisor to VIDC20 setting */96switch (div) {97case 1: vidc->control |= VIDC20_CTRL_PIX_CK; break;98case 2: vidc->control |= VIDC20_CTRL_PIX_CK2; break;99case 3: vidc->control |= VIDC20_CTRL_PIX_CK3; break;100case 4: vidc->control |= VIDC20_CTRL_PIX_CK4; break;101case 5: vidc->control |= VIDC20_CTRL_PIX_CK5; break;102case 6: vidc->control |= VIDC20_CTRL_PIX_CK6; break;103case 7: vidc->control |= VIDC20_CTRL_PIX_CK7; break;104case 8: vidc->control |= VIDC20_CTRL_PIX_CK8; break;105}106107/*108* With VRAM, the FIFO can be set to the highest possible setting109* because there are no latency considerations for other memory110* accesses. However, in 64 bit bus mode the FIFO preload value111* must not be set to VIDC20_CTRL_FIFO_28 because this will let112* the FIFO overflow. See VIDC20 manual page 33 (6.0 Setting the113* FIFO preload value).114*/115if (current_par.using_vram) {116if (current_par.vram_half_sam == 2048)117vidc->control |= VIDC20_CTRL_FIFO_24;118else119vidc->control |= VIDC20_CTRL_FIFO_28;120} else {121unsigned long bandwidth = acornfb_bandwidth(var);122123/* Encode bandwidth as VIDC20 setting */124if (bandwidth > 33334) /* < 30.0MB/s */125vidc->control |= VIDC20_CTRL_FIFO_16;126else if (bandwidth > 26666) /* < 37.5MB/s */127vidc->control |= VIDC20_CTRL_FIFO_20;128else if (bandwidth > 22222) /* < 45.0MB/s */129vidc->control |= VIDC20_CTRL_FIFO_24;130else /* > 45.0MB/s */131vidc->control |= VIDC20_CTRL_FIFO_28;132}133134/* Find the PLL values */135vidc->pll_ctl = acornfb_vidc20_find_pll(var->pixclock / div);136}137138#define acornfb_default_control() (VIDC20_CTRL_PIX_VCLK)139#define acornfb_default_econtrol() (VIDC20_ECTL_DAC | VIDC20_ECTL_REG(3))140141142