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

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