1 /* SPDX-License-Identifier: GPL-2.0 */ 2 3 /* Copyright (c) 2018 Rockchip Electronics Co. Ltd. */ 4 5 #ifndef __RKFLASH_BLK_H 6 #define __RKFLASH_BLK_H 7 8 #include <linux/semaphore.h> 9 #include "rkflash_api.h" 10 11 /* RKFLASH Dev Patition Max Count */ 12 #define MAX_PART_COUNT 32 13 #define RK_PARTITION_TAG 0x50464B52 14 15 struct flash_part { 16 unsigned char name[32]; 17 unsigned int offset; 18 unsigned int size; 19 unsigned char type; 20 }; 21 22 struct flash_blk_ops { 23 char *name; 24 int major; 25 int minorbits; 26 int last_dev_index; 27 struct request_queue *rq; 28 spinlock_t queue_lock; /* queue lock */ 29 30 /* block-mq */ 31 struct list_head rq_list; 32 struct blk_mq_tag_set *tag_set; 33 34 struct list_head devs; 35 struct module *owner; 36 }; 37 38 struct flash_blk_dev { 39 struct flash_blk_ops *blk_ops; 40 struct list_head list; 41 int devnum; 42 unsigned int size; 43 unsigned int off_size; 44 int readonly; 45 int writeonly; 46 int disable_access; 47 void *blkcore_priv; 48 }; 49 50 enum ENUM_PARTITION_TYPE { 51 PART_VENDOR = 1 << 0, 52 PART_IDBLOCK = 1 << 1, 53 PART_KERNEL = 1 << 2, 54 PART_BOOT = 1 << 3, 55 PART_USER = 1 << 31 56 }; 57 58 struct STRUCT_DATETIME { 59 unsigned short year; 60 unsigned char month; 61 unsigned char day; 62 unsigned char hour; 63 unsigned char min; 64 unsigned char sec; 65 unsigned char reserve; 66 }; 67 68 struct STRUCT_FW_HEADER { 69 unsigned int ui_fw_tag; /* "RKFP" */ 70 struct STRUCT_DATETIME dt_release_data_time; 71 unsigned int ui_fw_ver; 72 unsigned int ui_size; /* size of sturct,unit of u8 */ 73 unsigned int ui_part_entry_offset; /* unit of sector */ 74 unsigned int ui_backup_part_entry_offset; 75 unsigned int ui_part_entry_size; /* unit of u8 */ 76 unsigned int ui_part_entry_count; 77 unsigned int ui_fw_size; /* unit of u8 */ 78 unsigned char reserved[464]; 79 unsigned int ui_part_entry_crc; 80 unsigned int ui_header_crc; 81 }; 82 83 struct STRUCT_PART_ENTRY { 84 unsigned char sz_name[32]; 85 enum ENUM_PARTITION_TYPE em_part_type; 86 unsigned int ui_pt_off; /* unit of sector */ 87 unsigned int ui_pt_sz; /* unit of sector */ 88 unsigned int ui_data_length; /* unit of u8 */ 89 unsigned int ui_part_property; 90 unsigned char reserved[76]; 91 }; 92 93 struct STRUCT_PART_INFO { 94 struct STRUCT_FW_HEADER hdr; /* 0.5KB */ 95 struct STRUCT_PART_ENTRY part[12]; /* 1.5KB */ 96 } __packed; 97 98 /* Including Dev APIs */ 99 #ifdef CONFIG_RK_SFC_NAND_MTD 100 int sfc_nand_mtd_init(struct SFNAND_DEV *p_dev, struct mutex *lock); 101 #endif 102 #ifdef CONFIG_RK_SFC_NOR_MTD 103 int sfc_nor_mtd_init(struct SFNOR_DEV *p_dev, struct mutex *lock); 104 #endif 105 106 int rkflash_dev_suspend(void); 107 int rkflash_dev_resume(void __iomem *reg_addr); 108 void rkflash_dev_shutdown(void); 109 void rkflash_dev_flush(void); 110 int rkflash_dev_init(void __iomem *reg_addr, 111 enum flash_type type, 112 const struct flash_boot_ops *ops); 113 int rkflash_dev_exit(void); 114 int rkflash_vendor_read(u32 sec, u32 n_sec, void *p_data); 115 int rkflash_vendor_write(u32 sec, u32 n_sec, void *p_data); 116 117 #endif 118