NOR: fix comment for Doxygen
[openocd.git] / src / flash / nor / driver.h
blob0e77132734bbf14d0589b8f6a623ed06ef7f3293
1 /***************************************************************************
2 * Copyright (C) 2005 by Dominic Rath <Dominic.Rath@gmx.de> *
3 * Copyright (C) 2007,2008 Øyvind Harboe <oyvind.harboe@zylin.com> *
4 * Copyright (C) 2008 by Spencer Oliver <spen@spen-soft.co.uk> *
5 * Copyright (C) 2009 Zachary T Welch <zw@superlucidity.net> *
6 * *
7 * This program is free software; you can redistribute it and/or modify *
8 * it under the terms of the GNU General Public License as published by *
9 * the Free Software Foundation; either version 2 of the License, or *
10 * (at your option) any later version. *
11 * *
12 * This program is distributed in the hope that it will be useful, *
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
15 * GNU General Public License for more details. *
16 * *
17 * You should have received a copy of the GNU General Public License *
18 * along with this program; if not, write to the *
19 * Free Software Foundation, Inc., *
20 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
21 ***************************************************************************/
22 #ifndef FLASH_NOR_DRIVER_H
23 #define FLASH_NOR_DRIVER_H
25 struct flash_bank;
27 #define __FLASH_BANK_COMMAND(name) \
28 COMMAND_HELPER(name, struct flash_bank *bank)
30 /**
31 * @brief Provides the implementation-independent structure that defines
32 * all of the callbacks required by OpenOCD flash drivers.
34 * Driver authors must implement the routines defined here, providing an
35 * instance with the fields filled out. After that, the instance must
36 * be registered in flash.c, so it can be used by the driver lookup system.
38 * Specifically, the user can issue the command: @par
39 * @code
40 * flash bank DRIVERNAME ...parameters...
41 * @endcode
43 * OpenOCD will search for the driver with a @c flash_driver_s::name
44 * that matches @c DRIVERNAME.
46 * The flash subsystem calls some of the other drivers routines a using
47 * corresponding static <code>flash_driver_<i>callback</i>()</code>
48 * routine in flash.c.
50 struct flash_driver
52 /**
53 * Gives a human-readable name of this flash driver,
54 * This field is used to select and initialize the driver.
56 char *name;
58 /**
59 * An array of driver-specific commands to register. When called
60 * during the "flash bank" command, the driver can register addition
61 * commands to support new flash chip functions.
63 const struct command_registration *commands;
65 /**
66 * Finish the "flash bank" command for @a bank. The
67 * @a bank parameter will have been filled in by the core flash
68 * layer when this routine is called, and the driver can store
69 * additional information in its struct flash_bank::driver_priv field.
71 * The CMD_ARGV are: @par
72 * @code
73 * CMD_ARGV[0] = bank
74 * CMD_ARGV[1] = drivername {name above}
75 * CMD_ARGV[2] = baseaddress
76 * CMD_ARGV[3] = lengthbytes
77 * CMD_ARGV[4] = chip_width_in bytes
78 * CMD_ARGV[5] = bus_width_in_bytes
79 * CMD_ARGV[6] = driver-specific parameters
80 * @endcode
82 * For example, CMD_ARGV[4] = 2 (for 16 bit flash),
83 * CMD_ARGV[5] = 4 (for 32 bit bus).
85 * If extra arguments are provided (@a CMD_ARGC > 6), they will
86 * start in @a CMD_ARGV[6]. These can be used to implement
87 * driver-specific extensions.
89 * @returns ERROR_OK if successful; otherwise, an error code.
91 __FLASH_BANK_COMMAND((*flash_bank_command));
93 /**
94 * Bank/sector erase routine (target-specific). When
95 * called, the flash driver should erase the specified sectors
96 * using whatever means are at its disposal.
98 * @param bank The bank of flash to be erased.
99 * @param first The number of the first sector to erase, typically 0.
100 * @param last The number of the last sector to erase, typically N-1.
101 * @returns ERROR_OK if successful; otherwise, an error code.
103 int (*erase)(struct flash_bank *bank, int first, int last);
106 * Bank/sector protection routine (target-specific).
107 * When called, the driver should disable 'flash write' bits (or
108 * enable 'erase protection' bits) for the given @a bank and @a
109 * sectors.
111 * @param bank The bank to protect or unprotect.
112 * @param set If non-zero, enable protection; if 0, disable it.
113 * @param first The first sector to (un)protect, typicaly 0.
114 * @param last The last sector to (un)project, typically N-1.
115 * @returns ERROR_OK if successful; otherwise, an error code.
117 int (*protect)(struct flash_bank *bank, int set, int first, int last);
120 * Program data into the flash. Note CPU address will be
121 * "bank->base + offset", while the physical address is
122 * dependent upon current target MMU mappings.
124 * @param bank The bank to program
125 * @param buffer The data bytes to write.
126 * @param offset The offset into the chip to program.
127 * @param count The number of bytes to write.
128 * @returns ERROR_OK if successful; otherwise, an error code.
130 int (*write)(struct flash_bank *bank,
131 uint8_t *buffer, uint32_t offset, uint32_t count);
134 * Probe to determine what kind of flash is present.
135 * This is invoked by the "probe" script command.
137 * @param bank The bank to probe
138 * @returns ERROR_OK if successful; otherwise, an error code.
140 int (*probe)(struct flash_bank *bank);
143 * Check the erasure status of a flash bank.
144 * When called, the driver routine must perform the required
145 * checks and then set the @c flash_sector_s::is_erased field
146 * for each of the flash banks's sectors.
148 * @param bank The bank to check
149 * @returns ERROR_OK if successful; otherwise, an error code.
151 int (*erase_check)(struct flash_bank *bank);
154 * Determine if the specific bank is "protected" or not.
155 * When called, the driver routine must must perform the
156 * required protection check(s) and then set the @c
157 * flash_sector_s::is_protected field for each of the flash
158 * bank's sectors.
160 * @param bank - the bank to check
161 * @returns ERROR_OK if successful; otherwise, an error code.
163 int (*protect_check)(struct flash_bank *bank);
166 * Display human-readable information about the flash
167 * bank into the given buffer. Drivers must be careful to avoid
168 * overflowing the buffer.
170 * @param bank - the bank to get info about
171 * @param char - where to put the text for the human to read
172 * @param buf_size - the size of the human buffer.
173 * @returns ERROR_OK if successful; otherwise, an error code.
175 int (*info)(struct flash_bank *bank, char *buf, int buf_size);
178 * A more gentle flavor of filash_driver_s::probe, performing
179 * setup with less noise. Generally, driver routines should test
180 * to seee if the bank has already been probed; if it has, the
181 * driver probably should not perform its probe a second time.
183 * This callback is often called from the inside of other
184 * routines (e.g. GDB flash downloads) to autoprobe the flash as
185 * it is programing the flash.
187 * @param bank - the bank to probe
188 * @returns ERROR_OK if successful; otherwise, an error code.
190 int (*auto_probe)(struct flash_bank *bank);
193 #define FLASH_BANK_COMMAND_HANDLER(name) static __FLASH_BANK_COMMAND(name)
196 * Find a NOR flash driver by its name.
197 * @param name The name of the requested driver.
198 * @returns The flash_driver called @c name, or NULL if not found.
200 struct flash_driver *flash_driver_find_by_name(const char *name);
202 #endif // FLASH_NOR_DRIVER_H