0160-owrt-lantiq-multiple-flash.patch 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. --- a/drivers/mtd/maps/lantiq-flash.c
  2. +++ b/drivers/mtd/maps/lantiq-flash.c
  3. @@ -17,6 +17,7 @@
  4. #include <linux/mtd/cfi.h>
  5. #include <linux/platform_device.h>
  6. #include <linux/mtd/physmap.h>
  7. +#include <linux/mtd/concat.h>
  8. #include <linux/of.h>
  9. #include <lantiq_soc.h>
  10. @@ -36,13 +37,16 @@ enum {
  11. LTQ_NOR_NORMAL
  12. };
  13. +#define MAX_RESOURCES 4
  14. +
  15. struct ltq_mtd {
  16. - struct resource *res;
  17. - struct mtd_info *mtd;
  18. - struct map_info *map;
  19. + struct mtd_info *mtd[MAX_RESOURCES];
  20. + struct mtd_info *cmtd;
  21. + struct map_info map[MAX_RESOURCES];
  22. };
  23. static const char ltq_map_name[] = "ltq_nor";
  24. +static const char * const ltq_probe_types[] = { "cmdlinepart", "ofpart", NULL };
  25. static map_word
  26. ltq_read16(struct map_info *map, unsigned long adr)
  27. @@ -106,11 +110,43 @@ ltq_copy_to(struct map_info *map, unsign
  28. }
  29. static int
  30. +ltq_mtd_remove(struct platform_device *pdev)
  31. +{
  32. + struct ltq_mtd *ltq_mtd = platform_get_drvdata(pdev);
  33. + int i;
  34. +
  35. + if (ltq_mtd == NULL)
  36. + return 0;
  37. +
  38. + if (ltq_mtd->cmtd) {
  39. + mtd_device_unregister(ltq_mtd->cmtd);
  40. + if (ltq_mtd->cmtd != ltq_mtd->mtd[0])
  41. + mtd_concat_destroy(ltq_mtd->cmtd);
  42. + }
  43. +
  44. + for (i = 0; i < MAX_RESOURCES; i++) {
  45. + if (ltq_mtd->mtd[i] != NULL)
  46. + map_destroy(ltq_mtd->mtd[i]);
  47. + }
  48. +
  49. + kfree(ltq_mtd);
  50. +
  51. + return 0;
  52. +}
  53. +
  54. +static int
  55. ltq_mtd_probe(struct platform_device *pdev)
  56. {
  57. struct ltq_mtd *ltq_mtd;
  58. struct cfi_private *cfi;
  59. - int err;
  60. + int err = 0;
  61. + int i;
  62. + int devices_found = 0;
  63. +
  64. + static const char *rom_probe_types[] = {
  65. + "cfi_probe", "jedec_probe", NULL
  66. + };
  67. + const char **type;
  68. ltq_mtd = devm_kzalloc(&pdev->dev, sizeof(struct ltq_mtd), GFP_KERNEL);
  69. if (!ltq_mtd)
  70. @@ -118,75 +154,89 @@ ltq_mtd_probe(struct platform_device *pd
  71. platform_set_drvdata(pdev, ltq_mtd);
  72. - ltq_mtd->res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  73. - if (!ltq_mtd->res) {
  74. - dev_err(&pdev->dev, "failed to get memory resource\n");
  75. - return -ENOENT;
  76. + for (i = 0; i < pdev->num_resources; i++) {
  77. + printk(KERN_NOTICE "lantiq nor flash device: %.8llx at %.8llx\n",
  78. + (unsigned long long)resource_size(&pdev->resource[i]),
  79. + (unsigned long long)pdev->resource[i].start);
  80. +
  81. + if (!devm_request_mem_region(&pdev->dev,
  82. + pdev->resource[i].start,
  83. + resource_size(&pdev->resource[i]),
  84. + dev_name(&pdev->dev))) {
  85. + dev_err(&pdev->dev, "Could not reserve memory region\n");
  86. + return -ENOMEM;
  87. + }
  88. +
  89. + ltq_mtd->map[i].name = ltq_map_name;
  90. + ltq_mtd->map[i].bankwidth = 2;
  91. + ltq_mtd->map[i].read = ltq_read16;
  92. + ltq_mtd->map[i].write = ltq_write16;
  93. + ltq_mtd->map[i].copy_from = ltq_copy_from;
  94. + ltq_mtd->map[i].copy_to = ltq_copy_to;
  95. +
  96. + if (of_find_property(pdev->dev.of_node, "lantiq,noxip", NULL))
  97. + ltq_mtd->map[i].phys = NO_XIP;
  98. + else
  99. + ltq_mtd->map[i].phys = pdev->resource[i].start;
  100. + ltq_mtd->map[i].size = resource_size(&pdev->resource[i]);
  101. + ltq_mtd->map[i].virt = devm_ioremap(&pdev->dev, pdev->resource[i].start,
  102. + ltq_mtd->map[i].size);
  103. + if (IS_ERR(ltq_mtd->map[i].virt))
  104. + return PTR_ERR(ltq_mtd->map[i].virt);
  105. +
  106. + if (ltq_mtd->map[i].virt == NULL) {
  107. + dev_err(&pdev->dev, "Failed to ioremap flash region\n");
  108. + err = PTR_ERR(ltq_mtd->map[i].virt);
  109. + goto err_out;
  110. + }
  111. +
  112. + ltq_mtd->map[i].map_priv_1 = LTQ_NOR_PROBING;
  113. + for (type = rom_probe_types; !ltq_mtd->mtd[i] && *type; type++)
  114. + ltq_mtd->mtd[i] = do_map_probe(*type, &ltq_mtd->map[i]);
  115. + ltq_mtd->map[i].map_priv_1 = LTQ_NOR_NORMAL;
  116. +
  117. + if (!ltq_mtd->mtd[i]) {
  118. + dev_err(&pdev->dev, "probing failed\n");
  119. + return -ENXIO;
  120. + } else {
  121. + devices_found++;
  122. + }
  123. +
  124. + ltq_mtd->mtd[i]->owner = THIS_MODULE;
  125. + ltq_mtd->mtd[i]->dev.parent = &pdev->dev;
  126. +
  127. + cfi = ltq_mtd->map[i].fldrv_priv;
  128. + cfi->addr_unlock1 ^= 1;
  129. + cfi->addr_unlock2 ^= 1;
  130. }
  131. - ltq_mtd->map = devm_kzalloc(&pdev->dev, sizeof(struct map_info),
  132. - GFP_KERNEL);
  133. - if (!ltq_mtd->map)
  134. - return -ENOMEM;
  135. -
  136. - if (of_find_property(pdev->dev.of_node, "lantiq,noxip", NULL))
  137. - ltq_mtd->map->phys = NO_XIP;
  138. - else
  139. - ltq_mtd->map->phys = ltq_mtd->res->start;
  140. - ltq_mtd->res->start;
  141. - ltq_mtd->map->size = resource_size(ltq_mtd->res);
  142. - ltq_mtd->map->virt = devm_ioremap_resource(&pdev->dev, ltq_mtd->res);
  143. - if (IS_ERR(ltq_mtd->map->virt))
  144. - return PTR_ERR(ltq_mtd->map->virt);
  145. -
  146. - ltq_mtd->map->name = ltq_map_name;
  147. - ltq_mtd->map->bankwidth = 2;
  148. - ltq_mtd->map->read = ltq_read16;
  149. - ltq_mtd->map->write = ltq_write16;
  150. - ltq_mtd->map->copy_from = ltq_copy_from;
  151. - ltq_mtd->map->copy_to = ltq_copy_to;
  152. -
  153. - ltq_mtd->map->map_priv_1 = LTQ_NOR_PROBING;
  154. - ltq_mtd->mtd = do_map_probe("cfi_probe", ltq_mtd->map);
  155. - ltq_mtd->map->map_priv_1 = LTQ_NOR_NORMAL;
  156. -
  157. - if (!ltq_mtd->mtd) {
  158. - dev_err(&pdev->dev, "probing failed\n");
  159. - return -ENXIO;
  160. + if (devices_found == 1) {
  161. + ltq_mtd->cmtd = ltq_mtd->mtd[0];
  162. + } else if (devices_found > 1) {
  163. + /*
  164. + * We detected multiple devices. Concatenate them together.
  165. + */
  166. + ltq_mtd->cmtd = mtd_concat_create(ltq_mtd->mtd, devices_found, dev_name(&pdev->dev));
  167. + if (ltq_mtd->cmtd == NULL)
  168. + err = -ENXIO;
  169. }
  170. - ltq_mtd->mtd->dev.parent = &pdev->dev;
  171. - mtd_set_of_node(ltq_mtd->mtd, pdev->dev.of_node);
  172. -
  173. - cfi = ltq_mtd->map->fldrv_priv;
  174. - cfi->addr_unlock1 ^= 1;
  175. - cfi->addr_unlock2 ^= 1;
  176. + ltq_mtd->cmtd->dev.parent = &pdev->dev;
  177. + mtd_set_of_node(ltq_mtd->cmtd, pdev->dev.of_node);
  178. - err = mtd_device_register(ltq_mtd->mtd, NULL, 0);
  179. + err = mtd_device_register(ltq_mtd->cmtd, NULL, 0);
  180. if (err) {
  181. dev_err(&pdev->dev, "failed to add partitions\n");
  182. - goto err_destroy;
  183. + goto err_out;
  184. }
  185. return 0;
  186. -err_destroy:
  187. - map_destroy(ltq_mtd->mtd);
  188. +err_out:
  189. + ltq_mtd_remove(pdev);
  190. return err;
  191. }
  192. -static int
  193. -ltq_mtd_remove(struct platform_device *pdev)
  194. -{
  195. - struct ltq_mtd *ltq_mtd = platform_get_drvdata(pdev);
  196. -
  197. - if (ltq_mtd && ltq_mtd->mtd) {
  198. - mtd_device_unregister(ltq_mtd->mtd);
  199. - map_destroy(ltq_mtd->mtd);
  200. - }
  201. - return 0;
  202. -}
  203. -
  204. static const struct of_device_id ltq_mtd_match[] = {
  205. { .compatible = "lantiq,nor" },
  206. {},