21 #include <linux/i2c.h>
53 #define INTEL_P2_NUM 2
60 #define I8XX_DOT_MIN 25000
61 #define I8XX_DOT_MAX 350000
62 #define I8XX_VCO_MIN 930000
63 #define I8XX_VCO_MAX 1400000
67 #define I8XX_M_MAX 140
68 #define I8XX_M1_MIN 18
69 #define I8XX_M1_MAX 26
71 #define I8XX_M2_MAX 16
73 #define I8XX_P_MAX 128
75 #define I8XX_P1_MAX 33
76 #define I8XX_P1_LVDS_MIN 1
77 #define I8XX_P1_LVDS_MAX 6
78 #define I8XX_P2_SLOW 4
79 #define I8XX_P2_FAST 2
80 #define I8XX_P2_LVDS_SLOW 14
81 #define I8XX_P2_LVDS_FAST 14
82 #define I8XX_P2_SLOW_LIMIT 165000
84 #define I9XX_DOT_MIN 20000
85 #define I9XX_DOT_MAX 400000
86 #define I9XX_VCO_MIN 1400000
87 #define I9XX_VCO_MAX 2800000
91 #define I9XX_M_MAX 120
92 #define I9XX_M1_MIN 10
93 #define I9XX_M1_MAX 20
96 #define I9XX_P_SDVO_DAC_MIN 5
97 #define I9XX_P_SDVO_DAC_MAX 80
98 #define I9XX_P_LVDS_MIN 7
99 #define I9XX_P_LVDS_MAX 98
100 #define I9XX_P1_MIN 1
101 #define I9XX_P1_MAX 8
102 #define I9XX_P2_SDVO_DAC_SLOW 10
103 #define I9XX_P2_SDVO_DAC_FAST 5
104 #define I9XX_P2_SDVO_DAC_SLOW_LIMIT 200000
105 #define I9XX_P2_LVDS_SLOW 14
106 #define I9XX_P2_LVDS_FAST 7
107 #define I9XX_P2_LVDS_SLOW_LIMIT 112000
109 #define INTEL_LIMIT_I8XX_DVO_DAC 0
110 #define INTEL_LIMIT_I8XX_LVDS 1
111 #define INTEL_LIMIT_I9XX_SDVO_DAC 2
112 #define INTEL_LIMIT_I9XX_LVDS 3
184 clock->
m = 5 * (clock->
m1 + 2) + (clock->
m2 + 2);
185 clock->
p = clock->
p1 * clock->
p2;
186 clock->
vco = refclk * clock->
m / (clock->
n + 2);
187 clock->
dot = clock->
vco / clock->
p;
194 clock->
m = 5 * (clock->
m1 + 2) + (clock->
m2 + 2);
195 clock->
p = clock->
p1 * clock->
p2;
196 clock->
vco = refclk * clock->
m / (clock->
n + 2);
197 clock->
dot = clock->
vco / clock->
p;
200 static void psb_intel_clock(
struct drm_device *
dev,
int refclk,
203 return i9xx_clock(refclk, clock);
218 psb_intel_attached_encoder(l_entry);
219 if (psb_intel_encoder->
type == type)
226 #define INTELPllInvalid(s) { ; return false; }
232 static bool psb_intel_PLL_is_valid(
struct drm_crtc *crtc,
237 if (clock->
p1 < limit->
p1.min || limit->
p1.max < clock->
p1)
239 if (clock->
p < limit->p.min || limit->p.max < clock->
p)
241 if (clock->
m2 < limit->m2.min || limit->m2.max < clock->
m2)
243 if (clock->
m1 < limit->m1.min || limit->m1.max < clock->
m1)
245 if (clock->
m1 <= clock->
m2)
247 if (clock->
m < limit->m.min || limit->m.max < clock->
m)
249 if (clock->
n < limit->n.min || limit->n.max < clock->
n)
251 if (clock->
vco < limit->vco.min || limit->vco.max < clock->
vco)
257 if (clock->
dot < limit->dot.min || limit->dot.max < clock->
dot)
268 static bool psb_intel_find_best_PLL(
struct drm_crtc *crtc,
int target,
287 clock.
p2 = limit->
p2.p2_fast;
289 clock.
p2 = limit->
p2.p2_slow;
291 if (target < limit->
p2.dot_limit)
292 clock.
p2 = limit->
p2.p2_slow;
294 clock.
p2 = limit->
p2.p2_fast;
297 memset(best_clock, 0,
sizeof(*best_clock));
299 for (clock.
m1 = limit->m1.min; clock.
m1 <= limit->m1.max;
301 for (clock.
m2 = limit->m2.min;
302 clock.
m2 < clock.
m1 && clock.
m2 <= limit->m2.max;
304 for (clock.
n = limit->n.min;
305 clock.
n <= limit->n.max; clock.
n++) {
306 for (clock.
p1 = limit->
p1.min;
307 clock.
p1 <= limit->
p1.max;
311 psb_intel_clock(dev, refclk, &clock);
313 if (!psb_intel_PLL_is_valid
317 this_err =
abs(clock.
dot - target);
318 if (this_err < err) {
336 static int psb_intel_pipe_set_base(
struct drm_crtc *crtc,
354 dev_dbg(dev->dev,
"No FB bound\n");
355 goto psb_intel_pipe_cleaner;
362 goto psb_intel_pipe_set_base_exit;
363 start = psbfb->
gtt->offset;
365 offset = y * crtc->
fb->pitches[0] + x * (crtc->
fb->bits_per_pixel / 8);
372 switch (crtc->
fb->bits_per_pixel) {
377 if (crtc->
fb->depth == 15)
387 dev_err(dev->dev,
"Unknown color depth\n");
390 goto psb_intel_pipe_set_base_exit;
397 psb_intel_pipe_cleaner:
402 psb_intel_pipe_set_base_exit:
413 static void psb_intel_crtc_dpms(
struct drm_crtc *crtc,
int mode)
418 int pipe = psb_intel_crtc->
pipe;
455 temp | DISPLAY_PLANE_ENABLE);
476 if ((temp & DISPLAY_PLANE_ENABLE) != 0) {
478 temp & ~DISPLAY_PLANE_ENABLE);
486 if ((temp & PIPEACONF_ENABLE) != 0) {
495 if ((temp & DPLL_VCO_ENABLE) != 0) {
509 static void psb_intel_crtc_prepare(
struct drm_crtc *crtc)
515 static void psb_intel_crtc_commit(
struct drm_crtc *crtc)
542 kfree(intel_encoder);
545 static bool psb_intel_crtc_mode_fixup(
struct drm_crtc *crtc,
557 static int psb_intel_panel_fitter_pipe(
struct drm_device *dev)
570 static int psb_intel_crtc_mode_set(
struct drm_crtc *crtc,
580 int pipe = psb_intel_crtc->
pipe;
584 u32 dpll = 0,
fp = 0, dspcntr, pipeconf;
585 bool ok, is_sdvo =
false;
586 bool is_lvds =
false, is_tv =
false;
598 psb_intel_attached_encoder(connector);
601 || connector->
encoder->crtc != crtc)
604 switch (psb_intel_encoder->
type) {
619 ok = psb_intel_find_best_PLL(crtc, adjusted_mode->
clock, refclk,
622 dev_err(dev->dev,
"Couldn't find PLL settings for mode!\n");
626 fp = clock.
n << 16 | clock.
m1 << 8 | clock.
m2;
635 int sdvo_pixel_multiply =
643 dpll |= (1 << (clock.
p1 - 1)) << 16;
683 if (psb_intel_panel_fitter_pipe(dev) == pipe)
688 if (dpll & DPLL_VCO_ENABLE) {
786 switch (psb_intel_crtc->
pipe) {
791 dev_err(dev->dev,
"Illegal Pipe Number.\n");
796 for (i = 0; i < 256; i++) {
798 ((psb_intel_crtc->
lut_r[i] +
799 psb_intel_crtc->
lut_adj[i]) << 16) |
800 ((psb_intel_crtc->
lut_g[i] +
801 psb_intel_crtc->
lut_adj[i]) << 8) |
802 (psb_intel_crtc->
lut_b[i] +
807 for (i = 0; i < 256; i++) {
808 dev_priv->
regs.pipe[0].palette[
i] =
809 ((psb_intel_crtc->
lut_r[
i] +
810 psb_intel_crtc->
lut_adj[
i]) << 16) |
811 ((psb_intel_crtc->
lut_g[
i] +
813 (psb_intel_crtc->
lut_b[
i] +
823 static void psb_intel_crtc_save(
struct drm_crtc *crtc)
834 dev_err(dev->dev,
"No CRTC state found\n");
859 for (i = 0; i < 256; ++
i)
866 static void psb_intel_crtc_restore(
struct drm_crtc *crtc)
877 dev_err(dev->dev,
"No crtc state\n");
881 if (crtc_state->
saveDPLL & DPLL_VCO_ENABLE) {
883 crtc_state->
saveDPLL & ~DPLL_VCO_ENABLE);
921 for (i = 0; i < 256; ++
i)
925 static int psb_intel_crtc_cursor_set(
struct drm_crtc *crtc,
926 struct drm_file *file_priv,
933 int pipe = psb_intel_crtc->
pipe;
940 struct drm_gem_object *obj;
941 void *tmp_dst, *tmp_src;
942 int ret,
i, cursor_pages;
960 drm_gem_object_unreference(psb_intel_crtc->
cursor_obj);
968 if (width != 64 || height != 64) {
969 dev_dbg(dev->dev,
"we currently only support 64x64 cursors\n");
977 if (obj->size < width * height * 4) {
978 dev_dbg(dev->dev,
"buffer is to small\n");
987 dev_err(dev->dev,
"Can not pin down handle 0x%x\n", handle);
991 if (dev_priv->
ops->cursor_needs_phys) {
992 if (cursor_gt ==
NULL) {
993 dev_err(dev->dev,
"No hardware cursor mem available");
1001 cursor_pages = gt->
npage;
1005 for (i = 0; i < cursor_pages; i++) {
1020 temp |= (pipe << 28);
1034 drm_gem_object_unreference(psb_intel_crtc->
cursor_obj);
1040 static int psb_intel_crtc_cursor_move(
struct drm_crtc *crtc,
int x,
int y)
1044 int pipe = psb_intel_crtc->
pipe;
1080 for (i = 0; i < 256; i++) {
1081 psb_intel_crtc->
lut_r[
i] = red[
i] >> 8;
1082 psb_intel_crtc->
lut_g[
i] = green[
i] >> 8;
1083 psb_intel_crtc->
lut_b[
i] = blue[
i] >> 8;
1089 static int psb_crtc_set_config(
struct drm_mode_set *
set)
1105 static int psb_intel_crtc_clock_get(
struct drm_device *dev,
1110 int pipe = psb_intel_crtc->
pipe;
1129 if ((dpll & DISPLAY_RATE_SELECT_FPA1) == 0)
1134 is_lvds = (pipe == 1) && (dev_priv->
regs.psb.saveLVDS &
1152 i8xx_clock(66000, &clock);
1154 i8xx_clock(48000, &clock);
1169 i8xx_clock(48000, &clock);
1185 int pipe = psb_intel_crtc->
pipe;
1212 mode->
clock = psb_intel_crtc_clock_get(dev, crtc);
1213 mode->
hdisplay = (htot & 0xffff) + 1;
1214 mode->
htotal = ((htot & 0xffff0000) >> 16) + 1;
1216 mode->
hsync_end = ((hsync & 0xffff0000) >> 16) + 1;
1217 mode->
vdisplay = (vtot & 0xffff) + 1;
1218 mode->
vtotal = ((vtot & 0xffff0000) >> 16) + 1;
1220 mode->
vsync_end = ((vsync & 0xffff0000) >> 16) + 1;
1238 drm_gem_object_unreference(psb_intel_crtc->
cursor_obj);
1246 kfree(psb_intel_crtc);
1250 .dpms = psb_intel_crtc_dpms,
1251 .mode_fixup = psb_intel_crtc_mode_fixup,
1252 .mode_set = psb_intel_crtc_mode_set,
1253 .mode_set_base = psb_intel_pipe_set_base,
1254 .prepare = psb_intel_crtc_prepare,
1255 .commit = psb_intel_crtc_commit,
1259 .save = psb_intel_crtc_save,
1260 .restore = psb_intel_crtc_restore,
1261 .cursor_set = psb_intel_crtc_cursor_set,
1262 .cursor_move = psb_intel_crtc_cursor_move,
1264 .set_config = psb_crtc_set_config,
1272 static void psb_intel_cursor_init(
struct drm_device *dev,
1273 struct psb_intel_crtc *psb_intel_crtc)
1280 if (dev_priv->
ops->cursor_needs_phys) {
1305 struct psb_intel_crtc *psb_intel_crtc;
1312 kzalloc(
sizeof(
struct psb_intel_crtc) +
1315 if (psb_intel_crtc ==
NULL)
1321 dev_err(dev->dev,
"Crtc state error: No memory\n");
1322 kfree(psb_intel_crtc);
1333 r_base = psb_intel_crtc->
base.gamma_store;
1334 g_base = r_base + 256;
1335 b_base = g_base + 256;
1336 for (i = 0; i < 256; i++) {
1350 drm_crtc_helper_add(&psb_intel_crtc->
base,
1351 dev_priv->
ops->crtc_helper);
1358 &psb_intel_crtc->
base;
1360 &psb_intel_crtc->
base;
1361 psb_intel_crtc->
mode_set.connectors =
1363 psb_intel_crtc->
mode_set.num_connectors = 0;
1364 psb_intel_cursor_init(dev, psb_intel_crtc);
1367 psb_intel_crtc->
active =
true;
1371 struct drm_file *file_priv)
1376 struct psb_intel_crtc *crtc;
1379 dev_err(dev->dev,
"called with no initialization\n");
1387 dev_err(dev->dev,
"no such CRTC id\n");
1392 pipe_from_crtc_id->
pipe = crtc->
pipe;
1403 if (psb_intel_crtc->
pipe == pipe)
1417 struct psb_intel_encoder *psb_intel_encoder =
1418 psb_intel_attached_encoder(connector);
1419 if (type_mask & (1 << psb_intel_encoder->
type))
1420 index_mask |= (1 <<
entry);
1431 struct psb_intel_encoder *psb_intel_encoder =
1432 psb_intel_attached_encoder(connector);
1434 return &psb_intel_encoder->
base;
1438 struct psb_intel_encoder *encoder)