David Hendricks | 23cd778 | 2010-08-25 12:42:38 -0700 | [diff] [blame] | 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 | * |
David Hendricks | 23cd778 | 2010-08-25 12:42:38 -0700 | [diff] [blame] | 16 | */ |
| 17 | |
| 18 | #ifndef __WRITEPROTECT_H__ |
| 19 | #define __WRITEPROTECT_H__ 1 |
| 20 | |
Nikolai Artemiev | 9d3980e | 2021-03-30 22:26:37 +1100 | [diff] [blame] | 21 | #include "flash.h" |
| 22 | |
David Hendricks | 1c09f80 | 2012-10-03 11:03:48 -0700 | [diff] [blame] | 23 | enum wp_mode { |
| 24 | WP_MODE_UNKNOWN = -1, |
| 25 | WP_MODE_HARDWARE, /* hardware WP pin determines status */ |
| 26 | WP_MODE_POWER_CYCLE, /* WP active until power off/on cycle */ |
| 27 | WP_MODE_PERMANENT, /* status register permanently locked, |
| 28 | WP permanently enabled */ |
| 29 | }; |
| 30 | |
David Hendricks | 23cd778 | 2010-08-25 12:42:38 -0700 | [diff] [blame] | 31 | struct wp { |
Souvik Ghosh | d75cd67 | 2016-06-17 14:21:39 -0700 | [diff] [blame] | 32 | int (*list_ranges)(const struct flashctx *flash); |
| 33 | int (*set_range)(const struct flashctx *flash, |
David Hendricks | 23cd778 | 2010-08-25 12:42:38 -0700 | [diff] [blame] | 34 | unsigned int start, unsigned int len); |
Souvik Ghosh | d75cd67 | 2016-06-17 14:21:39 -0700 | [diff] [blame] | 35 | int (*enable)(const struct flashctx *flash, enum wp_mode mode); |
| 36 | int (*disable)(const struct flashctx *flash); |
| 37 | int (*wp_status)(const struct flashctx *flash); |
David Hendricks | 23cd778 | 2010-08-25 12:42:38 -0700 | [diff] [blame] | 38 | }; |
| 39 | |
| 40 | /* winbond w25-series */ |
David Hendricks | 1c09f80 | 2012-10-03 11:03:48 -0700 | [diff] [blame] | 41 | extern struct wp wp_w25; /* older winbond chips (w25p, w25x, etc) */ |
| 42 | extern struct wp wp_w25q; |
Duncan Laurie | 1801f7c | 2019-01-09 18:02:51 -0800 | [diff] [blame] | 43 | extern struct wp wp_w25q_large; /* large winbond chips (>= 32MB) */ |
David Hendricks | e0512a7 | 2014-07-15 20:30:47 -0700 | [diff] [blame] | 44 | |
| 45 | extern struct wp wp_generic; |
David Hendricks | 23cd778 | 2010-08-25 12:42:38 -0700 | [diff] [blame] | 46 | extern struct wp wp_wpce775x; |
| 47 | |
Nikolai Artemiev | 9d3980e | 2021-03-30 22:26:37 +1100 | [diff] [blame] | 48 | struct wp *get_wp_for_flashchip(const struct flashchip *chip); |
David Hendricks | 1c09f80 | 2012-10-03 11:03:48 -0700 | [diff] [blame] | 49 | enum wp_mode get_wp_mode(const char *mode_str); |
David Hendricks | 23cd778 | 2010-08-25 12:42:38 -0700 | [diff] [blame] | 50 | |
David Hendricks | 148a4bf | 2015-03-13 21:02:42 -0700 | [diff] [blame] | 51 | /* |
| 52 | * Generic write-protect stuff |
| 53 | */ |
| 54 | |
Edward O'Callaghan | 9c4c9a5 | 2019-12-04 18:18:01 +1100 | [diff] [blame] | 55 | struct modifier_bits { |
Edward O'Callaghan | 91b3827 | 2019-12-04 17:12:43 +1100 | [diff] [blame] | 56 | int sec; /* if 1, bp bits describe sectors */ |
| 57 | int tb; /* value of top/bottom select bit */ |
David Hendricks | 148a4bf | 2015-03-13 21:02:42 -0700 | [diff] [blame] | 58 | }; |
| 59 | |
Edward O'Callaghan | d1d0144 | 2020-11-25 18:44:20 +1100 | [diff] [blame] | 60 | #endif /* !__WRITEPROTECT_H__ */ |