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 |
Peter Meerwald | bf20385 | 2010-09-17 13:02:42 -0400 | [diff] [blame] | 25 | #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 Frysinger | d014e35 | 2008-10-12 21:41:06 -0400 | [diff] [blame] | 31 | |
| 32 | void *gpio_cfi_flash_swizzle(void *vaddr) |
| 33 | { |
| 34 | unsigned long addr = (unsigned long)vaddr; |
| 35 | |
Mike Frysinger | e81aa9e | 2010-06-02 05:22:16 -0400 | [diff] [blame] | 36 | gpio_set_value(GPIO_PIN_1, addr & GPIO_MASK_1); |
Mike Frysinger | d014e35 | 2008-10-12 21:41:06 -0400 | [diff] [blame] | 37 | |
Mike Frysinger | 2ff0a30 | 2010-07-24 03:54:19 -0400 | [diff] [blame] | 38 | #ifdef GPIO_PIN_2 |
Mike Frysinger | e81aa9e | 2010-06-02 05:22:16 -0400 | [diff] [blame] | 39 | gpio_set_value(GPIO_PIN_2, addr & GPIO_MASK_2); |
Mike Frysinger | d014e35 | 2008-10-12 21:41:06 -0400 | [diff] [blame] | 40 | #endif |
| 41 | |
Peter Meerwald | bf20385 | 2010-09-17 13:02:42 -0400 | [diff] [blame] | 42 | #ifdef GPIO_PIN_3 |
| 43 | gpio_set_value(GPIO_PIN_3, addr & GPIO_MASK_3); |
| 44 | #endif |
| 45 | |
Mike Frysinger | d014e35 | 2008-10-12 21:41:06 -0400 | [diff] [blame] | 46 | SSYNC(); |
Mike Frysinger | 2ff0a30 | 2010-07-24 03:54:19 -0400 | [diff] [blame] | 47 | udelay(1); |
Mike Frysinger | d014e35 | 2008-10-12 21:41:06 -0400 | [diff] [blame] | 48 | |
| 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) \ |
| 56 | void flash_write##size(u##size value, void *addr) \ |
| 57 | { \ |
| 58 | __raw_write##sfx(value, gpio_cfi_flash_swizzle(addr)); \ |
| 59 | } \ |
| 60 | u##size flash_read##size(void *addr) \ |
| 61 | { \ |
| 62 | return __raw_read##sfx(gpio_cfi_flash_swizzle(addr)); \ |
| 63 | } |
| 64 | MAKE_FLASH(8, b) /* flash_write8() flash_read8() */ |
Mike Frysinger | ce10f1b | 2009-08-20 19:17:59 -0400 | [diff] [blame] | 65 | MAKE_FLASH(16, w) /* flash_write16() flash_read16() */ |
| 66 | MAKE_FLASH(32, l) /* flash_write32() flash_read32() */ |
| 67 | MAKE_FLASH(64, q) /* flash_write64() flash_read64() */ |
Mike Frysinger | d014e35 | 2008-10-12 21:41:06 -0400 | [diff] [blame] | 68 | |
| 69 | void gpio_cfi_flash_init(void) |
| 70 | { |
Mike Frysinger | e81aa9e | 2010-06-02 05:22:16 -0400 | [diff] [blame] | 71 | gpio_request(GPIO_PIN_1, "gpio_cfi_flash"); |
Mike Frysinger | 2ff0a30 | 2010-07-24 03:54:19 -0400 | [diff] [blame] | 72 | gpio_direction_output(GPIO_PIN_1, 0); |
| 73 | #ifdef GPIO_PIN_2 |
Mike Frysinger | e81aa9e | 2010-06-02 05:22:16 -0400 | [diff] [blame] | 74 | gpio_request(GPIO_PIN_2, "gpio_cfi_flash"); |
Mike Frysinger | 2ff0a30 | 2010-07-24 03:54:19 -0400 | [diff] [blame] | 75 | gpio_direction_output(GPIO_PIN_2, 0); |
Mike Frysinger | e81aa9e | 2010-06-02 05:22:16 -0400 | [diff] [blame] | 76 | #endif |
Peter Meerwald | bf20385 | 2010-09-17 13:02:42 -0400 | [diff] [blame] | 77 | #ifdef GPIO_PIN_3 |
| 78 | gpio_request(GPIO_PIN_3, "gpio_cfi_flash"); |
| 79 | gpio_direction_output(GPIO_PIN_3, 0); |
| 80 | #endif |
Mike Frysinger | d014e35 | 2008-10-12 21:41:06 -0400 | [diff] [blame] | 81 | } |