050-linux-atm_nathan.patch 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277
  1. From: Nathan Williams <[email protected]>
  2. To: [email protected]
  3. Date: Wed, 05 Oct 2011 15:43:30 +1100
  4. Cc: [email protected],
  5. David Woodhouse <[email protected]>, [email protected]
  6. Subject: [Linux-ATM-General] [PATCH 1/4] atm: solos-pci: Add AnnexA/M
  7. capability attributes
  8. BisACapability and BisMCapability allow users to
  9. force either Annex A or Annex M.
  10. Signed-off-by: Nathan Williams <[email protected]>
  11. ---
  12. drivers/atm/solos-attrlist.c | 2 ++
  13. 1 files changed, 2 insertions(+), 0 deletions(-)
  14. --- a/drivers/atm/solos-attrlist.c
  15. +++ b/drivers/atm/solos-attrlist.c
  16. @@ -71,6 +71,8 @@ SOLOS_ATTR_RW(BisAForceSNRMarginDn)
  17. SOLOS_ATTR_RW(BisMForceSNRMarginDn)
  18. SOLOS_ATTR_RW(BisAMaxMargin)
  19. SOLOS_ATTR_RW(BisMMaxMargin)
  20. +SOLOS_ATTR_RW(BisACapability)
  21. +SOLOS_ATTR_RW(BisMCapability)
  22. SOLOS_ATTR_RW(AnnexAForceSNRMarginDn)
  23. SOLOS_ATTR_RW(AnnexAMaxMargin)
  24. SOLOS_ATTR_RW(AnnexMMaxMargin)
  25. --- a/drivers/atm/solos-pci.c
  26. +++ b/drivers/atm/solos-pci.c
  27. @@ -42,7 +42,8 @@
  28. #include <linux/swab.h>
  29. #include <linux/slab.h>
  30. -#define VERSION "0.07"
  31. +#define VERSION "1.0"
  32. +#define DRIVER_VERSION 0x01
  33. #define PTAG "solos-pci"
  34. #define CONFIG_RAM_SIZE 128
  35. @@ -56,16 +57,21 @@
  36. #define FLASH_BUSY 0x60
  37. #define FPGA_MODE 0x5C
  38. #define FLASH_MODE 0x58
  39. +#define GPIO_STATUS 0x54
  40. +#define DRIVER_VER 0x50
  41. #define TX_DMA_ADDR(port) (0x40 + (4 * (port)))
  42. #define RX_DMA_ADDR(port) (0x30 + (4 * (port)))
  43. #define DATA_RAM_SIZE 32768
  44. #define BUF_SIZE 2048
  45. #define OLD_BUF_SIZE 4096 /* For FPGA versions <= 2*/
  46. -#define FPGA_PAGE 528 /* FPGA flash page size*/
  47. -#define SOLOS_PAGE 512 /* Solos flash page size*/
  48. -#define FPGA_BLOCK (FPGA_PAGE * 8) /* FPGA flash block size*/
  49. -#define SOLOS_BLOCK (SOLOS_PAGE * 8) /* Solos flash block size*/
  50. +/* Old boards use ATMEL AD45DB161D flash */
  51. +#define ATMEL_FPGA_PAGE 528 /* FPGA flash page size*/
  52. +#define ATMEL_SOLOS_PAGE 512 /* Solos flash page size*/
  53. +#define ATMEL_FPGA_BLOCK (ATMEL_FPGA_PAGE * 8) /* FPGA block size*/
  54. +#define ATMEL_SOLOS_BLOCK (ATMEL_SOLOS_PAGE * 8) /* Solos block size*/
  55. +/* Current boards use M25P/M25PE SPI flash */
  56. +#define SPI_FLASH_BLOCK (256 * 64)
  57. #define RX_BUF(card, nr) ((card->buffers) + (nr)*(card->buffer_size)*2)
  58. #define TX_BUF(card, nr) ((card->buffers) + (nr)*(card->buffer_size)*2 + (card->buffer_size))
  59. @@ -127,6 +133,7 @@ struct solos_card {
  60. int using_dma;
  61. int fpga_version;
  62. int buffer_size;
  63. + int atmel_flash;
  64. };
  65. @@ -452,7 +459,6 @@ static ssize_t console_show(struct devic
  66. len = skb->len;
  67. memcpy(buf, skb->data, len);
  68. - dev_dbg(&card->dev->dev, "len: %d\n", len);
  69. kfree_skb(skb);
  70. return len;
  71. @@ -499,6 +505,87 @@ static ssize_t console_store(struct devi
  72. return err?:count;
  73. }
  74. +struct geos_gpio {
  75. + char *name;
  76. + int offset;
  77. +};
  78. +
  79. +static struct geos_gpio geos_gpio_pins[] = {
  80. + {"GPIO1", 9},
  81. + {"GPIO2", 10},
  82. + {"GPIO3", 11},
  83. + {"GPIO4", 12},
  84. + {"GPIO5", 13},
  85. + {"PushButton", 14},
  86. + {NULL, 0}
  87. +};
  88. +
  89. +static ssize_t geos_gpio_store(struct device *dev, struct device_attribute *attr,
  90. + const char *buf, size_t count)
  91. +{
  92. + struct atm_dev *atmdev = container_of(dev, struct atm_dev, class_dev);
  93. + struct solos_card *card = atmdev->dev_data;
  94. + uint32_t data32;
  95. +
  96. + struct geos_gpio *p = geos_gpio_pins;
  97. + while(p->name){
  98. + if(!strcmp(attr->attr.name, p->name)){
  99. + break;
  100. + }
  101. + p++;
  102. + }
  103. +
  104. + data32 = ioread32(card->config_regs + GPIO_STATUS);
  105. + if(buf[0] == '1'){
  106. + data32 |= 1 << p->offset;
  107. + iowrite32(data32, card->config_regs + GPIO_STATUS);
  108. + } else if(buf[0] == '0') {
  109. + data32 &= ~(1 << p->offset);
  110. + iowrite32(data32, card->config_regs + GPIO_STATUS);
  111. + }
  112. + return count;
  113. +}
  114. +
  115. +static ssize_t geos_gpio_show(struct device *dev, struct device_attribute *attr,
  116. + char *buf)
  117. +{
  118. + struct atm_dev *atmdev = container_of(dev, struct atm_dev, class_dev);
  119. + struct solos_card *card = atmdev->dev_data;
  120. + uint32_t data32;
  121. +
  122. + struct geos_gpio *p = geos_gpio_pins;
  123. + while(p->name){
  124. + if(!strcmp(attr->attr.name, p->name)){
  125. + break;
  126. + }
  127. + p++;
  128. + }
  129. +
  130. + data32 = ioread32(card->config_regs + GPIO_STATUS);
  131. + data32 = (data32 >> p->offset) & 1;
  132. +
  133. + return sprintf(buf, "%d\n", data32);
  134. +}
  135. +
  136. +static ssize_t hardware_show(struct device *dev, struct device_attribute *attr,
  137. + char *buf)
  138. +{
  139. + struct atm_dev *atmdev = container_of(dev, struct atm_dev, class_dev);
  140. + struct solos_card *card = atmdev->dev_data;
  141. + uint32_t data32;
  142. +
  143. + data32 = ioread32(card->config_regs + GPIO_STATUS);
  144. + if(!strcmp(attr->attr.name, "HardwareVersion")){
  145. + data32 = data32 & 0x1F;
  146. + return sprintf(buf, "%d\n", data32);
  147. + } else if(!strcmp(attr->attr.name, "HardwareVariant")){
  148. + data32 = (data32 >> 5) & 0x0F;
  149. + return sprintf(buf, "%d\n", data32);
  150. + }
  151. +
  152. + return sprintf(buf, "Error\n");
  153. +}
  154. +
  155. static DEVICE_ATTR(console, 0644, console_show, console_store);
  156. @@ -507,6 +594,14 @@ static DEVICE_ATTR(console, 0644, consol
  157. #include "solos-attrlist.c"
  158. +static DEVICE_ATTR(GPIO1, 0644, geos_gpio_show, geos_gpio_store);
  159. +static DEVICE_ATTR(GPIO2, 0644, geos_gpio_show, geos_gpio_store);
  160. +static DEVICE_ATTR(GPIO3, 0644, geos_gpio_show, geos_gpio_store);
  161. +static DEVICE_ATTR(GPIO4, 0644, geos_gpio_show, geos_gpio_store);
  162. +static DEVICE_ATTR(GPIO5, 0644, geos_gpio_show, geos_gpio_store);
  163. +static DEVICE_ATTR(PushButton, 0444, geos_gpio_show, NULL);
  164. +static DEVICE_ATTR(HardwareVersion, 0444, hardware_show, NULL);
  165. +static DEVICE_ATTR(HardwareVariant, 0444, hardware_show, NULL);
  166. #undef SOLOS_ATTR_RO
  167. #undef SOLOS_ATTR_RW
  168. @@ -515,6 +610,14 @@ static DEVICE_ATTR(console, 0644, consol
  169. static struct attribute *solos_attrs[] = {
  170. #include "solos-attrlist.c"
  171. + &dev_attr_GPIO1.attr,
  172. + &dev_attr_GPIO2.attr,
  173. + &dev_attr_GPIO3.attr,
  174. + &dev_attr_GPIO4.attr,
  175. + &dev_attr_GPIO5.attr,
  176. + &dev_attr_PushButton.attr,
  177. + &dev_attr_HardwareVersion.attr,
  178. + &dev_attr_HardwareVariant.attr,
  179. NULL
  180. };
  181. @@ -535,16 +638,25 @@ static int flash_upgrade(struct solos_ca
  182. switch (chip) {
  183. case 0:
  184. fw_name = "solos-FPGA.bin";
  185. - blocksize = FPGA_BLOCK;
  186. + if (card->atmel_flash)
  187. + blocksize = ATMEL_FPGA_BLOCK;
  188. + else
  189. + blocksize = SPI_FLASH_BLOCK;
  190. break;
  191. case 1:
  192. fw_name = "solos-Firmware.bin";
  193. - blocksize = SOLOS_BLOCK;
  194. + if (card->atmel_flash)
  195. + blocksize = ATMEL_SOLOS_BLOCK;
  196. + else
  197. + blocksize = SPI_FLASH_BLOCK;
  198. break;
  199. case 2:
  200. if (card->fpga_version > LEGACY_BUFFERS){
  201. fw_name = "solos-db-FPGA.bin";
  202. - blocksize = FPGA_BLOCK;
  203. + if (card->atmel_flash)
  204. + blocksize = ATMEL_FPGA_BLOCK;
  205. + else
  206. + blocksize = SPI_FLASH_BLOCK;
  207. } else {
  208. dev_info(&card->dev->dev, "FPGA version doesn't support"
  209. " daughter board upgrades\n");
  210. @@ -554,7 +666,10 @@ static int flash_upgrade(struct solos_ca
  211. case 3:
  212. if (card->fpga_version > LEGACY_BUFFERS){
  213. fw_name = "solos-Firmware.bin";
  214. - blocksize = SOLOS_BLOCK;
  215. + if (card->atmel_flash)
  216. + blocksize = ATMEL_SOLOS_BLOCK;
  217. + else
  218. + blocksize = SPI_FLASH_BLOCK;
  219. } else {
  220. dev_info(&card->dev->dev, "FPGA version doesn't support"
  221. " daughter board upgrades\n");
  222. @@ -599,9 +714,13 @@ static int flash_upgrade(struct solos_ca
  223. /* dev_info(&card->dev->dev, "Set FPGA Flash mode to Block Write\n"); */
  224. iowrite32(((chip * 2) + 1), card->config_regs + FLASH_MODE);
  225. - /* Copy block to buffer, swapping each 16 bits */
  226. + /* Copy block to buffer, swapping each 16 bits for Atmel flash */
  227. for(i = 0; i < blocksize; i += 4) {
  228. - uint32_t word = swahb32p((uint32_t *)(fw->data + offset + i));
  229. + uint32_t word;
  230. + if (card->atmel_flash)
  231. + word = swahb32p((uint32_t *)(fw->data + offset + i));
  232. + else
  233. + word = *(uint32_t *)(fw->data + offset + i);
  234. if(card->fpga_version > LEGACY_BUFFERS)
  235. iowrite32(word, FLASH_BUF + i);
  236. else
  237. @@ -1153,6 +1272,11 @@ static int fpga_probe(struct pci_dev *de
  238. db_fpga_upgrade = db_firmware_upgrade = 0;
  239. }
  240. + /* Stopped using Atmel flash after 0.03-38 */
  241. + if (fpga_ver < 39)
  242. + card->atmel_flash = 1;
  243. + else
  244. + card->atmel_flash = 0;
  245. if (card->fpga_version >= DMA_SUPPORTED){
  246. card->using_dma = 1;
  247. } else {
  248. @@ -1160,6 +1284,8 @@ static int fpga_probe(struct pci_dev *de
  249. /* Set RX empty flag for all ports */
  250. iowrite32(0xF0, card->config_regs + FLAGS_ADDR);
  251. }
  252. + /* New FPGAs require driver version before permitting flash upgrades */
  253. + iowrite32(DRIVER_VERSION, card->config_regs + DRIVER_VER);
  254. data32 = ioread32(card->config_regs + PORTS);
  255. card->nr_ports = (data32 & 0x000000FF);