atapi_if720.c
资源名称:8202s.rar [点击查看]
上传用户:poi891205
上传日期:2013-07-15
资源大小:9745k
文件大小:49k
源码类别:
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 "image.h"
- #include "fs.h"
- #include "func.h"
- #include "cderr.h"
- #include "avd.h"
- #include "drv.h"
- #include "atapi_if.h"
- #include "pu8560.h"
- extern UINT8 bReadSubChannel; //Jeff 20020927
- extern UINT16 iBlockLen;
- //#define UDETEST
- #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
- #define POLLING_MODE //if test interrupt mode, mark this define
- #ifdef DVD728
- #ifdef DVD_SERVO
- #define DVDDSP_CONFIG_DEF ATA_INTR_MODE //ATAPI_INTR_MODE
- #else
- #define DVDDSP_CONFIG_DEF ATA_POLLING_MODE //ATAPI_INTR_MODE
- #endif
- #define WaitIRQ() while ((regs0->dvddsp_function & DEVICE_INT) == 0) ;//for test DRQ mode
- #else
- #define POLLING_MODE //if test interrupt mode, mark this define
- #define DVDDSP_CONFIG_DEF ATAPI_ADV_POLLING
- #endif
- #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
- /*
- * variable
- */
- /*UINT8 pc[12];
- UINT8 pc_rdata[32];*/
- UINT16 request_sense_flag;
- UINT8 DiscType = CDDVD;// 0: DISC_VCD, 1: DISC_DVD
- UINT8 CSSEnable = 0;
- /*
- * external function
- */
- UINT32 udf_find_anchor(void);
- void disp_fan_in(void);
- void flush_atapi(void);;
- void cppm_init( UINT32 );
- // for compatible issue
- int atapi_read_error(void) {return 0;}
- int atapi_standby_mode(void) {return 0;}
- #ifndef DVD_SERVO
- void SetIDETimeOut(UINT32 time) {}
- #endif
- #ifndef ROM_ATA_SHARE_BUS
- UINT16
- atapi_reg_read(UINT8 addr)
- {
- UINT32 i=0;
- regs0->dvddsp_function = (addr<<8) | ATAPI_READ | REG_MODE | HOST_START;
- while ((regs0->dvddsp_function & HOST_BUSY) != 0)
- {
- i++;
- if(i>0xfffffff0)
- {
- printf(__FUNCTION__" ==> always busyn");
- break;
- }
- }
- //NowPrint("@");
- if (addr == IDE_DATA)
- return regs0->dvddsp_blocklength;
- return (UINT16) (regs0->dvddsp_function & 0xFF);
- }
- void
- atapi_reg_write(UINT8 addr, UINT16 data)
- {
- UINT32 i=0;
- if (addr == IDE_DATA) {
- regs0->dvddsp_blocklength = data;
- regs0->dvddsp_function = (addr<<8) | ATAPI_WRITE | REG_MODE | HOST_START;
- } else {
- regs0->dvddsp_function = (data & 0x00FF) |
- (addr<<8) | ATAPI_WRITE | REG_MODE | HOST_START;
- }
- while ((regs0->dvddsp_function & HOST_BUSY) != 0)
- {
- i++;
- if(i>0xfffffff0)
- {
- printf(__FUNCTION__" ==> always busyn");
- break;
- }
- }
- }
- #endif
- #ifdef DVD728
- void read_device_signature(UINT8 dev)
- {
- unsigned cylinder_hi;
- unsigned sector_cnt;
- printf("device %x sign.n", dev);
- atapi_reg_write(IDE_DEVICE_HEAD, (dev) ? 0x10 : 0x00);
- printf("tdevice%x's diag. code = %xn", dev, atapi_reg_read(IDE_ERROR));
- sector_cnt = atapi_reg_read(IDE_SECTOR_CNT);
- if (sector_cnt)
- {
- cylinder_hi = atapi_reg_read(IDE_CYLINDER_HI);
- if (cylinder_hi == 0xeb) printf("implement PACKET commandn");
- else if (cylinder_hi == 0x00) printf("NOT implement PACKET commandn");
- }
- else
- {
- printf("device%x occurs UNKNOWN read_device_signature %02xn", dev, sector_cnt);
- }
- }
- #endif
- // ATAPI Procedure
- // return 1: ERR, 0: OK
- //inline UINT8
- UINT8
- atapi_is_error(void)
- {
- // return (atapi_reg_read(IDE_STATUS) & STATUS_ERR);
- if ((atapi_reg_read(IDE_STATUS) & STATUS_ERR) != 0) {
- printf("atapi status error n");
- return ATAPI_ERROR;
- }
- return ATAPI_OK;
- }
- #ifdef DVD728
- UINT8
- atapi_rst(UINT8 mode)
- {
- UINT16 old_config,i;
- UINT16 status=0;
- printf(__FUNCTION__": mode:%xnn",mode);
- if (mode & DSP_HOST_RESET) {
- if (mode & ATA_HW_RESET)
- old_config = 0x0000;
- else
- old_config = regs0->dvddsp_public;
- regs0->dvddsp_public = old_config|ATAPI_DEVICE|ATAPI_HOST_RESET;
- delay(1); // assert RESET - at least 25us
- regs0->dvddsp_public = old_config;
- delay(5); // negate_wait 2 ms
- if(mode & ATA_HW_RESET)
- {
- regs0->dvddsp_ata_pio_cycle = 0x7764; // set ATAPI_PIO_CYCLE, PIO-MODE4
- regs0->dvddsp_ata_udma_cycle = 0x4924; // set ATAPI_UDMA_CYCLE
- regs0->dvddsp_ata_config = 0x0000 | ATA_INTR_MODE;
- // setup UDE configuration (useless now)
- regs0->dvddsp_ude_config = 0x0000;
- regs0->dvddsp_public = ATAPI_DEVICE|ATAPI_DEV_HRESET;
- delay(1);
- regs0->dvddsp_public = ATAPI_DEVICE;
- delay(5);
- #ifdef ROM_ATA_SHARE_BUS
- #define RST_GPIO 4
- //atapi hw reset
- regs0->gpio_master[RST_GPIO/16] |= (0x1)<<(RST_GPIO%16);
- regs0->gpio_oe[RST_GPIO/16] |= (0x1)<<(RST_GPIO%16);// -> 0
- regs0->gpio_out[RST_GPIO/16] &= ~((0x1)<<(RST_GPIO%16));// -> 0
- printf("<o0 >n");
- delay(1);
- regs0->gpio_out[RST_GPIO/16] |= ((0x1)<<(RST_GPIO%16));// -> 1
- printf("<o1 >n");
- delay(5);
- //while(1);
- #endif
- // select device
- atapi_reg_write(IDE_DEVICE_HEAD, (DEV) ? 0x10: 0x00);
- do {
- status = atapi_reg_read(IDE_STATUS);
- } while (status & STATUS_BSY);
- atapi_reg_write(IDE_DEVICE_CTRL, 0x00);
- // read read_device_signature
- //read_device_signature(1);
- //read_device_signature(0);
- }
- }
- if(mode&ATA_SW_RESET)
- {
- atapi_reg_write(IDE_DEVICE_CTRL, 0x04);
- delay(5);
- atapi_reg_write(IDE_DEVICE_CTRL, 0x00);
- delay(3);
- atapi_reg_write(IDE_DEVICE_HEAD, (DEV) ? 0x10: 0x00);
- do {
- status = atapi_reg_read(IDE_STATUS);
- } while (status & STATUS_BSY);
- regs0->dvddsp_ata_config = 0x0000 | ATA_INTR_MODE;
- atapi_reg_write(IDE_DEVICE_CTRL, 0x00);
- // set UDE config
- regs0->dvddsp_ude_config = 0x0000;
- // read read_device_signature
- //read_device_signature(1);
- //read_device_signature(0);
- // set ATAPI_PIO_CYCLE, PIO-MODE4
- regs0->dvddsp_ata_pio_cycle = 0x7764;
- // set ATAPI_UDMA_CYCLE
- regs0->dvddsp_ata_udma_cycle = 0x4924;
- #if 0
- if(atapi_chk_time_out(WAIT_STATUS_NO_BSY,LONG_TIME_OUT))
- {
- printf(__FUNCTION__" ==> Timout 1n");
- return ATAPI_ERROR;
- }
- #endif
- }
- if(mode&ATA_WAIT_RDY)
- {//terry,2002/5/31 09:56PM, FUSS request: open must be avaible
- //dev_status_flag|=ATAPI_RETRY_READY;
- for(i=0;i<100;i++)
- {
- if(atapi_p_test_unit_ready()==0)
- {
- //dev_status_flag&=~ATAPI_RETRY_READY;
- return 0;//test unit ready
- }
- delay(100);
- }
- //dev_status_flag&=~ATAPI_RETRY_READY;
- printf("!!!!!!STILL Not Readyn");
- return ATAPI_ERROR;
- }
- return 0;
- }
- #else
- UINT8
- atapi_rst(UINT8 mode)
- {
- UINT16 old_config,i;
- printf(__FUNCTION__": reset mode:%xnn",mode);
- if(mode&DSP_HOST_RESET)
- {
- if(mode&ATA_HW_RESET)
- old_config=0;
- else
- old_config=regs0->dvddsp_config ;
- regs0->dvddsp_config = old_config|ATAPI_HOST_RESET;
- delay(1);
- regs0->dvddsp_config = old_config;
- delay(1);
- if(mode&ATA_HW_RESET)
- {
- regs0->dvddsp_config = ATAPI_DEV_HRESET;
- delay(100);
- regs0->dvddsp_config = 0;
- delay(1);
- }
- }
- if(mode&ATA_SW_RESET)
- {
- atapi_reg_write(IDE_DEVICE_HEAD, (DEV) ? 0x10: 0x00);
- atapi_reg_write(IDE_FEATURE, 0x00);
- atapi_reg_write(IDE_SECTOR_CNT, 0x00);
- atapi_reg_write(IDE_SECTOR_NUM, 0x00);
- atapi_reg_write(IDE_CYLINDER_LO, 0x00);
- atapi_reg_write(IDE_CYLINDER_HI, 0x00);
- atapi_reg_write(IDE_COMMAND, 0x08);/*Drive reset*/
- delay(3);
- if(atapi_chk_time_out(WAIT_STATUS_NO_BSY,LONG_TIME_OUT))
- {
- printf(__FUNCTION__" ==> Timout 1n");
- return ATAPI_ERROR;
- }
- }
- if(mode&ATA_WAIT_RDY)
- {//terry,2002/5/31 09:56PM, FUSS request: open must be avaible
- //dev_status_flag|=ATAPI_RETRY_READY;
- for(i=0;i<100;i++)
- {
- //polling();
- //if(sys_cmd==(CMD_FUNC|CMD_FUNC_OPEN))
- // break;
- if(atapi_p_test_unit_ready()==0)
- {
- //dev_status_flag&=~ATAPI_RETRY_READY;
- return 0;//test unit ready
- }
- delay(100);
- }
- //dev_status_flag&=~ATAPI_RETRY_READY;
- printf("!!!!!!STILL Not Readyn");
- return ATAPI_ERROR;
- }
- return 0;
- }
- #endif
- UINT8
- atapi_write_block(UINT8 *p)
- {
- // UINT32 i=0;
- //atapi_device_sel();
- /*****
- * Write any required command parameter to the Features, Sector
- * Count, Sector Number, Cylinder High, Cylinder Low, and Device/
- * Head registers
- * 1. Features reg. (09h):
- * Normal: 0x00
- * NOP: 0x00, return command aborted and aborted
- * any outstanding queued commands.
- * Set Features: 0x03, set transfer mode.
- * 2. Sector Count reg. (0Ah):
- * Set Features: 0x00, PIO default mode
- * 0x22, Multiword DMA mode, Mode 2
- * 3. Cylinder Low reg. (0Ch)
- * 4. Cylinder High reg. (0Dh)
- * 5. Device/Head reg. (0Eh) with appropriate DEV
- *****/
- atapi_reg_write(IDE_FEATURE, *p);
- atapi_reg_write(IDE_SECTOR_CNT, *(p+1));
- atapi_reg_write(IDE_SECTOR_NUM, *(p+2));
- atapi_reg_write(IDE_CYLINDER_LO, 0xFE);
- atapi_reg_write(IDE_CYLINDER_HI, 0xFF);
- atapi_reg_write(IDE_DEVICE_HEAD, (DEV) ? 0x10: 0x00);
- /*****
- * Write command code to the command register (The host shall
- * wair at least 400ns before reading the Status register to
- * ensure the content is valid
- * 1. NOP: 0x00
- * 2. ATAPI PACKET COMMAND: 0xa0
- * 3. IDENTIFY PACKET DEVICE: 0xa1
- * 4. CHECK POWER MODE: 0xE5
- * 5. SLEEP: 0xE6
- *****/
- atapi_reg_write(IDE_COMMAND, *(p+3));
- /*****
- * The host shall wait at least 400ns before reading the Status
- * register to ensure the content is valid.
- *****/
- //delay(1);
- /*** Host: Read Status register until BSY=0 ***/
- if(atapi_chk_time_out(WAIT_ALT_NO_BUSY,LONG_TIME_OUT))
- {
- printf(__FUNCTION__" ==> Timout 1n");
- return ATAPI_ERROR;
- }
- return atapi_is_error();
- }
- UINT8
- atapi_send_data(UINT8 *p, int n)
- {
- int i=0;
- // UINT32 j;
- /*** Host: Read Status register until BSY=0 & DRQ=1 ***/
- if(atapi_chk_time_out(WAIT_DRQ_OK,LONG_TIME_OUT))
- {
- printf(__FUNCTION__" ==> Timout 1n");
- return ATAPI_ERROR;
- }
- for (i=0; i<n; i+=2)
- {
- atapi_reg_write(IDE_DATA,
- ( ((UINT16)(*(p+i+1))) << 8) | (UINT16)(*(p+i)) );
- }
- /*****
- * Host: wait device to clear BSY=0, it indicates command is complete.
- *****/
- if(atapi_chk_time_out(WAIT_STATUS_NO_BSY,LONG_TIME_OUT))
- {
- printf(__FUNCTION__" ==> Timout 2n");
- atapi_is_error();
- return ATAPI_ERROR;
- }
- /*****
- * Host: read Alternate status register and ignore results. This prevent
- * polling host from reading status before it is valid.
- * Note - Device is command complete, it should perform its error routine if
- * an error is reported
- *****/
- atapi_reg_read(IDE_ALT_STATUS);
- return atapi_is_error();
- }
- UINT8
- atapi_receive_data(UINT8 *p, int n)
- {
- UINT16 USER_DATA;
- int i, j,status;
- // UINT32 k;
- #ifdef USE_HDD
- //Verdure add, cyue:2002-06-12 04:45PM modified
- if (hd_play) return atapi_is_error();
- #endif
- /*****
- * Host: read Alternate status register and ignore results. This
- * prevent polling host from reading status before it is valid
- *****
- */
- atapi_reg_read(IDE_ALT_STATUS);
- j = 0;
- do {
- /*****
- * Host: read Status register until BSY=0 & DRQ=1. Status register
- * is read to clear pending interrput
- *****/
- #ifdef POLLING_MODE
- if(atapi_chk_time_out(WAIT_DRQ_OK,LONG_TIME_OUT))
- {
- printf(__FUNCTION__" ==> Timout 1n");
- cderr_handler(CDERR_ATA_BUSY);
- return ATAPI_ERROR;
- }
- #else
- while ( (atapi_reg_read(IDE_STATUS) & STATUS_BSY) ||
- !(atapi_reg_read(IDE_STATUS) & STATUS_DRQ) )
- {
- WaitIRQ();
- }
- #endif
- status=atapi_reg_read(IDE_STATUS);
- if((status==0x51)||(status==0x50))//BSY=0, DRQ=0, DSC=1
- {
- printf(__FUNCTION__" ==> skip directlyn");
- return ATAPI_ERROR;
- }
- i = atapi_reg_read(IDE_CYLINDER_HI);
- i = atapi_reg_read(IDE_CYLINDER_LO) + i * 256;
- //printf("data length: %dn", i);
- if (i > n)
- i = n;
- /*****
- * DRQ block transfer
- *****/
- for (; i > 0; i-=2)
- {
- USER_DATA = atapi_reg_read(IDE_DATA);
- *(p+j+1) = USER_DATA >> 8;
- *(p+j) = USER_DATA & 0xff;
- j += 2;
- n -= 2;
- }
- //ycwen 2004/08/10
- #ifdef NO_DVD_SERVO
- return ATAPI_ERROR;
- #endif
- } while (n != 0);
- /*****
- * Host: wait device to clear BSY=0, it indicates command is complete.
- *****/
- if(atapi_chk_time_out(WAIT_STATUS_NO_BSY,LONG_TIME_OUT))
- {
- printf(__FUNCTION__" ==> Timout 2n");
- //cderr_handler(CDERR_ATA_BUSY);
- if(atapi_is_error()==0)
- printf(__FUNCTION__" ==> !!!!ATAPI ERROR n");
- return ATAPI_ERROR;
- }
- /*****
- * Host: read Alternate status register and ignore results. This
- * polling host from reading status before it is valid.
- * Note - Device is command complete, it should perform its error routine if
- * an error is reported
- *****/
- atapi_reg_read(IDE_ALT_STATUS);
- return atapi_is_error();
- }
- // ATA command
- // packet size 12
- #ifdef POLLING_MODE
- //terry,2002/8/22 08:29PM
- const UINT8 block_data[7] = {0, 0, 0, 0xFE, 0xFF, 0, 0xA0 };
- #else
- const UINT8 block_data[7] = {0, 0, 0, 0x00, 0x08, 0, 0xA0 };
- #endif
- UINT8
- atapi_do_packet(UINT8 *pck)
- {
- int i;
- UINT32 wait_time;
- #ifdef USE_HDD
- //Verdure add, cyue:2002-06-12 04:45PM modified
- if (hd_play)
- {
- hdd_do_packet(wait_time,pck);
- return 0;
- }
- #endif
- if(dev_status_flag&READ_PRESENT_DATA)
- wait_time=SHORT_TIME_OUT;
- else
- wait_time=NORMAL_TIME_OUT;
- if(atapi_chk_time_out(WAIT_ALT_NO_BUSY,wait_time))
- {
- printf(__FUNCTION__" ==> Timout 1n");
- cderr_handler(CDERR_ATA_BUSY);
- return ATAPI_ERROR;
- }
- for (i = 0; i <= 6; i++)
- atapi_reg_write(i + 0x11, block_data[i]);
- if(atapi_chk_time_out(WAIT_ALT_NO_BUSY,wait_time))
- {
- printf(__FUNCTION__" ==> Timout 2n");
- cderr_handler(CDERR_ATA_BUSY);
- return ATAPI_ERROR;
- }
- i = atapi_reg_read(IDE_ALT_STATUS);
- if ((i & STATUS_ERR) != 0)
- {
- printf("write_block in do_packet error:%xn",i);
- return ATAPI_ERROR;
- }
- if(atapi_chk_time_out(WAIT_DRQ_OK,wait_time))
- {
- printf(__FUNCTION__" ==> Timout 3n");
- cderr_handler(CDERR_ATA_BUSY);
- return ATAPI_ERROR;
- }
- for (i=0; i<12; i+=2)
- {
- atapi_reg_write(IDE_DATA,
- ( ((UINT16)(*(pck+i+1))) << 8) | (UINT16)(*(pck+i)) );
- }
- #ifdef WAIT_ATA_ITRQ
- if(atapi_chk_time_out(WAIT_IRQ,MAX_TIME_OUT))
- {
- printf(__FUNCTION__" ==>< IRQ Timout >n");
- cderr_handler(CDERR_ATA_BUSY);
- return ATAPI_ERROR;
- }
- #endif
- //Actually, when timeout loader is still busy,
- //So I think output next command to loader, it will let loader hang up
- //Normal method, it should do software reset to reset loader and return ATAPI ERROR
- //But some loader will support software reset function
- #ifdef POLLING_MODE
- if(atapi_chk_time_out(WAIT_STATUS_NO_BSY,wait_time))
- {
- printf(__FUNCTION__" ==> Timout 4n");
- cderr_handler(CDERR_ATA_BUSY);
- return ATAPI_ERROR;
- }
- #else
- WaitIRQ();
- while (atapi_reg_read(IDE_STATUS) & STATUS_BSY)
- {
- ;
- }
- #endif
- atapi_reg_read(IDE_ALT_STATUS);
- if (atapi_is_error() != 0) {
- printf("send_data in do_packet errorn");
- print_block(pck, 12);
- // atapi_p_request_sense(pc_rdata);//kenny mark it
- return ATAPI_ERROR;
- }
- return ATAPI_OK;
- }
- /*****************************************************/
- /* */
- /* */
- /* */
- /******************************************************/
- extern void polling();
- BYTE atapi_chk_time_out(BYTE wait_state,int w_time)
- {
- int res=1,i=0;
- UINT16 timenow,diff=0,old_t,status;
- if(dev_status_flag&ATAPI_WAIT_TIME_OUT)
- {
- printf("<bug:reentry>");
- return 0;
- }
- dev_status_flag|=ATAPI_WAIT_TIME_OUT;
- old_t=regs0->rtc_15_0;
- while(diff<w_time)
- {
- timenow = regs0->rtc_15_0;
- diff = timenow-old_t;
- if(wait_state == WAIT_IRQ)
- {
- #ifdef DVD728
- if(regs0->dvddsp_ata_config & ATAPI_DEVICE_INT)
- #else
- if(regs0->dvddsp_config & ATAPI_DEVICE_INT)
- #endif
- res=0;
- }else if(wait_state== WAIT_STATUS_NO_BSY)
- {//wait BUSY bit of STATUS register is 0
- res=(atapi_reg_read(IDE_STATUS) & STATUS_BSY);
- }else if(wait_state== WAIT_ALT_NO_BUSY)
- {//wait BUSY bit of ALT STATUS register is 0
- res=(atapi_reg_read(IDE_ALT_STATUS) & STATUS_BSY);
- }else if(wait_state== WAIT_DRQ_OK)
- {//wait DRQ=1 or BUSY bit=0
- status = atapi_reg_read(IDE_STATUS);
- if( !(status & STATUS_BSY)|| (status & STATUS_DRQ) )
- res=0;
- // printf("<w:%x>",status);
- }else if(wait_state== WAIT_DRQ_HIGH)
- {//wait DRQ=1
- if( (atapi_reg_read(IDE_STATUS) & STATUS_DRQ) )
- res=0;
- }else if(wait_state== WAIT_DRQ_BSY_ZERO)
- {//wait DRQ=0 and BUSY=0
- res=(atapi_reg_read(IDE_STATUS) & (STATUS_BSY | STATUS_DRQ));
- }
- if(res)
- {//terry,2-5-15 15:56,reduce sensetive ability.
- //terry,2002/6/4 05:38PM,avoiding many confuse on read navigation data
- if( (dev_status_flag&READ_PRESENT_DATA)||(cd_type_loaded==CDROM) )
- {
- if( (system_state==SYSTEM_BROWSE)&&(i>200) )
- {
- polling();
- cderr_update_show_time();
- }else
- disp_fan_in();
- i++;
- }else if(system_state==SYSTEM_IDLE)
- polling();
- delay_1us(500);
- }else
- break;
- }//while
- dev_status_flag&=~ATAPI_WAIT_TIME_OUT;
- return res;
- }
- UINT8
- atapi_do_set_features(void)
- {
- UINT8 block_cmd[4];
- // enable PIO mode 4
- block_cmd[0] = 0x03;
- block_cmd[1] = 0x0C;
- block_cmd[2] = 0x00;
- block_cmd[3] = 0xEF;
- atapi_write_block(block_cmd);
- if (atapi_is_error() == 1) {
- printf("do_set_features errorn");
- return 1;
- }
- return 0;
- }
- // Packet command
- // read 18 bytes
- UINT8
- atapi_p_request_sense(UINT8 *block_info)
- {
- int sense_key;
- UINT8 pc[12];
- #ifdef USE_HDD
- //Verdure add, cyue:2002-06-12 04:45PM modified
- if (hd_play) return 0;
- #endif
- request_sense_flag=0;
- memset(pc, 0, 12);
- pc[0] = 0x03;
- pc[4] = 0x12;
- if (atapi_do_packet(pc) == 1) {
- printf("p_request_sense do_packet errorn");
- cderr_handler(CDERR_ATA_NOT_READY);
- return 1;
- }
- memset(block_info, 0xFF, 18);
- 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;
- }
- }
- //printf("sense info:n");
- //print_block(block_info, 18);
- return 0;
- }
- UINT8
- atapi_p_test_unit_ready(void)
- {
- UINT8 pc[12];
- UINT8 pc_rdata[32];
- int ret;
- memset(pc, 0, 12);
- //printf("!");
- ret=atapi_do_packet(pc);//ret==0, unit is ready
- if(ret==1)
- {
- 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();
- if (atapi_is_error() == ATAPI_ERROR) {
- printf("enter atapi_p_start_stop_unit errorn");
- atapi_p_request_sense(pc_rdata);
- }
- 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");
- return ATAPI_ERROR;
- }
- //printf("%dn", pc_rdata[1] >> 5);
- 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];
- //atapi_p_test_unit_ready();
- #if 0 //mark it to reduce code
- if (0)
- {
- //printf("generic_packet startn");
- print_block(cgc->cmd, 12); //printf("n");
- }
- switch (cgc->cmd[0]) {
- case GPCMD_READ_DVD_STRUCTURE:
- case GPCMD_REPORT_KEY:
- if (atapi_do_packet(cgc->cmd)) {
- printf("----------------generic packet errorn");
- atapi_p_request_sense(pc_rdata);//kenny
- return -1;
- }
- atapi_receive_data(cgc->buffer, cgc->buflen);
- break;
- case GPCMD_SEND_KEY:
- if (atapi_do_packet(cgc->cmd)) {
- printf("----------------generic packet errorn");
- atapi_p_request_sense(pc_rdata);//kenny
- return -1;
- }
- atapi_send_data(cgc->buffer, cgc->buflen);
- break;
- }
- #endif
- #if 1 //reduced code
- if ((cgc->cmd[0]==GPCMD_READ_DVD_STRUCTURE)||(cgc->cmd[0]==GPCMD_REPORT_KEY))
- {
- if (atapi_do_packet(cgc->cmd)!=0)
- {
- printf(__FUNCTION__ ":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(__FUNCTION__ ":packet errorn");
- atapi_p_request_sense(pc_rdata);
- memset(cgc->buffer,0,cgc->buflen);
- return -1;
- }
- atapi_send_data(cgc->buffer, cgc->buflen);
- }
- #endif
- {
- int i;
- i = atapi_is_error();
- if (i != 0) {
- UINT8 ubuf[20];
- printf(__FUNCTION__":error %dn", i);
- atapi_p_request_sense(ubuf);
- }
- return -i;
- }
- }
- 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;
- }
- UINT8
- atapi_block_read(UINT32 lba, UINT32 len)
- {
- UINT8 pc_rdata[32];
- #ifdef USE_HDD
- //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);
- //lba=lba_st.lba;
- return ATAPI_ERROR;//2001/12/20
- }
- if (is_user_opened())
- {
- printf("USER OPEN!!!n");
- return ATAPI_ERROR;
- }
- dev_status_flag|=READ_PRESENT_DATA;//kenny
- if (DiscType != CDDVD)
- {
- //printf("readcdn");
- if (atapi_read_cd(lba, len) == ATAPI_ERROR) return ATAPI_ERROR;
- if ( (cd_type_loaded==CDDA) && (cd_subtype!=CD_DTS) )
- regs0->dvddsp_blocksize = iBlockLen; //Jeff 20020927
- else
- regs0->dvddsp_blocksize = 2352/2;
- regs0->dvddsp_blocklength = len;
- #ifdef DVD728
- regs0->dvddsp_ata_config = DVDDSP_CONFIG_DEF;
- #else
- regs0->dvddsp_config = PIO_MODE2|DVDDSP_CONFIG_DEF;//DVDDSP_CONFIG_DEF;
- #endif
- }
- else
- { // DVD
- //printf("read12n");
- if (atapi_p_read_12(lba, len) == ATAPI_ERROR) return ATAPI_ERROR;
- #ifdef DVD728
- regs0->dvddsp_public = 0;
- if (CSSEnable)
- {
- #define CPPM_ENABLE
- #ifdef CPPM_ENABLE
- /*if(len==1)
- {
- regs0->dvddsp_public = 0x0080;
- }else */
- {
- //regs0->dvddsp_public = 0x80|ATAPI_CSS_ENABLE|(1<<8); // for FPGA
- regs0->dvddsp_public = 0x80|ATAPI_CSS_ENABLE; // for 8200 real chip + ATAPI loader
- }
- regs0->css_config = 0x00; // css use hw
- //regs0->css_public = 1<<8; // cppm
- regs0->css_public = 0;
- #else
- regs0->dvddsp_public = 0x0080 | ATAPI_CSS_ENABLE;
- regs0->css_config = 0x00; // css use hw
- //regs0->css_public = 0<<8; // css
- #endif
- }else
- regs0->dvddsp_public = 0x0080;
- #if 0
- regs0->dvddsp_public = 0;
- regs0->dvddsp_public = 0x0080|(1<<8); // host enable cppm
- regs0->css_config = 0x00; // css use hw
- regs0->css_public = 1<<8; // ..
- #endif
- regs0->dvddsp_ata_config = DVDDSP_CONFIG_DEF;
- #else
- #ifdef NINTAUS_LOADER//only use PIO_MODE2
- #define PIO_MODE_USE PIO_MODE2
- #else
- #define PIO_MODE_USE PIO_MODE3
- #endif
- if (CSSEnable)
- regs0->dvddsp_config = PIO_MODE_USE|ATAPI_CSS_ENABLE|DVDDSP_CONFIG_DEF;
- else
- regs0->dvddsp_config = PIO_MODE_USE|DVDDSP_CONFIG_DEF;
- #endif // DVD728
- regs0->dvddsp_blocksize = 1024;
- regs0->dvddsp_blocklength = len;
- }
- if (atapi_reg_read(IDE_STATUS) == 0x50) { //DRQ=0,BSY=0,DRDY=1,DSC=1
- printf("skip directly!n");
- return ATAPI_ERROR;
- } else {
- #ifdef DVD728
- regs0->dvddsp_function = ATAPI_READ | DATA_MODE | HOST_START | 0x00;
- #else
- regs0->dvddsp_function = (IDE_DATA<<8) | ATAPI_READ | DATA_MODE | HOST_START ;
- #endif
- }
- #if 0
- if((atapi_reg_read(IDE_STATUS) & (STATUS_BSY|STATUS_DRQ)) != STATUS_DRQ){
- printf("skip directly!n");
- return ATAPI_ERROR;
- } else {
- regs0->dvddsp_function = (IDE_DATA<<8) | ATAPI_READ | DATA_MODE | HOST_START ;
- }
- #endif
- return ATAPI_OK;
- }
- void
- atapi_init(void)
- {
- #ifdef DVD728
- regs0->dvddsp_ata_config = DVDDSP_CONFIG_DEF;
- atapi_rst(DSP_HOST_RESET|ATA_HW_RESET);
- regs0->dvddsp_ata_config = DVDDSP_CONFIG_DEF;
- #else
- regs0->dvddsp_config = PIO_MODE2|DVDDSP_CONFIG_DEF;//DVDDSP_CONFIG_DEF;
- atapi_rst(DSP_HOST_RESET|ATA_HW_RESET);
- regs0->dvddsp_config = PIO_MODE2|DVDDSP_CONFIG_DEF;//DVDDSP_CONFIG_DEF;
- #endif
- delay(1);
- atapi_p_test_unit_ready();//start up loader
- }
- #include "dvdioctl.h"
- #if DISC_SYSTEM==DISC_SYSTEM_ATAPI
- void disc_init(void)
- {
- DiscType = CDUNKNOWN;
- if (udf_find_anchor() == 0)
- {
- printf("no anchor foundn");
- } else {
- printf("initialize filesystemn");
- if ( fs_init() < 0) return;
- if(dVMG_LSN)
- {
- DiscType = CDDVD;
- cd_type_loaded=DiscType;
- #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
- printf("css:%xn",CSSEnable);
- /*
- if (s.copyright.cpst == 0)
- { // no css
- epp_write("no cssn");
- CSSEnable = 0;
- } else
- {
- epp_write("css enn");
- CSSEnable = 1;
- }*/
- }
- #ifdef DVD_AUDIO
- cppm_init( dAMG_LSN );
- #endif
- }
- }
- #else
- void disc_init(void)
- {
- dvd_struct s;
- if (udf_find_anchor() == 0)
- {
- printf("no anchor foundn");
- DiscType = CDUNKNOWN;
- } else {
- printf("initialize filesystemn");
- if ( fs_init() < 0)
- {
- DiscType = CDUNKNOWN;
- return;
- }
- if(dVMG_LSN)
- {
- DiscType = CDDVD;
- cd_type_loaded=DiscType;
- s.type = DVD_STRUCT_COPYRIGHT;
- s.copyright.layer_num = 0;
- CSSEnable = 1;
- }else
- {
- DiscType = CDUNKNOWN;
- }
- }
- }
- #endif
- BYTE user_only=0;
- 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, int msf_flag, 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[9] = (format << 6);//2001/9/26 mark it
- if (msf_flag)
- pc[1] = 2;
- 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];
- UINT8 pc_rdata[32];
- #ifdef NINTAUS_LOADER
- DiscType=CDDVD;
- return 0;
- #endif
- memset(&pc, 0, sizeof(pc));
- pc[0] = 0x5A;
- pc[2]=0x41;
- pc[7] = 0;
- pc[8] =buflen =0x0A;
- if (atapi_do_packet(pc) == 1) {
- printf("atapi_mode_sense errorn");
- atapi_p_request_sense(pc_rdata);
- return 1;
- }
- memset(pwb, 0, sizeof(pwb));
- if (atapi_receive_data(pwb, buflen) == 1) {
- printf("atapi_mode_sense receive data errorn");
- return 1;
- }
- //printf("DISC TYPE=%xn",pwb[2]);
- //pwb[2]=0x01: VCD,MP3
- //pwb[2]=0x02,0x06,0x12,0x16,0x22,0x26: CDDA
- //pwb[2]=0x041: DVD
- 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
- DiscType=CDUNKNOWN;
- return 0;
- }
- int
- atapi_open_tray(void)
- {
- printf("openn");
- return atapi_p_start_stop_unit(START_STOP_DO_EJECT);
- }
- /*
- int
- atapi_close_tray(void)
- {
- printf("closen");
- return atapi_p_start_stop_unit(START_STOP_DO_LOAD);
- }
- */
- int
- atapi_close_tray(UINT8 nStatus)
- {
- 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;
- }
- /*
- ** FUNCTION
- ** atapi_read_toc
- **
- */
- int atapi_read_toc(void)
- {
- BYTE cd_trk_cna;
- //int done;
- int toc_retry;
- int i;
- int ret;
- /*
- ** 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,1,2,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,1,2,(len/2*2)+4);
- #if 0
- {
- int j;
- printf("=========================n");
- for(j=0;j<(len/11);j++)
- {
- for(i=0;i<=10;i++)
- printf("%02x ",pwb[j*11+i]);
- printf("n");
- }
- printf("=========================n");
- }
- #endif
- SessionNs=0;
- for (i=4; i<len; i+=11)
- {
- p=&pwb[i];
- cd_trk_cna=(p[1]&0x0f)<<4;
- cd_trk_cna|=(p[1]&0xf0)>>4;
- if(p[3]<=0xa2)
- {
- if(p[3]==0xa0)
- {
- trk=0x64;
- if(p[0]==1)
- {
- cd_trk_lo_now=cd_trk_lo=p[8];
- }else if(p[0]>1)
- {
- SessionNs=p[8];
- printf("lo:%xn",p[8]);
- }
- }
- else if(p[3]==0xa1)
- {
- cd_trk_hi=p[8];
- trk=0x65;
- }
- else if(p[3]==0xa2)
- {
- trk=0x66;
- }
- else
- {
- trk=p[3];
- if(trk>100)
- {
- printf("~~read toc trk no.(%x) error~~n",trk);
- return -2;
- }
- }
- pFsJpeg->cdrom.track_info[trk]=((UINT32)(cd_trk_cna)<<24) | ((UINT32)p[8] <<16)| ((UINT32)p[9]<<8) | ((BYTE)(p[10]));
- printf("trk:%d msf:%08xn",trk,pFsJpeg->cdrom.track_info[trk]);
- }
- }
- 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================
- #ifdef 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 //NO_DVD_SERVO
- #if 0
- void
- atapi_menu(void)
- {
- char buf[5];
- while (1) {
- epp_write_wait("n");
- //printf("config 0x%04xn", regs0->dvddsp_config);
- epp_write_wait("1. EJECTn");
- epp_write_wait("2. LOADn");
- epp_write_wait("3. STARTn");
- epp_write_wait("4. STOPn");
- epp_write_wait("5. Hard Resetn");
- epp_write_wait("enter> continuen");
- //regs0->dvddsp_config = E10MHZ_MODE;
- regs0->dvddsp_config = 0;
- mon_read(buf);
- if (buf[0] == '1') {
- atapi_p_start_stop_unit(START_STOP_DO_EJECT);
- epp_write_wait("ejectn");
- } else if (buf[0] == '2') {
- atapi_p_start_stop_unit(START_STOP_DO_LOAD);
- epp_write_wait("loadn");
- } else if (buf[0] == '3') {
- atapi_p_start_stop_unit(START_STOP_DO_START);
- epp_write_wait("startn");
- } else if (buf[0] == '4') {
- atapi_p_start_stop_unit(START_STOP_DO_STOP);
- epp_write_wait("stopn");
- } else if (buf[0] == '5') {
- atapi_hard_rst();
- epp_write_wait("hard resetn");
- } else if (buf[0] == 0) {
- return;
- }
- }
- }
- UINT8
- atapi_p_unlock(void)
- {
- flush_atapi();
- memset(pc, 0, 12);
- pc[0] = 0x1E;
- pc[4] = 0x03;
- if (atapi_do_packet(pc) == 1) {
- printf("atapi_p_unlock errorn");
- atapi_p_request_sense(pc_rdata);//kenny
- return 1;
- }
- return 0;
- }
- // read 512 bytes
- UINT8 atapi_do_identify_packet_device(UINT8 *block_info)
- {
- UINT8 block_cmd[4];
- memset(block_cmd, 0, 4);
- block_cmd[3] = 0xA1;
- atapi_write_block(block_cmd);
- if (atapi_is_error() == 1) {
- printf("do_identify_packet_device errorn");
- return 1;
- }
- if (atapi_receive_data(block_info, 512) == 1) {
- printf("do_identify_packet_device receive errorn");
- return 1;
- }
- return 0;
- }
- UINT8
- atapi_read_cd_msf(t_cdrom_msf *pmsf)
- {
- UINT8 pc[12];
- UINT8 pc_rdata[32];
- memset(pc, 0, 12);
- pc[0] = 0xB9;
- pc[3] = pmsf->m0;
- pc[4] = pmsf->s0;
- pc[5] = pmsf->f0;
- pc[6] = pmsf->m1;
- pc[7] = pmsf->s1;
- pc[8] = pmsf->f1;
- pc[9] = 0x10;
- print_block(pc, 12);
- if (atapi_do_packet(pc) == 1) {
- printf("p_read_cd_msf errorn");
- atapi_p_request_sense(pc_rdata);
- return 1;
- }
- return 0;
- }
- UINT8
- atapi_p_read_capacity(UINT32 *plba, UINT32 *plen)
- {
- UINT8 *p;
- UINT8 pc[12];
- UINT8 pc_rdata[32];
- memset(pc, 0, 12);
- pc[0] = 0x25;
- if (atapi_do_packet(pc) == 1) {
- printf("p_read_capacity errorn");
- atapi_p_request_sense(pc_rdata);//kenny
- return 1;
- }
- memset(pc_rdata, 0, 12);
- if (atapi_receive_data(pc_rdata, 8) == 1) {
- printf("p_read_capacity receive data errorn");
- return 1;
- }
- p = pc_rdata;
- print_block(p, 12);
- *plba = getUINT32_bi(((UINT8 *)p) + 0);
- *plen = getUINT32_bi(((UINT8 *)p) + 4);
- return 0;
- }
- #endif