generic.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. /*
  2. * linux/drivers/mtd/onenand/generic.c
  3. *
  4. * Copyright (c) 2005 Samsung Electronics
  5. * Kyungmin Park <kyungmin.park@samsung.com>
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License version 2 as
  9. * published by the Free Software Foundation.
  10. *
  11. * Overview:
  12. * This is a device driver for the OneNAND flash for generic boards.
  13. */
  14. #include <linux/module.h>
  15. #include <linux/slab.h>
  16. #include <linux/platform_device.h>
  17. #include <linux/mtd/mtd.h>
  18. #include <linux/mtd/onenand.h>
  19. #include <linux/mtd/partitions.h>
  20. #include <linux/io.h>
  21. /*
  22. * Note: Driver name and platform data format have been updated!
  23. *
  24. * This version of the driver is named "onenand-flash" and takes struct
  25. * onenand_platform_data as platform data. The old ARM-specific version
  26. * with the name "onenand" used to take struct flash_platform_data.
  27. */
  28. #define DRIVER_NAME "onenand-flash"
  29. struct onenand_info {
  30. struct mtd_info mtd;
  31. struct onenand_chip onenand;
  32. };
  33. static int generic_onenand_probe(struct platform_device *pdev)
  34. {
  35. struct onenand_info *info;
  36. struct onenand_platform_data *pdata = dev_get_platdata(&pdev->dev);
  37. struct resource *res = pdev->resource;
  38. unsigned long size = resource_size(res);
  39. int err;
  40. info = kzalloc(sizeof(struct onenand_info), GFP_KERNEL);
  41. if (!info)
  42. return -ENOMEM;
  43. if (!request_mem_region(res->start, size, dev_name(&pdev->dev))) {
  44. err = -EBUSY;
  45. goto out_free_info;
  46. }
  47. info->onenand.base = ioremap(res->start, size);
  48. if (!info->onenand.base) {
  49. err = -ENOMEM;
  50. goto out_release_mem_region;
  51. }
  52. info->onenand.mmcontrol = pdata ? pdata->mmcontrol : NULL;
  53. info->onenand.irq = platform_get_irq(pdev, 0);
  54. info->mtd.dev.parent = &pdev->dev;
  55. info->mtd.priv = &info->onenand;
  56. if (onenand_scan(&info->mtd, 1)) {
  57. err = -ENXIO;
  58. goto out_iounmap;
  59. }
  60. err = mtd_device_parse_register(&info->mtd, NULL, NULL,
  61. pdata ? pdata->parts : NULL,
  62. pdata ? pdata->nr_parts : 0);
  63. platform_set_drvdata(pdev, info);
  64. return 0;
  65. out_iounmap:
  66. iounmap(info->onenand.base);
  67. out_release_mem_region:
  68. release_mem_region(res->start, size);
  69. out_free_info:
  70. kfree(info);
  71. return err;
  72. }
  73. static int generic_onenand_remove(struct platform_device *pdev)
  74. {
  75. struct onenand_info *info = platform_get_drvdata(pdev);
  76. struct resource *res = pdev->resource;
  77. unsigned long size = resource_size(res);
  78. if (info) {
  79. onenand_release(&info->mtd);
  80. release_mem_region(res->start, size);
  81. iounmap(info->onenand.base);
  82. kfree(info);
  83. }
  84. return 0;
  85. }
  86. static struct platform_driver generic_onenand_driver = {
  87. .driver = {
  88. .name = DRIVER_NAME,
  89. },
  90. .probe = generic_onenand_probe,
  91. .remove = generic_onenand_remove,
  92. };
  93. module_platform_driver(generic_onenand_driver);
  94. MODULE_LICENSE("GPL");
  95. MODULE_AUTHOR("Kyungmin Park <kyungmin.park@samsung.com>");
  96. MODULE_DESCRIPTION("Glue layer for OneNAND flash on generic boards");
  97. MODULE_ALIAS("platform:" DRIVER_NAME);