blob: 56644a03c3bb5ce1fabcc4980ef1fbf78d745d49 [file] [log] [blame]
Carl-Daniel Hailfinger5d5c0722009-12-14 03:32:24 +00001/*
2 * This file is part of the flashrom project.
3 *
4 * Copyright (C) 2009 Carl-Daniel Hailfinger
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; version 2 of the License.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
Carl-Daniel Hailfinger5d5c0722009-12-14 03:32:24 +000015 * Header file for flash chip drivers. Included from flash.h.
16 * As a general rule, every function listed here should take a pointer to
Carl-Daniel Hailfinger63fd9022011-12-14 22:25:15 +000017 * struct flashctx as first parameter.
Carl-Daniel Hailfinger5d5c0722009-12-14 03:32:24 +000018 */
19
20#ifndef __CHIPDRIVERS_H__
21#define __CHIPDRIVERS_H__ 1
22
Carl-Daniel Hailfinger63fd9022011-12-14 22:25:15 +000023#include "flash.h" /* for chipaddr and flashctx */
Stefan Taunera63c7c42011-08-16 12:08:22 +000024
Stefan Taunereb582572012-09-21 12:52:50 +000025/* spi.c */
Mark Marshallf20b7be2014-05-09 21:16:21 +000026int spi_aai_write(struct flashctx *flash, const uint8_t *buf, unsigned int start, unsigned int len);
27int spi_chip_write_256(struct flashctx *flash, const uint8_t *buf, unsigned int start, unsigned int len);
Stefan Taunereb582572012-09-21 12:52:50 +000028int spi_chip_read(struct flashctx *flash, uint8_t *buf, unsigned int start, int unsigned len);
29
30/* spi25.c */
Nico Huber8d0f4652024-05-04 18:52:51 +020031int spi_simple_write_cmd(struct flashctx *flash, uint8_t op, unsigned int poll_delay);
Carl-Daniel Hailfinger63fd9022011-12-14 22:25:15 +000032int probe_spi_rdid(struct flashctx *flash);
33int probe_spi_rdid4(struct flashctx *flash);
34int probe_spi_rems(struct flashctx *flash);
35int probe_spi_res1(struct flashctx *flash);
36int probe_spi_res2(struct flashctx *flash);
Stefan Tauner3f5e35d2013-04-19 01:58:33 +000037int probe_spi_res3(struct flashctx *flash);
Stefan Tauner57794ac2012-12-29 15:04:20 +000038int probe_spi_at25f(struct flashctx *flash);
Carl-Daniel Hailfinger8a3c60c2011-12-18 15:01:24 +000039int spi_write_enable(struct flashctx *flash);
40int spi_write_disable(struct flashctx *flash);
Carl-Daniel Hailfinger63fd9022011-12-14 22:25:15 +000041int spi_block_erase_20(struct flashctx *flash, unsigned int addr, unsigned int blocklen);
Nico Huber7e3c81a2017-10-14 18:56:50 +020042int spi_block_erase_21(struct flashctx *flash, unsigned int addr, unsigned int blocklen);
Stefan Tauner94b39b42012-10-27 00:06:02 +000043int spi_block_erase_50(struct flashctx *flash, unsigned int addr, unsigned int blocklen);
Carl-Daniel Hailfinger63fd9022011-12-14 22:25:15 +000044int spi_block_erase_52(struct flashctx *flash, unsigned int addr, unsigned int blocklen);
Nico Huberfffc48d2022-05-28 14:26:06 +020045int spi_block_erase_53(struct flashctx *flash, unsigned int addr, unsigned int blocklen);
Nico Huber7e3c81a2017-10-14 18:56:50 +020046int spi_block_erase_5c(struct flashctx *flash, unsigned int addr, unsigned int blocklen);
Carl-Daniel Hailfinger63fd9022011-12-14 22:25:15 +000047int spi_block_erase_60(struct flashctx *flash, unsigned int addr, unsigned int blocklen);
Stefan Tauner3c0fcd02012-09-21 12:46:56 +000048int spi_block_erase_62(struct flashctx *flash, unsigned int addr, unsigned int blocklen);
Stefan Tauner730e7e72013-05-01 14:04:19 +000049int spi_block_erase_81(struct flashctx *flash, unsigned int addr, unsigned int blocklen);
Nikolay Nikolaev6f59b0b2013-06-28 21:29:51 +000050int spi_block_erase_c4(struct flashctx *flash, unsigned int addr, unsigned int blocklen);
Carl-Daniel Hailfinger63fd9022011-12-14 22:25:15 +000051int spi_block_erase_c7(struct flashctx *flash, unsigned int addr, unsigned int blocklen);
Stefan Tauner730e7e72013-05-01 14:04:19 +000052int spi_block_erase_d7(struct flashctx *flash, unsigned int addr, unsigned int blocklen);
53int spi_block_erase_d8(struct flashctx *flash, unsigned int addr, unsigned int blocklen);
Nikolay Nikolaev579f1e02013-06-28 21:28:37 +000054int spi_block_erase_db(struct flashctx *flash, unsigned int addr, unsigned int blocklen);
Nico Huber7e3c81a2017-10-14 18:56:50 +020055int spi_block_erase_dc(struct flashctx *flash, unsigned int addr, unsigned int blocklen);
Thomas Heijligen35614512022-09-19 23:46:58 +020056erasefunc_t *spi25_get_erasefn_from_opcode(uint8_t opcode);
Nico Huber13389362024-03-05 18:35:30 +010057const uint8_t *spi_get_opcode_from_erasefn(erasefunc_t *func, bool *native_4ba);
Mark Marshallf20b7be2014-05-09 21:16:21 +000058int spi_chip_write_1(struct flashctx *flash, const uint8_t *buf, unsigned int start, unsigned int len);
Nico Huberca1c7fd2023-04-28 21:44:41 +000059int spi_nbyte_read(struct flashctx *flash, uint8_t *dst, unsigned int addr, unsigned int len);
Mark Marshallf20b7be2014-05-09 21:16:21 +000060int spi_write_chunked(struct flashctx *flash, const uint8_t *buf, unsigned int start, unsigned int len, unsigned int chunksize);
Nico Huber7eb38aa2019-03-21 15:42:54 +010061int spi_set_extended_address(struct flashctx *, uint8_t addr_high);
Nico Huber8d0f4652024-05-04 18:52:51 +020062
63/* spi25_prepare.c */
Nico Huber930d4212024-05-04 18:59:15 +020064int spi_prepare_io(struct flashctx *, enum preparation_steps);
65void spi_finish_io(struct flashctx *);
Nico Huber7e3c81a2017-10-14 18:56:50 +020066
Carl-Daniel Hailfinger5d5c0722009-12-14 03:32:24 +000067
Stefan Tauner6ee37e22012-12-29 15:03:51 +000068/* spi25_statusreg.c */
Nico Huber4ac536b2024-07-21 00:22:29 +020069enum wrsr_target {
70 WRSR_VOLATILE_BITS = 1,
71 WRSR_NON_VOLATILE_BITS = 2,
72 WRSR_EITHER = 3,
73};
Nico Huber55e78842024-07-21 00:46:19 +020074static inline enum wrsr_target default_wrsr_target(const struct flashctx *flash)
75{
76 return flash->flags.non_volatile_wrsr ? WRSR_NON_VOLATILE_BITS : WRSR_VOLATILE_BITS;
77}
Nikolai Artemiev01675222021-10-20 22:30:41 +110078int spi_read_register(const struct flashctx *flash, enum flash_reg reg, uint8_t *value);
Nico Huber4ac536b2024-07-21 00:22:29 +020079int spi_write_register(const struct flashctx *flash, enum flash_reg reg, uint8_t value, enum wrsr_target);
Aidan Thorntondb4e87d2013-08-27 18:01:53 +000080void spi_prettyprint_status_register_bit(uint8_t status, int bit);
Stefan Tauner6ee37e22012-12-29 15:03:51 +000081int spi_prettyprint_status_register_plain(struct flashctx *flash);
Stefan Tauner278ba6e2013-06-28 21:28:27 +000082int spi_prettyprint_status_register_default_welwip(struct flashctx *flash);
Stefan Tauner12f3d512014-05-27 21:27:27 +000083int spi_prettyprint_status_register_bp1_srwd(struct flashctx *flash);
84int spi_prettyprint_status_register_bp2_srwd(struct flashctx *flash);
85int spi_prettyprint_status_register_bp3_srwd(struct flashctx *flash);
86int spi_prettyprint_status_register_bp4_srwd(struct flashctx *flash);
Stefan Tauner85f09f72014-05-27 21:27:14 +000087int spi_prettyprint_status_register_bp2_bpl(struct flashctx *flash);
Ben Gardnerbcf61092015-11-22 02:23:31 +000088int spi_prettyprint_status_register_bp2_tb_bpl(struct flashctx *flash);
Stefan Tauner6ee37e22012-12-29 15:03:51 +000089int spi_disable_blockprotect(struct flashctx *flash);
Stefan Taunera60d4082014-06-04 16:17:03 +000090int spi_disable_blockprotect_bp1_srwd(struct flashctx *flash);
Stefan Tauner278ba6e2013-06-28 21:28:27 +000091int spi_disable_blockprotect_bp2_srwd(struct flashctx *flash);
92int spi_disable_blockprotect_bp3_srwd(struct flashctx *flash);
93int spi_disable_blockprotect_bp4_srwd(struct flashctx *flash);
Stefan Tauner6ee37e22012-12-29 15:03:51 +000094int spi_prettyprint_status_register_amic_a25l032(struct flashctx *flash);
95int spi_prettyprint_status_register_at25df(struct flashctx *flash);
96int spi_prettyprint_status_register_at25df_sec(struct flashctx *flash);
Stefan Tauner57794ac2012-12-29 15:04:20 +000097int spi_prettyprint_status_register_at25f(struct flashctx *flash);
98int spi_prettyprint_status_register_at25f512a(struct flashctx *flash);
Stefan Tauner6ee37e22012-12-29 15:03:51 +000099int spi_prettyprint_status_register_at25f512b(struct flashctx *flash);
Stefan Tauner57794ac2012-12-29 15:04:20 +0000100int spi_prettyprint_status_register_at25f4096(struct flashctx *flash);
Stefan Tauner6ee37e22012-12-29 15:03:51 +0000101int spi_prettyprint_status_register_at25fs010(struct flashctx *flash);
102int spi_prettyprint_status_register_at25fs040(struct flashctx *flash);
103int spi_prettyprint_status_register_at26df081a(struct flashctx *flash);
Stefan Taunercecb2c52013-06-20 22:55:41 +0000104int spi_disable_blockprotect_at2x_global_unprotect(struct flashctx *flash);
105int spi_disable_blockprotect_at2x_global_unprotect_sec(struct flashctx *flash);
Stefan Tauner57794ac2012-12-29 15:04:20 +0000106int spi_disable_blockprotect_at25f(struct flashctx *flash);
107int spi_disable_blockprotect_at25f512a(struct flashctx *flash);
Stefan Tauner6ee37e22012-12-29 15:03:51 +0000108int spi_disable_blockprotect_at25f512b(struct flashctx *flash);
109int spi_disable_blockprotect_at25fs010(struct flashctx *flash);
110int spi_disable_blockprotect_at25fs040(struct flashctx *flash);
Nikolay Nikolaevd0e3ea12013-06-28 21:29:08 +0000111int spi_prettyprint_status_register_en25s_wp(struct flashctx *flash);
Nikolay Nikolaev6f59b0b2013-06-28 21:29:51 +0000112int spi_prettyprint_status_register_n25q(struct flashctx *flash);
113int spi_disable_blockprotect_n25q(struct flashctx *flash);
Nikolay Nikolaevc80c4a32013-06-28 21:29:44 +0000114int spi_prettyprint_status_register_bp2_ep_srwd(struct flashctx *flash);
115int spi_disable_blockprotect_bp2_ep_srwd(struct flashctx *flash);
Stefan Tauner6ee37e22012-12-29 15:03:51 +0000116int spi_prettyprint_status_register_sst25(struct flashctx *flash);
117int spi_prettyprint_status_register_sst25vf016(struct flashctx *flash);
118int spi_prettyprint_status_register_sst25vf040b(struct flashctx *flash);
Wei Hu25584de2018-04-30 14:02:08 -0700119int spi_disable_blockprotect_sst26_global_unprotect(struct flashctx *flash);
Stefan Tauner6ee37e22012-12-29 15:03:51 +0000120
Stefan Taunerac1b4c82012-02-17 14:51:04 +0000121/* sfdp.c */
122int probe_spi_sfdp(struct flashctx *flash);
123
Carl-Daniel Hailfinger532c7172011-11-04 21:35:26 +0000124/* opaque.c */
Carl-Daniel Hailfinger63fd9022011-12-14 22:25:15 +0000125int probe_opaque(struct flashctx *flash);
126int read_opaque(struct flashctx *flash, uint8_t *buf, unsigned int start, unsigned int len);
Mark Marshallf20b7be2014-05-09 21:16:21 +0000127int write_opaque(struct flashctx *flash, const uint8_t *buf, unsigned int start, unsigned int len);
Carl-Daniel Hailfinger63fd9022011-12-14 22:25:15 +0000128int erase_opaque(struct flashctx *flash, unsigned int blockaddr, unsigned int blocklen);
Carl-Daniel Hailfinger532c7172011-11-04 21:35:26 +0000129
Aidan Thorntondb4e87d2013-08-27 18:01:53 +0000130/* at45db.c */
131int probe_spi_at45db(struct flashctx *flash);
132int spi_prettyprint_status_register_at45db(struct flashctx *flash);
133int spi_disable_blockprotect_at45db(struct flashctx *flash);
134int spi_read_at45db(struct flashctx *flash, uint8_t *buf, unsigned int start, unsigned int len);
Stefan Taunerfdc4f7e2013-08-27 18:02:12 +0000135int spi_read_at45db_e8(struct flashctx *flash, uint8_t *buf, unsigned int start, unsigned int len);
Mark Marshallf20b7be2014-05-09 21:16:21 +0000136int spi_write_at45db(struct flashctx *flash, const uint8_t *buf, unsigned int start, unsigned int len);
Aidan Thorntondb4e87d2013-08-27 18:01:53 +0000137int spi_erase_at45db_page(struct flashctx *flash, unsigned int addr, unsigned int blocklen);
138int spi_erase_at45db_block(struct flashctx *flash, unsigned int addr, unsigned int blocklen);
139int spi_erase_at45db_sector(struct flashctx *flash, unsigned int addr, unsigned int blocklen);
140int spi_erase_at45db_chip(struct flashctx *flash, unsigned int addr, unsigned int blocklen);
Stefan Tauner1dd5d3a2013-08-27 18:02:19 +0000141int spi_erase_at45cs_sector(struct flashctx *flash, unsigned int addr, unsigned int blocklen);
Aidan Thorntondb4e87d2013-08-27 18:01:53 +0000142
Carl-Daniel Hailfinger5d5c0722009-12-14 03:32:24 +0000143/* 82802ab.c */
Carl-Daniel Hailfinger63fd9022011-12-14 22:25:15 +0000144uint8_t wait_82802ab(struct flashctx *flash);
145int probe_82802ab(struct flashctx *flash);
146int erase_block_82802ab(struct flashctx *flash, unsigned int page, unsigned int pagesize);
Mark Marshallf20b7be2014-05-09 21:16:21 +0000147int write_82802ab(struct flashctx *flash, const uint8_t *buf, unsigned int start, unsigned int len);
Sean Nelson28accc22010-03-19 18:47:06 +0000148void print_status_82802ab(uint8_t status);
Carl-Daniel Hailfinger63fd9022011-12-14 22:25:15 +0000149int unlock_28f004s5(struct flashctx *flash);
150int unlock_lh28f008bjt(struct flashctx *flash);
Carl-Daniel Hailfinger5d5c0722009-12-14 03:32:24 +0000151
Carl-Daniel Hailfinger5d5c0722009-12-14 03:32:24 +0000152/* jedec.c */
153uint8_t oddparity(uint8_t val);
Stefan Tauner0ab1e5d2014-05-29 11:51:24 +0000154void toggle_ready_jedec(const struct flashctx *flash, chipaddr dst);
155void data_polling_jedec(const struct flashctx *flash, chipaddr dst, uint8_t data);
Carl-Daniel Hailfinger63fd9022011-12-14 22:25:15 +0000156int probe_jedec(struct flashctx *flash);
Stefan Tauner03a9c3c2014-08-03 14:15:14 +0000157int probe_jedec_29gl(struct flashctx *flash);
Mark Marshallf20b7be2014-05-09 21:16:21 +0000158int write_jedec(struct flashctx *flash, const uint8_t *buf, unsigned int start, unsigned int len);
159int write_jedec_1(struct flashctx *flash, const uint8_t *buf, unsigned int start, unsigned int len);
Carl-Daniel Hailfinger63fd9022011-12-14 22:25:15 +0000160int erase_sector_jedec(struct flashctx *flash, unsigned int page, unsigned int pagesize);
161int erase_block_jedec(struct flashctx *flash, unsigned int page, unsigned int blocksize);
162int erase_chip_block_jedec(struct flashctx *flash, unsigned int page, unsigned int blocksize);
Carl-Daniel Hailfinger5d5c0722009-12-14 03:32:24 +0000163
Carl-Daniel Hailfingeref3ac8a2014-08-03 13:05:34 +0000164int unlock_regspace2_uniform_32k(struct flashctx *flash);
165int unlock_regspace2_uniform_64k(struct flashctx *flash);
166int unlock_regspace2_block_eraser_0(struct flashctx *flash);
167int unlock_regspace2_block_eraser_1(struct flashctx *flash);
Carl-Daniel Hailfingeref3ac8a2014-08-03 13:05:34 +0000168int printlock_regspace2_uniform_64k(struct flashctx *flash);
169int printlock_regspace2_block_eraser_0(struct flashctx *flash);
170int printlock_regspace2_block_eraser_1(struct flashctx *flash);
171
Carl-Daniel Hailfinger5d5c0722009-12-14 03:32:24 +0000172/* sst28sf040.c */
Carl-Daniel Hailfinger63fd9022011-12-14 22:25:15 +0000173int erase_chip_28sf040(struct flashctx *flash, unsigned int addr, unsigned int blocklen);
174int erase_sector_28sf040(struct flashctx *flash, unsigned int address, unsigned int sector_size);
Edward O'Callaghand1fbc462020-12-19 11:57:30 +1100175int write_28sf040(struct flashctx *flash, const uint8_t *buf, unsigned int start, unsigned int len);
Carl-Daniel Hailfinger63fd9022011-12-14 22:25:15 +0000176int unprotect_28sf040(struct flashctx *flash);
177int protect_28sf040(struct flashctx *flash);
Carl-Daniel Hailfinger5d5c0722009-12-14 03:32:24 +0000178
Carl-Daniel Hailfinger5d5c0722009-12-14 03:32:24 +0000179/* sst49lfxxxc.c */
Carl-Daniel Hailfinger63fd9022011-12-14 22:25:15 +0000180int erase_sector_49lfxxxc(struct flashctx *flash, unsigned int address, unsigned int sector_size);
Carl-Daniel Hailfinger5d5c0722009-12-14 03:32:24 +0000181
182/* sst_fwhub.c */
Carl-Daniel Hailfinger63fd9022011-12-14 22:25:15 +0000183int printlock_sst_fwhub(struct flashctx *flash);
184int unlock_sst_fwhub(struct flashctx *flash);
Carl-Daniel Hailfinger5d5c0722009-12-14 03:32:24 +0000185
Carl-Daniel Hailfinger91882402010-12-05 16:33:59 +0000186/* w39.c */
Kyösti Mälkkic31243e2012-10-28 01:50:08 +0000187int printlock_w39f010(struct flashctx * flash);
188int printlock_w39l010(struct flashctx * flash);
189int printlock_w39l020(struct flashctx * flash);
Carl-Daniel Hailfinger63fd9022011-12-14 22:25:15 +0000190int printlock_w39l040(struct flashctx * flash);
191int printlock_w39v040a(struct flashctx *flash);
192int printlock_w39v040b(struct flashctx *flash);
193int printlock_w39v040c(struct flashctx *flash);
194int printlock_w39v040fa(struct flashctx *flash);
195int printlock_w39v040fb(struct flashctx *flash);
196int printlock_w39v040fc(struct flashctx *flash);
197int printlock_w39v080a(struct flashctx *flash);
198int printlock_w39v080fa(struct flashctx *flash);
199int printlock_w39v080fa_dual(struct flashctx *flash);
David Borgf5a30f62012-04-15 13:16:32 +0000200int printlock_at49f(struct flashctx *flash);
Carl-Daniel Hailfinger5d5c0722009-12-14 03:32:24 +0000201
202/* w29ee011.c */
Carl-Daniel Hailfinger63fd9022011-12-14 22:25:15 +0000203int probe_w29ee011(struct flashctx *flash);
Carl-Daniel Hailfinger5d5c0722009-12-14 03:32:24 +0000204
Stefan Tauner4404f732013-09-12 08:28:56 +0000205/* stm50.c */
206int erase_sector_stm50(struct flashctx *flash, unsigned int block, unsigned int blocksize);
Carl-Daniel Hailfinger5d5c0722009-12-14 03:32:24 +0000207
Rudolf Marek47eff6b2012-04-14 22:51:40 +0000208/* en29lv640b.c */
209int probe_en29lv640b(struct flashctx *flash);
Mark Marshallf20b7be2014-05-09 21:16:21 +0000210int write_en29lv640b(struct flashctx *flash, const uint8_t *buf, unsigned int start, unsigned int len);
Rudolf Marek47eff6b2012-04-14 22:51:40 +0000211
Paul Kocialkowski80ae14e2018-01-15 01:07:46 +0300212/* edi.c */
213int edi_chip_block_erase(struct flashctx *flash, unsigned int page, unsigned int size);
214int edi_chip_write(struct flashctx *flash, const uint8_t *buf, unsigned int start, unsigned int len);
215int edi_chip_read(struct flashctx *flash, uint8_t *buf, unsigned int start, unsigned int len);
216int edi_probe_kb9012(struct flashctx *flash);
217
Konstantin Grudnev3d8868c2019-07-23 00:48:54 +0300218/* spi95.c */
219int probe_spi_st95(struct flashctx *flash);
220int spi_block_erase_emulation(struct flashctx *flash, unsigned int addr, unsigned int blocklen);
221
Nikolai Artemievc9feb1b2021-10-21 01:35:13 +1100222/* writeprotect_ranges.c */
223void decode_range_spi25(size_t *start, size_t *len, const struct wp_bits *, size_t chip_len);
Sergii Dmytruk39687ac2022-07-25 00:23:25 +0300224void decode_range_spi25_64k_block(size_t *start, size_t *len, const struct wp_bits *, size_t chip_len);
225void decode_range_spi25_bit_cmp(size_t *start, size_t *len, const struct wp_bits *, size_t chip_len);
226void decode_range_spi25_2x_block(size_t *start, size_t *len, const struct wp_bits *, size_t chip_len);
Nikolai Artemievc9feb1b2021-10-21 01:35:13 +1100227
Nico Huber0e76d992023-01-12 20:22:55 +0100228/* memory_bus.c */
Nico Huber9eec4072023-01-12 01:17:30 +0100229int prepare_memory_access(struct flashctx *, enum preparation_steps);
Nico Huberb1974022023-01-12 13:13:12 +0100230int prepare_memory_register_access(struct flashctx *, enum preparation_steps);
Nico Huber9eec4072023-01-12 01:17:30 +0100231void finish_memory_access(struct flashctx *);
232
Carl-Daniel Hailfinger5d5c0722009-12-14 03:32:24 +0000233#endif /* !__CHIPDRIVERS_H__ */