added 2.6.29.6 aldebaran kernel
[nao-ulib.git] / kernel / 2.6.29.6-aldebaran-rt / drivers / staging / meilhaus / metempl_device.c
blobe48632ddc1aafe7d08aed1a47ddcd0a09b3f6e5c
1 /**
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
7 */
9 /*
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.
27 #ifndef __KERNEL__
28 # define __KERNEL__
29 #endif
31 #ifndef MODULE
32 # define MODULE
33 #endif
35 #include <linux/module.h>
37 #include <linux/pci.h>
38 #include <linux/slab.h>
40 #include <meids.h>
41 #include "meerror.h"
42 #include "mecommon.h"
43 #include "meinternal.h"
45 #include "medebug.h"
46 #include "medevice.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;
56 int err;
57 int i;
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");
66 return NULL;
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);
74 if (err) {
75 kfree(metempl_device);
76 PERROR("Cannot initialize device base class.\n");
77 return NULL;
80 /* Get the index in the device version information table. */
81 version_idx =
82 metempl_versions_get_device_index(metempl_device->base.info.pci.
83 device_id);
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++) {
90 subdevice =
91 (me_subdevice_t *) metempl_sub_constructor(metempl_device->
92 base.info.pci.
93 reg_bases[2], i,
94 &metempl_device->
95 ctrl_reg_lock);
97 if (!subdevice) {
98 me_device_deinit((me_device_t *) metempl_device);
99 kfree(metempl_device);
100 PERROR("Cannot get memory for subdevice.\n");
101 return NULL;
104 me_slist_add_subdevice_tail(&metempl_device->base.slist,
105 subdevice);
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.");
118 return 0;
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);