hpicmn.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722
  1. /******************************************************************************
  2. AudioScience HPI driver
  3. Copyright (C) 1997-2014 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 function %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->type); */
  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].type) {
  62. int a;
  63. for (a = HPI_MAX_ADAPTERS - 1; a >= 0; a--) {
  64. if (!adapters.adapter[a].type) {
  65. HPI_DEBUG_LOG(WARNING,
  66. "ASI%X duplicate index %d moved to %d\n",
  67. pao->type, pao->index, a);
  68. pao->index = a;
  69. break;
  70. }
  71. }
  72. if (a < 0) {
  73. retval = HPI_ERROR_DUPLICATE_ADAPTER_NUMBER;
  74. goto unlock;
  75. }
  76. }
  77. adapters.adapter[pao->index] = *pao;
  78. hpios_dsplock_init(&adapters.adapter[pao->index]);
  79. adapters.gw_num_adapters++;
  80. unlock:
  81. hpios_alistlock_unlock(&adapters);
  82. return retval;
  83. }
  84. void hpi_delete_adapter(struct hpi_adapter_obj *pao)
  85. {
  86. if (!pao->type) {
  87. HPI_DEBUG_LOG(ERROR, "removing null adapter?\n");
  88. return;
  89. }
  90. hpios_alistlock_lock(&adapters);
  91. if (adapters.adapter[pao->index].type)
  92. adapters.gw_num_adapters--;
  93. memset(&adapters.adapter[pao->index], 0, sizeof(adapters.adapter[0]));
  94. hpios_alistlock_unlock(&adapters);
  95. }
  96. /**
  97. * FindAdapter returns a pointer to the struct hpi_adapter_obj with
  98. * index wAdapterIndex in an HPI_ADAPTERS_LIST structure.
  99. *
  100. */
  101. struct hpi_adapter_obj *hpi_find_adapter(u16 adapter_index)
  102. {
  103. struct hpi_adapter_obj *pao = NULL;
  104. if (adapter_index >= HPI_MAX_ADAPTERS) {
  105. HPI_DEBUG_LOG(VERBOSE, "find_adapter invalid index %d\n",
  106. adapter_index);
  107. return NULL;
  108. }
  109. pao = &adapters.adapter[adapter_index];
  110. if (pao->type != 0) {
  111. /*
  112. HPI_DEBUG_LOG(VERBOSE, "Found adapter index %d\n",
  113. wAdapterIndex);
  114. */
  115. return pao;
  116. } else {
  117. /*
  118. HPI_DEBUG_LOG(VERBOSE, "No adapter index %d\n",
  119. wAdapterIndex);
  120. */
  121. return NULL;
  122. }
  123. }
  124. /**
  125. *
  126. * wipe an HPI_ADAPTERS_LIST structure.
  127. *
  128. **/
  129. static void wipe_adapter_list(void)
  130. {
  131. memset(&adapters, 0, sizeof(adapters));
  132. }
  133. static void subsys_get_adapter(struct hpi_message *phm,
  134. struct hpi_response *phr)
  135. {
  136. int count = phm->obj_index;
  137. u16 index = 0;
  138. /* find the nCount'th nonzero adapter in array */
  139. for (index = 0; index < HPI_MAX_ADAPTERS; index++) {
  140. if (adapters.adapter[index].type) {
  141. if (!count)
  142. break;
  143. count--;
  144. }
  145. }
  146. if (index < HPI_MAX_ADAPTERS) {
  147. phr->u.s.adapter_index = adapters.adapter[index].index;
  148. phr->u.s.adapter_type = adapters.adapter[index].type;
  149. } else {
  150. phr->u.s.adapter_index = 0;
  151. phr->u.s.adapter_type = 0;
  152. phr->error = HPI_ERROR_INVALID_OBJ_INDEX;
  153. }
  154. }
  155. static unsigned int control_cache_alloc_check(struct hpi_control_cache *pC)
  156. {
  157. unsigned int i;
  158. int cached = 0;
  159. if (!pC)
  160. return 0;
  161. if (pC->init)
  162. return pC->init;
  163. if (!pC->p_cache)
  164. return 0;
  165. if (pC->control_count && pC->cache_size_in_bytes) {
  166. char *p_master_cache;
  167. unsigned int byte_count = 0;
  168. p_master_cache = (char *)pC->p_cache;
  169. HPI_DEBUG_LOG(DEBUG, "check %d controls\n",
  170. pC->control_count);
  171. for (i = 0; i < pC->control_count; i++) {
  172. struct hpi_control_cache_info *info =
  173. (struct hpi_control_cache_info *)
  174. &p_master_cache[byte_count];
  175. u16 control_index = info->control_index;
  176. if (control_index >= pC->control_count) {
  177. HPI_DEBUG_LOG(INFO,
  178. "adap %d control index %d out of range, cache not ready?\n",
  179. pC->adap_idx, control_index);
  180. return 0;
  181. }
  182. if (!info->size_in32bit_words) {
  183. if (!i) {
  184. HPI_DEBUG_LOG(INFO,
  185. "adap %d cache not ready?\n",
  186. pC->adap_idx);
  187. return 0;
  188. }
  189. /* The cache is invalid.
  190. * Minimum valid entry size is
  191. * sizeof(struct hpi_control_cache_info)
  192. */
  193. HPI_DEBUG_LOG(ERROR,
  194. "adap %d zero size cache entry %d\n",
  195. pC->adap_idx, i);
  196. break;
  197. }
  198. if (info->control_type) {
  199. pC->p_info[control_index] = info;
  200. cached++;
  201. } else { /* dummy cache entry */
  202. pC->p_info[control_index] = NULL;
  203. }
  204. byte_count += info->size_in32bit_words * 4;
  205. HPI_DEBUG_LOG(VERBOSE,
  206. "cached %d, pinfo %p index %d type %d size %d\n",
  207. cached, pC->p_info[info->control_index],
  208. info->control_index, info->control_type,
  209. info->size_in32bit_words);
  210. /* quit loop early if whole cache has been scanned.
  211. * dwControlCount is the maximum possible entries
  212. * but some may be absent from the cache
  213. */
  214. if (byte_count >= pC->cache_size_in_bytes)
  215. break;
  216. /* have seen last control index */
  217. if (info->control_index == pC->control_count - 1)
  218. break;
  219. }
  220. if (byte_count != pC->cache_size_in_bytes)
  221. HPI_DEBUG_LOG(WARNING,
  222. "adap %d bytecount %d != cache size %d\n",
  223. pC->adap_idx, byte_count,
  224. pC->cache_size_in_bytes);
  225. else
  226. HPI_DEBUG_LOG(DEBUG,
  227. "adap %d cache good, bytecount == cache size = %d\n",
  228. pC->adap_idx, byte_count);
  229. pC->init = (u16)cached;
  230. }
  231. return pC->init;
  232. }
  233. /** Find a control.
  234. */
  235. static short find_control(u16 control_index,
  236. struct hpi_control_cache *p_cache, struct hpi_control_cache_info **pI)
  237. {
  238. if (!control_cache_alloc_check(p_cache)) {
  239. HPI_DEBUG_LOG(VERBOSE,
  240. "control_cache_alloc_check() failed %d\n",
  241. control_index);
  242. return 0;
  243. }
  244. *pI = p_cache->p_info[control_index];
  245. if (!*pI) {
  246. HPI_DEBUG_LOG(VERBOSE, "Uncached Control %d\n",
  247. control_index);
  248. return 0;
  249. } else {
  250. HPI_DEBUG_LOG(VERBOSE, "find_control() type %d\n",
  251. (*pI)->control_type);
  252. }
  253. return 1;
  254. }
  255. /* allow unified treatment of several string fields within struct */
  256. #define HPICMN_PAD_OFS_AND_SIZE(m) {\
  257. offsetof(struct hpi_control_cache_pad, m), \
  258. sizeof(((struct hpi_control_cache_pad *)(NULL))->m) }
  259. struct pad_ofs_size {
  260. unsigned int offset;
  261. unsigned int field_size;
  262. };
  263. static const struct pad_ofs_size pad_desc[] = {
  264. HPICMN_PAD_OFS_AND_SIZE(c_channel), /* HPI_PAD_CHANNEL_NAME */
  265. HPICMN_PAD_OFS_AND_SIZE(c_artist), /* HPI_PAD_ARTIST */
  266. HPICMN_PAD_OFS_AND_SIZE(c_title), /* HPI_PAD_TITLE */
  267. HPICMN_PAD_OFS_AND_SIZE(c_comment), /* HPI_PAD_COMMENT */
  268. };
  269. /** CheckControlCache checks the cache and fills the struct hpi_response
  270. * accordingly. It returns one if a cache hit occurred, zero otherwise.
  271. */
  272. short hpi_check_control_cache_single(struct hpi_control_cache_single *pC,
  273. struct hpi_message *phm, struct hpi_response *phr)
  274. {
  275. size_t response_size;
  276. short found = 1;
  277. /* set the default response size */
  278. response_size =
  279. sizeof(struct hpi_response_header) +
  280. sizeof(struct hpi_control_res);
  281. switch (pC->u.i.control_type) {
  282. case HPI_CONTROL_METER:
  283. if (phm->u.c.attribute == HPI_METER_PEAK) {
  284. phr->u.c.an_log_value[0] = pC->u.meter.an_log_peak[0];
  285. phr->u.c.an_log_value[1] = pC->u.meter.an_log_peak[1];
  286. } else if (phm->u.c.attribute == HPI_METER_RMS) {
  287. if (pC->u.meter.an_logRMS[0] ==
  288. HPI_CACHE_INVALID_SHORT) {
  289. phr->error =
  290. HPI_ERROR_INVALID_CONTROL_ATTRIBUTE;
  291. phr->u.c.an_log_value[0] = HPI_METER_MINIMUM;
  292. phr->u.c.an_log_value[1] = HPI_METER_MINIMUM;
  293. } else {
  294. phr->u.c.an_log_value[0] =
  295. pC->u.meter.an_logRMS[0];
  296. phr->u.c.an_log_value[1] =
  297. pC->u.meter.an_logRMS[1];
  298. }
  299. } else
  300. found = 0;
  301. break;
  302. case HPI_CONTROL_VOLUME:
  303. if (phm->u.c.attribute == HPI_VOLUME_GAIN) {
  304. phr->u.c.an_log_value[0] = pC->u.vol.an_log[0];
  305. phr->u.c.an_log_value[1] = pC->u.vol.an_log[1];
  306. } else if (phm->u.c.attribute == HPI_VOLUME_MUTE) {
  307. if (pC->u.vol.flags & HPI_VOLUME_FLAG_HAS_MUTE) {
  308. if (pC->u.vol.flags & HPI_VOLUME_FLAG_MUTED)
  309. phr->u.c.param1 =
  310. HPI_BITMASK_ALL_CHANNELS;
  311. else
  312. phr->u.c.param1 = 0;
  313. } else {
  314. phr->error =
  315. HPI_ERROR_INVALID_CONTROL_ATTRIBUTE;
  316. phr->u.c.param1 = 0;
  317. }
  318. } else {
  319. found = 0;
  320. }
  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 *)pC;
  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. pC->u.i.control_index, pC->u.i.control_type,
  465. phm->u.c.attribute);
  466. if (found) {
  467. phr->size = (u16)response_size;
  468. phr->type = HPI_TYPE_RESPONSE;
  469. phr->object = phm->object;
  470. phr->function = phm->function;
  471. }
  472. return found;
  473. }
  474. short hpi_check_control_cache(struct hpi_control_cache *p_cache,
  475. struct hpi_message *phm, struct hpi_response *phr)
  476. {
  477. struct hpi_control_cache_info *pI;
  478. if (!find_control(phm->obj_index, p_cache, &pI)) {
  479. HPI_DEBUG_LOG(VERBOSE,
  480. "HPICMN find_control() failed for adap %d\n",
  481. phm->adapter_index);
  482. return 0;
  483. }
  484. phr->error = 0;
  485. phr->specific_error = 0;
  486. phr->version = 0;
  487. return hpi_check_control_cache_single((struct hpi_control_cache_single
  488. *)pI, phm, phr);
  489. }
  490. /** Updates the cache with Set values.
  491. Only update if no error.
  492. Volume and Level return the limited values in the response, so use these
  493. Multiplexer does so use sent values
  494. */
  495. void hpi_cmn_control_cache_sync_to_msg_single(struct hpi_control_cache_single
  496. *pC, struct hpi_message *phm, struct hpi_response *phr)
  497. {
  498. switch (pC->u.i.control_type) {
  499. case HPI_CONTROL_VOLUME:
  500. if (phm->u.c.attribute == HPI_VOLUME_GAIN) {
  501. pC->u.vol.an_log[0] = phr->u.c.an_log_value[0];
  502. pC->u.vol.an_log[1] = phr->u.c.an_log_value[1];
  503. } else if (phm->u.c.attribute == HPI_VOLUME_MUTE) {
  504. if (phm->u.c.param1)
  505. pC->u.vol.flags |= HPI_VOLUME_FLAG_MUTED;
  506. else
  507. pC->u.vol.flags &= ~HPI_VOLUME_FLAG_MUTED;
  508. }
  509. break;
  510. case HPI_CONTROL_MULTIPLEXER:
  511. /* mux does not return its setting on Set command. */
  512. if (phm->u.c.attribute == HPI_MULTIPLEXER_SOURCE) {
  513. pC->u.mux.source_node_type = (u16)phm->u.c.param1;
  514. pC->u.mux.source_node_index = (u16)phm->u.c.param2;
  515. }
  516. break;
  517. case HPI_CONTROL_CHANNEL_MODE:
  518. /* mode does not return its setting on Set command. */
  519. if (phm->u.c.attribute == HPI_CHANNEL_MODE_MODE)
  520. pC->u.mode.mode = (u16)phm->u.c.param1;
  521. break;
  522. case HPI_CONTROL_LEVEL:
  523. if (phm->u.c.attribute == HPI_LEVEL_GAIN) {
  524. pC->u.vol.an_log[0] = phr->u.c.an_log_value[0];
  525. pC->u.vol.an_log[1] = phr->u.c.an_log_value[1];
  526. }
  527. break;
  528. case HPI_CONTROL_MICROPHONE:
  529. if (phm->u.c.attribute == HPI_MICROPHONE_PHANTOM_POWER)
  530. pC->u.microphone.phantom_state = (u16)phm->u.c.param1;
  531. break;
  532. case HPI_CONTROL_AESEBU_TRANSMITTER:
  533. if (phm->u.c.attribute == HPI_AESEBUTX_FORMAT)
  534. pC->u.aes3tx.format = phm->u.c.param1;
  535. break;
  536. case HPI_CONTROL_AESEBU_RECEIVER:
  537. if (phm->u.c.attribute == HPI_AESEBURX_FORMAT)
  538. pC->u.aes3rx.format = phm->u.c.param1;
  539. break;
  540. case HPI_CONTROL_SAMPLECLOCK:
  541. if (phm->u.c.attribute == HPI_SAMPLECLOCK_SOURCE)
  542. pC->u.clk.source = (u16)phm->u.c.param1;
  543. else if (phm->u.c.attribute == HPI_SAMPLECLOCK_SOURCE_INDEX)
  544. pC->u.clk.source_index = (u16)phm->u.c.param1;
  545. else if (phm->u.c.attribute == HPI_SAMPLECLOCK_SAMPLERATE)
  546. pC->u.clk.sample_rate = phm->u.c.param1;
  547. break;
  548. default:
  549. break;
  550. }
  551. }
  552. void hpi_cmn_control_cache_sync_to_msg(struct hpi_control_cache *p_cache,
  553. struct hpi_message *phm, struct hpi_response *phr)
  554. {
  555. struct hpi_control_cache_single *pC;
  556. struct hpi_control_cache_info *pI;
  557. if (phr->error)
  558. return;
  559. if (!find_control(phm->obj_index, p_cache, &pI)) {
  560. HPI_DEBUG_LOG(VERBOSE,
  561. "HPICMN find_control() failed for adap %d\n",
  562. phm->adapter_index);
  563. return;
  564. }
  565. /* pC is the default cached control strucure.
  566. May be cast to something else in the following switch statement.
  567. */
  568. pC = (struct hpi_control_cache_single *)pI;
  569. hpi_cmn_control_cache_sync_to_msg_single(pC, phm, phr);
  570. }
  571. /** Allocate control cache.
  572. \return Cache pointer, or NULL if allocation fails.
  573. */
  574. struct hpi_control_cache *hpi_alloc_control_cache(const u32 control_count,
  575. const u32 size_in_bytes, u8 *p_dsp_control_buffer)
  576. {
  577. struct hpi_control_cache *p_cache =
  578. kmalloc(sizeof(*p_cache), GFP_KERNEL);
  579. if (!p_cache)
  580. return NULL;
  581. p_cache->p_info =
  582. kcalloc(control_count, sizeof(*p_cache->p_info), GFP_KERNEL);
  583. if (!p_cache->p_info) {
  584. kfree(p_cache);
  585. return NULL;
  586. }
  587. p_cache->cache_size_in_bytes = size_in_bytes;
  588. p_cache->control_count = control_count;
  589. p_cache->p_cache = p_dsp_control_buffer;
  590. p_cache->init = 0;
  591. return p_cache;
  592. }
  593. void hpi_free_control_cache(struct hpi_control_cache *p_cache)
  594. {
  595. if (p_cache) {
  596. kfree(p_cache->p_info);
  597. kfree(p_cache);
  598. }
  599. }
  600. static void subsys_message(struct hpi_message *phm, struct hpi_response *phr)
  601. {
  602. hpi_init_response(phr, HPI_OBJ_SUBSYSTEM, phm->function, 0);
  603. switch (phm->function) {
  604. case HPI_SUBSYS_OPEN:
  605. case HPI_SUBSYS_CLOSE:
  606. case HPI_SUBSYS_DRIVER_UNLOAD:
  607. break;
  608. case HPI_SUBSYS_DRIVER_LOAD:
  609. wipe_adapter_list();
  610. hpios_alistlock_init(&adapters);
  611. break;
  612. case HPI_SUBSYS_GET_ADAPTER:
  613. subsys_get_adapter(phm, phr);
  614. break;
  615. case HPI_SUBSYS_GET_NUM_ADAPTERS:
  616. phr->u.s.num_adapters = adapters.gw_num_adapters;
  617. break;
  618. case HPI_SUBSYS_CREATE_ADAPTER:
  619. break;
  620. default:
  621. phr->error = HPI_ERROR_INVALID_FUNC;
  622. break;
  623. }
  624. }
  625. void HPI_COMMON(struct hpi_message *phm, struct hpi_response *phr)
  626. {
  627. switch (phm->type) {
  628. case HPI_TYPE_REQUEST:
  629. switch (phm->object) {
  630. case HPI_OBJ_SUBSYSTEM:
  631. subsys_message(phm, phr);
  632. break;
  633. }
  634. break;
  635. default:
  636. phr->error = HPI_ERROR_INVALID_TYPE;
  637. break;
  638. }
  639. }