File Index
Files and directories
Sign in
FILE

kempld-core.c

File preview with syntax highlighting.

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