rbtx4939-flash.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  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 * const rom_probe_types[] = {
  42. "cfi_probe", "jedec_probe", NULL };
  43. static int rbtx4939_flash_probe(struct platform_device *dev)
  44. {
  45. struct rbtx4939_flash_data *pdata;
  46. struct rbtx4939_flash_info *info;
  47. struct resource *res;
  48. const char * const *probe_type;
  49. int err = 0;
  50. unsigned long size;
  51. pdata = dev->dev.platform_data;
  52. if (!pdata)
  53. return -ENODEV;
  54. res = platform_get_resource(dev, IORESOURCE_MEM, 0);
  55. if (!res)
  56. return -ENODEV;
  57. info = devm_kzalloc(&dev->dev, sizeof(struct rbtx4939_flash_info),
  58. GFP_KERNEL);
  59. if (!info)
  60. return -ENOMEM;
  61. platform_set_drvdata(dev, info);
  62. size = resource_size(res);
  63. pr_notice("rbtx4939 platform flash device: %pR\n", res);
  64. if (!devm_request_mem_region(&dev->dev, res->start, size,
  65. dev_name(&dev->dev)))
  66. return -EBUSY;
  67. info->map.name = dev_name(&dev->dev);
  68. info->map.phys = res->start;
  69. info->map.size = size;
  70. info->map.bankwidth = pdata->width;
  71. info->map.virt = devm_ioremap(&dev->dev, info->map.phys, size);
  72. if (!info->map.virt)
  73. return -EBUSY;
  74. if (pdata->map_init)
  75. (*pdata->map_init)(&info->map);
  76. else
  77. simple_map_init(&info->map);
  78. probe_type = rom_probe_types;
  79. for (; !info->mtd && *probe_type; probe_type++)
  80. info->mtd = do_map_probe(*probe_type, &info->map);
  81. if (!info->mtd) {
  82. dev_err(&dev->dev, "map_probe failed\n");
  83. err = -ENXIO;
  84. goto err_out;
  85. }
  86. info->mtd->owner = THIS_MODULE;
  87. err = mtd_device_parse_register(info->mtd, NULL, NULL, pdata->parts,
  88. pdata->nr_parts);
  89. if (err)
  90. goto err_out;
  91. return 0;
  92. err_out:
  93. rbtx4939_flash_remove(dev);
  94. return err;
  95. }
  96. #ifdef CONFIG_PM
  97. static void rbtx4939_flash_shutdown(struct platform_device *dev)
  98. {
  99. struct rbtx4939_flash_info *info = platform_get_drvdata(dev);
  100. if (mtd_suspend(info->mtd) == 0)
  101. mtd_resume(info->mtd);
  102. }
  103. #else
  104. #define rbtx4939_flash_shutdown NULL
  105. #endif
  106. static struct platform_driver rbtx4939_flash_driver = {
  107. .probe = rbtx4939_flash_probe,
  108. .remove = rbtx4939_flash_remove,
  109. .shutdown = rbtx4939_flash_shutdown,
  110. .driver = {
  111. .name = "rbtx4939-flash",
  112. .owner = THIS_MODULE,
  113. },
  114. };
  115. module_platform_driver(rbtx4939_flash_driver);
  116. MODULE_LICENSE("GPL");
  117. MODULE_DESCRIPTION("RBTX4939 MTD map driver");
  118. MODULE_ALIAS("platform:rbtx4939-flash");