blob: 1075cc41127dabd31f54964a8ca095068a06b1d9 [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
Peter Meerwaldbf203852010-09-17 13:02:42 -040025#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)
Mike Frysingerd014e352008-10-12 21:41:06 -040031
32void *gpio_cfi_flash_swizzle(void *vaddr)
33{
34 unsigned long addr = (unsigned long)vaddr;
35
Mike Frysingere81aa9e2010-06-02 05:22:16 -040036 gpio_set_value(GPIO_PIN_1, addr & GPIO_MASK_1);
Mike Frysingerd014e352008-10-12 21:41:06 -040037
Mike Frysinger2ff0a302010-07-24 03:54:19 -040038#ifdef GPIO_PIN_2
Mike Frysingere81aa9e2010-06-02 05:22:16 -040039 gpio_set_value(GPIO_PIN_2, addr & GPIO_MASK_2);
Mike Frysingerd014e352008-10-12 21:41:06 -040040#endif
41
Peter Meerwaldbf203852010-09-17 13:02:42 -040042#ifdef GPIO_PIN_3
43 gpio_set_value(GPIO_PIN_3, addr & GPIO_MASK_3);
44#endif
45
Mike Frysingerd014e352008-10-12 21:41:06 -040046 SSYNC();
Mike Frysinger2ff0a302010-07-24 03:54:19 -040047 udelay(1);
Mike Frysingerd014e352008-10-12 21:41:06 -040048
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) \
56void flash_write##size(u##size value, void *addr) \
57{ \
58 __raw_write##sfx(value, gpio_cfi_flash_swizzle(addr)); \
59} \
60u##size flash_read##size(void *addr) \
61{ \
62 return __raw_read##sfx(gpio_cfi_flash_swizzle(addr)); \
63}
64MAKE_FLASH(8, b) /* flash_write8() flash_read8() */
Mike Frysingerce10f1b2009-08-20 19:17:59 -040065MAKE_FLASH(16, w) /* flash_write16() flash_read16() */
66MAKE_FLASH(32, l) /* flash_write32() flash_read32() */
67MAKE_FLASH(64, q) /* flash_write64() flash_read64() */
Mike Frysingerd014e352008-10-12 21:41:06 -040068
69void gpio_cfi_flash_init(void)
70{
Mike Frysingere81aa9e2010-06-02 05:22:16 -040071 gpio_request(GPIO_PIN_1, "gpio_cfi_flash");
Mike Frysinger2ff0a302010-07-24 03:54:19 -040072 gpio_direction_output(GPIO_PIN_1, 0);
73#ifdef GPIO_PIN_2
Mike Frysingere81aa9e2010-06-02 05:22:16 -040074 gpio_request(GPIO_PIN_2, "gpio_cfi_flash");
Mike Frysinger2ff0a302010-07-24 03:54:19 -040075 gpio_direction_output(GPIO_PIN_2, 0);
Mike Frysingere81aa9e2010-06-02 05:22:16 -040076#endif
Peter Meerwaldbf203852010-09-17 13:02:42 -040077#ifdef GPIO_PIN_3
78 gpio_request(GPIO_PIN_3, "gpio_cfi_flash");
79 gpio_direction_output(GPIO_PIN_3, 0);
80#endif
Mike Frysingerd014e352008-10-12 21:41:06 -040081}