Linux Audio

Check our new training course

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