; Copyright 2010 Castle Technology Ltd
;
; Licensed under the Apache License, Version 2.0 (the "License");
; you may not use this file except in compliance with the License.
; You may obtain a copy of the License at
;
;     http://www.apache.org/licenses/LICENSE-2.0
;
; Unless required by applicable law or agreed to in writing, software
; distributed under the License is distributed on an "AS IS" BASIS,
; WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
; See the License for the specific language governing permissions and
; limitations under the License.
;

        ; Array writer macros
        MACRO
        DCDArray $string, $len, $pre, $post
        LCLS     string2
 [ $len > 0
   [ "$string" = ""
        % $len*4
   |
string2 SETS " DCD      $pre" :CC: ("$string" :LEFT: 1) :CC: "$post"
        $string2
string2 SETS " DCDArray " :CC: ("$string" :RIGHT: ((:LEN: "$string")-1)) :CC: "," :CC: :STR: ($len-1) :CC: ",$pre,$post"
        $string2
   ]
 |
        ASSERT "$string" = ""
 ]
        MEND

        MACRO
        DCBArray $string, $len, $pre, $post
        LCLS     string2
 [ $len > 0
   [ "$string" = ""
        % $len
   |
string2 SETS " DCB      $pre" :CC: ("$string" :LEFT: 1) :CC: "$post"
        $string2
string2 SETS " DCBArray " :CC: ("$string" :RIGHT: ((:LEN: "$string")-1)) :CC: "," :CC: :STR: ($len-1) :CC: ",$pre,$post"
        $string2
   ]
 |
        ASSERT "$string" = ""
 ]
        MEND

        ; Big ugly macro for defining a board config
        ; Note - $mixers is the set of enabled mixers (not including the system)
        MACRO
        BOARDCFG $name, $codename, $debuguart, $haluarts, $defaultuart, $hali2cs, $numi2c, $videoi2c, $apll_ctl, $videogpio, $usbgpio, $mixers, $vbcflags, $vbclcdnum, $vbclcdptr
01
        DCD      $debuguart
        DCDArray "$haluarts", 4, L4_UART
        DCBArray "$haluarts", 4, UART, _IRQ
        DCB      $defaultuart-1
        %        3
        ASSERT   (:LEN: "$hali2cs") >= $numi2c
        ASSERT   ((:LEN: "$hali2cs") >= $videoi2c) :LOR: ($videoi2c = 255)
        DCDArray "$hali2cs", 3, L4_I2C
        DCBArray "$hali2cs", 3, I2C, _IRQ
        DCB      $numi2c
        DCB      $videoi2c
        DCB      $apll_ctl
        DCB      $videogpio
        DCB      $usbgpio
        ASSERT   MixerChannels = 8
        ASSERT   $mixers <= 255
        DCB      255-($mixers :OR: (1<<MixerChannel_System)) ; convert to mask of disabled channels
        DCB      $vbcflags
        DCB      $vbclcdnum
        DCB      :LEN: "$haluarts"
        DCD      $vbclcdptr
        IMPORT   Board_Init_$codename
        DCD      Board_Init_$codename
        IMPORT   Board_InitDevices_$codename
        DCD      Board_InitDevices_$codename
        IMPORT   Board_PowerOff_$codename
        DCD      Board_PowerOff_$codename
        ASSERT   (:LEN: "$name") < ?BoardConfig_Name
        DCB      "$name"
        %        ?BoardConfig_Name-(:LEN: "$name")
        DCD      MachID_$codename
        ASSERT (. - %BT01) = BoardConfig_Size
        MEND

        ; Macro for defining LCDConfig structs
        MACRO
$label  LCDCONFIG $dsi_bpp, $dsi_lanes, $acbias_freq, $lcdtype, $flags, $timings, $maxpixrate
$label  DCB       $dsi_bpp
        DCB       $dsi_lanes
        DCB       $acbias_freq
        DCB       LCDConfig_LCDType_$lcdtype
        DCD       $flags
        IMPORT    Video_Power_$label
        DCD       Video_Power_$label
        DCD       $timings
        DCD       $maxpixrate
        ASSERT (. - $label) = LCDConfig_Size
        MEND

        ; Macro for defining LCDTimings structs
        MACRO
