31
31
*/
32
32
33
33
#define FM25_SN_LEN 8 /* serial number length */
34
+ #define EE_MAXADDRLEN 3 /* 24 bit addresses, up to 2 MBytes */
35
+
34
36
struct at25_data {
35
37
struct spi_eeprom chip ;
36
38
struct spi_device * spi ;
@@ -39,6 +41,7 @@ struct at25_data {
39
41
struct nvmem_config nvmem_config ;
40
42
struct nvmem_device * nvmem ;
41
43
u8 sernum [FM25_SN_LEN ];
44
+ u8 command [EE_MAXADDRLEN + 1 ];
42
45
};
43
46
44
47
#define AT25_WREN 0x06 /* latch the write enable */
@@ -61,8 +64,6 @@ struct at25_data {
61
64
62
65
#define FM25_ID_LEN 9 /* ID length */
63
66
64
- #define EE_MAXADDRLEN 3 /* 24 bit addresses, up to 2 MBytes */
65
-
66
67
/*
67
68
* Specs often allow 5ms for a page write, sometimes 20ms;
68
69
* it's important to recover from write timeouts.
@@ -78,7 +79,6 @@ static int at25_ee_read(void *priv, unsigned int offset,
78
79
{
79
80
struct at25_data * at25 = priv ;
80
81
char * buf = val ;
81
- u8 command [EE_MAXADDRLEN + 1 ];
82
82
u8 * cp ;
83
83
ssize_t status ;
84
84
struct spi_transfer t [2 ];
@@ -92,12 +92,15 @@ static int at25_ee_read(void *priv, unsigned int offset,
92
92
if (unlikely (!count ))
93
93
return - EINVAL ;
94
94
95
- cp = command ;
95
+ cp = at25 -> command ;
96
96
97
97
instr = AT25_READ ;
98
98
if (at25 -> chip .flags & EE_INSTR_BIT3_IS_ADDR )
99
99
if (offset >= BIT (at25 -> addrlen * 8 ))
100
100
instr |= AT25_INSTR_BIT3 ;
101
+
102
+ mutex_lock (& at25 -> lock );
103
+
101
104
* cp ++ = instr ;
102
105
103
106
/* 8/16/24-bit address is written MSB first */
@@ -116,16 +119,14 @@ static int at25_ee_read(void *priv, unsigned int offset,
116
119
spi_message_init (& m );
117
120
memset (t , 0 , sizeof (t ));
118
121
119
- t [0 ].tx_buf = command ;
122
+ t [0 ].tx_buf = at25 -> command ;
120
123
t [0 ].len = at25 -> addrlen + 1 ;
121
124
spi_message_add_tail (& t [0 ], & m );
122
125
123
126
t [1 ].rx_buf = buf ;
124
127
t [1 ].len = count ;
125
128
spi_message_add_tail (& t [1 ], & m );
126
129
127
- mutex_lock (& at25 -> lock );
128
-
129
130
/*
130
131
* Read it all at once.
131
132
*
@@ -152,7 +153,7 @@ static int fm25_aux_read(struct at25_data *at25, u8 *buf, uint8_t command,
152
153
spi_message_init (& m );
153
154
memset (t , 0 , sizeof (t ));
154
155
155
- t [0 ].tx_buf = & command ;
156
+ t [0 ].tx_buf = at25 -> command ;
156
157
t [0 ].len = 1 ;
157
158
spi_message_add_tail (& t [0 ], & m );
158
159
@@ -162,6 +163,8 @@ static int fm25_aux_read(struct at25_data *at25, u8 *buf, uint8_t command,
162
163
163
164
mutex_lock (& at25 -> lock );
164
165
166
+ at25 -> command [0 ] = command ;
167
+
165
168
status = spi_sync (at25 -> spi , & m );
166
169
dev_dbg (& at25 -> spi -> dev , "read %d aux bytes --> %d\n" , len , status );
167
170
0 commit comments