2 * @file metempl_device.c
4 * @brief template device class implementation.
5 * @note Copyright (C) 2007 Meilhaus Electronic GmbH (support@meilhaus.de)
6 * @author Guenter Gebhardt
10 * Copyright (C) 2007 Meilhaus Electronic GmbH (support@meilhaus.de)
12 * This file is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
35 #include <linux/module.h>
37 #include <linux/pci.h>
38 #include <linux/slab.h>
43 #include "meinternal.h"
47 #include "metempl_device.h"
48 #include "mesubdevice.h"
49 #include "metempl_sub.h"
51 me_device_t *metempl_pci_constructor(struct pci_dev *pci_device)
53 metempl_device_t *metempl_device;
54 me_subdevice_t *subdevice;
55 unsigned int version_idx;
59 PDEBUG("executed.\n");
61 // Allocate structure for device instance.
62 metempl_device = kmalloc(sizeof(metempl_device_t), GFP_KERNEL);
64 if (!metempl_device) {
65 PERROR("Cannot get memory for device instance.\n");
69 memset(metempl_device, 0, sizeof(metempl_device_t));
71 // Initialize base class structure.
72 err = me_device_pci_init((me_device_t *) metempl_device, pci_device);
75 kfree(metempl_device);
76 PERROR("Cannot initialize device base class.\n");
80 /* Get the index in the device version information table. */
82 metempl_versions_get_device_index(metempl_device->base.info.pci.
85 // Initialize spin lock .
86 spin_lock_init(&metempl_device->ctrl_reg_lock);
88 // Create subdevice instances.
89 for (i = 0; i < metempl_versions[version_idx].subdevices; i++) {
91 (me_subdevice_t *) metempl_sub_constructor(metempl_device->
98 me_device_deinit((me_device_t *) metempl_device);
99 kfree(metempl_device);
100 PERROR("Cannot get memory for subdevice.\n");
104 me_slist_add_subdevice_tail(&metempl_device->base.slist,
108 /* Overwrite base class methods if applicable. */
110 return (me_device_t *) metempl_device;
113 // Init and exit of module.
115 static int __init metempl_init(void)
117 PDEBUG("executed.\n.");
121 static void __exit metempl_exit(void)
123 PDEBUG("executed.\n.");
126 module_init(metempl_init);
128 module_exit(metempl_exit);
130 // Administrative stuff for modinfo.
131 MODULE_AUTHOR("Guenter Gebhardt <g.gebhardt@meilhaus.de>");
132 MODULE_DESCRIPTION("Device Driver Module for Template Device");
133 MODULE_SUPPORTED_DEVICE("Meilhaus Template Devices");
134 MODULE_LICENSE("GPL");
136 // Export the constructor.
137 EXPORT_SYMBOL(metempl_pci_constructor);