/*-
* Copyright (c) 2008 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
* by David Young.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/* wait for retrace */
static int
isv_retrace_wait(struct isv_regs *ir, int *state, const struct timeval *end)
{
struct timeval now;
for (;;) {
if (!isv_delta(state, isv_retrace(ir))) {
microtime(&now);
continue;
}
if (*state == ISV_S_RETRACE)
break;
if (*state != ISV_S_CAPTURE0)
continue;
/* enter read mode, then toggle counter mode,
* autoinc -> reset -> autoinc, so that we start reading
* at the top of the frame.
*/
isv_write(ir, ISV_CONTROL,
ISV_CONTROL_MODE_READ|ISV_CONTROL_COUNTER_AUTOINC);
isv_write(ir, ISV_CONTROL,
ISV_CONTROL_MODE_READ|ISV_CONTROL_COUNTER_RESET);
isv_write(ir, ISV_CONTROL,
ISV_CONTROL_MODE_READ|ISV_CONTROL_COUNTER_AUTOINC);
/* read one dummy word to prime the state machine on the
* image capture board
*/
isv_read(ir, ISV_DATA);
bus_space_read_multi_stream_2(ir->ir_bt, ir->ir_bh, ISV_DATA,
sc->sc_frame, ISV_WIDTH * ISV_LINES / 2);
/* restore to initial conditions */
isv_write(ir, ISV_CONTROL,
ISV_CONTROL_MODE_CAPTURE|ISV_CONTROL_COUNTER_AUTOINC);
microtime(&stop);
timersub(&stop, &start, &diff);
aprint_debug_dev(sc->sc_dev, "read in %" PRId64 ".%06d seconds\n",
diff.tv_sec, diff.tv_usec);
state = 0;
if (isv_retrace_wait(ir, &state, &end) != 0)
return 0;
sc->sc_speed++;
if (isv_capture_wait(ir, &state, &end) != 0)
return 0;
sc->sc_speed++;