1/***********************license start***************
2 * Copyright (c) 2003-2010  Cavium Inc. (support@cavium.com). All rights
3 * reserved.
4 *
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are
8 * met:
9 *
10 *   * Redistributions of source code must retain the above copyright
11 *     notice, this list of conditions and the following disclaimer.
12 *
13 *   * Redistributions in binary form must reproduce the above
14 *     copyright notice, this list of conditions and the following
15 *     disclaimer in the documentation and/or other materials provided
16 *     with the distribution.
17
18 *   * Neither the name of Cavium Inc. nor the names of
19 *     its contributors may be used to endorse or promote products
20 *     derived from this software without specific prior written
21 *     permission.
22
23 * This Software, including technical data, may be subject to U.S. export  control
24 * laws, including the U.S. Export Administration Act and its  associated
25 * regulations, and may be subject to export or import  regulations in other
26 * countries.
27
28 * TO THE MAXIMUM EXTENT PERMITTED BY LAW, THE SOFTWARE IS PROVIDED "AS IS"
29 * AND WITH ALL FAULTS AND CAVIUM INC. MAKES NO PROMISES, REPRESENTATIONS OR
30 * WARRANTIES, EITHER EXPRESS, IMPLIED, STATUTORY, OR OTHERWISE, WITH RESPECT TO
31 * THE SOFTWARE, INCLUDING ITS CONDITION, ITS CONFORMITY TO ANY REPRESENTATION OR
32 * DESCRIPTION, OR THE EXISTENCE OF ANY LATENT OR PATENT DEFECTS, AND CAVIUM
33 * SPECIFICALLY DISCLAIMS ALL IMPLIED (IF ANY) WARRANTIES OF TITLE,
34 * MERCHANTABILITY, NONINFRINGEMENT, FITNESS FOR A PARTICULAR PURPOSE, LACK OF
35 * VIRUSES, ACCURACY OR COMPLETENESS, QUIET ENJOYMENT, QUIET POSSESSION OR
36 * CORRESPONDENCE TO DESCRIPTION. THE ENTIRE  RISK ARISING OUT OF USE OR
37 * PERFORMANCE OF THE SOFTWARE LIES WITH YOU.
38 ***********************license end**************************************/
39
40
41
42
43
44
45
46/**
47 * @file
48 *
49 * This file provides bootbus flash operations
50 *
51 * <hr>$Revision: 70030 $<hr>
52 *
53 *
54 */
55
56
57#ifndef __CVMX_FLASH_H__
58#define __CVMX_FLASH_H__
59
60#ifdef	__cplusplus
61extern "C" {
62#endif
63
64typedef struct
65{
66    int start_offset;
67    int block_size;
68    int num_blocks;
69} cvmx_flash_region_t;
70
71/**
72 * Initialize the flash access library
73 */
74void cvmx_flash_initialize(void);
75
76/**
77 * Return a pointer to the flash chip
78 *
79 * @param chip_id Chip ID to return
80 * @return NULL if the chip doesn't exist
81 */
82void *cvmx_flash_get_base(int chip_id);
83
84/**
85 * Return the number of erasable regions on the chip
86 *
87 * @param chip_id Chip to return info for
88 * @return Number of regions
89 */
90int cvmx_flash_get_num_regions(int chip_id);
91
92/**
93 * Return information about a flash chips region
94 *
95 * @param chip_id Chip to get info for
96 * @param region  Region to get info for
97 * @return Region information
98 */
99const cvmx_flash_region_t *cvmx_flash_get_region_info(int chip_id, int region);
100
101/**
102 * Erase a block on the flash chip
103 *
104 * @param chip_id Chip to erase a block on
105 * @param region  Region to erase a block in
106 * @param block   Block number to erase
107 * @return Zero on success. Negative on failure
108 */
109int cvmx_flash_erase_block(int chip_id, int region, int block);
110
111/**
112 * Write a block on the flash chip
113 *
114 * @param chip_id Chip to write a block on
115 * @param region  Region to write a block in
116 * @param block   Block number to write
117 * @param data    Data to write
118 * @return Zero on success. Negative on failure
119 */
120int cvmx_flash_write_block(int chip_id, int region, int block, const void *data);
121
122/**
123 * Erase and write data to a flash
124 *
125 * @param address Memory address to write to
126 * @param data    Data to write
127 * @param len     Length of the data
128 * @return Zero on success. Negative on failure
129 */
130int cvmx_flash_write(void *address, const void *data, int len);
131
132#ifdef	__cplusplus
133}
134#endif
135
136#endif /* __CVMX_FLASH_H__ */
137