2 * gpio_cfi_flash.c - GPIO-assisted Flash Chip Support
4 * Copyright (c) 2009 Analog Devices Inc.
6 * Licensed under the GPL-2 or later.
10 #include <asm/blackfin.h>
13 #include "gpio_cfi_flash.h"
15 #define GPIO_PIN_1 GPIO_PF4
16 #define GPIO_MASK_1 (1 << 21)
17 #define GPIO_PIN_2 GPIO_PF5
18 #define GPIO_MASK_2 (1 << 22)
19 #define GPIO_MASK (GPIO_MASK_1 | GPIO_MASK_2)
21 void *gpio_cfi_flash_swizzle(void *vaddr)
23 unsigned long addr = (unsigned long)vaddr;
25 gpio_set_value(GPIO_PIN_1, addr & GPIO_MASK_1);
28 gpio_set_value(GPIO_PIN_2, addr & GPIO_MASK_2);
33 return (void *)(addr & ~GPIO_MASK);
36 #define __raw_writeq(value, addr) *(volatile u64 *)addr = value
37 #define __raw_readq(addr) *(volatile u64 *)addr
39 #define MAKE_FLASH(size, sfx) \
40 void flash_write##size(u##size value, void *addr) \
42 __raw_write##sfx(value, gpio_cfi_flash_swizzle(addr)); \
44 u##size flash_read##size(void *addr) \
46 return __raw_read##sfx(gpio_cfi_flash_swizzle(addr)); \
48 MAKE_FLASH(8, b) /* flash_write8() flash_read8() */
49 MAKE_FLASH(16, w) /* flash_write16() flash_read16() */
50 MAKE_FLASH(32, l) /* flash_write32() flash_read32() */
51 MAKE_FLASH(64, q) /* flash_write64() flash_read64() */
53 void gpio_cfi_flash_init(void)
55 gpio_request(GPIO_PIN_1, "gpio_cfi_flash");
57 gpio_request(GPIO_PIN_2, "gpio_cfi_flash");
59 gpio_cfi_flash_swizzle((void *)CONFIG_SYS_FLASH_BASE);