Initial import of OsmocomBB into git repository
[osmocom-bb.git] / src / target / firmware / include / cfi_flash.h
1
2 #ifndef _CFI_FLASH_H
3 #define _CFI_FLASH_H
4
5 #include <stdint.h>
6
7
8 #define CFI_FLASH_MAX_ERASE_REGIONS 4
9
10 /* structure of erase region descriptor */
11 struct cfi_region {
12         uint16_t b_count;
13         uint16_t b_size;
14 } __attribute__((packed));
15
16
17 /* structure of cfi query response */
18 struct cfi_query {
19         uint8_t qry[3];
20         uint16_t        p_id;
21         uint16_t        p_adr;
22         uint16_t        a_id;
23         uint16_t        a_adr;
24         uint8_t vcc_min;
25         uint8_t vcc_max;
26         uint8_t vpp_min;
27         uint8_t vpp_max;
28         uint8_t word_write_timeout_typ;
29         uint8_t buf_write_timeout_typ;
30         uint8_t block_erase_timeout_typ;
31         uint8_t chip_erase_timeout_typ;
32         uint8_t word_write_timeout_max;
33         uint8_t buf_write_timeout_max;
34         uint8_t block_erase_timeout_max;
35         uint8_t chip_erase_timeout_max;
36         uint8_t dev_size;
37         uint16_t        interface_desc;
38         uint16_t        max_buf_write_size;
39         uint8_t num_erase_regions;
40         struct cfi_region  erase_regions[CFI_FLASH_MAX_ERASE_REGIONS];
41 } __attribute__((packed));
42
43 typedef struct {
44         void *f_base;
45
46         uint32_t f_size;
47
48         uint16_t f_manuf_id;
49         uint16_t f_dev_id;
50
51         struct cfi_query f_query;
52 } cfi_flash_t;
53
54 typedef uint8_t flash_lock;
55
56 void flash_init(cfi_flash_t *flash, void *base_addr);
57
58 void flash_dump_info(cfi_flash_t *flash);
59
60 flash_lock flash_block_getlock(cfi_flash_t *base_addr, uint32_t block_offset);
61
62 void flash_block_unlock(cfi_flash_t *base_addr, uint32_t block_offset);
63 void flash_block_lock(cfi_flash_t *base_addr, uint32_t block_offset);
64 void flash_block_lockdown(cfi_flash_t *base_addr, uint32_t block_offset);
65
66 void flash_block_erase(cfi_flash_t *base_addr, uint32_t block_addr);
67
68 #endif