Lines Matching full:chip

56 static int max8997_haptic_set_duty_cycle(struct max8997_haptic *chip)  in max8997_haptic_set_duty_cycle()  argument
60 if (chip->mode == MAX8997_EXTERNAL_MODE) { in max8997_haptic_set_duty_cycle()
61 unsigned int duty = chip->pwm_period * chip->level / 100; in max8997_haptic_set_duty_cycle()
62 ret = pwm_config(chip->pwm, duty, chip->pwm_period); in max8997_haptic_set_duty_cycle()
68 if (chip->level <= i * 100 / 64) { in max8997_haptic_set_duty_cycle()
73 switch (chip->internal_mode_pattern) { in max8997_haptic_set_duty_cycle()
75 max8997_write_reg(chip->client, in max8997_haptic_set_duty_cycle()
79 max8997_write_reg(chip->client, in max8997_haptic_set_duty_cycle()
83 max8997_write_reg(chip->client, in max8997_haptic_set_duty_cycle()
87 max8997_write_reg(chip->client, in max8997_haptic_set_duty_cycle()
97 static void max8997_haptic_configure(struct max8997_haptic *chip) in max8997_haptic_configure() argument
101 value = chip->type << MAX8997_MOTOR_TYPE_SHIFT | in max8997_haptic_configure()
102 chip->enabled << MAX8997_ENABLE_SHIFT | in max8997_haptic_configure()
103 chip->mode << MAX8997_MODE_SHIFT | chip->pwm_divisor; in max8997_haptic_configure()
104 max8997_write_reg(chip->client, MAX8997_HAPTIC_REG_CONF2, value); in max8997_haptic_configure()
106 if (chip->mode == MAX8997_INTERNAL_MODE && chip->enabled) { in max8997_haptic_configure()
107 value = chip->internal_mode_pattern << MAX8997_CYCLE_SHIFT | in max8997_haptic_configure()
108 chip->internal_mode_pattern << MAX8997_SIG_PERIOD_SHIFT | in max8997_haptic_configure()
109 chip->internal_mode_pattern << MAX8997_SIG_DUTY_SHIFT | in max8997_haptic_configure()
110 chip->internal_mode_pattern << MAX8997_PWM_DUTY_SHIFT; in max8997_haptic_configure()
111 max8997_write_reg(chip->client, in max8997_haptic_configure()
114 switch (chip->internal_mode_pattern) { in max8997_haptic_configure()
116 value = chip->pattern_cycle << 4; in max8997_haptic_configure()
117 max8997_write_reg(chip->client, in max8997_haptic_configure()
119 value = chip->pattern_signal_period; in max8997_haptic_configure()
120 max8997_write_reg(chip->client, in max8997_haptic_configure()
125 value = chip->pattern_cycle; in max8997_haptic_configure()
126 max8997_write_reg(chip->client, in max8997_haptic_configure()
128 value = chip->pattern_signal_period; in max8997_haptic_configure()
129 max8997_write_reg(chip->client, in max8997_haptic_configure()
134 value = chip->pattern_cycle << 4; in max8997_haptic_configure()
135 max8997_write_reg(chip->client, in max8997_haptic_configure()
137 value = chip->pattern_signal_period; in max8997_haptic_configure()
138 max8997_write_reg(chip->client, in max8997_haptic_configure()
143 value = chip->pattern_cycle; in max8997_haptic_configure()
144 max8997_write_reg(chip->client, in max8997_haptic_configure()
146 value = chip->pattern_signal_period; in max8997_haptic_configure()
147 max8997_write_reg(chip->client, in max8997_haptic_configure()
157 static void max8997_haptic_enable(struct max8997_haptic *chip) in max8997_haptic_enable() argument
161 mutex_lock(&chip->mutex); in max8997_haptic_enable()
163 error = max8997_haptic_set_duty_cycle(chip); in max8997_haptic_enable()
165 dev_err(chip->dev, "set_pwm_cycle failed, error: %d\n", error); in max8997_haptic_enable()
169 if (!chip->enabled) { in max8997_haptic_enable()
170 error = regulator_enable(chip->regulator); in max8997_haptic_enable()
172 dev_err(chip->dev, "Failed to enable regulator\n"); in max8997_haptic_enable()
175 max8997_haptic_configure(chip); in max8997_haptic_enable()
176 if (chip->mode == MAX8997_EXTERNAL_MODE) { in max8997_haptic_enable()
177 error = pwm_enable(chip->pwm); in max8997_haptic_enable()
179 dev_err(chip->dev, "Failed to enable PWM\n"); in max8997_haptic_enable()
180 regulator_disable(chip->regulator); in max8997_haptic_enable()
184 chip->enabled = true; in max8997_haptic_enable()
188 mutex_unlock(&chip->mutex); in max8997_haptic_enable()
191 static void max8997_haptic_disable(struct max8997_haptic *chip) in max8997_haptic_disable() argument
193 mutex_lock(&chip->mutex); in max8997_haptic_disable()
195 if (chip->enabled) { in max8997_haptic_disable()
196 chip->enabled = false; in max8997_haptic_disable()
197 max8997_haptic_configure(chip); in max8997_haptic_disable()
198 if (chip->mode == MAX8997_EXTERNAL_MODE) in max8997_haptic_disable()
199 pwm_disable(chip->pwm); in max8997_haptic_disable()
200 regulator_disable(chip->regulator); in max8997_haptic_disable()
203 mutex_unlock(&chip->mutex); in max8997_haptic_disable()
208 struct max8997_haptic *chip = in max8997_haptic_play_effect_work() local
211 if (chip->level) in max8997_haptic_play_effect_work()
212 max8997_haptic_enable(chip); in max8997_haptic_play_effect_work()
214 max8997_haptic_disable(chip); in max8997_haptic_play_effect_work()
220 struct max8997_haptic *chip = input_get_drvdata(dev); in max8997_haptic_play_effect() local
222 chip->level = effect->u.rumble.strong_magnitude; in max8997_haptic_play_effect()
223 if (!chip->level) in max8997_haptic_play_effect()
224 chip->level = effect->u.rumble.weak_magnitude; in max8997_haptic_play_effect()
226 schedule_work(&chip->work); in max8997_haptic_play_effect()
233 struct max8997_haptic *chip = input_get_drvdata(dev); in max8997_haptic_close() local
235 cancel_work_sync(&chip->work); in max8997_haptic_close()
236 max8997_haptic_disable(chip); in max8997_haptic_close()
245 struct max8997_haptic *chip; in max8997_haptic_probe() local
257 chip = kzalloc(sizeof(struct max8997_haptic), GFP_KERNEL); in max8997_haptic_probe()
259 if (!chip || !input_dev) { in max8997_haptic_probe()
265 INIT_WORK(&chip->work, max8997_haptic_play_effect_work); in max8997_haptic_probe()
266 mutex_init(&chip->mutex); in max8997_haptic_probe()
268 chip->client = iodev->haptic; in max8997_haptic_probe()
269 chip->dev = &pdev->dev; in max8997_haptic_probe()
270 chip->input_dev = input_dev; in max8997_haptic_probe()
271 chip->pwm_period = haptic_pdata->pwm_period; in max8997_haptic_probe()
272 chip->type = haptic_pdata->type; in max8997_haptic_probe()
273 chip->mode = haptic_pdata->mode; in max8997_haptic_probe()
274 chip->pwm_divisor = haptic_pdata->pwm_divisor; in max8997_haptic_probe()
276 switch (chip->mode) { in max8997_haptic_probe()
278 chip->internal_mode_pattern = in max8997_haptic_probe()
280 chip->pattern_cycle = haptic_pdata->pattern_cycle; in max8997_haptic_probe()
281 chip->pattern_signal_period = in max8997_haptic_probe()
286 chip->pwm = pwm_request(haptic_pdata->pwm_channel_id, in max8997_haptic_probe()
288 if (IS_ERR(chip->pwm)) { in max8997_haptic_probe()
289 error = PTR_ERR(chip->pwm); in max8997_haptic_probe()
300 pwm_apply_args(chip->pwm); in max8997_haptic_probe()
305 "Invalid chip mode specified (%d)\n", chip->mode); in max8997_haptic_probe()
310 chip->regulator = regulator_get(&pdev->dev, "inmotor"); in max8997_haptic_probe()
311 if (IS_ERR(chip->regulator)) { in max8997_haptic_probe()
312 error = PTR_ERR(chip->regulator); in max8997_haptic_probe()
323 input_set_drvdata(input_dev, chip); in max8997_haptic_probe()
343 platform_set_drvdata(pdev, chip); in max8997_haptic_probe()
349 regulator_put(chip->regulator); in max8997_haptic_probe()
351 if (chip->mode == MAX8997_EXTERNAL_MODE) in max8997_haptic_probe()
352 pwm_free(chip->pwm); in max8997_haptic_probe()
355 kfree(chip); in max8997_haptic_probe()
362 struct max8997_haptic *chip = platform_get_drvdata(pdev); in max8997_haptic_remove() local
364 input_unregister_device(chip->input_dev); in max8997_haptic_remove()
365 regulator_put(chip->regulator); in max8997_haptic_remove()
367 if (chip->mode == MAX8997_EXTERNAL_MODE) in max8997_haptic_remove()
368 pwm_free(chip->pwm); in max8997_haptic_remove()
370 kfree(chip); in max8997_haptic_remove()
378 struct max8997_haptic *chip = platform_get_drvdata(pdev); in max8997_haptic_suspend() local
380 max8997_haptic_disable(chip); in max8997_haptic_suspend()