$label  LCDTIMING $pixelrate, $hsw, $hfp, $hbp, $width, $vsw, $vfp, $vbp, $height, $syncpol
$label  DCD       $pixelrate*1000
        DCW       $hsw
        DCW       $hfp
        DCW       $hbp
        DCW       $width
        DCW       $vsw
        DCW       $vfp
        DCW       $vbp
        DCW       $height
        DCD       $syncpol
        ASSERT (. - $label) = LCDTimings_Size
        MEND

        ; Make the mixer constants a bit nicer
M_HSO   *   1<<MixerChannel_HeadsetOut
M_AI    *   1<<MixerChannel_AuxInput
M_PD    *   1<<MixerChannel_Predriver
M_HF    *   1<<MixerChannel_HandsFree

        ; And VBC flags
VBC_SV   *  VideoBoardConfig_Flags_SVideo
VBC_C    *  VideoBoardConfig_Flags_Composite
VBC_Both *  VideoBoardConfig_Flags_SVideo+VideoBoardConfig_Flags_Composite

        ; And now the table of board configs

BoardConfigTable
        ;        Name           CodeName     DebugUART UARTs  DefaultUART I2Cs   NumI2C VideoI2C APLL_CTL VideoGPIO       USBGPIO MixerChans       VBC_Flags VBC_LCDNum VBC_LCDPtr
        BOARDCFG "BeagleBoard", BeagleBoard, L4_UART3, "123", 3,          "123", 3,     2,       &16,     170,            147,    M_HSO+M_AI,      VBC_SV,   1,         VBC_DVI
        BOARDCFG "DevKit8000",  DevKit8000,  L4_UART3, "123", 3,          "132", 3,     2,       &16,     GPIO_PIN_MAX+7, 147,    M_HSO+M_AI,      VBC_SV,   1,         VBC_DVI       ; TODO - If USB host is completely broken, we should hide it from RO
        BOARDCFG "IGEPv2",      IGEPv2,      L4_UART3, "123", 3,          "123", 3,     2,       &16,     170,            24,     M_HSO+M_AI,      0,        1,         VBC_DVI
        BOARDCFG "Pandora",     Pandora,     L4_UART3, "123", 3,          "123", 3,     255,     &16,     255,            16,     M_HSO+M_AI+M_PD, VBC_Both, 1,         VBC_Pandora
        BOARDCFG "Touch Book",  TouchBook,   L4_UART3, "123", 3,          "123", 3,     255,     &16,     176,            147,    M_HSO+M_AI+M_HF, 0,        1,         VBC_TouchBook
        BOARDCFG "OMAP3 EVM",   OMAP35xEVM,  L4_UART1, "123", 1,          "123", 3,     255,     &16,     GPIO_PIN_MAX+7, 21,     M_HSO+M_AI,      VBC_Both, 1,         VBC_DVI
BoardConfigTable_End

              ;         DSI_BPP DSI_LANES ACBias_freq LCDType     Flags                       LCDTimings     Max_PixelRate
VBC_DVI       LCDCONFIG 24,     3,        &28,        TFT,        0,                          0,             100000
VBC_Pandora   LCDCONFIG 24,     3,        0,          TFT,        LCDConfig_Flags_IPC,        LCD_Pandora,   0
VBC_TouchBook LCDCONFIG 24,     3,        0,          TFT,        LCDConfig_Flags_Brightness, LCD_TouchBook, 0

              ;         PixelRate HSW HFP HBP Width VSW VFP VBP Height SyncPol
LCD_Pandora   LCDTIMING 36000,    1,  68, 214,800,  1,  39, 34, 480,   SyncPol_InvertHSync+SyncPol_InvertVSync ; http://www.mail-archive.com/linux-omap@vger.kernel.org/msg22228.html
LCD_TouchBook LCDTIMING 64000,    3,  3,  39, 1024, 1,  2,  7,  600,   0 ; http://www.mail-archive.com/linux-omap@vger.kernel.org/msg19279.html - Looks like panel is only 16bpp?? and almost 100Hz!

        END