mcb-lpc.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. /*
  2. * MEN Chameleon Bus.
  3. *
  4. * Copyright (C) 2014 MEN Mikroelektronik GmbH (www.men.de)
  5. * Author: Andreas Werner <andreas.werner@men.de>
  6. *
  7. * This program is free software; you can redistribute it and/or modify it
  8. * under the terms of the GNU General Public License as published by the Free
  9. * Software Foundation; version 2 of the License.
  10. */
  11. #include <linux/platform_device.h>
  12. #include <linux/module.h>
  13. #include <linux/dmi.h>
  14. #include <linux/mcb.h>
  15. #include <linux/io.h>
  16. #include "mcb-internal.h"
  17. struct priv {
  18. struct mcb_bus *bus;
  19. struct resource *mem;
  20. void __iomem *base;
  21. };
  22. static int mcb_lpc_probe(struct platform_device *pdev)
  23. {
  24. struct resource *res;
  25. struct priv *priv;
  26. int ret = 0;
  27. priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL);
  28. if (!priv)
  29. return -ENOMEM;
  30. priv->mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  31. if (!priv->mem) {
  32. dev_err(&pdev->dev, "No Memory resource\n");
  33. return -ENODEV;
  34. }
  35. res = devm_request_mem_region(&pdev->dev, priv->mem->start,
  36. resource_size(priv->mem),
  37. KBUILD_MODNAME);
  38. if (!res) {
  39. dev_err(&pdev->dev, "Failed to request IO memory\n");
  40. return -EBUSY;
  41. }
  42. priv->base = devm_ioremap(&pdev->dev, priv->mem->start,
  43. resource_size(priv->mem));
  44. if (!priv->base) {
  45. dev_err(&pdev->dev, "Cannot ioremap\n");
  46. return -ENOMEM;
  47. }
  48. platform_set_drvdata(pdev, priv);
  49. priv->bus = mcb_alloc_bus(&pdev->dev);
  50. if (IS_ERR(priv->bus))
  51. return PTR_ERR(priv->bus);
  52. ret = chameleon_parse_cells(priv->bus, priv->mem->start, priv->base);
  53. if (ret < 0) {
  54. mcb_release_bus(priv->bus);
  55. return ret;
  56. }
  57. dev_dbg(&pdev->dev, "Found %d cells\n", ret);
  58. mcb_bus_add_devices(priv->bus);
  59. return 0;
  60. }
  61. static int mcb_lpc_remove(struct platform_device *pdev)
  62. {
  63. struct priv *priv = platform_get_drvdata(pdev);
  64. mcb_release_bus(priv->bus);
  65. return 0;
  66. }
  67. static struct platform_device *mcb_lpc_pdev;
  68. static int mcb_lpc_create_platform_device(const struct dmi_system_id *id)
  69. {
  70. struct resource *res = id->driver_data;
  71. int ret;
  72. mcb_lpc_pdev = platform_device_alloc("mcb-lpc", -1);
  73. if (!mcb_lpc_pdev)
  74. return -ENOMEM;
  75. ret = platform_device_add_resources(mcb_lpc_pdev, res, 1);
  76. if (ret)
  77. goto out_put;
  78. ret = platform_device_add(mcb_lpc_pdev);
  79. if (ret)
  80. goto out_put;
  81. return 0;
  82. out_put:
  83. platform_device_put(mcb_lpc_pdev);
  84. return ret;
  85. }
  86. static struct resource sc24_fpga_resource = {
  87. .start = 0xe000e000,
  88. .end = 0xe000e000 + CHAM_HEADER_SIZE,
  89. .flags = IORESOURCE_MEM,
  90. };
  91. static struct resource sc31_fpga_resource = {
  92. .start = 0xf000e000,
  93. .end = 0xf000e000 + CHAM_HEADER_SIZE,
  94. .flags = IORESOURCE_MEM,
  95. };
  96. static struct platform_driver mcb_lpc_driver = {
  97. .driver = {
  98. .name = "mcb-lpc",
  99. },
  100. .probe = mcb_lpc_probe,
  101. .remove = mcb_lpc_remove,
  102. };
  103. static const struct dmi_system_id mcb_lpc_dmi_table[] = {
  104. {
  105. .ident = "SC24",
  106. .matches = {
  107. DMI_MATCH(DMI_SYS_VENDOR, "MEN"),
  108. DMI_MATCH(DMI_PRODUCT_VERSION, "14SC24"),
  109. },
  110. .driver_data = (void *)&sc24_fpga_resource,
  111. .callback = mcb_lpc_create_platform_device,
  112. },
  113. {
  114. .ident = "SC31",
  115. .matches = {
  116. DMI_MATCH(DMI_SYS_VENDOR, "MEN"),
  117. DMI_MATCH(DMI_PRODUCT_VERSION, "14SC31"),
  118. },
  119. .driver_data = (void *)&sc31_fpga_resource,
  120. .callback = mcb_lpc_create_platform_device,
  121. },
  122. {}
  123. };
  124. MODULE_DEVICE_TABLE(dmi, mcb_lpc_dmi_table);
  125. static int __init mcb_lpc_init(void)
  126. {
  127. if (!dmi_check_system(mcb_lpc_dmi_table))
  128. return -ENODEV;
  129. return platform_driver_register(&mcb_lpc_driver);
  130. }
  131. static void __exit mcb_lpc_exit(void)
  132. {
  133. platform_device_unregister(mcb_lpc_pdev);
  134. platform_driver_unregister(&mcb_lpc_driver);
  135. }
  136. module_init(mcb_lpc_init);
  137. module_exit(mcb_lpc_exit);
  138. MODULE_AUTHOR("Andreas Werner <andreas.werner@men.de>");
  139. MODULE_LICENSE("GPL");
  140. MODULE_DESCRIPTION("MCB over LPC support");