Carl-Daniel Hailfinger | cc1802d | 2010-01-06 10:21:00 +0000 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the flashrom project. |
| 3 | * |
| 4 | * Copyright (C) 2009,2010 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; 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 | * |
| 16 | * You should have received a copy of the GNU General Public License |
| 17 | * along with this program; if not, write to the Free Software |
| 18 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
| 19 | */ |
| 20 | |
Carl-Daniel Hailfinger | cc1802d | 2010-01-06 10:21:00 +0000 | [diff] [blame] | 21 | #include "flash.h" |
| 22 | |
| 23 | /* No-op shutdown() for programmers which don't need special handling */ |
| 24 | int noop_shutdown(void) |
| 25 | { |
| 26 | return 0; |
| 27 | } |
| 28 | |
| 29 | /* Fallback map() for programmers which don't need special handling */ |
| 30 | void *fallback_map(const char *descr, unsigned long phys_addr, size_t len) |
| 31 | { |
| 32 | /* FIXME: Should return phys_addr. */ |
Peter Huewe | 73f8ec8 | 2011-01-24 19:15:51 +0000 | [diff] [blame] | 33 | return NULL; |
Carl-Daniel Hailfinger | cc1802d | 2010-01-06 10:21:00 +0000 | [diff] [blame] | 34 | } |
| 35 | |
| 36 | /* No-op/fallback unmap() for programmers which don't need special handling */ |
| 37 | void fallback_unmap(void *virt_addr, size_t len) |
| 38 | { |
| 39 | } |
| 40 | |
| 41 | /* No-op chip_writeb() for drivers not supporting addr/data pair accesses */ |
| 42 | uint8_t noop_chip_readb(const chipaddr addr) |
| 43 | { |
| 44 | return 0xff; |
| 45 | } |
| 46 | |
| 47 | /* No-op chip_writeb() for drivers not supporting addr/data pair accesses */ |
| 48 | void noop_chip_writeb(uint8_t val, chipaddr addr) |
| 49 | { |
| 50 | } |
| 51 | |
| 52 | /* Little-endian fallback for drivers not supporting 16 bit accesses */ |
| 53 | void fallback_chip_writew(uint16_t val, chipaddr addr) |
| 54 | { |
| 55 | chip_writeb(val & 0xff, addr); |
| 56 | chip_writeb((val >> 8) & 0xff, addr + 1); |
| 57 | } |
| 58 | |
| 59 | /* Little-endian fallback for drivers not supporting 16 bit accesses */ |
| 60 | uint16_t fallback_chip_readw(const chipaddr addr) |
| 61 | { |
| 62 | uint16_t val; |
| 63 | val = chip_readb(addr); |
| 64 | val |= chip_readb(addr + 1) << 8; |
| 65 | return val; |
| 66 | } |
| 67 | |
| 68 | /* Little-endian fallback for drivers not supporting 32 bit accesses */ |
| 69 | void fallback_chip_writel(uint32_t val, chipaddr addr) |
| 70 | { |
| 71 | chip_writew(val & 0xffff, addr); |
| 72 | chip_writew((val >> 16) & 0xffff, addr + 2); |
| 73 | } |
| 74 | |
| 75 | /* Little-endian fallback for drivers not supporting 32 bit accesses */ |
| 76 | uint32_t fallback_chip_readl(const chipaddr addr) |
| 77 | { |
| 78 | uint32_t val; |
| 79 | val = chip_readw(addr); |
| 80 | val |= chip_readw(addr + 2) << 16; |
| 81 | return val; |
| 82 | } |
| 83 | |
| 84 | void fallback_chip_writen(uint8_t *buf, chipaddr addr, size_t len) |
| 85 | { |
| 86 | size_t i; |
| 87 | for (i = 0; i < len; i++) |
| 88 | chip_writeb(buf[i], addr + i); |
| 89 | return; |
| 90 | } |
| 91 | |
| 92 | void fallback_chip_readn(uint8_t *buf, chipaddr addr, size_t len) |
| 93 | { |
| 94 | size_t i; |
| 95 | for (i = 0; i < len; i++) |
| 96 | buf[i] = chip_readb(addr + i); |
| 97 | return; |
| 98 | } |