Merge branch 'v4l_for_linus' into patchwork
authorMauro Carvalho Chehab <mchehab@redhat.com>
Tue, 25 Jun 2013 10:24:22 +0000 (07:24 -0300)
committerMauro Carvalho Chehab <mchehab@redhat.com>
Tue, 25 Jun 2013 10:25:09 +0000 (07:25 -0300)
* v4l_for_linus:
  [media] Fix build when drivers are builtin and frontend modules
  [media] s5p makefiles: don't override other selections on obj-[ym]
  [media] exynos4-is: Fix FIMC-IS clocks initialization
  [media] rtl28xxu: fix buffer overflow when probing Rafael Micro r820t tuner

Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
1  2 
drivers/media/platform/exynos4-is/fimc-is.c
drivers/media/platform/exynos4-is/fimc-is.h
drivers/media/usb/dvb-usb-v2/rtl28xxu.c

index 290146ecfb8a7773c88ed13596ab39d048630711,0741945b79ed08829d0fe7490771a9f725f6063c..967f6a939340ea7ace2eb8826703bf713be4cd9d
@@@ -129,7 -129,7 +129,7 @@@ static int fimc_is_setup_clocks(struct 
                                        ATCLK_MCUISP_FREQUENCY);
  }
  
 -int fimc_is_enable_clocks(struct fimc_is *is)
 +static int fimc_is_enable_clocks(struct fimc_is *is)
  {
        int i, ret;
  
        return 0;
  }
  
 -void fimc_is_disable_clocks(struct fimc_is *is)
 +static void fimc_is_disable_clocks(struct fimc_is *is)
  {
        int i;
  
@@@ -527,8 -527,8 +527,8 @@@ static void fimc_is_general_irq_handler
                        break;
  
                case HIC_SET_PARAMETER:
 -                      is->config[is->config_index].p_region_index1 = 0;
 -                      is->config[is->config_index].p_region_index2 = 0;
 +                      is->config[is->config_index].p_region_index[0] = 0;
 +                      is->config[is->config_index].p_region_index[1] = 0;
                        set_bit(IS_ST_BLOCK_CMD_CLEARED, &is->state);
                        pr_debug("HIC_SET_PARAMETER\n");
                        break;
  
                switch (is->i2h_cmd.args[0]) {
                case HIC_SET_PARAMETER:
 -                      is->config[is->config_index].p_region_index1 = 0;
 -                      is->config[is->config_index].p_region_index2 = 0;
 +                      is->config[is->config_index].p_region_index[0] = 0;
 +                      is->config[is->config_index].p_region_index[1] = 0;
                        set_bit(IS_ST_BLOCK_CMD_CLEARED, &is->state);
                        break;
                }
@@@ -834,23 -834,11 +834,11 @@@ static int fimc_is_probe(struct platfor
                goto err_clk;
        }
        pm_runtime_enable(dev);
-       /*
-        * Enable only the ISP power domain, keep FIMC-IS clocks off until
-        * the whole clock tree is configured. The ISP power domain needs
-        * be active in order to acces any CMU_ISP clock registers.
-        */
-       ret = pm_runtime_get_sync(dev);
-       if (ret < 0)
-               goto err_irq;
-       ret = fimc_is_setup_clocks(is);
-       pm_runtime_put_sync(dev);
  
+       ret = pm_runtime_get_sync(dev);
        if (ret < 0)
                goto err_irq;
  
-       is->clk_init = true;
        is->alloc_ctx = vb2_dma_contig_init_ctx(dev);
        if (IS_ERR(is->alloc_ctx)) {
                ret = PTR_ERR(is->alloc_ctx);
        if (ret < 0)
                goto err_dfs;
  
+       pm_runtime_put_sync(dev);
        dev_dbg(dev, "FIMC-IS registered successfully\n");
        return 0;
  
@@@ -891,9 -881,11 +881,11 @@@ err_clk
  static int fimc_is_runtime_resume(struct device *dev)
  {
        struct fimc_is *is = dev_get_drvdata(dev);
+       int ret;
  
-       if (!is->clk_init)
-               return 0;
+       ret = fimc_is_setup_clocks(is);
+       if (ret)
+               return ret;
  
        return fimc_is_enable_clocks(is);
  }
@@@ -902,9 -894,7 +894,7 @@@ static int fimc_is_runtime_suspend(stru
  {
        struct fimc_is *is = dev_get_drvdata(dev);
  
-       if (is->clk_init)
-               fimc_is_disable_clocks(is);
+       fimc_is_disable_clocks(is);
        return 0;
  }
  
index 4b0eccb68480a97755b72453d8c17a5005ac0c66,d7db133b493f7068e9f5281af8a2c95b9c21bf50..08fa518c34f754030aca4fb3afe0a5b5f195eae6
@@@ -225,7 -225,8 +225,7 @@@ struct chain_config 
        struct drc_param        drc;
        struct fd_param         fd;
  
 -      unsigned long           p_region_index1;
 -      unsigned long           p_region_index2;
 +      unsigned long           p_region_index[2];
  };
  
  /**
@@@ -263,7 -264,6 +263,6 @@@ struct fimc_is 
        spinlock_t                      slock;
  
        struct clk                      *clocks[ISS_CLKS_MAX];
-       bool                            clk_init;
        void __iomem                    *regs;
        void __iomem                    *pmu_regs;
        int                             irq;
@@@ -302,7 -302,10 +301,7 @@@ static inline void fimc_is_set_param_bi
  {
        struct chain_config *cfg = &is->config[is->config_index];
  
 -      if (num >= 32)
 -              set_bit(num - 32, &cfg->p_region_index2);
 -      else
 -              set_bit(num, &cfg->p_region_index1);
 +      set_bit(num, &cfg->p_region_index[0]);
  }
  
  static inline void fimc_is_set_param_ctrl_cmd(struct fimc_is *is, int cmd)
index 9a3c044fda3bf86fc1c0d681d4544dbfe16ab378,2cc8ec70e3b68cee498a850525973c771354eef3..c0cd0848631b22953bd09723aa722decedef8687
@@@ -376,7 -376,7 +376,7 @@@ static int rtl2832u_read_config(struct 
        struct rtl28xxu_req req_mxl5007t = {0xd9c0, CMD_I2C_RD, 1, buf};
        struct rtl28xxu_req req_e4000 = {0x02c8, CMD_I2C_RD, 1, buf};
        struct rtl28xxu_req req_tda18272 = {0x00c0, CMD_I2C_RD, 2, buf};
-       struct rtl28xxu_req req_r820t = {0x0034, CMD_I2C_RD, 5, buf};
+       struct rtl28xxu_req req_r820t = {0x0034, CMD_I2C_RD, 1, buf};
  
        dev_dbg(&d->udev->dev, "%s:\n", __func__);
  
                goto found;
        }
  
-       /* check R820T by reading tuner stats at I2C addr 0x1a */
+       /* check R820T ID register; reg=00 val=69 */
        ret = rtl28xxu_ctrl_msg(d, &req_r820t);
-       if (ret == 0) {
+       if (ret == 0 && buf[0] == 0x69) {
                priv->tuner = TUNER_RTL2832_R820T;
                priv->tuner_name = "R820T";
                goto found;
  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);
 +              /* GPIO3=1, GPIO4=0 */
 +              ret = rtl28xx_wr_reg_mask(d, SYS_GPIO_OUT_VAL, 0x08, 0x18);
                if (ret)
                        goto err;
  
 -              val |= 0x08;
 -              val &= 0xef;
 -
 -              ret = rtl28xx_wr_reg(d, SYS_GPIO_OUT_VAL, val);
 +              /* suspend? */
 +              ret = rtl28xx_wr_reg_mask(d, SYS_DEMOD_CTL1, 0x00, 0x10);
                if (ret)
                        goto err;
  
 -              /* demod_ctl_1 */
 -              ret = rtl28xx_rd_reg(d, SYS_DEMOD_CTL1, &val);
 +              /* enable PLL */
 +              ret = rtl28xx_wr_reg_mask(d, SYS_DEMOD_CTL, 0x80, 0x80);
                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);
 +              /* disable reset */
 +              ret = rtl28xx_wr_reg_mask(d, SYS_DEMOD_CTL, 0x20, 0x20);
                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);
 +              /* enable ADC */
 +              ret = rtl28xx_wr_reg_mask(d, SYS_DEMOD_CTL, 0x48, 0x48);
                if (ret)
                        goto err;
  
                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);
 +              /* GPIO4=1 */
 +              ret = rtl28xx_wr_reg_mask(d, SYS_GPIO_OUT_VAL, 0x10, 0x10);
                if (ret)
                        goto err;
  
 -              /* demod control */
 -              ret = rtl28xx_rd_reg(d, SYS_DEMOD_CTL, &val);
 +              /* disable ADC */
 +              ret = rtl28xx_wr_reg_mask(d, SYS_DEMOD_CTL, 0x00, 0x48);
                if (ret)
                        goto err;
  
 -              val &= 0x37;
 -
 -              ret = rtl28xx_wr_reg(d, SYS_DEMOD_CTL, val);
 +              /* disable PLL */
 +              ret = rtl28xx_wr_reg_mask(d, SYS_DEMOD_CTL, 0x00, 0x80);
                if (ret)
                        goto err;
  
