static int rtl28xxu_init(struct dvb_usb_device *d) { int ret; u8 val; dev_dbg(&d->udev->dev, "%s:\n", __func__); /* init USB endpoints */ ret = rtl28xx_rd_reg(d, USB_SYSCTL_0, &val); if (ret) goto err; /* enable DMA and Full Packet Mode*/ val |= 0x09; ret = rtl28xx_wr_reg(d, USB_SYSCTL_0, val); if (ret) goto err; /* set EPA maximum packet size to 0x0200 */ ret = rtl28xx_wr_regs(d, USB_EPA_MAXPKT, "\x00\x02\x00\x00", 4); if (ret) goto err; /* change EPA FIFO length */ ret = rtl28xx_wr_regs(d, USB_EPA_FIFO_CFG, "\x14\x00\x00\x00", 4); if (ret) goto err; return ret; err: dev_dbg(&d->udev->dev, "%s: failed=%d\n", __func__, ret); return ret; }
static int rtl2832u_power_ctrl(struct dvb_usb_device *d, int onoff) { int ret; dev_dbg(&d->udev->dev, "%s: onoff=%d\n", __func__, onoff); if (onoff) { /* GPIO3=1, GPIO4=0 */ ret = rtl28xx_wr_reg_mask(d, SYS_GPIO_OUT_VAL, 0x08, 0x18); if (ret) goto err; /* suspend? */ ret = rtl28xx_wr_reg_mask(d, SYS_DEMOD_CTL1, 0x00, 0x10); if (ret) goto err; /* enable PLL */ ret = rtl28xx_wr_reg_mask(d, SYS_DEMOD_CTL, 0x80, 0x80); if (ret) goto err; /* disable reset */ ret = rtl28xx_wr_reg_mask(d, SYS_DEMOD_CTL, 0x20, 0x20); if (ret) goto err; /* streaming EP: clear stall & reset */ ret = rtl28xx_wr_regs(d, USB_EPA_CTL, "\x00\x00", 2); if (ret) goto err; ret = usb_clear_halt(d->udev, usb_rcvbulkpipe(d->udev, 0x81)); if (ret) goto err; } else { /* GPIO4=1 */ ret = rtl28xx_wr_reg_mask(d, SYS_GPIO_OUT_VAL, 0x10, 0x10); if (ret) goto err; /* disable PLL */ ret = rtl28xx_wr_reg_mask(d, SYS_DEMOD_CTL, 0x00, 0x80); if (ret) goto err; /* streaming EP: set stall & reset */ ret = rtl28xx_wr_regs(d, USB_EPA_CTL, "\x10\x02", 2); if (ret) goto err; } return ret; err: dev_dbg(&d->udev->dev, "%s: failed=%d\n", __func__, ret); return ret; }
static int rtl2832u_streaming_ctrl(struct dvb_usb_adapter *adap , int onoff) { int ret; u8 buf[2]; deb_info("%s: onoff=%d\n", __func__, onoff); if (onoff) { buf[0] = 0x00; buf[1] = 0x00; } else { buf[0] = 0x10; /* stall EPA */ buf[1] = 0x02; /* reset EPA */ } ret = rtl28xx_wr_regs(adap->dev, USB_EPA_CTL, buf, 2); if (ret) goto err; return ret; err: deb_info("%s: failed=%d\n", __func__, ret); return ret; }
static int rtl2831u_streaming_ctrl(struct dvb_usb_adapter *adap , int onoff) { int ret; u8 buf[2], gpio; deb_info("%s: onoff=%d\n", __func__, onoff); ret = rtl28xx_rd_reg(adap->dev, SYS_GPIO_OUT_VAL, &gpio); if (ret) goto err; if (onoff) { buf[0] = 0x00; buf[1] = 0x00; gpio |= 0x04; /* LED on */ } else { buf[0] = 0x10; /* stall EPA */ buf[1] = 0x02; /* reset EPA */ gpio &= (~0x04); /* LED off */ } ret = rtl28xx_wr_reg(adap->dev, SYS_GPIO_OUT_VAL, gpio); if (ret) goto err; ret = rtl28xx_wr_regs(adap->dev, USB_EPA_CTL, buf, 2); if (ret) goto err; return ret; err: deb_info("%s: failed=%d\n", __func__, ret); return ret; }
static int rtl2831u_power_ctrl(struct dvb_usb_device *d, int onoff) { int ret; u8 gpio, sys0, epa_ctl[2]; dev_dbg(&d->udev->dev, "%s: onoff=%d\n", __func__, onoff); /* demod adc */ ret = rtl28xx_rd_reg(d, SYS_SYS0, &sys0); if (ret) goto err; /* tuner power, read GPIOs */ ret = rtl28xx_rd_reg(d, SYS_GPIO_OUT_VAL, &gpio); if (ret) goto err; dev_dbg(&d->udev->dev, "%s: RD SYS0=%02x GPIO_OUT_VAL=%02x\n", __func__, sys0, gpio); if (onoff) { gpio |= 0x01; /* GPIO0 = 1 */ gpio &= (~0x10); /* GPIO4 = 0 */ gpio |= 0x04; /* GPIO2 = 1, LED on */ sys0 = sys0 & 0x0f; sys0 |= 0xe0; epa_ctl[0] = 0x00; /* clear stall */ epa_ctl[1] = 0x00; /* clear reset */ } else { gpio &= (~0x01); /* GPIO0 = 0 */ gpio |= 0x10; /* GPIO4 = 1 */ gpio &= (~0x04); /* GPIO2 = 1, LED off */ sys0 = sys0 & (~0xc0); epa_ctl[0] = 0x10; /* set stall */ epa_ctl[1] = 0x02; /* set reset */ } dev_dbg(&d->udev->dev, "%s: WR SYS0=%02x GPIO_OUT_VAL=%02x\n", __func__, sys0, gpio); /* demod adc */ ret = rtl28xx_wr_reg(d, SYS_SYS0, sys0); if (ret) goto err; /* tuner power, write GPIOs */ ret = rtl28xx_wr_reg(d, SYS_GPIO_OUT_VAL, gpio); if (ret) goto err; /* streaming EP: stall & reset */ ret = rtl28xx_wr_regs(d, USB_EPA_CTL, epa_ctl, 2); if (ret) goto err; if (onoff) usb_clear_halt(d->udev, usb_rcvbulkpipe(d->udev, 0x81)); return ret; err: dev_dbg(&d->udev->dev, "%s: failed=%d\n", __func__, ret); return ret; }
static int rtl28xx_wr_reg(struct dvb_usb_device *d, u16 reg, u8 val) { return rtl28xx_wr_regs(d, reg, &val, 1); }
static int rtl2832u_power_ctrl(struct dvb_usb_device *d, int onoff) { int ret; u8 val; dev_dbg(&d->udev->dev, "%s: onoff=%d\n", __func__, onoff); if (onoff) { /* set output values */ ret = rtl28xx_rd_reg(d, SYS_GPIO_OUT_VAL, &val); if (ret) goto err; val |= 0x08; val &= 0xef; ret = rtl28xx_wr_reg(d, SYS_GPIO_OUT_VAL, val); if (ret) goto err; /* demod_ctl_1 */ ret = rtl28xx_rd_reg(d, SYS_DEMOD_CTL1, &val); if (ret) goto err; val &= 0xef; ret = rtl28xx_wr_reg(d, SYS_DEMOD_CTL1, val); if (ret) goto err; /* demod control */ /* PLL enable */ ret = rtl28xx_rd_reg(d, SYS_DEMOD_CTL, &val); if (ret) goto err; /* bit 7 to 1 */ val |= 0x80; ret = rtl28xx_wr_reg(d, SYS_DEMOD_CTL, val); if (ret) goto err; ret = rtl28xx_rd_reg(d, SYS_DEMOD_CTL, &val); if (ret) goto err; val |= 0x20; ret = rtl28xx_wr_reg(d, SYS_DEMOD_CTL, val); if (ret) goto err; mdelay(5); /*enable ADC_Q and ADC_I */ ret = rtl28xx_rd_reg(d, SYS_DEMOD_CTL, &val); if (ret) goto err; val |= 0x48; ret = rtl28xx_wr_reg(d, SYS_DEMOD_CTL, val); if (ret) goto err; /* streaming EP: clear stall & reset */ ret = rtl28xx_wr_regs(d, USB_EPA_CTL, "\x00\x00", 2); if (ret) goto err; ret = usb_clear_halt(d->udev, usb_rcvbulkpipe(d->udev, 0x81)); if (ret) goto err; } else { /* demod_ctl_1 */ ret = rtl28xx_rd_reg(d, SYS_DEMOD_CTL1, &val); if (ret) goto err; val |= 0x0c; ret = rtl28xx_wr_reg(d, SYS_DEMOD_CTL1, val); if (ret) goto err; /* set output values */ ret = rtl28xx_rd_reg(d, SYS_GPIO_OUT_VAL, &val); if (ret) goto err; val |= 0x10; ret = rtl28xx_wr_reg(d, SYS_GPIO_OUT_VAL, val); if (ret) goto err; /* demod control */ ret = rtl28xx_rd_reg(d, SYS_DEMOD_CTL, &val); if (ret) goto err; val &= 0x37; ret = rtl28xx_wr_reg(d, SYS_DEMOD_CTL, val); if (ret) goto err; /* streaming EP: set stall & reset */ ret = rtl28xx_wr_regs(d, USB_EPA_CTL, "\x10\x02", 2); if (ret) goto err; } return ret; err: dev_dbg(&d->udev->dev, "%s: failed=%d\n", __func__, ret); return ret; }
static int rtl2832u_tuner_attach(struct dvb_usb_adapter *adap) { int ret; struct dvb_usb_device *d = adap_to_d(adap); struct rtl28xxu_priv *priv = d_to_priv(d); struct dvb_frontend *fe = NULL; struct i2c_board_info info; struct i2c_client *client; dev_dbg(&d->udev->dev, "%s:\n", __func__); memset(&info, 0, sizeof(struct i2c_board_info)); switch (priv->tuner) { case TUNER_RTL2832_FC0012: fe = dvb_attach(fc0012_attach, adap->fe[0], &d->i2c_adap, &rtl2832u_fc0012_config); /* since fc0012 includs reading the signal strength delegate * that to the tuner driver */ adap->fe[0]->ops.read_signal_strength = adap->fe[0]->ops.tuner_ops.get_rf_strength; /* attach SDR */ dvb_attach_sdr(rtl2832_sdr_attach, adap->fe[0], &d->i2c_adap, &rtl28xxu_rtl2832_fc0012_config, NULL); break; case TUNER_RTL2832_FC0013: fe = dvb_attach(fc0013_attach, adap->fe[0], &d->i2c_adap, 0xc6>>1, 0, FC_XTAL_28_8_MHZ); /* fc0013 also supports signal strength reading */ adap->fe[0]->ops.read_signal_strength = adap->fe[0]->ops.tuner_ops.get_rf_strength; /* attach SDR */ dvb_attach_sdr(rtl2832_sdr_attach, adap->fe[0], &d->i2c_adap, &rtl28xxu_rtl2832_fc0013_config, NULL); break; case TUNER_RTL2832_E4000: { struct v4l2_subdev *sd; struct i2c_adapter *i2c_adap_internal = rtl2832_get_private_i2c_adapter(adap->fe[0]); struct e4000_config e4000_config = { .fe = adap->fe[0], .clock = 28800000, }; strlcpy(info.type, "e4000", I2C_NAME_SIZE); info.addr = 0x64; info.platform_data = &e4000_config; request_module(info.type); client = i2c_new_device(priv->demod_i2c_adapter, &info); if (client == NULL || client->dev.driver == NULL) break; if (!try_module_get(client->dev.driver->owner)) { i2c_unregister_device(client); break; } priv->i2c_client_tuner = client; sd = i2c_get_clientdata(client); i2c_set_adapdata(i2c_adap_internal, d); /* attach SDR */ dvb_attach_sdr(rtl2832_sdr_attach, adap->fe[0], i2c_adap_internal, &rtl28xxu_rtl2832_e4000_config, sd); } break; case TUNER_RTL2832_FC2580: fe = dvb_attach(fc2580_attach, adap->fe[0], &d->i2c_adap, &rtl2832u_fc2580_config); break; case TUNER_RTL2832_TUA9001: /* enable GPIO1 and GPIO4 as output */ ret = rtl28xx_wr_reg_mask(d, SYS_GPIO_DIR, 0x00, 0x12); if (ret) goto err; ret = rtl28xx_wr_reg_mask(d, SYS_GPIO_OUT_EN, 0x12, 0x12); if (ret) goto err; fe = dvb_attach(tua9001_attach, adap->fe[0], &d->i2c_adap, &rtl2832u_tua9001_config); break; case TUNER_RTL2832_R820T: fe = dvb_attach(r820t_attach, adap->fe[0], &d->i2c_adap, &rtl2832u_r820t_config); /* Use tuner to get the signal strength */ adap->fe[0]->ops.read_signal_strength = adap->fe[0]->ops.tuner_ops.get_rf_strength; /* attach SDR */ dvb_attach_sdr(rtl2832_sdr_attach, adap->fe[0], &d->i2c_adap, &rtl28xxu_rtl2832_r820t_config, NULL); break; case TUNER_RTL2832_R828D: fe = dvb_attach(r820t_attach, adap->fe[0], priv->demod_i2c_adapter, &rtl2832u_r828d_config); adap->fe[0]->ops.read_signal_strength = adap->fe[0]->ops.tuner_ops.get_rf_strength; if (adap->fe[1]) { fe = dvb_attach(r820t_attach, adap->fe[1], priv->demod_i2c_adapter, &rtl2832u_r828d_config); adap->fe[1]->ops.read_signal_strength = adap->fe[1]->ops.tuner_ops.get_rf_strength; } /* attach SDR */ dvb_attach_sdr(rtl2832_sdr_attach, adap->fe[0], &d->i2c_adap, &rtl28xxu_rtl2832_r820t_config, NULL); break; default: dev_err(&d->udev->dev, "%s: unknown tuner=%d\n", KBUILD_MODNAME, priv->tuner); } if (fe == NULL && priv->i2c_client_tuner == NULL) { ret = -ENODEV; goto err; } return 0; err: dev_dbg(&d->udev->dev, "%s: failed=%d\n", __func__, ret); return ret; } static int rtl2832u_tuner_detach(struct dvb_usb_adapter *adap) { struct dvb_usb_device *d = adap_to_d(adap); struct rtl28xxu_priv *priv = d_to_priv(d); struct i2c_client *client; dev_dbg(&d->udev->dev, "%s:\n", __func__); /* remove I2C tuner */ client = priv->i2c_client_tuner; if (client) { module_put(client->dev.driver->owner); i2c_unregister_device(client); } return 0; } static int rtl28xxu_init(struct dvb_usb_device *d) { int ret; u8 val; dev_dbg(&d->udev->dev, "%s:\n", __func__); /* init USB endpoints */ ret = rtl28xx_rd_reg(d, USB_SYSCTL_0, &val); if (ret) goto err; /* enable DMA and Full Packet Mode*/ val |= 0x09; ret = rtl28xx_wr_reg(d, USB_SYSCTL_0, val); if (ret) goto err; /* set EPA maximum packet size to 0x0200 */ ret = rtl28xx_wr_regs(d, USB_EPA_MAXPKT, "\x00\x02\x00\x00", 4); if (ret) goto err; /* change EPA FIFO length */ ret = rtl28xx_wr_regs(d, USB_EPA_FIFO_CFG, "\x14\x00\x00\x00", 4); if (ret) goto err; return ret; err: dev_dbg(&d->udev->dev, "%s: failed=%d\n", __func__, ret); return ret; }
static int rtl28xxu_probe(struct usb_interface *intf, const struct usb_device_id *id) { int ret, i; u8 val; int properties_count = ARRAY_SIZE(rtl28xxu_properties); struct dvb_usb_device *d; struct usb_device *udev; bool found; deb_info("%s: interface=%d\n", __func__, intf->cur_altsetting->desc.bInterfaceNumber); if (intf->cur_altsetting->desc.bInterfaceNumber != 0) return 0; /* Dynamic USB ID support. Replaces first device ID with current one .*/ udev = interface_to_usbdev(intf); for (i = 0, found = false; i < ARRAY_SIZE(rtl28xxu_table) - 1; i++) { if (rtl28xxu_table[i].idVendor == le16_to_cpu(udev->descriptor.idVendor) && rtl28xxu_table[i].idProduct == le16_to_cpu(udev->descriptor.idProduct)) { found = true; break; } } if (!found) { deb_info("%s: using dynamic ID %04x:%04x\n", __func__, le16_to_cpu(udev->descriptor.idVendor), le16_to_cpu(udev->descriptor.idProduct)); rtl28xxu_properties[0].devices[0].warm_ids[0]->idVendor = le16_to_cpu(udev->descriptor.idVendor); rtl28xxu_properties[0].devices[0].warm_ids[0]->idProduct = le16_to_cpu(udev->descriptor.idProduct); } for (i = 0; i < properties_count; i++) { ret = dvb_usb_device_init(intf, &rtl28xxu_properties[i], THIS_MODULE, &d, adapter_nr); if (ret == 0 || ret != -ENODEV) break; } if (ret) goto err; /* init USB endpoints */ ret = rtl28xx_rd_reg(d, USB_SYSCTL_0, &val); if (ret) goto err; /* enable DMA and Full Packet Mode*/ val |= 0x09; ret = rtl28xx_wr_reg(d, USB_SYSCTL_0, val); if (ret) goto err; /* set EPA maximum packet size to 0x0200 */ ret = rtl28xx_wr_regs(d, USB_EPA_MAXPKT, "\x00\x02\x00\x00", 4); if (ret) goto err; /* change EPA FIFO length */ ret = rtl28xx_wr_regs(d, USB_EPA_FIFO_CFG, "\x14\x00\x00\x00", 4); if (ret) goto err; return ret; err: deb_info("%s: failed=%d\n", __func__, ret); return ret; }