Skip to content

Commit cac2ccd

Browse files
author
Alexander Preißner
committed
feat: Flash: adds W25Q page layout implementation
* This commit adds an implementation of the page_layout API call to the Winbond W25Q series driver. * Added data structure flash_w25qxxxx_pages_layout that describes the Flash chip's layout of erasable units. * Added function spi_flash_wb_page_layout that creates the Page Layout Table containing the above single page layout descriptor. * Updated the page_layout pointer in the driver API struct. * Added Doxygen-style documentation to all added code. * Closes zephyrproject-rtos#11
1 parent 3631e83 commit cac2ccd

File tree

1 file changed

+49
-3
lines changed

1 file changed

+49
-3
lines changed

drivers/flash/spi_flash_w25qxxxx.c

Lines changed: 49 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
/*
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]>
311
*
412
* SPDX-License-Identifier: Apache-2.0
513
*/
@@ -14,6 +22,22 @@
1422
#include "spi_flash_w25qxxxx.h"
1523
#include "flash_priv.h"
1624

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+
1741
static inline int spi_flash_wb_id(struct device *dev)
1842
{
1943
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)
340364
return ret;
341365
}
342366

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+
343390
static const struct flash_driver_api spi_flash_api = {
344391
.read = spi_flash_wb_read,
345392
.write = spi_flash_wb_write,
346393
.erase = spi_flash_wb_erase,
347394
.write_protection = spi_flash_wb_write_protection_set,
348395
#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,
351397
#endif
352398
.write_block_size = 1,
353399
};

0 commit comments

Comments
 (0)