gpio_cfi_flash.c 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. /*
  2. * gpio_cfi_flash.c - GPIO-assisted Flash Chip Support
  3. *
  4. * Copyright (c) 2009-2010 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. /* Allow this driver to be shared among boards */
  14. #ifndef GPIO_PIN_1
  15. #define GPIO_PIN_1 GPIO_PF4
  16. #endif
  17. #define GPIO_MASK_1 (1 << 21)
  18. #ifndef GPIO_PIN_2
  19. #define GPIO_MASK_2 (0)
  20. #else
  21. #define GPIO_MASK_2 (1 << 22)
  22. #endif
  23. #define GPIO_MASK (GPIO_MASK_1 | GPIO_MASK_2)
  24. void *gpio_cfi_flash_swizzle(void *vaddr)
  25. {
  26. unsigned long addr = (unsigned long)vaddr;
  27. gpio_set_value(GPIO_PIN_1, addr & GPIO_MASK_1);
  28. #ifdef GPIO_PIN_2
  29. gpio_set_value(GPIO_PIN_2, addr & GPIO_MASK_2);
  30. #endif
  31. SSYNC();
  32. udelay(1);
  33. return (void *)(addr & ~GPIO_MASK);
  34. }
  35. #define __raw_writeq(value, addr) *(volatile u64 *)addr = value
  36. #define __raw_readq(addr) *(volatile u64 *)addr
  37. #define MAKE_FLASH(size, sfx) \
  38. void flash_write##size(u##size value, void *addr) \
  39. { \
  40. __raw_write##sfx(value, gpio_cfi_flash_swizzle(addr)); \
  41. } \
  42. u##size flash_read##size(void *addr) \
  43. { \
  44. return __raw_read##sfx(gpio_cfi_flash_swizzle(addr)); \
  45. }
  46. MAKE_FLASH(8, b) /* flash_write8() flash_read8() */
  47. MAKE_FLASH(16, w) /* flash_write16() flash_read16() */
  48. MAKE_FLASH(32, l) /* flash_write32() flash_read32() */
  49. MAKE_FLASH(64, q) /* flash_write64() flash_read64() */
  50. void gpio_cfi_flash_init(void)
  51. {
  52. gpio_request(GPIO_PIN_1, "gpio_cfi_flash");
  53. gpio_direction_output(GPIO_PIN_1, 0);
  54. #ifdef GPIO_PIN_2
  55. gpio_request(GPIO_PIN_2, "gpio_cfi_flash");
  56. gpio_direction_output(GPIO_PIN_2, 0);
  57. #endif
  58. }