main.c 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. /*
  2. * BCM47XX NAND flash driver
  3. *
  4. * Copyright (C) 2012 Rafał Miłecki <zajec5@gmail.com>
  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. */
  11. #include "bcm47xxnflash.h"
  12. #include <linux/module.h>
  13. #include <linux/kernel.h>
  14. #include <linux/slab.h>
  15. #include <linux/platform_device.h>
  16. #include <linux/bcma/bcma.h>
  17. MODULE_DESCRIPTION("NAND flash driver for BCMA bus");
  18. MODULE_LICENSE("GPL");
  19. MODULE_AUTHOR("Rafał Miłecki");
  20. static const char *probes[] = { "bcm47xxpart", NULL };
  21. static int bcm47xxnflash_probe(struct platform_device *pdev)
  22. {
  23. struct bcma_nflash *nflash = dev_get_platdata(&pdev->dev);
  24. struct bcm47xxnflash *b47n;
  25. int err = 0;
  26. b47n = kzalloc(sizeof(*b47n), GFP_KERNEL);
  27. if (!b47n) {
  28. err = -ENOMEM;
  29. goto out;
  30. }
  31. b47n->nand_chip.priv = b47n;
  32. b47n->mtd.owner = THIS_MODULE;
  33. b47n->mtd.priv = &b47n->nand_chip; /* Required */
  34. b47n->cc = container_of(nflash, struct bcma_drv_cc, nflash);
  35. if (b47n->cc->core->bus->chipinfo.id == BCMA_CHIP_ID_BCM4706) {
  36. err = bcm47xxnflash_ops_bcm4706_init(b47n);
  37. } else {
  38. pr_err("Device not supported\n");
  39. err = -ENOTSUPP;
  40. }
  41. if (err) {
  42. pr_err("Initialization failed: %d\n", err);
  43. goto err_init;
  44. }
  45. err = mtd_device_parse_register(&b47n->mtd, probes, NULL, NULL, 0);
  46. if (err) {
  47. pr_err("Failed to register MTD device: %d\n", err);
  48. goto err_dev_reg;
  49. }
  50. return 0;
  51. err_dev_reg:
  52. err_init:
  53. kfree(b47n);
  54. out:
  55. return err;
  56. }
  57. static int bcm47xxnflash_remove(struct platform_device *pdev)
  58. {
  59. struct bcma_nflash *nflash = dev_get_platdata(&pdev->dev);
  60. if (nflash->mtd)
  61. mtd_device_unregister(nflash->mtd);
  62. return 0;
  63. }
  64. static struct platform_driver bcm47xxnflash_driver = {
  65. .probe = bcm47xxnflash_probe,
  66. .remove = bcm47xxnflash_remove,
  67. .driver = {
  68. .name = "bcma_nflash",
  69. .owner = THIS_MODULE,
  70. },
  71. };
  72. static int __init bcm47xxnflash_init(void)
  73. {
  74. int err;
  75. err = platform_driver_register(&bcm47xxnflash_driver);
  76. if (err)
  77. pr_err("Failed to register bcm47xx nand flash driver: %d\n",
  78. err);
  79. return err;
  80. }
  81. static void __exit bcm47xxnflash_exit(void)
  82. {
  83. platform_driver_unregister(&bcm47xxnflash_driver);
  84. }
  85. module_init(bcm47xxnflash_init);
  86. module_exit(bcm47xxnflash_exit);