#ident "$Id: dvd_hw.h,v 1.18 2008/04/24 17:53:51 cnguyen Exp $"
/*
 *               Copyright (C) 2005, BroadOn Communications Corp.
 *
 *  These coded instructions, statements, and computer programs contain
 *  unpublished  proprietary information of BroadOn Communications Corp.,
 *  and  are protected by Federal copyright law. They may not be disclosed
 *  to  third  parties or copied or duplicated in any form, in whole or in
 *  part, without the prior written consent of BroadOn Communications Corp.
 *
 */

#ifndef DVD_HW_H
#define DVD_HW_H

#include <types.h>

#define DVD_VIDEO_SECTOR_SIZE   2048
/*
 * Declarations and definitions for the hardware interface
 * to the DVD drive
 */

/* DI_Status register bit macros */
#define DI_BREAK_INTR                   (1 << 6)
#define DI_BREAK_INTR_MASK              (1 << 5)
#define DI_TRANS_COMPLETE_INTR          (1 << 4)
#define DI_TRANS_COMPLETE_INTR_MASK     (1 << 3)
#define DI_ERROR_INTR                   (1 << 2)
#define DI_ERROR_INTR_MASK              (1 << 1)
#define DI_BREAK                        (1 << 0)
#define DI_STATUS_INTRS                 (DI_BREAK_INTR | DI_TRANS_COMPLETE_INTR | DI_ERROR_INTR)

/* DI_Cover_Reg macros */
#define DI_COVER_INTR                   (1 << 2)
#define DI_COVER_INTR_MASK              (1 << 1)
#define DI_COVER_STATUS                 (1 << 0)
#define DI_COVER_CLOSED                 0

/* DI_Control macros */
#define DI_DMA_MODE                     (1 << 1)
#define DI_TRANSFER                     (1 << 0)

/*
 * Note: read data requests from the PowerPC side are encoded
 *       as DI_READ_RVL_CMD.  Legitimate DI_READ_CMD requests
 *       only come from the driver itself
 */

/* Command codes - values are significant (not arbitrary) */
#define DI_INQUIRY_CMD                  0x12
#define DI_REPORT_KEY_CMD               0xA4
#define DI_READ_CMD                     0xA8
#define DI_SEEK_CMD                     0xAB
#define DI_READ_DVD_STRUCT_CMD          0xAD
#define DI_READ_DVD_CONFIG_CMD          0xD1
#define DI_STOP_LASER_CMD               0xD2
#define DI_OFFSET_CMD                   0xD9
#define DI_READ_DISC_INFO_CMD           0xDA
#define DI_REQUEST_DISC_STATUS_CMD      0xDB
#define DI_REQUEST_RETRY_NUMBER_CMD     0xDC
#define DI_SET_MAXIMUM_ROTATION_CMD     0xDD
#define DI_SER_MEAS_CONTROL_CMD         0xDF
#define DI_REQUEST_ERROR_CMD            0xE0
#define DI_AUDIO_STREAM_CMD             0xE1
#define DI_AUDIO_REQUEST_STATUS_CMD     0xE2
#define DI_STOP_MOTOR_CMD               0xE3
#define DI_AUDIO_BUF_CONFIG_CMD         0xE4
#define DI_READ_DVD_CMD                 0xD0

/*
 * Pseudo-command codes - values are arbitrary,
 * but must match the dvd_hw.h in the RVL SDK
 * tree
 */
#define DI_READ_DISK_ID_CMD             0x70
#define DI_READ_RVL_CMD                 0x71
#define DI_SEEK_RVL_CMD                 0x72
#define DI_WAIT_FOR_COVER_CLOSE_CMD     0x79
#define DI_GET_COVER_REGISTER_CMD       0x7A
#define DI_NOTIFY_RESET_CMD             0x7E
#define DI_SET_SPINUP_FLAG_CMD          0x7F
#define DI_READ_DVD_PHYSICAL_CMD        0x80
#define DI_READ_DVD_COPYRIGHT_CMD       0x81
#define DI_READ_DVD_DISC_KEY_CMD        0x82
#define DI_GET_LENGTH_CMD               0x83
#define DI_GET_IMM_BUFFER_CMD           0x84
#define DI_MASK_COVER_INTERRUPT         0x85
#define DI_CLEAR_COVER_INTERRUPT        0x86
#define DI_UNMASK_STATUS_INTERRUPTS     0x87
#define DI_GET_COVER_STATUS_CMD         0x88
#define DI_UNMASK_COVER_INTERRUPT       0x89
#define DI_RESET_CMD                    0x8A
#define DI_OPEN_PARTITION_CMD           0x8B
#define DI_CLOSE_PARTITION_CMD          0x8C
#define DI_UNENCRYPTED_READ_CMD         0x8D
#define DI_DVD_VIDEO_ENABLE_CMD         0x8E
#define DI_GET_NO_DISC_OPEN_PARAMS_CMD  0x90
#define DI_NO_DISC_OPEN_PARTITION_CMD   0x91
#define DI_GET_NO_DISC_BUFFER_SIZES_CMD 0x92
#define DI_OPEN_PART_TMD_TICKET_CMD     0x93
#define DI_OPEN_PART_TMD_TICKET_VIEW_CMD 0x94
#define DI_GET_STATUS_REGISTER_CMD      0x95
#define DI_GET_CONTROL_REGISTER_CMD     0x96

