Sandrine Bailleux | 3cd87d7 | 2018-10-09 11:12:55 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2018, Arm Limited. All rights reserved. |
| 3 | * |
| 4 | * SPDX-License-Identifier: BSD-3-Clause |
| 5 | */ |
| 6 | |
| 7 | #include <assert.h> |
Antonio Nino Diaz | 09a00ef | 2019-01-11 13:12:58 +0000 | [diff] [blame^] | 8 | #include <drivers/io/io_driver.h> |
| 9 | #include <drivers/io/io_nor_flash.h> |
Sandrine Bailleux | 3cd87d7 | 2018-10-09 11:12:55 +0200 | [diff] [blame] | 10 | #include <io_storage.h> |
| 11 | #include <platform.h> |
| 12 | #include <tftf.h> |
| 13 | #include "platform_def.h" |
| 14 | |
| 15 | #pragma weak plat_get_nvm_handle |
| 16 | |
| 17 | /* IO devices */ |
| 18 | static const io_dev_connector_t *flash_dev_con; |
| 19 | static uintptr_t flash_dev_spec; |
| 20 | static uintptr_t flash_init_params; |
| 21 | static uintptr_t flash_dev_handle; |
| 22 | static uintptr_t flash_handle; |
| 23 | static unsigned int flash_init; |
| 24 | |
| 25 | static const io_nor_flash_spec_t flash_main_block_spec = { |
| 26 | .device_address = FLASH_BASE, |
| 27 | .region_address = FLASH_BASE, |
| 28 | .block_size = NOR_FLASH_BLOCK_SIZE, |
| 29 | .block_count = FLASH_SIZE / NOR_FLASH_BLOCK_SIZE |
| 30 | }; |
| 31 | |
| 32 | int arm_io_setup(void) |
| 33 | { |
| 34 | int io_result; |
| 35 | |
| 36 | io_result = register_io_dev_nor_flash(&flash_dev_con); |
| 37 | if (io_result != IO_SUCCESS) |
| 38 | return io_result; |
| 39 | |
| 40 | io_result = io_dev_open(flash_dev_con, flash_dev_spec, |
| 41 | &flash_dev_handle); |
| 42 | if (io_result != IO_SUCCESS) |
| 43 | return io_result; |
| 44 | |
| 45 | io_result = io_dev_init(flash_dev_handle, flash_init_params); |
| 46 | if (io_result != IO_SUCCESS) |
| 47 | return io_result; |
| 48 | |
| 49 | io_result = io_open(flash_dev_handle, |
| 50 | (uintptr_t)&flash_main_block_spec, |
| 51 | &flash_handle); |
| 52 | |
| 53 | if (io_result == IO_SUCCESS) |
| 54 | flash_init = 1; |
| 55 | return io_result; |
| 56 | } |
| 57 | |
| 58 | void plat_get_nvm_handle(uintptr_t *handle) |
| 59 | { |
| 60 | assert(handle); |
| 61 | assert(flash_init); |
| 62 | |
| 63 | *handle = flash_handle; |
| 64 | } |
| 65 | |