Lines Matching refs:chip
56 static void max8997_haptic_set_internal_duty_cycle(struct max8997_haptic *chip) in max8997_haptic_set_internal_duty_cycle() argument
58 u8 duty_index = DIV_ROUND_UP(chip->level * 64, 100); in max8997_haptic_set_internal_duty_cycle()
60 switch (chip->internal_mode_pattern) { in max8997_haptic_set_internal_duty_cycle()
62 max8997_write_reg(chip->client, in max8997_haptic_set_internal_duty_cycle()
66 max8997_write_reg(chip->client, in max8997_haptic_set_internal_duty_cycle()
70 max8997_write_reg(chip->client, in max8997_haptic_set_internal_duty_cycle()
74 max8997_write_reg(chip->client, in max8997_haptic_set_internal_duty_cycle()
82 static void max8997_haptic_configure(struct max8997_haptic *chip) in max8997_haptic_configure() argument
86 value = chip->type << MAX8997_MOTOR_TYPE_SHIFT | in max8997_haptic_configure()
87 chip->enabled << MAX8997_ENABLE_SHIFT | in max8997_haptic_configure()
88 chip->mode << MAX8997_MODE_SHIFT | chip->pwm_divisor; in max8997_haptic_configure()
89 max8997_write_reg(chip->client, MAX8997_HAPTIC_REG_CONF2, value); in max8997_haptic_configure()
91 if (chip->mode == MAX8997_INTERNAL_MODE && chip->enabled) { in max8997_haptic_configure()
92 value = chip->internal_mode_pattern << MAX8997_CYCLE_SHIFT | in max8997_haptic_configure()
93 chip->internal_mode_pattern << MAX8997_SIG_PERIOD_SHIFT | in max8997_haptic_configure()
94 chip->internal_mode_pattern << MAX8997_SIG_DUTY_SHIFT | in max8997_haptic_configure()
95 chip->internal_mode_pattern << MAX8997_PWM_DUTY_SHIFT; in max8997_haptic_configure()
96 max8997_write_reg(chip->client, in max8997_haptic_configure()
99 switch (chip->internal_mode_pattern) { in max8997_haptic_configure()
101 value = chip->pattern_cycle << 4; in max8997_haptic_configure()
102 max8997_write_reg(chip->client, in max8997_haptic_configure()
104 value = chip->pattern_signal_period; in max8997_haptic_configure()
105 max8997_write_reg(chip->client, in max8997_haptic_configure()
110 value = chip->pattern_cycle; in max8997_haptic_configure()
111 max8997_write_reg(chip->client, in max8997_haptic_configure()
113 value = chip->pattern_signal_period; in max8997_haptic_configure()
114 max8997_write_reg(chip->client, in max8997_haptic_configure()
119 value = chip->pattern_cycle << 4; in max8997_haptic_configure()
120 max8997_write_reg(chip->client, in max8997_haptic_configure()
122 value = chip->pattern_signal_period; in max8997_haptic_configure()
123 max8997_write_reg(chip->client, in max8997_haptic_configure()
128 value = chip->pattern_cycle; in max8997_haptic_configure()
129 max8997_write_reg(chip->client, in max8997_haptic_configure()
131 value = chip->pattern_signal_period; in max8997_haptic_configure()
132 max8997_write_reg(chip->client, in max8997_haptic_configure()
142 static void max8997_haptic_enable(struct max8997_haptic *chip) in max8997_haptic_enable() argument
146 guard(mutex)(&chip->mutex); in max8997_haptic_enable()
148 if (chip->mode != MAX8997_EXTERNAL_MODE) in max8997_haptic_enable()
149 max8997_haptic_set_internal_duty_cycle(chip); in max8997_haptic_enable()
151 if (!chip->enabled) { in max8997_haptic_enable()
152 error = regulator_enable(chip->regulator); in max8997_haptic_enable()
154 dev_err(chip->dev, "Failed to enable regulator\n"); in max8997_haptic_enable()
157 max8997_haptic_configure(chip); in max8997_haptic_enable()
167 if (chip->mode == MAX8997_EXTERNAL_MODE) { in max8997_haptic_enable()
170 pwm_init_state(chip->pwm, &state); in max8997_haptic_enable()
171 state.period = chip->pwm_period; in max8997_haptic_enable()
172 state.duty_cycle = chip->pwm_period * chip->level / 100; in max8997_haptic_enable()
175 error = pwm_apply_might_sleep(chip->pwm, &state); in max8997_haptic_enable()
177 dev_err(chip->dev, "Failed to enable PWM\n"); in max8997_haptic_enable()
178 regulator_disable(chip->regulator); in max8997_haptic_enable()
183 chip->enabled = true; in max8997_haptic_enable()
186 static void max8997_haptic_disable(struct max8997_haptic *chip) in max8997_haptic_disable() argument
188 guard(mutex)(&chip->mutex); in max8997_haptic_disable()
190 if (chip->enabled) { in max8997_haptic_disable()
191 chip->enabled = false; in max8997_haptic_disable()
192 max8997_haptic_configure(chip); in max8997_haptic_disable()
193 if (chip->mode == MAX8997_EXTERNAL_MODE) in max8997_haptic_disable()
194 pwm_disable(chip->pwm); in max8997_haptic_disable()
195 regulator_disable(chip->regulator); in max8997_haptic_disable()
201 struct max8997_haptic *chip = in max8997_haptic_play_effect_work() local
204 if (chip->level) in max8997_haptic_play_effect_work()
205 max8997_haptic_enable(chip); in max8997_haptic_play_effect_work()
207 max8997_haptic_disable(chip); in max8997_haptic_play_effect_work()
213 struct max8997_haptic *chip = input_get_drvdata(dev); in max8997_haptic_play_effect() local
215 chip->level = effect->u.rumble.strong_magnitude; in max8997_haptic_play_effect()
216 if (!chip->level) in max8997_haptic_play_effect()
217 chip->level = effect->u.rumble.weak_magnitude; in max8997_haptic_play_effect()
219 schedule_work(&chip->work); in max8997_haptic_play_effect()
226 struct max8997_haptic *chip = input_get_drvdata(dev); in max8997_haptic_close() local
228 cancel_work_sync(&chip->work); in max8997_haptic_close()
229 max8997_haptic_disable(chip); in max8997_haptic_close()
238 struct max8997_haptic *chip; in max8997_haptic_probe() local
250 chip = kzalloc(sizeof(*chip), GFP_KERNEL); in max8997_haptic_probe()
252 if (!chip || !input_dev) { in max8997_haptic_probe()
258 INIT_WORK(&chip->work, max8997_haptic_play_effect_work); in max8997_haptic_probe()
259 mutex_init(&chip->mutex); in max8997_haptic_probe()
261 chip->client = iodev->haptic; in max8997_haptic_probe()
262 chip->dev = &pdev->dev; in max8997_haptic_probe()
263 chip->input_dev = input_dev; in max8997_haptic_probe()
264 chip->pwm_period = haptic_pdata->pwm_period; in max8997_haptic_probe()
265 chip->type = haptic_pdata->type; in max8997_haptic_probe()
266 chip->mode = haptic_pdata->mode; in max8997_haptic_probe()
267 chip->pwm_divisor = haptic_pdata->pwm_divisor; in max8997_haptic_probe()
269 switch (chip->mode) { in max8997_haptic_probe()
271 chip->internal_mode_pattern = in max8997_haptic_probe()
273 chip->pattern_cycle = haptic_pdata->pattern_cycle; in max8997_haptic_probe()
274 chip->pattern_signal_period = in max8997_haptic_probe()
279 chip->pwm = pwm_get(&pdev->dev, NULL); in max8997_haptic_probe()
280 if (IS_ERR(chip->pwm)) { in max8997_haptic_probe()
281 error = PTR_ERR(chip->pwm); in max8997_haptic_probe()
292 "Invalid chip mode specified (%d)\n", chip->mode); in max8997_haptic_probe()
297 chip->regulator = regulator_get(&pdev->dev, "inmotor"); in max8997_haptic_probe()
298 if (IS_ERR(chip->regulator)) { in max8997_haptic_probe()
299 error = PTR_ERR(chip->regulator); in max8997_haptic_probe()
310 input_set_drvdata(input_dev, chip); in max8997_haptic_probe()
330 platform_set_drvdata(pdev, chip); in max8997_haptic_probe()
336 regulator_put(chip->regulator); in max8997_haptic_probe()
338 if (chip->mode == MAX8997_EXTERNAL_MODE) in max8997_haptic_probe()
339 pwm_put(chip->pwm); in max8997_haptic_probe()
342 kfree(chip); in max8997_haptic_probe()
349 struct max8997_haptic *chip = platform_get_drvdata(pdev); in max8997_haptic_remove() local
351 input_unregister_device(chip->input_dev); in max8997_haptic_remove()
352 regulator_put(chip->regulator); in max8997_haptic_remove()
354 if (chip->mode == MAX8997_EXTERNAL_MODE) in max8997_haptic_remove()
355 pwm_put(chip->pwm); in max8997_haptic_remove()
357 kfree(chip); in max8997_haptic_remove()
363 struct max8997_haptic *chip = platform_get_drvdata(pdev); in max8997_haptic_suspend() local
365 max8997_haptic_disable(chip); in max8997_haptic_suspend()