Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/geert/linux...
[pandora-kernel.git] / sound / pci / asihpi / hpimsginit.c
1 /******************************************************************************
2
3     AudioScience HPI driver
4     Copyright (C) 1997-2010  AudioScience Inc. <support@audioscience.com>
5
6     This program is free software; you can redistribute it and/or modify
7     it under the terms of version 2 of the GNU General Public License as
8     published by the Free Software Foundation;
9
10     This program is distributed in the hope that it will be useful,
11     but WITHOUT ANY WARRANTY; without even the implied warranty of
12     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13     GNU General Public License for more details.
14
15     You should have received a copy of the GNU General Public License
16     along with this program; if not, write to the Free Software
17     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18
19  Hardware Programming Interface (HPI) Utility functions.
20
21  (C) Copyright AudioScience Inc. 2007
22 *******************************************************************************/
23
24 #include "hpi_internal.h"
25 #include "hpimsginit.h"
26
27 /* The actual message size for each object type */
28 static u16 msg_size[HPI_OBJ_MAXINDEX + 1] = HPI_MESSAGE_SIZE_BY_OBJECT;
29 /* The actual response size for each object type */
30 static u16 res_size[HPI_OBJ_MAXINDEX + 1] = HPI_RESPONSE_SIZE_BY_OBJECT;
31 /* Flag to enable alternate message type for SSX2 bypass. */
32 static u16 gwSSX2_bypass;
33
34 /** \internal
35   * initialize the HPI message structure
36   */
37 static void hpi_init_message(struct hpi_message *phm, u16 object,
38         u16 function)
39 {
40         memset(phm, 0, sizeof(*phm));
41         if ((object > 0) && (object <= HPI_OBJ_MAXINDEX))
42                 phm->size = msg_size[object];
43         else
44                 phm->size = sizeof(*phm);
45
46         if (gwSSX2_bypass)
47                 phm->type = HPI_TYPE_SSX2BYPASS_MESSAGE;
48         else
49                 phm->type = HPI_TYPE_REQUEST;
50         phm->object = object;
51         phm->function = function;
52         phm->version = 0;
53         phm->adapter_index = HPI_ADAPTER_INDEX_INVALID;
54         /* Expect actual adapter index to be set by caller */
55 }
56
57 /** \internal
58   * initialize the HPI response structure
59   */
60 void hpi_init_response(struct hpi_response *phr, u16 object, u16 function,
61         u16 error)
62 {
63         memset(phr, 0, sizeof(*phr));
64         phr->type = HPI_TYPE_RESPONSE;
65         if ((object > 0) && (object <= HPI_OBJ_MAXINDEX))
66                 phr->size = res_size[object];
67         else
68                 phr->size = sizeof(*phr);
69         phr->object = object;
70         phr->function = function;
71         phr->error = error;
72         phr->specific_error = 0;
73         phr->version = 0;
74 }
75
76 void hpi_init_message_response(struct hpi_message *phm,
77         struct hpi_response *phr, u16 object, u16 function)
78 {
79         hpi_init_message(phm, object, function);
80         /* default error return if the response is
81            not filled in by the callee */
82         hpi_init_response(phr, object, function,
83                 HPI_ERROR_PROCESSING_MESSAGE);
84 }
85
86 static void hpi_init_messageV1(struct hpi_message_header *phm, u16 size,
87         u16 object, u16 function)
88 {
89         memset(phm, 0, sizeof(*phm));
90         if ((object > 0) && (object <= HPI_OBJ_MAXINDEX)) {
91                 phm->size = size;
92                 phm->type = HPI_TYPE_REQUEST;
93                 phm->object = object;
94                 phm->function = function;
95                 phm->version = 1;
96                 /* Expect adapter index to be set by caller */
97         }
98 }
99
100 void hpi_init_responseV1(struct hpi_response_header *phr, u16 size,
101         u16 object, u16 function)
102 {
103         memset(phr, 0, sizeof(*phr));
104         phr->size = size;
105         phr->version = 1;
106         phr->type = HPI_TYPE_RESPONSE;
107         phr->error = HPI_ERROR_PROCESSING_MESSAGE;
108 }
109
110 void hpi_init_message_responseV1(struct hpi_message_header *phm, u16 msg_size,
111         struct hpi_response_header *phr, u16 res_size, u16 object,
112         u16 function)
113 {
114         hpi_init_messageV1(phm, msg_size, object, function);
115         hpi_init_responseV1(phr, res_size, object, function);
116 }