x86: unmask CPUID levels on Intel CPUs
[linux-2.6/mini2440.git] / drivers / staging / meilhaus / metempl_sub.c
blobf1d65d889e23903125dd6a65f6f938fbc2968443
1 /**
2 * @file metempl_sub.c
4 * @brief Subdevice instance.
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
32 * Includes
34 #include <linux/module.h>
36 #include <linux/slab.h>
37 #include <linux/spinlock.h>
38 #include <asm/io.h>
39 #include <linux/types.h>
41 #include "medefines.h"
42 #include "meinternal.h"
43 #include "meerror.h"
45 #include "medebug.h"
46 #include "metempl_sub_reg.h"
47 #include "metempl_sub.h"
50 * Defines
54 * Functions
57 static void metempl_sub_destructor(struct me_subdevice *subdevice)
59 metempl_sub_subdevice_t *instance;
61 PDEBUG("executed.\n");
62 instance = (metempl_sub_subdevice_t *) subdevice;
64 /* Until there this was the things the default constructor does.
65 If you do not have any additional things to do you can wipe it out. */
67 me_subdevice_deinit(&instance->base);
68 kfree(instance);
71 static int metempl_sub_query_number_channels(me_subdevice_t * subdevice,
72 int *number)
74 PDEBUG("executed.\n");
75 *number = 0;
76 return ME_ERRNO_SUCCESS;
79 static int metempl_sub_query_subdevice_type(me_subdevice_t * subdevice,
80 int *type, int *subtype)
82 PDEBUG("executed.\n");
83 *type = 0;
84 *subtype = 0;
85 return ME_ERRNO_SUCCESS;
88 static int metempl_sub_query_subdevice_caps(me_subdevice_t * subdevice,
89 int *caps)
91 PDEBUG("executed.\n");
92 *caps = 0;
93 return ME_ERRNO_SUCCESS;
96 metempl_sub_subdevice_t *metempl_sub_constructor(uint32_t reg_base,
97 unsigned int sub_idx,
98 spinlock_t * ctrl_reg_lock)
100 metempl_sub_subdevice_t *subdevice;
101 int err;
103 PDEBUG("executed.\n");
105 /* Allocate memory for subdevice instance */
106 subdevice = kmalloc(sizeof(metempl_sub_subdevice_t), GFP_KERNEL);
108 if (!subdevice) {
109 PERROR("Cannot get memory for subdevice instance.\n");
110 return NULL;
113 memset(subdevice, 0, sizeof(metempl_sub_subdevice_t));
115 /* Check if subdevice index is out of range */
117 if (sub_idx >= 2) {
118 PERROR("Template subdevice index is out of range.\n");
119 kfree(subdevice);
120 return NULL;
123 /* Initialize subdevice base class */
124 err = me_subdevice_init(&subdevice->base);
126 if (err) {
127 PERROR("Cannot initialize subdevice base class instance.\n");
128 kfree(subdevice);
129 return NULL;
131 // Initialize spin locks.
132 spin_lock_init(&subdevice->subdevice_lock);
134 subdevice->ctrl_reg_lock = ctrl_reg_lock;
136 /* Save the subdevice index */
137 subdevice->sub_idx = sub_idx;
139 /* Override base class methods. */
140 subdevice->base.me_subdevice_destructor = metempl_sub_destructor;
141 subdevice->base.me_subdevice_query_number_channels =
142 metempl_sub_query_number_channels;
143 subdevice->base.me_subdevice_query_subdevice_type =
144 metempl_sub_query_subdevice_type;
145 subdevice->base.me_subdevice_query_subdevice_caps =
146 metempl_sub_query_subdevice_caps;
148 return subdevice;