Mike Frysinger | 59e4be9 | 2008-10-12 21:55:45 -0400 | [diff] [blame] | 1 | /* |
| 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 Frysinger | 570ba44 | 2010-06-02 05:22:16 -0400 | [diff] [blame^] | 11 | #include <asm/gpio.h> |
Mike Frysinger | 59e4be9 | 2008-10-12 21:55:45 -0400 | [diff] [blame] | 12 | #include <asm/io.h> |
| 13 | #include "gpio_cfi_flash.h" |
| 14 | |
Mike Frysinger | 570ba44 | 2010-06-02 05:22:16 -0400 | [diff] [blame^] | 15 | #define GPIO_PIN_1 GPIO_PH9 |
Mike Frysinger | 59e4be9 | 2008-10-12 21:55:45 -0400 | [diff] [blame] | 16 | #define GPIO_MASK_1 (1 << 21) |
Mike Frysinger | 570ba44 | 2010-06-02 05:22:16 -0400 | [diff] [blame^] | 17 | #define GPIO_PIN_2 GPIO_PG11 |
Mike Frysinger | 59e4be9 | 2008-10-12 21:55:45 -0400 | [diff] [blame] | 18 | #define GPIO_MASK_2 (1 << 22) |
| 19 | #define GPIO_MASK (GPIO_MASK_1 | GPIO_MASK_2) |
| 20 | |
| 21 | void *gpio_cfi_flash_swizzle(void *vaddr) |
| 22 | { |
| 23 | unsigned long addr = (unsigned long)vaddr; |
| 24 | |
Mike Frysinger | 570ba44 | 2010-06-02 05:22:16 -0400 | [diff] [blame^] | 25 | gpio_set_value(GPIO_PIN_1, addr & GPIO_MASK_1); |
Mike Frysinger | 59e4be9 | 2008-10-12 21:55:45 -0400 | [diff] [blame] | 26 | |
| 27 | #ifdef GPIO_MASK_2 |
Mike Frysinger | 570ba44 | 2010-06-02 05:22:16 -0400 | [diff] [blame^] | 28 | gpio_set_value(GPIO_PIN_2, addr & GPIO_MASK_2); |
Mike Frysinger | 59e4be9 | 2008-10-12 21:55:45 -0400 | [diff] [blame] | 29 | #endif |
| 30 | |
| 31 | SSYNC(); |
| 32 | |
| 33 | return (void *)(addr & ~GPIO_MASK); |
| 34 | } |
| 35 | |
| 36 | #define __raw_writeq(value, addr) *(volatile u64 *)addr = value |
| 37 | #define __raw_readq(addr) *(volatile u64 *)addr |
| 38 | |
| 39 | #define MAKE_FLASH(size, sfx) \ |
| 40 | void flash_write##size(u##size value, void *addr) \ |
| 41 | { \ |
| 42 | __raw_write##sfx(value, gpio_cfi_flash_swizzle(addr)); \ |
| 43 | } \ |
| 44 | u##size flash_read##size(void *addr) \ |
| 45 | { \ |
| 46 | return __raw_read##sfx(gpio_cfi_flash_swizzle(addr)); \ |
| 47 | } |
| 48 | MAKE_FLASH(8, b) /* flash_write8() flash_read8() */ |
Mike Frysinger | e637385 | 2009-08-20 19:17:59 -0400 | [diff] [blame] | 49 | MAKE_FLASH(16, w) /* flash_write16() flash_read16() */ |
| 50 | MAKE_FLASH(32, l) /* flash_write32() flash_read32() */ |
| 51 | MAKE_FLASH(64, q) /* flash_write64() flash_read64() */ |
Mike Frysinger | 59e4be9 | 2008-10-12 21:55:45 -0400 | [diff] [blame] | 52 | |
| 53 | void gpio_cfi_flash_init(void) |
| 54 | { |
Mike Frysinger | 570ba44 | 2010-06-02 05:22:16 -0400 | [diff] [blame^] | 55 | gpio_request(GPIO_PIN_1, "gpio_cfi_flash"); |
| 56 | #ifdef GPIO_MASK_2 |
| 57 | gpio_request(GPIO_PIN_2, "gpio_cfi_flash"); |
| 58 | #endif |
Mike Frysinger | 59e4be9 | 2008-10-12 21:55:45 -0400 | [diff] [blame] | 59 | gpio_cfi_flash_swizzle((void *)CONFIG_SYS_FLASH_BASE); |
| 60 | } |