blob: 6f822ea6cf23d4469bde0bd9729e2d61d5852bf5 [file] [log] [blame]
Quinn Male2e883752019-03-22 11:28:54 -07001/* st_hw_common.h
2 *
3 * Contains common functionality between
4 * sound trigger hw and sound trigger extension interface.
5 *
6 * Copyright (c) 2016, 2018-2019, The Linux Foundation. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions are
10 * met:
11 * * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * * Redistributions in binary form must reproduce the above
14 * copyright notice, this list of conditions and the following
15 * disclaimer in the documentation and/or other materials provided
16 * with the distribution.
17 * * Neither the name of The Linux Foundation nor the names of its
18 * contributors may be used to endorse or promote products derived
19 * from this software without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
22 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
23 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
25 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
28 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
29 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
30 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
31 * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 */
33
34#include "sound_trigger_hw.h"
35#include "st_session.h"
36
37bool st_hw_check_ses_ss_usecase_allowed(st_session_t *st_ses);
Quinn Malecc1affd2019-07-18 16:13:31 -070038void st_hw_check_and_update_lpi(struct sound_trigger_device *stdev, st_session_t *st_ses);
Quinn Male2e883752019-03-22 11:28:54 -070039bool st_hw_check_vad_support(struct sound_trigger_device *stdev, st_session_t *st_ses, bool lpi_enable);
40void st_hw_check_and_set_lpi_mode(st_session_t *st_ses);
41bool st_hw_check_multi_stage_lsm_support();
42int st_hw_ses_update_config(st_session_t *st_ses, st_hw_session_t *st_hw_ses);
43
44int stop_other_sessions(struct sound_trigger_device *stdev,
45 st_session_t *cur_ses);
46int start_other_sessions(struct sound_trigger_device *stdev,
47 st_session_t *cur_ses);
48st_session_t* get_sound_trigger_session(struct sound_trigger_device *stdev,
49 sound_model_handle_t sound_model_handle);
50
51/* callback to hw for session events */
52typedef void (*hw_session_notify_callback_t)(sound_model_handle_t handle,
53 st_session_event_id_t event);
54int hw_session_notifier_init(hw_session_notify_callback_t cb);
55void hw_session_notifier_deinit();
56int hw_session_notifier_enqueue(sound_model_handle_t handle,
57 st_session_event_id_t event, uint64_t delay_ms);
58int hw_session_notifier_cancel(sound_model_handle_t handle,
59 st_session_event_id_t event);
60
61/* 2nd stage detection */
62int st_hw_ses_get_hist_buff_payload(st_hw_session_t *p_ses,
63 uint8_t *payload_buff, size_t buff_size);
Quinn Male2e883752019-03-22 11:28:54 -070064
65static inline uint64_t get_current_time_ns()
66{
67 struct timespec ts;
68
69 clock_gettime(CLOCK_MONOTONIC, &ts);
70 return (ts.tv_sec * NSECS_PER_SEC) + ts.tv_nsec;
71}
72
73static inline unsigned int convert_ms_to_bytes
74(
75 unsigned int input_ms,
76 struct pcm_config *config
77)
78{
79 return ((input_ms * config->rate * config->channels *
80 (pcm_format_to_bits(config->format) >> 3)) / 1000);
81}
82
83static inline unsigned int convert_bytes_to_ms
84(
85 unsigned int input_bytes,
86 struct pcm_config *config
87)
88{
89 return ((input_bytes * 1000) / (config->rate * config->channels *
90 (pcm_format_to_bits(config->format) >> 3)));
91}