diff options
264 files changed, 8069 insertions, 5753 deletions
diff --git a/Documentation/devicetree/bindings/media/i2c/panasonic,amg88xx.txt b/Documentation/devicetree/bindings/media/i2c/panasonic,amg88xx.txt new file mode 100644 index 000000000000..4a3181a3dd7e --- /dev/null +++ b/Documentation/devicetree/bindings/media/i2c/panasonic,amg88xx.txt @@ -0,0 +1,19 @@ +* Panasonic AMG88xx + +The Panasonic family of AMG88xx Grid-Eye sensors allow recording +8x8 10Hz video which consists of thermal datapoints + +Required Properties: + - compatible : Must be "panasonic,amg88xx" + - reg : i2c address of the device + +Example: + + i2c0@1c22000 { + ... + amg88xx@69 { + compatible = "panasonic,amg88xx"; + reg = <0x69>; + }; + ... + }; diff --git a/Documentation/devicetree/bindings/media/rcar_vin.txt b/Documentation/devicetree/bindings/media/rcar_vin.txt index 1ce7ff9449c5..a19517e1c669 100644 --- a/Documentation/devicetree/bindings/media/rcar_vin.txt +++ b/Documentation/devicetree/bindings/media/rcar_vin.txt @@ -2,20 +2,28 @@ Renesas R-Car Video Input driver (rcar_vin) ------------------------------------------- The rcar_vin device provides video input capabilities for the Renesas R-Car -family of devices. The current blocks are always slaves and suppot one input -channel which can be either RGB, YUYV or BT656. +family of devices. + +Each VIN instance has a single parallel input that supports RGB and YUV video, +with both external synchronization and BT.656 synchronization for the latter. +Depending on the instance the VIN input is connected to external SoC pins, or +on Gen3 platforms to a CSI-2 receiver. - compatible: Must be one or more of the following - - "renesas,vin-r8a7795" for the R8A7795 device - - "renesas,vin-r8a7794" for the R8A7794 device - - "renesas,vin-r8a7793" for the R8A7793 device - - "renesas,vin-r8a7792" for the R8A7792 device - - "renesas,vin-r8a7791" for the R8A7791 device - - "renesas,vin-r8a7790" for the R8A7790 device - - "renesas,vin-r8a7779" for the R8A7779 device + - "renesas,vin-r8a7743" for the R8A7743 device + - "renesas,vin-r8a7745" for the R8A7745 device - "renesas,vin-r8a7778" for the R8A7778 device - - "renesas,rcar-gen2-vin" for a generic R-Car Gen2 compatible device. - - "renesas,rcar-gen3-vin" for a generic R-Car Gen3 compatible device. + - "renesas,vin-r8a7779" for the R8A7779 device + - "renesas,vin-r8a7790" for the R8A7790 device + - "renesas,vin-r8a7791" for the R8A7791 device + - "renesas,vin-r8a7792" for the R8A7792 device + - "renesas,vin-r8a7793" for the R8A7793 device + - "renesas,vin-r8a7794" for the R8A7794 device + - "renesas,vin-r8a7795" for the R8A7795 device + - "renesas,vin-r8a7796" for the R8A7796 device + - "renesas,vin-r8a77970" for the R8A77970 device + - "renesas,rcar-gen2-vin" for a generic R-Car Gen2 or RZ/G1 compatible + device. When compatible with the generic version nodes must list the SoC-specific version corresponding to the platform first @@ -28,21 +36,38 @@ channel which can be either RGB, YUYV or BT656. Additionally, an alias named vinX will need to be created to specify which video input device this is. -The per-board settings: +The per-board settings Gen2 platforms: - port sub-node describing a single endpoint connected to the vin as described in video-interfaces.txt[1]. Only the first one will be considered as each vin interface has one input port. - These settings are used to work out video input format and widths - into the system. +The per-board settings Gen3 platforms: +Gen3 platforms can support both a single connected parallel input source +from external SoC pins (port0) and/or multiple parallel input sources +from local SoC CSI-2 receivers (port1) depending on SoC. -Device node example -------------------- +- renesas,id - ID number of the VIN, VINx in the documentation. +- ports + - port 0 - sub-node describing a single endpoint connected to the VIN + from external SoC pins described in video-interfaces.txt[1]. + Describing more then one endpoint in port 0 is invalid. Only VIN + instances that are connected to external pins should have port 0. + - port 1 - sub-nodes describing one or more endpoints connected to + the VIN from local SoC CSI-2 receivers. The endpoint numbers must + use the following schema. - aliases { - vin0 = &vin0; - }; + - Endpoint 0 - sub-node describing the endpoint connected to CSI20 + - Endpoint 1 - sub-node describing the endpoint connected to CSI21 + - Endpoint 2 - sub-node describing the endpoint connected to CSI40 + - Endpoint 3 - sub-node describing the endpoint connected to CSI41 + +Device node example for Gen2 platforms +-------------------------------------- + + aliases { + vin0 = &vin0; + }; vin0: vin@e6ef0000 { compatible = "renesas,vin-r8a7790", "renesas,rcar-gen2-vin"; @@ -52,8 +77,8 @@ Device node example status = "disabled"; }; -Board setup example (vin1 composite video input) ------------------------------------------------- +Board setup example for Gen2 platforms (vin1 composite video input) +------------------------------------------------------------------- &i2c2 { status = "okay"; @@ -92,6 +117,77 @@ Board setup example (vin1 composite video input) }; }; +Device node example for Gen3 platforms +-------------------------------------- + + vin0: video@e6ef0000 { + compatible = "renesas,vin-r8a7795"; + reg = <0 0xe6ef0000 0 0x1000>; + interrupts = <GIC_SPI 188 IRQ_TYPE_LEVEL_HIGH>; + clocks = <&cpg CPG_MOD 811>; + power-domains = <&sysc R8A7795_PD_ALWAYS_ON>; + resets = <&cpg 811>; + renesas,id = <0>; + + ports { + #address-cells = <1>; + #size-cells = <0>; + + port@1 { + #address-cells = <1>; + #size-cells = <0>; + + reg = <1>; + + vin0csi20: endpoint@0 { + reg = <0>; + remote-endpoint= <&csi20vin0>; + }; + vin0csi21: endpoint@1 { + reg = <1>; + remote-endpoint= <&csi21vin0>; + }; + vin0csi40: endpoint@2 { + reg = <2>; + remote-endpoint= <&csi40vin0>; + }; + }; + }; + }; + csi20: csi2@fea80000 { + compatible = "renesas,r8a7795-csi2"; + reg = <0 0xfea80000 0 0x10000>; + interrupts = <GIC_SPI 184 IRQ_TYPE_LEVEL_HIGH>; + clocks = <&cpg CPG_MOD 714>; + power-domains = <&sysc R8A7795_PD_ALWAYS_ON>; + resets = <&cpg 714>; + + ports { + #address-cells = <1>; + #size-cells = <0>; + + port@0 { + reg = <0>; + csi20_in: endpoint { + clock-lanes = <0>; + data-lanes = <1>; + remote-endpoint = <&adv7482_txb>; + }; + }; + + port@1 { + #address-cells = <1>; + #size-cells = <0>; + + reg = <1>; + + csi20vin0: endpoint@0 { + reg = <0>; + remote-endpoint = <&vin0csi20>; + }; + }; + }; + }; [1] video-interfaces.txt common video media interface diff --git a/Documentation/media/uapi/rc/lirc-dev-intro.rst b/Documentation/media/uapi/rc/lirc-dev-intro.rst index 698e4f80270e..11516c8bff62 100644 --- a/Documentation/media/uapi/rc/lirc-dev-intro.rst +++ b/Documentation/media/uapi/rc/lirc-dev-intro.rst @@ -18,7 +18,7 @@ Example dmesg output upon a driver registering w/LIRC: .. code-block:: none $ dmesg |grep lirc_dev - rc rc0: lirc_dev: driver mceusb registered at minor = 0 + rc rc0: lirc_dev: driver mceusb registered at minor = 0, raw IR receiver, raw IR transmitter What you should see for a chardev: diff --git a/Documentation/media/uapi/rc/lirc-func.rst b/Documentation/media/uapi/rc/lirc-func.rst index ddb4620de294..9656423a3f28 100644 --- a/Documentation/media/uapi/rc/lirc-func.rst +++ b/Documentation/media/uapi/rc/lirc-func.rst @@ -17,6 +17,7 @@ LIRC Function Reference lirc-get-rec-resolution lirc-set-send-duty-cycle lirc-get-timeout + lirc-get-rec-timeout lirc-set-rec-timeout lirc-set-rec-carrier lirc-set-rec-carrier-range diff --git a/Documentation/media/uapi/rc/lirc-set-rec-timeout.rst b/Documentation/media/uapi/rc/lirc-set-rec-timeout.rst index b3e16bbdbc90..a833a6a4c25a 100644 --- a/Documentation/media/uapi/rc/lirc-set-rec-timeout.rst +++ b/Documentation/media/uapi/rc/lirc-set-rec-timeout.rst @@ -1,19 +1,23 @@ .. -*- coding: utf-8; mode: rst -*- .. _lirc_set_rec_timeout: +.. _lirc_get_rec_timeout: -************************** -ioctl LIRC_SET_REC_TIMEOUT -************************** +*************************************************** +ioctl LIRC_GET_REC_TIMEOUT and LIRC_SET_REC_TIMEOUT +*************************************************** Name ==== -LIRC_SET_REC_TIMEOUT - sets the integer value for IR inactivity timeout. +LIRC_GET_REC_TIMEOUT/LIRC_SET_REC_TIMEOUT - Get/set the integer value for IR inactivity timeout. Synopsis ======== +.. c:function:: int ioctl( int fd, LIRC_GET_REC_TIMEOUT, __u32 *timeout ) + :name: LIRC_GET_REC_TIMEOUT + .. c:function:: int ioctl( int fd, LIRC_SET_REC_TIMEOUT, __u32 *timeout ) :name: LIRC_SET_REC_TIMEOUT @@ -30,7 +34,7 @@ Arguments Description =========== -Sets the integer value for IR inactivity timeout. +Get and set the integer value for IR inactivity timeout. If supported by the hardware, setting it to 0 disables all hardware timeouts and data should be reported as soon as possible. If the exact value diff --git a/Documentation/media/v4l-drivers/cx23885-cardlist.rst b/Documentation/media/v4l-drivers/cx23885-cardlist.rst index 3129ef04ddd3..8c24df8e0423 100644 --- a/Documentation/media/v4l-drivers/cx23885-cardlist.rst +++ b/Documentation/media/v4l-drivers/cx23885-cardlist.rst @@ -186,7 +186,7 @@ cx23885 cards list * - 43 - Hauppauge ImpactVCB-e - - 0070:7133 + - 0070:7133, 0070:7137 * - 44 - DViCO FusionHDTV DVB-T Dual Express2 @@ -243,3 +243,19 @@ cx23885 cards list * - 57 - Hauppauge WinTV-QuadHD-ATSC - 0070:6a18, 0070:6b18 + + * - 58 + - Hauppauge WinTV-HVR-1265(161111) + - 0070:2a18 + + * - 59 + - Hauppauge WinTV-Starburst2 + - 0070:f02a + + * - 60 + - Hauppauge WinTV-QuadHD-DVB(885) + - + + * - 61 + - Hauppauge WinTV-QuadHD-ATSC(885) + - diff --git a/Documentation/media/v4l-drivers/em28xx-cardlist.rst b/Documentation/media/v4l-drivers/em28xx-cardlist.rst index ec938c08f43d..dfe882ca945f 100644 --- a/Documentation/media/v4l-drivers/em28xx-cardlist.rst +++ b/Documentation/media/v4l-drivers/em28xx-cardlist.rst @@ -391,7 +391,7 @@ EM28xx cards list * - 94 - PCTV tripleStick (292e) - em28178 - - 2013:025f, 2040:0264 + - 2013:025f, 2013:0264, 2040:0264, 2040:8264, 2040:8268, 2040:8268 * - 95 - Leadtek VC100 - em2861 @@ -411,12 +411,16 @@ EM28xx cards list * - 99 - Hauppauge WinTV-dualHD DVB - em28174 - - 2040:0265 + - 2040:0265, 2040:8265 * - 100 - Hauppauge WinTV-dualHD 01595 ATSC/QAM - em28174 - - 2040:026d + - 2040:026d, 2040:826d * - 101 - Terratec Cinergy H6 rev. 2 - em2884 - 0ccd:10b2 + * - 102 + - :ZOLID HYBRID TV STICK + - em2882 + - diff --git a/MAINTAINERS b/MAINTAINERS index df6e9bb2559a..49003f77cedd 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -14929,6 +14929,12 @@ L: linux-media@vger.kernel.org S: Maintained F: drivers/media/platform/video-mux.c +VIDEO I2C POLLING DRIVER +M: Matt Ranostay <matt.ranostay@konsulko.com> +L: linux-media@vger.kernel.org +S: Maintained +F: drivers/media/i2c/video-i2c.c + VIDEOBUF2 FRAMEWORK M: Pawel Osciak <pawel@osciak.com> M: Marek Szyprowski <m.szyprowski@samsung.com> diff --git a/drivers/media/Kconfig b/drivers/media/Kconfig index 37124c3b8c2a..8add62a18293 100644 --- a/drivers/media/Kconfig +++ b/drivers/media/Kconfig @@ -78,13 +78,13 @@ config MEDIA_SDR_SUPPORT Say Y when you have a software defined radio device. config MEDIA_CEC_SUPPORT - bool "HDMI CEC support" - ---help--- - Enable support for HDMI CEC (Consumer Electronics Control), - which is an optional HDMI feature. + bool "HDMI CEC support" + ---help--- + Enable support for HDMI CEC (Consumer Electronics Control), + which is an optional HDMI feature. - Say Y when you have an HDMI receiver, transmitter or a USB CEC - adapter that supports HDMI CEC. + Say Y when you have an HDMI receiver, transmitter or a USB CEC + adapter that supports HDMI CEC. source "drivers/media/cec/Kconfig" diff --git a/drivers/media/cec/cec-core.c b/drivers/media/cec/cec-core.c index b0c87f9ea08f..b278ab90b387 100644 --- a/drivers/media/cec/cec-core.c +++ b/drivers/media/cec/cec-core.c @@ -322,7 +322,7 @@ struct cec_adapter *cec_allocate_adapter(const struct cec_adap_ops *ops, adap->rc->allowed_protocols = RC_PROTO_BIT_CEC; adap->rc->priv = adap; adap->rc->map_name = RC_MAP_CEC; - adap->rc->timeout = MS_TO_NS(100); + adap->rc->timeout = MS_TO_NS(550); #endif return adap; } diff --git a/drivers/media/cec/cec-pin-error-inj.c b/drivers/media/cec/cec-pin-error-inj.c index aaa899a175ce..7132a2758bd3 100644 --- a/drivers/media/cec/cec-pin-error-inj.c +++ b/drivers/media/cec/cec-pin-error-inj.c @@ -203,16 +203,18 @@ bool cec_pin_error_inj_parse_line(struct cec_adapter *adap, char *line) mode_mask = CEC_ERROR_INJ_MODE_MASK << mode_offset; arg_idx = cec_error_inj_cmds[i].arg_idx; - if (mode_offset == CEC_ERROR_INJ_RX_ARB_LOST_OFFSET || - mode_offset == CEC_ERROR_INJ_TX_ADD_BYTES_OFFSET) - is_bit_pos = false; - if (mode_offset == CEC_ERROR_INJ_RX_ARB_LOST_OFFSET) { if (has_op) return false; if (!has_pos) pos = 0x0f; + is_bit_pos = false; + } else if (mode_offset == CEC_ERROR_INJ_TX_ADD_BYTES_OFFSET) { + if (!has_pos || !pos) + return false; + is_bit_pos = false; } + if (arg_idx >= 0 && is_bit_pos) { if (!has_pos || pos >= 160) return false; diff --git a/drivers/media/cec/cec-pin.c b/drivers/media/cec/cec-pin.c index 2a5df99735fa..6e311424f0dc 100644 --- a/drivers/media/cec/cec-pin.c +++ b/drivers/media/cec/cec-pin.c @@ -119,7 +119,7 @@ static void cec_pin_update(struct cec_pin *pin, bool v, bool force) if (pin->work_pin_events_dropped) { pin->work_pin_events_dropped = false; - v |= CEC_PIN_EVENT_FL_DROPPED; + ev |= CEC_PIN_EVENT_FL_DROPPED; } pin->work_pin_events[pin->work_pin_events_wr] = ev; pin->work_pin_ts[pin->work_pin_events_wr] = ktime_get(); diff --git a/drivers/media/common/b2c2/flexcop-fe-tuner.c b/drivers/media/common/b2c2/flexcop-fe-tuner.c index a1ce3e8eb1d3..aac1aadb0cb1 100644 --- a/drivers/media/common/b2c2/flexcop-fe-tuner.c +++ b/drivers/media/common/b2c2/flexcop-fe-tuner.c @@ -495,7 +495,6 @@ static int airstar_atsc2_attach(struct flexcop_device *fc, /* AirStar ATSC 3rd generation */ #if FE_SUPPORTED(LGDT330X) static struct lgdt330x_config air2pc_atsc_hd5000_config = { - .demod_address = 0x59, .demod_chip = LGDT3303, .serial_mpeg = 0x04, .clock_polarity_flip = 1, @@ -504,7 +503,8 @@ static struct lgdt330x_config air2pc_atsc_hd5000_config = { static int airstar_atsc3_attach(struct flexcop_device *fc, struct i2c_adapter *i2c) { - fc->fe = dvb_attach(lgdt330x_attach, &air2pc_atsc_hd5000_config, i2c); + fc->fe = dvb_attach(lgdt330x_attach, &air2pc_atsc_hd5000_config, + 0x59, i2c); if (!fc->fe) return 0; diff --git a/drivers/media/common/b2c2/flexcop-i2c.c b/drivers/media/common/b2c2/flexcop-i2c.c index 564da6fa900d..6675b605eb6f 100644 --- a/drivers/media/common/b2c2/flexcop-i2c.c +++ b/drivers/media/common/b2c2/flexcop-i2c.c @@ -105,40 +105,36 @@ static int flexcop_i2c_write4(struct flexcop_device *fc, } int flexcop_i2c_request(struct flexcop_i2c_adapter *i2c, - flexcop_access_op_t op, u8 chipaddr, u8 addr, u8 *buf, u16 len) + flexcop_access_op_t op, u8 chipaddr, + u8 start_addr, u8 *buf, u16 size) { int ret; - -#ifdef DUMP_I2C_MESSAGES - int i; -#endif + int len = size; + u8 *p; + u8 addr = start_addr; u16 bytes_to_transfer; flexcop_ibi_value r100; - deb_i2c("op = %d\n",op); + deb_i2c("port %d %s(%02x): register %02x, size: %d\n", + i2c->port, + op == FC_READ ? "rd" : "wr", + chipaddr, start_addr, size); r100.raw = 0; r100.tw_sm_c_100.chipaddr = chipaddr; r100.tw_sm_c_100.twoWS_rw = op; r100.tw_sm_c_100.twoWS_port_reg = i2c->port; -#ifdef DUMP_I2C_MESSAGES - printk(KERN_DEBUG "%d ", i2c->port); - if (op == FC_READ) - printk(KERN_CONT "rd("); - else - printk(KERN_CONT "wr("); - printk(KERN_CONT "%02x): %02x ", chipaddr, addr); -#endif - /* in that case addr is the only value -> * we write it twice as baseaddr and val0 * BBTI is doing it like that for ISL6421 at least */ if (i2c->no_base_addr && len == 0 && op == FC_WRITE) { - buf = &addr; + buf = &start_addr; len = 1; } + p = buf; + while (len != 0) { bytes_to_transfer = len > 4 ? 4 : len; @@ -146,26 +142,21 @@ int flexcop_i2c_request(struct flexcop_i2c_adapter *i2c, r100.tw_sm_c_100.baseaddr = addr; if (op == FC_READ) - ret = flexcop_i2c_read4(i2c, r100, buf); + ret = flexcop_i2c_read4(i2c, r100, p); else - ret = flexcop_i2c_write4(i2c->fc, r100, buf); - -#ifdef DUMP_I2C_MESSAGES - for (i = 0; i < bytes_to_transfer; i++) - printk(KERN_CONT "%02x ", buf[i]); -#endif + ret = flexcop_i2c_write4(i2c->fc, r100, p); if (ret < 0) return ret; - buf += bytes_to_transfer; + p += bytes_to_transfer; addr += bytes_to_transfer; len -= bytes_to_transfer; } - -#ifdef DUMP_I2C_MESSAGES - printk(KERN_CONT "\n"); -#endif + deb_i2c_dump("port %d %s(%02x): register %02x: %*ph\n", + i2c->port, + op == FC_READ ? "rd" : "wr", + chipaddr, start_addr, size, buf); return 0; } diff --git a/drivers/media/common/b2c2/flexcop.c b/drivers/media/common/b2c2/flexcop.c index 2e0ab55cd67e..cbaa61f10d5f 100644 --- a/drivers/media/common/b2c2/flexcop.c +++ b/drivers/media/common/b2c2/flexcop.c @@ -42,7 +42,7 @@ int b2c2_flexcop_debug; EXPORT_SYMBOL_GPL(b2c2_flexcop_debug); module_param_named(debug, b2c2_flexcop_debug, int, 0644); MODULE_PARM_DESC(debug, - "set debug level (1=info,2=tuner,4=i2c,8=ts,16=sram,32=reg (|-able))." + "set debug level (1=info,2=tuner,4=i2c,8=ts,16=sram,32=reg,64=i2cdump (|-able))." DEBSTATUS); #undef DEBSTATUS diff --git a/drivers/media/common/b2c2/flexcop.h b/drivers/media/common/b2c2/flexcop.h index 911ece59ea02..486fe2380b92 100644 --- a/drivers/media/common/b2c2/flexcop.h +++ b/drivers/media/common/b2c2/flexcop.h @@ -26,5 +26,6 @@ extern int b2c2_flexcop_debug; #define deb_ts(args...) dprintk(0x08, args) #define deb_sram(args...) dprintk(0x10, args) #define deb_rdump(args...) dprintk(0x20, args) +#define deb_i2c_dump(args...) dprintk(0x40, args) #endif diff --git a/drivers/media/common/siano/smscoreapi.c b/drivers/media/common/siano/smscoreapi.c index b5dcc6d1fe90..1c93258a2d47 100644 --- a/drivers/media/common/siano/smscoreapi.c +++ b/drivers/media/common/siano/smscoreapi.c @@ -415,8 +415,8 @@ EXPORT_SYMBOL_GPL(smscore_get_board_id); struct smscore_registry_entry_t { struct list_head entry; - char devpath[32]; - int mode; + char devpath[32]; + int mode; enum sms_device_type_st type; }; @@ -442,7 +442,7 @@ static struct smscore_registry_entry_t *smscore_find_registry(char *devpath) next != &g_smscore_registry; next = next->next) { entry = (struct smscore_registry_entry_t *) next; - if (!strcmp(entry->devpath, devpath)) { + if (!strncmp(entry->devpath, devpath, sizeof(entry->devpath))) { kmutex_unlock(&g_smscore_registrylock); return entry; } @@ -450,7 +450,7 @@ static struct smscore_registry_entry_t *smscore_find_registry(char *devpath) entry = kmalloc(sizeof(*entry), GFP_KERNEL); if (entry) { entry->mode = default_mode; - strcpy(entry->devpath, devpath); + strlcpy(entry->devpath, devpath, sizeof(entry->devpath)); list_add(&entry->entry, &g_smscore_registry); } else pr_err("failed to create smscore_registry.\n"); @@ -733,7 +733,7 @@ int smscore_register_device(struct smsdevice_params_t *params, dev->postload_handler = params->postload_handler; dev->device_flags = params->flags; - strcpy(dev->devpath, params->devpath); + strlcpy(dev->devpath, params->devpath, sizeof(dev->devpath)); smscore_registry_settype(dev->devpath, params->device_type); diff --git a/drivers/media/common/siano/smsendian.c b/drivers/media/common/siano/smsendian.c index bfe831c10b1c..b95a631f23f9 100644 --- a/drivers/media/common/siano/smsendian.c +++ b/drivers/media/common/siano/smsendian.c @@ -35,7 +35,7 @@ void smsendian_handle_tx_message(void *buffer) switch (msg->x_msg_header.msg_type) { case MSG_SMS_DATA_DOWNLOAD_REQ: { - msg->msg_data[0] = le32_to_cpu(msg->msg_data[0]); + msg->msg_data[0] = le32_to_cpu((__force __le32)(msg->msg_data[0])); break; } @@ -44,7 +44,7 @@ void smsendian_handle_tx_message(void *buffer) sizeof(struct sms_msg_hdr))/4; for (i = 0; i < msg_words; i++) - msg->msg_data[i] = le32_to_cpu(msg->msg_data[i]); + msg->msg_data[i] = le32_to_cpu((__force __le32)msg->msg_data[i]); break; } @@ -64,7 +64,7 @@ void smsendian_handle_rx_message(void *buffer) { struct sms_version_res *ver = (struct sms_version_res *) msg; - ver->chip_model = le16_to_cpu(ver->chip_model); + ver->chip_model = le16_to_cpu((__force __le16)ver->chip_model); break; } @@ -81,7 +81,7 @@ void smsendian_handle_rx_message(void *buffer) sizeof(struct sms_msg_hdr))/4; for (i = 0; i < msg_words; i++) - msg->msg_data[i] = le32_to_cpu(msg->msg_data[i]); + msg->msg_data[i] = le32_to_cpu((__force __le32)msg->msg_data[i]); break; } @@ -95,9 +95,9 @@ void smsendian_handle_message_header(void *msg) #ifdef __BIG_ENDIAN struct sms_msg_hdr *phdr = (struct sms_msg_hdr *)msg; - phdr->msg_type = le16_to_cpu(phdr->msg_type); - phdr->msg_length = le16_to_cpu(phdr->msg_length); - phdr->msg_flags = le16_to_cpu(phdr->msg_flags); + phdr->msg_type = le16_to_cpu((__force __le16)phdr->msg_type); + phdr->msg_length = le16_to_cpu((__force __le16)phdr->msg_length); + phdr->msg_flags = le16_to_cpu((__force __le16)phdr->msg_flags); #endif /* __BIG_ENDIAN */ } EXPORT_SYMBOL_GPL(smsendian_handle_message_header); diff --git a/drivers/media/dvb-core/dmxdev.c b/drivers/media/dvb-core/dmxdev.c index 61a750fae465..cb078d688c70 100644 --- a/drivers/media/dvb-core/dmxdev.c +++ b/drivers/media/dvb-core/dmxdev.c @@ -622,7 +622,7 @@ static int dvb_dmxdev_start_feed(struct dmxdev *dmxdev, struct dmxdev_filter *filter, struct dmxdev_feed *feed) { - ktime_t timeout = 0; + ktime_t timeout = ktime_set(0, 0); struct dmx_pes_filter_params *para = &filter->params.pes; enum dmx_output otype; int ret; diff --git a/drivers/media/dvb-core/dvb_frontend.c b/drivers/media/dvb-core/dvb_frontend.c index e33414975065..bc5eaad0f915 100644 --- a/drivers/media/dvb-core/dvb_frontend.c +++ b/drivers/media/dvb-core/dvb_frontend.c @@ -275,8 +275,20 @@ static void dvb_frontend_add_event(struct dvb_frontend *fe, wake_up_interruptible (&events->wait_queue); } +static int dvb_frontend_test_event(struct dvb_frontend_private *fepriv, + struct dvb_fe_events *events) +{ + int ret; + + up(&fepriv->sem); + ret = events->eventw != events->eventr; + down(&fepriv->sem); + + return ret; +} + static int dvb_frontend_get_event(struct dvb_frontend *fe, - struct dvb_frontend_event *event, int flags) + struct dvb_frontend_event *event, int flags) { struct dvb_frontend_private *fepriv = fe->frontend_priv; struct dvb_fe_events *events = &fepriv->events; @@ -294,13 +306,8 @@ static int dvb_frontend_get_event(struct dvb_frontend *fe, if (flags & O_NONBLOCK) return -EWOULDBLOCK; - up(&fepriv->sem); - - ret = wait_event_interruptible (events->wait_queue, - events->eventw != events->eventr); - - if (down_interruptible (&fepriv->sem)) - return -ERESTARTSYS; + ret = wait_event_interruptible(events->wait_queue, + dvb_frontend_test_event(fepriv, events)); if (ret < 0) return ret; @@ -973,7 +980,7 @@ static int dvb_frontend_clear_cache(struct dvb_frontend *fe) c->isdbt_sb_subchannel = 0; c->isdbt_sb_segment_idx = 0; c->isdbt_sb_segment_count = 0; - c->isdbt_layer_enabled = 0; + c->isdbt_layer_enabled = 7; /* All layers (A,B,C) */ for (i = 0; i < 3; i++) { c->layer[i].fec = FEC_AUTO; c->layer[i].modulation = QAM_AUTO; diff --git a/drivers/media/dvb-core/dvb_net.c b/drivers/media/dvb-core/dvb_net.c index ba39f9942e1d..10f78109bb3f 100644 --- a/drivers/media/dvb-core/dvb_net.c +++ b/drivers/media/dvb-core/dvb_net.c @@ -1005,7 +1005,7 @@ static int dvb_net_sec_callback(const u8 *buffer1, size_t buffer1_len, return 0; } -static int dvb_net_tx(struct sk_buff *skb, struct net_device *dev) +static netdev_tx_t dvb_net_tx(struct sk_buff *skb, struct net_device *dev) { dev_kfree_skb(skb); return NETDEV_TX_OK; diff --git a/drivers/media/dvb-frontends/Kconfig b/drivers/media/dvb-frontends/Kconfig index 0712069fd9fe..55e36a4f5215 100644 --- a/drivers/media/dvb-frontends/Kconfig +++ b/drivers/media/dvb-frontends/Kconfig @@ -903,7 +903,7 @@ comment "Common Interface (EN50221) controller drivers" depends on DVB_CORE config DVB_CXD2099 - tristate "CXD2099AR Common Interface driver" + tristate "Sony CXD2099AR Common Interface driver" depends on DVB_CORE && I2C select REGMAP_I2C default m if !MEDIA_SUBDRV_AUTOSELECT diff --git a/drivers/media/dvb-frontends/cx24116.c b/drivers/media/dvb-frontends/cx24116.c index 786c56a4ef76..2dbc7349d870 100644 --- a/drivers/media/dvb-frontends/cx24116.c +++ b/drivers/media/dvb-frontends/cx24116.c @@ -1456,7 +1456,7 @@ static int cx24116_tune(struct dvb_frontend *fe, bool re_tune, return cx24116_read_status(fe, status); } -static int cx24116_get_algo(struct dvb_frontend *fe) +static enum dvbfe_algo cx24116_get_algo(struct dvb_frontend *fe) { return DVBFE_ALGO_HW; } diff --git a/drivers/media/dvb-frontends/cx24117.c b/drivers/media/dvb-frontends/cx24117.c index 8935114b75f3..ba55d75d916c 100644 --- a/drivers/media/dvb-frontends/cx24117.c +++ b/drivers/media/dvb-frontends/cx24117.c @@ -1555,7 +1555,7 @@ static int cx24117_tune(struct dvb_frontend *fe, bool re_tune, return cx24117_read_status(fe, status); } -static int cx24117_get_algo(struct dvb_frontend *fe) +static enum dvbfe_algo cx24117_get_algo(struct dvb_frontend *fe) { return DVBFE_ALGO_HW; } diff --git a/drivers/media/dvb-frontends/cx24120.c b/drivers/media/dvb-frontends/cx24120.c index 810f68acd69b..ccbabdae6a69 100644 --- a/drivers/media/dvb-frontends/cx24120.c +++ b/drivers/media/dvb-frontends/cx24120.c @@ -1491,7 +1491,7 @@ static int cx24120_tune(struct dvb_frontend *fe, bool re_tune, return cx24120_read_status(fe, status); } -static int cx24120_get_algo(struct dvb_frontend *fe) +static enum dvbfe_algo cx24120_get_algo(struct dvb_frontend *fe) { return DVBFE_ALGO_HW; } diff --git a/drivers/media/dvb-frontends/cx24123.c b/drivers/media/dvb-frontends/cx24123.c index 228ba1f4bf63..bf33e7390aaf 100644 --- a/drivers/media/dvb-frontends/cx24123.c +++ b/drivers/media/dvb-frontends/cx24123.c @@ -1005,7 +1005,7 @@ static int cx24123_tune(struct dvb_frontend *fe, return retval; } -static int cx24123_get_algo(struct dvb_frontend *fe) +static enum dvbfe_algo cx24123_get_algo(struct dvb_frontend *fe) { return DVBFE_ALGO_HW; } diff --git a/drivers/media/dvb-frontends/cxd2099.c b/drivers/media/dvb-frontends/cxd2099.c index c0a5849b76bb..4a0ce3037fd6 100644 --- a/drivers/media/dvb-frontends/cxd2099.c +++ b/drivers/media/dvb-frontends/cxd2099.c @@ -1,5 +1,5 @@ /* - * cxd2099.c: Driver for the CXD2099AR Common Interface Controller + * cxd2099.c: Driver for the Sony CXD2099AR Common Interface Controller * * Copyright (C) 2010-2013 Digital Devices GmbH * @@ -699,6 +699,6 @@ static struct i2c_driver cxd2099_driver = { module_i2c_driver(cxd2099_driver); -MODULE_DESCRIPTION("CXD2099AR Common Interface controller driver"); +MODULE_DESCRIPTION("Sony CXD2099AR Common Interface controller driver"); MODULE_AUTHOR("Ralph Metzler"); MODULE_LICENSE("GPL"); diff --git a/drivers/media/dvb-frontends/cxd2099.h b/drivers/media/dvb-frontends/cxd2099.h index 8fa45a4c615a..ec1910dec3f3 100644 --- a/drivers/media/dvb-frontends/cxd2099.h +++ b/drivers/media/dvb-frontends/cxd2099.h @@ -1,5 +1,5 @@ /* - * cxd2099.h: Driver for the CXD2099AR Common Interface Controller + * cxd2099.h: Driver for the Sony CXD2099AR Common Interface Controller * * Copyright (C) 2010-2011 Digital Devices GmbH * diff --git a/drivers/media/dvb-frontends/cxd2820r_core.c b/drivers/media/dvb-frontends/cxd2820r_core.c index f6ebbb47b9b2..3e0d8cbd76da 100644 --- a/drivers/media/dvb-frontends/cxd2820r_core.c +++ b/drivers/media/dvb-frontends/cxd2820r_core.c @@ -403,7 +403,7 @@ error: return DVBFE_ALGO_SEARCH_ERROR; } -static int cxd2820r_get_frontend_algo(struct dvb_frontend *fe) +static enum dvbfe_algo cxd2820r_get_frontend_algo(struct dvb_frontend *fe) { return DVBFE_ALGO_CUSTOM; } diff --git a/drivers/media/dvb-frontends/cxd2880/cxd2880_tnrdmd_driver_version.h b/drivers/media/dvb-frontends/cxd2880/cxd2880_tnrdmd_driver_version.h index fab55038b37b..c6d6c8dd16a1 100644 --- a/drivers/media/dvb-frontends/cxd2880/cxd2880_tnrdmd_driver_version.h +++ b/drivers/media/dvb-frontends/cxd2880/cxd2880_tnrdmd_driver_version.h @@ -7,6 +7,6 @@ * Copyright (C) 2016, 2017, 2018 Sony Semiconductor Solutions Corporation */ -#define CXD2880_TNRDMD_DRIVER_VERSION "1.4.1 - 1.0.4" +#define CXD2880_TNRDMD_DRIVER_VERSION "1.4.1 - 1.0.5" -#define CXD2880_TNRDMD_DRIVER_RELEASE_DATE "2018-01-17" +#define CXD2880_TNRDMD_DRIVER_RELEASE_DATE "2018-04-25" diff --git a/drivers/media/dvb-frontends/cxd2880/cxd2880_top.c b/drivers/media/dvb-frontends/cxd2880/cxd2880_top.c index d474dc1b05da..bd9101e246d5 100644 --- a/drivers/media/dvb-frontends/cxd2880/cxd2880_top.c +++ b/drivers/media/dvb-frontends/cxd2880/cxd2880_top.c @@ -520,6 +520,15 @@ static int cxd2880_init(struct dvb_frontend *fe) pr_err("cxd2880 integ init failed %d\n", ret); return ret; } + + ret = cxd2880_tnrdmd_set_cfg(&priv->tnrdmd, + CXD2880_TNRDMD_CFG_TSPIN_CURRENT, + 0x00); + if (ret) { + mutex_unlock(priv->spi_mutex); + pr_err("cxd2880 set config failed %d\n", ret); + return ret; + } mutex_unlock(priv->spi_mutex); pr_debug("OK.\n"); @@ -1126,7 +1135,7 @@ static int cxd2880_get_stats(struct dvb_frontend *fe, priv = fe->demodulator_priv; c = &fe->dtv_property_cache; - if (!(status & FE_HAS_LOCK)) { + if (!(status & FE_HAS_LOCK) || !(status & FE_HAS_CARRIER)) { c->pre_bit_error.len = 1; c->pre_bit_error.stat[0].scale = FE_SCALE_NOT_AVAILABLE; c->pre_bit_count.len = 1; @@ -1345,7 +1354,8 @@ static int cxd2880_read_status(struct dvb_frontend *fe, pr_debug("status %d\n", *status); - if (priv->s == 0 && (*status & FE_HAS_LOCK)) { + if (priv->s == 0 && (*status & FE_HAS_LOCK) && + (*status & FE_HAS_CARRIER)) { mutex_lock(priv->spi_mutex); if (c->delivery_system == SYS_DVBT) { ret = cxd2880_set_ber_per_period_t(fe); diff --git a/drivers/media/dvb-frontends/dvb-pll.c b/drivers/media/dvb-frontends/dvb-pll.c index 5553b89b804e..e3894ff403d7 100644 --- a/drivers/media/dvb-frontends/dvb-pll.c +++ b/drivers/media/dvb-frontends/dvb-pll.c @@ -533,6 +533,45 @@ static const struct dvb_pll_desc dvb_pll_alps_tdee4 = { } }; +/* Infineon TUA6034 ISDB-T, used in Friio */ +/* CP cur. 50uA, AGC takeover: 103dBuV, PORT3 on */ +static const struct dvb_pll_desc dvb_pll_tua6034_friio = { + .name = "Infineon TUA6034 ISDB-T (Friio)", + .min = 90000000, + .max = 770000000, + .iffreq = 57000000, + .initdata = (u8[]){ 4, 0x9a, 0x50, 0xb2, 0x08 }, + .sleepdata = (u8[]){ 4, 0x9a, 0x70, 0xb3, 0x0b }, + .count = 3, + .entries = { + { 170000000, 142857, 0xba, 0x09 }, + { 470000000, 142857, 0xba, 0x0a }, + { 770000000, 142857, 0xb2, 0x08 }, + } +}; + +/* Philips TDA6651 ISDB-T, used in Earthsoft PT1 */ +static const struct dvb_pll_desc dvb_pll_tda665x_earth_pt1 = { + .name = "Philips TDA6651 ISDB-T (EarthSoft PT1)", + .min = 90000000, + .max = 770000000, + .iffreq = 57000000, + .initdata = (u8[]){ 5, 0x0e, 0x7f, 0xc1, 0x80, 0x80 }, + .count = 10, + .entries = { + { 140000000, 142857, 0xc1, 0x81 }, + { 170000000, 142857, 0xc1, 0xa1 }, + { 220000000, 142857, 0xc1, 0x62 }, + { 330000000, 142857, 0xc1, 0xa2 }, + { 402000000, 142857, 0xc1, 0xe2 }, + { 450000000, 142857, 0xc1, 0x64 }, + { 550000000, 142857, 0xc1, 0x84 }, + { 600000000, 142857, 0xc1, 0xa4 }, + { 700000000, 142857, 0xc1, 0xc4 }, + { 770000000, 142857, 0xc1, 0xe4 }, + } +}; + /* ----------------------------------------------------------- */ static const struct dvb_pll_desc *pll_list[] = { @@ -556,6 +595,8 @@ static const struct dvb_pll_desc *pll_list[] = { [DVB_PLL_SAMSUNG_TDTC9251DH0] = &dvb_pll_samsung_tdtc9251dh0, [DVB_PLL_SAMSUNG_TBDU18132] = &dvb_pll_samsung_tbdu18132, [DVB_PLL_SAMSUNG_TBMU24112] = &dvb_pll_samsung_tbmu24112, + [DVB_PLL_TUA6034_FRIIO] = &dvb_pll_tua6034_friio, + [DVB_PLL_TDA665X_EARTH_PT1] = &dvb_pll_tda665x_earth_pt1, }; /* ----------------------------------------------------------- */ @@ -827,6 +868,75 @@ struct dvb_frontend *dvb_pll_attach(struct dvb_frontend *fe, int pll_addr, } EXPORT_SYMBOL(dvb_pll_attach); + +static int +dvb_pll_probe(struct i2c_client *client, const struct i2c_device_id *id) +{ + struct dvb_pll_config *cfg; + struct dvb_frontend *fe; + unsigned int desc_id; + + cfg = client->dev.platform_data; + fe = cfg->fe; + i2c_set_clientdata(client, fe); + desc_id = (unsigned int) id->driver_data; + + if (!dvb_pll_attach(fe, client->addr, client->adapter, desc_id)) + return -ENOMEM; + + dev_info(&client->dev, "DVB Simple Tuner attached.\n"); + return 0; +} + +static int dvb_pll_remove(struct i2c_client *client) +{ + struct dvb_frontend *fe; + + fe = i2c_get_clientdata(client); + dvb_pll_release(fe); + return 0; +} + + +static const struct i2c_device_id dvb_pll_id[] = { + {"dtt7579", DVB_PLL_THOMSON_DTT7579}, + {"dtt759x", DVB_PLL_THOMSON_DTT759X}, + {"z201", DVB_PLL_LG_Z201}, + {"unknown_1", DVB_PLL_UNKNOWN_1}, + {"tua6010xs", DVB_PLL_TUA6010XS}, + {"env57h1xd5", DVB_PLL_ENV57H1XD5}, + {"tua6034", DVB_PLL_TUA6034}, + {"tda665x", DVB_PLL_TDA665X}, + {"tded4", DVB_PLL_TDED4}, + {"tdhu2", DVB_PLL_TDHU2}, + {"tbmv", DVB_PLL_SAMSUNG_TBMV}, + {"sd1878_tda8261", DVB_PLL_PHILIPS_SD1878_TDA8261}, + {"opera1", DVB_PLL_OPERA1}, + {"dtos403ih102a", DVB_PLL_SAMSUNG_DTOS403IH102A}, + {"tdtc9251dh0", DVB_PLL_SAMSUNG_TDTC9251DH0}, + {"tbdu18132", DVB_PLL_SAMSUNG_TBDU18132}, + {"tbmu24112", DVB_PLL_SAMSUNG_TBMU24112}, + {"tdee4", DVB_PLL_TDEE4}, + {"dtt7520x", DVB_PLL_THOMSON_DTT7520X}, + {"tua6034_friio", DVB_PLL_TUA6034_FRIIO}, + {"tda665x_earthpt1", DVB_PLL_TDA665X_EARTH_PT1}, + {} +}; + + +MODULE_DEVICE_TABLE(i2c, dvb_pll_id); + +static struct i2c_driver dvb_pll_driver = { + .driver = { + .name = "dvb_pll", + }, + .probe = dvb_pll_probe, + .remove = dvb_pll_remove, + .id_table = dvb_pll_id, +}; + +module_i2c_driver(dvb_pll_driver); + MODULE_DESCRIPTION("dvb pll library"); MODULE_AUTHOR("Gerd Knorr"); MODULE_LICENSE("GPL"); diff --git a/drivers/media/dvb-frontends/dvb-pll.h b/drivers/media/dvb-frontends/dvb-pll.h index ca885e71d2f0..973a66a82e27 100644 --- a/drivers/media/dvb-frontends/dvb-pll.h +++ b/drivers/media/dvb-frontends/dvb-pll.h @@ -29,6 +29,12 @@ #define DVB_PLL_SAMSUNG_TBMU24112 17 #define DVB_PLL_TDEE4 18 #define DVB_PLL_THOMSON_DTT7520X 19 +#define DVB_PLL_TUA6034_FRIIO 20 +#define DVB_PLL_TDA665X_EARTH_PT1 21 + +struct dvb_pll_config { + struct dvb_frontend *fe; +}; #if IS_REACHABLE(CONFIG_DVB_PLL) /** diff --git a/drivers/media/dvb-frontends/lgdt3306a.c b/drivers/media/dvb-frontends/lgdt3306a.c index 7eb4e1469d20..32de824476db 100644 --- a/drivers/media/dvb-frontends/lgdt3306a.c +++ b/drivers/media/dvb-frontends/lgdt3306a.c @@ -1784,7 +1784,7 @@ static int lgdt3306a_get_tune_settings(struct dvb_frontend *fe, return 0; } -static int lgdt3306a_search(struct dvb_frontend *fe) +static enum dvbfe_search lgdt3306a_search(struct dvb_frontend *fe) { enum fe_status status = 0; int ret; diff --git a/drivers/media/dvb-frontends/lgdt330x.c b/drivers/media/dvb-frontends/lgdt330x.c index 8ad03bd81af5..f6731738b073 100644 --- a/drivers/media/dvb-frontends/lgdt330x.c +++ b/drivers/media/dvb-frontends/lgdt330x.c @@ -47,50 +47,50 @@ static int debug; module_param(debug, int, 0644); -MODULE_PARM_DESC(debug,"Turn on/off lgdt330x frontend debugging (default:off)."); -#define dprintk(args...) \ -do { \ -if (debug) printk(KERN_DEBUG "lgdt330x: " args); \ +MODULE_PARM_DESC(debug, "Turn on/off lgdt330x frontend debugging (default:off)."); + +#define dprintk(state, fmt, arg...) do { \ + if (debug) \ + dev_printk(KERN_DEBUG, &state->client->dev, fmt, ##arg);\ } while (0) -struct lgdt330x_state -{ - struct i2c_adapter* i2c; +struct lgdt330x_state { + struct i2c_client *client; /* Configuration settings */ - const struct lgdt330x_config* config; + struct lgdt330x_config config; struct dvb_frontend frontend; /* Demodulator private data */ enum fe_modulation current_modulation; - u32 snr; /* Result of last SNR calculation */ + u32 snr; /* Result of last SNR calculation */ + u16 ucblocks; + unsigned long last_stats_time; /* Tuner private data */ u32 current_frequency; }; -static int i2c_write_demod_bytes (struct lgdt330x_state* state, - u8 *buf, /* data bytes to send */ - int len /* number of bytes to send */ ) +static int i2c_write_demod_bytes(struct lgdt330x_state *state, + const u8 *buf, /* data bytes to send */ + int len /* number of bytes to send */) { - struct i2c_msg msg = - { .addr = state->config->demod_address, - .flags = 0, - .buf = buf, - .len = 2 }; int i; int err; - for (i=0; i<len-1; i+=2){ - if ((err = i2c_transfer(state->i2c, &msg, 1)) != 1) { - printk(KERN_WARNING "lgdt330x: %s error (addr %02x <- %02x, err = %i)\n", __func__, msg.buf[0], msg.buf[1], err); + for (i = 0; i < len - 1; i += 2) { + err = i2c_master_send(state->client, buf, 2); + if (err != 2) { + dev_warn(&state->client->dev, + "%s: error (addr %02x <- %02x, err = %i)\n", + __func__, buf[0], buf[1], err); if (err < 0) return err; else return -EREMOTEIO; } - msg.buf += 2; + buf += 2; } return 0; } @@ -99,21 +99,30 @@ static int i2c_write_demod_bytes (struct lgdt330x_state* state, * This routine writes the register (reg) to the demod bus * then reads the data returned for (len) bytes. */ - static int i2c_read_demod_bytes(struct lgdt330x_state *state, enum I2C_REG reg, u8 *buf, int len) { - u8 wr [] = { reg }; - struct i2c_msg msg [] = { - { .addr = state->config->demod_address, - .flags = 0, .buf = wr, .len = 1 }, - { .addr = state->config->demod_address, - .flags = I2C_M_RD, .buf = buf, .len = len }, + u8 wr[] = { reg }; + struct i2c_msg msg[] = { + { + .addr = state->client->addr, + .flags = 0, + .buf = wr, + .len = 1 + }, { + .addr = state->client->addr, + .flags = I2C_M_RD, + .buf = buf, + .len = len + }, }; int ret; - ret = i2c_transfer(state->i2c, msg, 2); + + ret = i2c_transfer(state->client->adapter, msg, 2); if (ret != 2) { - printk(KERN_WARNING "lgdt330x: %s: addr 0x%02x select 0x%02x error (ret == %i)\n", __func__, state->config->demod_address, reg, ret); + dev_warn(&state->client->dev, + "%s: addr 0x%02x select 0x%02x error (ret == %i)\n", + __func__, state->client->addr, reg, ret); if (ret >= 0) ret = -EIO; } else { @@ -123,19 +132,21 @@ static int i2c_read_demod_bytes(struct lgdt330x_state *state, } /* Software reset */ -static int lgdt3302_SwReset(struct lgdt330x_state* state) +static int lgdt3302_sw_reset(struct lgdt330x_state *state) { u8 ret; u8 reset[] = { IRQ_MASK, - 0x00 /* bit 6 is active low software reset - * bits 5-0 are 1 to mask interrupts */ + /* + * bit 6 is active low software reset + * bits 5-0 are 1 to mask interrupts + */ + 0x00 }; ret = i2c_write_demod_bytes(state, reset, sizeof(reset)); if (ret == 0) { - /* force reset high (inactive) and unmask interrupts */ reset[1] = 0x7f; ret = i2c_write_demod_bytes(state, @@ -144,7 +155,7 @@ static int lgdt3302_SwReset(struct lgdt330x_state* state) return ret; } -static int lgdt3303_SwReset(struct lgdt330x_state* state) +static int lgdt3303_sw_reset(struct lgdt330x_state *state) { u8 ret; u8 reset[] = { @@ -155,7 +166,6 @@ static int lgdt3303_SwReset(struct lgdt330x_state* state) ret = i2c_write_demod_bytes(state, reset, sizeof(reset)); if (ret == 0) { - /* force reset high (inactive) */ reset[1] = 0x01; ret = i2c_write_demod_bytes(state, @@ -164,81 +174,94 @@ static int lgdt3303_SwReset(struct lgdt330x_state* state) return ret; } -static int lgdt330x_SwReset(struct lgdt330x_state* state) +static int lgdt330x_sw_reset(struct lgdt330x_state *state) { - switch (state->config->demod_chip) { + switch (state->config.demod_chip) { case LGDT3302: - return lgdt3302_SwReset(state); + return lgdt3302_sw_reset(state); case LGDT3303: - return lgdt3303_SwReset(state); + return lgdt3303_sw_reset(state); default: return -ENODEV; } } -static int lgdt330x_init(struct dvb_frontend* fe) +static int lgdt330x_init(struct dvb_frontend *fe) { - /* Hardware reset is done using gpio[0] of cx23880x chip. - * I'd like to do it here, but don't know how to find chip address. - * cx88-cards.c arranges for the reset bit to be inactive (high). - * Maybe there needs to be a callable function in cx88-core or - * the caller of this function needs to do it. */ - + struct lgdt330x_state *state = fe->demodulator_priv; + struct dtv_frontend_properties *p = &fe->dtv_property_cache; + char *chip_name; + int err; /* * Array of byte pairs <address, value> * to initialize each different chip */ - static u8 lgdt3302_init_data[] = { - /* Use 50MHz parameter values from spec sheet since xtal is 50 */ - /* Change the value of NCOCTFV[25:0] of carrier - recovery center frequency register */ + static const u8 lgdt3302_init_data[] = { + /* Use 50MHz param values from spec sheet since xtal is 50 */ + /* + * Change the value of NCOCTFV[25:0] of carrier + * recovery center frequency register + */ VSB_CARRIER_FREQ0, 0x00, VSB_CARRIER_FREQ1, 0x87, VSB_CARRIER_FREQ2, 0x8e, VSB_CARRIER_FREQ3, 0x01, - /* Change the TPCLK pin polarity - data is valid on falling clock */ + /* + * Change the TPCLK pin polarity + * data is valid on falling clock + */ DEMUX_CONTROL, 0xfb, - /* Change the value of IFBW[11:0] of - AGC IF/RF loop filter bandwidth register */ + /* + * Change the value of IFBW[11:0] of + * AGC IF/RF loop filter bandwidth register + */ AGC_RF_BANDWIDTH0, 0x40, AGC_RF_BANDWIDTH1, 0x93, AGC_RF_BANDWIDTH2, 0x00, - /* Change the value of bit 6, 'nINAGCBY' and - 'NSSEL[1:0] of ACG function control register 2 */ + /* + * Change the value of bit 6, 'nINAGCBY' and + * 'NSSEL[1:0] of ACG function control register 2 + */ AGC_FUNC_CTRL2, 0xc6, - /* Change the value of bit 6 'RFFIX' - of AGC function control register 3 */ + /* + * Change the value of bit 6 'RFFIX' + * of AGC function control register 3 + */ AGC_FUNC_CTRL3, 0x40, - /* Set the value of 'INLVTHD' register 0x2a/0x2c - to 0x7fe */ + /* + * Set the value of 'INLVTHD' register 0x2a/0x2c + * to 0x7fe + */ AGC_DELAY0, 0x07, AGC_DELAY2, 0xfe, - /* Change the value of IAGCBW[15:8] - of inner AGC loop filter bandwidth */ + /* + * Change the value of IAGCBW[15:8] + * of inner AGC loop filter bandwidth + */ AGC_LOOP_BANDWIDTH0, 0x08, AGC_LOOP_BANDWIDTH1, 0x9a }; - - static u8 lgdt3303_init_data[] = { + static const u8 lgdt3303_init_data[] = { 0x4c, 0x14 }; - - static u8 flip_1_lgdt3303_init_data[] = { + static const u8 flip_1_lgdt3303_init_data[] = { 0x4c, 0x14, 0x87, 0xf3 }; - - static u8 flip_2_lgdt3303_init_data[] = { + static const u8 flip_2_lgdt3303_init_data[] = { 0x4c, 0x14, 0x87, 0xda }; - struct lgdt330x_state* state = fe->demodulator_priv; - char *chip_name; - int err; + /* + * Hardware reset is done using gpio[0] of cx23880x chip. + * I'd like to do it here, but don't know how to find chip address. + * cx88-cards.c arranges for the reset bit to be inactive (high). + * Maybe there needs to be a callable function in cx88-core or + * the caller of this function needs to do it. + */ - switch (state->config->demod_chip) { + switch (state->config.demod_chip) { case LGDT3302: chip_name = "LGDT3302"; err = i2c_write_demod_bytes(state, lgdt3302_init_data, @@ -246,16 +269,16 @@ static int lgdt330x_init(struct dvb_frontend* fe) break; case LGDT3303: chip_name = "LGDT3303"; - switch (state->config->clock_polarity_flip) { + switch (state->config.clock_polarity_flip) { case 2: err = i2c_write_demod_bytes(state, - flip_2_lgdt3303_init_data, - sizeof(flip_2_lgdt3303_init_data)); + flip_2_lgdt3303_init_data, + sizeof(flip_2_lgdt3303_init_data)); break; case 1: err = i2c_write_demod_bytes(state, - flip_1_lgdt3303_init_data, - sizeof(flip_1_lgdt3303_init_data)); + flip_1_lgdt3303_init_data, + sizeof(flip_1_lgdt3303_init_data)); break; case 0: default: @@ -265,70 +288,55 @@ static int lgdt330x_init(struct dvb_frontend* fe) break; default: chip_name = "undefined"; - printk (KERN_WARNING "Only LGDT3302 and LGDT3303 are supported chips.\n"); + dev_warn(&state->client->dev, + "Only LGDT3302 and LGDT3303 are supported chips.\n"); err = -ENODEV; } - dprintk("%s entered as %s\n", __func__, chip_name); + dprintk(state, "Initialized the %s chip\n", chip_name); if (err < 0) return err; - return lgdt330x_SwReset(state); -} -static int lgdt330x_read_ber(struct dvb_frontend* fe, u32* ber) -{ - *ber = 0; /* Not supplied by the demod chips */ - return 0; + p->cnr.len = 1; + p->cnr.stat[0].scale = FE_SCALE_NOT_AVAILABLE; + p->block_error.len = 1; + p->block_error.stat[0].scale = FE_SCALE_NOT_AVAILABLE; + p->block_count.len = 1; + p->block_count.stat[0].scale = FE_SCALE_NOT_AVAILABLE; + state->last_stats_time = 0; + + return lgdt330x_sw_reset(state); } -static int lgdt330x_read_ucblocks(struct dvb_frontend* fe, u32* ucblocks) +static int lgdt330x_read_ucblocks(struct dvb_frontend *fe, u32 *ucblocks) { - struct lgdt330x_state* state = fe->demodulator_priv; - int err; - u8 buf[2]; + struct lgdt330x_state *state = fe->demodulator_priv; - *ucblocks = 0; + *ucblocks = state->ucblocks; - switch (state->config->demod_chip) { - case LGDT3302: - err = i2c_read_demod_bytes(state, LGDT3302_PACKET_ERR_COUNTER1, - buf, sizeof(buf)); - break; - case LGDT3303: - err = i2c_read_demod_bytes(state, LGDT3303_PACKET_ERR_COUNTER1, - buf, sizeof(buf)); - break; - default: - printk(KERN_WARNING - "Only LGDT3302 and LGDT3303 are supported chips.\n"); - err = -ENODEV; - } - if (err < 0) - return err; - - *ucblocks = (buf[0] << 8) | buf[1]; return 0; } static int lgdt330x_set_parameters(struct dvb_frontend *fe) { struct dtv_frontend_properties *p = &fe->dtv_property_cache; + struct lgdt330x_state *state = fe->demodulator_priv; /* * Array of byte pairs <address, value> * to initialize 8VSB for lgdt3303 chip 50 MHz IF */ - static u8 lgdt3303_8vsb_44_data[] = { + static const u8 lgdt3303_8vsb_44_data[] = { 0x04, 0x00, 0x0d, 0x40, 0x0e, 0x87, 0x0f, 0x8e, 0x10, 0x01, - 0x47, 0x8b }; - + 0x47, 0x8b + }; /* * Array of byte pairs <address, value> * to initialize QAM for lgdt3303 chip */ - static u8 lgdt3303_qam_data[] = { + static const u8 lgdt3303_qam_data[] = { 0x04, 0x00, 0x0d, 0x00, 0x0e, 0x00, @@ -339,98 +347,105 @@ static int lgdt330x_set_parameters(struct dvb_frontend *fe) 0x48, 0x66, 0x4d, 0x1a, 0x49, 0x08, - 0x4a, 0x9b }; - - struct lgdt330x_state* state = fe->demodulator_priv; - - static u8 top_ctrl_cfg[] = { TOP_CONTROL, 0x03 }; + 0x4a, 0x9b + }; + u8 top_ctrl_cfg[] = { TOP_CONTROL, 0x03 }; int err = 0; /* Change only if we are actually changing the modulation */ if (state->current_modulation != p->modulation) { switch (p->modulation) { case VSB_8: - dprintk("%s: VSB_8 MODE\n", __func__); + dprintk(state, "VSB_8 MODE\n"); /* Select VSB mode */ top_ctrl_cfg[1] = 0x03; /* Select ANT connector if supported by card */ - if (state->config->pll_rf_set) - state->config->pll_rf_set(fe, 1); + if (state->config.pll_rf_set) + state->config.pll_rf_set(fe, 1); - if (state->config->demod_chip == LGDT3303) { - err = i2c_write_demod_bytes(state, lgdt3303_8vsb_44_data, + if (state->config.demod_chip == LGDT3303) { + err = i2c_write_demod_bytes(state, + lgdt3303_8vsb_44_data, sizeof(lgdt3303_8vsb_44_data)); } break; case QAM_64: - dprintk("%s: QAM_64 MODE\n", __func__); + dprintk(state, "QAM_64 MODE\n"); /* Select QAM_64 mode */ top_ctrl_cfg[1] = 0x00; /* Select CABLE connector if supported by card */ - if (state->config->pll_rf_set) - state->config->pll_rf_set(fe, 0); + if (state->config.pll_rf_set) + state->config.pll_rf_set(fe, 0); - if (state->config->demod_chip == LGDT3303) { - err = i2c_write_demod_bytes(state, lgdt3303_qam_data, - sizeof(lgdt3303_qam_data)); + if (state->config.demod_chip == LGDT3303) { + err = i2c_write_demod_bytes(state, + lgdt3303_qam_data, + sizeof(lgdt3303_qam_data)); } break; case QAM_256: - dprintk("%s: QAM_256 MODE\n", __func__); + dprintk(state, "QAM_256 MODE\n"); /* Select QAM_256 mode */ top_ctrl_cfg[1] = 0x01; /* Select CABLE connector if supported by card */ - if (state->config->pll_rf_set) - state->config->pll_rf_set(fe, 0); + if (state->config.pll_rf_set) + state->config.pll_rf_set(fe, 0); - if (state->config->demod_chip == LGDT3303) { - err = i2c_write_demod_bytes(state, lgdt3303_qam_data, - sizeof(lgdt3303_qam_data)); + if (state->config.demod_chip == LGDT3303) { + err = i2c_write_demod_bytes(state, + lgdt3303_qam_data, + sizeof(lgdt3303_qam_data)); } break; default: - printk(KERN_WARNING "lgdt330x: %s: Modulation type(%d) UNSUPPORTED\n", __func__, p->modulation); + dev_warn(&state->client->dev, + "%s: Modulation type(%d) UNSUPPORTED\n", + __func__, p->modulation); return -1; } if (err < 0) - printk(KERN_WARNING "lgdt330x: %s: error blasting bytes to lgdt3303 for modulation type(%d)\n", - __func__, p->modulation); + dev_warn(&state->client->dev, + "%s: error blasting bytes to lgdt3303 for modulation type(%d)\n", + __func__, p->modulation); /* - * select serial or parallel MPEG harware interface + * select serial or parallel MPEG hardware interface * Serial: 0x04 for LGDT3302 or 0x40 for LGDT3303 * Parallel: 0x00 */ - top_ctrl_cfg[1] |= state->config->serial_mpeg; + top_ctrl_cfg[1] |= state->config.serial_mpeg; /* Select the requested mode */ i2c_write_demod_bytes(state, top_ctrl_cfg, sizeof(top_ctrl_cfg)); - if (state->config->set_ts_params) - state->config->set_ts_params(fe, 0); + if (state->config.set_ts_params) + state->config.set_ts_params(fe, 0); state->current_modulation = p->modulation; } /* Tune to the specified frequency */ if (fe->ops.tuner_ops.set_params) { fe->ops.tuner_ops.set_params(fe); - if (fe->ops.i2c_gate_ctrl) fe->ops.i2c_gate_ctrl(fe, 0); + if (fe->ops.i2c_gate_ctrl) + fe->ops.i2c_gate_ctrl(fe, 0); } /* Keep track of the new frequency */ - /* FIXME this is the wrong way to do this... */ - /* The tuner is shared with the video4linux analog API */ + /* + * FIXME this is the wrong way to do this... + * The tuner is shared with the video4linux analog API + */ state->current_frequency = p->frequency; - lgdt330x_SwReset(state); + lgdt330x_sw_reset(state); return 0; } @@ -443,20 +458,191 @@ static int lgdt330x_get_frontend(struct dvb_frontend *fe, return 0; } +/* + * Calculate SNR estimation (scaled by 2^24) + * + * 8-VSB SNR equations from LGDT3302 and LGDT3303 datasheets, QAM + * equations from LGDT3303 datasheet. VSB is the same between the '02 + * and '03, so maybe QAM is too? Perhaps someone with a newer datasheet + * that has QAM information could verify? + * + * For 8-VSB: (two ways, take your pick) + * LGDT3302: + * SNR_EQ = 10 * log10(25 * 24^2 / EQ_MSE) + * LGDT3303: + * SNR_EQ = 10 * log10(25 * 32^2 / EQ_MSE) + * LGDT3302 & LGDT3303: + * SNR_PT = 10 * log10(25 * 32^2 / PT_MSE) (we use this one) + * For 64-QAM: + * SNR = 10 * log10( 688128 / MSEQAM) + * For 256-QAM: + * SNR = 10 * log10( 696320 / MSEQAM) + * + * We re-write the snr equation as: + * SNR * 2^24 = 10*(c - intlog10(MSE)) + * Where for 256-QAM, c = log10(696320) * 2^24, and so on. + */ +static u32 calculate_snr(u32 mse, u32 c) +{ + if (mse == 0) /* No signal */ + return 0; + + mse = intlog10(mse); + if (mse > c) { + /* + * Negative SNR, which is possible, but realisticly the + * demod will lose lock before the signal gets this bad. + * The API only allows for unsigned values, so just return 0 + */ + return 0; + } + return 10 * (c - mse); +} + +static int lgdt3302_read_snr(struct dvb_frontend *fe) +{ + struct lgdt330x_state *state = fe->demodulator_priv; + u8 buf[5]; /* read data buffer */ + u32 noise; /* noise value */ + u32 c; /* per-modulation SNR calculation constant */ + + switch (state->current_modulation) { + case VSB_8: + i2c_read_demod_bytes(state, LGDT3302_EQPH_ERR0, buf, 5); +#ifdef USE_EQMSE + /* Use Equalizer Mean-Square Error Register */ + /* SNR for ranges from -15.61 to +41.58 */ + noise = ((buf[0] & 7) << 16) | (buf[1] << 8) | buf[2]; + c = 69765745; /* log10(25*24^2)*2^24 */ +#else + /* Use Phase Tracker Mean-Square Error Register */ + /* SNR for ranges from -13.11 to +44.08 */ + noise = ((buf[0] & 7 << 3) << 13) | (buf[3] << 8) | buf[4]; + c = 73957994; /* log10(25*32^2)*2^24 */ +#endif + break; + case QAM_64: + case QAM_256: + i2c_read_demod_bytes(state, CARRIER_MSEQAM1, buf, 2); + noise = ((buf[0] & 3) << 8) | buf[1]; + c = state->current_modulation == QAM_64 ? 97939837 : 98026066; + /* log10(688128)*2^24 and log10(696320)*2^24 */ + break; + default: + dev_err(&state->client->dev, + "%s: Modulation set to unsupported value\n", + __func__); + + state->snr = 0; + + return -EREMOTEIO; /* return -EDRIVER_IS_GIBBERED; */ + } + + state->snr = calculate_snr(noise, c); + + dprintk(state, "noise = 0x%08x, snr = %d.%02d dB\n", noise, + state->snr >> 24, (((state->snr >> 8) & 0xffff) * 100) >> 16); + + return 0; +} + +static int lgdt3303_read_snr(struct dvb_frontend *fe) +{ + struct lgdt330x_state *state = fe->demodulator_priv; + u8 buf[5]; /* read data buffer */ + u32 noise; /* noise value */ + u32 c; /* per-modulation SNR calculation constant */ + + switch (state->current_modulation) { + case VSB_8: + i2c_read_demod_bytes(state, LGDT3303_EQPH_ERR0, buf, 5); +#ifdef USE_EQMSE + /* Use Equalizer Mean-Square Error Register */ + /* SNR for ranges from -16.12 to +44.08 */ + noise = ((buf[0] & 0x78) << 13) | (buf[1] << 8) | buf[2]; + c = 73957994; /* log10(25*32^2)*2^24 */ +#else + /* Use Phase Tracker Mean-Square Error Register */ + /* SNR for ranges from -13.11 to +44.08 */ + noise = ((buf[0] & 7) << 16) | (buf[3] << 8) | buf[4]; + c = 73957994; /* log10(25*32^2)*2^24 */ +#endif + break; + case QAM_64: + case QAM_256: + i2c_read_demod_bytes(state, CARRIER_MSEQAM1, buf, 2); + noise = (buf[0] << 8) | buf[1]; + c = state->current_modulation == QAM_64 ? 97939837 : 98026066; + /* log10(688128)*2^24 and log10(696320)*2^24 */ + break; + default: + dev_err(&state->client->dev, + "%s: Modulation set to unsupported value\n", + __func__); + state->snr = 0; + return -EREMOTEIO; /* return -EDRIVER_IS_GIBBERED; */ + } + + state->snr = calculate_snr(noise, c); + + dprintk(state, "noise = 0x%08x, snr = %d.%02d dB\n", noise, + state->snr >> 24, (((state->snr >> 8) & 0xffff) * 100) >> 16); + + return 0; +} + +static int lgdt330x_read_snr(struct dvb_frontend *fe, u16 *snr) +{ + struct lgdt330x_state *state = fe->demodulator_priv; + + *snr = (state->snr) >> 16; /* Convert from 8.24 fixed-point to 8.8 */ + + return 0; +} + +static int lgdt330x_read_signal_strength(struct dvb_frontend *fe, u16 *strength) +{ + /* Calculate Strength from SNR up to 35dB */ + /* + * Even though the SNR can go higher than 35dB, there is some comfort + * factor in having a range of strong signals that can show at 100% + */ + struct lgdt330x_state *state = fe->demodulator_priv; + u16 snr; + int ret; + + ret = fe->ops.read_snr(fe, &snr); + if (ret != 0) + return ret; + /* Rather than use the 8.8 value snr, use state->snr which is 8.24 */ + /* scale the range 0 - 35*2^24 into 0 - 65535 */ + if (state->snr >= 8960 * 0x10000) + *strength = 0xffff; + else + *strength = state->snr / 8960; + + return 0; +} + + static int lgdt3302_read_status(struct dvb_frontend *fe, enum fe_status *status) { - struct lgdt330x_state* state = fe->demodulator_priv; + struct lgdt330x_state *state = fe->demodulator_priv; + struct dtv_frontend_properties *p = &fe->dtv_property_cache; u8 buf[3]; + int err; *status = 0; /* Reset status result */ /* AGC status register */ i2c_read_demod_bytes(state, AGC_STATUS, buf, 1); - dprintk("%s: AGC_STATUS = 0x%02x\n", __func__, buf[0]); - if ((buf[0] & 0x0c) == 0x8){ - /* Test signal does not exist flag */ - /* as well as the AGC lock flag. */ + dprintk(state, "AGC_STATUS = 0x%02x\n", buf[0]); + if ((buf[0] & 0x0c) == 0x8) { + /* + * Test signal does not exist flag + * as well as the AGC lock flag. + */ *status |= FE_HAS_SIGNAL; } @@ -465,25 +651,24 @@ static int lgdt3302_read_status(struct dvb_frontend *fe, * to see that status bit in the IRQ_STATUS register. * This is done in SwReset(); */ + /* signal status */ i2c_read_demod_bytes(state, TOP_CONTROL, buf, sizeof(buf)); - dprintk("%s: TOP_CONTROL = 0x%02x, IRO_MASK = 0x%02x, IRQ_STATUS = 0x%02x\n", __func__, buf[0], buf[1], buf[2]); - + dprintk(state, + "TOP_CONTROL = 0x%02x, IRO_MASK = 0x%02x, IRQ_STATUS = 0x%02x\n", + buf[0], buf[1], buf[2]); /* sync status */ - if ((buf[2] & 0x03) == 0x01) { + if ((buf[2] & 0x03) == 0x01) *status |= FE_HAS_SYNC; - } /* FEC error status */ - if ((buf[2] & 0x0c) == 0x08) { - *status |= FE_HAS_LOCK; - *status |= FE_HAS_VITERBI; - } + if ((buf[2] & 0x0c) == 0x08) + *status |= FE_HAS_LOCK | FE_HAS_VITERBI; /* Carrier Recovery Lock Status Register */ i2c_read_demod_bytes(state, CARRIER_LOCK, buf, 1); - dprintk("%s: CARRIER_LOCK = 0x%02x\n", __func__, buf[0]); + dprintk(state, "CARRIER_LOCK = 0x%02x\n", buf[0]); switch (state->current_modulation) { case QAM_256: case QAM_64: @@ -496,7 +681,48 @@ static int lgdt3302_read_status(struct dvb_frontend *fe, *status |= FE_HAS_CARRIER; break; default: - printk(KERN_WARNING "lgdt330x: %s: Modulation set to unsupported value\n", __func__); + dev_warn(&state->client->dev, + "%s: Modulation set to unsupported value\n", + __func__); + } + + if (!(*status & FE_HAS_LOCK)) { + p->cnr.stat[0].scale = FE_SCALE_NOT_AVAILABLE; + p->block_error.stat[0].scale = FE_SCALE_NOT_AVAILABLE; + p->block_count.stat[0].scale = FE_SCALE_NOT_AVAILABLE; + return 0; + } + + if (state->last_stats_time && + time_is_after_jiffies(state->last_stats_time)) + return 0; + + state->last_stats_time = jiffies + msecs_to_jiffies(1000); + + err = lgdt3302_read_snr(fe); + if (!err) { + p->cnr.stat[0].scale = FE_SCALE_DECIBEL; + p->cnr.stat[0].svalue = (((u64)state->snr) * 1000) >> 24; + } else { + p->cnr.stat[0].scale = FE_SCALE_NOT_AVAILABLE; + } + + err = i2c_read_demod_bytes(state, LGDT3302_PACKET_ERR_COUNTER1, + buf, sizeof(buf)); + if (!err) { + state->ucblocks = (buf[0] << 8) | buf[1]; + + dprintk(state, "UCB = 0x%02x\n", state->ucblocks); + + p->block_error.stat[0].uvalue += state->ucblocks; + /* FIXME: what's the basis for block count */ + p->block_count.stat[0].uvalue += 10000; + + p->block_error.stat[0].scale = FE_SCALE_COUNTER; + p->block_count.stat[0].scale = FE_SCALE_COUNTER; + } else { + p->block_error.stat[0].scale = FE_SCALE_NOT_AVAILABLE; + p->block_count.stat[0].scale = FE_SCALE_NOT_AVAILABLE; } return 0; @@ -505,9 +731,10 @@ static int lgdt3302_read_status(struct dvb_frontend *fe, static int lgdt3303_read_status(struct dvb_frontend *fe, enum fe_status *status) { - struct lgdt330x_state* state = fe->demodulator_priv; - int err; + struct lgdt330x_state *state = fe->demodulator_priv; + struct dtv_frontend_properties *p = &fe->dtv_property_cache; u8 buf[3]; + int err; *status = 0; /* Reset status result */ @@ -516,16 +743,18 @@ static int lgdt3303_read_status(struct dvb_frontend *fe, if (err < 0) return err; - dprintk("%s: AGC_STATUS = 0x%02x\n", __func__, buf[0]); - if ((buf[0] & 0x21) == 0x01){ - /* Test input signal does not exist flag */ - /* as well as the AGC lock flag. */ + dprintk(state, "AGC_STATUS = 0x%02x\n", buf[0]); + if ((buf[0] & 0x21) == 0x01) { + /* + * Test input signal does not exist flag + * as well as the AGC lock flag. + */ *status |= FE_HAS_SIGNAL; } /* Carrier Recovery Lock Status Register */ i2c_read_demod_bytes(state, CARRIER_LOCK, buf, 1); - dprintk("%s: CARRIER_LOCK = 0x%02x\n", __func__, buf[0]); + dprintk(state, "CARRIER_LOCK = 0x%02x\n", buf[0]); switch (state->current_modulation) { case QAM_256: case QAM_64: @@ -535,6 +764,8 @@ static int lgdt3303_read_status(struct dvb_frontend *fe, else break; i2c_read_demod_bytes(state, 0x8a, buf, 1); + dprintk(state, "QAM LOCK = 0x%02x\n", buf[0]); + if ((buf[0] & 0x04) == 0x04) *status |= FE_HAS_SYNC; if ((buf[0] & 0x01) == 0x01) @@ -548,168 +779,64 @@ static int lgdt3303_read_status(struct dvb_frontend *fe, else break; i2c_read_demod_bytes(state, 0x38, buf, 1); + dprintk(state, "8-VSB LOCK = 0x%02x\n", buf[0]); + if ((buf[0] & 0x02) == 0x00) *status |= FE_HAS_SYNC; - if ((buf[0] & 0x01) == 0x01) { - *status |= FE_HAS_LOCK; - *status |= FE_HAS_VITERBI; - } + if ((buf[0] & 0xfd) == 0x01) + *status |= FE_HAS_VITERBI | FE_HAS_LOCK; break; default: - printk(KERN_WARNING "lgdt330x: %s: Modulation set to unsupported value\n", __func__); + dev_warn(&state->client->dev, + "%s: Modulation set to unsupported value\n", + __func__); } - return 0; -} - -/* Calculate SNR estimation (scaled by 2^24) - - 8-VSB SNR equations from LGDT3302 and LGDT3303 datasheets, QAM - equations from LGDT3303 datasheet. VSB is the same between the '02 - and '03, so maybe QAM is too? Perhaps someone with a newer datasheet - that has QAM information could verify? - - For 8-VSB: (two ways, take your pick) - LGDT3302: - SNR_EQ = 10 * log10(25 * 24^2 / EQ_MSE) - LGDT3303: - SNR_EQ = 10 * log10(25 * 32^2 / EQ_MSE) - LGDT3302 & LGDT3303: - SNR_PT = 10 * log10(25 * 32^2 / PT_MSE) (we use this one) - For 64-QAM: - SNR = 10 * log10( 688128 / MSEQAM) - For 256-QAM: - SNR = 10 * log10( 696320 / MSEQAM) - - We re-write the snr equation as: - SNR * 2^24 = 10*(c - intlog10(MSE)) - Where for 256-QAM, c = log10(696320) * 2^24, and so on. */ -static u32 calculate_snr(u32 mse, u32 c) -{ - if (mse == 0) /* No signal */ + if (!(*status & FE_HAS_LOCK)) { + p->cnr.stat[0].scale = FE_SCALE_NOT_AVAILABLE; + p->block_error.stat[0].scale = FE_SCALE_NOT_AVAILABLE; + p->block_count.stat[0].scale = FE_SCALE_NOT_AVAILABLE; return 0; + } - mse = intlog10(mse); - if (mse > c) { - /* Negative SNR, which is possible, but realisticly the - demod will lose lock before the signal gets this bad. The - API only allows for unsigned values, so just return 0 */ + if (state->last_stats_time && + time_is_after_jiffies(state->last_stats_time)) return 0; - } - return 10*(c - mse); -} -static int lgdt3302_read_snr(struct dvb_frontend* fe, u16* snr) -{ - struct lgdt330x_state* state = (struct lgdt330x_state*) fe->demodulator_priv; - u8 buf[5]; /* read data buffer */ - u32 noise; /* noise value */ - u32 c; /* per-modulation SNR calculation constant */ + state->last_stats_time = jiffies + msecs_to_jiffies(1000); - switch(state->current_modulation) { - case VSB_8: - i2c_read_demod_bytes(state, LGDT3302_EQPH_ERR0, buf, 5); -#ifdef USE_EQMSE - /* Use Equalizer Mean-Square Error Register */ - /* SNR for ranges from -15.61 to +41.58 */ - noise = ((buf[0] & 7) << 16) | (buf[1] << 8) | buf[2]; - c = 69765745; /* log10(25*24^2)*2^24 */ -#else - /* Use Phase Tracker Mean-Square Error Register */ - /* SNR for ranges from -13.11 to +44.08 */ - noise = ((buf[0] & 7<<3) << 13) | (buf[3] << 8) | buf[4]; - c = 73957994; /* log10(25*32^2)*2^24 */ -#endif - break; - case QAM_64: - case QAM_256: - i2c_read_demod_bytes(state, CARRIER_MSEQAM1, buf, 2); - noise = ((buf[0] & 3) << 8) | buf[1]; - c = state->current_modulation == QAM_64 ? 97939837 : 98026066; - /* log10(688128)*2^24 and log10(696320)*2^24 */ - break; - default: - printk(KERN_ERR "lgdt330x: %s: Modulation set to unsupported value\n", - __func__); - return -EREMOTEIO; /* return -EDRIVER_IS_GIBBERED; */ + err = lgdt3303_read_snr(fe); + if (!err) { + p->cnr.stat[0].scale = FE_SCALE_DECIBEL; + p->cnr.stat[0].svalue = (((u64)state->snr) * 1000) >> 24; + } else { + p->cnr.stat[0].scale = FE_SCALE_NOT_AVAILABLE; } - state->snr = calculate_snr(noise, c); - *snr = (state->snr) >> 16; /* Convert from 8.24 fixed-point to 8.8 */ - - dprintk("%s: noise = 0x%08x, snr = %d.%02d dB\n", __func__, noise, - state->snr >> 24, (((state->snr>>8) & 0xffff) * 100) >> 16); + err = i2c_read_demod_bytes(state, LGDT3303_PACKET_ERR_COUNTER1, + buf, sizeof(buf)); + if (!err) { + state->ucblocks = (buf[0] << 8) | buf[1]; - return 0; -} + dprintk(state, "UCB = 0x%02x\n", state->ucblocks); -static int lgdt3303_read_snr(struct dvb_frontend* fe, u16* snr) -{ - struct lgdt330x_state* state = (struct lgdt330x_state*) fe->demodulator_priv; - u8 buf[5]; /* read data buffer */ - u32 noise; /* noise value */ - u32 c; /* per-modulation SNR calculation constant */ + p->block_error.stat[0].uvalue += state->ucblocks; + /* FIXME: what's the basis for block count */ + p->block_count.stat[0].uvalue += 10000; - switch(state->current_modulation) { - case VSB_8: - i2c_read_demod_bytes(state, LGDT3303_EQPH_ERR0, buf, 5); -#ifdef USE_EQMSE - /* Use Equalizer Mean-Square Error Register */ - /* SNR for ranges from -16.12 to +44.08 */ - noise = ((buf[0] & 0x78) << 13) | (buf[1] << 8) | buf[2]; - c = 73957994; /* log10(25*32^2)*2^24 */ -#else - /* Use Phase Tracker Mean-Square Error Register */ - /* SNR for ranges from -13.11 to +44.08 */ - noise = ((buf[0] & 7) << 16) | (buf[3] << 8) | buf[4]; - c = 73957994; /* log10(25*32^2)*2^24 */ -#endif - break; - case QAM_64: - case QAM_256: - i2c_read_demod_bytes(state, CARRIER_MSEQAM1, buf, 2); - noise = (buf[0] << 8) | buf[1]; - c = state->current_modulation == QAM_64 ? 97939837 : 98026066; - /* log10(688128)*2^24 and log10(696320)*2^24 */ - break; - default: - printk(KERN_ERR "lgdt330x: %s: Modulation set to unsupported value\n", - __func__); - return -EREMOTEIO; /* return -EDRIVER_IS_GIBBERED; */ + p->block_error.stat[0].scale = FE_SCALE_COUNTER; + p->block_count.stat[0].scale = FE_SCALE_COUNTER; + } else { + p->block_error.stat[0].scale = FE_SCALE_NOT_AVAILABLE; + p->block_count.stat[0].scale = FE_SCALE_NOT_AVAILABLE; } - state->snr = calculate_snr(noise, c); - *snr = (state->snr) >> 16; /* Convert from 8.24 fixed-point to 8.8 */ - - dprintk("%s: noise = 0x%08x, snr = %d.%02d dB\n", __func__, noise, - state->snr >> 24, (((state->snr >> 8) & 0xffff) * 100) >> 16); - return 0; } -static int lgdt330x_read_signal_strength(struct dvb_frontend* fe, u16* strength) -{ - /* Calculate Strength from SNR up to 35dB */ - /* Even though the SNR can go higher than 35dB, there is some comfort */ - /* factor in having a range of strong signals that can show at 100% */ - struct lgdt330x_state* state = (struct lgdt330x_state*) fe->demodulator_priv; - u16 snr; - int ret; - - ret = fe->ops.read_snr(fe, &snr); - if (ret != 0) - return ret; - /* Rather than use the 8.8 value snr, use state->snr which is 8.24 */ - /* scale the range 0 - 35*2^24 into 0 - 65535 */ - if (state->snr >= 8960 * 0x10000) - *strength = 0xffff; - else - *strength = state->snr / 8960; - - return 0; -} - -static int lgdt330x_get_tune_settings(struct dvb_frontend* fe, struct dvb_frontend_tune_settings* fe_tune_settings) +static int +lgdt330x_get_tune_settings(struct dvb_frontend *fe, + struct dvb_frontend_tune_settings *fe_tune_settings) { /* I have no idea about this - it may not be needed */ fe_tune_settings->min_delay_ms = 500; @@ -718,43 +845,63 @@ static int lgdt330x_get_tune_settings(struct dvb_frontend* fe, struct dvb_fronte return 0; } -static void lgdt330x_release(struct dvb_frontend* fe) +static void lgdt330x_release(struct dvb_frontend *fe) { - struct lgdt330x_state* state = (struct lgdt330x_state*) fe->demodulator_priv; - kfree(state); + struct lgdt330x_state *state = fe->demodulator_priv; + struct i2c_client *client = state->client; + + dev_dbg(&client->dev, "\n"); + + i2c_unregister_device(client); +} + +static struct dvb_frontend *lgdt330x_get_dvb_frontend(struct i2c_client *client) +{ + struct lgdt330x_state *state = i2c_get_clientdata(client); + + dev_dbg(&client->dev, "\n"); + + return &state->frontend; } static const struct dvb_frontend_ops lgdt3302_ops; static const struct dvb_frontend_ops lgdt3303_ops; -struct dvb_frontend* lgdt330x_attach(const struct lgdt330x_config* config, - struct i2c_adapter* i2c) +static int lgdt330x_probe(struct i2c_client *client, + const struct i2c_device_id *id) { - struct lgdt330x_state* state = NULL; + struct lgdt330x_state *state = NULL; u8 buf[1]; /* Allocate memory for the internal state */ - state = kzalloc(sizeof(struct lgdt330x_state), GFP_KERNEL); - if (state == NULL) + state = kzalloc(sizeof(*state), GFP_KERNEL); + if (!state) goto error; /* Setup the state */ - state->config = config; - state->i2c = i2c; + memcpy(&state->config, client->dev.platform_data, + sizeof(state->config)); + i2c_set_clientdata(client, state); + state->client = client; /* Create dvb_frontend */ - switch (config->demod_chip) { + switch (state->config.demod_chip) { case LGDT3302: - memcpy(&state->frontend.ops, &lgdt3302_ops, sizeof(struct dvb_frontend_ops)); + memcpy(&state->frontend.ops, &lgdt3302_ops, + sizeof(struct dvb_frontend_ops)); break; case LGDT3303: - memcpy(&state->frontend.ops, &lgdt3303_ops, sizeof(struct dvb_frontend_ops)); + memcpy(&state->frontend.ops, &lgdt3303_ops, + sizeof(struct dvb_frontend_ops)); break; default: goto error; } state->frontend.demodulator_priv = state; + /* Setup get frontend callback */ + state->config.get_dvb_frontend = lgdt330x_get_dvb_frontend; + /* Verify communication with demod chip */ if (i2c_read_demod_bytes(state, 2, buf, 1)) goto error; @@ -762,21 +909,44 @@ struct dvb_frontend* lgdt330x_attach(const struct lgdt330x_config* config, state->current_frequency = -1; state->current_modulation = -1; - return &state->frontend; + dev_info(&state->client->dev, + "Demod loaded for LGDT330%s chip\n", + state->config.demod_chip == LGDT3302 ? "2" : "3"); + + return 0; error: kfree(state); - dprintk("%s: ERROR\n",__func__); - return NULL; + if (debug) + dev_printk(KERN_DEBUG, &client->dev, "Error loading lgdt330x driver\n"); + return -ENODEV; +} +struct dvb_frontend *lgdt330x_attach(const struct lgdt330x_config *_config, + u8 demod_address, + struct i2c_adapter *i2c) +{ + struct i2c_client *client; + struct i2c_board_info board_info = {}; + struct lgdt330x_config config = *_config; + + strlcpy(board_info.type, "lgdt330x", sizeof(board_info.type)); + board_info.addr = demod_address; + board_info.platform_data = &config; + client = i2c_new_device(i2c, &board_info); + if (!client || !client->dev.driver) + return NULL; + + return lgdt330x_get_dvb_frontend(client); } +EXPORT_SYMBOL(lgdt330x_attach); static const struct dvb_frontend_ops lgdt3302_ops = { .delsys = { SYS_ATSC, SYS_DVBC_ANNEX_B }, .info = { - .name= "LG Electronics LGDT3302 VSB/QAM Frontend", - .frequency_min= 54000000, - .frequency_max= 858000000, - .frequency_stepsize= 62500, + .name = "LG Electronics LGDT3302 VSB/QAM Frontend", + .frequency_min = 54000000, + .frequency_max = 858000000, + .frequency_stepsize = 62500, .symbol_rate_min = 5056941, /* QAM 64 */ .symbol_rate_max = 10762000, /* VSB 8 */ .caps = FE_CAN_QAM_64 | FE_CAN_QAM_256 | FE_CAN_8VSB @@ -786,9 +956,8 @@ static const struct dvb_frontend_ops lgdt3302_ops = { .get_frontend = lgdt330x_get_frontend, .get_tune_settings = lgdt330x_get_tune_settings, .read_status = lgdt3302_read_status, - .read_ber = lgdt330x_read_ber, .read_signal_strength = lgdt330x_read_signal_strength, - .read_snr = lgdt3302_read_snr, + .read_snr = lgdt330x_read_snr, .read_ucblocks = lgdt330x_read_ucblocks, .release = lgdt330x_release, }; @@ -796,10 +965,10 @@ static const struct dvb_frontend_ops lgdt3302_ops = { static const struct dvb_frontend_ops lgdt3303_ops = { .delsys = { SYS_ATSC, SYS_DVBC_ANNEX_B }, .info = { - .name= "LG Electronics LGDT3303 VSB/QAM Frontend", - .frequency_min= 54000000, - .frequency_max= 858000000, - .frequency_stepsize= 62500, + .name = "LG Electronics LGDT3303 VSB/QAM Frontend", + .frequency_min = 54000000, + .frequency_max = 858000000, + .frequency_stepsize = 62500, .symbol_rate_min = 5056941, /* QAM 64 */ .symbol_rate_max = 10762000, /* VSB 8 */ .caps = FE_CAN_QAM_64 | FE_CAN_QAM_256 | FE_CAN_8VSB @@ -809,15 +978,42 @@ static const struct dvb_frontend_ops lgdt3303_ops = { .get_frontend = lgdt330x_get_frontend, .get_tune_settings = lgdt330x_get_tune_settings, .read_status = lgdt3303_read_status, - .read_ber = lgdt330x_read_ber, .read_signal_strength = lgdt330x_read_signal_strength, - .read_snr = lgdt3303_read_snr, + .read_snr = lgdt330x_read_snr, .read_ucblocks = lgdt330x_read_ucblocks, .release = lgdt330x_release, }; +static int lgdt330x_remove(struct i2c_client *client) +{ + struct lgdt330x_state *state = i2c_get_clientdata(client); + + dev_dbg(&client->dev, "\n"); + + kfree(state); + + return 0; +} + +static const struct i2c_device_id lgdt330x_id_table[] = { + {"lgdt330x", 0}, + {} +}; +MODULE_DEVICE_TABLE(i2c, lgdt330x_id_table); + +static struct i2c_driver lgdt330x_driver = { + .driver = { + .name = "lgdt330x", + .suppress_bind_attrs = true, + }, + .probe = lgdt330x_probe, + .remove = lgdt330x_remove, + .id_table = lgdt330x_id_table, +}; + +module_i2c_driver(lgdt330x_driver); + + MODULE_DESCRIPTION("LGDT330X (ATSC 8VSB & ITU-T J.83 AnnexB 64/256 QAM) Demodulator Driver"); MODULE_AUTHOR("Wilson Michaels"); MODULE_LICENSE("GPL"); - -EXPORT_SYMBOL(lgdt330x_attach); diff --git a/drivers/media/dvb-frontends/lgdt330x.h b/drivers/media/dvb-frontends/lgdt330x.h index 61434cbecd2c..94cc09d15ece 100644 --- a/drivers/media/dvb-frontends/lgdt330x.h +++ b/drivers/media/dvb-frontends/lgdt330x.h @@ -26,34 +26,41 @@ typedef enum lg_chip_t { LGDT3303 }lg_chip_type; +/** + * struct lgdt330x_config - contains lgdt330x configuration + * + * @demod_chip: LG demodulator chip LGDT3302 or LGDT3303 + * @serial_mpeg: MPEG hardware interface - 0:parallel 1:serial + * @pll_rf_set: Callback function to set PLL interface + * @set_ts_params: Callback function to set device param for start_dma + * @clock_polarity_flip: + * Flip the polarity of the mpeg data transfer clock using alternate + * init data. + * This option applies ONLY to LGDT3303 - 0:disabled (default) 1:enabled + * @get_dvb_frontend: + * returns the frontend associated with this I2C client. + * Filled by the driver. + */ struct lgdt330x_config { - /* The demodulator's i2c address */ - u8 demod_address; - - /* LG demodulator chip LGDT3302 or LGDT3303 */ lg_chip_type demod_chip; - - /* MPEG hardware interface - 0:parallel 1:serial */ int serial_mpeg; - - /* PLL interface */ int (*pll_rf_set) (struct dvb_frontend* fe, int index); - - /* Need to set device param for start_dma */ int (*set_ts_params)(struct dvb_frontend* fe, int is_punctured); - - /* Flip the polarity of the mpeg data transfer clock using alternate init data - * This option applies ONLY to LGDT3303 - 0:disabled (default) 1:enabled */ int clock_polarity_flip; + + struct dvb_frontend* (*get_dvb_frontend)(struct i2c_client *); }; #if IS_REACHABLE(CONFIG_DVB_LGDT330X) -extern struct dvb_frontend* lgdt330x_attach(const struct lgdt330x_config* config, - struct i2c_adapter* i2c); +struct dvb_frontend *lgdt330x_attach(const struct lgdt330x_config *config, + u8 demod_address, + struct i2c_adapter *i2c); #else -static inline struct dvb_frontend* lgdt330x_attach(const struct lgdt330x_config* config, - struct i2c_adapter* i2c) +static +struct dvb_frontend *lgdt330x_attach(const struct lgdt330x_config *config, + u8 demod_address, + struct i2c_adapter *i2c) { printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __func__); return NULL; diff --git a/drivers/media/dvb-frontends/mb86a20s.c b/drivers/media/dvb-frontends/mb86a20s.c index 36e95196dff4..c3b1b88e2e7a 100644 --- a/drivers/media/dvb-frontends/mb86a20s.c +++ b/drivers/media/dvb-frontends/mb86a20s.c @@ -2055,7 +2055,7 @@ static void mb86a20s_release(struct dvb_frontend *fe) kfree(state); } -static int mb86a20s_get_frontend_algo(struct dvb_frontend *fe) +static enum dvbfe_algo mb86a20s_get_frontend_algo(struct dvb_frontend *fe) { return DVBFE_ALGO_HW; } diff --git a/drivers/media/dvb-frontends/mxl5xx.c b/drivers/media/dvb-frontends/mxl5xx.c index 483ee7d6198e..274d8fca0763 100644 --- a/drivers/media/dvb-frontends/mxl5xx.c +++ b/drivers/media/dvb-frontends/mxl5xx.c @@ -375,7 +375,7 @@ static void release(struct dvb_frontend *fe) kfree(state); } -static int get_algo(struct dvb_frontend *fe) +static enum dvbfe_algo get_algo(struct dvb_frontend *fe) { return DVBFE_ALGO_HW; } diff --git a/drivers/media/dvb-frontends/s921.c b/drivers/media/dvb-frontends/s921.c index 2d75ede77aca..6c9015236655 100644 --- a/drivers/media/dvb-frontends/s921.c +++ b/drivers/media/dvb-frontends/s921.c @@ -464,7 +464,7 @@ static int s921_tune(struct dvb_frontend *fe, return rc; } -static int s921_get_algo(struct dvb_frontend *fe) +static enum dvbfe_algo s921_get_algo(struct dvb_frontend *fe) { return DVBFE_ALGO_HW; } diff --git a/drivers/media/dvb-frontends/stv0910.c b/drivers/media/dvb-frontends/stv0910.c index 52355c14fd64..7e9b016b3b28 100644 --- a/drivers/media/dvb-frontends/stv0910.c +++ b/drivers/media/dvb-frontends/stv0910.c @@ -1220,6 +1220,12 @@ static int probe(struct stv *state) write_reg(state, RSTV0910_P1_I2CRPT, state->i2crpt); write_reg(state, RSTV0910_P2_I2CRPT, state->i2crpt); + write_reg(state, RSTV0910_P1_TSINSDELM, 0x17); + write_reg(state, RSTV0910_P1_TSINSDELL, 0xff); + + write_reg(state, RSTV0910_P2_TSINSDELM, 0x17); + write_reg(state, RSTV0910_P2_TSINSDELL, 0xff); + init_diseqc(state); return 0; } @@ -1320,7 +1326,7 @@ static int read_snr(struct dvb_frontend *fe) if (!get_signal_to_noise(state, &snrval)) { p->cnr.stat[0].scale = FE_SCALE_DECIBEL; - p->cnr.stat[0].uvalue = 100 * snrval; /* fix scale */ + p->cnr.stat[0].svalue = 100 * snrval; /* fix scale */ } else { p->cnr.stat[0].scale = FE_SCALE_NOT_AVAILABLE; } @@ -1633,7 +1639,7 @@ static int tune(struct dvb_frontend *fe, bool re_tune, return 0; } -static int get_algo(struct dvb_frontend *fe) +static enum dvbfe_algo get_algo(struct dvb_frontend *fe) { return DVBFE_ALGO_HW; } diff --git a/drivers/media/dvb-frontends/tc90522.c b/drivers/media/dvb-frontends/tc90522.c index 5572b39614d5..7abf6b0916ed 100644 --- a/drivers/media/dvb-frontends/tc90522.c +++ b/drivers/media/dvb-frontends/tc90522.c @@ -1,17 +1,8 @@ +// SPDX-License-Identifier: GPL-2.0 /* * Toshiba TC90522 Demodulator * * Copyright (C) 2014 Akihiro Tsukada <tskd08@gmail.com> - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation version 2. - * - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. */ /* @@ -352,7 +343,7 @@ static int tc90522t_get_frontend(struct dvb_frontend *fe, mode = 1; ret = reg_read(state, 0xb0, val, 1); if (ret == 0) { - mode = (val[0] & 0xc0) >> 2; + mode = (val[0] & 0xc0) >> 6; c->transmission_mode = tm_conv[mode]; c->guard_interval = (val[0] & 0x30) >> 4; } @@ -379,7 +370,7 @@ static int tc90522t_get_frontend(struct dvb_frontend *fe, } /* layer B */ - v = (val[3] & 0x03) << 1 | (val[4] & 0xc0) >> 6; + v = (val[3] & 0x03) << 2 | (val[4] & 0xc0) >> 6; if (v == 0x0f) c->layer[1].segment_count = 0; else { diff --git a/drivers/media/dvb-frontends/tc90522.h b/drivers/media/dvb-frontends/tc90522.h index 10e585f32499..ac0e2ab51924 100644 --- a/drivers/media/dvb-frontends/tc90522.h +++ b/drivers/media/dvb-frontends/tc90522.h @@ -1,17 +1,8 @@ +/* SPDX-License-Identifier: GPL-2.0 */ /* * Toshiba TC90522 Demodulator * * Copyright (C) 2014 Akihiro Tsukada <tskd08@gmail.com> - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation version 2. - * - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. */ /* diff --git a/drivers/media/i2c/Kconfig b/drivers/media/i2c/Kconfig index 541f0d28afd8..faaaceb94832 100644 --- a/drivers/media/i2c/Kconfig +++ b/drivers/media/i2c/Kconfig @@ -974,6 +974,19 @@ config VIDEO_M52790 To compile this driver as a module, choose M here: the module will be called m52790. + +config VIDEO_I2C + tristate "I2C transport video support" + depends on VIDEO_V4L2 && I2C + select VIDEOBUF2_VMALLOC + ---help--- + Enable the I2C transport video support which supports the + following: + * Panasonic AMG88xx Grid-Eye Sensors + + To compile this driver as a module, choose M here: the + module will be called video-i2c + endmenu menu "Sensors used on soc_camera driver" diff --git a/drivers/media/i2c/Makefile b/drivers/media/i2c/Makefile index ea34aee1a85a..84cc472238ef 100644 --- a/drivers/media/i2c/Makefile +++ b/drivers/media/i2c/Makefile @@ -96,6 +96,7 @@ obj-$(CONFIG_VIDEO_LM3646) += lm3646.o obj-$(CONFIG_VIDEO_SMIAPP_PLL) += smiapp-pll.o obj-$(CONFIG_VIDEO_AK881X) += ak881x.o obj-$(CONFIG_VIDEO_IR_I2C) += ir-kbd-i2c.o +obj-$(CONFIG_VIDEO_I2C) += video-i2c.o obj-$(CONFIG_VIDEO_ML86V7667) += ml86v7667.o obj-$(CONFIG_VIDEO_OV2659) += ov2659.o obj-$(CONFIG_VIDEO_TC358743) += tc358743.o diff --git a/drivers/media/i2c/ir-kbd-i2c.c b/drivers/media/i2c/ir-kbd-i2c.c index a7e23bcf845c..a14a74e6b986 100644 --- a/drivers/media/i2c/ir-kbd-i2c.c +++ b/drivers/media/i2c/ir-kbd-i2c.c @@ -739,6 +739,7 @@ static int ir_probe(struct i2c_client *client, const struct i2c_device_id *id) struct rc_dev *rc = NULL; struct i2c_adapter *adap = client->adapter; unsigned short addr = client->addr; + bool probe_tx = (id->driver_data & FLAG_TX) != 0; int err; if ((id->driver_data & FLAG_HDPVR) && !enable_hdpvr) { @@ -800,6 +801,7 @@ static int ir_probe(struct i2c_client *client, const struct i2c_device_id *id) rc_proto = RC_PROTO_BIT_RC5 | RC_PROTO_BIT_RC6_MCE | RC_PROTO_BIT_RC6_6A_32; ir_codes = RC_MAP_HAUPPAUGE; + probe_tx = true; break; } @@ -892,7 +894,7 @@ static int ir_probe(struct i2c_client *client, const struct i2c_device_id *id) INIT_DELAYED_WORK(&ir->work, ir_work); - if (id->driver_data & FLAG_TX) { + if (probe_tx) { ir->tx_c = i2c_new_dummy(client->adapter, 0x70); if (!ir->tx_c) { dev_err(&client->dev, "failed to setup tx i2c address"); diff --git a/drivers/media/i2c/ov13858.c b/drivers/media/i2c/ov13858.c index 3dbcae257164..a66f6201f53c 100644 --- a/drivers/media/i2c/ov13858.c +++ b/drivers/media/i2c/ov13858.c @@ -1796,7 +1796,6 @@ MODULE_DEVICE_TABLE(acpi, ov13858_acpi_ids); static struct i2c_driver ov13858_i2c_driver = { .driver = { .name = "ov13858", - .owner = THIS_MODULE, .pm = &ov13858_pm_ops, .acpi_match_table = ACPI_PTR(ov13858_acpi_ids), }, diff --git a/drivers/media/i2c/ov5695.c b/drivers/media/i2c/ov5695.c index 9be38a0a2046..9a80decd93d3 100644 --- a/drivers/media/i2c/ov5695.c +++ b/drivers/media/i2c/ov5695.c @@ -1385,7 +1385,6 @@ MODULE_DEVICE_TABLE(of, ov5695_of_match); static struct i2c_driver ov5695_i2c_driver = { .driver = { .name = "ov5695", - .owner = THIS_MODULE, .pm = &ov5695_pm_ops, .of_match_table = of_match_ptr(ov5695_of_match), }, diff --git a/drivers/media/i2c/ov7740.c b/drivers/media/i2c/ov7740.c index 01f578785e79..605f3e25ad82 100644 --- a/drivers/media/i2c/ov7740.c +++ b/drivers/media/i2c/ov7740.c @@ -953,7 +953,7 @@ static int ov7740_init_controls(struct ov7740 *ov7740) struct v4l2_ctrl_handler *ctrl_hdlr = &ov7740->ctrl_handler; int ret; - ret = v4l2_ctrl_handler_init(ctrl_hdlr, 2); + ret = v4l2_ctrl_handler_init(ctrl_hdlr, 12); if (ret < 0) return ret; @@ -980,27 +980,39 @@ static int ov7740_init_controls(struct ov7740 *ov7740) V4L2_CID_HFLIP, 0, 1, 1, 0); ov7740->vflip = v4l2_ctrl_new_std(ctrl_hdlr, &ov7740_ctrl_ops, V4L2_CID_VFLIP, 0, 1, 1, 0); + ov7740->gain = v4l2_ctrl_new_std(ctrl_hdlr, &ov7740_ctrl_ops, V4L2_CID_GAIN, 0, 1023, 1, 500); + if (ov7740->gain) + ov7740->gain->flags |= V4L2_CTRL_FLAG_VOLATILE; + ov7740->auto_gain = v4l2_ctrl_new_std(ctrl_hdlr, &ov7740_ctrl_ops, V4L2_CID_AUTOGAIN, 0, 1, 1, 1); + ov7740->exposure = v4l2_ctrl_new_std(ctrl_hdlr, &ov7740_ctrl_ops, V4L2_CID_EXPOSURE, 0, 65535, 1, 500); + if (ov7740->exposure) + ov7740->exposure->flags |= V4L2_CTRL_FLAG_VOLATILE; + ov7740->auto_exposure = v4l2_ctrl_new_std_menu(ctrl_hdlr, &ov7740_ctrl_ops, V4L2_CID_EXPOSURE_AUTO, V4L2_EXPOSURE_MANUAL, 0, V4L2_EXPOSURE_AUTO); - ov7740->gain->flags |= V4L2_CTRL_FLAG_VOLATILE; - ov7740->exposure->flags |= V4L2_CTRL_FLAG_VOLATILE; - v4l2_ctrl_auto_cluster(3, &ov7740->auto_wb, 0, false); v4l2_ctrl_auto_cluster(2, &ov7740->auto_gain, 0, true); v4l2_ctrl_auto_cluster(2, &ov7740->auto_exposure, V4L2_EXPOSURE_MANUAL, false); v4l2_ctrl_cluster(2, &ov7740->hflip); + if (ctrl_hdlr->error) { + ret = ctrl_hdlr->error; + dev_err(&client->dev, "controls initialisation failed (%d)\n", + ret); + goto error; + } + ret = v4l2_ctrl_handler_setup(ctrl_hdlr); if (ret) { dev_err(&client->dev, "%s control init failed (%d)\n", @@ -1074,7 +1086,7 @@ static int ov7740_probe(struct i2c_client *client, #ifdef CONFIG_VIDEO_V4L2_SUBDEV_API sd->internal_ops = &ov7740_subdev_internal_ops; - sd->flags |= V4L2_SUBDEV_FL_HAS_DEVNODE; + sd->flags |= V4L2_SUBDEV_FL_HAS_DEVNODE | V4L2_SUBDEV_FL_HAS_EVENTS; #endif #if defined(CONFIG_MEDIA_CONTROLLER) diff --git a/drivers/media/i2c/tda1997x.c b/drivers/media/i2c/tda1997x.c index 3021913c28fa..1c5b5f70866f 100644 --- a/drivers/media/i2c/tda1997x.c +++ b/drivers/media/i2c/tda1997x.c @@ -2567,7 +2567,7 @@ static int tda1997x_probe(struct i2c_client *client, snprintf(sd->name, sizeof(sd->name), "%s %d-%04x", id->name, i2c_adapter_id(client->adapter), client->addr); - sd->flags = V4L2_SUBDEV_FL_HAS_DEVNODE | V4L2_SUBDEV_FL_HAS_EVENTS; + sd->flags |= V4L2_SUBDEV_FL_HAS_DEVNODE | V4L2_SUBDEV_FL_HAS_EVENTS; sd->entity.function = MEDIA_ENT_F_DTV_DECODER; sd->entity.ops = &tda1997x_media_ops; diff --git a/drivers/media/i2c/tvp5150.c b/drivers/media/i2c/tvp5150.c index 1734ed4ede33..b162c2fe62c3 100644 --- a/drivers/media/i2c/tvp5150.c +++ b/drivers/media/i2c/tvp5150.c @@ -319,136 +319,136 @@ struct i2c_reg_value { /* Default values as sugested at TVP5150AM1 datasheet */ static const struct i2c_reg_value tvp5150_init_default[] = { { /* 0x00 */ - TVP5150_VD_IN_SRC_SEL_1,0x00 + TVP5150_VD_IN_SRC_SEL_1, 0x00 }, { /* 0x01 */ - TVP5150_ANAL_CHL_CTL,0x15 + TVP5150_ANAL_CHL_CTL, 0x15 }, { /* 0x02 */ - TVP5150_OP_MODE_CTL,0x00 + TVP5150_OP_MODE_CTL, 0x00 }, { /* 0x03 */ - TVP5150_MISC_CTL,0x01 + TVP5150_MISC_CTL, 0x01 }, { /* 0x06 */ - TVP5150_COLOR_KIL_THSH_CTL,0x10 + TVP5150_COLOR_KIL_THSH_CTL, 0x10 }, { /* 0x07 */ - TVP5150_LUMA_PROC_CTL_1,0x60 + TVP5150_LUMA_PROC_CTL_1, 0x60 }, { /* 0x08 */ - TVP5150_LUMA_PROC_CTL_2,0x00 + TVP5150_LUMA_PROC_CTL_2, 0x00 }, { /* 0x09 */ - TVP5150_BRIGHT_CTL,0x80 + TVP5150_BRIGHT_CTL, 0x80 }, { /* 0x0a */ - TVP5150_SATURATION_CTL,0x80 + TVP5150_SATURATION_CTL, 0x80 }, { /* 0x0b */ - TVP5150_HUE_CTL,0x00 + TVP5150_HUE_CTL, 0x00 }, { /* 0x0c */ - TVP5150_CONTRAST_CTL,0x80 + TVP5150_CONTRAST_CTL, 0x80 }, { /* 0x0d */ - TVP5150_DATA_RATE_SEL,0x47 + TVP5150_DATA_RATE_SEL, 0x47 }, { /* 0x0e */ - TVP5150_LUMA_PROC_CTL_3,0x00 + TVP5150_LUMA_PROC_CTL_3, 0x00 }, { /* 0x0f */ - TVP5150_CONF_SHARED_PIN,0x08 + TVP5150_CONF_SHARED_PIN, 0x08 }, { /* 0x11 */ - TVP5150_ACT_VD_CROP_ST_MSB,0x00 + TVP5150_ACT_VD_CROP_ST_MSB, 0x00 }, { /* 0x12 */ - TVP5150_ACT_VD_CROP_ST_LSB,0x00 + TVP5150_ACT_VD_CROP_ST_LSB, 0x00 }, { /* 0x13 */ - TVP5150_ACT_VD_CROP_STP_MSB,0x00 + TVP5150_ACT_VD_CROP_STP_MSB, 0x00 }, { /* 0x14 */ - TVP5150_ACT_VD_CROP_STP_LSB,0x00 + TVP5150_ACT_VD_CROP_STP_LSB, 0x00 }, { /* 0x15 */ - TVP5150_GENLOCK,0x01 + TVP5150_GENLOCK, 0x01 }, { /* 0x16 */ - TVP5150_HORIZ_SYNC_START,0x80 + TVP5150_HORIZ_SYNC_START, 0x80 }, { /* 0x18 */ - TVP5150_VERT_BLANKING_START,0x00 + TVP5150_VERT_BLANKING_START, 0x00 }, { /* 0x19 */ - TVP5150_VERT_BLANKING_STOP,0x00 + TVP5150_VERT_BLANKING_STOP, 0x00 }, { /* 0x1a */ - TVP5150_CHROMA_PROC_CTL_1,0x0c + TVP5150_CHROMA_PROC_CTL_1, 0x0c }, { /* 0x1b */ - TVP5150_CHROMA_PROC_CTL_2,0x14 + TVP5150_CHROMA_PROC_CTL_2, 0x14 }, { /* 0x1c */ - TVP5150_INT_RESET_REG_B,0x00 + TVP5150_INT_RESET_REG_B, 0x00 }, { /* 0x1d */ - TVP5150_INT_ENABLE_REG_B,0x00 + TVP5150_INT_ENABLE_REG_B, 0x00 }, { /* 0x1e */ - TVP5150_INTT_CONFIG_REG_B,0x00 + TVP5150_INTT_CONFIG_REG_B, 0x00 }, { /* 0x28 */ - TVP5150_VIDEO_STD,0x00 + TVP5150_VIDEO_STD, 0x00 }, { /* 0x2e */ - TVP5150_MACROVISION_ON_CTR,0x0f + TVP5150_MACROVISION_ON_CTR, 0x0f }, { /* 0x2f */ - TVP5150_MACROVISION_OFF_CTR,0x01 + TVP5150_MACROVISION_OFF_CTR, 0x01 }, { /* 0xbb */ - TVP5150_TELETEXT_FIL_ENA,0x00 + TVP5150_TELETEXT_FIL_ENA, 0x00 }, { /* 0xc0 */ - TVP5150_INT_STATUS_REG_A,0x00 + TVP5150_INT_STATUS_REG_A, 0x00 }, { /* 0xc1 */ - TVP5150_INT_ENABLE_REG_A,0x00 + TVP5150_INT_ENABLE_REG_A, 0x00 }, { /* 0xc2 */ - TVP5150_INT_CONF,0x04 + TVP5150_INT_CONF, 0x04 }, { /* 0xc8 */ - TVP5150_FIFO_INT_THRESHOLD,0x80 + TVP5150_FIFO_INT_THRESHOLD, 0x80 }, { /* 0xc9 */ - TVP5150_FIFO_RESET,0x00 + TVP5150_FIFO_RESET, 0x00 }, { /* 0xca */ - TVP5150_LINE_NUMBER_INT,0x00 + TVP5150_LINE_NUMBER_INT, 0x00 }, { /* 0xcb */ - TVP5150_PIX_ALIGN_REG_LOW,0x4e + TVP5150_PIX_ALIGN_REG_LOW, 0x4e }, { /* 0xcc */ - TVP5150_PIX_ALIGN_REG_HIGH,0x00 + TVP5150_PIX_ALIGN_REG_HIGH, 0x00 }, { /* 0xcd */ - TVP5150_FIFO_OUT_CTRL,0x01 + TVP5150_FIFO_OUT_CTRL, 0x01 }, { /* 0xcf */ - TVP5150_FULL_FIELD_ENA,0x00 + TVP5150_FULL_FIELD_ENA, 0x00 }, { /* 0xd0 */ - TVP5150_LINE_MODE_INI,0x00 + TVP5150_LINE_MODE_INI, 0x00 }, { /* 0xfc */ - TVP5150_FULL_FIELD_MODE_REG,0x7f + TVP5150_FULL_FIELD_MODE_REG, 0x7f }, { /* end of data */ - 0xff,0xff + 0xff, 0xff } }; @@ -456,27 +456,27 @@ static const struct i2c_reg_value tvp5150_init_default[] = { static const struct i2c_reg_value tvp5150_init_enable[] = { { TVP5150_CONF_SHARED_PIN, 2 - },{ /* Automatic offset and AGC enabled */ + }, { /* Automatic offset and AGC enabled */ TVP5150_ANAL_CHL_CTL, 0x15 - },{ /* Activate YCrCb output 0x9 or 0xd ? */ + }, { /* Activate YCrCb output 0x9 or 0xd ? */ TVP5150_MISC_CTL, TVP5150_MISC_CTL_GPCL | TVP5150_MISC_CTL_INTREQ_OE | TVP5150_MISC_CTL_YCBCR_OE | TVP5150_MISC_CTL_SYNC_OE | TVP5150_MISC_CTL_VBLANK | TVP5150_MISC_CTL_CLOCK_OE, - },{ /* Activates video std autodetection for all standards */ + }, { /* Activates video std autodetection for all standards */ TVP5150_AUTOSW_MSK, 0x0 - },{ /* Default format: 0x47. For 4:2:2: 0x40 */ + }, { /* Default format: 0x47. For 4:2:2: 0x40 */ TVP5150_DATA_RATE_SEL, 0x47 - },{ + }, { TVP5150_CHROMA_PROC_CTL_1, 0x0c - },{ + }, { TVP5150_CHROMA_PROC_CTL_2, 0x54 - },{ /* Non documented, but initialized on WinTV USB2 */ + }, { /* Non documented, but initialized on WinTV USB2 */ 0x27, 0x20 - },{ - 0xff,0xff + }, { + 0xff, 0xff } }; @@ -500,78 +500,80 @@ struct i2c_vbi_ram_value { * and so on. There are 16 possible locations from 0 to 15. */ -static struct i2c_vbi_ram_value vbi_ram_default[] = -{ - /* FIXME: Current api doesn't handle all VBI types, those not - yet supported are placed under #if 0 */ +static struct i2c_vbi_ram_value vbi_ram_default[] = { + + /* + * FIXME: Current api doesn't handle all VBI types, those not + * yet supported are placed under #if 0 + */ #if 0 [0] = {0x010, /* Teletext, SECAM, WST System A */ - {V4L2_SLICED_TELETEXT_SECAM,6,23,1}, + {V4L2_SLICED_TELETEXT_SECAM, 6, 23, 1}, { 0xaa, 0xaa, 0xff, 0xff, 0xe7, 0x2e, 0x20, 0x26, 0xe6, 0xb4, 0x0e, 0x00, 0x00, 0x00, 0x10, 0x00 } }, #endif [1] = {0x030, /* Teletext, PAL, WST System B */ - {V4L2_SLICED_TELETEXT_B,6,22,1}, + {V4L2_SLICED_TELETEXT_B, 6, 22, 1}, { 0xaa, 0xaa, 0xff, 0xff, 0x27, 0x2e, 0x20, 0x2b, 0xa6, 0x72, 0x10, 0x00, 0x00, 0x00, 0x10, 0x00 } }, #if 0 [2] = {0x050, /* Teletext, PAL, WST System C */ - {V4L2_SLICED_TELETEXT_PAL_C,6,22,1}, + {V4L2_SLICED_TELETEXT_PAL_C, 6, 22, 1}, { 0xaa, 0xaa, 0xff, 0xff, 0xe7, 0x2e, 0x20, 0x22, 0xa6, 0x98, 0x0d, 0x00, 0x00, 0x00, 0x10, 0x00 } }, [3] = {0x070, /* Teletext, NTSC, WST System B */ - {V4L2_SLICED_TELETEXT_NTSC_B,10,21,1}, + {V4L2_SLICED_TELETEXT_NTSC_B, 10, 21, 1}, { 0xaa, 0xaa, 0xff, 0xff, 0x27, 0x2e, 0x20, 0x23, 0x69, 0x93, 0x0d, 0x00, 0x00, 0x00, 0x10, 0x00 } }, [4] = {0x090, /* Tetetext, NTSC NABTS System C */ - {V4L2_SLICED_TELETEXT_NTSC_C,10,21,1}, + {V4L2_SLICED_TELETEXT_NTSC_C, 10, 21, 1}, { 0xaa, 0xaa, 0xff, 0xff, 0xe7, 0x2e, 0x20, 0x22, 0x69, 0x93, 0x0d, 0x00, 0x00, 0x00, 0x15, 0x00 } }, [5] = {0x0b0, /* Teletext, NTSC-J, NABTS System D */ - {V4L2_SLICED_TELETEXT_NTSC_D,10,21,1}, + {V4L2_SLICED_TELETEXT_NTSC_D, 10, 21, 1}, { 0xaa, 0xaa, 0xff, 0xff, 0xa7, 0x2e, 0x20, 0x23, 0x69, 0x93, 0x0d, 0x00, 0x00, 0x00, 0x10, 0x00 } }, [6] = {0x0d0, /* Closed Caption, PAL/SECAM */ - {V4L2_SLICED_CAPTION_625,22,22,1}, + {V4L2_SLICED_CAPTION_625, 22, 22, 1}, { 0xaa, 0x2a, 0xff, 0x3f, 0x04, 0x51, 0x6e, 0x02, 0xa6, 0x7b, 0x09, 0x00, 0x00, 0x00, 0x27, 0x00 } }, #endif [7] = {0x0f0, /* Closed Caption, NTSC */ - {V4L2_SLICED_CAPTION_525,21,21,1}, + {V4L2_SLICED_CAPTION_525, 21, 21, 1}, { 0xaa, 0x2a, 0xff, 0x3f, 0x04, 0x51, 0x6e, 0x02, 0x69, 0x8c, 0x09, 0x00, 0x00, 0x00, 0x27, 0x00 } }, [8] = {0x110, /* Wide Screen Signal, PAL/SECAM */ - {V4L2_SLICED_WSS_625,23,23,1}, + {V4L2_SLICED_WSS_625, 23, 23, 1}, { 0x5b, 0x55, 0xc5, 0xff, 0x00, 0x71, 0x6e, 0x42, 0xa6, 0xcd, 0x0f, 0x00, 0x00, 0x00, 0x3a, 0x00 } }, #if 0 [9] = {0x130, /* Wide Screen Signal, NTSC C */ - {V4L2_SLICED_WSS_525,20,20,1}, + {V4L2_SLICED_WSS_525, 20, 20, 1}, { 0x38, 0x00, 0x3f, 0x00, 0x00, 0x71, 0x6e, 0x43, 0x69, 0x7c, 0x08, 0x00, 0x00, 0x00, 0x39, 0x00 } }, [10] = {0x150, /* Vertical Interval Timecode (VITC), PAL/SECAM */ - {V4l2_SLICED_VITC_625,6,22,0}, + {V4l2_SLICED_VITC_625, 6, 22, 0}, { 0x00, 0x00, 0x00, 0x00, 0x00, 0x8f, 0x6d, 0x49, 0xa6, 0x85, 0x08, 0x00, 0x00, 0x00, 0x4c, 0x00 } }, [11] = {0x170, /* Vertical Interval Timecode (VITC), NTSC */ - {V4l2_SLICED_VITC_525,10,20,0}, + {V4l2_SLICED_VITC_525, 10, 20, 0}, { 0x00, 0x00, 0x00, 0x00, 0x00, 0x8f, 0x6d, 0x49, 0x69, 0x94, 0x08, 0x00, 0x00, 0x00, 0x4c, 0x00 } }, #endif [12] = {0x190, /* Video Program System (VPS), PAL */ - {V4L2_SLICED_VPS,16,16,0}, + {V4L2_SLICED_VPS, 16, 16, 0}, { 0xaa, 0xaa, 0xff, 0xff, 0xba, 0xce, 0x2b, 0x0d, 0xa6, 0xda, 0x0b, 0x00, 0x00, 0x00, 0x60, 0x00 } }, @@ -623,7 +625,7 @@ static int tvp5150_g_sliced_vbi_cap(struct v4l2_subdev *sd, int line, i; dev_dbg_lvl(sd->dev, 1, debug, "g_sliced_vbi_cap\n"); - memset(cap, 0, sizeof *cap); + memset(cap, 0, sizeof(*cap)); for (i = 0; i < ARRAY_SIZE(vbi_ram_default); i++) { const struct i2c_vbi_ram_value *regs = &vbi_ram_default[i]; @@ -655,7 +657,7 @@ static int tvp5150_g_sliced_vbi_cap(struct v4l2_subdev *sd, * MSB = field2 */ static int tvp5150_set_vbi(struct v4l2_subdev *sd, - unsigned int type,u8 flags, int line, + unsigned int type, u8 flags, int line, const int fields) { struct tvp5150 *decoder = to_tvp5150(sd); @@ -1101,11 +1103,14 @@ static int tvp5150_s_routing(struct v4l2_subdev *sd, static int tvp5150_s_raw_fmt(struct v4l2_subdev *sd, struct v4l2_vbi_format *fmt) { - /* this is for capturing 36 raw vbi lines - if there's a way to cut off the beginning 2 vbi lines - with the tvp5150 then the vbi line count could be lowered - to 17 lines/field again, although I couldn't find a register - which could do that cropping */ + /* + * this is for capturing 36 raw vbi lines + * if there's a way to cut off the beginning 2 vbi lines + * with the tvp5150 then the vbi line count could be lowered + * to 17 lines/field again, although I couldn't find a register + * which could do that cropping + */ + if (fmt->sample_format == V4L2_PIX_FMT_GREY) tvp5150_write(sd, TVP5150_LUMA_PROC_CTL_1, 0x70); if (fmt->count[0] == 18 && fmt->count[1] == 18) { diff --git a/drivers/media/i2c/video-i2c.c b/drivers/media/i2c/video-i2c.c new file mode 100644 index 000000000000..0b347cc19aa5 --- /dev/null +++ b/drivers/media/i2c/video-i2c.c @@ -0,0 +1,564 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * video-i2c.c - Support for I2C transport video devices + * + * Copyright (C) 2018 Matt Ranostay <matt.ranostay@konsulko.com> + * + * Supported: + * - Panasonic AMG88xx Grid-Eye Sensors + */ + +#include <linux/delay.h> +#include <linux/freezer.h> +#include <linux/kthread.h> +#include <linux/i2c.h> +#include <linux/list.h> +#include <linux/module.h> +#include <linux/mutex.h> +#include <linux/of_device.h> +#include <linux/sched.h> +#include <linux/slab.h> +#include <linux/videodev2.h> +#include <media/v4l2-common.h> +#include <media/v4l2-device.h> +#include <media/v4l2-event.h> +#include <media/v4l2-fh.h> +#include <media/v4l2-ioctl.h> +#include <media/videobuf2-v4l2.h> +#include <media/videobuf2-vmalloc.h> + +#define VIDEO_I2C_DRIVER "video-i2c" + +struct video_i2c_chip; + +struct video_i2c_buffer { + struct vb2_v4l2_buffer vb; + struct list_head list; +}; + +struct video_i2c_data { + struct i2c_client *client; + const struct video_i2c_chip *chip; + struct mutex lock; + spinlock_t slock; + unsigned int sequence; + struct mutex queue_lock; + + struct v4l2_device v4l2_dev; + struct video_device vdev; + struct vb2_queue vb_vidq; + + struct task_struct *kthread_vid_cap; + struct list_head vid_cap_active; +}; + +static const struct v4l2_fmtdesc amg88xx_format = { + .pixelformat = V4L2_PIX_FMT_Y12, +}; + +static const struct v4l2_frmsize_discrete amg88xx_size = { + .width = 8, + .height = 8, +}; + +struct video_i2c_chip { + /* video dimensions */ + const struct v4l2_fmtdesc *format; + const struct v4l2_frmsize_discrete *size; + + /* max frames per second */ + unsigned int max_fps; + + /* pixel buffer size */ + unsigned int buffer_size; + + /* pixel size in bits */ + unsigned int bpp; + + /* xfer function */ + int (*xfer)(struct video_i2c_data *data, char *buf); +}; + +static int amg88xx_xfer(struct video_i2c_data *data, char *buf) +{ + struct i2c_client *client = data->client; + struct i2c_msg msg[2]; + u8 reg = 0x80; + int ret; + + msg[0].addr = client->addr; + msg[0].flags = 0; + msg[0].len = 1; + msg[0].buf = (char *)® + + msg[1].addr = client->addr; + msg[1].flags = I2C_M_RD; + msg[1].len = data->chip->buffer_size; + msg[1].buf = (char *)buf; + + ret = i2c_transfer(client->adapter, msg, 2); + + return (ret == 2) ? 0 : -EIO; +} + +#define AMG88XX 0 + +static const struct video_i2c_chip video_i2c_chip[] = { + [AMG88XX] = { + .size = &amg88xx_size, + .format = &amg88xx_format, + .max_fps = 10, + .buffer_size = 128, + .bpp = 16, + .xfer = &amg88xx_xfer, + }, +}; + +static const struct v4l2_file_operations video_i2c_fops = { + .owner = THIS_MODULE, + .open = v4l2_fh_open, + .release = vb2_fop_release, + .poll = vb2_fop_poll, + .read = vb2_fop_read, + .mmap = vb2_fop_mmap, + .unlocked_ioctl = video_ioctl2, +}; + +static int queue_setup(struct vb2_queue *vq, + unsigned int *nbuffers, unsigned int *nplanes, + unsigned int sizes[], struct device *alloc_devs[]) +{ + struct video_i2c_data *data = vb2_get_drv_priv(vq); + unsigned int size = data->chip->buffer_size; + + if (vq->num_buffers + *nbuffers < 2) + *nbuffers = 2; + + if (*nplanes) + return sizes[0] < size ? -EINVAL : 0; + + *nplanes = 1; + sizes[0] = size; + + return 0; +} + +static int buffer_prepare(struct vb2_buffer *vb) +{ + struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb); + struct video_i2c_data *data = vb2_get_drv_priv(vb->vb2_queue); + unsigned int size = data->chip->buffer_size; + + if (vb2_plane_size(vb, 0) < size) + return -EINVAL; + + vbuf->field = V4L2_FIELD_NONE; + vb2_set_plane_payload(vb, 0, size); + + return 0; +} + +static void buffer_queue(struct vb2_buffer *vb) +{ + struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb); + struct video_i2c_data *data = vb2_get_drv_priv(vb->vb2_queue); + struct video_i2c_buffer *buf = + container_of(vbuf, struct video_i2c_buffer, vb); + + spin_lock(&data->slock); + list_add_tail(&buf->list, &data->vid_cap_active); + spin_unlock(&data->slock); +} + +static int video_i2c_thread_vid_cap(void *priv) +{ + struct video_i2c_data *data = priv; + unsigned int delay = msecs_to_jiffies(1000 / data->chip->max_fps); + + set_freezable(); + + do { + unsigned long start_jiffies = jiffies; + struct video_i2c_buffer *vid_cap_buf = NULL; + int schedule_delay; + + try_to_freeze(); + + spin_lock(&data->slock); + + if (!list_empty(&data->vid_cap_active)) { + vid_cap_buf = list_last_entry(&data->vid_cap_active, + struct video_i2c_buffer, list); + list_del(&vid_cap_buf->list); + } + + spin_unlock(&data->slock); + + if (vid_cap_buf) { + struct vb2_buffer *vb2_buf = &vid_cap_buf->vb.vb2_buf; + void *vbuf = vb2_plane_vaddr(vb2_buf, 0); + int ret; + + ret = data->chip->xfer(data, vbuf); + vb2_buf->timestamp = ktime_get_ns(); + vid_cap_buf->vb.sequence = data->sequence++; + vb2_buffer_done(vb2_buf, ret ? + VB2_BUF_STATE_ERROR : VB2_BUF_STATE_DONE); + } + + schedule_delay = delay - (jiffies - start_jiffies); + + if (time_after(jiffies, start_jiffies + delay)) + schedule_delay = delay; + + schedule_timeout_interruptible(schedule_delay); + } while (!kthread_should_stop()); + + return 0; +} + +static void video_i2c_del_list(struct vb2_queue *vq, enum vb2_buffer_state state) +{ + struct video_i2c_data *data = vb2_get_drv_priv(vq); + struct video_i2c_buffer *buf, *tmp; + + spin_lock(&data->slock); + + list_for_each_entry_safe(buf, tmp, &data->vid_cap_active, list) { + list_del(&buf->list); + vb2_buffer_done(&buf->vb.vb2_buf, state); + } + + spin_unlock(&data->slock); +} + +static int start_streaming(struct vb2_queue *vq, unsigned int count) +{ + struct video_i2c_data *data = vb2_get_drv_priv(vq); + + if (data->kthread_vid_cap) + return 0; + + data->sequence = 0; + data->kthread_vid_cap = kthread_run(video_i2c_thread_vid_cap, data, + "%s-vid-cap", data->v4l2_dev.name); + if (!IS_ERR(data->kthread_vid_cap)) + return 0; + + video_i2c_del_list(vq, VB2_BUF_STATE_QUEUED); + + return PTR_ERR(data->kthread_vid_cap); +} + +static void stop_streaming(struct vb2_queue *vq) +{ + struct video_i2c_data *data = vb2_get_drv_priv(vq); + + if (data->kthread_vid_cap == NULL) + return; + + kthread_stop(data->kthread_vid_cap); + data->kthread_vid_cap = NULL; + + video_i2c_del_list(vq, VB2_BUF_STATE_ERROR); +} + +static struct vb2_ops video_i2c_video_qops = { + .queue_setup = queue_setup, + .buf_prepare = buffer_prepare, + .buf_queue = buffer_queue, + .start_streaming = start_streaming, + .stop_streaming = stop_streaming, + .wait_prepare = vb2_ops_wait_prepare, + .wait_finish = vb2_ops_wait_finish, +}; + +static int video_i2c_querycap(struct file *file, void *priv, + struct v4l2_capability *vcap) +{ + struct video_i2c_data *data = video_drvdata(file); + struct i2c_client *client = data->client; + + strlcpy(vcap->driver, data->v4l2_dev.name, sizeof(vcap->driver)); + strlcpy(vcap->card, data->vdev.name, sizeof(vcap->card)); + + sprintf(vcap->bus_info, "I2C:%d-%d", client->adapter->nr, client->addr); + + return 0; +} + +static int video_i2c_g_input(struct file *file, void *fh, unsigned int *inp) +{ + *inp = 0; + + return 0; +} + +static int video_i2c_s_input(struct file *file, void *fh, unsigned int inp) +{ + return (inp > 0) ? -EINVAL : 0; +} + +static int video_i2c_enum_input(struct file *file, void *fh, + struct v4l2_input *vin) +{ + if (vin->index > 0) + return -EINVAL; + + strlcpy(vin->name, "Camera", sizeof(vin->name)); + + vin->type = V4L2_INPUT_TYPE_CAMERA; + + return 0; +} + +static int video_i2c_enum_fmt_vid_cap(struct file *file, void *fh, + struct v4l2_fmtdesc *fmt) +{ + struct video_i2c_data *data = video_drvdata(file); + enum v4l2_buf_type type = fmt->type; + + if (fmt->index > 0) + return -EINVAL; + + *fmt = *data->chip->format; + fmt->type = type; + + return 0; +} + +static int video_i2c_enum_framesizes(struct file *file, void *fh, + struct v4l2_frmsizeenum *fsize) +{ + const struct video_i2c_data *data = video_drvdata(file); + const struct v4l2_frmsize_discrete *size = data->chip->size; + + /* currently only one frame size is allowed */ + if (fsize->index > 0) + return -EINVAL; + + if (fsize->pixel_format != data->chip->format->pixelformat) + return -EINVAL; + + fsize->type = V4L2_FRMSIZE_TYPE_DISCRETE; + fsize->discrete.width = size->width; + fsize->discrete.height = size->height; + + return 0; +} + +static int video_i2c_enum_frameintervals(struct file *file, void *priv, + struct v4l2_frmivalenum *fe) +{ + const struct video_i2c_data *data = video_drvdata(file); + const struct v4l2_frmsize_discrete *size = data->chip->size; + + if (fe->index > 0) + return -EINVAL; + + if (fe->width != size->width || fe->height != size->height) + return -EINVAL; + + fe->type = V4L2_FRMIVAL_TYPE_DISCRETE; + fe->discrete.numerator = 1; + fe->discrete.denominator = data->chip->max_fps; + + return 0; +} + +static int video_i2c_try_fmt_vid_cap(struct file *file, void *fh, + struct v4l2_format *fmt) +{ + const struct video_i2c_data *data = video_drvdata(file); + const struct v4l2_frmsize_discrete *size = data->chip->size; + struct v4l2_pix_format *pix = &fmt->fmt.pix; + unsigned int bpp = data->chip->bpp / 8; + + pix->width = size->width; + pix->height = size->height; + pix->pixelformat = data->chip->format->pixelformat; + pix->field = V4L2_FIELD_NONE; + pix->bytesperline = pix->width * bpp; + pix->sizeimage = pix->bytesperline * pix->height; + pix->colorspace = V4L2_COLORSPACE_RAW; + + return 0; +} + +static int video_i2c_s_fmt_vid_cap(struct file *file, void *fh, + struct v4l2_format *fmt) +{ + struct video_i2c_data *data = video_drvdata(file); + + if (vb2_is_busy(&data->vb_vidq)) + return -EBUSY; + + return video_i2c_try_fmt_vid_cap(file, fh, fmt); +} + +static int video_i2c_g_parm(struct file *filp, void *priv, + struct v4l2_streamparm *parm) +{ + struct video_i2c_data *data = video_drvdata(filp); + + if (parm->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) + return -EINVAL; + + parm->parm.capture.readbuffers = 1; + parm->parm.capture.capability = V4L2_CAP_TIMEPERFRAME; + parm->parm.capture.timeperframe.numerator = 1; + parm->parm.capture.timeperframe.denominator = data->chip->max_fps; + + return 0; +} + +static const struct v4l2_ioctl_ops video_i2c_ioctl_ops = { + .vidioc_querycap = video_i2c_querycap, + .vidioc_g_input = video_i2c_g_input, + .vidioc_s_input = video_i2c_s_input, + .vidioc_enum_input = video_i2c_enum_input, + .vidioc_enum_fmt_vid_cap = video_i2c_enum_fmt_vid_cap, + .vidioc_enum_framesizes = video_i2c_enum_framesizes, + .vidioc_enum_frameintervals = video_i2c_enum_frameintervals, + .vidioc_g_fmt_vid_cap = video_i2c_try_fmt_vid_cap, + .vidioc_s_fmt_vid_cap = video_i2c_s_fmt_vid_cap, + .vidioc_g_parm = video_i2c_g_parm, + .vidioc_s_parm = video_i2c_g_parm, + .vidioc_try_fmt_vid_cap = video_i2c_try_fmt_vid_cap, + .vidioc_reqbufs = vb2_ioctl_reqbufs, + .vidioc_create_bufs = vb2_ioctl_create_bufs, + .vidioc_prepare_buf = vb2_ioctl_prepare_buf, + .vidioc_querybuf = vb2_ioctl_querybuf, + .vidioc_qbuf = vb2_ioctl_qbuf, + .vidioc_dqbuf = vb2_ioctl_dqbuf, + .vidioc_streamon = vb2_ioctl_streamon, + .vidioc_streamoff = vb2_ioctl_streamoff, +}; + +static void video_i2c_release(struct video_device *vdev) +{ + kfree(video_get_drvdata(vdev)); +} + +static int video_i2c_probe(struct i2c_client *client, + const struct i2c_device_id *id) +{ + struct video_i2c_data *data; + struct v4l2_device *v4l2_dev; + struct vb2_queue *queue; + int ret = -ENODEV; + + data = kzalloc(sizeof(*data), GFP_KERNEL); + if (!data) + return -ENOMEM; + + if (dev_fwnode(&client->dev)) + data->chip = device_get_match_data(&client->dev); + else if (id) + data->chip = &video_i2c_chip[id->driver_data]; + else + goto error_free_device; + + data->client = client; + v4l2_dev = &data->v4l2_dev; + strlcpy(v4l2_dev->name, VIDEO_I2C_DRIVER, sizeof(v4l2_dev->name)); + + ret = v4l2_device_register(&client->dev, v4l2_dev); + if (ret < 0) + goto error_free_device; + + mutex_init(&data->lock); + mutex_init(&data->queue_lock); + + queue = &data->vb_vidq; + queue->type = V4L2_BUF_TYPE_VIDEO_CAPTURE; + queue->io_modes = VB2_DMABUF | VB2_MMAP | VB2_USERPTR | VB2_READ; + queue->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC; + queue->drv_priv = data; + queue->buf_struct_size = sizeof(struct video_i2c_buffer); + queue->min_buffers_needed = 1; + queue->ops = &video_i2c_video_qops; + queue->mem_ops = &vb2_vmalloc_memops; + + ret = vb2_queue_init(queue); + if (ret < 0) + goto error_unregister_device; + + data->vdev.queue = queue; + data->vdev.queue->lock = &data->queue_lock; + + snprintf(data->vdev.name, sizeof(data->vdev.name), + "I2C %d-%d Transport Video", + client->adapter->nr, client->addr); + + data->vdev.v4l2_dev = v4l2_dev; + data->vdev.fops = &video_i2c_fops; + data->vdev.lock = &data->lock; + data->vdev.ioctl_ops = &video_i2c_ioctl_ops; + data->vdev.release = video_i2c_release; + data->vdev.device_caps = V4L2_CAP_VIDEO_CAPTURE | + V4L2_CAP_READWRITE | V4L2_CAP_STREAMING; + + spin_lock_init(&data->slock); + INIT_LIST_HEAD(&data->vid_cap_active); + + video_set_drvdata(&data->vdev, data); + i2c_set_clientdata(client, data); + + ret = video_register_device(&data->vdev, VFL_TYPE_GRABBER, -1); + if (ret < 0) + goto error_unregister_device; + + return 0; + +error_unregister_device: + v4l2_device_unregister(v4l2_dev); + mutex_destroy(&data->lock); + mutex_destroy(&data->queue_lock); + +error_free_device: + kfree(data); + + return ret; +} + +static int video_i2c_remove(struct i2c_client *client) +{ + struct video_i2c_data *data = i2c_get_clientdata(client); + + video_unregister_device(&data->vdev); + v4l2_device_unregister(&data->v4l2_dev); + + mutex_destroy(&data->lock); + mutex_destroy(&data->queue_lock); + + return 0; +} + +static const struct i2c_device_id video_i2c_id_table[] = { + { "amg88xx", AMG88XX }, + {} +}; +MODULE_DEVICE_TABLE(i2c, video_i2c_id_table); + +static const struct of_device_id video_i2c_of_match[] = { + { .compatible = "panasonic,amg88xx", .data = &video_i2c_chip[AMG88XX] }, + {} +}; +MODULE_DEVICE_TABLE(of, video_i2c_of_match); + +static struct i2c_driver video_i2c_driver = { + .driver = { + .name = VIDEO_I2C_DRIVER, + .of_match_table = video_i2c_of_match, + }, + .probe = video_i2c_probe, + .remove = video_i2c_remove, + .id_table = video_i2c_id_table, +}; + +module_i2c_driver(video_i2c_driver); + +MODULE_AUTHOR("Matt Ranostay <matt.ranostay@konsulko.com>"); +MODULE_DESCRIPTION("I2C transport video support"); +MODULE_LICENSE("GPL v2"); diff --git a/drivers/media/media-device.c b/drivers/media/media-device.c index 35e81f7c0d2f..ae59c3177555 100644 --- a/drivers/media/media-device.c +++ b/drivers/media/media-device.c @@ -54,9 +54,10 @@ static int media_device_close(struct file *filp) return 0; } -static int media_device_get_info(struct media_device *dev, - struct media_device_info *info) +static long media_device_get_info(struct media_device *dev, void *arg) { + struct media_device_info *info = arg; + memset(info, 0, sizeof(*info)); if (dev->driver_name[0]) @@ -93,9 +94,9 @@ static struct media_entity *find_entity(struct media_device *mdev, u32 id) return NULL; } -static long media_device_enum_entities(struct media_device *mdev, - struct media_entity_desc *entd) +static long media_device_enum_entities(struct media_device *mdev, void *arg) { + struct media_entity_desc *entd = arg; struct media_entity *ent; ent = find_entity(mdev, entd->id); @@ -146,9 +147,9 @@ static void media_device_kpad_to_upad(const struct media_pad *kpad, upad->flags = kpad->flags; } -static long media_device_enum_links(struct media_device *mdev, - struct media_links_enum *links) +static long media_device_enum_links(struct media_device *mdev, void *arg) { + struct media_links_enum *links = arg; struct media_entity *entity; entity = find_entity(mdev, links->entity); @@ -195,9 +196,9 @@ static long media_device_enum_links(struct media_device *mdev, return 0; } -static long media_device_setup_link(struct media_device *mdev, - struct media_link_desc *linkd) +static long media_device_setup_link(struct media_device *mdev, void *arg) { + struct media_link_desc *linkd = arg; struct media_link *link = NULL; struct media_entity *source; struct media_entity *sink; @@ -225,9 +226,9 @@ static long media_device_setup_link(struct media_device *mdev, return __media_entity_setup_link(link, linkd->flags); } -static long media_device_get_topology(struct media_device *mdev, - struct media_v2_topology *topo) +static long media_device_get_topology(struct media_device *mdev, void *arg) { + struct media_v2_topology *topo = arg; struct media_entity *entity; struct media_interface *intf; struct media_pad *pad; diff --git a/drivers/media/pci/bt8xx/bttv-risc.c b/drivers/media/pci/bt8xx/bttv-risc.c index 3859dde98be2..6a6be0b49f70 100644 --- a/drivers/media/pci/bt8xx/bttv-risc.c +++ b/drivers/media/pci/bt8xx/bttv-risc.c @@ -189,20 +189,21 @@ bttv_risc_planar(struct bttv *btv, struct btcx_riscmem *risc, yoffset -= sg_dma_len(ysg); ysg = sg_next(ysg); } - while (uoffset && uoffset >= sg_dma_len(usg)) { - uoffset -= sg_dma_len(usg); - usg = sg_next(usg); - } - while (voffset && voffset >= sg_dma_len(vsg)) { - voffset -= sg_dma_len(vsg); - vsg = sg_next(vsg); - } /* calculate max number of bytes we can write */ ylen = todo; if (yoffset + ylen > sg_dma_len(ysg)) ylen = sg_dma_len(ysg) - yoffset; if (chroma) { + while (uoffset && uoffset >= sg_dma_len(usg)) { + uoffset -= sg_dma_len(usg); + usg = sg_next(usg); + } + while (voffset && voffset >= sg_dma_len(vsg)) { + voffset -= sg_dma_len(vsg); + vsg = sg_next(vsg); + } + if (uoffset + (ylen>>hshift) > sg_dma_len(usg)) ylen = (sg_dma_len(usg) - uoffset) << hshift; if (voffset + (ylen>>hshift) > sg_dma_len(vsg)) diff --git a/drivers/media/pci/bt8xx/dst.c b/drivers/media/pci/bt8xx/dst.c index 4f0bba9e4c48..2e33b7236672 100644 --- a/drivers/media/pci/bt8xx/dst.c +++ b/drivers/media/pci/bt8xx/dst.c @@ -1657,7 +1657,7 @@ static int dst_tune_frontend(struct dvb_frontend* fe, return 0; } -static int dst_get_tuning_algo(struct dvb_frontend *fe) +static enum dvbfe_algo dst_get_tuning_algo(struct dvb_frontend *fe) { return dst_algo ? DVBFE_ALGO_HW : DVBFE_ALGO_SW; } diff --git a/drivers/media/pci/bt8xx/dvb-bt8xx.c b/drivers/media/pci/bt8xx/dvb-bt8xx.c index f60d69ac515b..5ef6e2051d45 100644 --- a/drivers/media/pci/bt8xx/dvb-bt8xx.c +++ b/drivers/media/pci/bt8xx/dvb-bt8xx.c @@ -575,7 +575,6 @@ static struct mt352_config digitv_alps_tded4_config = { }; static struct lgdt330x_config tdvs_tua6034_config = { - .demod_address = 0x0e, .demod_chip = LGDT3303, .serial_mpeg = 0x40, /* TPSERIAL for 3303 in TOP_CONTROL */ }; @@ -614,7 +613,8 @@ static void frontend_init(struct dvb_bt8xx_card *card, u32 type) case BTTV_BOARD_DVICO_FUSIONHDTV_5_LITE: lgdt330x_reset(card); - card->fe = dvb_attach(lgdt330x_attach, &tdvs_tua6034_config, card->i2c_adapter); + card->fe = dvb_attach(lgdt330x_attach, &tdvs_tua6034_config, + 0x0e, card->i2c_adapter); if (card->fe != NULL) { dvb_attach(simple_tuner_attach, card->fe, card->i2c_adapter, 0x61, diff --git a/drivers/media/pci/cx23885/cx23885-dvb.c b/drivers/media/pci/cx23885/cx23885-dvb.c index 114d9bcbe4f4..7d52173073d6 100644 --- a/drivers/media/pci/cx23885/cx23885-dvb.c +++ b/drivers/media/pci/cx23885/cx23885-dvb.c @@ -252,7 +252,6 @@ static struct mt2131_config hauppauge_generic_tunerconfig = { }; static struct lgdt330x_config fusionhdtv_5_express = { - .demod_address = 0x0e, .demod_chip = LGDT3303, .serial_mpeg = 0x40, }; @@ -1321,8 +1320,9 @@ static int dvb_register(struct cx23885_tsport *port) case CX23885_BOARD_DVICO_FUSIONHDTV_5_EXP: i2c_bus = &dev->i2c_bus[0]; fe0->dvb.frontend = dvb_attach(lgdt330x_attach, - &fusionhdtv_5_express, - &i2c_bus->i2c_adap); + &fusionhdtv_5_express, + 0x0e, + &i2c_bus->i2c_adap); if (fe0->dvb.frontend == NULL) break; dvb_attach(simple_tuner_attach, fe0->dvb.frontend, diff --git a/drivers/media/pci/cx88/cx88-dvb.c b/drivers/media/pci/cx88/cx88-dvb.c index 2f886140dd2e..ccfde28d4af2 100644 --- a/drivers/media/pci/cx88/cx88-dvb.c +++ b/drivers/media/pci/cx88/cx88-dvb.c @@ -411,21 +411,18 @@ static int lgdt330x_set_ts_param(struct dvb_frontend *fe, int is_punctured) } static struct lgdt330x_config fusionhdtv_3_gold = { - .demod_address = 0x0e, .demod_chip = LGDT3302, .serial_mpeg = 0x04, /* TPSERIAL for 3302 in TOP_CONTROL */ .set_ts_params = lgdt330x_set_ts_param, }; static const struct lgdt330x_config fusionhdtv_5_gold = { - .demod_address = 0x0e, .demod_chip = LGDT3303, .serial_mpeg = 0x40, /* TPSERIAL for 3303 in TOP_CONTROL */ .set_ts_params = lgdt330x_set_ts_param, }; static const struct lgdt330x_config pchdtv_hd5500 = { - .demod_address = 0x59, .demod_chip = LGDT3303, .serial_mpeg = 0x40, /* TPSERIAL for 3303 in TOP_CONTROL */ .set_ts_params = lgdt330x_set_ts_param, @@ -1237,6 +1234,7 @@ static int dvb_register(struct cx8802_dev *dev) fusionhdtv_3_gold.pll_rf_set = lgdt330x_pll_rf_set; fe0->dvb.frontend = dvb_attach(lgdt330x_attach, &fusionhdtv_3_gold, + 0x0e, &core->i2c_adap); if (fe0->dvb.frontend) { if (!dvb_attach(simple_tuner_attach, fe0->dvb.frontend, @@ -1255,6 +1253,7 @@ static int dvb_register(struct cx8802_dev *dev) mdelay(200); fe0->dvb.frontend = dvb_attach(lgdt330x_attach, &fusionhdtv_3_gold, + 0x0e, &core->i2c_adap); if (fe0->dvb.frontend) { if (!dvb_attach(simple_tuner_attach, fe0->dvb.frontend, @@ -1273,6 +1272,7 @@ static int dvb_register(struct cx8802_dev *dev) mdelay(200); fe0->dvb.frontend = dvb_attach(lgdt330x_attach, &fusionhdtv_5_gold, + 0x0e, &core->i2c_adap); if (fe0->dvb.frontend) { if (!dvb_attach(simple_tuner_attach, fe0->dvb.frontend, @@ -1294,6 +1294,7 @@ static int dvb_register(struct cx8802_dev *dev) mdelay(200); fe0->dvb.frontend = dvb_attach(lgdt330x_attach, &pchdtv_hd5500, + 0x59, &core->i2c_adap); if (fe0->dvb.frontend) { if (!dvb_attach(simple_tuner_attach, fe0->dvb.frontend, diff --git a/drivers/media/pci/cx88/cx88-input.c b/drivers/media/pci/cx88/cx88-input.c index 6f4e6923a91a..2f5debce4905 100644 --- a/drivers/media/pci/cx88/cx88-input.c +++ b/drivers/media/pci/cx88/cx88-input.c @@ -180,7 +180,8 @@ static enum hrtimer_restart cx88_ir_work(struct hrtimer *timer) struct cx88_IR *ir = container_of(timer, struct cx88_IR, timer); cx88_ir_handle_key(ir); - missed = hrtimer_forward_now(&ir->timer, ir->polling * 1000000LL); + missed = hrtimer_forward_now(&ir->timer, + ktime_set(0, ir->polling * 1000000)); if (missed > 1) ir_dprintk("Missed ticks %ld\n", missed - 1); @@ -200,7 +201,8 @@ static int __cx88_ir_start(void *priv) if (ir->polling) { hrtimer_init(&ir->timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL); ir->timer.function = cx88_ir_work; - hrtimer_start(&ir->timer, ir->polling * 1000000LL, + hrtimer_start(&ir->timer, + ktime_set(0, ir->polling * 1000000), HRTIMER_MODE_REL); } if (ir->sampling) { @@ -632,8 +634,9 @@ void cx88_i2c_init_ir(struct cx88_core *core) memset(&core->init_data, 0, sizeof(core->init_data)); if (*addrp == 0x71) { - /* Hauppauge XVR */ - core->init_data.name = "cx88 Hauppauge XVR remote"; + /* Hauppauge Z8F0811 */ + strlcpy(info.type, "ir_z8f0811_haup", I2C_NAME_SIZE); + core->init_data.name = core->board.name; core->init_data.ir_codes = RC_MAP_HAUPPAUGE; core->init_data.type = RC_PROTO_BIT_RC5 | RC_PROTO_BIT_RC6_MCE | RC_PROTO_BIT_RC6_6A_32; diff --git a/drivers/media/pci/cx88/cx88-vbi.c b/drivers/media/pci/cx88/cx88-vbi.c index c637679b01b2..58489ea0c1da 100644 --- a/drivers/media/pci/cx88/cx88-vbi.c +++ b/drivers/media/pci/cx88/cx88-vbi.c @@ -178,7 +178,6 @@ static void buffer_queue(struct vb2_buffer *vb) if (list_empty(&q->active)) { list_add_tail(&buf->list, &q->active); - cx8800_start_vbi_dma(dev, q, buf); dprintk(2, "[%p/%d] vbi_queue - first active\n", buf, buf->vb.vb2_buf.index); diff --git a/drivers/media/pci/ddbridge/Kconfig b/drivers/media/pci/ddbridge/Kconfig index a422dde2f34a..16faef265e97 100644 --- a/drivers/media/pci/ddbridge/Kconfig +++ b/drivers/media/pci/ddbridge/Kconfig @@ -14,6 +14,7 @@ config DVB_DDBRIDGE select MEDIA_TUNER_TDA18212 if MEDIA_SUBDRV_AUTOSELECT select DVB_MXL5XX if MEDIA_SUBDRV_AUTOSELECT select DVB_CXD2099 if MEDIA_SUBDRV_AUTOSELECT + select DVB_DUMMY_FE if MEDIA_SUBDRV_AUTOSELECT ---help--- Support for cards with the Digital Devices PCI express bridge: - Octopus PCIe Bridge diff --git a/drivers/media/pci/ddbridge/Makefile b/drivers/media/pci/ddbridge/Makefile index 745b37d07558..9b9e35f171b7 100644 --- a/drivers/media/pci/ddbridge/Makefile +++ b/drivers/media/pci/ddbridge/Makefile @@ -4,7 +4,7 @@ # ddbridge-objs := ddbridge-main.o ddbridge-core.o ddbridge-ci.o \ - ddbridge-hw.o ddbridge-i2c.o ddbridge-max.o + ddbridge-hw.o ddbridge-i2c.o ddbridge-max.o ddbridge-mci.o obj-$(CONFIG_DVB_DDBRIDGE) += ddbridge.o diff --git a/drivers/media/pci/ddbridge/ddbridge-ci.c b/drivers/media/pci/ddbridge/ddbridge-ci.c index a9dbc4ebf94f..cfe23d02e561 100644 --- a/drivers/media/pci/ddbridge/ddbridge-ci.c +++ b/drivers/media/pci/ddbridge/ddbridge-ci.c @@ -164,7 +164,7 @@ static struct dvb_ca_en50221 en_templ = { static void ci_attach(struct ddb_port *port) { - struct ddb_ci *ci = NULL; + struct ddb_ci *ci; ci = kzalloc(sizeof(*ci), GFP_KERNEL); if (!ci) diff --git a/drivers/media/pci/ddbridge/ddbridge-core.c b/drivers/media/pci/ddbridge/ddbridge-core.c index 90687eff5909..377269c64449 100644 --- a/drivers/media/pci/ddbridge/ddbridge-core.c +++ b/drivers/media/pci/ddbridge/ddbridge-core.c @@ -54,6 +54,7 @@ #include "stv6111.h" #include "lnbh25.h" #include "cxd2099.h" +#include "dvb_dummy_fe.h" /****************************************************************************/ @@ -68,11 +69,53 @@ module_param(adapter_alloc, int, 0444); MODULE_PARM_DESC(adapter_alloc, "0-one adapter per io, 1-one per tab with io, 2-one per tab, 3-one for all"); +static int ci_bitrate = 70000; +module_param(ci_bitrate, int, 0444); +MODULE_PARM_DESC(ci_bitrate, " Bitrate in KHz for output to CI."); + +static int ts_loop = -1; +module_param(ts_loop, int, 0444); +MODULE_PARM_DESC(ts_loop, "TS in/out test loop on port ts_loop"); + +static int xo2_speed = 2; +module_param(xo2_speed, int, 0444); +MODULE_PARM_DESC(xo2_speed, "default transfer speed for xo2 based duoflex, 0=55,1=75,2=90,3=104 MBit/s, default=2, use attribute to change for individual cards"); + +#ifdef __arm__ +static int alt_dma = 1; +#else +static int alt_dma; +#endif +module_param(alt_dma, int, 0444); +MODULE_PARM_DESC(alt_dma, "use alternative DMA buffer handling"); + +static int no_init; +module_param(no_init, int, 0444); +MODULE_PARM_DESC(no_init, "do not initialize most devices"); + +static int stv0910_single; +module_param(stv0910_single, int, 0444); +MODULE_PARM_DESC(stv0910_single, "use stv0910 cards as single demods"); + +static int dma_buf_num = 8; +module_param(dma_buf_num, int, 0444); +MODULE_PARM_DESC(dma_buf_num, "Number of DMA buffers, possible values: 8-32"); + +static int dma_buf_size = 21; +module_param(dma_buf_size, int, 0444); +MODULE_PARM_DESC(dma_buf_size, + "DMA buffer size as multiple of 128*47, possible values: 1-43"); + +static int dummy_tuner; +module_param(dummy_tuner, int, 0444); +MODULE_PARM_DESC(dummy_tuner, + "attach dummy tuner to port 0 on Octopus V3 or Octopus Mini cards"); + /****************************************************************************/ static DEFINE_MUTEX(redirect_lock); -struct workqueue_struct *ddb_wq; +static struct workqueue_struct *ddb_wq; static struct ddb *ddbs[DDB_MAX_ADAPTER]; @@ -80,6 +123,16 @@ static struct ddb *ddbs[DDB_MAX_ADAPTER]; /****************************************************************************/ /****************************************************************************/ +struct ddb_irq *ddb_irq_set(struct ddb *dev, u32 link, u32 nr, + void (*handler)(void *), void *data) +{ + struct ddb_irq *irq = &dev->link[link].irq[nr]; + + irq->handler = handler; + irq->data = data; + return irq; +} + static void ddb_set_dma_table(struct ddb_io *io) { struct ddb *dev = io->port->dev; @@ -410,13 +463,11 @@ static void ddb_output_start(struct ddb_output *output) struct ddb *dev = output->port->dev; u32 con = 0x11c, con2 = 0; - if (output->dma) { - spin_lock_irq(&output->dma->lock); - output->dma->cbuf = 0; - output->dma->coff = 0; - output->dma->stat = 0; - ddbwritel(dev, 0, DMA_BUFFER_CONTROL(output->dma)); - } + spin_lock_irq(&output->dma->lock); + output->dma->cbuf = 0; + output->dma->coff = 0; + output->dma->stat = 0; + ddbwritel(dev, 0, DMA_BUFFER_CONTROL(output->dma)); if (output->port->input[0]->port->class == DDB_PORT_LOOP) con = (1UL << 13) | 0x14; @@ -429,36 +480,29 @@ static void ddb_output_start(struct ddb_output *output) ddbwritel(dev, con, TS_CONTROL(output)); ddbwritel(dev, con2, TS_CONTROL2(output)); - if (output->dma) { - ddbwritel(dev, output->dma->bufval, - DMA_BUFFER_SIZE(output->dma)); - ddbwritel(dev, 0, DMA_BUFFER_ACK(output->dma)); - ddbwritel(dev, 1, DMA_BASE_READ); - ddbwritel(dev, 7, DMA_BUFFER_CONTROL(output->dma)); - } + ddbwritel(dev, output->dma->bufval, + DMA_BUFFER_SIZE(output->dma)); + ddbwritel(dev, 0, DMA_BUFFER_ACK(output->dma)); + ddbwritel(dev, 1, DMA_BASE_READ); + ddbwritel(dev, 7, DMA_BUFFER_CONTROL(output->dma)); ddbwritel(dev, con | 1, TS_CONTROL(output)); - if (output->dma) { - output->dma->running = 1; - spin_unlock_irq(&output->dma->lock); - } + output->dma->running = 1; + spin_unlock_irq(&output->dma->lock); } static void ddb_output_stop(struct ddb_output *output) { struct ddb *dev = output->port->dev; - if (output->dma) - spin_lock_irq(&output->dma->lock); + spin_lock_irq(&output->dma->lock); ddbwritel(dev, 0, TS_CONTROL(output)); - if (output->dma) { - ddbwritel(dev, 0, DMA_BUFFER_CONTROL(output->dma)); - output->dma->running = 0; - spin_unlock_irq(&output->dma->lock); - } + ddbwritel(dev, 0, DMA_BUFFER_CONTROL(output->dma)); + output->dma->running = 0; + spin_unlock_irq(&output->dma->lock); } static void ddb_input_stop(struct ddb_input *input) @@ -466,45 +510,42 @@ static void ddb_input_stop(struct ddb_input *input) struct ddb *dev = input->port->dev; u32 tag = DDB_LINK_TAG(input->port->lnr); - if (input->dma) - spin_lock_irq(&input->dma->lock); + spin_lock_irq(&input->dma->lock); + ddbwritel(dev, 0, tag | TS_CONTROL(input)); - if (input->dma) { - ddbwritel(dev, 0, DMA_BUFFER_CONTROL(input->dma)); - input->dma->running = 0; - spin_unlock_irq(&input->dma->lock); - } + + ddbwritel(dev, 0, DMA_BUFFER_CONTROL(input->dma)); + input->dma->running = 0; + spin_unlock_irq(&input->dma->lock); } static void ddb_input_start(struct ddb_input *input) { struct ddb *dev = input->port->dev; - if (input->dma) { - spin_lock_irq(&input->dma->lock); - input->dma->cbuf = 0; - input->dma->coff = 0; - input->dma->stat = 0; - ddbwritel(dev, 0, DMA_BUFFER_CONTROL(input->dma)); - } + spin_lock_irq(&input->dma->lock); + input->dma->cbuf = 0; + input->dma->coff = 0; + input->dma->stat = 0; + ddbwritel(dev, 0, DMA_BUFFER_CONTROL(input->dma)); + ddbwritel(dev, 0, TS_CONTROL(input)); ddbwritel(dev, 2, TS_CONTROL(input)); ddbwritel(dev, 0, TS_CONTROL(input)); - if (input->dma) { - ddbwritel(dev, input->dma->bufval, - DMA_BUFFER_SIZE(input->dma)); - ddbwritel(dev, 0, DMA_BUFFER_ACK(input->dma)); - ddbwritel(dev, 1, DMA_BASE_WRITE); - ddbwritel(dev, 3, DMA_BUFFER_CONTROL(input->dma)); - } + ddbwritel(dev, input->dma->bufval, + DMA_BUFFER_SIZE(input->dma)); + ddbwritel(dev, 0, DMA_BUFFER_ACK(input->dma)); + ddbwritel(dev, 1, DMA_BASE_WRITE); + ddbwritel(dev, 3, DMA_BUFFER_CONTROL(input->dma)); ddbwritel(dev, 0x09, TS_CONTROL(input)); - if (input->dma) { - input->dma->running = 1; - spin_unlock_irq(&input->dma->lock); - } + if (input->port->type == DDB_TUNER_DUMMY) + ddbwritel(dev, 0x000fff01, TS_CONTROL2(input)); + + input->dma->running = 1; + spin_unlock_irq(&input->dma->lock); } static void ddb_input_start_all(struct ddb_input *input) @@ -549,12 +590,12 @@ static u32 ddb_output_free(struct ddb_output *output) if (output->dma->cbuf != idx) { if ((((output->dma->cbuf + 1) % output->dma->num) == idx) && - (output->dma->size - output->dma->coff <= 188)) + (output->dma->size - output->dma->coff <= (2 * 188))) return 0; return 188; } diff = off - output->dma->coff; - if (diff <= 0 || diff > 188) + if (diff <= 0 || diff > (2 * 188)) return 188; return 0; } @@ -1208,6 +1249,20 @@ static int tuner_attach_stv6111(struct ddb_input *input, int type) return 0; } +static int demod_attach_dummy(struct ddb_input *input) +{ + struct ddb_dvb *dvb = &input->port->dvb[input->nr & 1]; + struct device *dev = input->port->dev->dev; + + dvb->fe = dvb_attach(dvb_dummy_fe_qam_attach); + if (!dvb->fe) { + dev_err(dev, "QAM dummy attach failed!\n"); + return -ENODEV; + } + + return 0; +} + static int start_feed(struct dvb_demux_feed *dvbdmxfeed) { struct dvb_demux *dvbdmx = dvbdmxfeed->demux; @@ -1500,6 +1555,14 @@ static int dvb_input_attach(struct ddb_input *input) if (tuner_attach_tda18212(input, port->type) < 0) goto err_tuner; break; + case DDB_TUNER_DUMMY: + if (demod_attach_dummy(input) < 0) + goto err_detach; + break; + case DDB_TUNER_MCI: + if (ddb_fe_attach_mci(input) < 0) + goto err_detach; + break; default: return 0; } @@ -1762,6 +1825,15 @@ static void ddb_port_probe(struct ddb_port *port) /* Handle missing ports and ports without I2C */ + if (dummy_tuner && !port->nr && + dev->link[0].ids.device == 0x0005) { + port->name = "DUMMY"; + port->class = DDB_PORT_TUNER; + port->type = DDB_TUNER_DUMMY; + port->type_name = "DUMMY"; + return; + } + if (port->nr == ts_loop) { port->name = "TS LOOP"; port->class = DDB_PORT_LOOP; @@ -1786,6 +1858,16 @@ static void ddb_port_probe(struct ddb_port *port) return; } + if (dev->link[l].info->type == DDB_OCTOPUS_MCI) { + if (port->nr >= dev->link[l].info->mci) + return; + port->name = "DUAL MCI"; + port->type_name = "MCI"; + port->class = DDB_PORT_TUNER; + port->type = DDB_TUNER_MCI; + return; + } + if (port->nr > 1 && dev->link[l].info->type == DDB_OCTOPUS_CI) { port->name = "CI internal"; port->type_name = "INTERNAL"; @@ -2081,39 +2163,39 @@ static void input_work(struct work_struct *work) spin_unlock_irqrestore(&dma->lock, flags); } -static void input_handler(unsigned long data) +static void input_handler(void *data) { struct ddb_input *input = (struct ddb_input *)data; struct ddb_dma *dma = input->dma; - /* - * If there is no input connected, input_tasklet() will - * just copy pointers and ACK. So, there is no need to go - * through the tasklet scheduler. - */ - if (input->redi) - queue_work(ddb_wq, &dma->work); - else - input_work(&dma->work); + queue_work(ddb_wq, &dma->work); } -static void output_handler(unsigned long data) +static void output_work(struct work_struct *work) { - struct ddb_output *output = (struct ddb_output *)data; - struct ddb_dma *dma = output->dma; + struct ddb_dma *dma = container_of(work, struct ddb_dma, work); + struct ddb_output *output = (struct ddb_output *)dma->io; struct ddb *dev = output->port->dev; + unsigned long flags; - spin_lock(&dma->lock); - if (!dma->running) { - spin_unlock(&dma->lock); - return; - } + spin_lock_irqsave(&dma->lock, flags); + if (!dma->running) + goto unlock_exit; dma->stat = ddbreadl(dev, DMA_BUFFER_CURRENT(dma)); dma->ctrl = ddbreadl(dev, DMA_BUFFER_CONTROL(dma)); if (output->redi) output_ack_input(output, output->redi); wake_up(&dma->wq); - spin_unlock(&dma->lock); +unlock_exit: + spin_unlock_irqrestore(&dma->lock, flags); +} + +static void output_handler(void *data) +{ + struct ddb_output *output = (struct ddb_output *)data; + struct ddb_dma *dma = output->dma; + + queue_work(ddb_wq, &dma->work); } /****************************************************************************/ @@ -2146,18 +2228,19 @@ static void ddb_dma_init(struct ddb_io *io, int nr, int out) spin_lock_init(&dma->lock); init_waitqueue_head(&dma->wq); if (out) { + INIT_WORK(&dma->work, output_work); dma->regs = rm->odma->base + rm->odma->size * nr; dma->bufregs = rm->odma_buf->base + rm->odma_buf->size * nr; - dma->num = OUTPUT_DMA_BUFS; - dma->size = OUTPUT_DMA_SIZE; - dma->div = OUTPUT_DMA_IRQ_DIV; + dma->num = dma_buf_num; + dma->size = dma_buf_size * 128 * 47; + dma->div = 1; } else { INIT_WORK(&dma->work, input_work); dma->regs = rm->idma->base + rm->idma->size * nr; dma->bufregs = rm->idma_buf->base + rm->idma_buf->size * nr; - dma->num = INPUT_DMA_BUFS; - dma->size = INPUT_DMA_SIZE; - dma->div = INPUT_DMA_IRQ_DIV; + dma->num = dma_buf_num; + dma->size = dma_buf_size * 128 * 47; + dma->div = 1; } ddbwritel(io->port->dev, 0, DMA_BUFFER_ACK(dma)); dev_dbg(io->port->dev->dev, "init link %u, io %u, dma %u, dmaregs %08x bufregs %08x\n", @@ -2190,8 +2273,7 @@ static void ddb_input_init(struct ddb_port *port, int nr, int pnr, int anr) dev_dbg(dev->dev, "init link %u, input %u, handler %u\n", port->lnr, nr, dma_nr + base); - dev->handler[0][dma_nr + base] = input_handler; - dev->handler_data[0][dma_nr + base] = (unsigned long)input; + ddb_irq_set(dev, 0, dma_nr + base, &input_handler, input); ddb_dma_init(input, dma_nr, 0); } } @@ -2216,8 +2298,7 @@ static void ddb_output_init(struct ddb_port *port, int nr) const struct ddb_regmap *rm0 = io_regmap(output, 0); u32 base = rm0->irq_base_odma; - dev->handler[0][nr + base] = output_handler; - dev->handler_data[0][nr + base] = (unsigned long)output; + ddb_irq_set(dev, 0, nr + base, &output_handler, output); ddb_dma_init(output, nr, 1); } } @@ -2329,6 +2410,7 @@ void ddb_ports_init(struct ddb *dev) break; case DDB_OCTOPUS_MAX: case DDB_OCTOPUS_MAX_CT: + case DDB_OCTOPUS_MCI: ddb_input_init(port, 2 * i, 0, 2 * p); ddb_input_init(port, 2 * i + 1, 1, 2 * p + 1); break; @@ -2361,73 +2443,62 @@ void ddb_ports_release(struct ddb *dev) /****************************************************************************/ #define IRQ_HANDLE(_nr) \ - do { if ((s & (1UL << ((_nr) & 0x1f))) && dev->handler[0][_nr]) \ - dev->handler[0][_nr](dev->handler_data[0][_nr]); } \ + do { if ((s & (1UL << ((_nr) & 0x1f))) && \ + dev->link[0].irq[_nr].handler) \ + dev->link[0].irq[_nr].handler(dev->link[0].irq[_nr].data); } \ while (0) +#define IRQ_HANDLE_NIBBLE(_shift) { \ + if (s & (0x0000000f << ((_shift) & 0x1f))) { \ + IRQ_HANDLE(0 + (_shift)); \ + IRQ_HANDLE(1 + (_shift)); \ + IRQ_HANDLE(2 + (_shift)); \ + IRQ_HANDLE(3 + (_shift)); \ + } \ +} + +#define IRQ_HANDLE_BYTE(_shift) { \ + if (s & (0x000000ff << ((_shift) & 0x1f))) { \ + IRQ_HANDLE(0 + (_shift)); \ + IRQ_HANDLE(1 + (_shift)); \ + IRQ_HANDLE(2 + (_shift)); \ + IRQ_HANDLE(3 + (_shift)); \ + IRQ_HANDLE(4 + (_shift)); \ + IRQ_HANDLE(5 + (_shift)); \ + IRQ_HANDLE(6 + (_shift)); \ + IRQ_HANDLE(7 + (_shift)); \ + } \ +} + static void irq_handle_msg(struct ddb *dev, u32 s) { dev->i2c_irq++; - IRQ_HANDLE(0); - IRQ_HANDLE(1); - IRQ_HANDLE(2); - IRQ_HANDLE(3); + IRQ_HANDLE_NIBBLE(0); } static void irq_handle_io(struct ddb *dev, u32 s) { dev->ts_irq++; - if ((s & 0x000000f0)) { - IRQ_HANDLE(4); - IRQ_HANDLE(5); - IRQ_HANDLE(6); - IRQ_HANDLE(7); - } - if ((s & 0x0000ff00)) { - IRQ_HANDLE(8); - IRQ_HANDLE(9); - IRQ_HANDLE(10); - IRQ_HANDLE(11); - IRQ_HANDLE(12); - IRQ_HANDLE(13); - IRQ_HANDLE(14); - IRQ_HANDLE(15); - } - if ((s & 0x00ff0000)) { - IRQ_HANDLE(16); - IRQ_HANDLE(17); - IRQ_HANDLE(18); - IRQ_HANDLE(19); - IRQ_HANDLE(20); - IRQ_HANDLE(21); - IRQ_HANDLE(22); - IRQ_HANDLE(23); - } - if ((s & 0xff000000)) { - IRQ_HANDLE(24); - IRQ_HANDLE(25); - IRQ_HANDLE(26); - IRQ_HANDLE(27); - IRQ_HANDLE(28); - IRQ_HANDLE(29); - IRQ_HANDLE(30); - IRQ_HANDLE(31); - } + IRQ_HANDLE_NIBBLE(4); + IRQ_HANDLE_BYTE(8); + IRQ_HANDLE_BYTE(16); + IRQ_HANDLE_BYTE(24); } irqreturn_t ddb_irq_handler0(int irq, void *dev_id) { struct ddb *dev = (struct ddb *)dev_id; - u32 s = ddbreadl(dev, INTERRUPT_STATUS); + u32 mask = 0x8fffff00; + u32 s = mask & ddbreadl(dev, INTERRUPT_STATUS); + if (!s) + return IRQ_NONE; do { if (s & 0x80000000) return IRQ_NONE; - if (!(s & 0xfffff00)) - return IRQ_NONE; - ddbwritel(dev, s & 0xfffff00, INTERRUPT_ACK); + ddbwritel(dev, s, INTERRUPT_ACK); irq_handle_io(dev, s); - } while ((s = ddbreadl(dev, INTERRUPT_STATUS))); + } while ((s = mask & ddbreadl(dev, INTERRUPT_STATUS))); return IRQ_HANDLED; } @@ -2435,16 +2506,17 @@ irqreturn_t ddb_irq_handler0(int irq, void *dev_id) irqreturn_t ddb_irq_handler1(int irq, void *dev_id) { struct ddb *dev = (struct ddb *)dev_id; - u32 s = ddbreadl(dev, INTERRUPT_STATUS); + u32 mask = 0x8000000f; + u32 s = mask & ddbreadl(dev, INTERRUPT_STATUS); + if (!s) + return IRQ_NONE; do { if (s & 0x80000000) return IRQ_NONE; - if (!(s & 0x0000f)) - return IRQ_NONE; - ddbwritel(dev, s & 0x0000f, INTERRUPT_ACK); + ddbwritel(dev, s, INTERRUPT_ACK); irq_handle_msg(dev, s); - } while ((s = ddbreadl(dev, INTERRUPT_STATUS))); + } while ((s = mask & ddbreadl(dev, INTERRUPT_STATUS))); return IRQ_HANDLED; } @@ -3027,7 +3099,7 @@ static struct class ddb_class = { .devnode = ddb_devnode, }; -int ddb_class_create(void) +static int ddb_class_create(void) { ddb_major = register_chrdev(0, DDB_NAME, &ddb_fops); if (ddb_major < 0) @@ -3037,7 +3109,7 @@ int ddb_class_create(void) return 0; } -void ddb_class_destroy(void) +static void ddb_class_destroy(void) { class_unregister(&ddb_class); unregister_chrdev(ddb_major, DDB_NAME); @@ -3173,7 +3245,7 @@ static void tempmon_setfan(struct ddb_link *link) ddblwritel(link, (pwm << 8), TEMPMON_FANCONTROL); } -static void temp_handler(unsigned long data) +static void temp_handler(void *data) { struct ddb_link *link = (struct ddb_link *)data; @@ -3196,8 +3268,7 @@ static int tempmon_init(struct ddb_link *link, int first_time) memcpy(link->temp_tab, temperature_table, sizeof(temperature_table)); } - dev->handler[l][link->info->tempmon_irq] = temp_handler; - dev->handler_data[l][link->info->tempmon_irq] = (unsigned long)link; + ddb_irq_set(dev, l, link->info->tempmon_irq, temp_handler, link); ddblwritel(link, (TEMPMON_CONTROL_OVERTEMP | TEMPMON_CONTROL_AUTOSCAN | TEMPMON_CONTROL_INTENABLE), TEMPMON_CONTROL); @@ -3309,3 +3380,38 @@ void ddb_unmap(struct ddb *dev) iounmap(dev->regs); vfree(dev); } + +int ddb_exit_ddbridge(int stage, int error) +{ + switch (stage) { + default: + case 2: + destroy_workqueue(ddb_wq); + /* fall-through */ + case 1: + ddb_class_destroy(); + break; + } + + return error; +} + +int ddb_init_ddbridge(void) +{ + if (dma_buf_num < 8) + dma_buf_num = 8; + if (dma_buf_num > 32) + dma_buf_num = 32; + if (dma_buf_size < 1) + dma_buf_size = 1; + if (dma_buf_size > 43) + dma_buf_size = 43; + + if (ddb_class_create() < 0) + return -1; + ddb_wq = alloc_workqueue("ddbridge", 0, 0); + if (!ddb_wq) + return ddb_exit_ddbridge(1, -1); + + return 0; +} diff --git a/drivers/media/pci/ddbridge/ddbridge-hw.c b/drivers/media/pci/ddbridge/ddbridge-hw.c index c6d14925e2fc..1d3ee6accdd5 100644 --- a/drivers/media/pci/ddbridge/ddbridge-hw.c +++ b/drivers/media/pci/ddbridge/ddbridge-hw.c @@ -311,6 +311,16 @@ static const struct ddb_info ddb_s2_48 = { .tempmon_irq = 24, }; +static const struct ddb_info ddb_s2x_48 = { + .type = DDB_OCTOPUS_MCI, + .name = "Digital Devices MAX SX8", + .regmap = &octopus_map, + .port_num = 4, + .i2c_mask = 0x00, + .tempmon_irq = 24, + .mci = 4 +}; + /****************************************************************************/ /****************************************************************************/ /****************************************************************************/ @@ -346,6 +356,7 @@ static const struct ddb_device_id ddb_device_ids[] = { DDB_DEVID(0x0008, 0x0036, ddb_isdbt_8), DDB_DEVID(0x0008, 0x0037, ddb_c2t2i_v0_8), DDB_DEVID(0x0008, 0x0038, ddb_c2t2i_8), + DDB_DEVID(0x0009, 0x0025, ddb_s2x_48), DDB_DEVID(0x0006, 0x0039, ddb_ctv7), DDB_DEVID(0x0011, 0x0040, ddb_ci), DDB_DEVID(0x0011, 0x0041, ddb_cis), diff --git a/drivers/media/pci/ddbridge/ddbridge-i2c.c b/drivers/media/pci/ddbridge/ddbridge-i2c.c index 82a9a0e806fc..667340c86ea7 100644 --- a/drivers/media/pci/ddbridge/ddbridge-i2c.c +++ b/drivers/media/pci/ddbridge/ddbridge-i2c.c @@ -147,7 +147,7 @@ void ddb_i2c_release(struct ddb *dev) } } -static void i2c_handler(unsigned long priv) +static void i2c_handler(void *priv) { struct ddb_i2c *i2c = (struct ddb_i2c *)priv; @@ -210,8 +210,7 @@ int ddb_i2c_init(struct ddb *dev) if (!(dev->link[l].info->i2c_mask & (1 << i))) continue; i2c = &dev->i2c[num]; - dev->handler_data[l][i + base] = (unsigned long)i2c; - dev->handler[l][i + base] = i2c_handler; + ddb_irq_set(dev, l, i + base, i2c_handler, i2c); stat = ddb_i2c_add(dev, i2c, regmap, l, i, num); if (stat) break; diff --git a/drivers/media/pci/ddbridge/ddbridge-main.c b/drivers/media/pci/ddbridge/ddbridge-main.c index 26497d6b1395..f4748cfd904b 100644 --- a/drivers/media/pci/ddbridge/ddbridge-main.c +++ b/drivers/media/pci/ddbridge/ddbridge-main.c @@ -55,34 +55,6 @@ MODULE_PARM_DESC(msi, "Control MSI interrupts: 0-disable (default), 1-enable"); #endif #endif -int ci_bitrate = 70000; -module_param(ci_bitrate, int, 0444); -MODULE_PARM_DESC(ci_bitrate, " Bitrate in KHz for output to CI."); - -int ts_loop = -1; -module_param(ts_loop, int, 0444); -MODULE_PARM_DESC(ts_loop, "TS in/out test loop on port ts_loop"); - -int xo2_speed = 2; -module_param(xo2_speed, int, 0444); -MODULE_PARM_DESC(xo2_speed, "default transfer speed for xo2 based duoflex, 0=55,1=75,2=90,3=104 MBit/s, default=2, use attribute to change for individual cards"); - -#ifdef __arm__ -int alt_dma = 1; -#else -int alt_dma; -#endif -module_param(alt_dma, int, 0444); -MODULE_PARM_DESC(alt_dma, "use alternative DMA buffer handling"); - -int no_init; -module_param(no_init, int, 0444); -MODULE_PARM_DESC(no_init, "do not initialize most devices"); - -int stv0910_single; -module_param(stv0910_single, int, 0444); -MODULE_PARM_DESC(stv0910_single, "use stv0910 cards as single demods"); - /****************************************************************************/ /****************************************************************************/ /****************************************************************************/ @@ -93,18 +65,22 @@ static void ddb_irq_disable(struct ddb *dev) ddbwritel(dev, 0, MSI1_ENABLE); } -static void ddb_irq_exit(struct ddb *dev) +static void ddb_msi_exit(struct ddb *dev) { - ddb_irq_disable(dev); - if (dev->msi == 2) - free_irq(dev->pdev->irq + 1, dev); - free_irq(dev->pdev->irq, dev); #ifdef CONFIG_PCI_MSI if (dev->msi) - pci_disable_msi(dev->pdev); + pci_free_irq_vectors(dev->pdev); #endif } +static void ddb_irq_exit(struct ddb *dev) +{ + ddb_irq_disable(dev); + if (dev->msi == 2) + free_irq(pci_irq_vector(dev->pdev, 1), dev); + free_irq(pci_irq_vector(dev->pdev, 0), dev); +} + static void ddb_remove(struct pci_dev *pdev) { struct ddb *dev = (struct ddb *)pci_get_drvdata(pdev); @@ -114,6 +90,7 @@ static void ddb_remove(struct pci_dev *pdev) ddb_i2c_release(dev); ddb_irq_exit(dev); + ddb_msi_exit(dev); ddb_ports_release(dev); ddb_buffers_free(dev); @@ -128,7 +105,8 @@ static void ddb_irq_msi(struct ddb *dev, int nr) int stat; if (msi && pci_msi_enabled()) { - stat = pci_alloc_irq_vectors(dev->pdev, 1, nr, PCI_IRQ_MSI); + stat = pci_alloc_irq_vectors(dev->pdev, 1, nr, + PCI_IRQ_MSI | PCI_IRQ_MSIX); if (stat >= 1) { dev->msi = stat; dev_info(dev->dev, "using %d MSI interrupt(s)\n", @@ -160,21 +138,24 @@ static int ddb_irq_init(struct ddb *dev) if (dev->msi) irq_flag = 0; if (dev->msi == 2) { - stat = request_irq(dev->pdev->irq, ddb_irq_handler0, - irq_flag, "ddbridge", (void *)dev); + stat = request_irq(pci_irq_vector(dev->pdev, 0), + ddb_irq_handler0, irq_flag, "ddbridge", + (void *)dev); if (stat < 0) return stat; - stat = request_irq(dev->pdev->irq + 1, ddb_irq_handler1, - irq_flag, "ddbridge", (void *)dev); + stat = request_irq(pci_irq_vector(dev->pdev, 1), + ddb_irq_handler1, irq_flag, "ddbridge", + (void *)dev); if (stat < 0) { - free_irq(dev->pdev->irq, dev); + free_irq(pci_irq_vector(dev->pdev, 0), dev); return stat; } } else #endif { - stat = request_irq(dev->pdev->irq, ddb_irq_handler, - irq_flag, "ddbridge", (void *)dev); + stat = request_irq(pci_irq_vector(dev->pdev, 0), + ddb_irq_handler, irq_flag, "ddbridge", + (void *)dev); if (stat < 0) return stat; } @@ -217,6 +198,7 @@ static int ddb_probe(struct pci_dev *pdev, dev->link[0].ids.device = id->device; dev->link[0].ids.subvendor = id->subvendor; dev->link[0].ids.subdevice = pdev->subsystem_device; + dev->link[0].ids.devid = (id->device << 16) | id->vendor; dev->link[0].dev = dev; dev->link[0].info = get_ddb_info(id->vendor, id->device, @@ -258,8 +240,7 @@ static int ddb_probe(struct pci_dev *pdev, ddb_irq_exit(dev); fail0: dev_err(&pdev->dev, "fail0\n"); - if (dev->msi) - pci_disable_msi(dev->pdev); + ddb_msi_exit(dev); fail: dev_err(&pdev->dev, "fail\n"); @@ -283,6 +264,7 @@ static const struct pci_device_id ddb_id_table[] = { DDB_DEVICE_ANY(0x0006), DDB_DEVICE_ANY(0x0007), DDB_DEVICE_ANY(0x0008), + DDB_DEVICE_ANY(0x0009), DDB_DEVICE_ANY(0x0011), DDB_DEVICE_ANY(0x0012), DDB_DEVICE_ANY(0x0013), @@ -310,32 +292,25 @@ static struct pci_driver ddb_pci_driver = { static __init int module_init_ddbridge(void) { - int stat = -1; + int stat; pr_info("Digital Devices PCIE bridge driver " DDBRIDGE_VERSION ", Copyright (C) 2010-17 Digital Devices GmbH\n"); - if (ddb_class_create() < 0) - return -1; - ddb_wq = create_workqueue("ddbridge"); - if (!ddb_wq) - goto exit1; + stat = ddb_init_ddbridge(); + if (stat < 0) + return stat; stat = pci_register_driver(&ddb_pci_driver); if (stat < 0) - goto exit2; - return stat; -exit2: - destroy_workqueue(ddb_wq); -exit1: - ddb_class_destroy(); + ddb_exit_ddbridge(0, stat); + return stat; } static __exit void module_exit_ddbridge(void) { pci_unregister_driver(&ddb_pci_driver); - destroy_workqueue(ddb_wq); - ddb_class_destroy(); + ddb_exit_ddbridge(0, 0); } module_init(module_init_ddbridge); diff --git a/drivers/media/pci/ddbridge/ddbridge-max.c b/drivers/media/pci/ddbridge/ddbridge-max.c index dc6b81488746..739e4b444cf4 100644 --- a/drivers/media/pci/ddbridge/ddbridge-max.c +++ b/drivers/media/pci/ddbridge/ddbridge-max.c @@ -33,6 +33,7 @@ #include "ddbridge.h" #include "ddbridge-regs.h" #include "ddbridge-io.h" +#include "ddbridge-mci.h" #include "ddbridge-max.h" #include "mxl5xx.h" @@ -452,3 +453,44 @@ int ddb_fe_attach_mxl5xx(struct ddb_input *input) dvb->input = tuner; return 0; } + +/******************************************************************************/ +/* MAX MCI related functions */ + +int ddb_fe_attach_mci(struct ddb_input *input) +{ + struct ddb *dev = input->port->dev; + struct ddb_dvb *dvb = &input->port->dvb[input->nr & 1]; + struct ddb_port *port = input->port; + struct ddb_link *link = &dev->link[port->lnr]; + int demod, tuner; + + demod = input->nr; + tuner = demod & 3; + if (fmode == 3) + tuner = 0; + dvb->fe = ddb_mci_attach(input, 0, demod, &dvb->set_input); + if (!dvb->fe) { + dev_err(dev->dev, "No MAXSX8 found!\n"); + return -ENODEV; + } + if (!dvb->set_input) { + dev_err(dev->dev, "No MCI set_input function pointer!\n"); + return -ENODEV; + } + if (input->nr < 4) { + lnb_command(dev, port->lnr, input->nr, LNB_CMD_INIT); + lnb_set_voltage(dev, port->lnr, input->nr, SEC_VOLTAGE_OFF); + } + ddb_lnb_init_fmode(dev, link, fmode); + + dvb->fe->ops.set_voltage = max_set_voltage; + dvb->fe->ops.enable_high_lnb_voltage = max_enable_high_lnb_voltage; + dvb->fe->ops.set_tone = max_set_tone; + dvb->diseqc_send_master_cmd = dvb->fe->ops.diseqc_send_master_cmd; + dvb->fe->ops.diseqc_send_master_cmd = max_send_master_cmd; + dvb->fe->ops.diseqc_send_burst = max_send_burst; + dvb->fe->sec_priv = input; + dvb->input = tuner; + return 0; +} diff --git a/drivers/media/pci/ddbridge/ddbridge-max.h b/drivers/media/pci/ddbridge/ddbridge-max.h index bf8bf38739f6..82efc53baa94 100644 --- a/drivers/media/pci/ddbridge/ddbridge-max.h +++ b/drivers/media/pci/ddbridge/ddbridge-max.h @@ -25,5 +25,6 @@ int ddb_lnb_init_fmode(struct ddb *dev, struct ddb_link *link, u32 fm); int ddb_fe_attach_mxl5xx(struct ddb_input *input); +int ddb_fe_attach_mci(struct ddb_input *input); #endif /* _DDBRIDGE_MAX_H */ diff --git a/drivers/media/pci/ddbridge/ddbridge-mci.c b/drivers/media/pci/ddbridge/ddbridge-mci.c new file mode 100644 index 000000000000..a85ff3e6b919 --- /dev/null +++ b/drivers/media/pci/ddbridge/ddbridge-mci.c @@ -0,0 +1,550 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * ddbridge-mci.c: Digital Devices microcode interface + * + * Copyright (C) 2017 Digital Devices GmbH + * Ralph Metzler <rjkm@metzlerbros.de> + * Marcus Metzler <mocm@metzlerbros.de> + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * version 2 only, as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + */ + +#include "ddbridge.h" +#include "ddbridge-io.h" +#include "ddbridge-mci.h" + +static LIST_HEAD(mci_list); + +static const u32 MCLK = (1550000000 / 12); +static const u32 MAX_DEMOD_LDPC_BITRATE = (1550000000 / 6); +static const u32 MAX_LDPC_BITRATE = (720000000); + +struct mci_base { + struct list_head mci_list; + void *key; + struct ddb_link *link; + struct completion completion; + + struct device *dev; + struct mutex tuner_lock; /* concurrent tuner access lock */ + u8 adr; + struct mutex mci_lock; /* concurrent MCI access lock */ + int count; + + u8 tuner_use_count[4]; + u8 assigned_demod[8]; + u32 used_ldpc_bitrate[8]; + u8 demod_in_use[8]; + u32 iq_mode; +}; + +struct mci { + struct mci_base *base; + struct dvb_frontend fe; + int nr; + int demod; + int tuner; + int first_time_lock; + int started; + struct mci_result signal_info; + + u32 bb_mode; +}; + +static int mci_reset(struct mci *state) +{ + struct ddb_link *link = state->base->link; + u32 status = 0; + u32 timeout = 40; + + ddblwritel(link, MCI_CONTROL_RESET, MCI_CONTROL); + ddblwritel(link, 0, MCI_CONTROL + 4); /* 1= no internal init */ + msleep(300); + ddblwritel(link, 0, MCI_CONTROL); + + while (1) { + status = ddblreadl(link, MCI_CONTROL); + if ((status & MCI_CONTROL_READY) == MCI_CONTROL_READY) + break; + if (--timeout == 0) + break; + msleep(50); + } + if ((status & MCI_CONTROL_READY) == 0) + return -1; + if (link->ids.device == 0x0009) + ddblwritel(link, SX8_TSCONFIG_MODE_NORMAL, SX8_TSCONFIG); + return 0; +} + +static int mci_config(struct mci *state, u32 config) +{ + struct ddb_link *link = state->base->link; + + if (link->ids.device != 0x0009) + return -EINVAL; + ddblwritel(link, config, SX8_TSCONFIG); + return 0; +} + +static int _mci_cmd_unlocked(struct mci *state, + u32 *cmd, u32 cmd_len, + u32 *res, u32 res_len) +{ + struct ddb_link *link = state->base->link; + u32 i, val; + unsigned long stat; + + val = ddblreadl(link, MCI_CONTROL); + if (val & (MCI_CONTROL_RESET | MCI_CONTROL_START_COMMAND)) + return -EIO; + if (cmd && cmd_len) + for (i = 0; i < cmd_len; i++) + ddblwritel(link, cmd[i], MCI_COMMAND + i * 4); + val |= (MCI_CONTROL_START_COMMAND | MCI_CONTROL_ENABLE_DONE_INTERRUPT); + ddblwritel(link, val, MCI_CONTROL); + + stat = wait_for_completion_timeout(&state->base->completion, HZ); + if (stat == 0) { + dev_warn(state->base->dev, "MCI-%d: MCI timeout\n", state->nr); + return -EIO; + } + if (res && res_len) + for (i = 0; i < res_len; i++) + res[i] = ddblreadl(link, MCI_RESULT + i * 4); + return 0; +} + +static int mci_cmd(struct mci *state, + struct mci_command *command, + struct mci_result *result) +{ + int stat; + + mutex_lock(&state->base->mci_lock); + stat = _mci_cmd_unlocked(state, + (u32 *)command, sizeof(*command) / sizeof(u32), + (u32 *)result, sizeof(*result) / sizeof(u32)); + mutex_unlock(&state->base->mci_lock); + return stat; +} + +static void mci_handler(void *priv) +{ + struct mci_base *base = (struct mci_base *)priv; + + complete(&base->completion); +} + +static void release(struct dvb_frontend *fe) +{ + struct mci *state = fe->demodulator_priv; + + state->base->count--; + if (state->base->count == 0) { + list_del(&state->base->mci_list); + kfree(state->base); + } + kfree(state); +} + +static int read_status(struct dvb_frontend *fe, enum fe_status *status) +{ + int stat; + struct mci *state = fe->demodulator_priv; + struct mci_command cmd; + struct mci_result res; + + cmd.command = MCI_CMD_GETSTATUS; + cmd.demod = state->demod; + stat = mci_cmd(state, &cmd, &res); + if (stat) + return stat; + *status = 0x00; + if (res.status == SX8_DEMOD_WAIT_MATYPE) + *status = 0x0f; + if (res.status == SX8_DEMOD_LOCKED) + *status = 0x1f; + return stat; +} + +static int mci_set_tuner(struct dvb_frontend *fe, u32 tuner, u32 on) +{ + struct mci *state = fe->demodulator_priv; + struct mci_command cmd; + + memset(&cmd, 0, sizeof(cmd)); + cmd.tuner = state->tuner; + cmd.command = on ? SX8_CMD_INPUT_ENABLE : SX8_CMD_INPUT_DISABLE; + return mci_cmd(state, &cmd, NULL); +} + +static int stop(struct dvb_frontend *fe) +{ + struct mci *state = fe->demodulator_priv; + struct mci_command cmd; + u32 input = state->tuner; + + memset(&cmd, 0, sizeof(cmd)); + if (state->demod != 0xff) { + cmd.command = MCI_CMD_STOP; + cmd.demod = state->demod; + mci_cmd(state, &cmd, NULL); + if (state->base->iq_mode) { + cmd.command = MCI_CMD_STOP; + cmd.demod = state->demod; + cmd.output = 0; + mci_cmd(state, &cmd, NULL); + mci_config(state, SX8_TSCONFIG_MODE_NORMAL); + } + } + mutex_lock(&state->base->tuner_lock); + state->base->tuner_use_count[input]--; + if (!state->base->tuner_use_count[input]) + mci_set_tuner(fe, input, 0); + state->base->demod_in_use[state->demod] = 0; + state->base->used_ldpc_bitrate[state->nr] = 0; + state->demod = 0xff; + state->base->assigned_demod[state->nr] = 0xff; + state->base->iq_mode = 0; + mutex_unlock(&state->base->tuner_lock); + state->started = 0; + return 0; +} + +static int start(struct dvb_frontend *fe, u32 flags, u32 modmask, u32 ts_config) +{ + struct mci *state = fe->demodulator_priv; + struct dtv_frontend_properties *p = &fe->dtv_property_cache; + u32 used_ldpc_bitrate = 0, free_ldpc_bitrate; + u32 used_demods = 0; + struct mci_command cmd; + u32 input = state->tuner; + u32 bits_per_symbol = 0; + int i, stat = 0; + + if (p->symbol_rate >= (MCLK / 2)) + flags &= ~1; + if ((flags & 3) == 0) + return -EINVAL; + + if (flags & 2) { + u32 tmp = modmask; + + bits_per_symbol = 1; + while (tmp & 1) { + tmp >>= 1; + bits_per_symbol++; + } + } + + mutex_lock(&state->base->tuner_lock); + if (state->base->iq_mode) { + stat = -EBUSY; + goto unlock; + } + for (i = 0; i < 8; i++) { + used_ldpc_bitrate += state->base->used_ldpc_bitrate[i]; + if (state->base->demod_in_use[i]) + used_demods++; + } + if (used_ldpc_bitrate >= MAX_LDPC_BITRATE || + ((ts_config & SX8_TSCONFIG_MODE_MASK) > + SX8_TSCONFIG_MODE_NORMAL && used_demods > 0)) { + stat = -EBUSY; + goto unlock; + } + free_ldpc_bitrate = MAX_LDPC_BITRATE - used_ldpc_bitrate; + if (free_ldpc_bitrate > MAX_DEMOD_LDPC_BITRATE) + free_ldpc_bitrate = MAX_DEMOD_LDPC_BITRATE; + + while (p->symbol_rate * bits_per_symbol > free_ldpc_bitrate) + bits_per_symbol--; + + if (bits_per_symbol < 2) { + stat = -EBUSY; + goto unlock; + } + i = (p->symbol_rate > (MCLK / 2)) ? 3 : 7; + while (i >= 0 && state->base->demod_in_use[i]) + i--; + if (i < 0) { + stat = -EBUSY; + goto unlock; + } + state->base->demod_in_use[i] = 1; + state->base->used_ldpc_bitrate[state->nr] = p->symbol_rate + * bits_per_symbol; + state->demod = i; + state->base->assigned_demod[state->nr] = i; + + if (!state->base->tuner_use_count[input]) + mci_set_tuner(fe, input, 1); + state->base->tuner_use_count[input]++; + state->base->iq_mode = (ts_config > 1); +unlock: + mutex_unlock(&state->base->tuner_lock); + if (stat) + return stat; + memset(&cmd, 0, sizeof(cmd)); + + if (state->base->iq_mode) { + cmd.command = SX8_CMD_SELECT_IQOUT; + cmd.demod = state->demod; + cmd.output = 0; + mci_cmd(state, &cmd, NULL); + mci_config(state, ts_config); + } + if (p->stream_id != NO_STREAM_ID_FILTER && p->stream_id != 0x80000000) + flags |= 0x80; + dev_dbg(state->base->dev, "MCI-%d: tuner=%d demod=%d\n", + state->nr, state->tuner, state->demod); + cmd.command = MCI_CMD_SEARCH_DVBS; + cmd.dvbs2_search.flags = flags; + cmd.dvbs2_search.s2_modulation_mask = + modmask & ((1 << (bits_per_symbol - 1)) - 1); + cmd.dvbs2_search.retry = 2; + cmd.dvbs2_search.frequency = p->frequency * 1000; + cmd.dvbs2_search.symbol_rate = p->symbol_rate; + cmd.dvbs2_search.scrambling_sequence_index = + p->scrambling_sequence_index; + cmd.dvbs2_search.input_stream_id = + (p->stream_id != NO_STREAM_ID_FILTER) ? p->stream_id : 0; + cmd.tuner = state->tuner; + cmd.demod = state->demod; + cmd.output = state->nr; + if (p->stream_id == 0x80000000) + cmd.output |= 0x80; + stat = mci_cmd(state, &cmd, NULL); + if (stat) + stop(fe); + return stat; +} + +static int start_iq(struct dvb_frontend *fe, u32 ts_config) +{ + struct mci *state = fe->demodulator_priv; + struct dtv_frontend_properties *p = &fe->dtv_property_cache; + u32 used_demods = 0; + struct mci_command cmd; + u32 input = state->tuner; + int i, stat = 0; + + mutex_lock(&state->base->tuner_lock); + if (state->base->iq_mode) { + stat = -EBUSY; + goto unlock; + } + for (i = 0; i < 8; i++) + if (state->base->demod_in_use[i]) + used_demods++; + if (used_demods > 0) { + stat = -EBUSY; + goto unlock; + } + state->demod = 0; + state->base->assigned_demod[state->nr] = 0; + if (!state->base->tuner_use_count[input]) + mci_set_tuner(fe, input, 1); + state->base->tuner_use_count[input]++; + state->base->iq_mode = (ts_config > 1); +unlock: + mutex_unlock(&state->base->tuner_lock); + if (stat) + return stat; + + memset(&cmd, 0, sizeof(cmd)); + cmd.command = SX8_CMD_START_IQ; + cmd.dvbs2_search.frequency = p->frequency * 1000; + cmd.dvbs2_search.symbol_rate = p->symbol_rate; + cmd.tuner = state->tuner; + cmd.demod = state->demod; + cmd.output = 7; + mci_config(state, ts_config); + stat = mci_cmd(state, &cmd, NULL); + if (stat) + stop(fe); + return stat; +} + +static int set_parameters(struct dvb_frontend *fe) +{ + int stat = 0; + struct mci *state = fe->demodulator_priv; + struct dtv_frontend_properties *p = &fe->dtv_property_cache; + u32 ts_config, iq_mode = 0, isi; + + if (state->started) + stop(fe); + + isi = p->stream_id; + if (isi != NO_STREAM_ID_FILTER) + iq_mode = (isi & 0x30000000) >> 28; + + switch (iq_mode) { + case 1: + ts_config = (SX8_TSCONFIG_TSHEADER | SX8_TSCONFIG_MODE_IQ); + break; + case 2: + ts_config = (SX8_TSCONFIG_TSHEADER | SX8_TSCONFIG_MODE_IQ); + break; + default: + ts_config = SX8_TSCONFIG_MODE_NORMAL; + break; + } + + if (iq_mode != 2) { + u32 flags = 3; + u32 mask = 3; + + if (p->modulation == APSK_16 || + p->modulation == APSK_32) { + flags = 2; + mask = 15; + } + stat = start(fe, flags, mask, ts_config); + } else { + stat = start_iq(fe, ts_config); + } + + if (!stat) { + state->started = 1; + state->first_time_lock = 1; + state->signal_info.status = SX8_DEMOD_WAIT_SIGNAL; + } + + return stat; +} + +static int tune(struct dvb_frontend *fe, bool re_tune, + unsigned int mode_flags, + unsigned int *delay, enum fe_status *status) +{ + int r; + + if (re_tune) { + r = set_parameters(fe); + if (r) + return r; + } + r = read_status(fe, status); + if (r) + return r; + + if (*status & FE_HAS_LOCK) + return 0; + *delay = HZ / 10; + return 0; +} + +static enum dvbfe_algo get_algo(struct dvb_frontend *fe) +{ + return DVBFE_ALGO_HW; +} + +static int set_input(struct dvb_frontend *fe, int input) +{ + struct mci *state = fe->demodulator_priv; + + state->tuner = input; + dev_dbg(state->base->dev, "MCI-%d: input=%d\n", state->nr, input); + return 0; +} + +static struct dvb_frontend_ops mci_ops = { + .delsys = { SYS_DVBS, SYS_DVBS2 }, + .info = { + .name = "Digital Devices MaxSX8 MCI DVB-S/S2/S2X", + .frequency_min = 950000, + .frequency_max = 2150000, + .frequency_stepsize = 0, + .frequency_tolerance = 0, + .symbol_rate_min = 100000, + .symbol_rate_max = 100000000, + .caps = FE_CAN_INVERSION_AUTO | + FE_CAN_FEC_AUTO | + FE_CAN_QPSK | + FE_CAN_2G_MODULATION | + FE_CAN_MULTISTREAM, + }, + .get_frontend_algo = get_algo, + .tune = tune, + .release = release, + .read_status = read_status, +}; + +static struct mci_base *match_base(void *key) +{ + struct mci_base *p; + + list_for_each_entry(p, &mci_list, mci_list) + if (p->key == key) + return p; + return NULL; +} + +static int probe(struct mci *state) +{ + mci_reset(state); + return 0; +} + +struct dvb_frontend +*ddb_mci_attach(struct ddb_input *input, + int mci_type, int nr, + int (**fn_set_input)(struct dvb_frontend *, int)) +{ + struct ddb_port *port = input->port; + struct ddb *dev = port->dev; + struct ddb_link *link = &dev->link[port->lnr]; + struct mci_base *base; + struct mci *state; + void *key = mci_type ? (void *)port : (void *)link; + + state = kzalloc(sizeof(*state), GFP_KERNEL); + if (!state) + return NULL; + + base = match_base(key); + if (base) { + base->count++; + state->base = base; + } else { + base = kzalloc(sizeof(*base), GFP_KERNEL); + if (!base) + goto fail; + base->key = key; + base->count = 1; + base->link = link; + base->dev = dev->dev; + mutex_init(&base->mci_lock); + mutex_init(&base->tuner_lock); + ddb_irq_set(dev, link->nr, 0, mci_handler, base); + init_completion(&base->completion); + state->base = base; + if (probe(state) < 0) { + kfree(base); + goto fail; + } + list_add(&base->mci_list, &mci_list); + } + state->fe.ops = mci_ops; + state->fe.demodulator_priv = state; + state->nr = nr; + *fn_set_input = set_input; + + state->tuner = nr; + state->demod = nr; + + return &state->fe; +fail: + kfree(state); + return NULL; +} diff --git a/drivers/media/pci/ddbridge/ddbridge-mci.h b/drivers/media/pci/ddbridge/ddbridge-mci.h new file mode 100644 index 000000000000..c4193c5ee095 --- /dev/null +++ b/drivers/media/pci/ddbridge/ddbridge-mci.h @@ -0,0 +1,152 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * ddbridge-mci.h: Digital Devices micro code interface + * + * Copyright (C) 2017 Digital Devices GmbH + * Marcus Metzler <mocm@metzlerbros.de> + * Ralph Metzler <rjkm@metzlerbros.de> + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * version 2 only, as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + */ + +#ifndef _DDBRIDGE_MCI_H_ +#define _DDBRIDGE_MCI_H_ + +#define MCI_CONTROL (0x500) +#define MCI_COMMAND (0x600) +#define MCI_RESULT (0x680) + +#define MCI_COMMAND_SIZE (0x80) +#define MCI_RESULT_SIZE (0x80) + +#define MCI_CONTROL_START_COMMAND (0x00000001) +#define MCI_CONTROL_ENABLE_DONE_INTERRUPT (0x00000002) +#define MCI_CONTROL_RESET (0x00008000) +#define MCI_CONTROL_READY (0x00010000) + +#define SX8_TSCONFIG (0x280) + +#define SX8_TSCONFIG_MODE_MASK (0x00000003) +#define SX8_TSCONFIG_MODE_OFF (0x00000000) +#define SX8_TSCONFIG_MODE_NORMAL (0x00000001) +#define SX8_TSCONFIG_MODE_IQ (0x00000003) + +#define SX8_TSCONFIG_TSHEADER (0x00000004) +#define SX8_TSCONFIG_BURST (0x00000008) + +#define SX8_TSCONFIG_BURSTSIZE_MASK (0x00000030) +#define SX8_TSCONFIG_BURSTSIZE_2K (0x00000000) +#define SX8_TSCONFIG_BURSTSIZE_4K (0x00000010) +#define SX8_TSCONFIG_BURSTSIZE_8K (0x00000020) +#define SX8_TSCONFIG_BURSTSIZE_16K (0x00000030) + +#define SX8_DEMOD_STOPPED (0) +#define SX8_DEMOD_IQ_MODE (1) +#define SX8_DEMOD_WAIT_SIGNAL (2) +#define SX8_DEMOD_WAIT_MATYPE (3) +#define SX8_DEMOD_TIMEOUT (14) +#define SX8_DEMOD_LOCKED (15) + +#define MCI_CMD_STOP (0x01) +#define MCI_CMD_GETSTATUS (0x02) +#define MCI_CMD_GETSIGNALINFO (0x03) +#define MCI_CMD_RFPOWER (0x04) + +#define MCI_CMD_SEARCH_DVBS (0x10) + +#define MCI_CMD_GET_IQSYMBOL (0x30) + +#define SX8_CMD_INPUT_ENABLE (0x40) +#define SX8_CMD_INPUT_DISABLE (0x41) +#define SX8_CMD_START_IQ (0x42) +#define SX8_CMD_STOP_IQ (0x43) +#define SX8_CMD_SELECT_IQOUT (0x44) +#define SX8_CMD_SELECT_TSOUT (0x45) + +#define SX8_ERROR_UNSUPPORTED (0x80) + +#define SX8_SUCCESS(status) (status < SX8_ERROR_UNSUPPORTED) + +#define SX8_CMD_DIAG_READ8 (0xE0) +#define SX8_CMD_DIAG_READ32 (0xE1) +#define SX8_CMD_DIAG_WRITE8 (0xE2) +#define SX8_CMD_DIAG_WRITE32 (0xE3) + +#define SX8_CMD_DIAG_READRF (0xE8) +#define SX8_CMD_DIAG_WRITERF (0xE9) + +struct mci_command { + union { + u32 command_word; + struct { + u8 command; + u8 tuner; + u8 demod; + u8 output; + }; + }; + union { + u32 params[31]; + struct { + u8 flags; + u8 s2_modulation_mask; + u8 rsvd1; + u8 retry; + u32 frequency; + u32 symbol_rate; + u8 input_stream_id; + u8 rsvd2[3]; + u32 scrambling_sequence_index; + } dvbs2_search; + }; +}; + +struct mci_result { + union { + u32 status_word; + struct { + u8 status; + u8 rsvd; + u16 time; + }; + }; + union { + u32 result[27]; + struct { + u8 standard; + /* puncture rate for DVB-S */ + u8 pls_code; + /* 7-6: rolloff, 5-2: rsrvd, 1:short, 0:pilots */ + u8 roll_off; + u8 rsvd; + u32 frequency; + u32 symbol_rate; + s16 channel_power; + s16 band_power; + s16 signal_to_noise; + s16 rsvd2; + u32 packet_errors; + u32 ber_numerator; + u32 ber_denominator; + } dvbs2_signal_info; + struct { + u8 i_symbol; + u8 q_symbol; + } dvbs2_signal_iq; + }; + u32 version[4]; +}; + +struct dvb_frontend +*ddb_mci_attach(struct ddb_input *input, + int mci_type, int nr, + int (**fn_set_input)(struct dvb_frontend *, int)); + +#endif /* _DDBRIDGE_MCI_H_ */ diff --git a/drivers/media/pci/ddbridge/ddbridge-regs.h b/drivers/media/pci/ddbridge/ddbridge-regs.h index 23d74ff83fe4..b978b5991940 100644 --- a/drivers/media/pci/ddbridge/ddbridge-regs.h +++ b/drivers/media/pci/ddbridge/ddbridge-regs.h @@ -17,6 +17,9 @@ * http://www.gnu.org/copyleft/gpl.html */ +#ifndef __DDBRIDGE_REGS_H__ +#define __DDBRIDGE_REGS_H__ + /* ------------------------------------------------------------------------- */ /* SPI Controller */ @@ -154,3 +157,4 @@ #define LNB_BUF_LEVEL(i) (LNB_BASE + (i) * 0x20 + 0x10) #define LNB_BUF_WRITE(i) (LNB_BASE + (i) * 0x20 + 0x14) +#endif /* __DDBRIDGE_REGS_H__ */ diff --git a/drivers/media/pci/ddbridge/ddbridge.h b/drivers/media/pci/ddbridge/ddbridge.h index f223dc6c9963..a66b1125cc74 100644 --- a/drivers/media/pci/ddbridge/ddbridge.h +++ b/drivers/media/pci/ddbridge/ddbridge.h @@ -63,7 +63,7 @@ #include <media/dvb_ca_en50221.h> #include <media/dvb_net.h> -#define DDBRIDGE_VERSION "0.9.32-integrated" +#define DDBRIDGE_VERSION "0.9.33-integrated" #define DDB_MAX_I2C 32 #define DDB_MAX_PORT 32 @@ -112,11 +112,12 @@ struct ddb_ids { struct ddb_info { int type; -#define DDB_NONE 0 -#define DDB_OCTOPUS 1 -#define DDB_OCTOPUS_CI 2 -#define DDB_OCTOPUS_MAX 5 +#define DDB_NONE 0 +#define DDB_OCTOPUS 1 +#define DDB_OCTOPUS_CI 2 +#define DDB_OCTOPUS_MAX 5 #define DDB_OCTOPUS_MAX_CT 6 +#define DDB_OCTOPUS_MCI 9 char *name; u32 i2c_mask; u8 port_num; @@ -133,23 +134,12 @@ struct ddb_info { #define TS_QUIRK_REVERSED 2 #define TS_QUIRK_ALT_OSC 8 u32 tempmon_irq; + u8 mci; const struct ddb_regmap *regmap; }; -/* DMA_SIZE MUST be smaller than 256k and - * MUST be divisible by 188 and 128 !!! - */ - #define DMA_MAX_BUFS 32 /* hardware table limit */ -#define INPUT_DMA_BUFS 8 -#define INPUT_DMA_SIZE (128 * 47 * 21) -#define INPUT_DMA_IRQ_DIV 1 - -#define OUTPUT_DMA_BUFS 8 -#define OUTPUT_DMA_SIZE (128 * 47 * 21) -#define OUTPUT_DMA_IRQ_DIV 1 - struct ddb; struct ddb_port; @@ -248,6 +238,7 @@ struct ddb_port { char *name; char *type_name; u32 type; +#define DDB_TUNER_DUMMY 0xffffffff #define DDB_TUNER_NONE 0 #define DDB_TUNER_DVBS_ST 1 #define DDB_TUNER_DVBS_ST_AA 2 @@ -264,6 +255,7 @@ struct ddb_port { #define DDB_CI_EXTERNAL_XO2_B 13 #define DDB_TUNER_DVBS_STV0910_PR 14 #define DDB_TUNER_DVBC2T2I_SONY_P 15 +#define DDB_TUNER_MCI 16 #define DDB_TUNER_XO2 32 #define DDB_TUNER_DVBS_STV0910 (DDB_TUNER_XO2 + 0) @@ -305,6 +297,11 @@ struct ddb_lnb { u32 fmode; }; +struct ddb_irq { + void (*handler)(void *); + void *data; +}; + struct ddb_link { struct ddb *dev; const struct ddb_info *info; @@ -319,6 +316,7 @@ struct ddb_link { spinlock_t temp_lock; /* lock temp chip access */ int overtemperature_error; u8 temp_tab[11]; + struct ddb_irq irq[256]; }; struct ddb { @@ -343,9 +341,6 @@ struct ddb { struct ddb_dma idma[DDB_MAX_INPUT]; struct ddb_dma odma[DDB_MAX_OUTPUT]; - void (*handler[4][256])(unsigned long); - unsigned long handler_data[4][256]; - struct device *ddb_dev; u32 ddb_dev_users; u32 nr; @@ -368,16 +363,9 @@ int ddbridge_flashread(struct ddb *dev, u32 link, u8 *buf, u32 addr, u32 len); /****************************************************************************/ -/* ddbridge-main.c (modparams) */ -extern int ci_bitrate; -extern int ts_loop; -extern int xo2_speed; -extern int alt_dma; -extern int no_init; -extern int stv0910_single; -extern struct workqueue_struct *ddb_wq; - /* ddbridge-core.c */ +struct ddb_irq *ddb_irq_set(struct ddb *dev, u32 link, u32 nr, + void (*handler)(void *), void *data); void ddb_ports_detach(struct ddb *dev); void ddb_ports_release(struct ddb *dev); void ddb_buffers_free(struct ddb *dev); @@ -389,9 +377,9 @@ void ddb_ports_init(struct ddb *dev); int ddb_buffers_alloc(struct ddb *dev); int ddb_ports_attach(struct ddb *dev); int ddb_device_create(struct ddb *dev); -int ddb_class_create(void); -void ddb_class_destroy(void); int ddb_init(struct ddb *dev); void ddb_unmap(struct ddb *dev); +int ddb_exit_ddbridge(int stage, int error); +int ddb_init_ddbridge(void); #endif /* DDBRIDGE_H */ diff --git a/drivers/media/pci/intel/ipu3/Kconfig b/drivers/media/pci/intel/ipu3/Kconfig index a82d3fe277d2..fdae26b2bef0 100644 --- a/drivers/media/pci/intel/ipu3/Kconfig +++ b/drivers/media/pci/intel/ipu3/Kconfig @@ -2,18 +2,17 @@ config VIDEO_IPU3_CIO2 tristate "Intel ipu3-cio2 driver" depends on VIDEO_V4L2 && PCI depends on VIDEO_V4L2_SUBDEV_API - depends on X86 || COMPILE_TEST + depends on (X86 && ACPI) || COMPILE_TEST depends on MEDIA_CONTROLLER depends on HAS_DMA - depends on ACPI select V4L2_FWNODE select VIDEOBUF2_DMA_SG ---help--- - This is the Intel IPU3 CIO2 CSI-2 receiver unit, found in Intel - Skylake and Kaby Lake SoCs and used for capturing images and - video from a camera sensor. + This is the Intel IPU3 CIO2 CSI-2 receiver unit, found in Intel + Skylake and Kaby Lake SoCs and used for capturing images and + video from a camera sensor. - Say Y or M here if you have a Skylake/Kaby Lake SoC with MIPI CSI-2 - connected camera. - The module will be called ipu3-cio2. + Say Y or M here if you have a Skylake/Kaby Lake SoC with MIPI CSI-2 + connected camera. + The module will be called ipu3-cio2. diff --git a/drivers/media/pci/intel/ipu3/ipu3-cio2.c b/drivers/media/pci/intel/ipu3/ipu3-cio2.c index 7d768ec0f824..29027159eced 100644 --- a/drivers/media/pci/intel/ipu3/ipu3-cio2.c +++ b/drivers/media/pci/intel/ipu3/ipu3-cio2.c @@ -640,18 +640,10 @@ static const char *const cio2_port_errs[] = { "PKT2LONG", }; -static irqreturn_t cio2_irq(int irq, void *cio2_ptr) +static void cio2_irq_handle_once(struct cio2_device *cio2, u32 int_status) { - struct cio2_device *cio2 = cio2_ptr; void __iomem *const base = cio2->base; struct device *dev = &cio2->pci_dev->dev; - u32 int_status, int_clear; - - int_status = readl(base + CIO2_REG_INT_STS); - int_clear = int_status; - - if (!int_status) - return IRQ_NONE; if (int_status & CIO2_INT_IOOE) { /* @@ -770,9 +762,29 @@ static irqreturn_t cio2_irq(int irq, void *cio2_ptr) int_status &= ~(CIO2_INT_IOIE | CIO2_INT_IOIRQ); } - writel(int_clear, base + CIO2_REG_INT_STS); if (int_status) dev_warn(dev, "unknown interrupt 0x%x on INT\n", int_status); +} + +static irqreturn_t cio2_irq(int irq, void *cio2_ptr) +{ + struct cio2_device *cio2 = cio2_ptr; + void __iomem *const base = cio2->base; + struct device *dev = &cio2->pci_dev->dev; + u32 int_status; + + int_status = readl(base + CIO2_REG_INT_STS); + dev_dbg(dev, "isr enter - interrupt status 0x%x\n", int_status); + if (!int_status) + return IRQ_NONE; + + do { + writel(int_status, base + CIO2_REG_INT_STS); + cio2_irq_handle_once(cio2, int_status); + int_status = readl(base + CIO2_REG_INT_STS); + if (int_status) + dev_dbg(dev, "pending status 0x%x\n", int_status); + } while (int_status); return IRQ_HANDLED; } diff --git a/drivers/media/pci/mantis/mantis_uart.c b/drivers/media/pci/mantis/mantis_uart.c index 18f81c135996..b7765687e0c3 100644 --- a/drivers/media/pci/mantis/mantis_uart.c +++ b/drivers/media/pci/mantis/mantis_uart.c @@ -92,6 +92,7 @@ static void mantis_uart_work(struct work_struct *work) { struct mantis_pci *mantis = container_of(work, struct mantis_pci, uart_work); u32 stat; + unsigned long timeout; stat = mmread(MANTIS_UART_STAT); @@ -102,9 +103,15 @@ static void mantis_uart_work(struct work_struct *work) * MANTIS_UART_RXFIFO_DATA is only set if at least * config->bytes + 1 bytes are in the FIFO. */ + + /* FIXME: is 10ms good enough ? */ + timeout = jiffies + msecs_to_jiffies(10); while (stat & MANTIS_UART_RXFIFO_DATA) { mantis_uart_read(mantis); stat = mmread(MANTIS_UART_STAT); + + if (!time_is_after_jiffies(timeout)) + break; } /* re-enable UART (RX) interrupt */ diff --git a/drivers/media/pci/meye/Kconfig b/drivers/media/pci/meye/Kconfig index b4bf848be5a0..2e60334ffef5 100644 --- a/drivers/media/pci/meye/Kconfig +++ b/drivers/media/pci/meye/Kconfig @@ -1,6 +1,7 @@ config VIDEO_MEYE tristate "Sony Vaio Picturebook Motion Eye Video For Linux" - depends on PCI && SONY_LAPTOP && VIDEO_V4L2 + depends on PCI && VIDEO_V4L2 + depends on SONY_LAPTOP || COMPILE_TEST ---help--- This is the video4linux driver for the Motion Eye camera found in the Vaio Picturebook laptops. Please read the material in diff --git a/drivers/media/pci/ngene/ngene-cards.c b/drivers/media/pci/ngene/ngene-cards.c index 65fc8f23ad86..7738565193d6 100644 --- a/drivers/media/pci/ngene/ngene-cards.c +++ b/drivers/media/pci/ngene/ngene-cards.c @@ -137,11 +137,6 @@ static int tuner_attach_stv6110(struct ngene_channel *chan) chan->dev->card_info->tuner_config[chan->number]; const struct stv6110x_devctl *ctl; - if (chan->number < 2) - i2c = &chan->dev->channel[0].i2c_adapter; - else - i2c = &chan->dev->channel[1].i2c_adapter; - ctl = dvb_attach(stv6110x_attach, chan->fe, tunerconf, i2c); if (ctl == NULL) { dev_err(pdev, "No STV6110X found!\n"); @@ -304,14 +299,6 @@ static int demod_attach_stv0900(struct ngene_channel *chan) struct stv090x_config *feconf = (struct stv090x_config *) chan->dev->card_info->fe_config[chan->number]; - /* tuner 1+2: i2c adapter #0, tuner 3+4: i2c adapter #1 */ - /* Note: Both adapters share the same i2c bus, but the demod */ - /* driver requires that each demod has its own i2c adapter */ - if (chan->number < 2) - i2c = &chan->dev->channel[0].i2c_adapter; - else - i2c = &chan->dev->channel[1].i2c_adapter; - chan->fe = dvb_attach(stv090x_attach, feconf, i2c, (chan->number & 1) == 0 ? STV090x_DEMODULATOR_0 : STV090x_DEMODULATOR_1); @@ -721,7 +708,6 @@ static int cineS2_probe(struct ngene_channel *chan) static struct lgdt330x_config aver_m780 = { - .demod_address = 0xb2 >> 1, .demod_chip = LGDT3303, .serial_mpeg = 0x00, /* PARALLEL */ .clock_polarity_flip = 1, @@ -738,7 +724,8 @@ static int demod_attach_lg330x(struct ngene_channel *chan) { struct device *pdev = &chan->dev->pci_dev->dev; - chan->fe = dvb_attach(lgdt330x_attach, &aver_m780, &chan->i2c_adapter); + chan->fe = dvb_attach(lgdt330x_attach, &aver_m780, + 0xb2 >> 1, &chan->i2c_adapter); if (chan->fe == NULL) { dev_err(pdev, "No LGDT330x found!\n"); return -ENODEV; diff --git a/drivers/media/pci/ngene/ngene-dvb.c b/drivers/media/pci/ngene/ngene-dvb.c index fee89b9ed9c1..5147e83397a1 100644 --- a/drivers/media/pci/ngene/ngene-dvb.c +++ b/drivers/media/pci/ngene/ngene-dvb.c @@ -40,7 +40,7 @@ static int ci_tsfix = 1; module_param(ci_tsfix, int, 0444); -MODULE_PARM_DESC(ci_tsfix, "Detect and fix TS buffer offset shifs in conjunction with CI expansions (default: 1/enabled)"); +MODULE_PARM_DESC(ci_tsfix, "Detect and fix TS buffer offset shifts in conjunction with CI expansions (default: 1/enabled)"); /****************************************************************************/ /* COMMAND API interface ****************************************************/ diff --git a/drivers/media/pci/pt1/Kconfig b/drivers/media/pci/pt1/Kconfig index 24501d5bf70d..2718b4c6b7c6 100644 --- a/drivers/media/pci/pt1/Kconfig +++ b/drivers/media/pci/pt1/Kconfig @@ -1,6 +1,9 @@ config DVB_PT1 tristate "PT1 cards" depends on DVB_CORE && PCI && I2C + select DVB_TC90522 if MEDIA_SUBDRV_AUTOSELECT + select DVB_PLL if MEDIA_SUBDRV_AUTOSELECT + select MEDIA_TUNER_QM1D1B0004 if MEDIA_SUBDRV_AUTOSELECT help Support for Earthsoft PT1 PCI cards. diff --git a/drivers/media/pci/pt1/Makefile b/drivers/media/pci/pt1/Makefile index ab873ae088a0..bc491e08dd63 100644 --- a/drivers/media/pci/pt1/Makefile +++ b/drivers/media/pci/pt1/Makefile @@ -1,5 +1,6 @@ -earth-pt1-objs := pt1.o va1j5jf8007s.o va1j5jf8007t.o +earth-pt1-objs := pt1.o obj-$(CONFIG_DVB_PT1) += earth-pt1.o ccflags-y += -Idrivers/media/dvb-frontends +ccflags-y += -Idrivers/media/tuners diff --git a/drivers/media/pci/pt1/pt1.c b/drivers/media/pci/pt1/pt1.c index 4f6867af8311..5708f69622cc 100644 --- a/drivers/media/pci/pt1/pt1.c +++ b/drivers/media/pci/pt1/pt1.c @@ -18,7 +18,10 @@ */ #include <linux/kernel.h> +#include <linux/sched.h> #include <linux/sched/signal.h> +#include <linux/hrtimer.h> +#include <linux/delay.h> #include <linux/module.h> #include <linux/slab.h> #include <linux/vmalloc.h> @@ -26,6 +29,8 @@ #include <linux/kthread.h> #include <linux/freezer.h> #include <linux/ratelimit.h> +#include <linux/string.h> +#include <linux/i2c.h> #include <media/dvbdev.h> #include <media/dvb_demux.h> @@ -33,8 +38,9 @@ #include <media/dvb_net.h> #include <media/dvb_frontend.h> -#include "va1j5jf8007t.h" -#include "va1j5jf8007s.h" +#include "tc90522.h" +#include "qm1d1b0004.h" +#include "dvb-pll.h" #define DRIVER_NAME "earth-pt1" @@ -63,6 +69,11 @@ struct pt1_table { struct pt1_buffer bufs[PT1_NR_BUFS]; }; +enum pt1_fe_clk { + PT1_FE_CLK_20MHZ, /* PT1 */ + PT1_FE_CLK_25MHZ, /* PT2 */ +}; + #define PT1_NR_ADAPS 4 struct pt1_adapter; @@ -81,6 +92,8 @@ struct pt1 { struct mutex lock; int power; int reset; + + enum pt1_fe_clk fe_clk; }; struct pt1_adapter { @@ -97,6 +110,8 @@ struct pt1_adapter { int users; struct dmxdev dmxdev; struct dvb_frontend *fe; + struct i2c_client *demod_i2c_client; + struct i2c_client *tuner_i2c_client; int (*orig_set_voltage)(struct dvb_frontend *fe, enum fe_sec_voltage voltage); int (*orig_sleep)(struct dvb_frontend *fe); @@ -106,6 +121,145 @@ struct pt1_adapter { int sleep; }; +union pt1_tuner_config { + struct qm1d1b0004_config qm1d1b0004; + struct dvb_pll_config tda6651; +}; + +struct pt1_config { + struct i2c_board_info demod_info; + struct tc90522_config demod_cfg; + + struct i2c_board_info tuner_info; + union pt1_tuner_config tuner_cfg; +}; + +static const struct pt1_config pt1_configs[PT1_NR_ADAPS] = { + { + .demod_info = { + I2C_BOARD_INFO(TC90522_I2C_DEV_SAT, 0x1b), + }, + .tuner_info = { + I2C_BOARD_INFO("qm1d1b0004", 0x60), + }, + }, + { + .demod_info = { + I2C_BOARD_INFO(TC90522_I2C_DEV_TER, 0x1a), + }, + .tuner_info = { + I2C_BOARD_INFO("tda665x_earthpt1", 0x61), + }, + }, + { + .demod_info = { + I2C_BOARD_INFO(TC90522_I2C_DEV_SAT, 0x19), + }, + .tuner_info = { + I2C_BOARD_INFO("qm1d1b0004", 0x60), + }, + }, + { + .demod_info = { + I2C_BOARD_INFO(TC90522_I2C_DEV_TER, 0x18), + }, + .tuner_info = { + I2C_BOARD_INFO("tda665x_earthpt1", 0x61), + }, + }, +}; + +static const u8 va1j5jf8007s_20mhz_configs[][2] = { + {0x04, 0x02}, {0x0d, 0x55}, {0x11, 0x40}, {0x13, 0x80}, {0x17, 0x01}, + {0x1c, 0x0a}, {0x1d, 0xaa}, {0x1e, 0x20}, {0x1f, 0x88}, {0x51, 0xb0}, + {0x52, 0x89}, {0x53, 0xb3}, {0x5a, 0x2d}, {0x5b, 0xd3}, {0x85, 0x69}, + {0x87, 0x04}, {0x8e, 0x02}, {0xa3, 0xf7}, {0xa5, 0xc0}, +}; + +static const u8 va1j5jf8007s_25mhz_configs[][2] = { + {0x04, 0x02}, {0x11, 0x40}, {0x13, 0x80}, {0x17, 0x01}, {0x1c, 0x0a}, + {0x1d, 0xaa}, {0x1e, 0x20}, {0x1f, 0x88}, {0x51, 0xb0}, {0x52, 0x89}, + {0x53, 0xb3}, {0x5a, 0x2d}, {0x5b, 0xd3}, {0x85, 0x69}, {0x87, 0x04}, + {0x8e, 0x26}, {0xa3, 0xf7}, {0xa5, 0xc0}, +}; + +static const u8 va1j5jf8007t_20mhz_configs[][2] = { + {0x03, 0x90}, {0x14, 0x8f}, {0x1c, 0x2a}, {0x1d, 0xa8}, {0x1e, 0xa2}, + {0x22, 0x83}, {0x31, 0x0d}, {0x32, 0xe0}, {0x39, 0xd3}, {0x3a, 0x00}, + {0x3b, 0x11}, {0x3c, 0x3f}, + {0x5c, 0x40}, {0x5f, 0x80}, {0x75, 0x02}, {0x76, 0x4e}, {0x77, 0x03}, + {0xef, 0x01} +}; + +static const u8 va1j5jf8007t_25mhz_configs[][2] = { + {0x03, 0x90}, {0x1c, 0x2a}, {0x1d, 0xa8}, {0x1e, 0xa2}, {0x22, 0x83}, + {0x3a, 0x04}, {0x3b, 0x11}, {0x3c, 0x3f}, {0x5c, 0x40}, {0x5f, 0x80}, + {0x75, 0x0a}, {0x76, 0x4c}, {0x77, 0x03}, {0xef, 0x01} +}; + +static int config_demod(struct i2c_client *cl, enum pt1_fe_clk clk) +{ + int ret; + u8 buf[2] = {0x01, 0x80}; + bool is_sat; + const u8 (*cfg_data)[2]; + int i, len; + + ret = i2c_master_send(cl, buf, 2); + if (ret < 0) + return ret; + usleep_range(30000, 50000); + + is_sat = !strncmp(cl->name, TC90522_I2C_DEV_SAT, + strlen(TC90522_I2C_DEV_SAT)); + if (is_sat) { + struct i2c_msg msg[2]; + u8 wbuf, rbuf; + + wbuf = 0x07; + msg[0].addr = cl->addr; + msg[0].flags = 0; + msg[0].len = 1; + msg[0].buf = &wbuf; + + msg[1].addr = cl->addr; + msg[1].flags = I2C_M_RD; + msg[1].len = 1; + msg[1].buf = &rbuf; + ret = i2c_transfer(cl->adapter, msg, 2); + if (ret < 0) + return ret; + if (rbuf != 0x41) + return -EIO; + } + + /* frontend init */ + if (clk == PT1_FE_CLK_20MHZ) { + if (is_sat) { + cfg_data = va1j5jf8007s_20mhz_configs; + len = ARRAY_SIZE(va1j5jf8007s_20mhz_configs); + } else { + cfg_data = va1j5jf8007t_20mhz_configs; + len = ARRAY_SIZE(va1j5jf8007t_20mhz_configs); + } + } else { + if (is_sat) { + cfg_data = va1j5jf8007s_25mhz_configs; + len = ARRAY_SIZE(va1j5jf8007s_25mhz_configs); + } else { + cfg_data = va1j5jf8007t_25mhz_configs; + len = ARRAY_SIZE(va1j5jf8007t_25mhz_configs); + } + } + + for (i = 0; i < len; i++) { + ret = i2c_master_send(cl, cfg_data[i], 2); + if (ret < 0) + return ret; + } + return 0; +} + static void pt1_write_reg(struct pt1 *pt1, int reg, u32 data) { writel(data, pt1->regs + reg * 4); @@ -171,7 +325,7 @@ static int pt1_unlock(struct pt1 *pt1) for (i = 0; i < 3; i++) { if (pt1_read_reg(pt1, 0) & 0x80000000) return 0; - schedule_timeout_uninterruptible((HZ + 999) / 1000); + usleep_range(1000, 2000); } dev_err(&pt1->pdev->dev, "could not unlock\n"); return -EIO; @@ -185,7 +339,7 @@ static int pt1_reset_pci(struct pt1 *pt1) for (i = 0; i < 10; i++) { if (pt1_read_reg(pt1, 0) & 0x00000001) return 0; - schedule_timeout_uninterruptible((HZ + 999) / 1000); + usleep_range(1000, 2000); } dev_err(&pt1->pdev->dev, "could not reset PCI\n"); return -EIO; @@ -199,7 +353,7 @@ static int pt1_reset_ram(struct pt1 *pt1) for (i = 0; i < 10; i++) { if (pt1_read_reg(pt1, 0) & 0x00000002) return 0; - schedule_timeout_uninterruptible((HZ + 999) / 1000); + usleep_range(1000, 2000); } dev_err(&pt1->pdev->dev, "could not reset RAM\n"); return -EIO; @@ -216,7 +370,7 @@ static int pt1_do_enable_ram(struct pt1 *pt1) if ((pt1_read_reg(pt1, 0) & 0x00000004) != status) return 0; } - schedule_timeout_uninterruptible((HZ + 999) / 1000); + usleep_range(1000, 2000); } dev_err(&pt1->pdev->dev, "could not enable RAM\n"); return -EIO; @@ -226,7 +380,7 @@ static int pt1_enable_ram(struct pt1 *pt1) { int i, ret; int phase; - schedule_timeout_uninterruptible((HZ + 999) / 1000); + usleep_range(1000, 2000); phase = pt1->pdev->device == 0x211a ? 128 : 166; for (i = 0; i < phase; i++) { ret = pt1_do_enable_ram(pt1); @@ -311,16 +465,31 @@ static int pt1_thread(void *data) { struct pt1 *pt1; struct pt1_buffer_page *page; + bool was_frozen; + +#define PT1_FETCH_DELAY 10 +#define PT1_FETCH_DELAY_DELTA 2 pt1 = data; set_freezable(); - while (!kthread_should_stop()) { - try_to_freeze(); + while (!kthread_freezable_should_stop(&was_frozen)) { + if (was_frozen) { + int i; + + for (i = 0; i < PT1_NR_ADAPS; i++) + pt1_set_stream(pt1, i, !!pt1->adaps[i]->users); + } page = pt1->tables[pt1->table_index].bufs[pt1->buf_index].page; if (!pt1_filter(pt1, page)) { - schedule_timeout_interruptible((HZ + 999) / 1000); + ktime_t delay; + + delay = ktime_set(0, PT1_FETCH_DELAY * NSEC_PER_MSEC); + set_current_state(TASK_INTERRUPTIBLE); + schedule_hrtimeout_range(&delay, + PT1_FETCH_DELAY_DELTA * NSEC_PER_MSEC, + HRTIMER_MODE_REL); continue; } @@ -556,7 +725,7 @@ pt1_update_power(struct pt1 *pt1) adap = pt1->adaps[i]; switch (adap->voltage) { case SEC_VOLTAGE_13: /* actually 11V */ - bits |= 1 << 1; + bits |= 1 << 2; break; case SEC_VOLTAGE_18: /* actually 15V */ bits |= 1 << 1 | 1 << 2; @@ -589,30 +758,33 @@ static int pt1_set_voltage(struct dvb_frontend *fe, enum fe_sec_voltage voltage) static int pt1_sleep(struct dvb_frontend *fe) { struct pt1_adapter *adap; + int ret; adap = container_of(fe->dvb, struct pt1_adapter, adap); - adap->sleep = 1; - pt1_update_power(adap->pt1); + ret = 0; if (adap->orig_sleep) - return adap->orig_sleep(fe); - else - return 0; + ret = adap->orig_sleep(fe); + + adap->sleep = 1; + pt1_update_power(adap->pt1); + return ret; } static int pt1_wakeup(struct dvb_frontend *fe) { struct pt1_adapter *adap; + int ret; adap = container_of(fe->dvb, struct pt1_adapter, adap); adap->sleep = 0; pt1_update_power(adap->pt1); - schedule_timeout_uninterruptible((HZ + 999) / 1000); + usleep_range(1000, 2000); - if (adap->orig_init) - return adap->orig_init(fe); - else - return 0; + ret = config_demod(adap->demod_i2c_client, adap->pt1->fe_clk); + if (ret == 0 && adap->orig_init) + ret = adap->orig_init(fe); + return ret; } static void pt1_free_adapter(struct pt1_adapter *adap) @@ -735,6 +907,8 @@ err: static void pt1_cleanup_frontend(struct pt1_adapter *adap) { dvb_unregister_frontend(adap->fe); + dvb_module_release(adap->tuner_i2c_client); + dvb_module_release(adap->demod_i2c_client); } static int pt1_init_frontend(struct pt1_adapter *adap, struct dvb_frontend *fe) @@ -763,112 +937,70 @@ static void pt1_cleanup_frontends(struct pt1 *pt1) pt1_cleanup_frontend(pt1->adaps[i]); } -struct pt1_config { - struct va1j5jf8007s_config va1j5jf8007s_config; - struct va1j5jf8007t_config va1j5jf8007t_config; -}; - -static const struct pt1_config pt1_configs[2] = { - { - { - .demod_address = 0x1b, - .frequency = VA1J5JF8007S_20MHZ, - }, - { - .demod_address = 0x1a, - .frequency = VA1J5JF8007T_20MHZ, - }, - }, { - { - .demod_address = 0x19, - .frequency = VA1J5JF8007S_20MHZ, - }, - { - .demod_address = 0x18, - .frequency = VA1J5JF8007T_20MHZ, - }, - }, -}; - -static const struct pt1_config pt2_configs[2] = { - { - { - .demod_address = 0x1b, - .frequency = VA1J5JF8007S_25MHZ, - }, - { - .demod_address = 0x1a, - .frequency = VA1J5JF8007T_25MHZ, - }, - }, { - { - .demod_address = 0x19, - .frequency = VA1J5JF8007S_25MHZ, - }, - { - .demod_address = 0x18, - .frequency = VA1J5JF8007T_25MHZ, - }, - }, -}; - static int pt1_init_frontends(struct pt1 *pt1) { - int i, j; - struct i2c_adapter *i2c_adap; - const struct pt1_config *configs, *config; - struct dvb_frontend *fe[4]; + int i; int ret; - i = 0; - j = 0; - - i2c_adap = &pt1->i2c_adap; - configs = pt1->pdev->device == 0x211a ? pt1_configs : pt2_configs; - do { - config = &configs[i / 2]; - - fe[i] = va1j5jf8007s_attach(&config->va1j5jf8007s_config, - i2c_adap); - if (!fe[i]) { - ret = -ENODEV; /* This does not sound nice... */ - goto err; - } - i++; - - fe[i] = va1j5jf8007t_attach(&config->va1j5jf8007t_config, - i2c_adap); - if (!fe[i]) { - ret = -ENODEV; - goto err; + for (i = 0; i < ARRAY_SIZE(pt1_configs); i++) { + const struct i2c_board_info *info; + struct tc90522_config dcfg; + struct i2c_client *cl; + + info = &pt1_configs[i].demod_info; + dcfg = pt1_configs[i].demod_cfg; + dcfg.tuner_i2c = NULL; + + ret = -ENODEV; + cl = dvb_module_probe("tc90522", info->type, &pt1->i2c_adap, + info->addr, &dcfg); + if (!cl) + goto fe_unregister; + pt1->adaps[i]->demod_i2c_client = cl; + + if (!strncmp(cl->name, TC90522_I2C_DEV_SAT, + strlen(TC90522_I2C_DEV_SAT))) { + struct qm1d1b0004_config tcfg; + + info = &pt1_configs[i].tuner_info; + tcfg = pt1_configs[i].tuner_cfg.qm1d1b0004; + tcfg.fe = dcfg.fe; + cl = dvb_module_probe("qm1d1b0004", + info->type, dcfg.tuner_i2c, + info->addr, &tcfg); + } else { + struct dvb_pll_config tcfg; + + info = &pt1_configs[i].tuner_info; + tcfg = pt1_configs[i].tuner_cfg.tda6651; + tcfg.fe = dcfg.fe; + cl = dvb_module_probe("dvb_pll", + info->type, dcfg.tuner_i2c, + info->addr, &tcfg); } - i++; - - ret = va1j5jf8007s_prepare(fe[i - 2]); - if (ret < 0) - goto err; + if (!cl) + goto demod_release; + pt1->adaps[i]->tuner_i2c_client = cl; - ret = va1j5jf8007t_prepare(fe[i - 1]); - if (ret < 0) - goto err; - - } while (i < 4); - - do { - ret = pt1_init_frontend(pt1->adaps[j], fe[j]); + ret = pt1_init_frontend(pt1->adaps[i], dcfg.fe); if (ret < 0) - goto err; - } while (++j < 4); + goto tuner_release; + } return 0; -err: - while (i-- > j) - fe[i]->ops.release(fe[i]); - - while (j--) - dvb_unregister_frontend(fe[j]); - +tuner_release: + dvb_module_release(pt1->adaps[i]->tuner_i2c_client); +demod_release: + dvb_module_release(pt1->adaps[i]->demod_i2c_client); +fe_unregister: + dev_warn(&pt1->pdev->dev, "failed to init FE(%d).\n", i); + i--; + for (; i >= 0; i--) { + dvb_unregister_frontend(pt1->adaps[i]->fe); + dvb_module_release(pt1->adaps[i]->tuner_i2c_client); + dvb_module_release(pt1->adaps[i]->demod_i2c_client); + } return ret; } @@ -954,7 +1086,7 @@ static int pt1_i2c_end(struct pt1 *pt1, int addr) do { if (signal_pending(current)) return -EINTR; - schedule_timeout_interruptible((HZ + 999) / 1000); + usleep_range(1000, 2000); } while (pt1_read_reg(pt1, 0) & 0x00000080); return 0; } @@ -1052,6 +1184,98 @@ static void pt1_i2c_init(struct pt1 *pt1) pt1_i2c_emit(pt1, i, 0, 0, 1, 1, 0); } +#ifdef CONFIG_PM_SLEEP + +static int pt1_suspend(struct device *dev) +{ + struct pci_dev *pdev = to_pci_dev(dev); + struct pt1 *pt1 = pci_get_drvdata(pdev); + + pt1_init_streams(pt1); + pt1_disable_ram(pt1); + pt1->power = 0; + pt1->reset = 1; + pt1_update_power(pt1); + return 0; +} + +static int pt1_resume(struct device *dev) +{ + struct pci_dev *pdev = to_pci_dev(dev); + struct pt1 *pt1 = pci_get_drvdata(pdev); + int ret; + int i; + + pt1->power = 0; + pt1->reset = 1; + pt1_update_power(pt1); + + pt1_i2c_init(pt1); + pt1_i2c_wait(pt1); + + ret = pt1_sync(pt1); + if (ret < 0) + goto resume_err; + + pt1_identify(pt1); + + ret = pt1_unlock(pt1); + if (ret < 0) + goto resume_err; + + ret = pt1_reset_pci(pt1); + if (ret < 0) + goto resume_err; + + ret = pt1_reset_ram(pt1); + if (ret < 0) + goto resume_err; + + ret = pt1_enable_ram(pt1); + if (ret < 0) + goto resume_err; + + pt1_init_streams(pt1); + + pt1->power = 1; + pt1_update_power(pt1); + msleep(20); + + pt1->reset = 0; + pt1_update_power(pt1); + usleep_range(1000, 2000); + + for (i = 0; i < PT1_NR_ADAPS; i++) + dvb_frontend_reinitialise(pt1->adaps[i]->fe); + + pt1_init_table_count(pt1); + for (i = 0; i < pt1_nr_tables; i++) { + int j; + + for (j = 0; j < PT1_NR_BUFS; j++) + pt1->tables[i].bufs[j].page->upackets[PT1_NR_UPACKETS-1] + = 0; + pt1_increment_table_count(pt1); + } + pt1_register_tables(pt1, pt1->tables[0].addr >> PT1_PAGE_SHIFT); + + pt1->table_index = 0; + pt1->buf_index = 0; + for (i = 0; i < PT1_NR_ADAPS; i++) { + pt1->adaps[i]->upacket_count = 0; + pt1->adaps[i]->packet_count = 0; + pt1->adaps[i]->st_count = -1; + } + + return 0; + +resume_err: + dev_info(&pt1->pdev->dev, "failed to resume PT1/PT2."); + return 0; /* resume anyway */ +} + +#endif /* CONFIG_PM_SLEEP */ + static void pt1_remove(struct pci_dev *pdev) { struct pt1 *pt1; @@ -1112,6 +1336,8 @@ static int pt1_probe(struct pci_dev *pdev, const struct pci_device_id *ent) mutex_init(&pt1->lock); pt1->pdev = pdev; pt1->regs = regs; + pt1->fe_clk = (pdev->device == 0x211a) ? + PT1_FE_CLK_20MHZ : PT1_FE_CLK_25MHZ; pci_set_drvdata(pdev, pt1); ret = pt1_init_adapters(pt1); @@ -1163,11 +1389,11 @@ static int pt1_probe(struct pci_dev *pdev, const struct pci_device_id *ent) pt1->power = 1; pt1_update_power(pt1); - schedule_timeout_uninterruptible((HZ + 49) / 50); + msleep(20); pt1->reset = 0; pt1_update_power(pt1); - schedule_timeout_uninterruptible((HZ + 999) / 1000); + usleep_range(1000, 2000); ret = pt1_init_frontends(pt1); if (ret < 0) @@ -1210,11 +1436,16 @@ static const struct pci_device_id pt1_id_table[] = { }; MODULE_DEVICE_TABLE(pci, pt1_id_table); +static SIMPLE_DEV_PM_OPS(pt1_pm_ops, pt1_suspend, pt1_resume); + static struct pci_driver pt1_driver = { .name = DRIVER_NAME, .probe = pt1_probe, .remove = pt1_remove, .id_table = pt1_id_table, +#ifdef CONFIG_PM_SLEEP + .driver.pm = &pt1_pm_ops, +#endif }; module_pci_driver(pt1_driver); diff --git a/drivers/media/pci/pt1/va1j5jf8007s.c b/drivers/media/pci/pt1/va1j5jf8007s.c deleted file mode 100644 index f49867aef054..000000000000 --- a/drivers/media/pci/pt1/va1j5jf8007s.c +++ /dev/null @@ -1,732 +0,0 @@ -/* - * ISDB-S driver for VA1J5JF8007/VA1J5JF8011 - * - * Copyright (C) 2009 HIRANO Takahito <hiranotaka@zng.info> - * - * based on pt1dvr - http://pt1dvr.sourceforge.jp/ - * by Tomoaki Ishikawa <tomy@users.sourceforge.jp> - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - */ - -#include <linux/kernel.h> -#include <linux/module.h> -#include <linux/slab.h> -#include <linux/i2c.h> -#include <media/dvb_frontend.h> -#include "va1j5jf8007s.h" - -enum va1j5jf8007s_tune_state { - VA1J5JF8007S_IDLE, - VA1J5JF8007S_SET_FREQUENCY_1, - VA1J5JF8007S_SET_FREQUENCY_2, - VA1J5JF8007S_SET_FREQUENCY_3, - VA1J5JF8007S_CHECK_FREQUENCY, - VA1J5JF8007S_SET_MODULATION, - VA1J5JF8007S_CHECK_MODULATION, - VA1J5JF8007S_SET_TS_ID, - VA1J5JF8007S_CHECK_TS_ID, - VA1J5JF8007S_TRACK, -}; - -struct va1j5jf8007s_state { - const struct va1j5jf8007s_config *config; - struct i2c_adapter *adap; - struct dvb_frontend fe; - enum va1j5jf8007s_tune_state tune_state; -}; - -static int va1j5jf8007s_read_snr(struct dvb_frontend *fe, u16 *snr) -{ - struct va1j5jf8007s_state *state; - u8 addr; - int i; - u8 write_buf[1], read_buf[1]; - struct i2c_msg msgs[2]; - s32 word, x1, x2, x3, x4, x5, y; - - state = fe->demodulator_priv; - addr = state->config->demod_address; - - word = 0; - for (i = 0; i < 2; i++) { - write_buf[0] = 0xbc + i; - - msgs[0].addr = addr; - msgs[0].flags = 0; - msgs[0].len = sizeof(write_buf); - msgs[0].buf = write_buf; - - msgs[1].addr = addr; - msgs[1].flags = I2C_M_RD; - msgs[1].len = sizeof(read_buf); - msgs[1].buf = read_buf; - - if (i2c_transfer(state->adap, msgs, 2) != 2) - return -EREMOTEIO; - - word <<= 8; - word |= read_buf[0]; - } - - word -= 3000; - if (word < 0) - word = 0; - - x1 = int_sqrt(word << 16) * ((15625ll << 21) / 1000000); - x2 = (s64)x1 * x1 >> 31; - x3 = (s64)x2 * x1 >> 31; - x4 = (s64)x2 * x2 >> 31; - x5 = (s64)x4 * x1 >> 31; - - y = (58857ll << 23) / 1000; - y -= (s64)x1 * ((89565ll << 24) / 1000) >> 30; - y += (s64)x2 * ((88977ll << 24) / 1000) >> 28; - y -= (s64)x3 * ((50259ll << 25) / 1000) >> 27; - y += (s64)x4 * ((14341ll << 27) / 1000) >> 27; - y -= (s64)x5 * ((16346ll << 30) / 10000) >> 28; - - *snr = y < 0 ? 0 : y >> 15; - return 0; -} - -static int va1j5jf8007s_get_frontend_algo(struct dvb_frontend *fe) -{ - return DVBFE_ALGO_HW; -} - -static int -va1j5jf8007s_read_status(struct dvb_frontend *fe, enum fe_status *status) -{ - struct va1j5jf8007s_state *state; - - state = fe->demodulator_priv; - - switch (state->tune_state) { - case VA1J5JF8007S_IDLE: - case VA1J5JF8007S_SET_FREQUENCY_1: - case VA1J5JF8007S_SET_FREQUENCY_2: - case VA1J5JF8007S_SET_FREQUENCY_3: - case VA1J5JF8007S_CHECK_FREQUENCY: - *status = 0; - return 0; - - - case VA1J5JF8007S_SET_MODULATION: - case VA1J5JF8007S_CHECK_MODULATION: - *status |= FE_HAS_SIGNAL; - return 0; - - case VA1J5JF8007S_SET_TS_ID: - case VA1J5JF8007S_CHECK_TS_ID: - *status |= FE_HAS_SIGNAL | FE_HAS_CARRIER; - return 0; - - case VA1J5JF8007S_TRACK: - *status |= FE_HAS_SIGNAL | FE_HAS_CARRIER | FE_HAS_LOCK; - return 0; - } - - BUG(); -} - -struct va1j5jf8007s_cb_map { - u32 frequency; - u8 cb; -}; - -static const struct va1j5jf8007s_cb_map va1j5jf8007s_cb_maps[] = { - { 986000, 0xb2 }, - { 1072000, 0xd2 }, - { 1154000, 0xe2 }, - { 1291000, 0x20 }, - { 1447000, 0x40 }, - { 1615000, 0x60 }, - { 1791000, 0x80 }, - { 1972000, 0xa0 }, -}; - -static u8 va1j5jf8007s_lookup_cb(u32 frequency) -{ - int i; - const struct va1j5jf8007s_cb_map *map; - - for (i = 0; i < ARRAY_SIZE(va1j5jf8007s_cb_maps); i++) { - map = &va1j5jf8007s_cb_maps[i]; - if (frequency < map->frequency) - return map->cb; - } - return 0xc0; -} - -static int va1j5jf8007s_set_frequency_1(struct va1j5jf8007s_state *state) -{ - u32 frequency; - u16 word; - u8 buf[6]; - struct i2c_msg msg; - - frequency = state->fe.dtv_property_cache.frequency; - - word = (frequency + 500) / 1000; - if (frequency < 1072000) - word = (word << 1 & ~0x1f) | (word & 0x0f); - - buf[0] = 0xfe; - buf[1] = 0xc0; - buf[2] = 0x40 | word >> 8; - buf[3] = word; - buf[4] = 0xe0; - buf[5] = va1j5jf8007s_lookup_cb(frequency); - - msg.addr = state->config->demod_address; - msg.flags = 0; - msg.len = sizeof(buf); - msg.buf = buf; - - if (i2c_transfer(state->adap, &msg, 1) != 1) - return -EREMOTEIO; - - return 0; -} - -static int va1j5jf8007s_set_frequency_2(struct va1j5jf8007s_state *state) -{ - u8 buf[3]; - struct i2c_msg msg; - - buf[0] = 0xfe; - buf[1] = 0xc0; - buf[2] = 0xe4; - - msg.addr = state->config->demod_address; - msg.flags = 0; - msg.len = sizeof(buf); - msg.buf = buf; - - if (i2c_transfer(state->adap, &msg, 1) != 1) - return -EREMOTEIO; - - return 0; -} - -static int va1j5jf8007s_set_frequency_3(struct va1j5jf8007s_state *state) -{ - u32 frequency; - u8 buf[4]; - struct i2c_msg msg; - - frequency = state->fe.dtv_property_cache.frequency; - - buf[0] = 0xfe; - buf[1] = 0xc0; - buf[2] = 0xf4; - buf[3] = va1j5jf8007s_lookup_cb(frequency) | 0x4; - - msg.addr = state->config->demod_address; - msg.flags = 0; - msg.len = sizeof(buf); - msg.buf = buf; - - if (i2c_transfer(state->adap, &msg, 1) != 1) - return -EREMOTEIO; - - return 0; -} - -static int -va1j5jf8007s_check_frequency(struct va1j5jf8007s_state *state, int *lock) -{ - u8 addr; - u8 write_buf[2], read_buf[1]; - struct i2c_msg msgs[2]; - - addr = state->config->demod_address; - - write_buf[0] = 0xfe; - write_buf[1] = 0xc1; - - msgs[0].addr = addr; - msgs[0].flags = 0; - msgs[0].len = sizeof(write_buf); - msgs[0].buf = write_buf; - - msgs[1].addr = addr; - msgs[1].flags = I2C_M_RD; - msgs[1].len = sizeof(read_buf); - msgs[1].buf = read_buf; - - if (i2c_transfer(state->adap, msgs, 2) != 2) - return -EREMOTEIO; - - *lock = read_buf[0] & 0x40; - return 0; -} - -static int va1j5jf8007s_set_modulation(struct va1j5jf8007s_state *state) -{ - u8 buf[2]; - struct i2c_msg msg; - - buf[0] = 0x03; - buf[1] = 0x01; - - msg.addr = state->config->demod_address; - msg.flags = 0; - msg.len = sizeof(buf); - msg.buf = buf; - - if (i2c_transfer(state->adap, &msg, 1) != 1) - return -EREMOTEIO; - - return 0; -} - -static int -va1j5jf8007s_check_modulation(struct va1j5jf8007s_state *state, int *lock) -{ - u8 addr; - u8 write_buf[1], read_buf[1]; - struct i2c_msg msgs[2]; - - addr = state->config->demod_address; - - write_buf[0] = 0xc3; - - msgs[0].addr = addr; - msgs[0].flags = 0; - msgs[0].len = sizeof(write_buf); - msgs[0].buf = write_buf; - - msgs[1].addr = addr; - msgs[1].flags = I2C_M_RD; - msgs[1].len = sizeof(read_buf); - msgs[1].buf = read_buf; - - if (i2c_transfer(state->adap, msgs, 2) != 2) - return -EREMOTEIO; - - *lock = !(read_buf[0] & 0x10); - return 0; -} - -static int -va1j5jf8007s_set_ts_id(struct va1j5jf8007s_state *state) -{ - u32 ts_id; - u8 buf[3]; - struct i2c_msg msg; - - ts_id = state->fe.dtv_property_cache.stream_id; - if (!ts_id || ts_id == NO_STREAM_ID_FILTER) - return 0; - - buf[0] = 0x8f; - buf[1] = ts_id >> 8; - buf[2] = ts_id; - - msg.addr = state->config->demod_address; - msg.flags = 0; - msg.len = sizeof(buf); - msg.buf = buf; - - if (i2c_transfer(state->adap, &msg, 1) != 1) - return -EREMOTEIO; - - return 0; -} - -static int -va1j5jf8007s_check_ts_id(struct va1j5jf8007s_state *state, int *lock) -{ - u8 addr; - u8 write_buf[1], read_buf[2]; - struct i2c_msg msgs[2]; - u32 ts_id; - - ts_id = state->fe.dtv_property_cache.stream_id; - if (!ts_id || ts_id == NO_STREAM_ID_FILTER) { - *lock = 1; - return 0; - } - - addr = state->config->demod_address; - - write_buf[0] = 0xe6; - - msgs[0].addr = addr; - msgs[0].flags = 0; - msgs[0].len = sizeof(write_buf); - msgs[0].buf = write_buf; - - msgs[1].addr = addr; - msgs[1].flags = I2C_M_RD; - msgs[1].len = sizeof(read_buf); - msgs[1].buf = read_buf; - - if (i2c_transfer(state->adap, msgs, 2) != 2) - return -EREMOTEIO; - - *lock = (read_buf[0] << 8 | read_buf[1]) == ts_id; - return 0; -} - -static int -va1j5jf8007s_tune(struct dvb_frontend *fe, - bool re_tune, - unsigned int mode_flags, unsigned int *delay, - enum fe_status *status) -{ - struct va1j5jf8007s_state *state; - int ret; - int lock = 0; - - state = fe->demodulator_priv; - - if (re_tune) - state->tune_state = VA1J5JF8007S_SET_FREQUENCY_1; - - switch (state->tune_state) { - case VA1J5JF8007S_IDLE: - *delay = 3 * HZ; - *status = 0; - return 0; - - case VA1J5JF8007S_SET_FREQUENCY_1: - ret = va1j5jf8007s_set_frequency_1(state); - if (ret < 0) - return ret; - - state->tune_state = VA1J5JF8007S_SET_FREQUENCY_2; - *delay = 0; - *status = 0; - return 0; - - case VA1J5JF8007S_SET_FREQUENCY_2: - ret = va1j5jf8007s_set_frequency_2(state); - if (ret < 0) - return ret; - - state->tune_state = VA1J5JF8007S_SET_FREQUENCY_3; - *delay = (HZ + 99) / 100; - *status = 0; - return 0; - - case VA1J5JF8007S_SET_FREQUENCY_3: - ret = va1j5jf8007s_set_frequency_3(state); - if (ret < 0) - return ret; - - state->tune_state = VA1J5JF8007S_CHECK_FREQUENCY; - *delay = 0; - *status = 0; - return 0; - - case VA1J5JF8007S_CHECK_FREQUENCY: - ret = va1j5jf8007s_check_frequency(state, &lock); - if (ret < 0) - return ret; - - if (!lock) { - *delay = (HZ + 999) / 1000; - *status = 0; - return 0; - } - - state->tune_state = VA1J5JF8007S_SET_MODULATION; - *delay = 0; - *status = FE_HAS_SIGNAL; - return 0; - - case VA1J5JF8007S_SET_MODULATION: - ret = va1j5jf8007s_set_modulation(state); - if (ret < 0) - return ret; - - state->tune_state = VA1J5JF8007S_CHECK_MODULATION; - *delay = 0; - *status = FE_HAS_SIGNAL; - return 0; - - case VA1J5JF8007S_CHECK_MODULATION: - ret = va1j5jf8007s_check_modulation(state, &lock); - if (ret < 0) - return ret; - - if (!lock) { - *delay = (HZ + 49) / 50; - *status = FE_HAS_SIGNAL; - return 0; - } - - state->tune_state = VA1J5JF8007S_SET_TS_ID; - *delay = 0; - *status = FE_HAS_SIGNAL | FE_HAS_CARRIER; - return 0; - - case VA1J5JF8007S_SET_TS_ID: - ret = va1j5jf8007s_set_ts_id(state); - if (ret < 0) - return ret; - - state->tune_state = VA1J5JF8007S_CHECK_TS_ID; - return 0; - - case VA1J5JF8007S_CHECK_TS_ID: - ret = va1j5jf8007s_check_ts_id(state, &lock); - if (ret < 0) - return ret; - - if (!lock) { - *delay = (HZ + 99) / 100; - *status = FE_HAS_SIGNAL | FE_HAS_CARRIER; - return 0; - } - - state->tune_state = VA1J5JF8007S_TRACK; - /* fall through */ - - case VA1J5JF8007S_TRACK: - *delay = 3 * HZ; - *status = FE_HAS_SIGNAL | FE_HAS_CARRIER | FE_HAS_LOCK; - return 0; - } - - BUG(); -} - -static int va1j5jf8007s_init_frequency(struct va1j5jf8007s_state *state) -{ - u8 buf[4]; - struct i2c_msg msg; - - buf[0] = 0xfe; - buf[1] = 0xc0; - buf[2] = 0xf0; - buf[3] = 0x04; - - msg.addr = state->config->demod_address; - msg.flags = 0; - msg.len = sizeof(buf); - msg.buf = buf; - - if (i2c_transfer(state->adap, &msg, 1) != 1) - return -EREMOTEIO; - - return 0; -} - -static int va1j5jf8007s_set_sleep(struct va1j5jf8007s_state *state, int sleep) -{ - u8 buf[2]; - struct i2c_msg msg; - - buf[0] = 0x17; - buf[1] = sleep ? 0x01 : 0x00; - - msg.addr = state->config->demod_address; - msg.flags = 0; - msg.len = sizeof(buf); - msg.buf = buf; - - if (i2c_transfer(state->adap, &msg, 1) != 1) - return -EREMOTEIO; - - return 0; -} - -static int va1j5jf8007s_sleep(struct dvb_frontend *fe) -{ - struct va1j5jf8007s_state *state; - int ret; - - state = fe->demodulator_priv; - - ret = va1j5jf8007s_init_frequency(state); - if (ret < 0) - return ret; - - return va1j5jf8007s_set_sleep(state, 1); -} - -static int va1j5jf8007s_init(struct dvb_frontend *fe) -{ - struct va1j5jf8007s_state *state; - - state = fe->demodulator_priv; - state->tune_state = VA1J5JF8007S_IDLE; - - return va1j5jf8007s_set_sleep(state, 0); -} - -static void va1j5jf8007s_release(struct dvb_frontend *fe) -{ - struct va1j5jf8007s_state *state; - state = fe->demodulator_priv; - kfree(state); -} - -static const struct dvb_frontend_ops va1j5jf8007s_ops = { - .delsys = { SYS_ISDBS }, - .info = { - .name = "VA1J5JF8007/VA1J5JF8011 ISDB-S", - .frequency_min = 950000, - .frequency_max = 2150000, - .frequency_stepsize = 1000, - .caps = FE_CAN_INVERSION_AUTO | FE_CAN_FEC_AUTO | - FE_CAN_QAM_AUTO | FE_CAN_TRANSMISSION_MODE_AUTO | - FE_CAN_GUARD_INTERVAL_AUTO | FE_CAN_HIERARCHY_AUTO | - FE_CAN_MULTISTREAM, - }, - - .read_snr = va1j5jf8007s_read_snr, - .get_frontend_algo = va1j5jf8007s_get_frontend_algo, - .read_status = va1j5jf8007s_read_status, - .tune = va1j5jf8007s_tune, - .sleep = va1j5jf8007s_sleep, - .init = va1j5jf8007s_init, - .release = va1j5jf8007s_release, -}; - -static int va1j5jf8007s_prepare_1(struct va1j5jf8007s_state *state) -{ - u8 addr; - u8 write_buf[1], read_buf[1]; - struct i2c_msg msgs[2]; - - addr = state->config->demod_address; - - write_buf[0] = 0x07; - - msgs[0].addr = addr; - msgs[0].flags = 0; - msgs[0].len = sizeof(write_buf); - msgs[0].buf = write_buf; - - msgs[1].addr = addr; - msgs[1].flags = I2C_M_RD; - msgs[1].len = sizeof(read_buf); - msgs[1].buf = read_buf; - - if (i2c_transfer(state->adap, msgs, 2) != 2) - return -EREMOTEIO; - - if (read_buf[0] != 0x41) - return -EIO; - - return 0; -} - -static const u8 va1j5jf8007s_20mhz_prepare_bufs[][2] = { - {0x04, 0x02}, {0x0d, 0x55}, {0x11, 0x40}, {0x13, 0x80}, {0x17, 0x01}, - {0x1c, 0x0a}, {0x1d, 0xaa}, {0x1e, 0x20}, {0x1f, 0x88}, {0x51, 0xb0}, - {0x52, 0x89}, {0x53, 0xb3}, {0x5a, 0x2d}, {0x5b, 0xd3}, {0x85, 0x69}, - {0x87, 0x04}, {0x8e, 0x02}, {0xa3, 0xf7}, {0xa5, 0xc0}, -}; - -static const u8 va1j5jf8007s_25mhz_prepare_bufs[][2] = { - {0x04, 0x02}, {0x11, 0x40}, {0x13, 0x80}, {0x17, 0x01}, {0x1c, 0x0a}, - {0x1d, 0xaa}, {0x1e, 0x20}, {0x1f, 0x88}, {0x51, 0xb0}, {0x52, 0x89}, - {0x53, 0xb3}, {0x5a, 0x2d}, {0x5b, 0xd3}, {0x85, 0x69}, {0x87, 0x04}, - {0x8e, 0x26}, {0xa3, 0xf7}, {0xa5, 0xc0}, -}; - -static int va1j5jf8007s_prepare_2(struct va1j5jf8007s_state *state) -{ - const u8 (*bufs)[2]; - int size; - u8 addr; - u8 buf[2]; - struct i2c_msg msg; - int i; - - switch (state->config->frequency) { - case VA1J5JF8007S_20MHZ: - bufs = va1j5jf8007s_20mhz_prepare_bufs; - size = ARRAY_SIZE(va1j5jf8007s_20mhz_prepare_bufs); - break; - case VA1J5JF8007S_25MHZ: - bufs = va1j5jf8007s_25mhz_prepare_bufs; - size = ARRAY_SIZE(va1j5jf8007s_25mhz_prepare_bufs); - break; - default: - return -EINVAL; - } - - addr = state->config->demod_address; - - msg.addr = addr; - msg.flags = 0; - msg.len = 2; - msg.buf = buf; - for (i = 0; i < size; i++) { - memcpy(buf, bufs[i], sizeof(buf)); - if (i2c_transfer(state->adap, &msg, 1) != 1) - return -EREMOTEIO; - } - - return 0; -} - -/* must be called after va1j5jf8007t_attach */ -int va1j5jf8007s_prepare(struct dvb_frontend *fe) -{ - struct va1j5jf8007s_state *state; - int ret; - - state = fe->demodulator_priv; - - ret = va1j5jf8007s_prepare_1(state); - if (ret < 0) - return ret; - - ret = va1j5jf8007s_prepare_2(state); - if (ret < 0) - return ret; - - return va1j5jf8007s_init_frequency(state); -} - -struct dvb_frontend * -va1j5jf8007s_attach(const struct va1j5jf8007s_config *config, - struct i2c_adapter *adap) -{ - struct va1j5jf8007s_state *state; - struct dvb_frontend *fe; - u8 buf[2]; - struct i2c_msg msg; - - state = kzalloc(sizeof(struct va1j5jf8007s_state), GFP_KERNEL); - if (!state) - return NULL; - - state->config = config; - state->adap = adap; - - fe = &state->fe; - memcpy(&fe->ops, &va1j5jf8007s_ops, sizeof(struct dvb_frontend_ops)); - fe->demodulator_priv = state; - - buf[0] = 0x01; - buf[1] = 0x80; - - msg.addr = state->config->demod_address; - msg.flags = 0; - msg.len = sizeof(buf); - msg.buf = buf; - - if (i2c_transfer(state->adap, &msg, 1) != 1) { - kfree(state); - return NULL; - } - - return fe; -} diff --git a/drivers/media/pci/pt1/va1j5jf8007s.h b/drivers/media/pci/pt1/va1j5jf8007s.h deleted file mode 100644 index f8ce5609095d..000000000000 --- a/drivers/media/pci/pt1/va1j5jf8007s.h +++ /dev/null @@ -1,42 +0,0 @@ -/* - * ISDB-S driver for VA1J5JF8007/VA1J5JF8011 - * - * Copyright (C) 2009 HIRANO Takahito <hiranotaka@zng.info> - * - * based on pt1dvr - http://pt1dvr.sourceforge.jp/ - * by Tomoaki Ishikawa <tomy@users.sourceforge.jp> - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - */ - -#ifndef VA1J5JF8007S_H -#define VA1J5JF8007S_H - -enum va1j5jf8007s_frequency { - VA1J5JF8007S_20MHZ, - VA1J5JF8007S_25MHZ, -}; - -struct va1j5jf8007s_config { - u8 demod_address; - enum va1j5jf8007s_frequency frequency; -}; - -struct i2c_adapter; - -struct dvb_frontend * -va1j5jf8007s_attach(const struct va1j5jf8007s_config *config, - struct i2c_adapter *adap); - -/* must be called after va1j5jf8007t_attach */ -int va1j5jf8007s_prepare(struct dvb_frontend *fe); - -#endif diff --git a/drivers/media/pci/pt1/va1j5jf8007t.c b/drivers/media/pci/pt1/va1j5jf8007t.c deleted file mode 100644 index a52984a6f9b3..000000000000 --- a/drivers/media/pci/pt1/va1j5jf8007t.c +++ /dev/null @@ -1,532 +0,0 @@ -/* - * ISDB-T driver for VA1J5JF8007/VA1J5JF8011 - * - * Copyright (C) 2009 HIRANO Takahito <hiranotaka@zng.info> - * - * based on pt1dvr - http://pt1dvr.sourceforge.jp/ - * by Tomoaki Ishikawa <tomy@users.sourceforge.jp> - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - */ - -#include <linux/kernel.h> -#include <linux/module.h> -#include <linux/slab.h> -#include <linux/i2c.h> -#include <media/dvb_frontend.h> -#include <media/dvb_math.h> -#include "va1j5jf8007t.h" - -enum va1j5jf8007t_tune_state { - VA1J5JF8007T_IDLE, - VA1J5JF8007T_SET_FREQUENCY, - VA1J5JF8007T_CHECK_FREQUENCY, - VA1J5JF8007T_SET_MODULATION, - VA1J5JF8007T_CHECK_MODULATION, - VA1J5JF8007T_TRACK, - VA1J5JF8007T_ABORT, -}; - -struct va1j5jf8007t_state { - const struct va1j5jf8007t_config *config; - struct i2c_adapter *adap; - struct dvb_frontend fe; - enum va1j5jf8007t_tune_state tune_state; -}; - -static int va1j5jf8007t_read_snr(struct dvb_frontend *fe, u16 *snr) -{ - struct va1j5jf8007t_state *state; - u8 addr; - int i; - u8 write_buf[1], read_buf[1]; - struct i2c_msg msgs[2]; - s32 word, x, y; - - state = fe->demodulator_priv; - addr = state->config->demod_address; - - word = 0; - for (i = 0; i < 3; i++) { - write_buf[0] = 0x8b + i; - - msgs[0].addr = addr; - msgs[0].flags = 0; - msgs[0].len = sizeof(write_buf); - msgs[0].buf = write_buf; - - msgs[1].addr = addr; - msgs[1].flags = I2C_M_RD; - msgs[1].len = sizeof(read_buf); - msgs[1].buf = read_buf; - - if (i2c_transfer(state->adap, msgs, 2) != 2) - return -EREMOTEIO; - - word <<= 8; - word |= read_buf[0]; - } - - if (!word) - return -EIO; - - x = 10 * (intlog10(0x540000 * 100 / word) - (2 << 24)); - y = (24ll << 46) / 1000000; - y = ((s64)y * x >> 30) - (16ll << 40) / 10000; - y = ((s64)y * x >> 29) + (398ll << 35) / 10000; - y = ((s64)y * x >> 30) + (5491ll << 29) / 10000; - y = ((s64)y * x >> 30) + (30965ll << 23) / 10000; - *snr = y >> 15; - return 0; -} - -static int va1j5jf8007t_get_frontend_algo(struct dvb_frontend *fe) -{ - return DVBFE_ALGO_HW; -} - -static int -va1j5jf8007t_read_status(struct dvb_frontend *fe, enum fe_status *status) -{ - struct va1j5jf8007t_state *state; - - state = fe->demodulator_priv; - - switch (state->tune_state) { - case VA1J5JF8007T_IDLE: - case VA1J5JF8007T_SET_FREQUENCY: - case VA1J5JF8007T_CHECK_FREQUENCY: - *status = 0; - return 0; - - - case VA1J5JF8007T_SET_MODULATION: - case VA1J5JF8007T_CHECK_MODULATION: - case VA1J5JF8007T_ABORT: - *status |= FE_HAS_SIGNAL; - return 0; - - case VA1J5JF8007T_TRACK: - *status |= FE_HAS_SIGNAL | FE_HAS_CARRIER | FE_HAS_LOCK; - return 0; - } - - BUG(); -} - -struct va1j5jf8007t_cb_map { - u32 frequency; - u8 cb; -}; - -static const struct va1j5jf8007t_cb_map va1j5jf8007t_cb_maps[] = { - { 90000000, 0x80 }, - { 140000000, 0x81 }, - { 170000000, 0xa1 }, - { 220000000, 0x62 }, - { 330000000, 0xa2 }, - { 402000000, 0xe2 }, - { 450000000, 0x64 }, - { 550000000, 0x84 }, - { 600000000, 0xa4 }, - { 700000000, 0xc4 }, -}; - -static u8 va1j5jf8007t_lookup_cb(u32 frequency) -{ - int i; - const struct va1j5jf8007t_cb_map *map; - - for (i = 0; i < ARRAY_SIZE(va1j5jf8007t_cb_maps); i++) { - map = &va1j5jf8007t_cb_maps[i]; - if (frequency < map->frequency) - return map->cb; - } - return 0xe4; -} - -static int va1j5jf8007t_set_frequency(struct va1j5jf8007t_state *state) -{ - u32 frequency; - u16 word; - u8 buf[6]; - struct i2c_msg msg; - - frequency = state->fe.dtv_property_cache.frequency; - - word = (frequency + 71428) / 142857 + 399; - buf[0] = 0xfe; - buf[1] = 0xc2; - buf[2] = word >> 8; - buf[3] = word; - buf[4] = 0x80; - buf[5] = va1j5jf8007t_lookup_cb(frequency); - - msg.addr = state->config->demod_address; - msg.flags = 0; - msg.len = sizeof(buf); - msg.buf = buf; - - if (i2c_transfer(state->adap, &msg, 1) != 1) - return -EREMOTEIO; - - return 0; -} - -static int -va1j5jf8007t_check_frequency(struct va1j5jf8007t_state *state, int *lock) -{ - u8 addr; - u8 write_buf[2], read_buf[1]; - struct i2c_msg msgs[2]; - - addr = state->config->demod_address; - - write_buf[0] = 0xfe; - write_buf[1] = 0xc3; - - msgs[0].addr = addr; - msgs[0].flags = 0; - msgs[0].len = sizeof(write_buf); - msgs[0].buf = write_buf; - - msgs[1].addr = addr; - msgs[1].flags = I2C_M_RD; - msgs[1].len = sizeof(read_buf); - msgs[1].buf = read_buf; - - if (i2c_transfer(state->adap, msgs, 2) != 2) - return -EREMOTEIO; - - *lock = read_buf[0] & 0x40; - return 0; -} - -static int va1j5jf8007t_set_modulation(struct va1j5jf8007t_state *state) -{ - u8 buf[2]; - struct i2c_msg msg; - - buf[0] = 0x01; - buf[1] = 0x40; - - msg.addr = state->config->demod_address; - msg.flags = 0; - msg.len = sizeof(buf); - msg.buf = buf; - - if (i2c_transfer(state->adap, &msg, 1) != 1) - return -EREMOTEIO; - - return 0; -} - -static int va1j5jf8007t_check_modulation(struct va1j5jf8007t_state *state, - int *lock, int *retry) -{ - u8 addr; - u8 write_buf[1], read_buf[1]; - struct i2c_msg msgs[2]; - - addr = state->config->demod_address; - - write_buf[0] = 0x80; - - msgs[0].addr = addr; - msgs[0].flags = 0; - msgs[0].len = sizeof(write_buf); - msgs[0].buf = write_buf; - - msgs[1].addr = addr; - msgs[1].flags = I2C_M_RD; - msgs[1].len = sizeof(read_buf); - msgs[1].buf = read_buf; - - if (i2c_transfer(state->adap, msgs, 2) != 2) - return -EREMOTEIO; - - *lock = !(read_buf[0] & 0x10); - *retry = read_buf[0] & 0x80; - return 0; -} - -static int -va1j5jf8007t_tune(struct dvb_frontend *fe, - bool re_tune, - unsigned int mode_flags, unsigned int *delay, - enum fe_status *status) -{ - struct va1j5jf8007t_state *state; - int ret; - int lock = 0, retry = 0; - - state = fe->demodulator_priv; - - if (re_tune) - state->tune_state = VA1J5JF8007T_SET_FREQUENCY; - - switch (state->tune_state) { - case VA1J5JF8007T_IDLE: - *delay = 3 * HZ; - *status = 0; - return 0; - - case VA1J5JF8007T_SET_FREQUENCY: - ret = va1j5jf8007t_set_frequency(state); - if (ret < 0) - return ret; - - state->tune_state = VA1J5JF8007T_CHECK_FREQUENCY; - *delay = 0; - *status = 0; - return 0; - - case VA1J5JF8007T_CHECK_FREQUENCY: - ret = va1j5jf8007t_check_frequency(state, &lock); - if (ret < 0) - return ret; - - if (!lock) { - *delay = (HZ + 999) / 1000; - *status = 0; - return 0; - } - - state->tune_state = VA1J5JF8007T_SET_MODULATION; - *delay = 0; - *status = FE_HAS_SIGNAL; - return 0; - - case VA1J5JF8007T_SET_MODULATION: - ret = va1j5jf8007t_set_modulation(state); - if (ret < 0) - return ret; - - state->tune_state = VA1J5JF8007T_CHECK_MODULATION; - *delay = 0; - *status = FE_HAS_SIGNAL; - return 0; - - case VA1J5JF8007T_CHECK_MODULATION: - ret = va1j5jf8007t_check_modulation(state, &lock, &retry); - if (ret < 0) - return ret; - - if (!lock) { - if (!retry) { - state->tune_state = VA1J5JF8007T_ABORT; - *delay = 3 * HZ; - *status = FE_HAS_SIGNAL; - return 0; - } - *delay = (HZ + 999) / 1000; - *status = FE_HAS_SIGNAL; - return 0; - } - - state->tune_state = VA1J5JF8007T_TRACK; - /* fall through */ - - case VA1J5JF8007T_TRACK: - *delay = 3 * HZ; - *status = FE_HAS_SIGNAL | FE_HAS_CARRIER | FE_HAS_LOCK; - return 0; - - case VA1J5JF8007T_ABORT: - *delay = 3 * HZ; - *status = FE_HAS_SIGNAL; - return 0; - } - - BUG(); -} - -static int va1j5jf8007t_init_frequency(struct va1j5jf8007t_state *state) -{ - u8 buf[7]; - struct i2c_msg msg; - - buf[0] = 0xfe; - buf[1] = 0xc2; - buf[2] = 0x01; - buf[3] = 0x8f; - buf[4] = 0xc1; - buf[5] = 0x80; - buf[6] = 0x80; - - msg.addr = state->config->demod_address; - msg.flags = 0; - msg.len = sizeof(buf); - msg.buf = buf; - - if (i2c_transfer(state->adap, &msg, 1) != 1) - return -EREMOTEIO; - - return 0; -} - -static int va1j5jf8007t_set_sleep(struct va1j5jf8007t_state *state, int sleep) -{ - u8 buf[2]; - struct i2c_msg msg; - - buf[0] = 0x03; - buf[1] = sleep ? 0x90 : 0x80; - - msg.addr = state->config->demod_address; - msg.flags = 0; - msg.len = sizeof(buf); - msg.buf = buf; - - if (i2c_transfer(state->adap, &msg, 1) != 1) - return -EREMOTEIO; - - return 0; -} - -static int va1j5jf8007t_sleep(struct dvb_frontend *fe) -{ - struct va1j5jf8007t_state *state; - int ret; - - state = fe->demodulator_priv; - - ret = va1j5jf8007t_init_frequency(state); - if (ret < 0) - return ret; - - return va1j5jf8007t_set_sleep(state, 1); -} - -static int va1j5jf8007t_init(struct dvb_frontend *fe) -{ - struct va1j5jf8007t_state *state; - - state = fe->demodulator_priv; - state->tune_state = VA1J5JF8007T_IDLE; - - return va1j5jf8007t_set_sleep(state, 0); -} - -static void va1j5jf8007t_release(struct dvb_frontend *fe) -{ - struct va1j5jf8007t_state *state; - state = fe->demodulator_priv; - kfree(state); -} - -static const struct dvb_frontend_ops va1j5jf8007t_ops = { - .delsys = { SYS_ISDBT }, - .info = { - .name = "VA1J5JF8007/VA1J5JF8011 ISDB-T", - .frequency_min = 90000000, - .frequency_max = 770000000, - .frequency_stepsize = 142857, - .caps = FE_CAN_INVERSION_AUTO | FE_CAN_FEC_AUTO | - FE_CAN_QAM_AUTO | FE_CAN_TRANSMISSION_MODE_AUTO | - FE_CAN_GUARD_INTERVAL_AUTO | FE_CAN_HIERARCHY_AUTO, - }, - - .read_snr = va1j5jf8007t_read_snr, - .get_frontend_algo = va1j5jf8007t_get_frontend_algo, - .read_status = va1j5jf8007t_read_status, - .tune = va1j5jf8007t_tune, - .sleep = va1j5jf8007t_sleep, - .init = va1j5jf8007t_init, - .release = va1j5jf8007t_release, -}; - -static const u8 va1j5jf8007t_20mhz_prepare_bufs[][2] = { - {0x03, 0x90}, {0x14, 0x8f}, {0x1c, 0x2a}, {0x1d, 0xa8}, {0x1e, 0xa2}, - {0x22, 0x83}, {0x31, 0x0d}, {0x32, 0xe0}, {0x39, 0xd3}, {0x3a, 0x00}, - {0x5c, 0x40}, {0x5f, 0x80}, {0x75, 0x02}, {0x76, 0x4e}, {0x77, 0x03}, - {0xef, 0x01} -}; - -static const u8 va1j5jf8007t_25mhz_prepare_bufs[][2] = { - {0x03, 0x90}, {0x1c, 0x2a}, {0x1d, 0xa8}, {0x1e, 0xa2}, {0x22, 0x83}, - {0x3a, 0x00}, {0x5c, 0x40}, {0x5f, 0x80}, {0x75, 0x0a}, {0x76, 0x4c}, - {0x77, 0x03}, {0xef, 0x01} -}; - -int va1j5jf8007t_prepare(struct dvb_frontend *fe) -{ - struct va1j5jf8007t_state *state; - const u8 (*bufs)[2]; - int size; - u8 buf[2]; - struct i2c_msg msg; - int i; - - state = fe->demodulator_priv; - - switch (state->config->frequency) { - case VA1J5JF8007T_20MHZ: - bufs = va1j5jf8007t_20mhz_prepare_bufs; - size = ARRAY_SIZE(va1j5jf8007t_20mhz_prepare_bufs); - break; - case VA1J5JF8007T_25MHZ: - bufs = va1j5jf8007t_25mhz_prepare_bufs; - size = ARRAY_SIZE(va1j5jf8007t_25mhz_prepare_bufs); - break; - default: - return -EINVAL; - } - - msg.addr = state->config->demod_address; - msg.flags = 0; - msg.len = sizeof(buf); - msg.buf = buf; - - for (i = 0; i < size; i++) { - memcpy(buf, bufs[i], sizeof(buf)); - if (i2c_transfer(state->adap, &msg, 1) != 1) - return -EREMOTEIO; - } - - return va1j5jf8007t_init_frequency(state); -} - -struct dvb_frontend * -va1j5jf8007t_attach(const struct va1j5jf8007t_config *config, - struct i2c_adapter *adap) -{ - struct va1j5jf8007t_state *state; - struct dvb_frontend *fe; - u8 buf[2]; - struct i2c_msg msg; - - state = kzalloc(sizeof(struct va1j5jf8007t_state), GFP_KERNEL); - if (!state) - return NULL; - - state->config = config; - state->adap = adap; - - fe = &state->fe; - memcpy(&fe->ops, &va1j5jf8007t_ops, sizeof(struct dvb_frontend_ops)); - fe->demodulator_priv = state; - - buf[0] = 0x01; - buf[1] = 0x80; - - msg.addr = state->config->demod_address; - msg.flags = 0; - msg.len = sizeof(buf); - msg.buf = buf; - - if (i2c_transfer(state->adap, &msg, 1) != 1) { - kfree(state); - return NULL; - } - - return fe; -} diff --git a/drivers/media/pci/pt1/va1j5jf8007t.h b/drivers/media/pci/pt1/va1j5jf8007t.h deleted file mode 100644 index 95eb7d294d20..000000000000 --- a/drivers/media/pci/pt1/va1j5jf8007t.h +++ /dev/null @@ -1,42 +0,0 @@ -/* - * ISDB-T driver for VA1J5JF8007/VA1J5JF8011 - * - * Copyright (C) 2009 HIRANO Takahito <hiranotaka@zng.info> - * - * based on pt1dvr - http://pt1dvr.sourceforge.jp/ - * by Tomoaki Ishikawa <tomy@users.sourceforge.jp> - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - */ - -#ifndef VA1J5JF8007T_H -#define VA1J5JF8007T_H - -enum va1j5jf8007t_frequency { - VA1J5JF8007T_20MHZ, - VA1J5JF8007T_25MHZ, -}; - -struct va1j5jf8007t_config { - u8 demod_address; - enum va1j5jf8007t_frequency frequency; -}; - -struct i2c_adapter; - -struct dvb_frontend * -va1j5jf8007t_attach(const struct va1j5jf8007t_config *config, - struct i2c_adapter *adap); - -/* must be called after va1j5jf8007s_attach */ -int va1j5jf8007t_prepare(struct dvb_frontend *fe); - -#endif diff --git a/drivers/media/pci/pt3/pt3.c b/drivers/media/pci/pt3/pt3.c index da74828805bc..90273b4d772f 100644 --- a/drivers/media/pci/pt3/pt3.c +++ b/drivers/media/pci/pt3/pt3.c @@ -1,17 +1,8 @@ +// SPDX-License-Identifier: GPL-2.0 /* * Earthsoft PT3 driver * * Copyright (C) 2014 Akihiro Tsukada <tskd08@gmail.com> - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation version 2. - * - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. */ #include <linux/freezer.h> @@ -376,25 +367,22 @@ static int pt3_fe_init(struct pt3_board *pt3) static int pt3_attach_fe(struct pt3_board *pt3, int i) { - struct i2c_board_info info; + const struct i2c_board_info *info; struct tc90522_config cfg; struct i2c_client *cl; struct dvb_adapter *dvb_adap; int ret; - info = adap_conf[i].demod_info; + info = &adap_conf[i].demod_info; cfg = adap_conf[i].demod_cfg; cfg.tuner_i2c = NULL; - info.platform_data = &cfg; ret = -ENODEV; - request_module("tc90522"); - cl = i2c_new_device(&pt3->i2c_adap, &info); - if (!cl || !cl->dev.driver) + cl = dvb_module_probe("tc90522", info->type, &pt3->i2c_adap, + info->addr, &cfg); + if (!cl) return -ENODEV; pt3->adaps[i]->i2c_demod = cl; - if (!try_module_get(cl->dev.driver->owner)) - goto err_demod_i2c_unregister_device; if (!strncmp(cl->name, TC90522_I2C_DEV_SAT, strlen(TC90522_I2C_DEV_SAT))) { @@ -402,41 +390,33 @@ static int pt3_attach_fe(struct pt3_board *pt3, int i) tcfg = adap_conf[i].tuner_cfg.qm1d1c0042; tcfg.fe = cfg.fe; - info = adap_conf[i].tuner_info; - info.platform_data = &tcfg; - request_module("qm1d1c0042"); - cl = i2c_new_device(cfg.tuner_i2c, &info); + info = &adap_conf[i].tuner_info; + cl = dvb_module_probe("qm1d1c0042", info->type, cfg.tuner_i2c, + info->addr, &tcfg); } else { struct mxl301rf_config tcfg; tcfg = adap_conf[i].tuner_cfg.mxl301rf; tcfg.fe = cfg.fe; - info = adap_conf[i].tuner_info; - info.platform_data = &tcfg; - request_module("mxl301rf"); - cl = i2c_new_device(cfg.tuner_i2c, &info); + info = &adap_conf[i].tuner_info; + cl = dvb_module_probe("mxl301rf", info->type, cfg.tuner_i2c, + info->addr, &tcfg); } - if (!cl || !cl->dev.driver) - goto err_demod_module_put; + if (!cl) + goto err_demod_module_release; pt3->adaps[i]->i2c_tuner = cl; - if (!try_module_get(cl->dev.driver->owner)) - goto err_tuner_i2c_unregister_device; dvb_adap = &pt3->adaps[one_adapter ? 0 : i]->dvb_adap; ret = dvb_register_frontend(dvb_adap, cfg.fe); if (ret < 0) - goto err_tuner_module_put; + goto err_tuner_module_release; pt3->adaps[i]->fe = cfg.fe; return 0; -err_tuner_module_put: - module_put(pt3->adaps[i]->i2c_tuner->dev.driver->owner); -err_tuner_i2c_unregister_device: - i2c_unregister_device(pt3->adaps[i]->i2c_tuner); -err_demod_module_put: - module_put(pt3->adaps[i]->i2c_demod->dev.driver->owner); -err_demod_i2c_unregister_device: - i2c_unregister_device(pt3->adaps[i]->i2c_demod); +err_tuner_module_release: + dvb_module_release(pt3->adaps[i]->i2c_tuner); +err_demod_module_release: + dvb_module_release(pt3->adaps[i]->i2c_demod); return ret; } @@ -464,7 +444,7 @@ static int pt3_fetch_thread(void *data) pt3_proc_dma(adap); - delay = PT3_FETCH_DELAY * NSEC_PER_MSEC; + delay = ktime_set(0, PT3_FETCH_DELAY * NSEC_PER_MSEC); set_current_state(TASK_UNINTERRUPTIBLE); freezable_schedule_hrtimeout_range(&delay, PT3_FETCH_DELAY_DELTA * NSEC_PER_MSEC, @@ -630,14 +610,8 @@ static void pt3_cleanup_adapter(struct pt3_board *pt3, int index) adap->fe->callback = NULL; if (adap->fe->frontend_priv) dvb_unregister_frontend(adap->fe); - if (adap->i2c_tuner) { - module_put(adap->i2c_tuner->dev.driver->owner); - i2c_unregister_device(adap->i2c_tuner); - } - if (adap->i2c_demod) { - module_put(adap->i2c_demod->dev.driver->owner); - i2c_unregister_device(adap->i2c_demod); - } + dvb_module_release(adap->i2c_tuner); + dvb_module_release(adap->i2c_demod); } pt3_free_dmabuf(adap); dvb_dmxdev_release(&adap->dmxdev); diff --git a/drivers/media/pci/pt3/pt3.h b/drivers/media/pci/pt3/pt3.h index fbe8d9b847b0..495891a4ee17 100644 --- a/drivers/media/pci/pt3/pt3.h +++ b/drivers/media/pci/pt3/pt3.h @@ -1,17 +1,8 @@ +/* SPDX-License-Identifier: GPL-2.0 */ /* * Earthsoft PT3 driver * * Copyright (C) 2014 Akihiro Tsukada <tskd08@gmail.com> - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation version 2. - * - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. */ #ifndef PT3_H diff --git a/drivers/media/pci/pt3/pt3_dma.c b/drivers/media/pci/pt3/pt3_dma.c index f0ce90437fac..de677b90ea5c 100644 --- a/drivers/media/pci/pt3/pt3_dma.c +++ b/drivers/media/pci/pt3/pt3_dma.c @@ -1,17 +1,8 @@ +// SPDX-License-Identifier: GPL-2.0 /* * Earthsoft PT3 driver * * Copyright (C) 2014 Akihiro Tsukada <tskd08@gmail.com> - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation version 2. - * - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. */ #include <linux/dma-mapping.h> #include <linux/kernel.h> diff --git a/drivers/media/pci/pt3/pt3_i2c.c b/drivers/media/pci/pt3/pt3_i2c.c index b66138c7b364..b02be789a8c5 100644 --- a/drivers/media/pci/pt3/pt3_i2c.c +++ b/drivers/media/pci/pt3/pt3_i2c.c @@ -1,17 +1,8 @@ +// SPDX-License-Identifier: GPL-2.0 /* * Earthsoft PT3 driver * * Copyright (C) 2014 Akihiro Tsukada <tskd08@gmail.com> - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation version 2. - * - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. */ #include <linux/delay.h> #include <linux/device.h> diff --git a/drivers/media/pci/saa7164/saa7164-fw.c b/drivers/media/pci/saa7164/saa7164-fw.c index ef4906406ebf..a50461861133 100644 --- a/drivers/media/pci/saa7164/saa7164-fw.c +++ b/drivers/media/pci/saa7164/saa7164-fw.c @@ -426,7 +426,8 @@ int saa7164_downloadfirmware(struct saa7164_dev *dev) __func__, fw->size); if (fw->size != fwlength) { - printk(KERN_ERR "xc5000: firmware incorrect size\n"); + printk(KERN_ERR "saa7164: firmware incorrect size %zu != %u\n", + fw->size, fwlength); ret = -ENOMEM; goto out; } diff --git a/drivers/media/pci/sta2x11/Kconfig b/drivers/media/pci/sta2x11/Kconfig index e03587b1af71..7af3f1cbcea8 100644 --- a/drivers/media/pci/sta2x11/Kconfig +++ b/drivers/media/pci/sta2x11/Kconfig @@ -1,6 +1,6 @@ config STA2X11_VIP tristate "STA2X11 VIP Video For Linux" - depends on STA2X11 + depends on STA2X11 || COMPILE_TEST depends on HAS_DMA select VIDEO_ADV7180 if MEDIA_SUBDRV_AUTOSELECT select VIDEOBUF2_DMA_CONTIG diff --git a/drivers/media/pci/sta2x11/sta2x11_vip.c b/drivers/media/pci/sta2x11/sta2x11_vip.c index dd199bfc1d45..069c4a853346 100644 --- a/drivers/media/pci/sta2x11/sta2x11_vip.c +++ b/drivers/media/pci/sta2x11/sta2x11_vip.c @@ -908,10 +908,10 @@ static int sta2x11_vip_init_controls(struct sta2x11_vip *vip) static int vip_gpio_reserve(struct device *dev, int pin, int dir, const char *name) { - int ret; + int ret = -ENODEV; - if (pin == -1) - return 0; + if (!gpio_is_valid(pin)) + return ret; ret = gpio_request(pin, name); if (ret) { @@ -946,7 +946,7 @@ static int vip_gpio_reserve(struct device *dev, int pin, int dir, */ static void vip_gpio_release(struct device *dev, int pin, const char *name) { - if (pin != -1) { + if (gpio_is_valid(pin)) { dev_dbg(dev, "releasing pin %d (%s)\n", pin, name); gpio_unexport(pin); gpio_free(pin); @@ -1003,25 +1003,24 @@ static int sta2x11_vip_init_one(struct pci_dev *pdev, if (ret) goto disable; - if (config->reset_pin >= 0) { - ret = vip_gpio_reserve(&pdev->dev, config->reset_pin, 0, - config->reset_name); - if (ret) { - vip_gpio_release(&pdev->dev, config->pwr_pin, - config->pwr_name); - goto disable; - } + ret = vip_gpio_reserve(&pdev->dev, config->reset_pin, 0, + config->reset_name); + if (ret) { + vip_gpio_release(&pdev->dev, config->pwr_pin, + config->pwr_name); + goto disable; } - if (config->pwr_pin != -1) { + + if (gpio_is_valid(config->pwr_pin)) { /* Datasheet says 5ms between PWR and RST */ usleep_range(5000, 25000); - ret = gpio_direction_output(config->pwr_pin, 1); + gpio_direction_output(config->pwr_pin, 1); } - if (config->reset_pin != -1) { + if (gpio_is_valid(config->reset_pin)) { /* Datasheet says 5ms between PWR and RST */ usleep_range(5000, 25000); - ret = gpio_direction_output(config->reset_pin, 1); + gpio_direction_output(config->reset_pin, 1); } usleep_range(5000, 25000); diff --git a/drivers/media/platform/Kconfig b/drivers/media/platform/Kconfig index c7a1cf8a1b01..5c3ae58cc40c 100644 --- a/drivers/media/platform/Kconfig +++ b/drivers/media/platform/Kconfig @@ -42,7 +42,7 @@ config VIDEO_SH_VOU config VIDEO_VIU tristate "Freescale VIU Video Driver" - depends on VIDEO_V4L2 && PPC_MPC512x + depends on VIDEO_V4L2 && (PPC_MPC512x || COMPILE_TEST) && I2C select VIDEOBUF_DMA_CONTIG default y ---help--- @@ -62,10 +62,11 @@ config VIDEO_MUX config VIDEO_OMAP3 tristate "OMAP 3 Camera support" - depends on VIDEO_V4L2 && I2C && VIDEO_V4L2_SUBDEV_API && ARCH_OMAP3 + depends on VIDEO_V4L2 && I2C && VIDEO_V4L2_SUBDEV_API + depends on (ARCH_OMAP3 && OMAP_IOMMU) || COMPILE_TEST + depends on COMMON_CLK depends on HAS_DMA && OF - depends on OMAP_IOMMU - select ARM_DMA_USE_IOMMU + select ARM_DMA_USE_IOMMU if OMAP_IOMMU select VIDEOBUF2_DMA_CONTIG select MFD_SYSCON select V4L2_FWNODE @@ -558,7 +559,7 @@ config VIDEO_MESON_AO_CEC config CEC_GPIO tristate "Generic GPIO-based CEC driver" - depends on PREEMPT + depends on PREEMPT || COMPILE_TEST select CEC_CORE select CEC_PIN select GPIOLIB diff --git a/drivers/media/platform/am437x/am437x-vpfe.c b/drivers/media/platform/am437x/am437x-vpfe.c index 601ae6487617..58ebc2220d0e 100644 --- a/drivers/media/platform/am437x/am437x-vpfe.c +++ b/drivers/media/platform/am437x/am437x-vpfe.c @@ -2662,8 +2662,7 @@ static void vpfe_save_context(struct vpfe_ccdc *ccdc) static int vpfe_suspend(struct device *dev) { - struct platform_device *pdev = to_platform_device(dev); - struct vpfe_device *vpfe = platform_get_drvdata(pdev); + struct vpfe_device *vpfe = dev_get_drvdata(dev); struct vpfe_ccdc *ccdc = &vpfe->ccdc; /* if streaming has not started we don't care */ @@ -2720,8 +2719,7 @@ static void vpfe_restore_context(struct vpfe_ccdc *ccdc) static int vpfe_resume(struct device *dev) { - struct platform_device *pdev = to_platform_device(dev); - struct vpfe_device *vpfe = platform_get_drvdata(pdev); + struct vpfe_device *vpfe = dev_get_drvdata(dev); struct vpfe_ccdc *ccdc = &vpfe->ccdc; /* if streaming has not started we don't care */ diff --git a/drivers/media/platform/cec-gpio/cec-gpio.c b/drivers/media/platform/cec-gpio/cec-gpio.c index f1f28cf5c751..69f8242209c2 100644 --- a/drivers/media/platform/cec-gpio/cec-gpio.c +++ b/drivers/media/platform/cec-gpio/cec-gpio.c @@ -158,7 +158,7 @@ static int cec_gpio_probe(struct platform_device *pdev) cec->dev = dev; - cec->cec_gpio = devm_gpiod_get(dev, "cec", GPIOD_IN); + cec->cec_gpio = devm_gpiod_get(dev, "cec", GPIOD_OUT_HIGH_OPEN_DRAIN); if (IS_ERR(cec->cec_gpio)) return PTR_ERR(cec->cec_gpio); cec->cec_irq = gpiod_to_irq(cec->cec_gpio); diff --git a/drivers/media/platform/coda/coda-common.c b/drivers/media/platform/coda/coda-common.c index 04e35d70ce2e..c7631e117dd3 100644 --- a/drivers/media/platform/coda/coda-common.c +++ b/drivers/media/platform/coda/coda-common.c @@ -779,16 +779,27 @@ static int coda_s_fmt_vid_cap(struct file *file, void *priv, r.width = q_data_src->width; r.height = q_data_src->height; - return coda_s_fmt(ctx, f, &r); + ret = coda_s_fmt(ctx, f, &r); + if (ret) + return ret; + + if (ctx->inst_type != CODA_INST_ENCODER) + return 0; + + ctx->colorspace = f->fmt.pix.colorspace; + ctx->xfer_func = f->fmt.pix.xfer_func; + ctx->ycbcr_enc = f->fmt.pix.ycbcr_enc; + ctx->quantization = f->fmt.pix.quantization; + + return 0; } static int coda_s_fmt_vid_out(struct file *file, void *priv, struct v4l2_format *f) { struct coda_ctx *ctx = fh_to_ctx(priv); - struct coda_q_data *q_data_src; struct v4l2_format f_cap; - struct v4l2_rect r; + struct vb2_queue *dst_vq; int ret; ret = coda_try_fmt_vid_out(file, priv, f); @@ -799,28 +810,34 @@ static int coda_s_fmt_vid_out(struct file *file, void *priv, if (ret) return ret; + if (ctx->inst_type != CODA_INST_DECODER) + return 0; + ctx->colorspace = f->fmt.pix.colorspace; ctx->xfer_func = f->fmt.pix.xfer_func; ctx->ycbcr_enc = f->fmt.pix.ycbcr_enc; ctx->quantization = f->fmt.pix.quantization; + dst_vq = v4l2_m2m_get_vq(ctx->fh.m2m_ctx, V4L2_BUF_TYPE_VIDEO_CAPTURE); + if (!dst_vq) + return -EINVAL; + + /* + * Setting the capture queue format is not possible while the capture + * queue is still busy. This is not an error, but the user will have to + * make sure themselves that the capture format is set correctly before + * starting the output queue again. + */ + if (vb2_is_busy(dst_vq)) + return 0; + memset(&f_cap, 0, sizeof(f_cap)); f_cap.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; coda_g_fmt(file, priv, &f_cap); f_cap.fmt.pix.width = f->fmt.pix.width; f_cap.fmt.pix.height = f->fmt.pix.height; - ret = coda_try_fmt_vid_cap(file, priv, &f_cap); - if (ret) - return ret; - - q_data_src = get_q_data(ctx, V4L2_BUF_TYPE_VIDEO_OUTPUT); - r.left = 0; - r.top = 0; - r.width = q_data_src->width; - r.height = q_data_src->height; - - return coda_s_fmt(ctx, &f_cap, &r); + return coda_s_fmt_vid_cap(file, priv, &f_cap); } static int coda_reqbufs(struct file *file, void *priv, diff --git a/drivers/media/platform/davinci/Kconfig b/drivers/media/platform/davinci/Kconfig index 55982e681d77..b463d1726335 100644 --- a/drivers/media/platform/davinci/Kconfig +++ b/drivers/media/platform/davinci/Kconfig @@ -67,7 +67,8 @@ config VIDEO_DM355_CCDC config VIDEO_DM365_ISIF tristate "TI DM365 ISIF video capture driver" - depends on VIDEO_V4L2 && ARCH_DAVINCI + depends on VIDEO_V4L2 + depends on ARCH_DAVINCI || COMPILE_TEST depends on HAS_DMA depends on I2C select VIDEOBUF_DMA_CONTIG @@ -81,7 +82,8 @@ config VIDEO_DM365_ISIF config VIDEO_DAVINCI_VPBE_DISPLAY tristate "TI DaVinci VPBE V4L2-Display driver" - depends on VIDEO_V4L2 && ARCH_DAVINCI + depends on VIDEO_V4L2 + depends on ARCH_DAVINCI || COMPILE_TEST depends on HAS_DMA depends on I2C select VIDEOBUF2_DMA_CONTIG diff --git a/drivers/media/platform/davinci/isif.c b/drivers/media/platform/davinci/isif.c index d5ff58494c1e..f924e76e2fbf 100644 --- a/drivers/media/platform/davinci/isif.c +++ b/drivers/media/platform/davinci/isif.c @@ -31,8 +31,6 @@ #include <linux/err.h> #include <linux/module.h> -#include <mach/mux.h> - #include <media/davinci/isif.h> #include <media/davinci/vpss.h> @@ -1029,7 +1027,7 @@ static int isif_probe(struct platform_device *pdev) { void (*setup_pinmux)(void); struct resource *res; - void *__iomem addr; + void __iomem *addr; int status = 0, i; /* Platform data holds setup_pinmux function ptr */ diff --git a/drivers/media/platform/davinci/vpbe.c b/drivers/media/platform/davinci/vpbe.c index 7f6462562579..18c035ef84cf 100644 --- a/drivers/media/platform/davinci/vpbe.c +++ b/drivers/media/platform/davinci/vpbe.c @@ -51,7 +51,7 @@ MODULE_AUTHOR("Texas Instruments"); /** * vpbe_current_encoder_info - Get config info for current encoder - * @vpbe_dev - vpbe device ptr + * @vpbe_dev: vpbe device ptr * * Return ptr to current encoder config info */ @@ -68,8 +68,8 @@ vpbe_current_encoder_info(struct vpbe_device *vpbe_dev) /** * vpbe_find_encoder_sd_index - Given a name find encoder sd index * - * @vpbe_config - ptr to vpbe cfg - * @output_index - index used by application + * @cfg: ptr to vpbe cfg + * @index: index used by application * * Return sd index of the encoder */ @@ -94,8 +94,8 @@ static int vpbe_find_encoder_sd_index(struct vpbe_config *cfg, /** * vpbe_g_cropcap - Get crop capabilities of the display - * @vpbe_dev - vpbe device ptr - * @cropcap - cropcap is a ptr to struct v4l2_cropcap + * @vpbe_dev: vpbe device ptr + * @cropcap: cropcap is a ptr to struct v4l2_cropcap * * Update the crop capabilities in crop cap for current * mode @@ -116,8 +116,8 @@ static int vpbe_g_cropcap(struct vpbe_device *vpbe_dev, /** * vpbe_enum_outputs - enumerate outputs - * @vpbe_dev - vpbe device ptr - * @output - ptr to v4l2_output structure + * @vpbe_dev: vpbe device ptr + * @output: ptr to v4l2_output structure * * Enumerates the outputs available at the vpbe display * returns the status, -EINVAL if end of output list @@ -212,8 +212,8 @@ static int vpbe_get_std_info_by_name(struct vpbe_device *vpbe_dev, /** * vpbe_set_output - Set output - * @vpbe_dev - vpbe device ptr - * @index - index of output + * @vpbe_dev: vpbe device ptr + * @index: index of output * * Set vpbe output to the output specified by the index */ @@ -308,7 +308,7 @@ static int vpbe_set_default_output(struct vpbe_device *vpbe_dev) /** * vpbe_get_output - Get output - * @vpbe_dev - vpbe device ptr + * @vpbe_dev: vpbe device ptr * * return current vpbe output to the the index */ @@ -317,7 +317,7 @@ static unsigned int vpbe_get_output(struct vpbe_device *vpbe_dev) return vpbe_dev->current_out_index; } -/** +/* * vpbe_s_dv_timings - Set the given preset timings in the encoder * * Sets the timings if supported by the current encoder. Return the status. @@ -369,7 +369,7 @@ static int vpbe_s_dv_timings(struct vpbe_device *vpbe_dev, return ret; } -/** +/* * vpbe_g_dv_timings - Get the timings in the current encoder * * Get the timings in the current encoder. Return the status. 0 - success @@ -394,7 +394,7 @@ static int vpbe_g_dv_timings(struct vpbe_device *vpbe_dev, return -EINVAL; } -/** +/* * vpbe_enum_dv_timings - Enumerate the dv timings in the current encoder * * Get the timings in the current encoder. Return the status. 0 - success @@ -426,7 +426,7 @@ static int vpbe_enum_dv_timings(struct vpbe_device *vpbe_dev, return 0; } -/** +/* * vpbe_s_std - Set the given standard in the encoder * * Sets the standard if supported by the current encoder. Return the status. @@ -465,7 +465,7 @@ static int vpbe_s_std(struct vpbe_device *vpbe_dev, v4l2_std_id std_id) return ret; } -/** +/* * vpbe_g_std - Get the standard in the current encoder * * Get the standard in the current encoder. Return the status. 0 - success @@ -488,7 +488,7 @@ static int vpbe_g_std(struct vpbe_device *vpbe_dev, v4l2_std_id *std_id) return -EINVAL; } -/** +/* * vpbe_set_mode - Set mode in the current encoder using mode info * * Use the mode string to decide what timings to set in the encoder @@ -572,7 +572,8 @@ static int platform_device_get(struct device *dev, void *data) /** * vpbe_initialize() - Initialize the vpbe display controller - * @vpbe_dev - vpbe device ptr + * @dev: Master and slave device ptr + * @vpbe_dev: vpbe device ptr * * Master frame buffer device drivers calls this to initialize vpbe * display controller. This will then registers v4l2 device and the sub @@ -769,7 +770,8 @@ fail_mutex_unlock: /** * vpbe_deinitialize() - de-initialize the vpbe display controller - * @dev - Master and slave device ptr + * @dev: Master and slave device ptr + * @vpbe_dev: vpbe device ptr * * vpbe_master and slave frame buffer devices calls this to de-initialize * the display controller. It is called when master and slave device diff --git a/drivers/media/platform/davinci/vpbe_display.c b/drivers/media/platform/davinci/vpbe_display.c index 6aabd21fe69f..b0eb3d899eb4 100644 --- a/drivers/media/platform/davinci/vpbe_display.c +++ b/drivers/media/platform/davinci/vpbe_display.c @@ -26,7 +26,10 @@ #include <linux/slab.h> #include <asm/pgtable.h> + +#ifdef CONFIG_ARCH_DAVINCI #include <mach/cputype.h> +#endif #include <media/v4l2-dev.h> #include <media/v4l2-common.h> @@ -53,8 +56,7 @@ static int vpbe_set_osd_display_params(struct vpbe_display *disp_dev, static int venc_is_second_field(struct vpbe_display *disp_dev) { struct vpbe_device *vpbe_dev = disp_dev->vpbe_dev; - int ret; - int val; + int ret, val; ret = v4l2_subdev_call(vpbe_dev->venc, core, @@ -64,6 +66,7 @@ static int venc_is_second_field(struct vpbe_display *disp_dev) if (ret < 0) { v4l2_err(&vpbe_dev->v4l2_dev, "Error in getting Field ID 0\n"); + return 1; } return val; } @@ -282,7 +285,7 @@ static int vpbe_start_streaming(struct vb2_queue *vq, unsigned int count) struct osd_state *osd_device = layer->disp_dev->osd_device; int ret; - osd_device->ops.disable_layer(osd_device, layer->layer_info.id); + osd_device->ops.disable_layer(osd_device, layer->layer_info.id); /* Get the next frame from the buffer queue */ layer->next_frm = layer->cur_frm = list_entry(layer->dma_queue.next, @@ -564,7 +567,7 @@ static void vpbe_disp_check_window_params(struct vpbe_display *disp_dev, } -/** +/* * vpbe_try_format() * If user application provides width and height, and have bytesperline set * to zero, driver calculates bytesperline and sizeimage based on hardware @@ -929,7 +932,7 @@ static int vpbe_display_try_fmt(struct file *file, void *priv, } -/** +/* * vpbe_display_s_std - Set the given standard in the encoder * * Sets the standard if supported by the current encoder. Return the status. @@ -961,7 +964,7 @@ static int vpbe_display_s_std(struct file *file, void *priv, return 0; } -/** +/* * vpbe_display_g_std - Get the standard in the current encoder * * Get the standard in the current encoder. Return the status. 0 - success @@ -984,7 +987,7 @@ static int vpbe_display_g_std(struct file *file, void *priv, return -EINVAL; } -/** +/* * vpbe_display_enum_output - enumerate outputs * * Enumerates the outputs available at the vpbe display @@ -1013,7 +1016,7 @@ static int vpbe_display_enum_output(struct file *file, void *priv, return 0; } -/** +/* * vpbe_display_s_output - Set output to * the output specified by the index */ @@ -1042,7 +1045,7 @@ static int vpbe_display_s_output(struct file *file, void *priv, return 0; } -/** +/* * vpbe_display_g_output - Get output from subdevice * for a given by the index */ @@ -1059,7 +1062,7 @@ static int vpbe_display_g_output(struct file *file, void *priv, return 0; } -/** +/* * vpbe_display_enum_dv_timings - Enumerate the dv timings * * enum the timings in the current encoder. Return the status. 0 - success @@ -1089,7 +1092,7 @@ vpbe_display_enum_dv_timings(struct file *file, void *priv, return 0; } -/** +/* * vpbe_display_s_dv_timings - Set the dv timings * * Set the timings in the current encoder. Return the status. 0 - success @@ -1122,7 +1125,7 @@ vpbe_display_s_dv_timings(struct file *file, void *priv, return 0; } -/** +/* * vpbe_display_g_dv_timings - Set the dv timings * * Get the timings in the current encoder. Return the status. 0 - success @@ -1351,9 +1354,9 @@ static int register_device(struct vpbe_layer *vpbe_display_layer, v4l2_info(&disp_dev->vpbe_dev->v4l2_dev, "Trying to register VPBE display device.\n"); v4l2_info(&disp_dev->vpbe_dev->v4l2_dev, - "layer=%x,layer->video_dev=%x\n", - (int)vpbe_display_layer, - (int)&vpbe_display_layer->video_dev); + "layer=%p,layer->video_dev=%p\n", + vpbe_display_layer, + &vpbe_display_layer->video_dev); vpbe_display_layer->video_dev.queue = &vpbe_display_layer->buffer_queue; err = video_register_device(&vpbe_display_layer->video_dev, diff --git a/drivers/media/platform/davinci/vpbe_osd.c b/drivers/media/platform/davinci/vpbe_osd.c index 66449791c70c..7f610320426d 100644 --- a/drivers/media/platform/davinci/vpbe_osd.c +++ b/drivers/media/platform/davinci/vpbe_osd.c @@ -24,8 +24,10 @@ #include <linux/clk.h> #include <linux/slab.h> +#ifdef CONFIG_ARCH_DAVINCI #include <mach/cputype.h> #include <mach/hardware.h> +#endif #include <media/davinci/vpss.h> #include <media/v4l2-device.h> @@ -122,10 +124,10 @@ static inline u32 osd_modify(struct osd_state *sd, u32 mask, u32 val, /** * _osd_dm6446_vid0_pingpong() - field inversion fix for DM6446 - * @sd - ptr to struct osd_state - * @field_inversion - inversion flag - * @fb_base_phys - frame buffer address - * @lconfig - ptr to layer config + * @sd: ptr to struct osd_state + * @field_inversion: inversion flag + * @fb_base_phys: frame buffer address + * @lconfig: ptr to layer config * * This routine implements a workaround for the field signal inversion silicon * erratum described in Advisory 1.3.8 for the DM6446. The fb_base_phys and @@ -782,9 +784,9 @@ static void osd_get_layer_config(struct osd_state *sd, enum osd_layer layer, /** * try_layer_config() - Try a specific configuration for the layer - * @sd - ptr to struct osd_state - * @layer - layer to configure - * @lconfig - layer configuration to try + * @sd: ptr to struct osd_state + * @layer: layer to configure + * @lconfig: layer configuration to try * * If the requested lconfig is completely rejected and the value of lconfig on * exit is the current lconfig, then try_layer_config() returns 1. Otherwise, @@ -844,9 +846,10 @@ static int try_layer_config(struct osd_state *sd, enum osd_layer layer, /* DM6446: */ /* only one OSD window at a time can use RGB pixel formats */ - if ((osd->vpbe_type == VPBE_VERSION_1) && - is_osd_win(layer) && is_rgb_pixfmt(lconfig->pixfmt)) { + if ((osd->vpbe_type == VPBE_VERSION_1) && + is_osd_win(layer) && is_rgb_pixfmt(lconfig->pixfmt)) { enum osd_pix_format pixfmt; + if (layer == WIN_OSD0) pixfmt = osd->win[WIN_OSD1].lconfig.pixfmt; else diff --git a/drivers/media/platform/davinci/vpbe_venc.c b/drivers/media/platform/davinci/vpbe_venc.c index 3a4e78595149..ba157827192c 100644 --- a/drivers/media/platform/davinci/vpbe_venc.c +++ b/drivers/media/platform/davinci/vpbe_venc.c @@ -21,8 +21,11 @@ #include <linux/videodev2.h> #include <linux/slab.h> +#ifdef CONFIG_ARCH_DAVINCI #include <mach/hardware.h> #include <mach/mux.h> +#endif + #include <linux/platform_data/i2c-davinci.h> #include <linux/io.h> @@ -224,7 +227,6 @@ venc_enable_vpss_clock(int venc_type, */ static int venc_set_ntsc(struct v4l2_subdev *sd) { - u32 val; struct venc_state *venc = to_state(sd); struct venc_platform_data *pdata = venc->pdata; @@ -241,7 +243,7 @@ static int venc_set_ntsc(struct v4l2_subdev *sd) if (venc->venc_type == VPBE_VERSION_3) { venc_write(sd, VENC_CLKCTL, 0x01); venc_write(sd, VENC_VIDCTL, 0); - val = vdaccfg_write(sd, VDAC_CONFIG_SD_V3); + vdaccfg_write(sd, VDAC_CONFIG_SD_V3); } else if (venc->venc_type == VPBE_VERSION_2) { venc_write(sd, VENC_CLKCTL, 0x01); venc_write(sd, VENC_VIDCTL, 0); @@ -604,10 +606,9 @@ static int venc_device_get(struct device *dev, void *data) struct v4l2_subdev *venc_sub_dev_init(struct v4l2_device *v4l2_dev, const char *venc_name) { - struct venc_state *venc; - int err; + struct venc_state *venc = NULL; - err = bus_for_each_dev(&platform_bus_type, NULL, &venc, + bus_for_each_dev(&platform_bus_type, NULL, &venc, venc_device_get); if (venc == NULL) return NULL; diff --git a/drivers/media/platform/davinci/vpfe_capture.c b/drivers/media/platform/davinci/vpfe_capture.c index 6f44abf7fa31..8613358ed245 100644 --- a/drivers/media/platform/davinci/vpfe_capture.c +++ b/drivers/media/platform/davinci/vpfe_capture.c @@ -1509,7 +1509,7 @@ static int vpfe_streamon(struct file *file, void *priv, unlock_out: mutex_unlock(&vpfe_dev->lock); streamoff: - ret = videobuf_streamoff(&vpfe_dev->buffer_queue); + videobuf_streamoff(&vpfe_dev->buffer_queue); return ret; } diff --git a/drivers/media/platform/exynos4-is/Kconfig b/drivers/media/platform/exynos4-is/Kconfig index 7b2c49e5a592..c8e5ad8f8294 100644 --- a/drivers/media/platform/exynos4-is/Kconfig +++ b/drivers/media/platform/exynos4-is/Kconfig @@ -41,11 +41,10 @@ config VIDEO_S5P_MIPI_CSIS To compile this driver as a module, choose M here: the module will be called s5p-csis. -if SOC_EXYNOS4412 || SOC_EXYNOS5250 - config VIDEO_EXYNOS_FIMC_LITE tristate "EXYNOS FIMC-LITE camera interface driver" depends on I2C + depends on SOC_EXYNOS4412 || SOC_EXYNOS5250 || COMPILE_TEST depends on HAS_DMA select VIDEOBUF2_DMA_CONTIG select VIDEO_EXYNOS4_IS_COMMON @@ -55,7 +54,6 @@ config VIDEO_EXYNOS_FIMC_LITE To compile this driver as a module, choose M here: the module will be called exynos-fimc-lite. -endif config VIDEO_EXYNOS4_FIMC_IS tristate "EXYNOS4x12 FIMC-IS (Imaging Subsystem) driver" diff --git a/drivers/media/platform/exynos4-is/fimc-lite-reg.c b/drivers/media/platform/exynos4-is/fimc-lite-reg.c index f0acc550d065..16565a0b4bf1 100644 --- a/drivers/media/platform/exynos4-is/fimc-lite-reg.c +++ b/drivers/media/platform/exynos4-is/fimc-lite-reg.c @@ -254,7 +254,7 @@ void flite_hw_set_dma_window(struct fimc_lite *dev, struct flite_frame *f) /* Maximum output pixel size */ cfg = readl(dev->regs + FLITE_REG_CIOCAN); cfg &= ~FLITE_REG_CIOCAN_MASK; - cfg = (f->f_height << 16) | f->f_width; + cfg |= (f->f_height << 16) | f->f_width; writel(cfg, dev->regs + FLITE_REG_CIOCAN); /* DMA offsets */ diff --git a/drivers/media/platform/fsl-viu.c b/drivers/media/platform/fsl-viu.c index 200c47c69a75..e41510ce69a4 100644 --- a/drivers/media/platform/fsl-viu.c +++ b/drivers/media/platform/fsl-viu.c @@ -36,6 +36,12 @@ #define DRV_NAME "fsl_viu" #define VIU_VERSION "0.5.1" +/* Allow building this driver with COMPILE_TEST */ +#ifndef CONFIG_PPC +#define out_be32(v, a) iowrite32be(a, (void __iomem *)v) +#define in_be32(a) ioread32be((void __iomem *)a) +#endif + #define BUFFER_TIMEOUT msecs_to_jiffies(500) /* 0.5 seconds */ #define VIU_VID_MEM_LIMIT 4 /* Video memory limit, in Mb */ @@ -128,7 +134,7 @@ struct viu_dev { int dma_done; /* Hardware register area */ - struct viu_reg *vr; + struct viu_reg __iomem *vr; /* Interrupt vector */ int irq; @@ -229,7 +235,7 @@ enum status_config { static irqreturn_t viu_intr(int irq, void *dev_id); -struct viu_fmt *format_by_fourcc(int fourcc) +static struct viu_fmt *format_by_fourcc(int fourcc) { int i; @@ -242,9 +248,9 @@ struct viu_fmt *format_by_fourcc(int fourcc) return NULL; } -void viu_start_dma(struct viu_dev *dev) +static void viu_start_dma(struct viu_dev *dev) { - struct viu_reg *vr = dev->vr; + struct viu_reg __iomem *vr = dev->vr; dev->field = 0; @@ -253,9 +259,9 @@ void viu_start_dma(struct viu_dev *dev) out_be32(&vr->status_cfg, INT_FIELD_EN); } -void viu_stop_dma(struct viu_dev *dev) +static void viu_stop_dma(struct viu_dev *dev) { - struct viu_reg *vr = dev->vr; + struct viu_reg __iomem *vr = dev->vr; int cnt = 100; u32 status_cfg; @@ -290,7 +296,7 @@ static int restart_video_queue(struct viu_dmaqueue *vidq) { struct viu_buf *buf, *prev; - dprintk(1, "%s vidq=0x%08lx\n", __func__, (unsigned long)vidq); + dprintk(1, "%s vidq=%p\n", __func__, vidq); if (!list_empty(&vidq->active)) { buf = list_entry(vidq->active.next, struct viu_buf, vb.queue); dprintk(2, "restart_queue [%p/%d]: restart dma\n", @@ -395,7 +401,7 @@ static void free_buffer(struct videobuf_queue *vq, struct viu_buf *buf) inline int buffer_activate(struct viu_dev *dev, struct viu_buf *buf) { - struct viu_reg *vr = dev->vr; + struct viu_reg __iomem *vr = dev->vr; int bpp; /* setup the DMA base address */ @@ -497,8 +503,7 @@ static void buffer_queue(struct videobuf_queue *vq, struct videobuf_buffer *vb) struct viu_buf *prev; if (!list_empty(&vidq->queued)) { - dprintk(1, "adding vb queue=0x%08lx\n", - (unsigned long)&buf->vb.queue); + dprintk(1, "adding vb queue=%p\n", &buf->vb.queue); dprintk(1, "vidq pointer 0x%p, queued 0x%p\n", vidq, &vidq->queued); dprintk(1, "dev %p, queued: self %p, next %p, head %p\n", @@ -509,8 +514,7 @@ static void buffer_queue(struct videobuf_queue *vq, struct videobuf_buffer *vb) dprintk(2, "[%p/%d] buffer_queue - append to queued\n", buf, buf->vb.i); } else if (list_empty(&vidq->active)) { - dprintk(1, "adding vb active=0x%08lx\n", - (unsigned long)&buf->vb.queue); + dprintk(1, "adding vb active=%p\n", &buf->vb.queue); list_add_tail(&buf->vb.queue, &vidq->active); buf->vb.state = VIDEOBUF_ACTIVE; mod_timer(&vidq->timeout, jiffies+BUFFER_TIMEOUT); @@ -519,8 +523,7 @@ static void buffer_queue(struct videobuf_queue *vq, struct videobuf_buffer *vb) buffer_activate(dev, buf); } else { - dprintk(1, "adding vb queue2=0x%08lx\n", - (unsigned long)&buf->vb.queue); + dprintk(1, "adding vb queue2=%p\n", &buf->vb.queue); prev = list_entry(vidq->active.prev, struct viu_buf, vb.queue); if (prev->vb.width == buf->vb.width && prev->vb.height == buf->vb.height && @@ -703,10 +706,8 @@ static int verify_preview(struct viu_dev *dev, struct v4l2_window *win) return 0; } -inline void viu_activate_overlay(struct viu_reg *viu_reg) +inline void viu_activate_overlay(struct viu_reg __iomem *vr) { - struct viu_reg *vr = viu_reg; - out_be32(&vr->field_base_addr, reg_val.field_base_addr); out_be32(&vr->dma_inc, reg_val.dma_inc); out_be32(&vr->picture_count, reg_val.picture_count); @@ -749,7 +750,7 @@ static int viu_setup_preview(struct viu_dev *dev, struct viu_fh *fh) reg_val.status_cfg |= DMA_ACT | INT_DMA_END_EN | INT_FIELD_EN; /* setup the base address of the overlay buffer */ - reg_val.field_base_addr = (u32)dev->ovbuf.base; + reg_val.field_base_addr = (u32)(long)dev->ovbuf.base; return 0; } @@ -802,7 +803,7 @@ static int vidioc_overlay(struct file *file, void *priv, unsigned int on) return 0; } -int vidioc_g_fbuf(struct file *file, void *priv, struct v4l2_framebuffer *arg) +static int vidioc_g_fbuf(struct file *file, void *priv, struct v4l2_framebuffer *arg) { struct viu_fh *fh = priv; struct viu_dev *dev = fh->dev; @@ -813,7 +814,7 @@ int vidioc_g_fbuf(struct file *file, void *priv, struct v4l2_framebuffer *arg) return 0; } -int vidioc_s_fbuf(struct file *file, void *priv, const struct v4l2_framebuffer *arg) +static int vidioc_s_fbuf(struct file *file, void *priv, const struct v4l2_framebuffer *arg) { struct viu_fh *fh = priv; struct viu_dev *dev = fh->dev; @@ -985,10 +986,8 @@ inline void viu_activate_next_buf(struct viu_dev *dev, } } -inline void viu_default_settings(struct viu_reg *viu_reg) +inline void viu_default_settings(struct viu_reg __iomem *vr) { - struct viu_reg *vr = viu_reg; - out_be32(&vr->luminance, 0x9512A254); out_be32(&vr->chroma_r, 0x03310000); out_be32(&vr->chroma_g, 0x06600F38); @@ -1001,7 +1000,7 @@ inline void viu_default_settings(struct viu_reg *viu_reg) static void viu_overlay_intr(struct viu_dev *dev, u32 status) { - struct viu_reg *vr = dev->vr; + struct viu_reg __iomem *vr = dev->vr; if (status & INT_DMA_END_STATUS) dev->dma_done = 1; @@ -1032,7 +1031,7 @@ static void viu_overlay_intr(struct viu_dev *dev, u32 status) static void viu_capture_intr(struct viu_dev *dev, u32 status) { struct viu_dmaqueue *vidq = &dev->vidq; - struct viu_reg *vr = dev->vr; + struct viu_reg __iomem *vr = dev->vr; struct viu_buf *buf; int field_num; int need_two; @@ -1104,7 +1103,7 @@ static void viu_capture_intr(struct viu_dev *dev, u32 status) static irqreturn_t viu_intr(int irq, void *dev_id) { struct viu_dev *dev = (struct viu_dev *)dev_id; - struct viu_reg *vr = dev->vr; + struct viu_reg __iomem *vr = dev->vr; u32 status; u32 error; @@ -1169,7 +1168,7 @@ static int viu_open(struct file *file) struct video_device *vdev = video_devdata(file); struct viu_dev *dev = video_get_drvdata(vdev); struct viu_fh *fh; - struct viu_reg *vr; + struct viu_reg __iomem *vr; int minor = vdev->minor; u32 status_cfg; @@ -1210,9 +1209,7 @@ static int viu_open(struct file *file) dev->crop_current.width = fh->width; dev->crop_current.height = fh->height; - dprintk(1, "Open: fh=0x%08lx, dev=0x%08lx, dev->vidq=0x%08lx\n", - (unsigned long)fh, (unsigned long)dev, - (unsigned long)&dev->vidq); + dprintk(1, "Open: fh=%p, dev=%p, dev->vidq=%p\n", fh, dev, &dev->vidq); dprintk(1, "Open: list_empty queued=%d\n", list_empty(&dev->vidq.queued)); dprintk(1, "Open: list_empty active=%d\n", @@ -1305,7 +1302,7 @@ static int viu_release(struct file *file) return 0; } -void viu_reset(struct viu_reg *reg) +static void viu_reset(struct viu_reg __iomem *reg) { out_be32(®->status_cfg, 0); out_be32(®->luminance, 0x9512a254); @@ -1325,7 +1322,7 @@ static int viu_mmap(struct file *file, struct vm_area_struct *vma) struct viu_dev *dev = fh->dev; int ret; - dprintk(1, "mmap called, vma=0x%08lx\n", (unsigned long)vma); + dprintk(1, "mmap called, vma=%p\n", vma); if (mutex_lock_interruptible(&dev->lock)) return -ERESTARTSYS; @@ -1407,7 +1404,7 @@ static int viu_of_probe(struct platform_device *op) } viu_irq = irq_of_parse_and_map(op->dev.of_node, 0); - if (viu_irq == NO_IRQ) { + if (!viu_irq) { dev_err(&op->dev, "Error while mapping the irq\n"); return -EINVAL; } diff --git a/drivers/media/platform/marvell-ccic/Kconfig b/drivers/media/platform/marvell-ccic/Kconfig index 4bf5bd1e90d6..21dacef7c2fc 100644 --- a/drivers/media/platform/marvell-ccic/Kconfig +++ b/drivers/media/platform/marvell-ccic/Kconfig @@ -13,8 +13,9 @@ config VIDEO_CAFE_CCIC config VIDEO_MMP_CAMERA tristate "Marvell Armada 610 integrated camera controller support" - depends on ARCH_MMP && I2C && VIDEO_V4L2 - depends on HAS_DMA && BROKEN + depends on I2C && VIDEO_V4L2 + depends on HAS_DMA + depends on ARCH_MMP || COMPILE_TEST select VIDEO_OV7670 select I2C_GPIO select VIDEOBUF2_DMA_SG diff --git a/drivers/media/platform/marvell-ccic/mmp-driver.c b/drivers/media/platform/marvell-ccic/mmp-driver.c index 816f4b6a7b8e..3cf300072348 100644 --- a/drivers/media/platform/marvell-ccic/mmp-driver.c +++ b/drivers/media/platform/marvell-ccic/mmp-driver.c @@ -37,7 +37,7 @@ MODULE_LICENSE("GPL"); static char *mcam_clks[] = {"CCICAXICLK", "CCICFUNCLK", "CCICPHYCLK"}; struct mmp_camera { - void *power_regs; + void __iomem *power_regs; struct platform_device *pdev; struct mcam_camera mcam; struct list_head devlist; @@ -183,7 +183,7 @@ static void mmpcam_power_down(struct mcam_camera *mcam) mcam_clk_disable(mcam); } -void mcam_ctlr_reset(struct mcam_camera *mcam) +static void mcam_ctlr_reset(struct mcam_camera *mcam) { unsigned long val; struct mmp_camera *cam = mcam_to_cam(mcam); @@ -214,7 +214,7 @@ void mcam_ctlr_reset(struct mcam_camera *mcam) * CSI2_DPHY3 and CSI2_DPHY6 can be set with a default value * or be calculated dynamically */ -void mmpcam_calc_dphy(struct mcam_camera *mcam) +static void mmpcam_calc_dphy(struct mcam_camera *mcam) { struct mmp_camera *cam = mcam_to_cam(mcam); struct mmp_camera_platform_data *pdata = cam->pdev->dev.platform_data; diff --git a/drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c b/drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c index af17aaa21f58..328e8f650d9b 100644 --- a/drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c +++ b/drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c @@ -1084,10 +1084,7 @@ static int mtk_jpeg_clk_init(struct mtk_jpeg_dev *jpeg) return PTR_ERR(jpeg->clk_jdec); jpeg->clk_jdec_smi = devm_clk_get(jpeg->dev, "jpgdec-smi"); - if (IS_ERR(jpeg->clk_jdec_smi)) - return PTR_ERR(jpeg->clk_jdec_smi); - - return 0; + return PTR_ERR_OR_ZERO(jpeg->clk_jdec_smi); } static int mtk_jpeg_probe(struct platform_device *pdev) diff --git a/drivers/media/platform/omap/Kconfig b/drivers/media/platform/omap/Kconfig index e8e2db181a7a..a414bcbb9b08 100644 --- a/drivers/media/platform/omap/Kconfig +++ b/drivers/media/platform/omap/Kconfig @@ -1,15 +1,16 @@ config VIDEO_OMAP2_VOUT_VRFB bool + default y + depends on VIDEO_OMAP2_VOUT && (OMAP2_VRFB || COMPILE_TEST) config VIDEO_OMAP2_VOUT tristate "OMAP2/OMAP3 V4L2-Display driver" depends on MMU - depends on ARCH_OMAP2 || ARCH_OMAP3 - depends on FB_OMAP2 + depends on FB_OMAP2 || COMPILE_TEST + depends on ARCH_OMAP2 || ARCH_OMAP3 || COMPILE_TEST select VIDEOBUF_GEN select VIDEOBUF_DMA_CONTIG select OMAP2_VRFB if ARCH_OMAP2 || ARCH_OMAP3 - select VIDEO_OMAP2_VOUT_VRFB if VIDEO_OMAP2_VOUT && OMAP2_VRFB select FRAME_VECTOR default n ---help--- diff --git a/drivers/media/platform/omap/omap_vout.c b/drivers/media/platform/omap/omap_vout.c index a795a9fae899..5700b7818621 100644 --- a/drivers/media/platform/omap/omap_vout.c +++ b/drivers/media/platform/omap/omap_vout.c @@ -198,7 +198,7 @@ static int omap_vout_try_format(struct v4l2_pix_format *pix) * omap_vout_get_userptr: Convert user space virtual address to physical * address. */ -static int omap_vout_get_userptr(struct videobuf_buffer *vb, u32 virtp, +static int omap_vout_get_userptr(struct videobuf_buffer *vb, long virtp, u32 *physp) { struct frame_vector *vec; @@ -702,19 +702,18 @@ static int omap_vout_buffer_setup(struct videobuf_queue *q, unsigned int *count, virt_addr = omap_vout_alloc_buffer(vout->buffer_size, &phy_addr); if (!virt_addr) { - if (ovid->rotation_type == VOUT_ROT_NONE) { + if (ovid->rotation_type == VOUT_ROT_NONE) break; - } else { - if (!is_rotation_enabled(vout)) - break; + + if (!is_rotation_enabled(vout)) + break; + /* Free the VRFB buffers if no space for V4L2 buffers */ for (j = i; j < *count; j++) { - omap_vout_free_buffer( - vout->smsshado_virt_addr[j], - vout->smsshado_size); + omap_vout_free_buffer(vout->smsshado_virt_addr[j], + vout->smsshado_size); vout->smsshado_virt_addr[j] = 0; vout->smsshado_phy_addr[j] = 0; - } } } vout->buf_virt_addr[i] = virt_addr; diff --git a/drivers/media/platform/omap/omap_vout_vrfb.c b/drivers/media/platform/omap/omap_vout_vrfb.c index 1d8508237220..29e3f5da59c1 100644 --- a/drivers/media/platform/omap/omap_vout_vrfb.c +++ b/drivers/media/platform/omap/omap_vout_vrfb.c @@ -54,8 +54,8 @@ static int omap_vout_allocate_vrfb_buffers(struct omap_vout_device *vout, *count = 0; return -ENOMEM; } - memset((void *) vout->smsshado_virt_addr[i], 0, - vout->smsshado_size); + memset((void *)(long)vout->smsshado_virt_addr[i], 0, + vout->smsshado_size); } return 0; } diff --git a/drivers/media/platform/omap3isp/isp.c b/drivers/media/platform/omap3isp/isp.c index 8eb000e3d8fd..f22cf351e3ee 100644 --- a/drivers/media/platform/omap3isp/isp.c +++ b/drivers/media/platform/omap3isp/isp.c @@ -61,7 +61,9 @@ #include <linux/sched.h> #include <linux/vmalloc.h> +#ifdef CONFIG_ARM_DMA_USE_IOMMU #include <asm/dma-iommu.h> +#endif #include <media/v4l2-common.h> #include <media/v4l2-fwnode.h> @@ -284,13 +286,6 @@ static const struct clk_ops isp_xclk_ops = { static const char *isp_xclk_parent_name = "cam_mclk"; -static const struct clk_init_data isp_xclk_init_data = { - .name = "cam_xclk", - .ops = &isp_xclk_ops, - .parent_names = &isp_xclk_parent_name, - .num_parents = 1, -}; - static struct clk *isp_xclk_src_get(struct of_phandle_args *clkspec, void *data) { unsigned int idx = clkspec->args[0]; @@ -1945,12 +1940,16 @@ error_csi2: static void isp_detach_iommu(struct isp_device *isp) { +#ifdef CONFIG_ARM_DMA_USE_IOMMU + arm_iommu_detach_device(isp->dev); arm_iommu_release_mapping(isp->mapping); isp->mapping = NULL; +#endif } static int isp_attach_iommu(struct isp_device *isp) { +#ifdef CONFIG_ARM_DMA_USE_IOMMU struct dma_iommu_mapping *mapping; int ret; @@ -1961,8 +1960,7 @@ static int isp_attach_iommu(struct isp_device *isp) mapping = arm_iommu_create_mapping(&platform_bus_type, SZ_1G, SZ_2G); if (IS_ERR(mapping)) { dev_err(isp->dev, "failed to create ARM IOMMU mapping\n"); - ret = PTR_ERR(mapping); - goto error; + return PTR_ERR(mapping); } isp->mapping = mapping; @@ -1977,8 +1975,12 @@ static int isp_attach_iommu(struct isp_device *isp) return 0; error: - isp_detach_iommu(isp); + arm_iommu_release_mapping(isp->mapping); + isp->mapping = NULL; return ret; +#else + return -ENODEV; +#endif } /* diff --git a/drivers/media/platform/omap3isp/ispccdc.c b/drivers/media/platform/omap3isp/ispccdc.c index b66276ab5765..77b73e27a274 100644 --- a/drivers/media/platform/omap3isp/ispccdc.c +++ b/drivers/media/platform/omap3isp/ispccdc.c @@ -735,7 +735,7 @@ static int ccdc_config(struct isp_ccdc_device *ccdc, return -ENOMEM; if (copy_from_user(fpc_new.addr, - (__force void __user *)fpc.fpcaddr, + (__force void __user *)(long)fpc.fpcaddr, size)) { dma_free_coherent(isp->dev, size, fpc_new.addr, fpc_new.dma); diff --git a/drivers/media/platform/omap3isp/isph3a_aewb.c b/drivers/media/platform/omap3isp/isph3a_aewb.c index d44626f20ac6..3c82dea4d375 100644 --- a/drivers/media/platform/omap3isp/isph3a_aewb.c +++ b/drivers/media/platform/omap3isp/isph3a_aewb.c @@ -250,6 +250,8 @@ static long h3a_aewb_ioctl(struct v4l2_subdev *sd, unsigned int cmd, void *arg) return omap3isp_stat_config(stat, arg); case VIDIOC_OMAP3ISP_STAT_REQ: return omap3isp_stat_request_statistics(stat, arg); + case VIDIOC_OMAP3ISP_STAT_REQ_TIME32: + return omap3isp_stat_request_statistics_time32(stat, arg); case VIDIOC_OMAP3ISP_STAT_EN: { unsigned long *en = arg; return omap3isp_stat_enable(stat, !!*en); diff --git a/drivers/media/platform/omap3isp/isph3a_af.c b/drivers/media/platform/omap3isp/isph3a_af.c index 99bd6cc21d86..4da25c84f0c6 100644 --- a/drivers/media/platform/omap3isp/isph3a_af.c +++ b/drivers/media/platform/omap3isp/isph3a_af.c @@ -314,6 +314,8 @@ static long h3a_af_ioctl(struct v4l2_subdev *sd, unsigned int cmd, void *arg) return omap3isp_stat_config(stat, arg); case VIDIOC_OMAP3ISP_STAT_REQ: return omap3isp_stat_request_statistics(stat, arg); + case VIDIOC_OMAP3ISP_STAT_REQ_TIME32: + return omap3isp_stat_request_statistics_time32(stat, arg); case VIDIOC_OMAP3ISP_STAT_EN: { int *en = arg; return omap3isp_stat_enable(stat, !!*en); diff --git a/drivers/media/platform/omap3isp/isphist.c b/drivers/media/platform/omap3isp/isphist.c index a4ed5d140d48..d4be3d0e06f9 100644 --- a/drivers/media/platform/omap3isp/isphist.c +++ b/drivers/media/platform/omap3isp/isphist.c @@ -435,6 +435,8 @@ static long hist_ioctl(struct v4l2_subdev *sd, unsigned int cmd, void *arg) return omap3isp_stat_config(stat, arg); case VIDIOC_OMAP3ISP_STAT_REQ: return omap3isp_stat_request_statistics(stat, arg); + case VIDIOC_OMAP3ISP_STAT_REQ_TIME32: + return omap3isp_stat_request_statistics_time32(stat, arg); case VIDIOC_OMAP3ISP_STAT_EN: { int *en = arg; return omap3isp_stat_enable(stat, !!*en); diff --git a/drivers/media/platform/omap3isp/isppreview.c b/drivers/media/platform/omap3isp/isppreview.c index ac30a0f83780..3195f7c8b8b7 100644 --- a/drivers/media/platform/omap3isp/isppreview.c +++ b/drivers/media/platform/omap3isp/isppreview.c @@ -25,7 +25,7 @@ #include "isppreview.h" /* Default values in Office Fluorescent Light for RGBtoRGB Blending */ -static struct omap3isp_prev_rgbtorgb flr_rgb2rgb = { +static const struct omap3isp_prev_rgbtorgb flr_rgb2rgb = { { /* RGB-RGB Matrix */ {0x01E2, 0x0F30, 0x0FEE}, {0x0F9B, 0x01AC, 0x0FB9}, @@ -35,7 +35,7 @@ static struct omap3isp_prev_rgbtorgb flr_rgb2rgb = { }; /* Default values in Office Fluorescent Light for RGB to YUV Conversion*/ -static struct omap3isp_prev_csc flr_prev_csc = { +static const struct omap3isp_prev_csc flr_prev_csc = { { /* CSC Coef Matrix */ {66, 129, 25}, {-38, -75, 112}, @@ -890,7 +890,7 @@ static int preview_config(struct isp_prev_device *prev, params = &prev->params.params[!!(active & bit)]; if (cfg->flag & bit) { - void __user *from = *(void * __user *) + void __user *from = *(void __user **) ((void *)cfg + attr->config_offset); void *to = (void *)params + attr->param_offset; size_t size = attr->param_size; diff --git a/drivers/media/platform/omap3isp/ispstat.c b/drivers/media/platform/omap3isp/ispstat.c index 47cbc7e3d825..47353fee26c3 100644 --- a/drivers/media/platform/omap3isp/ispstat.c +++ b/drivers/media/platform/omap3isp/ispstat.c @@ -17,6 +17,7 @@ #include <linux/dma-mapping.h> #include <linux/slab.h> +#include <linux/timekeeping.h> #include <linux/uaccess.h> #include "isp.h" @@ -237,7 +238,7 @@ static int isp_stat_buf_queue(struct ispstat *stat) if (!stat->active_buf) return STAT_NO_BUF; - v4l2_get_timestamp(&stat->active_buf->ts); + ktime_get_ts64(&stat->active_buf->ts); stat->active_buf->buf_size = stat->buf_size; if (isp_stat_buf_check_magic(stat, stat->active_buf)) { @@ -370,7 +371,7 @@ static int isp_stat_bufs_alloc_one(struct device *dev, int ret; buf->virt_addr = dma_alloc_coherent(dev, size, &buf->dma_addr, - GFP_KERNEL | GFP_DMA); + GFP_KERNEL); if (!buf->virt_addr) return -ENOMEM; @@ -449,10 +450,8 @@ static int isp_stat_bufs_alloc(struct ispstat *stat, u32 size) buf->empty = 1; dev_dbg(stat->isp->dev, - "%s: buffer[%u] allocated. dma=0x%08lx virt=0x%08lx", - stat->subdev.name, i, - (unsigned long)buf->dma_addr, - (unsigned long)buf->virt_addr); + "%s: buffer[%u] allocated. dma=%pad virt=%p", + stat->subdev.name, i, &buf->dma_addr, buf->virt_addr); } return 0; @@ -500,7 +499,8 @@ int omap3isp_stat_request_statistics(struct ispstat *stat, return PTR_ERR(buf); } - data->ts = buf->ts; + data->ts.tv_sec = buf->ts.tv_sec; + data->ts.tv_usec = buf->ts.tv_nsec / NSEC_PER_USEC; data->config_counter = buf->config_counter; data->frame_number = buf->frame_number; data->buf_size = buf->buf_size; @@ -512,6 +512,23 @@ int omap3isp_stat_request_statistics(struct ispstat *stat, return 0; } +int omap3isp_stat_request_statistics_time32(struct ispstat *stat, + struct omap3isp_stat_data_time32 *data) +{ + struct omap3isp_stat_data data64; + int ret; + + ret = omap3isp_stat_request_statistics(stat, &data64); + if (ret) + return ret; + + data->ts.tv_sec = data64.ts.tv_sec; + data->ts.tv_usec = data64.ts.tv_usec; + memcpy(&data->buf, &data64.buf, sizeof(*data) - sizeof(data->ts)); + + return 0; +} + /* * omap3isp_stat_config - Receives new statistic engine configuration. * @new_conf: Pointer to config structure. @@ -527,12 +544,6 @@ int omap3isp_stat_config(struct ispstat *stat, void *new_conf) struct ispstat_generic_config *user_cfg = new_conf; u32 buf_size = user_cfg->buf_size; - if (!new_conf) { - dev_dbg(stat->isp->dev, "%s: configuration is NULL\n", - stat->subdev.name); - return -EINVAL; - } - mutex_lock(&stat->ioctl_lock); dev_dbg(stat->isp->dev, diff --git a/drivers/media/platform/omap3isp/ispstat.h b/drivers/media/platform/omap3isp/ispstat.h index 6d9b0244f320..923b38cfc682 100644 --- a/drivers/media/platform/omap3isp/ispstat.h +++ b/drivers/media/platform/omap3isp/ispstat.h @@ -39,7 +39,7 @@ struct ispstat_buffer { struct sg_table sgt; void *virt_addr; dma_addr_t dma_addr; - struct timeval ts; + struct timespec64 ts; u32 buf_size; u32 frame_number; u16 config_counter; @@ -130,6 +130,8 @@ struct ispstat_generic_config { int omap3isp_stat_config(struct ispstat *stat, void *new_conf); int omap3isp_stat_request_statistics(struct ispstat *stat, struct omap3isp_stat_data *data); +int omap3isp_stat_request_statistics_time32(struct ispstat *stat, + struct omap3isp_stat_data_time32 *data); int omap3isp_stat_init(struct ispstat *stat, const char *name, const struct v4l2_subdev_ops *sd_ops); void omap3isp_stat_cleanup(struct ispstat *stat); diff --git a/drivers/media/platform/omap3isp/ispvideo.c b/drivers/media/platform/omap3isp/ispvideo.c index a751c89a3ea8..9d228eac24ea 100644 --- a/drivers/media/platform/omap3isp/ispvideo.c +++ b/drivers/media/platform/omap3isp/ispvideo.c @@ -1403,7 +1403,7 @@ static int isp_video_mmap(struct file *file, struct vm_area_struct *vma) return vb2_mmap(&vfh->queue, vma); } -static struct v4l2_file_operations isp_video_fops = { +static const struct v4l2_file_operations isp_video_fops = { .owner = THIS_MODULE, .unlocked_ioctl = video_ioctl2, .open = isp_video_open, diff --git a/drivers/media/platform/rcar-vin/Kconfig b/drivers/media/platform/rcar-vin/Kconfig index af4c98b44d2e..8fa7ee468c63 100644 --- a/drivers/media/platform/rcar-vin/Kconfig +++ b/drivers/media/platform/rcar-vin/Kconfig @@ -6,7 +6,7 @@ config VIDEO_RCAR_VIN select V4L2_FWNODE ---help--- Support for Renesas R-Car Video Input (VIN) driver. - Supports R-Car Gen2 SoCs. + Supports R-Car Gen2 and Gen3 SoCs. To compile this driver as a module, choose M here: the module will be called rcar-vin. diff --git a/drivers/media/platform/rcar-vin/rcar-core.c b/drivers/media/platform/rcar-vin/rcar-core.c index f1fc7978d6d1..d3072e166a1c 100644 --- a/drivers/media/platform/rcar-vin/rcar-core.c +++ b/drivers/media/platform/rcar-vin/rcar-core.c @@ -20,12 +20,341 @@ #include <linux/of_graph.h> #include <linux/platform_device.h> #include <linux/pm_runtime.h> +#include <linux/slab.h> +#include <linux/sys_soc.h> #include <media/v4l2-async.h> #include <media/v4l2-fwnode.h> +#include <media/v4l2-mc.h> #include "rcar-vin.h" +/* + * The companion CSI-2 receiver driver (rcar-csi2) is known + * and we know it has one source pad (pad 0) and four sink + * pads (pad 1-4). So to translate a pad on the remote + * CSI-2 receiver to/from the VIN internal channel number simply + * subtract/add one from the pad/channel number. + */ +#define rvin_group_csi_pad_to_channel(pad) ((pad) - 1) +#define rvin_group_csi_channel_to_pad(channel) ((channel) + 1) + +/* + * Not all VINs are created equal, master VINs control the + * routing for other VIN's. We can figure out which VIN is + * master by looking at a VINs id. + */ +#define rvin_group_id_to_master(vin) ((vin) < 4 ? 0 : 4) + +/* ----------------------------------------------------------------------------- + * Media Controller link notification + */ + +/* group lock should be held when calling this function. */ +static int rvin_group_entity_to_csi_id(struct rvin_group *group, + struct media_entity *entity) +{ + struct v4l2_subdev *sd; + unsigned int i; + + sd = media_entity_to_v4l2_subdev(entity); + + for (i = 0; i < RVIN_CSI_MAX; i++) + if (group->csi[i].subdev == sd) + return i; + + return -ENODEV; +} + +static unsigned int rvin_group_get_mask(struct rvin_dev *vin, + enum rvin_csi_id csi_id, + unsigned char channel) +{ + const struct rvin_group_route *route; + unsigned int mask = 0; + + for (route = vin->info->routes; route->mask; route++) { + if (route->vin == vin->id && + route->csi == csi_id && + route->channel == channel) { + vin_dbg(vin, + "Adding route: vin: %d csi: %d channel: %d\n", + route->vin, route->csi, route->channel); + mask |= route->mask; + } + } + + return mask; +} + +/* + * Link setup for the links between a VIN and a CSI-2 receiver is a bit + * complex. The reason for this is that the register controlling routing + * is not present in each VIN instance. There are special VINs which + * control routing for themselves and other VINs. There are not many + * different possible links combinations that can be enabled at the same + * time, therefor all already enabled links which are controlled by a + * master VIN need to be taken into account when making the decision + * if a new link can be enabled or not. + * + * 1. Find out which VIN the link the user tries to enable is connected to. + * 2. Lookup which master VIN controls the links for this VIN. + * 3. Start with a bitmask with all bits set. + * 4. For each previously enabled link from the master VIN bitwise AND its + * route mask (see documentation for mask in struct rvin_group_route) + * with the bitmask. + * 5. Bitwise AND the mask for the link the user tries to enable to the bitmask. + * 6. If the bitmask is not empty at this point the new link can be enabled + * while keeping all previous links enabled. Update the CHSEL value of the + * master VIN and inform the user that the link could be enabled. + * + * Please note that no link can be enabled if any VIN in the group is + * currently open. + */ +static int rvin_group_link_notify(struct media_link *link, u32 flags, + unsigned int notification) +{ + struct rvin_group *group = container_of(link->graph_obj.mdev, + struct rvin_group, mdev); + unsigned int master_id, channel, mask_new, i; + unsigned int mask = ~0; + struct media_entity *entity; + struct video_device *vdev; + struct media_pad *csi_pad; + struct rvin_dev *vin = NULL; + int csi_id, ret; + + ret = v4l2_pipeline_link_notify(link, flags, notification); + if (ret) + return ret; + + /* Only care about link enablement for VIN nodes. */ + if (!(flags & MEDIA_LNK_FL_ENABLED) || + !is_media_entity_v4l2_video_device(link->sink->entity)) + return 0; + + /* If any entity is in use don't allow link changes. */ + media_device_for_each_entity(entity, &group->mdev) + if (entity->use_count) + return -EBUSY; + + mutex_lock(&group->lock); + + /* Find the master VIN that controls the routes. */ + vdev = media_entity_to_video_device(link->sink->entity); + vin = container_of(vdev, struct rvin_dev, vdev); + master_id = rvin_group_id_to_master(vin->id); + + if (WARN_ON(!group->vin[master_id])) { + ret = -ENODEV; + goto out; + } + + /* Build a mask for already enabled links. */ + for (i = master_id; i < master_id + 4; i++) { + if (!group->vin[i]) + continue; + + /* Get remote CSI-2, if any. */ + csi_pad = media_entity_remote_pad( + &group->vin[i]->vdev.entity.pads[0]); + if (!csi_pad) + continue; + + csi_id = rvin_group_entity_to_csi_id(group, csi_pad->entity); + channel = rvin_group_csi_pad_to_channel(csi_pad->index); + + mask &= rvin_group_get_mask(group->vin[i], csi_id, channel); + } + + /* Add the new link to the existing mask and check if it works. */ + csi_id = rvin_group_entity_to_csi_id(group, link->source->entity); + channel = rvin_group_csi_pad_to_channel(link->source->index); + mask_new = mask & rvin_group_get_mask(vin, csi_id, channel); + + vin_dbg(vin, "Try link change mask: 0x%x new: 0x%x\n", mask, mask_new); + + if (!mask_new) { + ret = -EMLINK; + goto out; + } + + /* New valid CHSEL found, set the new value. */ + ret = rvin_set_channel_routing(group->vin[master_id], __ffs(mask_new)); +out: + mutex_unlock(&group->lock); + + return ret; +} + +static const struct media_device_ops rvin_media_ops = { + .link_notify = rvin_group_link_notify, +}; + +/* ----------------------------------------------------------------------------- + * Gen3 CSI2 Group Allocator + */ + +/* FIXME: This should if we find a system that supports more + * than one group for the whole system be replaced with a linked + * list of groups. And eventually all of this should be replaced + * with a global device allocator API. + * + * But for now this works as on all supported systems there will + * be only one group for all instances. + */ + +static DEFINE_MUTEX(rvin_group_lock); +static struct rvin_group *rvin_group_data; + +static void rvin_group_cleanup(struct rvin_group *group) +{ + media_device_unregister(&group->mdev); + media_device_cleanup(&group->mdev); + mutex_destroy(&group->lock); +} + +static int rvin_group_init(struct rvin_group *group, struct rvin_dev *vin) +{ + struct media_device *mdev = &group->mdev; + const struct of_device_id *match; + struct device_node *np; + int ret; + + mutex_init(&group->lock); + + /* Count number of VINs in the system */ + group->count = 0; + for_each_matching_node(np, vin->dev->driver->of_match_table) + if (of_device_is_available(np)) + group->count++; + + vin_dbg(vin, "found %u enabled VIN's in DT", group->count); + + mdev->dev = vin->dev; + mdev->ops = &rvin_media_ops; + + match = of_match_node(vin->dev->driver->of_match_table, + vin->dev->of_node); + + strlcpy(mdev->driver_name, KBUILD_MODNAME, sizeof(mdev->driver_name)); + strlcpy(mdev->model, match->compatible, sizeof(mdev->model)); + snprintf(mdev->bus_info, sizeof(mdev->bus_info), "platform:%s", + dev_name(mdev->dev)); + + media_device_init(mdev); + + ret = media_device_register(&group->mdev); + if (ret) + rvin_group_cleanup(group); + + return ret; +} + +static void rvin_group_release(struct kref *kref) +{ + struct rvin_group *group = + container_of(kref, struct rvin_group, refcount); + + mutex_lock(&rvin_group_lock); + + rvin_group_data = NULL; + + rvin_group_cleanup(group); + + kfree(group); + + mutex_unlock(&rvin_group_lock); +} + +static int rvin_group_get(struct rvin_dev *vin) +{ + struct rvin_group *group; + u32 id; + int ret; + + /* Make sure VIN id is present and sane */ + ret = of_property_read_u32(vin->dev->of_node, "renesas,id", &id); + if (ret) { + vin_err(vin, "%pOF: No renesas,id property found\n", + vin->dev->of_node); + return -EINVAL; + } + + if (id >= RCAR_VIN_NUM) { + vin_err(vin, "%pOF: Invalid renesas,id '%u'\n", + vin->dev->of_node, id); + return -EINVAL; + } + + /* Join or create a VIN group */ + mutex_lock(&rvin_group_lock); + if (rvin_group_data) { + group = rvin_group_data; + kref_get(&group->refcount); + } else { + group = kzalloc(sizeof(*group), GFP_KERNEL); + if (!group) { + ret = -ENOMEM; + goto err_group; + } + + ret = rvin_group_init(group, vin); + if (ret) { + kfree(group); + vin_err(vin, "Failed to initialize group\n"); + goto err_group; + } + + kref_init(&group->refcount); + + rvin_group_data = group; + } + mutex_unlock(&rvin_group_lock); + + /* Add VIN to group */ + mutex_lock(&group->lock); + + if (group->vin[id]) { + vin_err(vin, "Duplicate renesas,id property value %u\n", id); + mutex_unlock(&group->lock); + kref_put(&group->refcount, rvin_group_release); + return -EINVAL; + } + + group->vin[id] = vin; + + vin->id = id; + vin->group = group; + vin->v4l2_dev.mdev = &group->mdev; + + mutex_unlock(&group->lock); + + return 0; +err_group: + mutex_unlock(&rvin_group_lock); + return ret; +} + +static void rvin_group_put(struct rvin_dev *vin) +{ + struct rvin_group *group = vin->group; + + mutex_lock(&group->lock); + + vin->group = NULL; + vin->v4l2_dev.mdev = NULL; + + if (WARN_ON(group->vin[vin->id] != vin)) + goto out; + + group->vin[vin->id] = NULL; +out: + mutex_unlock(&group->lock); + + kref_put(&group->refcount, rvin_group_release); +} + /* ----------------------------------------------------------------------------- * Async notifier */ @@ -46,30 +375,93 @@ static int rvin_find_pad(struct v4l2_subdev *sd, int direction) return -EINVAL; } -static bool rvin_mbus_supported(struct rvin_graph_entity *entity) +/* ----------------------------------------------------------------------------- + * Digital async notifier + */ + +/* The vin lock should be held when calling the subdevice attach and detach */ +static int rvin_digital_subdevice_attach(struct rvin_dev *vin, + struct v4l2_subdev *subdev) { - struct v4l2_subdev *sd = entity->subdev; struct v4l2_subdev_mbus_code_enum code = { .which = V4L2_SUBDEV_FORMAT_ACTIVE, }; + int ret; + /* Find source and sink pad of remote subdevice */ + ret = rvin_find_pad(subdev, MEDIA_PAD_FL_SOURCE); + if (ret < 0) + return ret; + vin->digital->source_pad = ret; + + ret = rvin_find_pad(subdev, MEDIA_PAD_FL_SINK); + vin->digital->sink_pad = ret < 0 ? 0 : ret; + + /* Find compatible subdevices mbus format */ + vin->mbus_code = 0; code.index = 0; - code.pad = entity->source_pad; - while (!v4l2_subdev_call(sd, pad, enum_mbus_code, NULL, &code)) { + code.pad = vin->digital->source_pad; + while (!vin->mbus_code && + !v4l2_subdev_call(subdev, pad, enum_mbus_code, NULL, &code)) { code.index++; switch (code.code) { case MEDIA_BUS_FMT_YUYV8_1X16: + case MEDIA_BUS_FMT_UYVY8_1X16: case MEDIA_BUS_FMT_UYVY8_2X8: case MEDIA_BUS_FMT_UYVY10_2X10: case MEDIA_BUS_FMT_RGB888_1X24: - entity->code = code.code; - return true; + vin->mbus_code = code.code; + vin_dbg(vin, "Found media bus format for %s: %d\n", + subdev->name, vin->mbus_code); + break; default: break; } } - return false; + if (!vin->mbus_code) { + vin_err(vin, "Unsupported media bus format for %s\n", + subdev->name); + return -EINVAL; + } + + /* Read tvnorms */ + ret = v4l2_subdev_call(subdev, video, g_tvnorms, &vin->vdev.tvnorms); + if (ret < 0 && ret != -ENOIOCTLCMD && ret != -ENODEV) + return ret; + + /* Read standard */ + vin->std = V4L2_STD_UNKNOWN; + ret = v4l2_subdev_call(subdev, video, g_std, &vin->std); + if (ret < 0 && ret != -ENOIOCTLCMD) + return ret; + + /* Add the controls */ + ret = v4l2_ctrl_handler_init(&vin->ctrl_handler, 16); + if (ret < 0) + return ret; + + ret = v4l2_ctrl_add_handler(&vin->ctrl_handler, subdev->ctrl_handler, + NULL); + if (ret < 0) { + v4l2_ctrl_handler_free(&vin->ctrl_handler); + return ret; + } + + vin->vdev.ctrl_handler = &vin->ctrl_handler; + + vin->digital->subdev = subdev; + + return 0; +} + +static void rvin_digital_subdevice_detach(struct rvin_dev *vin) +{ + rvin_v4l2_unregister(vin); + v4l2_ctrl_handler_free(&vin->ctrl_handler); + + vin->vdev.ctrl_handler = NULL; + vin->digital->subdev = NULL; } static int rvin_digital_notify_complete(struct v4l2_async_notifier *notifier) @@ -77,23 +469,13 @@ static int rvin_digital_notify_complete(struct v4l2_async_notifier *notifier) struct rvin_dev *vin = notifier_to_vin(notifier); int ret; - /* Verify subdevices mbus format */ - if (!rvin_mbus_supported(vin->digital)) { - vin_err(vin, "Unsupported media bus format for %s\n", - vin->digital->subdev->name); - return -EINVAL; - } - - vin_dbg(vin, "Found media bus format for %s: %d\n", - vin->digital->subdev->name, vin->digital->code); - ret = v4l2_device_register_subdev_nodes(&vin->v4l2_dev); if (ret < 0) { vin_err(vin, "Failed to register subdev nodes\n"); return ret; } - return rvin_v4l2_probe(vin); + return rvin_v4l2_register(vin); } static void rvin_digital_notify_unbind(struct v4l2_async_notifier *notifier, @@ -103,8 +485,10 @@ static void rvin_digital_notify_unbind(struct v4l2_async_notifier *notifier, struct rvin_dev *vin = notifier_to_vin(notifier); vin_dbg(vin, "unbind digital subdev %s\n", subdev->name); - rvin_v4l2_remove(vin); - vin->digital->subdev = NULL; + + mutex_lock(&vin->lock); + rvin_digital_subdevice_detach(vin); + mutex_unlock(&vin->lock); } static int rvin_digital_notify_bound(struct v4l2_async_notifier *notifier, @@ -114,19 +498,13 @@ static int rvin_digital_notify_bound(struct v4l2_async_notifier *notifier, struct rvin_dev *vin = notifier_to_vin(notifier); int ret; - v4l2_set_subdev_hostdata(subdev, vin); - - /* Find source and sink pad of remote subdevice */ - - ret = rvin_find_pad(subdev, MEDIA_PAD_FL_SOURCE); - if (ret < 0) + mutex_lock(&vin->lock); + ret = rvin_digital_subdevice_attach(vin, subdev); + mutex_unlock(&vin->lock); + if (ret) return ret; - vin->digital->source_pad = ret; - ret = rvin_find_pad(subdev, MEDIA_PAD_FL_SINK); - vin->digital->sink_pad = ret < 0 ? 0 : ret; - - vin->digital->subdev = subdev; + v4l2_set_subdev_hostdata(subdev, vin); vin_dbg(vin, "bound subdev %s source pad: %u sink pad: %u\n", subdev->name, vin->digital->source_pad, @@ -134,13 +512,13 @@ static int rvin_digital_notify_bound(struct v4l2_async_notifier *notifier, return 0; } + static const struct v4l2_async_notifier_operations rvin_digital_notify_ops = { .bound = rvin_digital_notify_bound, .unbind = rvin_digital_notify_unbind, .complete = rvin_digital_notify_complete, }; - static int rvin_digital_parse_v4l2(struct device *dev, struct v4l2_fwnode_endpoint *vep, struct v4l2_async_subdev *asd) @@ -152,16 +530,16 @@ static int rvin_digital_parse_v4l2(struct device *dev, if (vep->base.port || vep->base.id) return -ENOTCONN; - rvge->mbus_cfg.type = vep->bus_type; + vin->mbus_cfg.type = vep->bus_type; - switch (rvge->mbus_cfg.type) { + switch (vin->mbus_cfg.type) { case V4L2_MBUS_PARALLEL: vin_dbg(vin, "Found PARALLEL media bus\n"); - rvge->mbus_cfg.flags = vep->bus.parallel.flags; + vin->mbus_cfg.flags = vep->bus.parallel.flags; break; case V4L2_MBUS_BT656: vin_dbg(vin, "Found BT656 media bus\n"); - rvge->mbus_cfg.flags = 0; + vin->mbus_cfg.flags = 0; break; default: vin_err(vin, "Unknown media bus type\n"); @@ -200,24 +578,477 @@ static int rvin_digital_graph_init(struct rvin_dev *vin) } /* ----------------------------------------------------------------------------- + * Group async notifier + */ + +static int rvin_group_notify_complete(struct v4l2_async_notifier *notifier) +{ + struct rvin_dev *vin = notifier_to_vin(notifier); + const struct rvin_group_route *route; + unsigned int i; + int ret; + + ret = v4l2_device_register_subdev_nodes(&vin->v4l2_dev); + if (ret) { + vin_err(vin, "Failed to register subdev nodes\n"); + return ret; + } + + /* Register all video nodes for the group. */ + for (i = 0; i < RCAR_VIN_NUM; i++) { + if (vin->group->vin[i]) { + ret = rvin_v4l2_register(vin->group->vin[i]); + if (ret) + return ret; + } + } + + /* Create all media device links between VINs and CSI-2's. */ + mutex_lock(&vin->group->lock); + for (route = vin->info->routes; route->mask; route++) { + struct media_pad *source_pad, *sink_pad; + struct media_entity *source, *sink; + unsigned int source_idx; + + /* Check that VIN is part of the group. */ + if (!vin->group->vin[route->vin]) + continue; + + /* Check that VIN' master is part of the group. */ + if (!vin->group->vin[rvin_group_id_to_master(route->vin)]) + continue; + + /* Check that CSI-2 is part of the group. */ + if (!vin->group->csi[route->csi].subdev) + continue; + + source = &vin->group->csi[route->csi].subdev->entity; + source_idx = rvin_group_csi_channel_to_pad(route->channel); + source_pad = &source->pads[source_idx]; + + sink = &vin->group->vin[route->vin]->vdev.entity; + sink_pad = &sink->pads[0]; + + /* Skip if link already exists. */ + if (media_entity_find_link(source_pad, sink_pad)) + continue; + + ret = media_create_pad_link(source, source_idx, sink, 0, 0); + if (ret) { + vin_err(vin, "Error adding link from %s to %s\n", + source->name, sink->name); + break; + } + } + mutex_unlock(&vin->group->lock); + + return ret; +} + +static void rvin_group_notify_unbind(struct v4l2_async_notifier *notifier, + struct v4l2_subdev *subdev, + struct v4l2_async_subdev *asd) +{ + struct rvin_dev *vin = notifier_to_vin(notifier); + unsigned int i; + + for (i = 0; i < RCAR_VIN_NUM; i++) + if (vin->group->vin[i]) + rvin_v4l2_unregister(vin->group->vin[i]); + + mutex_lock(&vin->group->lock); + + for (i = 0; i < RVIN_CSI_MAX; i++) { + if (vin->group->csi[i].fwnode != asd->match.fwnode) + continue; + vin->group->csi[i].subdev = NULL; + vin_dbg(vin, "Unbind CSI-2 %s from slot %u\n", subdev->name, i); + break; + } + + mutex_unlock(&vin->group->lock); +} + +static int rvin_group_notify_bound(struct v4l2_async_notifier *notifier, + struct v4l2_subdev *subdev, + struct v4l2_async_subdev *asd) +{ + struct rvin_dev *vin = notifier_to_vin(notifier); + unsigned int i; + + mutex_lock(&vin->group->lock); + + for (i = 0; i < RVIN_CSI_MAX; i++) { + if (vin->group->csi[i].fwnode != asd->match.fwnode) + continue; + vin->group->csi[i].subdev = subdev; + vin_dbg(vin, "Bound CSI-2 %s to slot %u\n", subdev->name, i); + break; + } + + mutex_unlock(&vin->group->lock); + + return 0; +} + +static const struct v4l2_async_notifier_operations rvin_group_notify_ops = { + .bound = rvin_group_notify_bound, + .unbind = rvin_group_notify_unbind, + .complete = rvin_group_notify_complete, +}; + +static int rvin_mc_parse_of_endpoint(struct device *dev, + struct v4l2_fwnode_endpoint *vep, + struct v4l2_async_subdev *asd) +{ + struct rvin_dev *vin = dev_get_drvdata(dev); + + if (vep->base.port != 1 || vep->base.id >= RVIN_CSI_MAX) + return -EINVAL; + + if (!of_device_is_available(to_of_node(asd->match.fwnode))) { + + vin_dbg(vin, "OF device %pOF disabled, ignoring\n", + to_of_node(asd->match.fwnode)); + return -ENOTCONN; + + } + + if (vin->group->csi[vep->base.id].fwnode) { + vin_dbg(vin, "OF device %pOF already handled\n", + to_of_node(asd->match.fwnode)); + return -ENOTCONN; + } + + vin->group->csi[vep->base.id].fwnode = asd->match.fwnode; + + vin_dbg(vin, "Add group OF device %pOF to slot %u\n", + to_of_node(asd->match.fwnode), vep->base.id); + + return 0; +} + +static int rvin_mc_parse_of_graph(struct rvin_dev *vin) +{ + unsigned int count = 0; + unsigned int i; + int ret; + + mutex_lock(&vin->group->lock); + + /* If there already is a notifier something has gone wrong, bail out. */ + if (WARN_ON(vin->group->notifier)) { + mutex_unlock(&vin->group->lock); + return -EINVAL; + } + + /* If not all VIN's are registered don't register the notifier. */ + for (i = 0; i < RCAR_VIN_NUM; i++) + if (vin->group->vin[i]) + count++; + + if (vin->group->count != count) { + mutex_unlock(&vin->group->lock); + return 0; + } + + /* + * Have all VIN's look for subdevices. Some subdevices will overlap + * but the parser function can handle it, so each subdevice will + * only be registered once with the notifier. + */ + + vin->group->notifier = &vin->notifier; + + for (i = 0; i < RCAR_VIN_NUM; i++) { + if (!vin->group->vin[i]) + continue; + + ret = v4l2_async_notifier_parse_fwnode_endpoints_by_port( + vin->group->vin[i]->dev, vin->group->notifier, + sizeof(struct v4l2_async_subdev), 1, + rvin_mc_parse_of_endpoint); + if (ret) { + mutex_unlock(&vin->group->lock); + return ret; + } + } + + mutex_unlock(&vin->group->lock); + + vin->group->notifier->ops = &rvin_group_notify_ops; + + ret = v4l2_async_notifier_register(&vin->v4l2_dev, &vin->notifier); + if (ret < 0) { + vin_err(vin, "Notifier registration failed\n"); + return ret; + } + + return 0; +} + +static int rvin_mc_init(struct rvin_dev *vin) +{ + int ret; + + /* All our sources are CSI-2 */ + vin->mbus_cfg.type = V4L2_MBUS_CSI2; + vin->mbus_cfg.flags = 0; + + vin->pad.flags = MEDIA_PAD_FL_SINK; + ret = media_entity_pads_init(&vin->vdev.entity, 1, &vin->pad); + if (ret) + return ret; + + ret = rvin_group_get(vin); + if (ret) + return ret; + + ret = rvin_mc_parse_of_graph(vin); + if (ret) + rvin_group_put(vin); + + return ret; +} + +/* ----------------------------------------------------------------------------- * Platform Device Driver */ +static const struct rvin_info rcar_info_h1 = { + .model = RCAR_H1, + .use_mc = false, + .max_width = 2048, + .max_height = 2048, +}; + +static const struct rvin_info rcar_info_m1 = { + .model = RCAR_M1, + .use_mc = false, + .max_width = 2048, + .max_height = 2048, +}; + +static const struct rvin_info rcar_info_gen2 = { + .model = RCAR_GEN2, + .use_mc = false, + .max_width = 2048, + .max_height = 2048, +}; + +static const struct rvin_group_route rcar_info_r8a7795_routes[] = { + { .csi = RVIN_CSI40, .channel = 0, .vin = 0, .mask = BIT(0) | BIT(3) }, + { .csi = RVIN_CSI20, .channel = 0, .vin = 0, .mask = BIT(1) | BIT(4) }, + { .csi = RVIN_CSI40, .channel = 1, .vin = 0, .mask = BIT(2) }, + { .csi = RVIN_CSI20, .channel = 0, .vin = 1, .mask = BIT(0) }, + { .csi = RVIN_CSI40, .channel = 1, .vin = 1, .mask = BIT(1) | BIT(3) }, + { .csi = RVIN_CSI40, .channel = 0, .vin = 1, .mask = BIT(2) }, + { .csi = RVIN_CSI20, .channel = 1, .vin = 1, .mask = BIT(4) }, + { .csi = RVIN_CSI20, .channel = 1, .vin = 2, .mask = BIT(0) }, + { .csi = RVIN_CSI40, .channel = 0, .vin = 2, .mask = BIT(1) }, + { .csi = RVIN_CSI20, .channel = 0, .vin = 2, .mask = BIT(2) }, + { .csi = RVIN_CSI40, .channel = 2, .vin = 2, .mask = BIT(3) }, + { .csi = RVIN_CSI20, .channel = 2, .vin = 2, .mask = BIT(4) }, + { .csi = RVIN_CSI40, .channel = 1, .vin = 3, .mask = BIT(0) }, + { .csi = RVIN_CSI20, .channel = 1, .vin = 3, .mask = BIT(1) | BIT(2) }, + { .csi = RVIN_CSI40, .channel = 3, .vin = 3, .mask = BIT(3) }, + { .csi = RVIN_CSI20, .channel = 3, .vin = 3, .mask = BIT(4) }, + { .csi = RVIN_CSI41, .channel = 0, .vin = 4, .mask = BIT(0) | BIT(3) }, + { .csi = RVIN_CSI20, .channel = 0, .vin = 4, .mask = BIT(1) | BIT(4) }, + { .csi = RVIN_CSI41, .channel = 1, .vin = 4, .mask = BIT(2) }, + { .csi = RVIN_CSI20, .channel = 0, .vin = 5, .mask = BIT(0) }, + { .csi = RVIN_CSI41, .channel = 1, .vin = 5, .mask = BIT(1) | BIT(3) }, + { .csi = RVIN_CSI41, .channel = 0, .vin = 5, .mask = BIT(2) }, + { .csi = RVIN_CSI20, .channel = 1, .vin = 5, .mask = BIT(4) }, + { .csi = RVIN_CSI20, .channel = 1, .vin = 6, .mask = BIT(0) }, + { .csi = RVIN_CSI41, .channel = 0, .vin = 6, .mask = BIT(1) }, + { .csi = RVIN_CSI20, .channel = 0, .vin = 6, .mask = BIT(2) }, + { .csi = RVIN_CSI41, .channel = 2, .vin = 6, .mask = BIT(3) }, + { .csi = RVIN_CSI20, .channel = 2, .vin = 6, .mask = BIT(4) }, + { .csi = RVIN_CSI41, .channel = 1, .vin = 7, .mask = BIT(0) }, + { .csi = RVIN_CSI20, .channel = 1, .vin = 7, .mask = BIT(1) | BIT(2) }, + { .csi = RVIN_CSI41, .channel = 3, .vin = 7, .mask = BIT(3) }, + { .csi = RVIN_CSI20, .channel = 3, .vin = 7, .mask = BIT(4) }, + { /* Sentinel */ } +}; + +static const struct rvin_info rcar_info_r8a7795 = { + .model = RCAR_GEN3, + .use_mc = true, + .max_width = 4096, + .max_height = 4096, + .routes = rcar_info_r8a7795_routes, +}; + +static const struct rvin_group_route rcar_info_r8a7795es1_routes[] = { + { .csi = RVIN_CSI40, .channel = 0, .vin = 0, .mask = BIT(0) | BIT(3) }, + { .csi = RVIN_CSI20, .channel = 0, .vin = 0, .mask = BIT(1) | BIT(4) }, + { .csi = RVIN_CSI21, .channel = 0, .vin = 0, .mask = BIT(2) | BIT(5) }, + { .csi = RVIN_CSI20, .channel = 0, .vin = 1, .mask = BIT(0) }, + { .csi = RVIN_CSI21, .channel = 0, .vin = 1, .mask = BIT(1) }, + { .csi = RVIN_CSI40, .channel = 0, .vin = 1, .mask = BIT(2) }, + { .csi = RVIN_CSI40, .channel = 1, .vin = 1, .mask = BIT(3) }, + { .csi = RVIN_CSI20, .channel = 1, .vin = 1, .mask = BIT(4) }, + { .csi = RVIN_CSI21, .channel = 1, .vin = 1, .mask = BIT(5) }, + { .csi = RVIN_CSI21, .channel = 0, .vin = 2, .mask = BIT(0) }, + { .csi = RVIN_CSI40, .channel = 0, .vin = 2, .mask = BIT(1) }, + { .csi = RVIN_CSI20, .channel = 0, .vin = 2, .mask = BIT(2) }, + { .csi = RVIN_CSI40, .channel = 2, .vin = 2, .mask = BIT(3) }, + { .csi = RVIN_CSI20, .channel = 2, .vin = 2, .mask = BIT(4) }, + { .csi = RVIN_CSI21, .channel = 2, .vin = 2, .mask = BIT(5) }, + { .csi = RVIN_CSI40, .channel = 1, .vin = 3, .mask = BIT(0) }, + { .csi = RVIN_CSI20, .channel = 1, .vin = 3, .mask = BIT(1) }, + { .csi = RVIN_CSI21, .channel = 1, .vin = 3, .mask = BIT(2) }, + { .csi = RVIN_CSI40, .channel = 3, .vin = 3, .mask = BIT(3) }, + { .csi = RVIN_CSI20, .channel = 3, .vin = 3, .mask = BIT(4) }, + { .csi = RVIN_CSI21, .channel = 3, .vin = 3, .mask = BIT(5) }, + { .csi = RVIN_CSI41, .channel = 0, .vin = 4, .mask = BIT(0) | BIT(3) }, + { .csi = RVIN_CSI20, .channel = 0, .vin = 4, .mask = BIT(1) | BIT(4) }, + { .csi = RVIN_CSI21, .channel = 0, .vin = 4, .mask = BIT(2) | BIT(5) }, + { .csi = RVIN_CSI20, .channel = 0, .vin = 5, .mask = BIT(0) }, + { .csi = RVIN_CSI21, .channel = 0, .vin = 5, .mask = BIT(1) }, + { .csi = RVIN_CSI41, .channel = 0, .vin = 5, .mask = BIT(2) }, + { .csi = RVIN_CSI41, .channel = 1, .vin = 5, .mask = BIT(3) }, + { .csi = RVIN_CSI20, .channel = 1, .vin = 5, .mask = BIT(4) }, + { .csi = RVIN_CSI21, .channel = 1, .vin = 5, .mask = BIT(5) }, + { .csi = RVIN_CSI21, .channel = 0, .vin = 6, .mask = BIT(0) }, + { .csi = RVIN_CSI41, .channel = 0, .vin = 6, .mask = BIT(1) }, + { .csi = RVIN_CSI20, .channel = 0, .vin = 6, .mask = BIT(2) }, + { .csi = RVIN_CSI41, .channel = 2, .vin = 6, .mask = BIT(3) }, + { .csi = RVIN_CSI20, .channel = 2, .vin = 6, .mask = BIT(4) }, + { .csi = RVIN_CSI21, .channel = 2, .vin = 6, .mask = BIT(5) }, + { .csi = RVIN_CSI41, .channel = 1, .vin = 7, .mask = BIT(0) }, + { .csi = RVIN_CSI20, .channel = 1, .vin = 7, .mask = BIT(1) }, + { .csi = RVIN_CSI21, .channel = 1, .vin = 7, .mask = BIT(2) }, + { .csi = RVIN_CSI41, .channel = 3, .vin = 7, .mask = BIT(3) }, + { .csi = RVIN_CSI20, .channel = 3, .vin = 7, .mask = BIT(4) }, + { .csi = RVIN_CSI21, .channel = 3, .vin = 7, .mask = BIT(5) }, + { /* Sentinel */ } +}; + +static const struct rvin_info rcar_info_r8a7795es1 = { + .model = RCAR_GEN3, + .use_mc = true, + .max_width = 4096, + .max_height = 4096, + .routes = rcar_info_r8a7795es1_routes, +}; + +static const struct rvin_group_route rcar_info_r8a7796_routes[] = { + { .csi = RVIN_CSI40, .channel = 0, .vin = 0, .mask = BIT(0) | BIT(3) }, + { .csi = RVIN_CSI20, .channel = 0, .vin = 0, .mask = BIT(1) | BIT(4) }, + { .csi = RVIN_CSI20, .channel = 0, .vin = 1, .mask = BIT(0) }, + { .csi = RVIN_CSI40, .channel = 0, .vin = 1, .mask = BIT(2) }, + { .csi = RVIN_CSI40, .channel = 1, .vin = 1, .mask = BIT(3) }, + { .csi = RVIN_CSI20, .channel = 1, .vin = 1, .mask = BIT(4) }, + { .csi = RVIN_CSI40, .channel = 0, .vin = 2, .mask = BIT(1) }, + { .csi = RVIN_CSI20, .channel = 0, .vin = 2, .mask = BIT(2) }, + { .csi = RVIN_CSI40, .channel = 2, .vin = 2, .mask = BIT(3) }, + { .csi = RVIN_CSI20, .channel = 2, .vin = 2, .mask = BIT(4) }, + { .csi = RVIN_CSI40, .channel = 1, .vin = 3, .mask = BIT(0) }, + { .csi = RVIN_CSI20, .channel = 1, .vin = 3, .mask = BIT(1) }, + { .csi = RVIN_CSI40, .channel = 3, .vin = 3, .mask = BIT(3) }, + { .csi = RVIN_CSI20, .channel = 3, .vin = 3, .mask = BIT(4) }, + { .csi = RVIN_CSI40, .channel = 0, .vin = 4, .mask = BIT(0) | BIT(3) }, + { .csi = RVIN_CSI20, .channel = 0, .vin = 4, .mask = BIT(1) | BIT(4) }, + { .csi = RVIN_CSI20, .channel = 0, .vin = 5, .mask = BIT(0) }, + { .csi = RVIN_CSI40, .channel = 0, .vin = 5, .mask = BIT(2) }, + { .csi = RVIN_CSI40, .channel = 1, .vin = 5, .mask = BIT(3) }, + { .csi = RVIN_CSI20, .channel = 1, .vin = 5, .mask = BIT(4) }, + { .csi = RVIN_CSI40, .channel = 0, .vin = 6, .mask = BIT(1) }, + { .csi = RVIN_CSI20, .channel = 0, .vin = 6, .mask = BIT(2) }, + { .csi = RVIN_CSI40, .channel = 2, .vin = 6, .mask = BIT(3) }, + { .csi = RVIN_CSI20, .channel = 2, .vin = 6, .mask = BIT(4) }, + { .csi = RVIN_CSI40, .channel = 1, .vin = 7, .mask = BIT(0) }, + { .csi = RVIN_CSI20, .channel = 1, .vin = 7, .mask = BIT(1) }, + { .csi = RVIN_CSI40, .channel = 3, .vin = 7, .mask = BIT(3) }, + { .csi = RVIN_CSI20, .channel = 3, .vin = 7, .mask = BIT(4) }, + { /* Sentinel */ } +}; + +static const struct rvin_info rcar_info_r8a7796 = { + .model = RCAR_GEN3, + .use_mc = true, + .max_width = 4096, + .max_height = 4096, + .routes = rcar_info_r8a7796_routes, +}; + +static const struct rvin_group_route _rcar_info_r8a77970_routes[] = { + { .csi = RVIN_CSI40, .channel = 0, .vin = 0, .mask = BIT(0) | BIT(3) }, + { .csi = RVIN_CSI40, .channel = 0, .vin = 1, .mask = BIT(2) }, + { .csi = RVIN_CSI40, .channel = 1, .vin = 1, .mask = BIT(3) }, + { .csi = RVIN_CSI40, .channel = 0, .vin = 2, .mask = BIT(1) }, + { .csi = RVIN_CSI40, .channel = 2, .vin = 2, .mask = BIT(3) }, + { .csi = RVIN_CSI40, .channel = 1, .vin = 3, .mask = BIT(0) }, + { .csi = RVIN_CSI40, .channel = 3, .vin = 3, .mask = BIT(3) }, + { /* Sentinel */ } +}; + +static const struct rvin_info rcar_info_r8a77970 = { + .model = RCAR_GEN3, + .use_mc = true, + .max_width = 4096, + .max_height = 4096, + .routes = _rcar_info_r8a77970_routes, +}; + static const struct of_device_id rvin_of_id_table[] = { - { .compatible = "renesas,vin-r8a7794", .data = (void *)RCAR_GEN2 }, - { .compatible = "renesas,vin-r8a7793", .data = (void *)RCAR_GEN2 }, - { .compatible = "renesas,vin-r8a7791", .data = (void *)RCAR_GEN2 }, - { .compatible = "renesas,vin-r8a7790", .data = (void *)RCAR_GEN2 }, - { .compatible = "renesas,vin-r8a7779", .data = (void *)RCAR_H1 }, - { .compatible = "renesas,vin-r8a7778", .data = (void *)RCAR_M1 }, - { .compatible = "renesas,rcar-gen2-vin", .data = (void *)RCAR_GEN2 }, - { }, + { + .compatible = "renesas,vin-r8a7778", + .data = &rcar_info_m1, + }, + { + .compatible = "renesas,vin-r8a7779", + .data = &rcar_info_h1, + }, + { + .compatible = "renesas,vin-r8a7790", + .data = &rcar_info_gen2, + }, + { + .compatible = "renesas,vin-r8a7791", + .data = &rcar_info_gen2, + }, + { + .compatible = "renesas,vin-r8a7793", + .data = &rcar_info_gen2, + }, + { + .compatible = "renesas,vin-r8a7794", + .data = &rcar_info_gen2, + }, + { + .compatible = "renesas,rcar-gen2-vin", + .data = &rcar_info_gen2, + }, + { + .compatible = "renesas,vin-r8a7795", + .data = &rcar_info_r8a7795, + }, + { + .compatible = "renesas,vin-r8a7796", + .data = &rcar_info_r8a7796, + }, + { + .compatible = "renesas,vin-r8a77970", + .data = &rcar_info_r8a77970, + }, + { /* Sentinel */ }, }; MODULE_DEVICE_TABLE(of, rvin_of_id_table); +static const struct soc_device_attribute r8a7795es1[] = { + { + .soc_id = "r8a7795", .revision = "ES1.*", + .data = &rcar_info_r8a7795es1, + }, + { /* Sentinel */ } +}; + static int rcar_vin_probe(struct platform_device *pdev) { - const struct of_device_id *match; + const struct soc_device_attribute *attr; struct rvin_dev *vin; struct resource *mem; int irq, ret; @@ -226,12 +1057,16 @@ static int rcar_vin_probe(struct platform_device *pdev) if (!vin) return -ENOMEM; - match = of_match_device(of_match_ptr(rvin_of_id_table), &pdev->dev); - if (!match) - return -ENODEV; - vin->dev = &pdev->dev; - vin->chip = (enum chip_id)match->data; + vin->info = of_device_get_match_data(&pdev->dev); + + /* + * Special care is needed on r8a7795 ES1.x since it + * uses different routing than r8a7795 ES2.0. + */ + attr = soc_device_match(r8a7795es1); + if (attr) + vin->info = attr->data; mem = platform_get_resource(pdev, IORESOURCE_MEM, 0); if (mem == NULL) @@ -245,13 +1080,15 @@ static int rcar_vin_probe(struct platform_device *pdev) if (irq < 0) return irq; - ret = rvin_dma_probe(vin, irq); + ret = rvin_dma_register(vin, irq); if (ret) return ret; platform_set_drvdata(pdev, vin); - - ret = rvin_digital_graph_init(vin); + if (vin->info->use_mc) + ret = rvin_mc_init(vin); + else + ret = rvin_digital_graph_init(vin); if (ret < 0) goto error; @@ -260,7 +1097,7 @@ static int rcar_vin_probe(struct platform_device *pdev) return 0; error: - rvin_dma_remove(vin); + rvin_dma_unregister(vin); v4l2_async_notifier_cleanup(&vin->notifier); return ret; @@ -272,10 +1109,22 @@ static int rcar_vin_remove(struct platform_device *pdev) pm_runtime_disable(&pdev->dev); + rvin_v4l2_unregister(vin); + v4l2_async_notifier_unregister(&vin->notifier); v4l2_async_notifier_cleanup(&vin->notifier); - rvin_dma_remove(vin); + if (vin->info->use_mc) { + mutex_lock(&vin->group->lock); + if (vin->group->notifier == &vin->notifier) + vin->group->notifier = NULL; + mutex_unlock(&vin->group->lock); + rvin_group_put(vin); + } else { + v4l2_ctrl_handler_free(&vin->ctrl_handler); + } + + rvin_dma_unregister(vin); return 0; } diff --git a/drivers/media/platform/rcar-vin/rcar-dma.c b/drivers/media/platform/rcar-vin/rcar-dma.c index 4a40e6ad1be7..b41ba9a4a2b3 100644 --- a/drivers/media/platform/rcar-vin/rcar-dma.c +++ b/drivers/media/platform/rcar-vin/rcar-dma.c @@ -16,6 +16,7 @@ #include <linux/delay.h> #include <linux/interrupt.h> +#include <linux/pm_runtime.h> #include <media/videobuf2-dma-contig.h> @@ -33,21 +34,23 @@ #define VNELPRC_REG 0x10 /* Video n End Line Pre-Clip Register */ #define VNSPPRC_REG 0x14 /* Video n Start Pixel Pre-Clip Register */ #define VNEPPRC_REG 0x18 /* Video n End Pixel Pre-Clip Register */ -#define VNSLPOC_REG 0x1C /* Video n Start Line Post-Clip Register */ -#define VNELPOC_REG 0x20 /* Video n End Line Post-Clip Register */ -#define VNSPPOC_REG 0x24 /* Video n Start Pixel Post-Clip Register */ -#define VNEPPOC_REG 0x28 /* Video n End Pixel Post-Clip Register */ #define VNIS_REG 0x2C /* Video n Image Stride Register */ #define VNMB_REG(m) (0x30 + ((m) << 2)) /* Video n Memory Base m Register */ #define VNIE_REG 0x40 /* Video n Interrupt Enable Register */ #define VNINTS_REG 0x44 /* Video n Interrupt Status Register */ #define VNSI_REG 0x48 /* Video n Scanline Interrupt Register */ #define VNMTC_REG 0x4C /* Video n Memory Transfer Control Register */ -#define VNYS_REG 0x50 /* Video n Y Scale Register */ -#define VNXS_REG 0x54 /* Video n X Scale Register */ #define VNDMR_REG 0x58 /* Video n Data Mode Register */ #define VNDMR2_REG 0x5C /* Video n Data Mode Register 2 */ #define VNUVAOF_REG 0x60 /* Video n UV Address Offset Register */ + +/* Register offsets specific for Gen2 */ +#define VNSLPOC_REG 0x1C /* Video n Start Line Post-Clip Register */ +#define VNELPOC_REG 0x20 /* Video n End Line Post-Clip Register */ +#define VNSPPOC_REG 0x24 /* Video n Start Pixel Post-Clip Register */ +#define VNEPPOC_REG 0x28 /* Video n End Pixel Post-Clip Register */ +#define VNYS_REG 0x50 /* Video n Y Scale Register */ +#define VNXS_REG 0x54 /* Video n X Scale Register */ #define VNC1A_REG 0x80 /* Video n Coefficient Set C1A Register */ #define VNC1B_REG 0x84 /* Video n Coefficient Set C1B Register */ #define VNC1C_REG 0x88 /* Video n Coefficient Set C1C Register */ @@ -73,9 +76,13 @@ #define VNC8B_REG 0xF4 /* Video n Coefficient Set C8B Register */ #define VNC8C_REG 0xF8 /* Video n Coefficient Set C8C Register */ +/* Register offsets specific for Gen3 */ +#define VNCSI_IFMD_REG 0x20 /* Video n CSI2 Interface Mode Register */ /* Register bit fields for R-Car VIN */ /* Video n Main Control Register bits */ +#define VNMC_DPINE (1 << 27) /* Gen3 specific */ +#define VNMC_SCLE (1 << 26) /* Gen3 specific */ #define VNMC_FOC (1 << 21) #define VNMC_YCAL (1 << 19) #define VNMC_INF_YUV8_BT656 (0 << 16) @@ -117,7 +124,15 @@ #define VNDMR2_VPS (1 << 30) #define VNDMR2_HPS (1 << 29) #define VNDMR2_FTEV (1 << 17) +#define VNDMR2_FTEH (1 << 16) #define VNDMR2_VLV(n) ((n & 0xf) << 12) +#define VNDMR2_HLV(n) ((n) & 0xfff) + +/* Video n CSI2 Interface Mode Register (Gen3) */ +#define VNCSI_IFMD_DES1 (1 << 26) +#define VNCSI_IFMD_DES0 (1 << 25) +#define VNCSI_IFMD_CSI_CHSEL(n) (((n) & 0xf) << 0) +#define VNCSI_IFMD_CSI_CHSEL_MASK 0xf struct rvin_buffer { struct vb2_v4l2_buffer vb; @@ -138,267 +153,6 @@ static u32 rvin_read(struct rvin_dev *vin, u32 offset) return ioread32(vin->base + offset); } -static int rvin_setup(struct rvin_dev *vin) -{ - u32 vnmc, dmr, dmr2, interrupts; - v4l2_std_id std; - bool progressive = false, output_is_yuv = false, input_is_yuv = false; - - switch (vin->format.field) { - case V4L2_FIELD_TOP: - vnmc = VNMC_IM_ODD; - break; - case V4L2_FIELD_BOTTOM: - vnmc = VNMC_IM_EVEN; - break; - case V4L2_FIELD_INTERLACED: - /* Default to TB */ - vnmc = VNMC_IM_FULL; - /* Use BT if video standard can be read and is 60 Hz format */ - if (!v4l2_subdev_call(vin_to_source(vin), video, g_std, &std)) { - if (std & V4L2_STD_525_60) - vnmc = VNMC_IM_FULL | VNMC_FOC; - } - break; - case V4L2_FIELD_INTERLACED_TB: - vnmc = VNMC_IM_FULL; - break; - case V4L2_FIELD_INTERLACED_BT: - vnmc = VNMC_IM_FULL | VNMC_FOC; - break; - case V4L2_FIELD_ALTERNATE: - case V4L2_FIELD_NONE: - vnmc = VNMC_IM_ODD_EVEN; - progressive = true; - break; - default: - vnmc = VNMC_IM_ODD; - break; - } - - /* - * Input interface - */ - switch (vin->digital->code) { - case MEDIA_BUS_FMT_YUYV8_1X16: - /* BT.601/BT.1358 16bit YCbCr422 */ - vnmc |= VNMC_INF_YUV16; - input_is_yuv = true; - break; - case MEDIA_BUS_FMT_UYVY8_2X8: - /* BT.656 8bit YCbCr422 or BT.601 8bit YCbCr422 */ - vnmc |= vin->digital->mbus_cfg.type == V4L2_MBUS_BT656 ? - VNMC_INF_YUV8_BT656 : VNMC_INF_YUV8_BT601; - input_is_yuv = true; - break; - case MEDIA_BUS_FMT_RGB888_1X24: - vnmc |= VNMC_INF_RGB888; - break; - case MEDIA_BUS_FMT_UYVY10_2X10: - /* BT.656 10bit YCbCr422 or BT.601 10bit YCbCr422 */ - vnmc |= vin->digital->mbus_cfg.type == V4L2_MBUS_BT656 ? - VNMC_INF_YUV10_BT656 : VNMC_INF_YUV10_BT601; - input_is_yuv = true; - break; - default: - break; - } - - /* Enable VSYNC Field Toogle mode after one VSYNC input */ - dmr2 = VNDMR2_FTEV | VNDMR2_VLV(1); - - /* Hsync Signal Polarity Select */ - if (!(vin->digital->mbus_cfg.flags & V4L2_MBUS_HSYNC_ACTIVE_LOW)) - dmr2 |= VNDMR2_HPS; - - /* Vsync Signal Polarity Select */ - if (!(vin->digital->mbus_cfg.flags & V4L2_MBUS_VSYNC_ACTIVE_LOW)) - dmr2 |= VNDMR2_VPS; - - /* - * Output format - */ - switch (vin->format.pixelformat) { - case V4L2_PIX_FMT_NV16: - rvin_write(vin, - ALIGN(vin->format.width * vin->format.height, 0x80), - VNUVAOF_REG); - dmr = VNDMR_DTMD_YCSEP; - output_is_yuv = true; - break; - case V4L2_PIX_FMT_YUYV: - dmr = VNDMR_BPSM; - output_is_yuv = true; - break; - case V4L2_PIX_FMT_UYVY: - dmr = 0; - output_is_yuv = true; - break; - case V4L2_PIX_FMT_XRGB555: - dmr = VNDMR_DTMD_ARGB1555; - break; - case V4L2_PIX_FMT_RGB565: - dmr = 0; - break; - case V4L2_PIX_FMT_XBGR32: - /* Note: not supported on M1 */ - dmr = VNDMR_EXRGB; - break; - default: - vin_err(vin, "Invalid pixelformat (0x%x)\n", - vin->format.pixelformat); - return -EINVAL; - } - - /* Always update on field change */ - vnmc |= VNMC_VUP; - - /* If input and output use the same colorspace, use bypass mode */ - if (input_is_yuv == output_is_yuv) - vnmc |= VNMC_BPS; - - /* Progressive or interlaced mode */ - interrupts = progressive ? VNIE_FIE : VNIE_EFE; - - /* Ack interrupts */ - rvin_write(vin, interrupts, VNINTS_REG); - /* Enable interrupts */ - rvin_write(vin, interrupts, VNIE_REG); - /* Start capturing */ - rvin_write(vin, dmr, VNDMR_REG); - rvin_write(vin, dmr2, VNDMR2_REG); - - /* Enable module */ - rvin_write(vin, vnmc | VNMC_ME, VNMC_REG); - - return 0; -} - -static void rvin_disable_interrupts(struct rvin_dev *vin) -{ - rvin_write(vin, 0, VNIE_REG); -} - -static u32 rvin_get_interrupt_status(struct rvin_dev *vin) -{ - return rvin_read(vin, VNINTS_REG); -} - -static void rvin_ack_interrupt(struct rvin_dev *vin) -{ - rvin_write(vin, rvin_read(vin, VNINTS_REG), VNINTS_REG); -} - -static bool rvin_capture_active(struct rvin_dev *vin) -{ - return rvin_read(vin, VNMS_REG) & VNMS_CA; -} - -static enum v4l2_field rvin_get_active_field(struct rvin_dev *vin, u32 vnms) -{ - if (vin->format.field == V4L2_FIELD_ALTERNATE) { - /* If FS is set it's a Even field */ - if (vnms & VNMS_FS) - return V4L2_FIELD_BOTTOM; - return V4L2_FIELD_TOP; - } - - return vin->format.field; -} - -static void rvin_set_slot_addr(struct rvin_dev *vin, int slot, dma_addr_t addr) -{ - const struct rvin_video_format *fmt; - int offsetx, offsety; - dma_addr_t offset; - - fmt = rvin_format_from_pixel(vin->format.pixelformat); - - /* - * There is no HW support for composition do the beast we can - * by modifying the buffer offset - */ - offsetx = vin->compose.left * fmt->bpp; - offsety = vin->compose.top * vin->format.bytesperline; - offset = addr + offsetx + offsety; - - /* - * The address needs to be 128 bytes aligned. Driver should never accept - * settings that do not satisfy this in the first place... - */ - if (WARN_ON((offsetx | offsety | offset) & HW_BUFFER_MASK)) - return; - - rvin_write(vin, offset, VNMB_REG(slot)); -} - -/* - * Moves a buffer from the queue to the HW slot. If no buffer is - * available use the scratch buffer. The scratch buffer is never - * returned to userspace, its only function is to enable the capture - * loop to keep running. - */ -static void rvin_fill_hw_slot(struct rvin_dev *vin, int slot) -{ - struct rvin_buffer *buf; - struct vb2_v4l2_buffer *vbuf; - dma_addr_t phys_addr; - - /* A already populated slot shall never be overwritten. */ - if (WARN_ON(vin->queue_buf[slot] != NULL)) - return; - - vin_dbg(vin, "Filling HW slot: %d\n", slot); - - if (list_empty(&vin->buf_list)) { - vin->queue_buf[slot] = NULL; - phys_addr = vin->scratch_phys; - } else { - /* Keep track of buffer we give to HW */ - buf = list_entry(vin->buf_list.next, struct rvin_buffer, list); - vbuf = &buf->vb; - list_del_init(to_buf_list(vbuf)); - vin->queue_buf[slot] = vbuf; - - /* Setup DMA */ - phys_addr = vb2_dma_contig_plane_dma_addr(&vbuf->vb2_buf, 0); - } - - rvin_set_slot_addr(vin, slot, phys_addr); -} - -static int rvin_capture_start(struct rvin_dev *vin) -{ - int slot, ret; - - for (slot = 0; slot < HW_BUFFER_NUM; slot++) - rvin_fill_hw_slot(vin, slot); - - rvin_crop_scale_comp(vin); - - ret = rvin_setup(vin); - if (ret) - return ret; - - vin_dbg(vin, "Starting to capture\n"); - - /* Continuous Frame Capture Mode */ - rvin_write(vin, VNFC_C_FRAME, VNFC_REG); - - vin->state = RUNNING; - - return 0; -} - -static void rvin_capture_stop(struct rvin_dev *vin) -{ - /* Set continuous & single transfer off */ - rvin_write(vin, 0, VNFC_REG); - - /* Disable module */ - rvin_write(vin, rvin_read(vin, VNMC_REG) & ~VNMC_ME, VNMC_REG); -} - /* ----------------------------------------------------------------------------- * Crop and Scaling Gen2 */ @@ -775,28 +529,10 @@ static void rvin_set_coeff(struct rvin_dev *vin, unsigned short xs) rvin_write(vin, p_set->coeff_set[23], VNC8C_REG); } -void rvin_crop_scale_comp(struct rvin_dev *vin) +static void rvin_crop_scale_comp_gen2(struct rvin_dev *vin) { u32 xs, ys; - /* Set Start/End Pixel/Line Pre-Clip */ - rvin_write(vin, vin->crop.left, VNSPPRC_REG); - rvin_write(vin, vin->crop.left + vin->crop.width - 1, VNEPPRC_REG); - switch (vin->format.field) { - case V4L2_FIELD_INTERLACED: - case V4L2_FIELD_INTERLACED_TB: - case V4L2_FIELD_INTERLACED_BT: - rvin_write(vin, vin->crop.top / 2, VNSLPRC_REG); - rvin_write(vin, (vin->crop.top + vin->crop.height) / 2 - 1, - VNELPRC_REG); - break; - default: - rvin_write(vin, vin->crop.top, VNSLPRC_REG); - rvin_write(vin, vin->crop.top + vin->crop.height - 1, - VNELPRC_REG); - break; - } - /* Set scaling coefficient */ ys = 0; if (vin->crop.height != vin->compose.height) @@ -834,11 +570,6 @@ void rvin_crop_scale_comp(struct rvin_dev *vin) break; } - if (vin->format.pixelformat == V4L2_PIX_FMT_NV16) - rvin_write(vin, ALIGN(vin->format.width, 0x20), VNIS_REG); - else - rvin_write(vin, ALIGN(vin->format.width, 0x10), VNIS_REG); - vin_dbg(vin, "Pre-Clip: %ux%u@%u:%u YS: %d XS: %d Post-Clip: %ux%u@%u:%u\n", vin->crop.width, vin->crop.height, vin->crop.left, @@ -846,12 +577,307 @@ void rvin_crop_scale_comp(struct rvin_dev *vin) 0, 0); } -void rvin_scale_try(struct rvin_dev *vin, struct v4l2_pix_format *pix, - u32 width, u32 height) +void rvin_crop_scale_comp(struct rvin_dev *vin) +{ + /* Set Start/End Pixel/Line Pre-Clip */ + rvin_write(vin, vin->crop.left, VNSPPRC_REG); + rvin_write(vin, vin->crop.left + vin->crop.width - 1, VNEPPRC_REG); + + switch (vin->format.field) { + case V4L2_FIELD_INTERLACED: + case V4L2_FIELD_INTERLACED_TB: + case V4L2_FIELD_INTERLACED_BT: + rvin_write(vin, vin->crop.top / 2, VNSLPRC_REG); + rvin_write(vin, (vin->crop.top + vin->crop.height) / 2 - 1, + VNELPRC_REG); + break; + default: + rvin_write(vin, vin->crop.top, VNSLPRC_REG); + rvin_write(vin, vin->crop.top + vin->crop.height - 1, + VNELPRC_REG); + break; + } + + /* TODO: Add support for the UDS scaler. */ + if (vin->info->model != RCAR_GEN3) + rvin_crop_scale_comp_gen2(vin); + + if (vin->format.pixelformat == V4L2_PIX_FMT_NV16) + rvin_write(vin, ALIGN(vin->format.width, 0x20), VNIS_REG); + else + rvin_write(vin, ALIGN(vin->format.width, 0x10), VNIS_REG); +} + +/* ----------------------------------------------------------------------------- + * Hardware setup + */ + +static int rvin_setup(struct rvin_dev *vin) +{ + u32 vnmc, dmr, dmr2, interrupts, lines; + bool progressive = false, output_is_yuv = false, input_is_yuv = false; + bool halfsize = false; + + switch (vin->format.field) { + case V4L2_FIELD_TOP: + vnmc = VNMC_IM_ODD; + break; + case V4L2_FIELD_BOTTOM: + vnmc = VNMC_IM_EVEN; + break; + case V4L2_FIELD_INTERLACED: + /* Default to TB */ + vnmc = VNMC_IM_FULL; + /* Use BT if video standard can be read and is 60 Hz format */ + if (!vin->info->use_mc && vin->std & V4L2_STD_525_60) + vnmc = VNMC_IM_FULL | VNMC_FOC; + halfsize = true; + break; + case V4L2_FIELD_INTERLACED_TB: + vnmc = VNMC_IM_FULL; + halfsize = true; + break; + case V4L2_FIELD_INTERLACED_BT: + vnmc = VNMC_IM_FULL | VNMC_FOC; + halfsize = true; + break; + case V4L2_FIELD_NONE: + vnmc = VNMC_IM_ODD_EVEN; + progressive = true; + break; + default: + vnmc = VNMC_IM_ODD; + break; + } + + /* + * Input interface + */ + switch (vin->mbus_code) { + case MEDIA_BUS_FMT_YUYV8_1X16: + /* BT.601/BT.1358 16bit YCbCr422 */ + vnmc |= VNMC_INF_YUV16; + input_is_yuv = true; + break; + case MEDIA_BUS_FMT_UYVY8_1X16: + vnmc |= VNMC_INF_YUV16 | VNMC_YCAL; + input_is_yuv = true; + break; + case MEDIA_BUS_FMT_UYVY8_2X8: + /* BT.656 8bit YCbCr422 or BT.601 8bit YCbCr422 */ + vnmc |= vin->mbus_cfg.type == V4L2_MBUS_BT656 ? + VNMC_INF_YUV8_BT656 : VNMC_INF_YUV8_BT601; + input_is_yuv = true; + break; + case MEDIA_BUS_FMT_RGB888_1X24: + vnmc |= VNMC_INF_RGB888; + break; + case MEDIA_BUS_FMT_UYVY10_2X10: + /* BT.656 10bit YCbCr422 or BT.601 10bit YCbCr422 */ + vnmc |= vin->mbus_cfg.type == V4L2_MBUS_BT656 ? + VNMC_INF_YUV10_BT656 : VNMC_INF_YUV10_BT601; + input_is_yuv = true; + break; + default: + break; + } + + if (vin->info->model == RCAR_GEN3) { + /* Enable HSYNC Field Toggle mode after height HSYNC inputs. */ + lines = vin->format.height / (halfsize ? 2 : 1); + dmr2 = VNDMR2_FTEH | VNDMR2_HLV(lines); + vin_dbg(vin, "Field Toogle after %u lines\n", lines); + } else { + /* Enable VSYNC Field Toogle mode after one VSYNC input. */ + dmr2 = VNDMR2_FTEV | VNDMR2_VLV(1); + } + + /* Hsync Signal Polarity Select */ + if (!(vin->mbus_cfg.flags & V4L2_MBUS_HSYNC_ACTIVE_LOW)) + dmr2 |= VNDMR2_HPS; + + /* Vsync Signal Polarity Select */ + if (!(vin->mbus_cfg.flags & V4L2_MBUS_VSYNC_ACTIVE_LOW)) + dmr2 |= VNDMR2_VPS; + + /* + * Output format + */ + switch (vin->format.pixelformat) { + case V4L2_PIX_FMT_NV16: + rvin_write(vin, + ALIGN(vin->format.width * vin->format.height, 0x80), + VNUVAOF_REG); + dmr = VNDMR_DTMD_YCSEP; + output_is_yuv = true; + break; + case V4L2_PIX_FMT_YUYV: + dmr = VNDMR_BPSM; + output_is_yuv = true; + break; + case V4L2_PIX_FMT_UYVY: + dmr = 0; + output_is_yuv = true; + break; + case V4L2_PIX_FMT_XRGB555: + dmr = VNDMR_DTMD_ARGB1555; + break; + case V4L2_PIX_FMT_RGB565: + dmr = 0; + break; + case V4L2_PIX_FMT_XBGR32: + /* Note: not supported on M1 */ + dmr = VNDMR_EXRGB; + break; + default: + vin_err(vin, "Invalid pixelformat (0x%x)\n", + vin->format.pixelformat); + return -EINVAL; + } + + /* Always update on field change */ + vnmc |= VNMC_VUP; + + /* If input and output use the same colorspace, use bypass mode */ + if (input_is_yuv == output_is_yuv) + vnmc |= VNMC_BPS; + + if (vin->info->model == RCAR_GEN3) { + /* Select between CSI-2 and Digital input */ + if (vin->mbus_cfg.type == V4L2_MBUS_CSI2) + vnmc &= ~VNMC_DPINE; + else + vnmc |= VNMC_DPINE; + } + + /* Progressive or interlaced mode */ + interrupts = progressive ? VNIE_FIE : VNIE_EFE; + + /* Ack interrupts */ + rvin_write(vin, interrupts, VNINTS_REG); + /* Enable interrupts */ + rvin_write(vin, interrupts, VNIE_REG); + /* Start capturing */ + rvin_write(vin, dmr, VNDMR_REG); + rvin_write(vin, dmr2, VNDMR2_REG); + + /* Enable module */ + rvin_write(vin, vnmc | VNMC_ME, VNMC_REG); + + return 0; +} + +static void rvin_disable_interrupts(struct rvin_dev *vin) +{ + rvin_write(vin, 0, VNIE_REG); +} + +static u32 rvin_get_interrupt_status(struct rvin_dev *vin) +{ + return rvin_read(vin, VNINTS_REG); +} + +static void rvin_ack_interrupt(struct rvin_dev *vin) { - /* All VIN channels on Gen2 have scalers */ - pix->width = width; - pix->height = height; + rvin_write(vin, rvin_read(vin, VNINTS_REG), VNINTS_REG); +} + +static bool rvin_capture_active(struct rvin_dev *vin) +{ + return rvin_read(vin, VNMS_REG) & VNMS_CA; +} + +static void rvin_set_slot_addr(struct rvin_dev *vin, int slot, dma_addr_t addr) +{ + const struct rvin_video_format *fmt; + int offsetx, offsety; + dma_addr_t offset; + + fmt = rvin_format_from_pixel(vin->format.pixelformat); + + /* + * There is no HW support for composition do the beast we can + * by modifying the buffer offset + */ + offsetx = vin->compose.left * fmt->bpp; + offsety = vin->compose.top * vin->format.bytesperline; + offset = addr + offsetx + offsety; + + /* + * The address needs to be 128 bytes aligned. Driver should never accept + * settings that do not satisfy this in the first place... + */ + if (WARN_ON((offsetx | offsety | offset) & HW_BUFFER_MASK)) + return; + + rvin_write(vin, offset, VNMB_REG(slot)); +} + +/* + * Moves a buffer from the queue to the HW slot. If no buffer is + * available use the scratch buffer. The scratch buffer is never + * returned to userspace, its only function is to enable the capture + * loop to keep running. + */ +static void rvin_fill_hw_slot(struct rvin_dev *vin, int slot) +{ + struct rvin_buffer *buf; + struct vb2_v4l2_buffer *vbuf; + dma_addr_t phys_addr; + + /* A already populated slot shall never be overwritten. */ + if (WARN_ON(vin->queue_buf[slot] != NULL)) + return; + + vin_dbg(vin, "Filling HW slot: %d\n", slot); + + if (list_empty(&vin->buf_list)) { + vin->queue_buf[slot] = NULL; + phys_addr = vin->scratch_phys; + } else { + /* Keep track of buffer we give to HW */ + buf = list_entry(vin->buf_list.next, struct rvin_buffer, list); + vbuf = &buf->vb; + list_del_init(to_buf_list(vbuf)); + vin->queue_buf[slot] = vbuf; + + /* Setup DMA */ + phys_addr = vb2_dma_contig_plane_dma_addr(&vbuf->vb2_buf, 0); + } + + rvin_set_slot_addr(vin, slot, phys_addr); +} + +static int rvin_capture_start(struct rvin_dev *vin) +{ + int slot, ret; + + for (slot = 0; slot < HW_BUFFER_NUM; slot++) + rvin_fill_hw_slot(vin, slot); + + rvin_crop_scale_comp(vin); + + ret = rvin_setup(vin); + if (ret) + return ret; + + vin_dbg(vin, "Starting to capture\n"); + + /* Continuous Frame Capture Mode */ + rvin_write(vin, VNFC_C_FRAME, VNFC_REG); + + vin->state = RUNNING; + + return 0; +} + +static void rvin_capture_stop(struct rvin_dev *vin) +{ + /* Set continuous & single transfer off */ + rvin_write(vin, 0, VNFC_REG); + + /* Disable module */ + rvin_write(vin, rvin_read(vin, VNMC_REG) & ~VNMC_ME, VNMC_REG); } /* ----------------------------------------------------------------------------- @@ -896,7 +922,7 @@ static irqreturn_t rvin_irq(int irq, void *data) /* Capture frame */ if (vin->queue_buf[slot]) { - vin->queue_buf[slot]->field = rvin_get_active_field(vin, vnms); + vin->queue_buf[slot]->field = vin->format.field; vin->queue_buf[slot]->sequence = vin->sequence; vin->queue_buf[slot]->vb2_buf.timestamp = ktime_get_ns(); vb2_buffer_done(&vin->queue_buf[slot]->vb2_buf, @@ -984,10 +1010,127 @@ static void rvin_buffer_queue(struct vb2_buffer *vb) spin_unlock_irqrestore(&vin->qlock, flags); } +static int rvin_mc_validate_format(struct rvin_dev *vin, struct v4l2_subdev *sd, + struct media_pad *pad) +{ + struct v4l2_subdev_format fmt = { + .which = V4L2_SUBDEV_FORMAT_ACTIVE, + }; + + fmt.pad = pad->index; + if (v4l2_subdev_call(sd, pad, get_fmt, NULL, &fmt)) + return -EPIPE; + + switch (fmt.format.code) { + case MEDIA_BUS_FMT_YUYV8_1X16: + case MEDIA_BUS_FMT_UYVY8_1X16: + case MEDIA_BUS_FMT_UYVY8_2X8: + case MEDIA_BUS_FMT_UYVY10_2X10: + case MEDIA_BUS_FMT_RGB888_1X24: + vin->mbus_code = fmt.format.code; + break; + default: + return -EPIPE; + } + + switch (fmt.format.field) { + case V4L2_FIELD_TOP: + case V4L2_FIELD_BOTTOM: + case V4L2_FIELD_NONE: + case V4L2_FIELD_INTERLACED_TB: + case V4L2_FIELD_INTERLACED_BT: + case V4L2_FIELD_INTERLACED: + case V4L2_FIELD_SEQ_TB: + case V4L2_FIELD_SEQ_BT: + /* Supported natively */ + break; + case V4L2_FIELD_ALTERNATE: + switch (vin->format.field) { + case V4L2_FIELD_TOP: + case V4L2_FIELD_BOTTOM: + case V4L2_FIELD_NONE: + break; + case V4L2_FIELD_INTERLACED_TB: + case V4L2_FIELD_INTERLACED_BT: + case V4L2_FIELD_INTERLACED: + case V4L2_FIELD_SEQ_TB: + case V4L2_FIELD_SEQ_BT: + /* Use VIN hardware to combine the two fields */ + fmt.format.height *= 2; + break; + default: + return -EPIPE; + } + break; + default: + return -EPIPE; + } + + if (fmt.format.width != vin->format.width || + fmt.format.height != vin->format.height || + fmt.format.code != vin->mbus_code) + return -EPIPE; + + return 0; +} + +static int rvin_set_stream(struct rvin_dev *vin, int on) +{ + struct media_pipeline *pipe; + struct media_device *mdev; + struct v4l2_subdev *sd; + struct media_pad *pad; + int ret; + + /* No media controller used, simply pass operation to subdevice. */ + if (!vin->info->use_mc) { + ret = v4l2_subdev_call(vin->digital->subdev, video, s_stream, + on); + + return ret == -ENOIOCTLCMD ? 0 : ret; + } + + pad = media_entity_remote_pad(&vin->pad); + if (!pad) + return -EPIPE; + + sd = media_entity_to_v4l2_subdev(pad->entity); + + if (!on) { + media_pipeline_stop(&vin->vdev.entity); + return v4l2_subdev_call(sd, video, s_stream, 0); + } + + ret = rvin_mc_validate_format(vin, sd, pad); + if (ret) + return ret; + + /* + * The graph lock needs to be taken to protect concurrent + * starts of multiple VIN instances as they might share + * a common subdevice down the line and then should use + * the same pipe. + */ + mdev = vin->vdev.entity.graph_obj.mdev; + mutex_lock(&mdev->graph_mutex); + pipe = sd->entity.pipe ? sd->entity.pipe : &vin->vdev.pipe; + ret = __media_pipeline_start(&vin->vdev.entity, pipe); + mutex_unlock(&mdev->graph_mutex); + if (ret) + return ret; + + ret = v4l2_subdev_call(sd, video, s_stream, 1); + if (ret == -ENOIOCTLCMD) + ret = 0; + if (ret) + media_pipeline_stop(&vin->vdev.entity); + + return ret; +} + static int rvin_start_streaming(struct vb2_queue *vq, unsigned int count) { struct rvin_dev *vin = vb2_get_drv_priv(vq); - struct v4l2_subdev *sd; unsigned long flags; int ret; @@ -1002,8 +1145,13 @@ static int rvin_start_streaming(struct vb2_queue *vq, unsigned int count) return -ENOMEM; } - sd = vin_to_source(vin); - v4l2_subdev_call(sd, video, s_stream, 1); + ret = rvin_set_stream(vin, 1); + if (ret) { + spin_lock_irqsave(&vin->qlock, flags); + return_all_buffers(vin, VB2_BUF_STATE_QUEUED); + spin_unlock_irqrestore(&vin->qlock, flags); + goto out; + } spin_lock_irqsave(&vin->qlock, flags); @@ -1012,11 +1160,11 @@ static int rvin_start_streaming(struct vb2_queue *vq, unsigned int count) ret = rvin_capture_start(vin); if (ret) { return_all_buffers(vin, VB2_BUF_STATE_QUEUED); - v4l2_subdev_call(sd, video, s_stream, 0); + rvin_set_stream(vin, 0); } spin_unlock_irqrestore(&vin->qlock, flags); - +out: if (ret) dma_free_coherent(vin->dev, vin->format.sizeimage, vin->scratch, vin->scratch_phys); @@ -1027,7 +1175,6 @@ static int rvin_start_streaming(struct vb2_queue *vq, unsigned int count) static void rvin_stop_streaming(struct vb2_queue *vq) { struct rvin_dev *vin = vb2_get_drv_priv(vq); - struct v4l2_subdev *sd; unsigned long flags; int retries = 0; @@ -1066,8 +1213,7 @@ static void rvin_stop_streaming(struct vb2_queue *vq) spin_unlock_irqrestore(&vin->qlock, flags); - sd = vin_to_source(vin); - v4l2_subdev_call(sd, video, s_stream, 0); + rvin_set_stream(vin, 0); /* disable interrupts */ rvin_disable_interrupts(vin); @@ -1087,14 +1233,14 @@ static const struct vb2_ops rvin_qops = { .wait_finish = vb2_ops_wait_finish, }; -void rvin_dma_remove(struct rvin_dev *vin) +void rvin_dma_unregister(struct rvin_dev *vin) { mutex_destroy(&vin->lock); v4l2_device_unregister(&vin->v4l2_dev); } -int rvin_dma_probe(struct rvin_dev *vin, int irq) +int rvin_dma_register(struct rvin_dev *vin, int irq) { struct vb2_queue *q = &vin->queue; int i, ret; @@ -1142,7 +1288,43 @@ int rvin_dma_probe(struct rvin_dev *vin, int irq) return 0; error: - rvin_dma_remove(vin); + rvin_dma_unregister(vin); + + return ret; +} + +/* ----------------------------------------------------------------------------- + * Gen3 CHSEL manipulation + */ + +/* + * There is no need to have locking around changing the routing + * as it's only possible to do so when no VIN in the group is + * streaming so nothing can race with the VNMC register. + */ +int rvin_set_channel_routing(struct rvin_dev *vin, u8 chsel) +{ + u32 ifmd, vnmc; + int ret; + + ret = pm_runtime_get_sync(vin->dev); + if (ret < 0) + return ret; + + /* Make register writes take effect immediately. */ + vnmc = rvin_read(vin, VNMC_REG); + rvin_write(vin, vnmc & ~VNMC_VUP, VNMC_REG); + + ifmd = VNCSI_IFMD_DES1 | VNCSI_IFMD_DES0 | VNCSI_IFMD_CSI_CHSEL(chsel); + + rvin_write(vin, ifmd, VNCSI_IFMD_REG); + + vin_dbg(vin, "Set IFMD 0x%x\n", ifmd); + + /* Restore VNMC. */ + rvin_write(vin, vnmc, VNMC_REG); + + pm_runtime_put(vin->dev); return ret; } diff --git a/drivers/media/platform/rcar-vin/rcar-v4l2.c b/drivers/media/platform/rcar-vin/rcar-v4l2.c index b479b882da12..2fb8587116f2 100644 --- a/drivers/media/platform/rcar-vin/rcar-v4l2.c +++ b/drivers/media/platform/rcar-vin/rcar-v4l2.c @@ -18,13 +18,16 @@ #include <media/v4l2-event.h> #include <media/v4l2-ioctl.h> +#include <media/v4l2-mc.h> #include <media/v4l2-rect.h> #include "rcar-vin.h" #define RVIN_DEFAULT_FORMAT V4L2_PIX_FMT_YUYV -#define RVIN_MAX_WIDTH 2048 -#define RVIN_MAX_HEIGHT 2048 +#define RVIN_DEFAULT_WIDTH 800 +#define RVIN_DEFAULT_HEIGHT 600 +#define RVIN_DEFAULT_FIELD V4L2_FIELD_NONE +#define RVIN_DEFAULT_COLORSPACE V4L2_COLORSPACE_SRGB /* ----------------------------------------------------------------------------- * Format Conversions @@ -88,99 +91,111 @@ static u32 rvin_format_sizeimage(struct v4l2_pix_format *pix) return pix->bytesperline * pix->height; } -/* ----------------------------------------------------------------------------- - * V4L2 - */ - -static void rvin_reset_crop_compose(struct rvin_dev *vin) +static void rvin_format_align(struct rvin_dev *vin, struct v4l2_pix_format *pix) { - vin->crop.top = vin->crop.left = 0; - vin->crop.width = vin->source.width; - vin->crop.height = vin->source.height; + u32 walign; - vin->compose.top = vin->compose.left = 0; - vin->compose.width = vin->format.width; - vin->compose.height = vin->format.height; + if (!rvin_format_from_pixel(pix->pixelformat) || + (vin->info->model == RCAR_M1 && + pix->pixelformat == V4L2_PIX_FMT_XBGR32)) + pix->pixelformat = RVIN_DEFAULT_FORMAT; + + switch (pix->field) { + case V4L2_FIELD_TOP: + case V4L2_FIELD_BOTTOM: + case V4L2_FIELD_NONE: + case V4L2_FIELD_INTERLACED_TB: + case V4L2_FIELD_INTERLACED_BT: + case V4L2_FIELD_INTERLACED: + break; + case V4L2_FIELD_ALTERNATE: + /* + * Driver does not (yet) support outputting ALTERNATE to a + * userspace. It does support outputting INTERLACED so use + * the VIN hardware to combine the two fields. + */ + pix->field = V4L2_FIELD_INTERLACED; + pix->height *= 2; + break; + default: + pix->field = RVIN_DEFAULT_FIELD; + break; + } + + /* HW limit width to a multiple of 32 (2^5) for NV16 else 2 (2^1) */ + walign = vin->format.pixelformat == V4L2_PIX_FMT_NV16 ? 5 : 1; + + /* Limit to VIN capabilities */ + v4l_bound_align_image(&pix->width, 2, vin->info->max_width, walign, + &pix->height, 4, vin->info->max_height, 2, 0); + + pix->bytesperline = rvin_format_bytesperline(pix); + pix->sizeimage = rvin_format_sizeimage(pix); + + vin_dbg(vin, "Format %ux%u bpl: %u size: %u\n", + pix->width, pix->height, pix->bytesperline, pix->sizeimage); } +/* ----------------------------------------------------------------------------- + * V4L2 + */ + static int rvin_reset_format(struct rvin_dev *vin) { struct v4l2_subdev_format fmt = { .which = V4L2_SUBDEV_FORMAT_ACTIVE, + .pad = vin->digital->source_pad, }; - struct v4l2_mbus_framefmt *mf = &fmt.format; int ret; - fmt.pad = vin->digital->source_pad; - ret = v4l2_subdev_call(vin_to_source(vin), pad, get_fmt, NULL, &fmt); if (ret) return ret; - vin->format.width = mf->width; - vin->format.height = mf->height; - vin->format.colorspace = mf->colorspace; - vin->format.field = mf->field; + v4l2_fill_pix_format(&vin->format, &fmt.format); - /* - * If the subdevice uses ALTERNATE field mode and G_STD is - * implemented use the VIN HW to combine the two fields to - * one INTERLACED frame. The ALTERNATE field mode can still - * be requested in S_FMT and be respected, this is just the - * default which is applied at probing or when S_STD is called. - */ - if (vin->format.field == V4L2_FIELD_ALTERNATE && - v4l2_subdev_has_op(vin_to_source(vin), video, g_std)) - vin->format.field = V4L2_FIELD_INTERLACED; + rvin_format_align(vin, &vin->format); - switch (vin->format.field) { - case V4L2_FIELD_TOP: - case V4L2_FIELD_BOTTOM: - case V4L2_FIELD_ALTERNATE: - vin->format.height /= 2; - break; - case V4L2_FIELD_NONE: - case V4L2_FIELD_INTERLACED_TB: - case V4L2_FIELD_INTERLACED_BT: - case V4L2_FIELD_INTERLACED: - break; - default: - vin->format.field = V4L2_FIELD_NONE; - break; - } - - rvin_reset_crop_compose(vin); + vin->source.top = 0; + vin->source.left = 0; + vin->source.width = vin->format.width; + vin->source.height = vin->format.height; - vin->format.bytesperline = rvin_format_bytesperline(&vin->format); - vin->format.sizeimage = rvin_format_sizeimage(&vin->format); + vin->crop = vin->source; + vin->compose = vin->source; return 0; } -static int __rvin_try_format_source(struct rvin_dev *vin, - u32 which, - struct v4l2_pix_format *pix, - struct rvin_source_fmt *source) +static int rvin_try_format(struct rvin_dev *vin, u32 which, + struct v4l2_pix_format *pix, + struct v4l2_rect *crop, struct v4l2_rect *compose) { - struct v4l2_subdev *sd; + struct v4l2_subdev *sd = vin_to_source(vin); struct v4l2_subdev_pad_config *pad_cfg; struct v4l2_subdev_format format = { .which = which, + .pad = vin->digital->source_pad, }; enum v4l2_field field; + u32 width, height; int ret; - sd = vin_to_source(vin); - - v4l2_fill_mbus_format(&format.format, pix, vin->digital->code); - pad_cfg = v4l2_subdev_alloc_pad_config(sd); if (pad_cfg == NULL) return -ENOMEM; - format.pad = vin->digital->source_pad; + if (!rvin_format_from_pixel(pix->pixelformat) || + (vin->info->model == RCAR_M1 && + pix->pixelformat == V4L2_PIX_FMT_XBGR32)) + pix->pixelformat = RVIN_DEFAULT_FORMAT; + + v4l2_fill_mbus_format(&format.format, pix, vin->mbus_code); + /* Allow the video device to override field and to scale */ field = pix->field; + width = pix->width; + height = pix->height; ret = v4l2_subdev_call(sd, pad, set_fmt, pad_cfg, &format); if (ret < 0 && ret != -ENOIOCTLCMD) @@ -188,92 +203,36 @@ static int __rvin_try_format_source(struct rvin_dev *vin, v4l2_fill_pix_format(pix, &format.format); - pix->field = field; - - source->width = pix->width; - source->height = pix->height; - - vin_dbg(vin, "Source resolution: %ux%u\n", source->width, - source->height); + if (crop) { + crop->top = 0; + crop->left = 0; + crop->width = pix->width; + crop->height = pix->height; -done: - v4l2_subdev_free_pad_config(pad_cfg); - return ret; -} - -static int __rvin_try_format(struct rvin_dev *vin, - u32 which, - struct v4l2_pix_format *pix, - struct rvin_source_fmt *source) -{ - u32 rwidth, rheight, walign; - int ret; - - /* Requested */ - rwidth = pix->width; - rheight = pix->height; - - /* Keep current field if no specific one is asked for */ - if (pix->field == V4L2_FIELD_ANY) - pix->field = vin->format.field; - - /* If requested format is not supported fallback to the default */ - if (!rvin_format_from_pixel(pix->pixelformat)) { - vin_dbg(vin, "Format 0x%x not found, using default 0x%x\n", - pix->pixelformat, RVIN_DEFAULT_FORMAT); - pix->pixelformat = RVIN_DEFAULT_FORMAT; + /* + * If source is ALTERNATE the driver will use the VIN hardware + * to INTERLACE it. The crop height then needs to be doubled. + */ + if (pix->field == V4L2_FIELD_ALTERNATE) + crop->height *= 2; } - /* Always recalculate */ - pix->bytesperline = 0; - pix->sizeimage = 0; + if (field != V4L2_FIELD_ANY) + pix->field = field; - /* Limit to source capabilities */ - ret = __rvin_try_format_source(vin, which, pix, source); - if (ret) - return ret; + pix->width = width; + pix->height = height; - switch (pix->field) { - case V4L2_FIELD_TOP: - case V4L2_FIELD_BOTTOM: - case V4L2_FIELD_ALTERNATE: - pix->height /= 2; - source->height /= 2; - break; - case V4L2_FIELD_NONE: - case V4L2_FIELD_INTERLACED_TB: - case V4L2_FIELD_INTERLACED_BT: - case V4L2_FIELD_INTERLACED: - break; - default: - pix->field = V4L2_FIELD_NONE; - break; - } - - /* If source can't match format try if VIN can scale */ - if (source->width != rwidth || source->height != rheight) - rvin_scale_try(vin, pix, rwidth, rheight); - - /* HW limit width to a multiple of 32 (2^5) for NV16 else 2 (2^1) */ - walign = vin->format.pixelformat == V4L2_PIX_FMT_NV16 ? 5 : 1; + rvin_format_align(vin, pix); - /* Limit to VIN capabilities */ - v4l_bound_align_image(&pix->width, 2, RVIN_MAX_WIDTH, walign, - &pix->height, 4, RVIN_MAX_HEIGHT, 2, 0); - - pix->bytesperline = max_t(u32, pix->bytesperline, - rvin_format_bytesperline(pix)); - pix->sizeimage = max_t(u32, pix->sizeimage, - rvin_format_sizeimage(pix)); - - if (vin->chip == RCAR_M1 && pix->pixelformat == V4L2_PIX_FMT_XBGR32) { - vin_err(vin, "pixel format XBGR32 not supported on M1\n"); - return -EINVAL; + if (compose) { + compose->top = 0; + compose->left = 0; + compose->width = pix->width; + compose->height = pix->height; } - - vin_dbg(vin, "Requested %ux%u Got %ux%u bpl: %d size: %d\n", - rwidth, rheight, pix->width, pix->height, - pix->bytesperline, pix->sizeimage); +done: + v4l2_subdev_free_pad_config(pad_cfg); return 0; } @@ -294,33 +253,30 @@ static int rvin_try_fmt_vid_cap(struct file *file, void *priv, struct v4l2_format *f) { struct rvin_dev *vin = video_drvdata(file); - struct rvin_source_fmt source; - return __rvin_try_format(vin, V4L2_SUBDEV_FORMAT_TRY, &f->fmt.pix, - &source); + return rvin_try_format(vin, V4L2_SUBDEV_FORMAT_TRY, &f->fmt.pix, NULL, + NULL); } static int rvin_s_fmt_vid_cap(struct file *file, void *priv, struct v4l2_format *f) { struct rvin_dev *vin = video_drvdata(file); - struct rvin_source_fmt source; + struct v4l2_rect crop, compose; int ret; if (vb2_is_busy(&vin->queue)) return -EBUSY; - ret = __rvin_try_format(vin, V4L2_SUBDEV_FORMAT_ACTIVE, &f->fmt.pix, - &source); + ret = rvin_try_format(vin, V4L2_SUBDEV_FORMAT_ACTIVE, &f->fmt.pix, + &crop, &compose); if (ret) return ret; - vin->source.width = source.width; - vin->source.height = source.height; - vin->format = f->fmt.pix; - - rvin_reset_crop_compose(vin); + vin->crop = crop; + vin->compose = compose; + vin->source = crop; return 0; } @@ -405,8 +361,8 @@ static int rvin_s_selection(struct file *file, void *fh, max_rect.height = vin->source.height; v4l2_rect_map_inside(&r, &max_rect); - v4l_bound_align_image(&r.width, 2, vin->source.width, 1, - &r.height, 4, vin->source.height, 2, 0); + v4l_bound_align_image(&r.width, 6, vin->source.width, 0, + &r.height, 2, vin->source.height, 0, 0); r.top = clamp_t(s32, r.top, 0, vin->source.height - r.height); r.left = clamp_t(s32, r.left, 0, vin->source.width - r.width); @@ -523,6 +479,8 @@ static int rvin_s_std(struct file *file, void *priv, v4l2_std_id a) if (ret < 0) return ret; + vin->std = a; + /* Changing the standard will change the width/height */ return rvin_reset_format(vin); } @@ -530,9 +488,13 @@ static int rvin_s_std(struct file *file, void *priv, v4l2_std_id a) static int rvin_g_std(struct file *file, void *priv, v4l2_std_id *a) { struct rvin_dev *vin = video_drvdata(file); - struct v4l2_subdev *sd = vin_to_source(vin); - return v4l2_subdev_call(sd, video, g_std, a); + if (v4l2_subdev_has_op(vin_to_source(vin), pad, dv_timings_cap)) + return -ENOIOCTLCMD; + + *a = vin->std; + + return 0; } static int rvin_subscribe_event(struct v4l2_fh *fh, @@ -697,6 +659,91 @@ static const struct v4l2_ioctl_ops rvin_ioctl_ops = { }; /* ----------------------------------------------------------------------------- + * V4L2 Media Controller + */ + +static void rvin_mc_try_format(struct rvin_dev *vin, + struct v4l2_pix_format *pix) +{ + /* + * The V4L2 specification clearly documents the colorspace fields + * as being set by drivers for capture devices. Using the values + * supplied by userspace thus wouldn't comply with the API. Until + * the API is updated force fixed vaules. + */ + pix->colorspace = RVIN_DEFAULT_COLORSPACE; + pix->xfer_func = V4L2_MAP_XFER_FUNC_DEFAULT(pix->colorspace); + pix->ycbcr_enc = V4L2_MAP_YCBCR_ENC_DEFAULT(pix->colorspace); + pix->quantization = V4L2_MAP_QUANTIZATION_DEFAULT(true, pix->colorspace, + pix->ycbcr_enc); + + rvin_format_align(vin, pix); +} + +static int rvin_mc_try_fmt_vid_cap(struct file *file, void *priv, + struct v4l2_format *f) +{ + struct rvin_dev *vin = video_drvdata(file); + + rvin_mc_try_format(vin, &f->fmt.pix); + + return 0; +} + +static int rvin_mc_s_fmt_vid_cap(struct file *file, void *priv, + struct v4l2_format *f) +{ + struct rvin_dev *vin = video_drvdata(file); + + if (vb2_is_busy(&vin->queue)) + return -EBUSY; + + rvin_mc_try_format(vin, &f->fmt.pix); + + vin->format = f->fmt.pix; + + return 0; +} + +static int rvin_mc_enum_input(struct file *file, void *priv, + struct v4l2_input *i) +{ + if (i->index != 0) + return -EINVAL; + + i->type = V4L2_INPUT_TYPE_CAMERA; + strlcpy(i->name, "Camera", sizeof(i->name)); + + return 0; +} + +static const struct v4l2_ioctl_ops rvin_mc_ioctl_ops = { + .vidioc_querycap = rvin_querycap, + .vidioc_try_fmt_vid_cap = rvin_mc_try_fmt_vid_cap, + .vidioc_g_fmt_vid_cap = rvin_g_fmt_vid_cap, + .vidioc_s_fmt_vid_cap = rvin_mc_s_fmt_vid_cap, + .vidioc_enum_fmt_vid_cap = rvin_enum_fmt_vid_cap, + + .vidioc_enum_input = rvin_mc_enum_input, + .vidioc_g_input = rvin_g_input, + .vidioc_s_input = rvin_s_input, + + .vidioc_reqbufs = vb2_ioctl_reqbufs, + .vidioc_create_bufs = vb2_ioctl_create_bufs, + .vidioc_querybuf = vb2_ioctl_querybuf, + .vidioc_qbuf = vb2_ioctl_qbuf, + .vidioc_dqbuf = vb2_ioctl_dqbuf, + .vidioc_expbuf = vb2_ioctl_expbuf, + .vidioc_prepare_buf = vb2_ioctl_prepare_buf, + .vidioc_streamon = vb2_ioctl_streamon, + .vidioc_streamoff = vb2_ioctl_streamoff, + + .vidioc_log_status = v4l2_ctrl_log_status, + .vidioc_subscribe_event = rvin_subscribe_event, + .vidioc_unsubscribe_event = v4l2_event_unsubscribe, +}; + +/* ----------------------------------------------------------------------------- * File Operations */ @@ -839,14 +886,82 @@ static const struct v4l2_file_operations rvin_fops = { .read = vb2_fop_read, }; -void rvin_v4l2_remove(struct rvin_dev *vin) +/* ----------------------------------------------------------------------------- + * Media controller file operations + */ + +static int rvin_mc_open(struct file *file) +{ + struct rvin_dev *vin = video_drvdata(file); + int ret; + + ret = mutex_lock_interruptible(&vin->lock); + if (ret) + return ret; + + ret = pm_runtime_get_sync(vin->dev); + if (ret < 0) + goto err_unlock; + + ret = v4l2_pipeline_pm_use(&vin->vdev.entity, 1); + if (ret < 0) + goto err_pm; + + file->private_data = vin; + + ret = v4l2_fh_open(file); + if (ret) + goto err_v4l2pm; + + mutex_unlock(&vin->lock); + + return 0; +err_v4l2pm: + v4l2_pipeline_pm_use(&vin->vdev.entity, 0); +err_pm: + pm_runtime_put(vin->dev); +err_unlock: + mutex_unlock(&vin->lock); + + return ret; +} + +static int rvin_mc_release(struct file *file) +{ + struct rvin_dev *vin = video_drvdata(file); + int ret; + + mutex_lock(&vin->lock); + + /* the release helper will cleanup any on-going streaming. */ + ret = _vb2_fop_release(file, NULL); + + v4l2_pipeline_pm_use(&vin->vdev.entity, 0); + pm_runtime_put(vin->dev); + + mutex_unlock(&vin->lock); + + return ret; +} + +static const struct v4l2_file_operations rvin_mc_fops = { + .owner = THIS_MODULE, + .unlocked_ioctl = video_ioctl2, + .open = rvin_mc_open, + .release = rvin_mc_release, + .poll = vb2_fop_poll, + .mmap = vb2_fop_mmap, + .read = vb2_fop_read, +}; + +void rvin_v4l2_unregister(struct rvin_dev *vin) { + if (!video_is_registered(&vin->vdev)) + return; + v4l2_info(&vin->v4l2_dev, "Removing %s\n", video_device_node_name(&vin->vdev)); - /* Checks internaly if handlers have been init or not */ - v4l2_ctrl_handler_free(&vin->ctrl_handler); - /* Checks internaly if vdev have been init or not */ video_unregister_device(&vin->vdev); } @@ -866,58 +981,39 @@ static void rvin_notify(struct v4l2_subdev *sd, } } -int rvin_v4l2_probe(struct rvin_dev *vin) +int rvin_v4l2_register(struct rvin_dev *vin) { struct video_device *vdev = &vin->vdev; - struct v4l2_subdev *sd = vin_to_source(vin); int ret; - v4l2_set_subdev_hostdata(sd, vin); - vin->v4l2_dev.notify = rvin_notify; - ret = v4l2_subdev_call(sd, video, g_tvnorms, &vin->vdev.tvnorms); - if (ret < 0 && ret != -ENOIOCTLCMD && ret != -ENODEV) - return ret; - - if (vin->vdev.tvnorms == 0) { - /* Disable the STD API if there are no tvnorms defined */ - v4l2_disable_ioctl(&vin->vdev, VIDIOC_G_STD); - v4l2_disable_ioctl(&vin->vdev, VIDIOC_S_STD); - v4l2_disable_ioctl(&vin->vdev, VIDIOC_QUERYSTD); - v4l2_disable_ioctl(&vin->vdev, VIDIOC_ENUMSTD); - } - - /* Add the controls */ - /* - * Currently the subdev with the largest number of controls (13) is - * ov6550. So let's pick 16 as a hint for the control handler. Note - * that this is a hint only: too large and you waste some memory, too - * small and there is a (very) small performance hit when looking up - * controls in the internal hash. - */ - ret = v4l2_ctrl_handler_init(&vin->ctrl_handler, 16); - if (ret < 0) - return ret; - - ret = v4l2_ctrl_add_handler(&vin->ctrl_handler, sd->ctrl_handler, NULL); - if (ret < 0) - return ret; - /* video node */ - vdev->fops = &rvin_fops; vdev->v4l2_dev = &vin->v4l2_dev; vdev->queue = &vin->queue; - strlcpy(vdev->name, KBUILD_MODNAME, sizeof(vdev->name)); + snprintf(vdev->name, sizeof(vdev->name), "VIN%u output", vin->id); vdev->release = video_device_release_empty; - vdev->ioctl_ops = &rvin_ioctl_ops; vdev->lock = &vin->lock; - vdev->ctrl_handler = &vin->ctrl_handler; vdev->device_caps = V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_STREAMING | V4L2_CAP_READWRITE; + /* Set a default format */ vin->format.pixelformat = RVIN_DEFAULT_FORMAT; - rvin_reset_format(vin); + vin->format.width = RVIN_DEFAULT_WIDTH; + vin->format.height = RVIN_DEFAULT_HEIGHT; + vin->format.field = RVIN_DEFAULT_FIELD; + vin->format.colorspace = RVIN_DEFAULT_COLORSPACE; + + if (vin->info->use_mc) { + vdev->fops = &rvin_mc_fops; + vdev->ioctl_ops = &rvin_mc_ioctl_ops; + } else { + vdev->fops = &rvin_fops; + vdev->ioctl_ops = &rvin_ioctl_ops; + rvin_reset_format(vin); + } + + rvin_format_align(vin, &vin->format); ret = video_register_device(&vin->vdev, VFL_TYPE_GRABBER, -1); if (ret) { diff --git a/drivers/media/platform/rcar-vin/rcar-vin.h b/drivers/media/platform/rcar-vin/rcar-vin.h index 95897127cc41..c2aef789b491 100644 --- a/drivers/media/platform/rcar-vin/rcar-vin.h +++ b/drivers/media/platform/rcar-vin/rcar-vin.h @@ -17,6 +17,8 @@ #ifndef __RCAR_VIN__ #define __RCAR_VIN__ +#include <linux/kref.h> + #include <media/v4l2-async.h> #include <media/v4l2-ctrls.h> #include <media/v4l2-dev.h> @@ -29,10 +31,24 @@ /* Address alignment mask for HW buffers */ #define HW_BUFFER_MASK 0x7f -enum chip_id { +/* Max number on VIN instances that can be in a system */ +#define RCAR_VIN_NUM 8 + +struct rvin_group; + +enum model_id { RCAR_H1, RCAR_M1, RCAR_GEN2, + RCAR_GEN3, +}; + +enum rvin_csi_id { + RVIN_CSI20, + RVIN_CSI21, + RVIN_CSI40, + RVIN_CSI41, + RVIN_CSI_MAX, }; /** @@ -47,16 +63,6 @@ enum rvin_dma_state { }; /** - * struct rvin_source_fmt - Source information - * @width: Width from source - * @height: Height from source - */ -struct rvin_source_fmt { - u32 width; - u32 height; -}; - -/** * struct rvin_video_format - Data format stored in memory * @fourcc: Pixelformat * @bpp: Bytes per pixel @@ -70,8 +76,6 @@ struct rvin_video_format { * struct rvin_graph_entity - Video endpoint from async framework * @asd: sub-device descriptor for async framework * @subdev: subdevice matched using async framework - * @code: Media bus format from source - * @mbus_cfg: Media bus format from DT * @source_pad: source pad of remote subdevice * @sink_pad: sink pad of remote subdevice */ @@ -79,18 +83,64 @@ struct rvin_graph_entity { struct v4l2_async_subdev asd; struct v4l2_subdev *subdev; - u32 code; - struct v4l2_mbus_config mbus_cfg; - unsigned int source_pad; unsigned int sink_pad; }; /** + * struct rvin_group_route - describes a route from a channel of a + * CSI-2 receiver to a VIN + * + * @csi: CSI-2 receiver ID. + * @channel: Output channel of the CSI-2 receiver. + * @vin: VIN ID. + * @mask: Bitmask of the different CHSEL register values that + * allow for a route from @csi + @chan to @vin. + * + * .. note:: + * Each R-Car CSI-2 receiver has four output channels facing the VIN + * devices, each channel can carry one CSI-2 Virtual Channel (VC). + * There is no correlation between channel number and CSI-2 VC. It's + * up to the CSI-2 receiver driver to configure which VC is output + * on which channel, the VIN devices only care about output channels. + * + * There are in some cases multiple CHSEL register settings which would + * allow for the same route from @csi + @channel to @vin. For example + * on R-Car H3 both the CHSEL values 0 and 3 allow for a route from + * CSI40/VC0 to VIN0. All possible CHSEL values for a route need to be + * recorded as a bitmask in @mask, in this example bit 0 and 3 should + * be set. + */ +struct rvin_group_route { + enum rvin_csi_id csi; + unsigned int channel; + unsigned int vin; + unsigned int mask; +}; + +/** + * struct rvin_info - Information about the particular VIN implementation + * @model: VIN model + * @use_mc: use media controller instead of controlling subdevice + * @max_width: max input width the VIN supports + * @max_height: max input height the VIN supports + * @routes: list of possible routes from the CSI-2 recivers to + * all VINs. The list mush be NULL terminated. + */ +struct rvin_info { + enum model_id model; + bool use_mc; + + unsigned int max_width; + unsigned int max_height; + const struct rvin_group_route *routes; +}; + +/** * struct rvin_dev - Renesas VIN device structure * @dev: (OF) device * @base: device I/O register space remapped to virtual memory - * @chip: type of VIN chip + * @info: info about VIN instance * * @vdev: V4L2 video device associated with VIN * @v4l2_dev: V4L2 device @@ -98,6 +148,10 @@ struct rvin_graph_entity { * @notifier: V4L2 asynchronous subdevs notifier * @digital: entity in the DT for local digital subdevice * + * @group: Gen3 CSI group + * @id: Gen3 group id for this VIN + * @pad: media pad for the video device entity + * * @lock: protects @queue * @queue: vb2 buffers queue * @scratch: cpu address for scratch buffer @@ -110,16 +164,19 @@ struct rvin_graph_entity { * @sequence: V4L2 buffers sequence number * @state: keeps track of operation state * - * @source: active format from the video source + * @mbus_cfg: media bus configuration from DT + * @mbus_code: media bus format code * @format: active V4L2 pixel format * * @crop: active cropping * @compose: active composing + * @source: active size of the video source + * @std: active video standard of the video source */ struct rvin_dev { struct device *dev; void __iomem *base; - enum chip_id chip; + const struct rvin_info *info; struct video_device vdev; struct v4l2_device v4l2_dev; @@ -127,6 +184,10 @@ struct rvin_dev { struct v4l2_async_notifier notifier; struct rvin_graph_entity *digital; + struct rvin_group *group; + unsigned int id; + struct media_pad pad; + struct mutex lock; struct vb2_queue queue; void *scratch; @@ -138,11 +199,14 @@ struct rvin_dev { unsigned int sequence; enum rvin_dma_state state; - struct rvin_source_fmt source; + struct v4l2_mbus_config mbus_cfg; + u32 mbus_code; struct v4l2_pix_format format; struct v4l2_rect crop; struct v4l2_rect compose; + struct v4l2_rect source; + v4l2_std_id std; }; #define vin_to_source(vin) ((vin)->digital->subdev) @@ -153,17 +217,47 @@ struct rvin_dev { #define vin_warn(d, fmt, arg...) dev_warn(d->dev, fmt, ##arg) #define vin_err(d, fmt, arg...) dev_err(d->dev, fmt, ##arg) -int rvin_dma_probe(struct rvin_dev *vin, int irq); -void rvin_dma_remove(struct rvin_dev *vin); +/** + * struct rvin_group - VIN CSI2 group information + * @refcount: number of VIN instances using the group + * + * @mdev: media device which represents the group + * + * @lock: protects the count, notifier, vin and csi members + * @count: number of enabled VIN instances found in DT + * @notifier: pointer to the notifier of a VIN which handles the + * groups async sub-devices. + * @vin: VIN instances which are part of the group + * @csi: array of pairs of fwnode and subdev pointers + * to all CSI-2 subdevices. + */ +struct rvin_group { + struct kref refcount; + + struct media_device mdev; -int rvin_v4l2_probe(struct rvin_dev *vin); -void rvin_v4l2_remove(struct rvin_dev *vin); + struct mutex lock; + unsigned int count; + struct v4l2_async_notifier *notifier; + struct rvin_dev *vin[RCAR_VIN_NUM]; + + struct { + struct fwnode_handle *fwnode; + struct v4l2_subdev *subdev; + } csi[RVIN_CSI_MAX]; +}; + +int rvin_dma_register(struct rvin_dev *vin, int irq); +void rvin_dma_unregister(struct rvin_dev *vin); + +int rvin_v4l2_register(struct rvin_dev *vin); +void rvin_v4l2_unregister(struct rvin_dev *vin); const struct rvin_video_format *rvin_format_from_pixel(u32 pixelformat); /* Cropping, composing and scaling */ -void rvin_scale_try(struct rvin_dev *vin, struct v4l2_pix_format *pix, - u32 width, u32 height); void rvin_crop_scale_comp(struct rvin_dev *vin); +int rvin_set_channel_routing(struct rvin_dev *vin, u8 chsel); + #endif diff --git a/drivers/media/platform/renesas-ceu.c b/drivers/media/platform/renesas-ceu.c index 6599dba5ab84..dec1b3572e9b 100644 --- a/drivers/media/platform/renesas-ceu.c +++ b/drivers/media/platform/renesas-ceu.c @@ -777,8 +777,15 @@ static int ceu_try_fmt(struct ceu_device *ceudev, struct v4l2_format *v4l2_fmt) const struct ceu_fmt *ceu_fmt; int ret; + /* + * Set format on sensor sub device: bus format used to produce memory + * format is selected at initialization time. + */ struct v4l2_subdev_format sd_format = { - .which = V4L2_SUBDEV_FORMAT_TRY, + .which = V4L2_SUBDEV_FORMAT_TRY, + .format = { + .code = ceu_sd->mbus_fmt.mbus_code, + }, }; switch (pix->pixelformat) { @@ -800,10 +807,6 @@ static int ceu_try_fmt(struct ceu_device *ceudev, struct v4l2_format *v4l2_fmt) v4l_bound_align_image(&pix->width, 2, CEU_MAX_WIDTH, 4, &pix->height, 4, CEU_MAX_HEIGHT, 4, 0); - /* - * Set format on sensor sub device: bus format used to produce memory - * format is selected at initialization time. - */ v4l2_fill_mbus_format_mplane(&sd_format.format, pix); ret = v4l2_subdev_call(v4l2_sd, pad, set_fmt, &pad_cfg, &sd_format); if (ret) @@ -827,8 +830,15 @@ static int ceu_set_fmt(struct ceu_device *ceudev, struct v4l2_format *v4l2_fmt) struct v4l2_subdev *v4l2_sd = ceu_sd->v4l2_sd; int ret; + /* + * Set format on sensor sub device: bus format used to produce memory + * format is selected at initialization time. + */ struct v4l2_subdev_format format = { .which = V4L2_SUBDEV_FORMAT_ACTIVE, + .format = { + .code = ceu_sd->mbus_fmt.mbus_code, + }, }; ret = ceu_try_fmt(ceudev, v4l2_fmt); diff --git a/drivers/media/platform/s5p-jpeg/jpeg-hw-exynos3250.c b/drivers/media/platform/s5p-jpeg/jpeg-hw-exynos3250.c index 0974b9a7a584..0861842b2dfc 100644 --- a/drivers/media/platform/s5p-jpeg/jpeg-hw-exynos3250.c +++ b/drivers/media/platform/s5p-jpeg/jpeg-hw-exynos3250.c @@ -425,9 +425,9 @@ unsigned int exynos3250_jpeg_get_int_status(void __iomem *regs) } void exynos3250_jpeg_clear_int_status(void __iomem *regs, - unsigned int value) + unsigned int value) { - return writel(value, regs + EXYNOS3250_JPGINTST); + writel(value, regs + EXYNOS3250_JPGINTST); } unsigned int exynos3250_jpeg_operating(void __iomem *regs) diff --git a/drivers/media/platform/via-camera.c b/drivers/media/platform/via-camera.c index e9a02639554b..f01c3e813247 100644 --- a/drivers/media/platform/via-camera.c +++ b/drivers/media/platform/via-camera.c @@ -178,7 +178,7 @@ static int via_sensor_power_setup(struct via_camera *cam) cam->power_gpio = viafb_gpio_lookup("VGPIO3"); cam->reset_gpio = viafb_gpio_lookup("VGPIO2"); - if (cam->power_gpio < 0 || cam->reset_gpio < 0) { + if (!gpio_is_valid(cam->power_gpio) || !gpio_is_valid(cam->reset_gpio)) { dev_err(&cam->platdev->dev, "Unable to find GPIO lines\n"); return -EINVAL; } diff --git a/drivers/media/platform/video-mux.c b/drivers/media/platform/video-mux.c index ee89ad76bee2..1fb887293337 100644 --- a/drivers/media/platform/video-mux.c +++ b/drivers/media/platform/video-mux.c @@ -45,6 +45,7 @@ static int video_mux_link_setup(struct media_entity *entity, { struct v4l2_subdev *sd = media_entity_to_v4l2_subdev(entity); struct video_mux *vmux = v4l2_subdev_to_video_mux(sd); + u16 source_pad = entity->num_pads - 1; int ret = 0; /* @@ -74,6 +75,9 @@ static int video_mux_link_setup(struct media_entity *entity, if (ret < 0) goto out; vmux->active = local->index; + + /* Propagate the active format to the source */ + vmux->format_mbus[source_pad] = vmux->format_mbus[vmux->active]; } else { if (vmux->active != local->index) goto out; @@ -162,14 +166,20 @@ static int video_mux_set_format(struct v4l2_subdev *sd, struct v4l2_subdev_format *sdformat) { struct video_mux *vmux = v4l2_subdev_to_video_mux(sd); - struct v4l2_mbus_framefmt *mbusformat; + struct v4l2_mbus_framefmt *mbusformat, *source_mbusformat; struct media_pad *pad = &vmux->pads[sdformat->pad]; + u16 source_pad = sd->entity.num_pads - 1; mbusformat = __video_mux_get_pad_format(sd, cfg, sdformat->pad, sdformat->which); if (!mbusformat) return -EINVAL; + source_mbusformat = __video_mux_get_pad_format(sd, cfg, source_pad, + sdformat->which); + if (!source_mbusformat) + return -EINVAL; + mutex_lock(&vmux->lock); /* Source pad mirrors active sink pad, no limitations on sink pads */ @@ -178,6 +188,10 @@ static int video_mux_set_format(struct v4l2_subdev *sd, *mbusformat = sdformat->format; + /* Propagate the format from an active sink to source */ + if ((pad->flags & MEDIA_PAD_FL_SINK) && (pad->index == vmux->active)) + *source_mbusformat = sdformat->format; + mutex_unlock(&vmux->lock); return 0; diff --git a/drivers/media/platform/vsp1/Makefile b/drivers/media/platform/vsp1/Makefile index f5cd6f0491cb..596775f932c0 100644 --- a/drivers/media/platform/vsp1/Makefile +++ b/drivers/media/platform/vsp1/Makefile @@ -3,7 +3,7 @@ vsp1-y := vsp1_drv.o vsp1_entity.o vsp1_pipe.o vsp1-y += vsp1_dl.o vsp1_drm.o vsp1_video.o vsp1-y += vsp1_rpf.o vsp1_rwpf.o vsp1_wpf.o vsp1-y += vsp1_clu.o vsp1_hsit.o vsp1_lut.o -vsp1-y += vsp1_bru.o vsp1_sru.o vsp1_uds.o +vsp1-y += vsp1_brx.o vsp1_sru.o vsp1_uds.o vsp1-y += vsp1_hgo.o vsp1_hgt.o vsp1_histo.o vsp1-y += vsp1_lif.o diff --git a/drivers/media/platform/vsp1/vsp1.h b/drivers/media/platform/vsp1/vsp1.h index 78ef838416b3..894cc725c2d4 100644 --- a/drivers/media/platform/vsp1/vsp1.h +++ b/drivers/media/platform/vsp1/vsp1.h @@ -30,7 +30,7 @@ struct rcar_fcp_device; struct vsp1_drm; struct vsp1_entity; struct vsp1_platform_data; -struct vsp1_bru; +struct vsp1_brx; struct vsp1_clu; struct vsp1_hgo; struct vsp1_hgt; @@ -78,8 +78,8 @@ struct vsp1_device { struct rcar_fcp_device *fcp; struct device *bus_master; - struct vsp1_bru *brs; - struct vsp1_bru *bru; + struct vsp1_brx *brs; + struct vsp1_brx *bru; struct vsp1_clu *clu; struct vsp1_hgo *hgo; struct vsp1_hgt *hgt; diff --git a/drivers/media/platform/vsp1/vsp1_bru.c b/drivers/media/platform/vsp1/vsp1_brx.c index e8fd2ae3b3eb..b4af1d546022 100644 --- a/drivers/media/platform/vsp1/vsp1_bru.c +++ b/drivers/media/platform/vsp1/vsp1_brx.c @@ -1,5 +1,5 @@ /* - * vsp1_bru.c -- R-Car VSP1 Blend ROP Unit + * vsp1_brx.c -- R-Car VSP1 Blend ROP Unit (BRU and BRS) * * Copyright (C) 2013 Renesas Corporation * @@ -17,45 +17,45 @@ #include <media/v4l2-subdev.h> #include "vsp1.h" -#include "vsp1_bru.h" +#include "vsp1_brx.h" #include "vsp1_dl.h" #include "vsp1_pipe.h" #include "vsp1_rwpf.h" #include "vsp1_video.h" -#define BRU_MIN_SIZE 1U -#define BRU_MAX_SIZE 8190U +#define BRX_MIN_SIZE 1U +#define BRX_MAX_SIZE 8190U /* ----------------------------------------------------------------------------- * Device Access */ -static inline void vsp1_bru_write(struct vsp1_bru *bru, struct vsp1_dl_list *dl, +static inline void vsp1_brx_write(struct vsp1_brx *brx, struct vsp1_dl_list *dl, u32 reg, u32 data) { - vsp1_dl_list_write(dl, bru->base + reg, data); + vsp1_dl_list_write(dl, brx->base + reg, data); } /* ----------------------------------------------------------------------------- * Controls */ -static int bru_s_ctrl(struct v4l2_ctrl *ctrl) +static int brx_s_ctrl(struct v4l2_ctrl *ctrl) { - struct vsp1_bru *bru = - container_of(ctrl->handler, struct vsp1_bru, ctrls); + struct vsp1_brx *brx = + container_of(ctrl->handler, struct vsp1_brx, ctrls); switch (ctrl->id) { case V4L2_CID_BG_COLOR: - bru->bgcolor = ctrl->val; + brx->bgcolor = ctrl->val; break; } return 0; } -static const struct v4l2_ctrl_ops bru_ctrl_ops = { - .s_ctrl = bru_s_ctrl, +static const struct v4l2_ctrl_ops brx_ctrl_ops = { + .s_ctrl = brx_s_ctrl, }; /* ----------------------------------------------------------------------------- @@ -63,12 +63,12 @@ static const struct v4l2_ctrl_ops bru_ctrl_ops = { */ /* - * The BRU can't perform format conversion, all sink and source formats must be + * The BRx can't perform format conversion, all sink and source formats must be * identical. We pick the format on the first sink pad (pad 0) and propagate it * to all other pads. */ -static int bru_enum_mbus_code(struct v4l2_subdev *subdev, +static int brx_enum_mbus_code(struct v4l2_subdev *subdev, struct v4l2_subdev_pad_config *cfg, struct v4l2_subdev_mbus_code_enum *code) { @@ -81,7 +81,7 @@ static int bru_enum_mbus_code(struct v4l2_subdev *subdev, ARRAY_SIZE(codes)); } -static int bru_enum_frame_size(struct v4l2_subdev *subdev, +static int brx_enum_frame_size(struct v4l2_subdev *subdev, struct v4l2_subdev_pad_config *cfg, struct v4l2_subdev_frame_size_enum *fse) { @@ -92,29 +92,29 @@ static int bru_enum_frame_size(struct v4l2_subdev *subdev, fse->code != MEDIA_BUS_FMT_AYUV8_1X32) return -EINVAL; - fse->min_width = BRU_MIN_SIZE; - fse->max_width = BRU_MAX_SIZE; - fse->min_height = BRU_MIN_SIZE; - fse->max_height = BRU_MAX_SIZE; + fse->min_width = BRX_MIN_SIZE; + fse->max_width = BRX_MAX_SIZE; + fse->min_height = BRX_MIN_SIZE; + fse->max_height = BRX_MAX_SIZE; return 0; } -static struct v4l2_rect *bru_get_compose(struct vsp1_bru *bru, +static struct v4l2_rect *brx_get_compose(struct vsp1_brx *brx, struct v4l2_subdev_pad_config *cfg, unsigned int pad) { - return v4l2_subdev_get_try_compose(&bru->entity.subdev, cfg, pad); + return v4l2_subdev_get_try_compose(&brx->entity.subdev, cfg, pad); } -static void bru_try_format(struct vsp1_bru *bru, +static void brx_try_format(struct vsp1_brx *brx, struct v4l2_subdev_pad_config *config, unsigned int pad, struct v4l2_mbus_framefmt *fmt) { struct v4l2_mbus_framefmt *format; switch (pad) { - case BRU_PAD_SINK(0): + case BRX_PAD_SINK(0): /* Default to YUV if the requested format is not supported. */ if (fmt->code != MEDIA_BUS_FMT_ARGB8888_1X32 && fmt->code != MEDIA_BUS_FMT_AYUV8_1X32) @@ -122,46 +122,46 @@ static void bru_try_format(struct vsp1_bru *bru, break; default: - /* The BRU can't perform format conversion. */ - format = vsp1_entity_get_pad_format(&bru->entity, config, - BRU_PAD_SINK(0)); + /* The BRx can't perform format conversion. */ + format = vsp1_entity_get_pad_format(&brx->entity, config, + BRX_PAD_SINK(0)); fmt->code = format->code; break; } - fmt->width = clamp(fmt->width, BRU_MIN_SIZE, BRU_MAX_SIZE); - fmt->height = clamp(fmt->height, BRU_MIN_SIZE, BRU_MAX_SIZE); + fmt->width = clamp(fmt->width, BRX_MIN_SIZE, BRX_MAX_SIZE); + fmt->height = clamp(fmt->height, BRX_MIN_SIZE, BRX_MAX_SIZE); fmt->field = V4L2_FIELD_NONE; fmt->colorspace = V4L2_COLORSPACE_SRGB; } -static int bru_set_format(struct v4l2_subdev *subdev, +static int brx_set_format(struct v4l2_subdev *subdev, struct v4l2_subdev_pad_config *cfg, struct v4l2_subdev_format *fmt) { - struct vsp1_bru *bru = to_bru(subdev); + struct vsp1_brx *brx = to_brx(subdev); struct v4l2_subdev_pad_config *config; struct v4l2_mbus_framefmt *format; int ret = 0; - mutex_lock(&bru->entity.lock); + mutex_lock(&brx->entity.lock); - config = vsp1_entity_get_pad_config(&bru->entity, cfg, fmt->which); + config = vsp1_entity_get_pad_config(&brx->entity, cfg, fmt->which); if (!config) { ret = -EINVAL; goto done; } - bru_try_format(bru, config, fmt->pad, &fmt->format); + brx_try_format(brx, config, fmt->pad, &fmt->format); - format = vsp1_entity_get_pad_format(&bru->entity, config, fmt->pad); + format = vsp1_entity_get_pad_format(&brx->entity, config, fmt->pad); *format = fmt->format; /* Reset the compose rectangle */ - if (fmt->pad != bru->entity.source_pad) { + if (fmt->pad != brx->entity.source_pad) { struct v4l2_rect *compose; - compose = bru_get_compose(bru, config, fmt->pad); + compose = brx_get_compose(brx, config, fmt->pad); compose->left = 0; compose->top = 0; compose->width = format->width; @@ -169,48 +169,48 @@ static int bru_set_format(struct v4l2_subdev *subdev, } /* Propagate the format code to all pads */ - if (fmt->pad == BRU_PAD_SINK(0)) { + if (fmt->pad == BRX_PAD_SINK(0)) { unsigned int i; - for (i = 0; i <= bru->entity.source_pad; ++i) { - format = vsp1_entity_get_pad_format(&bru->entity, + for (i = 0; i <= brx->entity.source_pad; ++i) { + format = vsp1_entity_get_pad_format(&brx->entity, config, i); format->code = fmt->format.code; } } done: - mutex_unlock(&bru->entity.lock); + mutex_unlock(&brx->entity.lock); return ret; } -static int bru_get_selection(struct v4l2_subdev *subdev, +static int brx_get_selection(struct v4l2_subdev *subdev, struct v4l2_subdev_pad_config *cfg, struct v4l2_subdev_selection *sel) { - struct vsp1_bru *bru = to_bru(subdev); + struct vsp1_brx *brx = to_brx(subdev); struct v4l2_subdev_pad_config *config; - if (sel->pad == bru->entity.source_pad) + if (sel->pad == brx->entity.source_pad) return -EINVAL; switch (sel->target) { case V4L2_SEL_TGT_COMPOSE_BOUNDS: sel->r.left = 0; sel->r.top = 0; - sel->r.width = BRU_MAX_SIZE; - sel->r.height = BRU_MAX_SIZE; + sel->r.width = BRX_MAX_SIZE; + sel->r.height = BRX_MAX_SIZE; return 0; case V4L2_SEL_TGT_COMPOSE: - config = vsp1_entity_get_pad_config(&bru->entity, cfg, + config = vsp1_entity_get_pad_config(&brx->entity, cfg, sel->which); if (!config) return -EINVAL; - mutex_lock(&bru->entity.lock); - sel->r = *bru_get_compose(bru, config, sel->pad); - mutex_unlock(&bru->entity.lock); + mutex_lock(&brx->entity.lock); + sel->r = *brx_get_compose(brx, config, sel->pad); + mutex_unlock(&brx->entity.lock); return 0; default: @@ -218,25 +218,25 @@ static int bru_get_selection(struct v4l2_subdev *subdev, } } -static int bru_set_selection(struct v4l2_subdev *subdev, +static int brx_set_selection(struct v4l2_subdev *subdev, struct v4l2_subdev_pad_config *cfg, struct v4l2_subdev_selection *sel) { - struct vsp1_bru *bru = to_bru(subdev); + struct vsp1_brx *brx = to_brx(subdev); struct v4l2_subdev_pad_config *config; struct v4l2_mbus_framefmt *format; struct v4l2_rect *compose; int ret = 0; - if (sel->pad == bru->entity.source_pad) + if (sel->pad == brx->entity.source_pad) return -EINVAL; if (sel->target != V4L2_SEL_TGT_COMPOSE) return -EINVAL; - mutex_lock(&bru->entity.lock); + mutex_lock(&brx->entity.lock); - config = vsp1_entity_get_pad_config(&bru->entity, cfg, sel->which); + config = vsp1_entity_get_pad_config(&brx->entity, cfg, sel->which); if (!config) { ret = -EINVAL; goto done; @@ -246,8 +246,8 @@ static int bru_set_selection(struct v4l2_subdev *subdev, * The compose rectangle top left corner must be inside the output * frame. */ - format = vsp1_entity_get_pad_format(&bru->entity, config, - bru->entity.source_pad); + format = vsp1_entity_get_pad_format(&brx->entity, config, + brx->entity.source_pad); sel->r.left = clamp_t(unsigned int, sel->r.left, 0, format->width - 1); sel->r.top = clamp_t(unsigned int, sel->r.top, 0, format->height - 1); @@ -255,42 +255,42 @@ static int bru_set_selection(struct v4l2_subdev *subdev, * Scaling isn't supported, the compose rectangle size must be identical * to the sink format size. */ - format = vsp1_entity_get_pad_format(&bru->entity, config, sel->pad); + format = vsp1_entity_get_pad_format(&brx->entity, config, sel->pad); sel->r.width = format->width; sel->r.height = format->height; - compose = bru_get_compose(bru, config, sel->pad); + compose = brx_get_compose(brx, config, sel->pad); *compose = sel->r; done: - mutex_unlock(&bru->entity.lock); + mutex_unlock(&brx->entity.lock); return ret; } -static const struct v4l2_subdev_pad_ops bru_pad_ops = { +static const struct v4l2_subdev_pad_ops brx_pad_ops = { .init_cfg = vsp1_entity_init_cfg, - .enum_mbus_code = bru_enum_mbus_code, - .enum_frame_size = bru_enum_frame_size, + .enum_mbus_code = brx_enum_mbus_code, + .enum_frame_size = brx_enum_frame_size, .get_fmt = vsp1_subdev_get_pad_format, - .set_fmt = bru_set_format, - .get_selection = bru_get_selection, - .set_selection = bru_set_selection, + .set_fmt = brx_set_format, + .get_selection = brx_get_selection, + .set_selection = brx_set_selection, }; -static const struct v4l2_subdev_ops bru_ops = { - .pad = &bru_pad_ops, +static const struct v4l2_subdev_ops brx_ops = { + .pad = &brx_pad_ops, }; /* ----------------------------------------------------------------------------- * VSP1 Entity Operations */ -static void bru_configure(struct vsp1_entity *entity, +static void brx_configure(struct vsp1_entity *entity, struct vsp1_pipeline *pipe, struct vsp1_dl_list *dl, enum vsp1_entity_params params) { - struct vsp1_bru *bru = to_bru(&entity->subdev); + struct vsp1_brx *brx = to_brx(&entity->subdev); struct v4l2_mbus_framefmt *format; unsigned int flags; unsigned int i; @@ -298,8 +298,8 @@ static void bru_configure(struct vsp1_entity *entity, if (params != VSP1_ENTITY_PARAMS_INIT) return; - format = vsp1_entity_get_pad_format(&bru->entity, bru->entity.config, - bru->entity.source_pad); + format = vsp1_entity_get_pad_format(&brx->entity, brx->entity.config, + brx->entity.source_pad); /* * The hardware is extremely flexible but we have no userspace API to @@ -313,7 +313,7 @@ static void bru_configure(struct vsp1_entity *entity, * format at the pipeline output is premultiplied. */ flags = pipe->output ? pipe->output->format.flags : 0; - vsp1_bru_write(bru, dl, VI6_BRU_INCTRL, + vsp1_brx_write(brx, dl, VI6_BRU_INCTRL, flags & V4L2_PIX_FMT_FLAG_PREMUL_ALPHA ? 0 : VI6_BRU_INCTRL_NRM); @@ -321,12 +321,12 @@ static void bru_configure(struct vsp1_entity *entity, * Set the background position to cover the whole output image and * configure its color. */ - vsp1_bru_write(bru, dl, VI6_BRU_VIRRPF_SIZE, + vsp1_brx_write(brx, dl, VI6_BRU_VIRRPF_SIZE, (format->width << VI6_BRU_VIRRPF_SIZE_HSIZE_SHIFT) | (format->height << VI6_BRU_VIRRPF_SIZE_VSIZE_SHIFT)); - vsp1_bru_write(bru, dl, VI6_BRU_VIRRPF_LOC, 0); + vsp1_brx_write(brx, dl, VI6_BRU_VIRRPF_LOC, 0); - vsp1_bru_write(bru, dl, VI6_BRU_VIRRPF_COL, bru->bgcolor | + vsp1_brx_write(brx, dl, VI6_BRU_VIRRPF_COL, brx->bgcolor | (0xff << VI6_BRU_VIRRPF_COL_A_SHIFT)); /* @@ -336,25 +336,25 @@ static void bru_configure(struct vsp1_entity *entity, * unit. */ if (entity->type == VSP1_ENTITY_BRU) - vsp1_bru_write(bru, dl, VI6_BRU_ROP, + vsp1_brx_write(brx, dl, VI6_BRU_ROP, VI6_BRU_ROP_DSTSEL_BRUIN(1) | VI6_BRU_ROP_CROP(VI6_ROP_NOP) | VI6_BRU_ROP_AROP(VI6_ROP_NOP)); - for (i = 0; i < bru->entity.source_pad; ++i) { + for (i = 0; i < brx->entity.source_pad; ++i) { bool premultiplied = false; u32 ctrl = 0; /* - * Configure all Blend/ROP units corresponding to an enabled BRU + * Configure all Blend/ROP units corresponding to an enabled BRx * input for alpha blending. Blend/ROP units corresponding to - * disabled BRU inputs are used in ROP NOP mode to ignore the + * disabled BRx inputs are used in ROP NOP mode to ignore the * SRC input. */ - if (bru->inputs[i].rpf) { + if (brx->inputs[i].rpf) { ctrl |= VI6_BRU_CTRL_RBC; - premultiplied = bru->inputs[i].rpf->format.flags + premultiplied = brx->inputs[i].rpf->format.flags & V4L2_PIX_FMT_FLAG_PREMUL_ALPHA; } else { ctrl |= VI6_BRU_CTRL_CROP(VI6_ROP_NOP) @@ -378,7 +378,7 @@ static void bru_configure(struct vsp1_entity *entity, if (!(entity->type == VSP1_ENTITY_BRU && i == 1)) ctrl |= VI6_BRU_CTRL_SRCSEL_BRUIN(i); - vsp1_bru_write(bru, dl, VI6_BRU_CTRL(i), ctrl); + vsp1_brx_write(brx, dl, VI6_BRU_CTRL(i), ctrl); /* * Harcode the blending formula to @@ -393,7 +393,7 @@ static void bru_configure(struct vsp1_entity *entity, * * otherwise. */ - vsp1_bru_write(bru, dl, VI6_BRU_BLD(i), + vsp1_brx_write(brx, dl, VI6_BRU_BLD(i), VI6_BRU_BLD_CCMDX_255_SRC_A | (premultiplied ? VI6_BRU_BLD_CCMDY_COEFY : VI6_BRU_BLD_CCMDY_SRC_A) | @@ -403,29 +403,29 @@ static void bru_configure(struct vsp1_entity *entity, } } -static const struct vsp1_entity_operations bru_entity_ops = { - .configure = bru_configure, +static const struct vsp1_entity_operations brx_entity_ops = { + .configure = brx_configure, }; /* ----------------------------------------------------------------------------- * Initialization and Cleanup */ -struct vsp1_bru *vsp1_bru_create(struct vsp1_device *vsp1, +struct vsp1_brx *vsp1_brx_create(struct vsp1_device *vsp1, enum vsp1_entity_type type) { - struct vsp1_bru *bru; + struct vsp1_brx *brx; unsigned int num_pads; const char *name; int ret; - bru = devm_kzalloc(vsp1->dev, sizeof(*bru), GFP_KERNEL); - if (bru == NULL) + brx = devm_kzalloc(vsp1->dev, sizeof(*brx), GFP_KERNEL); + if (brx == NULL) return ERR_PTR(-ENOMEM); - bru->base = type == VSP1_ENTITY_BRU ? VI6_BRU_BASE : VI6_BRS_BASE; - bru->entity.ops = &bru_entity_ops; - bru->entity.type = type; + brx->base = type == VSP1_ENTITY_BRU ? VI6_BRU_BASE : VI6_BRS_BASE; + brx->entity.ops = &brx_entity_ops; + brx->entity.type = type; if (type == VSP1_ENTITY_BRU) { num_pads = vsp1->info->num_bru_inputs + 1; @@ -435,26 +435,26 @@ struct vsp1_bru *vsp1_bru_create(struct vsp1_device *vsp1, name = "brs"; } - ret = vsp1_entity_init(vsp1, &bru->entity, name, num_pads, &bru_ops, + ret = vsp1_entity_init(vsp1, &brx->entity, name, num_pads, &brx_ops, MEDIA_ENT_F_PROC_VIDEO_COMPOSER); if (ret < 0) return ERR_PTR(ret); /* Initialize the control handler. */ - v4l2_ctrl_handler_init(&bru->ctrls, 1); - v4l2_ctrl_new_std(&bru->ctrls, &bru_ctrl_ops, V4L2_CID_BG_COLOR, + v4l2_ctrl_handler_init(&brx->ctrls, 1); + v4l2_ctrl_new_std(&brx->ctrls, &brx_ctrl_ops, V4L2_CID_BG_COLOR, 0, 0xffffff, 1, 0); - bru->bgcolor = 0; + brx->bgcolor = 0; - bru->entity.subdev.ctrl_handler = &bru->ctrls; + brx->entity.subdev.ctrl_handler = &brx->ctrls; - if (bru->ctrls.error) { + if (brx->ctrls.error) { dev_err(vsp1->dev, "%s: failed to initialize controls\n", name); - ret = bru->ctrls.error; - vsp1_entity_destroy(&bru->entity); + ret = brx->ctrls.error; + vsp1_entity_destroy(&brx->entity); return ERR_PTR(ret); } - return bru; + return brx; } diff --git a/drivers/media/platform/vsp1/vsp1_bru.h b/drivers/media/platform/vsp1/vsp1_brx.h index c98ed96d8de6..927aa4254c0f 100644 --- a/drivers/media/platform/vsp1/vsp1_bru.h +++ b/drivers/media/platform/vsp1/vsp1_brx.h @@ -1,5 +1,5 @@ /* - * vsp1_bru.h -- R-Car VSP1 Blend ROP Unit + * vsp1_brx.h -- R-Car VSP1 Blend ROP Unit (BRU and BRS) * * Copyright (C) 2013 Renesas Corporation * @@ -10,8 +10,8 @@ * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. */ -#ifndef __VSP1_BRU_H__ -#define __VSP1_BRU_H__ +#ifndef __VSP1_BRX_H__ +#define __VSP1_BRX_H__ #include <media/media-entity.h> #include <media/v4l2-ctrls.h> @@ -22,9 +22,9 @@ struct vsp1_device; struct vsp1_rwpf; -#define BRU_PAD_SINK(n) (n) +#define BRX_PAD_SINK(n) (n) -struct vsp1_bru { +struct vsp1_brx { struct vsp1_entity entity; unsigned int base; @@ -37,12 +37,12 @@ struct vsp1_bru { u32 bgcolor; }; -static inline struct vsp1_bru *to_bru(struct v4l2_subdev *subdev) +static inline struct vsp1_brx *to_brx(struct v4l2_subdev *subdev) { - return container_of(subdev, struct vsp1_bru, entity.subdev); + return container_of(subdev, struct vsp1_brx, entity.subdev); } -struct vsp1_bru *vsp1_bru_create(struct vsp1_device *vsp1, +struct vsp1_brx *vsp1_brx_create(struct vsp1_device *vsp1, enum vsp1_entity_type type); -#endif /* __VSP1_BRU_H__ */ +#endif /* __VSP1_BRX_H__ */ diff --git a/drivers/media/platform/vsp1/vsp1_dl.c b/drivers/media/platform/vsp1/vsp1_dl.c index 0b86ed01e85d..30ad491605ff 100644 --- a/drivers/media/platform/vsp1/vsp1_dl.c +++ b/drivers/media/platform/vsp1/vsp1_dl.c @@ -72,6 +72,7 @@ struct vsp1_dl_body { * @fragments: list of extra display list bodies * @has_chain: if true, indicates that there's a partition chain * @chain: entry in the display list partition chain + * @internal: whether the display list is used for internal purpose */ struct vsp1_dl_list { struct list_head list; @@ -85,6 +86,8 @@ struct vsp1_dl_list { bool has_chain; struct list_head chain; + + bool internal; }; enum vsp1_dl_mode { @@ -550,8 +553,16 @@ static void vsp1_dl_list_commit_continuous(struct vsp1_dl_list *dl) * case we can't replace the queued list by the new one, as we could * race with the hardware. We thus mark the update as pending, it will * be queued up to the hardware by the frame end interrupt handler. + * + * If a display list is already pending we simply drop it as the new + * display list is assumed to contain a more recent configuration. It is + * an error if the already pending list has the internal flag set, as + * there is then a process waiting for that list to complete. This + * shouldn't happen as the waiting process should perform proper + * locking, but warn just in case. */ if (vsp1_dl_list_hw_update_pending(dlm)) { + WARN_ON(dlm->pending && dlm->pending->internal); __vsp1_dl_list_put(dlm->pending); dlm->pending = dl; return; @@ -581,7 +592,7 @@ static void vsp1_dl_list_commit_singleshot(struct vsp1_dl_list *dl) dlm->active = dl; } -void vsp1_dl_list_commit(struct vsp1_dl_list *dl) +void vsp1_dl_list_commit(struct vsp1_dl_list *dl, bool internal) { struct vsp1_dl_manager *dlm = dl->dlm; struct vsp1_dl_list *dl_child; @@ -598,6 +609,8 @@ void vsp1_dl_list_commit(struct vsp1_dl_list *dl) } } + dl->internal = internal; + spin_lock_irqsave(&dlm->lock, flags); if (dlm->singleshot) @@ -616,14 +629,22 @@ void vsp1_dl_list_commit(struct vsp1_dl_list *dl) * vsp1_dlm_irq_frame_end - Display list handler for the frame end interrupt * @dlm: the display list manager * - * Return true if the previous display list has completed at frame end, or false - * if it has been delayed by one frame because the display list commit raced - * with the frame end interrupt. The function always returns true in header mode - * as display list processing is then not continuous and races never occur. + * Return a set of flags that indicates display list completion status. + * + * The VSP1_DL_FRAME_END_COMPLETED flag indicates that the previous display list + * has completed at frame end. If the flag is not returned display list + * completion has been delayed by one frame because the display list commit + * raced with the frame end interrupt. The function always returns with the flag + * set in header mode as display list processing is then not continuous and + * races never occur. + * + * The VSP1_DL_FRAME_END_INTERNAL flag indicates that the previous display list + * has completed and had been queued with the internal notification flag. + * Internal notification is only supported for continuous mode. */ -bool vsp1_dlm_irq_frame_end(struct vsp1_dl_manager *dlm) +unsigned int vsp1_dlm_irq_frame_end(struct vsp1_dl_manager *dlm) { - bool completed = false; + unsigned int flags = 0; spin_lock(&dlm->lock); @@ -634,7 +655,7 @@ bool vsp1_dlm_irq_frame_end(struct vsp1_dl_manager *dlm) if (dlm->singleshot) { __vsp1_dl_list_put(dlm->active); dlm->active = NULL; - completed = true; + flags |= VSP1_DL_FRAME_END_COMPLETED; goto done; } @@ -652,10 +673,14 @@ bool vsp1_dlm_irq_frame_end(struct vsp1_dl_manager *dlm) * frame end interrupt. The display list thus becomes active. */ if (dlm->queued) { + if (dlm->queued->internal) + flags |= VSP1_DL_FRAME_END_INTERNAL; + dlm->queued->internal = false; + __vsp1_dl_list_put(dlm->active); dlm->active = dlm->queued; dlm->queued = NULL; - completed = true; + flags |= VSP1_DL_FRAME_END_COMPLETED; } /* @@ -672,7 +697,7 @@ bool vsp1_dlm_irq_frame_end(struct vsp1_dl_manager *dlm) done: spin_unlock(&dlm->lock); - return completed; + return flags; } /* Hardware Setup */ diff --git a/drivers/media/platform/vsp1/vsp1_dl.h b/drivers/media/platform/vsp1/vsp1_dl.h index ee3508172f0a..1a5bbd5ddb7b 100644 --- a/drivers/media/platform/vsp1/vsp1_dl.h +++ b/drivers/media/platform/vsp1/vsp1_dl.h @@ -20,6 +20,9 @@ struct vsp1_dl_fragment; struct vsp1_dl_list; struct vsp1_dl_manager; +#define VSP1_DL_FRAME_END_COMPLETED BIT(0) +#define VSP1_DL_FRAME_END_INTERNAL BIT(1) + void vsp1_dlm_setup(struct vsp1_device *vsp1); struct vsp1_dl_manager *vsp1_dlm_create(struct vsp1_device *vsp1, @@ -27,12 +30,12 @@ struct vsp1_dl_manager *vsp1_dlm_create(struct vsp1_device *vsp1, unsigned int prealloc); void vsp1_dlm_destroy(struct vsp1_dl_manager *dlm); void vsp1_dlm_reset(struct vsp1_dl_manager *dlm); -bool vsp1_dlm_irq_frame_end(struct vsp1_dl_manager *dlm); +unsigned int vsp1_dlm_irq_frame_end(struct vsp1_dl_manager *dlm); struct vsp1_dl_list *vsp1_dl_list_get(struct vsp1_dl_manager *dlm); void vsp1_dl_list_put(struct vsp1_dl_list *dl); void vsp1_dl_list_write(struct vsp1_dl_list *dl, u32 reg, u32 data); -void vsp1_dl_list_commit(struct vsp1_dl_list *dl); +void vsp1_dl_list_commit(struct vsp1_dl_list *dl, bool internal); struct vsp1_dl_body *vsp1_dl_fragment_alloc(struct vsp1_device *vsp1, unsigned int num_entries); diff --git a/drivers/media/platform/vsp1/vsp1_drm.c b/drivers/media/platform/vsp1/vsp1_drm.c index b8fee1834253..095dc48aa25a 100644 --- a/drivers/media/platform/vsp1/vsp1_drm.c +++ b/drivers/media/platform/vsp1/vsp1_drm.c @@ -20,26 +20,454 @@ #include <media/vsp1.h> #include "vsp1.h" -#include "vsp1_bru.h" +#include "vsp1_brx.h" #include "vsp1_dl.h" #include "vsp1_drm.h" #include "vsp1_lif.h" #include "vsp1_pipe.h" #include "vsp1_rwpf.h" -#define BRU_NAME(e) (e)->type == VSP1_ENTITY_BRU ? "BRU" : "BRS" +#define BRX_NAME(e) (e)->type == VSP1_ENTITY_BRU ? "BRU" : "BRS" /* ----------------------------------------------------------------------------- * Interrupt Handling */ static void vsp1_du_pipeline_frame_end(struct vsp1_pipeline *pipe, - bool completed) + unsigned int completion) { struct vsp1_drm_pipeline *drm_pipe = to_vsp1_drm_pipeline(pipe); + bool complete = completion == VSP1_DL_FRAME_END_COMPLETED; if (drm_pipe->du_complete) - drm_pipe->du_complete(drm_pipe->du_private, completed); + drm_pipe->du_complete(drm_pipe->du_private, complete); + + if (completion & VSP1_DL_FRAME_END_INTERNAL) { + drm_pipe->force_brx_release = false; + wake_up(&drm_pipe->wait_queue); + } +} + +/* ----------------------------------------------------------------------------- + * Pipeline Configuration + */ + +/* Setup one RPF and the connected BRx sink pad. */ +static int vsp1_du_pipeline_setup_rpf(struct vsp1_device *vsp1, + struct vsp1_pipeline *pipe, + struct vsp1_rwpf *rpf, + unsigned int brx_input) +{ + struct v4l2_subdev_selection sel; + struct v4l2_subdev_format format; + const struct v4l2_rect *crop; + int ret; + + /* + * Configure the format on the RPF sink pad and propagate it up to the + * BRx sink pad. + */ + crop = &vsp1->drm->inputs[rpf->entity.index].crop; + + memset(&format, 0, sizeof(format)); + format.which = V4L2_SUBDEV_FORMAT_ACTIVE; + format.pad = RWPF_PAD_SINK; + format.format.width = crop->width + crop->left; + format.format.height = crop->height + crop->top; + format.format.code = rpf->fmtinfo->mbus; + format.format.field = V4L2_FIELD_NONE; + + ret = v4l2_subdev_call(&rpf->entity.subdev, pad, set_fmt, NULL, + &format); + if (ret < 0) + return ret; + + dev_dbg(vsp1->dev, + "%s: set format %ux%u (%x) on RPF%u sink\n", + __func__, format.format.width, format.format.height, + format.format.code, rpf->entity.index); + + memset(&sel, 0, sizeof(sel)); + sel.which = V4L2_SUBDEV_FORMAT_ACTIVE; + sel.pad = RWPF_PAD_SINK; + sel.target = V4L2_SEL_TGT_CROP; + sel.r = *crop; + + ret = v4l2_subdev_call(&rpf->entity.subdev, pad, set_selection, NULL, + &sel); + if (ret < 0) + return ret; + + dev_dbg(vsp1->dev, + "%s: set selection (%u,%u)/%ux%u on RPF%u sink\n", + __func__, sel.r.left, sel.r.top, sel.r.width, sel.r.height, + rpf->entity.index); + + /* + * RPF source, hardcode the format to ARGB8888 to turn on format + * conversion if needed. + */ + format.pad = RWPF_PAD_SOURCE; + + ret = v4l2_subdev_call(&rpf->entity.subdev, pad, get_fmt, NULL, + &format); + if (ret < 0) + return ret; + + dev_dbg(vsp1->dev, + "%s: got format %ux%u (%x) on RPF%u source\n", + __func__, format.format.width, format.format.height, + format.format.code, rpf->entity.index); + + format.format.code = MEDIA_BUS_FMT_ARGB8888_1X32; + + ret = v4l2_subdev_call(&rpf->entity.subdev, pad, set_fmt, NULL, + &format); + if (ret < 0) + return ret; + + /* BRx sink, propagate the format from the RPF source. */ + format.pad = brx_input; + + ret = v4l2_subdev_call(&pipe->brx->subdev, pad, set_fmt, NULL, + &format); + if (ret < 0) + return ret; + + dev_dbg(vsp1->dev, "%s: set format %ux%u (%x) on %s pad %u\n", + __func__, format.format.width, format.format.height, + format.format.code, BRX_NAME(pipe->brx), format.pad); + + sel.pad = brx_input; + sel.target = V4L2_SEL_TGT_COMPOSE; + sel.r = vsp1->drm->inputs[rpf->entity.index].compose; + + ret = v4l2_subdev_call(&pipe->brx->subdev, pad, set_selection, NULL, + &sel); + if (ret < 0) + return ret; + + dev_dbg(vsp1->dev, "%s: set selection (%u,%u)/%ux%u on %s pad %u\n", + __func__, sel.r.left, sel.r.top, sel.r.width, sel.r.height, + BRX_NAME(pipe->brx), sel.pad); + + return 0; +} + +/* Setup the BRx source pad. */ +static int vsp1_du_pipeline_setup_inputs(struct vsp1_device *vsp1, + struct vsp1_pipeline *pipe); +static void vsp1_du_pipeline_configure(struct vsp1_pipeline *pipe); + +static int vsp1_du_pipeline_setup_brx(struct vsp1_device *vsp1, + struct vsp1_pipeline *pipe) +{ + struct vsp1_drm_pipeline *drm_pipe = to_vsp1_drm_pipeline(pipe); + struct v4l2_subdev_format format = { + .which = V4L2_SUBDEV_FORMAT_ACTIVE, + }; + struct vsp1_entity *brx; + int ret; + + /* + * Pick a BRx: + * - If we need more than two inputs, use the BRU. + * - Otherwise, if we are not forced to release our BRx, keep it. + * - Else, use any free BRx (randomly starting with the BRU). + */ + if (pipe->num_inputs > 2) + brx = &vsp1->bru->entity; + else if (pipe->brx && !drm_pipe->force_brx_release) + brx = pipe->brx; + else if (!vsp1->bru->entity.pipe) + brx = &vsp1->bru->entity; + else + brx = &vsp1->brs->entity; + + /* Switch BRx if needed. */ + if (brx != pipe->brx) { + struct vsp1_entity *released_brx = NULL; + + /* Release our BRx if we have one. */ + if (pipe->brx) { + dev_dbg(vsp1->dev, "%s: pipe %u: releasing %s\n", + __func__, pipe->lif->index, + BRX_NAME(pipe->brx)); + + /* + * The BRx might be acquired by the other pipeline in + * the next step. We must thus remove it from the list + * of entities for this pipeline. The other pipeline's + * hardware configuration will reconfigure the BRx + * routing. + * + * However, if the other pipeline doesn't acquire our + * BRx, we need to keep it in the list, otherwise the + * hardware configuration step won't disconnect it from + * the pipeline. To solve this, store the released BRx + * pointer to add it back to the list of entities later + * if it isn't acquired by the other pipeline. + */ + released_brx = pipe->brx; + + list_del(&pipe->brx->list_pipe); + pipe->brx->sink = NULL; + pipe->brx->pipe = NULL; + pipe->brx = NULL; + } + + /* + * If the BRx we need is in use, force the owner pipeline to + * switch to the other BRx and wait until the switch completes. + */ + if (brx->pipe) { + struct vsp1_drm_pipeline *owner_pipe; + + dev_dbg(vsp1->dev, "%s: pipe %u: waiting for %s\n", + __func__, pipe->lif->index, BRX_NAME(brx)); + + owner_pipe = to_vsp1_drm_pipeline(brx->pipe); + owner_pipe->force_brx_release = true; + + vsp1_du_pipeline_setup_inputs(vsp1, &owner_pipe->pipe); + vsp1_du_pipeline_configure(&owner_pipe->pipe); + + ret = wait_event_timeout(owner_pipe->wait_queue, + !owner_pipe->force_brx_release, + msecs_to_jiffies(500)); + if (ret == 0) + dev_warn(vsp1->dev, + "DRM pipeline %u reconfiguration timeout\n", + owner_pipe->pipe.lif->index); + } + + /* + * If the BRx we have released previously hasn't been acquired + * by the other pipeline, add it back to the entities list (with + * the pipe pointer NULL) to let vsp1_du_pipeline_configure() + * disconnect it from the hardware pipeline. + */ + if (released_brx && !released_brx->pipe) + list_add_tail(&released_brx->list_pipe, + &pipe->entities); + + /* Add the BRx to the pipeline. */ + dev_dbg(vsp1->dev, "%s: pipe %u: acquired %s\n", + __func__, pipe->lif->index, BRX_NAME(brx)); + + pipe->brx = brx; + pipe->brx->pipe = pipe; + pipe->brx->sink = &pipe->output->entity; + pipe->brx->sink_pad = 0; + + list_add_tail(&pipe->brx->list_pipe, &pipe->entities); + } + + /* + * Configure the format on the BRx source and verify that it matches the + * requested format. We don't set the media bus code as it is configured + * on the BRx sink pad 0 and propagated inside the entity, not on the + * source pad. + */ + format.pad = pipe->brx->source_pad; + format.format.width = drm_pipe->width; + format.format.height = drm_pipe->height; + format.format.field = V4L2_FIELD_NONE; + + ret = v4l2_subdev_call(&pipe->brx->subdev, pad, set_fmt, NULL, + &format); + if (ret < 0) + return ret; + + dev_dbg(vsp1->dev, "%s: set format %ux%u (%x) on %s pad %u\n", + __func__, format.format.width, format.format.height, + format.format.code, BRX_NAME(pipe->brx), pipe->brx->source_pad); + + if (format.format.width != drm_pipe->width || + format.format.height != drm_pipe->height) { + dev_dbg(vsp1->dev, "%s: format mismatch\n", __func__); + return -EPIPE; + } + + return 0; +} + +static unsigned int rpf_zpos(struct vsp1_device *vsp1, struct vsp1_rwpf *rpf) +{ + return vsp1->drm->inputs[rpf->entity.index].zpos; +} + +/* Setup the input side of the pipeline (RPFs and BRx). */ +static int vsp1_du_pipeline_setup_inputs(struct vsp1_device *vsp1, + struct vsp1_pipeline *pipe) +{ + struct vsp1_rwpf *inputs[VSP1_MAX_RPF] = { NULL, }; + struct vsp1_brx *brx; + unsigned int i; + int ret; + + /* Count the number of enabled inputs and sort them by Z-order. */ + pipe->num_inputs = 0; + + for (i = 0; i < vsp1->info->rpf_count; ++i) { + struct vsp1_rwpf *rpf = vsp1->rpf[i]; + unsigned int j; + + if (!pipe->inputs[i]) + continue; + + /* Insert the RPF in the sorted RPFs array. */ + for (j = pipe->num_inputs++; j > 0; --j) { + if (rpf_zpos(vsp1, inputs[j-1]) <= rpf_zpos(vsp1, rpf)) + break; + inputs[j] = inputs[j-1]; + } + + inputs[j] = rpf; + } + + /* + * Setup the BRx. This must be done before setting up the RPF input + * pipelines as the BRx sink compose rectangles depend on the BRx source + * format. + */ + ret = vsp1_du_pipeline_setup_brx(vsp1, pipe); + if (ret < 0) { + dev_err(vsp1->dev, "%s: failed to setup %s source\n", __func__, + BRX_NAME(pipe->brx)); + return ret; + } + + brx = to_brx(&pipe->brx->subdev); + + /* Setup the RPF input pipeline for every enabled input. */ + for (i = 0; i < pipe->brx->source_pad; ++i) { + struct vsp1_rwpf *rpf = inputs[i]; + + if (!rpf) { + brx->inputs[i].rpf = NULL; + continue; + } + + if (!rpf->entity.pipe) { + rpf->entity.pipe = pipe; + list_add_tail(&rpf->entity.list_pipe, &pipe->entities); + } + + brx->inputs[i].rpf = rpf; + rpf->brx_input = i; + rpf->entity.sink = pipe->brx; + rpf->entity.sink_pad = i; + + dev_dbg(vsp1->dev, "%s: connecting RPF.%u to %s:%u\n", + __func__, rpf->entity.index, BRX_NAME(pipe->brx), i); + + ret = vsp1_du_pipeline_setup_rpf(vsp1, pipe, rpf, i); + if (ret < 0) { + dev_err(vsp1->dev, + "%s: failed to setup RPF.%u\n", + __func__, rpf->entity.index); + return ret; + } + } + + return 0; +} + +/* Setup the output side of the pipeline (WPF and LIF). */ +static int vsp1_du_pipeline_setup_output(struct vsp1_device *vsp1, + struct vsp1_pipeline *pipe) +{ + struct vsp1_drm_pipeline *drm_pipe = to_vsp1_drm_pipeline(pipe); + struct v4l2_subdev_format format = { 0, }; + int ret; + + format.which = V4L2_SUBDEV_FORMAT_ACTIVE; + format.pad = RWPF_PAD_SINK; + format.format.width = drm_pipe->width; + format.format.height = drm_pipe->height; + format.format.code = MEDIA_BUS_FMT_ARGB8888_1X32; + format.format.field = V4L2_FIELD_NONE; + + ret = v4l2_subdev_call(&pipe->output->entity.subdev, pad, set_fmt, NULL, + &format); + if (ret < 0) + return ret; + + dev_dbg(vsp1->dev, "%s: set format %ux%u (%x) on WPF%u sink\n", + __func__, format.format.width, format.format.height, + format.format.code, pipe->output->entity.index); + + format.pad = RWPF_PAD_SOURCE; + ret = v4l2_subdev_call(&pipe->output->entity.subdev, pad, get_fmt, NULL, + &format); + if (ret < 0) + return ret; + + dev_dbg(vsp1->dev, "%s: got format %ux%u (%x) on WPF%u source\n", + __func__, format.format.width, format.format.height, + format.format.code, pipe->output->entity.index); + + format.pad = LIF_PAD_SINK; + ret = v4l2_subdev_call(&pipe->lif->subdev, pad, set_fmt, NULL, + &format); + if (ret < 0) + return ret; + + dev_dbg(vsp1->dev, "%s: set format %ux%u (%x) on LIF%u sink\n", + __func__, format.format.width, format.format.height, + format.format.code, pipe->lif->index); + + /* + * Verify that the format at the output of the pipeline matches the + * requested frame size and media bus code. + */ + if (format.format.width != drm_pipe->width || + format.format.height != drm_pipe->height || + format.format.code != MEDIA_BUS_FMT_ARGB8888_1X32) { + dev_dbg(vsp1->dev, "%s: format mismatch on LIF%u\n", __func__, + pipe->lif->index); + return -EPIPE; + } + + return 0; +} + +/* Configure all entities in the pipeline. */ +static void vsp1_du_pipeline_configure(struct vsp1_pipeline *pipe) +{ + struct vsp1_drm_pipeline *drm_pipe = to_vsp1_drm_pipeline(pipe); + struct vsp1_entity *entity; + struct vsp1_entity *next; + struct vsp1_dl_list *dl; + + dl = vsp1_dl_list_get(pipe->output->dlm); + + list_for_each_entry_safe(entity, next, &pipe->entities, list_pipe) { + /* Disconnect unused entities from the pipeline. */ + if (!entity->pipe) { + vsp1_dl_list_write(dl, entity->route->reg, + VI6_DPR_NODE_UNUSED); + + entity->sink = NULL; + list_del(&entity->list_pipe); + + continue; + } + + vsp1_entity_route_setup(entity, pipe, dl); + + if (entity->ops->configure) { + entity->ops->configure(entity, pipe, dl, + VSP1_ENTITY_PARAMS_INIT); + entity->ops->configure(entity, pipe, dl, + VSP1_ENTITY_PARAMS_RUNTIME); + entity->ops->configure(entity, pipe, dl, + VSP1_ENTITY_PARAMS_PARTITION); + } + } + + vsp1_dl_list_commit(dl, drm_pipe->force_brx_release); } /* ----------------------------------------------------------------------------- @@ -64,8 +492,8 @@ EXPORT_SYMBOL_GPL(vsp1_du_init); * @cfg: the LIF configuration * * Configure the output part of VSP DRM pipeline for the given frame @cfg.width - * and @cfg.height. This sets up formats on the blend unit (BRU or BRS) source - * pad, the WPF sink and source pads, and the LIF sink pad. + * and @cfg.height. This sets up formats on the BRx source pad, the WPF sink and + * source pads, and the LIF sink pad. * * The @pipe_index argument selects which DRM pipeline to setup. The number of * available pipelines depend on the VSP instance. @@ -84,11 +512,6 @@ int vsp1_du_setup_lif(struct device *dev, unsigned int pipe_index, struct vsp1_device *vsp1 = dev_get_drvdata(dev); struct vsp1_drm_pipeline *drm_pipe; struct vsp1_pipeline *pipe; - struct vsp1_bru *bru; - struct vsp1_entity *entity; - struct vsp1_entity *next; - struct vsp1_dl_list *dl; - struct v4l2_subdev_format format; unsigned long flags; unsigned int i; int ret; @@ -98,9 +521,14 @@ int vsp1_du_setup_lif(struct device *dev, unsigned int pipe_index, drm_pipe = &vsp1->drm->pipe[pipe_index]; pipe = &drm_pipe->pipe; - bru = to_bru(&pipe->bru->subdev); if (!cfg) { + struct vsp1_brx *brx; + + mutex_lock(&vsp1->drm->lock); + + brx = to_brx(&pipe->brx->subdev); + /* * NULL configuration means the CRTC is being disabled, stop * the pipeline and turn the light off. @@ -109,8 +537,6 @@ int vsp1_du_setup_lif(struct device *dev, unsigned int pipe_index, if (ret == -ETIMEDOUT) dev_err(vsp1->dev, "DRM pipeline stop timeout\n"); - media_pipeline_stop(&pipe->output->entity.subdev.entity); - for (i = 0; i < ARRAY_SIZE(pipe->inputs); ++i) { struct vsp1_rwpf *rpf = pipe->inputs[i]; @@ -118,19 +544,30 @@ int vsp1_du_setup_lif(struct device *dev, unsigned int pipe_index, continue; /* - * Remove the RPF from the pipe and the list of BRU + * Remove the RPF from the pipe and the list of BRx * inputs. */ - WARN_ON(list_empty(&rpf->entity.list_pipe)); - list_del_init(&rpf->entity.list_pipe); + WARN_ON(!rpf->entity.pipe); + rpf->entity.pipe = NULL; + list_del(&rpf->entity.list_pipe); pipe->inputs[i] = NULL; - bru->inputs[rpf->bru_input].rpf = NULL; + brx->inputs[rpf->brx_input].rpf = NULL; } drm_pipe->du_complete = NULL; pipe->num_inputs = 0; + dev_dbg(vsp1->dev, "%s: pipe %u: releasing %s\n", + __func__, pipe->lif->index, + BRX_NAME(pipe->brx)); + + list_del(&pipe->brx->list_pipe); + pipe->brx->pipe = NULL; + pipe->brx = NULL; + + mutex_unlock(&vsp1->drm->lock); + vsp1_dlm_reset(pipe->output->dlm); vsp1_device_put(vsp1); @@ -139,100 +576,27 @@ int vsp1_du_setup_lif(struct device *dev, unsigned int pipe_index, return 0; } + drm_pipe->width = cfg->width; + drm_pipe->height = cfg->height; + dev_dbg(vsp1->dev, "%s: configuring LIF%u with format %ux%u\n", __func__, pipe_index, cfg->width, cfg->height); - /* - * Configure the format at the BRU sinks and propagate it through the - * pipeline. - */ - memset(&format, 0, sizeof(format)); - format.which = V4L2_SUBDEV_FORMAT_ACTIVE; - - for (i = 0; i < pipe->bru->source_pad; ++i) { - format.pad = i; - - format.format.width = cfg->width; - format.format.height = cfg->height; - format.format.code = MEDIA_BUS_FMT_ARGB8888_1X32; - format.format.field = V4L2_FIELD_NONE; - - ret = v4l2_subdev_call(&pipe->bru->subdev, pad, - set_fmt, NULL, &format); - if (ret < 0) - return ret; - - dev_dbg(vsp1->dev, "%s: set format %ux%u (%x) on %s pad %u\n", - __func__, format.format.width, format.format.height, - format.format.code, BRU_NAME(pipe->bru), i); - } - - format.pad = pipe->bru->source_pad; - format.format.width = cfg->width; - format.format.height = cfg->height; - format.format.code = MEDIA_BUS_FMT_ARGB8888_1X32; - format.format.field = V4L2_FIELD_NONE; - - ret = v4l2_subdev_call(&pipe->bru->subdev, pad, set_fmt, NULL, - &format); - if (ret < 0) - return ret; - - dev_dbg(vsp1->dev, "%s: set format %ux%u (%x) on %s pad %u\n", - __func__, format.format.width, format.format.height, - format.format.code, BRU_NAME(pipe->bru), i); + mutex_lock(&vsp1->drm->lock); - format.pad = RWPF_PAD_SINK; - ret = v4l2_subdev_call(&pipe->output->entity.subdev, pad, set_fmt, NULL, - &format); - if (ret < 0) - return ret; - - dev_dbg(vsp1->dev, "%s: set format %ux%u (%x) on WPF%u sink\n", - __func__, format.format.width, format.format.height, - format.format.code, pipe->output->entity.index); - - format.pad = RWPF_PAD_SOURCE; - ret = v4l2_subdev_call(&pipe->output->entity.subdev, pad, get_fmt, NULL, - &format); + /* Setup formats through the pipeline. */ + ret = vsp1_du_pipeline_setup_inputs(vsp1, pipe); if (ret < 0) - return ret; + goto unlock; - dev_dbg(vsp1->dev, "%s: got format %ux%u (%x) on WPF%u source\n", - __func__, format.format.width, format.format.height, - format.format.code, pipe->output->entity.index); - - format.pad = LIF_PAD_SINK; - ret = v4l2_subdev_call(&pipe->lif->subdev, pad, set_fmt, NULL, - &format); + ret = vsp1_du_pipeline_setup_output(vsp1, pipe); if (ret < 0) - return ret; - - dev_dbg(vsp1->dev, "%s: set format %ux%u (%x) on LIF%u sink\n", - __func__, format.format.width, format.format.height, - format.format.code, pipe_index); - - /* - * Verify that the format at the output of the pipeline matches the - * requested frame size and media bus code. - */ - if (format.format.width != cfg->width || - format.format.height != cfg->height || - format.format.code != MEDIA_BUS_FMT_ARGB8888_1X32) { - dev_dbg(vsp1->dev, "%s: format mismatch\n", __func__); - return -EPIPE; - } + goto unlock; - /* - * Mark the pipeline as streaming and enable the VSP1. This will store - * the pipeline pointer in all entities, which the s_stream handlers - * will need. We don't start the entities themselves right at this point - * as there's no plane configured yet, so we can't start processing - * buffers. - */ + /* Enable the VSP1. */ ret = vsp1_device_get(vsp1); if (ret < 0) - return ret; + goto unlock; /* * Register a callback to allow us to notify the DRM driver of frame @@ -241,35 +605,18 @@ int vsp1_du_setup_lif(struct device *dev, unsigned int pipe_index, drm_pipe->du_complete = cfg->callback; drm_pipe->du_private = cfg->callback_data; - ret = media_pipeline_start(&pipe->output->entity.subdev.entity, - &pipe->pipe); - if (ret < 0) { - dev_dbg(vsp1->dev, "%s: pipeline start failed\n", __func__); - vsp1_device_put(vsp1); - return ret; - } - /* Disable the display interrupts. */ vsp1_write(vsp1, VI6_DISP_IRQ_STA, 0); vsp1_write(vsp1, VI6_DISP_IRQ_ENB, 0); /* Configure all entities in the pipeline. */ - dl = vsp1_dl_list_get(pipe->output->dlm); - - list_for_each_entry_safe(entity, next, &pipe->entities, list_pipe) { - vsp1_entity_route_setup(entity, pipe, dl); + vsp1_du_pipeline_configure(pipe); - if (entity->ops->configure) { - entity->ops->configure(entity, pipe, dl, - VSP1_ENTITY_PARAMS_INIT); - entity->ops->configure(entity, pipe, dl, - VSP1_ENTITY_PARAMS_RUNTIME); - entity->ops->configure(entity, pipe, dl, - VSP1_ENTITY_PARAMS_PARTITION); - } - } +unlock: + mutex_unlock(&vsp1->drm->lock); - vsp1_dl_list_commit(dl); + if (ret < 0) + return ret; /* Start the pipeline. */ spin_lock_irqsave(&pipe->irqlock, flags); @@ -290,9 +637,8 @@ EXPORT_SYMBOL_GPL(vsp1_du_setup_lif); void vsp1_du_atomic_begin(struct device *dev, unsigned int pipe_index) { struct vsp1_device *vsp1 = dev_get_drvdata(dev); - struct vsp1_drm_pipeline *drm_pipe = &vsp1->drm->pipe[pipe_index]; - drm_pipe->enabled = drm_pipe->pipe.num_inputs != 0; + mutex_lock(&vsp1->drm->lock); } EXPORT_SYMBOL_GPL(vsp1_du_atomic_begin); @@ -345,10 +691,11 @@ int vsp1_du_atomic_update(struct device *dev, unsigned int pipe_index, rpf_index); /* - * Remove the RPF from the pipe's inputs. The atomic flush - * handler will disable the input and remove the entity from the - * pipe's entities list. + * Remove the RPF from the pipeline's inputs. Keep it in the + * pipeline's entity list to let vsp1_du_pipeline_configure() + * remove it from the hardware pipeline. */ + rpf->entity.pipe = NULL; drm_pipe->pipe.inputs[rpf_index] = NULL; return 0; } @@ -392,111 +739,6 @@ int vsp1_du_atomic_update(struct device *dev, unsigned int pipe_index, } EXPORT_SYMBOL_GPL(vsp1_du_atomic_update); -static int vsp1_du_setup_rpf_pipe(struct vsp1_device *vsp1, - struct vsp1_pipeline *pipe, - struct vsp1_rwpf *rpf, unsigned int bru_input) -{ - struct v4l2_subdev_selection sel; - struct v4l2_subdev_format format; - const struct v4l2_rect *crop; - int ret; - - /* - * Configure the format on the RPF sink pad and propagate it up to the - * BRU sink pad. - */ - crop = &vsp1->drm->inputs[rpf->entity.index].crop; - - memset(&format, 0, sizeof(format)); - format.which = V4L2_SUBDEV_FORMAT_ACTIVE; - format.pad = RWPF_PAD_SINK; - format.format.width = crop->width + crop->left; - format.format.height = crop->height + crop->top; - format.format.code = rpf->fmtinfo->mbus; - format.format.field = V4L2_FIELD_NONE; - - ret = v4l2_subdev_call(&rpf->entity.subdev, pad, set_fmt, NULL, - &format); - if (ret < 0) - return ret; - - dev_dbg(vsp1->dev, - "%s: set format %ux%u (%x) on RPF%u sink\n", - __func__, format.format.width, format.format.height, - format.format.code, rpf->entity.index); - - memset(&sel, 0, sizeof(sel)); - sel.which = V4L2_SUBDEV_FORMAT_ACTIVE; - sel.pad = RWPF_PAD_SINK; - sel.target = V4L2_SEL_TGT_CROP; - sel.r = *crop; - - ret = v4l2_subdev_call(&rpf->entity.subdev, pad, set_selection, NULL, - &sel); - if (ret < 0) - return ret; - - dev_dbg(vsp1->dev, - "%s: set selection (%u,%u)/%ux%u on RPF%u sink\n", - __func__, sel.r.left, sel.r.top, sel.r.width, sel.r.height, - rpf->entity.index); - - /* - * RPF source, hardcode the format to ARGB8888 to turn on format - * conversion if needed. - */ - format.pad = RWPF_PAD_SOURCE; - - ret = v4l2_subdev_call(&rpf->entity.subdev, pad, get_fmt, NULL, - &format); - if (ret < 0) - return ret; - - dev_dbg(vsp1->dev, - "%s: got format %ux%u (%x) on RPF%u source\n", - __func__, format.format.width, format.format.height, - format.format.code, rpf->entity.index); - - format.format.code = MEDIA_BUS_FMT_ARGB8888_1X32; - - ret = v4l2_subdev_call(&rpf->entity.subdev, pad, set_fmt, NULL, - &format); - if (ret < 0) - return ret; - - /* BRU sink, propagate the format from the RPF source. */ - format.pad = bru_input; - - ret = v4l2_subdev_call(&pipe->bru->subdev, pad, set_fmt, NULL, - &format); - if (ret < 0) - return ret; - - dev_dbg(vsp1->dev, "%s: set format %ux%u (%x) on %s pad %u\n", - __func__, format.format.width, format.format.height, - format.format.code, BRU_NAME(pipe->bru), format.pad); - - sel.pad = bru_input; - sel.target = V4L2_SEL_TGT_COMPOSE; - sel.r = vsp1->drm->inputs[rpf->entity.index].compose; - - ret = v4l2_subdev_call(&pipe->bru->subdev, pad, set_selection, NULL, - &sel); - if (ret < 0) - return ret; - - dev_dbg(vsp1->dev, "%s: set selection (%u,%u)/%ux%u on %s pad %u\n", - __func__, sel.r.left, sel.r.top, sel.r.width, sel.r.height, - BRU_NAME(pipe->bru), sel.pad); - - return 0; -} - -static unsigned int rpf_zpos(struct vsp1_device *vsp1, struct vsp1_rwpf *rpf) -{ - return vsp1->drm->inputs[rpf->entity.index].zpos; -} - /** * vsp1_du_atomic_flush - Commit an atomic update * @dev: the VSP device @@ -507,99 +749,10 @@ void vsp1_du_atomic_flush(struct device *dev, unsigned int pipe_index) struct vsp1_device *vsp1 = dev_get_drvdata(dev); struct vsp1_drm_pipeline *drm_pipe = &vsp1->drm->pipe[pipe_index]; struct vsp1_pipeline *pipe = &drm_pipe->pipe; - struct vsp1_rwpf *inputs[VSP1_MAX_RPF] = { NULL, }; - struct vsp1_bru *bru = to_bru(&pipe->bru->subdev); - struct vsp1_entity *entity; - struct vsp1_entity *next; - struct vsp1_dl_list *dl; - unsigned int i; - int ret; - - /* Prepare the display list. */ - dl = vsp1_dl_list_get(pipe->output->dlm); - - /* Count the number of enabled inputs and sort them by Z-order. */ - pipe->num_inputs = 0; - for (i = 0; i < vsp1->info->rpf_count; ++i) { - struct vsp1_rwpf *rpf = vsp1->rpf[i]; - unsigned int j; - - /* - * Make sure we don't accept more inputs than the hardware can - * handle. This is a temporary fix to avoid display stall, we - * need to instead allocate the BRU or BRS to display pipelines - * dynamically based on the number of planes they each use. - */ - if (pipe->num_inputs >= pipe->bru->source_pad) - pipe->inputs[i] = NULL; - - if (!pipe->inputs[i]) - continue; - - /* Insert the RPF in the sorted RPFs array. */ - for (j = pipe->num_inputs++; j > 0; --j) { - if (rpf_zpos(vsp1, inputs[j-1]) <= rpf_zpos(vsp1, rpf)) - break; - inputs[j] = inputs[j-1]; - } - - inputs[j] = rpf; - } - - /* Setup the RPF input pipeline for every enabled input. */ - for (i = 0; i < pipe->bru->source_pad; ++i) { - struct vsp1_rwpf *rpf = inputs[i]; - - if (!rpf) { - bru->inputs[i].rpf = NULL; - continue; - } - - if (list_empty(&rpf->entity.list_pipe)) - list_add_tail(&rpf->entity.list_pipe, &pipe->entities); - - bru->inputs[i].rpf = rpf; - rpf->bru_input = i; - rpf->entity.sink = pipe->bru; - rpf->entity.sink_pad = i; - - dev_dbg(vsp1->dev, "%s: connecting RPF.%u to %s:%u\n", - __func__, rpf->entity.index, BRU_NAME(pipe->bru), i); - - ret = vsp1_du_setup_rpf_pipe(vsp1, pipe, rpf, i); - if (ret < 0) - dev_err(vsp1->dev, - "%s: failed to setup RPF.%u\n", - __func__, rpf->entity.index); - } - - /* Configure all entities in the pipeline. */ - list_for_each_entry_safe(entity, next, &pipe->entities, list_pipe) { - /* Disconnect unused RPFs from the pipeline. */ - if (entity->type == VSP1_ENTITY_RPF && - !pipe->inputs[entity->index]) { - vsp1_dl_list_write(dl, entity->route->reg, - VI6_DPR_NODE_UNUSED); - - list_del_init(&entity->list_pipe); - - continue; - } - - vsp1_entity_route_setup(entity, pipe, dl); - - if (entity->ops->configure) { - entity->ops->configure(entity, pipe, dl, - VSP1_ENTITY_PARAMS_INIT); - entity->ops->configure(entity, pipe, dl, - VSP1_ENTITY_PARAMS_RUNTIME); - entity->ops->configure(entity, pipe, dl, - VSP1_ENTITY_PARAMS_PARTITION); - } - } - - vsp1_dl_list_commit(dl); + vsp1_du_pipeline_setup_inputs(vsp1, pipe); + vsp1_du_pipeline_configure(pipe); + mutex_unlock(&vsp1->drm->lock); } EXPORT_SYMBOL_GPL(vsp1_du_atomic_flush); @@ -638,31 +791,33 @@ int vsp1_drm_init(struct vsp1_device *vsp1) if (!vsp1->drm) return -ENOMEM; + mutex_init(&vsp1->drm->lock); + /* Create one DRM pipeline per LIF. */ for (i = 0; i < vsp1->info->lif_count; ++i) { struct vsp1_drm_pipeline *drm_pipe = &vsp1->drm->pipe[i]; struct vsp1_pipeline *pipe = &drm_pipe->pipe; + init_waitqueue_head(&drm_pipe->wait_queue); + vsp1_pipeline_init(pipe); + pipe->frame_end = vsp1_du_pipeline_frame_end; + /* - * The DRM pipeline is static, add entities manually. The first - * pipeline uses the BRU and the second pipeline the BRS. + * The output side of the DRM pipeline is static, add the + * corresponding entities manually. */ - pipe->bru = i == 0 ? &vsp1->bru->entity : &vsp1->brs->entity; - pipe->lif = &vsp1->lif[i]->entity; pipe->output = vsp1->wpf[i]; - pipe->output->pipe = pipe; - pipe->frame_end = vsp1_du_pipeline_frame_end; + pipe->lif = &vsp1->lif[i]->entity; - pipe->bru->sink = &pipe->output->entity; - pipe->bru->sink_pad = 0; + pipe->output->entity.pipe = pipe; pipe->output->entity.sink = pipe->lif; pipe->output->entity.sink_pad = 0; + list_add_tail(&pipe->output->entity.list_pipe, &pipe->entities); - list_add_tail(&pipe->bru->list_pipe, &pipe->entities); + pipe->lif->pipe = pipe; list_add_tail(&pipe->lif->list_pipe, &pipe->entities); - list_add_tail(&pipe->output->entity.list_pipe, &pipe->entities); } /* Disable all RPFs initially. */ @@ -677,4 +832,5 @@ int vsp1_drm_init(struct vsp1_device *vsp1) void vsp1_drm_cleanup(struct vsp1_device *vsp1) { + mutex_destroy(&vsp1->drm->lock); } diff --git a/drivers/media/platform/vsp1/vsp1_drm.h b/drivers/media/platform/vsp1/vsp1_drm.h index 1cd9db785bf7..d738cc57f0e3 100644 --- a/drivers/media/platform/vsp1/vsp1_drm.h +++ b/drivers/media/platform/vsp1/vsp1_drm.h @@ -13,20 +13,30 @@ #ifndef __VSP1_DRM_H__ #define __VSP1_DRM_H__ +#include <linux/mutex.h> #include <linux/videodev2.h> +#include <linux/wait.h> #include "vsp1_pipe.h" /** * vsp1_drm_pipeline - State for the API exposed to the DRM driver * @pipe: the VSP1 pipeline used for display - * @enabled: pipeline state at the beginning of an update + * @width: output display width + * @height: output display height + * @force_brx_release: when set, release the BRx during the next reconfiguration + * @wait_queue: wait queue to wait for BRx release completion * @du_complete: frame completion callback for the DU driver (optional) * @du_private: data to be passed to the du_complete callback */ struct vsp1_drm_pipeline { struct vsp1_pipeline pipe; - bool enabled; + + unsigned int width; + unsigned int height; + + bool force_brx_release; + wait_queue_head_t wait_queue; /* Frame synchronisation */ void (*du_complete)(void *, bool); @@ -36,11 +46,13 @@ struct vsp1_drm_pipeline { /** * vsp1_drm - State for the API exposed to the DRM driver * @pipe: the VSP1 DRM pipeline used for display + * @lock: protects the BRU and BRS allocation * @inputs: source crop rectangle, destination compose rectangle and z-order * position for every input (indexed by RPF index) */ struct vsp1_drm { struct vsp1_drm_pipeline pipe[VSP1_MAX_LIF]; + struct mutex lock; struct { struct v4l2_rect crop; diff --git a/drivers/media/platform/vsp1/vsp1_drv.c b/drivers/media/platform/vsp1/vsp1_drv.c index eed9516e25e1..f41cd70409db 100644 --- a/drivers/media/platform/vsp1/vsp1_drv.c +++ b/drivers/media/platform/vsp1/vsp1_drv.c @@ -26,7 +26,7 @@ #include <media/v4l2-subdev.h> #include "vsp1.h" -#include "vsp1_bru.h" +#include "vsp1_brx.h" #include "vsp1_clu.h" #include "vsp1_dl.h" #include "vsp1_drm.h" @@ -63,7 +63,7 @@ static irqreturn_t vsp1_irq_handler(int irq, void *data) vsp1_write(vsp1, VI6_WPF_IRQ_STA(i), ~status & mask); if (status & VI6_WFP_IRQ_STA_DFE) { - vsp1_pipeline_frame_end(wpf->pipe); + vsp1_pipeline_frame_end(wpf->entity.pipe); ret = IRQ_HANDLED; } } @@ -269,7 +269,7 @@ static int vsp1_create_entities(struct vsp1_device *vsp1) /* Instantiate all the entities. */ if (vsp1->info->features & VSP1_HAS_BRS) { - vsp1->brs = vsp1_bru_create(vsp1, VSP1_ENTITY_BRS); + vsp1->brs = vsp1_brx_create(vsp1, VSP1_ENTITY_BRS); if (IS_ERR(vsp1->brs)) { ret = PTR_ERR(vsp1->brs); goto done; @@ -279,7 +279,7 @@ static int vsp1_create_entities(struct vsp1_device *vsp1) } if (vsp1->info->features & VSP1_HAS_BRU) { - vsp1->bru = vsp1_bru_create(vsp1, VSP1_ENTITY_BRU); + vsp1->bru = vsp1_brx_create(vsp1, VSP1_ENTITY_BRU); if (IS_ERR(vsp1->bru)) { ret = PTR_ERR(vsp1->bru); goto done; diff --git a/drivers/media/platform/vsp1/vsp1_entity.h b/drivers/media/platform/vsp1/vsp1_entity.h index 408602ebeb97..c26523c56c05 100644 --- a/drivers/media/platform/vsp1/vsp1_entity.h +++ b/drivers/media/platform/vsp1/vsp1_entity.h @@ -106,6 +106,8 @@ struct vsp1_entity { unsigned int index; const struct vsp1_route *route; + struct vsp1_pipeline *pipe; + struct list_head list_dev; struct list_head list_pipe; diff --git a/drivers/media/platform/vsp1/vsp1_histo.c b/drivers/media/platform/vsp1/vsp1_histo.c index afab77cf4fa5..8638ebc514b4 100644 --- a/drivers/media/platform/vsp1/vsp1_histo.c +++ b/drivers/media/platform/vsp1/vsp1_histo.c @@ -61,7 +61,7 @@ void vsp1_histogram_buffer_complete(struct vsp1_histogram *histo, struct vsp1_histogram_buffer *buf, size_t size) { - struct vsp1_pipeline *pipe = histo->pipe; + struct vsp1_pipeline *pipe = histo->entity.pipe; unsigned long flags; /* diff --git a/drivers/media/platform/vsp1/vsp1_histo.h b/drivers/media/platform/vsp1/vsp1_histo.h index af2874f6031d..e774adbf251f 100644 --- a/drivers/media/platform/vsp1/vsp1_histo.h +++ b/drivers/media/platform/vsp1/vsp1_histo.h @@ -25,7 +25,6 @@ #include "vsp1_entity.h" struct vsp1_device; -struct vsp1_pipeline; #define HISTO_PAD_SINK 0 #define HISTO_PAD_SOURCE 1 @@ -37,8 +36,6 @@ struct vsp1_histogram_buffer { }; struct vsp1_histogram { - struct vsp1_pipeline *pipe; - struct vsp1_entity entity; struct video_device video; struct media_pad pad; diff --git a/drivers/media/platform/vsp1/vsp1_pipe.c b/drivers/media/platform/vsp1/vsp1_pipe.c index 44944ac86d9b..3fc5ecfa35e8 100644 --- a/drivers/media/platform/vsp1/vsp1_pipe.c +++ b/drivers/media/platform/vsp1/vsp1_pipe.c @@ -20,7 +20,7 @@ #include <media/v4l2-subdev.h> #include "vsp1.h" -#include "vsp1_bru.h" +#include "vsp1_brx.h" #include "vsp1_dl.h" #include "vsp1_entity.h" #include "vsp1_hgo.h" @@ -185,44 +185,29 @@ const struct vsp1_format_info *vsp1_get_format_info(struct vsp1_device *vsp1, void vsp1_pipeline_reset(struct vsp1_pipeline *pipe) { + struct vsp1_entity *entity; unsigned int i; - if (pipe->bru) { - struct vsp1_bru *bru = to_bru(&pipe->bru->subdev); + if (pipe->brx) { + struct vsp1_brx *brx = to_brx(&pipe->brx->subdev); - for (i = 0; i < ARRAY_SIZE(bru->inputs); ++i) - bru->inputs[i].rpf = NULL; + for (i = 0; i < ARRAY_SIZE(brx->inputs); ++i) + brx->inputs[i].rpf = NULL; } - for (i = 0; i < ARRAY_SIZE(pipe->inputs); ++i) { - if (pipe->inputs[i]) { - pipe->inputs[i]->pipe = NULL; - pipe->inputs[i] = NULL; - } - } - - if (pipe->output) { - pipe->output->pipe = NULL; - pipe->output = NULL; - } + for (i = 0; i < ARRAY_SIZE(pipe->inputs); ++i) + pipe->inputs[i] = NULL; - if (pipe->hgo) { - struct vsp1_hgo *hgo = to_hgo(&pipe->hgo->subdev); + pipe->output = NULL; - hgo->histo.pipe = NULL; - } - - if (pipe->hgt) { - struct vsp1_hgt *hgt = to_hgt(&pipe->hgt->subdev); - - hgt->histo.pipe = NULL; - } + list_for_each_entry(entity, &pipe->entities, list_pipe) + entity->pipe = NULL; INIT_LIST_HEAD(&pipe->entities); pipe->state = VSP1_PIPELINE_STOPPED; pipe->buffers_ready = 0; pipe->num_inputs = 0; - pipe->bru = NULL; + pipe->brx = NULL; pipe->hgo = NULL; pipe->hgt = NULL; pipe->lif = NULL; @@ -330,17 +315,17 @@ bool vsp1_pipeline_ready(struct vsp1_pipeline *pipe) void vsp1_pipeline_frame_end(struct vsp1_pipeline *pipe) { - bool completed; + unsigned int flags; if (pipe == NULL) return; /* * If the DL commit raced with the frame end interrupt, the commit ends - * up being postponed by one frame. @completed represents whether the + * up being postponed by one frame. The returned flags tell whether the * active frame was finished or postponed. */ - completed = vsp1_dlm_irq_frame_end(pipe->output->dlm); + flags = vsp1_dlm_irq_frame_end(pipe->output->dlm); if (pipe->hgo) vsp1_hgo_frame_end(pipe->hgo); @@ -353,7 +338,7 @@ void vsp1_pipeline_frame_end(struct vsp1_pipeline *pipe) * frame_end to account for vblank events. */ if (pipe->frame_end) - pipe->frame_end(pipe, completed); + pipe->frame_end(pipe, flags); pipe->sequence++; } @@ -423,7 +408,7 @@ void vsp1_pipelines_suspend(struct vsp1_device *vsp1) if (wpf == NULL) continue; - pipe = wpf->pipe; + pipe = wpf->entity.pipe; if (pipe == NULL) continue; @@ -440,7 +425,7 @@ void vsp1_pipelines_suspend(struct vsp1_device *vsp1) if (wpf == NULL) continue; - pipe = wpf->pipe; + pipe = wpf->entity.pipe; if (pipe == NULL) continue; @@ -465,7 +450,7 @@ void vsp1_pipelines_resume(struct vsp1_device *vsp1) if (wpf == NULL) continue; - pipe = wpf->pipe; + pipe = wpf->entity.pipe; if (pipe == NULL) continue; diff --git a/drivers/media/platform/vsp1/vsp1_pipe.h b/drivers/media/platform/vsp1/vsp1_pipe.h index dfff9b5685fe..07ccd6b810c5 100644 --- a/drivers/media/platform/vsp1/vsp1_pipe.h +++ b/drivers/media/platform/vsp1/vsp1_pipe.h @@ -99,7 +99,7 @@ struct vsp1_partition { * @num_inputs: number of RPFs * @inputs: array of RPFs in the pipeline (indexed by RPF index) * @output: WPF at the output of the pipeline - * @bru: BRU entity, if present + * @brx: BRx entity, if present * @hgo: HGO entity, if present * @hgt: HGT entity, if present * @lif: LIF entity, if present @@ -118,7 +118,7 @@ struct vsp1_pipeline { enum vsp1_pipeline_state state; wait_queue_head_t wq; - void (*frame_end)(struct vsp1_pipeline *pipe, bool completed); + void (*frame_end)(struct vsp1_pipeline *pipe, unsigned int completion); struct mutex lock; struct kref kref; @@ -129,7 +129,7 @@ struct vsp1_pipeline { unsigned int num_inputs; struct vsp1_rwpf *inputs[VSP1_MAX_RPF]; struct vsp1_rwpf *output; - struct vsp1_entity *bru; + struct vsp1_entity *brx; struct vsp1_entity *hgo; struct vsp1_entity *hgt; struct vsp1_entity *lif; diff --git a/drivers/media/platform/vsp1/vsp1_rpf.c b/drivers/media/platform/vsp1/vsp1_rpf.c index fe0633da5a5f..7e74c2015070 100644 --- a/drivers/media/platform/vsp1/vsp1_rpf.c +++ b/drivers/media/platform/vsp1/vsp1_rpf.c @@ -167,12 +167,12 @@ static void rpf_configure(struct vsp1_entity *entity, vsp1_rpf_write(rpf, dl, VI6_RPF_DSWAP, fmtinfo->swap); /* Output location */ - if (pipe->bru) { + if (pipe->brx) { const struct v4l2_rect *compose; - compose = vsp1_entity_get_pad_selection(pipe->bru, - pipe->bru->config, - rpf->bru_input, + compose = vsp1_entity_get_pad_selection(pipe->brx, + pipe->brx->config, + rpf->brx_input, V4L2_SEL_TGT_COMPOSE); left = compose->left; top = compose->top; @@ -191,10 +191,10 @@ static void rpf_configure(struct vsp1_entity *entity, * alpha channel by a fixed global alpha value, and multiply the pixel * components to convert the input to premultiplied alpha. * - * As alpha premultiplication is available in the BRU for both Gen2 and + * As alpha premultiplication is available in the BRx for both Gen2 and * Gen3 we handle it there and use the Gen3 alpha multiplier for global * alpha multiplication only. This however prevents conversion to - * premultiplied alpha if no BRU is present in the pipeline. If that use + * premultiplied alpha if no BRx is present in the pipeline. If that use * case turns out to be useful we will revisit the implementation (for * Gen3 only). * diff --git a/drivers/media/platform/vsp1/vsp1_rwpf.h b/drivers/media/platform/vsp1/vsp1_rwpf.h index 58215a7ab631..915aeadb21dd 100644 --- a/drivers/media/platform/vsp1/vsp1_rwpf.h +++ b/drivers/media/platform/vsp1/vsp1_rwpf.h @@ -27,7 +27,6 @@ struct v4l2_ctrl; struct vsp1_dl_manager; -struct vsp1_pipeline; struct vsp1_rwpf; struct vsp1_video; @@ -39,7 +38,6 @@ struct vsp1_rwpf { struct vsp1_entity entity; struct v4l2_ctrl_handler ctrls; - struct vsp1_pipeline *pipe; struct vsp1_video *video; unsigned int max_width; @@ -47,7 +45,7 @@ struct vsp1_rwpf { struct v4l2_pix_format_mplane format; const struct vsp1_format_info *fmtinfo; - unsigned int bru_input; + unsigned int brx_input; unsigned int alpha; diff --git a/drivers/media/platform/vsp1/vsp1_video.c b/drivers/media/platform/vsp1/vsp1_video.c index c2d3b8f0f487..2b1c94ffc6f5 100644 --- a/drivers/media/platform/vsp1/vsp1_video.c +++ b/drivers/media/platform/vsp1/vsp1_video.c @@ -28,7 +28,7 @@ #include <media/videobuf2-dma-contig.h> #include "vsp1.h" -#include "vsp1_bru.h" +#include "vsp1_brx.h" #include "vsp1_dl.h" #include "vsp1_entity.h" #include "vsp1_hgo.h" @@ -324,7 +324,7 @@ static int vsp1_video_pipeline_setup_partitions(struct vsp1_pipeline *pipe) static struct vsp1_vb2_buffer * vsp1_video_complete_buffer(struct vsp1_video *video) { - struct vsp1_pipeline *pipe = video->rwpf->pipe; + struct vsp1_pipeline *pipe = video->rwpf->entity.pipe; struct vsp1_vb2_buffer *next = NULL; struct vsp1_vb2_buffer *done; unsigned long flags; @@ -437,14 +437,14 @@ static void vsp1_video_pipeline_run(struct vsp1_pipeline *pipe) } /* Complete, and commit the head display list. */ - vsp1_dl_list_commit(pipe->dl); + vsp1_dl_list_commit(pipe->dl, false); pipe->dl = NULL; vsp1_pipeline_run(pipe); } static void vsp1_video_pipeline_frame_end(struct vsp1_pipeline *pipe, - bool completed) + unsigned int completion) { struct vsp1_device *vsp1 = pipe->output->entity.vsp1; enum vsp1_pipeline_state state; @@ -452,7 +452,7 @@ static void vsp1_video_pipeline_frame_end(struct vsp1_pipeline *pipe, unsigned int i; /* M2M Pipelines should never call here with an incomplete frame. */ - WARN_ON_ONCE(!completed); + WARN_ON_ONCE(!(completion & VSP1_DL_FRAME_END_COMPLETED)); spin_lock_irqsave(&pipe->irqlock, flags); @@ -488,7 +488,7 @@ static int vsp1_video_pipeline_build_branch(struct vsp1_pipeline *pipe, struct media_entity_enum ent_enum; struct vsp1_entity *entity; struct media_pad *pad; - struct vsp1_bru *bru = NULL; + struct vsp1_brx *brx = NULL; int ret; ret = media_entity_enum_init(&ent_enum, &input->entity.vsp1->media_dev); @@ -524,14 +524,14 @@ static int vsp1_video_pipeline_build_branch(struct vsp1_pipeline *pipe, if (entity->type == VSP1_ENTITY_BRU || entity->type == VSP1_ENTITY_BRS) { /* BRU and BRS can't be chained. */ - if (bru) { + if (brx) { ret = -EPIPE; goto out; } - bru = to_bru(&entity->subdev); - bru->inputs[pad->index].rpf = input; - input->bru_input = pad->index; + brx = to_brx(&entity->subdev); + brx->inputs[pad->index].rpf = input; + input->brx_input = pad->index; } /* We've reached the WPF, we're done. */ @@ -553,7 +553,7 @@ static int vsp1_video_pipeline_build_branch(struct vsp1_pipeline *pipe, } pipe->uds = entity; - pipe->uds_input = bru ? &bru->entity : &input->entity; + pipe->uds_input = brx ? &brx->entity : &input->entity; } /* Follow the source link, ignoring any HGO or HGT. */ @@ -598,20 +598,19 @@ static int vsp1_video_pipeline_build(struct vsp1_pipeline *pipe, subdev = media_entity_to_v4l2_subdev(entity); e = to_vsp1_entity(subdev); list_add_tail(&e->list_pipe, &pipe->entities); + e->pipe = pipe; switch (e->type) { case VSP1_ENTITY_RPF: rwpf = to_rwpf(subdev); pipe->inputs[rwpf->entity.index] = rwpf; rwpf->video->pipe_index = ++pipe->num_inputs; - rwpf->pipe = pipe; break; case VSP1_ENTITY_WPF: rwpf = to_rwpf(subdev); pipe->output = rwpf; rwpf->video->pipe_index = 0; - rwpf->pipe = pipe; break; case VSP1_ENTITY_LIF: @@ -620,17 +619,15 @@ static int vsp1_video_pipeline_build(struct vsp1_pipeline *pipe, case VSP1_ENTITY_BRU: case VSP1_ENTITY_BRS: - pipe->bru = e; + pipe->brx = e; break; case VSP1_ENTITY_HGO: pipe->hgo = e; - to_hgo(subdev)->histo.pipe = pipe; break; case VSP1_ENTITY_HGT: pipe->hgt = e; - to_hgt(subdev)->histo.pipe = pipe; break; default: @@ -682,7 +679,7 @@ static struct vsp1_pipeline *vsp1_video_pipeline_get(struct vsp1_video *video) * Otherwise allocate a new pipeline and initialize it, it will be freed * when the last reference is released. */ - if (!video->rwpf->pipe) { + if (!video->rwpf->entity.pipe) { pipe = kzalloc(sizeof(*pipe), GFP_KERNEL); if (!pipe) return ERR_PTR(-ENOMEM); @@ -694,7 +691,7 @@ static struct vsp1_pipeline *vsp1_video_pipeline_get(struct vsp1_video *video) return ERR_PTR(ret); } } else { - pipe = video->rwpf->pipe; + pipe = video->rwpf->entity.pipe; kref_get(&pipe->kref); } @@ -777,7 +774,7 @@ static void vsp1_video_buffer_queue(struct vb2_buffer *vb) { struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb); struct vsp1_video *video = vb2_get_drv_priv(vb->vb2_queue); - struct vsp1_pipeline *pipe = video->rwpf->pipe; + struct vsp1_pipeline *pipe = video->rwpf->entity.pipe; struct vsp1_vb2_buffer *buf = to_vsp1_vb2_buffer(vbuf); unsigned long flags; bool empty; @@ -872,7 +869,7 @@ static void vsp1_video_cleanup_pipeline(struct vsp1_pipeline *pipe) static int vsp1_video_start_streaming(struct vb2_queue *vq, unsigned int count) { struct vsp1_video *video = vb2_get_drv_priv(vq); - struct vsp1_pipeline *pipe = video->rwpf->pipe; + struct vsp1_pipeline *pipe = video->rwpf->entity.pipe; bool start_pipeline = false; unsigned long flags; int ret; @@ -913,7 +910,7 @@ static int vsp1_video_start_streaming(struct vb2_queue *vq, unsigned int count) static void vsp1_video_stop_streaming(struct vb2_queue *vq) { struct vsp1_video *video = vb2_get_drv_priv(vq); - struct vsp1_pipeline *pipe = video->rwpf->pipe; + struct vsp1_pipeline *pipe = video->rwpf->entity.pipe; unsigned long flags; int ret; diff --git a/drivers/media/platform/vsp1/vsp1_wpf.c b/drivers/media/platform/vsp1/vsp1_wpf.c index 8bd6b2f1af15..53858d100228 100644 --- a/drivers/media/platform/vsp1/vsp1_wpf.c +++ b/drivers/media/platform/vsp1/vsp1_wpf.c @@ -436,7 +436,7 @@ static void wpf_configure(struct vsp1_entity *entity, vsp1_dl_list_write(dl, VI6_WPF_WRBCK_CTRL, 0); /* - * Sources. If the pipeline has a single input and BRU is not used, + * Sources. If the pipeline has a single input and BRx is not used, * configure it as the master layer. Otherwise configure all * inputs as sub-layers and select the virtual RPF as the master * layer. @@ -447,13 +447,13 @@ static void wpf_configure(struct vsp1_entity *entity, if (!input) continue; - srcrpf |= (!pipe->bru && pipe->num_inputs == 1) + srcrpf |= (!pipe->brx && pipe->num_inputs == 1) ? VI6_WPF_SRCRPF_RPF_ACT_MST(input->entity.index) : VI6_WPF_SRCRPF_RPF_ACT_SUB(input->entity.index); } - if (pipe->bru) - srcrpf |= pipe->bru->type == VSP1_ENTITY_BRU + if (pipe->brx) + srcrpf |= pipe->brx->type == VSP1_ENTITY_BRU ? VI6_WPF_SRCRPF_VIRACT_MST : VI6_WPF_SRCRPF_VIRACT2_MST; diff --git a/drivers/media/radio/Kconfig b/drivers/media/radio/Kconfig index 192f36f2f4aa..8fa403c7149e 100644 --- a/drivers/media/radio/Kconfig +++ b/drivers/media/radio/Kconfig @@ -15,10 +15,6 @@ if RADIO_ADAPTERS && VIDEO_V4L2 config RADIO_TEA575X tristate -config RADIO_SI470X - bool "Silicon Labs Si470x FM Radio Receiver support" - depends on VIDEO_V4L2 - source "drivers/media/radio/si470x/Kconfig" config RADIO_SI4713 @@ -235,7 +231,7 @@ source "drivers/media/radio/wl128x/Kconfig" menuconfig V4L_RADIO_ISA_DRIVERS bool "ISA radio devices" - depends on ISA + depends on ISA || COMPILE_TEST default n ---help--- Say Y here to enable support for these ISA drivers. @@ -243,12 +239,13 @@ menuconfig V4L_RADIO_ISA_DRIVERS if V4L_RADIO_ISA_DRIVERS config RADIO_ISA - depends on ISA + depends on ISA || COMPILE_TEST tristate config RADIO_CADET tristate "ADS Cadet AM/FM Tuner" - depends on ISA && VIDEO_V4L2 + depends on ISA || COMPILE_TEST + depends on VIDEO_V4L2 ---help--- Choose Y here if you have one of these AM/FM radio cards, and then fill in the port address below. @@ -258,8 +255,8 @@ config RADIO_CADET config RADIO_RTRACK tristate "AIMSlab RadioTrack (aka RadioReveal) support" - depends on ISA && VIDEO_V4L2 - select RADIO_ISA + depends on ISA || COMPILE_TEST + depends on VIDEO_V4L2 ---help--- Choose Y here if you have one of these FM radio cards, and then fill in the port address below. @@ -289,7 +286,8 @@ config RADIO_RTRACK_PORT config RADIO_RTRACK2 tristate "AIMSlab RadioTrack II support" - depends on ISA && VIDEO_V4L2 + depends on ISA || COMPILE_TEST + depends on VIDEO_V4L2 select RADIO_ISA ---help--- Choose Y here if you have this FM radio card, and then fill in the @@ -312,7 +310,8 @@ config RADIO_RTRACK2_PORT config RADIO_AZTECH tristate "Aztech/Packard Bell Radio" - depends on ISA && VIDEO_V4L2 + depends on ISA || COMPILE_TEST + depends on VIDEO_V4L2 select RADIO_ISA ---help--- Choose Y here if you have one of these FM radio cards, and then fill @@ -332,7 +331,8 @@ config RADIO_AZTECH_PORT config RADIO_GEMTEK tristate "GemTek Radio card (or compatible) support" - depends on ISA && VIDEO_V4L2 + depends on ISA || COMPILE_TEST + depends on VIDEO_V4L2 select RADIO_ISA ---help--- Choose Y here if you have this FM radio card, and then fill in the @@ -372,7 +372,8 @@ config RADIO_GEMTEK_PROBE config RADIO_MIROPCM20 tristate "miroSOUND PCM20 radio" - depends on ISA && ISA_DMA_API && VIDEO_V4L2 && SND + depends on ISA || COMPILE_TEST + depends on ISA_DMA_API && VIDEO_V4L2 && SND select SND_ISA select SND_MIRO ---help--- @@ -386,7 +387,8 @@ config RADIO_MIROPCM20 config RADIO_SF16FMI tristate "SF16-FMI/SF16-FMP/SF16-FMD Radio" - depends on ISA && VIDEO_V4L2 + depends on ISA || COMPILE_TEST + depends on VIDEO_V4L2 ---help--- Choose Y here if you have one of these FM radio cards. @@ -395,7 +397,8 @@ config RADIO_SF16FMI config RADIO_SF16FMR2 tristate "SF16-FMR2/SF16-FMD2 Radio" - depends on ISA && VIDEO_V4L2 + depends on ISA || COMPILE_TEST + depends on VIDEO_V4L2 select RADIO_TEA575X ---help--- Choose Y here if you have one of these FM radio cards. @@ -405,7 +408,8 @@ config RADIO_SF16FMR2 config RADIO_TERRATEC tristate "TerraTec ActiveRadio ISA Standalone" - depends on ISA && VIDEO_V4L2 + depends on ISA || COMPILE_TEST + depends on VIDEO_V4L2 select RADIO_ISA ---help--- Choose Y here if you have this FM radio card. @@ -419,7 +423,8 @@ config RADIO_TERRATEC config RADIO_TRUST tristate "Trust FM radio card" - depends on ISA && VIDEO_V4L2 + depends on ISA || COMPILE_TEST + depends on VIDEO_V4L2 select RADIO_ISA help This is a driver for the Trust FM radio cards. Say Y if you have @@ -442,7 +447,8 @@ config RADIO_TRUST_PORT config RADIO_TYPHOON tristate "Typhoon Radio (a.k.a. EcoRadio)" - depends on ISA && VIDEO_V4L2 + depends on ISA || COMPILE_TEST + depends on VIDEO_V4L2 select RADIO_ISA ---help--- Choose Y here if you have one of these FM radio cards, and then fill @@ -476,7 +482,8 @@ config RADIO_TYPHOON_MUTEFREQ config RADIO_ZOLTRIX tristate "Zoltrix Radio" - depends on ISA && VIDEO_V4L2 + depends on ISA || COMPILE_TEST + depends on VIDEO_V4L2 select RADIO_ISA ---help--- Choose Y here if you have one of these FM radio cards, and then fill diff --git a/drivers/media/radio/si470x/Kconfig b/drivers/media/radio/si470x/Kconfig index a466654ee5c9..a21172e413a9 100644 --- a/drivers/media/radio/si470x/Kconfig +++ b/drivers/media/radio/si470x/Kconfig @@ -1,3 +1,17 @@ +config RADIO_SI470X + tristate "Silicon Labs Si470x FM Radio Receiver support" + depends on VIDEO_V4L2 + ---help--- + This is a driver for devices with the Silicon Labs SI470x + chip (either via USB or I2C buses). + + Say Y here if you want to connect this type of radio to your + computer's USB port or if it is used by some other driver + via I2C bus. + + To compile this driver as a module, choose M here: the + module will be called radio-si470x-common. + config USB_SI470X tristate "Silicon Labs Si470x FM Radio Receiver support with USB" depends on USB && RADIO_SI470X @@ -25,7 +39,7 @@ config USB_SI470X config I2C_SI470X tristate "Silicon Labs Si470x FM Radio Receiver support with I2C" - depends on I2C && RADIO_SI470X && !USB_SI470X + depends on I2C && RADIO_SI470X ---help--- This is a driver for I2C devices with the Silicon Labs SI470x chip. diff --git a/drivers/media/radio/si470x/Makefile b/drivers/media/radio/si470x/Makefile index 06964816cfd6..682b3146397e 100644 --- a/drivers/media/radio/si470x/Makefile +++ b/drivers/media/radio/si470x/Makefile @@ -2,8 +2,6 @@ # Makefile for radios with Silicon Labs Si470x FM Radio Receivers # -radio-usb-si470x-objs := radio-si470x-usb.o radio-si470x-common.o -radio-i2c-si470x-objs := radio-si470x-i2c.o radio-si470x-common.o - -obj-$(CONFIG_USB_SI470X) += radio-usb-si470x.o -obj-$(CONFIG_I2C_SI470X) += radio-i2c-si470x.o +obj-$(CONFIG_RADIO_SI470X) += radio-si470x-common.o +obj-$(CONFIG_USB_SI470X) += radio-si470x-usb.o +obj-$(CONFIG_I2C_SI470X) += radio-si470x-i2c.o diff --git a/drivers/media/radio/si470x/radio-si470x-common.c b/drivers/media/radio/si470x/radio-si470x-common.c index b94d66e53d4e..c40e1753f34b 100644 --- a/drivers/media/radio/si470x/radio-si470x-common.c +++ b/drivers/media/radio/si470x/radio-si470x-common.c @@ -110,8 +110,6 @@ /* kernel includes */ #include "radio-si470x.h" - - /************************************************************************** * Module Parameters **************************************************************************/ @@ -195,7 +193,7 @@ static int si470x_set_band(struct si470x_device *radio, int band) radio->band = band; radio->registers[SYSCONFIG2] &= ~SYSCONFIG2_BAND; radio->registers[SYSCONFIG2] |= radio->band << 6; - return si470x_set_register(radio, SYSCONFIG2); + return radio->set_register(radio, SYSCONFIG2); } /* @@ -207,7 +205,7 @@ static int si470x_set_chan(struct si470x_device *radio, unsigned short chan) unsigned long time_left; bool timed_out = false; - retval = si470x_get_register(radio, POWERCFG); + retval = radio->get_register(radio, POWERCFG); if (retval) return retval; @@ -219,7 +217,7 @@ static int si470x_set_chan(struct si470x_device *radio, unsigned short chan) /* start tuning */ radio->registers[CHANNEL] &= ~CHANNEL_CHAN; radio->registers[CHANNEL] |= CHANNEL_TUNE | chan; - retval = si470x_set_register(radio, CHANNEL); + retval = radio->set_register(radio, CHANNEL); if (retval < 0) goto done; @@ -238,7 +236,7 @@ static int si470x_set_chan(struct si470x_device *radio, unsigned short chan) /* stop tuning */ radio->registers[CHANNEL] &= ~CHANNEL_TUNE; - retval = si470x_set_register(radio, CHANNEL); + retval = radio->set_register(radio, CHANNEL); done: return retval; @@ -272,7 +270,7 @@ static int si470x_get_freq(struct si470x_device *radio, unsigned int *freq) int chan, retval; /* read channel */ - retval = si470x_get_register(radio, READCHAN); + retval = radio->get_register(radio, READCHAN); chan = radio->registers[READCHAN] & READCHAN_READCHAN; /* Frequency (MHz) = Spacing (kHz) x Channel + Bottom of Band (MHz) */ @@ -296,6 +294,7 @@ int si470x_set_freq(struct si470x_device *radio, unsigned int freq) return si470x_set_chan(radio, chan); } +EXPORT_SYMBOL_GPL(si470x_set_freq); /* @@ -343,7 +342,7 @@ static int si470x_set_seek(struct si470x_device *radio, radio->registers[POWERCFG] |= POWERCFG_SEEKUP; else radio->registers[POWERCFG] &= ~POWERCFG_SEEKUP; - retval = si470x_set_register(radio, POWERCFG); + retval = radio->set_register(radio, POWERCFG); if (retval < 0) return retval; @@ -362,7 +361,7 @@ static int si470x_set_seek(struct si470x_device *radio, /* stop seeking */ radio->registers[POWERCFG] &= ~POWERCFG_SEEK; - retval = si470x_set_register(radio, POWERCFG); + retval = radio->set_register(radio, POWERCFG); /* try again, if timed out */ if (retval == 0 && timed_out) @@ -381,7 +380,7 @@ int si470x_start(struct si470x_device *radio) /* powercfg */ radio->registers[POWERCFG] = POWERCFG_DMUTE | POWERCFG_ENABLE | POWERCFG_RDSM; - retval = si470x_set_register(radio, POWERCFG); + retval = radio->set_register(radio, POWERCFG); if (retval < 0) goto done; @@ -392,7 +391,7 @@ int si470x_start(struct si470x_device *radio) radio->registers[SYSCONFIG1] |= SYSCONFIG1_GPIO2_INT; if (de) radio->registers[SYSCONFIG1] |= SYSCONFIG1_DE; - retval = si470x_set_register(radio, SYSCONFIG1); + retval = radio->set_register(radio, SYSCONFIG1); if (retval < 0) goto done; @@ -402,7 +401,7 @@ int si470x_start(struct si470x_device *radio) ((radio->band << 6) & SYSCONFIG2_BAND) |/* BAND */ ((space << 4) & SYSCONFIG2_SPACE) | /* SPACE */ 15; /* VOLUME (max) */ - retval = si470x_set_register(radio, SYSCONFIG2); + retval = radio->set_register(radio, SYSCONFIG2); if (retval < 0) goto done; @@ -413,6 +412,7 @@ int si470x_start(struct si470x_device *radio) done: return retval; } +EXPORT_SYMBOL_GPL(si470x_start); /* @@ -424,7 +424,7 @@ int si470x_stop(struct si470x_device *radio) /* sysconfig 1 */ radio->registers[SYSCONFIG1] &= ~SYSCONFIG1_RDS; - retval = si470x_set_register(radio, SYSCONFIG1); + retval = radio->set_register(radio, SYSCONFIG1); if (retval < 0) goto done; @@ -432,11 +432,12 @@ int si470x_stop(struct si470x_device *radio) radio->registers[POWERCFG] &= ~POWERCFG_DMUTE; /* POWERCFG_ENABLE has to automatically go low */ radio->registers[POWERCFG] |= POWERCFG_ENABLE | POWERCFG_DISABLE; - retval = si470x_set_register(radio, POWERCFG); + retval = radio->set_register(radio, POWERCFG); done: return retval; } +EXPORT_SYMBOL_GPL(si470x_stop); /* @@ -448,7 +449,7 @@ static int si470x_rds_on(struct si470x_device *radio) /* sysconfig 1 */ radio->registers[SYSCONFIG1] |= SYSCONFIG1_RDS; - retval = si470x_set_register(radio, SYSCONFIG1); + retval = radio->set_register(radio, SYSCONFIG1); if (retval < 0) radio->registers[SYSCONFIG1] &= ~SYSCONFIG1_RDS; @@ -542,6 +543,25 @@ static __poll_t si470x_fops_poll(struct file *file, } +static int si470x_fops_open(struct file *file) +{ + struct si470x_device *radio = video_drvdata(file); + + return radio->fops_open(file); +} + + +/* + * si470x_fops_release - file release + */ +static int si470x_fops_release(struct file *file) +{ + struct si470x_device *radio = video_drvdata(file); + + return radio->fops_release(file); +} + + /* * si470x_fops - file operations interface */ @@ -570,13 +590,13 @@ static int si470x_s_ctrl(struct v4l2_ctrl *ctrl) case V4L2_CID_AUDIO_VOLUME: radio->registers[SYSCONFIG2] &= ~SYSCONFIG2_VOLUME; radio->registers[SYSCONFIG2] |= ctrl->val; - return si470x_set_register(radio, SYSCONFIG2); + return radio->set_register(radio, SYSCONFIG2); case V4L2_CID_AUDIO_MUTE: if (ctrl->val) radio->registers[POWERCFG] &= ~POWERCFG_DMUTE; else radio->registers[POWERCFG] |= POWERCFG_DMUTE; - return si470x_set_register(radio, POWERCFG); + return radio->set_register(radio, POWERCFG); default: return -EINVAL; } @@ -596,7 +616,7 @@ static int si470x_vidioc_g_tuner(struct file *file, void *priv, return -EINVAL; if (!radio->status_rssi_auto_update) { - retval = si470x_get_register(radio, STATUSRSSI); + retval = radio->get_register(radio, STATUSRSSI); if (retval < 0) return retval; } @@ -665,7 +685,7 @@ static int si470x_vidioc_s_tuner(struct file *file, void *priv, break; } - return si470x_set_register(radio, POWERCFG); + return radio->set_register(radio, POWERCFG); } @@ -742,6 +762,15 @@ static int si470x_vidioc_enum_freq_bands(struct file *file, void *priv, const struct v4l2_ctrl_ops si470x_ctrl_ops = { .s_ctrl = si470x_s_ctrl, }; +EXPORT_SYMBOL_GPL(si470x_ctrl_ops); + +static int si470x_vidioc_querycap(struct file *file, void *priv, + struct v4l2_capability *capability) +{ + struct si470x_device *radio = video_drvdata(file); + + return radio->vidioc_querycap(file, priv, capability); +}; /* * si470x_ioctl_ops - video device ioctl operations @@ -768,3 +797,6 @@ const struct video_device si470x_viddev_template = { .release = video_device_release_empty, .ioctl_ops = &si470x_ioctl_ops, }; +EXPORT_SYMBOL_GPL(si470x_viddev_template); + +MODULE_LICENSE("GPL"); diff --git a/drivers/media/radio/si470x/radio-si470x-i2c.c b/drivers/media/radio/si470x/radio-si470x-i2c.c index 41709b24b28f..e3b3ecd14a4d 100644 --- a/drivers/media/radio/si470x/radio-si470x-i2c.c +++ b/drivers/media/radio/si470x/radio-si470x-i2c.c @@ -89,9 +89,9 @@ MODULE_PARM_DESC(max_rds_errors, "RDS maximum block errors: *1*"); /* * si470x_get_register - read register */ -int si470x_get_register(struct si470x_device *radio, int regnr) +static int si470x_get_register(struct si470x_device *radio, int regnr) { - u16 buf[READ_REG_NUM]; + __be16 buf[READ_REG_NUM]; struct i2c_msg msgs[1] = { { .addr = radio->client->addr, @@ -113,10 +113,10 @@ int si470x_get_register(struct si470x_device *radio, int regnr) /* * si470x_set_register - write register */ -int si470x_set_register(struct si470x_device *radio, int regnr) +static int si470x_set_register(struct si470x_device *radio, int regnr) { int i; - u16 buf[WRITE_REG_NUM]; + __be16 buf[WRITE_REG_NUM]; struct i2c_msg msgs[1] = { { .addr = radio->client->addr, @@ -146,7 +146,7 @@ int si470x_set_register(struct si470x_device *radio, int regnr) static int si470x_get_all_registers(struct si470x_device *radio) { int i; - u16 buf[READ_REG_NUM]; + __be16 buf[READ_REG_NUM]; struct i2c_msg msgs[1] = { { .addr = radio->client->addr, @@ -174,7 +174,7 @@ static int si470x_get_all_registers(struct si470x_device *radio) /* * si470x_fops_open - file open */ -int si470x_fops_open(struct file *file) +static int si470x_fops_open(struct file *file) { struct si470x_device *radio = video_drvdata(file); int retval = v4l2_fh_open(file); @@ -206,7 +206,7 @@ done: /* * si470x_fops_release - file release */ -int si470x_fops_release(struct file *file) +static int si470x_fops_release(struct file *file) { struct si470x_device *radio = video_drvdata(file); @@ -226,8 +226,8 @@ int si470x_fops_release(struct file *file) /* * si470x_vidioc_querycap - query device capabilities */ -int si470x_vidioc_querycap(struct file *file, void *priv, - struct v4l2_capability *capability) +static int si470x_vidioc_querycap(struct file *file, void *priv, + struct v4l2_capability *capability) { strlcpy(capability->driver, DRIVER_NAME, sizeof(capability->driver)); strlcpy(capability->card, DRIVER_CARD, sizeof(capability->card)); @@ -361,6 +361,12 @@ static int si470x_i2c_probe(struct i2c_client *client, mutex_init(&radio->lock); init_completion(&radio->completion); + radio->get_register = si470x_get_register; + radio->set_register = si470x_set_register; + radio->fops_open = si470x_fops_open; + radio->fops_release = si470x_fops_release; + radio->vidioc_querycap = si470x_vidioc_querycap; + retval = v4l2_device_register(&client->dev, &radio->v4l2_dev); if (retval < 0) { dev_err(&client->dev, "couldn't register v4l2_device\n"); diff --git a/drivers/media/radio/si470x/radio-si470x-usb.c b/drivers/media/radio/si470x/radio-si470x-usb.c index 2277e850bb5e..313a95f195a2 100644 --- a/drivers/media/radio/si470x/radio-si470x-usb.c +++ b/drivers/media/radio/si470x/radio-si470x-usb.c @@ -250,7 +250,7 @@ static int si470x_set_report(struct si470x_device *radio, void *buf, int size) /* * si470x_get_register - read register */ -int si470x_get_register(struct si470x_device *radio, int regnr) +static int si470x_get_register(struct si470x_device *radio, int regnr) { int retval; @@ -268,7 +268,7 @@ int si470x_get_register(struct si470x_device *radio, int regnr) /* * si470x_set_register - write register */ -int si470x_set_register(struct si470x_device *radio, int regnr) +static int si470x_set_register(struct si470x_device *radio, int regnr) { int retval; @@ -482,12 +482,12 @@ resubmit: } -int si470x_fops_open(struct file *file) +static int si470x_fops_open(struct file *file) { return v4l2_fh_open(file); } -int si470x_fops_release(struct file *file) +static int si470x_fops_release(struct file *file) { return v4l2_fh_release(file); } @@ -514,8 +514,8 @@ static void si470x_usb_release(struct v4l2_device *v4l2_dev) /* * si470x_vidioc_querycap - query device capabilities */ -int si470x_vidioc_querycap(struct file *file, void *priv, - struct v4l2_capability *capability) +static int si470x_vidioc_querycap(struct file *file, void *priv, + struct v4l2_capability *capability) { struct si470x_device *radio = video_drvdata(file); @@ -598,6 +598,12 @@ static int si470x_usb_driver_probe(struct usb_interface *intf, mutex_init(&radio->lock); init_completion(&radio->completion); + radio->get_register = si470x_get_register; + radio->set_register = si470x_set_register; + radio->fops_open = si470x_fops_open; + radio->fops_release = si470x_fops_release; + radio->vidioc_querycap = si470x_vidioc_querycap; + iface_desc = intf->cur_altsetting; /* Set up interrupt endpoint information. */ diff --git a/drivers/media/radio/si470x/radio-si470x.h b/drivers/media/radio/si470x/radio-si470x.h index 0202f8eb90c4..35fa0f3bbdd2 100644 --- a/drivers/media/radio/si470x/radio-si470x.h +++ b/drivers/media/radio/si470x/radio-si470x.h @@ -161,6 +161,15 @@ struct si470x_device { struct completion completion; bool status_rssi_auto_update; /* Does RSSI get updated automatic? */ + /* si470x ops */ + + int (*get_register)(struct si470x_device *radio, int regnr); + int (*set_register)(struct si470x_device *radio, int regnr); + int (*fops_open)(struct file *file); + int (*fops_release)(struct file *file); + int (*vidioc_querycap)(struct file *file, void *priv, + struct v4l2_capability *capability); + #if IS_ENABLED(CONFIG_USB_SI470X) /* reference to USB and video device */ struct usb_device *usbdev; @@ -213,13 +222,7 @@ struct si470x_device { **************************************************************************/ extern const struct video_device si470x_viddev_template; extern const struct v4l2_ctrl_ops si470x_ctrl_ops; -int si470x_get_register(struct si470x_device *radio, int regnr); -int si470x_set_register(struct si470x_device *radio, int regnr); int si470x_disconnect_check(struct si470x_device *radio); int si470x_set_freq(struct si470x_device *radio, unsigned int freq); int si470x_start(struct si470x_device *radio); int si470x_stop(struct si470x_device *radio); -int si470x_fops_open(struct file *file); -int si470x_fops_release(struct file *file); -int si470x_vidioc_querycap(struct file *file, void *priv, - struct v4l2_capability *capability); diff --git a/drivers/media/rc/Kconfig b/drivers/media/rc/Kconfig index eb2c3b6eca7f..9a3b66c6700c 100644 --- a/drivers/media/rc/Kconfig +++ b/drivers/media/rc/Kconfig @@ -149,7 +149,7 @@ config RC_ATI_REMOTE config IR_ENE tristate "ENE eHome Receiver/Transceiver (pnp id: ENE0100/ENE02xxx)" - depends on PNP + depends on PNP || COMPILE_TEST depends on RC_CORE ---help--- Say Y here to enable support for integrated infrared receiver @@ -210,7 +210,7 @@ config IR_MCEUSB config IR_ITE_CIR tristate "ITE Tech Inc. IT8712/IT8512 Consumer Infrared Transceiver" - depends on PNP + depends on PNP || COMPILE_TEST depends on RC_CORE ---help--- Say Y here to enable support for integrated infrared receivers @@ -223,7 +223,7 @@ config IR_ITE_CIR config IR_FINTEK tristate "Fintek Consumer Infrared Transceiver" - depends on PNP + depends on PNP || COMPILE_TEST depends on RC_CORE ---help--- Say Y here to enable support for integrated infrared receiver @@ -257,7 +257,7 @@ config IR_MTK config IR_NUVOTON tristate "Nuvoton w836x7hg Consumer Infrared Transceiver" - depends on PNP + depends on PNP || COMPILE_TEST depends on RC_CORE ---help--- Say Y here to enable support for integrated infrared receiver @@ -305,7 +305,7 @@ config IR_STREAMZAP config IR_WINBOND_CIR tristate "Winbond IR remote control" - depends on X86 && PNP + depends on (X86 && PNP) || COMPILE_TEST depends on RC_CORE select NEW_LEDS select LEDS_CLASS diff --git a/drivers/media/rc/ir-imon-decoder.c b/drivers/media/rc/ir-imon-decoder.c index a1ff06a26542..67c1b0c15aae 100644 --- a/drivers/media/rc/ir-imon-decoder.c +++ b/drivers/media/rc/ir-imon-decoder.c @@ -31,9 +31,69 @@ enum imon_state { STATE_INACTIVE, STATE_BIT_CHK, STATE_BIT_START, - STATE_FINISHED + STATE_FINISHED, + STATE_ERROR, }; +static void ir_imon_decode_scancode(struct rc_dev *dev) +{ + struct imon_dec *imon = &dev->raw->imon; + + /* Keyboard/Mouse toggle */ + if (imon->bits == 0x299115b7) + imon->stick_keyboard = !imon->stick_keyboard; + + if ((imon->bits & 0xfc0000ff) == 0x680000b7) { + int rel_x, rel_y; + u8 buf; + + buf = imon->bits >> 16; + rel_x = (buf & 0x08) | (buf & 0x10) >> 2 | + (buf & 0x20) >> 4 | (buf & 0x40) >> 6; + if (imon->bits & 0x02000000) + rel_x |= ~0x0f; + buf = imon->bits >> 8; + rel_y = (buf & 0x08) | (buf & 0x10) >> 2 | + (buf & 0x20) >> 4 | (buf & 0x40) >> 6; + if (imon->bits & 0x01000000) + rel_y |= ~0x0f; + + if (rel_x && rel_y && imon->stick_keyboard) { + if (abs(rel_y) > abs(rel_x)) + imon->bits = rel_y > 0 ? + 0x289515b7 : /* KEY_DOWN */ + 0x2aa515b7; /* KEY_UP */ + else + imon->bits = rel_x > 0 ? + 0x2ba515b7 : /* KEY_RIGHT */ + 0x29a515b7; /* KEY_LEFT */ + } + + if (!imon->stick_keyboard) { + struct lirc_scancode lsc = { + .scancode = imon->bits, + .rc_proto = RC_PROTO_IMON, + }; + + ir_lirc_scancode_event(dev, &lsc); + + input_event(imon->idev, EV_MSC, MSC_SCAN, imon->bits); + + input_report_rel(imon->idev, REL_X, rel_x); + input_report_rel(imon->idev, REL_Y, rel_y); + + input_report_key(imon->idev, BTN_LEFT, + (imon->bits & 0x00010000) != 0); + input_report_key(imon->idev, BTN_RIGHT, + (imon->bits & 0x00040000) != 0); + input_sync(imon->idev); + return; + } + } + + rc_keydown(dev, RC_PROTO_IMON, imon->bits, 0); +} + /** * ir_imon_decode() - Decode one iMON pulse or space * @dev: the struct rc_dev descriptor of the device @@ -56,6 +116,22 @@ static int ir_imon_decode(struct rc_dev *dev, struct ir_raw_event ev) data->state, data->count, TO_US(ev.duration), TO_STR(ev.pulse)); + /* + * Since iMON protocol is a series of bits, if at any point + * we encounter an error, make sure that any remaining bits + * aren't parsed as a scancode made up of less bits. + * + * Note that if the stick is held, then the remote repeats + * the scancode with about 12ms between them. So, make sure + * we have at least 10ms of space after an error. That way, + * we're at a new scancode. + */ + if (data->state == STATE_ERROR) { + if (!ev.pulse && ev.duration > MS_TO_NS(10)) + data->state = STATE_INACTIVE; + return 0; + } + for (;;) { if (!geq_margin(ev.duration, IMON_UNIT, IMON_UNIT / 2)) return 0; @@ -95,7 +171,7 @@ static int ir_imon_decode(struct rc_dev *dev, struct ir_raw_event ev) case STATE_FINISHED: if (ev.pulse) goto err_out; - rc_keydown(dev, RC_PROTO_IMON, data->bits, 0); + ir_imon_decode_scancode(dev); data->state = STATE_INACTIVE; break; } @@ -107,7 +183,7 @@ err_out: data->state, data->count, TO_US(ev.duration), TO_STR(ev.pulse)); - data->state = STATE_INACTIVE; + data->state = STATE_ERROR; return -EINVAL; } @@ -165,11 +241,65 @@ static int ir_imon_encode(enum rc_proto protocol, u32 scancode, return e - events; } +static int ir_imon_register(struct rc_dev *dev) +{ + struct input_dev *idev; + struct imon_dec *imon = &dev->raw->imon; + int ret; + + idev = input_allocate_device(); + if (!idev) + return -ENOMEM; + + snprintf(imon->name, sizeof(imon->name), + "iMON PAD Stick (%s)", dev->device_name); + idev->name = imon->name; + idev->phys = dev->input_phys; + + /* Mouse bits */ + set_bit(EV_REL, idev->evbit); + set_bit(EV_KEY, idev->evbit); + set_bit(REL_X, idev->relbit); + set_bit(REL_Y, idev->relbit); + set_bit(BTN_LEFT, idev->keybit); + set_bit(BTN_RIGHT, idev->keybit); + + /* Report scancodes too */ + set_bit(EV_MSC, idev->evbit); + set_bit(MSC_SCAN, idev->mscbit); + + input_set_drvdata(idev, imon); + + ret = input_register_device(idev); + if (ret < 0) { + input_free_device(idev); + return -EIO; + } + + imon->idev = idev; + imon->stick_keyboard = false; + + return 0; +} + +static int ir_imon_unregister(struct rc_dev *dev) +{ + struct imon_dec *imon = &dev->raw->imon; + + input_unregister_device(imon->idev); + imon->idev = NULL; + + return 0; +} + static struct ir_raw_handler imon_handler = { .protocols = RC_PROTO_BIT_IMON, .decode = ir_imon_decode, .encode = ir_imon_encode, .carrier = 38000, + .raw_register = ir_imon_register, + .raw_unregister = ir_imon_unregister, + .min_timeout = IMON_UNIT * IMON_BITS * 2, }; static int __init ir_imon_decode_init(void) diff --git a/drivers/media/rc/ir-jvc-decoder.c b/drivers/media/rc/ir-jvc-decoder.c index 8cb68ae43282..5706cfe60027 100644 --- a/drivers/media/rc/ir-jvc-decoder.c +++ b/drivers/media/rc/ir-jvc-decoder.c @@ -213,6 +213,7 @@ static struct ir_raw_handler jvc_handler = { .decode = ir_jvc_decode, .encode = ir_jvc_encode, .carrier = 38000, + .min_timeout = JVC_TRAILER_SPACE, }; static int __init ir_jvc_decode_init(void) diff --git a/drivers/media/rc/ir-mce_kbd-decoder.c b/drivers/media/rc/ir-mce_kbd-decoder.c index c110984ca671..9574c3dd90f2 100644 --- a/drivers/media/rc/ir-mce_kbd-decoder.c +++ b/drivers/media/rc/ir-mce_kbd-decoder.c @@ -119,17 +119,25 @@ static void mce_kbd_rx_timeout(struct timer_list *t) { struct ir_raw_event_ctrl *raw = from_timer(raw, t, mce_kbd.rx_timeout); unsigned char maskcode; + unsigned long flags; int i; dev_dbg(&raw->dev->dev, "timer callback clearing all keys\n"); - for (i = 0; i < 7; i++) { - maskcode = kbd_keycodes[MCIR2_MASK_KEYS_START + i]; - input_report_key(raw->mce_kbd.idev, maskcode, 0); - } + spin_lock_irqsave(&raw->mce_kbd.keylock, flags); - for (i = 0; i < MCIR2_MASK_KEYS_START; i++) - input_report_key(raw->mce_kbd.idev, kbd_keycodes[i], 0); + if (time_is_before_eq_jiffies(raw->mce_kbd.rx_timeout.expires)) { + for (i = 0; i < 7; i++) { + maskcode = kbd_keycodes[MCIR2_MASK_KEYS_START + i]; + input_report_key(raw->mce_kbd.idev, maskcode, 0); + } + + for (i = 0; i < MCIR2_MASK_KEYS_START; i++) + input_report_key(raw->mce_kbd.idev, kbd_keycodes[i], 0); + + input_sync(raw->mce_kbd.idev); + } + spin_unlock_irqrestore(&raw->mce_kbd.keylock, flags); } static enum mce_kbd_mode mce_kbd_mode(struct mce_kbd_dec *data) @@ -147,13 +155,14 @@ static enum mce_kbd_mode mce_kbd_mode(struct mce_kbd_dec *data) static void ir_mce_kbd_process_keyboard_data(struct rc_dev *dev, u32 scancode) { struct mce_kbd_dec *data = &dev->raw->mce_kbd; - u8 keydata = (scancode >> 8) & 0xff; + u8 keydata1 = (scancode >> 8) & 0xff; + u8 keydata2 = (scancode >> 16) & 0xff; u8 shiftmask = scancode & 0xff; - unsigned char keycode, maskcode; + unsigned char maskcode; int i, keystate; - dev_dbg(&dev->dev, "keyboard: keydata = 0x%02x, shiftmask = 0x%02x\n", - keydata, shiftmask); + dev_dbg(&dev->dev, "keyboard: keydata2 = 0x%02x, keydata1 = 0x%02x, shiftmask = 0x%02x\n", + keydata2, keydata1, shiftmask); for (i = 0; i < 7; i++) { maskcode = kbd_keycodes[MCIR2_MASK_KEYS_START + i]; @@ -164,10 +173,12 @@ static void ir_mce_kbd_process_keyboard_data(struct rc_dev *dev, u32 scancode) input_report_key(data->idev, maskcode, keystate); } - if (keydata) { - keycode = kbd_keycodes[keydata]; - input_report_key(data->idev, keycode, 1); - } else { + if (keydata1) + input_report_key(data->idev, kbd_keycodes[keydata1], 1); + if (keydata2) + input_report_key(data->idev, kbd_keycodes[keydata2], 1); + + if (!keydata1 && !keydata2) { for (i = 0; i < MCIR2_MASK_KEYS_START; i++) input_report_key(data->idev, kbd_keycodes[i], 0); } @@ -319,16 +330,20 @@ again: switch (data->wanted_bits) { case MCIR2_KEYBOARD_NBITS: - scancode = data->body & 0xffff; + scancode = data->body & 0xffffff; dev_dbg(&dev->dev, "keyboard data 0x%08x\n", data->body); - if (dev->timeout) - delay = usecs_to_jiffies(dev->timeout / 1000); - else - delay = msecs_to_jiffies(100); - mod_timer(&data->rx_timeout, jiffies + delay); + spin_lock(&data->keylock); + if (scancode) { + delay = nsecs_to_jiffies(dev->timeout) + + msecs_to_jiffies(100); + mod_timer(&data->rx_timeout, jiffies + delay); + } else { + del_timer(&data->rx_timeout); + } /* Pass data to keyboard buffer parser */ ir_mce_kbd_process_keyboard_data(dev, scancode); + spin_unlock(&data->keylock); lsc.rc_proto = RC_PROTO_MCIR2_KBD; break; case MCIR2_MOUSE_NBITS: @@ -355,7 +370,6 @@ out: dev_dbg(&dev->dev, "failed at state %i (%uus %s)\n", data->state, TO_US(ev.duration), TO_STR(ev.pulse)); data->state = STATE_INACTIVE; - input_sync(data->idev); return -EINVAL; } @@ -394,6 +408,7 @@ static int ir_mce_kbd_register(struct rc_dev *dev) set_bit(MSC_SCAN, idev->mscbit); timer_setup(&mce_kbd->rx_timeout, mce_kbd_rx_timeout, 0); + spin_lock_init(&mce_kbd->keylock); input_set_drvdata(idev, mce_kbd); @@ -475,6 +490,7 @@ static struct ir_raw_handler mce_kbd_handler = { .raw_register = ir_mce_kbd_register, .raw_unregister = ir_mce_kbd_unregister, .carrier = 36000, + .min_timeout = MCIR2_MAX_LEN + MCIR2_UNIT / 2, }; static int __init ir_mce_kbd_decode_init(void) diff --git a/drivers/media/rc/ir-nec-decoder.c b/drivers/media/rc/ir-nec-decoder.c index 21647b809e6f..6a8973ae3684 100644 --- a/drivers/media/rc/ir-nec-decoder.c +++ b/drivers/media/rc/ir-nec-decoder.c @@ -253,6 +253,7 @@ static struct ir_raw_handler nec_handler = { .decode = ir_nec_decode, .encode = ir_nec_encode, .carrier = 38000, + .min_timeout = NEC_TRAILER_SPACE, }; static int __init ir_nec_decode_init(void) diff --git a/drivers/media/rc/ir-rc5-decoder.c b/drivers/media/rc/ir-rc5-decoder.c index 74d3b859c3a2..cbfaadbee8fa 100644 --- a/drivers/media/rc/ir-rc5-decoder.c +++ b/drivers/media/rc/ir-rc5-decoder.c @@ -274,6 +274,7 @@ static struct ir_raw_handler rc5_handler = { .decode = ir_rc5_decode, .encode = ir_rc5_encode, .carrier = 36000, + .min_timeout = RC5_TRAILER, }; static int __init ir_rc5_decode_init(void) diff --git a/drivers/media/rc/ir-rc6-decoder.c b/drivers/media/rc/ir-rc6-decoder.c index 8314da32453f..66e07109f6fc 100644 --- a/drivers/media/rc/ir-rc6-decoder.c +++ b/drivers/media/rc/ir-rc6-decoder.c @@ -394,6 +394,7 @@ static struct ir_raw_handler rc6_handler = { .decode = ir_rc6_decode, .encode = ir_rc6_encode, .carrier = 36000, + .min_timeout = RC6_SUFFIX_SPACE, }; static int __init ir_rc6_decode_init(void) diff --git a/drivers/media/rc/ir-sanyo-decoder.c b/drivers/media/rc/ir-sanyo-decoder.c index 4efe6db5376a..dd6ee1e339d6 100644 --- a/drivers/media/rc/ir-sanyo-decoder.c +++ b/drivers/media/rc/ir-sanyo-decoder.c @@ -210,6 +210,7 @@ static struct ir_raw_handler sanyo_handler = { .decode = ir_sanyo_decode, .encode = ir_sanyo_encode, .carrier = 38000, + .min_timeout = SANYO_TRAILER_SPACE, }; static int __init ir_sanyo_decode_init(void) diff --git a/drivers/media/rc/ir-sharp-decoder.c b/drivers/media/rc/ir-sharp-decoder.c index 6a38c50566a4..f96e0c992eed 100644 --- a/drivers/media/rc/ir-sharp-decoder.c +++ b/drivers/media/rc/ir-sharp-decoder.c @@ -226,6 +226,7 @@ static struct ir_raw_handler sharp_handler = { .decode = ir_sharp_decode, .encode = ir_sharp_encode, .carrier = 38000, + .min_timeout = SHARP_ECHO_SPACE + SHARP_ECHO_SPACE / 4, }; static int __init ir_sharp_decode_init(void) diff --git a/drivers/media/rc/ir-sony-decoder.c b/drivers/media/rc/ir-sony-decoder.c index 6764ec9de646..5065c081238d 100644 --- a/drivers/media/rc/ir-sony-decoder.c +++ b/drivers/media/rc/ir-sony-decoder.c @@ -224,6 +224,7 @@ static struct ir_raw_handler sony_handler = { .decode = ir_sony_decode, .encode = ir_sony_encode, .carrier = 40000, + .min_timeout = SONY_TRAILER_SPACE, }; static int __init ir_sony_decode_init(void) diff --git a/drivers/media/rc/ir-spi.c b/drivers/media/rc/ir-spi.c index 7163d5ce2e64..66334e8d63ba 100644 --- a/drivers/media/rc/ir-spi.c +++ b/drivers/media/rc/ir-spi.c @@ -2,7 +2,7 @@ // SPI driven IR LED device driver // // Copyright (c) 2016 Samsung Electronics Co., Ltd. -// Copyright (c) Andi Shyti <andi.shyti@samsung.com> +// Copyright (c) Andi Shyti <andi@etezian.org> #include <linux/delay.h> #include <linux/fs.h> @@ -173,6 +173,6 @@ static struct spi_driver ir_spi_driver = { module_spi_driver(ir_spi_driver); -MODULE_AUTHOR("Andi Shyti <andi.shyti@samsung.com>"); +MODULE_AUTHOR("Andi Shyti <andi@etezian.org>"); MODULE_DESCRIPTION("SPI IR LED"); MODULE_LICENSE("GPL v2"); diff --git a/drivers/media/rc/ir-xmp-decoder.c b/drivers/media/rc/ir-xmp-decoder.c index 58b47af1a763..c965f51df1c1 100644 --- a/drivers/media/rc/ir-xmp-decoder.c +++ b/drivers/media/rc/ir-xmp-decoder.c @@ -199,6 +199,7 @@ static int ir_xmp_decode(struct rc_dev *dev, struct ir_raw_event ev) static struct ir_raw_handler xmp_handler = { .protocols = RC_PROTO_BIT_XMP, .decode = ir_xmp_decode, + .min_timeout = XMP_TRAILER_SPACE, }; static int __init ir_xmp_decode_init(void) diff --git a/drivers/media/rc/lirc_dev.c b/drivers/media/rc/lirc_dev.c index 24e9fbb80e81..cc58ed78462f 100644 --- a/drivers/media/rc/lirc_dev.c +++ b/drivers/media/rc/lirc_dev.c @@ -575,10 +575,17 @@ static long ir_lirc_ioctl(struct file *file, unsigned int cmd, } break; - case LIRC_SET_REC_TIMEOUT_REPORTS: + case LIRC_GET_REC_TIMEOUT: if (!dev->timeout) ret = -ENOTTY; else + val = DIV_ROUND_UP(dev->timeout, 1000); + break; + + case LIRC_SET_REC_TIMEOUT_REPORTS: + if (dev->driver_type != RC_DRIVER_IR_RAW) + ret = -ENOTTY; + else fh->send_timeout_reports = !!val; break; @@ -735,6 +742,7 @@ static void lirc_release_device(struct device *ld) int ir_lirc_register(struct rc_dev *dev) { + const char *rx_type, *tx_type; int err, minor; minor = ida_simple_get(&lirc_ida, 0, RC_DEV_MAX, GFP_KERNEL); @@ -759,8 +767,25 @@ int ir_lirc_register(struct rc_dev *dev) get_device(&dev->dev); - dev_info(&dev->dev, "lirc_dev: driver %s registered at minor = %d", - dev->driver_name, minor); + switch (dev->driver_type) { + case RC_DRIVER_SCANCODE: + rx_type = "scancode"; + break; + case RC_DRIVER_IR_RAW: + rx_type = "raw IR"; + break; + default: + rx_type = "no"; + break; + } + + if (dev->tx_ir) + tx_type = "raw IR"; + else + tx_type = "no"; + + dev_info(&dev->dev, "lirc_dev: driver %s registered at minor = %d, %s receiver, %s transmitter", + dev->driver_name, minor, rx_type, tx_type); return 0; diff --git a/drivers/media/rc/mceusb.c b/drivers/media/rc/mceusb.c index 69ba57372c05..5c0bf61fae26 100644 --- a/drivers/media/rc/mceusb.c +++ b/drivers/media/rc/mceusb.c @@ -982,6 +982,25 @@ static int mceusb_set_tx_carrier(struct rc_dev *dev, u32 carrier) return 0; } +static int mceusb_set_timeout(struct rc_dev *dev, unsigned int timeout) +{ + u8 cmdbuf[4] = { MCE_CMD_PORT_IR, MCE_CMD_SETIRTIMEOUT, 0, 0 }; + struct mceusb_dev *ir = dev->priv; + unsigned int units; + + units = DIV_ROUND_CLOSEST(timeout, US_TO_NS(MCE_TIME_UNIT)); + + cmdbuf[2] = units >> 8; + cmdbuf[3] = units; + + mce_async_out(ir, cmdbuf, sizeof(cmdbuf)); + + /* get receiver timeout value */ + mce_async_out(ir, GET_RX_TIMEOUT, sizeof(GET_RX_TIMEOUT)); + + return 0; +} + /* * Select or deselect the 2nd receiver port. * Second receiver is learning mode, wide-band, short-range receiver. @@ -1182,7 +1201,12 @@ static void mceusb_process_ir_data(struct mceusb_dev *ir, int buf_len) if (ir->rem) { ir->parser_state = PARSE_IRDATA; } else { - ir_raw_event_reset(ir->rc); + init_ir_raw_event(&rawir); + rawir.timeout = 1; + rawir.duration = ir->rc->timeout; + if (ir_raw_event_store_with_filter(ir->rc, + &rawir)) + event = true; ir->pulse_tunit = 0; ir->pulse_count = 0; } @@ -1415,7 +1439,10 @@ static struct rc_dev *mceusb_init_rc_dev(struct mceusb_dev *ir) rc->dev.parent = dev; rc->priv = ir; rc->allowed_protocols = RC_PROTO_BIT_ALL_IR_DECODER; + rc->min_timeout = US_TO_NS(MCE_TIME_UNIT); rc->timeout = MS_TO_NS(100); + rc->max_timeout = 10 * IR_DEFAULT_TIMEOUT; + rc->s_timeout = mceusb_set_timeout; if (!ir->flags.no_tx) { rc->s_tx_mask = mceusb_set_tx_mask; rc->s_tx_carrier = mceusb_set_tx_carrier; diff --git a/drivers/media/rc/mtk-cir.c b/drivers/media/rc/mtk-cir.c index e88eb64e8e69..e42efd9d382e 100644 --- a/drivers/media/rc/mtk-cir.c +++ b/drivers/media/rc/mtk-cir.c @@ -299,8 +299,6 @@ static int mtk_ir_probe(struct platform_device *pdev) { struct device *dev = &pdev->dev; struct device_node *dn = dev->of_node; - const struct of_device_id *of_id = - of_match_device(mtk_ir_match, &pdev->dev); struct resource *res; struct mtk_ir *ir; u32 val; @@ -312,7 +310,7 @@ static int mtk_ir_probe(struct platform_device *pdev) return -ENOMEM; ir->dev = dev; - ir->data = of_id->data; + ir->data = of_device_get_match_data(dev); ir->clk = devm_clk_get(dev, "clk"); if (IS_ERR(ir->clk)) { diff --git a/drivers/media/rc/rc-core-priv.h b/drivers/media/rc/rc-core-priv.h index e0e6a17460f6..bbb9a7eb6b63 100644 --- a/drivers/media/rc/rc-core-priv.h +++ b/drivers/media/rc/rc-core-priv.h @@ -37,6 +37,7 @@ struct ir_raw_handler { int (*encode)(enum rc_proto protocol, u32 scancode, struct ir_raw_event *events, unsigned int max); u32 carrier; + u32 min_timeout; /* These two should only be used by the mce kbd decoder */ int (*raw_register)(struct rc_dev *dev); @@ -104,6 +105,8 @@ struct ir_raw_event_ctrl { } sharp; struct mce_kbd_dec { struct input_dev *idev; + /* locks key up timer */ + spinlock_t keylock; struct timer_list rx_timeout; char name[64]; char phys[64]; @@ -123,6 +126,9 @@ struct ir_raw_event_ctrl { int count; int last_chk; unsigned int bits; + bool stick_keyboard; + struct input_dev *idev; + char name[64]; } imon; }; diff --git a/drivers/media/rc/rc-ir-raw.c b/drivers/media/rc/rc-ir-raw.c index 374f83105a23..2ab8a2b7092a 100644 --- a/drivers/media/rc/rc-ir-raw.c +++ b/drivers/media/rc/rc-ir-raw.c @@ -233,7 +233,49 @@ ir_raw_get_allowed_protocols(void) static int change_protocol(struct rc_dev *dev, u64 *rc_proto) { - /* the caller will update dev->enabled_protocols */ + struct ir_raw_handler *handler; + u32 timeout = 0; + + mutex_lock(&ir_raw_handler_lock); + list_for_each_entry(handler, &ir_raw_handler_list, list) { + if (!(dev->enabled_protocols & handler->protocols) && + (*rc_proto & handler->protocols) && handler->raw_register) + handler->raw_register(dev); + + if ((dev->enabled_protocols & handler->protocols) && + !(*rc_proto & handler->protocols) && + handler->raw_unregister) + handler->raw_unregister(dev); + } + mutex_unlock(&ir_raw_handler_lock); + + if (!dev->max_timeout) + return 0; + + mutex_lock(&ir_raw_handler_lock); + list_for_each_entry(handler, &ir_raw_handler_list, list) { + if (handler->protocols & *rc_proto) { + if (timeout < handler->min_timeout) + timeout = handler->min_timeout; + } + } + mutex_unlock(&ir_raw_handler_lock); + + if (timeout == 0) + timeout = IR_DEFAULT_TIMEOUT; + else + timeout += MS_TO_NS(10); + + if (timeout < dev->min_timeout) + timeout = dev->min_timeout; + else if (timeout > dev->max_timeout) + timeout = dev->max_timeout; + + if (dev->s_timeout) + dev->s_timeout(dev, timeout); + else + dev->timeout = timeout; + return 0; } @@ -578,7 +620,6 @@ int ir_raw_event_prepare(struct rc_dev *dev) int ir_raw_event_register(struct rc_dev *dev) { - struct ir_raw_handler *handler; struct task_struct *thread; thread = kthread_run(ir_raw_event_thread, dev->raw, "rc%u", dev->minor); @@ -589,9 +630,6 @@ int ir_raw_event_register(struct rc_dev *dev) mutex_lock(&ir_raw_handler_lock); list_add_tail(&dev->raw->list, &ir_raw_client_list); - list_for_each_entry(handler, &ir_raw_handler_list, list) - if (handler->raw_register) - handler->raw_register(dev); mutex_unlock(&ir_raw_handler_lock); return 0; @@ -619,7 +657,8 @@ void ir_raw_event_unregister(struct rc_dev *dev) mutex_lock(&ir_raw_handler_lock); list_del(&dev->raw->list); list_for_each_entry(handler, &ir_raw_handler_list, list) - if (handler->raw_unregister) + if (handler->raw_unregister && + (handler->protocols & dev->enabled_protocols)) handler->raw_unregister(dev); mutex_unlock(&ir_raw_handler_lock); @@ -632,13 +671,8 @@ void ir_raw_event_unregister(struct rc_dev *dev) int ir_raw_handler_register(struct ir_raw_handler *ir_raw_handler) { - struct ir_raw_event_ctrl *raw; - mutex_lock(&ir_raw_handler_lock); list_add_tail(&ir_raw_handler->list, &ir_raw_handler_list); - if (ir_raw_handler->raw_register) - list_for_each_entry(raw, &ir_raw_client_list, list) - ir_raw_handler->raw_register(raw->dev); atomic64_or(ir_raw_handler->protocols, &available_protocols); mutex_unlock(&ir_raw_handler_lock); @@ -654,9 +688,10 @@ void ir_raw_handler_unregister(struct ir_raw_handler *ir_raw_handler) mutex_lock(&ir_raw_handler_lock); list_del(&ir_raw_handler->list); list_for_each_entry(raw, &ir_raw_client_list, list) { - ir_raw_disable_protocols(raw->dev, protocols); - if (ir_raw_handler->raw_unregister) + if (ir_raw_handler->raw_unregister && + (raw->dev->enabled_protocols & protocols)) ir_raw_handler->raw_unregister(raw->dev); + ir_raw_disable_protocols(raw->dev, protocols); } atomic64_andnot(protocols, &available_protocols); mutex_unlock(&ir_raw_handler_lock); diff --git a/drivers/media/rc/rc-main.c b/drivers/media/rc/rc-main.c index b67be33bd62f..b7071bde670a 100644 --- a/drivers/media/rc/rc-main.c +++ b/drivers/media/rc/rc-main.c @@ -26,50 +26,50 @@ static const struct { unsigned int repeat_period; unsigned int scancode_bits; } protocols[] = { - [RC_PROTO_UNKNOWN] = { .name = "unknown", .repeat_period = 250 }, - [RC_PROTO_OTHER] = { .name = "other", .repeat_period = 250 }, + [RC_PROTO_UNKNOWN] = { .name = "unknown", .repeat_period = 125 }, + [RC_PROTO_OTHER] = { .name = "other", .repeat_period = 125 }, [RC_PROTO_RC5] = { .name = "rc-5", - .scancode_bits = 0x1f7f, .repeat_period = 250 }, + .scancode_bits = 0x1f7f, .repeat_period = 114 }, [RC_PROTO_RC5X_20] = { .name = "rc-5x-20", - .scancode_bits = 0x1f7f3f, .repeat_period = 250 }, + .scancode_bits = 0x1f7f3f, .repeat_period = 114 }, [RC_PROTO_RC5_SZ] = { .name = "rc-5-sz", - .scancode_bits = 0x2fff, .repeat_period = 250 }, + .scancode_bits = 0x2fff, .repeat_period = 114 }, [RC_PROTO_JVC] = { .name = "jvc", - .scancode_bits = 0xffff, .repeat_period = 250 }, + .scancode_bits = 0xffff, .repeat_period = 125 }, [RC_PROTO_SONY12] = { .name = "sony-12", - .scancode_bits = 0x1f007f, .repeat_period = 250 }, + .scancode_bits = 0x1f007f, .repeat_period = 100 }, [RC_PROTO_SONY15] = { .name = "sony-15", - .scancode_bits = 0xff007f, .repeat_period = 250 }, + .scancode_bits = 0xff007f, .repeat_period = 100 }, [RC_PROTO_SONY20] = { .name = "sony-20", - .scancode_bits = 0x1fff7f, .repeat_period = 250 }, + .scancode_bits = 0x1fff7f, .repeat_period = 100 }, [RC_PROTO_NEC] = { .name = "nec", - .scancode_bits = 0xffff, .repeat_period = 250 }, + .scancode_bits = 0xffff, .repeat_period = 110 }, [RC_PROTO_NECX] = { .name = "nec-x", - .scancode_bits = 0xffffff, .repeat_period = 250 }, + .scancode_bits = 0xffffff, .repeat_period = 110 }, [RC_PROTO_NEC32] = { .name = "nec-32", - .scancode_bits = 0xffffffff, .repeat_period = 250 }, + .scancode_bits = 0xffffffff, .repeat_period = 110 }, [RC_PROTO_SANYO] = { .name = "sanyo", - .scancode_bits = 0x1fffff, .repeat_period = 250 }, + .scancode_bits = 0x1fffff, .repeat_period = 125 }, [RC_PROTO_MCIR2_KBD] = { .name = "mcir2-kbd", - .scancode_bits = 0xffff, .repeat_period = 250 }, + .scancode_bits = 0xffffff, .repeat_period = 100 }, [RC_PROTO_MCIR2_MSE] = { .name = "mcir2-mse", - .scancode_bits = 0x1fffff, .repeat_period = 250 }, + .scancode_bits = 0x1fffff, .repeat_period = 100 }, [RC_PROTO_RC6_0] = { .name = "rc-6-0", - .scancode_bits = 0xffff, .repeat_period = 250 }, + .scancode_bits = 0xffff, .repeat_period = 114 }, [RC_PROTO_RC6_6A_20] = { .name = "rc-6-6a-20", - .scancode_bits = 0xfffff, .repeat_period = 250 }, + .scancode_bits = 0xfffff, .repeat_period = 114 }, [RC_PROTO_RC6_6A_24] = { .name = "rc-6-6a-24", - .scancode_bits = 0xffffff, .repeat_period = 250 }, + .scancode_bits = 0xffffff, .repeat_period = 114 }, [RC_PROTO_RC6_6A_32] = { .name = "rc-6-6a-32", - .scancode_bits = 0xffffffff, .repeat_period = 250 }, + .scancode_bits = 0xffffffff, .repeat_period = 114 }, [RC_PROTO_RC6_MCE] = { .name = "rc-6-mce", - .scancode_bits = 0xffff7fff, .repeat_period = 250 }, + .scancode_bits = 0xffff7fff, .repeat_period = 114 }, [RC_PROTO_SHARP] = { .name = "sharp", - .scancode_bits = 0x1fff, .repeat_period = 250 }, - [RC_PROTO_XMP] = { .name = "xmp", .repeat_period = 250 }, - [RC_PROTO_CEC] = { .name = "cec", .repeat_period = 550 }, + .scancode_bits = 0x1fff, .repeat_period = 125 }, + [RC_PROTO_XMP] = { .name = "xmp", .repeat_period = 125 }, + [RC_PROTO_CEC] = { .name = "cec", .repeat_period = 0 }, [RC_PROTO_IMON] = { .name = "imon", - .scancode_bits = 0x7fffffff, .repeat_period = 250 }, + .scancode_bits = 0x7fffffff, .repeat_period = 114 }, }; /* Used to keep track of known keymaps */ @@ -690,7 +690,8 @@ static void ir_timer_repeat(struct timer_list *t) void rc_repeat(struct rc_dev *dev) { unsigned long flags; - unsigned int timeout = protocols[dev->last_protocol].repeat_period; + unsigned int timeout = nsecs_to_jiffies(dev->timeout) + + msecs_to_jiffies(protocols[dev->last_protocol].repeat_period); struct lirc_scancode sc = { .scancode = dev->last_scancode, .rc_proto = dev->last_protocol, .keycode = dev->keypressed ? dev->last_keycode : KEY_RESERVED, @@ -706,7 +707,7 @@ void rc_repeat(struct rc_dev *dev) input_sync(dev->input_dev); if (dev->keypressed) { - dev->keyup_jiffies = jiffies + msecs_to_jiffies(timeout); + dev->keyup_jiffies = jiffies + timeout; mod_timer(&dev->timer_keyup, dev->keyup_jiffies); } @@ -801,7 +802,7 @@ void rc_keydown(struct rc_dev *dev, enum rc_proto protocol, u32 scancode, ir_do_keydown(dev, protocol, scancode, keycode, toggle); if (dev->keypressed) { - dev->keyup_jiffies = jiffies + + dev->keyup_jiffies = jiffies + nsecs_to_jiffies(dev->timeout) + msecs_to_jiffies(protocols[protocol].repeat_period); mod_timer(&dev->timer_keyup, dev->keyup_jiffies); } @@ -1241,6 +1242,9 @@ static ssize_t store_protocols(struct device *device, if (rc < 0) goto out; + if (dev->driver_type == RC_DRIVER_IR_RAW) + ir_raw_load_modules(&new_protocols); + rc = dev->change_protocol(dev, &new_protocols); if (rc < 0) { dev_dbg(&dev->dev, "Error setting protocols to 0x%llx\n", @@ -1248,9 +1252,6 @@ static ssize_t store_protocols(struct device *device, goto out; } - if (dev->driver_type == RC_DRIVER_IR_RAW) - ir_raw_load_modules(&new_protocols); - if (new_protocols != old_protocols) { *current_protocols = new_protocols; dev_dbg(&dev->dev, "Protocols changed to 0x%llx\n", @@ -1647,6 +1648,7 @@ struct rc_dev *rc_allocate_device(enum rc_driver_type type) dev->input_dev->setkeycode = ir_setkeycode; input_set_drvdata(dev->input_dev, dev); + dev->timeout = IR_DEFAULT_TIMEOUT; timer_setup(&dev->timer_keyup, ir_timer_keyup, 0); timer_setup(&dev->timer_repeat, ir_timer_repeat, 0); @@ -1735,6 +1737,9 @@ static int rc_prepare_rx_device(struct rc_dev *dev) if (dev->driver_type == RC_DRIVER_SCANCODE && !dev->change_protocol) dev->enabled_protocols = dev->allowed_protocols; + if (dev->driver_type == RC_DRIVER_IR_RAW) + ir_raw_load_modules(&rc_proto); + if (dev->change_protocol) { rc = dev->change_protocol(dev, &rc_proto); if (rc < 0) @@ -1742,9 +1747,6 @@ static int rc_prepare_rx_device(struct rc_dev *dev) dev->enabled_protocols = rc_proto; } - if (dev->driver_type == RC_DRIVER_IR_RAW) - ir_raw_load_modules(&rc_proto); - set_bit(EV_KEY, dev->input_dev->evbit); set_bit(EV_REP, dev->input_dev->evbit); set_bit(EV_MSC, dev->input_dev->evbit); diff --git a/drivers/media/rc/st_rc.c b/drivers/media/rc/st_rc.c index d2efd7b2c3bc..c855b177103c 100644 --- a/drivers/media/rc/st_rc.c +++ b/drivers/media/rc/st_rc.c @@ -96,19 +96,24 @@ static void st_rc_send_lirc_timeout(struct rc_dev *rdev) static irqreturn_t st_rc_rx_interrupt(int irq, void *data) { + unsigned long timeout; unsigned int symbol, mark = 0; struct st_rc_device *dev = data; int last_symbol = 0; - u32 status; + u32 status, int_status; DEFINE_IR_RAW_EVENT(ev); if (dev->irq_wake) pm_wakeup_event(dev->dev, 0); - status = readl(dev->rx_base + IRB_RX_STATUS); + /* FIXME: is 10ms good enough ? */ + timeout = jiffies + msecs_to_jiffies(10); + do { + status = readl(dev->rx_base + IRB_RX_STATUS); + if (!(status & (IRB_FIFO_NOT_EMPTY | IRB_OVERFLOW))) + break; - while (status & (IRB_FIFO_NOT_EMPTY | IRB_OVERFLOW)) { - u32 int_status = readl(dev->rx_base + IRB_RX_INT_STATUS); + int_status = readl(dev->rx_base + IRB_RX_INT_STATUS); if (unlikely(int_status & IRB_RX_OVERRUN_INT)) { /* discard the entire collection in case of errors! */ ir_raw_event_reset(dev->rdev); @@ -148,8 +153,7 @@ static irqreturn_t st_rc_rx_interrupt(int irq, void *data) } last_symbol = 0; - status = readl(dev->rx_base + IRB_RX_STATUS); - } + } while (time_is_after_jiffies(timeout)); writel(IRB_RX_INTS, dev->rx_base + IRB_RX_INT_CLEAR); diff --git a/drivers/media/spi/cxd2880-spi.c b/drivers/media/spi/cxd2880-spi.c index 4df3bd312f48..11ce5101e19f 100644 --- a/drivers/media/spi/cxd2880-spi.c +++ b/drivers/media/spi/cxd2880-spi.c @@ -60,14 +60,13 @@ DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr); static int cxd2880_write_spi(struct spi_device *spi, u8 *data, u32 size) { struct spi_message msg; - struct spi_transfer tx; + struct spi_transfer tx = {}; if (!spi || !data) { pr_err("invalid arg\n"); return -EINVAL; } - memset(&tx, 0, sizeof(tx)); tx.tx_buf = data; tx.len = size; @@ -88,7 +87,7 @@ static int cxd2880_write_reg(struct spi_device *spi, pr_err("invalid arg\n"); return -EINVAL; } - if (size > BURST_WRITE_MAX) { + if (size > BURST_WRITE_MAX || size > U8_MAX) { pr_err("data size > WRITE_MAX\n"); return -EINVAL; } @@ -101,24 +100,14 @@ static int cxd2880_write_reg(struct spi_device *spi, send_data[0] = 0x0e; write_data_top = data; - while (size > 0) { - send_data[1] = sub_address; - if (size > 255) - send_data[2] = 255; - else - send_data[2] = (u8)size; + send_data[1] = sub_address; + send_data[2] = (u8)size; - memcpy(&send_data[3], write_data_top, send_data[2]); + memcpy(&send_data[3], write_data_top, send_data[2]); - ret = cxd2880_write_spi(spi, send_data, send_data[2] + 3); - if (ret) { - pr_err("write spi failed %d\n", ret); - break; - } - sub_address += send_data[2]; - write_data_top += send_data[2]; - size -= send_data[2]; - } + ret = cxd2880_write_spi(spi, send_data, send_data[2] + 3); + if (ret) + pr_err("write spi failed %d\n", ret); return ret; } @@ -130,7 +119,7 @@ static int cxd2880_spi_read_ts(struct spi_device *spi, int ret; u8 data[3]; struct spi_message message; - struct spi_transfer transfer[2]; + struct spi_transfer transfer[2] = {}; if (!spi || !read_data || !packet_num) { pr_err("invalid arg\n"); @@ -146,7 +135,6 @@ static int cxd2880_spi_read_ts(struct spi_device *spi, data[2] = packet_num; spi_message_init(&message); - memset(transfer, 0, sizeof(transfer)); transfer[0].len = 3; transfer[0].tx_buf = data; @@ -383,7 +371,7 @@ static int cxd2880_start_feed(struct dvb_demux_feed *feed) } } if (i == CXD2880_MAX_FILTER_SIZE) { - pr_err("PID filter is full. Assumed bug.\n"); + pr_err("PID filter is full.\n"); return -EINVAL; } if (!dvb_spi->all_pid_feed_count) diff --git a/drivers/media/tuners/Kconfig b/drivers/media/tuners/Kconfig index 6687514df97f..147f3cd0bb95 100644 --- a/drivers/media/tuners/Kconfig +++ b/drivers/media/tuners/Kconfig @@ -284,4 +284,11 @@ config MEDIA_TUNER_QM1D1C0042 default m if !MEDIA_SUBDRV_AUTOSELECT help Sharp QM1D1C0042 trellis coded 8PSK tuner driver. + +config MEDIA_TUNER_QM1D1B0004 + tristate "Sharp QM1D1B0004 tuner" + depends on MEDIA_SUPPORT && I2C + default m if !MEDIA_SUBDRV_AUTOSELECT + help + Sharp QM1D1B0004 ISDB-S tuner driver. endmenu diff --git a/drivers/media/tuners/Makefile b/drivers/media/tuners/Makefile index 0ff21f1c7eed..7b4f8423501e 100644 --- a/drivers/media/tuners/Makefile +++ b/drivers/media/tuners/Makefile @@ -41,6 +41,7 @@ obj-$(CONFIG_MEDIA_TUNER_IT913X) += it913x.o obj-$(CONFIG_MEDIA_TUNER_R820T) += r820t.o obj-$(CONFIG_MEDIA_TUNER_MXL301RF) += mxl301rf.o obj-$(CONFIG_MEDIA_TUNER_QM1D1C0042) += qm1d1c0042.o +obj-$(CONFIG_MEDIA_TUNER_QM1D1B0004) += qm1d1b0004.o obj-$(CONFIG_MEDIA_TUNER_M88RS6000T) += m88rs6000t.o obj-$(CONFIG_MEDIA_TUNER_TDA18250) += tda18250.o diff --git a/drivers/media/tuners/mxl301rf.c b/drivers/media/tuners/mxl301rf.c index 1575a5db776a..57b0e4862aaf 100644 --- a/drivers/media/tuners/mxl301rf.c +++ b/drivers/media/tuners/mxl301rf.c @@ -1,17 +1,8 @@ +// SPDX-License-Identifier: GPL-2.0 /* * MaxLinear MxL301RF OFDM tuner driver * * Copyright (C) 2014 Akihiro Tsukada <tskd08@gmail.com> - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation version 2. - * - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. */ /* diff --git a/drivers/media/tuners/mxl301rf.h b/drivers/media/tuners/mxl301rf.h index d32d4e8dc448..1d5bb10ba07a 100644 --- a/drivers/media/tuners/mxl301rf.h +++ b/drivers/media/tuners/mxl301rf.h @@ -1,17 +1,8 @@ +/* SPDX-License-Identifier: GPL-2.0 */ /* * MaxLinear MxL301RF OFDM tuner driver * * Copyright (C) 2014 Akihiro Tsukada <tskd08@gmail.com> - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation version 2. - * - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. */ #ifndef MXL301RF_H diff --git a/drivers/media/tuners/qm1d1b0004.c b/drivers/media/tuners/qm1d1b0004.c new file mode 100644 index 000000000000..b4495cc1626b --- /dev/null +++ b/drivers/media/tuners/qm1d1b0004.c @@ -0,0 +1,266 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Sharp QM1D1B0004 satellite tuner + * + * Copyright (C) 2014 Akihiro Tsukada <tskd08@gmail.com> + * + * based on (former) drivers/media/pci/pt1/va1j5jf8007s.c. + */ + +/* + * Note: + * Since the data-sheet of this tuner chip is not available, + * this driver lacks some tuner_ops and config options. + * In addition, the implementation might be dependent on the specific use + * in the FE module: VA1J5JF8007S and/or in the product: Earthsoft PT1/PT2. + */ + +#include <linux/kernel.h> +#include <linux/module.h> +#include <media/dvb_frontend.h> +#include "qm1d1b0004.h" + +/* + * Tuner I/F (copied from the former va1j5jf8007s.c) + * b[0] I2C addr + * b[1] "0":1, BG:2, divider_quotient[7:3]:5 + * b[2] divider_quotient[2:0]:3, divider_remainder:5 + * b[3] "111":3, LPF[3:2]:2, TM:1, "0":1, REF:1 + * b[4] BANDX, PSC:1, LPF[1:0]:2, DIV:1, "0":1 + * + * PLL frequency step := + * REF == 0 -> PLL XTL frequency(4MHz) / 8 + * REF == 1 -> PLL XTL frequency(4MHz) / 4 + * + * PreScaler := + * PSC == 0 -> x32 + * PSC == 1 -> x16 + * + * divider_quotient := (frequency / PLL frequency step) / PreScaler + * divider_remainder := (frequency / PLL frequency step) % PreScaler + * + * LPF := LPF Frequency / 1000 / 2 - 2 + * LPF Frequency @ baudrate=28.86Mbps = 30000 + * + * band (1..9) + * band 1 (freq < 986000) -> DIV:1, BANDX:5, PSC:1 + * band 2 (freq < 1072000) -> DIV:1, BANDX:6, PSC:1 + * band 3 (freq < 1154000) -> DIV:1, BANDX:7, PSC:0 + * band 4 (freq < 1291000) -> DIV:0, BANDX:1, PSC:0 + * band 5 (freq < 1447000) -> DIV:0, BANDX:2, PSC:0 + * band 6 (freq < 1615000) -> DIV:0, BANDX:3, PSC:0 + * band 7 (freq < 1791000) -> DIV:0, BANDX:4, PSC:0 + * band 8 (freq < 1972000) -> DIV:0, BANDX:5, PSC:0 + * band 9 (freq < 2150000) -> DIV:0, BANDX:6, PSC:0 + */ + +#define QM1D1B0004_PSC_MASK (1 << 4) + +#define QM1D1B0004_XTL_FREQ 4000 +#define QM1D1B0004_LPF_FALLBACK 30000 + +#if 0 /* Currently unused */ +static const struct qm1d1b0004_config default_cfg = { + .lpf_freq = QM1D1B0004_CFG_LPF_DFLT, + .half_step = false, +}; +#endif + +struct qm1d1b0004_state { + struct qm1d1b0004_config cfg; + struct i2c_client *i2c; +}; + + +struct qm1d1b0004_cb_map { + u32 frequency; + u8 cb; +}; + +static const struct qm1d1b0004_cb_map cb_maps[] = { + { 986000, 0xb2 }, + { 1072000, 0xd2 }, + { 1154000, 0xe2 }, + { 1291000, 0x20 }, + { 1447000, 0x40 }, + { 1615000, 0x60 }, + { 1791000, 0x80 }, + { 1972000, 0xa0 }, +}; + +static u8 lookup_cb(u32 frequency) +{ + int i; + const struct qm1d1b0004_cb_map *map; + + for (i = 0; i < ARRAY_SIZE(cb_maps); i++) { + map = &cb_maps[i]; + if (frequency < map->frequency) + return map->cb; + } + return 0xc0; +} + +static int qm1d1b0004_set_params(struct dvb_frontend *fe) +{ + struct qm1d1b0004_state *state; + u32 frequency, pll, lpf_freq; + u16 word; + u8 buf[4], cb, lpf; + int ret; + + state = fe->tuner_priv; + frequency = fe->dtv_property_cache.frequency; + + pll = QM1D1B0004_XTL_FREQ / 4; + if (state->cfg.half_step) + pll /= 2; + word = DIV_ROUND_CLOSEST(frequency, pll); + cb = lookup_cb(frequency); + if (cb & QM1D1B0004_PSC_MASK) + word = (word << 1 & ~0x1f) | (word & 0x0f); + + /* step.1: set frequency with BG:2, TM:0(4MHZ), LPF:4MHz */ + buf[0] = 0x40 | word >> 8; + buf[1] = word; + /* inconsisnten with the above I/F doc. maybe the doc is wrong */ + buf[2] = 0xe0 | state->cfg.half_step; + buf[3] = cb; + ret = i2c_master_send(state->i2c, buf, 4); + if (ret < 0) + return ret; + + /* step.2: set TM:1 */ + buf[0] = 0xe4 | state->cfg.half_step; + ret = i2c_master_send(state->i2c, buf, 1); + if (ret < 0) + return ret; + msleep(20); + + /* step.3: set LPF */ + lpf_freq = state->cfg.lpf_freq; + if (lpf_freq == QM1D1B0004_CFG_LPF_DFLT) + lpf_freq = fe->dtv_property_cache.symbol_rate / 1000; + if (lpf_freq == 0) + lpf_freq = QM1D1B0004_LPF_FALLBACK; + lpf = DIV_ROUND_UP(lpf_freq, 2000) - 2; + buf[0] = 0xe4 | ((lpf & 0x0c) << 1) | state->cfg.half_step; + buf[1] = cb | ((lpf & 0x03) << 2); + ret = i2c_master_send(state->i2c, buf, 2); + if (ret < 0) + return ret; + + /* step.4: read PLL lock? */ + buf[0] = 0; + ret = i2c_master_recv(state->i2c, buf, 1); + if (ret < 0) + return ret; + return 0; +} + + +static int qm1d1b0004_set_config(struct dvb_frontend *fe, void *priv_cfg) +{ + struct qm1d1b0004_state *state; + + state = fe->tuner_priv; + memcpy(&state->cfg, priv_cfg, sizeof(state->cfg)); + return 0; +} + + +static int qm1d1b0004_init(struct dvb_frontend *fe) +{ + struct qm1d1b0004_state *state; + u8 buf[2] = {0xf8, 0x04}; + + state = fe->tuner_priv; + if (state->cfg.half_step) + buf[0] |= 0x01; + + return i2c_master_send(state->i2c, buf, 2); +} + + +static const struct dvb_tuner_ops qm1d1b0004_ops = { + .info = { + .name = "Sharp qm1d1b0004", + + .frequency_min = 950000, + .frequency_max = 2150000, + }, + + .init = qm1d1b0004_init, + + .set_params = qm1d1b0004_set_params, + .set_config = qm1d1b0004_set_config, +}; + +static int +qm1d1b0004_probe(struct i2c_client *client, const struct i2c_device_id *id) +{ + struct dvb_frontend *fe; + struct qm1d1b0004_config *cfg; + struct qm1d1b0004_state *state; + int ret; + + cfg = client->dev.platform_data; + fe = cfg->fe; + i2c_set_clientdata(client, fe); + + fe->tuner_priv = kzalloc(sizeof(struct qm1d1b0004_state), GFP_KERNEL); + if (!fe->tuner_priv) { + ret = -ENOMEM; + goto err_mem; + } + + memcpy(&fe->ops.tuner_ops, &qm1d1b0004_ops, sizeof(fe->ops.tuner_ops)); + + state = fe->tuner_priv; + state->i2c = client; + ret = qm1d1b0004_set_config(fe, cfg); + if (ret != 0) + goto err_priv; + + dev_info(&client->dev, "Sharp QM1D1B0004 attached.\n"); + return 0; + +err_priv: + kfree(fe->tuner_priv); +err_mem: + fe->tuner_priv = NULL; + return ret; +} + +static int qm1d1b0004_remove(struct i2c_client *client) +{ + struct dvb_frontend *fe; + + fe = i2c_get_clientdata(client); + kfree(fe->tuner_priv); + fe->tuner_priv = NULL; + return 0; +} + + +static const struct i2c_device_id qm1d1b0004_id[] = { + {"qm1d1b0004", 0}, + {} +}; + +MODULE_DEVICE_TABLE(i2c, qm1d1b0004_id); + +static struct i2c_driver qm1d1b0004_driver = { + .driver = { + .name = "qm1d1b0004", + }, + .probe = qm1d1b0004_probe, + .remove = qm1d1b0004_remove, + .id_table = qm1d1b0004_id, +}; + +module_i2c_driver(qm1d1b0004_driver); + +MODULE_DESCRIPTION("Sharp QM1D1B0004"); +MODULE_AUTHOR("Akihiro Tsukada"); +MODULE_LICENSE("GPL"); diff --git a/drivers/media/tuners/qm1d1b0004.h b/drivers/media/tuners/qm1d1b0004.h new file mode 100644 index 000000000000..7734ed109a22 --- /dev/null +++ b/drivers/media/tuners/qm1d1b0004.h @@ -0,0 +1,24 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * Sharp QM1D1B0004 satellite tuner + * + * Copyright (C) 2014 Akihiro Tsukada <tskd08@gmail.com> + */ + +#ifndef QM1D1B0004_H +#define QM1D1B0004_H + +#include <media/dvb_frontend.h> + +struct qm1d1b0004_config { + struct dvb_frontend *fe; + + u32 lpf_freq; /* LPF frequency[kHz]. Default: symbol rate */ + bool half_step; /* use PLL frequency step of 500Hz istead of 1000Hz */ +}; + +/* special values indicating to use the default in qm1d1b0004_config */ +#define QM1D1B0004_CFG_PLL_DFLT 0 +#define QM1D1B0004_CFG_LPF_DFLT 0 + +#endif diff --git a/drivers/media/tuners/qm1d1c0042.c b/drivers/media/tuners/qm1d1c0042.c index 9af2a155cfca..642a065b9a07 100644 --- a/drivers/media/tuners/qm1d1c0042.c +++ b/drivers/media/tuners/qm1d1c0042.c @@ -1,17 +1,8 @@ +// SPDX-License-Identifier: GPL-2.0 /* * Sharp QM1D1C0042 8PSK tuner driver * * Copyright (C) 2014 Akihiro Tsukada <tskd08@gmail.com> - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation version 2. - * - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. */ /* diff --git a/drivers/media/tuners/qm1d1c0042.h b/drivers/media/tuners/qm1d1c0042.h index 8331f8baa094..b22fa98bf56e 100644 --- a/drivers/media/tuners/qm1d1c0042.h +++ b/drivers/media/tuners/qm1d1c0042.h @@ -1,17 +1,8 @@ +/* SPDX-License-Identifier: GPL-2.0 */ /* * Sharp QM1D1C0042 8PSK tuner driver * * Copyright (C) 2014 Akihiro Tsukada <tskd08@gmail.com> - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation version 2. - * - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. */ #ifndef QM1D1C0042_H diff --git a/drivers/media/usb/cx231xx/Kconfig b/drivers/media/usb/cx231xx/Kconfig index 6276d9b2198b..0f13192634c7 100644 --- a/drivers/media/usb/cx231xx/Kconfig +++ b/drivers/media/usb/cx231xx/Kconfig @@ -1,13 +1,11 @@ config VIDEO_CX231XX tristate "Conexant cx231xx USB video capture support" - depends on VIDEO_DEV && I2C + depends on VIDEO_DEV && I2C && I2C_MUX select VIDEO_TUNER select VIDEO_TVEEPROM - depends on RC_CORE select VIDEOBUF_VMALLOC select VIDEO_CX25840 select VIDEO_CX2341X - select I2C_MUX ---help--- This is a video4linux driver for Conexant 231xx USB based TV cards. @@ -42,7 +40,6 @@ config VIDEO_CX231XX_ALSA config VIDEO_CX231XX_DVB tristate "DVB/ATSC Support for Cx231xx based TV cards" depends on VIDEO_CX231XX && DVB_CORE - select VIDEOBUF_DVB select MEDIA_TUNER_XC5000 if MEDIA_SUBDRV_AUTOSELECT select MEDIA_TUNER_TDA18271 if MEDIA_SUBDRV_AUTOSELECT select DVB_MB86A20S if MEDIA_SUBDRV_AUTOSELECT diff --git a/drivers/media/usb/cx231xx/cx231xx-cards.c b/drivers/media/usb/cx231xx/cx231xx-cards.c index c76b2101193c..a431a998d58f 100644 --- a/drivers/media/usb/cx231xx/cx231xx-cards.c +++ b/drivers/media/usb/cx231xx/cx231xx-cards.c @@ -715,7 +715,7 @@ struct cx231xx_board cx231xx_boards[] = { .tuner_i2c_master = I2C_1_MUX_3, .demod_i2c_master = I2C_1_MUX_3, .has_dvb = 1, - .demod_addr = 0x0e, + .demod_addr = 0x64, /* 0xc8 >> 1 */ .norm = V4L2_STD_PAL, .input = {{ @@ -754,7 +754,7 @@ struct cx231xx_board cx231xx_boards[] = { .tuner_i2c_master = I2C_1_MUX_3, .demod_i2c_master = I2C_1_MUX_3, .has_dvb = 1, - .demod_addr = 0x0e, + .demod_addr = 0x64, /* 0xc8 >> 1 */ .norm = V4L2_STD_PAL, .input = {{ @@ -793,7 +793,7 @@ struct cx231xx_board cx231xx_boards[] = { .tuner_i2c_master = I2C_1_MUX_3, .demod_i2c_master = I2C_1_MUX_3, .has_dvb = 1, - .demod_addr = 0x0e, + .demod_addr = 0x59, /* 0xb2 >> 1 */ .norm = V4L2_STD_NTSC, .input = {{ @@ -1024,6 +1024,9 @@ struct usb_device_id cx231xx_id_table[] = { .driver_info = CX231XX_BOARD_CNXT_RDE_250}, {USB_DEVICE(0x0572, 0x58A0), .driver_info = CX231XX_BOARD_CNXT_RDU_250}, + /* AverMedia DVD EZMaker 7 */ + {USB_DEVICE(0x07ca, 0xc039), + .driver_info = CX231XX_BOARD_CNXT_VIDEO_GRABBER}, {USB_DEVICE(0x2040, 0xb110), .driver_info = CX231XX_BOARD_HAUPPAUGE_USB2_FM_PAL}, {USB_DEVICE(0x2040, 0xb111), diff --git a/drivers/media/usb/cx231xx/cx231xx-dvb.c b/drivers/media/usb/cx231xx/cx231xx-dvb.c index 67ed66712d05..89357cb08b1a 100644 --- a/drivers/media/usb/cx231xx/cx231xx-dvb.c +++ b/drivers/media/usb/cx231xx/cx231xx-dvb.c @@ -23,8 +23,12 @@ #include <linux/kernel.h> #include <linux/slab.h> +#include <media/dvbdev.h> +#include <media/dmxdev.h> +#include <media/dvb_demux.h> +#include <media/dvb_net.h> +#include <media/dvb_frontend.h> #include <media/v4l2-common.h> -#include <media/videobuf-vmalloc.h> #include <media/tuner.h> #include "xc5000.h" @@ -156,10 +160,8 @@ static struct tda18271_config pv_tda18271_config = { }; static struct lgdt3306a_config hauppauge_955q_lgdt3306a_config = { - .i2c_addr = 0x59, .qam_if_khz = 4000, .vsb_if_khz = 3250, - .deny_i2c_rptr = 1, .spectral_inversion = 1, .mpeg_mode = LGDT3306A_MPEG_SERIAL, .tpclk_edge = LGDT3306A_TPCLK_RISING_EDGE, @@ -600,7 +602,6 @@ fail_adapter: static void unregister_dvb(struct cx231xx_dvb *dvb) { - struct i2c_client *client; dvb_net_release(&dvb->net); dvb->demux.dmx.remove_frontend(&dvb->demux.dmx, &dvb->fe_mem); dvb->demux.dmx.remove_frontend(&dvb->demux.dmx, &dvb->fe_hw); @@ -613,23 +614,15 @@ static void unregister_dvb(struct cx231xx_dvb *dvb) dvb_frontend_detach(dvb->frontend[1]); dvb_frontend_detach(dvb->frontend[0]); dvb_unregister_adapter(&dvb->adapter); + /* remove I2C tuner */ - client = dvb->i2c_client_tuner; - if (client) { - module_put(client->dev.driver->owner); - i2c_unregister_device(client); - } - /* remove I2C demod */ - client = dvb->i2c_client_demod[1]; - if (client) { - module_put(client->dev.driver->owner); - i2c_unregister_device(client); - } - client = dvb->i2c_client_demod[0]; - if (client) { - module_put(client->dev.driver->owner); - i2c_unregister_device(client); - } + dvb_module_release(dvb->i2c_client_tuner); + dvb->i2c_client_tuner = NULL; + /* remove I2C demod(s) */ + dvb_module_release(dvb->i2c_client_demod[1]); + dvb->i2c_client_demod[1] = NULL; + dvb_module_release(dvb->i2c_client_demod[0]); + dvb->i2c_client_demod[0] = NULL; } static int dvb_init(struct cx231xx *dev) @@ -638,6 +631,8 @@ static int dvb_init(struct cx231xx *dev) struct cx231xx_dvb *dvb; struct i2c_adapter *tuner_i2c; struct i2c_adapter *demod_i2c; + struct i2c_client *client; + struct i2c_adapter *adapter; if (!dev->board.has_dvb) { /* This device does not support the extension */ @@ -728,7 +723,7 @@ static int dvb_init(struct cx231xx *dev) dvb->frontend[0]->callback = cx231xx_tuner_callback; if (!dvb_attach(tda18271_attach, dev->dvb->frontend[0], - 0x60, tuner_i2c, + dev->board.tuner_addr, tuner_i2c, &cnxt_rde253s_tunerconfig)) { result = -EINVAL; goto out_free; @@ -752,7 +747,7 @@ static int dvb_init(struct cx231xx *dev) dvb->frontend[0]->callback = cx231xx_tuner_callback; if (!dvb_attach(tda18271_attach, dev->dvb->frontend[0], - 0x60, tuner_i2c, + dev->board.tuner_addr, tuner_i2c, &cnxt_rde253s_tunerconfig)) { result = -EINVAL; goto out_free; @@ -779,41 +774,27 @@ static int dvb_init(struct cx231xx *dev) dvb->frontend[0]->callback = cx231xx_tuner_callback; dvb_attach(tda18271_attach, dev->dvb->frontend[0], - 0x60, tuner_i2c, + dev->board.tuner_addr, tuner_i2c, &hcw_tda18271_config); break; case CX231XX_BOARD_HAUPPAUGE_930C_HD_1113xx: { - struct i2c_client *client; - struct i2c_board_info info; - struct si2165_platform_data si2165_pdata; + struct si2165_platform_data si2165_pdata = {}; /* attach demod */ - memset(&si2165_pdata, 0, sizeof(si2165_pdata)); si2165_pdata.fe = &dev->dvb->frontend[0]; si2165_pdata.chip_mode = SI2165_MODE_PLL_XTAL; si2165_pdata.ref_freq_hz = 16000000; - memset(&info, 0, sizeof(struct i2c_board_info)); - strlcpy(info.type, "si2165", I2C_NAME_SIZE); - info.addr = 0x64; - info.platform_data = &si2165_pdata; - request_module(info.type); - client = i2c_new_device(demod_i2c, &info); - if (!client || !client->dev.driver || !dev->dvb->frontend[0]) { - dev_err(dev->dev, - "Failed to attach SI2165 front end\n"); - result = -EINVAL; - goto out_free; - } - - if (!try_module_get(client->dev.driver->owner)) { - i2c_unregister_device(client); + /* perform probe/init/attach */ + client = dvb_module_probe("si2165", NULL, demod_i2c, + dev->board.demod_addr, + &si2165_pdata); + if (!client) { result = -ENODEV; goto out_free; } - dvb->i2c_client_demod[0] = client; dev->dvb->frontend[0]->ops.i2c_gate_ctrl = NULL; @@ -822,8 +803,7 @@ static int dvb_init(struct cx231xx *dev) dvb->frontend[0]->callback = cx231xx_tuner_callback; dvb_attach(tda18271_attach, dev->dvb->frontend[0], - 0x60, - tuner_i2c, + dev->board.tuner_addr, tuner_i2c, &hcw_tda18271_config); dev->cx231xx_reset_analog_tuner = NULL; @@ -831,74 +811,45 @@ static int dvb_init(struct cx231xx *dev) } case CX231XX_BOARD_HAUPPAUGE_930C_HD_1114xx: { - struct i2c_client *client; - struct i2c_board_info info; - struct si2165_platform_data si2165_pdata; - struct si2157_config si2157_config; + struct si2165_platform_data si2165_pdata = {}; + struct si2157_config si2157_config = {}; /* attach demod */ - memset(&si2165_pdata, 0, sizeof(si2165_pdata)); si2165_pdata.fe = &dev->dvb->frontend[0]; si2165_pdata.chip_mode = SI2165_MODE_PLL_EXT; si2165_pdata.ref_freq_hz = 24000000; - memset(&info, 0, sizeof(struct i2c_board_info)); - strlcpy(info.type, "si2165", I2C_NAME_SIZE); - info.addr = 0x64; - info.platform_data = &si2165_pdata; - request_module(info.type); - client = i2c_new_device(demod_i2c, &info); - if (!client || !client->dev.driver || !dev->dvb->frontend[0]) { - dev_err(dev->dev, - "Failed to attach SI2165 front end\n"); - result = -EINVAL; - goto out_free; - } - - if (!try_module_get(client->dev.driver->owner)) { - i2c_unregister_device(client); + /* perform probe/init/attach */ + client = dvb_module_probe("si2165", NULL, demod_i2c, + dev->board.demod_addr, + &si2165_pdata); + if (!client) { result = -ENODEV; goto out_free; } - dvb->i2c_client_demod[0] = client; - memset(&info, 0, sizeof(struct i2c_board_info)); - dev->dvb->frontend[0]->ops.i2c_gate_ctrl = NULL; /* define general-purpose callback pointer */ dvb->frontend[0]->callback = cx231xx_tuner_callback; /* attach tuner */ - memset(&si2157_config, 0, sizeof(si2157_config)); si2157_config.fe = dev->dvb->frontend[0]; #ifdef CONFIG_MEDIA_CONTROLLER_DVB si2157_config.mdev = dev->media_dev; #endif si2157_config.if_port = 1; si2157_config.inversion = true; - strlcpy(info.type, "si2157", I2C_NAME_SIZE); - info.addr = 0x60; - info.platform_data = &si2157_config; - request_module("si2157"); - - client = i2c_new_device( - tuner_i2c, - &info); - if (client == NULL || client->dev.driver == NULL) { - dvb_frontend_detach(dev->dvb->frontend[0]); - result = -ENODEV; - goto out_free; - } - if (!try_module_get(client->dev.driver->owner)) { - i2c_unregister_device(client); - dvb_frontend_detach(dev->dvb->frontend[0]); + /* perform probe/init/attach */ + client = dvb_module_probe("si2157", NULL, tuner_i2c, + dev->board.tuner_addr, + &si2157_config); + if (!client) { result = -ENODEV; goto out_free; } - dev->cx231xx_reset_analog_tuner = NULL; dev->dvb->i2c_client_tuner = client; @@ -906,23 +857,22 @@ static int dvb_init(struct cx231xx *dev) } case CX231XX_BOARD_HAUPPAUGE_955Q: { - struct i2c_client *client; - struct i2c_board_info info; - struct si2157_config si2157_config; - - memset(&info, 0, sizeof(struct i2c_board_info)); + struct si2157_config si2157_config = {}; + struct lgdt3306a_config lgdt3306a_config = {}; - dev->dvb->frontend[0] = dvb_attach(lgdt3306a_attach, - &hauppauge_955q_lgdt3306a_config, - demod_i2c - ); + lgdt3306a_config = hauppauge_955q_lgdt3306a_config; + lgdt3306a_config.fe = &dev->dvb->frontend[0]; + lgdt3306a_config.i2c_adapter = &adapter; - if (!dev->dvb->frontend[0]) { - dev_err(dev->dev, - "Failed to attach LGDT3306A frontend.\n"); - result = -EINVAL; + /* perform probe/init/attach */ + client = dvb_module_probe("lgdt3306a", NULL, demod_i2c, + dev->board.demod_addr, + &lgdt3306a_config); + if (!client) { + result = -ENODEV; goto out_free; } + dvb->i2c_client_demod[0] = client; dev->dvb->frontend[0]->ops.i2c_gate_ctrl = NULL; @@ -930,34 +880,21 @@ static int dvb_init(struct cx231xx *dev) dvb->frontend[0]->callback = cx231xx_tuner_callback; /* attach tuner */ - memset(&si2157_config, 0, sizeof(si2157_config)); si2157_config.fe = dev->dvb->frontend[0]; #ifdef CONFIG_MEDIA_CONTROLLER_DVB si2157_config.mdev = dev->media_dev; #endif si2157_config.if_port = 1; si2157_config.inversion = true; - strlcpy(info.type, "si2157", I2C_NAME_SIZE); - info.addr = 0x60; - info.platform_data = &si2157_config; - request_module("si2157"); - - client = i2c_new_device( - tuner_i2c, - &info); - if (client == NULL || client->dev.driver == NULL) { - dvb_frontend_detach(dev->dvb->frontend[0]); - result = -ENODEV; - goto out_free; - } - if (!try_module_get(client->dev.driver->owner)) { - i2c_unregister_device(client); - dvb_frontend_detach(dev->dvb->frontend[0]); + /* perform probe/init/attach */ + client = dvb_module_probe("si2157", NULL, tuner_i2c, + dev->board.tuner_addr, + &si2157_config); + if (!client) { result = -ENODEV; goto out_free; } - dev->cx231xx_reset_analog_tuner = NULL; dev->dvb->i2c_client_tuner = client; @@ -985,7 +922,7 @@ static int dvb_init(struct cx231xx *dev) dvb->frontend[0]->callback = cx231xx_tuner_callback; dvb_attach(tda18271_attach, dev->dvb->frontend[0], - 0x60, tuner_i2c, + dev->board.tuner_addr, tuner_i2c, &pv_tda18271_config); break; @@ -993,9 +930,6 @@ static int dvb_init(struct cx231xx *dev) { struct si2157_config si2157_config = {}; struct si2168_config si2168_config = {}; - struct i2c_board_info info = {}; - struct i2c_client *client; - struct i2c_adapter *adapter; /* attach demodulator chip */ si2168_config.ts_mode = SI2168_TS_SERIAL; /* from *.inf file */ @@ -1003,24 +937,14 @@ static int dvb_init(struct cx231xx *dev) si2168_config.i2c_adapter = &adapter; si2168_config.ts_clock_inv = true; - strlcpy(info.type, "si2168", sizeof(info.type)); - info.addr = dev->board.demod_addr; - info.platform_data = &si2168_config; - - request_module(info.type); - client = i2c_new_device(demod_i2c, &info); - - if (client == NULL || client->dev.driver == NULL) { + /* perform probe/init/attach */ + client = dvb_module_probe("si2168", NULL, demod_i2c, + dev->board.demod_addr, + &si2168_config); + if (!client) { result = -ENODEV; goto out_free; } - - if (!try_module_get(client->dev.driver->owner)) { - i2c_unregister_device(client); - result = -ENODEV; - goto out_free; - } - dvb->i2c_client_demod[0] = client; /* attach tuner chip */ @@ -1031,37 +955,20 @@ static int dvb_init(struct cx231xx *dev) si2157_config.if_port = 1; si2157_config.inversion = false; - memset(&info, 0, sizeof(info)); - strlcpy(info.type, "si2157", sizeof(info.type)); - info.addr = dev->board.tuner_addr; - info.platform_data = &si2157_config; - - request_module(info.type); - client = i2c_new_device(tuner_i2c, &info); - - if (client == NULL || client->dev.driver == NULL) { - module_put(dvb->i2c_client_demod[0]->dev.driver->owner); - i2c_unregister_device(dvb->i2c_client_demod[0]); - result = -ENODEV; - goto out_free; - } - - if (!try_module_get(client->dev.driver->owner)) { - i2c_unregister_device(client); - module_put(dvb->i2c_client_demod[0]->dev.driver->owner); - i2c_unregister_device(dvb->i2c_client_demod[0]); + /* perform probe/init/attach */ + client = dvb_module_probe("si2157", NULL, tuner_i2c, + dev->board.tuner_addr, + &si2157_config); + if (!client) { result = -ENODEV; goto out_free; } - dev->cx231xx_reset_analog_tuner = NULL; dev->dvb->i2c_client_tuner = client; break; } case CX231XX_BOARD_ASTROMETA_T2HYBRID: { - struct i2c_client *client; - struct i2c_board_info info = {}; struct mn88473_config mn88473_config = {}; /* attach demodulator chip */ @@ -1069,24 +976,14 @@ static int dvb_init(struct cx231xx *dev) mn88473_config.xtal = 25000000; mn88473_config.fe = &dev->dvb->frontend[0]; - strlcpy(info.type, "mn88473", sizeof(info.type)); - info.addr = dev->board.demod_addr; - info.platform_data = &mn88473_config; - - request_module(info.type); - client = i2c_new_device(demod_i2c, &info); - - if (client == NULL || client->dev.driver == NULL) { - result = -ENODEV; - goto out_free; - } - - if (!try_module_get(client->dev.driver->owner)) { - i2c_unregister_device(client); + /* perform probe/init/attach */ + client = dvb_module_probe("mn88473", NULL, demod_i2c, + dev->board.demod_addr, + &mn88473_config); + if (!client) { result = -ENODEV; goto out_free; } - dvb->i2c_client_demod[0] = client; /* define general-purpose callback pointer */ @@ -1100,9 +997,6 @@ static int dvb_init(struct cx231xx *dev) } case CX231XX_BOARD_HAUPPAUGE_935C: { - struct i2c_client *client; - struct i2c_adapter *adapter; - struct i2c_board_info info = {}; struct si2157_config si2157_config = {}; struct si2168_config si2168_config = {}; @@ -1112,25 +1006,14 @@ static int dvb_init(struct cx231xx *dev) si2168_config.i2c_adapter = &adapter; si2168_config.ts_clock_inv = true; - strlcpy(info.type, "si2168", sizeof(info.type)); - info.addr = dev->board.demod_addr; - info.platform_data = &si2168_config; - - request_module(info.type); - client = i2c_new_device(demod_i2c, &info); - if (client == NULL || client->dev.driver == NULL) { - result = -ENODEV; - goto out_free; - } - - if (!try_module_get(client->dev.driver->owner)) { - dev_err(dev->dev, - "Failed to attach %s frontend.\n", info.type); - i2c_unregister_device(client); + /* perform probe/init/attach */ + client = dvb_module_probe("si2168", NULL, demod_i2c, + dev->board.demod_addr, + &si2168_config); + if (!client) { result = -ENODEV; goto out_free; } - dvb->i2c_client_demod[0] = client; dev->dvb->frontend[0]->ops.i2c_gate_ctrl = NULL; @@ -1145,40 +1028,21 @@ static int dvb_init(struct cx231xx *dev) si2157_config.if_port = 1; si2157_config.inversion = true; - memset(&info, 0, sizeof(struct i2c_board_info)); - strlcpy(info.type, "si2157", I2C_NAME_SIZE); - info.addr = dev->board.tuner_addr; - info.platform_data = &si2157_config; - request_module("si2157"); - - client = i2c_new_device(adapter, &info); - if (client == NULL || client->dev.driver == NULL) { - module_put(dvb->i2c_client_demod[0]->dev.driver->owner); - i2c_unregister_device(dvb->i2c_client_demod[0]); - result = -ENODEV; - goto out_free; - } - - if (!try_module_get(client->dev.driver->owner)) { - dev_err(dev->dev, - "Failed to obtain %s tuner.\n", info.type); - i2c_unregister_device(client); - module_put(dvb->i2c_client_demod[0]->dev.driver->owner); - i2c_unregister_device(dvb->i2c_client_demod[0]); + /* perform probe/init/attach */ + client = dvb_module_probe("si2157", NULL, tuner_i2c, + dev->board.tuner_addr, + &si2157_config); + if (!client) { result = -ENODEV; goto out_free; } - dev->cx231xx_reset_analog_tuner = NULL; dev->dvb->i2c_client_tuner = client; break; } case CX231XX_BOARD_HAUPPAUGE_975: { - struct i2c_client *client; - struct i2c_adapter *adapter; struct i2c_adapter *adapter2; - struct i2c_board_info info = {}; struct si2157_config si2157_config = {}; struct lgdt3306a_config lgdt3306a_config = {}; struct si2168_config si2168_config = {}; @@ -1187,27 +1051,15 @@ static int dvb_init(struct cx231xx *dev) lgdt3306a_config = hauppauge_955q_lgdt3306a_config; lgdt3306a_config.fe = &dev->dvb->frontend[0]; lgdt3306a_config.i2c_adapter = &adapter; - lgdt3306a_config.deny_i2c_rptr = 0; - - strlcpy(info.type, "lgdt3306a", sizeof(info.type)); - info.addr = dev->board.demod_addr; - info.platform_data = &lgdt3306a_config; - - request_module(info.type); - client = i2c_new_device(demod_i2c, &info); - if (client == NULL || client->dev.driver == NULL) { - result = -ENODEV; - goto out_free; - } - if (!try_module_get(client->dev.driver->owner)) { - dev_err(dev->dev, - "Failed to attach %s frontend.\n", info.type); - i2c_unregister_device(client); + /* perform probe/init/attach */ + client = dvb_module_probe("lgdt3306a", NULL, demod_i2c, + dev->board.demod_addr, + &lgdt3306a_config); + if (!client) { result = -ENODEV; goto out_free; } - dvb->i2c_client_demod[0] = client; /* attach second demodulator chip */ @@ -1216,30 +1068,14 @@ static int dvb_init(struct cx231xx *dev) si2168_config.i2c_adapter = &adapter2; si2168_config.ts_clock_inv = true; - memset(&info, 0, sizeof(struct i2c_board_info)); - strlcpy(info.type, "si2168", sizeof(info.type)); - info.addr = dev->board.demod_addr2; - info.platform_data = &si2168_config; - - request_module(info.type); - client = i2c_new_device(adapter, &info); - if (client == NULL || client->dev.driver == NULL) { - dev_err(dev->dev, - "Failed to attach %s frontend.\n", info.type); - module_put(dvb->i2c_client_demod[0]->dev.driver->owner); - i2c_unregister_device(dvb->i2c_client_demod[0]); - result = -ENODEV; - goto out_free; - } - - if (!try_module_get(client->dev.driver->owner)) { - i2c_unregister_device(client); - module_put(dvb->i2c_client_demod[0]->dev.driver->owner); - i2c_unregister_device(dvb->i2c_client_demod[0]); + /* perform probe/init/attach */ + client = dvb_module_probe("si2168", NULL, adapter, + dev->board.demod_addr2, + &si2168_config); + if (!client) { result = -ENODEV; goto out_free; } - dvb->i2c_client_demod[1] = client; dvb->frontend[1]->id = 1; @@ -1255,34 +1091,14 @@ static int dvb_init(struct cx231xx *dev) si2157_config.if_port = 1; si2157_config.inversion = true; - memset(&info, 0, sizeof(struct i2c_board_info)); - strlcpy(info.type, "si2157", I2C_NAME_SIZE); - info.addr = dev->board.tuner_addr; - info.platform_data = &si2157_config; - request_module("si2157"); - - client = i2c_new_device(adapter, &info); - if (client == NULL || client->dev.driver == NULL) { - module_put(dvb->i2c_client_demod[1]->dev.driver->owner); - i2c_unregister_device(dvb->i2c_client_demod[1]); - module_put(dvb->i2c_client_demod[0]->dev.driver->owner); - i2c_unregister_device(dvb->i2c_client_demod[0]); - result = -ENODEV; - goto out_free; - } - - if (!try_module_get(client->dev.driver->owner)) { - dev_err(dev->dev, - "Failed to obtain %s tuner.\n", info.type); - i2c_unregister_device(client); - module_put(dvb->i2c_client_demod[1]->dev.driver->owner); - i2c_unregister_device(dvb->i2c_client_demod[1]); - module_put(dvb->i2c_client_demod[0]->dev.driver->owner); - i2c_unregister_device(dvb->i2c_client_demod[0]); + /* perform probe/init/attach */ + client = dvb_module_probe("si2157", NULL, adapter, + dev->board.tuner_addr, + &si2157_config); + if (!client) { result = -ENODEV; goto out_free; } - dev->cx231xx_reset_analog_tuner = NULL; dvb->i2c_client_tuner = client; @@ -1321,6 +1137,14 @@ ret: return result; out_free: + /* remove I2C tuner */ + dvb_module_release(dvb->i2c_client_tuner); + dvb->i2c_client_tuner = NULL; + /* remove I2C demod(s) */ + dvb_module_release(dvb->i2c_client_demod[1]); + dvb->i2c_client_demod[1] = NULL; + dvb_module_release(dvb->i2c_client_demod[0]); + dvb->i2c_client_demod[0] = NULL; kfree(dvb); dev->dvb = NULL; goto ret; diff --git a/drivers/media/usb/cx231xx/cx231xx.h b/drivers/media/usb/cx231xx/cx231xx.h index 6ffa4bd96484..fa640bf20111 100644 --- a/drivers/media/usb/cx231xx/cx231xx.h +++ b/drivers/media/usb/cx231xx/cx231xx.h @@ -38,7 +38,6 @@ #include <media/v4l2-fh.h> #include <media/rc-core.h> #include <media/i2c/ir-kbd-i2c.h> -#include <media/videobuf-dvb.h> #include "cx231xx-reg.h" #include "cx231xx-pcb-cfg.h" @@ -546,8 +545,6 @@ struct cx231xx_tsport { int nr; int sram_chno; - struct videobuf_dvb_frontends frontends; - /* dma queues */ u32 ts_packet_size; diff --git a/drivers/media/usb/dvb-usb-v2/dvbsky.c b/drivers/media/usb/dvb-usb-v2/dvbsky.c index 43eb82884555..1aa88d94e57f 100644 --- a/drivers/media/usb/dvb-usb-v2/dvbsky.c +++ b/drivers/media/usb/dvb-usb-v2/dvbsky.c @@ -31,7 +31,6 @@ MODULE_PARM_DESC(disable_rc, "Disable inbuilt IR receiver."); DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr); struct dvbsky_state { - struct mutex stream_mutex; u8 ibuf[DVBSKY_BUF_LEN]; u8 obuf[DVBSKY_BUF_LEN]; u8 last_lock; @@ -68,18 +67,17 @@ static int dvbsky_usb_generic_rw(struct dvb_usb_device *d, static int dvbsky_stream_ctrl(struct dvb_usb_device *d, u8 onoff) { - struct dvbsky_state *state = d_to_priv(d); int ret; - u8 obuf_pre[3] = { 0x37, 0, 0 }; - u8 obuf_post[3] = { 0x36, 3, 0 }; + static u8 obuf_pre[3] = { 0x37, 0, 0 }; + static u8 obuf_post[3] = { 0x36, 3, 0 }; - mutex_lock(&state->stream_mutex); - ret = dvbsky_usb_generic_rw(d, obuf_pre, 3, NULL, 0); + mutex_lock(&d->usb_mutex); + ret = dvb_usbv2_generic_rw_locked(d, obuf_pre, 3, NULL, 0); if (!ret && onoff) { msleep(20); - ret = dvbsky_usb_generic_rw(d, obuf_post, 3, NULL, 0); + ret = dvb_usbv2_generic_rw_locked(d, obuf_post, 3, NULL, 0); } - mutex_unlock(&state->stream_mutex); + mutex_unlock(&d->usb_mutex); return ret; } @@ -290,61 +288,44 @@ static int dvbsky_usb_read_status(struct dvb_frontend *fe, return ret; } -static const struct m88ds3103_config dvbsky_s960_m88ds3103_config = { - .i2c_addr = 0x68, - .clock = 27000000, - .i2c_wr_max = 33, - .clock_out = 0, - .ts_mode = M88DS3103_TS_CI, - .ts_clk = 16000, - .ts_clk_pol = 0, - .agc = 0x99, - .lnb_hv_pol = 1, - .lnb_en_pol = 1, -}; - static int dvbsky_s960_attach(struct dvb_usb_adapter *adap) { struct dvbsky_state *state = adap_to_priv(adap); struct dvb_usb_device *d = adap_to_d(adap); - int ret = 0; - /* demod I2C adapter */ - struct i2c_adapter *i2c_adapter = NULL; - struct i2c_client *client; - struct i2c_board_info info; + struct i2c_adapter *i2c_adapter; + struct m88ds3103_platform_data m88ds3103_pdata = {}; struct ts2020_config ts2020_config = {}; - memset(&info, 0, sizeof(struct i2c_board_info)); /* attach demod */ - adap->fe[0] = dvb_attach(m88ds3103_attach, - &dvbsky_s960_m88ds3103_config, - &d->i2c_adap, - &i2c_adapter); - if (!adap->fe[0]) { - dev_err(&d->udev->dev, "dvbsky_s960_attach fail.\n"); - ret = -ENODEV; - goto fail_attach; - } + m88ds3103_pdata.clk = 27000000; + m88ds3103_pdata.i2c_wr_max = 33; + m88ds3103_pdata.clk_out = 0; + m88ds3103_pdata.ts_mode = M88DS3103_TS_CI; + m88ds3103_pdata.ts_clk = 16000; + m88ds3103_pdata.ts_clk_pol = 0; + m88ds3103_pdata.agc = 0x99; + m88ds3103_pdata.lnb_hv_pol = 1, + m88ds3103_pdata.lnb_en_pol = 1, + + state->i2c_client_demod = dvb_module_probe("m88ds3103", NULL, + &d->i2c_adap, + 0x68, &m88ds3103_pdata); + if (!state->i2c_client_demod) + return -ENODEV; + + adap->fe[0] = m88ds3103_pdata.get_dvb_frontend(state->i2c_client_demod); + i2c_adapter = m88ds3103_pdata.get_i2c_adapter(state->i2c_client_demod); /* attach tuner */ ts2020_config.fe = adap->fe[0]; ts2020_config.get_agc_pwm = m88ds3103_get_agc_pwm; - strlcpy(info.type, "ts2020", I2C_NAME_SIZE); - info.addr = 0x60; - info.platform_data = &ts2020_config; - request_module("ts2020"); - client = i2c_new_device(i2c_adapter, &info); - if (client == NULL || client->dev.driver == NULL) { - dvb_frontend_detach(adap->fe[0]); - ret = -ENODEV; - goto fail_attach; - } - if (!try_module_get(client->dev.driver->owner)) { - i2c_unregister_device(client); - dvb_frontend_detach(adap->fe[0]); - ret = -ENODEV; - goto fail_attach; + state->i2c_client_tuner = dvb_module_probe("ts2020", NULL, + i2c_adapter, + 0x60, &ts2020_config); + if (!state->i2c_client_tuner) { + dvb_module_release(state->i2c_client_demod); + return -ENODEV; } /* delegate signal strength measurement to tuner */ @@ -359,10 +340,7 @@ static int dvbsky_s960_attach(struct dvb_usb_adapter *adap) state->fe_set_voltage = adap->fe[0]->ops.set_voltage; adap->fe[0]->ops.set_voltage = dvbsky_usb_set_voltage; - state->i2c_client_tuner = client; - -fail_attach: - return ret; + return 0; } static int dvbsky_usb_ci_set_voltage(struct dvb_frontend *fe, @@ -412,80 +390,60 @@ err: return ret; } -static const struct m88ds3103_config dvbsky_s960c_m88ds3103_config = { - .i2c_addr = 0x68, - .clock = 27000000, - .i2c_wr_max = 33, - .clock_out = 0, - .ts_mode = M88DS3103_TS_CI, - .ts_clk = 10000, - .ts_clk_pol = 1, - .agc = 0x99, - .lnb_hv_pol = 0, - .lnb_en_pol = 1, -}; - static int dvbsky_s960c_attach(struct dvb_usb_adapter *adap) { struct dvbsky_state *state = adap_to_priv(adap); struct dvb_usb_device *d = adap_to_d(adap); - int ret = 0; - /* demod I2C adapter */ - struct i2c_adapter *i2c_adapter = NULL; - struct i2c_client *client_tuner, *client_ci; - struct i2c_board_info info; - struct sp2_config sp2_config; + struct i2c_adapter *i2c_adapter; + struct m88ds3103_platform_data m88ds3103_pdata = {}; struct ts2020_config ts2020_config = {}; - memset(&info, 0, sizeof(struct i2c_board_info)); + struct sp2_config sp2_config = {}; /* attach demod */ - adap->fe[0] = dvb_attach(m88ds3103_attach, - &dvbsky_s960c_m88ds3103_config, - &d->i2c_adap, - &i2c_adapter); - if (!adap->fe[0]) { - dev_err(&d->udev->dev, "dvbsky_s960ci_attach fail.\n"); - ret = -ENODEV; - goto fail_attach; - } + m88ds3103_pdata.clk = 27000000, + m88ds3103_pdata.i2c_wr_max = 33, + m88ds3103_pdata.clk_out = 0, + m88ds3103_pdata.ts_mode = M88DS3103_TS_CI, + m88ds3103_pdata.ts_clk = 10000, + m88ds3103_pdata.ts_clk_pol = 1, + m88ds3103_pdata.agc = 0x99, + m88ds3103_pdata.lnb_hv_pol = 0, + m88ds3103_pdata.lnb_en_pol = 1, + + state->i2c_client_demod = dvb_module_probe("m88ds3103", NULL, + &d->i2c_adap, + 0x68, &m88ds3103_pdata); + if (!state->i2c_client_demod) + return -ENODEV; + + adap->fe[0] = m88ds3103_pdata.get_dvb_frontend(state->i2c_client_demod); + i2c_adapter = m88ds3103_pdata.get_i2c_adapter(state->i2c_client_demod); /* attach tuner */ ts2020_config.fe = adap->fe[0]; ts2020_config.get_agc_pwm = m88ds3103_get_agc_pwm; - strlcpy(info.type, "ts2020", I2C_NAME_SIZE); - info.addr = 0x60; - info.platform_data = &ts2020_config; - request_module("ts2020"); - client_tuner = i2c_new_device(i2c_adapter, &info); - if (client_tuner == NULL || client_tuner->dev.driver == NULL) { - ret = -ENODEV; - goto fail_tuner_device; - } - if (!try_module_get(client_tuner->dev.driver->owner)) { - ret = -ENODEV; - goto fail_tuner_module; + state->i2c_client_tuner = dvb_module_probe("ts2020", NULL, + i2c_adapter, + 0x60, &ts2020_config); + if (!state->i2c_client_tuner) { + dvb_module_release(state->i2c_client_demod); + return -ENODEV; } /* attach ci controller */ - memset(&sp2_config, 0, sizeof(sp2_config)); sp2_config.dvb_adap = &adap->dvb_adap; sp2_config.priv = d; sp2_config.ci_control = dvbsky_ci_ctrl; - memset(&info, 0, sizeof(struct i2c_board_info)); - strlcpy(info.type, "sp2", I2C_NAME_SIZE); - info.addr = 0x40; - info.platform_data = &sp2_config; - request_module("sp2"); - client_ci = i2c_new_device(&d->i2c_adap, &info); - if (client_ci == NULL || client_ci->dev.driver == NULL) { - ret = -ENODEV; - goto fail_ci_device; - } - if (!try_module_get(client_ci->dev.driver->owner)) { - ret = -ENODEV; - goto fail_ci_module; + state->i2c_client_ci = dvb_module_probe("sp2", NULL, + &d->i2c_adap, + 0x40, &sp2_config); + + if (!state->i2c_client_ci) { + dvb_module_release(state->i2c_client_tuner); + dvb_module_release(state->i2c_client_demod); + return -ENODEV; } /* delegate signal strength measurement to tuner */ @@ -500,165 +458,92 @@ static int dvbsky_s960c_attach(struct dvb_usb_adapter *adap) state->fe_set_voltage = adap->fe[0]->ops.set_voltage; adap->fe[0]->ops.set_voltage = dvbsky_usb_ci_set_voltage; - state->i2c_client_tuner = client_tuner; - state->i2c_client_ci = client_ci; - return ret; -fail_ci_module: - i2c_unregister_device(client_ci); -fail_ci_device: - module_put(client_tuner->dev.driver->owner); -fail_tuner_module: - i2c_unregister_device(client_tuner); -fail_tuner_device: - dvb_frontend_detach(adap->fe[0]); -fail_attach: - return ret; + return 0; } static int dvbsky_t680c_attach(struct dvb_usb_adapter *adap) { struct dvbsky_state *state = adap_to_priv(adap); struct dvb_usb_device *d = adap_to_d(adap); - int ret = 0; struct i2c_adapter *i2c_adapter; - struct i2c_client *client_demod, *client_tuner, *client_ci; - struct i2c_board_info info; - struct si2168_config si2168_config; - struct si2157_config si2157_config; - struct sp2_config sp2_config; + struct si2168_config si2168_config = {}; + struct si2157_config si2157_config = {}; + struct sp2_config sp2_config = {}; /* attach demod */ - memset(&si2168_config, 0, sizeof(si2168_config)); si2168_config.i2c_adapter = &i2c_adapter; si2168_config.fe = &adap->fe[0]; si2168_config.ts_mode = SI2168_TS_PARALLEL; - memset(&info, 0, sizeof(struct i2c_board_info)); - strlcpy(info.type, "si2168", I2C_NAME_SIZE); - info.addr = 0x64; - info.platform_data = &si2168_config; - - request_module(info.type); - client_demod = i2c_new_device(&d->i2c_adap, &info); - if (client_demod == NULL || - client_demod->dev.driver == NULL) - goto fail_demod_device; - if (!try_module_get(client_demod->dev.driver->owner)) - goto fail_demod_module; + + state->i2c_client_demod = dvb_module_probe("si2168", NULL, + &d->i2c_adap, + 0x64, &si2168_config); + if (!state->i2c_client_demod) + return -ENODEV; /* attach tuner */ - memset(&si2157_config, 0, sizeof(si2157_config)); si2157_config.fe = adap->fe[0]; si2157_config.if_port = 1; - memset(&info, 0, sizeof(struct i2c_board_info)); - strlcpy(info.type, "si2157", I2C_NAME_SIZE); - info.addr = 0x60; - info.platform_data = &si2157_config; - - request_module(info.type); - client_tuner = i2c_new_device(i2c_adapter, &info); - if (client_tuner == NULL || - client_tuner->dev.driver == NULL) - goto fail_tuner_device; - if (!try_module_get(client_tuner->dev.driver->owner)) - goto fail_tuner_module; + + state->i2c_client_tuner = dvb_module_probe("si2157", NULL, + i2c_adapter, + 0x60, &si2157_config); + if (!state->i2c_client_tuner) { + dvb_module_release(state->i2c_client_demod); + return -ENODEV; + } /* attach ci controller */ - memset(&sp2_config, 0, sizeof(sp2_config)); sp2_config.dvb_adap = &adap->dvb_adap; sp2_config.priv = d; sp2_config.ci_control = dvbsky_ci_ctrl; - memset(&info, 0, sizeof(struct i2c_board_info)); - strlcpy(info.type, "sp2", I2C_NAME_SIZE); - info.addr = 0x40; - info.platform_data = &sp2_config; - request_module(info.type); - client_ci = i2c_new_device(&d->i2c_adap, &info); + state->i2c_client_ci = dvb_module_probe("sp2", NULL, + &d->i2c_adap, + 0x40, &sp2_config); - if (client_ci == NULL || client_ci->dev.driver == NULL) - goto fail_ci_device; - - if (!try_module_get(client_ci->dev.driver->owner)) - goto fail_ci_module; + if (!state->i2c_client_ci) { + dvb_module_release(state->i2c_client_tuner); + dvb_module_release(state->i2c_client_demod); + return -ENODEV; + } - state->i2c_client_demod = client_demod; - state->i2c_client_tuner = client_tuner; - state->i2c_client_ci = client_ci; - return ret; -fail_ci_module: - i2c_unregister_device(client_ci); -fail_ci_device: - module_put(client_tuner->dev.driver->owner); -fail_tuner_module: - i2c_unregister_device(client_tuner); -fail_tuner_device: - module_put(client_demod->dev.driver->owner); -fail_demod_module: - i2c_unregister_device(client_demod); -fail_demod_device: - ret = -ENODEV; - return ret; + return 0; } static int dvbsky_t330_attach(struct dvb_usb_adapter *adap) { struct dvbsky_state *state = adap_to_priv(adap); struct dvb_usb_device *d = adap_to_d(adap); - int ret = 0; struct i2c_adapter *i2c_adapter; - struct i2c_client *client_demod, *client_tuner; - struct i2c_board_info info; - struct si2168_config si2168_config; - struct si2157_config si2157_config; + struct si2168_config si2168_config = {}; + struct si2157_config si2157_config = {}; /* attach demod */ - memset(&si2168_config, 0, sizeof(si2168_config)); si2168_config.i2c_adapter = &i2c_adapter; si2168_config.fe = &adap->fe[0]; si2168_config.ts_mode = SI2168_TS_PARALLEL; si2168_config.ts_clock_gapped = true; - memset(&info, 0, sizeof(struct i2c_board_info)); - strlcpy(info.type, "si2168", I2C_NAME_SIZE); - info.addr = 0x64; - info.platform_data = &si2168_config; - - request_module(info.type); - client_demod = i2c_new_device(&d->i2c_adap, &info); - if (client_demod == NULL || - client_demod->dev.driver == NULL) - goto fail_demod_device; - if (!try_module_get(client_demod->dev.driver->owner)) - goto fail_demod_module; + + state->i2c_client_demod = dvb_module_probe("si2168", NULL, + &d->i2c_adap, + 0x64, &si2168_config); + if (!state->i2c_client_demod) + return -ENODEV; /* attach tuner */ - memset(&si2157_config, 0, sizeof(si2157_config)); si2157_config.fe = adap->fe[0]; si2157_config.if_port = 1; - memset(&info, 0, sizeof(struct i2c_board_info)); - strlcpy(info.type, "si2157", I2C_NAME_SIZE); - info.addr = 0x60; - info.platform_data = &si2157_config; - - request_module(info.type); - client_tuner = i2c_new_device(i2c_adapter, &info); - if (client_tuner == NULL || - client_tuner->dev.driver == NULL) - goto fail_tuner_device; - if (!try_module_get(client_tuner->dev.driver->owner)) - goto fail_tuner_module; - - state->i2c_client_demod = client_demod; - state->i2c_client_tuner = client_tuner; - return ret; -fail_tuner_module: - i2c_unregister_device(client_tuner); -fail_tuner_device: - module_put(client_demod->dev.driver->owner); -fail_demod_module: - i2c_unregister_device(client_demod); -fail_demod_device: - ret = -ENODEV; - return ret; + + state->i2c_client_tuner = dvb_module_probe("si2157", NULL, + i2c_adapter, + 0x60, &si2157_config); + if (!state->i2c_client_tuner) { + dvb_module_release(state->i2c_client_demod); + return -ENODEV; + } + + return 0; } static int dvbsky_mygica_t230c_attach(struct dvb_usb_adapter *adap) @@ -666,57 +551,34 @@ static int dvbsky_mygica_t230c_attach(struct dvb_usb_adapter *adap) struct dvbsky_state *state = adap_to_priv(adap); struct dvb_usb_device *d = adap_to_d(adap); struct i2c_adapter *i2c_adapter; - struct i2c_client *client_demod, *client_tuner; - struct i2c_board_info info; - struct si2168_config si2168_config; - struct si2157_config si2157_config; + struct si2168_config si2168_config = {}; + struct si2157_config si2157_config = {}; /* attach demod */ - memset(&si2168_config, 0, sizeof(si2168_config)); si2168_config.i2c_adapter = &i2c_adapter; si2168_config.fe = &adap->fe[0]; si2168_config.ts_mode = SI2168_TS_PARALLEL; si2168_config.ts_clock_inv = 1; - memset(&info, 0, sizeof(struct i2c_board_info)); - strlcpy(info.type, "si2168", sizeof(info.type)); - info.addr = 0x64; - info.platform_data = &si2168_config; - - request_module("si2168"); - client_demod = i2c_new_device(&d->i2c_adap, &info); - if (!client_demod || !client_demod->dev.driver) - goto fail_demod_device; - if (!try_module_get(client_demod->dev.driver->owner)) - goto fail_demod_module; + + state->i2c_client_demod = dvb_module_probe("si2168", NULL, + &d->i2c_adap, + 0x64, &si2168_config); + if (!state->i2c_client_demod) + return -ENODEV; /* attach tuner */ - memset(&si2157_config, 0, sizeof(si2157_config)); si2157_config.fe = adap->fe[0]; si2157_config.if_port = 0; - memset(&info, 0, sizeof(struct i2c_board_info)); - strlcpy(info.type, "si2141", sizeof(info.type)); - info.addr = 0x60; - info.platform_data = &si2157_config; - - request_module("si2157"); - client_tuner = i2c_new_device(i2c_adapter, &info); - if (!client_tuner || !client_tuner->dev.driver) - goto fail_tuner_device; - if (!try_module_get(client_tuner->dev.driver->owner)) - goto fail_tuner_module; - - state->i2c_client_demod = client_demod; - state->i2c_client_tuner = client_tuner; - return 0; -fail_tuner_module: - i2c_unregister_device(client_tuner); -fail_tuner_device: - module_put(client_demod->dev.driver->owner); -fail_demod_module: - i2c_unregister_device(client_demod); -fail_demod_device: - return -ENODEV; + state->i2c_client_tuner = dvb_module_probe("si2157", "si2141", + i2c_adapter, + 0x60, &si2157_config); + if (!state->i2c_client_tuner) { + dvb_module_release(state->i2c_client_demod); + return -ENODEV; + } + + return 0; } @@ -744,8 +606,6 @@ static int dvbsky_init(struct dvb_usb_device *d) if (ret) return ret; */ - mutex_init(&state->stream_mutex); - state->last_lock = 0; return 0; @@ -754,26 +614,13 @@ static int dvbsky_init(struct dvb_usb_device *d) static void dvbsky_exit(struct dvb_usb_device *d) { struct dvbsky_state *state = d_to_priv(d); - struct i2c_client *client; + struct dvb_usb_adapter *adap = &d->adapter[0]; - client = state->i2c_client_tuner; - /* remove I2C tuner */ - if (client) { - module_put(client->dev.driver->owner); - i2c_unregister_device(client); - } - client = state->i2c_client_demod; - /* remove I2C demod */ - if (client) { - module_put(client->dev.driver->owner); - i2c_unregister_device(client); - } - client = state->i2c_client_ci; - /* remove I2C ci */ - if (client) { - module_put(client->dev.driver->owner); - i2c_unregister_device(client); - } + dvb_module_release(state->i2c_client_tuner); + dvb_module_release(state->i2c_client_demod); + dvb_module_release(state->i2c_client_ci); + + adap->fe[0] = NULL; } /* DVB USB Driver stuff */ diff --git a/drivers/media/usb/dvb-usb-v2/gl861.c b/drivers/media/usb/dvb-usb-v2/gl861.c index b1b09c547861..4817dfd3e659 100644 --- a/drivers/media/usb/dvb-usb-v2/gl861.c +++ b/drivers/media/usb/dvb-usb-v2/gl861.c @@ -20,6 +20,8 @@ static int gl861_i2c_msg(struct dvb_usb_device *d, u8 addr, u16 value = addr << (8 + 1); int wo = (rbuf == NULL || rlen == 0); /* write-only */ u8 req, type; + u8 *buf; + int ret; if (wo) { req = GL861_REQ_I2C_WRITE; @@ -42,11 +44,23 @@ static int gl861_i2c_msg(struct dvb_usb_device *d, u8 addr, KBUILD_MODNAME, wlen); return -EINVAL; } + buf = NULL; + if (rlen > 0) { + buf = kmalloc(rlen, GFP_KERNEL); + if (!buf) + return -ENOMEM; + } + usleep_range(1000, 2000); /* avoid I2C errors */ + + ret = usb_control_msg(d->udev, usb_rcvctrlpipe(d->udev, 0), req, type, + value, index, buf, rlen, 2000); + if (rlen > 0) { + if (ret > 0) + memcpy(rbuf, buf, rlen); + kfree(buf); + } - msleep(1); /* avoid I2C errors */ - - return usb_control_msg(d->udev, usb_rcvctrlpipe(d->udev, 0), req, type, - value, index, rbuf, rlen, 2000); + return ret; } /* I2C */ diff --git a/drivers/media/usb/dvb-usb-v2/usb_urb.c b/drivers/media/usb/dvb-usb-v2/usb_urb.c index dce2b97efce4..b0499f95ec45 100644 --- a/drivers/media/usb/dvb-usb-v2/usb_urb.c +++ b/drivers/media/usb/dvb-usb-v2/usb_urb.c @@ -155,8 +155,7 @@ static int usb_urb_alloc_bulk_urbs(struct usb_data_stream *stream) stream->props.u.bulk.buffersize, usb_urb_complete, stream); - stream->urb_list[i]->transfer_flags = URB_NO_TRANSFER_DMA_MAP; - stream->urb_list[i]->transfer_dma = stream->dma_addr[i]; + stream->urb_list[i]->transfer_flags = URB_FREE_BUFFER; stream->urbs_initialized++; } return 0; @@ -187,13 +186,12 @@ static int usb_urb_alloc_isoc_urbs(struct usb_data_stream *stream) urb->complete = usb_urb_complete; urb->pipe = usb_rcvisocpipe(stream->udev, stream->props.endpoint); - urb->transfer_flags = URB_ISO_ASAP | URB_NO_TRANSFER_DMA_MAP; + urb->transfer_flags = URB_ISO_ASAP | URB_FREE_BUFFER; urb->interval = stream->props.u.isoc.interval; urb->number_of_packets = stream->props.u.isoc.framesperurb; urb->transfer_buffer_length = stream->props.u.isoc.framesize * stream->props.u.isoc.framesperurb; urb->transfer_buffer = stream->buf_list[i]; - urb->transfer_dma = stream->dma_addr[i]; for (j = 0; j < stream->props.u.isoc.framesperurb; j++) { urb->iso_frame_desc[j].offset = frame_offset; @@ -212,11 +210,7 @@ static int usb_free_stream_buffers(struct usb_data_stream *stream) if (stream->state & USB_STATE_URB_BUF) { while (stream->buf_num) { stream->buf_num--; - dev_dbg(&stream->udev->dev, "%s: free buf=%d\n", - __func__, stream->buf_num); - usb_free_coherent(stream->udev, stream->buf_size, - stream->buf_list[stream->buf_num], - stream->dma_addr[stream->buf_num]); + stream->buf_list[stream->buf_num] = NULL; } } @@ -236,9 +230,7 @@ static int usb_alloc_stream_buffers(struct usb_data_stream *stream, int num, __func__, num * size); for (stream->buf_num = 0; stream->buf_num < num; stream->buf_num++) { - stream->buf_list[stream->buf_num] = usb_alloc_coherent( - stream->udev, size, GFP_ATOMIC, - &stream->dma_addr[stream->buf_num]); + stream->buf_list[stream->buf_num] = kzalloc(size, GFP_ATOMIC); if (!stream->buf_list[stream->buf_num]) { dev_dbg(&stream->udev->dev, "%s: alloc buf=%d failed\n", __func__, stream->buf_num); @@ -250,7 +242,6 @@ static int usb_alloc_stream_buffers(struct usb_data_stream *stream, int num, __func__, stream->buf_num, stream->buf_list[stream->buf_num], (long long)stream->dma_addr[stream->buf_num]); - memset(stream->buf_list[stream->buf_num], 0, size); stream->state |= USB_STATE_URB_BUF; } diff --git a/drivers/media/usb/dvb-usb/cxusb.c b/drivers/media/usb/dvb-usb/cxusb.c index 387a074ea6ec..b70d289dc738 100644 --- a/drivers/media/usb/dvb-usb/cxusb.c +++ b/drivers/media/usb/dvb-usb/cxusb.c @@ -540,12 +540,10 @@ static struct cx22702_config cxusb_cx22702_config = { }; static struct lgdt330x_config cxusb_lgdt3303_config = { - .demod_address = 0x0e, .demod_chip = LGDT3303, }; static struct lgdt330x_config cxusb_aver_lgdt3303_config = { - .demod_address = 0x0e, .demod_chip = LGDT3303, .clock_polarity_flip = 2, }; @@ -763,6 +761,7 @@ static int cxusb_lgdt3303_frontend_attach(struct dvb_usb_adapter *adap) adap->fe_adap[0].fe = dvb_attach(lgdt330x_attach, &cxusb_lgdt3303_config, + 0x0e, &adap->dev->i2c_adap); if ((adap->fe_adap[0].fe) != NULL) return 0; @@ -772,8 +771,10 @@ static int cxusb_lgdt3303_frontend_attach(struct dvb_usb_adapter *adap) static int cxusb_aver_lgdt3303_frontend_attach(struct dvb_usb_adapter *adap) { - adap->fe_adap[0].fe = dvb_attach(lgdt330x_attach, &cxusb_aver_lgdt3303_config, - &adap->dev->i2c_adap); + adap->fe_adap[0].fe = dvb_attach(lgdt330x_attach, + &cxusb_aver_lgdt3303_config, + 0x0e, + &adap->dev->i2c_adap); if (adap->fe_adap[0].fe != NULL) return 0; diff --git a/drivers/media/usb/dvb-usb/usb-urb.c b/drivers/media/usb/dvb-usb/usb-urb.c index 2804d2d0e83a..5e05963f4220 100644 --- a/drivers/media/usb/dvb-usb/usb-urb.c +++ b/drivers/media/usb/dvb-usb/usb-urb.c @@ -118,7 +118,7 @@ static int usb_allocate_stream_buffers(struct usb_data_stream *stream, int num, for (stream->buf_num = 0; stream->buf_num < num; stream->buf_num++) { deb_mem("allocating buffer %d\n",stream->buf_num); if (( stream->buf_list[stream->buf_num] = - usb_alloc_coherent(stream->udev, size, GFP_ATOMIC, + usb_alloc_coherent(stream->udev, size, GFP_KERNEL, &stream->dma_addr[stream->buf_num]) ) == NULL) { deb_mem("not enough memory for urb-buffer allocation.\n"); usb_free_stream_buffers(stream); @@ -145,7 +145,7 @@ static int usb_bulk_urb_init(struct usb_data_stream *stream) /* allocate the URBs */ for (i = 0; i < stream->props.count; i++) { - stream->urb_list[i] = usb_alloc_urb(0, GFP_ATOMIC); + stream->urb_list[i] = usb_alloc_urb(0, GFP_KERNEL); if (!stream->urb_list[i]) { deb_mem("not enough memory for urb_alloc_urb!.\n"); for (j = 0; j < i; j++) @@ -178,7 +178,7 @@ static int usb_isoc_urb_init(struct usb_data_stream *stream) struct urb *urb; int frame_offset = 0; - stream->urb_list[i] = usb_alloc_urb(stream->props.u.isoc.framesperurb, GFP_ATOMIC); + stream->urb_list[i] = usb_alloc_urb(stream->props.u.isoc.framesperurb, GFP_KERNEL); if (!stream->urb_list[i]) { deb_mem("not enough memory for urb_alloc_urb!\n"); for (j = 0; j < i; j++) diff --git a/drivers/media/usb/em28xx/em28xx-cards.c b/drivers/media/usb/em28xx/em28xx-cards.c index 7c3203d7044b..e88e239904eb 100644 --- a/drivers/media/usb/em28xx/em28xx-cards.c +++ b/drivers/media/usb/em28xx/em28xx-cards.c @@ -87,6 +87,21 @@ static const struct em28xx_reg_seq default_digital[] = { { -1, -1, -1, -1}, }; +/* Board :Zolid Hybrid Tv Stick */ +static struct em28xx_reg_seq zolid_tuner[] = { + {EM2820_R08_GPIO_CTRL, 0xfd, 0xff, 100}, + {EM2820_R08_GPIO_CTRL, 0xfe, 0xff, 100}, + { -1, -1, -1, -1}, +}; + +static struct em28xx_reg_seq zolid_digital[] = { + {EM2820_R08_GPIO_CTRL, 0x6a, 0xff, 100}, + {EM2820_R08_GPIO_CTRL, 0x7a, 0xff, 100}, + {EM2880_R04_GPO, 0x04, 0xff, 100}, + {EM2880_R04_GPO, 0x0c, 0xff, 100}, + { -1, -1, -1, -1}, +}; + /* Board Hauppauge WinTV HVR 900 analog */ static const struct em28xx_reg_seq hauppauge_wintv_hvr_900_analog[] = { {EM2820_R08_GPIO_CTRL, 0x2d, ~EM_GPIO_4, 10}, @@ -666,6 +681,16 @@ const struct em28xx_board em28xx_boards[] = { .tuner_type = TUNER_ABSENT, .is_webcam = 1, /* To enable sensor probe */ }, + [EM2882_BOARD_ZOLID_HYBRID_TV_STICK] = { + .name = ":ZOLID HYBRID TV STICK", + .tuner_type = TUNER_XC2028, + .tuner_gpio = zolid_tuner, + .decoder = EM28XX_TVP5150, + .xclk = EM28XX_XCLK_FREQUENCY_12MHZ, + .mts_firmware = 1, + .has_dvb = 1, + .dvb_gpio = zolid_digital, + }, [EM2750_BOARD_DLCW_130] = { /* Beijing Huaqi Information Digital Technology Co., Ltd */ .name = "Huaqi DLCW-130", @@ -2493,7 +2518,7 @@ struct usb_device_id em28xx_id_table[] = { .driver_info = EM2820_BOARD_UNKNOWN }, { USB_DEVICE(0xeb1a, 0x2881), .driver_info = EM2820_BOARD_UNKNOWN }, - { USB_DEVICE(0xeb1a, 0x2883), + { USB_DEVICE(0xeb1a, 0x2883), /* used by :Zolid Hybrid Tv Stick */ .driver_info = EM2820_BOARD_UNKNOWN }, { USB_DEVICE(0xeb1a, 0x2868), .driver_info = EM2820_BOARD_UNKNOWN }, @@ -2663,6 +2688,8 @@ struct usb_device_id em28xx_id_table[] = { .driver_info = EM28178_BOARD_PCTV_292E }, { USB_DEVICE(0x2040, 0x8268), /* Hauppauge Retail WinTV-soloHD Bulk */ .driver_info = EM28178_BOARD_PCTV_292E }, + { USB_DEVICE(0x2040, 0x8268), /* Hauppauge WinTV-soloHD alt. PID */ + .driver_info = EM28178_BOARD_PCTV_292E }, { USB_DEVICE(0x0413, 0x6f07), .driver_info = EM2861_BOARD_LEADTEK_VC100 }, { USB_DEVICE(0xeb1a, 0x8179), @@ -2688,6 +2715,7 @@ static const struct em28xx_hash_table em28xx_eeprom_hash[] = { {0xb8846b20, EM2881_BOARD_PINNACLE_HYBRID_PRO, TUNER_XC2028}, {0x63f653bd, EM2870_BOARD_REDDO_DVB_C_USB_BOX, TUNER_ABSENT}, {0x4e913442, EM2882_BOARD_DIKOM_DK300, TUNER_XC2028}, + {0x85dd871e, EM2882_BOARD_ZOLID_HYBRID_TV_STICK, TUNER_XC2028}, }; /* I2C devicelist hash table for devices with generic USB IDs */ @@ -2699,6 +2727,7 @@ static const struct em28xx_hash_table em28xx_i2c_hash[] = { {0xc51200e3, EM2820_BOARD_GADMEI_TVR200, TUNER_LG_PAL_NEW_TAPC}, {0x4ba50080, EM2861_BOARD_GADMEI_UTV330PLUS, TUNER_TNF_5335MF}, {0x6b800080, EM2874_BOARD_LEADERSHIP_ISDBT, TUNER_ABSENT}, + {0x27e10080, EM2882_BOARD_ZOLID_HYBRID_TV_STICK, TUNER_XC2028}, }; /* NOTE: introduce a separate hash table for devices with 16 bit eeproms */ @@ -3182,11 +3211,10 @@ void em28xx_setup_xc3028(struct em28xx *dev, struct xc2028_ctrl *ctl) case EM2880_BOARD_EMPIRE_DUAL_TV: case EM2880_BOARD_HAUPPAUGE_WINTV_HVR_900: case EM2882_BOARD_TERRATEC_HYBRID_XS: - ctl->demod = XC3028_FE_ZARLINK456; - break; case EM2880_BOARD_TERRATEC_HYBRID_XS: case EM2880_BOARD_TERRATEC_HYBRID_XS_FR: case EM2881_BOARD_PINNACLE_HYBRID_PRO: + case EM2882_BOARD_ZOLID_HYBRID_TV_STICK: ctl->demod = XC3028_FE_ZARLINK456; break; case EM2880_BOARD_HAUPPAUGE_WINTV_HVR_900_R2: @@ -3736,7 +3764,7 @@ static int em28xx_usb_probe(struct usb_interface *intf, speed = "unknown"; } - dev_err(&intf->dev, + dev_info(&intf->dev, "New device %s %s @ %s Mbps (%04x:%04x, interface %d, class %d)\n", udev->manufacturer ? udev->manufacturer : "", udev->product ? udev->product : "", @@ -3771,7 +3799,7 @@ static int em28xx_usb_probe(struct usb_interface *intf, dev->dev_next = NULL; if (has_vendor_audio) { - dev_err(&intf->dev, + dev_info(&intf->dev, "Audio interface %i found (Vendor Class)\n", ifnum); dev->usb_audio_type = EM28XX_USB_AUDIO_VENDOR; } @@ -3790,12 +3818,12 @@ static int em28xx_usb_probe(struct usb_interface *intf, } if (has_video) - dev_err(&intf->dev, "Video interface %i found:%s%s\n", + dev_info(&intf->dev, "Video interface %i found:%s%s\n", ifnum, dev->analog_ep_bulk ? " bulk" : "", dev->analog_ep_isoc ? " isoc" : ""); if (has_dvb) - dev_err(&intf->dev, "DVB interface %i found:%s%s\n", + dev_info(&intf->dev, "DVB interface %i found:%s%s\n", ifnum, dev->dvb_ep_bulk ? " bulk" : "", dev->dvb_ep_isoc ? " isoc" : ""); @@ -3837,13 +3865,13 @@ static int em28xx_usb_probe(struct usb_interface *intf, if (has_video) { if (!dev->analog_ep_isoc || (try_bulk && dev->analog_ep_bulk)) dev->analog_xfer_bulk = 1; - dev_err(&intf->dev, "analog set to %s mode.\n", + dev_info(&intf->dev, "analog set to %s mode.\n", dev->analog_xfer_bulk ? "bulk" : "isoc"); } if (has_dvb) { if (!dev->dvb_ep_isoc || (try_bulk && dev->dvb_ep_bulk)) dev->dvb_xfer_bulk = 1; - dev_err(&intf->dev, "dvb set to %s mode.\n", + dev_info(&intf->dev, "dvb set to %s mode.\n", dev->dvb_xfer_bulk ? "bulk" : "isoc"); } diff --git a/drivers/media/usb/em28xx/em28xx-core.c b/drivers/media/usb/em28xx/em28xx-core.c index f28995383090..f70845e7d8c6 100644 --- a/drivers/media/usb/em28xx/em28xx-core.c +++ b/drivers/media/usb/em28xx/em28xx-core.c @@ -1171,8 +1171,9 @@ int em28xx_resume_extension(struct em28xx *dev) dev_info(&dev->intf->dev, "Resuming extensions\n"); mutex_lock(&em28xx_devlist_mutex); list_for_each_entry(ops, &em28xx_extension_devlist, next) { - if (ops->resume) - ops->resume(dev); + if (!ops->resume) + continue; + ops->resume(dev); if (dev->dev_next) ops->resume(dev->dev_next); } diff --git a/drivers/media/usb/em28xx/em28xx-dvb.c b/drivers/media/usb/em28xx/em28xx-dvb.c index 3f493e0b0716..b778d8a1983e 100644 --- a/drivers/media/usb/em28xx/em28xx-dvb.c +++ b/drivers/media/usb/em28xx/em28xx-dvb.c @@ -199,6 +199,7 @@ static int em28xx_start_streaming(struct em28xx_dvb *dvb) int rc; struct em28xx_i2c_bus *i2c_bus = dvb->adapter.priv; struct em28xx *dev = i2c_bus->dev; + struct usb_device *udev = interface_to_usbdev(dev->intf); int dvb_max_packet_size, packet_multiplier, dvb_alt; if (dev->dvb_xfer_bulk) { @@ -217,6 +218,7 @@ static int em28xx_start_streaming(struct em28xx_dvb *dvb) dvb_alt = dev->dvb_alt_isoc; } + usb_set_interface(udev, dev->ifnum, dvb_alt); rc = em28xx_set_mode(dev, EM28XX_DIGITAL_MODE); if (rc < 0) return rc; @@ -298,7 +300,6 @@ static int em28xx_dvb_bus_ctrl(struct dvb_frontend *fe, int acquire) /* ------------------------------------------------------------------ */ static struct lgdt330x_config em2880_lgdt3303_dev = { - .demod_address = 0x0e, .demod_chip = LGDT3303, }; @@ -1392,7 +1393,7 @@ static int em28174_dvb_init_hauppauge_wintv_dualhd_01595(struct em28xx *dev) dvb->i2c_client_tuner = dvb_module_probe("si2157", NULL, adapter, - 0x60, &si2157_config); + addr, &si2157_config); if (!dvb->i2c_client_tuner) { dvb_module_release(dvb->i2c_client_demod); return -ENODEV; @@ -1470,6 +1471,7 @@ static int em28xx_dvb_init(struct em28xx *dev) case EM2880_BOARD_AMD_ATI_TV_WONDER_HD_600: dvb->fe[0] = dvb_attach(lgdt330x_attach, &em2880_lgdt3303_dev, + 0x0e, &dev->i2c_adap[dev->def_i2c_bus]); if (em28xx_attach_xc3028(0x61, dev) < 0) { result = -EINVAL; @@ -1488,6 +1490,7 @@ static int em28xx_dvb_init(struct em28xx *dev) case EM2880_BOARD_HAUPPAUGE_WINTV_HVR_900: case EM2882_BOARD_TERRATEC_HYBRID_XS: case EM2880_BOARD_EMPIRE_DUAL_TV: + case EM2882_BOARD_ZOLID_HYBRID_TV_STICK: dvb->fe[0] = dvb_attach(zl10353_attach, &em28xx_zl10353_xc3028_no_i2c_gate, &dev->i2c_adap[dev->def_i2c_bus]); @@ -1550,6 +1553,7 @@ static int em28xx_dvb_init(struct em28xx *dev) case EM2882_BOARD_KWORLD_ATSC_315U: dvb->fe[0] = dvb_attach(lgdt330x_attach, &em2880_lgdt3303_dev, + 0x0e, &dev->i2c_adap[dev->def_i2c_bus]); if (dvb->fe[0]) { if (!dvb_attach(simple_tuner_attach, dvb->fe[0], diff --git a/drivers/media/usb/em28xx/em28xx.h b/drivers/media/usb/em28xx/em28xx.h index b0378e77ddff..953caac025f2 100644 --- a/drivers/media/usb/em28xx/em28xx.h +++ b/drivers/media/usb/em28xx/em28xx.h @@ -148,6 +148,7 @@ #define EM28174_BOARD_HAUPPAUGE_WINTV_DUALHD_DVB 99 #define EM28174_BOARD_HAUPPAUGE_WINTV_DUALHD_01595 100 #define EM2884_BOARD_TERRATEC_H6 101 +#define EM2882_BOARD_ZOLID_HYBRID_TV_STICK 102 /* Limits minimum and default number of buffers */ #define EM28XX_MIN_BUF 4 diff --git a/drivers/media/usb/gspca/jl2005bcd.c b/drivers/media/usb/gspca/jl2005bcd.c index d668589598d6..c40245950553 100644 --- a/drivers/media/usb/gspca/jl2005bcd.c +++ b/drivers/media/usb/gspca/jl2005bcd.c @@ -321,7 +321,7 @@ static void jl2005c_dostream(struct work_struct *work) int ret; u8 *buffer; - buffer = kmalloc(JL2005C_MAX_TRANSFER, GFP_KERNEL | GFP_DMA); + buffer = kmalloc(JL2005C_MAX_TRANSFER, GFP_KERNEL); if (!buffer) { pr_err("Couldn't allocate USB buffer\n"); goto quit_stream; diff --git a/drivers/media/usb/gspca/sq905.c b/drivers/media/usb/gspca/sq905.c index cc8ff41b8ab3..ffea9c35b0a0 100644 --- a/drivers/media/usb/gspca/sq905.c +++ b/drivers/media/usb/gspca/sq905.c @@ -217,7 +217,7 @@ static void sq905_dostream(struct work_struct *work) u8 *data; u8 *buffer; - buffer = kmalloc(SQ905_MAX_TRANSFER, GFP_KERNEL | GFP_DMA); + buffer = kmalloc(SQ905_MAX_TRANSFER, GFP_KERNEL); if (!buffer) { pr_err("Couldn't allocate USB buffer\n"); goto quit_stream; diff --git a/drivers/media/usb/gspca/sq905c.c b/drivers/media/usb/gspca/sq905c.c index 5e1269eb7c50..274921c0bb46 100644 --- a/drivers/media/usb/gspca/sq905c.c +++ b/drivers/media/usb/gspca/sq905c.c @@ -138,7 +138,7 @@ static void sq905c_dostream(struct work_struct *work) int ret; u8 *buffer; - buffer = kmalloc(SQ905C_MAX_TRANSFER, GFP_KERNEL | GFP_DMA); + buffer = kmalloc(SQ905C_MAX_TRANSFER, GFP_KERNEL); if (!buffer) { pr_err("Couldn't allocate USB buffer\n"); goto quit_stream; diff --git a/drivers/media/usb/gspca/vicam.c b/drivers/media/usb/gspca/vicam.c index 554b90ef2200..8562bda0ef88 100644 --- a/drivers/media/usb/gspca/vicam.c +++ b/drivers/media/usb/gspca/vicam.c @@ -182,7 +182,7 @@ static void vicam_dostream(struct work_struct *work) frame_sz = gspca_dev->cam.cam_mode[gspca_dev->curr_mode].sizeimage + HEADER_SIZE; - buffer = kmalloc(frame_sz, GFP_KERNEL | GFP_DMA); + buffer = kmalloc(frame_sz, GFP_KERNEL); if (!buffer) { pr_err("Couldn't allocate USB buffer\n"); goto exit; diff --git a/drivers/media/usb/pvrusb2/pvrusb2-cx2584x-v4l.c b/drivers/media/usb/pvrusb2/pvrusb2-cx2584x-v4l.c index 242b213b7599..d5bec0f69bec 100644 --- a/drivers/media/usb/pvrusb2/pvrusb2-cx2584x-v4l.c +++ b/drivers/media/usb/pvrusb2/pvrusb2-cx2584x-v4l.c @@ -23,7 +23,6 @@ */ #include "pvrusb2-cx2584x-v4l.h" -#include "pvrusb2-video-v4l.h" #include "pvrusb2-hdw-internal.h" diff --git a/drivers/media/usb/pvrusb2/pvrusb2-devattr.c b/drivers/media/usb/pvrusb2/pvrusb2-devattr.c index 71537097c13f..06de1c83f444 100644 --- a/drivers/media/usb/pvrusb2/pvrusb2-devattr.c +++ b/drivers/media/usb/pvrusb2/pvrusb2-devattr.c @@ -182,7 +182,6 @@ static const struct pvr2_device_desc pvr2_device_av400 = { #ifdef CONFIG_VIDEO_PVRUSB2_DVB static struct lgdt330x_config pvr2_lgdt3303_config = { - .demod_address = 0x0e, .demod_chip = LGDT3303, .clock_polarity_flip = 1, }; @@ -190,6 +189,7 @@ static struct lgdt330x_config pvr2_lgdt3303_config = { static int pvr2_lgdt3303_attach(struct pvr2_dvb_adapter *adap) { adap->fe = dvb_attach(lgdt330x_attach, &pvr2_lgdt3303_config, + 0x0e, &adap->channel.hdw->i2c_adap); if (adap->fe) return 0; @@ -243,13 +243,13 @@ static const struct pvr2_device_desc pvr2_device_onair_creator = { #ifdef CONFIG_VIDEO_PVRUSB2_DVB static struct lgdt330x_config pvr2_lgdt3302_config = { - .demod_address = 0x0e, .demod_chip = LGDT3302, }; static int pvr2_lgdt3302_attach(struct pvr2_dvb_adapter *adap) { adap->fe = dvb_attach(lgdt330x_attach, &pvr2_lgdt3302_config, + 0x0e, &adap->channel.hdw->i2c_adap); if (adap->fe) return 0; diff --git a/drivers/media/usb/usbtv/usbtv-video.c b/drivers/media/usb/usbtv/usbtv-video.c index 3668a04359e8..c2f8e50228ac 100644 --- a/drivers/media/usb/usbtv/usbtv-video.c +++ b/drivers/media/usb/usbtv/usbtv-video.c @@ -54,7 +54,7 @@ static struct usbtv_norm_params norm_params[] = { .cap_height = 480, }, { - .norm = V4L2_STD_PAL, + .norm = V4L2_STD_625_50, .cap_width = 720, .cap_height = 576, } @@ -77,7 +77,7 @@ static int usbtv_configure_for_norm(struct usbtv *usbtv, v4l2_std_id norm) usbtv->height = params->cap_height; usbtv->n_chunks = usbtv->width * usbtv->height / 4 / USBTV_CHUNK; - usbtv->norm = params->norm; + usbtv->norm = norm; } else ret = -EINVAL; @@ -121,52 +121,144 @@ static int usbtv_select_input(struct usbtv *usbtv, int input) return ret; } +static uint16_t usbtv_norm_to_16f_reg(v4l2_std_id norm) +{ + /* NTSC M/M-JP/M-KR */ + if (norm & V4L2_STD_NTSC) + return 0x00b8; + /* PAL BG/DK/H/I */ + if (norm & V4L2_STD_PAL) + return 0x00ee; + /* SECAM B/D/G/H/K/K1/L/Lc */ + if (norm & V4L2_STD_SECAM) + return 0x00ff; + if (norm & V4L2_STD_NTSC_443) + return 0x00a8; + if (norm & (V4L2_STD_PAL_M | V4L2_STD_PAL_60)) + return 0x00bc; + /* Fallback to automatic detection for other standards */ + return 0x0000; +} + static int usbtv_select_norm(struct usbtv *usbtv, v4l2_std_id norm) { int ret; + /* These are the series of register values used to configure the + * decoder for a specific standard. + * The first 21 register writes are copied from the + * Settings\DecoderDefaults registry keys present in the Windows driver + * .INF file, and control various image tuning parameters (color + * correction, sharpness, ...). + */ static const u16 pal[][2] = { + /* "AVPAL" tuning sequence from .INF file */ + { USBTV_BASE + 0x0003, 0x0004 }, { USBTV_BASE + 0x001a, 0x0068 }, + { USBTV_BASE + 0x0100, 0x00d3 }, { USBTV_BASE + 0x010e, 0x0072 }, { USBTV_BASE + 0x010f, 0x00a2 }, { USBTV_BASE + 0x0112, 0x00b0 }, + { USBTV_BASE + 0x0115, 0x0015 }, { USBTV_BASE + 0x0117, 0x0001 }, { USBTV_BASE + 0x0118, 0x002c }, { USBTV_BASE + 0x012d, 0x0010 }, { USBTV_BASE + 0x012f, 0x0020 }, + { USBTV_BASE + 0x0220, 0x002e }, + { USBTV_BASE + 0x0225, 0x0008 }, + { USBTV_BASE + 0x024e, 0x0002 }, { USBTV_BASE + 0x024f, 0x0002 }, { USBTV_BASE + 0x0254, 0x0059 }, { USBTV_BASE + 0x025a, 0x0016 }, { USBTV_BASE + 0x025b, 0x0035 }, { USBTV_BASE + 0x0263, 0x0017 }, { USBTV_BASE + 0x0266, 0x0016 }, - { USBTV_BASE + 0x0267, 0x0036 } + { USBTV_BASE + 0x0267, 0x0036 }, + /* End image tuning */ + { USBTV_BASE + 0x024e, 0x0002 }, + { USBTV_BASE + 0x024f, 0x0002 }, }; static const u16 ntsc[][2] = { + /* "AVNTSC" tuning sequence from .INF file */ + { USBTV_BASE + 0x0003, 0x0004 }, { USBTV_BASE + 0x001a, 0x0079 }, + { USBTV_BASE + 0x0100, 0x00d3 }, { USBTV_BASE + 0x010e, 0x0068 }, { USBTV_BASE + 0x010f, 0x009c }, { USBTV_BASE + 0x0112, 0x00f0 }, + { USBTV_BASE + 0x0115, 0x0015 }, { USBTV_BASE + 0x0117, 0x0000 }, { USBTV_BASE + 0x0118, 0x00fc }, { USBTV_BASE + 0x012d, 0x0004 }, { USBTV_BASE + 0x012f, 0x0008 }, + { USBTV_BASE + 0x0220, 0x002e }, + { USBTV_BASE + 0x0225, 0x0008 }, + { USBTV_BASE + 0x024e, 0x0002 }, { USBTV_BASE + 0x024f, 0x0001 }, { USBTV_BASE + 0x0254, 0x005f }, { USBTV_BASE + 0x025a, 0x0012 }, { USBTV_BASE + 0x025b, 0x0001 }, { USBTV_BASE + 0x0263, 0x001c }, { USBTV_BASE + 0x0266, 0x0011 }, - { USBTV_BASE + 0x0267, 0x0005 } + { USBTV_BASE + 0x0267, 0x0005 }, + /* End image tuning */ + { USBTV_BASE + 0x024e, 0x0002 }, + { USBTV_BASE + 0x024f, 0x0002 }, + }; + + static const u16 secam[][2] = { + /* "AVSECAM" tuning sequence from .INF file */ + { USBTV_BASE + 0x0003, 0x0004 }, + { USBTV_BASE + 0x001a, 0x0073 }, + { USBTV_BASE + 0x0100, 0x00dc }, + { USBTV_BASE + 0x010e, 0x0072 }, + { USBTV_BASE + 0x010f, 0x00a2 }, + { USBTV_BASE + 0x0112, 0x0090 }, + { USBTV_BASE + 0x0115, 0x0035 }, + { USBTV_BASE + 0x0117, 0x0001 }, + { USBTV_BASE + 0x0118, 0x0030 }, + { USBTV_BASE + 0x012d, 0x0004 }, + { USBTV_BASE + 0x012f, 0x0008 }, + { USBTV_BASE + 0x0220, 0x002d }, + { USBTV_BASE + 0x0225, 0x0028 }, + { USBTV_BASE + 0x024e, 0x0008 }, + { USBTV_BASE + 0x024f, 0x0002 }, + { USBTV_BASE + 0x0254, 0x0069 }, + { USBTV_BASE + 0x025a, 0x0016 }, + { USBTV_BASE + 0x025b, 0x0035 }, + { USBTV_BASE + 0x0263, 0x0021 }, + { USBTV_BASE + 0x0266, 0x0016 }, + { USBTV_BASE + 0x0267, 0x0036 }, + /* End image tuning */ + { USBTV_BASE + 0x024e, 0x0002 }, + { USBTV_BASE + 0x024f, 0x0002 }, }; ret = usbtv_configure_for_norm(usbtv, norm); if (!ret) { - if (norm & V4L2_STD_525_60) + /* Masks for norms using a NTSC or PAL color encoding. */ + static const v4l2_std_id ntsc_mask = + V4L2_STD_NTSC | V4L2_STD_NTSC_443; + static const v4l2_std_id pal_mask = + V4L2_STD_PAL | V4L2_STD_PAL_60 | V4L2_STD_PAL_M; + + if (norm & ntsc_mask) ret = usbtv_set_regs(usbtv, ntsc, ARRAY_SIZE(ntsc)); - else if (norm & V4L2_STD_PAL) + else if (norm & pal_mask) ret = usbtv_set_regs(usbtv, pal, ARRAY_SIZE(pal)); + else if (norm & V4L2_STD_SECAM) + ret = usbtv_set_regs(usbtv, secam, ARRAY_SIZE(secam)); + else + ret = -EINVAL; + } + + if (!ret) { + /* Configure the decoder for the color standard */ + const u16 cfg[][2] = { + { USBTV_BASE + 0x016f, usbtv_norm_to_16f_reg(norm) } + }; + ret = usbtv_set_regs(usbtv, cfg, ARRAY_SIZE(cfg)); } return ret; @@ -236,15 +328,6 @@ static int usbtv_setup_capture(struct usbtv *usbtv) { USBTV_BASE + 0x0158, 0x001f }, { USBTV_BASE + 0x0159, 0x0006 }, { USBTV_BASE + 0x015d, 0x0000 }, - - { USBTV_BASE + 0x0003, 0x0004 }, - { USBTV_BASE + 0x0100, 0x00d3 }, - { USBTV_BASE + 0x0115, 0x0015 }, - { USBTV_BASE + 0x0220, 0x002e }, - { USBTV_BASE + 0x0225, 0x0008 }, - { USBTV_BASE + 0x024e, 0x0002 }, - { USBTV_BASE + 0x024e, 0x0002 }, - { USBTV_BASE + 0x024f, 0x0002 }, }; ret = usbtv_set_regs(usbtv, setup, ARRAY_SIZE(setup)); @@ -587,7 +670,7 @@ static int usbtv_s_std(struct file *file, void *priv, v4l2_std_id norm) int ret = -EINVAL; struct usbtv *usbtv = video_drvdata(file); - if ((norm & V4L2_STD_525_60) || (norm & V4L2_STD_PAL)) + if (norm & USBTV_TV_STD) ret = usbtv_select_norm(usbtv, norm); return ret; diff --git a/drivers/media/usb/usbtv/usbtv.h b/drivers/media/usb/usbtv/usbtv.h index 0231e449877e..77a368e90fd0 100644 --- a/drivers/media/usb/usbtv/usbtv.h +++ b/drivers/media/usb/usbtv/usbtv.h @@ -68,7 +68,7 @@ #define USBTV_ODD(chunk) ((be32_to_cpu(chunk[0]) & 0x0000f000) >> 15) #define USBTV_CHUNK_NO(chunk) (be32_to_cpu(chunk[0]) & 0x00000fff) -#define USBTV_TV_STD (V4L2_STD_525_60 | V4L2_STD_PAL) +#define USBTV_TV_STD (V4L2_STD_525_60 | V4L2_STD_PAL | V4L2_STD_SECAM) /* parameters for supported TV norms */ struct usbtv_norm_params { diff --git a/drivers/media/usb/usbvision/usbvision-core.c b/drivers/media/usb/usbvision/usbvision-core.c index 3f87fbc80be2..7138c2b606cc 100644 --- a/drivers/media/usb/usbvision/usbvision-core.c +++ b/drivers/media/usb/usbvision/usbvision-core.c @@ -1857,7 +1857,7 @@ int usbvision_stream_interrupt(struct usb_usbvision *usbvision) static int usbvision_set_compress_params(struct usb_usbvision *usbvision) { - static const char proc[] = "usbvision_set_compresion_params: "; + static const char proc[] = "usbvision_set_compression_params: "; int rc; unsigned char *value = usbvision->ctrl_urb_buffer; diff --git a/drivers/media/v4l2-core/Kconfig b/drivers/media/v4l2-core/Kconfig index 8e37e7c5e0f7..2a56f37f186b 100644 --- a/drivers/media/v4l2-core/Kconfig +++ b/drivers/media/v4l2-core/Kconfig @@ -76,7 +76,3 @@ config VIDEOBUF_DMA_CONTIG tristate depends on HAS_DMA select VIDEOBUF_GEN - -config VIDEOBUF_DVB - tristate - select VIDEOBUF_GEN diff --git a/drivers/media/v4l2-core/Makefile b/drivers/media/v4l2-core/Makefile index 7df54582e956..9ee57e1efefe 100644 --- a/drivers/media/v4l2-core/Makefile +++ b/drivers/media/v4l2-core/Makefile @@ -31,7 +31,6 @@ obj-$(CONFIG_VIDEOBUF_GEN) += videobuf-core.o obj-$(CONFIG_VIDEOBUF_DMA_SG) += videobuf-dma-sg.o obj-$(CONFIG_VIDEOBUF_DMA_CONTIG) += videobuf-dma-contig.o obj-$(CONFIG_VIDEOBUF_VMALLOC) += videobuf-vmalloc.o -obj-$(CONFIG_VIDEOBUF_DVB) += videobuf-dvb.o ccflags-y += -I$(srctree)/drivers/media/dvb-frontends ccflags-y += -I$(srctree)/drivers/media/tuners diff --git a/drivers/media/v4l2-core/v4l2-compat-ioctl32.c b/drivers/media/v4l2-core/v4l2-compat-ioctl32.c index 4312935f1dfc..6481212fda77 100644 --- a/drivers/media/v4l2-core/v4l2-compat-ioctl32.c +++ b/drivers/media/v4l2-core/v4l2-compat-ioctl32.c @@ -22,7 +22,18 @@ #include <media/v4l2-ctrls.h> #include <media/v4l2-ioctl.h> -/* Use the same argument order as copy_in_user */ +/** + * assign_in_user() - Copy from one __user var to another one + * + * @to: __user var where data will be stored + * @from: __user var where data will be retrieved. + * + * As this code very often needs to allocate userspace memory, it is easier + * to have a macro that will do both get_user() and put_user() at once. + * + * This function complements the macros defined at asm-generic/uaccess.h. + * It uses the same argument order as copy_in_user() + */ #define assign_in_user(to, from) \ ({ \ typeof(*from) __assign_tmp; \ @@ -30,6 +41,73 @@ get_user(__assign_tmp, from) || put_user(__assign_tmp, to); \ }) +/** + * get_user_cast() - Stores at a kernelspace local var the contents from a + * pointer with userspace data that is not tagged with __user. + * + * @__x: var where data will be stored + * @__ptr: var where data will be retrieved. + * + * Sometimes we need to declare a pointer without __user because it + * comes from a pointer struct field that will be retrieved from userspace + * by the 64-bit native ioctl handler. This function ensures that the + * @__ptr will be cast to __user before calling get_user() in order to + * avoid warnings with static code analyzers like smatch. + */ +#define get_user_cast(__x, __ptr) \ +({ \ + get_user(__x, (typeof(*__ptr) __user *)(__ptr)); \ +}) + +/** + * put_user_force() - Stores the contents of a kernelspace local var + * into a userspace pointer, removing any __user cast. + * + * @__x: var where data will be stored + * @__ptr: var where data will be retrieved. + * + * Sometimes we need to remove the __user attribute from some data, + * by passing the __force macro. This function ensures that the + * @__ptr will be cast with __force before calling put_user(), in order to + * avoid warnings with static code analyzers like smatch. + */ +#define put_user_force(__x, __ptr) \ +({ \ + put_user((typeof(*__x) __force *)(__x), __ptr); \ +}) + +/** + * assign_in_user_cast() - Copy from one __user var to another one + * + * @to: __user var where data will be stored + * @from: var where data will be retrieved that needs to be cast to __user. + * + * As this code very often needs to allocate userspace memory, it is easier + * to have a macro that will do both get_user_cast() and put_user() at once. + * + * This function should be used instead of assign_in_user() when the @from + * variable was not declared as __user. See get_user_cast() for more details. + * + * This function complements the macros defined at asm-generic/uaccess.h. + * It uses the same argument order as copy_in_user() + */ +#define assign_in_user_cast(to, from) \ +({ \ + typeof(*from) __assign_tmp; \ + \ + get_user_cast(__assign_tmp, from) || put_user(__assign_tmp, to);\ +}) + +/** + * native_ioctl - Ancillary function that calls the native 64 bits ioctl + * handler. + * + * @file: pointer to &struct file with the file handler + * @cmd: ioctl to be called + * @arg: arguments passed from/to the ioctl handler + * + * This function calls the native ioctl handler at v4l2-dev, e. g. v4l2_ioctl() + */ static long native_ioctl(struct file *file, unsigned int cmd, unsigned long arg) { long ret = -ENOIOCTLCMD; @@ -41,6 +119,21 @@ static long native_ioctl(struct file *file, unsigned int cmd, unsigned long arg) } +/* + * Per-ioctl data copy handlers. + * + * Those come in pairs, with a get_v4l2_foo() and a put_v4l2_foo() routine, + * where "v4l2_foo" is the name of the V4L2 struct. + * + * They basically get two __user pointers, one with a 32-bits struct that + * came from the userspace call and a 64-bits struct, also allocated as + * userspace, but filled internally by do_video_ioctl(). + * + * For ioctls that have pointers inside it, the functions will also + * receive an ancillary buffer with extra space, used to pass extra + * data to the routine. + */ + struct v4l2_clip32 { struct v4l2_rect c; compat_caddr_t next; @@ -56,8 +149,8 @@ struct v4l2_window32 { __u8 global_alpha; }; -static int get_v4l2_window32(struct v4l2_window __user *kp, - struct v4l2_window32 __user *up, +static int get_v4l2_window32(struct v4l2_window __user *p64, + struct v4l2_window32 __user *p32, void __user *aux_buf, u32 aux_space) { struct v4l2_clip32 __user *uclips; @@ -65,26 +158,26 @@ static int get_v4l2_window32(struct v4l2_window __user *kp, compat_caddr_t p; u32 clipcount; - if (!access_ok(VERIFY_READ, up, sizeof(*up)) || - copy_in_user(&kp->w, &up->w, sizeof(up->w)) || - assign_in_user(&kp->field, &up->field) || - assign_in_user(&kp->chromakey, &up->chromakey) || - assign_in_user(&kp->global_alpha, &up->global_alpha) || - get_user(clipcount, &up->clipcount) || - put_user(clipcount, &kp->clipcount)) + if (!access_ok(VERIFY_READ, p32, sizeof(*p32)) || + copy_in_user(&p64->w, &p32->w, sizeof(p32->w)) || + assign_in_user(&p64->field, &p32->field) || + assign_in_user(&p64->chromakey, &p32->chromakey) || + assign_in_user(&p64->global_alpha, &p32->global_alpha) || + get_user(clipcount, &p32->clipcount) || + put_user(clipcount, &p64->clipcount)) return -EFAULT; if (clipcount > 2048) return -EINVAL; if (!clipcount) - return put_user(NULL, &kp->clips); + return put_user(NULL, &p64->clips); - if (get_user(p, &up->clips)) + if (get_user(p, &p32->clips)) return -EFAULT; uclips = compat_ptr(p); if (aux_space < clipcount * sizeof(*kclips)) return -EFAULT; kclips = aux_buf; - if (put_user(kclips, &kp->clips)) + if (put_user(kclips, &p64->clips)) return -EFAULT; while (clipcount--) { @@ -98,27 +191,27 @@ static int get_v4l2_window32(struct v4l2_window __user *kp, return 0; } -static int put_v4l2_window32(struct v4l2_window __user *kp, - struct v4l2_window32 __user *up) +static int put_v4l2_window32(struct v4l2_window __user *p64, + struct v4l2_window32 __user *p32) { struct v4l2_clip __user *kclips; struct v4l2_clip32 __user *uclips; compat_caddr_t p; u32 clipcount; - if (copy_in_user(&up->w, &kp->w, sizeof(kp->w)) || - assign_in_user(&up->field, &kp->field) || - assign_in_user(&up->chromakey, &kp->chromakey) || - assign_in_user(&up->global_alpha, &kp->global_alpha) || - get_user(clipcount, &kp->clipcount) || - put_user(clipcount, &up->clipcount)) + if (copy_in_user(&p32->w, &p64->w, sizeof(p64->w)) || + assign_in_user(&p32->field, &p64->field) || + assign_in_user(&p32->chromakey, &p64->chromakey) || + assign_in_user(&p32->global_alpha, &p64->global_alpha) || + get_user(clipcount, &p64->clipcount) || + put_user(clipcount, &p32->clipcount)) return -EFAULT; if (!clipcount) return 0; - if (get_user(kclips, &kp->clips)) + if (get_user(kclips, &p64->clips)) return -EFAULT; - if (get_user(p, &up->clips)) + if (get_user(p, &p32->clips)) return -EFAULT; uclips = compat_ptr(p); while (clipcount--) { @@ -161,11 +254,11 @@ struct v4l2_create_buffers32 { __u32 reserved[8]; }; -static int __bufsize_v4l2_format(struct v4l2_format32 __user *up, u32 *size) +static int __bufsize_v4l2_format(struct v4l2_format32 __user *p32, u32 *size) { u32 type; - if (get_user(type, &up->type)) + if (get_user(type, &p32->type)) return -EFAULT; switch (type) { @@ -173,7 +266,7 @@ static int __bufsize_v4l2_format(struct v4l2_format32 __user *up, u32 *size) case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY: { u32 clipcount; - if (get_user(clipcount, &up->fmt.win.clipcount)) + if (get_user(clipcount, &p32->fmt.win.clipcount)) return -EFAULT; if (clipcount > 2048) return -EINVAL; @@ -186,141 +279,141 @@ static int __bufsize_v4l2_format(struct v4l2_format32 __user *up, u32 *size) } } -static int bufsize_v4l2_format(struct v4l2_format32 __user *up, u32 *size) +static int bufsize_v4l2_format(struct v4l2_format32 __user *p32, u32 *size) { - if (!access_ok(VERIFY_READ, up, sizeof(*up))) + if (!access_ok(VERIFY_READ, p32, sizeof(*p32))) return -EFAULT; - return __bufsize_v4l2_format(up, size); + return __bufsize_v4l2_format(p32, size); } -static int __get_v4l2_format32(struct v4l2_format __user *kp, - struct v4l2_format32 __user *up, +static int __get_v4l2_format32(struct v4l2_format __user *p64, + struct v4l2_format32 __user *p32, void __user *aux_buf, u32 aux_space) { u32 type; - if (get_user(type, &up->type) || put_user(type, &kp->type)) + if (get_user(type, &p32->type) || put_user(type, &p64->type)) return -EFAULT; switch (type) { case V4L2_BUF_TYPE_VIDEO_CAPTURE: case V4L2_BUF_TYPE_VIDEO_OUTPUT: - return copy_in_user(&kp->fmt.pix, &up->fmt.pix, - sizeof(kp->fmt.pix)) ? -EFAULT : 0; + return copy_in_user(&p64->fmt.pix, &p32->fmt.pix, + sizeof(p64->fmt.pix)) ? -EFAULT : 0; case V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE: case V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE: - return copy_in_user(&kp->fmt.pix_mp, &up->fmt.pix_mp, - sizeof(kp->fmt.pix_mp)) ? -EFAULT : 0; + return copy_in_user(&p64->fmt.pix_mp, &p32->fmt.pix_mp, + sizeof(p64->fmt.pix_mp)) ? -EFAULT : 0; case V4L2_BUF_TYPE_VIDEO_OVERLAY: case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY: - return get_v4l2_window32(&kp->fmt.win, &up->fmt.win, + return get_v4l2_window32(&p64->fmt.win, &p32->fmt.win, aux_buf, aux_space); case V4L2_BUF_TYPE_VBI_CAPTURE: case V4L2_BUF_TYPE_VBI_OUTPUT: - return copy_in_user(&kp->fmt.vbi, &up->fmt.vbi, - sizeof(kp->fmt.vbi)) ? -EFAULT : 0; + return copy_in_user(&p64->fmt.vbi, &p32->fmt.vbi, + sizeof(p64->fmt.vbi)) ? -EFAULT : 0; case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE: case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT: - return copy_in_user(&kp->fmt.sliced, &up->fmt.sliced, - sizeof(kp->fmt.sliced)) ? -EFAULT : 0; + return copy_in_user(&p64->fmt.sliced, &p32->fmt.sliced, + sizeof(p64->fmt.sliced)) ? -EFAULT : 0; case V4L2_BUF_TYPE_SDR_CAPTURE: case V4L2_BUF_TYPE_SDR_OUTPUT: - return copy_in_user(&kp->fmt.sdr, &up->fmt.sdr, - sizeof(kp->fmt.sdr)) ? -EFAULT : 0; + return copy_in_user(&p64->fmt.sdr, &p32->fmt.sdr, + sizeof(p64->fmt.sdr)) ? -EFAULT : 0; case V4L2_BUF_TYPE_META_CAPTURE: - return copy_in_user(&kp->fmt.meta, &up->fmt.meta, - sizeof(kp->fmt.meta)) ? -EFAULT : 0; + return copy_in_user(&p64->fmt.meta, &p32->fmt.meta, + sizeof(p64->fmt.meta)) ? -EFAULT : 0; default: return -EINVAL; } } -static int get_v4l2_format32(struct v4l2_format __user *kp, - struct v4l2_format32 __user *up, +static int get_v4l2_format32(struct v4l2_format __user *p64, + struct v4l2_format32 __user *p32, void __user *aux_buf, u32 aux_space) { - if (!access_ok(VERIFY_READ, up, sizeof(*up))) + if (!access_ok(VERIFY_READ, p32, sizeof(*p32))) return -EFAULT; - return __get_v4l2_format32(kp, up, aux_buf, aux_space); + return __get_v4l2_format32(p64, p32, aux_buf, aux_space); } -static int bufsize_v4l2_create(struct v4l2_create_buffers32 __user *up, +static int bufsize_v4l2_create(struct v4l2_create_buffers32 __user *p32, u32 *size) { - if (!access_ok(VERIFY_READ, up, sizeof(*up))) + if (!access_ok(VERIFY_READ, p32, sizeof(*p32))) return -EFAULT; - return __bufsize_v4l2_format(&up->format, size); + return __bufsize_v4l2_format(&p32->format, size); } -static int get_v4l2_create32(struct v4l2_create_buffers __user *kp, - struct v4l2_create_buffers32 __user *up, +static int get_v4l2_create32(struct v4l2_create_buffers __user *p64, + struct v4l2_create_buffers32 __user *p32, void __user *aux_buf, u32 aux_space) { - if (!access_ok(VERIFY_READ, up, sizeof(*up)) || - copy_in_user(kp, up, + if (!access_ok(VERIFY_READ, p32, sizeof(*p32)) || + copy_in_user(p64, p32, offsetof(struct v4l2_create_buffers32, format))) return -EFAULT; - return __get_v4l2_format32(&kp->format, &up->format, + return __get_v4l2_format32(&p64->format, &p32->format, aux_buf, aux_space); } -static int __put_v4l2_format32(struct v4l2_format __user *kp, - struct v4l2_format32 __user *up) +static int __put_v4l2_format32(struct v4l2_format __user *p64, + struct v4l2_format32 __user *p32) { u32 type; - if (get_user(type, &kp->type)) + if (get_user(type, &p64->type)) return -EFAULT; switch (type) { case V4L2_BUF_TYPE_VIDEO_CAPTURE: case V4L2_BUF_TYPE_VIDEO_OUTPUT: - return copy_in_user(&up->fmt.pix, &kp->fmt.pix, - sizeof(kp->fmt.pix)) ? -EFAULT : 0; + return copy_in_user(&p32->fmt.pix, &p64->fmt.pix, + sizeof(p64->fmt.pix)) ? -EFAULT : 0; case V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE: case V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE: - return copy_in_user(&up->fmt.pix_mp, &kp->fmt.pix_mp, - sizeof(kp->fmt.pix_mp)) ? -EFAULT : 0; + return copy_in_user(&p32->fmt.pix_mp, &p64->fmt.pix_mp, + sizeof(p64->fmt.pix_mp)) ? -EFAULT : 0; case V4L2_BUF_TYPE_VIDEO_OVERLAY: case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY: - return put_v4l2_window32(&kp->fmt.win, &up->fmt.win); + return put_v4l2_window32(&p64->fmt.win, &p32->fmt.win); case V4L2_BUF_TYPE_VBI_CAPTURE: case V4L2_BUF_TYPE_VBI_OUTPUT: - return copy_in_user(&up->fmt.vbi, &kp->fmt.vbi, - sizeof(kp->fmt.vbi)) ? -EFAULT : 0; + return copy_in_user(&p32->fmt.vbi, &p64->fmt.vbi, + sizeof(p64->fmt.vbi)) ? -EFAULT : 0; case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE: case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT: - return copy_in_user(&up->fmt.sliced, &kp->fmt.sliced, - sizeof(kp->fmt.sliced)) ? -EFAULT : 0; + return copy_in_user(&p32->fmt.sliced, &p64->fmt.sliced, + sizeof(p64->fmt.sliced)) ? -EFAULT : 0; case V4L2_BUF_TYPE_SDR_CAPTURE: case V4L2_BUF_TYPE_SDR_OUTPUT: - return copy_in_user(&up->fmt.sdr, &kp->fmt.sdr, - sizeof(kp->fmt.sdr)) ? -EFAULT : 0; + return copy_in_user(&p32->fmt.sdr, &p64->fmt.sdr, + sizeof(p64->fmt.sdr)) ? -EFAULT : 0; case V4L2_BUF_TYPE_META_CAPTURE: - return copy_in_user(&up->fmt.meta, &kp->fmt.meta, - sizeof(kp->fmt.meta)) ? -EFAULT : 0; + return copy_in_user(&p32->fmt.meta, &p64->fmt.meta, + sizeof(p64->fmt.meta)) ? -EFAULT : 0; default: return -EINVAL; } } -static int put_v4l2_format32(struct v4l2_format __user *kp, - struct v4l2_format32 __user *up) +static int put_v4l2_format32(struct v4l2_format __user *p64, + struct v4l2_format32 __user *p32) { - if (!access_ok(VERIFY_WRITE, up, sizeof(*up))) + if (!access_ok(VERIFY_WRITE, p32, sizeof(*p32))) return -EFAULT; - return __put_v4l2_format32(kp, up); + return __put_v4l2_format32(p64, p32); } -static int put_v4l2_create32(struct v4l2_create_buffers __user *kp, - struct v4l2_create_buffers32 __user *up) +static int put_v4l2_create32(struct v4l2_create_buffers __user *p64, + struct v4l2_create_buffers32 __user *p32) { - if (!access_ok(VERIFY_WRITE, up, sizeof(*up)) || - copy_in_user(up, kp, + if (!access_ok(VERIFY_WRITE, p32, sizeof(*p32)) || + copy_in_user(p32, p64, offsetof(struct v4l2_create_buffers32, format)) || - copy_in_user(up->reserved, kp->reserved, sizeof(kp->reserved))) + copy_in_user(p32->reserved, p64->reserved, sizeof(p64->reserved))) return -EFAULT; - return __put_v4l2_format32(&kp->format, &up->format); + return __put_v4l2_format32(&p64->format, &p32->format); } struct v4l2_standard32 { @@ -332,27 +425,27 @@ struct v4l2_standard32 { __u32 reserved[4]; }; -static int get_v4l2_standard32(struct v4l2_standard __user *kp, - struct v4l2_standard32 __user *up) +static int get_v4l2_standard32(struct v4l2_standard __user *p64, + struct v4l2_standard32 __user *p32) { /* other fields are not set by the user, nor used by the driver */ - if (!access_ok(VERIFY_READ, up, sizeof(*up)) || - assign_in_user(&kp->index, &up->index)) + if (!access_ok(VERIFY_READ, p32, sizeof(*p32)) || + assign_in_user(&p64->index, &p32->index)) return -EFAULT; return 0; } -static int put_v4l2_standard32(struct v4l2_standard __user *kp, - struct v4l2_standard32 __user *up) +static int put_v4l2_standard32(struct v4l2_standard __user *p64, + struct v4l2_standard32 __user *p32) { - if (!access_ok(VERIFY_WRITE, up, sizeof(*up)) || - assign_in_user(&up->index, &kp->index) || - assign_in_user(&up->id, &kp->id) || - copy_in_user(up->name, kp->name, sizeof(up->name)) || - copy_in_user(&up->frameperiod, &kp->frameperiod, - sizeof(up->frameperiod)) || - assign_in_user(&up->framelines, &kp->framelines) || - copy_in_user(up->reserved, kp->reserved, sizeof(up->reserved))) + if (!access_ok(VERIFY_WRITE, p32, sizeof(*p32)) || + assign_in_user(&p32->index, &p64->index) || + assign_in_user(&p32->id, &p64->id) || + copy_in_user(p32->name, p64->name, sizeof(p32->name)) || + copy_in_user(&p32->frameperiod, &p64->frameperiod, + sizeof(p32->frameperiod)) || + assign_in_user(&p32->framelines, &p64->framelines) || + copy_in_user(p32->reserved, p64->reserved, sizeof(p32->reserved))) return -EFAULT; return 0; } @@ -392,31 +485,31 @@ struct v4l2_buffer32 { __u32 reserved; }; -static int get_v4l2_plane32(struct v4l2_plane __user *up, - struct v4l2_plane32 __user *up32, +static int get_v4l2_plane32(struct v4l2_plane __user *p64, + struct v4l2_plane32 __user *p32, enum v4l2_memory memory) { compat_ulong_t p; - if (copy_in_user(up, up32, 2 * sizeof(__u32)) || - copy_in_user(&up->data_offset, &up32->data_offset, - sizeof(up->data_offset))) + if (copy_in_user(p64, p32, 2 * sizeof(__u32)) || + copy_in_user(&p64->data_offset, &p32->data_offset, + sizeof(p64->data_offset))) return -EFAULT; switch (memory) { case V4L2_MEMORY_MMAP: case V4L2_MEMORY_OVERLAY: - if (copy_in_user(&up->m.mem_offset, &up32->m.mem_offset, - sizeof(up32->m.mem_offset))) + if (copy_in_user(&p64->m.mem_offset, &p32->m.mem_offset, + sizeof(p32->m.mem_offset))) return -EFAULT; break; case V4L2_MEMORY_USERPTR: - if (get_user(p, &up32->m.userptr) || - put_user((unsigned long)compat_ptr(p), &up->m.userptr)) + if (get_user(p, &p32->m.userptr) || + put_user((unsigned long)compat_ptr(p), &p64->m.userptr)) return -EFAULT; break; case V4L2_MEMORY_DMABUF: - if (copy_in_user(&up->m.fd, &up32->m.fd, sizeof(up32->m.fd))) + if (copy_in_user(&p64->m.fd, &p32->m.fd, sizeof(p32->m.fd))) return -EFAULT; break; } @@ -424,32 +517,32 @@ static int get_v4l2_plane32(struct v4l2_plane __user *up, return 0; } -static int put_v4l2_plane32(struct v4l2_plane __user *up, - struct v4l2_plane32 __user *up32, +static int put_v4l2_plane32(struct v4l2_plane __user *p64, + struct v4l2_plane32 __user *p32, enum v4l2_memory memory) { unsigned long p; - if (copy_in_user(up32, up, 2 * sizeof(__u32)) || - copy_in_user(&up32->data_offset, &up->data_offset, - sizeof(up->data_offset))) + if (copy_in_user(p32, p64, 2 * sizeof(__u32)) || + copy_in_user(&p32->data_offset, &p64->data_offset, + sizeof(p64->data_offset))) return -EFAULT; switch (memory) { case V4L2_MEMORY_MMAP: case V4L2_MEMORY_OVERLAY: - if (copy_in_user(&up32->m.mem_offset, &up->m.mem_offset, - sizeof(up->m.mem_offset))) + if (copy_in_user(&p32->m.mem_offset, &p64->m.mem_offset, + sizeof(p64->m.mem_offset))) return -EFAULT; break; case V4L2_MEMORY_USERPTR: - if (get_user(p, &up->m.userptr) || - put_user((compat_ulong_t)ptr_to_compat((__force void *)p), - &up32->m.userptr)) + if (get_user(p, &p64->m.userptr) || + put_user((compat_ulong_t)ptr_to_compat((void __user *)p), + &p32->m.userptr)) return -EFAULT; break; case V4L2_MEMORY_DMABUF: - if (copy_in_user(&up32->m.fd, &up->m.fd, sizeof(up->m.fd))) + if (copy_in_user(&p32->m.fd, &p64->m.fd, sizeof(p64->m.fd))) return -EFAULT; break; } @@ -457,14 +550,14 @@ static int put_v4l2_plane32(struct v4l2_plane __user *up, return 0; } -static int bufsize_v4l2_buffer(struct v4l2_buffer32 __user *up, u32 *size) +static int bufsize_v4l2_buffer(struct v4l2_buffer32 __user *p32, u32 *size) { u32 type; u32 length; - if (!access_ok(VERIFY_READ, up, sizeof(*up)) || - get_user(type, &up->type) || - get_user(length, &up->length)) + if (!access_ok(VERIFY_READ, p32, sizeof(*p32)) || + get_user(type, &p32->type) || + get_user(length, &p32->length)) return -EFAULT; if (V4L2_TYPE_IS_MULTIPLANAR(type)) { @@ -482,8 +575,8 @@ static int bufsize_v4l2_buffer(struct v4l2_buffer32 __user *up, u32 *size) return 0; } -static int get_v4l2_buffer32(struct v4l2_buffer __user *kp, - struct v4l2_buffer32 __user *up, +static int get_v4l2_buffer32(struct v4l2_buffer __user *p64, + struct v4l2_buffer32 __user *p32, void __user *aux_buf, u32 aux_space) { u32 type; @@ -494,24 +587,24 @@ static int get_v4l2_buffer32(struct v4l2_buffer __user *kp, compat_caddr_t p; int ret; - if (!access_ok(VERIFY_READ, up, sizeof(*up)) || - assign_in_user(&kp->index, &up->index) || - get_user(type, &up->type) || - put_user(type, &kp->type) || - assign_in_user(&kp->flags, &up->flags) || - get_user(memory, &up->memory) || - put_user(memory, &kp->memory) || - get_user(length, &up->length) || - put_user(length, &kp->length)) + if (!access_ok(VERIFY_READ, p32, sizeof(*p32)) || + assign_in_user(&p64->index, &p32->index) || + get_user(type, &p32->type) || + put_user(type, &p64->type) || + assign_in_user(&p64->flags, &p32->flags) || + get_user(memory, &p32->memory) || + put_user(memory, &p64->memory) || + get_user(length, &p32->length) || + put_user(length, &p64->length)) return -EFAULT; if (V4L2_TYPE_IS_OUTPUT(type)) - if (assign_in_user(&kp->bytesused, &up->bytesused) || - assign_in_user(&kp->field, &up->field) || - assign_in_user(&kp->timestamp.tv_sec, - &up->timestamp.tv_sec) || - assign_in_user(&kp->timestamp.tv_usec, - &up->timestamp.tv_usec)) + if (assign_in_user(&p64->bytesused, &p32->bytesused) || + assign_in_user(&p64->field, &p32->field) || + assign_in_user(&p64->timestamp.tv_sec, + &p32->timestamp.tv_sec) || + assign_in_user(&p64->timestamp.tv_usec, + &p32->timestamp.tv_usec)) return -EFAULT; if (V4L2_TYPE_IS_MULTIPLANAR(type)) { @@ -522,12 +615,12 @@ static int get_v4l2_buffer32(struct v4l2_buffer __user *kp, * num_planes == 0 is legal, e.g. when userspace doesn't * need planes array on DQBUF */ - return put_user(NULL, &kp->m.planes); + return put_user(NULL, &p64->m.planes); } if (num_planes > VIDEO_MAX_PLANES) return -EINVAL; - if (get_user(p, &up->m.planes)) + if (get_user(p, &p32->m.planes)) return -EFAULT; uplane32 = compat_ptr(p); @@ -543,8 +636,7 @@ static int get_v4l2_buffer32(struct v4l2_buffer __user *kp, return -EFAULT; uplane = aux_buf; - if (put_user((__force struct v4l2_plane *)uplane, - &kp->m.planes)) + if (put_user_force(uplane, &p64->m.planes)) return -EFAULT; while (num_planes--) { @@ -558,20 +650,20 @@ static int get_v4l2_buffer32(struct v4l2_buffer __user *kp, switch (memory) { case V4L2_MEMORY_MMAP: case V4L2_MEMORY_OVERLAY: - if (assign_in_user(&kp->m.offset, &up->m.offset)) + if (assign_in_user(&p64->m.offset, &p32->m.offset)) return -EFAULT; break; case V4L2_MEMORY_USERPTR: { compat_ulong_t userptr; - if (get_user(userptr, &up->m.userptr) || + if (get_user(userptr, &p32->m.userptr) || put_user((unsigned long)compat_ptr(userptr), - &kp->m.userptr)) + &p64->m.userptr)) return -EFAULT; break; } case V4L2_MEMORY_DMABUF: - if (assign_in_user(&kp->m.fd, &up->m.fd)) + if (assign_in_user(&p64->m.fd, &p32->m.fd)) return -EFAULT; break; } @@ -580,36 +672,36 @@ static int get_v4l2_buffer32(struct v4l2_buffer __user *kp, return 0; } -static int put_v4l2_buffer32(struct v4l2_buffer __user *kp, - struct v4l2_buffer32 __user *up) +static int put_v4l2_buffer32(struct v4l2_buffer __user *p64, + struct v4l2_buffer32 __user *p32) { u32 type; u32 length; enum v4l2_memory memory; struct v4l2_plane32 __user *uplane32; - struct v4l2_plane __user *uplane; + struct v4l2_plane *uplane; compat_caddr_t p; int ret; - if (!access_ok(VERIFY_WRITE, up, sizeof(*up)) || - assign_in_user(&up->index, &kp->index) || - get_user(type, &kp->type) || - put_user(type, &up->type) || - assign_in_user(&up->flags, &kp->flags) || - get_user(memory, &kp->memory) || - put_user(memory, &up->memory)) + if (!access_ok(VERIFY_WRITE, p32, sizeof(*p32)) || + assign_in_user(&p32->index, &p64->index) || + get_user(type, &p64->type) || + put_user(type, &p32->type) || + assign_in_user(&p32->flags, &p64->flags) || + get_user(memory, &p64->memory) || + put_user(memory, &p32->memory)) return -EFAULT; - if (assign_in_user(&up->bytesused, &kp->bytesused) || - assign_in_user(&up->field, &kp->field) || - assign_in_user(&up->timestamp.tv_sec, &kp->timestamp.tv_sec) || - assign_in_user(&up->timestamp.tv_usec, &kp->timestamp.tv_usec) || - copy_in_user(&up->timecode, &kp->timecode, sizeof(kp->timecode)) || - assign_in_user(&up->sequence, &kp->sequence) || - assign_in_user(&up->reserved2, &kp->reserved2) || - assign_in_user(&up->reserved, &kp->reserved) || - get_user(length, &kp->length) || - put_user(length, &up->length)) + if (assign_in_user(&p32->bytesused, &p64->bytesused) || + assign_in_user(&p32->field, &p64->field) || + assign_in_user(&p32->timestamp.tv_sec, &p64->timestamp.tv_sec) || + assign_in_user(&p32->timestamp.tv_usec, &p64->timestamp.tv_usec) || + copy_in_user(&p32->timecode, &p64->timecode, sizeof(p64->timecode)) || + assign_in_user(&p32->sequence, &p64->sequence) || + assign_in_user(&p32->reserved2, &p64->reserved2) || + assign_in_user(&p32->reserved, &p64->reserved) || + get_user(length, &p64->length) || + put_user(length, &p32->length)) return -EFAULT; if (V4L2_TYPE_IS_MULTIPLANAR(type)) { @@ -617,15 +709,23 @@ static int put_v4l2_buffer32(struct v4l2_buffer __user *kp, if (num_planes == 0) return 0; - - if (get_user(uplane, ((__force struct v4l2_plane __user **)&kp->m.planes))) + /* We need to define uplane without __user, even though + * it does point to data in userspace here. The reason is + * that v4l2-ioctl.c copies it from userspace to kernelspace, + * so its definition in videodev2.h doesn't have a + * __user markup. Defining uplane with __user causes + * smatch warnings, so instead declare it without __user + * and cast it as a userspace pointer to put_v4l2_plane32(). + */ + if (get_user(uplane, &p64->m.planes)) return -EFAULT; - if (get_user(p, &up->m.planes)) + if (get_user(p, &p32->m.planes)) return -EFAULT; uplane32 = compat_ptr(p); while (num_planes--) { - ret = put_v4l2_plane32(uplane, uplane32, memory); + ret = put_v4l2_plane32((void __user *)uplane, + uplane32, memory); if (ret) return ret; ++uplane; @@ -635,15 +735,15 @@ static int put_v4l2_buffer32(struct v4l2_buffer __user *kp, switch (memory) { case V4L2_MEMORY_MMAP: case V4L2_MEMORY_OVERLAY: - if (assign_in_user(&up->m.offset, &kp->m.offset)) + if (assign_in_user(&p32->m.offset, &p64->m.offset)) return -EFAULT; break; case V4L2_MEMORY_USERPTR: - if (assign_in_user(&up->m.userptr, &kp->m.userptr)) + if (assign_in_user(&p32->m.userptr, &p64->m.userptr)) return -EFAULT; break; case V4L2_MEMORY_DMABUF: - if (assign_in_user(&up->m.fd, &kp->m.fd)) + if (assign_in_user(&p32->m.fd, &p64->m.fd)) return -EFAULT; break; } @@ -668,32 +768,32 @@ struct v4l2_framebuffer32 { } fmt; }; -static int get_v4l2_framebuffer32(struct v4l2_framebuffer __user *kp, - struct v4l2_framebuffer32 __user *up) +static int get_v4l2_framebuffer32(struct v4l2_framebuffer __user *p64, + struct v4l2_framebuffer32 __user *p32) { compat_caddr_t tmp; - if (!access_ok(VERIFY_READ, up, sizeof(*up)) || - get_user(tmp, &up->base) || - put_user((__force void *)compat_ptr(tmp), &kp->base) || - assign_in_user(&kp->capability, &up->capability) || - assign_in_user(&kp->flags, &up->flags) || - copy_in_user(&kp->fmt, &up->fmt, sizeof(kp->fmt))) + if (!access_ok(VERIFY_READ, p32, sizeof(*p32)) || + get_user(tmp, &p32->base) || + put_user_force(compat_ptr(tmp), &p64->base) || + assign_in_user(&p64->capability, &p32->capability) || + assign_in_user(&p64->flags, &p32->flags) || + copy_in_user(&p64->fmt, &p32->fmt, sizeof(p64->fmt))) return -EFAULT; return 0; } -static int put_v4l2_framebuffer32(struct v4l2_framebuffer __user *kp, - struct v4l2_framebuffer32 __user *up) +static int put_v4l2_framebuffer32(struct v4l2_framebuffer __user *p64, + struct v4l2_framebuffer32 __user *p32) { void *base; - if (!access_ok(VERIFY_WRITE, up, sizeof(*up)) || - get_user(base, &kp->base) || - put_user(ptr_to_compat(base), &up->base) || - assign_in_user(&up->capability, &kp->capability) || - assign_in_user(&up->flags, &kp->flags) || - copy_in_user(&up->fmt, &kp->fmt, sizeof(kp->fmt))) + if (!access_ok(VERIFY_WRITE, p32, sizeof(*p32)) || + get_user(base, &p64->base) || + put_user(ptr_to_compat((void __user *)base), &p32->base) || + assign_in_user(&p32->capability, &p64->capability) || + assign_in_user(&p32->flags, &p64->flags) || + copy_in_user(&p32->fmt, &p64->fmt, sizeof(p64->fmt))) return -EFAULT; return 0; } @@ -714,18 +814,18 @@ struct v4l2_input32 { * The 64-bit v4l2_input struct has extra padding at the end of the struct. * Otherwise it is identical to the 32-bit version. */ -static inline int get_v4l2_input32(struct v4l2_input __user *kp, - struct v4l2_input32 __user *up) +static inline int get_v4l2_input32(struct v4l2_input __user *p64, + struct v4l2_input32 __user *p32) { - if (copy_in_user(kp, up, sizeof(*up))) + if (copy_in_user(p64, p32, sizeof(*p32))) return -EFAULT; return 0; } -static inline int put_v4l2_input32(struct v4l2_input __user *kp, - struct v4l2_input32 __user *up) +static inline int put_v4l2_input32(struct v4l2_input __user *p64, + struct v4l2_input32 __user *p32) { - if (copy_in_user(up, kp, sizeof(*up))) + if (copy_in_user(p32, p64, sizeof(*p32))) return -EFAULT; return 0; } @@ -779,13 +879,13 @@ static inline bool ctrl_is_pointer(struct file *file, u32 id) (qec.flags & V4L2_CTRL_FLAG_HAS_PAYLOAD); } -static int bufsize_v4l2_ext_controls(struct v4l2_ext_controls32 __user *up, +static int bufsize_v4l2_ext_controls(struct v4l2_ext_controls32 __user *p32, u32 *size) { u32 count; - if (!access_ok(VERIFY_READ, up, sizeof(*up)) || - get_user(count, &up->count)) + if (!access_ok(VERIFY_READ, p32, sizeof(*p32)) || + get_user(count, &p32->count)) return -EFAULT; if (count > V4L2_CID_MAX_CTRLS) return -EINVAL; @@ -794,8 +894,8 @@ static int bufsize_v4l2_ext_controls(struct v4l2_ext_controls32 __user *up, } static int get_v4l2_ext_controls32(struct file *file, - struct v4l2_ext_controls __user *kp, - struct v4l2_ext_controls32 __user *up, + struct v4l2_ext_controls __user *p64, + struct v4l2_ext_controls32 __user *p32, void __user *aux_buf, u32 aux_space) { struct v4l2_ext_control32 __user *ucontrols; @@ -804,19 +904,19 @@ static int get_v4l2_ext_controls32(struct file *file, u32 n; compat_caddr_t p; - if (!access_ok(VERIFY_READ, up, sizeof(*up)) || - assign_in_user(&kp->which, &up->which) || - get_user(count, &up->count) || - put_user(count, &kp->count) || - assign_in_user(&kp->error_idx, &up->error_idx) || - copy_in_user(kp->reserved, up->reserved, sizeof(kp->reserved))) + if (!access_ok(VERIFY_READ, p32, sizeof(*p32)) || + assign_in_user(&p64->which, &p32->which) || + get_user(count, &p32->count) || + put_user(count, &p64->count) || + assign_in_user(&p64->error_idx, &p32->error_idx) || + copy_in_user(p64->reserved, p32->reserved, sizeof(p64->reserved))) return -EFAULT; if (count == 0) - return put_user(NULL, &kp->controls); + return put_user(NULL, &p64->controls); if (count > V4L2_CID_MAX_CTRLS) return -EINVAL; - if (get_user(p, &up->controls)) + if (get_user(p, &p32->controls)) return -EFAULT; ucontrols = compat_ptr(p); if (!access_ok(VERIFY_READ, ucontrols, count * sizeof(*ucontrols))) @@ -824,8 +924,7 @@ static int get_v4l2_ext_controls32(struct file *file, if (aux_space < count * sizeof(*kcontrols)) return -EFAULT; kcontrols = aux_buf; - if (put_user((__force struct v4l2_ext_control *)kcontrols, - &kp->controls)) + if (put_user_force(kcontrols, &p64->controls)) return -EFAULT; for (n = 0; n < count; n++) { @@ -853,27 +952,35 @@ static int get_v4l2_ext_controls32(struct file *file, } static int put_v4l2_ext_controls32(struct file *file, - struct v4l2_ext_controls __user *kp, - struct v4l2_ext_controls32 __user *up) + struct v4l2_ext_controls __user *p64, + struct v4l2_ext_controls32 __user *p32) { struct v4l2_ext_control32 __user *ucontrols; - struct v4l2_ext_control __user *kcontrols; + struct v4l2_ext_control *kcontrols; u32 count; u32 n; compat_caddr_t p; - if (!access_ok(VERIFY_WRITE, up, sizeof(*up)) || - assign_in_user(&up->which, &kp->which) || - get_user(count, &kp->count) || - put_user(count, &up->count) || - assign_in_user(&up->error_idx, &kp->error_idx) || - copy_in_user(up->reserved, kp->reserved, sizeof(up->reserved)) || - get_user(kcontrols, &kp->controls)) + /* + * We need to define kcontrols without __user, even though it does + * point to data in userspace here. The reason is that v4l2-ioctl.c + * copies it from userspace to kernelspace, so its definition in + * videodev2.h doesn't have a __user markup. Defining kcontrols + * with __user causes smatch warnings, so instead declare it + * without __user and cast it as a userspace pointer where needed. + */ + if (!access_ok(VERIFY_WRITE, p32, sizeof(*p32)) || + assign_in_user(&p32->which, &p64->which) || + get_user(count, &p64->count) || + put_user(count, &p32->count) || + assign_in_user(&p32->error_idx, &p64->error_idx) || + copy_in_user(p32->reserved, p64->reserved, sizeof(p32->reserved)) || + get_user(kcontrols, &p64->controls)) return -EFAULT; - if (!count) + if (!count || count > (U32_MAX/sizeof(*ucontrols))) return 0; - if (get_user(p, &up->controls)) + if (get_user(p, &p32->controls)) return -EFAULT; ucontrols = compat_ptr(p); if (!access_ok(VERIFY_WRITE, ucontrols, count * sizeof(*ucontrols))) @@ -883,10 +990,11 @@ static int put_v4l2_ext_controls32(struct file *file, unsigned int size = sizeof(*ucontrols); u32 id; - if (get_user(id, &kcontrols->id) || + if (get_user_cast(id, &kcontrols->id) || put_user(id, &ucontrols->id) || - assign_in_user(&ucontrols->size, &kcontrols->size) || - copy_in_user(&ucontrols->reserved2, &kcontrols->reserved2, + assign_in_user_cast(&ucontrols->size, &kcontrols->size) || + copy_in_user(&ucontrols->reserved2, + (void __user *)&kcontrols->reserved2, sizeof(ucontrols->reserved2))) return -EFAULT; @@ -898,7 +1006,8 @@ static int put_v4l2_ext_controls32(struct file *file, if (ctrl_is_pointer(file, id)) size -= sizeof(ucontrols->value64); - if (copy_in_user(ucontrols, kcontrols, size)) + if (copy_in_user(ucontrols, + (void __user *)kcontrols, size)) return -EFAULT; ucontrols++; @@ -920,18 +1029,18 @@ struct v4l2_event32 { __u32 reserved[8]; }; -static int put_v4l2_event32(struct v4l2_event __user *kp, - struct v4l2_event32 __user *up) +static int put_v4l2_event32(struct v4l2_event __user *p64, + struct v4l2_event32 __user *p32) { - if (!access_ok(VERIFY_WRITE, up, sizeof(*up)) || - assign_in_user(&up->type, &kp->type) || - copy_in_user(&up->u, &kp->u, sizeof(kp->u)) || - assign_in_user(&up->pending, &kp->pending) || - assign_in_user(&up->sequence, &kp->sequence) || - assign_in_user(&up->timestamp.tv_sec, &kp->timestamp.tv_sec) || - assign_in_user(&up->timestamp.tv_nsec, &kp->timestamp.tv_nsec) || - assign_in_user(&up->id, &kp->id) || - copy_in_user(up->reserved, kp->reserved, sizeof(up->reserved))) + if (!access_ok(VERIFY_WRITE, p32, sizeof(*p32)) || + assign_in_user(&p32->type, &p64->type) || + copy_in_user(&p32->u, &p64->u, sizeof(p64->u)) || + assign_in_user(&p32->pending, &p64->pending) || + assign_in_user(&p32->sequence, &p64->sequence) || + assign_in_user(&p32->timestamp.tv_sec, &p64->timestamp.tv_sec) || + assign_in_user(&p32->timestamp.tv_nsec, &p64->timestamp.tv_nsec) || + assign_in_user(&p32->id, &p64->id) || + copy_in_user(p32->reserved, p64->reserved, sizeof(p32->reserved))) return -EFAULT; return 0; } @@ -944,38 +1053,45 @@ struct v4l2_edid32 { compat_caddr_t edid; }; -static int get_v4l2_edid32(struct v4l2_edid __user *kp, - struct v4l2_edid32 __user *up) +static int get_v4l2_edid32(struct v4l2_edid __user *p64, + struct v4l2_edid32 __user *p32) { compat_uptr_t tmp; - if (!access_ok(VERIFY_READ, up, sizeof(*up)) || - assign_in_user(&kp->pad, &up->pad) || - assign_in_user(&kp->start_block, &up->start_block) || - assign_in_user(&kp->blocks, &up->blocks) || - get_user(tmp, &up->edid) || - put_user(compat_ptr(tmp), &kp->edid) || - copy_in_user(kp->reserved, up->reserved, sizeof(kp->reserved))) + if (!access_ok(VERIFY_READ, p32, sizeof(*p32)) || + assign_in_user(&p64->pad, &p32->pad) || + assign_in_user(&p64->start_block, &p32->start_block) || + assign_in_user_cast(&p64->blocks, &p32->blocks) || + get_user(tmp, &p32->edid) || + put_user_force(compat_ptr(tmp), &p64->edid) || + copy_in_user(p64->reserved, p32->reserved, sizeof(p64->reserved))) return -EFAULT; return 0; } -static int put_v4l2_edid32(struct v4l2_edid __user *kp, - struct v4l2_edid32 __user *up) +static int put_v4l2_edid32(struct v4l2_edid __user *p64, + struct v4l2_edid32 __user *p32) { void *edid; - if (!access_ok(VERIFY_WRITE, up, sizeof(*up)) || - assign_in_user(&up->pad, &kp->pad) || - assign_in_user(&up->start_block, &kp->start_block) || - assign_in_user(&up->blocks, &kp->blocks) || - get_user(edid, &kp->edid) || - put_user(ptr_to_compat(edid), &up->edid) || - copy_in_user(up->reserved, kp->reserved, sizeof(up->reserved))) + if (!access_ok(VERIFY_WRITE, p32, sizeof(*p32)) || + assign_in_user(&p32->pad, &p64->pad) || + assign_in_user(&p32->start_block, &p64->start_block) || + assign_in_user(&p32->blocks, &p64->blocks) || + get_user(edid, &p64->edid) || + put_user(ptr_to_compat((void __user *)edid), &p32->edid) || + copy_in_user(p32->reserved, p64->reserved, sizeof(p32->reserved))) return -EFAULT; return 0; } +/* + * List of ioctls that require 32-bits/64-bits conversion + * + * The V4L2 ioctls that aren't listed there don't have pointer arguments + * and the struct size is identical for both 32 and 64 bits versions, so + * they don't need translations. + */ #define VIDIOC_G_FMT32 _IOWR('V', 4, struct v4l2_format32) #define VIDIOC_S_FMT32 _IOWR('V', 5, struct v4l2_format32) @@ -1004,27 +1120,61 @@ static int put_v4l2_edid32(struct v4l2_edid __user *kp, #define VIDIOC_G_OUTPUT32 _IOR ('V', 46, s32) #define VIDIOC_S_OUTPUT32 _IOWR('V', 47, s32) +/** + * alloc_userspace() - Allocates a 64-bits userspace pointer compatible + * for calling the native 64-bits version of an ioctl. + * + * @size: size of the structure itself to be allocated. + * @aux_space: extra size needed to store "extra" data, e.g. space for + * other __user data that is pointed to fields inside the + * structure. + * @new_p64: pointer to a pointer to be filled with the allocated struct. + * + * Return: + * + * if it can't allocate memory, either -ENOMEM or -EFAULT will be returned. + * Zero otherwise. + */ static int alloc_userspace(unsigned int size, u32 aux_space, - void __user **up_native) + void __user **new_p64) { - *up_native = compat_alloc_user_space(size + aux_space); - if (!*up_native) + *new_p64 = compat_alloc_user_space(size + aux_space); + if (!*new_p64) return -ENOMEM; - if (clear_user(*up_native, size)) + if (clear_user(*new_p64, size)) return -EFAULT; return 0; } +/** + * do_video_ioctl() - Ancillary function with handles a compat32 ioctl call + * + * @file: pointer to &struct file with the file handler + * @cmd: ioctl to be called + * @arg: arguments passed from/to the ioctl handler + * + * This function is called when a 32 bits application calls a V4L2 ioctl + * and the Kernel is compiled with 64 bits. + * + * This function is called by v4l2_compat_ioctl32() when the function is + * not private to some specific driver. + * + * It converts a 32-bits struct into a 64 bits one, calls the native 64-bits + * ioctl handler and fills back the 32-bits struct with the results of the + * native call. + */ static long do_video_ioctl(struct file *file, unsigned int cmd, unsigned long arg) { - void __user *up = compat_ptr(arg); - void __user *up_native = NULL; + void __user *p32 = compat_ptr(arg); + void __user *new_p64 = NULL; void __user *aux_buf; u32 aux_space; int compatible_arg = 1; long err = 0; - /* First, convert the command. */ + /* + * 1. When struct size is different, converts the command. + */ switch (cmd) { case VIDIOC_G_FMT32: cmd = VIDIOC_G_FMT; break; case VIDIOC_S_FMT32: cmd = VIDIOC_S_FMT; break; @@ -1053,56 +1203,61 @@ static long do_video_ioctl(struct file *file, unsigned int cmd, unsigned long ar case VIDIOC_S_EDID32: cmd = VIDIOC_S_EDID; break; } + /* + * 2. Allocates a 64-bits userspace pointer to store the + * values of the ioctl and copy data from the 32-bits __user + * argument into it. + */ switch (cmd) { case VIDIOC_OVERLAY: case VIDIOC_STREAMON: case VIDIOC_STREAMOFF: case VIDIOC_S_INPUT: case VIDIOC_S_OUTPUT: - err = alloc_userspace(sizeof(unsigned int), 0, &up_native); - if (!err && assign_in_user((unsigned int __user *)up_native, - (compat_uint_t __user *)up)) + err = alloc_userspace(sizeof(unsigned int), 0, &new_p64); + if (!err && assign_in_user((unsigned int __user *)new_p64, + (compat_uint_t __user *)p32)) err = -EFAULT; compatible_arg = 0; break; case VIDIOC_G_INPUT: case VIDIOC_G_OUTPUT: - err = alloc_userspace(sizeof(unsigned int), 0, &up_native); + err = alloc_userspace(sizeof(unsigned int), 0, &new_p64); compatible_arg = 0; break; case VIDIOC_G_EDID: case VIDIOC_S_EDID: - err = alloc_userspace(sizeof(struct v4l2_edid), 0, &up_native); + err = alloc_userspace(sizeof(struct v4l2_edid), 0, &new_p64); if (!err) - err = get_v4l2_edid32(up_native, up); + err = get_v4l2_edid32(new_p64, p32); compatible_arg = 0; break; case VIDIOC_G_FMT: case VIDIOC_S_FMT: case VIDIOC_TRY_FMT: - err = bufsize_v4l2_format(up, &aux_space); + err = bufsize_v4l2_format(p32, &aux_space); if (!err) err = alloc_userspace(sizeof(struct v4l2_format), - aux_space, &up_native); + aux_space, &new_p64); if (!err) { - aux_buf = up_native + sizeof(struct v4l2_format); - err = get_v4l2_format32(up_native, up, + aux_buf = new_p64 + sizeof(struct v4l2_format); + err = get_v4l2_format32(new_p64, p32, aux_buf, aux_space); } compatible_arg = 0; break; case VIDIOC_CREATE_BUFS: - err = bufsize_v4l2_create(up, &aux_space); + err = bufsize_v4l2_create(p32, &aux_space); if (!err) err = alloc_userspace(sizeof(struct v4l2_create_buffers), - aux_space, &up_native); + aux_space, &new_p64); if (!err) { - aux_buf = up_native + sizeof(struct v4l2_create_buffers); - err = get_v4l2_create32(up_native, up, + aux_buf = new_p64 + sizeof(struct v4l2_create_buffers); + err = get_v4l2_create32(new_p64, p32, aux_buf, aux_space); } compatible_arg = 0; @@ -1112,13 +1267,13 @@ static long do_video_ioctl(struct file *file, unsigned int cmd, unsigned long ar case VIDIOC_QUERYBUF: case VIDIOC_QBUF: case VIDIOC_DQBUF: - err = bufsize_v4l2_buffer(up, &aux_space); + err = bufsize_v4l2_buffer(p32, &aux_space); if (!err) err = alloc_userspace(sizeof(struct v4l2_buffer), - aux_space, &up_native); + aux_space, &new_p64); if (!err) { - aux_buf = up_native + sizeof(struct v4l2_buffer); - err = get_v4l2_buffer32(up_native, up, + aux_buf = new_p64 + sizeof(struct v4l2_buffer); + err = get_v4l2_buffer32(new_p64, p32, aux_buf, aux_space); } compatible_arg = 0; @@ -1126,133 +1281,165 @@ static long do_video_ioctl(struct file *file, unsigned int cmd, unsigned long ar case VIDIOC_S_FBUF: err = alloc_userspace(sizeof(struct v4l2_framebuffer), 0, - &up_native); + &new_p64); if (!err) - err = get_v4l2_framebuffer32(up_native, up); + err = get_v4l2_framebuffer32(new_p64, p32); compatible_arg = 0; break; case VIDIOC_G_FBUF: err = alloc_userspace(sizeof(struct v4l2_framebuffer), 0, - &up_native); + &new_p64); compatible_arg = 0; break; case VIDIOC_ENUMSTD: err = alloc_userspace(sizeof(struct v4l2_standard), 0, - &up_native); + &new_p64); if (!err) - err = get_v4l2_standard32(up_native, up); + err = get_v4l2_standard32(new_p64, p32); compatible_arg = 0; break; case VIDIOC_ENUMINPUT: - err = alloc_userspace(sizeof(struct v4l2_input), 0, &up_native); + err = alloc_userspace(sizeof(struct v4l2_input), 0, &new_p64); if (!err) - err = get_v4l2_input32(up_native, up); + err = get_v4l2_input32(new_p64, p32); compatible_arg = 0; break; case VIDIOC_G_EXT_CTRLS: case VIDIOC_S_EXT_CTRLS: case VIDIOC_TRY_EXT_CTRLS: - err = bufsize_v4l2_ext_controls(up, &aux_space); + err = bufsize_v4l2_ext_controls(p32, &aux_space); if (!err) err = alloc_userspace(sizeof(struct v4l2_ext_controls), - aux_space, &up_native); + aux_space, &new_p64); if (!err) { - aux_buf = up_native + sizeof(struct v4l2_ext_controls); - err = get_v4l2_ext_controls32(file, up_native, up, + aux_buf = new_p64 + sizeof(struct v4l2_ext_controls); + err = get_v4l2_ext_controls32(file, new_p64, p32, aux_buf, aux_space); } compatible_arg = 0; break; case VIDIOC_DQEVENT: - err = alloc_userspace(sizeof(struct v4l2_event), 0, &up_native); + err = alloc_userspace(sizeof(struct v4l2_event), 0, &new_p64); compatible_arg = 0; break; } if (err) return err; + /* + * 3. Calls the native 64-bits ioctl handler. + * + * For the functions where a conversion was not needed, + * compatible_arg is true, and it will call it with the arguments + * provided by userspace and stored at @p32 var. + * + * Otherwise, it will pass the newly allocated @new_p64 argument. + */ if (compatible_arg) - err = native_ioctl(file, cmd, (unsigned long)up); + err = native_ioctl(file, cmd, (unsigned long)p32); else - err = native_ioctl(file, cmd, (unsigned long)up_native); + err = native_ioctl(file, cmd, (unsigned long)new_p64); if (err == -ENOTTY) return err; /* - * Special case: even after an error we need to put the - * results back for these ioctls since the error_idx will - * contain information on which control failed. + * 4. Special case: even after an error we need to put the + * results back for some ioctls. + * + * In the case of EXT_CTRLS, the error_idx will contain information + * on which control failed. + * + * In the case of S_EDID, the driver can return E2BIG and set + * the blocks to maximum allowed value. */ switch (cmd) { case VIDIOC_G_EXT_CTRLS: case VIDIOC_S_EXT_CTRLS: case VIDIOC_TRY_EXT_CTRLS: - if (put_v4l2_ext_controls32(file, up_native, up)) + if (put_v4l2_ext_controls32(file, new_p64, p32)) err = -EFAULT; break; case VIDIOC_S_EDID: - if (put_v4l2_edid32(up_native, up)) + if (put_v4l2_edid32(new_p64, p32)) err = -EFAULT; break; } if (err) return err; + /* + * 5. Copy the data returned at the 64 bits userspace pointer to + * the original 32 bits structure. + */ switch (cmd) { case VIDIOC_S_INPUT: case VIDIOC_S_OUTPUT: case VIDIOC_G_INPUT: case VIDIOC_G_OUTPUT: - if (assign_in_user((compat_uint_t __user *)up, - ((unsigned int __user *)up_native))) + if (assign_in_user((compat_uint_t __user *)p32, + ((unsigned int __user *)new_p64))) err = -EFAULT; break; case VIDIOC_G_FBUF: - err = put_v4l2_framebuffer32(up_native, up); + err = put_v4l2_framebuffer32(new_p64, p32); break; case VIDIOC_DQEVENT: - err = put_v4l2_event32(up_native, up); + err = put_v4l2_event32(new_p64, p32); break; case VIDIOC_G_EDID: - err = put_v4l2_edid32(up_native, up); + err = put_v4l2_edid32(new_p64, p32); break; case VIDIOC_G_FMT: case VIDIOC_S_FMT: case VIDIOC_TRY_FMT: - err = put_v4l2_format32(up_native, up); + err = put_v4l2_format32(new_p64, p32); break; case VIDIOC_CREATE_BUFS: - err = put_v4l2_create32(up_native, up); + err = put_v4l2_create32(new_p64, p32); break; case VIDIOC_PREPARE_BUF: case VIDIOC_QUERYBUF: case VIDIOC_QBUF: case VIDIOC_DQBUF: - err = put_v4l2_buffer32(up_native, up); + err = put_v4l2_buffer32(new_p64, p32); break; case VIDIOC_ENUMSTD: - err = put_v4l2_standard32(up_native, up); + err = put_v4l2_standard32(new_p64, p32); break; case VIDIOC_ENUMINPUT: - err = put_v4l2_input32(up_native, up); + err = put_v4l2_input32(new_p64, p32); break; } return err; } +/** + * v4l2_compat_ioctl32() - Handles a compat32 ioctl call + * + * @file: pointer to &struct file with the file handler + * @cmd: ioctl to be called + * @arg: arguments passed from/to the ioctl handler + * + * This function is meant to be used as .compat_ioctl fops at v4l2-dev.c + * in order to deal with 32-bit calls on a 64-bits Kernel. + * + * This function calls do_video_ioctl() for non-private V4L2 ioctls. + * If the function is a private one it calls vdev->fops->compat_ioctl32 + * instead. + */ long v4l2_compat_ioctl32(struct file *file, unsigned int cmd, unsigned long arg) { struct video_device *vdev = video_devdata(file); diff --git a/drivers/media/v4l2-core/v4l2-dev.c b/drivers/media/v4l2-core/v4l2-dev.c index c080dcc75393..c4f4357e9ca4 100644 --- a/drivers/media/v4l2-core/v4l2-dev.c +++ b/drivers/media/v4l2-core/v4l2-dev.c @@ -16,6 +16,8 @@ * - Added procfs support */ +#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt + #include <linux/module.h> #include <linux/types.h> #include <linux/kernel.h> @@ -34,6 +36,12 @@ #define VIDEO_NUM_DEVICES 256 #define VIDEO_NAME "video4linux" +#define dprintk(fmt, arg...) do { \ + printk(KERN_DEBUG pr_fmt("%s: " fmt), \ + __func__, ##arg); \ +} while (0) + + /* * sysfs stuff */ @@ -91,7 +99,7 @@ ATTRIBUTE_GROUPS(video_device); /* * Active devices */ -static struct video_device *video_device[VIDEO_NUM_DEVICES]; +static struct video_device *video_devices[VIDEO_NUM_DEVICES]; static DEFINE_MUTEX(videodev_lock); static DECLARE_BITMAP(devnode_nums[VFL_TYPE_MAX], VIDEO_NUM_DEVICES); @@ -173,14 +181,14 @@ static void v4l2_device_release(struct device *cd) struct v4l2_device *v4l2_dev = vdev->v4l2_dev; mutex_lock(&videodev_lock); - if (WARN_ON(video_device[vdev->minor] != vdev)) { + if (WARN_ON(video_devices[vdev->minor] != vdev)) { /* should not happen */ mutex_unlock(&videodev_lock); return; } /* Free up this device for reuse */ - video_device[vdev->minor] = NULL; + video_devices[vdev->minor] = NULL; /* Delete the cdev on this minor as well */ cdev_del(vdev->cdev); @@ -229,7 +237,7 @@ static struct class video_class = { struct video_device *video_devdata(struct file *file) { - return video_device[iminor(file_inode(file))]; + return video_devices[iminor(file_inode(file))]; } EXPORT_SYMBOL(video_devdata); @@ -309,7 +317,7 @@ static ssize_t v4l2_read(struct file *filp, char __user *buf, ret = vdev->fops->read(filp, buf, sz, off); if ((vdev->dev_debug & V4L2_DEV_DEBUG_FOP) && (vdev->dev_debug & V4L2_DEV_DEBUG_STREAMING)) - printk(KERN_DEBUG "%s: read: %zd (%d)\n", + dprintk("%s: read: %zd (%d)\n", video_device_node_name(vdev), sz, ret); return ret; } @@ -326,7 +334,7 @@ static ssize_t v4l2_write(struct file *filp, const char __user *buf, ret = vdev->fops->write(filp, buf, sz, off); if ((vdev->dev_debug & V4L2_DEV_DEBUG_FOP) && (vdev->dev_debug & V4L2_DEV_DEBUG_STREAMING)) - printk(KERN_DEBUG "%s: write: %zd (%d)\n", + dprintk("%s: write: %zd (%d)\n", video_device_node_name(vdev), sz, ret); return ret; } @@ -341,7 +349,7 @@ static __poll_t v4l2_poll(struct file *filp, struct poll_table_struct *poll) if (video_is_registered(vdev)) res = vdev->fops->poll(filp, poll); if (vdev->dev_debug & V4L2_DEV_DEBUG_POLL) - printk(KERN_DEBUG "%s: poll: %08x\n", + dprintk("%s: poll: %08x\n", video_device_node_name(vdev), res); return res; } @@ -382,7 +390,7 @@ static unsigned long v4l2_get_unmapped_area(struct file *filp, return -ENODEV; ret = vdev->fops->get_unmapped_area(filp, addr, len, pgoff, flags); if (vdev->dev_debug & V4L2_DEV_DEBUG_FOP) - printk(KERN_DEBUG "%s: get_unmapped_area (%d)\n", + dprintk("%s: get_unmapped_area (%d)\n", video_device_node_name(vdev), ret); return ret; } @@ -398,7 +406,7 @@ static int v4l2_mmap(struct file *filp, struct vm_area_struct *vm) if (video_is_registered(vdev)) ret = vdev->fops->mmap(filp, vm); if (vdev->dev_debug & V4L2_DEV_DEBUG_FOP) - printk(KERN_DEBUG "%s: mmap (%d)\n", + dprintk("%s: mmap (%d)\n", video_device_node_name(vdev), ret); return ret; } @@ -428,7 +436,7 @@ static int v4l2_open(struct inode *inode, struct file *filp) } if (vdev->dev_debug & V4L2_DEV_DEBUG_FOP) - printk(KERN_DEBUG "%s: open (%d)\n", + dprintk("%s: open (%d)\n", video_device_node_name(vdev), ret); /* decrease the refcount in case of an error */ if (ret) @@ -445,7 +453,7 @@ static int v4l2_release(struct inode *inode, struct file *filp) if (vdev->fops->release) ret = vdev->fops->release(filp); if (vdev->dev_debug & V4L2_DEV_DEBUG_FOP) - printk(KERN_DEBUG "%s: release\n", + dprintk("%s: release\n", video_device_node_name(vdev)); /* decrease the refcount unconditionally since the release() @@ -493,9 +501,9 @@ static int get_index(struct video_device *vdev) bitmap_zero(used, VIDEO_NUM_DEVICES); for (i = 0; i < VIDEO_NUM_DEVICES; i++) { - if (video_device[i] != NULL && - video_device[i]->v4l2_dev == vdev->v4l2_dev) { - set_bit(video_device[i]->index, used); + if (video_devices[i] != NULL && + video_devices[i]->v4l2_dev == vdev->v4l2_dev) { + set_bit(video_devices[i]->index, used); } } @@ -786,8 +794,7 @@ static int video_register_media_controller(struct video_device *vdev, int type) ret = media_device_register_entity(vdev->v4l2_dev->mdev, &vdev->entity); if (ret < 0) { - printk(KERN_WARNING - "%s: media_device_register_entity failed\n", + pr_warn("%s: media_device_register_entity failed\n", __func__); return ret; } @@ -869,7 +876,7 @@ int __video_register_device(struct video_device *vdev, name_base = "v4l-touch"; break; default: - printk(KERN_ERR "%s called with unknown type: %d\n", + pr_err("%s called with unknown type: %d\n", __func__, type); return -EINVAL; } @@ -918,7 +925,7 @@ int __video_register_device(struct video_device *vdev, if (nr == minor_cnt) nr = devnode_find(vdev, 0, minor_cnt); if (nr == minor_cnt) { - printk(KERN_ERR "could not get a free device node number\n"); + pr_err("could not get a free device node number\n"); mutex_unlock(&videodev_lock); return -ENFILE; } @@ -929,11 +936,11 @@ int __video_register_device(struct video_device *vdev, /* The device node number and minor numbers are independent, so we just find the first free minor number. */ for (i = 0; i < VIDEO_NUM_DEVICES; i++) - if (video_device[i] == NULL) + if (video_devices[i] == NULL) break; if (i == VIDEO_NUM_DEVICES) { mutex_unlock(&videodev_lock); - printk(KERN_ERR "could not get a free minor\n"); + pr_err("could not get a free minor\n"); return -ENFILE; } #endif @@ -941,14 +948,14 @@ int __video_register_device(struct video_device *vdev, vdev->num = nr; /* Should not happen since we thought this minor was free */ - if (WARN_ON(video_device[vdev->minor])) { + if (WARN_ON(video_devices[vdev->minor])) { mutex_unlock(&videodev_lock); - printk(KERN_ERR "video_device not empty!\n"); + pr_err("video_device not empty!\n"); return -ENFILE; } devnode_set(vdev); vdev->index = get_index(vdev); - video_device[vdev->minor] = vdev; + video_devices[vdev->minor] = vdev; mutex_unlock(&videodev_lock); if (vdev->ioctl_ops) @@ -964,7 +971,7 @@ int __video_register_device(struct video_device *vdev, vdev->cdev->owner = owner; ret = cdev_add(vdev->cdev, MKDEV(VIDEO_MAJOR, vdev->minor), 1); if (ret < 0) { - printk(KERN_ERR "%s: cdev_add failed\n", __func__); + pr_err("%s: cdev_add failed\n", __func__); kfree(vdev->cdev); vdev->cdev = NULL; goto cleanup; @@ -977,7 +984,7 @@ int __video_register_device(struct video_device *vdev, dev_set_name(&vdev->dev, "%s%d", name_base, vdev->num); ret = device_register(&vdev->dev); if (ret < 0) { - printk(KERN_ERR "%s: device_register failed\n", __func__); + pr_err("%s: device_register failed\n", __func__); goto cleanup; } /* Register the release callback that will be called when the last @@ -985,7 +992,7 @@ int __video_register_device(struct video_device *vdev, vdev->dev.release = v4l2_device_release; if (nr != -1 && nr != vdev->num && warn_if_nr_in_use) - printk(KERN_WARNING "%s: requested %s%d, got %s\n", __func__, + pr_warn("%s: requested %s%d, got %s\n", __func__, name_base, nr, video_device_node_name(vdev)); /* Increase v4l2_device refcount */ @@ -1003,7 +1010,7 @@ cleanup: mutex_lock(&videodev_lock); if (vdev->cdev) cdev_del(vdev->cdev); - video_device[vdev->minor] = NULL; + video_devices[vdev->minor] = NULL; devnode_clear(vdev); mutex_unlock(&videodev_lock); /* Mark this video device as never having been registered. */ @@ -1043,10 +1050,10 @@ static int __init videodev_init(void) dev_t dev = MKDEV(VIDEO_MAJOR, 0); int ret; - printk(KERN_INFO "Linux video capture interface: v2.00\n"); + pr_info("Linux video capture interface: v2.00\n"); ret = register_chrdev_region(dev, VIDEO_NUM_DEVICES, VIDEO_NAME); if (ret < 0) { - printk(KERN_WARNING "videodev: unable to get major %d\n", + pr_warn("videodev: unable to get major %d\n", VIDEO_MAJOR); return ret; } @@ -1054,7 +1061,7 @@ static int __init videodev_init(void) ret = class_register(&video_class); if (ret < 0) { unregister_chrdev_region(dev, VIDEO_NUM_DEVICES); - printk(KERN_WARNING "video_dev: class_register failed\n"); + pr_warn("video_dev: class_register failed\n"); return -EIO; } diff --git a/drivers/media/v4l2-core/v4l2-fwnode.c b/drivers/media/v4l2-core/v4l2-fwnode.c index d630640642ee..3f77aa318035 100644 --- a/drivers/media/v4l2-core/v4l2-fwnode.c +++ b/drivers/media/v4l2-core/v4l2-fwnode.c @@ -819,17 +819,25 @@ static int v4l2_fwnode_reference_parse_int_props( unsigned int index; int ret; - for (index = 0; !IS_ERR((fwnode = v4l2_fwnode_reference_get_int_prop( - dev_fwnode(dev), prop, index, props, - nprops))); index++) + index = 0; + do { + fwnode = v4l2_fwnode_reference_get_int_prop(dev_fwnode(dev), + prop, index, + props, nprops); + if (IS_ERR(fwnode)) { + /* + * Note that right now both -ENODATA and -ENOENT may + * signal out-of-bounds access. Return the error in + * cases other than that. + */ + if (PTR_ERR(fwnode) != -ENOENT && + PTR_ERR(fwnode) != -ENODATA) + return PTR_ERR(fwnode); + break; + } fwnode_handle_put(fwnode); - - /* - * Note that right now both -ENODATA and -ENOENT may signal - * out-of-bounds access. Return the error in cases other than that. - */ - if (PTR_ERR(fwnode) != -ENOENT && PTR_ERR(fwnode) != -ENODATA) - return PTR_ERR(fwnode); + index++; + } while (1); ret = v4l2_async_notifier_realloc(notifier, notifier->num_subdevs + index); diff --git a/drivers/media/v4l2-core/videobuf-dma-sg.c b/drivers/media/v4l2-core/videobuf-dma-sg.c index 7770034aae28..2e5c346f9c30 100644 --- a/drivers/media/v4l2-core/videobuf-dma-sg.c +++ b/drivers/media/v4l2-core/videobuf-dma-sg.c @@ -334,7 +334,7 @@ int videobuf_dma_unmap(struct device *dev, struct videobuf_dmabuf *dma) if (!dma->sglen) return 0; - dma_unmap_sg(dev, dma->sglist, dma->sglen, dma->direction); + dma_unmap_sg(dev, dma->sglist, dma->nr_pages, dma->direction); vfree(dma->sglist); dma->sglist = NULL; @@ -434,7 +434,7 @@ static void videobuf_vm_close(struct vm_area_struct *vma) * now ...). Bounce buffers don't work very well for the data rates * video capture has. */ -static int videobuf_vm_fault(struct vm_fault *vmf) +static vm_fault_t videobuf_vm_fault(struct vm_fault *vmf) { struct vm_area_struct *vma = vmf->vma; struct page *page; @@ -581,7 +581,7 @@ static int __videobuf_sync(struct videobuf_queue *q, MAGIC_CHECK(mem->dma.magic, MAGIC_DMABUF); dma_sync_sg_for_cpu(q->dev, mem->dma.sglist, - mem->dma.sglen, mem->dma.direction); + mem->dma.nr_pages, mem->dma.direction); return 0; } diff --git a/drivers/media/v4l2-core/videobuf-dvb.c b/drivers/media/v4l2-core/videobuf-dvb.c deleted file mode 100644 index b7efa4516d36..000000000000 --- a/drivers/media/v4l2-core/videobuf-dvb.c +++ /dev/null @@ -1,398 +0,0 @@ -/* - * - * some helper function for simple DVB cards which simply DMA the - * complete transport stream and let the computer sort everything else - * (i.e. we are using the software demux, ...). Also uses the - * video-buf to manage DMA buffers. - * - * (c) 2004 Gerd Knorr <kraxel@bytesex.org> [SUSE Labs] - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - */ - -#include <linux/module.h> -#include <linux/init.h> -#include <linux/device.h> -#include <linux/fs.h> -#include <linux/kthread.h> -#include <linux/file.h> -#include <linux/slab.h> - -#include <linux/freezer.h> - -#include <media/videobuf-core.h> -#include <media/videobuf-dvb.h> - -/* ------------------------------------------------------------------ */ - -MODULE_AUTHOR("Gerd Knorr <kraxel@bytesex.org> [SuSE Labs]"); -MODULE_LICENSE("GPL"); - -static unsigned int debug; -module_param(debug, int, 0644); -MODULE_PARM_DESC(debug,"enable debug messages"); - -#define dprintk(fmt, arg...) if (debug) \ - printk(KERN_DEBUG "%s/dvb: " fmt, dvb->name , ## arg) - -/* ------------------------------------------------------------------ */ - -static int videobuf_dvb_thread(void *data) -{ - struct videobuf_dvb *dvb = data; - struct videobuf_buffer *buf; - unsigned long flags; - void *outp; - - dprintk("dvb thread started\n"); - set_freezable(); - videobuf_read_start(&dvb->dvbq); - - for (;;) { - /* fetch next buffer */ - buf = list_entry(dvb->dvbq.stream.next, - struct videobuf_buffer, stream); - list_del(&buf->stream); - videobuf_waiton(&dvb->dvbq, buf, 0, 1); - - /* no more feeds left or stop_feed() asked us to quit */ - if (0 == dvb->nfeeds) - break; - if (kthread_should_stop()) - break; - try_to_freeze(); - - /* feed buffer data to demux */ - outp = videobuf_queue_to_vaddr(&dvb->dvbq, buf); - - if (buf->state == VIDEOBUF_DONE) - dvb_dmx_swfilter(&dvb->demux, outp, - buf->size); - - /* requeue buffer */ - list_add_tail(&buf->stream,&dvb->dvbq.stream); - spin_lock_irqsave(dvb->dvbq.irqlock,flags); - dvb->dvbq.ops->buf_queue(&dvb->dvbq,buf); - spin_unlock_irqrestore(dvb->dvbq.irqlock,flags); - } - - videobuf_read_stop(&dvb->dvbq); - dprintk("dvb thread stopped\n"); - - /* Hmm, linux becomes *very* unhappy without this ... */ - while (!kthread_should_stop()) { - set_current_state(TASK_INTERRUPTIBLE); - schedule(); - } - return 0; -} - -static int videobuf_dvb_start_feed(struct dvb_demux_feed *feed) -{ - struct dvb_demux *demux = feed->demux; - struct videobuf_dvb *dvb = demux->priv; - int rc; - - if (!demux->dmx.frontend) - return -EINVAL; - - mutex_lock(&dvb->lock); - dvb->nfeeds++; - rc = dvb->nfeeds; - - if (NULL != dvb->thread) - goto out; - dvb->thread = kthread_run(videobuf_dvb_thread, - dvb, "%s dvb", dvb->name); - if (IS_ERR(dvb->thread)) { - rc = PTR_ERR(dvb->thread); - dvb->thread = NULL; - } - -out: - mutex_unlock(&dvb->lock); - return rc; -} - -static int videobuf_dvb_stop_feed(struct dvb_demux_feed *feed) -{ - struct dvb_demux *demux = feed->demux; - struct videobuf_dvb *dvb = demux->priv; - int err = 0; - - mutex_lock(&dvb->lock); - dvb->nfeeds--; - if (0 == dvb->nfeeds && NULL != dvb->thread) { - err = kthread_stop(dvb->thread); - dvb->thread = NULL; - } - mutex_unlock(&dvb->lock); - return err; -} - -static int videobuf_dvb_register_adapter(struct videobuf_dvb_frontends *fe, - struct module *module, - void *adapter_priv, - struct device *device, - char *adapter_name, - short *adapter_nr, - int mfe_shared) -{ - int result; - - mutex_init(&fe->lock); - - /* register adapter */ - result = dvb_register_adapter(&fe->adapter, adapter_name, module, - device, adapter_nr); - if (result < 0) { - printk(KERN_WARNING "%s: dvb_register_adapter failed (errno = %d)\n", - adapter_name, result); - } - fe->adapter.priv = adapter_priv; - fe->adapter.mfe_shared = mfe_shared; - - return result; -} - -static int videobuf_dvb_register_frontend(struct dvb_adapter *adapter, - struct videobuf_dvb *dvb) -{ - int result; - - /* register frontend */ - result = dvb_register_frontend(adapter, dvb->frontend); - if (result < 0) { - printk(KERN_WARNING "%s: dvb_register_frontend failed (errno = %d)\n", - dvb->name, result); - goto fail_frontend; - } - - /* register demux stuff */ - dvb->demux.dmx.capabilities = - DMX_TS_FILTERING | DMX_SECTION_FILTERING | - DMX_MEMORY_BASED_FILTERING; - dvb->demux.priv = dvb; - dvb->demux.filternum = 256; - dvb->demux.feednum = 256; - dvb->demux.start_feed = videobuf_dvb_start_feed; - dvb->demux.stop_feed = videobuf_dvb_stop_feed; - result = dvb_dmx_init(&dvb->demux); - if (result < 0) { - printk(KERN_WARNING "%s: dvb_dmx_init failed (errno = %d)\n", - dvb->name, result); - goto fail_dmx; - } - - dvb->dmxdev.filternum = 256; - dvb->dmxdev.demux = &dvb->demux.dmx; - dvb->dmxdev.capabilities = 0; - result = dvb_dmxdev_init(&dvb->dmxdev, adapter); - - if (result < 0) { - printk(KERN_WARNING "%s: dvb_dmxdev_init failed (errno = %d)\n", - dvb->name, result); - goto fail_dmxdev; - } - - dvb->fe_hw.source = DMX_FRONTEND_0; - result = dvb->demux.dmx.add_frontend(&dvb->demux.dmx, &dvb->fe_hw); - if (result < 0) { - printk(KERN_WARNING "%s: add_frontend failed (DMX_FRONTEND_0, errno = %d)\n", - dvb->name, result); - goto fail_fe_hw; - } - - dvb->fe_mem.source = DMX_MEMORY_FE; - result = dvb->demux.dmx.add_frontend(&dvb->demux.dmx, &dvb->fe_mem); - if (result < 0) { - printk(KERN_WARNING "%s: add_frontend failed (DMX_MEMORY_FE, errno = %d)\n", - dvb->name, result); - goto fail_fe_mem; - } - - result = dvb->demux.dmx.connect_frontend(&dvb->demux.dmx, &dvb->fe_hw); - if (result < 0) { - printk(KERN_WARNING "%s: connect_frontend failed (errno = %d)\n", - dvb->name, result); - goto fail_fe_conn; - } - - /* register network adapter */ - result = dvb_net_init(adapter, &dvb->net, &dvb->demux.dmx); - if (result < 0) { - printk(KERN_WARNING "%s: dvb_net_init failed (errno = %d)\n", - dvb->name, result); - goto fail_fe_conn; - } - return 0; - -fail_fe_conn: - dvb->demux.dmx.remove_frontend(&dvb->demux.dmx, &dvb->fe_mem); -fail_fe_mem: - dvb->demux.dmx.remove_frontend(&dvb->demux.dmx, &dvb->fe_hw); -fail_fe_hw: - dvb_dmxdev_release(&dvb->dmxdev); -fail_dmxdev: - dvb_dmx_release(&dvb->demux); -fail_dmx: - dvb_unregister_frontend(dvb->frontend); -fail_frontend: - dvb_frontend_detach(dvb->frontend); - dvb->frontend = NULL; - - return result; -} - -/* ------------------------------------------------------------------ */ -/* Register a single adapter and one or more frontends */ -int videobuf_dvb_register_bus(struct videobuf_dvb_frontends *f, - struct module *module, - void *adapter_priv, - struct device *device, - short *adapter_nr, - int mfe_shared) -{ - struct list_head *list, *q; - struct videobuf_dvb_frontend *fe; - int res; - - fe = videobuf_dvb_get_frontend(f, 1); - if (!fe) { - printk(KERN_WARNING "Unable to register the adapter which has no frontends\n"); - return -EINVAL; - } - - /* Bring up the adapter */ - res = videobuf_dvb_register_adapter(f, module, adapter_priv, device, - fe->dvb.name, adapter_nr, mfe_shared); - if (res < 0) { - printk(KERN_WARNING "videobuf_dvb_register_adapter failed (errno = %d)\n", res); - return res; - } - - /* Attach all of the frontends to the adapter */ - mutex_lock(&f->lock); - list_for_each_safe(list, q, &f->felist) { - fe = list_entry(list, struct videobuf_dvb_frontend, felist); - res = videobuf_dvb_register_frontend(&f->adapter, &fe->dvb); - if (res < 0) { - printk(KERN_WARNING "%s: videobuf_dvb_register_frontend failed (errno = %d)\n", - fe->dvb.name, res); - goto err; - } - } - mutex_unlock(&f->lock); - return 0; - -err: - mutex_unlock(&f->lock); - videobuf_dvb_unregister_bus(f); - return res; -} -EXPORT_SYMBOL(videobuf_dvb_register_bus); - -void videobuf_dvb_unregister_bus(struct videobuf_dvb_frontends *f) -{ - videobuf_dvb_dealloc_frontends(f); - - dvb_unregister_adapter(&f->adapter); -} -EXPORT_SYMBOL(videobuf_dvb_unregister_bus); - -struct videobuf_dvb_frontend *videobuf_dvb_get_frontend( - struct videobuf_dvb_frontends *f, int id) -{ - struct list_head *list, *q; - struct videobuf_dvb_frontend *fe, *ret = NULL; - - mutex_lock(&f->lock); - - list_for_each_safe(list, q, &f->felist) { - fe = list_entry(list, struct videobuf_dvb_frontend, felist); - if (fe->id == id) { - ret = fe; - break; - } - } - - mutex_unlock(&f->lock); - - return ret; -} -EXPORT_SYMBOL(videobuf_dvb_get_frontend); - -int videobuf_dvb_find_frontend(struct videobuf_dvb_frontends *f, - struct dvb_frontend *p) -{ - struct list_head *list, *q; - struct videobuf_dvb_frontend *fe = NULL; - int ret = 0; - - mutex_lock(&f->lock); - - list_for_each_safe(list, q, &f->felist) { - fe = list_entry(list, struct videobuf_dvb_frontend, felist); - if (fe->dvb.frontend == p) { - ret = fe->id; - break; - } - } - - mutex_unlock(&f->lock); - - return ret; -} -EXPORT_SYMBOL(videobuf_dvb_find_frontend); - -struct videobuf_dvb_frontend *videobuf_dvb_alloc_frontend( - struct videobuf_dvb_frontends *f, int id) -{ - struct videobuf_dvb_frontend *fe; - - fe = kzalloc(sizeof(struct videobuf_dvb_frontend), GFP_KERNEL); - if (fe == NULL) - goto fail_alloc; - - fe->id = id; - mutex_init(&fe->dvb.lock); - - mutex_lock(&f->lock); - list_add_tail(&fe->felist, &f->felist); - mutex_unlock(&f->lock); - -fail_alloc: - return fe; -} -EXPORT_SYMBOL(videobuf_dvb_alloc_frontend); - -void videobuf_dvb_dealloc_frontends(struct videobuf_dvb_frontends *f) -{ - struct list_head *list, *q; - struct videobuf_dvb_frontend *fe; - - mutex_lock(&f->lock); - list_for_each_safe(list, q, &f->felist) { - fe = list_entry(list, struct videobuf_dvb_frontend, felist); - if (fe->dvb.net.dvbdev) { - dvb_net_release(&fe->dvb.net); - fe->dvb.demux.dmx.remove_frontend(&fe->dvb.demux.dmx, - &fe->dvb.fe_mem); - fe->dvb.demux.dmx.remove_frontend(&fe->dvb.demux.dmx, - &fe->dvb.fe_hw); - dvb_dmxdev_release(&fe->dvb.dmxdev); - dvb_dmx_release(&fe->dvb.demux); - dvb_unregister_frontend(fe->dvb.frontend); - } - if (fe->dvb.frontend) - /* always allocated, may have been reset */ - dvb_frontend_detach(fe->dvb.frontend); - list_del(list); /* remove list entry */ - kfree(fe); /* free frontend allocation */ - } - mutex_unlock(&f->lock); -} -EXPORT_SYMBOL(videobuf_dvb_dealloc_frontends); diff --git a/drivers/pnp/isapnp/Kconfig b/drivers/pnp/isapnp/Kconfig index f1ef36673ad4..a1af146d2d90 100644 --- a/drivers/pnp/isapnp/Kconfig +++ b/drivers/pnp/isapnp/Kconfig @@ -3,7 +3,7 @@ # config ISAPNP bool "ISA Plug and Play support" - depends on ISA + depends on ISA || COMPILE_TEST help Say Y here if you would like support for ISA Plug and Play devices. Some information is in <file:Documentation/isapnp.txt>. diff --git a/drivers/staging/media/atomisp/pci/atomisp2/atomisp_acc.c b/drivers/staging/media/atomisp/pci/atomisp2/atomisp_acc.c index a6638edee360..7ebcebd80b77 100644 --- a/drivers/staging/media/atomisp/pci/atomisp2/atomisp_acc.c +++ b/drivers/staging/media/atomisp/pci/atomisp2/atomisp_acc.c @@ -353,10 +353,10 @@ int atomisp_acc_map(struct atomisp_sub_device *asd, struct atomisp_acc_map *map) } pgnr = DIV_ROUND_UP(map->length, PAGE_SIZE); - cssptr = hrt_isp_css_mm_alloc_user_ptr( - map->length, map->user_ptr, - pgnr, HRT_USR_PTR, - (map->flags & ATOMISP_MAP_FLAG_CACHED)); + cssptr = hrt_isp_css_mm_alloc_user_ptr(map->length, + map->user_ptr, + pgnr, HRT_USR_PTR, + (map->flags & ATOMISP_MAP_FLAG_CACHED)); } else { /* Allocate private buffer. */ if (map->flags & ATOMISP_MAP_FLAG_CACHED) diff --git a/drivers/staging/media/atomisp/pci/atomisp2/atomisp_cmd.c b/drivers/staging/media/atomisp/pci/atomisp2/atomisp_cmd.c index fa6ea506f8b1..874165654850 100644 --- a/drivers/staging/media/atomisp/pci/atomisp2/atomisp_cmd.c +++ b/drivers/staging/media/atomisp/pci/atomisp2/atomisp_cmd.c @@ -3299,7 +3299,7 @@ static unsigned int long copy_from_compatible(void *to, const void *from, unsigned long n, bool from_user) { if (from_user) - return copy_from_user(to, from, n); + return copy_from_user(to, (void __user *)from, n); else memcpy(to, from, n); return 0; @@ -4067,7 +4067,7 @@ int atomisp_cp_morph_table(struct atomisp_sub_device *asd, for (i = 0; i < CSS_MORPH_TABLE_NUM_PLANES; i++) { if (copy_from_compatible(morph_table->coordinates_x[i], - source_morph_table->coordinates_x[i], + (__force void *)source_morph_table->coordinates_x[i], #ifndef ISP2401 source_morph_table->height * source_morph_table->width * sizeof(*source_morph_table->coordinates_x[i]), @@ -4079,7 +4079,7 @@ int atomisp_cp_morph_table(struct atomisp_sub_device *asd, goto error; if (copy_from_compatible(morph_table->coordinates_y[i], - source_morph_table->coordinates_y[i], + (__force void *)source_morph_table->coordinates_y[i], #ifndef ISP2401 source_morph_table->height * source_morph_table->width * sizeof(*source_morph_table->coordinates_y[i]), @@ -6176,7 +6176,8 @@ int atomisp_set_shading_table(struct atomisp_sub_device *asd, ATOMISP_SC_TYPE_SIZE; for (i = 0; i < ATOMISP_NUM_SC_COLORS; i++) { ret = copy_from_user(shading_table->data[i], - user_shading_table->data[i], len_table); + (void __user *)user_shading_table->data[i], + len_table); if (ret) { free_table = shading_table; ret = -EFAULT; diff --git a/drivers/staging/media/atomisp/pci/atomisp2/atomisp_compat.h b/drivers/staging/media/atomisp/pci/atomisp2/atomisp_compat.h index 6c829d0a1e4c..aac0eccee798 100644 --- a/drivers/staging/media/atomisp/pci/atomisp2/atomisp_compat.h +++ b/drivers/staging/media/atomisp/pci/atomisp2/atomisp_compat.h @@ -353,7 +353,7 @@ void atomisp_css_frame_free(struct atomisp_css_frame *frame); int atomisp_css_frame_map(struct atomisp_css_frame **frame, const struct atomisp_css_frame_info *info, - const void *data, uint16_t attribute, + const void __user *data, uint16_t attribute, void *context); int atomisp_css_set_black_frame(struct atomisp_sub_device *asd, diff --git a/drivers/staging/media/atomisp/pci/atomisp2/atomisp_compat_css20.c b/drivers/staging/media/atomisp/pci/atomisp2/atomisp_compat_css20.c index f668c68dc33a..df88d9df2027 100644 --- a/drivers/staging/media/atomisp/pci/atomisp2/atomisp_compat_css20.c +++ b/drivers/staging/media/atomisp/pci/atomisp2/atomisp_compat_css20.c @@ -2189,7 +2189,7 @@ void atomisp_css_frame_free(struct atomisp_css_frame *frame) int atomisp_css_frame_map(struct atomisp_css_frame **frame, const struct atomisp_css_frame_info *info, - const void *data, uint16_t attribute, + const void __user *data, uint16_t attribute, void *context) { if (ia_css_frame_map(frame, info, data, attribute, context) diff --git a/drivers/staging/media/atomisp/pci/atomisp2/atomisp_compat_ioctl32.c b/drivers/staging/media/atomisp/pci/atomisp2/atomisp_compat_ioctl32.c index 44c21813a06e..b86ab107a9e5 100644 --- a/drivers/staging/media/atomisp/pci/atomisp2/atomisp_compat_ioctl32.c +++ b/drivers/staging/media/atomisp/pci/atomisp2/atomisp_compat_ioctl32.c @@ -21,6 +21,7 @@ #include "atomisp_internal.h" #include "atomisp_compat.h" +#include "atomisp_ioctl.h" #include "atomisp_compat_ioctl32.h" static int get_atomisp_histogram32(struct atomisp_histogram *kp, @@ -77,7 +78,7 @@ static int get_v4l2_framebuffer32(struct v4l2_framebuffer *kp, get_user(kp->flags, &up->flags)) return -EFAULT; - kp->base = compat_ptr(tmp); + kp->base = (void __force *)compat_ptr(tmp); get_v4l2_pix_format((struct v4l2_pix_format *)&kp->fmt, &up->fmt); return 0; } @@ -228,10 +229,10 @@ static int get_atomisp_dvs_6axis_config32(struct atomisp_dvs_6axis_config *kp, get_user(ycoords_uv, &up->ycoords_uv)) return -EFAULT; - kp->xcoords_y = compat_ptr(xcoords_y); - kp->ycoords_y = compat_ptr(ycoords_y); - kp->xcoords_uv = compat_ptr(xcoords_uv); - kp->ycoords_uv = compat_ptr(ycoords_uv); + kp->xcoords_y = (void __force *)compat_ptr(xcoords_y); + kp->ycoords_y = (void __force *)compat_ptr(ycoords_y); + kp->xcoords_uv = (void __force *)compat_ptr(xcoords_uv); + kp->ycoords_uv = (void __force *)compat_ptr(ycoords_uv); return 0; } @@ -292,7 +293,7 @@ static int get_atomisp_metadata_stat32(struct atomisp_metadata *kp, return -EFAULT; kp->data = compat_ptr(data); - kp->effective_width = compat_ptr(effective_width); + kp->effective_width = (void __force *)compat_ptr(effective_width); return 0; } @@ -356,7 +357,7 @@ static int get_atomisp_metadata_by_type_stat32( return -EFAULT; kp->data = compat_ptr(data); - kp->effective_width = compat_ptr(effective_width); + kp->effective_width = (void __force *)compat_ptr(effective_width); return 0; } @@ -433,7 +434,7 @@ static int get_atomisp_overlay32(struct atomisp_overlay *kp, get_user(kp->overlay_start_x, &up->overlay_start_y)) return -EFAULT; - kp->frame = compat_ptr(frame); + kp->frame = (void __force *)compat_ptr(frame); return 0; } @@ -477,7 +478,7 @@ static int get_atomisp_calibration_group32( get_user(calb_grp_values, &up->calb_grp_values)) return -EFAULT; - kp->calb_grp_values = compat_ptr(calb_grp_values); + kp->calb_grp_values = (void __force *)compat_ptr(calb_grp_values); return 0; } @@ -691,31 +692,25 @@ static int get_atomisp_parameters32(struct atomisp_parameters *kp, sizeof(compat_uptr_t); unsigned int size, offset = 0; void __user *user_ptr; -#ifdef ISP2401 unsigned int stp, mtp, dcp, dscp = 0; -#endif if (!access_ok(VERIFY_READ, up, sizeof(struct atomisp_parameters32))) return -EFAULT; while (n >= 0) { - compat_uptr_t *src = (compat_uptr_t *)up + n; - uintptr_t *dst = (uintptr_t *)kp + n; + compat_uptr_t __user *src = ((compat_uptr_t __user *)up) + n; + uintptr_t *dst = ((uintptr_t *)kp) + n; if (get_user((*dst), src)) return -EFAULT; n--; } if (get_user(kp->isp_config_id, &up->isp_config_id) || -#ifndef ISP2401 - get_user(kp->per_frame_setting, &up->per_frame_setting)) -#else get_user(kp->per_frame_setting, &up->per_frame_setting) || get_user(stp, &up->shading_table) || get_user(mtp, &up->morph_table) || get_user(dcp, &up->dvs2_coefs) || get_user(dscp, &up->dvs_6axis_config)) -#endif return -EFAULT; { @@ -733,102 +728,73 @@ static int get_atomisp_parameters32(struct atomisp_parameters *kp, user_ptr = compat_alloc_user_space(size); /* handle shading table */ -#ifndef ISP2401 - if (up->shading_table != 0) { -#else if (stp != 0) { -#endif if (get_atomisp_shading_table32(&karg.shading_table, (struct atomisp_shading_table32 __user *) -#ifndef ISP2401 - (uintptr_t)up->shading_table)) -#else (uintptr_t)stp)) -#endif return -EFAULT; - kp->shading_table = user_ptr + offset; + kp->shading_table = (void __force *)user_ptr + offset; offset = sizeof(struct atomisp_shading_table); if (!kp->shading_table) return -EFAULT; - if (copy_to_user(kp->shading_table, + if (copy_to_user((void __user *)kp->shading_table, &karg.shading_table, sizeof(struct atomisp_shading_table))) return -EFAULT; } /* handle morph table */ -#ifndef ISP2401 - if (up->morph_table != 0) { -#else if (mtp != 0) { -#endif if (get_atomisp_morph_table32(&karg.morph_table, (struct atomisp_morph_table32 __user *) -#ifndef ISP2401 - (uintptr_t)up->morph_table)) -#else (uintptr_t)mtp)) -#endif return -EFAULT; - kp->morph_table = user_ptr + offset; + kp->morph_table = (void __force *)user_ptr + offset; offset += sizeof(struct atomisp_morph_table); if (!kp->morph_table) return -EFAULT; - if (copy_to_user(kp->morph_table, &karg.morph_table, - sizeof(struct atomisp_morph_table))) + if (copy_to_user((void __user *)kp->morph_table, + &karg.morph_table, + sizeof(struct atomisp_morph_table))) return -EFAULT; } /* handle dvs2 coefficients */ -#ifndef ISP2401 - if (up->dvs2_coefs != 0) { -#else if (dcp != 0) { -#endif if (get_atomisp_dis_coefficients32(&karg.dvs2_coefs, (struct atomisp_dis_coefficients32 __user *) -#ifndef ISP2401 - (uintptr_t)up->dvs2_coefs)) -#else (uintptr_t)dcp)) -#endif return -EFAULT; - kp->dvs2_coefs = user_ptr + offset; + kp->dvs2_coefs = (void __force *)user_ptr + offset; offset += sizeof(struct atomisp_dis_coefficients); if (!kp->dvs2_coefs) return -EFAULT; - if (copy_to_user(kp->dvs2_coefs, &karg.dvs2_coefs, - sizeof(struct atomisp_dis_coefficients))) + if (copy_to_user((void __user *)kp->dvs2_coefs, + &karg.dvs2_coefs, + sizeof(struct atomisp_dis_coefficients))) return -EFAULT; } /* handle dvs 6axis configuration */ -#ifndef ISP2401 - if (up->dvs_6axis_config != 0) { -#else if (dscp != 0) { -#endif if (get_atomisp_dvs_6axis_config32(&karg.dvs_6axis_config, (struct atomisp_dvs_6axis_config32 __user *) -#ifndef ISP2401 - (uintptr_t)up->dvs_6axis_config)) -#else (uintptr_t)dscp)) -#endif return -EFAULT; - kp->dvs_6axis_config = user_ptr + offset; + kp->dvs_6axis_config = (void __force *)user_ptr + offset; offset += sizeof(struct atomisp_dvs_6axis_config); if (!kp->dvs_6axis_config) return -EFAULT; - if (copy_to_user(kp->dvs_6axis_config, &karg.dvs_6axis_config, - sizeof(struct atomisp_dvs_6axis_config))) + if (copy_to_user((void __user *)kp->dvs_6axis_config, + &karg.dvs_6axis_config, + sizeof(struct atomisp_dvs_6axis_config))) return -EFAULT; } } @@ -887,7 +853,7 @@ static int get_atomisp_sensor_ae_bracketing_lut( get_user(lut, &up->lut)) return -EFAULT; - kp->lut = compat_ptr(lut); + kp->lut = (void __force *)compat_ptr(lut); return 0; } @@ -901,8 +867,8 @@ static long native_ioctl(struct file *file, unsigned int cmd, unsigned long arg) return ret; } -long atomisp_do_compat_ioctl(struct file *file, - unsigned int cmd, unsigned long arg) +static long atomisp_do_compat_ioctl(struct file *file, + unsigned int cmd, unsigned long arg) { union { struct atomisp_histogram his; diff --git a/drivers/staging/media/atomisp/pci/atomisp2/atomisp_fops.c b/drivers/staging/media/atomisp/pci/atomisp2/atomisp_fops.c index 709137f25700..693b905547e4 100644 --- a/drivers/staging/media/atomisp/pci/atomisp2/atomisp_fops.c +++ b/drivers/staging/media/atomisp/pci/atomisp2/atomisp_fops.c @@ -773,8 +773,7 @@ static int atomisp_open(struct file *file) rt_mutex_lock(&isp->mutex); - acc_node = !strncmp(vdev->name, "ATOMISP ISP ACC", - sizeof(vdev->name)); + acc_node = !strcmp(vdev->name, "ATOMISP ISP ACC"); if (acc_node) { acc_pipe = atomisp_to_acc_pipe(vdev); asd = acc_pipe->asd; @@ -910,8 +909,7 @@ static int atomisp_release(struct file *file) rt_mutex_lock(&isp->mutex); dev_dbg(isp->dev, "release device %s\n", vdev->name); - acc_node = !strncmp(vdev->name, "ATOMISP ISP ACC", - sizeof(vdev->name)); + acc_node = !strcmp(vdev->name, "ATOMISP ISP ACC"); if (acc_node) { acc_pipe = atomisp_to_acc_pipe(vdev); asd = acc_pipe->asd; diff --git a/drivers/staging/media/atomisp/pci/atomisp2/atomisp_ioctl.c b/drivers/staging/media/atomisp/pci/atomisp2/atomisp_ioctl.c index 61bd550dafb9..8c67aea67b6b 100644 --- a/drivers/staging/media/atomisp/pci/atomisp2/atomisp_ioctl.c +++ b/drivers/staging/media/atomisp/pci/atomisp2/atomisp_ioctl.c @@ -1253,7 +1253,7 @@ static int atomisp_qbuf(struct file *file, void *fh, struct v4l2_buffer *buf) attributes.type = HRT_USR_PTR; #endif ret = atomisp_css_frame_map(&handle, &frame_info, - (void *)buf->m.userptr, + (void __user *)buf->m.userptr, 0, &attributes); if (ret) { dev_err(isp->dev, "Failed to map user buffer\n"); @@ -2748,8 +2748,7 @@ static long atomisp_vidioc_default(struct file *file, void *fh, bool acc_node; int err; - acc_node = !strncmp(vdev->name, "ATOMISP ISP ACC", - sizeof(vdev->name)); + acc_node = !strcmp(vdev->name, "ATOMISP ISP ACC"); if (acc_node) asd = atomisp_to_acc_pipe(vdev)->asd; else diff --git a/drivers/staging/media/atomisp/pci/atomisp2/css2400/hive_isp_css_common/host/mmu.c b/drivers/staging/media/atomisp/pci/atomisp2/css2400/hive_isp_css_common/host/mmu.c index a28b67eb66ea..1a1719d3e745 100644 --- a/drivers/staging/media/atomisp/pci/atomisp2/css2400/hive_isp_css_common/host/mmu.c +++ b/drivers/staging/media/atomisp/pci/atomisp2/css2400/hive_isp_css_common/host/mmu.c @@ -15,10 +15,6 @@ /* The name "mmu.h is already taken" */ #include "mmu_device.h" -#ifndef __INLINE_MMU__ -#include "mmu_private.h" -#endif /* __INLINE_MMU__ */ - void mmu_set_page_table_base_index( const mmu_ID_t ID, const hrt_data base_index) diff --git a/drivers/staging/media/atomisp/pci/atomisp2/css2400/hive_isp_css_common/host/mmu_private.h b/drivers/staging/media/atomisp/pci/atomisp2/css2400/hive_isp_css_common/host/mmu_private.h deleted file mode 100644 index 7377666f6eb7..000000000000 --- a/drivers/staging/media/atomisp/pci/atomisp2/css2400/hive_isp_css_common/host/mmu_private.h +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Support for Intel Camera Imaging ISP subsystem. - * Copyright (c) 2010-2015, Intel Corporation. - * - * This program is free software; you can redistribute it and/or modify it - * under the terms and conditions of the GNU General Public License, - * version 2, as published by the Free Software Foundation. - * - * This program is distributed in the hope it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for - * more details. - */ - -#ifndef __MMU_PRIVATE_H_INCLUDED__ -#define __MMU_PRIVATE_H_INCLUDED__ - -#include "mmu_public.h" - -#include "device_access.h" - -#include "assert_support.h" - -STORAGE_CLASS_MMU_H void mmu_reg_store( - const mmu_ID_t ID, - const unsigned int reg, - const hrt_data value) -{ - assert(ID < N_MMU_ID); - assert(MMU_BASE[ID] != (hrt_address)-1); - ia_css_device_store_uint32(MMU_BASE[ID] + reg*sizeof(hrt_data), value); - return; -} - -STORAGE_CLASS_MMU_H hrt_data mmu_reg_load( - const mmu_ID_t ID, - const unsigned int reg) -{ - assert(ID < N_MMU_ID); - assert(MMU_BASE[ID] != (hrt_address)-1); - return ia_css_device_load_uint32(MMU_BASE[ID] + reg*sizeof(hrt_data)); -} - -#endif /* __MMU_PRIVATE_H_INCLUDED__ */ diff --git a/drivers/staging/media/atomisp/pci/atomisp2/css2400/hive_isp_css_include/host/mmu_public.h b/drivers/staging/media/atomisp/pci/atomisp2/css2400/hive_isp_css_include/host/mmu_public.h index 0a13eda73607..bbff4128603b 100644 --- a/drivers/staging/media/atomisp/pci/atomisp2/css2400/hive_isp_css_include/host/mmu_public.h +++ b/drivers/staging/media/atomisp/pci/atomisp2/css2400/hive_isp_css_include/host/mmu_public.h @@ -16,6 +16,8 @@ #define __MMU_PUBLIC_H_INCLUDED__ #include "system_types.h" +#include "device_access.h" +#include "assert_support.h" /*! Set the page table base index of MMU[ID] @@ -62,10 +64,17 @@ extern void mmu_invalidate_cache_all(void); \return none, MMU[ID].ctrl[reg] = value */ -STORAGE_CLASS_MMU_H void mmu_reg_store( +static inline void mmu_reg_store( const mmu_ID_t ID, const unsigned int reg, - const hrt_data value); + const hrt_data value) +{ + assert(ID < N_MMU_ID); + assert(MMU_BASE[ID] != (hrt_address)-1); + ia_css_device_store_uint32(MMU_BASE[ID] + reg*sizeof(hrt_data), value); + return; +} + /*! Read from a control register of MMU[ID] @@ -75,8 +84,13 @@ STORAGE_CLASS_MMU_H void mmu_reg_store( \return MMU[ID].ctrl[reg] */ -STORAGE_CLASS_MMU_H hrt_data mmu_reg_load( +static inline hrt_data mmu_reg_load( const mmu_ID_t ID, - const unsigned int reg); + const unsigned int reg) +{ + assert(ID < N_MMU_ID); + assert(MMU_BASE[ID] != (hrt_address)-1); + return ia_css_device_load_uint32(MMU_BASE[ID] + reg*sizeof(hrt_data)); +} #endif /* __MMU_PUBLIC_H_INCLUDED__ */ diff --git a/drivers/staging/media/atomisp/pci/atomisp2/css2400/hive_isp_css_include/memory_access/memory_access.h b/drivers/staging/media/atomisp/pci/atomisp2/css2400/hive_isp_css_include/memory_access/memory_access.h index 195c4a5bceeb..d2387812f3a6 100644 --- a/drivers/staging/media/atomisp/pci/atomisp2/css2400/hive_isp_css_include/memory_access/memory_access.h +++ b/drivers/staging/media/atomisp/pci/atomisp2/css2400/hive_isp_css_include/memory_access/memory_access.h @@ -137,7 +137,7 @@ extern hrt_vaddress mmgr_alloc_attr(const size_t size, const uint16_t attribute) \return vaddress */ extern hrt_vaddress mmgr_mmap( - const void *ptr, + const void __user *ptr, const size_t size, uint16_t attribute, void *context); diff --git a/drivers/staging/media/atomisp/pci/atomisp2/css2400/hive_isp_css_include/mmu_device.h b/drivers/staging/media/atomisp/pci/atomisp2/css2400/hive_isp_css_include/mmu_device.h index 519e850ec390..8f6f1dc40095 100644 --- a/drivers/staging/media/atomisp/pci/atomisp2/css2400/hive_isp_css_include/mmu_device.h +++ b/drivers/staging/media/atomisp/pci/atomisp2/css2400/hive_isp_css_include/mmu_device.h @@ -35,14 +35,6 @@ #include "system_local.h" #include "mmu_local.h" -#ifndef __INLINE_MMU__ -#define STORAGE_CLASS_MMU_H extern -#define STORAGE_CLASS_MMU_C #include "mmu_public.h" -#else /* __INLINE_MMU__ */ -#define STORAGE_CLASS_MMU_H static inline -#define STORAGE_CLASS_MMU_C static inline -#include "mmu_private.h" -#endif /* __INLINE_MMU__ */ #endif /* __MMU_DEVICE_H_INCLUDED__ */ diff --git a/drivers/staging/media/atomisp/pci/atomisp2/css2400/ia_css_frame_public.h b/drivers/staging/media/atomisp/pci/atomisp2/css2400/ia_css_frame_public.h index 0beb7347a4f3..89943e8bf180 100644 --- a/drivers/staging/media/atomisp/pci/atomisp2/css2400/ia_css_frame_public.h +++ b/drivers/staging/media/atomisp/pci/atomisp2/css2400/ia_css_frame_public.h @@ -333,7 +333,7 @@ ia_css_frame_set_data(struct ia_css_frame *frame, enum ia_css_err ia_css_frame_map(struct ia_css_frame **frame, const struct ia_css_frame_info *info, - const void *data, + const void __user *data, uint16_t attribute, void *context); diff --git a/drivers/staging/media/atomisp/pci/atomisp2/css2400/ia_css_memory_access.c b/drivers/staging/media/atomisp/pci/atomisp2/css2400/ia_css_memory_access.c index 282075942ba6..8222dd0a41f2 100644 --- a/drivers/staging/media/atomisp/pci/atomisp2/css2400/ia_css_memory_access.c +++ b/drivers/staging/media/atomisp/pci/atomisp2/css2400/ia_css_memory_access.c @@ -72,12 +72,12 @@ mmgr_store(const hrt_vaddress vaddr, const void *data, const size_t size) } hrt_vaddress -mmgr_mmap(const void *ptr, const size_t size, +mmgr_mmap(const void __user *ptr, const size_t size, uint16_t attribute, void *context) { struct hrt_userbuffer_attr *userbuffer_attr = context; return hrt_isp_css_mm_alloc_user_ptr( - size, (void *)ptr, userbuffer_attr->pgnr, + size, ptr, userbuffer_attr->pgnr, userbuffer_attr->type, attribute & HRT_BUF_FLAG_CACHED); } diff --git a/drivers/staging/media/atomisp/pci/atomisp2/css2400/isp/kernels/eed1_8/ia_css_eed1_8.host.c b/drivers/staging/media/atomisp/pci/atomisp2/css2400/isp/kernels/eed1_8/ia_css_eed1_8.host.c index 47bb5042381b..8f2178bf9e68 100644 --- a/drivers/staging/media/atomisp/pci/atomisp2/css2400/isp/kernels/eed1_8/ia_css_eed1_8.host.c +++ b/drivers/staging/media/atomisp/pci/atomisp2/css2400/isp/kernels/eed1_8/ia_css_eed1_8.host.c @@ -160,17 +160,25 @@ ia_css_eed1_8_vmem_encode( base = shuffle_block * i; for (j = 0; j < IA_CSS_NUMBER_OF_DEW_ENHANCE_SEGMENTS; j++) { - to->e_dew_enh_x[0][base + j] = min(max(from->dew_enhance_seg_x[j], 0), 8191); - to->e_dew_enh_y[0][base + j] = min(max(from->dew_enhance_seg_y[j], -8192), 8191); + to->e_dew_enh_x[0][base + j] = min_t(int, max_t(int, + from->dew_enhance_seg_x[j], 0), + 8191); + to->e_dew_enh_y[0][base + j] = min_t(int, max_t(int, + from->dew_enhance_seg_y[j], -8192), + 8191); } for (j = 0; j < (IA_CSS_NUMBER_OF_DEW_ENHANCE_SEGMENTS - 1); j++) { - to->e_dew_enh_a[0][base + j] = min(max(from->dew_enhance_seg_slope[j], -8192), 8191); + to->e_dew_enh_a[0][base + j] = min_t(int, max_t(int, + from->dew_enhance_seg_slope[j], + -8192), 8191); /* Convert dew_enhance_seg_exp to flag: * 0 -> 0 * 1...13 -> 1 */ - to->e_dew_enh_f[0][base + j] = (min(max(from->dew_enhance_seg_exp[j], 0), 13) > 0); + to->e_dew_enh_f[0][base + j] = (min_t(int, max_t(int, + from->dew_enhance_seg_exp[j], + 0), 13) > 0); } /* Hard-coded to 0, in order to be able to handle out of diff --git a/drivers/staging/media/atomisp/pci/atomisp2/css2400/runtime/frame/src/frame.c b/drivers/staging/media/atomisp/pci/atomisp2/css2400/runtime/frame/src/frame.c index 7562beadabef..fd8e6fda5db4 100644 --- a/drivers/staging/media/atomisp/pci/atomisp2/css2400/runtime/frame/src/frame.c +++ b/drivers/staging/media/atomisp/pci/atomisp2/css2400/runtime/frame/src/frame.c @@ -175,7 +175,7 @@ enum ia_css_err ia_css_frame_allocate(struct ia_css_frame **frame, enum ia_css_err ia_css_frame_map(struct ia_css_frame **frame, const struct ia_css_frame_info *info, - const void *data, + const void __user *data, uint16_t attribute, void *context) { diff --git a/drivers/staging/media/atomisp/pci/atomisp2/css2400/sh_css_frac.h b/drivers/staging/media/atomisp/pci/atomisp2/css2400/sh_css_frac.h index 1d1771d71f3c..90a63b3921e6 100644 --- a/drivers/staging/media/atomisp/pci/atomisp2/css2400/sh_css_frac.h +++ b/drivers/staging/media/atomisp/pci/atomisp2/css2400/sh_css_frac.h @@ -30,7 +30,7 @@ /* a:fraction bits for 16bit precision, b:fraction bits for ISP precision */ #define sDIGIT_FITTING(v, a, b) \ - min(max((((v)>>sSHIFT) >> max(sFRACTION_BITS_FITTING(a)-(b), 0)), \ + min_t(int, max_t(int, (((v)>>sSHIFT) >> max(sFRACTION_BITS_FITTING(a)-(b), 0)), \ sISP_VAL_MIN), sISP_VAL_MAX) #define uDIGIT_FITTING(v, a, b) \ min((unsigned)max((unsigned)(((v)>>uSHIFT) \ diff --git a/drivers/staging/media/atomisp/pci/atomisp2/hmm/hmm.c b/drivers/staging/media/atomisp/pci/atomisp2/hmm/hmm.c index 4338b8a1309f..15bc10b5e9b1 100644 --- a/drivers/staging/media/atomisp/pci/atomisp2/hmm/hmm.c +++ b/drivers/staging/media/atomisp/pci/atomisp2/hmm/hmm.c @@ -219,7 +219,7 @@ void hmm_cleanup(void) } ia_css_ptr hmm_alloc(size_t bytes, enum hmm_bo_type type, - int from_highmem, void *userptr, bool cached) + int from_highmem, const void __user *userptr, bool cached) { unsigned int pgnr; struct hmm_buffer_object *bo; diff --git a/drivers/staging/media/atomisp/pci/atomisp2/hmm/hmm_bo.c b/drivers/staging/media/atomisp/pci/atomisp2/hmm/hmm_bo.c index 79bd540d7882..a6620d2c9f50 100644 --- a/drivers/staging/media/atomisp/pci/atomisp2/hmm/hmm_bo.c +++ b/drivers/staging/media/atomisp/pci/atomisp2/hmm/hmm_bo.c @@ -319,7 +319,7 @@ static void __bo_take_off_handling(struct hmm_buffer_object *bo) * to take off this bo, we just set take the "prev/next" pointers * to NULL, the free rbtree stays unchaged */ - } else { + } else if (bo->prev != NULL && bo->next != NULL) { bo->next->prev = bo->prev; bo->prev->next = bo->next; bo->next = NULL; @@ -977,7 +977,7 @@ static int get_pfnmap_pages(struct task_struct *tsk, struct mm_struct *mm, * Convert user space virtual address into pages list */ static int alloc_user_pages(struct hmm_buffer_object *bo, - void *userptr, bool cached) + const void __user *userptr, bool cached) { int page_nr; int i; @@ -1081,7 +1081,7 @@ static void free_user_pages(struct hmm_buffer_object *bo) */ int hmm_bo_alloc_pages(struct hmm_buffer_object *bo, enum hmm_bo_type type, int from_highmem, - void *userptr, bool cached) + const void __user *userptr, bool cached) { int ret = -EINVAL; diff --git a/drivers/staging/media/atomisp/pci/atomisp2/hrt/hive_isp_css_mm_hrt.c b/drivers/staging/media/atomisp/pci/atomisp2/hrt/hive_isp_css_mm_hrt.c index a94958bde718..9b186517f20a 100644 --- a/drivers/staging/media/atomisp/pci/atomisp2/hrt/hive_isp_css_mm_hrt.c +++ b/drivers/staging/media/atomisp/pci/atomisp2/hrt/hive_isp_css_mm_hrt.c @@ -24,11 +24,11 @@ #define __page_align(size) (((size) + (PAGE_SIZE-1)) & (~(PAGE_SIZE-1))) -static void *my_userptr; +static void __user *my_userptr; static unsigned my_num_pages; static enum hrt_userptr_type my_usr_type; -void hrt_isp_css_mm_set_user_ptr(void *userptr, +void hrt_isp_css_mm_set_user_ptr(void __user *userptr, unsigned int num_pages, enum hrt_userptr_type type) { @@ -37,10 +37,11 @@ void hrt_isp_css_mm_set_user_ptr(void *userptr, my_usr_type = type; } -static ia_css_ptr __hrt_isp_css_mm_alloc(size_t bytes, void *userptr, - unsigned int num_pages, - enum hrt_userptr_type type, - bool cached) +static ia_css_ptr __hrt_isp_css_mm_alloc(size_t bytes, + const void __user *userptr, + unsigned int num_pages, + enum hrt_userptr_type type, + bool cached) { #ifdef CONFIG_ION if (type == HRT_USR_ION) @@ -78,10 +79,11 @@ ia_css_ptr hrt_isp_css_mm_alloc(size_t bytes) my_num_pages, my_usr_type, false); } -ia_css_ptr hrt_isp_css_mm_alloc_user_ptr(size_t bytes, void *userptr, - unsigned int num_pages, - enum hrt_userptr_type type, - bool cached) +ia_css_ptr hrt_isp_css_mm_alloc_user_ptr(size_t bytes, + const void __user *userptr, + unsigned int num_pages, + enum hrt_userptr_type type, + bool cached) { return __hrt_isp_css_mm_alloc(bytes, userptr, num_pages, type, cached); diff --git a/drivers/staging/media/atomisp/pci/atomisp2/hrt/hive_isp_css_mm_hrt.h b/drivers/staging/media/atomisp/pci/atomisp2/hrt/hive_isp_css_mm_hrt.h index 15c2dfb6794e..93762e71b4ca 100644 --- a/drivers/staging/media/atomisp/pci/atomisp2/hrt/hive_isp_css_mm_hrt.h +++ b/drivers/staging/media/atomisp/pci/atomisp2/hrt/hive_isp_css_mm_hrt.h @@ -37,15 +37,16 @@ struct hrt_userbuffer_attr { unsigned int pgnr; }; -void hrt_isp_css_mm_set_user_ptr(void *userptr, +void hrt_isp_css_mm_set_user_ptr(void __user *userptr, unsigned int num_pages, enum hrt_userptr_type); /* Allocate memory, returns a virtual address */ ia_css_ptr hrt_isp_css_mm_alloc(size_t bytes); -ia_css_ptr hrt_isp_css_mm_alloc_user_ptr(size_t bytes, void *userptr, - unsigned int num_pages, - enum hrt_userptr_type, - bool cached); +ia_css_ptr hrt_isp_css_mm_alloc_user_ptr(size_t bytes, + const void __user *userptr, + unsigned int num_pages, + enum hrt_userptr_type, + bool cached); ia_css_ptr hrt_isp_css_mm_alloc_cached(size_t bytes); /* allocate memory and initialize with zeros, diff --git a/drivers/staging/media/atomisp/pci/atomisp2/include/hmm/hmm.h b/drivers/staging/media/atomisp/pci/atomisp2/include/hmm/hmm.h index 1e135c7c6d9b..7dcc73c9f49d 100644 --- a/drivers/staging/media/atomisp/pci/atomisp2/include/hmm/hmm.h +++ b/drivers/staging/media/atomisp/pci/atomisp2/include/hmm/hmm.h @@ -38,7 +38,7 @@ int hmm_init(void); void hmm_cleanup(void); ia_css_ptr hmm_alloc(size_t bytes, enum hmm_bo_type type, - int from_highmem, void *userptr, bool cached); + int from_highmem, const void __user *userptr, bool cached); void hmm_free(ia_css_ptr ptr); int hmm_load(ia_css_ptr virt, void *data, unsigned int bytes); int hmm_store(ia_css_ptr virt, const void *data, unsigned int bytes); diff --git a/drivers/staging/media/atomisp/pci/atomisp2/include/hmm/hmm_bo.h b/drivers/staging/media/atomisp/pci/atomisp2/include/hmm/hmm_bo.h index bd44ebbc427c..508d6fd68f93 100644 --- a/drivers/staging/media/atomisp/pci/atomisp2/include/hmm/hmm_bo.h +++ b/drivers/staging/media/atomisp/pci/atomisp2/include/hmm/hmm_bo.h @@ -244,7 +244,7 @@ int hmm_bo_allocated(struct hmm_buffer_object *bo); */ int hmm_bo_alloc_pages(struct hmm_buffer_object *bo, enum hmm_bo_type type, int from_highmem, - void *userptr, bool cached); + const void __user *userptr, bool cached); void hmm_bo_free_pages(struct hmm_buffer_object *bo); int hmm_bo_page_allocated(struct hmm_buffer_object *bo); diff --git a/drivers/staging/media/atomisp/platform/intel-mid/atomisp_gmin_platform.c b/drivers/staging/media/atomisp/platform/intel-mid/atomisp_gmin_platform.c index 3283c1b05d6a..70c34de98707 100644 --- a/drivers/staging/media/atomisp/platform/intel-mid/atomisp_gmin_platform.c +++ b/drivers/staging/media/atomisp/platform/intel-mid/atomisp_gmin_platform.c @@ -693,12 +693,6 @@ static int gmin_get_config_var(struct device *dev, const char *var, for (i = 0; i < sizeof(var8) && var8[i]; i++) var16[i] = var8[i]; -#ifdef CONFIG_64BIT - /* To avoid owerflows when calling the efivar API */ - if (*out_len > ULONG_MAX) - return -EINVAL; -#endif - /* Not sure this API usage is kosher; efivar_entry_get()'s * implementation simply uses VariableName and VendorGuid from * the struct and ignores the rest, but it seems like there diff --git a/drivers/staging/media/davinci_vpfe/Kconfig b/drivers/staging/media/davinci_vpfe/Kconfig index f40a06954a92..bcba9a64c514 100644 --- a/drivers/staging/media/davinci_vpfe/Kconfig +++ b/drivers/staging/media/davinci_vpfe/Kconfig @@ -1,6 +1,7 @@ config VIDEO_DM365_VPFE tristate "DM365 VPFE Media Controller Capture Driver" - depends on VIDEO_V4L2 && ARCH_DAVINCI_DM365 && !VIDEO_DM365_ISIF + depends on VIDEO_V4L2 + depends on (ARCH_DAVINCI_DM365 && !VIDEO_DM365_ISIF) || COMPILE_TEST depends on HAS_DMA depends on VIDEO_V4L2_SUBDEV_API depends on VIDEO_DAVINCI_VPBE_DISPLAY diff --git a/drivers/staging/media/davinci_vpfe/Makefile b/drivers/staging/media/davinci_vpfe/Makefile index 3019c9ecd548..9c57042c877d 100644 --- a/drivers/staging/media/davinci_vpfe/Makefile +++ b/drivers/staging/media/davinci_vpfe/Makefile @@ -3,3 +3,8 @@ obj-$(CONFIG_VIDEO_DM365_VPFE) += davinci-vfpe.o davinci-vfpe-objs := \ dm365_isif.o dm365_ipipe_hw.o dm365_ipipe.o \ dm365_resizer.o dm365_ipipeif.o vpfe_mc_capture.o vpfe_video.o + +# Allow building it with COMPILE_TEST on other archs +ifndef CONFIG_ARCH_DAVINCI +ccflags-y += -Iarch/arm/mach-davinci/include/ +endif diff --git a/drivers/staging/media/davinci_vpfe/TODO b/drivers/staging/media/davinci_vpfe/TODO index 3e5477e8cfa5..cc8bd9306f2a 100644 --- a/drivers/staging/media/davinci_vpfe/TODO +++ b/drivers/staging/media/davinci_vpfe/TODO @@ -20,6 +20,7 @@ TODO (general): - While replacing the older driver in media folder, provide a compatibility layer and compatibility tests that warrants (using the libv4l's LD_PRELOAD approach) there is no regression for the users using the older driver. +- make it independent of arch-specific APIs (mach/mux.h). Building of uImage and Applications: ================================== diff --git a/drivers/staging/media/davinci_vpfe/dm365_ipipe.c b/drivers/staging/media/davinci_vpfe/dm365_ipipe.c index 6a3434cebd79..95942768639c 100644 --- a/drivers/staging/media/davinci_vpfe/dm365_ipipe.c +++ b/drivers/staging/media/davinci_vpfe/dm365_ipipe.c @@ -27,6 +27,7 @@ */ #include <linux/slab.h> +#include <linux/bitops.h> #include "dm365_ipipe.h" #include "dm365_ipipe_hw.h" @@ -56,7 +57,7 @@ static int ipipe_validate_lutdpc_params(struct vpfe_ipipe_lutdpc *lutdpc) lutdpc->dpc_size > LUT_DPC_MAX_SIZE) return -EINVAL; - if (lutdpc->en && !lutdpc->table) + if (lutdpc->en) return -EINVAL; for (i = 0; i < lutdpc->dpc_size; i++) @@ -71,14 +72,12 @@ static int ipipe_set_lutdpc_params(struct vpfe_ipipe_device *ipipe, void *param) { struct vpfe_ipipe_lutdpc *lutdpc = &ipipe->config.lutdpc; struct vpfe_ipipe_lutdpc *dpc_param; - struct device *dev; if (!param) { memset((void *)lutdpc, 0, sizeof(struct vpfe_ipipe_lutdpc)); goto success; } - dev = ipipe->subdev.v4l2_dev->dev; dpc_param = param; lutdpc->en = dpc_param->en; lutdpc->repl_white = dpc_param->repl_white; @@ -694,7 +693,7 @@ static int ipipe_get_gamma_params(struct vpfe_ipipe_device *ipipe, void *param) table_size = gamma->tbl_size; - if (!gamma->bypass_r && !gamma_param->table_r) { + if (!gamma->bypass_r) { dev_err(dev, "ipipe_get_gamma_params: table ptr empty for R\n"); return -EINVAL; @@ -702,14 +701,14 @@ static int ipipe_get_gamma_params(struct vpfe_ipipe_device *ipipe, void *param) memcpy(gamma_param->table_r, gamma->table_r, (table_size * sizeof(struct vpfe_ipipe_gamma_entry))); - if (!gamma->bypass_g && !gamma_param->table_g) { + if (!gamma->bypass_g) { dev_err(dev, "ipipe_get_gamma_params: table ptr empty for G\n"); return -EINVAL; } memcpy(gamma_param->table_g, gamma->table_g, (table_size * sizeof(struct vpfe_ipipe_gamma_entry))); - if (!gamma->bypass_b && !gamma_param->table_b) { + if (!gamma->bypass_b) { dev_err(dev, "ipipe_get_gamma_params: table ptr empty for B\n"); return -EINVAL; } @@ -739,13 +738,8 @@ static int ipipe_get_3d_lut_params(struct vpfe_ipipe_device *ipipe, void *param) { struct vpfe_ipipe_3d_lut *lut_param = param; struct vpfe_ipipe_3d_lut *lut = &ipipe->config.lut; - struct device *dev = ipipe->subdev.v4l2_dev->dev; lut_param->en = lut->en; - if (!lut_param->table) { - dev_err(dev, "ipipe_get_3d_lut_params: Invalid table ptr\n"); - return -EINVAL; - } memcpy(lut_param->table, &lut->table, (VPFE_IPIPE_MAX_SIZE_3D_LUT * @@ -919,14 +913,9 @@ static int ipipe_get_gbce_params(struct vpfe_ipipe_device *ipipe, void *param) { struct vpfe_ipipe_gbce *gbce_param = param; struct vpfe_ipipe_gbce *gbce = &ipipe->config.gbce; - struct device *dev = ipipe->subdev.v4l2_dev->dev; gbce_param->en = gbce->en; gbce_param->type = gbce->type; - if (!gbce_param->table) { - dev_err(dev, "ipipe_get_gbce_params: Invalid table ptr\n"); - return -EINVAL; - } memcpy(gbce_param->table, gbce->table, (VPFE_IPIPE_MAX_SIZE_GBCE_LUT * sizeof(unsigned short))); @@ -1267,37 +1256,36 @@ static int ipipe_s_config(struct v4l2_subdev *sd, struct vpfe_ipipe_config *cfg) int rval = 0; for (i = 0; i < ARRAY_SIZE(ipipe_modules); i++) { - unsigned int bit = 1 << i; - - if (cfg->flag & bit) { - const struct ipipe_module_if *module_if = - &ipipe_modules[i]; - struct ipipe_module_params *params; - void __user *from = *(void * __user *) - ((void *)cfg + module_if->config_offset); - size_t size; - void *to; - - params = kmalloc(sizeof(struct ipipe_module_params), - GFP_KERNEL); - to = (void *)params + module_if->param_offset; - size = module_if->param_size; - - if (to && from && size) { - if (copy_from_user(to, from, size)) { - rval = -EFAULT; - break; - } - rval = module_if->set(ipipe, to); - if (rval) - goto error; - } else if (to && !from && size) { - rval = module_if->set(ipipe, NULL); - if (rval) - goto error; + const struct ipipe_module_if *module_if; + struct ipipe_module_params *params; + void *from, *to; + size_t size; + + if (!(cfg->flag & BIT(i))) + continue; + + module_if = &ipipe_modules[i]; + from = *(void **)((void *)cfg + module_if->config_offset); + + params = kmalloc(sizeof(struct ipipe_module_params), + GFP_KERNEL); + to = (void *)params + module_if->param_offset; + size = module_if->param_size; + + if (to && from && size) { + if (copy_from_user(to, (void __user *)from, size)) { + rval = -EFAULT; + break; } - kfree(params); + rval = module_if->set(ipipe, to); + if (rval) + goto error; + } else if (to && !from && size) { + rval = module_if->set(ipipe, NULL); + if (rval) + goto error; } + kfree(params); } error: return rval; @@ -1310,33 +1298,32 @@ static int ipipe_g_config(struct v4l2_subdev *sd, struct vpfe_ipipe_config *cfg) int rval = 0; for (i = 1; i < ARRAY_SIZE(ipipe_modules); i++) { - unsigned int bit = 1 << i; - - if (cfg->flag & bit) { - const struct ipipe_module_if *module_if = - &ipipe_modules[i]; - struct ipipe_module_params *params; - void __user *to = *(void * __user *) - ((void *)cfg + module_if->config_offset); - size_t size; - void *from; - - params = kmalloc(sizeof(struct ipipe_module_params), - GFP_KERNEL); - from = (void *)params + module_if->param_offset; - size = module_if->param_size; - - if (to && from && size) { - rval = module_if->get(ipipe, from); - if (rval) - goto error; - if (copy_to_user(to, from, size)) { - rval = -EFAULT; - break; - } + const struct ipipe_module_if *module_if; + struct ipipe_module_params *params; + void *from, *to; + size_t size; + + if (!(cfg->flag & BIT(i))) + continue; + + module_if = &ipipe_modules[i]; + to = *(void **)((void *)cfg + module_if->config_offset); + + params = kmalloc(sizeof(struct ipipe_module_params), + GFP_KERNEL); + from = (void *)params + module_if->param_offset; + size = module_if->param_size; + + if (to && from && size) { + rval = module_if->get(ipipe, from); + if (rval) + goto error; + if (copy_to_user((void __user *)to, from, size)) { + rval = -EFAULT; + break; } - kfree(params); } + kfree(params); } error: return rval; @@ -1790,25 +1777,25 @@ vpfe_ipipe_init(struct vpfe_ipipe_device *ipipe, struct platform_device *pdev) struct media_pad *pads = &ipipe->pads[0]; struct v4l2_subdev *sd = &ipipe->subdev; struct media_entity *me = &sd->entity; - static resource_size_t res_len; - struct resource *res; + struct resource *res, *memres; res = platform_get_resource(pdev, IORESOURCE_MEM, 4); if (!res) return -ENOENT; - res_len = resource_size(res); - res = request_mem_region(res->start, res_len, res->name); - if (!res) + memres = request_mem_region(res->start, resource_size(res), res->name); + if (!memres) return -EBUSY; - ipipe->base_addr = ioremap_nocache(res->start, res_len); + ipipe->base_addr = ioremap_nocache(memres->start, + resource_size(memres)); if (!ipipe->base_addr) goto error_release; res = platform_get_resource(pdev, IORESOURCE_MEM, 6); if (!res) goto error_unmap; - ipipe->isp5_base_addr = ioremap_nocache(res->start, res_len); + ipipe->isp5_base_addr = ioremap_nocache(res->start, + resource_size(res)); if (!ipipe->isp5_base_addr) goto error_unmap; @@ -1843,7 +1830,7 @@ vpfe_ipipe_init(struct vpfe_ipipe_device *ipipe, struct platform_device *pdev) error_unmap: iounmap(ipipe->base_addr); error_release: - release_mem_region(res->start, res_len); + release_mem_region(memres->start, resource_size(memres)); return -ENOMEM; } diff --git a/drivers/staging/media/davinci_vpfe/dm365_ipipe_hw.c b/drivers/staging/media/davinci_vpfe/dm365_ipipe_hw.c index a893072d0f04..dbb7ddc70bef 100644 --- a/drivers/staging/media/davinci_vpfe/dm365_ipipe_hw.c +++ b/drivers/staging/media/davinci_vpfe/dm365_ipipe_hw.c @@ -430,9 +430,6 @@ ipipe_set_lutdpc_regs(void __iomem *base_addr, void __iomem *isp5_base_addr, regw_ip(base_addr, LUT_DPC_START_ADDR, DPC_LUT_ADR); regw_ip(base_addr, dpc->dpc_size, DPC_LUT_SIZ & LUT_DPC_SIZE_MASK); - if (dpc->table == NULL) - return; - for (count = 0; count < dpc->dpc_size; count++) { if (count >= max_tbl_size) lut_start_addr = DPC_TB1_START_ADDR; @@ -760,13 +757,13 @@ ipipe_set_gamma_regs(void __iomem *base_addr, void __iomem *isp5_base_addr, table_size = gamma->tbl_size; - if (!gamma->bypass_r && gamma->table_r != NULL) + if (!gamma->bypass_r) ipipe_update_gamma_tbl(isp5_base_addr, gamma->table_r, table_size, GAMMA_R_START_ADDR); - if (!gamma->bypass_b && gamma->table_b != NULL) + if (!gamma->bypass_b) ipipe_update_gamma_tbl(isp5_base_addr, gamma->table_b, table_size, GAMMA_B_START_ADDR); - if (!gamma->bypass_g && gamma->table_g != NULL) + if (!gamma->bypass_g) ipipe_update_gamma_tbl(isp5_base_addr, gamma->table_g, table_size, GAMMA_G_START_ADDR); } @@ -787,10 +784,6 @@ ipipe_set_3d_lut_regs(void __iomem *base_addr, void __iomem *isp5_base_addr, if (!lut_3d->en) return; - /* lut_3d enabled */ - if (!lut_3d->table) - return; - /* valied table */ tbl = lut_3d->table; for (i = 0; i < VPFE_IPIPE_MAX_SIZE_3D_LUT; i++) { @@ -900,9 +893,6 @@ ipipe_set_gbce_regs(void __iomem *base_addr, void __iomem *isp5_base_addr, regw_ip(base_addr, gbce->type, GBCE_TYP); - if (!gbce->table) - return; - for (count = 0; count < VPFE_IPIPE_MAX_SIZE_GBCE_LUT; count += 2) w_ip_table(isp5_base_addr, ((gbce->table[count + 1] & mask) << GBCE_ENTRY_SHIFT) | (gbce->table[count] & mask), @@ -943,9 +933,6 @@ ipipe_set_ee_regs(void __iomem *base_addr, void __iomem *isp5_base_addr, regw_ip(base_addr, ee->es_gain_grad & YEE_THR_MASK, YEE_G_GAN); regw_ip(base_addr, ee->es_ofst_grad & YEE_THR_MASK, YEE_G_OFT); - if (ee->table == NULL) - return; - for (count = 0; count < VPFE_IPIPE_MAX_SIZE_YEE_LUT; count += 2) w_ip_table(isp5_base_addr, ((ee->table[count + 1] & YEE_ENTRY_MASK) << YEE_ENTRY_SHIFT) | diff --git a/drivers/staging/media/davinci_vpfe/dm365_ipipeif.c b/drivers/staging/media/davinci_vpfe/dm365_ipipeif.c index 46fd2c7f69c3..11c9edfbdbe3 100644 --- a/drivers/staging/media/davinci_vpfe/dm365_ipipeif.c +++ b/drivers/staging/media/davinci_vpfe/dm365_ipipeif.c @@ -66,17 +66,17 @@ ipipeif_get_pack_mode(u32 in_pix_fmt) } } -static inline u32 ipipeif_read(void *addr, u32 offset) +static inline u32 ipipeif_read(void __iomem *addr, u32 offset) { return readl(addr + offset); } -static inline void ipipeif_write(u32 val, void *addr, u32 offset) +static inline void ipipeif_write(u32 val, void __iomem *addr, u32 offset) { writel(val, addr + offset); } -static void ipipeif_config_dpc(void *addr, struct ipipeif_dpc *dpc) +static void ipipeif_config_dpc(void __iomem *addr, struct ipipeif_dpc *dpc) { u32 val = 0; @@ -191,7 +191,7 @@ static int ipipeif_hw_setup(struct v4l2_subdev *sd) struct ipipeif_params params = ipipeif->config; enum ipipeif_input_source ipipeif_source; u32 isif_port_if; - void *ipipeif_base_addr; + void __iomem *ipipeif_base_addr; unsigned int val; int data_shift; int pack_mode; @@ -418,7 +418,7 @@ ipipeif_set_config(struct v4l2_subdev *sd, struct ipipeif_params *config) } static int -ipipeif_get_config(struct v4l2_subdev *sd, void __user *arg) +ipipeif_get_config(struct v4l2_subdev *sd, void *arg) { struct vpfe_ipipeif_device *ipipeif = v4l2_get_subdevdata(sd); struct ipipeif_params *config = arg; @@ -507,7 +507,7 @@ static int ipipeif_s_ctrl(struct v4l2_ctrl *ctrl) void vpfe_ipipeif_enable(struct vpfe_device *vpfe_dev) { struct vpfe_ipipeif_device *ipipeif = &vpfe_dev->vpfe_ipipeif; - void *ipipeif_base_addr = ipipeif->ipipeif_base_addr; + void __iomem *ipipeif_base_addr = ipipeif->ipipeif_base_addr; unsigned char val; if (ipipeif->input != IPIPEIF_INPUT_MEMORY) @@ -794,7 +794,7 @@ static int ipipeif_video_in_queue(struct vpfe_device *vpfe_dev, unsigned long addr) { struct vpfe_ipipeif_device *ipipeif = &vpfe_dev->vpfe_ipipeif; - void *ipipeif_base_addr = ipipeif->ipipeif_base_addr; + void __iomem *ipipeif_base_addr = ipipeif->ipipeif_base_addr; unsigned int adofs; u32 val; diff --git a/drivers/staging/media/davinci_vpfe/dm365_isif.c b/drivers/staging/media/davinci_vpfe/dm365_isif.c index 569bcdc9ce2f..745e33fa6bea 100644 --- a/drivers/staging/media/davinci_vpfe/dm365_isif.c +++ b/drivers/staging/media/davinci_vpfe/dm365_isif.c @@ -1397,14 +1397,9 @@ __isif_get_format(struct vpfe_isif_device *isif, struct v4l2_subdev_pad_config *cfg, unsigned int pad, enum v4l2_subdev_format_whence which) { - if (which == V4L2_SUBDEV_FORMAT_TRY) { - struct v4l2_subdev_format fmt; - - fmt.pad = pad; - fmt.which = which; - + if (which == V4L2_SUBDEV_FORMAT_TRY) return v4l2_subdev_get_try_format(&isif->subdev, cfg, pad); - } + return &isif->formats[pad]; } diff --git a/drivers/staging/media/davinci_vpfe/dm365_resizer.c b/drivers/staging/media/davinci_vpfe/dm365_resizer.c index 1ee216d71d42..df6d55e9554d 100644 --- a/drivers/staging/media/davinci_vpfe/dm365_resizer.c +++ b/drivers/staging/media/davinci_vpfe/dm365_resizer.c @@ -794,7 +794,7 @@ resizer_configure_in_single_shot_mode(struct vpfe_resizer_device *resizer) } static void -resizer_set_defualt_configuration(struct vpfe_resizer_device *resizer) +resizer_set_default_configuration(struct vpfe_resizer_device *resizer) { #define WIDTH_I 640 #define HEIGHT_I 480 @@ -916,10 +916,11 @@ resizer_set_configuration(struct vpfe_resizer_device *resizer, struct vpfe_rsz_config *chan_config) { if (!chan_config->config) - resizer_set_defualt_configuration(resizer); + resizer_set_default_configuration(resizer); else if (copy_from_user(&resizer->config.user_config, - chan_config->config, sizeof(struct vpfe_rsz_config_params))) + (void __user *)chan_config->config, + sizeof(struct vpfe_rsz_config_params))) return -EFAULT; return 0; @@ -942,9 +943,9 @@ resizer_get_configuration(struct vpfe_resizer_device *resizer, return -EINVAL; } - if (copy_to_user((void *)chan_config->config, - (void *)&resizer->config.user_config, - sizeof(struct vpfe_rsz_config_params))) { + if (copy_to_user((void __user *)chan_config->config, + (void *)&resizer->config.user_config, + sizeof(struct vpfe_rsz_config_params))) { dev_err(dev, "resizer_get_configuration: Error in copy to user\n"); return -EFAULT; } diff --git a/drivers/staging/media/davinci_vpfe/vpfe_mc_capture.c b/drivers/staging/media/davinci_vpfe/vpfe_mc_capture.c index 634d38c4bea1..e55c815b9b65 100644 --- a/drivers/staging/media/davinci_vpfe/vpfe_mc_capture.c +++ b/drivers/staging/media/davinci_vpfe/vpfe_mc_capture.c @@ -77,7 +77,7 @@ static bool interface; module_param(interface, bool, 0444); module_param(debug, bool, 0644); -/** +/* * VPFE capture can be used for capturing video such as from TVP5146 or TVP7002 * and for capture raw bayer data from camera sensors such as mt9p031. At this * point there is problem in co-existence of mt9p031 and tvp5146 due to i2c diff --git a/drivers/staging/media/davinci_vpfe/vpfe_video.c b/drivers/staging/media/davinci_vpfe/vpfe_video.c index 588743a6fd8a..390fc98d07dd 100644 --- a/drivers/staging/media/davinci_vpfe/vpfe_video.c +++ b/drivers/staging/media/davinci_vpfe/vpfe_video.c @@ -214,7 +214,7 @@ int vpfe_video_is_pipe_ready(struct vpfe_pipeline *pipe) return 1; } -/** +/* * Validate a pipeline by checking both ends of all links for format * discrepancies. * @@ -1468,7 +1468,6 @@ static int vpfe_streamon(struct file *file, void *priv, struct vpfe_device *vpfe_dev = video->vpfe_dev; struct vpfe_pipeline *pipe = &video->pipe; struct vpfe_fh *fh = file->private_data; - struct vpfe_ext_subdev_info *sdinfo; int ret = -EINVAL; v4l2_dbg(1, debug, &vpfe_dev->v4l2_dev, "vpfe_streamon\n"); @@ -1483,7 +1482,6 @@ static int vpfe_streamon(struct file *file, void *priv, v4l2_err(&vpfe_dev->v4l2_dev, "fh->io_allowed\n"); return -EACCES; } - sdinfo = video->current_ext_subdev; /* If buffer queue is empty, return error */ if (list_empty(&video->buffer_queue.queued_list)) { v4l2_err(&vpfe_dev->v4l2_dev, "buffer queue is empty\n"); diff --git a/drivers/staging/media/imx/imx-media-csi.c b/drivers/staging/media/imx/imx-media-csi.c index aeab05f682d9..95d7805f3485 100644 --- a/drivers/staging/media/imx/imx-media-csi.c +++ b/drivers/staging/media/imx/imx-media-csi.c @@ -409,7 +409,8 @@ static int csi_idmac_setup_channel(struct csi_priv *priv) case V4L2_PIX_FMT_SGBRG16: case V4L2_PIX_FMT_SGRBG16: case V4L2_PIX_FMT_SRGGB16: - burst_size = 4; + case V4L2_PIX_FMT_Y16: + burst_size = 8; passthrough = true; passthrough_bits = 16; break; diff --git a/drivers/staging/media/imx/imx-media-utils.c b/drivers/staging/media/imx/imx-media-utils.c index fab98fc0d6a0..7ec2db84451c 100644 --- a/drivers/staging/media/imx/imx-media-utils.c +++ b/drivers/staging/media/imx/imx-media-utils.c @@ -168,6 +168,15 @@ static const struct imx_media_pixfmt rgb_formats[] = { .cs = IPUV3_COLORSPACE_RGB, .bpp = 8, .bayer = true, + }, { + .fourcc = V4L2_PIX_FMT_Y16, + .codes = { + MEDIA_BUS_FMT_Y10_1X10, + MEDIA_BUS_FMT_Y12_1X12, + }, + .cs = IPUV3_COLORSPACE_RGB, + .bpp = 16, + .bayer = true, }, /*** * non-mbus RGB formats start here. NOTE! when adding non-mbus diff --git a/drivers/staging/media/omap4iss/Kconfig b/drivers/staging/media/omap4iss/Kconfig index 46183464ee79..192ba0829128 100644 --- a/drivers/staging/media/omap4iss/Kconfig +++ b/drivers/staging/media/omap4iss/Kconfig @@ -1,6 +1,7 @@ config VIDEO_OMAP4 tristate "OMAP 4 Camera support" - depends on VIDEO_V4L2 && VIDEO_V4L2_SUBDEV_API && I2C && ARCH_OMAP4 + depends on VIDEO_V4L2 && VIDEO_V4L2_SUBDEV_API && I2C + depends on ARCH_OMAP4 || COMPILE_TEST depends on HAS_DMA select MFD_SYSCON select VIDEOBUF2_DMA_CONTIG diff --git a/drivers/staging/media/tegra-vde/tegra-vde.c b/drivers/staging/media/tegra-vde/tegra-vde.c index c47659e96089..90177a59b97c 100644 --- a/drivers/staging/media/tegra-vde/tegra-vde.c +++ b/drivers/staging/media/tegra-vde/tegra-vde.c @@ -16,7 +16,7 @@ #include <linux/iopoll.h> #include <linux/miscdevice.h> #include <linux/module.h> -#include <linux/platform_device.h> +#include <linux/of_device.h> #include <linux/pm_runtime.h> #include <linux/reset.h> #include <linux/slab.h> @@ -368,6 +368,11 @@ static int tegra_vde_setup_hw_context(struct tegra_vde *vde, tegra_vde_setup_iram_tables(vde, dpb_frames, ctx->dpb_frames_nb - 1, ctx->dpb_ref_frames_with_earlier_poc_nb); + + /* + * The IRAM mapping is write-combine, ensure that CPU buffers have + * been flushed at this point. + */ wmb(); VDE_WR(0x00000000, vde->bsev + 0x8C); @@ -440,7 +445,7 @@ static int tegra_vde_setup_hw_context(struct tegra_vde *vde, VDE_WR(value, vde->sxe + 0x4C); value = 0x03800000; - value |= min_t(size_t, bitstream_data_size, SZ_1M); + value |= bitstream_data_size & GENMASK(19, 15); VDE_WR(value, vde->sxe + 0x68); @@ -522,7 +527,8 @@ static void tegra_vde_detach_and_put_dmabuf(struct dma_buf_attachment *a, static int tegra_vde_attach_dmabuf(struct device *dev, int fd, unsigned long offset, - unsigned int min_size, + size_t min_size, + size_t align_size, struct dma_buf_attachment **a, dma_addr_t *addr, struct sg_table **s, @@ -540,9 +546,14 @@ static int tegra_vde_attach_dmabuf(struct device *dev, return PTR_ERR(dmabuf); } + if (dmabuf->size & (align_size - 1)) { + dev_err(dev, "Unaligned dmabuf 0x%zX, should be aligned to 0x%zX\n", + dmabuf->size, align_size); + return -EINVAL; + } + if ((u64)offset + min_size > dmabuf->size) { - dev_err(dev, "Too small dmabuf size %zu @0x%lX, " - "should be at least %d\n", + dev_err(dev, "Too small dmabuf size %zu @0x%lX, should be at least %zu\n", dmabuf->size, offset, min_size); return -EINVAL; } @@ -591,12 +602,12 @@ static int tegra_vde_attach_dmabufs_to_frame(struct device *dev, struct tegra_vde_h264_frame *src, enum dma_data_direction dma_dir, bool baseline_profile, - size_t csize) + size_t lsize, size_t csize) { int err; err = tegra_vde_attach_dmabuf(dev, src->y_fd, - src->y_offset, csize * 4, + src->y_offset, lsize, SZ_256, &frame->y_dmabuf_attachment, &frame->y_addr, &frame->y_sgt, @@ -605,7 +616,7 @@ static int tegra_vde_attach_dmabufs_to_frame(struct device *dev, return err; err = tegra_vde_attach_dmabuf(dev, src->cb_fd, - src->cb_offset, csize, + src->cb_offset, csize, SZ_256, &frame->cb_dmabuf_attachment, &frame->cb_addr, &frame->cb_sgt, @@ -614,7 +625,7 @@ static int tegra_vde_attach_dmabufs_to_frame(struct device *dev, goto err_release_y; err = tegra_vde_attach_dmabuf(dev, src->cr_fd, - src->cr_offset, csize, + src->cr_offset, csize, SZ_256, &frame->cr_dmabuf_attachment, &frame->cr_addr, &frame->cr_sgt, @@ -628,7 +639,7 @@ static int tegra_vde_attach_dmabufs_to_frame(struct device *dev, } err = tegra_vde_attach_dmabuf(dev, src->aux_fd, - src->aux_offset, csize, + src->aux_offset, csize, SZ_256, &frame->aux_dmabuf_attachment, &frame->aux_addr, &frame->aux_sgt, @@ -677,21 +688,6 @@ static int tegra_vde_validate_frame(struct device *dev, return -EINVAL; } - if (frame->y_offset & 0xFF) { - dev_err(dev, "Bad y_offset 0x%X\n", frame->y_offset); - return -EINVAL; - } - - if (frame->cb_offset & 0xFF) { - dev_err(dev, "Bad cb_offset 0x%X\n", frame->cb_offset); - return -EINVAL; - } - - if (frame->cr_offset & 0xFF) { - dev_err(dev, "Bad cr_offset 0x%X\n", frame->cr_offset); - return -EINVAL; - } - return 0; } @@ -777,9 +773,11 @@ static int tegra_vde_ioctl_decode_h264(struct tegra_vde *vde, enum dma_data_direction dma_dir; dma_addr_t bitstream_data_addr; dma_addr_t bsev_ptr; + size_t lsize, csize; size_t bitstream_data_size; unsigned int macroblocks_nb; unsigned int read_bytes; + unsigned int cstride; unsigned int i; long timeout; int ret, err; @@ -792,7 +790,8 @@ static int tegra_vde_ioctl_decode_h264(struct tegra_vde *vde, return ret; ret = tegra_vde_attach_dmabuf(dev, ctx.bitstream_data_fd, - ctx.bitstream_data_offset, 0, + ctx.bitstream_data_offset, + SZ_16K, SZ_16K, &bitstream_data_dmabuf_attachment, &bitstream_data_addr, &bitstream_sgt, @@ -817,6 +816,10 @@ static int tegra_vde_ioctl_decode_h264(struct tegra_vde *vde, goto free_dpb_frames; } + cstride = ALIGN(ctx.pic_width_in_mbs * 8, 16); + csize = cstride * ctx.pic_height_in_mbs * 8; + lsize = macroblocks_nb * 256; + for (i = 0; i < ctx.dpb_frames_nb; i++) { ret = tegra_vde_validate_frame(dev, &frames[i]); if (ret) @@ -830,7 +833,7 @@ static int tegra_vde_ioctl_decode_h264(struct tegra_vde *vde, ret = tegra_vde_attach_dmabufs_to_frame(dev, &dpb_frames[i], &frames[i], dma_dir, ctx.baseline_profile, - macroblocks_nb * 64); + lsize, csize); if (ret) goto release_dpb_frames; } @@ -869,8 +872,7 @@ static int tegra_vde_ioctl_decode_h264(struct tegra_vde *vde, macroblocks_nb = readl_relaxed(vde->sxe + 0xC8) & 0x1FFF; read_bytes = bsev_ptr ? bsev_ptr - bitstream_data_addr : 0; - dev_err(dev, "Decoding failed: " - "read 0x%X bytes, %u macroblocks parsed\n", + dev_err(dev, "Decoding failed: read 0x%X bytes, %u macroblocks parsed\n", read_bytes, macroblocks_nb); ret = -EIO; @@ -933,6 +935,9 @@ static irqreturn_t tegra_vde_isr(int irq, void *data) { struct tegra_vde *vde = data; + if (completion_done(&vde->decode_completion)) + return IRQ_NONE; + tegra_vde_set_bits(vde, 0, vde->frameid + 0x208); complete(&vde->decode_completion); diff --git a/drivers/video/fbdev/omap2/Kconfig b/drivers/video/fbdev/omap2/Kconfig index 0921c4de8407..4de381f2452e 100644 --- a/drivers/video/fbdev/omap2/Kconfig +++ b/drivers/video/fbdev/omap2/Kconfig @@ -1,4 +1,4 @@ -if ARCH_OMAP2PLUS +if OF && (ARCH_OMAP2PLUS || COMPILE_TEST) source "drivers/video/fbdev/omap2/omapfb/Kconfig" diff --git a/include/linux/omap-iommu.h b/include/linux/omap-iommu.h index c1aede46718b..ce1b7c6283ee 100644 --- a/include/linux/omap-iommu.h +++ b/include/linux/omap-iommu.h @@ -13,7 +13,12 @@ #ifndef _OMAP_IOMMU_H_ #define _OMAP_IOMMU_H_ +#ifdef CONFIG_OMAP_IOMMU extern void omap_iommu_save_ctx(struct device *dev); extern void omap_iommu_restore_ctx(struct device *dev); +#else +static inline void omap_iommu_save_ctx(struct device *dev) {} +static inline void omap_iommu_restore_ctx(struct device *dev) {} +#endif #endif diff --git a/include/linux/platform_data/media/mmp-camera.h b/include/linux/platform_data/media/mmp-camera.h index 83804028115c..d2d3a443eedf 100644 --- a/include/linux/platform_data/media/mmp-camera.h +++ b/include/linux/platform_data/media/mmp-camera.h @@ -3,8 +3,27 @@ * Information for the Marvell Armada MMP camera */ +#include <media/v4l2-mediabus.h> + +enum dphy3_algo { + DPHY3_ALGO_DEFAULT = 0, + DPHY3_ALGO_PXA910, + DPHY3_ALGO_PXA2128 +}; + struct mmp_camera_platform_data { struct platform_device *i2c_device; int sensor_power_gpio; int sensor_reset_gpio; + enum v4l2_mbus_type bus_type; + int mclk_min; /* The minimal value of MCLK */ + int mclk_src; /* which clock source the MCLK derives from */ + int mclk_div; /* Clock Divider Value for MCLK */ + /* + * MIPI support + */ + int dphy[3]; /* DPHY: CSI2_DPHY3, CSI2_DPHY5, CSI2_DPHY6 */ + enum dphy3_algo dphy3_algo; /* algos for calculate CSI2_DPHY3 */ + int lane; /* ccic used lane number; 0 means DVP mode */ + int lane_clk; }; diff --git a/include/linux/sony-laptop.h b/include/linux/sony-laptop.h index 1a4b77317fa1..374d0fdb0743 100644 --- a/include/linux/sony-laptop.h +++ b/include/linux/sony-laptop.h @@ -28,7 +28,11 @@ #define SONY_PIC_COMMAND_GETCAMERAROMVERSION 18 /* obsolete */ #define SONY_PIC_COMMAND_GETCAMERAREVISION 19 /* obsolete */ +#if IS_ENABLED(CONFIG_SONY_LAPTOP) int sony_pic_camera_command(int command, u8 value); +#else +static inline int sony_pic_camera_command(int command, u8 value) { return 0; }; +#endif #endif /* __KERNEL__ */ diff --git a/include/media/dvb-usb-ids.h b/include/media/dvb-usb-ids.h index 28e2be5c8a98..f9e73b4a6e89 100644 --- a/include/media/dvb-usb-ids.h +++ b/include/media/dvb-usb-ids.h @@ -418,6 +418,7 @@ #define USB_PID_SVEON_STV27 0xd3af #define USB_PID_TURBOX_DTT_2000 0xd3a4 #define USB_PID_WINTV_SOLOHD 0x0264 +#define USB_PID_WINTV_SOLOHD_2 0x8268 #define USB_PID_EVOLVEO_XTRATV_STICK 0xa115 #define USB_PID_HAMA_DVBT_HYBRID 0x2758 #define USB_PID_XBOX_ONE_TUNER 0x02d5 diff --git a/include/media/media-entity.h b/include/media/media-entity.h index a732af1dbba0..3aa3d58d1d58 100644 --- a/include/media/media-entity.h +++ b/include/media/media-entity.h @@ -842,7 +842,7 @@ struct media_entity *media_entity_get(struct media_entity *entity); * a fwnode. This is useful for devices which use more complex * mappings of media pads. * - * If the entity dose not implement the get_fwnode_pad() operation + * If the entity does not implement the get_fwnode_pad() operation * then this function searches the entity for the first pad that * matches the @direction_flags. * diff --git a/include/media/v4l2-dev.h b/include/media/v4l2-dev.h index f60cf9cf3b9c..73073f6ee48c 100644 --- a/include/media/v4l2-dev.h +++ b/include/media/v4l2-dev.h @@ -30,6 +30,7 @@ * @VFL_TYPE_SUBDEV: for V4L2 subdevices * @VFL_TYPE_SDR: for Software Defined Radio tuners * @VFL_TYPE_TOUCH: for touch sensors + * @VFL_TYPE_MAX: number of VFL types, must always be last in the enum */ enum vfl_devnode_type { VFL_TYPE_GRABBER = 0, diff --git a/include/media/v4l2-fwnode.h b/include/media/v4l2-fwnode.h index c228ec1c77cf..9cccab618b98 100644 --- a/include/media/v4l2-fwnode.h +++ b/include/media/v4l2-fwnode.h @@ -99,7 +99,7 @@ struct v4l2_fwnode_endpoint { struct fwnode_endpoint base; /* * Fields below this line will be zeroed by - * v4l2_fwnode_parse_endpoint() + * v4l2_fwnode_endpoint_parse() */ enum v4l2_mbus_type bus_type; union { diff --git a/include/media/videobuf-dvb.h b/include/media/videobuf-dvb.h deleted file mode 100644 index c9c81990a56c..000000000000 --- a/include/media/videobuf-dvb.h +++ /dev/null @@ -1,59 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -#include <media/dvbdev.h> -#include <media/dmxdev.h> -#include <media/dvb_demux.h> -#include <media/dvb_net.h> -#include <media/dvb_frontend.h> - -#ifndef _VIDEOBUF_DVB_H_ -#define _VIDEOBUF_DVB_H_ - -struct videobuf_dvb { - /* filling that the job of the driver */ - char *name; - struct dvb_frontend *frontend; - struct videobuf_queue dvbq; - - /* video-buf-dvb state info */ - struct mutex lock; - struct task_struct *thread; - int nfeeds; - - /* videobuf_dvb_(un)register manges this */ - struct dvb_demux demux; - struct dmxdev dmxdev; - struct dmx_frontend fe_hw; - struct dmx_frontend fe_mem; - struct dvb_net net; -}; - -struct videobuf_dvb_frontend { - struct list_head felist; - int id; - struct videobuf_dvb dvb; -}; - -struct videobuf_dvb_frontends { - struct list_head felist; - struct mutex lock; - struct dvb_adapter adapter; - int active_fe_id; /* Indicates which frontend in the felist is in use */ - int gate; /* Frontend with gate control 0=!MFE,1=fe0,2=fe1 etc */ -}; - -int videobuf_dvb_register_bus(struct videobuf_dvb_frontends *f, - struct module *module, - void *adapter_priv, - struct device *device, - short *adapter_nr, - int mfe_shared); - -void videobuf_dvb_unregister_bus(struct videobuf_dvb_frontends *f); - -struct videobuf_dvb_frontend * videobuf_dvb_alloc_frontend(struct videobuf_dvb_frontends *f, int id); -void videobuf_dvb_dealloc_frontends(struct videobuf_dvb_frontends *f); - -struct videobuf_dvb_frontend * videobuf_dvb_get_frontend(struct videobuf_dvb_frontends *f, int id); -int videobuf_dvb_find_frontend(struct videobuf_dvb_frontends *f, struct dvb_frontend *p); - -#endif /* _VIDEOBUF_DVB_H_ */ diff --git a/include/uapi/linux/lirc.h b/include/uapi/linux/lirc.h index f189931042a7..6b319581882f 100644 --- a/include/uapi/linux/lirc.h +++ b/include/uapi/linux/lirc.h @@ -134,6 +134,12 @@ #define LIRC_SET_WIDEBAND_RECEIVER _IOW('i', 0x00000023, __u32) /* + * Return the recording timeout, which is either set by + * the ioctl LIRC_SET_REC_TIMEOUT or by the kernel after setting the protocols. + */ +#define LIRC_GET_REC_TIMEOUT _IOR('i', 0x00000024, __u32) + +/* * struct lirc_scancode - decoded scancode with protocol for use with * LIRC_MODE_SCANCODE * diff --git a/include/uapi/linux/omap3isp.h b/include/uapi/linux/omap3isp.h index 1a920145db04..87b55755f4ff 100644 --- a/include/uapi/linux/omap3isp.h +++ b/include/uapi/linux/omap3isp.h @@ -55,6 +55,8 @@ _IOWR('V', BASE_VIDIOC_PRIVATE + 5, struct omap3isp_h3a_af_config) #define VIDIOC_OMAP3ISP_STAT_REQ \ _IOWR('V', BASE_VIDIOC_PRIVATE + 6, struct omap3isp_stat_data) +#define VIDIOC_OMAP3ISP_STAT_REQ_TIME32 \ + _IOWR('V', BASE_VIDIOC_PRIVATE + 6, struct omap3isp_stat_data_time32) #define VIDIOC_OMAP3ISP_STAT_EN \ _IOWR('V', BASE_VIDIOC_PRIVATE + 7, unsigned long) @@ -165,7 +167,14 @@ struct omap3isp_h3a_aewb_config { * @config_counter: Number of the configuration associated with the data. */ struct omap3isp_stat_data { +#ifdef __KERNEL__ + struct { + __s64 tv_sec; + __s64 tv_usec; + } ts; +#else struct timeval ts; +#endif void __user *buf; __u32 buf_size; __u16 frame_number; @@ -173,6 +182,19 @@ struct omap3isp_stat_data { __u16 config_counter; }; +#ifdef __KERNEL__ +struct omap3isp_stat_data_time32 { + struct { + __s32 tv_sec; + __s32 tv_usec; + } ts; + __u32 buf; + __u32 buf_size; + __u16 frame_number; + __u16 cur_frame; + __u16 config_counter; +}; +#endif /* Histogram related structs */ diff --git a/include/video/omapfb_dss.h b/include/video/omapfb_dss.h index 1d38901d599d..12755d8d9b4f 100644 --- a/include/video/omapfb_dss.h +++ b/include/video/omapfb_dss.h @@ -774,6 +774,12 @@ struct omap_dss_driver { const struct hdmi_avi_infoframe *avi); }; +#define for_each_dss_dev(d) while ((d = omap_dss_get_next_device(d)) != NULL) + +typedef void (*omap_dispc_isr_t) (void *arg, u32 mask); + +#if IS_ENABLED(CONFIG_FB_OMAP2) + enum omapdss_version omapdss_get_version(void); bool omapdss_is_initialized(void); @@ -785,7 +791,6 @@ void omapdss_unregister_display(struct omap_dss_device *dssdev); struct omap_dss_device *omap_dss_get_device(struct omap_dss_device *dssdev); void omap_dss_put_device(struct omap_dss_device *dssdev); -#define for_each_dss_dev(d) while ((d = omap_dss_get_next_device(d)) != NULL) struct omap_dss_device *omap_dss_get_next_device(struct omap_dss_device *from); struct omap_dss_device *omap_dss_find_device(void *data, int (*match)(struct omap_dss_device *dssdev, void *data)); @@ -826,7 +831,6 @@ int omapdss_default_get_recommended_bpp(struct omap_dss_device *dssdev); void omapdss_default_get_timings(struct omap_dss_device *dssdev, struct omap_video_timings *timings); -typedef void (*omap_dispc_isr_t) (void *arg, u32 mask); int omap_dispc_register_isr(omap_dispc_isr_t isr, void *arg, u32 mask); int omap_dispc_unregister_isr(omap_dispc_isr_t isr, void *arg, u32 mask); @@ -856,5 +860,51 @@ omapdss_of_get_first_endpoint(const struct device_node *parent); struct omap_dss_device * omapdss_of_find_source_for_first_ep(struct device_node *node); +#else + +static inline enum omapdss_version omapdss_get_version(void) +{ return OMAPDSS_VER_UNKNOWN; }; + +static inline bool omapdss_is_initialized(void) +{ return false; }; + +static inline int omap_dispc_register_isr(omap_dispc_isr_t isr, + void *arg, u32 mask) +{ return 0; }; + +static inline int omap_dispc_unregister_isr(omap_dispc_isr_t isr, + void *arg, u32 mask) +{ return 0; }; + +static inline struct omap_dss_device +*omap_dss_get_device(struct omap_dss_device *dssdev) +{ return NULL; }; + +static inline struct omap_dss_device +*omap_dss_get_next_device(struct omap_dss_device *from) +{return NULL; }; + +static inline void omap_dss_put_device(struct omap_dss_device *dssdev) {}; + +static inline int omapdss_compat_init(void) +{ return 0; }; + +static inline void omapdss_compat_uninit(void) {}; + +static inline int omap_dss_get_num_overlay_managers(void) +{ return 0; }; + +static inline struct omap_overlay_manager *omap_dss_get_overlay_manager(int num) +{ return NULL; }; + +static inline int omap_dss_get_num_overlays(void) +{ return 0; }; + +static inline struct omap_overlay *omap_dss_get_overlay(int num) +{ return NULL; }; + + +#endif /* FB_OMAP2 */ + #endif /* __OMAPFB_DSS_H */ diff --git a/sound/isa/Kconfig b/sound/isa/Kconfig index cb54d9c0a77f..43b35a873d78 100644 --- a/sound/isa/Kconfig +++ b/sound/isa/Kconfig @@ -20,7 +20,8 @@ config SND_SB16_DSP menuconfig SND_ISA bool "ISA sound devices" - depends on ISA && ISA_DMA_API + depends on ISA || COMPILE_TEST + depends on ISA_DMA_API default y help Support for sound devices connected via the ISA bus. |