Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | #ifndef FWH_LOCK_H |
| 2 | #define FWH_LOCK_H |
| 3 | |
| 4 | |
| 5 | enum fwh_lock_state { |
| 6 | FWH_UNLOCKED = 0, |
| 7 | FWH_DENY_WRITE = 1, |
| 8 | FWH_IMMUTABLE = 2, |
| 9 | FWH_DENY_READ = 4, |
| 10 | }; |
| 11 | |
| 12 | struct fwh_xxlock_thunk { |
| 13 | enum fwh_lock_state val; |
| 14 | flstate_t state; |
| 15 | }; |
| 16 | |
| 17 | |
| 18 | #define FWH_XXLOCK_ONEBLOCK_LOCK ((struct fwh_xxlock_thunk){ FWH_DENY_WRITE, FL_LOCKING}) |
| 19 | #define FWH_XXLOCK_ONEBLOCK_UNLOCK ((struct fwh_xxlock_thunk){ FWH_UNLOCKED, FL_UNLOCKING}) |
| 20 | |
| 21 | /* |
| 22 | * This locking/unlock is specific to firmware hub parts. Only one |
| 23 | * is known that supports the Intel command set. Firmware |
| 24 | * hub parts cannot be interleaved as they are on the LPC bus |
| 25 | * so this code has not been tested with interleaved chips, |
| 26 | * and will likely fail in that context. |
| 27 | */ |
Thomas Gleixner | 1f948b4 | 2005-11-07 11:15:37 +0000 | [diff] [blame] | 28 | static int fwh_xxlock_oneblock(struct map_info *map, struct flchip *chip, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 29 | unsigned long adr, int len, void *thunk) |
| 30 | { |
| 31 | struct cfi_private *cfi = map->fldrv_priv; |
| 32 | struct fwh_xxlock_thunk *xxlt = (struct fwh_xxlock_thunk *)thunk; |
| 33 | int ret; |
| 34 | |
| 35 | /* Refuse the operation if the we cannot look behind the chip */ |
| 36 | if (chip->start < 0x400000) { |
Brian Norris | 289c052 | 2011-07-19 10:06:09 -0700 | [diff] [blame] | 37 | pr_debug( "MTD %s(): chip->start: %lx wanted >= 0x400000\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 38 | __func__, chip->start ); |
| 39 | return -EIO; |
| 40 | } |
| 41 | /* |
| 42 | * lock block registers: |
| 43 | * - on 64k boundariesand |
| 44 | * - bit 1 set high |
| 45 | * - block lock registers are 4MiB lower - overflow subtract (danger) |
Thomas Gleixner | 1f948b4 | 2005-11-07 11:15:37 +0000 | [diff] [blame] | 46 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 47 | * The address manipulation is first done on the logical address |
| 48 | * which is 0 at the start of the chip, and then the offset of |
| 49 | * the individual chip is addted to it. Any other order a weird |
| 50 | * map offset could cause problems. |
| 51 | */ |
| 52 | adr = (adr & ~0xffffUL) | 0x2; |
| 53 | adr += chip->start - 0x400000; |
| 54 | |
| 55 | /* |
| 56 | * This is easy because these are writes to registers and not writes |
| 57 | * to flash memory - that means that we don't have to check status |
| 58 | * and timeout. |
| 59 | */ |
Stefani Seibold | c4e7737 | 2010-04-18 22:46:44 +0200 | [diff] [blame] | 60 | mutex_lock(&chip->mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 61 | ret = get_chip(map, chip, adr, FL_LOCKING); |
| 62 | if (ret) { |
Stefani Seibold | c4e7737 | 2010-04-18 22:46:44 +0200 | [diff] [blame] | 63 | mutex_unlock(&chip->mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 64 | return ret; |
| 65 | } |
| 66 | |
Shashi Rao | e6be133 | 2007-03-28 15:56:28 -0700 | [diff] [blame] | 67 | chip->oldstate = chip->state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 68 | chip->state = xxlt->state; |
| 69 | map_write(map, CMD(xxlt->val), adr); |
| 70 | |
| 71 | /* Done and happy. */ |
Shashi Rao | e6be133 | 2007-03-28 15:56:28 -0700 | [diff] [blame] | 72 | chip->state = chip->oldstate; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 73 | put_chip(map, chip, adr); |
Stefani Seibold | c4e7737 | 2010-04-18 22:46:44 +0200 | [diff] [blame] | 74 | mutex_unlock(&chip->mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 75 | return 0; |
| 76 | } |
| 77 | |
| 78 | |
Adrian Hunter | 69423d9 | 2008-12-10 13:37:21 +0000 | [diff] [blame] | 79 | static int fwh_lock_varsize(struct mtd_info *mtd, loff_t ofs, uint64_t len) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 80 | { |
| 81 | int ret; |
| 82 | |
| 83 | ret = cfi_varsize_frob(mtd, fwh_xxlock_oneblock, ofs, len, |
| 84 | (void *)&FWH_XXLOCK_ONEBLOCK_LOCK); |
| 85 | |
| 86 | return ret; |
| 87 | } |
| 88 | |
| 89 | |
Adrian Hunter | 69423d9 | 2008-12-10 13:37:21 +0000 | [diff] [blame] | 90 | static int fwh_unlock_varsize(struct mtd_info *mtd, loff_t ofs, uint64_t len) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 91 | { |
| 92 | int ret; |
| 93 | |
| 94 | ret = cfi_varsize_frob(mtd, fwh_xxlock_oneblock, ofs, len, |
| 95 | (void *)&FWH_XXLOCK_ONEBLOCK_UNLOCK); |
Thomas Gleixner | 1f948b4 | 2005-11-07 11:15:37 +0000 | [diff] [blame] | 96 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 97 | return ret; |
| 98 | } |
| 99 | |
Guillaume LECERF | cc31822 | 2010-11-17 12:35:50 +0100 | [diff] [blame] | 100 | static void fixup_use_fwh_lock(struct mtd_info *mtd) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 101 | { |
| 102 | printk(KERN_NOTICE "using fwh lock/unlock method\n"); |
| 103 | /* Setup for the chips with the fwh lock method */ |
Artem Bityutskiy | 3c3c10b | 2012-01-30 14:58:32 +0200 | [diff] [blame] | 104 | mtd->_lock = fwh_lock_varsize; |
| 105 | mtd->_unlock = fwh_unlock_varsize; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 106 | } |
| 107 | #endif /* FWH_LOCK_H */ |