1 /* $NetBSD: emdtvvar.h,v 1.5 2022/06/26 22:49:09 riastradh 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 bool sc_subdevs_attached; 74 75 const struct emdtv_board *sc_board; 76 77 struct lg3303 *sc_lg3303; 78 struct xc3028 *sc_xc3028; 79 80 struct i2c_controller sc_i2c; 81 kmutex_t sc_i2c_lock; 82 83 uint8_t sc_eeprom[EMDTV_EEPROM_LEN]; 84 85 struct usbd_interface *sc_iface; 86 87 struct usbd_pipe *sc_isoc_pipe; 88 int sc_isoc_buflen; 89 int sc_isoc_maxpacketsize; 90 struct emdtv_isoc_xfer sc_ix[EMDTV_NXFERS]; 91 92 struct usbd_pipe *sc_intr_pipe; 93 uint8_t sc_intr_buf; 94 struct workqueue *sc_ir_wq; 95 struct work sc_ir_work; 96 uint8_t sc_ir_keyid; 97 98 kmutex_t sc_ir_mutex; 99 uint8_t sc_ir_queue[EMDTV_CIR_BUFLEN][3]; 100 int sc_ir_cnt; 101 int sc_ir_ptr; 102 bool sc_ir_open; 103 104 uint32_t sc_frequency; 105 106 bool sc_streaming; 107 void (*sc_dtvsubmitcb)(void *, 108 const struct dtv_payload *); 109 void *sc_dtvsubmitarg; 110 111 bool sc_dying; 112 }; 113 114 void emdtv_dtv_attach(struct emdtv_softc *); 115 void emdtv_dtv_detach(struct emdtv_softc *, int); 116 void emdtv_dtv_rescan(struct emdtv_softc *, const char *, const int *); 117 void emdtv_ir_attach(struct emdtv_softc *); 118 void emdtv_ir_detach(struct emdtv_softc *, int); 119 int emdtv_i2c_attach(struct emdtv_softc *); 120 int emdtv_i2c_detach(struct emdtv_softc *, int); 121 122 uint8_t emdtv_read_1(struct emdtv_softc *, uint8_t, uint16_t); 123 void emdtv_read_multi_1(struct emdtv_softc *, uint8_t, uint16_t, 124 uint8_t *, uint16_t); 125 void emdtv_write_1(struct emdtv_softc *, uint8_t, uint16_t, uint8_t); 126 void emdtv_write_multi_1(struct emdtv_softc *, uint8_t, uint16_t, 127 const uint8_t *, uint16_t); 128 129 bool emdtv_gpio_ctl(struct emdtv_softc *, emdtv_gpio_reg_t, bool); 130 131 #endif /* !_DEV_USB_EMDTVVAR_H */ 132