gpio_cfi_flash.c 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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. #include <common.h>
  9. #include <asm/blackfin.h>
  10. #include <asm/gpio.h>
  11. #include <asm/io.h>
  12. #include "gpio_cfi_flash.h"
  13. #define GPIO_PIN_1 GPIO_PH9
  14. #define GPIO_MASK_1 (1 << 21)
  15. #define GPIO_PIN_2 GPIO_PG11
  16. #define GPIO_MASK_2 (1 << 22)
  17. #define GPIO_MASK (GPIO_MASK_1 | GPIO_MASK_2)
  18. void *gpio_cfi_flash_swizzle(void *vaddr)
  19. {
  20. unsigned long addr = (unsigned long)vaddr;
  21. gpio_set_value(GPIO_PIN_1, addr & GPIO_MASK_1);
  22. #ifdef GPIO_MASK_2
  23. gpio_set_value(GPIO_PIN_2, addr & GPIO_MASK_2);
  24. #endif
  25. SSYNC();
  26. return (void *)(addr & ~GPIO_MASK);
  27. }
  28. #define __raw_writeq(value, addr) *(volatile u64 *)addr = value
  29. #define __raw_readq(addr) *(volatile u64 *)addr
  30. #define MAKE_FLASH(size, sfx) \
  31. void flash_write##size(u##size value, void *addr) \
  32. { \
  33. __raw_write##sfx(value, gpio_cfi_flash_swizzle(addr)); \
  34. } \
  35. u##size flash_read##size(void *addr) \
  36. { \
  37. return __raw_read##sfx(gpio_cfi_flash_swizzle(addr)); \
  38. }
  39. MAKE_FLASH(8, b) /* flash_write8() flash_read8() */
  40. MAKE_FLASH(16, w) /* flash_write16() flash_read16() */
  41. MAKE_FLASH(32, l) /* flash_write32() flash_read32() */
  42. MAKE_FLASH(64, q) /* flash_write64() flash_read64() */
  43. void gpio_cfi_flash_init(void)
  44. {
  45. gpio_request(GPIO_PIN_1, "gpio_cfi_flash");
  46. #ifdef GPIO_MASK_2
  47. gpio_request(GPIO_PIN_2, "gpio_cfi_flash");
  48. #endif
  49. gpio_cfi_flash_swizzle((void *)CONFIG_SYS_FLASH_BASE);
  50. }