]> git.ipfire.org Git - people/ms/u-boot.git/blob - board/cm-bf537e/gpio_cfi_flash.c
drivers/crypto/fsl: fix endianness issue in RNG
[people/ms/u-boot.git] / board / cm-bf537e / gpio_cfi_flash.c
1 /*
2 * gpio_cfi_flash.c - GPIO-assisted Flash Chip Support
3 *
4 * Copyright (c) 2009-2010 Analog Devices Inc.
5 *
6 * Licensed under the GPL-2 or later.
7 */
8
9 #include <common.h>
10 #include <asm/blackfin.h>
11 #include <asm/gpio.h>
12 #include <asm/io.h>
13 #include "gpio_cfi_flash.h"
14
15 /* Allow this driver to be shared among boards */
16 #ifndef GPIO_PIN_1
17 #define GPIO_PIN_1 GPIO_PF4
18 #endif
19 #define GPIO_MASK_1 (1 << 21)
20 #ifndef GPIO_PIN_2
21 #define GPIO_MASK_2 (0)
22 #else
23 #define GPIO_MASK_2 (1 << 22)
24 #endif
25 #ifndef GPIO_PIN_3
26 #define GPIO_MASK_3 (0)
27 #else
28 #define GPIO_MASK_3 (1 << 23)
29 #endif
30 #define GPIO_MASK (GPIO_MASK_1 | GPIO_MASK_2 | GPIO_MASK_3)
31
32 void *gpio_cfi_flash_swizzle(void *vaddr)
33 {
34 unsigned long addr = (unsigned long)vaddr;
35
36 gpio_set_value(GPIO_PIN_1, addr & GPIO_MASK_1);
37
38 #ifdef GPIO_PIN_2
39 gpio_set_value(GPIO_PIN_2, addr & GPIO_MASK_2);
40 #endif
41
42 #ifdef GPIO_PIN_3
43 gpio_set_value(GPIO_PIN_3, addr & GPIO_MASK_3);
44 #endif
45
46 SSYNC();
47 udelay(1);
48
49 return (void *)(addr & ~GPIO_MASK);
50 }
51
52 #define __raw_writeq(value, addr) *(volatile u64 *)addr = value
53 #define __raw_readq(addr) *(volatile u64 *)addr
54
55 #define MAKE_FLASH(size, sfx) \
56 void flash_write##size(u##size value, void *addr) \
57 { \
58 __raw_write##sfx(value, gpio_cfi_flash_swizzle(addr)); \
59 } \
60 u##size flash_read##size(void *addr) \
61 { \
62 return __raw_read##sfx(gpio_cfi_flash_swizzle(addr)); \
63 }
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() */
68
69 void gpio_cfi_flash_init(void)
70 {
71 gpio_request(GPIO_PIN_1, "gpio_cfi_flash");
72 gpio_direction_output(GPIO_PIN_1, 0);
73 #ifdef GPIO_PIN_2
74 gpio_request(GPIO_PIN_2, "gpio_cfi_flash");
75 gpio_direction_output(GPIO_PIN_2, 0);
76 #endif
77 #ifdef GPIO_PIN_3
78 gpio_request(GPIO_PIN_3, "gpio_cfi_flash");
79 gpio_direction_output(GPIO_PIN_3, 0);
80 #endif
81 }