2 * gpio_cfi_flash.c - GPIO-assisted Flash Chip Support
4 * Copyright (c) 2009-2010 Analog Devices Inc.
6 * Licensed under the GPL-2 or later.
10 #include <asm/blackfin.h>
13 #include "gpio_cfi_flash.h"
15 /* Allow this driver to be shared among boards */
17 #define GPIO_PIN_1 GPIO_PF4
19 #define GPIO_MASK_1 (1 << 21)
21 #define GPIO_MASK_2 (0)
23 #define GPIO_MASK_2 (1 << 22)
26 #define GPIO_MASK_3 (0)
28 #define GPIO_MASK_3 (1 << 23)
30 #define GPIO_MASK (GPIO_MASK_1 | GPIO_MASK_2 | GPIO_MASK_3)
32 void *gpio_cfi_flash_swizzle(void *vaddr)
34 unsigned long addr = (unsigned long)vaddr;
36 gpio_set_value(GPIO_PIN_1, addr & GPIO_MASK_1);
39 gpio_set_value(GPIO_PIN_2, addr & GPIO_MASK_2);
43 gpio_set_value(GPIO_PIN_3, addr & GPIO_MASK_3);
49 return (void *)(addr & ~GPIO_MASK);
52 #define __raw_writeq(value, addr) *(volatile u64 *)addr = value
53 #define __raw_readq(addr) *(volatile u64 *)addr
55 #define MAKE_FLASH(size, sfx) \
56 void flash_write##size(u##size value, void *addr) \
58 __raw_write##sfx(value, gpio_cfi_flash_swizzle(addr)); \
60 u##size flash_read##size(void *addr) \
62 return __raw_read##sfx(gpio_cfi_flash_swizzle(addr)); \
64 MAKE_FLASH(8, b) /* flash_write8() flash_read8() */
65 MAKE_FLASH(16, w) /* flash_write16() flash_read16() */
66 MAKE_FLASH(32, l) /* flash_write32() flash_read32() */
67 MAKE_FLASH(64, q) /* flash_write64() flash_read64() */
69 void gpio_cfi_flash_init(void)
71 gpio_request(GPIO_PIN_1, "gpio_cfi_flash");
72 gpio_direction_output(GPIO_PIN_1, 0);
74 gpio_request(GPIO_PIN_2, "gpio_cfi_flash");
75 gpio_direction_output(GPIO_PIN_2, 0);
78 gpio_request(GPIO_PIN_3, "gpio_cfi_flash");
79 gpio_direction_output(GPIO_PIN_3, 0);