flash.h 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. /*
  2. * Copyright (c) 2008, Google Inc.
  3. * All rights reserved.
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions
  7. * are met:
  8. * * Redistributions of source code must retain the above copyright
  9. * notice, this list of conditions and the following disclaimer.
  10. * * Redistributions in binary form must reproduce the above copyright
  11. * notice, this list of conditions and the following disclaimer in
  12. * the documentation and/or other materials provided with the
  13. * distribution.
  14. *
  15. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  16. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  17. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  18. * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  19. * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  20. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  21. * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
  22. * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
  23. * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  24. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
  25. * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  26. * SUCH DAMAGE.
  27. */
  28. #ifndef __DEV_FLASH_H
  29. #define __DEV_FLASH_H
  30. #include <lib/ptable.h>
  31. struct flash_info {
  32. unsigned id;
  33. unsigned type;
  34. unsigned vendor;
  35. unsigned device;
  36. unsigned page_size;
  37. unsigned block_size;
  38. unsigned spare_size;
  39. unsigned num_blocks;
  40. };
  41. void flash_init(void);
  42. struct ptable *flash_get_ptable(void);
  43. void flash_set_ptable(struct ptable *ptable);
  44. struct flash_info *flash_get_info(void);
  45. /* flash operations */
  46. int flash_erase(struct ptentry *ptn);
  47. int flash_read_ext(struct ptentry *ptn, unsigned extra_per_page,
  48. unsigned offset, void *data, unsigned bytes);
  49. int flash_write(struct ptentry *ptn, unsigned extra_per_page, const void *data,
  50. unsigned bytes);
  51. static inline int flash_read(struct ptentry *ptn, unsigned offset, void *data,
  52. unsigned bytes)
  53. {
  54. return flash_read_ext(ptn, 0, offset, data, bytes);
  55. }
  56. unsigned flash_page_size(void);
  57. int flash_ecc_bch_enabled(void);
  58. #endif /* __DEV_FLASH_H */