ms_misc.h 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. #ifndef _H_MS_MISC
  2. #define _H_MS_MISC
  3. #include <linux/types.h>
  4. #include <linux/kernel.h>
  5. #include <linux/err.h>
  6. #include <linux/slab.h>
  7. #include <linux/module.h>
  8. #include <linux/init.h>
  9. #include <linux/delay.h>
  10. #include <mach/am_regs.h>
  11. #include <asm/cacheflush.h>
  12. #include <asm/delay.h>
  13. #include <mach/am_regs.h>
  14. #include "ms_protocol.h"
  15. #include "mspro_protocol.h"
  16. #include "ms_mspro.h"
  17. //#define ms_get_timer_tick() READ_ISA_REG(IREG_TIMER_E_COUNT) //unit: 10us or 1/100ms, max: 0 ~ 0xFFFFFF
  18. #define ms_get_timer_tick() READ_CBUS_REG(ISA_TIMERE)
  19. #define MS_MAX_TIMER_TICK 0xFFFFFF
  20. //#define TIMER_1US 1
  21. //#define TIMER_10US (10*TIMER_1US)
  22. //#define TIMER_1MS (100*TIMER_10US)
  23. #define TIMER_1MS 1
  24. void ms_start_timer(unsigned long time_value);
  25. int ms_check_timer(void);
  26. int ms_check_timeout(void);
  27. #define MS_MSPRO_DEBUG
  28. #define Debug_Printf printk
  29. extern const unsigned short ms_crc_table[];
  30. //#define inline _Inline
  31. //Definition to use block address 0x3400000
  32. //#define AMLOGIC_CHIP_SUPPORT
  33. #ifdef AMLOGIC_CHIP_SUPPORT
  34. #ifdef AVOS
  35. #define WRITE_BYTE_TO_FIFO(DATA) {WRITE_MPEG_REG(HFIFO_DATA,DATA);while((READ_MPEG_REG(BFIFO_LEVEL)>>8) >= 120){}}
  36. #else /* */
  37. #define WRITE_BYTE_TO_FIFO(DATA) {Wr(HFIFO_DATA,DATA);while((Rd(BFIFO_LEVEL)>>8) >= 120){}}
  38. #endif /* */
  39. #endif /* */
  40. #define MS_MSPRO_HW_CONTROL
  41. #define MS_MSPRO_SW_CONTROL
  42. #define MS_MSPRO_ALLOC_MEMORY
  43. #ifdef MS_MSPRO_ALLOC_MEMORY
  44. #define ms_mspro_malloc kzalloc
  45. #define ms_mspro_free kfree
  46. #endif /* */
  47. //Definition for debug
  48. #if ((!defined __ROM_) || (defined __ROM_ && defined __ROMDBG_))
  49. #define MS_MSPRO_DEBUG
  50. //#define MS_MSPRO_CRC_CHECK
  51. #endif /* */
  52. #define MS_MSPRO_CRC_CHECK
  53. //Delay time in 1 us
  54. void ms_delay_us(unsigned long num_us);
  55. //Delay time in 1 ms
  56. void ms_delay_ms(unsigned long num_ms);
  57. //Maximum 20Mhz, Period = 50ns
  58. #define ms_clk_delay_serial_low()
  59. #define ms_clk_delay_serial_high()
  60. //Maximum 40Mhz, Period = 25ns
  61. #define ms_clk_delay_parallel_low()
  62. #define ms_clk_delay_parallel_high()
  63. #define ms_clk_serial_low() {ms_set_clk_low();ms_clk_delay_serial_low();}
  64. #define ms_clk_serial_high() {ms_set_clk_high();ms_clk_delay_serial_high();}
  65. #define ms_clk_parallel_low() {ms_set_clk_low();ms_clk_delay_parallel_low();}
  66. #define ms_clk_parallel_high() {ms_set_clk_high();ms_clk_delay_parallel_high();}
  67. unsigned short ms_verify_crc16(unsigned char *ptr, unsigned int len);
  68. unsigned short ms_cal_crc16(unsigned char *ptr, unsigned int len);
  69. /**************************************************************/
  70. int ms_media_type_identification(MS_MSPRO_Card_Info_t *ms_mspro_info);
  71. int ms_search_boot_block(MS_MSPRO_Card_Info_t *ms_mspro_info, unsigned char *data_buf);
  72. int ms_check_boot_block(MS_MSPRO_Card_Info_t *ms_mspro_info, unsigned char *data_buf);
  73. int ms_check_disabled_block(MS_MSPRO_Card_Info_t *ms_mspro_info, unsigned char *data_buf);
  74. int ms_boot_area_protection(MS_MSPRO_Card_Info_t *ms_mspro_info, unsigned char *data_buf);
  75. int ms_logical_physical_table_creation(MS_MSPRO_Card_Info_t *ms_mspro_info, unsigned short seg_no);
  76. //int ms_read_boot_idi(unsigned char * data_buf);
  77. int ms_read_page(MS_MSPRO_Card_Info_t *ms_mspro_info, unsigned long block_addr, unsigned char page_addr,
  78. unsigned char *data_buf);
  79. int ms_write_page(MS_MSPRO_Card_Info_t *ms_mspro_info, unsigned long block_addr, unsigned char page_addr,
  80. unsigned char *data_buf);
  81. int ms_copy_page(MS_MSPRO_Card_Info_t *ms_mspro_info, unsigned long source_block_addr,
  82. unsigned char source_page_addr, unsigned long dest_block_addr,
  83. unsigned char dest_page_addr, unsigned char *data_buf);
  84. int ms_read_block(MS_MSPRO_Card_Info_t *ms_mspro_info, unsigned long block_addr, unsigned char page_addr,
  85. unsigned short page_nums, unsigned char *data_buf);
  86. int ms_write_block(MS_MSPRO_Card_Info_t *ms_mspro_info, unsigned long block_addr, unsigned char page_addr,
  87. unsigned short page_nums, unsigned char *data_buf);
  88. int ms_erase_block(MS_MSPRO_Card_Info_t *ms_mspro_info, unsigned long block_addr);
  89. int ms_read_extra_data(MS_MSPRO_Card_Info_t *ms_mspro_info, unsigned long block_addr, unsigned char page_addr);
  90. int ms_write_extra_data(MS_MSPRO_Card_Info_t *ms_mspro_info, unsigned long block_addr, unsigned char page_addr);
  91. int ms_overwrite_extra_data(MS_MSPRO_Card_Info_t *ms_mspro_info, unsigned long block_addr, unsigned char page_addr,
  92. unsigned char mask_data);
  93. int ms_sleep(void);
  94. int ms_clear_buffer(void);
  95. int ms_flash_stop(void);
  96. int ms_reset(MS_MSPRO_Card_Info_t *ms_mspro_info);
  97. /***************************************************************/
  98. int mspro_media_type_identification(MS_MSPRO_Card_Info_t *ms_mspro_info);
  99. int mspro_cpu_startup(MS_MSPRO_Card_Info_t *ms_mspro_info);
  100. int mspro_confirm_attribute_information(MS_MSPRO_Card_Info_t *ms_mspro_info, unsigned char *data_buf);
  101. int mspro_confirm_system_information(MS_MSPRO_Card_Info_t *ms_mspro_info, unsigned char *data_buf);
  102. int mspro_recognize_file_system(void);
  103. int mspro_read_user_sector(MS_MSPRO_Card_Info_t *ms_mspro_info, unsigned long sector_addr,
  104. unsigned short sector_count,
  105. unsigned char *data_buf);
  106. int mspro_write_user_sector(MS_MSPRO_Card_Info_t *ms_mspro_info, unsigned long sector_addr,
  107. unsigned short sector_count,
  108. unsigned char *data_buf);
  109. int mspro_erase_user_sector(MS_MSPRO_Card_Info_t *ms_mspro_info, unsigned long sector_addr,
  110. unsigned short sector_count);
  111. int mspro_read_attribute_sector(MS_MSPRO_Card_Info_t *ms_mspro_info, unsigned long sector_addr,
  112. unsigned short sector_count,
  113. unsigned char *data_buf);
  114. int mspro_read_information_block(void);
  115. int mspro_update_imformation_block(void);
  116. int mspro_format(void);
  117. int mspro_sleep(void);
  118. /**************************************************************/
  119. //Following functions only used in ms_protocol.c and mspro_protocol.c
  120. int ms_mspro_wait_int(MS_MSPRO_Card_Info_t *ms_mspro_info, MS_MSPRO_TPC_Packet_t * tpc_packet);
  121. int ms_mspro_wait_rdy(MS_MSPRO_Card_Info_t *ms_mspro_info, MS_MSPRO_TPC_Packet_t * tpc_packet);
  122. int ms_mspro_write_tpc(MS_MSPRO_Card_Info_t *ms_mspro_info, MS_MSPRO_TPC_Packet_t * tpc_packet);
  123. int ms_mspro_read_data_line(MS_MSPRO_Card_Info_t *ms_mspro_info, MS_MSPRO_TPC_Packet_t * tpc_packet);
  124. int ms_mspro_write_data_line(MS_MSPRO_Card_Info_t *ms_mspro_info, MS_MSPRO_TPC_Packet_t * tpc_packet);
  125. int ms_mspro_packet_communicate(MS_MSPRO_Card_Info_t *ms_mspro_info, MS_MSPRO_TPC_Packet_t * tpc_packet);
  126. char *ms_mspro_error_to_string(int errcode);
  127. void ms_mspro_endian_convert(Endian_Type_t data_type, void *data);
  128. //Following functions are the API used for outside routinue
  129. //void ms_mspro_get_info(blkdev_stat_t *info);
  130. int ms_mspro_init(MS_MSPRO_Card_Info_t * card_info);
  131. void ms_mspro_exit(MS_MSPRO_Card_Info_t *ms_mspro_info);
  132. void ms_mspro_prepare_init(MS_MSPRO_Card_Info_t *ms_mspro_info);
  133. int ms_mspro_check_insert(MS_MSPRO_Card_Info_t *ms_mspro_info);
  134. int ms_mspro_read_data(MS_MSPRO_Card_Info_t *ms_mspro_info, unsigned long lba, unsigned long byte_cnt,
  135. unsigned char *data_buf);
  136. int ms_mspro_write_data(MS_MSPRO_Card_Info_t *ms_mspro_info, unsigned long lba, unsigned long byte_cnt,
  137. unsigned char *data_buf);
  138. void ms_mspro_power_on(MS_MSPRO_Card_Info_t *ms_mspro_info);
  139. void ms_mspro_power_off(MS_MSPRO_Card_Info_t *ms_mspro_info);
  140. #endif //_H_MS_MISC