xref: /openbmc/linux/drivers/mfd/kempld-core.c (revision b38269ec)
1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3  * Kontron PLD MFD core driver
4  *
5  * Copyright (c) 2010-2013 Kontron Europe GmbH
6  * Author: Michael Brunner <michael.brunner@kontron.com>
7  */
8 
9 #include <linux/platform_device.h>
10 #include <linux/mfd/core.h>
11 #include <linux/mfd/kempld.h>
12 #include <linux/module.h>
13 #include <linux/dmi.h>
14 #include <linux/io.h>
15 #include <linux/delay.h>
16 #include <linux/acpi.h>
17 
18 #define MAX_ID_LEN 4
19 static char force_device_id[MAX_ID_LEN + 1] = "";
20 module_param_string(force_device_id, force_device_id,
21 		    sizeof(force_device_id), 0);
22 MODULE_PARM_DESC(force_device_id, "Override detected product");
23 
24 /*
25  * Get hardware mutex to block firmware from accessing the pld.
26  * It is possible for the firmware may hold the mutex for an extended length of
27  * time. This function will block until access has been granted.
28  */
29 static void kempld_get_hardware_mutex(struct kempld_device_data *pld)
30 {
31 	/* The mutex bit will read 1 until access has been granted */
32 	while (ioread8(pld->io_index) & KEMPLD_MUTEX_KEY)
33 		usleep_range(1000, 3000);
34 }
35 
36 static void kempld_release_hardware_mutex(struct kempld_device_data *pld)
37 {
38 	/* The harware mutex is released when 1 is written to the mutex bit. */
39 	iowrite8(KEMPLD_MUTEX_KEY, pld->io_index);
40 }
41 
42 static int kempld_get_info_generic(struct kempld_device_data *pld)
43 {
44 	u16 version;
45 	u8 spec;
46 
47 	kempld_get_mutex(pld);
48 
49 	version = kempld_read16(pld, KEMPLD_VERSION);
50 	spec = kempld_read8(pld, KEMPLD_SPEC);
51 	pld->info.buildnr = kempld_read16(pld, KEMPLD_BUILDNR);
52 
53 	pld->info.minor = KEMPLD_VERSION_GET_MINOR(version);
54 	pld->info.major = KEMPLD_VERSION_GET_MAJOR(version);
55 	pld->info.number = KEMPLD_VERSION_GET_NUMBER(version);
56 	pld->info.type = KEMPLD_VERSION_GET_TYPE(version);
57 
58 	if (spec == 0xff) {
59 		pld->info.spec_minor = 0;
60 		pld->info.spec_major = 1;
61 	} else {
62 		pld->info.spec_minor = KEMPLD_SPEC_GET_MINOR(spec);
63 		pld->info.spec_major = KEMPLD_SPEC_GET_MAJOR(spec);
64 	}
65 
66 	if (pld->info.spec_major > 0)
67 		pld->feature_mask = kempld_read16(pld, KEMPLD_FEATURE);
68 	else
69 		pld->feature_mask = 0;
70 
71 	kempld_release_mutex(pld);
72 
73 	return 0;
74 }
75 
76 enum kempld_cells {
77 	KEMPLD_I2C = 0,
78 	KEMPLD_WDT,
79 	KEMPLD_GPIO,
80 	KEMPLD_UART,
81 };
82 
83 static const char *kempld_dev_names[] = {
84 	[KEMPLD_I2C] = "kempld-i2c",
85 	[KEMPLD_WDT] = "kempld-wdt",
86 	[KEMPLD_GPIO] = "kempld-gpio",
87 	[KEMPLD_UART] = "kempld-uart",
88 };
89 
90 #define KEMPLD_MAX_DEVS	ARRAY_SIZE(kempld_dev_names)
91 
92 static int kempld_register_cells_generic(struct kempld_device_data *pld)
93 {
94 	struct mfd_cell devs[KEMPLD_MAX_DEVS] = {};
95 	int i = 0;
96 
97 	if (pld->feature_mask & KEMPLD_FEATURE_BIT_I2C)
98 		devs[i++].name = kempld_dev_names[KEMPLD_I2C];
99 
100 	if (pld->feature_mask & KEMPLD_FEATURE_BIT_WATCHDOG)
101 		devs[i++].name = kempld_dev_names[KEMPLD_WDT];
102 
103 	if (pld->feature_mask & KEMPLD_FEATURE_BIT_GPIO)
104 		devs[i++].name = kempld_dev_names[KEMPLD_GPIO];
105 
106 	if (pld->feature_mask & KEMPLD_FEATURE_MASK_UART)
107 		devs[i++].name = kempld_dev_names[KEMPLD_UART];
108 
109 	return mfd_add_devices(pld->dev, -1, devs, i, NULL, 0, NULL);
110 }
111 
112 static struct resource kempld_ioresource = {
113 	.start	= KEMPLD_IOINDEX,
114 	.end	= KEMPLD_IODATA,
115 	.flags	= IORESOURCE_IO,
116 };
117 
118 static const struct kempld_platform_data kempld_platform_data_generic = {
119 	.pld_clock		= KEMPLD_CLK,
120 	.ioresource		= &kempld_ioresource,
121 	.get_hardware_mutex	= kempld_get_hardware_mutex,
122 	.release_hardware_mutex	= kempld_release_hardware_mutex,
123 	.get_info		= kempld_get_info_generic,
124 	.register_cells		= kempld_register_cells_generic,
125 };
126 
127 static struct platform_device *kempld_pdev;
128 
129 static int kempld_create_platform_device(const struct dmi_system_id *id)
130 {
131 	const struct kempld_platform_data *pdata = id->driver_data;
132 	int ret;
133 
134 	kempld_pdev = platform_device_alloc("kempld", -1);
135 	if (!kempld_pdev)
136 		return -ENOMEM;
137 
138 	ret = platform_device_add_data(kempld_pdev, pdata, sizeof(*pdata));
139 	if (ret)
140 		goto err;
141 
142 	ret = platform_device_add_resources(kempld_pdev, pdata->ioresource, 1);
143 	if (ret)
144 		goto err;
145 
146 	ret = platform_device_add(kempld_pdev);
147 	if (ret)
148 		goto err;
149 
150 	return 0;
151 err:
152 	platform_device_put(kempld_pdev);
153 	return ret;
154 }
155 
156 /**
157  * kempld_read8 - read 8 bit register
158  * @pld: kempld_device_data structure describing the PLD
159  * @index: register index on the chip
160  *
161  * kempld_get_mutex must be called prior to calling this function.
162  */
163 u8 kempld_read8(struct kempld_device_data *pld, u8 index)
164 {
165 	iowrite8(index, pld->io_index);
166 	return ioread8(pld->io_data);
167 }
168 EXPORT_SYMBOL_GPL(kempld_read8);
169 
170 /**
171  * kempld_write8 - write 8 bit register
172  * @pld: kempld_device_data structure describing the PLD
173  * @index: register index on the chip
174  * @data: new register value
175  *
176  * kempld_get_mutex must be called prior to calling this function.
177  */
178 void kempld_write8(struct kempld_device_data *pld, u8 index, u8 data)
179 {
180 	iowrite8(index, pld->io_index);
181 	iowrite8(data, pld->io_data);
182 }
183 EXPORT_SYMBOL_GPL(kempld_write8);
184 
185 /**
186  * kempld_read16 - read 16 bit register
187  * @pld: kempld_device_data structure describing the PLD
188  * @index: register index on the chip
189  *
190  * kempld_get_mutex must be called prior to calling this function.
191  */
192 u16 kempld_read16(struct kempld_device_data *pld, u8 index)
193 {
194 	return kempld_read8(pld, index) | kempld_read8(pld, index + 1) << 8;
195 }
196 EXPORT_SYMBOL_GPL(kempld_read16);
197 
198 /**
199  * kempld_write16 - write 16 bit register
200  * @pld: kempld_device_data structure describing the PLD
201  * @index: register index on the chip
202  * @data: new register value
203  *
204  * kempld_get_mutex must be called prior to calling this function.
205  */
206 void kempld_write16(struct kempld_device_data *pld, u8 index, u16 data)
207 {
208 	kempld_write8(pld, index, (u8)data);
209 	kempld_write8(pld, index + 1, (u8)(data >> 8));
210 }
211 EXPORT_SYMBOL_GPL(kempld_write16);
212 
213 /**
214  * kempld_read32 - read 32 bit register
215  * @pld: kempld_device_data structure describing the PLD
216  * @index: register index on the chip
217  *
218  * kempld_get_mutex must be called prior to calling this function.
219  */
220 u32 kempld_read32(struct kempld_device_data *pld, u8 index)
221 {
222 	return kempld_read16(pld, index) | kempld_read16(pld, index + 2) << 16;
223 }
224 EXPORT_SYMBOL_GPL(kempld_read32);
225 
226 /**
227  * kempld_write32 - write 32 bit register
228  * @pld: kempld_device_data structure describing the PLD
229  * @index: register index on the chip
230  * @data: new register value
231  *
232  * kempld_get_mutex must be called prior to calling this function.
233  */
234 void kempld_write32(struct kempld_device_data *pld, u8 index, u32 data)
235 {
236 	kempld_write16(pld, index, (u16)data);
237 	kempld_write16(pld, index + 2, (u16)(data >> 16));
238 }
239 EXPORT_SYMBOL_GPL(kempld_write32);
240 
241 /**
242  * kempld_get_mutex - acquire PLD mutex
243  * @pld: kempld_device_data structure describing the PLD
244  */
245 void kempld_get_mutex(struct kempld_device_data *pld)
246 {
247 	const struct kempld_platform_data *pdata = dev_get_platdata(pld->dev);
248 
249 	mutex_lock(&pld->lock);
250 	pdata->get_hardware_mutex(pld);
251 }
252 EXPORT_SYMBOL_GPL(kempld_get_mutex);
253 
254 /**
255  * kempld_release_mutex - release PLD mutex
256  * @pld: kempld_device_data structure describing the PLD
257  */
258 void kempld_release_mutex(struct kempld_device_data *pld)
259 {
260 	const struct kempld_platform_data *pdata = dev_get_platdata(pld->dev);
261 
262 	pdata->release_hardware_mutex(pld);
263 	mutex_unlock(&pld->lock);
264 }
265 EXPORT_SYMBOL_GPL(kempld_release_mutex);
266 
267 /**
268  * kempld_get_info - update device specific information
269  * @pld: kempld_device_data structure describing the PLD
270  *
271  * This function calls the configured board specific kempld_get_info_XXXX
272  * function which is responsible for gathering information about the specific
273  * hardware. The information is then stored within the pld structure.
274  */
275 static int kempld_get_info(struct kempld_device_data *pld)
276 {
277 	int ret;
278 	const struct kempld_platform_data *pdata = dev_get_platdata(pld->dev);
279 	char major, minor;
280 
281 	ret = pdata->get_info(pld);
282 	if (ret)
283 		return ret;
284 
285 	/* The Kontron PLD firmware version string has the following format:
286 	 * Pwxy.zzzz
287 	 *   P:    Fixed
288 	 *   w:    PLD number    - 1 hex digit
289 	 *   x:    Major version - 1 alphanumerical digit (0-9A-V)
290 	 *   y:    Minor version - 1 alphanumerical digit (0-9A-V)
291 	 *   zzzz: Build number  - 4 zero padded hex digits */
292 
293 	if (pld->info.major < 10)
294 		major = pld->info.major + '0';
295 	else
296 		major = (pld->info.major - 10) + 'A';
297 	if (pld->info.minor < 10)
298 		minor = pld->info.minor + '0';
299 	else
300 		minor = (pld->info.minor - 10) + 'A';
301 
302 	ret = scnprintf(pld->info.version, sizeof(pld->info.version),
303 			"P%X%c%c.%04X", pld->info.number, major, minor,
304 			pld->info.buildnr);
305 	if (ret < 0)
306 		return ret;
307 
308 	return 0;
309 }
310 
311 /*
312  * kempld_register_cells - register cell drivers
313  *
314  * This function registers cell drivers for the detected hardware by calling
315  * the configured kempld_register_cells_XXXX function which is responsible
316  * to detect and register the needed cell drivers.
317  */
318 static int kempld_register_cells(struct kempld_device_data *pld)
319 {
320 	const struct kempld_platform_data *pdata = dev_get_platdata(pld->dev);
321 
322 	return pdata->register_cells(pld);
323 }
324 
325 static const char *kempld_get_type_string(struct kempld_device_data *pld)
326 {
327 	const char *version_type;
328 
329 	switch (pld->info.type) {
330 	case 0:
331 		version_type = "release";
332 		break;
333 	case 1:
334 		version_type = "debug";
335 		break;
336 	case 2:
337 		version_type = "custom";
338 		break;
339 	default:
340 		version_type = "unspecified";
341 		break;
342 	}
343 
344 	return version_type;
345 }
346 
347 static ssize_t pld_version_show(struct device *dev,
348 				struct device_attribute *attr, char *buf)
349 {
350 	struct kempld_device_data *pld = dev_get_drvdata(dev);
351 
352 	return scnprintf(buf, PAGE_SIZE, "%s\n", pld->info.version);
353 }
354 
355 static ssize_t pld_specification_show(struct device *dev,
356 				      struct device_attribute *attr, char *buf)
357 {
358 	struct kempld_device_data *pld = dev_get_drvdata(dev);
359 
360 	return scnprintf(buf, PAGE_SIZE, "%d.%d\n", pld->info.spec_major,
361 		       pld->info.spec_minor);
362 }
363 
364 static ssize_t pld_type_show(struct device *dev,
365 			     struct device_attribute *attr, char *buf)
366 {
367 	struct kempld_device_data *pld = dev_get_drvdata(dev);
368 
369 	return scnprintf(buf, PAGE_SIZE, "%s\n", kempld_get_type_string(pld));
370 }
371 
372 static DEVICE_ATTR_RO(pld_version);
373 static DEVICE_ATTR_RO(pld_specification);
374 static DEVICE_ATTR_RO(pld_type);
375 
376 static struct attribute *pld_attributes[] = {
377 	&dev_attr_pld_version.attr,
378 	&dev_attr_pld_specification.attr,
379 	&dev_attr_pld_type.attr,
380 	NULL
381 };
382 
383 static const struct attribute_group pld_attr_group = {
384 	.attrs = pld_attributes,
385 };
386 
387 static int kempld_detect_device(struct kempld_device_data *pld)
388 {
389 	u8 index_reg;
390 	int ret;
391 
392 	mutex_lock(&pld->lock);
393 
394 	/* Check for empty IO space */
395 	index_reg = ioread8(pld->io_index);
396 	if (index_reg == 0xff && ioread8(pld->io_data) == 0xff) {
397 		mutex_unlock(&pld->lock);
398 		return -ENODEV;
399 	}
400 
401 	/* Release hardware mutex if acquired */
402 	if (!(index_reg & KEMPLD_MUTEX_KEY)) {
403 		iowrite8(KEMPLD_MUTEX_KEY, pld->io_index);
404 		/* PXT and COMe-cPC2 boards may require a second release */
405 		iowrite8(KEMPLD_MUTEX_KEY, pld->io_index);
406 	}
407 
408 	mutex_unlock(&pld->lock);
409 
410 	ret = kempld_get_info(pld);
411 	if (ret)
412 		return ret;
413 
414 	dev_info(pld->dev, "Found Kontron PLD - %s (%s), spec %d.%d\n",
415 		 pld->info.version, kempld_get_type_string(pld),
416 		 pld->info.spec_major, pld->info.spec_minor);
417 
418 	ret = sysfs_create_group(&pld->dev->kobj, &pld_attr_group);
419 	if (ret)
420 		return ret;
421 
422 	ret = kempld_register_cells(pld);
423 	if (ret)
424 		sysfs_remove_group(&pld->dev->kobj, &pld_attr_group);
425 
426 	return ret;
427 }
428 
429 #ifdef CONFIG_ACPI
430 static int kempld_get_acpi_data(struct platform_device *pdev)
431 {
432 	struct list_head resource_list;
433 	struct resource *resources;
434 	struct resource_entry *rentry;
435 	struct device *dev = &pdev->dev;
436 	struct acpi_device *acpi_dev = ACPI_COMPANION(dev);
437 	const struct kempld_platform_data *pdata;
438 	int ret;
439 	int count;
440 
441 	pdata = acpi_device_get_match_data(dev);
442 	ret = platform_device_add_data(pdev, pdata,
443 				       sizeof(struct kempld_platform_data));
444 	if (ret)
445 		return ret;
446 
447 	INIT_LIST_HEAD(&resource_list);
448 	ret = acpi_dev_get_resources(acpi_dev, &resource_list, NULL, NULL);
449 	if (ret < 0)
450 		goto out;
451 
452 	count = ret;
453 
454 	if (count == 0) {
455 		ret = platform_device_add_resources(pdev, pdata->ioresource, 1);
456 		goto out;
457 	}
458 
459 	resources = devm_kcalloc(&acpi_dev->dev, count, sizeof(*resources),
460 				 GFP_KERNEL);
461 	if (!resources) {
462 		ret = -ENOMEM;
463 		goto out;
464 	}
465 
466 	count = 0;
467 	list_for_each_entry(rentry, &resource_list, node) {
468 		memcpy(&resources[count], rentry->res,
469 		       sizeof(*resources));
470 		count++;
471 	}
472 	ret = platform_device_add_resources(pdev, resources, count);
473 
474 out:
475 	acpi_dev_free_resource_list(&resource_list);
476 
477 	return ret;
478 }
479 #else
480 static int kempld_get_acpi_data(struct platform_device *pdev)
481 {
482 	return -ENODEV;
483 }
484 #endif /* CONFIG_ACPI */
485 
486 static int kempld_probe(struct platform_device *pdev)
487 {
488 	const struct kempld_platform_data *pdata;
489 	struct device *dev = &pdev->dev;
490 	struct kempld_device_data *pld;
491 	struct resource *ioport;
492 	int ret;
493 
494 	if (kempld_pdev == NULL) {
495 		/*
496 		 * No kempld_pdev device has been registered in kempld_init,
497 		 * so we seem to be probing an ACPI platform device.
498 		 */
499 		ret = kempld_get_acpi_data(pdev);
500 		if (ret)
501 			return ret;
502 	} else if (kempld_pdev != pdev) {
503 		/*
504 		 * The platform device we are probing is not the one we
505 		 * registered in kempld_init using the DMI table, so this one
506 		 * comes from ACPI.
507 		 * As we can only probe one - abort here and use the DMI
508 		 * based one instead.
509 		 */
510 		dev_notice(dev, "platform device exists - not using ACPI\n");
511 		return -ENODEV;
512 	}
513 	pdata = dev_get_platdata(dev);
514 
515 	pld = devm_kzalloc(dev, sizeof(*pld), GFP_KERNEL);
516 	if (!pld)
517 		return -ENOMEM;
518 
519 	ioport = platform_get_resource(pdev, IORESOURCE_IO, 0);
520 	if (!ioport)
521 		return -EINVAL;
522 
523 	pld->io_base = devm_ioport_map(dev, ioport->start,
524 					resource_size(ioport));
525 	if (!pld->io_base)
526 		return -ENOMEM;
527 
528 	pld->io_index = pld->io_base;
529 	pld->io_data = pld->io_base + 1;
530 	pld->pld_clock = pdata->pld_clock;
531 	pld->dev = dev;
532 
533 	mutex_init(&pld->lock);
534 	platform_set_drvdata(pdev, pld);
535 
536 	return kempld_detect_device(pld);
537 }
538 
539 static int kempld_remove(struct platform_device *pdev)
540 {
541 	struct kempld_device_data *pld = platform_get_drvdata(pdev);
542 	const struct kempld_platform_data *pdata = dev_get_platdata(pld->dev);
543 
544 	sysfs_remove_group(&pld->dev->kobj, &pld_attr_group);
545 
546 	mfd_remove_devices(&pdev->dev);
547 	pdata->release_hardware_mutex(pld);
548 
549 	return 0;
550 }
551 
552 #ifdef CONFIG_ACPI
553 static const struct acpi_device_id kempld_acpi_table[] = {
554 	{ "KEM0000", (kernel_ulong_t)&kempld_platform_data_generic },
555 	{ "KEM0001", (kernel_ulong_t)&kempld_platform_data_generic },
556 	{}
557 };
558 MODULE_DEVICE_TABLE(acpi, kempld_acpi_table);
559 #endif
560 
561 static struct platform_driver kempld_driver = {
562 	.driver		= {
563 		.name	= "kempld",
564 		.acpi_match_table = ACPI_PTR(kempld_acpi_table),
565 	},
566 	.probe		= kempld_probe,
567 	.remove		= kempld_remove,
568 };
569 
570 static const struct dmi_system_id kempld_dmi_table[] __initconst = {
571 	{
572 		.ident = "BBD6",
573 		.matches = {
574 			DMI_MATCH(DMI_BOARD_VENDOR, "Kontron"),
575 			DMI_MATCH(DMI_BOARD_NAME, "COMe-bBD"),
576 		},
577 		.driver_data = (void *)&kempld_platform_data_generic,
578 		.callback = kempld_create_platform_device,
579 	}, {
580 		.ident = "BBL6",
581 		.matches = {
582 			DMI_MATCH(DMI_BOARD_VENDOR, "Kontron"),
583 			DMI_MATCH(DMI_BOARD_NAME, "COMe-bBL6"),
584 		},
585 		.driver_data = (void *)&kempld_platform_data_generic,
586 		.callback = kempld_create_platform_device,
587 	}, {
588 		.ident = "BDV7",
589 		.matches = {
590 			DMI_MATCH(DMI_BOARD_VENDOR, "Kontron"),
591 			DMI_MATCH(DMI_BOARD_NAME, "COMe-bDV7"),
592 		},
593 		.driver_data = (void *)&kempld_platform_data_generic,
594 		.callback = kempld_create_platform_device,
595 	}, {
596 		.ident = "BHL6",
597 		.matches = {
598 			DMI_MATCH(DMI_BOARD_VENDOR, "Kontron"),
599 			DMI_MATCH(DMI_BOARD_NAME, "COMe-bHL6"),
600 		},
601 		.driver_data = (void *)&kempld_platform_data_generic,
602 		.callback = kempld_create_platform_device,
603 	}, {
604 		.ident = "BKL6",
605 		.matches = {
606 			DMI_MATCH(DMI_BOARD_VENDOR, "Kontron"),
607 			DMI_MATCH(DMI_BOARD_NAME, "COMe-bKL6"),
608 		},
609 		.driver_data = (void *)&kempld_platform_data_generic,
610 		.callback = kempld_create_platform_device,
611 	}, {
612 		.ident = "BSL6",
613 		.matches = {
614 			DMI_MATCH(DMI_BOARD_VENDOR, "Kontron"),
615 			DMI_MATCH(DMI_BOARD_NAME, "COMe-bSL6"),
616 		},
617 		.driver_data = (void *)&kempld_platform_data_generic,
618 		.callback = kempld_create_platform_device,
619 	}, {
620 		.ident = "CAL6",
621 		.matches = {
622 			DMI_MATCH(DMI_BOARD_VENDOR, "Kontron"),
623 			DMI_MATCH(DMI_BOARD_NAME, "COMe-cAL"),
624 		},
625 		.driver_data = (void *)&kempld_platform_data_generic,
626 		.callback = kempld_create_platform_device,
627 	}, {
628 		.ident = "CBL6",
629 		.matches = {
630 			DMI_MATCH(DMI_BOARD_VENDOR, "Kontron"),
631 			DMI_MATCH(DMI_BOARD_NAME, "COMe-cBL6"),
632 		},
633 		.driver_data = (void *)&kempld_platform_data_generic,
634 		.callback = kempld_create_platform_device,
635 	}, {
636 		.ident = "CBW6",
637 		.matches = {
638 			DMI_MATCH(DMI_BOARD_VENDOR, "Kontron"),
639 			DMI_MATCH(DMI_BOARD_NAME, "COMe-cBW6"),
640 		},
641 		.driver_data = (void *)&kempld_platform_data_generic,
642 		.callback = kempld_create_platform_device,
643 	}, {
644 		.ident = "CCR2",
645 		.matches = {
646 			DMI_MATCH(DMI_BOARD_VENDOR, "Kontron"),
647 			DMI_MATCH(DMI_BOARD_NAME, "COMe-bIP2"),
648 		},
649 		.driver_data = (void *)&kempld_platform_data_generic,
650 		.callback = kempld_create_platform_device,
651 	}, {
652 		.ident = "CCR6",
653 		.matches = {
654 			DMI_MATCH(DMI_BOARD_VENDOR, "Kontron"),
655 			DMI_MATCH(DMI_BOARD_NAME, "COMe-bIP6"),
656 		},
657 		.driver_data = (void *)&kempld_platform_data_generic,
658 		.callback = kempld_create_platform_device,
659 	}, {
660 		.ident = "CDV7",
661 		.matches = {
662 			DMI_MATCH(DMI_BOARD_VENDOR, "Kontron"),
663 			DMI_MATCH(DMI_BOARD_NAME, "COMe-cDV7"),
664 		},
665 		.driver_data = (void *)&kempld_platform_data_generic,
666 		.callback = kempld_create_platform_device,
667 	}, {
668 		.ident = "CHL6",
669 		.matches = {
670 			DMI_MATCH(DMI_BOARD_VENDOR, "Kontron"),
671 			DMI_MATCH(DMI_BOARD_NAME, "COMe-cHL6"),
672 		},
673 		.driver_data = (void *)&kempld_platform_data_generic,
674 		.callback = kempld_create_platform_device,
675 	}, {
676 		.ident = "CHR2",
677 		.matches = {
678 			DMI_MATCH(DMI_BOARD_VENDOR, "Kontron"),
679 			DMI_MATCH(DMI_BOARD_NAME, "ETXexpress-SC T2"),
680 		},
681 		.driver_data = (void *)&kempld_platform_data_generic,
682 		.callback = kempld_create_platform_device,
683 	}, {
684 		.ident = "CHR2",
685 		.matches = {
686 			DMI_MATCH(DMI_BOARD_VENDOR, "Kontron"),
687 			DMI_MATCH(DMI_BOARD_NAME, "ETXe-SC T2"),
688 		},
689 		.driver_data = (void *)&kempld_platform_data_generic,
690 		.callback = kempld_create_platform_device,
691 	}, {
692 		.ident = "CHR2",
693 		.matches = {
694 			DMI_MATCH(DMI_BOARD_VENDOR, "Kontron"),
695 			DMI_MATCH(DMI_BOARD_NAME, "COMe-bSC2"),
696 		},
697 		.driver_data = (void *)&kempld_platform_data_generic,
698 		.callback = kempld_create_platform_device,
699 	}, {
700 		.ident = "CHR6",
701 		.matches = {
702 			DMI_MATCH(DMI_BOARD_VENDOR, "Kontron"),
703 			DMI_MATCH(DMI_BOARD_NAME, "ETXexpress-SC T6"),
704 		},
705 		.driver_data = (void *)&kempld_platform_data_generic,
706 		.callback = kempld_create_platform_device,
707 	}, {
708 		.ident = "CHR6",
709 		.matches = {
710 			DMI_MATCH(DMI_BOARD_VENDOR, "Kontron"),
711 			DMI_MATCH(DMI_BOARD_NAME, "ETXe-SC T6"),
712 		},
713 		.driver_data = (void *)&kempld_platform_data_generic,
714 		.callback = kempld_create_platform_device,
715 	}, {
716 		.ident = "CHR6",
717 		.matches = {
718 			DMI_MATCH(DMI_BOARD_VENDOR, "Kontron"),
719 			DMI_MATCH(DMI_BOARD_NAME, "COMe-bSC6"),
720 		},
721 		.driver_data = (void *)&kempld_platform_data_generic,
722 		.callback = kempld_create_platform_device,
723 	}, {
724 		.ident = "CKL6",
725 		.matches = {
726 			DMI_MATCH(DMI_BOARD_VENDOR, "Kontron"),
727 			DMI_MATCH(DMI_BOARD_NAME, "COMe-cKL6"),
728 		},
729 		.driver_data = (void *)&kempld_platform_data_generic,
730 		.callback = kempld_create_platform_device,
731 	}, {
732 		.ident = "CNTG",
733 		.matches = {
734 			DMI_MATCH(DMI_BOARD_VENDOR, "Kontron"),
735 			DMI_MATCH(DMI_BOARD_NAME, "ETXexpress-PC"),
736 		},
737 		.driver_data = (void *)&kempld_platform_data_generic,
738 		.callback = kempld_create_platform_device,
739 	}, {
740 		.ident = "CNTG",
741 		.matches = {
742 			DMI_MATCH(DMI_BOARD_VENDOR, "Kontron"),
743 			DMI_MATCH(DMI_BOARD_NAME, "COMe-bPC2"),
744 		},
745 		.driver_data = (void *)&kempld_platform_data_generic,
746 		.callback = kempld_create_platform_device,
747 	}, {
748 		.ident = "CNTX",
749 		.matches = {
750 			DMI_MATCH(DMI_BOARD_VENDOR, "Kontron"),
751 			DMI_MATCH(DMI_BOARD_NAME, "PXT"),
752 		},
753 		.driver_data = (void *)&kempld_platform_data_generic,
754 		.callback = kempld_create_platform_device,
755 	}, {
756 		.ident = "CSL6",
757 		.matches = {
758 			DMI_MATCH(DMI_BOARD_VENDOR, "Kontron"),
759 			DMI_MATCH(DMI_BOARD_NAME, "COMe-cSL6"),
760 		},
761 		.driver_data = (void *)&kempld_platform_data_generic,
762 		.callback = kempld_create_platform_device,
763 	}, {
764 		.ident = "CVV6",
765 		.matches = {
766 			DMI_MATCH(DMI_BOARD_VENDOR, "Kontron"),
767 			DMI_MATCH(DMI_BOARD_NAME, "COMe-cBT"),
768 		},
769 		.driver_data = (void *)&kempld_platform_data_generic,
770 		.callback = kempld_create_platform_device,
771 	}, {
772 		.ident = "FRI2",
773 		.matches = {
774 			DMI_MATCH(DMI_BOARD_VENDOR, "Kontron"),
775 			DMI_MATCH(DMI_BIOS_VERSION, "FRI2"),
776 		},
777 		.driver_data = (void *)&kempld_platform_data_generic,
778 		.callback = kempld_create_platform_device,
779 	}, {
780 		.ident = "FRI2",
781 		.matches = {
782 			DMI_MATCH(DMI_PRODUCT_NAME, "Fish River Island II"),
783 		},
784 		.driver_data = (void *)&kempld_platform_data_generic,
785 		.callback = kempld_create_platform_device,
786 	}, {
787 		.ident = "A203",
788 		.matches = {
789 			DMI_MATCH(DMI_BOARD_VENDOR, "Kontron"),
790 			DMI_MATCH(DMI_BOARD_NAME, "KBox A-203"),
791 		},
792 		.driver_data = (void *)&kempld_platform_data_generic,
793 		.callback = kempld_create_platform_device,
794 	}, {
795 		.ident = "M4A1",
796 		.matches = {
797 			DMI_MATCH(DMI_BOARD_VENDOR, "Kontron"),
798 			DMI_MATCH(DMI_BOARD_NAME, "COMe-m4AL"),
799 		},
800 		.driver_data = (void *)&kempld_platform_data_generic,
801 		.callback = kempld_create_platform_device,
802 	}, {
803 		.ident = "MAL1",
804 		.matches = {
805 			DMI_MATCH(DMI_BOARD_VENDOR, "Kontron"),
806 			DMI_MATCH(DMI_BOARD_NAME, "COMe-mAL10"),
807 		},
808 		.driver_data = (void *)&kempld_platform_data_generic,
809 		.callback = kempld_create_platform_device,
810 	}, {
811 		.ident = "MAPL",
812 		.matches = {
813 			DMI_MATCH(DMI_BOARD_VENDOR, "Kontron"),
814 			DMI_MATCH(DMI_BOARD_NAME, "mITX-APL"),
815 		},
816 		.driver_data = (void *)&kempld_platform_data_generic,
817 		.callback = kempld_create_platform_device,
818 	}, {
819 		.ident = "MBR1",
820 		.matches = {
821 			DMI_MATCH(DMI_BOARD_VENDOR, "Kontron"),
822 			DMI_MATCH(DMI_BOARD_NAME, "ETX-OH"),
823 		},
824 		.driver_data = (void *)&kempld_platform_data_generic,
825 		.callback = kempld_create_platform_device,
826 	}, {
827 		.ident = "MVV1",
828 		.matches = {
829 			DMI_MATCH(DMI_BOARD_VENDOR, "Kontron"),
830 			DMI_MATCH(DMI_BOARD_NAME, "COMe-mBT"),
831 		},
832 		.driver_data = (void *)&kempld_platform_data_generic,
833 		.callback = kempld_create_platform_device,
834 	}, {
835 		.ident = "NTC1",
836 		.matches = {
837 			DMI_MATCH(DMI_BOARD_VENDOR, "Kontron"),
838 			DMI_MATCH(DMI_BOARD_NAME, "nanoETXexpress-TT"),
839 		},
840 		.driver_data = (void *)&kempld_platform_data_generic,
841 		.callback = kempld_create_platform_device,
842 	}, {
843 		.ident = "NTC1",
844 		.matches = {
845 			DMI_MATCH(DMI_BOARD_VENDOR, "Kontron"),
846 			DMI_MATCH(DMI_BOARD_NAME, "nETXe-TT"),
847 		},
848 		.driver_data = (void *)&kempld_platform_data_generic,
849 		.callback = kempld_create_platform_device,
850 	}, {
851 		.ident = "NTC1",
852 		.matches = {
853 			DMI_MATCH(DMI_BOARD_VENDOR, "Kontron"),
854 			DMI_MATCH(DMI_BOARD_NAME, "COMe-mTT"),
855 		},
856 		.driver_data = (void *)&kempld_platform_data_generic,
857 		.callback = kempld_create_platform_device,
858 	}, {
859 		.ident = "NUP1",
860 		.matches = {
861 			DMI_MATCH(DMI_BOARD_VENDOR, "Kontron"),
862 			DMI_MATCH(DMI_BOARD_NAME, "COMe-mCT"),
863 		},
864 		.driver_data = (void *)&kempld_platform_data_generic,
865 		.callback = kempld_create_platform_device,
866 	}, {
867 		.ident = "PAPL",
868 		.matches = {
869 			DMI_MATCH(DMI_BOARD_VENDOR, "Kontron"),
870 			DMI_MATCH(DMI_BOARD_NAME, "pITX-APL"),
871 		},
872 		.driver_data = (void *)&kempld_platform_data_generic,
873 		.callback = kempld_create_platform_device,
874 	}, {
875 		.ident = "SXAL",
876 		.matches = {
877 			DMI_MATCH(DMI_BOARD_VENDOR, "Kontron"),
878 			DMI_MATCH(DMI_BOARD_NAME, "SMARC-sXAL"),
879 		},
880 		.driver_data = (void *)&kempld_platform_data_generic,
881 		.callback = kempld_create_platform_device,
882 	}, {
883 		.ident = "SXAL4",
884 		.matches = {
885 			DMI_MATCH(DMI_BOARD_VENDOR, "Kontron"),
886 			DMI_MATCH(DMI_BOARD_NAME, "SMARC-sXA4"),
887 		},
888 		.driver_data = (void *)&kempld_platform_data_generic,
889 		.callback = kempld_create_platform_device,
890 	}, {
891 		.ident = "UNP1",
892 		.matches = {
893 			DMI_MATCH(DMI_BOARD_VENDOR, "Kontron"),
894 			DMI_MATCH(DMI_BOARD_NAME, "microETXexpress-DC"),
895 		},
896 		.driver_data = (void *)&kempld_platform_data_generic,
897 		.callback = kempld_create_platform_device,
898 	}, {
899 		.ident = "UNP1",
900 		.matches = {
901 			DMI_MATCH(DMI_BOARD_VENDOR, "Kontron"),
902 			DMI_MATCH(DMI_BOARD_NAME, "COMe-cDC2"),
903 		},
904 		.driver_data = (void *)&kempld_platform_data_generic,
905 		.callback = kempld_create_platform_device,
906 	}, {
907 		.ident = "UNTG",
908 		.matches = {
909 			DMI_MATCH(DMI_BOARD_VENDOR, "Kontron"),
910 			DMI_MATCH(DMI_BOARD_NAME, "microETXexpress-PC"),
911 		},
912 		.driver_data = (void *)&kempld_platform_data_generic,
913 		.callback = kempld_create_platform_device,
914 	}, {
915 		.ident = "UNTG",
916 		.matches = {
917 			DMI_MATCH(DMI_BOARD_VENDOR, "Kontron"),
918 			DMI_MATCH(DMI_BOARD_NAME, "COMe-cPC2"),
919 		},
920 		.driver_data = (void *)&kempld_platform_data_generic,
921 		.callback = kempld_create_platform_device,
922 	}, {
923 		.ident = "UUP6",
924 		.matches = {
925 			DMI_MATCH(DMI_BOARD_VENDOR, "Kontron"),
926 			DMI_MATCH(DMI_BOARD_NAME, "COMe-cCT6"),
927 		},
928 		.driver_data = (void *)&kempld_platform_data_generic,
929 		.callback = kempld_create_platform_device,
930 	}, {
931 		.ident = "UTH6",
932 		.matches = {
933 			DMI_MATCH(DMI_BOARD_VENDOR, "Kontron"),
934 			DMI_MATCH(DMI_BOARD_NAME, "COMe-cTH6"),
935 		},
936 		.driver_data = (void *)&kempld_platform_data_generic,
937 		.callback = kempld_create_platform_device,
938 	}, {
939 		.ident = "Q7AL",
940 		.matches = {
941 			DMI_MATCH(DMI_BOARD_VENDOR, "Kontron"),
942 			DMI_MATCH(DMI_BOARD_NAME, "Qseven-Q7AL"),
943 		},
944 		.driver_data = (void *)&kempld_platform_data_generic,
945 		.callback = kempld_create_platform_device,
946 	},
947 	{}
948 };
949 MODULE_DEVICE_TABLE(dmi, kempld_dmi_table);
950 
951 static int __init kempld_init(void)
952 {
953 	const struct dmi_system_id *id;
954 
955 	if (force_device_id[0]) {
956 		for (id = kempld_dmi_table;
957 		     id->matches[0].slot != DMI_NONE; id++)
958 			if (strstr(id->ident, force_device_id))
959 				if (id->callback && !id->callback(id))
960 					break;
961 		if (id->matches[0].slot == DMI_NONE)
962 			return -ENODEV;
963 	} else {
964 		dmi_check_system(kempld_dmi_table);
965 	}
966 
967 	return platform_driver_register(&kempld_driver);
968 }
969 
970 static void __exit kempld_exit(void)
971 {
972 	if (kempld_pdev)
973 		platform_device_unregister(kempld_pdev);
974 
975 	platform_driver_unregister(&kempld_driver);
976 }
977 
978 module_init(kempld_init);
979 module_exit(kempld_exit);
980 
981 MODULE_DESCRIPTION("KEM PLD Core Driver");
982 MODULE_AUTHOR("Michael Brunner <michael.brunner@kontron.com>");
983 MODULE_LICENSE("GPL");
984 MODULE_ALIAS("platform:kempld-core");
985