generic.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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/init.h>
  16. #include <linux/slab.h>
  17. #include <linux/platform_device.h>
  18. #include <linux/mtd/mtd.h>
  19. #include <linux/mtd/onenand.h>
  20. #include <linux/mtd/partitions.h>
  21. #include <asm/io.h>
  22. /*
  23. * Note: Driver name and platform data format have been updated!
  24. *
  25. * This version of the driver is named "onenand-flash" and takes struct
  26. * onenand_platform_data as platform data. The old ARM-specific version
  27. * with the name "onenand" used to take struct flash_platform_data.
  28. */
  29. #define DRIVER_NAME "onenand-flash"
  30. struct onenand_info {
  31. struct mtd_info mtd;
  32. struct onenand_chip onenand;
  33. };
  34. static int __devinit generic_onenand_probe(struct platform_device *pdev)
  35. {
  36. struct onenand_info *info;
  37. struct onenand_platform_data *pdata = pdev->dev.platform_data;
  38. struct resource *res = pdev->resource;
  39. unsigned long size = resource_size(res);
  40. int err;
  41. info = kzalloc(sizeof(struct onenand_info), GFP_KERNEL);
  42. if (!info)
  43. return -ENOMEM;
  44. if (!request_mem_region(res->start, size, dev_name(&pdev->dev))) {
  45. err = -EBUSY;
  46. goto out_free_info;
  47. }
  48. info->onenand.base = ioremap(res->start, size);
  49. if (!info->onenand.base) {
  50. err = -ENOMEM;
  51. goto out_release_mem_region;
  52. }
  53. info->onenand.mmcontrol = pdata ? pdata->mmcontrol : 0;
  54. info->onenand.irq = platform_get_irq(pdev, 0);
  55. info->mtd.name = dev_name(&pdev->dev);
  56. info->mtd.priv = &info->onenand;
  57. info->mtd.owner = THIS_MODULE;
  58. if (onenand_scan(&info->mtd, 1)) {
  59. err = -ENXIO;
  60. goto out_iounmap;
  61. }
  62. err = mtd_device_parse_register(&info->mtd, NULL, NULL,
  63. pdata ? pdata->parts : NULL,
  64. pdata ? pdata->nr_parts : 0);
  65. platform_set_drvdata(pdev, info);
  66. return 0;
  67. out_iounmap:
  68. iounmap(info->onenand.base);
  69. out_release_mem_region:
  70. release_mem_region(res->start, size);
  71. out_free_info:
  72. kfree(info);
  73. return err;
  74. }
  75. static int __devexit generic_onenand_remove(struct platform_device *pdev)
  76. {
  77. struct onenand_info *info = platform_get_drvdata(pdev);
  78. struct resource *res = pdev->resource;
  79. unsigned long size = resource_size(res);
  80. platform_set_drvdata(pdev, NULL);
  81. if (info) {
  82. onenand_release(&info->mtd);
  83. release_mem_region(res->start, size);
  84. iounmap(info->onenand.base);
  85. kfree(info);
  86. }
  87. return 0;
  88. }
  89. static struct platform_driver generic_onenand_driver = {
  90. .driver = {
  91. .name = DRIVER_NAME,
  92. .owner = THIS_MODULE,
  93. },
  94. .probe = generic_onenand_probe,
  95. .remove = __devexit_p(generic_onenand_remove),
  96. };
  97. module_platform_driver(generic_onenand_driver);
  98. MODULE_LICENSE("GPL");
  99. MODULE_AUTHOR("Kyungmin Park <kyungmin.park@samsung.com>");
  100. MODULE_DESCRIPTION("Glue layer for OneNAND flash on generic boards");
  101. MODULE_ALIAS("platform:" DRIVER_NAME);