Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Merge tag 'media/v4.3-1' of git://git.kernel.org/pub/scm/linux/kernel/git/mchehab/linux-media

Pull media updates from Mauro Carvalho Chehab:
- new DVB frontend drivers: ascot2e, cxd2841er, horus3a, lnbh25
- new HDMI capture driver: tc358743
- new driver for NetUP DVB new boards (netup_unidvb)
- IR support for DVBSky cards (smipcie-ir)
- Coda driver has gain macroblock tiling support
- Renesas R-Car gains JPEG codec driver
- new DVB platform driver for STi boards: c8sectpfe
- added documentation for the media core kABI to device-drivers DocBook
- lots of driver fixups, cleanups and improvements

* tag 'media/v4.3-1' of git://git.kernel.org/pub/scm/linux/kernel/git/mchehab/linux-media: (297 commits)
[media] c8sectpfe: Remove select on undefined LIBELF_32
[media] i2c: fix platform_no_drv_owner.cocci warnings
[media] cx231xx: Use wake_up_interruptible() instead of wake_up_interruptible_nr()
[media] tc358743: only queue subdev notifications if devnode is set
[media] tc358743: add missing Kconfig dependency/select
[media] c8sectpfe: Use %pad to print 'dma_addr_t'
[media] DocBook media: Fix typo "the the" in xml files
[media] tc358743: make reset gpio optional
[media] tc358743: set direction of reset gpio using devm_gpiod_get
[media] dvbdev: document most of the functions/data structs
[media] dvb_frontend.h: document the struct dvb_frontend
[media] dvb-frontend.h: document struct dtv_frontend_properties
[media] dvb-frontend.h: document struct dvb_frontend_ops
[media] dvb: Use DVBFE_ALGO_HW where applicable
[media] dvb_frontend.h: document struct analog_demod_ops
[media] dvb_frontend.h: Document struct dvb_tuner_ops
[media] Docbook: Document struct analog_parameters
[media] dvb_frontend.h: get rid of dvbfe_modcod
[media] add documentation for struct dvb_tuner_info
[media] dvb_frontend: document dvb_frontend_tune_settings
...

+18659 -4356
+34
Documentation/DocBook/device-drivers.tmpl
··· 217 217 --> 218 218 </chapter> 219 219 220 + <chapter id="mediadev"> 221 + <title>Media Devices</title> 222 + 223 + <sect1><title>Video2Linux devices</title> 224 + !Iinclude/media/v4l2-async.h 225 + !Iinclude/media/v4l2-ctrls.h 226 + !Iinclude/media/v4l2-dv-timings.h 227 + !Iinclude/media/v4l2-event.h 228 + !Iinclude/media/v4l2-flash-led-class.h 229 + !Iinclude/media/v4l2-mediabus.h 230 + !Iinclude/media/v4l2-mem2mem.h 231 + !Iinclude/media/v4l2-of.h 232 + !Iinclude/media/v4l2-subdev.h 233 + !Iinclude/media/videobuf2-core.h 234 + !Iinclude/media/videobuf2-memops.h 235 + </sect1> 236 + <sect1><title>Digital TV (DVB) devices</title> 237 + !Idrivers/media/dvb-core/dvb_ca_en50221.h 238 + !Idrivers/media/dvb-core/dvb_frontend.h 239 + !Idrivers/media/dvb-core/dvb_math.h 240 + !Idrivers/media/dvb-core/dvb_ringbuffer.h 241 + !Idrivers/media/dvb-core/dvbdev.h 242 + </sect1> 243 + <sect1><title>Remote Controller devices</title> 244 + !Iinclude/media/rc-core.h 245 + </sect1> 246 + <sect1><title>Media Controller devices</title> 247 + !Iinclude/media/media-device.h 248 + !Iinclude/media/media-devnode.h 249 + !Iinclude/media/media-entity.h 250 + </sect1> 251 + 252 + </chapter> 253 + 220 254 <chapter id="uart16x50"> 221 255 <title>16x50 UART Driver</title> 222 256 !Edrivers/tty/serial/serial_core.c
+2 -1
Documentation/DocBook/media/Makefile
··· 199 199 # 200 200 201 201 install_media_images = \ 202 - $(Q)-cp $(OBJIMGFILES) $(MEDIA_SRC_DIR)/*.svg $(MEDIA_SRC_DIR)/v4l/*.svg $(MEDIA_OBJ_DIR)/media_api 202 + $(Q)-mkdir $(MEDIA_OBJ_DIR)/media_api; \ 203 + cp $(OBJIMGFILES) $(MEDIA_SRC_DIR)/*.svg $(MEDIA_SRC_DIR)/v4l/*.svg $(MEDIA_OBJ_DIR)/media_api 203 204 204 205 $(MEDIA_OBJ_DIR)/%: $(MEDIA_SRC_DIR)/%.b64 205 206 $(Q)base64 -d $< >$@
+2 -3
Documentation/DocBook/media/dvb/intro.xml
··· 163 163 <para>where N enumerates the DVB PCI cards in a system starting 164 164 from&#x00A0;0, and M enumerates the devices of each type within each 165 165 adapter, starting from&#x00A0;0, too. We will omit the &#8220; 166 - <constant>/dev/dvb/adapterN/</constant>&#8221; in the further dicussion 167 - of these devices. The naming scheme for the devices is the same wheter 168 - devfs is used or not.</para> 166 + <constant>/dev/dvb/adapterN/</constant>&#8221; in the further discussion 167 + of these devices.</para> 169 168 170 169 <para>More details about the data structures and function calls of all 171 170 the devices are described in the following chapters.</para>
+1 -1
Documentation/DocBook/media/v4l/controls.xml
··· 3414 3414 <row> 3415 3415 <entry><constant>V4L2_EXPOSURE_METERING_MATRIX</constant>&nbsp;</entry> 3416 3416 <entry>A multi-zone metering. The light intensity is measured 3417 - in several points of the frame and the the results are combined. The 3417 + in several points of the frame and the results are combined. The 3418 3418 algorithm of the zones selection and their significance in calculating the 3419 3419 final value is device dependent.</entry> 3420 3420 </row>
+1 -1
Documentation/DocBook/media/v4l/media-ioc-device-info.xml
··· 102 102 </row> 103 103 <row> 104 104 <entry>__u32</entry> 105 - <entry><structfield>media_version</structfield></entry> 105 + <entry><structfield>driver_version</structfield></entry> 106 106 <entry>Media device driver version, formatted with the 107 107 <constant>KERNEL_VERSION()</constant> macro. Together with the 108 108 <structfield>driver</structfield> field this identifies a particular
+19 -19
Documentation/DocBook/media/v4l/vidioc-expbuf.xml
··· 62 62 &VIDIOC-REQBUFS; ioctl.</para> 63 63 64 64 <para> To export a buffer, applications fill &v4l2-exportbuffer;. The 65 - <structfield> type </structfield> field is set to the same buffer type as was 66 - previously used with &v4l2-requestbuffers;<structfield> type </structfield>. 67 - Applications must also set the <structfield> index </structfield> field. Valid 65 + <structfield>type</structfield> field is set to the same buffer type as was 66 + previously used with &v4l2-requestbuffers; <structfield>type</structfield>. 67 + Applications must also set the <structfield>index</structfield> field. Valid 68 68 index numbers range from zero to the number of buffers allocated with 69 - &VIDIOC-REQBUFS; (&v4l2-requestbuffers;<structfield> count </structfield>) 70 - minus one. For the multi-planar API, applications set the <structfield> plane 71 - </structfield> field to the index of the plane to be exported. Valid planes 69 + &VIDIOC-REQBUFS; (&v4l2-requestbuffers; <structfield>count</structfield>) 70 + minus one. For the multi-planar API, applications set the <structfield>plane</structfield> 71 + field to the index of the plane to be exported. Valid planes 72 72 range from zero to the maximal number of valid planes for the currently active 73 - format. For the single-planar API, applications must set <structfield> plane 74 - </structfield> to zero. Additional flags may be posted in the <structfield> 75 - flags </structfield> field. Refer to a manual for open() for details. 73 + format. For the single-planar API, applications must set <structfield>plane</structfield> 74 + to zero. Additional flags may be posted in the <structfield>flags</structfield> 75 + field. Refer to a manual for open() for details. 76 76 Currently only O_CLOEXEC, O_RDONLY, O_WRONLY, and O_RDWR are supported. All 77 77 other fields must be set to zero. 78 78 In the case of multi-planar API, every plane is exported separately using 79 - multiple <constant> VIDIOC_EXPBUF </constant> calls. </para> 79 + multiple <constant>VIDIOC_EXPBUF</constant> calls.</para> 80 80 81 - <para> After calling <constant>VIDIOC_EXPBUF</constant> the <structfield> fd 82 - </structfield> field will be set by a driver. This is a DMABUF file 81 + <para>After calling <constant>VIDIOC_EXPBUF</constant> the <structfield>fd</structfield> 82 + field will be set by a driver. This is a DMABUF file 83 83 descriptor. The application may pass it to other DMABUF-aware devices. Refer to 84 84 <link linkend="dmabuf">DMABUF importing</link> for details about importing 85 85 DMABUF files into V4L2 nodes. It is recommended to close a DMABUF file when it 86 - is no longer used to allow the associated memory to be reclaimed. </para> 86 + is no longer used to allow the associated memory to be reclaimed.</para> 87 87 </refsect1> 88 88 89 89 <refsect1> ··· 170 170 <row> 171 171 <entry>__u32</entry> 172 172 <entry><structfield>flags</structfield></entry> 173 - <entry>Flags for the newly created file, currently only <constant> 174 - O_CLOEXEC </constant>, <constant>O_RDONLY</constant>, <constant>O_WRONLY 175 - </constant>, and <constant>O_RDWR</constant> are supported, refer to the manual 173 + <entry>Flags for the newly created file, currently only 174 + <constant>O_CLOEXEC</constant>, <constant>O_RDONLY</constant>, <constant>O_WRONLY</constant>, 175 + and <constant>O_RDWR</constant> are supported, refer to the manual 176 176 of open() for more details.</entry> 177 177 </row> 178 178 <row> ··· 200 200 <term><errorcode>EINVAL</errorcode></term> 201 201 <listitem> 202 202 <para>A queue is not in MMAP mode or DMABUF exporting is not 203 - supported or <structfield> flags </structfield> or <structfield> type 204 - </structfield> or <structfield> index </structfield> or <structfield> plane 205 - </structfield> fields are invalid.</para> 203 + supported or <structfield>flags</structfield> or <structfield>type</structfield> 204 + or <structfield>index</structfield> or <structfield>plane</structfield> fields 205 + are invalid.</para> 206 206 </listitem> 207 207 </varlistentry> 208 208 </variablelist>
+1 -1
Documentation/DocBook/media/v4l/vidioc-g-parm.xml
··· 267 267 best possible image quality that the hardware can deliver. It is not 268 268 defined how the driver writer may achieve that; it will depend on the 269 269 hardware and the ingenuity of the driver writer. High quality mode is 270 - a different mode from the the regular motion video capture modes. In 270 + a different mode from the regular motion video capture modes. In 271 271 high quality mode:<itemizedlist> 272 272 <listitem> 273 273 <para>The driver may be able to capture higher
+1 -1
Documentation/DocBook/media/v4l/vidioc-queryctrl.xml
··· 616 616 <entry><constant>V4L2_CTRL_FLAG_EXECUTE_ON_WRITE</constant></entry> 617 617 <entry>0x0200</entry> 618 618 <entry>The value provided to the control will be propagated to the driver 619 - even if remains constant. This is required when the control represents an action 619 + even if it remains constant. This is required when the control represents an action 620 620 on the hardware. For example: clearing an error flag or triggering the flash. All the 621 621 controls of the type <constant>V4L2_CTRL_TYPE_BUTTON</constant> have this flag set.</entry> 622 622 </row>
+13 -8
Documentation/devicetree/bindings/media/i2c/adv7604.txt
··· 1 - * Analog Devices ADV7604/11 video decoder with HDMI receiver 1 + * Analog Devices ADV7604/11/12 video decoder with HDMI receiver 2 2 3 - The ADV7604 and ADV7611 are multiformat video decoders with an integrated HDMI 4 - receiver. The ADV7604 has four multiplexed HDMI inputs and one analog input, 5 - and the ADV7611 has one HDMI input and no analog input. 3 + The ADV7604 and ADV7611/12 are multiformat video decoders with an integrated 4 + HDMI receiver. The ADV7604 has four multiplexed HDMI inputs and one analog 5 + input, and the ADV7611 has one HDMI input and no analog input. The 7612 is 6 + similar to the 7611 but has 2 HDMI inputs. 6 7 7 - These device tree bindings support the ADV7611 only at the moment. 8 + These device tree bindings support the ADV7611/12 only at the moment. 8 9 9 10 Required Properties: 10 11 11 12 - compatible: Must contain one of the following 12 13 - "adi,adv7611" for the ADV7611 14 + - "adi,adv7612" for the ADV7612 13 15 14 16 - reg: I2C slave address 15 17 ··· 24 22 Documentation/devicetree/bindings/media/video-interfaces.txt. The port nodes 25 23 are numbered as follows. 26 24 27 - Port ADV7611 25 + Port ADV7611 ADV7612 28 26 ------------------------------------------------------------ 29 - HDMI 0 30 - Digital output 1 27 + HDMI 0 0, 1 28 + Digital output 1 2 31 29 32 30 The digital output port node must contain at least one endpoint. 33 31 ··· 47 45 If none of hsync-active, vsync-active and pclk-sample is specified the 48 46 endpoint will use embedded BT.656 synchronization. 49 47 48 + - default-input: Select which input is selected after reset. 50 49 51 50 Example: 52 51 ··· 60 57 61 58 #address-cells = <1>; 62 59 #size-cells = <0>; 60 + 61 + default-input = <0>; 63 62 64 63 port@0 { 65 64 reg = <0>;
+48
Documentation/devicetree/bindings/media/i2c/tc358743.txt
··· 1 + * Toshiba TC358743 HDMI-RX to MIPI CSI2-TX Bridge 2 + 3 + The Toshiba TC358743 HDMI-RX to MIPI CSI2-TX (H2C) is a bridge that converts 4 + a HDMI stream to MIPI CSI-2 TX. It is programmable through I2C. 5 + 6 + Required Properties: 7 + 8 + - compatible: value should be "toshiba,tc358743" 9 + - clocks, clock-names: should contain a phandle link to the reference clock 10 + source, the clock input is named "refclk". 11 + 12 + Optional Properties: 13 + 14 + - reset-gpios: gpio phandle GPIO connected to the reset pin 15 + - interrupts, interrupt-parent: GPIO connected to the interrupt pin 16 + - data-lanes: should be <1 2 3 4> for four-lane operation, 17 + or <1 2> for two-lane operation 18 + - clock-lanes: should be <0> 19 + - clock-noncontinuous: Presence of this boolean property decides whether the 20 + MIPI CSI-2 clock is continuous or non-continuous. 21 + - link-frequencies: List of allowed link frequencies in Hz. Each frequency is 22 + expressed as a 64-bit big-endian integer. The frequency 23 + is half of the bps per lane due to DDR transmission. 24 + 25 + For further information on the MIPI CSI-2 endpoint node properties, see 26 + Documentation/devicetree/bindings/media/video-interfaces.txt. 27 + 28 + Example: 29 + 30 + tc358743@0f { 31 + compatible = "toshiba,tc358743"; 32 + reg = <0x0f>; 33 + clocks = <&hdmi_osc>; 34 + clock-names = "refclk"; 35 + reset-gpios = <&gpio6 9 GPIO_ACTIVE_LOW>; 36 + interrupt-parent = <&gpio2>; 37 + interrupts = <5 IRQ_TYPE_LEVEL_HIGH>; 38 + 39 + port { 40 + tc358743_out: endpoint { 41 + remote-endpoint = <&mipi_csi2_in>; 42 + data-lanes = <1 2 3 4>; 43 + clock-lanes = <0>; 44 + clock-noncontinuous; 45 + link-frequencies = /bits/ 64 <297000000>; 46 + }; 47 + }; 48 + };
+24
Documentation/devicetree/bindings/media/renesas,jpu.txt
··· 1 + * Renesas JPEG Processing Unit 2 + 3 + The JPEG processing unit (JPU) incorporates the JPEG codec with an encoding 4 + and decoding function conforming to the JPEG baseline process, so that the JPU 5 + can encode image data and decode JPEG data quickly. 6 + 7 + Required properties: 8 + - compatible: should containg one of the following: 9 + - "renesas,jpu-r8a7790" for R-Car H2 10 + - "renesas,jpu-r8a7791" for R-Car M2-W 11 + - "renesas,jpu-r8a7792" for R-Car V2H 12 + - "renesas,jpu-r8a7793" for R-Car M2-N 13 + 14 + - reg: Base address and length of the registers block for the JPU. 15 + - interrupts: JPU interrupt specifier. 16 + - clocks: A phandle + clock-specifier pair for the JPU functional clock. 17 + 18 + Example: R8A7790 (R-Car H2) JPU node 19 + jpeg-codec@fe980000 { 20 + compatible = "renesas,jpu-r8a7790"; 21 + reg = <0 0xfe980000 0 0x10300>; 22 + interrupts = <0 272 IRQ_TYPE_LEVEL_HIGH>; 23 + clocks = <&mstp1_clks R8A7790_CLK_JPU>; 24 + };
+89
Documentation/devicetree/bindings/media/stih407-c8sectpfe.txt
··· 1 + STMicroelectronics STi c8sectpfe binding 2 + ============================================ 3 + 4 + This document describes the c8sectpfe device bindings that is used to get transport 5 + stream data into the SoC on the TS pins, and into DDR for further processing. 6 + 7 + It is typically used in conjunction with one or more demodulator and tuner devices 8 + which converts from the RF to digital domain. Demodulators and tuners are usually 9 + located on an external DVB frontend card connected to SoC TS input pins. 10 + 11 + Currently 7 TS input (tsin) channels are supported on the stih407 family SoC. 12 + 13 + Required properties (controller (parent) node): 14 + - compatible : Should be "stih407-c8sectpfe" 15 + 16 + - reg : Address and length of register sets for each device in 17 + "reg-names" 18 + 19 + - reg-names : The names of the register addresses corresponding to the 20 + registers filled in "reg": 21 + - c8sectpfe: c8sectpfe registers 22 + - c8sectpfe-ram: c8sectpfe internal sram 23 + 24 + - clocks : phandle list of c8sectpfe clocks 25 + - clock-names : should be "c8sectpfe" 26 + See: Documentation/devicetree/bindings/clock/clock-bindings.txt 27 + 28 + - pinctrl-names : a pinctrl state named tsin%d-serial or tsin%d-parallel (where %d is tsin-num) 29 + must be defined for each tsin child node. 30 + - pinctrl-0 : phandle referencing pin configuration for this tsin configuration 31 + See: Documentation/devicetree/bindings/pinctrl/pinctrl-binding.txt 32 + 33 + 34 + Required properties (tsin (child) node): 35 + 36 + - tsin-num : tsin id of the InputBlock (must be between 0 to 6) 37 + - i2c-bus : phandle to the I2C bus DT node which the demodulators & tuners on this tsin channel are connected. 38 + - rst-gpio : reset gpio for this tsin channel. 39 + 40 + Optional properties (tsin (child) node): 41 + 42 + - invert-ts-clk : Bool property to control sense of ts input clock (data stored on falling edge of clk). 43 + - serial-not-parallel : Bool property to configure input bus width (serial on ts_data<7>). 44 + - async-not-sync : Bool property to control if data is received in asynchronous mode 45 + (all bits/bytes with ts_valid or ts_packet asserted are valid). 46 + 47 + - dvb-card : Describes the NIM card connected to this tsin channel. 48 + 49 + Example: 50 + 51 + /* stih410 SoC b2120 + b2004a + stv0367-pll(NIMB) + stv0367-tda18212 (NIMA) DT example) */ 52 + 53 + c8sectpfe@08a20000 { 54 + compatible = "st,stih407-c8sectpfe"; 55 + status = "okay"; 56 + reg = <0x08a20000 0x10000>, <0x08a00000 0x4000>; 57 + reg-names = "stfe", "stfe-ram"; 58 + interrupts = <0 34 0>, <0 35 0>; 59 + interrupt-names = "stfe-error-irq", "stfe-idle-irq"; 60 + 61 + pinctrl-names = "tsin0-serial", "tsin0-parallel", "tsin3-serial", 62 + "tsin4-serial", "tsin5-serial"; 63 + 64 + pinctrl-0 = <&pinctrl_tsin0_serial>; 65 + pinctrl-1 = <&pinctrl_tsin0_parallel>; 66 + pinctrl-2 = <&pinctrl_tsin3_serial>; 67 + pinctrl-3 = <&pinctrl_tsin4_serial_alt3>; 68 + pinctrl-4 = <&pinctrl_tsin5_serial_alt1>; 69 + 70 + clocks = <&clk_s_c0_flexgen CLK_PROC_STFE>; 71 + clock-names = "stfe"; 72 + 73 + /* tsin0 is TSA on NIMA */ 74 + tsin0: port@0 { 75 + tsin-num = <0>; 76 + serial-not-parallel; 77 + i2c-bus = <&ssc2>; 78 + rst-gpio = <&pio15 4 0>; 79 + dvb-card = <STV0367_TDA18212_NIMA_1>; 80 + }; 81 + 82 + tsin3: port@3 { 83 + tsin-num = <3>; 84 + serial-not-parallel; 85 + i2c-bus = <&ssc3>; 86 + rst-gpio = <&pio15 7 0>; 87 + dvb-card = <STV0367_TDA18212_NIMB_1>; 88 + }; 89 + };
+59
MAINTAINERS
··· 1525 1525 F: drivers/clocksource/clksrc_st_lpc.c 1526 1526 F: drivers/i2c/busses/i2c-st.c 1527 1527 F: drivers/media/rc/st_rc.c 1528 + F: drivers/media/platform/sti/c8sectpfe/ 1528 1529 F: drivers/mmc/host/sdhci-st.c 1529 1530 F: drivers/phy/phy-miphy28lp.c 1530 1531 F: drivers/phy/phy-miphy365x.c ··· 5820 5819 F: fs/jbd2/ 5821 5820 F: include/linux/jbd2.h 5822 5821 5822 + JPU V4L2 MEM2MEM DRIVER FOR RENESAS 5823 + M: Mikhail Ulyanov <mikhail.ulyanov@cogentembedded.com> 5824 + L: linux-media@vger.kernel.org 5825 + S: Maintained 5826 + F: drivers/media/platform/rcar_jpu.c 5827 + 5823 5828 JSM Neo PCI based serial card 5824 5829 M: Thadeu Lima de Souza Cascardo <cascardo@linux.vnet.ibm.com> 5825 5830 L: linux-serial@vger.kernel.org ··· 6668 6661 S: Supported 6669 6662 F: Documentation/devicetree/bindings/media/renesas,vsp1.txt 6670 6663 F: drivers/media/platform/vsp1/ 6664 + 6665 + MEDIA DRIVERS FOR ASCOT2E 6666 + M: Sergey Kozlov <serjk@netup.ru> 6667 + L: linux-media@vger.kernel.org 6668 + W: http://linuxtv.org 6669 + W: http://netup.tv/ 6670 + T: git git://linuxtv.org/media_tree.git 6671 + S: Supported 6672 + F: drivers/media/dvb-frontends/ascot2e* 6673 + 6674 + MEDIA DRIVERS FOR CXD2841ER 6675 + M: Sergey Kozlov <serjk@netup.ru> 6676 + L: linux-media@vger.kernel.org 6677 + W: http://linuxtv.org/ 6678 + W: http://netup.tv/ 6679 + T: git git://linuxtv.org/media_tree.git 6680 + S: Supported 6681 + F: drivers/media/dvb-frontends/cxd2841er* 6682 + 6683 + MEDIA DRIVERS FOR HORUS3A 6684 + M: Sergey Kozlov <serjk@netup.ru> 6685 + L: linux-media@vger.kernel.org 6686 + W: http://linuxtv.org/ 6687 + W: http://netup.tv/ 6688 + T: git git://linuxtv.org/media_tree.git 6689 + S: Supported 6690 + F: drivers/media/dvb-frontends/horus3a* 6691 + 6692 + MEDIA DRIVERS FOR LNBH25 6693 + M: Sergey Kozlov <serjk@netup.ru> 6694 + L: linux-media@vger.kernel.org 6695 + W: http://linuxtv.org/ 6696 + W: http://netup.tv/ 6697 + T: git git://linuxtv.org/media_tree.git 6698 + S: Supported 6699 + F: drivers/media/dvb-frontends/lnbh25* 6700 + 6701 + MEDIA DRIVERS FOR NETUP PCI UNIVERSAL DVB devices 6702 + M: Sergey Kozlov <serjk@netup.ru> 6703 + L: linux-media@vger.kernel.org 6704 + W: http://linuxtv.org/ 6705 + W: http://netup.tv/ 6706 + T: git git://linuxtv.org/media_tree.git 6707 + S: Supported 6708 + F: drivers/media/pci/netup_unidvb/* 6671 6709 6672 6710 MEDIA INPUT INFRASTRUCTURE (V4L/DVB) 6673 6711 M: Mauro Carvalho Chehab <mchehab@osg.samsung.com> ··· 10479 10427 F: drivers/char/toshiba.c 10480 10428 F: include/linux/toshiba.h 10481 10429 F: include/uapi/linux/toshiba.h 10430 + 10431 + TOSHIBA TC358743 DRIVER 10432 + M: Mats Randgaard <matrandg@cisco.com> 10433 + L: linux-media@vger.kernel.org 10434 + S: Maintained 10435 + F: drivers/media/i2c/tc358743* 10436 + F: include/media/tc358743.h 10482 10437 10483 10438 TMIO MMC DRIVER 10484 10439 M: Ian Molton <ian@mnementh.co.uk>
+1 -1
arch/sh/kernel/cpu/sh4a/clock-sh7724.c
··· 343 343 CLKDEV_CON_ID("2ddmac0", &mstp_clks[HWBLK_2DDMAC]), 344 344 CLKDEV_DEV_ID("sh_fsi.0", &mstp_clks[HWBLK_SPU]), 345 345 CLKDEV_CON_ID("jpu0", &mstp_clks[HWBLK_JPU]), 346 - CLKDEV_DEV_ID("sh-vou.0", &mstp_clks[HWBLK_VOU]), 346 + CLKDEV_DEV_ID("sh-vou", &mstp_clks[HWBLK_VOU]), 347 347 CLKDEV_CON_ID("beu0", &mstp_clks[HWBLK_BEU0]), 348 348 CLKDEV_DEV_ID("sh_mobile_ceu.0", &mstp_clks[HWBLK_CEU0]), 349 349 CLKDEV_CON_ID("veu0", &mstp_clks[HWBLK_VEU0]),
+3 -6
drivers/media/common/saa7146/saa7146_hlp.c
··· 307 307 /* simple bubble-sort algorithm with duplicate elimination */ 308 308 static int sort_and_eliminate(u32* values, int* count) 309 309 { 310 - int low = 0, high = 0, top = 0, temp = 0; 310 + int low = 0, high = 0, top = 0; 311 311 int cur = 0, next = 0; 312 312 313 313 /* sanity checks */ ··· 318 318 /* bubble sort the first @count items of the array @values */ 319 319 for( top = *count; top > 0; top--) { 320 320 for( low = 0, high = 1; high < top; low++, high++) { 321 - if( values[low] > values[high] ) { 322 - temp = values[low]; 323 - values[low] = values[high]; 324 - values[high] = temp; 325 - } 321 + if( values[low] > values[high] ) 322 + swap(values[low], values[high]); 326 323 } 327 324 } 328 325
+84 -83
drivers/media/dvb-core/dvb_ca_en50221.c
··· 169 169 /** 170 170 * Safely find needle in haystack. 171 171 * 172 - * @param haystack Buffer to look in. 173 - * @param hlen Number of bytes in haystack. 174 - * @param needle Buffer to find. 175 - * @param nlen Number of bytes in needle. 172 + * @haystack: Buffer to look in. 173 + * @hlen: Number of bytes in haystack. 174 + * @needle: Buffer to find. 175 + * @nlen: Number of bytes in needle. 176 176 * @return Pointer into haystack needle was found at, or NULL if not found. 177 177 */ 178 178 static char *findstr(char * haystack, int hlen, char * needle, int nlen) ··· 197 197 198 198 199 199 /** 200 - * Check CAM status. 200 + * dvb_ca_en50221_check_camstatus - Check CAM status. 201 201 */ 202 202 static int dvb_ca_en50221_check_camstatus(struct dvb_ca_private *ca, int slot) 203 203 { ··· 240 240 241 241 242 242 /** 243 - * Wait for flags to become set on the STATUS register on a CAM interface, 244 - * checking for errors and timeout. 243 + * dvb_ca_en50221_wait_if_status - Wait for flags to become set on the STATUS 244 + * register on a CAM interface, checking for errors and timeout. 245 245 * 246 - * @param ca CA instance. 247 - * @param slot Slot on interface. 248 - * @param waitfor Flags to wait for. 249 - * @param timeout_ms Timeout in milliseconds. 246 + * @ca: CA instance. 247 + * @slot: Slot on interface. 248 + * @waitfor: Flags to wait for. 249 + * @timeout_ms: Timeout in milliseconds. 250 250 * 251 251 * @return 0 on success, nonzero on error. 252 252 */ ··· 290 290 291 291 292 292 /** 293 - * Initialise the link layer connection to a CAM. 293 + * dvb_ca_en50221_link_init - Initialise the link layer connection to a CAM. 294 294 * 295 - * @param ca CA instance. 296 - * @param slot Slot id. 295 + * @ca: CA instance. 296 + * @slot: Slot id. 297 297 * 298 298 * @return 0 on success, nonzero on failure. 299 299 */ ··· 346 346 } 347 347 348 348 /** 349 - * Read a tuple from attribute memory. 349 + * dvb_ca_en50221_read_tuple - Read a tuple from attribute memory. 350 350 * 351 - * @param ca CA instance. 352 - * @param slot Slot id. 353 - * @param address Address to read from. Updated. 354 - * @param tupleType Tuple id byte. Updated. 355 - * @param tupleLength Tuple length. Updated. 356 - * @param tuple Dest buffer for tuple (must be 256 bytes). Updated. 351 + * @ca: CA instance. 352 + * @slot: Slot id. 353 + * @address: Address to read from. Updated. 354 + * @tupleType: Tuple id byte. Updated. 355 + * @tupleLength: Tuple length. Updated. 356 + * @tuple: Dest buffer for tuple (must be 256 bytes). Updated. 357 357 * 358 358 * @return 0 on success, nonzero on error. 359 359 */ ··· 399 399 400 400 401 401 /** 402 - * Parse attribute memory of a CAM module, extracting Config register, and checking 403 - * it is a DVB CAM module. 402 + * dvb_ca_en50221_parse_attributes - Parse attribute memory of a CAM module, 403 + * extracting Config register, and checking it is a DVB CAM module. 404 404 * 405 - * @param ca CA instance. 406 - * @param slot Slot id. 405 + * @ca: CA instance. 406 + * @slot: Slot id. 407 407 * 408 408 * @return 0 on success, <0 on failure. 409 409 */ ··· 546 546 547 547 548 548 /** 549 - * Set CAM's configoption correctly. 549 + * dvb_ca_en50221_set_configoption - Set CAM's configoption correctly. 550 550 * 551 - * @param ca CA instance. 552 - * @param slot Slot containing the CAM. 551 + * @ca: CA instance. 552 + * @slot: Slot containing the CAM. 553 553 */ 554 554 static int dvb_ca_en50221_set_configoption(struct dvb_ca_private *ca, int slot) 555 555 { ··· 574 574 575 575 576 576 /** 577 - * This function talks to an EN50221 CAM control interface. It reads a buffer of 578 - * data from the CAM. The data can either be stored in a supplied buffer, or 579 - * automatically be added to the slot's rx_buffer. 577 + * dvb_ca_en50221_read_data - This function talks to an EN50221 CAM control 578 + * interface. It reads a buffer of data from the CAM. The data can either 579 + * be stored in a supplied buffer, or automatically be added to the slot's 580 + * rx_buffer. 580 581 * 581 - * @param ca CA instance. 582 - * @param slot Slot to read from. 583 - * @param ebuf If non-NULL, the data will be written to this buffer. If NULL, 582 + * @ca: CA instance. 583 + * @slot: Slot to read from. 584 + * @ebuf: If non-NULL, the data will be written to this buffer. If NULL, 584 585 * the data will be added into the buffering system as a normal fragment. 585 - * @param ecount Size of ebuf. Ignored if ebuf is NULL. 586 + * @ecount: Size of ebuf. Ignored if ebuf is NULL. 586 587 * 587 588 * @return Number of bytes read, or < 0 on error 588 589 */ ··· 699 698 700 699 701 700 /** 702 - * This function talks to an EN50221 CAM control interface. It writes a buffer of data 703 - * to a CAM. 701 + * dvb_ca_en50221_write_data - This function talks to an EN50221 CAM control 702 + * interface. It writes a buffer of data to a CAM. 704 703 * 705 - * @param ca CA instance. 706 - * @param slot Slot to write to. 707 - * @param ebuf The data in this buffer is treated as a complete link-level packet to 704 + * @ca: CA instance. 705 + * @slot: Slot to write to. 706 + * @ebuf: The data in this buffer is treated as a complete link-level packet to 708 707 * be written. 709 - * @param count Size of ebuf. 708 + * @count: Size of ebuf. 710 709 * 711 710 * @return Number of bytes written, or < 0 on error. 712 711 */ ··· 791 790 792 791 793 792 /** 794 - * A CAM has been removed => shut it down. 793 + * dvb_ca_en50221_camready_irq - A CAM has been removed => shut it down. 795 794 * 796 - * @param ca CA instance. 797 - * @param slot Slot to shut down. 795 + * @ca: CA instance. 796 + * @slot: Slot to shut down. 798 797 */ 799 798 static int dvb_ca_en50221_slot_shutdown(struct dvb_ca_private *ca, int slot) 800 799 { ··· 816 815 817 816 818 817 /** 819 - * A CAMCHANGE IRQ has occurred. 818 + * dvb_ca_en50221_camready_irq - A CAMCHANGE IRQ has occurred. 820 819 * 821 - * @param ca CA instance. 822 - * @param slot Slot concerned. 823 - * @param change_type One of the DVB_CA_CAMCHANGE_* values. 820 + * @ca: CA instance. 821 + * @slot: Slot concerned. 822 + * @change_type: One of the DVB_CA_CAMCHANGE_* values. 824 823 */ 825 824 void dvb_ca_en50221_camchange_irq(struct dvb_ca_en50221 *pubca, int slot, int change_type) 826 825 { ··· 845 844 846 845 847 846 /** 848 - * A CAMREADY IRQ has occurred. 847 + * dvb_ca_en50221_camready_irq - A CAMREADY IRQ has occurred. 849 848 * 850 - * @param ca CA instance. 851 - * @param slot Slot concerned. 849 + * @ca: CA instance. 850 + * @slot: Slot concerned. 852 851 */ 853 852 void dvb_ca_en50221_camready_irq(struct dvb_ca_en50221 *pubca, int slot) 854 853 { ··· 866 865 /** 867 866 * An FR or DA IRQ has occurred. 868 867 * 869 - * @param ca CA instance. 870 - * @param slot Slot concerned. 868 + * @ca: CA instance. 869 + * @slot: Slot concerned. 871 870 */ 872 871 void dvb_ca_en50221_frda_irq(struct dvb_ca_en50221 *pubca, int slot) 873 872 { ··· 900 899 /** 901 900 * Wake up the DVB CA thread 902 901 * 903 - * @param ca CA instance. 902 + * @ca: CA instance. 904 903 */ 905 904 static void dvb_ca_en50221_thread_wakeup(struct dvb_ca_private *ca) 906 905 { ··· 915 914 /** 916 915 * Update the delay used by the thread. 917 916 * 918 - * @param ca CA instance. 917 + * @ca: CA instance. 919 918 */ 920 919 static void dvb_ca_en50221_thread_update_delay(struct dvb_ca_private *ca) 921 920 { ··· 1178 1177 * Real ioctl implementation. 1179 1178 * NOTE: CA_SEND_MSG/CA_GET_MSG ioctls have userspace buffers passed to them. 1180 1179 * 1181 - * @param inode Inode concerned. 1182 - * @param file File concerned. 1183 - * @param cmd IOCTL command. 1184 - * @param arg Associated argument. 1180 + * @inode: Inode concerned. 1181 + * @file: File concerned. 1182 + * @cmd: IOCTL command. 1183 + * @arg: Associated argument. 1185 1184 * 1186 1185 * @return 0 on success, <0 on error. 1187 1186 */ ··· 1259 1258 /** 1260 1259 * Wrapper for ioctl implementation. 1261 1260 * 1262 - * @param inode Inode concerned. 1263 - * @param file File concerned. 1264 - * @param cmd IOCTL command. 1265 - * @param arg Associated argument. 1261 + * @inode: Inode concerned. 1262 + * @file: File concerned. 1263 + * @cmd: IOCTL command. 1264 + * @arg: Associated argument. 1266 1265 * 1267 1266 * @return 0 on success, <0 on error. 1268 1267 */ ··· 1276 1275 /** 1277 1276 * Implementation of write() syscall. 1278 1277 * 1279 - * @param file File structure. 1280 - * @param buf Source buffer. 1281 - * @param count Size of source buffer. 1282 - * @param ppos Position in file (ignored). 1278 + * @file: File structure. 1279 + * @buf: Source buffer. 1280 + * @count: Size of source buffer. 1281 + * @ppos: Position in file (ignored). 1283 1282 * 1284 1283 * @return Number of bytes read, or <0 on error. 1285 1284 */ ··· 1417 1416 /** 1418 1417 * Implementation of read() syscall. 1419 1418 * 1420 - * @param file File structure. 1421 - * @param buf Destination buffer. 1422 - * @param count Size of destination buffer. 1423 - * @param ppos Position in file (ignored). 1419 + * @file: File structure. 1420 + * @buf: Destination buffer. 1421 + * @count: Size of destination buffer. 1422 + * @ppos: Position in file (ignored). 1424 1423 * 1425 1424 * @return Number of bytes read, or <0 on error. 1426 1425 */ ··· 1520 1519 /** 1521 1520 * Implementation of file open syscall. 1522 1521 * 1523 - * @param inode Inode concerned. 1524 - * @param file File concerned. 1522 + * @inode: Inode concerned. 1523 + * @file: File concerned. 1525 1524 * 1526 1525 * @return 0 on success, <0 on failure. 1527 1526 */ ··· 1565 1564 /** 1566 1565 * Implementation of file close syscall. 1567 1566 * 1568 - * @param inode Inode concerned. 1569 - * @param file File concerned. 1567 + * @inode: Inode concerned. 1568 + * @file: File concerned. 1570 1569 * 1571 1570 * @return 0 on success, <0 on failure. 1572 1571 */ ··· 1593 1592 /** 1594 1593 * Implementation of poll() syscall. 1595 1594 * 1596 - * @param file File concerned. 1597 - * @param wait poll wait table. 1595 + * @file: File concerned. 1596 + * @wait: poll wait table. 1598 1597 * 1599 1598 * @return Standard poll mask. 1600 1599 */ ··· 1657 1656 /** 1658 1657 * Initialise a new DVB CA EN50221 interface device. 1659 1658 * 1660 - * @param dvb_adapter DVB adapter to attach the new CA device to. 1661 - * @param ca The dvb_ca instance. 1662 - * @param flags Flags describing the CA device (DVB_CA_FLAG_*). 1663 - * @param slot_count Number of slots supported. 1659 + * @dvb_adapter: DVB adapter to attach the new CA device to. 1660 + * @ca: The dvb_ca instance. 1661 + * @flags: Flags describing the CA device (DVB_CA_FLAG_*). 1662 + * @slot_count: Number of slots supported. 1664 1663 * 1665 1664 * @return 0 on success, nonzero on failure 1666 1665 */ ··· 1744 1743 /** 1745 1744 * Release a DVB CA EN50221 interface device. 1746 1745 * 1747 - * @param ca_dev The dvb_device_t instance for the CA device. 1748 - * @param ca The associated dvb_ca instance. 1746 + * @ca_dev: The dvb_device_t instance for the CA device. 1747 + * @ca: The associated dvb_ca instance. 1749 1748 */ 1750 1749 void dvb_ca_en50221_release(struct dvb_ca_en50221 *pubca) 1751 1750 {
+17 -17
drivers/media/dvb-core/dvb_ca_en50221.h
··· 83 83 /* Functions for reporting IRQ events */ 84 84 85 85 /** 86 - * A CAMCHANGE IRQ has occurred. 86 + * dvb_ca_en50221_camchange_irq - A CAMCHANGE IRQ has occurred. 87 87 * 88 - * @param ca CA instance. 89 - * @param slot Slot concerned. 90 - * @param change_type One of the DVB_CA_CAMCHANGE_* values 88 + * @pubca: CA instance. 89 + * @slot: Slot concerned. 90 + * @change_type: One of the DVB_CA_CAMCHANGE_* values 91 91 */ 92 92 void dvb_ca_en50221_camchange_irq(struct dvb_ca_en50221* pubca, int slot, int change_type); 93 93 94 94 /** 95 - * A CAMREADY IRQ has occurred. 95 + * dvb_ca_en50221_camready_irq - A CAMREADY IRQ has occurred. 96 96 * 97 - * @param ca CA instance. 98 - * @param slot Slot concerned. 97 + * @pubca: CA instance. 98 + * @slot: Slot concerned. 99 99 */ 100 100 void dvb_ca_en50221_camready_irq(struct dvb_ca_en50221* pubca, int slot); 101 101 102 102 /** 103 - * An FR or a DA IRQ has occurred. 103 + * dvb_ca_en50221_frda_irq - An FR or a DA IRQ has occurred. 104 104 * 105 - * @param ca CA instance. 106 - * @param slot Slot concerned. 105 + * @ca: CA instance. 106 + * @slot: Slot concerned. 107 107 */ 108 108 void dvb_ca_en50221_frda_irq(struct dvb_ca_en50221* ca, int slot); 109 109 ··· 113 113 /* Initialisation/shutdown functions */ 114 114 115 115 /** 116 - * Initialise a new DVB CA device. 116 + * dvb_ca_en50221_init - Initialise a new DVB CA device. 117 117 * 118 - * @param dvb_adapter DVB adapter to attach the new CA device to. 119 - * @param ca The dvb_ca instance. 120 - * @param flags Flags describing the CA device (DVB_CA_EN50221_FLAG_*). 121 - * @param slot_count Number of slots supported. 118 + * @dvb_adapter: DVB adapter to attach the new CA device to. 119 + * @ca: The dvb_ca instance. 120 + * @flags: Flags describing the CA device (DVB_CA_EN50221_FLAG_*). 121 + * @slot_count: Number of slots supported. 122 122 * 123 123 * @return 0 on success, nonzero on failure 124 124 */ 125 125 extern int dvb_ca_en50221_init(struct dvb_adapter *dvb_adapter, struct dvb_ca_en50221* ca, int flags, int slot_count); 126 126 127 127 /** 128 - * Release a DVB CA device. 128 + * dvb_ca_en50221_release - Release a DVB CA device. 129 129 * 130 - * @param ca The associated dvb_ca instance. 130 + * @ca: The associated dvb_ca instance. 131 131 */ 132 132 extern void dvb_ca_en50221_release(struct dvb_ca_en50221* ca); 133 133
-1
drivers/media/dvb-core/dvb_frontend.c
··· 81 81 #define FESTATE_SEARCHING_SLOW (FESTATE_TUNING_SLOW | FESTATE_ZIGZAG_SLOW) 82 82 #define FESTATE_LOSTLOCK (FESTATE_ZIGZAG_FAST | FESTATE_ZIGZAG_SLOW) 83 83 84 - #define FE_ALGO_HW 1 85 84 /* 86 85 * FESTATE_IDLE. No tuning parameters have been supplied and the loop is idling. 87 86 * FESTATE_RETUNE. Parameters have been supplied, but we have not yet performed the first tune.
+329 -77
drivers/media/dvb-core/dvb_frontend.h
··· 48 48 */ 49 49 #define MAX_DELSYS 8 50 50 51 + /** 52 + * struct dvb_frontend_tune_settings - parameters to adjust frontend tuning 53 + * 54 + * @min_delay_ms: minimum delay for tuning, in ms 55 + * @step_size: step size between two consecutive frequencies 56 + * @max_drift: maximum drift 57 + * 58 + * NOTE: step_size is in Hz, for terrestrial/cable or kHz for satellite 59 + */ 51 60 struct dvb_frontend_tune_settings { 52 61 int min_delay_ms; 53 62 int step_size; ··· 65 56 66 57 struct dvb_frontend; 67 58 59 + /** 60 + * struct dvb_tuner_info - Frontend name and min/max ranges/bandwidths 61 + * 62 + * @name: name of the Frontend 63 + * @frequency_min: minimal frequency supported 64 + * @frequency_max: maximum frequency supported 65 + * @frequency_step: frequency step 66 + * @bandwidth_min: minimal frontend bandwidth supported 67 + * @bandwidth_max: maximum frontend bandwidth supported 68 + * @bandwidth_step: frontend bandwidth step 69 + * 70 + * NOTE: frequency parameters are in Hz, for terrestrial/cable or kHz for 71 + * satellite. 72 + */ 68 73 struct dvb_tuner_info { 69 74 char name[128]; 70 75 ··· 91 68 u32 bandwidth_step; 92 69 }; 93 70 71 + /** 72 + * struct analog_parameters - Parameters to tune into an analog/radio channel 73 + * 74 + * @frequency: Frequency used by analog TV tuner (either in 62.5 kHz step, 75 + * for TV, or 62.5 Hz for radio) 76 + * @mode: Tuner mode, as defined on enum v4l2_tuner_type 77 + * @audmode: Audio mode as defined for the rxsubchans field at videodev2.h, 78 + * e. g. V4L2_TUNER_MODE_* 79 + * @std: TV standard bitmap as defined at videodev2.h, e. g. V4L2_STD_* 80 + * 81 + * Hybrid tuners should be supported by both V4L2 and DVB APIs. This 82 + * struct contains the data that are used by the V4L2 side. To avoid 83 + * dependencies from V4L2 headers, all enums here are declared as integers. 84 + */ 94 85 struct analog_parameters { 95 86 unsigned int frequency; 96 87 unsigned int mode; 97 88 unsigned int audmode; 98 89 u64 std; 99 - }; 100 - 101 - enum dvbfe_modcod { 102 - DVBFE_MODCOD_DUMMY_PLFRAME = 0, 103 - DVBFE_MODCOD_QPSK_1_4, 104 - DVBFE_MODCOD_QPSK_1_3, 105 - DVBFE_MODCOD_QPSK_2_5, 106 - DVBFE_MODCOD_QPSK_1_2, 107 - DVBFE_MODCOD_QPSK_3_5, 108 - DVBFE_MODCOD_QPSK_2_3, 109 - DVBFE_MODCOD_QPSK_3_4, 110 - DVBFE_MODCOD_QPSK_4_5, 111 - DVBFE_MODCOD_QPSK_5_6, 112 - DVBFE_MODCOD_QPSK_8_9, 113 - DVBFE_MODCOD_QPSK_9_10, 114 - DVBFE_MODCOD_8PSK_3_5, 115 - DVBFE_MODCOD_8PSK_2_3, 116 - DVBFE_MODCOD_8PSK_3_4, 117 - DVBFE_MODCOD_8PSK_5_6, 118 - DVBFE_MODCOD_8PSK_8_9, 119 - DVBFE_MODCOD_8PSK_9_10, 120 - DVBFE_MODCOD_16APSK_2_3, 121 - DVBFE_MODCOD_16APSK_3_4, 122 - DVBFE_MODCOD_16APSK_4_5, 123 - DVBFE_MODCOD_16APSK_5_6, 124 - DVBFE_MODCOD_16APSK_8_9, 125 - DVBFE_MODCOD_16APSK_9_10, 126 - DVBFE_MODCOD_32APSK_3_4, 127 - DVBFE_MODCOD_32APSK_4_5, 128 - DVBFE_MODCOD_32APSK_5_6, 129 - DVBFE_MODCOD_32APSK_8_9, 130 - DVBFE_MODCOD_32APSK_9_10, 131 - DVBFE_MODCOD_RESERVED_1, 132 - DVBFE_MODCOD_BPSK_1_3, 133 - DVBFE_MODCOD_BPSK_1_4, 134 - DVBFE_MODCOD_RESERVED_2 135 90 }; 136 91 137 92 enum tuner_param { ··· 122 121 DVBFE_TUNER_DUMMY = (1 << 31) 123 122 }; 124 123 125 - /* 126 - * ALGO_HW: (Hardware Algorithm) 127 - * ---------------------------------------------------------------- 128 - * Devices that support this algorithm do everything in hardware 129 - * and no software support is needed to handle them. 130 - * Requesting these devices to LOCK is the only thing required, 131 - * device is supposed to do everything in the hardware. 124 + /** 125 + * enum dvbfe_algo - defines the algorithm used to tune into a channel 132 126 * 133 - * ALGO_SW: (Software Algorithm) 134 - * ---------------------------------------------------------------- 127 + * @DVBFE_ALGO_HW: Hardware Algorithm - 128 + * Devices that support this algorithm do everything in hardware 129 + * and no software support is needed to handle them. 130 + * Requesting these devices to LOCK is the only thing required, 131 + * device is supposed to do everything in the hardware. 132 + * 133 + * @DVBFE_ALGO_SW: Software Algorithm - 135 134 * These are dumb devices, that require software to do everything 136 135 * 137 - * ALGO_CUSTOM: (Customizable Agorithm) 138 - * ---------------------------------------------------------------- 139 - * Devices having this algorithm can be customized to have specific 140 - * algorithms in the frontend driver, rather than simply doing a 141 - * software zig-zag. In this case the zigzag maybe hardware assisted 142 - * or it maybe completely done in hardware. In all cases, usage of 143 - * this algorithm, in conjunction with the search and track 144 - * callbacks, utilizes the driver specific algorithm. 136 + * @DVBFE_ALGO_CUSTOM: Customizable Agorithm - 137 + * Devices having this algorithm can be customized to have specific 138 + * algorithms in the frontend driver, rather than simply doing a 139 + * software zig-zag. In this case the zigzag maybe hardware assisted 140 + * or it maybe completely done in hardware. In all cases, usage of 141 + * this algorithm, in conjunction with the search and track 142 + * callbacks, utilizes the driver specific algorithm. 145 143 * 146 - * ALGO_RECOVERY: (Recovery Algorithm) 147 - * ---------------------------------------------------------------- 148 - * These devices have AUTO recovery capabilities from LOCK failure 144 + * @DVBFE_ALGO_RECOVERY: Recovery Algorithm - 145 + * These devices have AUTO recovery capabilities from LOCK failure 149 146 */ 150 147 enum dvbfe_algo { 151 148 DVBFE_ALGO_HW = (1 << 0), ··· 161 162 u32 refclock; 162 163 }; 163 164 164 - /* 165 - * search callback possible return status 165 + /** 166 + * enum dvbfe_search - search callback possible return status 166 167 * 167 - * DVBFE_ALGO_SEARCH_SUCCESS 168 - * The frontend search algorithm completed and returned successfully 168 + * @DVBFE_ALGO_SEARCH_SUCCESS: 169 + * The frontend search algorithm completed and returned successfully 169 170 * 170 - * DVBFE_ALGO_SEARCH_ASLEEP 171 - * The frontend search algorithm is sleeping 171 + * @DVBFE_ALGO_SEARCH_ASLEEP: 172 + * The frontend search algorithm is sleeping 172 173 * 173 - * DVBFE_ALGO_SEARCH_FAILED 174 - * The frontend search for a signal failed 174 + * @DVBFE_ALGO_SEARCH_FAILED: 175 + * The frontend search for a signal failed 175 176 * 176 - * DVBFE_ALGO_SEARCH_INVALID 177 - * The frontend search algorith was probably supplied with invalid 178 - * parameters and the search is an invalid one 177 + * @DVBFE_ALGO_SEARCH_INVALID: 178 + * The frontend search algorith was probably supplied with invalid 179 + * parameters and the search is an invalid one 179 180 * 180 - * DVBFE_ALGO_SEARCH_ERROR 181 - * The frontend search algorithm failed due to some error 181 + * @DVBFE_ALGO_SEARCH_ERROR: 182 + * The frontend search algorithm failed due to some error 182 183 * 183 - * DVBFE_ALGO_SEARCH_AGAIN 184 - * The frontend search algorithm was requested to search again 184 + * @DVBFE_ALGO_SEARCH_AGAIN: 185 + * The frontend search algorithm was requested to search again 185 186 */ 186 187 enum dvbfe_search { 187 188 DVBFE_ALGO_SEARCH_SUCCESS = (1 << 0), ··· 192 193 DVBFE_ALGO_SEARCH_ERROR = (1 << 31), 193 194 }; 194 195 195 - 196 + /** 197 + * struct dvb_tuner_ops - Tuner information and callbacks 198 + * 199 + * @info: embedded struct dvb_tuner_info with tuner properties 200 + * @release: callback function called when frontend is dettached. 201 + * drivers should free any allocated memory. 202 + * @init: callback function used to initialize the tuner device. 203 + * @sleep: callback function used to put the tuner to sleep. 204 + * @suspend: callback function used to inform that the Kernel will 205 + * suspend. 206 + * @resume: callback function used to inform that the Kernel is 207 + * resuming from suspend. 208 + * @set_params: callback function used to inform the tuner to tune 209 + * into a digital TV channel. The properties to be used 210 + * are stored at @dvb_frontend.dtv_property_cache;. The 211 + * tuner demod can change the parameters to reflect the 212 + * changes needed for the channel to be tuned, and 213 + * update statistics. 214 + * @set_analog_params: callback function used to tune into an analog TV 215 + * channel on hybrid tuners. It passes @analog_parameters; 216 + * to the driver. 217 + * @calc_regs: callback function used to pass register data settings 218 + * for simple tuners. 219 + * @set_config: callback function used to send some tuner-specific 220 + * parameters. 221 + * @get_frequency: get the actual tuned frequency 222 + * @get_bandwidth: get the bandwitdh used by the low pass filters 223 + * @get_if_frequency: get the Intermediate Frequency, in Hz. For baseband, 224 + * should return 0. 225 + * @get_status: returns the frontend lock status 226 + * @get_rf_strength: returns the RF signal strengh. Used mostly to support 227 + * analog TV and radio. Digital TV should report, instead, 228 + * via DVBv5 API (@dvb_frontend.dtv_property_cache;). 229 + * @get_afc: Used only by analog TV core. Reports the frequency 230 + * drift due to AFC. 231 + * @set_frequency: Set a new frequency. Please notice that using 232 + * set_params is preferred. 233 + * @set_bandwidth: Set a new frequency. Please notice that using 234 + * set_params is preferred. 235 + * @set_state: callback function used on some legacy drivers that 236 + * don't implement set_params in order to set properties. 237 + * Shouldn't be used on new drivers. 238 + * @get_state: callback function used to get properties by some 239 + * legacy drivers that don't implement set_params. 240 + * Shouldn't be used on new drivers. 241 + * 242 + * NOTE: frequencies used on get_frequency and set_frequency are in Hz for 243 + * terrestrial/cable or kHz for satellite. 244 + * 245 + */ 196 246 struct dvb_tuner_ops { 197 247 198 248 struct dvb_tuner_info info; ··· 285 237 int (*get_state)(struct dvb_frontend *fe, enum tuner_param param, struct tuner_state *state); 286 238 }; 287 239 240 + /** 241 + * struct analog_demod_info - Information struct for analog TV part of the demod 242 + * 243 + * @name: Name of the analog TV demodulator 244 + */ 288 245 struct analog_demod_info { 289 246 char *name; 290 247 }; 291 248 249 + /** 250 + * struct analog_demod_ops - Demodulation information and callbacks for 251 + * analog TV and radio 252 + * 253 + * @info: pointer to struct analog_demod_info 254 + * @set_params: callback function used to inform the demod to set the 255 + * demodulator parameters needed to decode an analog or 256 + * radio channel. The properties are passed via 257 + * struct @analog_params;. 258 + * @has_signal: returns 0xffff if has signal, or 0 if it doesn't. 259 + * @get_afc: Used only by analog TV core. Reports the frequency 260 + * drift due to AFC. 261 + * @tuner_status: callback function that returns tuner status bits, e. g. 262 + * TUNER_STATUS_LOCKED and TUNER_STATUS_STEREO. 263 + * @standby: set the tuner to standby mode. 264 + * @release: callback function called when frontend is dettached. 265 + * drivers should free any allocated memory. 266 + * @i2c_gate_ctrl: controls the I2C gate. Newer drivers should use I2C 267 + * mux support instead. 268 + * @set_config: callback function used to send some tuner-specific 269 + * parameters. 270 + */ 292 271 struct analog_demod_ops { 293 272 294 273 struct analog_demod_info info; ··· 335 260 336 261 struct dtv_frontend_properties; 337 262 263 + 264 + /** 265 + * struct dvb_frontend_ops - Demodulation information and callbacks for 266 + * ditialt TV 267 + * 268 + * @info: embedded struct dvb_tuner_info with tuner properties 269 + * @delsys: Delivery systems supported by the frontend 270 + * @release: callback function called when frontend is dettached. 271 + * drivers should free any allocated memory. 272 + * @release_sec: callback function requesting that the Satelite Equipment 273 + * Control (SEC) driver to release and free any memory 274 + * allocated by the driver. 275 + * @init: callback function used to initialize the tuner device. 276 + * @sleep: callback function used to put the tuner to sleep. 277 + * @write: callback function used by some demod legacy drivers to 278 + * allow other drivers to write data into their registers. 279 + * Should not be used on new drivers. 280 + * @tune: callback function used by demod drivers that use 281 + * @DVBFE_ALGO_HW; to tune into a frequency. 282 + * @get_frontend_algo: returns the desired hardware algorithm. 283 + * @set_frontend: callback function used to inform the demod to set the 284 + * parameters for demodulating a digital TV channel. 285 + * The properties to be used are stored at 286 + * @dvb_frontend.dtv_property_cache;. The demod can change 287 + * the parameters to reflect the changes needed for the 288 + * channel to be decoded, and update statistics. 289 + * @get_tune_settings: callback function 290 + * @get_frontend: callback function used to inform the parameters 291 + * actuall in use. The properties to be used are stored at 292 + * @dvb_frontend.dtv_property_cache; and update 293 + * statistics. Please notice that it should not return 294 + * an error code if the statistics are not available 295 + * because the demog is not locked. 296 + * @read_status: returns the locking status of the frontend. 297 + * @read_ber: legacy callback function to return the bit error rate. 298 + * Newer drivers should provide such info via DVBv5 API, 299 + * e. g. @set_frontend;/@get_frontend;, implementing this 300 + * callback only if DVBv3 API compatibility is wanted. 301 + * @read_signal_strength: legacy callback function to return the signal 302 + * strength. Newer drivers should provide such info via 303 + * DVBv5 API, e. g. @set_frontend;/@get_frontend;, 304 + * implementing this callback only if DVBv3 API 305 + * compatibility is wanted. 306 + * @read_snr: legacy callback function to return the Signal/Noise 307 + * rate. Newer drivers should provide such info via 308 + * DVBv5 API, e. g. @set_frontend;/@get_frontend;, 309 + * implementing this callback only if DVBv3 API 310 + * compatibility is wanted. 311 + * @read_ucblocks: legacy callback function to return the Uncorrected Error 312 + * Blocks. Newer drivers should provide such info via 313 + * DVBv5 API, e. g. @set_frontend;/@get_frontend;, 314 + * implementing this callback only if DVBv3 API 315 + * compatibility is wanted. 316 + * @diseqc_reset_overload: callback function to implement the 317 + * FE_DISEQC_RESET_OVERLOAD ioctl (only Satellite) 318 + * @diseqc_send_master_cmd: callback function to implement the 319 + * FE_DISEQC_SEND_MASTER_CMD ioctl (only Satellite). 320 + * @diseqc_recv_slave_reply: callback function to implement the 321 + * FE_DISEQC_RECV_SLAVE_REPLY ioctl (only Satellite) 322 + * @diseqc_send_burst: callback function to implement the 323 + * FE_DISEQC_SEND_BURST ioctl (only Satellite). 324 + * @set_tone: callback function to implement the 325 + * FE_SET_TONE ioctl (only Satellite). 326 + * @set_voltage: callback function to implement the 327 + * FE_SET_VOLTAGE ioctl (only Satellite). 328 + * @enable_high_lnb_voltage: callback function to implement the 329 + * FE_ENABLE_HIGH_LNB_VOLTAGE ioctl (only Satellite). 330 + * @dishnetwork_send_legacy_command: callback function to implement the 331 + * FE_DISHNETWORK_SEND_LEGACY_CMD ioctl (only Satellite). 332 + * @i2c_gate_ctrl: controls the I2C gate. Newer drivers should use I2C 333 + * mux support instead. 334 + * @ts_bus_ctrl: callback function used to take control of the TS bus. 335 + * @set_lna: callback function to power on/off/auto the LNA. 336 + * @search: callback function used on some custom algo search algos. 337 + * @tuner_ops: pointer to struct dvb_tuner_ops 338 + * @analog_ops: pointer to struct analog_demod_ops 339 + * @set_property: callback function to allow the frontend to validade 340 + * incoming properties. Should not be used on new drivers. 341 + * @get_property: callback function to allow the frontend to override 342 + * outcoming properties. Should not be used on new drivers. 343 + */ 338 344 struct dvb_frontend_ops { 339 345 340 346 struct dvb_frontend_info info; ··· 436 280 unsigned int mode_flags, 437 281 unsigned int *delay, 438 282 enum fe_status *status); 283 + 439 284 /* get frontend tuning algorithm from the module */ 440 285 enum dvbfe_algo (*get_frontend_algo)(struct dvb_frontend *fe); 441 286 ··· 481 324 #ifdef __DVB_CORE__ 482 325 #define MAX_EVENT 8 483 326 327 + /* Used only internally at dvb_frontend.c */ 484 328 struct dvb_fe_events { 485 329 struct dvb_frontend_event events[MAX_EVENT]; 486 330 int eventw; ··· 492 334 }; 493 335 #endif 494 336 337 + /** 338 + * struct dtv_frontend_properties - contains a list of properties that are 339 + * specific to a digital TV standard. 340 + * 341 + * @frequency: frequency in Hz for terrestrial/cable or in kHz for 342 + * Satellite 343 + * @modulation: Frontend modulation type 344 + * @voltage: SEC voltage (only Satellite) 345 + * @sectone: SEC tone mode (only Satellite) 346 + * @inversion: Spectral inversion 347 + * @fec_inner: Forward error correction inner Code Rate 348 + * @transmission_mode: Transmission Mode 349 + * @bandwidth_hz: Bandwidth, in Hz. A zero value means that userspace 350 + * wants to autodetect. 351 + * @guard_interval: Guard Interval 352 + * @hierarchy: Hierarchy 353 + * @symbol_rate: Symbol Rate 354 + * @code_rate_HP: high priority stream code rate 355 + * @code_rate_LP: low priority stream code rate 356 + * @pilot: Enable/disable/autodetect pilot tones 357 + * @rolloff: Rolloff factor (alpha) 358 + * @delivery_system: FE delivery system (e. g. digital TV standard) 359 + * @interleaving: interleaving 360 + * @isdbt_partial_reception: ISDB-T partial reception (only ISDB standard) 361 + * @isdbt_sb_mode: ISDB-T Sound Broadcast (SB) mode (only ISDB standard) 362 + * @isdbt_sb_subchannel: ISDB-T SB subchannel (only ISDB standard) 363 + * @isdbt_sb_segment_idx: ISDB-T SB segment index (only ISDB standard) 364 + * @isdbt_sb_segment_count: ISDB-T SB segment count (only ISDB standard) 365 + * @isdbt_layer_enabled: ISDB Layer enabled (only ISDB standard) 366 + * @layer: ISDB per-layer data (only ISDB standard) 367 + * @layer.segment_count: Segment Count; 368 + * @layer.fec: per layer code rate; 369 + * @layer.modulation: per layer modulation; 370 + * @layer.interleaving: per layer interleaving. 371 + * @stream_id: If different than zero, enable substream filtering, if 372 + * hardware supports (DVB-S2 and DVB-T2). 373 + * @atscmh_fic_ver: Version number of the FIC (Fast Information Channel) 374 + * signaling data (only ATSC-M/H) 375 + * @atscmh_parade_id: Parade identification number (only ATSC-M/H) 376 + * @atscmh_nog: Number of MH groups per MH subframe for a designated 377 + * parade (only ATSC-M/H) 378 + * @atscmh_tnog: Total number of MH groups including all MH groups 379 + * belonging to all MH parades in one MH subframe 380 + * (only ATSC-M/H) 381 + * @atscmh_sgn: Start group number (only ATSC-M/H) 382 + * @atscmh_prc: Parade repetition cycle (only ATSC-M/H) 383 + * @atscmh_rs_frame_mode: Reed Solomon (RS) frame mode (only ATSC-M/H) 384 + * @atscmh_rs_frame_ensemble: RS frame ensemble (only ATSC-M/H) 385 + * @atscmh_rs_code_mode_pri: RS code mode pri (only ATSC-M/H) 386 + * @atscmh_rs_code_mode_sec: RS code mode sec (only ATSC-M/H) 387 + * @atscmh_sccc_block_mode: Series Concatenated Convolutional Code (SCCC) 388 + * Block Mode (only ATSC-M/H) 389 + * @atscmh_sccc_code_mode_a: SCCC code mode A (only ATSC-M/H) 390 + * @atscmh_sccc_code_mode_b: SCCC code mode B (only ATSC-M/H) 391 + * @atscmh_sccc_code_mode_c: SCCC code mode C (only ATSC-M/H) 392 + * @atscmh_sccc_code_mode_d: SCCC code mode D (only ATSC-M/H) 393 + * @lna: Power ON/OFF/AUTO the Linear Now-noise Amplifier (LNA) 394 + * @strength: DVBv5 API statistics: Signal Strength 395 + * @cnr: DVBv5 API statistics: Signal to Noise ratio of the 396 + * (main) carrier 397 + * @pre_bit_error: DVBv5 API statistics: pre-Viterbi bit error count 398 + * @pre_bit_count: DVBv5 API statistics: pre-Viterbi bit count 399 + * @post_bit_error: DVBv5 API statistics: post-Viterbi bit error count 400 + * @post_bit_count: DVBv5 API statistics: post-Viterbi bit count 401 + * @block_error: DVBv5 API statistics: block error count 402 + * @block_count: DVBv5 API statistics: block count 403 + * 404 + * NOTE: derivated statistics like Uncorrected Error blocks (UCE) are 405 + * calculated on userspace. 406 + * 407 + * Only a subset of the properties are needed for a given delivery system. 408 + * For more info, consult the media_api.html with the documentation of the 409 + * Userspace API. 410 + */ 495 411 struct dtv_frontend_properties { 496 - 497 - /* Cache State */ 498 - u32 state; 499 - 500 412 u32 frequency; 501 - enum fe_modulation modulation; 413 + enum fe_modulation modulation; 502 414 503 415 enum fe_sec_voltage voltage; 504 416 enum fe_sec_tone_mode sectone; ··· 635 407 struct dtv_fe_stats post_bit_count; 636 408 struct dtv_fe_stats block_error; 637 409 struct dtv_fe_stats block_count; 410 + 411 + /* private: */ 412 + /* Cache State */ 413 + u32 state; 414 + 638 415 }; 639 416 640 417 #define DVB_FE_NO_EXIT 0 641 418 #define DVB_FE_NORMAL_EXIT 1 642 419 #define DVB_FE_DEVICE_REMOVED 2 643 420 #define DVB_FE_DEVICE_RESUME 3 421 + 422 + /** 423 + * struct dvb_frontend - Frontend structure to be used on drivers. 424 + * 425 + * @ops: embedded struct dvb_frontend_ops 426 + * @dvb: pointer to struct dvb_adapter 427 + * @demodulator_priv: demod private data 428 + * @tuner_priv: tuner private data 429 + * @frontend_priv: frontend private data 430 + * @sec_priv: SEC private data 431 + * @analog_demod_priv: Analog demod private data 432 + * @dtv_property_cache: embedded struct dtv_frontend_properties 433 + * @callback: callback function used on some drivers to call 434 + * either the tuner or the demodulator. 435 + * @id: Frontend ID 436 + * @exit: Used to inform the DVB core that the frontend 437 + * thread should exit (usually, means that the hardware 438 + * got disconnected. 439 + */ 644 440 645 441 struct dvb_frontend { 646 442 struct dvb_frontend_ops ops;
+15 -10
drivers/media/dvb-core/dvb_math.h
··· 25 25 #include <linux/types.h> 26 26 27 27 /** 28 - * computes log2 of a value; the result is shifted left by 24 bits 28 + * cintlog2 - computes log2 of a value; the result is shifted left by 24 bits 29 + * 30 + * @value: The value (must be != 0) 29 31 * 30 32 * to use rational values you can use the following method: 31 33 * intlog2(value) = intlog2(value * 2^x) - x * 2^24 32 34 * 33 - * example: intlog2(8) will give 3 << 24 = 3 * 2^24 34 - * example: intlog2(9) will give 3 << 24 + ... = 3.16... * 2^24 35 - * example: intlog2(1.5) = intlog2(3) - 2^24 = 0.584... * 2^24 35 + * Some usecase examples: 36 + * intlog2(8) will give 3 << 24 = 3 * 2^24 37 + * intlog2(9) will give 3 << 24 + ... = 3.16... * 2^24 38 + * intlog2(1.5) = intlog2(3) - 2^24 = 0.584... * 2^24 36 39 * 37 - * @param value The value (must be != 0) 38 - * @return log2(value) * 2^24 40 + * 41 + * return: log2(value) * 2^24 39 42 */ 40 43 extern unsigned int intlog2(u32 value); 41 44 42 45 /** 43 - * computes log10 of a value; the result is shifted left by 24 bits 46 + * intlog10 - computes log10 of a value; the result is shifted left by 24 bits 47 + * 48 + * @value: The value (must be != 0) 44 49 * 45 50 * to use rational values you can use the following method: 46 51 * intlog10(value) = intlog10(value * 10^x) - x * 2^24 47 52 * 48 - * example: intlog10(1000) will give 3 << 24 = 3 * 2^24 53 + * An usecase example: 54 + * intlog10(1000) will give 3 << 24 = 3 * 2^24 49 55 * due to the implementation intlog10(1000) might be not exactly 3 * 2^24 50 56 * 51 57 * look at intlog2 for similar examples 52 58 * 53 - * @param value The value (must be != 0) 54 - * @return log10(value) * 2^24 59 + * return: log10(value) * 2^24 55 60 */ 56 61 extern unsigned int intlog10(u32 value); 57 62
+1 -1
drivers/media/dvb-core/dvb_net.c
··· 709 709 if (!priv->ule_dbit) { 710 710 /* dest_addr buffer is only valid if priv->ule_dbit == 0 */ 711 711 memcpy(ethh->h_dest, dest_addr, ETH_ALEN); 712 - memset(ethh->h_source, 0, ETH_ALEN); 712 + eth_zero_addr(ethh->h_source); 713 713 } 714 714 else /* zeroize source and dest */ 715 715 memset( ethh, 0, ETH_ALEN*2 );
+74 -59
drivers/media/dvb-core/dvb_ringbuffer.h
··· 45 45 46 46 47 47 /* 48 - ** Notes: 49 - ** ------ 50 - ** (1) For performance reasons read and write routines don't check buffer sizes 51 - ** and/or number of bytes free/available. This has to be done before these 52 - ** routines are called. For example: 53 - ** 54 - ** *** write <buflen> bytes *** 55 - ** free = dvb_ringbuffer_free(rbuf); 56 - ** if (free >= buflen) 57 - ** count = dvb_ringbuffer_write(rbuf, buffer, buflen); 58 - ** else 59 - ** ... 60 - ** 61 - ** *** read min. 1000, max. <bufsize> bytes *** 62 - ** avail = dvb_ringbuffer_avail(rbuf); 63 - ** if (avail >= 1000) 64 - ** count = dvb_ringbuffer_read(rbuf, buffer, min(avail, bufsize)); 65 - ** else 66 - ** ... 67 - ** 68 - ** (2) If there is exactly one reader and one writer, there is no need 69 - ** to lock read or write operations. 70 - ** Two or more readers must be locked against each other. 71 - ** Flushing the buffer counts as a read operation. 72 - ** Resetting the buffer counts as a read and write operation. 73 - ** Two or more writers must be locked against each other. 74 - */ 48 + * Notes: 49 + * ------ 50 + * (1) For performance reasons read and write routines don't check buffer sizes 51 + * and/or number of bytes free/available. This has to be done before these 52 + * routines are called. For example: 53 + * 54 + * *** write @buflen: bytes *** 55 + * free = dvb_ringbuffer_free(rbuf); 56 + * if (free >= buflen) 57 + * count = dvb_ringbuffer_write(rbuf, buffer, buflen); 58 + * else 59 + * ... 60 + * 61 + * *** read min. 1000, max. @bufsize: bytes *** 62 + * avail = dvb_ringbuffer_avail(rbuf); 63 + * if (avail >= 1000) 64 + * count = dvb_ringbuffer_read(rbuf, buffer, min(avail, bufsize)); 65 + * else 66 + * ... 67 + * 68 + * (2) If there is exactly one reader and one writer, there is no need 69 + * to lock read or write operations. 70 + * Two or more readers must be locked against each other. 71 + * Flushing the buffer counts as a read operation. 72 + * Resetting the buffer counts as a read and write operation. 73 + * Two or more writers must be locked against each other. 74 + */ 75 75 76 76 /* initialize ring buffer, lock and queue */ 77 77 extern void dvb_ringbuffer_init(struct dvb_ringbuffer *rbuf, void *data, size_t len); ··· 87 87 88 88 89 89 /* 90 - ** Reset the read and write pointers to zero and flush the buffer 91 - ** This counts as a read and write operation 92 - */ 90 + * Reset the read and write pointers to zero and flush the buffer 91 + * This counts as a read and write operation 92 + */ 93 93 extern void dvb_ringbuffer_reset(struct dvb_ringbuffer *rbuf); 94 94 95 95 ··· 101 101 /* flush buffer protected by spinlock and wake-up waiting task(s) */ 102 102 extern void dvb_ringbuffer_flush_spinlock_wakeup(struct dvb_ringbuffer *rbuf); 103 103 104 - /* peek at byte <offs> in the buffer */ 104 + /* peek at byte @offs: in the buffer */ 105 105 #define DVB_RINGBUFFER_PEEK(rbuf,offs) \ 106 106 (rbuf)->data[((rbuf)->pread+(offs))%(rbuf)->size] 107 107 108 - /* advance read ptr by <num> bytes */ 108 + /* advance read ptr by @num: bytes */ 109 109 #define DVB_RINGBUFFER_SKIP(rbuf,num) \ 110 110 (rbuf)->pread=((rbuf)->pread+(num))%(rbuf)->size 111 111 112 112 /* 113 - ** read <len> bytes from ring buffer into <buf> 114 - ** <usermem> specifies whether <buf> resides in user space 115 - ** returns number of bytes transferred or -EFAULT 116 - */ 113 + * read @len: bytes from ring buffer into @buf: 114 + * @usermem: specifies whether @buf: resides in user space 115 + * returns number of bytes transferred or -EFAULT 116 + */ 117 117 extern ssize_t dvb_ringbuffer_read_user(struct dvb_ringbuffer *rbuf, 118 118 u8 __user *buf, size_t len); 119 119 extern void dvb_ringbuffer_read(struct dvb_ringbuffer *rbuf, ··· 127 127 { (rbuf)->data[(rbuf)->pwrite]=(byte); \ 128 128 (rbuf)->pwrite=((rbuf)->pwrite+1)%(rbuf)->size; } 129 129 /* 130 - ** write <len> bytes to ring buffer 131 - ** <usermem> specifies whether <buf> resides in user space 132 - ** returns number of bytes transferred or -EFAULT 130 + * write @len: bytes to ring buffer 131 + * @usermem: specifies whether @buf: resides in user space 132 + * returns number of bytes transferred or -EFAULT 133 133 */ 134 134 extern ssize_t dvb_ringbuffer_write(struct dvb_ringbuffer *rbuf, const u8 *buf, 135 135 size_t len); ··· 138 138 139 139 140 140 /** 141 - * Write a packet into the ringbuffer. 141 + * dvb_ringbuffer_pkt_write - Write a packet into the ringbuffer. 142 142 * 143 - * <rbuf> Ringbuffer to write to. 144 - * <buf> Buffer to write. 145 - * <len> Length of buffer (currently limited to 65535 bytes max). 143 + * @rbuf: Ringbuffer to write to. 144 + * @buf: Buffer to write. 145 + * @len: Length of buffer (currently limited to 65535 bytes max). 146 146 * returns Number of bytes written, or -EFAULT, -ENOMEM, -EVINAL. 147 147 */ 148 148 extern ssize_t dvb_ringbuffer_pkt_write(struct dvb_ringbuffer *rbuf, u8* buf, 149 149 size_t len); 150 150 151 151 /** 152 - * Read from a packet in the ringbuffer. Note: unlike dvb_ringbuffer_read(), this 153 - * does NOT update the read pointer in the ringbuffer. You must use 154 - * dvb_ringbuffer_pkt_dispose() to mark a packet as no longer required. 152 + * dvb_ringbuffer_pkt_read_user - Read from a packet in the ringbuffer. 153 + * Note: unlike dvb_ringbuffer_read(), this does NOT update the read pointer 154 + * in the ringbuffer. You must use dvb_ringbuffer_pkt_dispose() to mark a 155 + * packet as no longer required. 155 156 * 156 - * <rbuf> Ringbuffer concerned. 157 - * <idx> Packet index as returned by dvb_ringbuffer_pkt_next(). 158 - * <offset> Offset into packet to read from. 159 - * <buf> Destination buffer for data. 160 - * <len> Size of destination buffer. 161 - * <usermem> Set to 1 if <buf> is in userspace. 157 + * @rbuf: Ringbuffer concerned. 158 + * @idx: Packet index as returned by dvb_ringbuffer_pkt_next(). 159 + * @offset: Offset into packet to read from. 160 + * @buf: Destination buffer for data. 161 + * @len: Size of destination buffer. 162 + * 162 163 * returns Number of bytes read, or -EFAULT. 163 164 */ 164 165 extern ssize_t dvb_ringbuffer_pkt_read_user(struct dvb_ringbuffer *rbuf, size_t idx, 165 166 int offset, u8 __user *buf, size_t len); 167 + 168 + /** 169 + * dvb_ringbuffer_pkt_read - Read from a packet in the ringbuffer. 170 + * Note: unlike dvb_ringbuffer_read_user(), this DOES update the read pointer 171 + * in the ringbuffer. 172 + * 173 + * @rbuf: Ringbuffer concerned. 174 + * @idx: Packet index as returned by dvb_ringbuffer_pkt_next(). 175 + * @offset: Offset into packet to read from. 176 + * @buf: Destination buffer for data. 177 + * @len: Size of destination buffer. 178 + * 179 + * returns Number of bytes read, or -EFAULT. 180 + */ 166 181 extern ssize_t dvb_ringbuffer_pkt_read(struct dvb_ringbuffer *rbuf, size_t idx, 167 182 int offset, u8 *buf, size_t len); 168 183 169 184 /** 170 - * Dispose of a packet in the ring buffer. 185 + * dvb_ringbuffer_pkt_dispose - Dispose of a packet in the ring buffer. 171 186 * 172 - * <rbuf> Ring buffer concerned. 173 - * <idx> Packet index as returned by dvb_ringbuffer_pkt_next(). 187 + * @rbuf: Ring buffer concerned. 188 + * @idx: Packet index as returned by dvb_ringbuffer_pkt_next(). 174 189 */ 175 190 extern void dvb_ringbuffer_pkt_dispose(struct dvb_ringbuffer *rbuf, size_t idx); 176 191 177 192 /** 178 - * Get the index of the next packet in a ringbuffer. 193 + * dvb_ringbuffer_pkt_next - Get the index of the next packet in a ringbuffer. 179 194 * 180 - * <rbuf> Ringbuffer concerned. 181 - * <idx> Previous packet index, or -1 to return the first packet index. 182 - * <pktlen> On success, will be updated to contain the length of the packet in bytes. 195 + * @rbuf: Ringbuffer concerned. 196 + * @idx: Previous packet index, or -1 to return the first packet index. 197 + * @pktlen: On success, will be updated to contain the length of the packet in bytes. 183 198 * returns Packet index (if >=0), or -1 if no packets available. 184 199 */ 185 200 extern ssize_t dvb_ringbuffer_pkt_next(struct dvb_ringbuffer *rbuf, size_t idx, size_t* pktlen);
+98 -16
drivers/media/dvb-core/dvbdev.h
··· 57 57 58 58 struct dvb_frontend; 59 59 60 + /** 61 + * struct dvb_adapter - represents a Digital TV adapter using Linux DVB API 62 + * 63 + * @num: Number of the adapter 64 + * @list_head: List with the DVB adapters 65 + * @device_list: List with the DVB devices 66 + * @name: Name of the adapter 67 + * @proposed_mac: proposed MAC address for the adapter 68 + * @priv: private data 69 + * @device: pointer to struct device 70 + * @module: pointer to struct module 71 + * @mfe_shared: mfe shared: indicates mutually exclusive frontends 72 + * Thie usage of this flag is currently deprecated 73 + * @mfe_dvbdev: Frontend device in use, in the case of MFE 74 + * @mfe_lock: Lock to prevent using the other frontends when MFE is 75 + * used. 76 + * @mdev: pointer to struct media_device, used when the media 77 + * controller is used. 78 + */ 60 79 struct dvb_adapter { 61 80 int num; 62 81 struct list_head list_head; ··· 97 78 #endif 98 79 }; 99 80 100 - 81 + /** 82 + * struct dvb_device - represents a DVB device node 83 + * 84 + * @list_head: List head with all DVB devices 85 + * @fops: pointer to struct file_operations 86 + * @adapter: pointer to the adapter that holds this device node 87 + * @type: type of the device: DVB_DEVICE_SEC, DVB_DEVICE_FRONTEND, 88 + * DVB_DEVICE_DEMUX, DVB_DEVICE_DVR, DVB_DEVICE_CA, DVB_DEVICE_NET 89 + * @minor: devnode minor number. Major number is always DVB_MAJOR. 90 + * @id: device ID number, inside the adapter 91 + * @readers: Initialized by the caller. Each call to open() in Read Only mode 92 + * decreases this counter by one. 93 + * @writers: Initialized by the caller. Each call to open() in Read/Write 94 + * mode decreases this counter by one. 95 + * @users: Initialized by the caller. Each call to open() in any mode 96 + * decreases this counter by one. 97 + * @wait_queue: wait queue, used to wait for certain events inside one of 98 + * the DVB API callers 99 + * @kernel_ioctl: callback function used to handle ioctl calls from userspace. 100 + * @name: Name to be used for the device at the Media Controller 101 + * @entity: pointer to struct media_entity associated with the device node 102 + * @pads: pointer to struct media_pad associated with @entity; 103 + * @priv: private data 104 + * 105 + * This structure is used by the DVB core (frontend, CA, net, demux) in 106 + * order to create the device nodes. Usually, driver should not initialize 107 + * this struct diretly. 108 + */ 101 109 struct dvb_device { 102 110 struct list_head list_head; 103 111 const struct file_operations *fops; ··· 155 109 void *priv; 156 110 }; 157 111 112 + /** 113 + * dvb_register_adapter - Registers a new DVB adapter 114 + * 115 + * @adap: pointer to struct dvb_adapter 116 + * @name: Adapter's name 117 + * @module: initialized with THIS_MODULE at the caller 118 + * @device: pointer to struct device that corresponds to the device driver 119 + * @adapter_nums: Array with a list of the numbers for @dvb_register_adapter; 120 + * to select among them. Typically, initialized with: 121 + * DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nums) 122 + */ 123 + int dvb_register_adapter(struct dvb_adapter *adap, const char *name, 124 + struct module *module, struct device *device, 125 + short *adapter_nums); 158 126 159 - extern int dvb_register_adapter(struct dvb_adapter *adap, const char *name, 160 - struct module *module, struct device *device, 161 - short *adapter_nums); 162 - extern int dvb_unregister_adapter (struct dvb_adapter *adap); 127 + /** 128 + * dvb_unregister_adapter - Unregisters a DVB adapter 129 + * 130 + * @adap: pointer to struct dvb_adapter 131 + */ 132 + int dvb_unregister_adapter(struct dvb_adapter *adap); 163 133 164 - extern int dvb_register_device (struct dvb_adapter *adap, 165 - struct dvb_device **pdvbdev, 166 - const struct dvb_device *template, 167 - void *priv, 168 - int type); 134 + /** 135 + * dvb_register_device - Registers a new DVB device 136 + * 137 + * @adap: pointer to struct dvb_adapter 138 + * @pdvbdev: pointer to the place where the new struct dvb_device will be 139 + * stored 140 + * @template: Template used to create &pdvbdev; 141 + * @device: pointer to struct device that corresponds to the device driver 142 + * @adapter_nums: Array with a list of the numbers for @dvb_register_adapter; 143 + * to select among them. Typically, initialized with: 144 + * DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nums) 145 + * @priv: private data 146 + * @type: type of the device: DVB_DEVICE_SEC, DVB_DEVICE_FRONTEND, 147 + * DVB_DEVICE_DEMUX, DVB_DEVICE_DVR, DVB_DEVICE_CA, DVB_DEVICE_NET 148 + */ 149 + int dvb_register_device(struct dvb_adapter *adap, 150 + struct dvb_device **pdvbdev, 151 + const struct dvb_device *template, 152 + void *priv, 153 + int type); 169 154 170 - extern void dvb_unregister_device (struct dvb_device *dvbdev); 155 + /** 156 + * dvb_unregister_device - Unregisters a DVB device 157 + * 158 + * @dvbdev: pointer to struct dvb_device 159 + */ 160 + void dvb_unregister_device(struct dvb_device *dvbdev); 171 161 172 162 #ifdef CONFIG_MEDIA_CONTROLLER_DVB 173 163 void dvb_create_media_graph(struct dvb_adapter *adap); ··· 218 136 #define dvb_register_media_controller(a, b) {} 219 137 #endif 220 138 221 - extern int dvb_generic_open (struct inode *inode, struct file *file); 222 - extern int dvb_generic_release (struct inode *inode, struct file *file); 223 - extern long dvb_generic_ioctl (struct file *file, 139 + int dvb_generic_open (struct inode *inode, struct file *file); 140 + int dvb_generic_release (struct inode *inode, struct file *file); 141 + long dvb_generic_ioctl (struct file *file, 224 142 unsigned int cmd, unsigned long arg); 225 143 226 144 /* we don't mess with video_usercopy() any more, 227 145 we simply define out own dvb_usercopy(), which will hopefully become 228 146 generic_usercopy() someday... */ 229 147 230 - extern int dvb_usercopy(struct file *file, unsigned int cmd, unsigned long arg, 231 - int (*func)(struct file *file, unsigned int cmd, void *arg)); 148 + int dvb_usercopy(struct file *file, unsigned int cmd, unsigned long arg, 149 + int (*func)(struct file *file, unsigned int cmd, void *arg)); 232 150 233 151 /** generic DVB attach function. */ 234 152 #ifdef CONFIG_MEDIA_ATTACH
+31 -1
drivers/media/dvb-frontends/Kconfig
··· 1 1 menu "Customise DVB Frontends" 2 - visible if !MEDIA_SUBDRV_AUTOSELECT 2 + visible if !MEDIA_SUBDRV_AUTOSELECT || COMPILE_TEST 3 3 4 4 comment "Multistandard (satellite) frontends" 5 5 depends on DVB_CORE ··· 264 264 config DVB_TDA10071 265 265 tristate "NXP TDA10071" 266 266 depends on DVB_CORE && I2C 267 + select REGMAP 267 268 default m if !MEDIA_SUBDRV_AUTOSELECT 268 269 help 269 270 Say Y when you want to support this frontend. ··· 446 445 447 446 config DVB_CXD2820R 448 447 tristate "Sony CXD2820R" 448 + depends on DVB_CORE && I2C 449 + default m if !MEDIA_SUBDRV_AUTOSELECT 450 + help 451 + Say Y when you want to support this frontend. 452 + 453 + config DVB_CXD2841ER 454 + tristate "Sony CXD2841ER" 449 455 depends on DVB_CORE && I2C 450 456 default m if !MEDIA_SUBDRV_AUTOSELECT 451 457 help ··· 720 712 721 713 source "drivers/media/dvb-frontends/drx39xyj/Kconfig" 722 714 715 + config DVB_LNBH25 716 + tristate "LNBH25 SEC controller" 717 + depends on DVB_CORE && I2C 718 + default m if !MEDIA_SUBDRV_AUTOSELECT 719 + help 720 + An SEC control chip. 721 + Say Y when you want to support this chip. 722 + 723 723 config DVB_LNBP21 724 724 tristate "LNBP21/LNBH24 SEC controllers" 725 725 depends on DVB_CORE && I2C ··· 830 814 tristate "Afatech AF9033 DVB-T demodulator" 831 815 depends on DVB_CORE && I2C 832 816 default m if !MEDIA_SUBDRV_AUTOSELECT 817 + 818 + config DVB_HORUS3A 819 + tristate "Sony Horus3A tuner" 820 + depends on DVB_CORE && I2C 821 + default m if !MEDIA_SUBDRV_AUTOSELECT 822 + help 823 + Say Y when you want to support this frontend. 824 + 825 + config DVB_ASCOT2E 826 + tristate "Sony Ascot2E tuner" 827 + depends on DVB_CORE && I2C 828 + default m if !MEDIA_SUBDRV_AUTOSELECT 829 + help 830 + Say Y when you want to support this frontend. 833 831 834 832 comment "Tools to develop new frontends" 835 833
+4
drivers/media/dvb-frontends/Makefile
··· 57 57 obj-$(CONFIG_DVB_LGDT3306A) += lgdt3306a.o 58 58 obj-$(CONFIG_DVB_LG2160) += lg2160.o 59 59 obj-$(CONFIG_DVB_CX24123) += cx24123.o 60 + obj-$(CONFIG_DVB_LNBH25) += lnbh25.o 60 61 obj-$(CONFIG_DVB_LNBP21) += lnbp21.o 61 62 obj-$(CONFIG_DVB_LNBP22) += lnbp22.o 62 63 obj-$(CONFIG_DVB_ISL6405) += isl6405.o ··· 106 105 obj-$(CONFIG_DVB_IX2505V) += ix2505v.o 107 106 obj-$(CONFIG_DVB_STV0367) += stv0367.o 108 107 obj-$(CONFIG_DVB_CXD2820R) += cxd2820r.o 108 + obj-$(CONFIG_DVB_CXD2841ER) += cxd2841er.o 109 109 obj-$(CONFIG_DVB_DRXK) += drxk.o 110 110 obj-$(CONFIG_DVB_TDA18271C2DD) += tda18271c2dd.o 111 111 obj-$(CONFIG_DVB_SI2165) += si2165.o ··· 120 118 obj-$(CONFIG_DVB_AF9033) += af9033.o 121 119 obj-$(CONFIG_DVB_AS102_FE) += as102_fe.o 122 120 obj-$(CONFIG_DVB_TC90522) += tc90522.o 121 + obj-$(CONFIG_DVB_HORUS3A) += horus3a.o 122 + obj-$(CONFIG_DVB_ASCOT2E) += ascot2e.o
+29 -139
drivers/media/dvb-frontends/a8293.c
··· 12 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 14 * GNU General Public License for more details. 15 - * 16 - * You should have received a copy of the GNU General Public License along 17 - * with this program; if not, write to the Free Software Foundation, Inc., 18 - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 19 15 */ 20 16 21 - #include "dvb_frontend.h" 22 17 #include "a8293.h" 23 18 24 - struct a8293_priv { 25 - u8 i2c_addr; 26 - struct i2c_adapter *i2c; 19 + struct a8293_dev { 27 20 struct i2c_client *client; 28 21 u8 reg[2]; 29 22 }; 30 23 31 - static int a8293_i2c(struct a8293_priv *priv, u8 *val, int len, bool rd) 32 - { 33 - int ret; 34 - struct i2c_msg msg[1] = { 35 - { 36 - .addr = priv->i2c_addr, 37 - .len = len, 38 - .buf = val, 39 - } 40 - }; 41 - 42 - if (rd) 43 - msg[0].flags = I2C_M_RD; 44 - else 45 - msg[0].flags = 0; 46 - 47 - ret = i2c_transfer(priv->i2c, msg, 1); 48 - if (ret == 1) { 49 - ret = 0; 50 - } else { 51 - dev_warn(&priv->i2c->dev, "%s: i2c failed=%d rd=%d\n", 52 - KBUILD_MODNAME, ret, rd); 53 - ret = -EREMOTEIO; 54 - } 55 - 56 - return ret; 57 - } 58 - 59 - static int a8293_wr(struct a8293_priv *priv, u8 *val, int len) 60 - { 61 - return a8293_i2c(priv, val, len, 0); 62 - } 63 - 64 - static int a8293_rd(struct a8293_priv *priv, u8 *val, int len) 65 - { 66 - return a8293_i2c(priv, val, len, 1); 67 - } 68 - 69 24 static int a8293_set_voltage(struct dvb_frontend *fe, 70 - enum fe_sec_voltage fe_sec_voltage) 25 + enum fe_sec_voltage fe_sec_voltage) 71 26 { 72 - struct a8293_priv *priv = fe->sec_priv; 27 + struct a8293_dev *dev = fe->sec_priv; 28 + struct i2c_client *client = dev->client; 73 29 int ret; 30 + u8 reg0, reg1; 74 31 75 - dev_dbg(&priv->i2c->dev, "%s: fe_sec_voltage=%d\n", __func__, 76 - fe_sec_voltage); 32 + dev_dbg(&client->dev, "fe_sec_voltage=%d\n", fe_sec_voltage); 77 33 78 34 switch (fe_sec_voltage) { 79 35 case SEC_VOLTAGE_OFF: 80 36 /* ENB=0 */ 81 - priv->reg[0] = 0x10; 37 + reg0 = 0x10; 82 38 break; 83 39 case SEC_VOLTAGE_13: 84 40 /* VSEL0=1, VSEL1=0, VSEL2=0, VSEL3=0, ENB=1*/ 85 - priv->reg[0] = 0x31; 41 + reg0 = 0x31; 86 42 break; 87 43 case SEC_VOLTAGE_18: 88 44 /* VSEL0=0, VSEL1=0, VSEL2=0, VSEL3=1, ENB=1*/ 89 - priv->reg[0] = 0x38; 45 + reg0 = 0x38; 90 46 break; 91 47 default: 92 48 ret = -EINVAL; 93 49 goto err; 94 50 } 95 - 96 - ret = a8293_wr(priv, &priv->reg[0], 1); 97 - if (ret) 98 - goto err; 99 - 100 - usleep_range(1500, 50000); 101 - 102 - return ret; 103 - err: 104 - dev_dbg(&priv->i2c->dev, "%s: failed=%d\n", __func__, ret); 105 - return ret; 106 - } 107 - 108 - static void a8293_release_sec(struct dvb_frontend *fe) 109 - { 110 - a8293_set_voltage(fe, SEC_VOLTAGE_OFF); 111 - 112 - kfree(fe->sec_priv); 113 - fe->sec_priv = NULL; 114 - } 115 - 116 - struct dvb_frontend *a8293_attach(struct dvb_frontend *fe, 117 - struct i2c_adapter *i2c, const struct a8293_config *cfg) 118 - { 119 - int ret; 120 - struct a8293_priv *priv = NULL; 121 - u8 buf[2]; 122 - 123 - /* allocate memory for the internal priv */ 124 - priv = kzalloc(sizeof(struct a8293_priv), GFP_KERNEL); 125 - if (priv == NULL) { 126 - ret = -ENOMEM; 127 - goto err; 51 + if (reg0 != dev->reg[0]) { 52 + ret = i2c_master_send(client, &reg0, 1); 53 + if (ret < 0) 54 + goto err; 55 + dev->reg[0] = reg0; 128 56 } 129 57 130 - /* setup the priv */ 131 - priv->i2c = i2c; 132 - priv->i2c_addr = cfg->i2c_addr; 133 - fe->sec_priv = priv; 134 - 135 - /* check if the SEC is there */ 136 - ret = a8293_rd(priv, buf, 2); 137 - if (ret) 138 - goto err; 139 - 140 - /* ENB=0 */ 141 - priv->reg[0] = 0x10; 142 - ret = a8293_wr(priv, &priv->reg[0], 1); 143 - if (ret) 144 - goto err; 145 - 146 58 /* TMODE=0, TGATE=1 */ 147 - priv->reg[1] = 0x82; 148 - ret = a8293_wr(priv, &priv->reg[1], 1); 149 - if (ret) 150 - goto err; 59 + reg1 = 0x82; 60 + if (reg1 != dev->reg[1]) { 61 + ret = i2c_master_send(client, &reg1, 1); 62 + if (ret < 0) 63 + goto err; 64 + dev->reg[1] = reg1; 65 + } 151 66 152 - fe->ops.release_sec = a8293_release_sec; 153 - 154 - /* override frontend ops */ 155 - fe->ops.set_voltage = a8293_set_voltage; 156 - 157 - dev_info(&priv->i2c->dev, "%s: Allegro A8293 SEC attached\n", 158 - KBUILD_MODNAME); 159 - 160 - return fe; 67 + usleep_range(1500, 50000); 68 + return 0; 161 69 err: 162 - dev_dbg(&i2c->dev, "%s: failed=%d\n", __func__, ret); 163 - kfree(priv); 164 - return NULL; 70 + dev_dbg(&client->dev, "failed=%d\n", ret); 71 + return ret; 165 72 } 166 - EXPORT_SYMBOL(a8293_attach); 167 73 168 74 static int a8293_probe(struct i2c_client *client, 169 - const struct i2c_device_id *id) 75 + const struct i2c_device_id *id) 170 76 { 171 - struct a8293_priv *dev; 77 + struct a8293_dev *dev; 172 78 struct a8293_platform_data *pdata = client->dev.platform_data; 173 79 struct dvb_frontend *fe = pdata->dvb_frontend; 174 80 int ret; ··· 87 181 } 88 182 89 183 dev->client = client; 90 - dev->i2c = client->adapter; 91 - dev->i2c_addr = client->addr; 92 184 93 185 /* check if the SEC is there */ 94 - ret = a8293_rd(dev, buf, 2); 95 - if (ret) 96 - goto err_kfree; 97 - 98 - /* ENB=0 */ 99 - dev->reg[0] = 0x10; 100 - ret = a8293_wr(dev, &dev->reg[0], 1); 101 - if (ret) 102 - goto err_kfree; 103 - 104 - /* TMODE=0, TGATE=1 */ 105 - dev->reg[1] = 0x82; 106 - ret = a8293_wr(dev, &dev->reg[1], 1); 107 - if (ret) 186 + ret = i2c_master_recv(client, buf, 2); 187 + if (ret < 0) 108 188 goto err_kfree; 109 189 110 190 /* override frontend ops */ 111 191 fe->ops.set_voltage = a8293_set_voltage; 112 - 113 192 fe->sec_priv = dev; 114 193 i2c_set_clientdata(client, dev); 115 194 ··· 125 234 126 235 static struct i2c_driver a8293_driver = { 127 236 .driver = { 128 - .owner = THIS_MODULE, 129 237 .name = "a8293", 130 238 .suppress_bind_attrs = true, 131 239 },
-22
drivers/media/dvb-frontends/a8293.h
··· 12 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 14 * GNU General Public License for more details. 15 - * 16 - * You should have received a copy of the GNU General Public License along 17 - * with this program; if not, write to the Free Software Foundation, Inc., 18 - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 19 15 */ 20 16 21 17 #ifndef A8293_H 22 18 #define A8293_H 23 19 24 20 #include "dvb_frontend.h" 25 - #include <linux/kconfig.h> 26 21 27 22 /* 28 23 * I2C address ··· 31 36 struct a8293_platform_data { 32 37 struct dvb_frontend *dvb_frontend; 33 38 }; 34 - 35 - 36 - struct a8293_config { 37 - u8 i2c_addr; 38 - }; 39 - 40 - #if IS_REACHABLE(CONFIG_DVB_A8293) 41 - extern struct dvb_frontend *a8293_attach(struct dvb_frontend *fe, 42 - struct i2c_adapter *i2c, const struct a8293_config *cfg); 43 - #else 44 - static inline struct dvb_frontend *a8293_attach(struct dvb_frontend *fe, 45 - struct i2c_adapter *i2c, const struct a8293_config *cfg) 46 - { 47 - printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __func__); 48 - return NULL; 49 - } 50 - #endif 51 39 52 40 #endif /* A8293_H */
-1
drivers/media/dvb-frontends/af9033.c
··· 1387 1387 1388 1388 static struct i2c_driver af9033_driver = { 1389 1389 .driver = { 1390 - .owner = THIS_MODULE, 1391 1390 .name = "af9033", 1392 1391 }, 1393 1392 .probe = af9033_probe,
+548
drivers/media/dvb-frontends/ascot2e.c
··· 1 + /* 2 + * ascot2e.c 3 + * 4 + * Sony Ascot3E DVB-T/T2/C/C2 tuner driver 5 + * 6 + * Copyright 2012 Sony Corporation 7 + * Copyright (C) 2014 NetUP Inc. 8 + * Copyright (C) 2014 Sergey Kozlov <serjk@netup.ru> 9 + * Copyright (C) 2014 Abylay Ospan <aospan@netup.ru> 10 + * 11 + * This program is free software; you can redistribute it and/or modify 12 + * it under the terms of the GNU General Public License as published by 13 + * the Free Software Foundation; either version 2 of the License, or 14 + * (at your option) any later version. 15 + * 16 + * This program is distributed in the hope that it will be useful, 17 + * but WITHOUT ANY WARRANTY; without even the implied warranty of 18 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 + * GNU General Public License for more details. 20 + */ 21 + 22 + #include <linux/slab.h> 23 + #include <linux/module.h> 24 + #include <linux/dvb/frontend.h> 25 + #include <linux/types.h> 26 + #include "ascot2e.h" 27 + #include "dvb_frontend.h" 28 + 29 + #define MAX_WRITE_REGSIZE 10 30 + 31 + enum ascot2e_state { 32 + STATE_UNKNOWN, 33 + STATE_SLEEP, 34 + STATE_ACTIVE 35 + }; 36 + 37 + struct ascot2e_priv { 38 + u32 frequency; 39 + u8 i2c_address; 40 + struct i2c_adapter *i2c; 41 + enum ascot2e_state state; 42 + void *set_tuner_data; 43 + int (*set_tuner)(void *, int); 44 + }; 45 + 46 + enum ascot2e_tv_system_t { 47 + ASCOT2E_DTV_DVBT_5, 48 + ASCOT2E_DTV_DVBT_6, 49 + ASCOT2E_DTV_DVBT_7, 50 + ASCOT2E_DTV_DVBT_8, 51 + ASCOT2E_DTV_DVBT2_1_7, 52 + ASCOT2E_DTV_DVBT2_5, 53 + ASCOT2E_DTV_DVBT2_6, 54 + ASCOT2E_DTV_DVBT2_7, 55 + ASCOT2E_DTV_DVBT2_8, 56 + ASCOT2E_DTV_DVBC_6, 57 + ASCOT2E_DTV_DVBC_8, 58 + ASCOT2E_DTV_DVBC2_6, 59 + ASCOT2E_DTV_DVBC2_8, 60 + ASCOT2E_DTV_UNKNOWN 61 + }; 62 + 63 + struct ascot2e_band_sett { 64 + u8 if_out_sel; 65 + u8 agc_sel; 66 + u8 mix_oll; 67 + u8 rf_gain; 68 + u8 if_bpf_gc; 69 + u8 fif_offset; 70 + u8 bw_offset; 71 + u8 bw; 72 + u8 rf_oldet; 73 + u8 if_bpf_f0; 74 + }; 75 + 76 + #define ASCOT2E_AUTO 0xff 77 + #define ASCOT2E_OFFSET(ofs) ((u8)(ofs) & 0x1F) 78 + #define ASCOT2E_BW_6 0x00 79 + #define ASCOT2E_BW_7 0x01 80 + #define ASCOT2E_BW_8 0x02 81 + #define ASCOT2E_BW_1_7 0x03 82 + 83 + static struct ascot2e_band_sett ascot2e_sett[] = { 84 + { ASCOT2E_AUTO, ASCOT2E_AUTO, 0x03, ASCOT2E_AUTO, 0x06, 85 + ASCOT2E_OFFSET(-8), ASCOT2E_OFFSET(-6), ASCOT2E_BW_6, 0x0B, 0x00 }, 86 + { ASCOT2E_AUTO, ASCOT2E_AUTO, 0x03, ASCOT2E_AUTO, 0x06, 87 + ASCOT2E_OFFSET(-8), ASCOT2E_OFFSET(-6), ASCOT2E_BW_6, 0x0B, 0x00 }, 88 + { ASCOT2E_AUTO, ASCOT2E_AUTO, 0x03, ASCOT2E_AUTO, 0x06, 89 + ASCOT2E_OFFSET(-6), ASCOT2E_OFFSET(-4), ASCOT2E_BW_7, 0x0B, 0x00 }, 90 + { ASCOT2E_AUTO, ASCOT2E_AUTO, 0x03, ASCOT2E_AUTO, 0x06, 91 + ASCOT2E_OFFSET(-4), ASCOT2E_OFFSET(-2), ASCOT2E_BW_8, 0x0B, 0x00 }, 92 + { ASCOT2E_AUTO, ASCOT2E_AUTO, 0x03, ASCOT2E_AUTO, 0x06, 93 + ASCOT2E_OFFSET(-10), ASCOT2E_OFFSET(-16), ASCOT2E_BW_1_7, 0x0B, 0x00 }, 94 + { ASCOT2E_AUTO, ASCOT2E_AUTO, 0x03, ASCOT2E_AUTO, 0x06, 95 + ASCOT2E_OFFSET(-8), ASCOT2E_OFFSET(-6), ASCOT2E_BW_6, 0x0B, 0x00 }, 96 + { ASCOT2E_AUTO, ASCOT2E_AUTO, 0x03, ASCOT2E_AUTO, 0x06, 97 + ASCOT2E_OFFSET(-8), ASCOT2E_OFFSET(-6), ASCOT2E_BW_6, 0x0B, 0x00 }, 98 + { ASCOT2E_AUTO, ASCOT2E_AUTO, 0x03, ASCOT2E_AUTO, 0x06, 99 + ASCOT2E_OFFSET(-6), ASCOT2E_OFFSET(-4), ASCOT2E_BW_7, 0x0B, 0x00 }, 100 + { ASCOT2E_AUTO, ASCOT2E_AUTO, 0x03, ASCOT2E_AUTO, 0x06, 101 + ASCOT2E_OFFSET(-4), ASCOT2E_OFFSET(-2), ASCOT2E_BW_8, 0x0B, 0x00 }, 102 + { ASCOT2E_AUTO, ASCOT2E_AUTO, 0x02, ASCOT2E_AUTO, 0x03, 103 + ASCOT2E_OFFSET(-6), ASCOT2E_OFFSET(-8), ASCOT2E_BW_6, 0x09, 0x00 }, 104 + { ASCOT2E_AUTO, ASCOT2E_AUTO, 0x02, ASCOT2E_AUTO, 0x03, 105 + ASCOT2E_OFFSET(-2), ASCOT2E_OFFSET(-1), ASCOT2E_BW_8, 0x09, 0x00 }, 106 + { ASCOT2E_AUTO, ASCOT2E_AUTO, 0x03, ASCOT2E_AUTO, 0x01, 107 + ASCOT2E_OFFSET(-6), ASCOT2E_OFFSET(-4), ASCOT2E_BW_6, 0x09, 0x00 }, 108 + { ASCOT2E_AUTO, ASCOT2E_AUTO, 0x03, ASCOT2E_AUTO, 0x01, 109 + ASCOT2E_OFFSET(-2), ASCOT2E_OFFSET(2), ASCOT2E_BW_8, 0x09, 0x00 } 110 + }; 111 + 112 + static void ascot2e_i2c_debug(struct ascot2e_priv *priv, 113 + u8 reg, u8 write, const u8 *data, u32 len) 114 + { 115 + dev_dbg(&priv->i2c->dev, "ascot2e: I2C %s reg 0x%02x size %d\n", 116 + (write == 0 ? "read" : "write"), reg, len); 117 + print_hex_dump_bytes("ascot2e: I2C data: ", 118 + DUMP_PREFIX_OFFSET, data, len); 119 + } 120 + 121 + static int ascot2e_write_regs(struct ascot2e_priv *priv, 122 + u8 reg, const u8 *data, u32 len) 123 + { 124 + int ret; 125 + u8 buf[MAX_WRITE_REGSIZE + 1]; 126 + struct i2c_msg msg[1] = { 127 + { 128 + .addr = priv->i2c_address, 129 + .flags = 0, 130 + .len = len + 1, 131 + .buf = buf, 132 + } 133 + }; 134 + 135 + if (len + 1 >= sizeof(buf)) { 136 + dev_warn(&priv->i2c->dev,"wr reg=%04x: len=%d is too big!\n", 137 + reg, len + 1); 138 + return -E2BIG; 139 + } 140 + 141 + ascot2e_i2c_debug(priv, reg, 1, data, len); 142 + buf[0] = reg; 143 + memcpy(&buf[1], data, len); 144 + ret = i2c_transfer(priv->i2c, msg, 1); 145 + if (ret >= 0 && ret != 1) 146 + ret = -EREMOTEIO; 147 + if (ret < 0) { 148 + dev_warn(&priv->i2c->dev, 149 + "%s: i2c wr failed=%d reg=%02x len=%d\n", 150 + KBUILD_MODNAME, ret, reg, len); 151 + return ret; 152 + } 153 + return 0; 154 + } 155 + 156 + static int ascot2e_write_reg(struct ascot2e_priv *priv, u8 reg, u8 val) 157 + { 158 + return ascot2e_write_regs(priv, reg, &val, 1); 159 + } 160 + 161 + static int ascot2e_read_regs(struct ascot2e_priv *priv, 162 + u8 reg, u8 *val, u32 len) 163 + { 164 + int ret; 165 + struct i2c_msg msg[2] = { 166 + { 167 + .addr = priv->i2c_address, 168 + .flags = 0, 169 + .len = 1, 170 + .buf = &reg, 171 + }, { 172 + .addr = priv->i2c_address, 173 + .flags = I2C_M_RD, 174 + .len = len, 175 + .buf = val, 176 + } 177 + }; 178 + 179 + ret = i2c_transfer(priv->i2c, &msg[0], 1); 180 + if (ret >= 0 && ret != 1) 181 + ret = -EREMOTEIO; 182 + if (ret < 0) { 183 + dev_warn(&priv->i2c->dev, 184 + "%s: I2C rw failed=%d addr=%02x reg=%02x\n", 185 + KBUILD_MODNAME, ret, priv->i2c_address, reg); 186 + return ret; 187 + } 188 + ret = i2c_transfer(priv->i2c, &msg[1], 1); 189 + if (ret >= 0 && ret != 1) 190 + ret = -EREMOTEIO; 191 + if (ret < 0) { 192 + dev_warn(&priv->i2c->dev, 193 + "%s: i2c rd failed=%d addr=%02x reg=%02x\n", 194 + KBUILD_MODNAME, ret, priv->i2c_address, reg); 195 + return ret; 196 + } 197 + ascot2e_i2c_debug(priv, reg, 0, val, len); 198 + return 0; 199 + } 200 + 201 + static int ascot2e_read_reg(struct ascot2e_priv *priv, u8 reg, u8 *val) 202 + { 203 + return ascot2e_read_regs(priv, reg, val, 1); 204 + } 205 + 206 + static int ascot2e_set_reg_bits(struct ascot2e_priv *priv, 207 + u8 reg, u8 data, u8 mask) 208 + { 209 + int res; 210 + u8 rdata; 211 + 212 + if (mask != 0xff) { 213 + res = ascot2e_read_reg(priv, reg, &rdata); 214 + if (res != 0) 215 + return res; 216 + data = ((data & mask) | (rdata & (mask ^ 0xFF))); 217 + } 218 + return ascot2e_write_reg(priv, reg, data); 219 + } 220 + 221 + static int ascot2e_enter_power_save(struct ascot2e_priv *priv) 222 + { 223 + u8 data[2]; 224 + 225 + dev_dbg(&priv->i2c->dev, "%s()\n", __func__); 226 + if (priv->state == STATE_SLEEP) 227 + return 0; 228 + data[0] = 0x00; 229 + data[1] = 0x04; 230 + ascot2e_write_regs(priv, 0x14, data, 2); 231 + ascot2e_write_reg(priv, 0x50, 0x01); 232 + priv->state = STATE_SLEEP; 233 + return 0; 234 + } 235 + 236 + static int ascot2e_leave_power_save(struct ascot2e_priv *priv) 237 + { 238 + u8 data[2] = { 0xFB, 0x0F }; 239 + 240 + dev_dbg(&priv->i2c->dev, "%s()\n", __func__); 241 + if (priv->state == STATE_ACTIVE) 242 + return 0; 243 + ascot2e_write_regs(priv, 0x14, data, 2); 244 + ascot2e_write_reg(priv, 0x50, 0x00); 245 + priv->state = STATE_ACTIVE; 246 + return 0; 247 + } 248 + 249 + static int ascot2e_init(struct dvb_frontend *fe) 250 + { 251 + struct ascot2e_priv *priv = fe->tuner_priv; 252 + 253 + dev_dbg(&priv->i2c->dev, "%s()\n", __func__); 254 + return ascot2e_leave_power_save(priv); 255 + } 256 + 257 + static int ascot2e_release(struct dvb_frontend *fe) 258 + { 259 + struct ascot2e_priv *priv = fe->tuner_priv; 260 + 261 + dev_dbg(&priv->i2c->dev, "%s()\n", __func__); 262 + kfree(fe->tuner_priv); 263 + fe->tuner_priv = NULL; 264 + return 0; 265 + } 266 + 267 + static int ascot2e_sleep(struct dvb_frontend *fe) 268 + { 269 + struct ascot2e_priv *priv = fe->tuner_priv; 270 + 271 + dev_dbg(&priv->i2c->dev, "%s()\n", __func__); 272 + ascot2e_enter_power_save(priv); 273 + return 0; 274 + } 275 + 276 + static enum ascot2e_tv_system_t ascot2e_get_tv_system(struct dvb_frontend *fe) 277 + { 278 + enum ascot2e_tv_system_t system = ASCOT2E_DTV_UNKNOWN; 279 + struct dtv_frontend_properties *p = &fe->dtv_property_cache; 280 + struct ascot2e_priv *priv = fe->tuner_priv; 281 + 282 + if (p->delivery_system == SYS_DVBT) { 283 + if (p->bandwidth_hz <= 5000000) 284 + system = ASCOT2E_DTV_DVBT_5; 285 + else if (p->bandwidth_hz <= 6000000) 286 + system = ASCOT2E_DTV_DVBT_6; 287 + else if (p->bandwidth_hz <= 7000000) 288 + system = ASCOT2E_DTV_DVBT_7; 289 + else if (p->bandwidth_hz <= 8000000) 290 + system = ASCOT2E_DTV_DVBT_8; 291 + else { 292 + system = ASCOT2E_DTV_DVBT_8; 293 + p->bandwidth_hz = 8000000; 294 + } 295 + } else if (p->delivery_system == SYS_DVBT2) { 296 + if (p->bandwidth_hz <= 5000000) 297 + system = ASCOT2E_DTV_DVBT2_5; 298 + else if (p->bandwidth_hz <= 6000000) 299 + system = ASCOT2E_DTV_DVBT2_6; 300 + else if (p->bandwidth_hz <= 7000000) 301 + system = ASCOT2E_DTV_DVBT2_7; 302 + else if (p->bandwidth_hz <= 8000000) 303 + system = ASCOT2E_DTV_DVBT2_8; 304 + else { 305 + system = ASCOT2E_DTV_DVBT2_8; 306 + p->bandwidth_hz = 8000000; 307 + } 308 + } else if (p->delivery_system == SYS_DVBC_ANNEX_A) { 309 + if (p->bandwidth_hz <= 6000000) 310 + system = ASCOT2E_DTV_DVBC_6; 311 + else if (p->bandwidth_hz <= 8000000) 312 + system = ASCOT2E_DTV_DVBC_8; 313 + } 314 + dev_dbg(&priv->i2c->dev, 315 + "%s(): ASCOT2E DTV system %d (delsys %d, bandwidth %d)\n", 316 + __func__, (int)system, p->delivery_system, p->bandwidth_hz); 317 + return system; 318 + } 319 + 320 + static int ascot2e_set_params(struct dvb_frontend *fe) 321 + { 322 + u8 data[10]; 323 + u32 frequency; 324 + enum ascot2e_tv_system_t tv_system; 325 + struct dtv_frontend_properties *p = &fe->dtv_property_cache; 326 + struct ascot2e_priv *priv = fe->tuner_priv; 327 + 328 + dev_dbg(&priv->i2c->dev, "%s(): tune frequency %dkHz\n", 329 + __func__, p->frequency / 1000); 330 + tv_system = ascot2e_get_tv_system(fe); 331 + 332 + if (tv_system == ASCOT2E_DTV_UNKNOWN) { 333 + dev_dbg(&priv->i2c->dev, "%s(): unknown DTV system\n", 334 + __func__); 335 + return -EINVAL; 336 + } 337 + if (priv->set_tuner) 338 + priv->set_tuner(priv->set_tuner_data, 1); 339 + frequency = roundup(p->frequency / 1000, 25); 340 + if (priv->state == STATE_SLEEP) 341 + ascot2e_leave_power_save(priv); 342 + 343 + /* IF_OUT_SEL / AGC_SEL setting */ 344 + data[0] = 0x00; 345 + if (ascot2e_sett[tv_system].agc_sel != ASCOT2E_AUTO) { 346 + /* AGC pin setting from parameter table */ 347 + data[0] |= (u8)( 348 + (ascot2e_sett[tv_system].agc_sel & 0x03) << 3); 349 + } 350 + if (ascot2e_sett[tv_system].if_out_sel != ASCOT2E_AUTO) { 351 + /* IFOUT pin setting from parameter table */ 352 + data[0] |= (u8)( 353 + (ascot2e_sett[tv_system].if_out_sel & 0x01) << 2); 354 + } 355 + /* Set bit[4:2] only */ 356 + ascot2e_set_reg_bits(priv, 0x05, data[0], 0x1c); 357 + /* 0x06 - 0x0F */ 358 + /* REF_R setting (0x06) */ 359 + if (tv_system == ASCOT2E_DTV_DVBC_6 || 360 + tv_system == ASCOT2E_DTV_DVBC_8) { 361 + /* xtal, xtal*2 */ 362 + data[0] = (frequency > 500000) ? 16 : 32; 363 + } else { 364 + /* xtal/8, xtal/4 */ 365 + data[0] = (frequency > 500000) ? 2 : 4; 366 + } 367 + /* XOSC_SEL=100uA */ 368 + data[1] = 0x04; 369 + /* KBW setting (0x08), KC0 setting (0x09), KC1 setting (0x0A) */ 370 + if (tv_system == ASCOT2E_DTV_DVBC_6 || 371 + tv_system == ASCOT2E_DTV_DVBC_8) { 372 + data[2] = 18; 373 + data[3] = 120; 374 + data[4] = 20; 375 + } else { 376 + data[2] = 48; 377 + data[3] = 10; 378 + data[4] = 30; 379 + } 380 + /* ORDER/R2_RANGE/R2_BANK/C2_BANK setting (0x0B) */ 381 + if (tv_system == ASCOT2E_DTV_DVBC_6 || 382 + tv_system == ASCOT2E_DTV_DVBC_8) 383 + data[5] = (frequency > 500000) ? 0x08 : 0x0c; 384 + else 385 + data[5] = (frequency > 500000) ? 0x30 : 0x38; 386 + /* Set MIX_OLL (0x0C) value from parameter table */ 387 + data[6] = ascot2e_sett[tv_system].mix_oll; 388 + /* Set RF_GAIN (0x0D) setting from parameter table */ 389 + if (ascot2e_sett[tv_system].rf_gain == ASCOT2E_AUTO) { 390 + /* RF_GAIN auto control enable */ 391 + ascot2e_write_reg(priv, 0x4E, 0x01); 392 + /* RF_GAIN Default value */ 393 + data[7] = 0x00; 394 + } else { 395 + /* RF_GAIN auto control disable */ 396 + ascot2e_write_reg(priv, 0x4E, 0x00); 397 + data[7] = ascot2e_sett[tv_system].rf_gain; 398 + } 399 + /* Set IF_BPF_GC/FIF_OFFSET (0x0E) value from parameter table */ 400 + data[8] = (u8)((ascot2e_sett[tv_system].fif_offset << 3) | 401 + (ascot2e_sett[tv_system].if_bpf_gc & 0x07)); 402 + /* Set BW_OFFSET (0x0F) value from parameter table */ 403 + data[9] = ascot2e_sett[tv_system].bw_offset; 404 + ascot2e_write_regs(priv, 0x06, data, 10); 405 + /* 406 + * 0x45 - 0x47 407 + * LNA optimization setting 408 + * RF_LNA_DIST1-5, RF_LNA_CM 409 + */ 410 + if (tv_system == ASCOT2E_DTV_DVBC_6 || 411 + tv_system == ASCOT2E_DTV_DVBC_8) { 412 + data[0] = 0x0F; 413 + data[1] = 0x00; 414 + data[2] = 0x01; 415 + } else { 416 + data[0] = 0x0F; 417 + data[1] = 0x00; 418 + data[2] = 0x03; 419 + } 420 + ascot2e_write_regs(priv, 0x45, data, 3); 421 + /* 0x49 - 0x4A 422 + Set RF_OLDET_ENX/RF_OLDET_OLL value from parameter table */ 423 + data[0] = ascot2e_sett[tv_system].rf_oldet; 424 + /* Set IF_BPF_F0 value from parameter table */ 425 + data[1] = ascot2e_sett[tv_system].if_bpf_f0; 426 + ascot2e_write_regs(priv, 0x49, data, 2); 427 + /* 428 + * Tune now 429 + * RFAGC fast mode / RFAGC auto control enable 430 + * (set bit[7], bit[5:4] only) 431 + * vco_cal = 1, set MIX_OL_CPU_EN 432 + */ 433 + ascot2e_set_reg_bits(priv, 0x0c, 0x90, 0xb0); 434 + /* Logic wake up, CPU wake up */ 435 + data[0] = 0xc4; 436 + data[1] = 0x40; 437 + ascot2e_write_regs(priv, 0x03, data, 2); 438 + /* 0x10 - 0x14 */ 439 + data[0] = (u8)(frequency & 0xFF); /* 0x10: FRF_L */ 440 + data[1] = (u8)((frequency >> 8) & 0xFF); /* 0x11: FRF_M */ 441 + data[2] = (u8)((frequency >> 16) & 0x0F); /* 0x12: FRF_H (bit[3:0]) */ 442 + /* 0x12: BW (bit[5:4]) */ 443 + data[2] |= (u8)(ascot2e_sett[tv_system].bw << 4); 444 + data[3] = 0xFF; /* 0x13: VCO calibration enable */ 445 + data[4] = 0xFF; /* 0x14: Analog block enable */ 446 + /* Tune (Burst write) */ 447 + ascot2e_write_regs(priv, 0x10, data, 5); 448 + msleep(50); 449 + /* CPU deep sleep */ 450 + ascot2e_write_reg(priv, 0x04, 0x00); 451 + /* Logic sleep */ 452 + ascot2e_write_reg(priv, 0x03, 0xC0); 453 + /* RFAGC normal mode (set bit[5:4] only) */ 454 + ascot2e_set_reg_bits(priv, 0x0C, 0x00, 0x30); 455 + priv->frequency = frequency; 456 + return 0; 457 + } 458 + 459 + static int ascot2e_get_frequency(struct dvb_frontend *fe, u32 *frequency) 460 + { 461 + struct ascot2e_priv *priv = fe->tuner_priv; 462 + 463 + *frequency = priv->frequency * 1000; 464 + return 0; 465 + } 466 + 467 + static struct dvb_tuner_ops ascot2e_tuner_ops = { 468 + .info = { 469 + .name = "Sony ASCOT2E", 470 + .frequency_min = 1000000, 471 + .frequency_max = 1200000000, 472 + .frequency_step = 25000, 473 + }, 474 + .init = ascot2e_init, 475 + .release = ascot2e_release, 476 + .sleep = ascot2e_sleep, 477 + .set_params = ascot2e_set_params, 478 + .get_frequency = ascot2e_get_frequency, 479 + }; 480 + 481 + struct dvb_frontend *ascot2e_attach(struct dvb_frontend *fe, 482 + const struct ascot2e_config *config, 483 + struct i2c_adapter *i2c) 484 + { 485 + u8 data[4]; 486 + struct ascot2e_priv *priv = NULL; 487 + 488 + priv = kzalloc(sizeof(struct ascot2e_priv), GFP_KERNEL); 489 + if (priv == NULL) 490 + return NULL; 491 + priv->i2c_address = (config->i2c_address >> 1); 492 + priv->i2c = i2c; 493 + priv->set_tuner_data = config->set_tuner_priv; 494 + priv->set_tuner = config->set_tuner_callback; 495 + 496 + if (fe->ops.i2c_gate_ctrl) 497 + fe->ops.i2c_gate_ctrl(fe, 1); 498 + 499 + /* 16 MHz xTal frequency */ 500 + data[0] = 16; 501 + /* VCO current setting */ 502 + data[1] = 0x06; 503 + /* Logic wake up, CPU boot */ 504 + data[2] = 0xC4; 505 + data[3] = 0x40; 506 + ascot2e_write_regs(priv, 0x01, data, 4); 507 + /* RFVGA optimization setting (RF_DIST0 - RF_DIST2) */ 508 + data[0] = 0x10; 509 + data[1] = 0x3F; 510 + data[2] = 0x25; 511 + ascot2e_write_regs(priv, 0x22, data, 3); 512 + /* PLL mode setting */ 513 + ascot2e_write_reg(priv, 0x28, 0x1e); 514 + /* RSSI setting */ 515 + ascot2e_write_reg(priv, 0x59, 0x04); 516 + /* TODO check CPU HW error state here */ 517 + msleep(80); 518 + /* Xtal oscillator current control setting */ 519 + ascot2e_write_reg(priv, 0x4c, 0x01); 520 + /* XOSC_SEL=100uA */ 521 + ascot2e_write_reg(priv, 0x07, 0x04); 522 + /* CPU deep sleep */ 523 + ascot2e_write_reg(priv, 0x04, 0x00); 524 + /* Logic sleep */ 525 + ascot2e_write_reg(priv, 0x03, 0xc0); 526 + /* Power save setting */ 527 + data[0] = 0x00; 528 + data[1] = 0x04; 529 + ascot2e_write_regs(priv, 0x14, data, 2); 530 + ascot2e_write_reg(priv, 0x50, 0x01); 531 + priv->state = STATE_SLEEP; 532 + 533 + if (fe->ops.i2c_gate_ctrl) 534 + fe->ops.i2c_gate_ctrl(fe, 0); 535 + 536 + memcpy(&fe->ops.tuner_ops, &ascot2e_tuner_ops, 537 + sizeof(struct dvb_tuner_ops)); 538 + fe->tuner_priv = priv; 539 + dev_info(&priv->i2c->dev, 540 + "Sony ASCOT2E attached on addr=%x at I2C adapter %p\n", 541 + priv->i2c_address, priv->i2c); 542 + return fe; 543 + } 544 + EXPORT_SYMBOL(ascot2e_attach); 545 + 546 + MODULE_DESCRIPTION("Sony ASCOT2E terr/cab tuner driver"); 547 + MODULE_AUTHOR("info@netup.ru"); 548 + MODULE_LICENSE("GPL");
+58
drivers/media/dvb-frontends/ascot2e.h
··· 1 + /* 2 + * ascot2e.h 3 + * 4 + * Sony Ascot3E DVB-T/T2/C/C2 tuner driver 5 + * 6 + * Copyright 2012 Sony Corporation 7 + * Copyright (C) 2014 NetUP Inc. 8 + * Copyright (C) 2014 Sergey Kozlov <serjk@netup.ru> 9 + * Copyright (C) 2014 Abylay Ospan <aospan@netup.ru> 10 + * 11 + * This program is free software; you can redistribute it and/or modify 12 + * it under the terms of the GNU General Public License as published by 13 + * the Free Software Foundation; either version 2 of the License, or 14 + * (at your option) any later version. 15 + * 16 + * This program is distributed in the hope that it will be useful, 17 + * but WITHOUT ANY WARRANTY; without even the implied warranty of 18 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 + * GNU General Public License for more details. 20 + */ 21 + 22 + #ifndef __DVB_ASCOT2E_H__ 23 + #define __DVB_ASCOT2E_H__ 24 + 25 + #include <linux/kconfig.h> 26 + #include <linux/dvb/frontend.h> 27 + #include <linux/i2c.h> 28 + 29 + /** 30 + * struct ascot2e_config - the configuration of Ascot2E tuner driver 31 + * @i2c_address: I2C address of the tuner 32 + * @xtal_freq_mhz: Oscillator frequency, MHz 33 + * @set_tuner_priv: Callback function private context 34 + * @set_tuner_callback: Callback function that notifies the parent driver 35 + * which tuner is active now 36 + */ 37 + struct ascot2e_config { 38 + u8 i2c_address; 39 + u8 xtal_freq_mhz; 40 + void *set_tuner_priv; 41 + int (*set_tuner_callback)(void *, int); 42 + }; 43 + 44 + #if IS_REACHABLE(CONFIG_DVB_ASCOT2E) 45 + extern struct dvb_frontend *ascot2e_attach(struct dvb_frontend *fe, 46 + const struct ascot2e_config *config, 47 + struct i2c_adapter *i2c); 48 + #else 49 + static inline struct dvb_frontend *ascot2e_attach(struct dvb_frontend *fe, 50 + const struct ascot2e_config *config, 51 + struct i2c_adapter *i2c) 52 + { 53 + printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __func__); 54 + return NULL; 55 + } 56 + #endif 57 + 58 + #endif
-1
drivers/media/dvb-frontends/au8522_decoder.c
··· 820 820 821 821 static struct i2c_driver au8522_driver = { 822 822 .driver = { 823 - .owner = THIS_MODULE, 824 823 .name = "au8522", 825 824 }, 826 825 .probe = au8522_probe,
+1 -1
drivers/media/dvb-frontends/cx24123.c
··· 1011 1011 1012 1012 static int cx24123_get_algo(struct dvb_frontend *fe) 1013 1013 { 1014 - return 1; /* FE_ALGO_HW */ 1014 + return DVBFE_ALGO_HW; 1015 1015 } 1016 1016 1017 1017 static void cx24123_release(struct dvb_frontend *fe)
+2727
drivers/media/dvb-frontends/cxd2841er.c
··· 1 + /* 2 + * cxd2841er.c 3 + * 4 + * Sony CXD2441ER digital demodulator driver 5 + * 6 + * Copyright 2012 Sony Corporation 7 + * Copyright (C) 2014 NetUP Inc. 8 + * Copyright (C) 2014 Sergey Kozlov <serjk@netup.ru> 9 + * Copyright (C) 2014 Abylay Ospan <aospan@netup.ru> 10 + * 11 + * This program is free software; you can redistribute it and/or modify 12 + * it under the terms of the GNU General Public License as published by 13 + * the Free Software Foundation; either version 2 of the License, or 14 + * (at your option) any later version. 15 + * 16 + * This program is distributed in the hope that it will be useful, 17 + * but WITHOUT ANY WARRANTY; without even the implied warranty of 18 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 + * GNU General Public License for more details. 20 + */ 21 + 22 + #include <linux/module.h> 23 + #include <linux/init.h> 24 + #include <linux/string.h> 25 + #include <linux/slab.h> 26 + #include <linux/bitops.h> 27 + #include <linux/math64.h> 28 + #include <linux/log2.h> 29 + #include <linux/dynamic_debug.h> 30 + 31 + #include "dvb_math.h" 32 + #include "dvb_frontend.h" 33 + #include "cxd2841er.h" 34 + #include "cxd2841er_priv.h" 35 + 36 + #define MAX_WRITE_REGSIZE 16 37 + 38 + enum cxd2841er_state { 39 + STATE_SHUTDOWN = 0, 40 + STATE_SLEEP_S, 41 + STATE_ACTIVE_S, 42 + STATE_SLEEP_TC, 43 + STATE_ACTIVE_TC 44 + }; 45 + 46 + struct cxd2841er_priv { 47 + struct dvb_frontend frontend; 48 + struct i2c_adapter *i2c; 49 + u8 i2c_addr_slvx; 50 + u8 i2c_addr_slvt; 51 + const struct cxd2841er_config *config; 52 + enum cxd2841er_state state; 53 + u8 system; 54 + }; 55 + 56 + static const struct cxd2841er_cnr_data s_cn_data[] = { 57 + { 0x033e, 0 }, { 0x0339, 100 }, { 0x0333, 200 }, 58 + { 0x032e, 300 }, { 0x0329, 400 }, { 0x0324, 500 }, 59 + { 0x031e, 600 }, { 0x0319, 700 }, { 0x0314, 800 }, 60 + { 0x030f, 900 }, { 0x030a, 1000 }, { 0x02ff, 1100 }, 61 + { 0x02f4, 1200 }, { 0x02e9, 1300 }, { 0x02de, 1400 }, 62 + { 0x02d4, 1500 }, { 0x02c9, 1600 }, { 0x02bf, 1700 }, 63 + { 0x02b5, 1800 }, { 0x02ab, 1900 }, { 0x02a1, 2000 }, 64 + { 0x029b, 2100 }, { 0x0295, 2200 }, { 0x0290, 2300 }, 65 + { 0x028a, 2400 }, { 0x0284, 2500 }, { 0x027f, 2600 }, 66 + { 0x0279, 2700 }, { 0x0274, 2800 }, { 0x026e, 2900 }, 67 + { 0x0269, 3000 }, { 0x0262, 3100 }, { 0x025c, 3200 }, 68 + { 0x0255, 3300 }, { 0x024f, 3400 }, { 0x0249, 3500 }, 69 + { 0x0242, 3600 }, { 0x023c, 3700 }, { 0x0236, 3800 }, 70 + { 0x0230, 3900 }, { 0x022a, 4000 }, { 0x0223, 4100 }, 71 + { 0x021c, 4200 }, { 0x0215, 4300 }, { 0x020e, 4400 }, 72 + { 0x0207, 4500 }, { 0x0201, 4600 }, { 0x01fa, 4700 }, 73 + { 0x01f4, 4800 }, { 0x01ed, 4900 }, { 0x01e7, 5000 }, 74 + { 0x01e0, 5100 }, { 0x01d9, 5200 }, { 0x01d2, 5300 }, 75 + { 0x01cb, 5400 }, { 0x01c4, 5500 }, { 0x01be, 5600 }, 76 + { 0x01b7, 5700 }, { 0x01b1, 5800 }, { 0x01aa, 5900 }, 77 + { 0x01a4, 6000 }, { 0x019d, 6100 }, { 0x0196, 6200 }, 78 + { 0x018f, 6300 }, { 0x0189, 6400 }, { 0x0182, 6500 }, 79 + { 0x017c, 6600 }, { 0x0175, 6700 }, { 0x016f, 6800 }, 80 + { 0x0169, 6900 }, { 0x0163, 7000 }, { 0x015c, 7100 }, 81 + { 0x0156, 7200 }, { 0x0150, 7300 }, { 0x014a, 7400 }, 82 + { 0x0144, 7500 }, { 0x013e, 7600 }, { 0x0138, 7700 }, 83 + { 0x0132, 7800 }, { 0x012d, 7900 }, { 0x0127, 8000 }, 84 + { 0x0121, 8100 }, { 0x011c, 8200 }, { 0x0116, 8300 }, 85 + { 0x0111, 8400 }, { 0x010b, 8500 }, { 0x0106, 8600 }, 86 + { 0x0101, 8700 }, { 0x00fc, 8800 }, { 0x00f7, 8900 }, 87 + { 0x00f2, 9000 }, { 0x00ee, 9100 }, { 0x00ea, 9200 }, 88 + { 0x00e6, 9300 }, { 0x00e2, 9400 }, { 0x00de, 9500 }, 89 + { 0x00da, 9600 }, { 0x00d7, 9700 }, { 0x00d3, 9800 }, 90 + { 0x00d0, 9900 }, { 0x00cc, 10000 }, { 0x00c7, 10100 }, 91 + { 0x00c3, 10200 }, { 0x00bf, 10300 }, { 0x00ba, 10400 }, 92 + { 0x00b6, 10500 }, { 0x00b2, 10600 }, { 0x00ae, 10700 }, 93 + { 0x00aa, 10800 }, { 0x00a7, 10900 }, { 0x00a3, 11000 }, 94 + { 0x009f, 11100 }, { 0x009c, 11200 }, { 0x0098, 11300 }, 95 + { 0x0094, 11400 }, { 0x0091, 11500 }, { 0x008e, 11600 }, 96 + { 0x008a, 11700 }, { 0x0087, 11800 }, { 0x0084, 11900 }, 97 + { 0x0081, 12000 }, { 0x007e, 12100 }, { 0x007b, 12200 }, 98 + { 0x0079, 12300 }, { 0x0076, 12400 }, { 0x0073, 12500 }, 99 + { 0x0071, 12600 }, { 0x006e, 12700 }, { 0x006c, 12800 }, 100 + { 0x0069, 12900 }, { 0x0067, 13000 }, { 0x0065, 13100 }, 101 + { 0x0062, 13200 }, { 0x0060, 13300 }, { 0x005e, 13400 }, 102 + { 0x005c, 13500 }, { 0x005a, 13600 }, { 0x0058, 13700 }, 103 + { 0x0056, 13800 }, { 0x0054, 13900 }, { 0x0052, 14000 }, 104 + { 0x0050, 14100 }, { 0x004e, 14200 }, { 0x004c, 14300 }, 105 + { 0x004b, 14400 }, { 0x0049, 14500 }, { 0x0047, 14600 }, 106 + { 0x0046, 14700 }, { 0x0044, 14800 }, { 0x0043, 14900 }, 107 + { 0x0041, 15000 }, { 0x003f, 15100 }, { 0x003e, 15200 }, 108 + { 0x003c, 15300 }, { 0x003b, 15400 }, { 0x003a, 15500 }, 109 + { 0x0037, 15700 }, { 0x0036, 15800 }, { 0x0034, 15900 }, 110 + { 0x0033, 16000 }, { 0x0032, 16100 }, { 0x0031, 16200 }, 111 + { 0x0030, 16300 }, { 0x002f, 16400 }, { 0x002e, 16500 }, 112 + { 0x002d, 16600 }, { 0x002c, 16700 }, { 0x002b, 16800 }, 113 + { 0x002a, 16900 }, { 0x0029, 17000 }, { 0x0028, 17100 }, 114 + { 0x0027, 17200 }, { 0x0026, 17300 }, { 0x0025, 17400 }, 115 + { 0x0024, 17500 }, { 0x0023, 17600 }, { 0x0022, 17800 }, 116 + { 0x0021, 17900 }, { 0x0020, 18000 }, { 0x001f, 18200 }, 117 + { 0x001e, 18300 }, { 0x001d, 18500 }, { 0x001c, 18700 }, 118 + { 0x001b, 18900 }, { 0x001a, 19000 }, { 0x0019, 19200 }, 119 + { 0x0018, 19300 }, { 0x0017, 19500 }, { 0x0016, 19700 }, 120 + { 0x0015, 19900 }, { 0x0014, 20000 }, 121 + }; 122 + 123 + static const struct cxd2841er_cnr_data s2_cn_data[] = { 124 + { 0x05af, 0 }, { 0x0597, 100 }, { 0x057e, 200 }, 125 + { 0x0567, 300 }, { 0x0550, 400 }, { 0x0539, 500 }, 126 + { 0x0522, 600 }, { 0x050c, 700 }, { 0x04f6, 800 }, 127 + { 0x04e1, 900 }, { 0x04cc, 1000 }, { 0x04b6, 1100 }, 128 + { 0x04a1, 1200 }, { 0x048c, 1300 }, { 0x0477, 1400 }, 129 + { 0x0463, 1500 }, { 0x044f, 1600 }, { 0x043c, 1700 }, 130 + { 0x0428, 1800 }, { 0x0416, 1900 }, { 0x0403, 2000 }, 131 + { 0x03ef, 2100 }, { 0x03dc, 2200 }, { 0x03c9, 2300 }, 132 + { 0x03b6, 2400 }, { 0x03a4, 2500 }, { 0x0392, 2600 }, 133 + { 0x0381, 2700 }, { 0x036f, 2800 }, { 0x035f, 2900 }, 134 + { 0x034e, 3000 }, { 0x033d, 3100 }, { 0x032d, 3200 }, 135 + { 0x031d, 3300 }, { 0x030d, 3400 }, { 0x02fd, 3500 }, 136 + { 0x02ee, 3600 }, { 0x02df, 3700 }, { 0x02d0, 3800 }, 137 + { 0x02c2, 3900 }, { 0x02b4, 4000 }, { 0x02a6, 4100 }, 138 + { 0x0299, 4200 }, { 0x028c, 4300 }, { 0x027f, 4400 }, 139 + { 0x0272, 4500 }, { 0x0265, 4600 }, { 0x0259, 4700 }, 140 + { 0x024d, 4800 }, { 0x0241, 4900 }, { 0x0236, 5000 }, 141 + { 0x022b, 5100 }, { 0x0220, 5200 }, { 0x0215, 5300 }, 142 + { 0x020a, 5400 }, { 0x0200, 5500 }, { 0x01f6, 5600 }, 143 + { 0x01ec, 5700 }, { 0x01e2, 5800 }, { 0x01d8, 5900 }, 144 + { 0x01cf, 6000 }, { 0x01c6, 6100 }, { 0x01bc, 6200 }, 145 + { 0x01b3, 6300 }, { 0x01aa, 6400 }, { 0x01a2, 6500 }, 146 + { 0x0199, 6600 }, { 0x0191, 6700 }, { 0x0189, 6800 }, 147 + { 0x0181, 6900 }, { 0x0179, 7000 }, { 0x0171, 7100 }, 148 + { 0x0169, 7200 }, { 0x0161, 7300 }, { 0x015a, 7400 }, 149 + { 0x0153, 7500 }, { 0x014b, 7600 }, { 0x0144, 7700 }, 150 + { 0x013d, 7800 }, { 0x0137, 7900 }, { 0x0130, 8000 }, 151 + { 0x012a, 8100 }, { 0x0124, 8200 }, { 0x011e, 8300 }, 152 + { 0x0118, 8400 }, { 0x0112, 8500 }, { 0x010c, 8600 }, 153 + { 0x0107, 8700 }, { 0x0101, 8800 }, { 0x00fc, 8900 }, 154 + { 0x00f7, 9000 }, { 0x00f2, 9100 }, { 0x00ec, 9200 }, 155 + { 0x00e7, 9300 }, { 0x00e2, 9400 }, { 0x00dd, 9500 }, 156 + { 0x00d8, 9600 }, { 0x00d4, 9700 }, { 0x00cf, 9800 }, 157 + { 0x00ca, 9900 }, { 0x00c6, 10000 }, { 0x00c2, 10100 }, 158 + { 0x00be, 10200 }, { 0x00b9, 10300 }, { 0x00b5, 10400 }, 159 + { 0x00b1, 10500 }, { 0x00ae, 10600 }, { 0x00aa, 10700 }, 160 + { 0x00a6, 10800 }, { 0x00a3, 10900 }, { 0x009f, 11000 }, 161 + { 0x009b, 11100 }, { 0x0098, 11200 }, { 0x0095, 11300 }, 162 + { 0x0091, 11400 }, { 0x008e, 11500 }, { 0x008b, 11600 }, 163 + { 0x0088, 11700 }, { 0x0085, 11800 }, { 0x0082, 11900 }, 164 + { 0x007f, 12000 }, { 0x007c, 12100 }, { 0x007a, 12200 }, 165 + { 0x0077, 12300 }, { 0x0074, 12400 }, { 0x0072, 12500 }, 166 + { 0x006f, 12600 }, { 0x006d, 12700 }, { 0x006b, 12800 }, 167 + { 0x0068, 12900 }, { 0x0066, 13000 }, { 0x0064, 13100 }, 168 + { 0x0061, 13200 }, { 0x005f, 13300 }, { 0x005d, 13400 }, 169 + { 0x005b, 13500 }, { 0x0059, 13600 }, { 0x0057, 13700 }, 170 + { 0x0055, 13800 }, { 0x0053, 13900 }, { 0x0051, 14000 }, 171 + { 0x004f, 14100 }, { 0x004e, 14200 }, { 0x004c, 14300 }, 172 + { 0x004a, 14400 }, { 0x0049, 14500 }, { 0x0047, 14600 }, 173 + { 0x0045, 14700 }, { 0x0044, 14800 }, { 0x0042, 14900 }, 174 + { 0x0041, 15000 }, { 0x003f, 15100 }, { 0x003e, 15200 }, 175 + { 0x003c, 15300 }, { 0x003b, 15400 }, { 0x003a, 15500 }, 176 + { 0x0038, 15600 }, { 0x0037, 15700 }, { 0x0036, 15800 }, 177 + { 0x0034, 15900 }, { 0x0033, 16000 }, { 0x0032, 16100 }, 178 + { 0x0031, 16200 }, { 0x0030, 16300 }, { 0x002f, 16400 }, 179 + { 0x002e, 16500 }, { 0x002d, 16600 }, { 0x002c, 16700 }, 180 + { 0x002b, 16800 }, { 0x002a, 16900 }, { 0x0029, 17000 }, 181 + { 0x0028, 17100 }, { 0x0027, 17200 }, { 0x0026, 17300 }, 182 + { 0x0025, 17400 }, { 0x0024, 17500 }, { 0x0023, 17600 }, 183 + { 0x0022, 17800 }, { 0x0021, 17900 }, { 0x0020, 18000 }, 184 + { 0x001f, 18200 }, { 0x001e, 18300 }, { 0x001d, 18500 }, 185 + { 0x001c, 18700 }, { 0x001b, 18900 }, { 0x001a, 19000 }, 186 + { 0x0019, 19200 }, { 0x0018, 19300 }, { 0x0017, 19500 }, 187 + { 0x0016, 19700 }, { 0x0015, 19900 }, { 0x0014, 20000 }, 188 + }; 189 + 190 + #define MAKE_IFFREQ_CONFIG(iffreq) ((u32)(((iffreq)/41.0)*16777216.0 + 0.5)) 191 + 192 + static void cxd2841er_i2c_debug(struct cxd2841er_priv *priv, 193 + u8 addr, u8 reg, u8 write, 194 + const u8 *data, u32 len) 195 + { 196 + dev_dbg(&priv->i2c->dev, 197 + "cxd2841er: I2C %s addr %02x reg 0x%02x size %d\n", 198 + (write == 0 ? "read" : "write"), addr, reg, len); 199 + print_hex_dump_bytes("cxd2841er: I2C data: ", 200 + DUMP_PREFIX_OFFSET, data, len); 201 + } 202 + 203 + static int cxd2841er_write_regs(struct cxd2841er_priv *priv, 204 + u8 addr, u8 reg, const u8 *data, u32 len) 205 + { 206 + int ret; 207 + u8 buf[MAX_WRITE_REGSIZE + 1]; 208 + u8 i2c_addr = (addr == I2C_SLVX ? 209 + priv->i2c_addr_slvx : priv->i2c_addr_slvt); 210 + struct i2c_msg msg[1] = { 211 + { 212 + .addr = i2c_addr, 213 + .flags = 0, 214 + .len = len + 1, 215 + .buf = buf, 216 + } 217 + }; 218 + 219 + if (len + 1 >= sizeof(buf)) { 220 + dev_warn(&priv->i2c->dev,"wr reg=%04x: len=%d is too big!\n", 221 + reg, len + 1); 222 + return -E2BIG; 223 + } 224 + 225 + cxd2841er_i2c_debug(priv, i2c_addr, reg, 1, data, len); 226 + buf[0] = reg; 227 + memcpy(&buf[1], data, len); 228 + 229 + ret = i2c_transfer(priv->i2c, msg, 1); 230 + if (ret >= 0 && ret != 1) 231 + ret = -EIO; 232 + if (ret < 0) { 233 + dev_warn(&priv->i2c->dev, 234 + "%s: i2c wr failed=%d addr=%02x reg=%02x len=%d\n", 235 + KBUILD_MODNAME, ret, i2c_addr, reg, len); 236 + return ret; 237 + } 238 + return 0; 239 + } 240 + 241 + static int cxd2841er_write_reg(struct cxd2841er_priv *priv, 242 + u8 addr, u8 reg, u8 val) 243 + { 244 + return cxd2841er_write_regs(priv, addr, reg, &val, 1); 245 + } 246 + 247 + static int cxd2841er_read_regs(struct cxd2841er_priv *priv, 248 + u8 addr, u8 reg, u8 *val, u32 len) 249 + { 250 + int ret; 251 + u8 i2c_addr = (addr == I2C_SLVX ? 252 + priv->i2c_addr_slvx : priv->i2c_addr_slvt); 253 + struct i2c_msg msg[2] = { 254 + { 255 + .addr = i2c_addr, 256 + .flags = 0, 257 + .len = 1, 258 + .buf = &reg, 259 + }, { 260 + .addr = i2c_addr, 261 + .flags = I2C_M_RD, 262 + .len = len, 263 + .buf = val, 264 + } 265 + }; 266 + 267 + ret = i2c_transfer(priv->i2c, &msg[0], 1); 268 + if (ret >= 0 && ret != 1) 269 + ret = -EIO; 270 + if (ret < 0) { 271 + dev_warn(&priv->i2c->dev, 272 + "%s: i2c rw failed=%d addr=%02x reg=%02x\n", 273 + KBUILD_MODNAME, ret, i2c_addr, reg); 274 + return ret; 275 + } 276 + ret = i2c_transfer(priv->i2c, &msg[1], 1); 277 + if (ret >= 0 && ret != 1) 278 + ret = -EIO; 279 + if (ret < 0) { 280 + dev_warn(&priv->i2c->dev, 281 + "%s: i2c rd failed=%d addr=%02x reg=%02x\n", 282 + KBUILD_MODNAME, ret, i2c_addr, reg); 283 + return ret; 284 + } 285 + return 0; 286 + } 287 + 288 + static int cxd2841er_read_reg(struct cxd2841er_priv *priv, 289 + u8 addr, u8 reg, u8 *val) 290 + { 291 + return cxd2841er_read_regs(priv, addr, reg, val, 1); 292 + } 293 + 294 + static int cxd2841er_set_reg_bits(struct cxd2841er_priv *priv, 295 + u8 addr, u8 reg, u8 data, u8 mask) 296 + { 297 + int res; 298 + u8 rdata; 299 + 300 + if (mask != 0xff) { 301 + res = cxd2841er_read_reg(priv, addr, reg, &rdata); 302 + if (res) 303 + return res; 304 + data = ((data & mask) | (rdata & (mask ^ 0xFF))); 305 + } 306 + return cxd2841er_write_reg(priv, addr, reg, data); 307 + } 308 + 309 + static int cxd2841er_dvbs2_set_symbol_rate(struct cxd2841er_priv *priv, 310 + u32 symbol_rate) 311 + { 312 + u32 reg_value = 0; 313 + u8 data[3] = {0, 0, 0}; 314 + 315 + dev_dbg(&priv->i2c->dev, "%s()\n", __func__); 316 + /* 317 + * regValue = (symbolRateKSps * 2^14 / 1000) + 0.5 318 + * = ((symbolRateKSps * 2^14) + 500) / 1000 319 + * = ((symbolRateKSps * 16384) + 500) / 1000 320 + */ 321 + reg_value = DIV_ROUND_CLOSEST(symbol_rate * 16384, 1000); 322 + if ((reg_value == 0) || (reg_value > 0xFFFFF)) { 323 + dev_err(&priv->i2c->dev, 324 + "%s(): reg_value is out of range\n", __func__); 325 + return -EINVAL; 326 + } 327 + data[0] = (u8)((reg_value >> 16) & 0x0F); 328 + data[1] = (u8)((reg_value >> 8) & 0xFF); 329 + data[2] = (u8)(reg_value & 0xFF); 330 + /* Set SLV-T Bank : 0xAE */ 331 + cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0xae); 332 + cxd2841er_write_regs(priv, I2C_SLVT, 0x20, data, 3); 333 + return 0; 334 + } 335 + 336 + static void cxd2841er_set_ts_clock_mode(struct cxd2841er_priv *priv, 337 + u8 system); 338 + 339 + static int cxd2841er_sleep_s_to_active_s(struct cxd2841er_priv *priv, 340 + u8 system, u32 symbol_rate) 341 + { 342 + int ret; 343 + u8 data[4] = { 0, 0, 0, 0 }; 344 + 345 + if (priv->state != STATE_SLEEP_S) { 346 + dev_err(&priv->i2c->dev, "%s(): invalid state %d\n", 347 + __func__, (int)priv->state); 348 + return -EINVAL; 349 + } 350 + dev_dbg(&priv->i2c->dev, "%s()\n", __func__); 351 + cxd2841er_set_ts_clock_mode(priv, SYS_DVBS); 352 + /* Set demod mode */ 353 + if (system == SYS_DVBS) { 354 + data[0] = 0x0A; 355 + } else if (system == SYS_DVBS2) { 356 + data[0] = 0x0B; 357 + } else { 358 + dev_err(&priv->i2c->dev, "%s(): invalid delsys %d\n", 359 + __func__, system); 360 + return -EINVAL; 361 + } 362 + /* Set SLV-X Bank : 0x00 */ 363 + cxd2841er_write_reg(priv, I2C_SLVX, 0x00, 0x00); 364 + cxd2841er_write_reg(priv, I2C_SLVX, 0x17, data[0]); 365 + /* DVB-S/S2 */ 366 + data[0] = 0x00; 367 + /* Set SLV-T Bank : 0x00 */ 368 + cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x00); 369 + /* Enable S/S2 auto detection 1 */ 370 + cxd2841er_write_reg(priv, I2C_SLVT, 0x2d, data[0]); 371 + /* Set SLV-T Bank : 0xAE */ 372 + cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0xae); 373 + /* Enable S/S2 auto detection 2 */ 374 + cxd2841er_write_reg(priv, I2C_SLVT, 0x30, data[0]); 375 + /* Set SLV-T Bank : 0x00 */ 376 + cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x00); 377 + /* Enable demod clock */ 378 + cxd2841er_write_reg(priv, I2C_SLVT, 0x2c, 0x01); 379 + /* Enable ADC clock */ 380 + cxd2841er_write_reg(priv, I2C_SLVT, 0x31, 0x01); 381 + /* Enable ADC 1 */ 382 + cxd2841er_write_reg(priv, I2C_SLVT, 0x63, 0x16); 383 + /* Enable ADC 2 */ 384 + cxd2841er_write_reg(priv, I2C_SLVT, 0x65, 0x3f); 385 + /* Set SLV-X Bank : 0x00 */ 386 + cxd2841er_write_reg(priv, I2C_SLVX, 0x00, 0x00); 387 + /* Enable ADC 3 */ 388 + cxd2841er_write_reg(priv, I2C_SLVX, 0x18, 0x00); 389 + /* Set SLV-T Bank : 0xA3 */ 390 + cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0xa3); 391 + cxd2841er_write_reg(priv, I2C_SLVT, 0xac, 0x00); 392 + data[0] = 0x07; 393 + data[1] = 0x3B; 394 + data[2] = 0x08; 395 + data[3] = 0xC5; 396 + /* Set SLV-T Bank : 0xAB */ 397 + cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0xab); 398 + cxd2841er_write_regs(priv, I2C_SLVT, 0x98, data, 4); 399 + data[0] = 0x05; 400 + data[1] = 0x80; 401 + data[2] = 0x0A; 402 + data[3] = 0x80; 403 + cxd2841er_write_regs(priv, I2C_SLVT, 0xa8, data, 4); 404 + data[0] = 0x0C; 405 + data[1] = 0xCC; 406 + cxd2841er_write_regs(priv, I2C_SLVT, 0xc3, data, 2); 407 + /* Set demod parameter */ 408 + ret = cxd2841er_dvbs2_set_symbol_rate(priv, symbol_rate); 409 + if (ret != 0) 410 + return ret; 411 + /* Set SLV-T Bank : 0x00 */ 412 + cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x00); 413 + /* disable Hi-Z setting 1 */ 414 + cxd2841er_write_reg(priv, I2C_SLVT, 0x80, 0x10); 415 + /* disable Hi-Z setting 2 */ 416 + cxd2841er_write_reg(priv, I2C_SLVT, 0x81, 0x00); 417 + priv->state = STATE_ACTIVE_S; 418 + return 0; 419 + } 420 + 421 + static int cxd2841er_sleep_tc_to_active_t_band(struct cxd2841er_priv *priv, 422 + u32 bandwidth); 423 + 424 + static int cxd2841er_sleep_tc_to_active_t2_band(struct cxd2841er_priv *priv, 425 + u32 bandwidth); 426 + 427 + static int cxd2841er_sleep_tc_to_active_c_band(struct cxd2841er_priv *priv, 428 + u32 bandwidth); 429 + 430 + static int cxd2841er_retune_active(struct cxd2841er_priv *priv, 431 + struct dtv_frontend_properties *p) 432 + { 433 + dev_dbg(&priv->i2c->dev, "%s()\n", __func__); 434 + if (priv->state != STATE_ACTIVE_S && 435 + priv->state != STATE_ACTIVE_TC) { 436 + dev_dbg(&priv->i2c->dev, "%s(): invalid state %d\n", 437 + __func__, priv->state); 438 + return -EINVAL; 439 + } 440 + /* Set SLV-T Bank : 0x00 */ 441 + cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x00); 442 + /* disable TS output */ 443 + cxd2841er_write_reg(priv, I2C_SLVT, 0xc3, 0x01); 444 + if (priv->state == STATE_ACTIVE_S) 445 + return cxd2841er_dvbs2_set_symbol_rate( 446 + priv, p->symbol_rate / 1000); 447 + else if (priv->state == STATE_ACTIVE_TC) { 448 + switch (priv->system) { 449 + case SYS_DVBT: 450 + return cxd2841er_sleep_tc_to_active_t_band( 451 + priv, p->bandwidth_hz); 452 + case SYS_DVBT2: 453 + return cxd2841er_sleep_tc_to_active_t2_band( 454 + priv, p->bandwidth_hz); 455 + case SYS_DVBC_ANNEX_A: 456 + return cxd2841er_sleep_tc_to_active_c_band( 457 + priv, 8000000); 458 + } 459 + } 460 + dev_dbg(&priv->i2c->dev, "%s(): invalid delivery system %d\n", 461 + __func__, priv->system); 462 + return -EINVAL; 463 + } 464 + 465 + static int cxd2841er_active_s_to_sleep_s(struct cxd2841er_priv *priv) 466 + { 467 + dev_dbg(&priv->i2c->dev, "%s()\n", __func__); 468 + if (priv->state != STATE_ACTIVE_S) { 469 + dev_err(&priv->i2c->dev, "%s(): invalid state %d\n", 470 + __func__, priv->state); 471 + return -EINVAL; 472 + } 473 + /* Set SLV-T Bank : 0x00 */ 474 + cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x00); 475 + /* disable TS output */ 476 + cxd2841er_write_reg(priv, I2C_SLVT, 0xc3, 0x01); 477 + /* enable Hi-Z setting 1 */ 478 + cxd2841er_write_reg(priv, I2C_SLVT, 0x80, 0x1f); 479 + /* enable Hi-Z setting 2 */ 480 + cxd2841er_write_reg(priv, I2C_SLVT, 0x81, 0xff); 481 + /* Set SLV-X Bank : 0x00 */ 482 + cxd2841er_write_reg(priv, I2C_SLVX, 0x00, 0x00); 483 + /* disable ADC 1 */ 484 + cxd2841er_write_reg(priv, I2C_SLVX, 0x18, 0x01); 485 + /* Set SLV-T Bank : 0x00 */ 486 + cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x00); 487 + /* disable ADC clock */ 488 + cxd2841er_write_reg(priv, I2C_SLVT, 0x31, 0x00); 489 + /* disable ADC 2 */ 490 + cxd2841er_write_reg(priv, I2C_SLVT, 0x63, 0x16); 491 + /* disable ADC 3 */ 492 + cxd2841er_write_reg(priv, I2C_SLVT, 0x65, 0x27); 493 + /* SADC Bias ON */ 494 + cxd2841er_write_reg(priv, I2C_SLVT, 0x69, 0x06); 495 + /* disable demod clock */ 496 + cxd2841er_write_reg(priv, I2C_SLVT, 0x2c, 0x00); 497 + /* Set SLV-T Bank : 0xAE */ 498 + cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0xae); 499 + /* disable S/S2 auto detection1 */ 500 + cxd2841er_write_reg(priv, I2C_SLVT, 0x30, 0x00); 501 + /* Set SLV-T Bank : 0x00 */ 502 + cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x00); 503 + /* disable S/S2 auto detection2 */ 504 + cxd2841er_write_reg(priv, I2C_SLVT, 0x2d, 0x00); 505 + priv->state = STATE_SLEEP_S; 506 + return 0; 507 + } 508 + 509 + static int cxd2841er_sleep_s_to_shutdown(struct cxd2841er_priv *priv) 510 + { 511 + dev_dbg(&priv->i2c->dev, "%s()\n", __func__); 512 + if (priv->state != STATE_SLEEP_S) { 513 + dev_dbg(&priv->i2c->dev, "%s(): invalid demod state %d\n", 514 + __func__, priv->state); 515 + return -EINVAL; 516 + } 517 + /* Set SLV-T Bank : 0x00 */ 518 + cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x00); 519 + /* Disable DSQOUT */ 520 + cxd2841er_write_reg(priv, I2C_SLVT, 0x80, 0x3f); 521 + /* Disable DSQIN */ 522 + cxd2841er_write_reg(priv, I2C_SLVT, 0x9c, 0x00); 523 + /* Set SLV-X Bank : 0x00 */ 524 + cxd2841er_write_reg(priv, I2C_SLVX, 0x00, 0x00); 525 + /* Disable oscillator */ 526 + cxd2841er_write_reg(priv, I2C_SLVX, 0x15, 0x01); 527 + /* Set demod mode */ 528 + cxd2841er_write_reg(priv, I2C_SLVX, 0x17, 0x01); 529 + priv->state = STATE_SHUTDOWN; 530 + return 0; 531 + } 532 + 533 + static int cxd2841er_sleep_tc_to_shutdown(struct cxd2841er_priv *priv) 534 + { 535 + dev_dbg(&priv->i2c->dev, "%s()\n", __func__); 536 + if (priv->state != STATE_SLEEP_TC) { 537 + dev_dbg(&priv->i2c->dev, "%s(): invalid demod state %d\n", 538 + __func__, priv->state); 539 + return -EINVAL; 540 + } 541 + /* Set SLV-X Bank : 0x00 */ 542 + cxd2841er_write_reg(priv, I2C_SLVX, 0x00, 0x00); 543 + /* Disable oscillator */ 544 + cxd2841er_write_reg(priv, I2C_SLVX, 0x15, 0x01); 545 + /* Set demod mode */ 546 + cxd2841er_write_reg(priv, I2C_SLVX, 0x17, 0x01); 547 + priv->state = STATE_SHUTDOWN; 548 + return 0; 549 + } 550 + 551 + static int cxd2841er_active_t_to_sleep_tc(struct cxd2841er_priv *priv) 552 + { 553 + dev_dbg(&priv->i2c->dev, "%s()\n", __func__); 554 + if (priv->state != STATE_ACTIVE_TC) { 555 + dev_err(&priv->i2c->dev, "%s(): invalid state %d\n", 556 + __func__, priv->state); 557 + return -EINVAL; 558 + } 559 + /* Set SLV-T Bank : 0x00 */ 560 + cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x00); 561 + /* disable TS output */ 562 + cxd2841er_write_reg(priv, I2C_SLVT, 0xc3, 0x01); 563 + /* enable Hi-Z setting 1 */ 564 + cxd2841er_write_reg(priv, I2C_SLVT, 0x80, 0x3f); 565 + /* enable Hi-Z setting 2 */ 566 + cxd2841er_write_reg(priv, I2C_SLVT, 0x81, 0xff); 567 + /* Set SLV-X Bank : 0x00 */ 568 + cxd2841er_write_reg(priv, I2C_SLVX, 0x00, 0x00); 569 + /* disable ADC 1 */ 570 + cxd2841er_write_reg(priv, I2C_SLVX, 0x18, 0x01); 571 + /* Set SLV-T Bank : 0x00 */ 572 + cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x00); 573 + /* Disable ADC 2 */ 574 + cxd2841er_write_reg(priv, I2C_SLVT, 0x43, 0x0a); 575 + /* Disable ADC 3 */ 576 + cxd2841er_write_reg(priv, I2C_SLVT, 0x41, 0x0a); 577 + /* Disable ADC clock */ 578 + cxd2841er_write_reg(priv, I2C_SLVT, 0x30, 0x00); 579 + /* Disable RF level monitor */ 580 + cxd2841er_write_reg(priv, I2C_SLVT, 0x2f, 0x00); 581 + /* Disable demod clock */ 582 + cxd2841er_write_reg(priv, I2C_SLVT, 0x2c, 0x00); 583 + priv->state = STATE_SLEEP_TC; 584 + return 0; 585 + } 586 + 587 + static int cxd2841er_active_t2_to_sleep_tc(struct cxd2841er_priv *priv) 588 + { 589 + dev_dbg(&priv->i2c->dev, "%s()\n", __func__); 590 + if (priv->state != STATE_ACTIVE_TC) { 591 + dev_err(&priv->i2c->dev, "%s(): invalid state %d\n", 592 + __func__, priv->state); 593 + return -EINVAL; 594 + } 595 + /* Set SLV-T Bank : 0x00 */ 596 + cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x00); 597 + /* disable TS output */ 598 + cxd2841er_write_reg(priv, I2C_SLVT, 0xc3, 0x01); 599 + /* enable Hi-Z setting 1 */ 600 + cxd2841er_write_reg(priv, I2C_SLVT, 0x80, 0x3f); 601 + /* enable Hi-Z setting 2 */ 602 + cxd2841er_write_reg(priv, I2C_SLVT, 0x81, 0xff); 603 + /* Cancel DVB-T2 setting */ 604 + cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x13); 605 + cxd2841er_write_reg(priv, I2C_SLVT, 0x83, 0x40); 606 + cxd2841er_write_reg(priv, I2C_SLVT, 0x86, 0x21); 607 + cxd2841er_set_reg_bits(priv, I2C_SLVT, 0x9e, 0x09, 0x0f); 608 + cxd2841er_write_reg(priv, I2C_SLVT, 0x9f, 0xfb); 609 + cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x2a); 610 + cxd2841er_set_reg_bits(priv, I2C_SLVT, 0x38, 0x00, 0x0f); 611 + cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x2b); 612 + cxd2841er_set_reg_bits(priv, I2C_SLVT, 0x11, 0x00, 0x3f); 613 + /* Set SLV-X Bank : 0x00 */ 614 + cxd2841er_write_reg(priv, I2C_SLVX, 0x00, 0x00); 615 + /* disable ADC 1 */ 616 + cxd2841er_write_reg(priv, I2C_SLVX, 0x18, 0x01); 617 + /* Set SLV-T Bank : 0x00 */ 618 + cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x00); 619 + /* Disable ADC 2 */ 620 + cxd2841er_write_reg(priv, I2C_SLVT, 0x43, 0x0a); 621 + /* Disable ADC 3 */ 622 + cxd2841er_write_reg(priv, I2C_SLVT, 0x41, 0x0a); 623 + /* Disable ADC clock */ 624 + cxd2841er_write_reg(priv, I2C_SLVT, 0x30, 0x00); 625 + /* Disable RF level monitor */ 626 + cxd2841er_write_reg(priv, I2C_SLVT, 0x2f, 0x00); 627 + /* Disable demod clock */ 628 + cxd2841er_write_reg(priv, I2C_SLVT, 0x2c, 0x00); 629 + priv->state = STATE_SLEEP_TC; 630 + return 0; 631 + } 632 + 633 + static int cxd2841er_active_c_to_sleep_tc(struct cxd2841er_priv *priv) 634 + { 635 + dev_dbg(&priv->i2c->dev, "%s()\n", __func__); 636 + if (priv->state != STATE_ACTIVE_TC) { 637 + dev_err(&priv->i2c->dev, "%s(): invalid state %d\n", 638 + __func__, priv->state); 639 + return -EINVAL; 640 + } 641 + /* Set SLV-T Bank : 0x00 */ 642 + cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x00); 643 + /* disable TS output */ 644 + cxd2841er_write_reg(priv, I2C_SLVT, 0xc3, 0x01); 645 + /* enable Hi-Z setting 1 */ 646 + cxd2841er_write_reg(priv, I2C_SLVT, 0x80, 0x3f); 647 + /* enable Hi-Z setting 2 */ 648 + cxd2841er_write_reg(priv, I2C_SLVT, 0x81, 0xff); 649 + /* Cancel DVB-C setting */ 650 + cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x11); 651 + cxd2841er_set_reg_bits(priv, I2C_SLVT, 0xa3, 0x00, 0x1f); 652 + /* Set SLV-X Bank : 0x00 */ 653 + cxd2841er_write_reg(priv, I2C_SLVX, 0x00, 0x00); 654 + /* disable ADC 1 */ 655 + cxd2841er_write_reg(priv, I2C_SLVX, 0x18, 0x01); 656 + /* Set SLV-T Bank : 0x00 */ 657 + cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x00); 658 + /* Disable ADC 2 */ 659 + cxd2841er_write_reg(priv, I2C_SLVT, 0x43, 0x0a); 660 + /* Disable ADC 3 */ 661 + cxd2841er_write_reg(priv, I2C_SLVT, 0x41, 0x0a); 662 + /* Disable ADC clock */ 663 + cxd2841er_write_reg(priv, I2C_SLVT, 0x30, 0x00); 664 + /* Disable RF level monitor */ 665 + cxd2841er_write_reg(priv, I2C_SLVT, 0x2f, 0x00); 666 + /* Disable demod clock */ 667 + cxd2841er_write_reg(priv, I2C_SLVT, 0x2c, 0x00); 668 + priv->state = STATE_SLEEP_TC; 669 + return 0; 670 + } 671 + 672 + static int cxd2841er_shutdown_to_sleep_s(struct cxd2841er_priv *priv) 673 + { 674 + dev_dbg(&priv->i2c->dev, "%s()\n", __func__); 675 + if (priv->state != STATE_SHUTDOWN) { 676 + dev_dbg(&priv->i2c->dev, "%s(): invalid demod state %d\n", 677 + __func__, priv->state); 678 + return -EINVAL; 679 + } 680 + /* Set SLV-X Bank : 0x00 */ 681 + cxd2841er_write_reg(priv, I2C_SLVX, 0x00, 0x00); 682 + /* Clear all demodulator registers */ 683 + cxd2841er_write_reg(priv, I2C_SLVX, 0x02, 0x00); 684 + usleep_range(3000, 5000); 685 + /* Set SLV-X Bank : 0x00 */ 686 + cxd2841er_write_reg(priv, I2C_SLVX, 0x00, 0x00); 687 + /* Set demod SW reset */ 688 + cxd2841er_write_reg(priv, I2C_SLVX, 0x10, 0x01); 689 + /* Set X'tal clock to 20.5Mhz */ 690 + cxd2841er_write_reg(priv, I2C_SLVX, 0x14, 0x00); 691 + /* Set demod mode */ 692 + cxd2841er_write_reg(priv, I2C_SLVX, 0x17, 0x0a); 693 + /* Clear demod SW reset */ 694 + cxd2841er_write_reg(priv, I2C_SLVX, 0x10, 0x00); 695 + usleep_range(1000, 2000); 696 + /* Set SLV-T Bank : 0x00 */ 697 + cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x00); 698 + /* enable DSQOUT */ 699 + cxd2841er_write_reg(priv, I2C_SLVT, 0x80, 0x1F); 700 + /* enable DSQIN */ 701 + cxd2841er_write_reg(priv, I2C_SLVT, 0x9C, 0x40); 702 + /* TADC Bias On */ 703 + cxd2841er_write_reg(priv, I2C_SLVT, 0x43, 0x0a); 704 + cxd2841er_write_reg(priv, I2C_SLVT, 0x41, 0x0a); 705 + /* SADC Bias On */ 706 + cxd2841er_write_reg(priv, I2C_SLVT, 0x63, 0x16); 707 + cxd2841er_write_reg(priv, I2C_SLVT, 0x65, 0x27); 708 + cxd2841er_write_reg(priv, I2C_SLVT, 0x69, 0x06); 709 + priv->state = STATE_SLEEP_S; 710 + return 0; 711 + } 712 + 713 + static int cxd2841er_shutdown_to_sleep_tc(struct cxd2841er_priv *priv) 714 + { 715 + dev_dbg(&priv->i2c->dev, "%s()\n", __func__); 716 + if (priv->state != STATE_SHUTDOWN) { 717 + dev_dbg(&priv->i2c->dev, "%s(): invalid demod state %d\n", 718 + __func__, priv->state); 719 + return -EINVAL; 720 + } 721 + /* Set SLV-X Bank : 0x00 */ 722 + cxd2841er_write_reg(priv, I2C_SLVX, 0x00, 0x00); 723 + /* Clear all demodulator registers */ 724 + cxd2841er_write_reg(priv, I2C_SLVX, 0x02, 0x00); 725 + usleep_range(3000, 5000); 726 + /* Set SLV-X Bank : 0x00 */ 727 + cxd2841er_write_reg(priv, I2C_SLVX, 0x00, 0x00); 728 + /* Set demod SW reset */ 729 + cxd2841er_write_reg(priv, I2C_SLVX, 0x10, 0x01); 730 + /* Set X'tal clock to 20.5Mhz */ 731 + cxd2841er_write_reg(priv, I2C_SLVX, 0x13, 0x00); 732 + cxd2841er_write_reg(priv, I2C_SLVX, 0x14, 0x00); 733 + /* Clear demod SW reset */ 734 + cxd2841er_write_reg(priv, I2C_SLVX, 0x10, 0x00); 735 + usleep_range(1000, 2000); 736 + /* Set SLV-T Bank : 0x00 */ 737 + cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x00); 738 + /* TADC Bias On */ 739 + cxd2841er_write_reg(priv, I2C_SLVT, 0x43, 0x0a); 740 + cxd2841er_write_reg(priv, I2C_SLVT, 0x41, 0x0a); 741 + /* SADC Bias On */ 742 + cxd2841er_write_reg(priv, I2C_SLVT, 0x63, 0x16); 743 + cxd2841er_write_reg(priv, I2C_SLVT, 0x65, 0x27); 744 + cxd2841er_write_reg(priv, I2C_SLVT, 0x69, 0x06); 745 + priv->state = STATE_SLEEP_TC; 746 + return 0; 747 + } 748 + 749 + static int cxd2841er_tune_done(struct cxd2841er_priv *priv) 750 + { 751 + dev_dbg(&priv->i2c->dev, "%s()\n", __func__); 752 + /* Set SLV-T Bank : 0x00 */ 753 + cxd2841er_write_reg(priv, I2C_SLVT, 0, 0); 754 + /* SW Reset */ 755 + cxd2841er_write_reg(priv, I2C_SLVT, 0xfe, 0x01); 756 + /* Enable TS output */ 757 + cxd2841er_write_reg(priv, I2C_SLVT, 0xc3, 0x00); 758 + return 0; 759 + } 760 + 761 + /* Set TS parallel mode */ 762 + static void cxd2841er_set_ts_clock_mode(struct cxd2841er_priv *priv, 763 + u8 system) 764 + { 765 + u8 serial_ts, ts_rate_ctrl_off, ts_in_off; 766 + 767 + dev_dbg(&priv->i2c->dev, "%s()\n", __func__); 768 + /* Set SLV-T Bank : 0x00 */ 769 + cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x00); 770 + cxd2841er_read_reg(priv, I2C_SLVT, 0xc4, &serial_ts); 771 + cxd2841er_read_reg(priv, I2C_SLVT, 0xd3, &ts_rate_ctrl_off); 772 + cxd2841er_read_reg(priv, I2C_SLVT, 0xde, &ts_in_off); 773 + dev_dbg(&priv->i2c->dev, "%s(): ser_ts=0x%02x rate_ctrl_off=0x%02x in_off=0x%02x\n", 774 + __func__, serial_ts, ts_rate_ctrl_off, ts_in_off); 775 + 776 + /* 777 + * slave Bank Addr Bit default Name 778 + * <SLV-T> 00h D9h [7:0] 8'h08 OTSCKPERIOD 779 + */ 780 + cxd2841er_write_reg(priv, I2C_SLVT, 0xd9, 0x08); 781 + /* 782 + * Disable TS IF Clock 783 + * slave Bank Addr Bit default Name 784 + * <SLV-T> 00h 32h [0] 1'b1 OREG_CK_TSIF_EN 785 + */ 786 + cxd2841er_set_reg_bits(priv, I2C_SLVT, 0x32, 0x00, 0x01); 787 + /* 788 + * slave Bank Addr Bit default Name 789 + * <SLV-T> 00h 33h [1:0] 2'b01 OREG_CKSEL_TSIF 790 + */ 791 + cxd2841er_set_reg_bits(priv, I2C_SLVT, 0x33, 0x00, 0x03); 792 + /* 793 + * Enable TS IF Clock 794 + * slave Bank Addr Bit default Name 795 + * <SLV-T> 00h 32h [0] 1'b1 OREG_CK_TSIF_EN 796 + */ 797 + cxd2841er_set_reg_bits(priv, I2C_SLVT, 0x32, 0x01, 0x01); 798 + 799 + if (system == SYS_DVBT) { 800 + /* Enable parity period for DVB-T */ 801 + cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x10); 802 + cxd2841er_set_reg_bits(priv, I2C_SLVT, 0x66, 0x01, 0x01); 803 + } else if (system == SYS_DVBC_ANNEX_A) { 804 + /* Enable parity period for DVB-C */ 805 + cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x40); 806 + cxd2841er_set_reg_bits(priv, I2C_SLVT, 0x66, 0x01, 0x01); 807 + } 808 + } 809 + 810 + static u8 cxd2841er_chip_id(struct cxd2841er_priv *priv) 811 + { 812 + u8 chip_id; 813 + 814 + dev_dbg(&priv->i2c->dev, "%s()\n", __func__); 815 + cxd2841er_write_reg(priv, I2C_SLVT, 0, 0); 816 + cxd2841er_read_reg(priv, I2C_SLVT, 0xfd, &chip_id); 817 + return chip_id; 818 + } 819 + 820 + static int cxd2841er_read_status_s(struct dvb_frontend *fe, 821 + enum fe_status *status) 822 + { 823 + u8 reg = 0; 824 + struct cxd2841er_priv *priv = fe->demodulator_priv; 825 + 826 + dev_dbg(&priv->i2c->dev, "%s()\n", __func__); 827 + *status = 0; 828 + if (priv->state != STATE_ACTIVE_S) { 829 + dev_err(&priv->i2c->dev, "%s(): invalid state %d\n", 830 + __func__, priv->state); 831 + return -EINVAL; 832 + } 833 + /* Set SLV-T Bank : 0xA0 */ 834 + cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0xa0); 835 + /* 836 + * slave Bank Addr Bit Signal name 837 + * <SLV-T> A0h 11h [2] ITSLOCK 838 + */ 839 + cxd2841er_read_reg(priv, I2C_SLVT, 0x11, &reg); 840 + if (reg & 0x04) { 841 + *status = FE_HAS_SIGNAL 842 + | FE_HAS_CARRIER 843 + | FE_HAS_VITERBI 844 + | FE_HAS_SYNC 845 + | FE_HAS_LOCK; 846 + } 847 + dev_dbg(&priv->i2c->dev, "%s(): result 0x%x\n", __func__, *status); 848 + return 0; 849 + } 850 + 851 + static int cxd2841er_read_status_t_t2(struct cxd2841er_priv *priv, 852 + u8 *sync, u8 *tslock, u8 *unlock) 853 + { 854 + u8 data = 0; 855 + 856 + dev_dbg(&priv->i2c->dev, "%s()\n", __func__); 857 + if (priv->state != STATE_ACTIVE_TC) 858 + return -EINVAL; 859 + if (priv->system == SYS_DVBT) { 860 + /* Set SLV-T Bank : 0x10 */ 861 + cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x10); 862 + } else { 863 + /* Set SLV-T Bank : 0x20 */ 864 + cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x20); 865 + } 866 + cxd2841er_read_reg(priv, I2C_SLVT, 0x10, &data); 867 + if ((data & 0x07) == 0x07) { 868 + dev_dbg(&priv->i2c->dev, 869 + "%s(): invalid hardware state detected\n", __func__); 870 + *sync = 0; 871 + *tslock = 0; 872 + *unlock = 0; 873 + } else { 874 + *sync = ((data & 0x07) == 0x6 ? 1 : 0); 875 + *tslock = ((data & 0x20) ? 1 : 0); 876 + *unlock = ((data & 0x10) ? 1 : 0); 877 + } 878 + return 0; 879 + } 880 + 881 + static int cxd2841er_read_status_c(struct cxd2841er_priv *priv, u8 *tslock) 882 + { 883 + u8 data; 884 + 885 + dev_dbg(&priv->i2c->dev, "%s()\n", __func__); 886 + if (priv->state != STATE_ACTIVE_TC) 887 + return -EINVAL; 888 + cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x40); 889 + cxd2841er_read_reg(priv, I2C_SLVT, 0x88, &data); 890 + if ((data & 0x01) == 0) { 891 + *tslock = 0; 892 + } else { 893 + cxd2841er_read_reg(priv, I2C_SLVT, 0x10, &data); 894 + *tslock = ((data & 0x20) ? 1 : 0); 895 + } 896 + return 0; 897 + } 898 + 899 + static int cxd2841er_read_status_tc(struct dvb_frontend *fe, 900 + enum fe_status *status) 901 + { 902 + int ret = 0; 903 + u8 sync = 0; 904 + u8 tslock = 0; 905 + u8 unlock = 0; 906 + struct cxd2841er_priv *priv = fe->demodulator_priv; 907 + 908 + *status = 0; 909 + if (priv->state == STATE_ACTIVE_TC) { 910 + if (priv->system == SYS_DVBT || priv->system == SYS_DVBT2) { 911 + ret = cxd2841er_read_status_t_t2( 912 + priv, &sync, &tslock, &unlock); 913 + if (ret) 914 + goto done; 915 + if (unlock) 916 + goto done; 917 + if (sync) 918 + *status = FE_HAS_SIGNAL | 919 + FE_HAS_CARRIER | 920 + FE_HAS_VITERBI | 921 + FE_HAS_SYNC; 922 + if (tslock) 923 + *status |= FE_HAS_LOCK; 924 + } else if (priv->system == SYS_DVBC_ANNEX_A) { 925 + ret = cxd2841er_read_status_c(priv, &tslock); 926 + if (ret) 927 + goto done; 928 + if (tslock) 929 + *status = FE_HAS_SIGNAL | 930 + FE_HAS_CARRIER | 931 + FE_HAS_VITERBI | 932 + FE_HAS_SYNC | 933 + FE_HAS_LOCK; 934 + } 935 + } 936 + done: 937 + dev_dbg(&priv->i2c->dev, "%s(): status 0x%x\n", __func__, *status); 938 + return ret; 939 + } 940 + 941 + static int cxd2841er_get_carrier_offset_s_s2(struct cxd2841er_priv *priv, 942 + int *offset) 943 + { 944 + u8 data[3]; 945 + u8 is_hs_mode; 946 + s32 cfrl_ctrlval; 947 + s32 temp_div, temp_q, temp_r; 948 + 949 + if (priv->state != STATE_ACTIVE_S) { 950 + dev_dbg(&priv->i2c->dev, "%s(): invalid state %d\n", 951 + __func__, priv->state); 952 + return -EINVAL; 953 + } 954 + /* 955 + * Get High Sampling Rate mode 956 + * slave Bank Addr Bit Signal name 957 + * <SLV-T> A0h 10h [0] ITRL_LOCK 958 + */ 959 + cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0xa0); 960 + cxd2841er_read_reg(priv, I2C_SLVT, 0x10, &data[0]); 961 + if (data[0] & 0x01) { 962 + /* 963 + * slave Bank Addr Bit Signal name 964 + * <SLV-T> A0h 50h [4] IHSMODE 965 + */ 966 + cxd2841er_read_reg(priv, I2C_SLVT, 0x50, &data[0]); 967 + is_hs_mode = (data[0] & 0x10 ? 1 : 0); 968 + } else { 969 + dev_dbg(&priv->i2c->dev, 970 + "%s(): unable to detect sampling rate mode\n", 971 + __func__); 972 + return -EINVAL; 973 + } 974 + /* 975 + * slave Bank Addr Bit Signal name 976 + * <SLV-T> A0h 45h [4:0] ICFRL_CTRLVAL[20:16] 977 + * <SLV-T> A0h 46h [7:0] ICFRL_CTRLVAL[15:8] 978 + * <SLV-T> A0h 47h [7:0] ICFRL_CTRLVAL[7:0] 979 + */ 980 + cxd2841er_read_regs(priv, I2C_SLVT, 0x45, data, 3); 981 + cfrl_ctrlval = sign_extend32((((u32)data[0] & 0x1F) << 16) | 982 + (((u32)data[1] & 0xFF) << 8) | 983 + ((u32)data[2] & 0xFF), 20); 984 + temp_div = (is_hs_mode ? 1048576 : 1572864); 985 + if (cfrl_ctrlval > 0) { 986 + temp_q = div_s64_rem(97375LL * cfrl_ctrlval, 987 + temp_div, &temp_r); 988 + } else { 989 + temp_q = div_s64_rem(-97375LL * cfrl_ctrlval, 990 + temp_div, &temp_r); 991 + } 992 + if (temp_r >= temp_div / 2) 993 + temp_q++; 994 + if (cfrl_ctrlval > 0) 995 + temp_q *= -1; 996 + *offset = temp_q; 997 + return 0; 998 + } 999 + 1000 + static int cxd2841er_get_carrier_offset_t2(struct cxd2841er_priv *priv, 1001 + u32 bandwidth, int *offset) 1002 + { 1003 + u8 data[4]; 1004 + 1005 + dev_dbg(&priv->i2c->dev, "%s()\n", __func__); 1006 + if (priv->state != STATE_ACTIVE_TC) { 1007 + dev_dbg(&priv->i2c->dev, "%s(): invalid state %d\n", 1008 + __func__, priv->state); 1009 + return -EINVAL; 1010 + } 1011 + if (priv->system != SYS_DVBT2) { 1012 + dev_dbg(&priv->i2c->dev, "%s(): invalid delivery system %d\n", 1013 + __func__, priv->system); 1014 + return -EINVAL; 1015 + } 1016 + cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x20); 1017 + cxd2841er_read_regs(priv, I2C_SLVT, 0x4c, data, sizeof(data)); 1018 + *offset = -1 * sign_extend32( 1019 + ((u32)(data[0] & 0x0F) << 24) | ((u32)data[1] << 16) | 1020 + ((u32)data[2] << 8) | (u32)data[3], 27); 1021 + switch (bandwidth) { 1022 + case 1712000: 1023 + *offset /= 582; 1024 + break; 1025 + case 5000000: 1026 + case 6000000: 1027 + case 7000000: 1028 + case 8000000: 1029 + *offset *= (bandwidth / 1000000); 1030 + *offset /= 940; 1031 + break; 1032 + default: 1033 + dev_dbg(&priv->i2c->dev, "%s(): invalid bandwidth %d\n", 1034 + __func__, bandwidth); 1035 + return -EINVAL; 1036 + } 1037 + return 0; 1038 + } 1039 + 1040 + static int cxd2841er_get_carrier_offset_c(struct cxd2841er_priv *priv, 1041 + int *offset) 1042 + { 1043 + u8 data[2]; 1044 + 1045 + dev_dbg(&priv->i2c->dev, "%s()\n", __func__); 1046 + if (priv->state != STATE_ACTIVE_TC) { 1047 + dev_dbg(&priv->i2c->dev, "%s(): invalid state %d\n", 1048 + __func__, priv->state); 1049 + return -EINVAL; 1050 + } 1051 + if (priv->system != SYS_DVBC_ANNEX_A) { 1052 + dev_dbg(&priv->i2c->dev, "%s(): invalid delivery system %d\n", 1053 + __func__, priv->system); 1054 + return -EINVAL; 1055 + } 1056 + cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x40); 1057 + cxd2841er_read_regs(priv, I2C_SLVT, 0x15, data, sizeof(data)); 1058 + *offset = div_s64(41000LL * sign_extend32((((u32)data[0] & 0x3f) << 8) 1059 + | (u32)data[1], 13), 16384); 1060 + return 0; 1061 + } 1062 + 1063 + static int cxd2841er_read_packet_errors_t( 1064 + struct cxd2841er_priv *priv, u32 *penum) 1065 + { 1066 + u8 data[3]; 1067 + 1068 + *penum = 0; 1069 + if (priv->state != STATE_ACTIVE_TC) { 1070 + dev_dbg(&priv->i2c->dev, "%s(): invalid state %d\n", 1071 + __func__, priv->state); 1072 + return -EINVAL; 1073 + } 1074 + cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x10); 1075 + cxd2841er_read_regs(priv, I2C_SLVT, 0xea, data, sizeof(data)); 1076 + if (data[2] & 0x01) 1077 + *penum = ((u32)data[0] << 8) | (u32)data[1]; 1078 + return 0; 1079 + } 1080 + 1081 + static int cxd2841er_read_packet_errors_t2( 1082 + struct cxd2841er_priv *priv, u32 *penum) 1083 + { 1084 + u8 data[3]; 1085 + 1086 + *penum = 0; 1087 + if (priv->state != STATE_ACTIVE_TC) { 1088 + dev_dbg(&priv->i2c->dev, "%s(): invalid state %d\n", 1089 + __func__, priv->state); 1090 + return -EINVAL; 1091 + } 1092 + cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x24); 1093 + cxd2841er_read_regs(priv, I2C_SLVT, 0xfd, data, sizeof(data)); 1094 + if (data[0] & 0x01) 1095 + *penum = ((u32)data[1] << 8) | (u32)data[2]; 1096 + return 0; 1097 + } 1098 + 1099 + static u32 cxd2841er_mon_read_ber_s(struct cxd2841er_priv *priv) 1100 + { 1101 + u8 data[11]; 1102 + u32 bit_error, bit_count; 1103 + u32 temp_q, temp_r; 1104 + 1105 + /* Set SLV-T Bank : 0xA0 */ 1106 + cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0xa0); 1107 + /* 1108 + * slave Bank Addr Bit Signal name 1109 + * <SLV-T> A0h 35h [0] IFVBER_VALID 1110 + * <SLV-T> A0h 36h [5:0] IFVBER_BITERR[21:16] 1111 + * <SLV-T> A0h 37h [7:0] IFVBER_BITERR[15:8] 1112 + * <SLV-T> A0h 38h [7:0] IFVBER_BITERR[7:0] 1113 + * <SLV-T> A0h 3Dh [5:0] IFVBER_BITNUM[21:16] 1114 + * <SLV-T> A0h 3Eh [7:0] IFVBER_BITNUM[15:8] 1115 + * <SLV-T> A0h 3Fh [7:0] IFVBER_BITNUM[7:0] 1116 + */ 1117 + cxd2841er_read_regs(priv, I2C_SLVT, 0x35, data, 11); 1118 + if (data[0] & 0x01) { 1119 + bit_error = ((u32)(data[1] & 0x3F) << 16) | 1120 + ((u32)(data[2] & 0xFF) << 8) | 1121 + (u32)(data[3] & 0xFF); 1122 + bit_count = ((u32)(data[8] & 0x3F) << 16) | 1123 + ((u32)(data[9] & 0xFF) << 8) | 1124 + (u32)(data[10] & 0xFF); 1125 + /* 1126 + * BER = bitError / bitCount 1127 + * = (bitError * 10^7) / bitCount 1128 + * = ((bitError * 625 * 125 * 128) / bitCount 1129 + */ 1130 + if ((bit_count == 0) || (bit_error > bit_count)) { 1131 + dev_dbg(&priv->i2c->dev, 1132 + "%s(): invalid bit_error %d, bit_count %d\n", 1133 + __func__, bit_error, bit_count); 1134 + return 0; 1135 + } 1136 + temp_q = div_u64_rem(10000000ULL * bit_error, 1137 + bit_count, &temp_r); 1138 + if (bit_count != 1 && temp_r >= bit_count / 2) 1139 + temp_q++; 1140 + return temp_q; 1141 + } 1142 + dev_dbg(&priv->i2c->dev, "%s(): no data available\n", __func__); 1143 + return 0; 1144 + } 1145 + 1146 + 1147 + static u32 cxd2841er_mon_read_ber_s2(struct cxd2841er_priv *priv) 1148 + { 1149 + u8 data[5]; 1150 + u32 bit_error, period; 1151 + u32 temp_q, temp_r; 1152 + u32 result = 0; 1153 + 1154 + /* Set SLV-T Bank : 0xB2 */ 1155 + cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0xb2); 1156 + /* 1157 + * slave Bank Addr Bit Signal name 1158 + * <SLV-T> B2h 30h [0] IFLBER_VALID 1159 + * <SLV-T> B2h 31h [3:0] IFLBER_BITERR[27:24] 1160 + * <SLV-T> B2h 32h [7:0] IFLBER_BITERR[23:16] 1161 + * <SLV-T> B2h 33h [7:0] IFLBER_BITERR[15:8] 1162 + * <SLV-T> B2h 34h [7:0] IFLBER_BITERR[7:0] 1163 + */ 1164 + cxd2841er_read_regs(priv, I2C_SLVT, 0x30, data, 5); 1165 + if (data[0] & 0x01) { 1166 + /* Bit error count */ 1167 + bit_error = ((u32)(data[1] & 0x0F) << 24) | 1168 + ((u32)(data[2] & 0xFF) << 16) | 1169 + ((u32)(data[3] & 0xFF) << 8) | 1170 + (u32)(data[4] & 0xFF); 1171 + 1172 + /* Set SLV-T Bank : 0xA0 */ 1173 + cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0xa0); 1174 + cxd2841er_read_reg(priv, I2C_SLVT, 0x7a, data); 1175 + /* Measurement period */ 1176 + period = (u32)(1 << (data[0] & 0x0F)); 1177 + if (period == 0) { 1178 + dev_dbg(&priv->i2c->dev, 1179 + "%s(): period is 0\n", __func__); 1180 + return 0; 1181 + } 1182 + if (bit_error > (period * 64800)) { 1183 + dev_dbg(&priv->i2c->dev, 1184 + "%s(): invalid bit_err 0x%x period 0x%x\n", 1185 + __func__, bit_error, period); 1186 + return 0; 1187 + } 1188 + /* 1189 + * BER = bitError / (period * 64800) 1190 + * = (bitError * 10^7) / (period * 64800) 1191 + * = (bitError * 10^5) / (period * 648) 1192 + * = (bitError * 12500) / (period * 81) 1193 + * = (bitError * 10) * 1250 / (period * 81) 1194 + */ 1195 + temp_q = div_u64_rem(12500ULL * bit_error, 1196 + period * 81, &temp_r); 1197 + if (temp_r >= period * 40) 1198 + temp_q++; 1199 + result = temp_q; 1200 + } else { 1201 + dev_dbg(&priv->i2c->dev, 1202 + "%s(): no data available\n", __func__); 1203 + } 1204 + return result; 1205 + } 1206 + 1207 + static int cxd2841er_read_ber_t2(struct cxd2841er_priv *priv, u32 *ber) 1208 + { 1209 + u8 data[4]; 1210 + u32 div, q, r; 1211 + u32 bit_err, period_exp, n_ldpc; 1212 + 1213 + *ber = 0; 1214 + if (priv->state != STATE_ACTIVE_TC) { 1215 + dev_dbg(&priv->i2c->dev, 1216 + "%s(): invalid state %d\n", __func__, priv->state); 1217 + return -EINVAL; 1218 + } 1219 + cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x20); 1220 + cxd2841er_read_regs(priv, I2C_SLVT, 0x39, data, sizeof(data)); 1221 + if (!(data[0] & 0x10)) { 1222 + dev_dbg(&priv->i2c->dev, 1223 + "%s(): no valid BER data\n", __func__); 1224 + return 0; 1225 + } 1226 + bit_err = ((u32)(data[0] & 0x0f) << 24) | 1227 + ((u32)data[1] << 16) | 1228 + ((u32)data[2] << 8) | 1229 + (u32)data[3]; 1230 + cxd2841er_read_reg(priv, I2C_SLVT, 0x6f, data); 1231 + period_exp = data[0] & 0x0f; 1232 + cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x22); 1233 + cxd2841er_read_reg(priv, I2C_SLVT, 0x5e, data); 1234 + n_ldpc = ((data[0] & 0x03) == 0 ? 16200 : 64800); 1235 + if (bit_err > ((1U << period_exp) * n_ldpc)) { 1236 + dev_dbg(&priv->i2c->dev, 1237 + "%s(): invalid BER value\n", __func__); 1238 + return -EINVAL; 1239 + } 1240 + if (period_exp >= 4) { 1241 + div = (1U << (period_exp - 4)) * (n_ldpc / 200); 1242 + q = div_u64_rem(3125ULL * bit_err, div, &r); 1243 + } else { 1244 + div = (1U << period_exp) * (n_ldpc / 200); 1245 + q = div_u64_rem(50000ULL * bit_err, div, &r); 1246 + } 1247 + *ber = (r >= div / 2) ? q + 1 : q; 1248 + return 0; 1249 + } 1250 + 1251 + static int cxd2841er_read_ber_t(struct cxd2841er_priv *priv, u32 *ber) 1252 + { 1253 + u8 data[2]; 1254 + u32 div, q, r; 1255 + u32 bit_err, period; 1256 + 1257 + *ber = 0; 1258 + if (priv->state != STATE_ACTIVE_TC) { 1259 + dev_dbg(&priv->i2c->dev, 1260 + "%s(): invalid state %d\n", __func__, priv->state); 1261 + return -EINVAL; 1262 + } 1263 + cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x10); 1264 + cxd2841er_read_reg(priv, I2C_SLVT, 0x39, data); 1265 + if (!(data[0] & 0x01)) { 1266 + dev_dbg(&priv->i2c->dev, 1267 + "%s(): no valid BER data\n", __func__); 1268 + return 0; 1269 + } 1270 + cxd2841er_read_regs(priv, I2C_SLVT, 0x22, data, sizeof(data)); 1271 + bit_err = ((u32)data[0] << 8) | (u32)data[1]; 1272 + cxd2841er_read_reg(priv, I2C_SLVT, 0x6f, data); 1273 + period = ((data[0] & 0x07) == 0) ? 256 : (4096 << (data[0] & 0x07)); 1274 + div = period / 128; 1275 + q = div_u64_rem(78125ULL * bit_err, div, &r); 1276 + *ber = (r >= div / 2) ? q + 1 : q; 1277 + return 0; 1278 + } 1279 + 1280 + static u32 cxd2841er_dvbs_read_snr(struct cxd2841er_priv *priv, u8 delsys) 1281 + { 1282 + u8 data[3]; 1283 + u32 res = 0, value; 1284 + int min_index, max_index, index; 1285 + static const struct cxd2841er_cnr_data *cn_data; 1286 + 1287 + /* Set SLV-T Bank : 0xA1 */ 1288 + cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0xa1); 1289 + /* 1290 + * slave Bank Addr Bit Signal name 1291 + * <SLV-T> A1h 10h [0] ICPM_QUICKRDY 1292 + * <SLV-T> A1h 11h [4:0] ICPM_QUICKCNDT[12:8] 1293 + * <SLV-T> A1h 12h [7:0] ICPM_QUICKCNDT[7:0] 1294 + */ 1295 + cxd2841er_read_regs(priv, I2C_SLVT, 0x10, data, 3); 1296 + if (data[0] & 0x01) { 1297 + value = ((u32)(data[1] & 0x1F) << 8) | (u32)(data[2] & 0xFF); 1298 + min_index = 0; 1299 + if (delsys == SYS_DVBS) { 1300 + cn_data = s_cn_data; 1301 + max_index = sizeof(s_cn_data) / 1302 + sizeof(s_cn_data[0]) - 1; 1303 + } else { 1304 + cn_data = s2_cn_data; 1305 + max_index = sizeof(s2_cn_data) / 1306 + sizeof(s2_cn_data[0]) - 1; 1307 + } 1308 + if (value >= cn_data[min_index].value) { 1309 + res = cn_data[min_index].cnr_x1000; 1310 + goto done; 1311 + } 1312 + if (value <= cn_data[max_index].value) { 1313 + res = cn_data[max_index].cnr_x1000; 1314 + goto done; 1315 + } 1316 + while ((max_index - min_index) > 1) { 1317 + index = (max_index + min_index) / 2; 1318 + if (value == cn_data[index].value) { 1319 + res = cn_data[index].cnr_x1000; 1320 + goto done; 1321 + } else if (value > cn_data[index].value) 1322 + max_index = index; 1323 + else 1324 + min_index = index; 1325 + if ((max_index - min_index) <= 1) { 1326 + if (value == cn_data[max_index].value) { 1327 + res = cn_data[max_index].cnr_x1000; 1328 + goto done; 1329 + } else { 1330 + res = cn_data[min_index].cnr_x1000; 1331 + goto done; 1332 + } 1333 + } 1334 + } 1335 + } else { 1336 + dev_dbg(&priv->i2c->dev, 1337 + "%s(): no data available\n", __func__); 1338 + } 1339 + done: 1340 + return res; 1341 + } 1342 + 1343 + static int cxd2841er_read_snr_t(struct cxd2841er_priv *priv, u32 *snr) 1344 + { 1345 + u32 reg; 1346 + u8 data[2]; 1347 + 1348 + *snr = 0; 1349 + if (priv->state != STATE_ACTIVE_TC) { 1350 + dev_dbg(&priv->i2c->dev, 1351 + "%s(): invalid state %d\n", __func__, priv->state); 1352 + return -EINVAL; 1353 + } 1354 + cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x10); 1355 + cxd2841er_read_regs(priv, I2C_SLVT, 0x28, data, sizeof(data)); 1356 + reg = ((u32)data[0] << 8) | (u32)data[1]; 1357 + if (reg == 0) { 1358 + dev_dbg(&priv->i2c->dev, 1359 + "%s(): reg value out of range\n", __func__); 1360 + return 0; 1361 + } 1362 + if (reg > 4996) 1363 + reg = 4996; 1364 + *snr = 10000 * ((intlog10(reg) - intlog10(5350 - reg)) >> 24) + 28500; 1365 + return 0; 1366 + } 1367 + 1368 + static int cxd2841er_read_snr_t2(struct cxd2841er_priv *priv, u32 *snr) 1369 + { 1370 + u32 reg; 1371 + u8 data[2]; 1372 + 1373 + *snr = 0; 1374 + if (priv->state != STATE_ACTIVE_TC) { 1375 + dev_dbg(&priv->i2c->dev, 1376 + "%s(): invalid state %d\n", __func__, priv->state); 1377 + return -EINVAL; 1378 + } 1379 + cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x20); 1380 + cxd2841er_read_regs(priv, I2C_SLVT, 0x28, data, sizeof(data)); 1381 + reg = ((u32)data[0] << 8) | (u32)data[1]; 1382 + if (reg == 0) { 1383 + dev_dbg(&priv->i2c->dev, 1384 + "%s(): reg value out of range\n", __func__); 1385 + return 0; 1386 + } 1387 + if (reg > 10876) 1388 + reg = 10876; 1389 + *snr = 10000 * ((intlog10(reg) - 1390 + intlog10(12600 - reg)) >> 24) + 32000; 1391 + return 0; 1392 + } 1393 + 1394 + static u16 cxd2841er_read_agc_gain_t_t2(struct cxd2841er_priv *priv, 1395 + u8 delsys) 1396 + { 1397 + u8 data[2]; 1398 + 1399 + cxd2841er_write_reg( 1400 + priv, I2C_SLVT, 0x00, (delsys == SYS_DVBT ? 0x10 : 0x20)); 1401 + cxd2841er_read_regs(priv, I2C_SLVT, 0x26, data, 2); 1402 + return ((((u16)data[0] & 0x0F) << 8) | (u16)(data[1] & 0xFF)) << 4; 1403 + } 1404 + 1405 + static u16 cxd2841er_read_agc_gain_s(struct cxd2841er_priv *priv) 1406 + { 1407 + u8 data[2]; 1408 + 1409 + /* Set SLV-T Bank : 0xA0 */ 1410 + cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0xa0); 1411 + /* 1412 + * slave Bank Addr Bit Signal name 1413 + * <SLV-T> A0h 1Fh [4:0] IRFAGC_GAIN[12:8] 1414 + * <SLV-T> A0h 20h [7:0] IRFAGC_GAIN[7:0] 1415 + */ 1416 + cxd2841er_read_regs(priv, I2C_SLVT, 0x1f, data, 2); 1417 + return ((((u16)data[0] & 0x1F) << 8) | (u16)(data[1] & 0xFF)) << 3; 1418 + } 1419 + 1420 + static int cxd2841er_read_ber(struct dvb_frontend *fe, u32 *ber) 1421 + { 1422 + struct dtv_frontend_properties *p = &fe->dtv_property_cache; 1423 + struct cxd2841er_priv *priv = fe->demodulator_priv; 1424 + 1425 + dev_dbg(&priv->i2c->dev, "%s()\n", __func__); 1426 + *ber = 0; 1427 + switch (p->delivery_system) { 1428 + case SYS_DVBS: 1429 + *ber = cxd2841er_mon_read_ber_s(priv); 1430 + break; 1431 + case SYS_DVBS2: 1432 + *ber = cxd2841er_mon_read_ber_s2(priv); 1433 + break; 1434 + case SYS_DVBT: 1435 + return cxd2841er_read_ber_t(priv, ber); 1436 + case SYS_DVBT2: 1437 + return cxd2841er_read_ber_t2(priv, ber); 1438 + default: 1439 + *ber = 0; 1440 + break; 1441 + } 1442 + return 0; 1443 + } 1444 + 1445 + static int cxd2841er_read_signal_strength(struct dvb_frontend *fe, 1446 + u16 *strength) 1447 + { 1448 + struct dtv_frontend_properties *p = &fe->dtv_property_cache; 1449 + struct cxd2841er_priv *priv = fe->demodulator_priv; 1450 + 1451 + dev_dbg(&priv->i2c->dev, "%s()\n", __func__); 1452 + switch (p->delivery_system) { 1453 + case SYS_DVBT: 1454 + case SYS_DVBT2: 1455 + *strength = 65535 - cxd2841er_read_agc_gain_t_t2( 1456 + priv, p->delivery_system); 1457 + break; 1458 + case SYS_DVBS: 1459 + case SYS_DVBS2: 1460 + *strength = 65535 - cxd2841er_read_agc_gain_s(priv); 1461 + break; 1462 + default: 1463 + *strength = 0; 1464 + break; 1465 + } 1466 + return 0; 1467 + } 1468 + 1469 + static int cxd2841er_read_snr(struct dvb_frontend *fe, u16 *snr) 1470 + { 1471 + u32 tmp = 0; 1472 + struct dtv_frontend_properties *p = &fe->dtv_property_cache; 1473 + struct cxd2841er_priv *priv = fe->demodulator_priv; 1474 + 1475 + dev_dbg(&priv->i2c->dev, "%s()\n", __func__); 1476 + switch (p->delivery_system) { 1477 + case SYS_DVBT: 1478 + cxd2841er_read_snr_t(priv, &tmp); 1479 + break; 1480 + case SYS_DVBT2: 1481 + cxd2841er_read_snr_t2(priv, &tmp); 1482 + break; 1483 + case SYS_DVBS: 1484 + case SYS_DVBS2: 1485 + tmp = cxd2841er_dvbs_read_snr(priv, p->delivery_system); 1486 + break; 1487 + default: 1488 + dev_dbg(&priv->i2c->dev, "%s(): unknown delivery system %d\n", 1489 + __func__, p->delivery_system); 1490 + break; 1491 + } 1492 + *snr = tmp & 0xffff; 1493 + return 0; 1494 + } 1495 + 1496 + static int cxd2841er_read_ucblocks(struct dvb_frontend *fe, u32 *ucblocks) 1497 + { 1498 + struct dtv_frontend_properties *p = &fe->dtv_property_cache; 1499 + struct cxd2841er_priv *priv = fe->demodulator_priv; 1500 + 1501 + dev_dbg(&priv->i2c->dev, "%s()\n", __func__); 1502 + switch (p->delivery_system) { 1503 + case SYS_DVBT: 1504 + cxd2841er_read_packet_errors_t(priv, ucblocks); 1505 + break; 1506 + case SYS_DVBT2: 1507 + cxd2841er_read_packet_errors_t2(priv, ucblocks); 1508 + break; 1509 + default: 1510 + *ucblocks = 0; 1511 + break; 1512 + } 1513 + dev_dbg(&priv->i2c->dev, "%s()\n", __func__); 1514 + return 0; 1515 + } 1516 + 1517 + static int cxd2841er_dvbt2_set_profile( 1518 + struct cxd2841er_priv *priv, enum cxd2841er_dvbt2_profile_t profile) 1519 + { 1520 + u8 tune_mode; 1521 + u8 seq_not2d_time; 1522 + 1523 + dev_dbg(&priv->i2c->dev, "%s()\n", __func__); 1524 + switch (profile) { 1525 + case DVBT2_PROFILE_BASE: 1526 + tune_mode = 0x01; 1527 + seq_not2d_time = 12; 1528 + break; 1529 + case DVBT2_PROFILE_LITE: 1530 + tune_mode = 0x05; 1531 + seq_not2d_time = 40; 1532 + break; 1533 + case DVBT2_PROFILE_ANY: 1534 + tune_mode = 0x00; 1535 + seq_not2d_time = 40; 1536 + break; 1537 + default: 1538 + return -EINVAL; 1539 + } 1540 + /* Set SLV-T Bank : 0x2E */ 1541 + cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x2e); 1542 + /* Set profile and tune mode */ 1543 + cxd2841er_set_reg_bits(priv, I2C_SLVT, 0x10, tune_mode, 0x07); 1544 + /* Set SLV-T Bank : 0x2B */ 1545 + cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x2b); 1546 + /* Set early unlock detection time */ 1547 + cxd2841er_write_reg(priv, I2C_SLVT, 0x9d, seq_not2d_time); 1548 + return 0; 1549 + } 1550 + 1551 + static int cxd2841er_dvbt2_set_plp_config(struct cxd2841er_priv *priv, 1552 + u8 is_auto, u8 plp_id) 1553 + { 1554 + if (is_auto) { 1555 + dev_dbg(&priv->i2c->dev, 1556 + "%s() using auto PLP selection\n", __func__); 1557 + } else { 1558 + dev_dbg(&priv->i2c->dev, 1559 + "%s() using manual PLP selection, ID %d\n", 1560 + __func__, plp_id); 1561 + } 1562 + /* Set SLV-T Bank : 0x23 */ 1563 + cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x23); 1564 + if (!is_auto) { 1565 + /* Manual PLP selection mode. Set the data PLP Id. */ 1566 + cxd2841er_write_reg(priv, I2C_SLVT, 0xaf, plp_id); 1567 + } 1568 + /* Auto PLP select (Scanning mode = 0x00). Data PLP select = 0x01. */ 1569 + cxd2841er_write_reg(priv, I2C_SLVT, 0xad, (is_auto ? 0x00 : 0x01)); 1570 + return 0; 1571 + } 1572 + 1573 + static int cxd2841er_sleep_tc_to_active_t2_band(struct cxd2841er_priv *priv, 1574 + u32 bandwidth) 1575 + { 1576 + u32 iffreq; 1577 + u8 b20_9f[5]; 1578 + u8 b10_a6[14]; 1579 + u8 b10_b6[3]; 1580 + u8 b10_d7; 1581 + 1582 + dev_dbg(&priv->i2c->dev, "%s()\n", __func__); 1583 + switch (bandwidth) { 1584 + case 8000000: 1585 + /* bank 0x20, reg 0x9f */ 1586 + b20_9f[0] = 0x11; 1587 + b20_9f[1] = 0xf0; 1588 + b20_9f[2] = 0x00; 1589 + b20_9f[3] = 0x00; 1590 + b20_9f[4] = 0x00; 1591 + /* bank 0x10, reg 0xa6 */ 1592 + b10_a6[0] = 0x26; 1593 + b10_a6[1] = 0xaf; 1594 + b10_a6[2] = 0x06; 1595 + b10_a6[3] = 0xcd; 1596 + b10_a6[4] = 0x13; 1597 + b10_a6[5] = 0xbb; 1598 + b10_a6[6] = 0x28; 1599 + b10_a6[7] = 0xba; 1600 + b10_a6[8] = 0x23; 1601 + b10_a6[9] = 0xa9; 1602 + b10_a6[10] = 0x1f; 1603 + b10_a6[11] = 0xa8; 1604 + b10_a6[12] = 0x2c; 1605 + b10_a6[13] = 0xc8; 1606 + iffreq = MAKE_IFFREQ_CONFIG(4.80); 1607 + b10_d7 = 0x00; 1608 + break; 1609 + case 7000000: 1610 + /* bank 0x20, reg 0x9f */ 1611 + b20_9f[0] = 0x14; 1612 + b20_9f[1] = 0x80; 1613 + b20_9f[2] = 0x00; 1614 + b20_9f[3] = 0x00; 1615 + b20_9f[4] = 0x00; 1616 + /* bank 0x10, reg 0xa6 */ 1617 + b10_a6[0] = 0x2C; 1618 + b10_a6[1] = 0xBD; 1619 + b10_a6[2] = 0x02; 1620 + b10_a6[3] = 0xCF; 1621 + b10_a6[4] = 0x04; 1622 + b10_a6[5] = 0xF8; 1623 + b10_a6[6] = 0x23; 1624 + b10_a6[7] = 0xA6; 1625 + b10_a6[8] = 0x29; 1626 + b10_a6[9] = 0xB0; 1627 + b10_a6[10] = 0x26; 1628 + b10_a6[11] = 0xA9; 1629 + b10_a6[12] = 0x21; 1630 + b10_a6[13] = 0xA5; 1631 + iffreq = MAKE_IFFREQ_CONFIG(4.2); 1632 + b10_d7 = 0x02; 1633 + break; 1634 + case 6000000: 1635 + /* bank 0x20, reg 0x9f */ 1636 + b20_9f[0] = 0x17; 1637 + b20_9f[1] = 0xEA; 1638 + b20_9f[2] = 0xAA; 1639 + b20_9f[3] = 0xAA; 1640 + b20_9f[4] = 0xAA; 1641 + /* bank 0x10, reg 0xa6 */ 1642 + b10_a6[0] = 0x27; 1643 + b10_a6[1] = 0xA7; 1644 + b10_a6[2] = 0x28; 1645 + b10_a6[3] = 0xB3; 1646 + b10_a6[4] = 0x02; 1647 + b10_a6[5] = 0xF0; 1648 + b10_a6[6] = 0x01; 1649 + b10_a6[7] = 0xE8; 1650 + b10_a6[8] = 0x00; 1651 + b10_a6[9] = 0xCF; 1652 + b10_a6[10] = 0x00; 1653 + b10_a6[11] = 0xE6; 1654 + b10_a6[12] = 0x23; 1655 + b10_a6[13] = 0xA4; 1656 + iffreq = MAKE_IFFREQ_CONFIG(3.6); 1657 + b10_d7 = 0x04; 1658 + break; 1659 + case 5000000: 1660 + /* bank 0x20, reg 0x9f */ 1661 + b20_9f[0] = 0x1C; 1662 + b20_9f[1] = 0xB3; 1663 + b20_9f[2] = 0x33; 1664 + b20_9f[3] = 0x33; 1665 + b20_9f[4] = 0x33; 1666 + /* bank 0x10, reg 0xa6 */ 1667 + b10_a6[0] = 0x27; 1668 + b10_a6[1] = 0xA7; 1669 + b10_a6[2] = 0x28; 1670 + b10_a6[3] = 0xB3; 1671 + b10_a6[4] = 0x02; 1672 + b10_a6[5] = 0xF0; 1673 + b10_a6[6] = 0x01; 1674 + b10_a6[7] = 0xE8; 1675 + b10_a6[8] = 0x00; 1676 + b10_a6[9] = 0xCF; 1677 + b10_a6[10] = 0x00; 1678 + b10_a6[11] = 0xE6; 1679 + b10_a6[12] = 0x23; 1680 + b10_a6[13] = 0xA4; 1681 + iffreq = MAKE_IFFREQ_CONFIG(3.6); 1682 + b10_d7 = 0x06; 1683 + break; 1684 + case 1712000: 1685 + /* bank 0x20, reg 0x9f */ 1686 + b20_9f[0] = 0x58; 1687 + b20_9f[1] = 0xE2; 1688 + b20_9f[2] = 0xAF; 1689 + b20_9f[3] = 0xE0; 1690 + b20_9f[4] = 0xBC; 1691 + /* bank 0x10, reg 0xa6 */ 1692 + b10_a6[0] = 0x25; 1693 + b10_a6[1] = 0xA0; 1694 + b10_a6[2] = 0x36; 1695 + b10_a6[3] = 0x8D; 1696 + b10_a6[4] = 0x2E; 1697 + b10_a6[5] = 0x94; 1698 + b10_a6[6] = 0x28; 1699 + b10_a6[7] = 0x9B; 1700 + b10_a6[8] = 0x32; 1701 + b10_a6[9] = 0x90; 1702 + b10_a6[10] = 0x2C; 1703 + b10_a6[11] = 0x9D; 1704 + b10_a6[12] = 0x29; 1705 + b10_a6[13] = 0x99; 1706 + iffreq = MAKE_IFFREQ_CONFIG(3.5); 1707 + b10_d7 = 0x03; 1708 + break; 1709 + default: 1710 + return -EINVAL; 1711 + } 1712 + /* Set SLV-T Bank : 0x20 */ 1713 + cxd2841er_write_reg(priv, I2C_SLVX, 0x00, 0x20); 1714 + cxd2841er_write_regs(priv, I2C_SLVT, 0x9f, b20_9f, sizeof(b20_9f)); 1715 + /* Set SLV-T Bank : 0x27 */ 1716 + cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x27); 1717 + cxd2841er_set_reg_bits( 1718 + priv, I2C_SLVT, 0x7a, 1719 + (bandwidth == 1712000 ? 0x03 : 0x00), 0x0f); 1720 + /* Set SLV-T Bank : 0x10 */ 1721 + cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x10); 1722 + /* Group delay equaliser sett. for ASCOT2E */ 1723 + cxd2841er_write_regs(priv, I2C_SLVT, 0xa6, b10_a6, sizeof(b10_a6)); 1724 + /* <IF freq setting> */ 1725 + b10_b6[0] = (u8) ((iffreq >> 16) & 0xff); 1726 + b10_b6[1] = (u8)((iffreq >> 8) & 0xff); 1727 + b10_b6[2] = (u8)(iffreq & 0xff); 1728 + cxd2841er_write_regs(priv, I2C_SLVT, 0xb6, b10_b6, sizeof(b10_b6)); 1729 + /* System bandwidth setting */ 1730 + cxd2841er_set_reg_bits(priv, I2C_SLVT, 0xd7, b10_d7, 0x07); 1731 + return 0; 1732 + } 1733 + 1734 + static int cxd2841er_sleep_tc_to_active_t_band( 1735 + struct cxd2841er_priv *priv, u32 bandwidth) 1736 + { 1737 + u8 b13_9c[2] = { 0x01, 0x14 }; 1738 + u8 bw8mhz_b10_9f[] = { 0x11, 0xF0, 0x00, 0x00, 0x00 }; 1739 + u8 bw8mhz_b10_a6[] = { 0x26, 0xAF, 0x06, 0xCD, 0x13, 0xBB, 1740 + 0x28, 0xBA, 0x23, 0xA9, 0x1F, 0xA8, 0x2C, 0xC8 }; 1741 + u8 bw8mhz_b10_d9[] = { 0x01, 0xE0 }; 1742 + u8 bw8mhz_b17_38[] = { 0x01, 0x02 }; 1743 + u8 bw7mhz_b10_9f[] = { 0x14, 0x80, 0x00, 0x00, 0x00 }; 1744 + u8 bw7mhz_b10_a6[] = { 0x2C, 0xBD, 0x02, 0xCF, 0x04, 0xF8, 1745 + 0x23, 0xA6, 0x29, 0xB0, 0x26, 0xA9, 0x21, 0xA5 }; 1746 + u8 bw7mhz_b10_d9[] = { 0x12, 0xF8 }; 1747 + u8 bw7mhz_b17_38[] = { 0x00, 0x03 }; 1748 + u8 bw6mhz_b10_9f[] = { 0x17, 0xEA, 0xAA, 0xAA, 0xAA }; 1749 + u8 bw6mhz_b10_a6[] = { 0x27, 0xA7, 0x28, 0xB3, 0x02, 0xF0, 1750 + 0x01, 0xE8, 0x00, 0xCF, 0x00, 0xE6, 0x23, 0xA4 }; 1751 + u8 bw6mhz_b10_d9[] = { 0x1F, 0xDC }; 1752 + u8 bw6mhz_b17_38[] = { 0x00, 0x03 }; 1753 + u8 bw5mhz_b10_9f[] = { 0x1C, 0xB3, 0x33, 0x33, 0x33 }; 1754 + u8 bw5mhz_b10_a6[] = { 0x27, 0xA7, 0x28, 0xB3, 0x02, 0xF0, 1755 + 0x01, 0xE8, 0x00, 0xCF, 0x00, 0xE6, 0x23, 0xA4 }; 1756 + u8 bw5mhz_b10_d9[] = { 0x26, 0x3C }; 1757 + u8 bw5mhz_b17_38[] = { 0x00, 0x03 }; 1758 + u8 b10_b6[3]; 1759 + u8 d7val; 1760 + u32 iffreq; 1761 + u8 *b10_9f; 1762 + u8 *b10_a6; 1763 + u8 *b10_d9; 1764 + u8 *b17_38; 1765 + 1766 + dev_dbg(&priv->i2c->dev, "%s()\n", __func__); 1767 + cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x13); 1768 + /* Echo performance optimization setting */ 1769 + cxd2841er_write_regs(priv, I2C_SLVT, 0x9c, b13_9c, sizeof(b13_9c)); 1770 + cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x10); 1771 + 1772 + switch (bandwidth) { 1773 + case 8000000: 1774 + b10_9f = bw8mhz_b10_9f; 1775 + b10_a6 = bw8mhz_b10_a6; 1776 + b10_d9 = bw8mhz_b10_d9; 1777 + b17_38 = bw8mhz_b17_38; 1778 + d7val = 0; 1779 + iffreq = MAKE_IFFREQ_CONFIG(4.80); 1780 + break; 1781 + case 7000000: 1782 + b10_9f = bw7mhz_b10_9f; 1783 + b10_a6 = bw7mhz_b10_a6; 1784 + b10_d9 = bw7mhz_b10_d9; 1785 + b17_38 = bw7mhz_b17_38; 1786 + d7val = 2; 1787 + iffreq = MAKE_IFFREQ_CONFIG(4.20); 1788 + break; 1789 + case 6000000: 1790 + b10_9f = bw6mhz_b10_9f; 1791 + b10_a6 = bw6mhz_b10_a6; 1792 + b10_d9 = bw6mhz_b10_d9; 1793 + b17_38 = bw6mhz_b17_38; 1794 + d7val = 4; 1795 + iffreq = MAKE_IFFREQ_CONFIG(3.60); 1796 + break; 1797 + case 5000000: 1798 + b10_9f = bw5mhz_b10_9f; 1799 + b10_a6 = bw5mhz_b10_a6; 1800 + b10_d9 = bw5mhz_b10_d9; 1801 + b17_38 = bw5mhz_b17_38; 1802 + d7val = 6; 1803 + iffreq = MAKE_IFFREQ_CONFIG(3.60); 1804 + break; 1805 + default: 1806 + dev_dbg(&priv->i2c->dev, "%s(): invalid bandwidth %d\n", 1807 + __func__, bandwidth); 1808 + return -EINVAL; 1809 + } 1810 + /* <IF freq setting> */ 1811 + b10_b6[0] = (u8) ((iffreq >> 16) & 0xff); 1812 + b10_b6[1] = (u8)((iffreq >> 8) & 0xff); 1813 + b10_b6[2] = (u8)(iffreq & 0xff); 1814 + cxd2841er_write_regs( 1815 + priv, I2C_SLVT, 0x9f, b10_9f, sizeof(bw8mhz_b10_9f)); 1816 + cxd2841er_write_regs( 1817 + priv, I2C_SLVT, 0xa6, b10_a6, sizeof(bw8mhz_b10_a6)); 1818 + cxd2841er_write_regs(priv, I2C_SLVT, 0xb6, b10_b6, sizeof(b10_b6)); 1819 + cxd2841er_set_reg_bits(priv, I2C_SLVT, 0xd7, d7val, 0x7); 1820 + cxd2841er_write_regs( 1821 + priv, I2C_SLVT, 0xd9, b10_d9, sizeof(bw8mhz_b10_d9)); 1822 + cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x17); 1823 + cxd2841er_write_regs( 1824 + priv, I2C_SLVT, 0x38, b17_38, sizeof(bw8mhz_b17_38)); 1825 + return 0; 1826 + } 1827 + 1828 + static int cxd2841er_sleep_tc_to_active_c_band(struct cxd2841er_priv *priv, 1829 + u32 bandwidth) 1830 + { 1831 + u8 bw7_8mhz_b10_a6[] = { 1832 + 0x2D, 0xC7, 0x04, 0xF4, 0x07, 0xC5, 0x2A, 0xB8, 1833 + 0x27, 0x9E, 0x27, 0xA4, 0x29, 0xAB }; 1834 + u8 bw6mhz_b10_a6[] = { 1835 + 0x27, 0xA7, 0x28, 0xB3, 0x02, 0xF0, 0x01, 0xE8, 1836 + 0x00, 0xCF, 0x00, 0xE6, 0x23, 0xA4 }; 1837 + u8 b10_b6[3]; 1838 + u32 iffreq; 1839 + 1840 + dev_dbg(&priv->i2c->dev, "%s()\n", __func__); 1841 + cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x10); 1842 + switch (bandwidth) { 1843 + case 8000000: 1844 + case 7000000: 1845 + cxd2841er_write_regs( 1846 + priv, I2C_SLVT, 0xa6, 1847 + bw7_8mhz_b10_a6, sizeof(bw7_8mhz_b10_a6)); 1848 + iffreq = MAKE_IFFREQ_CONFIG(4.9); 1849 + break; 1850 + case 6000000: 1851 + cxd2841er_write_regs( 1852 + priv, I2C_SLVT, 0xa6, 1853 + bw6mhz_b10_a6, sizeof(bw6mhz_b10_a6)); 1854 + iffreq = MAKE_IFFREQ_CONFIG(3.7); 1855 + break; 1856 + default: 1857 + dev_dbg(&priv->i2c->dev, "%s(): unsupported bandwidth %d\n", 1858 + __func__, bandwidth); 1859 + return -EINVAL; 1860 + } 1861 + /* <IF freq setting> */ 1862 + b10_b6[0] = (u8) ((iffreq >> 16) & 0xff); 1863 + b10_b6[1] = (u8)((iffreq >> 8) & 0xff); 1864 + b10_b6[2] = (u8)(iffreq & 0xff); 1865 + cxd2841er_write_regs(priv, I2C_SLVT, 0xb6, b10_b6, sizeof(b10_b6)); 1866 + /* Set SLV-T Bank : 0x11 */ 1867 + cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x11); 1868 + switch (bandwidth) { 1869 + case 8000000: 1870 + case 7000000: 1871 + cxd2841er_set_reg_bits( 1872 + priv, I2C_SLVT, 0xa3, 0x00, 0x1f); 1873 + break; 1874 + case 6000000: 1875 + cxd2841er_set_reg_bits( 1876 + priv, I2C_SLVT, 0xa3, 0x14, 0x1f); 1877 + break; 1878 + } 1879 + /* Set SLV-T Bank : 0x40 */ 1880 + cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x40); 1881 + switch (bandwidth) { 1882 + case 8000000: 1883 + cxd2841er_set_reg_bits( 1884 + priv, I2C_SLVT, 0x26, 0x0b, 0x0f); 1885 + cxd2841er_write_reg(priv, I2C_SLVT, 0x27, 0x3e); 1886 + break; 1887 + case 7000000: 1888 + cxd2841er_set_reg_bits( 1889 + priv, I2C_SLVT, 0x26, 0x09, 0x0f); 1890 + cxd2841er_write_reg(priv, I2C_SLVT, 0x27, 0xd6); 1891 + break; 1892 + case 6000000: 1893 + cxd2841er_set_reg_bits( 1894 + priv, I2C_SLVT, 0x26, 0x08, 0x0f); 1895 + cxd2841er_write_reg(priv, I2C_SLVT, 0x27, 0x6e); 1896 + break; 1897 + } 1898 + return 0; 1899 + } 1900 + 1901 + static int cxd2841er_sleep_tc_to_active_t(struct cxd2841er_priv *priv, 1902 + u32 bandwidth) 1903 + { 1904 + u8 data[2] = { 0x09, 0x54 }; 1905 + 1906 + dev_dbg(&priv->i2c->dev, "%s()\n", __func__); 1907 + cxd2841er_set_ts_clock_mode(priv, SYS_DVBT); 1908 + /* Set SLV-X Bank : 0x00 */ 1909 + cxd2841er_write_reg(priv, I2C_SLVX, 0x00, 0x00); 1910 + /* Set demod mode */ 1911 + cxd2841er_write_reg(priv, I2C_SLVX, 0x17, 0x01); 1912 + /* Set SLV-T Bank : 0x00 */ 1913 + cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x00); 1914 + /* Enable demod clock */ 1915 + cxd2841er_write_reg(priv, I2C_SLVT, 0x2c, 0x01); 1916 + /* Disable RF level monitor */ 1917 + cxd2841er_write_reg(priv, I2C_SLVT, 0x2f, 0x00); 1918 + /* Enable ADC clock */ 1919 + cxd2841er_write_reg(priv, I2C_SLVT, 0x30, 0x00); 1920 + /* Enable ADC 1 */ 1921 + cxd2841er_write_reg(priv, I2C_SLVT, 0x41, 0x1a); 1922 + /* xtal freq 20.5MHz */ 1923 + cxd2841er_write_regs(priv, I2C_SLVT, 0x43, data, 2); 1924 + /* Enable ADC 4 */ 1925 + cxd2841er_write_reg(priv, I2C_SLVX, 0x18, 0x00); 1926 + /* Set SLV-T Bank : 0x10 */ 1927 + cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x10); 1928 + /* IFAGC gain settings */ 1929 + cxd2841er_set_reg_bits(priv, I2C_SLVT, 0xd2, 0x0c, 0x1f); 1930 + /* Set SLV-T Bank : 0x11 */ 1931 + cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x11); 1932 + /* BBAGC TARGET level setting */ 1933 + cxd2841er_write_reg(priv, I2C_SLVT, 0x6a, 0x50); 1934 + /* Set SLV-T Bank : 0x10 */ 1935 + cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x10); 1936 + /* ASCOT setting ON */ 1937 + cxd2841er_set_reg_bits(priv, I2C_SLVT, 0xa5, 0x01, 0x01); 1938 + /* Set SLV-T Bank : 0x18 */ 1939 + cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x18); 1940 + /* Pre-RS BER moniter setting */ 1941 + cxd2841er_set_reg_bits(priv, I2C_SLVT, 0x36, 0x40, 0x07); 1942 + /* FEC Auto Recovery setting */ 1943 + cxd2841er_set_reg_bits(priv, I2C_SLVT, 0x30, 0x01, 0x01); 1944 + cxd2841er_set_reg_bits(priv, I2C_SLVT, 0x31, 0x01, 0x01); 1945 + /* Set SLV-T Bank : 0x00 */ 1946 + cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x00); 1947 + /* TSIF setting */ 1948 + cxd2841er_set_reg_bits(priv, I2C_SLVT, 0xce, 0x01, 0x01); 1949 + cxd2841er_set_reg_bits(priv, I2C_SLVT, 0xcf, 0x01, 0x01); 1950 + cxd2841er_sleep_tc_to_active_t_band(priv, bandwidth); 1951 + /* Set SLV-T Bank : 0x00 */ 1952 + cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x00); 1953 + /* Disable HiZ Setting 1 */ 1954 + cxd2841er_write_reg(priv, I2C_SLVT, 0x80, 0x28); 1955 + /* Disable HiZ Setting 2 */ 1956 + cxd2841er_write_reg(priv, I2C_SLVT, 0x81, 0x00); 1957 + priv->state = STATE_ACTIVE_TC; 1958 + return 0; 1959 + } 1960 + 1961 + static int cxd2841er_sleep_tc_to_active_t2(struct cxd2841er_priv *priv, 1962 + u32 bandwidth) 1963 + { 1964 + u8 data[2] = { 0x09, 0x54 }; 1965 + 1966 + dev_dbg(&priv->i2c->dev, "%s()\n", __func__); 1967 + cxd2841er_set_ts_clock_mode(priv, SYS_DVBT2); 1968 + /* Set SLV-X Bank : 0x00 */ 1969 + cxd2841er_write_reg(priv, I2C_SLVX, 0x00, 0x00); 1970 + /* Set demod mode */ 1971 + cxd2841er_write_reg(priv, I2C_SLVX, 0x17, 0x02); 1972 + /* Set SLV-T Bank : 0x00 */ 1973 + cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x00); 1974 + /* Enable demod clock */ 1975 + cxd2841er_write_reg(priv, I2C_SLVT, 0x2c, 0x01); 1976 + /* Disable RF level monitor */ 1977 + cxd2841er_write_reg(priv, I2C_SLVT, 0x2f, 0x00); 1978 + /* Enable ADC clock */ 1979 + cxd2841er_write_reg(priv, I2C_SLVT, 0x30, 0x00); 1980 + /* Enable ADC 1 */ 1981 + cxd2841er_write_reg(priv, I2C_SLVT, 0x41, 0x1a); 1982 + /* xtal freq 20.5MHz */ 1983 + cxd2841er_write_regs(priv, I2C_SLVT, 0x43, data, 2); 1984 + /* Enable ADC 4 */ 1985 + cxd2841er_write_reg(priv, I2C_SLVX, 0x18, 0x00); 1986 + /* Set SLV-T Bank : 0x10 */ 1987 + cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x10); 1988 + /* IFAGC gain settings */ 1989 + cxd2841er_set_reg_bits(priv, I2C_SLVT, 0xd2, 0x0c, 0x1f); 1990 + /* Set SLV-T Bank : 0x11 */ 1991 + cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x11); 1992 + /* BBAGC TARGET level setting */ 1993 + cxd2841er_write_reg(priv, I2C_SLVT, 0x6a, 0x50); 1994 + /* Set SLV-T Bank : 0x10 */ 1995 + cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x10); 1996 + /* ASCOT setting ON */ 1997 + cxd2841er_set_reg_bits(priv, I2C_SLVT, 0xa5, 0x01, 0x01); 1998 + /* Set SLV-T Bank : 0x20 */ 1999 + cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x20); 2000 + /* Acquisition optimization setting */ 2001 + cxd2841er_write_reg(priv, I2C_SLVT, 0x8b, 0x3c); 2002 + /* Set SLV-T Bank : 0x2b */ 2003 + cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x2b); 2004 + cxd2841er_set_reg_bits(priv, I2C_SLVT, 0x76, 0x20, 0x70); 2005 + /* Set SLV-T Bank : 0x00 */ 2006 + cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x00); 2007 + /* TSIF setting */ 2008 + cxd2841er_set_reg_bits(priv, I2C_SLVT, 0xce, 0x01, 0x01); 2009 + cxd2841er_set_reg_bits(priv, I2C_SLVT, 0xcf, 0x01, 0x01); 2010 + /* DVB-T2 initial setting */ 2011 + cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x13); 2012 + cxd2841er_write_reg(priv, I2C_SLVT, 0x83, 0x10); 2013 + cxd2841er_write_reg(priv, I2C_SLVT, 0x86, 0x34); 2014 + cxd2841er_set_reg_bits(priv, I2C_SLVT, 0x9e, 0x09, 0x0f); 2015 + cxd2841er_write_reg(priv, I2C_SLVT, 0x9f, 0xd8); 2016 + /* Set SLV-T Bank : 0x2a */ 2017 + cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x2a); 2018 + cxd2841er_set_reg_bits(priv, I2C_SLVT, 0x38, 0x04, 0x0f); 2019 + /* Set SLV-T Bank : 0x2b */ 2020 + cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x2b); 2021 + cxd2841er_set_reg_bits(priv, I2C_SLVT, 0x11, 0x20, 0x3f); 2022 + 2023 + cxd2841er_sleep_tc_to_active_t2_band(priv, bandwidth); 2024 + 2025 + /* Set SLV-T Bank : 0x00 */ 2026 + cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x00); 2027 + /* Disable HiZ Setting 1 */ 2028 + cxd2841er_write_reg(priv, I2C_SLVT, 0x80, 0x28); 2029 + /* Disable HiZ Setting 2 */ 2030 + cxd2841er_write_reg(priv, I2C_SLVT, 0x81, 0x00); 2031 + priv->state = STATE_ACTIVE_TC; 2032 + return 0; 2033 + } 2034 + 2035 + static int cxd2841er_sleep_tc_to_active_c(struct cxd2841er_priv *priv, 2036 + u32 bandwidth) 2037 + { 2038 + u8 data[2] = { 0x09, 0x54 }; 2039 + 2040 + dev_dbg(&priv->i2c->dev, "%s()\n", __func__); 2041 + cxd2841er_set_ts_clock_mode(priv, SYS_DVBC_ANNEX_A); 2042 + /* Set SLV-X Bank : 0x00 */ 2043 + cxd2841er_write_reg(priv, I2C_SLVX, 0x00, 0x00); 2044 + /* Set demod mode */ 2045 + cxd2841er_write_reg(priv, I2C_SLVX, 0x17, 0x04); 2046 + /* Set SLV-T Bank : 0x00 */ 2047 + cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x00); 2048 + /* Enable demod clock */ 2049 + cxd2841er_write_reg(priv, I2C_SLVT, 0x2c, 0x01); 2050 + /* Disable RF level monitor */ 2051 + cxd2841er_write_reg(priv, I2C_SLVT, 0x2f, 0x00); 2052 + /* Enable ADC clock */ 2053 + cxd2841er_write_reg(priv, I2C_SLVT, 0x30, 0x00); 2054 + /* Enable ADC 1 */ 2055 + cxd2841er_write_reg(priv, I2C_SLVT, 0x41, 0x1a); 2056 + /* xtal freq 20.5MHz */ 2057 + cxd2841er_write_regs(priv, I2C_SLVT, 0x43, data, 2); 2058 + /* Enable ADC 4 */ 2059 + cxd2841er_write_reg(priv, I2C_SLVX, 0x18, 0x00); 2060 + /* Set SLV-T Bank : 0x10 */ 2061 + cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x10); 2062 + /* IFAGC gain settings */ 2063 + cxd2841er_set_reg_bits(priv, I2C_SLVT, 0xd2, 0x09, 0x1f); 2064 + /* Set SLV-T Bank : 0x11 */ 2065 + cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x11); 2066 + /* BBAGC TARGET level setting */ 2067 + cxd2841er_write_reg(priv, I2C_SLVT, 0x6a, 0x48); 2068 + /* Set SLV-T Bank : 0x10 */ 2069 + cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x10); 2070 + /* ASCOT setting ON */ 2071 + cxd2841er_set_reg_bits(priv, I2C_SLVT, 0xa5, 0x01, 0x01); 2072 + /* Set SLV-T Bank : 0x40 */ 2073 + cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x40); 2074 + /* Demod setting */ 2075 + cxd2841er_set_reg_bits(priv, I2C_SLVT, 0xc3, 0x00, 0x04); 2076 + /* Set SLV-T Bank : 0x00 */ 2077 + cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x00); 2078 + /* TSIF setting */ 2079 + cxd2841er_set_reg_bits(priv, I2C_SLVT, 0xce, 0x01, 0x01); 2080 + cxd2841er_set_reg_bits(priv, I2C_SLVT, 0xcf, 0x01, 0x01); 2081 + 2082 + cxd2841er_sleep_tc_to_active_c_band(priv, 8000000); 2083 + /* Set SLV-T Bank : 0x00 */ 2084 + cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x00); 2085 + /* Disable HiZ Setting 1 */ 2086 + cxd2841er_write_reg(priv, I2C_SLVT, 0x80, 0x28); 2087 + /* Disable HiZ Setting 2 */ 2088 + cxd2841er_write_reg(priv, I2C_SLVT, 0x81, 0x00); 2089 + priv->state = STATE_ACTIVE_TC; 2090 + return 0; 2091 + } 2092 + 2093 + static int cxd2841er_get_frontend(struct dvb_frontend *fe) 2094 + { 2095 + enum fe_status status = 0; 2096 + u16 strength = 0, snr = 0; 2097 + u32 errors = 0, ber = 0; 2098 + struct cxd2841er_priv *priv = fe->demodulator_priv; 2099 + struct dtv_frontend_properties *p = &fe->dtv_property_cache; 2100 + 2101 + dev_dbg(&priv->i2c->dev, "%s()\n", __func__); 2102 + if (priv->state == STATE_ACTIVE_S) 2103 + cxd2841er_read_status_s(fe, &status); 2104 + else if (priv->state == STATE_ACTIVE_TC) 2105 + cxd2841er_read_status_tc(fe, &status); 2106 + 2107 + if (status & FE_HAS_LOCK) { 2108 + cxd2841er_read_signal_strength(fe, &strength); 2109 + p->strength.len = 1; 2110 + p->strength.stat[0].scale = FE_SCALE_RELATIVE; 2111 + p->strength.stat[0].uvalue = strength; 2112 + cxd2841er_read_snr(fe, &snr); 2113 + p->cnr.len = 1; 2114 + p->cnr.stat[0].scale = FE_SCALE_DECIBEL; 2115 + p->cnr.stat[0].svalue = snr; 2116 + cxd2841er_read_ucblocks(fe, &errors); 2117 + p->block_error.len = 1; 2118 + p->block_error.stat[0].scale = FE_SCALE_COUNTER; 2119 + p->block_error.stat[0].uvalue = errors; 2120 + cxd2841er_read_ber(fe, &ber); 2121 + p->post_bit_error.len = 1; 2122 + p->post_bit_error.stat[0].scale = FE_SCALE_COUNTER; 2123 + p->post_bit_error.stat[0].uvalue = ber; 2124 + } else { 2125 + p->strength.len = 1; 2126 + p->strength.stat[0].scale = FE_SCALE_NOT_AVAILABLE; 2127 + p->cnr.len = 1; 2128 + p->cnr.stat[0].scale = FE_SCALE_NOT_AVAILABLE; 2129 + p->block_error.len = 1; 2130 + p->block_error.stat[0].scale = FE_SCALE_NOT_AVAILABLE; 2131 + p->post_bit_error.len = 1; 2132 + p->post_bit_error.stat[0].scale = FE_SCALE_NOT_AVAILABLE; 2133 + } 2134 + return 0; 2135 + } 2136 + 2137 + static int cxd2841er_set_frontend_s(struct dvb_frontend *fe) 2138 + { 2139 + int ret = 0, i, timeout, carr_offset; 2140 + enum fe_status status; 2141 + struct cxd2841er_priv *priv = fe->demodulator_priv; 2142 + struct dtv_frontend_properties *p = &fe->dtv_property_cache; 2143 + u32 symbol_rate = p->symbol_rate/1000; 2144 + 2145 + dev_dbg(&priv->i2c->dev, "%s(): %s frequency=%d symbol_rate=%d\n", 2146 + __func__, 2147 + (p->delivery_system == SYS_DVBS ? "DVB-S" : "DVB-S2"), 2148 + p->frequency, symbol_rate); 2149 + switch (priv->state) { 2150 + case STATE_SLEEP_S: 2151 + ret = cxd2841er_sleep_s_to_active_s( 2152 + priv, p->delivery_system, symbol_rate); 2153 + break; 2154 + case STATE_ACTIVE_S: 2155 + ret = cxd2841er_retune_active(priv, p); 2156 + break; 2157 + default: 2158 + dev_dbg(&priv->i2c->dev, "%s(): invalid state %d\n", 2159 + __func__, priv->state); 2160 + ret = -EINVAL; 2161 + goto done; 2162 + } 2163 + if (ret) { 2164 + dev_dbg(&priv->i2c->dev, "%s(): tune failed\n", __func__); 2165 + goto done; 2166 + } 2167 + if (fe->ops.i2c_gate_ctrl) 2168 + fe->ops.i2c_gate_ctrl(fe, 1); 2169 + if (fe->ops.tuner_ops.set_params) 2170 + fe->ops.tuner_ops.set_params(fe); 2171 + if (fe->ops.i2c_gate_ctrl) 2172 + fe->ops.i2c_gate_ctrl(fe, 0); 2173 + cxd2841er_tune_done(priv); 2174 + timeout = ((3000000 + (symbol_rate - 1)) / symbol_rate) + 150; 2175 + for (i = 0; i < timeout / CXD2841ER_DVBS_POLLING_INVL; i++) { 2176 + usleep_range(CXD2841ER_DVBS_POLLING_INVL*1000, 2177 + (CXD2841ER_DVBS_POLLING_INVL + 2) * 1000); 2178 + cxd2841er_read_status_s(fe, &status); 2179 + if (status & FE_HAS_LOCK) 2180 + break; 2181 + } 2182 + if (status & FE_HAS_LOCK) { 2183 + if (cxd2841er_get_carrier_offset_s_s2( 2184 + priv, &carr_offset)) { 2185 + ret = -EINVAL; 2186 + goto done; 2187 + } 2188 + dev_dbg(&priv->i2c->dev, "%s(): carrier_offset=%d\n", 2189 + __func__, carr_offset); 2190 + } 2191 + done: 2192 + return ret; 2193 + } 2194 + 2195 + static int cxd2841er_set_frontend_tc(struct dvb_frontend *fe) 2196 + { 2197 + int ret = 0, timeout; 2198 + enum fe_status status; 2199 + struct cxd2841er_priv *priv = fe->demodulator_priv; 2200 + struct dtv_frontend_properties *p = &fe->dtv_property_cache; 2201 + 2202 + dev_dbg(&priv->i2c->dev, "%s()\n", __func__); 2203 + if (p->delivery_system == SYS_DVBT) { 2204 + priv->system = SYS_DVBT; 2205 + switch (priv->state) { 2206 + case STATE_SLEEP_TC: 2207 + ret = cxd2841er_sleep_tc_to_active_t( 2208 + priv, p->bandwidth_hz); 2209 + break; 2210 + case STATE_ACTIVE_TC: 2211 + ret = cxd2841er_retune_active(priv, p); 2212 + break; 2213 + default: 2214 + dev_dbg(&priv->i2c->dev, "%s(): invalid state %d\n", 2215 + __func__, priv->state); 2216 + ret = -EINVAL; 2217 + } 2218 + } else if (p->delivery_system == SYS_DVBT2) { 2219 + priv->system = SYS_DVBT2; 2220 + cxd2841er_dvbt2_set_plp_config(priv, 2221 + (int)(p->stream_id > 255), p->stream_id); 2222 + cxd2841er_dvbt2_set_profile(priv, DVBT2_PROFILE_BASE); 2223 + switch (priv->state) { 2224 + case STATE_SLEEP_TC: 2225 + ret = cxd2841er_sleep_tc_to_active_t2(priv, 2226 + p->bandwidth_hz); 2227 + break; 2228 + case STATE_ACTIVE_TC: 2229 + ret = cxd2841er_retune_active(priv, p); 2230 + break; 2231 + default: 2232 + dev_dbg(&priv->i2c->dev, "%s(): invalid state %d\n", 2233 + __func__, priv->state); 2234 + ret = -EINVAL; 2235 + } 2236 + } else if (p->delivery_system == SYS_DVBC_ANNEX_A || 2237 + p->delivery_system == SYS_DVBC_ANNEX_C) { 2238 + priv->system = SYS_DVBC_ANNEX_A; 2239 + switch (priv->state) { 2240 + case STATE_SLEEP_TC: 2241 + ret = cxd2841er_sleep_tc_to_active_c( 2242 + priv, p->bandwidth_hz); 2243 + break; 2244 + case STATE_ACTIVE_TC: 2245 + ret = cxd2841er_retune_active(priv, p); 2246 + break; 2247 + default: 2248 + dev_dbg(&priv->i2c->dev, "%s(): invalid state %d\n", 2249 + __func__, priv->state); 2250 + ret = -EINVAL; 2251 + } 2252 + } else { 2253 + dev_dbg(&priv->i2c->dev, 2254 + "%s(): invalid delivery system %d\n", 2255 + __func__, p->delivery_system); 2256 + ret = -EINVAL; 2257 + } 2258 + if (ret) 2259 + goto done; 2260 + if (fe->ops.i2c_gate_ctrl) 2261 + fe->ops.i2c_gate_ctrl(fe, 1); 2262 + if (fe->ops.tuner_ops.set_params) 2263 + fe->ops.tuner_ops.set_params(fe); 2264 + if (fe->ops.i2c_gate_ctrl) 2265 + fe->ops.i2c_gate_ctrl(fe, 0); 2266 + cxd2841er_tune_done(priv); 2267 + timeout = 2500; 2268 + while (timeout > 0) { 2269 + ret = cxd2841er_read_status_tc(fe, &status); 2270 + if (ret) 2271 + goto done; 2272 + if (status & FE_HAS_LOCK) 2273 + break; 2274 + msleep(20); 2275 + timeout -= 20; 2276 + } 2277 + if (timeout < 0) 2278 + dev_dbg(&priv->i2c->dev, 2279 + "%s(): LOCK wait timeout\n", __func__); 2280 + done: 2281 + return ret; 2282 + } 2283 + 2284 + static int cxd2841er_tune_s(struct dvb_frontend *fe, 2285 + bool re_tune, 2286 + unsigned int mode_flags, 2287 + unsigned int *delay, 2288 + enum fe_status *status) 2289 + { 2290 + int ret, carrier_offset; 2291 + struct cxd2841er_priv *priv = fe->demodulator_priv; 2292 + struct dtv_frontend_properties *p = &fe->dtv_property_cache; 2293 + 2294 + dev_dbg(&priv->i2c->dev, "%s() re_tune=%d\n", __func__, re_tune); 2295 + if (re_tune) { 2296 + ret = cxd2841er_set_frontend_s(fe); 2297 + if (ret) 2298 + return ret; 2299 + cxd2841er_read_status_s(fe, status); 2300 + if (*status & FE_HAS_LOCK) { 2301 + if (cxd2841er_get_carrier_offset_s_s2( 2302 + priv, &carrier_offset)) 2303 + return -EINVAL; 2304 + p->frequency += carrier_offset; 2305 + ret = cxd2841er_set_frontend_s(fe); 2306 + if (ret) 2307 + return ret; 2308 + } 2309 + } 2310 + *delay = HZ / 5; 2311 + return cxd2841er_read_status_s(fe, status); 2312 + } 2313 + 2314 + static int cxd2841er_tune_tc(struct dvb_frontend *fe, 2315 + bool re_tune, 2316 + unsigned int mode_flags, 2317 + unsigned int *delay, 2318 + enum fe_status *status) 2319 + { 2320 + int ret, carrier_offset; 2321 + struct cxd2841er_priv *priv = fe->demodulator_priv; 2322 + struct dtv_frontend_properties *p = &fe->dtv_property_cache; 2323 + 2324 + dev_dbg(&priv->i2c->dev, "%s(): re_tune %d\n", __func__, re_tune); 2325 + if (re_tune) { 2326 + ret = cxd2841er_set_frontend_tc(fe); 2327 + if (ret) 2328 + return ret; 2329 + cxd2841er_read_status_tc(fe, status); 2330 + if (*status & FE_HAS_LOCK) { 2331 + switch (priv->system) { 2332 + case SYS_DVBT: 2333 + case SYS_DVBT2: 2334 + ret = cxd2841er_get_carrier_offset_t2( 2335 + priv, p->bandwidth_hz, 2336 + &carrier_offset); 2337 + break; 2338 + case SYS_DVBC_ANNEX_A: 2339 + ret = cxd2841er_get_carrier_offset_c( 2340 + priv, &carrier_offset); 2341 + break; 2342 + default: 2343 + dev_dbg(&priv->i2c->dev, 2344 + "%s(): invalid delivery system %d\n", 2345 + __func__, priv->system); 2346 + return -EINVAL; 2347 + } 2348 + if (ret) 2349 + return ret; 2350 + dev_dbg(&priv->i2c->dev, "%s(): carrier offset %d\n", 2351 + __func__, carrier_offset); 2352 + p->frequency += carrier_offset; 2353 + ret = cxd2841er_set_frontend_tc(fe); 2354 + if (ret) 2355 + return ret; 2356 + } 2357 + } 2358 + *delay = HZ / 5; 2359 + return cxd2841er_read_status_tc(fe, status); 2360 + } 2361 + 2362 + static int cxd2841er_sleep_s(struct dvb_frontend *fe) 2363 + { 2364 + struct cxd2841er_priv *priv = fe->demodulator_priv; 2365 + 2366 + dev_dbg(&priv->i2c->dev, "%s()\n", __func__); 2367 + cxd2841er_active_s_to_sleep_s(fe->demodulator_priv); 2368 + cxd2841er_sleep_s_to_shutdown(fe->demodulator_priv); 2369 + return 0; 2370 + } 2371 + 2372 + static int cxd2841er_sleep_tc(struct dvb_frontend *fe) 2373 + { 2374 + struct cxd2841er_priv *priv = fe->demodulator_priv; 2375 + 2376 + dev_dbg(&priv->i2c->dev, "%s()\n", __func__); 2377 + if (priv->state == STATE_ACTIVE_TC) { 2378 + switch (priv->system) { 2379 + case SYS_DVBT: 2380 + cxd2841er_active_t_to_sleep_tc(priv); 2381 + break; 2382 + case SYS_DVBT2: 2383 + cxd2841er_active_t2_to_sleep_tc(priv); 2384 + break; 2385 + case SYS_DVBC_ANNEX_A: 2386 + cxd2841er_active_c_to_sleep_tc(priv); 2387 + break; 2388 + default: 2389 + dev_warn(&priv->i2c->dev, 2390 + "%s(): unknown delivery system %d\n", 2391 + __func__, priv->system); 2392 + } 2393 + } 2394 + if (priv->state != STATE_SLEEP_TC) { 2395 + dev_err(&priv->i2c->dev, "%s(): invalid state %d\n", 2396 + __func__, priv->state); 2397 + return -EINVAL; 2398 + } 2399 + cxd2841er_sleep_tc_to_shutdown(priv); 2400 + return 0; 2401 + } 2402 + 2403 + static int cxd2841er_send_burst(struct dvb_frontend *fe, 2404 + enum fe_sec_mini_cmd burst) 2405 + { 2406 + u8 data; 2407 + struct cxd2841er_priv *priv = fe->demodulator_priv; 2408 + 2409 + dev_dbg(&priv->i2c->dev, "%s(): burst mode %s\n", __func__, 2410 + (burst == SEC_MINI_A ? "A" : "B")); 2411 + if (priv->state != STATE_SLEEP_S && 2412 + priv->state != STATE_ACTIVE_S) { 2413 + dev_err(&priv->i2c->dev, "%s(): invalid demod state %d\n", 2414 + __func__, priv->state); 2415 + return -EINVAL; 2416 + } 2417 + data = (burst == SEC_MINI_A ? 0 : 1); 2418 + cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0xbb); 2419 + cxd2841er_write_reg(priv, I2C_SLVT, 0x34, 0x01); 2420 + cxd2841er_write_reg(priv, I2C_SLVT, 0x35, data); 2421 + return 0; 2422 + } 2423 + 2424 + static int cxd2841er_set_tone(struct dvb_frontend *fe, 2425 + enum fe_sec_tone_mode tone) 2426 + { 2427 + u8 data; 2428 + struct cxd2841er_priv *priv = fe->demodulator_priv; 2429 + 2430 + dev_dbg(&priv->i2c->dev, "%s(): tone %s\n", __func__, 2431 + (tone == SEC_TONE_ON ? "On" : "Off")); 2432 + if (priv->state != STATE_SLEEP_S && 2433 + priv->state != STATE_ACTIVE_S) { 2434 + dev_err(&priv->i2c->dev, "%s(): invalid demod state %d\n", 2435 + __func__, priv->state); 2436 + return -EINVAL; 2437 + } 2438 + data = (tone == SEC_TONE_ON ? 1 : 0); 2439 + cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0xbb); 2440 + cxd2841er_write_reg(priv, I2C_SLVT, 0x36, data); 2441 + return 0; 2442 + } 2443 + 2444 + static int cxd2841er_send_diseqc_msg(struct dvb_frontend *fe, 2445 + struct dvb_diseqc_master_cmd *cmd) 2446 + { 2447 + int i; 2448 + u8 data[12]; 2449 + struct cxd2841er_priv *priv = fe->demodulator_priv; 2450 + 2451 + if (priv->state != STATE_SLEEP_S && 2452 + priv->state != STATE_ACTIVE_S) { 2453 + dev_err(&priv->i2c->dev, "%s(): invalid demod state %d\n", 2454 + __func__, priv->state); 2455 + return -EINVAL; 2456 + } 2457 + dev_dbg(&priv->i2c->dev, 2458 + "%s(): cmd->len %d\n", __func__, cmd->msg_len); 2459 + cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0xbb); 2460 + /* DiDEqC enable */ 2461 + cxd2841er_write_reg(priv, I2C_SLVT, 0x33, 0x01); 2462 + /* cmd1 length & data */ 2463 + cxd2841er_write_reg(priv, I2C_SLVT, 0x3d, cmd->msg_len); 2464 + memset(data, 0, sizeof(data)); 2465 + for (i = 0; i < cmd->msg_len && i < sizeof(data); i++) 2466 + data[i] = cmd->msg[i]; 2467 + cxd2841er_write_regs(priv, I2C_SLVT, 0x3e, data, sizeof(data)); 2468 + /* repeat count for cmd1 */ 2469 + cxd2841er_write_reg(priv, I2C_SLVT, 0x37, 1); 2470 + /* repeat count for cmd2: always 0 */ 2471 + cxd2841er_write_reg(priv, I2C_SLVT, 0x38, 0); 2472 + /* start transmit */ 2473 + cxd2841er_write_reg(priv, I2C_SLVT, 0x32, 0x01); 2474 + /* wait for 1 sec timeout */ 2475 + for (i = 0; i < 50; i++) { 2476 + cxd2841er_read_reg(priv, I2C_SLVT, 0x10, data); 2477 + if (!data[0]) { 2478 + dev_dbg(&priv->i2c->dev, 2479 + "%s(): DiSEqC cmd has been sent\n", __func__); 2480 + return 0; 2481 + } 2482 + msleep(20); 2483 + } 2484 + dev_dbg(&priv->i2c->dev, 2485 + "%s(): DiSEqC cmd transmit timeout\n", __func__); 2486 + return -ETIMEDOUT; 2487 + } 2488 + 2489 + static void cxd2841er_release(struct dvb_frontend *fe) 2490 + { 2491 + struct cxd2841er_priv *priv = fe->demodulator_priv; 2492 + 2493 + dev_dbg(&priv->i2c->dev, "%s()\n", __func__); 2494 + kfree(priv); 2495 + } 2496 + 2497 + static int cxd2841er_i2c_gate_ctrl(struct dvb_frontend *fe, int enable) 2498 + { 2499 + struct cxd2841er_priv *priv = fe->demodulator_priv; 2500 + 2501 + dev_dbg(&priv->i2c->dev, "%s(): enable=%d\n", __func__, enable); 2502 + cxd2841er_set_reg_bits( 2503 + priv, I2C_SLVX, 0x8, (enable ? 0x01 : 0x00), 0x01); 2504 + return 0; 2505 + } 2506 + 2507 + static enum dvbfe_algo cxd2841er_get_algo(struct dvb_frontend *fe) 2508 + { 2509 + struct cxd2841er_priv *priv = fe->demodulator_priv; 2510 + 2511 + dev_dbg(&priv->i2c->dev, "%s()\n", __func__); 2512 + return DVBFE_ALGO_HW; 2513 + } 2514 + 2515 + static int cxd2841er_init_s(struct dvb_frontend *fe) 2516 + { 2517 + struct cxd2841er_priv *priv = fe->demodulator_priv; 2518 + 2519 + dev_dbg(&priv->i2c->dev, "%s()\n", __func__); 2520 + cxd2841er_shutdown_to_sleep_s(priv); 2521 + /* SONY_DEMOD_CONFIG_SAT_IFAGCNEG set to 1 */ 2522 + cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0xa0); 2523 + cxd2841er_set_reg_bits(priv, I2C_SLVT, 0xb9, 0x01, 0x01); 2524 + return 0; 2525 + } 2526 + 2527 + static int cxd2841er_init_tc(struct dvb_frontend *fe) 2528 + { 2529 + struct cxd2841er_priv *priv = fe->demodulator_priv; 2530 + 2531 + dev_dbg(&priv->i2c->dev, "%s()\n", __func__); 2532 + cxd2841er_shutdown_to_sleep_tc(priv); 2533 + /* SONY_DEMOD_CONFIG_IFAGCNEG = 1 */ 2534 + cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x10); 2535 + cxd2841er_set_reg_bits(priv, I2C_SLVT, 0xcb, 0x40, 0x40); 2536 + /* SONY_DEMOD_CONFIG_IFAGC_ADC_FS = 0 */ 2537 + cxd2841er_write_reg(priv, I2C_SLVT, 0xcd, 0x50); 2538 + /* SONY_DEMOD_CONFIG_PARALLEL_SEL = 1 */ 2539 + cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x00); 2540 + cxd2841er_set_reg_bits(priv, I2C_SLVT, 0xc4, 0x00, 0x80); 2541 + return 0; 2542 + } 2543 + 2544 + static struct dvb_frontend_ops cxd2841er_dvbs_s2_ops; 2545 + static struct dvb_frontend_ops cxd2841er_dvbt_t2_ops; 2546 + static struct dvb_frontend_ops cxd2841er_dvbc_ops; 2547 + 2548 + static struct dvb_frontend *cxd2841er_attach(struct cxd2841er_config *cfg, 2549 + struct i2c_adapter *i2c, 2550 + u8 system) 2551 + { 2552 + u8 chip_id = 0; 2553 + const char *type; 2554 + struct cxd2841er_priv *priv = NULL; 2555 + 2556 + /* allocate memory for the internal state */ 2557 + priv = kzalloc(sizeof(struct cxd2841er_priv), GFP_KERNEL); 2558 + if (!priv) 2559 + return NULL; 2560 + priv->i2c = i2c; 2561 + priv->config = cfg; 2562 + priv->i2c_addr_slvx = (cfg->i2c_addr + 4) >> 1; 2563 + priv->i2c_addr_slvt = (cfg->i2c_addr) >> 1; 2564 + /* create dvb_frontend */ 2565 + switch (system) { 2566 + case SYS_DVBS: 2567 + memcpy(&priv->frontend.ops, 2568 + &cxd2841er_dvbs_s2_ops, 2569 + sizeof(struct dvb_frontend_ops)); 2570 + type = "S/S2"; 2571 + break; 2572 + case SYS_DVBT: 2573 + memcpy(&priv->frontend.ops, 2574 + &cxd2841er_dvbt_t2_ops, 2575 + sizeof(struct dvb_frontend_ops)); 2576 + type = "T/T2"; 2577 + break; 2578 + case SYS_DVBC_ANNEX_A: 2579 + memcpy(&priv->frontend.ops, 2580 + &cxd2841er_dvbc_ops, 2581 + sizeof(struct dvb_frontend_ops)); 2582 + type = "C/C2"; 2583 + break; 2584 + default: 2585 + kfree(priv); 2586 + return NULL; 2587 + } 2588 + priv->frontend.demodulator_priv = priv; 2589 + dev_info(&priv->i2c->dev, 2590 + "%s(): attaching CXD2841ER DVB-%s frontend\n", 2591 + __func__, type); 2592 + dev_info(&priv->i2c->dev, 2593 + "%s(): I2C adapter %p SLVX addr %x SLVT addr %x\n", 2594 + __func__, priv->i2c, 2595 + priv->i2c_addr_slvx, priv->i2c_addr_slvt); 2596 + chip_id = cxd2841er_chip_id(priv); 2597 + if (chip_id != CXD2841ER_CHIP_ID) { 2598 + dev_err(&priv->i2c->dev, "%s(): invalid chip ID 0x%02x\n", 2599 + __func__, chip_id); 2600 + priv->frontend.demodulator_priv = NULL; 2601 + kfree(priv); 2602 + return NULL; 2603 + } 2604 + dev_info(&priv->i2c->dev, "%s(): chip ID 0x%02x OK.\n", 2605 + __func__, chip_id); 2606 + return &priv->frontend; 2607 + } 2608 + 2609 + struct dvb_frontend *cxd2841er_attach_s(struct cxd2841er_config *cfg, 2610 + struct i2c_adapter *i2c) 2611 + { 2612 + return cxd2841er_attach(cfg, i2c, SYS_DVBS); 2613 + } 2614 + EXPORT_SYMBOL(cxd2841er_attach_s); 2615 + 2616 + struct dvb_frontend *cxd2841er_attach_t(struct cxd2841er_config *cfg, 2617 + struct i2c_adapter *i2c) 2618 + { 2619 + return cxd2841er_attach(cfg, i2c, SYS_DVBT); 2620 + } 2621 + EXPORT_SYMBOL(cxd2841er_attach_t); 2622 + 2623 + struct dvb_frontend *cxd2841er_attach_c(struct cxd2841er_config *cfg, 2624 + struct i2c_adapter *i2c) 2625 + { 2626 + return cxd2841er_attach(cfg, i2c, SYS_DVBC_ANNEX_A); 2627 + } 2628 + EXPORT_SYMBOL(cxd2841er_attach_c); 2629 + 2630 + static struct dvb_frontend_ops cxd2841er_dvbs_s2_ops = { 2631 + .delsys = { SYS_DVBS, SYS_DVBS2 }, 2632 + .info = { 2633 + .name = "Sony CXD2841ER DVB-S/S2 demodulator", 2634 + .frequency_min = 500000, 2635 + .frequency_max = 2500000, 2636 + .frequency_stepsize = 0, 2637 + .symbol_rate_min = 1000000, 2638 + .symbol_rate_max = 45000000, 2639 + .symbol_rate_tolerance = 500, 2640 + .caps = FE_CAN_INVERSION_AUTO | 2641 + FE_CAN_FEC_AUTO | 2642 + FE_CAN_QPSK, 2643 + }, 2644 + .init = cxd2841er_init_s, 2645 + .sleep = cxd2841er_sleep_s, 2646 + .release = cxd2841er_release, 2647 + .set_frontend = cxd2841er_set_frontend_s, 2648 + .get_frontend = cxd2841er_get_frontend, 2649 + .read_status = cxd2841er_read_status_s, 2650 + .i2c_gate_ctrl = cxd2841er_i2c_gate_ctrl, 2651 + .get_frontend_algo = cxd2841er_get_algo, 2652 + .set_tone = cxd2841er_set_tone, 2653 + .diseqc_send_burst = cxd2841er_send_burst, 2654 + .diseqc_send_master_cmd = cxd2841er_send_diseqc_msg, 2655 + .tune = cxd2841er_tune_s 2656 + }; 2657 + 2658 + static struct dvb_frontend_ops cxd2841er_dvbt_t2_ops = { 2659 + .delsys = { SYS_DVBT, SYS_DVBT2 }, 2660 + .info = { 2661 + .name = "Sony CXD2841ER DVB-T/T2 demodulator", 2662 + .caps = FE_CAN_FEC_1_2 | 2663 + FE_CAN_FEC_2_3 | 2664 + FE_CAN_FEC_3_4 | 2665 + FE_CAN_FEC_5_6 | 2666 + FE_CAN_FEC_7_8 | 2667 + FE_CAN_FEC_AUTO | 2668 + FE_CAN_QPSK | 2669 + FE_CAN_QAM_16 | 2670 + FE_CAN_QAM_32 | 2671 + FE_CAN_QAM_64 | 2672 + FE_CAN_QAM_128 | 2673 + FE_CAN_QAM_256 | 2674 + FE_CAN_QAM_AUTO | 2675 + FE_CAN_TRANSMISSION_MODE_AUTO | 2676 + FE_CAN_GUARD_INTERVAL_AUTO | 2677 + FE_CAN_HIERARCHY_AUTO | 2678 + FE_CAN_MUTE_TS | 2679 + FE_CAN_2G_MODULATION, 2680 + .frequency_min = 42000000, 2681 + .frequency_max = 1002000000 2682 + }, 2683 + .init = cxd2841er_init_tc, 2684 + .sleep = cxd2841er_sleep_tc, 2685 + .release = cxd2841er_release, 2686 + .set_frontend = cxd2841er_set_frontend_tc, 2687 + .get_frontend = cxd2841er_get_frontend, 2688 + .read_status = cxd2841er_read_status_tc, 2689 + .tune = cxd2841er_tune_tc, 2690 + .i2c_gate_ctrl = cxd2841er_i2c_gate_ctrl, 2691 + .get_frontend_algo = cxd2841er_get_algo 2692 + }; 2693 + 2694 + static struct dvb_frontend_ops cxd2841er_dvbc_ops = { 2695 + .delsys = { SYS_DVBC_ANNEX_A }, 2696 + .info = { 2697 + .name = "Sony CXD2841ER DVB-C demodulator", 2698 + .caps = FE_CAN_FEC_1_2 | 2699 + FE_CAN_FEC_2_3 | 2700 + FE_CAN_FEC_3_4 | 2701 + FE_CAN_FEC_5_6 | 2702 + FE_CAN_FEC_7_8 | 2703 + FE_CAN_FEC_AUTO | 2704 + FE_CAN_QAM_16 | 2705 + FE_CAN_QAM_32 | 2706 + FE_CAN_QAM_64 | 2707 + FE_CAN_QAM_128 | 2708 + FE_CAN_QAM_256 | 2709 + FE_CAN_QAM_AUTO | 2710 + FE_CAN_INVERSION_AUTO, 2711 + .frequency_min = 42000000, 2712 + .frequency_max = 1002000000 2713 + }, 2714 + .init = cxd2841er_init_tc, 2715 + .sleep = cxd2841er_sleep_tc, 2716 + .release = cxd2841er_release, 2717 + .set_frontend = cxd2841er_set_frontend_tc, 2718 + .get_frontend = cxd2841er_get_frontend, 2719 + .read_status = cxd2841er_read_status_tc, 2720 + .tune = cxd2841er_tune_tc, 2721 + .i2c_gate_ctrl = cxd2841er_i2c_gate_ctrl, 2722 + .get_frontend_algo = cxd2841er_get_algo, 2723 + }; 2724 + 2725 + MODULE_DESCRIPTION("Sony CXD2841ER DVB-C/C2/T/T2/S/S2 demodulator driver"); 2726 + MODULE_AUTHOR("Sergey Kozlov <serjk@netup.ru>"); 2727 + MODULE_LICENSE("GPL");
+65
drivers/media/dvb-frontends/cxd2841er.h
··· 1 + /* 2 + * cxd2841er.h 3 + * 4 + * Sony CXD2441ER digital demodulator driver public definitions 5 + * 6 + * Copyright 2012 Sony Corporation 7 + * Copyright (C) 2014 NetUP Inc. 8 + * Copyright (C) 2014 Sergey Kozlov <serjk@netup.ru> 9 + * Copyright (C) 2014 Abylay Ospan <aospan@netup.ru> 10 + * 11 + * This program is free software; you can redistribute it and/or modify 12 + * it under the terms of the GNU General Public License as published by 13 + * the Free Software Foundation; either version 2 of the License, or 14 + * (at your option) any later version. 15 + * 16 + * This program is distributed in the hope that it will be useful, 17 + * but WITHOUT ANY WARRANTY; without even the implied warranty of 18 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 + * GNU General Public License for more details. 20 + */ 21 + 22 + #ifndef CXD2841ER_H 23 + #define CXD2841ER_H 24 + 25 + #include <linux/kconfig.h> 26 + #include <linux/dvb/frontend.h> 27 + 28 + struct cxd2841er_config { 29 + u8 i2c_addr; 30 + }; 31 + 32 + #if IS_REACHABLE(CONFIG_DVB_CXD2841ER) 33 + extern struct dvb_frontend *cxd2841er_attach_s(struct cxd2841er_config *cfg, 34 + struct i2c_adapter *i2c); 35 + 36 + extern struct dvb_frontend *cxd2841er_attach_t(struct cxd2841er_config *cfg, 37 + struct i2c_adapter *i2c); 38 + 39 + extern struct dvb_frontend *cxd2841er_attach_c(struct cxd2841er_config *cfg, 40 + struct i2c_adapter *i2c); 41 + #else 42 + static inline struct dvb_frontend *cxd2841er_attach_s( 43 + struct cxd2841er_config *cfg, 44 + struct i2c_adapter *i2c) 45 + { 46 + printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __func__); 47 + return NULL; 48 + } 49 + 50 + static inline struct dvb_frontend *cxd2841er_attach_t( 51 + struct cxd2841er_config *cfg, struct i2c_adapter *i2c) 52 + { 53 + printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __func__); 54 + return NULL; 55 + } 56 + 57 + static inline struct dvb_frontend *cxd2841er_attach_c( 58 + struct cxd2841er_config *cfg, struct i2c_adapter *i2c) 59 + { 60 + printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __func__); 61 + return NULL; 62 + } 63 + #endif 64 + 65 + #endif
+43
drivers/media/dvb-frontends/cxd2841er_priv.h
··· 1 + /* 2 + * cxd2841er_priv.h 3 + * 4 + * Sony CXD2441ER digital demodulator driver internal definitions 5 + * 6 + * Copyright 2012 Sony Corporation 7 + * Copyright (C) 2014 NetUP Inc. 8 + * Copyright (C) 2014 Sergey Kozlov <serjk@netup.ru> 9 + * Copyright (C) 2014 Abylay Ospan <aospan@netup.ru> 10 + * 11 + * This program is free software; you can redistribute it and/or modify 12 + * it under the terms of the GNU General Public License as published by 13 + * the Free Software Foundation; either version 2 of the License, or 14 + * (at your option) any later version. 15 + * 16 + * This program is distributed in the hope that it will be useful, 17 + * but WITHOUT ANY WARRANTY; without even the implied warranty of 18 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 + * GNU General Public License for more details. 20 + */ 21 + 22 + #ifndef CXD2841ER_PRIV_H 23 + #define CXD2841ER_PRIV_H 24 + 25 + #define I2C_SLVX 0 26 + #define I2C_SLVT 1 27 + 28 + #define CXD2841ER_CHIP_ID 0xa7 29 + 30 + #define CXD2841ER_DVBS_POLLING_INVL 10 31 + 32 + struct cxd2841er_cnr_data { 33 + u32 value; 34 + int cnr_x1000; 35 + }; 36 + 37 + enum cxd2841er_dvbt2_profile_t { 38 + DVBT2_PROFILE_ANY = 0, 39 + DVBT2_PROFILE_BASE = 1, 40 + DVBT2_PROFILE_LITE = 2 41 + }; 42 + 43 + #endif
+25 -25
drivers/media/dvb-frontends/dvb-pll.c
··· 34 34 struct i2c_adapter *i2c; 35 35 36 36 /* the PLL descriptor */ 37 - struct dvb_pll_desc *pll_desc; 37 + const struct dvb_pll_desc *pll_desc; 38 38 39 39 /* cached frequency/bandwidth */ 40 40 u32 frequency; ··· 57 57 /* ----------------------------------------------------------- */ 58 58 59 59 struct dvb_pll_desc { 60 - char *name; 60 + const char *name; 61 61 u32 min; 62 62 u32 max; 63 63 u32 iffreq; ··· 71 71 u32 stepsize; 72 72 u8 config; 73 73 u8 cb; 74 - } entries[12]; 74 + } entries[]; 75 75 }; 76 76 77 77 /* ----------------------------------------------------------- */ 78 78 /* descriptions */ 79 79 80 - static struct dvb_pll_desc dvb_pll_thomson_dtt7579 = { 80 + static const struct dvb_pll_desc dvb_pll_thomson_dtt7579 = { 81 81 .name = "Thomson dtt7579", 82 82 .min = 177000000, 83 83 .max = 858000000, ··· 99 99 buf[3] |= 0x10; 100 100 } 101 101 102 - static struct dvb_pll_desc dvb_pll_thomson_dtt759x = { 102 + static const struct dvb_pll_desc dvb_pll_thomson_dtt759x = { 103 103 .name = "Thomson dtt759x", 104 104 .min = 177000000, 105 105 .max = 896000000, ··· 123 123 buf[3] ^= 0x10; 124 124 } 125 125 126 - static struct dvb_pll_desc dvb_pll_thomson_dtt7520x = { 126 + static const struct dvb_pll_desc dvb_pll_thomson_dtt7520x = { 127 127 .name = "Thomson dtt7520x", 128 128 .min = 185000000, 129 129 .max = 900000000, ··· 141 141 }, 142 142 }; 143 143 144 - static struct dvb_pll_desc dvb_pll_lg_z201 = { 144 + static const struct dvb_pll_desc dvb_pll_lg_z201 = { 145 145 .name = "LG z201", 146 146 .min = 174000000, 147 147 .max = 862000000, ··· 157 157 }, 158 158 }; 159 159 160 - static struct dvb_pll_desc dvb_pll_unknown_1 = { 160 + static const struct dvb_pll_desc dvb_pll_unknown_1 = { 161 161 .name = "unknown 1", /* used by dntv live dvb-t */ 162 162 .min = 174000000, 163 163 .max = 862000000, ··· 179 179 /* Infineon TUA6010XS 180 180 * used in Thomson Cable Tuner 181 181 */ 182 - static struct dvb_pll_desc dvb_pll_tua6010xs = { 182 + static const struct dvb_pll_desc dvb_pll_tua6010xs = { 183 183 .name = "Infineon TUA6010XS", 184 184 .min = 44250000, 185 185 .max = 858000000, ··· 193 193 }; 194 194 195 195 /* Panasonic env57h1xd5 (some Philips PLL ?) */ 196 - static struct dvb_pll_desc dvb_pll_env57h1xd5 = { 196 + static const struct dvb_pll_desc dvb_pll_env57h1xd5 = { 197 197 .name = "Panasonic ENV57H1XD5", 198 198 .min = 44250000, 199 199 .max = 858000000, ··· 217 217 buf[3] |= 0x08; 218 218 } 219 219 220 - static struct dvb_pll_desc dvb_pll_tda665x = { 220 + static const struct dvb_pll_desc dvb_pll_tda665x = { 221 221 .name = "Philips TDA6650/TDA6651", 222 222 .min = 44250000, 223 223 .max = 858000000, ··· 251 251 buf[3] |= 0x08; 252 252 } 253 253 254 - static struct dvb_pll_desc dvb_pll_tua6034 = { 254 + static const struct dvb_pll_desc dvb_pll_tua6034 = { 255 255 .name = "Infineon TUA6034", 256 256 .min = 44250000, 257 257 .max = 858000000, ··· 275 275 buf[3] |= 0x04; 276 276 } 277 277 278 - static struct dvb_pll_desc dvb_pll_tded4 = { 278 + static const struct dvb_pll_desc dvb_pll_tded4 = { 279 279 .name = "ALPS TDED4", 280 280 .min = 47000000, 281 281 .max = 863000000, ··· 293 293 /* ALPS TDHU2 294 294 * used in AverTVHD MCE A180 295 295 */ 296 - static struct dvb_pll_desc dvb_pll_tdhu2 = { 296 + static const struct dvb_pll_desc dvb_pll_tdhu2 = { 297 297 .name = "ALPS TDHU2", 298 298 .min = 54000000, 299 299 .max = 864000000, ··· 310 310 /* Samsung TBMV30111IN / TBMV30712IN1 311 311 * used in Air2PC ATSC - 2nd generation (nxt2002) 312 312 */ 313 - static struct dvb_pll_desc dvb_pll_samsung_tbmv = { 313 + static const struct dvb_pll_desc dvb_pll_samsung_tbmv = { 314 314 .name = "Samsung TBMV30111IN / TBMV30712IN1", 315 315 .min = 54000000, 316 316 .max = 860000000, ··· 329 329 /* 330 330 * Philips SD1878 Tuner. 331 331 */ 332 - static struct dvb_pll_desc dvb_pll_philips_sd1878_tda8261 = { 332 + static const struct dvb_pll_desc dvb_pll_philips_sd1878_tda8261 = { 333 333 .name = "Philips SD1878", 334 334 .min = 950000, 335 335 .max = 2150000, ··· 395 395 return; 396 396 } 397 397 398 - static struct dvb_pll_desc dvb_pll_opera1 = { 398 + static const struct dvb_pll_desc dvb_pll_opera1 = { 399 399 .name = "Opera Tuner", 400 400 .min = 900000, 401 401 .max = 2250000, ··· 442 442 } 443 443 444 444 /* unknown pll used in Samsung DTOS403IH102A DVB-C tuner */ 445 - static struct dvb_pll_desc dvb_pll_samsung_dtos403ih102a = { 445 + static const struct dvb_pll_desc dvb_pll_samsung_dtos403ih102a = { 446 446 .name = "Samsung DTOS403IH102A", 447 447 .min = 44250000, 448 448 .max = 858000000, ··· 462 462 }; 463 463 464 464 /* Samsung TDTC9251DH0 DVB-T NIM, as used on AirStar 2 */ 465 - static struct dvb_pll_desc dvb_pll_samsung_tdtc9251dh0 = { 465 + static const struct dvb_pll_desc dvb_pll_samsung_tdtc9251dh0 = { 466 466 .name = "Samsung TDTC9251DH0", 467 467 .min = 48000000, 468 468 .max = 863000000, ··· 476 476 }; 477 477 478 478 /* Samsung TBDU18132 DVB-S NIM with TSA5059 PLL, used in SkyStar2 DVB-S 2.3 */ 479 - static struct dvb_pll_desc dvb_pll_samsung_tbdu18132 = { 479 + static const struct dvb_pll_desc dvb_pll_samsung_tbdu18132 = { 480 480 .name = "Samsung TBDU18132", 481 481 .min = 950000, 482 482 .max = 2150000, /* guesses */ ··· 497 497 }; 498 498 499 499 /* Samsung TBMU24112 DVB-S NIM with SL1935 zero-IF tuner */ 500 - static struct dvb_pll_desc dvb_pll_samsung_tbmu24112 = { 500 + static const struct dvb_pll_desc dvb_pll_samsung_tbmu24112 = { 501 501 .name = "Samsung TBMU24112", 502 502 .min = 950000, 503 503 .max = 2150000, /* guesses */ ··· 518 518 * 153 - 430 0 * 0 0 0 0 1 0 0x02 519 519 * 430 - 822 0 * 0 0 1 0 0 0 0x08 520 520 * 822 - 862 1 * 0 0 1 0 0 0 0x88 */ 521 - static struct dvb_pll_desc dvb_pll_alps_tdee4 = { 521 + static const struct dvb_pll_desc dvb_pll_alps_tdee4 = { 522 522 .name = "ALPS TDEE4", 523 523 .min = 47000000, 524 524 .max = 862000000, ··· 534 534 535 535 /* ----------------------------------------------------------- */ 536 536 537 - static struct dvb_pll_desc *pll_list[] = { 537 + static const struct dvb_pll_desc *pll_list[] = { 538 538 [DVB_PLL_UNDEFINED] = NULL, 539 539 [DVB_PLL_THOMSON_DTT7579] = &dvb_pll_thomson_dtt7579, 540 540 [DVB_PLL_THOMSON_DTT759X] = &dvb_pll_thomson_dtt759x, ··· 564 564 const u32 frequency) 565 565 { 566 566 struct dvb_pll_priv *priv = fe->tuner_priv; 567 - struct dvb_pll_desc *desc = priv->pll_desc; 567 + const struct dvb_pll_desc *desc = priv->pll_desc; 568 568 u32 div; 569 569 int i; 570 570 ··· 758 758 .buf = b1, .len = 1 }; 759 759 struct dvb_pll_priv *priv = NULL; 760 760 int ret; 761 - struct dvb_pll_desc *desc; 761 + const struct dvb_pll_desc *desc; 762 762 763 763 if ((id[dvb_pll_devcount] > DVB_PLL_UNDEFINED) && 764 764 (id[dvb_pll_devcount] < ARRAY_SIZE(pll_list)))
+430
drivers/media/dvb-frontends/horus3a.c
··· 1 + /* 2 + * horus3a.h 3 + * 4 + * Sony Horus3A DVB-S/S2 tuner driver 5 + * 6 + * Copyright 2012 Sony Corporation 7 + * Copyright (C) 2014 NetUP Inc. 8 + * Copyright (C) 2014 Sergey Kozlov <serjk@netup.ru> 9 + * Copyright (C) 2014 Abylay Ospan <aospan@netup.ru> 10 + * 11 + * This program is free software; you can redistribute it and/or modify 12 + * it under the terms of the GNU General Public License as published by 13 + * the Free Software Foundation; either version 2 of the License, or 14 + * (at your option) any later version. 15 + * 16 + * This program is distributed in the hope that it will be useful, 17 + * but WITHOUT ANY WARRANTY; without even the implied warranty of 18 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 + * GNU General Public License for more details. 20 + */ 21 + 22 + #include <linux/slab.h> 23 + #include <linux/module.h> 24 + #include <linux/dvb/frontend.h> 25 + #include <linux/types.h> 26 + #include "horus3a.h" 27 + #include "dvb_frontend.h" 28 + 29 + #define MAX_WRITE_REGSIZE 5 30 + 31 + enum horus3a_state { 32 + STATE_UNKNOWN, 33 + STATE_SLEEP, 34 + STATE_ACTIVE 35 + }; 36 + 37 + struct horus3a_priv { 38 + u32 frequency; 39 + u8 i2c_address; 40 + struct i2c_adapter *i2c; 41 + enum horus3a_state state; 42 + void *set_tuner_data; 43 + int (*set_tuner)(void *, int); 44 + }; 45 + 46 + static void horus3a_i2c_debug(struct horus3a_priv *priv, 47 + u8 reg, u8 write, const u8 *data, u32 len) 48 + { 49 + dev_dbg(&priv->i2c->dev, "horus3a: I2C %s reg 0x%02x size %d\n", 50 + (write == 0 ? "read" : "write"), reg, len); 51 + print_hex_dump_bytes("horus3a: I2C data: ", 52 + DUMP_PREFIX_OFFSET, data, len); 53 + } 54 + 55 + static int horus3a_write_regs(struct horus3a_priv *priv, 56 + u8 reg, const u8 *data, u32 len) 57 + { 58 + int ret; 59 + u8 buf[MAX_WRITE_REGSIZE + 1]; 60 + struct i2c_msg msg[1] = { 61 + { 62 + .addr = priv->i2c_address, 63 + .flags = 0, 64 + .len = len + 1, 65 + .buf = buf, 66 + } 67 + }; 68 + 69 + if (len + 1 >= sizeof(buf)) { 70 + dev_warn(&priv->i2c->dev,"wr reg=%04x: len=%d is too big!\n", 71 + reg, len + 1); 72 + return -E2BIG; 73 + } 74 + 75 + horus3a_i2c_debug(priv, reg, 1, data, len); 76 + buf[0] = reg; 77 + memcpy(&buf[1], data, len); 78 + ret = i2c_transfer(priv->i2c, msg, 1); 79 + if (ret >= 0 && ret != 1) 80 + ret = -EREMOTEIO; 81 + if (ret < 0) { 82 + dev_warn(&priv->i2c->dev, 83 + "%s: i2c wr failed=%d reg=%02x len=%d\n", 84 + KBUILD_MODNAME, ret, reg, len); 85 + return ret; 86 + } 87 + return 0; 88 + } 89 + 90 + static int horus3a_write_reg(struct horus3a_priv *priv, u8 reg, u8 val) 91 + { 92 + return horus3a_write_regs(priv, reg, &val, 1); 93 + } 94 + 95 + static int horus3a_enter_power_save(struct horus3a_priv *priv) 96 + { 97 + u8 data[2]; 98 + 99 + dev_dbg(&priv->i2c->dev, "%s()\n", __func__); 100 + if (priv->state == STATE_SLEEP) 101 + return 0; 102 + /* IQ Generator disable */ 103 + horus3a_write_reg(priv, 0x2a, 0x79); 104 + /* MDIV_EN = 0 */ 105 + horus3a_write_reg(priv, 0x29, 0x70); 106 + /* VCO disable preparation */ 107 + horus3a_write_reg(priv, 0x28, 0x3e); 108 + /* VCO buffer disable */ 109 + horus3a_write_reg(priv, 0x2a, 0x19); 110 + /* VCO calibration disable */ 111 + horus3a_write_reg(priv, 0x1c, 0x00); 112 + /* Power save setting (xtal is not stopped) */ 113 + data[0] = 0xC0; 114 + /* LNA is Disabled */ 115 + data[1] = 0xA7; 116 + /* 0x11 - 0x12 */ 117 + horus3a_write_regs(priv, 0x11, data, sizeof(data)); 118 + priv->state = STATE_SLEEP; 119 + return 0; 120 + } 121 + 122 + static int horus3a_leave_power_save(struct horus3a_priv *priv) 123 + { 124 + u8 data[2]; 125 + 126 + dev_dbg(&priv->i2c->dev, "%s()\n", __func__); 127 + if (priv->state == STATE_ACTIVE) 128 + return 0; 129 + /* Leave power save */ 130 + data[0] = 0x00; 131 + /* LNA is Disabled */ 132 + data[1] = 0xa7; 133 + /* 0x11 - 0x12 */ 134 + horus3a_write_regs(priv, 0x11, data, sizeof(data)); 135 + /* VCO buffer enable */ 136 + horus3a_write_reg(priv, 0x2a, 0x79); 137 + /* VCO calibration enable */ 138 + horus3a_write_reg(priv, 0x1c, 0xc0); 139 + /* MDIV_EN = 1 */ 140 + horus3a_write_reg(priv, 0x29, 0x71); 141 + usleep_range(5000, 7000); 142 + priv->state = STATE_ACTIVE; 143 + return 0; 144 + } 145 + 146 + static int horus3a_init(struct dvb_frontend *fe) 147 + { 148 + struct horus3a_priv *priv = fe->tuner_priv; 149 + 150 + dev_dbg(&priv->i2c->dev, "%s()\n", __func__); 151 + return 0; 152 + } 153 + 154 + static int horus3a_release(struct dvb_frontend *fe) 155 + { 156 + struct horus3a_priv *priv = fe->tuner_priv; 157 + 158 + dev_dbg(&priv->i2c->dev, "%s()\n", __func__); 159 + kfree(fe->tuner_priv); 160 + fe->tuner_priv = NULL; 161 + return 0; 162 + } 163 + 164 + static int horus3a_sleep(struct dvb_frontend *fe) 165 + { 166 + struct horus3a_priv *priv = fe->tuner_priv; 167 + 168 + dev_dbg(&priv->i2c->dev, "%s()\n", __func__); 169 + horus3a_enter_power_save(priv); 170 + return 0; 171 + } 172 + 173 + static int horus3a_set_params(struct dvb_frontend *fe) 174 + { 175 + struct dtv_frontend_properties *p = &fe->dtv_property_cache; 176 + struct horus3a_priv *priv = fe->tuner_priv; 177 + u32 frequency = p->frequency; 178 + u32 symbol_rate = p->symbol_rate/1000; 179 + u8 mixdiv = 0; 180 + u8 mdiv = 0; 181 + u32 ms = 0; 182 + u8 f_ctl = 0; 183 + u8 g_ctl = 0; 184 + u8 fc_lpf = 0; 185 + u8 data[5]; 186 + 187 + dev_dbg(&priv->i2c->dev, "%s(): frequency %dkHz symbol_rate %dksps\n", 188 + __func__, frequency, symbol_rate); 189 + if (priv->set_tuner) 190 + priv->set_tuner(priv->set_tuner_data, 0); 191 + if (priv->state == STATE_SLEEP) 192 + horus3a_leave_power_save(priv); 193 + 194 + /* frequency should be X MHz (X : integer) */ 195 + frequency = DIV_ROUND_CLOSEST(frequency, 1000) * 1000; 196 + if (frequency <= 1155000) { 197 + mixdiv = 4; 198 + mdiv = 1; 199 + } else { 200 + mixdiv = 2; 201 + mdiv = 0; 202 + } 203 + /* Assumed that fREF == 1MHz (1000kHz) */ 204 + ms = DIV_ROUND_CLOSEST((frequency * mixdiv) / 2, 1000); 205 + if (ms > 0x7FFF) { /* 15 bit */ 206 + dev_err(&priv->i2c->dev, "horus3a: invalid frequency %d\n", 207 + frequency); 208 + return -EINVAL; 209 + } 210 + if (frequency < 975000) { 211 + /* F_CTL=11100 G_CTL=001 */ 212 + f_ctl = 0x1C; 213 + g_ctl = 0x01; 214 + } else if (frequency < 1050000) { 215 + /* F_CTL=11000 G_CTL=010 */ 216 + f_ctl = 0x18; 217 + g_ctl = 0x02; 218 + } else if (frequency < 1150000) { 219 + /* F_CTL=10100 G_CTL=010 */ 220 + f_ctl = 0x14; 221 + g_ctl = 0x02; 222 + } else if (frequency < 1250000) { 223 + /* F_CTL=10000 G_CTL=011 */ 224 + f_ctl = 0x10; 225 + g_ctl = 0x03; 226 + } else if (frequency < 1350000) { 227 + /* F_CTL=01100 G_CTL=100 */ 228 + f_ctl = 0x0C; 229 + g_ctl = 0x04; 230 + } else if (frequency < 1450000) { 231 + /* F_CTL=01010 G_CTL=100 */ 232 + f_ctl = 0x0A; 233 + g_ctl = 0x04; 234 + } else if (frequency < 1600000) { 235 + /* F_CTL=00111 G_CTL=101 */ 236 + f_ctl = 0x07; 237 + g_ctl = 0x05; 238 + } else if (frequency < 1800000) { 239 + /* F_CTL=00100 G_CTL=010 */ 240 + f_ctl = 0x04; 241 + g_ctl = 0x02; 242 + } else if (frequency < 2000000) { 243 + /* F_CTL=00010 G_CTL=001 */ 244 + f_ctl = 0x02; 245 + g_ctl = 0x01; 246 + } else { 247 + /* F_CTL=00000 G_CTL=000 */ 248 + f_ctl = 0x00; 249 + g_ctl = 0x00; 250 + } 251 + /* LPF cutoff frequency setting */ 252 + if (p->delivery_system == SYS_DVBS) { 253 + /* 254 + * rolloff = 0.35 255 + * SR <= 4.3 256 + * fc_lpf = 5 257 + * 4.3 < SR <= 10 258 + * fc_lpf = SR * (1 + rolloff) / 2 + SR / 2 = 259 + * SR * 1.175 = SR * (47/40) 260 + * 10 < SR 261 + * fc_lpf = SR * (1 + rolloff) / 2 + 5 = 262 + * SR * 0.675 + 5 = SR * (27/40) + 5 263 + * NOTE: The result should be round up. 264 + */ 265 + if (symbol_rate <= 4300) 266 + fc_lpf = 5; 267 + else if (symbol_rate <= 10000) 268 + fc_lpf = (u8)DIV_ROUND_UP(symbol_rate * 47, 40000); 269 + else 270 + fc_lpf = (u8)DIV_ROUND_UP(symbol_rate * 27, 40000) + 5; 271 + /* 5 <= fc_lpf <= 36 */ 272 + if (fc_lpf > 36) 273 + fc_lpf = 36; 274 + } else if (p->delivery_system == SYS_DVBS2) { 275 + int rolloff; 276 + 277 + switch (p->rolloff) { 278 + case ROLLOFF_35: 279 + rolloff = 35; 280 + break; 281 + case ROLLOFF_25: 282 + rolloff = 25; 283 + break; 284 + case ROLLOFF_20: 285 + rolloff = 20; 286 + break; 287 + case ROLLOFF_AUTO: 288 + default: 289 + dev_err(&priv->i2c->dev, 290 + "horus3a: auto roll-off is not supported\n"); 291 + return -EINVAL; 292 + } 293 + /* 294 + * SR <= 4.5: 295 + * fc_lpf = 5 296 + * 4.5 < SR <= 10: 297 + * fc_lpf = SR * (1 + rolloff) / 2 + SR / 2 298 + * 10 < SR: 299 + * fc_lpf = SR * (1 + rolloff) / 2 + 5 300 + * NOTE: The result should be round up. 301 + */ 302 + if (symbol_rate <= 4500) 303 + fc_lpf = 5; 304 + else if (symbol_rate <= 10000) 305 + fc_lpf = (u8)DIV_ROUND_UP( 306 + symbol_rate * (200 + rolloff), 200000); 307 + else 308 + fc_lpf = (u8)DIV_ROUND_UP( 309 + symbol_rate * (100 + rolloff), 200000) + 5; 310 + /* 5 <= fc_lpf <= 36 is valid */ 311 + if (fc_lpf > 36) 312 + fc_lpf = 36; 313 + } else { 314 + dev_err(&priv->i2c->dev, 315 + "horus3a: invalid delivery system %d\n", 316 + p->delivery_system); 317 + return -EINVAL; 318 + } 319 + /* 0x00 - 0x04 */ 320 + data[0] = (u8)((ms >> 7) & 0xFF); 321 + data[1] = (u8)((ms << 1) & 0xFF); 322 + data[2] = 0x00; 323 + data[3] = 0x00; 324 + data[4] = (u8)(mdiv << 7); 325 + horus3a_write_regs(priv, 0x00, data, sizeof(data)); 326 + /* Write G_CTL, F_CTL */ 327 + horus3a_write_reg(priv, 0x09, (u8)((g_ctl << 5) | f_ctl)); 328 + /* Write LPF cutoff frequency */ 329 + horus3a_write_reg(priv, 0x37, (u8)(0x80 | (fc_lpf << 1))); 330 + /* Start Calibration */ 331 + horus3a_write_reg(priv, 0x05, 0x80); 332 + /* IQ Generator enable */ 333 + horus3a_write_reg(priv, 0x2a, 0x7b); 334 + /* tuner stabilization time */ 335 + msleep(60); 336 + /* Store tuned frequency to the struct */ 337 + priv->frequency = ms * 2 * 1000 / mixdiv; 338 + return 0; 339 + } 340 + 341 + static int horus3a_get_frequency(struct dvb_frontend *fe, u32 *frequency) 342 + { 343 + struct horus3a_priv *priv = fe->tuner_priv; 344 + 345 + *frequency = priv->frequency; 346 + return 0; 347 + } 348 + 349 + static struct dvb_tuner_ops horus3a_tuner_ops = { 350 + .info = { 351 + .name = "Sony Horus3a", 352 + .frequency_min = 950000, 353 + .frequency_max = 2150000, 354 + .frequency_step = 1000, 355 + }, 356 + .init = horus3a_init, 357 + .release = horus3a_release, 358 + .sleep = horus3a_sleep, 359 + .set_params = horus3a_set_params, 360 + .get_frequency = horus3a_get_frequency, 361 + }; 362 + 363 + struct dvb_frontend *horus3a_attach(struct dvb_frontend *fe, 364 + const struct horus3a_config *config, 365 + struct i2c_adapter *i2c) 366 + { 367 + u8 buf[3], val; 368 + struct horus3a_priv *priv = NULL; 369 + 370 + priv = kzalloc(sizeof(struct horus3a_priv), GFP_KERNEL); 371 + if (priv == NULL) 372 + return NULL; 373 + priv->i2c_address = (config->i2c_address >> 1); 374 + priv->i2c = i2c; 375 + priv->set_tuner_data = config->set_tuner_priv; 376 + priv->set_tuner = config->set_tuner_callback; 377 + 378 + if (fe->ops.i2c_gate_ctrl) 379 + fe->ops.i2c_gate_ctrl(fe, 1); 380 + 381 + /* wait 4ms after power on */ 382 + usleep_range(4000, 6000); 383 + /* IQ Generator disable */ 384 + horus3a_write_reg(priv, 0x2a, 0x79); 385 + /* REF_R = Xtal Frequency */ 386 + buf[0] = config->xtal_freq_mhz; 387 + buf[1] = config->xtal_freq_mhz; 388 + buf[2] = 0; 389 + /* 0x6 - 0x8 */ 390 + horus3a_write_regs(priv, 0x6, buf, 3); 391 + /* IQ Out = Single Ended */ 392 + horus3a_write_reg(priv, 0x0a, 0x40); 393 + switch (config->xtal_freq_mhz) { 394 + case 27: 395 + val = 0x1f; 396 + break; 397 + case 24: 398 + val = 0x10; 399 + break; 400 + case 16: 401 + val = 0xc; 402 + break; 403 + default: 404 + val = 0; 405 + dev_warn(&priv->i2c->dev, 406 + "horus3a: invalid xtal frequency %dMHz\n", 407 + config->xtal_freq_mhz); 408 + break; 409 + } 410 + val <<= 2; 411 + horus3a_write_reg(priv, 0x0e, val); 412 + horus3a_enter_power_save(priv); 413 + usleep_range(3000, 5000); 414 + 415 + if (fe->ops.i2c_gate_ctrl) 416 + fe->ops.i2c_gate_ctrl(fe, 0); 417 + 418 + memcpy(&fe->ops.tuner_ops, &horus3a_tuner_ops, 419 + sizeof(struct dvb_tuner_ops)); 420 + fe->tuner_priv = priv; 421 + dev_info(&priv->i2c->dev, 422 + "Sony HORUS3A attached on addr=%x at I2C adapter %p\n", 423 + priv->i2c_address, priv->i2c); 424 + return fe; 425 + } 426 + EXPORT_SYMBOL(horus3a_attach); 427 + 428 + MODULE_DESCRIPTION("Sony HORUS3A sattelite tuner driver"); 429 + MODULE_AUTHOR("Sergey Kozlov <serjk@netup.ru>"); 430 + MODULE_LICENSE("GPL");
+58
drivers/media/dvb-frontends/horus3a.h
··· 1 + /* 2 + * horus3a.h 3 + * 4 + * Sony Horus3A DVB-S/S2 tuner driver 5 + * 6 + * Copyright 2012 Sony Corporation 7 + * Copyright (C) 2014 NetUP Inc. 8 + * Copyright (C) 2014 Sergey Kozlov <serjk@netup.ru> 9 + * Copyright (C) 2014 Abylay Ospan <aospan@netup.ru> 10 + * 11 + * This program is free software; you can redistribute it and/or modify 12 + * it under the terms of the GNU General Public License as published by 13 + * the Free Software Foundation; either version 2 of the License, or 14 + * (at your option) any later version. 15 + * 16 + * This program is distributed in the hope that it will be useful, 17 + * but WITHOUT ANY WARRANTY; without even the implied warranty of 18 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 + * GNU General Public License for more details. 20 + */ 21 + 22 + #ifndef __DVB_HORUS3A_H__ 23 + #define __DVB_HORUS3A_H__ 24 + 25 + #include <linux/kconfig.h> 26 + #include <linux/dvb/frontend.h> 27 + #include <linux/i2c.h> 28 + 29 + /** 30 + * struct horus3a_config - the configuration of Horus3A tuner driver 31 + * @i2c_address: I2C address of the tuner 32 + * @xtal_freq_mhz: Oscillator frequency, MHz 33 + * @set_tuner_priv: Callback function private context 34 + * @set_tuner_callback: Callback function that notifies the parent driver 35 + * which tuner is active now 36 + */ 37 + struct horus3a_config { 38 + u8 i2c_address; 39 + u8 xtal_freq_mhz; 40 + void *set_tuner_priv; 41 + int (*set_tuner_callback)(void *, int); 42 + }; 43 + 44 + #if IS_REACHABLE(CONFIG_DVB_HORUS3A) 45 + extern struct dvb_frontend *horus3a_attach(struct dvb_frontend *fe, 46 + const struct horus3a_config *config, 47 + struct i2c_adapter *i2c); 48 + #else 49 + static inline struct dvb_frontend *horus3a_attach( 50 + const struct cxd2820r_config *config, 51 + struct i2c_adapter *i2c) 52 + { 53 + printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __func__); 54 + return NULL; 55 + } 56 + #endif 57 + 58 + #endif
+189
drivers/media/dvb-frontends/lnbh25.c
··· 1 + /* 2 + * lnbh25.c 3 + * 4 + * Driver for LNB supply and control IC LNBH25 5 + * 6 + * Copyright (C) 2014 NetUP Inc. 7 + * Copyright (C) 2014 Sergey Kozlov <serjk@netup.ru> 8 + * Copyright (C) 2014 Abylay Ospan <aospan@netup.ru> 9 + * 10 + * This program is free software; you can redistribute it and/or modify 11 + * it under the terms of the GNU General Public License as published by 12 + * the Free Software Foundation; either version 2 of the License, or 13 + * (at your option) any later version. 14 + * 15 + * This program is distributed in the hope that it will be useful, 16 + * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 + * GNU General Public License for more details. 19 + */ 20 + 21 + #include <linux/module.h> 22 + #include <linux/init.h> 23 + #include <linux/string.h> 24 + #include <linux/slab.h> 25 + 26 + #include "dvb_frontend.h" 27 + #include "lnbh25.h" 28 + 29 + /** 30 + * struct lnbh25_priv - LNBH25 driver private data 31 + * @i2c: pointer to the I2C adapter structure 32 + * @i2c_address: I2C address of LNBH25 SEC chip 33 + * @config: Registers configuration: 34 + * offset 0: 1st register address, always 0x02 (DATA1) 35 + * offset 1: DATA1 register value 36 + * offset 2: DATA2 register value 37 + */ 38 + struct lnbh25_priv { 39 + struct i2c_adapter *i2c; 40 + u8 i2c_address; 41 + u8 config[3]; 42 + }; 43 + 44 + #define LNBH25_STATUS_OFL 0x1 45 + #define LNBH25_STATUS_VMON 0x4 46 + #define LNBH25_VSEL_13 0x03 47 + #define LNBH25_VSEL_18 0x0a 48 + 49 + static int lnbh25_read_vmon(struct lnbh25_priv *priv) 50 + { 51 + int i, ret; 52 + u8 addr = 0x00; 53 + u8 status[6]; 54 + struct i2c_msg msg[2] = { 55 + { 56 + .addr = priv->i2c_address, 57 + .flags = 0, 58 + .len = 1, 59 + .buf = &addr 60 + }, { 61 + .addr = priv->i2c_address, 62 + .flags = I2C_M_RD, 63 + .len = sizeof(status), 64 + .buf = status 65 + } 66 + }; 67 + 68 + for (i = 0; i < 2; i++) { 69 + ret = i2c_transfer(priv->i2c, &msg[i], 1); 70 + if (ret >= 0 && ret != 1) 71 + ret = -EIO; 72 + if (ret < 0) { 73 + dev_dbg(&priv->i2c->dev, 74 + "%s(): I2C transfer %d failed (%d)\n", 75 + __func__, i, ret); 76 + return ret; 77 + } 78 + } 79 + print_hex_dump_bytes("lnbh25_read_vmon: ", 80 + DUMP_PREFIX_OFFSET, status, sizeof(status)); 81 + if ((status[0] & (LNBH25_STATUS_OFL | LNBH25_STATUS_VMON)) != 0) { 82 + dev_err(&priv->i2c->dev, 83 + "%s(): voltage in failure state, status reg 0x%x\n", 84 + __func__, status[0]); 85 + return -EIO; 86 + } 87 + return 0; 88 + } 89 + 90 + static int lnbh25_set_voltage(struct dvb_frontend *fe, 91 + enum fe_sec_voltage voltage) 92 + { 93 + int ret; 94 + u8 data1_reg; 95 + const char *vsel; 96 + struct lnbh25_priv *priv = fe->sec_priv; 97 + struct i2c_msg msg = { 98 + .addr = priv->i2c_address, 99 + .flags = 0, 100 + .len = sizeof(priv->config), 101 + .buf = priv->config 102 + }; 103 + 104 + switch (voltage) { 105 + case SEC_VOLTAGE_OFF: 106 + data1_reg = 0x00; 107 + vsel = "Off"; 108 + break; 109 + case SEC_VOLTAGE_13: 110 + data1_reg = LNBH25_VSEL_13; 111 + vsel = "13V"; 112 + break; 113 + case SEC_VOLTAGE_18: 114 + data1_reg = LNBH25_VSEL_18; 115 + vsel = "18V"; 116 + break; 117 + default: 118 + return -EINVAL; 119 + } 120 + priv->config[1] = data1_reg; 121 + dev_dbg(&priv->i2c->dev, 122 + "%s(): %s, I2C 0x%x write [ %02x %02x %02x ]\n", 123 + __func__, vsel, priv->i2c_address, 124 + priv->config[0], priv->config[1], priv->config[2]); 125 + ret = i2c_transfer(priv->i2c, &msg, 1); 126 + if (ret >= 0 && ret != 1) 127 + ret = -EIO; 128 + if (ret < 0) { 129 + dev_err(&priv->i2c->dev, "%s(): I2C transfer error (%d)\n", 130 + __func__, ret); 131 + return ret; 132 + } 133 + if (voltage != SEC_VOLTAGE_OFF) { 134 + msleep(120); 135 + ret = lnbh25_read_vmon(priv); 136 + } else { 137 + msleep(20); 138 + ret = 0; 139 + } 140 + return ret; 141 + } 142 + 143 + static void lnbh25_release(struct dvb_frontend *fe) 144 + { 145 + struct lnbh25_priv *priv = fe->sec_priv; 146 + 147 + dev_dbg(&priv->i2c->dev, "%s()\n", __func__); 148 + lnbh25_set_voltage(fe, SEC_VOLTAGE_OFF); 149 + kfree(fe->sec_priv); 150 + fe->sec_priv = NULL; 151 + } 152 + 153 + struct dvb_frontend *lnbh25_attach(struct dvb_frontend *fe, 154 + struct lnbh25_config *cfg, 155 + struct i2c_adapter *i2c) 156 + { 157 + struct lnbh25_priv *priv; 158 + 159 + dev_dbg(&i2c->dev, "%s()\n", __func__); 160 + priv = kzalloc(sizeof(struct lnbh25_priv), GFP_KERNEL); 161 + if (!priv) 162 + return NULL; 163 + priv->i2c_address = (cfg->i2c_address >> 1); 164 + priv->i2c = i2c; 165 + priv->config[0] = 0x02; 166 + priv->config[1] = 0x00; 167 + priv->config[2] = cfg->data2_config; 168 + fe->sec_priv = priv; 169 + if (lnbh25_set_voltage(fe, SEC_VOLTAGE_OFF)) { 170 + dev_err(&i2c->dev, 171 + "%s(): no LNBH25 found at I2C addr 0x%02x\n", 172 + __func__, priv->i2c_address); 173 + kfree(priv); 174 + fe->sec_priv = NULL; 175 + return NULL; 176 + } 177 + 178 + fe->ops.release_sec = lnbh25_release; 179 + fe->ops.set_voltage = lnbh25_set_voltage; 180 + 181 + dev_err(&i2c->dev, "%s(): attached at I2C addr 0x%02x\n", 182 + __func__, priv->i2c_address); 183 + return fe; 184 + } 185 + EXPORT_SYMBOL(lnbh25_attach); 186 + 187 + MODULE_DESCRIPTION("ST LNBH25 driver"); 188 + MODULE_AUTHOR("info@netup.ru"); 189 + MODULE_LICENSE("GPL");
+56
drivers/media/dvb-frontends/lnbh25.h
··· 1 + /* 2 + * lnbh25.c 3 + * 4 + * Driver for LNB supply and control IC LNBH25 5 + * 6 + * Copyright (C) 2014 NetUP Inc. 7 + * Copyright (C) 2014 Sergey Kozlov <serjk@netup.ru> 8 + * Copyright (C) 2014 Abylay Ospan <aospan@netup.ru> 9 + * 10 + * This program is free software; you can redistribute it and/or modify 11 + * it under the terms of the GNU General Public License as published by 12 + * the Free Software Foundation; either version 2 of the License, or 13 + * (at your option) any later version. 14 + * 15 + * This program is distributed in the hope that it will be useful, 16 + * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 + * GNU General Public License for more details. 19 + */ 20 + 21 + #ifndef LNBH25_H 22 + #define LNBH25_H 23 + 24 + #include <linux/i2c.h> 25 + #include <linux/kconfig.h> 26 + #include <linux/dvb/frontend.h> 27 + 28 + /* 22 kHz tone enabled. Tone output controlled by DSQIN pin */ 29 + #define LNBH25_TEN 0x01 30 + /* Low power mode activated (used only with 22 kHz tone output disabled) */ 31 + #define LNBH25_LPM 0x02 32 + /* DSQIN input pin is set to receive external 22 kHz TTL signal source */ 33 + #define LNBH25_EXTM 0x04 34 + 35 + struct lnbh25_config { 36 + u8 i2c_address; 37 + u8 data2_config; 38 + }; 39 + 40 + #if IS_REACHABLE(CONFIG_DVB_LNBH25) 41 + struct dvb_frontend *lnbh25_attach( 42 + struct dvb_frontend *fe, 43 + struct lnbh25_config *cfg, 44 + struct i2c_adapter *i2c); 45 + #else 46 + static inline dvb_frontend *lnbh25_attach( 47 + struct dvb_frontend *fe, 48 + struct lnbh25_config *cfg, 49 + struct i2c_adapter *i2c) 50 + { 51 + printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __func__); 52 + return NULL; 53 + } 54 + #endif 55 + 56 + #endif
-1
drivers/media/dvb-frontends/m88ds3103.c
··· 1495 1495 1496 1496 static struct i2c_driver m88ds3103_driver = { 1497 1497 .driver = { 1498 - .owner = THIS_MODULE, 1499 1498 .name = "m88ds3103", 1500 1499 .suppress_bind_attrs = true, 1501 1500 },
-1
drivers/media/dvb-frontends/rtl2830.c
··· 915 915 916 916 static struct i2c_driver rtl2830_driver = { 917 917 .driver = { 918 - .owner = THIS_MODULE, 919 918 .name = "rtl2830", 920 919 }, 921 920 .probe = rtl2830_probe,
-1
drivers/media/dvb-frontends/rtl2832.c
··· 1319 1319 1320 1320 static struct i2c_driver rtl2832_driver = { 1321 1321 .driver = { 1322 - .owner = THIS_MODULE, 1323 1322 .name = "rtl2832", 1324 1323 }, 1325 1324 .probe = rtl2832_probe,
-1
drivers/media/dvb-frontends/rtl2832_sdr.c
··· 1538 1538 static struct platform_driver rtl2832_sdr_driver = { 1539 1539 .driver = { 1540 1540 .name = "rtl2832_sdr", 1541 - .owner = THIS_MODULE, 1542 1541 }, 1543 1542 .probe = rtl2832_sdr_probe, 1544 1543 .remove = rtl2832_sdr_remove,
+1 -1
drivers/media/dvb-frontends/s921.c
··· 466 466 467 467 static int s921_get_algo(struct dvb_frontend *fe) 468 468 { 469 - return 1; /* FE_ALGO_HW */ 469 + return DVBFE_ALGO_HW; 470 470 } 471 471 472 472 static void s921_release(struct dvb_frontend *fe)
-1
drivers/media/dvb-frontends/si2168.c
··· 757 757 758 758 static struct i2c_driver si2168_driver = { 759 759 .driver = { 760 - .owner = THIS_MODULE, 761 760 .name = "si2168", 762 761 }, 763 762 .probe = si2168_probe,
-1
drivers/media/dvb-frontends/sp2.c
··· 426 426 427 427 static struct i2c_driver sp2_driver = { 428 428 .driver = { 429 - .owner = THIS_MODULE, 430 429 .name = "sp2", 431 430 }, 432 431 .probe = sp2_probe,
+13 -4
drivers/media/dvb-frontends/stv0367.c
··· 791 791 memcpy(buf + 2, data, len); 792 792 793 793 if (i2cdebug) 794 - printk(KERN_DEBUG "%s: %02x: %02x\n", __func__, reg, buf[2]); 794 + printk(KERN_DEBUG "%s: [%02x] %02x: %02x\n", __func__, 795 + state->config->demod_address, reg, buf[2]); 795 796 796 797 ret = i2c_transfer(state->i2c, &msg, 1); 797 798 if (ret != 1) 798 - printk(KERN_ERR "%s: i2c write error!\n", __func__); 799 + printk(KERN_ERR "%s: i2c write error! ([%02x] %02x: %02x)\n", 800 + __func__, state->config->demod_address, reg, buf[2]); 799 801 800 802 return (ret != 1) ? -EREMOTEIO : 0; 801 803 } ··· 831 829 832 830 ret = i2c_transfer(state->i2c, msg, 2); 833 831 if (ret != 2) 834 - printk(KERN_ERR "%s: i2c read error\n", __func__); 832 + printk(KERN_ERR "%s: i2c read error ([%02x] %02x: %02x)\n", 833 + __func__, state->config->demod_address, reg, b1[0]); 835 834 836 835 if (i2cdebug) 837 - printk(KERN_DEBUG "%s: %02x: %02x\n", __func__, reg, b1[0]); 836 + printk(KERN_DEBUG "%s: [%02x] %02x: %02x\n", __func__, 837 + state->config->demod_address, reg, b1[0]); 838 838 839 839 return b1[0]; 840 840 } ··· 1554 1550 1555 1551 switch (state->config->xtal) { 1556 1552 /*set internal freq to 53.125MHz */ 1553 + case 16000000: 1554 + stv0367_writereg(state, R367TER_PLLMDIV, 0x2); 1555 + stv0367_writereg(state, R367TER_PLLNDIV, 0x1b); 1556 + stv0367_writereg(state, R367TER_PLLSETUP, 0x18); 1557 + break; 1557 1558 case 25000000: 1558 1559 stv0367_writereg(state, R367TER_PLLMDIV, 0xa); 1559 1560 stv0367_writereg(state, R367TER_PLLNDIV, 0x55);
+338 -497
drivers/media/dvb-frontends/tda10071.c
··· 20 20 21 21 #include "tda10071_priv.h" 22 22 23 - /* Max transfer size done by I2C transfer functions */ 24 - #define MAX_XFER_SIZE 64 25 - 26 23 static struct dvb_frontend_ops tda10071_ops; 27 24 28 - /* write multiple registers */ 29 - static int tda10071_wr_regs(struct tda10071_priv *priv, u8 reg, u8 *val, 30 - int len) 31 - { 32 - int ret; 33 - u8 buf[MAX_XFER_SIZE]; 34 - struct i2c_msg msg[1] = { 35 - { 36 - .addr = priv->cfg.demod_i2c_addr, 37 - .flags = 0, 38 - .len = 1 + len, 39 - .buf = buf, 40 - } 41 - }; 42 - 43 - if (1 + len > sizeof(buf)) { 44 - dev_warn(&priv->i2c->dev, 45 - "%s: i2c wr reg=%04x: len=%d is too big!\n", 46 - KBUILD_MODNAME, reg, len); 47 - return -EINVAL; 48 - } 49 - 50 - buf[0] = reg; 51 - memcpy(&buf[1], val, len); 52 - 53 - ret = i2c_transfer(priv->i2c, msg, 1); 54 - if (ret == 1) { 55 - ret = 0; 56 - } else { 57 - dev_warn(&priv->i2c->dev, 58 - "%s: i2c wr failed=%d reg=%02x len=%d\n", 59 - KBUILD_MODNAME, ret, reg, len); 60 - ret = -EREMOTEIO; 61 - } 62 - return ret; 63 - } 64 - 65 - /* read multiple registers */ 66 - static int tda10071_rd_regs(struct tda10071_priv *priv, u8 reg, u8 *val, 67 - int len) 68 - { 69 - int ret; 70 - u8 buf[MAX_XFER_SIZE]; 71 - struct i2c_msg msg[2] = { 72 - { 73 - .addr = priv->cfg.demod_i2c_addr, 74 - .flags = 0, 75 - .len = 1, 76 - .buf = &reg, 77 - }, { 78 - .addr = priv->cfg.demod_i2c_addr, 79 - .flags = I2C_M_RD, 80 - .len = len, 81 - .buf = buf, 82 - } 83 - }; 84 - 85 - if (len > sizeof(buf)) { 86 - dev_warn(&priv->i2c->dev, 87 - "%s: i2c wr reg=%04x: len=%d is too big!\n", 88 - KBUILD_MODNAME, reg, len); 89 - return -EINVAL; 90 - } 91 - 92 - ret = i2c_transfer(priv->i2c, msg, 2); 93 - if (ret == 2) { 94 - memcpy(val, buf, len); 95 - ret = 0; 96 - } else { 97 - dev_warn(&priv->i2c->dev, 98 - "%s: i2c rd failed=%d reg=%02x len=%d\n", 99 - KBUILD_MODNAME, ret, reg, len); 100 - ret = -EREMOTEIO; 101 - } 102 - return ret; 103 - } 104 - 105 - /* write single register */ 106 - static int tda10071_wr_reg(struct tda10071_priv *priv, u8 reg, u8 val) 107 - { 108 - return tda10071_wr_regs(priv, reg, &val, 1); 109 - } 110 - 111 - /* read single register */ 112 - static int tda10071_rd_reg(struct tda10071_priv *priv, u8 reg, u8 *val) 113 - { 114 - return tda10071_rd_regs(priv, reg, val, 1); 115 - } 116 - 25 + /* 26 + * XXX: regmap_update_bits() does not fit our needs as it does not support 27 + * partially volatile registers. Also it performs register read even mask is as 28 + * wide as register value. 29 + */ 117 30 /* write single register with mask */ 118 - static int tda10071_wr_reg_mask(struct tda10071_priv *priv, 31 + static int tda10071_wr_reg_mask(struct tda10071_dev *dev, 119 32 u8 reg, u8 val, u8 mask) 120 33 { 121 34 int ret; ··· 36 123 37 124 /* no need for read if whole reg is written */ 38 125 if (mask != 0xff) { 39 - ret = tda10071_rd_regs(priv, reg, &tmp, 1); 126 + ret = regmap_bulk_read(dev->regmap, reg, &tmp, 1); 40 127 if (ret) 41 128 return ret; 42 129 ··· 45 132 val |= tmp; 46 133 } 47 134 48 - return tda10071_wr_regs(priv, reg, &val, 1); 49 - } 50 - 51 - /* read single register with mask */ 52 - static int tda10071_rd_reg_mask(struct tda10071_priv *priv, 53 - u8 reg, u8 *val, u8 mask) 54 - { 55 - int ret, i; 56 - u8 tmp; 57 - 58 - ret = tda10071_rd_regs(priv, reg, &tmp, 1); 59 - if (ret) 60 - return ret; 61 - 62 - tmp &= mask; 63 - 64 - /* find position of the first bit */ 65 - for (i = 0; i < 8; i++) { 66 - if ((mask >> i) & 0x01) 67 - break; 68 - } 69 - *val = tmp >> i; 70 - 71 - return 0; 135 + return regmap_bulk_write(dev->regmap, reg, &val, 1); 72 136 } 73 137 74 138 /* execute firmware command */ 75 - static int tda10071_cmd_execute(struct tda10071_priv *priv, 139 + static int tda10071_cmd_execute(struct tda10071_dev *dev, 76 140 struct tda10071_cmd *cmd) 77 141 { 142 + struct i2c_client *client = dev->client; 78 143 int ret, i; 79 - u8 tmp; 144 + unsigned int uitmp; 80 145 81 - if (!priv->warm) { 146 + if (!dev->warm) { 82 147 ret = -EFAULT; 83 148 goto error; 84 149 } 85 150 151 + mutex_lock(&dev->cmd_execute_mutex); 152 + 86 153 /* write cmd and args for firmware */ 87 - ret = tda10071_wr_regs(priv, 0x00, cmd->args, cmd->len); 154 + ret = regmap_bulk_write(dev->regmap, 0x00, cmd->args, cmd->len); 88 155 if (ret) 89 - goto error; 156 + goto error_mutex_unlock; 90 157 91 158 /* start cmd execution */ 92 - ret = tda10071_wr_reg(priv, 0x1f, 1); 159 + ret = regmap_write(dev->regmap, 0x1f, 1); 93 160 if (ret) 94 - goto error; 161 + goto error_mutex_unlock; 95 162 96 163 /* wait cmd execution terminate */ 97 - for (i = 1000, tmp = 1; i && tmp; i--) { 98 - ret = tda10071_rd_reg(priv, 0x1f, &tmp); 164 + for (i = 1000, uitmp = 1; i && uitmp; i--) { 165 + ret = regmap_read(dev->regmap, 0x1f, &uitmp); 99 166 if (ret) 100 - goto error; 167 + goto error_mutex_unlock; 101 168 102 169 usleep_range(200, 5000); 103 170 } 104 171 105 - dev_dbg(&priv->i2c->dev, "%s: loop=%d\n", __func__, i); 172 + mutex_unlock(&dev->cmd_execute_mutex); 173 + dev_dbg(&client->dev, "loop=%d\n", i); 106 174 107 175 if (i == 0) { 108 176 ret = -ETIMEDOUT; ··· 91 197 } 92 198 93 199 return ret; 200 + error_mutex_unlock: 201 + mutex_unlock(&dev->cmd_execute_mutex); 94 202 error: 95 - dev_dbg(&priv->i2c->dev, "%s: failed=%d\n", __func__, ret); 203 + dev_dbg(&client->dev, "failed=%d\n", ret); 96 204 return ret; 97 205 } 98 206 99 207 static int tda10071_set_tone(struct dvb_frontend *fe, 100 208 enum fe_sec_tone_mode fe_sec_tone_mode) 101 209 { 102 - struct tda10071_priv *priv = fe->demodulator_priv; 210 + struct tda10071_dev *dev = fe->demodulator_priv; 211 + struct i2c_client *client = dev->client; 103 212 struct tda10071_cmd cmd; 104 213 int ret; 105 214 u8 tone; 106 215 107 - if (!priv->warm) { 216 + if (!dev->warm) { 108 217 ret = -EFAULT; 109 218 goto error; 110 219 } 111 220 112 - dev_dbg(&priv->i2c->dev, "%s: tone_mode=%d\n", __func__, 113 - fe_sec_tone_mode); 221 + dev_dbg(&client->dev, "tone_mode=%d\n", fe_sec_tone_mode); 114 222 115 223 switch (fe_sec_tone_mode) { 116 224 case SEC_TONE_ON: ··· 122 226 tone = 0; 123 227 break; 124 228 default: 125 - dev_dbg(&priv->i2c->dev, "%s: invalid fe_sec_tone_mode\n", 126 - __func__); 229 + dev_dbg(&client->dev, "invalid fe_sec_tone_mode\n"); 127 230 ret = -EINVAL; 128 231 goto error; 129 232 } ··· 133 238 cmd.args[3] = 0x00; 134 239 cmd.args[4] = tone; 135 240 cmd.len = 5; 136 - ret = tda10071_cmd_execute(priv, &cmd); 241 + ret = tda10071_cmd_execute(dev, &cmd); 137 242 if (ret) 138 243 goto error; 139 244 140 245 return ret; 141 246 error: 142 - dev_dbg(&priv->i2c->dev, "%s: failed=%d\n", __func__, ret); 247 + dev_dbg(&client->dev, "failed=%d\n", ret); 143 248 return ret; 144 249 } 145 250 146 251 static int tda10071_set_voltage(struct dvb_frontend *fe, 147 252 enum fe_sec_voltage fe_sec_voltage) 148 253 { 149 - struct tda10071_priv *priv = fe->demodulator_priv; 254 + struct tda10071_dev *dev = fe->demodulator_priv; 255 + struct i2c_client *client = dev->client; 150 256 struct tda10071_cmd cmd; 151 257 int ret; 152 258 u8 voltage; 153 259 154 - if (!priv->warm) { 260 + if (!dev->warm) { 155 261 ret = -EFAULT; 156 262 goto error; 157 263 } 158 264 159 - dev_dbg(&priv->i2c->dev, "%s: voltage=%d\n", __func__, fe_sec_voltage); 265 + dev_dbg(&client->dev, "voltage=%d\n", fe_sec_voltage); 160 266 161 267 switch (fe_sec_voltage) { 162 268 case SEC_VOLTAGE_13: ··· 170 274 voltage = 0; 171 275 break; 172 276 default: 173 - dev_dbg(&priv->i2c->dev, "%s: invalid fe_sec_voltage\n", 174 - __func__); 277 + dev_dbg(&client->dev, "invalid fe_sec_voltage\n"); 175 278 ret = -EINVAL; 176 279 goto error; 177 280 } ··· 179 284 cmd.args[1] = 0; 180 285 cmd.args[2] = voltage; 181 286 cmd.len = 3; 182 - ret = tda10071_cmd_execute(priv, &cmd); 287 + ret = tda10071_cmd_execute(dev, &cmd); 183 288 if (ret) 184 289 goto error; 185 290 186 291 return ret; 187 292 error: 188 - dev_dbg(&priv->i2c->dev, "%s: failed=%d\n", __func__, ret); 293 + dev_dbg(&client->dev, "failed=%d\n", ret); 189 294 return ret; 190 295 } 191 296 192 297 static int tda10071_diseqc_send_master_cmd(struct dvb_frontend *fe, 193 298 struct dvb_diseqc_master_cmd *diseqc_cmd) 194 299 { 195 - struct tda10071_priv *priv = fe->demodulator_priv; 300 + struct tda10071_dev *dev = fe->demodulator_priv; 301 + struct i2c_client *client = dev->client; 196 302 struct tda10071_cmd cmd; 197 303 int ret, i; 198 - u8 tmp; 304 + unsigned int uitmp; 199 305 200 - if (!priv->warm) { 306 + if (!dev->warm) { 201 307 ret = -EFAULT; 202 308 goto error; 203 309 } 204 310 205 - dev_dbg(&priv->i2c->dev, "%s: msg_len=%d\n", __func__, 206 - diseqc_cmd->msg_len); 311 + dev_dbg(&client->dev, "msg_len=%d\n", diseqc_cmd->msg_len); 207 312 208 313 if (diseqc_cmd->msg_len < 3 || diseqc_cmd->msg_len > 6) { 209 314 ret = -EINVAL; ··· 211 316 } 212 317 213 318 /* wait LNB TX */ 214 - for (i = 500, tmp = 0; i && !tmp; i--) { 215 - ret = tda10071_rd_reg_mask(priv, 0x47, &tmp, 0x01); 319 + for (i = 500, uitmp = 0; i && !uitmp; i--) { 320 + ret = regmap_read(dev->regmap, 0x47, &uitmp); 216 321 if (ret) 217 322 goto error; 218 - 323 + uitmp = (uitmp >> 0) & 1; 219 324 usleep_range(10000, 20000); 220 325 } 221 326 222 - dev_dbg(&priv->i2c->dev, "%s: loop=%d\n", __func__, i); 327 + dev_dbg(&client->dev, "loop=%d\n", i); 223 328 224 329 if (i == 0) { 225 330 ret = -ETIMEDOUT; 226 331 goto error; 227 332 } 228 333 229 - ret = tda10071_wr_reg_mask(priv, 0x47, 0x00, 0x01); 334 + ret = regmap_update_bits(dev->regmap, 0x47, 0x01, 0x00); 230 335 if (ret) 231 336 goto error; 232 337 ··· 239 344 cmd.args[6] = diseqc_cmd->msg_len; 240 345 memcpy(&cmd.args[7], diseqc_cmd->msg, diseqc_cmd->msg_len); 241 346 cmd.len = 7 + diseqc_cmd->msg_len; 242 - ret = tda10071_cmd_execute(priv, &cmd); 347 + ret = tda10071_cmd_execute(dev, &cmd); 243 348 if (ret) 244 349 goto error; 245 350 246 351 return ret; 247 352 error: 248 - dev_dbg(&priv->i2c->dev, "%s: failed=%d\n", __func__, ret); 353 + dev_dbg(&client->dev, "failed=%d\n", ret); 249 354 return ret; 250 355 } 251 356 252 357 static int tda10071_diseqc_recv_slave_reply(struct dvb_frontend *fe, 253 358 struct dvb_diseqc_slave_reply *reply) 254 359 { 255 - struct tda10071_priv *priv = fe->demodulator_priv; 360 + struct tda10071_dev *dev = fe->demodulator_priv; 361 + struct i2c_client *client = dev->client; 256 362 struct tda10071_cmd cmd; 257 363 int ret, i; 258 - u8 tmp; 364 + unsigned int uitmp; 259 365 260 - if (!priv->warm) { 366 + if (!dev->warm) { 261 367 ret = -EFAULT; 262 368 goto error; 263 369 } 264 370 265 - dev_dbg(&priv->i2c->dev, "%s:\n", __func__); 371 + dev_dbg(&client->dev, "\n"); 266 372 267 373 /* wait LNB RX */ 268 - for (i = 500, tmp = 0; i && !tmp; i--) { 269 - ret = tda10071_rd_reg_mask(priv, 0x47, &tmp, 0x02); 374 + for (i = 500, uitmp = 0; i && !uitmp; i--) { 375 + ret = regmap_read(dev->regmap, 0x47, &uitmp); 270 376 if (ret) 271 377 goto error; 272 - 378 + uitmp = (uitmp >> 1) & 1; 273 379 usleep_range(10000, 20000); 274 380 } 275 381 276 - dev_dbg(&priv->i2c->dev, "%s: loop=%d\n", __func__, i); 382 + dev_dbg(&client->dev, "loop=%d\n", i); 277 383 278 384 if (i == 0) { 279 385 ret = -ETIMEDOUT; ··· 282 386 } 283 387 284 388 /* reply len */ 285 - ret = tda10071_rd_reg(priv, 0x46, &tmp); 389 + ret = regmap_read(dev->regmap, 0x46, &uitmp); 286 390 if (ret) 287 391 goto error; 288 392 289 - reply->msg_len = tmp & 0x1f; /* [4:0] */ 393 + reply->msg_len = uitmp & 0x1f; /* [4:0] */ 290 394 if (reply->msg_len > sizeof(reply->msg)) 291 395 reply->msg_len = sizeof(reply->msg); /* truncate API max */ 292 396 ··· 294 398 cmd.args[0] = CMD_LNB_UPDATE_REPLY; 295 399 cmd.args[1] = 0; 296 400 cmd.len = 2; 297 - ret = tda10071_cmd_execute(priv, &cmd); 401 + ret = tda10071_cmd_execute(dev, &cmd); 298 402 if (ret) 299 403 goto error; 300 404 301 - ret = tda10071_rd_regs(priv, cmd.len, reply->msg, reply->msg_len); 405 + ret = regmap_bulk_read(dev->regmap, cmd.len, reply->msg, 406 + reply->msg_len); 302 407 if (ret) 303 408 goto error; 304 409 305 410 return ret; 306 411 error: 307 - dev_dbg(&priv->i2c->dev, "%s: failed=%d\n", __func__, ret); 412 + dev_dbg(&client->dev, "failed=%d\n", ret); 308 413 return ret; 309 414 } 310 415 311 416 static int tda10071_diseqc_send_burst(struct dvb_frontend *fe, 312 417 enum fe_sec_mini_cmd fe_sec_mini_cmd) 313 418 { 314 - struct tda10071_priv *priv = fe->demodulator_priv; 419 + struct tda10071_dev *dev = fe->demodulator_priv; 420 + struct i2c_client *client = dev->client; 315 421 struct tda10071_cmd cmd; 316 422 int ret, i; 317 - u8 tmp, burst; 423 + unsigned int uitmp; 424 + u8 burst; 318 425 319 - if (!priv->warm) { 426 + if (!dev->warm) { 320 427 ret = -EFAULT; 321 428 goto error; 322 429 } 323 430 324 - dev_dbg(&priv->i2c->dev, "%s: fe_sec_mini_cmd=%d\n", __func__, 325 - fe_sec_mini_cmd); 431 + dev_dbg(&client->dev, "fe_sec_mini_cmd=%d\n", fe_sec_mini_cmd); 326 432 327 433 switch (fe_sec_mini_cmd) { 328 434 case SEC_MINI_A: ··· 334 436 burst = 1; 335 437 break; 336 438 default: 337 - dev_dbg(&priv->i2c->dev, "%s: invalid fe_sec_mini_cmd\n", 338 - __func__); 439 + dev_dbg(&client->dev, "invalid fe_sec_mini_cmd\n"); 339 440 ret = -EINVAL; 340 441 goto error; 341 442 } 342 443 343 444 /* wait LNB TX */ 344 - for (i = 500, tmp = 0; i && !tmp; i--) { 345 - ret = tda10071_rd_reg_mask(priv, 0x47, &tmp, 0x01); 445 + for (i = 500, uitmp = 0; i && !uitmp; i--) { 446 + ret = regmap_read(dev->regmap, 0x47, &uitmp); 346 447 if (ret) 347 448 goto error; 348 - 449 + uitmp = (uitmp >> 0) & 1; 349 450 usleep_range(10000, 20000); 350 451 } 351 452 352 - dev_dbg(&priv->i2c->dev, "%s: loop=%d\n", __func__, i); 453 + dev_dbg(&client->dev, "loop=%d\n", i); 353 454 354 455 if (i == 0) { 355 456 ret = -ETIMEDOUT; 356 457 goto error; 357 458 } 358 459 359 - ret = tda10071_wr_reg_mask(priv, 0x47, 0x00, 0x01); 460 + ret = regmap_update_bits(dev->regmap, 0x47, 0x01, 0x00); 360 461 if (ret) 361 462 goto error; 362 463 ··· 363 466 cmd.args[1] = 0; 364 467 cmd.args[2] = burst; 365 468 cmd.len = 3; 366 - ret = tda10071_cmd_execute(priv, &cmd); 469 + ret = tda10071_cmd_execute(dev, &cmd); 367 470 if (ret) 368 471 goto error; 369 472 370 473 return ret; 371 474 error: 372 - dev_dbg(&priv->i2c->dev, "%s: failed=%d\n", __func__, ret); 475 + dev_dbg(&client->dev, "failed=%d\n", ret); 373 476 return ret; 374 477 } 375 478 376 479 static int tda10071_read_status(struct dvb_frontend *fe, enum fe_status *status) 377 480 { 378 - struct tda10071_priv *priv = fe->demodulator_priv; 481 + struct tda10071_dev *dev = fe->demodulator_priv; 482 + struct i2c_client *client = dev->client; 483 + struct dtv_frontend_properties *c = &fe->dtv_property_cache; 484 + struct tda10071_cmd cmd; 379 485 int ret; 380 - u8 tmp; 486 + unsigned int uitmp; 487 + u8 buf[8]; 381 488 382 489 *status = 0; 383 490 384 - if (!priv->warm) { 491 + if (!dev->warm) { 385 492 ret = 0; 386 493 goto error; 387 494 } 388 495 389 - ret = tda10071_rd_reg(priv, 0x39, &tmp); 496 + ret = regmap_read(dev->regmap, 0x39, &uitmp); 390 497 if (ret) 391 498 goto error; 392 499 393 500 /* 0x39[0] tuner PLL */ 394 - if (tmp & 0x02) /* demod PLL */ 501 + if (uitmp & 0x02) /* demod PLL */ 395 502 *status |= FE_HAS_SIGNAL | FE_HAS_CARRIER; 396 - if (tmp & 0x04) /* viterbi or LDPC*/ 503 + if (uitmp & 0x04) /* viterbi or LDPC*/ 397 504 *status |= FE_HAS_VITERBI; 398 - if (tmp & 0x08) /* RS or BCH */ 505 + if (uitmp & 0x08) /* RS or BCH */ 399 506 *status |= FE_HAS_SYNC | FE_HAS_LOCK; 400 507 401 - priv->fe_status = *status; 508 + dev->fe_status = *status; 509 + 510 + /* signal strength */ 511 + if (dev->fe_status & FE_HAS_SIGNAL) { 512 + cmd.args[0] = CMD_GET_AGCACC; 513 + cmd.args[1] = 0; 514 + cmd.len = 2; 515 + ret = tda10071_cmd_execute(dev, &cmd); 516 + if (ret) 517 + goto error; 518 + 519 + /* input power estimate dBm */ 520 + ret = regmap_read(dev->regmap, 0x50, &uitmp); 521 + if (ret) 522 + goto error; 523 + 524 + c->strength.stat[0].scale = FE_SCALE_DECIBEL; 525 + c->strength.stat[0].svalue = (int) (uitmp - 256) * 1000; 526 + } else { 527 + c->strength.stat[0].scale = FE_SCALE_NOT_AVAILABLE; 528 + } 529 + 530 + /* CNR */ 531 + if (dev->fe_status & FE_HAS_VITERBI) { 532 + /* Es/No */ 533 + ret = regmap_bulk_read(dev->regmap, 0x3a, buf, 2); 534 + if (ret) 535 + goto error; 536 + 537 + c->cnr.stat[0].scale = FE_SCALE_DECIBEL; 538 + c->cnr.stat[0].svalue = (buf[0] << 8 | buf[1] << 0) * 100; 539 + } else { 540 + c->cnr.stat[0].scale = FE_SCALE_NOT_AVAILABLE; 541 + } 542 + 543 + /* UCB/PER/BER */ 544 + if (dev->fe_status & FE_HAS_LOCK) { 545 + /* TODO: report total bits/packets */ 546 + u8 delivery_system, reg, len; 547 + 548 + switch (dev->delivery_system) { 549 + case SYS_DVBS: 550 + reg = 0x4c; 551 + len = 8; 552 + delivery_system = 1; 553 + break; 554 + case SYS_DVBS2: 555 + reg = 0x4d; 556 + len = 4; 557 + delivery_system = 0; 558 + break; 559 + default: 560 + ret = -EINVAL; 561 + goto error; 562 + } 563 + 564 + ret = regmap_read(dev->regmap, reg, &uitmp); 565 + if (ret) 566 + goto error; 567 + 568 + if (dev->meas_count == uitmp) { 569 + dev_dbg(&client->dev, "meas not ready=%02x\n", uitmp); 570 + ret = 0; 571 + goto error; 572 + } else { 573 + dev->meas_count = uitmp; 574 + } 575 + 576 + cmd.args[0] = CMD_BER_UPDATE_COUNTERS; 577 + cmd.args[1] = 0; 578 + cmd.args[2] = delivery_system; 579 + cmd.len = 3; 580 + ret = tda10071_cmd_execute(dev, &cmd); 581 + if (ret) 582 + goto error; 583 + 584 + ret = regmap_bulk_read(dev->regmap, cmd.len, buf, len); 585 + if (ret) 586 + goto error; 587 + 588 + if (dev->delivery_system == SYS_DVBS) { 589 + dev->dvbv3_ber = buf[0] << 24 | buf[1] << 16 | 590 + buf[2] << 8 | buf[3] << 0; 591 + dev->post_bit_error += buf[0] << 24 | buf[1] << 16 | 592 + buf[2] << 8 | buf[3] << 0; 593 + c->post_bit_error.stat[0].scale = FE_SCALE_COUNTER; 594 + c->post_bit_error.stat[0].uvalue = dev->post_bit_error; 595 + dev->block_error += buf[4] << 8 | buf[5] << 0; 596 + c->block_error.stat[0].scale = FE_SCALE_COUNTER; 597 + c->block_error.stat[0].uvalue = dev->block_error; 598 + } else { 599 + dev->dvbv3_ber = buf[0] << 8 | buf[1] << 0; 600 + dev->post_bit_error += buf[0] << 8 | buf[1] << 0; 601 + c->post_bit_error.stat[0].scale = FE_SCALE_COUNTER; 602 + c->post_bit_error.stat[0].uvalue = dev->post_bit_error; 603 + c->block_error.stat[0].scale = FE_SCALE_NOT_AVAILABLE; 604 + } 605 + } else { 606 + c->post_bit_error.stat[0].scale = FE_SCALE_NOT_AVAILABLE; 607 + c->block_error.stat[0].scale = FE_SCALE_NOT_AVAILABLE; 608 + } 402 609 403 610 return ret; 404 611 error: 405 - dev_dbg(&priv->i2c->dev, "%s: failed=%d\n", __func__, ret); 612 + dev_dbg(&client->dev, "failed=%d\n", ret); 406 613 return ret; 407 614 } 408 615 409 616 static int tda10071_read_snr(struct dvb_frontend *fe, u16 *snr) 410 617 { 411 - struct tda10071_priv *priv = fe->demodulator_priv; 412 - int ret; 413 - u8 buf[2]; 618 + struct dtv_frontend_properties *c = &fe->dtv_property_cache; 414 619 415 - if (!priv->warm || !(priv->fe_status & FE_HAS_LOCK)) { 620 + if (c->cnr.stat[0].scale == FE_SCALE_DECIBEL) 621 + *snr = div_s64(c->cnr.stat[0].svalue, 100); 622 + else 416 623 *snr = 0; 417 - ret = 0; 418 - goto error; 419 - } 420 - 421 - ret = tda10071_rd_regs(priv, 0x3a, buf, 2); 422 - if (ret) 423 - goto error; 424 - 425 - /* Es/No dBx10 */ 426 - *snr = buf[0] << 8 | buf[1]; 427 - 428 - return ret; 429 - error: 430 - dev_dbg(&priv->i2c->dev, "%s: failed=%d\n", __func__, ret); 431 - return ret; 624 + return 0; 432 625 } 433 626 434 627 static int tda10071_read_signal_strength(struct dvb_frontend *fe, u16 *strength) 435 628 { 436 - struct tda10071_priv *priv = fe->demodulator_priv; 437 - struct tda10071_cmd cmd; 438 - int ret; 439 - u8 tmp; 629 + struct dtv_frontend_properties *c = &fe->dtv_property_cache; 630 + unsigned int uitmp; 440 631 441 - if (!priv->warm || !(priv->fe_status & FE_HAS_LOCK)) { 632 + if (c->strength.stat[0].scale == FE_SCALE_DECIBEL) { 633 + uitmp = div_s64(c->strength.stat[0].svalue, 1000) + 256; 634 + uitmp = clamp(uitmp, 181U, 236U); /* -75dBm - -20dBm */ 635 + /* scale value to 0x0000-0xffff */ 636 + *strength = (uitmp-181) * 0xffff / (236-181); 637 + } else { 442 638 *strength = 0; 443 - ret = 0; 444 - goto error; 445 639 } 446 - 447 - cmd.args[0] = CMD_GET_AGCACC; 448 - cmd.args[1] = 0; 449 - cmd.len = 2; 450 - ret = tda10071_cmd_execute(priv, &cmd); 451 - if (ret) 452 - goto error; 453 - 454 - /* input power estimate dBm */ 455 - ret = tda10071_rd_reg(priv, 0x50, &tmp); 456 - if (ret) 457 - goto error; 458 - 459 - if (tmp < 181) 460 - tmp = 181; /* -75 dBm */ 461 - else if (tmp > 236) 462 - tmp = 236; /* -20 dBm */ 463 - 464 - /* scale value to 0x0000-0xffff */ 465 - *strength = (tmp-181) * 0xffff / (236-181); 466 - 467 - return ret; 468 - error: 469 - dev_dbg(&priv->i2c->dev, "%s: failed=%d\n", __func__, ret); 470 - return ret; 640 + return 0; 471 641 } 472 642 473 643 static int tda10071_read_ber(struct dvb_frontend *fe, u32 *ber) 474 644 { 475 - struct tda10071_priv *priv = fe->demodulator_priv; 476 - struct tda10071_cmd cmd; 477 - int ret, i, len; 478 - u8 tmp, reg, buf[8]; 645 + struct tda10071_dev *dev = fe->demodulator_priv; 479 646 480 - if (!priv->warm || !(priv->fe_status & FE_HAS_LOCK)) { 481 - *ber = priv->ber = 0; 482 - ret = 0; 483 - goto error; 484 - } 485 - 486 - switch (priv->delivery_system) { 487 - case SYS_DVBS: 488 - reg = 0x4c; 489 - len = 8; 490 - i = 1; 491 - break; 492 - case SYS_DVBS2: 493 - reg = 0x4d; 494 - len = 4; 495 - i = 0; 496 - break; 497 - default: 498 - *ber = priv->ber = 0; 499 - return 0; 500 - } 501 - 502 - ret = tda10071_rd_reg(priv, reg, &tmp); 503 - if (ret) 504 - goto error; 505 - 506 - if (priv->meas_count[i] == tmp) { 507 - dev_dbg(&priv->i2c->dev, "%s: meas not ready=%02x\n", __func__, 508 - tmp); 509 - *ber = priv->ber; 510 - return 0; 511 - } else { 512 - priv->meas_count[i] = tmp; 513 - } 514 - 515 - cmd.args[0] = CMD_BER_UPDATE_COUNTERS; 516 - cmd.args[1] = 0; 517 - cmd.args[2] = i; 518 - cmd.len = 3; 519 - ret = tda10071_cmd_execute(priv, &cmd); 520 - if (ret) 521 - goto error; 522 - 523 - ret = tda10071_rd_regs(priv, cmd.len, buf, len); 524 - if (ret) 525 - goto error; 526 - 527 - if (priv->delivery_system == SYS_DVBS) { 528 - *ber = (buf[0] << 24) | (buf[1] << 16) | (buf[2] << 8) | buf[3]; 529 - priv->ucb += (buf[4] << 8) | buf[5]; 530 - } else { 531 - *ber = (buf[0] << 8) | buf[1]; 532 - } 533 - priv->ber = *ber; 534 - 535 - return ret; 536 - error: 537 - dev_dbg(&priv->i2c->dev, "%s: failed=%d\n", __func__, ret); 538 - return ret; 647 + *ber = dev->dvbv3_ber; 648 + return 0; 539 649 } 540 650 541 651 static int tda10071_read_ucblocks(struct dvb_frontend *fe, u32 *ucblocks) 542 652 { 543 - struct tda10071_priv *priv = fe->demodulator_priv; 544 - int ret = 0; 653 + struct dtv_frontend_properties *c = &fe->dtv_property_cache; 545 654 546 - if (!priv->warm || !(priv->fe_status & FE_HAS_LOCK)) { 655 + if (c->block_error.stat[0].scale == FE_SCALE_COUNTER) 656 + *ucblocks = c->block_error.stat[0].uvalue; 657 + else 547 658 *ucblocks = 0; 548 - goto error; 549 - } 550 - 551 - /* UCB is updated when BER is read. Assume BER is read anyway. */ 552 - 553 - *ucblocks = priv->ucb; 554 - 555 - return ret; 556 - error: 557 - dev_dbg(&priv->i2c->dev, "%s: failed=%d\n", __func__, ret); 558 - return ret; 659 + return 0; 559 660 } 560 661 561 662 static int tda10071_set_frontend(struct dvb_frontend *fe) 562 663 { 563 - struct tda10071_priv *priv = fe->demodulator_priv; 664 + struct tda10071_dev *dev = fe->demodulator_priv; 665 + struct i2c_client *client = dev->client; 564 666 struct tda10071_cmd cmd; 565 667 struct dtv_frontend_properties *c = &fe->dtv_property_cache; 566 668 int ret, i; 567 669 u8 mode, rolloff, pilot, inversion, div; 568 670 enum fe_modulation modulation; 569 671 570 - dev_dbg(&priv->i2c->dev, 571 - "%s: delivery_system=%d modulation=%d frequency=%d symbol_rate=%d inversion=%d pilot=%d rolloff=%d\n", 572 - __func__, c->delivery_system, c->modulation, 573 - c->frequency, c->symbol_rate, c->inversion, c->pilot, 574 - c->rolloff); 672 + dev_dbg(&client->dev, 673 + "delivery_system=%d modulation=%d frequency=%u symbol_rate=%d inversion=%d pilot=%d rolloff=%d\n", 674 + c->delivery_system, c->modulation, c->frequency, c->symbol_rate, 675 + c->inversion, c->pilot, c->rolloff); 575 676 576 - priv->delivery_system = SYS_UNDEFINED; 677 + dev->delivery_system = SYS_UNDEFINED; 577 678 578 - if (!priv->warm) { 679 + if (!dev->warm) { 579 680 ret = -EFAULT; 580 681 goto error; 581 682 } ··· 591 696 inversion = 3; 592 697 break; 593 698 default: 594 - dev_dbg(&priv->i2c->dev, "%s: invalid inversion\n", __func__); 699 + dev_dbg(&client->dev, "invalid inversion\n"); 595 700 ret = -EINVAL; 596 701 goto error; 597 702 } ··· 617 722 break; 618 723 case ROLLOFF_AUTO: 619 724 default: 620 - dev_dbg(&priv->i2c->dev, "%s: invalid rolloff\n", 621 - __func__); 725 + dev_dbg(&client->dev, "invalid rolloff\n"); 622 726 ret = -EINVAL; 623 727 goto error; 624 728 } ··· 633 739 pilot = 2; 634 740 break; 635 741 default: 636 - dev_dbg(&priv->i2c->dev, "%s: invalid pilot\n", 637 - __func__); 742 + dev_dbg(&client->dev, "invalid pilot\n"); 638 743 ret = -EINVAL; 639 744 goto error; 640 745 } 641 746 break; 642 747 default: 643 - dev_dbg(&priv->i2c->dev, "%s: invalid delivery_system\n", 644 - __func__); 748 + dev_dbg(&client->dev, "invalid delivery_system\n"); 645 749 ret = -EINVAL; 646 750 goto error; 647 751 } ··· 649 757 modulation == TDA10071_MODCOD[i].modulation && 650 758 c->fec_inner == TDA10071_MODCOD[i].fec) { 651 759 mode = TDA10071_MODCOD[i].val; 652 - dev_dbg(&priv->i2c->dev, "%s: mode found=%02x\n", 653 - __func__, mode); 760 + dev_dbg(&client->dev, "mode found=%02x\n", mode); 654 761 break; 655 762 } 656 763 } 657 764 658 765 if (mode == 0xff) { 659 - dev_dbg(&priv->i2c->dev, "%s: invalid parameter combination\n", 660 - __func__); 766 + dev_dbg(&client->dev, "invalid parameter combination\n"); 661 767 ret = -EINVAL; 662 768 goto error; 663 769 } ··· 665 775 else 666 776 div = 4; 667 777 668 - ret = tda10071_wr_reg(priv, 0x81, div); 778 + ret = regmap_write(dev->regmap, 0x81, div); 669 779 if (ret) 670 780 goto error; 671 781 672 - ret = tda10071_wr_reg(priv, 0xe3, div); 782 + ret = regmap_write(dev->regmap, 0xe3, div); 673 783 if (ret) 674 784 goto error; 675 785 ··· 689 799 cmd.args[13] = 0x00; 690 800 cmd.args[14] = 0x00; 691 801 cmd.len = 15; 692 - ret = tda10071_cmd_execute(priv, &cmd); 802 + ret = tda10071_cmd_execute(dev, &cmd); 693 803 if (ret) 694 804 goto error; 695 805 696 - priv->delivery_system = c->delivery_system; 806 + dev->delivery_system = c->delivery_system; 697 807 698 808 return ret; 699 809 error: 700 - dev_dbg(&priv->i2c->dev, "%s: failed=%d\n", __func__, ret); 810 + dev_dbg(&client->dev, "failed=%d\n", ret); 701 811 return ret; 702 812 } 703 813 704 814 static int tda10071_get_frontend(struct dvb_frontend *fe) 705 815 { 706 - struct tda10071_priv *priv = fe->demodulator_priv; 816 + struct tda10071_dev *dev = fe->demodulator_priv; 817 + struct i2c_client *client = dev->client; 707 818 struct dtv_frontend_properties *c = &fe->dtv_property_cache; 708 819 int ret, i; 709 820 u8 buf[5], tmp; 710 821 711 - if (!priv->warm || !(priv->fe_status & FE_HAS_LOCK)) { 712 - ret = -EFAULT; 822 + if (!dev->warm || !(dev->fe_status & FE_HAS_LOCK)) { 823 + ret = 0; 713 824 goto error; 714 825 } 715 826 716 - ret = tda10071_rd_regs(priv, 0x30, buf, 5); 827 + ret = regmap_bulk_read(dev->regmap, 0x30, buf, 5); 717 828 if (ret) 718 829 goto error; 719 830 ··· 747 856 748 857 c->frequency = (buf[2] << 16) | (buf[3] << 8) | (buf[4] << 0); 749 858 750 - ret = tda10071_rd_regs(priv, 0x52, buf, 3); 859 + ret = regmap_bulk_read(dev->regmap, 0x52, buf, 3); 751 860 if (ret) 752 861 goto error; 753 862 ··· 755 864 756 865 return ret; 757 866 error: 758 - dev_dbg(&priv->i2c->dev, "%s: failed=%d\n", __func__, ret); 867 + dev_dbg(&client->dev, "failed=%d\n", ret); 759 868 return ret; 760 869 } 761 870 762 871 static int tda10071_init(struct dvb_frontend *fe) 763 872 { 764 - struct tda10071_priv *priv = fe->demodulator_priv; 873 + struct tda10071_dev *dev = fe->demodulator_priv; 874 + struct i2c_client *client = dev->client; 875 + struct dtv_frontend_properties *c = &fe->dtv_property_cache; 765 876 struct tda10071_cmd cmd; 766 877 int ret, i, len, remaining, fw_size; 878 + unsigned int uitmp; 767 879 const struct firmware *fw; 768 880 u8 *fw_file = TDA10071_FIRMWARE; 769 881 u8 tmp, buf[4]; ··· 784 890 }; 785 891 struct tda10071_reg_val_mask tab2[] = { 786 892 { 0xf1, 0x70, 0xff }, 787 - { 0x88, priv->cfg.pll_multiplier, 0x3f }, 893 + { 0x88, dev->pll_multiplier, 0x3f }, 788 894 { 0x89, 0x00, 0x10 }, 789 895 { 0x89, 0x10, 0x10 }, 790 896 { 0xc0, 0x01, 0x01 }, ··· 828 934 { 0xd5, 0x03, 0x03 }, 829 935 }; 830 936 831 - if (priv->warm) { 937 + if (dev->warm) { 832 938 /* warm state - wake up device from sleep */ 833 939 834 940 for (i = 0; i < ARRAY_SIZE(tab); i++) { 835 - ret = tda10071_wr_reg_mask(priv, tab[i].reg, 941 + ret = tda10071_wr_reg_mask(dev, tab[i].reg, 836 942 tab[i].val, tab[i].mask); 837 943 if (ret) 838 944 goto error; ··· 842 948 cmd.args[1] = 0; 843 949 cmd.args[2] = 0; 844 950 cmd.len = 3; 845 - ret = tda10071_cmd_execute(priv, &cmd); 951 + ret = tda10071_cmd_execute(dev, &cmd); 846 952 if (ret) 847 953 goto error; 848 954 } else { 849 955 /* cold state - try to download firmware */ 850 956 851 957 /* request the firmware, this will block and timeout */ 852 - ret = request_firmware(&fw, fw_file, priv->i2c->dev.parent); 958 + ret = request_firmware(&fw, fw_file, &client->dev); 853 959 if (ret) { 854 - dev_err(&priv->i2c->dev, 855 - "%s: did not find the firmware file. (%s) Please see linux/Documentation/dvb/ for more details on firmware-problems. (%d)\n", 856 - KBUILD_MODNAME, fw_file, ret); 960 + dev_err(&client->dev, 961 + "did not find the firmware file. (%s) Please see linux/Documentation/dvb/ for more details on firmware-problems. (%d)\n", 962 + fw_file, ret); 857 963 goto error; 858 964 } 859 965 860 966 /* init */ 861 967 for (i = 0; i < ARRAY_SIZE(tab2); i++) { 862 - ret = tda10071_wr_reg_mask(priv, tab2[i].reg, 968 + ret = tda10071_wr_reg_mask(dev, tab2[i].reg, 863 969 tab2[i].val, tab2[i].mask); 864 970 if (ret) 865 971 goto error_release_firmware; 866 972 } 867 973 868 974 /* download firmware */ 869 - ret = tda10071_wr_reg(priv, 0xe0, 0x7f); 975 + ret = regmap_write(dev->regmap, 0xe0, 0x7f); 870 976 if (ret) 871 977 goto error_release_firmware; 872 978 873 - ret = tda10071_wr_reg(priv, 0xf7, 0x81); 979 + ret = regmap_write(dev->regmap, 0xf7, 0x81); 874 980 if (ret) 875 981 goto error_release_firmware; 876 982 877 - ret = tda10071_wr_reg(priv, 0xf8, 0x00); 983 + ret = regmap_write(dev->regmap, 0xf8, 0x00); 878 984 if (ret) 879 985 goto error_release_firmware; 880 986 881 - ret = tda10071_wr_reg(priv, 0xf9, 0x00); 987 + ret = regmap_write(dev->regmap, 0xf9, 0x00); 882 988 if (ret) 883 989 goto error_release_firmware; 884 990 885 - dev_info(&priv->i2c->dev, 886 - "%s: found a '%s' in cold state, will try to load a firmware\n", 887 - KBUILD_MODNAME, tda10071_ops.info.name); 888 - dev_info(&priv->i2c->dev, 889 - "%s: downloading firmware from file '%s'\n", 890 - KBUILD_MODNAME, fw_file); 991 + dev_info(&client->dev, 992 + "found a '%s' in cold state, will try to load a firmware\n", 993 + tda10071_ops.info.name); 994 + dev_info(&client->dev, "downloading firmware from file '%s'\n", 995 + fw_file); 891 996 892 997 /* do not download last byte */ 893 998 fw_size = fw->size - 1; 894 999 895 1000 for (remaining = fw_size; remaining > 0; 896 - remaining -= (priv->cfg.i2c_wr_max - 1)) { 1001 + remaining -= (dev->i2c_wr_max - 1)) { 897 1002 len = remaining; 898 - if (len > (priv->cfg.i2c_wr_max - 1)) 899 - len = (priv->cfg.i2c_wr_max - 1); 1003 + if (len > (dev->i2c_wr_max - 1)) 1004 + len = (dev->i2c_wr_max - 1); 900 1005 901 - ret = tda10071_wr_regs(priv, 0xfa, 1006 + ret = regmap_bulk_write(dev->regmap, 0xfa, 902 1007 (u8 *) &fw->data[fw_size - remaining], len); 903 1008 if (ret) { 904 - dev_err(&priv->i2c->dev, 905 - "%s: firmware download failed=%d\n", 906 - KBUILD_MODNAME, ret); 1009 + dev_err(&client->dev, 1010 + "firmware download failed=%d\n", ret); 907 1011 goto error_release_firmware; 908 1012 } 909 1013 } 910 1014 release_firmware(fw); 911 1015 912 - ret = tda10071_wr_reg(priv, 0xf7, 0x0c); 1016 + ret = regmap_write(dev->regmap, 0xf7, 0x0c); 913 1017 if (ret) 914 1018 goto error; 915 1019 916 - ret = tda10071_wr_reg(priv, 0xe0, 0x00); 1020 + ret = regmap_write(dev->regmap, 0xe0, 0x00); 917 1021 if (ret) 918 1022 goto error; 919 1023 ··· 919 1027 msleep(250); 920 1028 921 1029 /* firmware status */ 922 - ret = tda10071_rd_reg(priv, 0x51, &tmp); 1030 + ret = regmap_read(dev->regmap, 0x51, &uitmp); 923 1031 if (ret) 924 1032 goto error; 925 1033 926 - if (tmp) { 927 - dev_info(&priv->i2c->dev, "%s: firmware did not run\n", 928 - KBUILD_MODNAME); 1034 + if (uitmp) { 1035 + dev_info(&client->dev, "firmware did not run\n"); 929 1036 ret = -EFAULT; 930 1037 goto error; 931 1038 } else { 932 - priv->warm = true; 1039 + dev->warm = true; 933 1040 } 934 1041 935 1042 cmd.args[0] = CMD_GET_FW_VERSION; 936 1043 cmd.len = 1; 937 - ret = tda10071_cmd_execute(priv, &cmd); 1044 + ret = tda10071_cmd_execute(dev, &cmd); 938 1045 if (ret) 939 1046 goto error; 940 1047 941 - ret = tda10071_rd_regs(priv, cmd.len, buf, 4); 1048 + ret = regmap_bulk_read(dev->regmap, cmd.len, buf, 4); 942 1049 if (ret) 943 1050 goto error; 944 1051 945 - dev_info(&priv->i2c->dev, "%s: firmware version %d.%d.%d.%d\n", 946 - KBUILD_MODNAME, buf[0], buf[1], buf[2], buf[3]); 947 - dev_info(&priv->i2c->dev, "%s: found a '%s' in warm state\n", 948 - KBUILD_MODNAME, tda10071_ops.info.name); 1052 + dev_info(&client->dev, "firmware version %d.%d.%d.%d\n", 1053 + buf[0], buf[1], buf[2], buf[3]); 1054 + dev_info(&client->dev, "found a '%s' in warm state\n", 1055 + tda10071_ops.info.name); 949 1056 950 - ret = tda10071_rd_regs(priv, 0x81, buf, 2); 1057 + ret = regmap_bulk_read(dev->regmap, 0x81, buf, 2); 951 1058 if (ret) 952 1059 goto error; 953 1060 954 1061 cmd.args[0] = CMD_DEMOD_INIT; 955 - cmd.args[1] = ((priv->cfg.xtal / 1000) >> 8) & 0xff; 956 - cmd.args[2] = ((priv->cfg.xtal / 1000) >> 0) & 0xff; 1062 + cmd.args[1] = ((dev->clk / 1000) >> 8) & 0xff; 1063 + cmd.args[2] = ((dev->clk / 1000) >> 0) & 0xff; 957 1064 cmd.args[3] = buf[0]; 958 1065 cmd.args[4] = buf[1]; 959 - cmd.args[5] = priv->cfg.pll_multiplier; 960 - cmd.args[6] = priv->cfg.spec_inv; 1066 + cmd.args[5] = dev->pll_multiplier; 1067 + cmd.args[6] = dev->spec_inv; 961 1068 cmd.args[7] = 0x00; 962 1069 cmd.len = 8; 963 - ret = tda10071_cmd_execute(priv, &cmd); 1070 + ret = tda10071_cmd_execute(dev, &cmd); 964 1071 if (ret) 965 1072 goto error; 966 1073 967 - if (priv->cfg.tuner_i2c_addr) 968 - tmp = priv->cfg.tuner_i2c_addr; 1074 + if (dev->tuner_i2c_addr) 1075 + tmp = dev->tuner_i2c_addr; 969 1076 else 970 1077 tmp = 0x14; 971 1078 ··· 984 1093 cmd.args[13] = 0x00; 985 1094 cmd.args[14] = 0x00; 986 1095 cmd.len = 15; 987 - ret = tda10071_cmd_execute(priv, &cmd); 1096 + ret = tda10071_cmd_execute(dev, &cmd); 988 1097 if (ret) 989 1098 goto error; 990 1099 991 1100 cmd.args[0] = CMD_MPEG_CONFIG; 992 1101 cmd.args[1] = 0; 993 - cmd.args[2] = priv->cfg.ts_mode; 1102 + cmd.args[2] = dev->ts_mode; 994 1103 cmd.args[3] = 0x00; 995 1104 cmd.args[4] = 0x04; 996 1105 cmd.args[5] = 0x00; 997 1106 cmd.len = 6; 998 - ret = tda10071_cmd_execute(priv, &cmd); 1107 + ret = tda10071_cmd_execute(dev, &cmd); 999 1108 if (ret) 1000 1109 goto error; 1001 1110 1002 - ret = tda10071_wr_reg_mask(priv, 0xf0, 0x01, 0x01); 1111 + ret = regmap_update_bits(dev->regmap, 0xf0, 0x01, 0x01); 1003 1112 if (ret) 1004 1113 goto error; 1005 1114 ··· 1015 1124 cmd.args[9] = 30; 1016 1125 cmd.args[10] = 30; 1017 1126 cmd.len = 11; 1018 - ret = tda10071_cmd_execute(priv, &cmd); 1127 + ret = tda10071_cmd_execute(dev, &cmd); 1019 1128 if (ret) 1020 1129 goto error; 1021 1130 ··· 1024 1133 cmd.args[2] = 14; 1025 1134 cmd.args[3] = 14; 1026 1135 cmd.len = 4; 1027 - ret = tda10071_cmd_execute(priv, &cmd); 1136 + ret = tda10071_cmd_execute(dev, &cmd); 1028 1137 if (ret) 1029 1138 goto error; 1030 1139 } 1140 + 1141 + /* init stats here in order signal app which stats are supported */ 1142 + c->strength.len = 1; 1143 + c->strength.stat[0].scale = FE_SCALE_NOT_AVAILABLE; 1144 + c->cnr.len = 1; 1145 + c->cnr.stat[0].scale = FE_SCALE_NOT_AVAILABLE; 1146 + c->post_bit_error.len = 1; 1147 + c->post_bit_error.stat[0].scale = FE_SCALE_NOT_AVAILABLE; 1148 + c->block_error.len = 1; 1149 + c->block_error.stat[0].scale = FE_SCALE_NOT_AVAILABLE; 1031 1150 1032 1151 return ret; 1033 1152 error_release_firmware: 1034 1153 release_firmware(fw); 1035 1154 error: 1036 - dev_dbg(&priv->i2c->dev, "%s: failed=%d\n", __func__, ret); 1155 + dev_dbg(&client->dev, "failed=%d\n", ret); 1037 1156 return ret; 1038 1157 } 1039 1158 1040 1159 static int tda10071_sleep(struct dvb_frontend *fe) 1041 1160 { 1042 - struct tda10071_priv *priv = fe->demodulator_priv; 1161 + struct tda10071_dev *dev = fe->demodulator_priv; 1162 + struct i2c_client *client = dev->client; 1043 1163 struct tda10071_cmd cmd; 1044 1164 int ret, i; 1045 1165 struct tda10071_reg_val_mask tab[] = { ··· 1066 1164 { 0xce, 0x10, 0x10 }, 1067 1165 }; 1068 1166 1069 - if (!priv->warm) { 1167 + if (!dev->warm) { 1070 1168 ret = -EFAULT; 1071 1169 goto error; 1072 1170 } ··· 1075 1173 cmd.args[1] = 0; 1076 1174 cmd.args[2] = 1; 1077 1175 cmd.len = 3; 1078 - ret = tda10071_cmd_execute(priv, &cmd); 1176 + ret = tda10071_cmd_execute(dev, &cmd); 1079 1177 if (ret) 1080 1178 goto error; 1081 1179 1082 1180 for (i = 0; i < ARRAY_SIZE(tab); i++) { 1083 - ret = tda10071_wr_reg_mask(priv, tab[i].reg, tab[i].val, 1181 + ret = tda10071_wr_reg_mask(dev, tab[i].reg, tab[i].val, 1084 1182 tab[i].mask); 1085 1183 if (ret) 1086 1184 goto error; ··· 1088 1186 1089 1187 return ret; 1090 1188 error: 1091 - dev_dbg(&priv->i2c->dev, "%s: failed=%d\n", __func__, ret); 1189 + dev_dbg(&client->dev, "failed=%d\n", ret); 1092 1190 return ret; 1093 1191 } 1094 1192 ··· 1101 1199 1102 1200 return 0; 1103 1201 } 1104 - 1105 - static void tda10071_release(struct dvb_frontend *fe) 1106 - { 1107 - struct tda10071_priv *priv = fe->demodulator_priv; 1108 - kfree(priv); 1109 - } 1110 - 1111 - struct dvb_frontend *tda10071_attach(const struct tda10071_config *config, 1112 - struct i2c_adapter *i2c) 1113 - { 1114 - int ret; 1115 - struct tda10071_priv *priv = NULL; 1116 - u8 tmp; 1117 - 1118 - /* allocate memory for the internal priv */ 1119 - priv = kzalloc(sizeof(struct tda10071_priv), GFP_KERNEL); 1120 - if (priv == NULL) { 1121 - ret = -ENOMEM; 1122 - goto error; 1123 - } 1124 - 1125 - /* make sure demod i2c address is specified */ 1126 - if (!config->demod_i2c_addr) { 1127 - dev_dbg(&i2c->dev, "%s: invalid demod i2c address\n", __func__); 1128 - ret = -EINVAL; 1129 - goto error; 1130 - } 1131 - 1132 - /* make sure tuner i2c address is specified */ 1133 - if (!config->tuner_i2c_addr) { 1134 - dev_dbg(&i2c->dev, "%s: invalid tuner i2c address\n", __func__); 1135 - ret = -EINVAL; 1136 - goto error; 1137 - } 1138 - 1139 - /* setup the priv */ 1140 - priv->i2c = i2c; 1141 - memcpy(&priv->cfg, config, sizeof(struct tda10071_config)); 1142 - 1143 - /* chip ID */ 1144 - ret = tda10071_rd_reg(priv, 0xff, &tmp); 1145 - if (ret || tmp != 0x0f) 1146 - goto error; 1147 - 1148 - /* chip type */ 1149 - ret = tda10071_rd_reg(priv, 0xdd, &tmp); 1150 - if (ret || tmp != 0x00) 1151 - goto error; 1152 - 1153 - /* chip version */ 1154 - ret = tda10071_rd_reg(priv, 0xfe, &tmp); 1155 - if (ret || tmp != 0x01) 1156 - goto error; 1157 - 1158 - /* create dvb_frontend */ 1159 - memcpy(&priv->fe.ops, &tda10071_ops, sizeof(struct dvb_frontend_ops)); 1160 - priv->fe.demodulator_priv = priv; 1161 - 1162 - return &priv->fe; 1163 - error: 1164 - dev_dbg(&i2c->dev, "%s: failed=%d\n", __func__, ret); 1165 - kfree(priv); 1166 - return NULL; 1167 - } 1168 - EXPORT_SYMBOL(tda10071_attach); 1169 1202 1170 1203 static struct dvb_frontend_ops tda10071_ops = { 1171 1204 .delsys = { SYS_DVBS, SYS_DVBS2 }, ··· 1126 1289 FE_CAN_2G_MODULATION 1127 1290 }, 1128 1291 1129 - .release = tda10071_release, 1130 - 1131 1292 .get_tune_settings = tda10071_get_tune_settings, 1132 1293 1133 1294 .init = tda10071_init, ··· 1150 1315 1151 1316 static struct dvb_frontend *tda10071_get_dvb_frontend(struct i2c_client *client) 1152 1317 { 1153 - struct tda10071_priv *dev = i2c_get_clientdata(client); 1318 + struct tda10071_dev *dev = i2c_get_clientdata(client); 1154 1319 1155 1320 dev_dbg(&client->dev, "\n"); 1156 1321 ··· 1160 1325 static int tda10071_probe(struct i2c_client *client, 1161 1326 const struct i2c_device_id *id) 1162 1327 { 1163 - struct tda10071_priv *dev; 1328 + struct tda10071_dev *dev; 1164 1329 struct tda10071_platform_data *pdata = client->dev.platform_data; 1165 1330 int ret; 1166 - u8 u8tmp; 1331 + unsigned int uitmp; 1332 + static const struct regmap_config regmap_config = { 1333 + .reg_bits = 8, 1334 + .val_bits = 8, 1335 + }; 1167 1336 1168 1337 dev = kzalloc(sizeof(*dev), GFP_KERNEL); 1169 1338 if (!dev) { ··· 1176 1337 } 1177 1338 1178 1339 dev->client = client; 1179 - dev->i2c = client->adapter; 1180 - dev->cfg.demod_i2c_addr = client->addr; 1181 - dev->cfg.i2c_wr_max = pdata->i2c_wr_max; 1182 - dev->cfg.ts_mode = pdata->ts_mode; 1183 - dev->cfg.spec_inv = pdata->spec_inv; 1184 - dev->cfg.xtal = pdata->clk; 1185 - dev->cfg.pll_multiplier = pdata->pll_multiplier; 1186 - dev->cfg.tuner_i2c_addr = pdata->tuner_i2c_addr; 1340 + mutex_init(&dev->cmd_execute_mutex); 1341 + dev->clk = pdata->clk; 1342 + dev->i2c_wr_max = pdata->i2c_wr_max; 1343 + dev->ts_mode = pdata->ts_mode; 1344 + dev->spec_inv = pdata->spec_inv; 1345 + dev->pll_multiplier = pdata->pll_multiplier; 1346 + dev->tuner_i2c_addr = pdata->tuner_i2c_addr; 1347 + dev->regmap = devm_regmap_init_i2c(client, &regmap_config); 1348 + if (IS_ERR(dev->regmap)) { 1349 + ret = PTR_ERR(dev->regmap); 1350 + goto err_kfree; 1351 + } 1187 1352 1188 1353 /* chip ID */ 1189 - ret = tda10071_rd_reg(dev, 0xff, &u8tmp); 1354 + ret = regmap_read(dev->regmap, 0xff, &uitmp); 1190 1355 if (ret) 1191 1356 goto err_kfree; 1192 - if (u8tmp != 0x0f) { 1357 + if (uitmp != 0x0f) { 1193 1358 ret = -ENODEV; 1194 1359 goto err_kfree; 1195 1360 } 1196 1361 1197 1362 /* chip type */ 1198 - ret = tda10071_rd_reg(dev, 0xdd, &u8tmp); 1363 + ret = regmap_read(dev->regmap, 0xdd, &uitmp); 1199 1364 if (ret) 1200 1365 goto err_kfree; 1201 - if (u8tmp != 0x00) { 1366 + if (uitmp != 0x00) { 1202 1367 ret = -ENODEV; 1203 1368 goto err_kfree; 1204 1369 } 1205 1370 1206 1371 /* chip version */ 1207 - ret = tda10071_rd_reg(dev, 0xfe, &u8tmp); 1372 + ret = regmap_read(dev->regmap, 0xfe, &uitmp); 1208 1373 if (ret) 1209 1374 goto err_kfree; 1210 - if (u8tmp != 0x01) { 1375 + if (uitmp != 0x01) { 1211 1376 ret = -ENODEV; 1212 1377 goto err_kfree; 1213 1378 } 1214 1379 1215 1380 /* create dvb_frontend */ 1216 1381 memcpy(&dev->fe.ops, &tda10071_ops, sizeof(struct dvb_frontend_ops)); 1217 - dev->fe.ops.release = NULL; 1218 1382 dev->fe.demodulator_priv = dev; 1219 1383 i2c_set_clientdata(client, dev); 1220 1384 ··· 1251 1409 1252 1410 static struct i2c_driver tda10071_driver = { 1253 1411 .driver = { 1254 - .owner = THIS_MODULE, 1255 1412 .name = "tda10071", 1256 1413 .suppress_bind_attrs = true, 1257 1414 },
+1 -62
drivers/media/dvb-frontends/tda10071.h
··· 21 21 #ifndef TDA10071_H 22 22 #define TDA10071_H 23 23 24 - #include <linux/kconfig.h> 25 24 #include <linux/dvb/frontend.h> 26 25 27 26 /* 28 27 * I2C address 29 - * 0x55, 28 + * 0x05, 0x55, 30 29 */ 31 30 32 31 /** ··· 51 52 52 53 struct dvb_frontend* (*get_dvb_frontend)(struct i2c_client *); 53 54 }; 54 - 55 - struct tda10071_config { 56 - /* Demodulator I2C address. 57 - * Default: none, must set 58 - * Values: 0x55, 59 - */ 60 - u8 demod_i2c_addr; 61 - 62 - /* Tuner I2C address. 63 - * Default: none, must set 64 - * Values: 0x14, 0x54, ... 65 - */ 66 - u8 tuner_i2c_addr; 67 - 68 - /* Max bytes I2C provider can write at once. 69 - * Note: Buffer is taken from the stack currently! 70 - * Default: none, must set 71 - * Values: 72 - */ 73 - u16 i2c_wr_max; 74 - 75 - /* TS output mode. 76 - * Default: TDA10071_TS_SERIAL 77 - * Values: 78 - */ 79 - #define TDA10071_TS_SERIAL 0 80 - #define TDA10071_TS_PARALLEL 1 81 - u8 ts_mode; 82 - 83 - /* Input spectrum inversion. 84 - * Default: 0 85 - * Values: 0, 1 86 - */ 87 - bool spec_inv; 88 - 89 - /* Xtal frequency Hz 90 - * Default: none, must set 91 - * Values: 92 - */ 93 - u32 xtal; 94 - 95 - /* PLL multiplier. 96 - * Default: none, must set 97 - * Values: 98 - */ 99 - u8 pll_multiplier; 100 - }; 101 - 102 - 103 - #if IS_REACHABLE(CONFIG_DVB_TDA10071) 104 - extern struct dvb_frontend *tda10071_attach( 105 - const struct tda10071_config *config, struct i2c_adapter *i2c); 106 - #else 107 - static inline struct dvb_frontend *tda10071_attach( 108 - const struct tda10071_config *config, struct i2c_adapter *i2c) 109 - { 110 - dev_warn(&i2c->dev, "%s: driver disabled by Kconfig\n", __func__); 111 - return NULL; 112 - } 113 - #endif 114 55 115 56 #endif /* TDA10071_H */
+14 -6
drivers/media/dvb-frontends/tda10071_priv.h
··· 24 24 #include "dvb_frontend.h" 25 25 #include "tda10071.h" 26 26 #include <linux/firmware.h> 27 + #include <linux/regmap.h> 27 28 28 - struct tda10071_priv { 29 - struct i2c_adapter *i2c; 29 + struct tda10071_dev { 30 30 struct dvb_frontend fe; 31 31 struct i2c_client *client; 32 - struct tda10071_config cfg; 32 + struct regmap *regmap; 33 + struct mutex cmd_execute_mutex; 34 + u32 clk; 35 + u16 i2c_wr_max; 36 + u8 ts_mode; 37 + bool spec_inv; 38 + u8 pll_multiplier; 39 + u8 tuner_i2c_addr; 33 40 34 - u8 meas_count[2]; 35 - u32 ber; 36 - u32 ucb; 41 + u8 meas_count; 42 + u32 dvbv3_ber; 37 43 enum fe_status fe_status; 38 44 enum fe_delivery_system delivery_system; 39 45 bool warm; /* FW running */ 46 + u64 post_bit_error; 47 + u64 block_error; 40 48 }; 41 49 42 50 static struct tda10071_modcod {
-1
drivers/media/dvb-frontends/ts2020.c
··· 726 726 727 727 static struct i2c_driver ts2020_driver = { 728 728 .driver = { 729 - .owner = THIS_MODULE, 730 729 .name = "ts2020", 731 730 }, 732 731 .probe = ts2020_probe,
+13 -2
drivers/media/i2c/Kconfig
··· 22 22 # 23 23 24 24 menu "Encoders, decoders, sensors and other helper chips" 25 - visible if !MEDIA_SUBDRV_AUTOSELECT 25 + visible if !MEDIA_SUBDRV_AUTOSELECT || COMPILE_TEST 26 26 27 27 comment "Audio decoders, processors and mixers" 28 28 ··· 196 196 197 197 config VIDEO_ADV7604 198 198 tristate "Analog Devices ADV7604 decoder" 199 - depends on VIDEO_V4L2 && I2C && VIDEO_V4L2_SUBDEV_API && GPIOLIB 199 + depends on VIDEO_V4L2 && I2C && VIDEO_V4L2_SUBDEV_API 200 + depends on GPIOLIB || COMPILE_TEST 200 201 select HDMI 201 202 ---help--- 202 203 Support for the Analog Devices ADV7604 video decoder. ··· 286 285 287 286 To compile this driver as a module, choose M here: the 288 287 module will be called saa7115. 288 + 289 + config VIDEO_TC358743 290 + tristate "Toshiba TC358743 decoder" 291 + depends on VIDEO_V4L2 && I2C && VIDEO_V4L2_SUBDEV_API 292 + select HDMI 293 + ---help--- 294 + Support for the Toshiba TC358743 HDMI to MIPI CSI-2 bridge. 295 + 296 + To compile this driver as a module, choose M here: the 297 + module will be called tc358743. 289 298 290 299 config VIDEO_TVP514X 291 300 tristate "Texas Instruments TVP514x video decoder"
+1
drivers/media/i2c/Makefile
··· 78 78 obj-$(CONFIG_VIDEO_IR_I2C) += ir-kbd-i2c.o 79 79 obj-$(CONFIG_VIDEO_ML86V7667) += ml86v7667.o 80 80 obj-$(CONFIG_VIDEO_OV2659) += ov2659.o 81 + obj-$(CONFIG_VIDEO_TC358743) += tc358743.o
-1
drivers/media/i2c/adv7170.c
··· 401 401 402 402 static struct i2c_driver adv7170_driver = { 403 403 .driver = { 404 - .owner = THIS_MODULE, 405 404 .name = "adv7170", 406 405 }, 407 406 .probe = adv7170_probe,
-1
drivers/media/i2c/adv7175.c
··· 455 455 456 456 static struct i2c_driver adv7175_driver = { 457 457 .driver = { 458 - .owner = THIS_MODULE, 459 458 .name = "adv7175", 460 459 }, 461 460 .probe = adv7175_probe,
+11 -1
drivers/media/i2c/adv7180.c
··· 25 25 #include <linux/interrupt.h> 26 26 #include <linux/i2c.h> 27 27 #include <linux/slab.h> 28 + #include <linux/of.h> 28 29 #include <media/v4l2-ioctl.h> 29 30 #include <linux/videodev2.h> 30 31 #include <media/v4l2-device.h> ··· 1325 1324 #define ADV7180_PM_OPS NULL 1326 1325 #endif 1327 1326 1327 + #ifdef CONFIG_OF 1328 + static const struct of_device_id adv7180_of_id[] = { 1329 + { .compatible = "adi,adv7180", }, 1330 + { }, 1331 + }; 1332 + 1333 + MODULE_DEVICE_TABLE(of, adv7180_of_id); 1334 + #endif 1335 + 1328 1336 static struct i2c_driver adv7180_driver = { 1329 1337 .driver = { 1330 - .owner = THIS_MODULE, 1331 1338 .name = KBUILD_MODNAME, 1332 1339 .pm = ADV7180_PM_OPS, 1340 + .of_match_table = of_match_ptr(adv7180_of_id), 1333 1341 }, 1334 1342 .probe = adv7180_probe, 1335 1343 .remove = adv7180_remove,
-8
drivers/media/i2c/adv7343.c
··· 319 319 320 320 static const struct v4l2_subdev_core_ops adv7343_core_ops = { 321 321 .log_status = adv7343_log_status, 322 - .g_ext_ctrls = v4l2_subdev_g_ext_ctrls, 323 - .try_ext_ctrls = v4l2_subdev_try_ext_ctrls, 324 - .s_ext_ctrls = v4l2_subdev_s_ext_ctrls, 325 - .g_ctrl = v4l2_subdev_g_ctrl, 326 - .s_ctrl = v4l2_subdev_s_ctrl, 327 - .queryctrl = v4l2_subdev_queryctrl, 328 - .querymenu = v4l2_subdev_querymenu, 329 322 }; 330 323 331 324 static int adv7343_s_std_output(struct v4l2_subdev *sd, v4l2_std_id std) ··· 522 529 static struct i2c_driver adv7343_driver = { 523 530 .driver = { 524 531 .of_match_table = of_match_ptr(adv7343_of_match), 525 - .owner = THIS_MODULE, 526 532 .name = "adv7343", 527 533 }, 528 534 .probe = adv7343_probe,
-7
drivers/media/i2c/adv7393.c
··· 306 306 307 307 static const struct v4l2_subdev_core_ops adv7393_core_ops = { 308 308 .log_status = adv7393_log_status, 309 - .g_ext_ctrls = v4l2_subdev_g_ext_ctrls, 310 - .try_ext_ctrls = v4l2_subdev_try_ext_ctrls, 311 - .s_ext_ctrls = v4l2_subdev_s_ext_ctrls, 312 - .g_ctrl = v4l2_subdev_g_ctrl, 313 - .s_ctrl = v4l2_subdev_s_ctrl, 314 - .queryctrl = v4l2_subdev_queryctrl, 315 - .querymenu = v4l2_subdev_querymenu, 316 309 }; 317 310 318 311 static int adv7393_s_std_output(struct v4l2_subdev *sd, v4l2_std_id std)
+1 -2
drivers/media/i2c/adv7511.c
··· 40 40 41 41 MODULE_DESCRIPTION("Analog Devices ADV7511 HDMI Transmitter Device Driver"); 42 42 MODULE_AUTHOR("Hans Verkuil"); 43 - MODULE_LICENSE("GPL"); 43 + MODULE_LICENSE("GPL v2"); 44 44 45 45 #define MASK_ADV7511_EDID_RDY_INT 0x04 46 46 #define MASK_ADV7511_MSEN_INT 0x40 ··· 1576 1576 1577 1577 static struct i2c_driver adv7511_driver = { 1578 1578 .driver = { 1579 - .owner = THIS_MODULE, 1580 1579 .name = "adv7511", 1581 1580 }, 1582 1581 .probe = adv7511_probe,
+381 -105
drivers/media/i2c/adv7604.c
··· 37 37 #include <linux/v4l2-dv-timings.h> 38 38 #include <linux/videodev2.h> 39 39 #include <linux/workqueue.h> 40 + #include <linux/regmap.h> 40 41 41 42 #include <media/adv7604.h> 42 43 #include <media/v4l2-ctrls.h> 43 44 #include <media/v4l2-device.h> 45 + #include <media/v4l2-event.h> 44 46 #include <media/v4l2-dv-timings.h> 45 47 #include <media/v4l2-of.h> 46 48 ··· 83 81 enum adv76xx_type { 84 82 ADV7604, 85 83 ADV7611, 84 + ADV7612, 86 85 }; 87 86 88 87 struct adv76xx_reg_seq { ··· 190 187 191 188 /* i2c clients */ 192 189 struct i2c_client *i2c_clients[ADV76XX_PAGE_MAX]; 190 + 191 + /* Regmaps */ 192 + struct regmap *regmap[ADV76XX_PAGE_MAX]; 193 193 194 194 /* controls */ 195 195 struct v4l2_ctrl *detect_tx_5v_ctrl; ··· 379 373 380 374 /* ----------------------------------------------------------------------- */ 381 375 382 - static s32 adv_smbus_read_byte_data_check(struct i2c_client *client, 383 - u8 command, bool check) 376 + static int adv76xx_read_check(struct adv76xx_state *state, 377 + int client_page, u8 reg) 384 378 { 385 - union i2c_smbus_data data; 386 - 387 - if (!i2c_smbus_xfer(client->adapter, client->addr, client->flags, 388 - I2C_SMBUS_READ, command, 389 - I2C_SMBUS_BYTE_DATA, &data)) 390 - return data.byte; 391 - if (check) 392 - v4l_err(client, "error reading %02x, %02x\n", 393 - client->addr, command); 394 - return -EIO; 395 - } 396 - 397 - static s32 adv_smbus_read_byte_data(struct adv76xx_state *state, 398 - enum adv76xx_page page, u8 command) 399 - { 400 - return adv_smbus_read_byte_data_check(state->i2c_clients[page], 401 - command, true); 402 - } 403 - 404 - static s32 adv_smbus_write_byte_data(struct adv76xx_state *state, 405 - enum adv76xx_page page, u8 command, 406 - u8 value) 407 - { 408 - struct i2c_client *client = state->i2c_clients[page]; 409 - union i2c_smbus_data data; 379 + struct i2c_client *client = state->i2c_clients[client_page]; 410 380 int err; 411 - int i; 381 + unsigned int val; 412 382 413 - data.byte = value; 414 - for (i = 0; i < 3; i++) { 415 - err = i2c_smbus_xfer(client->adapter, client->addr, 416 - client->flags, 417 - I2C_SMBUS_WRITE, command, 418 - I2C_SMBUS_BYTE_DATA, &data); 419 - if (!err) 420 - break; 383 + err = regmap_read(state->regmap[client_page], reg, &val); 384 + 385 + if (err) { 386 + v4l_err(client, "error reading %02x, %02x\n", 387 + client->addr, reg); 388 + return err; 421 389 } 422 - if (err < 0) 423 - v4l_err(client, "error writing %02x, %02x, %02x\n", 424 - client->addr, command, value); 425 - return err; 390 + return val; 426 391 } 427 392 428 - static s32 adv_smbus_write_i2c_block_data(struct adv76xx_state *state, 429 - enum adv76xx_page page, u8 command, 430 - unsigned length, const u8 *values) 393 + /* adv76xx_write_block(): Write raw data with a maximum of I2C_SMBUS_BLOCK_MAX 394 + * size to one or more registers. 395 + * 396 + * A value of zero will be returned on success, a negative errno will 397 + * be returned in error cases. 398 + */ 399 + static int adv76xx_write_block(struct adv76xx_state *state, int client_page, 400 + unsigned int init_reg, const void *val, 401 + size_t val_len) 431 402 { 432 - struct i2c_client *client = state->i2c_clients[page]; 433 - union i2c_smbus_data data; 403 + struct regmap *regmap = state->regmap[client_page]; 434 404 435 - if (length > I2C_SMBUS_BLOCK_MAX) 436 - length = I2C_SMBUS_BLOCK_MAX; 437 - data.block[0] = length; 438 - memcpy(data.block + 1, values, length); 439 - return i2c_smbus_xfer(client->adapter, client->addr, client->flags, 440 - I2C_SMBUS_WRITE, command, 441 - I2C_SMBUS_I2C_BLOCK_DATA, &data); 405 + if (val_len > I2C_SMBUS_BLOCK_MAX) 406 + val_len = I2C_SMBUS_BLOCK_MAX; 407 + 408 + return regmap_raw_write(regmap, init_reg, val, val_len); 442 409 } 443 410 444 411 /* ----------------------------------------------------------------------- */ ··· 420 441 { 421 442 struct adv76xx_state *state = to_state(sd); 422 443 423 - return adv_smbus_read_byte_data(state, ADV76XX_PAGE_IO, reg); 444 + return adv76xx_read_check(state, ADV76XX_PAGE_IO, reg); 424 445 } 425 446 426 447 static inline int io_write(struct v4l2_subdev *sd, u8 reg, u8 val) 427 448 { 428 449 struct adv76xx_state *state = to_state(sd); 429 450 430 - return adv_smbus_write_byte_data(state, ADV76XX_PAGE_IO, reg, val); 451 + return regmap_write(state->regmap[ADV76XX_PAGE_IO], reg, val); 431 452 } 432 453 433 454 static inline int io_write_clr_set(struct v4l2_subdev *sd, u8 reg, u8 mask, u8 val) ··· 439 460 { 440 461 struct adv76xx_state *state = to_state(sd); 441 462 442 - return adv_smbus_read_byte_data(state, ADV7604_PAGE_AVLINK, reg); 463 + return adv76xx_read_check(state, ADV7604_PAGE_AVLINK, reg); 443 464 } 444 465 445 466 static inline int avlink_write(struct v4l2_subdev *sd, u8 reg, u8 val) 446 467 { 447 468 struct adv76xx_state *state = to_state(sd); 448 469 449 - return adv_smbus_write_byte_data(state, ADV7604_PAGE_AVLINK, reg, val); 470 + return regmap_write(state->regmap[ADV7604_PAGE_AVLINK], reg, val); 450 471 } 451 472 452 473 static inline int cec_read(struct v4l2_subdev *sd, u8 reg) 453 474 { 454 475 struct adv76xx_state *state = to_state(sd); 455 476 456 - return adv_smbus_read_byte_data(state, ADV76XX_PAGE_CEC, reg); 477 + return adv76xx_read_check(state, ADV76XX_PAGE_CEC, reg); 457 478 } 458 479 459 480 static inline int cec_write(struct v4l2_subdev *sd, u8 reg, u8 val) 460 481 { 461 482 struct adv76xx_state *state = to_state(sd); 462 483 463 - return adv_smbus_write_byte_data(state, ADV76XX_PAGE_CEC, reg, val); 484 + return regmap_write(state->regmap[ADV76XX_PAGE_CEC], reg, val); 464 485 } 465 486 466 487 static inline int infoframe_read(struct v4l2_subdev *sd, u8 reg) 467 488 { 468 489 struct adv76xx_state *state = to_state(sd); 469 490 470 - return adv_smbus_read_byte_data(state, ADV76XX_PAGE_INFOFRAME, reg); 491 + return adv76xx_read_check(state, ADV76XX_PAGE_INFOFRAME, reg); 471 492 } 472 493 473 494 static inline int infoframe_write(struct v4l2_subdev *sd, u8 reg, u8 val) 474 495 { 475 496 struct adv76xx_state *state = to_state(sd); 476 497 477 - return adv_smbus_write_byte_data(state, ADV76XX_PAGE_INFOFRAME, 478 - reg, val); 498 + return regmap_write(state->regmap[ADV76XX_PAGE_INFOFRAME], reg, val); 479 499 } 480 500 481 501 static inline int afe_read(struct v4l2_subdev *sd, u8 reg) 482 502 { 483 503 struct adv76xx_state *state = to_state(sd); 484 504 485 - return adv_smbus_read_byte_data(state, ADV76XX_PAGE_AFE, reg); 505 + return adv76xx_read_check(state, ADV76XX_PAGE_AFE, reg); 486 506 } 487 507 488 508 static inline int afe_write(struct v4l2_subdev *sd, u8 reg, u8 val) 489 509 { 490 510 struct adv76xx_state *state = to_state(sd); 491 511 492 - return adv_smbus_write_byte_data(state, ADV76XX_PAGE_AFE, reg, val); 512 + return regmap_write(state->regmap[ADV76XX_PAGE_AFE], reg, val); 493 513 } 494 514 495 515 static inline int rep_read(struct v4l2_subdev *sd, u8 reg) 496 516 { 497 517 struct adv76xx_state *state = to_state(sd); 498 518 499 - return adv_smbus_read_byte_data(state, ADV76XX_PAGE_REP, reg); 519 + return adv76xx_read_check(state, ADV76XX_PAGE_REP, reg); 500 520 } 501 521 502 522 static inline int rep_write(struct v4l2_subdev *sd, u8 reg, u8 val) 503 523 { 504 524 struct adv76xx_state *state = to_state(sd); 505 525 506 - return adv_smbus_write_byte_data(state, ADV76XX_PAGE_REP, reg, val); 526 + return regmap_write(state->regmap[ADV76XX_PAGE_REP], reg, val); 507 527 } 508 528 509 529 static inline int rep_write_clr_set(struct v4l2_subdev *sd, u8 reg, u8 mask, u8 val) ··· 514 536 { 515 537 struct adv76xx_state *state = to_state(sd); 516 538 517 - return adv_smbus_read_byte_data(state, ADV76XX_PAGE_EDID, reg); 539 + return adv76xx_read_check(state, ADV76XX_PAGE_EDID, reg); 518 540 } 519 541 520 542 static inline int edid_write(struct v4l2_subdev *sd, u8 reg, u8 val) 521 543 { 522 544 struct adv76xx_state *state = to_state(sd); 523 545 524 - return adv_smbus_write_byte_data(state, ADV76XX_PAGE_EDID, reg, val); 546 + return regmap_write(state->regmap[ADV76XX_PAGE_EDID], reg, val); 525 547 } 526 548 527 549 static inline int edid_write_block(struct v4l2_subdev *sd, 528 - unsigned len, const u8 *val) 550 + unsigned int total_len, const u8 *val) 529 551 { 530 552 struct adv76xx_state *state = to_state(sd); 531 553 int err = 0; 532 - int i; 554 + int i = 0; 555 + int len = 0; 533 556 534 - v4l2_dbg(2, debug, sd, "%s: write EDID block (%d byte)\n", __func__, len); 557 + v4l2_dbg(2, debug, sd, "%s: write EDID block (%d byte)\n", 558 + __func__, total_len); 535 559 536 - for (i = 0; !err && i < len; i += I2C_SMBUS_BLOCK_MAX) 537 - err = adv_smbus_write_i2c_block_data(state, ADV76XX_PAGE_EDID, 538 - i, I2C_SMBUS_BLOCK_MAX, val + i); 560 + while (!err && i < total_len) { 561 + len = (total_len - i) > I2C_SMBUS_BLOCK_MAX ? 562 + I2C_SMBUS_BLOCK_MAX : 563 + (total_len - i); 564 + 565 + err = adv76xx_write_block(state, ADV76XX_PAGE_EDID, 566 + i, val + i, len); 567 + i += len; 568 + } 569 + 539 570 return err; 540 571 } 541 572 ··· 574 587 { 575 588 struct adv76xx_state *state = to_state(sd); 576 589 577 - return adv_smbus_read_byte_data(state, ADV76XX_PAGE_HDMI, reg); 590 + return adv76xx_read_check(state, ADV76XX_PAGE_HDMI, reg); 578 591 } 579 592 580 593 static u16 hdmi_read16(struct v4l2_subdev *sd, u8 reg, u16 mask) ··· 586 599 { 587 600 struct adv76xx_state *state = to_state(sd); 588 601 589 - return adv_smbus_write_byte_data(state, ADV76XX_PAGE_HDMI, reg, val); 602 + return regmap_write(state->regmap[ADV76XX_PAGE_HDMI], reg, val); 590 603 } 591 604 592 605 static inline int hdmi_write_clr_set(struct v4l2_subdev *sd, u8 reg, u8 mask, u8 val) ··· 598 611 { 599 612 struct adv76xx_state *state = to_state(sd); 600 613 601 - return adv_smbus_write_byte_data(state, ADV76XX_PAGE_TEST, reg, val); 614 + return regmap_write(state->regmap[ADV76XX_PAGE_TEST], reg, val); 602 615 } 603 616 604 617 static inline int cp_read(struct v4l2_subdev *sd, u8 reg) 605 618 { 606 619 struct adv76xx_state *state = to_state(sd); 607 620 608 - return adv_smbus_read_byte_data(state, ADV76XX_PAGE_CP, reg); 621 + return adv76xx_read_check(state, ADV76XX_PAGE_CP, reg); 609 622 } 610 623 611 624 static u16 cp_read16(struct v4l2_subdev *sd, u8 reg, u16 mask) ··· 617 630 { 618 631 struct adv76xx_state *state = to_state(sd); 619 632 620 - return adv_smbus_write_byte_data(state, ADV76XX_PAGE_CP, reg, val); 633 + return regmap_write(state->regmap[ADV76XX_PAGE_CP], reg, val); 621 634 } 622 635 623 636 static inline int cp_write_clr_set(struct v4l2_subdev *sd, u8 reg, u8 mask, u8 val) ··· 629 642 { 630 643 struct adv76xx_state *state = to_state(sd); 631 644 632 - return adv_smbus_read_byte_data(state, ADV7604_PAGE_VDP, reg); 645 + return adv76xx_read_check(state, ADV7604_PAGE_VDP, reg); 633 646 } 634 647 635 648 static inline int vdp_write(struct v4l2_subdev *sd, u8 reg, u8 val) 636 649 { 637 650 struct adv76xx_state *state = to_state(sd); 638 651 639 - return adv_smbus_write_byte_data(state, ADV7604_PAGE_VDP, reg, val); 652 + return regmap_write(state->regmap[ADV7604_PAGE_VDP], reg, val); 640 653 } 641 654 642 655 #define ADV76XX_REG(page, offset) (((page) << 8) | (offset)) ··· 647 660 { 648 661 struct adv76xx_state *state = to_state(sd); 649 662 unsigned int page = reg >> 8; 663 + unsigned int val; 664 + int err; 650 665 651 666 if (!(BIT(page) & state->info->page_mask)) 652 667 return -EINVAL; 653 668 654 669 reg &= 0xff; 670 + err = regmap_read(state->regmap[page], reg, &val); 655 671 656 - return adv_smbus_read_byte_data(state, page, reg); 672 + return err ? err : val; 657 673 } 658 674 #endif 659 675 ··· 670 680 671 681 reg &= 0xff; 672 682 673 - return adv_smbus_write_byte_data(state, page, reg, val); 683 + return regmap_write(state->regmap[page], reg, val); 674 684 } 675 685 676 686 static void adv76xx_write_reg_seq(struct v4l2_subdev *sd, ··· 754 764 ADV76XX_OP_MODE_SEL_SDR_422_2X | ADV76XX_OP_FORMAT_SEL_12BIT }, 755 765 { MEDIA_BUS_FMT_YVYU12_1X24, ADV76XX_OP_CH_SEL_RGB, false, true, 756 766 ADV76XX_OP_MODE_SEL_SDR_422_2X | ADV76XX_OP_FORMAT_SEL_12BIT }, 767 + }; 768 + 769 + static const struct adv76xx_format_info adv7612_formats[] = { 770 + { MEDIA_BUS_FMT_RGB888_1X24, ADV76XX_OP_CH_SEL_RGB, true, false, 771 + ADV76XX_OP_MODE_SEL_SDR_444 | ADV76XX_OP_FORMAT_SEL_8BIT }, 772 + { MEDIA_BUS_FMT_YUYV8_2X8, ADV76XX_OP_CH_SEL_RGB, false, false, 773 + ADV76XX_OP_MODE_SEL_SDR_422 | ADV76XX_OP_FORMAT_SEL_8BIT }, 774 + { MEDIA_BUS_FMT_YVYU8_2X8, ADV76XX_OP_CH_SEL_RGB, false, true, 775 + ADV76XX_OP_MODE_SEL_SDR_422 | ADV76XX_OP_FORMAT_SEL_8BIT }, 776 + { MEDIA_BUS_FMT_UYVY8_1X16, ADV76XX_OP_CH_SEL_RBG, false, false, 777 + ADV76XX_OP_MODE_SEL_SDR_422_2X | ADV76XX_OP_FORMAT_SEL_8BIT }, 778 + { MEDIA_BUS_FMT_VYUY8_1X16, ADV76XX_OP_CH_SEL_RBG, false, true, 779 + ADV76XX_OP_MODE_SEL_SDR_422_2X | ADV76XX_OP_FORMAT_SEL_8BIT }, 780 + { MEDIA_BUS_FMT_YUYV8_1X16, ADV76XX_OP_CH_SEL_RGB, false, false, 781 + ADV76XX_OP_MODE_SEL_SDR_422_2X | ADV76XX_OP_FORMAT_SEL_8BIT }, 782 + { MEDIA_BUS_FMT_YVYU8_1X16, ADV76XX_OP_CH_SEL_RGB, false, true, 783 + ADV76XX_OP_MODE_SEL_SDR_422_2X | ADV76XX_OP_FORMAT_SEL_8BIT }, 757 784 }; 758 785 759 786 static const struct adv76xx_format_info * ··· 872 865 873 866 static unsigned int adv7611_read_cable_det(struct v4l2_subdev *sd) 874 867 { 868 + u8 value = io_read(sd, 0x6f); 869 + 870 + return value & 1; 871 + } 872 + 873 + static unsigned int adv7612_read_cable_det(struct v4l2_subdev *sd) 874 + { 875 + /* Reads CABLE_DET_A_RAW. For input B support, need to 876 + * account for bit 7 [MSB] of 0x6a (ie. CABLE_DET_B_RAW) 877 + */ 875 878 u8 value = io_read(sd, 0x6f); 876 879 877 880 return value & 1; ··· 993 976 /* Should only be set in auto-graphics mode [REF_02, p. 91-92] */ 994 977 /* setup PLL_DIV_MAN_EN and PLL_DIV_RATIO */ 995 978 /* IO-map reg. 0x16 and 0x17 should be written in sequence */ 996 - if (adv_smbus_write_i2c_block_data(state, ADV76XX_PAGE_IO, 997 - 0x16, 2, pll)) 979 + if (regmap_raw_write(state->regmap[ADV76XX_PAGE_IO], 980 + 0x16, pll, 2)) 998 981 v4l2_err(sd, "writing to reg 0x16 and 0x17 failed\n"); 999 982 1000 983 /* active video - horizontal timing */ ··· 1045 1028 offset_buf[3] = offset_c & 0x0ff; 1046 1029 1047 1030 /* Registers must be written in this order with no i2c access in between */ 1048 - if (adv_smbus_write_i2c_block_data(state, ADV76XX_PAGE_CP, 1049 - 0x77, 4, offset_buf)) 1031 + if (regmap_raw_write(state->regmap[ADV76XX_PAGE_CP], 1032 + 0x77, offset_buf, 4)) 1050 1033 v4l2_err(sd, "%s: i2c error writing to CP reg 0x77, 0x78, 0x79, 0x7a\n", __func__); 1051 1034 } 1052 1035 ··· 1075 1058 gain_buf[3] = ((gain_c & 0x0ff)); 1076 1059 1077 1060 /* Registers must be written in this order with no i2c access in between */ 1078 - if (adv_smbus_write_i2c_block_data(state, ADV76XX_PAGE_CP, 1079 - 0x73, 4, gain_buf)) 1061 + if (regmap_raw_write(state->regmap[ADV76XX_PAGE_CP], 1062 + 0x73, gain_buf, 4)) 1080 1063 v4l2_err(sd, "%s: i2c error writing to CP reg 0x73, 0x74, 0x75, 0x76\n", __func__); 1081 1064 } 1082 1065 ··· 1345 1328 } 1346 1329 } 1347 1330 1348 - if (v4l2_detect_cvt(stdi->lcf + 1, hfreq, stdi->lcvs, 1331 + if (v4l2_detect_cvt(stdi->lcf + 1, hfreq, stdi->lcvs, 0, 1349 1332 (stdi->hs_pol == '+' ? V4L2_DV_HSYNC_POS_POL : 0) | 1350 1333 (stdi->vs_pol == '+' ? V4L2_DV_VSYNC_POS_POL : 0), 1351 1334 false, timings)) ··· 1777 1760 select_input(sd); 1778 1761 enable_input(sd); 1779 1762 1780 - v4l2_subdev_notify(sd, V4L2_DEVICE_NOTIFY_EVENT, 1781 - (void *)&adv76xx_ev_fmt); 1763 + v4l2_subdev_notify_event(sd, &adv76xx_ev_fmt); 1764 + 1782 1765 return 0; 1783 1766 } 1784 1767 ··· 1945 1928 "%s: fmt_change = 0x%x, fmt_change_digital = 0x%x\n", 1946 1929 __func__, fmt_change, fmt_change_digital); 1947 1930 1948 - v4l2_subdev_notify(sd, V4L2_DEVICE_NOTIFY_EVENT, 1949 - (void *)&adv76xx_ev_fmt); 1931 + v4l2_subdev_notify_event(sd, &adv76xx_ev_fmt); 1950 1932 1951 1933 if (handled) 1952 1934 *handled = true; ··· 2363 2347 return 0; 2364 2348 } 2365 2349 2350 + static int adv76xx_subscribe_event(struct v4l2_subdev *sd, 2351 + struct v4l2_fh *fh, 2352 + struct v4l2_event_subscription *sub) 2353 + { 2354 + switch (sub->type) { 2355 + case V4L2_EVENT_SOURCE_CHANGE: 2356 + return v4l2_src_change_event_subdev_subscribe(sd, fh, sub); 2357 + case V4L2_EVENT_CTRL: 2358 + return v4l2_ctrl_subdev_subscribe_event(sd, fh, sub); 2359 + default: 2360 + return -EINVAL; 2361 + } 2362 + } 2363 + 2366 2364 /* ----------------------------------------------------------------------- */ 2367 2365 2368 2366 static const struct v4l2_ctrl_ops adv76xx_ctrl_ops = { ··· 2386 2356 static const struct v4l2_subdev_core_ops adv76xx_core_ops = { 2387 2357 .log_status = adv76xx_log_status, 2388 2358 .interrupt_service_routine = adv76xx_isr, 2359 + .subscribe_event = adv76xx_subscribe_event, 2360 + .unsubscribe_event = v4l2_event_subdev_unsubscribe, 2389 2361 #ifdef CONFIG_VIDEO_ADV_DEBUG 2390 2362 .g_register = adv76xx_g_register, 2391 2363 .s_register = adv76xx_s_register, ··· 2542 2510 io_write(sd, 0x41, 0xd0); /* STDI irq for any change, disable INT2 */ 2543 2511 } 2544 2512 2513 + static void adv7612_setup_irqs(struct v4l2_subdev *sd) 2514 + { 2515 + io_write(sd, 0x41, 0xd0); /* disable INT2 */ 2516 + } 2517 + 2545 2518 static void adv76xx_unregister_clients(struct adv76xx_state *state) 2546 2519 { 2547 2520 unsigned int i; ··· 2631 2594 { ADV76XX_REG(ADV76XX_PAGE_HDMI, 0x8d), 0x04 }, 2632 2595 { ADV76XX_REG(ADV76XX_PAGE_HDMI, 0x8e), 0x1e }, 2633 2596 2597 + { ADV76XX_REG_SEQ_TERM, 0 }, 2598 + }; 2599 + 2600 + static const struct adv76xx_reg_seq adv7612_recommended_settings_hdmi[] = { 2601 + { ADV76XX_REG(ADV76XX_PAGE_CP, 0x6c), 0x00 }, 2602 + { ADV76XX_REG(ADV76XX_PAGE_HDMI, 0x9b), 0x03 }, 2603 + { ADV76XX_REG(ADV76XX_PAGE_HDMI, 0x6f), 0x08 }, 2604 + { ADV76XX_REG(ADV76XX_PAGE_HDMI, 0x85), 0x1f }, 2605 + { ADV76XX_REG(ADV76XX_PAGE_HDMI, 0x87), 0x70 }, 2606 + { ADV76XX_REG(ADV76XX_PAGE_HDMI, 0x57), 0xda }, 2607 + { ADV76XX_REG(ADV76XX_PAGE_HDMI, 0x58), 0x01 }, 2608 + { ADV76XX_REG(ADV76XX_PAGE_HDMI, 0x03), 0x98 }, 2609 + { ADV76XX_REG(ADV76XX_PAGE_HDMI, 0x4c), 0x44 }, 2634 2610 { ADV76XX_REG_SEQ_TERM, 0 }, 2635 2611 }; 2636 2612 ··· 2735 2685 .field1_vsync_mask = 0x3fff, 2736 2686 .field1_vbackporch_mask = 0x3fff, 2737 2687 }, 2688 + [ADV7612] = { 2689 + .type = ADV7612, 2690 + .has_afe = false, 2691 + .max_port = ADV76XX_PAD_HDMI_PORT_A, /* B not supported */ 2692 + .num_dv_ports = 1, /* normally 2 */ 2693 + .edid_enable_reg = 0x74, 2694 + .edid_status_reg = 0x76, 2695 + .lcf_reg = 0xa3, 2696 + .tdms_lock_mask = 0x43, 2697 + .cable_det_mask = 0x01, 2698 + .fmt_change_digital_mask = 0x03, 2699 + .cp_csc = 0xf4, 2700 + .formats = adv7612_formats, 2701 + .nformats = ARRAY_SIZE(adv7612_formats), 2702 + .set_termination = adv7611_set_termination, 2703 + .setup_irqs = adv7612_setup_irqs, 2704 + .read_hdmi_pixelclock = adv7611_read_hdmi_pixelclock, 2705 + .read_cable_det = adv7612_read_cable_det, 2706 + .recommended_settings = { 2707 + [1] = adv7612_recommended_settings_hdmi, 2708 + }, 2709 + .num_recommended_settings = { 2710 + [1] = ARRAY_SIZE(adv7612_recommended_settings_hdmi), 2711 + }, 2712 + .page_mask = BIT(ADV76XX_PAGE_IO) | BIT(ADV76XX_PAGE_CEC) | 2713 + BIT(ADV76XX_PAGE_INFOFRAME) | BIT(ADV76XX_PAGE_AFE) | 2714 + BIT(ADV76XX_PAGE_REP) | BIT(ADV76XX_PAGE_EDID) | 2715 + BIT(ADV76XX_PAGE_HDMI) | BIT(ADV76XX_PAGE_CP), 2716 + .linewidth_mask = 0x1fff, 2717 + .field0_height_mask = 0x1fff, 2718 + .field1_height_mask = 0x1fff, 2719 + .hfrontporch_mask = 0x1fff, 2720 + .hsync_mask = 0x1fff, 2721 + .hbackporch_mask = 0x1fff, 2722 + .field0_vfrontporch_mask = 0x3fff, 2723 + .field0_vsync_mask = 0x3fff, 2724 + .field0_vbackporch_mask = 0x3fff, 2725 + .field1_vfrontporch_mask = 0x3fff, 2726 + .field1_vsync_mask = 0x3fff, 2727 + .field1_vbackporch_mask = 0x3fff, 2728 + }, 2738 2729 }; 2739 2730 2740 2731 static const struct i2c_device_id adv76xx_i2c_id[] = { 2741 2732 { "adv7604", (kernel_ulong_t)&adv76xx_chip_info[ADV7604] }, 2742 2733 { "adv7611", (kernel_ulong_t)&adv76xx_chip_info[ADV7611] }, 2734 + { "adv7612", (kernel_ulong_t)&adv76xx_chip_info[ADV7612] }, 2743 2735 { } 2744 2736 }; 2745 2737 MODULE_DEVICE_TABLE(i2c, adv76xx_i2c_id); 2746 2738 2747 2739 static const struct of_device_id adv76xx_of_id[] __maybe_unused = { 2748 2740 { .compatible = "adi,adv7611", .data = &adv76xx_chip_info[ADV7611] }, 2741 + { .compatible = "adi,adv7612", .data = &adv76xx_chip_info[ADV7612] }, 2749 2742 { } 2750 2743 }; 2751 2744 MODULE_DEVICE_TABLE(of, adv76xx_of_id); ··· 2799 2706 struct device_node *endpoint; 2800 2707 struct device_node *np; 2801 2708 unsigned int flags; 2709 + u32 v; 2802 2710 2803 2711 np = state->i2c_clients[ADV76XX_PAGE_IO]->dev.of_node; 2804 2712 ··· 2809 2715 return -EINVAL; 2810 2716 2811 2717 v4l2_of_parse_endpoint(endpoint, &bus_cfg); 2718 + 2719 + if (!of_property_read_u32(endpoint, "default-input", &v)) 2720 + state->pdata.default_input = v; 2721 + else 2722 + state->pdata.default_input = -1; 2723 + 2812 2724 of_node_put(endpoint); 2813 2725 2814 2726 flags = bus_cfg.bus.parallel.flags; ··· 2853 2753 /* Hardcode the remaining platform data fields. */ 2854 2754 state->pdata.disable_pwrdnb = 0; 2855 2755 state->pdata.disable_cable_det_rst = 0; 2856 - state->pdata.default_input = -1; 2857 2756 state->pdata.blank_data = 1; 2858 2757 state->pdata.alt_data_sat = 1; 2859 2758 state->pdata.op_format_mode_sel = ADV7604_OP_FORMAT_MODE0; 2860 2759 state->pdata.bus_order = ADV7604_BUS_ORDER_RGB; 2861 2760 2761 + return 0; 2762 + } 2763 + 2764 + static const struct regmap_config adv76xx_regmap_cnf[] = { 2765 + { 2766 + .name = "io", 2767 + .reg_bits = 8, 2768 + .val_bits = 8, 2769 + 2770 + .max_register = 0xff, 2771 + .cache_type = REGCACHE_NONE, 2772 + }, 2773 + { 2774 + .name = "avlink", 2775 + .reg_bits = 8, 2776 + .val_bits = 8, 2777 + 2778 + .max_register = 0xff, 2779 + .cache_type = REGCACHE_NONE, 2780 + }, 2781 + { 2782 + .name = "cec", 2783 + .reg_bits = 8, 2784 + .val_bits = 8, 2785 + 2786 + .max_register = 0xff, 2787 + .cache_type = REGCACHE_NONE, 2788 + }, 2789 + { 2790 + .name = "infoframe", 2791 + .reg_bits = 8, 2792 + .val_bits = 8, 2793 + 2794 + .max_register = 0xff, 2795 + .cache_type = REGCACHE_NONE, 2796 + }, 2797 + { 2798 + .name = "esdp", 2799 + .reg_bits = 8, 2800 + .val_bits = 8, 2801 + 2802 + .max_register = 0xff, 2803 + .cache_type = REGCACHE_NONE, 2804 + }, 2805 + { 2806 + .name = "epp", 2807 + .reg_bits = 8, 2808 + .val_bits = 8, 2809 + 2810 + .max_register = 0xff, 2811 + .cache_type = REGCACHE_NONE, 2812 + }, 2813 + { 2814 + .name = "afe", 2815 + .reg_bits = 8, 2816 + .val_bits = 8, 2817 + 2818 + .max_register = 0xff, 2819 + .cache_type = REGCACHE_NONE, 2820 + }, 2821 + { 2822 + .name = "rep", 2823 + .reg_bits = 8, 2824 + .val_bits = 8, 2825 + 2826 + .max_register = 0xff, 2827 + .cache_type = REGCACHE_NONE, 2828 + }, 2829 + { 2830 + .name = "edid", 2831 + .reg_bits = 8, 2832 + .val_bits = 8, 2833 + 2834 + .max_register = 0xff, 2835 + .cache_type = REGCACHE_NONE, 2836 + }, 2837 + 2838 + { 2839 + .name = "hdmi", 2840 + .reg_bits = 8, 2841 + .val_bits = 8, 2842 + 2843 + .max_register = 0xff, 2844 + .cache_type = REGCACHE_NONE, 2845 + }, 2846 + { 2847 + .name = "test", 2848 + .reg_bits = 8, 2849 + .val_bits = 8, 2850 + 2851 + .max_register = 0xff, 2852 + .cache_type = REGCACHE_NONE, 2853 + }, 2854 + { 2855 + .name = "cp", 2856 + .reg_bits = 8, 2857 + .val_bits = 8, 2858 + 2859 + .max_register = 0xff, 2860 + .cache_type = REGCACHE_NONE, 2861 + }, 2862 + { 2863 + .name = "vdp", 2864 + .reg_bits = 8, 2865 + .val_bits = 8, 2866 + 2867 + .max_register = 0xff, 2868 + .cache_type = REGCACHE_NONE, 2869 + }, 2870 + }; 2871 + 2872 + static int configure_regmap(struct adv76xx_state *state, int region) 2873 + { 2874 + int err; 2875 + 2876 + if (!state->i2c_clients[region]) 2877 + return -ENODEV; 2878 + 2879 + state->regmap[region] = 2880 + devm_regmap_init_i2c(state->i2c_clients[region], 2881 + &adv76xx_regmap_cnf[region]); 2882 + 2883 + if (IS_ERR(state->regmap[region])) { 2884 + err = PTR_ERR(state->regmap[region]); 2885 + v4l_err(state->i2c_clients[region], 2886 + "Error initializing regmap %d with error %d\n", 2887 + region, err); 2888 + return -EINVAL; 2889 + } 2890 + 2891 + return 0; 2892 + } 2893 + 2894 + static int configure_regmaps(struct adv76xx_state *state) 2895 + { 2896 + int i, err; 2897 + 2898 + for (i = ADV7604_PAGE_AVLINK ; i < ADV76XX_PAGE_MAX; i++) { 2899 + err = configure_regmap(state, i); 2900 + if (err && (err != -ENODEV)) 2901 + return err; 2902 + } 2862 2903 return 0; 2863 2904 } 2864 2905 ··· 3012 2771 struct v4l2_ctrl_handler *hdl; 3013 2772 struct v4l2_subdev *sd; 3014 2773 unsigned int i; 3015 - u16 val; 2774 + unsigned int val, val2; 3016 2775 int err; 3017 2776 3018 2777 /* Check if the adapter supports the needed features */ ··· 3074 2833 snprintf(sd->name, sizeof(sd->name), "%s %d-%04x", 3075 2834 id->name, i2c_adapter_id(client->adapter), 3076 2835 client->addr); 3077 - sd->flags |= V4L2_SUBDEV_FL_HAS_DEVNODE; 2836 + sd->flags |= V4L2_SUBDEV_FL_HAS_DEVNODE | V4L2_SUBDEV_FL_HAS_EVENTS; 2837 + 2838 + /* Configure IO Regmap region */ 2839 + err = configure_regmap(state, ADV76XX_PAGE_IO); 2840 + 2841 + if (err) { 2842 + v4l2_err(sd, "Error configuring IO regmap region\n"); 2843 + return -ENODEV; 2844 + } 3078 2845 3079 2846 /* 3080 2847 * Verify that the chip is present. On ADV7604 the RD_INFO register only 3081 2848 * identifies the revision, while on ADV7611 it identifies the model as 3082 2849 * well. Use the HDMI slave address on ADV7604 and RD_INFO on ADV7611. 3083 2850 */ 3084 - if (state->info->type == ADV7604) { 3085 - val = adv_smbus_read_byte_data_check(client, 0xfb, false); 2851 + switch (state->info->type) { 2852 + case ADV7604: 2853 + err = regmap_read(state->regmap[ADV76XX_PAGE_IO], 0xfb, &val); 2854 + if (err) { 2855 + v4l2_err(sd, "Error %d reading IO Regmap\n", err); 2856 + return -ENODEV; 2857 + } 3086 2858 if (val != 0x68) { 3087 - v4l2_info(sd, "not an adv7604 on address 0x%x\n", 2859 + v4l2_err(sd, "not an adv7604 on address 0x%x\n", 3088 2860 client->addr << 1); 3089 2861 return -ENODEV; 3090 2862 } 3091 - } else { 3092 - val = (adv_smbus_read_byte_data_check(client, 0xea, false) << 8) 3093 - | (adv_smbus_read_byte_data_check(client, 0xeb, false) << 0); 3094 - if (val != 0x2051) { 3095 - v4l2_info(sd, "not an adv7611 on address 0x%x\n", 2863 + break; 2864 + case ADV7611: 2865 + case ADV7612: 2866 + err = regmap_read(state->regmap[ADV76XX_PAGE_IO], 2867 + 0xea, 2868 + &val); 2869 + if (err) { 2870 + v4l2_err(sd, "Error %d reading IO Regmap\n", err); 2871 + return -ENODEV; 2872 + } 2873 + val2 = val << 8; 2874 + err = regmap_read(state->regmap[ADV76XX_PAGE_IO], 2875 + 0xeb, 2876 + &val); 2877 + if (err) { 2878 + v4l2_err(sd, "Error %d reading IO Regmap\n", err); 2879 + return -ENODEV; 2880 + } 2881 + val |= val2; 2882 + if ((state->info->type == ADV7611 && val != 0x2051) || 2883 + (state->info->type == ADV7612 && val != 0x2041)) { 2884 + v4l2_err(sd, "not an adv761x on address 0x%x\n", 3096 2885 client->addr << 1); 3097 2886 return -ENODEV; 3098 2887 } 2888 + break; 3099 2889 } 3100 2890 3101 2891 /* control handlers */ ··· 3213 2941 if (err) 3214 2942 goto err_work_queues; 3215 2943 2944 + /* Configure regmaps */ 2945 + err = configure_regmaps(state); 2946 + if (err) 2947 + goto err_entity; 2948 + 3216 2949 err = adv76xx_core_init(sd); 3217 2950 if (err) 3218 2951 goto err_entity; ··· 3262 2985 3263 2986 static struct i2c_driver adv76xx_driver = { 3264 2987 .driver = { 3265 - .owner = THIS_MODULE, 3266 2988 .name = "adv7604", 3267 2989 .of_match_table = of_match_ptr(adv76xx_of_id), 3268 2990 },
+21 -7
drivers/media/i2c/adv7842.c
··· 40 40 #include <linux/v4l2-dv-timings.h> 41 41 #include <linux/hdmi.h> 42 42 #include <media/v4l2-device.h> 43 + #include <media/v4l2-event.h> 43 44 #include <media/v4l2-ctrls.h> 44 45 #include <media/v4l2-dv-timings.h> 45 46 #include <media/adv7842.h> ··· 1443 1442 } 1444 1443 } 1445 1444 1446 - if (v4l2_detect_cvt(stdi->lcf + 1, hfreq, stdi->lcvs, 1445 + if (v4l2_detect_cvt(stdi->lcf + 1, hfreq, stdi->lcvs, 0, 1447 1446 (stdi->hs_pol == '+' ? V4L2_DV_HSYNC_POS_POL : 0) | 1448 1447 (stdi->vs_pol == '+' ? V4L2_DV_VSYNC_POS_POL : 0), 1449 1448 false, timings)) ··· 1981 1980 select_input(sd, state->vid_std_select); 1982 1981 enable_input(sd); 1983 1982 1984 - v4l2_subdev_notify(sd, V4L2_DEVICE_NOTIFY_EVENT, 1985 - (void *)&adv7842_ev_fmt); 1983 + v4l2_subdev_notify_event(sd, &adv7842_ev_fmt); 1986 1984 1987 1985 return 0; 1988 1986 } ··· 2214 2214 "%s: fmt_change_cp = 0x%x, fmt_change_digital = 0x%x, fmt_change_sdp = 0x%x\n", 2215 2215 __func__, fmt_change_cp, fmt_change_digital, 2216 2216 fmt_change_sdp); 2217 - v4l2_subdev_notify(sd, V4L2_DEVICE_NOTIFY_EVENT, 2218 - (void *)&adv7842_ev_fmt); 2217 + v4l2_subdev_notify_event(sd, &adv7842_ev_fmt); 2219 2218 if (handled) 2220 2219 *handled = true; 2221 2220 } ··· 3004 3005 return -ENOTTY; 3005 3006 } 3006 3007 3008 + static int adv7842_subscribe_event(struct v4l2_subdev *sd, 3009 + struct v4l2_fh *fh, 3010 + struct v4l2_event_subscription *sub) 3011 + { 3012 + switch (sub->type) { 3013 + case V4L2_EVENT_SOURCE_CHANGE: 3014 + return v4l2_src_change_event_subdev_subscribe(sd, fh, sub); 3015 + case V4L2_EVENT_CTRL: 3016 + return v4l2_ctrl_subdev_subscribe_event(sd, fh, sub); 3017 + default: 3018 + return -EINVAL; 3019 + } 3020 + } 3021 + 3007 3022 /* ----------------------------------------------------------------------- */ 3008 3023 3009 3024 static const struct v4l2_ctrl_ops adv7842_ctrl_ops = { ··· 3028 3015 .log_status = adv7842_log_status, 3029 3016 .ioctl = adv7842_ioctl, 3030 3017 .interrupt_service_routine = adv7842_isr, 3018 + .subscribe_event = adv7842_subscribe_event, 3019 + .unsubscribe_event = v4l2_event_subdev_unsubscribe, 3031 3020 #ifdef CONFIG_VIDEO_ADV_DEBUG 3032 3021 .g_register = adv7842_g_register, 3033 3022 .s_register = adv7842_s_register, ··· 3225 3210 3226 3211 sd = &state->sd; 3227 3212 v4l2_i2c_subdev_init(sd, client, &adv7842_ops); 3228 - sd->flags |= V4L2_SUBDEV_FL_HAS_DEVNODE; 3213 + sd->flags |= V4L2_SUBDEV_FL_HAS_DEVNODE | V4L2_SUBDEV_FL_HAS_EVENTS; 3229 3214 state->mode = pdata->mode; 3230 3215 3231 3216 state->hdmi_port_a = pdata->input == ADV7842_SELECT_HDMI_PORT_A; ··· 3363 3348 3364 3349 static struct i2c_driver adv7842_driver = { 3365 3350 .driver = { 3366 - .owner = THIS_MODULE, 3367 3351 .name = "adv7842", 3368 3352 }, 3369 3353 .probe = adv7842_probe,
+4 -4
drivers/media/i2c/ak881x.c
··· 156 156 } else if (std == V4L2_STD_PAL_60) { 157 157 vp1 = 7; 158 158 ak881x->lines = 480; 159 - } else if (std && !(std & ~V4L2_STD_PAL)) { 160 - vp1 = 0xf; 161 - ak881x->lines = 576; 162 - } else if (std && !(std & ~V4L2_STD_NTSC)) { 159 + } else if (std & V4L2_STD_NTSC) { 163 160 vp1 = 0; 164 161 ak881x->lines = 480; 162 + } else if (std & V4L2_STD_PAL) { 163 + vp1 = 0xf; 164 + ak881x->lines = 576; 165 165 } else { 166 166 /* No SECAM or PAL_N/Nc supported */ 167 167 return -EINVAL;
-12
drivers/media/i2c/bt819.c
··· 379 379 .s_ctrl = bt819_s_ctrl, 380 380 }; 381 381 382 - static const struct v4l2_subdev_core_ops bt819_core_ops = { 383 - .g_ext_ctrls = v4l2_subdev_g_ext_ctrls, 384 - .try_ext_ctrls = v4l2_subdev_try_ext_ctrls, 385 - .s_ext_ctrls = v4l2_subdev_s_ext_ctrls, 386 - .g_ctrl = v4l2_subdev_g_ctrl, 387 - .s_ctrl = v4l2_subdev_s_ctrl, 388 - .queryctrl = v4l2_subdev_queryctrl, 389 - .querymenu = v4l2_subdev_querymenu, 390 - }; 391 - 392 382 static const struct v4l2_subdev_video_ops bt819_video_ops = { 393 383 .s_std = bt819_s_std, 394 384 .s_routing = bt819_s_routing, ··· 388 398 }; 389 399 390 400 static const struct v4l2_subdev_ops bt819_ops = { 391 - .core = &bt819_core_ops, 392 401 .video = &bt819_video_ops, 393 402 }; 394 403 ··· 481 492 482 493 static struct i2c_driver bt819_driver = { 483 494 .driver = { 484 - .owner = THIS_MODULE, 485 495 .name = "bt819", 486 496 }, 487 497 .probe = bt819_probe,
-1
drivers/media/i2c/bt856.c
··· 252 252 253 253 static struct i2c_driver bt856_driver = { 254 254 .driver = { 255 - .owner = THIS_MODULE, 256 255 .name = "bt856", 257 256 }, 258 257 .probe = bt856_probe,
-1
drivers/media/i2c/bt866.c
··· 218 218 219 219 static struct i2c_driver bt866_driver = { 220 220 .driver = { 221 - .owner = THIS_MODULE, 222 221 .name = "bt866", 223 222 }, 224 223 .probe = bt866_probe,
-8
drivers/media/i2c/cs5345.c
··· 132 132 133 133 static const struct v4l2_subdev_core_ops cs5345_core_ops = { 134 134 .log_status = cs5345_log_status, 135 - .g_ext_ctrls = v4l2_subdev_g_ext_ctrls, 136 - .try_ext_ctrls = v4l2_subdev_try_ext_ctrls, 137 - .s_ext_ctrls = v4l2_subdev_s_ext_ctrls, 138 - .g_ctrl = v4l2_subdev_g_ctrl, 139 - .s_ctrl = v4l2_subdev_s_ctrl, 140 - .queryctrl = v4l2_subdev_queryctrl, 141 - .querymenu = v4l2_subdev_querymenu, 142 135 #ifdef CONFIG_VIDEO_ADV_DEBUG 143 136 .g_register = cs5345_g_register, 144 137 .s_register = cs5345_s_register, ··· 211 218 212 219 static struct i2c_driver cs5345_driver = { 213 220 .driver = { 214 - .owner = THIS_MODULE, 215 221 .name = "cs5345", 216 222 }, 217 223 .probe = cs5345_probe,
-1
drivers/media/i2c/cs53l32a.c
··· 228 228 229 229 static struct i2c_driver cs53l32a_driver = { 230 230 .driver = { 231 - .owner = THIS_MODULE, 232 231 .name = "cs53l32a", 233 232 }, 234 233 .probe = cs53l32a_probe,
-1
drivers/media/i2c/cx25840/cx25840-core.c
··· 5348 5348 5349 5349 static struct i2c_driver cx25840_driver = { 5350 5350 .driver = { 5351 - .owner = THIS_MODULE, 5352 5351 .name = "cx25840", 5353 5352 }, 5354 5353 .probe = cx25840_probe,
+1
drivers/media/i2c/ir-kbd-i2c.c
··· 478 478 { "ir_rx_z8f0811_hdpvr", 0 }, 479 479 { } 480 480 }; 481 + MODULE_DEVICE_TABLE(i2c, ir_kbd_id); 481 482 482 483 static struct i2c_driver ir_kbd_driver = { 483 484 .driver = {
-1
drivers/media/i2c/ks0127.c
··· 708 708 709 709 static struct i2c_driver ks0127_driver = { 710 710 .driver = { 711 - .owner = THIS_MODULE, 712 711 .name = "ks0127", 713 712 }, 714 713 .probe = ks0127_probe,
-1
drivers/media/i2c/m52790.c
··· 185 185 186 186 static struct i2c_driver m52790_driver = { 187 187 .driver = { 188 - .owner = THIS_MODULE, 189 188 .name = "m52790", 190 189 }, 191 190 .probe = m52790_probe,
-1
drivers/media/i2c/msp3400-driver.c
··· 894 894 895 895 static struct i2c_driver msp_driver = { 896 896 .driver = { 897 - .owner = THIS_MODULE, 898 897 .name = "msp3400", 899 898 .pm = &msp3400_pm_ops, 900 899 },
-1
drivers/media/i2c/mt9v011.c
··· 583 583 584 584 static struct i2c_driver mt9v011_driver = { 585 585 .driver = { 586 - .owner = THIS_MODULE, 587 586 .name = "mt9v011", 588 587 }, 589 588 .probe = mt9v011_probe,
+1 -1
drivers/media/i2c/mt9v032.c
··· 882 882 static struct mt9v032_platform_data * 883 883 mt9v032_get_pdata(struct i2c_client *client) 884 884 { 885 - struct mt9v032_platform_data *pdata; 885 + struct mt9v032_platform_data *pdata = NULL; 886 886 struct v4l2_of_endpoint endpoint; 887 887 struct device_node *np; 888 888 struct property *prop;
-4
drivers/media/i2c/ov2659.c
··· 909 909 u8 ctrl1_reg = 0, ctrl2_reg = 0, ctrl3_reg = 0; 910 910 struct i2c_client *client = ov2659->client; 911 911 unsigned int desired = pdata->link_frequency; 912 - u32 s_prediv = 1, s_postdiv = 1, s_mult = 1; 913 912 u32 prediv, postdiv, mult; 914 913 u32 bestdelta = -1; 915 914 u32 delta, actual; ··· 928 929 929 930 if ((delta < bestdelta) || (bestdelta == -1)) { 930 931 bestdelta = delta; 931 - s_mult = mult; 932 - s_prediv = prediv; 933 - s_postdiv = postdiv; 934 932 ctrl1_reg = ctrl1[i].reg; 935 933 ctrl2_reg = mult; 936 934 ctrl3_reg = ctrl3[j].reg;
-1
drivers/media/i2c/ov7640.c
··· 94 94 95 95 static struct i2c_driver ov7640_driver = { 96 96 .driver = { 97 - .owner = THIS_MODULE, 98 97 .name = "ov7640", 99 98 }, 100 99 .probe = ov7640_probe,
-1
drivers/media/i2c/ov7670.c
··· 1674 1674 1675 1675 static struct i2c_driver ov7670_driver = { 1676 1676 .driver = { 1677 - .owner = THIS_MODULE, 1678 1677 .name = "ov7670", 1679 1678 }, 1680 1679 .probe = ov7670_probe,
+1 -1
drivers/media/i2c/ov9650.c
··· 1436 1436 int ret; 1437 1437 1438 1438 mutex_lock(&ov965x->lock); 1439 - __ov965x_set_power(ov965x, 1); 1439 + __ov965x_set_power(ov965x, 1); 1440 1440 usleep_range(25000, 26000); 1441 1441 1442 1442 /* Check sensor revision */
-1
drivers/media/i2c/s5c73m3/s5c73m3-spi.c
··· 149 149 spidrv->remove = s5c73m3_spi_remove; 150 150 spidrv->probe = s5c73m3_spi_probe; 151 151 spidrv->driver.name = S5C73M3_SPI_DRV_NAME; 152 - spidrv->driver.bus = &spi_bus_type; 153 152 spidrv->driver.owner = THIS_MODULE; 154 153 spidrv->driver.of_match_table = s5c73m3_spi_ids; 155 154
+1
drivers/media/i2c/s5k6a3.c
··· 363 363 static const struct i2c_device_id s5k6a3_ids[] = { 364 364 { } 365 365 }; 366 + MODULE_DEVICE_TABLE(i2c, s5k6a3_ids); 366 367 367 368 #ifdef CONFIG_OF 368 369 static const struct of_device_id s5k6a3_of_match[] = {
+1 -4
drivers/media/i2c/saa6588.c
··· 301 301 first and the last of the 3 bytes block. 302 302 */ 303 303 304 - tmp = tmpbuf[2]; 305 - tmpbuf[2] = tmpbuf[0]; 306 - tmpbuf[0] = tmp; 304 + swap(tmpbuf[2], tmpbuf[0]); 307 305 308 306 /* Map 'Invalid block E' to 'Invalid Block' */ 309 307 if (blocknum == 6) ··· 518 520 519 521 static struct i2c_driver saa6588_driver = { 520 522 .driver = { 521 - .owner = THIS_MODULE, 522 523 .name = "saa6588", 523 524 }, 524 525 .probe = saa6588_probe,
-1
drivers/media/i2c/saa6752hs.c
··· 793 793 794 794 static struct i2c_driver saa6752hs_driver = { 795 795 .driver = { 796 - .owner = THIS_MODULE, 797 796 .name = "saa6752hs", 798 797 }, 799 798 .probe = saa6752hs_probe,
-12
drivers/media/i2c/saa7110.c
··· 357 357 .s_ctrl = saa7110_s_ctrl, 358 358 }; 359 359 360 - static const struct v4l2_subdev_core_ops saa7110_core_ops = { 361 - .g_ext_ctrls = v4l2_subdev_g_ext_ctrls, 362 - .try_ext_ctrls = v4l2_subdev_try_ext_ctrls, 363 - .s_ext_ctrls = v4l2_subdev_s_ext_ctrls, 364 - .g_ctrl = v4l2_subdev_g_ctrl, 365 - .s_ctrl = v4l2_subdev_s_ctrl, 366 - .queryctrl = v4l2_subdev_queryctrl, 367 - .querymenu = v4l2_subdev_querymenu, 368 - }; 369 - 370 360 static const struct v4l2_subdev_video_ops saa7110_video_ops = { 371 361 .s_std = saa7110_s_std, 372 362 .s_routing = saa7110_s_routing, ··· 366 376 }; 367 377 368 378 static const struct v4l2_subdev_ops saa7110_ops = { 369 - .core = &saa7110_core_ops, 370 379 .video = &saa7110_video_ops, 371 380 }; 372 381 ··· 461 472 462 473 static struct i2c_driver saa7110_driver = { 463 474 .driver = { 464 - .owner = THIS_MODULE, 465 475 .name = "saa7110", 466 476 }, 467 477 .probe = saa7110_probe,
-1
drivers/media/i2c/saa7115.c
··· 1929 1929 1930 1930 static struct i2c_driver saa711x_driver = { 1931 1931 .driver = { 1932 - .owner = THIS_MODULE, 1933 1932 .name = "saa7115", 1934 1933 }, 1935 1934 .probe = saa711x_probe,
-1
drivers/media/i2c/saa7127.c
··· 822 822 823 823 static struct i2c_driver saa7127_driver = { 824 824 .driver = { 825 - .owner = THIS_MODULE, 826 825 .name = "saa7127", 827 826 }, 828 827 .probe = saa7127_probe,
-8
drivers/media/i2c/saa717x.c
··· 1204 1204 .g_register = saa717x_g_register, 1205 1205 .s_register = saa717x_s_register, 1206 1206 #endif 1207 - .g_ext_ctrls = v4l2_subdev_g_ext_ctrls, 1208 - .try_ext_ctrls = v4l2_subdev_try_ext_ctrls, 1209 - .s_ext_ctrls = v4l2_subdev_s_ext_ctrls, 1210 - .g_ctrl = v4l2_subdev_g_ctrl, 1211 - .s_ctrl = v4l2_subdev_s_ctrl, 1212 - .queryctrl = v4l2_subdev_queryctrl, 1213 - .querymenu = v4l2_subdev_querymenu, 1214 1207 .log_status = saa717x_log_status, 1215 1208 }; 1216 1209 ··· 1356 1363 1357 1364 static struct i2c_driver saa717x_driver = { 1358 1365 .driver = { 1359 - .owner = THIS_MODULE, 1360 1366 .name = "saa717x", 1361 1367 }, 1362 1368 .probe = saa717x_probe,
-1
drivers/media/i2c/saa7185.c
··· 356 356 357 357 static struct i2c_driver saa7185_driver = { 358 358 .driver = { 359 - .owner = THIS_MODULE, 360 359 .name = "saa7185", 361 360 }, 362 361 .probe = saa7185_probe,
+4 -4
drivers/media/i2c/soc_camera/mt9t112.c
··· 104 104 static const struct mt9t112_format mt9t112_cfmts[] = { 105 105 { 106 106 .code = MEDIA_BUS_FMT_UYVY8_2X8, 107 - .colorspace = V4L2_COLORSPACE_JPEG, 107 + .colorspace = V4L2_COLORSPACE_SRGB, 108 108 .fmt = 1, 109 109 .order = 0, 110 110 }, { 111 111 .code = MEDIA_BUS_FMT_VYUY8_2X8, 112 - .colorspace = V4L2_COLORSPACE_JPEG, 112 + .colorspace = V4L2_COLORSPACE_SRGB, 113 113 .fmt = 1, 114 114 .order = 1, 115 115 }, { 116 116 .code = MEDIA_BUS_FMT_YUYV8_2X8, 117 - .colorspace = V4L2_COLORSPACE_JPEG, 117 + .colorspace = V4L2_COLORSPACE_SRGB, 118 118 .fmt = 1, 119 119 .order = 2, 120 120 }, { 121 121 .code = MEDIA_BUS_FMT_YVYU8_2X8, 122 - .colorspace = V4L2_COLORSPACE_JPEG, 122 + .colorspace = V4L2_COLORSPACE_SRGB, 123 123 .fmt = 1, 124 124 .order = 3, 125 125 }, {
+31 -4
drivers/media/i2c/soc_camera/tw9910.c
··· 510 510 { 511 511 struct i2c_client *client = v4l2_get_subdevdata(sd); 512 512 struct tw9910_priv *priv = to_tw9910(client); 513 + const unsigned hact = 720; 514 + const unsigned hdelay = 15; 515 + unsigned vact; 516 + unsigned vdelay; 517 + int ret; 513 518 514 519 if (!(norm & (V4L2_STD_NTSC | V4L2_STD_PAL))) 515 520 return -EINVAL; 516 521 517 522 priv->norm = norm; 523 + if (norm & V4L2_STD_525_60) { 524 + vact = 240; 525 + vdelay = 18; 526 + ret = tw9910_mask_set(client, VVBI, 0x10, 0x10); 527 + } else { 528 + vact = 288; 529 + vdelay = 24; 530 + ret = tw9910_mask_set(client, VVBI, 0x10, 0x00); 531 + } 532 + if (!ret) 533 + ret = i2c_smbus_write_byte_data(client, CROP_HI, 534 + ((vdelay >> 2) & 0xc0) | 535 + ((vact >> 4) & 0x30) | 536 + ((hdelay >> 6) & 0x0c) | 537 + ((hact >> 8) & 0x03)); 538 + if (!ret) 539 + ret = i2c_smbus_write_byte_data(client, VDELAY_LO, 540 + vdelay & 0xff); 541 + if (!ret) 542 + ret = i2c_smbus_write_byte_data(client, VACTIVE_LO, 543 + vact & 0xff); 518 544 519 - return 0; 545 + return ret; 520 546 } 521 547 522 548 #ifdef CONFIG_VIDEO_ADV_DEBUG ··· 737 711 mf->width = priv->scale->width; 738 712 mf->height = priv->scale->height; 739 713 mf->code = MEDIA_BUS_FMT_UYVY8_2X8; 740 - mf->colorspace = V4L2_COLORSPACE_JPEG; 714 + mf->colorspace = V4L2_COLORSPACE_SMPTE170M; 741 715 mf->field = V4L2_FIELD_INTERLACED_BT; 742 716 743 717 return 0; ··· 758 732 if (mf->code != MEDIA_BUS_FMT_UYVY8_2X8) 759 733 return -EINVAL; 760 734 761 - mf->colorspace = V4L2_COLORSPACE_JPEG; 735 + mf->colorspace = V4L2_COLORSPACE_SMPTE170M; 762 736 763 737 ret = tw9910_set_frame(sd, &width, &height); 764 738 if (!ret) { ··· 788 762 } 789 763 790 764 mf->code = MEDIA_BUS_FMT_UYVY8_2X8; 791 - mf->colorspace = V4L2_COLORSPACE_JPEG; 765 + mf->colorspace = V4L2_COLORSPACE_SMPTE170M; 792 766 793 767 /* 794 768 * select suitable norm ··· 846 820 "tw9910 Product ID %0x:%0x\n", id, priv->revision); 847 821 848 822 priv->norm = V4L2_STD_NTSC; 823 + priv->scale = &tw9910_ntsc_scales[0]; 849 824 850 825 done: 851 826 tw9910_s_power(&priv->subdev, 0);
-1
drivers/media/i2c/sony-btf-mpx.c
··· 388 388 389 389 static struct i2c_driver sony_btf_mpx_driver = { 390 390 .driver = { 391 - .owner = THIS_MODULE, 392 391 .name = "sony-btf-mpx", 393 392 }, 394 393 .probe = sony_btf_mpx_probe,
+2 -13
drivers/media/i2c/sr030pc30.c
··· 489 489 { 490 490 struct v4l2_mbus_framefmt *mf; 491 491 struct sr030pc30_info *info = to_sr030pc30(sd); 492 - int ret; 493 492 494 493 if (!format || format->pad) 495 494 return -EINVAL; 496 495 497 496 mf = &format->format; 498 497 499 - if (!info->curr_win || !info->curr_fmt) { 500 - ret = sr030pc30_set_params(sd); 501 - if (ret) 502 - return ret; 503 - } 498 + if (!info->curr_win || !info->curr_fmt) 499 + return -EINVAL; 504 500 505 501 mf->width = info->curr_win->width; 506 502 mf->height = info->curr_win->height; ··· 632 636 633 637 static const struct v4l2_subdev_core_ops sr030pc30_core_ops = { 634 638 .s_power = sr030pc30_s_power, 635 - .g_ext_ctrls = v4l2_subdev_g_ext_ctrls, 636 - .try_ext_ctrls = v4l2_subdev_try_ext_ctrls, 637 - .s_ext_ctrls = v4l2_subdev_s_ext_ctrls, 638 - .g_ctrl = v4l2_subdev_g_ctrl, 639 - .s_ctrl = v4l2_subdev_s_ctrl, 640 - .queryctrl = v4l2_subdev_queryctrl, 641 - .querymenu = v4l2_subdev_querymenu, 642 639 }; 643 640 644 641 static const struct v4l2_subdev_pad_ops sr030pc30_pad_ops = {
+1979
drivers/media/i2c/tc358743.c
··· 1 + /* 2 + * tc358743 - Toshiba HDMI to CSI-2 bridge 3 + * 4 + * Copyright 2015 Cisco Systems, Inc. and/or its affiliates. All rights 5 + * reserved. 6 + * 7 + * This program is free software; you may redistribute it and/or modify 8 + * it under the terms of the GNU General Public License as published by 9 + * the Free Software Foundation; version 2 of the License. 10 + * 11 + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 12 + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 13 + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 14 + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 15 + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 16 + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 17 + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 18 + * SOFTWARE. 19 + * 20 + */ 21 + 22 + /* 23 + * References (c = chapter, p = page): 24 + * REF_01 - Toshiba, TC358743XBG (H2C), Functional Specification, Rev 0.60 25 + * REF_02 - Toshiba, TC358743XBG_HDMI-CSI_Tv11p_nm.xls 26 + */ 27 + 28 + #include <linux/kernel.h> 29 + #include <linux/module.h> 30 + #include <linux/slab.h> 31 + #include <linux/i2c.h> 32 + #include <linux/clk.h> 33 + #include <linux/delay.h> 34 + #include <linux/gpio/consumer.h> 35 + #include <linux/interrupt.h> 36 + #include <linux/videodev2.h> 37 + #include <linux/workqueue.h> 38 + #include <linux/v4l2-dv-timings.h> 39 + #include <linux/hdmi.h> 40 + #include <media/v4l2-dv-timings.h> 41 + #include <media/v4l2-device.h> 42 + #include <media/v4l2-ctrls.h> 43 + #include <media/v4l2-event.h> 44 + #include <media/v4l2-of.h> 45 + #include <media/tc358743.h> 46 + 47 + #include "tc358743_regs.h" 48 + 49 + static int debug; 50 + module_param(debug, int, 0644); 51 + MODULE_PARM_DESC(debug, "debug level (0-3)"); 52 + 53 + MODULE_DESCRIPTION("Toshiba TC358743 HDMI to CSI-2 bridge driver"); 54 + MODULE_AUTHOR("Ramakrishnan Muthukrishnan <ram@rkrishnan.org>"); 55 + MODULE_AUTHOR("Mikhail Khelik <mkhelik@cisco.com>"); 56 + MODULE_AUTHOR("Mats Randgaard <matrandg@cisco.com>"); 57 + MODULE_LICENSE("GPL"); 58 + 59 + #define EDID_NUM_BLOCKS_MAX 8 60 + #define EDID_BLOCK_SIZE 128 61 + 62 + /* Max transfer size done by I2C transfer functions */ 63 + #define MAX_XFER_SIZE (EDID_NUM_BLOCKS_MAX * EDID_BLOCK_SIZE + 2) 64 + 65 + static const struct v4l2_dv_timings_cap tc358743_timings_cap = { 66 + .type = V4L2_DV_BT_656_1120, 67 + /* keep this initialization for compatibility with GCC < 4.4.6 */ 68 + .reserved = { 0 }, 69 + /* Pixel clock from REF_01 p. 20. Min/max height/width are unknown */ 70 + V4L2_INIT_BT_TIMINGS(1, 10000, 1, 10000, 0, 165000000, 71 + V4L2_DV_BT_STD_CEA861 | V4L2_DV_BT_STD_DMT | 72 + V4L2_DV_BT_STD_GTF | V4L2_DV_BT_STD_CVT, 73 + V4L2_DV_BT_CAP_PROGRESSIVE | 74 + V4L2_DV_BT_CAP_REDUCED_BLANKING | 75 + V4L2_DV_BT_CAP_CUSTOM) 76 + }; 77 + 78 + struct tc358743_state { 79 + struct tc358743_platform_data pdata; 80 + struct v4l2_of_bus_mipi_csi2 bus; 81 + struct v4l2_subdev sd; 82 + struct media_pad pad; 83 + struct v4l2_ctrl_handler hdl; 84 + struct i2c_client *i2c_client; 85 + /* CONFCTL is modified in ops and tc358743_hdmi_sys_int_handler */ 86 + struct mutex confctl_mutex; 87 + 88 + /* controls */ 89 + struct v4l2_ctrl *detect_tx_5v_ctrl; 90 + struct v4l2_ctrl *audio_sampling_rate_ctrl; 91 + struct v4l2_ctrl *audio_present_ctrl; 92 + 93 + /* work queues */ 94 + struct workqueue_struct *work_queues; 95 + struct delayed_work delayed_work_enable_hotplug; 96 + 97 + /* edid */ 98 + u8 edid_blocks_written; 99 + 100 + /* used by i2c_wr() */ 101 + u8 wr_data[MAX_XFER_SIZE]; 102 + 103 + struct v4l2_dv_timings timings; 104 + u32 mbus_fmt_code; 105 + 106 + struct gpio_desc *reset_gpio; 107 + }; 108 + 109 + static void tc358743_enable_interrupts(struct v4l2_subdev *sd, 110 + bool cable_connected); 111 + static int tc358743_s_ctrl_detect_tx_5v(struct v4l2_subdev *sd); 112 + 113 + static inline struct tc358743_state *to_state(struct v4l2_subdev *sd) 114 + { 115 + return container_of(sd, struct tc358743_state, sd); 116 + } 117 + 118 + /* --------------- I2C --------------- */ 119 + 120 + static void i2c_rd(struct v4l2_subdev *sd, u16 reg, u8 *values, u32 n) 121 + { 122 + struct tc358743_state *state = to_state(sd); 123 + struct i2c_client *client = state->i2c_client; 124 + int err; 125 + u8 buf[2] = { reg >> 8, reg & 0xff }; 126 + struct i2c_msg msgs[] = { 127 + { 128 + .addr = client->addr, 129 + .flags = 0, 130 + .len = 2, 131 + .buf = buf, 132 + }, 133 + { 134 + .addr = client->addr, 135 + .flags = I2C_M_RD, 136 + .len = n, 137 + .buf = values, 138 + }, 139 + }; 140 + 141 + err = i2c_transfer(client->adapter, msgs, ARRAY_SIZE(msgs)); 142 + if (err != ARRAY_SIZE(msgs)) { 143 + v4l2_err(sd, "%s: reading register 0x%x from 0x%x failed\n", 144 + __func__, reg, client->addr); 145 + } 146 + } 147 + 148 + static void i2c_wr(struct v4l2_subdev *sd, u16 reg, u8 *values, u32 n) 149 + { 150 + struct tc358743_state *state = to_state(sd); 151 + struct i2c_client *client = state->i2c_client; 152 + u8 *data = state->wr_data; 153 + int err, i; 154 + struct i2c_msg msg; 155 + 156 + if ((2 + n) > sizeof(state->wr_data)) 157 + v4l2_warn(sd, "i2c wr reg=%04x: len=%d is too big!\n", 158 + reg, 2 + n); 159 + 160 + msg.addr = client->addr; 161 + msg.buf = data; 162 + msg.len = 2 + n; 163 + msg.flags = 0; 164 + 165 + data[0] = reg >> 8; 166 + data[1] = reg & 0xff; 167 + 168 + for (i = 0; i < n; i++) 169 + data[2 + i] = values[i]; 170 + 171 + err = i2c_transfer(client->adapter, &msg, 1); 172 + if (err != 1) { 173 + v4l2_err(sd, "%s: writing register 0x%x from 0x%x failed\n", 174 + __func__, reg, client->addr); 175 + return; 176 + } 177 + 178 + if (debug < 3) 179 + return; 180 + 181 + switch (n) { 182 + case 1: 183 + v4l2_info(sd, "I2C write 0x%04x = 0x%02x", 184 + reg, data[2]); 185 + break; 186 + case 2: 187 + v4l2_info(sd, "I2C write 0x%04x = 0x%02x%02x", 188 + reg, data[3], data[2]); 189 + break; 190 + case 4: 191 + v4l2_info(sd, "I2C write 0x%04x = 0x%02x%02x%02x%02x", 192 + reg, data[5], data[4], data[3], data[2]); 193 + break; 194 + default: 195 + v4l2_info(sd, "I2C write %d bytes from address 0x%04x\n", 196 + n, reg); 197 + } 198 + } 199 + 200 + static u8 i2c_rd8(struct v4l2_subdev *sd, u16 reg) 201 + { 202 + u8 val; 203 + 204 + i2c_rd(sd, reg, &val, 1); 205 + 206 + return val; 207 + } 208 + 209 + static void i2c_wr8(struct v4l2_subdev *sd, u16 reg, u8 val) 210 + { 211 + i2c_wr(sd, reg, &val, 1); 212 + } 213 + 214 + static void i2c_wr8_and_or(struct v4l2_subdev *sd, u16 reg, 215 + u8 mask, u8 val) 216 + { 217 + i2c_wr8(sd, reg, (i2c_rd8(sd, reg) & mask) | val); 218 + } 219 + 220 + static u16 i2c_rd16(struct v4l2_subdev *sd, u16 reg) 221 + { 222 + u16 val; 223 + 224 + i2c_rd(sd, reg, (u8 *)&val, 2); 225 + 226 + return val; 227 + } 228 + 229 + static void i2c_wr16(struct v4l2_subdev *sd, u16 reg, u16 val) 230 + { 231 + i2c_wr(sd, reg, (u8 *)&val, 2); 232 + } 233 + 234 + static void i2c_wr16_and_or(struct v4l2_subdev *sd, u16 reg, u16 mask, u16 val) 235 + { 236 + i2c_wr16(sd, reg, (i2c_rd16(sd, reg) & mask) | val); 237 + } 238 + 239 + static u32 i2c_rd32(struct v4l2_subdev *sd, u16 reg) 240 + { 241 + u32 val; 242 + 243 + i2c_rd(sd, reg, (u8 *)&val, 4); 244 + 245 + return val; 246 + } 247 + 248 + static void i2c_wr32(struct v4l2_subdev *sd, u16 reg, u32 val) 249 + { 250 + i2c_wr(sd, reg, (u8 *)&val, 4); 251 + } 252 + 253 + /* --------------- STATUS --------------- */ 254 + 255 + static inline bool is_hdmi(struct v4l2_subdev *sd) 256 + { 257 + return i2c_rd8(sd, SYS_STATUS) & MASK_S_HDMI; 258 + } 259 + 260 + static inline bool tx_5v_power_present(struct v4l2_subdev *sd) 261 + { 262 + return i2c_rd8(sd, SYS_STATUS) & MASK_S_DDC5V; 263 + } 264 + 265 + static inline bool no_signal(struct v4l2_subdev *sd) 266 + { 267 + return !(i2c_rd8(sd, SYS_STATUS) & MASK_S_TMDS); 268 + } 269 + 270 + static inline bool no_sync(struct v4l2_subdev *sd) 271 + { 272 + return !(i2c_rd8(sd, SYS_STATUS) & MASK_S_SYNC); 273 + } 274 + 275 + static inline bool audio_present(struct v4l2_subdev *sd) 276 + { 277 + return i2c_rd8(sd, AU_STATUS0) & MASK_S_A_SAMPLE; 278 + } 279 + 280 + static int get_audio_sampling_rate(struct v4l2_subdev *sd) 281 + { 282 + static const int code_to_rate[] = { 283 + 44100, 0, 48000, 32000, 22050, 384000, 24000, 352800, 284 + 88200, 768000, 96000, 705600, 176400, 0, 192000, 0 285 + }; 286 + 287 + /* Register FS_SET is not cleared when the cable is disconnected */ 288 + if (no_signal(sd)) 289 + return 0; 290 + 291 + return code_to_rate[i2c_rd8(sd, FS_SET) & MASK_FS]; 292 + } 293 + 294 + static unsigned tc358743_num_csi_lanes_in_use(struct v4l2_subdev *sd) 295 + { 296 + return ((i2c_rd32(sd, CSI_CONTROL) & MASK_NOL) >> 1) + 1; 297 + } 298 + 299 + /* --------------- TIMINGS --------------- */ 300 + 301 + static inline unsigned fps(const struct v4l2_bt_timings *t) 302 + { 303 + if (!V4L2_DV_BT_FRAME_HEIGHT(t) || !V4L2_DV_BT_FRAME_WIDTH(t)) 304 + return 0; 305 + 306 + return DIV_ROUND_CLOSEST((unsigned)t->pixelclock, 307 + V4L2_DV_BT_FRAME_HEIGHT(t) * V4L2_DV_BT_FRAME_WIDTH(t)); 308 + } 309 + 310 + static int tc358743_get_detected_timings(struct v4l2_subdev *sd, 311 + struct v4l2_dv_timings *timings) 312 + { 313 + struct v4l2_bt_timings *bt = &timings->bt; 314 + unsigned width, height, frame_width, frame_height, frame_interval, fps; 315 + 316 + memset(timings, 0, sizeof(struct v4l2_dv_timings)); 317 + 318 + if (no_signal(sd)) { 319 + v4l2_dbg(1, debug, sd, "%s: no valid signal\n", __func__); 320 + return -ENOLINK; 321 + } 322 + if (no_sync(sd)) { 323 + v4l2_dbg(1, debug, sd, "%s: no sync on signal\n", __func__); 324 + return -ENOLCK; 325 + } 326 + 327 + timings->type = V4L2_DV_BT_656_1120; 328 + bt->interlaced = i2c_rd8(sd, VI_STATUS1) & MASK_S_V_INTERLACE ? 329 + V4L2_DV_INTERLACED : V4L2_DV_PROGRESSIVE; 330 + 331 + width = ((i2c_rd8(sd, DE_WIDTH_H_HI) & 0x1f) << 8) + 332 + i2c_rd8(sd, DE_WIDTH_H_LO); 333 + height = ((i2c_rd8(sd, DE_WIDTH_V_HI) & 0x1f) << 8) + 334 + i2c_rd8(sd, DE_WIDTH_V_LO); 335 + frame_width = ((i2c_rd8(sd, H_SIZE_HI) & 0x1f) << 8) + 336 + i2c_rd8(sd, H_SIZE_LO); 337 + frame_height = (((i2c_rd8(sd, V_SIZE_HI) & 0x3f) << 8) + 338 + i2c_rd8(sd, V_SIZE_LO)) / 2; 339 + /* frame interval in milliseconds * 10 340 + * Require SYS_FREQ0 and SYS_FREQ1 are precisely set */ 341 + frame_interval = ((i2c_rd8(sd, FV_CNT_HI) & 0x3) << 8) + 342 + i2c_rd8(sd, FV_CNT_LO); 343 + fps = (frame_interval > 0) ? 344 + DIV_ROUND_CLOSEST(10000, frame_interval) : 0; 345 + 346 + bt->width = width; 347 + bt->height = height; 348 + bt->vsync = frame_height - height; 349 + bt->hsync = frame_width - width; 350 + bt->pixelclock = frame_width * frame_height * fps; 351 + if (bt->interlaced == V4L2_DV_INTERLACED) { 352 + bt->height *= 2; 353 + bt->il_vsync = bt->vsync + 1; 354 + bt->pixelclock /= 2; 355 + } 356 + 357 + return 0; 358 + } 359 + 360 + /* --------------- HOTPLUG / HDCP / EDID --------------- */ 361 + 362 + static void tc358743_delayed_work_enable_hotplug(struct work_struct *work) 363 + { 364 + struct delayed_work *dwork = to_delayed_work(work); 365 + struct tc358743_state *state = container_of(dwork, 366 + struct tc358743_state, delayed_work_enable_hotplug); 367 + struct v4l2_subdev *sd = &state->sd; 368 + 369 + v4l2_dbg(2, debug, sd, "%s:\n", __func__); 370 + 371 + i2c_wr8_and_or(sd, HPD_CTL, ~MASK_HPD_OUT0, MASK_HPD_OUT0); 372 + } 373 + 374 + static void tc358743_set_hdmi_hdcp(struct v4l2_subdev *sd, bool enable) 375 + { 376 + v4l2_dbg(2, debug, sd, "%s: %s\n", __func__, enable ? 377 + "enable" : "disable"); 378 + 379 + i2c_wr8_and_or(sd, HDCP_REG1, 380 + ~(MASK_AUTH_UNAUTH_SEL | MASK_AUTH_UNAUTH), 381 + MASK_AUTH_UNAUTH_SEL_16_FRAMES | MASK_AUTH_UNAUTH_AUTO); 382 + 383 + i2c_wr8_and_or(sd, HDCP_REG2, ~MASK_AUTO_P3_RESET, 384 + SET_AUTO_P3_RESET_FRAMES(0x0f)); 385 + 386 + /* HDCP is disabled by configuring the receiver as HDCP repeater. The 387 + * repeater mode require software support to work, so HDCP 388 + * authentication will fail. 389 + */ 390 + i2c_wr8_and_or(sd, HDCP_REG3, ~KEY_RD_CMD, enable ? KEY_RD_CMD : 0); 391 + i2c_wr8_and_or(sd, HDCP_MODE, ~(MASK_AUTO_CLR | MASK_MODE_RST_TN), 392 + enable ? (MASK_AUTO_CLR | MASK_MODE_RST_TN) : 0); 393 + 394 + /* Apple MacBook Pro gen.8 has a bug that makes it freeze every fifth 395 + * second when HDCP is disabled, but the MAX_EXCED bit is handled 396 + * correctly and HDCP is disabled on the HDMI output. 397 + */ 398 + i2c_wr8_and_or(sd, BSTATUS1, ~MASK_MAX_EXCED, 399 + enable ? 0 : MASK_MAX_EXCED); 400 + i2c_wr8_and_or(sd, BCAPS, ~(MASK_REPEATER | MASK_READY), 401 + enable ? 0 : MASK_REPEATER | MASK_READY); 402 + } 403 + 404 + static void tc358743_disable_edid(struct v4l2_subdev *sd) 405 + { 406 + struct tc358743_state *state = to_state(sd); 407 + 408 + v4l2_dbg(2, debug, sd, "%s:\n", __func__); 409 + 410 + cancel_delayed_work_sync(&state->delayed_work_enable_hotplug); 411 + 412 + /* DDC access to EDID is also disabled when hotplug is disabled. See 413 + * register DDC_CTL */ 414 + i2c_wr8_and_or(sd, HPD_CTL, ~MASK_HPD_OUT0, 0x0); 415 + } 416 + 417 + static void tc358743_enable_edid(struct v4l2_subdev *sd) 418 + { 419 + struct tc358743_state *state = to_state(sd); 420 + 421 + if (state->edid_blocks_written == 0) { 422 + v4l2_dbg(2, debug, sd, "%s: no EDID -> no hotplug\n", __func__); 423 + return; 424 + } 425 + 426 + v4l2_dbg(2, debug, sd, "%s:\n", __func__); 427 + 428 + /* Enable hotplug after 100 ms. DDC access to EDID is also enabled when 429 + * hotplug is enabled. See register DDC_CTL */ 430 + queue_delayed_work(state->work_queues, 431 + &state->delayed_work_enable_hotplug, HZ / 10); 432 + 433 + tc358743_enable_interrupts(sd, true); 434 + tc358743_s_ctrl_detect_tx_5v(sd); 435 + } 436 + 437 + static void tc358743_erase_bksv(struct v4l2_subdev *sd) 438 + { 439 + int i; 440 + 441 + for (i = 0; i < 5; i++) 442 + i2c_wr8(sd, BKSV + i, 0); 443 + } 444 + 445 + /* --------------- AVI infoframe --------------- */ 446 + 447 + static void print_avi_infoframe(struct v4l2_subdev *sd) 448 + { 449 + struct i2c_client *client = v4l2_get_subdevdata(sd); 450 + struct device *dev = &client->dev; 451 + union hdmi_infoframe frame; 452 + u8 buffer[HDMI_INFOFRAME_SIZE(AVI)]; 453 + 454 + if (!is_hdmi(sd)) { 455 + v4l2_info(sd, "DVI-D signal - AVI infoframe not supported\n"); 456 + return; 457 + } 458 + 459 + i2c_rd(sd, PK_AVI_0HEAD, buffer, HDMI_INFOFRAME_SIZE(AVI)); 460 + 461 + if (hdmi_infoframe_unpack(&frame, buffer) < 0) { 462 + v4l2_err(sd, "%s: unpack of AVI infoframe failed\n", __func__); 463 + return; 464 + } 465 + 466 + hdmi_infoframe_log(KERN_INFO, dev, &frame); 467 + } 468 + 469 + /* --------------- CTRLS --------------- */ 470 + 471 + static int tc358743_s_ctrl_detect_tx_5v(struct v4l2_subdev *sd) 472 + { 473 + struct tc358743_state *state = to_state(sd); 474 + 475 + return v4l2_ctrl_s_ctrl(state->detect_tx_5v_ctrl, 476 + tx_5v_power_present(sd)); 477 + } 478 + 479 + static int tc358743_s_ctrl_audio_sampling_rate(struct v4l2_subdev *sd) 480 + { 481 + struct tc358743_state *state = to_state(sd); 482 + 483 + return v4l2_ctrl_s_ctrl(state->audio_sampling_rate_ctrl, 484 + get_audio_sampling_rate(sd)); 485 + } 486 + 487 + static int tc358743_s_ctrl_audio_present(struct v4l2_subdev *sd) 488 + { 489 + struct tc358743_state *state = to_state(sd); 490 + 491 + return v4l2_ctrl_s_ctrl(state->audio_present_ctrl, 492 + audio_present(sd)); 493 + } 494 + 495 + static int tc358743_update_controls(struct v4l2_subdev *sd) 496 + { 497 + int ret = 0; 498 + 499 + ret |= tc358743_s_ctrl_detect_tx_5v(sd); 500 + ret |= tc358743_s_ctrl_audio_sampling_rate(sd); 501 + ret |= tc358743_s_ctrl_audio_present(sd); 502 + 503 + return ret; 504 + } 505 + 506 + /* --------------- INIT --------------- */ 507 + 508 + static void tc358743_reset_phy(struct v4l2_subdev *sd) 509 + { 510 + v4l2_dbg(1, debug, sd, "%s:\n", __func__); 511 + 512 + i2c_wr8_and_or(sd, PHY_RST, ~MASK_RESET_CTRL, 0); 513 + i2c_wr8_and_or(sd, PHY_RST, ~MASK_RESET_CTRL, MASK_RESET_CTRL); 514 + } 515 + 516 + static void tc358743_reset(struct v4l2_subdev *sd, uint16_t mask) 517 + { 518 + u16 sysctl = i2c_rd16(sd, SYSCTL); 519 + 520 + i2c_wr16(sd, SYSCTL, sysctl | mask); 521 + i2c_wr16(sd, SYSCTL, sysctl & ~mask); 522 + } 523 + 524 + static inline void tc358743_sleep_mode(struct v4l2_subdev *sd, bool enable) 525 + { 526 + i2c_wr16_and_or(sd, SYSCTL, ~MASK_SLEEP, 527 + enable ? MASK_SLEEP : 0); 528 + } 529 + 530 + static inline void enable_stream(struct v4l2_subdev *sd, bool enable) 531 + { 532 + struct tc358743_state *state = to_state(sd); 533 + 534 + v4l2_dbg(3, debug, sd, "%s: %sable\n", 535 + __func__, enable ? "en" : "dis"); 536 + 537 + if (enable) { 538 + /* It is critical for CSI receiver to see lane transition 539 + * LP11->HS. Set to non-continuous mode to enable clock lane 540 + * LP11 state. */ 541 + i2c_wr32(sd, TXOPTIONCNTRL, 0); 542 + /* Set to continuous mode to trigger LP11->HS transition */ 543 + i2c_wr32(sd, TXOPTIONCNTRL, MASK_CONTCLKMODE); 544 + /* Unmute video */ 545 + i2c_wr8(sd, VI_MUTE, MASK_AUTO_MUTE); 546 + } else { 547 + /* Mute video so that all data lanes go to LSP11 state. 548 + * No data is output to CSI Tx block. */ 549 + i2c_wr8(sd, VI_MUTE, MASK_AUTO_MUTE | MASK_VI_MUTE); 550 + } 551 + 552 + mutex_lock(&state->confctl_mutex); 553 + i2c_wr16_and_or(sd, CONFCTL, ~(MASK_VBUFEN | MASK_ABUFEN), 554 + enable ? (MASK_VBUFEN | MASK_ABUFEN) : 0x0); 555 + mutex_unlock(&state->confctl_mutex); 556 + } 557 + 558 + static void tc358743_set_pll(struct v4l2_subdev *sd) 559 + { 560 + struct tc358743_state *state = to_state(sd); 561 + struct tc358743_platform_data *pdata = &state->pdata; 562 + u16 pllctl0 = i2c_rd16(sd, PLLCTL0); 563 + u16 pllctl1 = i2c_rd16(sd, PLLCTL1); 564 + u16 pllctl0_new = SET_PLL_PRD(pdata->pll_prd) | 565 + SET_PLL_FBD(pdata->pll_fbd); 566 + u32 hsck = (pdata->refclk_hz / pdata->pll_prd) * pdata->pll_fbd; 567 + 568 + v4l2_dbg(2, debug, sd, "%s:\n", __func__); 569 + 570 + /* Only rewrite when needed (new value or disabled), since rewriting 571 + * triggers another format change event. */ 572 + if ((pllctl0 != pllctl0_new) || ((pllctl1 & MASK_PLL_EN) == 0)) { 573 + u16 pll_frs; 574 + 575 + if (hsck > 500000000) 576 + pll_frs = 0x0; 577 + else if (hsck > 250000000) 578 + pll_frs = 0x1; 579 + else if (hsck > 125000000) 580 + pll_frs = 0x2; 581 + else 582 + pll_frs = 0x3; 583 + 584 + v4l2_dbg(1, debug, sd, "%s: updating PLL clock\n", __func__); 585 + tc358743_sleep_mode(sd, true); 586 + i2c_wr16(sd, PLLCTL0, pllctl0_new); 587 + i2c_wr16_and_or(sd, PLLCTL1, 588 + ~(MASK_PLL_FRS | MASK_RESETB | MASK_PLL_EN), 589 + (SET_PLL_FRS(pll_frs) | MASK_RESETB | 590 + MASK_PLL_EN)); 591 + udelay(10); /* REF_02, Sheet "Source HDMI" */ 592 + i2c_wr16_and_or(sd, PLLCTL1, ~MASK_CKEN, MASK_CKEN); 593 + tc358743_sleep_mode(sd, false); 594 + } 595 + } 596 + 597 + static void tc358743_set_ref_clk(struct v4l2_subdev *sd) 598 + { 599 + struct tc358743_state *state = to_state(sd); 600 + struct tc358743_platform_data *pdata = &state->pdata; 601 + u32 sys_freq; 602 + u32 lockdet_ref; 603 + u16 fh_min; 604 + u16 fh_max; 605 + 606 + BUG_ON(!(pdata->refclk_hz == 26000000 || 607 + pdata->refclk_hz == 27000000 || 608 + pdata->refclk_hz == 42000000)); 609 + 610 + sys_freq = pdata->refclk_hz / 10000; 611 + i2c_wr8(sd, SYS_FREQ0, sys_freq & 0x00ff); 612 + i2c_wr8(sd, SYS_FREQ1, (sys_freq & 0xff00) >> 8); 613 + 614 + i2c_wr8_and_or(sd, PHY_CTL0, ~MASK_PHY_SYSCLK_IND, 615 + (pdata->refclk_hz == 42000000) ? 616 + MASK_PHY_SYSCLK_IND : 0x0); 617 + 618 + fh_min = pdata->refclk_hz / 100000; 619 + i2c_wr8(sd, FH_MIN0, fh_min & 0x00ff); 620 + i2c_wr8(sd, FH_MIN1, (fh_min & 0xff00) >> 8); 621 + 622 + fh_max = (fh_min * 66) / 10; 623 + i2c_wr8(sd, FH_MAX0, fh_max & 0x00ff); 624 + i2c_wr8(sd, FH_MAX1, (fh_max & 0xff00) >> 8); 625 + 626 + lockdet_ref = pdata->refclk_hz / 100; 627 + i2c_wr8(sd, LOCKDET_REF0, lockdet_ref & 0x0000ff); 628 + i2c_wr8(sd, LOCKDET_REF1, (lockdet_ref & 0x00ff00) >> 8); 629 + i2c_wr8(sd, LOCKDET_REF2, (lockdet_ref & 0x0f0000) >> 16); 630 + 631 + i2c_wr8_and_or(sd, NCO_F0_MOD, ~MASK_NCO_F0_MOD, 632 + (pdata->refclk_hz == 27000000) ? 633 + MASK_NCO_F0_MOD_27MHZ : 0x0); 634 + } 635 + 636 + static void tc358743_set_csi_color_space(struct v4l2_subdev *sd) 637 + { 638 + struct tc358743_state *state = to_state(sd); 639 + 640 + switch (state->mbus_fmt_code) { 641 + case MEDIA_BUS_FMT_UYVY8_1X16: 642 + v4l2_dbg(2, debug, sd, "%s: YCbCr 422 16-bit\n", __func__); 643 + i2c_wr8_and_or(sd, VOUT_SET2, 644 + ~(MASK_SEL422 | MASK_VOUT_422FIL_100) & 0xff, 645 + MASK_SEL422 | MASK_VOUT_422FIL_100); 646 + i2c_wr8_and_or(sd, VI_REP, ~MASK_VOUT_COLOR_SEL & 0xff, 647 + MASK_VOUT_COLOR_601_YCBCR_LIMITED); 648 + mutex_lock(&state->confctl_mutex); 649 + i2c_wr16_and_or(sd, CONFCTL, ~MASK_YCBCRFMT, 650 + MASK_YCBCRFMT_422_8_BIT); 651 + mutex_unlock(&state->confctl_mutex); 652 + break; 653 + case MEDIA_BUS_FMT_RGB888_1X24: 654 + v4l2_dbg(2, debug, sd, "%s: RGB 888 24-bit\n", __func__); 655 + i2c_wr8_and_or(sd, VOUT_SET2, 656 + ~(MASK_SEL422 | MASK_VOUT_422FIL_100) & 0xff, 657 + 0x00); 658 + i2c_wr8_and_or(sd, VI_REP, ~MASK_VOUT_COLOR_SEL & 0xff, 659 + MASK_VOUT_COLOR_RGB_FULL); 660 + mutex_lock(&state->confctl_mutex); 661 + i2c_wr16_and_or(sd, CONFCTL, ~MASK_YCBCRFMT, 0); 662 + mutex_unlock(&state->confctl_mutex); 663 + break; 664 + default: 665 + v4l2_dbg(2, debug, sd, "%s: Unsupported format code 0x%x\n", 666 + __func__, state->mbus_fmt_code); 667 + } 668 + } 669 + 670 + static unsigned tc358743_num_csi_lanes_needed(struct v4l2_subdev *sd) 671 + { 672 + struct tc358743_state *state = to_state(sd); 673 + struct v4l2_bt_timings *bt = &state->timings.bt; 674 + struct tc358743_platform_data *pdata = &state->pdata; 675 + u32 bits_pr_pixel = 676 + (state->mbus_fmt_code == MEDIA_BUS_FMT_UYVY8_1X16) ? 16 : 24; 677 + u32 bps = bt->width * bt->height * fps(bt) * bits_pr_pixel; 678 + u32 bps_pr_lane = (pdata->refclk_hz / pdata->pll_prd) * pdata->pll_fbd; 679 + 680 + return DIV_ROUND_UP(bps, bps_pr_lane); 681 + } 682 + 683 + static void tc358743_set_csi(struct v4l2_subdev *sd) 684 + { 685 + struct tc358743_state *state = to_state(sd); 686 + struct tc358743_platform_data *pdata = &state->pdata; 687 + unsigned lanes = tc358743_num_csi_lanes_needed(sd); 688 + 689 + v4l2_dbg(3, debug, sd, "%s:\n", __func__); 690 + 691 + tc358743_reset(sd, MASK_CTXRST); 692 + 693 + if (lanes < 1) 694 + i2c_wr32(sd, CLW_CNTRL, MASK_CLW_LANEDISABLE); 695 + if (lanes < 1) 696 + i2c_wr32(sd, D0W_CNTRL, MASK_D0W_LANEDISABLE); 697 + if (lanes < 2) 698 + i2c_wr32(sd, D1W_CNTRL, MASK_D1W_LANEDISABLE); 699 + if (lanes < 3) 700 + i2c_wr32(sd, D2W_CNTRL, MASK_D2W_LANEDISABLE); 701 + if (lanes < 4) 702 + i2c_wr32(sd, D3W_CNTRL, MASK_D3W_LANEDISABLE); 703 + 704 + i2c_wr32(sd, LINEINITCNT, pdata->lineinitcnt); 705 + i2c_wr32(sd, LPTXTIMECNT, pdata->lptxtimecnt); 706 + i2c_wr32(sd, TCLK_HEADERCNT, pdata->tclk_headercnt); 707 + i2c_wr32(sd, TCLK_TRAILCNT, pdata->tclk_trailcnt); 708 + i2c_wr32(sd, THS_HEADERCNT, pdata->ths_headercnt); 709 + i2c_wr32(sd, TWAKEUP, pdata->twakeup); 710 + i2c_wr32(sd, TCLK_POSTCNT, pdata->tclk_postcnt); 711 + i2c_wr32(sd, THS_TRAILCNT, pdata->ths_trailcnt); 712 + i2c_wr32(sd, HSTXVREGCNT, pdata->hstxvregcnt); 713 + 714 + i2c_wr32(sd, HSTXVREGEN, 715 + ((lanes > 0) ? MASK_CLM_HSTXVREGEN : 0x0) | 716 + ((lanes > 0) ? MASK_D0M_HSTXVREGEN : 0x0) | 717 + ((lanes > 1) ? MASK_D1M_HSTXVREGEN : 0x0) | 718 + ((lanes > 2) ? MASK_D2M_HSTXVREGEN : 0x0) | 719 + ((lanes > 3) ? MASK_D3M_HSTXVREGEN : 0x0)); 720 + 721 + i2c_wr32(sd, TXOPTIONCNTRL, (state->bus.flags & 722 + V4L2_MBUS_CSI2_CONTINUOUS_CLOCK) ? MASK_CONTCLKMODE : 0); 723 + i2c_wr32(sd, STARTCNTRL, MASK_START); 724 + i2c_wr32(sd, CSI_START, MASK_STRT); 725 + 726 + i2c_wr32(sd, CSI_CONFW, MASK_MODE_SET | 727 + MASK_ADDRESS_CSI_CONTROL | 728 + MASK_CSI_MODE | 729 + MASK_TXHSMD | 730 + ((lanes == 4) ? MASK_NOL_4 : 731 + (lanes == 3) ? MASK_NOL_3 : 732 + (lanes == 2) ? MASK_NOL_2 : MASK_NOL_1)); 733 + 734 + i2c_wr32(sd, CSI_CONFW, MASK_MODE_SET | 735 + MASK_ADDRESS_CSI_ERR_INTENA | MASK_TXBRK | MASK_QUNK | 736 + MASK_WCER | MASK_INER); 737 + 738 + i2c_wr32(sd, CSI_CONFW, MASK_MODE_CLEAR | 739 + MASK_ADDRESS_CSI_ERR_HALT | MASK_TXBRK | MASK_QUNK); 740 + 741 + i2c_wr32(sd, CSI_CONFW, MASK_MODE_SET | 742 + MASK_ADDRESS_CSI_INT_ENA | MASK_INTER); 743 + } 744 + 745 + static void tc358743_set_hdmi_phy(struct v4l2_subdev *sd) 746 + { 747 + struct tc358743_state *state = to_state(sd); 748 + struct tc358743_platform_data *pdata = &state->pdata; 749 + 750 + /* Default settings from REF_02, sheet "Source HDMI" 751 + * and custom settings as platform data */ 752 + i2c_wr8_and_or(sd, PHY_EN, ~MASK_ENABLE_PHY, 0x0); 753 + i2c_wr8(sd, PHY_CTL1, SET_PHY_AUTO_RST1_US(1600) | 754 + SET_FREQ_RANGE_MODE_CYCLES(1)); 755 + i2c_wr8_and_or(sd, PHY_CTL2, ~MASK_PHY_AUTO_RSTn, 756 + (pdata->hdmi_phy_auto_reset_tmds_detected ? 757 + MASK_PHY_AUTO_RST2 : 0) | 758 + (pdata->hdmi_phy_auto_reset_tmds_in_range ? 759 + MASK_PHY_AUTO_RST3 : 0) | 760 + (pdata->hdmi_phy_auto_reset_tmds_valid ? 761 + MASK_PHY_AUTO_RST4 : 0)); 762 + i2c_wr8(sd, PHY_BIAS, 0x40); 763 + i2c_wr8(sd, PHY_CSQ, SET_CSQ_CNT_LEVEL(0x0a)); 764 + i2c_wr8(sd, AVM_CTL, 45); 765 + i2c_wr8_and_or(sd, HDMI_DET, ~MASK_HDMI_DET_V, 766 + pdata->hdmi_detection_delay << 4); 767 + i2c_wr8_and_or(sd, HV_RST, ~(MASK_H_PI_RST | MASK_V_PI_RST), 768 + (pdata->hdmi_phy_auto_reset_hsync_out_of_range ? 769 + MASK_H_PI_RST : 0) | 770 + (pdata->hdmi_phy_auto_reset_vsync_out_of_range ? 771 + MASK_V_PI_RST : 0)); 772 + i2c_wr8_and_or(sd, PHY_EN, ~MASK_ENABLE_PHY, MASK_ENABLE_PHY); 773 + } 774 + 775 + static void tc358743_set_hdmi_audio(struct v4l2_subdev *sd) 776 + { 777 + struct tc358743_state *state = to_state(sd); 778 + 779 + /* Default settings from REF_02, sheet "Source HDMI" */ 780 + i2c_wr8(sd, FORCE_MUTE, 0x00); 781 + i2c_wr8(sd, AUTO_CMD0, MASK_AUTO_MUTE7 | MASK_AUTO_MUTE6 | 782 + MASK_AUTO_MUTE5 | MASK_AUTO_MUTE4 | 783 + MASK_AUTO_MUTE1 | MASK_AUTO_MUTE0); 784 + i2c_wr8(sd, AUTO_CMD1, MASK_AUTO_MUTE9); 785 + i2c_wr8(sd, AUTO_CMD2, MASK_AUTO_PLAY3 | MASK_AUTO_PLAY2); 786 + i2c_wr8(sd, BUFINIT_START, SET_BUFINIT_START_MS(500)); 787 + i2c_wr8(sd, FS_MUTE, 0x00); 788 + i2c_wr8(sd, FS_IMODE, MASK_NLPCM_SMODE | MASK_FS_SMODE); 789 + i2c_wr8(sd, ACR_MODE, MASK_CTS_MODE); 790 + i2c_wr8(sd, ACR_MDF0, MASK_ACR_L2MDF_1976_PPM | MASK_ACR_L1MDF_976_PPM); 791 + i2c_wr8(sd, ACR_MDF1, MASK_ACR_L3MDF_3906_PPM); 792 + i2c_wr8(sd, SDO_MODE1, MASK_SDO_FMT_I2S); 793 + i2c_wr8(sd, DIV_MODE, SET_DIV_DLY_MS(100)); 794 + 795 + mutex_lock(&state->confctl_mutex); 796 + i2c_wr16_and_or(sd, CONFCTL, 0xffff, MASK_AUDCHNUM_2 | 797 + MASK_AUDOUTSEL_I2S | MASK_AUTOINDEX); 798 + mutex_unlock(&state->confctl_mutex); 799 + } 800 + 801 + static void tc358743_set_hdmi_info_frame_mode(struct v4l2_subdev *sd) 802 + { 803 + /* Default settings from REF_02, sheet "Source HDMI" */ 804 + i2c_wr8(sd, PK_INT_MODE, MASK_ISRC2_INT_MODE | MASK_ISRC_INT_MODE | 805 + MASK_ACP_INT_MODE | MASK_VS_INT_MODE | 806 + MASK_SPD_INT_MODE | MASK_MS_INT_MODE | 807 + MASK_AUD_INT_MODE | MASK_AVI_INT_MODE); 808 + i2c_wr8(sd, NO_PKT_LIMIT, 0x2c); 809 + i2c_wr8(sd, NO_PKT_CLR, 0x53); 810 + i2c_wr8(sd, ERR_PK_LIMIT, 0x01); 811 + i2c_wr8(sd, NO_PKT_LIMIT2, 0x30); 812 + i2c_wr8(sd, NO_GDB_LIMIT, 0x10); 813 + } 814 + 815 + static void tc358743_initial_setup(struct v4l2_subdev *sd) 816 + { 817 + struct tc358743_state *state = to_state(sd); 818 + struct tc358743_platform_data *pdata = &state->pdata; 819 + 820 + /* CEC and IR are not supported by this driver */ 821 + i2c_wr16_and_or(sd, SYSCTL, ~(MASK_CECRST | MASK_IRRST), 822 + (MASK_CECRST | MASK_IRRST)); 823 + 824 + tc358743_reset(sd, MASK_CTXRST | MASK_HDMIRST); 825 + tc358743_sleep_mode(sd, false); 826 + 827 + i2c_wr16(sd, FIFOCTL, pdata->fifo_level); 828 + 829 + tc358743_set_ref_clk(sd); 830 + 831 + i2c_wr8_and_or(sd, DDC_CTL, ~MASK_DDC5V_MODE, 832 + pdata->ddc5v_delay & MASK_DDC5V_MODE); 833 + i2c_wr8_and_or(sd, EDID_MODE, ~MASK_EDID_MODE, MASK_EDID_MODE_E_DDC); 834 + 835 + tc358743_set_hdmi_phy(sd); 836 + tc358743_set_hdmi_hdcp(sd, pdata->enable_hdcp); 837 + tc358743_set_hdmi_audio(sd); 838 + tc358743_set_hdmi_info_frame_mode(sd); 839 + 840 + /* All CE and IT formats are detected as RGB full range in DVI mode */ 841 + i2c_wr8_and_or(sd, VI_MODE, ~MASK_RGB_DVI, 0); 842 + 843 + i2c_wr8_and_or(sd, VOUT_SET2, ~MASK_VOUTCOLORMODE, 844 + MASK_VOUTCOLORMODE_AUTO); 845 + i2c_wr8(sd, VOUT_SET3, MASK_VOUT_EXTCNT); 846 + } 847 + 848 + /* --------------- IRQ --------------- */ 849 + 850 + static void tc358743_format_change(struct v4l2_subdev *sd) 851 + { 852 + struct tc358743_state *state = to_state(sd); 853 + struct v4l2_dv_timings timings; 854 + const struct v4l2_event tc358743_ev_fmt = { 855 + .type = V4L2_EVENT_SOURCE_CHANGE, 856 + .u.src_change.changes = V4L2_EVENT_SRC_CH_RESOLUTION, 857 + }; 858 + 859 + if (tc358743_get_detected_timings(sd, &timings)) { 860 + enable_stream(sd, false); 861 + 862 + v4l2_dbg(1, debug, sd, "%s: Format changed. No signal\n", 863 + __func__); 864 + } else { 865 + if (!v4l2_match_dv_timings(&state->timings, &timings, 0)) 866 + enable_stream(sd, false); 867 + 868 + v4l2_print_dv_timings(sd->name, 869 + "tc358743_format_change: Format changed. New format: ", 870 + &timings, false); 871 + } 872 + 873 + if (sd->devnode) 874 + v4l2_subdev_notify_event(sd, &tc358743_ev_fmt); 875 + } 876 + 877 + static void tc358743_init_interrupts(struct v4l2_subdev *sd) 878 + { 879 + u16 i; 880 + 881 + /* clear interrupt status registers */ 882 + for (i = SYS_INT; i <= KEY_INT; i++) 883 + i2c_wr8(sd, i, 0xff); 884 + 885 + i2c_wr16(sd, INTSTATUS, 0xffff); 886 + } 887 + 888 + static void tc358743_enable_interrupts(struct v4l2_subdev *sd, 889 + bool cable_connected) 890 + { 891 + v4l2_dbg(2, debug, sd, "%s: cable connected = %d\n", __func__, 892 + cable_connected); 893 + 894 + if (cable_connected) { 895 + i2c_wr8(sd, SYS_INTM, ~(MASK_M_DDC | MASK_M_DVI_DET | 896 + MASK_M_HDMI_DET) & 0xff); 897 + i2c_wr8(sd, CLK_INTM, ~MASK_M_IN_DE_CHG); 898 + i2c_wr8(sd, CBIT_INTM, ~(MASK_M_CBIT_FS | MASK_M_AF_LOCK | 899 + MASK_M_AF_UNLOCK) & 0xff); 900 + i2c_wr8(sd, AUDIO_INTM, ~MASK_M_BUFINIT_END); 901 + i2c_wr8(sd, MISC_INTM, ~MASK_M_SYNC_CHG); 902 + } else { 903 + i2c_wr8(sd, SYS_INTM, ~MASK_M_DDC & 0xff); 904 + i2c_wr8(sd, CLK_INTM, 0xff); 905 + i2c_wr8(sd, CBIT_INTM, 0xff); 906 + i2c_wr8(sd, AUDIO_INTM, 0xff); 907 + i2c_wr8(sd, MISC_INTM, 0xff); 908 + } 909 + } 910 + 911 + static void tc358743_hdmi_audio_int_handler(struct v4l2_subdev *sd, 912 + bool *handled) 913 + { 914 + u8 audio_int_mask = i2c_rd8(sd, AUDIO_INTM); 915 + u8 audio_int = i2c_rd8(sd, AUDIO_INT) & ~audio_int_mask; 916 + 917 + i2c_wr8(sd, AUDIO_INT, audio_int); 918 + 919 + v4l2_dbg(3, debug, sd, "%s: AUDIO_INT = 0x%02x\n", __func__, audio_int); 920 + 921 + tc358743_s_ctrl_audio_sampling_rate(sd); 922 + tc358743_s_ctrl_audio_present(sd); 923 + } 924 + 925 + static void tc358743_csi_err_int_handler(struct v4l2_subdev *sd, bool *handled) 926 + { 927 + v4l2_err(sd, "%s: CSI_ERR = 0x%x\n", __func__, i2c_rd32(sd, CSI_ERR)); 928 + 929 + i2c_wr32(sd, CSI_INT_CLR, MASK_ICRER); 930 + } 931 + 932 + static void tc358743_hdmi_misc_int_handler(struct v4l2_subdev *sd, 933 + bool *handled) 934 + { 935 + u8 misc_int_mask = i2c_rd8(sd, MISC_INTM); 936 + u8 misc_int = i2c_rd8(sd, MISC_INT) & ~misc_int_mask; 937 + 938 + i2c_wr8(sd, MISC_INT, misc_int); 939 + 940 + v4l2_dbg(3, debug, sd, "%s: MISC_INT = 0x%02x\n", __func__, misc_int); 941 + 942 + if (misc_int & MASK_I_SYNC_CHG) { 943 + /* Reset the HDMI PHY to try to trigger proper lock on the 944 + * incoming video format. Erase BKSV to prevent that old keys 945 + * are used when a new source is connected. */ 946 + if (no_sync(sd) || no_signal(sd)) { 947 + tc358743_reset_phy(sd); 948 + tc358743_erase_bksv(sd); 949 + } 950 + 951 + tc358743_format_change(sd); 952 + 953 + misc_int &= ~MASK_I_SYNC_CHG; 954 + if (handled) 955 + *handled = true; 956 + } 957 + 958 + if (misc_int) { 959 + v4l2_err(sd, "%s: Unhandled MISC_INT interrupts: 0x%02x\n", 960 + __func__, misc_int); 961 + } 962 + } 963 + 964 + static void tc358743_hdmi_cbit_int_handler(struct v4l2_subdev *sd, 965 + bool *handled) 966 + { 967 + u8 cbit_int_mask = i2c_rd8(sd, CBIT_INTM); 968 + u8 cbit_int = i2c_rd8(sd, CBIT_INT) & ~cbit_int_mask; 969 + 970 + i2c_wr8(sd, CBIT_INT, cbit_int); 971 + 972 + v4l2_dbg(3, debug, sd, "%s: CBIT_INT = 0x%02x\n", __func__, cbit_int); 973 + 974 + if (cbit_int & MASK_I_CBIT_FS) { 975 + 976 + v4l2_dbg(1, debug, sd, "%s: Audio sample rate changed\n", 977 + __func__); 978 + tc358743_s_ctrl_audio_sampling_rate(sd); 979 + 980 + cbit_int &= ~MASK_I_CBIT_FS; 981 + if (handled) 982 + *handled = true; 983 + } 984 + 985 + if (cbit_int & (MASK_I_AF_LOCK | MASK_I_AF_UNLOCK)) { 986 + 987 + v4l2_dbg(1, debug, sd, "%s: Audio present changed\n", 988 + __func__); 989 + tc358743_s_ctrl_audio_present(sd); 990 + 991 + cbit_int &= ~(MASK_I_AF_LOCK | MASK_I_AF_UNLOCK); 992 + if (handled) 993 + *handled = true; 994 + } 995 + 996 + if (cbit_int) { 997 + v4l2_err(sd, "%s: Unhandled CBIT_INT interrupts: 0x%02x\n", 998 + __func__, cbit_int); 999 + } 1000 + } 1001 + 1002 + static void tc358743_hdmi_clk_int_handler(struct v4l2_subdev *sd, bool *handled) 1003 + { 1004 + u8 clk_int_mask = i2c_rd8(sd, CLK_INTM); 1005 + u8 clk_int = i2c_rd8(sd, CLK_INT) & ~clk_int_mask; 1006 + 1007 + /* Bit 7 and bit 6 are set even when they are masked */ 1008 + i2c_wr8(sd, CLK_INT, clk_int | 0x80 | MASK_I_OUT_H_CHG); 1009 + 1010 + v4l2_dbg(3, debug, sd, "%s: CLK_INT = 0x%02x\n", __func__, clk_int); 1011 + 1012 + if (clk_int & (MASK_I_IN_DE_CHG)) { 1013 + 1014 + v4l2_dbg(1, debug, sd, "%s: DE size or position has changed\n", 1015 + __func__); 1016 + 1017 + /* If the source switch to a new resolution with the same pixel 1018 + * frequency as the existing (e.g. 1080p25 -> 720p50), the 1019 + * I_SYNC_CHG interrupt is not always triggered, while the 1020 + * I_IN_DE_CHG interrupt seems to work fine. Format change 1021 + * notifications are only sent when the signal is stable to 1022 + * reduce the number of notifications. */ 1023 + if (!no_signal(sd) && !no_sync(sd)) 1024 + tc358743_format_change(sd); 1025 + 1026 + clk_int &= ~(MASK_I_IN_DE_CHG); 1027 + if (handled) 1028 + *handled = true; 1029 + } 1030 + 1031 + if (clk_int) { 1032 + v4l2_err(sd, "%s: Unhandled CLK_INT interrupts: 0x%02x\n", 1033 + __func__, clk_int); 1034 + } 1035 + } 1036 + 1037 + static void tc358743_hdmi_sys_int_handler(struct v4l2_subdev *sd, bool *handled) 1038 + { 1039 + struct tc358743_state *state = to_state(sd); 1040 + u8 sys_int_mask = i2c_rd8(sd, SYS_INTM); 1041 + u8 sys_int = i2c_rd8(sd, SYS_INT) & ~sys_int_mask; 1042 + 1043 + i2c_wr8(sd, SYS_INT, sys_int); 1044 + 1045 + v4l2_dbg(3, debug, sd, "%s: SYS_INT = 0x%02x\n", __func__, sys_int); 1046 + 1047 + if (sys_int & MASK_I_DDC) { 1048 + bool tx_5v = tx_5v_power_present(sd); 1049 + 1050 + v4l2_dbg(1, debug, sd, "%s: Tx 5V power present: %s\n", 1051 + __func__, tx_5v ? "yes" : "no"); 1052 + 1053 + if (tx_5v) { 1054 + tc358743_enable_edid(sd); 1055 + } else { 1056 + tc358743_enable_interrupts(sd, false); 1057 + tc358743_disable_edid(sd); 1058 + memset(&state->timings, 0, sizeof(state->timings)); 1059 + tc358743_erase_bksv(sd); 1060 + tc358743_update_controls(sd); 1061 + } 1062 + 1063 + sys_int &= ~MASK_I_DDC; 1064 + if (handled) 1065 + *handled = true; 1066 + } 1067 + 1068 + if (sys_int & MASK_I_DVI) { 1069 + v4l2_dbg(1, debug, sd, "%s: HDMI->DVI change detected\n", 1070 + __func__); 1071 + 1072 + /* Reset the HDMI PHY to try to trigger proper lock on the 1073 + * incoming video format. Erase BKSV to prevent that old keys 1074 + * are used when a new source is connected. */ 1075 + if (no_sync(sd) || no_signal(sd)) { 1076 + tc358743_reset_phy(sd); 1077 + tc358743_erase_bksv(sd); 1078 + } 1079 + 1080 + sys_int &= ~MASK_I_DVI; 1081 + if (handled) 1082 + *handled = true; 1083 + } 1084 + 1085 + if (sys_int & MASK_I_HDMI) { 1086 + v4l2_dbg(1, debug, sd, "%s: DVI->HDMI change detected\n", 1087 + __func__); 1088 + 1089 + /* Register is reset in DVI mode (REF_01, c. 6.6.41) */ 1090 + i2c_wr8(sd, ANA_CTL, MASK_APPL_PCSX_NORMAL | MASK_ANALOG_ON); 1091 + 1092 + sys_int &= ~MASK_I_HDMI; 1093 + if (handled) 1094 + *handled = true; 1095 + } 1096 + 1097 + if (sys_int) { 1098 + v4l2_err(sd, "%s: Unhandled SYS_INT interrupts: 0x%02x\n", 1099 + __func__, sys_int); 1100 + } 1101 + } 1102 + 1103 + /* --------------- CORE OPS --------------- */ 1104 + 1105 + static int tc358743_log_status(struct v4l2_subdev *sd) 1106 + { 1107 + struct tc358743_state *state = to_state(sd); 1108 + struct v4l2_dv_timings timings; 1109 + uint8_t hdmi_sys_status = i2c_rd8(sd, SYS_STATUS); 1110 + uint16_t sysctl = i2c_rd16(sd, SYSCTL); 1111 + u8 vi_status3 = i2c_rd8(sd, VI_STATUS3); 1112 + const int deep_color_mode[4] = { 8, 10, 12, 16 }; 1113 + static const char * const input_color_space[] = { 1114 + "RGB", "YCbCr 601", "Adobe RGB", "YCbCr 709", "NA (4)", 1115 + "xvYCC 601", "NA(6)", "xvYCC 709", "NA(8)", "sYCC601", 1116 + "NA(10)", "NA(11)", "NA(12)", "Adobe YCC 601"}; 1117 + 1118 + v4l2_info(sd, "-----Chip status-----\n"); 1119 + v4l2_info(sd, "Chip ID: 0x%02x\n", 1120 + (i2c_rd16(sd, CHIPID) & MASK_CHIPID) >> 8); 1121 + v4l2_info(sd, "Chip revision: 0x%02x\n", 1122 + i2c_rd16(sd, CHIPID) & MASK_REVID); 1123 + v4l2_info(sd, "Reset: IR: %d, CEC: %d, CSI TX: %d, HDMI: %d\n", 1124 + !!(sysctl & MASK_IRRST), 1125 + !!(sysctl & MASK_CECRST), 1126 + !!(sysctl & MASK_CTXRST), 1127 + !!(sysctl & MASK_HDMIRST)); 1128 + v4l2_info(sd, "Sleep mode: %s\n", sysctl & MASK_SLEEP ? "on" : "off"); 1129 + v4l2_info(sd, "Cable detected (+5V power): %s\n", 1130 + hdmi_sys_status & MASK_S_DDC5V ? "yes" : "no"); 1131 + v4l2_info(sd, "DDC lines enabled: %s\n", 1132 + (i2c_rd8(sd, EDID_MODE) & MASK_EDID_MODE_E_DDC) ? 1133 + "yes" : "no"); 1134 + v4l2_info(sd, "Hotplug enabled: %s\n", 1135 + (i2c_rd8(sd, HPD_CTL) & MASK_HPD_OUT0) ? 1136 + "yes" : "no"); 1137 + v4l2_info(sd, "CEC enabled: %s\n", 1138 + (i2c_rd16(sd, CECEN) & MASK_CECEN) ? "yes" : "no"); 1139 + v4l2_info(sd, "-----Signal status-----\n"); 1140 + v4l2_info(sd, "TMDS signal detected: %s\n", 1141 + hdmi_sys_status & MASK_S_TMDS ? "yes" : "no"); 1142 + v4l2_info(sd, "Stable sync signal: %s\n", 1143 + hdmi_sys_status & MASK_S_SYNC ? "yes" : "no"); 1144 + v4l2_info(sd, "PHY PLL locked: %s\n", 1145 + hdmi_sys_status & MASK_S_PHY_PLL ? "yes" : "no"); 1146 + v4l2_info(sd, "PHY DE detected: %s\n", 1147 + hdmi_sys_status & MASK_S_PHY_SCDT ? "yes" : "no"); 1148 + 1149 + if (tc358743_get_detected_timings(sd, &timings)) { 1150 + v4l2_info(sd, "No video detected\n"); 1151 + } else { 1152 + v4l2_print_dv_timings(sd->name, "Detected format: ", &timings, 1153 + true); 1154 + } 1155 + v4l2_print_dv_timings(sd->name, "Configured format: ", &state->timings, 1156 + true); 1157 + 1158 + v4l2_info(sd, "-----CSI-TX status-----\n"); 1159 + v4l2_info(sd, "Lanes needed: %d\n", 1160 + tc358743_num_csi_lanes_needed(sd)); 1161 + v4l2_info(sd, "Lanes in use: %d\n", 1162 + tc358743_num_csi_lanes_in_use(sd)); 1163 + v4l2_info(sd, "Waiting for particular sync signal: %s\n", 1164 + (i2c_rd16(sd, CSI_STATUS) & MASK_S_WSYNC) ? 1165 + "yes" : "no"); 1166 + v4l2_info(sd, "Transmit mode: %s\n", 1167 + (i2c_rd16(sd, CSI_STATUS) & MASK_S_TXACT) ? 1168 + "yes" : "no"); 1169 + v4l2_info(sd, "Receive mode: %s\n", 1170 + (i2c_rd16(sd, CSI_STATUS) & MASK_S_RXACT) ? 1171 + "yes" : "no"); 1172 + v4l2_info(sd, "Stopped: %s\n", 1173 + (i2c_rd16(sd, CSI_STATUS) & MASK_S_HLT) ? 1174 + "yes" : "no"); 1175 + v4l2_info(sd, "Color space: %s\n", 1176 + state->mbus_fmt_code == MEDIA_BUS_FMT_UYVY8_1X16 ? 1177 + "YCbCr 422 16-bit" : 1178 + state->mbus_fmt_code == MEDIA_BUS_FMT_RGB888_1X24 ? 1179 + "RGB 888 24-bit" : "Unsupported"); 1180 + 1181 + v4l2_info(sd, "-----%s status-----\n", is_hdmi(sd) ? "HDMI" : "DVI-D"); 1182 + v4l2_info(sd, "HDCP encrypted content: %s\n", 1183 + hdmi_sys_status & MASK_S_HDCP ? "yes" : "no"); 1184 + v4l2_info(sd, "Input color space: %s %s range\n", 1185 + input_color_space[(vi_status3 & MASK_S_V_COLOR) >> 1], 1186 + (vi_status3 & MASK_LIMITED) ? "limited" : "full"); 1187 + if (!is_hdmi(sd)) 1188 + return 0; 1189 + v4l2_info(sd, "AV Mute: %s\n", hdmi_sys_status & MASK_S_AVMUTE ? "on" : 1190 + "off"); 1191 + v4l2_info(sd, "Deep color mode: %d-bits per channel\n", 1192 + deep_color_mode[(i2c_rd8(sd, VI_STATUS1) & 1193 + MASK_S_DEEPCOLOR) >> 2]); 1194 + print_avi_infoframe(sd); 1195 + 1196 + return 0; 1197 + } 1198 + 1199 + #ifdef CONFIG_VIDEO_ADV_DEBUG 1200 + static void tc358743_print_register_map(struct v4l2_subdev *sd) 1201 + { 1202 + v4l2_info(sd, "0x0000–0x00FF: Global Control Register\n"); 1203 + v4l2_info(sd, "0x0100–0x01FF: CSI2-TX PHY Register\n"); 1204 + v4l2_info(sd, "0x0200–0x03FF: CSI2-TX PPI Register\n"); 1205 + v4l2_info(sd, "0x0400–0x05FF: Reserved\n"); 1206 + v4l2_info(sd, "0x0600–0x06FF: CEC Register\n"); 1207 + v4l2_info(sd, "0x0700–0x84FF: Reserved\n"); 1208 + v4l2_info(sd, "0x8500–0x85FF: HDMIRX System Control Register\n"); 1209 + v4l2_info(sd, "0x8600–0x86FF: HDMIRX Audio Control Register\n"); 1210 + v4l2_info(sd, "0x8700–0x87FF: HDMIRX InfoFrame packet data Register\n"); 1211 + v4l2_info(sd, "0x8800–0x88FF: HDMIRX HDCP Port Register\n"); 1212 + v4l2_info(sd, "0x8900–0x89FF: HDMIRX Video Output Port & 3D Register\n"); 1213 + v4l2_info(sd, "0x8A00–0x8BFF: Reserved\n"); 1214 + v4l2_info(sd, "0x8C00–0x8FFF: HDMIRX EDID-RAM (1024bytes)\n"); 1215 + v4l2_info(sd, "0x9000–0x90FF: HDMIRX GBD Extraction Control\n"); 1216 + v4l2_info(sd, "0x9100–0x92FF: HDMIRX GBD RAM read\n"); 1217 + v4l2_info(sd, "0x9300- : Reserved\n"); 1218 + } 1219 + 1220 + static int tc358743_get_reg_size(u16 address) 1221 + { 1222 + /* REF_01 p. 66-72 */ 1223 + if (address <= 0x00ff) 1224 + return 2; 1225 + else if ((address >= 0x0100) && (address <= 0x06FF)) 1226 + return 4; 1227 + else if ((address >= 0x0700) && (address <= 0x84ff)) 1228 + return 2; 1229 + else 1230 + return 1; 1231 + } 1232 + 1233 + static int tc358743_g_register(struct v4l2_subdev *sd, 1234 + struct v4l2_dbg_register *reg) 1235 + { 1236 + if (reg->reg > 0xffff) { 1237 + tc358743_print_register_map(sd); 1238 + return -EINVAL; 1239 + } 1240 + 1241 + reg->size = tc358743_get_reg_size(reg->reg); 1242 + 1243 + i2c_rd(sd, reg->reg, (u8 *)&reg->val, reg->size); 1244 + 1245 + return 0; 1246 + } 1247 + 1248 + static int tc358743_s_register(struct v4l2_subdev *sd, 1249 + const struct v4l2_dbg_register *reg) 1250 + { 1251 + if (reg->reg > 0xffff) { 1252 + tc358743_print_register_map(sd); 1253 + return -EINVAL; 1254 + } 1255 + 1256 + /* It should not be possible for the user to enable HDCP with a simple 1257 + * v4l2-dbg command. 1258 + * 1259 + * DO NOT REMOVE THIS unless all other issues with HDCP have been 1260 + * resolved. 1261 + */ 1262 + if (reg->reg == HDCP_MODE || 1263 + reg->reg == HDCP_REG1 || 1264 + reg->reg == HDCP_REG2 || 1265 + reg->reg == HDCP_REG3 || 1266 + reg->reg == BCAPS) 1267 + return 0; 1268 + 1269 + i2c_wr(sd, (u16)reg->reg, (u8 *)&reg->val, 1270 + tc358743_get_reg_size(reg->reg)); 1271 + 1272 + return 0; 1273 + } 1274 + #endif 1275 + 1276 + static int tc358743_isr(struct v4l2_subdev *sd, u32 status, bool *handled) 1277 + { 1278 + u16 intstatus = i2c_rd16(sd, INTSTATUS); 1279 + 1280 + v4l2_dbg(1, debug, sd, "%s: IntStatus = 0x%04x\n", __func__, intstatus); 1281 + 1282 + if (intstatus & MASK_HDMI_INT) { 1283 + u8 hdmi_int0 = i2c_rd8(sd, HDMI_INT0); 1284 + u8 hdmi_int1 = i2c_rd8(sd, HDMI_INT1); 1285 + 1286 + if (hdmi_int0 & MASK_I_MISC) 1287 + tc358743_hdmi_misc_int_handler(sd, handled); 1288 + if (hdmi_int1 & MASK_I_CBIT) 1289 + tc358743_hdmi_cbit_int_handler(sd, handled); 1290 + if (hdmi_int1 & MASK_I_CLK) 1291 + tc358743_hdmi_clk_int_handler(sd, handled); 1292 + if (hdmi_int1 & MASK_I_SYS) 1293 + tc358743_hdmi_sys_int_handler(sd, handled); 1294 + if (hdmi_int1 & MASK_I_AUD) 1295 + tc358743_hdmi_audio_int_handler(sd, handled); 1296 + 1297 + i2c_wr16(sd, INTSTATUS, MASK_HDMI_INT); 1298 + intstatus &= ~MASK_HDMI_INT; 1299 + } 1300 + 1301 + if (intstatus & MASK_CSI_INT) { 1302 + u32 csi_int = i2c_rd32(sd, CSI_INT); 1303 + 1304 + if (csi_int & MASK_INTER) 1305 + tc358743_csi_err_int_handler(sd, handled); 1306 + 1307 + i2c_wr16(sd, INTSTATUS, MASK_CSI_INT); 1308 + intstatus &= ~MASK_CSI_INT; 1309 + } 1310 + 1311 + intstatus = i2c_rd16(sd, INTSTATUS); 1312 + if (intstatus) { 1313 + v4l2_dbg(1, debug, sd, 1314 + "%s: Unhandled IntStatus interrupts: 0x%02x\n", 1315 + __func__, intstatus); 1316 + } 1317 + 1318 + return 0; 1319 + } 1320 + 1321 + static irqreturn_t tc358743_irq_handler(int irq, void *dev_id) 1322 + { 1323 + struct tc358743_state *state = dev_id; 1324 + bool handled; 1325 + 1326 + tc358743_isr(&state->sd, 0, &handled); 1327 + 1328 + return handled ? IRQ_HANDLED : IRQ_NONE; 1329 + } 1330 + 1331 + static int tc358743_subscribe_event(struct v4l2_subdev *sd, struct v4l2_fh *fh, 1332 + struct v4l2_event_subscription *sub) 1333 + { 1334 + switch (sub->type) { 1335 + case V4L2_EVENT_SOURCE_CHANGE: 1336 + return v4l2_src_change_event_subdev_subscribe(sd, fh, sub); 1337 + case V4L2_EVENT_CTRL: 1338 + return v4l2_ctrl_subdev_subscribe_event(sd, fh, sub); 1339 + default: 1340 + return -EINVAL; 1341 + } 1342 + } 1343 + 1344 + /* --------------- VIDEO OPS --------------- */ 1345 + 1346 + static int tc358743_g_input_status(struct v4l2_subdev *sd, u32 *status) 1347 + { 1348 + *status = 0; 1349 + *status |= no_signal(sd) ? V4L2_IN_ST_NO_SIGNAL : 0; 1350 + *status |= no_sync(sd) ? V4L2_IN_ST_NO_SYNC : 0; 1351 + 1352 + v4l2_dbg(1, debug, sd, "%s: status = 0x%x\n", __func__, *status); 1353 + 1354 + return 0; 1355 + } 1356 + 1357 + static int tc358743_s_dv_timings(struct v4l2_subdev *sd, 1358 + struct v4l2_dv_timings *timings) 1359 + { 1360 + struct tc358743_state *state = to_state(sd); 1361 + 1362 + if (!timings) 1363 + return -EINVAL; 1364 + 1365 + if (debug) 1366 + v4l2_print_dv_timings(sd->name, "tc358743_s_dv_timings: ", 1367 + timings, false); 1368 + 1369 + if (v4l2_match_dv_timings(&state->timings, timings, 0)) { 1370 + v4l2_dbg(1, debug, sd, "%s: no change\n", __func__); 1371 + return 0; 1372 + } 1373 + 1374 + if (!v4l2_valid_dv_timings(timings, 1375 + &tc358743_timings_cap, NULL, NULL)) { 1376 + v4l2_dbg(1, debug, sd, "%s: timings out of range\n", __func__); 1377 + return -ERANGE; 1378 + } 1379 + 1380 + state->timings = *timings; 1381 + 1382 + enable_stream(sd, false); 1383 + tc358743_set_pll(sd); 1384 + tc358743_set_csi(sd); 1385 + 1386 + return 0; 1387 + } 1388 + 1389 + static int tc358743_g_dv_timings(struct v4l2_subdev *sd, 1390 + struct v4l2_dv_timings *timings) 1391 + { 1392 + struct tc358743_state *state = to_state(sd); 1393 + 1394 + *timings = state->timings; 1395 + 1396 + return 0; 1397 + } 1398 + 1399 + static int tc358743_enum_dv_timings(struct v4l2_subdev *sd, 1400 + struct v4l2_enum_dv_timings *timings) 1401 + { 1402 + if (timings->pad != 0) 1403 + return -EINVAL; 1404 + 1405 + return v4l2_enum_dv_timings_cap(timings, 1406 + &tc358743_timings_cap, NULL, NULL); 1407 + } 1408 + 1409 + static int tc358743_query_dv_timings(struct v4l2_subdev *sd, 1410 + struct v4l2_dv_timings *timings) 1411 + { 1412 + int ret; 1413 + 1414 + ret = tc358743_get_detected_timings(sd, timings); 1415 + if (ret) 1416 + return ret; 1417 + 1418 + if (debug) 1419 + v4l2_print_dv_timings(sd->name, "tc358743_query_dv_timings: ", 1420 + timings, false); 1421 + 1422 + if (!v4l2_valid_dv_timings(timings, 1423 + &tc358743_timings_cap, NULL, NULL)) { 1424 + v4l2_dbg(1, debug, sd, "%s: timings out of range\n", __func__); 1425 + return -ERANGE; 1426 + } 1427 + 1428 + return 0; 1429 + } 1430 + 1431 + static int tc358743_dv_timings_cap(struct v4l2_subdev *sd, 1432 + struct v4l2_dv_timings_cap *cap) 1433 + { 1434 + if (cap->pad != 0) 1435 + return -EINVAL; 1436 + 1437 + *cap = tc358743_timings_cap; 1438 + 1439 + return 0; 1440 + } 1441 + 1442 + static int tc358743_g_mbus_config(struct v4l2_subdev *sd, 1443 + struct v4l2_mbus_config *cfg) 1444 + { 1445 + cfg->type = V4L2_MBUS_CSI2; 1446 + 1447 + /* Support for non-continuous CSI-2 clock is missing in the driver */ 1448 + cfg->flags = V4L2_MBUS_CSI2_CONTINUOUS_CLOCK; 1449 + 1450 + switch (tc358743_num_csi_lanes_in_use(sd)) { 1451 + case 1: 1452 + cfg->flags |= V4L2_MBUS_CSI2_1_LANE; 1453 + break; 1454 + case 2: 1455 + cfg->flags |= V4L2_MBUS_CSI2_2_LANE; 1456 + break; 1457 + case 3: 1458 + cfg->flags |= V4L2_MBUS_CSI2_3_LANE; 1459 + break; 1460 + case 4: 1461 + cfg->flags |= V4L2_MBUS_CSI2_4_LANE; 1462 + break; 1463 + default: 1464 + return -EINVAL; 1465 + } 1466 + 1467 + return 0; 1468 + } 1469 + 1470 + static int tc358743_s_stream(struct v4l2_subdev *sd, int enable) 1471 + { 1472 + enable_stream(sd, enable); 1473 + 1474 + return 0; 1475 + } 1476 + 1477 + /* --------------- PAD OPS --------------- */ 1478 + 1479 + static int tc358743_get_fmt(struct v4l2_subdev *sd, 1480 + struct v4l2_subdev_pad_config *cfg, 1481 + struct v4l2_subdev_format *format) 1482 + { 1483 + struct tc358743_state *state = to_state(sd); 1484 + u8 vi_rep = i2c_rd8(sd, VI_REP); 1485 + 1486 + if (format->pad != 0) 1487 + return -EINVAL; 1488 + 1489 + format->format.code = state->mbus_fmt_code; 1490 + format->format.width = state->timings.bt.width; 1491 + format->format.height = state->timings.bt.height; 1492 + format->format.field = V4L2_FIELD_NONE; 1493 + 1494 + switch (vi_rep & MASK_VOUT_COLOR_SEL) { 1495 + case MASK_VOUT_COLOR_RGB_FULL: 1496 + case MASK_VOUT_COLOR_RGB_LIMITED: 1497 + format->format.colorspace = V4L2_COLORSPACE_SRGB; 1498 + break; 1499 + case MASK_VOUT_COLOR_601_YCBCR_LIMITED: 1500 + case MASK_VOUT_COLOR_601_YCBCR_FULL: 1501 + format->format.colorspace = V4L2_COLORSPACE_SMPTE170M; 1502 + break; 1503 + case MASK_VOUT_COLOR_709_YCBCR_FULL: 1504 + case MASK_VOUT_COLOR_709_YCBCR_LIMITED: 1505 + format->format.colorspace = V4L2_COLORSPACE_REC709; 1506 + break; 1507 + default: 1508 + format->format.colorspace = 0; 1509 + break; 1510 + } 1511 + 1512 + return 0; 1513 + } 1514 + 1515 + static int tc358743_set_fmt(struct v4l2_subdev *sd, 1516 + struct v4l2_subdev_pad_config *cfg, 1517 + struct v4l2_subdev_format *format) 1518 + { 1519 + struct tc358743_state *state = to_state(sd); 1520 + 1521 + u32 code = format->format.code; /* is overwritten by get_fmt */ 1522 + int ret = tc358743_get_fmt(sd, cfg, format); 1523 + 1524 + format->format.code = code; 1525 + 1526 + if (ret) 1527 + return ret; 1528 + 1529 + switch (code) { 1530 + case MEDIA_BUS_FMT_RGB888_1X24: 1531 + case MEDIA_BUS_FMT_UYVY8_1X16: 1532 + break; 1533 + default: 1534 + return -EINVAL; 1535 + } 1536 + 1537 + if (format->which == V4L2_SUBDEV_FORMAT_TRY) 1538 + return 0; 1539 + 1540 + state->mbus_fmt_code = format->format.code; 1541 + 1542 + enable_stream(sd, false); 1543 + tc358743_set_pll(sd); 1544 + tc358743_set_csi(sd); 1545 + tc358743_set_csi_color_space(sd); 1546 + 1547 + return 0; 1548 + } 1549 + 1550 + static int tc358743_g_edid(struct v4l2_subdev *sd, 1551 + struct v4l2_subdev_edid *edid) 1552 + { 1553 + struct tc358743_state *state = to_state(sd); 1554 + 1555 + if (edid->pad != 0) 1556 + return -EINVAL; 1557 + 1558 + if (edid->start_block == 0 && edid->blocks == 0) { 1559 + edid->blocks = state->edid_blocks_written; 1560 + return 0; 1561 + } 1562 + 1563 + if (state->edid_blocks_written == 0) 1564 + return -ENODATA; 1565 + 1566 + if (edid->start_block >= state->edid_blocks_written || 1567 + edid->blocks == 0) 1568 + return -EINVAL; 1569 + 1570 + if (edid->start_block + edid->blocks > state->edid_blocks_written) 1571 + edid->blocks = state->edid_blocks_written - edid->start_block; 1572 + 1573 + i2c_rd(sd, EDID_RAM + (edid->start_block * EDID_BLOCK_SIZE), edid->edid, 1574 + edid->blocks * EDID_BLOCK_SIZE); 1575 + 1576 + return 0; 1577 + } 1578 + 1579 + static int tc358743_s_edid(struct v4l2_subdev *sd, 1580 + struct v4l2_subdev_edid *edid) 1581 + { 1582 + struct tc358743_state *state = to_state(sd); 1583 + u16 edid_len = edid->blocks * EDID_BLOCK_SIZE; 1584 + 1585 + v4l2_dbg(2, debug, sd, "%s, pad %d, start block %d, blocks %d\n", 1586 + __func__, edid->pad, edid->start_block, edid->blocks); 1587 + 1588 + if (edid->pad != 0) 1589 + return -EINVAL; 1590 + 1591 + if (edid->start_block != 0) 1592 + return -EINVAL; 1593 + 1594 + if (edid->blocks > EDID_NUM_BLOCKS_MAX) { 1595 + edid->blocks = EDID_NUM_BLOCKS_MAX; 1596 + return -E2BIG; 1597 + } 1598 + 1599 + tc358743_disable_edid(sd); 1600 + 1601 + i2c_wr8(sd, EDID_LEN1, edid_len & 0xff); 1602 + i2c_wr8(sd, EDID_LEN2, edid_len >> 8); 1603 + 1604 + if (edid->blocks == 0) { 1605 + state->edid_blocks_written = 0; 1606 + return 0; 1607 + } 1608 + 1609 + i2c_wr(sd, EDID_RAM, edid->edid, edid_len); 1610 + 1611 + state->edid_blocks_written = edid->blocks; 1612 + 1613 + if (tx_5v_power_present(sd)) 1614 + tc358743_enable_edid(sd); 1615 + 1616 + return 0; 1617 + } 1618 + 1619 + /* -------------------------------------------------------------------------- */ 1620 + 1621 + static const struct v4l2_subdev_core_ops tc358743_core_ops = { 1622 + .log_status = tc358743_log_status, 1623 + #ifdef CONFIG_VIDEO_ADV_DEBUG 1624 + .g_register = tc358743_g_register, 1625 + .s_register = tc358743_s_register, 1626 + #endif 1627 + .interrupt_service_routine = tc358743_isr, 1628 + .subscribe_event = tc358743_subscribe_event, 1629 + .unsubscribe_event = v4l2_event_subdev_unsubscribe, 1630 + }; 1631 + 1632 + static const struct v4l2_subdev_video_ops tc358743_video_ops = { 1633 + .g_input_status = tc358743_g_input_status, 1634 + .s_dv_timings = tc358743_s_dv_timings, 1635 + .g_dv_timings = tc358743_g_dv_timings, 1636 + .query_dv_timings = tc358743_query_dv_timings, 1637 + .g_mbus_config = tc358743_g_mbus_config, 1638 + .s_stream = tc358743_s_stream, 1639 + }; 1640 + 1641 + static const struct v4l2_subdev_pad_ops tc358743_pad_ops = { 1642 + .set_fmt = tc358743_set_fmt, 1643 + .get_fmt = tc358743_get_fmt, 1644 + .get_edid = tc358743_g_edid, 1645 + .set_edid = tc358743_s_edid, 1646 + .enum_dv_timings = tc358743_enum_dv_timings, 1647 + .dv_timings_cap = tc358743_dv_timings_cap, 1648 + }; 1649 + 1650 + static const struct v4l2_subdev_ops tc358743_ops = { 1651 + .core = &tc358743_core_ops, 1652 + .video = &tc358743_video_ops, 1653 + .pad = &tc358743_pad_ops, 1654 + }; 1655 + 1656 + /* --------------- CUSTOM CTRLS --------------- */ 1657 + 1658 + static const struct v4l2_ctrl_config tc358743_ctrl_audio_sampling_rate = { 1659 + .id = TC358743_CID_AUDIO_SAMPLING_RATE, 1660 + .name = "Audio sampling rate", 1661 + .type = V4L2_CTRL_TYPE_INTEGER, 1662 + .min = 0, 1663 + .max = 768000, 1664 + .step = 1, 1665 + .def = 0, 1666 + .flags = V4L2_CTRL_FLAG_READ_ONLY, 1667 + }; 1668 + 1669 + static const struct v4l2_ctrl_config tc358743_ctrl_audio_present = { 1670 + .id = TC358743_CID_AUDIO_PRESENT, 1671 + .name = "Audio present", 1672 + .type = V4L2_CTRL_TYPE_BOOLEAN, 1673 + .min = 0, 1674 + .max = 1, 1675 + .step = 1, 1676 + .def = 0, 1677 + .flags = V4L2_CTRL_FLAG_READ_ONLY, 1678 + }; 1679 + 1680 + /* --------------- PROBE / REMOVE --------------- */ 1681 + 1682 + #ifdef CONFIG_OF 1683 + static void tc358743_gpio_reset(struct tc358743_state *state) 1684 + { 1685 + usleep_range(5000, 10000); 1686 + gpiod_set_value(state->reset_gpio, 1); 1687 + usleep_range(1000, 2000); 1688 + gpiod_set_value(state->reset_gpio, 0); 1689 + msleep(20); 1690 + } 1691 + 1692 + static int tc358743_probe_of(struct tc358743_state *state) 1693 + { 1694 + struct device *dev = &state->i2c_client->dev; 1695 + struct v4l2_of_endpoint *endpoint; 1696 + struct device_node *ep; 1697 + struct clk *refclk; 1698 + u32 bps_pr_lane; 1699 + int ret = -EINVAL; 1700 + 1701 + refclk = devm_clk_get(dev, "refclk"); 1702 + if (IS_ERR(refclk)) { 1703 + if (PTR_ERR(refclk) != -EPROBE_DEFER) 1704 + dev_err(dev, "failed to get refclk: %ld\n", 1705 + PTR_ERR(refclk)); 1706 + return PTR_ERR(refclk); 1707 + } 1708 + 1709 + ep = of_graph_get_next_endpoint(dev->of_node, NULL); 1710 + if (!ep) { 1711 + dev_err(dev, "missing endpoint node\n"); 1712 + return -EINVAL; 1713 + } 1714 + 1715 + endpoint = v4l2_of_alloc_parse_endpoint(ep); 1716 + if (IS_ERR(endpoint)) { 1717 + dev_err(dev, "failed to parse endpoint\n"); 1718 + return PTR_ERR(endpoint); 1719 + } 1720 + 1721 + if (endpoint->bus_type != V4L2_MBUS_CSI2 || 1722 + endpoint->bus.mipi_csi2.num_data_lanes == 0 || 1723 + endpoint->nr_of_link_frequencies == 0) { 1724 + dev_err(dev, "missing CSI-2 properties in endpoint\n"); 1725 + goto free_endpoint; 1726 + } 1727 + 1728 + state->bus = endpoint->bus.mipi_csi2; 1729 + 1730 + clk_prepare_enable(refclk); 1731 + 1732 + state->pdata.refclk_hz = clk_get_rate(refclk); 1733 + state->pdata.ddc5v_delay = DDC5V_DELAY_100_MS; 1734 + state->pdata.enable_hdcp = false; 1735 + /* A FIFO level of 16 should be enough for 2-lane 720p60 at 594 MHz. */ 1736 + state->pdata.fifo_level = 16; 1737 + /* 1738 + * The PLL input clock is obtained by dividing refclk by pll_prd. 1739 + * It must be between 6 MHz and 40 MHz, lower frequency is better. 1740 + */ 1741 + switch (state->pdata.refclk_hz) { 1742 + case 26000000: 1743 + case 27000000: 1744 + case 42000000: 1745 + state->pdata.pll_prd = state->pdata.refclk_hz / 6000000; 1746 + break; 1747 + default: 1748 + dev_err(dev, "unsupported refclk rate: %u Hz\n", 1749 + state->pdata.refclk_hz); 1750 + goto disable_clk; 1751 + } 1752 + 1753 + /* 1754 + * The CSI bps per lane must be between 62.5 Mbps and 1 Gbps. 1755 + * The default is 594 Mbps for 4-lane 1080p60 or 2-lane 720p60. 1756 + */ 1757 + bps_pr_lane = 2 * endpoint->link_frequencies[0]; 1758 + if (bps_pr_lane < 62500000U || bps_pr_lane > 1000000000U) { 1759 + dev_err(dev, "unsupported bps per lane: %u bps\n", bps_pr_lane); 1760 + goto disable_clk; 1761 + } 1762 + 1763 + /* The CSI speed per lane is refclk / pll_prd * pll_fbd */ 1764 + state->pdata.pll_fbd = bps_pr_lane / 1765 + state->pdata.refclk_hz * state->pdata.pll_prd; 1766 + 1767 + /* 1768 + * FIXME: These timings are from REF_02 for 594 Mbps per lane (297 MHz 1769 + * link frequency). In principle it should be possible to calculate 1770 + * them based on link frequency and resolution. 1771 + */ 1772 + if (bps_pr_lane != 594000000U) 1773 + dev_warn(dev, "untested bps per lane: %u bps\n", bps_pr_lane); 1774 + state->pdata.lineinitcnt = 0xe80; 1775 + state->pdata.lptxtimecnt = 0x003; 1776 + /* tclk-preparecnt: 3, tclk-zerocnt: 20 */ 1777 + state->pdata.tclk_headercnt = 0x1403; 1778 + state->pdata.tclk_trailcnt = 0x00; 1779 + /* ths-preparecnt: 3, ths-zerocnt: 1 */ 1780 + state->pdata.ths_headercnt = 0x0103; 1781 + state->pdata.twakeup = 0x4882; 1782 + state->pdata.tclk_postcnt = 0x008; 1783 + state->pdata.ths_trailcnt = 0x2; 1784 + state->pdata.hstxvregcnt = 0; 1785 + 1786 + state->reset_gpio = devm_gpiod_get_optional(dev, "reset", 1787 + GPIOD_OUT_LOW); 1788 + if (IS_ERR(state->reset_gpio)) { 1789 + dev_err(dev, "failed to get reset gpio\n"); 1790 + ret = PTR_ERR(state->reset_gpio); 1791 + goto disable_clk; 1792 + } 1793 + 1794 + if (state->reset_gpio) 1795 + tc358743_gpio_reset(state); 1796 + 1797 + ret = 0; 1798 + goto free_endpoint; 1799 + 1800 + disable_clk: 1801 + clk_disable_unprepare(refclk); 1802 + free_endpoint: 1803 + v4l2_of_free_endpoint(endpoint); 1804 + return ret; 1805 + } 1806 + #else 1807 + static inline int tc358743_probe_of(struct tc358743_state *state) 1808 + { 1809 + return -ENODEV; 1810 + } 1811 + #endif 1812 + 1813 + static int tc358743_probe(struct i2c_client *client, 1814 + const struct i2c_device_id *id) 1815 + { 1816 + static struct v4l2_dv_timings default_timing = 1817 + V4L2_DV_BT_CEA_640X480P59_94; 1818 + struct tc358743_state *state; 1819 + struct tc358743_platform_data *pdata = client->dev.platform_data; 1820 + struct v4l2_subdev *sd; 1821 + int err; 1822 + 1823 + if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE_DATA)) 1824 + return -EIO; 1825 + v4l_dbg(1, debug, client, "chip found @ 0x%x (%s)\n", 1826 + client->addr << 1, client->adapter->name); 1827 + 1828 + state = devm_kzalloc(&client->dev, sizeof(struct tc358743_state), 1829 + GFP_KERNEL); 1830 + if (!state) 1831 + return -ENOMEM; 1832 + 1833 + state->i2c_client = client; 1834 + 1835 + /* platform data */ 1836 + if (pdata) { 1837 + state->pdata = *pdata; 1838 + state->bus.flags = V4L2_MBUS_CSI2_CONTINUOUS_CLOCK; 1839 + } else { 1840 + err = tc358743_probe_of(state); 1841 + if (err == -ENODEV) 1842 + v4l_err(client, "No platform data!\n"); 1843 + if (err) 1844 + return err; 1845 + } 1846 + 1847 + sd = &state->sd; 1848 + v4l2_i2c_subdev_init(sd, client, &tc358743_ops); 1849 + sd->flags |= V4L2_SUBDEV_FL_HAS_DEVNODE | V4L2_SUBDEV_FL_HAS_EVENTS; 1850 + 1851 + /* i2c access */ 1852 + if ((i2c_rd16(sd, CHIPID) & MASK_CHIPID) != 0) { 1853 + v4l2_info(sd, "not a TC358743 on address 0x%x\n", 1854 + client->addr << 1); 1855 + return -ENODEV; 1856 + } 1857 + 1858 + /* control handlers */ 1859 + v4l2_ctrl_handler_init(&state->hdl, 3); 1860 + 1861 + /* private controls */ 1862 + state->detect_tx_5v_ctrl = v4l2_ctrl_new_std(&state->hdl, NULL, 1863 + V4L2_CID_DV_RX_POWER_PRESENT, 0, 1, 0, 0); 1864 + 1865 + /* custom controls */ 1866 + state->audio_sampling_rate_ctrl = v4l2_ctrl_new_custom(&state->hdl, 1867 + &tc358743_ctrl_audio_sampling_rate, NULL); 1868 + 1869 + state->audio_present_ctrl = v4l2_ctrl_new_custom(&state->hdl, 1870 + &tc358743_ctrl_audio_present, NULL); 1871 + 1872 + sd->ctrl_handler = &state->hdl; 1873 + if (state->hdl.error) { 1874 + err = state->hdl.error; 1875 + goto err_hdl; 1876 + } 1877 + 1878 + if (tc358743_update_controls(sd)) { 1879 + err = -ENODEV; 1880 + goto err_hdl; 1881 + } 1882 + 1883 + /* work queues */ 1884 + state->work_queues = create_singlethread_workqueue(client->name); 1885 + if (!state->work_queues) { 1886 + v4l2_err(sd, "Could not create work queue\n"); 1887 + err = -ENOMEM; 1888 + goto err_hdl; 1889 + } 1890 + 1891 + state->pad.flags = MEDIA_PAD_FL_SOURCE; 1892 + err = media_entity_init(&sd->entity, 1, &state->pad, 0); 1893 + if (err < 0) 1894 + goto err_hdl; 1895 + 1896 + sd->dev = &client->dev; 1897 + err = v4l2_async_register_subdev(sd); 1898 + if (err < 0) 1899 + goto err_hdl; 1900 + 1901 + mutex_init(&state->confctl_mutex); 1902 + 1903 + INIT_DELAYED_WORK(&state->delayed_work_enable_hotplug, 1904 + tc358743_delayed_work_enable_hotplug); 1905 + 1906 + tc358743_initial_setup(sd); 1907 + 1908 + tc358743_s_dv_timings(sd, &default_timing); 1909 + 1910 + state->mbus_fmt_code = MEDIA_BUS_FMT_RGB888_1X24; 1911 + tc358743_set_csi_color_space(sd); 1912 + 1913 + tc358743_init_interrupts(sd); 1914 + 1915 + if (state->i2c_client->irq) { 1916 + err = devm_request_threaded_irq(&client->dev, 1917 + state->i2c_client->irq, 1918 + NULL, tc358743_irq_handler, 1919 + IRQF_TRIGGER_HIGH | IRQF_ONESHOT, 1920 + "tc358743", state); 1921 + if (err) 1922 + goto err_work_queues; 1923 + } 1924 + 1925 + tc358743_enable_interrupts(sd, tx_5v_power_present(sd)); 1926 + i2c_wr16(sd, INTMASK, ~(MASK_HDMI_MSK | MASK_CSI_MSK) & 0xffff); 1927 + 1928 + err = v4l2_ctrl_handler_setup(sd->ctrl_handler); 1929 + if (err) 1930 + goto err_work_queues; 1931 + 1932 + v4l2_info(sd, "%s found @ 0x%x (%s)\n", client->name, 1933 + client->addr << 1, client->adapter->name); 1934 + 1935 + return 0; 1936 + 1937 + err_work_queues: 1938 + cancel_delayed_work(&state->delayed_work_enable_hotplug); 1939 + destroy_workqueue(state->work_queues); 1940 + mutex_destroy(&state->confctl_mutex); 1941 + err_hdl: 1942 + media_entity_cleanup(&sd->entity); 1943 + v4l2_ctrl_handler_free(&state->hdl); 1944 + return err; 1945 + } 1946 + 1947 + static int tc358743_remove(struct i2c_client *client) 1948 + { 1949 + struct v4l2_subdev *sd = i2c_get_clientdata(client); 1950 + struct tc358743_state *state = to_state(sd); 1951 + 1952 + cancel_delayed_work(&state->delayed_work_enable_hotplug); 1953 + destroy_workqueue(state->work_queues); 1954 + v4l2_async_unregister_subdev(sd); 1955 + v4l2_device_unregister_subdev(sd); 1956 + mutex_destroy(&state->confctl_mutex); 1957 + media_entity_cleanup(&sd->entity); 1958 + v4l2_ctrl_handler_free(&state->hdl); 1959 + 1960 + return 0; 1961 + } 1962 + 1963 + static struct i2c_device_id tc358743_id[] = { 1964 + {"tc358743", 0}, 1965 + {} 1966 + }; 1967 + 1968 + MODULE_DEVICE_TABLE(i2c, tc358743_id); 1969 + 1970 + static struct i2c_driver tc358743_driver = { 1971 + .driver = { 1972 + .name = "tc358743", 1973 + }, 1974 + .probe = tc358743_probe, 1975 + .remove = tc358743_remove, 1976 + .id_table = tc358743_id, 1977 + }; 1978 + 1979 + module_i2c_driver(tc358743_driver);
+681
drivers/media/i2c/tc358743_regs.h
··· 1 + /* 2 + * tc358743 - Toshiba HDMI to CSI-2 bridge - register names and bit masks 3 + * 4 + * Copyright 2015 Cisco Systems, Inc. and/or its affiliates. All rights 5 + * reserved. 6 + * 7 + * This program is free software; you may redistribute it and/or modify 8 + * it under the terms of the GNU General Public License as published by 9 + * the Free Software Foundation; version 2 of the License. 10 + * 11 + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 12 + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 13 + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 14 + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 15 + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 16 + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 17 + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 18 + * SOFTWARE. 19 + * 20 + */ 21 + 22 + /* 23 + * References (c = chapter, p = page): 24 + * REF_01 - Toshiba, TC358743XBG (H2C), Functional Specification, Rev 0.60 25 + */ 26 + 27 + /* Bit masks has prefix 'MASK_' and options after '_'. */ 28 + 29 + #ifndef __TC358743_REGS_H 30 + #define __TC358743_REGS_H 31 + 32 + #define CHIPID 0x0000 33 + #define MASK_CHIPID 0xff00 34 + #define MASK_REVID 0x00ff 35 + 36 + #define SYSCTL 0x0002 37 + #define MASK_IRRST 0x0800 38 + #define MASK_CECRST 0x0400 39 + #define MASK_CTXRST 0x0200 40 + #define MASK_HDMIRST 0x0100 41 + #define MASK_SLEEP 0x0001 42 + 43 + #define CONFCTL 0x0004 44 + #define MASK_PWRISO 0x8000 45 + #define MASK_ACLKOPT 0x1000 46 + #define MASK_AUDCHNUM 0x0c00 47 + #define MASK_AUDCHNUM_8 0x0000 48 + #define MASK_AUDCHNUM_6 0x0400 49 + #define MASK_AUDCHNUM_4 0x0800 50 + #define MASK_AUDCHNUM_2 0x0c00 51 + #define MASK_AUDCHSEL 0x0200 52 + #define MASK_I2SDLYOPT 0x0100 53 + #define MASK_YCBCRFMT 0x00c0 54 + #define MASK_YCBCRFMT_444 0x0000 55 + #define MASK_YCBCRFMT_422_12_BIT 0x0040 56 + #define MASK_YCBCRFMT_COLORBAR 0x0080 57 + #define MASK_YCBCRFMT_422_8_BIT 0x00c0 58 + #define MASK_INFRMEN 0x0020 59 + #define MASK_AUDOUTSEL 0x0018 60 + #define MASK_AUDOUTSEL_CSI 0x0000 61 + #define MASK_AUDOUTSEL_I2S 0x0010 62 + #define MASK_AUDOUTSEL_TDM 0x0018 63 + #define MASK_AUTOINDEX 0x0004 64 + #define MASK_ABUFEN 0x0002 65 + #define MASK_VBUFEN 0x0001 66 + 67 + #define FIFOCTL 0x0006 68 + 69 + #define INTSTATUS 0x0014 70 + #define MASK_AMUTE_INT 0x0400 71 + #define MASK_HDMI_INT 0x0200 72 + #define MASK_CSI_INT 0x0100 73 + #define MASK_SYS_INT 0x0020 74 + #define MASK_CEC_EINT 0x0010 75 + #define MASK_CEC_TINT 0x0008 76 + #define MASK_CEC_RINT 0x0004 77 + #define MASK_IR_EINT 0x0002 78 + #define MASK_IR_DINT 0x0001 79 + 80 + #define INTMASK 0x0016 81 + #define MASK_AMUTE_MSK 0x0400 82 + #define MASK_HDMI_MSK 0x0200 83 + #define MASK_CSI_MSK 0x0100 84 + #define MASK_SYS_MSK 0x0020 85 + #define MASK_CEC_EMSK 0x0010 86 + #define MASK_CEC_TMSK 0x0008 87 + #define MASK_CEC_RMSK 0x0004 88 + #define MASK_IR_EMSK 0x0002 89 + #define MASK_IR_DMSK 0x0001 90 + 91 + #define INTFLAG 0x0018 92 + #define INTSYSSTATUS 0x001A 93 + 94 + #define PLLCTL0 0x0020 95 + #define MASK_PLL_PRD 0xf000 96 + #define SET_PLL_PRD(prd) ((((prd) - 1) << 12) &\ 97 + MASK_PLL_PRD) 98 + #define MASK_PLL_FBD 0x01ff 99 + #define SET_PLL_FBD(fbd) (((fbd) - 1) & MASK_PLL_FBD) 100 + 101 + #define PLLCTL1 0x0022 102 + #define MASK_PLL_FRS 0x0c00 103 + #define SET_PLL_FRS(frs) (((frs) << 10) & MASK_PLL_FRS) 104 + #define MASK_PLL_LBWS 0x0300 105 + #define MASK_LFBREN 0x0040 106 + #define MASK_BYPCKEN 0x0020 107 + #define MASK_CKEN 0x0010 108 + #define MASK_RESETB 0x0002 109 + #define MASK_PLL_EN 0x0001 110 + 111 + #define CLW_CNTRL 0x0140 112 + #define MASK_CLW_LANEDISABLE 0x0001 113 + 114 + #define D0W_CNTRL 0x0144 115 + #define MASK_D0W_LANEDISABLE 0x0001 116 + 117 + #define D1W_CNTRL 0x0148 118 + #define MASK_D1W_LANEDISABLE 0x0001 119 + 120 + #define D2W_CNTRL 0x014C 121 + #define MASK_D2W_LANEDISABLE 0x0001 122 + 123 + #define D3W_CNTRL 0x0150 124 + #define MASK_D3W_LANEDISABLE 0x0001 125 + 126 + #define STARTCNTRL 0x0204 127 + #define MASK_START 0x00000001 128 + 129 + #define LINEINITCNT 0x0210 130 + #define LPTXTIMECNT 0x0214 131 + #define TCLK_HEADERCNT 0x0218 132 + #define TCLK_TRAILCNT 0x021C 133 + #define THS_HEADERCNT 0x0220 134 + #define TWAKEUP 0x0224 135 + #define TCLK_POSTCNT 0x0228 136 + #define THS_TRAILCNT 0x022C 137 + #define HSTXVREGCNT 0x0230 138 + 139 + #define HSTXVREGEN 0x0234 140 + #define MASK_D3M_HSTXVREGEN 0x0010 141 + #define MASK_D2M_HSTXVREGEN 0x0008 142 + #define MASK_D1M_HSTXVREGEN 0x0004 143 + #define MASK_D0M_HSTXVREGEN 0x0002 144 + #define MASK_CLM_HSTXVREGEN 0x0001 145 + 146 + 147 + #define TXOPTIONCNTRL 0x0238 148 + #define MASK_CONTCLKMODE 0x00000001 149 + 150 + #define CSI_CONTROL 0x040C 151 + #define MASK_CSI_MODE 0x8000 152 + #define MASK_HTXTOEN 0x0400 153 + #define MASK_TXHSMD 0x0080 154 + #define MASK_HSCKMD 0x0020 155 + #define MASK_NOL 0x0006 156 + #define MASK_NOL_1 0x0000 157 + #define MASK_NOL_2 0x0002 158 + #define MASK_NOL_3 0x0004 159 + #define MASK_NOL_4 0x0006 160 + #define MASK_EOTDIS 0x0001 161 + 162 + #define CSI_INT 0x0414 163 + #define MASK_INTHLT 0x00000008 164 + #define MASK_INTER 0x00000004 165 + 166 + #define CSI_INT_ENA 0x0418 167 + #define MASK_IENHLT 0x00000008 168 + #define MASK_IENER 0x00000004 169 + 170 + #define CSI_ERR 0x044C 171 + #define MASK_INER 0x00000200 172 + #define MASK_WCER 0x00000100 173 + #define MASK_QUNK 0x00000010 174 + #define MASK_TXBRK 0x00000002 175 + 176 + #define CSI_ERR_INTENA 0x0450 177 + #define CSI_ERR_HALT 0x0454 178 + 179 + #define CSI_CONFW 0x0500 180 + #define MASK_MODE 0xe0000000 181 + #define MASK_MODE_SET 0xa0000000 182 + #define MASK_MODE_CLEAR 0xc0000000 183 + #define MASK_ADDRESS 0x1f000000 184 + #define MASK_ADDRESS_CSI_CONTROL 0x03000000 185 + #define MASK_ADDRESS_CSI_INT_ENA 0x06000000 186 + #define MASK_ADDRESS_CSI_ERR_INTENA 0x14000000 187 + #define MASK_ADDRESS_CSI_ERR_HALT 0x15000000 188 + #define MASK_DATA 0x0000ffff 189 + 190 + #define CSI_INT_CLR 0x050C 191 + #define MASK_ICRER 0x00000004 192 + 193 + #define CSI_START 0x0518 194 + #define MASK_STRT 0x00000001 195 + 196 + #define CECEN 0x0600 197 + #define MASK_CECEN 0x0001 198 + 199 + #define HDMI_INT0 0x8500 200 + #define MASK_I_KEY 0x80 201 + #define MASK_I_MISC 0x02 202 + #define MASK_I_PHYERR 0x01 203 + 204 + #define HDMI_INT1 0x8501 205 + #define MASK_I_GBD 0x80 206 + #define MASK_I_HDCP 0x40 207 + #define MASK_I_ERR 0x20 208 + #define MASK_I_AUD 0x10 209 + #define MASK_I_CBIT 0x08 210 + #define MASK_I_PACKET 0x04 211 + #define MASK_I_CLK 0x02 212 + #define MASK_I_SYS 0x01 213 + 214 + #define SYS_INT 0x8502 215 + #define MASK_I_ACR_CTS 0x80 216 + #define MASK_I_ACRN 0x40 217 + #define MASK_I_DVI 0x20 218 + #define MASK_I_HDMI 0x10 219 + #define MASK_I_NOPMBDET 0x08 220 + #define MASK_I_DPMBDET 0x04 221 + #define MASK_I_TMDS 0x02 222 + #define MASK_I_DDC 0x01 223 + 224 + #define CLK_INT 0x8503 225 + #define MASK_I_OUT_H_CHG 0x40 226 + #define MASK_I_IN_DE_CHG 0x20 227 + #define MASK_I_IN_HV_CHG 0x10 228 + #define MASK_I_DC_CHG 0x08 229 + #define MASK_I_PXCLK_CHG 0x04 230 + #define MASK_I_PHYCLK_CHG 0x02 231 + #define MASK_I_TMDSCLK_CHG 0x01 232 + 233 + #define CBIT_INT 0x8505 234 + #define MASK_I_AF_LOCK 0x80 235 + #define MASK_I_AF_UNLOCK 0x40 236 + #define MASK_I_CBIT_FS 0x02 237 + 238 + #define AUDIO_INT 0x8506 239 + 240 + #define ERR_INT 0x8507 241 + #define MASK_I_EESS_ERR 0x80 242 + 243 + #define HDCP_INT 0x8508 244 + #define MASK_I_AVM_SET 0x80 245 + #define MASK_I_AVM_CLR 0x40 246 + #define MASK_I_LINKERR 0x20 247 + #define MASK_I_SHA_END 0x10 248 + #define MASK_I_R0_END 0x08 249 + #define MASK_I_KM_END 0x04 250 + #define MASK_I_AKSV_END 0x02 251 + #define MASK_I_AN_END 0x01 252 + 253 + #define MISC_INT 0x850B 254 + #define MASK_I_AS_LAYOUT 0x10 255 + #define MASK_I_NO_SPD 0x08 256 + #define MASK_I_NO_VS 0x03 257 + #define MASK_I_SYNC_CHG 0x02 258 + #define MASK_I_AUDIO_MUTE 0x01 259 + 260 + #define KEY_INT 0x850F 261 + 262 + #define SYS_INTM 0x8512 263 + #define MASK_M_ACR_CTS 0x80 264 + #define MASK_M_ACR_N 0x40 265 + #define MASK_M_DVI_DET 0x20 266 + #define MASK_M_HDMI_DET 0x10 267 + #define MASK_M_NOPMBDET 0x08 268 + #define MASK_M_BPMBDET 0x04 269 + #define MASK_M_TMDS 0x02 270 + #define MASK_M_DDC 0x01 271 + 272 + #define CLK_INTM 0x8513 273 + #define MASK_M_OUT_H_CHG 0x40 274 + #define MASK_M_IN_DE_CHG 0x20 275 + #define MASK_M_IN_HV_CHG 0x10 276 + #define MASK_M_DC_CHG 0x08 277 + #define MASK_M_PXCLK_CHG 0x04 278 + #define MASK_M_PHYCLK_CHG 0x02 279 + #define MASK_M_TMDS_CHG 0x01 280 + 281 + #define PACKET_INTM 0x8514 282 + 283 + #define CBIT_INTM 0x8515 284 + #define MASK_M_AF_LOCK 0x80 285 + #define MASK_M_AF_UNLOCK 0x40 286 + #define MASK_M_CBIT_FS 0x02 287 + 288 + #define AUDIO_INTM 0x8516 289 + #define MASK_M_BUFINIT_END 0x01 290 + 291 + #define ERR_INTM 0x8517 292 + #define MASK_M_EESS_ERR 0x80 293 + 294 + #define HDCP_INTM 0x8518 295 + #define MASK_M_AVM_SET 0x80 296 + #define MASK_M_AVM_CLR 0x40 297 + #define MASK_M_LINKERR 0x20 298 + #define MASK_M_SHA_END 0x10 299 + #define MASK_M_R0_END 0x08 300 + #define MASK_M_KM_END 0x04 301 + #define MASK_M_AKSV_END 0x02 302 + #define MASK_M_AN_END 0x01 303 + 304 + #define MISC_INTM 0x851B 305 + #define MASK_M_AS_LAYOUT 0x10 306 + #define MASK_M_NO_SPD 0x08 307 + #define MASK_M_NO_VS 0x03 308 + #define MASK_M_SYNC_CHG 0x02 309 + #define MASK_M_AUDIO_MUTE 0x01 310 + 311 + #define KEY_INTM 0x851F 312 + 313 + #define SYS_STATUS 0x8520 314 + #define MASK_S_SYNC 0x80 315 + #define MASK_S_AVMUTE 0x40 316 + #define MASK_S_HDCP 0x20 317 + #define MASK_S_HDMI 0x10 318 + #define MASK_S_PHY_SCDT 0x08 319 + #define MASK_S_PHY_PLL 0x04 320 + #define MASK_S_TMDS 0x02 321 + #define MASK_S_DDC5V 0x01 322 + 323 + #define CSI_STATUS 0x0410 324 + #define MASK_S_WSYNC 0x0400 325 + #define MASK_S_TXACT 0x0200 326 + #define MASK_S_RXACT 0x0100 327 + #define MASK_S_HLT 0x0001 328 + 329 + #define VI_STATUS1 0x8522 330 + #define MASK_S_V_GBD 0x08 331 + #define MASK_S_DEEPCOLOR 0x0c 332 + #define MASK_S_V_422 0x02 333 + #define MASK_S_V_INTERLACE 0x01 334 + 335 + #define AU_STATUS0 0x8523 336 + #define MASK_S_A_SAMPLE 0x01 337 + 338 + #define VI_STATUS3 0x8528 339 + #define MASK_S_V_COLOR 0x1e 340 + #define MASK_LIMITED 0x01 341 + 342 + #define PHY_CTL0 0x8531 343 + #define MASK_PHY_SYSCLK_IND 0x02 344 + #define MASK_PHY_CTL 0x01 345 + 346 + 347 + #define PHY_CTL1 0x8532 /* Not in REF_01 */ 348 + #define MASK_PHY_AUTO_RST1 0xf0 349 + #define MASK_PHY_AUTO_RST1_OFF 0x00 350 + #define SET_PHY_AUTO_RST1_US(us) ((((us) / 200) << 4) & \ 351 + MASK_PHY_AUTO_RST1) 352 + #define MASK_FREQ_RANGE_MODE 0x0f 353 + #define SET_FREQ_RANGE_MODE_CYCLES(cycles) (((cycles) - 1) & \ 354 + MASK_FREQ_RANGE_MODE) 355 + 356 + #define PHY_CTL2 0x8533 /* Not in REF_01 */ 357 + #define MASK_PHY_AUTO_RST4 0x04 358 + #define MASK_PHY_AUTO_RST3 0x02 359 + #define MASK_PHY_AUTO_RST2 0x01 360 + #define MASK_PHY_AUTO_RSTn (MASK_PHY_AUTO_RST4 | \ 361 + MASK_PHY_AUTO_RST3 | \ 362 + MASK_PHY_AUTO_RST2) 363 + 364 + #define PHY_EN 0x8534 365 + #define MASK_ENABLE_PHY 0x01 366 + 367 + #define PHY_RST 0x8535 368 + #define MASK_RESET_CTRL 0x01 /* Reset active low */ 369 + 370 + #define PHY_BIAS 0x8536 /* Not in REF_01 */ 371 + 372 + #define PHY_CSQ 0x853F /* Not in REF_01 */ 373 + #define MASK_CSQ_CNT 0x0f 374 + #define SET_CSQ_CNT_LEVEL(n) (n & MASK_CSQ_CNT) 375 + 376 + #define SYS_FREQ0 0x8540 377 + #define SYS_FREQ1 0x8541 378 + 379 + #define SYS_CLK 0x8542 /* Not in REF_01 */ 380 + #define MASK_CLK_DIFF 0x0C 381 + #define MASK_CLK_DIV 0x03 382 + 383 + #define DDC_CTL 0x8543 384 + #define MASK_DDC_ACK_POL 0x08 385 + #define MASK_DDC_ACTION 0x04 386 + #define MASK_DDC5V_MODE 0x03 387 + #define MASK_DDC5V_MODE_0MS 0x00 388 + #define MASK_DDC5V_MODE_50MS 0x01 389 + #define MASK_DDC5V_MODE_100MS 0x02 390 + #define MASK_DDC5V_MODE_200MS 0x03 391 + 392 + #define HPD_CTL 0x8544 393 + #define MASK_HPD_CTL0 0x10 394 + #define MASK_HPD_OUT0 0x01 395 + 396 + #define ANA_CTL 0x8545 397 + #define MASK_APPL_PCSX 0x30 398 + #define MASK_APPL_PCSX_HIZ 0x00 399 + #define MASK_APPL_PCSX_L_FIX 0x10 400 + #define MASK_APPL_PCSX_H_FIX 0x20 401 + #define MASK_APPL_PCSX_NORMAL 0x30 402 + #define MASK_ANALOG_ON 0x01 403 + 404 + #define AVM_CTL 0x8546 405 + 406 + #define INIT_END 0x854A 407 + #define MASK_INIT_END 0x01 408 + 409 + #define HDMI_DET 0x8552 /* Not in REF_01 */ 410 + #define MASK_HDMI_DET_MOD1 0x80 411 + #define MASK_HDMI_DET_MOD0 0x40 412 + #define MASK_HDMI_DET_V 0x30 413 + #define MASK_HDMI_DET_V_SYNC 0x00 414 + #define MASK_HDMI_DET_V_ASYNC_25MS 0x10 415 + #define MASK_HDMI_DET_V_ASYNC_50MS 0x20 416 + #define MASK_HDMI_DET_V_ASYNC_100MS 0x30 417 + #define MASK_HDMI_DET_NUM 0x0f 418 + 419 + #define HDCP_MODE 0x8560 420 + #define MASK_MODE_RST_TN 0x20 421 + #define MASK_LINE_REKEY 0x10 422 + #define MASK_AUTO_CLR 0x04 423 + 424 + #define HDCP_REG1 0x8563 /* Not in REF_01 */ 425 + #define MASK_AUTH_UNAUTH_SEL 0x70 426 + #define MASK_AUTH_UNAUTH_SEL_12_FRAMES 0x70 427 + #define MASK_AUTH_UNAUTH_SEL_8_FRAMES 0x60 428 + #define MASK_AUTH_UNAUTH_SEL_4_FRAMES 0x50 429 + #define MASK_AUTH_UNAUTH_SEL_2_FRAMES 0x40 430 + #define MASK_AUTH_UNAUTH_SEL_64_FRAMES 0x30 431 + #define MASK_AUTH_UNAUTH_SEL_32_FRAMES 0x20 432 + #define MASK_AUTH_UNAUTH_SEL_16_FRAMES 0x10 433 + #define MASK_AUTH_UNAUTH_SEL_ONCE 0x00 434 + #define MASK_AUTH_UNAUTH 0x01 435 + #define MASK_AUTH_UNAUTH_AUTO 0x01 436 + 437 + #define HDCP_REG2 0x8564 /* Not in REF_01 */ 438 + #define MASK_AUTO_P3_RESET 0x0F 439 + #define SET_AUTO_P3_RESET_FRAMES(n) (n & MASK_AUTO_P3_RESET) 440 + #define MASK_AUTO_P3_RESET_OFF 0x00 441 + 442 + #define VI_MODE 0x8570 443 + #define MASK_RGB_DVI 0x08 /* Not in REF_01 */ 444 + 445 + #define VOUT_SET2 0x8573 446 + #define MASK_SEL422 0x80 447 + #define MASK_VOUT_422FIL_100 0x40 448 + #define MASK_VOUTCOLORMODE 0x03 449 + #define MASK_VOUTCOLORMODE_THROUGH 0x00 450 + #define MASK_VOUTCOLORMODE_AUTO 0x01 451 + #define MASK_VOUTCOLORMODE_MANUAL 0x03 452 + 453 + #define VOUT_SET3 0x8574 454 + #define MASK_VOUT_EXTCNT 0x08 455 + 456 + #define VI_REP 0x8576 457 + #define MASK_VOUT_COLOR_SEL 0xe0 458 + #define MASK_VOUT_COLOR_RGB_FULL 0x00 459 + #define MASK_VOUT_COLOR_RGB_LIMITED 0x20 460 + #define MASK_VOUT_COLOR_601_YCBCR_FULL 0x40 461 + #define MASK_VOUT_COLOR_601_YCBCR_LIMITED 0x60 462 + #define MASK_VOUT_COLOR_709_YCBCR_FULL 0x80 463 + #define MASK_VOUT_COLOR_709_YCBCR_LIMITED 0xa0 464 + #define MASK_VOUT_COLOR_FULL_TO_LIMITED 0xc0 465 + #define MASK_VOUT_COLOR_LIMITED_TO_FULL 0xe0 466 + #define MASK_IN_REP_HEN 0x10 467 + #define MASK_IN_REP 0x0f 468 + 469 + #define VI_MUTE 0x857F 470 + #define MASK_AUTO_MUTE 0xc0 471 + #define MASK_VI_MUTE 0x10 472 + 473 + #define DE_WIDTH_H_LO 0x8582 /* Not in REF_01 */ 474 + #define DE_WIDTH_H_HI 0x8583 /* Not in REF_01 */ 475 + #define DE_WIDTH_V_LO 0x8588 /* Not in REF_01 */ 476 + #define DE_WIDTH_V_HI 0x8589 /* Not in REF_01 */ 477 + #define H_SIZE_LO 0x858A /* Not in REF_01 */ 478 + #define H_SIZE_HI 0x858B /* Not in REF_01 */ 479 + #define V_SIZE_LO 0x858C /* Not in REF_01 */ 480 + #define V_SIZE_HI 0x858D /* Not in REF_01 */ 481 + #define FV_CNT_LO 0x85A1 /* Not in REF_01 */ 482 + #define FV_CNT_HI 0x85A2 /* Not in REF_01 */ 483 + 484 + #define FH_MIN0 0x85AA /* Not in REF_01 */ 485 + #define FH_MIN1 0x85AB /* Not in REF_01 */ 486 + #define FH_MAX0 0x85AC /* Not in REF_01 */ 487 + #define FH_MAX1 0x85AD /* Not in REF_01 */ 488 + 489 + #define HV_RST 0x85AF /* Not in REF_01 */ 490 + #define MASK_H_PI_RST 0x20 491 + #define MASK_V_PI_RST 0x10 492 + 493 + #define EDID_MODE 0x85C7 494 + #define MASK_EDID_SPEED 0x40 495 + #define MASK_EDID_MODE 0x03 496 + #define MASK_EDID_MODE_DISABLE 0x00 497 + #define MASK_EDID_MODE_DDC2B 0x01 498 + #define MASK_EDID_MODE_E_DDC 0x02 499 + 500 + #define EDID_LEN1 0x85CA 501 + #define EDID_LEN2 0x85CB 502 + 503 + #define HDCP_REG3 0x85D1 /* Not in REF_01 */ 504 + #define KEY_RD_CMD 0x01 505 + 506 + #define FORCE_MUTE 0x8600 507 + #define MASK_FORCE_AMUTE 0x10 508 + #define MASK_FORCE_DMUTE 0x01 509 + 510 + #define CMD_AUD 0x8601 511 + #define MASK_CMD_BUFINIT 0x04 512 + #define MASK_CMD_LOCKDET 0x02 513 + #define MASK_CMD_MUTE 0x01 514 + 515 + #define AUTO_CMD0 0x8602 516 + #define MASK_AUTO_MUTE7 0x80 517 + #define MASK_AUTO_MUTE6 0x40 518 + #define MASK_AUTO_MUTE5 0x20 519 + #define MASK_AUTO_MUTE4 0x10 520 + #define MASK_AUTO_MUTE3 0x08 521 + #define MASK_AUTO_MUTE2 0x04 522 + #define MASK_AUTO_MUTE1 0x02 523 + #define MASK_AUTO_MUTE0 0x01 524 + 525 + #define AUTO_CMD1 0x8603 526 + #define MASK_AUTO_MUTE10 0x04 527 + #define MASK_AUTO_MUTE9 0x02 528 + #define MASK_AUTO_MUTE8 0x01 529 + 530 + #define AUTO_CMD2 0x8604 531 + #define MASK_AUTO_PLAY3 0x08 532 + #define MASK_AUTO_PLAY2 0x04 533 + 534 + #define BUFINIT_START 0x8606 535 + #define SET_BUFINIT_START_MS(milliseconds) ((milliseconds) / 100) 536 + 537 + #define FS_MUTE 0x8607 538 + #define MASK_FS_ELSE_MUTE 0x80 539 + #define MASK_FS22_MUTE 0x40 540 + #define MASK_FS24_MUTE 0x20 541 + #define MASK_FS88_MUTE 0x10 542 + #define MASK_FS96_MUTE 0x08 543 + #define MASK_FS176_MUTE 0x04 544 + #define MASK_FS192_MUTE 0x02 545 + #define MASK_FS_NO_MUTE 0x01 546 + 547 + #define FS_IMODE 0x8620 548 + #define MASK_NLPCM_HMODE 0x40 549 + #define MASK_NLPCM_SMODE 0x20 550 + #define MASK_NLPCM_IMODE 0x10 551 + #define MASK_FS_HMODE 0x08 552 + #define MASK_FS_AMODE 0x04 553 + #define MASK_FS_SMODE 0x02 554 + #define MASK_FS_IMODE 0x01 555 + 556 + #define FS_SET 0x8621 557 + #define MASK_FS 0x0f 558 + 559 + #define LOCKDET_REF0 0x8630 560 + #define LOCKDET_REF1 0x8631 561 + #define LOCKDET_REF2 0x8632 562 + 563 + #define ACR_MODE 0x8640 564 + #define MASK_ACR_LOAD 0x10 565 + #define MASK_N_MODE 0x04 566 + #define MASK_CTS_MODE 0x01 567 + 568 + #define ACR_MDF0 0x8641 569 + #define MASK_ACR_L2MDF 0x70 570 + #define MASK_ACR_L2MDF_0_PPM 0x00 571 + #define MASK_ACR_L2MDF_61_PPM 0x10 572 + #define MASK_ACR_L2MDF_122_PPM 0x20 573 + #define MASK_ACR_L2MDF_244_PPM 0x30 574 + #define MASK_ACR_L2MDF_488_PPM 0x40 575 + #define MASK_ACR_L2MDF_976_PPM 0x50 576 + #define MASK_ACR_L2MDF_1976_PPM 0x60 577 + #define MASK_ACR_L2MDF_3906_PPM 0x70 578 + #define MASK_ACR_L1MDF 0x07 579 + #define MASK_ACR_L1MDF_0_PPM 0x00 580 + #define MASK_ACR_L1MDF_61_PPM 0x01 581 + #define MASK_ACR_L1MDF_122_PPM 0x02 582 + #define MASK_ACR_L1MDF_244_PPM 0x03 583 + #define MASK_ACR_L1MDF_488_PPM 0x04 584 + #define MASK_ACR_L1MDF_976_PPM 0x05 585 + #define MASK_ACR_L1MDF_1976_PPM 0x06 586 + #define MASK_ACR_L1MDF_3906_PPM 0x07 587 + 588 + #define ACR_MDF1 0x8642 589 + #define MASK_ACR_L3MDF 0x07 590 + #define MASK_ACR_L3MDF_0_PPM 0x00 591 + #define MASK_ACR_L3MDF_61_PPM 0x01 592 + #define MASK_ACR_L3MDF_122_PPM 0x02 593 + #define MASK_ACR_L3MDF_244_PPM 0x03 594 + #define MASK_ACR_L3MDF_488_PPM 0x04 595 + #define MASK_ACR_L3MDF_976_PPM 0x05 596 + #define MASK_ACR_L3MDF_1976_PPM 0x06 597 + #define MASK_ACR_L3MDF_3906_PPM 0x07 598 + 599 + #define SDO_MODE1 0x8652 600 + #define MASK_SDO_BIT_LENG 0x70 601 + #define MASK_SDO_FMT 0x03 602 + #define MASK_SDO_FMT_RIGHT 0x00 603 + #define MASK_SDO_FMT_LEFT 0x01 604 + #define MASK_SDO_FMT_I2S 0x02 605 + 606 + #define DIV_MODE 0x8665 /* Not in REF_01 */ 607 + #define MASK_DIV_DLY 0xf0 608 + #define SET_DIV_DLY_MS(milliseconds) ((((milliseconds) / 100) << 4) & \ 609 + MASK_DIV_DLY) 610 + #define MASK_DIV_MODE 0x01 611 + 612 + #define NCO_F0_MOD 0x8670 613 + #define MASK_NCO_F0_MOD 0x03 614 + #define MASK_NCO_F0_MOD_42MHZ 0x00 615 + #define MASK_NCO_F0_MOD_27MHZ 0x01 616 + 617 + #define PK_INT_MODE 0x8709 618 + #define MASK_ISRC2_INT_MODE 0x80 619 + #define MASK_ISRC_INT_MODE 0x40 620 + #define MASK_ACP_INT_MODE 0x20 621 + #define MASK_VS_INT_MODE 0x10 622 + #define MASK_SPD_INT_MODE 0x08 623 + #define MASK_MS_INT_MODE 0x04 624 + #define MASK_AUD_INT_MODE 0x02 625 + #define MASK_AVI_INT_MODE 0x01 626 + 627 + #define NO_PKT_LIMIT 0x870B 628 + #define MASK_NO_ACP_LIMIT 0xf0 629 + #define SET_NO_ACP_LIMIT_MS(milliseconds) ((((milliseconds) / 80) << 4) & \ 630 + MASK_NO_ACP_LIMIT) 631 + #define MASK_NO_AVI_LIMIT 0x0f 632 + #define SET_NO_AVI_LIMIT_MS(milliseconds) (((milliseconds) / 80) & \ 633 + MASK_NO_AVI_LIMIT) 634 + 635 + #define NO_PKT_CLR 0x870C 636 + #define MASK_NO_VS_CLR 0x40 637 + #define MASK_NO_SPD_CLR 0x20 638 + #define MASK_NO_ACP_CLR 0x10 639 + #define MASK_NO_AVI_CLR1 0x02 640 + #define MASK_NO_AVI_CLR0 0x01 641 + 642 + #define ERR_PK_LIMIT 0x870D 643 + #define NO_PKT_LIMIT2 0x870E 644 + #define PK_AVI_0HEAD 0x8710 645 + #define PK_AVI_1HEAD 0x8711 646 + #define PK_AVI_2HEAD 0x8712 647 + #define PK_AVI_0BYTE 0x8713 648 + #define PK_AVI_1BYTE 0x8714 649 + #define PK_AVI_2BYTE 0x8715 650 + #define PK_AVI_3BYTE 0x8716 651 + #define PK_AVI_4BYTE 0x8717 652 + #define PK_AVI_5BYTE 0x8718 653 + #define PK_AVI_6BYTE 0x8719 654 + #define PK_AVI_7BYTE 0x871A 655 + #define PK_AVI_8BYTE 0x871B 656 + #define PK_AVI_9BYTE 0x871C 657 + #define PK_AVI_10BYTE 0x871D 658 + #define PK_AVI_11BYTE 0x871E 659 + #define PK_AVI_12BYTE 0x871F 660 + #define PK_AVI_13BYTE 0x8720 661 + #define PK_AVI_14BYTE 0x8721 662 + #define PK_AVI_15BYTE 0x8722 663 + #define PK_AVI_16BYTE 0x8723 664 + 665 + #define BKSV 0x8800 666 + 667 + #define BCAPS 0x8840 668 + #define MASK_HDMI_RSVD 0x80 669 + #define MASK_REPEATER 0x40 670 + #define MASK_READY 0x20 671 + #define MASK_FASTI2C 0x10 672 + #define MASK_1_1_FEA 0x02 673 + #define MASK_FAST_REAU 0x01 674 + 675 + #define BSTATUS1 0x8842 676 + #define MASK_MAX_EXCED 0x08 677 + 678 + #define EDID_RAM 0x8C00 679 + #define NO_GDB_LIMIT 0x9007 680 + 681 + #endif
-8
drivers/media/i2c/tda7432.c
··· 331 331 332 332 static const struct v4l2_subdev_core_ops tda7432_core_ops = { 333 333 .log_status = tda7432_log_status, 334 - .g_ext_ctrls = v4l2_subdev_g_ext_ctrls, 335 - .try_ext_ctrls = v4l2_subdev_try_ext_ctrls, 336 - .s_ext_ctrls = v4l2_subdev_s_ext_ctrls, 337 - .g_ctrl = v4l2_subdev_g_ctrl, 338 - .s_ctrl = v4l2_subdev_s_ctrl, 339 - .queryctrl = v4l2_subdev_queryctrl, 340 - .querymenu = v4l2_subdev_querymenu, 341 334 }; 342 335 343 336 static const struct v4l2_subdev_ops tda7432_ops = { ··· 409 416 410 417 static struct i2c_driver tda7432_driver = { 411 418 .driver = { 412 - .owner = THIS_MODULE, 413 419 .name = "tda7432", 414 420 }, 415 421 .probe = tda7432_probe,
-1
drivers/media/i2c/tda9840.c
··· 199 199 200 200 static struct i2c_driver tda9840_driver = { 201 201 .driver = { 202 - .owner = THIS_MODULE, 203 202 .name = "tda9840", 204 203 }, 205 204 .probe = tda9840_probe,
-1
drivers/media/i2c/tea6415c.c
··· 162 162 163 163 static struct i2c_driver tea6415c_driver = { 164 164 .driver = { 165 - .owner = THIS_MODULE, 166 165 .name = "tea6415c", 167 166 }, 168 167 .probe = tea6415c_probe,
-1
drivers/media/i2c/tea6420.c
··· 144 144 145 145 static struct i2c_driver tea6420_driver = { 146 146 .driver = { 147 - .owner = THIS_MODULE, 148 147 .name = "tea6420", 149 148 }, 150 149 .probe = tea6420_probe,
-1
drivers/media/i2c/ths7303.c
··· 377 377 378 378 static struct i2c_driver ths7303_driver = { 379 379 .driver = { 380 - .owner = THIS_MODULE, 381 380 .name = "ths73x3", 382 381 }, 383 382 .probe = ths7303_probe,
-7
drivers/media/i2c/tlv320aic23b.c
··· 122 122 123 123 static const struct v4l2_subdev_core_ops tlv320aic23b_core_ops = { 124 124 .log_status = tlv320aic23b_log_status, 125 - .g_ext_ctrls = v4l2_subdev_g_ext_ctrls, 126 - .try_ext_ctrls = v4l2_subdev_try_ext_ctrls, 127 - .s_ext_ctrls = v4l2_subdev_s_ext_ctrls, 128 - .g_ctrl = v4l2_subdev_g_ctrl, 129 - .s_ctrl = v4l2_subdev_s_ctrl, 130 - .queryctrl = v4l2_subdev_queryctrl, 131 - .querymenu = v4l2_subdev_querymenu, 132 125 }; 133 126 134 127 static const struct v4l2_subdev_audio_ops tlv320aic23b_audio_ops = {
-1
drivers/media/i2c/tvaudio.c
··· 2051 2051 2052 2052 static struct i2c_driver tvaudio_driver = { 2053 2053 .driver = { 2054 - .owner = THIS_MODULE, 2055 2054 .name = "tvaudio", 2056 2055 }, 2057 2056 .probe = tvaudio_probe,
-11
drivers/media/i2c/tvp514x.c
··· 957 957 return 0; 958 958 } 959 959 960 - static const struct v4l2_subdev_core_ops tvp514x_core_ops = { 961 - .g_ext_ctrls = v4l2_subdev_g_ext_ctrls, 962 - .try_ext_ctrls = v4l2_subdev_try_ext_ctrls, 963 - .s_ext_ctrls = v4l2_subdev_s_ext_ctrls, 964 - .g_ctrl = v4l2_subdev_g_ctrl, 965 - .s_ctrl = v4l2_subdev_s_ctrl, 966 - .queryctrl = v4l2_subdev_queryctrl, 967 - .querymenu = v4l2_subdev_querymenu, 968 - }; 969 - 970 960 static const struct v4l2_subdev_video_ops tvp514x_video_ops = { 971 961 .s_std = tvp514x_s_std, 972 962 .s_routing = tvp514x_s_routing, ··· 973 983 }; 974 984 975 985 static const struct v4l2_subdev_ops tvp514x_ops = { 976 - .core = &tvp514x_core_ops, 977 986 .video = &tvp514x_video_ops, 978 987 .pad = &tvp514x_pad_ops, 979 988 };
-1
drivers/media/i2c/tvp5150.c
··· 1215 1215 1216 1216 static struct i2c_driver tvp5150_driver = { 1217 1217 .driver = { 1218 - .owner = THIS_MODULE, 1219 1218 .name = "tvp5150", 1220 1219 }, 1221 1220 .probe = tvp5150_probe,
-7
drivers/media/i2c/tvp7002.c
··· 861 861 /* V4L2 core operation handlers */ 862 862 static const struct v4l2_subdev_core_ops tvp7002_core_ops = { 863 863 .log_status = tvp7002_log_status, 864 - .g_ext_ctrls = v4l2_subdev_g_ext_ctrls, 865 - .try_ext_ctrls = v4l2_subdev_try_ext_ctrls, 866 - .s_ext_ctrls = v4l2_subdev_s_ext_ctrls, 867 - .g_ctrl = v4l2_subdev_g_ctrl, 868 - .s_ctrl = v4l2_subdev_s_ctrl, 869 - .queryctrl = v4l2_subdev_queryctrl, 870 - .querymenu = v4l2_subdev_querymenu, 871 864 #ifdef CONFIG_VIDEO_ADV_DEBUG 872 865 .g_register = tvp7002_g_register, 873 866 .s_register = tvp7002_s_register,
-1
drivers/media/i2c/tw9903.c
··· 266 266 267 267 static struct i2c_driver tw9903_driver = { 268 268 .driver = { 269 - .owner = THIS_MODULE, 270 269 .name = "tw9903", 271 270 }, 272 271 .probe = tw9903_probe,
-1
drivers/media/i2c/tw9906.c
··· 234 234 235 235 static struct i2c_driver tw9906_driver = { 236 236 .driver = { 237 - .owner = THIS_MODULE, 238 237 .name = "tw9906", 239 238 }, 240 239 .probe = tw9906_probe,
-1
drivers/media/i2c/upd64031a.c
··· 241 241 242 242 static struct i2c_driver upd64031a_driver = { 243 243 .driver = { 244 - .owner = THIS_MODULE, 245 244 .name = "upd64031a", 246 245 }, 247 246 .probe = upd64031a_probe,
-1
drivers/media/i2c/upd64083.c
··· 213 213 214 214 static struct i2c_driver upd64083_driver = { 215 215 .driver = { 216 - .owner = THIS_MODULE, 217 216 .name = "upd64083", 218 217 }, 219 218 .probe = upd64083_probe,
-1
drivers/media/i2c/vp27smpx.c
··· 194 194 195 195 static struct i2c_driver vp27smpx_driver = { 196 196 .driver = { 197 - .owner = THIS_MODULE, 198 197 .name = "vp27smpx", 199 198 }, 200 199 .probe = vp27smpx_probe,
-8
drivers/media/i2c/vpx3220.c
··· 450 450 451 451 static const struct v4l2_subdev_core_ops vpx3220_core_ops = { 452 452 .init = vpx3220_init, 453 - .g_ext_ctrls = v4l2_subdev_g_ext_ctrls, 454 - .try_ext_ctrls = v4l2_subdev_try_ext_ctrls, 455 - .s_ext_ctrls = v4l2_subdev_s_ext_ctrls, 456 - .g_ctrl = v4l2_subdev_g_ctrl, 457 - .s_ctrl = v4l2_subdev_s_ctrl, 458 - .queryctrl = v4l2_subdev_queryctrl, 459 - .querymenu = v4l2_subdev_querymenu, 460 453 }; 461 454 462 455 static const struct v4l2_subdev_video_ops vpx3220_video_ops = { ··· 560 567 561 568 static struct i2c_driver vpx3220_driver = { 562 569 .driver = { 563 - .owner = THIS_MODULE, 564 570 .name = "vpx3220", 565 571 }, 566 572 .probe = vpx3220_probe,
-8
drivers/media/i2c/wm8739.c
··· 176 176 177 177 static const struct v4l2_subdev_core_ops wm8739_core_ops = { 178 178 .log_status = wm8739_log_status, 179 - .g_ext_ctrls = v4l2_subdev_g_ext_ctrls, 180 - .try_ext_ctrls = v4l2_subdev_try_ext_ctrls, 181 - .s_ext_ctrls = v4l2_subdev_s_ext_ctrls, 182 - .g_ctrl = v4l2_subdev_g_ctrl, 183 - .s_ctrl = v4l2_subdev_s_ctrl, 184 - .queryctrl = v4l2_subdev_queryctrl, 185 - .querymenu = v4l2_subdev_querymenu, 186 179 }; 187 180 188 181 static const struct v4l2_subdev_audio_ops wm8739_audio_ops = { ··· 265 272 266 273 static struct i2c_driver wm8739_driver = { 267 274 .driver = { 268 - .owner = THIS_MODULE, 269 275 .name = "wm8739", 270 276 }, 271 277 .probe = wm8739_probe,
-1
drivers/media/i2c/wm8775.c
··· 318 318 319 319 static struct i2c_driver wm8775_driver = { 320 320 .driver = { 321 - .owner = THIS_MODULE, 322 321 .name = "wm8775", 323 322 }, 324 323 .probe = wm8775_probe,
+3 -3
drivers/media/media-entity.c
··· 282 282 if (ret < 0 && ret != -ENOIOCTLCMD) { 283 283 dev_dbg(entity->parent->dev, 284 284 "link validation failed for \"%s\":%u -> \"%s\":%u, error %d\n", 285 - entity->name, link->source->index, 286 - link->sink->entity->name, 287 - link->sink->index, ret); 285 + link->source->entity->name, 286 + link->source->index, 287 + entity->name, link->sink->index, ret); 288 288 goto error; 289 289 } 290 290 }
+4 -3
drivers/media/pci/Kconfig
··· 11 11 if MEDIA_CAMERA_SUPPORT 12 12 comment "Media capture support" 13 13 source "drivers/media/pci/meye/Kconfig" 14 + source "drivers/media/pci/solo6x10/Kconfig" 14 15 source "drivers/media/pci/sta2x11/Kconfig" 16 + source "drivers/media/pci/tw68/Kconfig" 17 + source "drivers/media/pci/zoran/Kconfig" 15 18 endif 16 19 17 20 if MEDIA_ANALOG_TV_SUPPORT 18 21 comment "Media capture/analog TV support" 19 22 source "drivers/media/pci/ivtv/Kconfig" 20 - source "drivers/media/pci/zoran/Kconfig" 21 23 source "drivers/media/pci/saa7146/Kconfig" 22 - source "drivers/media/pci/solo6x10/Kconfig" 23 - source "drivers/media/pci/tw68/Kconfig" 24 24 source "drivers/media/pci/dt3155/Kconfig" 25 25 endif 26 26 ··· 49 49 source "drivers/media/pci/ngene/Kconfig" 50 50 source "drivers/media/pci/ddbridge/Kconfig" 51 51 source "drivers/media/pci/smipcie/Kconfig" 52 + source "drivers/media/pci/netup_unidvb/Kconfig" 52 53 endif 53 54 54 55 endif #MEDIA_PCI_SUPPORT
+2 -1
drivers/media/pci/Makefile
··· 12 12 ngene/ \ 13 13 ddbridge/ \ 14 14 saa7146/ \ 15 - smipcie/ 15 + smipcie/ \ 16 + netup_unidvb/ 16 17 17 18 obj-$(CONFIG_VIDEO_IVTV) += ivtv/ 18 19 obj-$(CONFIG_VIDEO_ZORAN) += zoran/
+1 -4
drivers/media/pci/bt8xx/btcx-risc.c
··· 160 160 void 161 161 btcx_sort_clips(struct v4l2_clip *clips, unsigned int nclips) 162 162 { 163 - struct v4l2_clip swap; 164 163 int i,j,n; 165 164 166 165 if (nclips < 2) ··· 167 168 for (i = nclips-2; i >= 0; i--) { 168 169 for (n = 0, j = 0; j <= i; j++) { 169 170 if (clips[j].c.left > clips[j+1].c.left) { 170 - swap = clips[j]; 171 - clips[j] = clips[j+1]; 172 - clips[j+1] = swap; 171 + swap(clips[j], clips[j + 1]); 173 172 n++; 174 173 } 175 174 }
+8 -13
drivers/media/pci/bt8xx/bttv-input.c
··· 194 194 static void bttv_rc5_timer_end(unsigned long data) 195 195 { 196 196 struct bttv_ir *ir = (struct bttv_ir *)data; 197 - struct timeval tv; 197 + ktime_t tv; 198 198 u32 gap, rc5, scancode; 199 199 u8 toggle, command, system; 200 200 201 201 /* get time */ 202 - do_gettimeofday(&tv); 202 + tv = ktime_get(); 203 203 204 + gap = ktime_to_us(ktime_sub(tv, ir->base_time)); 204 205 /* avoid overflow with gap >1s */ 205 - if (tv.tv_sec - ir->base_time.tv_sec > 1) { 206 + if (gap > USEC_PER_SEC) { 206 207 gap = 200000; 207 - } else { 208 - gap = 1000000 * (tv.tv_sec - ir->base_time.tv_sec) + 209 - tv.tv_usec - ir->base_time.tv_usec; 210 208 } 211 - 212 209 /* signal we're ready to start a new code */ 213 210 ir->active = false; 214 211 ··· 246 249 static int bttv_rc5_irq(struct bttv *btv) 247 250 { 248 251 struct bttv_ir *ir = btv->remote; 249 - struct timeval tv; 252 + ktime_t tv; 250 253 u32 gpio; 251 254 u32 gap; 252 255 unsigned long current_jiffies; ··· 256 259 257 260 /* get time of bit */ 258 261 current_jiffies = jiffies; 259 - do_gettimeofday(&tv); 262 + tv = ktime_get(); 260 263 264 + gap = ktime_to_us(ktime_sub(tv, ir->base_time)); 261 265 /* avoid overflow with gap >1s */ 262 - if (tv.tv_sec - ir->base_time.tv_sec > 1) { 266 + if (gap > USEC_PER_SEC) { 263 267 gap = 200000; 264 - } else { 265 - gap = 1000000 * (tv.tv_sec - ir->base_time.tv_sec) + 266 - tv.tv_usec - ir->base_time.tv_usec; 267 268 } 268 269 269 270 dprintk("RC5 IRQ: gap %d us for %s\n",
+1 -1
drivers/media/pci/bt8xx/bttvp.h
··· 140 140 bool rc5_gpio; /* Is RC5 legacy GPIO enabled? */ 141 141 u32 last_bit; /* last raw bit seen */ 142 142 u32 code; /* raw code under construction */ 143 - struct timeval base_time; /* time of last seen code */ 143 + ktime_t base_time; /* time of last seen code */ 144 144 bool active; /* building raw code */ 145 145 }; 146 146
+2 -1
drivers/media/pci/cobalt/Kconfig
··· 1 1 config VIDEO_COBALT 2 2 tristate "Cisco Cobalt support" 3 3 depends on VIDEO_V4L2 && I2C && MEDIA_CONTROLLER 4 - depends on PCI_MSI && MTD_COMPLEX_MAPPINGS && GPIOLIB 4 + depends on PCI_MSI && MTD_COMPLEX_MAPPINGS 5 + depends on GPIOLIB || COMPILE_TEST 5 6 depends on SND 6 7 select I2C_ALGOBIT 7 8 select VIDEO_ADV7604
+6 -5
drivers/media/pci/cobalt/cobalt-driver.c
··· 339 339 } 340 340 341 341 if (pcie_link_get_lanes(cobalt) != 8) { 342 - cobalt_err("PCI Express link width is not 8 lanes (%d)\n", 342 + cobalt_warn("PCI Express link width is %d lanes.\n", 343 343 pcie_link_get_lanes(cobalt)); 344 344 if (pcie_bus_link_get_lanes(cobalt) < 8) 345 - cobalt_err("The current slot only supports %d lanes, at least 8 are needed\n", 345 + cobalt_warn("The current slot only supports %d lanes, for best performance 8 are needed\n", 346 346 pcie_bus_link_get_lanes(cobalt)); 347 - else 347 + if (pcie_link_get_lanes(cobalt) != pcie_bus_link_get_lanes(cobalt)) { 348 348 cobalt_err("The card is most likely not seated correctly in the PCIe slot\n"); 349 - ret = -EIO; 350 - goto err_disable; 349 + ret = -EIO; 350 + goto err_disable; 351 + } 351 352 } 352 353 353 354 if (pci_set_dma_mask(pci_dev, DMA_BIT_MASK(64))) {
+8 -3
drivers/media/pci/cobalt/cobalt-v4l2.c
··· 28 28 29 29 #include <media/v4l2-ctrls.h> 30 30 #include <media/v4l2-event.h> 31 + #include <media/v4l2-dv-timings.h> 31 32 #include <media/adv7604.h> 32 33 #include <media/adv7842.h> 33 34 ··· 642 641 struct cobalt_stream *s = video_drvdata(file); 643 642 int err; 644 643 645 - if (vb2_is_busy(&s->q)) 646 - return -EBUSY; 647 - 648 644 if (s->input == 1) { 649 645 *timings = cea1080p60; 650 646 return 0; 651 647 } 648 + 649 + if (v4l2_match_dv_timings(timings, &s->timings, 0)) 650 + return 0; 651 + 652 + if (vb2_is_busy(&s->q)) 653 + return -EBUSY; 654 + 652 655 err = v4l2_subdev_call(s->sd, 653 656 video, s_dv_timings, timings); 654 657 if (!err) {
-7
drivers/media/pci/ivtv/ivtv-gpio.c
··· 313 313 314 314 static const struct v4l2_subdev_core_ops subdev_core_ops = { 315 315 .log_status = subdev_log_status, 316 - .g_ext_ctrls = v4l2_subdev_g_ext_ctrls, 317 - .try_ext_ctrls = v4l2_subdev_try_ext_ctrls, 318 - .s_ext_ctrls = v4l2_subdev_s_ext_ctrls, 319 - .g_ctrl = v4l2_subdev_g_ctrl, 320 - .s_ctrl = v4l2_subdev_s_ctrl, 321 - .queryctrl = v4l2_subdev_queryctrl, 322 - .querymenu = v4l2_subdev_querymenu, 323 316 }; 324 317 325 318 static const struct v4l2_subdev_tuner_ops subdev_tuner_ops = {
+1 -3
drivers/media/pci/mantis/mantis_dma.c
··· 140 140 /* Stop RISC Engine */ 141 141 mmwrite(0, MANTIS_DMA_CTL); 142 142 143 - goto err; 143 + return err; 144 144 } 145 145 146 146 return 0; 147 - err: 148 - return err; 149 147 } 150 148 EXPORT_SYMBOL_GPL(mantis_dma_init); 151 149
+12
drivers/media/pci/netup_unidvb/Kconfig
··· 1 + config DVB_NETUP_UNIDVB 2 + tristate "NetUP Universal DVB card support" 3 + depends on DVB_CORE && VIDEO_DEV && PCI && I2C && SPI_MASTER 4 + select VIDEOBUF2_DVB 5 + select VIDEOBUF2_VMALLOC 6 + select DVB_HORUS3A if MEDIA_SUBDRV_AUTOSELECT 7 + select DVB_ASCOT2E if MEDIA_SUBDRV_AUTOSELECT 8 + select DVB_LNBH25 if MEDIA_SUBDRV_AUTOSELECT 9 + select DVB_CXD2841ER if MEDIA_SUBDRV_AUTOSELECT 10 + ---help--- 11 + Support for NetUP PCI express Universal DVB card. 12 +
+9
drivers/media/pci/netup_unidvb/Makefile
··· 1 + netup-unidvb-objs += netup_unidvb_core.o 2 + netup-unidvb-objs += netup_unidvb_i2c.o 3 + netup-unidvb-objs += netup_unidvb_ci.o 4 + netup-unidvb-objs += netup_unidvb_spi.o 5 + 6 + obj-$(CONFIG_DVB_NETUP_UNIDVB) += netup-unidvb.o 7 + 8 + ccflags-y += -Idrivers/media/dvb-core 9 + ccflags-y += -Idrivers/media/dvb-frontends
+133
drivers/media/pci/netup_unidvb/netup_unidvb.h
··· 1 + /* 2 + * netup_unidvb.h 3 + * 4 + * Data type definitions for NetUP Universal Dual DVB-CI 5 + * 6 + * Copyright (C) 2014 NetUP Inc. 7 + * Copyright (C) 2014 Sergey Kozlov <serjk@netup.ru> 8 + * Copyright (C) 2014 Abylay Ospan <aospan@netup.ru> 9 + * 10 + * This program is free software; you can redistribute it and/or modify 11 + * it under the terms of the GNU General Public License as published by 12 + * the Free Software Foundation; either version 2 of the License, or 13 + * (at your option) any later version. 14 + * 15 + * This program is distributed in the hope that it will be useful, 16 + * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 + * GNU General Public License for more details. 19 + */ 20 + 21 + #include <linux/pci.h> 22 + #include <linux/i2c.h> 23 + #include <linux/workqueue.h> 24 + #include <media/v4l2-common.h> 25 + #include <media/v4l2-device.h> 26 + #include <media/videobuf2-dvb.h> 27 + #include <dvb_ca_en50221.h> 28 + 29 + #define NETUP_UNIDVB_NAME "netup_unidvb" 30 + #define NETUP_UNIDVB_VERSION "0.0.1" 31 + #define NETUP_VENDOR_ID 0x1b55 32 + #define NETUP_PCI_DEV_REVISION 0x2 33 + 34 + /* IRQ-related regisers */ 35 + #define REG_ISR 0x4890 36 + #define REG_ISR_MASKED 0x4892 37 + #define REG_IMASK_SET 0x4894 38 + #define REG_IMASK_CLEAR 0x4896 39 + /* REG_ISR register bits */ 40 + #define NETUP_UNIDVB_IRQ_SPI (1 << 0) 41 + #define NETUP_UNIDVB_IRQ_I2C0 (1 << 1) 42 + #define NETUP_UNIDVB_IRQ_I2C1 (1 << 2) 43 + #define NETUP_UNIDVB_IRQ_FRA0 (1 << 4) 44 + #define NETUP_UNIDVB_IRQ_FRA1 (1 << 5) 45 + #define NETUP_UNIDVB_IRQ_FRB0 (1 << 6) 46 + #define NETUP_UNIDVB_IRQ_FRB1 (1 << 7) 47 + #define NETUP_UNIDVB_IRQ_DMA1 (1 << 8) 48 + #define NETUP_UNIDVB_IRQ_DMA2 (1 << 9) 49 + #define NETUP_UNIDVB_IRQ_CI (1 << 10) 50 + #define NETUP_UNIDVB_IRQ_CAM0 (1 << 11) 51 + #define NETUP_UNIDVB_IRQ_CAM1 (1 << 12) 52 + 53 + struct netup_dma { 54 + u8 num; 55 + spinlock_t lock; 56 + struct netup_unidvb_dev *ndev; 57 + struct netup_dma_regs *regs; 58 + u32 ring_buffer_size; 59 + u8 *addr_virt; 60 + dma_addr_t addr_phys; 61 + u64 addr_last; 62 + u32 high_addr; 63 + u32 data_offset; 64 + u32 data_size; 65 + struct list_head free_buffers; 66 + struct work_struct work; 67 + struct timer_list timeout; 68 + }; 69 + 70 + enum netup_i2c_state { 71 + STATE_DONE, 72 + STATE_WAIT, 73 + STATE_WANT_READ, 74 + STATE_WANT_WRITE, 75 + STATE_ERROR 76 + }; 77 + 78 + struct netup_i2c_regs; 79 + 80 + struct netup_i2c { 81 + spinlock_t lock; 82 + wait_queue_head_t wq; 83 + struct i2c_adapter adap; 84 + struct netup_unidvb_dev *dev; 85 + struct netup_i2c_regs *regs; 86 + struct i2c_msg *msg; 87 + enum netup_i2c_state state; 88 + u32 xmit_size; 89 + }; 90 + 91 + struct netup_ci_state { 92 + struct dvb_ca_en50221 ca; 93 + u8 __iomem *membase8_config; 94 + u8 __iomem *membase8_io; 95 + struct netup_unidvb_dev *dev; 96 + int status; 97 + int nr; 98 + }; 99 + 100 + struct netup_spi; 101 + 102 + struct netup_unidvb_dev { 103 + struct pci_dev *pci_dev; 104 + int pci_bus; 105 + int pci_slot; 106 + int pci_func; 107 + int board_num; 108 + int old_fw; 109 + u32 __iomem *lmmio0; 110 + u8 __iomem *bmmio0; 111 + u32 __iomem *lmmio1; 112 + u8 __iomem *bmmio1; 113 + u8 *dma_virt; 114 + dma_addr_t dma_phys; 115 + u32 dma_size; 116 + struct vb2_dvb_frontends frontends[2]; 117 + struct netup_i2c i2c[2]; 118 + struct workqueue_struct *wq; 119 + struct netup_dma dma[2]; 120 + struct netup_ci_state ci[2]; 121 + struct netup_spi *spi; 122 + }; 123 + 124 + int netup_i2c_register(struct netup_unidvb_dev *ndev); 125 + void netup_i2c_unregister(struct netup_unidvb_dev *ndev); 126 + irqreturn_t netup_ci_interrupt(struct netup_unidvb_dev *ndev); 127 + irqreturn_t netup_i2c_interrupt(struct netup_i2c *i2c); 128 + irqreturn_t netup_spi_interrupt(struct netup_spi *spi); 129 + int netup_unidvb_ci_register(struct netup_unidvb_dev *dev, 130 + int num, struct pci_dev *pci_dev); 131 + void netup_unidvb_ci_unregister(struct netup_unidvb_dev *dev, int num); 132 + int netup_spi_init(struct netup_unidvb_dev *ndev); 133 + void netup_spi_release(struct netup_unidvb_dev *ndev);
+248
drivers/media/pci/netup_unidvb/netup_unidvb_ci.c
··· 1 + /* 2 + * netup_unidvb_ci.c 3 + * 4 + * DVB CAM support for NetUP Universal Dual DVB-CI 5 + * 6 + * Copyright (C) 2014 NetUP Inc. 7 + * Copyright (C) 2014 Sergey Kozlov <serjk@netup.ru> 8 + * Copyright (C) 2014 Abylay Ospan <aospan@netup.ru> 9 + * 10 + * This program is free software; you can redistribute it and/or modify 11 + * it under the terms of the GNU General Public License as published by 12 + * the Free Software Foundation; either version 2 of the License, or 13 + * (at your option) any later version. 14 + * 15 + * This program is distributed in the hope that it will be useful, 16 + * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 + * GNU General Public License for more details. 19 + */ 20 + 21 + #include <linux/init.h> 22 + #include <linux/module.h> 23 + #include <linux/moduleparam.h> 24 + #include <linux/kmod.h> 25 + #include <linux/kernel.h> 26 + #include <linux/slab.h> 27 + #include <linux/interrupt.h> 28 + #include <linux/delay.h> 29 + #include "netup_unidvb.h" 30 + 31 + /* CI slot 0 base address */ 32 + #define CAM0_CONFIG 0x0 33 + #define CAM0_IO 0x8000 34 + #define CAM0_MEM 0x10000 35 + #define CAM0_SZ 32 36 + /* CI slot 1 base address */ 37 + #define CAM1_CONFIG 0x20000 38 + #define CAM1_IO 0x28000 39 + #define CAM1_MEM 0x30000 40 + #define CAM1_SZ 32 41 + /* ctrlstat registers */ 42 + #define CAM_CTRLSTAT_READ_SET 0x4980 43 + #define CAM_CTRLSTAT_CLR 0x4982 44 + /* register bits */ 45 + #define BIT_CAM_STCHG (1<<0) 46 + #define BIT_CAM_PRESENT (1<<1) 47 + #define BIT_CAM_RESET (1<<2) 48 + #define BIT_CAM_BYPASS (1<<3) 49 + #define BIT_CAM_READY (1<<4) 50 + #define BIT_CAM_ERROR (1<<5) 51 + #define BIT_CAM_OVERCURR (1<<6) 52 + /* BIT_CAM_BYPASS bit shift for SLOT 1 */ 53 + #define CAM1_SHIFT 8 54 + 55 + irqreturn_t netup_ci_interrupt(struct netup_unidvb_dev *ndev) 56 + { 57 + writew(0x101, ndev->bmmio0 + CAM_CTRLSTAT_CLR); 58 + return IRQ_HANDLED; 59 + } 60 + 61 + static int netup_unidvb_ci_slot_ts_ctl(struct dvb_ca_en50221 *en50221, 62 + int slot) 63 + { 64 + struct netup_ci_state *state = en50221->data; 65 + struct netup_unidvb_dev *dev = state->dev; 66 + u16 shift = (state->nr == 1) ? CAM1_SHIFT : 0; 67 + 68 + dev_dbg(&dev->pci_dev->dev, "%s(): CAM_CTRLSTAT=0x%x\n", 69 + __func__, readw(dev->bmmio0 + CAM_CTRLSTAT_READ_SET)); 70 + if (slot != 0) 71 + return -EINVAL; 72 + /* pass data to CAM module */ 73 + writew(BIT_CAM_BYPASS << shift, dev->bmmio0 + CAM_CTRLSTAT_CLR); 74 + dev_dbg(&dev->pci_dev->dev, "%s(): CAM_CTRLSTAT=0x%x done\n", 75 + __func__, readw(dev->bmmio0 + CAM_CTRLSTAT_READ_SET)); 76 + return 0; 77 + } 78 + 79 + static int netup_unidvb_ci_slot_shutdown(struct dvb_ca_en50221 *en50221, 80 + int slot) 81 + { 82 + struct netup_ci_state *state = en50221->data; 83 + struct netup_unidvb_dev *dev = state->dev; 84 + 85 + dev_dbg(&dev->pci_dev->dev, "%s()\n", __func__); 86 + return 0; 87 + } 88 + 89 + static int netup_unidvb_ci_slot_reset(struct dvb_ca_en50221 *en50221, 90 + int slot) 91 + { 92 + struct netup_ci_state *state = en50221->data; 93 + struct netup_unidvb_dev *dev = state->dev; 94 + unsigned long timeout = 0; 95 + u16 shift = (state->nr == 1) ? CAM1_SHIFT : 0; 96 + u16 ci_stat = 0; 97 + int reset_counter = 3; 98 + 99 + dev_dbg(&dev->pci_dev->dev, "%s(): CAM_CTRLSTAT_READ_SET=0x%x\n", 100 + __func__, readw(dev->bmmio0 + CAM_CTRLSTAT_READ_SET)); 101 + reset: 102 + timeout = jiffies + msecs_to_jiffies(5000); 103 + /* start reset */ 104 + writew(BIT_CAM_RESET << shift, dev->bmmio0 + CAM_CTRLSTAT_READ_SET); 105 + dev_dbg(&dev->pci_dev->dev, "%s(): waiting for reset\n", __func__); 106 + /* wait until reset done */ 107 + while (time_before(jiffies, timeout)) { 108 + ci_stat = readw(dev->bmmio0 + CAM_CTRLSTAT_READ_SET); 109 + if (ci_stat & (BIT_CAM_READY << shift)) 110 + break; 111 + udelay(1000); 112 + } 113 + if (!(ci_stat & (BIT_CAM_READY << shift)) && reset_counter > 0) { 114 + dev_dbg(&dev->pci_dev->dev, 115 + "%s(): CAMP reset timeout! Will try again..\n", 116 + __func__); 117 + reset_counter--; 118 + goto reset; 119 + } 120 + return 0; 121 + } 122 + 123 + static int netup_unidvb_poll_ci_slot_status(struct dvb_ca_en50221 *en50221, 124 + int slot, int open) 125 + { 126 + struct netup_ci_state *state = en50221->data; 127 + struct netup_unidvb_dev *dev = state->dev; 128 + u16 shift = (state->nr == 1) ? CAM1_SHIFT : 0; 129 + u16 ci_stat = 0; 130 + 131 + dev_dbg(&dev->pci_dev->dev, "%s(): CAM_CTRLSTAT_READ_SET=0x%x\n", 132 + __func__, readw(dev->bmmio0 + CAM_CTRLSTAT_READ_SET)); 133 + ci_stat = readw(dev->bmmio0 + CAM_CTRLSTAT_READ_SET); 134 + if (ci_stat & (BIT_CAM_READY << shift)) { 135 + state->status = DVB_CA_EN50221_POLL_CAM_PRESENT | 136 + DVB_CA_EN50221_POLL_CAM_READY; 137 + } else if (ci_stat & (BIT_CAM_PRESENT << shift)) { 138 + state->status = DVB_CA_EN50221_POLL_CAM_PRESENT; 139 + } else { 140 + state->status = 0; 141 + } 142 + return state->status; 143 + } 144 + 145 + static int netup_unidvb_ci_read_attribute_mem(struct dvb_ca_en50221 *en50221, 146 + int slot, int addr) 147 + { 148 + struct netup_ci_state *state = en50221->data; 149 + struct netup_unidvb_dev *dev = state->dev; 150 + u8 val = state->membase8_config[addr]; 151 + 152 + dev_dbg(&dev->pci_dev->dev, 153 + "%s(): addr=0x%x val=0x%x\n", __func__, addr, val); 154 + return val; 155 + } 156 + 157 + static int netup_unidvb_ci_write_attribute_mem(struct dvb_ca_en50221 *en50221, 158 + int slot, int addr, u8 data) 159 + { 160 + struct netup_ci_state *state = en50221->data; 161 + struct netup_unidvb_dev *dev = state->dev; 162 + 163 + dev_dbg(&dev->pci_dev->dev, 164 + "%s(): addr=0x%x data=0x%x\n", __func__, addr, data); 165 + state->membase8_config[addr] = data; 166 + return 0; 167 + } 168 + 169 + static int netup_unidvb_ci_read_cam_ctl(struct dvb_ca_en50221 *en50221, 170 + int slot, u8 addr) 171 + { 172 + struct netup_ci_state *state = en50221->data; 173 + struct netup_unidvb_dev *dev = state->dev; 174 + u8 val = state->membase8_io[addr]; 175 + 176 + dev_dbg(&dev->pci_dev->dev, 177 + "%s(): addr=0x%x val=0x%x\n", __func__, addr, val); 178 + return val; 179 + } 180 + 181 + static int netup_unidvb_ci_write_cam_ctl(struct dvb_ca_en50221 *en50221, 182 + int slot, u8 addr, u8 data) 183 + { 184 + struct netup_ci_state *state = en50221->data; 185 + struct netup_unidvb_dev *dev = state->dev; 186 + 187 + dev_dbg(&dev->pci_dev->dev, 188 + "%s(): addr=0x%x data=0x%x\n", __func__, addr, data); 189 + state->membase8_io[addr] = data; 190 + return 0; 191 + } 192 + 193 + int netup_unidvb_ci_register(struct netup_unidvb_dev *dev, 194 + int num, struct pci_dev *pci_dev) 195 + { 196 + int result; 197 + struct netup_ci_state *state; 198 + 199 + if (num < 0 || num > 1) { 200 + dev_err(&pci_dev->dev, "%s(): invalid CI adapter %d\n", 201 + __func__, num); 202 + return -EINVAL; 203 + } 204 + state = &dev->ci[num]; 205 + state->nr = num; 206 + state->membase8_config = dev->bmmio1 + 207 + ((num == 0) ? CAM0_CONFIG : CAM1_CONFIG); 208 + state->membase8_io = dev->bmmio1 + 209 + ((num == 0) ? CAM0_IO : CAM1_IO); 210 + state->dev = dev; 211 + state->ca.owner = THIS_MODULE; 212 + state->ca.read_attribute_mem = netup_unidvb_ci_read_attribute_mem; 213 + state->ca.write_attribute_mem = netup_unidvb_ci_write_attribute_mem; 214 + state->ca.read_cam_control = netup_unidvb_ci_read_cam_ctl; 215 + state->ca.write_cam_control = netup_unidvb_ci_write_cam_ctl; 216 + state->ca.slot_reset = netup_unidvb_ci_slot_reset; 217 + state->ca.slot_shutdown = netup_unidvb_ci_slot_shutdown; 218 + state->ca.slot_ts_enable = netup_unidvb_ci_slot_ts_ctl; 219 + state->ca.poll_slot_status = netup_unidvb_poll_ci_slot_status; 220 + state->ca.data = state; 221 + result = dvb_ca_en50221_init(&dev->frontends[num].adapter, 222 + &state->ca, 0, 1); 223 + if (result < 0) { 224 + dev_err(&pci_dev->dev, 225 + "%s(): dvb_ca_en50221_init result %d\n", 226 + __func__, result); 227 + return result; 228 + } 229 + writew(NETUP_UNIDVB_IRQ_CI, (u16 *)(dev->bmmio0 + REG_IMASK_SET)); 230 + dev_info(&pci_dev->dev, 231 + "%s(): CI adapter %d init done\n", __func__, num); 232 + return 0; 233 + } 234 + 235 + void netup_unidvb_ci_unregister(struct netup_unidvb_dev *dev, int num) 236 + { 237 + struct netup_ci_state *state; 238 + 239 + dev_dbg(&dev->pci_dev->dev, "%s()\n", __func__); 240 + if (num < 0 || num > 1) { 241 + dev_err(&dev->pci_dev->dev, "%s(): invalid CI adapter %d\n", 242 + __func__, num); 243 + return; 244 + } 245 + state = &dev->ci[num]; 246 + dvb_ca_en50221_release(&state->ca); 247 + } 248 +
+1001
drivers/media/pci/netup_unidvb/netup_unidvb_core.c
··· 1 + /* 2 + * netup_unidvb_core.c 3 + * 4 + * Main module for NetUP Universal Dual DVB-CI 5 + * 6 + * Copyright (C) 2014 NetUP Inc. 7 + * Copyright (C) 2014 Sergey Kozlov <serjk@netup.ru> 8 + * Copyright (C) 2014 Abylay Ospan <aospan@netup.ru> 9 + * 10 + * This program is free software; you can redistribute it and/or modify 11 + * it under the terms of the GNU General Public License as published by 12 + * the Free Software Foundation; either version 2 of the License, or 13 + * (at your option) any later version. 14 + * 15 + * This program is distributed in the hope that it will be useful, 16 + * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 + * GNU General Public License for more details. 19 + */ 20 + 21 + #include <linux/init.h> 22 + #include <linux/module.h> 23 + #include <linux/moduleparam.h> 24 + #include <linux/kmod.h> 25 + #include <linux/kernel.h> 26 + #include <linux/slab.h> 27 + #include <linux/interrupt.h> 28 + #include <linux/delay.h> 29 + #include <linux/list.h> 30 + #include <media/videobuf2-vmalloc.h> 31 + 32 + #include "netup_unidvb.h" 33 + #include "cxd2841er.h" 34 + #include "horus3a.h" 35 + #include "ascot2e.h" 36 + #include "lnbh25.h" 37 + 38 + static int spi_enable; 39 + module_param(spi_enable, int, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); 40 + 41 + MODULE_DESCRIPTION("Driver for NetUP Dual Universal DVB CI PCIe card"); 42 + MODULE_AUTHOR("info@netup.ru"); 43 + MODULE_VERSION(NETUP_UNIDVB_VERSION); 44 + MODULE_LICENSE("GPL"); 45 + 46 + DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr); 47 + 48 + /* Avalon-MM PCI-E registers */ 49 + #define AVL_PCIE_IENR 0x50 50 + #define AVL_PCIE_ISR 0x40 51 + #define AVL_IRQ_ENABLE 0x80 52 + #define AVL_IRQ_ASSERTED 0x80 53 + /* GPIO registers */ 54 + #define GPIO_REG_IO 0x4880 55 + #define GPIO_REG_IO_TOGGLE 0x4882 56 + #define GPIO_REG_IO_SET 0x4884 57 + #define GPIO_REG_IO_CLEAR 0x4886 58 + /* GPIO bits */ 59 + #define GPIO_FEA_RESET (1 << 0) 60 + #define GPIO_FEB_RESET (1 << 1) 61 + #define GPIO_RFA_CTL (1 << 2) 62 + #define GPIO_RFB_CTL (1 << 3) 63 + #define GPIO_FEA_TU_RESET (1 << 4) 64 + #define GPIO_FEB_TU_RESET (1 << 5) 65 + /* DMA base address */ 66 + #define NETUP_DMA0_ADDR 0x4900 67 + #define NETUP_DMA1_ADDR 0x4940 68 + /* 8 DMA blocks * 128 packets * 188 bytes*/ 69 + #define NETUP_DMA_BLOCKS_COUNT 8 70 + #define NETUP_DMA_PACKETS_COUNT 128 71 + /* DMA status bits */ 72 + #define BIT_DMA_RUN 1 73 + #define BIT_DMA_ERROR 2 74 + #define BIT_DMA_IRQ 0x200 75 + 76 + /** 77 + * struct netup_dma_regs - the map of DMA module registers 78 + * @ctrlstat_set: Control register, write to set control bits 79 + * @ctrlstat_clear: Control register, write to clear control bits 80 + * @start_addr_lo: DMA ring buffer start address, lower part 81 + * @start_addr_hi: DMA ring buffer start address, higher part 82 + * @size: DMA ring buffer size register 83 + Bits [0-7]: DMA packet size, 188 bytes 84 + Bits [16-23]: packets count in block, 128 packets 85 + Bits [24-31]: blocks count, 8 blocks 86 + * @timeout: DMA timeout in units of 8ns 87 + For example, value of 375000000 equals to 3 sec 88 + * @curr_addr_lo: Current ring buffer head address, lower part 89 + * @curr_addr_hi: Current ring buffer head address, higher part 90 + * @stat_pkt_received: Statistic register, not tested 91 + * @stat_pkt_accepted: Statistic register, not tested 92 + * @stat_pkt_overruns: Statistic register, not tested 93 + * @stat_pkt_underruns: Statistic register, not tested 94 + * @stat_fifo_overruns: Statistic register, not tested 95 + */ 96 + struct netup_dma_regs { 97 + __le32 ctrlstat_set; 98 + __le32 ctrlstat_clear; 99 + __le32 start_addr_lo; 100 + __le32 start_addr_hi; 101 + __le32 size; 102 + __le32 timeout; 103 + __le32 curr_addr_lo; 104 + __le32 curr_addr_hi; 105 + __le32 stat_pkt_received; 106 + __le32 stat_pkt_accepted; 107 + __le32 stat_pkt_overruns; 108 + __le32 stat_pkt_underruns; 109 + __le32 stat_fifo_overruns; 110 + } __packed __aligned(1); 111 + 112 + struct netup_unidvb_buffer { 113 + struct vb2_buffer vb; 114 + struct list_head list; 115 + u32 size; 116 + }; 117 + 118 + static int netup_unidvb_tuner_ctrl(void *priv, int is_dvb_tc); 119 + static void netup_unidvb_queue_cleanup(struct netup_dma *dma); 120 + 121 + static struct cxd2841er_config demod_config = { 122 + .i2c_addr = 0xc8 123 + }; 124 + 125 + static struct horus3a_config horus3a_conf = { 126 + .i2c_address = 0xc0, 127 + .xtal_freq_mhz = 16, 128 + .set_tuner_callback = netup_unidvb_tuner_ctrl 129 + }; 130 + 131 + static struct ascot2e_config ascot2e_conf = { 132 + .i2c_address = 0xc2, 133 + .set_tuner_callback = netup_unidvb_tuner_ctrl 134 + }; 135 + 136 + static struct lnbh25_config lnbh25_conf = { 137 + .i2c_address = 0x10, 138 + .data2_config = LNBH25_TEN | LNBH25_EXTM 139 + }; 140 + 141 + static int netup_unidvb_tuner_ctrl(void *priv, int is_dvb_tc) 142 + { 143 + u8 reg, mask; 144 + struct netup_dma *dma = priv; 145 + struct netup_unidvb_dev *ndev; 146 + 147 + if (!priv) 148 + return -EINVAL; 149 + ndev = dma->ndev; 150 + dev_dbg(&ndev->pci_dev->dev, "%s(): num %d is_dvb_tc %d\n", 151 + __func__, dma->num, is_dvb_tc); 152 + reg = readb(ndev->bmmio0 + GPIO_REG_IO); 153 + mask = (dma->num == 0) ? GPIO_RFA_CTL : GPIO_RFB_CTL; 154 + if (!is_dvb_tc) 155 + reg |= mask; 156 + else 157 + reg &= ~mask; 158 + writeb(reg, ndev->bmmio0 + GPIO_REG_IO); 159 + return 0; 160 + } 161 + 162 + static void netup_unidvb_dev_enable(struct netup_unidvb_dev *ndev) 163 + { 164 + u16 gpio_reg; 165 + 166 + /* enable PCI-E interrupts */ 167 + writel(AVL_IRQ_ENABLE, ndev->bmmio0 + AVL_PCIE_IENR); 168 + /* unreset frontends bits[0:1] */ 169 + writeb(0x00, ndev->bmmio0 + GPIO_REG_IO); 170 + msleep(100); 171 + gpio_reg = 172 + GPIO_FEA_RESET | GPIO_FEB_RESET | 173 + GPIO_FEA_TU_RESET | GPIO_FEB_TU_RESET | 174 + GPIO_RFA_CTL | GPIO_RFB_CTL; 175 + writeb(gpio_reg, ndev->bmmio0 + GPIO_REG_IO); 176 + dev_dbg(&ndev->pci_dev->dev, 177 + "%s(): AVL_PCIE_IENR 0x%x GPIO_REG_IO 0x%x\n", 178 + __func__, readl(ndev->bmmio0 + AVL_PCIE_IENR), 179 + (int)readb(ndev->bmmio0 + GPIO_REG_IO)); 180 + 181 + } 182 + 183 + static void netup_unidvb_dma_enable(struct netup_dma *dma, int enable) 184 + { 185 + u32 irq_mask = (dma->num == 0 ? 186 + NETUP_UNIDVB_IRQ_DMA1 : NETUP_UNIDVB_IRQ_DMA2); 187 + 188 + dev_dbg(&dma->ndev->pci_dev->dev, 189 + "%s(): DMA%d enable %d\n", __func__, dma->num, enable); 190 + if (enable) { 191 + writel(BIT_DMA_RUN, &dma->regs->ctrlstat_set); 192 + writew(irq_mask, 193 + (u16 *)(dma->ndev->bmmio0 + REG_IMASK_SET)); 194 + } else { 195 + writel(BIT_DMA_RUN, &dma->regs->ctrlstat_clear); 196 + writew(irq_mask, 197 + (u16 *)(dma->ndev->bmmio0 + REG_IMASK_CLEAR)); 198 + } 199 + } 200 + 201 + static irqreturn_t netup_dma_interrupt(struct netup_dma *dma) 202 + { 203 + u64 addr_curr; 204 + u32 size; 205 + unsigned long flags; 206 + struct device *dev = &dma->ndev->pci_dev->dev; 207 + 208 + spin_lock_irqsave(&dma->lock, flags); 209 + addr_curr = ((u64)readl(&dma->regs->curr_addr_hi) << 32) | 210 + (u64)readl(&dma->regs->curr_addr_lo) | dma->high_addr; 211 + /* clear IRQ */ 212 + writel(BIT_DMA_IRQ, &dma->regs->ctrlstat_clear); 213 + /* sanity check */ 214 + if (addr_curr < dma->addr_phys || 215 + addr_curr > dma->addr_phys + dma->ring_buffer_size) { 216 + if (addr_curr != 0) { 217 + dev_err(dev, 218 + "%s(): addr 0x%llx not from 0x%llx:0x%llx\n", 219 + __func__, addr_curr, (u64)dma->addr_phys, 220 + (u64)(dma->addr_phys + dma->ring_buffer_size)); 221 + } 222 + goto irq_handled; 223 + } 224 + size = (addr_curr >= dma->addr_last) ? 225 + (u32)(addr_curr - dma->addr_last) : 226 + (u32)(dma->ring_buffer_size - (dma->addr_last - addr_curr)); 227 + if (dma->data_size != 0) { 228 + printk_ratelimited("%s(): lost interrupt, data size %d\n", 229 + __func__, dma->data_size); 230 + dma->data_size += size; 231 + } 232 + if (dma->data_size == 0 || dma->data_size > dma->ring_buffer_size) { 233 + dma->data_size = size; 234 + dma->data_offset = (u32)(dma->addr_last - dma->addr_phys); 235 + } 236 + dma->addr_last = addr_curr; 237 + queue_work(dma->ndev->wq, &dma->work); 238 + irq_handled: 239 + spin_unlock_irqrestore(&dma->lock, flags); 240 + return IRQ_HANDLED; 241 + } 242 + 243 + static irqreturn_t netup_unidvb_isr(int irq, void *dev_id) 244 + { 245 + struct pci_dev *pci_dev = (struct pci_dev *)dev_id; 246 + struct netup_unidvb_dev *ndev = pci_get_drvdata(pci_dev); 247 + u32 reg40, reg_isr; 248 + irqreturn_t iret = IRQ_NONE; 249 + 250 + /* disable interrupts */ 251 + writel(0, ndev->bmmio0 + AVL_PCIE_IENR); 252 + /* check IRQ source */ 253 + reg40 = readl(ndev->bmmio0 + AVL_PCIE_ISR); 254 + if ((reg40 & AVL_IRQ_ASSERTED) != 0) { 255 + /* IRQ is being signaled */ 256 + reg_isr = readw(ndev->bmmio0 + REG_ISR); 257 + if (reg_isr & NETUP_UNIDVB_IRQ_I2C0) { 258 + iret = netup_i2c_interrupt(&ndev->i2c[0]); 259 + } else if (reg_isr & NETUP_UNIDVB_IRQ_I2C1) { 260 + iret = netup_i2c_interrupt(&ndev->i2c[1]); 261 + } else if (reg_isr & NETUP_UNIDVB_IRQ_SPI) { 262 + iret = netup_spi_interrupt(ndev->spi); 263 + } else if (reg_isr & NETUP_UNIDVB_IRQ_DMA1) { 264 + iret = netup_dma_interrupt(&ndev->dma[0]); 265 + } else if (reg_isr & NETUP_UNIDVB_IRQ_DMA2) { 266 + iret = netup_dma_interrupt(&ndev->dma[1]); 267 + } else if (reg_isr & NETUP_UNIDVB_IRQ_CI) { 268 + iret = netup_ci_interrupt(ndev); 269 + } else { 270 + dev_err(&pci_dev->dev, 271 + "%s(): unknown interrupt 0x%x\n", 272 + __func__, reg_isr); 273 + } 274 + } 275 + /* re-enable interrupts */ 276 + writel(AVL_IRQ_ENABLE, ndev->bmmio0 + AVL_PCIE_IENR); 277 + return iret; 278 + } 279 + 280 + static int netup_unidvb_queue_setup(struct vb2_queue *vq, 281 + const struct v4l2_format *fmt, 282 + unsigned int *nbuffers, 283 + unsigned int *nplanes, 284 + unsigned int sizes[], 285 + void *alloc_ctxs[]) 286 + { 287 + struct netup_dma *dma = vb2_get_drv_priv(vq); 288 + 289 + dev_dbg(&dma->ndev->pci_dev->dev, "%s()\n", __func__); 290 + 291 + *nplanes = 1; 292 + if (vq->num_buffers + *nbuffers < VIDEO_MAX_FRAME) 293 + *nbuffers = VIDEO_MAX_FRAME - vq->num_buffers; 294 + sizes[0] = PAGE_ALIGN(NETUP_DMA_PACKETS_COUNT * 188); 295 + dev_dbg(&dma->ndev->pci_dev->dev, "%s() nbuffers=%d sizes[0]=%d\n", 296 + __func__, *nbuffers, sizes[0]); 297 + return 0; 298 + } 299 + 300 + static int netup_unidvb_buf_prepare(struct vb2_buffer *vb) 301 + { 302 + struct netup_dma *dma = vb2_get_drv_priv(vb->vb2_queue); 303 + struct netup_unidvb_buffer *buf = container_of(vb, 304 + struct netup_unidvb_buffer, vb); 305 + 306 + dev_dbg(&dma->ndev->pci_dev->dev, "%s(): buf 0x%p\n", __func__, buf); 307 + buf->size = 0; 308 + return 0; 309 + } 310 + 311 + static void netup_unidvb_buf_queue(struct vb2_buffer *vb) 312 + { 313 + unsigned long flags; 314 + struct netup_dma *dma = vb2_get_drv_priv(vb->vb2_queue); 315 + struct netup_unidvb_buffer *buf = container_of(vb, 316 + struct netup_unidvb_buffer, vb); 317 + 318 + dev_dbg(&dma->ndev->pci_dev->dev, "%s(): %p\n", __func__, buf); 319 + spin_lock_irqsave(&dma->lock, flags); 320 + list_add_tail(&buf->list, &dma->free_buffers); 321 + spin_unlock_irqrestore(&dma->lock, flags); 322 + mod_timer(&dma->timeout, jiffies + msecs_to_jiffies(1000)); 323 + } 324 + 325 + static int netup_unidvb_start_streaming(struct vb2_queue *q, unsigned int count) 326 + { 327 + struct netup_dma *dma = vb2_get_drv_priv(q); 328 + 329 + dev_dbg(&dma->ndev->pci_dev->dev, "%s()\n", __func__); 330 + netup_unidvb_dma_enable(dma, 1); 331 + return 0; 332 + } 333 + 334 + static void netup_unidvb_stop_streaming(struct vb2_queue *q) 335 + { 336 + struct netup_dma *dma = vb2_get_drv_priv(q); 337 + 338 + dev_dbg(&dma->ndev->pci_dev->dev, "%s()\n", __func__); 339 + netup_unidvb_dma_enable(dma, 0); 340 + netup_unidvb_queue_cleanup(dma); 341 + } 342 + 343 + static struct vb2_ops dvb_qops = { 344 + .queue_setup = netup_unidvb_queue_setup, 345 + .buf_prepare = netup_unidvb_buf_prepare, 346 + .buf_queue = netup_unidvb_buf_queue, 347 + .start_streaming = netup_unidvb_start_streaming, 348 + .stop_streaming = netup_unidvb_stop_streaming, 349 + }; 350 + 351 + static int netup_unidvb_queue_init(struct netup_dma *dma, 352 + struct vb2_queue *vb_queue) 353 + { 354 + int res; 355 + 356 + /* Init videobuf2 queue structure */ 357 + vb_queue->type = V4L2_BUF_TYPE_VIDEO_CAPTURE; 358 + vb_queue->io_modes = VB2_MMAP | VB2_USERPTR | VB2_READ; 359 + vb_queue->drv_priv = dma; 360 + vb_queue->buf_struct_size = sizeof(struct netup_unidvb_buffer); 361 + vb_queue->ops = &dvb_qops; 362 + vb_queue->mem_ops = &vb2_vmalloc_memops; 363 + vb_queue->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC; 364 + res = vb2_queue_init(vb_queue); 365 + if (res != 0) { 366 + dev_err(&dma->ndev->pci_dev->dev, 367 + "%s(): vb2_queue_init failed (%d)\n", __func__, res); 368 + } 369 + return res; 370 + } 371 + 372 + static int netup_unidvb_dvb_init(struct netup_unidvb_dev *ndev, 373 + int num) 374 + { 375 + struct vb2_dvb_frontend *fe0, *fe1, *fe2; 376 + 377 + if (num < 0 || num > 1) { 378 + dev_dbg(&ndev->pci_dev->dev, 379 + "%s(): unable to init DVB bus %d\n", __func__, num); 380 + return -ENODEV; 381 + } 382 + mutex_init(&ndev->frontends[num].lock); 383 + INIT_LIST_HEAD(&ndev->frontends[num].felist); 384 + if (vb2_dvb_alloc_frontend(&ndev->frontends[num], 1) == NULL || 385 + vb2_dvb_alloc_frontend( 386 + &ndev->frontends[num], 2) == NULL || 387 + vb2_dvb_alloc_frontend( 388 + &ndev->frontends[num], 3) == NULL) { 389 + dev_dbg(&ndev->pci_dev->dev, 390 + "%s(): unable to to alllocate vb2_dvb_frontend\n", 391 + __func__); 392 + return -ENOMEM; 393 + } 394 + fe0 = vb2_dvb_get_frontend(&ndev->frontends[num], 1); 395 + fe1 = vb2_dvb_get_frontend(&ndev->frontends[num], 2); 396 + fe2 = vb2_dvb_get_frontend(&ndev->frontends[num], 3); 397 + if (fe0 == NULL || fe1 == NULL || fe2 == NULL) { 398 + dev_dbg(&ndev->pci_dev->dev, 399 + "%s(): frontends has not been allocated\n", __func__); 400 + return -EINVAL; 401 + } 402 + netup_unidvb_queue_init(&ndev->dma[num], &fe0->dvb.dvbq); 403 + netup_unidvb_queue_init(&ndev->dma[num], &fe1->dvb.dvbq); 404 + netup_unidvb_queue_init(&ndev->dma[num], &fe2->dvb.dvbq); 405 + fe0->dvb.name = "netup_fe0"; 406 + fe1->dvb.name = "netup_fe1"; 407 + fe2->dvb.name = "netup_fe2"; 408 + fe0->dvb.frontend = dvb_attach(cxd2841er_attach_s, 409 + &demod_config, &ndev->i2c[num].adap); 410 + if (fe0->dvb.frontend == NULL) { 411 + dev_dbg(&ndev->pci_dev->dev, 412 + "%s(): unable to attach DVB-S/S2 frontend\n", 413 + __func__); 414 + goto frontend_detach; 415 + } 416 + horus3a_conf.set_tuner_priv = &ndev->dma[num]; 417 + if (!dvb_attach(horus3a_attach, fe0->dvb.frontend, 418 + &horus3a_conf, &ndev->i2c[num].adap)) { 419 + dev_dbg(&ndev->pci_dev->dev, 420 + "%s(): unable to attach DVB-S/S2 tuner frontend\n", 421 + __func__); 422 + goto frontend_detach; 423 + } 424 + if (!dvb_attach(lnbh25_attach, fe0->dvb.frontend, 425 + &lnbh25_conf, &ndev->i2c[num].adap)) { 426 + dev_dbg(&ndev->pci_dev->dev, 427 + "%s(): unable to attach SEC frontend\n", __func__); 428 + goto frontend_detach; 429 + } 430 + /* DVB-T/T2 frontend */ 431 + fe1->dvb.frontend = dvb_attach(cxd2841er_attach_t, 432 + &demod_config, &ndev->i2c[num].adap); 433 + if (fe1->dvb.frontend == NULL) { 434 + dev_dbg(&ndev->pci_dev->dev, 435 + "%s(): unable to attach DVB-T frontend\n", __func__); 436 + goto frontend_detach; 437 + } 438 + fe1->dvb.frontend->id = 1; 439 + ascot2e_conf.set_tuner_priv = &ndev->dma[num]; 440 + if (!dvb_attach(ascot2e_attach, fe1->dvb.frontend, 441 + &ascot2e_conf, &ndev->i2c[num].adap)) { 442 + dev_dbg(&ndev->pci_dev->dev, 443 + "%s(): unable to attach DVB-T tuner frontend\n", 444 + __func__); 445 + goto frontend_detach; 446 + } 447 + /* DVB-C/C2 frontend */ 448 + fe2->dvb.frontend = dvb_attach(cxd2841er_attach_c, 449 + &demod_config, &ndev->i2c[num].adap); 450 + if (fe2->dvb.frontend == NULL) { 451 + dev_dbg(&ndev->pci_dev->dev, 452 + "%s(): unable to attach DVB-C frontend\n", __func__); 453 + goto frontend_detach; 454 + } 455 + fe2->dvb.frontend->id = 2; 456 + if (!dvb_attach(ascot2e_attach, fe2->dvb.frontend, 457 + &ascot2e_conf, &ndev->i2c[num].adap)) { 458 + dev_dbg(&ndev->pci_dev->dev, 459 + "%s(): unable to attach DVB-T/C tuner frontend\n", 460 + __func__); 461 + goto frontend_detach; 462 + } 463 + 464 + if (vb2_dvb_register_bus(&ndev->frontends[num], 465 + THIS_MODULE, NULL, 466 + &ndev->pci_dev->dev, adapter_nr, 1)) { 467 + dev_dbg(&ndev->pci_dev->dev, 468 + "%s(): unable to register DVB bus %d\n", 469 + __func__, num); 470 + goto frontend_detach; 471 + } 472 + dev_info(&ndev->pci_dev->dev, "DVB init done, num=%d\n", num); 473 + return 0; 474 + frontend_detach: 475 + vb2_dvb_dealloc_frontends(&ndev->frontends[num]); 476 + return -EINVAL; 477 + } 478 + 479 + static void netup_unidvb_dvb_fini(struct netup_unidvb_dev *ndev, int num) 480 + { 481 + if (num < 0 || num > 1) { 482 + dev_err(&ndev->pci_dev->dev, 483 + "%s(): unable to unregister DVB bus %d\n", 484 + __func__, num); 485 + return; 486 + } 487 + vb2_dvb_unregister_bus(&ndev->frontends[num]); 488 + dev_info(&ndev->pci_dev->dev, 489 + "%s(): DVB bus %d unregistered\n", __func__, num); 490 + } 491 + 492 + static int netup_unidvb_dvb_setup(struct netup_unidvb_dev *ndev) 493 + { 494 + int res; 495 + 496 + res = netup_unidvb_dvb_init(ndev, 0); 497 + if (res) 498 + return res; 499 + res = netup_unidvb_dvb_init(ndev, 1); 500 + if (res) { 501 + netup_unidvb_dvb_fini(ndev, 0); 502 + return res; 503 + } 504 + return 0; 505 + } 506 + 507 + static int netup_unidvb_ring_copy(struct netup_dma *dma, 508 + struct netup_unidvb_buffer *buf) 509 + { 510 + u32 copy_bytes, ring_bytes; 511 + u32 buff_bytes = NETUP_DMA_PACKETS_COUNT * 188 - buf->size; 512 + u8 *p = vb2_plane_vaddr(&buf->vb, 0); 513 + struct netup_unidvb_dev *ndev = dma->ndev; 514 + 515 + if (p == NULL) { 516 + dev_err(&ndev->pci_dev->dev, 517 + "%s(): buffer is NULL\n", __func__); 518 + return -EINVAL; 519 + } 520 + p += buf->size; 521 + if (dma->data_offset + dma->data_size > dma->ring_buffer_size) { 522 + ring_bytes = dma->ring_buffer_size - dma->data_offset; 523 + copy_bytes = (ring_bytes > buff_bytes) ? 524 + buff_bytes : ring_bytes; 525 + memcpy_fromio(p, dma->addr_virt + dma->data_offset, copy_bytes); 526 + p += copy_bytes; 527 + buf->size += copy_bytes; 528 + buff_bytes -= copy_bytes; 529 + dma->data_size -= copy_bytes; 530 + dma->data_offset += copy_bytes; 531 + if (dma->data_offset == dma->ring_buffer_size) 532 + dma->data_offset = 0; 533 + } 534 + if (buff_bytes > 0) { 535 + ring_bytes = dma->data_size; 536 + copy_bytes = (ring_bytes > buff_bytes) ? 537 + buff_bytes : ring_bytes; 538 + memcpy_fromio(p, dma->addr_virt + dma->data_offset, copy_bytes); 539 + buf->size += copy_bytes; 540 + dma->data_size -= copy_bytes; 541 + dma->data_offset += copy_bytes; 542 + if (dma->data_offset == dma->ring_buffer_size) 543 + dma->data_offset = 0; 544 + } 545 + return 0; 546 + } 547 + 548 + static void netup_unidvb_dma_worker(struct work_struct *work) 549 + { 550 + struct netup_dma *dma = container_of(work, struct netup_dma, work); 551 + struct netup_unidvb_dev *ndev = dma->ndev; 552 + struct netup_unidvb_buffer *buf; 553 + unsigned long flags; 554 + 555 + spin_lock_irqsave(&dma->lock, flags); 556 + if (dma->data_size == 0) { 557 + dev_dbg(&ndev->pci_dev->dev, 558 + "%s(): data_size == 0\n", __func__); 559 + goto work_done; 560 + } 561 + while (dma->data_size > 0) { 562 + if (list_empty(&dma->free_buffers)) { 563 + dev_dbg(&ndev->pci_dev->dev, 564 + "%s(): no free buffers\n", __func__); 565 + goto work_done; 566 + } 567 + buf = list_first_entry(&dma->free_buffers, 568 + struct netup_unidvb_buffer, list); 569 + if (buf->size >= NETUP_DMA_PACKETS_COUNT * 188) { 570 + dev_dbg(&ndev->pci_dev->dev, 571 + "%s(): buffer overflow, size %d\n", 572 + __func__, buf->size); 573 + goto work_done; 574 + } 575 + if (netup_unidvb_ring_copy(dma, buf)) 576 + goto work_done; 577 + if (buf->size == NETUP_DMA_PACKETS_COUNT * 188) { 578 + list_del(&buf->list); 579 + dev_dbg(&ndev->pci_dev->dev, 580 + "%s(): buffer %p done, size %d\n", 581 + __func__, buf, buf->size); 582 + v4l2_get_timestamp(&buf->vb.v4l2_buf.timestamp); 583 + vb2_set_plane_payload(&buf->vb, 0, buf->size); 584 + vb2_buffer_done(&buf->vb, VB2_BUF_STATE_DONE); 585 + } 586 + } 587 + work_done: 588 + dma->data_size = 0; 589 + spin_unlock_irqrestore(&dma->lock, flags); 590 + } 591 + 592 + static void netup_unidvb_queue_cleanup(struct netup_dma *dma) 593 + { 594 + struct netup_unidvb_buffer *buf; 595 + unsigned long flags; 596 + 597 + spin_lock_irqsave(&dma->lock, flags); 598 + while (!list_empty(&dma->free_buffers)) { 599 + buf = list_first_entry(&dma->free_buffers, 600 + struct netup_unidvb_buffer, list); 601 + list_del(&buf->list); 602 + vb2_buffer_done(&buf->vb, VB2_BUF_STATE_ERROR); 603 + } 604 + spin_unlock_irqrestore(&dma->lock, flags); 605 + } 606 + 607 + static void netup_unidvb_dma_timeout(unsigned long data) 608 + { 609 + struct netup_dma *dma = (struct netup_dma *)data; 610 + struct netup_unidvb_dev *ndev = dma->ndev; 611 + 612 + dev_dbg(&ndev->pci_dev->dev, "%s()\n", __func__); 613 + netup_unidvb_queue_cleanup(dma); 614 + } 615 + 616 + static int netup_unidvb_dma_init(struct netup_unidvb_dev *ndev, int num) 617 + { 618 + struct netup_dma *dma; 619 + struct device *dev = &ndev->pci_dev->dev; 620 + 621 + if (num < 0 || num > 1) { 622 + dev_err(dev, "%s(): unable to register DMA%d\n", 623 + __func__, num); 624 + return -ENODEV; 625 + } 626 + dma = &ndev->dma[num]; 627 + dev_info(dev, "%s(): starting DMA%d\n", __func__, num); 628 + dma->num = num; 629 + dma->ndev = ndev; 630 + spin_lock_init(&dma->lock); 631 + INIT_WORK(&dma->work, netup_unidvb_dma_worker); 632 + INIT_LIST_HEAD(&dma->free_buffers); 633 + dma->timeout.function = netup_unidvb_dma_timeout; 634 + dma->timeout.data = (unsigned long)dma; 635 + init_timer(&dma->timeout); 636 + dma->ring_buffer_size = ndev->dma_size / 2; 637 + dma->addr_virt = ndev->dma_virt + dma->ring_buffer_size * num; 638 + dma->addr_phys = (dma_addr_t)((u64)ndev->dma_phys + 639 + dma->ring_buffer_size * num); 640 + dev_info(dev, "%s(): DMA%d buffer virt/phys 0x%p/0x%llx size %d\n", 641 + __func__, num, dma->addr_virt, 642 + (unsigned long long)dma->addr_phys, 643 + dma->ring_buffer_size); 644 + memset_io(dma->addr_virt, 0, dma->ring_buffer_size); 645 + dma->addr_last = dma->addr_phys; 646 + dma->high_addr = (u32)(dma->addr_phys & 0xC0000000); 647 + dma->regs = (struct netup_dma_regs *)(num == 0 ? 648 + ndev->bmmio0 + NETUP_DMA0_ADDR : 649 + ndev->bmmio0 + NETUP_DMA1_ADDR); 650 + writel((NETUP_DMA_BLOCKS_COUNT << 24) | 651 + (NETUP_DMA_PACKETS_COUNT << 8) | 188, &dma->regs->size); 652 + writel((u32)(dma->addr_phys & 0x3FFFFFFF), &dma->regs->start_addr_lo); 653 + writel(0, &dma->regs->start_addr_hi); 654 + writel(dma->high_addr, ndev->bmmio0 + 0x1000); 655 + writel(375000000, &dma->regs->timeout); 656 + msleep(1000); 657 + writel(BIT_DMA_IRQ, &dma->regs->ctrlstat_clear); 658 + return 0; 659 + } 660 + 661 + static void netup_unidvb_dma_fini(struct netup_unidvb_dev *ndev, int num) 662 + { 663 + struct netup_dma *dma; 664 + 665 + if (num < 0 || num > 1) 666 + return; 667 + dev_dbg(&ndev->pci_dev->dev, "%s(): num %d\n", __func__, num); 668 + dma = &ndev->dma[num]; 669 + netup_unidvb_dma_enable(dma, 0); 670 + msleep(50); 671 + cancel_work_sync(&dma->work); 672 + del_timer(&dma->timeout); 673 + } 674 + 675 + static int netup_unidvb_dma_setup(struct netup_unidvb_dev *ndev) 676 + { 677 + int res; 678 + 679 + res = netup_unidvb_dma_init(ndev, 0); 680 + if (res) 681 + return res; 682 + res = netup_unidvb_dma_init(ndev, 1); 683 + if (res) { 684 + netup_unidvb_dma_fini(ndev, 0); 685 + return res; 686 + } 687 + netup_unidvb_dma_enable(&ndev->dma[0], 0); 688 + netup_unidvb_dma_enable(&ndev->dma[1], 0); 689 + return 0; 690 + } 691 + 692 + static int netup_unidvb_ci_setup(struct netup_unidvb_dev *ndev, 693 + struct pci_dev *pci_dev) 694 + { 695 + int res; 696 + 697 + writew(NETUP_UNIDVB_IRQ_CI, ndev->bmmio0 + REG_IMASK_SET); 698 + res = netup_unidvb_ci_register(ndev, 0, pci_dev); 699 + if (res) 700 + return res; 701 + res = netup_unidvb_ci_register(ndev, 1, pci_dev); 702 + if (res) 703 + netup_unidvb_ci_unregister(ndev, 0); 704 + return res; 705 + } 706 + 707 + static int netup_unidvb_request_mmio(struct pci_dev *pci_dev) 708 + { 709 + if (!request_mem_region(pci_resource_start(pci_dev, 0), 710 + pci_resource_len(pci_dev, 0), NETUP_UNIDVB_NAME)) { 711 + dev_err(&pci_dev->dev, 712 + "%s(): unable to request MMIO bar 0 at 0x%llx\n", 713 + __func__, 714 + (unsigned long long)pci_resource_start(pci_dev, 0)); 715 + return -EBUSY; 716 + } 717 + if (!request_mem_region(pci_resource_start(pci_dev, 1), 718 + pci_resource_len(pci_dev, 1), NETUP_UNIDVB_NAME)) { 719 + dev_err(&pci_dev->dev, 720 + "%s(): unable to request MMIO bar 1 at 0x%llx\n", 721 + __func__, 722 + (unsigned long long)pci_resource_start(pci_dev, 1)); 723 + release_mem_region(pci_resource_start(pci_dev, 0), 724 + pci_resource_len(pci_dev, 0)); 725 + return -EBUSY; 726 + } 727 + return 0; 728 + } 729 + 730 + static int netup_unidvb_request_modules(struct device *dev) 731 + { 732 + static const char * const modules[] = { 733 + "lnbh25", "ascot2e", "horus3a", "cxd2841er", NULL 734 + }; 735 + const char * const *curr_mod = modules; 736 + int err; 737 + 738 + while (*curr_mod != NULL) { 739 + err = request_module(*curr_mod); 740 + if (err) { 741 + dev_warn(dev, "request_module(%s) failed: %d\n", 742 + *curr_mod, err); 743 + } 744 + ++curr_mod; 745 + } 746 + return 0; 747 + } 748 + 749 + static int netup_unidvb_initdev(struct pci_dev *pci_dev, 750 + const struct pci_device_id *pci_id) 751 + { 752 + u8 board_revision; 753 + u16 board_vendor; 754 + struct netup_unidvb_dev *ndev; 755 + int old_firmware = 0; 756 + 757 + netup_unidvb_request_modules(&pci_dev->dev); 758 + 759 + /* Check card revision */ 760 + if (pci_dev->revision != NETUP_PCI_DEV_REVISION) { 761 + dev_err(&pci_dev->dev, 762 + "netup_unidvb: expected card revision %d, got %d\n", 763 + NETUP_PCI_DEV_REVISION, pci_dev->revision); 764 + dev_err(&pci_dev->dev, 765 + "Please upgrade firmware!\n"); 766 + dev_err(&pci_dev->dev, 767 + "Instructions on http://www.netup.tv\n"); 768 + old_firmware = 1; 769 + spi_enable = 1; 770 + } 771 + 772 + /* allocate device context */ 773 + ndev = kzalloc(sizeof(*ndev), GFP_KERNEL); 774 + 775 + if (!ndev) 776 + goto dev_alloc_err; 777 + memset(ndev, 0, sizeof(*ndev)); 778 + ndev->old_fw = old_firmware; 779 + ndev->wq = create_singlethread_workqueue(NETUP_UNIDVB_NAME); 780 + if (!ndev->wq) { 781 + dev_err(&pci_dev->dev, 782 + "%s(): unable to create workqueue\n", __func__); 783 + goto wq_create_err; 784 + } 785 + ndev->pci_dev = pci_dev; 786 + ndev->pci_bus = pci_dev->bus->number; 787 + ndev->pci_slot = PCI_SLOT(pci_dev->devfn); 788 + ndev->pci_func = PCI_FUNC(pci_dev->devfn); 789 + ndev->board_num = ndev->pci_bus*10 + ndev->pci_slot; 790 + pci_set_drvdata(pci_dev, ndev); 791 + /* PCI init */ 792 + dev_info(&pci_dev->dev, "%s(): PCI device (%d). Bus:0x%x Slot:0x%x\n", 793 + __func__, ndev->board_num, ndev->pci_bus, ndev->pci_slot); 794 + 795 + if (pci_enable_device(pci_dev)) { 796 + dev_err(&pci_dev->dev, "%s(): pci_enable_device failed\n", 797 + __func__); 798 + goto pci_enable_err; 799 + } 800 + /* read PCI info */ 801 + pci_read_config_byte(pci_dev, PCI_CLASS_REVISION, &board_revision); 802 + pci_read_config_word(pci_dev, PCI_VENDOR_ID, &board_vendor); 803 + if (board_vendor != NETUP_VENDOR_ID) { 804 + dev_err(&pci_dev->dev, "%s(): unknown board vendor 0x%x", 805 + __func__, board_vendor); 806 + goto pci_detect_err; 807 + } 808 + dev_info(&pci_dev->dev, 809 + "%s(): board vendor 0x%x, revision 0x%x\n", 810 + __func__, board_vendor, board_revision); 811 + pci_set_master(pci_dev); 812 + if (!pci_dma_supported(pci_dev, 0xffffffff)) { 813 + dev_err(&pci_dev->dev, 814 + "%s(): 32bit PCI DMA is not supported\n", __func__); 815 + goto pci_detect_err; 816 + } 817 + dev_info(&pci_dev->dev, "%s(): using 32bit PCI DMA\n", __func__); 818 + /* Clear "no snoop" and "relaxed ordering" bits, use default MRRS. */ 819 + pcie_capability_clear_and_set_word(pci_dev, PCI_EXP_DEVCTL, 820 + PCI_EXP_DEVCTL_READRQ | PCI_EXP_DEVCTL_RELAX_EN | 821 + PCI_EXP_DEVCTL_NOSNOOP_EN, 0); 822 + /* Adjust PCIe completion timeout. */ 823 + pcie_capability_clear_and_set_word(pci_dev, 824 + PCI_EXP_DEVCTL2, 0xf, 0x2); 825 + 826 + if (netup_unidvb_request_mmio(pci_dev)) { 827 + dev_err(&pci_dev->dev, 828 + "%s(): unable to request MMIO regions\n", __func__); 829 + goto pci_detect_err; 830 + } 831 + ndev->lmmio0 = ioremap(pci_resource_start(pci_dev, 0), 832 + pci_resource_len(pci_dev, 0)); 833 + if (!ndev->lmmio0) { 834 + dev_err(&pci_dev->dev, 835 + "%s(): unable to remap MMIO bar 0\n", __func__); 836 + goto pci_bar0_error; 837 + } 838 + ndev->lmmio1 = ioremap(pci_resource_start(pci_dev, 1), 839 + pci_resource_len(pci_dev, 1)); 840 + if (!ndev->lmmio1) { 841 + dev_err(&pci_dev->dev, 842 + "%s(): unable to remap MMIO bar 1\n", __func__); 843 + goto pci_bar1_error; 844 + } 845 + ndev->bmmio0 = (u8 __iomem *)ndev->lmmio0; 846 + ndev->bmmio1 = (u8 __iomem *)ndev->lmmio1; 847 + dev_info(&pci_dev->dev, 848 + "%s(): PCI MMIO at 0x%p (%d); 0x%p (%d); IRQ %d", 849 + __func__, 850 + ndev->lmmio0, (u32)pci_resource_len(pci_dev, 0), 851 + ndev->lmmio1, (u32)pci_resource_len(pci_dev, 1), 852 + pci_dev->irq); 853 + if (request_irq(pci_dev->irq, netup_unidvb_isr, IRQF_SHARED, 854 + "netup_unidvb", pci_dev) < 0) { 855 + dev_err(&pci_dev->dev, 856 + "%s(): can't get IRQ %d\n", __func__, pci_dev->irq); 857 + goto irq_request_err; 858 + } 859 + ndev->dma_size = 2 * 188 * 860 + NETUP_DMA_BLOCKS_COUNT * NETUP_DMA_PACKETS_COUNT; 861 + ndev->dma_virt = dma_alloc_coherent(&pci_dev->dev, 862 + ndev->dma_size, &ndev->dma_phys, GFP_KERNEL); 863 + if (!ndev->dma_virt) { 864 + dev_err(&pci_dev->dev, "%s(): unable to allocate DMA buffer\n", 865 + __func__); 866 + goto dma_alloc_err; 867 + } 868 + netup_unidvb_dev_enable(ndev); 869 + if (spi_enable && netup_spi_init(ndev)) { 870 + dev_warn(&pci_dev->dev, 871 + "netup_unidvb: SPI flash setup failed\n"); 872 + goto spi_setup_err; 873 + } 874 + if (old_firmware) { 875 + dev_err(&pci_dev->dev, 876 + "netup_unidvb: card initialization was incomplete\n"); 877 + return 0; 878 + } 879 + if (netup_i2c_register(ndev)) { 880 + dev_err(&pci_dev->dev, "netup_unidvb: I2C setup failed\n"); 881 + goto i2c_setup_err; 882 + } 883 + /* enable I2C IRQs */ 884 + writew(NETUP_UNIDVB_IRQ_I2C0 | NETUP_UNIDVB_IRQ_I2C1, 885 + ndev->bmmio0 + REG_IMASK_SET); 886 + usleep_range(5000, 10000); 887 + if (netup_unidvb_dvb_setup(ndev)) { 888 + dev_err(&pci_dev->dev, "netup_unidvb: DVB setup failed\n"); 889 + goto dvb_setup_err; 890 + } 891 + if (netup_unidvb_ci_setup(ndev, pci_dev)) { 892 + dev_err(&pci_dev->dev, "netup_unidvb: CI setup failed\n"); 893 + goto ci_setup_err; 894 + } 895 + if (netup_unidvb_dma_setup(ndev)) { 896 + dev_err(&pci_dev->dev, "netup_unidvb: DMA setup failed\n"); 897 + goto dma_setup_err; 898 + } 899 + dev_info(&pci_dev->dev, 900 + "netup_unidvb: device has been initialized\n"); 901 + return 0; 902 + dma_setup_err: 903 + netup_unidvb_ci_unregister(ndev, 0); 904 + netup_unidvb_ci_unregister(ndev, 1); 905 + ci_setup_err: 906 + netup_unidvb_dvb_fini(ndev, 0); 907 + netup_unidvb_dvb_fini(ndev, 1); 908 + dvb_setup_err: 909 + netup_i2c_unregister(ndev); 910 + i2c_setup_err: 911 + if (ndev->spi) 912 + netup_spi_release(ndev); 913 + spi_setup_err: 914 + dma_free_coherent(&pci_dev->dev, ndev->dma_size, 915 + ndev->dma_virt, ndev->dma_phys); 916 + dma_alloc_err: 917 + free_irq(pci_dev->irq, pci_dev); 918 + irq_request_err: 919 + iounmap(ndev->lmmio1); 920 + pci_bar1_error: 921 + iounmap(ndev->lmmio0); 922 + pci_bar0_error: 923 + release_mem_region(pci_resource_start(pci_dev, 0), 924 + pci_resource_len(pci_dev, 0)); 925 + release_mem_region(pci_resource_start(pci_dev, 1), 926 + pci_resource_len(pci_dev, 1)); 927 + pci_detect_err: 928 + pci_disable_device(pci_dev); 929 + pci_enable_err: 930 + pci_set_drvdata(pci_dev, NULL); 931 + destroy_workqueue(ndev->wq); 932 + wq_create_err: 933 + kfree(ndev); 934 + dev_alloc_err: 935 + dev_err(&pci_dev->dev, 936 + "%s(): failed to initizalize device\n", __func__); 937 + return -EIO; 938 + } 939 + 940 + static void netup_unidvb_finidev(struct pci_dev *pci_dev) 941 + { 942 + struct netup_unidvb_dev *ndev = pci_get_drvdata(pci_dev); 943 + 944 + dev_info(&pci_dev->dev, "%s(): trying to stop device\n", __func__); 945 + if (!ndev->old_fw) { 946 + netup_unidvb_dma_fini(ndev, 0); 947 + netup_unidvb_dma_fini(ndev, 1); 948 + netup_unidvb_ci_unregister(ndev, 0); 949 + netup_unidvb_ci_unregister(ndev, 1); 950 + netup_unidvb_dvb_fini(ndev, 0); 951 + netup_unidvb_dvb_fini(ndev, 1); 952 + netup_i2c_unregister(ndev); 953 + } 954 + if (ndev->spi) 955 + netup_spi_release(ndev); 956 + writew(0xffff, ndev->bmmio0 + REG_IMASK_CLEAR); 957 + dma_free_coherent(&ndev->pci_dev->dev, ndev->dma_size, 958 + ndev->dma_virt, ndev->dma_phys); 959 + free_irq(pci_dev->irq, pci_dev); 960 + iounmap(ndev->lmmio0); 961 + iounmap(ndev->lmmio1); 962 + release_mem_region(pci_resource_start(pci_dev, 0), 963 + pci_resource_len(pci_dev, 0)); 964 + release_mem_region(pci_resource_start(pci_dev, 1), 965 + pci_resource_len(pci_dev, 1)); 966 + pci_disable_device(pci_dev); 967 + pci_set_drvdata(pci_dev, NULL); 968 + destroy_workqueue(ndev->wq); 969 + kfree(ndev); 970 + dev_info(&pci_dev->dev, 971 + "%s(): device has been successfully stopped\n", __func__); 972 + } 973 + 974 + 975 + static struct pci_device_id netup_unidvb_pci_tbl[] = { 976 + { PCI_DEVICE(0x1b55, 0x18f6) }, 977 + { 0, } 978 + }; 979 + MODULE_DEVICE_TABLE(pci, netup_unidvb_pci_tbl); 980 + 981 + static struct pci_driver netup_unidvb_pci_driver = { 982 + .name = "netup_unidvb", 983 + .id_table = netup_unidvb_pci_tbl, 984 + .probe = netup_unidvb_initdev, 985 + .remove = netup_unidvb_finidev, 986 + .suspend = NULL, 987 + .resume = NULL, 988 + }; 989 + 990 + static int __init netup_unidvb_init(void) 991 + { 992 + return pci_register_driver(&netup_unidvb_pci_driver); 993 + } 994 + 995 + static void __exit netup_unidvb_fini(void) 996 + { 997 + pci_unregister_driver(&netup_unidvb_pci_driver); 998 + } 999 + 1000 + module_init(netup_unidvb_init); 1001 + module_exit(netup_unidvb_fini);
+381
drivers/media/pci/netup_unidvb/netup_unidvb_i2c.c
··· 1 + /* 2 + * netup_unidvb_i2c.c 3 + * 4 + * Internal I2C bus driver for NetUP Universal Dual DVB-CI 5 + * 6 + * Copyright (C) 2014 NetUP Inc. 7 + * Copyright (C) 2014 Sergey Kozlov <serjk@netup.ru> 8 + * Copyright (C) 2014 Abylay Ospan <aospan@netup.ru> 9 + * 10 + * This program is free software; you can redistribute it and/or modify 11 + * it under the terms of the GNU General Public License as published by 12 + * the Free Software Foundation; either version 2 of the License, or 13 + * (at your option) any later version. 14 + * 15 + * This program is distributed in the hope that it will be useful, 16 + * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 + * GNU General Public License for more details. 19 + */ 20 + 21 + #include <linux/module.h> 22 + #include <linux/moduleparam.h> 23 + #include <linux/init.h> 24 + #include <linux/delay.h> 25 + #include "netup_unidvb.h" 26 + 27 + #define NETUP_I2C_BUS0_ADDR 0x4800 28 + #define NETUP_I2C_BUS1_ADDR 0x4840 29 + #define NETUP_I2C_TIMEOUT 1000 30 + 31 + /* twi_ctrl0_stat reg bits */ 32 + #define TWI_IRQEN_COMPL 0x1 33 + #define TWI_IRQEN_ANACK 0x2 34 + #define TWI_IRQEN_DNACK 0x4 35 + #define TWI_IRQ_COMPL (TWI_IRQEN_COMPL << 8) 36 + #define TWI_IRQ_ANACK (TWI_IRQEN_ANACK << 8) 37 + #define TWI_IRQ_DNACK (TWI_IRQEN_DNACK << 8) 38 + #define TWI_IRQ_TX 0x800 39 + #define TWI_IRQ_RX 0x1000 40 + #define TWI_IRQEN (TWI_IRQEN_COMPL | TWI_IRQEN_ANACK | TWI_IRQEN_DNACK) 41 + /* twi_addr_ctrl1 reg bits*/ 42 + #define TWI_TRANSFER 0x100 43 + #define TWI_NOSTOP 0x200 44 + #define TWI_SOFT_RESET 0x2000 45 + /* twi_clkdiv reg value */ 46 + #define TWI_CLKDIV 156 47 + /* fifo_stat_ctrl reg bits */ 48 + #define FIFO_IRQEN 0x8000 49 + #define FIFO_RESET 0x4000 50 + /* FIFO size */ 51 + #define FIFO_SIZE 16 52 + 53 + struct netup_i2c_fifo_regs { 54 + union { 55 + __u8 data8; 56 + __le16 data16; 57 + __le32 data32; 58 + }; 59 + __u8 padding[4]; 60 + __le16 stat_ctrl; 61 + } __packed __aligned(1); 62 + 63 + struct netup_i2c_regs { 64 + __le16 clkdiv; 65 + __le16 twi_ctrl0_stat; 66 + __le16 twi_addr_ctrl1; 67 + __le16 length; 68 + __u8 padding1[8]; 69 + struct netup_i2c_fifo_regs tx_fifo; 70 + __u8 padding2[6]; 71 + struct netup_i2c_fifo_regs rx_fifo; 72 + } __packed __aligned(1); 73 + 74 + irqreturn_t netup_i2c_interrupt(struct netup_i2c *i2c) 75 + { 76 + u16 reg, tmp; 77 + unsigned long flags; 78 + irqreturn_t iret = IRQ_HANDLED; 79 + 80 + spin_lock_irqsave(&i2c->lock, flags); 81 + reg = readw(&i2c->regs->twi_ctrl0_stat); 82 + writew(reg & ~TWI_IRQEN, &i2c->regs->twi_ctrl0_stat); 83 + dev_dbg(i2c->adap.dev.parent, 84 + "%s(): twi_ctrl0_state 0x%x\n", __func__, reg); 85 + if ((reg & TWI_IRQEN_COMPL) != 0 && (reg & TWI_IRQ_COMPL)) { 86 + dev_dbg(i2c->adap.dev.parent, 87 + "%s(): TWI_IRQEN_COMPL\n", __func__); 88 + i2c->state = STATE_DONE; 89 + goto irq_ok; 90 + } 91 + if ((reg & TWI_IRQEN_ANACK) != 0 && (reg & TWI_IRQ_ANACK)) { 92 + dev_dbg(i2c->adap.dev.parent, 93 + "%s(): TWI_IRQEN_ANACK\n", __func__); 94 + i2c->state = STATE_ERROR; 95 + goto irq_ok; 96 + } 97 + if ((reg & TWI_IRQEN_DNACK) != 0 && (reg & TWI_IRQ_DNACK)) { 98 + dev_dbg(i2c->adap.dev.parent, 99 + "%s(): TWI_IRQEN_DNACK\n", __func__); 100 + i2c->state = STATE_ERROR; 101 + goto irq_ok; 102 + } 103 + if ((reg & TWI_IRQ_RX) != 0) { 104 + tmp = readw(&i2c->regs->rx_fifo.stat_ctrl); 105 + writew(tmp & ~FIFO_IRQEN, &i2c->regs->rx_fifo.stat_ctrl); 106 + i2c->state = STATE_WANT_READ; 107 + dev_dbg(i2c->adap.dev.parent, 108 + "%s(): want read\n", __func__); 109 + goto irq_ok; 110 + } 111 + if ((reg & TWI_IRQ_TX) != 0) { 112 + tmp = readw(&i2c->regs->tx_fifo.stat_ctrl); 113 + writew(tmp & ~FIFO_IRQEN, &i2c->regs->tx_fifo.stat_ctrl); 114 + i2c->state = STATE_WANT_WRITE; 115 + dev_dbg(i2c->adap.dev.parent, 116 + "%s(): want write\n", __func__); 117 + goto irq_ok; 118 + } 119 + dev_warn(&i2c->adap.dev, "%s(): not mine interrupt\n", __func__); 120 + iret = IRQ_NONE; 121 + irq_ok: 122 + spin_unlock_irqrestore(&i2c->lock, flags); 123 + if (iret == IRQ_HANDLED) 124 + wake_up(&i2c->wq); 125 + return iret; 126 + } 127 + 128 + static void netup_i2c_reset(struct netup_i2c *i2c) 129 + { 130 + dev_dbg(i2c->adap.dev.parent, "%s()\n", __func__); 131 + i2c->state = STATE_DONE; 132 + writew(TWI_SOFT_RESET, &i2c->regs->twi_addr_ctrl1); 133 + writew(TWI_CLKDIV, &i2c->regs->clkdiv); 134 + writew(FIFO_RESET, &i2c->regs->tx_fifo.stat_ctrl); 135 + writew(FIFO_RESET, &i2c->regs->rx_fifo.stat_ctrl); 136 + writew(0x800, &i2c->regs->tx_fifo.stat_ctrl); 137 + writew(0x800, &i2c->regs->rx_fifo.stat_ctrl); 138 + } 139 + 140 + static void netup_i2c_fifo_tx(struct netup_i2c *i2c) 141 + { 142 + u8 data; 143 + u32 fifo_space = FIFO_SIZE - 144 + (readw(&i2c->regs->tx_fifo.stat_ctrl) & 0x3f); 145 + u32 msg_length = i2c->msg->len - i2c->xmit_size; 146 + 147 + msg_length = (msg_length < fifo_space ? msg_length : fifo_space); 148 + while (msg_length--) { 149 + data = i2c->msg->buf[i2c->xmit_size++]; 150 + writeb(data, &i2c->regs->tx_fifo.data8); 151 + dev_dbg(i2c->adap.dev.parent, 152 + "%s(): write 0x%02x\n", __func__, data); 153 + } 154 + if (i2c->xmit_size < i2c->msg->len) { 155 + dev_dbg(i2c->adap.dev.parent, 156 + "%s(): TX IRQ enabled\n", __func__); 157 + writew(readw(&i2c->regs->tx_fifo.stat_ctrl) | FIFO_IRQEN, 158 + &i2c->regs->tx_fifo.stat_ctrl); 159 + } 160 + } 161 + 162 + static void netup_i2c_fifo_rx(struct netup_i2c *i2c) 163 + { 164 + u8 data; 165 + u32 fifo_size = readw(&i2c->regs->rx_fifo.stat_ctrl) & 0x3f; 166 + 167 + dev_dbg(i2c->adap.dev.parent, 168 + "%s(): RX fifo size %d\n", __func__, fifo_size); 169 + while (fifo_size--) { 170 + data = readb(&i2c->regs->rx_fifo.data8); 171 + if ((i2c->msg->flags & I2C_M_RD) != 0 && 172 + i2c->xmit_size < i2c->msg->len) { 173 + i2c->msg->buf[i2c->xmit_size++] = data; 174 + dev_dbg(i2c->adap.dev.parent, 175 + "%s(): read 0x%02x\n", __func__, data); 176 + } 177 + } 178 + if (i2c->xmit_size < i2c->msg->len) { 179 + dev_dbg(i2c->adap.dev.parent, 180 + "%s(): RX IRQ enabled\n", __func__); 181 + writew(readw(&i2c->regs->rx_fifo.stat_ctrl) | FIFO_IRQEN, 182 + &i2c->regs->rx_fifo.stat_ctrl); 183 + } 184 + } 185 + 186 + static void netup_i2c_start_xfer(struct netup_i2c *i2c) 187 + { 188 + u16 rdflag = ((i2c->msg->flags & I2C_M_RD) ? 1 : 0); 189 + u16 reg = readw(&i2c->regs->twi_ctrl0_stat); 190 + 191 + writew(TWI_IRQEN | reg, &i2c->regs->twi_ctrl0_stat); 192 + writew(i2c->msg->len, &i2c->regs->length); 193 + writew(TWI_TRANSFER | (i2c->msg->addr << 1) | rdflag, 194 + &i2c->regs->twi_addr_ctrl1); 195 + dev_dbg(i2c->adap.dev.parent, 196 + "%s(): length %d twi_addr_ctrl1 0x%x twi_ctrl0_stat 0x%x\n", 197 + __func__, readw(&i2c->regs->length), 198 + readw(&i2c->regs->twi_addr_ctrl1), 199 + readw(&i2c->regs->twi_ctrl0_stat)); 200 + i2c->state = STATE_WAIT; 201 + i2c->xmit_size = 0; 202 + if (!rdflag) 203 + netup_i2c_fifo_tx(i2c); 204 + else 205 + writew(FIFO_IRQEN | readw(&i2c->regs->rx_fifo.stat_ctrl), 206 + &i2c->regs->rx_fifo.stat_ctrl); 207 + } 208 + 209 + static int netup_i2c_xfer(struct i2c_adapter *adap, 210 + struct i2c_msg *msgs, int num) 211 + { 212 + unsigned long flags; 213 + int i, trans_done, res = num; 214 + struct netup_i2c *i2c = i2c_get_adapdata(adap); 215 + u16 reg; 216 + 217 + if (num <= 0) { 218 + dev_dbg(i2c->adap.dev.parent, 219 + "%s(): num == %d\n", __func__, num); 220 + return -EINVAL; 221 + } 222 + spin_lock_irqsave(&i2c->lock, flags); 223 + if (i2c->state != STATE_DONE) { 224 + dev_dbg(i2c->adap.dev.parent, 225 + "%s(): i2c->state == %d, resetting I2C\n", 226 + __func__, i2c->state); 227 + netup_i2c_reset(i2c); 228 + } 229 + dev_dbg(i2c->adap.dev.parent, "%s() num %d\n", __func__, num); 230 + for (i = 0; i < num; i++) { 231 + i2c->msg = &msgs[i]; 232 + netup_i2c_start_xfer(i2c); 233 + trans_done = 0; 234 + while (!trans_done) { 235 + spin_unlock_irqrestore(&i2c->lock, flags); 236 + if (wait_event_timeout(i2c->wq, 237 + i2c->state != STATE_WAIT, 238 + msecs_to_jiffies(NETUP_I2C_TIMEOUT))) { 239 + spin_lock_irqsave(&i2c->lock, flags); 240 + switch (i2c->state) { 241 + case STATE_WANT_READ: 242 + netup_i2c_fifo_rx(i2c); 243 + break; 244 + case STATE_WANT_WRITE: 245 + netup_i2c_fifo_tx(i2c); 246 + break; 247 + case STATE_DONE: 248 + if ((i2c->msg->flags & I2C_M_RD) != 0 && 249 + i2c->xmit_size != i2c->msg->len) 250 + netup_i2c_fifo_rx(i2c); 251 + dev_dbg(i2c->adap.dev.parent, 252 + "%s(): msg %d OK\n", 253 + __func__, i); 254 + trans_done = 1; 255 + break; 256 + case STATE_ERROR: 257 + res = -EIO; 258 + dev_dbg(i2c->adap.dev.parent, 259 + "%s(): error state\n", 260 + __func__); 261 + goto done; 262 + default: 263 + dev_dbg(i2c->adap.dev.parent, 264 + "%s(): invalid state %d\n", 265 + __func__, i2c->state); 266 + res = -EINVAL; 267 + goto done; 268 + } 269 + if (!trans_done) { 270 + i2c->state = STATE_WAIT; 271 + reg = readw( 272 + &i2c->regs->twi_ctrl0_stat); 273 + writew(TWI_IRQEN | reg, 274 + &i2c->regs->twi_ctrl0_stat); 275 + } 276 + spin_unlock_irqrestore(&i2c->lock, flags); 277 + } else { 278 + spin_lock_irqsave(&i2c->lock, flags); 279 + dev_dbg(i2c->adap.dev.parent, 280 + "%s(): wait timeout\n", __func__); 281 + res = -ETIMEDOUT; 282 + goto done; 283 + } 284 + spin_lock_irqsave(&i2c->lock, flags); 285 + } 286 + } 287 + done: 288 + spin_unlock_irqrestore(&i2c->lock, flags); 289 + dev_dbg(i2c->adap.dev.parent, "%s(): result %d\n", __func__, res); 290 + return res; 291 + } 292 + 293 + static u32 netup_i2c_func(struct i2c_adapter *adap) 294 + { 295 + return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL; 296 + } 297 + 298 + static const struct i2c_algorithm netup_i2c_algorithm = { 299 + .master_xfer = netup_i2c_xfer, 300 + .functionality = netup_i2c_func, 301 + }; 302 + 303 + static struct i2c_adapter netup_i2c_adapter = { 304 + .owner = THIS_MODULE, 305 + .name = NETUP_UNIDVB_NAME, 306 + .class = I2C_CLASS_HWMON | I2C_CLASS_SPD, 307 + .algo = &netup_i2c_algorithm, 308 + }; 309 + 310 + static int netup_i2c_init(struct netup_unidvb_dev *ndev, int bus_num) 311 + { 312 + int ret; 313 + struct netup_i2c *i2c; 314 + 315 + if (bus_num < 0 || bus_num > 1) { 316 + dev_err(&ndev->pci_dev->dev, 317 + "%s(): invalid bus_num %d\n", __func__, bus_num); 318 + return -EINVAL; 319 + } 320 + i2c = &ndev->i2c[bus_num]; 321 + spin_lock_init(&i2c->lock); 322 + init_waitqueue_head(&i2c->wq); 323 + i2c->regs = (struct netup_i2c_regs *)(ndev->bmmio0 + 324 + (bus_num == 0 ? NETUP_I2C_BUS0_ADDR : NETUP_I2C_BUS1_ADDR)); 325 + netup_i2c_reset(i2c); 326 + i2c->adap = netup_i2c_adapter; 327 + i2c->adap.dev.parent = &ndev->pci_dev->dev; 328 + i2c_set_adapdata(&i2c->adap, i2c); 329 + ret = i2c_add_adapter(&i2c->adap); 330 + if (ret) { 331 + dev_err(&ndev->pci_dev->dev, 332 + "%s(): failed to add I2C adapter\n", __func__); 333 + return ret; 334 + } 335 + dev_info(&ndev->pci_dev->dev, 336 + "%s(): registered I2C bus %d at 0x%x\n", 337 + __func__, 338 + bus_num, (bus_num == 0 ? 339 + NETUP_I2C_BUS0_ADDR : 340 + NETUP_I2C_BUS1_ADDR)); 341 + return 0; 342 + } 343 + 344 + static void netup_i2c_remove(struct netup_unidvb_dev *ndev, int bus_num) 345 + { 346 + struct netup_i2c *i2c; 347 + 348 + if (bus_num < 0 || bus_num > 1) { 349 + dev_err(&ndev->pci_dev->dev, 350 + "%s(): invalid bus number %d\n", __func__, bus_num); 351 + return; 352 + } 353 + i2c = &ndev->i2c[bus_num]; 354 + netup_i2c_reset(i2c); 355 + /* remove adapter */ 356 + i2c_del_adapter(&i2c->adap); 357 + dev_info(&ndev->pci_dev->dev, 358 + "netup_i2c_remove: unregistered I2C bus %d\n", bus_num); 359 + } 360 + 361 + int netup_i2c_register(struct netup_unidvb_dev *ndev) 362 + { 363 + int ret; 364 + 365 + ret = netup_i2c_init(ndev, 0); 366 + if (ret) 367 + return ret; 368 + ret = netup_i2c_init(ndev, 1); 369 + if (ret) { 370 + netup_i2c_remove(ndev, 0); 371 + return ret; 372 + } 373 + return 0; 374 + } 375 + 376 + void netup_i2c_unregister(struct netup_unidvb_dev *ndev) 377 + { 378 + netup_i2c_remove(ndev, 0); 379 + netup_i2c_remove(ndev, 1); 380 + } 381 +
+252
drivers/media/pci/netup_unidvb/netup_unidvb_spi.c
··· 1 + /* 2 + * netup_unidvb_spi.c 3 + * 4 + * Internal SPI driver for NetUP Universal Dual DVB-CI 5 + * 6 + * Copyright (C) 2014 NetUP Inc. 7 + * Copyright (C) 2014 Sergey Kozlov <serjk@netup.ru> 8 + * Copyright (C) 2014 Abylay Ospan <aospan@netup.ru> 9 + * 10 + * This program is free software; you can redistribute it and/or modify 11 + * it under the terms of the GNU General Public License as published by 12 + * the Free Software Foundation; either version 2 of the License, or 13 + * (at your option) any later version. 14 + * 15 + * This program is distributed in the hope that it will be useful, 16 + * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 + * GNU General Public License for more details. 19 + */ 20 + 21 + #include "netup_unidvb.h" 22 + #include <linux/spi/spi.h> 23 + #include <linux/spi/flash.h> 24 + #include <linux/mtd/partitions.h> 25 + #include <mtd/mtd-abi.h> 26 + 27 + #define NETUP_SPI_CTRL_IRQ 0x1000 28 + #define NETUP_SPI_CTRL_IMASK 0x2000 29 + #define NETUP_SPI_CTRL_START 0x8000 30 + #define NETUP_SPI_CTRL_LAST_CS 0x4000 31 + 32 + #define NETUP_SPI_TIMEOUT 6000 33 + 34 + enum netup_spi_state { 35 + SPI_STATE_START, 36 + SPI_STATE_DONE, 37 + }; 38 + 39 + struct netup_spi_regs { 40 + __u8 data[1024]; 41 + __le16 control_stat; 42 + __le16 clock_divider; 43 + } __packed __aligned(1); 44 + 45 + struct netup_spi { 46 + struct device *dev; 47 + struct spi_master *master; 48 + struct netup_spi_regs *regs; 49 + u8 __iomem *mmio; 50 + spinlock_t lock; 51 + wait_queue_head_t waitq; 52 + enum netup_spi_state state; 53 + }; 54 + 55 + static char netup_spi_name[64] = "fpga"; 56 + 57 + static struct mtd_partition netup_spi_flash_partitions = { 58 + .name = netup_spi_name, 59 + .size = 0x1000000, /* 16MB */ 60 + .offset = 0, 61 + .mask_flags = MTD_CAP_ROM 62 + }; 63 + 64 + static struct flash_platform_data spi_flash_data = { 65 + .name = "netup0_m25p128", 66 + .parts = &netup_spi_flash_partitions, 67 + .nr_parts = 1, 68 + }; 69 + 70 + static struct spi_board_info netup_spi_board = { 71 + .modalias = "m25p128", 72 + .max_speed_hz = 11000000, 73 + .chip_select = 0, 74 + .mode = SPI_MODE_0, 75 + .platform_data = &spi_flash_data, 76 + }; 77 + 78 + irqreturn_t netup_spi_interrupt(struct netup_spi *spi) 79 + { 80 + u16 reg; 81 + unsigned long flags; 82 + 83 + if (!spi) { 84 + dev_dbg(&spi->master->dev, 85 + "%s(): SPI not initialized\n", __func__); 86 + return IRQ_NONE; 87 + } 88 + spin_lock_irqsave(&spi->lock, flags); 89 + reg = readw(&spi->regs->control_stat); 90 + if (!(reg & NETUP_SPI_CTRL_IRQ)) { 91 + spin_unlock_irqrestore(&spi->lock, flags); 92 + dev_dbg(&spi->master->dev, 93 + "%s(): not mine interrupt\n", __func__); 94 + return IRQ_NONE; 95 + } 96 + writew(reg | NETUP_SPI_CTRL_IRQ, &spi->regs->control_stat); 97 + reg = readw(&spi->regs->control_stat); 98 + writew(reg & ~NETUP_SPI_CTRL_IMASK, &spi->regs->control_stat); 99 + spi->state = SPI_STATE_DONE; 100 + wake_up(&spi->waitq); 101 + spin_unlock_irqrestore(&spi->lock, flags); 102 + dev_dbg(&spi->master->dev, 103 + "%s(): SPI interrupt handled\n", __func__); 104 + return IRQ_HANDLED; 105 + } 106 + 107 + static int netup_spi_transfer(struct spi_master *master, 108 + struct spi_message *msg) 109 + { 110 + struct netup_spi *spi = spi_master_get_devdata(master); 111 + struct spi_transfer *t; 112 + int result = 0; 113 + u32 tr_size; 114 + 115 + /* reset CS */ 116 + writew(NETUP_SPI_CTRL_LAST_CS, &spi->regs->control_stat); 117 + writew(0, &spi->regs->control_stat); 118 + list_for_each_entry(t, &msg->transfers, transfer_list) { 119 + tr_size = t->len; 120 + while (tr_size) { 121 + u32 frag_offset = t->len - tr_size; 122 + u32 frag_size = (tr_size > sizeof(spi->regs->data)) ? 123 + sizeof(spi->regs->data) : tr_size; 124 + int frag_last = 0; 125 + 126 + if (list_is_last(&t->transfer_list, 127 + &msg->transfers) && 128 + frag_offset + frag_size == t->len) { 129 + frag_last = 1; 130 + } 131 + if (t->tx_buf) { 132 + memcpy_toio(spi->regs->data, 133 + t->tx_buf + frag_offset, 134 + frag_size); 135 + } else { 136 + memset_io(spi->regs->data, 137 + 0, frag_size); 138 + } 139 + spi->state = SPI_STATE_START; 140 + writew((frag_size & 0x3ff) | 141 + NETUP_SPI_CTRL_IMASK | 142 + NETUP_SPI_CTRL_START | 143 + (frag_last ? NETUP_SPI_CTRL_LAST_CS : 0), 144 + &spi->regs->control_stat); 145 + dev_dbg(&spi->master->dev, 146 + "%s(): control_stat 0x%04x\n", 147 + __func__, readw(&spi->regs->control_stat)); 148 + wait_event_timeout(spi->waitq, 149 + spi->state != SPI_STATE_START, 150 + msecs_to_jiffies(NETUP_SPI_TIMEOUT)); 151 + if (spi->state == SPI_STATE_DONE) { 152 + if (t->rx_buf) { 153 + memcpy_fromio(t->rx_buf + frag_offset, 154 + spi->regs->data, frag_size); 155 + } 156 + } else { 157 + if (spi->state == SPI_STATE_START) { 158 + dev_dbg(&spi->master->dev, 159 + "%s(): transfer timeout\n", 160 + __func__); 161 + } else { 162 + dev_dbg(&spi->master->dev, 163 + "%s(): invalid state %d\n", 164 + __func__, spi->state); 165 + } 166 + result = -EIO; 167 + goto done; 168 + } 169 + tr_size -= frag_size; 170 + msg->actual_length += frag_size; 171 + } 172 + } 173 + done: 174 + msg->status = result; 175 + spi_finalize_current_message(master); 176 + return result; 177 + } 178 + 179 + static int netup_spi_setup(struct spi_device *spi) 180 + { 181 + return 0; 182 + } 183 + 184 + int netup_spi_init(struct netup_unidvb_dev *ndev) 185 + { 186 + struct spi_master *master; 187 + struct netup_spi *nspi; 188 + 189 + master = spi_alloc_master(&ndev->pci_dev->dev, 190 + sizeof(struct netup_spi)); 191 + if (!master) { 192 + dev_err(&ndev->pci_dev->dev, 193 + "%s(): unable to alloc SPI master\n", __func__); 194 + return -EINVAL; 195 + } 196 + nspi = spi_master_get_devdata(master); 197 + master->mode_bits = SPI_CPOL | SPI_CPHA | SPI_LSB_FIRST; 198 + master->bus_num = -1; 199 + master->num_chipselect = 1; 200 + master->transfer_one_message = netup_spi_transfer; 201 + master->setup = netup_spi_setup; 202 + spin_lock_init(&nspi->lock); 203 + init_waitqueue_head(&nspi->waitq); 204 + nspi->master = master; 205 + nspi->regs = (struct netup_spi_regs *)(ndev->bmmio0 + 0x4000); 206 + writew(2, &nspi->regs->clock_divider); 207 + writew(NETUP_UNIDVB_IRQ_SPI, ndev->bmmio0 + REG_IMASK_SET); 208 + ndev->spi = nspi; 209 + if (spi_register_master(master)) { 210 + ndev->spi = NULL; 211 + dev_err(&ndev->pci_dev->dev, 212 + "%s(): unable to register SPI bus\n", __func__); 213 + return -EINVAL; 214 + } 215 + snprintf(netup_spi_name, 216 + sizeof(netup_spi_name), 217 + "fpga_%02x:%02x.%01x", 218 + ndev->pci_bus, 219 + ndev->pci_slot, 220 + ndev->pci_func); 221 + if (!spi_new_device(master, &netup_spi_board)) { 222 + ndev->spi = NULL; 223 + dev_err(&ndev->pci_dev->dev, 224 + "%s(): unable to create SPI device\n", __func__); 225 + return -EINVAL; 226 + } 227 + dev_dbg(&ndev->pci_dev->dev, "%s(): SPI init OK\n", __func__); 228 + return 0; 229 + } 230 + 231 + void netup_spi_release(struct netup_unidvb_dev *ndev) 232 + { 233 + u16 reg; 234 + unsigned long flags; 235 + struct netup_spi *spi = ndev->spi; 236 + 237 + if (!spi) { 238 + dev_dbg(&spi->master->dev, 239 + "%s(): SPI not initialized\n", __func__); 240 + return; 241 + } 242 + spin_lock_irqsave(&spi->lock, flags); 243 + reg = readw(&spi->regs->control_stat); 244 + writew(reg | NETUP_SPI_CTRL_IRQ, &spi->regs->control_stat); 245 + reg = readw(&spi->regs->control_stat); 246 + writew(reg & ~NETUP_SPI_CTRL_IMASK, &spi->regs->control_stat); 247 + spin_unlock_irqrestore(&spi->lock, flags); 248 + spi_unregister_master(spi->master); 249 + ndev->spi = NULL; 250 + } 251 + 252 +
+1
drivers/media/pci/smipcie/Kconfig
··· 7 7 select DVB_TS2020 if MEDIA_SUBDRV_AUTOSELECT 8 8 select MEDIA_TUNER_M88RS6000T if MEDIA_SUBDRV_AUTOSELECT 9 9 select MEDIA_TUNER_SI2157 if MEDIA_SUBDRV_AUTOSELECT 10 + depends on RC_CORE 10 11 help 11 12 Support for cards with SMI PCIe bridge: 12 13 - DVBSky S950 V3
+3
drivers/media/pci/smipcie/Makefile
··· 1 + 2 + smipcie-objs := smipcie-main.o smipcie-ir.o 3 + 1 4 obj-$(CONFIG_DVB_SMIPCIE) += smipcie.o 2 5 3 6 ccflags-y += -Idrivers/media/tuners
+232
drivers/media/pci/smipcie/smipcie-ir.c
··· 1 + /* 2 + * SMI PCIe driver for DVBSky cards. 3 + * 4 + * Copyright (C) 2014 Max nibble <nibble.max@gmail.com> 5 + * 6 + * This program is free software; you can redistribute it and/or modify 7 + * it under the terms of the GNU General Public License as published by 8 + * the Free Software Foundation; either version 2 of the License, or 9 + * (at your option) any later version. 10 + * 11 + * This program is distributed in the hope that it will be useful, 12 + * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 + * GNU General Public License for more details. 15 + */ 16 + 17 + #include "smipcie.h" 18 + 19 + static void smi_ir_enableInterrupt(struct smi_rc *ir) 20 + { 21 + struct smi_dev *dev = ir->dev; 22 + 23 + smi_write(MSI_INT_ENA_SET, IR_X_INT); 24 + } 25 + 26 + static void smi_ir_disableInterrupt(struct smi_rc *ir) 27 + { 28 + struct smi_dev *dev = ir->dev; 29 + 30 + smi_write(MSI_INT_ENA_CLR, IR_X_INT); 31 + } 32 + 33 + static void smi_ir_clearInterrupt(struct smi_rc *ir) 34 + { 35 + struct smi_dev *dev = ir->dev; 36 + 37 + smi_write(MSI_INT_STATUS_CLR, IR_X_INT); 38 + } 39 + 40 + static void smi_ir_stop(struct smi_rc *ir) 41 + { 42 + struct smi_dev *dev = ir->dev; 43 + 44 + smi_ir_disableInterrupt(ir); 45 + smi_clear(IR_Init_Reg, 0x80); 46 + } 47 + 48 + #define BITS_PER_COMMAND 14 49 + #define GROUPS_PER_BIT 2 50 + #define IR_RC5_MIN_BIT 36 51 + #define IR_RC5_MAX_BIT 52 52 + static u32 smi_decode_rc5(u8 *pData, u8 size) 53 + { 54 + u8 index, current_bit, bit_count; 55 + u8 group_array[BITS_PER_COMMAND * GROUPS_PER_BIT + 4]; 56 + u8 group_index = 0; 57 + u32 command = 0xFFFFFFFF; 58 + 59 + group_array[group_index++] = 1; 60 + 61 + for (index = 0; index < size; index++) { 62 + 63 + current_bit = (pData[index] & 0x80) ? 1 : 0; 64 + bit_count = pData[index] & 0x7f; 65 + 66 + if ((current_bit == 1) && (bit_count >= 2*IR_RC5_MAX_BIT + 1)) { 67 + goto process_code; 68 + } else if ((bit_count >= IR_RC5_MIN_BIT) && 69 + (bit_count <= IR_RC5_MAX_BIT)) { 70 + group_array[group_index++] = current_bit; 71 + } else if ((bit_count > IR_RC5_MAX_BIT) && 72 + (bit_count <= 2*IR_RC5_MAX_BIT)) { 73 + group_array[group_index++] = current_bit; 74 + group_array[group_index++] = current_bit; 75 + } else { 76 + goto invalid_timing; 77 + } 78 + if (group_index >= BITS_PER_COMMAND*GROUPS_PER_BIT) 79 + goto process_code; 80 + 81 + if ((group_index == BITS_PER_COMMAND*GROUPS_PER_BIT - 1) 82 + && (group_array[group_index-1] == 0)) { 83 + group_array[group_index++] = 1; 84 + goto process_code; 85 + } 86 + } 87 + 88 + process_code: 89 + if (group_index == (BITS_PER_COMMAND*GROUPS_PER_BIT-1)) 90 + group_array[group_index++] = 1; 91 + 92 + if (group_index == BITS_PER_COMMAND*GROUPS_PER_BIT) { 93 + command = 0; 94 + for (index = 0; index < (BITS_PER_COMMAND*GROUPS_PER_BIT); 95 + index = index + 2) { 96 + if ((group_array[index] == 1) && 97 + (group_array[index+1] == 0)) { 98 + command |= (1 << (BITS_PER_COMMAND - 99 + (index/2) - 1)); 100 + } else if ((group_array[index] == 0) && 101 + (group_array[index+1] == 1)) { 102 + /* */ 103 + } else { 104 + command = 0xFFFFFFFF; 105 + goto invalid_timing; 106 + } 107 + } 108 + } 109 + 110 + invalid_timing: 111 + return command; 112 + } 113 + 114 + static void smi_ir_decode(struct work_struct *work) 115 + { 116 + struct smi_rc *ir = container_of(work, struct smi_rc, work); 117 + struct smi_dev *dev = ir->dev; 118 + struct rc_dev *rc_dev = ir->rc_dev; 119 + u32 dwIRControl, dwIRData, dwIRCode, scancode; 120 + u8 index, ucIRCount, readLoop, rc5_command, rc5_system, toggle; 121 + 122 + dwIRControl = smi_read(IR_Init_Reg); 123 + if (dwIRControl & rbIRVld) { 124 + ucIRCount = (u8) smi_read(IR_Data_Cnt); 125 + 126 + if (ucIRCount < 4) 127 + goto end_ir_decode; 128 + 129 + readLoop = ucIRCount/4; 130 + if (ucIRCount % 4) 131 + readLoop += 1; 132 + for (index = 0; index < readLoop; index++) { 133 + dwIRData = smi_read(IR_DATA_BUFFER_BASE + (index*4)); 134 + 135 + ir->irData[index*4 + 0] = (u8)(dwIRData); 136 + ir->irData[index*4 + 1] = (u8)(dwIRData >> 8); 137 + ir->irData[index*4 + 2] = (u8)(dwIRData >> 16); 138 + ir->irData[index*4 + 3] = (u8)(dwIRData >> 24); 139 + } 140 + dwIRCode = smi_decode_rc5(ir->irData, ucIRCount); 141 + 142 + if (dwIRCode != 0xFFFFFFFF) { 143 + rc5_command = dwIRCode & 0x3F; 144 + rc5_system = (dwIRCode & 0x7C0) >> 6; 145 + toggle = (dwIRCode & 0x800) ? 1 : 0; 146 + scancode = rc5_system << 8 | rc5_command; 147 + rc_keydown(rc_dev, RC_TYPE_RC5, scancode, toggle); 148 + } 149 + } 150 + end_ir_decode: 151 + smi_set(IR_Init_Reg, 0x04); 152 + smi_ir_enableInterrupt(ir); 153 + } 154 + 155 + /* ir functions call by main driver.*/ 156 + int smi_ir_irq(struct smi_rc *ir, u32 int_status) 157 + { 158 + int handled = 0; 159 + 160 + if (int_status & IR_X_INT) { 161 + smi_ir_disableInterrupt(ir); 162 + smi_ir_clearInterrupt(ir); 163 + schedule_work(&ir->work); 164 + handled = 1; 165 + } 166 + return handled; 167 + } 168 + 169 + void smi_ir_start(struct smi_rc *ir) 170 + { 171 + struct smi_dev *dev = ir->dev; 172 + 173 + smi_write(IR_Idle_Cnt_Low, 0x00140070); 174 + msleep(20); 175 + smi_set(IR_Init_Reg, 0x90); 176 + 177 + smi_ir_enableInterrupt(ir); 178 + } 179 + 180 + int smi_ir_init(struct smi_dev *dev) 181 + { 182 + int ret; 183 + struct rc_dev *rc_dev; 184 + struct smi_rc *ir = &dev->ir; 185 + 186 + rc_dev = rc_allocate_device(); 187 + if (!rc_dev) 188 + return -ENOMEM; 189 + 190 + /* init input device */ 191 + snprintf(ir->input_name, sizeof(ir->input_name), "IR (%s)", 192 + dev->info->name); 193 + snprintf(ir->input_phys, sizeof(ir->input_phys), "pci-%s/ir0", 194 + pci_name(dev->pci_dev)); 195 + 196 + rc_dev->driver_name = "SMI_PCIe"; 197 + rc_dev->input_phys = ir->input_phys; 198 + rc_dev->input_name = ir->input_name; 199 + rc_dev->input_id.bustype = BUS_PCI; 200 + rc_dev->input_id.version = 1; 201 + rc_dev->input_id.vendor = dev->pci_dev->subsystem_vendor; 202 + rc_dev->input_id.product = dev->pci_dev->subsystem_device; 203 + rc_dev->dev.parent = &dev->pci_dev->dev; 204 + 205 + rc_dev->driver_type = RC_DRIVER_SCANCODE; 206 + rc_dev->map_name = RC_MAP_DVBSKY; 207 + 208 + ir->rc_dev = rc_dev; 209 + ir->dev = dev; 210 + 211 + INIT_WORK(&ir->work, smi_ir_decode); 212 + smi_ir_disableInterrupt(ir); 213 + 214 + ret = rc_register_device(rc_dev); 215 + if (ret) 216 + goto ir_err; 217 + 218 + return 0; 219 + ir_err: 220 + rc_free_device(rc_dev); 221 + return ret; 222 + } 223 + 224 + void smi_ir_exit(struct smi_dev *dev) 225 + { 226 + struct smi_rc *ir = &dev->ir; 227 + struct rc_dev *rc_dev = ir->rc_dev; 228 + 229 + smi_ir_stop(ir); 230 + rc_unregister_device(rc_dev); 231 + ir->rc_dev = NULL; 232 + }
+13 -1
drivers/media/pci/smipcie/smipcie.c drivers/media/pci/smipcie/smipcie-main.c
··· 468 468 struct smi_dev *dev = dev_id; 469 469 struct smi_port *port0 = &dev->ts_port[0]; 470 470 struct smi_port *port1 = &dev->ts_port[1]; 471 + struct smi_rc *ir = &dev->ir; 471 472 int handled = 0; 472 473 473 474 u32 intr_status = smi_read(MSI_INT_STATUS); ··· 480 479 /* ts1 interrupt.*/ 481 480 if (dev->info->ts_1) 482 481 handled += smi_port_irq(port1, intr_status); 482 + 483 + /* ir interrupt.*/ 484 + handled += smi_ir_irq(ir, intr_status); 483 485 484 486 return IRQ_RETVAL(handled); 485 487 } ··· 997 993 goto err_del_port0_attach; 998 994 } 999 995 996 + ret = smi_ir_init(dev); 997 + if (ret < 0) 998 + goto err_del_port1_attach; 999 + 1000 1000 #ifdef CONFIG_PCI_MSI /* to do msi interrupt.???*/ 1001 1001 if (pci_msi_enabled()) 1002 1002 ret = pci_enable_msi(dev->pci_dev); ··· 1011 1003 ret = request_irq(dev->pci_dev->irq, smi_irq_handler, 1012 1004 IRQF_SHARED, "SMI_PCIE", dev); 1013 1005 if (ret < 0) 1014 - goto err_del_port1_attach; 1006 + goto err_del_ir; 1015 1007 1008 + smi_ir_start(&dev->ir); 1016 1009 return 0; 1017 1010 1011 + err_del_ir: 1012 + smi_ir_exit(dev); 1018 1013 err_del_port1_attach: 1019 1014 if (dev->info->ts_1) 1020 1015 smi_port_detach(&dev->ts_port[1]); ··· 1050 1039 if (dev->info->ts_0) 1051 1040 smi_port_detach(&dev->ts_port[0]); 1052 1041 1042 + smi_ir_exit(dev); 1053 1043 smi_i2c_exit(dev); 1054 1044 iounmap(dev->lmmio); 1055 1045 pci_set_drvdata(pdev, NULL);
+19
drivers/media/pci/smipcie/smipcie.h
··· 234 234 int fe_1; 235 235 }; 236 236 237 + struct smi_rc { 238 + struct smi_dev *dev; 239 + struct rc_dev *rc_dev; 240 + char input_phys[64]; 241 + char input_name[64]; 242 + struct work_struct work; 243 + u8 irData[256]; 244 + 245 + int users; 246 + }; 247 + 237 248 struct smi_port { 238 249 struct smi_dev *dev; 239 250 int idx; ··· 295 284 /* i2c */ 296 285 struct i2c_adapter i2c_bus[2]; 297 286 struct i2c_algo_bit_data i2c_bit[2]; 287 + 288 + /* ir */ 289 + struct smi_rc ir; 298 290 }; 299 291 300 292 #define smi_read(reg) readl(dev->lmmio + ((reg)>>2)) ··· 309 295 310 296 #define smi_set(reg, bit) smi_andor((reg), (bit), (bit)) 311 297 #define smi_clear(reg, bit) smi_andor((reg), (bit), 0) 298 + 299 + int smi_ir_irq(struct smi_rc *ir, u32 int_status); 300 + void smi_ir_start(struct smi_rc *ir); 301 + void smi_ir_exit(struct smi_dev *dev); 302 + int smi_ir_init(struct smi_dev *dev); 312 303 313 304 #endif /* #ifndef _SMI_PCIE_H_ */
+2 -16
drivers/media/pci/solo6x10/solo6x10-core.c
··· 134 134 135 135 static void free_solo_dev(struct solo_dev *solo_dev) 136 136 { 137 - struct pci_dev *pdev; 138 - 139 - if (!solo_dev) 140 - return; 137 + struct pci_dev *pdev = solo_dev->pdev; 141 138 142 139 if (solo_dev->dev.parent) 143 140 device_unregister(&solo_dev->dev); 144 - 145 - pdev = solo_dev->pdev; 146 - 147 - /* If we never initialized the PCI device, then nothing else 148 - * below here needs cleanup */ 149 - if (!pdev) { 150 - kfree(solo_dev); 151 - return; 152 - } 153 141 154 142 if (solo_dev->reg_base) { 155 143 /* Bring down the sub-devices first */ ··· 152 164 153 165 /* Now cleanup the PCI device */ 154 166 solo_irq_off(solo_dev, ~0); 167 + free_irq(pdev->irq, solo_dev); 155 168 pci_iounmap(pdev, solo_dev->reg_base); 156 - if (pdev->irq) 157 - free_irq(pdev->irq, solo_dev); 158 169 } 159 170 160 171 pci_release_regions(pdev); ··· 470 483 471 484 solo_dev->type = id->driver_data; 472 485 solo_dev->pdev = pdev; 473 - spin_lock_init(&solo_dev->reg_io_lock); 474 486 ret = v4l2_device_register(&pdev->dev, &solo_dev->v4l2_dev); 475 487 if (ret) 476 488 goto fail_probe;
+6 -7
drivers/media/pci/solo6x10/solo6x10-g723.c
··· 48 48 /* The solo writes to 1k byte pages, 32 pages, in the dma. Each 1k page 49 49 * is broken down to 20 * 48 byte regions (one for each channel possible) 50 50 * with the rest of the page being dummy data. */ 51 - #define G723_MAX_BUFFER (G723_PERIOD_BYTES * PERIODS_MAX) 51 + #define PERIODS G723_FDMA_PAGES 52 52 #define G723_INTR_ORDER 4 /* 0 - 4 */ 53 - #define PERIODS_MIN (1 << G723_INTR_ORDER) 54 - #define PERIODS_MAX G723_FDMA_PAGES 55 53 56 54 struct solo_snd_pcm { 57 55 int on; ··· 128 130 .rate_max = SAMPLERATE, 129 131 .channels_min = 1, 130 132 .channels_max = 1, 131 - .buffer_bytes_max = G723_MAX_BUFFER, 133 + .buffer_bytes_max = G723_PERIOD_BYTES * PERIODS, 132 134 .period_bytes_min = G723_PERIOD_BYTES, 133 135 .period_bytes_max = G723_PERIOD_BYTES, 134 - .periods_min = PERIODS_MIN, 135 - .periods_max = PERIODS_MAX, 136 + .periods_min = PERIODS, 137 + .periods_max = PERIODS, 136 138 }; 137 139 138 140 static int snd_solo_pcm_open(struct snd_pcm_substream *ss) ··· 338 340 ret = snd_pcm_lib_preallocate_pages_for_all(pcm, 339 341 SNDRV_DMA_TYPE_CONTINUOUS, 340 342 snd_dma_continuous_data(GFP_KERNEL), 341 - G723_MAX_BUFFER, G723_MAX_BUFFER); 343 + G723_PERIOD_BYTES * PERIODS, 344 + G723_PERIOD_BYTES * PERIODS); 342 345 if (ret < 0) 343 346 return ret; 344 347
+1 -25
drivers/media/pci/solo6x10/solo6x10.h
··· 199 199 int nr_ext; 200 200 u32 irq_mask; 201 201 u32 motion_mask; 202 - spinlock_t reg_io_lock; 203 202 struct v4l2_device v4l2_dev; 204 203 205 204 /* tw28xx accounting */ ··· 280 281 281 282 static inline u32 solo_reg_read(struct solo_dev *solo_dev, int reg) 282 283 { 283 - unsigned long flags; 284 - u32 ret; 285 - u16 val; 286 - 287 - spin_lock_irqsave(&solo_dev->reg_io_lock, flags); 288 - 289 - ret = readl(solo_dev->reg_base + reg); 290 - rmb(); 291 - pci_read_config_word(solo_dev->pdev, PCI_STATUS, &val); 292 - rmb(); 293 - 294 - spin_unlock_irqrestore(&solo_dev->reg_io_lock, flags); 295 - 296 - return ret; 284 + return readl(solo_dev->reg_base + reg); 297 285 } 298 286 299 287 static inline void solo_reg_write(struct solo_dev *solo_dev, int reg, 300 288 u32 data) 301 289 { 302 - unsigned long flags; 303 - u16 val; 304 - 305 - spin_lock_irqsave(&solo_dev->reg_io_lock, flags); 306 - 307 290 writel(data, solo_dev->reg_base + reg); 308 - wmb(); 309 - pci_read_config_word(solo_dev->pdev, PCI_STATUS, &val); 310 - rmb(); 311 - 312 - spin_unlock_irqrestore(&solo_dev->reg_io_lock, flags); 313 291 } 314 292 315 293 static inline void solo_irq_on(struct solo_dev *dev, u32 mask)
+1 -1
drivers/media/pci/ttpci/budget-av.c
··· 1508 1508 if (i2c_readregs(&budget_av->budget.i2c_adap, 0xa0, 0x30, mac, 6)) { 1509 1509 pr_err("KNC1-%d: Could not read MAC from KNC1 card\n", 1510 1510 budget_av->budget.dvb_adapter.num); 1511 - memset(mac, 0, 6); 1511 + eth_zero_addr(mac); 1512 1512 } else { 1513 1513 pr_info("KNC1-%d: MAC addr = %pM\n", 1514 1514 budget_av->budget.dvb_adapter.num, mac);
+4 -5
drivers/media/pci/ttpci/ttpci-eeprom.c
··· 36 36 #include <linux/module.h> 37 37 #include <linux/string.h> 38 38 #include <linux/i2c.h> 39 + #include <linux/etherdevice.h> 39 40 40 41 #include "ttpci-eeprom.h" 41 42 ··· 146 145 147 146 if (ret != 0) { /* Will only be -ENODEV */ 148 147 dprintk("Couldn't read from EEPROM: not there?\n"); 149 - memset(proposed_mac, 0, 6); 148 + eth_zero_addr(proposed_mac); 150 149 return ret; 151 150 } 152 151 ··· 158 157 dprintk( "%.2x:", encodedMAC[i]); 159 158 } 160 159 dprintk("%.2x\n", encodedMAC[19]); 161 - memset(proposed_mac, 0, 6); 160 + eth_zero_addr(proposed_mac); 162 161 return ret; 163 162 } 164 163 165 164 memcpy(proposed_mac, decodedMAC, 6); 166 - dprintk("adapter has MAC addr = %.2x:%.2x:%.2x:%.2x:%.2x:%.2x\n", 167 - decodedMAC[0], decodedMAC[1], decodedMAC[2], 168 - decodedMAC[3], decodedMAC[4], decodedMAC[5]); 165 + dprintk("adapter has MAC addr = %pM\n", decodedMAC); 169 166 return 0; 170 167 } 171 168
+11 -10
drivers/media/pci/tw68/tw68-core.c
··· 37 37 #include <linux/delay.h> 38 38 #include <linux/mutex.h> 39 39 #include <linux/dma-mapping.h> 40 + #include <linux/pci_ids.h> 40 41 #include <linux/pm.h> 41 42 42 43 #include <media/v4l2-dev.h> ··· 71 70 * added under vendor 0x1797 (Techwell Inc.) as subsystem IDs. 72 71 */ 73 72 static const struct pci_device_id tw68_pci_tbl[] = { 74 - {PCI_DEVICE(PCI_VENDOR_ID_TECHWELL, PCI_DEVICE_ID_6800)}, 75 - {PCI_DEVICE(PCI_VENDOR_ID_TECHWELL, PCI_DEVICE_ID_6801)}, 76 - {PCI_DEVICE(PCI_VENDOR_ID_TECHWELL, PCI_DEVICE_ID_6804)}, 77 - {PCI_DEVICE(PCI_VENDOR_ID_TECHWELL, PCI_DEVICE_ID_6816_1)}, 78 - {PCI_DEVICE(PCI_VENDOR_ID_TECHWELL, PCI_DEVICE_ID_6816_2)}, 79 - {PCI_DEVICE(PCI_VENDOR_ID_TECHWELL, PCI_DEVICE_ID_6816_3)}, 80 - {PCI_DEVICE(PCI_VENDOR_ID_TECHWELL, PCI_DEVICE_ID_6816_4)}, 73 + {PCI_DEVICE(PCI_VENDOR_ID_TECHWELL, PCI_DEVICE_ID_TECHWELL_6800)}, 74 + {PCI_DEVICE(PCI_VENDOR_ID_TECHWELL, PCI_DEVICE_ID_TECHWELL_6801)}, 75 + {PCI_DEVICE(PCI_VENDOR_ID_TECHWELL, PCI_DEVICE_ID_TECHWELL_6804)}, 76 + {PCI_DEVICE(PCI_VENDOR_ID_TECHWELL, PCI_DEVICE_ID_TECHWELL_6816_1)}, 77 + {PCI_DEVICE(PCI_VENDOR_ID_TECHWELL, PCI_DEVICE_ID_TECHWELL_6816_2)}, 78 + {PCI_DEVICE(PCI_VENDOR_ID_TECHWELL, PCI_DEVICE_ID_TECHWELL_6816_3)}, 79 + {PCI_DEVICE(PCI_VENDOR_ID_TECHWELL, PCI_DEVICE_ID_TECHWELL_6816_4)}, 81 80 {0,} 82 81 }; 83 82 ··· 264 263 } 265 264 266 265 switch (pci_id->device) { 267 - case PCI_DEVICE_ID_6800: /* TW6800 */ 266 + case PCI_DEVICE_ID_TECHWELL_6800: /* TW6800 */ 268 267 dev->vdecoder = TW6800; 269 268 dev->board_virqmask = TW68_VID_INTS; 270 269 break; 271 - case PCI_DEVICE_ID_6801: /* Video decoder for TW6802 */ 270 + case PCI_DEVICE_ID_TECHWELL_6801: /* Video decoder for TW6802 */ 272 271 dev->vdecoder = TW6801; 273 272 dev->board_virqmask = TW68_VID_INTS | TW68_VID_INTSX; 274 273 break; 275 - case PCI_DEVICE_ID_6804: /* Video decoder for TW6804 */ 274 + case PCI_DEVICE_ID_TECHWELL_6804: /* Video decoder for TW6804 */ 276 275 dev->vdecoder = TW6804; 277 276 dev->board_virqmask = TW68_VID_INTS | TW68_VID_INTSX; 278 277 break;
-16
drivers/media/pci/tw68/tw68.h
··· 42 42 43 43 #define UNSET (-1U) 44 44 45 - /* system vendor and device ID's */ 46 - #define PCI_VENDOR_ID_TECHWELL 0x1797 47 - #define PCI_DEVICE_ID_6800 0x6800 48 - #define PCI_DEVICE_ID_6801 0x6801 49 - #define PCI_DEVICE_ID_AUDIO2 0x6802 50 - #define PCI_DEVICE_ID_TS3 0x6803 51 - #define PCI_DEVICE_ID_6804 0x6804 52 - #define PCI_DEVICE_ID_AUDIO5 0x6805 53 - #define PCI_DEVICE_ID_TS6 0x6806 54 - 55 - /* tw6816 based cards */ 56 - #define PCI_DEVICE_ID_6816_1 0x6810 57 - #define PCI_DEVICE_ID_6816_2 0x6811 58 - #define PCI_DEVICE_ID_6816_3 0x6812 59 - #define PCI_DEVICE_ID_6816_4 0x6813 60 - 61 45 #define TW68_NORMS ( \ 62 46 V4L2_STD_NTSC | V4L2_STD_PAL | V4L2_STD_SECAM | \ 63 47 V4L2_STD_PAL_M | V4L2_STD_PAL_Nc | V4L2_STD_PAL_60)
+5 -2
drivers/media/pci/zoran/zoran.h
··· 32 32 #define _BUZ_H_ 33 33 34 34 #include <media/v4l2-device.h> 35 + #include <media/v4l2-ctrls.h> 36 + #include <media/v4l2-fh.h> 35 37 36 38 struct zoran_sync { 37 39 unsigned long frame; /* number of buffer that has been free'd */ ··· 218 216 219 217 /* zoran_fh contains per-open() settings */ 220 218 struct zoran_fh { 219 + struct v4l2_fh fh; 221 220 struct zoran *zr; 222 221 223 222 enum zoran_map_mode map_mode; /* Flag which bufferset will map by next mmap() */ ··· 271 268 272 269 struct zoran { 273 270 struct v4l2_device v4l2_dev; 271 + struct v4l2_ctrl_handler hdl; 274 272 struct video_device *video_dev; 275 273 276 274 struct i2c_adapter i2c_adapter; /* */ ··· 284 280 struct videocodec *codec; /* video codec */ 285 281 struct videocodec *vfe; /* video front end */ 286 282 287 - struct mutex resource_lock; /* prevent evil stuff */ 288 - struct mutex other_lock; /* please merge with above */ 283 + struct mutex lock; /* file ops serialize lock */ 289 284 290 285 u8 initialized; /* flag if zoran has been correctly initialized */ 291 286 int user; /* number of current users */
+8 -3
drivers/media/pci/zoran/zoran_card.c
··· 1049 1049 /* 1050 1050 * Now add the template and register the device unit. 1051 1051 */ 1052 - memcpy(zr->video_dev, &zoran_template, sizeof(zoran_template)); 1052 + *zr->video_dev = zoran_template; 1053 1053 zr->video_dev->v4l2_dev = &zr->v4l2_dev; 1054 + zr->video_dev->lock = &zr->lock; 1054 1055 strcpy(zr->video_dev->name, ZR_DEVNAME(zr)); 1055 1056 /* It's not a mem2mem device, but you can both capture and output from 1056 1057 one and the same device. This should really be split up into two ··· 1117 1116 pci_disable_device(zr->pci_dev); 1118 1117 video_unregister_device(zr->video_dev); 1119 1118 exit_free: 1119 + v4l2_ctrl_handler_free(&zr->hdl); 1120 1120 v4l2_device_unregister(&zr->v4l2_dev); 1121 1121 kfree(zr); 1122 1122 } ··· 1221 1219 zr->pci_dev = pdev; 1222 1220 zr->id = nr; 1223 1221 snprintf(ZR_DEVNAME(zr), sizeof(ZR_DEVNAME(zr)), "MJPEG[%u]", zr->id); 1222 + if (v4l2_ctrl_handler_init(&zr->hdl, 10)) 1223 + goto zr_unreg; 1224 + zr->v4l2_dev.ctrl_handler = &zr->hdl; 1224 1225 spin_lock_init(&zr->spinlock); 1225 - mutex_init(&zr->resource_lock); 1226 - mutex_init(&zr->other_lock); 1226 + mutex_init(&zr->lock); 1227 1227 if (pci_enable_device(pdev)) 1228 1228 goto zr_unreg; 1229 1229 zr->revision = zr->pci_dev->revision; ··· 1447 1443 zr_unmap: 1448 1444 iounmap(zr->zr36057_mem); 1449 1445 zr_unreg: 1446 + v4l2_ctrl_handler_free(&zr->hdl); 1450 1447 v4l2_device_unregister(&zr->v4l2_dev); 1451 1448 zr_free_mem: 1452 1449 kfree(zr);
+5 -13
drivers/media/pci/zoran/zoran_device.c
··· 31 31 #include <linux/kernel.h> 32 32 #include <linux/module.h> 33 33 #include <linux/vmalloc.h> 34 + #include <linux/ktime.h> 34 35 35 36 #include <linux/interrupt.h> 36 37 #include <linux/proc_fs.h> ··· 182 181 } 183 182 } 184 183 185 - static inline unsigned long 186 - get_time (void) 187 - { 188 - struct timeval tv; 189 - 190 - do_gettimeofday(&tv); 191 - return (1000000 * tv.tv_sec + tv.tv_usec); 192 - } 193 - 194 184 void 195 185 detect_guest_activity (struct zoran *zr) 196 186 { 197 187 int timeout, i, j, res, guest[8], guest0[8], change[8][3]; 198 - unsigned long t0, t1; 188 + ktime_t t0, t1; 199 189 200 190 dump_guests(zr); 201 191 printk(KERN_INFO "%s: Detecting guests activity, please wait...\n", ··· 197 205 198 206 timeout = 0; 199 207 j = 0; 200 - t0 = get_time(); 208 + t0 = ktime_get(); 201 209 while (timeout < 10000) { 202 210 udelay(10); 203 211 timeout++; 204 212 for (i = 1; (i < 8) && (j < 8); i++) { 205 213 res = post_office_read(zr, i, 0); 206 214 if (res != guest[i]) { 207 - t1 = get_time(); 208 - change[j][0] = (t1 - t0); 215 + t1 = ktime_get(); 216 + change[j][0] = ktime_to_us(ktime_sub(t1, t0)); 209 217 t0 = t1; 210 218 change[j][1] = i; 211 219 change[j][2] = res;
+70 -274
drivers/media/pci/zoran/zoran_driver.c
··· 61 61 #include <linux/videodev2.h> 62 62 #include <media/v4l2-common.h> 63 63 #include <media/v4l2-ioctl.h> 64 + #include <media/v4l2-event.h> 64 65 #include "videocodec.h" 65 66 66 67 #include <asm/byteorder.h> ··· 593 592 return -EPROTO; 594 593 } 595 594 595 + mutex_unlock(&zr->lock); 596 596 /* wait on this buffer to get ready */ 597 597 if (!wait_event_interruptible_timeout(zr->v4l_capq, 598 - (zr->v4l_buffers.buffer[frame].state != BUZ_STATE_PEND), 10*HZ)) 598 + (zr->v4l_buffers.buffer[frame].state != BUZ_STATE_PEND), 10*HZ)) { 599 + mutex_lock(&zr->lock); 599 600 return -ETIME; 601 + } 602 + mutex_lock(&zr->lock); 600 603 if (signal_pending(current)) 601 604 return -ERESTARTSYS; 602 605 ··· 788 783 ZR_DEVNAME(zr), __func__); 789 784 return -EINVAL; 790 785 } 786 + mutex_unlock(&zr->lock); 791 787 if (!wait_event_interruptible_timeout(zr->jpg_capq, 792 788 (zr->jpg_que_tail != zr->jpg_dma_tail || 793 789 zr->jpg_dma_tail == zr->jpg_dma_head), ··· 799 793 udelay(1); 800 794 zr->codec->control(zr->codec, CODEC_G_STATUS, 801 795 sizeof(isr), &isr); 796 + mutex_lock(&zr->lock); 802 797 dprintk(1, 803 798 KERN_ERR 804 799 "%s: %s - timeout: codec isr=0x%02x\n", ··· 808 801 return -ETIME; 809 802 810 803 } 804 + mutex_lock(&zr->lock); 811 805 if (signal_pending(current)) 812 806 return -ERESTARTSYS; 813 807 ··· 919 911 dprintk(2, KERN_INFO "%s: %s(%s, pid=[%d]), users(-)=%d\n", 920 912 ZR_DEVNAME(zr), __func__, current->comm, task_pid_nr(current), zr->user + 1); 921 913 922 - mutex_lock(&zr->other_lock); 914 + mutex_lock(&zr->lock); 923 915 924 916 if (zr->user >= 2048) { 925 917 dprintk(1, KERN_ERR "%s: too many users (%d) on device\n", ··· 938 930 res = -ENOMEM; 939 931 goto fail_unlock; 940 932 } 933 + v4l2_fh_init(&fh->fh, video_devdata(file)); 934 + 941 935 /* used to be BUZ_MAX_WIDTH/HEIGHT, but that gives overflows 942 936 * on norm-change! */ 943 937 fh->overlay_mask = ··· 956 946 if (zr->user++ == 0) 957 947 first_open = 1; 958 948 959 - /*mutex_unlock(&zr->resource_lock);*/ 960 - 961 949 /* default setup - TODO: look at flags */ 962 950 if (first_open) { /* First device open */ 963 951 zr36057_restart(zr); ··· 969 961 file->private_data = fh; 970 962 fh->zr = zr; 971 963 zoran_open_init_session(fh); 972 - mutex_unlock(&zr->other_lock); 964 + v4l2_fh_add(&fh->fh); 965 + mutex_unlock(&zr->lock); 973 966 974 967 return 0; 975 968 976 969 fail_fh: 977 970 kfree(fh); 978 971 fail_unlock: 979 - mutex_unlock(&zr->other_lock); 972 + mutex_unlock(&zr->lock); 980 973 981 974 dprintk(2, KERN_INFO "%s: open failed (%d), users(-)=%d\n", 982 975 ZR_DEVNAME(zr), res, zr->user); ··· 996 987 997 988 /* kernel locks (fs/device.c), so don't do that ourselves 998 989 * (prevents deadlocks) */ 999 - mutex_lock(&zr->other_lock); 990 + mutex_lock(&zr->lock); 1000 991 1001 992 zoran_close_end_session(fh); 1002 993 ··· 1030 1021 encoder_call(zr, video, s_routing, 2, 0, 0); 1031 1022 } 1032 1023 } 1033 - mutex_unlock(&zr->other_lock); 1024 + mutex_unlock(&zr->lock); 1034 1025 1035 - file->private_data = NULL; 1026 + v4l2_fh_del(&fh->fh); 1027 + v4l2_fh_exit(&fh->fh); 1036 1028 kfree(fh->overlay_mask); 1037 1029 kfree(fh); 1038 1030 1039 1031 dprintk(4, KERN_INFO "%s: %s done\n", ZR_DEVNAME(zr), __func__); 1040 1032 1041 1033 return 0; 1042 - } 1043 - 1044 - 1045 - static ssize_t 1046 - zoran_read (struct file *file, 1047 - char __user *data, 1048 - size_t count, 1049 - loff_t *ppos) 1050 - { 1051 - /* we simply don't support read() (yet)... */ 1052 - 1053 - return -EINVAL; 1054 - } 1055 - 1056 - static ssize_t 1057 - zoran_write (struct file *file, 1058 - const char __user *data, 1059 - size_t count, 1060 - loff_t *ppos) 1061 - { 1062 - /* ...and the same goes for write() */ 1063 - 1064 - return -EINVAL; 1065 1034 } 1066 1035 1067 1036 static int setup_fbuffer(struct zoran_fh *fh, ··· 1510 1523 struct zoran_fh *fh = __fh; 1511 1524 struct zoran *zr = fh->zr; 1512 1525 1513 - memset(cap, 0, sizeof(*cap)); 1514 1526 strncpy(cap->card, ZR_DEVNAME(zr), sizeof(cap->card)-1); 1515 1527 strncpy(cap->driver, "zoran", sizeof(cap->driver)-1); 1516 1528 snprintf(cap->bus_info, sizeof(cap->bus_info), "PCI:%s", ··· 1569 1583 struct v4l2_format *fmt) 1570 1584 { 1571 1585 struct zoran_fh *fh = __fh; 1572 - struct zoran *zr = fh->zr; 1573 - 1574 - mutex_lock(&zr->resource_lock); 1575 1586 1576 1587 fmt->fmt.pix.width = fh->jpg_settings.img_width / fh->jpg_settings.HorDcm; 1577 1588 fmt->fmt.pix.height = fh->jpg_settings.img_height * 2 / ··· 1584 1601 fmt->fmt.pix.bytesperline = 0; 1585 1602 fmt->fmt.pix.colorspace = V4L2_COLORSPACE_SMPTE170M; 1586 1603 1587 - mutex_unlock(&zr->resource_lock); 1588 1604 return 0; 1589 1605 } 1590 1606 ··· 1596 1614 if (fh->map_mode != ZORAN_MAP_MODE_RAW) 1597 1615 return zoran_g_fmt_vid_out(file, fh, fmt); 1598 1616 1599 - mutex_lock(&zr->resource_lock); 1600 1617 fmt->fmt.pix.width = fh->v4l_settings.width; 1601 1618 fmt->fmt.pix.height = fh->v4l_settings.height; 1602 1619 fmt->fmt.pix.sizeimage = fh->v4l_settings.bytesperline * ··· 1607 1626 fmt->fmt.pix.field = V4L2_FIELD_INTERLACED; 1608 1627 else 1609 1628 fmt->fmt.pix.field = V4L2_FIELD_TOP; 1610 - mutex_unlock(&zr->resource_lock); 1611 1629 return 0; 1612 1630 } 1613 1631 ··· 1615 1635 { 1616 1636 struct zoran_fh *fh = __fh; 1617 1637 struct zoran *zr = fh->zr; 1618 - 1619 - mutex_lock(&zr->resource_lock); 1620 1638 1621 1639 fmt->fmt.win.w.left = fh->overlay_settings.x; 1622 1640 fmt->fmt.win.w.top = fh->overlay_settings.y; ··· 1625 1647 else 1626 1648 fmt->fmt.win.field = V4L2_FIELD_TOP; 1627 1649 1628 - mutex_unlock(&zr->resource_lock); 1629 1650 return 0; 1630 1651 } 1631 1652 ··· 1633 1656 { 1634 1657 struct zoran_fh *fh = __fh; 1635 1658 struct zoran *zr = fh->zr; 1636 - 1637 - mutex_lock(&zr->resource_lock); 1638 1659 1639 1660 if (fmt->fmt.win.w.width > BUZ_MAX_WIDTH) 1640 1661 fmt->fmt.win.w.width = BUZ_MAX_WIDTH; ··· 1643 1668 if (fmt->fmt.win.w.height < BUZ_MIN_HEIGHT) 1644 1669 fmt->fmt.win.w.height = BUZ_MIN_HEIGHT; 1645 1670 1646 - mutex_unlock(&zr->resource_lock); 1647 1671 return 0; 1648 1672 } 1649 1673 ··· 1657 1683 if (fmt->fmt.pix.pixelformat != V4L2_PIX_FMT_MJPEG) 1658 1684 return -EINVAL; 1659 1685 1660 - mutex_lock(&zr->resource_lock); 1661 1686 settings = fh->jpg_settings; 1662 1687 1663 1688 /* we actually need to set 'real' parameters now */ ··· 1691 1718 /* check */ 1692 1719 res = zoran_check_jpg_settings(zr, &settings, 1); 1693 1720 if (res) 1694 - goto tryfmt_unlock_and_return; 1721 + return res; 1695 1722 1696 1723 /* tell the user what we actually did */ 1697 1724 fmt->fmt.pix.width = settings.img_width / settings.HorDcm; ··· 1707 1734 fmt->fmt.pix.sizeimage = zoran_v4l2_calc_bufsize(&settings); 1708 1735 fmt->fmt.pix.bytesperline = 0; 1709 1736 fmt->fmt.pix.colorspace = V4L2_COLORSPACE_SMPTE170M; 1710 - tryfmt_unlock_and_return: 1711 - mutex_unlock(&zr->resource_lock); 1712 1737 return res; 1713 1738 } 1714 1739 ··· 1721 1750 if (fmt->fmt.pix.pixelformat == V4L2_PIX_FMT_MJPEG) 1722 1751 return zoran_try_fmt_vid_out(file, fh, fmt); 1723 1752 1724 - mutex_lock(&zr->resource_lock); 1725 - 1726 1753 for (i = 0; i < NUM_FORMATS; i++) 1727 1754 if (zoran_formats[i].fourcc == fmt->fmt.pix.pixelformat) 1728 1755 break; 1729 1756 1730 - if (i == NUM_FORMATS) { 1731 - mutex_unlock(&zr->resource_lock); 1757 + if (i == NUM_FORMATS) 1732 1758 return -EINVAL; 1733 - } 1734 1759 1735 1760 bpp = DIV_ROUND_UP(zoran_formats[i].depth, 8); 1736 1761 v4l_bound_align_image( 1737 1762 &fmt->fmt.pix.width, BUZ_MIN_WIDTH, BUZ_MAX_WIDTH, bpp == 2 ? 1 : 2, 1738 1763 &fmt->fmt.pix.height, BUZ_MIN_HEIGHT, BUZ_MAX_HEIGHT, 0, 0); 1739 - mutex_unlock(&zr->resource_lock); 1740 - 1741 1764 return 0; 1742 1765 } 1743 1766 ··· 1739 1774 struct v4l2_format *fmt) 1740 1775 { 1741 1776 struct zoran_fh *fh = __fh; 1742 - struct zoran *zr = fh->zr; 1743 1777 int res; 1744 1778 1745 1779 dprintk(3, "x=%d, y=%d, w=%d, h=%d, cnt=%d, map=0x%p\n", ··· 1747 1783 fmt->fmt.win.w.height, 1748 1784 fmt->fmt.win.clipcount, 1749 1785 fmt->fmt.win.bitmap); 1750 - mutex_lock(&zr->resource_lock); 1751 1786 res = setup_window(fh, fmt->fmt.win.w.left, fmt->fmt.win.w.top, 1752 1787 fmt->fmt.win.w.width, fmt->fmt.win.w.height, 1753 1788 (struct v4l2_clip __user *)fmt->fmt.win.clips, 1754 1789 fmt->fmt.win.clipcount, fmt->fmt.win.bitmap); 1755 - mutex_unlock(&zr->resource_lock); 1756 1790 return res; 1757 1791 } 1758 1792 ··· 1770 1808 if (fmt->fmt.pix.pixelformat != V4L2_PIX_FMT_MJPEG) 1771 1809 return -EINVAL; 1772 1810 1773 - mutex_lock(&zr->resource_lock); 1774 - 1775 1811 if (fh->buffers.allocated) { 1776 1812 dprintk(1, KERN_ERR "%s: VIDIOC_S_FMT - cannot change capture mode\n", 1777 1813 ZR_DEVNAME(zr)); 1778 1814 res = -EBUSY; 1779 - goto sfmtjpg_unlock_and_return; 1815 + return res; 1780 1816 } 1781 1817 1782 1818 settings = fh->jpg_settings; ··· 1811 1851 /* check */ 1812 1852 res = zoran_check_jpg_settings(zr, &settings, 0); 1813 1853 if (res) 1814 - goto sfmtjpg_unlock_and_return; 1854 + return res; 1815 1855 1816 1856 /* it's ok, so set them */ 1817 1857 fh->jpg_settings = settings; ··· 1832 1872 fmt->fmt.pix.bytesperline = 0; 1833 1873 fmt->fmt.pix.sizeimage = fh->buffers.buffer_size; 1834 1874 fmt->fmt.pix.colorspace = V4L2_COLORSPACE_SMPTE170M; 1835 - 1836 - sfmtjpg_unlock_and_return: 1837 - mutex_unlock(&zr->resource_lock); 1838 1875 return res; 1839 1876 } 1840 1877 ··· 1855 1898 return -EINVAL; 1856 1899 } 1857 1900 1858 - mutex_lock(&zr->resource_lock); 1859 - 1860 1901 if ((fh->map_mode != ZORAN_MAP_MODE_RAW && fh->buffers.allocated) || 1861 1902 fh->buffers.active != ZORAN_FREE) { 1862 1903 dprintk(1, KERN_ERR "%s: VIDIOC_S_FMT - cannot change capture mode\n", 1863 1904 ZR_DEVNAME(zr)); 1864 1905 res = -EBUSY; 1865 - goto sfmtv4l_unlock_and_return; 1906 + return res; 1866 1907 } 1867 1908 if (fmt->fmt.pix.height > BUZ_MAX_HEIGHT) 1868 1909 fmt->fmt.pix.height = BUZ_MAX_HEIGHT; ··· 1872 1917 res = zoran_v4l_set_format(fh, fmt->fmt.pix.width, fmt->fmt.pix.height, 1873 1918 &zoran_formats[i]); 1874 1919 if (res) 1875 - goto sfmtv4l_unlock_and_return; 1920 + return res; 1876 1921 1877 1922 /* tell the user the results/missing stuff */ 1878 1923 fmt->fmt.pix.bytesperline = fh->v4l_settings.bytesperline; ··· 1882 1927 fmt->fmt.pix.field = V4L2_FIELD_INTERLACED; 1883 1928 else 1884 1929 fmt->fmt.pix.field = V4L2_FIELD_TOP; 1885 - 1886 - sfmtv4l_unlock_and_return: 1887 - mutex_unlock(&zr->resource_lock); 1888 1930 return res; 1889 1931 } 1890 1932 ··· 1892 1940 struct zoran *zr = fh->zr; 1893 1941 1894 1942 memset(fb, 0, sizeof(*fb)); 1895 - mutex_lock(&zr->resource_lock); 1896 1943 fb->base = zr->vbuf_base; 1897 1944 fb->fmt.width = zr->vbuf_width; 1898 1945 fb->fmt.height = zr->vbuf_height; 1899 1946 if (zr->overlay_settings.format) 1900 1947 fb->fmt.pixelformat = fh->overlay_settings.format->fourcc; 1901 1948 fb->fmt.bytesperline = zr->vbuf_bytesperline; 1902 - mutex_unlock(&zr->resource_lock); 1903 1949 fb->fmt.colorspace = V4L2_COLORSPACE_SRGB; 1904 1950 fb->fmt.field = V4L2_FIELD_INTERLACED; 1905 1951 fb->capability = V4L2_FBUF_CAP_LIST_CLIPPING; ··· 1923 1973 return -EINVAL; 1924 1974 } 1925 1975 1926 - mutex_lock(&zr->resource_lock); 1927 1976 res = setup_fbuffer(fh, fb->base, &zoran_formats[i], fb->fmt.width, 1928 1977 fb->fmt.height, fb->fmt.bytesperline); 1929 - mutex_unlock(&zr->resource_lock); 1930 1978 1931 1979 return res; 1932 1980 } ··· 1932 1984 static int zoran_overlay(struct file *file, void *__fh, unsigned int on) 1933 1985 { 1934 1986 struct zoran_fh *fh = __fh; 1935 - struct zoran *zr = fh->zr; 1936 1987 int res; 1937 1988 1938 - mutex_lock(&zr->resource_lock); 1939 1989 res = setup_overlay(fh, on); 1940 - mutex_unlock(&zr->resource_lock); 1941 1990 1942 1991 return res; 1943 1992 } ··· 1958 2013 if (req->count == 0) 1959 2014 return zoran_streamoff(file, fh, req->type); 1960 2015 1961 - mutex_lock(&zr->resource_lock); 1962 2016 if (fh->buffers.allocated) { 1963 2017 dprintk(2, 1964 2018 KERN_ERR 1965 2019 "%s: VIDIOC_REQBUFS - buffers already allocated\n", 1966 2020 ZR_DEVNAME(zr)); 1967 2021 res = -EBUSY; 1968 - goto v4l2reqbuf_unlock_and_return; 2022 + return res; 1969 2023 } 1970 2024 1971 2025 if (fh->map_mode == ZORAN_MAP_MODE_RAW && ··· 1981 2037 1982 2038 if (v4l_fbuffer_alloc(fh)) { 1983 2039 res = -ENOMEM; 1984 - goto v4l2reqbuf_unlock_and_return; 2040 + return res; 1985 2041 } 1986 2042 } else if (fh->map_mode == ZORAN_MAP_MODE_JPG_REC || 1987 2043 fh->map_mode == ZORAN_MAP_MODE_JPG_PLAY) { ··· 1998 2054 1999 2055 if (jpg_fbuffer_alloc(fh)) { 2000 2056 res = -ENOMEM; 2001 - goto v4l2reqbuf_unlock_and_return; 2057 + return res; 2002 2058 } 2003 2059 } else { 2004 2060 dprintk(1, ··· 2006 2062 "%s: VIDIOC_REQBUFS - unknown type %d\n", 2007 2063 ZR_DEVNAME(zr), req->type); 2008 2064 res = -EINVAL; 2009 - goto v4l2reqbuf_unlock_and_return; 2065 + return res; 2010 2066 } 2011 - v4l2reqbuf_unlock_and_return: 2012 - mutex_unlock(&zr->resource_lock); 2013 - 2014 2067 return res; 2015 2068 } 2016 2069 2017 2070 static int zoran_querybuf(struct file *file, void *__fh, struct v4l2_buffer *buf) 2018 2071 { 2019 2072 struct zoran_fh *fh = __fh; 2020 - struct zoran *zr = fh->zr; 2021 2073 int res; 2022 2074 2023 - mutex_lock(&zr->resource_lock); 2024 2075 res = zoran_v4l2_buffer_status(fh, buf, buf->index); 2025 - mutex_unlock(&zr->resource_lock); 2026 2076 2027 2077 return res; 2028 2078 } ··· 2027 2089 struct zoran *zr = fh->zr; 2028 2090 int res = 0, codec_mode, buf_type; 2029 2091 2030 - mutex_lock(&zr->resource_lock); 2031 - 2032 2092 switch (fh->map_mode) { 2033 2093 case ZORAN_MAP_MODE_RAW: 2034 2094 if (buf->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) { ··· 2034 2098 "%s: VIDIOC_QBUF - invalid buf->type=%d for map_mode=%d\n", 2035 2099 ZR_DEVNAME(zr), buf->type, fh->map_mode); 2036 2100 res = -EINVAL; 2037 - goto qbuf_unlock_and_return; 2101 + return res; 2038 2102 } 2039 2103 2040 2104 res = zoran_v4l_queue_frame(fh, buf->index); 2041 2105 if (res) 2042 - goto qbuf_unlock_and_return; 2106 + return res; 2043 2107 if (!zr->v4l_memgrab_active && fh->buffers.active == ZORAN_LOCKED) 2044 2108 zr36057_set_memgrab(zr, 1); 2045 2109 break; ··· 2059 2123 "%s: VIDIOC_QBUF - invalid buf->type=%d for map_mode=%d\n", 2060 2124 ZR_DEVNAME(zr), buf->type, fh->map_mode); 2061 2125 res = -EINVAL; 2062 - goto qbuf_unlock_and_return; 2126 + return res; 2063 2127 } 2064 2128 2065 2129 res = zoran_jpg_queue_frame(fh, buf->index, codec_mode); 2066 2130 if (res != 0) 2067 - goto qbuf_unlock_and_return; 2131 + return res; 2068 2132 if (zr->codec_mode == BUZ_MODE_IDLE && 2069 2133 fh->buffers.active == ZORAN_LOCKED) 2070 2134 zr36057_enable_jpg(zr, codec_mode); ··· 2078 2142 res = -EINVAL; 2079 2143 break; 2080 2144 } 2081 - qbuf_unlock_and_return: 2082 - mutex_unlock(&zr->resource_lock); 2083 - 2084 2145 return res; 2085 2146 } 2086 2147 ··· 2087 2154 struct zoran *zr = fh->zr; 2088 2155 int res = 0, buf_type, num = -1; /* compiler borks here (?) */ 2089 2156 2090 - mutex_lock(&zr->resource_lock); 2091 - 2092 2157 switch (fh->map_mode) { 2093 2158 case ZORAN_MAP_MODE_RAW: 2094 2159 if (buf->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) { ··· 2094 2163 "%s: VIDIOC_QBUF - invalid buf->type=%d for map_mode=%d\n", 2095 2164 ZR_DEVNAME(zr), buf->type, fh->map_mode); 2096 2165 res = -EINVAL; 2097 - goto dqbuf_unlock_and_return; 2166 + return res; 2098 2167 } 2099 2168 2100 2169 num = zr->v4l_pend[zr->v4l_sync_tail & V4L_MASK_FRAME]; 2101 2170 if (file->f_flags & O_NONBLOCK && 2102 2171 zr->v4l_buffers.buffer[num].state != BUZ_STATE_DONE) { 2103 2172 res = -EAGAIN; 2104 - goto dqbuf_unlock_and_return; 2173 + return res; 2105 2174 } 2106 2175 res = v4l_sync(fh, num); 2107 2176 if (res) 2108 - goto dqbuf_unlock_and_return; 2177 + return res; 2109 2178 zr->v4l_sync_tail++; 2110 2179 res = zoran_v4l2_buffer_status(fh, buf, num); 2111 2180 break; ··· 2125 2194 "%s: VIDIOC_QBUF - invalid buf->type=%d for map_mode=%d\n", 2126 2195 ZR_DEVNAME(zr), buf->type, fh->map_mode); 2127 2196 res = -EINVAL; 2128 - goto dqbuf_unlock_and_return; 2197 + return res; 2129 2198 } 2130 2199 2131 2200 num = zr->jpg_pend[zr->jpg_que_tail & BUZ_MASK_FRAME]; ··· 2133 2202 if (file->f_flags & O_NONBLOCK && 2134 2203 zr->jpg_buffers.buffer[num].state != BUZ_STATE_DONE) { 2135 2204 res = -EAGAIN; 2136 - goto dqbuf_unlock_and_return; 2205 + return res; 2137 2206 } 2138 2207 bs.frame = 0; /* suppress compiler warning */ 2139 2208 res = jpg_sync(fh, &bs); 2140 2209 if (res) 2141 - goto dqbuf_unlock_and_return; 2210 + return res; 2142 2211 res = zoran_v4l2_buffer_status(fh, buf, bs.frame); 2143 2212 break; 2144 2213 } ··· 2150 2219 res = -EINVAL; 2151 2220 break; 2152 2221 } 2153 - dqbuf_unlock_and_return: 2154 - mutex_unlock(&zr->resource_lock); 2155 - 2156 2222 return res; 2157 2223 } 2158 2224 ··· 2159 2231 struct zoran *zr = fh->zr; 2160 2232 int res = 0; 2161 2233 2162 - mutex_lock(&zr->resource_lock); 2163 - 2164 2234 switch (fh->map_mode) { 2165 2235 case ZORAN_MAP_MODE_RAW: /* raw capture */ 2166 2236 if (zr->v4l_buffers.active != ZORAN_ACTIVE || 2167 2237 fh->buffers.active != ZORAN_ACTIVE) { 2168 2238 res = -EBUSY; 2169 - goto strmon_unlock_and_return; 2239 + return res; 2170 2240 } 2171 2241 2172 2242 zr->v4l_buffers.active = fh->buffers.active = ZORAN_LOCKED; ··· 2183 2257 if (zr->jpg_buffers.active != ZORAN_ACTIVE || 2184 2258 fh->buffers.active != ZORAN_ACTIVE) { 2185 2259 res = -EBUSY; 2186 - goto strmon_unlock_and_return; 2260 + return res; 2187 2261 } 2188 2262 2189 2263 zr->jpg_buffers.active = fh->buffers.active = ZORAN_LOCKED; ··· 2202 2276 res = -EINVAL; 2203 2277 break; 2204 2278 } 2205 - strmon_unlock_and_return: 2206 - mutex_unlock(&zr->resource_lock); 2207 - 2208 2279 return res; 2209 2280 } 2210 2281 ··· 2212 2289 int i, res = 0; 2213 2290 unsigned long flags; 2214 2291 2215 - mutex_lock(&zr->resource_lock); 2216 - 2217 2292 switch (fh->map_mode) { 2218 2293 case ZORAN_MAP_MODE_RAW: /* raw capture */ 2219 2294 if (fh->buffers.active == ZORAN_FREE && 2220 2295 zr->v4l_buffers.active != ZORAN_FREE) { 2221 2296 res = -EPERM; /* stay off other's settings! */ 2222 - goto strmoff_unlock_and_return; 2297 + return res; 2223 2298 } 2224 2299 if (zr->v4l_buffers.active == ZORAN_FREE) 2225 - goto strmoff_unlock_and_return; 2300 + return res; 2226 2301 2227 2302 spin_lock_irqsave(&zr->spinlock, flags); 2228 2303 /* unload capture */ ··· 2248 2327 if (fh->buffers.active == ZORAN_FREE && 2249 2328 zr->jpg_buffers.active != ZORAN_FREE) { 2250 2329 res = -EPERM; /* stay off other's settings! */ 2251 - goto strmoff_unlock_and_return; 2330 + return res; 2252 2331 } 2253 2332 if (zr->jpg_buffers.active == ZORAN_FREE) 2254 - goto strmoff_unlock_and_return; 2333 + return res; 2255 2334 2256 2335 res = jpg_qbuf(fh, -1, 2257 2336 (fh->map_mode == ZORAN_MAP_MODE_JPG_REC) ? 2258 2337 BUZ_MODE_MOTION_COMPRESS : 2259 2338 BUZ_MODE_MOTION_DECOMPRESS); 2260 2339 if (res) 2261 - goto strmoff_unlock_and_return; 2340 + return res; 2262 2341 break; 2263 2342 default: 2264 2343 dprintk(1, KERN_ERR ··· 2267 2346 res = -EINVAL; 2268 2347 break; 2269 2348 } 2270 - strmoff_unlock_and_return: 2271 - mutex_unlock(&zr->resource_lock); 2272 - 2273 2349 return res; 2274 2350 } 2275 - 2276 - static int zoran_queryctrl(struct file *file, void *__fh, 2277 - struct v4l2_queryctrl *ctrl) 2278 - { 2279 - struct zoran_fh *fh = __fh; 2280 - struct zoran *zr = fh->zr; 2281 - 2282 - /* we only support hue/saturation/contrast/brightness */ 2283 - if (ctrl->id < V4L2_CID_BRIGHTNESS || 2284 - ctrl->id > V4L2_CID_HUE) 2285 - return -EINVAL; 2286 - 2287 - decoder_call(zr, core, queryctrl, ctrl); 2288 - 2289 - return 0; 2290 - } 2291 - 2292 - static int zoran_g_ctrl(struct file *file, void *__fh, struct v4l2_control *ctrl) 2293 - { 2294 - struct zoran_fh *fh = __fh; 2295 - struct zoran *zr = fh->zr; 2296 - 2297 - /* we only support hue/saturation/contrast/brightness */ 2298 - if (ctrl->id < V4L2_CID_BRIGHTNESS || 2299 - ctrl->id > V4L2_CID_HUE) 2300 - return -EINVAL; 2301 - 2302 - mutex_lock(&zr->resource_lock); 2303 - decoder_call(zr, core, g_ctrl, ctrl); 2304 - mutex_unlock(&zr->resource_lock); 2305 - 2306 - return 0; 2307 - } 2308 - 2309 - static int zoran_s_ctrl(struct file *file, void *__fh, struct v4l2_control *ctrl) 2310 - { 2311 - struct zoran_fh *fh = __fh; 2312 - struct zoran *zr = fh->zr; 2313 - 2314 - /* we only support hue/saturation/contrast/brightness */ 2315 - if (ctrl->id < V4L2_CID_BRIGHTNESS || 2316 - ctrl->id > V4L2_CID_HUE) 2317 - return -EINVAL; 2318 - 2319 - mutex_lock(&zr->resource_lock); 2320 - decoder_call(zr, core, s_ctrl, ctrl); 2321 - mutex_unlock(&zr->resource_lock); 2322 - 2323 - return 0; 2324 - } 2325 - 2326 2351 static int zoran_g_std(struct file *file, void *__fh, v4l2_std_id *std) 2327 2352 { 2328 2353 struct zoran_fh *fh = __fh; 2329 2354 struct zoran *zr = fh->zr; 2330 2355 2331 - mutex_lock(&zr->resource_lock); 2332 2356 *std = zr->norm; 2333 - mutex_unlock(&zr->resource_lock); 2334 2357 return 0; 2335 2358 } 2336 2359 ··· 2284 2419 struct zoran *zr = fh->zr; 2285 2420 int res = 0; 2286 2421 2287 - mutex_lock(&zr->resource_lock); 2288 2422 res = zoran_set_norm(zr, std); 2289 2423 if (res) 2290 - goto sstd_unlock_and_return; 2424 + return res; 2291 2425 2292 2426 res = wait_grab_pending(zr); 2293 - sstd_unlock_and_return: 2294 - mutex_unlock(&zr->resource_lock); 2295 2427 return res; 2296 2428 } 2297 2429 ··· 2307 2445 inp->std = V4L2_STD_ALL; 2308 2446 2309 2447 /* Get status of video decoder */ 2310 - mutex_lock(&zr->resource_lock); 2311 2448 decoder_call(zr, video, g_input_status, &inp->status); 2312 - mutex_unlock(&zr->resource_lock); 2313 2449 return 0; 2314 2450 } 2315 2451 ··· 2316 2456 struct zoran_fh *fh = __fh; 2317 2457 struct zoran *zr = fh->zr; 2318 2458 2319 - mutex_lock(&zr->resource_lock); 2320 2459 *input = zr->input; 2321 - mutex_unlock(&zr->resource_lock); 2322 2460 2323 2461 return 0; 2324 2462 } ··· 2327 2469 struct zoran *zr = fh->zr; 2328 2470 int res; 2329 2471 2330 - mutex_lock(&zr->resource_lock); 2331 2472 res = zoran_set_input(zr, input); 2332 2473 if (res) 2333 - goto sinput_unlock_and_return; 2474 + return res; 2334 2475 2335 2476 /* Make sure the changes come into effect */ 2336 2477 res = wait_grab_pending(zr); 2337 - sinput_unlock_and_return: 2338 - mutex_unlock(&zr->resource_lock); 2339 2478 return res; 2340 2479 } 2341 2480 ··· 2375 2520 memset(cropcap, 0, sizeof(*cropcap)); 2376 2521 cropcap->type = type; 2377 2522 2378 - mutex_lock(&zr->resource_lock); 2379 - 2380 2523 if (cropcap->type != V4L2_BUF_TYPE_VIDEO_OUTPUT && 2381 2524 (cropcap->type != V4L2_BUF_TYPE_VIDEO_CAPTURE || 2382 2525 fh->map_mode == ZORAN_MAP_MODE_RAW)) { ··· 2382 2529 "%s: VIDIOC_CROPCAP - subcapture only supported for compressed capture\n", 2383 2530 ZR_DEVNAME(zr)); 2384 2531 res = -EINVAL; 2385 - goto cropcap_unlock_and_return; 2532 + return res; 2386 2533 } 2387 2534 2388 2535 cropcap->bounds.top = cropcap->bounds.left = 0; ··· 2391 2538 cropcap->defrect.top = cropcap->defrect.left = 0; 2392 2539 cropcap->defrect.width = BUZ_MIN_WIDTH; 2393 2540 cropcap->defrect.height = BUZ_MIN_HEIGHT; 2394 - cropcap_unlock_and_return: 2395 - mutex_unlock(&zr->resource_lock); 2396 2541 return res; 2397 2542 } 2398 2543 ··· 2403 2552 memset(crop, 0, sizeof(*crop)); 2404 2553 crop->type = type; 2405 2554 2406 - mutex_lock(&zr->resource_lock); 2407 - 2408 2555 if (crop->type != V4L2_BUF_TYPE_VIDEO_OUTPUT && 2409 2556 (crop->type != V4L2_BUF_TYPE_VIDEO_CAPTURE || 2410 2557 fh->map_mode == ZORAN_MAP_MODE_RAW)) { ··· 2411 2562 "%s: VIDIOC_G_CROP - subcapture only supported for compressed capture\n", 2412 2563 ZR_DEVNAME(zr)); 2413 2564 res = -EINVAL; 2414 - goto gcrop_unlock_and_return; 2565 + return res; 2415 2566 } 2416 2567 2417 2568 crop->c.top = fh->jpg_settings.img_y; 2418 2569 crop->c.left = fh->jpg_settings.img_x; 2419 2570 crop->c.width = fh->jpg_settings.img_width; 2420 2571 crop->c.height = fh->jpg_settings.img_height; 2421 - 2422 - gcrop_unlock_and_return: 2423 - mutex_unlock(&zr->resource_lock); 2424 - 2425 2572 return res; 2426 2573 } 2427 2574 ··· 2430 2585 2431 2586 settings = fh->jpg_settings; 2432 2587 2433 - mutex_lock(&zr->resource_lock); 2434 - 2435 2588 if (fh->buffers.allocated) { 2436 2589 dprintk(1, KERN_ERR 2437 2590 "%s: VIDIOC_S_CROP - cannot change settings while active\n", 2438 2591 ZR_DEVNAME(zr)); 2439 2592 res = -EBUSY; 2440 - goto scrop_unlock_and_return; 2593 + return res; 2441 2594 } 2442 2595 2443 2596 if (crop->type != V4L2_BUF_TYPE_VIDEO_OUTPUT && ··· 2445 2602 "%s: VIDIOC_G_CROP - subcapture only supported for compressed capture\n", 2446 2603 ZR_DEVNAME(zr)); 2447 2604 res = -EINVAL; 2448 - goto scrop_unlock_and_return; 2605 + return res; 2449 2606 } 2450 2607 2451 2608 /* move into a form that we understand */ ··· 2457 2614 /* check validity */ 2458 2615 res = zoran_check_jpg_settings(zr, &settings, 0); 2459 2616 if (res) 2460 - goto scrop_unlock_and_return; 2617 + return res; 2461 2618 2462 2619 /* accept */ 2463 2620 fh->jpg_settings = settings; 2464 - 2465 - scrop_unlock_and_return: 2466 - mutex_unlock(&zr->resource_lock); 2467 2621 return res; 2468 2622 } 2469 2623 ··· 2468 2628 struct v4l2_jpegcompression *params) 2469 2629 { 2470 2630 struct zoran_fh *fh = __fh; 2471 - struct zoran *zr = fh->zr; 2472 2631 memset(params, 0, sizeof(*params)); 2473 - 2474 - mutex_lock(&zr->resource_lock); 2475 2632 2476 2633 params->quality = fh->jpg_settings.jpg_comp.quality; 2477 2634 params->APPn = fh->jpg_settings.jpg_comp.APPn; ··· 2482 2645 params->COM_len = fh->jpg_settings.jpg_comp.COM_len; 2483 2646 params->jpeg_markers = 2484 2647 fh->jpg_settings.jpg_comp.jpeg_markers; 2485 - 2486 - mutex_unlock(&zr->resource_lock); 2487 2648 2488 2649 return 0; 2489 2650 } ··· 2498 2663 2499 2664 settings.jpg_comp = *params; 2500 2665 2501 - mutex_lock(&zr->resource_lock); 2502 - 2503 2666 if (fh->buffers.active != ZORAN_FREE) { 2504 2667 dprintk(1, KERN_WARNING 2505 2668 "%s: VIDIOC_S_JPEGCOMP called while in playback/capture mode\n", 2506 2669 ZR_DEVNAME(zr)); 2507 2670 res = -EBUSY; 2508 - goto sjpegc_unlock_and_return; 2671 + return res; 2509 2672 } 2510 2673 2511 2674 res = zoran_check_jpg_settings(zr, &settings, 0); 2512 2675 if (res) 2513 - goto sjpegc_unlock_and_return; 2676 + return res; 2514 2677 if (!fh->buffers.allocated) 2515 2678 fh->buffers.buffer_size = 2516 2679 zoran_v4l2_calc_bufsize(&fh->jpg_settings); 2517 2680 fh->jpg_settings.jpg_comp = settings.jpg_comp; 2518 - sjpegc_unlock_and_return: 2519 - mutex_unlock(&zr->resource_lock); 2520 - 2521 2681 return res; 2522 2682 } 2523 2683 ··· 2522 2692 { 2523 2693 struct zoran_fh *fh = file->private_data; 2524 2694 struct zoran *zr = fh->zr; 2525 - int res = 0, frame; 2695 + int res = v4l2_ctrl_poll(file, wait); 2696 + int frame; 2526 2697 unsigned long flags; 2527 2698 2528 2699 /* we should check whether buffers are ready to be synced on ··· 2533 2702 * if error, return POLLERR, 2534 2703 * if no buffers queued or so, return POLLNVAL 2535 2704 */ 2536 - 2537 - mutex_lock(&zr->resource_lock); 2538 2705 2539 2706 switch (fh->map_mode) { 2540 2707 case ZORAN_MAP_MODE_RAW: ··· 2551 2722 if (fh->buffers.active != ZORAN_FREE && 2552 2723 /* Buffer ready to DQBUF? */ 2553 2724 zr->v4l_buffers.buffer[frame].state == BUZ_STATE_DONE) 2554 - res = POLLIN | POLLRDNORM; 2725 + res |= POLLIN | POLLRDNORM; 2555 2726 spin_unlock_irqrestore(&zr->spinlock, flags); 2556 2727 2557 2728 break; ··· 2572 2743 if (fh->buffers.active != ZORAN_FREE && 2573 2744 zr->jpg_buffers.buffer[frame].state == BUZ_STATE_DONE) { 2574 2745 if (fh->map_mode == ZORAN_MAP_MODE_JPG_REC) 2575 - res = POLLIN | POLLRDNORM; 2746 + res |= POLLIN | POLLRDNORM; 2576 2747 else 2577 - res = POLLOUT | POLLWRNORM; 2748 + res |= POLLOUT | POLLWRNORM; 2578 2749 } 2579 2750 spin_unlock_irqrestore(&zr->spinlock, flags); 2580 2751 ··· 2585 2756 KERN_ERR 2586 2757 "%s: %s - internal error, unknown map_mode=%d\n", 2587 2758 ZR_DEVNAME(zr), __func__, fh->map_mode); 2588 - res = POLLNVAL; 2759 + res |= POLLERR; 2589 2760 } 2590 - 2591 - mutex_unlock(&zr->resource_lock); 2592 2761 2593 2762 return res; 2594 2763 } ··· 2619 2792 struct zoran *zr = fh->zr; 2620 2793 int i; 2621 2794 2622 - if (!atomic_dec_and_mutex_lock(&map->count, &zr->resource_lock)) 2623 - return; 2624 - 2625 2795 dprintk(3, KERN_INFO "%s: %s - munmap(%s)\n", ZR_DEVNAME(zr), 2626 2796 __func__, mode_name(fh->map_mode)); 2627 2797 ··· 2631 2807 /* Any buffers still mapped? */ 2632 2808 for (i = 0; i < fh->buffers.num_buffers; i++) { 2633 2809 if (fh->buffers.buffer[i].map) { 2634 - mutex_unlock(&zr->resource_lock); 2635 2810 return; 2636 2811 } 2637 2812 } 2638 2813 2639 2814 dprintk(3, KERN_INFO "%s: %s - free %s buffers\n", ZR_DEVNAME(zr), 2640 2815 __func__, mode_name(fh->map_mode)); 2641 - 2642 2816 2643 2817 if (fh->map_mode == ZORAN_MAP_MODE_RAW) { 2644 2818 if (fh->buffers.active != ZORAN_FREE) { ··· 2657 2835 } 2658 2836 jpg_fbuffer_free(fh); 2659 2837 } 2660 - 2661 - mutex_unlock(&zr->resource_lock); 2662 2838 } 2663 2839 2664 2840 static const struct vm_operations_struct zoran_vm_ops = { ··· 2692 2872 return -EINVAL; 2693 2873 } 2694 2874 2695 - mutex_lock(&zr->resource_lock); 2696 - 2697 2875 if (!fh->buffers.allocated) { 2698 2876 dprintk(1, 2699 2877 KERN_ERR 2700 2878 "%s: %s(%s) - buffers not yet allocated\n", 2701 2879 ZR_DEVNAME(zr), __func__, mode_name(fh->map_mode)); 2702 2880 res = -ENOMEM; 2703 - goto mmap_unlock_and_return; 2881 + return res; 2704 2882 } 2705 2883 2706 2884 first = offset / fh->buffers.buffer_size; ··· 2714 2896 fh->buffers.buffer_size, 2715 2897 fh->buffers.num_buffers); 2716 2898 res = -EINVAL; 2717 - goto mmap_unlock_and_return; 2899 + return res; 2718 2900 } 2719 2901 2720 2902 /* Check if any buffers are already mapped */ ··· 2725 2907 "%s: %s(%s) - buffer %d already mapped\n", 2726 2908 ZR_DEVNAME(zr), __func__, mode_name(fh->map_mode), i); 2727 2909 res = -EBUSY; 2728 - goto mmap_unlock_and_return; 2910 + return res; 2729 2911 } 2730 2912 } 2731 2913 ··· 2733 2915 map = kmalloc(sizeof(struct zoran_mapping), GFP_KERNEL); 2734 2916 if (!map) { 2735 2917 res = -ENOMEM; 2736 - goto mmap_unlock_and_return; 2918 + return res; 2737 2919 } 2738 2920 map->fh = fh; 2739 2921 atomic_set(&map->count, 1); ··· 2755 2937 "%s: %s(V4L) - remap_pfn_range failed\n", 2756 2938 ZR_DEVNAME(zr), __func__); 2757 2939 res = -EAGAIN; 2758 - goto mmap_unlock_and_return; 2940 + return res; 2759 2941 } 2760 2942 size -= todo; 2761 2943 start += todo; ··· 2787 2969 "%s: %s(V4L) - remap_pfn_range failed\n", 2788 2970 ZR_DEVNAME(zr), __func__); 2789 2971 res = -EAGAIN; 2790 - goto mmap_unlock_and_return; 2972 + return res; 2791 2973 } 2792 2974 size -= todo; 2793 2975 start += todo; ··· 2803 2985 2804 2986 } 2805 2987 } 2806 - 2807 - mmap_unlock_and_return: 2808 - mutex_unlock(&zr->resource_lock); 2809 - 2810 2988 return res; 2811 2989 } 2812 2990 ··· 2842 3028 .vidioc_try_fmt_vid_cap = zoran_try_fmt_vid_cap, 2843 3029 .vidioc_try_fmt_vid_out = zoran_try_fmt_vid_out, 2844 3030 .vidioc_try_fmt_vid_overlay = zoran_try_fmt_vid_overlay, 2845 - .vidioc_queryctrl = zoran_queryctrl, 2846 - .vidioc_s_ctrl = zoran_s_ctrl, 2847 - .vidioc_g_ctrl = zoran_g_ctrl, 3031 + .vidioc_subscribe_event = v4l2_ctrl_subscribe_event, 3032 + .vidioc_unsubscribe_event = v4l2_event_unsubscribe, 2848 3033 }; 2849 - 2850 - /* please use zr->resource_lock consistently and kill this wrapper */ 2851 - static long zoran_ioctl(struct file *file, unsigned int cmd, 2852 - unsigned long arg) 2853 - { 2854 - struct zoran_fh *fh = file->private_data; 2855 - struct zoran *zr = fh->zr; 2856 - int ret; 2857 - 2858 - mutex_lock(&zr->other_lock); 2859 - ret = video_ioctl2(file, cmd, arg); 2860 - mutex_unlock(&zr->other_lock); 2861 - 2862 - return ret; 2863 - } 2864 3034 2865 3035 static const struct v4l2_file_operations zoran_fops = { 2866 3036 .owner = THIS_MODULE, 2867 3037 .open = zoran_open, 2868 3038 .release = zoran_close, 2869 - .unlocked_ioctl = zoran_ioctl, 2870 - .read = zoran_read, 2871 - .write = zoran_write, 3039 + .unlocked_ioctl = video_ioctl2, 2872 3040 .mmap = zoran_mmap, 2873 3041 .poll = zoran_poll, 2874 3042 };
+25 -2
drivers/media/platform/Kconfig
··· 1 1 # 2 2 # Platform drivers 3 - # All drivers here are currently for webcam support 3 + # Most drivers here are currently for webcam support 4 4 5 5 menuconfig V4L_PLATFORM_DRIVERS 6 6 bool "V4L platform devices" ··· 86 86 config VIDEO_OMAP3 87 87 tristate "OMAP 3 Camera support" 88 88 depends on VIDEO_V4L2 && I2C && VIDEO_V4L2_SUBDEV_API && ARCH_OMAP3 89 - depends on HAS_DMA 89 + depends on HAS_DMA && OF 90 90 depends on OMAP_IOMMU 91 91 select ARM_DMA_USE_IOMMU 92 92 select VIDEOBUF2_DMA_CONTIG ··· 231 231 Support for the Video Engine Unit (VEU) on SuperH and 232 232 SH-Mobile SoCs. 233 233 234 + config VIDEO_RENESAS_JPU 235 + tristate "Renesas JPEG Processing Unit" 236 + depends on VIDEO_DEV && VIDEO_V4L2 237 + depends on ARCH_SHMOBILE || COMPILE_TEST 238 + select VIDEOBUF2_DMA_CONTIG 239 + select V4L2_MEM2MEM_DEV 240 + ---help--- 241 + This is a V4L2 driver for the Renesas JPEG Processing Unit. 242 + 243 + To compile this driver as a module, choose M here: the module 244 + will be called rcar_jpu. 245 + 234 246 config VIDEO_RENESAS_VSP1 235 247 tristate "Renesas VSP1 Video Processing Engine" 236 248 depends on VIDEO_V4L2 && VIDEO_V4L2_SUBDEV_API && HAS_DMA ··· 292 280 This is a virtual test device for the memory-to-memory driver 293 281 framework. 294 282 endif #V4L_TEST_DRIVERS 283 + 284 + menuconfig DVB_PLATFORM_DRIVERS 285 + bool "DVB platform devices" 286 + depends on MEDIA_DIGITAL_TV_SUPPORT 287 + default n 288 + ---help--- 289 + Say Y here to enable support for platform-specific Digital TV drivers. 290 + 291 + if DVB_PLATFORM_DRIVERS 292 + source "drivers/media/platform/sti/c8sectpfe/Kconfig" 293 + endif #DVB_PLATFORM_DRIVERS
+2
drivers/media/platform/Makefile
··· 35 35 obj-$(CONFIG_VIDEO_SAMSUNG_EXYNOS_GSC) += exynos-gsc/ 36 36 37 37 obj-$(CONFIG_VIDEO_STI_BDISP) += sti/bdisp/ 38 + obj-$(CONFIG_DVB_C8SECTPFE) += sti/c8sectpfe/ 38 39 39 40 obj-$(CONFIG_BLACKFIN) += blackfin/ 40 41 ··· 45 44 46 45 obj-$(CONFIG_SOC_CAMERA) += soc_camera/ 47 46 47 + obj-$(CONFIG_VIDEO_RENESAS_JPU) += rcar_jpu.o 48 48 obj-$(CONFIG_VIDEO_RENESAS_VSP1) += vsp1/ 49 49 50 50 obj-y += omap/
+13 -3
drivers/media/platform/am437x/am437x-vpfe.c
··· 1186 1186 static int vpfe_release(struct file *file) 1187 1187 { 1188 1188 struct vpfe_device *vpfe = video_drvdata(file); 1189 + bool fh_singular; 1189 1190 int ret; 1190 1191 1191 1192 mutex_lock(&vpfe->lock); 1192 1193 1193 - if (v4l2_fh_is_singular_file(file)) 1194 - vpfe_ccdc_close(&vpfe->ccdc, vpfe->pdev); 1194 + /* Save the singular status before we call the clean-up helper */ 1195 + fh_singular = v4l2_fh_is_singular_file(file); 1196 + 1197 + /* the release helper will cleanup any on-going streaming */ 1195 1198 ret = _vb2_fop_release(file, NULL); 1199 + 1200 + /* 1201 + * If this was the last open file. 1202 + * Then de-initialize hw module. 1203 + */ 1204 + if (fh_singular) 1205 + vpfe_ccdc_close(&vpfe->ccdc, vpfe->pdev); 1196 1206 1197 1207 mutex_unlock(&vpfe->lock); 1198 1208 ··· 1575 1565 return -EBUSY; 1576 1566 } 1577 1567 1578 - ret = vpfe_try_fmt(file, priv, fmt); 1568 + ret = vpfe_try_fmt(file, priv, &format); 1579 1569 if (ret) 1580 1570 return ret; 1581 1571
+1 -1
drivers/media/platform/coda/Makefile
··· 1 1 ccflags-y += -I$(src) 2 2 3 - coda-objs := coda-common.o coda-bit.o coda-h264.o coda-jpeg.o 3 + coda-objs := coda-common.o coda-bit.o coda-gdi.o coda-h264.o coda-jpeg.o 4 4 5 5 obj-$(CONFIG_VIDEO_CODA) += coda.o
+113 -34
drivers/media/platform/coda/coda-bit.c
··· 226 226 { 227 227 struct vb2_buffer *src_buf; 228 228 struct coda_buffer_meta *meta; 229 + unsigned long flags; 229 230 u32 start; 231 + 232 + if (ctx->bit_stream_param & CODA_BIT_STREAM_END_FLAG) 233 + return; 230 234 231 235 while (v4l2_m2m_num_src_bufs_ready(ctx->fh.m2m_ctx) > 0) { 232 236 /* ··· 256 252 continue; 257 253 } 258 254 255 + /* Dump empty buffers */ 256 + if (!vb2_get_plane_payload(src_buf, 0)) { 257 + src_buf = v4l2_m2m_src_buf_remove(ctx->fh.m2m_ctx); 258 + v4l2_m2m_buf_done(src_buf, VB2_BUF_STATE_DONE); 259 + continue; 260 + } 261 + 259 262 /* Buffer start position */ 260 263 start = ctx->bitstream_fifo.kfifo.in & 261 264 ctx->bitstream_fifo.kfifo.mask; ··· 282 271 meta->start = start; 283 272 meta->end = ctx->bitstream_fifo.kfifo.in & 284 273 ctx->bitstream_fifo.kfifo.mask; 274 + spin_lock_irqsave(&ctx->buffer_meta_lock, 275 + flags); 285 276 list_add_tail(&meta->list, 286 277 &ctx->buffer_meta_list); 278 + ctx->num_metas++; 279 + spin_unlock_irqrestore(&ctx->buffer_meta_lock, 280 + flags); 287 281 288 282 trace_coda_bit_queue(ctx, src_buf, meta); 289 283 } ··· 347 331 { 348 332 struct coda_dev *dev = ctx->dev; 349 333 int width, height; 350 - dma_addr_t paddr; 351 334 int ysize; 352 335 int ret; 353 336 int i; ··· 366 351 size_t size; 367 352 char *name; 368 353 369 - size = ysize + ysize / 2; 354 + if (ctx->tiled_map_type == GDI_TILED_FRAME_MB_RASTER_MAP) 355 + size = round_up(ysize, 4096) + ysize / 2; 356 + else 357 + size = ysize + ysize / 2; 370 358 if (ctx->codec->src_fourcc == V4L2_PIX_FMT_H264 && 371 359 dev->devtype->product != CODA_DX6) 372 360 size += ysize / 4; ··· 385 367 386 368 /* Register frame buffers in the parameter buffer */ 387 369 for (i = 0; i < ctx->num_internal_frames; i++) { 388 - paddr = ctx->internal_frames[i].paddr; 370 + u32 y, cb, cr; 371 + 389 372 /* Start addresses of Y, Cb, Cr planes */ 390 - coda_parabuf_write(ctx, i * 3 + 0, paddr); 391 - coda_parabuf_write(ctx, i * 3 + 1, paddr + ysize); 392 - coda_parabuf_write(ctx, i * 3 + 2, paddr + ysize + ysize / 4); 373 + y = ctx->internal_frames[i].paddr; 374 + cb = y + ysize; 375 + cr = y + ysize + ysize/4; 376 + if (ctx->tiled_map_type == GDI_TILED_FRAME_MB_RASTER_MAP) { 377 + cb = round_up(cb, 4096); 378 + cr = 0; 379 + /* Packed 20-bit MSB of base addresses */ 380 + /* YYYYYCCC, CCyyyyyc, cccc.... */ 381 + y = (y & 0xfffff000) | cb >> 20; 382 + cb = (cb & 0x000ff000) << 12; 383 + } 384 + coda_parabuf_write(ctx, i * 3 + 0, y); 385 + coda_parabuf_write(ctx, i * 3 + 1, cb); 386 + coda_parabuf_write(ctx, i * 3 + 2, cr); 393 387 394 388 /* mvcol buffer for h.264 */ 395 389 if (ctx->codec->src_fourcc == V4L2_PIX_FMT_H264 && ··· 414 384 /* mvcol buffer for mpeg4 */ 415 385 if ((dev->devtype->product != CODA_DX6) && 416 386 (ctx->codec->src_fourcc == V4L2_PIX_FMT_MPEG4)) 417 - coda_parabuf_write(ctx, 97, ctx->internal_frames[i].paddr + 387 + coda_parabuf_write(ctx, 97, ctx->internal_frames[0].paddr + 418 388 ysize + ysize/4 + ysize/4); 419 389 420 390 return 0; ··· 742 712 return ret; 743 713 } 744 714 715 + static void coda9_set_frame_cache(struct coda_ctx *ctx, u32 fourcc) 716 + { 717 + u32 cache_size, cache_config; 718 + 719 + if (ctx->tiled_map_type == GDI_LINEAR_FRAME_MAP) { 720 + /* Luma 2x0 page, 2x6 cache, chroma 2x0 page, 2x4 cache size */ 721 + cache_size = 0x20262024; 722 + cache_config = 2 << CODA9_CACHE_PAGEMERGE_OFFSET; 723 + } else { 724 + /* Luma 0x2 page, 4x4 cache, chroma 0x2 page, 4x3 cache size */ 725 + cache_size = 0x02440243; 726 + cache_config = 1 << CODA9_CACHE_PAGEMERGE_OFFSET; 727 + } 728 + coda_write(ctx->dev, cache_size, CODA9_CMD_SET_FRAME_CACHE_SIZE); 729 + if (fourcc == V4L2_PIX_FMT_NV12) { 730 + cache_config |= 32 << CODA9_CACHE_LUMA_BUFFER_SIZE_OFFSET | 731 + 16 << CODA9_CACHE_CR_BUFFER_SIZE_OFFSET | 732 + 0 << CODA9_CACHE_CB_BUFFER_SIZE_OFFSET; 733 + } else { 734 + cache_config |= 32 << CODA9_CACHE_LUMA_BUFFER_SIZE_OFFSET | 735 + 8 << CODA9_CACHE_CR_BUFFER_SIZE_OFFSET | 736 + 8 << CODA9_CACHE_CB_BUFFER_SIZE_OFFSET; 737 + } 738 + coda_write(ctx->dev, cache_config, CODA9_CMD_SET_FRAME_CACHE_CONFIG); 739 + } 740 + 745 741 /* 746 742 * Encoder context operations 747 743 */ ··· 845 789 break; 846 790 } 847 791 848 - ctx->frame_mem_ctrl &= ~CODA_FRAME_CHROMA_INTERLEAVE; 792 + ctx->frame_mem_ctrl &= ~(CODA_FRAME_CHROMA_INTERLEAVE | (0x3 << 9) | 793 + CODA9_FRAME_TILED2LINEAR); 849 794 if (q_data_src->fourcc == V4L2_PIX_FMT_NV12) 850 795 ctx->frame_mem_ctrl |= CODA_FRAME_CHROMA_INTERLEAVE; 796 + if (ctx->tiled_map_type == GDI_TILED_FRAME_MB_RASTER_MAP) 797 + ctx->frame_mem_ctrl |= (0x3 << 9) | CODA9_FRAME_TILED2LINEAR; 851 798 coda_write(dev, ctx->frame_mem_ctrl, CODA_REG_BIT_FRAME_MEM_CTRL); 852 799 853 800 if (dev->devtype->product == CODA_DX6) { ··· 972 913 value = (ctx->params.bitrate & CODA_RATECONTROL_BITRATE_MASK) 973 914 << CODA_RATECONTROL_BITRATE_OFFSET; 974 915 value |= 1 & CODA_RATECONTROL_ENABLE_MASK; 916 + value |= (ctx->params.vbv_delay & 917 + CODA_RATECONTROL_INITIALDELAY_MASK) 918 + << CODA_RATECONTROL_INITIALDELAY_OFFSET; 975 919 if (dev->devtype->product == CODA_960) 976 920 value |= BIT(31); /* disable autoskip */ 977 921 } else { ··· 982 920 } 983 921 coda_write(dev, value, CODA_CMD_ENC_SEQ_RC_PARA); 984 922 985 - coda_write(dev, 0, CODA_CMD_ENC_SEQ_RC_BUF_SIZE); 923 + coda_write(dev, ctx->params.vbv_size, CODA_CMD_ENC_SEQ_RC_BUF_SIZE); 986 924 coda_write(dev, ctx->params.intra_refresh, 987 925 CODA_CMD_ENC_SEQ_INTRA_REFRESH); 988 926 ··· 1058 996 ret = -EFAULT; 1059 997 goto out; 1060 998 } 999 + ctx->initialized = 1; 1061 1000 1062 1001 if (dst_fourcc != V4L2_PIX_FMT_JPEG) { 1063 1002 if (dev->devtype->product == CODA_960) ··· 1098 1035 if (dev->devtype->product == CODA_960) { 1099 1036 coda_write(dev, ctx->iram_info.buf_btp_use, 1100 1037 CODA9_CMD_SET_FRAME_AXI_BTP_ADDR); 1038 + 1039 + coda9_set_frame_cache(ctx, q_data_src->fourcc); 1101 1040 1102 1041 /* FIXME */ 1103 1042 coda_write(dev, ctx->internal_frames[2].paddr, ··· 1391 1326 mutex_lock(&ctx->buffer_mutex); 1392 1327 mutex_lock(&dev->coda_mutex); 1393 1328 1329 + if (ctx->initialized == 0) 1330 + goto out; 1331 + 1394 1332 v4l2_dbg(1, coda_debug, &dev->v4l2_dev, 1395 1333 "%d: %s: sent command 'SEQ_END' to coda\n", ctx->idx, 1396 1334 __func__); ··· 1402 1334 "CODA_COMMAND_SEQ_END failed\n"); 1403 1335 } 1404 1336 1337 + /* 1338 + * FIXME: Sometimes h.264 encoding fails with 8-byte sequences missing 1339 + * from the output stream after the h.264 decoder has run. Resetting the 1340 + * hardware after the decoder has finished seems to help. 1341 + */ 1342 + if (dev->devtype->product == CODA_960) 1343 + coda_hw_reset(ctx); 1344 + 1405 1345 kfifo_init(&ctx->bitstream_fifo, 1406 1346 ctx->bitstream.vaddr, ctx->bitstream.size); 1407 1347 1408 1348 coda_free_framebuffers(ctx); 1409 1349 1350 + ctx->initialized = 0; 1351 + 1352 + out: 1410 1353 mutex_unlock(&dev->coda_mutex); 1411 1354 mutex_unlock(&ctx->buffer_mutex); 1412 1355 } ··· 1527 1448 /* Update coda bitstream read and write pointers from kfifo */ 1528 1449 coda_kfifo_sync_to_device_full(ctx); 1529 1450 1530 - ctx->frame_mem_ctrl &= ~CODA_FRAME_CHROMA_INTERLEAVE; 1451 + ctx->frame_mem_ctrl &= ~(CODA_FRAME_CHROMA_INTERLEAVE | (0x3 << 9) | 1452 + CODA9_FRAME_TILED2LINEAR); 1531 1453 if (dst_fourcc == V4L2_PIX_FMT_NV12) 1532 1454 ctx->frame_mem_ctrl |= CODA_FRAME_CHROMA_INTERLEAVE; 1455 + if (ctx->tiled_map_type == GDI_TILED_FRAME_MB_RASTER_MAP) 1456 + ctx->frame_mem_ctrl |= (0x3 << 9) | CODA9_FRAME_TILED2LINEAR; 1533 1457 coda_write(dev, ctx->frame_mem_ctrl, CODA_REG_BIT_FRAME_MEM_CTRL); 1534 1458 1535 1459 ctx->display_idx = -1; ··· 1578 1496 coda_write(dev, 0, CODA_REG_BIT_BIT_STREAM_PARAM); 1579 1497 return -ETIMEDOUT; 1580 1498 } 1499 + ctx->initialized = 1; 1581 1500 1582 1501 /* Update kfifo out pointer from coda bitstream read pointer */ 1583 1502 coda_kfifo_sync_from_device(ctx); ··· 1661 1578 CODA7_CMD_SET_FRAME_AXI_DBKC_ADDR); 1662 1579 coda_write(dev, ctx->iram_info.buf_ovl_use, 1663 1580 CODA7_CMD_SET_FRAME_AXI_OVL_ADDR); 1664 - if (dev->devtype->product == CODA_960) 1581 + if (dev->devtype->product == CODA_960) { 1665 1582 coda_write(dev, ctx->iram_info.buf_btp_use, 1666 1583 CODA9_CMD_SET_FRAME_AXI_BTP_ADDR); 1667 - } 1668 1584 1669 - if (dev->devtype->product == CODA_960) { 1670 - int cbb_size, crb_size; 1671 - 1672 - coda_write(dev, -1, CODA9_CMD_SET_FRAME_DELAY); 1673 - /* Luma 2x0 page, 2x6 cache, chroma 2x0 page, 2x4 cache size */ 1674 - coda_write(dev, 0x20262024, CODA9_CMD_SET_FRAME_CACHE_SIZE); 1675 - 1676 - if (dst_fourcc == V4L2_PIX_FMT_NV12) { 1677 - cbb_size = 0; 1678 - crb_size = 16; 1679 - } else { 1680 - cbb_size = 8; 1681 - crb_size = 8; 1585 + coda_write(dev, -1, CODA9_CMD_SET_FRAME_DELAY); 1586 + coda9_set_frame_cache(ctx, dst_fourcc); 1682 1587 } 1683 - coda_write(dev, 2 << CODA9_CACHE_PAGEMERGE_OFFSET | 1684 - 32 << CODA9_CACHE_LUMA_BUFFER_SIZE_OFFSET | 1685 - cbb_size << CODA9_CACHE_CB_BUFFER_SIZE_OFFSET | 1686 - crb_size << CODA9_CACHE_CR_BUFFER_SIZE_OFFSET, 1687 - CODA9_CMD_SET_FRAME_CACHE_CONFIG); 1688 1588 } 1689 1589 1690 1590 if (src_fourcc == V4L2_PIX_FMT_H264) { ··· 1720 1654 struct coda_dev *dev = ctx->dev; 1721 1655 struct coda_q_data *q_data_dst; 1722 1656 struct coda_buffer_meta *meta; 1657 + unsigned long flags; 1723 1658 u32 reg_addr, reg_stride; 1724 1659 1725 1660 dst_buf = v4l2_m2m_next_dst_buf(ctx->fh.m2m_ctx); ··· 1799 1732 coda_write(dev, ctx->iram_info.axi_sram_use, 1800 1733 CODA7_REG_BIT_AXI_SRAM_USE); 1801 1734 1735 + spin_lock_irqsave(&ctx->buffer_meta_lock, flags); 1802 1736 meta = list_first_entry_or_null(&ctx->buffer_meta_list, 1803 1737 struct coda_buffer_meta, list); 1804 1738 ··· 1819 1751 kfifo_in(&ctx->bitstream_fifo, buf, pad); 1820 1752 } 1821 1753 } 1754 + spin_unlock_irqrestore(&ctx->buffer_meta_lock, flags); 1822 1755 1823 1756 coda_kfifo_sync_to_device_full(ctx); 1824 1757 ··· 1841 1772 struct vb2_buffer *dst_buf; 1842 1773 struct coda_buffer_meta *meta; 1843 1774 unsigned long payload; 1775 + unsigned long flags; 1844 1776 int width, height; 1845 1777 int decoded_idx; 1846 1778 int display_idx; ··· 1967 1897 } else { 1968 1898 val = coda_read(dev, CODA_RET_DEC_PIC_FRAME_NUM) - 1; 1969 1899 val -= ctx->sequence_offset; 1970 - mutex_lock(&ctx->bitstream_mutex); 1900 + spin_lock_irqsave(&ctx->buffer_meta_lock, flags); 1971 1901 if (!list_empty(&ctx->buffer_meta_list)) { 1972 1902 meta = list_first_entry(&ctx->buffer_meta_list, 1973 1903 struct coda_buffer_meta, list); 1974 1904 list_del(&meta->list); 1975 - if (val != (meta->sequence & 0xffff)) { 1905 + ctx->num_metas--; 1906 + spin_unlock_irqrestore(&ctx->buffer_meta_lock, flags); 1907 + /* 1908 + * Clamp counters to 16 bits for comparison, as the HW 1909 + * counter rolls over at this point for h.264. This 1910 + * may be different for other formats, but using 16 bits 1911 + * should be enough to detect most errors and saves us 1912 + * from doing different things based on the format. 1913 + */ 1914 + if ((val & 0xffff) != (meta->sequence & 0xffff)) { 1976 1915 v4l2_err(&dev->v4l2_dev, 1977 1916 "sequence number mismatch (%d(%d) != %d)\n", 1978 1917 val, ctx->sequence_offset, ··· 1990 1911 ctx->frame_metas[decoded_idx] = *meta; 1991 1912 kfree(meta); 1992 1913 } else { 1914 + spin_unlock_irqrestore(&ctx->buffer_meta_lock, flags); 1993 1915 v4l2_err(&dev->v4l2_dev, "empty timestamp list!\n"); 1994 1916 memset(&ctx->frame_metas[decoded_idx], 0, 1995 1917 sizeof(struct coda_buffer_meta)); 1996 1918 ctx->frame_metas[decoded_idx].sequence = val; 1997 1919 ctx->sequence_offset++; 1998 1920 } 1999 - mutex_unlock(&ctx->bitstream_mutex); 2000 1921 2001 1922 trace_coda_dec_pic_done(ctx, &ctx->frame_metas[decoded_idx]); 2002 1923 ··· 2039 1960 dst_buf->v4l2_buf.timecode = meta->timecode; 2040 1961 dst_buf->v4l2_buf.timestamp = meta->timestamp; 2041 1962 2042 - trace_coda_dec_rot_done(ctx, meta, dst_buf); 1963 + trace_coda_dec_rot_done(ctx, dst_buf, meta); 2043 1964 2044 1965 switch (q_data_dst->fourcc) { 2045 1966 case V4L2_PIX_FMT_YUV420:
+181 -157
drivers/media/platform/coda/coda-common.c
··· 15 15 #include <linux/debugfs.h> 16 16 #include <linux/delay.h> 17 17 #include <linux/firmware.h> 18 + #include <linux/gcd.h> 18 19 #include <linux/genalloc.h> 19 20 #include <linux/interrupt.h> 20 21 #include <linux/io.h> ··· 62 61 module_param(coda_debug, int, 0644); 63 62 MODULE_PARM_DESC(coda_debug, "Debug level (0-2)"); 64 63 65 - struct coda_fmt { 66 - char *name; 67 - u32 fourcc; 68 - }; 64 + static int disable_tiling; 65 + module_param(disable_tiling, int, 0644); 66 + MODULE_PARM_DESC(disable_tiling, "Disable tiled frame buffers"); 69 67 70 68 void coda_write(struct coda_dev *dev, u32 data, u32 reg) 71 69 { ··· 90 90 u32 base_cb, base_cr; 91 91 92 92 switch (q_data->fourcc) { 93 + case V4L2_PIX_FMT_NV12: 94 + case V4L2_PIX_FMT_YUV420: 95 + default: 96 + base_cb = base_y + q_data->bytesperline * q_data->height; 97 + base_cr = base_cb + q_data->bytesperline * q_data->height / 4; 98 + break; 93 99 case V4L2_PIX_FMT_YVU420: 94 100 /* Switch Cb and Cr for YVU420 format */ 95 101 base_cr = base_y + q_data->bytesperline * q_data->height; 96 102 base_cb = base_cr + q_data->bytesperline * q_data->height / 4; 97 - break; 98 - case V4L2_PIX_FMT_YUV420: 99 - case V4L2_PIX_FMT_NV12: 100 - default: 101 - base_cb = base_y + q_data->bytesperline * q_data->height; 102 - base_cr = base_cb + q_data->bytesperline * q_data->height / 4; 103 103 break; 104 104 case V4L2_PIX_FMT_YUV422P: 105 105 base_cb = base_y + q_data->bytesperline * q_data->height; ··· 110 110 coda_write(ctx->dev, base_cb, reg_y + 4); 111 111 coda_write(ctx->dev, base_cr, reg_y + 8); 112 112 } 113 - 114 - /* 115 - * Array of all formats supported by any version of Coda: 116 - */ 117 - static const struct coda_fmt coda_formats[] = { 118 - { 119 - .name = "YUV 4:2:0 Planar, YCbCr", 120 - .fourcc = V4L2_PIX_FMT_YUV420, 121 - }, 122 - { 123 - .name = "YUV 4:2:0 Planar, YCrCb", 124 - .fourcc = V4L2_PIX_FMT_YVU420, 125 - }, 126 - { 127 - .name = "YUV 4:2:0 Partial interleaved Y/CbCr", 128 - .fourcc = V4L2_PIX_FMT_NV12, 129 - }, 130 - { 131 - .name = "YUV 4:2:2 Planar, YCbCr", 132 - .fourcc = V4L2_PIX_FMT_YUV422P, 133 - }, 134 - { 135 - .name = "H264 Encoded Stream", 136 - .fourcc = V4L2_PIX_FMT_H264, 137 - }, 138 - { 139 - .name = "MPEG4 Encoded Stream", 140 - .fourcc = V4L2_PIX_FMT_MPEG4, 141 - }, 142 - { 143 - .name = "JPEG Encoded Images", 144 - .fourcc = V4L2_PIX_FMT_JPEG, 145 - }, 146 - }; 147 113 148 114 #define CODA_CODEC(mode, src_fourcc, dst_fourcc, max_w, max_h) \ 149 115 { mode, src_fourcc, dst_fourcc, max_w, max_h } ··· 156 190 .type = CODA_INST_ENCODER, 157 191 .ops = &coda_bit_encode_ops, 158 192 .src_formats = { 193 + V4L2_PIX_FMT_NV12, 159 194 V4L2_PIX_FMT_YUV420, 160 195 V4L2_PIX_FMT_YVU420, 161 - V4L2_PIX_FMT_NV12, 162 196 }, 163 197 .dst_formats = { 164 198 V4L2_PIX_FMT_H264, ··· 171 205 .type = CODA_INST_ENCODER, 172 206 .ops = &coda_bit_encode_ops, 173 207 .src_formats = { 208 + V4L2_PIX_FMT_NV12, 174 209 V4L2_PIX_FMT_YUV420, 175 210 V4L2_PIX_FMT_YVU420, 176 - V4L2_PIX_FMT_NV12, 177 211 V4L2_PIX_FMT_YUV422P, 178 212 }, 179 213 .dst_formats = { ··· 190 224 V4L2_PIX_FMT_MPEG4, 191 225 }, 192 226 .dst_formats = { 227 + V4L2_PIX_FMT_NV12, 193 228 V4L2_PIX_FMT_YUV420, 194 229 V4L2_PIX_FMT_YVU420, 195 - V4L2_PIX_FMT_NV12, 196 230 }, 197 231 }; 198 232 ··· 204 238 V4L2_PIX_FMT_JPEG, 205 239 }, 206 240 .dst_formats = { 241 + V4L2_PIX_FMT_NV12, 207 242 V4L2_PIX_FMT_YUV420, 208 243 V4L2_PIX_FMT_YVU420, 209 - V4L2_PIX_FMT_NV12, 210 244 V4L2_PIX_FMT_YUV422P, 211 245 }, 212 246 }; ··· 227 261 &coda_bit_decoder, 228 262 }; 229 263 230 - static bool coda_format_is_yuv(u32 fourcc) 231 - { 232 - switch (fourcc) { 233 - case V4L2_PIX_FMT_YUV420: 234 - case V4L2_PIX_FMT_YVU420: 235 - case V4L2_PIX_FMT_NV12: 236 - case V4L2_PIX_FMT_YUV422P: 237 - return true; 238 - default: 239 - return false; 240 - } 241 - } 242 - 243 - static const char *coda_format_name(u32 fourcc) 244 - { 245 - int i; 246 - 247 - for (i = 0; i < ARRAY_SIZE(coda_formats); i++) { 248 - if (coda_formats[i].fourcc == fourcc) 249 - return coda_formats[i].name; 250 - } 251 - 252 - return NULL; 253 - } 254 - 255 264 /* 256 265 * Normalize all supported YUV 4:2:0 formats to the value used in the codec 257 266 * tables. 258 267 */ 259 268 static u32 coda_format_normalize_yuv(u32 fourcc) 260 269 { 261 - return coda_format_is_yuv(fourcc) ? V4L2_PIX_FMT_YUV420 : fourcc; 270 + switch (fourcc) { 271 + case V4L2_PIX_FMT_NV12: 272 + case V4L2_PIX_FMT_YUV420: 273 + case V4L2_PIX_FMT_YVU420: 274 + case V4L2_PIX_FMT_YUV422P: 275 + return V4L2_PIX_FMT_YUV420; 276 + default: 277 + return fourcc; 278 + } 262 279 } 263 280 264 281 static const struct coda_codec *coda_find_codec(struct coda_dev *dev, ··· 345 396 struct video_device *vdev = video_devdata(file); 346 397 const struct coda_video_device *cvd = to_coda_video_device(vdev); 347 398 const u32 *formats; 348 - const char *name; 349 399 350 400 if (f->type == V4L2_BUF_TYPE_VIDEO_OUTPUT) 351 401 formats = cvd->src_formats; ··· 356 408 if (f->index >= CODA_MAX_FORMATS || formats[f->index] == 0) 357 409 return -EINVAL; 358 410 359 - name = coda_format_name(formats[f->index]); 360 - strlcpy(f->description, name, sizeof(f->description)); 361 411 f->pixelformat = formats[f->index]; 362 - if (!coda_format_is_yuv(formats[f->index])) 363 - f->flags |= V4L2_FMT_FLAG_COMPRESSED; 364 412 365 413 return 0; 366 414 } ··· 448 504 S_ALIGN); 449 505 450 506 switch (f->fmt.pix.pixelformat) { 507 + case V4L2_PIX_FMT_NV12: 451 508 case V4L2_PIX_FMT_YUV420: 452 509 case V4L2_PIX_FMT_YVU420: 453 - case V4L2_PIX_FMT_NV12: 454 510 /* 455 511 * Frame stride must be at least multiple of 8, 456 512 * but multiple of 16 for h.264 or JPEG 4:2:x ··· 588 644 q_data->rect.top = 0; 589 645 q_data->rect.width = f->fmt.pix.width; 590 646 q_data->rect.height = f->fmt.pix.height; 647 + 648 + switch (f->fmt.pix.pixelformat) { 649 + case V4L2_PIX_FMT_NV12: 650 + if (f->type == V4L2_BUF_TYPE_VIDEO_OUTPUT) { 651 + ctx->tiled_map_type = GDI_TILED_FRAME_MB_RASTER_MAP; 652 + if (!disable_tiling) 653 + break; 654 + } 655 + /* else fall through */ 656 + case V4L2_PIX_FMT_YUV420: 657 + case V4L2_PIX_FMT_YVU420: 658 + ctx->tiled_map_type = GDI_LINEAR_FRAME_MAP; 659 + break; 660 + default: 661 + break; 662 + } 591 663 592 664 v4l2_dbg(1, coda_debug, &ctx->dev->v4l2_dev, 593 665 "Setting format for type %d, wxh: %dx%d, fmt: %d\n", ··· 791 831 return 0; 792 832 } 793 833 834 + static int coda_g_parm(struct file *file, void *fh, struct v4l2_streamparm *a) 835 + { 836 + struct coda_ctx *ctx = fh_to_ctx(fh); 837 + struct v4l2_fract *tpf; 838 + 839 + if (a->type != V4L2_BUF_TYPE_VIDEO_OUTPUT) 840 + return -EINVAL; 841 + 842 + a->parm.output.capability = V4L2_CAP_TIMEPERFRAME; 843 + tpf = &a->parm.output.timeperframe; 844 + tpf->denominator = ctx->params.framerate & CODA_FRATE_RES_MASK; 845 + tpf->numerator = 1 + (ctx->params.framerate >> 846 + CODA_FRATE_DIV_OFFSET); 847 + 848 + return 0; 849 + } 850 + 851 + /* 852 + * Approximate timeperframe v4l2_fract with values that can be written 853 + * into the 16-bit CODA_FRATE_DIV and CODA_FRATE_RES fields. 854 + */ 855 + static void coda_approximate_timeperframe(struct v4l2_fract *timeperframe) 856 + { 857 + struct v4l2_fract s = *timeperframe; 858 + struct v4l2_fract f0; 859 + struct v4l2_fract f1 = { 1, 0 }; 860 + struct v4l2_fract f2 = { 0, 1 }; 861 + unsigned int i, div, s_denominator; 862 + 863 + /* Lower bound is 1/65535 */ 864 + if (s.numerator == 0 || s.denominator / s.numerator > 65535) { 865 + timeperframe->numerator = 1; 866 + timeperframe->denominator = 65535; 867 + return; 868 + } 869 + 870 + /* Upper bound is 65536/1, map everything above to infinity */ 871 + if (s.denominator == 0 || s.numerator / s.denominator > 65536) { 872 + timeperframe->numerator = 1; 873 + timeperframe->denominator = 0; 874 + return; 875 + } 876 + 877 + /* Reduce fraction to lowest terms */ 878 + div = gcd(s.numerator, s.denominator); 879 + if (div > 1) { 880 + s.numerator /= div; 881 + s.denominator /= div; 882 + } 883 + 884 + if (s.numerator <= 65536 && s.denominator < 65536) { 885 + *timeperframe = s; 886 + return; 887 + } 888 + 889 + /* Find successive convergents from continued fraction expansion */ 890 + while (f2.numerator <= 65536 && f2.denominator < 65536) { 891 + f0 = f1; 892 + f1 = f2; 893 + 894 + /* Stop when f2 exactly equals timeperframe */ 895 + if (s.numerator == 0) 896 + break; 897 + 898 + i = s.denominator / s.numerator; 899 + 900 + f2.numerator = f0.numerator + i * f1.numerator; 901 + f2.denominator = f0.denominator + i * f2.denominator; 902 + 903 + s_denominator = s.numerator; 904 + s.numerator = s.denominator % s.numerator; 905 + s.denominator = s_denominator; 906 + } 907 + 908 + *timeperframe = f1; 909 + } 910 + 911 + static uint32_t coda_timeperframe_to_frate(struct v4l2_fract *timeperframe) 912 + { 913 + return ((timeperframe->numerator - 1) << CODA_FRATE_DIV_OFFSET) | 914 + timeperframe->denominator; 915 + } 916 + 917 + static int coda_s_parm(struct file *file, void *fh, struct v4l2_streamparm *a) 918 + { 919 + struct coda_ctx *ctx = fh_to_ctx(fh); 920 + struct v4l2_fract *tpf; 921 + 922 + if (a->type != V4L2_BUF_TYPE_VIDEO_OUTPUT) 923 + return -EINVAL; 924 + 925 + tpf = &a->parm.output.timeperframe; 926 + coda_approximate_timeperframe(tpf); 927 + ctx->params.framerate = coda_timeperframe_to_frate(tpf); 928 + 929 + return 0; 930 + } 931 + 794 932 static int coda_subscribe_event(struct v4l2_fh *fh, 795 933 const struct v4l2_event_subscription *sub) 796 934 { ··· 929 871 .vidioc_try_decoder_cmd = coda_try_decoder_cmd, 930 872 .vidioc_decoder_cmd = coda_decoder_cmd, 931 873 874 + .vidioc_g_parm = coda_g_parm, 875 + .vidioc_s_parm = coda_s_parm, 876 + 932 877 .vidioc_subscribe_event = coda_subscribe_event, 933 878 .vidioc_unsubscribe_event = v4l2_event_unsubscribe, 934 879 }; 935 - 936 - void coda_set_gdi_regs(struct coda_ctx *ctx) 937 - { 938 - struct gdi_tiled_map *tiled_map = &ctx->tiled_map; 939 - struct coda_dev *dev = ctx->dev; 940 - int i; 941 - 942 - for (i = 0; i < 16; i++) 943 - coda_write(dev, tiled_map->xy2ca_map[i], 944 - CODA9_GDI_XY2_CAS_0 + 4 * i); 945 - for (i = 0; i < 4; i++) 946 - coda_write(dev, tiled_map->xy2ba_map[i], 947 - CODA9_GDI_XY2_BA_0 + 4 * i); 948 - for (i = 0; i < 16; i++) 949 - coda_write(dev, tiled_map->xy2ra_map[i], 950 - CODA9_GDI_XY2_RAS_0 + 4 * i); 951 - coda_write(dev, tiled_map->xy2rbc_config, CODA9_GDI_XY2_RBC_CONFIG); 952 - for (i = 0; i < 32; i++) 953 - coda_write(dev, tiled_map->rbc2axi_map[i], 954 - CODA9_GDI_RBC2_AXI_0 + 4 * i); 955 - } 956 880 957 881 /* 958 882 * Mem-to-mem operations. ··· 989 949 static int coda_job_ready(void *m2m_priv) 990 950 { 991 951 struct coda_ctx *ctx = m2m_priv; 952 + int src_bufs = v4l2_m2m_num_src_bufs_ready(ctx->fh.m2m_ctx); 992 953 993 954 /* 994 955 * For both 'P' and 'key' frame cases 1 picture 995 956 * and 1 frame are needed. In the decoder case, 996 957 * the compressed frame can be in the bitstream. 997 958 */ 998 - if (!v4l2_m2m_num_src_bufs_ready(ctx->fh.m2m_ctx) && 999 - ctx->inst_type != CODA_INST_DECODER) { 959 + if (!src_bufs && ctx->inst_type != CODA_INST_DECODER) { 1000 960 v4l2_dbg(1, coda_debug, &ctx->dev->v4l2_dev, 1001 961 "not ready: not enough video buffers.\n"); 1002 962 return 0; ··· 1009 969 } 1010 970 1011 971 if (ctx->inst_type == CODA_INST_DECODER && ctx->use_bit) { 1012 - struct list_head *meta; 1013 - bool stream_end; 1014 - int num_metas; 1015 - int src_bufs; 972 + bool stream_end = ctx->bit_stream_param & 973 + CODA_BIT_STREAM_END_FLAG; 974 + int num_metas = ctx->num_metas; 1016 975 1017 - if (ctx->hold && !v4l2_m2m_num_src_bufs_ready(ctx->fh.m2m_ctx)) { 976 + if (ctx->hold && !src_bufs) { 1018 977 v4l2_dbg(1, coda_debug, &ctx->dev->v4l2_dev, 1019 978 "%d: not ready: on hold for more buffers.\n", 1020 979 ctx->idx); 1021 980 return 0; 1022 981 } 1023 - 1024 - stream_end = ctx->bit_stream_param & 1025 - CODA_BIT_STREAM_END_FLAG; 1026 - 1027 - num_metas = 0; 1028 - list_for_each(meta, &ctx->buffer_meta_list) 1029 - num_metas++; 1030 - 1031 - src_bufs = v4l2_m2m_num_src_bufs_ready(ctx->fh.m2m_ctx); 1032 982 1033 983 if (!stream_end && (num_metas + src_bufs) < 2) { 1034 984 v4l2_dbg(1, coda_debug, &ctx->dev->v4l2_dev, ··· 1028 998 } 1029 999 1030 1000 1031 - if (!v4l2_m2m_num_src_bufs_ready(ctx->fh.m2m_ctx) && 1032 - !stream_end && (coda_get_bitstream_payload(ctx) < 512)) { 1001 + if (!src_bufs && !stream_end && 1002 + (coda_get_bitstream_payload(ctx) < 512)) { 1033 1003 v4l2_dbg(1, coda_debug, &ctx->dev->v4l2_dev, 1034 1004 "%d: not ready: not enough bitstream data (%d).\n", 1035 1005 ctx->idx, coda_get_bitstream_payload(ctx)); ··· 1045 1015 1046 1016 v4l2_dbg(1, coda_debug, &ctx->dev->v4l2_dev, 1047 1017 "job ready\n"); 1018 + 1048 1019 return 1; 1049 1020 } 1050 1021 ··· 1083 1052 .unlock = coda_unlock, 1084 1053 }; 1085 1054 1086 - static void coda_set_tiled_map_type(struct coda_ctx *ctx, int tiled_map_type) 1087 - { 1088 - struct gdi_tiled_map *tiled_map = &ctx->tiled_map; 1089 - int luma_map, chro_map, i; 1090 - 1091 - memset(tiled_map, 0, sizeof(*tiled_map)); 1092 - 1093 - luma_map = 64; 1094 - chro_map = 64; 1095 - tiled_map->map_type = tiled_map_type; 1096 - for (i = 0; i < 16; i++) 1097 - tiled_map->xy2ca_map[i] = luma_map << 8 | chro_map; 1098 - for (i = 0; i < 4; i++) 1099 - tiled_map->xy2ba_map[i] = luma_map << 8 | chro_map; 1100 - for (i = 0; i < 16; i++) 1101 - tiled_map->xy2ra_map[i] = luma_map << 8 | chro_map; 1102 - 1103 - if (tiled_map_type == GDI_LINEAR_FRAME_MAP) { 1104 - tiled_map->xy2rbc_config = 0; 1105 - } else { 1106 - dev_err(&ctx->dev->plat_dev->dev, "invalid map type: %d\n", 1107 - tiled_map_type); 1108 - return; 1109 - } 1110 - } 1111 - 1112 1055 static void set_default_params(struct coda_ctx *ctx) 1113 1056 { 1114 1057 unsigned int max_w, max_h, usize, csize; ··· 1099 1094 ctx->params.framerate = 30; 1100 1095 1101 1096 /* Default formats for output and input queues */ 1102 - ctx->q_data[V4L2_M2M_SRC].fourcc = ctx->codec->src_fourcc; 1103 - ctx->q_data[V4L2_M2M_DST].fourcc = ctx->codec->dst_fourcc; 1097 + ctx->q_data[V4L2_M2M_SRC].fourcc = ctx->cvd->src_formats[0]; 1098 + ctx->q_data[V4L2_M2M_DST].fourcc = ctx->cvd->dst_formats[0]; 1104 1099 ctx->q_data[V4L2_M2M_SRC].width = max_w; 1105 1100 ctx->q_data[V4L2_M2M_SRC].height = max_h; 1106 1101 ctx->q_data[V4L2_M2M_DST].width = max_w; ··· 1121 1116 ctx->q_data[V4L2_M2M_DST].rect.width = max_w; 1122 1117 ctx->q_data[V4L2_M2M_DST].rect.height = max_h; 1123 1118 1124 - if (ctx->dev->devtype->product == CODA_960) 1125 - coda_set_tiled_map_type(ctx, GDI_LINEAR_FRAME_MAP); 1119 + /* 1120 + * Since the RBC2AXI logic only supports a single chroma plane, 1121 + * macroblock tiling only works for to NV12 pixel format. 1122 + */ 1123 + ctx->tiled_map_type = GDI_LINEAR_FRAME_MAP; 1126 1124 } 1127 1125 1128 1126 /* ··· 1252 1244 1253 1245 q_data_src = get_q_data(ctx, V4L2_BUF_TYPE_VIDEO_OUTPUT); 1254 1246 if (q->type == V4L2_BUF_TYPE_VIDEO_OUTPUT) { 1255 - if (q_data_src->fourcc == V4L2_PIX_FMT_H264 || 1256 - (q_data_src->fourcc == V4L2_PIX_FMT_JPEG && 1257 - ctx->dev->devtype->product == CODA_7541)) { 1247 + if (ctx->inst_type == CODA_INST_DECODER && ctx->use_bit) { 1258 1248 /* copy the buffers that were queued before streamon */ 1259 1249 mutex_lock(&ctx->bitstream_mutex); 1260 1250 coda_fill_bitstream(ctx, false); ··· 1321 1315 goto err; 1322 1316 } 1323 1317 1324 - ctx->initialized = 1; 1325 1318 return ret; 1326 1319 1327 1320 err: ··· 1339 1334 struct coda_ctx *ctx = vb2_get_drv_priv(q); 1340 1335 struct coda_dev *dev = ctx->dev; 1341 1336 struct vb2_buffer *buf; 1337 + unsigned long flags; 1342 1338 bool stop; 1343 1339 1344 1340 stop = ctx->streamon_out && ctx->streamon_cap; ··· 1374 1368 queue_work(dev->workqueue, &ctx->seq_end_work); 1375 1369 flush_work(&ctx->seq_end_work); 1376 1370 } 1377 - mutex_lock(&ctx->bitstream_mutex); 1371 + spin_lock_irqsave(&ctx->buffer_meta_lock, flags); 1378 1372 while (!list_empty(&ctx->buffer_meta_list)) { 1379 1373 meta = list_first_entry(&ctx->buffer_meta_list, 1380 1374 struct coda_buffer_meta, list); 1381 1375 list_del(&meta->list); 1382 1376 kfree(meta); 1383 1377 } 1384 - mutex_unlock(&ctx->bitstream_mutex); 1378 + ctx->num_metas = 0; 1379 + spin_unlock_irqrestore(&ctx->buffer_meta_lock, flags); 1385 1380 kfifo_init(&ctx->bitstream_fifo, 1386 1381 ctx->bitstream.vaddr, ctx->bitstream.size); 1387 - ctx->initialized = 0; 1388 1382 ctx->runcounter = 0; 1389 1383 ctx->aborting = 0; 1390 1384 } 1385 + 1386 + if (!ctx->streamon_out && !ctx->streamon_cap) 1387 + ctx->bit_stream_param &= ~CODA_BIT_STREAM_END_FLAG; 1391 1388 } 1392 1389 1393 1390 static const struct vb2_ops coda_qops = { ··· 1478 1469 case V4L2_CID_JPEG_RESTART_INTERVAL: 1479 1470 ctx->params.jpeg_restart_interval = ctrl->val; 1480 1471 break; 1472 + case V4L2_CID_MPEG_VIDEO_VBV_DELAY: 1473 + ctx->params.vbv_delay = ctrl->val; 1474 + break; 1475 + case V4L2_CID_MPEG_VIDEO_VBV_SIZE: 1476 + ctx->params.vbv_size = min(ctrl->val * 8192, 0x7fffffff); 1477 + break; 1481 1478 default: 1482 1479 v4l2_dbg(1, coda_debug, &ctx->dev->v4l2_dev, 1483 1480 "Invalid control, id=%d, val=%d\n", ··· 1543 1528 v4l2_ctrl_new_std(&ctx->ctrls, &coda_ctrl_ops, 1544 1529 V4L2_CID_MPEG_VIDEO_CYCLIC_INTRA_REFRESH_MB, 0, 1545 1530 1920 * 1088 / 256, 1, 0); 1531 + v4l2_ctrl_new_std(&ctx->ctrls, &coda_ctrl_ops, 1532 + V4L2_CID_MPEG_VIDEO_VBV_DELAY, 0, 0x7fff, 1, 0); 1533 + /* 1534 + * The maximum VBV size value is 0x7fffffff bits, 1535 + * one bit less than 262144 KiB 1536 + */ 1537 + v4l2_ctrl_new_std(&ctx->ctrls, &coda_ctrl_ops, 1538 + V4L2_CID_MPEG_VIDEO_VBV_SIZE, 0, 262144, 1, 0); 1546 1539 } 1547 1540 1548 1541 static void coda_jpeg_encode_ctrls(struct coda_ctx *ctx) ··· 1749 1726 mutex_init(&ctx->bitstream_mutex); 1750 1727 mutex_init(&ctx->buffer_mutex); 1751 1728 INIT_LIST_HEAD(&ctx->buffer_meta_list); 1729 + spin_lock_init(&ctx->buffer_meta_lock); 1752 1730 1753 1731 coda_lock(ctx); 1754 1732 list_add(&ctx->list, &dev->instances); ··· 1793 1769 v4l2_m2m_ctx_release(ctx->fh.m2m_ctx); 1794 1770 1795 1771 /* In case the instance was not running, we still need to call SEQ_END */ 1796 - if (ctx->initialized && ctx->ops->seq_end_work) { 1772 + if (ctx->ops->seq_end_work) { 1797 1773 queue_work(dev->workqueue, &ctx->seq_end_work); 1798 1774 flush_work(&ctx->seq_end_work); 1799 1775 }
+150
drivers/media/platform/coda/coda-gdi.c
··· 1 + /* 2 + * Coda multi-standard codec IP 3 + * 4 + * Copyright (C) 2014 Philipp Zabel, Pengutronix 5 + * 6 + * This program is free software; you can redistribute it and/or modify 7 + * it under the terms of the GNU General Public License as published by 8 + * the Free Software Foundation; either version 2 of the License, or 9 + * (at your option) any later version. 10 + */ 11 + 12 + #include <linux/bitops.h> 13 + #include "coda.h" 14 + 15 + #define XY2_INVERT BIT(7) 16 + #define XY2_ZERO BIT(6) 17 + #define XY2_TB_XOR BIT(5) 18 + #define XY2_XYSEL BIT(4) 19 + #define XY2_Y (1 << 4) 20 + #define XY2_X (0 << 4) 21 + 22 + #define XY2(luma_sel, luma_bit, chroma_sel, chroma_bit) \ 23 + (((XY2_##luma_sel) | (luma_bit)) << 8 | \ 24 + (XY2_##chroma_sel) | (chroma_bit)) 25 + 26 + static const u16 xy2ca_zero_map[16] = { 27 + XY2(ZERO, 0, ZERO, 0), 28 + XY2(ZERO, 0, ZERO, 0), 29 + XY2(ZERO, 0, ZERO, 0), 30 + XY2(ZERO, 0, ZERO, 0), 31 + XY2(ZERO, 0, ZERO, 0), 32 + XY2(ZERO, 0, ZERO, 0), 33 + XY2(ZERO, 0, ZERO, 0), 34 + XY2(ZERO, 0, ZERO, 0), 35 + XY2(ZERO, 0, ZERO, 0), 36 + XY2(ZERO, 0, ZERO, 0), 37 + XY2(ZERO, 0, ZERO, 0), 38 + XY2(ZERO, 0, ZERO, 0), 39 + XY2(ZERO, 0, ZERO, 0), 40 + XY2(ZERO, 0, ZERO, 0), 41 + XY2(ZERO, 0, ZERO, 0), 42 + XY2(ZERO, 0, ZERO, 0), 43 + }; 44 + 45 + static const u16 xy2ca_tiled_map[16] = { 46 + XY2(Y, 0, Y, 0), 47 + XY2(Y, 1, Y, 1), 48 + XY2(Y, 2, Y, 2), 49 + XY2(Y, 3, X, 3), 50 + XY2(X, 3, ZERO, 0), 51 + XY2(ZERO, 0, ZERO, 0), 52 + XY2(ZERO, 0, ZERO, 0), 53 + XY2(ZERO, 0, ZERO, 0), 54 + XY2(ZERO, 0, ZERO, 0), 55 + XY2(ZERO, 0, ZERO, 0), 56 + XY2(ZERO, 0, ZERO, 0), 57 + XY2(ZERO, 0, ZERO, 0), 58 + XY2(ZERO, 0, ZERO, 0), 59 + XY2(ZERO, 0, ZERO, 0), 60 + XY2(ZERO, 0, ZERO, 0), 61 + XY2(ZERO, 0, ZERO, 0), 62 + }; 63 + 64 + /* 65 + * RA[15:0], CA[15:8] are hardwired to contain the 24-bit macroblock 66 + * start offset (macroblock size is 16x16 for luma, 16x8 for chroma). 67 + * Bits CA[4:0] are set using XY2CA above. BA[3:0] seems to be unused. 68 + */ 69 + 70 + #define RBC_CA (0 << 4) 71 + #define RBC_BA (1 << 4) 72 + #define RBC_RA (2 << 4) 73 + #define RBC_ZERO (3 << 4) 74 + 75 + #define RBC(luma_sel, luma_bit, chroma_sel, chroma_bit) \ 76 + (((RBC_##luma_sel) | (luma_bit)) << 6 | \ 77 + (RBC_##chroma_sel) | (chroma_bit)) 78 + 79 + static const u16 rbc2axi_tiled_map[32] = { 80 + RBC(ZERO, 0, ZERO, 0), 81 + RBC(ZERO, 0, ZERO, 0), 82 + RBC(ZERO, 0, ZERO, 0), 83 + RBC(CA, 0, CA, 0), 84 + RBC(CA, 1, CA, 1), 85 + RBC(CA, 2, CA, 2), 86 + RBC(CA, 3, CA, 3), 87 + RBC(CA, 4, CA, 8), 88 + RBC(CA, 8, CA, 9), 89 + RBC(CA, 9, CA, 10), 90 + RBC(CA, 10, CA, 11), 91 + RBC(CA, 11, CA, 12), 92 + RBC(CA, 12, CA, 13), 93 + RBC(CA, 13, CA, 14), 94 + RBC(CA, 14, CA, 15), 95 + RBC(CA, 15, RA, 0), 96 + RBC(RA, 0, RA, 1), 97 + RBC(RA, 1, RA, 2), 98 + RBC(RA, 2, RA, 3), 99 + RBC(RA, 3, RA, 4), 100 + RBC(RA, 4, RA, 5), 101 + RBC(RA, 5, RA, 6), 102 + RBC(RA, 6, RA, 7), 103 + RBC(RA, 7, RA, 8), 104 + RBC(RA, 8, RA, 9), 105 + RBC(RA, 9, RA, 10), 106 + RBC(RA, 10, RA, 11), 107 + RBC(RA, 11, RA, 12), 108 + RBC(RA, 12, RA, 13), 109 + RBC(RA, 13, RA, 14), 110 + RBC(RA, 14, RA, 15), 111 + RBC(RA, 15, ZERO, 0), 112 + }; 113 + 114 + void coda_set_gdi_regs(struct coda_ctx *ctx) 115 + { 116 + struct coda_dev *dev = ctx->dev; 117 + const u16 *xy2ca_map; 118 + u32 xy2rbc_config; 119 + int i; 120 + 121 + switch (ctx->tiled_map_type) { 122 + case GDI_LINEAR_FRAME_MAP: 123 + default: 124 + xy2ca_map = xy2ca_zero_map; 125 + xy2rbc_config = 0; 126 + break; 127 + case GDI_TILED_FRAME_MB_RASTER_MAP: 128 + xy2ca_map = xy2ca_tiled_map; 129 + xy2rbc_config = CODA9_XY2RBC_TILED_MAP | 130 + CODA9_XY2RBC_CA_INC_HOR | 131 + (16 - 1) << 12 | (8 - 1) << 4; 132 + break; 133 + } 134 + 135 + for (i = 0; i < 16; i++) 136 + coda_write(dev, xy2ca_map[i], 137 + CODA9_GDI_XY2_CAS_0 + 4 * i); 138 + for (i = 0; i < 4; i++) 139 + coda_write(dev, XY2(ZERO, 0, ZERO, 0), 140 + CODA9_GDI_XY2_BA_0 + 4 * i); 141 + for (i = 0; i < 16; i++) 142 + coda_write(dev, XY2(ZERO, 0, ZERO, 0), 143 + CODA9_GDI_XY2_RAS_0 + 4 * i); 144 + coda_write(dev, xy2rbc_config, CODA9_GDI_XY2_RBC_CONFIG); 145 + if (xy2rbc_config) { 146 + for (i = 0; i < 32; i++) 147 + coda_write(dev, rbc2axi_tiled_map[i], 148 + CODA9_GDI_RBC2_AXI_0 + 4 * i); 149 + } 150 + }
+6 -9
drivers/media/platform/coda/coda.h
··· 128 128 enum v4l2_mpeg_video_multi_slice_mode slice_mode; 129 129 u32 framerate; 130 130 u16 bitrate; 131 + u16 vbv_delay; 132 + u32 vbv_size; 131 133 u32 slice_max_bits; 132 134 u32 slice_max_mb; 133 135 }; ··· 167 165 phys_addr_t next_paddr; 168 166 }; 169 167 170 - struct gdi_tiled_map { 171 - int xy2ca_map[16]; 172 - int xy2ba_map[16]; 173 - int xy2ra_map[16]; 174 - int rbc2axi_map[32]; 175 - int xy2rbc_config; 176 - int map_type; 177 168 #define GDI_LINEAR_FRAME_MAP 0 178 - }; 169 + #define GDI_TILED_FRAME_MB_RASTER_MAP 1 179 170 180 171 struct coda_ctx; 181 172 ··· 222 227 struct coda_buffer_meta frame_metas[CODA_MAX_FRAMEBUFFERS]; 223 228 u32 frame_errors[CODA_MAX_FRAMEBUFFERS]; 224 229 struct list_head buffer_meta_list; 230 + spinlock_t buffer_meta_lock; 231 + int num_metas; 225 232 struct coda_aux_buf workbuf; 226 233 int num_internal_frames; 227 234 int idx; 228 235 int reg_idx; 229 236 struct coda_iram_info iram_info; 230 - struct gdi_tiled_map tiled_map; 237 + int tiled_map_type; 231 238 u32 bit_stream_param; 232 239 u32 frm_dis_flg; 233 240 u32 frame_mem_ctrl;
+10
drivers/media/platform/coda/coda_regs.h
··· 51 51 #define CODA7_STREAM_SEL_64BITS_ENDIAN (1 << 1) 52 52 #define CODA_STREAM_ENDIAN_SELECT (1 << 0) 53 53 #define CODA_REG_BIT_FRAME_MEM_CTRL 0x110 54 + #define CODA9_FRAME_TILED2LINEAR (1 << 11) 54 55 #define CODA_FRAME_CHROMA_INTERLEAVE (1 << 2) 55 56 #define CODA_IMAGE_ENDIAN_SELECT (1 << 0) 56 57 #define CODA_REG_BIT_BIT_STREAM_PARAM 0x114 ··· 264 263 #define CODADX6_PICHEIGHT_MASK 0x3ff 265 264 #define CODA7_PICHEIGHT_MASK 0xffff 266 265 #define CODA_CMD_ENC_SEQ_SRC_F_RATE 0x194 266 + #define CODA_FRATE_RES_OFFSET 0 267 + #define CODA_FRATE_RES_MASK 0xffff 268 + #define CODA_FRATE_DIV_OFFSET 16 269 + #define CODA_FRATE_DIV_MASK 0xffff 267 270 #define CODA_CMD_ENC_SEQ_MP4_PARA 0x198 268 271 #define CODA_MP4PARAM_VERID_OFFSET 6 269 272 #define CODA_MP4PARAM_VERID_MASK 0x01 ··· 453 448 #define CODA9_GDI_XY2_RAS_F (CODA9_GDMA_BASE + 0x88c) 454 449 455 450 #define CODA9_GDI_XY2_RBC_CONFIG (CODA9_GDMA_BASE + 0x890) 451 + #define CODA9_XY2RBC_SEPARATE_MAP BIT(19) 452 + #define CODA9_XY2RBC_TOP_BOT_SPLIT BIT(18) 453 + #define CODA9_XY2RBC_TILED_MAP BIT(17) 454 + #define CODA9_XY2RBC_CA_INC_HOR BIT(16) 456 455 #define CODA9_GDI_RBC2_AXI_0 (CODA9_GDMA_BASE + 0x8a0) 457 456 #define CODA9_GDI_RBC2_AXI_1F (CODA9_GDMA_BASE + 0x91c) 457 + #define CODA9_GDI_TILEDBUF_BASE (CODA9_GDMA_BASE + 0x920) 458 458 459 459 #endif
+26 -65
drivers/media/platform/coda/trace.h
··· 48 48 TP_printk("minor = %d, ctx = %d", __entry->minor, __entry->ctx) 49 49 ); 50 50 51 - TRACE_EVENT(coda_enc_pic_run, 51 + DECLARE_EVENT_CLASS(coda_buf_class, 52 52 TP_PROTO(struct coda_ctx *ctx, struct vb2_buffer *buf), 53 53 54 54 TP_ARGS(ctx, buf), ··· 69 69 __entry->minor, __entry->index, __entry->ctx) 70 70 ); 71 71 72 - TRACE_EVENT(coda_enc_pic_done, 72 + DEFINE_EVENT(coda_buf_class, coda_enc_pic_run, 73 73 TP_PROTO(struct coda_ctx *ctx, struct vb2_buffer *buf), 74 - 75 - TP_ARGS(ctx, buf), 76 - 77 - TP_STRUCT__entry( 78 - __field(int, minor) 79 - __field(int, index) 80 - __field(int, ctx) 81 - ), 82 - 83 - TP_fast_assign( 84 - __entry->minor = ctx->fh.vdev->minor; 85 - __entry->index = buf->v4l2_buf.index; 86 - __entry->ctx = ctx->idx; 87 - ), 88 - 89 - TP_printk("minor = %d, index = %d, ctx = %d", 90 - __entry->minor, __entry->index, __entry->ctx) 74 + TP_ARGS(ctx, buf) 91 75 ); 92 76 93 - TRACE_EVENT(coda_bit_queue, 77 + DEFINE_EVENT(coda_buf_class, coda_enc_pic_done, 78 + TP_PROTO(struct coda_ctx *ctx, struct vb2_buffer *buf), 79 + TP_ARGS(ctx, buf) 80 + ); 81 + 82 + DECLARE_EVENT_CLASS(coda_buf_meta_class, 94 83 TP_PROTO(struct coda_ctx *ctx, struct vb2_buffer *buf, 95 84 struct coda_buffer_meta *meta), 96 85 ··· 106 117 __entry->ctx) 107 118 ); 108 119 109 - TRACE_EVENT(coda_dec_pic_run, 120 + DEFINE_EVENT(coda_buf_meta_class, coda_bit_queue, 121 + TP_PROTO(struct coda_ctx *ctx, struct vb2_buffer *buf, 122 + struct coda_buffer_meta *meta), 123 + TP_ARGS(ctx, buf, meta) 124 + ); 125 + 126 + DECLARE_EVENT_CLASS(coda_meta_class, 110 127 TP_PROTO(struct coda_ctx *ctx, struct coda_buffer_meta *meta), 111 128 112 129 TP_ARGS(ctx, meta), ··· 135 140 __entry->minor, __entry->start, __entry->end, __entry->ctx) 136 141 ); 137 142 138 - TRACE_EVENT(coda_dec_pic_done, 143 + DEFINE_EVENT(coda_meta_class, coda_dec_pic_run, 139 144 TP_PROTO(struct coda_ctx *ctx, struct coda_buffer_meta *meta), 140 - 141 - TP_ARGS(ctx, meta), 142 - 143 - TP_STRUCT__entry( 144 - __field(int, minor) 145 - __field(int, start) 146 - __field(int, end) 147 - __field(int, ctx) 148 - ), 149 - 150 - TP_fast_assign( 151 - __entry->minor = ctx->fh.vdev->minor; 152 - __entry->start = meta->start; 153 - __entry->end = meta->end; 154 - __entry->ctx = ctx->idx; 155 - ), 156 - 157 - TP_printk("minor = %d, start = 0x%x, end = 0x%x, ctx = %d", 158 - __entry->minor, __entry->start, __entry->end, __entry->ctx) 145 + TP_ARGS(ctx, meta) 159 146 ); 160 147 161 - TRACE_EVENT(coda_dec_rot_done, 162 - TP_PROTO(struct coda_ctx *ctx, struct coda_buffer_meta *meta, 163 - struct vb2_buffer *buf), 148 + DEFINE_EVENT(coda_meta_class, coda_dec_pic_done, 149 + TP_PROTO(struct coda_ctx *ctx, struct coda_buffer_meta *meta), 150 + TP_ARGS(ctx, meta) 151 + ); 164 152 165 - TP_ARGS(ctx, meta, buf), 166 - 167 - TP_STRUCT__entry( 168 - __field(int, minor) 169 - __field(int, start) 170 - __field(int, end) 171 - __field(int, index) 172 - __field(int, ctx) 173 - ), 174 - 175 - TP_fast_assign( 176 - __entry->minor = ctx->fh.vdev->minor; 177 - __entry->start = meta->start; 178 - __entry->end = meta->end; 179 - __entry->index = buf->v4l2_buf.index; 180 - __entry->ctx = ctx->idx; 181 - ), 182 - 183 - TP_printk("minor = %d, start = 0x%x, end = 0x%x, index = %d, ctx = %d", 184 - __entry->minor, __entry->start, __entry->end, __entry->index, 185 - __entry->ctx) 153 + DEFINE_EVENT(coda_buf_meta_class, coda_dec_rot_done, 154 + TP_PROTO(struct coda_ctx *ctx, struct vb2_buffer *buf, 155 + struct coda_buffer_meta *meta), 156 + TP_ARGS(ctx, buf, meta) 186 157 ); 187 158 188 159 #endif /* __CODA_TRACE_H__ */
+41 -119
drivers/media/platform/fsl-viu.c
··· 28 28 #include <media/v4l2-common.h> 29 29 #include <media/v4l2-device.h> 30 30 #include <media/v4l2-ioctl.h> 31 + #include <media/v4l2-ctrls.h> 32 + #include <media/v4l2-fh.h> 33 + #include <media/v4l2-event.h> 31 34 #include <media/videobuf-dma-contig.h> 32 35 33 36 #define DRV_NAME "fsl_viu" ··· 42 39 43 40 /* I2C address of video decoder chip is 0x4A */ 44 41 #define VIU_VIDEO_DECODER_ADDR 0x25 45 - 46 - /* supported controls */ 47 - static struct v4l2_queryctrl viu_qctrl[] = { 48 - { 49 - .id = V4L2_CID_BRIGHTNESS, 50 - .type = V4L2_CTRL_TYPE_INTEGER, 51 - .name = "Brightness", 52 - .minimum = 0, 53 - .maximum = 255, 54 - .step = 1, 55 - .default_value = 127, 56 - .flags = 0, 57 - }, { 58 - .id = V4L2_CID_CONTRAST, 59 - .type = V4L2_CTRL_TYPE_INTEGER, 60 - .name = "Contrast", 61 - .minimum = 0, 62 - .maximum = 255, 63 - .step = 0x1, 64 - .default_value = 0x10, 65 - .flags = 0, 66 - }, { 67 - .id = V4L2_CID_SATURATION, 68 - .type = V4L2_CTRL_TYPE_INTEGER, 69 - .name = "Saturation", 70 - .minimum = 0, 71 - .maximum = 255, 72 - .step = 0x1, 73 - .default_value = 127, 74 - .flags = 0, 75 - }, { 76 - .id = V4L2_CID_HUE, 77 - .type = V4L2_CTRL_TYPE_INTEGER, 78 - .name = "Hue", 79 - .minimum = -128, 80 - .maximum = 127, 81 - .step = 0x1, 82 - .default_value = 0, 83 - .flags = 0, 84 - } 85 - }; 86 - 87 - static int qctl_regs[ARRAY_SIZE(viu_qctrl)]; 88 42 89 43 static int info_level; 90 44 ··· 55 95 * Basic structures 56 96 */ 57 97 struct viu_fmt { 58 - char name[32]; 59 98 u32 fourcc; /* v4l2 format id */ 60 99 u32 pixelformat; 61 100 int depth; ··· 62 103 63 104 static struct viu_fmt formats[] = { 64 105 { 65 - .name = "RGB-16 (5/B-6/G-5/R)", 66 106 .fourcc = V4L2_PIX_FMT_RGB565, 67 107 .pixelformat = V4L2_PIX_FMT_RGB565, 68 108 .depth = 16, 69 109 }, { 70 - .name = "RGB-32 (A-R-G-B)", 71 110 .fourcc = V4L2_PIX_FMT_RGB32, 72 111 .pixelformat = V4L2_PIX_FMT_RGB32, 73 112 .depth = 32, ··· 113 156 114 157 struct viu_dev { 115 158 struct v4l2_device v4l2_dev; 159 + struct v4l2_ctrl_handler hdl; 116 160 struct mutex lock; 117 161 spinlock_t slock; 118 162 int users; ··· 153 195 }; 154 196 155 197 struct viu_fh { 198 + /* must remain the first field of this struct */ 199 + struct v4l2_fh fh; 156 200 struct viu_dev *dev; 157 201 158 202 /* video capture */ ··· 564 604 { 565 605 strcpy(cap->driver, "viu"); 566 606 strcpy(cap->card, "viu"); 607 + strcpy(cap->bus_info, "platform:viu"); 567 608 cap->device_caps = V4L2_CAP_VIDEO_CAPTURE | 568 609 V4L2_CAP_STREAMING | 569 610 V4L2_CAP_VIDEO_OVERLAY | ··· 578 617 { 579 618 int index = f->index; 580 619 581 - if (f->index > NUM_FORMATS) 620 + if (f->index >= NUM_FORMATS) 582 621 return -EINVAL; 583 622 584 - strlcpy(f->description, formats[index].name, sizeof(f->description)); 585 623 f->pixelformat = formats[index].fourcc; 586 624 return 0; 587 625 } ··· 597 637 f->fmt.pix.bytesperline = 598 638 (f->fmt.pix.width * fh->fmt->depth) >> 3; 599 639 f->fmt.pix.sizeimage = fh->sizeimage; 640 + f->fmt.pix.colorspace = V4L2_COLORSPACE_SMPTE170M; 600 641 return 0; 601 642 } 602 643 ··· 605 644 struct v4l2_format *f) 606 645 { 607 646 struct viu_fmt *fmt; 608 - enum v4l2_field field; 609 647 unsigned int maxw, maxh; 610 648 611 649 fmt = format_by_fourcc(f->fmt.pix.pixelformat); ··· 614 654 return -EINVAL; 615 655 } 616 656 617 - field = f->fmt.pix.field; 618 - 619 - if (field == V4L2_FIELD_ANY) { 620 - field = V4L2_FIELD_INTERLACED; 621 - } else if (field != V4L2_FIELD_INTERLACED) { 622 - dprintk(1, "Field type invalid.\n"); 623 - return -EINVAL; 624 - } 625 - 626 657 maxw = norm_maxw(); 627 658 maxh = norm_maxh(); 628 659 629 - f->fmt.pix.field = field; 660 + f->fmt.pix.field = V4L2_FIELD_INTERLACED; 630 661 if (f->fmt.pix.height < 32) 631 662 f->fmt.pix.height = 32; 632 663 if (f->fmt.pix.height > maxh) ··· 629 678 f->fmt.pix.width &= ~0x03; 630 679 f->fmt.pix.bytesperline = 631 680 (f->fmt.pix.width * fmt->depth) >> 3; 681 + f->fmt.pix.sizeimage = f->fmt.pix.height * f->fmt.pix.bytesperline; 682 + f->fmt.pix.colorspace = V4L2_COLORSPACE_SMPTE170M; 632 683 633 684 return 0; 634 685 } ··· 651 698 fh->sizeimage = f->fmt.pix.sizeimage; 652 699 fh->vb_vidq.field = f->fmt.pix.field; 653 700 fh->type = f->type; 654 - dprintk(1, "set to pixelformat '%4.6s'\n", (char *)&fh->fmt->name); 655 701 return 0; 656 702 } 657 703 ··· 716 764 { 717 765 int bpp; 718 766 719 - dprintk(1, "%s %dx%d %s\n", __func__, 720 - fh->win.w.width, fh->win.w.height, dev->ovfmt->name); 767 + dprintk(1, "%s %dx%d\n", __func__, 768 + fh->win.w.width, fh->win.w.height); 721 769 722 770 reg_val.status_cfg = 0; 723 771 ··· 954 1002 { 955 1003 struct viu_fh *fh = priv; 956 1004 957 - if (i > 1) 1005 + if (i) 958 1006 return -EINVAL; 959 1007 960 1008 decoder_call(fh->dev, video, s_routing, i, 0, 0); 961 1009 return 0; 962 - } 963 - 964 - /* Controls */ 965 - static int vidioc_queryctrl(struct file *file, void *priv, 966 - struct v4l2_queryctrl *qc) 967 - { 968 - int i; 969 - 970 - for (i = 0; i < ARRAY_SIZE(viu_qctrl); i++) { 971 - if (qc->id && qc->id == viu_qctrl[i].id) { 972 - memcpy(qc, &(viu_qctrl[i]), sizeof(*qc)); 973 - return 0; 974 - } 975 - } 976 - return -EINVAL; 977 - } 978 - 979 - static int vidioc_g_ctrl(struct file *file, void *priv, 980 - struct v4l2_control *ctrl) 981 - { 982 - int i; 983 - 984 - for (i = 0; i < ARRAY_SIZE(viu_qctrl); i++) { 985 - if (ctrl->id == viu_qctrl[i].id) { 986 - ctrl->value = qctl_regs[i]; 987 - return 0; 988 - } 989 - } 990 - return -EINVAL; 991 - } 992 - static int vidioc_s_ctrl(struct file *file, void *priv, 993 - struct v4l2_control *ctrl) 994 - { 995 - int i; 996 - 997 - for (i = 0; i < ARRAY_SIZE(viu_qctrl); i++) { 998 - if (ctrl->id == viu_qctrl[i].id) { 999 - if (ctrl->value < viu_qctrl[i].minimum 1000 - || ctrl->value > viu_qctrl[i].maximum) 1001 - return -ERANGE; 1002 - qctl_regs[i] = ctrl->value; 1003 - return 0; 1004 - } 1005 - } 1006 - return -EINVAL; 1007 1010 } 1008 1011 1009 1012 inline void viu_activate_next_buf(struct viu_dev *dev, ··· 1172 1265 struct viu_reg *vr; 1173 1266 int minor = vdev->minor; 1174 1267 u32 status_cfg; 1175 - int i; 1176 1268 1177 1269 dprintk(1, "viu: open (minor=%d)\n", minor); 1178 1270 ··· 1199 1293 return -ENOMEM; 1200 1294 } 1201 1295 1296 + v4l2_fh_init(&fh->fh, vdev); 1202 1297 file->private_data = fh; 1203 1298 fh->dev = dev; 1204 1299 ··· 1209 1302 fh->height = norm_maxh(); 1210 1303 dev->crop_current.width = fh->width; 1211 1304 dev->crop_current.height = fh->height; 1212 - 1213 - /* Put all controls at a sane state */ 1214 - for (i = 0; i < ARRAY_SIZE(viu_qctrl); i++) 1215 - qctl_regs[i] = viu_qctrl[i].default_value; 1216 1305 1217 1306 dprintk(1, "Open: fh=0x%08lx, dev=0x%08lx, dev->vidq=0x%08lx\n", 1218 1307 (unsigned long)fh, (unsigned long)dev, ··· 1235 1332 fh->type, V4L2_FIELD_INTERLACED, 1236 1333 sizeof(struct viu_buf), fh, 1237 1334 &fh->dev->lock); 1335 + v4l2_fh_add(&fh->fh); 1238 1336 mutex_unlock(&dev->lock); 1239 1337 return 0; 1240 1338 } ··· 1268 1364 struct viu_fh *fh = file->private_data; 1269 1365 struct videobuf_queue *q = &fh->vb_vidq; 1270 1366 struct viu_dev *dev = fh->dev; 1271 - unsigned int res; 1367 + unsigned long req_events = poll_requested_events(wait); 1368 + unsigned int res = v4l2_ctrl_poll(file, wait); 1272 1369 1273 1370 if (V4L2_BUF_TYPE_VIDEO_CAPTURE != fh->type) 1274 1371 return POLLERR; 1275 1372 1373 + if (!(req_events & (POLLIN | POLLRDNORM))) 1374 + return res; 1375 + 1276 1376 mutex_lock(&dev->lock); 1277 - res = videobuf_poll_stream(file, q, wait); 1377 + res |= videobuf_poll_stream(file, q, wait); 1278 1378 mutex_unlock(&dev->lock); 1279 1379 return res; 1280 1380 } ··· 1293 1385 viu_stop_dma(dev); 1294 1386 videobuf_stop(&fh->vb_vidq); 1295 1387 videobuf_mmap_free(&fh->vb_vidq); 1388 + v4l2_fh_del(&fh->fh); 1389 + v4l2_fh_exit(&fh->fh); 1296 1390 mutex_unlock(&dev->lock); 1297 1391 1298 1392 kfree(fh); ··· 1373 1463 .vidioc_enum_input = vidioc_enum_input, 1374 1464 .vidioc_g_input = vidioc_g_input, 1375 1465 .vidioc_s_input = vidioc_s_input, 1376 - .vidioc_queryctrl = vidioc_queryctrl, 1377 - .vidioc_g_ctrl = vidioc_g_ctrl, 1378 - .vidioc_s_ctrl = vidioc_s_ctrl, 1379 1466 .vidioc_streamon = vidioc_streamon, 1380 1467 .vidioc_streamoff = vidioc_streamoff, 1468 + .vidioc_log_status = v4l2_ctrl_log_status, 1469 + .vidioc_subscribe_event = v4l2_ctrl_subscribe_event, 1470 + .vidioc_unsubscribe_event = v4l2_event_unsubscribe, 1381 1471 }; 1382 1472 1383 1473 static struct video_device viu_template = { ··· 1453 1543 } 1454 1544 1455 1545 ad = i2c_get_adapter(0); 1546 + 1547 + v4l2_ctrl_handler_init(&viu_dev->hdl, 5); 1548 + if (viu_dev->hdl.error) { 1549 + ret = viu_dev->hdl.error; 1550 + dev_err(&op->dev, "couldn't register control\n"); 1551 + goto err_vdev; 1552 + } 1553 + /* This control handler will inherit the control(s) from the 1554 + sub-device(s). */ 1555 + viu_dev->v4l2_dev.ctrl_handler = &viu_dev->hdl; 1456 1556 viu_dev->decoder = v4l2_i2c_new_subdev(&viu_dev->v4l2_dev, ad, 1457 1557 "saa7113", VIU_VIDEO_DECODER_ADDR, NULL); 1458 1558 ··· 1479 1559 goto err_vdev; 1480 1560 } 1481 1561 1482 - memcpy(vdev, &viu_template, sizeof(viu_template)); 1562 + *vdev = viu_template; 1483 1563 1484 1564 vdev->v4l2_dev = &viu_dev->v4l2_dev; 1485 1565 ··· 1534 1614 err_clk: 1535 1615 video_unregister_device(viu_dev->vdev); 1536 1616 err_vdev: 1617 + v4l2_ctrl_handler_free(&viu_dev->hdl); 1537 1618 mutex_unlock(&viu_dev->lock); 1538 1619 i2c_put_adapter(ad); 1539 1620 v4l2_device_unregister(&viu_dev->v4l2_dev); ··· 1556 1635 1557 1636 clk_disable_unprepare(dev->clk); 1558 1637 1638 + v4l2_ctrl_handler_free(&dev->hdl); 1559 1639 video_unregister_device(dev->vdev); 1560 1640 i2c_put_adapter(client->adapter); 1561 1641 v4l2_device_unregister(&dev->v4l2_dev);
+27 -117
drivers/media/platform/omap3isp/isp.c
··· 101 101 0x0000, /* csi2a, len 0x0170 */ 102 102 0x0170, /* csiphy2, len 0x000c */ 103 103 }, 104 - .syscon_offset = 0xdc, 105 104 .phy_type = ISP_PHY_TYPE_3430, 106 105 }, 107 106 { ··· 123 124 0x0570, /* csiphy1, len 0x000c */ 124 125 0x05c0, /* csi2c, len 0x0040 (2nd area) */ 125 126 }, 126 - .syscon_offset = 0x2f0, 127 127 .phy_type = ISP_PHY_TYPE_3630, 128 128 }, 129 129 }; ··· 827 829 int ret; 828 830 829 831 if (notification == MEDIA_DEV_NOTIFY_POST_LINK_CH && 830 - !(link->flags & MEDIA_LNK_FL_ENABLED)) { 832 + !(flags & MEDIA_LNK_FL_ENABLED)) { 831 833 /* Powering off entities is assumed to never fail. */ 832 834 isp_pipeline_pm_power(source, -sink_use); 833 835 isp_pipeline_pm_power(sink, -source_use); 834 836 return 0; 835 837 } 836 838 837 - if (notification == MEDIA_DEV_NOTIFY_POST_LINK_CH && 839 + if (notification == MEDIA_DEV_NOTIFY_PRE_LINK_CH && 838 840 (flags & MEDIA_LNK_FL_ENABLED)) { 839 841 840 842 ret = isp_pipeline_pm_power(source, sink_use); ··· 1794 1796 media_device_unregister(&isp->media_dev); 1795 1797 } 1796 1798 1797 - /* 1798 - * isp_register_subdev - Register a sub-device 1799 - * @isp: OMAP3 ISP device 1800 - * @isp_subdev: platform data related to a sub-device 1801 - * 1802 - * Register an I2C sub-device which has not been registered by other 1803 - * means (such as the Device Tree). 1804 - * 1805 - * Return a pointer to the sub-device if it has been successfully 1806 - * registered, or NULL otherwise. 1807 - */ 1808 - static struct v4l2_subdev * 1809 - isp_register_subdev(struct isp_device *isp, 1810 - struct isp_platform_subdev *isp_subdev) 1811 - { 1812 - struct i2c_adapter *adapter; 1813 - struct v4l2_subdev *sd; 1814 - 1815 - if (isp_subdev->board_info == NULL) 1816 - return NULL; 1817 - 1818 - adapter = i2c_get_adapter(isp_subdev->i2c_adapter_id); 1819 - if (adapter == NULL) { 1820 - dev_err(isp->dev, 1821 - "%s: Unable to get I2C adapter %d for device %s\n", 1822 - __func__, isp_subdev->i2c_adapter_id, 1823 - isp_subdev->board_info->type); 1824 - return NULL; 1825 - } 1826 - 1827 - sd = v4l2_i2c_new_subdev_board(&isp->v4l2_dev, adapter, 1828 - isp_subdev->board_info, NULL); 1829 - if (sd == NULL) { 1830 - dev_err(isp->dev, "%s: Unable to register subdev %s\n", 1831 - __func__, isp_subdev->board_info->type); 1832 - return NULL; 1833 - } 1834 - 1835 - return sd; 1836 - } 1837 - 1838 1799 static int isp_link_entity( 1839 1800 struct isp_device *isp, struct media_entity *entity, 1840 1801 enum isp_interface_type interface) ··· 1867 1910 1868 1911 static int isp_register_entities(struct isp_device *isp) 1869 1912 { 1870 - struct isp_platform_data *pdata = isp->pdata; 1871 - struct isp_platform_subdev *isp_subdev; 1872 1913 int ret; 1873 1914 1874 1915 isp->media_dev.dev = isp->dev; ··· 1923 1968 if (ret < 0) 1924 1969 goto done; 1925 1970 1926 - /* 1927 - * Device Tree --- the external sub-devices will be registered 1928 - * later. The same goes for the sub-device node registration. 1929 - */ 1930 - if (isp->dev->of_node) 1931 - return 0; 1932 - 1933 - /* Register external entities */ 1934 - for (isp_subdev = pdata ? pdata->subdevs : NULL; 1935 - isp_subdev && isp_subdev->board_info; isp_subdev++) { 1936 - struct v4l2_subdev *sd; 1937 - 1938 - sd = isp_register_subdev(isp, isp_subdev); 1939 - 1940 - /* 1941 - * No bus information --- this is either a flash or a 1942 - * lens subdev. 1943 - */ 1944 - if (!sd || !isp_subdev->bus) 1945 - continue; 1946 - 1947 - sd->host_priv = isp_subdev->bus; 1948 - 1949 - ret = isp_link_entity(isp, &sd->entity, 1950 - isp_subdev->bus->interface); 1951 - if (ret < 0) 1952 - goto done; 1953 - } 1954 - 1955 - ret = v4l2_device_register_subdev_nodes(&isp->v4l2_dev); 1956 - 1957 1971 done: 1958 - if (ret < 0) { 1972 + if (ret < 0) 1959 1973 isp_unregister_entities(isp); 1960 - v4l2_async_notifier_unregister(&isp->notifier); 1961 - } 1962 1974 1963 1975 return ret; 1964 1976 } ··· 2326 2404 return -ENOMEM; 2327 2405 } 2328 2406 2329 - if (IS_ENABLED(CONFIG_OF) && pdev->dev.of_node) { 2330 - ret = of_property_read_u32(pdev->dev.of_node, "ti,phy-type", 2331 - &isp->phy_type); 2332 - if (ret) 2333 - return ret; 2407 + ret = of_property_read_u32(pdev->dev.of_node, "ti,phy-type", 2408 + &isp->phy_type); 2409 + if (ret) 2410 + return ret; 2334 2411 2335 - isp->syscon = syscon_regmap_lookup_by_phandle(pdev->dev.of_node, 2336 - "syscon"); 2337 - if (IS_ERR(isp->syscon)) 2338 - return PTR_ERR(isp->syscon); 2412 + isp->syscon = syscon_regmap_lookup_by_phandle(pdev->dev.of_node, 2413 + "syscon"); 2414 + if (IS_ERR(isp->syscon)) 2415 + return PTR_ERR(isp->syscon); 2339 2416 2340 - ret = of_property_read_u32_index(pdev->dev.of_node, "syscon", 1, 2341 - &isp->syscon_offset); 2342 - if (ret) 2343 - return ret; 2417 + ret = of_property_read_u32_index(pdev->dev.of_node, "syscon", 1, 2418 + &isp->syscon_offset); 2419 + if (ret) 2420 + return ret; 2344 2421 2345 - ret = isp_of_parse_nodes(&pdev->dev, &isp->notifier); 2346 - if (ret < 0) 2347 - return ret; 2348 - ret = v4l2_async_notifier_register(&isp->v4l2_dev, 2349 - &isp->notifier); 2350 - if (ret) 2351 - return ret; 2352 - } else { 2353 - isp->pdata = pdev->dev.platform_data; 2354 - isp->syscon = syscon_regmap_lookup_by_pdevname("syscon.0"); 2355 - if (IS_ERR(isp->syscon)) 2356 - return PTR_ERR(isp->syscon); 2357 - dev_warn(&pdev->dev, 2358 - "Platform data support is deprecated! Please move to DT now!\n"); 2359 - } 2422 + ret = isp_of_parse_nodes(&pdev->dev, &isp->notifier); 2423 + if (ret < 0) 2424 + return ret; 2360 2425 2361 2426 isp->autoidle = autoidle; 2362 2427 ··· 2422 2513 goto error_isp; 2423 2514 } 2424 2515 2425 - if (!IS_ENABLED(CONFIG_OF) || !pdev->dev.of_node) { 2426 - isp->syscon_offset = isp_res_maps[m].syscon_offset; 2427 - isp->phy_type = isp_res_maps[m].phy_type; 2428 - } 2429 - 2430 2516 for (i = 1; i < OMAP3_ISP_IOMEM_CSI2A_REGS1; i++) 2431 2517 isp->mmio_base[i] = 2432 2518 isp->mmio_base[0] + isp_res_maps[m].offset[i]; ··· 2461 2557 if (ret < 0) 2462 2558 goto error_iommu; 2463 2559 2464 - isp->notifier.bound = isp_subdev_notifier_bound; 2465 - isp->notifier.complete = isp_subdev_notifier_complete; 2466 - 2467 2560 ret = isp_register_entities(isp); 2468 2561 if (ret < 0) 2469 2562 goto error_modules; 2563 + 2564 + isp->notifier.bound = isp_subdev_notifier_bound; 2565 + isp->notifier.complete = isp_subdev_notifier_complete; 2566 + 2567 + ret = v4l2_async_notifier_register(&isp->v4l2_dev, &isp->notifier); 2568 + if (ret) 2569 + goto error_register_entities; 2470 2570 2471 2571 isp_core_init(isp, 1); 2472 2572 omap3isp_put(isp); 2473 2573 2474 2574 return 0; 2475 2575 2576 + error_register_entities: 2577 + isp_unregister_entities(isp); 2476 2578 error_modules: 2477 2579 isp_cleanup_modules(isp); 2478 2580 error_iommu:
+1 -6
drivers/media/platform/omap3isp/isp.h
··· 17 17 #ifndef OMAP3_ISP_CORE_H 18 18 #define OMAP3_ISP_CORE_H 19 19 20 - #include <media/omap3isp.h> 21 20 #include <media/v4l2-async.h> 22 21 #include <media/v4l2-device.h> 23 22 #include <linux/clk-provider.h> ··· 26 27 #include <linux/platform_device.h> 27 28 #include <linux/wait.h> 28 29 30 + #include "omap3isp.h" 29 31 #include "ispstat.h" 30 32 #include "ispccdc.h" 31 33 #include "ispreg.h" ··· 101 101 * struct isp_res_mapping - Map ISP io resources to ISP revision. 102 102 * @isp_rev: ISP_REVISION_x_x 103 103 * @offset: register offsets of various ISP sub-blocks 104 - * @syscon_offset: offset of the syscon register for 343x / 3630 105 - * (CONTROL_CSIRXFE / CONTROL_CAMERA_PHY_CTRL, respectively) 106 - * from the syscon base address 107 104 * @phy_type: ISP_PHY_TYPE_{3430,3630} 108 105 */ 109 106 struct isp_res_mapping { 110 107 u32 isp_rev; 111 108 u32 offset[OMAP3_ISP_IOMEM_LAST]; 112 - u32 syscon_offset; 113 109 u32 phy_type; 114 110 }; 115 111 ··· 180 184 u32 revision; 181 185 182 186 /* platform HW resources */ 183 - struct isp_platform_data *pdata; 184 187 unsigned int irq_num; 185 188 186 189 void __iomem *mmio_base[OMAP3_ISP_IOMEM_LAST];
+1 -1
drivers/media/platform/omap3isp/ispcsiphy.h
··· 17 17 #ifndef OMAP3_ISP_CSI_PHY_H 18 18 #define OMAP3_ISP_CSI_PHY_H 19 19 20 - #include <media/omap3isp.h> 20 + #include "omap3isp.h" 21 21 22 22 struct isp_csi2_device; 23 23 struct regulator;
+3 -6
drivers/media/platform/omap3isp/ispvideo.c
··· 1018 1018 1019 1019 pipe->entities = 0; 1020 1020 1021 - if (video->isp->pdata && video->isp->pdata->set_constraints) 1022 - video->isp->pdata->set_constraints(video->isp, true); 1021 + /* TODO: Implement PM QoS */ 1023 1022 pipe->l3_ick = clk_get_rate(video->isp->clock[ISP_CLK_L3_ICK]); 1024 1023 pipe->max_rate = pipe->l3_ick; 1025 1024 ··· 1099 1100 err_check_format: 1100 1101 media_entity_pipeline_stop(&video->video.entity); 1101 1102 err_pipeline_start: 1102 - if (video->isp->pdata && video->isp->pdata->set_constraints) 1103 - video->isp->pdata->set_constraints(video->isp, false); 1103 + /* TODO: Implement PM QoS */ 1104 1104 /* The DMA queue must be emptied here, otherwise CCDC interrupts that 1105 1105 * will get triggered the next time the CCDC is powered up will try to 1106 1106 * access buffers that might have been freed but still present in the ··· 1159 1161 video->queue = NULL; 1160 1162 video->error = false; 1161 1163 1162 - if (video->isp->pdata && video->isp->pdata->set_constraints) 1163 - video->isp->pdata->set_constraints(video->isp, false); 1164 + /* TODO: Implement PM QoS */ 1164 1165 media_entity_pipeline_stop(&video->video.entity); 1165 1166 1166 1167 done:
+1794
drivers/media/platform/rcar_jpu.c
··· 1 + /* 2 + * Author: Mikhail Ulyanov 3 + * Copyright (C) 2014-2015 Cogent Embedded, Inc. <source@cogentembedded.com> 4 + * Copyright (C) 2014-2015 Renesas Electronics Corporation 5 + * 6 + * This is based on the drivers/media/platform/s5p-jpeg driver by 7 + * Andrzej Pietrasiewicz and Jacek Anaszewski. 8 + * Some portions of code inspired by VSP1 driver by Laurent Pinchart. 9 + * 10 + * TODO in order of priority: 11 + * 1) Rotation 12 + * 2) Cropping 13 + * 3) V4L2_CID_JPEG_ACTIVE_MARKER 14 + * 15 + * This program is free software; you can redistribute it and/or modify 16 + * it under the terms of the GNU General Public License version 2 as 17 + * published by the Free Software Foundation. 18 + */ 19 + 20 + #include <asm/unaligned.h> 21 + #include <linux/clk.h> 22 + #include <linux/err.h> 23 + #include <linux/interrupt.h> 24 + #include <linux/io.h> 25 + #include <linux/kernel.h> 26 + #include <linux/module.h> 27 + #include <linux/of.h> 28 + #include <linux/of_device.h> 29 + #include <linux/platform_device.h> 30 + #include <linux/slab.h> 31 + #include <linux/spinlock.h> 32 + #include <linux/string.h> 33 + #include <linux/videodev2.h> 34 + #include <media/v4l2-ctrls.h> 35 + #include <media/v4l2-device.h> 36 + #include <media/v4l2-event.h> 37 + #include <media/v4l2-fh.h> 38 + #include <media/v4l2-mem2mem.h> 39 + #include <media/v4l2-ioctl.h> 40 + #include <media/videobuf2-core.h> 41 + #include <media/videobuf2-dma-contig.h> 42 + 43 + 44 + #define DRV_NAME "rcar_jpu" 45 + 46 + /* 47 + * Align JPEG header end to cache line to make sure we will not have any issues 48 + * with cache; additionally to requerment (33.3.27 R01UH0501EJ0100 Rev.1.00) 49 + */ 50 + #define JPU_JPEG_HDR_SIZE (ALIGN(0x258, L1_CACHE_BYTES)) 51 + #define JPU_JPEG_MAX_BYTES_PER_PIXEL 2 /* 16 bit precision format */ 52 + #define JPU_JPEG_MIN_SIZE 25 /* SOI + SOF + EOI */ 53 + #define JPU_JPEG_QTBL_SIZE 0x40 54 + #define JPU_JPEG_HDCTBL_SIZE 0x1c 55 + #define JPU_JPEG_HACTBL_SIZE 0xb2 56 + #define JPU_JPEG_HEIGHT_OFFSET 0x91 57 + #define JPU_JPEG_WIDTH_OFFSET 0x93 58 + #define JPU_JPEG_SUBS_OFFSET 0x97 59 + #define JPU_JPEG_QTBL_LUM_OFFSET 0x07 60 + #define JPU_JPEG_QTBL_CHR_OFFSET 0x4c 61 + #define JPU_JPEG_HDCTBL_LUM_OFFSET 0xa4 62 + #define JPU_JPEG_HACTBL_LUM_OFFSET 0xc5 63 + #define JPU_JPEG_HDCTBL_CHR_OFFSET 0x17c 64 + #define JPU_JPEG_HACTBL_CHR_OFFSET 0x19d 65 + #define JPU_JPEG_PADDING_OFFSET 0x24f 66 + #define JPU_JPEG_LUM 0x00 67 + #define JPU_JPEG_CHR 0x01 68 + #define JPU_JPEG_DC 0x00 69 + #define JPU_JPEG_AC 0x10 70 + 71 + #define JPU_JPEG_422 0x21 72 + #define JPU_JPEG_420 0x22 73 + 74 + #define JPU_JPEG_DEFAULT_422_PIX_FMT V4L2_PIX_FMT_NV16M 75 + #define JPU_JPEG_DEFAULT_420_PIX_FMT V4L2_PIX_FMT_NV12M 76 + 77 + /* JPEG markers */ 78 + #define TEM 0x01 79 + #define SOF0 0xc0 80 + #define RST 0xd0 81 + #define SOI 0xd8 82 + #define EOI 0xd9 83 + #define DHP 0xde 84 + #define DHT 0xc4 85 + #define COM 0xfe 86 + #define DQT 0xdb 87 + #define DRI 0xdd 88 + #define APP0 0xe0 89 + 90 + #define JPU_RESET_TIMEOUT 100 /* ms */ 91 + #define JPU_JOB_TIMEOUT 300 /* ms */ 92 + #define JPU_MAX_QUALITY 4 93 + #define JPU_WIDTH_MIN 16 94 + #define JPU_HEIGHT_MIN 16 95 + #define JPU_WIDTH_MAX 4096 96 + #define JPU_HEIGHT_MAX 4096 97 + #define JPU_MEMALIGN 8 98 + 99 + /* Flags that indicate a format can be used for capture/output */ 100 + #define JPU_FMT_TYPE_OUTPUT 0 101 + #define JPU_FMT_TYPE_CAPTURE 1 102 + #define JPU_ENC_CAPTURE (1 << 0) 103 + #define JPU_ENC_OUTPUT (1 << 1) 104 + #define JPU_DEC_CAPTURE (1 << 2) 105 + #define JPU_DEC_OUTPUT (1 << 3) 106 + 107 + /* 108 + * JPEG registers and bits 109 + */ 110 + 111 + /* JPEG code mode register */ 112 + #define JCMOD 0x00 113 + #define JCMOD_PCTR (1 << 7) 114 + #define JCMOD_MSKIP_ENABLE (1 << 5) 115 + #define JCMOD_DSP_ENC (0 << 3) 116 + #define JCMOD_DSP_DEC (1 << 3) 117 + #define JCMOD_REDU (7 << 0) 118 + #define JCMOD_REDU_422 (1 << 0) 119 + #define JCMOD_REDU_420 (2 << 0) 120 + 121 + /* JPEG code command register */ 122 + #define JCCMD 0x04 123 + #define JCCMD_SRST (1 << 12) 124 + #define JCCMD_JEND (1 << 2) 125 + #define JCCMD_JSRT (1 << 0) 126 + 127 + /* JPEG code quantanization table number register */ 128 + #define JCQTN 0x0c 129 + #define JCQTN_SHIFT(t) (((t) - 1) << 1) 130 + 131 + /* JPEG code Huffman table number register */ 132 + #define JCHTN 0x10 133 + #define JCHTN_AC_SHIFT(t) (((t) << 1) - 1) 134 + #define JCHTN_DC_SHIFT(t) (((t) - 1) << 1) 135 + 136 + #define JCVSZU 0x1c /* JPEG code vertical size upper register */ 137 + #define JCVSZD 0x20 /* JPEG code vertical size lower register */ 138 + #define JCHSZU 0x24 /* JPEG code horizontal size upper register */ 139 + #define JCHSZD 0x28 /* JPEG code horizontal size lower register */ 140 + #define JCSZ_MASK 0xff /* JPEG code h/v size register contains only 1 byte*/ 141 + 142 + #define JCDTCU 0x2c /* JPEG code data count upper register */ 143 + #define JCDTCM 0x30 /* JPEG code data count middle register */ 144 + #define JCDTCD 0x34 /* JPEG code data count lower register */ 145 + 146 + /* JPEG interrupt enable register */ 147 + #define JINTE 0x38 148 + #define JINTE_ERR (7 << 5) /* INT5 + INT6 + INT7 */ 149 + #define JINTE_TRANSF_COMPL (1 << 10) 150 + 151 + /* JPEG interrupt status register */ 152 + #define JINTS 0x3c 153 + #define JINTS_MASK 0x7c68 154 + #define JINTS_ERR (1 << 5) 155 + #define JINTS_PROCESS_COMPL (1 << 6) 156 + #define JINTS_TRANSF_COMPL (1 << 10) 157 + 158 + #define JCDERR 0x40 /* JPEG code decode error register */ 159 + #define JCDERR_MASK 0xf /* JPEG code decode error register mask*/ 160 + 161 + /* JPEG interface encoding */ 162 + #define JIFECNT 0x70 163 + #define JIFECNT_INFT_422 0 164 + #define JIFECNT_INFT_420 1 165 + #define JIFECNT_SWAP_WB (3 << 4) /* to JPU */ 166 + 167 + #define JIFESYA1 0x74 /* encode source Y address register 1 */ 168 + #define JIFESCA1 0x78 /* encode source C address register 1 */ 169 + #define JIFESYA2 0x7c /* encode source Y address register 2 */ 170 + #define JIFESCA2 0x80 /* encode source C address register 2 */ 171 + #define JIFESMW 0x84 /* encode source memory width register */ 172 + #define JIFESVSZ 0x88 /* encode source vertical size register */ 173 + #define JIFESHSZ 0x8c /* encode source horizontal size register */ 174 + #define JIFEDA1 0x90 /* encode destination address register 1 */ 175 + #define JIFEDA2 0x94 /* encode destination address register 2 */ 176 + 177 + /* JPEG decoding control register */ 178 + #define JIFDCNT 0xa0 179 + #define JIFDCNT_SWAP_WB (3 << 1) /* from JPU */ 180 + 181 + #define JIFDSA1 0xa4 /* decode source address register 1 */ 182 + #define JIFDDMW 0xb0 /* decode destination memory width register */ 183 + #define JIFDDVSZ 0xb4 /* decode destination vert. size register */ 184 + #define JIFDDHSZ 0xb8 /* decode destination horiz. size register */ 185 + #define JIFDDYA1 0xbc /* decode destination Y address register 1 */ 186 + #define JIFDDCA1 0xc0 /* decode destination C address register 1 */ 187 + 188 + #define JCQTBL(n) (0x10000 + (n) * 0x40) /* quantization tables regs */ 189 + #define JCHTBD(n) (0x10100 + (n) * 0x100) /* Huffman table DC regs */ 190 + #define JCHTBA(n) (0x10120 + (n) * 0x100) /* Huffman table AC regs */ 191 + 192 + /** 193 + * struct jpu - JPEG IP abstraction 194 + * @mutex: the mutex protecting this structure 195 + * @lock: spinlock protecting the device contexts 196 + * @v4l2_dev: v4l2 device for mem2mem mode 197 + * @vfd_encoder: video device node for encoder mem2mem mode 198 + * @vfd_decoder: video device node for decoder mem2mem mode 199 + * @m2m_dev: v4l2 mem2mem device data 200 + * @curr: pointer to current context 201 + * @irq_queue: interrupt handler waitqueue 202 + * @regs: JPEG IP registers mapping 203 + * @irq: JPEG IP irq 204 + * @clk: JPEG IP clock 205 + * @dev: JPEG IP struct device 206 + * @alloc_ctx: videobuf2 memory allocator's context 207 + * @ref_count: reference counter 208 + */ 209 + struct jpu { 210 + struct mutex mutex; 211 + spinlock_t lock; 212 + struct v4l2_device v4l2_dev; 213 + struct video_device vfd_encoder; 214 + struct video_device vfd_decoder; 215 + struct v4l2_m2m_dev *m2m_dev; 216 + struct jpu_ctx *curr; 217 + wait_queue_head_t irq_queue; 218 + 219 + void __iomem *regs; 220 + unsigned int irq; 221 + struct clk *clk; 222 + struct device *dev; 223 + void *alloc_ctx; 224 + int ref_count; 225 + }; 226 + 227 + /** 228 + * struct jpu_buffer - driver's specific video buffer 229 + * @buf: m2m buffer 230 + * @compr_quality: destination image quality in compression mode 231 + * @subsampling: source image subsampling in decompression mode 232 + */ 233 + struct jpu_buffer { 234 + struct v4l2_m2m_buffer buf; 235 + unsigned short compr_quality; 236 + unsigned char subsampling; 237 + }; 238 + 239 + /** 240 + * struct jpu_fmt - driver's internal format data 241 + * @fourcc: the fourcc code, 0 if not applicable 242 + * @colorspace: the colorspace specifier 243 + * @bpp: number of bits per pixel per plane 244 + * @h_align: horizontal alignment order (align to 2^h_align) 245 + * @v_align: vertical alignment order (align to 2^v_align) 246 + * @subsampling: (horizontal:4 | vertical:4) subsampling factor 247 + * @num_planes: number of planes 248 + * @types: types of queue this format is applicable to 249 + */ 250 + struct jpu_fmt { 251 + u32 fourcc; 252 + u32 colorspace; 253 + u8 bpp[2]; 254 + u8 h_align; 255 + u8 v_align; 256 + u8 subsampling; 257 + u8 num_planes; 258 + u16 types; 259 + }; 260 + 261 + /** 262 + * jpu_q_data - parameters of one queue 263 + * @fmtinfo: driver-specific format of this queue 264 + * @format: multiplanar format of this queue 265 + * @sequence: sequence number 266 + */ 267 + struct jpu_q_data { 268 + struct jpu_fmt *fmtinfo; 269 + struct v4l2_pix_format_mplane format; 270 + unsigned int sequence; 271 + }; 272 + 273 + /** 274 + * jpu_ctx - the device context data 275 + * @jpu: JPEG IP device for this context 276 + * @encoder: compression (encode) operation or decompression (decode) 277 + * @compr_quality: destination image quality in compression (encode) mode 278 + * @out_q: source (output) queue information 279 + * @cap_q: destination (capture) queue information 280 + * @fh: file handler 281 + * @ctrl_handler: controls handler 282 + */ 283 + struct jpu_ctx { 284 + struct jpu *jpu; 285 + bool encoder; 286 + unsigned short compr_quality; 287 + struct jpu_q_data out_q; 288 + struct jpu_q_data cap_q; 289 + struct v4l2_fh fh; 290 + struct v4l2_ctrl_handler ctrl_handler; 291 + }; 292 + 293 + /** 294 + * jpeg_buffer - description of memory containing input JPEG data 295 + * @end: end position in the buffer 296 + * @curr: current position in the buffer 297 + */ 298 + struct jpeg_buffer { 299 + void *end; 300 + void *curr; 301 + }; 302 + 303 + static struct jpu_fmt jpu_formats[] = { 304 + { V4L2_PIX_FMT_JPEG, V4L2_COLORSPACE_JPEG, 305 + {0, 0}, 0, 0, 0, 1, JPU_ENC_CAPTURE | JPU_DEC_OUTPUT }, 306 + { V4L2_PIX_FMT_NV16M, V4L2_COLORSPACE_SRGB, 307 + {8, 8}, 2, 2, JPU_JPEG_422, 2, JPU_ENC_OUTPUT | JPU_DEC_CAPTURE }, 308 + { V4L2_PIX_FMT_NV12M, V4L2_COLORSPACE_SRGB, 309 + {8, 4}, 2, 2, JPU_JPEG_420, 2, JPU_ENC_OUTPUT | JPU_DEC_CAPTURE }, 310 + { V4L2_PIX_FMT_NV16, V4L2_COLORSPACE_SRGB, 311 + {16, 0}, 2, 2, JPU_JPEG_422, 1, JPU_ENC_OUTPUT | JPU_DEC_CAPTURE }, 312 + { V4L2_PIX_FMT_NV12, V4L2_COLORSPACE_SRGB, 313 + {12, 0}, 2, 2, JPU_JPEG_420, 1, JPU_ENC_OUTPUT | JPU_DEC_CAPTURE }, 314 + }; 315 + 316 + static const u8 zigzag[] = { 317 + 0x03, 0x02, 0x0b, 0x13, 0x0a, 0x01, 0x00, 0x09, 318 + 0x12, 0x1b, 0x23, 0x1a, 0x11, 0x08, 0x07, 0x06, 319 + 0x0f, 0x10, 0x19, 0x22, 0x2b, 0x33, 0x2a, 0x21, 320 + 0x18, 0x17, 0x0e, 0x05, 0x04, 0x0d, 0x16, 0x1f, 321 + 0x20, 0x29, 0x32, 0x3b, 0x3a, 0x31, 0x28, 0x27, 322 + 0x1e, 0x15, 0x0e, 0x14, 0x10, 0x26, 0x2f, 0x30, 323 + 0x39, 0x38, 0x37, 0x2e, 0x25, 0x1c, 0x24, 0x2b, 324 + 0x36, 0x3f, 0x3e, 0x35, 0x2c, 0x34, 0x3d, 0x3c 325 + }; 326 + 327 + #define QTBL_SIZE (ALIGN(JPU_JPEG_QTBL_SIZE, \ 328 + sizeof(unsigned int)) / sizeof(unsigned int)) 329 + #define HDCTBL_SIZE (ALIGN(JPU_JPEG_HDCTBL_SIZE, \ 330 + sizeof(unsigned int)) / sizeof(unsigned int)) 331 + #define HACTBL_SIZE (ALIGN(JPU_JPEG_HACTBL_SIZE, \ 332 + sizeof(unsigned int)) / sizeof(unsigned int)) 333 + /* 334 + * Start of image; Quantization tables 335 + * SOF0 (17 bytes payload) is Baseline DCT - Sample precision, height, width, 336 + * Number of image components, (Ci:8 - Hi:4 - Vi:4 - Tq:8) * 3 - Y,Cb,Cr; 337 + * Huffman tables; Padding with 0xff (33.3.27 R01UH0501EJ0100 Rev.1.00) 338 + */ 339 + #define JPU_JPEG_HDR_BLOB { \ 340 + 0xff, SOI, 0xff, DQT, 0x00, JPU_JPEG_QTBL_SIZE + 0x3, JPU_JPEG_LUM, \ 341 + [JPU_JPEG_QTBL_LUM_OFFSET ... \ 342 + JPU_JPEG_QTBL_LUM_OFFSET + JPU_JPEG_QTBL_SIZE - 1] = 0x00, \ 343 + 0xff, DQT, 0x00, JPU_JPEG_QTBL_SIZE + 0x3, JPU_JPEG_CHR, \ 344 + [JPU_JPEG_QTBL_CHR_OFFSET ... JPU_JPEG_QTBL_CHR_OFFSET + \ 345 + JPU_JPEG_QTBL_SIZE - 1] = 0x00, 0xff, SOF0, 0x00, 0x11, 0x08, \ 346 + [JPU_JPEG_HEIGHT_OFFSET ... JPU_JPEG_HEIGHT_OFFSET + 1] = 0x00, \ 347 + [JPU_JPEG_WIDTH_OFFSET ... JPU_JPEG_WIDTH_OFFSET + 1] = 0x00, \ 348 + 0x03, 0x01, [JPU_JPEG_SUBS_OFFSET] = 0x00, JPU_JPEG_LUM, \ 349 + 0x02, 0x11, JPU_JPEG_CHR, 0x03, 0x11, JPU_JPEG_CHR, \ 350 + 0xff, DHT, 0x00, JPU_JPEG_HDCTBL_SIZE + 0x3, JPU_JPEG_LUM|JPU_JPEG_DC, \ 351 + [JPU_JPEG_HDCTBL_LUM_OFFSET ... \ 352 + JPU_JPEG_HDCTBL_LUM_OFFSET + JPU_JPEG_HDCTBL_SIZE - 1] = 0x00, \ 353 + 0xff, DHT, 0x00, JPU_JPEG_HACTBL_SIZE + 0x3, JPU_JPEG_LUM|JPU_JPEG_AC, \ 354 + [JPU_JPEG_HACTBL_LUM_OFFSET ... \ 355 + JPU_JPEG_HACTBL_LUM_OFFSET + JPU_JPEG_HACTBL_SIZE - 1] = 0x00, \ 356 + 0xff, DHT, 0x00, JPU_JPEG_HDCTBL_SIZE + 0x3, JPU_JPEG_CHR|JPU_JPEG_DC, \ 357 + [JPU_JPEG_HDCTBL_CHR_OFFSET ... \ 358 + JPU_JPEG_HDCTBL_CHR_OFFSET + JPU_JPEG_HDCTBL_SIZE - 1] = 0x00, \ 359 + 0xff, DHT, 0x00, JPU_JPEG_HACTBL_SIZE + 0x3, JPU_JPEG_CHR|JPU_JPEG_AC, \ 360 + [JPU_JPEG_HACTBL_CHR_OFFSET ... \ 361 + JPU_JPEG_HACTBL_CHR_OFFSET + JPU_JPEG_HACTBL_SIZE - 1] = 0x00, \ 362 + [JPU_JPEG_PADDING_OFFSET ... JPU_JPEG_HDR_SIZE - 1] = 0xff \ 363 + } 364 + 365 + static unsigned char jpeg_hdrs[JPU_MAX_QUALITY][JPU_JPEG_HDR_SIZE] = { 366 + [0 ... JPU_MAX_QUALITY - 1] = JPU_JPEG_HDR_BLOB 367 + }; 368 + 369 + static const unsigned int qtbl_lum[JPU_MAX_QUALITY][QTBL_SIZE] = { 370 + { 371 + 0x14101927, 0x322e3e44, 0x10121726, 0x26354144, 372 + 0x19171f26, 0x35414444, 0x27262635, 0x41444444, 373 + 0x32263541, 0x44444444, 0x2e354144, 0x44444444, 374 + 0x3e414444, 0x44444444, 0x44444444, 0x44444444 375 + }, 376 + { 377 + 0x100b0b10, 0x171b1f1e, 0x0b0c0c0f, 0x1417171e, 378 + 0x0b0c0d10, 0x171a232f, 0x100f1017, 0x1a252f40, 379 + 0x1714171a, 0x27334040, 0x1b171a25, 0x33404040, 380 + 0x1f17232f, 0x40404040, 0x1e1e2f40, 0x40404040 381 + }, 382 + { 383 + 0x0c08080c, 0x11151817, 0x0809090b, 0x0f131217, 384 + 0x08090a0c, 0x13141b24, 0x0c0b0c15, 0x141c2435, 385 + 0x110f1314, 0x1e27333b, 0x1513141c, 0x27333b3b, 386 + 0x18121b24, 0x333b3b3b, 0x17172435, 0x3b3b3b3b 387 + }, 388 + { 389 + 0x08060608, 0x0c0e1011, 0x06060608, 0x0a0d0c0f, 390 + 0x06060708, 0x0d0e1218, 0x0808080e, 0x0d131823, 391 + 0x0c0a0d0d, 0x141a2227, 0x0e0d0e13, 0x1a222727, 392 + 0x100c1318, 0x22272727, 0x110f1823, 0x27272727 393 + } 394 + }; 395 + 396 + static const unsigned int qtbl_chr[JPU_MAX_QUALITY][QTBL_SIZE] = { 397 + { 398 + 0x15192026, 0x36444444, 0x191c1826, 0x36444444, 399 + 0x2018202b, 0x42444444, 0x26262b35, 0x44444444, 400 + 0x36424444, 0x44444444, 0x44444444, 0x44444444, 401 + 0x44444444, 0x44444444, 0x44444444, 0x44444444 402 + }, 403 + { 404 + 0x110f1115, 0x141a2630, 0x0f131211, 0x141a232b, 405 + 0x11121416, 0x1a1e2e35, 0x1511161c, 0x1e273540, 406 + 0x14141a1e, 0x27304040, 0x1a1a1e27, 0x303f4040, 407 + 0x26232e35, 0x40404040, 0x302b3540, 0x40404040 408 + }, 409 + { 410 + 0x0d0b0d10, 0x14141d25, 0x0b0e0e0e, 0x10141a20, 411 + 0x0d0e0f11, 0x14172328, 0x100e1115, 0x171e2832, 412 + 0x14101417, 0x1e25323b, 0x1414171e, 0x25303b3b, 413 + 0x1d1a2328, 0x323b3b3b, 0x25202832, 0x3b3b3b3b 414 + }, 415 + { 416 + 0x0908090b, 0x0e111318, 0x080a090b, 0x0e0d1116, 417 + 0x09090d0e, 0x0d0f171a, 0x0b0b0e0e, 0x0f141a21, 418 + 0x0e0e0d0f, 0x14182127, 0x110d0f14, 0x18202727, 419 + 0x1311171a, 0x21272727, 0x18161a21, 0x27272727 420 + } 421 + }; 422 + 423 + static const unsigned int hdctbl_lum[HDCTBL_SIZE] = { 424 + 0x00010501, 0x01010101, 0x01000000, 0x00000000, 425 + 0x00010203, 0x04050607, 0x08090a0b 426 + }; 427 + 428 + static const unsigned int hdctbl_chr[HDCTBL_SIZE] = { 429 + 0x00010501, 0x01010101, 0x01000000, 0x00000000, 430 + 0x00010203, 0x04050607, 0x08090a0b 431 + }; 432 + 433 + static const unsigned int hactbl_lum[HACTBL_SIZE] = { 434 + 0x00020103, 0x03020403, 0x05050404, 0x0000017d, 0x01020300, 0x04110512, 435 + 0x21314106, 0x13516107, 0x22711432, 0x8191a108, 0x2342b1c1, 0x1552d1f0, 436 + 0x24336272, 0x82090a16, 0x1718191a, 0x25262728, 0x292a3435, 0x36373839, 437 + 0x3a434445, 0x46474849, 0x4a535455, 0x56575859, 0x5a636465, 0x66676869, 438 + 0x6a737475, 0x76777879, 0x7a838485, 0x86878889, 0x8a929394, 0x95969798, 439 + 0x999aa2a3, 0xa4a5a6a7, 0xa8a9aab2, 0xb3b4b5b6, 0xb7b8b9ba, 0xc2c3c4c5, 440 + 0xc6c7c8c9, 0xcad2d3d4, 0xd5d6d7d8, 0xd9dae1e2, 0xe3e4e5e6, 0xe7e8e9ea, 441 + 0xf1f2f3f4, 0xf5f6f7f8, 0xf9fa0000 442 + }; 443 + 444 + static const unsigned int hactbl_chr[HACTBL_SIZE] = { 445 + 0x00020103, 0x03020403, 0x05050404, 0x0000017d, 0x01020300, 0x04110512, 446 + 0x21314106, 0x13516107, 0x22711432, 0x8191a108, 0x2342b1c1, 0x1552d1f0, 447 + 0x24336272, 0x82090a16, 0x1718191a, 0x25262728, 0x292a3435, 0x36373839, 448 + 0x3a434445, 0x46474849, 0x4a535455, 0x56575859, 0x5a636465, 0x66676869, 449 + 0x6a737475, 0x76777879, 0x7a838485, 0x86878889, 0x8a929394, 0x95969798, 450 + 0x999aa2a3, 0xa4a5a6a7, 0xa8a9aab2, 0xb3b4b5b6, 0xb7b8b9ba, 0xc2c3c4c5, 451 + 0xc6c7c8c9, 0xcad2d3d4, 0xd5d6d7d8, 0xd9dae1e2, 0xe3e4e5e6, 0xe7e8e9ea, 452 + 0xf1f2f3f4, 0xf5f6f7f8, 0xf9fa0000 453 + }; 454 + 455 + static const char *error_to_text[16] = { 456 + "Normal", 457 + "SOI not detected", 458 + "SOF1 to SOFF detected", 459 + "Subsampling not detected", 460 + "SOF accuracy error", 461 + "DQT accuracy error", 462 + "Component error 1", 463 + "Component error 2", 464 + "SOF0, DQT, and DHT not detected when SOS detected", 465 + "SOS not detected", 466 + "EOI not detected", 467 + "Restart interval data number error detected", 468 + "Image size error", 469 + "Last MCU data number error", 470 + "Block data number error", 471 + "Unknown" 472 + }; 473 + 474 + static struct jpu_buffer *vb2_to_jpu_buffer(struct vb2_buffer *vb) 475 + { 476 + struct v4l2_m2m_buffer *b = 477 + container_of(vb, struct v4l2_m2m_buffer, vb); 478 + 479 + return container_of(b, struct jpu_buffer, buf); 480 + } 481 + 482 + static u32 jpu_read(struct jpu *jpu, unsigned int reg) 483 + { 484 + return ioread32(jpu->regs + reg); 485 + } 486 + 487 + static void jpu_write(struct jpu *jpu, u32 val, unsigned int reg) 488 + { 489 + iowrite32(val, jpu->regs + reg); 490 + } 491 + 492 + static struct jpu_ctx *ctrl_to_ctx(struct v4l2_ctrl *c) 493 + { 494 + return container_of(c->handler, struct jpu_ctx, ctrl_handler); 495 + } 496 + 497 + static struct jpu_ctx *fh_to_ctx(struct v4l2_fh *fh) 498 + { 499 + return container_of(fh, struct jpu_ctx, fh); 500 + } 501 + 502 + static void jpu_set_tbl(struct jpu *jpu, u32 reg, const unsigned int *tbl, 503 + unsigned int len) { 504 + unsigned int i; 505 + 506 + for (i = 0; i < len; i++) 507 + jpu_write(jpu, tbl[i], reg + (i << 2)); 508 + } 509 + 510 + static void jpu_set_qtbl(struct jpu *jpu, unsigned short quality) 511 + { 512 + jpu_set_tbl(jpu, JCQTBL(0), qtbl_lum[quality], QTBL_SIZE); 513 + jpu_set_tbl(jpu, JCQTBL(1), qtbl_chr[quality], QTBL_SIZE); 514 + } 515 + 516 + static void jpu_set_htbl(struct jpu *jpu) 517 + { 518 + jpu_set_tbl(jpu, JCHTBD(0), hdctbl_lum, HDCTBL_SIZE); 519 + jpu_set_tbl(jpu, JCHTBA(0), hactbl_lum, HACTBL_SIZE); 520 + jpu_set_tbl(jpu, JCHTBD(1), hdctbl_chr, HDCTBL_SIZE); 521 + jpu_set_tbl(jpu, JCHTBA(1), hactbl_chr, HACTBL_SIZE); 522 + } 523 + 524 + static int jpu_wait_reset(struct jpu *jpu) 525 + { 526 + unsigned long timeout; 527 + 528 + timeout = jiffies + msecs_to_jiffies(JPU_RESET_TIMEOUT); 529 + 530 + while (jpu_read(jpu, JCCMD) & JCCMD_SRST) { 531 + if (time_after(jiffies, timeout)) { 532 + dev_err(jpu->dev, "timed out in reset\n"); 533 + return -ETIMEDOUT; 534 + } 535 + schedule(); 536 + } 537 + 538 + return 0; 539 + } 540 + 541 + static int jpu_reset(struct jpu *jpu) 542 + { 543 + jpu_write(jpu, JCCMD_SRST, JCCMD); 544 + return jpu_wait_reset(jpu); 545 + } 546 + 547 + /* 548 + * ============================================================================ 549 + * video ioctl operations 550 + * ============================================================================ 551 + */ 552 + static void put_qtbl(u8 *p, const u8 *qtbl) 553 + { 554 + unsigned int i; 555 + 556 + for (i = 0; i < ARRAY_SIZE(zigzag); i++) 557 + p[i] = *(qtbl + zigzag[i]); 558 + } 559 + 560 + static void put_htbl(u8 *p, const u8 *htbl, unsigned int len) 561 + { 562 + unsigned int i, j; 563 + 564 + for (i = 0; i < len; i += 4) 565 + for (j = 0; j < 4 && (i + j) < len; ++j) 566 + p[i + j] = htbl[i + 3 - j]; 567 + } 568 + 569 + static void jpu_generate_hdr(unsigned short quality, unsigned char *p) 570 + { 571 + put_qtbl(p + JPU_JPEG_QTBL_LUM_OFFSET, (const u8 *)qtbl_lum[quality]); 572 + put_qtbl(p + JPU_JPEG_QTBL_CHR_OFFSET, (const u8 *)qtbl_chr[quality]); 573 + 574 + put_htbl(p + JPU_JPEG_HDCTBL_LUM_OFFSET, (const u8 *)hdctbl_lum, 575 + JPU_JPEG_HDCTBL_SIZE); 576 + put_htbl(p + JPU_JPEG_HACTBL_LUM_OFFSET, (const u8 *)hactbl_lum, 577 + JPU_JPEG_HACTBL_SIZE); 578 + 579 + put_htbl(p + JPU_JPEG_HDCTBL_CHR_OFFSET, (const u8 *)hdctbl_chr, 580 + JPU_JPEG_HDCTBL_SIZE); 581 + put_htbl(p + JPU_JPEG_HACTBL_CHR_OFFSET, (const u8 *)hactbl_chr, 582 + JPU_JPEG_HACTBL_SIZE); 583 + } 584 + 585 + static int get_byte(struct jpeg_buffer *buf) 586 + { 587 + if (buf->curr >= buf->end) 588 + return -1; 589 + 590 + return *(u8 *)buf->curr++; 591 + } 592 + 593 + static int get_word_be(struct jpeg_buffer *buf, unsigned int *word) 594 + { 595 + if (buf->end - buf->curr < 2) 596 + return -1; 597 + 598 + *word = get_unaligned_be16(buf->curr); 599 + buf->curr += 2; 600 + 601 + return 0; 602 + } 603 + 604 + static void skip(struct jpeg_buffer *buf, unsigned long len) 605 + { 606 + buf->curr += min((unsigned long)(buf->end - buf->curr), len); 607 + } 608 + 609 + static u8 jpu_parse_hdr(void *buffer, unsigned long size, unsigned int *width, 610 + unsigned int *height) 611 + { 612 + struct jpeg_buffer jpeg_buffer; 613 + unsigned int word; 614 + bool soi = false; 615 + 616 + jpeg_buffer.end = buffer + size; 617 + jpeg_buffer.curr = buffer; 618 + 619 + /* 620 + * basic size check and EOI - we don't want to let JPU cross 621 + * buffer bounds in any case. Hope it's stopping by EOI. 622 + */ 623 + if (size < JPU_JPEG_MIN_SIZE || *(u8 *)(buffer + size - 1) != EOI) 624 + return 0; 625 + 626 + for (;;) { 627 + int c; 628 + 629 + /* skip preceding filler bytes */ 630 + do 631 + c = get_byte(&jpeg_buffer); 632 + while (c == 0xff || c == 0); 633 + 634 + if (!soi && c == SOI) { 635 + soi = true; 636 + continue; 637 + } else if (soi != (c != SOI)) 638 + return 0; 639 + 640 + switch (c) { 641 + case SOF0: /* SOF0: baseline JPEG */ 642 + skip(&jpeg_buffer, 3); /* segment length and bpp */ 643 + if (get_word_be(&jpeg_buffer, height) || 644 + get_word_be(&jpeg_buffer, width) || 645 + get_byte(&jpeg_buffer) != 3) /* YCbCr only */ 646 + return 0; 647 + 648 + skip(&jpeg_buffer, 1); 649 + return get_byte(&jpeg_buffer); 650 + case DHT: 651 + case DQT: 652 + case COM: 653 + case DRI: 654 + case APP0 ... APP0 + 0x0f: 655 + if (get_word_be(&jpeg_buffer, &word)) 656 + return 0; 657 + skip(&jpeg_buffer, (long)word - 2); 658 + case 0: 659 + break; 660 + default: 661 + return 0; 662 + } 663 + } 664 + 665 + return 0; 666 + } 667 + 668 + static int jpu_querycap(struct file *file, void *priv, 669 + struct v4l2_capability *cap) 670 + { 671 + struct jpu_ctx *ctx = fh_to_ctx(priv); 672 + 673 + if (ctx->encoder) 674 + strlcpy(cap->card, DRV_NAME " encoder", sizeof(cap->card)); 675 + else 676 + strlcpy(cap->card, DRV_NAME " decoder", sizeof(cap->card)); 677 + 678 + strlcpy(cap->driver, DRV_NAME, sizeof(cap->driver)); 679 + snprintf(cap->bus_info, sizeof(cap->bus_info), "platform:%s", 680 + dev_name(ctx->jpu->dev)); 681 + cap->device_caps |= V4L2_CAP_STREAMING | V4L2_CAP_VIDEO_M2M_MPLANE; 682 + cap->capabilities = V4L2_CAP_DEVICE_CAPS | cap->device_caps; 683 + memset(cap->reserved, 0, sizeof(cap->reserved)); 684 + 685 + return 0; 686 + } 687 + 688 + static struct jpu_fmt *jpu_find_format(bool encoder, u32 pixelformat, 689 + unsigned int fmt_type) 690 + { 691 + unsigned int i, fmt_flag; 692 + 693 + if (encoder) 694 + fmt_flag = fmt_type == JPU_FMT_TYPE_OUTPUT ? JPU_ENC_OUTPUT : 695 + JPU_ENC_CAPTURE; 696 + else 697 + fmt_flag = fmt_type == JPU_FMT_TYPE_OUTPUT ? JPU_DEC_OUTPUT : 698 + JPU_DEC_CAPTURE; 699 + 700 + for (i = 0; i < ARRAY_SIZE(jpu_formats); i++) { 701 + struct jpu_fmt *fmt = &jpu_formats[i]; 702 + 703 + if (fmt->fourcc == pixelformat && fmt->types & fmt_flag) 704 + return fmt; 705 + } 706 + 707 + return NULL; 708 + } 709 + 710 + static int jpu_enum_fmt(struct v4l2_fmtdesc *f, u32 type) 711 + { 712 + unsigned int i, num = 0; 713 + 714 + for (i = 0; i < ARRAY_SIZE(jpu_formats); ++i) { 715 + if (jpu_formats[i].types & type) { 716 + if (num == f->index) 717 + break; 718 + ++num; 719 + } 720 + } 721 + 722 + if (i >= ARRAY_SIZE(jpu_formats)) 723 + return -EINVAL; 724 + 725 + f->pixelformat = jpu_formats[i].fourcc; 726 + 727 + return 0; 728 + } 729 + 730 + static int jpu_enum_fmt_cap(struct file *file, void *priv, 731 + struct v4l2_fmtdesc *f) 732 + { 733 + struct jpu_ctx *ctx = fh_to_ctx(priv); 734 + 735 + return jpu_enum_fmt(f, ctx->encoder ? JPU_ENC_CAPTURE : 736 + JPU_DEC_CAPTURE); 737 + } 738 + 739 + static int jpu_enum_fmt_out(struct file *file, void *priv, 740 + struct v4l2_fmtdesc *f) 741 + { 742 + struct jpu_ctx *ctx = fh_to_ctx(priv); 743 + 744 + return jpu_enum_fmt(f, ctx->encoder ? JPU_ENC_OUTPUT : JPU_DEC_OUTPUT); 745 + } 746 + 747 + static struct jpu_q_data *jpu_get_q_data(struct jpu_ctx *ctx, 748 + enum v4l2_buf_type type) 749 + { 750 + if (V4L2_TYPE_IS_OUTPUT(type)) 751 + return &ctx->out_q; 752 + else 753 + return &ctx->cap_q; 754 + } 755 + 756 + static void jpu_bound_align_image(u32 *w, unsigned int w_min, 757 + unsigned int w_max, unsigned int w_align, 758 + u32 *h, unsigned int h_min, 759 + unsigned int h_max, unsigned int h_align) 760 + { 761 + unsigned int width, height, w_step, h_step; 762 + 763 + width = *w; 764 + height = *h; 765 + 766 + w_step = 1U << w_align; 767 + h_step = 1U << h_align; 768 + v4l_bound_align_image(w, w_min, w_max, w_align, h, h_min, h_max, 769 + h_align, 3); 770 + 771 + if (*w < width && *w + w_step < w_max) 772 + *w += w_step; 773 + if (*h < height && *h + h_step < h_max) 774 + *h += h_step; 775 + } 776 + 777 + static int __jpu_try_fmt(struct jpu_ctx *ctx, struct jpu_fmt **fmtinfo, 778 + struct v4l2_pix_format_mplane *pix, 779 + enum v4l2_buf_type type) 780 + { 781 + struct jpu_fmt *fmt; 782 + unsigned int f_type, w, h; 783 + 784 + f_type = V4L2_TYPE_IS_OUTPUT(type) ? JPU_FMT_TYPE_OUTPUT : 785 + JPU_FMT_TYPE_CAPTURE; 786 + 787 + fmt = jpu_find_format(ctx->encoder, pix->pixelformat, f_type); 788 + if (!fmt) { 789 + unsigned int pixelformat; 790 + 791 + dev_dbg(ctx->jpu->dev, "unknown format; set default format\n"); 792 + if (ctx->encoder) 793 + pixelformat = f_type == JPU_FMT_TYPE_OUTPUT ? 794 + V4L2_PIX_FMT_NV16M : V4L2_PIX_FMT_JPEG; 795 + else 796 + pixelformat = f_type == JPU_FMT_TYPE_CAPTURE ? 797 + V4L2_PIX_FMT_NV16M : V4L2_PIX_FMT_JPEG; 798 + fmt = jpu_find_format(ctx->encoder, pixelformat, f_type); 799 + } 800 + 801 + pix->pixelformat = fmt->fourcc; 802 + pix->colorspace = fmt->colorspace; 803 + pix->field = V4L2_FIELD_NONE; 804 + pix->num_planes = fmt->num_planes; 805 + memset(pix->reserved, 0, sizeof(pix->reserved)); 806 + 807 + jpu_bound_align_image(&pix->width, JPU_WIDTH_MIN, JPU_WIDTH_MAX, 808 + fmt->h_align, &pix->height, JPU_HEIGHT_MIN, 809 + JPU_HEIGHT_MAX, fmt->v_align); 810 + 811 + w = pix->width; 812 + h = pix->height; 813 + 814 + if (fmt->fourcc == V4L2_PIX_FMT_JPEG) { 815 + /* ignore userspaces's sizeimage for encoding */ 816 + if (pix->plane_fmt[0].sizeimage <= 0 || ctx->encoder) 817 + pix->plane_fmt[0].sizeimage = JPU_JPEG_HDR_SIZE + 818 + (JPU_JPEG_MAX_BYTES_PER_PIXEL * w * h); 819 + pix->plane_fmt[0].bytesperline = 0; 820 + memset(pix->plane_fmt[0].reserved, 0, 821 + sizeof(pix->plane_fmt[0].reserved)); 822 + } else { 823 + unsigned int i, bpl = 0; 824 + 825 + for (i = 0; i < pix->num_planes; ++i) 826 + bpl = max(bpl, pix->plane_fmt[i].bytesperline); 827 + 828 + bpl = clamp_t(unsigned int, bpl, w, JPU_WIDTH_MAX); 829 + bpl = round_up(bpl, JPU_MEMALIGN); 830 + 831 + for (i = 0; i < pix->num_planes; ++i) { 832 + pix->plane_fmt[i].bytesperline = bpl; 833 + pix->plane_fmt[i].sizeimage = bpl * h * fmt->bpp[i] / 8; 834 + memset(pix->plane_fmt[i].reserved, 0, 835 + sizeof(pix->plane_fmt[i].reserved)); 836 + } 837 + } 838 + 839 + if (fmtinfo) 840 + *fmtinfo = fmt; 841 + 842 + return 0; 843 + } 844 + 845 + static int jpu_try_fmt(struct file *file, void *priv, struct v4l2_format *f) 846 + { 847 + struct jpu_ctx *ctx = fh_to_ctx(priv); 848 + 849 + if (!v4l2_m2m_get_vq(ctx->fh.m2m_ctx, f->type)) 850 + return -EINVAL; 851 + 852 + return __jpu_try_fmt(ctx, NULL, &f->fmt.pix_mp, f->type); 853 + } 854 + 855 + static int jpu_s_fmt(struct file *file, void *priv, struct v4l2_format *f) 856 + { 857 + struct vb2_queue *vq; 858 + struct jpu_ctx *ctx = fh_to_ctx(priv); 859 + struct v4l2_m2m_ctx *m2m_ctx = ctx->fh.m2m_ctx; 860 + struct jpu_fmt *fmtinfo; 861 + struct jpu_q_data *q_data; 862 + int ret; 863 + 864 + vq = v4l2_m2m_get_vq(m2m_ctx, f->type); 865 + if (!vq) 866 + return -EINVAL; 867 + 868 + if (vb2_is_busy(vq)) { 869 + v4l2_err(&ctx->jpu->v4l2_dev, "%s queue busy\n", __func__); 870 + return -EBUSY; 871 + } 872 + 873 + ret = __jpu_try_fmt(ctx, &fmtinfo, &f->fmt.pix_mp, f->type); 874 + if (ret < 0) 875 + return ret; 876 + 877 + q_data = jpu_get_q_data(ctx, f->type); 878 + 879 + q_data->format = f->fmt.pix_mp; 880 + q_data->fmtinfo = fmtinfo; 881 + 882 + return 0; 883 + } 884 + 885 + static int jpu_g_fmt(struct file *file, void *priv, struct v4l2_format *f) 886 + { 887 + struct jpu_q_data *q_data; 888 + struct jpu_ctx *ctx = fh_to_ctx(priv); 889 + 890 + if (!v4l2_m2m_get_vq(ctx->fh.m2m_ctx, f->type)) 891 + return -EINVAL; 892 + 893 + q_data = jpu_get_q_data(ctx, f->type); 894 + f->fmt.pix_mp = q_data->format; 895 + 896 + return 0; 897 + } 898 + 899 + /* 900 + * V4L2 controls 901 + */ 902 + static int jpu_s_ctrl(struct v4l2_ctrl *ctrl) 903 + { 904 + struct jpu_ctx *ctx = ctrl_to_ctx(ctrl); 905 + unsigned long flags; 906 + 907 + spin_lock_irqsave(&ctx->jpu->lock, flags); 908 + if (ctrl->id == V4L2_CID_JPEG_COMPRESSION_QUALITY) 909 + ctx->compr_quality = ctrl->val; 910 + spin_unlock_irqrestore(&ctx->jpu->lock, flags); 911 + 912 + return 0; 913 + } 914 + 915 + static const struct v4l2_ctrl_ops jpu_ctrl_ops = { 916 + .s_ctrl = jpu_s_ctrl, 917 + }; 918 + 919 + static int jpu_streamon(struct file *file, void *priv, enum v4l2_buf_type type) 920 + { 921 + struct jpu_ctx *ctx = fh_to_ctx(priv); 922 + struct jpu_q_data *src_q_data, *dst_q_data, *orig, adj, *ref; 923 + enum v4l2_buf_type adj_type; 924 + 925 + src_q_data = jpu_get_q_data(ctx, V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE); 926 + dst_q_data = jpu_get_q_data(ctx, V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE); 927 + 928 + if (ctx->encoder) { 929 + adj = *src_q_data; 930 + orig = src_q_data; 931 + ref = dst_q_data; 932 + adj_type = V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE; 933 + } else { 934 + adj = *dst_q_data; 935 + orig = dst_q_data; 936 + ref = src_q_data; 937 + adj_type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE; 938 + } 939 + 940 + adj.format.width = ref->format.width; 941 + adj.format.height = ref->format.height; 942 + 943 + __jpu_try_fmt(ctx, NULL, &adj.format, adj_type); 944 + 945 + if (adj.format.width != orig->format.width || 946 + adj.format.height != orig->format.height) { 947 + dev_err(ctx->jpu->dev, "src and dst formats do not match.\n"); 948 + /* maybe we can return -EPIPE here? */ 949 + return -EINVAL; 950 + } 951 + 952 + return v4l2_m2m_streamon(file, ctx->fh.m2m_ctx, type); 953 + } 954 + 955 + static const struct v4l2_ioctl_ops jpu_ioctl_ops = { 956 + .vidioc_querycap = jpu_querycap, 957 + 958 + .vidioc_enum_fmt_vid_cap_mplane = jpu_enum_fmt_cap, 959 + .vidioc_enum_fmt_vid_out_mplane = jpu_enum_fmt_out, 960 + .vidioc_g_fmt_vid_cap_mplane = jpu_g_fmt, 961 + .vidioc_g_fmt_vid_out_mplane = jpu_g_fmt, 962 + .vidioc_try_fmt_vid_cap_mplane = jpu_try_fmt, 963 + .vidioc_try_fmt_vid_out_mplane = jpu_try_fmt, 964 + .vidioc_s_fmt_vid_cap_mplane = jpu_s_fmt, 965 + .vidioc_s_fmt_vid_out_mplane = jpu_s_fmt, 966 + 967 + .vidioc_reqbufs = v4l2_m2m_ioctl_reqbufs, 968 + .vidioc_create_bufs = v4l2_m2m_ioctl_create_bufs, 969 + .vidioc_querybuf = v4l2_m2m_ioctl_querybuf, 970 + .vidioc_qbuf = v4l2_m2m_ioctl_qbuf, 971 + .vidioc_dqbuf = v4l2_m2m_ioctl_dqbuf, 972 + .vidioc_expbuf = v4l2_m2m_ioctl_expbuf, 973 + 974 + .vidioc_streamon = jpu_streamon, 975 + .vidioc_streamoff = v4l2_m2m_ioctl_streamoff, 976 + 977 + .vidioc_subscribe_event = v4l2_ctrl_subscribe_event, 978 + .vidioc_unsubscribe_event = v4l2_event_unsubscribe 979 + }; 980 + 981 + static int jpu_controls_create(struct jpu_ctx *ctx) 982 + { 983 + struct v4l2_ctrl *ctrl; 984 + int ret; 985 + 986 + v4l2_ctrl_handler_init(&ctx->ctrl_handler, 1); 987 + 988 + ctrl = v4l2_ctrl_new_std(&ctx->ctrl_handler, &jpu_ctrl_ops, 989 + V4L2_CID_JPEG_COMPRESSION_QUALITY, 990 + 0, JPU_MAX_QUALITY - 1, 1, 0); 991 + 992 + if (ctx->ctrl_handler.error) { 993 + ret = ctx->ctrl_handler.error; 994 + goto error_free; 995 + } 996 + 997 + if (!ctx->encoder) 998 + ctrl->flags |= V4L2_CTRL_FLAG_VOLATILE | 999 + V4L2_CTRL_FLAG_READ_ONLY; 1000 + 1001 + ret = v4l2_ctrl_handler_setup(&ctx->ctrl_handler); 1002 + if (ret < 0) 1003 + goto error_free; 1004 + 1005 + return 0; 1006 + 1007 + error_free: 1008 + v4l2_ctrl_handler_free(&ctx->ctrl_handler); 1009 + return ret; 1010 + } 1011 + 1012 + /* 1013 + * ============================================================================ 1014 + * Queue operations 1015 + * ============================================================================ 1016 + */ 1017 + static int jpu_queue_setup(struct vb2_queue *vq, 1018 + const struct v4l2_format *fmt, 1019 + unsigned int *nbuffers, unsigned int *nplanes, 1020 + unsigned int sizes[], void *alloc_ctxs[]) 1021 + { 1022 + struct jpu_ctx *ctx = vb2_get_drv_priv(vq); 1023 + struct jpu_q_data *q_data; 1024 + unsigned int i; 1025 + 1026 + q_data = jpu_get_q_data(ctx, vq->type); 1027 + 1028 + *nplanes = q_data->format.num_planes; 1029 + 1030 + for (i = 0; i < *nplanes; i++) { 1031 + unsigned int q_size = q_data->format.plane_fmt[i].sizeimage; 1032 + unsigned int f_size = fmt ? 1033 + fmt->fmt.pix_mp.plane_fmt[i].sizeimage : 0; 1034 + 1035 + if (fmt && f_size < q_size) 1036 + return -EINVAL; 1037 + 1038 + sizes[i] = fmt ? f_size : q_size; 1039 + alloc_ctxs[i] = ctx->jpu->alloc_ctx; 1040 + } 1041 + 1042 + return 0; 1043 + } 1044 + 1045 + static int jpu_buf_prepare(struct vb2_buffer *vb) 1046 + { 1047 + struct jpu_ctx *ctx = vb2_get_drv_priv(vb->vb2_queue); 1048 + struct jpu_q_data *q_data; 1049 + unsigned int i; 1050 + 1051 + q_data = jpu_get_q_data(ctx, vb->vb2_queue->type); 1052 + 1053 + if (V4L2_TYPE_IS_OUTPUT(vb->vb2_queue->type)) { 1054 + if (vb->v4l2_buf.field == V4L2_FIELD_ANY) 1055 + vb->v4l2_buf.field = V4L2_FIELD_NONE; 1056 + if (vb->v4l2_buf.field != V4L2_FIELD_NONE) { 1057 + dev_err(ctx->jpu->dev, "%s field isn't supported\n", 1058 + __func__); 1059 + return -EINVAL; 1060 + } 1061 + } 1062 + 1063 + for (i = 0; i < q_data->format.num_planes; i++) { 1064 + unsigned long size = q_data->format.plane_fmt[i].sizeimage; 1065 + 1066 + if (vb2_plane_size(vb, i) < size) { 1067 + dev_err(ctx->jpu->dev, 1068 + "%s: data will not fit into plane (%lu < %lu)\n", 1069 + __func__, vb2_plane_size(vb, i), size); 1070 + return -EINVAL; 1071 + } 1072 + 1073 + /* decoder capture queue */ 1074 + if (!ctx->encoder && !V4L2_TYPE_IS_OUTPUT(vb->vb2_queue->type)) 1075 + vb2_set_plane_payload(vb, i, size); 1076 + } 1077 + 1078 + return 0; 1079 + } 1080 + 1081 + static void jpu_buf_queue(struct vb2_buffer *vb) 1082 + { 1083 + struct jpu_ctx *ctx = vb2_get_drv_priv(vb->vb2_queue); 1084 + 1085 + if (!ctx->encoder && V4L2_TYPE_IS_OUTPUT(vb->vb2_queue->type)) { 1086 + struct jpu_buffer *jpu_buf = vb2_to_jpu_buffer(vb); 1087 + struct jpu_q_data *q_data, adjust; 1088 + void *buffer = vb2_plane_vaddr(vb, 0); 1089 + unsigned long buf_size = vb2_get_plane_payload(vb, 0); 1090 + unsigned int width, height; 1091 + 1092 + u8 subsampling = jpu_parse_hdr(buffer, buf_size, &width, 1093 + &height); 1094 + 1095 + /* check if JPEG data basic parsing was successful */ 1096 + if (subsampling != JPU_JPEG_422 && subsampling != JPU_JPEG_420) 1097 + goto format_error; 1098 + 1099 + q_data = &ctx->out_q; 1100 + 1101 + adjust = *q_data; 1102 + adjust.format.width = width; 1103 + adjust.format.height = height; 1104 + 1105 + __jpu_try_fmt(ctx, &adjust.fmtinfo, &adjust.format, 1106 + V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE); 1107 + 1108 + if (adjust.format.width != q_data->format.width || 1109 + adjust.format.height != q_data->format.height) 1110 + goto format_error; 1111 + 1112 + /* 1113 + * keep subsampling in buffer to check it 1114 + * for compatibility in device_run 1115 + */ 1116 + jpu_buf->subsampling = subsampling; 1117 + } 1118 + 1119 + if (ctx->fh.m2m_ctx) 1120 + v4l2_m2m_buf_queue(ctx->fh.m2m_ctx, vb); 1121 + 1122 + return; 1123 + 1124 + format_error: 1125 + dev_err(ctx->jpu->dev, "incompatible or corrupted JPEG data\n"); 1126 + vb2_buffer_done(vb, VB2_BUF_STATE_ERROR); 1127 + } 1128 + 1129 + static void jpu_buf_finish(struct vb2_buffer *vb) 1130 + { 1131 + struct jpu_buffer *jpu_buf = vb2_to_jpu_buffer(vb); 1132 + struct jpu_ctx *ctx = vb2_get_drv_priv(vb->vb2_queue); 1133 + struct jpu_q_data *q_data = &ctx->out_q; 1134 + enum v4l2_buf_type type = vb->vb2_queue->type; 1135 + u8 *buffer; 1136 + 1137 + if (vb->state == VB2_BUF_STATE_DONE) 1138 + vb->v4l2_buf.sequence = jpu_get_q_data(ctx, type)->sequence++; 1139 + 1140 + if (!ctx->encoder || vb->state != VB2_BUF_STATE_DONE || 1141 + V4L2_TYPE_IS_OUTPUT(type)) 1142 + return; 1143 + 1144 + buffer = vb2_plane_vaddr(vb, 0); 1145 + 1146 + memcpy(buffer, jpeg_hdrs[jpu_buf->compr_quality], JPU_JPEG_HDR_SIZE); 1147 + *(u16 *)(buffer + JPU_JPEG_HEIGHT_OFFSET) = 1148 + cpu_to_be16(q_data->format.height); 1149 + *(u16 *)(buffer + JPU_JPEG_WIDTH_OFFSET) = 1150 + cpu_to_be16(q_data->format.width); 1151 + *(buffer + JPU_JPEG_SUBS_OFFSET) = q_data->fmtinfo->subsampling; 1152 + } 1153 + 1154 + static int jpu_start_streaming(struct vb2_queue *vq, unsigned count) 1155 + { 1156 + struct jpu_ctx *ctx = vb2_get_drv_priv(vq); 1157 + struct jpu_q_data *q_data = jpu_get_q_data(ctx, vq->type); 1158 + 1159 + q_data->sequence = 0; 1160 + return 0; 1161 + } 1162 + 1163 + static void jpu_stop_streaming(struct vb2_queue *vq) 1164 + { 1165 + struct jpu_ctx *ctx = vb2_get_drv_priv(vq); 1166 + struct vb2_buffer *vb; 1167 + unsigned long flags; 1168 + 1169 + for (;;) { 1170 + if (V4L2_TYPE_IS_OUTPUT(vq->type)) 1171 + vb = v4l2_m2m_src_buf_remove(ctx->fh.m2m_ctx); 1172 + else 1173 + vb = v4l2_m2m_dst_buf_remove(ctx->fh.m2m_ctx); 1174 + if (vb == NULL) 1175 + return; 1176 + spin_lock_irqsave(&ctx->jpu->lock, flags); 1177 + v4l2_m2m_buf_done(vb, VB2_BUF_STATE_ERROR); 1178 + spin_unlock_irqrestore(&ctx->jpu->lock, flags); 1179 + } 1180 + } 1181 + 1182 + static struct vb2_ops jpu_qops = { 1183 + .queue_setup = jpu_queue_setup, 1184 + .buf_prepare = jpu_buf_prepare, 1185 + .buf_queue = jpu_buf_queue, 1186 + .buf_finish = jpu_buf_finish, 1187 + .start_streaming = jpu_start_streaming, 1188 + .stop_streaming = jpu_stop_streaming, 1189 + .wait_prepare = vb2_ops_wait_prepare, 1190 + .wait_finish = vb2_ops_wait_finish, 1191 + }; 1192 + 1193 + static int jpu_queue_init(void *priv, struct vb2_queue *src_vq, 1194 + struct vb2_queue *dst_vq) 1195 + { 1196 + struct jpu_ctx *ctx = priv; 1197 + int ret; 1198 + 1199 + memset(src_vq, 0, sizeof(*src_vq)); 1200 + src_vq->type = V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE; 1201 + src_vq->io_modes = VB2_MMAP | VB2_DMABUF; 1202 + src_vq->drv_priv = ctx; 1203 + src_vq->buf_struct_size = sizeof(struct jpu_buffer); 1204 + src_vq->ops = &jpu_qops; 1205 + src_vq->mem_ops = &vb2_dma_contig_memops; 1206 + src_vq->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_COPY; 1207 + src_vq->lock = &ctx->jpu->mutex; 1208 + 1209 + ret = vb2_queue_init(src_vq); 1210 + if (ret) 1211 + return ret; 1212 + 1213 + memset(dst_vq, 0, sizeof(*dst_vq)); 1214 + dst_vq->type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE; 1215 + dst_vq->io_modes = VB2_MMAP | VB2_DMABUF; 1216 + dst_vq->drv_priv = ctx; 1217 + dst_vq->buf_struct_size = sizeof(struct jpu_buffer); 1218 + dst_vq->ops = &jpu_qops; 1219 + dst_vq->mem_ops = &vb2_dma_contig_memops; 1220 + dst_vq->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_COPY; 1221 + dst_vq->lock = &ctx->jpu->mutex; 1222 + 1223 + return vb2_queue_init(dst_vq); 1224 + } 1225 + 1226 + /* 1227 + * ============================================================================ 1228 + * Device file operations 1229 + * ============================================================================ 1230 + */ 1231 + static int jpu_open(struct file *file) 1232 + { 1233 + struct jpu *jpu = video_drvdata(file); 1234 + struct video_device *vfd = video_devdata(file); 1235 + struct jpu_ctx *ctx; 1236 + int ret; 1237 + 1238 + ctx = kzalloc(sizeof(*ctx), GFP_KERNEL); 1239 + if (!ctx) 1240 + return -ENOMEM; 1241 + 1242 + v4l2_fh_init(&ctx->fh, vfd); 1243 + ctx->fh.ctrl_handler = &ctx->ctrl_handler; 1244 + file->private_data = &ctx->fh; 1245 + v4l2_fh_add(&ctx->fh); 1246 + 1247 + ctx->jpu = jpu; 1248 + ctx->encoder = vfd == &jpu->vfd_encoder; 1249 + 1250 + __jpu_try_fmt(ctx, &ctx->out_q.fmtinfo, &ctx->out_q.format, 1251 + V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE); 1252 + __jpu_try_fmt(ctx, &ctx->cap_q.fmtinfo, &ctx->cap_q.format, 1253 + V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE); 1254 + 1255 + ctx->fh.m2m_ctx = v4l2_m2m_ctx_init(jpu->m2m_dev, ctx, jpu_queue_init); 1256 + if (IS_ERR(ctx->fh.m2m_ctx)) { 1257 + ret = PTR_ERR(ctx->fh.m2m_ctx); 1258 + goto v4l_prepare_rollback; 1259 + } 1260 + 1261 + ret = jpu_controls_create(ctx); 1262 + if (ret < 0) 1263 + goto v4l_prepare_rollback; 1264 + 1265 + if (mutex_lock_interruptible(&jpu->mutex)) { 1266 + ret = -ERESTARTSYS; 1267 + goto v4l_prepare_rollback; 1268 + } 1269 + 1270 + if (jpu->ref_count == 0) { 1271 + ret = clk_prepare_enable(jpu->clk); 1272 + if (ret < 0) 1273 + goto device_prepare_rollback; 1274 + /* ...issue software reset */ 1275 + ret = jpu_reset(jpu); 1276 + if (ret) 1277 + goto device_prepare_rollback; 1278 + } 1279 + 1280 + jpu->ref_count++; 1281 + 1282 + mutex_unlock(&jpu->mutex); 1283 + return 0; 1284 + 1285 + device_prepare_rollback: 1286 + mutex_unlock(&jpu->mutex); 1287 + v4l_prepare_rollback: 1288 + v4l2_fh_del(&ctx->fh); 1289 + v4l2_fh_exit(&ctx->fh); 1290 + kfree(ctx); 1291 + return ret; 1292 + } 1293 + 1294 + static int jpu_release(struct file *file) 1295 + { 1296 + struct jpu *jpu = video_drvdata(file); 1297 + struct jpu_ctx *ctx = fh_to_ctx(file->private_data); 1298 + 1299 + mutex_lock(&jpu->mutex); 1300 + if (--jpu->ref_count == 0) 1301 + clk_disable_unprepare(jpu->clk); 1302 + mutex_unlock(&jpu->mutex); 1303 + 1304 + v4l2_m2m_ctx_release(ctx->fh.m2m_ctx); 1305 + v4l2_ctrl_handler_free(&ctx->ctrl_handler); 1306 + v4l2_fh_del(&ctx->fh); 1307 + v4l2_fh_exit(&ctx->fh); 1308 + kfree(ctx); 1309 + 1310 + return 0; 1311 + } 1312 + 1313 + static const struct v4l2_file_operations jpu_fops = { 1314 + .owner = THIS_MODULE, 1315 + .open = jpu_open, 1316 + .release = jpu_release, 1317 + .unlocked_ioctl = video_ioctl2, 1318 + .poll = v4l2_m2m_fop_poll, 1319 + .mmap = v4l2_m2m_fop_mmap, 1320 + }; 1321 + 1322 + /* 1323 + * ============================================================================ 1324 + * mem2mem callbacks 1325 + * ============================================================================ 1326 + */ 1327 + static void jpu_cleanup(struct jpu_ctx *ctx, bool reset) 1328 + { 1329 + /* remove current buffers and finish job */ 1330 + struct vb2_buffer *src_buf, *dst_buf; 1331 + unsigned long flags; 1332 + 1333 + spin_lock_irqsave(&ctx->jpu->lock, flags); 1334 + 1335 + src_buf = v4l2_m2m_src_buf_remove(ctx->fh.m2m_ctx); 1336 + dst_buf = v4l2_m2m_dst_buf_remove(ctx->fh.m2m_ctx); 1337 + 1338 + v4l2_m2m_buf_done(src_buf, VB2_BUF_STATE_ERROR); 1339 + v4l2_m2m_buf_done(dst_buf, VB2_BUF_STATE_ERROR); 1340 + 1341 + /* ...and give it a chance on next run */ 1342 + if (reset) 1343 + jpu_write(ctx->jpu, JCCMD_SRST, JCCMD); 1344 + 1345 + spin_unlock_irqrestore(&ctx->jpu->lock, flags); 1346 + 1347 + v4l2_m2m_job_finish(ctx->jpu->m2m_dev, ctx->fh.m2m_ctx); 1348 + } 1349 + 1350 + static void jpu_device_run(void *priv) 1351 + { 1352 + struct jpu_ctx *ctx = priv; 1353 + struct jpu *jpu = ctx->jpu; 1354 + struct jpu_buffer *jpu_buf; 1355 + struct jpu_q_data *q_data; 1356 + struct vb2_buffer *src_buf, *dst_buf; 1357 + unsigned int w, h, bpl; 1358 + unsigned char num_planes, subsampling; 1359 + unsigned long flags; 1360 + 1361 + /* ...wait until module reset completes; we have mutex locked here */ 1362 + if (jpu_wait_reset(jpu)) { 1363 + jpu_cleanup(ctx, true); 1364 + return; 1365 + } 1366 + 1367 + spin_lock_irqsave(&ctx->jpu->lock, flags); 1368 + 1369 + jpu->curr = ctx; 1370 + 1371 + src_buf = v4l2_m2m_next_src_buf(ctx->fh.m2m_ctx); 1372 + dst_buf = v4l2_m2m_next_dst_buf(ctx->fh.m2m_ctx); 1373 + 1374 + if (ctx->encoder) { 1375 + jpu_buf = vb2_to_jpu_buffer(dst_buf); 1376 + q_data = &ctx->out_q; 1377 + } else { 1378 + jpu_buf = vb2_to_jpu_buffer(src_buf); 1379 + q_data = &ctx->cap_q; 1380 + } 1381 + 1382 + w = q_data->format.width; 1383 + h = q_data->format.height; 1384 + bpl = q_data->format.plane_fmt[0].bytesperline; 1385 + num_planes = q_data->fmtinfo->num_planes; 1386 + subsampling = q_data->fmtinfo->subsampling; 1387 + 1388 + if (ctx->encoder) { 1389 + unsigned long src_1_addr, src_2_addr, dst_addr; 1390 + unsigned int redu, inft; 1391 + 1392 + dst_addr = vb2_dma_contig_plane_dma_addr(dst_buf, 0); 1393 + src_1_addr = vb2_dma_contig_plane_dma_addr(src_buf, 0); 1394 + if (num_planes > 1) 1395 + src_2_addr = vb2_dma_contig_plane_dma_addr(src_buf, 1); 1396 + else 1397 + src_2_addr = src_1_addr + w * h; 1398 + 1399 + jpu_buf->compr_quality = ctx->compr_quality; 1400 + 1401 + if (subsampling == JPU_JPEG_420) { 1402 + redu = JCMOD_REDU_420; 1403 + inft = JIFECNT_INFT_420; 1404 + } else { 1405 + redu = JCMOD_REDU_422; 1406 + inft = JIFECNT_INFT_422; 1407 + } 1408 + 1409 + /* only no marker mode works for encoding */ 1410 + jpu_write(jpu, JCMOD_DSP_ENC | JCMOD_PCTR | redu | 1411 + JCMOD_MSKIP_ENABLE, JCMOD); 1412 + 1413 + jpu_write(jpu, JIFECNT_SWAP_WB | inft, JIFECNT); 1414 + jpu_write(jpu, JIFDCNT_SWAP_WB, JIFDCNT); 1415 + jpu_write(jpu, JINTE_TRANSF_COMPL, JINTE); 1416 + 1417 + /* Y and C components source addresses */ 1418 + jpu_write(jpu, src_1_addr, JIFESYA1); 1419 + jpu_write(jpu, src_2_addr, JIFESCA1); 1420 + 1421 + /* memory width */ 1422 + jpu_write(jpu, bpl, JIFESMW); 1423 + 1424 + jpu_write(jpu, (w >> 8) & JCSZ_MASK, JCHSZU); 1425 + jpu_write(jpu, w & JCSZ_MASK, JCHSZD); 1426 + 1427 + jpu_write(jpu, (h >> 8) & JCSZ_MASK, JCVSZU); 1428 + jpu_write(jpu, h & JCSZ_MASK, JCVSZD); 1429 + 1430 + jpu_write(jpu, w, JIFESHSZ); 1431 + jpu_write(jpu, h, JIFESVSZ); 1432 + 1433 + jpu_write(jpu, dst_addr + JPU_JPEG_HDR_SIZE, JIFEDA1); 1434 + 1435 + jpu_write(jpu, 0 << JCQTN_SHIFT(1) | 1 << JCQTN_SHIFT(2) | 1436 + 1 << JCQTN_SHIFT(3), JCQTN); 1437 + 1438 + jpu_write(jpu, 0 << JCHTN_AC_SHIFT(1) | 0 << JCHTN_DC_SHIFT(1) | 1439 + 1 << JCHTN_AC_SHIFT(2) | 1 << JCHTN_DC_SHIFT(2) | 1440 + 1 << JCHTN_AC_SHIFT(3) | 1 << JCHTN_DC_SHIFT(3), 1441 + JCHTN); 1442 + 1443 + jpu_set_qtbl(jpu, ctx->compr_quality); 1444 + jpu_set_htbl(jpu); 1445 + } else { 1446 + unsigned long src_addr, dst_1_addr, dst_2_addr; 1447 + 1448 + if (jpu_buf->subsampling != subsampling) { 1449 + dev_err(ctx->jpu->dev, 1450 + "src and dst formats do not match.\n"); 1451 + spin_unlock_irqrestore(&ctx->jpu->lock, flags); 1452 + jpu_cleanup(ctx, false); 1453 + return; 1454 + } 1455 + 1456 + src_addr = vb2_dma_contig_plane_dma_addr(src_buf, 0); 1457 + dst_1_addr = vb2_dma_contig_plane_dma_addr(dst_buf, 0); 1458 + if (q_data->fmtinfo->num_planes > 1) 1459 + dst_2_addr = vb2_dma_contig_plane_dma_addr(dst_buf, 1); 1460 + else 1461 + dst_2_addr = dst_1_addr + w * h; 1462 + 1463 + /* ...set up decoder operation */ 1464 + jpu_write(jpu, JCMOD_DSP_DEC | JCMOD_PCTR, JCMOD); 1465 + jpu_write(jpu, JIFECNT_SWAP_WB, JIFECNT); 1466 + jpu_write(jpu, JIFDCNT_SWAP_WB, JIFDCNT); 1467 + 1468 + /* ...enable interrupts on transfer completion and d-g error */ 1469 + jpu_write(jpu, JINTE_TRANSF_COMPL | JINTE_ERR, JINTE); 1470 + 1471 + /* ...set source/destination addresses of encoded data */ 1472 + jpu_write(jpu, src_addr, JIFDSA1); 1473 + jpu_write(jpu, dst_1_addr, JIFDDYA1); 1474 + jpu_write(jpu, dst_2_addr, JIFDDCA1); 1475 + 1476 + jpu_write(jpu, bpl, JIFDDMW); 1477 + } 1478 + 1479 + /* ...start encoder/decoder operation */ 1480 + jpu_write(jpu, JCCMD_JSRT, JCCMD); 1481 + 1482 + spin_unlock_irqrestore(&ctx->jpu->lock, flags); 1483 + } 1484 + 1485 + static int jpu_job_ready(void *priv) 1486 + { 1487 + return 1; 1488 + } 1489 + 1490 + static void jpu_job_abort(void *priv) 1491 + { 1492 + struct jpu_ctx *ctx = priv; 1493 + 1494 + if (!wait_event_timeout(ctx->jpu->irq_queue, !ctx->jpu->curr, 1495 + msecs_to_jiffies(JPU_JOB_TIMEOUT))) 1496 + jpu_cleanup(ctx, true); 1497 + } 1498 + 1499 + static struct v4l2_m2m_ops jpu_m2m_ops = { 1500 + .device_run = jpu_device_run, 1501 + .job_ready = jpu_job_ready, 1502 + .job_abort = jpu_job_abort, 1503 + }; 1504 + 1505 + /* 1506 + * ============================================================================ 1507 + * IRQ handler 1508 + * ============================================================================ 1509 + */ 1510 + static irqreturn_t jpu_irq_handler(int irq, void *dev_id) 1511 + { 1512 + struct jpu *jpu = dev_id; 1513 + struct jpu_ctx *curr_ctx; 1514 + struct vb2_buffer *src_buf, *dst_buf; 1515 + unsigned int int_status; 1516 + 1517 + int_status = jpu_read(jpu, JINTS); 1518 + 1519 + /* ...spurious interrupt */ 1520 + if (!((JINTS_TRANSF_COMPL | JINTS_PROCESS_COMPL | JINTS_ERR) & 1521 + int_status)) 1522 + return IRQ_NONE; 1523 + 1524 + /* ...clear interrupts */ 1525 + jpu_write(jpu, ~(int_status & JINTS_MASK), JINTS); 1526 + if (int_status & (JINTS_ERR | JINTS_PROCESS_COMPL)) 1527 + jpu_write(jpu, JCCMD_JEND, JCCMD); 1528 + 1529 + spin_lock(&jpu->lock); 1530 + 1531 + if ((int_status & JINTS_PROCESS_COMPL) && 1532 + !(int_status & JINTS_TRANSF_COMPL)) 1533 + goto handled; 1534 + 1535 + curr_ctx = v4l2_m2m_get_curr_priv(jpu->m2m_dev); 1536 + if (!curr_ctx) { 1537 + /* ...instance is not running */ 1538 + dev_err(jpu->dev, "no active context for m2m\n"); 1539 + goto handled; 1540 + } 1541 + 1542 + src_buf = v4l2_m2m_src_buf_remove(curr_ctx->fh.m2m_ctx); 1543 + dst_buf = v4l2_m2m_dst_buf_remove(curr_ctx->fh.m2m_ctx); 1544 + 1545 + if (int_status & JINTS_TRANSF_COMPL) { 1546 + if (curr_ctx->encoder) { 1547 + unsigned long payload_size = jpu_read(jpu, JCDTCU) << 16 1548 + | jpu_read(jpu, JCDTCM) << 8 1549 + | jpu_read(jpu, JCDTCD); 1550 + vb2_set_plane_payload(dst_buf, 0, 1551 + payload_size + JPU_JPEG_HDR_SIZE); 1552 + } 1553 + 1554 + dst_buf->v4l2_buf.field = src_buf->v4l2_buf.field; 1555 + dst_buf->v4l2_buf.timestamp = src_buf->v4l2_buf.timestamp; 1556 + if (src_buf->v4l2_buf.flags & V4L2_BUF_FLAG_TIMECODE) 1557 + dst_buf->v4l2_buf.timecode = src_buf->v4l2_buf.timecode; 1558 + dst_buf->v4l2_buf.flags &= ~V4L2_BUF_FLAG_TSTAMP_SRC_MASK; 1559 + dst_buf->v4l2_buf.flags |= src_buf->v4l2_buf.flags & 1560 + V4L2_BUF_FLAG_TSTAMP_SRC_MASK; 1561 + dst_buf->v4l2_buf.flags = src_buf->v4l2_buf.flags & 1562 + (V4L2_BUF_FLAG_TIMECODE | V4L2_BUF_FLAG_KEYFRAME | 1563 + V4L2_BUF_FLAG_PFRAME | V4L2_BUF_FLAG_BFRAME | 1564 + V4L2_BUF_FLAG_TSTAMP_SRC_MASK); 1565 + 1566 + v4l2_m2m_buf_done(src_buf, VB2_BUF_STATE_DONE); 1567 + v4l2_m2m_buf_done(dst_buf, VB2_BUF_STATE_DONE); 1568 + } else if (int_status & JINTS_ERR) { 1569 + unsigned char error = jpu_read(jpu, JCDERR) & JCDERR_MASK; 1570 + 1571 + dev_dbg(jpu->dev, "processing error: %#X: %s\n", error, 1572 + error_to_text[error]); 1573 + 1574 + v4l2_m2m_buf_done(src_buf, VB2_BUF_STATE_ERROR); 1575 + v4l2_m2m_buf_done(dst_buf, VB2_BUF_STATE_ERROR); 1576 + } 1577 + 1578 + jpu->curr = NULL; 1579 + 1580 + /* ...reset JPU after completion */ 1581 + jpu_write(jpu, JCCMD_SRST, JCCMD); 1582 + spin_unlock(&jpu->lock); 1583 + 1584 + v4l2_m2m_job_finish(jpu->m2m_dev, curr_ctx->fh.m2m_ctx); 1585 + 1586 + /* ...wakeup abort routine if needed */ 1587 + wake_up(&jpu->irq_queue); 1588 + 1589 + return IRQ_HANDLED; 1590 + 1591 + handled: 1592 + spin_unlock(&jpu->lock); 1593 + return IRQ_HANDLED; 1594 + } 1595 + 1596 + /* 1597 + * ============================================================================ 1598 + * Driver basic infrastructure 1599 + * ============================================================================ 1600 + */ 1601 + static const struct of_device_id jpu_dt_ids[] = { 1602 + { .compatible = "renesas,jpu-r8a7790" }, /* H2 */ 1603 + { .compatible = "renesas,jpu-r8a7791" }, /* M2-W */ 1604 + { .compatible = "renesas,jpu-r8a7792" }, /* V2H */ 1605 + { .compatible = "renesas,jpu-r8a7793" }, /* M2-N */ 1606 + { }, 1607 + }; 1608 + MODULE_DEVICE_TABLE(of, jpu_dt_ids); 1609 + 1610 + static int jpu_probe(struct platform_device *pdev) 1611 + { 1612 + struct jpu *jpu; 1613 + struct resource *res; 1614 + int ret; 1615 + unsigned int i; 1616 + 1617 + jpu = devm_kzalloc(&pdev->dev, sizeof(*jpu), GFP_KERNEL); 1618 + if (!jpu) 1619 + return -ENOMEM; 1620 + 1621 + init_waitqueue_head(&jpu->irq_queue); 1622 + mutex_init(&jpu->mutex); 1623 + spin_lock_init(&jpu->lock); 1624 + jpu->dev = &pdev->dev; 1625 + 1626 + /* memory-mapped registers */ 1627 + res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 1628 + jpu->regs = devm_ioremap_resource(&pdev->dev, res); 1629 + if (IS_ERR(jpu->regs)) 1630 + return PTR_ERR(jpu->regs); 1631 + 1632 + /* interrupt service routine registration */ 1633 + jpu->irq = ret = platform_get_irq(pdev, 0); 1634 + if (ret < 0) { 1635 + dev_err(&pdev->dev, "cannot find IRQ\n"); 1636 + return ret; 1637 + } 1638 + 1639 + ret = devm_request_irq(&pdev->dev, jpu->irq, jpu_irq_handler, 0, 1640 + dev_name(&pdev->dev), jpu); 1641 + if (ret) { 1642 + dev_err(&pdev->dev, "cannot claim IRQ %d\n", jpu->irq); 1643 + return ret; 1644 + } 1645 + 1646 + /* clocks */ 1647 + jpu->clk = devm_clk_get(&pdev->dev, NULL); 1648 + if (IS_ERR(jpu->clk)) { 1649 + dev_err(&pdev->dev, "cannot get clock\n"); 1650 + return PTR_ERR(jpu->clk); 1651 + } 1652 + 1653 + /* v4l2 device */ 1654 + ret = v4l2_device_register(&pdev->dev, &jpu->v4l2_dev); 1655 + if (ret) { 1656 + dev_err(&pdev->dev, "Failed to register v4l2 device\n"); 1657 + return ret; 1658 + } 1659 + 1660 + /* mem2mem device */ 1661 + jpu->m2m_dev = v4l2_m2m_init(&jpu_m2m_ops); 1662 + if (IS_ERR(jpu->m2m_dev)) { 1663 + v4l2_err(&jpu->v4l2_dev, "Failed to init mem2mem device\n"); 1664 + ret = PTR_ERR(jpu->m2m_dev); 1665 + goto device_register_rollback; 1666 + } 1667 + 1668 + jpu->alloc_ctx = vb2_dma_contig_init_ctx(&pdev->dev); 1669 + if (IS_ERR(jpu->alloc_ctx)) { 1670 + v4l2_err(&jpu->v4l2_dev, "Failed to init memory allocator\n"); 1671 + ret = PTR_ERR(jpu->alloc_ctx); 1672 + goto m2m_init_rollback; 1673 + } 1674 + 1675 + /* fill in qantization and Huffman tables for encoder */ 1676 + for (i = 0; i < JPU_MAX_QUALITY; i++) 1677 + jpu_generate_hdr(i, (unsigned char *)jpeg_hdrs[i]); 1678 + 1679 + strlcpy(jpu->vfd_encoder.name, DRV_NAME, sizeof(jpu->vfd_encoder.name)); 1680 + jpu->vfd_encoder.fops = &jpu_fops; 1681 + jpu->vfd_encoder.ioctl_ops = &jpu_ioctl_ops; 1682 + jpu->vfd_encoder.minor = -1; 1683 + jpu->vfd_encoder.release = video_device_release_empty; 1684 + jpu->vfd_encoder.lock = &jpu->mutex; 1685 + jpu->vfd_encoder.v4l2_dev = &jpu->v4l2_dev; 1686 + jpu->vfd_encoder.vfl_dir = VFL_DIR_M2M; 1687 + 1688 + ret = video_register_device(&jpu->vfd_encoder, VFL_TYPE_GRABBER, -1); 1689 + if (ret) { 1690 + v4l2_err(&jpu->v4l2_dev, "Failed to register video device\n"); 1691 + goto vb2_allocator_rollback; 1692 + } 1693 + 1694 + video_set_drvdata(&jpu->vfd_encoder, jpu); 1695 + 1696 + strlcpy(jpu->vfd_decoder.name, DRV_NAME, sizeof(jpu->vfd_decoder.name)); 1697 + jpu->vfd_decoder.fops = &jpu_fops; 1698 + jpu->vfd_decoder.ioctl_ops = &jpu_ioctl_ops; 1699 + jpu->vfd_decoder.minor = -1; 1700 + jpu->vfd_decoder.release = video_device_release_empty; 1701 + jpu->vfd_decoder.lock = &jpu->mutex; 1702 + jpu->vfd_decoder.v4l2_dev = &jpu->v4l2_dev; 1703 + jpu->vfd_decoder.vfl_dir = VFL_DIR_M2M; 1704 + 1705 + ret = video_register_device(&jpu->vfd_decoder, VFL_TYPE_GRABBER, -1); 1706 + if (ret) { 1707 + v4l2_err(&jpu->v4l2_dev, "Failed to register video device\n"); 1708 + goto enc_vdev_register_rollback; 1709 + } 1710 + 1711 + video_set_drvdata(&jpu->vfd_decoder, jpu); 1712 + platform_set_drvdata(pdev, jpu); 1713 + 1714 + v4l2_info(&jpu->v4l2_dev, "encoder device registered as /dev/video%d\n", 1715 + jpu->vfd_encoder.num); 1716 + v4l2_info(&jpu->v4l2_dev, "decoder device registered as /dev/video%d\n", 1717 + jpu->vfd_decoder.num); 1718 + 1719 + return 0; 1720 + 1721 + enc_vdev_register_rollback: 1722 + video_unregister_device(&jpu->vfd_encoder); 1723 + 1724 + vb2_allocator_rollback: 1725 + vb2_dma_contig_cleanup_ctx(jpu->alloc_ctx); 1726 + 1727 + m2m_init_rollback: 1728 + v4l2_m2m_release(jpu->m2m_dev); 1729 + 1730 + device_register_rollback: 1731 + v4l2_device_unregister(&jpu->v4l2_dev); 1732 + 1733 + return ret; 1734 + } 1735 + 1736 + static int jpu_remove(struct platform_device *pdev) 1737 + { 1738 + struct jpu *jpu = platform_get_drvdata(pdev); 1739 + 1740 + video_unregister_device(&jpu->vfd_decoder); 1741 + video_unregister_device(&jpu->vfd_encoder); 1742 + vb2_dma_contig_cleanup_ctx(jpu->alloc_ctx); 1743 + v4l2_m2m_release(jpu->m2m_dev); 1744 + v4l2_device_unregister(&jpu->v4l2_dev); 1745 + 1746 + return 0; 1747 + } 1748 + 1749 + #ifdef CONFIG_PM_SLEEP 1750 + static int jpu_suspend(struct device *dev) 1751 + { 1752 + struct jpu *jpu = dev_get_drvdata(dev); 1753 + 1754 + if (jpu->ref_count == 0) 1755 + return 0; 1756 + 1757 + clk_disable_unprepare(jpu->clk); 1758 + 1759 + return 0; 1760 + } 1761 + 1762 + static int jpu_resume(struct device *dev) 1763 + { 1764 + struct jpu *jpu = dev_get_drvdata(dev); 1765 + 1766 + if (jpu->ref_count == 0) 1767 + return 0; 1768 + 1769 + clk_prepare_enable(jpu->clk); 1770 + 1771 + return 0; 1772 + } 1773 + #endif 1774 + 1775 + static const struct dev_pm_ops jpu_pm_ops = { 1776 + SET_SYSTEM_SLEEP_PM_OPS(jpu_suspend, jpu_resume) 1777 + }; 1778 + 1779 + static struct platform_driver jpu_driver = { 1780 + .probe = jpu_probe, 1781 + .remove = jpu_remove, 1782 + .driver = { 1783 + .of_match_table = jpu_dt_ids, 1784 + .name = DRV_NAME, 1785 + .pm = &jpu_pm_ops, 1786 + }, 1787 + }; 1788 + 1789 + module_platform_driver(jpu_driver); 1790 + 1791 + MODULE_ALIAS("platform:" DRV_NAME); 1792 + MODULE_AUTHOR("Mikhail Ulianov <mikhail.ulyanov@cogentembedded.com>"); 1793 + MODULE_DESCRIPTION("Renesas R-Car JPEG processing unit driver"); 1794 + MODULE_LICENSE("GPL v2");
+4 -10
drivers/media/platform/s5p-jpeg/jpeg-core.c
··· 2544 2544 ret = video_register_device(jpeg->vfd_encoder, VFL_TYPE_GRABBER, -1); 2545 2545 if (ret) { 2546 2546 v4l2_err(&jpeg->v4l2_dev, "Failed to register video device\n"); 2547 - goto enc_vdev_alloc_rollback; 2547 + video_device_release(jpeg->vfd_encoder); 2548 + goto vb2_allocator_rollback; 2548 2549 } 2549 2550 2550 2551 video_set_drvdata(jpeg->vfd_encoder, jpeg); ··· 2573 2572 ret = video_register_device(jpeg->vfd_decoder, VFL_TYPE_GRABBER, -1); 2574 2573 if (ret) { 2575 2574 v4l2_err(&jpeg->v4l2_dev, "Failed to register video device\n"); 2576 - goto dec_vdev_alloc_rollback; 2575 + video_device_release(jpeg->vfd_decoder); 2576 + goto enc_vdev_register_rollback; 2577 2577 } 2578 2578 2579 2579 video_set_drvdata(jpeg->vfd_decoder, jpeg); ··· 2591 2589 2592 2590 return 0; 2593 2591 2594 - dec_vdev_alloc_rollback: 2595 - video_device_release(jpeg->vfd_decoder); 2596 - 2597 2592 enc_vdev_register_rollback: 2598 2593 video_unregister_device(jpeg->vfd_encoder); 2599 - 2600 - enc_vdev_alloc_rollback: 2601 - video_device_release(jpeg->vfd_encoder); 2602 2594 2603 2595 vb2_allocator_rollback: 2604 2596 vb2_dma_contig_cleanup_ctx(jpeg->alloc_ctx); ··· 2618 2622 pm_runtime_disable(jpeg->dev); 2619 2623 2620 2624 video_unregister_device(jpeg->vfd_decoder); 2621 - video_device_release(jpeg->vfd_decoder); 2622 2625 video_unregister_device(jpeg->vfd_encoder); 2623 - video_device_release(jpeg->vfd_encoder); 2624 2626 vb2_dma_contig_cleanup_ctx(jpeg->alloc_ctx); 2625 2627 v4l2_m2m_release(jpeg->m2m_dev); 2626 2628 v4l2_device_unregister(&jpeg->v4l2_dev);
+5 -1
drivers/media/platform/s5p-mfc/s5p_mfc_cmd_v6.c
··· 37 37 { 38 38 struct s5p_mfc_cmd_args h2r_args; 39 39 struct s5p_mfc_buf_size_v6 *buf_size = dev->variant->buf_size->priv; 40 + int ret; 40 41 41 - s5p_mfc_hw_call(dev->mfc_ops, alloc_dev_context_buffer, dev); 42 + ret = s5p_mfc_hw_call(dev->mfc_ops, alloc_dev_context_buffer, dev); 43 + if (ret) 44 + return ret; 45 + 42 46 mfc_write(dev, dev->ctx_buf.dma, S5P_FIMV_CONTEXT_MEM_ADDR_V6); 43 47 mfc_write(dev, buf_size->dev_ctx, S5P_FIMV_CONTEXT_MEM_SIZE_V6); 44 48 return s5p_mfc_cmd_host2risc_v6(dev, S5P_FIMV_H2R_CMD_SYS_INIT_V6,
+5 -4
drivers/media/platform/s5p-mfc/s5p_mfc_enc.c
··· 1819 1819 struct s5p_mfc_ctx *ctx = fh_to_ctx(vq->drv_priv); 1820 1820 struct s5p_mfc_dev *dev = ctx->dev; 1821 1821 1822 - if (ctx->state != MFCINST_GOT_INST) { 1823 - mfc_err("inavlid state: %d\n", ctx->state); 1824 - return -EINVAL; 1825 - } 1826 1822 if (vq->type == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE) { 1823 + if (ctx->state != MFCINST_GOT_INST) { 1824 + mfc_err("inavlid state: %d\n", ctx->state); 1825 + return -EINVAL; 1826 + } 1827 + 1827 1828 if (ctx->dst_fmt) 1828 1829 *plane_count = ctx->dst_fmt->num_planes; 1829 1830 else
+9 -2
drivers/media/platform/s5p-mfc/s5p_mfc_opr.c
··· 37 37 dev->mfc_regs = s5p_mfc_init_regs_v6_plus(dev); 38 38 } 39 39 40 - int s5p_mfc_alloc_priv_buf(struct device *dev, 40 + int s5p_mfc_alloc_priv_buf(struct device *dev, dma_addr_t base, 41 41 struct s5p_mfc_priv_buf *b) 42 42 { 43 - 44 43 mfc_debug(3, "Allocating priv: %zu\n", b->size); 45 44 46 45 b->virt = dma_alloc_coherent(dev, b->size, &b->dma, GFP_KERNEL); 47 46 48 47 if (!b->virt) { 49 48 mfc_err("Allocating private buffer failed\n"); 49 + return -ENOMEM; 50 + } 51 + 52 + if (b->dma < base) { 53 + mfc_err("Invaling memory configuration!\n"); 54 + mfc_err("Allocated buffer (%pad) is lower than memory base address (%pad)\n", 55 + &b->dma, &base); 56 + dma_free_coherent(dev, b->size, b->virt, b->dma); 50 57 return -ENOMEM; 51 58 } 52 59
+1 -1
drivers/media/platform/s5p-mfc/s5p_mfc_opr.h
··· 334 334 335 335 void s5p_mfc_init_hw_ops(struct s5p_mfc_dev *dev); 336 336 void s5p_mfc_init_regs(struct s5p_mfc_dev *dev); 337 - int s5p_mfc_alloc_priv_buf(struct device *dev, 337 + int s5p_mfc_alloc_priv_buf(struct device *dev, dma_addr_t base, 338 338 struct s5p_mfc_priv_buf *b); 339 339 void s5p_mfc_release_priv_buf(struct device *dev, 340 340 struct s5p_mfc_priv_buf *b);
+7 -5
drivers/media/platform/s5p-mfc/s5p_mfc_opr_v5.c
··· 41 41 int ret; 42 42 43 43 ctx->dsc.size = buf_size->dsc; 44 - ret = s5p_mfc_alloc_priv_buf(dev->mem_dev_l, &ctx->dsc); 44 + ret = s5p_mfc_alloc_priv_buf(dev->mem_dev_l, dev->bank1, &ctx->dsc); 45 45 if (ret) { 46 46 mfc_err("Failed to allocate temporary buffer\n"); 47 47 return ret; ··· 172 172 /* Allocate only if memory from bank 1 is necessary */ 173 173 if (ctx->bank1.size > 0) { 174 174 175 - ret = s5p_mfc_alloc_priv_buf(dev->mem_dev_l, &ctx->bank1); 175 + ret = s5p_mfc_alloc_priv_buf(dev->mem_dev_l, dev->bank1, 176 + &ctx->bank1); 176 177 if (ret) { 177 178 mfc_err("Failed to allocate Bank1 temporary buffer\n"); 178 179 return ret; ··· 182 181 } 183 182 /* Allocate only if memory from bank 2 is necessary */ 184 183 if (ctx->bank2.size > 0) { 185 - ret = s5p_mfc_alloc_priv_buf(dev->mem_dev_r, &ctx->bank2); 184 + ret = s5p_mfc_alloc_priv_buf(dev->mem_dev_r, dev->bank2, 185 + &ctx->bank2); 186 186 if (ret) { 187 187 mfc_err("Failed to allocate Bank2 temporary buffer\n"); 188 188 s5p_mfc_release_priv_buf(ctx->dev->mem_dev_l, &ctx->bank1); ··· 214 212 else 215 213 ctx->ctx.size = buf_size->non_h264_ctx; 216 214 217 - ret = s5p_mfc_alloc_priv_buf(dev->mem_dev_l, &ctx->ctx); 215 + ret = s5p_mfc_alloc_priv_buf(dev->mem_dev_l, dev->bank1, &ctx->ctx); 218 216 if (ret) { 219 217 mfc_err("Failed to allocate instance buffer\n"); 220 218 return ret; ··· 227 225 228 226 /* Initialize shared memory */ 229 227 ctx->shm.size = buf_size->shm; 230 - ret = s5p_mfc_alloc_priv_buf(dev->mem_dev_l, &ctx->shm); 228 + ret = s5p_mfc_alloc_priv_buf(dev->mem_dev_l, dev->bank1, &ctx->shm); 231 229 if (ret) { 232 230 mfc_err("Failed to allocate shared memory buffer\n"); 233 231 s5p_mfc_release_priv_buf(dev->mem_dev_l, &ctx->ctx);
+5 -3
drivers/media/platform/s5p-mfc/s5p_mfc_opr_v6.c
··· 239 239 240 240 /* Allocate only if memory from bank 1 is necessary */ 241 241 if (ctx->bank1.size > 0) { 242 - ret = s5p_mfc_alloc_priv_buf(dev->mem_dev_l, &ctx->bank1); 242 + ret = s5p_mfc_alloc_priv_buf(dev->mem_dev_l, dev->bank1, 243 + &ctx->bank1); 243 244 if (ret) { 244 245 mfc_err("Failed to allocate Bank1 memory\n"); 245 246 return ret; ··· 292 291 break; 293 292 } 294 293 295 - ret = s5p_mfc_alloc_priv_buf(dev->mem_dev_l, &ctx->ctx); 294 + ret = s5p_mfc_alloc_priv_buf(dev->mem_dev_l, dev->bank1, &ctx->ctx); 296 295 if (ret) { 297 296 mfc_err("Failed to allocate instance buffer\n"); 298 297 return ret; ··· 321 320 mfc_debug_enter(); 322 321 323 322 dev->ctx_buf.size = buf_size->dev_ctx; 324 - ret = s5p_mfc_alloc_priv_buf(dev->mem_dev_l, &dev->ctx_buf); 323 + ret = s5p_mfc_alloc_priv_buf(dev->mem_dev_l, dev->bank1, 324 + &dev->ctx_buf); 325 325 if (ret) { 326 326 mfc_err("Failed to allocate device context buffer\n"); 327 327 return ret;
-1
drivers/media/platform/s5p-tv/hdmiphy_drv.c
··· 315 315 static struct i2c_driver hdmiphy_driver = { 316 316 .driver = { 317 317 .name = "s5p-hdmiphy", 318 - .owner = THIS_MODULE, 319 318 }, 320 319 .probe = hdmiphy_probe, 321 320 .remove = hdmiphy_remove,
+5 -7
drivers/media/platform/s5p-tv/mixer_reg.c
··· 357 357 358 358 int mxr_reg_wait4vsync(struct mxr_device *mdev) 359 359 { 360 - int ret; 360 + long time_left; 361 361 362 362 clear_bit(MXR_EVENT_VSYNC, &mdev->event_flags); 363 363 /* TODO: consider adding interruptible */ 364 - ret = wait_event_timeout(mdev->event_queue, 365 - test_bit(MXR_EVENT_VSYNC, &mdev->event_flags), 366 - msecs_to_jiffies(1000)); 367 - if (ret > 0) 364 + time_left = wait_event_timeout(mdev->event_queue, 365 + test_bit(MXR_EVENT_VSYNC, &mdev->event_flags), 366 + msecs_to_jiffies(1000)); 367 + if (time_left > 0) 368 368 return 0; 369 - if (ret < 0) 370 - return ret; 371 369 mxr_warn(mdev, "no vsync detected - timeout\n"); 372 370 return -ETIME; 373 371 }
-1
drivers/media/platform/s5p-tv/sii9234_drv.c
··· 397 397 static struct i2c_driver sii9234_driver = { 398 398 .driver = { 399 399 .name = "sii9234", 400 - .owner = THIS_MODULE, 401 400 .pm = &sii9234_pm_ops, 402 401 }, 403 402 .probe = sii9234_probe,
+9 -1
drivers/media/platform/sh_veu.c
··· 211 211 case V4L2_PIX_FMT_NV12: 212 212 case V4L2_PIX_FMT_NV16: 213 213 case V4L2_PIX_FMT_NV24: 214 - return V4L2_COLORSPACE_JPEG; 214 + return V4L2_COLORSPACE_SMPTE170M; 215 215 case V4L2_PIX_FMT_RGB332: 216 216 case V4L2_PIX_FMT_RGB444: 217 217 case V4L2_PIX_FMT_RGB565: ··· 958 958 src_vq->ops = &sh_veu_qops; 959 959 src_vq->mem_ops = &vb2_dma_contig_memops; 960 960 src_vq->lock = &veu->fop_lock; 961 + src_vq->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_COPY; 961 962 962 963 ret = vb2_queue_init(src_vq); 963 964 if (ret < 0) ··· 972 971 dst_vq->ops = &sh_veu_qops; 973 972 dst_vq->mem_ops = &vb2_dma_contig_memops; 974 973 dst_vq->lock = &veu->fop_lock; 974 + dst_vq->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_COPY; 975 975 976 976 return vb2_queue_init(dst_vq); 977 977 } ··· 1104 1102 src = v4l2_m2m_src_buf_remove(veu->m2m_ctx); 1105 1103 if (!src || !dst) 1106 1104 return IRQ_NONE; 1105 + 1106 + dst->v4l2_buf.timestamp = src->v4l2_buf.timestamp; 1107 + dst->v4l2_buf.flags &= ~V4L2_BUF_FLAG_TSTAMP_SRC_MASK; 1108 + dst->v4l2_buf.flags |= 1109 + src->v4l2_buf.flags & V4L2_BUF_FLAG_TSTAMP_SRC_MASK; 1110 + dst->v4l2_buf.timecode = src->v4l2_buf.timecode; 1107 1111 1108 1112 spin_lock(&veu->lock); 1109 1113 v4l2_m2m_buf_done(src, VB2_BUF_STATE_DONE);
+390 -465
drivers/media/platform/sh_vou.c
··· 27 27 #include <media/v4l2-device.h> 28 28 #include <media/v4l2-ioctl.h> 29 29 #include <media/v4l2-mediabus.h> 30 - #include <media/videobuf-dma-contig.h> 30 + #include <media/videobuf2-dma-contig.h> 31 31 32 32 /* Mirror addresses are not available for all registers */ 33 33 #define VOUER 0 ··· 57 57 SH_VOU_RUNNING, 58 58 }; 59 59 60 + #define VOU_MIN_IMAGE_WIDTH 16 60 61 #define VOU_MAX_IMAGE_WIDTH 720 61 - #define VOU_MAX_IMAGE_HEIGHT 576 62 + #define VOU_MIN_IMAGE_HEIGHT 16 63 + 64 + struct sh_vou_buffer { 65 + struct vb2_buffer vb; 66 + struct list_head list; 67 + }; 68 + 69 + static inline struct sh_vou_buffer *to_sh_vou_buffer(struct vb2_buffer *vb2) 70 + { 71 + return container_of(vb2, struct sh_vou_buffer, vb); 72 + } 62 73 63 74 struct sh_vou_device { 64 75 struct v4l2_device v4l2_dev; 65 76 struct video_device vdev; 66 - atomic_t use_count; 67 77 struct sh_vou_pdata *pdata; 68 78 spinlock_t lock; 69 79 void __iomem *base; 70 80 /* State information */ 71 81 struct v4l2_pix_format pix; 72 82 struct v4l2_rect rect; 73 - struct list_head queue; 83 + struct list_head buf_list; 74 84 v4l2_std_id std; 75 85 int pix_idx; 76 - struct videobuf_buffer *active; 86 + struct vb2_queue queue; 87 + struct vb2_alloc_ctx *alloc_ctx; 88 + struct sh_vou_buffer *active; 77 89 enum sh_vou_status status; 90 + unsigned sequence; 78 91 struct mutex fop_lock; 79 - }; 80 - 81 - struct sh_vou_file { 82 - struct videobuf_queue vbq; 83 92 }; 84 93 85 94 /* Register access routines for sides A, B and mirror addresses */ ··· 142 133 u32 pfmt; 143 134 char *desc; 144 135 unsigned char bpp; 136 + unsigned char bpl; 145 137 unsigned char rgb; 146 138 unsigned char yf; 147 139 unsigned char pkf; ··· 153 143 { 154 144 .pfmt = V4L2_PIX_FMT_NV12, 155 145 .bpp = 12, 146 + .bpl = 1, 156 147 .desc = "YVU420 planar", 157 148 .yf = 0, 158 149 .rgb = 0, ··· 161 150 { 162 151 .pfmt = V4L2_PIX_FMT_NV16, 163 152 .bpp = 16, 153 + .bpl = 1, 164 154 .desc = "YVYU planar", 165 155 .yf = 1, 166 156 .rgb = 0, ··· 169 157 { 170 158 .pfmt = V4L2_PIX_FMT_RGB24, 171 159 .bpp = 24, 160 + .bpl = 3, 172 161 .desc = "RGB24", 173 162 .pkf = 2, 174 163 .rgb = 1, ··· 177 164 { 178 165 .pfmt = V4L2_PIX_FMT_RGB565, 179 166 .bpp = 16, 167 + .bpl = 2, 180 168 .desc = "RGB565", 181 169 .pkf = 3, 182 170 .rgb = 1, ··· 185 171 { 186 172 .pfmt = V4L2_PIX_FMT_RGB565X, 187 173 .bpp = 16, 174 + .bpl = 2, 188 175 .desc = "RGB565 byteswapped", 189 176 .pkf = 3, 190 177 .rgb = 1, ··· 193 178 }; 194 179 195 180 static void sh_vou_schedule_next(struct sh_vou_device *vou_dev, 196 - struct videobuf_buffer *vb) 181 + struct vb2_buffer *vb) 197 182 { 198 183 dma_addr_t addr1, addr2; 199 184 200 - addr1 = videobuf_to_dma_contig(vb); 185 + addr1 = vb2_dma_contig_plane_dma_addr(vb, 0); 201 186 switch (vou_dev->pix.pixelformat) { 202 187 case V4L2_PIX_FMT_NV12: 203 188 case V4L2_PIX_FMT_NV16: ··· 211 196 sh_vou_reg_m_write(vou_dev, VOUAD2R, addr2); 212 197 } 213 198 214 - static void sh_vou_stream_start(struct sh_vou_device *vou_dev, 215 - struct videobuf_buffer *vb) 199 + static void sh_vou_stream_config(struct sh_vou_device *vou_dev) 216 200 { 217 201 unsigned int row_coeff; 218 202 #ifdef __LITTLE_ENDIAN ··· 238 224 239 225 sh_vou_reg_a_write(vou_dev, VOUSWR, dataswap); 240 226 sh_vou_reg_ab_write(vou_dev, VOUAIR, vou_dev->pix.width * row_coeff); 241 - sh_vou_schedule_next(vou_dev, vb); 242 - } 243 - 244 - static void free_buffer(struct videobuf_queue *vq, struct videobuf_buffer *vb) 245 - { 246 - BUG_ON(in_interrupt()); 247 - 248 - /* Wait until this buffer is no longer in STATE_QUEUED or STATE_ACTIVE */ 249 - videobuf_waiton(vq, vb, 0, 0); 250 - videobuf_dma_contig_free(vq, vb); 251 - vb->state = VIDEOBUF_NEEDS_INIT; 252 227 } 253 228 254 229 /* Locking: caller holds fop_lock mutex */ 255 - static int sh_vou_buf_setup(struct videobuf_queue *vq, unsigned int *count, 256 - unsigned int *size) 230 + static int sh_vou_queue_setup(struct vb2_queue *vq, const struct v4l2_format *fmt, 231 + unsigned int *nbuffers, unsigned int *nplanes, 232 + unsigned int sizes[], void *alloc_ctxs[]) 257 233 { 258 - struct video_device *vdev = vq->priv_data; 259 - struct sh_vou_device *vou_dev = video_get_drvdata(vdev); 260 - 261 - *size = vou_fmt[vou_dev->pix_idx].bpp * vou_dev->pix.width * 262 - vou_dev->pix.height / 8; 263 - 264 - if (*count < 2) 265 - *count = 2; 266 - 267 - /* Taking into account maximum frame size, *count will stay >= 2 */ 268 - if (PAGE_ALIGN(*size) * *count > 4 * 1024 * 1024) 269 - *count = 4 * 1024 * 1024 / PAGE_ALIGN(*size); 270 - 271 - dev_dbg(vou_dev->v4l2_dev.dev, "%s(): count=%d, size=%d\n", __func__, 272 - *count, *size); 273 - 274 - return 0; 275 - } 276 - 277 - /* Locking: caller holds fop_lock mutex */ 278 - static int sh_vou_buf_prepare(struct videobuf_queue *vq, 279 - struct videobuf_buffer *vb, 280 - enum v4l2_field field) 281 - { 282 - struct video_device *vdev = vq->priv_data; 283 - struct sh_vou_device *vou_dev = video_get_drvdata(vdev); 234 + struct sh_vou_device *vou_dev = vb2_get_drv_priv(vq); 284 235 struct v4l2_pix_format *pix = &vou_dev->pix; 285 236 int bytes_per_line = vou_fmt[vou_dev->pix_idx].bpp * pix->width / 8; 286 - int ret; 287 237 288 238 dev_dbg(vou_dev->v4l2_dev.dev, "%s()\n", __func__); 289 239 290 - if (vb->width != pix->width || 291 - vb->height != pix->height || 292 - vb->field != pix->field) { 293 - vb->width = pix->width; 294 - vb->height = pix->height; 295 - vb->field = field; 296 - if (vb->state != VIDEOBUF_NEEDS_INIT) 297 - free_buffer(vq, vb); 298 - } 240 + if (fmt && fmt->fmt.pix.sizeimage < pix->height * bytes_per_line) 241 + return -EINVAL; 242 + *nplanes = 1; 243 + sizes[0] = fmt ? fmt->fmt.pix.sizeimage : pix->height * bytes_per_line; 244 + alloc_ctxs[0] = vou_dev->alloc_ctx; 245 + return 0; 246 + } 299 247 300 - vb->size = vb->height * bytes_per_line; 301 - if (vb->baddr && vb->bsize < vb->size) { 248 + static int sh_vou_buf_prepare(struct vb2_buffer *vb) 249 + { 250 + struct sh_vou_device *vou_dev = vb2_get_drv_priv(vb->vb2_queue); 251 + struct v4l2_pix_format *pix = &vou_dev->pix; 252 + unsigned bytes_per_line = vou_fmt[vou_dev->pix_idx].bpp * pix->width / 8; 253 + unsigned size = pix->height * bytes_per_line; 254 + 255 + dev_dbg(vou_dev->v4l2_dev.dev, "%s()\n", __func__); 256 + 257 + if (vb2_plane_size(vb, 0) < size) { 302 258 /* User buffer too small */ 303 - dev_warn(vq->dev, "User buffer too small: [%zu] @ %lx\n", 304 - vb->bsize, vb->baddr); 259 + dev_warn(vou_dev->v4l2_dev.dev, "buffer too small (%lu < %u)\n", 260 + vb2_plane_size(vb, 0), size); 305 261 return -EINVAL; 306 262 } 307 263 308 - if (vb->state == VIDEOBUF_NEEDS_INIT) { 309 - ret = videobuf_iolock(vq, vb, NULL); 310 - if (ret < 0) { 311 - dev_warn(vq->dev, "IOLOCK buf-type %d: %d\n", 312 - vb->memory, ret); 313 - return ret; 314 - } 315 - vb->state = VIDEOBUF_PREPARED; 316 - } 317 - 318 - dev_dbg(vou_dev->v4l2_dev.dev, 319 - "%s(): fmt #%d, %u bytes per line, phys %pad, type %d, state %d\n", 320 - __func__, vou_dev->pix_idx, bytes_per_line, 321 - ({ dma_addr_t addr = videobuf_to_dma_contig(vb); &addr; }), 322 - vb->memory, vb->state); 323 - 264 + vb2_set_plane_payload(vb, 0, size); 324 265 return 0; 325 266 } 326 267 327 268 /* Locking: caller holds fop_lock mutex and vq->irqlock spinlock */ 328 - static void sh_vou_buf_queue(struct videobuf_queue *vq, 329 - struct videobuf_buffer *vb) 269 + static void sh_vou_buf_queue(struct vb2_buffer *vb) 330 270 { 331 - struct video_device *vdev = vq->priv_data; 332 - struct sh_vou_device *vou_dev = video_get_drvdata(vdev); 333 - 334 - dev_dbg(vou_dev->v4l2_dev.dev, "%s()\n", __func__); 335 - 336 - vb->state = VIDEOBUF_QUEUED; 337 - list_add_tail(&vb->queue, &vou_dev->queue); 338 - 339 - if (vou_dev->status == SH_VOU_RUNNING) { 340 - return; 341 - } else if (!vou_dev->active) { 342 - vou_dev->active = vb; 343 - /* Start from side A: we use mirror addresses, so, set B */ 344 - sh_vou_reg_a_write(vou_dev, VOURPR, 1); 345 - dev_dbg(vou_dev->v4l2_dev.dev, "%s: first buffer status 0x%x\n", 346 - __func__, sh_vou_reg_a_read(vou_dev, VOUSTR)); 347 - sh_vou_schedule_next(vou_dev, vb); 348 - /* Only activate VOU after the second buffer */ 349 - } else if (vou_dev->active->queue.next == &vb->queue) { 350 - /* Second buffer - initialise register side B */ 351 - sh_vou_reg_a_write(vou_dev, VOURPR, 0); 352 - sh_vou_stream_start(vou_dev, vb); 353 - 354 - /* Register side switching with frame VSYNC */ 355 - sh_vou_reg_a_write(vou_dev, VOURCR, 5); 356 - dev_dbg(vou_dev->v4l2_dev.dev, "%s: second buffer status 0x%x\n", 357 - __func__, sh_vou_reg_a_read(vou_dev, VOUSTR)); 358 - 359 - /* Enable End-of-Frame (VSYNC) interrupts */ 360 - sh_vou_reg_a_write(vou_dev, VOUIR, 0x10004); 361 - /* Two buffers on the queue - activate the hardware */ 362 - 363 - vou_dev->status = SH_VOU_RUNNING; 364 - sh_vou_reg_a_write(vou_dev, VOUER, 0x107); 365 - } 366 - } 367 - 368 - static void sh_vou_buf_release(struct videobuf_queue *vq, 369 - struct videobuf_buffer *vb) 370 - { 371 - struct video_device *vdev = vq->priv_data; 372 - struct sh_vou_device *vou_dev = video_get_drvdata(vdev); 271 + struct sh_vou_device *vou_dev = vb2_get_drv_priv(vb->vb2_queue); 272 + struct sh_vou_buffer *shbuf = to_sh_vou_buffer(vb); 373 273 unsigned long flags; 374 274 375 - dev_dbg(vou_dev->v4l2_dev.dev, "%s()\n", __func__); 376 - 377 275 spin_lock_irqsave(&vou_dev->lock, flags); 378 - 379 - if (vou_dev->active == vb) { 380 - /* disable output */ 381 - sh_vou_reg_a_set(vou_dev, VOUER, 0, 1); 382 - /* ...but the current frame will complete */ 383 - sh_vou_reg_a_set(vou_dev, VOUIR, 0, 0x30000); 384 - vou_dev->active = NULL; 385 - } 386 - 387 - if ((vb->state == VIDEOBUF_ACTIVE || vb->state == VIDEOBUF_QUEUED)) { 388 - vb->state = VIDEOBUF_ERROR; 389 - list_del(&vb->queue); 390 - } 391 - 276 + list_add_tail(&shbuf->list, &vou_dev->buf_list); 392 277 spin_unlock_irqrestore(&vou_dev->lock, flags); 393 - 394 - free_buffer(vq, vb); 395 278 } 396 279 397 - static struct videobuf_queue_ops sh_vou_video_qops = { 398 - .buf_setup = sh_vou_buf_setup, 399 - .buf_prepare = sh_vou_buf_prepare, 400 - .buf_queue = sh_vou_buf_queue, 401 - .buf_release = sh_vou_buf_release, 280 + static int sh_vou_start_streaming(struct vb2_queue *vq, unsigned int count) 281 + { 282 + struct sh_vou_device *vou_dev = vb2_get_drv_priv(vq); 283 + struct sh_vou_buffer *buf, *node; 284 + int ret; 285 + 286 + vou_dev->sequence = 0; 287 + ret = v4l2_device_call_until_err(&vou_dev->v4l2_dev, 0, 288 + video, s_stream, 1); 289 + if (ret < 0 && ret != -ENOIOCTLCMD) { 290 + list_for_each_entry_safe(buf, node, &vou_dev->buf_list, list) { 291 + vb2_buffer_done(&buf->vb, VB2_BUF_STATE_QUEUED); 292 + list_del(&buf->list); 293 + } 294 + vou_dev->active = NULL; 295 + return ret; 296 + } 297 + 298 + buf = list_entry(vou_dev->buf_list.next, struct sh_vou_buffer, list); 299 + 300 + vou_dev->active = buf; 301 + 302 + /* Start from side A: we use mirror addresses, so, set B */ 303 + sh_vou_reg_a_write(vou_dev, VOURPR, 1); 304 + dev_dbg(vou_dev->v4l2_dev.dev, "%s: first buffer status 0x%x\n", 305 + __func__, sh_vou_reg_a_read(vou_dev, VOUSTR)); 306 + sh_vou_schedule_next(vou_dev, &buf->vb); 307 + 308 + buf = list_entry(buf->list.next, struct sh_vou_buffer, list); 309 + 310 + /* Second buffer - initialise register side B */ 311 + sh_vou_reg_a_write(vou_dev, VOURPR, 0); 312 + sh_vou_schedule_next(vou_dev, &buf->vb); 313 + 314 + /* Register side switching with frame VSYNC */ 315 + sh_vou_reg_a_write(vou_dev, VOURCR, 5); 316 + 317 + sh_vou_stream_config(vou_dev); 318 + /* Enable End-of-Frame (VSYNC) interrupts */ 319 + sh_vou_reg_a_write(vou_dev, VOUIR, 0x10004); 320 + 321 + /* Two buffers on the queue - activate the hardware */ 322 + vou_dev->status = SH_VOU_RUNNING; 323 + sh_vou_reg_a_write(vou_dev, VOUER, 0x107); 324 + return 0; 325 + } 326 + 327 + static void sh_vou_stop_streaming(struct vb2_queue *vq) 328 + { 329 + struct sh_vou_device *vou_dev = vb2_get_drv_priv(vq); 330 + struct sh_vou_buffer *buf, *node; 331 + unsigned long flags; 332 + 333 + v4l2_device_call_until_err(&vou_dev->v4l2_dev, 0, 334 + video, s_stream, 0); 335 + /* disable output */ 336 + sh_vou_reg_a_set(vou_dev, VOUER, 0, 1); 337 + /* ...but the current frame will complete */ 338 + sh_vou_reg_a_set(vou_dev, VOUIR, 0, 0x30000); 339 + msleep(50); 340 + spin_lock_irqsave(&vou_dev->lock, flags); 341 + list_for_each_entry_safe(buf, node, &vou_dev->buf_list, list) { 342 + vb2_buffer_done(&buf->vb, VB2_BUF_STATE_ERROR); 343 + list_del(&buf->list); 344 + } 345 + vou_dev->active = NULL; 346 + spin_unlock_irqrestore(&vou_dev->lock, flags); 347 + } 348 + 349 + static struct vb2_ops sh_vou_qops = { 350 + .queue_setup = sh_vou_queue_setup, 351 + .buf_prepare = sh_vou_buf_prepare, 352 + .buf_queue = sh_vou_buf_queue, 353 + .start_streaming = sh_vou_start_streaming, 354 + .stop_streaming = sh_vou_stop_streaming, 355 + .wait_prepare = vb2_ops_wait_prepare, 356 + .wait_finish = vb2_ops_wait_finish, 402 357 }; 403 358 404 359 /* Video IOCTLs */ ··· 379 396 dev_dbg(vou_dev->v4l2_dev.dev, "%s()\n", __func__); 380 397 381 398 strlcpy(cap->card, "SuperH VOU", sizeof(cap->card)); 382 - cap->device_caps = V4L2_CAP_VIDEO_OUTPUT | V4L2_CAP_STREAMING; 399 + strlcpy(cap->driver, "sh-vou", sizeof(cap->driver)); 400 + strlcpy(cap->bus_info, "platform:sh-vou", sizeof(cap->bus_info)); 401 + cap->device_caps = V4L2_CAP_VIDEO_OUTPUT | V4L2_CAP_READWRITE | 402 + V4L2_CAP_STREAMING; 383 403 cap->capabilities = cap->device_caps | V4L2_CAP_DEVICE_CAPS; 384 404 return 0; 385 405 } ··· 526 540 img_height_max = 576; 527 541 528 542 /* Image width must be a multiple of 4 */ 529 - v4l_bound_align_image(&geo->in_width, 0, VOU_MAX_IMAGE_WIDTH, 2, 530 - &geo->in_height, 0, img_height_max, 1, 0); 543 + v4l_bound_align_image(&geo->in_width, 544 + VOU_MIN_IMAGE_WIDTH, VOU_MAX_IMAGE_WIDTH, 2, 545 + &geo->in_height, 546 + VOU_MIN_IMAGE_HEIGHT, img_height_max, 1, 0); 531 547 532 548 /* Select scales to come as close as possible to the output image */ 533 549 for (i = ARRAY_SIZE(vou_scale_h_num) - 1; i >= 0; i--) { ··· 659 671 vou_scale_v_num[idx_v], vou_scale_v_den[idx_v], best); 660 672 } 661 673 662 - static int sh_vou_s_fmt_vid_out(struct file *file, void *priv, 663 - struct v4l2_format *fmt) 674 + static int sh_vou_try_fmt_vid_out(struct file *file, void *priv, 675 + struct v4l2_format *fmt) 664 676 { 665 677 struct sh_vou_device *vou_dev = video_drvdata(file); 666 678 struct v4l2_pix_format *pix = &fmt->fmt.pix; 667 679 unsigned int img_height_max; 668 680 int pix_idx; 669 - struct sh_vou_geometry geo; 670 - struct v4l2_subdev_format format = { 671 - .which = V4L2_SUBDEV_FORMAT_ACTIVE, 672 - /* Revisit: is this the correct code? */ 673 - .format.code = MEDIA_BUS_FMT_YUYV8_2X8, 674 - .format.field = V4L2_FIELD_INTERLACED, 675 - .format.colorspace = V4L2_COLORSPACE_SMPTE170M, 676 - }; 677 - struct v4l2_mbus_framefmt *mbfmt = &format.format; 678 - int ret; 679 681 680 - dev_dbg(vou_dev->v4l2_dev.dev, "%s(): %ux%u -> %ux%u\n", __func__, 681 - vou_dev->rect.width, vou_dev->rect.height, 682 - pix->width, pix->height); 682 + dev_dbg(vou_dev->v4l2_dev.dev, "%s()\n", __func__); 683 683 684 - if (pix->field == V4L2_FIELD_ANY) 685 - pix->field = V4L2_FIELD_NONE; 686 - 687 - if (fmt->type != V4L2_BUF_TYPE_VIDEO_OUTPUT || 688 - pix->field != V4L2_FIELD_NONE) 689 - return -EINVAL; 684 + pix->field = V4L2_FIELD_INTERLACED; 685 + pix->colorspace = V4L2_COLORSPACE_SMPTE170M; 686 + pix->ycbcr_enc = pix->quantization = 0; 690 687 691 688 for (pix_idx = 0; pix_idx < ARRAY_SIZE(vou_fmt); pix_idx++) 692 689 if (vou_fmt[pix_idx].pfmt == pix->pixelformat) ··· 685 712 else 686 713 img_height_max = 576; 687 714 688 - /* Image width must be a multiple of 4 */ 689 - v4l_bound_align_image(&pix->width, 0, VOU_MAX_IMAGE_WIDTH, 2, 690 - &pix->height, 0, img_height_max, 1, 0); 715 + v4l_bound_align_image(&pix->width, 716 + VOU_MIN_IMAGE_WIDTH, VOU_MAX_IMAGE_WIDTH, 2, 717 + &pix->height, 718 + VOU_MIN_IMAGE_HEIGHT, img_height_max, 1, 0); 719 + pix->bytesperline = pix->width * vou_fmt[pix_idx].bpl; 720 + pix->sizeimage = pix->height * ((pix->width * vou_fmt[pix_idx].bpp) >> 3); 721 + 722 + return 0; 723 + } 724 + 725 + static int sh_vou_set_fmt_vid_out(struct sh_vou_device *vou_dev, 726 + struct v4l2_pix_format *pix) 727 + { 728 + unsigned int img_height_max; 729 + struct sh_vou_geometry geo; 730 + struct v4l2_subdev_format format = { 731 + .which = V4L2_SUBDEV_FORMAT_ACTIVE, 732 + /* Revisit: is this the correct code? */ 733 + .format.code = MEDIA_BUS_FMT_YUYV8_2X8, 734 + .format.field = V4L2_FIELD_INTERLACED, 735 + .format.colorspace = V4L2_COLORSPACE_SMPTE170M, 736 + }; 737 + struct v4l2_mbus_framefmt *mbfmt = &format.format; 738 + int pix_idx; 739 + int ret; 740 + 741 + if (vb2_is_busy(&vou_dev->queue)) 742 + return -EBUSY; 743 + 744 + for (pix_idx = 0; pix_idx < ARRAY_SIZE(vou_fmt); pix_idx++) 745 + if (vou_fmt[pix_idx].pfmt == pix->pixelformat) 746 + break; 691 747 692 748 geo.in_width = pix->width; 693 749 geo.in_height = pix->height; ··· 734 732 735 733 dev_dbg(vou_dev->v4l2_dev.dev, "%s(): %ux%u -> %ux%u\n", __func__, 736 734 geo.output.width, geo.output.height, mbfmt->width, mbfmt->height); 735 + 736 + if (vou_dev->std & V4L2_STD_525_60) 737 + img_height_max = 480; 738 + else 739 + img_height_max = 576; 737 740 738 741 /* Sanity checks */ 739 742 if ((unsigned)mbfmt->width > VOU_MAX_IMAGE_WIDTH || ··· 772 765 return 0; 773 766 } 774 767 775 - static int sh_vou_try_fmt_vid_out(struct file *file, void *priv, 776 - struct v4l2_format *fmt) 768 + static int sh_vou_s_fmt_vid_out(struct file *file, void *priv, 769 + struct v4l2_format *fmt) 777 770 { 778 771 struct sh_vou_device *vou_dev = video_drvdata(file); 779 - struct v4l2_pix_format *pix = &fmt->fmt.pix; 780 - int i; 772 + int ret = sh_vou_try_fmt_vid_out(file, priv, fmt); 781 773 782 - dev_dbg(vou_dev->v4l2_dev.dev, "%s()\n", __func__); 783 - 784 - fmt->type = V4L2_BUF_TYPE_VIDEO_OUTPUT; 785 - pix->field = V4L2_FIELD_NONE; 786 - 787 - v4l_bound_align_image(&pix->width, 0, VOU_MAX_IMAGE_WIDTH, 1, 788 - &pix->height, 0, VOU_MAX_IMAGE_HEIGHT, 1, 0); 789 - 790 - for (i = 0; i < ARRAY_SIZE(vou_fmt); i++) 791 - if (vou_fmt[i].pfmt == pix->pixelformat) 792 - return 0; 793 - 794 - pix->pixelformat = vou_fmt[0].pfmt; 795 - 796 - return 0; 797 - } 798 - 799 - static int sh_vou_reqbufs(struct file *file, void *priv, 800 - struct v4l2_requestbuffers *req) 801 - { 802 - struct sh_vou_device *vou_dev = video_drvdata(file); 803 - struct sh_vou_file *vou_file = priv; 804 - 805 - dev_dbg(vou_dev->v4l2_dev.dev, "%s()\n", __func__); 806 - 807 - if (req->type != V4L2_BUF_TYPE_VIDEO_OUTPUT) 808 - return -EINVAL; 809 - 810 - return videobuf_reqbufs(&vou_file->vbq, req); 811 - } 812 - 813 - static int sh_vou_querybuf(struct file *file, void *priv, 814 - struct v4l2_buffer *b) 815 - { 816 - struct sh_vou_device *vou_dev = video_drvdata(file); 817 - struct sh_vou_file *vou_file = priv; 818 - 819 - dev_dbg(vou_dev->v4l2_dev.dev, "%s()\n", __func__); 820 - 821 - return videobuf_querybuf(&vou_file->vbq, b); 822 - } 823 - 824 - static int sh_vou_qbuf(struct file *file, void *priv, struct v4l2_buffer *b) 825 - { 826 - struct sh_vou_device *vou_dev = video_drvdata(file); 827 - struct sh_vou_file *vou_file = priv; 828 - 829 - dev_dbg(vou_dev->v4l2_dev.dev, "%s()\n", __func__); 830 - 831 - return videobuf_qbuf(&vou_file->vbq, b); 832 - } 833 - 834 - static int sh_vou_dqbuf(struct file *file, void *priv, struct v4l2_buffer *b) 835 - { 836 - struct sh_vou_device *vou_dev = video_drvdata(file); 837 - struct sh_vou_file *vou_file = priv; 838 - 839 - dev_dbg(vou_dev->v4l2_dev.dev, "%s()\n", __func__); 840 - 841 - return videobuf_dqbuf(&vou_file->vbq, b, file->f_flags & O_NONBLOCK); 842 - } 843 - 844 - static int sh_vou_streamon(struct file *file, void *priv, 845 - enum v4l2_buf_type buftype) 846 - { 847 - struct sh_vou_device *vou_dev = video_drvdata(file); 848 - struct sh_vou_file *vou_file = priv; 849 - int ret; 850 - 851 - dev_dbg(vou_dev->v4l2_dev.dev, "%s()\n", __func__); 852 - 853 - ret = v4l2_device_call_until_err(&vou_dev->v4l2_dev, 0, 854 - video, s_stream, 1); 855 - if (ret < 0 && ret != -ENOIOCTLCMD) 774 + if (ret) 856 775 return ret; 857 - 858 - /* This calls our .buf_queue() (== sh_vou_buf_queue) */ 859 - return videobuf_streamon(&vou_file->vbq); 776 + return sh_vou_set_fmt_vid_out(vou_dev, &fmt->fmt.pix); 860 777 } 861 778 862 - static int sh_vou_streamoff(struct file *file, void *priv, 863 - enum v4l2_buf_type buftype) 779 + static int sh_vou_enum_output(struct file *file, void *fh, 780 + struct v4l2_output *a) 864 781 { 865 782 struct sh_vou_device *vou_dev = video_drvdata(file); 866 - struct sh_vou_file *vou_file = priv; 867 783 868 - dev_dbg(vou_dev->v4l2_dev.dev, "%s()\n", __func__); 869 - 870 - /* 871 - * This calls buf_release from host driver's videobuf_queue_ops for all 872 - * remaining buffers. When the last buffer is freed, stop streaming 873 - */ 874 - videobuf_streamoff(&vou_file->vbq); 875 - v4l2_device_call_until_err(&vou_dev->v4l2_dev, 0, video, s_stream, 0); 876 - 784 + if (a->index) 785 + return -EINVAL; 786 + strlcpy(a->name, "Video Out", sizeof(a->name)); 787 + a->type = V4L2_OUTPUT_TYPE_ANALOG; 788 + a->std = vou_dev->vdev.tvnorms; 877 789 return 0; 790 + } 791 + 792 + static int sh_vou_g_output(struct file *file, void *fh, unsigned int *i) 793 + { 794 + *i = 0; 795 + return 0; 796 + } 797 + 798 + static int sh_vou_s_output(struct file *file, void *fh, unsigned int i) 799 + { 800 + return i ? -EINVAL : 0; 878 801 } 879 802 880 803 static u32 sh_vou_ntsc_mode(enum sh_vou_bus_fmt bus_fmt) ··· 829 892 830 893 dev_dbg(vou_dev->v4l2_dev.dev, "%s(): 0x%llx\n", __func__, std_id); 831 894 832 - if (std_id & ~vou_dev->vdev.tvnorms) 833 - return -EINVAL; 895 + if (std_id == vou_dev->std) 896 + return 0; 897 + 898 + if (vb2_is_busy(&vou_dev->queue)) 899 + return -EBUSY; 834 900 835 901 ret = v4l2_device_call_until_err(&vou_dev->v4l2_dev, 0, video, 836 902 s_std_output, std_id); ··· 841 901 if (ret < 0 && ret != -ENOIOCTLCMD) 842 902 return ret; 843 903 844 - if (std_id & V4L2_STD_525_60) 904 + vou_dev->rect.top = vou_dev->rect.left = 0; 905 + vou_dev->rect.width = VOU_MAX_IMAGE_WIDTH; 906 + if (std_id & V4L2_STD_525_60) { 845 907 sh_vou_reg_ab_set(vou_dev, VOUCR, 846 908 sh_vou_ntsc_mode(vou_dev->pdata->bus_fmt) << 29, 7 << 29); 847 - else 909 + vou_dev->rect.height = 480; 910 + } else { 848 911 sh_vou_reg_ab_set(vou_dev, VOUCR, 5 << 29, 7 << 29); 912 + vou_dev->rect.height = 576; 913 + } 849 914 915 + vou_dev->pix.width = vou_dev->rect.width; 916 + vou_dev->pix.height = vou_dev->rect.height; 917 + vou_dev->pix.bytesperline = 918 + vou_dev->pix.width * vou_fmt[vou_dev->pix_idx].bpl; 919 + vou_dev->pix.sizeimage = vou_dev->pix.height * 920 + ((vou_dev->pix.width * vou_fmt[vou_dev->pix_idx].bpp) >> 3); 850 921 vou_dev->std = std_id; 922 + sh_vou_set_fmt_vid_out(vou_dev, &vou_dev->pix); 851 923 852 924 return 0; 853 925 } ··· 875 923 return 0; 876 924 } 877 925 878 - static int sh_vou_g_crop(struct file *file, void *fh, struct v4l2_crop *a) 926 + static int sh_vou_log_status(struct file *file, void *priv) 879 927 { 880 928 struct sh_vou_device *vou_dev = video_drvdata(file); 881 929 882 - dev_dbg(vou_dev->v4l2_dev.dev, "%s()\n", __func__); 930 + pr_info("VOUER: 0x%08x\n", sh_vou_reg_a_read(vou_dev, VOUER)); 931 + pr_info("VOUCR: 0x%08x\n", sh_vou_reg_a_read(vou_dev, VOUCR)); 932 + pr_info("VOUSTR: 0x%08x\n", sh_vou_reg_a_read(vou_dev, VOUSTR)); 933 + pr_info("VOUVCR: 0x%08x\n", sh_vou_reg_a_read(vou_dev, VOUVCR)); 934 + pr_info("VOUISR: 0x%08x\n", sh_vou_reg_a_read(vou_dev, VOUISR)); 935 + pr_info("VOUBCR: 0x%08x\n", sh_vou_reg_a_read(vou_dev, VOUBCR)); 936 + pr_info("VOUDPR: 0x%08x\n", sh_vou_reg_a_read(vou_dev, VOUDPR)); 937 + pr_info("VOUDSR: 0x%08x\n", sh_vou_reg_a_read(vou_dev, VOUDSR)); 938 + pr_info("VOUVPR: 0x%08x\n", sh_vou_reg_a_read(vou_dev, VOUVPR)); 939 + pr_info("VOUIR: 0x%08x\n", sh_vou_reg_a_read(vou_dev, VOUIR)); 940 + pr_info("VOUSRR: 0x%08x\n", sh_vou_reg_a_read(vou_dev, VOUSRR)); 941 + pr_info("VOUMSR: 0x%08x\n", sh_vou_reg_a_read(vou_dev, VOUMSR)); 942 + pr_info("VOUHIR: 0x%08x\n", sh_vou_reg_a_read(vou_dev, VOUHIR)); 943 + pr_info("VOUDFR: 0x%08x\n", sh_vou_reg_a_read(vou_dev, VOUDFR)); 944 + pr_info("VOUAD1R: 0x%08x\n", sh_vou_reg_a_read(vou_dev, VOUAD1R)); 945 + pr_info("VOUAD2R: 0x%08x\n", sh_vou_reg_a_read(vou_dev, VOUAD2R)); 946 + pr_info("VOUAIR: 0x%08x\n", sh_vou_reg_a_read(vou_dev, VOUAIR)); 947 + pr_info("VOUSWR: 0x%08x\n", sh_vou_reg_a_read(vou_dev, VOUSWR)); 948 + pr_info("VOURCR: 0x%08x\n", sh_vou_reg_a_read(vou_dev, VOURCR)); 949 + pr_info("VOURPR: 0x%08x\n", sh_vou_reg_a_read(vou_dev, VOURPR)); 950 + return 0; 951 + } 883 952 884 - a->type = V4L2_BUF_TYPE_VIDEO_OUTPUT; 885 - a->c = vou_dev->rect; 953 + static int sh_vou_g_selection(struct file *file, void *fh, 954 + struct v4l2_selection *sel) 955 + { 956 + struct sh_vou_device *vou_dev = video_drvdata(file); 886 957 958 + if (sel->type != V4L2_BUF_TYPE_VIDEO_OUTPUT) 959 + return -EINVAL; 960 + switch (sel->target) { 961 + case V4L2_SEL_TGT_COMPOSE: 962 + sel->r = vou_dev->rect; 963 + break; 964 + case V4L2_SEL_TGT_COMPOSE_DEFAULT: 965 + case V4L2_SEL_TGT_COMPOSE_BOUNDS: 966 + sel->r.left = 0; 967 + sel->r.top = 0; 968 + sel->r.width = VOU_MAX_IMAGE_WIDTH; 969 + if (vou_dev->std & V4L2_STD_525_60) 970 + sel->r.height = 480; 971 + else 972 + sel->r.height = 576; 973 + break; 974 + default: 975 + return -EINVAL; 976 + } 887 977 return 0; 888 978 } 889 979 890 980 /* Assume a dull encoder, do all the work ourselves. */ 891 - static int sh_vou_s_crop(struct file *file, void *fh, const struct v4l2_crop *a) 981 + static int sh_vou_s_selection(struct file *file, void *fh, 982 + struct v4l2_selection *sel) 892 983 { 893 - struct v4l2_crop a_writable = *a; 984 + struct v4l2_rect *rect = &sel->r; 894 985 struct sh_vou_device *vou_dev = video_drvdata(file); 895 - struct v4l2_rect *rect = &a_writable.c; 896 986 struct v4l2_crop sd_crop = {.type = V4L2_BUF_TYPE_VIDEO_OUTPUT}; 897 987 struct v4l2_pix_format *pix = &vou_dev->pix; 898 988 struct sh_vou_geometry geo; ··· 948 954 unsigned int img_height_max; 949 955 int ret; 950 956 951 - dev_dbg(vou_dev->v4l2_dev.dev, "%s(): %ux%u@%u:%u\n", __func__, 952 - rect->width, rect->height, rect->left, rect->top); 953 - 954 - if (a->type != V4L2_BUF_TYPE_VIDEO_OUTPUT) 957 + if (sel->type != V4L2_BUF_TYPE_VIDEO_OUTPUT || 958 + sel->target != V4L2_SEL_TGT_COMPOSE) 955 959 return -EINVAL; 960 + 961 + if (vb2_is_busy(&vou_dev->queue)) 962 + return -EBUSY; 956 963 957 964 if (vou_dev->std & V4L2_STD_525_60) 958 965 img_height_max = 480; 959 966 else 960 967 img_height_max = 576; 961 968 962 - v4l_bound_align_image(&rect->width, 0, VOU_MAX_IMAGE_WIDTH, 1, 963 - &rect->height, 0, img_height_max, 1, 0); 969 + v4l_bound_align_image(&rect->width, 970 + VOU_MIN_IMAGE_WIDTH, VOU_MAX_IMAGE_WIDTH, 1, 971 + &rect->height, 972 + VOU_MIN_IMAGE_HEIGHT, img_height_max, 1, 0); 964 973 965 974 if (rect->width + rect->left > VOU_MAX_IMAGE_WIDTH) 966 975 rect->left = VOU_MAX_IMAGE_WIDTH - rect->width; ··· 1018 1021 return 0; 1019 1022 } 1020 1023 1021 - /* 1022 - * Total field: NTSC 858 x 2 * 262/263, PAL 864 x 2 * 312/313, default rectangle 1023 - * is the initial register values, height takes the interlaced format into 1024 - * account. The actual image can only go up to 720 x 2 * 240, So, VOUVPR can 1025 - * actually only meaningfully contain values <= 720 and <= 240 respectively, and 1026 - * not <= 864 and <= 312. 1027 - */ 1028 - static int sh_vou_cropcap(struct file *file, void *priv, 1029 - struct v4l2_cropcap *a) 1030 - { 1031 - struct sh_vou_device *vou_dev = video_drvdata(file); 1032 - 1033 - dev_dbg(vou_dev->v4l2_dev.dev, "%s()\n", __func__); 1034 - 1035 - a->type = V4L2_BUF_TYPE_VIDEO_OUTPUT; 1036 - a->bounds.left = 0; 1037 - a->bounds.top = 0; 1038 - a->bounds.width = VOU_MAX_IMAGE_WIDTH; 1039 - a->bounds.height = VOU_MAX_IMAGE_HEIGHT; 1040 - /* Default = max, set VOUDPR = 0, which is not hardware default */ 1041 - a->defrect.left = 0; 1042 - a->defrect.top = 0; 1043 - a->defrect.width = VOU_MAX_IMAGE_WIDTH; 1044 - a->defrect.height = VOU_MAX_IMAGE_HEIGHT; 1045 - a->pixelaspect.numerator = 1; 1046 - a->pixelaspect.denominator = 1; 1047 - 1048 - return 0; 1049 - } 1050 - 1051 1024 static irqreturn_t sh_vou_isr(int irq, void *dev_id) 1052 1025 { 1053 1026 struct sh_vou_device *vou_dev = dev_id; 1054 1027 static unsigned long j; 1055 - struct videobuf_buffer *vb; 1028 + struct sh_vou_buffer *vb; 1056 1029 static int cnt; 1057 1030 u32 irq_status = sh_vou_reg_a_read(vou_dev, VOUIR), masked; 1058 1031 u32 vou_status = sh_vou_reg_a_read(vou_dev, VOUSTR); ··· 1035 1068 } 1036 1069 1037 1070 spin_lock(&vou_dev->lock); 1038 - if (!vou_dev->active || list_empty(&vou_dev->queue)) { 1071 + if (!vou_dev->active || list_empty(&vou_dev->buf_list)) { 1039 1072 if (printk_timed_ratelimit(&j, 500)) 1040 1073 dev_warn(vou_dev->v4l2_dev.dev, 1041 1074 "IRQ without active buffer: %x!\n", irq_status); ··· 1057 1090 sh_vou_reg_a_write(vou_dev, VOUIR, masked); 1058 1091 1059 1092 vb = vou_dev->active; 1060 - list_del(&vb->queue); 1061 - 1062 - vb->state = VIDEOBUF_DONE; 1063 - v4l2_get_timestamp(&vb->ts); 1064 - vb->field_count++; 1065 - wake_up(&vb->done); 1066 - 1067 - if (list_empty(&vou_dev->queue)) { 1068 - /* Stop VOU */ 1069 - dev_dbg(vou_dev->v4l2_dev.dev, "%s: queue empty after %d\n", 1070 - __func__, cnt); 1071 - sh_vou_reg_a_set(vou_dev, VOUER, 0, 1); 1072 - vou_dev->active = NULL; 1073 - vou_dev->status = SH_VOU_INITIALISING; 1074 - /* Disable End-of-Frame (VSYNC) interrupts */ 1075 - sh_vou_reg_a_set(vou_dev, VOUIR, 0, 0x30000); 1093 + if (list_is_singular(&vb->list)) { 1094 + /* Keep cycling while no next buffer is available */ 1095 + sh_vou_schedule_next(vou_dev, &vb->vb); 1076 1096 spin_unlock(&vou_dev->lock); 1077 1097 return IRQ_HANDLED; 1078 1098 } 1079 1099 1080 - vou_dev->active = list_entry(vou_dev->queue.next, 1081 - struct videobuf_buffer, queue); 1100 + list_del(&vb->list); 1082 1101 1083 - if (vou_dev->active->queue.next != &vou_dev->queue) { 1084 - struct videobuf_buffer *new = list_entry(vou_dev->active->queue.next, 1085 - struct videobuf_buffer, queue); 1086 - sh_vou_schedule_next(vou_dev, new); 1102 + v4l2_get_timestamp(&vb->vb.v4l2_buf.timestamp); 1103 + vb->vb.v4l2_buf.sequence = vou_dev->sequence++; 1104 + vb->vb.v4l2_buf.field = V4L2_FIELD_INTERLACED; 1105 + vb2_buffer_done(&vb->vb, VB2_BUF_STATE_DONE); 1106 + 1107 + vou_dev->active = list_entry(vou_dev->buf_list.next, 1108 + struct sh_vou_buffer, list); 1109 + 1110 + if (list_is_singular(&vou_dev->buf_list)) { 1111 + /* Keep cycling while no next buffer is available */ 1112 + sh_vou_schedule_next(vou_dev, &vou_dev->active->vb); 1113 + } else { 1114 + struct sh_vou_buffer *new = list_entry(vou_dev->active->list.next, 1115 + struct sh_vou_buffer, list); 1116 + sh_vou_schedule_next(vou_dev, &new->vb); 1087 1117 } 1088 1118 1089 1119 spin_unlock(&vou_dev->lock); ··· 1120 1156 /* Default - fixed HSYNC length, can be made configurable is required */ 1121 1157 sh_vou_reg_ab_write(vou_dev, VOUMSR, 0x800000); 1122 1158 1159 + sh_vou_set_fmt_vid_out(vou_dev, &vou_dev->pix); 1160 + 1123 1161 return 0; 1124 1162 } 1125 1163 ··· 1129 1163 static int sh_vou_open(struct file *file) 1130 1164 { 1131 1165 struct sh_vou_device *vou_dev = video_drvdata(file); 1132 - struct sh_vou_file *vou_file = kzalloc(sizeof(struct sh_vou_file), 1133 - GFP_KERNEL); 1166 + int err; 1134 1167 1135 - if (!vou_file) 1136 - return -ENOMEM; 1137 - 1138 - dev_dbg(vou_dev->v4l2_dev.dev, "%s()\n", __func__); 1139 - 1140 - if (mutex_lock_interruptible(&vou_dev->fop_lock)) { 1141 - kfree(vou_file); 1168 + if (mutex_lock_interruptible(&vou_dev->fop_lock)) 1142 1169 return -ERESTARTSYS; 1143 - } 1144 - if (atomic_inc_return(&vou_dev->use_count) == 1) { 1145 - int ret; 1170 + 1171 + err = v4l2_fh_open(file); 1172 + if (err) 1173 + goto done_open; 1174 + if (v4l2_fh_is_singular_file(file) && 1175 + vou_dev->status == SH_VOU_INITIALISING) { 1146 1176 /* First open */ 1147 - vou_dev->status = SH_VOU_INITIALISING; 1148 1177 pm_runtime_get_sync(vou_dev->v4l2_dev.dev); 1149 - ret = sh_vou_hw_init(vou_dev); 1150 - if (ret < 0) { 1151 - atomic_dec(&vou_dev->use_count); 1178 + err = sh_vou_hw_init(vou_dev); 1179 + if (err < 0) { 1152 1180 pm_runtime_put(vou_dev->v4l2_dev.dev); 1181 + v4l2_fh_release(file); 1182 + } else { 1153 1183 vou_dev->status = SH_VOU_IDLE; 1154 - mutex_unlock(&vou_dev->fop_lock); 1155 - kfree(vou_file); 1156 - return ret; 1157 1184 } 1158 1185 } 1159 - 1160 - videobuf_queue_dma_contig_init(&vou_file->vbq, &sh_vou_video_qops, 1161 - vou_dev->v4l2_dev.dev, &vou_dev->lock, 1162 - V4L2_BUF_TYPE_VIDEO_OUTPUT, 1163 - V4L2_FIELD_NONE, 1164 - sizeof(struct videobuf_buffer), 1165 - &vou_dev->vdev, &vou_dev->fop_lock); 1186 + done_open: 1166 1187 mutex_unlock(&vou_dev->fop_lock); 1167 - 1168 - file->private_data = vou_file; 1169 - 1170 - return 0; 1188 + return err; 1171 1189 } 1172 1190 1173 1191 static int sh_vou_release(struct file *file) 1174 1192 { 1175 1193 struct sh_vou_device *vou_dev = video_drvdata(file); 1176 - struct sh_vou_file *vou_file = file->private_data; 1177 - 1178 - dev_dbg(vou_dev->v4l2_dev.dev, "%s()\n", __func__); 1179 - 1180 - if (!atomic_dec_return(&vou_dev->use_count)) { 1181 - mutex_lock(&vou_dev->fop_lock); 1182 - /* Last close */ 1183 - vou_dev->status = SH_VOU_IDLE; 1184 - sh_vou_reg_a_set(vou_dev, VOUER, 0, 0x101); 1185 - pm_runtime_put(vou_dev->v4l2_dev.dev); 1186 - mutex_unlock(&vou_dev->fop_lock); 1187 - } 1188 - 1189 - file->private_data = NULL; 1190 - kfree(vou_file); 1191 - 1192 - return 0; 1193 - } 1194 - 1195 - static int sh_vou_mmap(struct file *file, struct vm_area_struct *vma) 1196 - { 1197 - struct sh_vou_device *vou_dev = video_drvdata(file); 1198 - struct sh_vou_file *vou_file = file->private_data; 1199 - int ret; 1200 - 1201 - dev_dbg(vou_dev->v4l2_dev.dev, "%s()\n", __func__); 1202 - 1203 - if (mutex_lock_interruptible(&vou_dev->fop_lock)) 1204 - return -ERESTARTSYS; 1205 - ret = videobuf_mmap_mapper(&vou_file->vbq, vma); 1206 - mutex_unlock(&vou_dev->fop_lock); 1207 - return ret; 1208 - } 1209 - 1210 - static unsigned int sh_vou_poll(struct file *file, poll_table *wait) 1211 - { 1212 - struct sh_vou_device *vou_dev = video_drvdata(file); 1213 - struct sh_vou_file *vou_file = file->private_data; 1214 - unsigned int res; 1215 - 1216 - dev_dbg(vou_dev->v4l2_dev.dev, "%s()\n", __func__); 1194 + bool is_last; 1217 1195 1218 1196 mutex_lock(&vou_dev->fop_lock); 1219 - res = videobuf_poll_stream(file, &vou_file->vbq, wait); 1197 + is_last = v4l2_fh_is_singular_file(file); 1198 + _vb2_fop_release(file, NULL); 1199 + if (is_last) { 1200 + /* Last close */ 1201 + vou_dev->status = SH_VOU_INITIALISING; 1202 + sh_vou_reg_a_set(vou_dev, VOUER, 0, 0x101); 1203 + pm_runtime_put(vou_dev->v4l2_dev.dev); 1204 + } 1220 1205 mutex_unlock(&vou_dev->fop_lock); 1221 - return res; 1206 + return 0; 1222 1207 } 1223 1208 1224 1209 /* sh_vou display ioctl operations */ ··· 1179 1262 .vidioc_g_fmt_vid_out = sh_vou_g_fmt_vid_out, 1180 1263 .vidioc_s_fmt_vid_out = sh_vou_s_fmt_vid_out, 1181 1264 .vidioc_try_fmt_vid_out = sh_vou_try_fmt_vid_out, 1182 - .vidioc_reqbufs = sh_vou_reqbufs, 1183 - .vidioc_querybuf = sh_vou_querybuf, 1184 - .vidioc_qbuf = sh_vou_qbuf, 1185 - .vidioc_dqbuf = sh_vou_dqbuf, 1186 - .vidioc_streamon = sh_vou_streamon, 1187 - .vidioc_streamoff = sh_vou_streamoff, 1265 + .vidioc_reqbufs = vb2_ioctl_reqbufs, 1266 + .vidioc_create_bufs = vb2_ioctl_create_bufs, 1267 + .vidioc_querybuf = vb2_ioctl_querybuf, 1268 + .vidioc_qbuf = vb2_ioctl_qbuf, 1269 + .vidioc_dqbuf = vb2_ioctl_dqbuf, 1270 + .vidioc_prepare_buf = vb2_ioctl_prepare_buf, 1271 + .vidioc_streamon = vb2_ioctl_streamon, 1272 + .vidioc_streamoff = vb2_ioctl_streamoff, 1273 + .vidioc_expbuf = vb2_ioctl_expbuf, 1274 + .vidioc_g_output = sh_vou_g_output, 1275 + .vidioc_s_output = sh_vou_s_output, 1276 + .vidioc_enum_output = sh_vou_enum_output, 1188 1277 .vidioc_s_std = sh_vou_s_std, 1189 1278 .vidioc_g_std = sh_vou_g_std, 1190 - .vidioc_cropcap = sh_vou_cropcap, 1191 - .vidioc_g_crop = sh_vou_g_crop, 1192 - .vidioc_s_crop = sh_vou_s_crop, 1279 + .vidioc_g_selection = sh_vou_g_selection, 1280 + .vidioc_s_selection = sh_vou_s_selection, 1281 + .vidioc_log_status = sh_vou_log_status, 1193 1282 }; 1194 1283 1195 1284 static const struct v4l2_file_operations sh_vou_fops = { ··· 1203 1280 .open = sh_vou_open, 1204 1281 .release = sh_vou_release, 1205 1282 .unlocked_ioctl = video_ioctl2, 1206 - .mmap = sh_vou_mmap, 1207 - .poll = sh_vou_poll, 1283 + .mmap = vb2_fop_mmap, 1284 + .poll = vb2_fop_poll, 1285 + .write = vb2_fop_write, 1208 1286 }; 1209 1287 1210 1288 static const struct video_device sh_vou_video_template = { ··· 1224 1300 struct i2c_adapter *i2c_adap; 1225 1301 struct video_device *vdev; 1226 1302 struct sh_vou_device *vou_dev; 1227 - struct resource *reg_res, *region; 1303 + struct resource *reg_res; 1228 1304 struct v4l2_subdev *subdev; 1305 + struct vb2_queue *q; 1229 1306 int irq, ret; 1230 1307 1231 1308 reg_res = platform_get_resource(pdev, IORESOURCE_MEM, 0); ··· 1237 1312 return -ENODEV; 1238 1313 } 1239 1314 1240 - vou_dev = kzalloc(sizeof(*vou_dev), GFP_KERNEL); 1315 + vou_dev = devm_kzalloc(&pdev->dev, sizeof(*vou_dev), GFP_KERNEL); 1241 1316 if (!vou_dev) 1242 1317 return -ENOMEM; 1243 1318 1244 - INIT_LIST_HEAD(&vou_dev->queue); 1319 + INIT_LIST_HEAD(&vou_dev->buf_list); 1245 1320 spin_lock_init(&vou_dev->lock); 1246 1321 mutex_init(&vou_dev->fop_lock); 1247 - atomic_set(&vou_dev->use_count, 0); 1248 1322 vou_dev->pdata = vou_pdata; 1249 - vou_dev->status = SH_VOU_IDLE; 1323 + vou_dev->status = SH_VOU_INITIALISING; 1324 + vou_dev->pix_idx = 1; 1250 1325 1251 1326 rect = &vou_dev->rect; 1252 1327 pix = &vou_dev->pix; ··· 1259 1334 rect->height = 480; 1260 1335 pix->width = VOU_MAX_IMAGE_WIDTH; 1261 1336 pix->height = 480; 1262 - pix->pixelformat = V4L2_PIX_FMT_YVYU; 1263 - pix->field = V4L2_FIELD_NONE; 1264 - pix->bytesperline = VOU_MAX_IMAGE_WIDTH * 2; 1337 + pix->pixelformat = V4L2_PIX_FMT_NV16; 1338 + pix->field = V4L2_FIELD_INTERLACED; 1339 + pix->bytesperline = VOU_MAX_IMAGE_WIDTH; 1265 1340 pix->sizeimage = VOU_MAX_IMAGE_WIDTH * 2 * 480; 1266 1341 pix->colorspace = V4L2_COLORSPACE_SMPTE170M; 1267 1342 1268 - region = request_mem_region(reg_res->start, resource_size(reg_res), 1269 - pdev->name); 1270 - if (!region) { 1271 - dev_err(&pdev->dev, "VOU region already claimed\n"); 1272 - ret = -EBUSY; 1273 - goto ereqmemreg; 1274 - } 1343 + vou_dev->base = devm_ioremap_resource(&pdev->dev, reg_res); 1344 + if (IS_ERR(vou_dev->base)) 1345 + return PTR_ERR(vou_dev->base); 1275 1346 1276 - vou_dev->base = ioremap(reg_res->start, resource_size(reg_res)); 1277 - if (!vou_dev->base) { 1278 - ret = -ENOMEM; 1279 - goto emap; 1280 - } 1281 - 1282 - ret = request_irq(irq, sh_vou_isr, 0, "vou", vou_dev); 1347 + ret = devm_request_irq(&pdev->dev, irq, sh_vou_isr, 0, "vou", vou_dev); 1283 1348 if (ret < 0) 1284 - goto ereqirq; 1349 + return ret; 1285 1350 1286 1351 ret = v4l2_device_register(&pdev->dev, &vou_dev->v4l2_dev); 1287 1352 if (ret < 0) { 1288 1353 dev_err(&pdev->dev, "Error registering v4l2 device\n"); 1289 - goto ev4l2devreg; 1354 + return ret; 1290 1355 } 1291 1356 1292 1357 vdev = &vou_dev->vdev; ··· 1288 1373 vdev->lock = &vou_dev->fop_lock; 1289 1374 1290 1375 video_set_drvdata(vdev, vou_dev); 1376 + 1377 + /* Initialize the vb2 queue */ 1378 + q = &vou_dev->queue; 1379 + q->type = V4L2_BUF_TYPE_VIDEO_OUTPUT; 1380 + q->io_modes = VB2_MMAP | VB2_DMABUF | VB2_WRITE; 1381 + q->drv_priv = vou_dev; 1382 + q->buf_struct_size = sizeof(struct sh_vou_buffer); 1383 + q->ops = &sh_vou_qops; 1384 + q->mem_ops = &vb2_dma_contig_memops; 1385 + q->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC; 1386 + q->min_buffers_needed = 2; 1387 + q->lock = &vou_dev->fop_lock; 1388 + ret = vb2_queue_init(q); 1389 + if (ret) 1390 + goto einitctx; 1391 + 1392 + vou_dev->alloc_ctx = vb2_dma_contig_init_ctx(&pdev->dev); 1393 + if (IS_ERR(vou_dev->alloc_ctx)) { 1394 + dev_err(&pdev->dev, "Can't allocate buffer context"); 1395 + ret = PTR_ERR(vou_dev->alloc_ctx); 1396 + goto einitctx; 1397 + } 1398 + vdev->queue = q; 1399 + INIT_LIST_HEAD(&vou_dev->buf_list); 1291 1400 1292 1401 pm_runtime_enable(&pdev->dev); 1293 1402 pm_runtime_resume(&pdev->dev); ··· 1344 1405 ereset: 1345 1406 i2c_put_adapter(i2c_adap); 1346 1407 ei2cgadap: 1408 + vb2_dma_contig_cleanup_ctx(vou_dev->alloc_ctx); 1409 + einitctx: 1347 1410 pm_runtime_disable(&pdev->dev); 1348 1411 v4l2_device_unregister(&vou_dev->v4l2_dev); 1349 - ev4l2devreg: 1350 - free_irq(irq, vou_dev); 1351 - ereqirq: 1352 - iounmap(vou_dev->base); 1353 - emap: 1354 - release_mem_region(reg_res->start, resource_size(reg_res)); 1355 - ereqmemreg: 1356 - kfree(vou_dev); 1357 1412 return ret; 1358 1413 } 1359 1414 1360 1415 static int sh_vou_remove(struct platform_device *pdev) 1361 1416 { 1362 - int irq = platform_get_irq(pdev, 0); 1363 1417 struct v4l2_device *v4l2_dev = platform_get_drvdata(pdev); 1364 1418 struct sh_vou_device *vou_dev = container_of(v4l2_dev, 1365 1419 struct sh_vou_device, v4l2_dev); 1366 1420 struct v4l2_subdev *sd = list_entry(v4l2_dev->subdevs.next, 1367 1421 struct v4l2_subdev, list); 1368 1422 struct i2c_client *client = v4l2_get_subdevdata(sd); 1369 - struct resource *reg_res; 1370 1423 1371 - if (irq > 0) 1372 - free_irq(irq, vou_dev); 1373 1424 pm_runtime_disable(&pdev->dev); 1374 1425 video_unregister_device(&vou_dev->vdev); 1375 1426 i2c_put_adapter(client->adapter); 1427 + vb2_dma_contig_cleanup_ctx(vou_dev->alloc_ctx); 1376 1428 v4l2_device_unregister(&vou_dev->v4l2_dev); 1377 - iounmap(vou_dev->base); 1378 - reg_res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 1379 - if (reg_res) 1380 - release_mem_region(reg_res->start, resource_size(reg_res)); 1381 - kfree(vou_dev); 1382 1429 return 0; 1383 1430 } 1384 1431
+48 -57
drivers/media/platform/soc_camera/atmel-isi.c
··· 20 20 #include <linux/kernel.h> 21 21 #include <linux/module.h> 22 22 #include <linux/platform_device.h> 23 + #include <linux/pm_runtime.h> 23 24 #include <linux/slab.h> 24 25 25 26 #include <media/atmel-isi.h> ··· 35 34 #define VID_LIMIT_BYTES (16 * 1024 * 1024) 36 35 #define MIN_FRAME_RATE 15 37 36 #define FRAME_INTERVAL_MILLI_SEC (1000 / MIN_FRAME_RATE) 38 - #define ISI_DEFAULT_MCLK_FREQ 25000000 39 37 40 38 /* Frame buffer descriptor */ 41 39 struct fbd { ··· 82 82 struct completion complete; 83 83 /* ISI peripherial clock */ 84 84 struct clk *pclk; 85 - /* ISI_MCK, feed to camera sensor to generate pixel clock */ 86 - struct clk *mck; 87 85 unsigned int irq; 88 86 89 87 struct isi_platform_data pdata; ··· 384 386 struct atmel_isi *isi = ici->priv; 385 387 int ret; 386 388 389 + pm_runtime_get_sync(ici->v4l2_dev.dev); 390 + 387 391 /* Reset ISI */ 388 392 ret = atmel_isi_wait_status(isi, WAIT_ISI_RESET); 389 393 if (ret < 0) { 390 394 dev_err(icd->parent, "Reset ISI timed out\n"); 395 + pm_runtime_put(ici->v4l2_dev.dev); 391 396 return ret; 392 397 } 393 398 /* Disable all interrupts */ ··· 432 431 time_before(jiffies, timeout)) 433 432 msleep(1); 434 433 435 - if (time_after(jiffies, timeout)) { 434 + if (time_after(jiffies, timeout)) 436 435 dev_err(icd->parent, 437 436 "Timeout waiting for finishing codec request\n"); 438 - return; 439 - } 440 437 441 438 /* Disable interrupts */ 442 439 isi_writel(isi, ISI_INTDIS, ··· 444 445 ret = atmel_isi_wait_status(isi, WAIT_ISI_DISABLE); 445 446 if (ret < 0) 446 447 dev_err(icd->parent, "Disable ISI timed out\n"); 448 + 449 + pm_runtime_put(ici->v4l2_dev.dev); 447 450 } 448 451 449 452 static struct vb2_ops isi_video_qops = { ··· 517 516 if (mf->code != xlate->code) 518 517 return -EINVAL; 519 518 519 + /* Enable PM and peripheral clock before operate isi registers */ 520 + pm_runtime_get_sync(ici->v4l2_dev.dev); 521 + 520 522 ret = configure_geometry(isi, pix->width, pix->height, xlate->code); 523 + 524 + pm_runtime_put(ici->v4l2_dev.dev); 525 + 521 526 if (ret < 0) 522 527 return ret; 523 528 ··· 737 730 icd->devnum); 738 731 } 739 732 740 - /* Called with .host_lock held */ 741 - static int isi_camera_clock_start(struct soc_camera_host *ici) 742 - { 743 - struct atmel_isi *isi = ici->priv; 744 - int ret; 745 - 746 - ret = clk_prepare_enable(isi->pclk); 747 - if (ret) 748 - return ret; 749 - 750 - if (!IS_ERR(isi->mck)) { 751 - ret = clk_prepare_enable(isi->mck); 752 - if (ret) { 753 - clk_disable_unprepare(isi->pclk); 754 - return ret; 755 - } 756 - } 757 - 758 - return 0; 759 - } 760 - 761 - /* Called with .host_lock held */ 762 - static void isi_camera_clock_stop(struct soc_camera_host *ici) 763 - { 764 - struct atmel_isi *isi = ici->priv; 765 - 766 - if (!IS_ERR(isi->mck)) 767 - clk_disable_unprepare(isi->mck); 768 - clk_disable_unprepare(isi->pclk); 769 - } 770 - 771 733 static unsigned int isi_camera_poll(struct file *file, poll_table *pt) 772 734 { 773 735 struct soc_camera_device *icd = file->private_data; ··· 831 855 832 856 cfg1 |= ISI_CFG1_THMASK_BEATS_16; 833 857 858 + /* Enable PM and peripheral clock before operate isi registers */ 859 + pm_runtime_get_sync(ici->v4l2_dev.dev); 860 + 834 861 isi_writel(isi, ISI_CTRL, ISI_CTRL_DIS); 835 862 isi_writel(isi, ISI_CFG1, cfg1); 863 + 864 + pm_runtime_put(ici->v4l2_dev.dev); 836 865 837 866 return 0; 838 867 } ··· 846 865 .owner = THIS_MODULE, 847 866 .add = isi_camera_add_device, 848 867 .remove = isi_camera_remove_device, 849 - .clock_start = isi_camera_clock_start, 850 - .clock_stop = isi_camera_clock_stop, 851 868 .set_fmt = isi_camera_set_fmt, 852 869 .try_fmt = isi_camera_try_fmt, 853 870 .get_formats = isi_camera_get_formats, ··· 868 889 sizeof(struct fbd) * MAX_BUFFER_NUM, 869 890 isi->p_fb_descriptors, 870 891 isi->fb_descriptors_phys); 892 + pm_runtime_disable(&pdev->dev); 871 893 872 894 return 0; 873 895 } ··· 882 902 883 903 /* Default settings for ISI */ 884 904 isi->pdata.full_mode = 1; 885 - isi->pdata.mck_hz = ISI_DEFAULT_MCLK_FREQ; 886 905 isi->pdata.frate = ISI_CFG1_FRATE_CAPTURE_ALL; 887 906 888 907 np = of_graph_get_next_endpoint(np, NULL); ··· 957 978 INIT_LIST_HEAD(&isi->video_buffer_list); 958 979 INIT_LIST_HEAD(&isi->dma_desc_head); 959 980 960 - /* ISI_MCK is the sensor master clock. It should be handled by the 961 - * sensor driver directly, as the ISI has no use for that clock. Make 962 - * the clock optional here while platforms transition to the correct 963 - * model. 964 - */ 965 - isi->mck = devm_clk_get(dev, "isi_mck"); 966 - if (!IS_ERR(isi->mck)) { 967 - /* Set ISI_MCK's frequency, it should be faster than pixel 968 - * clock. 969 - */ 970 - ret = clk_set_rate(isi->mck, isi->pdata.mck_hz); 971 - if (ret < 0) 972 - return ret; 973 - } 974 - 975 981 isi->p_fb_descriptors = dma_alloc_coherent(&pdev->dev, 976 982 sizeof(struct fbd) * MAX_BUFFER_NUM, 977 983 &isi->fb_descriptors_phys, ··· 991 1027 if (isi->pdata.data_width_flags & ISI_DATAWIDTH_10) 992 1028 isi->width_flags |= 1 << 9; 993 1029 994 - isi_writel(isi, ISI_CTRL, ISI_CTRL_DIS); 995 - 996 1030 irq = platform_get_irq(pdev, 0); 997 1031 if (IS_ERR_VALUE(irq)) { 998 1032 ret = irq; ··· 1011 1049 soc_host->v4l2_dev.dev = &pdev->dev; 1012 1050 soc_host->nr = pdev->id; 1013 1051 1052 + pm_suspend_ignore_children(&pdev->dev, true); 1053 + pm_runtime_enable(&pdev->dev); 1054 + 1014 1055 if (isi->pdata.asd_sizes) { 1015 1056 soc_host->asd = isi->pdata.asd; 1016 1057 soc_host->asd_sizes = isi->pdata.asd_sizes; ··· 1027 1062 return 0; 1028 1063 1029 1064 err_register_soc_camera_host: 1065 + pm_runtime_disable(&pdev->dev); 1030 1066 err_req_irq: 1031 1067 err_ioremap: 1032 1068 vb2_dma_contig_cleanup_ctx(isi->alloc_ctx); ··· 1040 1074 return ret; 1041 1075 } 1042 1076 1077 + static int atmel_isi_runtime_suspend(struct device *dev) 1078 + { 1079 + struct soc_camera_host *soc_host = to_soc_camera_host(dev); 1080 + struct atmel_isi *isi = container_of(soc_host, 1081 + struct atmel_isi, soc_host); 1082 + 1083 + clk_disable_unprepare(isi->pclk); 1084 + 1085 + return 0; 1086 + } 1087 + static int atmel_isi_runtime_resume(struct device *dev) 1088 + { 1089 + struct soc_camera_host *soc_host = to_soc_camera_host(dev); 1090 + struct atmel_isi *isi = container_of(soc_host, 1091 + struct atmel_isi, soc_host); 1092 + 1093 + return clk_prepare_enable(isi->pclk); 1094 + } 1095 + 1096 + static const struct dev_pm_ops atmel_isi_dev_pm_ops = { 1097 + SET_RUNTIME_PM_OPS(atmel_isi_runtime_suspend, 1098 + atmel_isi_runtime_resume, NULL) 1099 + }; 1100 + 1043 1101 static const struct of_device_id atmel_isi_of_match[] = { 1044 1102 { .compatible = "atmel,at91sam9g45-isi" }, 1045 1103 { } ··· 1075 1085 .driver = { 1076 1086 .name = "atmel_isi", 1077 1087 .of_match_table = of_match_ptr(atmel_isi_of_match), 1088 + .pm = &atmel_isi_dev_pm_ops, 1078 1089 }, 1079 1090 }; 1080 1091
+14 -2
drivers/media/platform/soc_camera/rcar_vin.c
··· 98 98 #define VNMC_INF_YUV10_BT656 (2 << 16) 99 99 #define VNMC_INF_YUV10_BT601 (3 << 16) 100 100 #define VNMC_INF_YUV16 (5 << 16) 101 + #define VNMC_INF_RGB888 (6 << 16) 101 102 #define VNMC_VUP (1 << 10) 102 103 #define VNMC_IM_ODD (0 << 3) 103 104 #define VNMC_IM_ODD_EVEN (1 << 3) ··· 541 540 unsigned int bytes_per_line; 542 541 int ret; 543 542 543 + if (fmt->fmt.pix.sizeimage < icd->sizeimage) 544 + return -EINVAL; 545 + 544 546 xlate = soc_camera_xlate_by_fourcc(icd, 545 547 fmt->fmt.pix.pixelformat); 546 548 if (!xlate) ··· 593 589 struct soc_camera_device *icd = priv->ici.icd; 594 590 struct rcar_vin_cam *cam = icd->host_priv; 595 591 u32 vnmc, dmr, interrupts; 596 - bool progressive = false, output_is_yuv = false; 592 + bool progressive = false, output_is_yuv = false, input_is_yuv = false; 597 593 598 594 switch (priv->field) { 599 595 case V4L2_FIELD_TOP: ··· 627 623 case MEDIA_BUS_FMT_YUYV8_1X16: 628 624 /* BT.601/BT.1358 16bit YCbCr422 */ 629 625 vnmc |= VNMC_INF_YUV16; 626 + input_is_yuv = true; 630 627 break; 631 628 case MEDIA_BUS_FMT_YUYV8_2X8: 632 629 /* BT.656 8bit YCbCr422 or BT.601 8bit YCbCr422 */ 633 630 vnmc |= priv->pdata_flags & RCAR_VIN_BT656 ? 634 631 VNMC_INF_YUV8_BT656 : VNMC_INF_YUV8_BT601; 632 + input_is_yuv = true; 633 + break; 634 + case MEDIA_BUS_FMT_RGB888_1X24: 635 + vnmc |= VNMC_INF_RGB888; 635 636 break; 636 637 case MEDIA_BUS_FMT_YUYV10_2X10: 637 638 /* BT.656 10bit YCbCr422 or BT.601 10bit YCbCr422 */ 638 639 vnmc |= priv->pdata_flags & RCAR_VIN_BT656 ? 639 640 VNMC_INF_YUV10_BT656 : VNMC_INF_YUV10_BT601; 641 + input_is_yuv = true; 640 642 break; 641 643 default: 642 644 break; ··· 686 676 vnmc |= VNMC_VUP; 687 677 688 678 /* If input and output use the same colorspace, use bypass mode */ 689 - if (output_is_yuv) 679 + if (input_is_yuv == output_is_yuv) 690 680 vnmc |= VNMC_BPS; 691 681 692 682 /* progressive or interlaced mode */ ··· 1433 1423 case MEDIA_BUS_FMT_YUYV8_1X16: 1434 1424 case MEDIA_BUS_FMT_YUYV8_2X8: 1435 1425 case MEDIA_BUS_FMT_YUYV10_2X10: 1426 + case MEDIA_BUS_FMT_RGB888_1X24: 1436 1427 if (cam->extra_fmt) 1437 1428 break; 1438 1429 ··· 1794 1783 strlcpy(cap->card, "R_Car_VIN", sizeof(cap->card)); 1795 1784 cap->device_caps = V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_STREAMING; 1796 1785 cap->capabilities = cap->device_caps | V4L2_CAP_DEVICE_CAPS; 1786 + snprintf(cap->bus_info, sizeof(cap->bus_info), "platform:%s%d", DRV_NAME, ici->nr); 1797 1787 1798 1788 return 0; 1799 1789 }
+3
drivers/media/platform/soc_camera/sh_mobile_ceu_camera.c
··· 1665 1665 struct v4l2_capability *cap) 1666 1666 { 1667 1667 strlcpy(cap->card, "SuperH_Mobile_CEU", sizeof(cap->card)); 1668 + strlcpy(cap->driver, "sh_mobile_ceu", sizeof(cap->driver)); 1669 + strlcpy(cap->bus_info, "platform:sh_mobile_ceu", sizeof(cap->bus_info)); 1668 1670 cap->device_caps = V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_STREAMING; 1669 1671 cap->capabilities = cap->device_caps | V4L2_CAP_DEVICE_CAPS; 1670 1672 ··· 1775 1773 pcdev->max_height = pcdev->pdata->max_height; 1776 1774 pcdev->flags = pcdev->pdata->flags; 1777 1775 } 1776 + pcdev->field = V4L2_FIELD_NONE; 1778 1777 1779 1778 if (!pcdev->max_width) { 1780 1779 unsigned int v;
+29 -19
drivers/media/platform/soc_camera/soc_camera.c
··· 309 309 static int soc_camera_enum_input(struct file *file, void *priv, 310 310 struct v4l2_input *inp) 311 311 { 312 + struct soc_camera_device *icd = file->private_data; 313 + 312 314 if (inp->index != 0) 313 315 return -EINVAL; 314 316 315 317 /* default is camera */ 316 318 inp->type = V4L2_INPUT_TYPE_CAMERA; 319 + inp->std = icd->vdev->tvnorms; 317 320 strcpy(inp->name, "Camera"); 318 321 319 322 return 0; ··· 384 381 ret = vb2_reqbufs(&icd->vb2_vidq, p); 385 382 } 386 383 387 - if (!ret && !icd->streamer) 388 - icd->streamer = file; 389 - 384 + if (!ret) 385 + icd->streamer = p->count ? file : NULL; 390 386 return ret; 391 387 } 392 388 ··· 442 440 { 443 441 struct soc_camera_device *icd = file->private_data; 444 442 struct soc_camera_host *ici = to_soc_camera_host(icd->parent); 443 + int ret; 445 444 446 445 /* videobuf2 only */ 447 446 if (ici->ops->init_videobuf) 448 - return -EINVAL; 449 - else 450 - return vb2_create_bufs(&icd->vb2_vidq, create); 447 + return -ENOTTY; 448 + 449 + if (icd->streamer && icd->streamer != file) 450 + return -EBUSY; 451 + 452 + ret = vb2_create_bufs(&icd->vb2_vidq, create); 453 + if (!ret) 454 + icd->streamer = file; 455 + return ret; 451 456 } 452 457 453 458 static int soc_camera_prepare_buf(struct file *file, void *priv, ··· 476 467 struct soc_camera_device *icd = file->private_data; 477 468 struct soc_camera_host *ici = to_soc_camera_host(icd->parent); 478 469 479 - if (icd->streamer != file) 480 - return -EBUSY; 481 - 482 470 /* videobuf2 only */ 483 471 if (ici->ops->init_videobuf) 484 - return -EINVAL; 485 - else 486 - return vb2_expbuf(&icd->vb2_vidq, p); 472 + return -ENOTTY; 473 + 474 + if (icd->streamer && icd->streamer != file) 475 + return -EBUSY; 476 + return vb2_expbuf(&icd->vb2_vidq, p); 487 477 } 488 478 489 479 /* Always entered with .host_lock held */ ··· 788 780 struct soc_camera_host *ici = to_soc_camera_host(icd->parent); 789 781 790 782 mutex_lock(&ici->host_lock); 783 + if (icd->streamer == file) { 784 + if (ici->ops->init_videobuf2) 785 + vb2_queue_release(&icd->vb2_vidq); 786 + icd->streamer = NULL; 787 + } 791 788 icd->use_count--; 792 789 if (!icd->use_count) { 793 790 pm_runtime_suspend(&icd->vdev->dev); 794 791 pm_runtime_disable(&icd->vdev->dev); 795 792 796 - if (ici->ops->init_videobuf2) 797 - vb2_queue_release(&icd->vb2_vidq); 798 793 __soc_camera_power_off(icd); 799 794 800 795 soc_camera_remove_device(icd); 801 796 } 802 797 803 - if (icd->streamer == file) 804 - icd->streamer = NULL; 805 798 mutex_unlock(&ici->host_lock); 806 799 807 800 module_put(ici->ops->owner); ··· 1001 992 struct soc_camera_device *icd = file->private_data; 1002 993 struct v4l2_subdev *sd = soc_camera_to_subdev(icd); 1003 994 struct soc_camera_host *ici = to_soc_camera_host(icd->parent); 995 + int ret; 1004 996 1005 997 WARN_ON(priv != file->private_data); 1006 998 ··· 1016 1006 * remaining buffers. When the last buffer is freed, stop capture 1017 1007 */ 1018 1008 if (ici->ops->init_videobuf) 1019 - videobuf_streamoff(&icd->vb_vidq); 1009 + ret = videobuf_streamoff(&icd->vb_vidq); 1020 1010 else 1021 - vb2_streamoff(&icd->vb2_vidq, i); 1011 + ret = vb2_streamoff(&icd->vb2_vidq, i); 1022 1012 1023 1013 v4l2_subdev_call(sd, video, s_stream, 0); 1024 1014 1025 - return 0; 1015 + return ret; 1026 1016 } 1027 1017 1028 1018 static int soc_camera_cropcap(struct file *file, void *fh,
+8
drivers/media/platform/sti/bdisp/bdisp-debug.c
··· 116 116 case BDISP_RGB565: 117 117 seq_puts(s, "RGB565 - "); 118 118 break; 119 + case BDISP_RGB888: 120 + seq_puts(s, "RGB888 - "); 121 + break; 119 122 case BDISP_XRGB8888: 120 123 seq_puts(s, "xRGB888 - "); 121 124 break; ··· 187 184 switch ((val & BLT_TTY_COL_MASK) >> BLT_TTY_COL_SHIFT) { 188 185 case BDISP_RGB565: 189 186 seq_puts(s, "RGB565 - "); 187 + break; 188 + case BDISP_RGB888: 189 + seq_puts(s, "RGB888 - "); 190 190 break; 191 191 case BDISP_XRGB8888: 192 192 seq_puts(s, "xRGB888 - "); ··· 426 420 return "NV12"; 427 421 case V4L2_PIX_FMT_RGB565: 428 422 return "RGB16"; 423 + case V4L2_PIX_FMT_RGB24: 424 + return "RGB24"; 429 425 case V4L2_PIX_FMT_XBGR32: 430 426 return "XRGB"; 431 427 case V4L2_PIX_FMT_ABGR32:
+6 -6
drivers/media/platform/sti/bdisp/bdisp-hw.c
··· 336 336 337 337 src_w = ctx->src.crop.width; 338 338 src_h = ctx->src.crop.height; 339 - dst_w = ctx->dst.width; 340 - dst_h = ctx->dst.height; 339 + dst_w = ctx->dst.crop.width; 340 + dst_h = ctx->dst.crop.height; 341 341 342 342 if (bdisp_hw_get_inc(src_w, dst_w, h_inc) || 343 343 bdisp_hw_get_inc(src_h, dst_h, v_inc)) { ··· 483 483 src_rect.width -= src_x_offset; 484 484 src_rect.width = min_t(__s32, MAX_SRC_WIDTH, src_rect.width); 485 485 486 - dst_x_offset = (src_x_offset * dst->width) / ctx->src.crop.width; 486 + dst_x_offset = (src_x_offset * dst_width) / ctx->src.crop.width; 487 487 dst_rect.left += dst_x_offset; 488 - dst_rect.width = (src_rect.width * dst->width) / ctx->src.crop.width; 488 + dst_rect.width = (src_rect.width * dst_width) / ctx->src.crop.width; 489 489 490 490 /* General */ 491 491 src_fmt = src->fmt->pixelformat; ··· 768 768 /* Allocate memory if not done yet */ 769 769 if (!copy_node[i]) { 770 770 copy_node[i] = devm_kzalloc(ctx->bdisp_dev->dev, 771 - sizeof(*copy_node), 771 + sizeof(*copy_node[i]), 772 772 GFP_KERNEL); 773 773 if (!copy_node[i]) 774 774 return; 775 775 } 776 - copy_node[i] = node[i]; 776 + *copy_node[i] = *node[i]; 777 777 } 778 778 } 779 779
+51 -25
drivers/media/platform/sti/bdisp/bdisp-v4l2.c
··· 851 851 struct bdisp_frame *frame; 852 852 struct bdisp_ctx *ctx = fh_to_ctx(fh); 853 853 854 - if (s->type != V4L2_BUF_TYPE_VIDEO_OUTPUT) { 855 - /* Composing / capture is not supported */ 856 - dev_dbg(ctx->bdisp_dev->dev, "Not supported for capture\n"); 857 - return -EINVAL; 858 - } 859 - 860 854 frame = ctx_get_frame(ctx, s->type); 861 855 if (IS_ERR(frame)) { 862 856 dev_err(ctx->bdisp_dev->dev, "Invalid frame (%p)\n", frame); 863 857 return PTR_ERR(frame); 864 858 } 865 859 866 - switch (s->target) { 867 - case V4L2_SEL_TGT_CROP: 868 - /* cropped frame */ 869 - s->r = frame->crop; 860 + switch (s->type) { 861 + case V4L2_BUF_TYPE_VIDEO_OUTPUT: 862 + switch (s->target) { 863 + case V4L2_SEL_TGT_CROP: 864 + /* cropped frame */ 865 + s->r = frame->crop; 866 + break; 867 + case V4L2_SEL_TGT_CROP_DEFAULT: 868 + case V4L2_SEL_TGT_CROP_BOUNDS: 869 + /* complete frame */ 870 + s->r.left = 0; 871 + s->r.top = 0; 872 + s->r.width = frame->width; 873 + s->r.height = frame->height; 874 + break; 875 + default: 876 + dev_err(ctx->bdisp_dev->dev, "Invalid target\n"); 877 + return -EINVAL; 878 + } 870 879 break; 871 - case V4L2_SEL_TGT_CROP_DEFAULT: 872 - case V4L2_SEL_TGT_CROP_BOUNDS: 873 - /* complete frame */ 874 - s->r.left = 0; 875 - s->r.top = 0; 876 - s->r.width = frame->width; 877 - s->r.height = frame->height; 880 + 881 + case V4L2_BUF_TYPE_VIDEO_CAPTURE: 882 + switch (s->target) { 883 + case V4L2_SEL_TGT_COMPOSE: 884 + case V4L2_SEL_TGT_COMPOSE_PADDED: 885 + /* composed (cropped) frame */ 886 + s->r = frame->crop; 887 + break; 888 + case V4L2_SEL_TGT_COMPOSE_DEFAULT: 889 + case V4L2_SEL_TGT_COMPOSE_BOUNDS: 890 + /* complete frame */ 891 + s->r.left = 0; 892 + s->r.top = 0; 893 + s->r.width = frame->width; 894 + s->r.height = frame->height; 895 + break; 896 + default: 897 + dev_err(ctx->bdisp_dev->dev, "Invalid target\n"); 898 + return -EINVAL; 899 + } 878 900 break; 901 + 879 902 default: 880 - dev_dbg(ctx->bdisp_dev->dev, "Invalid target\n"); 903 + dev_err(ctx->bdisp_dev->dev, "Invalid type\n"); 881 904 return -EINVAL; 882 905 } 883 906 ··· 929 906 struct bdisp_frame *frame; 930 907 struct bdisp_ctx *ctx = fh_to_ctx(fh); 931 908 struct v4l2_rect *in, out; 909 + bool valid = false; 932 910 933 - if (s->type != V4L2_BUF_TYPE_VIDEO_OUTPUT) { 934 - /* Composing / capture is not supported */ 935 - dev_dbg(ctx->bdisp_dev->dev, "Not supported for capture\n"); 936 - return -EINVAL; 937 - } 911 + if ((s->type == V4L2_BUF_TYPE_VIDEO_OUTPUT) && 912 + (s->target == V4L2_SEL_TGT_CROP)) 913 + valid = true; 938 914 939 - if (s->target != V4L2_SEL_TGT_CROP) { 940 - dev_dbg(ctx->bdisp_dev->dev, "Invalid target\n"); 915 + if ((s->type == V4L2_BUF_TYPE_VIDEO_CAPTURE) && 916 + (s->target == V4L2_SEL_TGT_COMPOSE)) 917 + valid = true; 918 + 919 + if (!valid) { 920 + dev_err(ctx->bdisp_dev->dev, "Invalid type / target\n"); 941 921 return -EINVAL; 942 922 } 943 923
+28
drivers/media/platform/sti/c8sectpfe/Kconfig
··· 1 + config DVB_C8SECTPFE 2 + tristate "STMicroelectronics C8SECTPFE DVB support" 3 + depends on PINCTRL && DVB_CORE && I2C 4 + depends on ARCH_STI || ARCH_MULTIPLATFORM || COMPILE_TEST 5 + select FW_LOADER 6 + select FW_LOADER_USER_HELPER_FALLBACK 7 + select DEBUG_FS 8 + select DVB_LNBP21 if MEDIA_SUBDRV_AUTOSELECT 9 + select DVB_STV090x if MEDIA_SUBDRV_AUTOSELECT 10 + select DVB_STB6100 if MEDIA_SUBDRV_AUTOSELECT 11 + select DVB_STV6110 if MEDIA_SUBDRV_AUTOSELECT 12 + select DVB_STV0900 if MEDIA_SUBDRV_AUTOSELECT 13 + select DVB_STV0367 if MEDIA_SUBDRV_AUTOSELECT 14 + select MEDIA_TUNER_TDA18212 if MEDIA_SUBDRV_AUTOSELECT 15 + 16 + ---help--- 17 + This adds support for DVB front-end cards connected 18 + to TS inputs of STiH407/410 SoC. 19 + 20 + The driver currently supports C8SECTPFE's TS input block, 21 + memdma engine, and HW PID filtering. 22 + 23 + Supported DVB front-end cards are: 24 + - STMicroelectronics DVB-T B2100A (STV0367 + TDA18212) 25 + - STMicroelectronics DVB-S/S2 STV0903 + STV6110 + LNBP24 board 26 + 27 + To compile this driver as a module, choose M here: the 28 + module will be called c8sectpfe.
+9
drivers/media/platform/sti/c8sectpfe/Makefile
··· 1 + c8sectpfe-y += c8sectpfe-core.o c8sectpfe-common.o c8sectpfe-dvb.o \ 2 + c8sectpfe-debugfs.o 3 + 4 + obj-$(CONFIG_DVB_C8SECTPFE) += c8sectpfe.o 5 + 6 + ccflags-y += -Idrivers/media/i2c 7 + ccflags-y += -Idrivers/media/common 8 + ccflags-y += -Idrivers/media/dvb-core/ -Idrivers/media/dvb-frontends/ \ 9 + -Idrivers/media/tuners/
+265
drivers/media/platform/sti/c8sectpfe/c8sectpfe-common.c
··· 1 + /* 2 + * c8sectpfe-common.c - C8SECTPFE STi DVB driver 3 + * 4 + * Copyright (c) STMicroelectronics 2015 5 + * 6 + * Author: Peter Griffin <peter.griffin@linaro.org> 7 + * 8 + * This program is free software; you can redistribute it and/or 9 + * modify it under the terms of the GNU General Public License as 10 + * published by the Free Software Foundation; either version 2 of 11 + * the License, or (at your option) any later version. 12 + */ 13 + #include <linux/completion.h> 14 + #include <linux/delay.h> 15 + #include <linux/device.h> 16 + #include <linux/dvb/dmx.h> 17 + #include <linux/errno.h> 18 + #include <linux/init.h> 19 + #include <linux/interrupt.h> 20 + #include <linux/io.h> 21 + #include <linux/ioport.h> 22 + #include <linux/module.h> 23 + #include <linux/slab.h> 24 + #include <linux/time.h> 25 + #include <linux/wait.h> 26 + 27 + #include "dmxdev.h" 28 + #include "dvbdev.h" 29 + #include "dvb_demux.h" 30 + #include "dvb_frontend.h" 31 + #include "dvb_net.h" 32 + 33 + #include "c8sectpfe-common.h" 34 + #include "c8sectpfe-core.h" 35 + #include "c8sectpfe-dvb.h" 36 + 37 + static int register_dvb(struct stdemux *demux, struct dvb_adapter *adap, 38 + void *start_feed, void *stop_feed, 39 + struct c8sectpfei *fei) 40 + { 41 + int result; 42 + 43 + demux->dvb_demux.dmx.capabilities = DMX_TS_FILTERING | 44 + DMX_SECTION_FILTERING | 45 + DMX_MEMORY_BASED_FILTERING; 46 + 47 + demux->dvb_demux.priv = demux; 48 + demux->dvb_demux.filternum = C8SECTPFE_MAXCHANNEL; 49 + demux->dvb_demux.feednum = C8SECTPFE_MAXCHANNEL; 50 + 51 + demux->dvb_demux.start_feed = start_feed; 52 + demux->dvb_demux.stop_feed = stop_feed; 53 + demux->dvb_demux.write_to_decoder = NULL; 54 + 55 + result = dvb_dmx_init(&demux->dvb_demux); 56 + if (result < 0) { 57 + dev_err(fei->dev, "dvb_dmx_init failed (errno = %d)\n", 58 + result); 59 + goto err_dmx; 60 + } 61 + 62 + demux->dmxdev.filternum = demux->dvb_demux.filternum; 63 + demux->dmxdev.demux = &demux->dvb_demux.dmx; 64 + demux->dmxdev.capabilities = 0; 65 + 66 + result = dvb_dmxdev_init(&demux->dmxdev, adap); 67 + if (result < 0) { 68 + dev_err(fei->dev, "dvb_dmxdev_init failed (errno = %d)\n", 69 + result); 70 + 71 + goto err_dmxdev; 72 + } 73 + 74 + demux->hw_frontend.source = DMX_FRONTEND_0 + demux->tsin_index; 75 + 76 + result = demux->dvb_demux.dmx.add_frontend(&demux->dvb_demux.dmx, 77 + &demux->hw_frontend); 78 + if (result < 0) { 79 + dev_err(fei->dev, "add_frontend failed (errno = %d)\n", result); 80 + goto err_fe_hw; 81 + } 82 + 83 + demux->mem_frontend.source = DMX_MEMORY_FE; 84 + result = demux->dvb_demux.dmx.add_frontend(&demux->dvb_demux.dmx, 85 + &demux->mem_frontend); 86 + if (result < 0) { 87 + dev_err(fei->dev, "add_frontend failed (%d)\n", result); 88 + goto err_fe_mem; 89 + } 90 + 91 + result = demux->dvb_demux.dmx.connect_frontend(&demux->dvb_demux.dmx, 92 + &demux->hw_frontend); 93 + if (result < 0) { 94 + dev_err(fei->dev, "connect_frontend (%d)\n", result); 95 + goto err_fe_con; 96 + } 97 + 98 + return 0; 99 + 100 + err_fe_con: 101 + demux->dvb_demux.dmx.remove_frontend(&demux->dvb_demux.dmx, 102 + &demux->mem_frontend); 103 + err_fe_mem: 104 + demux->dvb_demux.dmx.remove_frontend(&demux->dvb_demux.dmx, 105 + &demux->hw_frontend); 106 + err_fe_hw: 107 + dvb_dmxdev_release(&demux->dmxdev); 108 + err_dmxdev: 109 + dvb_dmx_release(&demux->dvb_demux); 110 + err_dmx: 111 + return result; 112 + 113 + } 114 + 115 + static void unregister_dvb(struct stdemux *demux) 116 + { 117 + 118 + demux->dvb_demux.dmx.remove_frontend(&demux->dvb_demux.dmx, 119 + &demux->mem_frontend); 120 + 121 + demux->dvb_demux.dmx.remove_frontend(&demux->dvb_demux.dmx, 122 + &demux->hw_frontend); 123 + 124 + dvb_dmxdev_release(&demux->dmxdev); 125 + 126 + dvb_dmx_release(&demux->dvb_demux); 127 + } 128 + 129 + static struct c8sectpfe *c8sectpfe_create(struct c8sectpfei *fei, 130 + void *start_feed, 131 + void *stop_feed) 132 + { 133 + struct c8sectpfe *c8sectpfe; 134 + int result; 135 + int i, j; 136 + 137 + short int ids[] = { -1 }; 138 + 139 + c8sectpfe = kzalloc(sizeof(struct c8sectpfe), GFP_KERNEL); 140 + if (!c8sectpfe) 141 + goto err1; 142 + 143 + mutex_init(&c8sectpfe->lock); 144 + 145 + c8sectpfe->device = fei->dev; 146 + 147 + result = dvb_register_adapter(&c8sectpfe->adapter, "STi c8sectpfe", 148 + THIS_MODULE, fei->dev, ids); 149 + if (result < 0) { 150 + dev_err(fei->dev, "dvb_register_adapter failed (errno = %d)\n", 151 + result); 152 + goto err2; 153 + } 154 + 155 + c8sectpfe->adapter.priv = fei; 156 + 157 + for (i = 0; i < fei->tsin_count; i++) { 158 + 159 + c8sectpfe->demux[i].tsin_index = i; 160 + c8sectpfe->demux[i].c8sectpfei = fei; 161 + 162 + result = register_dvb(&c8sectpfe->demux[i], &c8sectpfe->adapter, 163 + start_feed, stop_feed, fei); 164 + if (result < 0) { 165 + dev_err(fei->dev, 166 + "register_dvb feed=%d failed (errno = %d)\n", 167 + result, i); 168 + 169 + /* we take a all or nothing approach */ 170 + for (j = 0; j < i; j++) 171 + unregister_dvb(&c8sectpfe->demux[j]); 172 + goto err3; 173 + } 174 + } 175 + 176 + c8sectpfe->num_feeds = fei->tsin_count; 177 + 178 + return c8sectpfe; 179 + err3: 180 + dvb_unregister_adapter(&c8sectpfe->adapter); 181 + err2: 182 + kfree(c8sectpfe); 183 + err1: 184 + return NULL; 185 + }; 186 + 187 + static void c8sectpfe_delete(struct c8sectpfe *c8sectpfe) 188 + { 189 + int i; 190 + 191 + if (!c8sectpfe) 192 + return; 193 + 194 + for (i = 0; i < c8sectpfe->num_feeds; i++) 195 + unregister_dvb(&c8sectpfe->demux[i]); 196 + 197 + dvb_unregister_adapter(&c8sectpfe->adapter); 198 + 199 + kfree(c8sectpfe); 200 + }; 201 + 202 + void c8sectpfe_tuner_unregister_frontend(struct c8sectpfe *c8sectpfe, 203 + struct c8sectpfei *fei) 204 + { 205 + int n; 206 + struct channel_info *tsin; 207 + 208 + for (n = 0; n < fei->tsin_count; n++) { 209 + 210 + tsin = fei->channel_data[n]; 211 + 212 + if (tsin && tsin->frontend) { 213 + dvb_unregister_frontend(tsin->frontend); 214 + dvb_frontend_detach(tsin->frontend); 215 + } 216 + 217 + if (tsin && tsin->i2c_adapter) 218 + i2c_put_adapter(tsin->i2c_adapter); 219 + 220 + if (tsin && tsin->i2c_client) { 221 + if (tsin->i2c_client->dev.driver->owner) 222 + module_put(tsin->i2c_client->dev.driver->owner); 223 + i2c_unregister_device(tsin->i2c_client); 224 + } 225 + } 226 + 227 + c8sectpfe_delete(c8sectpfe); 228 + }; 229 + 230 + int c8sectpfe_tuner_register_frontend(struct c8sectpfe **c8sectpfe, 231 + struct c8sectpfei *fei, 232 + void *start_feed, 233 + void *stop_feed) 234 + { 235 + struct channel_info *tsin; 236 + struct dvb_frontend *frontend; 237 + int n, res; 238 + 239 + *c8sectpfe = c8sectpfe_create(fei, start_feed, stop_feed); 240 + if (!*c8sectpfe) 241 + return -ENOMEM; 242 + 243 + for (n = 0; n < fei->tsin_count; n++) { 244 + tsin = fei->channel_data[n]; 245 + 246 + res = c8sectpfe_frontend_attach(&frontend, *c8sectpfe, tsin, n); 247 + if (res) 248 + goto err; 249 + 250 + res = dvb_register_frontend(&c8sectpfe[0]->adapter, frontend); 251 + if (res < 0) { 252 + dev_err(fei->dev, "dvb_register_frontend failed (%d)\n", 253 + res); 254 + goto err; 255 + } 256 + 257 + tsin->frontend = frontend; 258 + } 259 + 260 + return 0; 261 + 262 + err: 263 + c8sectpfe_tuner_unregister_frontend(*c8sectpfe, fei); 264 + return res; 265 + }
+64
drivers/media/platform/sti/c8sectpfe/c8sectpfe-common.h
··· 1 + /* 2 + * c8sectpfe-common.h - C8SECTPFE STi DVB driver 3 + * 4 + * Copyright (c) STMicroelectronics 2015 5 + * 6 + * Author: Peter Griffin <peter.griffin@linaro.org> 7 + * 8 + * This program is free software; you can redistribute it and/or 9 + * modify it under the terms of the GNU General Public License as 10 + * published by the Free Software Foundation; either version 2 of 11 + * the License, or (at your option) any later version. 12 + */ 13 + #ifndef _C8SECTPFE_COMMON_H_ 14 + #define _C8SECTPFE_COMMON_H_ 15 + 16 + #include <linux/dvb/dmx.h> 17 + #include <linux/dvb/frontend.h> 18 + #include <linux/gpio.h> 19 + #include <linux/version.h> 20 + 21 + #include "dmxdev.h" 22 + #include "dvb_demux.h" 23 + #include "dvb_frontend.h" 24 + #include "dvb_net.h" 25 + 26 + /* Maximum number of channels */ 27 + #define C8SECTPFE_MAXADAPTER (4) 28 + #define C8SECTPFE_MAXCHANNEL 64 29 + #define STPTI_MAXCHANNEL 64 30 + 31 + #define MAX_INPUTBLOCKS 7 32 + 33 + struct c8sectpfe; 34 + struct stdemux; 35 + 36 + struct stdemux { 37 + struct dvb_demux dvb_demux; 38 + struct dmxdev dmxdev; 39 + struct dmx_frontend hw_frontend; 40 + struct dmx_frontend mem_frontend; 41 + int tsin_index; 42 + int running_feed_count; 43 + struct c8sectpfei *c8sectpfei; 44 + }; 45 + 46 + struct c8sectpfe { 47 + struct stdemux demux[MAX_INPUTBLOCKS]; 48 + struct mutex lock; 49 + struct dvb_adapter adapter; 50 + struct device *device; 51 + int mapping; 52 + int num_feeds; 53 + }; 54 + 55 + /* Channel registration */ 56 + int c8sectpfe_tuner_register_frontend(struct c8sectpfe **c8sectpfe, 57 + struct c8sectpfei *fei, 58 + void *start_feed, 59 + void *stop_feed); 60 + 61 + void c8sectpfe_tuner_unregister_frontend(struct c8sectpfe *c8sectpfe, 62 + struct c8sectpfei *fei); 63 + 64 + #endif
+1236
drivers/media/platform/sti/c8sectpfe/c8sectpfe-core.c
··· 1 + /* 2 + * c8sectpfe-core.c - C8SECTPFE STi DVB driver 3 + * 4 + * Copyright (c) STMicroelectronics 2015 5 + * 6 + * Author:Peter Bennett <peter.bennett@st.com> 7 + * Peter Griffin <peter.griffin@linaro.org> 8 + * 9 + * This program is free software; you can redistribute it and/or 10 + * modify it under the terms of the GNU General Public License as 11 + * published by the Free Software Foundation; either version 2 of 12 + * the License, or (at your option) any later version. 13 + */ 14 + #include <linux/atomic.h> 15 + #include <linux/clk.h> 16 + #include <linux/completion.h> 17 + #include <linux/delay.h> 18 + #include <linux/device.h> 19 + #include <linux/dma-mapping.h> 20 + #include <linux/dvb/dmx.h> 21 + #include <linux/dvb/frontend.h> 22 + #include <linux/errno.h> 23 + #include <linux/firmware.h> 24 + #include <linux/init.h> 25 + #include <linux/interrupt.h> 26 + #include <linux/io.h> 27 + #include <linux/module.h> 28 + #include <linux/of_gpio.h> 29 + #include <linux/of_platform.h> 30 + #include <linux/platform_device.h> 31 + #include <linux/usb.h> 32 + #include <linux/slab.h> 33 + #include <linux/time.h> 34 + #include <linux/version.h> 35 + #include <linux/wait.h> 36 + #include <linux/pinctrl/pinctrl.h> 37 + 38 + #include "c8sectpfe-core.h" 39 + #include "c8sectpfe-common.h" 40 + #include "c8sectpfe-debugfs.h" 41 + #include "dmxdev.h" 42 + #include "dvb_demux.h" 43 + #include "dvb_frontend.h" 44 + #include "dvb_net.h" 45 + 46 + #define FIRMWARE_MEMDMA "pti_memdma_h407.elf" 47 + MODULE_FIRMWARE(FIRMWARE_MEMDMA); 48 + 49 + #define PID_TABLE_SIZE 1024 50 + #define POLL_MSECS 50 51 + 52 + static int load_c8sectpfe_fw_step1(struct c8sectpfei *fei); 53 + 54 + #define TS_PKT_SIZE 188 55 + #define HEADER_SIZE (4) 56 + #define PACKET_SIZE (TS_PKT_SIZE+HEADER_SIZE) 57 + 58 + #define FEI_ALIGNMENT (32) 59 + /* hw requires minimum of 8*PACKET_SIZE and padded to 8byte boundary */ 60 + #define FEI_BUFFER_SIZE (8*PACKET_SIZE*340) 61 + 62 + #define FIFO_LEN 1024 63 + 64 + static void c8sectpfe_timer_interrupt(unsigned long ac8sectpfei) 65 + { 66 + struct c8sectpfei *fei = (struct c8sectpfei *)ac8sectpfei; 67 + struct channel_info *channel; 68 + int chan_num; 69 + 70 + /* iterate through input block channels */ 71 + for (chan_num = 0; chan_num < fei->tsin_count; chan_num++) { 72 + channel = fei->channel_data[chan_num]; 73 + 74 + /* is this descriptor initialised and TP enabled */ 75 + if (channel->irec && readl(channel->irec + DMA_PRDS_TPENABLE)) 76 + tasklet_schedule(&channel->tsklet); 77 + } 78 + 79 + fei->timer.expires = jiffies + msecs_to_jiffies(POLL_MSECS); 80 + add_timer(&fei->timer); 81 + } 82 + 83 + static void channel_swdemux_tsklet(unsigned long data) 84 + { 85 + struct channel_info *channel = (struct channel_info *)data; 86 + struct c8sectpfei *fei = channel->fei; 87 + unsigned long wp, rp; 88 + int pos, num_packets, n, size; 89 + u8 *buf; 90 + 91 + if (unlikely(!channel || !channel->irec)) 92 + return; 93 + 94 + wp = readl(channel->irec + DMA_PRDS_BUSWP_TP(0)); 95 + rp = readl(channel->irec + DMA_PRDS_BUSRP_TP(0)); 96 + 97 + pos = rp - channel->back_buffer_busaddr; 98 + 99 + /* has it wrapped */ 100 + if (wp < rp) 101 + wp = channel->back_buffer_busaddr + FEI_BUFFER_SIZE; 102 + 103 + size = wp - rp; 104 + num_packets = size / PACKET_SIZE; 105 + 106 + /* manage cache so data is visible to CPU */ 107 + dma_sync_single_for_cpu(fei->dev, 108 + rp, 109 + size, 110 + DMA_FROM_DEVICE); 111 + 112 + buf = (u8 *) channel->back_buffer_aligned; 113 + 114 + dev_dbg(fei->dev, 115 + "chan=%d channel=%p num_packets = %d, buf = %p, pos = 0x%x\n\t" 116 + "rp=0x%lx, wp=0x%lx\n", 117 + channel->tsin_id, channel, num_packets, buf, pos, rp, wp); 118 + 119 + for (n = 0; n < num_packets; n++) { 120 + dvb_dmx_swfilter_packets( 121 + &fei->c8sectpfe[0]-> 122 + demux[channel->demux_mapping].dvb_demux, 123 + &buf[pos], 1); 124 + 125 + pos += PACKET_SIZE; 126 + } 127 + 128 + /* advance the read pointer */ 129 + if (wp == (channel->back_buffer_busaddr + FEI_BUFFER_SIZE)) 130 + writel(channel->back_buffer_busaddr, channel->irec + 131 + DMA_PRDS_BUSRP_TP(0)); 132 + else 133 + writel(wp, channel->irec + DMA_PRDS_BUSWP_TP(0)); 134 + } 135 + 136 + static int c8sectpfe_start_feed(struct dvb_demux_feed *dvbdmxfeed) 137 + { 138 + struct dvb_demux *demux = dvbdmxfeed->demux; 139 + struct stdemux *stdemux = (struct stdemux *)demux->priv; 140 + struct c8sectpfei *fei = stdemux->c8sectpfei; 141 + struct channel_info *channel; 142 + u32 tmp; 143 + unsigned long *bitmap; 144 + 145 + switch (dvbdmxfeed->type) { 146 + case DMX_TYPE_TS: 147 + break; 148 + case DMX_TYPE_SEC: 149 + break; 150 + default: 151 + dev_err(fei->dev, "%s:%d Error bailing\n" 152 + , __func__, __LINE__); 153 + return -EINVAL; 154 + } 155 + 156 + if (dvbdmxfeed->type == DMX_TYPE_TS) { 157 + switch (dvbdmxfeed->pes_type) { 158 + case DMX_PES_VIDEO: 159 + case DMX_PES_AUDIO: 160 + case DMX_PES_TELETEXT: 161 + case DMX_PES_PCR: 162 + case DMX_PES_OTHER: 163 + break; 164 + default: 165 + dev_err(fei->dev, "%s:%d Error bailing\n" 166 + , __func__, __LINE__); 167 + return -EINVAL; 168 + } 169 + } 170 + 171 + if (!atomic_read(&fei->fw_loaded)) { 172 + dev_err(fei->dev, "%s: c8sectpfe fw not loaded\n", __func__); 173 + return -EINVAL; 174 + } 175 + 176 + mutex_lock(&fei->lock); 177 + 178 + channel = fei->channel_data[stdemux->tsin_index]; 179 + 180 + bitmap = (unsigned long *) channel->pid_buffer_aligned; 181 + 182 + /* 8192 is a special PID */ 183 + if (dvbdmxfeed->pid == 8192) { 184 + tmp = readl(fei->io + C8SECTPFE_IB_PID_SET(channel->tsin_id)); 185 + tmp &= ~C8SECTPFE_PID_ENABLE; 186 + writel(tmp, fei->io + C8SECTPFE_IB_PID_SET(channel->tsin_id)); 187 + 188 + } else { 189 + bitmap_set(bitmap, dvbdmxfeed->pid, 1); 190 + } 191 + 192 + /* manage cache so PID bitmap is visible to HW */ 193 + dma_sync_single_for_device(fei->dev, 194 + channel->pid_buffer_busaddr, 195 + PID_TABLE_SIZE, 196 + DMA_TO_DEVICE); 197 + 198 + channel->active = 1; 199 + 200 + if (fei->global_feed_count == 0) { 201 + fei->timer.expires = jiffies + 202 + msecs_to_jiffies(msecs_to_jiffies(POLL_MSECS)); 203 + 204 + add_timer(&fei->timer); 205 + } 206 + 207 + if (stdemux->running_feed_count == 0) { 208 + 209 + dev_dbg(fei->dev, "Starting channel=%p\n", channel); 210 + 211 + tasklet_init(&channel->tsklet, channel_swdemux_tsklet, 212 + (unsigned long) channel); 213 + 214 + /* Reset the internal inputblock sram pointers */ 215 + writel(channel->fifo, 216 + fei->io + C8SECTPFE_IB_BUFF_STRT(channel->tsin_id)); 217 + writel(channel->fifo + FIFO_LEN - 1, 218 + fei->io + C8SECTPFE_IB_BUFF_END(channel->tsin_id)); 219 + 220 + writel(channel->fifo, 221 + fei->io + C8SECTPFE_IB_READ_PNT(channel->tsin_id)); 222 + writel(channel->fifo, 223 + fei->io + C8SECTPFE_IB_WRT_PNT(channel->tsin_id)); 224 + 225 + 226 + /* reset read / write memdma ptrs for this channel */ 227 + writel(channel->back_buffer_busaddr, channel->irec + 228 + DMA_PRDS_BUSBASE_TP(0)); 229 + 230 + tmp = channel->back_buffer_busaddr + FEI_BUFFER_SIZE - 1; 231 + writel(tmp, channel->irec + DMA_PRDS_BUSTOP_TP(0)); 232 + 233 + writel(channel->back_buffer_busaddr, channel->irec + 234 + DMA_PRDS_BUSWP_TP(0)); 235 + 236 + /* Issue a reset and enable InputBlock */ 237 + writel(C8SECTPFE_SYS_ENABLE | C8SECTPFE_SYS_RESET 238 + , fei->io + C8SECTPFE_IB_SYS(channel->tsin_id)); 239 + 240 + /* and enable the tp */ 241 + writel(0x1, channel->irec + DMA_PRDS_TPENABLE); 242 + 243 + dev_dbg(fei->dev, "%s:%d Starting DMA feed on stdemux=%p\n" 244 + , __func__, __LINE__, stdemux); 245 + } 246 + 247 + stdemux->running_feed_count++; 248 + fei->global_feed_count++; 249 + 250 + mutex_unlock(&fei->lock); 251 + 252 + return 0; 253 + } 254 + 255 + static int c8sectpfe_stop_feed(struct dvb_demux_feed *dvbdmxfeed) 256 + { 257 + 258 + struct dvb_demux *demux = dvbdmxfeed->demux; 259 + struct stdemux *stdemux = (struct stdemux *)demux->priv; 260 + struct c8sectpfei *fei = stdemux->c8sectpfei; 261 + struct channel_info *channel; 262 + int idlereq; 263 + u32 tmp; 264 + int ret; 265 + unsigned long *bitmap; 266 + 267 + if (!atomic_read(&fei->fw_loaded)) { 268 + dev_err(fei->dev, "%s: c8sectpfe fw not loaded\n", __func__); 269 + return -EINVAL; 270 + } 271 + 272 + mutex_lock(&fei->lock); 273 + 274 + channel = fei->channel_data[stdemux->tsin_index]; 275 + 276 + bitmap = (unsigned long *) channel->pid_buffer_aligned; 277 + 278 + if (dvbdmxfeed->pid == 8192) { 279 + tmp = readl(fei->io + C8SECTPFE_IB_PID_SET(channel->tsin_id)); 280 + tmp |= C8SECTPFE_PID_ENABLE; 281 + writel(tmp, fei->io + C8SECTPFE_IB_PID_SET(channel->tsin_id)); 282 + } else { 283 + bitmap_clear(bitmap, dvbdmxfeed->pid, 1); 284 + } 285 + 286 + /* manage cache so data is visible to HW */ 287 + dma_sync_single_for_device(fei->dev, 288 + channel->pid_buffer_busaddr, 289 + PID_TABLE_SIZE, 290 + DMA_TO_DEVICE); 291 + 292 + if (--stdemux->running_feed_count == 0) { 293 + 294 + channel = fei->channel_data[stdemux->tsin_index]; 295 + 296 + /* TP re-configuration on page 168 of functional spec */ 297 + 298 + /* disable IB (prevents more TS data going to memdma) */ 299 + writel(0, fei->io + C8SECTPFE_IB_SYS(channel->tsin_id)); 300 + 301 + /* disable this channels descriptor */ 302 + writel(0, channel->irec + DMA_PRDS_TPENABLE); 303 + 304 + tasklet_disable(&channel->tsklet); 305 + 306 + /* now request memdma channel goes idle */ 307 + idlereq = (1 << channel->tsin_id) | IDLEREQ; 308 + writel(idlereq, fei->io + DMA_IDLE_REQ); 309 + 310 + /* wait for idle irq handler to signal completion */ 311 + ret = wait_for_completion_timeout(&channel->idle_completion, 312 + msecs_to_jiffies(100)); 313 + 314 + if (ret == 0) 315 + dev_warn(fei->dev, 316 + "Timeout waiting for idle irq on tsin%d\n", 317 + channel->tsin_id); 318 + 319 + reinit_completion(&channel->idle_completion); 320 + 321 + /* reset read / write ptrs for this channel */ 322 + 323 + writel(channel->back_buffer_busaddr, 324 + channel->irec + DMA_PRDS_BUSBASE_TP(0)); 325 + 326 + tmp = channel->back_buffer_busaddr + FEI_BUFFER_SIZE - 1; 327 + writel(tmp, channel->irec + DMA_PRDS_BUSTOP_TP(0)); 328 + 329 + writel(channel->back_buffer_busaddr, 330 + channel->irec + DMA_PRDS_BUSWP_TP(0)); 331 + 332 + dev_dbg(fei->dev, 333 + "%s:%d stopping DMA feed on stdemux=%p channel=%d\n", 334 + __func__, __LINE__, stdemux, channel->tsin_id); 335 + 336 + /* turn off all PIDS in the bitmap */ 337 + memset((void *)channel->pid_buffer_aligned 338 + , 0x00, PID_TABLE_SIZE); 339 + 340 + /* manage cache so data is visible to HW */ 341 + dma_sync_single_for_device(fei->dev, 342 + channel->pid_buffer_busaddr, 343 + PID_TABLE_SIZE, 344 + DMA_TO_DEVICE); 345 + 346 + channel->active = 0; 347 + } 348 + 349 + if (--fei->global_feed_count == 0) { 350 + dev_dbg(fei->dev, "%s:%d global_feed_count=%d\n" 351 + , __func__, __LINE__, fei->global_feed_count); 352 + 353 + del_timer(&fei->timer); 354 + } 355 + 356 + mutex_unlock(&fei->lock); 357 + 358 + return 0; 359 + } 360 + 361 + static struct channel_info *find_channel(struct c8sectpfei *fei, int tsin_num) 362 + { 363 + int i; 364 + 365 + for (i = 0; i < C8SECTPFE_MAX_TSIN_CHAN; i++) { 366 + if (!fei->channel_data[i]) 367 + continue; 368 + 369 + if (fei->channel_data[i]->tsin_id == tsin_num) 370 + return fei->channel_data[i]; 371 + } 372 + 373 + return NULL; 374 + } 375 + 376 + static void c8sectpfe_getconfig(struct c8sectpfei *fei) 377 + { 378 + struct c8sectpfe_hw *hw = &fei->hw_stats; 379 + 380 + hw->num_ib = readl(fei->io + SYS_CFG_NUM_IB); 381 + hw->num_mib = readl(fei->io + SYS_CFG_NUM_MIB); 382 + hw->num_swts = readl(fei->io + SYS_CFG_NUM_SWTS); 383 + hw->num_tsout = readl(fei->io + SYS_CFG_NUM_TSOUT); 384 + hw->num_ccsc = readl(fei->io + SYS_CFG_NUM_CCSC); 385 + hw->num_ram = readl(fei->io + SYS_CFG_NUM_RAM); 386 + hw->num_tp = readl(fei->io + SYS_CFG_NUM_TP); 387 + 388 + dev_info(fei->dev, "C8SECTPFE hw supports the following:\n"); 389 + dev_info(fei->dev, "Input Blocks: %d\n", hw->num_ib); 390 + dev_info(fei->dev, "Merged Input Blocks: %d\n", hw->num_mib); 391 + dev_info(fei->dev, "Software Transport Stream Inputs: %d\n" 392 + , hw->num_swts); 393 + dev_info(fei->dev, "Transport Stream Output: %d\n", hw->num_tsout); 394 + dev_info(fei->dev, "Cable Card Converter: %d\n", hw->num_ccsc); 395 + dev_info(fei->dev, "RAMs supported by C8SECTPFE: %d\n", hw->num_ram); 396 + dev_info(fei->dev, "Tango TPs supported by C8SECTPFE: %d\n" 397 + , hw->num_tp); 398 + } 399 + 400 + static irqreturn_t c8sectpfe_idle_irq_handler(int irq, void *priv) 401 + { 402 + struct c8sectpfei *fei = priv; 403 + struct channel_info *chan; 404 + int bit; 405 + unsigned long tmp = readl(fei->io + DMA_IDLE_REQ); 406 + 407 + /* page 168 of functional spec: Clear the idle request 408 + by writing 0 to the C8SECTPFE_DMA_IDLE_REQ register. */ 409 + 410 + /* signal idle completion */ 411 + for_each_set_bit(bit, &tmp, fei->hw_stats.num_ib) { 412 + 413 + chan = find_channel(fei, bit); 414 + 415 + if (chan) 416 + complete(&chan->idle_completion); 417 + } 418 + 419 + writel(0, fei->io + DMA_IDLE_REQ); 420 + 421 + return IRQ_HANDLED; 422 + } 423 + 424 + 425 + static void free_input_block(struct c8sectpfei *fei, struct channel_info *tsin) 426 + { 427 + if (!fei || !tsin) 428 + return; 429 + 430 + if (tsin->back_buffer_busaddr) 431 + if (!dma_mapping_error(fei->dev, tsin->back_buffer_busaddr)) 432 + dma_unmap_single(fei->dev, tsin->back_buffer_busaddr, 433 + FEI_BUFFER_SIZE, DMA_BIDIRECTIONAL); 434 + 435 + kfree(tsin->back_buffer_start); 436 + 437 + if (tsin->pid_buffer_busaddr) 438 + if (!dma_mapping_error(fei->dev, tsin->pid_buffer_busaddr)) 439 + dma_unmap_single(fei->dev, tsin->pid_buffer_busaddr, 440 + PID_TABLE_SIZE, DMA_BIDIRECTIONAL); 441 + 442 + kfree(tsin->pid_buffer_start); 443 + } 444 + 445 + #define MAX_NAME 20 446 + 447 + static int configure_memdma_and_inputblock(struct c8sectpfei *fei, 448 + struct channel_info *tsin) 449 + { 450 + int ret; 451 + u32 tmp; 452 + char tsin_pin_name[MAX_NAME]; 453 + 454 + if (!fei || !tsin) 455 + return -EINVAL; 456 + 457 + dev_dbg(fei->dev, "%s:%d Configuring channel=%p tsin=%d\n" 458 + , __func__, __LINE__, tsin, tsin->tsin_id); 459 + 460 + init_completion(&tsin->idle_completion); 461 + 462 + tsin->back_buffer_start = kzalloc(FEI_BUFFER_SIZE + 463 + FEI_ALIGNMENT, GFP_KERNEL); 464 + 465 + if (!tsin->back_buffer_start) { 466 + ret = -ENOMEM; 467 + goto err_unmap; 468 + } 469 + 470 + /* Ensure backbuffer is 32byte aligned */ 471 + tsin->back_buffer_aligned = tsin->back_buffer_start 472 + + FEI_ALIGNMENT; 473 + 474 + tsin->back_buffer_aligned = (void *) 475 + (((uintptr_t) tsin->back_buffer_aligned) & ~0x1F); 476 + 477 + tsin->back_buffer_busaddr = dma_map_single(fei->dev, 478 + (void *)tsin->back_buffer_aligned, 479 + FEI_BUFFER_SIZE, 480 + DMA_BIDIRECTIONAL); 481 + 482 + if (dma_mapping_error(fei->dev, tsin->back_buffer_busaddr)) { 483 + dev_err(fei->dev, "failed to map back_buffer\n"); 484 + ret = -EFAULT; 485 + goto err_unmap; 486 + } 487 + 488 + /* 489 + * The pid buffer can be configured (in hw) for byte or bit 490 + * per pid. By powers of deduction we conclude stih407 family 491 + * is configured (at SoC design stage) for bit per pid. 492 + */ 493 + tsin->pid_buffer_start = kzalloc(2048, GFP_KERNEL); 494 + 495 + if (!tsin->pid_buffer_start) { 496 + ret = -ENOMEM; 497 + goto err_unmap; 498 + } 499 + 500 + /* 501 + * PID buffer needs to be aligned to size of the pid table 502 + * which at bit per pid is 1024 bytes (8192 pids / 8). 503 + * PIDF_BASE register enforces this alignment when writing 504 + * the register. 505 + */ 506 + 507 + tsin->pid_buffer_aligned = tsin->pid_buffer_start + 508 + PID_TABLE_SIZE; 509 + 510 + tsin->pid_buffer_aligned = (void *) 511 + (((uintptr_t) tsin->pid_buffer_aligned) & ~0x3ff); 512 + 513 + tsin->pid_buffer_busaddr = dma_map_single(fei->dev, 514 + tsin->pid_buffer_aligned, 515 + PID_TABLE_SIZE, 516 + DMA_BIDIRECTIONAL); 517 + 518 + if (dma_mapping_error(fei->dev, tsin->pid_buffer_busaddr)) { 519 + dev_err(fei->dev, "failed to map pid_bitmap\n"); 520 + ret = -EFAULT; 521 + goto err_unmap; 522 + } 523 + 524 + /* manage cache so pid bitmap is visible to HW */ 525 + dma_sync_single_for_device(fei->dev, 526 + tsin->pid_buffer_busaddr, 527 + PID_TABLE_SIZE, 528 + DMA_TO_DEVICE); 529 + 530 + snprintf(tsin_pin_name, MAX_NAME, "tsin%d-%s", tsin->tsin_id, 531 + (tsin->serial_not_parallel ? "serial" : "parallel")); 532 + 533 + tsin->pstate = pinctrl_lookup_state(fei->pinctrl, tsin_pin_name); 534 + if (IS_ERR(tsin->pstate)) { 535 + dev_err(fei->dev, "%s: pinctrl_lookup_state couldn't find %s state\n" 536 + , __func__, tsin_pin_name); 537 + ret = PTR_ERR(tsin->pstate); 538 + goto err_unmap; 539 + } 540 + 541 + ret = pinctrl_select_state(fei->pinctrl, tsin->pstate); 542 + 543 + if (ret) { 544 + dev_err(fei->dev, "%s: pinctrl_select_state failed\n" 545 + , __func__); 546 + goto err_unmap; 547 + } 548 + 549 + /* Enable this input block */ 550 + tmp = readl(fei->io + SYS_INPUT_CLKEN); 551 + tmp |= BIT(tsin->tsin_id); 552 + writel(tmp, fei->io + SYS_INPUT_CLKEN); 553 + 554 + if (tsin->serial_not_parallel) 555 + tmp |= C8SECTPFE_SERIAL_NOT_PARALLEL; 556 + 557 + if (tsin->invert_ts_clk) 558 + tmp |= C8SECTPFE_INVERT_TSCLK; 559 + 560 + if (tsin->async_not_sync) 561 + tmp |= C8SECTPFE_ASYNC_NOT_SYNC; 562 + 563 + tmp |= C8SECTPFE_ALIGN_BYTE_SOP | C8SECTPFE_BYTE_ENDIANNESS_MSB; 564 + 565 + writel(tmp, fei->io + C8SECTPFE_IB_IP_FMT_CFG(tsin->tsin_id)); 566 + 567 + writel(C8SECTPFE_SYNC(0x9) | 568 + C8SECTPFE_DROP(0x9) | 569 + C8SECTPFE_TOKEN(0x47), 570 + fei->io + C8SECTPFE_IB_SYNCLCKDRP_CFG(tsin->tsin_id)); 571 + 572 + writel(TS_PKT_SIZE, fei->io + C8SECTPFE_IB_PKT_LEN(tsin->tsin_id)); 573 + 574 + /* Place the FIFO's at the end of the irec descriptors */ 575 + 576 + tsin->fifo = (tsin->tsin_id * FIFO_LEN); 577 + 578 + writel(tsin->fifo, fei->io + C8SECTPFE_IB_BUFF_STRT(tsin->tsin_id)); 579 + writel(tsin->fifo + FIFO_LEN - 1, 580 + fei->io + C8SECTPFE_IB_BUFF_END(tsin->tsin_id)); 581 + 582 + writel(tsin->fifo, fei->io + C8SECTPFE_IB_READ_PNT(tsin->tsin_id)); 583 + writel(tsin->fifo, fei->io + C8SECTPFE_IB_WRT_PNT(tsin->tsin_id)); 584 + 585 + writel(tsin->pid_buffer_busaddr, 586 + fei->io + PIDF_BASE(tsin->tsin_id)); 587 + 588 + dev_info(fei->dev, "chan=%d PIDF_BASE=0x%x pid_bus_addr=%pad\n", 589 + tsin->tsin_id, readl(fei->io + PIDF_BASE(tsin->tsin_id)), 590 + &tsin->pid_buffer_busaddr); 591 + 592 + /* Configure and enable HW PID filtering */ 593 + 594 + /* 595 + * The PID value is created by assembling the first 8 bytes of 596 + * the TS packet into a 64-bit word in big-endian format. A 597 + * slice of that 64-bit word is taken from 598 + * (PID_OFFSET+PID_NUM_BITS-1) to PID_OFFSET. 599 + */ 600 + tmp = (C8SECTPFE_PID_ENABLE | C8SECTPFE_PID_NUMBITS(13) 601 + | C8SECTPFE_PID_OFFSET(40)); 602 + 603 + writel(tmp, fei->io + C8SECTPFE_IB_PID_SET(tsin->tsin_id)); 604 + 605 + dev_dbg(fei->dev, "chan=%d setting wp: %d, rp: %d, buf: %d-%d\n", 606 + tsin->tsin_id, 607 + readl(fei->io + C8SECTPFE_IB_WRT_PNT(tsin->tsin_id)), 608 + readl(fei->io + C8SECTPFE_IB_READ_PNT(tsin->tsin_id)), 609 + readl(fei->io + C8SECTPFE_IB_BUFF_STRT(tsin->tsin_id)), 610 + readl(fei->io + C8SECTPFE_IB_BUFF_END(tsin->tsin_id))); 611 + 612 + /* Get base addpress of pointer record block from DMEM */ 613 + tsin->irec = fei->io + DMA_MEMDMA_OFFSET + DMA_DMEM_OFFSET + 614 + readl(fei->io + DMA_PTRREC_BASE); 615 + 616 + /* fill out pointer record data structure */ 617 + 618 + /* advance pointer record block to our channel */ 619 + tsin->irec += (tsin->tsin_id * DMA_PRDS_SIZE); 620 + 621 + writel(tsin->fifo, tsin->irec + DMA_PRDS_MEMBASE); 622 + 623 + writel(tsin->fifo + FIFO_LEN - 1, tsin->irec + DMA_PRDS_MEMTOP); 624 + 625 + writel((188 + 7)&~7, tsin->irec + DMA_PRDS_PKTSIZE); 626 + 627 + writel(0x1, tsin->irec + DMA_PRDS_TPENABLE); 628 + 629 + /* read/write pointers with physical bus address */ 630 + 631 + writel(tsin->back_buffer_busaddr, tsin->irec + DMA_PRDS_BUSBASE_TP(0)); 632 + 633 + tmp = tsin->back_buffer_busaddr + FEI_BUFFER_SIZE - 1; 634 + writel(tmp, tsin->irec + DMA_PRDS_BUSTOP_TP(0)); 635 + 636 + writel(tsin->back_buffer_busaddr, tsin->irec + DMA_PRDS_BUSWP_TP(0)); 637 + writel(tsin->back_buffer_busaddr, tsin->irec + DMA_PRDS_BUSRP_TP(0)); 638 + 639 + /* initialize tasklet */ 640 + tasklet_init(&tsin->tsklet, channel_swdemux_tsklet, 641 + (unsigned long) tsin); 642 + 643 + return 0; 644 + 645 + err_unmap: 646 + free_input_block(fei, tsin); 647 + return ret; 648 + } 649 + 650 + static irqreturn_t c8sectpfe_error_irq_handler(int irq, void *priv) 651 + { 652 + struct c8sectpfei *fei = priv; 653 + 654 + dev_err(fei->dev, "%s: error handling not yet implemented\n" 655 + , __func__); 656 + 657 + /* 658 + * TODO FIXME we should detect some error conditions here 659 + * and ideally so something about them! 660 + */ 661 + 662 + return IRQ_HANDLED; 663 + } 664 + 665 + static int c8sectpfe_probe(struct platform_device *pdev) 666 + { 667 + struct device *dev = &pdev->dev; 668 + struct device_node *child, *np = dev->of_node; 669 + struct c8sectpfei *fei; 670 + struct resource *res; 671 + int ret, index = 0; 672 + struct channel_info *tsin; 673 + 674 + /* Allocate the c8sectpfei structure */ 675 + fei = devm_kzalloc(dev, sizeof(struct c8sectpfei), GFP_KERNEL); 676 + if (!fei) 677 + return -ENOMEM; 678 + 679 + fei->dev = dev; 680 + 681 + res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "c8sectpfe"); 682 + fei->io = devm_ioremap_resource(dev, res); 683 + if (IS_ERR(fei->io)) 684 + return PTR_ERR(fei->io); 685 + 686 + res = platform_get_resource_byname(pdev, IORESOURCE_MEM, 687 + "c8sectpfe-ram"); 688 + fei->sram = devm_ioremap_resource(dev, res); 689 + if (IS_ERR(fei->sram)) 690 + return PTR_ERR(fei->sram); 691 + 692 + fei->sram_size = res->end - res->start; 693 + 694 + fei->idle_irq = platform_get_irq_byname(pdev, "c8sectpfe-idle-irq"); 695 + if (fei->idle_irq < 0) { 696 + dev_err(dev, "Can't get c8sectpfe-idle-irq\n"); 697 + return fei->idle_irq; 698 + } 699 + 700 + fei->error_irq = platform_get_irq_byname(pdev, "c8sectpfe-error-irq"); 701 + if (fei->error_irq < 0) { 702 + dev_err(dev, "Can't get c8sectpfe-error-irq\n"); 703 + return fei->error_irq; 704 + } 705 + 706 + platform_set_drvdata(pdev, fei); 707 + 708 + fei->c8sectpfeclk = devm_clk_get(dev, "c8sectpfe"); 709 + if (IS_ERR(fei->c8sectpfeclk)) { 710 + dev_err(dev, "c8sectpfe clk not found\n"); 711 + return PTR_ERR(fei->c8sectpfeclk); 712 + } 713 + 714 + ret = clk_prepare_enable(fei->c8sectpfeclk); 715 + if (ret) { 716 + dev_err(dev, "Failed to enable c8sectpfe clock\n"); 717 + return ret; 718 + } 719 + 720 + /* to save power disable all IP's (on by default) */ 721 + writel(0, fei->io + SYS_INPUT_CLKEN); 722 + 723 + /* Enable memdma clock */ 724 + writel(MEMDMAENABLE, fei->io + SYS_OTHER_CLKEN); 725 + 726 + /* clear internal sram */ 727 + memset_io(fei->sram, 0x0, fei->sram_size); 728 + 729 + c8sectpfe_getconfig(fei); 730 + 731 + ret = devm_request_irq(dev, fei->idle_irq, c8sectpfe_idle_irq_handler, 732 + 0, "c8sectpfe-idle-irq", fei); 733 + if (ret) { 734 + dev_err(dev, "Can't register c8sectpfe-idle-irq IRQ.\n"); 735 + goto err_clk_disable; 736 + } 737 + 738 + ret = devm_request_irq(dev, fei->error_irq, 739 + c8sectpfe_error_irq_handler, 0, 740 + "c8sectpfe-error-irq", fei); 741 + if (ret) { 742 + dev_err(dev, "Can't register c8sectpfe-error-irq IRQ.\n"); 743 + goto err_clk_disable; 744 + } 745 + 746 + fei->tsin_count = of_get_child_count(np); 747 + 748 + if (fei->tsin_count > C8SECTPFE_MAX_TSIN_CHAN || 749 + fei->tsin_count > fei->hw_stats.num_ib) { 750 + 751 + dev_err(dev, "More tsin declared than exist on SoC!\n"); 752 + ret = -EINVAL; 753 + goto err_clk_disable; 754 + } 755 + 756 + fei->pinctrl = devm_pinctrl_get(dev); 757 + 758 + if (IS_ERR(fei->pinctrl)) { 759 + dev_err(dev, "Error getting tsin pins\n"); 760 + ret = PTR_ERR(fei->pinctrl); 761 + goto err_clk_disable; 762 + } 763 + 764 + for_each_child_of_node(np, child) { 765 + struct device_node *i2c_bus; 766 + 767 + fei->channel_data[index] = devm_kzalloc(dev, 768 + sizeof(struct channel_info), 769 + GFP_KERNEL); 770 + 771 + if (!fei->channel_data[index]) { 772 + ret = -ENOMEM; 773 + goto err_clk_disable; 774 + } 775 + 776 + tsin = fei->channel_data[index]; 777 + 778 + tsin->fei = fei; 779 + 780 + ret = of_property_read_u32(child, "tsin-num", &tsin->tsin_id); 781 + if (ret) { 782 + dev_err(&pdev->dev, "No tsin_num found\n"); 783 + goto err_clk_disable; 784 + } 785 + 786 + /* sanity check value */ 787 + if (tsin->tsin_id > fei->hw_stats.num_ib) { 788 + dev_err(&pdev->dev, 789 + "tsin-num %d specified greater than number\n\t" 790 + "of input block hw in SoC! (%d)", 791 + tsin->tsin_id, fei->hw_stats.num_ib); 792 + ret = -EINVAL; 793 + goto err_clk_disable; 794 + } 795 + 796 + tsin->invert_ts_clk = of_property_read_bool(child, 797 + "invert-ts-clk"); 798 + 799 + tsin->serial_not_parallel = of_property_read_bool(child, 800 + "serial-not-parallel"); 801 + 802 + tsin->async_not_sync = of_property_read_bool(child, 803 + "async-not-sync"); 804 + 805 + ret = of_property_read_u32(child, "dvb-card", 806 + &tsin->dvb_card); 807 + if (ret) { 808 + dev_err(&pdev->dev, "No dvb-card found\n"); 809 + goto err_clk_disable; 810 + } 811 + 812 + i2c_bus = of_parse_phandle(child, "i2c-bus", 0); 813 + if (!i2c_bus) { 814 + dev_err(&pdev->dev, "No i2c-bus found\n"); 815 + goto err_clk_disable; 816 + } 817 + tsin->i2c_adapter = 818 + of_find_i2c_adapter_by_node(i2c_bus); 819 + if (!tsin->i2c_adapter) { 820 + dev_err(&pdev->dev, "No i2c adapter found\n"); 821 + of_node_put(i2c_bus); 822 + goto err_clk_disable; 823 + } 824 + of_node_put(i2c_bus); 825 + 826 + tsin->rst_gpio = of_get_named_gpio(child, "rst-gpio", 0); 827 + 828 + ret = gpio_is_valid(tsin->rst_gpio); 829 + if (!ret) { 830 + dev_err(dev, 831 + "reset gpio for tsin%d not valid (gpio=%d)\n", 832 + tsin->tsin_id, tsin->rst_gpio); 833 + goto err_clk_disable; 834 + } 835 + 836 + ret = devm_gpio_request_one(dev, tsin->rst_gpio, 837 + GPIOF_OUT_INIT_LOW, "NIM reset"); 838 + if (ret && ret != -EBUSY) { 839 + dev_err(dev, "Can't request tsin%d reset gpio\n" 840 + , fei->channel_data[index]->tsin_id); 841 + goto err_clk_disable; 842 + } 843 + 844 + if (!ret) { 845 + /* toggle reset lines */ 846 + gpio_direction_output(tsin->rst_gpio, 0); 847 + usleep_range(3500, 5000); 848 + gpio_direction_output(tsin->rst_gpio, 1); 849 + usleep_range(3000, 5000); 850 + } 851 + 852 + tsin->demux_mapping = index; 853 + 854 + dev_dbg(fei->dev, 855 + "channel=%p n=%d tsin_num=%d, invert-ts-clk=%d\n\t" 856 + "serial-not-parallel=%d pkt-clk-valid=%d dvb-card=%d\n", 857 + fei->channel_data[index], index, 858 + tsin->tsin_id, tsin->invert_ts_clk, 859 + tsin->serial_not_parallel, tsin->async_not_sync, 860 + tsin->dvb_card); 861 + 862 + index++; 863 + } 864 + 865 + /* Setup timer interrupt */ 866 + init_timer(&fei->timer); 867 + fei->timer.function = c8sectpfe_timer_interrupt; 868 + fei->timer.data = (unsigned long)fei; 869 + 870 + mutex_init(&fei->lock); 871 + 872 + /* Get the configuration information about the tuners */ 873 + ret = c8sectpfe_tuner_register_frontend(&fei->c8sectpfe[0], 874 + (void *)fei, 875 + c8sectpfe_start_feed, 876 + c8sectpfe_stop_feed); 877 + if (ret) { 878 + dev_err(dev, "c8sectpfe_tuner_register_frontend failed (%d)\n", 879 + ret); 880 + goto err_clk_disable; 881 + } 882 + 883 + /* ensure all other init has been done before requesting firmware */ 884 + ret = load_c8sectpfe_fw_step1(fei); 885 + if (ret) { 886 + dev_err(dev, "Couldn't load slim core firmware\n"); 887 + goto err_clk_disable; 888 + } 889 + 890 + c8sectpfe_debugfs_init(fei); 891 + 892 + return 0; 893 + 894 + err_clk_disable: 895 + /* TODO uncomment when upstream has taken a reference on this clk */ 896 + /*clk_disable_unprepare(fei->c8sectpfeclk);*/ 897 + return ret; 898 + } 899 + 900 + static int c8sectpfe_remove(struct platform_device *pdev) 901 + { 902 + struct c8sectpfei *fei = platform_get_drvdata(pdev); 903 + struct channel_info *channel; 904 + int i; 905 + 906 + wait_for_completion(&fei->fw_ack); 907 + 908 + c8sectpfe_tuner_unregister_frontend(fei->c8sectpfe[0], fei); 909 + 910 + /* 911 + * Now loop through and un-configure each of the InputBlock resources 912 + */ 913 + for (i = 0; i < fei->tsin_count; i++) { 914 + channel = fei->channel_data[i]; 915 + free_input_block(fei, channel); 916 + } 917 + 918 + c8sectpfe_debugfs_exit(fei); 919 + 920 + dev_info(fei->dev, "Stopping memdma SLIM core\n"); 921 + if (readl(fei->io + DMA_CPU_RUN)) 922 + writel(0x0, fei->io + DMA_CPU_RUN); 923 + 924 + /* unclock all internal IP's */ 925 + if (readl(fei->io + SYS_INPUT_CLKEN)) 926 + writel(0, fei->io + SYS_INPUT_CLKEN); 927 + 928 + if (readl(fei->io + SYS_OTHER_CLKEN)) 929 + writel(0, fei->io + SYS_OTHER_CLKEN); 930 + 931 + /* TODO uncomment when upstream has taken a reference on this clk */ 932 + /* 933 + if (fei->c8sectpfeclk) 934 + clk_disable_unprepare(fei->c8sectpfeclk); 935 + */ 936 + 937 + return 0; 938 + } 939 + 940 + 941 + static int configure_channels(struct c8sectpfei *fei) 942 + { 943 + int index = 0, ret; 944 + struct channel_info *tsin; 945 + struct device_node *child, *np = fei->dev->of_node; 946 + 947 + /* iterate round each tsin and configure memdma descriptor and IB hw */ 948 + for_each_child_of_node(np, child) { 949 + 950 + tsin = fei->channel_data[index]; 951 + 952 + ret = configure_memdma_and_inputblock(fei, 953 + fei->channel_data[index]); 954 + 955 + if (ret) { 956 + dev_err(fei->dev, 957 + "configure_memdma_and_inputblock failed\n"); 958 + goto err_unmap; 959 + } 960 + index++; 961 + } 962 + 963 + return 0; 964 + 965 + err_unmap: 966 + for (index = 0; index < fei->tsin_count; index++) { 967 + tsin = fei->channel_data[index]; 968 + free_input_block(fei, tsin); 969 + } 970 + return ret; 971 + } 972 + 973 + static int 974 + c8sectpfe_elf_sanity_check(struct c8sectpfei *fei, const struct firmware *fw) 975 + { 976 + struct elf32_hdr *ehdr; 977 + char class; 978 + 979 + if (!fw) { 980 + dev_err(fei->dev, "failed to load %s\n", FIRMWARE_MEMDMA); 981 + return -EINVAL; 982 + } 983 + 984 + if (fw->size < sizeof(struct elf32_hdr)) { 985 + dev_err(fei->dev, "Image is too small\n"); 986 + return -EINVAL; 987 + } 988 + 989 + ehdr = (struct elf32_hdr *)fw->data; 990 + 991 + /* We only support ELF32 at this point */ 992 + class = ehdr->e_ident[EI_CLASS]; 993 + if (class != ELFCLASS32) { 994 + dev_err(fei->dev, "Unsupported class: %d\n", class); 995 + return -EINVAL; 996 + } 997 + 998 + if (ehdr->e_ident[EI_DATA] != ELFDATA2LSB) { 999 + dev_err(fei->dev, "Unsupported firmware endianness\n"); 1000 + return -EINVAL; 1001 + } 1002 + 1003 + if (fw->size < ehdr->e_shoff + sizeof(struct elf32_shdr)) { 1004 + dev_err(fei->dev, "Image is too small\n"); 1005 + return -EINVAL; 1006 + } 1007 + 1008 + if (memcmp(ehdr->e_ident, ELFMAG, SELFMAG)) { 1009 + dev_err(fei->dev, "Image is corrupted (bad magic)\n"); 1010 + return -EINVAL; 1011 + } 1012 + 1013 + /* Check ELF magic */ 1014 + ehdr = (Elf32_Ehdr *)fw->data; 1015 + if (ehdr->e_ident[EI_MAG0] != ELFMAG0 || 1016 + ehdr->e_ident[EI_MAG1] != ELFMAG1 || 1017 + ehdr->e_ident[EI_MAG2] != ELFMAG2 || 1018 + ehdr->e_ident[EI_MAG3] != ELFMAG3) { 1019 + dev_err(fei->dev, "Invalid ELF magic\n"); 1020 + return -EINVAL; 1021 + } 1022 + 1023 + if (ehdr->e_type != ET_EXEC) { 1024 + dev_err(fei->dev, "Unsupported ELF header type\n"); 1025 + return -EINVAL; 1026 + } 1027 + 1028 + if (ehdr->e_phoff > fw->size) { 1029 + dev_err(fei->dev, "Firmware size is too small\n"); 1030 + return -EINVAL; 1031 + } 1032 + 1033 + return 0; 1034 + } 1035 + 1036 + 1037 + static void load_imem_segment(struct c8sectpfei *fei, Elf32_Phdr *phdr, 1038 + const struct firmware *fw, u8 __iomem *dest, 1039 + int seg_num) 1040 + { 1041 + const u8 *imem_src = fw->data + phdr->p_offset; 1042 + int i; 1043 + 1044 + /* 1045 + * For IMEM segments, the segment contains 24-bit 1046 + * instructions which must be padded to 32-bit 1047 + * instructions before being written. The written 1048 + * segment is padded with NOP instructions. 1049 + */ 1050 + 1051 + dev_dbg(fei->dev, 1052 + "Loading IMEM segment %d 0x%08x\n\t" 1053 + " (0x%x bytes) -> 0x%p (0x%x bytes)\n", seg_num, 1054 + phdr->p_paddr, phdr->p_filesz, 1055 + dest, phdr->p_memsz + phdr->p_memsz / 3); 1056 + 1057 + for (i = 0; i < phdr->p_filesz; i++) { 1058 + 1059 + writeb(readb((void __iomem *)imem_src), (void __iomem *)dest); 1060 + 1061 + /* Every 3 bytes, add an additional 1062 + * padding zero in destination */ 1063 + if (i % 3 == 2) { 1064 + dest++; 1065 + writeb(0x00, (void __iomem *)dest); 1066 + } 1067 + 1068 + dest++; 1069 + imem_src++; 1070 + } 1071 + } 1072 + 1073 + static void load_dmem_segment(struct c8sectpfei *fei, Elf32_Phdr *phdr, 1074 + const struct firmware *fw, u8 __iomem *dst, int seg_num) 1075 + { 1076 + /* 1077 + * For DMEM segments copy the segment data from the ELF 1078 + * file and pad segment with zeroes 1079 + */ 1080 + 1081 + dev_dbg(fei->dev, 1082 + "Loading DMEM segment %d 0x%08x\n\t" 1083 + "(0x%x bytes) -> 0x%p (0x%x bytes)\n", 1084 + seg_num, phdr->p_paddr, phdr->p_filesz, 1085 + dst, phdr->p_memsz); 1086 + 1087 + memcpy((void __iomem *)dst, (void *)fw->data + phdr->p_offset, 1088 + phdr->p_filesz); 1089 + 1090 + memset((void __iomem *)dst + phdr->p_filesz, 0, 1091 + phdr->p_memsz - phdr->p_filesz); 1092 + } 1093 + 1094 + static int load_slim_core_fw(const struct firmware *fw, void *context) 1095 + { 1096 + struct c8sectpfei *fei = context; 1097 + Elf32_Ehdr *ehdr; 1098 + Elf32_Phdr *phdr; 1099 + u8 __iomem *dst; 1100 + int err, i; 1101 + 1102 + if (!fw || !context) 1103 + return -EINVAL; 1104 + 1105 + ehdr = (Elf32_Ehdr *)fw->data; 1106 + phdr = (Elf32_Phdr *)(fw->data + ehdr->e_phoff); 1107 + 1108 + /* go through the available ELF segments */ 1109 + for (i = 0; i < ehdr->e_phnum && !err; i++, phdr++) { 1110 + 1111 + /* Only consider LOAD segments */ 1112 + if (phdr->p_type != PT_LOAD) 1113 + continue; 1114 + 1115 + /* 1116 + * Check segment is contained within the fw->data buffer 1117 + */ 1118 + if (phdr->p_offset + phdr->p_filesz > fw->size) { 1119 + dev_err(fei->dev, 1120 + "Segment %d is outside of firmware file\n", i); 1121 + err = -EINVAL; 1122 + break; 1123 + } 1124 + 1125 + /* 1126 + * MEMDMA IMEM has executable flag set, otherwise load 1127 + * this segment into DMEM. 1128 + * 1129 + */ 1130 + 1131 + if (phdr->p_flags & PF_X) { 1132 + dst = (u8 __iomem *) fei->io + DMA_MEMDMA_IMEM; 1133 + /* 1134 + * The Slim ELF file uses 32-bit word addressing for 1135 + * load offsets. 1136 + */ 1137 + dst += (phdr->p_paddr & 0xFFFFF) * sizeof(unsigned int); 1138 + load_imem_segment(fei, phdr, fw, dst, i); 1139 + } else { 1140 + dst = (u8 __iomem *) fei->io + DMA_MEMDMA_DMEM; 1141 + /* 1142 + * The Slim ELF file uses 32-bit word addressing for 1143 + * load offsets. 1144 + */ 1145 + dst += (phdr->p_paddr & 0xFFFFF) * sizeof(unsigned int); 1146 + load_dmem_segment(fei, phdr, fw, dst, i); 1147 + } 1148 + } 1149 + 1150 + release_firmware(fw); 1151 + return err; 1152 + } 1153 + 1154 + static void load_c8sectpfe_fw_cb(const struct firmware *fw, void *context) 1155 + { 1156 + struct c8sectpfei *fei = context; 1157 + int err; 1158 + 1159 + err = c8sectpfe_elf_sanity_check(fei, fw); 1160 + if (err) { 1161 + dev_err(fei->dev, "c8sectpfe_elf_sanity_check failed err=(%d)\n" 1162 + , err); 1163 + goto err; 1164 + } 1165 + 1166 + err = load_slim_core_fw(fw, context); 1167 + if (err) { 1168 + dev_err(fei->dev, "load_slim_core_fw failed err=(%d)\n", err); 1169 + goto err; 1170 + } 1171 + 1172 + /* now the firmware is loaded configure the input blocks */ 1173 + err = configure_channels(fei); 1174 + if (err) { 1175 + dev_err(fei->dev, "configure_channels failed err=(%d)\n", err); 1176 + goto err; 1177 + } 1178 + 1179 + /* 1180 + * STBus target port can access IMEM and DMEM ports 1181 + * without waiting for CPU 1182 + */ 1183 + writel(0x1, fei->io + DMA_PER_STBUS_SYNC); 1184 + 1185 + dev_info(fei->dev, "Boot the memdma SLIM core\n"); 1186 + writel(0x1, fei->io + DMA_CPU_RUN); 1187 + 1188 + atomic_set(&fei->fw_loaded, 1); 1189 + err: 1190 + complete_all(&fei->fw_ack); 1191 + } 1192 + 1193 + static int load_c8sectpfe_fw_step1(struct c8sectpfei *fei) 1194 + { 1195 + int ret; 1196 + int err; 1197 + 1198 + dev_info(fei->dev, "Loading firmware: %s\n", FIRMWARE_MEMDMA); 1199 + 1200 + init_completion(&fei->fw_ack); 1201 + atomic_set(&fei->fw_loaded, 0); 1202 + 1203 + err = request_firmware_nowait(THIS_MODULE, FW_ACTION_HOTPLUG, 1204 + FIRMWARE_MEMDMA, fei->dev, GFP_KERNEL, fei, 1205 + load_c8sectpfe_fw_cb); 1206 + 1207 + if (err) { 1208 + dev_err(fei->dev, "request_firmware_nowait err: %d.\n", err); 1209 + complete_all(&fei->fw_ack); 1210 + return ret; 1211 + } 1212 + 1213 + return 0; 1214 + } 1215 + 1216 + static const struct of_device_id c8sectpfe_match[] = { 1217 + { .compatible = "st,stih407-c8sectpfe" }, 1218 + { /* sentinel */ }, 1219 + }; 1220 + MODULE_DEVICE_TABLE(of, c8sectpfe_match); 1221 + 1222 + static struct platform_driver c8sectpfe_driver = { 1223 + .driver = { 1224 + .name = "c8sectpfe", 1225 + .of_match_table = of_match_ptr(c8sectpfe_match), 1226 + }, 1227 + .probe = c8sectpfe_probe, 1228 + .remove = c8sectpfe_remove, 1229 + }; 1230 + 1231 + module_platform_driver(c8sectpfe_driver); 1232 + 1233 + MODULE_AUTHOR("Peter Bennett <peter.bennett@st.com>"); 1234 + MODULE_AUTHOR("Peter Griffin <peter.griffin@linaro.org>"); 1235 + MODULE_DESCRIPTION("C8SECTPFE STi DVB Driver"); 1236 + MODULE_LICENSE("GPL");
+288
drivers/media/platform/sti/c8sectpfe/c8sectpfe-core.h
··· 1 + /* 2 + * c8sectpfe-core.h - C8SECTPFE STi DVB driver 3 + * 4 + * Copyright (c) STMicroelectronics 2015 5 + * 6 + * Author:Peter Bennett <peter.bennett@st.com> 7 + * Peter Griffin <peter.griffin@linaro.org> 8 + * 9 + * This program is free software; you can redistribute it and/or 10 + * modify it under the terms of the GNU General Public License as 11 + * published by the Free Software Foundation; either version 2 of 12 + * the License, or (at your option) any later version. 13 + */ 14 + #ifndef _C8SECTPFE_CORE_H_ 15 + #define _C8SECTPFE_CORE_H_ 16 + 17 + #define C8SECTPFEI_MAXCHANNEL 16 18 + #define C8SECTPFEI_MAXADAPTER 3 19 + 20 + #define C8SECTPFE_MAX_TSIN_CHAN 8 21 + 22 + struct channel_info { 23 + 24 + int tsin_id; 25 + bool invert_ts_clk; 26 + bool serial_not_parallel; 27 + bool async_not_sync; 28 + int i2c; 29 + int dvb_card; 30 + 31 + int rst_gpio; 32 + 33 + struct i2c_adapter *i2c_adapter; 34 + struct i2c_adapter *tuner_i2c; 35 + struct i2c_adapter *lnb_i2c; 36 + struct i2c_client *i2c_client; 37 + struct dvb_frontend *frontend; 38 + 39 + struct pinctrl_state *pstate; 40 + 41 + int demux_mapping; 42 + int active; 43 + 44 + void *back_buffer_start; 45 + void *back_buffer_aligned; 46 + dma_addr_t back_buffer_busaddr; 47 + 48 + void *pid_buffer_start; 49 + void *pid_buffer_aligned; 50 + dma_addr_t pid_buffer_busaddr; 51 + 52 + unsigned long fifo; 53 + 54 + struct completion idle_completion; 55 + struct tasklet_struct tsklet; 56 + 57 + struct c8sectpfei *fei; 58 + void __iomem *irec; 59 + 60 + }; 61 + 62 + struct c8sectpfe_hw { 63 + int num_ib; 64 + int num_mib; 65 + int num_swts; 66 + int num_tsout; 67 + int num_ccsc; 68 + int num_ram; 69 + int num_tp; 70 + }; 71 + 72 + struct c8sectpfei { 73 + 74 + struct device *dev; 75 + struct pinctrl *pinctrl; 76 + 77 + struct dentry *root; 78 + struct debugfs_regset32 *regset; 79 + struct completion fw_ack; 80 + atomic_t fw_loaded; 81 + 82 + int tsin_count; 83 + 84 + struct c8sectpfe_hw hw_stats; 85 + 86 + struct c8sectpfe *c8sectpfe[C8SECTPFEI_MAXADAPTER]; 87 + 88 + int mapping[C8SECTPFEI_MAXCHANNEL]; 89 + 90 + struct mutex lock; 91 + 92 + struct timer_list timer; /* timer interrupts for outputs */ 93 + 94 + void __iomem *io; 95 + void __iomem *sram; 96 + 97 + unsigned long sram_size; 98 + 99 + struct channel_info *channel_data[C8SECTPFE_MAX_TSIN_CHAN]; 100 + 101 + struct clk *c8sectpfeclk; 102 + int nima_rst_gpio; 103 + int nimb_rst_gpio; 104 + 105 + int idle_irq; 106 + int error_irq; 107 + 108 + int global_feed_count; 109 + }; 110 + 111 + /* C8SECTPFE SYS Regs list */ 112 + 113 + #define SYS_INPUT_ERR_STATUS 0x0 114 + #define SYS_OTHER_ERR_STATUS 0x8 115 + #define SYS_INPUT_ERR_MASK 0x10 116 + #define SYS_OTHER_ERR_MASK 0x18 117 + #define SYS_DMA_ROUTE 0x20 118 + #define SYS_INPUT_CLKEN 0x30 119 + #define IBENABLE_MASK 0x7F 120 + 121 + #define SYS_OTHER_CLKEN 0x38 122 + #define TSDMAENABLE BIT(1) 123 + #define MEMDMAENABLE BIT(0) 124 + 125 + #define SYS_CFG_NUM_IB 0x200 126 + #define SYS_CFG_NUM_MIB 0x204 127 + #define SYS_CFG_NUM_SWTS 0x208 128 + #define SYS_CFG_NUM_TSOUT 0x20C 129 + #define SYS_CFG_NUM_CCSC 0x210 130 + #define SYS_CFG_NUM_RAM 0x214 131 + #define SYS_CFG_NUM_TP 0x218 132 + 133 + /* Input Block Regs */ 134 + 135 + #define C8SECTPFE_INPUTBLK_OFFSET 0x1000 136 + #define C8SECTPFE_CHANNEL_OFFSET(x) ((x*0x40) + C8SECTPFE_INPUTBLK_OFFSET) 137 + 138 + #define C8SECTPFE_IB_IP_FMT_CFG(x) (C8SECTPFE_CHANNEL_OFFSET(x) + 0x00) 139 + #define C8SECTPFE_IGNORE_ERR_AT_SOP BIT(7) 140 + #define C8SECTPFE_IGNORE_ERR_IN_PKT BIT(6) 141 + #define C8SECTPFE_IGNORE_ERR_IN_BYTE BIT(5) 142 + #define C8SECTPFE_INVERT_TSCLK BIT(4) 143 + #define C8SECTPFE_ALIGN_BYTE_SOP BIT(3) 144 + #define C8SECTPFE_ASYNC_NOT_SYNC BIT(2) 145 + #define C8SECTPFE_BYTE_ENDIANNESS_MSB BIT(1) 146 + #define C8SECTPFE_SERIAL_NOT_PARALLEL BIT(0) 147 + 148 + #define C8SECTPFE_IB_SYNCLCKDRP_CFG(x) (C8SECTPFE_CHANNEL_OFFSET(x) + 0x04) 149 + #define C8SECTPFE_SYNC(x) (x & 0xf) 150 + #define C8SECTPFE_DROP(x) ((x<<4) & 0xf) 151 + #define C8SECTPFE_TOKEN(x) ((x<<8) & 0xff00) 152 + #define C8SECTPFE_SLDENDIANNESS BIT(16) 153 + 154 + #define C8SECTPFE_IB_TAGBYTES_CFG(x) (C8SECTPFE_CHANNEL_OFFSET(x) + 0x08) 155 + #define C8SECTPFE_TAG_HEADER(x) (x << 16) 156 + #define C8SECTPFE_TAG_COUNTER(x) ((x<<1) & 0x7fff) 157 + #define C8SECTPFE_TAG_ENABLE BIT(0) 158 + 159 + #define C8SECTPFE_IB_PID_SET(x) (C8SECTPFE_CHANNEL_OFFSET(x) + 0x0C) 160 + #define C8SECTPFE_PID_OFFSET(x) (x & 0x3f) 161 + #define C8SECTPFE_PID_NUMBITS(x) ((x << 6) & 0xfff) 162 + #define C8SECTPFE_PID_ENABLE BIT(31) 163 + 164 + #define C8SECTPFE_IB_PKT_LEN(x) (C8SECTPFE_CHANNEL_OFFSET(x) + 0x10) 165 + 166 + #define C8SECTPFE_IB_BUFF_STRT(x) (C8SECTPFE_CHANNEL_OFFSET(x) + 0x14) 167 + #define C8SECTPFE_IB_BUFF_END(x) (C8SECTPFE_CHANNEL_OFFSET(x) + 0x18) 168 + #define C8SECTPFE_IB_READ_PNT(x) (C8SECTPFE_CHANNEL_OFFSET(x) + 0x1C) 169 + #define C8SECTPFE_IB_WRT_PNT(x) (C8SECTPFE_CHANNEL_OFFSET(x) + 0x20) 170 + 171 + #define C8SECTPFE_IB_PRI_THRLD(x) (C8SECTPFE_CHANNEL_OFFSET(x) + 0x24) 172 + #define C8SECTPFE_PRI_VALUE(x) (x & 0x7fffff) 173 + #define C8SECTPFE_PRI_LOWPRI(x) ((x & 0xf) << 24) 174 + #define C8SECTPFE_PRI_HIGHPRI(x) ((x & 0xf) << 28) 175 + 176 + #define C8SECTPFE_IB_STAT(x) (C8SECTPFE_CHANNEL_OFFSET(x) + 0x28) 177 + #define C8SECTPFE_STAT_FIFO_OVERFLOW(x) (x & 0x1) 178 + #define C8SECTPFE_STAT_BUFFER_OVERFLOW(x) (x & 0x2) 179 + #define C8SECTPFE_STAT_OUTOFORDERRP(x) (x & 0x4) 180 + #define C8SECTPFE_STAT_PID_OVERFLOW(x) (x & 0x8) 181 + #define C8SECTPFE_STAT_PKT_OVERFLOW(x) (x & 0x10) 182 + #define C8SECTPFE_STAT_ERROR_PACKETS(x) ((x >> 8) & 0xf) 183 + #define C8SECTPFE_STAT_SHORT_PACKETS(x) ((x >> 12) & 0xf) 184 + 185 + #define C8SECTPFE_IB_MASK(x) (C8SECTPFE_CHANNEL_OFFSET(x) + 0x2C) 186 + #define C8SECTPFE_MASK_FIFO_OVERFLOW BIT(0) 187 + #define C8SECTPFE_MASK_BUFFER_OVERFLOW BIT(1) 188 + #define C8SECTPFE_MASK_OUTOFORDERRP(x) BIT(2) 189 + #define C8SECTPFE_MASK_PID_OVERFLOW(x) BIT(3) 190 + #define C8SECTPFE_MASK_PKT_OVERFLOW(x) BIT(4) 191 + #define C8SECTPFE_MASK_ERROR_PACKETS(x) ((x & 0xf) << 8) 192 + #define C8SECTPFE_MASK_SHORT_PACKETS(x) ((x & 0xf) >> 12) 193 + 194 + #define C8SECTPFE_IB_SYS(x) (C8SECTPFE_CHANNEL_OFFSET(x) + 0x30) 195 + #define C8SECTPFE_SYS_RESET BIT(1) 196 + #define C8SECTPFE_SYS_ENABLE BIT(0) 197 + 198 + /* 199 + * Ponter record data structure required for each input block 200 + * see Table 82 on page 167 of functional specification. 201 + */ 202 + 203 + #define DMA_PRDS_MEMBASE 0x0 /* Internal sram base address */ 204 + #define DMA_PRDS_MEMTOP 0x4 /* Internal sram top address */ 205 + 206 + /* 207 + * TS packet size, including tag bytes added by input block, 208 + * rounded up to the next multiple of 8 bytes. The packet size, 209 + * including any tagging bytes and rounded up to the nearest 210 + * multiple of 8 bytes must be less than 255 bytes. 211 + */ 212 + #define DMA_PRDS_PKTSIZE 0x8 213 + #define DMA_PRDS_TPENABLE 0xc 214 + 215 + #define TP0_OFFSET 0x10 216 + #define DMA_PRDS_BUSBASE_TP(x) ((0x10*x) + TP0_OFFSET) 217 + #define DMA_PRDS_BUSTOP_TP(x) ((0x10*x) + TP0_OFFSET + 0x4) 218 + #define DMA_PRDS_BUSWP_TP(x) ((0x10*x) + TP0_OFFSET + 0x8) 219 + #define DMA_PRDS_BUSRP_TP(x) ((0x10*x) + TP0_OFFSET + 0xc) 220 + 221 + #define DMA_PRDS_SIZE (0x20) 222 + 223 + #define DMA_MEMDMA_OFFSET 0x4000 224 + #define DMA_IMEM_OFFSET 0x0 225 + #define DMA_DMEM_OFFSET 0x4000 226 + #define DMA_CPU 0x8000 227 + #define DMA_PER_OFFSET 0xb000 228 + 229 + #define DMA_MEMDMA_DMEM (DMA_MEMDMA_OFFSET + DMA_DMEM_OFFSET) 230 + #define DMA_MEMDMA_IMEM (DMA_MEMDMA_OFFSET + DMA_IMEM_OFFSET) 231 + 232 + /* XP70 Slim core regs */ 233 + #define DMA_CPU_ID (DMA_MEMDMA_OFFSET + DMA_CPU + 0x0) 234 + #define DMA_CPU_VCR (DMA_MEMDMA_OFFSET + DMA_CPU + 0x4) 235 + #define DMA_CPU_RUN (DMA_MEMDMA_OFFSET + DMA_CPU + 0x8) 236 + #define DMA_CPU_CLOCKGATE (DMA_MEMDMA_OFFSET + DMA_CPU + 0xc) 237 + #define DMA_CPU_PC (DMA_MEMDMA_OFFSET + DMA_CPU + 0x20) 238 + 239 + /* Enable Interrupt for a IB */ 240 + #define DMA_PER_TPn_DREQ_MASK (DMA_MEMDMA_OFFSET + DMA_PER_OFFSET + 0xd00) 241 + /* Ack interrupt by setting corresponding bit */ 242 + #define DMA_PER_TPn_DACK_SET (DMA_MEMDMA_OFFSET + DMA_PER_OFFSET + 0xd80) 243 + #define DMA_PER_TPn_DREQ (DMA_MEMDMA_OFFSET + DMA_PER_OFFSET + 0xe00) 244 + #define DMA_PER_TPn_DACK (DMA_MEMDMA_OFFSET + DMA_PER_OFFSET + 0xe80) 245 + #define DMA_PER_DREQ_MODE (DMA_MEMDMA_OFFSET + DMA_PER_OFFSET + 0xf80) 246 + #define DMA_PER_STBUS_SYNC (DMA_MEMDMA_OFFSET + DMA_PER_OFFSET + 0xf88) 247 + #define DMA_PER_STBUS_ACCESS (DMA_MEMDMA_OFFSET + DMA_PER_OFFSET + 0xf8c) 248 + #define DMA_PER_STBUS_ADDRESS (DMA_MEMDMA_OFFSET + DMA_PER_OFFSET + 0xf90) 249 + #define DMA_PER_IDLE_INT (DMA_MEMDMA_OFFSET + DMA_PER_OFFSET + 0xfa8) 250 + #define DMA_PER_PRIORITY (DMA_MEMDMA_OFFSET + DMA_PER_OFFSET + 0xfac) 251 + #define DMA_PER_MAX_OPCODE (DMA_MEMDMA_OFFSET + DMA_PER_OFFSET + 0xfb0) 252 + #define DMA_PER_MAX_CHUNK (DMA_MEMDMA_OFFSET + DMA_PER_OFFSET + 0xfb4) 253 + #define DMA_PER_PAGE_SIZE (DMA_MEMDMA_OFFSET + DMA_PER_OFFSET + 0xfbc) 254 + #define DMA_PER_MBOX_STATUS (DMA_MEMDMA_OFFSET + DMA_PER_OFFSET + 0xfc0) 255 + #define DMA_PER_MBOX_SET (DMA_MEMDMA_OFFSET + DMA_PER_OFFSET + 0xfc8) 256 + #define DMA_PER_MBOX_CLEAR (DMA_MEMDMA_OFFSET + DMA_PER_OFFSET + 0xfd0) 257 + #define DMA_PER_MBOX_MASK (DMA_MEMDMA_OFFSET + DMA_PER_OFFSET + 0xfd8) 258 + #define DMA_PER_INJECT_PKT_SRC (DMA_MEMDMA_OFFSET + DMA_PER_OFFSET + 0xfe0) 259 + #define DMA_PER_INJECT_PKT_DEST (DMA_MEMDMA_OFFSET + DMA_PER_OFFSET + 0xfe4) 260 + #define DMA_PER_INJECT_PKT_ADDR (DMA_MEMDMA_OFFSET + DMA_PER_OFFSET + 0xfe8) 261 + #define DMA_PER_INJECT_PKT (DMA_MEMDMA_OFFSET + DMA_PER_OFFSET + 0xfec) 262 + #define DMA_PER_PAT_PTR_INIT (DMA_MEMDMA_OFFSET + DMA_PER_OFFSET + 0xff0) 263 + #define DMA_PER_PAT_PTR (DMA_MEMDMA_OFFSET + DMA_PER_OFFSET + 0xff4) 264 + #define DMA_PER_SLEEP_MASK (DMA_MEMDMA_OFFSET + DMA_PER_OFFSET + 0xff8) 265 + #define DMA_PER_SLEEP_COUNTER (DMA_MEMDMA_OFFSET + DMA_PER_OFFSET + 0xffc) 266 + /* #define DMA_RF_CPUREGn DMA_RFBASEADDR n=0 to 15) slim regsa */ 267 + 268 + /* The following are from DMA_DMEM_BaseAddress */ 269 + #define DMA_FIRMWARE_VERSION (DMA_MEMDMA_OFFSET + DMA_DMEM_OFFSET + 0x0) 270 + #define DMA_PTRREC_BASE (DMA_MEMDMA_OFFSET + DMA_DMEM_OFFSET + 0x4) 271 + #define DMA_PTRREC_INPUT_OFFSET (DMA_MEMDMA_OFFSET + DMA_DMEM_OFFSET + 0x8) 272 + #define DMA_ERRREC_BASE (DMA_MEMDMA_OFFSET + DMA_DMEM_OFFSET + 0xc) 273 + #define DMA_ERROR_RECORD(n) ((n*4) + DMA_ERRREC_BASE + 0x4) 274 + #define DMA_IDLE_REQ (DMA_MEMDMA_OFFSET + DMA_DMEM_OFFSET + 0x10) 275 + #define IDLEREQ BIT(31) 276 + 277 + #define DMA_FIRMWARE_CONFIG (DMA_MEMDMA_OFFSET + DMA_DMEM_OFFSET + 0x14) 278 + 279 + /* Regs for PID Filter */ 280 + 281 + #define PIDF_OFFSET 0x2800 282 + #define PIDF_BASE(n) ((n*4) + PIDF_OFFSET) 283 + #define PIDF_LEAK_ENABLE (PIDF_OFFSET + 0x100) 284 + #define PIDF_LEAK_STATUS (PIDF_OFFSET + 0x108) 285 + #define PIDF_LEAK_COUNT_RESET (PIDF_OFFSET + 0x110) 286 + #define PIDF_LEAK_COUNTER (PIDF_OFFSET + 0x114) 287 + 288 + #endif /* _C8SECTPFE_CORE_H_ */
+271
drivers/media/platform/sti/c8sectpfe/c8sectpfe-debugfs.c
··· 1 + /* 2 + * c8sectpfe-debugfs.c - C8SECTPFE STi DVB driver 3 + * 4 + * Copyright (c) STMicroelectronics 2015 5 + * 6 + * Author: Peter Griffin <peter.griffin@linaro.org> 7 + * 8 + * This program is free software: you can redistribute it and/or modify 9 + * it under the terms of the GNU General Public License version 2 of 10 + * the License as published by the Free Software Foundation. 11 + * 12 + * This program is distributed in the hope that it will be useful, 13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 + * GNU General Public License for more details. 16 + */ 17 + #include <linux/debugfs.h> 18 + #include <linux/device.h> 19 + #include <linux/interrupt.h> 20 + #include <linux/io.h> 21 + #include <linux/kernel.h> 22 + #include <linux/seq_file.h> 23 + #include <linux/slab.h> 24 + #include <linux/types.h> 25 + 26 + #include "c8sectpfe-debugfs.h" 27 + 28 + #define dump_register(nm ...) \ 29 + { \ 30 + .name = #nm, \ 31 + .offset = nm, \ 32 + } 33 + 34 + static const struct debugfs_reg32 fei_sys_regs[] = { 35 + dump_register(SYS_INPUT_ERR_STATUS), 36 + dump_register(SYS_OTHER_ERR_STATUS), 37 + dump_register(SYS_INPUT_ERR_MASK), 38 + dump_register(SYS_DMA_ROUTE), 39 + dump_register(SYS_INPUT_CLKEN), 40 + dump_register(IBENABLE_MASK), 41 + dump_register(SYS_OTHER_CLKEN), 42 + dump_register(SYS_CFG_NUM_IB), 43 + dump_register(SYS_CFG_NUM_MIB), 44 + dump_register(SYS_CFG_NUM_SWTS), 45 + dump_register(SYS_CFG_NUM_TSOUT), 46 + dump_register(SYS_CFG_NUM_CCSC), 47 + dump_register(SYS_CFG_NUM_RAM), 48 + dump_register(SYS_CFG_NUM_TP), 49 + 50 + dump_register(C8SECTPFE_IB_IP_FMT_CFG(0)), 51 + dump_register(C8SECTPFE_IB_TAGBYTES_CFG(0)), 52 + dump_register(C8SECTPFE_IB_PID_SET(0)), 53 + dump_register(C8SECTPFE_IB_PKT_LEN(0)), 54 + dump_register(C8SECTPFE_IB_BUFF_STRT(0)), 55 + dump_register(C8SECTPFE_IB_BUFF_END(0)), 56 + dump_register(C8SECTPFE_IB_READ_PNT(0)), 57 + dump_register(C8SECTPFE_IB_WRT_PNT(0)), 58 + dump_register(C8SECTPFE_IB_PRI_THRLD(0)), 59 + dump_register(C8SECTPFE_IB_STAT(0)), 60 + dump_register(C8SECTPFE_IB_MASK(0)), 61 + dump_register(C8SECTPFE_IB_SYS(0)), 62 + 63 + dump_register(C8SECTPFE_IB_IP_FMT_CFG(1)), 64 + dump_register(C8SECTPFE_IB_TAGBYTES_CFG(1)), 65 + dump_register(C8SECTPFE_IB_PID_SET(1)), 66 + dump_register(C8SECTPFE_IB_PKT_LEN(1)), 67 + dump_register(C8SECTPFE_IB_BUFF_STRT(1)), 68 + dump_register(C8SECTPFE_IB_BUFF_END(1)), 69 + dump_register(C8SECTPFE_IB_READ_PNT(1)), 70 + dump_register(C8SECTPFE_IB_WRT_PNT(1)), 71 + dump_register(C8SECTPFE_IB_PRI_THRLD(1)), 72 + dump_register(C8SECTPFE_IB_STAT(1)), 73 + dump_register(C8SECTPFE_IB_MASK(1)), 74 + dump_register(C8SECTPFE_IB_SYS(1)), 75 + 76 + dump_register(C8SECTPFE_IB_IP_FMT_CFG(2)), 77 + dump_register(C8SECTPFE_IB_TAGBYTES_CFG(2)), 78 + dump_register(C8SECTPFE_IB_PID_SET(2)), 79 + dump_register(C8SECTPFE_IB_PKT_LEN(2)), 80 + dump_register(C8SECTPFE_IB_BUFF_STRT(2)), 81 + dump_register(C8SECTPFE_IB_BUFF_END(2)), 82 + dump_register(C8SECTPFE_IB_READ_PNT(2)), 83 + dump_register(C8SECTPFE_IB_WRT_PNT(2)), 84 + dump_register(C8SECTPFE_IB_PRI_THRLD(2)), 85 + dump_register(C8SECTPFE_IB_STAT(2)), 86 + dump_register(C8SECTPFE_IB_MASK(2)), 87 + dump_register(C8SECTPFE_IB_SYS(2)), 88 + 89 + dump_register(C8SECTPFE_IB_IP_FMT_CFG(3)), 90 + dump_register(C8SECTPFE_IB_TAGBYTES_CFG(3)), 91 + dump_register(C8SECTPFE_IB_PID_SET(3)), 92 + dump_register(C8SECTPFE_IB_PKT_LEN(3)), 93 + dump_register(C8SECTPFE_IB_BUFF_STRT(3)), 94 + dump_register(C8SECTPFE_IB_BUFF_END(3)), 95 + dump_register(C8SECTPFE_IB_READ_PNT(3)), 96 + dump_register(C8SECTPFE_IB_WRT_PNT(3)), 97 + dump_register(C8SECTPFE_IB_PRI_THRLD(3)), 98 + dump_register(C8SECTPFE_IB_STAT(3)), 99 + dump_register(C8SECTPFE_IB_MASK(3)), 100 + dump_register(C8SECTPFE_IB_SYS(3)), 101 + 102 + dump_register(C8SECTPFE_IB_IP_FMT_CFG(4)), 103 + dump_register(C8SECTPFE_IB_TAGBYTES_CFG(4)), 104 + dump_register(C8SECTPFE_IB_PID_SET(4)), 105 + dump_register(C8SECTPFE_IB_PKT_LEN(4)), 106 + dump_register(C8SECTPFE_IB_BUFF_STRT(4)), 107 + dump_register(C8SECTPFE_IB_BUFF_END(4)), 108 + dump_register(C8SECTPFE_IB_READ_PNT(4)), 109 + dump_register(C8SECTPFE_IB_WRT_PNT(4)), 110 + dump_register(C8SECTPFE_IB_PRI_THRLD(4)), 111 + dump_register(C8SECTPFE_IB_STAT(4)), 112 + dump_register(C8SECTPFE_IB_MASK(4)), 113 + dump_register(C8SECTPFE_IB_SYS(4)), 114 + 115 + dump_register(C8SECTPFE_IB_IP_FMT_CFG(5)), 116 + dump_register(C8SECTPFE_IB_TAGBYTES_CFG(5)), 117 + dump_register(C8SECTPFE_IB_PID_SET(5)), 118 + dump_register(C8SECTPFE_IB_PKT_LEN(5)), 119 + dump_register(C8SECTPFE_IB_BUFF_STRT(5)), 120 + dump_register(C8SECTPFE_IB_BUFF_END(5)), 121 + dump_register(C8SECTPFE_IB_READ_PNT(5)), 122 + dump_register(C8SECTPFE_IB_WRT_PNT(5)), 123 + dump_register(C8SECTPFE_IB_PRI_THRLD(5)), 124 + dump_register(C8SECTPFE_IB_STAT(5)), 125 + dump_register(C8SECTPFE_IB_MASK(5)), 126 + dump_register(C8SECTPFE_IB_SYS(5)), 127 + 128 + dump_register(C8SECTPFE_IB_IP_FMT_CFG(6)), 129 + dump_register(C8SECTPFE_IB_TAGBYTES_CFG(6)), 130 + dump_register(C8SECTPFE_IB_PID_SET(6)), 131 + dump_register(C8SECTPFE_IB_PKT_LEN(6)), 132 + dump_register(C8SECTPFE_IB_BUFF_STRT(6)), 133 + dump_register(C8SECTPFE_IB_BUFF_END(6)), 134 + dump_register(C8SECTPFE_IB_READ_PNT(6)), 135 + dump_register(C8SECTPFE_IB_WRT_PNT(6)), 136 + dump_register(C8SECTPFE_IB_PRI_THRLD(6)), 137 + dump_register(C8SECTPFE_IB_STAT(6)), 138 + dump_register(C8SECTPFE_IB_MASK(6)), 139 + dump_register(C8SECTPFE_IB_SYS(6)), 140 + 141 + dump_register(DMA_CPU_ID), 142 + dump_register(DMA_CPU_VCR), 143 + dump_register(DMA_CPU_RUN), 144 + dump_register(DMA_CPU_PC), 145 + 146 + dump_register(DMA_PER_TPn_DREQ_MASK), 147 + dump_register(DMA_PER_TPn_DACK_SET), 148 + dump_register(DMA_PER_TPn_DREQ), 149 + dump_register(DMA_PER_TPn_DACK), 150 + dump_register(DMA_PER_DREQ_MODE), 151 + dump_register(DMA_PER_STBUS_SYNC), 152 + dump_register(DMA_PER_STBUS_ACCESS), 153 + dump_register(DMA_PER_STBUS_ADDRESS), 154 + dump_register(DMA_PER_IDLE_INT), 155 + dump_register(DMA_PER_PRIORITY), 156 + dump_register(DMA_PER_MAX_OPCODE), 157 + dump_register(DMA_PER_MAX_CHUNK), 158 + dump_register(DMA_PER_PAGE_SIZE), 159 + dump_register(DMA_PER_MBOX_STATUS), 160 + dump_register(DMA_PER_MBOX_SET), 161 + dump_register(DMA_PER_MBOX_CLEAR), 162 + dump_register(DMA_PER_MBOX_MASK), 163 + dump_register(DMA_PER_INJECT_PKT_SRC), 164 + dump_register(DMA_PER_INJECT_PKT_DEST), 165 + dump_register(DMA_PER_INJECT_PKT_ADDR), 166 + dump_register(DMA_PER_INJECT_PKT), 167 + dump_register(DMA_PER_PAT_PTR_INIT), 168 + dump_register(DMA_PER_PAT_PTR), 169 + dump_register(DMA_PER_SLEEP_MASK), 170 + dump_register(DMA_PER_SLEEP_COUNTER), 171 + 172 + dump_register(DMA_FIRMWARE_VERSION), 173 + dump_register(DMA_PTRREC_BASE), 174 + dump_register(DMA_PTRREC_INPUT_OFFSET), 175 + dump_register(DMA_ERRREC_BASE), 176 + 177 + dump_register(DMA_ERROR_RECORD(0)), 178 + dump_register(DMA_ERROR_RECORD(1)), 179 + dump_register(DMA_ERROR_RECORD(2)), 180 + dump_register(DMA_ERROR_RECORD(3)), 181 + dump_register(DMA_ERROR_RECORD(4)), 182 + dump_register(DMA_ERROR_RECORD(5)), 183 + dump_register(DMA_ERROR_RECORD(6)), 184 + dump_register(DMA_ERROR_RECORD(7)), 185 + dump_register(DMA_ERROR_RECORD(8)), 186 + dump_register(DMA_ERROR_RECORD(9)), 187 + dump_register(DMA_ERROR_RECORD(10)), 188 + dump_register(DMA_ERROR_RECORD(11)), 189 + dump_register(DMA_ERROR_RECORD(12)), 190 + dump_register(DMA_ERROR_RECORD(13)), 191 + dump_register(DMA_ERROR_RECORD(14)), 192 + dump_register(DMA_ERROR_RECORD(15)), 193 + dump_register(DMA_ERROR_RECORD(16)), 194 + dump_register(DMA_ERROR_RECORD(17)), 195 + dump_register(DMA_ERROR_RECORD(18)), 196 + dump_register(DMA_ERROR_RECORD(19)), 197 + dump_register(DMA_ERROR_RECORD(20)), 198 + dump_register(DMA_ERROR_RECORD(21)), 199 + dump_register(DMA_ERROR_RECORD(22)), 200 + 201 + dump_register(DMA_IDLE_REQ), 202 + dump_register(DMA_FIRMWARE_CONFIG), 203 + 204 + dump_register(PIDF_BASE(0)), 205 + dump_register(PIDF_BASE(1)), 206 + dump_register(PIDF_BASE(2)), 207 + dump_register(PIDF_BASE(3)), 208 + dump_register(PIDF_BASE(4)), 209 + dump_register(PIDF_BASE(5)), 210 + dump_register(PIDF_BASE(6)), 211 + dump_register(PIDF_BASE(7)), 212 + dump_register(PIDF_BASE(8)), 213 + dump_register(PIDF_BASE(9)), 214 + dump_register(PIDF_BASE(10)), 215 + dump_register(PIDF_BASE(11)), 216 + dump_register(PIDF_BASE(12)), 217 + dump_register(PIDF_BASE(13)), 218 + dump_register(PIDF_BASE(14)), 219 + dump_register(PIDF_BASE(15)), 220 + dump_register(PIDF_BASE(16)), 221 + dump_register(PIDF_BASE(17)), 222 + dump_register(PIDF_BASE(18)), 223 + dump_register(PIDF_BASE(19)), 224 + dump_register(PIDF_BASE(20)), 225 + dump_register(PIDF_BASE(21)), 226 + dump_register(PIDF_BASE(22)), 227 + dump_register(PIDF_LEAK_ENABLE), 228 + dump_register(PIDF_LEAK_STATUS), 229 + dump_register(PIDF_LEAK_COUNT_RESET), 230 + dump_register(PIDF_LEAK_COUNTER), 231 + }; 232 + 233 + void c8sectpfe_debugfs_init(struct c8sectpfei *fei) 234 + { 235 + struct dentry *root; 236 + struct dentry *file; 237 + 238 + root = debugfs_create_dir("c8sectpfe", NULL); 239 + if (!root) 240 + goto err; 241 + 242 + fei->root = root; 243 + 244 + fei->regset = devm_kzalloc(fei->dev, sizeof(*fei->regset), GFP_KERNEL); 245 + if (!fei->regset) 246 + goto err; 247 + 248 + fei->regset->regs = fei_sys_regs; 249 + fei->regset->nregs = ARRAY_SIZE(fei_sys_regs); 250 + fei->regset->base = fei->io; 251 + 252 + file = debugfs_create_regset32("registers", S_IRUGO, root, 253 + fei->regset); 254 + if (!file) { 255 + dev_err(fei->dev, 256 + "%s not able to create 'registers' debugfs\n" 257 + , __func__); 258 + goto err; 259 + } 260 + 261 + return; 262 + 263 + err: 264 + debugfs_remove_recursive(root); 265 + } 266 + 267 + void c8sectpfe_debugfs_exit(struct c8sectpfei *fei) 268 + { 269 + debugfs_remove_recursive(fei->root); 270 + fei->root = NULL; 271 + }
+26
drivers/media/platform/sti/c8sectpfe/c8sectpfe-debugfs.h
··· 1 + /** 2 + * c8sectpfe-debugfs.h - C8SECTPFE STi DVB driver debugfs header 3 + * 4 + * Copyright (c) STMicroelectronics 2015 5 + * 6 + * Authors: Peter Griffin <peter.griffin@linaro.org> 7 + * 8 + * This program is free software: you can redistribute it and/or modify 9 + * it under the terms of the GNU General Public License version 2 of 10 + * the License as published by the Free Software Foundation. 11 + * 12 + * This program is distributed in the hope that it will be useful, 13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 + * GNU General Public License for more details. 16 + */ 17 + 18 + #ifndef __C8SECTPFE_DEBUG_H 19 + #define __C8SECTPFE_DEBUG_H 20 + 21 + #include "c8sectpfe-core.h" 22 + 23 + void c8sectpfe_debugfs_init(struct c8sectpfei *); 24 + void c8sectpfe_debugfs_exit(struct c8sectpfei *); 25 + 26 + #endif /* __C8SECTPFE_DEBUG_H */
+244
drivers/media/platform/sti/c8sectpfe/c8sectpfe-dvb.c
··· 1 + /* 2 + * c8sectpfe-dvb.c - C8SECTPFE STi DVB driver 3 + * 4 + * Copyright (c) STMicroelectronics 2015 5 + * 6 + * Author Peter Griffin <peter.griffin@linaro.org> 7 + * 8 + * This program is free software; you can redistribute it and/or modify 9 + * it under the terms of the GNU General Public License as published by 10 + * the Free Software Foundation; either version 2 of the License, or 11 + * (at your option) any later version. 12 + * 13 + * This program is distributed in the hope that it will be useful, 14 + * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 + * 17 + * GNU General Public License for more details. 18 + */ 19 + #include <linux/completion.h> 20 + #include <linux/delay.h> 21 + #include <linux/i2c.h> 22 + #include <linux/interrupt.h> 23 + #include <linux/version.h> 24 + 25 + #include <dt-bindings/media/c8sectpfe.h> 26 + 27 + #include "c8sectpfe-common.h" 28 + #include "c8sectpfe-core.h" 29 + #include "c8sectpfe-dvb.h" 30 + 31 + #include "dvb-pll.h" 32 + #include "lnbh24.h" 33 + #include "stv0367.h" 34 + #include "stv0367_priv.h" 35 + #include "stv6110x.h" 36 + #include "stv090x.h" 37 + #include "tda18212.h" 38 + 39 + static inline const char *dvb_card_str(unsigned int c) 40 + { 41 + switch (c) { 42 + case STV0367_TDA18212_NIMA_1: return "STV0367_TDA18212_NIMA_1"; 43 + case STV0367_TDA18212_NIMA_2: return "STV0367_TDA18212_NIMA_2"; 44 + case STV0367_TDA18212_NIMB_1: return "STV0367_TDA18212_NIMB_1"; 45 + case STV0367_TDA18212_NIMB_2: return "STV0367_TDA18212_NIMB_2"; 46 + case STV0903_6110_LNB24_NIMA: return "STV0903_6110_LNB24_NIMA"; 47 + case STV0903_6110_LNB24_NIMB: return "STV0903_6110_LNB24_NIMB"; 48 + default: return "unknown dvb frontend card"; 49 + } 50 + } 51 + 52 + static struct stv090x_config stv090x_config = { 53 + .device = STV0903, 54 + .demod_mode = STV090x_SINGLE, 55 + .clk_mode = STV090x_CLK_EXT, 56 + .xtal = 16000000, 57 + .address = 0x69, 58 + 59 + .ts1_mode = STV090x_TSMODE_SERIAL_CONTINUOUS, 60 + .ts2_mode = STV090x_TSMODE_SERIAL_CONTINUOUS, 61 + 62 + .repeater_level = STV090x_RPTLEVEL_64, 63 + 64 + .tuner_init = NULL, 65 + .tuner_set_mode = NULL, 66 + .tuner_set_frequency = NULL, 67 + .tuner_get_frequency = NULL, 68 + .tuner_set_bandwidth = NULL, 69 + .tuner_get_bandwidth = NULL, 70 + .tuner_set_bbgain = NULL, 71 + .tuner_get_bbgain = NULL, 72 + .tuner_set_refclk = NULL, 73 + .tuner_get_status = NULL, 74 + }; 75 + 76 + static struct stv6110x_config stv6110x_config = { 77 + .addr = 0x60, 78 + .refclk = 16000000, 79 + }; 80 + 81 + #define NIMA 0 82 + #define NIMB 1 83 + 84 + static struct stv0367_config stv0367_tda18212_config[] = { 85 + { 86 + .demod_address = 0x1c, 87 + .xtal = 16000000, 88 + .if_khz = 4500, 89 + .if_iq_mode = FE_TER_NORMAL_IF_TUNER, 90 + .ts_mode = STV0367_SERIAL_PUNCT_CLOCK, 91 + .clk_pol = STV0367_CLOCKPOLARITY_DEFAULT, 92 + }, { 93 + .demod_address = 0x1d, 94 + .xtal = 16000000, 95 + .if_khz = 4500, 96 + .if_iq_mode = FE_TER_NORMAL_IF_TUNER, 97 + .ts_mode = STV0367_SERIAL_PUNCT_CLOCK, 98 + .clk_pol = STV0367_CLOCKPOLARITY_DEFAULT, 99 + }, { 100 + .demod_address = 0x1e, 101 + .xtal = 16000000, 102 + .if_khz = 4500, 103 + .if_iq_mode = FE_TER_NORMAL_IF_TUNER, 104 + .ts_mode = STV0367_SERIAL_PUNCT_CLOCK, 105 + .clk_pol = STV0367_CLOCKPOLARITY_DEFAULT, 106 + }, 107 + }; 108 + 109 + static struct tda18212_config tda18212_conf = { 110 + .if_dvbt_6 = 4150, 111 + .if_dvbt_7 = 4150, 112 + .if_dvbt_8 = 4500, 113 + .if_dvbc = 5000, 114 + }; 115 + 116 + int c8sectpfe_frontend_attach(struct dvb_frontend **fe, 117 + struct c8sectpfe *c8sectpfe, 118 + struct channel_info *tsin, int chan_num) 119 + { 120 + struct tda18212_config *tda18212; 121 + struct stv6110x_devctl *fe2; 122 + struct i2c_client *client; 123 + struct i2c_board_info tda18212_info = { 124 + .type = "tda18212", 125 + .addr = 0x60, 126 + }; 127 + 128 + if (!tsin) 129 + return -EINVAL; 130 + 131 + switch (tsin->dvb_card) { 132 + 133 + case STV0367_TDA18212_NIMA_1: 134 + case STV0367_TDA18212_NIMA_2: 135 + case STV0367_TDA18212_NIMB_1: 136 + case STV0367_TDA18212_NIMB_2: 137 + if (tsin->dvb_card == STV0367_TDA18212_NIMA_1) 138 + *fe = dvb_attach(stv0367ter_attach, 139 + &stv0367_tda18212_config[0], 140 + tsin->i2c_adapter); 141 + else if (tsin->dvb_card == STV0367_TDA18212_NIMB_1) 142 + *fe = dvb_attach(stv0367ter_attach, 143 + &stv0367_tda18212_config[1], 144 + tsin->i2c_adapter); 145 + else 146 + *fe = dvb_attach(stv0367ter_attach, 147 + &stv0367_tda18212_config[2], 148 + tsin->i2c_adapter); 149 + 150 + if (!*fe) { 151 + dev_err(c8sectpfe->device, 152 + "%s: stv0367ter_attach failed for NIM card %s\n" 153 + , __func__, dvb_card_str(tsin->dvb_card)); 154 + return -ENODEV; 155 + }; 156 + 157 + /* 158 + * init the demod so that i2c gate_ctrl 159 + * to the tuner works correctly 160 + */ 161 + (*fe)->ops.init(*fe); 162 + 163 + /* Allocate the tda18212 structure */ 164 + tda18212 = devm_kzalloc(c8sectpfe->device, 165 + sizeof(struct tda18212_config), 166 + GFP_KERNEL); 167 + if (!tda18212) { 168 + dev_err(c8sectpfe->device, 169 + "%s: devm_kzalloc failed\n", __func__); 170 + return -ENOMEM; 171 + } 172 + 173 + memcpy(tda18212, &tda18212_conf, 174 + sizeof(struct tda18212_config)); 175 + 176 + tda18212->fe = (*fe); 177 + 178 + tda18212_info.platform_data = tda18212; 179 + 180 + /* attach tuner */ 181 + request_module("tda18212"); 182 + client = i2c_new_device(tsin->i2c_adapter, &tda18212_info); 183 + if (!client || !client->dev.driver) { 184 + dvb_frontend_detach(*fe); 185 + return -ENODEV; 186 + } 187 + 188 + if (!try_module_get(client->dev.driver->owner)) { 189 + i2c_unregister_device(client); 190 + dvb_frontend_detach(*fe); 191 + return -ENODEV; 192 + } 193 + 194 + tsin->i2c_client = client; 195 + 196 + break; 197 + 198 + case STV0903_6110_LNB24_NIMA: 199 + *fe = dvb_attach(stv090x_attach, &stv090x_config, 200 + tsin->i2c_adapter, STV090x_DEMODULATOR_0); 201 + if (!*fe) { 202 + dev_err(c8sectpfe->device, "%s: stv090x_attach failed\n" 203 + "\tfor NIM card %s\n", 204 + __func__, dvb_card_str(tsin->dvb_card)); 205 + return -ENODEV; 206 + } 207 + 208 + fe2 = dvb_attach(stv6110x_attach, *fe, 209 + &stv6110x_config, tsin->i2c_adapter); 210 + if (!fe2) { 211 + dev_err(c8sectpfe->device, 212 + "%s: stv6110x_attach failed for NIM card %s\n" 213 + , __func__, dvb_card_str(tsin->dvb_card)); 214 + return -ENODEV; 215 + }; 216 + 217 + stv090x_config.tuner_init = fe2->tuner_init; 218 + stv090x_config.tuner_set_mode = fe2->tuner_set_mode; 219 + stv090x_config.tuner_set_frequency = fe2->tuner_set_frequency; 220 + stv090x_config.tuner_get_frequency = fe2->tuner_get_frequency; 221 + stv090x_config.tuner_set_bandwidth = fe2->tuner_set_bandwidth; 222 + stv090x_config.tuner_get_bandwidth = fe2->tuner_get_bandwidth; 223 + stv090x_config.tuner_set_bbgain = fe2->tuner_set_bbgain; 224 + stv090x_config.tuner_get_bbgain = fe2->tuner_get_bbgain; 225 + stv090x_config.tuner_set_refclk = fe2->tuner_set_refclk; 226 + stv090x_config.tuner_get_status = fe2->tuner_get_status; 227 + 228 + dvb_attach(lnbh24_attach, *fe, tsin->i2c_adapter, 0, 0, 0x9); 229 + break; 230 + 231 + default: 232 + dev_err(c8sectpfe->device, 233 + "%s: DVB frontend card %s not yet supported\n", 234 + __func__, dvb_card_str(tsin->dvb_card)); 235 + return -ENODEV; 236 + } 237 + 238 + (*fe)->id = chan_num; 239 + 240 + dev_info(c8sectpfe->device, 241 + "DVB frontend card %s successfully attached", 242 + dvb_card_str(tsin->dvb_card)); 243 + return 0; 244 + }
+20
drivers/media/platform/sti/c8sectpfe/c8sectpfe-dvb.h
··· 1 + /* 2 + * c8sectpfe-common.h - C8SECTPFE STi DVB driver 3 + * 4 + * Copyright (c) STMicroelectronics 2015 5 + * 6 + * Author: Peter Griffin <peter.griffin@linaro.org> 7 + * 8 + * This program is free software; you can redistribute it and/or 9 + * modify it under the terms of the GNU General Public License as 10 + * published by the Free Software Foundation; either version 2 of 11 + * the License, or (at your option) any later version. 12 + */ 13 + #ifndef _C8SECTPFE_DVB_H_ 14 + #define _C8SECTPFE_DVB_H_ 15 + 16 + int c8sectpfe_frontend_attach(struct dvb_frontend **fe, 17 + struct c8sectpfe *c8sectpfe, struct channel_info *tsin, 18 + int chan_num); 19 + 20 + #endif
+1 -1
drivers/media/platform/vivid/vivid-vid-cap.c
··· 1627 1627 h_freq = (u32)bt->pixelclock / total_h_pixel; 1628 1628 1629 1629 if (bt->standards == 0 || (bt->standards & V4L2_DV_BT_STD_CVT)) { 1630 - if (v4l2_detect_cvt(total_v_lines, h_freq, bt->vsync, 1630 + if (v4l2_detect_cvt(total_v_lines, h_freq, bt->vsync, bt->width, 1631 1631 bt->polarities, bt->interlaced, timings)) 1632 1632 return true; 1633 1633 }
+13 -2
drivers/media/platform/vivid/vivid-vid-out.c
··· 1124 1124 return 0; 1125 1125 } 1126 1126 1127 + static bool valid_cvt_gtf_timings(struct v4l2_dv_timings *timings) 1128 + { 1129 + struct v4l2_bt_timings *bt = &timings->bt; 1130 + 1131 + if ((bt->standards & (V4L2_DV_BT_STD_CVT | V4L2_DV_BT_STD_GTF)) && 1132 + v4l2_valid_dv_timings(timings, &vivid_dv_timings_cap, NULL, NULL)) 1133 + return true; 1134 + 1135 + return false; 1136 + } 1137 + 1127 1138 int vivid_vid_out_s_dv_timings(struct file *file, void *_fh, 1128 1139 struct v4l2_dv_timings *timings) 1129 1140 { 1130 1141 struct vivid_dev *dev = video_drvdata(file); 1131 - 1132 1142 if (!vivid_is_hdmi_out(dev)) 1133 1143 return -ENODATA; 1134 1144 if (!v4l2_find_dv_timings_cap(timings, &vivid_dv_timings_cap, 1135 - 0, NULL, NULL)) 1145 + 0, NULL, NULL) && 1146 + !valid_cvt_gtf_timings(timings)) 1136 1147 return -EINVAL; 1137 1148 if (v4l2_match_dv_timings(timings, &dev->dv_timings_out, 0)) 1138 1149 return 0;
+10 -3
drivers/media/platform/vsp1/vsp1_drv.c
··· 1 1 /* 2 2 * vsp1_drv.c -- R-Car VSP1 Driver 3 3 * 4 - * Copyright (C) 2013-2014 Renesas Electronics Corporation 4 + * Copyright (C) 2013-2015 Renesas Electronics Corporation 5 5 * 6 6 * Contact: Laurent Pinchart (laurent.pinchart@ideasonboard.com) 7 7 * ··· 403 403 if (vsp1->ref_count == 0) 404 404 return 0; 405 405 406 + vsp1_pipelines_suspend(vsp1); 407 + 406 408 clk_disable_unprepare(vsp1->clock); 409 + 407 410 return 0; 408 411 } 409 412 ··· 416 413 417 414 WARN_ON(mutex_is_locked(&vsp1->lock)); 418 415 419 - if (vsp1->ref_count) 416 + if (vsp1->ref_count == 0) 420 417 return 0; 421 418 422 - return clk_prepare_enable(vsp1->clock); 419 + clk_prepare_enable(vsp1->clock); 420 + 421 + vsp1_pipelines_resume(vsp1); 422 + 423 + return 0; 423 424 } 424 425 #endif 425 426
+9 -9
drivers/media/platform/vsp1/vsp1_entity.c
··· 24 24 25 25 bool vsp1_entity_is_streaming(struct vsp1_entity *entity) 26 26 { 27 + unsigned long flags; 27 28 bool streaming; 28 29 29 - mutex_lock(&entity->lock); 30 + spin_lock_irqsave(&entity->lock, flags); 30 31 streaming = entity->streaming; 31 - mutex_unlock(&entity->lock); 32 + spin_unlock_irqrestore(&entity->lock, flags); 32 33 33 34 return streaming; 34 35 } 35 36 36 37 int vsp1_entity_set_streaming(struct vsp1_entity *entity, bool streaming) 37 38 { 39 + unsigned long flags; 38 40 int ret; 39 41 40 - mutex_lock(&entity->lock); 42 + spin_lock_irqsave(&entity->lock, flags); 41 43 entity->streaming = streaming; 42 - mutex_unlock(&entity->lock); 44 + spin_unlock_irqrestore(&entity->lock, flags); 43 45 44 46 if (!streaming) 45 47 return 0; ··· 51 49 52 50 ret = v4l2_ctrl_handler_setup(entity->subdev.ctrl_handler); 53 51 if (ret < 0) { 54 - mutex_lock(&entity->lock); 52 + spin_lock_irqsave(&entity->lock, flags); 55 53 entity->streaming = false; 56 - mutex_unlock(&entity->lock); 54 + spin_unlock_irqrestore(&entity->lock, flags); 57 55 } 58 56 59 57 return ret; ··· 195 193 if (i == ARRAY_SIZE(vsp1_routes)) 196 194 return -EINVAL; 197 195 198 - mutex_init(&entity->lock); 196 + spin_lock_init(&entity->lock); 199 197 200 198 entity->vsp1 = vsp1; 201 199 entity->source_pad = num_pads - 1; ··· 230 228 if (entity->subdev.ctrl_handler) 231 229 v4l2_ctrl_handler_free(entity->subdev.ctrl_handler); 232 230 media_entity_cleanup(&entity->subdev.entity); 233 - 234 - mutex_destroy(&entity->lock); 235 231 }
+2 -2
drivers/media/platform/vsp1/vsp1_entity.h
··· 14 14 #define __VSP1_ENTITY_H__ 15 15 16 16 #include <linux/list.h> 17 - #include <linux/mutex.h> 17 + #include <linux/spinlock.h> 18 18 19 19 #include <media/v4l2-subdev.h> 20 20 ··· 73 73 74 74 struct vsp1_video *video; 75 75 76 - struct mutex lock; /* Protects the streaming field */ 76 + spinlock_t lock; /* Protects the streaming field */ 77 77 bool streaming; 78 78 }; 79 79
+3 -3
drivers/media/platform/vsp1/vsp1_regs.h
··· 238 238 #define VI6_WPF_SZCLIP_EN (1 << 28) 239 239 #define VI6_WPF_SZCLIP_OFST_MASK (0xff << 16) 240 240 #define VI6_WPF_SZCLIP_OFST_SHIFT 16 241 - #define VI6_WPF_SZCLIP_SIZE_MASK (0x1fff << 0) 241 + #define VI6_WPF_SZCLIP_SIZE_MASK (0xfff << 0) 242 242 #define VI6_WPF_SZCLIP_SIZE_SHIFT 0 243 243 244 244 #define VI6_WPF_OUTFMT 0x100c ··· 304 304 #define VI6_DPR_HST_ROUTE 0x2044 305 305 #define VI6_DPR_HSI_ROUTE 0x2048 306 306 #define VI6_DPR_BRU_ROUTE 0x204c 307 - #define VI6_DPR_ROUTE_FXA_MASK (0xff << 8) 307 + #define VI6_DPR_ROUTE_FXA_MASK (0xff << 16) 308 308 #define VI6_DPR_ROUTE_FXA_SHIFT 16 309 - #define VI6_DPR_ROUTE_FP_MASK (0xff << 8) 309 + #define VI6_DPR_ROUTE_FP_MASK (0x3f << 8) 310 310 #define VI6_DPR_ROUTE_FP_SHIFT 8 311 311 #define VI6_DPR_ROUTE_RT_MASK (0x3f << 0) 312 312 #define VI6_DPR_ROUTE_RT_SHIFT 0
+11
drivers/media/platform/vsp1/vsp1_rwpf.c
··· 197 197 */ 198 198 format = vsp1_entity_get_pad_format(&rwpf->entity, cfg, RWPF_PAD_SINK, 199 199 sel->which); 200 + 201 + /* Restrict the crop rectangle coordinates to multiples of 2 to avoid 202 + * shifting the color plane. 203 + */ 204 + if (format->code == MEDIA_BUS_FMT_AYUV8_1X32) { 205 + sel->r.left = ALIGN(sel->r.left, 2); 206 + sel->r.top = ALIGN(sel->r.top, 2); 207 + sel->r.width = round_down(sel->r.width, 2); 208 + sel->r.height = round_down(sel->r.height, 2); 209 + } 210 + 200 211 sel->r.left = min_t(unsigned int, sel->r.left, format->width - 2); 201 212 sel->r.top = min_t(unsigned int, sel->r.top, format->height - 2); 202 213 if (rwpf->entity.type == VSP1_ENTITY_WPF) {
+82 -3
drivers/media/platform/vsp1/vsp1_video.c
··· 1 1 /* 2 2 * vsp1_video.c -- R-Car VSP1 Video Node 3 3 * 4 - * Copyright (C) 2013-2014 Renesas Electronics Corporation 4 + * Copyright (C) 2013-2015 Renesas Electronics Corporation 5 5 * 6 6 * Contact: Laurent Pinchart (laurent.pinchart@ideasonboard.com) 7 7 * ··· 245 245 * the datasheet, strides not aligned to a multiple of 128 bytes result 246 246 * in image corruption. 247 247 */ 248 - for (i = 0; i < max(info->planes, 2U); ++i) { 248 + for (i = 0; i < min(info->planes, 2U); ++i) { 249 249 unsigned int hsub = i > 0 ? info->hsub : 1; 250 250 unsigned int vsub = i > 0 ? info->vsub : 1; 251 251 unsigned int align = 128; ··· 514 514 pipe->buffers_ready = 0; 515 515 } 516 516 517 + static bool vsp1_pipeline_stopped(struct vsp1_pipeline *pipe) 518 + { 519 + unsigned long flags; 520 + bool stopped; 521 + 522 + spin_lock_irqsave(&pipe->irqlock, flags); 523 + stopped = pipe->state == VSP1_PIPELINE_STOPPED, 524 + spin_unlock_irqrestore(&pipe->irqlock, flags); 525 + 526 + return stopped; 527 + } 528 + 517 529 static int vsp1_pipeline_stop(struct vsp1_pipeline *pipe) 518 530 { 519 531 struct vsp1_entity *entity; ··· 537 525 pipe->state = VSP1_PIPELINE_STOPPING; 538 526 spin_unlock_irqrestore(&pipe->irqlock, flags); 539 527 540 - ret = wait_event_timeout(pipe->wq, pipe->state == VSP1_PIPELINE_STOPPED, 528 + ret = wait_event_timeout(pipe->wq, vsp1_pipeline_stopped(pipe), 541 529 msecs_to_jiffies(500)); 542 530 ret = ret == 0 ? -ETIMEDOUT : 0; 543 531 ··· 712 700 713 701 pad = &entity->pads[entity->source_pad]; 714 702 pad = media_entity_remote_pad(pad); 703 + } 704 + } 705 + 706 + void vsp1_pipelines_suspend(struct vsp1_device *vsp1) 707 + { 708 + unsigned long flags; 709 + unsigned int i; 710 + int ret; 711 + 712 + /* To avoid increasing the system suspend time needlessly, loop over the 713 + * pipelines twice, first to set them all to the stopping state, and then 714 + * to wait for the stop to complete. 715 + */ 716 + for (i = 0; i < vsp1->pdata.wpf_count; ++i) { 717 + struct vsp1_rwpf *wpf = vsp1->wpf[i]; 718 + struct vsp1_pipeline *pipe; 719 + 720 + if (wpf == NULL) 721 + continue; 722 + 723 + pipe = to_vsp1_pipeline(&wpf->entity.subdev.entity); 724 + if (pipe == NULL) 725 + continue; 726 + 727 + spin_lock_irqsave(&pipe->irqlock, flags); 728 + if (pipe->state == VSP1_PIPELINE_RUNNING) 729 + pipe->state = VSP1_PIPELINE_STOPPING; 730 + spin_unlock_irqrestore(&pipe->irqlock, flags); 731 + } 732 + 733 + for (i = 0; i < vsp1->pdata.wpf_count; ++i) { 734 + struct vsp1_rwpf *wpf = vsp1->wpf[i]; 735 + struct vsp1_pipeline *pipe; 736 + 737 + if (wpf == NULL) 738 + continue; 739 + 740 + pipe = to_vsp1_pipeline(&wpf->entity.subdev.entity); 741 + if (pipe == NULL) 742 + continue; 743 + 744 + ret = wait_event_timeout(pipe->wq, vsp1_pipeline_stopped(pipe), 745 + msecs_to_jiffies(500)); 746 + if (ret == 0) 747 + dev_warn(vsp1->dev, "pipeline %u stop timeout\n", 748 + wpf->entity.index); 749 + } 750 + } 751 + 752 + void vsp1_pipelines_resume(struct vsp1_device *vsp1) 753 + { 754 + unsigned int i; 755 + 756 + /* Resume pipeline all running pipelines. */ 757 + for (i = 0; i < vsp1->pdata.wpf_count; ++i) { 758 + struct vsp1_rwpf *wpf = vsp1->wpf[i]; 759 + struct vsp1_pipeline *pipe; 760 + 761 + if (wpf == NULL) 762 + continue; 763 + 764 + pipe = to_vsp1_pipeline(&wpf->entity.subdev.entity); 765 + if (pipe == NULL) 766 + continue; 767 + 768 + if (vsp1_pipeline_ready(pipe)) 769 + vsp1_pipeline_run(pipe); 715 770 } 716 771 } 717 772
+4 -1
drivers/media/platform/vsp1/vsp1_video.h
··· 1 1 /* 2 2 * vsp1_video.h -- R-Car VSP1 Video Node 3 3 * 4 - * Copyright (C) 2013-2014 Renesas Electronics Corporation 4 + * Copyright (C) 2013-2015 Renesas Electronics Corporation 5 5 * 6 6 * Contact: Laurent Pinchart (laurent.pinchart@ideasonboard.com) 7 7 * ··· 148 148 void vsp1_pipeline_propagate_alpha(struct vsp1_pipeline *pipe, 149 149 struct vsp1_entity *input, 150 150 unsigned int alpha); 151 + 152 + void vsp1_pipelines_suspend(struct vsp1_device *vsp1); 153 + void vsp1_pipelines_resume(struct vsp1_device *vsp1); 151 154 152 155 #endif /* __VSP1_VIDEO_H__ */
+3 -1
drivers/media/platform/xilinx/xilinx-dma.c
··· 699 699 700 700 /* ... and the buffers queue... */ 701 701 dma->alloc_ctx = vb2_dma_contig_init_ctx(dma->xdev->dev); 702 - if (IS_ERR(dma->alloc_ctx)) 702 + if (IS_ERR(dma->alloc_ctx)) { 703 + ret = PTR_ERR(dma->alloc_ctx); 703 704 goto error; 705 + } 704 706 705 707 /* Don't enable VB2_READ and VB2_WRITE, as using the read() and write() 706 708 * V4L2 APIs would be inefficient. Testing on the command line with a
-1
drivers/media/radio/radio-tea5764.c
··· 526 526 static struct i2c_driver tea5764_i2c_driver = { 527 527 .driver = { 528 528 .name = "radio-tea5764", 529 - .owner = THIS_MODULE, 530 529 }, 531 530 .probe = tea5764_i2c_probe, 532 531 .remove = tea5764_i2c_remove,
+2 -15
drivers/media/radio/saa7706h.c
··· 336 336 .s_ctrl = saa7706h_s_ctrl, 337 337 }; 338 338 339 - static const struct v4l2_subdev_core_ops saa7706h_core_ops = { 340 - .g_ext_ctrls = v4l2_subdev_g_ext_ctrls, 341 - .try_ext_ctrls = v4l2_subdev_try_ext_ctrls, 342 - .s_ext_ctrls = v4l2_subdev_s_ext_ctrls, 343 - .g_ctrl = v4l2_subdev_g_ctrl, 344 - .s_ctrl = v4l2_subdev_s_ctrl, 345 - .queryctrl = v4l2_subdev_queryctrl, 346 - .querymenu = v4l2_subdev_querymenu, 347 - }; 348 - 349 - static const struct v4l2_subdev_ops saa7706h_ops = { 350 - .core = &saa7706h_core_ops, 351 - }; 339 + static const struct v4l2_subdev_ops empty_ops = {}; 352 340 353 341 /* 354 342 * Generic i2c probe ··· 361 373 if (state == NULL) 362 374 return -ENOMEM; 363 375 sd = &state->sd; 364 - v4l2_i2c_subdev_init(sd, client, &saa7706h_ops); 376 + v4l2_i2c_subdev_init(sd, client, &empty_ops); 365 377 366 378 v4l2_ctrl_handler_init(&state->hdl, 4); 367 379 v4l2_ctrl_new_std(&state->hdl, &saa7706h_ctrl_ops, ··· 417 429 418 430 static struct i2c_driver saa7706h_driver = { 419 431 .driver = { 420 - .owner = THIS_MODULE, 421 432 .name = DRIVER_NAME, 422 433 }, 423 434 .probe = saa7706h_probe,
-1
drivers/media/radio/tef6862.c
··· 195 195 196 196 static struct i2c_driver tef6862_driver = { 197 197 .driver = { 198 - .owner = THIS_MODULE, 199 198 .name = DRIVER_NAME, 200 199 }, 201 200 .probe = tef6862_probe,
+1 -4
drivers/media/radio/wl128x/fmdrv_common.c
··· 689 689 static void fm_rdsparse_swapbytes(struct fmdev *fmdev, 690 690 struct fm_rdsdata_format *rds_format) 691 691 { 692 - u8 byte1; 693 692 u8 index = 0; 694 693 u8 *rds_buff; 695 694 ··· 700 701 if (fmdev->asci_id != 0x6350) { 701 702 rds_buff = &rds_format->data.groupdatabuff.buff[0]; 702 703 while (index + 1 < FM_RX_RDS_INFO_FIELD_MAX) { 703 - byte1 = rds_buff[index]; 704 - rds_buff[index] = rds_buff[index + 1]; 705 - rds_buff[index + 1] = byte1; 704 + swap(rds_buff[index], rds_buff[index + 1]); 706 705 index += 2; 707 706 } 708 707 }
+12 -12
drivers/media/rc/Kconfig
··· 371 371 tristate "ST remote control receiver" 372 372 depends on RC_CORE 373 373 depends on ARCH_STI || COMPILE_TEST 374 - help 375 - Say Y here if you want support for ST remote control driver 376 - which allows both IR and UHF RX. 377 - The driver passes raw pulse and space information to the LIRC decoder. 374 + ---help--- 375 + Say Y here if you want support for ST remote control driver 376 + which allows both IR and UHF RX. 377 + The driver passes raw pulse and space information to the LIRC decoder. 378 378 379 - If you're not sure, select N here. 379 + If you're not sure, select N here. 380 380 381 381 config IR_SUNXI 382 - tristate "SUNXI IR remote control" 383 - depends on RC_CORE 384 - depends on ARCH_SUNXI || COMPILE_TEST 385 - ---help--- 386 - Say Y if you want to use sunXi internal IR Controller 382 + tristate "SUNXI IR remote control" 383 + depends on RC_CORE 384 + depends on ARCH_SUNXI || COMPILE_TEST 385 + ---help--- 386 + Say Y if you want to use sunXi internal IR Controller 387 387 388 - To compile this driver as a module, choose M here: the module will 389 - be called sunxi-ir. 388 + To compile this driver as a module, choose M here: the module will 389 + be called sunxi-ir. 390 390 391 391 endif #RC_DEVICES
+1 -4
drivers/media/rc/ir-lirc-codec.c
··· 35 35 struct lirc_codec *lirc = &dev->raw->lirc; 36 36 int sample; 37 37 38 - if (!(dev->enabled_protocols & RC_BIT_LIRC)) 39 - return 0; 40 - 41 38 if (!dev->raw->lirc.drv || !dev->raw->lirc.drv->rbuf) 42 39 return -EINVAL; 43 40 ··· 421 424 } 422 425 423 426 static struct ir_raw_handler lirc_handler = { 424 - .protocols = RC_BIT_LIRC, 427 + .protocols = 0, 425 428 .decode = ir_lirc_decode, 426 429 .raw_register = ir_lirc_register, 427 430 .raw_unregister = ir_lirc_unregister,
+1 -1
drivers/media/rc/keymaps/rc-lirc.c
··· 20 20 .map = { 21 21 .scan = lirc, 22 22 .size = ARRAY_SIZE(lirc), 23 - .rc_type = RC_TYPE_LIRC, 23 + .rc_type = RC_TYPE_OTHER, 24 24 .name = RC_MAP_LIRC, 25 25 } 26 26 };
+66 -66
drivers/media/rc/keymaps/rc-lme2510.c
··· 15 15 16 16 static struct rc_map_table lme2510_rc[] = { 17 17 /* Type 1 - 26 buttons */ 18 - { 0x10ed45, KEY_0 }, 19 - { 0x10ed5f, KEY_1 }, 20 - { 0x10ed50, KEY_2 }, 21 - { 0x10ed5d, KEY_3 }, 22 - { 0x10ed41, KEY_4 }, 23 - { 0x10ed0a, KEY_5 }, 24 - { 0x10ed42, KEY_6 }, 25 - { 0x10ed47, KEY_7 }, 26 - { 0x10ed49, KEY_8 }, 27 - { 0x10ed05, KEY_9 }, 28 - { 0x10ed43, KEY_POWER }, 29 - { 0x10ed46, KEY_SUBTITLE }, 30 - { 0x10ed06, KEY_PAUSE }, 31 - { 0x10ed03, KEY_MEDIA_REPEAT}, 32 - { 0x10ed02, KEY_PAUSE }, 33 - { 0x10ed5e, KEY_VOLUMEUP }, 34 - { 0x10ed5c, KEY_VOLUMEDOWN }, 35 - { 0x10ed09, KEY_CHANNELUP }, 36 - { 0x10ed1a, KEY_CHANNELDOWN }, 37 - { 0x10ed1e, KEY_PLAY }, 38 - { 0x10ed1b, KEY_ZOOM }, 39 - { 0x10ed59, KEY_MUTE }, 40 - { 0x10ed5a, KEY_TV }, 41 - { 0x10ed18, KEY_RECORD }, 42 - { 0x10ed07, KEY_EPG }, 43 - { 0x10ed01, KEY_STOP }, 18 + { 0xef12ba45, KEY_0 }, 19 + { 0xef12a05f, KEY_1 }, 20 + { 0xef12af50, KEY_2 }, 21 + { 0xef12a25d, KEY_3 }, 22 + { 0xef12be41, KEY_4 }, 23 + { 0xef12f50a, KEY_5 }, 24 + { 0xef12bd42, KEY_6 }, 25 + { 0xef12b847, KEY_7 }, 26 + { 0xef12b649, KEY_8 }, 27 + { 0xef12fa05, KEY_9 }, 28 + { 0xef12bc43, KEY_POWER }, 29 + { 0xef12b946, KEY_SUBTITLE }, 30 + { 0xef12f906, KEY_PAUSE }, 31 + { 0xef12fc03, KEY_MEDIA_REPEAT}, 32 + { 0xef12fd02, KEY_PAUSE }, 33 + { 0xef12a15e, KEY_VOLUMEUP }, 34 + { 0xef12a35c, KEY_VOLUMEDOWN }, 35 + { 0xef12f609, KEY_CHANNELUP }, 36 + { 0xef12e51a, KEY_CHANNELDOWN }, 37 + { 0xef12e11e, KEY_PLAY }, 38 + { 0xef12e41b, KEY_ZOOM }, 39 + { 0xef12a659, KEY_MUTE }, 40 + { 0xef12a55a, KEY_TV }, 41 + { 0xef12e718, KEY_RECORD }, 42 + { 0xef12f807, KEY_EPG }, 43 + { 0xef12fe01, KEY_STOP }, 44 44 /* Type 2 - 20 buttons */ 45 - { 0xbf15, KEY_0 }, 46 - { 0xbf08, KEY_1 }, 47 - { 0xbf09, KEY_2 }, 48 - { 0xbf0a, KEY_3 }, 49 - { 0xbf0c, KEY_4 }, 50 - { 0xbf0d, KEY_5 }, 51 - { 0xbf0e, KEY_6 }, 52 - { 0xbf10, KEY_7 }, 53 - { 0xbf11, KEY_8 }, 54 - { 0xbf12, KEY_9 }, 55 - { 0xbf00, KEY_POWER }, 56 - { 0xbf04, KEY_MEDIA_REPEAT}, /* Recall */ 57 - { 0xbf1a, KEY_PAUSE }, /* Timeshift */ 58 - { 0xbf02, KEY_VOLUMEUP }, /* 2 x -/+ Keys not marked */ 59 - { 0xbf06, KEY_VOLUMEDOWN }, /* Volume defined as right hand*/ 60 - { 0xbf01, KEY_CHANNELUP }, 61 - { 0xbf05, KEY_CHANNELDOWN }, 62 - { 0xbf14, KEY_ZOOM }, 63 - { 0xbf18, KEY_RECORD }, 64 - { 0xbf16, KEY_STOP }, 45 + { 0xff40ea15, KEY_0 }, 46 + { 0xff40f708, KEY_1 }, 47 + { 0xff40f609, KEY_2 }, 48 + { 0xff40f50a, KEY_3 }, 49 + { 0xff40f30c, KEY_4 }, 50 + { 0xff40f20d, KEY_5 }, 51 + { 0xff40f10e, KEY_6 }, 52 + { 0xff40ef10, KEY_7 }, 53 + { 0xff40ee11, KEY_8 }, 54 + { 0xff40ed12, KEY_9 }, 55 + { 0xff40ff00, KEY_POWER }, 56 + { 0xff40fb04, KEY_MEDIA_REPEAT}, /* Recall */ 57 + { 0xff40e51a, KEY_PAUSE }, /* Timeshift */ 58 + { 0xff40fd02, KEY_VOLUMEUP }, /* 2 x -/+ Keys not marked */ 59 + { 0xff40f906, KEY_VOLUMEDOWN }, /* Volume defined as right hand*/ 60 + { 0xff40fe01, KEY_CHANNELUP }, 61 + { 0xff40fa05, KEY_CHANNELDOWN }, 62 + { 0xff40eb14, KEY_ZOOM }, 63 + { 0xff40e718, KEY_RECORD }, 64 + { 0xff40e916, KEY_STOP }, 65 65 /* Type 3 - 20 buttons */ 66 - { 0x1c, KEY_0 }, 67 - { 0x07, KEY_1 }, 68 - { 0x15, KEY_2 }, 69 - { 0x09, KEY_3 }, 70 - { 0x16, KEY_4 }, 71 - { 0x19, KEY_5 }, 72 - { 0x0d, KEY_6 }, 73 - { 0x0c, KEY_7 }, 74 - { 0x18, KEY_8 }, 75 - { 0x5e, KEY_9 }, 76 - { 0x45, KEY_POWER }, 77 - { 0x44, KEY_MEDIA_REPEAT}, /* Recall */ 78 - { 0x4a, KEY_PAUSE }, /* Timeshift */ 79 - { 0x47, KEY_VOLUMEUP }, /* 2 x -/+ Keys not marked */ 80 - { 0x43, KEY_VOLUMEDOWN }, /* Volume defined as right hand*/ 81 - { 0x46, KEY_CHANNELUP }, 82 - { 0x40, KEY_CHANNELDOWN }, 83 - { 0x08, KEY_ZOOM }, 84 - { 0x42, KEY_RECORD }, 85 - { 0x5a, KEY_STOP }, 66 + { 0xff00e31c, KEY_0 }, 67 + { 0xff00f807, KEY_1 }, 68 + { 0xff00ea15, KEY_2 }, 69 + { 0xff00f609, KEY_3 }, 70 + { 0xff00e916, KEY_4 }, 71 + { 0xff00e619, KEY_5 }, 72 + { 0xff00f20d, KEY_6 }, 73 + { 0xff00f30c, KEY_7 }, 74 + { 0xff00e718, KEY_8 }, 75 + { 0xff00a15e, KEY_9 }, 76 + { 0xff00ba45, KEY_POWER }, 77 + { 0xff00bb44, KEY_MEDIA_REPEAT}, /* Recall */ 78 + { 0xff00b54a, KEY_PAUSE }, /* Timeshift */ 79 + { 0xff00b847, KEY_VOLUMEUP }, /* 2 x -/+ Keys not marked */ 80 + { 0xff00bc43, KEY_VOLUMEDOWN }, /* Volume defined as right hand*/ 81 + { 0xff00b946, KEY_CHANNELUP }, 82 + { 0xff00bf40, KEY_CHANNELDOWN }, 83 + { 0xff00f708, KEY_ZOOM }, 84 + { 0xff00bd42, KEY_RECORD }, 85 + { 0xff00a55a, KEY_STOP }, 86 86 }; 87 87 88 88 static struct rc_map_list lme2510_map = {
+1 -1
drivers/media/rc/rc-ir-raw.c
··· 271 271 272 272 spin_lock_init(&dev->raw->lock); 273 273 dev->raw->thread = kthread_run(ir_raw_event_thread, dev->raw, 274 - "rc%ld", dev->devno); 274 + "rc%u", dev->minor); 275 275 276 276 if (IS_ERR(dev->raw->thread)) { 277 277 rc = PTR_ERR(dev->raw->thread);
+46 -28
drivers/media/rc/rc-main.c
··· 18 18 #include <linux/input.h> 19 19 #include <linux/leds.h> 20 20 #include <linux/slab.h> 21 + #include <linux/idr.h> 21 22 #include <linux/device.h> 22 23 #include <linux/module.h> 23 24 #include "rc-core-priv.h" 24 25 25 - /* Bitmap to store allocated device numbers from 0 to IRRCV_NUM_DEVICES - 1 */ 26 - #define IRRCV_NUM_DEVICES 256 27 - static DECLARE_BITMAP(ir_core_dev_number, IRRCV_NUM_DEVICES); 28 - 29 26 /* Sizes are in bytes, 256 bytes allows for 32 entries on x64 */ 30 27 #define IR_TAB_MIN_SIZE 256 31 28 #define IR_TAB_MAX_SIZE 8192 29 + #define RC_DEV_MAX 256 32 30 33 31 /* FIXME: IR_KEYPRESS_TIMEOUT should be protocol specific */ 34 32 #define IR_KEYPRESS_TIMEOUT 250 ··· 35 37 static LIST_HEAD(rc_map_list); 36 38 static DEFINE_SPINLOCK(rc_map_lock); 37 39 static struct led_trigger *led_feedback; 40 + 41 + /* Used to keep track of rc devices */ 42 + static DEFINE_IDA(rc_ida); 38 43 39 44 static struct rc_map_list *seek_rc_map(const char *name) 40 45 { ··· 800 799 { RC_BIT_SANYO, "sanyo" }, 801 800 { RC_BIT_SHARP, "sharp" }, 802 801 { RC_BIT_MCE_KBD, "mce_kbd" }, 803 - { RC_BIT_LIRC, "lirc" }, 804 802 { RC_BIT_XMP, "xmp" }, 805 803 }; 806 804 ··· 827 827 .type = (_type), \ 828 828 .mask = (_mask), \ 829 829 } 830 + 831 + static bool lirc_is_present(void) 832 + { 833 + #if defined(CONFIG_LIRC_MODULE) 834 + struct module *lirc; 835 + 836 + mutex_lock(&module_mutex); 837 + lirc = find_module("lirc_dev"); 838 + mutex_unlock(&module_mutex); 839 + 840 + return lirc ? true : false; 841 + #elif defined(CONFIG_LIRC) 842 + return true; 843 + #else 844 + return false; 845 + #endif 846 + } 830 847 831 848 /** 832 849 * show_protocols() - shows the current/wakeup IR protocol(s) ··· 899 882 allowed &= ~proto_names[i].type; 900 883 } 901 884 885 + if (dev->driver_type == RC_DRIVER_IR_RAW && lirc_is_present()) 886 + tmp += sprintf(tmp, "[lirc] "); 887 + 902 888 if (tmp != buf) 903 889 tmp--; 904 890 *tmp = '\n'; ··· 953 933 } 954 934 955 935 if (i == ARRAY_SIZE(proto_names)) { 956 - IR_dprintk(1, "Unknown protocol: '%s'\n", tmp); 957 - return -EINVAL; 936 + if (!strcasecmp(tmp, "lirc")) 937 + mask = 0; 938 + else { 939 + IR_dprintk(1, "Unknown protocol: '%s'\n", tmp); 940 + return -EINVAL; 941 + } 958 942 } 959 943 960 944 count++; ··· 1215 1191 { 1216 1192 struct rc_dev *dev = to_rc_dev(device); 1217 1193 1218 - if (!dev || !dev->input_dev) 1219 - return -ENODEV; 1220 - 1221 1194 if (dev->rc_map.name) 1222 1195 ADD_HOTPLUG_VAR("NAME=%s", dev->rc_map.name); 1223 1196 if (dev->driver_name) ··· 1333 1312 static bool raw_init = false; /* raw decoders loaded? */ 1334 1313 struct rc_map *rc_map; 1335 1314 const char *path; 1336 - int rc, devno, attr = 0; 1315 + int attr = 0; 1316 + int minor; 1317 + int rc; 1337 1318 1338 1319 if (!dev || !dev->map_name) 1339 1320 return -EINVAL; ··· 1355 1332 if (dev->close) 1356 1333 dev->input_dev->close = ir_close; 1357 1334 1358 - do { 1359 - devno = find_first_zero_bit(ir_core_dev_number, 1360 - IRRCV_NUM_DEVICES); 1361 - /* No free device slots */ 1362 - if (devno >= IRRCV_NUM_DEVICES) 1363 - return -ENOMEM; 1364 - } while (test_and_set_bit(devno, ir_core_dev_number)); 1335 + minor = ida_simple_get(&rc_ida, 0, RC_DEV_MAX, GFP_KERNEL); 1336 + if (minor < 0) 1337 + return minor; 1338 + 1339 + dev->minor = minor; 1340 + dev_set_name(&dev->dev, "rc%u", dev->minor); 1341 + dev_set_drvdata(&dev->dev, dev); 1365 1342 1366 1343 dev->dev.groups = dev->sysfs_groups; 1367 1344 dev->sysfs_groups[attr++] = &rc_dev_protocol_attr_grp; ··· 1381 1358 */ 1382 1359 mutex_lock(&dev->lock); 1383 1360 1384 - dev->devno = devno; 1385 - dev_set_name(&dev->dev, "rc%ld", dev->devno); 1386 - dev_set_drvdata(&dev->dev, dev); 1387 1361 rc = device_add(&dev->dev); 1388 1362 if (rc) 1389 1363 goto out_unlock; ··· 1443 1423 1444 1424 if (dev->change_protocol) { 1445 1425 u64 rc_type = (1ll << rc_map->rc_type); 1446 - if (dev->driver_type == RC_DRIVER_IR_RAW) 1447 - rc_type |= RC_BIT_LIRC; 1448 1426 rc = dev->change_protocol(dev, &rc_type); 1449 1427 if (rc < 0) 1450 1428 goto out_raw; ··· 1451 1433 1452 1434 mutex_unlock(&dev->lock); 1453 1435 1454 - IR_dprintk(1, "Registered rc%ld (driver: %s, remote: %s, mode %s)\n", 1455 - dev->devno, 1436 + IR_dprintk(1, "Registered rc%u (driver: %s, remote: %s, mode %s)\n", 1437 + dev->minor, 1456 1438 dev->driver_name ? dev->driver_name : "unknown", 1457 1439 rc_map->name ? rc_map->name : "unknown", 1458 1440 dev->driver_type == RC_DRIVER_IR_RAW ? "raw" : "cooked"); ··· 1471 1453 device_del(&dev->dev); 1472 1454 out_unlock: 1473 1455 mutex_unlock(&dev->lock); 1474 - clear_bit(dev->devno, ir_core_dev_number); 1456 + ida_simple_remove(&rc_ida, minor); 1475 1457 return rc; 1476 1458 } 1477 1459 EXPORT_SYMBOL_GPL(rc_register_device); ··· 1482 1464 return; 1483 1465 1484 1466 del_timer_sync(&dev->timer_keyup); 1485 - 1486 - clear_bit(dev->devno, ir_core_dev_number); 1487 1467 1488 1468 if (dev->driver_type == RC_DRIVER_IR_RAW) 1489 1469 ir_raw_event_unregister(dev); ··· 1494 1478 dev->input_dev = NULL; 1495 1479 1496 1480 device_del(&dev->dev); 1481 + 1482 + ida_simple_remove(&rc_ida, dev->minor); 1497 1483 1498 1484 rc_free_device(dev); 1499 1485 }
+1 -1
drivers/media/tuners/Kconfig
··· 15 15 select MEDIA_TUNER_MC44S803 if MEDIA_SUBDRV_AUTOSELECT 16 16 17 17 menu "Customize TV tuners" 18 - visible if !MEDIA_SUBDRV_AUTOSELECT 18 + visible if !MEDIA_SUBDRV_AUTOSELECT || COMPILE_TEST 19 19 depends on MEDIA_ANALOG_TV_SUPPORT || MEDIA_DIGITAL_TV_SUPPORT || MEDIA_RADIO_SUPPORT || MEDIA_SDR_SUPPORT 20 20 21 21 config MEDIA_TUNER_SIMPLE
-1
drivers/media/tuners/e4000.c
··· 752 752 753 753 static struct i2c_driver e4000_driver = { 754 754 .driver = { 755 - .owner = THIS_MODULE, 756 755 .name = "e4000", 757 756 .suppress_bind_attrs = true, 758 757 },
-1
drivers/media/tuners/fc2580.c
··· 632 632 633 633 static struct i2c_driver fc2580_driver = { 634 634 .driver = { 635 - .owner = THIS_MODULE, 636 635 .name = "fc2580", 637 636 .suppress_bind_attrs = true, 638 637 },
-1
drivers/media/tuners/it913x.c
··· 463 463 464 464 static struct i2c_driver it913x_driver = { 465 465 .driver = { 466 - .owner = THIS_MODULE, 467 466 .name = "it913x", 468 467 }, 469 468 .probe = it913x_probe,
-1
drivers/media/tuners/m88rs6000t.c
··· 729 729 730 730 static struct i2c_driver m88rs6000t_driver = { 731 731 .driver = { 732 - .owner = THIS_MODULE, 733 732 .name = "m88rs6000t", 734 733 }, 735 734 .probe = m88rs6000t_probe,
-1
drivers/media/tuners/si2157.c
··· 469 469 470 470 static struct i2c_driver si2157_driver = { 471 471 .driver = { 472 - .owner = THIS_MODULE, 473 472 .name = "si2157", 474 473 }, 475 474 .probe = si2157_probe,
-1
drivers/media/tuners/tda18212.c
··· 277 277 278 278 static struct i2c_driver tda18212_driver = { 279 279 .driver = { 280 - .owner = THIS_MODULE, 281 280 .name = "tda18212", 282 281 }, 283 282 .probe = tda18212_probe,
-1
drivers/media/tuners/tua9001.c
··· 267 267 268 268 static struct i2c_driver tua9001_driver = { 269 269 .driver = { 270 - .owner = THIS_MODULE, 271 270 .name = "tua9001", 272 271 .suppress_bind_attrs = true, 273 272 },
-3
drivers/media/usb/airspy/airspy.c
··· 937 937 ret = airspy_ctrl_msg(s, CMD_SET_VGA_GAIN, 0, s->if_gain->val, 938 938 &u8tmp, 1); 939 939 if (ret) 940 - goto err; 941 - err: 942 - if (ret) 943 940 dev_dbg(s->dev, "failed=%d\n", ret); 944 941 945 942 return ret;
+2 -2
drivers/media/usb/cx231xx/cx231xx-video.c
··· 1875 1875 v4l2_fh_exit(&fh->fh); 1876 1876 kfree(fh); 1877 1877 dev->users--; 1878 - wake_up_interruptible_nr(&dev->open, 1); 1878 + wake_up_interruptible(&dev->open); 1879 1879 return 0; 1880 1880 } 1881 1881 ··· 1908 1908 } 1909 1909 v4l2_fh_exit(&fh->fh); 1910 1910 kfree(fh); 1911 - wake_up_interruptible_nr(&dev->open, 1); 1911 + wake_up_interruptible(&dev->open); 1912 1912 return 0; 1913 1913 } 1914 1914
+11 -10
drivers/media/usb/dvb-usb-v2/lmedm04.c
··· 348 348 switch (ibuf[0]) { 349 349 case 0xaa: 350 350 debug_data_snipet(1, "INT Remote data snipet", ibuf); 351 - if ((ibuf[4] + ibuf[5]) == 0xff) { 352 - key = RC_SCANCODE_NECX((ibuf[2] ^ 0xff) << 8 | 353 - (ibuf[3] > 0) ? (ibuf[3] ^ 0xff) : 0, 354 - ibuf[5]); 355 - deb_info(1, "INT Key =%08x", key); 356 - if (adap_to_d(adap)->rc_dev != NULL) 357 - rc_keydown(adap_to_d(adap)->rc_dev, 358 - RC_TYPE_NEC, key, 0); 359 - } 351 + if (!adap_to_d(adap)->rc_dev) 352 + break; 353 + 354 + key = RC_SCANCODE_NEC32(ibuf[2] << 24 | 355 + ibuf[3] << 16 | 356 + ibuf[4] << 8 | 357 + ibuf[5]); 358 + 359 + deb_info(1, "INT Key = 0x%08x", key); 360 + rc_keydown(adap_to_d(adap)->rc_dev, RC_TYPE_NEC, key, 0); 360 361 break; 361 362 case 0xbb: 362 363 switch (st->tuner_config) { ··· 1345 1344 1346 1345 MODULE_AUTHOR("Malcolm Priestley <tvboxspy@gmail.com>"); 1347 1346 MODULE_DESCRIPTION("LME2510(C) DVB-S USB2.0"); 1348 - MODULE_VERSION("2.06"); 1347 + MODULE_VERSION("2.07"); 1349 1348 MODULE_LICENSE("GPL"); 1350 1349 MODULE_FIRMWARE(LME2510_C_S7395); 1351 1350 MODULE_FIRMWARE(LME2510_C_LG);
+1 -1
drivers/media/usb/dvb-usb/pctv452e.c
··· 611 611 return 0; 612 612 613 613 failed: 614 - memset(mac, 0, 6); 614 + eth_zero_addr(mac); 615 615 616 616 return ret; 617 617 }
+1 -1
drivers/media/usb/dvb-usb/technisat-usb2.c
··· 707 707 708 708 .stream = { 709 709 .type = USB_ISOC, 710 - .count = 8, 710 + .count = 4, 711 711 .endpoint = 0x2, 712 712 .u = { 713 713 .isoc = {
-4
drivers/media/usb/em28xx/em28xx-dvb.c
··· 808 808 .gate = TDA18271_GATE_DIGITAL, 809 809 }; 810 810 811 - static const struct a8293_config em28xx_a8293_config = { 812 - .i2c_addr = 0x08, /* (0x10 >> 1) */ 813 - }; 814 - 815 811 static struct zl10353_config em28xx_zl10353_no_i2c_gate_dev = { 816 812 .demod_address = (0x1e >> 1), 817 813 .disable_i2c_gate_ctrl = 1,
-1
drivers/media/usb/go7007/s2250-board.c
··· 629 629 630 630 static struct i2c_driver s2250_driver = { 631 631 .driver = { 632 - .owner = THIS_MODULE, 633 632 .name = "s2250", 634 633 }, 635 634 .probe = s2250_probe,
+1 -1
drivers/media/usb/gspca/m5602/m5602_s5k83a.c
··· 177 177 __s32 vflip, hflip; 178 178 179 179 set_current_state(TASK_INTERRUPTIBLE); 180 - while (!schedule_timeout(100)) { 180 + while (!schedule_timeout(msecs_to_jiffies(100))) { 181 181 if (mutex_lock_interruptible(&sd->gspca_dev.usb_lock)) 182 182 break; 183 183
+1 -1
drivers/media/usb/gspca/sn9c2028.c
··· 140 140 status = sn9c2028_read1(gspca_dev); 141 141 if (status < 0) { 142 142 pr_err("long command status read error %d\n", status); 143 - return (status < 0) ? status : -EIO; 143 + return status; 144 144 } 145 145 146 146 memset(reading, 0, 4);
+1 -4
drivers/media/usb/stk1160/stk1160-core.c
··· 162 162 { 163 163 struct stk1160 *dev = container_of(v4l2_dev, struct stk1160, v4l2_dev); 164 164 165 - stk1160_info("releasing all resources\n"); 165 + stk1160_dbg("releasing all resources\n"); 166 166 167 167 stk1160_i2c_unregister(dev); 168 168 ··· 362 362 */ 363 363 dev->sd_saa7115 = v4l2_i2c_new_subdev(&dev->v4l2_dev, &dev->i2c_adap, 364 364 "saa7115_auto", 0, saa7113_addrs); 365 - 366 - stk1160_info("driver ver %s successfully loaded\n", 367 - STK1160_VERSION); 368 365 369 366 /* i2c reset saa711x */ 370 367 v4l2_device_call_all(&dev->v4l2_dev, 0, core, reset, 0);
+34
drivers/media/usb/stk1160/stk1160-reg.h
··· 33 33 */ 34 34 #define STK1160_DCTRL 0x100 35 35 36 + /* 37 + * Decimation Control Register: 38 + * Byte 104: Horizontal Decimation Line Unit Count 39 + * Byte 105: Vertical Decimation Line Unit Count 40 + * Byte 106: Decimation Control 41 + * Bit 0 - Horizontal Decimation Control 42 + * 0 Horizontal decimation is disabled. 43 + * 1 Horizontal decimation is enabled. 44 + * Bit 1 - Decimates Half or More Column 45 + * 0 Decimates less than half from original column, 46 + * send count unit (0x105) before each unit skipped. 47 + * 1 Decimates half or more from original column, 48 + * skip count unit (0x105) before each unit sent. 49 + * Bit 2 - Vertical Decimation Control 50 + * 0 Vertical decimation is disabled. 51 + * 1 Vertical decimation is enabled. 52 + * Bit 3 - Vertical Greater or Equal to Half 53 + * 0 Decimates less than half from original row, 54 + * send count unit (0x105) before each unit skipped. 55 + * 1 Decimates half or more from original row, 56 + * skip count unit (0x105) before each unit sent. 57 + * Bit 4 - Decimation Unit 58 + * 0 Decimation will work with 2 rows or columns per unit. 59 + * 1 Decimation will work with 4 rows or columns per unit. 60 + */ 61 + #define STK1160_DMCTRL_H_UNITS 0x104 62 + #define STK1160_DMCTRL_V_UNITS 0x105 63 + #define STK1160_DMCTRL 0x106 64 + #define STK1160_H_DEC_EN BIT(0) 65 + #define STK1160_H_DEC_MODE BIT(1) 66 + #define STK1160_V_DEC_EN BIT(2) 67 + #define STK1160_V_DEC_MODE BIT(3) 68 + #define STK1160_DEC_UNIT_SIZE BIT(4) 69 + 36 70 /* Capture Frame Start Position */ 37 71 #define STK116_CFSPO 0x110 38 72 #define STK116_CFSPO_STX_L 0x110
+187 -40
drivers/media/usb/stk1160/stk1160-v4l.c
··· 42 42 module_param(keep_buffers, bool, 0644); 43 43 MODULE_PARM_DESC(keep_buffers, "don't release buffers upon stop streaming"); 44 44 45 + enum stk1160_decimate_mode { 46 + STK1160_DECIMATE_MORE_THAN_HALF, 47 + STK1160_DECIMATE_LESS_THAN_HALF, 48 + }; 49 + 50 + struct stk1160_decimate_ctrl { 51 + bool col_en, row_en; 52 + enum stk1160_decimate_mode col_mode, row_mode; 53 + unsigned int col_n, row_n; 54 + }; 55 + 45 56 /* supported video standards */ 46 57 static struct stk1160_fmt format[] = { 47 58 { ··· 61 50 .depth = 16, 62 51 } 63 52 }; 53 + 54 + /* 55 + * Helper to find the next divisor that results in modulo being zero. 56 + * This is required to guarantee valid decimation unit counts. 57 + */ 58 + static unsigned int 59 + div_round_integer(unsigned int x, unsigned int y) 60 + { 61 + for (;; y++) { 62 + if (x % y == 0) 63 + return x / y; 64 + } 65 + } 64 66 65 67 static void stk1160_set_std(struct stk1160 *dev) 66 68 { ··· 130 106 131 107 } 132 108 109 + static void stk1160_set_fmt(struct stk1160 *dev, 110 + struct stk1160_decimate_ctrl *ctrl) 111 + { 112 + u32 val = 0; 113 + 114 + if (ctrl) { 115 + /* 116 + * Since the format is UYVY, the device must skip or send 117 + * a number of rows/columns multiple of four. This way, the 118 + * colour format is preserved. The STK1160_DEC_UNIT_SIZE bit 119 + * does exactly this. 120 + */ 121 + val |= STK1160_DEC_UNIT_SIZE; 122 + val |= ctrl->col_en ? STK1160_H_DEC_EN : 0; 123 + val |= ctrl->row_en ? STK1160_V_DEC_EN : 0; 124 + val |= ctrl->col_mode == 125 + STK1160_DECIMATE_MORE_THAN_HALF ? 126 + STK1160_H_DEC_MODE : 0; 127 + val |= ctrl->row_mode == 128 + STK1160_DECIMATE_MORE_THAN_HALF ? 129 + STK1160_V_DEC_MODE : 0; 130 + 131 + /* Horizontal count units */ 132 + stk1160_write_reg(dev, STK1160_DMCTRL_H_UNITS, ctrl->col_n); 133 + /* Vertical count units */ 134 + stk1160_write_reg(dev, STK1160_DMCTRL_V_UNITS, ctrl->row_n); 135 + 136 + stk1160_dbg("decimate 0x%x, column units %d, row units %d\n", 137 + val, ctrl->col_n, ctrl->row_n); 138 + } 139 + 140 + /* Decimation control */ 141 + stk1160_write_reg(dev, STK1160_DMCTRL, val); 142 + } 143 + 133 144 /* 134 145 * Set a new alternate setting. 135 146 * Returns true is dev->max_pkt_size has changed, false otherwise. ··· 195 136 dev->alt = i; 196 137 } 197 138 198 - stk1160_info("setting alternate %d\n", dev->alt); 139 + stk1160_dbg("setting alternate %d\n", dev->alt); 199 140 200 141 if (dev->alt != prev_alt) { 201 142 stk1160_dbg("minimum isoc packet size: %u (alt=%d)\n", ··· 253 194 /* Start saa711x */ 254 195 v4l2_device_call_all(&dev->v4l2_dev, 0, video, s_stream, 1); 255 196 197 + dev->sequence = 0; 198 + 256 199 /* Start stk1160 */ 257 200 stk1160_write_reg(dev, STK1160_DCTRL, 0xb3); 258 201 stk1160_write_reg(dev, STK1160_DCTRL+3, 0x00); ··· 285 224 286 225 /* set alternate 0 */ 287 226 dev->alt = 0; 288 - stk1160_info("setting alternate %d\n", dev->alt); 227 + stk1160_dbg("setting alternate %d\n", dev->alt); 289 228 usb_set_interface(dev->udev, 0, 0); 290 229 291 230 /* Stop stk1160 */ ··· 382 321 return 0; 383 322 } 384 323 324 + static int stk1160_try_fmt(struct stk1160 *dev, struct v4l2_format *f, 325 + struct stk1160_decimate_ctrl *ctrl) 326 + { 327 + unsigned int width, height; 328 + unsigned int base_width, base_height; 329 + unsigned int col_n, row_n; 330 + enum stk1160_decimate_mode col_mode, row_mode; 331 + bool col_en, row_en; 332 + 333 + base_width = 720; 334 + base_height = (dev->norm & V4L2_STD_525_60) ? 480 : 576; 335 + 336 + /* Minimum width and height is 5% the frame size */ 337 + width = clamp_t(unsigned int, f->fmt.pix.width, 338 + base_width / 20, base_width); 339 + height = clamp_t(unsigned int, f->fmt.pix.height, 340 + base_height / 20, base_height); 341 + 342 + /* Let's set default no decimation values */ 343 + col_n = 0; 344 + row_n = 0; 345 + col_en = false; 346 + row_en = false; 347 + f->fmt.pix.width = base_width; 348 + f->fmt.pix.height = base_height; 349 + row_mode = STK1160_DECIMATE_LESS_THAN_HALF; 350 + col_mode = STK1160_DECIMATE_LESS_THAN_HALF; 351 + 352 + if (width < base_width && width > base_width / 2) { 353 + /* 354 + * The device will send count units for each 355 + * unit skipped. This means count unit is: 356 + * 357 + * n = width / (frame width - width) 358 + * 359 + * And the width is: 360 + * 361 + * width = (n / n + 1) * frame width 362 + */ 363 + col_n = div_round_integer(width, base_width - width); 364 + if (col_n > 0 && col_n <= 255) { 365 + col_en = true; 366 + col_mode = STK1160_DECIMATE_LESS_THAN_HALF; 367 + f->fmt.pix.width = (base_width * col_n) / (col_n + 1); 368 + } 369 + 370 + } else if (width <= base_width / 2) { 371 + 372 + /* 373 + * The device will skip count units for each 374 + * unit sent. This means count is: 375 + * 376 + * n = (frame width / width) - 1 377 + * 378 + * And the width is: 379 + * 380 + * width = frame width / (n + 1) 381 + */ 382 + col_n = div_round_integer(base_width, width) - 1; 383 + if (col_n > 0 && col_n <= 255) { 384 + col_en = true; 385 + col_mode = STK1160_DECIMATE_MORE_THAN_HALF; 386 + f->fmt.pix.width = base_width / (col_n + 1); 387 + } 388 + } 389 + 390 + if (height < base_height && height > base_height / 2) { 391 + row_n = div_round_integer(height, base_height - height); 392 + if (row_n > 0 && row_n <= 255) { 393 + row_en = true; 394 + row_mode = STK1160_DECIMATE_LESS_THAN_HALF; 395 + f->fmt.pix.height = (base_height * row_n) / (row_n + 1); 396 + } 397 + 398 + } else if (height <= base_height / 2) { 399 + row_n = div_round_integer(base_height, height) - 1; 400 + if (row_n > 0 && row_n <= 255) { 401 + row_en = true; 402 + row_mode = STK1160_DECIMATE_MORE_THAN_HALF; 403 + f->fmt.pix.height = base_height / (row_n + 1); 404 + } 405 + } 406 + 407 + f->fmt.pix.pixelformat = dev->fmt->fourcc; 408 + f->fmt.pix.field = V4L2_FIELD_INTERLACED; 409 + f->fmt.pix.bytesperline = f->fmt.pix.width * 2; 410 + f->fmt.pix.sizeimage = f->fmt.pix.height * f->fmt.pix.bytesperline; 411 + f->fmt.pix.colorspace = V4L2_COLORSPACE_SMPTE170M; 412 + 413 + if (ctrl) { 414 + ctrl->col_en = col_en; 415 + ctrl->col_n = col_n; 416 + ctrl->col_mode = col_mode; 417 + ctrl->row_en = row_en; 418 + ctrl->row_n = row_n; 419 + ctrl->row_mode = row_mode; 420 + } 421 + 422 + stk1160_dbg("width %d, height %d\n", 423 + f->fmt.pix.width, f->fmt.pix.height); 424 + return 0; 425 + } 426 + 385 427 static int vidioc_try_fmt_vid_cap(struct file *file, void *priv, 386 - struct v4l2_format *f) 428 + struct v4l2_format *f) 387 429 { 388 430 struct stk1160 *dev = video_drvdata(file); 389 431 390 - /* 391 - * User can't choose size at his own will, 392 - * so we just return him the current size chosen 393 - * at standard selection. 394 - * TODO: Implement frame scaling? 395 - */ 396 - 397 - f->fmt.pix.pixelformat = dev->fmt->fourcc; 398 - f->fmt.pix.width = dev->width; 399 - f->fmt.pix.height = dev->height; 400 - f->fmt.pix.field = V4L2_FIELD_INTERLACED; 401 - f->fmt.pix.bytesperline = dev->width * 2; 402 - f->fmt.pix.sizeimage = dev->height * f->fmt.pix.bytesperline; 403 - f->fmt.pix.colorspace = V4L2_COLORSPACE_SMPTE170M; 404 - 405 - return 0; 432 + return stk1160_try_fmt(dev, f, NULL); 406 433 } 407 434 408 435 static int vidioc_s_fmt_vid_cap(struct file *file, void *priv, ··· 498 349 { 499 350 struct stk1160 *dev = video_drvdata(file); 500 351 struct vb2_queue *q = &dev->vb_vidq; 352 + struct stk1160_decimate_ctrl ctrl; 353 + int rc; 501 354 502 355 if (vb2_is_busy(q)) 503 356 return -EBUSY; 504 357 505 - vidioc_try_fmt_vid_cap(file, priv, f); 506 - 507 - /* We don't support any format changes */ 358 + rc = stk1160_try_fmt(dev, f, &ctrl); 359 + if (rc < 0) 360 + return rc; 361 + dev->width = f->fmt.pix.width; 362 + dev->height = f->fmt.pix.height; 363 + stk1160_set_fmt(dev, &ctrl); 508 364 509 365 return 0; 510 366 } ··· 545 391 return -ENODEV; 546 392 547 393 /* We need to set this now, before we call stk1160_set_std */ 394 + dev->width = 720; 395 + dev->height = (norm & V4L2_STD_525_60) ? 480 : 576; 548 396 dev->norm = norm; 549 397 550 - /* This is taken from saa7115 video decoder */ 551 - if (dev->norm & V4L2_STD_525_60) { 552 - dev->width = 720; 553 - dev->height = 480; 554 - } else if (dev->norm & V4L2_STD_625_50) { 555 - dev->width = 720; 556 - dev->height = 576; 557 - } else { 558 - stk1160_err("invalid standard\n"); 559 - return -EINVAL; 560 - } 561 - 562 398 stk1160_set_std(dev); 399 + 400 + /* Calling with NULL disables frame decimation */ 401 + stk1160_set_fmt(dev, NULL); 563 402 564 403 v4l2_device_call_all(&dev->v4l2_dev, 0, video, s_std, 565 404 dev->norm); ··· 685 538 686 539 sizes[0] = size; 687 540 688 - stk1160_info("%s: buffer count %d, each %ld bytes\n", 689 - __func__, *nbuffers, size); 541 + stk1160_dbg("%s: buffer count %d, each %ld bytes\n", 542 + __func__, *nbuffers, size); 690 543 691 544 return 0; 692 545 } ··· 770 623 struct stk1160_buffer, list); 771 624 list_del(&buf->list); 772 625 vb2_buffer_done(&buf->vb, VB2_BUF_STATE_ERROR); 773 - stk1160_info("buffer [%p/%d] aborted\n", 774 - buf, buf->vb.v4l2_buf.index); 626 + stk1160_dbg("buffer [%p/%d] aborted\n", 627 + buf, buf->vb.v4l2_buf.index); 775 628 } 776 629 777 630 /* It's important to release the current buffer */ ··· 780 633 dev->isoc_ctl.buf = NULL; 781 634 782 635 vb2_buffer_done(&buf->vb, VB2_BUF_STATE_ERROR); 783 - stk1160_info("buffer [%p/%d] aborted\n", 784 - buf, buf->vb.v4l2_buf.index); 636 + stk1160_dbg("buffer [%p/%d] aborted\n", 637 + buf, buf->vb.v4l2_buf.index); 785 638 } 786 639 spin_unlock_irqrestore(&dev->buf_lock, flags); 787 640 }
+1 -3
drivers/media/usb/stk1160/stk1160-video.c
··· 96 96 { 97 97 struct stk1160_buffer *buf = dev->isoc_ctl.buf; 98 98 99 - dev->field_count++; 100 - 101 - buf->vb.v4l2_buf.sequence = dev->field_count >> 1; 99 + buf->vb.v4l2_buf.sequence = dev->sequence++; 102 100 buf->vb.v4l2_buf.field = V4L2_FIELD_INTERLACED; 103 101 buf->vb.v4l2_buf.bytesused = buf->bytesused; 104 102 v4l2_get_timestamp(&buf->vb.v4l2_buf.timestamp);
+1 -3
drivers/media/usb/stk1160/stk1160.h
··· 58 58 * new drivers should use. 59 59 * 60 60 */ 61 - #define DEBUG 62 61 #ifdef DEBUG 63 62 #define stk1160_dbg(fmt, args...) \ 64 63 printk(KERN_DEBUG "stk1160: " fmt, ## args) ··· 150 151 v4l2_std_id norm; /* current norm */ 151 152 struct stk1160_fmt *fmt; /* selected format */ 152 153 153 - unsigned int field_count; /* not sure ??? */ 154 - enum v4l2_field field; /* also not sure :/ */ 154 + unsigned int sequence; 155 155 156 156 /* i2c i/o */ 157 157 struct i2c_adapter i2c_adap;
+2 -7
drivers/media/usb/ttusb-dec/ttusb_dec.c
··· 593 593 594 594 static void swap_bytes(u8 *b, int length) 595 595 { 596 - u8 c; 597 - 598 596 length -= length % 2; 599 - for (; length; b += 2, length -= 2) { 600 - c = *b; 601 - *b = *(b + 1); 602 - *(b + 1) = c; 603 - } 597 + for (; length; b += 2, length -= 2) 598 + swap(*b, *(b + 1)); 604 599 } 605 600 606 601 static void ttusb_dec_process_urb_frame(struct ttusb_dec *dec, u8 *b,
+10 -61
drivers/media/usb/usbvision/usbvision-core.c
··· 1367 1367 int usbvision_read_reg(struct usb_usbvision *usbvision, unsigned char reg) 1368 1368 { 1369 1369 int err_code = 0; 1370 - unsigned char buffer[1]; 1370 + unsigned char *buffer = usbvision->ctrl_urb_buffer; 1371 1371 1372 1372 if (!USBVISION_IS_OPERATIONAL(usbvision)) 1373 1373 return -1; ··· 1401 1401 if (!USBVISION_IS_OPERATIONAL(usbvision)) 1402 1402 return 0; 1403 1403 1404 + usbvision->ctrl_urb_buffer[0] = value; 1404 1405 err_code = usb_control_msg(usbvision->dev, usb_sndctrlpipe(usbvision->dev, 1), 1405 1406 USBVISION_OP_CODE, 1406 1407 USB_DIR_OUT | USB_TYPE_VENDOR | 1407 - USB_RECIP_ENDPOINT, 0, (__u16) reg, &value, 1, HZ); 1408 + USB_RECIP_ENDPOINT, 0, (__u16) reg, 1409 + usbvision->ctrl_urb_buffer, 1, HZ); 1408 1410 1409 1411 if (err_code < 0) { 1410 1412 dev_err(&usbvision->dev->dev, ··· 1598 1596 { 0x27, 0x00, 0x00 }, { 0x28, 0x00, 0x00 }, { 0x29, 0x00, 0x00 }, { 0x08, 0x80, 0x60 }, 1599 1597 { 0x0f, 0x2d, 0x24 }, { 0x0c, 0x80, 0x80 } 1600 1598 }; 1601 - char value[3]; 1599 + unsigned char *value = usbvision->ctrl_urb_buffer; 1602 1600 1603 1601 /* the only difference between PAL and NTSC init_values */ 1604 1602 if (usbvision_device_data[usbvision->dev_model].video_norm == V4L2_STD_NTSC) ··· 1637 1635 static int usbvision_set_video_format(struct usb_usbvision *usbvision, int format) 1638 1636 { 1639 1637 static const char proc[] = "usbvision_set_video_format"; 1638 + unsigned char *value = usbvision->ctrl_urb_buffer; 1640 1639 int rc; 1641 - unsigned char value[2]; 1642 1640 1643 1641 if (!USBVISION_IS_OPERATIONAL(usbvision)) 1644 1642 return 0; ··· 1679 1677 int err_code = 0; 1680 1678 int usb_width, usb_height; 1681 1679 unsigned int frame_rate = 0, frame_drop = 0; 1682 - unsigned char value[4]; 1680 + unsigned char *value = usbvision->ctrl_urb_buffer; 1683 1681 1684 1682 if (!USBVISION_IS_OPERATIONAL(usbvision)) 1685 1683 return 0; ··· 1791 1789 usbvision->num_frames--; 1792 1790 } 1793 1791 1794 - spin_lock_init(&usbvision->queue_lock); 1795 - init_waitqueue_head(&usbvision->wait_frame); 1796 - init_waitqueue_head(&usbvision->wait_stream); 1797 - 1798 1792 /* Allocate all buffers */ 1799 1793 for (i = 0; i < usbvision->num_frames; i++) { 1800 1794 usbvision->frame[i].index = i; ··· 1870 1872 { 1871 1873 static const char proc[] = "usbvision_set_compresion_params: "; 1872 1874 int rc; 1873 - unsigned char value[6]; 1875 + unsigned char *value = usbvision->ctrl_urb_buffer; 1874 1876 1875 1877 value[0] = 0x0F; /* Intra-Compression cycle */ 1876 1878 value[1] = 0x01; /* Reg.45 one line per strip */ ··· 1944 1946 { 1945 1947 static const char proc[] = "usbvision_set_input: "; 1946 1948 int rc; 1947 - unsigned char value[8]; 1949 + unsigned char *value = usbvision->ctrl_urb_buffer; 1948 1950 unsigned char dvi_yuv_value; 1949 1951 1950 1952 if (!USBVISION_IS_OPERATIONAL(usbvision)) ··· 2060 2062 2061 2063 static int usbvision_set_dram_settings(struct usb_usbvision *usbvision) 2062 2064 { 2065 + unsigned char *value = usbvision->ctrl_urb_buffer; 2063 2066 int rc; 2064 - unsigned char value[8]; 2065 2067 2066 2068 if (usbvision->isoc_mode == ISOC_MODE_COMPRESS) { 2067 2069 value[0] = 0x42; ··· 2157 2159 return err_code; 2158 2160 } 2159 2161 2160 - 2161 - /* 2162 - * usbvision timer stuff 2163 - */ 2164 - 2165 - /* to call usbvision_power_off from task queue */ 2166 - static void call_usbvision_power_off(struct work_struct *work) 2167 - { 2168 - struct usb_usbvision *usbvision = container_of(work, struct usb_usbvision, power_off_work); 2169 - 2170 - PDEBUG(DBG_FUNC, ""); 2171 - if (mutex_lock_interruptible(&usbvision->v4l2_lock)) 2172 - return; 2173 - 2174 - if (usbvision->user == 0) { 2175 - usbvision_i2c_unregister(usbvision); 2176 - 2177 - usbvision_power_off(usbvision); 2178 - usbvision->initialized = 0; 2179 - } 2180 - mutex_unlock(&usbvision->v4l2_lock); 2181 - } 2182 - 2183 - static void usbvision_power_off_timer(unsigned long data) 2184 - { 2185 - struct usb_usbvision *usbvision = (void *)data; 2186 - 2187 - PDEBUG(DBG_FUNC, ""); 2188 - del_timer(&usbvision->power_off_timer); 2189 - INIT_WORK(&usbvision->power_off_work, call_usbvision_power_off); 2190 - (void) schedule_work(&usbvision->power_off_work); 2191 - } 2192 - 2193 - void usbvision_init_power_off_timer(struct usb_usbvision *usbvision) 2194 - { 2195 - setup_timer(&usbvision->power_off_timer, usbvision_power_off_timer, 2196 - (unsigned long)usbvision); 2197 - } 2198 - 2199 - void usbvision_set_power_off_timer(struct usb_usbvision *usbvision) 2200 - { 2201 - mod_timer(&usbvision->power_off_timer, jiffies + USBVISION_POWEROFF_TIME); 2202 - } 2203 - 2204 - void usbvision_reset_power_off_timer(struct usb_usbvision *usbvision) 2205 - { 2206 - if (timer_pending(&usbvision->power_off_timer)) 2207 - del_timer(&usbvision->power_off_timer); 2208 - } 2209 2162 2210 2163 /* 2211 2164 * usbvision_begin_streaming()
+1 -1
drivers/media/usb/usbvision/usbvision-i2c.c
··· 343 343 { 344 344 int rc, retries; 345 345 int i; 346 - unsigned char value[6]; 346 + unsigned char *value = usbvision->ctrl_urb_buffer; 347 347 unsigned char ser_cont; 348 348 349 349 ser_cont = (len & 0x07) | 0x10;
+87 -159
drivers/media/usb/usbvision/usbvision-video.c
··· 62 62 #include <media/saa7115.h> 63 63 #include <media/v4l2-common.h> 64 64 #include <media/v4l2-ioctl.h> 65 + #include <media/v4l2-event.h> 65 66 #include <media/tuner.h> 66 67 67 68 #include <linux/workqueue.h> ··· 123 122 static int isoc_mode = ISOC_MODE_COMPRESS; 124 123 /* Set the default Debug Mode of the device driver */ 125 124 static int video_debug; 126 - /* Set the default device to power on at startup */ 127 - static int power_on_at_open = 1; 128 125 /* Sequential Number of Video Device */ 129 126 static int video_nr = -1; 130 127 /* Sequential Number of Radio Device */ ··· 133 134 /* Showing parameters under SYSFS */ 134 135 module_param(isoc_mode, int, 0444); 135 136 module_param(video_debug, int, 0444); 136 - module_param(power_on_at_open, int, 0444); 137 137 module_param(video_nr, int, 0444); 138 138 module_param(radio_nr, int, 0444); 139 139 140 140 MODULE_PARM_DESC(isoc_mode, " Set the default format for ISOC endpoint. Default: 0x60 (Compression On)"); 141 141 MODULE_PARM_DESC(video_debug, " Set the default Debug Mode of the device driver. Default: 0 (Off)"); 142 - MODULE_PARM_DESC(power_on_at_open, " Set the default device to power on when device is opened. Default: 1 (On)"); 143 142 MODULE_PARM_DESC(video_nr, "Set video device number (/dev/videoX). Default: -1 (autodetect)"); 144 143 MODULE_PARM_DESC(radio_nr, "Set radio device number (/dev/radioX). Default: -1 (autodetect)"); 145 144 ··· 348 351 349 352 if (mutex_lock_interruptible(&usbvision->v4l2_lock)) 350 353 return -ERESTARTSYS; 351 - usbvision_reset_power_off_timer(usbvision); 352 354 353 - if (usbvision->user) 355 + if (usbvision->user) { 354 356 err_code = -EBUSY; 355 - else { 357 + } else { 358 + err_code = v4l2_fh_open(file); 359 + if (err_code) 360 + goto unlock; 361 + 356 362 /* Allocate memory for the scratch ring buffer */ 357 363 err_code = usbvision_scratch_alloc(usbvision); 358 364 if (isoc_mode == ISOC_MODE_COMPRESS) { ··· 372 372 373 373 /* If so far no errors then we shall start the camera */ 374 374 if (!err_code) { 375 - if (usbvision->power == 0) { 376 - usbvision_power_on(usbvision); 377 - usbvision_i2c_register(usbvision); 378 - } 379 - 380 375 /* Send init sequence only once, it's large! */ 381 376 if (!usbvision->initialized) { 382 377 int setup_ok = 0; ··· 387 392 err_code = usbvision_init_isoc(usbvision); 388 393 /* device must be initialized before isoc transfer */ 389 394 usbvision_muxsel(usbvision, 0); 395 + 396 + /* prepare queues */ 397 + usbvision_empty_framequeues(usbvision); 390 398 usbvision->user++; 391 - } else { 392 - if (power_on_at_open) { 393 - usbvision_i2c_unregister(usbvision); 394 - usbvision_power_off(usbvision); 395 - usbvision->initialized = 0; 396 - } 397 399 } 398 400 } 399 401 400 - /* prepare queues */ 401 - usbvision_empty_framequeues(usbvision); 402 + unlock: 402 403 mutex_unlock(&usbvision->v4l2_lock); 403 404 404 405 PDEBUG(DBG_IO, "success"); ··· 426 435 usbvision_scratch_free(usbvision); 427 436 428 437 usbvision->user--; 429 - 430 - if (power_on_at_open) { 431 - /* power off in a little while 432 - to avoid off/on every close/open short sequences */ 433 - usbvision_set_power_off_timer(usbvision); 434 - usbvision->initialized = 0; 435 - } 438 + mutex_unlock(&usbvision->v4l2_lock); 436 439 437 440 if (usbvision->remove_pending) { 438 441 printk(KERN_INFO "%s: Final disconnect\n", __func__); 439 442 usbvision_release(usbvision); 440 443 return 0; 441 444 } 442 - mutex_unlock(&usbvision->v4l2_lock); 443 445 444 446 PDEBUG(DBG_IO, "success"); 445 - return 0; 447 + return v4l2_fh_release(file); 446 448 } 447 449 448 450 ··· 487 503 struct v4l2_capability *vc) 488 504 { 489 505 struct usb_usbvision *usbvision = video_drvdata(file); 506 + struct video_device *vdev = video_devdata(file); 490 507 491 508 strlcpy(vc->driver, "USBVision", sizeof(vc->driver)); 492 509 strlcpy(vc->card, 493 510 usbvision_device_data[usbvision->dev_model].model_string, 494 511 sizeof(vc->card)); 495 512 usb_make_path(usbvision->dev, vc->bus_info, sizeof(vc->bus_info)); 496 - vc->device_caps = V4L2_CAP_VIDEO_CAPTURE | 497 - V4L2_CAP_AUDIO | 498 - V4L2_CAP_READWRITE | 499 - V4L2_CAP_STREAMING | 500 - (usbvision->have_tuner ? V4L2_CAP_TUNER : 0); 501 - vc->capabilities = vc->device_caps | V4L2_CAP_DEVICE_CAPS; 513 + vc->device_caps = usbvision->have_tuner ? V4L2_CAP_TUNER : 0; 514 + if (vdev->vfl_type == VFL_TYPE_GRABBER) 515 + vc->device_caps |= V4L2_CAP_VIDEO_CAPTURE | 516 + V4L2_CAP_READWRITE | V4L2_CAP_STREAMING; 517 + else 518 + vc->device_caps |= V4L2_CAP_RADIO; 519 + 520 + vc->capabilities = vc->device_caps | V4L2_CAP_VIDEO_CAPTURE | 521 + V4L2_CAP_READWRITE | V4L2_CAP_STREAMING | V4L2_CAP_DEVICE_CAPS; 522 + if (usbvision_device_data[usbvision->dev_model].radio) 523 + vc->capabilities |= V4L2_CAP_RADIO; 502 524 return 0; 503 525 } 504 526 ··· 530 540 } else { 531 541 strcpy(vi->name, "Television"); 532 542 vi->type = V4L2_INPUT_TYPE_TUNER; 533 - vi->audioset = 1; 534 543 vi->tuner = chan; 535 544 vi->std = USBVISION_NORMS; 536 545 } ··· 540 551 strcpy(vi->name, "Green Video Input"); 541 552 else 542 553 strcpy(vi->name, "Composite Video Input"); 543 - vi->std = V4L2_STD_PAL; 554 + vi->std = USBVISION_NORMS; 544 555 break; 545 556 case 2: 546 557 vi->type = V4L2_INPUT_TYPE_CAMERA; ··· 548 559 strcpy(vi->name, "Yellow Video Input"); 549 560 else 550 561 strcpy(vi->name, "S-Video Input"); 551 - vi->std = V4L2_STD_PAL; 562 + vi->std = USBVISION_NORMS; 552 563 break; 553 564 case 3: 554 565 vi->type = V4L2_INPUT_TYPE_CAMERA; 555 566 strcpy(vi->name, "Red Video Input"); 556 - vi->std = V4L2_STD_PAL; 567 + vi->std = USBVISION_NORMS; 557 568 break; 558 569 } 559 570 return 0; ··· 608 619 { 609 620 struct usb_usbvision *usbvision = video_drvdata(file); 610 621 611 - if (!usbvision->have_tuner || vt->index) /* Only tuner 0 */ 622 + if (vt->index) /* Only tuner 0 */ 612 623 return -EINVAL; 613 - if (usbvision->radio) { 624 + if (vt->type == V4L2_TUNER_RADIO) 614 625 strcpy(vt->name, "Radio"); 615 - vt->type = V4L2_TUNER_RADIO; 616 - } else { 626 + else 617 627 strcpy(vt->name, "Television"); 618 - } 628 + 619 629 /* Let clients fill in the remainder of this struct */ 620 630 call_all(usbvision, tuner, g_tuner, vt); 621 631 ··· 626 638 { 627 639 struct usb_usbvision *usbvision = video_drvdata(file); 628 640 629 - /* Only no or one tuner for now */ 630 - if (!usbvision->have_tuner || vt->index) 641 + /* Only one tuner for now */ 642 + if (vt->index) 631 643 return -EINVAL; 632 644 /* let clients handle this */ 633 645 call_all(usbvision, tuner, s_tuner, vt); ··· 640 652 { 641 653 struct usb_usbvision *usbvision = video_drvdata(file); 642 654 643 - freq->tuner = 0; /* Only one tuner */ 644 - if (usbvision->radio) 645 - freq->type = V4L2_TUNER_RADIO; 655 + /* Only one tuner */ 656 + if (freq->tuner) 657 + return -EINVAL; 658 + if (freq->type == V4L2_TUNER_RADIO) 659 + freq->frequency = usbvision->radio_freq; 646 660 else 647 - freq->type = V4L2_TUNER_ANALOG_TV; 648 - freq->frequency = usbvision->freq; 661 + freq->frequency = usbvision->tv_freq; 649 662 650 663 return 0; 651 664 } ··· 655 666 const struct v4l2_frequency *freq) 656 667 { 657 668 struct usb_usbvision *usbvision = video_drvdata(file); 669 + struct v4l2_frequency new_freq = *freq; 658 670 659 - /* Only no or one tuner for now */ 660 - if (!usbvision->have_tuner || freq->tuner) 671 + /* Only one tuner for now */ 672 + if (freq->tuner) 661 673 return -EINVAL; 662 674 663 - usbvision->freq = freq->frequency; 664 675 call_all(usbvision, tuner, s_frequency, freq); 665 - 666 - return 0; 667 - } 668 - 669 - static int vidioc_g_audio(struct file *file, void *priv, struct v4l2_audio *a) 670 - { 671 - struct usb_usbvision *usbvision = video_drvdata(file); 672 - 673 - if (usbvision->radio) 674 - strcpy(a->name, "Radio"); 676 + call_all(usbvision, tuner, g_frequency, &new_freq); 677 + if (freq->type == V4L2_TUNER_RADIO) 678 + usbvision->radio_freq = new_freq.frequency; 675 679 else 676 - strcpy(a->name, "TV"); 680 + usbvision->tv_freq = new_freq.frequency; 677 681 678 - return 0; 679 - } 680 - 681 - static int vidioc_s_audio(struct file *file, void *fh, 682 - const struct v4l2_audio *a) 683 - { 684 - if (a->index) 685 - return -EINVAL; 686 - return 0; 687 - } 688 - 689 - static int vidioc_queryctrl(struct file *file, void *priv, 690 - struct v4l2_queryctrl *ctrl) 691 - { 692 - struct usb_usbvision *usbvision = video_drvdata(file); 693 - 694 - call_all(usbvision, core, queryctrl, ctrl); 695 - 696 - if (!ctrl->type) 697 - return -EINVAL; 698 - 699 - return 0; 700 - } 701 - 702 - static int vidioc_g_ctrl(struct file *file, void *priv, 703 - struct v4l2_control *ctrl) 704 - { 705 - struct usb_usbvision *usbvision = video_drvdata(file); 706 - 707 - call_all(usbvision, core, g_ctrl, ctrl); 708 - return 0; 709 - } 710 - 711 - static int vidioc_s_ctrl(struct file *file, void *priv, 712 - struct v4l2_control *ctrl) 713 - { 714 - struct usb_usbvision *usbvision = video_drvdata(file); 715 - 716 - call_all(usbvision, core, s_ctrl, ctrl); 717 682 return 0; 718 683 } 719 684 ··· 880 937 vf->fmt.pix.bytesperline = vf->fmt.pix.width* 881 938 usbvision->palette.bytes_per_pixel; 882 939 vf->fmt.pix.sizeimage = vf->fmt.pix.bytesperline*vf->fmt.pix.height; 940 + vf->fmt.pix.colorspace = V4L2_COLORSPACE_SMPTE170M; 941 + vf->fmt.pix.field = V4L2_FIELD_NONE; /* Always progressive image */ 883 942 884 943 return 0; 885 944 } ··· 1112 1167 1113 1168 if (mutex_lock_interruptible(&usbvision->v4l2_lock)) 1114 1169 return -ERESTARTSYS; 1170 + err_code = v4l2_fh_open(file); 1171 + if (err_code) 1172 + goto out; 1115 1173 if (usbvision->user) { 1116 1174 dev_err(&usbvision->rdev.dev, 1117 1175 "%s: Someone tried to open an already opened USBVision Radio!\n", 1118 1176 __func__); 1119 1177 err_code = -EBUSY; 1120 1178 } else { 1121 - if (power_on_at_open) { 1122 - usbvision_reset_power_off_timer(usbvision); 1123 - if (usbvision->power == 0) { 1124 - usbvision_power_on(usbvision); 1125 - usbvision_i2c_register(usbvision); 1126 - } 1127 - } 1128 - 1129 1179 /* Alternate interface 1 is is the biggest frame size */ 1130 1180 err_code = usbvision_set_alternate(usbvision); 1131 1181 if (err_code < 0) { ··· 1135 1195 usbvision_set_audio(usbvision, USBVISION_AUDIO_RADIO); 1136 1196 usbvision->user++; 1137 1197 } 1138 - 1139 - if (err_code) { 1140 - if (power_on_at_open) { 1141 - usbvision_i2c_unregister(usbvision); 1142 - usbvision_power_off(usbvision); 1143 - usbvision->initialized = 0; 1144 - } 1145 - } 1146 1198 out: 1147 1199 mutex_unlock(&usbvision->v4l2_lock); 1148 1200 return err_code; ··· 1144 1212 static int usbvision_radio_close(struct file *file) 1145 1213 { 1146 1214 struct usb_usbvision *usbvision = video_drvdata(file); 1147 - int err_code = 0; 1148 1215 1149 1216 PDEBUG(DBG_IO, ""); 1150 1217 1151 1218 mutex_lock(&usbvision->v4l2_lock); 1152 1219 /* Set packet size to 0 */ 1153 1220 usbvision->iface_alt = 0; 1154 - err_code = usb_set_interface(usbvision->dev, usbvision->iface, 1221 + usb_set_interface(usbvision->dev, usbvision->iface, 1155 1222 usbvision->iface_alt); 1156 1223 1157 1224 usbvision_audio_off(usbvision); 1158 1225 usbvision->radio = 0; 1159 1226 usbvision->user--; 1160 1227 1161 - if (power_on_at_open) { 1162 - usbvision_set_power_off_timer(usbvision); 1163 - usbvision->initialized = 0; 1164 - } 1165 - 1166 1228 if (usbvision->remove_pending) { 1167 1229 printk(KERN_INFO "%s: Final disconnect\n", __func__); 1230 + v4l2_fh_release(file); 1168 1231 usbvision_release(usbvision); 1169 - return err_code; 1232 + return 0; 1170 1233 } 1171 1234 1172 1235 mutex_unlock(&usbvision->v4l2_lock); 1173 1236 PDEBUG(DBG_IO, "success"); 1174 - return err_code; 1237 + return v4l2_fh_release(file); 1175 1238 } 1176 1239 1177 1240 /* Video registration stuff */ ··· 1179 1252 .read = usbvision_v4l2_read, 1180 1253 .mmap = usbvision_v4l2_mmap, 1181 1254 .unlocked_ioctl = video_ioctl2, 1182 - /* .poll = video_poll, */ 1183 1255 }; 1184 1256 1185 1257 static const struct v4l2_ioctl_ops usbvision_ioctl_ops = { ··· 1196 1270 .vidioc_enum_input = vidioc_enum_input, 1197 1271 .vidioc_g_input = vidioc_g_input, 1198 1272 .vidioc_s_input = vidioc_s_input, 1199 - .vidioc_queryctrl = vidioc_queryctrl, 1200 - .vidioc_g_audio = vidioc_g_audio, 1201 - .vidioc_s_audio = vidioc_s_audio, 1202 - .vidioc_g_ctrl = vidioc_g_ctrl, 1203 - .vidioc_s_ctrl = vidioc_s_ctrl, 1204 1273 .vidioc_streamon = vidioc_streamon, 1205 1274 .vidioc_streamoff = vidioc_streamoff, 1206 1275 .vidioc_g_tuner = vidioc_g_tuner, 1207 1276 .vidioc_s_tuner = vidioc_s_tuner, 1208 1277 .vidioc_g_frequency = vidioc_g_frequency, 1209 1278 .vidioc_s_frequency = vidioc_s_frequency, 1279 + .vidioc_log_status = v4l2_ctrl_log_status, 1280 + .vidioc_subscribe_event = v4l2_ctrl_subscribe_event, 1281 + .vidioc_unsubscribe_event = v4l2_event_unsubscribe, 1210 1282 #ifdef CONFIG_VIDEO_ADV_DEBUG 1211 1283 .vidioc_g_register = vidioc_g_register, 1212 1284 .vidioc_s_register = vidioc_s_register, ··· 1225 1301 .owner = THIS_MODULE, 1226 1302 .open = usbvision_radio_open, 1227 1303 .release = usbvision_radio_close, 1304 + .poll = v4l2_ctrl_poll, 1228 1305 .unlocked_ioctl = video_ioctl2, 1229 1306 }; 1230 1307 1231 1308 static const struct v4l2_ioctl_ops usbvision_radio_ioctl_ops = { 1232 1309 .vidioc_querycap = vidioc_querycap, 1233 - .vidioc_enum_input = vidioc_enum_input, 1234 - .vidioc_g_input = vidioc_g_input, 1235 - .vidioc_s_input = vidioc_s_input, 1236 - .vidioc_queryctrl = vidioc_queryctrl, 1237 - .vidioc_g_audio = vidioc_g_audio, 1238 - .vidioc_s_audio = vidioc_s_audio, 1239 - .vidioc_g_ctrl = vidioc_g_ctrl, 1240 - .vidioc_s_ctrl = vidioc_s_ctrl, 1241 1310 .vidioc_g_tuner = vidioc_g_tuner, 1242 1311 .vidioc_s_tuner = vidioc_s_tuner, 1243 1312 .vidioc_g_frequency = vidioc_g_frequency, 1244 1313 .vidioc_s_frequency = vidioc_s_frequency, 1314 + .vidioc_log_status = v4l2_ctrl_log_status, 1315 + .vidioc_subscribe_event = v4l2_ctrl_subscribe_event, 1316 + .vidioc_unsubscribe_event = v4l2_event_unsubscribe, 1245 1317 }; 1246 1318 1247 1319 static struct video_device usbvision_radio_template = { ··· 1289 1369 /* register video4linux devices */ 1290 1370 static int usbvision_register_video(struct usb_usbvision *usbvision) 1291 1371 { 1372 + int res = -ENOMEM; 1373 + 1292 1374 /* Video Device: */ 1293 1375 usbvision_vdev_init(usbvision, &usbvision->vdev, 1294 1376 &usbvision_video_template, "USBVision Video"); 1377 + if (!usbvision->have_tuner) { 1378 + v4l2_disable_ioctl(&usbvision->vdev, VIDIOC_G_FREQUENCY); 1379 + v4l2_disable_ioctl(&usbvision->vdev, VIDIOC_S_TUNER); 1380 + v4l2_disable_ioctl(&usbvision->vdev, VIDIOC_G_FREQUENCY); 1381 + v4l2_disable_ioctl(&usbvision->vdev, VIDIOC_S_TUNER); 1382 + } 1295 1383 if (video_register_device(&usbvision->vdev, VFL_TYPE_GRABBER, video_nr) < 0) 1296 1384 goto err_exit; 1297 1385 printk(KERN_INFO "USBVision[%d]: registered USBVision Video device %s [v4l2]\n", ··· 1323 1395 "USBVision[%d]: video_register_device() failed\n", 1324 1396 usbvision->nr); 1325 1397 usbvision_unregister_video(usbvision); 1326 - return -1; 1398 + return res; 1327 1399 } 1328 1400 1329 1401 /* ··· 1348 1420 if (v4l2_device_register(&intf->dev, &usbvision->v4l2_dev)) 1349 1421 goto err_free; 1350 1422 1423 + if (v4l2_ctrl_handler_init(&usbvision->hdl, 4)) 1424 + goto err_unreg; 1425 + usbvision->v4l2_dev.ctrl_handler = &usbvision->hdl; 1351 1426 mutex_init(&usbvision->v4l2_lock); 1352 1427 1353 1428 /* prepare control urb for control messages during interrupts */ ··· 1359 1428 goto err_unreg; 1360 1429 init_waitqueue_head(&usbvision->ctrl_urb_wq); 1361 1430 1362 - usbvision_init_power_off_timer(usbvision); 1363 - 1364 1431 return usbvision; 1365 1432 1366 1433 err_unreg: 1434 + v4l2_ctrl_handler_free(&usbvision->hdl); 1367 1435 v4l2_device_unregister(&usbvision->v4l2_dev); 1368 1436 err_free: 1369 1437 kfree(usbvision); ··· 1380 1450 { 1381 1451 PDEBUG(DBG_PROBE, ""); 1382 1452 1383 - usbvision_reset_power_off_timer(usbvision); 1384 - 1385 1453 usbvision->initialized = 0; 1386 1454 1387 1455 usbvision_remove_sysfs(&usbvision->vdev); ··· 1388 1460 1389 1461 usb_free_urb(usbvision->ctrl_urb); 1390 1462 1463 + v4l2_ctrl_handler_free(&usbvision->hdl); 1391 1464 v4l2_device_unregister(&usbvision->v4l2_dev); 1392 1465 kfree(usbvision); 1393 1466 ··· 1416 1487 } 1417 1488 1418 1489 usbvision->tvnorm_id = usbvision_device_data[model].video_norm; 1419 - 1420 1490 usbvision->video_inputs = usbvision_device_data[model].video_channels; 1421 1491 usbvision->ctl_input = 0; 1492 + usbvision->radio_freq = 87.5 * 16000; 1493 + usbvision->tv_freq = 400 * 16; 1422 1494 1423 1495 /* This should be here to make i2c clients to be able to register */ 1424 1496 /* first switch off audio */ 1425 1497 if (usbvision_device_data[model].audio_channels > 0) 1426 1498 usbvision_audio_off(usbvision); 1427 - if (!power_on_at_open) { 1428 - /* and then power up the noisy tuner */ 1429 - usbvision_power_on(usbvision); 1430 - usbvision_i2c_register(usbvision); 1431 - } 1499 + /* and then power up the tuner */ 1500 + usbvision_power_on(usbvision); 1501 + usbvision_i2c_register(usbvision); 1432 1502 } 1433 1503 1434 1504 /* ··· 1520 1592 1521 1593 usbvision->nr = usbvision_nr++; 1522 1594 1595 + spin_lock_init(&usbvision->queue_lock); 1596 + init_waitqueue_head(&usbvision->wait_frame); 1597 + init_waitqueue_head(&usbvision->wait_stream); 1598 + 1523 1599 usbvision->have_tuner = usbvision_device_data[model].tuner; 1524 1600 if (usbvision->have_tuner) 1525 1601 usbvision->tuner_type = usbvision_device_data[model].tuner_type; ··· 1578 1646 usbvision_stop_isoc(usbvision); 1579 1647 1580 1648 v4l2_device_disconnect(&usbvision->v4l2_dev); 1581 - 1582 - if (usbvision->power) { 1583 - usbvision_i2c_unregister(usbvision); 1584 - usbvision_power_off(usbvision); 1585 - } 1649 + usbvision_i2c_unregister(usbvision); 1586 1650 usbvision->remove_pending = 1; /* Now all ISO data will be ignored */ 1587 1651 1588 1652 usb_put_dev(usbvision->dev);
+4 -6
drivers/media/usb/usbvision/usbvision.h
··· 36 36 #include <linux/i2c.h> 37 37 #include <linux/mutex.h> 38 38 #include <media/v4l2-device.h> 39 + #include <media/v4l2-ctrls.h> 39 40 #include <media/tuner.h> 40 41 #include <linux/videodev2.h> 41 42 ··· 358 357 359 358 struct usb_usbvision { 360 359 struct v4l2_device v4l2_dev; 360 + struct v4l2_ctrl_handler hdl; 361 361 struct video_device vdev; /* Video Device */ 362 362 struct video_device rdev; /* Radio Device */ 363 363 ··· 378 376 int bridge_type; /* NT1003, NT1004, NT1005 */ 379 377 int radio; 380 378 int video_inputs; /* # of inputs */ 381 - unsigned long freq; 379 + unsigned long radio_freq; 380 + unsigned long tv_freq; 382 381 int audio_mute; 383 382 int audio_channel; 384 383 int isoc_mode; /* format of video data for the usb isoc-transfer */ ··· 394 391 unsigned char iface_alt; /* Alt settings */ 395 392 unsigned char vin_reg2_preset; 396 393 struct mutex v4l2_lock; 397 - struct timer_list power_off_timer; 398 - struct work_struct power_off_work; 399 394 int power; /* is the device powered on? */ 400 395 int user; /* user count for exclusive use */ 401 396 int initialized; /* Had we already sent init sequence? */ ··· 511 510 int usbvision_set_input(struct usb_usbvision *usbvision); 512 511 int usbvision_set_output(struct usb_usbvision *usbvision, int width, int height); 513 512 514 - void usbvision_init_power_off_timer(struct usb_usbvision *usbvision); 515 - void usbvision_set_power_off_timer(struct usb_usbvision *usbvision); 516 - void usbvision_reset_power_off_timer(struct usb_usbvision *usbvision); 517 513 int usbvision_power_off(struct usb_usbvision *usbvision); 518 514 int usbvision_power_on(struct usb_usbvision *usbvision); 519 515
+3
drivers/media/v4l2-core/Makefile
··· 13 13 ifeq ($(CONFIG_OF),y) 14 14 videodev-objs += v4l2-of.o 15 15 endif 16 + ifeq ($(CONFIG_TRACEPOINTS),y) 17 + videodev-objs += v4l2-trace.o 18 + endif 16 19 17 20 obj-$(CONFIG_VIDEO_V4L2) += videodev.o 18 21 obj-$(CONFIG_VIDEO_V4L2) += v4l2-common.o
-1
drivers/media/v4l2-core/tuner-core.c
··· 1366 1366 1367 1367 static struct i2c_driver tuner_driver = { 1368 1368 .driver = { 1369 - .owner = THIS_MODULE, 1370 1369 .name = "tuner", 1371 1370 .pm = &tuner_pm_ops, 1372 1371 },
-15
drivers/media/v4l2-core/v4l2-ctrls.c
··· 1678 1678 unsigned idx; 1679 1679 int err = 0; 1680 1680 1681 - if (!ctrl->is_ptr) { 1682 - switch (ctrl->type) { 1683 - case V4L2_CTRL_TYPE_INTEGER: 1684 - case V4L2_CTRL_TYPE_INTEGER_MENU: 1685 - case V4L2_CTRL_TYPE_MENU: 1686 - case V4L2_CTRL_TYPE_BITMASK: 1687 - case V4L2_CTRL_TYPE_BOOLEAN: 1688 - case V4L2_CTRL_TYPE_BUTTON: 1689 - case V4L2_CTRL_TYPE_CTRL_CLASS: 1690 - case V4L2_CTRL_TYPE_INTEGER64: 1691 - return ctrl->type_ops->validate(ctrl, 0, p_new); 1692 - default: 1693 - break; 1694 - } 1695 - } 1696 1681 for (idx = 0; !err && idx < ctrl->elems; idx++) 1697 1682 err = ctrl->type_ops->validate(ctrl, idx, p_new); 1698 1683 return err;
+68 -28
drivers/media/v4l2-core/v4l2-dv-timings.c
··· 256 256 { 257 257 const struct v4l2_bt_timings *bt = &t->bt; 258 258 u32 htot, vtot; 259 + u32 fps; 259 260 260 261 if (t->type != V4L2_DV_BT_656_1120) 261 262 return; ··· 266 265 if (bt->interlaced) 267 266 vtot /= 2; 268 267 268 + fps = (htot * vtot) > 0 ? div_u64((100 * (u64)bt->pixelclock), 269 + (htot * vtot)) : 0; 270 + 269 271 if (prefix == NULL) 270 272 prefix = ""; 271 273 272 - pr_info("%s: %s%ux%u%s%u (%ux%u)\n", dev_prefix, prefix, 274 + pr_info("%s: %s%ux%u%s%u.%u (%ux%u)\n", dev_prefix, prefix, 273 275 bt->width, bt->height, bt->interlaced ? "i" : "p", 274 - (htot * vtot) > 0 ? ((u32)bt->pixelclock / (htot * vtot)) : 0, 275 - htot, vtot); 276 + fps / 100, fps % 100, htot, vtot); 276 277 277 278 if (!detailed) 278 279 return; ··· 293 290 (bt->polarities & V4L2_DV_VSYNC_POS_POL) ? "+" : "-", 294 291 bt->il_vsync, bt->il_vbackporch); 295 292 pr_info("%s: pixelclock: %llu\n", dev_prefix, bt->pixelclock); 296 - pr_info("%s: flags (0x%x):%s%s%s%s%s\n", dev_prefix, bt->flags, 293 + pr_info("%s: flags (0x%x):%s%s%s%s%s%s\n", dev_prefix, bt->flags, 297 294 (bt->flags & V4L2_DV_FL_REDUCED_BLANKING) ? 298 295 " REDUCED_BLANKING" : "", 296 + ((bt->flags & V4L2_DV_FL_REDUCED_BLANKING) && 297 + bt->vsync == 8) ? " (V2)" : "", 299 298 (bt->flags & V4L2_DV_FL_CAN_REDUCE_FPS) ? 300 299 " CAN_REDUCE_FPS" : "", 301 300 (bt->flags & V4L2_DV_FL_REDUCED_FPS) ? ··· 321 316 */ 322 317 323 318 #define CVT_PXL_CLK_GRAN 250000 /* pixel clock granularity */ 319 + #define CVT_PXL_CLK_GRAN_RB_V2 1000 /* granularity for reduced blanking v2*/ 324 320 325 321 /* Normal blanking */ 326 322 #define CVT_MIN_V_BPORCH 7 /* lines */ ··· 341 335 /* Reduced Blanking */ 342 336 #define CVT_RB_MIN_V_BPORCH 7 /* lines */ 343 337 #define CVT_RB_V_FPORCH 3 /* lines */ 344 - #define CVT_RB_MIN_V_BLANK 460 /* us */ 338 + #define CVT_RB_MIN_V_BLANK 460 /* us */ 345 339 #define CVT_RB_H_SYNC 32 /* pixels */ 346 - #define CVT_RB_H_BPORCH 80 /* pixels */ 347 340 #define CVT_RB_H_BLANK 160 /* pixels */ 341 + /* Reduce blanking Version 2 */ 342 + #define CVT_RB_V2_H_BLANK 80 /* pixels */ 343 + #define CVT_RB_MIN_V_FPORCH 3 /* lines */ 344 + #define CVT_RB_V2_MIN_V_FPORCH 1 /* lines */ 345 + #define CVT_RB_V_BPORCH 6 /* lines */ 348 346 349 347 /** v4l2_detect_cvt - detect if the given timings follow the CVT standard 350 348 * @frame_height - the total height of the frame (including blanking) in lines. 351 349 * @hfreq - the horizontal frequency in Hz. 352 350 * @vsync - the height of the vertical sync in lines. 351 + * @active_width - active width of image (does not include blanking). This 352 + * information is needed only in case of version 2 of reduced blanking. 353 + * In other cases, this parameter does not have any effect on timings. 353 354 * @polarities - the horizontal and vertical polarities (same as struct 354 355 * v4l2_bt_timings polarities). 355 356 * @interlaced - if this flag is true, it indicates interlaced format ··· 365 352 * This function will attempt to detect if the given values correspond to a 366 353 * valid CVT format. If so, then it will return true, and fmt will be filled 367 354 * in with the found CVT timings. 368 - * 369 - * TODO: VESA defined a new version 2 of their reduced blanking 370 - * formula. Support for that is currently missing in this CVT 371 - * detection function. 372 355 */ 373 - bool v4l2_detect_cvt(unsigned frame_height, unsigned hfreq, unsigned vsync, 374 - u32 polarities, bool interlaced, struct v4l2_dv_timings *fmt) 356 + bool v4l2_detect_cvt(unsigned frame_height, 357 + unsigned hfreq, 358 + unsigned vsync, 359 + unsigned active_width, 360 + u32 polarities, 361 + bool interlaced, 362 + struct v4l2_dv_timings *fmt) 375 363 { 376 364 int v_fp, v_bp, h_fp, h_bp, hsync; 377 365 int frame_width, image_height, image_width; 378 366 bool reduced_blanking; 367 + bool rb_v2 = false; 379 368 unsigned pix_clk; 380 369 381 - if (vsync < 4 || vsync > 7) 370 + if (vsync < 4 || vsync > 8) 382 371 return false; 383 372 384 373 if (polarities == V4L2_DV_VSYNC_POS_POL) ··· 390 375 else 391 376 return false; 392 377 378 + if (reduced_blanking && vsync == 8) 379 + rb_v2 = true; 380 + 381 + if (rb_v2 && active_width == 0) 382 + return false; 383 + 384 + if (!rb_v2 && vsync > 7) 385 + return false; 386 + 393 387 if (hfreq == 0) 394 388 return false; 395 389 396 390 /* Vertical */ 397 391 if (reduced_blanking) { 398 - v_fp = CVT_RB_V_FPORCH; 399 - v_bp = (CVT_RB_MIN_V_BLANK * hfreq) / 1000000 + 1; 400 - v_bp -= vsync + v_fp; 392 + if (rb_v2) { 393 + v_bp = CVT_RB_V_BPORCH; 394 + v_fp = (CVT_RB_MIN_V_BLANK * hfreq) / 1000000 + 1; 395 + v_fp -= vsync + v_bp; 401 396 402 - if (v_bp < CVT_RB_MIN_V_BPORCH) 403 - v_bp = CVT_RB_MIN_V_BPORCH; 397 + if (v_fp < CVT_RB_V2_MIN_V_FPORCH) 398 + v_fp = CVT_RB_V2_MIN_V_FPORCH; 399 + } else { 400 + v_fp = CVT_RB_V_FPORCH; 401 + v_bp = (CVT_RB_MIN_V_BLANK * hfreq) / 1000000 + 1; 402 + v_bp -= vsync + v_fp; 403 + 404 + if (v_bp < CVT_RB_MIN_V_BPORCH) 405 + v_bp = CVT_RB_MIN_V_BPORCH; 406 + } 404 407 } else { 405 408 v_fp = CVT_MIN_V_PORCH_RND; 406 409 v_bp = (CVT_MIN_VSYNC_BP * hfreq) / 1000000 + 1 - vsync; ··· 455 422 else 456 423 return false; 457 424 break; 425 + case 8: 426 + image_width = active_width; 427 + break; 458 428 default: 459 429 return false; 460 430 } 461 431 462 - image_width = image_width & ~7; 432 + if (!rb_v2) 433 + image_width = image_width & ~7; 463 434 464 435 /* Horizontal */ 465 436 if (reduced_blanking) { 466 - pix_clk = (image_width + CVT_RB_H_BLANK) * hfreq; 467 - pix_clk = (pix_clk / CVT_PXL_CLK_GRAN) * CVT_PXL_CLK_GRAN; 437 + int h_blank; 438 + int clk_gran; 468 439 469 - h_bp = CVT_RB_H_BPORCH; 440 + h_blank = rb_v2 ? CVT_RB_V2_H_BLANK : CVT_RB_H_BLANK; 441 + clk_gran = rb_v2 ? CVT_PXL_CLK_GRAN_RB_V2 : CVT_PXL_CLK_GRAN; 442 + 443 + pix_clk = (image_width + h_blank) * hfreq; 444 + pix_clk = (pix_clk / clk_gran) * clk_gran; 445 + 446 + h_bp = h_blank / 2; 470 447 hsync = CVT_RB_H_SYNC; 471 - h_fp = CVT_RB_H_BLANK - h_bp - hsync; 448 + h_fp = h_blank - h_bp - hsync; 472 449 473 - frame_width = image_width + CVT_RB_H_BLANK; 450 + frame_width = image_width + h_blank; 474 451 } else { 475 452 unsigned ideal_duty_cycle_per_myriad = 476 453 100 * CVT_C_PRIME - (CVT_M_PRIME * 100000) / hfreq; ··· 708 665 struct v4l2_fract v4l2_calc_aspect_ratio(u8 hor_landscape, u8 vert_portrait) 709 666 { 710 667 struct v4l2_fract aspect = { 16, 9 }; 711 - u32 tmp; 712 668 u8 ratio; 713 669 714 670 /* Nothing filled in, fallback to 16:9 */ ··· 739 697 if (hor_landscape) 740 698 return aspect; 741 699 /* The aspect ratio is for portrait, so swap numerator and denominator */ 742 - tmp = aspect.denominator; 743 - aspect.denominator = aspect.numerator; 744 - aspect.numerator = tmp; 700 + swap(aspect.denominator, aspect.numerator); 745 701 return aspect; 746 702 } 747 703 EXPORT_SYMBOL_GPL(v4l2_calc_aspect_ratio);
+3
drivers/media/v4l2-core/v4l2-event.c
··· 172 172 unsigned long flags; 173 173 struct timespec timestamp; 174 174 175 + if (vdev == NULL) 176 + return; 177 + 175 178 ktime_get_ts(&timestamp); 176 179 177 180 spin_lock_irqsave(&vdev->fh_lock, flags);
+3 -3
drivers/media/v4l2-core/v4l2-ioctl.c
··· 28 28 #include <media/v4l2-device.h> 29 29 #include <media/videobuf2-core.h> 30 30 31 - #define CREATE_TRACE_POINTS 32 31 #include <trace/events/v4l2.h> 33 32 34 33 /* Zero out the end of the struct pointed to by p. Everything after, but ··· 1024 1025 * Drivers MUST fill in device_caps, so check for this and 1025 1026 * warn if it was forgotten. 1026 1027 */ 1027 - WARN_ON(!(cap->capabilities & V4L2_CAP_DEVICE_CAPS) || 1028 - !cap->device_caps); 1028 + WARN(!(cap->capabilities & V4L2_CAP_DEVICE_CAPS) || 1029 + !cap->device_caps, "Bad caps for driver %s, %x %x", 1030 + cap->driver, cap->capabilities, cap->device_caps); 1029 1031 cap->device_caps |= V4L2_CAP_EXT_PIX_FORMAT; 1030 1032 1031 1033 return ret;
+9 -12
drivers/media/v4l2-core/v4l2-mem2mem.c
··· 357 357 struct v4l2_requestbuffers *reqbufs) 358 358 { 359 359 struct vb2_queue *vq; 360 + int ret; 360 361 361 362 vq = v4l2_m2m_get_vq(m2m_ctx, reqbufs->type); 362 - return vb2_reqbufs(vq, reqbufs); 363 + ret = vb2_reqbufs(vq, reqbufs); 364 + /* If count == 0, then the owner has released all buffers and he 365 + is no longer owner of the queue. Otherwise we have an owner. */ 366 + if (ret == 0) 367 + vq->owner = reqbufs->count ? file->private_data : NULL; 368 + 369 + return ret; 363 370 } 364 371 EXPORT_SYMBOL_GPL(v4l2_m2m_reqbufs); 365 372 ··· 881 874 int v4l2_m2m_fop_mmap(struct file *file, struct vm_area_struct *vma) 882 875 { 883 876 struct v4l2_fh *fh = file->private_data; 884 - struct v4l2_m2m_ctx *m2m_ctx = fh->m2m_ctx; 885 - int ret; 886 877 887 - if (m2m_ctx->q_lock && mutex_lock_interruptible(m2m_ctx->q_lock)) 888 - return -ERESTARTSYS; 889 - 890 - ret = v4l2_m2m_mmap(file, m2m_ctx, vma); 891 - 892 - if (m2m_ctx->q_lock) 893 - mutex_unlock(m2m_ctx->q_lock); 894 - 895 - return ret; 878 + return v4l2_m2m_mmap(file, fh->m2m_ctx, vma); 896 879 } 897 880 EXPORT_SYMBOL_GPL(v4l2_m2m_fop_mmap); 898 881
+18
drivers/media/v4l2-core/v4l2-subdev.c
··· 588 588 #endif 589 589 } 590 590 EXPORT_SYMBOL(v4l2_subdev_init); 591 + 592 + /** 593 + * v4l2_subdev_notify_event() - Delivers event notification for subdevice 594 + * @sd: The subdev for which to deliver the event 595 + * @ev: The event to deliver 596 + * 597 + * Will deliver the specified event to all userspace event listeners which are 598 + * subscribed to the v42l subdev event queue as well as to the bridge driver 599 + * using the notify callback. The notification type for the notify callback 600 + * will be V4L2_DEVICE_NOTIFY_EVENT. 601 + */ 602 + void v4l2_subdev_notify_event(struct v4l2_subdev *sd, 603 + const struct v4l2_event *ev) 604 + { 605 + v4l2_event_queue(sd->devnode, ev); 606 + v4l2_subdev_notify(sd, V4L2_DEVICE_NOTIFY_EVENT, (void *)ev); 607 + } 608 + EXPORT_SYMBOL_GPL(v4l2_subdev_notify_event);
+11
drivers/media/v4l2-core/v4l2-trace.c
··· 1 + #include <media/v4l2-common.h> 2 + #include <media/v4l2-fh.h> 3 + #include <media/videobuf2-core.h> 4 + 5 + #define CREATE_TRACE_POINTS 6 + #include <trace/events/v4l2.h> 7 + 8 + EXPORT_TRACEPOINT_SYMBOL_GPL(vb2_buf_done); 9 + EXPORT_TRACEPOINT_SYMBOL_GPL(vb2_buf_queue); 10 + EXPORT_TRACEPOINT_SYMBOL_GPL(vb2_dqbuf); 11 + EXPORT_TRACEPOINT_SYMBOL_GPL(vb2_qbuf);
+11
drivers/media/v4l2-core/videobuf2-core.c
··· 30 30 #include <media/v4l2-common.h> 31 31 #include <media/videobuf2-core.h> 32 32 33 + #include <trace/events/v4l2.h> 34 + 33 35 static int debug; 34 36 module_param(debug, int, 0644); 35 37 ··· 1215 1213 atomic_dec(&q->owned_by_drv_count); 1216 1214 spin_unlock_irqrestore(&q->done_lock, flags); 1217 1215 1216 + trace_vb2_buf_done(q, vb); 1217 + 1218 1218 switch (state) { 1219 1219 case VB2_BUF_STATE_QUEUED: 1220 1220 return; ··· 1643 1639 vb->state = VB2_BUF_STATE_ACTIVE; 1644 1640 atomic_inc(&q->owned_by_drv_count); 1645 1641 1642 + trace_vb2_buf_queue(q, vb); 1643 + 1646 1644 /* sync buffers */ 1647 1645 for (plane = 0; plane < vb->num_planes; ++plane) 1648 1646 call_void_memop(vb, prepare, vb->planes[plane].mem_priv); ··· 1894 1888 vb->v4l2_buf.timecode = b->timecode; 1895 1889 } 1896 1890 1891 + trace_vb2_qbuf(q, vb); 1892 + 1897 1893 /* 1898 1894 * If already streaming, give the buffer to driver for processing. 1899 1895 * If not, the buffer will be given to driver on next streamon. ··· 2141 2133 /* Remove from videobuf queue */ 2142 2134 list_del(&vb->queued_entry); 2143 2135 q->queued_count--; 2136 + 2137 + trace_vb2_dqbuf(q, vb); 2138 + 2144 2139 if (!V4L2_TYPE_IS_OUTPUT(q->type) && 2145 2140 vb->v4l2_buf.flags & V4L2_BUF_FLAG_LAST) 2146 2141 q->last_buffer_dequeued = true;
+12 -8
drivers/staging/media/bcm2048/radio-bcm2048.c
··· 342 342 .deemphasis = 50, 343 343 .region = 3, 344 344 }, 345 - /* Japan wide band */ 346 - { 347 - .channel_spacing = 10, 348 - .bottom_frequency = 76000, 349 - .top_frequency = 108000, 350 - .deemphasis = 50, 351 - .region = 4, 352 - }, 353 345 }; 354 346 355 347 /* ··· 733 741 734 742 mutex_lock(&bdev->mutex); 735 743 bdev->region_info = region_configs[region]; 744 + 745 + if (region_configs[region].bottom_frequency < 87500) 746 + bdev->cache_fm_ctrl |= BCM2048_BAND_SELECT; 747 + else 748 + bdev->cache_fm_ctrl &= ~BCM2048_BAND_SELECT; 749 + 750 + err = bcm2048_send_command(bdev, BCM2048_I2C_FM_CTRL, 751 + bdev->cache_fm_ctrl); 752 + if (err) { 753 + mutex_unlock(&bdev->mutex); 754 + goto done; 755 + } 736 756 mutex_unlock(&bdev->mutex); 737 757 738 758 if (bdev->frequency < region_configs[region].bottom_frequency ||
+5 -5
drivers/staging/media/lirc/lirc_imon.c
··· 739 739 740 740 ep = &iface_desc->endpoint[i].desc; 741 741 ep_dir = ep->bEndpointAddress & USB_ENDPOINT_DIR_MASK; 742 - ep_type = ep->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK; 742 + ep_type = usb_endpoint_type(ep); 743 743 744 744 if (!ir_ep_found && 745 745 ep_dir == USB_DIR_IN && ··· 785 785 } 786 786 787 787 driver = kzalloc(sizeof(struct lirc_driver), GFP_KERNEL); 788 - if (!driver) { 788 + if (!driver) 789 789 goto free_context; 790 - } 790 + 791 791 rbuf = kmalloc(sizeof(struct lirc_buffer), GFP_KERNEL); 792 - if (!rbuf) { 792 + if (!rbuf) 793 793 goto free_driver; 794 - } 794 + 795 795 if (lirc_buffer_init(rbuf, BUF_CHUNK_SIZE, BUF_SIZE)) { 796 796 dev_err(dev, "%s: lirc_buffer_init failed\n", __func__); 797 797 goto free_rbuf;
+1 -1
drivers/staging/media/lirc/lirc_sasem.c
··· 184 184 __func__, retval); 185 185 else 186 186 dev_info(&context->dev->dev, 187 - "Deregistered Sasem driver (minor:%d)\n", minor); 187 + "Deregistered Sasem driver (minor:%d)\n", minor); 188 188 189 189 } 190 190
+1 -1
drivers/staging/media/lirc/lirc_zilog.c
··· 1364 1364 { "ir_rx_z8f0811_hdpvr", ID_FLAG_HDPVR }, 1365 1365 { } 1366 1366 }; 1367 + MODULE_DEVICE_TABLE(i2c, ir_transceiver_id); 1367 1368 1368 1369 static struct i2c_driver driver = { 1369 1370 .driver = { 1370 - .owner = THIS_MODULE, 1371 1371 .name = "Zilog/Hauppauge i2c IR", 1372 1372 }, 1373 1373 .probe = ir_probe,
-1
drivers/staging/media/mn88472/mn88472.c
··· 561 561 562 562 static struct i2c_driver mn88472_driver = { 563 563 .driver = { 564 - .owner = THIS_MODULE, 565 564 .name = "mn88472", 566 565 }, 567 566 .probe = mn88472_probe,
-1
drivers/staging/media/mn88473/mn88473.c
··· 507 507 508 508 static struct i2c_driver mn88473_driver = { 509 509 .driver = { 510 - .owner = THIS_MODULE, 511 510 .name = "mn88473", 512 511 }, 513 512 .probe = mn88473_probe,
+1 -1
drivers/staging/media/omap4iss/Kconfig
··· 1 1 config VIDEO_OMAP4 2 - bool "OMAP 4 Camera support" 2 + tristate "OMAP 4 Camera support" 3 3 depends on VIDEO_V4L2=y && VIDEO_V4L2_SUBDEV_API && I2C=y && ARCH_OMAP4 4 4 depends on HAS_DMA 5 5 select MFD_SYSCON
-1
drivers/staging/media/omap4iss/TODO
··· 1 - * Make the driver compile as a module 2 1 * Fix FIFO/buffer overflows and underflows 3 2 * Replace dummy resizer code with a real implementation 4 3 * Fix checkpatch errors and warnings
-73
drivers/staging/media/omap4iss/iss_video.c
··· 640 640 } 641 641 642 642 static int 643 - iss_video_cropcap(struct file *file, void *fh, struct v4l2_cropcap *cropcap) 644 - { 645 - struct iss_video *video = video_drvdata(file); 646 - struct v4l2_subdev *subdev; 647 - int ret; 648 - 649 - subdev = iss_video_remote_subdev(video, NULL); 650 - if (subdev == NULL) 651 - return -EINVAL; 652 - 653 - mutex_lock(&video->mutex); 654 - ret = v4l2_subdev_call(subdev, video, cropcap, cropcap); 655 - mutex_unlock(&video->mutex); 656 - 657 - return ret == -ENOIOCTLCMD ? -ENOTTY : ret; 658 - } 659 - 660 - static int 661 - iss_video_get_crop(struct file *file, void *fh, struct v4l2_crop *crop) 662 - { 663 - struct iss_video *video = video_drvdata(file); 664 - struct v4l2_subdev_format format; 665 - struct v4l2_subdev *subdev; 666 - u32 pad; 667 - int ret; 668 - 669 - subdev = iss_video_remote_subdev(video, &pad); 670 - if (subdev == NULL) 671 - return -EINVAL; 672 - 673 - /* Try the get crop operation first and fallback to get format if not 674 - * implemented. 675 - */ 676 - ret = v4l2_subdev_call(subdev, video, g_crop, crop); 677 - if (ret != -ENOIOCTLCMD) 678 - return ret; 679 - 680 - format.pad = pad; 681 - format.which = V4L2_SUBDEV_FORMAT_ACTIVE; 682 - ret = v4l2_subdev_call(subdev, pad, get_fmt, NULL, &format); 683 - if (ret < 0) 684 - return ret == -ENOIOCTLCMD ? -ENOTTY : ret; 685 - 686 - crop->c.left = 0; 687 - crop->c.top = 0; 688 - crop->c.width = format.format.width; 689 - crop->c.height = format.format.height; 690 - 691 - return 0; 692 - } 693 - 694 - static int 695 - iss_video_set_crop(struct file *file, void *fh, const struct v4l2_crop *crop) 696 - { 697 - struct iss_video *video = video_drvdata(file); 698 - struct v4l2_subdev *subdev; 699 - int ret; 700 - 701 - subdev = iss_video_remote_subdev(video, NULL); 702 - if (subdev == NULL) 703 - return -EINVAL; 704 - 705 - mutex_lock(&video->mutex); 706 - ret = v4l2_subdev_call(subdev, video, s_crop, crop); 707 - mutex_unlock(&video->mutex); 708 - 709 - return ret == -ENOIOCTLCMD ? -ENOTTY : ret; 710 - } 711 - 712 - static int 713 643 iss_video_get_param(struct file *file, void *fh, struct v4l2_streamparm *a) 714 644 { 715 645 struct iss_video_fh *vfh = to_iss_video_fh(fh); ··· 948 1018 .vidioc_g_fmt_vid_out = iss_video_get_format, 949 1019 .vidioc_s_fmt_vid_out = iss_video_set_format, 950 1020 .vidioc_try_fmt_vid_out = iss_video_try_format, 951 - .vidioc_cropcap = iss_video_cropcap, 952 - .vidioc_g_crop = iss_video_get_crop, 953 - .vidioc_s_crop = iss_video_set_crop, 954 1021 .vidioc_g_parm = iss_video_get_param, 955 1022 .vidioc_s_parm = iss_video_set_param, 956 1023 .vidioc_reqbufs = iss_video_reqbufs,
+12
include/dt-bindings/media/c8sectpfe.h
··· 1 + #ifndef __DT_C8SECTPFE_H 2 + #define __DT_C8SECTPFE_H 3 + 4 + #define STV0367_TDA18212_NIMA_1 0 5 + #define STV0367_TDA18212_NIMA_2 1 6 + #define STV0367_TDA18212_NIMB_1 2 7 + #define STV0367_TDA18212_NIMB_2 3 8 + 9 + #define STV0903_6110_LNB24_NIMA 4 10 + #define STV0903_6110_LNB24_NIMB 5 11 + 12 + #endif /* __DT_C8SECTPFE_H */
+9
include/linux/pci_ids.h
··· 2332 2332 2333 2333 #define PCI_VENDOR_ID_CAVIUM 0x177d 2334 2334 2335 + #define PCI_VENDOR_ID_TECHWELL 0x1797 2336 + #define PCI_DEVICE_ID_TECHWELL_6800 0x6800 2337 + #define PCI_DEVICE_ID_TECHWELL_6801 0x6801 2338 + #define PCI_DEVICE_ID_TECHWELL_6804 0x6804 2339 + #define PCI_DEVICE_ID_TECHWELL_6816_1 0x6810 2340 + #define PCI_DEVICE_ID_TECHWELL_6816_2 0x6811 2341 + #define PCI_DEVICE_ID_TECHWELL_6816_3 0x6812 2342 + #define PCI_DEVICE_ID_TECHWELL_6816_4 0x6813 2343 + 2335 2344 #define PCI_VENDOR_ID_BELKIN 0x1799 2336 2345 #define PCI_DEVICE_ID_BELKIN_F5D7010V7 0x701f 2337 2346
+4
include/media/media-devnode.h
··· 53 53 54 54 /** 55 55 * struct media_devnode - Media device node 56 + * @fops: pointer to struct media_file_operations with media device ops 57 + * @dev: struct device pointer for the media controller device 58 + * @cdev: struct cdev pointer character device 56 59 * @parent: parent device 57 60 * @minor: device node minor number 58 61 * @flags: flags, combination of the MEDIA_FLAG_* constants 62 + * @release: release callback called at the end of media_devnode_release() 59 63 * 60 64 * This structure represents a media-related device node. 61 65 *
+8 -34
include/media/omap3isp.h drivers/media/platform/omap3isp/omap3isp.h
··· 1 1 /* 2 2 * omap3isp.h 3 3 * 4 - * TI OMAP3 ISP - Platform data 4 + * TI OMAP3 ISP - Bus Configuration 5 5 * 6 6 * Copyright (C) 2011 Nokia Corporation 7 7 * ··· 16 16 * WITHOUT ANY WARRANTY; without even the implied warranty of 17 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 18 18 * General Public License for more details. 19 - * 20 - * You should have received a copy of the GNU General Public License 21 - * along with this program; if not, write to the Free Software 22 - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 23 - * 02110-1301 USA 24 19 */ 25 20 26 - #ifndef __MEDIA_OMAP3ISP_H__ 27 - #define __MEDIA_OMAP3ISP_H__ 28 - 29 - struct i2c_board_info; 30 - struct isp_device; 21 + #ifndef __OMAP3ISP_H__ 22 + #define __OMAP3ISP_H__ 31 23 32 24 enum isp_interface_type { 33 25 ISP_INTERFACE_PARALLEL, ··· 29 37 ISP_INTERFACE_CSI2C_PHY1, 30 38 }; 31 39 32 - enum { 33 - ISP_LANE_SHIFT_0 = 0, 34 - ISP_LANE_SHIFT_2 = 1, 35 - ISP_LANE_SHIFT_4 = 2, 36 - ISP_LANE_SHIFT_6 = 3, 37 - }; 38 - 39 40 /** 40 41 * struct isp_parallel_cfg - Parallel interface configuration 41 42 * @data_lane_shift: Data lane shifter 42 - * ISP_LANE_SHIFT_0 - CAMEXT[13:0] -> CAM[13:0] 43 - * ISP_LANE_SHIFT_2 - CAMEXT[13:2] -> CAM[11:0] 44 - * ISP_LANE_SHIFT_4 - CAMEXT[13:4] -> CAM[9:0] 45 - * ISP_LANE_SHIFT_6 - CAMEXT[13:6] -> CAM[7:0] 43 + * 0 - CAMEXT[13:0] -> CAM[13:0] 44 + * 1 - CAMEXT[13:2] -> CAM[11:0] 45 + * 2 - CAMEXT[13:4] -> CAM[9:0] 46 + * 3 - CAMEXT[13:6] -> CAM[7:0] 46 47 * @clk_pol: Pixel clock polarity 47 48 * 0 - Sample on rising edge, 1 - Sample on falling edge 48 49 * @hs_pol: Horizontal synchronization polarity ··· 129 144 } bus; /* gcc < 4.6.0 chokes on anonymous union initializers */ 130 145 }; 131 146 132 - struct isp_platform_subdev { 133 - struct i2c_board_info *board_info; 134 - int i2c_adapter_id; 135 - struct isp_bus_cfg *bus; 136 - }; 137 - 138 - struct isp_platform_data { 139 - struct isp_platform_subdev *subdevs; 140 - void (*set_constraints)(struct isp_device *isp, bool enable); 141 - }; 142 - 143 - #endif /* __MEDIA_OMAP3ISP_H__ */ 147 + #endif /* __OMAP3ISP_H__ */
+3 -3
include/media/rc-core.h
··· 69 69 * @rc_map: current scan/key table 70 70 * @lock: used to ensure we've filled in all protocol details before 71 71 * anyone can call show_protocols or store_protocols 72 - * @devno: unique remote control device number 72 + * @minor: unique minor remote control device number 73 73 * @raw: additional data for raw pulse/space devices 74 74 * @input_dev: the input child device used to communicate events to userspace 75 75 * @driver_type: specifies if protocol decoding is done in hardware or software ··· 110 110 * @s_tx_mask: set transmitter mask (for devices with multiple tx outputs) 111 111 * @s_tx_carrier: set transmit carrier frequency 112 112 * @s_tx_duty_cycle: set transmit duty cycle (0% - 100%) 113 - * @s_rx_carrier: inform driver about carrier it is expected to handle 113 + * @s_rx_carrier_range: inform driver about carrier it is expected to handle 114 114 * @tx_ir: transmit IR 115 115 * @s_idle: enable/disable hardware idle mode, upon which, 116 116 * device doesn't interrupt host until it sees IR pulses ··· 129 129 const char *map_name; 130 130 struct rc_map rc_map; 131 131 struct mutex lock; 132 - unsigned long devno; 132 + unsigned int minor; 133 133 struct ir_raw_event_ctrl *raw; 134 134 struct input_dev *input_dev; 135 135 enum rc_driver_type driver_type;
+18 -20
include/media/rc-map.h
··· 14 14 enum rc_type { 15 15 RC_TYPE_UNKNOWN = 0, /* Protocol not known */ 16 16 RC_TYPE_OTHER = 1, /* Protocol known but proprietary */ 17 - RC_TYPE_LIRC = 2, /* Pass raw IR to lirc userspace */ 18 - RC_TYPE_RC5 = 3, /* Philips RC5 protocol */ 19 - RC_TYPE_RC5X = 4, /* Philips RC5x protocol */ 20 - RC_TYPE_RC5_SZ = 5, /* StreamZap variant of RC5 */ 21 - RC_TYPE_JVC = 6, /* JVC protocol */ 22 - RC_TYPE_SONY12 = 7, /* Sony 12 bit protocol */ 23 - RC_TYPE_SONY15 = 8, /* Sony 15 bit protocol */ 24 - RC_TYPE_SONY20 = 9, /* Sony 20 bit protocol */ 25 - RC_TYPE_NEC = 10, /* NEC protocol */ 26 - RC_TYPE_SANYO = 11, /* Sanyo protocol */ 27 - RC_TYPE_MCE_KBD = 12, /* RC6-ish MCE keyboard/mouse */ 28 - RC_TYPE_RC6_0 = 13, /* Philips RC6-0-16 protocol */ 29 - RC_TYPE_RC6_6A_20 = 14, /* Philips RC6-6A-20 protocol */ 30 - RC_TYPE_RC6_6A_24 = 15, /* Philips RC6-6A-24 protocol */ 31 - RC_TYPE_RC6_6A_32 = 16, /* Philips RC6-6A-32 protocol */ 32 - RC_TYPE_RC6_MCE = 17, /* MCE (Philips RC6-6A-32 subtype) protocol */ 33 - RC_TYPE_SHARP = 18, /* Sharp protocol */ 34 - RC_TYPE_XMP = 19, /* XMP protocol */ 17 + RC_TYPE_RC5 = 2, /* Philips RC5 protocol */ 18 + RC_TYPE_RC5X = 3, /* Philips RC5x protocol */ 19 + RC_TYPE_RC5_SZ = 4, /* StreamZap variant of RC5 */ 20 + RC_TYPE_JVC = 5, /* JVC protocol */ 21 + RC_TYPE_SONY12 = 6, /* Sony 12 bit protocol */ 22 + RC_TYPE_SONY15 = 7, /* Sony 15 bit protocol */ 23 + RC_TYPE_SONY20 = 8, /* Sony 20 bit protocol */ 24 + RC_TYPE_NEC = 9, /* NEC protocol */ 25 + RC_TYPE_SANYO = 10, /* Sanyo protocol */ 26 + RC_TYPE_MCE_KBD = 11, /* RC6-ish MCE keyboard/mouse */ 27 + RC_TYPE_RC6_0 = 12, /* Philips RC6-0-16 protocol */ 28 + RC_TYPE_RC6_6A_20 = 13, /* Philips RC6-6A-20 protocol */ 29 + RC_TYPE_RC6_6A_24 = 14, /* Philips RC6-6A-24 protocol */ 30 + RC_TYPE_RC6_6A_32 = 15, /* Philips RC6-6A-32 protocol */ 31 + RC_TYPE_RC6_MCE = 16, /* MCE (Philips RC6-6A-32 subtype) protocol */ 32 + RC_TYPE_SHARP = 17, /* Sharp protocol */ 33 + RC_TYPE_XMP = 18, /* XMP protocol */ 35 34 }; 36 35 37 36 #define RC_BIT_NONE 0 38 37 #define RC_BIT_UNKNOWN (1 << RC_TYPE_UNKNOWN) 39 38 #define RC_BIT_OTHER (1 << RC_TYPE_OTHER) 40 - #define RC_BIT_LIRC (1 << RC_TYPE_LIRC) 41 39 #define RC_BIT_RC5 (1 << RC_TYPE_RC5) 42 40 #define RC_BIT_RC5X (1 << RC_TYPE_RC5X) 43 41 #define RC_BIT_RC5_SZ (1 << RC_TYPE_RC5_SZ) ··· 54 56 #define RC_BIT_SHARP (1 << RC_TYPE_SHARP) 55 57 #define RC_BIT_XMP (1 << RC_TYPE_XMP) 56 58 57 - #define RC_BIT_ALL (RC_BIT_UNKNOWN | RC_BIT_OTHER | RC_BIT_LIRC | \ 59 + #define RC_BIT_ALL (RC_BIT_UNKNOWN | RC_BIT_OTHER | \ 58 60 RC_BIT_RC5 | RC_BIT_RC5X | RC_BIT_RC5_SZ | \ 59 61 RC_BIT_JVC | \ 60 62 RC_BIT_SONY12 | RC_BIT_SONY15 | RC_BIT_SONY20 | \
+131
include/media/tc358743.h
··· 1 + /* 2 + * tc358743 - Toshiba HDMI to CSI-2 bridge 3 + * 4 + * Copyright 2015 Cisco Systems, Inc. and/or its affiliates. All rights 5 + * reserved. 6 + * 7 + * This program is free software; you may redistribute it and/or modify 8 + * it under the terms of the GNU General Public License as published by 9 + * the Free Software Foundation; version 2 of the License. 10 + * 11 + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 12 + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 13 + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 14 + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 15 + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 16 + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 17 + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 18 + * SOFTWARE. 19 + * 20 + */ 21 + 22 + /* 23 + * References (c = chapter, p = page): 24 + * REF_01 - Toshiba, TC358743XBG (H2C), Functional Specification, Rev 0.60 25 + * REF_02 - Toshiba, TC358743XBG_HDMI-CSI_Tv11p_nm.xls 26 + */ 27 + 28 + #ifndef _TC358743_ 29 + #define _TC358743_ 30 + 31 + enum tc358743_ddc5v_delays { 32 + DDC5V_DELAY_0_MS, 33 + DDC5V_DELAY_50_MS, 34 + DDC5V_DELAY_100_MS, 35 + DDC5V_DELAY_200_MS, 36 + }; 37 + 38 + enum tc358743_hdmi_detection_delay { 39 + HDMI_MODE_DELAY_0_MS, 40 + HDMI_MODE_DELAY_25_MS, 41 + HDMI_MODE_DELAY_50_MS, 42 + HDMI_MODE_DELAY_100_MS, 43 + }; 44 + 45 + struct tc358743_platform_data { 46 + /* System clock connected to REFCLK (pin H5) */ 47 + u32 refclk_hz; /* 26 MHz, 27 MHz or 42 MHz */ 48 + 49 + /* DDC +5V debounce delay to avoid spurious interrupts when the cable 50 + * is connected. 51 + * Sets DDC5V_MODE in register DDC_CTL. 52 + * Default: DDC5V_DELAY_0_MS 53 + */ 54 + enum tc358743_ddc5v_delays ddc5v_delay; 55 + 56 + bool enable_hdcp; 57 + 58 + /* 59 + * The FIFO size is 512x32, so Toshiba recommend to set the default FIFO 60 + * level to somewhere in the middle (e.g. 300), so it can cover speed 61 + * mismatches in input and output ports. 62 + */ 63 + u16 fifo_level; 64 + 65 + /* Bps pr lane is (refclk_hz / pll_prd) * pll_fbd */ 66 + u16 pll_prd; 67 + u16 pll_fbd; 68 + 69 + /* CSI 70 + * Calculate CSI parameters with REF_02 for the highest resolution your 71 + * CSI interface can handle. The driver will adjust the number of CSI 72 + * lanes in use according to the pixel clock. 73 + * 74 + * The values in brackets are calculated with REF_02 when the number of 75 + * bps pr lane is 823.5 MHz, and can serve as a starting point. 76 + */ 77 + u32 lineinitcnt; /* (0x00001770) */ 78 + u32 lptxtimecnt; /* (0x00000005) */ 79 + u32 tclk_headercnt; /* (0x00001d04) */ 80 + u32 tclk_trailcnt; /* (0x00000000) */ 81 + u32 ths_headercnt; /* (0x00000505) */ 82 + u32 twakeup; /* (0x00004650) */ 83 + u32 tclk_postcnt; /* (0x00000000) */ 84 + u32 ths_trailcnt; /* (0x00000004) */ 85 + u32 hstxvregcnt; /* (0x00000005) */ 86 + 87 + /* DVI->HDMI detection delay to avoid unnecessary switching between DVI 88 + * and HDMI mode. 89 + * Sets HDMI_DET_V in register HDMI_DET. 90 + * Default: HDMI_MODE_DELAY_0_MS 91 + */ 92 + enum tc358743_hdmi_detection_delay hdmi_detection_delay; 93 + 94 + /* Reset PHY automatically when TMDS clock goes from DC to AC. 95 + * Sets PHY_AUTO_RST2 in register PHY_CTL2. 96 + * Default: false 97 + */ 98 + bool hdmi_phy_auto_reset_tmds_detected; 99 + 100 + /* Reset PHY automatically when TMDS clock passes 21 MHz. 101 + * Sets PHY_AUTO_RST3 in register PHY_CTL2. 102 + * Default: false 103 + */ 104 + bool hdmi_phy_auto_reset_tmds_in_range; 105 + 106 + /* Reset PHY automatically when TMDS clock is detected. 107 + * Sets PHY_AUTO_RST4 in register PHY_CTL2. 108 + * Default: false 109 + */ 110 + bool hdmi_phy_auto_reset_tmds_valid; 111 + 112 + /* Reset HDMI PHY automatically when hsync period is out of range. 113 + * Sets H_PI_RST in register HV_RST. 114 + * Default: false 115 + */ 116 + bool hdmi_phy_auto_reset_hsync_out_of_range; 117 + 118 + /* Reset HDMI PHY automatically when vsync period is out of range. 119 + * Sets V_PI_RST in register HV_RST. 120 + * Default: false 121 + */ 122 + bool hdmi_phy_auto_reset_vsync_out_of_range; 123 + }; 124 + 125 + /* custom controls */ 126 + /* Audio sample rate in Hz */ 127 + #define TC358743_CID_AUDIO_SAMPLING_RATE (V4L2_CID_USER_TC358743_BASE + 0) 128 + /* Audio present status */ 129 + #define TC358743_CID_AUDIO_PRESENT (V4L2_CID_USER_TC358743_BASE + 1) 130 + 131 + #endif
+5 -3
include/media/v4l2-async.h
··· 32 32 33 33 /** 34 34 * struct v4l2_async_subdev - sub-device descriptor, as known to a bridge 35 - * @bus_type: subdevice bus type to select the appropriate matching method 35 + * 36 + * @match_type: type of match that will be used 36 37 * @match: union of per-bus type matching data sets 37 38 * @list: used to link struct v4l2_async_subdev objects, waiting to be 38 39 * probed, to a notifier->waiting list ··· 63 62 }; 64 63 65 64 /** 66 - * v4l2_async_notifier - v4l2_device notifier data 67 - * @num_subdevs:number of subdevices 65 + * struct v4l2_async_notifier - v4l2_device notifier data 66 + * 67 + * @num_subdevs: number of subdevices 68 68 * @subdevs: array of pointers to subdevice descriptors 69 69 * @v4l2_dev: pointer to struct v4l2_device 70 70 * @waiting: list of struct v4l2_async_subdev, waiting for their drivers
+558 -460
include/media/v4l2-ctrls.h
··· 36 36 struct v4l2_fh; 37 37 struct poll_table_struct; 38 38 39 - /** union v4l2_ctrl_ptr - A pointer to a control value. 39 + /** 40 + * union v4l2_ctrl_ptr - A pointer to a control value. 40 41 * @p_s32: Pointer to a 32-bit signed value. 41 42 * @p_s64: Pointer to a 64-bit signed value. 42 43 * @p_u8: Pointer to a 8-bit unsigned value. ··· 56 55 void *p; 57 56 }; 58 57 59 - /** struct v4l2_ctrl_ops - The control operations that the driver has to provide. 60 - * @g_volatile_ctrl: Get a new value for this control. Generally only relevant 61 - * for volatile (and usually read-only) controls such as a control 62 - * that returns the current signal strength which changes 63 - * continuously. 64 - * If not set, then the currently cached value will be returned. 65 - * @try_ctrl: Test whether the control's value is valid. Only relevant when 66 - * the usual min/max/step checks are not sufficient. 67 - * @s_ctrl: Actually set the new control value. s_ctrl is compulsory. The 68 - * ctrl->handler->lock is held when these ops are called, so no 69 - * one else can access controls owned by that handler. 70 - */ 58 + /** 59 + * struct v4l2_ctrl_ops - The control operations that the driver has to provide. 60 + * @g_volatile_ctrl: Get a new value for this control. Generally only relevant 61 + * for volatile (and usually read-only) controls such as a control 62 + * that returns the current signal strength which changes 63 + * continuously. 64 + * If not set, then the currently cached value will be returned. 65 + * @try_ctrl: Test whether the control's value is valid. Only relevant when 66 + * the usual min/max/step checks are not sufficient. 67 + * @s_ctrl: Actually set the new control value. s_ctrl is compulsory. The 68 + * ctrl->handler->lock is held when these ops are called, so no 69 + * one else can access controls owned by that handler. 70 + */ 71 71 struct v4l2_ctrl_ops { 72 72 int (*g_volatile_ctrl)(struct v4l2_ctrl *ctrl); 73 73 int (*try_ctrl)(struct v4l2_ctrl *ctrl); 74 74 int (*s_ctrl)(struct v4l2_ctrl *ctrl); 75 75 }; 76 76 77 - /** struct v4l2_ctrl_type_ops - The control type operations that the driver has to provide. 78 - * @equal: return true if both values are equal. 79 - * @init: initialize the value. 80 - * @log: log the value. 81 - * @validate: validate the value. Return 0 on success and a negative value otherwise. 82 - */ 77 + /** 78 + * struct v4l2_ctrl_type_ops - The control type operations that the driver 79 + * has to provide. 80 + * 81 + * @equal: return true if both values are equal. 82 + * @init: initialize the value. 83 + * @log: log the value. 84 + * @validate: validate the value. Return 0 on success and a negative value otherwise. 85 + */ 83 86 struct v4l2_ctrl_type_ops { 84 87 bool (*equal)(const struct v4l2_ctrl *ctrl, u32 idx, 85 88 union v4l2_ctrl_ptr ptr1, ··· 97 92 98 93 typedef void (*v4l2_ctrl_notify_fnc)(struct v4l2_ctrl *ctrl, void *priv); 99 94 100 - /** struct v4l2_ctrl - The control structure. 101 - * @node: The list node. 102 - * @ev_subs: The list of control event subscriptions. 103 - * @handler: The handler that owns the control. 104 - * @cluster: Point to start of cluster array. 105 - * @ncontrols: Number of controls in cluster array. 106 - * @done: Internal flag: set for each processed control. 107 - * @is_new: Set when the user specified a new value for this control. It 108 - * is also set when called from v4l2_ctrl_handler_setup. Drivers 109 - * should never set this flag. 110 - * @has_changed: Set when the current value differs from the new value. Drivers 111 - * should never use this flag. 112 - * @is_private: If set, then this control is private to its handler and it 113 - * will not be added to any other handlers. Drivers can set 114 - * this flag. 115 - * @is_auto: If set, then this control selects whether the other cluster 116 - * members are in 'automatic' mode or 'manual' mode. This is 117 - * used for autogain/gain type clusters. Drivers should never 118 - * set this flag directly. 119 - * @is_int: If set, then this control has a simple integer value (i.e. it 120 - * uses ctrl->val). 121 - * @is_string: If set, then this control has type V4L2_CTRL_TYPE_STRING. 122 - * @is_ptr: If set, then this control is an array and/or has type >= V4L2_CTRL_COMPOUND_TYPES 123 - * and/or has type V4L2_CTRL_TYPE_STRING. In other words, struct 124 - * v4l2_ext_control uses field p to point to the data. 125 - * @is_array: If set, then this control contains an N-dimensional array. 126 - * @has_volatiles: If set, then one or more members of the cluster are volatile. 127 - * Drivers should never touch this flag. 128 - * @call_notify: If set, then call the handler's notify function whenever the 129 - * control's value changes. 130 - * @manual_mode_value: If the is_auto flag is set, then this is the value 131 - * of the auto control that determines if that control is in 132 - * manual mode. So if the value of the auto control equals this 133 - * value, then the whole cluster is in manual mode. Drivers should 134 - * never set this flag directly. 135 - * @ops: The control ops. 136 - * @type_ops: The control type ops. 137 - * @id: The control ID. 138 - * @name: The control name. 139 - * @type: The control type. 140 - * @minimum: The control's minimum value. 141 - * @maximum: The control's maximum value. 142 - * @default_value: The control's default value. 143 - * @step: The control's step value for non-menu controls. 144 - * @elems: The number of elements in the N-dimensional array. 145 - * @elem_size: The size in bytes of the control. 146 - * @dims: The size of each dimension. 147 - * @nr_of_dims:The number of dimensions in @dims. 148 - * @menu_skip_mask: The control's skip mask for menu controls. This makes it 149 - * easy to skip menu items that are not valid. If bit X is set, 150 - * then menu item X is skipped. Of course, this only works for 151 - * menus with <= 32 menu items. There are no menus that come 152 - * close to that number, so this is OK. Should we ever need more, 153 - * then this will have to be extended to a u64 or a bit array. 154 - * @qmenu: A const char * array for all menu items. Array entries that are 155 - * empty strings ("") correspond to non-existing menu items (this 156 - * is in addition to the menu_skip_mask above). The last entry 157 - * must be NULL. 158 - * @flags: The control's flags. 159 - * @cur: The control's current value. 160 - * @val: The control's new s32 value. 161 - * @val64: The control's new s64 value. 162 - * @priv: The control's private pointer. For use by the driver. It is 163 - * untouched by the control framework. Note that this pointer is 164 - * not freed when the control is deleted. Should this be needed 165 - * then a new internal bitfield can be added to tell the framework 166 - * to free this pointer. 167 - */ 95 + /** 96 + * struct v4l2_ctrl - The control structure. 97 + * @node: The list node. 98 + * @ev_subs: The list of control event subscriptions. 99 + * @handler: The handler that owns the control. 100 + * @cluster: Point to start of cluster array. 101 + * @ncontrols: Number of controls in cluster array. 102 + * @done: Internal flag: set for each processed control. 103 + * @is_new: Set when the user specified a new value for this control. It 104 + * is also set when called from v4l2_ctrl_handler_setup. Drivers 105 + * should never set this flag. 106 + * @has_changed: Set when the current value differs from the new value. Drivers 107 + * should never use this flag. 108 + * @is_private: If set, then this control is private to its handler and it 109 + * will not be added to any other handlers. Drivers can set 110 + * this flag. 111 + * @is_auto: If set, then this control selects whether the other cluster 112 + * members are in 'automatic' mode or 'manual' mode. This is 113 + * used for autogain/gain type clusters. Drivers should never 114 + * set this flag directly. 115 + * @is_int: If set, then this control has a simple integer value (i.e. it 116 + * uses ctrl->val). 117 + * @is_string: If set, then this control has type V4L2_CTRL_TYPE_STRING. 118 + * @is_ptr: If set, then this control is an array and/or has type >= V4L2_CTRL_COMPOUND_TYPES 119 + * and/or has type V4L2_CTRL_TYPE_STRING. In other words, struct 120 + * v4l2_ext_control uses field p to point to the data. 121 + * @is_array: If set, then this control contains an N-dimensional array. 122 + * @has_volatiles: If set, then one or more members of the cluster are volatile. 123 + * Drivers should never touch this flag. 124 + * @call_notify: If set, then call the handler's notify function whenever the 125 + * control's value changes. 126 + * @manual_mode_value: If the is_auto flag is set, then this is the value 127 + * of the auto control that determines if that control is in 128 + * manual mode. So if the value of the auto control equals this 129 + * value, then the whole cluster is in manual mode. Drivers should 130 + * never set this flag directly. 131 + * @ops: The control ops. 132 + * @type_ops: The control type ops. 133 + * @id: The control ID. 134 + * @name: The control name. 135 + * @type: The control type. 136 + * @minimum: The control's minimum value. 137 + * @maximum: The control's maximum value. 138 + * @default_value: The control's default value. 139 + * @step: The control's step value for non-menu controls. 140 + * @elems: The number of elements in the N-dimensional array. 141 + * @elem_size: The size in bytes of the control. 142 + * @dims: The size of each dimension. 143 + * @nr_of_dims:The number of dimensions in @dims. 144 + * @menu_skip_mask: The control's skip mask for menu controls. This makes it 145 + * easy to skip menu items that are not valid. If bit X is set, 146 + * then menu item X is skipped. Of course, this only works for 147 + * menus with <= 32 menu items. There are no menus that come 148 + * close to that number, so this is OK. Should we ever need more, 149 + * then this will have to be extended to a u64 or a bit array. 150 + * @qmenu: A const char * array for all menu items. Array entries that are 151 + * empty strings ("") correspond to non-existing menu items (this 152 + * is in addition to the menu_skip_mask above). The last entry 153 + * must be NULL. 154 + * @flags: The control's flags. 155 + * @cur: The control's current value. 156 + * @val: The control's new s32 value. 157 + * @priv: The control's private pointer. For use by the driver. It is 158 + * untouched by the control framework. Note that this pointer is 159 + * not freed when the control is deleted. Should this be needed 160 + * then a new internal bitfield can be added to tell the framework 161 + * to free this pointer. 162 + * @p_cur: The control's current value represented via an union with 163 + * provides a standard way of accessing control types 164 + * through a pointer. 165 + * @p_new: The control's new value represented via an union with provides 166 + * a standard way of accessing control types 167 + * through a pointer. 168 + */ 168 169 struct v4l2_ctrl { 169 170 /* Administrative fields */ 170 171 struct list_head node; ··· 221 210 union v4l2_ctrl_ptr p_cur; 222 211 }; 223 212 224 - /** struct v4l2_ctrl_ref - The control reference. 225 - * @node: List node for the sorted list. 226 - * @next: Single-link list node for the hash. 227 - * @ctrl: The actual control information. 228 - * @helper: Pointer to helper struct. Used internally in prepare_ext_ctrls(). 229 - * 230 - * Each control handler has a list of these refs. The list_head is used to 231 - * keep a sorted-by-control-ID list of all controls, while the next pointer 232 - * is used to link the control in the hash's bucket. 233 - */ 213 + /** 214 + * struct v4l2_ctrl_ref - The control reference. 215 + * @node: List node for the sorted list. 216 + * @next: Single-link list node for the hash. 217 + * @ctrl: The actual control information. 218 + * @helper: Pointer to helper struct. Used internally in prepare_ext_ctrls(). 219 + * 220 + * Each control handler has a list of these refs. The list_head is used to 221 + * keep a sorted-by-control-ID list of all controls, while the next pointer 222 + * is used to link the control in the hash's bucket. 223 + */ 234 224 struct v4l2_ctrl_ref { 235 225 struct list_head node; 236 226 struct v4l2_ctrl_ref *next; ··· 239 227 struct v4l2_ctrl_helper *helper; 240 228 }; 241 229 242 - /** struct v4l2_ctrl_handler - The control handler keeps track of all the 243 - * controls: both the controls owned by the handler and those inherited 244 - * from other handlers. 245 - * @_lock: Default for "lock". 246 - * @lock: Lock to control access to this handler and its controls. 247 - * May be replaced by the user right after init. 248 - * @ctrls: The list of controls owned by this handler. 249 - * @ctrl_refs: The list of control references. 250 - * @cached: The last found control reference. It is common that the same 251 - * control is needed multiple times, so this is a simple 252 - * optimization. 253 - * @buckets: Buckets for the hashing. Allows for quick control lookup. 254 - * @notify: A notify callback that is called whenever the control changes value. 255 - * Note that the handler's lock is held when the notify function 256 - * is called! 257 - * @notify_priv: Passed as argument to the v4l2_ctrl notify callback. 258 - * @nr_of_buckets: Total number of buckets in the array. 259 - * @error: The error code of the first failed control addition. 260 - */ 230 + /** 231 + * struct v4l2_ctrl_handler - The control handler keeps track of all the 232 + * controls: both the controls owned by the handler and those inherited 233 + * from other handlers. 234 + * @_lock: Default for "lock". 235 + * @lock: Lock to control access to this handler and its controls. 236 + * May be replaced by the user right after init. 237 + * @ctrls: The list of controls owned by this handler. 238 + * @ctrl_refs: The list of control references. 239 + * @cached: The last found control reference. It is common that the same 240 + * control is needed multiple times, so this is a simple 241 + * optimization. 242 + * @buckets: Buckets for the hashing. Allows for quick control lookup. 243 + * @notify: A notify callback that is called whenever the control changes value. 244 + * Note that the handler's lock is held when the notify function 245 + * is called! 246 + * @notify_priv: Passed as argument to the v4l2_ctrl notify callback. 247 + * @nr_of_buckets: Total number of buckets in the array. 248 + * @error: The error code of the first failed control addition. 249 + */ 261 250 struct v4l2_ctrl_handler { 262 251 struct mutex _lock; 263 252 struct mutex *lock; ··· 272 259 int error; 273 260 }; 274 261 275 - /** struct v4l2_ctrl_config - Control configuration structure. 276 - * @ops: The control ops. 277 - * @type_ops: The control type ops. Only needed for compound controls. 278 - * @id: The control ID. 279 - * @name: The control name. 280 - * @type: The control type. 281 - * @min: The control's minimum value. 282 - * @max: The control's maximum value. 283 - * @step: The control's step value for non-menu controls. 284 - * @def: The control's default value. 285 - * @dims: The size of each dimension. 286 - * @elem_size: The size in bytes of the control. 287 - * @flags: The control's flags. 288 - * @menu_skip_mask: The control's skip mask for menu controls. This makes it 289 - * easy to skip menu items that are not valid. If bit X is set, 290 - * then menu item X is skipped. Of course, this only works for 291 - * menus with <= 64 menu items. There are no menus that come 292 - * close to that number, so this is OK. Should we ever need more, 293 - * then this will have to be extended to a bit array. 294 - * @qmenu: A const char * array for all menu items. Array entries that are 295 - * empty strings ("") correspond to non-existing menu items (this 296 - * is in addition to the menu_skip_mask above). The last entry 297 - * must be NULL. 298 - * @is_private: If set, then this control is private to its handler and it 299 - * will not be added to any other handlers. 300 - */ 262 + /** 263 + * struct v4l2_ctrl_config - Control configuration structure. 264 + * @ops: The control ops. 265 + * @type_ops: The control type ops. Only needed for compound controls. 266 + * @id: The control ID. 267 + * @name: The control name. 268 + * @type: The control type. 269 + * @min: The control's minimum value. 270 + * @max: The control's maximum value. 271 + * @step: The control's step value for non-menu controls. 272 + * @def: The control's default value. 273 + * @dims: The size of each dimension. 274 + * @elem_size: The size in bytes of the control. 275 + * @flags: The control's flags. 276 + * @menu_skip_mask: The control's skip mask for menu controls. This makes it 277 + * easy to skip menu items that are not valid. If bit X is set, 278 + * then menu item X is skipped. Of course, this only works for 279 + * menus with <= 64 menu items. There are no menus that come 280 + * close to that number, so this is OK. Should we ever need more, 281 + * then this will have to be extended to a bit array. 282 + * @qmenu: A const char * array for all menu items. Array entries that are 283 + * empty strings ("") correspond to non-existing menu items (this 284 + * is in addition to the menu_skip_mask above). The last entry 285 + * must be NULL. 286 + * @qmenu_int: A const s64 integer array for all menu items of the type 287 + * V4L2_CTRL_TYPE_INTEGER_MENU. 288 + * @is_private: If set, then this control is private to its handler and it 289 + * will not be added to any other handlers. 290 + */ 301 291 struct v4l2_ctrl_config { 302 292 const struct v4l2_ctrl_ops *ops; 303 293 const struct v4l2_ctrl_type_ops *type_ops; ··· 320 304 unsigned int is_private:1; 321 305 }; 322 306 323 - /** v4l2_ctrl_fill() - Fill in the control fields based on the control ID. 324 - * 325 - * This works for all standard V4L2 controls. 326 - * For non-standard controls it will only fill in the given arguments 327 - * and @name will be NULL. 328 - * 329 - * This function will overwrite the contents of @name, @type and @flags. 330 - * The contents of @min, @max, @step and @def may be modified depending on 331 - * the type. 332 - * 333 - * Do not use in drivers! It is used internally for backwards compatibility 334 - * control handling only. Once all drivers are converted to use the new 335 - * control framework this function will no longer be exported. 336 - */ 307 + /* 308 + * v4l2_ctrl_fill() - Fill in the control fields based on the control ID. 309 + * 310 + * This works for all standard V4L2 controls. 311 + * For non-standard controls it will only fill in the given arguments 312 + * and @name will be NULL. 313 + * 314 + * This function will overwrite the contents of @name, @type and @flags. 315 + * The contents of @min, @max, @step and @def may be modified depending on 316 + * the type. 317 + * 318 + * Do not use in drivers! It is used internally for backwards compatibility 319 + * control handling only. Once all drivers are converted to use the new 320 + * control framework this function will no longer be exported. 321 + */ 337 322 void v4l2_ctrl_fill(u32 id, const char **name, enum v4l2_ctrl_type *type, 338 323 s64 *min, s64 *max, u64 *step, s64 *def, u32 *flags); 339 324 340 325 341 - /** v4l2_ctrl_handler_init_class() - Initialize the control handler. 342 - * @hdl: The control handler. 343 - * @nr_of_controls_hint: A hint of how many controls this handler is 344 - * expected to refer to. This is the total number, so including 345 - * any inherited controls. It doesn't have to be precise, but if 346 - * it is way off, then you either waste memory (too many buckets 347 - * are allocated) or the control lookup becomes slower (not enough 348 - * buckets are allocated, so there are more slow list lookups). 349 - * It will always work, though. 350 - * @key: Used by the lock validator if CONFIG_LOCKDEP is set. 351 - * @name: Used by the lock validator if CONFIG_LOCKDEP is set. 352 - * 353 - * Returns an error if the buckets could not be allocated. This error will 354 - * also be stored in @hdl->error. 355 - * 356 - * Never use this call directly, always use the v4l2_ctrl_handler_init 357 - * macro that hides the @key and @name arguments. 358 - */ 326 + /** 327 + * v4l2_ctrl_handler_init_class() - Initialize the control handler. 328 + * @hdl: The control handler. 329 + * @nr_of_controls_hint: A hint of how many controls this handler is 330 + * expected to refer to. This is the total number, so including 331 + * any inherited controls. It doesn't have to be precise, but if 332 + * it is way off, then you either waste memory (too many buckets 333 + * are allocated) or the control lookup becomes slower (not enough 334 + * buckets are allocated, so there are more slow list lookups). 335 + * It will always work, though. 336 + * @key: Used by the lock validator if CONFIG_LOCKDEP is set. 337 + * @name: Used by the lock validator if CONFIG_LOCKDEP is set. 338 + * 339 + * Returns an error if the buckets could not be allocated. This error will 340 + * also be stored in @hdl->error. 341 + * 342 + * Never use this call directly, always use the v4l2_ctrl_handler_init 343 + * macro that hides the @key and @name arguments. 344 + */ 359 345 int v4l2_ctrl_handler_init_class(struct v4l2_ctrl_handler *hdl, 360 346 unsigned nr_of_controls_hint, 361 347 struct lock_class_key *key, const char *name); ··· 379 361 v4l2_ctrl_handler_init_class(hdl, nr_of_controls_hint, NULL, NULL) 380 362 #endif 381 363 382 - /** v4l2_ctrl_handler_free() - Free all controls owned by the handler and free 383 - * the control list. 384 - * @hdl: The control handler. 385 - * 386 - * Does nothing if @hdl == NULL. 387 - */ 364 + /** 365 + * v4l2_ctrl_handler_free() - Free all controls owned by the handler and free 366 + * the control list. 367 + * @hdl: The control handler. 368 + * 369 + * Does nothing if @hdl == NULL. 370 + */ 388 371 void v4l2_ctrl_handler_free(struct v4l2_ctrl_handler *hdl); 389 372 390 - /** v4l2_ctrl_lock() - Helper function to lock the handler 391 - * associated with the control. 392 - * @ctrl: The control to lock. 393 - */ 373 + /** 374 + * v4l2_ctrl_lock() - Helper function to lock the handler 375 + * associated with the control. 376 + * @ctrl: The control to lock. 377 + */ 394 378 static inline void v4l2_ctrl_lock(struct v4l2_ctrl *ctrl) 395 379 { 396 380 mutex_lock(ctrl->handler->lock); 397 381 } 398 382 399 - /** v4l2_ctrl_unlock() - Helper function to unlock the handler 400 - * associated with the control. 401 - * @ctrl: The control to unlock. 402 - */ 383 + /** 384 + * v4l2_ctrl_unlock() - Helper function to unlock the handler 385 + * associated with the control. 386 + * @ctrl: The control to unlock. 387 + */ 403 388 static inline void v4l2_ctrl_unlock(struct v4l2_ctrl *ctrl) 404 389 { 405 390 mutex_unlock(ctrl->handler->lock); 406 391 } 407 392 408 - /** v4l2_ctrl_handler_setup() - Call the s_ctrl op for all controls belonging 409 - * to the handler to initialize the hardware to the current control values. 410 - * @hdl: The control handler. 411 - * 412 - * Button controls will be skipped, as are read-only controls. 413 - * 414 - * If @hdl == NULL, then this just returns 0. 415 - */ 393 + /** 394 + * v4l2_ctrl_handler_setup() - Call the s_ctrl op for all controls belonging 395 + * to the handler to initialize the hardware to the current control values. 396 + * @hdl: The control handler. 397 + * 398 + * Button controls will be skipped, as are read-only controls. 399 + * 400 + * If @hdl == NULL, then this just returns 0. 401 + */ 416 402 int v4l2_ctrl_handler_setup(struct v4l2_ctrl_handler *hdl); 417 403 418 - /** v4l2_ctrl_handler_log_status() - Log all controls owned by the handler. 419 - * @hdl: The control handler. 420 - * @prefix: The prefix to use when logging the control values. If the 421 - * prefix does not end with a space, then ": " will be added 422 - * after the prefix. If @prefix == NULL, then no prefix will be 423 - * used. 424 - * 425 - * For use with VIDIOC_LOG_STATUS. 426 - * 427 - * Does nothing if @hdl == NULL. 428 - */ 404 + /** 405 + * v4l2_ctrl_handler_log_status() - Log all controls owned by the handler. 406 + * @hdl: The control handler. 407 + * @prefix: The prefix to use when logging the control values. If the 408 + * prefix does not end with a space, then ": " will be added 409 + * after the prefix. If @prefix == NULL, then no prefix will be 410 + * used. 411 + * 412 + * For use with VIDIOC_LOG_STATUS. 413 + * 414 + * Does nothing if @hdl == NULL. 415 + */ 429 416 void v4l2_ctrl_handler_log_status(struct v4l2_ctrl_handler *hdl, 430 417 const char *prefix); 431 418 432 - /** v4l2_ctrl_new_custom() - Allocate and initialize a new custom V4L2 433 - * control. 434 - * @hdl: The control handler. 435 - * @cfg: The control's configuration data. 436 - * @priv: The control's driver-specific private data. 437 - * 438 - * If the &v4l2_ctrl struct could not be allocated then NULL is returned 439 - * and @hdl->error is set to the error code (if it wasn't set already). 440 - */ 419 + /** 420 + * v4l2_ctrl_new_custom() - Allocate and initialize a new custom V4L2 421 + * control. 422 + * @hdl: The control handler. 423 + * @cfg: The control's configuration data. 424 + * @priv: The control's driver-specific private data. 425 + * 426 + * If the &v4l2_ctrl struct could not be allocated then NULL is returned 427 + * and @hdl->error is set to the error code (if it wasn't set already). 428 + */ 441 429 struct v4l2_ctrl *v4l2_ctrl_new_custom(struct v4l2_ctrl_handler *hdl, 442 430 const struct v4l2_ctrl_config *cfg, void *priv); 443 431 444 - /** v4l2_ctrl_new_std() - Allocate and initialize a new standard V4L2 non-menu control. 445 - * @hdl: The control handler. 446 - * @ops: The control ops. 447 - * @id: The control ID. 448 - * @min: The control's minimum value. 449 - * @max: The control's maximum value. 450 - * @step: The control's step value 451 - * @def: The control's default value. 452 - * 453 - * If the &v4l2_ctrl struct could not be allocated, or the control 454 - * ID is not known, then NULL is returned and @hdl->error is set to the 455 - * appropriate error code (if it wasn't set already). 456 - * 457 - * If @id refers to a menu control, then this function will return NULL. 458 - * 459 - * Use v4l2_ctrl_new_std_menu() when adding menu controls. 460 - */ 432 + /** 433 + * v4l2_ctrl_new_std() - Allocate and initialize a new standard V4L2 non-menu control. 434 + * @hdl: The control handler. 435 + * @ops: The control ops. 436 + * @id: The control ID. 437 + * @min: The control's minimum value. 438 + * @max: The control's maximum value. 439 + * @step: The control's step value 440 + * @def: The control's default value. 441 + * 442 + * If the &v4l2_ctrl struct could not be allocated, or the control 443 + * ID is not known, then NULL is returned and @hdl->error is set to the 444 + * appropriate error code (if it wasn't set already). 445 + * 446 + * If @id refers to a menu control, then this function will return NULL. 447 + * 448 + * Use v4l2_ctrl_new_std_menu() when adding menu controls. 449 + */ 461 450 struct v4l2_ctrl *v4l2_ctrl_new_std(struct v4l2_ctrl_handler *hdl, 462 451 const struct v4l2_ctrl_ops *ops, 463 452 u32 id, s64 min, s64 max, u64 step, s64 def); 464 453 465 - /** v4l2_ctrl_new_std_menu() - Allocate and initialize a new standard V4L2 menu control. 466 - * @hdl: The control handler. 467 - * @ops: The control ops. 468 - * @id: The control ID. 469 - * @max: The control's maximum value. 470 - * @mask: The control's skip mask for menu controls. This makes it 471 - * easy to skip menu items that are not valid. If bit X is set, 472 - * then menu item X is skipped. Of course, this only works for 473 - * menus with <= 64 menu items. There are no menus that come 474 - * close to that number, so this is OK. Should we ever need more, 475 - * then this will have to be extended to a bit array. 476 - * @def: The control's default value. 477 - * 478 - * Same as v4l2_ctrl_new_std(), but @min is set to 0 and the @mask value 479 - * determines which menu items are to be skipped. 480 - * 481 - * If @id refers to a non-menu control, then this function will return NULL. 482 - */ 454 + /** 455 + * v4l2_ctrl_new_std_menu() - Allocate and initialize a new standard V4L2 menu control. 456 + * @hdl: The control handler. 457 + * @ops: The control ops. 458 + * @id: The control ID. 459 + * @max: The control's maximum value. 460 + * @mask: The control's skip mask for menu controls. This makes it 461 + * easy to skip menu items that are not valid. If bit X is set, 462 + * then menu item X is skipped. Of course, this only works for 463 + * menus with <= 64 menu items. There are no menus that come 464 + * close to that number, so this is OK. Should we ever need more, 465 + * then this will have to be extended to a bit array. 466 + * @def: The control's default value. 467 + * 468 + * Same as v4l2_ctrl_new_std(), but @min is set to 0 and the @mask value 469 + * determines which menu items are to be skipped. 470 + * 471 + * If @id refers to a non-menu control, then this function will return NULL. 472 + */ 483 473 struct v4l2_ctrl *v4l2_ctrl_new_std_menu(struct v4l2_ctrl_handler *hdl, 484 474 const struct v4l2_ctrl_ops *ops, 485 475 u32 id, u8 max, u64 mask, u8 def); 486 476 487 - /** v4l2_ctrl_new_std_menu_items() - Create a new standard V4L2 menu control 488 - * with driver specific menu. 489 - * @hdl: The control handler. 490 - * @ops: The control ops. 491 - * @id: The control ID. 492 - * @max: The control's maximum value. 493 - * @mask: The control's skip mask for menu controls. This makes it 494 - * easy to skip menu items that are not valid. If bit X is set, 495 - * then menu item X is skipped. Of course, this only works for 496 - * menus with <= 64 menu items. There are no menus that come 497 - * close to that number, so this is OK. Should we ever need more, 498 - * then this will have to be extended to a bit array. 499 - * @def: The control's default value. 500 - * @qmenu: The new menu. 501 - * 502 - * Same as v4l2_ctrl_new_std_menu(), but @qmenu will be the driver specific 503 - * menu of this control. 504 - * 505 - */ 477 + /** 478 + * v4l2_ctrl_new_std_menu_items() - Create a new standard V4L2 menu control 479 + * with driver specific menu. 480 + * @hdl: The control handler. 481 + * @ops: The control ops. 482 + * @id: The control ID. 483 + * @max: The control's maximum value. 484 + * @mask: The control's skip mask for menu controls. This makes it 485 + * easy to skip menu items that are not valid. If bit X is set, 486 + * then menu item X is skipped. Of course, this only works for 487 + * menus with <= 64 menu items. There are no menus that come 488 + * close to that number, so this is OK. Should we ever need more, 489 + * then this will have to be extended to a bit array. 490 + * @def: The control's default value. 491 + * @qmenu: The new menu. 492 + * 493 + * Same as v4l2_ctrl_new_std_menu(), but @qmenu will be the driver specific 494 + * menu of this control. 495 + * 496 + */ 506 497 struct v4l2_ctrl *v4l2_ctrl_new_std_menu_items(struct v4l2_ctrl_handler *hdl, 507 498 const struct v4l2_ctrl_ops *ops, u32 id, u8 max, 508 499 u64 mask, u8 def, const char * const *qmenu); 509 500 510 - /** v4l2_ctrl_new_int_menu() - Create a new standard V4L2 integer menu control. 511 - * @hdl: The control handler. 512 - * @ops: The control ops. 513 - * @id: The control ID. 514 - * @max: The control's maximum value. 515 - * @def: The control's default value. 516 - * @qmenu_int: The control's menu entries. 517 - * 518 - * Same as v4l2_ctrl_new_std_menu(), but @mask is set to 0 and it additionaly 519 - * takes as an argument an array of integers determining the menu items. 520 - * 521 - * If @id refers to a non-integer-menu control, then this function will return NULL. 522 - */ 501 + /** 502 + * v4l2_ctrl_new_int_menu() - Create a new standard V4L2 integer menu control. 503 + * @hdl: The control handler. 504 + * @ops: The control ops. 505 + * @id: The control ID. 506 + * @max: The control's maximum value. 507 + * @def: The control's default value. 508 + * @qmenu_int: The control's menu entries. 509 + * 510 + * Same as v4l2_ctrl_new_std_menu(), but @mask is set to 0 and it additionaly 511 + * takes as an argument an array of integers determining the menu items. 512 + * 513 + * If @id refers to a non-integer-menu control, then this function will return NULL. 514 + */ 523 515 struct v4l2_ctrl *v4l2_ctrl_new_int_menu(struct v4l2_ctrl_handler *hdl, 524 516 const struct v4l2_ctrl_ops *ops, 525 517 u32 id, u8 max, u8 def, const s64 *qmenu_int); 526 518 527 - /** v4l2_ctrl_add_ctrl() - Add a control from another handler to this handler. 528 - * @hdl: The control handler. 529 - * @ctrl: The control to add. 530 - * 531 - * It will return NULL if it was unable to add the control reference. 532 - * If the control already belonged to the handler, then it will do 533 - * nothing and just return @ctrl. 534 - */ 519 + /** 520 + * v4l2_ctrl_add_ctrl() - Add a control from another handler to this handler. 521 + * @hdl: The control handler. 522 + * @ctrl: The control to add. 523 + * 524 + * It will return NULL if it was unable to add the control reference. 525 + * If the control already belonged to the handler, then it will do 526 + * nothing and just return @ctrl. 527 + */ 535 528 struct v4l2_ctrl *v4l2_ctrl_add_ctrl(struct v4l2_ctrl_handler *hdl, 536 529 struct v4l2_ctrl *ctrl); 537 530 538 - /** v4l2_ctrl_add_handler() - Add all controls from handler @add to 539 - * handler @hdl. 540 - * @hdl: The control handler. 541 - * @add: The control handler whose controls you want to add to 542 - * the @hdl control handler. 543 - * @filter: This function will filter which controls should be added. 544 - * 545 - * Does nothing if either of the two handlers is a NULL pointer. 546 - * If @filter is NULL, then all controls are added. Otherwise only those 547 - * controls for which @filter returns true will be added. 548 - * In case of an error @hdl->error will be set to the error code (if it 549 - * wasn't set already). 550 - */ 531 + /** 532 + * v4l2_ctrl_add_handler() - Add all controls from handler @add to 533 + * handler @hdl. 534 + * @hdl: The control handler. 535 + * @add: The control handler whose controls you want to add to 536 + * the @hdl control handler. 537 + * @filter: This function will filter which controls should be added. 538 + * 539 + * Does nothing if either of the two handlers is a NULL pointer. 540 + * If @filter is NULL, then all controls are added. Otherwise only those 541 + * controls for which @filter returns true will be added. 542 + * In case of an error @hdl->error will be set to the error code (if it 543 + * wasn't set already). 544 + */ 551 545 int v4l2_ctrl_add_handler(struct v4l2_ctrl_handler *hdl, 552 546 struct v4l2_ctrl_handler *add, 553 547 bool (*filter)(const struct v4l2_ctrl *ctrl)); 554 548 555 - /** v4l2_ctrl_radio_filter() - Standard filter for radio controls. 556 - * @ctrl: The control that is filtered. 557 - * 558 - * This will return true for any controls that are valid for radio device 559 - * nodes. Those are all of the V4L2_CID_AUDIO_* user controls and all FM 560 - * transmitter class controls. 561 - * 562 - * This function is to be used with v4l2_ctrl_add_handler(). 563 - */ 549 + /** 550 + * v4l2_ctrl_radio_filter() - Standard filter for radio controls. 551 + * @ctrl: The control that is filtered. 552 + * 553 + * This will return true for any controls that are valid for radio device 554 + * nodes. Those are all of the V4L2_CID_AUDIO_* user controls and all FM 555 + * transmitter class controls. 556 + * 557 + * This function is to be used with v4l2_ctrl_add_handler(). 558 + */ 564 559 bool v4l2_ctrl_radio_filter(const struct v4l2_ctrl *ctrl); 565 560 566 - /** v4l2_ctrl_cluster() - Mark all controls in the cluster as belonging to that cluster. 567 - * @ncontrols: The number of controls in this cluster. 568 - * @controls: The cluster control array of size @ncontrols. 569 - */ 561 + /** 562 + * v4l2_ctrl_cluster() - Mark all controls in the cluster as belonging to that cluster. 563 + * @ncontrols: The number of controls in this cluster. 564 + * @controls: The cluster control array of size @ncontrols. 565 + */ 570 566 void v4l2_ctrl_cluster(unsigned ncontrols, struct v4l2_ctrl **controls); 571 567 572 568 573 - /** v4l2_ctrl_auto_cluster() - Mark all controls in the cluster as belonging to 574 - * that cluster and set it up for autofoo/foo-type handling. 575 - * @ncontrols: The number of controls in this cluster. 576 - * @controls: The cluster control array of size @ncontrols. The first control 577 - * must be the 'auto' control (e.g. autogain, autoexposure, etc.) 578 - * @manual_val: The value for the first control in the cluster that equals the 579 - * manual setting. 580 - * @set_volatile: If true, then all controls except the first auto control will 581 - * be volatile. 582 - * 583 - * Use for control groups where one control selects some automatic feature and 584 - * the other controls are only active whenever the automatic feature is turned 585 - * off (manual mode). Typical examples: autogain vs gain, auto-whitebalance vs 586 - * red and blue balance, etc. 587 - * 588 - * The behavior of such controls is as follows: 589 - * 590 - * When the autofoo control is set to automatic, then any manual controls 591 - * are set to inactive and any reads will call g_volatile_ctrl (if the control 592 - * was marked volatile). 593 - * 594 - * When the autofoo control is set to manual, then any manual controls will 595 - * be marked active, and any reads will just return the current value without 596 - * going through g_volatile_ctrl. 597 - * 598 - * In addition, this function will set the V4L2_CTRL_FLAG_UPDATE flag 599 - * on the autofoo control and V4L2_CTRL_FLAG_INACTIVE on the foo control(s) 600 - * if autofoo is in auto mode. 601 - */ 569 + /** 570 + * v4l2_ctrl_auto_cluster() - Mark all controls in the cluster as belonging to 571 + * that cluster and set it up for autofoo/foo-type handling. 572 + * @ncontrols: The number of controls in this cluster. 573 + * @controls: The cluster control array of size @ncontrols. The first control 574 + * must be the 'auto' control (e.g. autogain, autoexposure, etc.) 575 + * @manual_val: The value for the first control in the cluster that equals the 576 + * manual setting. 577 + * @set_volatile: If true, then all controls except the first auto control will 578 + * be volatile. 579 + * 580 + * Use for control groups where one control selects some automatic feature and 581 + * the other controls are only active whenever the automatic feature is turned 582 + * off (manual mode). Typical examples: autogain vs gain, auto-whitebalance vs 583 + * red and blue balance, etc. 584 + * 585 + * The behavior of such controls is as follows: 586 + * 587 + * When the autofoo control is set to automatic, then any manual controls 588 + * are set to inactive and any reads will call g_volatile_ctrl (if the control 589 + * was marked volatile). 590 + * 591 + * When the autofoo control is set to manual, then any manual controls will 592 + * be marked active, and any reads will just return the current value without 593 + * going through g_volatile_ctrl. 594 + * 595 + * In addition, this function will set the V4L2_CTRL_FLAG_UPDATE flag 596 + * on the autofoo control and V4L2_CTRL_FLAG_INACTIVE on the foo control(s) 597 + * if autofoo is in auto mode. 598 + */ 602 599 void v4l2_ctrl_auto_cluster(unsigned ncontrols, struct v4l2_ctrl **controls, 603 600 u8 manual_val, bool set_volatile); 604 601 605 602 606 - /** v4l2_ctrl_find() - Find a control with the given ID. 607 - * @hdl: The control handler. 608 - * @id: The control ID to find. 609 - * 610 - * If @hdl == NULL this will return NULL as well. Will lock the handler so 611 - * do not use from inside &v4l2_ctrl_ops. 612 - */ 603 + /** 604 + * v4l2_ctrl_find() - Find a control with the given ID. 605 + * @hdl: The control handler. 606 + * @id: The control ID to find. 607 + * 608 + * If @hdl == NULL this will return NULL as well. Will lock the handler so 609 + * do not use from inside &v4l2_ctrl_ops. 610 + */ 613 611 struct v4l2_ctrl *v4l2_ctrl_find(struct v4l2_ctrl_handler *hdl, u32 id); 614 612 615 - /** v4l2_ctrl_activate() - Make the control active or inactive. 616 - * @ctrl: The control to (de)activate. 617 - * @active: True if the control should become active. 618 - * 619 - * This sets or clears the V4L2_CTRL_FLAG_INACTIVE flag atomically. 620 - * Does nothing if @ctrl == NULL. 621 - * This will usually be called from within the s_ctrl op. 622 - * The V4L2_EVENT_CTRL event will be generated afterwards. 623 - * 624 - * This function assumes that the control handler is locked. 625 - */ 613 + /** 614 + * v4l2_ctrl_activate() - Make the control active or inactive. 615 + * @ctrl: The control to (de)activate. 616 + * @active: True if the control should become active. 617 + * 618 + * This sets or clears the V4L2_CTRL_FLAG_INACTIVE flag atomically. 619 + * Does nothing if @ctrl == NULL. 620 + * This will usually be called from within the s_ctrl op. 621 + * The V4L2_EVENT_CTRL event will be generated afterwards. 622 + * 623 + * This function assumes that the control handler is locked. 624 + */ 626 625 void v4l2_ctrl_activate(struct v4l2_ctrl *ctrl, bool active); 627 626 628 - /** v4l2_ctrl_grab() - Mark the control as grabbed or not grabbed. 629 - * @ctrl: The control to (de)activate. 630 - * @grabbed: True if the control should become grabbed. 631 - * 632 - * This sets or clears the V4L2_CTRL_FLAG_GRABBED flag atomically. 633 - * Does nothing if @ctrl == NULL. 634 - * The V4L2_EVENT_CTRL event will be generated afterwards. 635 - * This will usually be called when starting or stopping streaming in the 636 - * driver. 637 - * 638 - * This function assumes that the control handler is not locked and will 639 - * take the lock itself. 640 - */ 627 + /** 628 + * v4l2_ctrl_grab() - Mark the control as grabbed or not grabbed. 629 + * @ctrl: The control to (de)activate. 630 + * @grabbed: True if the control should become grabbed. 631 + * 632 + * This sets or clears the V4L2_CTRL_FLAG_GRABBED flag atomically. 633 + * Does nothing if @ctrl == NULL. 634 + * The V4L2_EVENT_CTRL event will be generated afterwards. 635 + * This will usually be called when starting or stopping streaming in the 636 + * driver. 637 + * 638 + * This function assumes that the control handler is not locked and will 639 + * take the lock itself. 640 + */ 641 641 void v4l2_ctrl_grab(struct v4l2_ctrl *ctrl, bool grabbed); 642 642 643 643 644 - /** __v4l2_ctrl_modify_range() - Unlocked variant of v4l2_ctrl_modify_range() */ 644 + /** 645 + *__v4l2_ctrl_modify_range() - Unlocked variant of v4l2_ctrl_modify_range() 646 + * 647 + * @ctrl: The control to update. 648 + * @min: The control's minimum value. 649 + * @max: The control's maximum value. 650 + * @step: The control's step value 651 + * @def: The control's default value. 652 + * 653 + * Update the range of a control on the fly. This works for control types 654 + * INTEGER, BOOLEAN, MENU, INTEGER MENU and BITMASK. For menu controls the 655 + * @step value is interpreted as a menu_skip_mask. 656 + * 657 + * An error is returned if one of the range arguments is invalid for this 658 + * control type. 659 + * 660 + * This function assumes that the control handler is not locked and will 661 + * take the lock itself. 662 + */ 645 663 int __v4l2_ctrl_modify_range(struct v4l2_ctrl *ctrl, 646 664 s64 min, s64 max, u64 step, s64 def); 647 665 648 - /** v4l2_ctrl_modify_range() - Update the range of a control. 649 - * @ctrl: The control to update. 650 - * @min: The control's minimum value. 651 - * @max: The control's maximum value. 652 - * @step: The control's step value 653 - * @def: The control's default value. 654 - * 655 - * Update the range of a control on the fly. This works for control types 656 - * INTEGER, BOOLEAN, MENU, INTEGER MENU and BITMASK. For menu controls the 657 - * @step value is interpreted as a menu_skip_mask. 658 - * 659 - * An error is returned if one of the range arguments is invalid for this 660 - * control type. 661 - * 662 - * This function assumes that the control handler is not locked and will 663 - * take the lock itself. 664 - */ 666 + /** 667 + * v4l2_ctrl_modify_range() - Update the range of a control. 668 + * @ctrl: The control to update. 669 + * @min: The control's minimum value. 670 + * @max: The control's maximum value. 671 + * @step: The control's step value 672 + * @def: The control's default value. 673 + * 674 + * Update the range of a control on the fly. This works for control types 675 + * INTEGER, BOOLEAN, MENU, INTEGER MENU and BITMASK. For menu controls the 676 + * @step value is interpreted as a menu_skip_mask. 677 + * 678 + * An error is returned if one of the range arguments is invalid for this 679 + * control type. 680 + * 681 + * This function assumes that the control handler is not locked and will 682 + * take the lock itself. 683 + */ 665 684 static inline int v4l2_ctrl_modify_range(struct v4l2_ctrl *ctrl, 666 685 s64 min, s64 max, u64 step, s64 def) 667 686 { ··· 711 656 return rval; 712 657 } 713 658 714 - /** v4l2_ctrl_notify() - Function to set a notify callback for a control. 715 - * @ctrl: The control. 716 - * @notify: The callback function. 717 - * @priv: The callback private handle, passed as argument to the callback. 718 - * 719 - * This function sets a callback function for the control. If @ctrl is NULL, 720 - * then it will do nothing. If @notify is NULL, then the notify callback will 721 - * be removed. 722 - * 723 - * There can be only one notify. If another already exists, then a WARN_ON 724 - * will be issued and the function will do nothing. 725 - */ 659 + /** 660 + * v4l2_ctrl_notify() - Function to set a notify callback for a control. 661 + * @ctrl: The control. 662 + * @notify: The callback function. 663 + * @priv: The callback private handle, passed as argument to the callback. 664 + * 665 + * This function sets a callback function for the control. If @ctrl is NULL, 666 + * then it will do nothing. If @notify is NULL, then the notify callback will 667 + * be removed. 668 + * 669 + * There can be only one notify. If another already exists, then a WARN_ON 670 + * will be issued and the function will do nothing. 671 + */ 726 672 void v4l2_ctrl_notify(struct v4l2_ctrl *ctrl, v4l2_ctrl_notify_fnc notify, void *priv); 727 673 728 - /** v4l2_ctrl_get_name() - Get the name of the control 674 + /** 675 + * v4l2_ctrl_get_name() - Get the name of the control 729 676 * @id: The control ID. 730 677 * 731 678 * This function returns the name of the given control ID or NULL if it isn't ··· 735 678 */ 736 679 const char *v4l2_ctrl_get_name(u32 id); 737 680 738 - /** v4l2_ctrl_get_menu() - Get the menu string array of the control 681 + /** 682 + * v4l2_ctrl_get_menu() - Get the menu string array of the control 739 683 * @id: The control ID. 740 684 * 741 685 * This function returns the NULL-terminated menu string array name of the ··· 744 686 */ 745 687 const char * const *v4l2_ctrl_get_menu(u32 id); 746 688 747 - /** v4l2_ctrl_get_int_menu() - Get the integer menu array of the control 689 + /** 690 + * v4l2_ctrl_get_int_menu() - Get the integer menu array of the control 748 691 * @id: The control ID. 749 692 * @len: The size of the integer array. 750 693 * ··· 754 695 */ 755 696 const s64 *v4l2_ctrl_get_int_menu(u32 id, u32 *len); 756 697 757 - /** v4l2_ctrl_g_ctrl() - Helper function to get the control's value from within a driver. 758 - * @ctrl: The control. 759 - * 760 - * This returns the control's value safely by going through the control 761 - * framework. This function will lock the control's handler, so it cannot be 762 - * used from within the &v4l2_ctrl_ops functions. 763 - * 764 - * This function is for integer type controls only. 765 - */ 698 + /** 699 + * v4l2_ctrl_g_ctrl() - Helper function to get the control's value from within a driver. 700 + * @ctrl: The control. 701 + * 702 + * This returns the control's value safely by going through the control 703 + * framework. This function will lock the control's handler, so it cannot be 704 + * used from within the &v4l2_ctrl_ops functions. 705 + * 706 + * This function is for integer type controls only. 707 + */ 766 708 s32 v4l2_ctrl_g_ctrl(struct v4l2_ctrl *ctrl); 767 709 768 - /** __v4l2_ctrl_s_ctrl() - Unlocked variant of v4l2_ctrl_s_ctrl(). */ 710 + /** 711 + * __v4l2_ctrl_s_ctrl() - Unlocked variant of v4l2_ctrl_s_ctrl(). 712 + * @ctrl: The control. 713 + * @val: The new value. 714 + * 715 + * This set the control's new value safely by going through the control 716 + * framework. This function will lock the control's handler, so it cannot be 717 + * used from within the &v4l2_ctrl_ops functions. 718 + * 719 + * This function is for integer type controls only. 720 + */ 769 721 int __v4l2_ctrl_s_ctrl(struct v4l2_ctrl *ctrl, s32 val); 722 + 770 723 /** v4l2_ctrl_s_ctrl() - Helper function to set the control's value from within a driver. 771 - * @ctrl: The control. 772 - * @val: The new value. 773 - * 774 - * This set the control's new value safely by going through the control 775 - * framework. This function will lock the control's handler, so it cannot be 776 - * used from within the &v4l2_ctrl_ops functions. 777 - * 778 - * This function is for integer type controls only. 779 - */ 724 + * @ctrl: The control. 725 + * @val: The new value. 726 + * 727 + * This set the control's new value safely by going through the control 728 + * framework. This function will lock the control's handler, so it cannot be 729 + * used from within the &v4l2_ctrl_ops functions. 730 + * 731 + * This function is for integer type controls only. 732 + */ 780 733 static inline int v4l2_ctrl_s_ctrl(struct v4l2_ctrl *ctrl, s32 val) 781 734 { 782 735 int rval; ··· 800 729 return rval; 801 730 } 802 731 803 - /** v4l2_ctrl_g_ctrl_int64() - Helper function to get a 64-bit control's value from within a driver. 804 - * @ctrl: The control. 805 - * 806 - * This returns the control's value safely by going through the control 807 - * framework. This function will lock the control's handler, so it cannot be 808 - * used from within the &v4l2_ctrl_ops functions. 809 - * 810 - * This function is for 64-bit integer type controls only. 811 - */ 732 + /** 733 + * v4l2_ctrl_g_ctrl_int64() - Helper function to get a 64-bit control's value 734 + * from within a driver. 735 + * @ctrl: The control. 736 + * 737 + * This returns the control's value safely by going through the control 738 + * framework. This function will lock the control's handler, so it cannot be 739 + * used from within the &v4l2_ctrl_ops functions. 740 + * 741 + * This function is for 64-bit integer type controls only. 742 + */ 812 743 s64 v4l2_ctrl_g_ctrl_int64(struct v4l2_ctrl *ctrl); 813 744 814 - /** __v4l2_ctrl_s_ctrl_int64() - Unlocked variant of v4l2_ctrl_s_ctrl_int64(). */ 745 + /** 746 + * __v4l2_ctrl_s_ctrl_int64() - Unlocked variant of v4l2_ctrl_s_ctrl_int64(). 747 + * 748 + * @ctrl: The control. 749 + * @val: The new value. 750 + * 751 + * This set the control's new value safely by going through the control 752 + * framework. This function will lock the control's handler, so it cannot be 753 + * used from within the &v4l2_ctrl_ops functions. 754 + * 755 + * This function is for 64-bit integer type controls only. 756 + */ 815 757 int __v4l2_ctrl_s_ctrl_int64(struct v4l2_ctrl *ctrl, s64 val); 816 758 817 - /** v4l2_ctrl_s_ctrl_int64() - Helper function to set a 64-bit control's value from within a driver. 818 - * @ctrl: The control. 819 - * @val: The new value. 820 - * 821 - * This set the control's new value safely by going through the control 822 - * framework. This function will lock the control's handler, so it cannot be 823 - * used from within the &v4l2_ctrl_ops functions. 824 - * 825 - * This function is for 64-bit integer type controls only. 826 - */ 759 + /** v4l2_ctrl_s_ctrl_int64() - Helper function to set a 64-bit control's value 760 + * from within a driver. 761 + * 762 + * @ctrl: The control. 763 + * @val: The new value. 764 + * 765 + * This set the control's new value safely by going through the control 766 + * framework. This function will lock the control's handler, so it cannot be 767 + * used from within the &v4l2_ctrl_ops functions. 768 + * 769 + * This function is for 64-bit integer type controls only. 770 + */ 827 771 static inline int v4l2_ctrl_s_ctrl_int64(struct v4l2_ctrl *ctrl, s64 val) 828 772 { 829 773 int rval; ··· 850 764 return rval; 851 765 } 852 766 853 - /** __v4l2_ctrl_s_ctrl_string() - Unlocked variant of v4l2_ctrl_s_ctrl_string(). */ 767 + /** __v4l2_ctrl_s_ctrl_string() - Unlocked variant of v4l2_ctrl_s_ctrl_string(). 768 + * 769 + * @ctrl: The control. 770 + * @s: The new string. 771 + * 772 + * This set the control's new string safely by going through the control 773 + * framework. This function will lock the control's handler, so it cannot be 774 + * used from within the &v4l2_ctrl_ops functions. 775 + * 776 + * This function is for string type controls only. 777 + */ 854 778 int __v4l2_ctrl_s_ctrl_string(struct v4l2_ctrl *ctrl, const char *s); 855 779 856 - /** v4l2_ctrl_s_ctrl_string() - Helper function to set a control's string value from within a driver. 857 - * @ctrl: The control. 858 - * @s: The new string. 859 - * 860 - * This set the control's new string safely by going through the control 861 - * framework. This function will lock the control's handler, so it cannot be 862 - * used from within the &v4l2_ctrl_ops functions. 863 - * 864 - * This function is for string type controls only. 865 - */ 780 + /** v4l2_ctrl_s_ctrl_string() - Helper function to set a control's string value 781 + * from within a driver. 782 + * 783 + * @ctrl: The control. 784 + * @s: The new string. 785 + * 786 + * This set the control's new string safely by going through the control 787 + * framework. This function will lock the control's handler, so it cannot be 788 + * used from within the &v4l2_ctrl_ops functions. 789 + * 790 + * This function is for string type controls only. 791 + */ 866 792 static inline int v4l2_ctrl_s_ctrl_string(struct v4l2_ctrl *ctrl, const char *s) 867 793 { 868 794 int rval;
+82 -59
include/media/v4l2-dv-timings.h
··· 23 23 24 24 #include <linux/videodev2.h> 25 25 26 - /** v4l2_dv_timings_presets: list of all dv_timings presets. 26 + /** 27 + * v4l2_dv_timings_presets: list of all dv_timings presets. 27 28 */ 28 29 extern const struct v4l2_dv_timings v4l2_dv_timings_presets[]; 29 30 30 - /** v4l2_check_dv_timings_fnc - timings check callback 31 + /** 32 + * v4l2_check_dv_timings_fnc - timings check callback 33 + * 31 34 * @t: the v4l2_dv_timings struct. 32 35 * @handle: a handle from the driver. 33 36 * ··· 38 35 */ 39 36 typedef bool v4l2_check_dv_timings_fnc(const struct v4l2_dv_timings *t, void *handle); 40 37 41 - /** v4l2_valid_dv_timings() - are these timings valid? 42 - * @t: the v4l2_dv_timings struct. 43 - * @cap: the v4l2_dv_timings_cap capabilities. 44 - * @fnc: callback to check if this timing is OK. May be NULL. 45 - * @fnc_handle: a handle that is passed on to @fnc. 46 - * 47 - * Returns true if the given dv_timings struct is supported by the 48 - * hardware capabilities and the callback function (if non-NULL), returns 49 - * false otherwise. 50 - */ 38 + /** 39 + * v4l2_valid_dv_timings() - are these timings valid? 40 + * 41 + * @t: the v4l2_dv_timings struct. 42 + * @cap: the v4l2_dv_timings_cap capabilities. 43 + * @fnc: callback to check if this timing is OK. May be NULL. 44 + * @fnc_handle: a handle that is passed on to @fnc. 45 + * 46 + * Returns true if the given dv_timings struct is supported by the 47 + * hardware capabilities and the callback function (if non-NULL), returns 48 + * false otherwise. 49 + */ 51 50 bool v4l2_valid_dv_timings(const struct v4l2_dv_timings *t, 52 51 const struct v4l2_dv_timings_cap *cap, 53 52 v4l2_check_dv_timings_fnc fnc, 54 53 void *fnc_handle); 55 54 56 - /** v4l2_enum_dv_timings_cap() - Helper function to enumerate possible DV timings based on capabilities 57 - * @t: the v4l2_enum_dv_timings struct. 58 - * @cap: the v4l2_dv_timings_cap capabilities. 59 - * @fnc: callback to check if this timing is OK. May be NULL. 60 - * @fnc_handle: a handle that is passed on to @fnc. 61 - * 62 - * This enumerates dv_timings using the full list of possible CEA-861 and DMT 63 - * timings, filtering out any timings that are not supported based on the 64 - * hardware capabilities and the callback function (if non-NULL). 65 - * 66 - * If a valid timing for the given index is found, it will fill in @t and 67 - * return 0, otherwise it returns -EINVAL. 68 - */ 55 + /** 56 + * v4l2_enum_dv_timings_cap() - Helper function to enumerate possible DV 57 + * timings based on capabilities 58 + * 59 + * @t: the v4l2_enum_dv_timings struct. 60 + * @cap: the v4l2_dv_timings_cap capabilities. 61 + * @fnc: callback to check if this timing is OK. May be NULL. 62 + * @fnc_handle: a handle that is passed on to @fnc. 63 + * 64 + * This enumerates dv_timings using the full list of possible CEA-861 and DMT 65 + * timings, filtering out any timings that are not supported based on the 66 + * hardware capabilities and the callback function (if non-NULL). 67 + * 68 + * If a valid timing for the given index is found, it will fill in @t and 69 + * return 0, otherwise it returns -EINVAL. 70 + */ 69 71 int v4l2_enum_dv_timings_cap(struct v4l2_enum_dv_timings *t, 70 72 const struct v4l2_dv_timings_cap *cap, 71 73 v4l2_check_dv_timings_fnc fnc, 72 74 void *fnc_handle); 73 75 74 - /** v4l2_find_dv_timings_cap() - Find the closest timings struct 75 - * @t: the v4l2_enum_dv_timings struct. 76 - * @cap: the v4l2_dv_timings_cap capabilities. 77 - * @pclock_delta: maximum delta between t->pixelclock and the timing struct 78 - * under consideration. 79 - * @fnc: callback to check if a given timings struct is OK. May be NULL. 80 - * @fnc_handle: a handle that is passed on to @fnc. 81 - * 82 - * This function tries to map the given timings to an entry in the 83 - * full list of possible CEA-861 and DMT timings, filtering out any timings 84 - * that are not supported based on the hardware capabilities and the callback 85 - * function (if non-NULL). 86 - * 87 - * On success it will fill in @t with the found timings and it returns true. 88 - * On failure it will return false. 89 - */ 76 + /** 77 + * v4l2_find_dv_timings_cap() - Find the closest timings struct 78 + * 79 + * @t: the v4l2_enum_dv_timings struct. 80 + * @cap: the v4l2_dv_timings_cap capabilities. 81 + * @pclock_delta: maximum delta between t->pixelclock and the timing struct 82 + * under consideration. 83 + * @fnc: callback to check if a given timings struct is OK. May be NULL. 84 + * @fnc_handle: a handle that is passed on to @fnc. 85 + * 86 + * This function tries to map the given timings to an entry in the 87 + * full list of possible CEA-861 and DMT timings, filtering out any timings 88 + * that are not supported based on the hardware capabilities and the callback 89 + * function (if non-NULL). 90 + * 91 + * On success it will fill in @t with the found timings and it returns true. 92 + * On failure it will return false. 93 + */ 90 94 bool v4l2_find_dv_timings_cap(struct v4l2_dv_timings *t, 91 95 const struct v4l2_dv_timings_cap *cap, 92 96 unsigned pclock_delta, 93 97 v4l2_check_dv_timings_fnc fnc, 94 98 void *fnc_handle); 95 99 96 - /** v4l2_match_dv_timings() - do two timings match? 97 - * @measured: the measured timings data. 98 - * @standard: the timings according to the standard. 99 - * @pclock_delta: maximum delta in Hz between standard->pixelclock and 100 - * the measured timings. 101 - * 102 - * Returns true if the two timings match, returns false otherwise. 103 - */ 100 + /** 101 + * v4l2_match_dv_timings() - do two timings match? 102 + * 103 + * @measured: the measured timings data. 104 + * @standard: the timings according to the standard. 105 + * @pclock_delta: maximum delta in Hz between standard->pixelclock and 106 + * the measured timings. 107 + * 108 + * Returns true if the two timings match, returns false otherwise. 109 + */ 104 110 bool v4l2_match_dv_timings(const struct v4l2_dv_timings *measured, 105 111 const struct v4l2_dv_timings *standard, 106 112 unsigned pclock_delta); 107 113 108 - /** v4l2_print_dv_timings() - log the contents of a dv_timings struct 109 - * @dev_prefix:device prefix for each log line. 110 - * @prefix: additional prefix for each log line, may be NULL. 111 - * @t: the timings data. 112 - * @detailed: if true, give a detailed log. 113 - */ 114 + /** 115 + * v4l2_print_dv_timings() - log the contents of a dv_timings struct 116 + * @dev_prefix:device prefix for each log line. 117 + * @prefix: additional prefix for each log line, may be NULL. 118 + * @t: the timings data. 119 + * @detailed: if true, give a detailed log. 120 + */ 114 121 void v4l2_print_dv_timings(const char *dev_prefix, const char *prefix, 115 122 const struct v4l2_dv_timings *t, bool detailed); 116 123 117 - /** v4l2_detect_cvt - detect if the given timings follow the CVT standard 124 + /** 125 + * v4l2_detect_cvt - detect if the given timings follow the CVT standard 126 + * 118 127 * @frame_height - the total height of the frame (including blanking) in lines. 119 128 * @hfreq - the horizontal frequency in Hz. 120 129 * @vsync - the height of the vertical sync in lines. 130 + * @active_width - active width of image (does not include blanking). This 131 + * information is needed only in case of version 2 of reduced blanking. 132 + * In other cases, this parameter does not have any effect on timings. 121 133 * @polarities - the horizontal and vertical polarities (same as struct 122 134 * v4l2_bt_timings polarities). 123 135 * @interlaced - if this flag is true, it indicates interlaced format ··· 143 125 * in with the found CVT timings. 144 126 */ 145 127 bool v4l2_detect_cvt(unsigned frame_height, unsigned hfreq, unsigned vsync, 146 - u32 polarities, bool interlaced, struct v4l2_dv_timings *fmt); 128 + unsigned active_width, u32 polarities, bool interlaced, 129 + struct v4l2_dv_timings *fmt); 147 130 148 - /** v4l2_detect_gtf - detect if the given timings follow the GTF standard 131 + /** 132 + * v4l2_detect_gtf - detect if the given timings follow the GTF standard 133 + * 149 134 * @frame_height - the total height of the frame (including blanking) in lines. 150 135 * @hfreq - the horizontal frequency in Hz. 151 136 * @vsync - the height of the vertical sync in lines. ··· 170 149 u32 polarities, bool interlaced, struct v4l2_fract aspect, 171 150 struct v4l2_dv_timings *fmt); 172 151 173 - /** v4l2_calc_aspect_ratio - calculate the aspect ratio based on bytes 152 + /** 153 + * v4l2_calc_aspect_ratio - calculate the aspect ratio based on bytes 174 154 * 0x15 and 0x16 from the EDID. 155 + * 175 156 * @hor_landscape - byte 0x15 from the EDID. 176 157 * @vert_portrait - byte 0x16 from the EDID. 177 158 *
+25 -22
include/media/v4l2-event.h
··· 68 68 struct v4l2_subscribed_event; 69 69 struct video_device; 70 70 71 - /** struct v4l2_kevent - Internal kernel event struct. 72 - * @list: List node for the v4l2_fh->available list. 73 - * @sev: Pointer to parent v4l2_subscribed_event. 74 - * @event: The event itself. 71 + /** 72 + * struct v4l2_kevent - Internal kernel event struct. 73 + * @list: List node for the v4l2_fh->available list. 74 + * @sev: Pointer to parent v4l2_subscribed_event. 75 + * @event: The event itself. 75 76 */ 76 77 struct v4l2_kevent { 77 78 struct list_head list; ··· 81 80 }; 82 81 83 82 /** struct v4l2_subscribed_event_ops - Subscribed event operations. 84 - * @add: Optional callback, called when a new listener is added 85 - * @del: Optional callback, called when a listener stops listening 86 - * @replace: Optional callback that can replace event 'old' with event 'new'. 87 - * @merge: Optional callback that can merge event 'old' into event 'new'. 88 - */ 83 + * 84 + * @add: Optional callback, called when a new listener is added 85 + * @del: Optional callback, called when a listener stops listening 86 + * @replace: Optional callback that can replace event 'old' with event 'new'. 87 + * @merge: Optional callback that can merge event 'old' into event 'new'. 88 + */ 89 89 struct v4l2_subscribed_event_ops { 90 90 int (*add)(struct v4l2_subscribed_event *sev, unsigned elems); 91 91 void (*del)(struct v4l2_subscribed_event *sev); ··· 94 92 void (*merge)(const struct v4l2_event *old, struct v4l2_event *new); 95 93 }; 96 94 97 - /** struct v4l2_subscribed_event - Internal struct representing a subscribed event. 98 - * @list: List node for the v4l2_fh->subscribed list. 99 - * @type: Event type. 100 - * @id: Associated object ID (e.g. control ID). 0 if there isn't any. 101 - * @flags: Copy of v4l2_event_subscription->flags. 102 - * @fh: Filehandle that subscribed to this event. 103 - * @node: List node that hooks into the object's event list (if there is one). 104 - * @ops: v4l2_subscribed_event_ops 105 - * @elems: The number of elements in the events array. 106 - * @first: The index of the events containing the oldest available event. 107 - * @in_use: The number of queued events. 108 - * @events: An array of @elems events. 109 - */ 95 + /** 96 + * struct v4l2_subscribed_event - Internal struct representing a subscribed event. 97 + * @list: List node for the v4l2_fh->subscribed list. 98 + * @type: Event type. 99 + * @id: Associated object ID (e.g. control ID). 0 if there isn't any. 100 + * @flags: Copy of v4l2_event_subscription->flags. 101 + * @fh: Filehandle that subscribed to this event. 102 + * @node: List node that hooks into the object's event list (if there is one). 103 + * @ops: v4l2_subscribed_event_ops 104 + * @elems: The number of elements in the events array. 105 + * @first: The index of the events containing the oldest available event. 106 + * @in_use: The number of queued events. 107 + * @events: An array of @elems events. 108 + */ 110 109 struct v4l2_subscribed_event { 111 110 struct list_head list; 112 111 u32 type;
+6 -6
include/media/v4l2-flash-led-class.h
··· 48 48 /** 49 49 * struct v4l2_flash_config - V4L2 Flash sub-device initialization data 50 50 * @dev_name: the name of the media entity, 51 - unique in the system 51 + * unique in the system 52 52 * @torch_intensity: constraints for the LED in torch mode 53 53 * @indicator_intensity: constraints for the indicator LED 54 54 * @flash_faults: bitmask of flash faults that the LED flash class 55 - device can report; corresponding LED_FAULT* bit 56 - definitions are available in the header file 57 - <linux/led-class-flash.h> 55 + * device can report; corresponding LED_FAULT* bit 56 + * definitions are available in the header file 57 + * <linux/led-class-flash.h> 58 58 * @has_external_strobe: external strobe capability 59 59 */ 60 60 struct v4l2_flash_config { ··· 105 105 * @fled_cdev: LED flash class device to wrap 106 106 * @iled_cdev: LED flash class device representing indicator LED associated 107 107 * with fled_cdev, may be NULL 108 - * @flash_ops: V4L2 Flash device ops 108 + * @ops: V4L2 Flash device ops 109 109 * @config: initialization data for V4L2 Flash sub-device 110 110 * 111 111 * Create V4L2 Flash sub-device wrapping given LED subsystem device. ··· 123 123 124 124 /** 125 125 * v4l2_flash_release - release V4L2 Flash sub-device 126 - * @flash: the V4L2 Flash sub-device to release 126 + * @v4l2_flash: the V4L2 Flash sub-device to release 127 127 * 128 128 * Release V4L2 Flash sub-device. 129 129 */
+2 -2
include/media/v4l2-mediabus.h
··· 65 65 V4L2_MBUS_CSI2_CHANNEL_2 | V4L2_MBUS_CSI2_CHANNEL_3) 66 66 67 67 /** 68 - * v4l2_mbus_type - media bus type 68 + * enum v4l2_mbus_type - media bus type 69 69 * @V4L2_MBUS_PARALLEL: parallel interface with hsync and vsync 70 70 * @V4L2_MBUS_BT656: parallel interface with embedded synchronisation, can 71 71 * also be used for BT.1120 ··· 78 78 }; 79 79 80 80 /** 81 - * v4l2_mbus_config - media bus configuration 81 + * struct v4l2_mbus_config - media bus configuration 82 82 * @type: in: interface type 83 83 * @flags: in / out: configuration flags, depending on @type 84 84 */
+20
include/media/v4l2-mem2mem.h
··· 40 40 * v4l2_m2m_job_finish() (as if the transaction ended normally). 41 41 * This function does not have to (and will usually not) wait 42 42 * until the device enters a state when it can be stopped. 43 + * @lock: optional. Define a driver's own lock callback, instead of using 44 + * m2m_ctx->q_lock. 45 + * @unlock: optional. Define a driver's own unlock callback, instead of 46 + * using m2m_ctx->q_lock. 43 47 */ 44 48 struct v4l2_m2m_ops { 45 49 void (*device_run)(void *priv); ··· 165 161 /** 166 162 * v4l2_m2m_num_src_bufs_ready() - return the number of source buffers ready for 167 163 * use 164 + * 165 + * @m2m_ctx: pointer to struct v4l2_m2m_ctx 168 166 */ 169 167 static inline 170 168 unsigned int v4l2_m2m_num_src_bufs_ready(struct v4l2_m2m_ctx *m2m_ctx) ··· 177 171 /** 178 172 * v4l2_m2m_num_src_bufs_ready() - return the number of destination buffers 179 173 * ready for use 174 + * 175 + * @m2m_ctx: pointer to struct v4l2_m2m_ctx 180 176 */ 181 177 static inline 182 178 unsigned int v4l2_m2m_num_dst_bufs_ready(struct v4l2_m2m_ctx *m2m_ctx) ··· 191 183 /** 192 184 * v4l2_m2m_next_src_buf() - return next source buffer from the list of ready 193 185 * buffers 186 + * 187 + * @m2m_ctx: pointer to struct v4l2_m2m_ctx 194 188 */ 195 189 static inline void *v4l2_m2m_next_src_buf(struct v4l2_m2m_ctx *m2m_ctx) 196 190 { ··· 202 192 /** 203 193 * v4l2_m2m_next_dst_buf() - return next destination buffer from the list of 204 194 * ready buffers 195 + * 196 + * @m2m_ctx: pointer to struct v4l2_m2m_ctx 205 197 */ 206 198 static inline void *v4l2_m2m_next_dst_buf(struct v4l2_m2m_ctx *m2m_ctx) 207 199 { ··· 212 200 213 201 /** 214 202 * v4l2_m2m_get_src_vq() - return vb2_queue for source buffers 203 + * 204 + * @m2m_ctx: pointer to struct v4l2_m2m_ctx 215 205 */ 216 206 static inline 217 207 struct vb2_queue *v4l2_m2m_get_src_vq(struct v4l2_m2m_ctx *m2m_ctx) ··· 223 209 224 210 /** 225 211 * v4l2_m2m_get_dst_vq() - return vb2_queue for destination buffers 212 + * 213 + * @m2m_ctx: pointer to struct v4l2_m2m_ctx 226 214 */ 227 215 static inline 228 216 struct vb2_queue *v4l2_m2m_get_dst_vq(struct v4l2_m2m_ctx *m2m_ctx) ··· 237 221 /** 238 222 * v4l2_m2m_src_buf_remove() - take off a source buffer from the list of ready 239 223 * buffers and return it 224 + * 225 + * @m2m_ctx: pointer to struct v4l2_m2m_ctx 240 226 */ 241 227 static inline void *v4l2_m2m_src_buf_remove(struct v4l2_m2m_ctx *m2m_ctx) 242 228 { ··· 248 230 /** 249 231 * v4l2_m2m_dst_buf_remove() - take off a destination buffer from the list of 250 232 * ready buffers and return it 233 + * 234 + * @m2m_ctx: pointer to struct v4l2_m2m_ctx 251 235 */ 252 236 static inline void *v4l2_m2m_dst_buf_remove(struct v4l2_m2m_ctx *m2m_ctx) 253 237 {
+249 -127
include/media/v4l2-subdev.h
··· 44 44 45 45 struct v4l2_device; 46 46 struct v4l2_ctrl_handler; 47 + struct v4l2_event; 47 48 struct v4l2_event_subscription; 48 49 struct v4l2_fh; 49 50 struct v4l2_subdev; ··· 118 117 u8 strength; /* Pin drive strength */ 119 118 }; 120 119 121 - /* 122 - s_io_pin_config: configure one or more chip I/O pins for chips that 123 - multiplex different internal signal pads out to IO pins. This function 124 - takes a pointer to an array of 'n' pin configuration entries, one for 125 - each pin being configured. This function could be called at times 126 - other than just subdevice initialization. 127 - 128 - init: initialize the sensor registers to some sort of reasonable default 129 - values. Do not use for new drivers and should be removed in existing 130 - drivers. 131 - 132 - load_fw: load firmware. 133 - 134 - reset: generic reset command. The argument selects which subsystems to 135 - reset. Passing 0 will always reset the whole chip. Do not use for new 136 - drivers without discussing this first on the linux-media mailinglist. 137 - There should be no reason normally to reset a device. 138 - 139 - s_gpio: set GPIO pins. Very simple right now, might need to be extended with 140 - a direction argument if needed. 141 - 142 - s_power: puts subdevice in power saving mode (on == 0) or normal operation 143 - mode (on == 1). 144 - 145 - interrupt_service_routine: Called by the bridge chip's interrupt service 146 - handler, when an interrupt status has be raised due to this subdev, 147 - so that this subdev can handle the details. It may schedule work to be 148 - performed later. It must not sleep. *Called from an IRQ context*. 120 + /** 121 + * struct v4l2_subdev_core_ops - Define core ops callbacks for subdevs 122 + * 123 + * @log_status: callback for VIDIOC_LOG_STATUS ioctl handler code. 124 + * 125 + * @s_io_pin_config: configure one or more chip I/O pins for chips that 126 + * multiplex different internal signal pads out to IO pins. This function 127 + * takes a pointer to an array of 'n' pin configuration entries, one for 128 + * each pin being configured. This function could be called at times 129 + * other than just subdevice initialization. 130 + * 131 + * @init: initialize the sensor registers to some sort of reasonable default 132 + * values. Do not use for new drivers and should be removed in existing 133 + * drivers. 134 + * 135 + * @load_fw: load firmware. 136 + * 137 + * @reset: generic reset command. The argument selects which subsystems to 138 + * reset. Passing 0 will always reset the whole chip. Do not use for new 139 + * drivers without discussing this first on the linux-media mailinglist. 140 + * There should be no reason normally to reset a device. 141 + * 142 + * @s_gpio: set GPIO pins. Very simple right now, might need to be extended with 143 + * a direction argument if needed. 144 + * 145 + * @queryctrl: callback for VIDIOC_QUERYCTL ioctl handler code. 146 + * 147 + * @g_ctrl: callback for VIDIOC_G_CTRL ioctl handler code. 148 + * 149 + * @s_ctrl: callback for VIDIOC_S_CTRL ioctl handler code. 150 + * 151 + * @g_ext_ctrls: callback for VIDIOC_G_EXT_CTRLS ioctl handler code. 152 + * 153 + * @s_ext_ctrls: callback for VIDIOC_S_EXT_CTRLS ioctl handler code. 154 + * 155 + * @try_ext_ctrls: callback for VIDIOC_TRY_EXT_CTRLS ioctl handler code. 156 + * 157 + * @querymenu: callback for VIDIOC_QUERYMENU ioctl handler code. 158 + * 159 + * @ioctl: called at the end of ioctl() syscall handler at the V4L2 core. 160 + * used to provide support for private ioctls used on the driver. 161 + * 162 + * @compat_ioctl32: called when a 32 bits application uses a 64 bits Kernel, 163 + * in order to fix data passed from/to userspace. 164 + * 165 + * @g_register: callback for VIDIOC_G_REGISTER ioctl handler code. 166 + * 167 + * @s_register: callback for VIDIOC_G_REGISTER ioctl handler code. 168 + * 169 + * @s_power: puts subdevice in power saving mode (on == 0) or normal operation 170 + * mode (on == 1). 171 + * 172 + * @interrupt_service_routine: Called by the bridge chip's interrupt service 173 + * handler, when an interrupt status has be raised due to this subdev, 174 + * so that this subdev can handle the details. It may schedule work to be 175 + * performed later. It must not sleep. *Called from an IRQ context*. 176 + * 177 + * @subscribe_event: used by the drivers to request the control framework that 178 + * for it to be warned when the value of a control changes. 179 + * 180 + * @unsubscribe_event: remove event subscription from the control framework. 149 181 */ 150 182 struct v4l2_subdev_core_ops { 151 183 int (*log_status)(struct v4l2_subdev *sd); ··· 213 179 struct v4l2_event_subscription *sub); 214 180 }; 215 181 216 - /* s_radio: v4l device was opened in radio mode. 217 - 218 - g_frequency: freq->type must be filled in. Normally done by video_ioctl2 219 - or the bridge driver. 220 - 221 - g_tuner: 222 - s_tuner: vt->type must be filled in. Normally done by video_ioctl2 or the 223 - bridge driver. 224 - 225 - s_type_addr: sets tuner type and its I2C addr. 226 - 227 - s_config: sets tda9887 specific stuff, like port1, port2 and qss 182 + /** 183 + * struct s_radio - Callbacks used when v4l device was opened in radio mode. 184 + * 185 + * @s_radio: callback for VIDIOC_S_RADIO ioctl handler code. 186 + * 187 + * @s_frequency: callback for VIDIOC_S_FREQUENCY ioctl handler code. 188 + * 189 + * @g_frequency: callback for VIDIOC_G_FREQUENCY ioctl handler code. 190 + * freq->type must be filled in. Normally done by video_ioctl2 191 + * or the bridge driver. 192 + * 193 + * @enum_freq_bands: callback for VIDIOC_ENUM_FREQ_BANDS ioctl handler code. 194 + * 195 + * @g_tuner: callback for VIDIOC_G_TUNER ioctl handler code. 196 + * 197 + * @s_tuner: callback for VIDIOC_S_TUNER ioctl handler code. vt->type must be 198 + * filled in. Normally done by video_ioctl2 or the 199 + * bridge driver. 200 + * 201 + * @g_modulator: callback for VIDIOC_G_MODULATOR ioctl handler code. 202 + * 203 + * @s_modulator: callback for VIDIOC_S_MODULATOR ioctl handler code. 204 + * 205 + * @s_type_addr: sets tuner type and its I2C addr. 206 + * 207 + * @s_config: sets tda9887 specific stuff, like port1, port2 and qss 228 208 */ 229 209 struct v4l2_subdev_tuner_ops { 230 210 int (*s_radio)(struct v4l2_subdev *sd); ··· 253 205 int (*s_config)(struct v4l2_subdev *sd, const struct v4l2_priv_tun_config *config); 254 206 }; 255 207 256 - /* s_clock_freq: set the frequency (in Hz) of the audio clock output. 257 - Used to slave an audio processor to the video decoder, ensuring that 258 - audio and video remain synchronized. Usual values for the frequency 259 - are 48000, 44100 or 32000 Hz. If the frequency is not supported, then 260 - -EINVAL is returned. 261 - 262 - s_i2s_clock_freq: sets I2S speed in bps. This is used to provide a standard 263 - way to select I2S clock used by driving digital audio streams at some 264 - board designs. Usual values for the frequency are 1024000 and 2048000. 265 - If the frequency is not supported, then -EINVAL is returned. 266 - 267 - s_routing: used to define the input and/or output pins of an audio chip, 268 - and any additional configuration data. 269 - Never attempt to use user-level input IDs (e.g. Composite, S-Video, 270 - Tuner) at this level. An i2c device shouldn't know about whether an 271 - input pin is connected to a Composite connector, become on another 272 - board or platform it might be connected to something else entirely. 273 - The calling driver is responsible for mapping a user-level input to 274 - the right pins on the i2c device. 208 + /** 209 + * struct v4l2_subdev_audio_ops - Callbacks used for audio-related settings 210 + * 211 + * @s_clock_freq: set the frequency (in Hz) of the audio clock output. 212 + * Used to slave an audio processor to the video decoder, ensuring that 213 + * audio and video remain synchronized. Usual values for the frequency 214 + * are 48000, 44100 or 32000 Hz. If the frequency is not supported, then 215 + * -EINVAL is returned. 216 + * 217 + * @s_i2s_clock_freq: sets I2S speed in bps. This is used to provide a standard 218 + * way to select I2S clock used by driving digital audio streams at some 219 + * board designs. Usual values for the frequency are 1024000 and 2048000. 220 + * If the frequency is not supported, then -EINVAL is returned. 221 + * 222 + * @s_routing: used to define the input and/or output pins of an audio chip, 223 + * and any additional configuration data. 224 + * Never attempt to use user-level input IDs (e.g. Composite, S-Video, 225 + * Tuner) at this level. An i2c device shouldn't know about whether an 226 + * input pin is connected to a Composite connector, become on another 227 + * board or platform it might be connected to something else entirely. 228 + * The calling driver is responsible for mapping a user-level input to 229 + * the right pins on the i2c device. 230 + * 231 + * @s_stream: used to notify the audio code that stream will start or has 232 + * stopped. 275 233 */ 276 234 struct v4l2_subdev_audio_ops { 277 235 int (*s_clock_freq)(struct v4l2_subdev *sd, u32 freq); ··· 296 242 297 243 /** 298 244 * struct v4l2_mbus_frame_desc_entry - media bus frame description structure 245 + * 299 246 * @flags: V4L2_MBUS_FRAME_DESC_FL_* flags 300 247 * @pixelcode: media bus pixel code, valid if FRAME_DESC_FL_BLOB is not set 301 248 * @length: number of octets per frame, valid if V4L2_MBUS_FRAME_DESC_FL_BLOB ··· 320 265 unsigned short num_entries; 321 266 }; 322 267 323 - /* 324 - s_std_output: set v4l2_std_id for video OUTPUT devices. This is ignored by 325 - video input devices. 326 - 327 - g_std_output: get current standard for video OUTPUT devices. This is ignored 328 - by video input devices. 329 - 330 - g_tvnorms: get v4l2_std_id with all standards supported by the video 331 - CAPTURE device. This is ignored by video output devices. 332 - 333 - g_tvnorms_output: get v4l2_std_id with all standards supported by the video 334 - OUTPUT device. This is ignored by video capture devices. 335 - 336 - s_crystal_freq: sets the frequency of the crystal used to generate the 337 - clocks in Hz. An extra flags field allows device specific configuration 338 - regarding clock frequency dividers, etc. If not used, then set flags 339 - to 0. If the frequency is not supported, then -EINVAL is returned. 340 - 341 - g_input_status: get input status. Same as the status field in the v4l2_input 342 - struct. 343 - 344 - s_routing: see s_routing in audio_ops, except this version is for video 345 - devices. 346 - 347 - s_dv_timings(): Set custom dv timings in the sub device. This is used 348 - when sub device is capable of setting detailed timing information 349 - in the hardware to generate/detect the video signal. 350 - 351 - g_dv_timings(): Get custom dv timings in the sub device. 352 - 353 - g_mbus_config: get supported mediabus configurations 354 - 355 - s_mbus_config: set a certain mediabus configuration. This operation is added 356 - for compatibility with soc-camera drivers and should not be used by new 357 - software. 358 - 359 - s_rx_buffer: set a host allocated memory buffer for the subdev. The subdev 360 - can adjust @size to a lower value and must not write more data to the 361 - buffer starting at @data than the original value of @size. 268 + /** 269 + * struct v4l2_subdev_video_ops - Callbacks used when v4l device was opened 270 + * in video mode. 271 + * 272 + * @s_routing: see s_routing in audio_ops, except this version is for video 273 + * devices. 274 + * 275 + * @s_crystal_freq: sets the frequency of the crystal used to generate the 276 + * clocks in Hz. An extra flags field allows device specific configuration 277 + * regarding clock frequency dividers, etc. If not used, then set flags 278 + * to 0. If the frequency is not supported, then -EINVAL is returned. 279 + * 280 + * @g_std: callback for VIDIOC_G_STD ioctl handler code. 281 + * 282 + * @s_std: callback for VIDIOC_S_STD ioctl handler code. 283 + * 284 + * @s_std_output: set v4l2_std_id for video OUTPUT devices. This is ignored by 285 + * video input devices. 286 + * 287 + * @g_std_output: get current standard for video OUTPUT devices. This is ignored 288 + * by video input devices. 289 + * 290 + * @querystd: callback for VIDIOC_QUERYSTD ioctl handler code. 291 + * 292 + * @g_tvnorms: get v4l2_std_id with all standards supported by the video 293 + * CAPTURE device. This is ignored by video output devices. 294 + * 295 + * @g_tvnorms_output: get v4l2_std_id with all standards supported by the video 296 + * OUTPUT device. This is ignored by video capture devices. 297 + * 298 + * @g_input_status: get input status. Same as the status field in the v4l2_input 299 + * struct. 300 + * 301 + * @s_stream: used to notify the driver that a video stream will start or has 302 + * stopped. 303 + * 304 + * @cropcap: callback for VIDIOC_CROPCAP ioctl handler code. 305 + * 306 + * @g_crop: callback for VIDIOC_G_CROP ioctl handler code. 307 + * 308 + * @s_crop: callback for VIDIOC_S_CROP ioctl handler code. 309 + * 310 + * @g_parm: callback for VIDIOC_G_PARM ioctl handler code. 311 + * 312 + * @s_parm: callback for VIDIOC_S_PARM ioctl handler code. 313 + * 314 + * @g_frame_interval: callback for VIDIOC_G_FRAMEINTERVAL ioctl handler code. 315 + * 316 + * @s_frame_interval: callback for VIDIOC_S_FRAMEINTERVAL ioctl handler code. 317 + * 318 + * @s_dv_timings: Set custom dv timings in the sub device. This is used 319 + * when sub device is capable of setting detailed timing information 320 + * in the hardware to generate/detect the video signal. 321 + * 322 + * @g_dv_timings: Get custom dv timings in the sub device. 323 + * 324 + * @query_dv_timings: callback for VIDIOC_QUERY_DV_TIMINGS ioctl handler code. 325 + * 326 + * @g_mbus_config: get supported mediabus configurations 327 + * 328 + * @s_mbus_config: set a certain mediabus configuration. This operation is added 329 + * for compatibility with soc-camera drivers and should not be used by new 330 + * software. 331 + * 332 + * @s_rx_buffer: set a host allocated memory buffer for the subdev. The subdev 333 + * can adjust @size to a lower value and must not write more data to the 334 + * buffer starting at @data than the original value of @size. 362 335 */ 363 336 struct v4l2_subdev_video_ops { 364 337 int (*s_routing)(struct v4l2_subdev *sd, u32 input, u32 output, u32 config); ··· 423 340 unsigned int *size); 424 341 }; 425 342 426 - /* 427 - decode_vbi_line: video decoders that support sliced VBI need to implement 428 - this ioctl. Field p of the v4l2_sliced_vbi_line struct is set to the 429 - start of the VBI data that was generated by the decoder. The driver 430 - then parses the sliced VBI data and sets the other fields in the 431 - struct accordingly. The pointer p is updated to point to the start of 432 - the payload which can be copied verbatim into the data field of the 433 - v4l2_sliced_vbi_data struct. If no valid VBI data was found, then the 434 - type field is set to 0 on return. 435 - 436 - s_vbi_data: used to generate VBI signals on a video signal. 437 - v4l2_sliced_vbi_data is filled with the data packets that should be 438 - output. Note that if you set the line field to 0, then that VBI signal 439 - is disabled. If no valid VBI data was found, then the type field is 440 - set to 0 on return. 441 - 442 - g_vbi_data: used to obtain the sliced VBI packet from a readback register. 443 - Not all video decoders support this. If no data is available because 444 - the readback register contains invalid or erroneous data -EIO is 445 - returned. Note that you must fill in the 'id' member and the 'field' 446 - member (to determine whether CC data from the first or second field 447 - should be obtained). 448 - 449 - s_raw_fmt: setup the video encoder/decoder for raw VBI. 450 - 451 - g_sliced_fmt: retrieve the current sliced VBI settings. 452 - 453 - s_sliced_fmt: setup the sliced VBI settings. 343 + /** 344 + * struct v4l2_subdev_vbi_ops - Callbacks used when v4l device was opened 345 + * in video mode via the vbi device node. 346 + * 347 + * @decode_vbi_line: video decoders that support sliced VBI need to implement 348 + * this ioctl. Field p of the v4l2_sliced_vbi_line struct is set to the 349 + * start of the VBI data that was generated by the decoder. The driver 350 + * then parses the sliced VBI data and sets the other fields in the 351 + * struct accordingly. The pointer p is updated to point to the start of 352 + * the payload which can be copied verbatim into the data field of the 353 + * v4l2_sliced_vbi_data struct. If no valid VBI data was found, then the 354 + * type field is set to 0 on return. 355 + * 356 + * @s_vbi_data: used to generate VBI signals on a video signal. 357 + * v4l2_sliced_vbi_data is filled with the data packets that should be 358 + * output. Note that if you set the line field to 0, then that VBI signal 359 + * is disabled. If no valid VBI data was found, then the type field is 360 + * set to 0 on return. 361 + * 362 + * @g_vbi_data: used to obtain the sliced VBI packet from a readback register. 363 + * Not all video decoders support this. If no data is available because 364 + * the readback register contains invalid or erroneous data -EIO is 365 + * returned. Note that you must fill in the 'id' member and the 'field' 366 + * member (to determine whether CC data from the first or second field 367 + * should be obtained). 368 + * 369 + * @g_sliced_vbi_cap: callback for VIDIOC_SLICED_VBI_CAP ioctl handler code. 370 + * 371 + * @s_raw_fmt: setup the video encoder/decoder for raw VBI. 372 + * 373 + * @g_sliced_fmt: retrieve the current sliced VBI settings. 374 + * 375 + * @s_sliced_fmt: setup the sliced VBI settings. 454 376 */ 455 377 struct v4l2_subdev_vbi_ops { 456 378 int (*decode_vbi_line)(struct v4l2_subdev *sd, struct v4l2_decode_vbi_line *vbi_line); ··· 568 480 569 481 /** 570 482 * struct v4l2_subdev_pad_ops - v4l2-subdev pad level operations 483 + * 484 + * @enum_mbus_code: callback for VIDIOC_SUBDEV_ENUM_MBUS_CODE ioctl handler 485 + * code. 486 + * @enum_frame_size: callback for VIDIOC_SUBDEV_ENUM_FRAME_SIZE ioctl handler 487 + * code. 488 + * 489 + * @enum_frame_interval: callback for VIDIOC_SUBDEV_ENUM_FRAME_INTERVAL ioctl 490 + * handler code. 491 + * 492 + * @get_fmt: callback for VIDIOC_SUBDEV_G_FMT ioctl handler code. 493 + * 494 + * @set_fmt: callback for VIDIOC_SUBDEV_S_FMT ioctl handler code. 495 + * 496 + * @get_selection: callback for VIDIOC_SUBDEV_G_SELECTION ioctl handler code. 497 + * 498 + * @set_selection: callback for VIDIOC_SUBDEV_S_SELECTION ioctl handler code. 499 + * 500 + * @get_edid: callback for VIDIOC_SUBDEV_G_EDID ioctl handler code. 501 + * 502 + * @set_edid: callback for VIDIOC_SUBDEV_S_EDID ioctl handler code. 503 + * 504 + * @dv_timings_cap: callback for VIDIOC_SUBDEV_DV_TIMINGS_CAP ioctl handler 505 + * code. 506 + * 507 + * @enum_dv_timings: callback for VIDIOC_SUBDEV_ENUM_DV_TIMINGS ioctl handler 508 + * code. 509 + * 510 + * @link_validate: used by the media controller code to check if the links 511 + * that belongs to a pipeline can be used for stream. 512 + * 571 513 * @get_frame_desc: get the current low level media bus frame parameters. 572 - * @get_frame_desc: set the low level media bus frame parameters, @fd array 514 + * 515 + * @set_frame_desc: set the low level media bus frame parameters, @fd array 573 516 * may be adjusted by the subdev driver to device capabilities. 574 517 */ 575 518 struct v4l2_subdev_pad_ops { ··· 813 694 814 695 #define v4l2_subdev_has_op(sd, o, f) \ 815 696 ((sd)->ops->o && (sd)->ops->o->f) 697 + 698 + void v4l2_subdev_notify_event(struct v4l2_subdev *sd, 699 + const struct v4l2_event *ev); 816 700 817 701 #endif
+6 -4
include/media/videobuf2-core.h
··· 364 364 * start_streaming() can be called. Used when a DMA engine 365 365 * cannot be started unless at least this number of buffers 366 366 * have been queued into the driver. 367 - * 367 + */ 368 + /* 369 + * Private elements (won't appear at the DocBook): 368 370 * @mmap_lock: private mutex used when buffers are allocated/freed/mmapped 369 371 * @memory: current memory type used 370 372 * @bufs: videobuf buffer structures ··· 409 407 gfp_t gfp_flags; 410 408 u32 min_buffers_needed; 411 409 412 - /* private: internal use only */ 410 + /* private: internal use only */ 413 411 struct mutex mmap_lock; 414 412 enum v4l2_memory memory; 415 413 struct vb2_buffer *bufs[VIDEO_MAX_FRAME]; ··· 486 484 loff_t *ppos, int nonblock); 487 485 size_t vb2_write(struct vb2_queue *q, const char __user *data, size_t count, 488 486 loff_t *ppos, int nonblock); 489 - /** 487 + 488 + /* 490 489 * vb2_thread_fnc - callback function for use with vb2_thread 491 490 * 492 491 * This is called whenever a buffer is dequeued in the thread. ··· 580 577 * vb2_get_plane_payload() - get bytesused for the plane plane_no 581 578 * @vb: buffer for which plane payload should be set 582 579 * @plane_no: plane number for which payload should be set 583 - * @size: payload in bytes 584 580 */ 585 581 static inline unsigned long vb2_get_plane_payload(struct vb2_buffer *vb, 586 582 unsigned int plane_no)
+2 -1
include/media/videobuf2-memops.h
··· 17 17 #include <media/videobuf2-core.h> 18 18 19 19 /** 20 - * vb2_vmarea_handler - common vma refcount tracking handler 20 + * struct vb2_vmarea_handler - common vma refcount tracking handler 21 + * 21 22 * @refcount: pointer to refcount entry in the buffer 22 23 * @put: callback to function that decreases buffer refcount 23 24 * @arg: argument for @put callback
+176 -83
include/trace/events/v4l2.h
··· 93 93 { V4L2_TC_USERBITS_USERDEFINED, "USERBITS_USERDEFINED" }, \ 94 94 { V4L2_TC_USERBITS_8BITCHARS, "USERBITS_8BITCHARS" }) 95 95 96 - #define V4L2_TRACE_EVENT(event_name) \ 97 - TRACE_EVENT(event_name, \ 98 - TP_PROTO(int minor, struct v4l2_buffer *buf), \ 99 - \ 100 - TP_ARGS(minor, buf), \ 101 - \ 102 - TP_STRUCT__entry( \ 103 - __field(int, minor) \ 104 - __field(u32, index) \ 105 - __field(u32, type) \ 106 - __field(u32, bytesused) \ 107 - __field(u32, flags) \ 108 - __field(u32, field) \ 109 - __field(s64, timestamp) \ 110 - __field(u32, timecode_type) \ 111 - __field(u32, timecode_flags) \ 112 - __field(u8, timecode_frames) \ 113 - __field(u8, timecode_seconds) \ 114 - __field(u8, timecode_minutes) \ 115 - __field(u8, timecode_hours) \ 116 - __field(u8, timecode_userbits0) \ 117 - __field(u8, timecode_userbits1) \ 118 - __field(u8, timecode_userbits2) \ 119 - __field(u8, timecode_userbits3) \ 120 - __field(u32, sequence) \ 121 - ), \ 122 - \ 123 - TP_fast_assign( \ 124 - __entry->minor = minor; \ 125 - __entry->index = buf->index; \ 126 - __entry->type = buf->type; \ 127 - __entry->bytesused = buf->bytesused; \ 128 - __entry->flags = buf->flags; \ 129 - __entry->field = buf->field; \ 130 - __entry->timestamp = \ 131 - timeval_to_ns(&buf->timestamp); \ 132 - __entry->timecode_type = buf->timecode.type; \ 133 - __entry->timecode_flags = buf->timecode.flags; \ 134 - __entry->timecode_frames = \ 135 - buf->timecode.frames; \ 136 - __entry->timecode_seconds = \ 137 - buf->timecode.seconds; \ 138 - __entry->timecode_minutes = \ 139 - buf->timecode.minutes; \ 140 - __entry->timecode_hours = buf->timecode.hours; \ 141 - __entry->timecode_userbits0 = \ 142 - buf->timecode.userbits[0]; \ 143 - __entry->timecode_userbits1 = \ 144 - buf->timecode.userbits[1]; \ 145 - __entry->timecode_userbits2 = \ 146 - buf->timecode.userbits[2]; \ 147 - __entry->timecode_userbits3 = \ 148 - buf->timecode.userbits[3]; \ 149 - __entry->sequence = buf->sequence; \ 150 - ), \ 151 - \ 152 - TP_printk("minor = %d, index = %u, type = %s, " \ 153 - "bytesused = %u, flags = %s, " \ 154 - "field = %s, timestamp = %llu, timecode = { " \ 155 - "type = %s, flags = %s, frames = %u, " \ 156 - "seconds = %u, minutes = %u, hours = %u, " \ 157 - "userbits = { %u %u %u %u } }, " \ 158 - "sequence = %u", __entry->minor, \ 159 - __entry->index, show_type(__entry->type), \ 160 - __entry->bytesused, \ 161 - show_flags(__entry->flags), \ 162 - show_field(__entry->field), \ 163 - __entry->timestamp, \ 164 - show_timecode_type(__entry->timecode_type), \ 165 - show_timecode_flags(__entry->timecode_flags), \ 166 - __entry->timecode_frames, \ 167 - __entry->timecode_seconds, \ 168 - __entry->timecode_minutes, \ 169 - __entry->timecode_hours, \ 170 - __entry->timecode_userbits0, \ 171 - __entry->timecode_userbits1, \ 172 - __entry->timecode_userbits2, \ 173 - __entry->timecode_userbits3, \ 174 - __entry->sequence \ 175 - ) \ 176 - ) 96 + DECLARE_EVENT_CLASS(v4l2_event_class, 97 + TP_PROTO(int minor, struct v4l2_buffer *buf), 177 98 178 - V4L2_TRACE_EVENT(v4l2_dqbuf); 179 - V4L2_TRACE_EVENT(v4l2_qbuf); 99 + TP_ARGS(minor, buf), 100 + 101 + TP_STRUCT__entry( 102 + __field(int, minor) 103 + __field(u32, index) 104 + __field(u32, type) 105 + __field(u32, bytesused) 106 + __field(u32, flags) 107 + __field(u32, field) 108 + __field(s64, timestamp) 109 + __field(u32, timecode_type) 110 + __field(u32, timecode_flags) 111 + __field(u8, timecode_frames) 112 + __field(u8, timecode_seconds) 113 + __field(u8, timecode_minutes) 114 + __field(u8, timecode_hours) 115 + __field(u8, timecode_userbits0) 116 + __field(u8, timecode_userbits1) 117 + __field(u8, timecode_userbits2) 118 + __field(u8, timecode_userbits3) 119 + __field(u32, sequence) 120 + ), 121 + 122 + TP_fast_assign( 123 + __entry->minor = minor; 124 + __entry->index = buf->index; 125 + __entry->type = buf->type; 126 + __entry->bytesused = buf->bytesused; 127 + __entry->flags = buf->flags; 128 + __entry->field = buf->field; 129 + __entry->timestamp = timeval_to_ns(&buf->timestamp); 130 + __entry->timecode_type = buf->timecode.type; 131 + __entry->timecode_flags = buf->timecode.flags; 132 + __entry->timecode_frames = buf->timecode.frames; 133 + __entry->timecode_seconds = buf->timecode.seconds; 134 + __entry->timecode_minutes = buf->timecode.minutes; 135 + __entry->timecode_hours = buf->timecode.hours; 136 + __entry->timecode_userbits0 = buf->timecode.userbits[0]; 137 + __entry->timecode_userbits1 = buf->timecode.userbits[1]; 138 + __entry->timecode_userbits2 = buf->timecode.userbits[2]; 139 + __entry->timecode_userbits3 = buf->timecode.userbits[3]; 140 + __entry->sequence = buf->sequence; 141 + ), 142 + 143 + TP_printk("minor = %d, index = %u, type = %s, bytesused = %u, " 144 + "flags = %s, field = %s, timestamp = %llu, " 145 + "timecode = { type = %s, flags = %s, frames = %u, " 146 + "seconds = %u, minutes = %u, hours = %u, " 147 + "userbits = { %u %u %u %u } }, sequence = %u", __entry->minor, 148 + __entry->index, show_type(__entry->type), 149 + __entry->bytesused, 150 + show_flags(__entry->flags), 151 + show_field(__entry->field), 152 + __entry->timestamp, 153 + show_timecode_type(__entry->timecode_type), 154 + show_timecode_flags(__entry->timecode_flags), 155 + __entry->timecode_frames, 156 + __entry->timecode_seconds, 157 + __entry->timecode_minutes, 158 + __entry->timecode_hours, 159 + __entry->timecode_userbits0, 160 + __entry->timecode_userbits1, 161 + __entry->timecode_userbits2, 162 + __entry->timecode_userbits3, 163 + __entry->sequence 164 + ) 165 + ) 166 + 167 + DEFINE_EVENT(v4l2_event_class, v4l2_dqbuf, 168 + TP_PROTO(int minor, struct v4l2_buffer *buf), 169 + TP_ARGS(minor, buf) 170 + ); 171 + 172 + DEFINE_EVENT(v4l2_event_class, v4l2_qbuf, 173 + TP_PROTO(int minor, struct v4l2_buffer *buf), 174 + TP_ARGS(minor, buf) 175 + ); 176 + 177 + DECLARE_EVENT_CLASS(vb2_event_class, 178 + TP_PROTO(struct vb2_queue *q, struct vb2_buffer *vb), 179 + TP_ARGS(q, vb), 180 + 181 + TP_STRUCT__entry( 182 + __field(int, minor) 183 + __field(u32, queued_count) 184 + __field(int, owned_by_drv_count) 185 + __field(u32, index) 186 + __field(u32, type) 187 + __field(u32, bytesused) 188 + __field(u32, flags) 189 + __field(u32, field) 190 + __field(s64, timestamp) 191 + __field(u32, timecode_type) 192 + __field(u32, timecode_flags) 193 + __field(u8, timecode_frames) 194 + __field(u8, timecode_seconds) 195 + __field(u8, timecode_minutes) 196 + __field(u8, timecode_hours) 197 + __field(u8, timecode_userbits0) 198 + __field(u8, timecode_userbits1) 199 + __field(u8, timecode_userbits2) 200 + __field(u8, timecode_userbits3) 201 + __field(u32, sequence) 202 + ), 203 + 204 + TP_fast_assign( 205 + __entry->minor = q->owner ? q->owner->vdev->minor : -1; 206 + __entry->queued_count = q->queued_count; 207 + __entry->owned_by_drv_count = 208 + atomic_read(&q->owned_by_drv_count); 209 + __entry->index = vb->v4l2_buf.index; 210 + __entry->type = vb->v4l2_buf.type; 211 + __entry->bytesused = vb->v4l2_planes[0].bytesused; 212 + __entry->flags = vb->v4l2_buf.flags; 213 + __entry->field = vb->v4l2_buf.field; 214 + __entry->timestamp = timeval_to_ns(&vb->v4l2_buf.timestamp); 215 + __entry->timecode_type = vb->v4l2_buf.timecode.type; 216 + __entry->timecode_flags = vb->v4l2_buf.timecode.flags; 217 + __entry->timecode_frames = vb->v4l2_buf.timecode.frames; 218 + __entry->timecode_seconds = vb->v4l2_buf.timecode.seconds; 219 + __entry->timecode_minutes = vb->v4l2_buf.timecode.minutes; 220 + __entry->timecode_hours = vb->v4l2_buf.timecode.hours; 221 + __entry->timecode_userbits0 = vb->v4l2_buf.timecode.userbits[0]; 222 + __entry->timecode_userbits1 = vb->v4l2_buf.timecode.userbits[1]; 223 + __entry->timecode_userbits2 = vb->v4l2_buf.timecode.userbits[2]; 224 + __entry->timecode_userbits3 = vb->v4l2_buf.timecode.userbits[3]; 225 + __entry->sequence = vb->v4l2_buf.sequence; 226 + ), 227 + 228 + TP_printk("minor = %d, queued = %u, owned_by_drv = %d, index = %u, " 229 + "type = %s, bytesused = %u, flags = %s, field = %s, " 230 + "timestamp = %llu, timecode = { type = %s, flags = %s, " 231 + "frames = %u, seconds = %u, minutes = %u, hours = %u, " 232 + "userbits = { %u %u %u %u } }, sequence = %u", __entry->minor, 233 + __entry->queued_count, 234 + __entry->owned_by_drv_count, 235 + __entry->index, show_type(__entry->type), 236 + __entry->bytesused, 237 + show_flags(__entry->flags), 238 + show_field(__entry->field), 239 + __entry->timestamp, 240 + show_timecode_type(__entry->timecode_type), 241 + show_timecode_flags(__entry->timecode_flags), 242 + __entry->timecode_frames, 243 + __entry->timecode_seconds, 244 + __entry->timecode_minutes, 245 + __entry->timecode_hours, 246 + __entry->timecode_userbits0, 247 + __entry->timecode_userbits1, 248 + __entry->timecode_userbits2, 249 + __entry->timecode_userbits3, 250 + __entry->sequence 251 + ) 252 + ) 253 + 254 + DEFINE_EVENT(vb2_event_class, vb2_buf_done, 255 + TP_PROTO(struct vb2_queue *q, struct vb2_buffer *vb), 256 + TP_ARGS(q, vb) 257 + ); 258 + 259 + DEFINE_EVENT(vb2_event_class, vb2_buf_queue, 260 + TP_PROTO(struct vb2_queue *q, struct vb2_buffer *vb), 261 + TP_ARGS(q, vb) 262 + ); 263 + 264 + DEFINE_EVENT(vb2_event_class, vb2_dqbuf, 265 + TP_PROTO(struct vb2_queue *q, struct vb2_buffer *vb), 266 + TP_ARGS(q, vb) 267 + ); 268 + 269 + DEFINE_EVENT(vb2_event_class, vb2_qbuf, 270 + TP_PROTO(struct vb2_queue *q, struct vb2_buffer *vb), 271 + TP_ARGS(q, vb) 272 + ); 180 273 181 274 #endif /* if !defined(_TRACE_V4L2_H) || defined(TRACE_HEADER_MULTI_READ) */ 182 275
+4
include/uapi/linux/v4l2-controls.h
··· 174 174 * We reserve 16 controls for this driver. */ 175 175 #define V4L2_CID_USER_ADV7180_BASE (V4L2_CID_USER_BASE + 0x1070) 176 176 177 + /* The base for the tc358743 driver controls. 178 + * We reserve 16 controls for this driver. */ 179 + #define V4L2_CID_USER_TC358743_BASE (V4L2_CID_USER_BASE + 0x1080) 180 + 177 181 /* MPEG-class control IDs */ 178 182 /* The MPEG controls are applicable to all codec controls 179 183 * and the 'MPEG' part of the define is historical */
+1 -1
include/uapi/linux/vsp1.h
··· 28 28 _IOWR('V', BASE_VIDIOC_PRIVATE + 1, struct vsp1_lut_config) 29 29 30 30 struct vsp1_lut_config { 31 - u32 lut[256]; 31 + __u32 lut[256]; 32 32 }; 33 33 34 34 #endif /* __VSP1_USER_H__ */