blob: 416c6895003dfad5382915a4f9d84576c839d0c4 [file] [log] [blame]
Harald Krapfenbauerf4376602009-08-20 19:20:41 -04001/*
2 * gpio_cfi_flash.c - GPIO-assisted Flash Chip Support
3 *
4 * Copyright (c) 2009 Analog Devices Inc.
5 *
6 * Licensed under the GPL-2 or later.
7 */
8
9#include <common.h>
10#include <asm/blackfin.h>
Mike Frysingere81aa9e2010-06-02 05:22:16 -040011#include <asm/gpio.h>
Harald Krapfenbauerf4376602009-08-20 19:20:41 -040012#include <asm/io.h>
13#include "gpio_cfi_flash.h"
14
Mike Frysingere81aa9e2010-06-02 05:22:16 -040015#define GPIO_PIN_1 GPIO_PH0
Harald Krapfenbauerf4376602009-08-20 19:20:41 -040016#define GPIO_MASK_1 (1 << 21)
17#define GPIO_MASK (GPIO_MASK_1)
18
19void *gpio_cfi_flash_swizzle(void *vaddr)
20{
21 unsigned long addr = (unsigned long)vaddr;
22
Mike Frysingere81aa9e2010-06-02 05:22:16 -040023 gpio_set_value(GPIO_PIN_1, addr & GPIO_MASK_1);
Harald Krapfenbauerf4376602009-08-20 19:20:41 -040024
25#ifdef GPIO_MASK_2
Mike Frysingere81aa9e2010-06-02 05:22:16 -040026 gpio_set_value(GPIO_PIN_2, addr & GPIO_MASK_2);
Harald Krapfenbauerf4376602009-08-20 19:20:41 -040027#endif
28
29 SSYNC();
30
31 return (void *)(addr & ~GPIO_MASK);
32}
33
34#define __raw_writeq(value, addr) *(volatile u64 *)addr = value
35#define __raw_readq(addr) *(volatile u64 *)addr
36
37#define MAKE_FLASH(size, sfx) \
38void flash_write##size(u##size value, void *addr) \
39{ \
40 __raw_write##sfx(value, gpio_cfi_flash_swizzle(addr)); \
41} \
42u##size flash_read##size(void *addr) \
43{ \
44 return __raw_read##sfx(gpio_cfi_flash_swizzle(addr)); \
45}
46MAKE_FLASH(8, b) /* flash_write8() flash_read8() */
47MAKE_FLASH(16, w) /* flash_write16() flash_read16() */
48MAKE_FLASH(32, l) /* flash_write32() flash_read32() */
49MAKE_FLASH(64, q) /* flash_write64() flash_read64() */
50
51void gpio_cfi_flash_init(void)
52{
Mike Frysingere81aa9e2010-06-02 05:22:16 -040053 gpio_request(GPIO_PIN_1, "gpio_cfi_flash");
54#ifdef GPIO_MASK_2
55 gpio_request(GPIO_PIN_2, "gpio_cfi_flash");
56#endif
Harald Krapfenbauerf4376602009-08-20 19:20:41 -040057 gpio_cfi_flash_swizzle((void *)CONFIG_SYS_FLASH_BASE);
58}