160-vlynq_try_remote_first.patch 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300
  1. --- a/drivers/vlynq/vlynq.c
  2. +++ b/drivers/vlynq/vlynq.c
  3. @@ -119,20 +119,40 @@ static int vlynq_linked(struct vlynq_dev
  4. return 0;
  5. }
  6. +static volatile int vlynq_delay_value_new = 0;
  7. +
  8. +static void vlynq_delay_wait(u32 count)
  9. +{
  10. + /* Code adopted from original vlynq driver */
  11. + int i = 0;
  12. + volatile int *ptr = &vlynq_delay_value_new;
  13. + *ptr = 0;
  14. +
  15. + /* We are assuming that the each cycle takes about
  16. + * 23 assembly instructions. */
  17. + for(i = 0; i < (count + 23)/23; i++)
  18. + *ptr = *ptr + 1;
  19. +}
  20. +
  21. static void vlynq_reset(struct vlynq_device *dev)
  22. {
  23. + u32 rtm = readl(&dev->local->revision);
  24. +
  25. + rtm = rtm < 0x00010205 || readl(&dev->local->status) & 0x800 == 0 ?
  26. + 0 : 0x600000;
  27. +
  28. writel(readl(&dev->local->control) | VLYNQ_CTRL_RESET,
  29. &dev->local->control);
  30. /* Wait for the devices to finish resetting */
  31. - msleep(5);
  32. + vlynq_delay_wait(0xffffff);
  33. /* Remove reset bit */
  34. - writel(readl(&dev->local->control) & ~VLYNQ_CTRL_RESET,
  35. + writel(readl(&dev->local->control) & ~VLYNQ_CTRL_RESET | rtm,
  36. &dev->local->control);
  37. /* Give some time for the devices to settle */
  38. - msleep(5);
  39. + vlynq_delay_wait(0xffffff);
  40. }
  41. static void vlynq_irq_unmask(struct irq_data *d)
  42. @@ -379,6 +399,61 @@ void vlynq_unregister_driver(struct vlyn
  43. }
  44. EXPORT_SYMBOL(vlynq_unregister_driver);
  45. +enum vlynq_clk_src {
  46. + vlynq_clk_external,
  47. + vlynq_clk_local,
  48. + vlynq_clk_remote,
  49. + vlynq_clk_invalid,
  50. +};
  51. +
  52. +static int __vlynq_set_clocks(struct vlynq_device *dev,
  53. + enum vlynq_clk_src clk_dir,
  54. + int lclk_div, int rclk_div)
  55. +{
  56. + u32 reg;
  57. +
  58. + if (clk_dir == vlynq_clk_invalid) {
  59. + printk(KERN_ERR "%s: attempt to set invalid clocking\n",
  60. + dev_name(&dev->dev));
  61. + return -EINVAL;
  62. + }
  63. +
  64. + reg = readl(&dev->local->control);
  65. + if (readl(&dev->local->revision) < 0x00010205) {
  66. + if (clk_dir & vlynq_clk_local)
  67. + reg |= VLYNQ_CTRL_CLOCK_INT;
  68. + else
  69. + reg &= ~VLYNQ_CTRL_CLOCK_INT;
  70. + }
  71. + reg &= ~VLYNQ_CTRL_CLOCK_MASK;
  72. + reg |= VLYNQ_CTRL_CLOCK_DIV(lclk_div);
  73. + writel(reg, &dev->local->control);
  74. +
  75. + if (!vlynq_linked(dev))
  76. + return -ENODEV;
  77. +
  78. + printk(KERN_INFO "%s: local VLYNQ protocol rev. is 0x%08x\n",
  79. + dev_name(&dev->dev), readl(&dev->local->revision));
  80. + printk(KERN_INFO "%s: remote VLYNQ protocol rev. is 0x%08x\n",
  81. + dev_name(&dev->dev), readl(&dev->remote->revision));
  82. +
  83. + reg = readl(&dev->remote->control);
  84. + if (readl(&dev->remote->revision) < 0x00010205) {
  85. + if (clk_dir & vlynq_clk_remote)
  86. + reg |= VLYNQ_CTRL_CLOCK_INT;
  87. + else
  88. + reg &= ~VLYNQ_CTRL_CLOCK_INT;
  89. + }
  90. + reg &= ~VLYNQ_CTRL_CLOCK_MASK;
  91. + reg |= VLYNQ_CTRL_CLOCK_DIV(rclk_div);
  92. + writel(reg, &dev->remote->control);
  93. +
  94. + if (!vlynq_linked(dev))
  95. + return -ENODEV;
  96. +
  97. + return 0;
  98. +}
  99. +
  100. /*
  101. * A VLYNQ remote device can clock the VLYNQ bus master
  102. * using a dedicated clock line. In that case, both the
  103. @@ -392,29 +467,16 @@ static int __vlynq_try_remote(struct vly
  104. int i;
  105. vlynq_reset(dev);
  106. - for (i = dev->dev_id ? vlynq_rdiv2 : vlynq_rdiv8; dev->dev_id ?
  107. - i <= vlynq_rdiv8 : i >= vlynq_rdiv2;
  108. - dev->dev_id ? i++ : i--) {
  109. + for (i = 0; i <= 7; i++) {
  110. if (!vlynq_linked(dev))
  111. break;
  112. - writel((readl(&dev->remote->control) &
  113. - ~VLYNQ_CTRL_CLOCK_MASK) |
  114. - VLYNQ_CTRL_CLOCK_INT |
  115. - VLYNQ_CTRL_CLOCK_DIV(i - vlynq_rdiv1),
  116. - &dev->remote->control);
  117. - writel((readl(&dev->local->control)
  118. - & ~(VLYNQ_CTRL_CLOCK_INT |
  119. - VLYNQ_CTRL_CLOCK_MASK)) |
  120. - VLYNQ_CTRL_CLOCK_DIV(i - vlynq_rdiv1),
  121. - &dev->local->control);
  122. -
  123. - if (vlynq_linked(dev)) {
  124. - printk(KERN_DEBUG
  125. - "%s: using remote clock divisor %d\n",
  126. - dev_name(&dev->dev), i - vlynq_rdiv1 + 1);
  127. - dev->divisor = i;
  128. + if (!__vlynq_set_clocks(dev, vlynq_clk_remote, i, i)) {
  129. + printk(KERN_INFO
  130. + "%s: using remote clock divisor %d\n",
  131. + dev_name(&dev->dev), i + 1);
  132. + dev->divisor = i + vlynq_rdiv1;
  133. return 0;
  134. } else {
  135. vlynq_reset(dev);
  136. @@ -433,25 +495,17 @@ static int __vlynq_try_remote(struct vly
  137. */
  138. static int __vlynq_try_local(struct vlynq_device *dev)
  139. {
  140. - int i;
  141. + int i, dir = !dev->dev_id;
  142. vlynq_reset(dev);
  143. - for (i = dev->dev_id ? vlynq_ldiv2 : vlynq_ldiv8; dev->dev_id ?
  144. - i <= vlynq_ldiv8 : i >= vlynq_ldiv2;
  145. - dev->dev_id ? i++ : i--) {
  146. -
  147. - writel((readl(&dev->local->control) &
  148. - ~VLYNQ_CTRL_CLOCK_MASK) |
  149. - VLYNQ_CTRL_CLOCK_INT |
  150. - VLYNQ_CTRL_CLOCK_DIV(i - vlynq_ldiv1),
  151. - &dev->local->control);
  152. -
  153. - if (vlynq_linked(dev)) {
  154. - printk(KERN_DEBUG
  155. - "%s: using local clock divisor %d\n",
  156. - dev_name(&dev->dev), i - vlynq_ldiv1 + 1);
  157. - dev->divisor = i;
  158. + for (i = dir ? 7 : 0; dir ? i >= 0 : i <= 7; dir ? i-- : i++) {
  159. +
  160. + if (!__vlynq_set_clocks(dev, vlynq_clk_local, i, 0)) {
  161. + printk(KERN_INFO
  162. + "%s: using local clock divisor %d\n",
  163. + dev_name(&dev->dev), i + 1);
  164. + dev->divisor = i + vlynq_ldiv1;
  165. return 0;
  166. } else {
  167. vlynq_reset(dev);
  168. @@ -473,18 +527,10 @@ static int __vlynq_try_external(struct v
  169. if (!vlynq_linked(dev))
  170. return -ENODEV;
  171. - writel((readl(&dev->remote->control) &
  172. - ~VLYNQ_CTRL_CLOCK_INT),
  173. - &dev->remote->control);
  174. -
  175. - writel((readl(&dev->local->control) &
  176. - ~VLYNQ_CTRL_CLOCK_INT),
  177. - &dev->local->control);
  178. -
  179. - if (vlynq_linked(dev)) {
  180. - printk(KERN_DEBUG "%s: using external clock\n",
  181. - dev_name(&dev->dev));
  182. - dev->divisor = vlynq_div_external;
  183. + if (!__vlynq_set_clocks(dev, vlynq_clk_external, 0, 0)) {
  184. + printk(KERN_INFO "%s: using external clock\n",
  185. + dev_name(&dev->dev));
  186. + dev->divisor = vlynq_div_external;
  187. return 0;
  188. }
  189. @@ -501,24 +547,16 @@ static int __vlynq_enable_device(struct
  190. return result;
  191. switch (dev->divisor) {
  192. - case vlynq_div_external:
  193. case vlynq_div_auto:
  194. /* When the device is brought from reset it should have clock
  195. * generation negotiated by hardware.
  196. * Check which device is generating clocks and perform setup
  197. * accordingly */
  198. - if (vlynq_linked(dev) && readl(&dev->remote->control) &
  199. - VLYNQ_CTRL_CLOCK_INT) {
  200. - if (!__vlynq_try_remote(dev) ||
  201. - !__vlynq_try_local(dev) ||
  202. - !__vlynq_try_external(dev))
  203. - return 0;
  204. - } else {
  205. - if (!__vlynq_try_external(dev) ||
  206. - !__vlynq_try_local(dev) ||
  207. - !__vlynq_try_remote(dev))
  208. - return 0;
  209. - }
  210. + if (!__vlynq_try_remote(dev) || !__vlynq_try_local(dev))
  211. + return 0;
  212. + case vlynq_div_external:
  213. + if (!__vlynq_try_external(dev))
  214. + return 0;
  215. break;
  216. case vlynq_ldiv1:
  217. case vlynq_ldiv2:
  218. @@ -528,15 +566,12 @@ static int __vlynq_enable_device(struct
  219. case vlynq_ldiv6:
  220. case vlynq_ldiv7:
  221. case vlynq_ldiv8:
  222. - writel(VLYNQ_CTRL_CLOCK_INT |
  223. - VLYNQ_CTRL_CLOCK_DIV(dev->divisor -
  224. - vlynq_ldiv1), &dev->local->control);
  225. - writel(0, &dev->remote->control);
  226. - if (vlynq_linked(dev)) {
  227. - printk(KERN_DEBUG
  228. - "%s: using local clock divisor %d\n",
  229. - dev_name(&dev->dev),
  230. - dev->divisor - vlynq_ldiv1 + 1);
  231. + if (!__vlynq_set_clocks(dev, vlynq_clk_local, dev->divisor -
  232. + vlynq_ldiv1, 0)) {
  233. + printk(KERN_INFO
  234. + "%s: using local clock divisor %d\n",
  235. + dev_name(&dev->dev),
  236. + dev->divisor - vlynq_ldiv1 + 1);
  237. return 0;
  238. }
  239. break;
  240. @@ -548,20 +583,17 @@ static int __vlynq_enable_device(struct
  241. case vlynq_rdiv6:
  242. case vlynq_rdiv7:
  243. case vlynq_rdiv8:
  244. - writel(0, &dev->local->control);
  245. - writel(VLYNQ_CTRL_CLOCK_INT |
  246. - VLYNQ_CTRL_CLOCK_DIV(dev->divisor -
  247. - vlynq_rdiv1), &dev->remote->control);
  248. - if (vlynq_linked(dev)) {
  249. - printk(KERN_DEBUG
  250. - "%s: using remote clock divisor %d\n",
  251. - dev_name(&dev->dev),
  252. - dev->divisor - vlynq_rdiv1 + 1);
  253. + if (!__vlynq_set_clocks(dev, vlynq_clk_remote, 0,
  254. + dev->divisor - vlynq_rdiv1)) {
  255. + printk(KERN_INFO
  256. + "%s: using remote clock divisor %d\n",
  257. + dev_name(&dev->dev),
  258. + dev->divisor - vlynq_rdiv1 + 1);
  259. return 0;
  260. }
  261. break;
  262. }
  263. -
  264. + vlynq_reset(dev);
  265. ops->off(dev);
  266. return -ENODEV;
  267. }
  268. @@ -732,14 +764,14 @@ static int vlynq_probe(struct platform_d
  269. platform_set_drvdata(pdev, dev);
  270. printk(KERN_INFO "%s: regs 0x%p, irq %d, mem 0x%p\n",
  271. - dev_name(&dev->dev), (void *)dev->regs_start, dev->irq,
  272. - (void *)dev->mem_start);
  273. + dev_name(&dev->dev), (void *)dev->regs_start,
  274. + dev->irq, (void *)dev->mem_start);
  275. dev->dev_id = 0;
  276. dev->divisor = vlynq_div_auto;
  277. - result = __vlynq_enable_device(dev);
  278. - if (result == 0) {
  279. + if (!__vlynq_enable_device(dev)) {
  280. dev->dev_id = readl(&dev->remote->chip);
  281. + vlynq_reset(dev);
  282. ((struct plat_vlynq_ops *)(dev->dev.platform_data))->off(dev);
  283. }
  284. if (dev->dev_id)