|
1 | 1 | /* |
2 | | - * Copyright (c) 2016 Intel Corporation. |
| 2 | + * @file spi_flash_w25qxxxx.c |
| 3 | + * |
| 4 | + * @brief Driver implementation for Winbond W25Q series Flash devices. |
| 5 | + * |
| 6 | + * @copyright Apache License 2.0 |
| 7 | + * @copyright (c) 2016 Intel Corporation. |
| 8 | + * @copyright (c) 2018 blik GmbH |
| 9 | + * |
| 10 | + * @author Alexander Preißner <[email protected]> |
3 | 11 | * |
4 | 12 | * SPDX-License-Identifier: Apache-2.0 |
5 | 13 | */ |
|
14 | 22 | #include "spi_flash_w25qxxxx.h" |
15 | 23 | #include "flash_priv.h" |
16 | 24 |
|
| 25 | + |
| 26 | +/** |
| 27 | + * @brief Flash Pages Layout Table Entry |
| 28 | + * |
| 29 | + * In the W25QXXXX Flash devices the minimum erasable unit is one sector, which |
| 30 | + * is 16 W25QXXXX pages (term according to datasheet). |
| 31 | + * A W25QXXXX page is 256 bytes in size. |
| 32 | + * The number of Zephyr pages can be calculated by dividing the size of the |
| 33 | + * entire Flash (in bytes) by the erasable sector size (in bytes). |
| 34 | + */ |
| 35 | +static const struct flash_pages_layout flash_w25qxxxx_pages_layout = { |
| 36 | + .pages_count = CONFIG_SPI_FLASH_W25QXXXX_FLASH_SIZE / W25QXXXX_SECTOR_SIZE, |
| 37 | + .pages_size = W25QXXXX_SECTOR_SIZE, |
| 38 | +}; |
| 39 | + |
| 40 | + |
17 | 41 | static inline int spi_flash_wb_id(struct device *dev) |
18 | 42 | { |
19 | 43 | struct spi_flash_data *const driver_data = dev->driver_data; |
@@ -340,14 +364,36 @@ static int spi_flash_wb_erase(struct device *dev, off_t offset, size_t size) |
340 | 364 | return ret; |
341 | 365 | } |
342 | 366 |
|
| 367 | +/** |
| 368 | + * @brief Creates Flash Pages Layout Table |
| 369 | + * |
| 370 | + * The Flash Pages Layout Table describes the layout of erasable pages within |
| 371 | + * a Flash device. |
| 372 | + * The information is used by file systems to determine formatting and when to |
| 373 | + * erase what. |
| 374 | + * |
| 375 | + * @param dev Flash device struct |
| 376 | + * @param layout Pointer to an array of #flash_pages_layout descriptor structs |
| 377 | + * @param layout_size Pointer to a variable holding the size of the Pages |
| 378 | + * Layout Table |
| 379 | + */ |
| 380 | +void spi_flash_wb_page_layout(struct device *dev, |
| 381 | + const struct flash_pages_layout **layout, |
| 382 | + size_t *layout_size) |
| 383 | +{ |
| 384 | + *layout = &flash_w25qxxxx_pages_layout; |
| 385 | + *layout_size = 1; |
| 386 | + |
| 387 | + return; |
| 388 | +} |
| 389 | + |
343 | 390 | static const struct flash_driver_api spi_flash_api = { |
344 | 391 | .read = spi_flash_wb_read, |
345 | 392 | .write = spi_flash_wb_write, |
346 | 393 | .erase = spi_flash_wb_erase, |
347 | 394 | .write_protection = spi_flash_wb_write_protection_set, |
348 | 395 | #if defined(CONFIG_FLASH_PAGE_LAYOUT) |
349 | | - .page_layout = (flash_api_pages_layout) |
350 | | - flash_page_layout_not_implemented, |
| 396 | + .page_layout = spi_flash_wb_page_layout, |
351 | 397 | #endif |
352 | 398 | .write_block_size = 1, |
353 | 399 | }; |
|
0 commit comments