blob: ab6af81eac4dcbdfd20ae9770a439f26ebc377cb [file] [log] [blame]
Mike Frysingerd014e352008-10-12 21:41:06 -04001/*
2 * gpio_cfi_flash.c - GPIO-assisted Flash Chip Support
3 *
Mike Frysinger2ff0a302010-07-24 03:54:19 -04004 * Copyright (c) 2009-2010 Analog Devices Inc.
Mike Frysingerd014e352008-10-12 21:41:06 -04005 *
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>
Mike Frysingerd014e352008-10-12 21:41:06 -040012#include <asm/io.h>
13#include "gpio_cfi_flash.h"
14
Mike Frysinger2ff0a302010-07-24 03:54:19 -040015/* Allow this driver to be shared among boards */
16#ifndef GPIO_PIN_1
Mike Frysingere81aa9e2010-06-02 05:22:16 -040017#define GPIO_PIN_1 GPIO_PF4
Mike Frysinger2ff0a302010-07-24 03:54:19 -040018#endif
Mike Frysingerd014e352008-10-12 21:41:06 -040019#define GPIO_MASK_1 (1 << 21)
Mike Frysinger2ff0a302010-07-24 03:54:19 -040020#ifndef GPIO_PIN_2
21#define GPIO_MASK_2 (0)
22#else
23#define GPIO_MASK_2 (1 << 22)
24#endif
25#define GPIO_MASK (GPIO_MASK_1 | GPIO_MASK_2)
Mike Frysingerd014e352008-10-12 21:41:06 -040026
27void *gpio_cfi_flash_swizzle(void *vaddr)
28{
29 unsigned long addr = (unsigned long)vaddr;
30
Mike Frysingere81aa9e2010-06-02 05:22:16 -040031 gpio_set_value(GPIO_PIN_1, addr & GPIO_MASK_1);
Mike Frysingerd014e352008-10-12 21:41:06 -040032
Mike Frysinger2ff0a302010-07-24 03:54:19 -040033#ifdef GPIO_PIN_2
Mike Frysingere81aa9e2010-06-02 05:22:16 -040034 gpio_set_value(GPIO_PIN_2, addr & GPIO_MASK_2);
Mike Frysingerd014e352008-10-12 21:41:06 -040035#endif
36
37 SSYNC();
Mike Frysinger2ff0a302010-07-24 03:54:19 -040038 udelay(1);
Mike Frysingerd014e352008-10-12 21:41:06 -040039
40 return (void *)(addr & ~GPIO_MASK);
41}
42
43#define __raw_writeq(value, addr) *(volatile u64 *)addr = value
44#define __raw_readq(addr) *(volatile u64 *)addr
45
46#define MAKE_FLASH(size, sfx) \
47void flash_write##size(u##size value, void *addr) \
48{ \
49 __raw_write##sfx(value, gpio_cfi_flash_swizzle(addr)); \
50} \
51u##size flash_read##size(void *addr) \
52{ \
53 return __raw_read##sfx(gpio_cfi_flash_swizzle(addr)); \
54}
55MAKE_FLASH(8, b) /* flash_write8() flash_read8() */
Mike Frysingerce10f1b2009-08-20 19:17:59 -040056MAKE_FLASH(16, w) /* flash_write16() flash_read16() */
57MAKE_FLASH(32, l) /* flash_write32() flash_read32() */
58MAKE_FLASH(64, q) /* flash_write64() flash_read64() */
Mike Frysingerd014e352008-10-12 21:41:06 -040059
60void gpio_cfi_flash_init(void)
61{
Mike Frysingere81aa9e2010-06-02 05:22:16 -040062 gpio_request(GPIO_PIN_1, "gpio_cfi_flash");
Mike Frysinger2ff0a302010-07-24 03:54:19 -040063 gpio_direction_output(GPIO_PIN_1, 0);
64#ifdef GPIO_PIN_2
Mike Frysingere81aa9e2010-06-02 05:22:16 -040065 gpio_request(GPIO_PIN_2, "gpio_cfi_flash");
Mike Frysinger2ff0a302010-07-24 03:54:19 -040066 gpio_direction_output(GPIO_PIN_2, 0);
Mike Frysingere81aa9e2010-06-02 05:22:16 -040067#endif
Mike Frysingerd014e352008-10-12 21:41:06 -040068}