static int simatic_ipc_leds_probe()

in simple/simatic-ipc-leds.c [112:189]


static int simatic_ipc_leds_probe(struct platform_device *pdev)
{
	const struct simatic_ipc_platform *plat = pdev->dev.platform_data;
	struct device *dev = &pdev->dev;
	struct simatic_ipc_led *ipcled;
	struct led_classdev *cdev;
	struct resource *res;
	int err, type;
	u32 *p;

	switch (plat->devmode) {
	case SIMATIC_IPC_DEVICE_227D:
	case SIMATIC_IPC_DEVICE_427E:
		res = &simatic_ipc_led_io_res;
		ipcled = simatic_ipc_leds_io;
		/* on 227D the two bytes work the other way araound */
		if (plat->devmode == SIMATIC_IPC_DEVICE_227D) {
			while (ipcled->value) {
				ipcled->value = swab16(ipcled->value);
				ipcled++;
			}
			ipcled = simatic_ipc_leds_io;
		}
		type = IORESOURCE_IO;
		if (!devm_request_region(dev, res->start, resource_size(res), KBUILD_MODNAME)) {
			dev_err(dev, "Unable to register IO resource at %pR\n", res);
			return -EBUSY;
		}
		break;
	case SIMATIC_IPC_DEVICE_127E:
		res = &simatic_ipc_led_mem_res;
		ipcled = simatic_ipc_leds_mem;
		type = IORESOURCE_MEM;

		/* get GPIO base from PCI */
		res->start = simatic_ipc_get_membase0(PCI_DEVFN(13, 0));
		if (res->start == 0)
			return -ENODEV;

		/* do the final address calculation */
		res->start = res->start + (0xC5 << 16);
		res->end += res->start;

		simatic_ipc_led_memory = devm_ioremap_resource(dev, res);
		if (IS_ERR(simatic_ipc_led_memory))
			return PTR_ERR(simatic_ipc_led_memory);

		/* initialize power/watchdog LED */
		p = simatic_ipc_led_memory + 0x500 + 0x1D8; /* PM_WDT_OUT */
		*p = (*p & ~1);
		p = simatic_ipc_led_memory + 0x500 + 0x1C0; /* PM_BIOS_BOOT_N */
		*p = (*p | 1);

		break;
	default:
		return -ENODEV;
	}

	while (ipcled->value) {
		cdev = &ipcled->cdev;
		if (type == IORESOURCE_MEM) {
			cdev->brightness_set = simatic_ipc_led_set_mem;
			cdev->brightness_get = simatic_ipc_led_get_mem;
		} else {
			cdev->brightness_set = simatic_ipc_led_set_io;
			cdev->brightness_get = simatic_ipc_led_get_io;
		}
		cdev->max_brightness = LED_ON;
		cdev->name = ipcled->name;

		err = devm_led_classdev_register(dev, cdev);
		if (err < 0)
			return err;
		ipcled++;
	}

	return 0;
}