1 // SPDX-License-Identifier: GPL-2.0-only
5 * Copyright (C) 2014 MEN Mikroelektronik GmbH (www.men.de)
6 * Author: Andreas Werner <andreas.werner@men.de>
9 #include <linux/platform_device.h>
10 #include <linux/module.h>
11 #include <linux/dmi.h>
12 #include <linux/mcb.h>
14 #include "mcb-internal.h"
22 static int mcb_lpc_probe(struct platform_device *pdev)
26 int ret = 0, table_size;
28 priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL);
32 priv->mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
34 dev_err(&pdev->dev, "No Memory resource\n");
38 res = devm_request_mem_region(&pdev->dev, priv->mem->start,
39 resource_size(priv->mem),
42 dev_err(&pdev->dev, "Failed to request IO memory\n");
46 priv->base = devm_ioremap(&pdev->dev, priv->mem->start,
47 resource_size(priv->mem));
49 dev_err(&pdev->dev, "Cannot ioremap\n");
53 platform_set_drvdata(pdev, priv);
55 priv->bus = mcb_alloc_bus(&pdev->dev);
56 if (IS_ERR(priv->bus))
57 return PTR_ERR(priv->bus);
59 ret = chameleon_parse_cells(priv->bus, priv->mem->start, priv->base);
66 if (table_size < CHAM_HEADER_SIZE) {
67 /* Release the previous resources */
68 devm_iounmap(&pdev->dev, priv->base);
69 devm_release_mem_region(&pdev->dev, priv->mem->start, resource_size(priv->mem));
71 /* Then, allocate it again with the actual chameleon table size */
72 res = devm_request_mem_region(&pdev->dev, priv->mem->start,
76 dev_err(&pdev->dev, "Failed to request PCI memory\n");
81 priv->base = devm_ioremap(&pdev->dev, priv->mem->start, table_size);
83 dev_err(&pdev->dev, "Cannot ioremap\n");
88 platform_set_drvdata(pdev, priv);
91 mcb_bus_add_devices(priv->bus);
96 mcb_release_bus(priv->bus);
100 static int mcb_lpc_remove(struct platform_device *pdev)
102 struct priv *priv = platform_get_drvdata(pdev);
104 mcb_release_bus(priv->bus);
109 static struct platform_device *mcb_lpc_pdev;
111 static int mcb_lpc_create_platform_device(const struct dmi_system_id *id)
113 struct resource *res = id->driver_data;
116 mcb_lpc_pdev = platform_device_alloc("mcb-lpc", -1);
120 ret = platform_device_add_resources(mcb_lpc_pdev, res, 1);
124 ret = platform_device_add(mcb_lpc_pdev);
131 platform_device_put(mcb_lpc_pdev);
135 static struct resource sc24_fpga_resource = DEFINE_RES_MEM(0xe000e000, CHAM_HEADER_SIZE);
136 static struct resource sc31_fpga_resource = DEFINE_RES_MEM(0xf000e000, CHAM_HEADER_SIZE);
138 static struct platform_driver mcb_lpc_driver = {
142 .probe = mcb_lpc_probe,
143 .remove = mcb_lpc_remove,
146 static const struct dmi_system_id mcb_lpc_dmi_table[] = {
150 DMI_MATCH(DMI_SYS_VENDOR, "MEN"),
151 DMI_MATCH(DMI_PRODUCT_VERSION, "14SC24"),
153 .driver_data = (void *)&sc24_fpga_resource,
154 .callback = mcb_lpc_create_platform_device,
159 DMI_MATCH(DMI_SYS_VENDOR, "MEN"),
160 DMI_MATCH(DMI_PRODUCT_VERSION, "14SC31"),
162 .driver_data = (void *)&sc31_fpga_resource,
163 .callback = mcb_lpc_create_platform_device,
167 MODULE_DEVICE_TABLE(dmi, mcb_lpc_dmi_table);
169 static int __init mcb_lpc_init(void)
171 if (!dmi_check_system(mcb_lpc_dmi_table))
174 return platform_driver_register(&mcb_lpc_driver);
177 static void __exit mcb_lpc_exit(void)
179 platform_device_unregister(mcb_lpc_pdev);
180 platform_driver_unregister(&mcb_lpc_driver);
183 module_init(mcb_lpc_init);
184 module_exit(mcb_lpc_exit);
186 MODULE_AUTHOR("Andreas Werner <andreas.werner@men.de>");
187 MODULE_LICENSE("GPL");
188 MODULE_DESCRIPTION("MCB over LPC support");
189 MODULE_IMPORT_NS(MCB);