gpio_cfi_flash.c 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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. #ifndef GPIO_PIN_3
  24. #define GPIO_MASK_3 (0)
  25. #else
  26. #define GPIO_MASK_3 (1 << 23)
  27. #endif
  28. #define GPIO_MASK (GPIO_MASK_1 | GPIO_MASK_2 | GPIO_MASK_3)
  29. void *gpio_cfi_flash_swizzle(void *vaddr)
  30. {
  31. unsigned long addr = (unsigned long)vaddr;
  32. gpio_set_value(GPIO_PIN_1, addr & GPIO_MASK_1);
  33. #ifdef GPIO_PIN_2
  34. gpio_set_value(GPIO_PIN_2, addr & GPIO_MASK_2);
  35. #endif
  36. #ifdef GPIO_PIN_3
  37. gpio_set_value(GPIO_PIN_3, addr & GPIO_MASK_3);
  38. #endif
  39. SSYNC();
  40. udelay(1);
  41. return (void *)(addr & ~GPIO_MASK);
  42. }
  43. #define __raw_writeq(value, addr) *(volatile u64 *)addr = value
  44. #define __raw_readq(addr) *(volatile u64 *)addr
  45. #define MAKE_FLASH(size, sfx) \
  46. void flash_write##size(u##size value, void *addr) \
  47. { \
  48. __raw_write##sfx(value, gpio_cfi_flash_swizzle(addr)); \
  49. } \
  50. u##size flash_read##size(void *addr) \
  51. { \
  52. return __raw_read##sfx(gpio_cfi_flash_swizzle(addr)); \
  53. }
  54. MAKE_FLASH(8, b) /* flash_write8() flash_read8() */
  55. MAKE_FLASH(16, w) /* flash_write16() flash_read16() */
  56. MAKE_FLASH(32, l) /* flash_write32() flash_read32() */
  57. MAKE_FLASH(64, q) /* flash_write64() flash_read64() */
  58. void gpio_cfi_flash_init(void)
  59. {
  60. gpio_request(GPIO_PIN_1, "gpio_cfi_flash");
  61. gpio_direction_output(GPIO_PIN_1, 0);
  62. #ifdef GPIO_PIN_2
  63. gpio_request(GPIO_PIN_2, "gpio_cfi_flash");
  64. gpio_direction_output(GPIO_PIN_2, 0);
  65. #endif
  66. #ifdef GPIO_PIN_3
  67. gpio_request(GPIO_PIN_3, "gpio_cfi_flash");
  68. gpio_direction_output(GPIO_PIN_3, 0);
  69. #endif
  70. }