main.c 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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. struct mtd_info *mtd;
  26. int err = 0;
  27. b47n = devm_kzalloc(&pdev->dev, sizeof(*b47n), GFP_KERNEL);
  28. if (!b47n)
  29. return -ENOMEM;
  30. nand_set_controller_data(&b47n->nand_chip, b47n);
  31. mtd = nand_to_mtd(&b47n->nand_chip);
  32. mtd->dev.parent = &pdev->dev;
  33. b47n->cc = container_of(nflash, struct bcma_drv_cc, nflash);
  34. if (b47n->cc->core->bus->chipinfo.id == BCMA_CHIP_ID_BCM4706) {
  35. err = bcm47xxnflash_ops_bcm4706_init(b47n);
  36. } else {
  37. pr_err("Device not supported\n");
  38. err = -ENOTSUPP;
  39. }
  40. if (err) {
  41. pr_err("Initialization failed: %d\n", err);
  42. return err;
  43. }
  44. platform_set_drvdata(pdev, b47n);
  45. err = mtd_device_parse_register(mtd, probes, NULL, NULL, 0);
  46. if (err) {
  47. pr_err("Failed to register MTD device: %d\n", err);
  48. return err;
  49. }
  50. return 0;
  51. }
  52. static int bcm47xxnflash_remove(struct platform_device *pdev)
  53. {
  54. struct bcm47xxnflash *nflash = platform_get_drvdata(pdev);
  55. nand_release(&nflash->nand_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);