1 // SPDX-License-Identifier: GPL-2.0+
4 * Add an IPMI platform device.
7 #include <linux/platform_device.h>
8 #include "ipmi_plat_data.h"
11 struct platform_device *ipmi_platform_add(const char *name, unsigned int inst,
12 struct ipmi_plat_data *p)
14 struct platform_device *pdev;
15 unsigned int num_r = 1, size = 0, pidx = 0;
17 struct property_entry pr[6];
21 memset(pr, 0, sizeof(pr));
22 memset(r, 0, sizeof(r));
24 if (p->iftype == IPMI_PLAT_IF_SI) {
27 else if (p->type != SI_TYPE_INVALID)
31 p->regsize = DEFAULT_REGSIZE;
32 if (p->regspacing == 0)
33 p->regspacing = p->regsize;
35 pr[pidx++] = PROPERTY_ENTRY_U8("ipmi-type", p->type);
36 } else if (p->iftype == IPMI_PLAT_IF_SSIF) {
37 pr[pidx++] = PROPERTY_ENTRY_U16("i2c-addr", p->addr);
41 pr[pidx++] = PROPERTY_ENTRY_U8("slave-addr", p->slave_addr);
42 pr[pidx++] = PROPERTY_ENTRY_U8("addr-source", p->addr_source);
44 pr[pidx++] = PROPERTY_ENTRY_U8("reg-shift", p->regshift);
45 pr[pidx++] = PROPERTY_ENTRY_U8("reg-size", p->regsize);
46 /* Last entry must be left NULL to terminate it. */
48 pdev = platform_device_alloc(name, inst);
50 pr_err("Error allocating IPMI platform device %s.%d\n",
56 /* An invalid or SSIF interface, no resources. */
60 * Register spacing is derived from the resources in
61 * the IPMI platform code.
64 if (p->space == IPMI_IO_ADDR_SPACE)
65 flags = IORESOURCE_IO;
67 flags = IORESOURCE_MEM;
70 r[0].end = r[0].start + p->regsize - 1;
71 r[0].name = "IPMI Address 1";
75 r[1].start = r[0].start + p->regspacing;
76 r[1].end = r[1].start + p->regsize - 1;
77 r[1].name = "IPMI Address 2";
83 r[2].start = r[1].start + p->regspacing;
84 r[2].end = r[2].start + p->regsize - 1;
85 r[2].name = "IPMI Address 3";
91 r[num_r].start = p->irq;
92 r[num_r].end = p->irq;
93 r[num_r].name = "IPMI IRQ";
94 r[num_r].flags = IORESOURCE_IRQ;
98 rv = platform_device_add_resources(pdev, r, num_r);
101 "Unable to add hard-code resources: %d\n", rv);
105 rv = device_create_managed_software_node(&pdev->dev, pr, NULL);
108 "Unable to add hard-code properties: %d\n", rv);
112 rv = platform_device_add(pdev);
115 "Unable to add hard-code device: %d\n", rv);
121 platform_device_put(pdev);
124 EXPORT_SYMBOL(ipmi_platform_add);