rbtx4939-flash.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. /*
  2. * rbtx4939-flash (based on physmap.c)
  3. *
  4. * This is a simplified physmap driver with map_init callback function.
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License version 2 as
  8. * published by the Free Software Foundation.
  9. *
  10. * Copyright (C) 2009 Atsushi Nemoto <anemo@mba.ocn.ne.jp>
  11. */
  12. #include <linux/module.h>
  13. #include <linux/types.h>
  14. #include <linux/kernel.h>
  15. #include <linux/init.h>
  16. #include <linux/slab.h>
  17. #include <linux/device.h>
  18. #include <linux/platform_device.h>
  19. #include <linux/mtd/mtd.h>
  20. #include <linux/mtd/map.h>
  21. #include <linux/mtd/partitions.h>
  22. #include <asm/txx9/rbtx4939.h>
  23. struct rbtx4939_flash_info {
  24. struct mtd_info *mtd;
  25. struct map_info map;
  26. };
  27. static int rbtx4939_flash_remove(struct platform_device *dev)
  28. {
  29. struct rbtx4939_flash_info *info;
  30. info = platform_get_drvdata(dev);
  31. if (!info)
  32. return 0;
  33. platform_set_drvdata(dev, NULL);
  34. if (info->mtd) {
  35. struct rbtx4939_flash_data *pdata = dev->dev.platform_data;
  36. mtd_device_unregister(info->mtd);
  37. map_destroy(info->mtd);
  38. }
  39. return 0;
  40. }
  41. static const char *rom_probe_types[] = { "cfi_probe", "jedec_probe", NULL };
  42. static int rbtx4939_flash_probe(struct platform_device *dev)
  43. {
  44. struct rbtx4939_flash_data *pdata;
  45. struct rbtx4939_flash_info *info;
  46. struct resource *res;
  47. const char **probe_type;
  48. int err = 0;
  49. unsigned long size;
  50. pdata = dev->dev.platform_data;
  51. if (!pdata)
  52. return -ENODEV;
  53. res = platform_get_resource(dev, IORESOURCE_MEM, 0);
  54. if (!res)
  55. return -ENODEV;
  56. info = devm_kzalloc(&dev->dev, sizeof(struct rbtx4939_flash_info),
  57. GFP_KERNEL);
  58. if (!info)
  59. return -ENOMEM;
  60. platform_set_drvdata(dev, info);
  61. size = resource_size(res);
  62. pr_notice("rbtx4939 platform flash device: %pR\n", res);
  63. if (!devm_request_mem_region(&dev->dev, res->start, size,
  64. dev_name(&dev->dev)))
  65. return -EBUSY;
  66. info->map.name = dev_name(&dev->dev);
  67. info->map.phys = res->start;
  68. info->map.size = size;
  69. info->map.bankwidth = pdata->width;
  70. info->map.virt = devm_ioremap(&dev->dev, info->map.phys, size);
  71. if (!info->map.virt)
  72. return -EBUSY;
  73. if (pdata->map_init)
  74. (*pdata->map_init)(&info->map);
  75. else
  76. simple_map_init(&info->map);
  77. probe_type = rom_probe_types;
  78. for (; !info->mtd && *probe_type; probe_type++)
  79. info->mtd = do_map_probe(*probe_type, &info->map);
  80. if (!info->mtd) {
  81. dev_err(&dev->dev, "map_probe failed\n");
  82. err = -ENXIO;
  83. goto err_out;
  84. }
  85. info->mtd->owner = THIS_MODULE;
  86. if (err)
  87. goto err_out;
  88. err = mtd_device_parse_register(info->mtd, NULL, NULL, pdata->parts,
  89. pdata->nr_parts);
  90. if (err)
  91. goto err_out;
  92. return 0;
  93. err_out:
  94. rbtx4939_flash_remove(dev);
  95. return err;
  96. }
  97. #ifdef CONFIG_PM
  98. static void rbtx4939_flash_shutdown(struct platform_device *dev)
  99. {
  100. struct rbtx4939_flash_info *info = platform_get_drvdata(dev);
  101. if (mtd_suspend(info->mtd) == 0)
  102. mtd_resume(info->mtd);
  103. }
  104. #else
  105. #define rbtx4939_flash_shutdown NULL
  106. #endif
  107. static struct platform_driver rbtx4939_flash_driver = {
  108. .probe = rbtx4939_flash_probe,
  109. .remove = rbtx4939_flash_remove,
  110. .shutdown = rbtx4939_flash_shutdown,
  111. .driver = {
  112. .name = "rbtx4939-flash",
  113. .owner = THIS_MODULE,
  114. },
  115. };
  116. module_platform_driver(rbtx4939_flash_driver);
  117. MODULE_LICENSE("GPL");
  118. MODULE_DESCRIPTION("RBTX4939 MTD map driver");
  119. MODULE_ALIAS("platform:rbtx4939-flash");