hpicmn.c 18 KB

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