]> rtime.felk.cvut.cz Git - l4.git/blob - l4/pkg/drivers-frst/nand/src/mpc5121.h
update
[l4.git] / l4 / pkg / drivers-frst / nand / src / mpc5121.h
1 #pragma once
2
3 #include "nand.h"
4
5 class Mpc5121 : public Nand_ctrl 
6 {
7   enum
8     { Max_cs = 4, };
9   enum
10     { Max_us_reset = 100, };
11   enum
12     { Spare_section_len = 64, };
13
14   struct Reg
15     {
16       u16 _res1[2];
17       u16 ram_buffer_addr;
18       u16 nand_flash_addr;
19       u16 nand_flash_cmd;
20       u16 nfc_configuration;
21       u16 ecc_status_result1;
22       u16 ecc_status_result2;
23       u16 spas;
24       u16 nf_wr_prot;
25       u16 _res2[2];
26       u16 nand_flash_wr_pr_st;
27       u16 nand_flash_config1;
28       u16 nand_flash_config2;
29       u16 _res3;
30       u16 unlock_start_blk_add0;
31       u16 unlock_end_blk_add0;
32       u16 unlock_start_blk_add1;
33       u16 unlock_end_blk_add1;
34       u16 unlock_start_blk_add2;
35       u16 unlock_end_blk_add2;
36       u16 unlock_start_blk_add3;
37       u16 unlock_end_blk_add3;
38     };
39
40 public:
41   Mpc5121(addr base_addr);
42   
43 protected:
44   void add(Nand_chip *chip);
45   Nand_chip *select(loff_t addr);
46   
47   void wr_cmd(u8 c);
48   void wr_adr(u8 a);
49   void wr_dat(u8 d);
50   u8 rd_dat();
51   void rd_dat(const u8 *buf, unsigned len);
52   void wr_dat(const u8 *buf, unsigned len);
53   
54   int handle_irq();
55
56   int get_id(char id[4]);
57  
58 private:
59   void _get_status();
60   void _start_read();
61   void _start_write();
62
63   void _enable_irq();
64
65   void _copy_from_data(u8 *buf, int len);
66   void _copy_to_data(const u8 *buf, int len);
67   void _copy_from_spare(u8 *buf, int len);
68   void _copy_to_spare(const u8 *buf, int len);
69
70   volatile Reg *_reg;
71   Nand_chip *_chips[Max_cs];
72   
73   volatile u32 *_buffer_main;
74   u32 *_buffer_spare;
75   u32 _buffer_ptr;
76 };