Nikolay Petukhov | 4784c47 | 2008-05-17 01:08:58 +0000 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the flashrom project. |
| 3 | * |
| 4 | * Copyright (C) 2004 Tyan Corporation |
| 5 | * Copyright (C) 2007 Nikolay Petukhov <nikolay.petukhov@gmail.com> |
| 6 | * Copyright (C) 2007 Reinder E.N. de Haan <lb_reha@mveas.com> |
| 7 | * |
| 8 | * This program is free software; you can redistribute it and/or modify |
| 9 | * it under the terms of the GNU General Public License as published by |
| 10 | * the Free Software Foundation; either version 2 of the License, or |
| 11 | * (at your option) any later version. |
| 12 | * |
| 13 | * This program is distributed in the hope that it will be useful, |
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | * GNU General Public License for more details. |
| 17 | * |
| 18 | * You should have received a copy of the GNU General Public License |
| 19 | * along with this program; if not, write to the Free Software |
| 20 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
| 21 | */ |
| 22 | |
Nikolay Petukhov | 4784c47 | 2008-05-17 01:08:58 +0000 | [diff] [blame] | 23 | #include "flash.h" |
| 24 | |
Carl-Daniel Hailfinger | 8a3c60c | 2011-12-18 15:01:24 +0000 | [diff] [blame^] | 25 | static void write_lockbits_49fl00x(const struct flashctx *flash, |
| 26 | unsigned int size, unsigned char bits, |
| 27 | unsigned int block_size) |
Nikolay Petukhov | 4784c47 | 2008-05-17 01:08:58 +0000 | [diff] [blame] | 28 | { |
Stefan Tauner | c69c9c8 | 2011-11-23 09:13:48 +0000 | [diff] [blame] | 29 | unsigned int i, left = size; |
Carl-Daniel Hailfinger | 8a3c60c | 2011-12-18 15:01:24 +0000 | [diff] [blame^] | 30 | chipaddr bios = flash->virtual_registers; |
Nikolay Petukhov | 4784c47 | 2008-05-17 01:08:58 +0000 | [diff] [blame] | 31 | |
| 32 | for (i = 0; left >= block_size; i++, left -= block_size) { |
Nikolay Petukhov | 4784c47 | 2008-05-17 01:08:58 +0000 | [diff] [blame] | 33 | /* pm49fl002 */ |
Uwe Hermann | 394131e | 2008-10-18 21:14:13 +0000 | [diff] [blame] | 34 | if (block_size == 16384 && i % 2) |
Nikolay Petukhov | 4784c47 | 2008-05-17 01:08:58 +0000 | [diff] [blame] | 35 | continue; |
| 36 | |
Carl-Daniel Hailfinger | 8a3c60c | 2011-12-18 15:01:24 +0000 | [diff] [blame^] | 37 | chip_writeb(flash, bits, bios + (i * block_size) + 2); |
Nikolay Petukhov | 4784c47 | 2008-05-17 01:08:58 +0000 | [diff] [blame] | 38 | } |
| 39 | } |
| 40 | |
Carl-Daniel Hailfinger | 63fd902 | 2011-12-14 22:25:15 +0000 | [diff] [blame] | 41 | int unlock_49fl00x(struct flashctx *flash) |
Sean Nelson | 6e0b912 | 2010-02-19 00:52:10 +0000 | [diff] [blame] | 42 | { |
Carl-Daniel Hailfinger | 8a3c60c | 2011-12-18 15:01:24 +0000 | [diff] [blame^] | 43 | write_lockbits_49fl00x(flash, flash->total_size * 1024, 0, |
| 44 | flash->page_size); |
Sean Nelson | 6e0b912 | 2010-02-19 00:52:10 +0000 | [diff] [blame] | 45 | return 0; |
| 46 | } |
| 47 | |
Carl-Daniel Hailfinger | 63fd902 | 2011-12-14 22:25:15 +0000 | [diff] [blame] | 48 | int lock_49fl00x(struct flashctx *flash) |
Sean Nelson | 3617234 | 2010-02-27 18:01:15 +0000 | [diff] [blame] | 49 | { |
Carl-Daniel Hailfinger | 8a3c60c | 2011-12-18 15:01:24 +0000 | [diff] [blame^] | 50 | write_lockbits_49fl00x(flash, flash->total_size * 1024, 1, |
| 51 | flash->page_size); |
Sean Nelson | 3617234 | 2010-02-27 18:01:15 +0000 | [diff] [blame] | 52 | return 0; |
| 53 | } |