@@ -83,6 +83,10 @@ struct twl6040_data {
8383 int hs_power_mode_locked ;
8484 unsigned int clk_in ;
8585 unsigned int sysclk ;
86+ u16 hs_left_step ;
87+ u16 hs_right_step ;
88+ u16 hf_left_step ;
89+ u16 hf_right_step ;
8690 struct snd_pcm_hw_constraint_list * sysclk_constraints ;
8791 struct twl6040_jack_data hs_jack ;
8892 struct snd_soc_codec * codec ;
@@ -339,7 +343,11 @@ static inline int twl6040_hs_ramp_step(struct snd_soc_codec *codec,
339343 if (headset -> ramp == TWL6040_RAMP_UP ) {
340344 /* ramp step up */
341345 if (val < headset -> left_vol ) {
342- val += left_step ;
346+ if (val + left_step > headset -> left_vol )
347+ val = headset -> left_vol ;
348+ else
349+ val += left_step ;
350+
343351 reg &= ~TWL6040_HSL_VOL_MASK ;
344352 twl6040_write (codec , TWL6040_REG_HSGAIN ,
345353 (reg | (~val & TWL6040_HSL_VOL_MASK )));
@@ -349,7 +357,11 @@ static inline int twl6040_hs_ramp_step(struct snd_soc_codec *codec,
349357 } else if (headset -> ramp == TWL6040_RAMP_DOWN ) {
350358 /* ramp step down */
351359 if (val > 0x0 ) {
352- val -= left_step ;
360+ if ((int )val - (int )left_step < 0 )
361+ val = 0 ;
362+ else
363+ val -= left_step ;
364+
353365 reg &= ~TWL6040_HSL_VOL_MASK ;
354366 twl6040_write (codec , TWL6040_REG_HSGAIN , reg |
355367 (~val & TWL6040_HSL_VOL_MASK ));
@@ -366,7 +378,11 @@ static inline int twl6040_hs_ramp_step(struct snd_soc_codec *codec,
366378 if (headset -> ramp == TWL6040_RAMP_UP ) {
367379 /* ramp step up */
368380 if (val < headset -> right_vol ) {
369- val += right_step ;
381+ if (val + right_step > headset -> right_vol )
382+ val = headset -> right_vol ;
383+ else
384+ val += right_step ;
385+
370386 reg &= ~TWL6040_HSR_VOL_MASK ;
371387 twl6040_write (codec , TWL6040_REG_HSGAIN ,
372388 (reg | (~val << TWL6040_HSR_VOL_SHIFT )));
@@ -376,7 +392,11 @@ static inline int twl6040_hs_ramp_step(struct snd_soc_codec *codec,
376392 } else if (headset -> ramp == TWL6040_RAMP_DOWN ) {
377393 /* ramp step down */
378394 if (val > 0x0 ) {
379- val -= right_step ;
395+ if ((int )val - (int )right_step < 0 )
396+ val = 0 ;
397+ else
398+ val -= right_step ;
399+
380400 reg &= ~TWL6040_HSR_VOL_MASK ;
381401 twl6040_write (codec , TWL6040_REG_HSGAIN ,
382402 reg | (~val << TWL6040_HSR_VOL_SHIFT ));
@@ -407,7 +427,11 @@ static inline int twl6040_hf_ramp_step(struct snd_soc_codec *codec,
407427 if (handsfree -> ramp == TWL6040_RAMP_UP ) {
408428 /* ramp step up */
409429 if (val < handsfree -> left_vol ) {
410- val += left_step ;
430+ if (val + left_step > handsfree -> left_vol )
431+ val = handsfree -> left_vol ;
432+ else
433+ val += left_step ;
434+
411435 reg &= ~TWL6040_HF_VOL_MASK ;
412436 twl6040_write (codec , TWL6040_REG_HFLGAIN ,
413437 reg | (0x1D - val ));
@@ -417,7 +441,11 @@ static inline int twl6040_hf_ramp_step(struct snd_soc_codec *codec,
417441 } else if (handsfree -> ramp == TWL6040_RAMP_DOWN ) {
418442 /* ramp step down */
419443 if (val > 0 ) {
420- val -= left_step ;
444+ if ((int )val - (int )left_step < 0 )
445+ val = 0 ;
446+ else
447+ val -= left_step ;
448+
421449 reg &= ~TWL6040_HF_VOL_MASK ;
422450 twl6040_write (codec , TWL6040_REG_HFLGAIN ,
423451 reg | (0x1D - val ));
@@ -434,7 +462,11 @@ static inline int twl6040_hf_ramp_step(struct snd_soc_codec *codec,
434462 if (handsfree -> ramp == TWL6040_RAMP_UP ) {
435463 /* ramp step up */
436464 if (val < handsfree -> right_vol ) {
437- val += right_step ;
465+ if (val + right_step > handsfree -> right_vol )
466+ val = handsfree -> right_vol ;
467+ else
468+ val += right_step ;
469+
438470 reg &= ~TWL6040_HF_VOL_MASK ;
439471 twl6040_write (codec , TWL6040_REG_HFRGAIN ,
440472 reg | (0x1D - val ));
@@ -444,7 +476,11 @@ static inline int twl6040_hf_ramp_step(struct snd_soc_codec *codec,
444476 } else if (handsfree -> ramp == TWL6040_RAMP_DOWN ) {
445477 /* ramp step down */
446478 if (val > 0 ) {
447- val -= right_step ;
479+ if ((int )val - (int )right_step < 0 )
480+ val = 0 ;
481+ else
482+ val -= right_step ;
483+
448484 reg &= ~TWL6040_HF_VOL_MASK ;
449485 twl6040_write (codec , TWL6040_REG_HFRGAIN ,
450486 reg | (0x1D - val ));
@@ -473,11 +509,9 @@ static void twl6040_pga_hs_work(struct work_struct *work)
473509
474510 /* HS PGA volumes have 4 bits of resolution to ramp */
475511 for (i = 0 ; i <= 16 ; i ++ ) {
476- headset_complete = 1 ;
477- if (headset -> ramp != TWL6040_RAMP_NONE )
478- headset_complete = twl6040_hs_ramp_step (codec ,
479- headset -> left_step ,
480- headset -> right_step );
512+ headset_complete = twl6040_hs_ramp_step (codec ,
513+ headset -> left_step ,
514+ headset -> right_step );
481515
482516 /* ramp finished ? */
483517 if (headset_complete )
@@ -518,11 +552,9 @@ static void twl6040_pga_hf_work(struct work_struct *work)
518552
519553 /* HF PGA volumes have 5 bits of resolution to ramp */
520554 for (i = 0 ; i <= 32 ; i ++ ) {
521- handsfree_complete = 1 ;
522- if (handsfree -> ramp != TWL6040_RAMP_NONE )
523- handsfree_complete = twl6040_hf_ramp_step (codec ,
524- handsfree -> left_step ,
525- handsfree -> right_step );
555+ handsfree_complete = twl6040_hf_ramp_step (codec ,
556+ handsfree -> left_step ,
557+ handsfree -> right_step );
526558
527559 /* ramp finished ? */
528560 if (handsfree_complete )
@@ -563,12 +595,16 @@ static int pga_event(struct snd_soc_dapm_widget *w,
563595 out = & priv -> headset ;
564596 work = & priv -> hs_delayed_work ;
565597 queue = priv -> hs_workqueue ;
598+ out -> left_step = priv -> hs_left_step ;
599+ out -> right_step = priv -> hs_right_step ;
566600 out -> step_delay = 5 ; /* 5 ms between volume ramp steps */
567601 break ;
568602 case 4 :
569603 out = & priv -> handsfree ;
570604 work = & priv -> hf_delayed_work ;
571605 queue = priv -> hf_workqueue ;
606+ out -> left_step = priv -> hf_left_step ;
607+ out -> right_step = priv -> hf_right_step ;
572608 out -> step_delay = 5 ; /* 5 ms between volume ramp steps */
573609 if (SND_SOC_DAPM_EVENT_ON (event ))
574610 priv -> non_lp ++ ;
@@ -601,8 +637,6 @@ static int pga_event(struct snd_soc_dapm_widget *w,
601637
602638 if (!delayed_work_pending (work )) {
603639 /* use volume ramp for power-down */
604- out -> left_step = 1 ;
605- out -> right_step = 1 ;
606640 out -> ramp = TWL6040_RAMP_DOWN ;
607641 INIT_COMPLETION (out -> ramp_done );
608642
@@ -1492,6 +1526,7 @@ static int twl6040_resume(struct snd_soc_codec *codec)
14921526static int twl6040_probe (struct snd_soc_codec * codec )
14931527{
14941528 struct twl6040_data * priv ;
1529+ struct twl4030_codec_data * pdata = dev_get_platdata (codec -> dev );
14951530 int ret = 0 ;
14961531
14971532 priv = kzalloc (sizeof (struct twl6040_data ), GFP_KERNEL );
@@ -1502,6 +1537,22 @@ static int twl6040_probe(struct snd_soc_codec *codec)
15021537 priv -> codec = codec ;
15031538 codec -> control_data = dev_get_drvdata (codec -> dev -> parent );
15041539
1540+ if (pdata && pdata -> hs_left_step && pdata -> hs_right_step ) {
1541+ priv -> hs_left_step = pdata -> hs_left_step ;
1542+ priv -> hs_right_step = pdata -> hs_right_step ;
1543+ } else {
1544+ priv -> hs_left_step = 1 ;
1545+ priv -> hs_right_step = 1 ;
1546+ }
1547+
1548+ if (pdata && pdata -> hf_left_step && pdata -> hf_right_step ) {
1549+ priv -> hf_left_step = pdata -> hf_left_step ;
1550+ priv -> hf_right_step = pdata -> hf_right_step ;
1551+ } else {
1552+ priv -> hf_left_step = 1 ;
1553+ priv -> hf_right_step = 1 ;
1554+ }
1555+
15051556 priv -> sysclk_constraints = & hp_constraints ;
15061557 priv -> workqueue = create_singlethread_workqueue ("twl6040-codec" );
15071558 if (!priv -> workqueue ) {
0 commit comments