Motor: use default frequency when platform frequency request is predefined value, 0 97/233197/1
authorjeongsup.jeong <jeongsup.jeong@samsung.com>
Wed, 25 Mar 2020 10:30:57 +0000 (19:30 +0900)
committerChanwoo Choi <cw00.choi@samsung.com>
Thu, 7 May 2020 06:18:24 +0000 (15:18 +0900)
Change the default value of frequency from 1 to 0 as following:
- 0 (Use default frequency)
- 1 ~ 8191 (0.1 ~ 819.1 Hz)

And check whether intensity_level is valid or in the early ztm620_motor_run()
function. The intensity_level should be less than count_strength and
count_frequency. The number of count_strength and count_frequency are fixed
according to the h/w device. Each h/w device specifies the number of
count_strength and count_frequency in their own devicetree.

Change-Id: Ie3fd07fbbbf41f72726149864cc0dbe2ac9c71d3
Signed-off-by: jeongsup.jeong <jeongsup.jeong@samsung.com>
[cw00.choi: Add commig-msg as the public style]
Signed-off-by: Chanwoo Choi <cw00.choi@samsung.com>
drivers/motor/ztm620_motor.c
include/linux/ztm620_motor.h

index 7f069b4..098d618 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) {
@@ -245,10 +242,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:
@@ -611,7 +611,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;
@@ -769,7 +768,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 3e2e007..44522cc 100644 (file)
@@ -128,7 +128,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;
@@ -161,7 +161,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;