xref: /netbsd-src/sys/dev/usb/emdtvvar.h (revision bdc22b2e01993381dcefeff2bc9b56ca75a4235c)
1 /* $NetBSD: emdtvvar.h,v 1.4 2016/04/23 10:15:31 skrll Exp $ */
2 
3 /*-
4  * Copyright (c) 2008 Jared D. McNeill <jmcneill@invisible.ca>
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  * 1. Redistributions of source code must retain the above copyright
11  *    notice, this list of conditions and the following disclaimer.
12  * 2. Redistributions in binary form must reproduce the above copyright
13  *    notice, this list of conditions and the following disclaimer in the
14  *    documentation and/or other materials provided with the distribution.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
17  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
18  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
20  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26  * POSSIBILITY OF SUCH DAMAGE.
27  */
28 
29 #ifndef _DEV_USB_EMDTVVAR_H
30 #define _DEV_USB_EMDTVVAR_H
31 
32 #include <sys/mutex.h>
33 #include <sys/condvar.h>
34 #include <sys/workqueue.h>
35 
36 #include <dev/usb/usb.h>
37 #include <dev/usb/usbdi.h>
38 
39 #include <dev/usb/emdtv_board.h>
40 
41 #include <dev/i2c/i2cvar.h>
42 #include <dev/dtv/dtvif.h>
43 
44 #include <dev/i2c/lg3303var.h>
45 #include <dev/i2c/xc3028var.h>
46 
47 #define EMDTV_EEPROM_LEN	256
48 
49 #define EMDTV_NXFERS		6
50 #define EMDTV_NFRAMES		64
51 
52 #define EMDTV_CIR_BUFLEN	32
53 
54 struct emdtv_softc;
55 
56 struct emdtv_isoc_xfer {
57 	struct emdtv_softc	*ix_sc;
58 	struct usbd_xfer	*ix_xfer;
59 	uint8_t			*ix_buf;
60 	uint16_t		ix_frlengths[EMDTV_NFRAMES];
61 	struct emdtv_isoc_xfer	*ix_altix;
62 };
63 
64 struct emdtv_softc {
65 	device_t		sc_dev;
66 	struct usbd_device	*sc_udev;
67 
68 	device_t		sc_cirdev;
69 	device_t		sc_dtvdev;
70 
71 	uint16_t		sc_vendor, sc_product;
72 
73 	const struct emdtv_board *sc_board;
74 
75 	struct lg3303		*sc_lg3303;
76 	struct xc3028		*sc_xc3028;
77 
78 	struct i2c_controller	sc_i2c;
79 	kmutex_t		sc_i2c_lock;
80 
81 	uint8_t			sc_eeprom[EMDTV_EEPROM_LEN];
82 
83 	struct usbd_interface	*sc_iface;
84 
85 	struct usbd_pipe	*sc_isoc_pipe;
86 	int			sc_isoc_buflen;
87 	int			sc_isoc_maxpacketsize;
88 	struct emdtv_isoc_xfer	sc_ix[EMDTV_NXFERS];
89 
90 	struct usbd_pipe	*sc_intr_pipe;
91 	uint8_t			sc_intr_buf;
92 	struct workqueue	*sc_ir_wq;
93 	struct work		sc_ir_work;
94 	uint8_t			sc_ir_keyid;
95 
96 	kmutex_t		sc_ir_mutex;
97 	uint8_t			sc_ir_queue[EMDTV_CIR_BUFLEN][3];
98 	int			sc_ir_cnt;
99 	int			sc_ir_ptr;
100 	bool			sc_ir_open;
101 
102 	uint32_t		sc_frequency;
103 
104 	bool			sc_streaming;
105 	void			(*sc_dtvsubmitcb)(void *,
106 				    const struct dtv_payload *);
107 	void			*sc_dtvsubmitarg;
108 
109 	bool			sc_dying;
110 };
111 
112 void	emdtv_dtv_attach(struct emdtv_softc *);
113 void	emdtv_dtv_detach(struct emdtv_softc *, int);
114 void	emdtv_dtv_rescan(struct emdtv_softc *, const char *, const int *);
115 void	emdtv_ir_attach(struct emdtv_softc *);
116 void	emdtv_ir_detach(struct emdtv_softc *, int);
117 int	emdtv_i2c_attach(struct emdtv_softc *);
118 int	emdtv_i2c_detach(struct emdtv_softc *, int);
119 
120 uint8_t	emdtv_read_1(struct emdtv_softc *, uint8_t, uint16_t);
121 void	emdtv_read_multi_1(struct emdtv_softc *, uint8_t, uint16_t,
122 			   uint8_t *, uint16_t);
123 void	emdtv_write_1(struct emdtv_softc *, uint8_t, uint16_t, uint8_t);
124 void	emdtv_write_multi_1(struct emdtv_softc *, uint8_t, uint16_t,
125 			    const uint8_t *, uint16_t);
126 
127 bool	emdtv_gpio_ctl(struct emdtv_softc *, emdtv_gpio_reg_t, bool);
128 
129 #endif /* !_DEV_USB_EMDTVVAR_H */
130