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