rbtx4939-flash.c 3.2 KB

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