1 // SPDX-License-Identifier: GPL-2.0
3 * Atmel AT93C46 serial eeprom driver
5 * Brian Murphy <brian.murphy@eicon.com>
8 #include <linux/kernel.h>
9 #include <linux/delay.h>
10 #include <asm/lasat/lasat.h>
14 #define AT93C_ADDR_SHIFT 7
15 #define AT93C_ADDR_MAX ((1 << AT93C_ADDR_SHIFT) - 1)
16 #define AT93C_RCMD (0x6 << AT93C_ADDR_SHIFT)
17 #define AT93C_WCMD (0x5 << AT93C_ADDR_SHIFT)
18 #define AT93C_WENCMD 0x260
19 #define AT93C_WDSCMD 0x200
21 struct at93c_defs
*at93c
;
23 static void at93c_reg_write(u32 val
)
28 static u32
at93c_reg_read(void)
30 u32 tmp
= *at93c
->reg
;
34 static u32
at93c_datareg_read(void)
36 u32 tmp
= *at93c
->rdata_reg
;
40 static void at93c_cycle_clk(u32 data
)
42 at93c_reg_write(data
| at93c
->clk
);
44 at93c_reg_write(data
& ~at93c
->clk
);
48 static void at93c_write_databit(u8 bit
)
50 u32 data
= at93c_reg_read();
52 data
|= 1 << at93c
->wdata_shift
;
54 data
&= ~(1 << at93c
->wdata_shift
);
56 at93c_reg_write(data
);
58 at93c_cycle_clk(data
);
61 static unsigned int at93c_read_databit(void)
65 at93c_cycle_clk(at93c_reg_read());
66 data
= (at93c_datareg_read() >> at93c
->rdata_shift
) & 1;
70 static u8
at93c_read_byte(void)
75 for (i
= 0; i
<= 7; i
++) {
77 data
|= at93c_read_databit();
82 static void at93c_write_bits(u32 data
, int size
)
86 u32 mask
= (1 << shift
);
88 for (i
= 0; i
< size
; i
++) {
89 at93c_write_databit((data
& mask
) >> shift
);
94 static void at93c_init_op(void)
96 at93c_reg_write((at93c_reg_read() | at93c
->cs
) &
97 ~at93c
->clk
& ~(1 << at93c
->rdata_shift
));
101 static void at93c_end_op(void)
103 at93c_reg_write(at93c_reg_read() & ~at93c
->cs
);
107 static void at93c_wait(void)
110 while (!at93c_read_databit())
115 static void at93c_disable_wp(void)
118 at93c_write_bits(AT93C_WENCMD
, 10);
122 static void at93c_enable_wp(void)
125 at93c_write_bits(AT93C_WDSCMD
, 10);
129 u8
at93c_read(u8 addr
)
133 at93c_write_bits((addr
& AT93C_ADDR_MAX
)|AT93C_RCMD
, 10);
134 byte
= at93c_read_byte();
139 void at93c_write(u8 addr
, u8 data
)
143 at93c_write_bits((addr
& AT93C_ADDR_MAX
)|AT93C_WCMD
, 10);
144 at93c_write_bits(data
, 8);