blob: 919458412f80b709e08282db50786df7bcf94275 [file] [log] [blame]
David Hendricks23cd7782010-08-25 12:42:38 -07001/*
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 Hendricks23cd7782010-08-25 12:42:38 -070016 */
17
18#ifndef __WRITEPROTECT_H__
19#define __WRITEPROTECT_H__ 1
20
Nikolai Artemiev9d3980e2021-03-30 22:26:37 +110021#include "flash.h"
22
David Hendricks1c09f802012-10-03 11:03:48 -070023enum 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 Hendricks23cd7782010-08-25 12:42:38 -070031struct wp {
Souvik Ghoshd75cd672016-06-17 14:21:39 -070032 int (*list_ranges)(const struct flashctx *flash);
33 int (*set_range)(const struct flashctx *flash,
David Hendricks23cd7782010-08-25 12:42:38 -070034 unsigned int start, unsigned int len);
Souvik Ghoshd75cd672016-06-17 14:21:39 -070035 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 Hendricks23cd7782010-08-25 12:42:38 -070038};
39
40/* winbond w25-series */
David Hendricks1c09f802012-10-03 11:03:48 -070041extern struct wp wp_w25; /* older winbond chips (w25p, w25x, etc) */
42extern struct wp wp_w25q;
Duncan Laurie1801f7c2019-01-09 18:02:51 -080043extern struct wp wp_w25q_large; /* large winbond chips (>= 32MB) */
David Hendrickse0512a72014-07-15 20:30:47 -070044
45extern struct wp wp_generic;
David Hendricks23cd7782010-08-25 12:42:38 -070046extern struct wp wp_wpce775x;
47
Nikolai Artemiev9d3980e2021-03-30 22:26:37 +110048struct wp *get_wp_for_flashchip(const struct flashchip *chip);
David Hendricks1c09f802012-10-03 11:03:48 -070049enum wp_mode get_wp_mode(const char *mode_str);
David Hendricks23cd7782010-08-25 12:42:38 -070050
David Hendricks148a4bf2015-03-13 21:02:42 -070051/*
52 * Generic write-protect stuff
53 */
54
Edward O'Callaghan9c4c9a52019-12-04 18:18:01 +110055struct modifier_bits {
Edward O'Callaghan91b38272019-12-04 17:12:43 +110056 int sec; /* if 1, bp bits describe sectors */
57 int tb; /* value of top/bottom select bit */
David Hendricks148a4bf2015-03-13 21:02:42 -070058};
59
Edward O'Callaghand1d01442020-11-25 18:44:20 +110060#endif /* !__WRITEPROTECT_H__ */