Mike Frysinger | d014e35 | 2008-10-12 21:41:06 -0400 | [diff] [blame] | 1 | /* |
| 2 | * gpio_cfi_flash.c - GPIO-assisted Flash Chip Support |
| 3 | * |
Mike Frysinger | 2ff0a30 | 2010-07-24 03:54:19 -0400 | [diff] [blame^] | 4 | * Copyright (c) 2009-2010 Analog Devices Inc. |
Mike Frysinger | d014e35 | 2008-10-12 21:41:06 -0400 | [diff] [blame] | 5 | * |
| 6 | * Licensed under the GPL-2 or later. |
| 7 | */ |
| 8 | |
| 9 | #include <common.h> |
| 10 | #include <asm/blackfin.h> |
Mike Frysinger | e81aa9e | 2010-06-02 05:22:16 -0400 | [diff] [blame] | 11 | #include <asm/gpio.h> |
Mike Frysinger | d014e35 | 2008-10-12 21:41:06 -0400 | [diff] [blame] | 12 | #include <asm/io.h> |
| 13 | #include "gpio_cfi_flash.h" |
| 14 | |
Mike Frysinger | 2ff0a30 | 2010-07-24 03:54:19 -0400 | [diff] [blame^] | 15 | /* Allow this driver to be shared among boards */ |
| 16 | #ifndef GPIO_PIN_1 |
Mike Frysinger | e81aa9e | 2010-06-02 05:22:16 -0400 | [diff] [blame] | 17 | #define GPIO_PIN_1 GPIO_PF4 |
Mike Frysinger | 2ff0a30 | 2010-07-24 03:54:19 -0400 | [diff] [blame^] | 18 | #endif |
Mike Frysinger | d014e35 | 2008-10-12 21:41:06 -0400 | [diff] [blame] | 19 | #define GPIO_MASK_1 (1 << 21) |
Mike Frysinger | 2ff0a30 | 2010-07-24 03:54:19 -0400 | [diff] [blame^] | 20 | #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 Frysinger | d014e35 | 2008-10-12 21:41:06 -0400 | [diff] [blame] | 26 | |
| 27 | void *gpio_cfi_flash_swizzle(void *vaddr) |
| 28 | { |
| 29 | unsigned long addr = (unsigned long)vaddr; |
| 30 | |
Mike Frysinger | e81aa9e | 2010-06-02 05:22:16 -0400 | [diff] [blame] | 31 | gpio_set_value(GPIO_PIN_1, addr & GPIO_MASK_1); |
Mike Frysinger | d014e35 | 2008-10-12 21:41:06 -0400 | [diff] [blame] | 32 | |
Mike Frysinger | 2ff0a30 | 2010-07-24 03:54:19 -0400 | [diff] [blame^] | 33 | #ifdef GPIO_PIN_2 |
Mike Frysinger | e81aa9e | 2010-06-02 05:22:16 -0400 | [diff] [blame] | 34 | gpio_set_value(GPIO_PIN_2, addr & GPIO_MASK_2); |
Mike Frysinger | d014e35 | 2008-10-12 21:41:06 -0400 | [diff] [blame] | 35 | #endif |
| 36 | |
| 37 | SSYNC(); |
Mike Frysinger | 2ff0a30 | 2010-07-24 03:54:19 -0400 | [diff] [blame^] | 38 | udelay(1); |
Mike Frysinger | d014e35 | 2008-10-12 21:41:06 -0400 | [diff] [blame] | 39 | |
| 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) \ |
| 47 | void flash_write##size(u##size value, void *addr) \ |
| 48 | { \ |
| 49 | __raw_write##sfx(value, gpio_cfi_flash_swizzle(addr)); \ |
| 50 | } \ |
| 51 | u##size flash_read##size(void *addr) \ |
| 52 | { \ |
| 53 | return __raw_read##sfx(gpio_cfi_flash_swizzle(addr)); \ |
| 54 | } |
| 55 | MAKE_FLASH(8, b) /* flash_write8() flash_read8() */ |
Mike Frysinger | ce10f1b | 2009-08-20 19:17:59 -0400 | [diff] [blame] | 56 | MAKE_FLASH(16, w) /* flash_write16() flash_read16() */ |
| 57 | MAKE_FLASH(32, l) /* flash_write32() flash_read32() */ |
| 58 | MAKE_FLASH(64, q) /* flash_write64() flash_read64() */ |
Mike Frysinger | d014e35 | 2008-10-12 21:41:06 -0400 | [diff] [blame] | 59 | |
| 60 | void gpio_cfi_flash_init(void) |
| 61 | { |
Mike Frysinger | e81aa9e | 2010-06-02 05:22:16 -0400 | [diff] [blame] | 62 | gpio_request(GPIO_PIN_1, "gpio_cfi_flash"); |
Mike Frysinger | 2ff0a30 | 2010-07-24 03:54:19 -0400 | [diff] [blame^] | 63 | gpio_direction_output(GPIO_PIN_1, 0); |
| 64 | #ifdef GPIO_PIN_2 |
Mike Frysinger | e81aa9e | 2010-06-02 05:22:16 -0400 | [diff] [blame] | 65 | gpio_request(GPIO_PIN_2, "gpio_cfi_flash"); |
Mike Frysinger | 2ff0a30 | 2010-07-24 03:54:19 -0400 | [diff] [blame^] | 66 | gpio_direction_output(GPIO_PIN_2, 0); |
Mike Frysinger | e81aa9e | 2010-06-02 05:22:16 -0400 | [diff] [blame] | 67 | #endif |
Mike Frysinger | d014e35 | 2008-10-12 21:41:06 -0400 | [diff] [blame] | 68 | } |