Subversion Repositories Kolibri OS

Rev

Go to most recent revision | Blame | Last modification | View Log | Download | RSS feed

  1. /*
  2.  * Copyright 2007-2008  Luc Verhaegen <lverhaegen@novell.com>
  3.  * Copyright 2007-2008  Matthias Hopf <mhopf@novell.com>
  4.  * Copyright 2007-2008  Egbert Eich   <eich@novell.com>
  5.  *
  6.  * Permission is hereby granted, free of charge, to any person obtaining a
  7.  * copy of this software and associated documentation files (the "Software"),
  8.  * to deal in the Software without restriction, including without limitation
  9.  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  10.  * and/or sell copies of the Software, and to permit persons to whom the
  11.  * Software is furnished to do so, subject to the following conditions:
  12.  *
  13.  * The above copyright notice and this permission notice shall be included in
  14.  * all copies or substantial portions of the Software.
  15.  *
  16.  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  17.  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  18.  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
  19.  * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
  20.  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
  21.  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  22.  * OTHER DEALINGS IN THE SOFTWARE.
  23.  */
  24.  
  25. #ifdef HAVE_CONFIG_H
  26. #include "config.h"
  27. #endif
  28.  
  29. #include "xf86.h"
  30.  
  31. #include "rhd.h"
  32. #include "rhd_lut.h"
  33. #include "rhd_regs.h"
  34.  
  35. #define RHD_REGOFFSET_LUTA 0x000
  36. #define RHD_REGOFFSET_LUTB 0x800
  37.  
  38. /*
  39.  *
  40.  */
  41. static void
  42. LUTxSave(struct rhdLUT *LUT)
  43. {
  44.   CARD16 RegOff;
  45.   int i;
  46.     RHDFUNC(LUT);
  47.  
  48.   if (LUT->Id == RHD_LUT_A)
  49.     RegOff = RHD_REGOFFSET_LUTA;
  50.   else
  51.     RegOff = RHD_REGOFFSET_LUTB;
  52.  
  53.   LUT->StoreControl = RHDRegRead(LUT, RegOff + DC_LUTA_CONTROL);
  54.  
  55.   LUT->StoreBlackBlue = RHDRegRead(LUT, RegOff + DC_LUTA_BLACK_OFFSET_BLUE);
  56.   LUT->StoreBlackGreen = RHDRegRead(LUT, RegOff + DC_LUTA_BLACK_OFFSET_GREEN);
  57.   LUT->StoreBlackRed = RHDRegRead(LUT, RegOff + DC_LUTA_BLACK_OFFSET_RED);
  58.  
  59.   LUT->StoreWhiteBlue = RHDRegRead(LUT, RegOff + DC_LUTA_WHITE_OFFSET_BLUE);
  60.   LUT->StoreWhiteGreen = RHDRegRead(LUT, RegOff + DC_LUTA_WHITE_OFFSET_GREEN);
  61.   LUT->StoreWhiteRed = RHDRegRead(LUT, RegOff + DC_LUTA_WHITE_OFFSET_RED);
  62.  
  63.   RHDRegWrite(LUT, DC_LUT_RW_MODE, 0); /* Table */
  64.   if (LUT->Id == RHD_LUT_A)
  65.     RHDRegWrite(LUT, DC_LUT_READ_PIPE_SELECT, 0);
  66.   else
  67.     RHDRegWrite(LUT, DC_LUT_READ_PIPE_SELECT, 1);
  68.  
  69.   RHDRegWrite(LUT, DC_LUT_RW_INDEX, 0);
  70.   for (i = 0; i < 0x300; i++)
  71.     LUT->StoreEntry[i] = RHDRegRead(LUT, DC_LUT_SEQ_COLOR);
  72.  
  73.   LUT->Stored = TRUE;
  74. }
  75.  
  76. /*
  77.  *
  78.  */
  79. static void
  80. LUTxRestore(struct rhdLUT *LUT)
  81. {
  82.   CARD16 RegOff;
  83.   int i;
  84.     RHDFUNC(LUT);
  85.  
  86.     if (!LUT->Stored) {
  87.         xf86DrvMsg(LUT->scrnIndex, X_ERROR, "%s: %s: nothing stored!\n",
  88.                    __func__, LUT->Name);
  89.     return;
  90.   }
  91.  
  92.   if (LUT->Id == RHD_LUT_A)
  93.     RegOff = RHD_REGOFFSET_LUTA;
  94.   else
  95.     RegOff = RHD_REGOFFSET_LUTB;
  96.  
  97.   RHDRegWrite(LUT, RegOff + DC_LUTA_BLACK_OFFSET_BLUE, LUT->StoreBlackBlue);
  98.   RHDRegWrite(LUT, RegOff + DC_LUTA_BLACK_OFFSET_GREEN, LUT->StoreBlackGreen);
  99.   RHDRegWrite(LUT, RegOff + DC_LUTA_BLACK_OFFSET_RED, LUT->StoreBlackRed);
  100.  
  101.   RHDRegWrite(LUT, RegOff + DC_LUTA_WHITE_OFFSET_BLUE, LUT->StoreWhiteBlue);
  102.   RHDRegWrite(LUT, RegOff + DC_LUTA_WHITE_OFFSET_GREEN, LUT->StoreWhiteGreen);
  103.   RHDRegWrite(LUT, RegOff + DC_LUTA_WHITE_OFFSET_RED, LUT->StoreWhiteRed);
  104.  
  105.   if (LUT->Id == RHD_LUT_A)
  106.     RHDRegWrite(LUT, DC_LUT_RW_SELECT, 0);
  107.   else
  108.     RHDRegWrite(LUT, DC_LUT_RW_SELECT, 1);
  109.  
  110.   RHDRegWrite(LUT, DC_LUT_RW_MODE, 0); /* Table */
  111.   RHDRegWrite(LUT, DC_LUT_WRITE_EN_MASK, 0x0000003F);
  112.   RHDRegWrite(LUT, DC_LUT_RW_INDEX, 0);
  113.   for (i = 0; i < 0x300; i++)
  114.     RHDRegWrite(LUT, DC_LUT_SEQ_COLOR, LUT->StoreEntry[i]);
  115.  
  116.   RHDRegWrite(LUT, RegOff + DC_LUTA_CONTROL, LUT->StoreControl);
  117. }
  118.  
  119. /*
  120.  *
  121.  */
  122. static void
  123. LUTxSet(struct rhdLUT *LUT, int numColors, int *indices, LOCO *colors)
  124. {
  125.     //ScrnInfoPtr pScrn = xf86Screens[LUT->scrnIndex];
  126.   CARD16 RegOff;
  127.   int i, index;
  128.  
  129.     LUT->Initialised = TRUE; /* thank you RandR */
  130.  
  131.   if (LUT->Id == RHD_LUT_A)
  132.     RegOff = RHD_REGOFFSET_LUTA;
  133.   else
  134.     RegOff = RHD_REGOFFSET_LUTB;
  135.  
  136.   RHDRegWrite(LUT, RegOff + DC_LUTA_CONTROL, 0);
  137.  
  138.   RHDRegWrite(LUT, RegOff + DC_LUTA_BLACK_OFFSET_BLUE, 0);
  139.   RHDRegWrite(LUT, RegOff + DC_LUTA_BLACK_OFFSET_GREEN, 0);
  140.   RHDRegWrite(LUT, RegOff + DC_LUTA_BLACK_OFFSET_RED, 0);
  141.  
  142.   RHDRegWrite(LUT, RegOff + DC_LUTA_WHITE_OFFSET_BLUE, 0x0000FFFF);
  143.   RHDRegWrite(LUT, RegOff + DC_LUTA_WHITE_OFFSET_GREEN, 0x0000FFFF);
  144.   RHDRegWrite(LUT, RegOff + DC_LUTA_WHITE_OFFSET_RED, 0x0000FFFF);
  145.  
  146.   if (LUT->Id == RHD_LUT_A)
  147.     RHDRegWrite(LUT, DC_LUT_RW_SELECT, 0);
  148.   else
  149.     RHDRegWrite(LUT, DC_LUT_RW_SELECT, 1);
  150.  
  151.   RHDRegWrite(LUT, DC_LUT_RW_MODE, 0); /* table */
  152.   RHDRegWrite(LUT, DC_LUT_WRITE_EN_MASK, 0x0000003F);
  153.  
  154.   int depth = 32;
  155.  
  156.     switch (depth) {
  157.     case 8:
  158.     case 24:
  159.     case 32:
  160.         for (i = 0; i < numColors; i++) {
  161.         index = indices[i];
  162.         RHDRegWrite(LUT, DC_LUT_RW_INDEX, index);
  163.         RHDRegWrite(LUT, DC_LUT_30_COLOR, (colors[index].red << 22) |
  164.                     (colors[index].green << 12) | (colors[index].blue << 2));
  165.       }
  166.       break;
  167.     case 16:
  168.         for (i = 0; i < numColors; i++) {
  169.         int j;
  170.  
  171.         index = indices[i];
  172.         RHDRegWrite(LUT, DC_LUT_RW_INDEX, 4 * index);
  173.  
  174.         for (j = 0; j < 4; j++)
  175.           RHDRegWrite(LUT, DC_LUT_30_COLOR, (colors[index/2].red << 24) |
  176.                      (colors[index].green << 14) | (colors[index/2].blue << 4));
  177.       }
  178.       break;
  179.     case 15:
  180.         for (i = 0; i < numColors; i++) {
  181.         int j;
  182.  
  183.         index = indices[i];
  184.         RHDRegWrite(LUT, DC_LUT_RW_INDEX, 8 * index);
  185.  
  186.         for (j = 0; j < 8; j++)
  187.           RHDRegWrite(LUT, DC_LUT_30_COLOR, (colors[index].red << 25) |
  188.                      (colors[index].green << 15) | (colors[index].blue << 5));
  189.       }
  190.       break;
  191.   }
  192. }
  193.  
  194. /*
  195.  *
  196.  */
  197. void
  198. RHDLUTsInit(RHDPtr rhdPtr)
  199. {
  200.     struct rhdLUT *LUT;
  201.  
  202.     RHDFUNC(rhdPtr);
  203.  
  204.     LUT = xnfcalloc(sizeof(struct rhdLUT), 1);
  205.  
  206.     LUT->scrnIndex = rhdPtr->scrnIndex;
  207.     LUT->Name = "LUT A";
  208.     LUT->Id = RHD_LUT_A;
  209.  
  210.     LUT->Save = LUTxSave;
  211.     LUT->Restore = LUTxRestore;
  212.     LUT->Set = LUTxSet;
  213.  
  214.     rhdPtr->LUT[0] = LUT;
  215.  
  216.     LUT = xnfcalloc(sizeof(struct rhdLUT), 1);
  217.  
  218.     LUT->scrnIndex = rhdPtr->scrnIndex;
  219.     LUT->Name = "LUT B";
  220.     LUT->Id = RHD_LUT_B;
  221.  
  222.     LUT->Save = LUTxSave;
  223.     LUT->Restore = LUTxRestore;
  224.     LUT->Set = LUTxSet;
  225.  
  226.     rhdPtr->LUT[1] = LUT;
  227. }
  228.  
  229. /*
  230.  *
  231.  */
  232. struct rhdLUTStore {
  233.     CARD32 Select;
  234.     CARD32 Mode;
  235.     CARD32 Index;
  236.     CARD32 Color;
  237.     CARD32 ReadPipe;
  238.     CARD32 WriteMask;
  239. };
  240.  
  241. /*
  242.  *
  243.  */
  244. void
  245. RHDLUTsSave(RHDPtr rhdPtr)
  246. {
  247.   struct rhdLUTStore *Store = rhdPtr->LUTStore;
  248.  
  249.   RHDFUNC(rhdPtr);
  250.  
  251.     if (!Store) {
  252.         Store = xnfcalloc(sizeof(struct rhdLUTStore), 1);
  253.     rhdPtr->LUTStore = Store;
  254.   }
  255.  
  256.   Store->Select = _RHDRegRead(rhdPtr, DC_LUT_RW_SELECT);
  257.   Store->Mode = _RHDRegRead(rhdPtr, DC_LUT_RW_MODE);
  258.   Store->Index = _RHDRegRead(rhdPtr, DC_LUT_RW_INDEX);
  259.   Store->Color = _RHDRegRead(rhdPtr, DC_LUT_30_COLOR);
  260.   Store->ReadPipe = _RHDRegRead(rhdPtr, DC_LUT_READ_PIPE_SELECT);
  261.   Store->WriteMask = _RHDRegRead(rhdPtr, DC_LUT_WRITE_EN_MASK);
  262.  
  263.   rhdPtr->LUT[0]->Save(rhdPtr->LUT[0]);
  264.   rhdPtr->LUT[1]->Save(rhdPtr->LUT[1]);
  265. }
  266.  
  267. /*
  268.  *
  269.  */
  270. void
  271. RHDLUTsRestore(RHDPtr rhdPtr)
  272. {
  273.   struct rhdLUTStore *Store = rhdPtr->LUTStore;
  274.  
  275.   RHDFUNC(rhdPtr);
  276.  
  277.   rhdPtr->LUT[0]->Restore(rhdPtr->LUT[0]);
  278.   rhdPtr->LUT[1]->Restore(rhdPtr->LUT[1]);
  279.  
  280.     if (!Store) {
  281.         xf86DrvMsg(rhdPtr->scrnIndex, X_ERROR, "%s: nothing stored!\n", __func__);
  282.     return;
  283.   }
  284.  
  285.   _RHDRegWrite(rhdPtr, DC_LUT_RW_SELECT, Store->Select);
  286.   _RHDRegWrite(rhdPtr, DC_LUT_RW_MODE, Store->Mode);
  287.   _RHDRegWrite(rhdPtr, DC_LUT_RW_INDEX, Store->Index);
  288.   _RHDRegWrite(rhdPtr, DC_LUT_30_COLOR, Store->Color);
  289.   _RHDRegWrite(rhdPtr, DC_LUT_READ_PIPE_SELECT, Store->ReadPipe);
  290.   _RHDRegWrite(rhdPtr, DC_LUT_WRITE_EN_MASK, Store->WriteMask);
  291. }
  292.  
  293. /*
  294.  *
  295.  */
  296. void
  297. RHDLUTsDestroy(RHDPtr rhdPtr)
  298. {
  299.   RHDFUNC(rhdPtr);
  300.  
  301.     xfree(rhdPtr->LUT[0]);
  302.     xfree(rhdPtr->LUT[1]);
  303.     xfree(rhdPtr->LUTStore);
  304. }
  305.