generic.c 2.8 KB

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