@@ -106,7 +106,7 @@ static uint64_t vol_work(void *data, uint64_t delay)
106106 vol += VOL_RAMP_STEP ;
107107
108108 /* ramp completed ? */
109- if (vol >= cd -> tvolume [i ] || vol >= VOL_MAX )
109+ if (vol >= cd -> tvolume [i ] || vol >= cd -> max_volume )
110110 vol_update (cd , i );
111111 else {
112112 cd -> volume [i ] = vol ;
@@ -121,7 +121,7 @@ static uint64_t vol_work(void *data, uint64_t delay)
121121 } else {
122122 /* ramp completed ? */
123123 if (new_vol <= cd -> tvolume [i ] ||
124- new_vol <= VOL_MIN ) {
124+ new_vol <= cd -> min_volume ) {
125125 vol_update (cd , i );
126126 } else {
127127 cd -> volume [i ] = new_vol ;
@@ -141,6 +141,23 @@ static uint64_t vol_work(void *data, uint64_t delay)
141141 return 0 ;
142142}
143143
144+ /**
145+ * \brief Validates and sets minimum and maximum volume levels.
146+ * \details If max_vol < min_vol or it's equals 0 then set max_vol = VOL_MAX
147+ * \param[in,out] cd Volume component private data.
148+ * \param[in] min_vol Minimum volume level
149+ * \param[in] max_vol Maximum volume level
150+ */
151+ static void vol_set_min_max_levels (struct comp_data * cd ,
152+ uint32_t min_vol , uint32_t max_vol )
153+ {
154+ if (max_vol < min_vol || max_vol == 0 )
155+ cd -> max_volume = VOL_ZERO_DB ;
156+ else
157+ cd -> max_volume = max_vol ;
158+ cd -> min_volume = min_vol ;
159+ }
160+
144161/**
145162 * \brief Creates volume component.
146163 * \param[in,out] data Volume base component device.
@@ -177,10 +194,13 @@ static struct comp_dev *volume_new(struct sof_ipc_comp *comp)
177194
178195 /* set the default volumes */
179196 for (i = 0 ; i < PLATFORM_MAX_CHANNELS ; i ++ ) {
180- cd -> volume [i ] = VOL_MAX ;
181- cd -> tvolume [i ] = VOL_MAX ;
197+ cd -> volume [i ] = VOL_ZERO_DB ;
198+ cd -> tvolume [i ] = VOL_ZERO_DB ;
182199 }
183200
201+ /* set volume min/max levels */
202+ vol_set_min_max_levels (cd , ipc_vol -> min_value , ipc_vol -> max_value );
203+
184204 dev -> state = COMP_STATE_READY ;
185205 return dev ;
186206}
@@ -234,11 +254,11 @@ static inline void volume_set_chan(struct comp_dev *dev, int chan, uint32_t vol)
234254 * multiplication overflow with the 32 bit value. Non-zero MIN option
235255 * can be useful to prevent totally muted small volume gain.
236256 */
237- if (v <= VOL_MIN )
238- v = VOL_MIN ;
257+ if (v <= cd -> min_volume )
258+ v = cd -> min_volume ;
239259
240- if (v > VOL_MAX )
241- v = VOL_MAX ;
260+ if (v > cd -> max_volume )
261+ v = cd -> max_volume ;
242262
243263 cd -> tvolume [chan ] = v ;
244264}
0 commit comments