xref: /openbmc/linux/drivers/char/ipmi/ipmi_si_platform.c (revision c900529f3d9161bfde5cca0754f83b4d3c3e0220)
1243ac210SCorey Minyard // SPDX-License-Identifier: GPL-2.0+
29d70029eSCorey Minyard /*
39d70029eSCorey Minyard  * ipmi_si_platform.c
49d70029eSCorey Minyard  *
59d70029eSCorey Minyard  * Handling for platform devices in IPMI (ACPI, OF, and things
69d70029eSCorey Minyard  * coming from the platform.
79d70029eSCorey Minyard  */
825880f7dSJoe Perches 
925880f7dSJoe Perches #define pr_fmt(fmt) "ipmi_platform: " fmt
1025880f7dSJoe Perches #define dev_fmt pr_fmt
1125880f7dSJoe Perches 
129d70029eSCorey Minyard #include <linux/types.h>
139d70029eSCorey Minyard #include <linux/module.h>
149d70029eSCorey Minyard #include <linux/of_device.h>
159d70029eSCorey Minyard #include <linux/of_platform.h>
169d70029eSCorey Minyard #include <linux/of_address.h>
179d70029eSCorey Minyard #include <linux/of_irq.h>
189d70029eSCorey Minyard #include <linux/acpi.h>
199d70029eSCorey Minyard #include "ipmi_si.h"
2095e300c0SCorey Minyard #include "ipmi_dmi.h"
219d70029eSCorey Minyard 
222f663539SKefeng Wang static bool platform_registered;
239d70029eSCorey Minyard static bool si_tryplatform = true;
249d70029eSCorey Minyard #ifdef CONFIG_ACPI
259d70029eSCorey Minyard static bool          si_tryacpi = true;
269d70029eSCorey Minyard #endif
2795e300c0SCorey Minyard #ifdef CONFIG_OF
2895e300c0SCorey Minyard static bool          si_tryopenfirmware = true;
2995e300c0SCorey Minyard #endif
309d70029eSCorey Minyard #ifdef CONFIG_DMI
319d70029eSCorey Minyard static bool          si_trydmi = true;
3295e300c0SCorey Minyard #else
3395e300c0SCorey Minyard static bool          si_trydmi = false;
349d70029eSCorey Minyard #endif
359d70029eSCorey Minyard 
369d70029eSCorey Minyard module_param_named(tryplatform, si_tryplatform, bool, 0);
3707cbd87bSAndy Shevchenko MODULE_PARM_DESC(tryplatform,
3807cbd87bSAndy Shevchenko 		 "Setting this to zero will disable the default scan of the interfaces identified via platform interfaces besides ACPI, OpenFirmware, and DMI");
399d70029eSCorey Minyard #ifdef CONFIG_ACPI
409d70029eSCorey Minyard module_param_named(tryacpi, si_tryacpi, bool, 0);
4107cbd87bSAndy Shevchenko MODULE_PARM_DESC(tryacpi,
4207cbd87bSAndy Shevchenko 		 "Setting this to zero will disable the default scan of the interfaces identified via ACPI");
439d70029eSCorey Minyard #endif
4495e300c0SCorey Minyard #ifdef CONFIG_OF
4595e300c0SCorey Minyard module_param_named(tryopenfirmware, si_tryopenfirmware, bool, 0);
4607cbd87bSAndy Shevchenko MODULE_PARM_DESC(tryopenfirmware,
4707cbd87bSAndy Shevchenko 		 "Setting this to zero will disable the default scan of the interfaces identified via OpenFirmware");
4895e300c0SCorey Minyard #endif
499d70029eSCorey Minyard #ifdef CONFIG_DMI
509d70029eSCorey Minyard module_param_named(trydmi, si_trydmi, bool, 0);
5107cbd87bSAndy Shevchenko MODULE_PARM_DESC(trydmi,
5207cbd87bSAndy Shevchenko 		 "Setting this to zero will disable the default scan of the interfaces identified via DMI");
539d70029eSCorey Minyard #endif
549d70029eSCorey Minyard 
559d70029eSCorey Minyard #ifdef CONFIG_ACPI
569d70029eSCorey Minyard /* For GPE-type interrupts. */
ipmi_acpi_gpe(acpi_handle gpe_device,u32 gpe_number,void * context)579d70029eSCorey Minyard static u32 ipmi_acpi_gpe(acpi_handle gpe_device,
589d70029eSCorey Minyard 	u32 gpe_number, void *context)
599d70029eSCorey Minyard {
609d70029eSCorey Minyard 	struct si_sm_io *io = context;
619d70029eSCorey Minyard 
629d70029eSCorey Minyard 	ipmi_si_irq_handler(io->irq, io->irq_handler_data);
639d70029eSCorey Minyard 	return ACPI_INTERRUPT_HANDLED;
649d70029eSCorey Minyard }
659d70029eSCorey Minyard 
acpi_gpe_irq_cleanup(struct si_sm_io * io)669d70029eSCorey Minyard static void acpi_gpe_irq_cleanup(struct si_sm_io *io)
679d70029eSCorey Minyard {
689d70029eSCorey Minyard 	if (!io->irq)
699d70029eSCorey Minyard 		return;
709d70029eSCorey Minyard 
719d70029eSCorey Minyard 	ipmi_irq_start_cleanup(io);
729d70029eSCorey Minyard 	acpi_remove_gpe_handler(NULL, io->irq, &ipmi_acpi_gpe);
739d70029eSCorey Minyard }
749d70029eSCorey Minyard 
acpi_gpe_irq_setup(struct si_sm_io * io)759d70029eSCorey Minyard static int acpi_gpe_irq_setup(struct si_sm_io *io)
769d70029eSCorey Minyard {
779d70029eSCorey Minyard 	acpi_status status;
789d70029eSCorey Minyard 
799d70029eSCorey Minyard 	if (!io->irq)
809d70029eSCorey Minyard 		return 0;
819d70029eSCorey Minyard 
829d70029eSCorey Minyard 	status = acpi_install_gpe_handler(NULL,
839d70029eSCorey Minyard 					  io->irq,
849d70029eSCorey Minyard 					  ACPI_GPE_LEVEL_TRIGGERED,
859d70029eSCorey Minyard 					  &ipmi_acpi_gpe,
869d70029eSCorey Minyard 					  io);
87bd7a33bfSAndy Shevchenko 	if (ACPI_FAILURE(status)) {
889d70029eSCorey Minyard 		dev_warn(io->dev,
899d70029eSCorey Minyard 			 "Unable to claim ACPI GPE %d, running polled\n",
909d70029eSCorey Minyard 			 io->irq);
919d70029eSCorey Minyard 		io->irq = 0;
929d70029eSCorey Minyard 		return -EINVAL;
93bd7a33bfSAndy Shevchenko 	}
94bd7a33bfSAndy Shevchenko 
959d70029eSCorey Minyard 	io->irq_cleanup = acpi_gpe_irq_cleanup;
969d70029eSCorey Minyard 	ipmi_irq_finish_setup(io);
979d70029eSCorey Minyard 	dev_info(io->dev, "Using ACPI GPE %d\n", io->irq);
989d70029eSCorey Minyard 	return 0;
999d70029eSCorey Minyard }
1009d70029eSCorey Minyard #endif
1019d70029eSCorey Minyard 
ipmi_set_addr_data_and_space(struct resource * r,struct si_sm_io * io)102079dea00SAndy Shevchenko static void ipmi_set_addr_data_and_space(struct resource *r, struct si_sm_io *io)
103079dea00SAndy Shevchenko {
104079dea00SAndy Shevchenko 	if (resource_type(r) == IORESOURCE_IO)
105079dea00SAndy Shevchenko 		io->addr_space = IPMI_IO_ADDR_SPACE;
106079dea00SAndy Shevchenko 	else
107079dea00SAndy Shevchenko 		io->addr_space = IPMI_MEM_ADDR_SPACE;
108079dea00SAndy Shevchenko 	io->addr_data = r->start;
109079dea00SAndy Shevchenko }
110079dea00SAndy Shevchenko 
1119d70029eSCorey Minyard static struct resource *
ipmi_get_info_from_resources(struct platform_device * pdev,struct si_sm_io * io)1129d70029eSCorey Minyard ipmi_get_info_from_resources(struct platform_device *pdev,
1139d70029eSCorey Minyard 			     struct si_sm_io *io)
1149d70029eSCorey Minyard {
1159d70029eSCorey Minyard 	struct resource *res, *res_second;
1169d70029eSCorey Minyard 
117079dea00SAndy Shevchenko 	res = platform_get_mem_or_io(pdev, 0);
1189d70029eSCorey Minyard 	if (!res) {
1199d70029eSCorey Minyard 		dev_err(&pdev->dev, "no I/O or memory address\n");
1209d70029eSCorey Minyard 		return NULL;
1219d70029eSCorey Minyard 	}
122079dea00SAndy Shevchenko 	ipmi_set_addr_data_and_space(res, io);
1239d70029eSCorey Minyard 
1249d70029eSCorey Minyard 	io->regspacing = DEFAULT_REGSPACING;
125079dea00SAndy Shevchenko 	res_second = platform_get_mem_or_io(pdev, 1);
126079dea00SAndy Shevchenko 	if (res_second && resource_type(res_second) == resource_type(res)) {
1279d70029eSCorey Minyard 		if (res_second->start > io->addr_data)
1289d70029eSCorey Minyard 			io->regspacing = res_second->start - io->addr_data;
1299d70029eSCorey Minyard 	}
1309d70029eSCorey Minyard 
1319d70029eSCorey Minyard 	return res;
1329d70029eSCorey Minyard }
1339d70029eSCorey Minyard 
platform_ipmi_probe(struct platform_device * pdev)13495e300c0SCorey Minyard static int platform_ipmi_probe(struct platform_device *pdev)
1359d70029eSCorey Minyard {
1369d70029eSCorey Minyard 	struct si_sm_io io;
13741b766d6SCorey Minyard 	u8 type, slave_addr, addr_source, regsize, regshift;
1389d70029eSCorey Minyard 	int rv;
1399d70029eSCorey Minyard 
14095e300c0SCorey Minyard 	rv = device_property_read_u8(&pdev->dev, "addr-source", &addr_source);
14195e300c0SCorey Minyard 	if (rv)
14295e300c0SCorey Minyard 		addr_source = SI_PLATFORM;
14395e300c0SCorey Minyard 	if (addr_source >= SI_LAST)
14495e300c0SCorey Minyard 		return -EINVAL;
14595e300c0SCorey Minyard 
14695e300c0SCorey Minyard 	if (addr_source == SI_SMBIOS) {
1479d70029eSCorey Minyard 		if (!si_trydmi)
1489d70029eSCorey Minyard 			return -ENODEV;
14941b766d6SCorey Minyard 	} else if (addr_source != SI_HARDCODED) {
15095e300c0SCorey Minyard 		if (!si_tryplatform)
15195e300c0SCorey Minyard 			return -ENODEV;
15295e300c0SCorey Minyard 	}
1539d70029eSCorey Minyard 
1549d70029eSCorey Minyard 	rv = device_property_read_u8(&pdev->dev, "ipmi-type", &type);
1559d70029eSCorey Minyard 	if (rv)
1569d70029eSCorey Minyard 		return -ENODEV;
1579d70029eSCorey Minyard 
1589d70029eSCorey Minyard 	memset(&io, 0, sizeof(io));
15995e300c0SCorey Minyard 	io.addr_source = addr_source;
16025880f7dSJoe Perches 	dev_info(&pdev->dev, "probing via %s\n",
16195e300c0SCorey Minyard 		 ipmi_addr_src_to_str(addr_source));
1629d70029eSCorey Minyard 
1639d70029eSCorey Minyard 	switch (type) {
16495e300c0SCorey Minyard 	case SI_KCS:
16595e300c0SCorey Minyard 	case SI_SMIC:
16695e300c0SCorey Minyard 	case SI_BT:
16795e300c0SCorey Minyard 		io.si_type = type;
1689d70029eSCorey Minyard 		break;
16941b766d6SCorey Minyard 	case SI_TYPE_INVALID: /* User disabled this in hardcode. */
17041b766d6SCorey Minyard 		return -ENODEV;
1719d70029eSCorey Minyard 	default:
17295e300c0SCorey Minyard 		dev_err(&pdev->dev, "ipmi-type property is invalid\n");
1739d70029eSCorey Minyard 		return -EINVAL;
1749d70029eSCorey Minyard 	}
1759d70029eSCorey Minyard 
17641b766d6SCorey Minyard 	io.regsize = DEFAULT_REGSIZE;
17741b766d6SCorey Minyard 	rv = device_property_read_u8(&pdev->dev, "reg-size", &regsize);
17841b766d6SCorey Minyard 	if (!rv)
17941b766d6SCorey Minyard 		io.regsize = regsize;
18041b766d6SCorey Minyard 
18141b766d6SCorey Minyard 	io.regshift = 0;
18241b766d6SCorey Minyard 	rv = device_property_read_u8(&pdev->dev, "reg-shift", &regshift);
18341b766d6SCorey Minyard 	if (!rv)
18441b766d6SCorey Minyard 		io.regshift = regshift;
18541b766d6SCorey Minyard 
18695e300c0SCorey Minyard 	if (!ipmi_get_info_from_resources(pdev, &io))
18795e300c0SCorey Minyard 		return -EINVAL;
1889d70029eSCorey Minyard 
1899d70029eSCorey Minyard 	rv = device_property_read_u8(&pdev->dev, "slave-addr", &slave_addr);
190ed6c3a6dSCorey Minyard 	if (rv)
1919d70029eSCorey Minyard 		io.slave_addr = 0x20;
192ed6c3a6dSCorey Minyard 	else
1939d70029eSCorey Minyard 		io.slave_addr = slave_addr;
1949d70029eSCorey Minyard 
195443d372dSTakashi Iwai 	io.irq = platform_get_irq_optional(pdev, 0);
1969d70029eSCorey Minyard 	if (io.irq > 0)
1979d70029eSCorey Minyard 		io.irq_setup = ipmi_std_irq_setup;
1989d70029eSCorey Minyard 	else
1999d70029eSCorey Minyard 		io.irq = 0;
2009d70029eSCorey Minyard 
2019d70029eSCorey Minyard 	io.dev = &pdev->dev;
2029d70029eSCorey Minyard 
20341b766d6SCorey Minyard 	pr_info("ipmi_si: %s: %s %#lx regsize %d spacing %d irq %d\n",
20441b766d6SCorey Minyard 		ipmi_addr_src_to_str(addr_source),
205f6296bdcSCorey Minyard 		(io.addr_space == IPMI_IO_ADDR_SPACE) ? "io" : "mem",
2069d70029eSCorey Minyard 		io.addr_data, io.regsize, io.regspacing, io.irq);
2079d70029eSCorey Minyard 
2089d70029eSCorey Minyard 	ipmi_si_add_smi(&io);
2099d70029eSCorey Minyard 
2109d70029eSCorey Minyard 	return 0;
2119d70029eSCorey Minyard }
2129d70029eSCorey Minyard 
2139d70029eSCorey Minyard #ifdef CONFIG_OF
2149d70029eSCorey Minyard static const struct of_device_id of_ipmi_match[] = {
2159d70029eSCorey Minyard 	{ .type = "ipmi", .compatible = "ipmi-kcs",
2169d70029eSCorey Minyard 	  .data = (void *)(unsigned long) SI_KCS },
2179d70029eSCorey Minyard 	{ .type = "ipmi", .compatible = "ipmi-smic",
2189d70029eSCorey Minyard 	  .data = (void *)(unsigned long) SI_SMIC },
2199d70029eSCorey Minyard 	{ .type = "ipmi", .compatible = "ipmi-bt",
2209d70029eSCorey Minyard 	  .data = (void *)(unsigned long) SI_BT },
2219d70029eSCorey Minyard 	{},
2229d70029eSCorey Minyard };
2239d70029eSCorey Minyard MODULE_DEVICE_TABLE(of, of_ipmi_match);
2249d70029eSCorey Minyard 
of_ipmi_probe(struct platform_device * pdev)2259d70029eSCorey Minyard static int of_ipmi_probe(struct platform_device *pdev)
2269d70029eSCorey Minyard {
2279d70029eSCorey Minyard 	const struct of_device_id *match;
2289d70029eSCorey Minyard 	struct si_sm_io io;
2299d70029eSCorey Minyard 	struct resource resource;
2309d70029eSCorey Minyard 	const __be32 *regsize, *regspacing, *regshift;
2319d70029eSCorey Minyard 	struct device_node *np = pdev->dev.of_node;
2329d70029eSCorey Minyard 	int ret;
2339d70029eSCorey Minyard 	int proplen;
2349d70029eSCorey Minyard 
23595e300c0SCorey Minyard 	if (!si_tryopenfirmware)
23695e300c0SCorey Minyard 		return -ENODEV;
23795e300c0SCorey Minyard 
2389d70029eSCorey Minyard 	dev_info(&pdev->dev, "probing via device tree\n");
2399d70029eSCorey Minyard 
2409d70029eSCorey Minyard 	match = of_match_device(of_ipmi_match, &pdev->dev);
2419d70029eSCorey Minyard 	if (!match)
2429d70029eSCorey Minyard 		return -ENODEV;
2439d70029eSCorey Minyard 
2449d70029eSCorey Minyard 	if (!of_device_is_available(np))
2459d70029eSCorey Minyard 		return -EINVAL;
2469d70029eSCorey Minyard 
2479d70029eSCorey Minyard 	ret = of_address_to_resource(np, 0, &resource);
2489d70029eSCorey Minyard 	if (ret) {
24925880f7dSJoe Perches 		dev_warn(&pdev->dev, "invalid address from OF\n");
2509d70029eSCorey Minyard 		return ret;
2519d70029eSCorey Minyard 	}
2529d70029eSCorey Minyard 
2539d70029eSCorey Minyard 	regsize = of_get_property(np, "reg-size", &proplen);
2549d70029eSCorey Minyard 	if (regsize && proplen != 4) {
25525880f7dSJoe Perches 		dev_warn(&pdev->dev, "invalid regsize from OF\n");
2569d70029eSCorey Minyard 		return -EINVAL;
2579d70029eSCorey Minyard 	}
2589d70029eSCorey Minyard 
2599d70029eSCorey Minyard 	regspacing = of_get_property(np, "reg-spacing", &proplen);
2609d70029eSCorey Minyard 	if (regspacing && proplen != 4) {
26125880f7dSJoe Perches 		dev_warn(&pdev->dev, "invalid regspacing from OF\n");
2629d70029eSCorey Minyard 		return -EINVAL;
2639d70029eSCorey Minyard 	}
2649d70029eSCorey Minyard 
2659d70029eSCorey Minyard 	regshift = of_get_property(np, "reg-shift", &proplen);
2669d70029eSCorey Minyard 	if (regshift && proplen != 4) {
26725880f7dSJoe Perches 		dev_warn(&pdev->dev, "invalid regshift from OF\n");
2689d70029eSCorey Minyard 		return -EINVAL;
2699d70029eSCorey Minyard 	}
2709d70029eSCorey Minyard 
2719d70029eSCorey Minyard 	memset(&io, 0, sizeof(io));
272*d40f09c1SJustin Stitt 	io.si_type	= (unsigned long) match->data;
2739d70029eSCorey Minyard 	io.addr_source	= SI_DEVICETREE;
2749d70029eSCorey Minyard 	io.irq_setup	= ipmi_std_irq_setup;
2759d70029eSCorey Minyard 
276079dea00SAndy Shevchenko 	ipmi_set_addr_data_and_space(&resource, &io);
2779d70029eSCorey Minyard 
2789d70029eSCorey Minyard 	io.regsize	= regsize ? be32_to_cpup(regsize) : DEFAULT_REGSIZE;
2799d70029eSCorey Minyard 	io.regspacing	= regspacing ? be32_to_cpup(regspacing) : DEFAULT_REGSPACING;
2809d70029eSCorey Minyard 	io.regshift	= regshift ? be32_to_cpup(regshift) : 0;
2819d70029eSCorey Minyard 
2829d70029eSCorey Minyard 	io.irq		= irq_of_parse_and_map(pdev->dev.of_node, 0);
2839d70029eSCorey Minyard 	io.dev		= &pdev->dev;
2849d70029eSCorey Minyard 
2859d70029eSCorey Minyard 	dev_dbg(&pdev->dev, "addr 0x%lx regsize %d spacing %d irq %d\n",
2869d70029eSCorey Minyard 		io.addr_data, io.regsize, io.regspacing, io.irq);
2879d70029eSCorey Minyard 
2889d70029eSCorey Minyard 	return ipmi_si_add_smi(&io);
2899d70029eSCorey Minyard }
2909d70029eSCorey Minyard #else
2919d70029eSCorey Minyard #define of_ipmi_match NULL
of_ipmi_probe(struct platform_device * dev)2929d70029eSCorey Minyard static int of_ipmi_probe(struct platform_device *dev)
2939d70029eSCorey Minyard {
2949d70029eSCorey Minyard 	return -ENODEV;
2959d70029eSCorey Minyard }
2969d70029eSCorey Minyard #endif
2979d70029eSCorey Minyard 
2989d70029eSCorey Minyard #ifdef CONFIG_ACPI
find_slave_address(struct si_sm_io * io,int slave_addr)2999d70029eSCorey Minyard static int find_slave_address(struct si_sm_io *io, int slave_addr)
3009d70029eSCorey Minyard {
3019d70029eSCorey Minyard #ifdef CONFIG_IPMI_DMI_DECODE
3023cd83bacSCorey Minyard 	if (!slave_addr)
3033cd83bacSCorey Minyard 		slave_addr = ipmi_dmi_get_slave_addr(io->si_type,
3043cd83bacSCorey Minyard 						     io->addr_space,
3059d70029eSCorey Minyard 						     io->addr_data);
3069d70029eSCorey Minyard #endif
3079d70029eSCorey Minyard 
3089d70029eSCorey Minyard 	return slave_addr;
3099d70029eSCorey Minyard }
3109d70029eSCorey Minyard 
acpi_ipmi_probe(struct platform_device * pdev)3119d70029eSCorey Minyard static int acpi_ipmi_probe(struct platform_device *pdev)
3129d70029eSCorey Minyard {
31396c4d0deSAndy Shevchenko 	struct device *dev = &pdev->dev;
3149d70029eSCorey Minyard 	struct si_sm_io io;
3159d70029eSCorey Minyard 	acpi_handle handle;
3169d70029eSCorey Minyard 	acpi_status status;
3179d70029eSCorey Minyard 	unsigned long long tmp;
3189d70029eSCorey Minyard 	struct resource *res;
3199d70029eSCorey Minyard 
3209d70029eSCorey Minyard 	if (!si_tryacpi)
3219d70029eSCorey Minyard 		return -ENODEV;
3229d70029eSCorey Minyard 
32396c4d0deSAndy Shevchenko 	handle = ACPI_HANDLE(dev);
3249d70029eSCorey Minyard 	if (!handle)
3259d70029eSCorey Minyard 		return -ENODEV;
3269d70029eSCorey Minyard 
3279d70029eSCorey Minyard 	memset(&io, 0, sizeof(io));
3289d70029eSCorey Minyard 	io.addr_source = SI_ACPI;
32996c4d0deSAndy Shevchenko 	dev_info(dev, "probing via ACPI\n");
3309d70029eSCorey Minyard 
3319d70029eSCorey Minyard 	io.addr_info.acpi_info.acpi_handle = handle;
3329d70029eSCorey Minyard 
3339d70029eSCorey Minyard 	/* _IFT tells us the interface type: KCS, BT, etc */
3349d70029eSCorey Minyard 	status = acpi_evaluate_integer(handle, "_IFT", NULL, &tmp);
3359d70029eSCorey Minyard 	if (ACPI_FAILURE(status)) {
33696c4d0deSAndy Shevchenko 		dev_err(dev, "Could not find ACPI IPMI interface type\n");
337ea63a26eSAndy Shevchenko 		return -EINVAL;
3389d70029eSCorey Minyard 	}
3399d70029eSCorey Minyard 
3409d70029eSCorey Minyard 	switch (tmp) {
3419d70029eSCorey Minyard 	case 1:
3429d70029eSCorey Minyard 		io.si_type = SI_KCS;
3439d70029eSCorey Minyard 		break;
3449d70029eSCorey Minyard 	case 2:
3459d70029eSCorey Minyard 		io.si_type = SI_SMIC;
3469d70029eSCorey Minyard 		break;
3479d70029eSCorey Minyard 	case 3:
3489d70029eSCorey Minyard 		io.si_type = SI_BT;
3499d70029eSCorey Minyard 		break;
3509d70029eSCorey Minyard 	case 4: /* SSIF, just ignore */
351ea63a26eSAndy Shevchenko 		return -ENODEV;
3529d70029eSCorey Minyard 	default:
35396c4d0deSAndy Shevchenko 		dev_info(dev, "unknown IPMI type %lld\n", tmp);
354ea63a26eSAndy Shevchenko 		return -EINVAL;
3559d70029eSCorey Minyard 	}
3569d70029eSCorey Minyard 
35796c4d0deSAndy Shevchenko 	io.dev = dev;
35841b766d6SCorey Minyard 	io.regsize = DEFAULT_REGSIZE;
35941b766d6SCorey Minyard 	io.regshift = 0;
36041b766d6SCorey Minyard 
3619d70029eSCorey Minyard 	res = ipmi_get_info_from_resources(pdev, &io);
362ea63a26eSAndy Shevchenko 	if (!res)
363ea63a26eSAndy Shevchenko 		return -EINVAL;
3649d70029eSCorey Minyard 
3659d70029eSCorey Minyard 	/* If _GPE exists, use it; otherwise use standard interrupts */
3669d70029eSCorey Minyard 	status = acpi_evaluate_integer(handle, "_GPE", NULL, &tmp);
3679d70029eSCorey Minyard 	if (ACPI_SUCCESS(status)) {
3689d70029eSCorey Minyard 		io.irq = tmp;
3699d70029eSCorey Minyard 		io.irq_setup = acpi_gpe_irq_setup;
3709d70029eSCorey Minyard 	} else {
371443d372dSTakashi Iwai 		int irq = platform_get_irq_optional(pdev, 0);
3729d70029eSCorey Minyard 
3739d70029eSCorey Minyard 		if (irq > 0) {
3749d70029eSCorey Minyard 			io.irq = irq;
3759d70029eSCorey Minyard 			io.irq_setup = ipmi_std_irq_setup;
3769d70029eSCorey Minyard 		}
3779d70029eSCorey Minyard 	}
3789d70029eSCorey Minyard 
3799d70029eSCorey Minyard 	io.slave_addr = find_slave_address(&io, io.slave_addr);
3809d70029eSCorey Minyard 
38196c4d0deSAndy Shevchenko 	dev_info(dev, "%pR regsize %d spacing %d irq %d\n",
3829d70029eSCorey Minyard 		 res, io.regsize, io.regspacing, io.irq);
3839d70029eSCorey Minyard 
384e87443a5SCorey Minyard 	request_module_nowait("acpi_ipmi");
385429b00f6SStuart Hayes 
3869d70029eSCorey Minyard 	return ipmi_si_add_smi(&io);
3879d70029eSCorey Minyard }
3889d70029eSCorey Minyard 
3899d70029eSCorey Minyard static const struct acpi_device_id acpi_ipmi_match[] = {
3909d70029eSCorey Minyard 	{ "IPI0001", 0 },
3919d70029eSCorey Minyard 	{ },
3929d70029eSCorey Minyard };
3939d70029eSCorey Minyard MODULE_DEVICE_TABLE(acpi, acpi_ipmi_match);
3949d70029eSCorey Minyard #else
acpi_ipmi_probe(struct platform_device * dev)3959d70029eSCorey Minyard static int acpi_ipmi_probe(struct platform_device *dev)
3969d70029eSCorey Minyard {
3979d70029eSCorey Minyard 	return -ENODEV;
3989d70029eSCorey Minyard }
3999d70029eSCorey Minyard #endif
4009d70029eSCorey Minyard 
ipmi_probe(struct platform_device * pdev)4019d70029eSCorey Minyard static int ipmi_probe(struct platform_device *pdev)
4029d70029eSCorey Minyard {
4039d70029eSCorey Minyard 	if (pdev->dev.of_node && of_ipmi_probe(pdev) == 0)
4049d70029eSCorey Minyard 		return 0;
4059d70029eSCorey Minyard 
4069d70029eSCorey Minyard 	if (acpi_ipmi_probe(pdev) == 0)
4079d70029eSCorey Minyard 		return 0;
4089d70029eSCorey Minyard 
40995e300c0SCorey Minyard 	return platform_ipmi_probe(pdev);
4109d70029eSCorey Minyard }
4119d70029eSCorey Minyard 
ipmi_remove(struct platform_device * pdev)4129d70029eSCorey Minyard static int ipmi_remove(struct platform_device *pdev)
4139d70029eSCorey Minyard {
41487875c10SUwe Kleine-König 	ipmi_si_remove_by_dev(&pdev->dev);
41587875c10SUwe Kleine-König 
41687875c10SUwe Kleine-König 	return 0;
4179d70029eSCorey Minyard }
4189d70029eSCorey Minyard 
pdev_match_name(struct device * dev,const void * data)419418e3ea1SSuzuki K Poulose static int pdev_match_name(struct device *dev, const void *data)
420e17c6571SCorey Minyard {
421e17c6571SCorey Minyard 	struct platform_device *pdev = to_platform_device(dev);
422e17c6571SCorey Minyard 	const char *name = data;
423e17c6571SCorey Minyard 
424e17c6571SCorey Minyard 	return strcmp(pdev->name, name) == 0;
425e17c6571SCorey Minyard }
426e17c6571SCorey Minyard 
ipmi_remove_platform_device_by_name(char * name)427e17c6571SCorey Minyard void ipmi_remove_platform_device_by_name(char *name)
428e17c6571SCorey Minyard {
429e17c6571SCorey Minyard 	struct device *dev;
430e17c6571SCorey Minyard 
431e17c6571SCorey Minyard 	while ((dev = bus_find_device(&platform_bus_type, NULL, name,
432e17c6571SCorey Minyard 				      pdev_match_name))) {
433e17c6571SCorey Minyard 		struct platform_device *pdev = to_platform_device(dev);
434e17c6571SCorey Minyard 
435e17c6571SCorey Minyard 		platform_device_unregister(pdev);
4363559c327SSuzuki K Poulose 		put_device(dev);
437e17c6571SCorey Minyard 	}
438e17c6571SCorey Minyard }
439e17c6571SCorey Minyard 
440b3096c70SCorey Minyard static const struct platform_device_id si_plat_ids[] = {
441b3096c70SCorey Minyard 	{ "dmi-ipmi-si", 0 },
44241b766d6SCorey Minyard 	{ "hardcode-ipmi-si", 0 },
4433bb8ea40SCorey Minyard 	{ "hotmod-ipmi-si", 0 },
444b3096c70SCorey Minyard 	{ }
445b3096c70SCorey Minyard };
446b3096c70SCorey Minyard 
4479d70029eSCorey Minyard struct platform_driver ipmi_platform_driver = {
4489d70029eSCorey Minyard 	.driver = {
449104fb25fSCorey Minyard 		.name = SI_DEVICE_NAME,
4509d70029eSCorey Minyard 		.of_match_table = of_ipmi_match,
4519d70029eSCorey Minyard 		.acpi_match_table = ACPI_PTR(acpi_ipmi_match),
4529d70029eSCorey Minyard 	},
4539d70029eSCorey Minyard 	.probe		= ipmi_probe,
4549d70029eSCorey Minyard 	.remove		= ipmi_remove,
455b3096c70SCorey Minyard 	.id_table       = si_plat_ids
4569d70029eSCorey Minyard };
4579d70029eSCorey Minyard 
ipmi_si_platform_init(void)4589d70029eSCorey Minyard void ipmi_si_platform_init(void)
4599d70029eSCorey Minyard {
4609d70029eSCorey Minyard 	int rv = platform_driver_register(&ipmi_platform_driver);
4619d70029eSCorey Minyard 	if (rv)
46225880f7dSJoe Perches 		pr_err("Unable to register driver: %d\n", rv);
4632f663539SKefeng Wang 	else
4642f663539SKefeng Wang 		platform_registered = true;
4659d70029eSCorey Minyard }
4669d70029eSCorey Minyard 
ipmi_si_platform_shutdown(void)4679d70029eSCorey Minyard void ipmi_si_platform_shutdown(void)
4689d70029eSCorey Minyard {
4692f663539SKefeng Wang 	if (platform_registered)
4709d70029eSCorey Minyard 		platform_driver_unregister(&ipmi_platform_driver);
4719d70029eSCorey Minyard }
472