/* Command sub-codes */
#define DI_NORMAL_READ                  0x0
#define DI_DISC_ID_READ                 0x1

#define DI_DVD_STRUCT_PHYSICAL          0x0
#define DI_DVD_STRUCT_COPYRIGHT         0x1
#define DI_DVD_STRUCT_DISC_KEY          0x2

/* Error codes returned by commands */
#define DI_ERR_NO_ERROR                 0x000000
#define DI_ERR_MOTOR_STOP               0x020400
#define DI_ERR_ID_NOT_READ              0x020401
#define DI_ERR_COVER_OPENED             0x023A00
#define DI_ERR_SEEK_FAIL                0x030200
#define DI_ERR_UNRECOV_READ             0x031100
#define DI_ERR_PROTOCOL                 0x040800
#define DI_ERR_BAD_DISK_ADDR            0x052100
#define DI_ERR_BAD_COMMAND              0x052400
#define DI_ERR_VIDEO_DISK               0x053000
#define DI_ERR_LEAD_OUT_READ            0x056300
#define DI_ERR_DISC_CHANGE              0x062800
#define DI_ERR_AUDIO_BUF_NOT_SELECT     0x052000
#define DI_ERR_GAME_DISC                0x052000   /* Same as AUDIO...SELECT */

/* Status codes - sent as the high byte with the error code */
#define         STATUS_READY            0x00
#define         STATUS_COVER_OPEN       0x01
#define         STATUS_DISC_CHANGE      0x02
#define         STATUS_NO_DISC          0x03
#define         STATUS_MOTOR_STOP       0x04
#define         STATUS_ID_NOT_READ      0x05

/* These codes are generated by the driver, not the drive */

/* TODO: Send back FF as the drive status for DI_ERR_SECURITY */
#define DI_ERR_SECURITY                 0x007700 
#define DI_ERR_ETICKET                  0x007800 
#define DI_ERR_TIMEOUT                  0x008000
/* Error code for when transaction has error, but error code not retrieved */
#define DI_ERR_NONSPECIFIC              0x00A000
/* Error code sent when the caller screwed up */
#define DI_ERR_CALLER                   0x00B000

/* Invalid error code.  Should never be returned */
#define DI_ERR_BOGUS                    0xFFFFFFFF

/*******************************************************************/
/* Structures corresponding to information returned by the drive   */
/*******************************************************************/

#define REVOLUTION_MAGIC                0x5d1c9ea3   
#define GAMECUBE_MAGIC                  0x23339f3d

#if defined (__ARMEL__) || defined (__ARMEB__)
struct DVDDiskID {
    char           gameName[4];
    char           company[2];
    u8             diskNumber;
    u8             gameVersion;
    u8             streaming;
    u8             streamingBufSize; // 0 = default
    u8             padding1[14];     // 0's are stored
    u32            rvlMagic;         // Revolution magic number stored here
    u32            gcMagic;          // GC magic number is here
                                     // On revolution, value is 0
};
typedef struct DVDDiskID DVDDiskID;
#endif   // ARM

struct DVDDriveInfo {
    u16         revisionLevel;
    u16         deviceCode;
    u32         releaseDate;
    u8          padding[24];
};
typedef struct DVDDriveInfo DVDDriveInfo;

typedef struct DVDVideoPhysical {
    u8     data[2048];
} DVDVideoPhysical;

typedef struct DVDVideoCopyright {
    u8     systemType;
    u8     RegionInformation;
    u8     reserved[2];
    u8     padding[12];    // Needed because DMA's are multiple of 32
} DVDVideoCopyright;

typedef struct DVDVideoDiscKey {
    u8     data[2048];
} DVDVideoDiscKey;

typedef struct DVDVideoReportKey {
    u8     data[32];
} DVDVideoReportKey;

typedef struct DVDDiskBca {
    u8     data[64];
} DVDDiskBca;

typedef struct DVDLowDriveSer {
    u8     data[12];
    u8     padding[20];     // Needed because DMA's are multiple of 32
} DVDLowDriveSer;


#endif
