mflash : Change MG_BASE define to inline function
PATCH 1/4 mflash : Change MG_BASE define to inline function
Signed-off-by unsik Kim <[email protected]>
--- drivers/block/mg_disk.c | 45 ++++++++++++++++++++++++--------------------- 1 files changed, 24 insertions(+), 21 deletions(-)
drivers/block/mg_disk.c +24 -21
@@ -34,10 +34,13 @@#define MG_RES_SEC ((CONFIG_MG_DISK_RES) << 1) -#define MG_BASE (host.drv_data->base) -static struct mg_host host; +static inline u32 mg_base (void ) +{ +return host.drv_data->base; +} +static block_dev_desc_t mg_disk_dev = { .if_type =IF_TYPE_ATAPI , .part_type =PART_TYPE_UNKNOWN ,
@@ -122,7 +125,7 @@ static unsigned int mg_wait (u32 expect, u32 msec)reset_timer (); from =get_timer (0 ); - status =readb (MG_BASE +MG_REG_STATUS ); + status =readb (mg_base () +MG_REG_STATUS ); do { cur = get_timer(from); if (status & MG_REG_STATUS_BIT_BUSY) {
@@ -131,7 +134,7 @@ static unsigned int mg_wait (u32 expect, u32 msec) }else {/* Check the error condition! */ if (status &MG_REG_STATUS_BIT_ERROR ) { - err =readb (MG_BASE +MG_REG_ERROR ); + err =readb (mg_base () +MG_REG_ERROR );mg_dump_status ("mg_wait" , status, err);break ; }
@@ -144,7 +147,7 @@ static unsigned int mg_wait (u32 expect, u32 msec)if (status &MG_REG_STATUS_BIT_DATA_REQ )break ; } - status =readb (MG_BASE +MG_REG_STATUS ); + status =readb (mg_base () +MG_REG_STATUS ); }while (cur < msec);if (cur >= msec)
@@ -160,15 +163,15 @@ static int mg_get_disk_id (void)u32 i, err, res;u16 *buff = (u16 *)iobuf; -writeb (MG_CMD_ID ,MG_BASE +MG_REG_COMMAND ); +writeb (MG_CMD_ID ,mg_base () +MG_REG_COMMAND ); err =mg_wait (MG_REG_STATUS_BIT_DATA_REQ ,3000 );if (err)return err;for (i =0 ; i < (MG_SECTOR_SIZE /sizeof (u32)) >>1 ; i++) - buff[i] =readw (MG_BASE +MG_BUFF_OFFSET + i *2 ); + buff[i] =readw (mg_base () +MG_BUFF_OFFSET + i *2 ); -writeb (MG_CMD_RD_CONF ,MG_BASE +MG_REG_COMMAND ); +writeb (MG_CMD_RD_CONF ,mg_base () +MG_REG_COMMAND ); err =mg_wait (MG_STAT_READY ,3000 );if (err)return err;
@@ -235,18 +238,18 @@ static int mg_disk_reset (void)/* soft reset on */ writeb (MG_REG_CTRL_RESET |MG_REG_CTRL_INTR_DISABLE , -MG_BASE +MG_REG_DRV_CTRL ); +mg_base () +MG_REG_DRV_CTRL ); err =mg_wait (MG_REG_STATUS_BIT_BUSY ,3000 );if (err)return err;/* soft reset off */ -writeb (MG_REG_CTRL_INTR_DISABLE ,MG_BASE +MG_REG_DRV_CTRL ); +writeb (MG_REG_CTRL_INTR_DISABLE ,mg_base () +MG_REG_DRV_CTRL ); err =mg_wait (MG_STAT_READY ,3000 );if (err)return err; - init_status =readb (MG_BASE +MG_REG_STATUS ) &0xf ; + init_status =readb (mg_base () +MG_REG_STATUS ) &0xf ;if (init_status ==0xf )return MG_ERR_INIT_STAT ;
@@ -265,13 +268,13 @@ static unsigned int mg_out(unsigned int sect_num,if (err)return err; -writeb ((u8 )sect_cnt,MG_BASE +MG_REG_SECT_CNT ); -writeb ((u8 )sect_num,MG_BASE +MG_REG_SECT_NUM ); -writeb ((u8)(sect_num >>8 ),MG_BASE +MG_REG_CYL_LOW ); -writeb ((u8)(sect_num >>16 ),MG_BASE +MG_REG_CYL_HIGH ); +writeb ((u8 )sect_cnt,mg_base () +MG_REG_SECT_CNT ); +writeb ((u8 )sect_num,mg_base () +MG_REG_SECT_NUM ); +writeb ((u8)(sect_num >>8 ),mg_base () +MG_REG_CYL_LOW ); +writeb ((u8)(sect_num >>16 ),mg_base () +MG_REG_CYL_HIGH );writeb ((u8)((sect_num >>24 ) |MG_REG_HEAD_LBA_MODE ), -MG_BASE +MG_REG_DRV_HEAD ); -writeb (cmd,MG_BASE +MG_REG_COMMAND ); +mg_base () +MG_REG_DRV_HEAD ); +writeb (cmd,mg_base () +MG_REG_COMMAND );return err; }
@@ -293,11 +296,11 @@ static unsigned int mg_do_read_sects(void *buff, u32 sect_num, u32 sect_cnt)/* TODO : u16 unaligned case */ for (j =0 ; j <MG_SECTOR_SIZE >>1 ; j++) { *(u16 *)buff_ptr = -readw (MG_BASE +MG_BUFF_OFFSET + (j <<1 )); +readw (mg_base () +MG_BUFF_OFFSET + (j <<1 )); buff_ptr +=2 ; } -writeb (MG_CMD_RD_CONF ,MG_BASE +MG_REG_COMMAND ); +writeb (MG_CMD_RD_CONF ,mg_base () +MG_REG_COMMAND );MG_DBG ("%u (0x%8.8x) sector read" , sect_num + i, (sect_num + i) *MG_SECTOR_SIZE );
@@ -426,11 +429,11 @@ static int mg_do_write_sects(void *buff, u32 sect_num, u32 sect_cnt)/* TODO : u16 unaligned case */ for (j =0 ; j <MG_SECTOR_SIZE >>1 ; j++) {writew (*(u16 *)buff_ptr, -MG_BASE +MG_BUFF_OFFSET + (j <<1 )); +mg_base () +MG_BUFF_OFFSET + (j <<1 )); buff_ptr +=2 ; } -writeb (MG_CMD_WR_CONF ,MG_BASE +MG_REG_COMMAND ); +writeb (MG_CMD_WR_CONF ,mg_base () +MG_REG_COMMAND );MG_DBG ("%u (0x%8.8x) sector write" , sect_num + i, (sect_num + i) *MG_SECTOR_SIZE );
Signature · 1 line
1.5.6.6