writeprotect.h 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /*
  2. * This file is part of the flashrom project.
  3. *
  4. * Copyright (C) 2010 Google Inc.
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, write to the Free Software
  18. * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  19. */
  20. #ifndef __WRITEPROTECT_H__
  21. #define __WRITEPROTECT_H__ 1
  22. enum wp_mode {
  23. WP_MODE_UNKNOWN = -1,
  24. WP_MODE_HARDWARE, /* hardware WP pin determines status */
  25. WP_MODE_POWER_CYCLE, /* WP active until power off/on cycle */
  26. WP_MODE_PERMANENT, /* status register permanently locked,
  27. WP permanently enabled */
  28. };
  29. struct wp {
  30. int (*list_ranges)(const struct flashctx *flash);
  31. int (*set_range)(const struct flashctx *flash,
  32. unsigned int start, unsigned int len);
  33. int (*enable)(const struct flashctx *flash, enum wp_mode mode);
  34. int (*disable)(const struct flashctx *flash);
  35. int (*wp_status)(const struct flashctx *flash);
  36. };
  37. /* winbond w25-series */
  38. extern struct wp wp_w25; /* older winbond chips (w25p, w25x, etc) */
  39. extern struct wp wp_w25q;
  40. extern struct wp wp_w25r;
  41. extern struct wp wp_generic;
  42. extern struct wp wp_wpce775x;
  43. struct w25q_status {
  44. /* this maps to register layout -- do not change ordering */
  45. unsigned char busy : 1;
  46. unsigned char wel : 1;
  47. unsigned char bp0 : 1;
  48. unsigned char bp1 : 1;
  49. unsigned char bp2 : 1;
  50. unsigned char tb : 1;
  51. unsigned char sec : 1;
  52. unsigned char srp0 : 1;
  53. } __attribute__ ((packed));
  54. struct w25q_status_2 {
  55. unsigned char srp1 : 1;
  56. unsigned char qe : 1;
  57. unsigned char rsvd : 6;
  58. } __attribute__ ((packed));
  59. int w25_range_to_status(const struct flashctx *flash,
  60. unsigned int start, unsigned int len,
  61. struct w25q_status *status);
  62. int w25_status_to_range(const struct flashctx *flash,
  63. const struct w25q_status *status,
  64. unsigned int *start, unsigned int *len);
  65. enum wp_mode get_wp_mode(const char *mode_str);
  66. /*
  67. * Generic write-protect stuff
  68. */
  69. /* For now, use one struct for all modifier bits on all devices. We can get
  70. * more specific to certain chips if needed later on. */
  71. struct generic_modifier_bits {
  72. int tb; /* value of top/bottom bit */
  73. };
  74. #endif /* !__WRITEPROTECT_H__ */