main.c 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * BCM47XX NAND flash driver
  4. *
  5. * Copyright (C) 2012 Rafał Miłecki <[email protected]>
  6. */
  7. #include "bcm47xxnflash.h"
  8. #include <linux/module.h>
  9. #include <linux/kernel.h>
  10. #include <linux/slab.h>
  11. #include <linux/platform_device.h>
  12. #include <linux/bcma/bcma.h>
  13. MODULE_DESCRIPTION("NAND flash driver for BCMA bus");
  14. MODULE_LICENSE("GPL");
  15. MODULE_AUTHOR("Rafał Miłecki");
  16. static const char *probes[] = { "bcm47xxpart", NULL };
  17. static int bcm47xxnflash_probe(struct platform_device *pdev)
  18. {
  19. struct bcma_nflash *nflash = dev_get_platdata(&pdev->dev);
  20. struct bcm47xxnflash *b47n;
  21. struct mtd_info *mtd;
  22. int err = 0;
  23. b47n = devm_kzalloc(&pdev->dev, sizeof(*b47n), GFP_KERNEL);
  24. if (!b47n)
  25. return -ENOMEM;
  26. nand_set_controller_data(&b47n->nand_chip, b47n);
  27. mtd = nand_to_mtd(&b47n->nand_chip);
  28. mtd->dev.parent = &pdev->dev;
  29. b47n->cc = container_of(nflash, struct bcma_drv_cc, nflash);
  30. if (b47n->cc->core->bus->chipinfo.id == BCMA_CHIP_ID_BCM4706) {
  31. err = bcm47xxnflash_ops_bcm4706_init(b47n);
  32. } else {
  33. pr_err("Device not supported\n");
  34. err = -ENOTSUPP;
  35. }
  36. if (err) {
  37. pr_err("Initialization failed: %d\n", err);
  38. return err;
  39. }
  40. platform_set_drvdata(pdev, b47n);
  41. err = mtd_device_parse_register(mtd, probes, NULL, NULL, 0);
  42. if (err) {
  43. pr_err("Failed to register MTD device: %d\n", err);
  44. return err;
  45. }
  46. return 0;
  47. }
  48. static int bcm47xxnflash_remove(struct platform_device *pdev)
  49. {
  50. struct bcm47xxnflash *nflash = platform_get_drvdata(pdev);
  51. struct nand_chip *chip = &nflash->nand_chip;
  52. int ret;
  53. ret = mtd_device_unregister(nand_to_mtd(chip));
  54. WARN_ON(ret);
  55. nand_cleanup(chip);
  56. return 0;
  57. }
  58. static struct platform_driver bcm47xxnflash_driver = {
  59. .probe = bcm47xxnflash_probe,
  60. .remove = bcm47xxnflash_remove,
  61. .driver = {
  62. .name = "bcma_nflash",
  63. },
  64. };
  65. module_platform_driver(bcm47xxnflash_driver);