qfprom.c 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. /*
  2. * Copyright (C) 2015 Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License version 2 and
  6. * only version 2 as published by the Free Software Foundation.
  7. *
  8. * This program is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * GNU General Public License for more details.
  12. */
  13. #include <linux/device.h>
  14. #include <linux/module.h>
  15. #include <linux/nvmem-provider.h>
  16. #include <linux/platform_device.h>
  17. #include <linux/regmap.h>
  18. static struct regmap_config qfprom_regmap_config = {
  19. .reg_bits = 32,
  20. .val_bits = 8,
  21. .reg_stride = 1,
  22. };
  23. static struct nvmem_config econfig = {
  24. .name = "qfprom",
  25. .owner = THIS_MODULE,
  26. };
  27. static int qfprom_remove(struct platform_device *pdev)
  28. {
  29. struct nvmem_device *nvmem = platform_get_drvdata(pdev);
  30. return nvmem_unregister(nvmem);
  31. }
  32. static int qfprom_probe(struct platform_device *pdev)
  33. {
  34. struct device *dev = &pdev->dev;
  35. struct resource *res;
  36. struct nvmem_device *nvmem;
  37. struct regmap *regmap;
  38. void __iomem *base;
  39. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  40. base = devm_ioremap_resource(dev, res);
  41. if (IS_ERR(base))
  42. return PTR_ERR(base);
  43. qfprom_regmap_config.max_register = resource_size(res) - 1;
  44. regmap = devm_regmap_init_mmio(dev, base, &qfprom_regmap_config);
  45. if (IS_ERR(regmap)) {
  46. dev_err(dev, "regmap init failed\n");
  47. return PTR_ERR(regmap);
  48. }
  49. econfig.dev = dev;
  50. nvmem = nvmem_register(&econfig);
  51. if (IS_ERR(nvmem))
  52. return PTR_ERR(nvmem);
  53. platform_set_drvdata(pdev, nvmem);
  54. return 0;
  55. }
  56. static const struct of_device_id qfprom_of_match[] = {
  57. { .compatible = "qcom,qfprom",},
  58. {/* sentinel */},
  59. };
  60. MODULE_DEVICE_TABLE(of, qfprom_of_match);
  61. static struct platform_driver qfprom_driver = {
  62. .probe = qfprom_probe,
  63. .remove = qfprom_remove,
  64. .driver = {
  65. .name = "qcom,qfprom",
  66. .of_match_table = qfprom_of_match,
  67. },
  68. };
  69. module_platform_driver(qfprom_driver);
  70. MODULE_AUTHOR("Srinivas Kandagatla <srinivas.kandagatla@linaro.org>");
  71. MODULE_DESCRIPTION("Qualcomm QFPROM driver");
  72. MODULE_LICENSE("GPL v2");