Line data Source code
1 1 : /*
2 : * Copyright (c) 2017-2024 Nordic Semiconductor ASA
3 : * Copyright (c) 2016 Intel Corporation
4 : *
5 : * SPDX-License-Identifier: Apache-2.0
6 : */
7 :
8 : /**
9 : * @file
10 : * @brief Public API for FLASH drivers
11 : */
12 :
13 : #ifndef ZEPHYR_INCLUDE_DRIVERS_FLASH_H_
14 : #define ZEPHYR_INCLUDE_DRIVERS_FLASH_H_
15 :
16 : /**
17 : * @brief FLASH internal Interface
18 : * @defgroup flash_internal_interface FLASH internal Interface
19 : * @ingroup io_interfaces
20 : * @{
21 : */
22 :
23 : #include <errno.h>
24 :
25 : #include <zephyr/types.h>
26 : #include <stddef.h>
27 : #include <sys/types.h>
28 : #include <zephyr/device.h>
29 :
30 : #ifdef __cplusplus
31 : extern "C" {
32 : #endif
33 :
34 : #if defined(CONFIG_FLASH_PAGE_LAYOUT)
35 0 : struct flash_pages_layout {
36 0 : size_t pages_count; /* count of pages sequence of the same size */
37 0 : size_t pages_size;
38 : };
39 : #endif /* CONFIG_FLASH_PAGE_LAYOUT */
40 :
41 : /**
42 : * @}
43 : */
44 :
45 : /**
46 : * @brief FLASH Interface
47 : * @defgroup flash_interface FLASH Interface
48 : * @since 1.2
49 : * @version 1.0.0
50 : * @ingroup io_interfaces
51 : * @{
52 : */
53 :
54 : /**
55 : * Flash memory parameters. Contents of this structure suppose to be
56 : * filled in during flash device initialization and stay constant
57 : * through a runtime.
58 : */
59 1 : struct flash_parameters {
60 : /** Minimal write alignment and size */
61 1 : const size_t write_block_size;
62 :
63 : /** @cond INTERNAL_HIDDEN */
64 : /* User code should call flash_params_get_ functions on flash_parameters
65 : * to get capabilities, rather than accessing object contents directly.
66 : */
67 : struct {
68 : /* Device has no explicit erase, so it either erases on
69 : * write or does not require it at all.
70 : * This also includes devices that support erase but
71 : * do not require it.
72 : */
73 : bool no_explicit_erase: 1;
74 : } caps;
75 : /** @endcond */
76 : /** Value the device is filled in erased areas */
77 1 : uint8_t erase_value;
78 : };
79 :
80 : /** Set for ordinary Flash where erase is needed before write of random data */
81 1 : #define FLASH_ERASE_C_EXPLICIT 0x01
82 : /** Reserved for users as initializer for variables that will later store
83 : * capabilities.
84 : */
85 1 : #define FLASH_ERASE_CAPS_UNSET (int)-1
86 : /* The values below are now reserved but not used */
87 0 : #define FLASH_ERASE_C_SUPPORTED 0x02
88 0 : #define FLASH_ERASE_C_VAL_BIT 0x04
89 0 : #define FLASH_ERASE_UNIFORM_PAGE 0x08
90 :
91 :
92 : /* @brief Parser for flash_parameters for retrieving erase capabilities
93 : *
94 : * The functions parses flash_parameters type object and returns combination
95 : * of erase capabilities of 0 if device does not have any.
96 : * Not that in some cases availability of erase may be dependent on driver
97 : * options, so even if by hardware design a device provides some erase
98 : * capabilities, the function may return 0 if these been disabled or not
99 : * implemented by driver.
100 : *
101 : * @param p pointer to flash_parameters type object
102 : *
103 : * @return 0 or combination of FLASH_ERASE_C_ capabilities.
104 : */
105 : static inline
106 0 : int flash_params_get_erase_cap(const struct flash_parameters *p)
107 : {
108 : #if defined(CONFIG_FLASH_HAS_EXPLICIT_ERASE)
109 : #if defined(CONFIG_FLASH_HAS_NO_EXPLICIT_ERASE)
110 : return (p->caps.no_explicit_erase) ? 0 : FLASH_ERASE_C_EXPLICIT;
111 : #else
112 : ARG_UNUSED(p);
113 : return FLASH_ERASE_C_EXPLICIT;
114 : #endif
115 : #endif
116 : return 0;
117 : }
118 :
119 : /**
120 : * @}
121 : */
122 :
123 : /**
124 : * @addtogroup flash_internal_interface
125 : * @{
126 : */
127 :
128 0 : typedef int (*flash_api_read)(const struct device *dev, off_t offset,
129 : void *data,
130 : size_t len);
131 : /**
132 : * @brief Flash write implementation handler type
133 : *
134 : * @note Any necessary write protection management must be performed by
135 : * the driver, with the driver responsible for ensuring the "write-protect"
136 : * after the operation completes (successfully or not) matches the write-protect
137 : * state when the operation was started.
138 : */
139 1 : typedef int (*flash_api_write)(const struct device *dev, off_t offset,
140 : const void *data, size_t len);
141 :
142 : /**
143 : * @brief Flash erase implementation handler type
144 : *
145 : * @note Any necessary erase protection management must be performed by
146 : * the driver, with the driver responsible for ensuring the "erase-protect"
147 : * after the operation completes (successfully or not) matches the erase-protect
148 : * state when the operation was started.
149 : *
150 : * The callback is optional for RAM non-volatile devices, which do not
151 : * require erase by design, but may be provided if it allows device to
152 : * work more effectively, or if device has a support for internal fill
153 : * operation the erase in driver uses.
154 : */
155 1 : typedef int (*flash_api_erase)(const struct device *dev, off_t offset,
156 : size_t size);
157 :
158 : /**
159 : * @brief Get device size in bytes.
160 : *
161 : * Returns total logical device size in bytes.
162 : *
163 : * @param[in] dev flash device.
164 : * @param[out] size device size in bytes.
165 : *
166 : * @return 0 on success, negative errno code on error.
167 : */
168 0 : typedef int (*flash_api_get_size)(const struct device *dev, uint64_t *size);
169 :
170 : typedef const struct flash_parameters* (*flash_api_get_parameters)(const struct device *dev);
171 :
172 : #if defined(CONFIG_FLASH_PAGE_LAYOUT)
173 : /**
174 : * @brief Retrieve a flash device's layout.
175 : *
176 : * A flash device layout is a run-length encoded description of the
177 : * pages on the device. (Here, "page" means the smallest erasable
178 : * area on the flash device.)
179 : *
180 : * For flash memories which have uniform page sizes, this routine
181 : * returns an array of length 1, which specifies the page size and
182 : * number of pages in the memory.
183 : *
184 : * Layouts for flash memories with nonuniform page sizes will be
185 : * returned as an array with multiple elements, each of which
186 : * describes a group of pages that all have the same size. In this
187 : * case, the sequence of array elements specifies the order in which
188 : * these groups occur on the device.
189 : *
190 : * @param dev Flash device whose layout to retrieve.
191 : * @param layout The flash layout will be returned in this argument.
192 : * @param layout_size The number of elements in the returned layout.
193 : */
194 1 : typedef void (*flash_api_pages_layout)(const struct device *dev,
195 : const struct flash_pages_layout **layout,
196 : size_t *layout_size);
197 : #endif /* CONFIG_FLASH_PAGE_LAYOUT */
198 :
199 0 : typedef int (*flash_api_sfdp_read)(const struct device *dev, off_t offset,
200 : void *data, size_t len);
201 0 : typedef int (*flash_api_read_jedec_id)(const struct device *dev, uint8_t *id);
202 0 : typedef int (*flash_api_ex_op)(const struct device *dev, uint16_t code,
203 : const uintptr_t in, void *out);
204 :
205 0 : __subsystem struct flash_driver_api {
206 0 : flash_api_read read;
207 0 : flash_api_write write;
208 0 : flash_api_erase erase;
209 0 : flash_api_get_parameters get_parameters;
210 0 : flash_api_get_size get_size;
211 : #if defined(CONFIG_FLASH_PAGE_LAYOUT)
212 0 : flash_api_pages_layout page_layout;
213 : #endif /* CONFIG_FLASH_PAGE_LAYOUT */
214 : #if defined(CONFIG_FLASH_JESD216_API)
215 0 : flash_api_sfdp_read sfdp_read;
216 0 : flash_api_read_jedec_id read_jedec_id;
217 : #endif /* CONFIG_FLASH_JESD216_API */
218 : #if defined(CONFIG_FLASH_EX_OP_ENABLED)
219 : flash_api_ex_op ex_op;
220 : #endif /* CONFIG_FLASH_EX_OP_ENABLED */
221 : };
222 :
223 : /**
224 : * @}
225 : */
226 :
227 : /**
228 : * @addtogroup flash_interface
229 : * @{
230 : */
231 :
232 : /**
233 : * @brief Read data from flash
234 : *
235 : * All flash drivers support reads without alignment restrictions on
236 : * the read offset, the read size, or the destination address.
237 : *
238 : * @param dev : flash dev
239 : * @param offset : Offset (byte aligned) to read
240 : * @param data : Buffer to store read data
241 : * @param len : Number of bytes to read.
242 : *
243 : * @return 0 on success, negative errno code on fail.
244 : */
245 1 : __syscall int flash_read(const struct device *dev, off_t offset, void *data,
246 : size_t len);
247 :
248 : static inline int z_impl_flash_read(const struct device *dev, off_t offset,
249 : void *data,
250 : size_t len)
251 : {
252 : const struct flash_driver_api *api =
253 : (const struct flash_driver_api *)dev->api;
254 :
255 : return api->read(dev, offset, data, len);
256 : }
257 :
258 : /**
259 : * @brief Write buffer into flash memory.
260 : *
261 : * All flash drivers support a source buffer located either in RAM or
262 : * SoC flash, without alignment restrictions on the source address.
263 : * Write size and offset must be multiples of the minimum write block size
264 : * supported by the driver.
265 : *
266 : * Any necessary write protection management is performed by the driver
267 : * write implementation itself.
268 : *
269 : * @param dev : flash device
270 : * @param offset : starting offset for the write
271 : * @param data : data to write
272 : * @param len : Number of bytes to write
273 : *
274 : * @return 0 on success, negative errno code on fail.
275 : */
276 1 : __syscall int flash_write(const struct device *dev, off_t offset,
277 : const void *data,
278 : size_t len);
279 :
280 : static inline int z_impl_flash_write(const struct device *dev, off_t offset,
281 : const void *data, size_t len)
282 : {
283 : const struct flash_driver_api *api =
284 : (const struct flash_driver_api *)dev->api;
285 : int rc;
286 :
287 : rc = api->write(dev, offset, data, len);
288 :
289 : return rc;
290 : }
291 :
292 : /**
293 : * @brief Erase part or all of a flash memory
294 : *
295 : * Acceptable values of erase size and offset are subject to
296 : * hardware-specific multiples of page size and offset. Please check
297 : * the API implemented by the underlying sub driver, for example by
298 : * using flash_get_page_info_by_offs() if that is supported by your
299 : * flash driver.
300 : *
301 : * Any necessary erase protection management is performed by the driver
302 : * erase implementation itself.
303 : *
304 : * The function should be used only for devices that are really
305 : * explicit erase devices; in case when code relies on erasing
306 : * device, i.e. setting it to erase-value, prior to some operations,
307 : * but should work with explicit erase and RAM non-volatile devices,
308 : * then flash_flatten should rather be used.
309 : *
310 : * @param dev : flash device
311 : * @param offset : erase area starting offset
312 : * @param size : size of area to be erased
313 : *
314 : * @return 0 on success, negative errno code on fail.
315 : *
316 : * @see flash_flatten()
317 : * @see flash_get_page_info_by_offs()
318 : * @see flash_get_page_info_by_idx()
319 : */
320 1 : __syscall int flash_erase(const struct device *dev, off_t offset, size_t size);
321 :
322 : static inline int z_impl_flash_erase(const struct device *dev, off_t offset,
323 : size_t size)
324 : {
325 : int rc = -ENOSYS;
326 :
327 : const struct flash_driver_api *api =
328 : (const struct flash_driver_api *)dev->api;
329 :
330 : if (api->erase != NULL) {
331 : rc = api->erase(dev, offset, size);
332 : }
333 :
334 : return rc;
335 : }
336 :
337 : /**
338 : * @brief Get device size in bytes.
339 : *
340 : * Returns total logical device size in bytes. Not all devices may support
341 : * returning size, specifically those with non uniform page layouts or banked,
342 : * in which case the function will return -ENOTSUP, and user has to rely
343 : * on Flash page layout functions enabled by CONFIG_FLASH_PAGE_LAYOUT.
344 : *
345 : * @param[in] dev flash device.
346 : * @param[out] size device size in bytes.
347 : *
348 : * @return 0 on success, negative errno code on error.
349 : */
350 1 : __syscall int flash_get_size(const struct device *dev, uint64_t *size);
351 :
352 : static inline int z_impl_flash_get_size(const struct device *dev, uint64_t *size)
353 : {
354 : int rc = -ENOSYS;
355 : const struct flash_driver_api *api = (const struct flash_driver_api *)dev->api;
356 :
357 : if (api->get_size != NULL) {
358 : rc = api->get_size(dev, size);
359 : }
360 :
361 : return rc;
362 : }
363 :
364 : /**
365 : * @brief Fill selected range of device with specified value
366 : *
367 : * Utility function that allows to fill specified range on a device with
368 : * provided value. The @p offset and @p size of range need to be aligned to
369 : * a write block size of a device.
370 : *
371 : * @param dev : flash device
372 : * @param val : value to use for filling the range
373 : * @param offset : offset of the range to fill
374 : * @param size : size of the range
375 : *
376 : * @return 0 on success, negative errno code on fail.
377 : *
378 : */
379 1 : __syscall int flash_fill(const struct device *dev, uint8_t val, off_t offset, size_t size);
380 :
381 : /**
382 : * @brief Erase part or all of a flash memory or level it
383 : *
384 : * If device is explicit erase type device or device driver provides erase
385 : * callback, the callback of the device is called, in which it behaves
386 : * the same way as flash_erase.
387 : * If a device does not require explicit erase, either because
388 : * it has no erase at all or has auto-erase/erase-on-write,
389 : * and does not provide erase callback then erase is emulated by
390 : * leveling selected device memory area with erase_value assigned to
391 : * device.
392 : *
393 : * Erase page offset and size are constrains of paged, explicit erase devices,
394 : * but can be relaxed with devices without such requirement, which means that
395 : * it is up to user code to make sure they are correct as the function
396 : * will return on, if these constrains are not met, -EINVAL for
397 : * paged device, but may succeed on non-explicit erase devices.
398 : * For RAM non-volatile devices the erase pages are emulated,
399 : * at this point, to allow smooth transition for code relying on
400 : * device being paged to function properly; but this is completely
401 : * software constrain.
402 : *
403 : * Generally: if your code previously required device to be erase
404 : * prior to some actions to work, replace flash_erase calls with this
405 : * function; but if your code can work with non-volatile RAM type devices,
406 : * without emulating erase, you should rather have different path
407 : * of execution for page-erase, i.e. Flash, devices and call
408 : * flash_erase for them.
409 : *
410 : * @param dev : flash device
411 : * @param offset : erase area starting offset
412 : * @param size : size of area to be erased
413 : *
414 : * @return 0 on success, negative errno code on fail.
415 : *
416 : * @see flash_erase()
417 : */
418 1 : __syscall int flash_flatten(const struct device *dev, off_t offset, size_t size);
419 :
420 0 : struct flash_pages_info {
421 0 : off_t start_offset; /* offset from the base of flash address */
422 0 : size_t size;
423 0 : uint32_t index;
424 : };
425 :
426 : #if defined(CONFIG_FLASH_PAGE_LAYOUT)
427 : /**
428 : * @brief Get the size and start offset of flash page at certain flash offset.
429 : *
430 : * @param dev flash device
431 : * @param offset Offset within the page
432 : * @param info Page Info structure to be filled
433 : *
434 : * @return 0 on success, -EINVAL if page of the offset doesn't exist.
435 : */
436 1 : __syscall int flash_get_page_info_by_offs(const struct device *dev,
437 : off_t offset,
438 : struct flash_pages_info *info);
439 :
440 : /**
441 : * @brief Get the size and start offset of flash page of certain index.
442 : *
443 : * @param dev flash device
444 : * @param page_index Index of the page. Index are counted from 0.
445 : * @param info Page Info structure to be filled
446 : *
447 : * @return 0 on success, -EINVAL if page of the index doesn't exist.
448 : */
449 1 : __syscall int flash_get_page_info_by_idx(const struct device *dev,
450 : uint32_t page_index,
451 : struct flash_pages_info *info);
452 :
453 : /**
454 : * @brief Get the total number of flash pages.
455 : *
456 : * @param dev flash device
457 : *
458 : * @return Number of flash pages.
459 : */
460 1 : __syscall size_t flash_get_page_count(const struct device *dev);
461 :
462 : /**
463 : * @brief Callback type for iterating over flash pages present on a device.
464 : *
465 : * The callback should return true to continue iterating, and false to halt.
466 : *
467 : * @param info Information for current page
468 : * @param data Private data for callback
469 : * @return True to continue iteration, false to halt iteration.
470 : * @see flash_page_foreach()
471 : */
472 1 : typedef bool (*flash_page_cb)(const struct flash_pages_info *info, void *data);
473 :
474 : /**
475 : * @brief Iterate over all flash pages on a device
476 : *
477 : * This routine iterates over all flash pages on the given device,
478 : * ordered by increasing start offset. For each page, it invokes the
479 : * given callback, passing it the page's information and a private
480 : * data object.
481 : *
482 : * @param dev Device whose pages to iterate over
483 : * @param cb Callback to invoke for each flash page
484 : * @param data Private data for callback function
485 : */
486 1 : void flash_page_foreach(const struct device *dev, flash_page_cb cb,
487 : void *data);
488 : #endif /* CONFIG_FLASH_PAGE_LAYOUT */
489 :
490 : #if defined(CONFIG_FLASH_JESD216_API)
491 : /**
492 : * @brief Read data from Serial Flash Discoverable Parameters
493 : *
494 : * This routine reads data from a serial flash device compatible with
495 : * the JEDEC JESD216 standard for encoding flash memory
496 : * characteristics.
497 : *
498 : * Availability of this API is conditional on selecting
499 : * @c CONFIG_FLASH_JESD216_API and support of that functionality in
500 : * the driver underlying @p dev.
501 : *
502 : * @param dev device from which parameters will be read
503 : * @param offset address within the SFDP region containing data of interest
504 : * @param data where the data to be read will be placed
505 : * @param len the number of bytes of data to be read
506 : *
507 : * @retval 0 on success
508 : * @retval -ENOTSUP if the flash driver does not support SFDP access
509 : * @retval negative values for other errors.
510 : */
511 1 : __syscall int flash_sfdp_read(const struct device *dev, off_t offset,
512 : void *data, size_t len);
513 :
514 : static inline int z_impl_flash_sfdp_read(const struct device *dev,
515 : off_t offset,
516 : void *data, size_t len)
517 : {
518 : int rv = -ENOTSUP;
519 : const struct flash_driver_api *api =
520 : (const struct flash_driver_api *)dev->api;
521 :
522 : if (api->sfdp_read != NULL) {
523 : rv = api->sfdp_read(dev, offset, data, len);
524 : }
525 : return rv;
526 : }
527 :
528 : /**
529 : * @brief Read the JEDEC ID from a compatible flash device.
530 : *
531 : * @param dev device from which id will be read
532 : * @param id pointer to a buffer of at least 3 bytes into which id
533 : * will be stored
534 : *
535 : * @retval 0 on successful store of 3-byte JEDEC id
536 : * @retval -ENOTSUP if flash driver doesn't support this function
537 : * @retval negative values for other errors
538 : */
539 1 : __syscall int flash_read_jedec_id(const struct device *dev, uint8_t *id);
540 :
541 : static inline int z_impl_flash_read_jedec_id(const struct device *dev,
542 : uint8_t *id)
543 : {
544 : int rv = -ENOTSUP;
545 : const struct flash_driver_api *api =
546 : (const struct flash_driver_api *)dev->api;
547 :
548 : if (api->read_jedec_id != NULL) {
549 : rv = api->read_jedec_id(dev, id);
550 : }
551 : return rv;
552 : }
553 : #endif /* CONFIG_FLASH_JESD216_API */
554 :
555 : /**
556 : * @brief Get the minimum write block size supported by the driver
557 : *
558 : * The write block size supported by the driver might differ from the write
559 : * block size of memory used because the driver might implements write-modify
560 : * algorithm.
561 : *
562 : * @param dev flash device
563 : *
564 : * @return write block size in bytes.
565 : */
566 1 : __syscall size_t flash_get_write_block_size(const struct device *dev);
567 :
568 : static inline size_t z_impl_flash_get_write_block_size(const struct device *dev)
569 : {
570 : const struct flash_driver_api *api =
571 : (const struct flash_driver_api *)dev->api;
572 :
573 : return api->get_parameters(dev)->write_block_size;
574 : }
575 :
576 :
577 : /**
578 : * @brief Get pointer to flash_parameters structure
579 : *
580 : * Returned pointer points to a structure that should be considered
581 : * constant through a runtime, regardless if it is defined in RAM or
582 : * Flash.
583 : * Developer is free to cache the structure pointer or copy its contents.
584 : *
585 : * @return pointer to flash_parameters structure characteristic for
586 : * the device.
587 : */
588 1 : __syscall const struct flash_parameters *flash_get_parameters(const struct device *dev);
589 :
590 : static inline const struct flash_parameters *z_impl_flash_get_parameters(const struct device *dev)
591 : {
592 : const struct flash_driver_api *api =
593 : (const struct flash_driver_api *)dev->api;
594 :
595 : return api->get_parameters(dev);
596 : }
597 :
598 : /**
599 : * @brief Execute flash extended operation on given device
600 : *
601 : * Besides of standard flash operations like write or erase, flash controllers
602 : * also support additional features like write protection or readout
603 : * protection. These features are not available in every flash controller,
604 : * what's more controllers can implement it in a different way.
605 : *
606 : * It doesn't make sense to add a separate flash API function for every flash
607 : * controller feature, because it could be unique (supported on small number of
608 : * flash controllers) or the API won't be able to represent the same feature on
609 : * every flash controller.
610 : *
611 : * @param dev Flash device
612 : * @param code Operation which will be executed on the device.
613 : * @param in Pointer to input data used by operation. If operation doesn't
614 : * need any input data it could be NULL.
615 : * @param out Pointer to operation output data. If operation doesn't produce
616 : * any output it could be NULL.
617 : *
618 : * @retval 0 on success.
619 : * @retval -ENOTSUP if given device doesn't support extended operation.
620 : * @retval -ENOSYS if support for extended operations is not enabled in Kconfig
621 : * @retval negative value on extended operation errors.
622 : */
623 1 : __syscall int flash_ex_op(const struct device *dev, uint16_t code,
624 : const uintptr_t in, void *out);
625 :
626 : /**
627 : * @brief Copy flash memory from one device to another.
628 : *
629 : * Copy a region of flash memory from one place to another. The source and
630 : * destination flash devices may be the same or different devices. However,
631 : * this function will fail if the source and destination devices are the same
632 : * if memory regions overlap and are not identical.
633 : *
634 : * The caller must supply a buffer of suitable size and ensure that the
635 : * destination is erased beforehand, if necessary.
636 : *
637 : * @note If the source and destination devices are the same, and the source
638 : * and destination offsets are also the same, this function succeeds without
639 : * performing any copy operation.
640 : *
641 : * @param src_dev Source flash device.
642 : * @param dst_dev Destination flash device.
643 : * @param src_offset Offset within the source flash device.
644 : * @param dst_offset Offset within the destination flash device.
645 : * @param size Size of the region to copy, in bytes.
646 : * @param[out] buf Pointer to a buffer of size @a buf_size.
647 : * @param buf_size Size of the buffer pointed to by @a buf.
648 : *
649 : * @retval 0 on success
650 : * @retval -EINVAL if an argument is invalid.
651 : * @retval -EIO if an I/O error occurs.
652 : * @retval -ENODEV if either @a src_dev or @a dst_dev are not ready.
653 : */
654 1 : __syscall int flash_copy(const struct device *src_dev, off_t src_offset,
655 : const struct device *dst_dev, off_t dst_offset, off_t size, uint8_t *buf,
656 : size_t buf_size);
657 : /*
658 : * Extended operation interface provides flexible way for supporting flash
659 : * controller features. Code space is divided equally into Zephyr codes
660 : * (MSb == 0) and vendor codes (MSb == 1). This way we can easily add extended
661 : * operations to the drivers without cluttering the API or problems with API
662 : * incompatibility. Extended operation can be promoted from vendor codes to
663 : * Zephyr codes if the feature is available in most flash controllers and
664 : * can be represented in the same way.
665 : *
666 : * It's not forbidden to have operation in Zephyr codes and vendor codes for
667 : * the same functionality. In this case, vendor operation could provide more
668 : * specific access when abstraction in Zephyr counterpart is insufficient.
669 : */
670 0 : #define FLASH_EX_OP_VENDOR_BASE 0x8000
671 0 : #define FLASH_EX_OP_IS_VENDOR(c) ((c) & FLASH_EX_OP_VENDOR_BASE)
672 :
673 : /**
674 : * @brief Enumeration for extra flash operations
675 : */
676 0 : enum flash_ex_op_types {
677 : /*
678 : * Reset flash device.
679 : */
680 : FLASH_EX_OP_RESET = 0,
681 : };
682 :
683 : static inline int z_impl_flash_ex_op(const struct device *dev, uint16_t code,
684 : const uintptr_t in, void *out)
685 : {
686 : #if defined(CONFIG_FLASH_EX_OP_ENABLED)
687 : const struct flash_driver_api *api =
688 : (const struct flash_driver_api *)dev->api;
689 :
690 : if (api->ex_op == NULL) {
691 : return -ENOTSUP;
692 : }
693 :
694 : return api->ex_op(dev, code, in, out);
695 : #else
696 : ARG_UNUSED(dev);
697 : ARG_UNUSED(code);
698 : ARG_UNUSED(in);
699 : ARG_UNUSED(out);
700 :
701 : return -ENOSYS;
702 : #endif /* CONFIG_FLASH_EX_OP_ENABLED */
703 : }
704 :
705 : #ifdef __cplusplus
706 : }
707 : #endif
708 :
709 : /**
710 : * @}
711 : */
712 :
713 : #include <zephyr/syscalls/flash.h>
714 :
715 : #endif /* ZEPHYR_INCLUDE_DRIVERS_FLASH_H_ */
|