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