blob: 3fdaf8c2e763e81f971d72d6d9dfd9298f6e2e09 [file] [log] [blame]
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +02001/*
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 Diaz09a00ef2019-01-11 13:12:58 +00008#include <drivers/io/io_driver.h>
9#include <drivers/io/io_nor_flash.h>
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +020010#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 */
18static const io_dev_connector_t *flash_dev_con;
19static uintptr_t flash_dev_spec;
20static uintptr_t flash_init_params;
21static uintptr_t flash_dev_handle;
22static uintptr_t flash_handle;
23static unsigned int flash_init;
24
25static 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
32int 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
58void plat_get_nvm_handle(uintptr_t *handle)
59{
60 assert(handle);
61 assert(flash_init);
62
63 *handle = flash_handle;
64}
65