Motor: use default frequency when platform frequency request is predefined value, 0
authorjeongsup.jeong <jeongsup.jeong@samsung.com>
Fri, 24 Apr 2020 08:34:07 +0000 (17:34 +0900)
committerChanwoo Choi <cw00.choi@samsung.com>
Fri, 24 Apr 2020 08:34:07 +0000 (17:34 +0900)
TODO

Signed-off-by: jeongsup.jeong <jeongsup.jeong@samsung.com>
[cw00.choi: Cherry-pick commit c36cad40a5a2 ("Motor: use default frequency
when platform frequency request is predefined value, 0") and add commit-msg]
Signed-off-by: Chanwoo Choi <cw00.choi@samsung.com>
drivers/motor/ztm620_motor.c
include/linux/ztm620_motor.h

index 263a87726426575113a8c6ad79ca7b1ed8da4fb6..2d9c6e27c8ddaa70a2a3c4f6d607973f83097c34 100644 (file)
@@ -119,10 +119,14 @@ static int ztm620_motor_run(void) {
        /* intensity level cannot be 0 and also cannot exceed
           the number of strength values defined in dts */
        if (pMotorData->intensity_level == 0
-                       || pMotorData->intensity_level > pMotorPdata->count_strength) {
-               pr_err("[VIB] %s level error: level %d, str_cnt %d",
+                       || pMotorData->intensity_level
+                               > pMotorPdata->count_strength
+                       || pMotorData->intensity_level
+                               > pMotorPdata->count_frequency) {
+               pr_err("[VIB] %s level error: level %d, str_cnt %d, freq_cnt %d",
                                __func__, pMotorData->intensity_level,
-                               pMotorPdata->count_strength);
+                               pMotorPdata->count_strength,
+                               pMotorPdata->count_frequency);
                goto out;
        }
 
@@ -131,19 +135,12 @@ static int ztm620_motor_run(void) {
        strength = pMotorPdata->strength[pMotorData->intensity_level - 1]
                        * pMotorData->intensity_value / 10000;
 
-       if (pMotorPdata->count_frequency >= pMotorData->intensity_level)
-               /* use frequency value in dt if the requested level is mapped */
-               freq_hz = pMotorPdata->frequency[pMotorData->intensity_level - 1];
-       else if (pMotorData->frequency)
-               /* use frequency value given from platform if exists */
+       /* frequency data from platform is used unless it's 0
+          which means to use frequency defined in device tree for each model */
+       if (pMotorData->frequency)
                freq_hz = pMotorData->frequency;
-       else {
-               pr_err("[VIB] %s frequency error: freq_cnt %d, level %d, freq %d",
-                               __func__, pMotorPdata->count_frequency,
-                               pMotorData->intensity_level,
-                               pMotorData->frequency);
-               goto out;
-       }
+       else
+               freq_hz = pMotorPdata->frequency[pMotorData->intensity_level - 1];
 
        ret = ztm620_motor_reg_write(pMotorData, MOTOR_REG_SOFT_EN, SOFT_ENABLE);
        if (ret < 0) {
@@ -246,10 +243,13 @@ static int ztm620_motor_run(void) {
        }
 
        /* -1 for ovd means overdrive requested to be off by platform */
-       pr_info("[VIB] Start: level %d, value 0x%x(%d), freq 0x%x(%d.%d), ovd %d\n",
+       pr_info("[VIB] Start: level %d, value 0x%x(%d),"
+               " freq 0x%x(%d.%d/%d.%d), ovd %d\n",
                pMotorData->intensity_level,
                strength, pMotorData->intensity_value,
-               freq_reg, freq_hz / 10, freq_hz % 10,
+               freq_reg, pMotorData->frequency / 10, pMotorData->frequency % 10,
+               pMotorPdata->frequency[pMotorData->intensity_level - 1] / 10,
+               pMotorPdata->frequency[pMotorData->intensity_level - 1] % 10,
                pMotorData->overdrive?pMotorPdata->overdrive_num:-1);
 
 out:
@@ -612,7 +612,6 @@ err_free_input:
 static int of_ztm620_motor_dt(struct i2c_client* client, struct ztm620_motor_platform_data *pdata)
 {
        int err;
-       int ret = 0;
        const char *motor_type;
        const char *loop_type;
        int i;
@@ -766,7 +765,7 @@ static int of_ztm620_motor_dt(struct i2c_client* client, struct ztm620_motor_pla
 
        dev_info(&client->dev, "[VIB] %s: dt parsing done\n", __func__);
 
-       return ret;
+       return 0;
 }
 #endif /* CONFIG_OF */
 
index c60129b294cdfe044598fac33c57969b4432aa51..74de78751158b771cdb4a61e0f8fb601e990009d 100644 (file)
@@ -126,7 +126,7 @@ struct ztm620_motor_platform_data {
        const char *regulator_name;
        int adc_sampling_time;
        int soft_en_delay;
-       int *frequency; /* in 0.1 hz*/
+       int *frequency;         /* in 0.1 hz*/
        int count_frequency;
        int *strength;
        int count_strength;
@@ -157,7 +157,9 @@ struct ztm620_motor_data {
         __u16 weak_magnitude;   // weak_magnitude[15:13]
                                 //   = Intensity Level : 1 ~ 5
                                 // weak_magnitude[12:0]
-                                //   = Frequency in 0.1Hz : 0 ~ 8191 (0 ~ 819.1 Hz)
+                                //   = Frequency in 0.1Hz :
+                                //     0 (Use default frequency)
+                                //     1 ~ 8191 (0.1 ~ 819.1 Hz)
        }; */
        __u16 overdrive;
        __u16 intensity_value;