diff options
author | Eliot Blennerhassett <eliot@blennerhassett.gen.nz> | 2014-11-19 22:22:52 -0500 |
---|---|---|
committer | Takashi Iwai <tiwai@suse.de> | 2014-11-22 16:29:58 -0500 |
commit | c1464a885444dd7e9c4491177ee102b64adc46c5 (patch) | |
tree | 720a92a08ead20f065ac2b45128fb772b55d6117 | |
parent | e51c58c982a0f81baa6fdee7331a8700c8586be5 (diff) |
ALSA: asihpi: Refactor control cache code.
Signed-off-by: Eliot Blennerhassett <eliot@blennerhassett.gen.nz>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
-rw-r--r-- | sound/pci/asihpi/hpicmn.c | 107 |
1 files changed, 63 insertions, 44 deletions
diff --git a/sound/pci/asihpi/hpicmn.c b/sound/pci/asihpi/hpicmn.c index 7ed5c26c3737..c7751243dc42 100644 --- a/sound/pci/asihpi/hpicmn.c +++ b/sound/pci/asihpi/hpicmn.c | |||
@@ -1,7 +1,7 @@ | |||
1 | /****************************************************************************** | 1 | /****************************************************************************** |
2 | 2 | ||
3 | AudioScience HPI driver | 3 | AudioScience HPI driver |
4 | Copyright (C) 1997-2011 AudioScience Inc. <support@audioscience.com> | 4 | Copyright (C) 1997-2014 AudioScience Inc. <support@audioscience.com> |
5 | 5 | ||
6 | This program is free software; you can redistribute it and/or modify | 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 | 7 | it under the terms of version 2 of the GNU General Public License as |
@@ -206,6 +206,14 @@ static unsigned int control_cache_alloc_check(struct hpi_control_cache *pC) | |||
206 | struct hpi_control_cache_info *info = | 206 | struct hpi_control_cache_info *info = |
207 | (struct hpi_control_cache_info *) | 207 | (struct hpi_control_cache_info *) |
208 | &p_master_cache[byte_count]; | 208 | &p_master_cache[byte_count]; |
209 | u16 control_index = info->control_index; | ||
210 | |||
211 | if (control_index >= pC->control_count) { | ||
212 | HPI_DEBUG_LOG(INFO, | ||
213 | "adap %d control index %d out of range, cache not ready?\n", | ||
214 | pC->adap_idx, control_index); | ||
215 | return 0; | ||
216 | } | ||
209 | 217 | ||
210 | if (!info->size_in32bit_words) { | 218 | if (!info->size_in32bit_words) { |
211 | if (!i) { | 219 | if (!i) { |
@@ -225,10 +233,10 @@ static unsigned int control_cache_alloc_check(struct hpi_control_cache *pC) | |||
225 | } | 233 | } |
226 | 234 | ||
227 | if (info->control_type) { | 235 | if (info->control_type) { |
228 | pC->p_info[info->control_index] = info; | 236 | pC->p_info[control_index] = info; |
229 | cached++; | 237 | cached++; |
230 | } else { /* dummy cache entry */ | 238 | } else { /* dummy cache entry */ |
231 | pC->p_info[info->control_index] = NULL; | 239 | pC->p_info[control_index] = NULL; |
232 | } | 240 | } |
233 | 241 | ||
234 | byte_count += info->size_in32bit_words * 4; | 242 | byte_count += info->size_in32bit_words * 4; |
@@ -309,35 +317,18 @@ static const struct pad_ofs_size pad_desc[] = { | |||
309 | /** CheckControlCache checks the cache and fills the struct hpi_response | 317 | /** CheckControlCache checks the cache and fills the struct hpi_response |
310 | * accordingly. It returns one if a cache hit occurred, zero otherwise. | 318 | * accordingly. It returns one if a cache hit occurred, zero otherwise. |
311 | */ | 319 | */ |
312 | short hpi_check_control_cache(struct hpi_control_cache *p_cache, | 320 | short hpi_check_control_cache_single(struct hpi_control_cache_single *pC, |
313 | struct hpi_message *phm, struct hpi_response *phr) | 321 | struct hpi_message *phm, struct hpi_response *phr) |
314 | { | 322 | { |
315 | short found = 1; | ||
316 | struct hpi_control_cache_info *pI; | ||
317 | struct hpi_control_cache_single *pC; | ||
318 | size_t response_size; | 323 | size_t response_size; |
319 | if (!find_control(phm->obj_index, p_cache, &pI)) { | 324 | short found = 1; |
320 | HPI_DEBUG_LOG(VERBOSE, | ||
321 | "HPICMN find_control() failed for adap %d\n", | ||
322 | phm->adapter_index); | ||
323 | return 0; | ||
324 | } | ||
325 | |||
326 | phr->error = 0; | ||
327 | phr->specific_error = 0; | ||
328 | phr->version = 0; | ||
329 | 325 | ||
330 | /* set the default response size */ | 326 | /* set the default response size */ |
331 | response_size = | 327 | response_size = |
332 | sizeof(struct hpi_response_header) + | 328 | sizeof(struct hpi_response_header) + |
333 | sizeof(struct hpi_control_res); | 329 | sizeof(struct hpi_control_res); |
334 | 330 | ||
335 | /* pC is the default cached control strucure. May be cast to | 331 | switch (pC->u.i.control_type) { |
336 | something else in the following switch statement. | ||
337 | */ | ||
338 | pC = (struct hpi_control_cache_single *)pI; | ||
339 | |||
340 | switch (pI->control_type) { | ||
341 | 332 | ||
342 | case HPI_CONTROL_METER: | 333 | case HPI_CONTROL_METER: |
343 | if (phm->u.c.attribute == HPI_METER_PEAK) { | 334 | if (phm->u.c.attribute == HPI_METER_PEAK) { |
@@ -467,7 +458,7 @@ short hpi_check_control_cache(struct hpi_control_cache *p_cache, | |||
467 | break; | 458 | break; |
468 | case HPI_CONTROL_PAD:{ | 459 | case HPI_CONTROL_PAD:{ |
469 | struct hpi_control_cache_pad *p_pad; | 460 | struct hpi_control_cache_pad *p_pad; |
470 | p_pad = (struct hpi_control_cache_pad *)pI; | 461 | p_pad = (struct hpi_control_cache_pad *)pC; |
471 | 462 | ||
472 | if (!(p_pad->field_valid_flags & (1 << | 463 | if (!(p_pad->field_valid_flags & (1 << |
473 | HPI_CTL_ATTR_INDEX(phm->u.c. | 464 | HPI_CTL_ATTR_INDEX(phm->u.c. |
@@ -531,7 +522,8 @@ short hpi_check_control_cache(struct hpi_control_cache *p_cache, | |||
531 | 522 | ||
532 | HPI_DEBUG_LOG(VERBOSE, "%s Adap %d, Ctl %d, Type %d, Attr %d\n", | 523 | HPI_DEBUG_LOG(VERBOSE, "%s Adap %d, Ctl %d, Type %d, Attr %d\n", |
533 | found ? "Cached" : "Uncached", phm->adapter_index, | 524 | found ? "Cached" : "Uncached", phm->adapter_index, |
534 | pI->control_index, pI->control_type, phm->u.c.attribute); | 525 | pC->u.i.control_index, pC->u.i.control_type, |
526 | phm->u.c.attribute); | ||
535 | 527 | ||
536 | if (found) { | 528 | if (found) { |
537 | phr->size = (u16)response_size; | 529 | phr->size = (u16)response_size; |
@@ -543,34 +535,36 @@ short hpi_check_control_cache(struct hpi_control_cache *p_cache, | |||
543 | return found; | 535 | return found; |
544 | } | 536 | } |
545 | 537 | ||
546 | /** Updates the cache with Set values. | 538 | short hpi_check_control_cache(struct hpi_control_cache *p_cache, |
547 | |||
548 | Only update if no error. | ||
549 | Volume and Level return the limited values in the response, so use these | ||
550 | Multiplexer does so use sent values | ||
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) | 539 | struct hpi_message *phm, struct hpi_response *phr) |
554 | { | 540 | { |
555 | struct hpi_control_cache_single *pC; | ||
556 | struct hpi_control_cache_info *pI; | 541 | struct hpi_control_cache_info *pI; |
557 | 542 | ||
558 | if (phr->error) | ||
559 | return; | ||
560 | |||
561 | if (!find_control(phm->obj_index, p_cache, &pI)) { | 543 | if (!find_control(phm->obj_index, p_cache, &pI)) { |
562 | HPI_DEBUG_LOG(VERBOSE, | 544 | HPI_DEBUG_LOG(VERBOSE, |
563 | "HPICMN find_control() failed for adap %d\n", | 545 | "HPICMN find_control() failed for adap %d\n", |
564 | phm->adapter_index); | 546 | phm->adapter_index); |
565 | return; | 547 | return 0; |
566 | } | 548 | } |
567 | 549 | ||
568 | /* pC is the default cached control strucure. | 550 | phr->error = 0; |
569 | May be cast to something else in the following switch statement. | 551 | phr->specific_error = 0; |
570 | */ | 552 | phr->version = 0; |
571 | pC = (struct hpi_control_cache_single *)pI; | 553 | |
554 | return hpi_check_control_cache_single((struct hpi_control_cache_single | ||
555 | *)pI, phm, phr); | ||
556 | } | ||
557 | |||
558 | /** Updates the cache with Set values. | ||
572 | 559 | ||
573 | switch (pI->control_type) { | 560 | Only update if no error. |
561 | Volume and Level return the limited values in the response, so use these | ||
562 | Multiplexer does so use sent values | ||
563 | */ | ||
564 | void hpi_cmn_control_cache_sync_to_msg_single(struct hpi_control_cache_single | ||
565 | *pC, struct hpi_message *phm, struct hpi_response *phr) | ||
566 | { | ||
567 | switch (pC->u.i.control_type) { | ||
574 | case HPI_CONTROL_VOLUME: | 568 | case HPI_CONTROL_VOLUME: |
575 | if (phm->u.c.attribute == HPI_VOLUME_GAIN) { | 569 | if (phm->u.c.attribute == HPI_VOLUME_GAIN) { |
576 | pC->u.vol.an_log[0] = phr->u.c.an_log_value[0]; | 570 | pC->u.vol.an_log[0] = phr->u.c.an_log_value[0]; |
@@ -625,6 +619,30 @@ void hpi_cmn_control_cache_sync_to_msg(struct hpi_control_cache *p_cache, | |||
625 | } | 619 | } |
626 | } | 620 | } |
627 | 621 | ||
622 | void hpi_cmn_control_cache_sync_to_msg(struct hpi_control_cache *p_cache, | ||
623 | struct hpi_message *phm, struct hpi_response *phr) | ||
624 | { | ||
625 | struct hpi_control_cache_single *pC; | ||
626 | struct hpi_control_cache_info *pI; | ||
627 | |||
628 | if (phr->error) | ||
629 | return; | ||
630 | |||
631 | if (!find_control(phm->obj_index, p_cache, &pI)) { | ||
632 | HPI_DEBUG_LOG(VERBOSE, | ||
633 | "HPICMN find_control() failed for adap %d\n", | ||
634 | phm->adapter_index); | ||
635 | return; | ||
636 | } | ||
637 | |||
638 | /* pC is the default cached control strucure. | ||
639 | May be cast to something else in the following switch statement. | ||
640 | */ | ||
641 | pC = (struct hpi_control_cache_single *)pI; | ||
642 | |||
643 | hpi_cmn_control_cache_sync_to_msg_single(pC, phm, phr); | ||
644 | } | ||
645 | |||
628 | /** Allocate control cache. | 646 | /** Allocate control cache. |
629 | 647 | ||
630 | \return Cache pointer, or NULL if allocation fails. | 648 | \return Cache pointer, or NULL if allocation fails. |
@@ -637,12 +655,13 @@ struct hpi_control_cache *hpi_alloc_control_cache(const u32 control_count, | |||
637 | if (!p_cache) | 655 | if (!p_cache) |
638 | return NULL; | 656 | return NULL; |
639 | 657 | ||
640 | p_cache->p_info = kcalloc(control_count, sizeof(*p_cache->p_info), | 658 | p_cache->p_info = |
641 | GFP_KERNEL); | 659 | kcalloc(control_count, sizeof(*p_cache->p_info), GFP_KERNEL); |
642 | if (!p_cache->p_info) { | 660 | if (!p_cache->p_info) { |
643 | kfree(p_cache); | 661 | kfree(p_cache); |
644 | return NULL; | 662 | return NULL; |
645 | } | 663 | } |
664 | |||
646 | p_cache->cache_size_in_bytes = size_in_bytes; | 665 | p_cache->cache_size_in_bytes = size_in_bytes; |
647 | p_cache->control_count = control_count; | 666 | p_cache->control_count = control_count; |
648 | p_cache->p_cache = p_dsp_control_buffer; | 667 | p_cache->p_cache = p_dsp_control_buffer; |