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

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