Blame view
board/cm-bf537e/gpio_cfi_flash.c
1.87 KB
8a9bab08a
|
1 2 3 |
/* * gpio_cfi_flash.c - GPIO-assisted Flash Chip Support * |
71dcc2c2b
|
4 |
* Copyright (c) 2009-2010 Analog Devices Inc. |
8a9bab08a
|
5 6 7 8 9 10 |
* * Licensed under the GPL-2 or later. */ #include <common.h> #include <asm/blackfin.h> |
570ba440e
|
11 |
#include <asm/gpio.h> |
8a9bab08a
|
12 13 |
#include <asm/io.h> #include "gpio_cfi_flash.h" |
71dcc2c2b
|
14 15 |
/* Allow this driver to be shared among boards */ #ifndef GPIO_PIN_1 |
570ba440e
|
16 |
#define GPIO_PIN_1 GPIO_PF4 |
71dcc2c2b
|
17 |
#endif |
8a9bab08a
|
18 |
#define GPIO_MASK_1 (1 << 21) |
71dcc2c2b
|
19 20 21 22 23 |
#ifndef GPIO_PIN_2 #define GPIO_MASK_2 (0) #else #define GPIO_MASK_2 (1 << 22) #endif |
68409f844
|
24 25 26 27 28 29 |
#ifndef GPIO_PIN_3 #define GPIO_MASK_3 (0) #else #define GPIO_MASK_3 (1 << 23) #endif #define GPIO_MASK (GPIO_MASK_1 | GPIO_MASK_2 | GPIO_MASK_3) |
8a9bab08a
|
30 31 32 33 |
void *gpio_cfi_flash_swizzle(void *vaddr) { unsigned long addr = (unsigned long)vaddr; |
570ba440e
|
34 |
gpio_set_value(GPIO_PIN_1, addr & GPIO_MASK_1); |
8a9bab08a
|
35 |
|
71dcc2c2b
|
36 |
#ifdef GPIO_PIN_2 |
570ba440e
|
37 |
gpio_set_value(GPIO_PIN_2, addr & GPIO_MASK_2); |
8a9bab08a
|
38 |
#endif |
68409f844
|
39 40 41 |
#ifdef GPIO_PIN_3 gpio_set_value(GPIO_PIN_3, addr & GPIO_MASK_3); #endif |
8a9bab08a
|
42 |
SSYNC(); |
71dcc2c2b
|
43 |
udelay(1); |
8a9bab08a
|
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
return (void *)(addr & ~GPIO_MASK); } #define __raw_writeq(value, addr) *(volatile u64 *)addr = value #define __raw_readq(addr) *(volatile u64 *)addr #define MAKE_FLASH(size, sfx) \ void flash_write##size(u##size value, void *addr) \ { \ __raw_write##sfx(value, gpio_cfi_flash_swizzle(addr)); \ } \ u##size flash_read##size(void *addr) \ { \ return __raw_read##sfx(gpio_cfi_flash_swizzle(addr)); \ } MAKE_FLASH(8, b) /* flash_write8() flash_read8() */ |
e637385e6
|
61 62 63 |
MAKE_FLASH(16, w) /* flash_write16() flash_read16() */ MAKE_FLASH(32, l) /* flash_write32() flash_read32() */ MAKE_FLASH(64, q) /* flash_write64() flash_read64() */ |
8a9bab08a
|
64 65 66 |
void gpio_cfi_flash_init(void) { |
570ba440e
|
67 |
gpio_request(GPIO_PIN_1, "gpio_cfi_flash"); |
71dcc2c2b
|
68 69 |
gpio_direction_output(GPIO_PIN_1, 0); #ifdef GPIO_PIN_2 |
570ba440e
|
70 |
gpio_request(GPIO_PIN_2, "gpio_cfi_flash"); |
71dcc2c2b
|
71 |
gpio_direction_output(GPIO_PIN_2, 0); |
570ba440e
|
72 |
#endif |
68409f844
|
73 74 75 76 |
#ifdef GPIO_PIN_3 gpio_request(GPIO_PIN_3, "gpio_cfi_flash"); gpio_direction_output(GPIO_PIN_3, 0); #endif |
8a9bab08a
|
77 |
} |