/* -*- linux-c -*- * Copyright (c) 2004-2006 Winbond Electronics Corp. All rights reserved. * * The contents of this file are subject to the Open * Software License version 1.1 that can be found at * http://www.opensource.org/licenses/osl-1.1.txt and is included herein * by reference. * * Alternatively, the contents of this file may be used under the terms * of the GNU General Public License version 2 (the "GPL") as distributed * in the kernel source COPYING file, in which case the provisions of * the GPL are applicable instead of the above. If you wish to allow * the use of your version of this file only under the terms of the * GPL and not to allow others to use your version of this file under * the OSL, indicate your decision by deleting the provisions above and * replace them with the notice and other provisions required by the GPL. * If you do not delete the provisions above, a recipient may use your * version of this file under either the OSL or the GPL. * Maintained by: Weiming Shuai Jin Yuan Mu Dezheng Shen $Author: sjin $ $Id: wbmscard.h,v 1.8.2.5 2006/06/22 06:06:12 sjin Exp $ --- don't modify lines above --- Description: Enviornments: (1) RedHat 9 on 32-bit Intel UP/32-bit Intel dual-core (2) Fedora Core 4 (2.6.11) on 32-bit Intel/32-bit Intel dual-core/64-bit AMD/64-bit Intel dual-core (3) RedHat Enterprise Workstatin Rel 4 UP2 (2.6.9) on 32-bit Intel 32-bit Intel dual-core/64-bit AMD/64-bit Intel dual-core */ #ifndef _WB_MS_CARD_H_ #define _WB_MS_CARD_H_ #include #include #include "wbvirtualdev.h" #include "wbmsreader.h" #include "wbtable.h" #define MS_PAGE_SIZE (512) #define MS_MAX_BOOT_BLOCK_NUM (12) //---------------------card type-------------------------- #define WDEV_UNKNOWN (0x00) #define WDEV_MS (0x01) #define WDEV_MSPRO (0x02) #define WDEV_MS_IO (0x03) #define WDEV_MSPRO_IO (0x04) #define WRW_READ (0x01) #define WRW_WRITE (0x02) //---------------------MS/MSPro Command------------------ #define TPC_CODE(tpc) (((u8)(((u8)(tpc))<<4)) |(~((u8)(tpc)) & 0x0F)) #define TPC_READ_LONG_DATA TPC_CODE(0x2) //TPC: 0010 #define TPC_READ_SHORT_DATA TPC_CODE(0x3) //TPC: 0011 #define TPC_READ_REG TPC_CODE(0x4) //TPC: 0100 #define TPC_GET_INT TPC_CODE(0x7) //TPC: 0111 #define TPC_WRITE_LONG_DATA TPC_CODE(0xD) //TPC: 1101 #define TPC_WRITE_SHORT_DATA TPC_CODE(0xC) //TPC: 1100 #define TPC_WRITE_REG TPC_CODE(0xB) //TPC: 1011 #define TPC_SET_RW_REG_ADRS TPC_CODE(0x8) //TPC: 1000 #define TPC_SET_CMD TPC_CODE(0xE) //TPC: 1110 #define TPC_EX_SET_CMD TPC_CODE(0x9) //TPC: 1001 //MS Command Parameter #define MS_CP_BLOCK (0) #define MS_CP_PAGE (0x20) #define MS_CP_EXTRA (0x40) #define MS_CP_OVERWRITE (0x80) //MS Memory Access Command #define MS_BLOCK_READ (0xAA) #define MS_BLOCK_WRITE (0x55) #define MS_BLOCK_END (0x33) #define MS_BLOCK_ERASE (0x99) #define MS_FLASH_STOP (0xCC) //MS Function Command #define MS_SLEEP (0x5A) #define MS_CLEAR_BUF (0xC3) #define MS_RESET (0x3C) //MSPro Memory Access Command #define MSPRO_READ_DATA (0x20) #define MSPRO_WRITE_DATA (0x21) #define MSPRO_READ_ATRB (0x24) #define MSPRO_STOP (0x25) #define MSPRO_ERASE (0x26) #define MSPRO_SET_IBD (0x46) #define MSPRO_GET_IBA (0x47) //MSPro Function Command #define MSPRO_FORMAT (0x10) #define MSPRO_SLEEP (0x11) //MS register #define MSREG_INT_CMDNK (0x01) #define MSREG_INT_BREQ (0x20) #define MSREG_INT_ERR (0x40) #define MSREG_INT_CED (0x80) #define MSREG_STATUS0_WP (0x01) #define MSREG_STATUS0_SL (0x02) #define MSREG_STATUS0_BF (0x10) #define MSREG_STATUS0_BE (0x20) #define MSREG_STATUS0_FB0 (0x40) #define MSREG_STATUS0_MB (0x80) #define MSREG_STATUS1_UCFG (0x01) #define MSREG_STATUS1_FGER (0x02) #define MSREG_STATUS1_UCEX (0x04) #define MSREG_STATUS1_EXER (0x08) #define MSREG_STATUS1_UCDT (0x10) #define MSREG_STATUS1_DTER (0x20) #define MSREG_STATUS1_FBI (0x40) #define MSREG_STATUS1_MB (0x80) #define MSREG_SYSTEM_PAM (0x08) //MS page Extra Data Area // Overwrite Flag #define MS_OVERWRITE_BLOCK_STATUS (0x80) #define OVERWRITE_BLOCK_OK (0x80) #define OVERWRITE_BLOCK_NG (0x00) #define MS_OVERWRITE_PAGE_STATUS (0x60) #define OVERRITE_PAGE_OK (0x60) #define OVERRITE_PAGE_NG (0x40) #define OVERRITE_PAGE_UDEF (0x20) #define OVERRITE_PAGE_ERROR (0x00) #define OVERWRITE_USED_UPDATING (0x00) #define OVERWRITE_ERASED_WRITTEN (0x10) #define MS_OVERWRITE_UPDATA_STATUS (0x10) #define MS_OVERWRITE_FORMAT_RESERVED (0x0F) //Management Flag #define MS_MANAGEMENT_ACCESS (0x20) #define MS_MANAGEMENT_COPY (0x10) #define MS_MANAGEMENT_TRANS_TABLE (0x08) #define MS_MANAGEMENT_SYSTEM (0x04) #define MSPROREG_INT_CED (0x80) #define MSPROREG_INT_ERR (0x40) #define MSPROREG_INT_BREQ (0x20) #define MSPROREG_INT_CMDNK (0x01) #define MSPROREG_STATUS_ES (0x80) #define MSPROREG_STATUS_SL (0x02) #define MSPROREG_STATUS_WP (0x01) #define MSPROREG_SYSTEM_SRAC (0x80) typedef struct tag_wbms_extra_data { u8 overwrite_flag; u8 management_flag; u16 physical_address; u8 reserved[5]; u8 extra_ecc; u8 data_area_ecc; } __attribute__ ((packed)) wbms_extra_data_t; #define MS_BOOT_BLOCK_ID (0x0001) //Header typedef struct tag_wbms_boot_header { u16 block_id; u16 format_reserved; u8 reserved0[184]; u8 data_entry; u8 reserved1[179]; } __attribute__ ((packed)) wbms_boot_header_t; //System Entry typedef struct tag_wbms_system_entry_item { u32 start_addr; u32 data_size; u8 data_type_id; u8 reserved[3]; } __attribute__ ((packed)) wbms_system_entry_item_t; typedef struct tag_wbms_system_entry { wbms_system_entry_item_t disabled_block; wbms_system_entry_item_t cis_idi; u8 reserved[24]; } __attribute__ ((packed)) wbms_system_entry_t; //Boot & Attribute Information typedef struct tag_wbms_boot_attribute_information { u8 memorystick_class; u8 format_unique_value1; u16 block_size; u16 number_of_block; u16 number_of_effective_block; u16 page_size; u8 extr_data_size; u8 format_unique_value2; u64 assembly_time; u8 format_unique_value3; u8 serial_number[3]; u8 assembly_manufacturer_code; u8 assembly_model_code[3]; u16 memory_mamufacturer_code; u16 memory_device_code; u16 implemented_capacity; u8 format_unique_value4[2]; u8 vcc; u8 vpp; u16 controller_number; u16 controller_function; u8 reserved1[9]; u8 transfer_supporting; u16 format_unique_value5; u8 format_type; u8 memorystick_application; u8 device_type; u8 reserved2[22]; u8 format_uniqure_value6[2]; u8 reserved3[15]; } __attribute__ ((packed)) wbms_boot_attribute_information_t; typedef struct tag_wbms_boot_block_page0 { wbms_boot_header_t header; wbms_system_entry_t entry; wbms_boot_attribute_information_t attribute; } __attribute__ ((packed)) wbms_boot_block_page0_t; typedef struct tag_wbms_idi { u16 general_config; u16 logical_cylinders; u16 reserved; u16 logical_heads; u16 track_size; u16 sector_size; u16 sectors_per_track; u16 msw; u16 lsw; u16 reserved0; u8 serial_number[20]; u16 buffer_type; u16 buffer_size_increments; u16 long_command_ecc; u8 firmware_version; u8 model_name; u16 reserved1; u16 pio_mode_number; u16 dma_mode_number; u16 field_validity; u16 current_logical_cylinders; u16 current_logical_heads; u16 current_sectors_per_track; u32 current_sector_capality; u16 mutiple_sector_setting; u32 addressable_sectors; u16 single_word_dma; u16 multi_word_dma; u8 reserved2[128]; } __attribute__ ((packed)) wbms_idi; //----------------Card Register---------------- //MS register typedef struct tag_wbms_status_register { u8 reserved1; u8 interrupt; u8 status0; u8 status1; u8 type; u8 reserved2; u8 category; u8 class; u8 reserved3[8]; } __attribute__ ((packed)) wbms_status_register_t; typedef struct tag_wbms_param_register { u8 system; u8 block_address[3]; u8 cp; u8 page_address; } __attribute__ ((packed)) wbms_param_register_t; typedef struct tag_wbms_extra_data_register { u8 overwrite_flag; u8 management_flag; u16 logical_address; } __attribute__ ((packed)) wbms_extra_data_register_t; typedef struct tag_wbms_register { wbms_status_register_t status; wbms_param_register_t params; wbms_extra_data_register_t extra; } __attribute__ ((packed)) wbms_register_t; //MSPro register typedef struct tag_wbmspro_status_register { u8 reserved1; u8 interrupt; u8 status; u8 reserved2; u8 type; u8 reserved3; u8 category; u8 class; u8 reserved4[8]; } __attribute__ ((packed)) wbmspro_status_register_t; typedef struct tag_wbmspro_param_register { u8 system; u16 data_count; u32 data_address; u8 cmd_param; } __attribute__ ((packed)) wbmspro_param_register_t; typedef struct tag_wbmspro_register { wbmspro_status_register_t status; wbmspro_param_register_t params; } __attribute__ ((packed)) wbmspro_register_t; typedef struct tag_wbmspro_attribute { u16 signature; u16 version; u8 device_information_entry_count; u8 reserved[11]; } __attribute__ ((packed)) wbmspro_attribute_t; #define MSPRO_DEVINFOID_SYSINFO (0x10) #define MSPRO_DEVINFOID_MODELNAME (0x15) #define MSPRO_DEVINFOID_MBR (0x20) #define MSPRO_DEVINFOID_PBR16 (0x21) #define MSPRO_DEVINFOID_PBR32 (0x22) #define MSPRO_DEVINFOID_SPECFILEVALUES1 (0x25) #define MSPRO_DEVINFOID_SPECFILEVALUES2 (0x26) #define MSPRO_DEVINFOID_IDENTIFYDEVINFO (0x30) typedef struct tag_wbmspro_device_info_entry_item { u32 address; u32 size; u8 info_id; u8 reserved[3]; } __attribute__ ((packed)) wbmspro_device_info_entry_item_t; typedef struct tag_wbmspro_device_info_entry { wbmspro_device_info_entry_item_t entry[12]; u8 reserved[256]; } __attribute__ ((packed)) wbmspro_device_info_entry_t; typedef struct tag_wbmspro_sys_info { u8 class; // must be ? u8 reserved; // see below u16 block_size; // n KB u16 block_count; // number of physical block u16 user_block_count; // number of logical block u16 page_size; // must be 0x200 u8 reserved1[2]; // MS original Extra data size and format reserved u8 assembly_date[8]; u32 serial_number; u8 assembly_maker_code; u8 assembly_model_code[3]; u16 memory_maker_code; u16 memory_model_code; u8 reserved2[4]; //reserved[6] u8 vcc; u8 vpp; u16 controller_number; u16 controller_function; u16 start_sector; u16 unit_size; u8 ms_sub_class; u8 reserved3[4]; u8 interface_type; u16 controller_code; u8 format_type; u8 reserved4;; u8 device_type; u8 reserved5[7]; u8 mspro_id[16]; u8 reserved6[16]; } __attribute__ ((packed)) wbmspro_sys_info_t; typedef struct tag_wbmspro_mbr { u8 default_boot_partition; u8 start_head; u8 start_cylinder; u8 partition_type; u8 end_head; u8 end_sector; u8 end_cylinder; u32 start_sectors; u32 sectors_per_partition; } __attribute__ ((packed)) wbmspro_mbr_t; #define MS_IDI_OFFSET (256) typedef struct tab_wbmspro_identify_dev_info { u16 cylinders; u16 heads; u16 byte_per_track; u16 byte_per_sector; u16 sectors_per_track; u8 reserved[6]; } __attribute__ ((packed)) wbmspro_identify_dev_info_t; //Global variable typedef struct tag_wbms_card_info { wbms_register_t *ms_register; wbmspro_register_t *mspro_registe; unsigned char registers[0x20]; unsigned char dev_type; unsigned char rw_capality; unsigned char transfer_mode; unsigned int block_size; unsigned int page_pre_block; unsigned int number_of_physical_block; unsigned int number_of_boot_block; unsigned int boot_block_num[2]; unsigned short cylinders; unsigned short heads; unsigned int sectors; unsigned short sectors_per_track; unsigned int sector_size; } __attribute__ ((packed)) wbms_card_info_t; //TPC layer static inline int wbms_send_tpc(unsigned char cmd, unsigned char *buffer, int length); static inline int tpc_read_long_data(void); static inline int tpc_read_short_data(void); static inline int tpc_read_reg(void); static inline int tpc_get_int(void); static inline int tpc_write_long_data(void); static inline int tpc_write_short_data(void); static inline int tpc_write_reg(unsigned char *buffer, int len); static inline int tpc_set_cmd(unsigned char flash_cmd); static inline int tpc_ex_set_cmd(unsigned char flash_cmd, unsigned int block_addr, unsigned short size); static inline int tpc_set_rw_reg_adrs(unsigned char read_adrs, unsigned char read_size, unsigned char write_adrs, unsigned char write_size); //MS interface layer static int wbmspro_read_attribute(unsigned int page_address, unsigned int num_page, unsigned char *buffer); static int wbms_read_status_register(void); static int wbms_write_register(int start_addr, unsigned char *buffer, int length); static int inline wbms_read_extra_register(void); static int wbms_get_int(void); static int inline wbms_set_rw_param(unsigned char cp, unsigned int block_address, unsigned char page_address); static int wbms_read_page_extra(unsigned int block_address, unsigned short page_address); static int inline wbms_write_page_extra(unsigned int physical, unsigned char page_index, unsigned char overwrite, unsigned short logical); static int wbms_identification_card_type(void); //MSPro function interface static int wbmspro_set_wr_param(unsigned int lba, unsigned short count); #endif /* _WB_MS_CARD_H_ */