Lines Matching refs:data

58 static int sirf_serdev_open(struct sirf_data *data)  in sirf_serdev_open()  argument
62 mutex_lock(&data->serdev_mutex); in sirf_serdev_open()
63 if (++data->serdev_count == 1) { in sirf_serdev_open()
64 ret = serdev_device_open(data->serdev); in sirf_serdev_open()
66 data->serdev_count--; in sirf_serdev_open()
70 serdev_device_set_baudrate(data->serdev, data->speed); in sirf_serdev_open()
71 serdev_device_set_flow_control(data->serdev, false); in sirf_serdev_open()
75 mutex_unlock(&data->serdev_mutex); in sirf_serdev_open()
80 static void sirf_serdev_close(struct sirf_data *data) in sirf_serdev_close() argument
82 mutex_lock(&data->serdev_mutex); in sirf_serdev_close()
83 if (--data->serdev_count == 0) in sirf_serdev_close()
84 serdev_device_close(data->serdev); in sirf_serdev_close()
85 mutex_unlock(&data->serdev_mutex); in sirf_serdev_close()
90 struct sirf_data *data = gnss_get_drvdata(gdev); in sirf_open() local
91 struct serdev_device *serdev = data->serdev; in sirf_open()
94 mutex_lock(&data->gdev_mutex); in sirf_open()
95 data->open = true; in sirf_open()
96 mutex_unlock(&data->gdev_mutex); in sirf_open()
98 ret = sirf_serdev_open(data); in sirf_open()
100 mutex_lock(&data->gdev_mutex); in sirf_open()
101 data->open = false; in sirf_open()
102 mutex_unlock(&data->gdev_mutex); in sirf_open()
116 sirf_serdev_close(data); in sirf_open()
118 mutex_lock(&data->gdev_mutex); in sirf_open()
119 data->open = false; in sirf_open()
120 mutex_unlock(&data->gdev_mutex); in sirf_open()
127 struct sirf_data *data = gnss_get_drvdata(gdev); in sirf_close() local
128 struct serdev_device *serdev = data->serdev; in sirf_close()
130 sirf_serdev_close(data); in sirf_close()
134 mutex_lock(&data->gdev_mutex); in sirf_close()
135 data->open = false; in sirf_close()
136 mutex_unlock(&data->gdev_mutex); in sirf_close()
142 struct sirf_data *data = gnss_get_drvdata(gdev); in sirf_write_raw() local
143 struct serdev_device *serdev = data->serdev; in sirf_write_raw()
166 struct sirf_data *data = serdev_device_get_drvdata(serdev); in sirf_receive_buf() local
167 struct gnss_device *gdev = data->gdev; in sirf_receive_buf()
170 if (!data->wakeup && !data->active) { in sirf_receive_buf()
171 data->active = true; in sirf_receive_buf()
172 wake_up_interruptible(&data->power_wait); in sirf_receive_buf()
175 mutex_lock(&data->gdev_mutex); in sirf_receive_buf()
176 if (data->open) in sirf_receive_buf()
178 mutex_unlock(&data->gdev_mutex); in sirf_receive_buf()
190 struct sirf_data *data = dev_id; in sirf_wakeup_handler() local
191 struct device *dev = &data->serdev->dev; in sirf_wakeup_handler()
194 ret = gpiod_get_value_cansleep(data->wakeup); in sirf_wakeup_handler()
199 data->active = ret; in sirf_wakeup_handler()
200 wake_up_interruptible(&data->power_wait); in sirf_wakeup_handler()
205 static int sirf_wait_for_power_state_nowakeup(struct sirf_data *data, in sirf_wait_for_power_state_nowakeup() argument
215 data->active = false; in sirf_wait_for_power_state_nowakeup()
216 ret = wait_event_interruptible_timeout(data->power_wait, in sirf_wait_for_power_state_nowakeup()
217 data->active, msecs_to_jiffies(SIRF_REPORT_CYCLE)); in sirf_wait_for_power_state_nowakeup()
230 static int sirf_wait_for_power_state(struct sirf_data *data, bool active, in sirf_wait_for_power_state() argument
235 if (!data->wakeup) in sirf_wait_for_power_state()
236 return sirf_wait_for_power_state_nowakeup(data, active, timeout); in sirf_wait_for_power_state()
238 ret = wait_event_interruptible_timeout(data->power_wait, in sirf_wait_for_power_state()
239 data->active == active, msecs_to_jiffies(timeout)); in sirf_wait_for_power_state()
244 dev_warn(&data->serdev->dev, "timeout waiting for active state = %d\n", in sirf_wait_for_power_state()
252 static void sirf_pulse_on_off(struct sirf_data *data) in sirf_pulse_on_off() argument
254 gpiod_set_value_cansleep(data->on_off, 1); in sirf_pulse_on_off()
256 gpiod_set_value_cansleep(data->on_off, 0); in sirf_pulse_on_off()
259 static int sirf_set_active(struct sirf_data *data, bool active) in sirf_set_active() argument
270 if (!data->wakeup) { in sirf_set_active()
271 ret = sirf_serdev_open(data); in sirf_set_active()
277 sirf_pulse_on_off(data); in sirf_set_active()
278 ret = sirf_wait_for_power_state(data, active, timeout); in sirf_set_active()
281 if (!data->wakeup) in sirf_set_active()
282 sirf_serdev_close(data); in sirf_set_active()
292 struct sirf_data *data = dev_get_drvdata(dev); in sirf_runtime_suspend() local
296 if (data->on_off) in sirf_runtime_suspend()
297 ret = sirf_set_active(data, false); in sirf_runtime_suspend()
299 ret = regulator_disable(data->vcc); in sirf_runtime_suspend()
304 ret = regulator_disable(data->lna); in sirf_runtime_suspend()
311 if (data->on_off) in sirf_runtime_suspend()
312 ret2 = sirf_set_active(data, true); in sirf_runtime_suspend()
314 ret2 = regulator_enable(data->vcc); in sirf_runtime_suspend()
326 struct sirf_data *data = dev_get_drvdata(dev); in sirf_runtime_resume() local
329 ret = regulator_enable(data->lna); in sirf_runtime_resume()
333 if (data->on_off) in sirf_runtime_resume()
334 ret = sirf_set_active(data, true); in sirf_runtime_resume()
336 ret = regulator_enable(data->vcc); in sirf_runtime_resume()
344 regulator_disable(data->lna); in sirf_runtime_resume()
351 struct sirf_data *data = dev_get_drvdata(dev); in sirf_suspend() local
357 if (data->wakeup) in sirf_suspend()
358 disable_irq(data->irq); in sirf_suspend()
365 struct sirf_data *data = dev_get_drvdata(dev); in sirf_resume() local
368 if (data->wakeup) in sirf_resume()
369 enable_irq(data->irq); in sirf_resume()
384 struct sirf_data *data = serdev_device_get_drvdata(serdev); in sirf_parse_dt() local
390 data->speed = speed; in sirf_parse_dt()
399 struct sirf_data *data; in sirf_probe() local
402 data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL); in sirf_probe()
403 if (!data) in sirf_probe()
412 gnss_set_drvdata(gdev, data); in sirf_probe()
414 data->serdev = serdev; in sirf_probe()
415 data->gdev = gdev; in sirf_probe()
417 mutex_init(&data->gdev_mutex); in sirf_probe()
418 mutex_init(&data->serdev_mutex); in sirf_probe()
419 init_waitqueue_head(&data->power_wait); in sirf_probe()
421 serdev_device_set_drvdata(serdev, data); in sirf_probe()
428 data->vcc = devm_regulator_get(dev, "vcc"); in sirf_probe()
429 if (IS_ERR(data->vcc)) { in sirf_probe()
430 ret = PTR_ERR(data->vcc); in sirf_probe()
434 data->lna = devm_regulator_get(dev, "lna"); in sirf_probe()
435 if (IS_ERR(data->lna)) { in sirf_probe()
436 ret = PTR_ERR(data->lna); in sirf_probe()
440 data->on_off = devm_gpiod_get_optional(dev, "sirf,onoff", in sirf_probe()
442 if (IS_ERR(data->on_off)) { in sirf_probe()
443 ret = PTR_ERR(data->on_off); in sirf_probe()
447 if (data->on_off) { in sirf_probe()
448 data->wakeup = devm_gpiod_get_optional(dev, "sirf,wakeup", in sirf_probe()
450 if (IS_ERR(data->wakeup)) { in sirf_probe()
451 ret = PTR_ERR(data->wakeup); in sirf_probe()
455 ret = regulator_enable(data->vcc); in sirf_probe()
463 if (data->wakeup) { in sirf_probe()
464 ret = gpiod_get_value_cansleep(data->wakeup); in sirf_probe()
467 data->active = ret; in sirf_probe()
469 ret = gpiod_to_irq(data->wakeup); in sirf_probe()
472 data->irq = ret; in sirf_probe()
474 ret = request_threaded_irq(data->irq, NULL, sirf_wakeup_handler, in sirf_probe()
476 "wakeup", data); in sirf_probe()
481 if (data->on_off) { in sirf_probe()
482 if (!data->wakeup) { in sirf_probe()
483 data->active = false; in sirf_probe()
485 ret = sirf_serdev_open(data); in sirf_probe()
490 sirf_serdev_close(data); in sirf_probe()
494 if (data->active) { in sirf_probe()
495 ret = sirf_set_active(data, false); in sirf_probe()
525 if (data->wakeup) in sirf_probe()
526 free_irq(data->irq, data); in sirf_probe()
528 if (data->on_off) in sirf_probe()
529 regulator_disable(data->vcc); in sirf_probe()
531 gnss_put_device(data->gdev); in sirf_probe()
538 struct sirf_data *data = serdev_device_get_drvdata(serdev); in sirf_remove() local
540 gnss_deregister_device(data->gdev); in sirf_remove()
547 if (data->wakeup) in sirf_remove()
548 free_irq(data->irq, data); in sirf_remove()
550 if (data->on_off) in sirf_remove()
551 regulator_disable(data->vcc); in sirf_remove()
553 gnss_put_device(data->gdev); in sirf_remove()