rbtx4939-flash.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  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/slab.h>
  16. #include <linux/device.h>
  17. #include <linux/platform_device.h>
  18. #include <linux/mtd/mtd.h>
  19. #include <linux/mtd/map.h>
  20. #include <linux/mtd/partitions.h>
  21. #include <asm/txx9/rbtx4939.h>
  22. struct rbtx4939_flash_info {
  23. struct mtd_info *mtd;
  24. struct map_info map;
  25. };
  26. static int rbtx4939_flash_remove(struct platform_device *dev)
  27. {
  28. struct rbtx4939_flash_info *info;
  29. info = platform_get_drvdata(dev);
  30. if (!info)
  31. return 0;
  32. if (info->mtd) {
  33. mtd_device_unregister(info->mtd);
  34. map_destroy(info->mtd);
  35. }
  36. return 0;
  37. }
  38. static const char * const rom_probe_types[] = {
  39. "cfi_probe", "jedec_probe", NULL };
  40. static int rbtx4939_flash_probe(struct platform_device *dev)
  41. {
  42. struct rbtx4939_flash_data *pdata;
  43. struct rbtx4939_flash_info *info;
  44. struct resource *res;
  45. const char * const *probe_type;
  46. int err = 0;
  47. unsigned long size;
  48. pdata = dev_get_platdata(&dev->dev);
  49. if (!pdata)
  50. return -ENODEV;
  51. res = platform_get_resource(dev, IORESOURCE_MEM, 0);
  52. if (!res)
  53. return -ENODEV;
  54. info = devm_kzalloc(&dev->dev, sizeof(struct rbtx4939_flash_info),
  55. GFP_KERNEL);
  56. if (!info)
  57. return -ENOMEM;
  58. platform_set_drvdata(dev, info);
  59. size = resource_size(res);
  60. pr_notice("rbtx4939 platform flash device: %pR\n", res);
  61. if (!devm_request_mem_region(&dev->dev, res->start, size,
  62. dev_name(&dev->dev)))
  63. return -EBUSY;
  64. info->map.name = dev_name(&dev->dev);
  65. info->map.phys = res->start;
  66. info->map.size = size;
  67. info->map.bankwidth = pdata->width;
  68. info->map.virt = devm_ioremap(&dev->dev, info->map.phys, size);
  69. if (!info->map.virt)
  70. return -EBUSY;
  71. if (pdata->map_init)
  72. (*pdata->map_init)(&info->map);
  73. else
  74. simple_map_init(&info->map);
  75. probe_type = rom_probe_types;
  76. for (; !info->mtd && *probe_type; probe_type++)
  77. info->mtd = do_map_probe(*probe_type, &info->map);
  78. if (!info->mtd) {
  79. dev_err(&dev->dev, "map_probe failed\n");
  80. err = -ENXIO;
  81. goto err_out;
  82. }
  83. info->mtd->dev.parent = &dev->dev;
  84. err = mtd_device_parse_register(info->mtd, NULL, NULL, pdata->parts,
  85. pdata->nr_parts);
  86. if (err)
  87. goto err_out;
  88. return 0;
  89. err_out:
  90. rbtx4939_flash_remove(dev);
  91. return err;
  92. }
  93. #ifdef CONFIG_PM
  94. static void rbtx4939_flash_shutdown(struct platform_device *dev)
  95. {
  96. struct rbtx4939_flash_info *info = platform_get_drvdata(dev);
  97. if (mtd_suspend(info->mtd) == 0)
  98. mtd_resume(info->mtd);
  99. }
  100. #else
  101. #define rbtx4939_flash_shutdown NULL
  102. #endif
  103. static struct platform_driver rbtx4939_flash_driver = {
  104. .probe = rbtx4939_flash_probe,
  105. .remove = rbtx4939_flash_remove,
  106. .shutdown = rbtx4939_flash_shutdown,
  107. .driver = {
  108. .name = "rbtx4939-flash",
  109. },
  110. };
  111. module_platform_driver(rbtx4939_flash_driver);
  112. MODULE_LICENSE("GPL");
  113. MODULE_DESCRIPTION("RBTX4939 MTD map driver");
  114. MODULE_ALIAS("platform:rbtx4939-flash");