162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-only */
262306a36Sopenharmony_ci/*
362306a36Sopenharmony_ci *
462306a36Sopenharmony_ci *  Copyright (C) 2005 Mike Isely <isely@pobox.com>
562306a36Sopenharmony_ci */
662306a36Sopenharmony_ci#ifndef __PVRUSB2_IO_H
762306a36Sopenharmony_ci#define __PVRUSB2_IO_H
862306a36Sopenharmony_ci
962306a36Sopenharmony_ci#include <linux/usb.h>
1062306a36Sopenharmony_ci#include <linux/list.h>
1162306a36Sopenharmony_ci
1262306a36Sopenharmony_citypedef void (*pvr2_stream_callback)(void *);
1362306a36Sopenharmony_ci
1462306a36Sopenharmony_cienum pvr2_buffer_state {
1562306a36Sopenharmony_ci	pvr2_buffer_state_none = 0,   // Not on any list
1662306a36Sopenharmony_ci	pvr2_buffer_state_idle = 1,   // Buffer is ready to be used again
1762306a36Sopenharmony_ci	pvr2_buffer_state_queued = 2, // Buffer has been queued for filling
1862306a36Sopenharmony_ci	pvr2_buffer_state_ready = 3,  // Buffer has data available
1962306a36Sopenharmony_ci};
2062306a36Sopenharmony_ci
2162306a36Sopenharmony_cistruct pvr2_stream;
2262306a36Sopenharmony_cistruct pvr2_buffer;
2362306a36Sopenharmony_ci
2462306a36Sopenharmony_cistruct pvr2_stream_stats {
2562306a36Sopenharmony_ci	unsigned int buffers_in_queue;
2662306a36Sopenharmony_ci	unsigned int buffers_in_idle;
2762306a36Sopenharmony_ci	unsigned int buffers_in_ready;
2862306a36Sopenharmony_ci	unsigned int buffers_processed;
2962306a36Sopenharmony_ci	unsigned int buffers_failed;
3062306a36Sopenharmony_ci	unsigned int bytes_processed;
3162306a36Sopenharmony_ci};
3262306a36Sopenharmony_ci
3362306a36Sopenharmony_ci/* Initialize / tear down stream structure */
3462306a36Sopenharmony_cistruct pvr2_stream *pvr2_stream_create(void);
3562306a36Sopenharmony_civoid pvr2_stream_destroy(struct pvr2_stream *);
3662306a36Sopenharmony_civoid pvr2_stream_setup(struct pvr2_stream *,
3762306a36Sopenharmony_ci		       struct usb_device *dev,int endpoint,
3862306a36Sopenharmony_ci		       unsigned int tolerance);
3962306a36Sopenharmony_civoid pvr2_stream_set_callback(struct pvr2_stream *,
4062306a36Sopenharmony_ci			      pvr2_stream_callback func,
4162306a36Sopenharmony_ci			      void *data);
4262306a36Sopenharmony_civoid pvr2_stream_get_stats(struct pvr2_stream *,
4362306a36Sopenharmony_ci			   struct pvr2_stream_stats *,
4462306a36Sopenharmony_ci			   int zero_counts);
4562306a36Sopenharmony_ci
4662306a36Sopenharmony_ci/* Query / set the nominal buffer count */
4762306a36Sopenharmony_ciint pvr2_stream_get_buffer_count(struct pvr2_stream *);
4862306a36Sopenharmony_ciint pvr2_stream_set_buffer_count(struct pvr2_stream *,unsigned int);
4962306a36Sopenharmony_ci
5062306a36Sopenharmony_ci/* Get a pointer to a buffer that is either idle, ready, or is specified
5162306a36Sopenharmony_ci   named. */
5262306a36Sopenharmony_cistruct pvr2_buffer *pvr2_stream_get_idle_buffer(struct pvr2_stream *);
5362306a36Sopenharmony_cistruct pvr2_buffer *pvr2_stream_get_ready_buffer(struct pvr2_stream *);
5462306a36Sopenharmony_cistruct pvr2_buffer *pvr2_stream_get_buffer(struct pvr2_stream *sp,int id);
5562306a36Sopenharmony_ci
5662306a36Sopenharmony_ci/* Find out how many buffers are idle or ready */
5762306a36Sopenharmony_ciint pvr2_stream_get_ready_count(struct pvr2_stream *);
5862306a36Sopenharmony_ci
5962306a36Sopenharmony_ci
6062306a36Sopenharmony_ci/* Kill all pending buffers and throw away any ready buffers as well */
6162306a36Sopenharmony_civoid pvr2_stream_kill(struct pvr2_stream *);
6262306a36Sopenharmony_ci
6362306a36Sopenharmony_ci/* Set up the actual storage for a buffer */
6462306a36Sopenharmony_ciint pvr2_buffer_set_buffer(struct pvr2_buffer *,void *ptr,unsigned int cnt);
6562306a36Sopenharmony_ci
6662306a36Sopenharmony_ci/* Find out size of data in the given ready buffer */
6762306a36Sopenharmony_ciunsigned int pvr2_buffer_get_count(struct pvr2_buffer *);
6862306a36Sopenharmony_ci
6962306a36Sopenharmony_ci/* Retrieve completion code for given ready buffer */
7062306a36Sopenharmony_ciint pvr2_buffer_get_status(struct pvr2_buffer *);
7162306a36Sopenharmony_ci
7262306a36Sopenharmony_ci/* Retrieve ID of given buffer */
7362306a36Sopenharmony_ciint pvr2_buffer_get_id(struct pvr2_buffer *);
7462306a36Sopenharmony_ci
7562306a36Sopenharmony_ci/* Start reading into given buffer (kill it if needed) */
7662306a36Sopenharmony_ciint pvr2_buffer_queue(struct pvr2_buffer *);
7762306a36Sopenharmony_ci
7862306a36Sopenharmony_ci#endif /* __PVRUSB2_IO_H */
79