Lines Matching refs:flash

49  * This file provides bootbus flash operations
60 #include "cvmx-flash.h"
62 #define MAX_NUM_FLASH_CHIPS 8 /* Maximum number of flash chips */
77 void * base_ptr; /**< Memory pointer to start of flash */
93 * Read a byte from flash
107 * Read a byte from flash (for commands)
123 * Read 16bits from flash (for commands)
139 * Write a byte to flash
154 * Write a byte to flash (for commands)
169 * Query a address and see if a CFI flash chip is there.
178 cvmx_flash_t *flash = flash_info + chip_id;
181 flash->base_ptr = base_ptr;
182 flash->is_16bit = 1; /* FIXME: Currently assumes the chip is 16bits */
184 /* Put flash in CFI query mode */
185 __cvmx_flash_write_cmd(chip_id, 0x00, 0xf0); /* Reset the flash chip */
193 flash->base_ptr = NULL;
198 flash->vendor = __cvmx_flash_read_cmd16(chip_id, 0x13);
202 flash->write_timeout = 1ull << (__cvmx_flash_read_cmd(chip_id, 0x1f) +
207 flash->erase_timeout = 1ull << (__cvmx_flash_read_cmd(chip_id, 0x21) +
210 /* Get the flash size. This is 2^0x27 */
211 flash->size = 1<<__cvmx_flash_read_cmd(chip_id, 0x27);
214 flash->num_regions = __cvmx_flash_read_cmd(chip_id, 0x2c);
218 for (region=0; region<flash->num_regions; region++)
220 cvmx_flash_region_t *rgn_ptr = flash->region + region;
252 flash->write_timeout *= cvmx_clock_get_rate(CVMX_CLOCK_CORE) / 1000000;
253 flash->erase_timeout *= cvmx_clock_get_rate(CVMX_CLOCK_CORE) / 1000;
257 cvmx_dprintf("cvmx-flash: Base pointer: %p\n"
263 flash->base_ptr,
264 (unsigned int)flash->vendor,
265 flash->size,
266 flash->num_regions,
267 (unsigned long long)flash->erase_timeout,
268 (unsigned long long)flash->write_timeout);
270 for (region=0; region<flash->num_regions; region++)
274 flash->region[region].start_offset,
275 flash->region[region].num_blocks,
276 flash->region[region].block_size);
285 * Initialize the flash access library
300 bootloader already setup the flash */
308 /* Valid CFI flash chip found */
315 cvmx_dprintf("cvmx-flash: No CFI chips found\n");
320 * Return a pointer to the flash chip
344 * Return information about a flash chips region
357 * Erase a block on the flash chip
368 cvmx_dprintf("cvmx-flash: Erasing chip %d, region %d, block %d\n",
380 __cvmx_flash_write_cmd(chip_id, 0x00, 0xf0); /* Reset the flash chip */
413 cvmx_dprintf("cvmx-flash: Hardware timeout erasing block\n");
426 cvmx_dprintf("cvmx-flash: Timeout erasing block\n");
432 __cvmx_flash_write_cmd(chip_id, 0x00, 0xf0); /* Reset the flash chip */
440 __cvmx_flash_write_cmd(chip_id, 0x00, 0xff); /* Reset the flash chip */
451 cvmx_dprintf("cvmx-flash: Timeout erasing block\n");
461 cvmx_dprintf("cvmx-flash: Hardware failure erasing block\n");
466 __cvmx_flash_write_cmd(chip_id, 0x00, 0xff); /* Reset the flash chip */
472 cvmx_dprintf("cvmx-flash: Unsupported flash vendor\n");
479 * Write a block on the flash chip
491 cvmx_dprintf("cvmx-flash: Writing chip %d, region %d, block %d\n",
507 __cvmx_flash_write_cmd(chip_id, 0x00, 0xf0); /* Reset the flash chip */
528 cvmx_dprintf("cvmx-flash: Hardware write timeout\n");
536 cvmx_dprintf("cvmx-flash: Timeout writing block\n");
547 __cvmx_flash_write_cmd(chip_id, 0x00, 0xf0); /* Reset the flash chip */
559 __cvmx_flash_write_cmd(chip_id, 0x00, 0xff); /* Reset the flash chip */
570 cvmx_dprintf("cvmx-flash: Timeout writing block\n");
580 cvmx_dprintf("cvmx-flash: Hardware failure erasing block\n");
591 __cvmx_flash_write_cmd(chip_id, 0x00, 0xff); /* Reset the flash chip */
597 cvmx_dprintf("cvmx-flash: Unsupported flash vendor\n");
604 * Erase and write data to a flash
626 cvmx_dprintf("cvmx-flash: Unable to find chip that contains address %p\n", address);
630 cvmx_flash_t *flash = flash_info + chip_id;
633 void *region_base = flash->base_ptr;
635 while (region_base + flash->region[region].num_blocks * flash->region[region].block_size <= address)
638 region_base = flash->base_ptr + flash->region[region].start_offset;
642 int block = (address - region_base) / flash->region[region].block_size;
645 if (address != region_base + block*flash->region[region].block_size)
647 cvmx_dprintf("cvmx-flash: Write address not aligned on a block boundry\n");
662 data += flash->region[region].block_size;
663 len -= flash->region[region].block_size;
665 if (block >= flash->region[region].num_blocks)