Carl-Daniel Hailfinger | cc1802d | 2010-01-06 10:21:00 +0000 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the flashrom project. |
| 3 | * |
Carl-Daniel Hailfinger | 8a3c60c | 2011-12-18 15:01:24 +0000 | [diff] [blame^] | 4 | * Copyright (C) 2009,2010,2011 Carl-Daniel Hailfinger |
Carl-Daniel Hailfinger | cc1802d | 2010-01-06 10:21:00 +0000 | [diff] [blame] | 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" |
Carl-Daniel Hailfinger | eaacd2d | 2011-11-09 23:40:00 +0000 | [diff] [blame] | 22 | #include "programmer.h" |
| 23 | |
| 24 | static const struct par_programmer par_programmer_none = { |
| 25 | .chip_readb = noop_chip_readb, |
| 26 | .chip_readw = fallback_chip_readw, |
| 27 | .chip_readl = fallback_chip_readl, |
| 28 | .chip_readn = fallback_chip_readn, |
| 29 | .chip_writeb = noop_chip_writeb, |
| 30 | .chip_writew = fallback_chip_writew, |
| 31 | .chip_writel = fallback_chip_writel, |
| 32 | .chip_writen = fallback_chip_writen, |
| 33 | }; |
| 34 | |
| 35 | const struct par_programmer *par_programmer = &par_programmer_none; |
Carl-Daniel Hailfinger | cc1802d | 2010-01-06 10:21:00 +0000 | [diff] [blame] | 36 | |
| 37 | /* No-op shutdown() for programmers which don't need special handling */ |
| 38 | int noop_shutdown(void) |
| 39 | { |
| 40 | return 0; |
| 41 | } |
| 42 | |
| 43 | /* Fallback map() for programmers which don't need special handling */ |
| 44 | void *fallback_map(const char *descr, unsigned long phys_addr, size_t len) |
| 45 | { |
| 46 | /* FIXME: Should return phys_addr. */ |
Peter Huewe | 73f8ec8 | 2011-01-24 19:15:51 +0000 | [diff] [blame] | 47 | return NULL; |
Carl-Daniel Hailfinger | cc1802d | 2010-01-06 10:21:00 +0000 | [diff] [blame] | 48 | } |
| 49 | |
| 50 | /* No-op/fallback unmap() for programmers which don't need special handling */ |
| 51 | void fallback_unmap(void *virt_addr, size_t len) |
| 52 | { |
| 53 | } |
| 54 | |
| 55 | /* No-op chip_writeb() for drivers not supporting addr/data pair accesses */ |
Carl-Daniel Hailfinger | 8a3c60c | 2011-12-18 15:01:24 +0000 | [diff] [blame^] | 56 | uint8_t noop_chip_readb(const struct flashctx *flash, const chipaddr addr) |
Carl-Daniel Hailfinger | cc1802d | 2010-01-06 10:21:00 +0000 | [diff] [blame] | 57 | { |
| 58 | return 0xff; |
| 59 | } |
| 60 | |
| 61 | /* No-op chip_writeb() for drivers not supporting addr/data pair accesses */ |
Carl-Daniel Hailfinger | 8a3c60c | 2011-12-18 15:01:24 +0000 | [diff] [blame^] | 62 | void noop_chip_writeb(const struct flashctx *flash, uint8_t val, chipaddr addr) |
Carl-Daniel Hailfinger | cc1802d | 2010-01-06 10:21:00 +0000 | [diff] [blame] | 63 | { |
| 64 | } |
| 65 | |
| 66 | /* Little-endian fallback for drivers not supporting 16 bit accesses */ |
Carl-Daniel Hailfinger | 8a3c60c | 2011-12-18 15:01:24 +0000 | [diff] [blame^] | 67 | void fallback_chip_writew(const struct flashctx *flash, uint16_t val, |
| 68 | chipaddr addr) |
Carl-Daniel Hailfinger | cc1802d | 2010-01-06 10:21:00 +0000 | [diff] [blame] | 69 | { |
Carl-Daniel Hailfinger | 8a3c60c | 2011-12-18 15:01:24 +0000 | [diff] [blame^] | 70 | chip_writeb(flash, val & 0xff, addr); |
| 71 | chip_writeb(flash, (val >> 8) & 0xff, addr + 1); |
Carl-Daniel Hailfinger | cc1802d | 2010-01-06 10:21:00 +0000 | [diff] [blame] | 72 | } |
| 73 | |
| 74 | /* Little-endian fallback for drivers not supporting 16 bit accesses */ |
Carl-Daniel Hailfinger | 8a3c60c | 2011-12-18 15:01:24 +0000 | [diff] [blame^] | 75 | uint16_t fallback_chip_readw(const struct flashctx *flash, const chipaddr addr) |
Carl-Daniel Hailfinger | cc1802d | 2010-01-06 10:21:00 +0000 | [diff] [blame] | 76 | { |
| 77 | uint16_t val; |
Carl-Daniel Hailfinger | 8a3c60c | 2011-12-18 15:01:24 +0000 | [diff] [blame^] | 78 | val = chip_readb(flash, addr); |
| 79 | val |= chip_readb(flash, addr + 1) << 8; |
Carl-Daniel Hailfinger | cc1802d | 2010-01-06 10:21:00 +0000 | [diff] [blame] | 80 | return val; |
| 81 | } |
| 82 | |
| 83 | /* Little-endian fallback for drivers not supporting 32 bit accesses */ |
Carl-Daniel Hailfinger | 8a3c60c | 2011-12-18 15:01:24 +0000 | [diff] [blame^] | 84 | void fallback_chip_writel(const struct flashctx *flash, uint32_t val, |
| 85 | chipaddr addr) |
Carl-Daniel Hailfinger | cc1802d | 2010-01-06 10:21:00 +0000 | [diff] [blame] | 86 | { |
Carl-Daniel Hailfinger | 8a3c60c | 2011-12-18 15:01:24 +0000 | [diff] [blame^] | 87 | chip_writew(flash, val & 0xffff, addr); |
| 88 | chip_writew(flash, (val >> 16) & 0xffff, addr + 2); |
Carl-Daniel Hailfinger | cc1802d | 2010-01-06 10:21:00 +0000 | [diff] [blame] | 89 | } |
| 90 | |
| 91 | /* Little-endian fallback for drivers not supporting 32 bit accesses */ |
Carl-Daniel Hailfinger | 8a3c60c | 2011-12-18 15:01:24 +0000 | [diff] [blame^] | 92 | uint32_t fallback_chip_readl(const struct flashctx *flash, const chipaddr addr) |
Carl-Daniel Hailfinger | cc1802d | 2010-01-06 10:21:00 +0000 | [diff] [blame] | 93 | { |
| 94 | uint32_t val; |
Carl-Daniel Hailfinger | 8a3c60c | 2011-12-18 15:01:24 +0000 | [diff] [blame^] | 95 | val = chip_readw(flash, addr); |
| 96 | val |= chip_readw(flash, addr + 2) << 16; |
Carl-Daniel Hailfinger | cc1802d | 2010-01-06 10:21:00 +0000 | [diff] [blame] | 97 | return val; |
| 98 | } |
| 99 | |
Carl-Daniel Hailfinger | 8a3c60c | 2011-12-18 15:01:24 +0000 | [diff] [blame^] | 100 | void fallback_chip_writen(const struct flashctx *flash, uint8_t *buf, |
| 101 | chipaddr addr, size_t len) |
Carl-Daniel Hailfinger | cc1802d | 2010-01-06 10:21:00 +0000 | [diff] [blame] | 102 | { |
| 103 | size_t i; |
| 104 | for (i = 0; i < len; i++) |
Carl-Daniel Hailfinger | 8a3c60c | 2011-12-18 15:01:24 +0000 | [diff] [blame^] | 105 | chip_writeb(flash, buf[i], addr + i); |
Carl-Daniel Hailfinger | cc1802d | 2010-01-06 10:21:00 +0000 | [diff] [blame] | 106 | return; |
| 107 | } |
| 108 | |
Carl-Daniel Hailfinger | 8a3c60c | 2011-12-18 15:01:24 +0000 | [diff] [blame^] | 109 | void fallback_chip_readn(const struct flashctx *flash, uint8_t *buf, |
| 110 | chipaddr addr, size_t len) |
Carl-Daniel Hailfinger | cc1802d | 2010-01-06 10:21:00 +0000 | [diff] [blame] | 111 | { |
| 112 | size_t i; |
| 113 | for (i = 0; i < len; i++) |
Carl-Daniel Hailfinger | 8a3c60c | 2011-12-18 15:01:24 +0000 | [diff] [blame^] | 114 | buf[i] = chip_readb(flash, addr + i); |
Carl-Daniel Hailfinger | cc1802d | 2010-01-06 10:21:00 +0000 | [diff] [blame] | 115 | return; |
| 116 | } |
Carl-Daniel Hailfinger | eaacd2d | 2011-11-09 23:40:00 +0000 | [diff] [blame] | 117 | |
| 118 | void register_par_programmer(const struct par_programmer *pgm, const enum chipbustype buses) |
| 119 | { |
| 120 | par_programmer = pgm; |
| 121 | buses_supported |= buses; |
| 122 | } |