hpicmn.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679
  1. /******************************************************************************
  2. AudioScience HPI driver
  3. Copyright (C) 1997-2010 AudioScience Inc. <support@audioscience.com>
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of version 2 of the GNU General Public License as
  6. published by the Free Software Foundation;
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program; if not, write to the Free Software
  13. Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  14. \file hpicmn.c
  15. Common functions used by hpixxxx.c modules
  16. (C) Copyright AudioScience Inc. 1998-2003
  17. *******************************************************************************/
  18. #define SOURCEFILE_NAME "hpicmn.c"
  19. #include "hpi_internal.h"
  20. #include "hpidebug.h"
  21. #include "hpimsginit.h"
  22. #include "hpicmn.h"
  23. struct hpi_adapters_list {
  24. struct hpios_spinlock list_lock;
  25. struct hpi_adapter_obj adapter[HPI_MAX_ADAPTERS];
  26. u16 gw_num_adapters;
  27. };
  28. static struct hpi_adapters_list adapters;
  29. /**
  30. * Given an HPI Message that was sent out and a response that was received,
  31. * validate that the response has the correct fields filled in,
  32. * i.e ObjectType, Function etc
  33. **/
  34. u16 hpi_validate_response(struct hpi_message *phm, struct hpi_response *phr)
  35. {
  36. if (phr->type != HPI_TYPE_RESPONSE) {
  37. HPI_DEBUG_LOG(ERROR, "header type %d invalid", phr->type);
  38. return HPI_ERROR_INVALID_RESPONSE;
  39. }
  40. if (phr->object != phm->object) {
  41. HPI_DEBUG_LOG(ERROR, "header object %d invalid", phr->object);
  42. return HPI_ERROR_INVALID_RESPONSE;
  43. }
  44. if (phr->function != phm->function) {
  45. HPI_DEBUG_LOG(ERROR, "header type %d invalid", phr->function);
  46. return HPI_ERROR_INVALID_RESPONSE;
  47. }
  48. return 0;
  49. }
  50. u16 hpi_add_adapter(struct hpi_adapter_obj *pao)
  51. {
  52. u16 retval = 0;
  53. /*HPI_ASSERT(pao->wAdapterType); */
  54. hpios_alistlock_lock(&adapters);
  55. if (pao->index >= HPI_MAX_ADAPTERS) {
  56. retval = HPI_ERROR_BAD_ADAPTER_NUMBER;
  57. goto unlock;
  58. }
  59. if (adapters.adapter[pao->index].adapter_type) {
  60. {
  61. retval = HPI_DUPLICATE_ADAPTER_NUMBER;
  62. goto unlock;
  63. }
  64. }
  65. adapters.adapter[pao->index] = *pao;
  66. hpios_dsplock_init(&adapters.adapter[pao->index]);
  67. adapters.gw_num_adapters++;
  68. unlock:
  69. hpios_alistlock_unlock(&adapters);
  70. return retval;
  71. }
  72. void hpi_delete_adapter(struct hpi_adapter_obj *pao)
  73. {
  74. if (!pao->adapter_type) {
  75. HPI_DEBUG_LOG(ERROR, "removing null adapter?\n");
  76. return;
  77. }
  78. hpios_alistlock_lock(&adapters);
  79. if (adapters.adapter[pao->index].adapter_type)
  80. adapters.gw_num_adapters--;
  81. memset(&adapters.adapter[pao->index], 0, sizeof(adapters.adapter[0]));
  82. hpios_alistlock_unlock(&adapters);
  83. }
  84. /**
  85. * FindAdapter returns a pointer to the struct hpi_adapter_obj with
  86. * index wAdapterIndex in an HPI_ADAPTERS_LIST structure.
  87. *
  88. */
  89. struct hpi_adapter_obj *hpi_find_adapter(u16 adapter_index)
  90. {
  91. struct hpi_adapter_obj *pao = NULL;
  92. if (adapter_index >= HPI_MAX_ADAPTERS) {
  93. HPI_DEBUG_LOG(VERBOSE, "find_adapter invalid index %d ",
  94. adapter_index);
  95. return NULL;
  96. }
  97. pao = &adapters.adapter[adapter_index];
  98. if (pao->adapter_type != 0) {
  99. /*
  100. HPI_DEBUG_LOG(VERBOSE, "Found adapter index %d\n",
  101. wAdapterIndex);
  102. */
  103. return pao;
  104. } else {
  105. /*
  106. HPI_DEBUG_LOG(VERBOSE, "No adapter index %d\n",
  107. wAdapterIndex);
  108. */
  109. return NULL;
  110. }
  111. }
  112. /**
  113. *
  114. * wipe an HPI_ADAPTERS_LIST structure.
  115. *
  116. **/
  117. static void wipe_adapter_list(void)
  118. {
  119. memset(&adapters, 0, sizeof(adapters));
  120. }
  121. static void subsys_get_adapter(struct hpi_message *phm,
  122. struct hpi_response *phr)
  123. {
  124. int count = phm->obj_index;
  125. u16 index = 0;
  126. /* find the nCount'th nonzero adapter in array */
  127. for (index = 0; index < HPI_MAX_ADAPTERS; index++) {
  128. if (adapters.adapter[index].adapter_type) {
  129. if (count == 0)
  130. break;
  131. count--;
  132. }
  133. }
  134. if (index < HPI_MAX_ADAPTERS) {
  135. phr->u.s.adapter_index = adapters.adapter[index].index;
  136. phr->u.s.aw_adapter_list[0] =
  137. adapters.adapter[index].adapter_type;
  138. } else {
  139. phr->u.s.adapter_index = 0;
  140. phr->u.s.aw_adapter_list[0] = 0;
  141. phr->error = HPI_ERROR_BAD_ADAPTER_NUMBER;
  142. }
  143. }
  144. static unsigned int control_cache_alloc_check(struct hpi_control_cache *pC)
  145. {
  146. unsigned int i;
  147. int cached = 0;
  148. if (!pC)
  149. return 0;
  150. if (pC->init)
  151. return pC->init;
  152. if (!pC->p_cache)
  153. return 0;
  154. if (pC->control_count && pC->cache_size_in_bytes) {
  155. char *p_master_cache;
  156. unsigned int byte_count = 0;
  157. p_master_cache = (char *)pC->p_cache;
  158. HPI_DEBUG_LOG(DEBUG, "check %d controls\n",
  159. pC->control_count);
  160. for (i = 0; i < pC->control_count; i++) {
  161. struct hpi_control_cache_info *info =
  162. (struct hpi_control_cache_info *)
  163. &p_master_cache[byte_count];
  164. if (!info->size_in32bit_words) {
  165. /* ? This is a severe error, the cache is probably
  166. corrupted. Minimum valid entry size is
  167. sizeof(struct hpi_control_cache_info) */
  168. HPI_DEBUG_LOG(ERROR,
  169. "zero size cache entry %d\n", i);
  170. break;
  171. }
  172. if (info->control_type) {
  173. pC->p_info[info->control_index] = info;
  174. cached++;
  175. } else /* dummy cache entry */
  176. pC->p_info[info->control_index] = NULL;
  177. byte_count += info->size_in32bit_words * 4;
  178. HPI_DEBUG_LOG(VERBOSE,
  179. "cached %d, pinfo %p index %d type %d size %d\n",
  180. cached, pC->p_info[info->control_index],
  181. info->control_index, info->control_type,
  182. info->size_in32bit_words);
  183. /* quit loop early if whole cache has been scanned. */
  184. /* pC->dwControlCount is the maximum possible entries, */
  185. /* but some may not be in the cache at all */
  186. if (byte_count >= pC->cache_size_in_bytes)
  187. break;
  188. /* have seen last control index */
  189. if (info->control_index == pC->control_count - 1)
  190. break;
  191. }
  192. if (byte_count != pC->cache_size_in_bytes)
  193. HPI_DEBUG_LOG(WARNING,
  194. "bytecount %d != cache size %d", byte_count,
  195. pC->cache_size_in_bytes);
  196. else
  197. HPI_DEBUG_LOG(DEBUG,
  198. "cache good. bytecount == cache size = %d",
  199. byte_count);
  200. pC->init = cached;
  201. }
  202. return pC->init;
  203. }
  204. /** Find a control.
  205. */
  206. static short find_control(u16 control_index,
  207. struct hpi_control_cache *p_cache, struct hpi_control_cache_info **pI)
  208. {
  209. if (!control_cache_alloc_check(p_cache)) {
  210. HPI_DEBUG_LOG(VERBOSE,
  211. "control_cache_alloc_check() failed %d\n",
  212. control_index);
  213. return 0;
  214. }
  215. *pI = p_cache->p_info[control_index];
  216. if (!*pI) {
  217. HPI_DEBUG_LOG(VERBOSE, "Uncached Control %d\n",
  218. control_index);
  219. return 0;
  220. } else {
  221. HPI_DEBUG_LOG(VERBOSE, "find_control() type %d\n",
  222. (*pI)->control_type);
  223. }
  224. return 1;
  225. }
  226. /** Used by the kernel driver to figure out if a buffer needs mapping.
  227. */
  228. short hpi_check_buffer_mapping(struct hpi_control_cache *p_cache,
  229. struct hpi_message *phm, void **p, unsigned int *pN)
  230. {
  231. *pN = 0;
  232. *p = NULL;
  233. if ((phm->function == HPI_CONTROL_GET_STATE)
  234. && (phm->object == HPI_OBJ_CONTROLEX)
  235. ) {
  236. struct hpi_control_cache_info *pI;
  237. if (!find_control(phm->obj_index, p_cache, &pI)) {
  238. HPI_DEBUG_LOG(VERBOSE,
  239. "HPICMN find_control() failed for adap %d\n",
  240. phm->adapter_index);
  241. return 0;
  242. }
  243. }
  244. return 0;
  245. }
  246. /* allow unified treatment of several string fields within struct */
  247. #define HPICMN_PAD_OFS_AND_SIZE(m) {\
  248. offsetof(struct hpi_control_cache_pad, m), \
  249. sizeof(((struct hpi_control_cache_pad *)(NULL))->m) }
  250. struct pad_ofs_size {
  251. unsigned int offset;
  252. unsigned int field_size;
  253. };
  254. static struct pad_ofs_size pad_desc[] = {
  255. HPICMN_PAD_OFS_AND_SIZE(c_channel), /* HPI_PAD_CHANNEL_NAME */
  256. HPICMN_PAD_OFS_AND_SIZE(c_artist), /* HPI_PAD_ARTIST */
  257. HPICMN_PAD_OFS_AND_SIZE(c_title), /* HPI_PAD_TITLE */
  258. HPICMN_PAD_OFS_AND_SIZE(c_comment), /* HPI_PAD_COMMENT */
  259. };
  260. /** CheckControlCache checks the cache and fills the struct hpi_response
  261. * accordingly. It returns one if a cache hit occurred, zero otherwise.
  262. */
  263. short hpi_check_control_cache(struct hpi_control_cache *p_cache,
  264. struct hpi_message *phm, struct hpi_response *phr)
  265. {
  266. short found = 1;
  267. struct hpi_control_cache_info *pI;
  268. struct hpi_control_cache_single *pC;
  269. struct hpi_control_cache_pad *p_pad;
  270. if (!find_control(phm->obj_index, p_cache, &pI)) {
  271. HPI_DEBUG_LOG(VERBOSE,
  272. "HPICMN find_control() failed for adap %d\n",
  273. phm->adapter_index);
  274. return 0;
  275. }
  276. phr->error = 0;
  277. /* pC is the default cached control strucure. May be cast to
  278. something else in the following switch statement.
  279. */
  280. pC = (struct hpi_control_cache_single *)pI;
  281. p_pad = (struct hpi_control_cache_pad *)pI;
  282. switch (pI->control_type) {
  283. case HPI_CONTROL_METER:
  284. if (phm->u.c.attribute == HPI_METER_PEAK) {
  285. phr->u.c.an_log_value[0] = pC->u.meter.an_log_peak[0];
  286. phr->u.c.an_log_value[1] = pC->u.meter.an_log_peak[1];
  287. } else if (phm->u.c.attribute == HPI_METER_RMS) {
  288. if (pC->u.meter.an_logRMS[0] ==
  289. HPI_CACHE_INVALID_SHORT) {
  290. phr->error =
  291. HPI_ERROR_INVALID_CONTROL_ATTRIBUTE;
  292. phr->u.c.an_log_value[0] = HPI_METER_MINIMUM;
  293. phr->u.c.an_log_value[1] = HPI_METER_MINIMUM;
  294. } else {
  295. phr->u.c.an_log_value[0] =
  296. pC->u.meter.an_logRMS[0];
  297. phr->u.c.an_log_value[1] =
  298. pC->u.meter.an_logRMS[1];
  299. }
  300. } else
  301. found = 0;
  302. break;
  303. case HPI_CONTROL_VOLUME:
  304. if (phm->u.c.attribute == HPI_VOLUME_GAIN) {
  305. phr->u.c.an_log_value[0] = pC->u.vol.an_log[0];
  306. phr->u.c.an_log_value[1] = pC->u.vol.an_log[1];
  307. } else
  308. found = 0;
  309. break;
  310. case HPI_CONTROL_MULTIPLEXER:
  311. if (phm->u.c.attribute == HPI_MULTIPLEXER_SOURCE) {
  312. phr->u.c.param1 = pC->u.mux.source_node_type;
  313. phr->u.c.param2 = pC->u.mux.source_node_index;
  314. } else {
  315. found = 0;
  316. }
  317. break;
  318. case HPI_CONTROL_CHANNEL_MODE:
  319. if (phm->u.c.attribute == HPI_CHANNEL_MODE_MODE)
  320. phr->u.c.param1 = pC->u.mode.mode;
  321. else
  322. found = 0;
  323. break;
  324. case HPI_CONTROL_LEVEL:
  325. if (phm->u.c.attribute == HPI_LEVEL_GAIN) {
  326. phr->u.c.an_log_value[0] = pC->u.level.an_log[0];
  327. phr->u.c.an_log_value[1] = pC->u.level.an_log[1];
  328. } else
  329. found = 0;
  330. break;
  331. case HPI_CONTROL_TUNER:
  332. if (phm->u.c.attribute == HPI_TUNER_FREQ)
  333. phr->u.c.param1 = pC->u.tuner.freq_ink_hz;
  334. else if (phm->u.c.attribute == HPI_TUNER_BAND)
  335. phr->u.c.param1 = pC->u.tuner.band;
  336. else if (phm->u.c.attribute == HPI_TUNER_LEVEL_AVG)
  337. if (pC->u.tuner.s_level_avg ==
  338. HPI_CACHE_INVALID_SHORT) {
  339. phr->u.cu.tuner.s_level = 0;
  340. phr->error =
  341. HPI_ERROR_INVALID_CONTROL_ATTRIBUTE;
  342. } else
  343. phr->u.cu.tuner.s_level =
  344. pC->u.tuner.s_level_avg;
  345. else
  346. found = 0;
  347. break;
  348. case HPI_CONTROL_AESEBU_RECEIVER:
  349. if (phm->u.c.attribute == HPI_AESEBURX_ERRORSTATUS)
  350. phr->u.c.param1 = pC->u.aes3rx.error_status;
  351. else if (phm->u.c.attribute == HPI_AESEBURX_FORMAT)
  352. phr->u.c.param1 = pC->u.aes3rx.format;
  353. else
  354. found = 0;
  355. break;
  356. case HPI_CONTROL_AESEBU_TRANSMITTER:
  357. if (phm->u.c.attribute == HPI_AESEBUTX_FORMAT)
  358. phr->u.c.param1 = pC->u.aes3tx.format;
  359. else
  360. found = 0;
  361. break;
  362. case HPI_CONTROL_TONEDETECTOR:
  363. if (phm->u.c.attribute == HPI_TONEDETECTOR_STATE)
  364. phr->u.c.param1 = pC->u.tone.state;
  365. else
  366. found = 0;
  367. break;
  368. case HPI_CONTROL_SILENCEDETECTOR:
  369. if (phm->u.c.attribute == HPI_SILENCEDETECTOR_STATE) {
  370. phr->u.c.param1 = pC->u.silence.state;
  371. /*? phr->u.c.dwParam2 = pC->u.silence.dwCount; */
  372. } else
  373. found = 0;
  374. break;
  375. case HPI_CONTROL_MICROPHONE:
  376. if (phm->u.c.attribute == HPI_MICROPHONE_PHANTOM_POWER)
  377. phr->u.c.param1 = pC->u.microphone.phantom_state;
  378. else
  379. found = 0;
  380. break;
  381. case HPI_CONTROL_SAMPLECLOCK:
  382. if (phm->u.c.attribute == HPI_SAMPLECLOCK_SOURCE)
  383. phr->u.c.param1 = pC->u.clk.source;
  384. else if (phm->u.c.attribute == HPI_SAMPLECLOCK_SOURCE_INDEX) {
  385. if (pC->u.clk.source_index ==
  386. HPI_CACHE_INVALID_UINT16) {
  387. phr->u.c.param1 = 0;
  388. phr->error =
  389. HPI_ERROR_INVALID_CONTROL_ATTRIBUTE;
  390. } else
  391. phr->u.c.param1 = pC->u.clk.source_index;
  392. } else if (phm->u.c.attribute == HPI_SAMPLECLOCK_SAMPLERATE)
  393. phr->u.c.param1 = pC->u.clk.sample_rate;
  394. else
  395. found = 0;
  396. break;
  397. case HPI_CONTROL_PAD:{
  398. struct hpi_control_cache_pad *p_pad;
  399. p_pad = (struct hpi_control_cache_pad *)pI;
  400. if (!(p_pad->field_valid_flags & (1 <<
  401. HPI_CTL_ATTR_INDEX(phm->u.c.
  402. attribute)))) {
  403. phr->error =
  404. HPI_ERROR_INVALID_CONTROL_ATTRIBUTE;
  405. break;
  406. }
  407. if (phm->u.c.attribute == HPI_PAD_PROGRAM_ID)
  408. phr->u.c.param1 = p_pad->pI;
  409. else if (phm->u.c.attribute == HPI_PAD_PROGRAM_TYPE)
  410. phr->u.c.param1 = p_pad->pTY;
  411. else {
  412. unsigned int index =
  413. HPI_CTL_ATTR_INDEX(phm->u.c.
  414. attribute) - 1;
  415. unsigned int offset = phm->u.c.param1;
  416. unsigned int pad_string_len, field_size;
  417. char *pad_string;
  418. unsigned int tocopy;
  419. if (index > ARRAY_SIZE(pad_desc) - 1) {
  420. phr->error =
  421. HPI_ERROR_INVALID_CONTROL_ATTRIBUTE;
  422. break;
  423. }
  424. pad_string =
  425. ((char *)p_pad) +
  426. pad_desc[index].offset;
  427. field_size = pad_desc[index].field_size;
  428. /* Ensure null terminator */
  429. pad_string[field_size - 1] = 0;
  430. pad_string_len = strlen(pad_string) + 1;
  431. if (offset > pad_string_len) {
  432. phr->error =
  433. HPI_ERROR_INVALID_CONTROL_VALUE;
  434. break;
  435. }
  436. tocopy = pad_string_len - offset;
  437. if (tocopy > sizeof(phr->u.cu.chars8.sz_data))
  438. tocopy = sizeof(phr->u.cu.chars8.
  439. sz_data);
  440. memcpy(phr->u.cu.chars8.sz_data,
  441. &pad_string[offset], tocopy);
  442. phr->u.cu.chars8.remaining_chars =
  443. pad_string_len - offset - tocopy;
  444. }
  445. }
  446. break;
  447. default:
  448. found = 0;
  449. break;
  450. }
  451. HPI_DEBUG_LOG(VERBOSE, "%s Adap %d, Ctl %d, Type %d, Attr %d\n",
  452. found ? "Cached" : "Uncached", phm->adapter_index,
  453. pI->control_index, pI->control_type, phm->u.c.attribute);
  454. if (found)
  455. phr->size =
  456. sizeof(struct hpi_response_header) +
  457. sizeof(struct hpi_control_res);
  458. return found;
  459. }
  460. /** Updates the cache with Set values.
  461. Only update if no error.
  462. Volume and Level return the limited values in the response, so use these
  463. Multiplexer does so use sent values
  464. */
  465. void hpi_cmn_control_cache_sync_to_msg(struct hpi_control_cache *p_cache,
  466. struct hpi_message *phm, struct hpi_response *phr)
  467. {
  468. struct hpi_control_cache_single *pC;
  469. struct hpi_control_cache_info *pI;
  470. if (phr->error)
  471. return;
  472. if (!find_control(phm->obj_index, p_cache, &pI)) {
  473. HPI_DEBUG_LOG(VERBOSE,
  474. "HPICMN find_control() failed for adap %d\n",
  475. phm->adapter_index);
  476. return;
  477. }
  478. /* pC is the default cached control strucure.
  479. May be cast to something else in the following switch statement.
  480. */
  481. pC = (struct hpi_control_cache_single *)pI;
  482. switch (pI->control_type) {
  483. case HPI_CONTROL_VOLUME:
  484. if (phm->u.c.attribute == HPI_VOLUME_GAIN) {
  485. pC->u.vol.an_log[0] = phr->u.c.an_log_value[0];
  486. pC->u.vol.an_log[1] = phr->u.c.an_log_value[1];
  487. }
  488. break;
  489. case HPI_CONTROL_MULTIPLEXER:
  490. /* mux does not return its setting on Set command. */
  491. if (phm->u.c.attribute == HPI_MULTIPLEXER_SOURCE) {
  492. pC->u.mux.source_node_type = (u16)phm->u.c.param1;
  493. pC->u.mux.source_node_index = (u16)phm->u.c.param2;
  494. }
  495. break;
  496. case HPI_CONTROL_CHANNEL_MODE:
  497. /* mode does not return its setting on Set command. */
  498. if (phm->u.c.attribute == HPI_CHANNEL_MODE_MODE)
  499. pC->u.mode.mode = (u16)phm->u.c.param1;
  500. break;
  501. case HPI_CONTROL_LEVEL:
  502. if (phm->u.c.attribute == HPI_LEVEL_GAIN) {
  503. pC->u.vol.an_log[0] = phr->u.c.an_log_value[0];
  504. pC->u.vol.an_log[1] = phr->u.c.an_log_value[1];
  505. }
  506. break;
  507. case HPI_CONTROL_MICROPHONE:
  508. if (phm->u.c.attribute == HPI_MICROPHONE_PHANTOM_POWER)
  509. pC->u.microphone.phantom_state = (u16)phm->u.c.param1;
  510. break;
  511. case HPI_CONTROL_AESEBU_TRANSMITTER:
  512. if (phm->u.c.attribute == HPI_AESEBUTX_FORMAT)
  513. pC->u.aes3tx.format = phm->u.c.param1;
  514. break;
  515. case HPI_CONTROL_AESEBU_RECEIVER:
  516. if (phm->u.c.attribute == HPI_AESEBURX_FORMAT)
  517. pC->u.aes3rx.format = phm->u.c.param1;
  518. break;
  519. case HPI_CONTROL_SAMPLECLOCK:
  520. if (phm->u.c.attribute == HPI_SAMPLECLOCK_SOURCE)
  521. pC->u.clk.source = (u16)phm->u.c.param1;
  522. else if (phm->u.c.attribute == HPI_SAMPLECLOCK_SOURCE_INDEX)
  523. pC->u.clk.source_index = (u16)phm->u.c.param1;
  524. else if (phm->u.c.attribute == HPI_SAMPLECLOCK_SAMPLERATE)
  525. pC->u.clk.sample_rate = phm->u.c.param1;
  526. break;
  527. default:
  528. break;
  529. }
  530. }
  531. struct hpi_control_cache *hpi_alloc_control_cache(const u32
  532. number_of_controls, const u32 size_in_bytes, u8 *pDSP_control_buffer)
  533. {
  534. struct hpi_control_cache *p_cache =
  535. kmalloc(sizeof(*p_cache), GFP_KERNEL);
  536. if (!p_cache)
  537. return NULL;
  538. p_cache->p_info =
  539. kmalloc(sizeof(*p_cache->p_info) * number_of_controls,
  540. GFP_KERNEL);
  541. if (!p_cache->p_info) {
  542. kfree(p_cache);
  543. return NULL;
  544. }
  545. p_cache->cache_size_in_bytes = size_in_bytes;
  546. p_cache->control_count = number_of_controls;
  547. p_cache->p_cache =
  548. (struct hpi_control_cache_single *)pDSP_control_buffer;
  549. p_cache->init = 0;
  550. return p_cache;
  551. }
  552. void hpi_free_control_cache(struct hpi_control_cache *p_cache)
  553. {
  554. if (p_cache) {
  555. kfree(p_cache->p_info);
  556. p_cache->p_info = NULL;
  557. p_cache->init = 0;
  558. kfree(p_cache);
  559. }
  560. }
  561. static void subsys_message(struct hpi_message *phm, struct hpi_response *phr)
  562. {
  563. hpi_init_response(phr, HPI_OBJ_SUBSYSTEM, phm->function, 0);
  564. switch (phm->function) {
  565. case HPI_SUBSYS_OPEN:
  566. case HPI_SUBSYS_CLOSE:
  567. case HPI_SUBSYS_DRIVER_UNLOAD:
  568. break;
  569. case HPI_SUBSYS_DRIVER_LOAD:
  570. wipe_adapter_list();
  571. hpios_alistlock_init(&adapters);
  572. break;
  573. case HPI_SUBSYS_GET_ADAPTER:
  574. subsys_get_adapter(phm, phr);
  575. break;
  576. case HPI_SUBSYS_GET_NUM_ADAPTERS:
  577. phr->u.s.num_adapters = adapters.gw_num_adapters;
  578. break;
  579. case HPI_SUBSYS_CREATE_ADAPTER:
  580. case HPI_SUBSYS_DELETE_ADAPTER:
  581. break;
  582. default:
  583. phr->error = HPI_ERROR_INVALID_FUNC;
  584. break;
  585. }
  586. }
  587. void HPI_COMMON(struct hpi_message *phm, struct hpi_response *phr)
  588. {
  589. switch (phm->type) {
  590. case HPI_TYPE_MESSAGE:
  591. switch (phm->object) {
  592. case HPI_OBJ_SUBSYSTEM:
  593. subsys_message(phm, phr);
  594. break;
  595. }
  596. break;
  597. default:
  598. phr->error = HPI_ERROR_INVALID_TYPE;
  599. break;
  600. }
  601. }