1 // SPDX-License-Identifier: GPL-2.0-only
2 /* DVB USB compliant Linux driver for the
3 * - TwinhanDTV Alpha/MagicBoxII USB2.0 DVB-T receiver
4 * - DigitalNow TinyUSB2 DVB-t receiver
6 * Copyright (C) 2004-5 Patrick Boettcher (patrick.boettcher@posteo.de)
8 * Thanks to Twinhan who kindly provided hardware and information.
10 * see Documentation/driver-api/media/drivers/dvb-usb.rst for more information
15 static int dvb_usb_vp7045_debug
;
16 module_param_named(debug
,dvb_usb_vp7045_debug
, int, 0644);
17 MODULE_PARM_DESC(debug
, "set debugging level (1=info,xfer=2,rc=4 (or-able))." DVB_USB_DEBUG_STATUS
);
19 DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr
);
21 #define deb_info(args...) dprintk(dvb_usb_vp7045_debug,0x01,args)
22 #define deb_xfer(args...) dprintk(dvb_usb_vp7045_debug,0x02,args)
23 #define deb_rc(args...) dprintk(dvb_usb_vp7045_debug,0x04,args)
25 int vp7045_usb_op(struct dvb_usb_device
*d
, u8 cmd
, u8
*out
, int outlen
, u8
*in
, int inlen
, int msec
)
38 ret
= mutex_lock_interruptible(&d
->usb_mutex
);
42 if (out
!= NULL
&& outlen
> 0)
43 memcpy(&buf
[1], out
, outlen
);
45 deb_xfer("out buffer: ");
46 debug_dump(buf
, outlen
+1, deb_xfer
);
49 if (usb_control_msg(d
->udev
,
50 usb_sndctrlpipe(d
->udev
,0),
51 TH_COMMAND_OUT
, USB_TYPE_VENDOR
| USB_DIR_OUT
, 0, 0,
52 buf
, 20, 2000) != 20) {
53 err("USB control message 'out' went wrong.");
60 if (usb_control_msg(d
->udev
,
61 usb_rcvctrlpipe(d
->udev
,0),
62 TH_COMMAND_IN
, USB_TYPE_VENDOR
| USB_DIR_IN
, 0, 0,
63 buf
, 12, 2000) != 12) {
64 err("USB control message 'in' went wrong.");
69 deb_xfer("in buffer: ");
70 debug_dump(buf
, 12, deb_xfer
);
72 if (in
!= NULL
&& inlen
> 0)
73 memcpy(in
, &buf
[1], inlen
);
76 mutex_unlock(&d
->usb_mutex
);
81 u8
vp7045_read_reg(struct dvb_usb_device
*d
, u8 reg
)
86 vp7045_usb_op(d
,TUNER_REG_READ
,obuf
,2,&v
,1,30);
91 static int vp7045_power_ctrl(struct dvb_usb_device
*d
, int onoff
)
94 return vp7045_usb_op(d
,SET_TUNER_POWER
,&v
,1,NULL
,0,150);
97 static int vp7045_rc_query(struct dvb_usb_device
*d
)
102 ret
= vp7045_usb_op(d
, RC_VAL_READ
, NULL
, 0, &key
, 1, 20);
106 deb_rc("remote query key: %x\n", key
);
110 * The 8 bit address isn't available, but since the remote uses
111 * address 0 we'll use that. nec repeats are ignored too, even
112 * though the remote sends them.
114 rc_keydown(d
->rc_dev
, RC_PROTO_NEC
, RC_SCANCODE_NEC(0, key
), 0);
120 static int vp7045_read_eeprom(struct dvb_usb_device
*d
,u8
*buf
, int len
, int offset
)
124 for (i
=0; i
< len
; i
++) {
126 ret
= vp7045_usb_op(d
, GET_EE_VALUE
, &v
, 1, br
, 2, 5);
132 deb_info("VP7045 EEPROM read (offs: %d, len: %d) : ", offset
, i
);
133 debug_dump(buf
, i
, deb_info
);
137 static int vp7045_read_mac_addr(struct dvb_usb_device
*d
,u8 mac
[6])
139 return vp7045_read_eeprom(d
,mac
, 6, MAC_0_ADDR
);
142 static int vp7045_frontend_attach(struct dvb_usb_adapter
*adap
)
146 vp7045_usb_op(adap
->dev
,VENDOR_STRING_READ
,NULL
,0,buf
,20,0);
148 deb_info("firmware says: %s ",buf
);
150 vp7045_usb_op(adap
->dev
,PRODUCT_STRING_READ
,NULL
,0,buf
,20,0);
154 vp7045_usb_op(adap
->dev
,FW_VERSION_READ
,NULL
,0,buf
,20,0);
156 deb_info("v%s\n",buf
);
158 /* Dump the EEPROM */
159 /* vp7045_read_eeprom(d,buf, 255, FX2_ID_ADDR); */
161 adap
->fe_adap
[0].fe
= vp7045_fe_attach(adap
->dev
);
166 static struct dvb_usb_device_properties vp7045_properties
;
168 static int vp7045_usb_probe(struct usb_interface
*intf
,
169 const struct usb_device_id
*id
)
171 return dvb_usb_device_init(intf
, &vp7045_properties
,
172 THIS_MODULE
, NULL
, adapter_nr
);
175 static struct usb_device_id vp7045_usb_table
[] = {
176 { USB_DEVICE(USB_VID_VISIONPLUS
, USB_PID_TWINHAN_VP7045_COLD
) },
177 { USB_DEVICE(USB_VID_VISIONPLUS
, USB_PID_TWINHAN_VP7045_WARM
) },
178 { USB_DEVICE(USB_VID_VISIONPLUS
, USB_PID_DNTV_TINYUSB2_COLD
) },
179 { USB_DEVICE(USB_VID_VISIONPLUS
, USB_PID_DNTV_TINYUSB2_WARM
) },
182 MODULE_DEVICE_TABLE(usb
, vp7045_usb_table
);
184 static struct dvb_usb_device_properties vp7045_properties
= {
185 .usb_ctrl
= CYPRESS_FX2
,
186 .firmware
= "dvb-usb-vp7045-01.fw",
194 .frontend_attach
= vp7045_frontend_attach
,
195 /* parameter for the MPEG2-data transfer */
209 .power_ctrl
= vp7045_power_ctrl
,
210 .read_mac_address
= vp7045_read_mac_addr
,
214 .rc_codes
= RC_MAP_TWINHAN_VP1027_DVBS
,
215 .module_name
= KBUILD_MODNAME
,
216 .rc_query
= vp7045_rc_query
,
217 .allowed_protos
= RC_PROTO_BIT_NEC
,
218 .scancode_mask
= 0xff,
221 .num_device_descs
= 2,
223 { .name
= "Twinhan USB2.0 DVB-T receiver (TwinhanDTV Alpha/MagicBox II)",
224 .cold_ids
= { &vp7045_usb_table
[0], NULL
},
225 .warm_ids
= { &vp7045_usb_table
[1], NULL
},
227 { .name
= "DigitalNow TinyUSB 2 DVB-t Receiver",
228 .cold_ids
= { &vp7045_usb_table
[2], NULL
},
229 .warm_ids
= { &vp7045_usb_table
[3], NULL
},
235 /* usb specific object needed to register this driver with the usb subsystem */
236 static struct usb_driver vp7045_usb_driver
= {
237 .name
= "dvb_usb_vp7045",
238 .probe
= vp7045_usb_probe
,
239 .disconnect
= dvb_usb_device_exit
,
240 .id_table
= vp7045_usb_table
,
243 module_usb_driver(vp7045_usb_driver
);
245 MODULE_AUTHOR("Patrick Boettcher <patrick.boettcher@posteo.de>");
246 MODULE_DESCRIPTION("Driver for Twinhan MagicBox/Alpha and DNTV tinyUSB2 DVB-T USB2.0");
247 MODULE_VERSION("1.0");
248 MODULE_LICENSE("GPL");