4 * @brief Subdevice instance.
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.
34 #include <linux/module.h>
36 #include <linux/slab.h>
37 #include <linux/spinlock.h>
39 #include <linux/types.h>
41 #include "medefines.h"
42 #include "meinternal.h"
46 #include "metempl_sub_reg.h"
47 #include "metempl_sub.h"
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);
71 static int metempl_sub_query_number_channels(me_subdevice_t *subdevice,
74 PDEBUG("executed.\n");
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");
85 return ME_ERRNO_SUCCESS;
88 static int metempl_sub_query_subdevice_caps(me_subdevice_t *subdevice,
91 PDEBUG("executed.\n");
93 return ME_ERRNO_SUCCESS;
96 metempl_sub_subdevice_t *metempl_sub_constructor(uint32_t reg_base,
98 spinlock_t *ctrl_reg_lock)
100 metempl_sub_subdevice_t *subdevice;
103 PDEBUG("executed.\n");
105 /* Allocate memory for subdevice instance */
106 subdevice = kmalloc(sizeof(metempl_sub_subdevice_t), GFP_KERNEL);
109 PERROR("Cannot get memory for subdevice instance.\n");
113 memset(subdevice, 0, sizeof(metempl_sub_subdevice_t));
115 /* Check if subdevice index is out of range */
118 PERROR("Template subdevice index is out of range.\n");
123 /* Initialize subdevice base class */
124 err = me_subdevice_init(&subdevice->base);
127 PERROR("Cannot initialize subdevice base class instance.\n");
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;