@@@ -1191,47 -1242,42 +1191,47 @@@ static int rtl2831u_get_rc_config(struc
  
        return 0;
  }
 -#else
 -      #define rtl2831u_get_rc_config NULL
 -#endif
  
 -#if IS_ENABLED(CONFIG_RC_CORE)
  static int rtl2832u_rc_query(struct dvb_usb_device *d)
  {
 -      int ret, i;
 +      int ret, i, len;
        struct rtl28xxu_priv *priv = d->priv;
 +      struct ir_raw_event ev;
        u8 buf[128];
 -      int len;
 -      struct rtl28xxu_reg_val rc_nec_tab[] = {
 -              { IR_RX_CTRL,             0x20 },
 -              { IR_RX_BUF_CTRL,         0x80 },
 -              { IR_RX_IF,               0xff },
 -              { IR_RX_IE,               0xff },
 -              { IR_MAX_DURATION0,       0xd0 },
 -              { IR_MAX_DURATION1,       0x07 },
 -              { IR_IDLE_LEN0,           0xc0 },
 -              { IR_IDLE_LEN1,           0x00 },
 -              { IR_GLITCH_LEN,          0x03 },
 -              { IR_RX_CLK,              0x09 },
 -              { IR_RX_CFG,              0x1c },
 -              { IR_MAX_H_TOL_LEN,       0x1e },
 -              { IR_MAX_L_TOL_LEN,       0x1e },
 -              { IR_RX_CTRL,             0x80 },
 +      static const struct rtl28xxu_reg_val_mask refresh_tab[] = {
 +              {IR_RX_IF,               0x03, 0xff},
 +              {IR_RX_BUF_CTRL,         0x80, 0xff},
 +              {IR_RX_CTRL,             0x80, 0xff},
        };
  
        /* init remote controller */
        if (!priv->rc_active) {
 -              for (i = 0; i < ARRAY_SIZE(rc_nec_tab); i++) {
 -                      ret = rtl28xx_wr_reg(d, rc_nec_tab[i].reg,
 -                                      rc_nec_tab[i].val);
 +              static const struct rtl28xxu_reg_val_mask init_tab[] = {
 +                      {SYS_DEMOD_CTL1,         0x00, 0x04},
 +                      {SYS_DEMOD_CTL1,         0x00, 0x08},
 +                      {USB_CTRL,               0x20, 0x20},
 +                      {SYS_GPIO_DIR,           0x00, 0x08},
 +                      {SYS_GPIO_OUT_EN,        0x08, 0x08},
 +                      {SYS_GPIO_OUT_VAL,       0x08, 0x08},
 +                      {IR_MAX_DURATION0,       0xd0, 0xff},
 +                      {IR_MAX_DURATION1,       0x07, 0xff},
 +                      {IR_IDLE_LEN0,           0xc0, 0xff},
 +                      {IR_IDLE_LEN1,           0x00, 0xff},
 +                      {IR_GLITCH_LEN,          0x03, 0xff},
 +                      {IR_RX_CLK,              0x09, 0xff},
 +                      {IR_RX_CFG,              0x1c, 0xff},
 +                      {IR_MAX_H_TOL_LEN,       0x1e, 0xff},
 +                      {IR_MAX_L_TOL_LEN,       0x1e, 0xff},
 +                      {IR_RX_CTRL,             0x80, 0xff},
 +              };
 +
 +              for (i = 0; i < ARRAY_SIZE(init_tab); i++) {
 +                      ret = rtl28xx_wr_reg_mask(d, init_tab[i].reg,
 +                                      init_tab[i].val, init_tab[i].mask);
                        if (ret)
                                goto err;
                }
 +
                priv->rc_active = true;
        }
  
                goto err;
  
        len = buf[0];
 +
 +      /* read raw code from hw */
        ret = rtl2831_rd_regs(d, IR_RX_BUF, buf, len);
 +      if (ret)
 +              goto err;
  
 -      /* TODO: pass raw IR to Kernel IR decoder */
 +      /* let hw receive new code */
 +      for (i = 0; i < ARRAY_SIZE(refresh_tab); i++) {
 +              ret = rtl28xx_wr_reg_mask(d, refresh_tab[i].reg,
 +                              refresh_tab[i].val, refresh_tab[i].mask);
 +              if (ret)
 +                      goto err;
 +      }
  
 -      ret = rtl28xx_wr_reg(d, IR_RX_IF, 0x03);
 -      ret = rtl28xx_wr_reg(d, IR_RX_BUF_CTRL, 0x80);
 -      ret = rtl28xx_wr_reg(d, IR_RX_CTRL, 0x80);
 +      /* pass data to Kernel IR decoder */
 +      init_ir_raw_event(&ev);
  
 +      for (i = 0; i < len; i++) {
 +              ev.pulse = buf[i] >> 7;
 +              ev.duration = 50800 * (buf[i] & 0x7f);
 +              ir_raw_event_store_with_filter(d->rc_dev, &ev);
 +      }
 +
 +      /* 'flush' ir_raw_event_store_with_filter() */
 +      ir_raw_event_set_idle(d->rc_dev, true);
 +      ir_raw_event_handle(d->rc_dev);
  exit:
        return ret;
  err:
  static int rtl2832u_get_rc_config(struct dvb_usb_device *d,
                struct dvb_usb_rc *rc)
  {
 -      rc->map_name = RC_MAP_EMPTY;
 -      rc->allowed_protos = RC_BIT_NEC;
 +      /* load empty to enable rc */
 +      if (!rc->map_name)
 +              rc->map_name = RC_MAP_EMPTY;
 +      rc->allowed_protos = RC_BIT_ALL;
 +      rc->driver_type = RC_DRIVER_IR_RAW;
        rc->query = rtl2832u_rc_query;
        rc->interval = 400;
  
        return 0;
  }
  #else
 -      #define rtl2832u_get_rc_config NULL
 +#define rtl2831u_get_rc_config NULL
 +#define rtl2832u_get_rc_config NULL
  #endif
  
  static const struct dvb_usb_device_properties rtl2831u_props = {
@@@ -1355,7 -1379,7 +1355,7 @@@ static const struct usb_device_id rtl28
        { DVB_USB_DEVICE(USB_VID_REALTEK, 0x2838,
                &rtl2832u_props, "Realtek RTL2832U reference design", NULL) },
        { DVB_USB_DEVICE(USB_VID_TERRATEC, USB_PID_TERRATEC_CINERGY_T_STICK_BLACK_REV1,
 -              &rtl2832u_props, "TerraTec Cinergy T Stick Black", NULL) },
 +              &rtl2832u_props, "TerraTec Cinergy T Stick Black", RC_MAP_TERRATEC_SLIM) },
        { DVB_USB_DEVICE(USB_VID_GTEK, USB_PID_DELOCK_USB2_DVBT,
                &rtl2832u_props, "G-Tek Electronics Group Lifeview LV5TDLX DVB-T", NULL) },
        { DVB_USB_DEVICE(USB_VID_TERRATEC, USB_PID_NOXON_DAB_STICK,
        { DVB_USB_DEVICE(USB_VID_KWORLD_2, 0xd393,
                &rtl2832u_props, "GIGABYTE U7300", NULL) },
        { DVB_USB_DEVICE(USB_VID_DEXATEK, 0x1104,
 -              &rtl2832u_props, "Digivox Micro Hd", NULL) },
 +              &rtl2832u_props, "MSI DIGIVOX Micro HD", NULL) },
        { DVB_USB_DEVICE(USB_VID_COMPRO, 0x0620,
                &rtl2832u_props, "Compro VideoMate U620F", NULL) },
        { DVB_USB_DEVICE(USB_VID_KWORLD_2, 0xd394,
                &rtl2832u_props, "MaxMedia HU394-T", NULL) },
 +      { DVB_USB_DEVICE(USB_VID_LEADTEK, 0x6a03,
 +              &rtl2832u_props, "Leadtek WinFast DTV Dongle mini", NULL) },
 +      { DVB_USB_DEVICE(USB_VID_GTEK, USB_PID_CPYTO_REDI_PC50A,
 +              &rtl2832u_props, "Crypto ReDi PC 50 A", NULL) },
        { }
  };
  MODULE_DEVICE_TABLE(usb, rtl28xxu_id_table);