/recipes/linux/linux-2.6.24/hipox/hipox-nand-vs-pci.patch

https://github.com/SIFTeam/openembedded · Patch · 212 lines · 203 code · 9 blank · 0 comment · 0 complexity · 9deb2365cf051981c340ab27f8e1865a MD5 · raw file

  1. diff -Nurd linux-2.6.24.orig//drivers/mtd/nand/hipox_nand.c linux-2.6.24/drivers/mtd/nand/hipox_nand.c
  2. --- linux-2.6.24.orig//drivers/mtd/nand/hipox_nand.c 2010-01-08 10:57:15.000000000 +0100
  3. +++ linux-2.6.24/drivers/mtd/nand/hipox_nand.c 2010-01-08 10:58:33.000000000 +0100
  4. @@ -21,6 +21,7 @@
  5. #include <linux/mtd/nand.h>
  6. #include <linux/mtd/partitions.h>
  7. #include <linux/delay.h>
  8. +#include <linux/jiffies.h>
  9. #include <asm/io.h>
  10. #include <asm/arch/hardware.h>
  11. #include <asm/sizes.h>
  12. @@ -58,9 +59,52 @@
  13. };
  14. #endif
  15. +static unsigned int timestamp = 0;
  16. +/*
  17. + * Request PCI_ARB to grant access to the STATIC core.
  18. + */
  19. +static void request_bus(void)
  20. +{
  21. + unsigned maxtries = 10; /* wait for maxtries jiffies at maximum */
  22. +
  23. + /* set PCI_ARB request bit in Sysctrl_PCI_Ctrl1 */
  24. + writel(readl(SYS_CTRL_PCI_CTRL1) | (1UL << SYSCTL_PCI_CTRL1_SYSPCI_STATIC_REQ), SYS_CTRL_PCI_CTRL1);
  25. +
  26. + /* check if STATIC core has been granted access to the PCI bus
  27. + and can use PCI_AD[31:0] pins */
  28. + for (;maxtries > 0; maxtries--)
  29. + {
  30. + if (readl(SYS_CTRL_PCI_STAT) & (1UL << SYSCTL_PCI_STAT_SYSPCI_STATIC_GNT))
  31. + break;
  32. + udelay(10);
  33. + }
  34. +
  35. + /* check for timeout granting access */
  36. + if (!(readl(SYS_CTRL_PCI_STAT) & (1UL << SYSCTL_PCI_STAT_SYSPCI_STATIC_GNT)))
  37. + printk(KERN_WARNING "%s: timeout requesting access to PCI bus for static memory interface\n", __func__);
  38. +
  39. + timestamp = jiffies_to_msecs(get_jiffies_64());
  40. +}
  41. /*
  42. - * hardware specific access to control-lines
  43. + * Release access to PCI bus.
  44. + */
  45. +static void release_bus(void)
  46. +{
  47. + const unsigned int timeout = 100; /* ms */
  48. + unsigned int delta = jiffies_to_msecs(get_jiffies_64()) - timestamp;
  49. +
  50. + /* set PCI_ARB request bit in Sysctrl_PCI_Ctrl1 */
  51. + writel(readl(SYS_CTRL_PCI_CTRL1) & ~(1UL << SYSCTL_PCI_CTRL1_SYSPCI_STATIC_REQ), SYS_CTRL_PCI_CTRL1);
  52. +
  53. + if (delta > timeout)
  54. + {
  55. + printk(KERN_WARNING "%s: static memory interface blocked PCI bus for %u ms\n", __func__, delta);
  56. + }
  57. +}
  58. +
  59. +/*
  60. + * Hardware specific access to control-lines
  61. */
  62. static void hipox_nand_hwcontrol(struct mtd_info *mtd, int cmd, unsigned int ctrl)
  63. {
  64. @@ -85,30 +129,110 @@
  65. }
  66. if (cmd != NAND_CMD_NONE)
  67. + {
  68. + request_bus();
  69. writeb(cmd, this->IO_ADDR_W);
  70. + release_bus();
  71. + }
  72. }
  73. -static void hipox_read_buf(struct mtd_info *mtd, uint8_t *buf, int len)
  74. +/**
  75. + * hipox_nand_read_byte - read one byte from the chip
  76. + * @mtd: MTD device structure
  77. + *
  78. + * Read function for 8bit buswith
  79. + */
  80. +static uint8_t hipox_nand_read_byte(struct mtd_info *mtd)
  81. {
  82. - struct nand_chip *chip = mtd->priv;
  83. - volatile uint8_t *io = chip->IO_ADDR_R;
  84. + struct nand_chip *chip = mtd->priv;
  85. + uint8_t res;
  86. + request_bus();
  87. + res = readb(chip->IO_ADDR_R);
  88. + release_bus();
  89. + return res;
  90. +}
  91. - if((((int)buf) & 1) || (len & 1))
  92. - {
  93. - while(len-- > 0)
  94. - *buf++ = *io;
  95. +/**
  96. + * hipox_nand_read_word - read one word from the chip
  97. + * @mtd: MTD device structure
  98. + *
  99. + * Read function for 16bit buswith without
  100. + * endianess conversion
  101. + */
  102. +static u16 hipox_nand_read_word(struct mtd_info *mtd)
  103. +{
  104. + struct nand_chip *chip = mtd->priv;
  105. + u16 res;
  106. + request_bus();
  107. + res = readw(chip->IO_ADDR_R);
  108. + release_bus();
  109. + return res;
  110. +}
  111. - return;
  112. - }
  113. +/**
  114. + * hipox_nand_read_buf - read chip data into buffer
  115. + * @mtd: MTD device structure
  116. + * @buf: buffer to store date
  117. + * @len: number of bytes to read
  118. + *
  119. + * Read function for 8bit buswith
  120. + */
  121. +static void hipox_nand_read_buf(struct mtd_info *mtd, uint8_t *buf, int len)
  122. +{
  123. + int i;
  124. + struct nand_chip *chip = mtd->priv;
  125. - // now it's aligned, group to 16 bit access
  126. + request_bus();
  127. + for (i = 0; i < len; i++)
  128. + buf[i] = readb(chip->IO_ADDR_R);
  129. + release_bus();
  130. +}
  131. +
  132. +/**
  133. + * hipox_nand_write_buf - write buffer to chip
  134. + * @mtd: MTD device structure
  135. + * @buf: data buffer
  136. + * @len: number of bytes to write
  137. + *
  138. + * Write function for 8bit buswith
  139. + */
  140. +static void hipox_nand_write_buf(struct mtd_info *mtd, const uint8_t *buf, int len)
  141. +{
  142. + int i;
  143. + struct nand_chip *chip = mtd->priv;
  144. +
  145. + request_bus();
  146. + for (i = 0; i < len; i++)
  147. + writeb(buf[i], chip->IO_ADDR_W);
  148. + release_bus();
  149. +}
  150. +
  151. +/**
  152. + * hipox_nand_verify_buf - Verify chip data against buffer
  153. + * @mtd: MTD device structure
  154. + * @buf: buffer containing the data to compare
  155. + * @len: number of bytes to compare
  156. + *
  157. + * Verify function for 8bit buswith
  158. + */
  159. +static int hipox_nand_verify_buf(struct mtd_info *mtd, const uint8_t *buf, int len)
  160. +{
  161. + int i;
  162. + int ret = 0;
  163. + struct nand_chip *chip = mtd->priv;
  164. +
  165. + request_bus();
  166. + for (i = 0; i < len; i++)
  167. {
  168. - uint16_t *ptr16 = (uint16_t *)buf;
  169. - len >>= 1;
  170. -
  171. - while(len-- > 0)
  172. - *ptr16++ = *io | (*io << 8);
  173. + if (buf[i] != readb(chip->IO_ADDR_R))
  174. + {
  175. + ret = 0;
  176. + break;
  177. + }
  178. }
  179. + release_bus();
  180. +
  181. + return ret;
  182. }
  183. /*
  184. @@ -175,10 +299,18 @@
  185. /* insert callbacks */
  186. this->IO_ADDR_R = (void *)CONFIG_SYS_NAND_BASE;
  187. this->IO_ADDR_W = (void *)CONFIG_SYS_NAND_BASE;
  188. - this->cmd_ctrl = hipox_nand_hwcontrol;
  189. - this->read_buf = hipox_read_buf;
  190. this->chip_delay = 25; // 23 still worked on our EvalBoard
  191. this->ecc.mode = NAND_ECC_SOFT;
  192. + /* we overwrite these funcs because we need a special lock
  193. + handling for use of data pins shared between PCI and
  194. + static memory interface of OXE810 cpu */
  195. + this->cmd_ctrl = hipox_nand_hwcontrol;
  196. + this->read_byte = hipox_nand_read_byte;
  197. + this->read_word = hipox_nand_read_word;
  198. + this->read_buf = hipox_nand_read_buf;
  199. + this->write_buf = hipox_nand_write_buf;
  200. + this->verify_buf = hipox_nand_verify_buf;
  201. +
  202. printk("Searching for NAND flash...\n");
  203. /* Scan to find existence of the device */