Linux Audio

Check our new training course

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