• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * @file me1600_device.h
3  *
4  * @brief ME-1600 device class.
5  * @note Copyright (C) 2007 Meilhaus Electronic GmbH (support@meilhaus.de)
6  * @author Guenter Gebhardt
7  */
8 
9 /*
10  * Copyright (C) 2007 Meilhaus Electronic GmbH (support@meilhaus.de)
11  *
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.
16  *
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.
21  *
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.
25  */
26 
27 #ifndef _ME1600_H
28 #define _ME1600_H
29 
30 #include <linux/pci.h>
31 #include <linux/spinlock.h>
32 
33 #include "medevice.h"
34 #include "me1600_ao.h"
35 #include "me1600_ao_reg.h"
36 
37 #ifdef __KERNEL__
38 
39 /**
40  * @brief Structure to store device capabilities.
41  */
42 typedef struct me1600_version {
43 	uint16_t device_id;				/**< The PCI device id of the device. */
44 	unsigned int ao_chips;			/**< The number of analog outputs on the device. */
45 	int curr;						/**< Flag to identify amounts of current output. */
46 } me1600_version_t;
47 
48 /**
49   * @brief Defines for each ME-1600 device version its capabilities.
50  */
51 static me1600_version_t me1600_versions[] = {
52 	{PCI_DEVICE_ID_MEILHAUS_ME1600_4U, 4, 0},
53 	{PCI_DEVICE_ID_MEILHAUS_ME1600_8U, 8, 0},
54 	{PCI_DEVICE_ID_MEILHAUS_ME1600_12U, 12, 0},
55 	{PCI_DEVICE_ID_MEILHAUS_ME1600_16U, 16, 0},
56 	{PCI_DEVICE_ID_MEILHAUS_ME1600_16U_8I, 16, 8},
57 	{0}
58 };
59 
60 /**< Returns the number of entries in #me1600_versions. */
61 #define ME1600_DEVICE_VERSIONS (sizeof(me1600_versions) / sizeof(me1600_version_t) - 1)
62 
63 /**
64  * @brief Returns the index of the device entry in #me1600_versions.
65  *
66  * @param device_id The PCI device id of the device to query.
67  * @return The index of the device in #me1600_versions.
68  */
me1600_versions_get_device_index(uint16_t device_id)69 static inline unsigned int me1600_versions_get_device_index(uint16_t device_id)
70 {
71 	unsigned int i;
72 	for (i = 0; i < ME1600_DEVICE_VERSIONS; i++)
73 		if (me1600_versions[i].device_id == device_id)
74 			break;
75 	return i;
76 }
77 
78 /**
79  * @brief The ME-1600 device class structure.
80  */
81 typedef struct me1600_device {
82 	me_device_t base;						/**< The Meilhaus device base class. */
83 	spinlock_t config_regs_lock;			/**< Protects the configuration registers. */
84 
85 	me1600_ao_shadow_t ao_regs_shadows;		/**< Addresses and shadows of output's registers. */
86 	spinlock_t ao_shadows_lock;				/**< Protects the shadow's struct. */
87 } me1600_device_t;
88 
89 /**
90  * @brief The ME-1600 device class constructor.
91  *
92  * @param pci_device The pci device structure given by the PCI subsystem.
93  *
94  * @return On succes a new ME-1600 device instance. \n
95  *         NULL on error.
96  */
97 me_device_t *me1600_pci_constructor(struct pci_dev *pci_device)
98     __attribute__ ((weak));
99 
100 #endif
101 #endif
102