atapi_if728.c
资源名称:8202s.rar [点击查看]
上传用户:poi891205
上传日期:2013-07-15
资源大小:9745k
文件大小:28k
源码类别:
DVD
开发平台:
C/C++
- /*=================================================================
- atapi_if.c: ATAPI INTERFACE
- 2000-01-01 Created by
- 2002-06-12 08:42AM Modified by cyue
- 2004-04-16 Modified by Terry
- Copyright(c)2000-2002 by Sunplus Technology (HsingChu) Co., Ltd.
- ALL RIGHTS RESERVED
- =================================================================*/
- //#define NPRINTF
- //#define NEPRINTF
- #include "config.h"
- #include "misc.h"
- #include "global.h"
- #include "ata.h"
- #include "fs.h"
- #include "cderr.h"
- #include "drv.h"
- #include "sinf.h"
- #include "atapi_if.h"
- #include "pu8560.h"
- #include "emuio.h"
- #include "lbaif.h"
- #if 0//def SUPPORT_SPI_QSI
- #include "iop.h"
- #endif
- #ifdef SUPPORT_CD_TEXT
- #include "CDTextUtil.h"
- #include "memmap0.h"
- #endif
- #ifndef DVDRELEASE
- //#define DBG_ATAPI
- #endif
- #ifndef DBG_ATAPI
- #undef printf
- #undef print_block
- #define printf(f, a...) do {} while (0)
- #define print_block(x,y) do {} while (0)
- #endif
- extern UINT8 cIDEStatus;
- extern UINT8 *pServoMemXferPtr;
- extern UINT16 wServoMemXferLen;
- extern UINT8 cHostDVDDSPMode;
- extern UINT8 cCmdBlock[12];
- extern void ServoDecMainLoop(void);
- extern void save_cmp_disc_info(UINT32 info1);//wanghaoying 20030812
- extern UINT32 search_file(BYTE*);
- void IDECommandProc(void);
- void ServoDecInit(void);
- void ResetInterfaceProc(void);
- //==================================================================
- //UINT8 pc[12]; //reduce global var.
- //UINT8 pc_rdata[32];
- UINT16 request_sense_flag;
- // 0: DISC_VCD, 1: DISC_DVD
- UINT8 DiscType = CDDVD;
- //UINT8 CSSEnable = 0;
- UINT32 udf_find_anchor(void);
- //==================================================================
- #define DVDDSP_CONFIG_DEF ATA_INTR_MODE //ATAPI_INTR_MODE
- #define WaitIRQ() while ((regs0->dvddsp_function & DEVICE_INT) == 0) ;//for test DRQ mode
- #define SHORT_TIME_OUT 400//4 sec
- #define NORMAL_TIME_OUT 700//7 sec
- #define LONG_TIME_OUT 800//8 sec
- #define MAX_TIME_OUT 1000//10 sec
- //==================================================================
- //extern function and varible
- void disp_fan_in(void);
- void flush_atapi(void);;
- void cppm_init( UINT32 );
- void polling();
- extern UINT8 bReadSubChannel; //Jeff 20020927
- extern UINT16 iBlockLen;
- //terry,2004/2/6 05:43PM
- #ifdef DVD_SERVO
- //
- // FUNCTION
- // atapi_dvddsp_busy_waiting()
- //
- // DESCRIPTION
- // compatible atapi
- //
- void atapi_dvddsp_busy_waiting(int seek)
- {
- set_host_request();
- ServoDecMainLoop(); // DVD_SERVO
- }
- #endif
- //==================================================================
- // ATAPI Procedure
- // return 1: ERR, 0: OK
- //inline UINT8
- UINT16
- atapi_reg_read(UINT8 addr)
- {
- addr = IDE_STATUS;
- return (UINT16)cIDEStatus;
- }
- UINT8 atapi_is_error(void)
- {
- return (atapi_reg_read(IDE_STATUS) & STATUS_ERR);
- }
- int atapi_read_error(void)
- {
- UINT16 id;
- UINT8 ubuf[20];
- id=atapi_reg_read(IDE_STATUS) & STATUS_ERR;
- if (id != 0)
- {
- printf("atapi_read_error:error %dn",id);
- atapi_p_request_sense(ubuf);
- cderr_update_show_time();
- return -1;
- }
- return 0;
- }
- UINT8 atapi_rst(UINT8 mode)
- {
- printf("atapi_rst: reset mode:%xnn",mode);
- if (mode & DSP_HOST_RESET)
- {
- //necessary reset Loader HW
- ServoDecInit();
- ResetInterfaceProc();
- #ifdef SERVO_RANDOM_SEEK
- while(1)
- {
- polling(); // for random seek
- ServoDecMainLoop(); // barry add for polling servo status
- }
- #endif
- }
- if(mode&ATA_SW_RESET)
- {
- //necessary IDE_COMMAND=0x08 Driver reset
- }
- if(mode&ATA_WAIT_RDY)
- {
- //terry,2002/5/31 09:56PM, FUSS request: open must be avaible
- do
- {
- ServoDecMainLoop();
- } while ( (cIDEStatus&0x80) == 0x80 ); // BSY bit
- io_write("Servo Start-up finishn");
- //wait 10sec for atapi_p_test_unit_ready()
- //else return ATAPI_ERROR;
- }
- return 0;//success
- }
- UINT8
- atapi_receive_data(UINT8 *p, int n)
- {
- #define TIMEOUT 100 //1s
- #define GET_RTC_15_0() (regs0->rtc_15_0)
- UINT32 old,now,cnt;
- memset(p, 0, n);//clear buffer
- //wait servo ,run polling
- //receive data to pointer p,size n
- pServoMemXferPtr = p;
- wServoMemXferLen = n;
- cHostDVDDSPMode = 0;
- old = GET_RTC_15_0();
- //for read disc, open tray delay bug.
- if(system_state==SYSTEM_READ_TITLE) cnt=TIMEOUT;//terry,2003/11/21 04:03PM
- else cnt=0;
- do
- {
- now = GET_RTC_15_0();
- if(old!=now)
- {
- cnt++;
- old=now;
- }
- if(cnt>TIMEOUT)
- {
- polling();
- // printf(".");
- }
- //ycwen 2005/1/21: To prevent audio buffer from underflow when ran_read() taking too much time (e.x. long seek)
- #ifdef MP3_JPEG_COWORK
- polling_read_data();
- #endif
- disp_fan_in();//terry 20030902
- ServoDecMainLoop();
- } while ( (cIDEStatus&0x80) == 0x80 ); // BSY bit
- //printf("IDE Status1 : %x n",cIDEStatus);
- return atapi_is_error();
- }
- UINT8
- atapi_do_packet(UINT8 *pck)
- {
- #if 0
- UINT8 i;
- for (i=0 ; i<12 ; i++) { cCmdBlock[i] = *(pck+i); }
- #endif
- memcpyS(cCmdBlock,pck,12);
- print_block(cCmdBlock,6);
- IDECommandProc();
- if (cIDEStatus & 0x01)
- return ATAPI_ERROR;
- else
- return ATAPI_OK;
- }
- //return
- // 1: error
- // 0: ok
- /*UINT8 atapi_do_set_features(void)
- {
- return 0;
- }*/
- // Packet command
- // read 18 bytes
- UINT8
- atapi_p_request_sense(UINT8 *block_info)
- {
- int sense_key;
- UINT8 pc[12];
- request_sense_flag=0;
- memset(pc, 0, 12);
- pc[0] = 0x03;
- pc[4] = 0x12;
- atapi_do_packet(pc);
- if (atapi_receive_data(block_info, 18) == 1) {
- printf("p_request_sense receive data errorn");
- return 1;
- }
- sense_key=block_info[2]&0xf;
- if (block_info[2] == 00) {
- printf("no sensen");
- } else {
- //printf("Sense key: 0x%02xn",sense_key);
- //printf("ASC: 0x%02xn", block_info[12]);
- //printf("ASCQ:0x%02xn", block_info[13]);
- if(sense_key==2)
- {
- if(block_info[12]==0x04)
- request_sense_flag|=ATAPI_NOT_READY;
- else if((block_info[12]==0x3A)&&(block_info[13]==0x00))
- request_sense_flag|=ATAPI_NO_MEDIA;
- else if((block_info[12]==0x06)&&(block_info[13]==0x00))
- request_sense_flag|=ATAPI_MEDIA_UPSIDE_DOWN;
- }else if(sense_key==5)
- {
- if(block_info[12]==0x30)
- request_sense_flag|=ATAPI_UNKNOWN_MEDIA;
- else if(block_info[12]==0x64)
- request_sense_flag|=ATAPI_ILLEGAL_MODE;
- }
- else if(sense_key==4) //servo can't focus for a long time, Jeff 20031203
- {
- request_sense_flag|=ATAPI_UNKNOWN_MEDIA;
- }
- }
- return 0;
- }
- UINT8
- atapi_p_test_unit_ready(void)
- {
- int ret;
- UINT8 pc[12];
- UINT8 pc_rdata[32];
- memset(pc, 0, 12);
- //printf("!");
- ret=atapi_do_packet(pc);//ret==0, unit is ready
- //if(ret==1)
- if (cIDEStatus & 0x01) // CHECK bit assert
- {
- atapi_p_request_sense(pc_rdata);//kenny
- if(request_sense_flag&ATAPI_NO_MEDIA)
- ret=ATAPI_NO_MEDIA;
- else if(request_sense_flag&ATAPI_NOT_READY)
- ret=ATAPI_NOT_READY;
- else if(request_sense_flag&ATAPI_MEDIA_UPSIDE_DOWN)
- ret=ATAPI_MEDIA_UPSIDE_DOWN;
- else if(request_sense_flag&ATAPI_UNKNOWN_MEDIA)
- ret=ATAPI_UNKNOWN_MEDIA;
- else
- ret=0xff;
- }
- return ret;
- }
- UINT8
- atapi_p_start_stop_unit(UINT8 start)
- {
- UINT8 pc[12];
- UINT8 pc_rdata[32];
- flush_atapi();
- atapi_read_error();
- memset(pc, 0, 12);
- pc[0] = 0x1B;
- pc[1] = 0x01;
- pc[4] = start;
- if (atapi_do_packet(pc) == 1) {
- printf("p_start_stop_unit errorn");
- atapi_p_request_sense(pc_rdata);//kenny
- return 1;
- }
- return 0;
- }
- UINT8
- atapi_p_mechanism_status(void)
- {
- UINT8 pc[12];
- UINT8 pc_rdata[32];
- flush_atapi();//alan 2002/5/30 06:29PM added to solve standby wake up fail when power on/off
- memset(pc, 0, 12);
- pc[0] = 0xBD;
- pc[9] = 0x08;
- if (atapi_do_packet(pc) == ATAPI_ERROR) {
- printf("p_mechanism_status do_packet errorn");
- atapi_p_request_sense(pc_rdata);//kenny
- return ATAPI_ERROR;
- }
- memset(pc_rdata, 0, 8);
- if (atapi_receive_data(pc_rdata, 8) == ATAPI_ERROR) {
- printf("p_mechanism_status receive data errorn");
- #ifdef SHOW_SPECIAL_DISC_TYPE
- read_disc_state = 0xf0;
- #endif
- return ATAPI_ERROR;
- }
- // printf("%dn", pc_rdata[1] >> 5);
- if(pc_rdata[1] & 0x01)
- {
- // printf("===============>>>>>door close errorn");
- return ATAPI_DOOR_CLOSE_ERR;
- }else if (((pc_rdata[1] >> 4) & 1) == 0)
- {
- // printf("door closen");
- return ATAPI_DOOR_CLOSE;
- }
- // printf("door openn");
- return ATAPI_DOOR_OPEN;
- }
- UINT8
- atapi_p_read_12(UINT32 lba, UINT32 len)
- {
- BYTE ret;
- UINT8 pc[12];
- UINT8 pc_rdata[32];
- memset(pc, 0, 12);
- pc[0] = 0xA8;
- pc[2] = (lba >> 24) & 0x000000ff; /* LBA (MSB) */
- pc[3] = (lba >> 16) & 0x000000ff;
- pc[4] = (lba >> 8) & 0x000000ff;
- pc[5] = lba & 0x000000ff; /* LBA (LSB) */
- pc[6] = (len >> 24) & 0x000000ff; // transfer length(MSB)
- pc[7] = (len >> 16) & 0x000000ff;
- pc[8] = (len >> 8) & 0x000000ff;
- pc[9] = len & 0x000000ff;
- ret=atapi_do_packet(pc);
- if(dev_status_flag&READ_PRESENT_DATA)
- dev_status_flag&=~READ_PRESENT_DATA;
- if (ret == 1) {
- printf("!!!!!!!!p_read_12 errorn");
- atapi_p_request_sense(pc_rdata);
- printf("!!!!!!!!Request outn");
- if(request_sense_flag&ATAPI_NOT_READY)
- {
- printf("!!!!!!!!p_read_12 error, unit not readyn");
- cderr_handler(CDERR_ATA_NOT_READY);
- if(atapi_do_packet(pc) == 1)
- {
- printf("p_read_12 again errorn");
- atapi_p_request_sense(pc_rdata);//kenny
- }
- }//not ready
- else if(request_sense_flag&ATAPI_ILLEGAL_MODE)
- {
- return ATAPI_ILLEGAL;
- }
- return 1;
- }
- return 0;
- }
- // generic packet command
- void
- init_cdrom_command(struct cdrom_generic_command *cgc, void *buffer, int len)
- {
- memset(cgc, 0, sizeof(*cgc));
- memset(buffer, 0, len);
- cgc->buffer = (char *) buffer;
- cgc->buflen = len;
- }
- // only support 3 commands now
- // return 0: ok, -1: error
- int
- generic_packet(struct cdrom_generic_command *cgc)
- {
- UINT8 pc_rdata[32];
- if ((cgc->cmd[0]==GPCMD_READ_DVD_STRUCTURE)||(cgc->cmd[0]==GPCMD_REPORT_KEY))
- {
- if (atapi_do_packet(cgc->cmd)!=0)
- {
- printf("generic_packet:packet errorn");
- atapi_p_request_sense(pc_rdata);
- memset(cgc->buffer,0,cgc->buflen);
- return -1;
- }
- atapi_receive_data(cgc->buffer, cgc->buflen);
- }
- else if(cgc->cmd[0]==GPCMD_SEND_KEY)
- {
- if (atapi_do_packet(cgc->cmd)!=0)
- {
- printf("generic_packet:packet errorn");
- atapi_p_request_sense(pc_rdata);
- return -1;
- }
- //atapi_send_data(cgc->buffer, cgc->buflen);
- }
- return atapi_read_error();
- }
- UINT8
- atapi_get_cprm_config(void)
- {
- BYTE ret=0;
- UINT8 pc[12];
- UINT8 pc_rdata[32];
- memset(pc, 0, 12);
- pc[0] = 0x46;
- pc[1] = 0x02; //feature descriptor be returned
- pc[2] = 0x01; //cprm
- pc[3] = 0x0B;
- // transfer length
- pc[8] = 0x08;
- if( atapi_do_packet(pc)==0 )
- {
- if(atapi_receive_data(pc_rdata, 8) )
- {
- printf("atapi_get_cprm_config receive errorn");
- //memset(pc_rdata, 0, 2048*len);
- ret = ATAPI_ERROR;
- }else
- {
- print_block(pc_rdata,8);//01:0x010B
- if(pc_rdata[2]&0x01)
- {
- printf("DVD-R,DVD-RW or DVD-RAMn");
- }
- }
- }else
- {
- printf("get cprm config failn");
- atapi_p_request_sense(pc_rdata);
- ret = ATAPI_ERROR;
- }
- return ret;
- }
- /*
- * lba: read start location
- * len: read start length
- */
- UINT8
- atapi_block_read(UINT32 lba, UINT32 len)
- {
- UINT8 pc_rdata[32];
- #ifdef USE_HDD
- extern UINT8 hdd_block_read(UINT32 lba, UINT32 len);
- //Verdure add, cyue:2002-06-12 04:45PM modified
- if (hd_play)
- {
- hdd_block_read(lba, len);
- return 0;
- }
- #endif
- if (atapi_is_error() == ATAPI_ERROR)
- {
- printf("enter block_read errorn");
- atapi_p_request_sense(pc_rdata);
- cderr_handler(CDERR_DAT_DISCONTINUE);
- return ATAPI_ERROR;
- }
- if (is_user_opened())
- {
- printf("USER OPEN!!!n");
- return ATAPI_ERROR;
- }
- dev_status_flag|=READ_PRESENT_DATA;//kenny
- cHostDVDDSPMode = 1;
- if (DiscType != CDDVD)
- {
- //printf("readcdn");
- if (atapi_read_cd(lba, len) == ATAPI_ERROR)
- return ATAPI_ERROR;
- }
- else
- { // DVD
- //printf("read12n");
- if (atapi_p_read_12(lba, len) == ATAPI_ERROR) return ATAPI_ERROR;
- }
- if (atapi_reg_read(IDE_STATUS) == 0x50)
- { //DRQ=0,BSY=0,DRDY=1,DSC=1
- printf("skip directly!n");
- return ATAPI_ERROR;
- }
- return ATAPI_OK;
- }
- void
- atapi_init(void)
- {
- //io_write("Servo atapi_init Start!n");
- //ServoDecInit();
- //ResetInterfaceProc();
- hostx_servo_buf_init();
- atapi_rst(DSP_HOST_RESET|ATA_HW_RESET);
- //delay(1);
- atapi_p_test_unit_ready();//start up loader
- //io_write("Servo atapi_init End!n");
- }
- #include "dvdioctl.h"
- void disc_init(void)
- {
- // #define DISC_IS_DVD() (gbSrvDiscStatus&0x40)//terry,2003/12/26 03:01PM
- // extern BYTE gbSrvDiscStatus;
- int iRetry, nTryNum;
- UINT32 iAnchor=0;
- //UINT32 dVTS_LSN_VOB,dVTS_LSN_IFO;//terry,mark it,2003/8/7 02:19AM
- DiscType = CDUNKNOWN;
- printf("disc_init n");
- //add re-try anchor when read DVD disc, Jeff 20031017
- if ( DISC_IS_DVD() )
- nTryNum = 2;
- else
- nTryNum = 1;
- for (iRetry=0; iRetry<nTryNum; iRetry++) {
- iAnchor = udf_find_anchor();
- if (iAnchor !=0) break;
- // 2004/07/16 yltseng
- wb_tag_init();
- }
- //if (udf_find_anchor() == 0)
- //{
- // printf("no anchor foundn");
- //}
- if ( (iAnchor == 0) && (iRetry>=nTryNum) ) {
- printf("no anchor foundn");
- }
- else
- {
- printf("initialize filesystemn");
- if ( fs_init() < 0) return;
- if(dVMG_LSN)
- {
- DiscType = CDDVD;
- cd_type_loaded=DiscType;
- #if defined (SAME_DISC_RESUME) || defined (RECORD_KEY) || defined(POWER_RESUME) //terry,2003/8/7 02:20AM
- #ifdef DVD_AUDIO//nono 2004-2-25 0:40
- if((cd_type_loaded==CDDVD) && (dAMG_LSN==0))
- #endif //DVD_AUDIO
- {
- same_disc_vob11_pos = search_file("VTS_01_1.VOB");
- save_cmp_disc_info(same_disc_vob11_pos);
- }
- #endif //Maoyong 2004.02.25 end #if defined (SAME_DISC_RESUME) || defined (RECORD_KEY) || defined(POWER_RESUME) //terry,2003/8/7 02:20AM
- #define ALWAYS_ENABLE_CSS
- #ifdef ALWAYS_ENABLE_CSS
- // CSSEnable=1;
- #else
- {
- dvd_struct s;
- s.type = DVD_STRUCT_COPYRIGHT;
- s.copyright.layer_num = 0;
- dvd_read_struct(&s);
- CSSEnable=s.copyright.cpst;
- }
- #endif
- }
- #ifdef DVD_AUDIO
- cppm_init( dAMG_LSN );
- #endif
- }
- }
- BYTE user_only=0;
- //user_only :
- // 1:user data only
- // 0:ATAPI_READCD_9_SYNC|ATAPI_READCD_9_HEADER_ALL|ATAPI_READCD_9_USERDATA
- // | ATAPI_READCD_9_ECC;
- //if ( (cd_type_loaded==CDDA) && (cd_subtype!=CD_DTS) )
- // pc[10]=bReadSubChannel; //Jeff 20020927
- UINT8
- atapi_read_cd(UINT32 lba, UINT32 len)
- {
- BYTE ret;
- UINT8 pc[12];
- UINT8 pc_rdata[32];
- memset(pc, 0, 12);
- pc[0] = 0xBE;
- // LBA
- pc[2] = (lba >> 24) & 0x00ff;
- pc[3] = (lba >> 16) & 0x00ff;
- pc[4] = (lba >> 8) & 0x00ff;
- pc[5] = lba & 0x00ff;
- // transfer length
- pc[6] = (len >> 16) & 0x00ff;
- pc[7] = (len >> 8) & 0x00ff;
- pc[8] = len & 0x00ff;
- // ....
- #define ATAPI_READCD_9_SYNC (1<<7)
- #define ATAPI_READCD_9_HEADER_NONE (0<<5)
- #define ATAPI_READCD_9_HEADER_HEADER (1<<5)
- #define ATAPI_READCD_9_HEADER_SUBHEADER (2<<5)
- #define ATAPI_READCD_9_HEADER_ALL (3<<5)
- #define ATAPI_READCD_9_USERDATA (1<<4)
- #define ATAPI_READCD_9_ECC (1<<3)
- if(user_only==1)
- {
- pc[9] =0x10;
- }
- else
- {
- pc[9] = ATAPI_READCD_9_SYNC
- | ATAPI_READCD_9_HEADER_ALL
- | ATAPI_READCD_9_USERDATA
- | ATAPI_READCD_9_ECC;
- }
- if ( (cd_type_loaded==CDDA) && (cd_subtype!=CD_DTS) )
- pc[10]=bReadSubChannel; //Jeff 20020927
- ret=atapi_do_packet(pc);
- if((dev_status_flag&READ_PRESENT_DATA))
- {
- dev_status_flag&=~READ_PRESENT_DATA;
- }
- if (ret == 1)
- {
- printf("p_read_cd errorn");
- atapi_p_request_sense(pc_rdata);
- return 1;
- }
- return 0;
- }
- int
- cdrom_read_tocentry(int trackno, BYTE format, int buflen)
- {
- UINT8 pc[12];
- UINT8 pc_rdata[32];
- memset(&pc, 0, sizeof(pc));
- pc[0] = 0x43;
- pc[2] = format;//2001/9/26
- pc[6] = trackno;
- pc[7] = (buflen >> 8);
- pc[8] = (buflen & 0xff);
- pc[1] = 2;//msf_flag
- if (atapi_do_packet(pc) == 1) {
- printf("cdrom_read_tocentry errorn");
- atapi_p_request_sense(pc_rdata);
- if(request_sense_flag&ATAPI_NOT_READY)//kenny
- {
- printf("!!!!!cdrom_read_tocentry , Unit not ready");
- cderr_handler(CDERR_ATA_NOT_READY);
- if (atapi_do_packet(pc) == 1) {
- printf("cdrom_read_tocentry error againn");
- atapi_p_request_sense(pc_rdata);
- }
- } //if(not_ready==1)
- return 1;
- }
- //memset(pc_rdata, 0, sizeof(pc_rdata));
- //if (atapi_receive_data(pc_rdata, buflen) == 1) {
- //memset(pwb, 0, sizeof(pwb));
- if (atapi_receive_data(pwb, buflen) == 1) {
- printf("cdrom_read_tocentry receive data errorn");
- return 1;
- }
- return 0;
- }
- /************************************************/
- // atapi_p_mode_sense:
- // This function is only used before excute disc_init().
- // Because before reading TOC( disc type is unknown), I don't know read command should be command 0xA8 or 0xBE.
- // I found that if disc is CDDA and send 0xA8 or 0x28 to loader, then loader will response illegle mode error.
- // So we must make sure disc is CDDA or not.
- // If DISC is CDDA then DiscType is setting CDDA, for other disc DiscType is CDDVD.
- // And we can use disc_init() to identify disc is real DVD disc or not.
- // If it is not DVD disc then read toc to classify CDDA,VCD, MP3.
- //
- /***********************************************/
- BYTE atapi_p_get_disc_info(void)
- {
- BYTE buflen;
- UINT8 pc[12];
- pc[0] = 0x5A;
- pc[2] = 0x41;
- pc[7] = 0;
- pc[8] = buflen = 0x0A;
- atapi_do_packet(pc);
- // wait_servo();
- if (atapi_receive_data(pwb, buflen) == 1)
- {
- printf("atapi_mode_sense receive data errorn");
- return 1;
- }
- if(pwb[2]==0x02||pwb[2]==0x06||pwb[2]==0x12||pwb[2]==0x16||pwb[2]==0x22||pwb[2]==0x26)
- DiscType=CDDA;
- else if(pwb[2]==0x41)
- DiscType=CDDVD;
- else
- {
- printf("atapi_p_get_disc_infon");
- DiscType=CDUNKNOWN;
- }
- return 0;
- }
- int
- atapi_open_tray(void)
- {
- #if 0//def SUPPORT_SPI_QSI
- BYTE run_in_value;
- ReadFromI2c(I2C_ID_MEMORY,PRODUCTION_TESTING,(BYTE *)&run_in_value,sizeof(run_in_value));
- if(run_in_value==0)//production reset
- return;
- #endif
- printf("openn");
- return atapi_p_start_stop_unit(START_STOP_DO_EJECT);
- }
- int
- atapi_close_tray(UINT8 nStatus)
- {
- #if 0//def SUPPORT_SPI_QSI
- BYTE run_in_value;
- ReadFromI2c(I2C_ID_MEMORY,PRODUCTION_TESTING,(BYTE *)&run_in_value,sizeof(run_in_value));
- if(run_in_value==0)//production reset
- return;
- #endif
- printf("closen");
- if (!nStatus) // Robert 2003/12/16
- return atapi_p_start_stop_unit(START_STOP_DO_LOAD);
- else
- return atapi_p_start_stop_unit(START_STOP_DO_LOAD_POWER_OFF);
- }
- int
- atapi_abort_play(void)
- {
- printf("stopn");
- if(!is_user_opened())
- {
- return atapi_p_start_stop_unit(START_STOP_DO_STOP);
- }else
- return 0;
- }
- //terry,2003/8/23 08:03PM
- int
- atapi_standby_mode(void)
- {
- #if defined(TOP_DOOR_LOADER)||defined(TCL_STANDBY)||defined(CHECK_PORTABLE_OPCLSW) //Jack added 04/11/25 //2004-4-19 18:59 lijd
- extern UINT8 srv_on;
- printf("stopn");
- atapi_p_start_stop_unit(START_STOP_DO_STOP);
- #ifndef TOP_DOOR_FOR_NGAILIK //hq add for ngailik, in order to wake up the system after power off-on quickly switch. 2004-3-3 17:38
- if(srv_on!=0) //wthsin,2004/8/9 09:33pm to fast the standby time in Top Loader
- delay_srv_10ms(300);
- #endif//TOP_DOOR_FOR_NGAILIK
- #endif
- printf("standbyn");
- return atapi_p_start_stop_unit(START_STOP_DO_STANDBY);
- }
- #ifdef SUPPORT_CD_TEXT
- int atapi_read_cd_text( void )
- {
- int iCDTextRetry = 0;
- for( ; iCDTextRetry < READTOC_RETRY; iCDTextRetry++ )
- {
- if(is_user_opened())
- return -1;
- flush_atapi();
- int iRet = cdrom_read_tocentry( 1, 5, 4 );
- if( iRet == 0 )
- break;
- else if( iRet < 0 )
- return -2;
- else
- printf( "READ CD TEXT retry:%xn", iCDTextRetry );
- }
- if( iCDTextRetry >= READTOC_RETRY )
- {
- ClearCDTextData();//lizhx 2004/08/23
- printf( "READ CD TEXT FAIL,exitn" );
- return -2;
- }
- int iLen = (pwb[0]<<8) + pwb[1];
- if( ( iLen <= 0 ) || ( iLen > 2048 ) )
- {
- printf( "Read CD TEXT length errorn" );
- return -2;
- }
- printf( "CD TEXT length:%dn", iLen - 2 );
- if( is_user_opened() )
- return -1;
- cdrom_read_tocentry( 1, 5, ( iLen / 2 * 2 ) + 4 );
- PreParseCDTextData( pwb, iLen, cd_trk_hi - cd_trk_lo, (BYTE*) ( SDRAM_BASE + ( ( CD_TEXT_YA )<< 10 ) ), CD_TEXT_SIZE );
- }
- #endif
- /*
- ** FUNCTION
- ** atapi_read_toc
- **
- ** History : 2003/12/08(Jeff) when (is_svo_dvd()), change to fmt=0
- */
- int atapi_read_toc(void)
- {
- BYTE cd_trk_cna;
- int toc_retry;
- int i;
- int ret;
- BYTE fmt;
- int iSize;
- if ( is_svo_dvd() ) {
- fmt = 0;
- iSize = 4;
- } else {
- fmt = 2;
- iSize = 6;
- }
- #ifdef NINTAUS_DVD
- fmt = 2;
- iSize = 6;
- #endif
- //
- // init toc table
- //
- for (i=0; i<=0x66; i++)
- settrkmsf(i, READTOC_INIT);
- for(toc_retry=0;toc_retry<READTOC_RETRY;toc_retry++)
- {
- if(is_user_opened())
- return -1;
- flush_atapi();
- ret = cdrom_read_tocentry(1, fmt, 4);
- if(ret==0)
- break;
- else if(ret<0)
- return -2;
- else
- {
- printf("READ TOC retry:%xn",toc_retry);
- }
- }
- if(toc_retry>=READTOC_RETRY)
- {
- printf("READ LONG TOC FAIL,exitn");
- return -2;
- }
- {
- UINT8 *p;
- int len,trk;
- len=(pwb[0]<<8) + pwb[1] - 2;
- if( (len<=0)||(len>2048) )
- {
- printf("Read toc length errorn");
- return -2;
- }
- printf("toc table length:%dn",len);
- if(is_user_opened())
- return -1;
- cdrom_read_tocentry(1, fmt, (len/2*2)+4);
- #if 0
- {
- int j;
- int iSize;
- //iSize = 6;
- iSize = 4;
- printf("=========================n");
- printf("%02x%02x%02x%02x, len=%dn", pwb[0], pwb[1], pwb[2], pwb[3], len);
- for(j=4;j<len;j+=iSize)
- {
- for(i=0;i<iSize;i++)
- printf("%02x ",pwb[j+i]);
- printf("n");
- }
- printf("=========================n");
- }
- #endif
- // fmt = 2
- // =======================================
- // BYTE 0 1 2 3 4 5
- // servo Session ADR Pnt Min Sec Frm
- // atapi 0 1 3 8 9 10
- // =======================================
- // fmt = 0(for DVD only)
- // =======================================
- // BYTE 0 1 2 3
- // servo Session Min Sec Frm
- // atapi 2 4 5 6
- //
- SessionNs=0;
- //print_block(pwb,1024);
- for (i=4; i<len; i+=iSize)
- {
- p=&pwb[i];
- if (fmt==2) {
- cd_trk_cna=(p[1]&0x0f)<<4;
- cd_trk_cna|=(p[1]&0xf0)>>4;
- if(p[2]<=0xa2) {
- if(p[2]==0xa0) {
- trk=0x64;
- if(p[0]==1) {
- cd_trk_lo_now=cd_trk_lo=p[3];
- }else if(p[0]>1) {
- SessionNs=p[3];
- printf("lo:%xn",p[3]);
- }
- } else if(p[2]==0xa1) {
- cd_trk_hi=p[3];
- trk=0x65;
- } else if(p[2]==0xa2) {
- trk=0x66;
- } else {
- trk=p[2];
- if(trk>100) {
- printf("~~read toc trk no.(%x) error~~n",trk);
- return -2;
- }
- }
- {
- UINT32 iMSF;
- //check msf validation, Jeff update, 20030819
- //pFsJpeg->cdrom.track_info[trk]=((UINT32)(cd_trk_cna)<<24) | ((UINT32)p[3] <<16)| ((UINT32)p[4]<<8) | ((BYTE)(p[5]));
- iMSF = ((UINT32)p[3] << 16)| ((UINT32)p[4] << 8) | ((BYTE)(p[5]));
- if (iMSF<0x200) iMSF = 0x200;
- pFsJpeg->cdrom.track_info[trk]=((UINT32)(cd_trk_cna)<<24) | iMSF;
- printf("trk:%d msf:%08xn",trk,pFsJpeg->cdrom.track_info[trk]);
- }
- } //if(p[2]<=0xa2) {
- } else { //fmt=0(for DVD only)
- trk = p[0];
- pFsJpeg->cdrom.track_info[trk] = ((UINT32)( (0x41000000) | (p[1]<<16) | (p[2]<<8) | p[3]) );
- cd_trk_hi = trk;
- SessionNs = trk;
- }
- #ifdef MODIFY_MULTI_SESSION_CD_DISC//NONO for tonic GERMANY CD(totle trk 13->12).20040208
- if( ((gettrkcna(1) & 0x0040/*CNA_MASK_TYPE*/) != 0x40/*CNA_DATA*/)/*&&(cd_trk_hi<= p[3])*/&&(p[0]>1) )
- break;
- #endif//MODIFY_MULTI_SESSION_CD_DISC
- } //for (i=4; i<len; i+=6)
- pFsJpeg->cdrom.track_info[0]=pFsJpeg->cdrom.track_info[1];
- {
- UINT32 max,min;
- for(trk=cd_trk_lo_now;trk<cd_trk_hi;trk++)
- {
- max=pFsJpeg->cdrom.track_info[trk+1]&0xffffff;
- min=pFsJpeg->cdrom.track_info[trk]&0xffffff;
- if( (min>max)||(min==0xffffff) )
- {
- cd_trk_hi=trk-1;
- printf("Read toc length error,max:%x min:%xn",max,min);
- break;
- }
- }
- if(cd_trk_hi<cd_trk_lo_now)
- {
- printf("Read toc length error,hi:%x low:%xn",cd_trk_hi,cd_trk_lo_now);
- return -2;
- }
- }
- printf("read finishn" );
- return 0;
- }
- }
- //=============ycwen 2004/08/10================
- #if defined(DVD_SERVO_REAL_TURN_OFF)//nono rename 4-12-30 11:19//def NO_DVD_SERVO
- void servo_turn_off(void)
- {
- //Decoder gated clock
- WriteServoReg(0x4333,0x07);
- WriteServoReg(0x4334,0xff);
- WriteServoReg(0x4335,0xff);
- WriteServoReg(0x4336,0xff);
- WriteServoReg(0x4337,0xff);
- //Servo AFE power down
- WriteServoReg(0x4403,0x04);
- WriteServoReg(0x440e,0x02);
- WriteServoReg(0x4435,0x00);
- WriteServoReg(0x453c,0x20);
- //servo DSP gated clock
- WriteServoReg(0x4410,0x03);
- WriteServoReg(0x4416,0x01);
- }
- #endif //DVD_SERVO_REAL_TURN_OFF
- #ifdef MP4_SPEED_UP_SRV
- /************************************************/
- /* Change CD speed for some MP4 files that */
- /* need high transfer bit-rate. */
- /* axel 20041018 */
- /************************************************/
- void atapi_p_change_speed(UINT8 speed)
- {
- UINT8 pc[12];
- pc[0] = 0xf0;
- pc[1] = 0xbb;
- pc[2] = speed;
- atapi_do_packet(pc);
- }
- #endif //MP4_SPEED_UP_SRV