cvmx-flash.h revision 232812
190075Sobrien/***********************license start***************
2169689Skan * Copyright (c) 2003-2010  Cavium Inc. (support@cavium.com). All rights
3169689Skan * reserved.
4169689Skan *
590075Sobrien *
6132718Skan * Redistribution and use in source and binary forms, with or without
790075Sobrien * modification, are permitted provided that the following conditions are
8132718Skan * met:
990075Sobrien *
1090075Sobrien *   * Redistributions of source code must retain the above copyright
1190075Sobrien *     notice, this list of conditions and the following disclaimer.
1290075Sobrien *
13132718Skan *   * Redistributions in binary form must reproduce the above
1490075Sobrien *     copyright notice, this list of conditions and the following
1590075Sobrien *     disclaimer in the documentation and/or other materials provided
1690075Sobrien *     with the distribution.
1790075Sobrien
1890075Sobrien *   * Neither the name of Cavium Inc. nor the names of
19132718Skan *     its contributors may be used to endorse or promote products
20169689Skan *     derived from this software without specific prior written
21169689Skan *     permission.
2290075Sobrien
2390075Sobrien * This Software, including technical data, may be subject to U.S. export  control
2490075Sobrien * laws, including the U.S. Export Administration Act and its  associated
2590075Sobrien * regulations, and may be subject to export or import  regulations in other
2690075Sobrien * countries.
2790075Sobrien
2890075Sobrien * TO THE MAXIMUM EXTENT PERMITTED BY LAW, THE SOFTWARE IS PROVIDED "AS IS"
2990075Sobrien * AND WITH ALL FAULTS AND CAVIUM INC. MAKES NO PROMISES, REPRESENTATIONS OR
3090075Sobrien * WARRANTIES, EITHER EXPRESS, IMPLIED, STATUTORY, OR OTHERWISE, WITH RESPECT TO
3190075Sobrien * THE SOFTWARE, INCLUDING ITS CONDITION, ITS CONFORMITY TO ANY REPRESENTATION OR
3290075Sobrien * DESCRIPTION, OR THE EXISTENCE OF ANY LATENT OR PATENT DEFECTS, AND CAVIUM
3390075Sobrien * SPECIFICALLY DISCLAIMS ALL IMPLIED (IF ANY) WARRANTIES OF TITLE,
3490075Sobrien * MERCHANTABILITY, NONINFRINGEMENT, FITNESS FOR A PARTICULAR PURPOSE, LACK OF
3590075Sobrien * VIRUSES, ACCURACY OR COMPLETENESS, QUIET ENJOYMENT, QUIET POSSESSION OR
3690075Sobrien * CORRESPONDENCE TO DESCRIPTION. THE ENTIRE  RISK ARISING OUT OF USE OR
3790075Sobrien * PERFORMANCE OF THE SOFTWARE LIES WITH YOU.
3890075Sobrien ***********************license end**************************************/
3990075Sobrien
4090075Sobrien
4190075Sobrien
42169689Skan
43169689Skan
44169689Skan
45169689Skan
46169689Skan/**
47169689Skan * @file
4890075Sobrien *
4990075Sobrien * This file provides bootbus flash operations
5090075Sobrien *
51132718Skan * <hr>$Revision: 70030 $<hr>
52132718Skan *
5390075Sobrien *
54117395Skan */
5590075Sobrien
56117395Skan
5790075Sobrien#ifndef __CVMX_FLASH_H__
5890075Sobrien#define __CVMX_FLASH_H__
5990075Sobrien
60132718Skan#ifdef	__cplusplus
61146895Skanextern "C" {
6290075Sobrien#endif
6390075Sobrien
6490075Sobrientypedef struct
6590075Sobrien{
6690075Sobrien    int start_offset;
6790075Sobrien    int block_size;
6890075Sobrien    int num_blocks;
6990075Sobrien} cvmx_flash_region_t;
7090075Sobrien
7190075Sobrien/**
7290075Sobrien * Initialize the flash access library
7390075Sobrien */
7490075Sobrienvoid cvmx_flash_initialize(void);
7590075Sobrien
76169689Skan/**
7790075Sobrien * Return a pointer to the flash chip
7890075Sobrien *
7990075Sobrien * @param chip_id Chip ID to return
8090075Sobrien * @return NULL if the chip doesn't exist
8190075Sobrien */
82117395Skanvoid *cvmx_flash_get_base(int chip_id);
8390075Sobrien
8490075Sobrien/**
8590075Sobrien * Return the number of erasable regions on the chip
8690075Sobrien *
87117395Skan * @param chip_id Chip to return info for
88117395Skan * @return Number of regions
89117395Skan */
90117395Skanint cvmx_flash_get_num_regions(int chip_id);
91117395Skan
9290075Sobrien/**
9390075Sobrien * Return information about a flash chips region
94169689Skan *
9590075Sobrien * @param chip_id Chip to get info for
9690075Sobrien * @param region  Region to get info for
9790075Sobrien * @return Region information
98169689Skan */
99107590Sobrienconst cvmx_flash_region_t *cvmx_flash_get_region_info(int chip_id, int region);
100107590Sobrien
101169689Skan/**
102107590Sobrien * Erase a block on the flash chip
103107590Sobrien *
104107590Sobrien * @param chip_id Chip to erase a block on
105107590Sobrien * @param region  Region to erase a block in
106169689Skan * @param block   Block number to erase
10790075Sobrien * @return Zero on success. Negative on failure
108169689Skan */
109169689Skanint cvmx_flash_erase_block(int chip_id, int region, int block);
110169689Skan
111169689Skan/**
112169689Skan * Write a block on the flash chip
113169689Skan *
114169689Skan * @param chip_id Chip to write a block on
115169689Skan * @param region  Region to write a block in
116169689Skan * @param block   Block number to write
117169689Skan * @param data    Data to write
118169689Skan * @return Zero on success. Negative on failure
119169689Skan */
120169689Skanint cvmx_flash_write_block(int chip_id, int region, int block, const void *data);
121169689Skan
122169689Skan/**
123169689Skan * Erase and write data to a flash
124169689Skan *
125169689Skan * @param address Memory address to write to
126169689Skan * @param data    Data to write
127169689Skan * @param len     Length of the data
12890075Sobrien * @return Zero on success. Negative on failure
12990075Sobrien */
13090075Sobrienint cvmx_flash_write(void *address, const void *data, int len);
13190075Sobrien
13290075Sobrien#ifdef	__cplusplus
13390075Sobrien}
13490075Sobrien#endif
13590075Sobrien
13690075Sobrien#endif /* __CVMX_FLASH_H__ */
13790075Sobrien