388 spi_message_add_tail(&t[0], &m);
389
390 t[1].tx_buf = buf;
391 spi_message_add_tail(&t[1], &m);
392
393 mutex_lock(&flash->lock);
394
395
396 if (wait_till_ready(flash)) {
397 mutex_unlock(&flash->lock);
398 return 1;
399 }
400
401 write_enable(flash);
402
403
404 flash->command[0] = OPCODE_PP;
405 flash->command[1] = to >> 16;
406 flash->command[2] = to >> 8;
407 flash->command[3] = to;
408
409
410 page_offset = to % FLASH_PAGESIZE;
411
412
413 if (page_offset + len <= FLASH_PAGESIZE) {
414 t[1].len = len;
415
416 spi_sync(flash->spi, &m);
417
418 *retlen = m.actual_length - CMD_SIZE;
419 } else {
420 u32 i;
421
422
423 page_size = FLASH_PAGESIZE - page_offset;
424
425 t[1].len = page_size;
426 spi_sync(flash->spi, &m);
427
428 *retlen = m.actual_length - CMD_SIZE;