diff options
Diffstat (limited to 'drivers/mtd/devices/m25p80.c')
-rw-r--r-- | drivers/mtd/devices/m25p80.c | 50 |
1 files changed, 25 insertions, 25 deletions
diff --git a/drivers/mtd/devices/m25p80.c b/drivers/mtd/devices/m25p80.c index 71a072103a7f..45108ed85588 100644 --- a/drivers/mtd/devices/m25p80.c +++ b/drivers/mtd/devices/m25p80.c | |||
@@ -245,6 +245,21 @@ static int m25p80_read(struct mtd_info *mtd, loff_t from, size_t len, | |||
245 | if (from + len > flash->mtd.size) | 245 | if (from + len > flash->mtd.size) |
246 | return -EINVAL; | 246 | return -EINVAL; |
247 | 247 | ||
248 | spi_message_init(&m); | ||
249 | memset(t, 0, (sizeof t)); | ||
250 | |||
251 | t[0].tx_buf = flash->command; | ||
252 | t[0].len = sizeof(flash->command); | ||
253 | spi_message_add_tail(&t[0], &m); | ||
254 | |||
255 | t[1].rx_buf = buf; | ||
256 | t[1].len = len; | ||
257 | spi_message_add_tail(&t[1], &m); | ||
258 | |||
259 | /* Byte count starts at zero. */ | ||
260 | if (retlen) | ||
261 | *retlen = 0; | ||
262 | |||
248 | down(&flash->lock); | 263 | down(&flash->lock); |
249 | 264 | ||
250 | /* Wait till previous write/erase is done. */ | 265 | /* Wait till previous write/erase is done. */ |
@@ -254,8 +269,6 @@ static int m25p80_read(struct mtd_info *mtd, loff_t from, size_t len, | |||
254 | return 1; | 269 | return 1; |
255 | } | 270 | } |
256 | 271 | ||
257 | memset(t, 0, (sizeof t)); | ||
258 | |||
259 | /* NOTE: OPCODE_FAST_READ (if available) is faster... */ | 272 | /* NOTE: OPCODE_FAST_READ (if available) is faster... */ |
260 | 273 | ||
261 | /* Set up the write data buffer. */ | 274 | /* Set up the write data buffer. */ |
@@ -264,19 +277,6 @@ static int m25p80_read(struct mtd_info *mtd, loff_t from, size_t len, | |||
264 | flash->command[2] = from >> 8; | 277 | flash->command[2] = from >> 8; |
265 | flash->command[3] = from; | 278 | flash->command[3] = from; |
266 | 279 | ||
267 | /* Byte count starts at zero. */ | ||
268 | if (retlen) | ||
269 | *retlen = 0; | ||
270 | |||
271 | t[0].tx_buf = flash->command; | ||
272 | t[0].len = sizeof(flash->command); | ||
273 | |||
274 | t[1].rx_buf = buf; | ||
275 | t[1].len = len; | ||
276 | |||
277 | m.transfers = t; | ||
278 | m.n_transfer = 2; | ||
279 | |||
280 | spi_sync(flash->spi, &m); | 280 | spi_sync(flash->spi, &m); |
281 | 281 | ||
282 | *retlen = m.actual_length - sizeof(flash->command); | 282 | *retlen = m.actual_length - sizeof(flash->command); |
@@ -313,6 +313,16 @@ static int m25p80_write(struct mtd_info *mtd, loff_t to, size_t len, | |||
313 | if (to + len > flash->mtd.size) | 313 | if (to + len > flash->mtd.size) |
314 | return -EINVAL; | 314 | return -EINVAL; |
315 | 315 | ||
316 | spi_message_init(&m); | ||
317 | memset(t, 0, (sizeof t)); | ||
318 | |||
319 | t[0].tx_buf = flash->command; | ||
320 | t[0].len = sizeof(flash->command); | ||
321 | spi_message_add_tail(&t[0], &m); | ||
322 | |||
323 | t[1].tx_buf = buf; | ||
324 | spi_message_add_tail(&t[1], &m); | ||
325 | |||
316 | down(&flash->lock); | 326 | down(&flash->lock); |
317 | 327 | ||
318 | /* Wait until finished previous write command. */ | 328 | /* Wait until finished previous write command. */ |
@@ -321,26 +331,17 @@ static int m25p80_write(struct mtd_info *mtd, loff_t to, size_t len, | |||
321 | 331 | ||
322 | write_enable(flash); | 332 | write_enable(flash); |
323 | 333 | ||
324 | memset(t, 0, (sizeof t)); | ||
325 | |||
326 | /* Set up the opcode in the write buffer. */ | 334 | /* Set up the opcode in the write buffer. */ |
327 | flash->command[0] = OPCODE_PP; | 335 | flash->command[0] = OPCODE_PP; |
328 | flash->command[1] = to >> 16; | 336 | flash->command[1] = to >> 16; |
329 | flash->command[2] = to >> 8; | 337 | flash->command[2] = to >> 8; |
330 | flash->command[3] = to; | 338 | flash->command[3] = to; |
331 | 339 | ||
332 | t[0].tx_buf = flash->command; | ||
333 | t[0].len = sizeof(flash->command); | ||
334 | |||
335 | m.transfers = t; | ||
336 | m.n_transfer = 2; | ||
337 | |||
338 | /* what page do we start with? */ | 340 | /* what page do we start with? */ |
339 | page_offset = to % FLASH_PAGESIZE; | 341 | page_offset = to % FLASH_PAGESIZE; |
340 | 342 | ||
341 | /* do all the bytes fit onto one page? */ | 343 | /* do all the bytes fit onto one page? */ |
342 | if (page_offset + len <= FLASH_PAGESIZE) { | 344 | if (page_offset + len <= FLASH_PAGESIZE) { |
343 | t[1].tx_buf = buf; | ||
344 | t[1].len = len; | 345 | t[1].len = len; |
345 | 346 | ||
346 | spi_sync(flash->spi, &m); | 347 | spi_sync(flash->spi, &m); |
@@ -352,7 +353,6 @@ static int m25p80_write(struct mtd_info *mtd, loff_t to, size_t len, | |||
352 | /* the size of data remaining on the first page */ | 353 | /* the size of data remaining on the first page */ |
353 | page_size = FLASH_PAGESIZE - page_offset; | 354 | page_size = FLASH_PAGESIZE - page_offset; |
354 | 355 | ||
355 | t[1].tx_buf = buf; | ||
356 | t[1].len = page_size; | 356 | t[1].len = page_size; |
357 | spi_sync(flash->spi, &m); | 357 | spi_sync(flash->spi, &m); |
358 | 358 | ||