Commit 76deaff8085304e9f6a4ce165b61ff467bbcd888
Committed by
Mauro Carvalho Chehab
1 parent
e5d49a3ef4
Exists in
ti-lsk-linux-4.1.y
and in
10 other branches
[media] rcar_vin: Add DT support for r8a7793 and r8a7794 SoCs
Based on platform device work by Matsuoka-san. Signed-off-by: Yoshihiro Kaneko <ykaneko0929@gmail.com> Signed-off-by: Guennadi Liakhovetski <g.liakhovetski@gmx.de> Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
Showing 2 changed files with 4 additions and 0 deletions Inline Diff
Documentation/devicetree/bindings/media/rcar_vin.txt
1 | Renesas RCar Video Input driver (rcar_vin) | 1 | Renesas RCar Video Input driver (rcar_vin) |
2 | ------------------------------------------ | 2 | ------------------------------------------ |
3 | 3 | ||
4 | The rcar_vin device provides video input capabilities for the Renesas R-Car | 4 | The rcar_vin device provides video input capabilities for the Renesas R-Car |
5 | family of devices. The current blocks are always slaves and suppot one input | 5 | family of devices. The current blocks are always slaves and suppot one input |
6 | channel which can be either RGB, YUYV or BT656. | 6 | channel which can be either RGB, YUYV or BT656. |
7 | 7 | ||
8 | - compatible: Must be one of the following | 8 | - compatible: Must be one of the following |
9 | - "renesas,vin-r8a7794" for the R8A7794 device | ||
10 | - "renesas,vin-r8a7793" for the R8A7793 device | ||
9 | - "renesas,vin-r8a7791" for the R8A7791 device | 11 | - "renesas,vin-r8a7791" for the R8A7791 device |
10 | - "renesas,vin-r8a7790" for the R8A7790 device | 12 | - "renesas,vin-r8a7790" for the R8A7790 device |
11 | - "renesas,vin-r8a7779" for the R8A7779 device | 13 | - "renesas,vin-r8a7779" for the R8A7779 device |
12 | - "renesas,vin-r8a7778" for the R8A7778 device | 14 | - "renesas,vin-r8a7778" for the R8A7778 device |
13 | - reg: the register base and size for the device registers | 15 | - reg: the register base and size for the device registers |
14 | - interrupts: the interrupt for the device | 16 | - interrupts: the interrupt for the device |
15 | - clocks: Reference to the parent clock | 17 | - clocks: Reference to the parent clock |
16 | 18 | ||
17 | Additionally, an alias named vinX will need to be created to specify | 19 | Additionally, an alias named vinX will need to be created to specify |
18 | which video input device this is. | 20 | which video input device this is. |
19 | 21 | ||
20 | The per-board settings: | 22 | The per-board settings: |
21 | - port sub-node describing a single endpoint connected to the vin | 23 | - port sub-node describing a single endpoint connected to the vin |
22 | as described in video-interfaces.txt[1]. Only the first one will | 24 | as described in video-interfaces.txt[1]. Only the first one will |
23 | be considered as each vin interface has one input port. | 25 | be considered as each vin interface has one input port. |
24 | 26 | ||
25 | These settings are used to work out video input format and widths | 27 | These settings are used to work out video input format and widths |
26 | into the system. | 28 | into the system. |
27 | 29 | ||
28 | 30 | ||
29 | Device node example | 31 | Device node example |
30 | ------------------- | 32 | ------------------- |
31 | 33 | ||
32 | aliases { | 34 | aliases { |
33 | vin0 = &vin0; | 35 | vin0 = &vin0; |
34 | }; | 36 | }; |
35 | 37 | ||
36 | vin0: vin@0xe6ef0000 { | 38 | vin0: vin@0xe6ef0000 { |
37 | compatible = "renesas,vin-r8a7790"; | 39 | compatible = "renesas,vin-r8a7790"; |
38 | clocks = <&mstp8_clks R8A7790_CLK_VIN0>; | 40 | clocks = <&mstp8_clks R8A7790_CLK_VIN0>; |
39 | reg = <0 0xe6ef0000 0 0x1000>; | 41 | reg = <0 0xe6ef0000 0 0x1000>; |
40 | interrupts = <0 188 IRQ_TYPE_LEVEL_HIGH>; | 42 | interrupts = <0 188 IRQ_TYPE_LEVEL_HIGH>; |
41 | status = "disabled"; | 43 | status = "disabled"; |
42 | }; | 44 | }; |
43 | 45 | ||
44 | Board setup example (vin1 composite video input) | 46 | Board setup example (vin1 composite video input) |
45 | ------------------------------------------------ | 47 | ------------------------------------------------ |
46 | 48 | ||
47 | &i2c2 { | 49 | &i2c2 { |
48 | status = "ok"; | 50 | status = "ok"; |
49 | pinctrl-0 = <&i2c2_pins>; | 51 | pinctrl-0 = <&i2c2_pins>; |
50 | pinctrl-names = "default"; | 52 | pinctrl-names = "default"; |
51 | 53 | ||
52 | adv7180@20 { | 54 | adv7180@20 { |
53 | compatible = "adi,adv7180"; | 55 | compatible = "adi,adv7180"; |
54 | reg = <0x20>; | 56 | reg = <0x20>; |
55 | remote = <&vin1>; | 57 | remote = <&vin1>; |
56 | 58 | ||
57 | port { | 59 | port { |
58 | adv7180: endpoint { | 60 | adv7180: endpoint { |
59 | bus-width = <8>; | 61 | bus-width = <8>; |
60 | remote-endpoint = <&vin1ep0>; | 62 | remote-endpoint = <&vin1ep0>; |
61 | }; | 63 | }; |
62 | }; | 64 | }; |
63 | }; | 65 | }; |
64 | }; | 66 | }; |
65 | 67 | ||
66 | /* composite video input */ | 68 | /* composite video input */ |
67 | &vin1 { | 69 | &vin1 { |
68 | pinctrl-0 = <&vin1_pins>; | 70 | pinctrl-0 = <&vin1_pins>; |
69 | pinctrl-names = "default"; | 71 | pinctrl-names = "default"; |
70 | 72 | ||
71 | status = "ok"; | 73 | status = "ok"; |
72 | 74 | ||
73 | port { | 75 | port { |
74 | #address-cells = <1>; | 76 | #address-cells = <1>; |
75 | #size-cells = <0>; | 77 | #size-cells = <0>; |
76 | 78 | ||
77 | vin1ep0: endpoint { | 79 | vin1ep0: endpoint { |
78 | remote-endpoint = <&adv7180>; | 80 | remote-endpoint = <&adv7180>; |
79 | bus-width = <8>; | 81 | bus-width = <8>; |
80 | }; | 82 | }; |
81 | }; | 83 | }; |
82 | }; | 84 | }; |
83 | 85 | ||
84 | 86 | ||
85 | 87 | ||
86 | [1] video-interfaces.txt common video media interface | 88 | [1] video-interfaces.txt common video media interface |
87 | 89 |
drivers/media/platform/soc_camera/rcar_vin.c
1 | /* | 1 | /* |
2 | * SoC-camera host driver for Renesas R-Car VIN unit | 2 | * SoC-camera host driver for Renesas R-Car VIN unit |
3 | * | 3 | * |
4 | * Copyright (C) 2011-2013 Renesas Solutions Corp. | 4 | * Copyright (C) 2011-2013 Renesas Solutions Corp. |
5 | * Copyright (C) 2013 Cogent Embedded, Inc., <source@cogentembedded.com> | 5 | * Copyright (C) 2013 Cogent Embedded, Inc., <source@cogentembedded.com> |
6 | * | 6 | * |
7 | * Based on V4L2 Driver for SuperH Mobile CEU interface "sh_mobile_ceu_camera.c" | 7 | * Based on V4L2 Driver for SuperH Mobile CEU interface "sh_mobile_ceu_camera.c" |
8 | * | 8 | * |
9 | * Copyright (C) 2008 Magnus Damm | 9 | * Copyright (C) 2008 Magnus Damm |
10 | * | 10 | * |
11 | * This program is free software; you can redistribute it and/or modify it | 11 | * This program is free software; you can redistribute it and/or modify it |
12 | * under the terms of the GNU General Public License as published by the | 12 | * under the terms of the GNU General Public License as published by the |
13 | * Free Software Foundation; either version 2 of the License, or (at your | 13 | * Free Software Foundation; either version 2 of the License, or (at your |
14 | * option) any later version. | 14 | * option) any later version. |
15 | */ | 15 | */ |
16 | 16 | ||
17 | #include <linux/delay.h> | 17 | #include <linux/delay.h> |
18 | #include <linux/interrupt.h> | 18 | #include <linux/interrupt.h> |
19 | #include <linux/io.h> | 19 | #include <linux/io.h> |
20 | #include <linux/kernel.h> | 20 | #include <linux/kernel.h> |
21 | #include <linux/module.h> | 21 | #include <linux/module.h> |
22 | #include <linux/of.h> | 22 | #include <linux/of.h> |
23 | #include <linux/of_device.h> | 23 | #include <linux/of_device.h> |
24 | #include <linux/platform_data/camera-rcar.h> | 24 | #include <linux/platform_data/camera-rcar.h> |
25 | #include <linux/platform_device.h> | 25 | #include <linux/platform_device.h> |
26 | #include <linux/pm_runtime.h> | 26 | #include <linux/pm_runtime.h> |
27 | #include <linux/slab.h> | 27 | #include <linux/slab.h> |
28 | #include <linux/videodev2.h> | 28 | #include <linux/videodev2.h> |
29 | 29 | ||
30 | #include <media/soc_camera.h> | 30 | #include <media/soc_camera.h> |
31 | #include <media/soc_mediabus.h> | 31 | #include <media/soc_mediabus.h> |
32 | #include <media/v4l2-common.h> | 32 | #include <media/v4l2-common.h> |
33 | #include <media/v4l2-dev.h> | 33 | #include <media/v4l2-dev.h> |
34 | #include <media/v4l2-device.h> | 34 | #include <media/v4l2-device.h> |
35 | #include <media/v4l2-mediabus.h> | 35 | #include <media/v4l2-mediabus.h> |
36 | #include <media/v4l2-of.h> | 36 | #include <media/v4l2-of.h> |
37 | #include <media/v4l2-subdev.h> | 37 | #include <media/v4l2-subdev.h> |
38 | #include <media/videobuf2-dma-contig.h> | 38 | #include <media/videobuf2-dma-contig.h> |
39 | 39 | ||
40 | #include "soc_scale_crop.h" | 40 | #include "soc_scale_crop.h" |
41 | 41 | ||
42 | #define DRV_NAME "rcar_vin" | 42 | #define DRV_NAME "rcar_vin" |
43 | 43 | ||
44 | /* Register offsets for R-Car VIN */ | 44 | /* Register offsets for R-Car VIN */ |
45 | #define VNMC_REG 0x00 /* Video n Main Control Register */ | 45 | #define VNMC_REG 0x00 /* Video n Main Control Register */ |
46 | #define VNMS_REG 0x04 /* Video n Module Status Register */ | 46 | #define VNMS_REG 0x04 /* Video n Module Status Register */ |
47 | #define VNFC_REG 0x08 /* Video n Frame Capture Register */ | 47 | #define VNFC_REG 0x08 /* Video n Frame Capture Register */ |
48 | #define VNSLPRC_REG 0x0C /* Video n Start Line Pre-Clip Register */ | 48 | #define VNSLPRC_REG 0x0C /* Video n Start Line Pre-Clip Register */ |
49 | #define VNELPRC_REG 0x10 /* Video n End Line Pre-Clip Register */ | 49 | #define VNELPRC_REG 0x10 /* Video n End Line Pre-Clip Register */ |
50 | #define VNSPPRC_REG 0x14 /* Video n Start Pixel Pre-Clip Register */ | 50 | #define VNSPPRC_REG 0x14 /* Video n Start Pixel Pre-Clip Register */ |
51 | #define VNEPPRC_REG 0x18 /* Video n End Pixel Pre-Clip Register */ | 51 | #define VNEPPRC_REG 0x18 /* Video n End Pixel Pre-Clip Register */ |
52 | #define VNSLPOC_REG 0x1C /* Video n Start Line Post-Clip Register */ | 52 | #define VNSLPOC_REG 0x1C /* Video n Start Line Post-Clip Register */ |
53 | #define VNELPOC_REG 0x20 /* Video n End Line Post-Clip Register */ | 53 | #define VNELPOC_REG 0x20 /* Video n End Line Post-Clip Register */ |
54 | #define VNSPPOC_REG 0x24 /* Video n Start Pixel Post-Clip Register */ | 54 | #define VNSPPOC_REG 0x24 /* Video n Start Pixel Post-Clip Register */ |
55 | #define VNEPPOC_REG 0x28 /* Video n End Pixel Post-Clip Register */ | 55 | #define VNEPPOC_REG 0x28 /* Video n End Pixel Post-Clip Register */ |
56 | #define VNIS_REG 0x2C /* Video n Image Stride Register */ | 56 | #define VNIS_REG 0x2C /* Video n Image Stride Register */ |
57 | #define VNMB_REG(m) (0x30 + ((m) << 2)) /* Video n Memory Base m Register */ | 57 | #define VNMB_REG(m) (0x30 + ((m) << 2)) /* Video n Memory Base m Register */ |
58 | #define VNIE_REG 0x40 /* Video n Interrupt Enable Register */ | 58 | #define VNIE_REG 0x40 /* Video n Interrupt Enable Register */ |
59 | #define VNINTS_REG 0x44 /* Video n Interrupt Status Register */ | 59 | #define VNINTS_REG 0x44 /* Video n Interrupt Status Register */ |
60 | #define VNSI_REG 0x48 /* Video n Scanline Interrupt Register */ | 60 | #define VNSI_REG 0x48 /* Video n Scanline Interrupt Register */ |
61 | #define VNMTC_REG 0x4C /* Video n Memory Transfer Control Register */ | 61 | #define VNMTC_REG 0x4C /* Video n Memory Transfer Control Register */ |
62 | #define VNYS_REG 0x50 /* Video n Y Scale Register */ | 62 | #define VNYS_REG 0x50 /* Video n Y Scale Register */ |
63 | #define VNXS_REG 0x54 /* Video n X Scale Register */ | 63 | #define VNXS_REG 0x54 /* Video n X Scale Register */ |
64 | #define VNDMR_REG 0x58 /* Video n Data Mode Register */ | 64 | #define VNDMR_REG 0x58 /* Video n Data Mode Register */ |
65 | #define VNDMR2_REG 0x5C /* Video n Data Mode Register 2 */ | 65 | #define VNDMR2_REG 0x5C /* Video n Data Mode Register 2 */ |
66 | #define VNUVAOF_REG 0x60 /* Video n UV Address Offset Register */ | 66 | #define VNUVAOF_REG 0x60 /* Video n UV Address Offset Register */ |
67 | 67 | ||
68 | /* Register bit fields for R-Car VIN */ | 68 | /* Register bit fields for R-Car VIN */ |
69 | /* Video n Main Control Register bits */ | 69 | /* Video n Main Control Register bits */ |
70 | #define VNMC_FOC (1 << 21) | 70 | #define VNMC_FOC (1 << 21) |
71 | #define VNMC_YCAL (1 << 19) | 71 | #define VNMC_YCAL (1 << 19) |
72 | #define VNMC_INF_YUV8_BT656 (0 << 16) | 72 | #define VNMC_INF_YUV8_BT656 (0 << 16) |
73 | #define VNMC_INF_YUV8_BT601 (1 << 16) | 73 | #define VNMC_INF_YUV8_BT601 (1 << 16) |
74 | #define VNMC_INF_YUV10_BT656 (2 << 16) | 74 | #define VNMC_INF_YUV10_BT656 (2 << 16) |
75 | #define VNMC_INF_YUV10_BT601 (3 << 16) | 75 | #define VNMC_INF_YUV10_BT601 (3 << 16) |
76 | #define VNMC_INF_YUV16 (5 << 16) | 76 | #define VNMC_INF_YUV16 (5 << 16) |
77 | #define VNMC_VUP (1 << 10) | 77 | #define VNMC_VUP (1 << 10) |
78 | #define VNMC_IM_ODD (0 << 3) | 78 | #define VNMC_IM_ODD (0 << 3) |
79 | #define VNMC_IM_ODD_EVEN (1 << 3) | 79 | #define VNMC_IM_ODD_EVEN (1 << 3) |
80 | #define VNMC_IM_EVEN (2 << 3) | 80 | #define VNMC_IM_EVEN (2 << 3) |
81 | #define VNMC_IM_FULL (3 << 3) | 81 | #define VNMC_IM_FULL (3 << 3) |
82 | #define VNMC_BPS (1 << 1) | 82 | #define VNMC_BPS (1 << 1) |
83 | #define VNMC_ME (1 << 0) | 83 | #define VNMC_ME (1 << 0) |
84 | 84 | ||
85 | /* Video n Module Status Register bits */ | 85 | /* Video n Module Status Register bits */ |
86 | #define VNMS_FBS_MASK (3 << 3) | 86 | #define VNMS_FBS_MASK (3 << 3) |
87 | #define VNMS_FBS_SHIFT 3 | 87 | #define VNMS_FBS_SHIFT 3 |
88 | #define VNMS_AV (1 << 1) | 88 | #define VNMS_AV (1 << 1) |
89 | #define VNMS_CA (1 << 0) | 89 | #define VNMS_CA (1 << 0) |
90 | 90 | ||
91 | /* Video n Frame Capture Register bits */ | 91 | /* Video n Frame Capture Register bits */ |
92 | #define VNFC_C_FRAME (1 << 1) | 92 | #define VNFC_C_FRAME (1 << 1) |
93 | #define VNFC_S_FRAME (1 << 0) | 93 | #define VNFC_S_FRAME (1 << 0) |
94 | 94 | ||
95 | /* Video n Interrupt Enable Register bits */ | 95 | /* Video n Interrupt Enable Register bits */ |
96 | #define VNIE_FIE (1 << 4) | 96 | #define VNIE_FIE (1 << 4) |
97 | #define VNIE_EFE (1 << 1) | 97 | #define VNIE_EFE (1 << 1) |
98 | 98 | ||
99 | /* Video n Data Mode Register bits */ | 99 | /* Video n Data Mode Register bits */ |
100 | #define VNDMR_EXRGB (1 << 8) | 100 | #define VNDMR_EXRGB (1 << 8) |
101 | #define VNDMR_BPSM (1 << 4) | 101 | #define VNDMR_BPSM (1 << 4) |
102 | #define VNDMR_DTMD_YCSEP (1 << 1) | 102 | #define VNDMR_DTMD_YCSEP (1 << 1) |
103 | #define VNDMR_DTMD_ARGB1555 (1 << 0) | 103 | #define VNDMR_DTMD_ARGB1555 (1 << 0) |
104 | 104 | ||
105 | /* Video n Data Mode Register 2 bits */ | 105 | /* Video n Data Mode Register 2 bits */ |
106 | #define VNDMR2_VPS (1 << 30) | 106 | #define VNDMR2_VPS (1 << 30) |
107 | #define VNDMR2_HPS (1 << 29) | 107 | #define VNDMR2_HPS (1 << 29) |
108 | #define VNDMR2_FTEV (1 << 17) | 108 | #define VNDMR2_FTEV (1 << 17) |
109 | 109 | ||
110 | #define VIN_MAX_WIDTH 2048 | 110 | #define VIN_MAX_WIDTH 2048 |
111 | #define VIN_MAX_HEIGHT 2048 | 111 | #define VIN_MAX_HEIGHT 2048 |
112 | 112 | ||
113 | enum chip_id { | 113 | enum chip_id { |
114 | RCAR_GEN2, | 114 | RCAR_GEN2, |
115 | RCAR_H1, | 115 | RCAR_H1, |
116 | RCAR_M1, | 116 | RCAR_M1, |
117 | RCAR_E1, | 117 | RCAR_E1, |
118 | }; | 118 | }; |
119 | 119 | ||
120 | enum rcar_vin_state { | 120 | enum rcar_vin_state { |
121 | STOPPED = 0, | 121 | STOPPED = 0, |
122 | RUNNING, | 122 | RUNNING, |
123 | STOPPING, | 123 | STOPPING, |
124 | }; | 124 | }; |
125 | 125 | ||
126 | struct rcar_vin_priv { | 126 | struct rcar_vin_priv { |
127 | void __iomem *base; | 127 | void __iomem *base; |
128 | spinlock_t lock; | 128 | spinlock_t lock; |
129 | int sequence; | 129 | int sequence; |
130 | /* State of the VIN module in capturing mode */ | 130 | /* State of the VIN module in capturing mode */ |
131 | enum rcar_vin_state state; | 131 | enum rcar_vin_state state; |
132 | struct soc_camera_host ici; | 132 | struct soc_camera_host ici; |
133 | struct list_head capture; | 133 | struct list_head capture; |
134 | #define MAX_BUFFER_NUM 3 | 134 | #define MAX_BUFFER_NUM 3 |
135 | struct vb2_buffer *queue_buf[MAX_BUFFER_NUM]; | 135 | struct vb2_buffer *queue_buf[MAX_BUFFER_NUM]; |
136 | struct vb2_alloc_ctx *alloc_ctx; | 136 | struct vb2_alloc_ctx *alloc_ctx; |
137 | enum v4l2_field field; | 137 | enum v4l2_field field; |
138 | unsigned int pdata_flags; | 138 | unsigned int pdata_flags; |
139 | unsigned int vb_count; | 139 | unsigned int vb_count; |
140 | unsigned int nr_hw_slots; | 140 | unsigned int nr_hw_slots; |
141 | bool request_to_stop; | 141 | bool request_to_stop; |
142 | struct completion capture_stop; | 142 | struct completion capture_stop; |
143 | enum chip_id chip; | 143 | enum chip_id chip; |
144 | }; | 144 | }; |
145 | 145 | ||
146 | #define is_continuous_transfer(priv) (priv->vb_count > MAX_BUFFER_NUM) | 146 | #define is_continuous_transfer(priv) (priv->vb_count > MAX_BUFFER_NUM) |
147 | 147 | ||
148 | struct rcar_vin_buffer { | 148 | struct rcar_vin_buffer { |
149 | struct vb2_buffer vb; | 149 | struct vb2_buffer vb; |
150 | struct list_head list; | 150 | struct list_head list; |
151 | }; | 151 | }; |
152 | 152 | ||
153 | #define to_buf_list(vb2_buffer) (&container_of(vb2_buffer, \ | 153 | #define to_buf_list(vb2_buffer) (&container_of(vb2_buffer, \ |
154 | struct rcar_vin_buffer, \ | 154 | struct rcar_vin_buffer, \ |
155 | vb)->list) | 155 | vb)->list) |
156 | 156 | ||
157 | struct rcar_vin_cam { | 157 | struct rcar_vin_cam { |
158 | /* VIN offsets within the camera output, before the VIN scaler */ | 158 | /* VIN offsets within the camera output, before the VIN scaler */ |
159 | unsigned int vin_left; | 159 | unsigned int vin_left; |
160 | unsigned int vin_top; | 160 | unsigned int vin_top; |
161 | /* Client output, as seen by the VIN */ | 161 | /* Client output, as seen by the VIN */ |
162 | unsigned int width; | 162 | unsigned int width; |
163 | unsigned int height; | 163 | unsigned int height; |
164 | /* | 164 | /* |
165 | * User window from S_CROP / G_CROP, produced by client cropping and | 165 | * User window from S_CROP / G_CROP, produced by client cropping and |
166 | * scaling, VIN scaling and VIN cropping, mapped back onto the client | 166 | * scaling, VIN scaling and VIN cropping, mapped back onto the client |
167 | * input window | 167 | * input window |
168 | */ | 168 | */ |
169 | struct v4l2_rect subrect; | 169 | struct v4l2_rect subrect; |
170 | /* Camera cropping rectangle */ | 170 | /* Camera cropping rectangle */ |
171 | struct v4l2_rect rect; | 171 | struct v4l2_rect rect; |
172 | const struct soc_mbus_pixelfmt *extra_fmt; | 172 | const struct soc_mbus_pixelfmt *extra_fmt; |
173 | }; | 173 | }; |
174 | 174 | ||
175 | /* | 175 | /* |
176 | * .queue_setup() is called to check whether the driver can accept the requested | 176 | * .queue_setup() is called to check whether the driver can accept the requested |
177 | * number of buffers and to fill in plane sizes for the current frame format if | 177 | * number of buffers and to fill in plane sizes for the current frame format if |
178 | * required | 178 | * required |
179 | */ | 179 | */ |
180 | static int rcar_vin_videobuf_setup(struct vb2_queue *vq, | 180 | static int rcar_vin_videobuf_setup(struct vb2_queue *vq, |
181 | const struct v4l2_format *fmt, | 181 | const struct v4l2_format *fmt, |
182 | unsigned int *count, | 182 | unsigned int *count, |
183 | unsigned int *num_planes, | 183 | unsigned int *num_planes, |
184 | unsigned int sizes[], void *alloc_ctxs[]) | 184 | unsigned int sizes[], void *alloc_ctxs[]) |
185 | { | 185 | { |
186 | struct soc_camera_device *icd = soc_camera_from_vb2q(vq); | 186 | struct soc_camera_device *icd = soc_camera_from_vb2q(vq); |
187 | struct soc_camera_host *ici = to_soc_camera_host(icd->parent); | 187 | struct soc_camera_host *ici = to_soc_camera_host(icd->parent); |
188 | struct rcar_vin_priv *priv = ici->priv; | 188 | struct rcar_vin_priv *priv = ici->priv; |
189 | 189 | ||
190 | if (fmt) { | 190 | if (fmt) { |
191 | const struct soc_camera_format_xlate *xlate; | 191 | const struct soc_camera_format_xlate *xlate; |
192 | unsigned int bytes_per_line; | 192 | unsigned int bytes_per_line; |
193 | int ret; | 193 | int ret; |
194 | 194 | ||
195 | xlate = soc_camera_xlate_by_fourcc(icd, | 195 | xlate = soc_camera_xlate_by_fourcc(icd, |
196 | fmt->fmt.pix.pixelformat); | 196 | fmt->fmt.pix.pixelformat); |
197 | if (!xlate) | 197 | if (!xlate) |
198 | return -EINVAL; | 198 | return -EINVAL; |
199 | ret = soc_mbus_bytes_per_line(fmt->fmt.pix.width, | 199 | ret = soc_mbus_bytes_per_line(fmt->fmt.pix.width, |
200 | xlate->host_fmt); | 200 | xlate->host_fmt); |
201 | if (ret < 0) | 201 | if (ret < 0) |
202 | return ret; | 202 | return ret; |
203 | 203 | ||
204 | bytes_per_line = max_t(u32, fmt->fmt.pix.bytesperline, ret); | 204 | bytes_per_line = max_t(u32, fmt->fmt.pix.bytesperline, ret); |
205 | 205 | ||
206 | ret = soc_mbus_image_size(xlate->host_fmt, bytes_per_line, | 206 | ret = soc_mbus_image_size(xlate->host_fmt, bytes_per_line, |
207 | fmt->fmt.pix.height); | 207 | fmt->fmt.pix.height); |
208 | if (ret < 0) | 208 | if (ret < 0) |
209 | return ret; | 209 | return ret; |
210 | 210 | ||
211 | sizes[0] = max_t(u32, fmt->fmt.pix.sizeimage, ret); | 211 | sizes[0] = max_t(u32, fmt->fmt.pix.sizeimage, ret); |
212 | } else { | 212 | } else { |
213 | /* Called from VIDIOC_REQBUFS or in compatibility mode */ | 213 | /* Called from VIDIOC_REQBUFS or in compatibility mode */ |
214 | sizes[0] = icd->sizeimage; | 214 | sizes[0] = icd->sizeimage; |
215 | } | 215 | } |
216 | 216 | ||
217 | alloc_ctxs[0] = priv->alloc_ctx; | 217 | alloc_ctxs[0] = priv->alloc_ctx; |
218 | 218 | ||
219 | if (!vq->num_buffers) | 219 | if (!vq->num_buffers) |
220 | priv->sequence = 0; | 220 | priv->sequence = 0; |
221 | 221 | ||
222 | if (!*count) | 222 | if (!*count) |
223 | *count = 2; | 223 | *count = 2; |
224 | priv->vb_count = *count; | 224 | priv->vb_count = *count; |
225 | 225 | ||
226 | *num_planes = 1; | 226 | *num_planes = 1; |
227 | 227 | ||
228 | /* Number of hardware slots */ | 228 | /* Number of hardware slots */ |
229 | if (is_continuous_transfer(priv)) | 229 | if (is_continuous_transfer(priv)) |
230 | priv->nr_hw_slots = MAX_BUFFER_NUM; | 230 | priv->nr_hw_slots = MAX_BUFFER_NUM; |
231 | else | 231 | else |
232 | priv->nr_hw_slots = 1; | 232 | priv->nr_hw_slots = 1; |
233 | 233 | ||
234 | dev_dbg(icd->parent, "count=%d, size=%u\n", *count, sizes[0]); | 234 | dev_dbg(icd->parent, "count=%d, size=%u\n", *count, sizes[0]); |
235 | 235 | ||
236 | return 0; | 236 | return 0; |
237 | } | 237 | } |
238 | 238 | ||
239 | static int rcar_vin_setup(struct rcar_vin_priv *priv) | 239 | static int rcar_vin_setup(struct rcar_vin_priv *priv) |
240 | { | 240 | { |
241 | struct soc_camera_device *icd = priv->ici.icd; | 241 | struct soc_camera_device *icd = priv->ici.icd; |
242 | struct rcar_vin_cam *cam = icd->host_priv; | 242 | struct rcar_vin_cam *cam = icd->host_priv; |
243 | u32 vnmc, dmr, interrupts; | 243 | u32 vnmc, dmr, interrupts; |
244 | bool progressive = false, output_is_yuv = false; | 244 | bool progressive = false, output_is_yuv = false; |
245 | 245 | ||
246 | switch (priv->field) { | 246 | switch (priv->field) { |
247 | case V4L2_FIELD_TOP: | 247 | case V4L2_FIELD_TOP: |
248 | vnmc = VNMC_IM_ODD; | 248 | vnmc = VNMC_IM_ODD; |
249 | break; | 249 | break; |
250 | case V4L2_FIELD_BOTTOM: | 250 | case V4L2_FIELD_BOTTOM: |
251 | vnmc = VNMC_IM_EVEN; | 251 | vnmc = VNMC_IM_EVEN; |
252 | break; | 252 | break; |
253 | case V4L2_FIELD_INTERLACED: | 253 | case V4L2_FIELD_INTERLACED: |
254 | case V4L2_FIELD_INTERLACED_TB: | 254 | case V4L2_FIELD_INTERLACED_TB: |
255 | vnmc = VNMC_IM_FULL; | 255 | vnmc = VNMC_IM_FULL; |
256 | break; | 256 | break; |
257 | case V4L2_FIELD_INTERLACED_BT: | 257 | case V4L2_FIELD_INTERLACED_BT: |
258 | vnmc = VNMC_IM_FULL | VNMC_FOC; | 258 | vnmc = VNMC_IM_FULL | VNMC_FOC; |
259 | break; | 259 | break; |
260 | case V4L2_FIELD_NONE: | 260 | case V4L2_FIELD_NONE: |
261 | if (is_continuous_transfer(priv)) { | 261 | if (is_continuous_transfer(priv)) { |
262 | vnmc = VNMC_IM_ODD_EVEN; | 262 | vnmc = VNMC_IM_ODD_EVEN; |
263 | progressive = true; | 263 | progressive = true; |
264 | } else { | 264 | } else { |
265 | vnmc = VNMC_IM_ODD; | 265 | vnmc = VNMC_IM_ODD; |
266 | } | 266 | } |
267 | break; | 267 | break; |
268 | default: | 268 | default: |
269 | vnmc = VNMC_IM_ODD; | 269 | vnmc = VNMC_IM_ODD; |
270 | break; | 270 | break; |
271 | } | 271 | } |
272 | 272 | ||
273 | /* input interface */ | 273 | /* input interface */ |
274 | switch (icd->current_fmt->code) { | 274 | switch (icd->current_fmt->code) { |
275 | case MEDIA_BUS_FMT_YUYV8_1X16: | 275 | case MEDIA_BUS_FMT_YUYV8_1X16: |
276 | /* BT.601/BT.1358 16bit YCbCr422 */ | 276 | /* BT.601/BT.1358 16bit YCbCr422 */ |
277 | vnmc |= VNMC_INF_YUV16; | 277 | vnmc |= VNMC_INF_YUV16; |
278 | break; | 278 | break; |
279 | case MEDIA_BUS_FMT_YUYV8_2X8: | 279 | case MEDIA_BUS_FMT_YUYV8_2X8: |
280 | /* BT.656 8bit YCbCr422 or BT.601 8bit YCbCr422 */ | 280 | /* BT.656 8bit YCbCr422 or BT.601 8bit YCbCr422 */ |
281 | vnmc |= priv->pdata_flags & RCAR_VIN_BT656 ? | 281 | vnmc |= priv->pdata_flags & RCAR_VIN_BT656 ? |
282 | VNMC_INF_YUV8_BT656 : VNMC_INF_YUV8_BT601; | 282 | VNMC_INF_YUV8_BT656 : VNMC_INF_YUV8_BT601; |
283 | break; | 283 | break; |
284 | case MEDIA_BUS_FMT_YUYV10_2X10: | 284 | case MEDIA_BUS_FMT_YUYV10_2X10: |
285 | /* BT.656 10bit YCbCr422 or BT.601 10bit YCbCr422 */ | 285 | /* BT.656 10bit YCbCr422 or BT.601 10bit YCbCr422 */ |
286 | vnmc |= priv->pdata_flags & RCAR_VIN_BT656 ? | 286 | vnmc |= priv->pdata_flags & RCAR_VIN_BT656 ? |
287 | VNMC_INF_YUV10_BT656 : VNMC_INF_YUV10_BT601; | 287 | VNMC_INF_YUV10_BT656 : VNMC_INF_YUV10_BT601; |
288 | break; | 288 | break; |
289 | default: | 289 | default: |
290 | break; | 290 | break; |
291 | } | 291 | } |
292 | 292 | ||
293 | /* output format */ | 293 | /* output format */ |
294 | switch (icd->current_fmt->host_fmt->fourcc) { | 294 | switch (icd->current_fmt->host_fmt->fourcc) { |
295 | case V4L2_PIX_FMT_NV16: | 295 | case V4L2_PIX_FMT_NV16: |
296 | iowrite32(ALIGN(cam->width * cam->height, 0x80), | 296 | iowrite32(ALIGN(cam->width * cam->height, 0x80), |
297 | priv->base + VNUVAOF_REG); | 297 | priv->base + VNUVAOF_REG); |
298 | dmr = VNDMR_DTMD_YCSEP; | 298 | dmr = VNDMR_DTMD_YCSEP; |
299 | output_is_yuv = true; | 299 | output_is_yuv = true; |
300 | break; | 300 | break; |
301 | case V4L2_PIX_FMT_YUYV: | 301 | case V4L2_PIX_FMT_YUYV: |
302 | dmr = VNDMR_BPSM; | 302 | dmr = VNDMR_BPSM; |
303 | output_is_yuv = true; | 303 | output_is_yuv = true; |
304 | break; | 304 | break; |
305 | case V4L2_PIX_FMT_UYVY: | 305 | case V4L2_PIX_FMT_UYVY: |
306 | dmr = 0; | 306 | dmr = 0; |
307 | output_is_yuv = true; | 307 | output_is_yuv = true; |
308 | break; | 308 | break; |
309 | case V4L2_PIX_FMT_RGB555X: | 309 | case V4L2_PIX_FMT_RGB555X: |
310 | dmr = VNDMR_DTMD_ARGB1555; | 310 | dmr = VNDMR_DTMD_ARGB1555; |
311 | break; | 311 | break; |
312 | case V4L2_PIX_FMT_RGB565: | 312 | case V4L2_PIX_FMT_RGB565: |
313 | dmr = 0; | 313 | dmr = 0; |
314 | break; | 314 | break; |
315 | case V4L2_PIX_FMT_RGB32: | 315 | case V4L2_PIX_FMT_RGB32: |
316 | if (priv->chip == RCAR_GEN2 || priv->chip == RCAR_H1 || | 316 | if (priv->chip == RCAR_GEN2 || priv->chip == RCAR_H1 || |
317 | priv->chip == RCAR_E1) { | 317 | priv->chip == RCAR_E1) { |
318 | dmr = VNDMR_EXRGB; | 318 | dmr = VNDMR_EXRGB; |
319 | break; | 319 | break; |
320 | } | 320 | } |
321 | default: | 321 | default: |
322 | dev_warn(icd->parent, "Invalid fourcc format (0x%x)\n", | 322 | dev_warn(icd->parent, "Invalid fourcc format (0x%x)\n", |
323 | icd->current_fmt->host_fmt->fourcc); | 323 | icd->current_fmt->host_fmt->fourcc); |
324 | return -EINVAL; | 324 | return -EINVAL; |
325 | } | 325 | } |
326 | 326 | ||
327 | /* Always update on field change */ | 327 | /* Always update on field change */ |
328 | vnmc |= VNMC_VUP; | 328 | vnmc |= VNMC_VUP; |
329 | 329 | ||
330 | /* If input and output use the same colorspace, use bypass mode */ | 330 | /* If input and output use the same colorspace, use bypass mode */ |
331 | if (output_is_yuv) | 331 | if (output_is_yuv) |
332 | vnmc |= VNMC_BPS; | 332 | vnmc |= VNMC_BPS; |
333 | 333 | ||
334 | /* progressive or interlaced mode */ | 334 | /* progressive or interlaced mode */ |
335 | interrupts = progressive ? VNIE_FIE | VNIE_EFE : VNIE_EFE; | 335 | interrupts = progressive ? VNIE_FIE | VNIE_EFE : VNIE_EFE; |
336 | 336 | ||
337 | /* ack interrupts */ | 337 | /* ack interrupts */ |
338 | iowrite32(interrupts, priv->base + VNINTS_REG); | 338 | iowrite32(interrupts, priv->base + VNINTS_REG); |
339 | /* enable interrupts */ | 339 | /* enable interrupts */ |
340 | iowrite32(interrupts, priv->base + VNIE_REG); | 340 | iowrite32(interrupts, priv->base + VNIE_REG); |
341 | /* start capturing */ | 341 | /* start capturing */ |
342 | iowrite32(dmr, priv->base + VNDMR_REG); | 342 | iowrite32(dmr, priv->base + VNDMR_REG); |
343 | iowrite32(vnmc | VNMC_ME, priv->base + VNMC_REG); | 343 | iowrite32(vnmc | VNMC_ME, priv->base + VNMC_REG); |
344 | 344 | ||
345 | return 0; | 345 | return 0; |
346 | } | 346 | } |
347 | 347 | ||
348 | static void rcar_vin_capture(struct rcar_vin_priv *priv) | 348 | static void rcar_vin_capture(struct rcar_vin_priv *priv) |
349 | { | 349 | { |
350 | if (is_continuous_transfer(priv)) | 350 | if (is_continuous_transfer(priv)) |
351 | /* Continuous Frame Capture Mode */ | 351 | /* Continuous Frame Capture Mode */ |
352 | iowrite32(VNFC_C_FRAME, priv->base + VNFC_REG); | 352 | iowrite32(VNFC_C_FRAME, priv->base + VNFC_REG); |
353 | else | 353 | else |
354 | /* Single Frame Capture Mode */ | 354 | /* Single Frame Capture Mode */ |
355 | iowrite32(VNFC_S_FRAME, priv->base + VNFC_REG); | 355 | iowrite32(VNFC_S_FRAME, priv->base + VNFC_REG); |
356 | } | 356 | } |
357 | 357 | ||
358 | static void rcar_vin_request_capture_stop(struct rcar_vin_priv *priv) | 358 | static void rcar_vin_request_capture_stop(struct rcar_vin_priv *priv) |
359 | { | 359 | { |
360 | priv->state = STOPPING; | 360 | priv->state = STOPPING; |
361 | 361 | ||
362 | /* set continuous & single transfer off */ | 362 | /* set continuous & single transfer off */ |
363 | iowrite32(0, priv->base + VNFC_REG); | 363 | iowrite32(0, priv->base + VNFC_REG); |
364 | /* disable capture (release DMA buffer), reset */ | 364 | /* disable capture (release DMA buffer), reset */ |
365 | iowrite32(ioread32(priv->base + VNMC_REG) & ~VNMC_ME, | 365 | iowrite32(ioread32(priv->base + VNMC_REG) & ~VNMC_ME, |
366 | priv->base + VNMC_REG); | 366 | priv->base + VNMC_REG); |
367 | 367 | ||
368 | /* update the status if stopped already */ | 368 | /* update the status if stopped already */ |
369 | if (!(ioread32(priv->base + VNMS_REG) & VNMS_CA)) | 369 | if (!(ioread32(priv->base + VNMS_REG) & VNMS_CA)) |
370 | priv->state = STOPPED; | 370 | priv->state = STOPPED; |
371 | } | 371 | } |
372 | 372 | ||
373 | static int rcar_vin_get_free_hw_slot(struct rcar_vin_priv *priv) | 373 | static int rcar_vin_get_free_hw_slot(struct rcar_vin_priv *priv) |
374 | { | 374 | { |
375 | int slot; | 375 | int slot; |
376 | 376 | ||
377 | for (slot = 0; slot < priv->nr_hw_slots; slot++) | 377 | for (slot = 0; slot < priv->nr_hw_slots; slot++) |
378 | if (priv->queue_buf[slot] == NULL) | 378 | if (priv->queue_buf[slot] == NULL) |
379 | return slot; | 379 | return slot; |
380 | 380 | ||
381 | return -1; | 381 | return -1; |
382 | } | 382 | } |
383 | 383 | ||
384 | static int rcar_vin_hw_ready(struct rcar_vin_priv *priv) | 384 | static int rcar_vin_hw_ready(struct rcar_vin_priv *priv) |
385 | { | 385 | { |
386 | /* Ensure all HW slots are filled */ | 386 | /* Ensure all HW slots are filled */ |
387 | return rcar_vin_get_free_hw_slot(priv) < 0 ? 1 : 0; | 387 | return rcar_vin_get_free_hw_slot(priv) < 0 ? 1 : 0; |
388 | } | 388 | } |
389 | 389 | ||
390 | /* Moves a buffer from the queue to the HW slots */ | 390 | /* Moves a buffer from the queue to the HW slots */ |
391 | static int rcar_vin_fill_hw_slot(struct rcar_vin_priv *priv) | 391 | static int rcar_vin_fill_hw_slot(struct rcar_vin_priv *priv) |
392 | { | 392 | { |
393 | struct vb2_buffer *vb; | 393 | struct vb2_buffer *vb; |
394 | dma_addr_t phys_addr_top; | 394 | dma_addr_t phys_addr_top; |
395 | int slot; | 395 | int slot; |
396 | 396 | ||
397 | if (list_empty(&priv->capture)) | 397 | if (list_empty(&priv->capture)) |
398 | return 0; | 398 | return 0; |
399 | 399 | ||
400 | /* Find a free HW slot */ | 400 | /* Find a free HW slot */ |
401 | slot = rcar_vin_get_free_hw_slot(priv); | 401 | slot = rcar_vin_get_free_hw_slot(priv); |
402 | if (slot < 0) | 402 | if (slot < 0) |
403 | return 0; | 403 | return 0; |
404 | 404 | ||
405 | vb = &list_entry(priv->capture.next, struct rcar_vin_buffer, list)->vb; | 405 | vb = &list_entry(priv->capture.next, struct rcar_vin_buffer, list)->vb; |
406 | list_del_init(to_buf_list(vb)); | 406 | list_del_init(to_buf_list(vb)); |
407 | priv->queue_buf[slot] = vb; | 407 | priv->queue_buf[slot] = vb; |
408 | phys_addr_top = vb2_dma_contig_plane_dma_addr(vb, 0); | 408 | phys_addr_top = vb2_dma_contig_plane_dma_addr(vb, 0); |
409 | iowrite32(phys_addr_top, priv->base + VNMB_REG(slot)); | 409 | iowrite32(phys_addr_top, priv->base + VNMB_REG(slot)); |
410 | 410 | ||
411 | return 1; | 411 | return 1; |
412 | } | 412 | } |
413 | 413 | ||
414 | static void rcar_vin_videobuf_queue(struct vb2_buffer *vb) | 414 | static void rcar_vin_videobuf_queue(struct vb2_buffer *vb) |
415 | { | 415 | { |
416 | struct soc_camera_device *icd = soc_camera_from_vb2q(vb->vb2_queue); | 416 | struct soc_camera_device *icd = soc_camera_from_vb2q(vb->vb2_queue); |
417 | struct soc_camera_host *ici = to_soc_camera_host(icd->parent); | 417 | struct soc_camera_host *ici = to_soc_camera_host(icd->parent); |
418 | struct rcar_vin_priv *priv = ici->priv; | 418 | struct rcar_vin_priv *priv = ici->priv; |
419 | unsigned long size; | 419 | unsigned long size; |
420 | 420 | ||
421 | size = icd->sizeimage; | 421 | size = icd->sizeimage; |
422 | 422 | ||
423 | if (vb2_plane_size(vb, 0) < size) { | 423 | if (vb2_plane_size(vb, 0) < size) { |
424 | dev_err(icd->parent, "Buffer #%d too small (%lu < %lu)\n", | 424 | dev_err(icd->parent, "Buffer #%d too small (%lu < %lu)\n", |
425 | vb->v4l2_buf.index, vb2_plane_size(vb, 0), size); | 425 | vb->v4l2_buf.index, vb2_plane_size(vb, 0), size); |
426 | goto error; | 426 | goto error; |
427 | } | 427 | } |
428 | 428 | ||
429 | vb2_set_plane_payload(vb, 0, size); | 429 | vb2_set_plane_payload(vb, 0, size); |
430 | 430 | ||
431 | dev_dbg(icd->parent, "%s (vb=0x%p) 0x%p %lu\n", __func__, | 431 | dev_dbg(icd->parent, "%s (vb=0x%p) 0x%p %lu\n", __func__, |
432 | vb, vb2_plane_vaddr(vb, 0), vb2_get_plane_payload(vb, 0)); | 432 | vb, vb2_plane_vaddr(vb, 0), vb2_get_plane_payload(vb, 0)); |
433 | 433 | ||
434 | spin_lock_irq(&priv->lock); | 434 | spin_lock_irq(&priv->lock); |
435 | 435 | ||
436 | list_add_tail(to_buf_list(vb), &priv->capture); | 436 | list_add_tail(to_buf_list(vb), &priv->capture); |
437 | rcar_vin_fill_hw_slot(priv); | 437 | rcar_vin_fill_hw_slot(priv); |
438 | 438 | ||
439 | /* If we weren't running, and have enough buffers, start capturing! */ | 439 | /* If we weren't running, and have enough buffers, start capturing! */ |
440 | if (priv->state != RUNNING && rcar_vin_hw_ready(priv)) { | 440 | if (priv->state != RUNNING && rcar_vin_hw_ready(priv)) { |
441 | if (rcar_vin_setup(priv)) { | 441 | if (rcar_vin_setup(priv)) { |
442 | /* Submit error */ | 442 | /* Submit error */ |
443 | list_del_init(to_buf_list(vb)); | 443 | list_del_init(to_buf_list(vb)); |
444 | spin_unlock_irq(&priv->lock); | 444 | spin_unlock_irq(&priv->lock); |
445 | goto error; | 445 | goto error; |
446 | } | 446 | } |
447 | priv->request_to_stop = false; | 447 | priv->request_to_stop = false; |
448 | init_completion(&priv->capture_stop); | 448 | init_completion(&priv->capture_stop); |
449 | priv->state = RUNNING; | 449 | priv->state = RUNNING; |
450 | rcar_vin_capture(priv); | 450 | rcar_vin_capture(priv); |
451 | } | 451 | } |
452 | 452 | ||
453 | spin_unlock_irq(&priv->lock); | 453 | spin_unlock_irq(&priv->lock); |
454 | 454 | ||
455 | return; | 455 | return; |
456 | 456 | ||
457 | error: | 457 | error: |
458 | vb2_buffer_done(vb, VB2_BUF_STATE_ERROR); | 458 | vb2_buffer_done(vb, VB2_BUF_STATE_ERROR); |
459 | } | 459 | } |
460 | 460 | ||
461 | static void rcar_vin_videobuf_release(struct vb2_buffer *vb) | 461 | static void rcar_vin_videobuf_release(struct vb2_buffer *vb) |
462 | { | 462 | { |
463 | struct soc_camera_device *icd = soc_camera_from_vb2q(vb->vb2_queue); | 463 | struct soc_camera_device *icd = soc_camera_from_vb2q(vb->vb2_queue); |
464 | struct soc_camera_host *ici = to_soc_camera_host(icd->parent); | 464 | struct soc_camera_host *ici = to_soc_camera_host(icd->parent); |
465 | struct rcar_vin_priv *priv = ici->priv; | 465 | struct rcar_vin_priv *priv = ici->priv; |
466 | unsigned int i; | 466 | unsigned int i; |
467 | int buf_in_use = 0; | 467 | int buf_in_use = 0; |
468 | 468 | ||
469 | spin_lock_irq(&priv->lock); | 469 | spin_lock_irq(&priv->lock); |
470 | 470 | ||
471 | /* Is the buffer in use by the VIN hardware? */ | 471 | /* Is the buffer in use by the VIN hardware? */ |
472 | for (i = 0; i < MAX_BUFFER_NUM; i++) { | 472 | for (i = 0; i < MAX_BUFFER_NUM; i++) { |
473 | if (priv->queue_buf[i] == vb) { | 473 | if (priv->queue_buf[i] == vb) { |
474 | buf_in_use = 1; | 474 | buf_in_use = 1; |
475 | break; | 475 | break; |
476 | } | 476 | } |
477 | } | 477 | } |
478 | 478 | ||
479 | if (buf_in_use) { | 479 | if (buf_in_use) { |
480 | while (priv->state != STOPPED) { | 480 | while (priv->state != STOPPED) { |
481 | 481 | ||
482 | /* issue stop if running */ | 482 | /* issue stop if running */ |
483 | if (priv->state == RUNNING) | 483 | if (priv->state == RUNNING) |
484 | rcar_vin_request_capture_stop(priv); | 484 | rcar_vin_request_capture_stop(priv); |
485 | 485 | ||
486 | /* wait until capturing has been stopped */ | 486 | /* wait until capturing has been stopped */ |
487 | if (priv->state == STOPPING) { | 487 | if (priv->state == STOPPING) { |
488 | priv->request_to_stop = true; | 488 | priv->request_to_stop = true; |
489 | spin_unlock_irq(&priv->lock); | 489 | spin_unlock_irq(&priv->lock); |
490 | wait_for_completion(&priv->capture_stop); | 490 | wait_for_completion(&priv->capture_stop); |
491 | spin_lock_irq(&priv->lock); | 491 | spin_lock_irq(&priv->lock); |
492 | } | 492 | } |
493 | } | 493 | } |
494 | /* | 494 | /* |
495 | * Capturing has now stopped. The buffer we have been asked | 495 | * Capturing has now stopped. The buffer we have been asked |
496 | * to release could be any of the current buffers in use, so | 496 | * to release could be any of the current buffers in use, so |
497 | * release all buffers that are in use by HW | 497 | * release all buffers that are in use by HW |
498 | */ | 498 | */ |
499 | for (i = 0; i < MAX_BUFFER_NUM; i++) { | 499 | for (i = 0; i < MAX_BUFFER_NUM; i++) { |
500 | if (priv->queue_buf[i]) { | 500 | if (priv->queue_buf[i]) { |
501 | vb2_buffer_done(priv->queue_buf[i], | 501 | vb2_buffer_done(priv->queue_buf[i], |
502 | VB2_BUF_STATE_ERROR); | 502 | VB2_BUF_STATE_ERROR); |
503 | priv->queue_buf[i] = NULL; | 503 | priv->queue_buf[i] = NULL; |
504 | } | 504 | } |
505 | } | 505 | } |
506 | } else { | 506 | } else { |
507 | list_del_init(to_buf_list(vb)); | 507 | list_del_init(to_buf_list(vb)); |
508 | } | 508 | } |
509 | 509 | ||
510 | spin_unlock_irq(&priv->lock); | 510 | spin_unlock_irq(&priv->lock); |
511 | } | 511 | } |
512 | 512 | ||
513 | static int rcar_vin_videobuf_init(struct vb2_buffer *vb) | 513 | static int rcar_vin_videobuf_init(struct vb2_buffer *vb) |
514 | { | 514 | { |
515 | INIT_LIST_HEAD(to_buf_list(vb)); | 515 | INIT_LIST_HEAD(to_buf_list(vb)); |
516 | return 0; | 516 | return 0; |
517 | } | 517 | } |
518 | 518 | ||
519 | static void rcar_vin_stop_streaming(struct vb2_queue *vq) | 519 | static void rcar_vin_stop_streaming(struct vb2_queue *vq) |
520 | { | 520 | { |
521 | struct soc_camera_device *icd = soc_camera_from_vb2q(vq); | 521 | struct soc_camera_device *icd = soc_camera_from_vb2q(vq); |
522 | struct soc_camera_host *ici = to_soc_camera_host(icd->parent); | 522 | struct soc_camera_host *ici = to_soc_camera_host(icd->parent); |
523 | struct rcar_vin_priv *priv = ici->priv; | 523 | struct rcar_vin_priv *priv = ici->priv; |
524 | struct list_head *buf_head, *tmp; | 524 | struct list_head *buf_head, *tmp; |
525 | 525 | ||
526 | spin_lock_irq(&priv->lock); | 526 | spin_lock_irq(&priv->lock); |
527 | list_for_each_safe(buf_head, tmp, &priv->capture) | 527 | list_for_each_safe(buf_head, tmp, &priv->capture) |
528 | list_del_init(buf_head); | 528 | list_del_init(buf_head); |
529 | spin_unlock_irq(&priv->lock); | 529 | spin_unlock_irq(&priv->lock); |
530 | } | 530 | } |
531 | 531 | ||
532 | static struct vb2_ops rcar_vin_vb2_ops = { | 532 | static struct vb2_ops rcar_vin_vb2_ops = { |
533 | .queue_setup = rcar_vin_videobuf_setup, | 533 | .queue_setup = rcar_vin_videobuf_setup, |
534 | .buf_init = rcar_vin_videobuf_init, | 534 | .buf_init = rcar_vin_videobuf_init, |
535 | .buf_cleanup = rcar_vin_videobuf_release, | 535 | .buf_cleanup = rcar_vin_videobuf_release, |
536 | .buf_queue = rcar_vin_videobuf_queue, | 536 | .buf_queue = rcar_vin_videobuf_queue, |
537 | .stop_streaming = rcar_vin_stop_streaming, | 537 | .stop_streaming = rcar_vin_stop_streaming, |
538 | .wait_prepare = soc_camera_unlock, | 538 | .wait_prepare = soc_camera_unlock, |
539 | .wait_finish = soc_camera_lock, | 539 | .wait_finish = soc_camera_lock, |
540 | }; | 540 | }; |
541 | 541 | ||
542 | static irqreturn_t rcar_vin_irq(int irq, void *data) | 542 | static irqreturn_t rcar_vin_irq(int irq, void *data) |
543 | { | 543 | { |
544 | struct rcar_vin_priv *priv = data; | 544 | struct rcar_vin_priv *priv = data; |
545 | u32 int_status; | 545 | u32 int_status; |
546 | bool can_run = false, hw_stopped; | 546 | bool can_run = false, hw_stopped; |
547 | int slot; | 547 | int slot; |
548 | unsigned int handled = 0; | 548 | unsigned int handled = 0; |
549 | 549 | ||
550 | spin_lock(&priv->lock); | 550 | spin_lock(&priv->lock); |
551 | 551 | ||
552 | int_status = ioread32(priv->base + VNINTS_REG); | 552 | int_status = ioread32(priv->base + VNINTS_REG); |
553 | if (!int_status) | 553 | if (!int_status) |
554 | goto done; | 554 | goto done; |
555 | /* ack interrupts */ | 555 | /* ack interrupts */ |
556 | iowrite32(int_status, priv->base + VNINTS_REG); | 556 | iowrite32(int_status, priv->base + VNINTS_REG); |
557 | handled = 1; | 557 | handled = 1; |
558 | 558 | ||
559 | /* nothing to do if capture status is 'STOPPED' */ | 559 | /* nothing to do if capture status is 'STOPPED' */ |
560 | if (priv->state == STOPPED) | 560 | if (priv->state == STOPPED) |
561 | goto done; | 561 | goto done; |
562 | 562 | ||
563 | hw_stopped = !(ioread32(priv->base + VNMS_REG) & VNMS_CA); | 563 | hw_stopped = !(ioread32(priv->base + VNMS_REG) & VNMS_CA); |
564 | 564 | ||
565 | if (!priv->request_to_stop) { | 565 | if (!priv->request_to_stop) { |
566 | if (is_continuous_transfer(priv)) | 566 | if (is_continuous_transfer(priv)) |
567 | slot = (ioread32(priv->base + VNMS_REG) & | 567 | slot = (ioread32(priv->base + VNMS_REG) & |
568 | VNMS_FBS_MASK) >> VNMS_FBS_SHIFT; | 568 | VNMS_FBS_MASK) >> VNMS_FBS_SHIFT; |
569 | else | 569 | else |
570 | slot = 0; | 570 | slot = 0; |
571 | 571 | ||
572 | priv->queue_buf[slot]->v4l2_buf.field = priv->field; | 572 | priv->queue_buf[slot]->v4l2_buf.field = priv->field; |
573 | priv->queue_buf[slot]->v4l2_buf.sequence = priv->sequence++; | 573 | priv->queue_buf[slot]->v4l2_buf.sequence = priv->sequence++; |
574 | do_gettimeofday(&priv->queue_buf[slot]->v4l2_buf.timestamp); | 574 | do_gettimeofday(&priv->queue_buf[slot]->v4l2_buf.timestamp); |
575 | vb2_buffer_done(priv->queue_buf[slot], VB2_BUF_STATE_DONE); | 575 | vb2_buffer_done(priv->queue_buf[slot], VB2_BUF_STATE_DONE); |
576 | priv->queue_buf[slot] = NULL; | 576 | priv->queue_buf[slot] = NULL; |
577 | 577 | ||
578 | if (priv->state != STOPPING) | 578 | if (priv->state != STOPPING) |
579 | can_run = rcar_vin_fill_hw_slot(priv); | 579 | can_run = rcar_vin_fill_hw_slot(priv); |
580 | 580 | ||
581 | if (hw_stopped || !can_run) { | 581 | if (hw_stopped || !can_run) { |
582 | priv->state = STOPPED; | 582 | priv->state = STOPPED; |
583 | } else if (is_continuous_transfer(priv) && | 583 | } else if (is_continuous_transfer(priv) && |
584 | list_empty(&priv->capture) && | 584 | list_empty(&priv->capture) && |
585 | priv->state == RUNNING) { | 585 | priv->state == RUNNING) { |
586 | /* | 586 | /* |
587 | * The continuous capturing requires an explicit stop | 587 | * The continuous capturing requires an explicit stop |
588 | * operation when there is no buffer to be set into | 588 | * operation when there is no buffer to be set into |
589 | * the VnMBm registers. | 589 | * the VnMBm registers. |
590 | */ | 590 | */ |
591 | rcar_vin_request_capture_stop(priv); | 591 | rcar_vin_request_capture_stop(priv); |
592 | } else { | 592 | } else { |
593 | rcar_vin_capture(priv); | 593 | rcar_vin_capture(priv); |
594 | } | 594 | } |
595 | 595 | ||
596 | } else if (hw_stopped) { | 596 | } else if (hw_stopped) { |
597 | priv->state = STOPPED; | 597 | priv->state = STOPPED; |
598 | priv->request_to_stop = false; | 598 | priv->request_to_stop = false; |
599 | complete(&priv->capture_stop); | 599 | complete(&priv->capture_stop); |
600 | } | 600 | } |
601 | 601 | ||
602 | done: | 602 | done: |
603 | spin_unlock(&priv->lock); | 603 | spin_unlock(&priv->lock); |
604 | 604 | ||
605 | return IRQ_RETVAL(handled); | 605 | return IRQ_RETVAL(handled); |
606 | } | 606 | } |
607 | 607 | ||
608 | static int rcar_vin_add_device(struct soc_camera_device *icd) | 608 | static int rcar_vin_add_device(struct soc_camera_device *icd) |
609 | { | 609 | { |
610 | struct soc_camera_host *ici = to_soc_camera_host(icd->parent); | 610 | struct soc_camera_host *ici = to_soc_camera_host(icd->parent); |
611 | struct rcar_vin_priv *priv = ici->priv; | 611 | struct rcar_vin_priv *priv = ici->priv; |
612 | int i; | 612 | int i; |
613 | 613 | ||
614 | for (i = 0; i < MAX_BUFFER_NUM; i++) | 614 | for (i = 0; i < MAX_BUFFER_NUM; i++) |
615 | priv->queue_buf[i] = NULL; | 615 | priv->queue_buf[i] = NULL; |
616 | 616 | ||
617 | pm_runtime_get_sync(ici->v4l2_dev.dev); | 617 | pm_runtime_get_sync(ici->v4l2_dev.dev); |
618 | 618 | ||
619 | dev_dbg(icd->parent, "R-Car VIN driver attached to camera %d\n", | 619 | dev_dbg(icd->parent, "R-Car VIN driver attached to camera %d\n", |
620 | icd->devnum); | 620 | icd->devnum); |
621 | 621 | ||
622 | return 0; | 622 | return 0; |
623 | } | 623 | } |
624 | 624 | ||
625 | static void rcar_vin_remove_device(struct soc_camera_device *icd) | 625 | static void rcar_vin_remove_device(struct soc_camera_device *icd) |
626 | { | 626 | { |
627 | struct soc_camera_host *ici = to_soc_camera_host(icd->parent); | 627 | struct soc_camera_host *ici = to_soc_camera_host(icd->parent); |
628 | struct rcar_vin_priv *priv = ici->priv; | 628 | struct rcar_vin_priv *priv = ici->priv; |
629 | struct vb2_buffer *vb; | 629 | struct vb2_buffer *vb; |
630 | int i; | 630 | int i; |
631 | 631 | ||
632 | /* disable capture, disable interrupts */ | 632 | /* disable capture, disable interrupts */ |
633 | iowrite32(ioread32(priv->base + VNMC_REG) & ~VNMC_ME, | 633 | iowrite32(ioread32(priv->base + VNMC_REG) & ~VNMC_ME, |
634 | priv->base + VNMC_REG); | 634 | priv->base + VNMC_REG); |
635 | iowrite32(0, priv->base + VNIE_REG); | 635 | iowrite32(0, priv->base + VNIE_REG); |
636 | 636 | ||
637 | priv->state = STOPPED; | 637 | priv->state = STOPPED; |
638 | priv->request_to_stop = false; | 638 | priv->request_to_stop = false; |
639 | 639 | ||
640 | /* make sure active buffer is cancelled */ | 640 | /* make sure active buffer is cancelled */ |
641 | spin_lock_irq(&priv->lock); | 641 | spin_lock_irq(&priv->lock); |
642 | for (i = 0; i < MAX_BUFFER_NUM; i++) { | 642 | for (i = 0; i < MAX_BUFFER_NUM; i++) { |
643 | vb = priv->queue_buf[i]; | 643 | vb = priv->queue_buf[i]; |
644 | if (vb) { | 644 | if (vb) { |
645 | list_del_init(to_buf_list(vb)); | 645 | list_del_init(to_buf_list(vb)); |
646 | vb2_buffer_done(vb, VB2_BUF_STATE_ERROR); | 646 | vb2_buffer_done(vb, VB2_BUF_STATE_ERROR); |
647 | } | 647 | } |
648 | } | 648 | } |
649 | spin_unlock_irq(&priv->lock); | 649 | spin_unlock_irq(&priv->lock); |
650 | 650 | ||
651 | pm_runtime_put(ici->v4l2_dev.dev); | 651 | pm_runtime_put(ici->v4l2_dev.dev); |
652 | 652 | ||
653 | dev_dbg(icd->parent, "R-Car VIN driver detached from camera %d\n", | 653 | dev_dbg(icd->parent, "R-Car VIN driver detached from camera %d\n", |
654 | icd->devnum); | 654 | icd->devnum); |
655 | } | 655 | } |
656 | 656 | ||
657 | /* Called with .host_lock held */ | 657 | /* Called with .host_lock held */ |
658 | static int rcar_vin_clock_start(struct soc_camera_host *ici) | 658 | static int rcar_vin_clock_start(struct soc_camera_host *ici) |
659 | { | 659 | { |
660 | /* VIN does not have "mclk" */ | 660 | /* VIN does not have "mclk" */ |
661 | return 0; | 661 | return 0; |
662 | } | 662 | } |
663 | 663 | ||
664 | /* Called with .host_lock held */ | 664 | /* Called with .host_lock held */ |
665 | static void rcar_vin_clock_stop(struct soc_camera_host *ici) | 665 | static void rcar_vin_clock_stop(struct soc_camera_host *ici) |
666 | { | 666 | { |
667 | /* VIN does not have "mclk" */ | 667 | /* VIN does not have "mclk" */ |
668 | } | 668 | } |
669 | 669 | ||
670 | /* rect is guaranteed to not exceed the scaled camera rectangle */ | 670 | /* rect is guaranteed to not exceed the scaled camera rectangle */ |
671 | static int rcar_vin_set_rect(struct soc_camera_device *icd) | 671 | static int rcar_vin_set_rect(struct soc_camera_device *icd) |
672 | { | 672 | { |
673 | struct soc_camera_host *ici = to_soc_camera_host(icd->parent); | 673 | struct soc_camera_host *ici = to_soc_camera_host(icd->parent); |
674 | struct rcar_vin_cam *cam = icd->host_priv; | 674 | struct rcar_vin_cam *cam = icd->host_priv; |
675 | struct rcar_vin_priv *priv = ici->priv; | 675 | struct rcar_vin_priv *priv = ici->priv; |
676 | unsigned int left_offset, top_offset; | 676 | unsigned int left_offset, top_offset; |
677 | unsigned char dsize = 0; | 677 | unsigned char dsize = 0; |
678 | struct v4l2_rect *cam_subrect = &cam->subrect; | 678 | struct v4l2_rect *cam_subrect = &cam->subrect; |
679 | 679 | ||
680 | dev_dbg(icd->parent, "Crop %ux%u@%u:%u\n", | 680 | dev_dbg(icd->parent, "Crop %ux%u@%u:%u\n", |
681 | icd->user_width, icd->user_height, cam->vin_left, cam->vin_top); | 681 | icd->user_width, icd->user_height, cam->vin_left, cam->vin_top); |
682 | 682 | ||
683 | left_offset = cam->vin_left; | 683 | left_offset = cam->vin_left; |
684 | top_offset = cam->vin_top; | 684 | top_offset = cam->vin_top; |
685 | 685 | ||
686 | if (icd->current_fmt->host_fmt->fourcc == V4L2_PIX_FMT_RGB32 && | 686 | if (icd->current_fmt->host_fmt->fourcc == V4L2_PIX_FMT_RGB32 && |
687 | priv->chip == RCAR_E1) | 687 | priv->chip == RCAR_E1) |
688 | dsize = 1; | 688 | dsize = 1; |
689 | 689 | ||
690 | dev_dbg(icd->parent, "Cam %ux%u@%u:%u\n", | 690 | dev_dbg(icd->parent, "Cam %ux%u@%u:%u\n", |
691 | cam->width, cam->height, cam->vin_left, cam->vin_top); | 691 | cam->width, cam->height, cam->vin_left, cam->vin_top); |
692 | dev_dbg(icd->parent, "Cam subrect %ux%u@%u:%u\n", | 692 | dev_dbg(icd->parent, "Cam subrect %ux%u@%u:%u\n", |
693 | cam_subrect->width, cam_subrect->height, | 693 | cam_subrect->width, cam_subrect->height, |
694 | cam_subrect->left, cam_subrect->top); | 694 | cam_subrect->left, cam_subrect->top); |
695 | 695 | ||
696 | /* Set Start/End Pixel/Line Pre-Clip */ | 696 | /* Set Start/End Pixel/Line Pre-Clip */ |
697 | iowrite32(left_offset << dsize, priv->base + VNSPPRC_REG); | 697 | iowrite32(left_offset << dsize, priv->base + VNSPPRC_REG); |
698 | iowrite32((left_offset + cam->width - 1) << dsize, | 698 | iowrite32((left_offset + cam->width - 1) << dsize, |
699 | priv->base + VNEPPRC_REG); | 699 | priv->base + VNEPPRC_REG); |
700 | switch (priv->field) { | 700 | switch (priv->field) { |
701 | case V4L2_FIELD_INTERLACED: | 701 | case V4L2_FIELD_INTERLACED: |
702 | case V4L2_FIELD_INTERLACED_TB: | 702 | case V4L2_FIELD_INTERLACED_TB: |
703 | case V4L2_FIELD_INTERLACED_BT: | 703 | case V4L2_FIELD_INTERLACED_BT: |
704 | iowrite32(top_offset / 2, priv->base + VNSLPRC_REG); | 704 | iowrite32(top_offset / 2, priv->base + VNSLPRC_REG); |
705 | iowrite32((top_offset + cam->height) / 2 - 1, | 705 | iowrite32((top_offset + cam->height) / 2 - 1, |
706 | priv->base + VNELPRC_REG); | 706 | priv->base + VNELPRC_REG); |
707 | break; | 707 | break; |
708 | default: | 708 | default: |
709 | iowrite32(top_offset, priv->base + VNSLPRC_REG); | 709 | iowrite32(top_offset, priv->base + VNSLPRC_REG); |
710 | iowrite32(top_offset + cam->height - 1, | 710 | iowrite32(top_offset + cam->height - 1, |
711 | priv->base + VNELPRC_REG); | 711 | priv->base + VNELPRC_REG); |
712 | break; | 712 | break; |
713 | } | 713 | } |
714 | 714 | ||
715 | /* Set Start/End Pixel/Line Post-Clip */ | 715 | /* Set Start/End Pixel/Line Post-Clip */ |
716 | iowrite32(0, priv->base + VNSPPOC_REG); | 716 | iowrite32(0, priv->base + VNSPPOC_REG); |
717 | iowrite32(0, priv->base + VNSLPOC_REG); | 717 | iowrite32(0, priv->base + VNSLPOC_REG); |
718 | iowrite32((cam_subrect->width - 1) << dsize, priv->base + VNEPPOC_REG); | 718 | iowrite32((cam_subrect->width - 1) << dsize, priv->base + VNEPPOC_REG); |
719 | switch (priv->field) { | 719 | switch (priv->field) { |
720 | case V4L2_FIELD_INTERLACED: | 720 | case V4L2_FIELD_INTERLACED: |
721 | case V4L2_FIELD_INTERLACED_TB: | 721 | case V4L2_FIELD_INTERLACED_TB: |
722 | case V4L2_FIELD_INTERLACED_BT: | 722 | case V4L2_FIELD_INTERLACED_BT: |
723 | iowrite32(cam_subrect->height / 2 - 1, | 723 | iowrite32(cam_subrect->height / 2 - 1, |
724 | priv->base + VNELPOC_REG); | 724 | priv->base + VNELPOC_REG); |
725 | break; | 725 | break; |
726 | default: | 726 | default: |
727 | iowrite32(cam_subrect->height - 1, priv->base + VNELPOC_REG); | 727 | iowrite32(cam_subrect->height - 1, priv->base + VNELPOC_REG); |
728 | break; | 728 | break; |
729 | } | 729 | } |
730 | 730 | ||
731 | iowrite32(ALIGN(cam->width, 0x10), priv->base + VNIS_REG); | 731 | iowrite32(ALIGN(cam->width, 0x10), priv->base + VNIS_REG); |
732 | 732 | ||
733 | return 0; | 733 | return 0; |
734 | } | 734 | } |
735 | 735 | ||
736 | static void capture_stop_preserve(struct rcar_vin_priv *priv, u32 *vnmc) | 736 | static void capture_stop_preserve(struct rcar_vin_priv *priv, u32 *vnmc) |
737 | { | 737 | { |
738 | *vnmc = ioread32(priv->base + VNMC_REG); | 738 | *vnmc = ioread32(priv->base + VNMC_REG); |
739 | /* module disable */ | 739 | /* module disable */ |
740 | iowrite32(*vnmc & ~VNMC_ME, priv->base + VNMC_REG); | 740 | iowrite32(*vnmc & ~VNMC_ME, priv->base + VNMC_REG); |
741 | } | 741 | } |
742 | 742 | ||
743 | static void capture_restore(struct rcar_vin_priv *priv, u32 vnmc) | 743 | static void capture_restore(struct rcar_vin_priv *priv, u32 vnmc) |
744 | { | 744 | { |
745 | unsigned long timeout = jiffies + 10 * HZ; | 745 | unsigned long timeout = jiffies + 10 * HZ; |
746 | 746 | ||
747 | /* | 747 | /* |
748 | * Wait until the end of the current frame. It can take a long time, | 748 | * Wait until the end of the current frame. It can take a long time, |
749 | * but if it has been aborted by a MRST1 reset, it should exit sooner. | 749 | * but if it has been aborted by a MRST1 reset, it should exit sooner. |
750 | */ | 750 | */ |
751 | while ((ioread32(priv->base + VNMS_REG) & VNMS_AV) && | 751 | while ((ioread32(priv->base + VNMS_REG) & VNMS_AV) && |
752 | time_before(jiffies, timeout)) | 752 | time_before(jiffies, timeout)) |
753 | msleep(1); | 753 | msleep(1); |
754 | 754 | ||
755 | if (time_after(jiffies, timeout)) { | 755 | if (time_after(jiffies, timeout)) { |
756 | dev_err(priv->ici.v4l2_dev.dev, | 756 | dev_err(priv->ici.v4l2_dev.dev, |
757 | "Timeout waiting for frame end! Interface problem?\n"); | 757 | "Timeout waiting for frame end! Interface problem?\n"); |
758 | return; | 758 | return; |
759 | } | 759 | } |
760 | 760 | ||
761 | iowrite32(vnmc, priv->base + VNMC_REG); | 761 | iowrite32(vnmc, priv->base + VNMC_REG); |
762 | } | 762 | } |
763 | 763 | ||
764 | #define VIN_MBUS_FLAGS (V4L2_MBUS_MASTER | \ | 764 | #define VIN_MBUS_FLAGS (V4L2_MBUS_MASTER | \ |
765 | V4L2_MBUS_PCLK_SAMPLE_RISING | \ | 765 | V4L2_MBUS_PCLK_SAMPLE_RISING | \ |
766 | V4L2_MBUS_HSYNC_ACTIVE_HIGH | \ | 766 | V4L2_MBUS_HSYNC_ACTIVE_HIGH | \ |
767 | V4L2_MBUS_HSYNC_ACTIVE_LOW | \ | 767 | V4L2_MBUS_HSYNC_ACTIVE_LOW | \ |
768 | V4L2_MBUS_VSYNC_ACTIVE_HIGH | \ | 768 | V4L2_MBUS_VSYNC_ACTIVE_HIGH | \ |
769 | V4L2_MBUS_VSYNC_ACTIVE_LOW | \ | 769 | V4L2_MBUS_VSYNC_ACTIVE_LOW | \ |
770 | V4L2_MBUS_DATA_ACTIVE_HIGH) | 770 | V4L2_MBUS_DATA_ACTIVE_HIGH) |
771 | 771 | ||
772 | static int rcar_vin_set_bus_param(struct soc_camera_device *icd) | 772 | static int rcar_vin_set_bus_param(struct soc_camera_device *icd) |
773 | { | 773 | { |
774 | struct soc_camera_host *ici = to_soc_camera_host(icd->parent); | 774 | struct soc_camera_host *ici = to_soc_camera_host(icd->parent); |
775 | struct rcar_vin_priv *priv = ici->priv; | 775 | struct rcar_vin_priv *priv = ici->priv; |
776 | struct v4l2_subdev *sd = soc_camera_to_subdev(icd); | 776 | struct v4l2_subdev *sd = soc_camera_to_subdev(icd); |
777 | struct v4l2_mbus_config cfg; | 777 | struct v4l2_mbus_config cfg; |
778 | unsigned long common_flags; | 778 | unsigned long common_flags; |
779 | u32 vnmc; | 779 | u32 vnmc; |
780 | u32 val; | 780 | u32 val; |
781 | int ret; | 781 | int ret; |
782 | 782 | ||
783 | capture_stop_preserve(priv, &vnmc); | 783 | capture_stop_preserve(priv, &vnmc); |
784 | 784 | ||
785 | ret = v4l2_subdev_call(sd, video, g_mbus_config, &cfg); | 785 | ret = v4l2_subdev_call(sd, video, g_mbus_config, &cfg); |
786 | if (!ret) { | 786 | if (!ret) { |
787 | common_flags = soc_mbus_config_compatible(&cfg, VIN_MBUS_FLAGS); | 787 | common_flags = soc_mbus_config_compatible(&cfg, VIN_MBUS_FLAGS); |
788 | if (!common_flags) { | 788 | if (!common_flags) { |
789 | dev_warn(icd->parent, | 789 | dev_warn(icd->parent, |
790 | "MBUS flags incompatible: camera 0x%x, host 0x%x\n", | 790 | "MBUS flags incompatible: camera 0x%x, host 0x%x\n", |
791 | cfg.flags, VIN_MBUS_FLAGS); | 791 | cfg.flags, VIN_MBUS_FLAGS); |
792 | return -EINVAL; | 792 | return -EINVAL; |
793 | } | 793 | } |
794 | } else if (ret != -ENOIOCTLCMD) { | 794 | } else if (ret != -ENOIOCTLCMD) { |
795 | return ret; | 795 | return ret; |
796 | } else { | 796 | } else { |
797 | common_flags = VIN_MBUS_FLAGS; | 797 | common_flags = VIN_MBUS_FLAGS; |
798 | } | 798 | } |
799 | 799 | ||
800 | /* Make choises, based on platform preferences */ | 800 | /* Make choises, based on platform preferences */ |
801 | if ((common_flags & V4L2_MBUS_HSYNC_ACTIVE_HIGH) && | 801 | if ((common_flags & V4L2_MBUS_HSYNC_ACTIVE_HIGH) && |
802 | (common_flags & V4L2_MBUS_HSYNC_ACTIVE_LOW)) { | 802 | (common_flags & V4L2_MBUS_HSYNC_ACTIVE_LOW)) { |
803 | if (priv->pdata_flags & RCAR_VIN_HSYNC_ACTIVE_LOW) | 803 | if (priv->pdata_flags & RCAR_VIN_HSYNC_ACTIVE_LOW) |
804 | common_flags &= ~V4L2_MBUS_HSYNC_ACTIVE_HIGH; | 804 | common_flags &= ~V4L2_MBUS_HSYNC_ACTIVE_HIGH; |
805 | else | 805 | else |
806 | common_flags &= ~V4L2_MBUS_HSYNC_ACTIVE_LOW; | 806 | common_flags &= ~V4L2_MBUS_HSYNC_ACTIVE_LOW; |
807 | } | 807 | } |
808 | 808 | ||
809 | if ((common_flags & V4L2_MBUS_VSYNC_ACTIVE_HIGH) && | 809 | if ((common_flags & V4L2_MBUS_VSYNC_ACTIVE_HIGH) && |
810 | (common_flags & V4L2_MBUS_VSYNC_ACTIVE_LOW)) { | 810 | (common_flags & V4L2_MBUS_VSYNC_ACTIVE_LOW)) { |
811 | if (priv->pdata_flags & RCAR_VIN_VSYNC_ACTIVE_LOW) | 811 | if (priv->pdata_flags & RCAR_VIN_VSYNC_ACTIVE_LOW) |
812 | common_flags &= ~V4L2_MBUS_VSYNC_ACTIVE_HIGH; | 812 | common_flags &= ~V4L2_MBUS_VSYNC_ACTIVE_HIGH; |
813 | else | 813 | else |
814 | common_flags &= ~V4L2_MBUS_VSYNC_ACTIVE_LOW; | 814 | common_flags &= ~V4L2_MBUS_VSYNC_ACTIVE_LOW; |
815 | } | 815 | } |
816 | 816 | ||
817 | cfg.flags = common_flags; | 817 | cfg.flags = common_flags; |
818 | ret = v4l2_subdev_call(sd, video, s_mbus_config, &cfg); | 818 | ret = v4l2_subdev_call(sd, video, s_mbus_config, &cfg); |
819 | if (ret < 0 && ret != -ENOIOCTLCMD) | 819 | if (ret < 0 && ret != -ENOIOCTLCMD) |
820 | return ret; | 820 | return ret; |
821 | 821 | ||
822 | val = priv->field == V4L2_FIELD_NONE ? VNDMR2_FTEV : 0; | 822 | val = priv->field == V4L2_FIELD_NONE ? VNDMR2_FTEV : 0; |
823 | if (!(common_flags & V4L2_MBUS_VSYNC_ACTIVE_LOW)) | 823 | if (!(common_flags & V4L2_MBUS_VSYNC_ACTIVE_LOW)) |
824 | val |= VNDMR2_VPS; | 824 | val |= VNDMR2_VPS; |
825 | if (!(common_flags & V4L2_MBUS_HSYNC_ACTIVE_LOW)) | 825 | if (!(common_flags & V4L2_MBUS_HSYNC_ACTIVE_LOW)) |
826 | val |= VNDMR2_HPS; | 826 | val |= VNDMR2_HPS; |
827 | iowrite32(val, priv->base + VNDMR2_REG); | 827 | iowrite32(val, priv->base + VNDMR2_REG); |
828 | 828 | ||
829 | ret = rcar_vin_set_rect(icd); | 829 | ret = rcar_vin_set_rect(icd); |
830 | if (ret < 0) | 830 | if (ret < 0) |
831 | return ret; | 831 | return ret; |
832 | 832 | ||
833 | capture_restore(priv, vnmc); | 833 | capture_restore(priv, vnmc); |
834 | 834 | ||
835 | return 0; | 835 | return 0; |
836 | } | 836 | } |
837 | 837 | ||
838 | static int rcar_vin_try_bus_param(struct soc_camera_device *icd, | 838 | static int rcar_vin_try_bus_param(struct soc_camera_device *icd, |
839 | unsigned char buswidth) | 839 | unsigned char buswidth) |
840 | { | 840 | { |
841 | struct v4l2_subdev *sd = soc_camera_to_subdev(icd); | 841 | struct v4l2_subdev *sd = soc_camera_to_subdev(icd); |
842 | struct v4l2_mbus_config cfg; | 842 | struct v4l2_mbus_config cfg; |
843 | int ret; | 843 | int ret; |
844 | 844 | ||
845 | ret = v4l2_subdev_call(sd, video, g_mbus_config, &cfg); | 845 | ret = v4l2_subdev_call(sd, video, g_mbus_config, &cfg); |
846 | if (ret == -ENOIOCTLCMD) | 846 | if (ret == -ENOIOCTLCMD) |
847 | return 0; | 847 | return 0; |
848 | else if (ret) | 848 | else if (ret) |
849 | return ret; | 849 | return ret; |
850 | 850 | ||
851 | if (buswidth > 24) | 851 | if (buswidth > 24) |
852 | return -EINVAL; | 852 | return -EINVAL; |
853 | 853 | ||
854 | /* check is there common mbus flags */ | 854 | /* check is there common mbus flags */ |
855 | ret = soc_mbus_config_compatible(&cfg, VIN_MBUS_FLAGS); | 855 | ret = soc_mbus_config_compatible(&cfg, VIN_MBUS_FLAGS); |
856 | if (ret) | 856 | if (ret) |
857 | return 0; | 857 | return 0; |
858 | 858 | ||
859 | dev_warn(icd->parent, | 859 | dev_warn(icd->parent, |
860 | "MBUS flags incompatible: camera 0x%x, host 0x%x\n", | 860 | "MBUS flags incompatible: camera 0x%x, host 0x%x\n", |
861 | cfg.flags, VIN_MBUS_FLAGS); | 861 | cfg.flags, VIN_MBUS_FLAGS); |
862 | 862 | ||
863 | return -EINVAL; | 863 | return -EINVAL; |
864 | } | 864 | } |
865 | 865 | ||
866 | static bool rcar_vin_packing_supported(const struct soc_mbus_pixelfmt *fmt) | 866 | static bool rcar_vin_packing_supported(const struct soc_mbus_pixelfmt *fmt) |
867 | { | 867 | { |
868 | return fmt->packing == SOC_MBUS_PACKING_NONE || | 868 | return fmt->packing == SOC_MBUS_PACKING_NONE || |
869 | (fmt->bits_per_sample > 8 && | 869 | (fmt->bits_per_sample > 8 && |
870 | fmt->packing == SOC_MBUS_PACKING_EXTEND16); | 870 | fmt->packing == SOC_MBUS_PACKING_EXTEND16); |
871 | } | 871 | } |
872 | 872 | ||
873 | static const struct soc_mbus_pixelfmt rcar_vin_formats[] = { | 873 | static const struct soc_mbus_pixelfmt rcar_vin_formats[] = { |
874 | { | 874 | { |
875 | .fourcc = V4L2_PIX_FMT_NV16, | 875 | .fourcc = V4L2_PIX_FMT_NV16, |
876 | .name = "NV16", | 876 | .name = "NV16", |
877 | .bits_per_sample = 8, | 877 | .bits_per_sample = 8, |
878 | .packing = SOC_MBUS_PACKING_2X8_PADHI, | 878 | .packing = SOC_MBUS_PACKING_2X8_PADHI, |
879 | .order = SOC_MBUS_ORDER_LE, | 879 | .order = SOC_MBUS_ORDER_LE, |
880 | .layout = SOC_MBUS_LAYOUT_PLANAR_Y_C, | 880 | .layout = SOC_MBUS_LAYOUT_PLANAR_Y_C, |
881 | }, | 881 | }, |
882 | { | 882 | { |
883 | .fourcc = V4L2_PIX_FMT_YUYV, | 883 | .fourcc = V4L2_PIX_FMT_YUYV, |
884 | .name = "YUYV", | 884 | .name = "YUYV", |
885 | .bits_per_sample = 16, | 885 | .bits_per_sample = 16, |
886 | .packing = SOC_MBUS_PACKING_NONE, | 886 | .packing = SOC_MBUS_PACKING_NONE, |
887 | .order = SOC_MBUS_ORDER_LE, | 887 | .order = SOC_MBUS_ORDER_LE, |
888 | .layout = SOC_MBUS_LAYOUT_PACKED, | 888 | .layout = SOC_MBUS_LAYOUT_PACKED, |
889 | }, | 889 | }, |
890 | { | 890 | { |
891 | .fourcc = V4L2_PIX_FMT_UYVY, | 891 | .fourcc = V4L2_PIX_FMT_UYVY, |
892 | .name = "UYVY", | 892 | .name = "UYVY", |
893 | .bits_per_sample = 16, | 893 | .bits_per_sample = 16, |
894 | .packing = SOC_MBUS_PACKING_NONE, | 894 | .packing = SOC_MBUS_PACKING_NONE, |
895 | .order = SOC_MBUS_ORDER_LE, | 895 | .order = SOC_MBUS_ORDER_LE, |
896 | .layout = SOC_MBUS_LAYOUT_PACKED, | 896 | .layout = SOC_MBUS_LAYOUT_PACKED, |
897 | }, | 897 | }, |
898 | { | 898 | { |
899 | .fourcc = V4L2_PIX_FMT_RGB565, | 899 | .fourcc = V4L2_PIX_FMT_RGB565, |
900 | .name = "RGB565", | 900 | .name = "RGB565", |
901 | .bits_per_sample = 16, | 901 | .bits_per_sample = 16, |
902 | .packing = SOC_MBUS_PACKING_NONE, | 902 | .packing = SOC_MBUS_PACKING_NONE, |
903 | .order = SOC_MBUS_ORDER_LE, | 903 | .order = SOC_MBUS_ORDER_LE, |
904 | .layout = SOC_MBUS_LAYOUT_PACKED, | 904 | .layout = SOC_MBUS_LAYOUT_PACKED, |
905 | }, | 905 | }, |
906 | { | 906 | { |
907 | .fourcc = V4L2_PIX_FMT_RGB555X, | 907 | .fourcc = V4L2_PIX_FMT_RGB555X, |
908 | .name = "ARGB1555", | 908 | .name = "ARGB1555", |
909 | .bits_per_sample = 16, | 909 | .bits_per_sample = 16, |
910 | .packing = SOC_MBUS_PACKING_NONE, | 910 | .packing = SOC_MBUS_PACKING_NONE, |
911 | .order = SOC_MBUS_ORDER_LE, | 911 | .order = SOC_MBUS_ORDER_LE, |
912 | .layout = SOC_MBUS_LAYOUT_PACKED, | 912 | .layout = SOC_MBUS_LAYOUT_PACKED, |
913 | }, | 913 | }, |
914 | { | 914 | { |
915 | .fourcc = V4L2_PIX_FMT_RGB32, | 915 | .fourcc = V4L2_PIX_FMT_RGB32, |
916 | .name = "RGB888", | 916 | .name = "RGB888", |
917 | .bits_per_sample = 32, | 917 | .bits_per_sample = 32, |
918 | .packing = SOC_MBUS_PACKING_NONE, | 918 | .packing = SOC_MBUS_PACKING_NONE, |
919 | .order = SOC_MBUS_ORDER_LE, | 919 | .order = SOC_MBUS_ORDER_LE, |
920 | .layout = SOC_MBUS_LAYOUT_PACKED, | 920 | .layout = SOC_MBUS_LAYOUT_PACKED, |
921 | }, | 921 | }, |
922 | }; | 922 | }; |
923 | 923 | ||
924 | static int rcar_vin_get_formats(struct soc_camera_device *icd, unsigned int idx, | 924 | static int rcar_vin_get_formats(struct soc_camera_device *icd, unsigned int idx, |
925 | struct soc_camera_format_xlate *xlate) | 925 | struct soc_camera_format_xlate *xlate) |
926 | { | 926 | { |
927 | struct v4l2_subdev *sd = soc_camera_to_subdev(icd); | 927 | struct v4l2_subdev *sd = soc_camera_to_subdev(icd); |
928 | struct device *dev = icd->parent; | 928 | struct device *dev = icd->parent; |
929 | int ret, k, n; | 929 | int ret, k, n; |
930 | int formats = 0; | 930 | int formats = 0; |
931 | struct rcar_vin_cam *cam; | 931 | struct rcar_vin_cam *cam; |
932 | u32 code; | 932 | u32 code; |
933 | const struct soc_mbus_pixelfmt *fmt; | 933 | const struct soc_mbus_pixelfmt *fmt; |
934 | 934 | ||
935 | ret = v4l2_subdev_call(sd, video, enum_mbus_fmt, idx, &code); | 935 | ret = v4l2_subdev_call(sd, video, enum_mbus_fmt, idx, &code); |
936 | if (ret < 0) | 936 | if (ret < 0) |
937 | return 0; | 937 | return 0; |
938 | 938 | ||
939 | fmt = soc_mbus_get_fmtdesc(code); | 939 | fmt = soc_mbus_get_fmtdesc(code); |
940 | if (!fmt) { | 940 | if (!fmt) { |
941 | dev_warn(dev, "unsupported format code #%u: %d\n", idx, code); | 941 | dev_warn(dev, "unsupported format code #%u: %d\n", idx, code); |
942 | return 0; | 942 | return 0; |
943 | } | 943 | } |
944 | 944 | ||
945 | ret = rcar_vin_try_bus_param(icd, fmt->bits_per_sample); | 945 | ret = rcar_vin_try_bus_param(icd, fmt->bits_per_sample); |
946 | if (ret < 0) | 946 | if (ret < 0) |
947 | return 0; | 947 | return 0; |
948 | 948 | ||
949 | if (!icd->host_priv) { | 949 | if (!icd->host_priv) { |
950 | struct v4l2_mbus_framefmt mf; | 950 | struct v4l2_mbus_framefmt mf; |
951 | struct v4l2_rect rect; | 951 | struct v4l2_rect rect; |
952 | struct device *dev = icd->parent; | 952 | struct device *dev = icd->parent; |
953 | int shift; | 953 | int shift; |
954 | 954 | ||
955 | ret = v4l2_subdev_call(sd, video, g_mbus_fmt, &mf); | 955 | ret = v4l2_subdev_call(sd, video, g_mbus_fmt, &mf); |
956 | if (ret < 0) | 956 | if (ret < 0) |
957 | return ret; | 957 | return ret; |
958 | 958 | ||
959 | /* Cache current client geometry */ | 959 | /* Cache current client geometry */ |
960 | ret = soc_camera_client_g_rect(sd, &rect); | 960 | ret = soc_camera_client_g_rect(sd, &rect); |
961 | if (ret == -ENOIOCTLCMD) { | 961 | if (ret == -ENOIOCTLCMD) { |
962 | /* Sensor driver doesn't support cropping */ | 962 | /* Sensor driver doesn't support cropping */ |
963 | rect.left = 0; | 963 | rect.left = 0; |
964 | rect.top = 0; | 964 | rect.top = 0; |
965 | rect.width = mf.width; | 965 | rect.width = mf.width; |
966 | rect.height = mf.height; | 966 | rect.height = mf.height; |
967 | } else if (ret < 0) { | 967 | } else if (ret < 0) { |
968 | return ret; | 968 | return ret; |
969 | } | 969 | } |
970 | 970 | ||
971 | /* | 971 | /* |
972 | * If sensor proposes too large format then try smaller ones: | 972 | * If sensor proposes too large format then try smaller ones: |
973 | * 1280x960, 640x480, 320x240 | 973 | * 1280x960, 640x480, 320x240 |
974 | */ | 974 | */ |
975 | for (shift = 0; shift < 3; shift++) { | 975 | for (shift = 0; shift < 3; shift++) { |
976 | if (mf.width <= VIN_MAX_WIDTH && | 976 | if (mf.width <= VIN_MAX_WIDTH && |
977 | mf.height <= VIN_MAX_HEIGHT) | 977 | mf.height <= VIN_MAX_HEIGHT) |
978 | break; | 978 | break; |
979 | 979 | ||
980 | mf.width = 1280 >> shift; | 980 | mf.width = 1280 >> shift; |
981 | mf.height = 960 >> shift; | 981 | mf.height = 960 >> shift; |
982 | ret = v4l2_device_call_until_err(sd->v4l2_dev, | 982 | ret = v4l2_device_call_until_err(sd->v4l2_dev, |
983 | soc_camera_grp_id(icd), | 983 | soc_camera_grp_id(icd), |
984 | video, s_mbus_fmt, | 984 | video, s_mbus_fmt, |
985 | &mf); | 985 | &mf); |
986 | if (ret < 0) | 986 | if (ret < 0) |
987 | return ret; | 987 | return ret; |
988 | } | 988 | } |
989 | 989 | ||
990 | if (shift == 3) { | 990 | if (shift == 3) { |
991 | dev_err(dev, | 991 | dev_err(dev, |
992 | "Failed to configure the client below %ux%u\n", | 992 | "Failed to configure the client below %ux%u\n", |
993 | mf.width, mf.height); | 993 | mf.width, mf.height); |
994 | return -EIO; | 994 | return -EIO; |
995 | } | 995 | } |
996 | 996 | ||
997 | dev_dbg(dev, "camera fmt %ux%u\n", mf.width, mf.height); | 997 | dev_dbg(dev, "camera fmt %ux%u\n", mf.width, mf.height); |
998 | 998 | ||
999 | cam = kzalloc(sizeof(*cam), GFP_KERNEL); | 999 | cam = kzalloc(sizeof(*cam), GFP_KERNEL); |
1000 | if (!cam) | 1000 | if (!cam) |
1001 | return -ENOMEM; | 1001 | return -ENOMEM; |
1002 | /* | 1002 | /* |
1003 | * We are called with current camera crop, | 1003 | * We are called with current camera crop, |
1004 | * initialise subrect with it | 1004 | * initialise subrect with it |
1005 | */ | 1005 | */ |
1006 | cam->rect = rect; | 1006 | cam->rect = rect; |
1007 | cam->subrect = rect; | 1007 | cam->subrect = rect; |
1008 | cam->width = mf.width; | 1008 | cam->width = mf.width; |
1009 | cam->height = mf.height; | 1009 | cam->height = mf.height; |
1010 | 1010 | ||
1011 | icd->host_priv = cam; | 1011 | icd->host_priv = cam; |
1012 | } else { | 1012 | } else { |
1013 | cam = icd->host_priv; | 1013 | cam = icd->host_priv; |
1014 | } | 1014 | } |
1015 | 1015 | ||
1016 | /* Beginning of a pass */ | 1016 | /* Beginning of a pass */ |
1017 | if (!idx) | 1017 | if (!idx) |
1018 | cam->extra_fmt = NULL; | 1018 | cam->extra_fmt = NULL; |
1019 | 1019 | ||
1020 | switch (code) { | 1020 | switch (code) { |
1021 | case MEDIA_BUS_FMT_YUYV8_1X16: | 1021 | case MEDIA_BUS_FMT_YUYV8_1X16: |
1022 | case MEDIA_BUS_FMT_YUYV8_2X8: | 1022 | case MEDIA_BUS_FMT_YUYV8_2X8: |
1023 | case MEDIA_BUS_FMT_YUYV10_2X10: | 1023 | case MEDIA_BUS_FMT_YUYV10_2X10: |
1024 | if (cam->extra_fmt) | 1024 | if (cam->extra_fmt) |
1025 | break; | 1025 | break; |
1026 | 1026 | ||
1027 | /* Add all our formats that can be generated by VIN */ | 1027 | /* Add all our formats that can be generated by VIN */ |
1028 | cam->extra_fmt = rcar_vin_formats; | 1028 | cam->extra_fmt = rcar_vin_formats; |
1029 | 1029 | ||
1030 | n = ARRAY_SIZE(rcar_vin_formats); | 1030 | n = ARRAY_SIZE(rcar_vin_formats); |
1031 | formats += n; | 1031 | formats += n; |
1032 | for (k = 0; xlate && k < n; k++, xlate++) { | 1032 | for (k = 0; xlate && k < n; k++, xlate++) { |
1033 | xlate->host_fmt = &rcar_vin_formats[k]; | 1033 | xlate->host_fmt = &rcar_vin_formats[k]; |
1034 | xlate->code = code; | 1034 | xlate->code = code; |
1035 | dev_dbg(dev, "Providing format %s using code %d\n", | 1035 | dev_dbg(dev, "Providing format %s using code %d\n", |
1036 | rcar_vin_formats[k].name, code); | 1036 | rcar_vin_formats[k].name, code); |
1037 | } | 1037 | } |
1038 | break; | 1038 | break; |
1039 | default: | 1039 | default: |
1040 | if (!rcar_vin_packing_supported(fmt)) | 1040 | if (!rcar_vin_packing_supported(fmt)) |
1041 | return 0; | 1041 | return 0; |
1042 | 1042 | ||
1043 | dev_dbg(dev, "Providing format %s in pass-through mode\n", | 1043 | dev_dbg(dev, "Providing format %s in pass-through mode\n", |
1044 | fmt->name); | 1044 | fmt->name); |
1045 | break; | 1045 | break; |
1046 | } | 1046 | } |
1047 | 1047 | ||
1048 | /* Generic pass-through */ | 1048 | /* Generic pass-through */ |
1049 | formats++; | 1049 | formats++; |
1050 | if (xlate) { | 1050 | if (xlate) { |
1051 | xlate->host_fmt = fmt; | 1051 | xlate->host_fmt = fmt; |
1052 | xlate->code = code; | 1052 | xlate->code = code; |
1053 | xlate++; | 1053 | xlate++; |
1054 | } | 1054 | } |
1055 | 1055 | ||
1056 | return formats; | 1056 | return formats; |
1057 | } | 1057 | } |
1058 | 1058 | ||
1059 | static void rcar_vin_put_formats(struct soc_camera_device *icd) | 1059 | static void rcar_vin_put_formats(struct soc_camera_device *icd) |
1060 | { | 1060 | { |
1061 | kfree(icd->host_priv); | 1061 | kfree(icd->host_priv); |
1062 | icd->host_priv = NULL; | 1062 | icd->host_priv = NULL; |
1063 | } | 1063 | } |
1064 | 1064 | ||
1065 | static int rcar_vin_set_crop(struct soc_camera_device *icd, | 1065 | static int rcar_vin_set_crop(struct soc_camera_device *icd, |
1066 | const struct v4l2_crop *a) | 1066 | const struct v4l2_crop *a) |
1067 | { | 1067 | { |
1068 | struct v4l2_crop a_writable = *a; | 1068 | struct v4l2_crop a_writable = *a; |
1069 | const struct v4l2_rect *rect = &a_writable.c; | 1069 | const struct v4l2_rect *rect = &a_writable.c; |
1070 | struct soc_camera_host *ici = to_soc_camera_host(icd->parent); | 1070 | struct soc_camera_host *ici = to_soc_camera_host(icd->parent); |
1071 | struct rcar_vin_priv *priv = ici->priv; | 1071 | struct rcar_vin_priv *priv = ici->priv; |
1072 | struct v4l2_crop cam_crop; | 1072 | struct v4l2_crop cam_crop; |
1073 | struct rcar_vin_cam *cam = icd->host_priv; | 1073 | struct rcar_vin_cam *cam = icd->host_priv; |
1074 | struct v4l2_rect *cam_rect = &cam_crop.c; | 1074 | struct v4l2_rect *cam_rect = &cam_crop.c; |
1075 | struct v4l2_subdev *sd = soc_camera_to_subdev(icd); | 1075 | struct v4l2_subdev *sd = soc_camera_to_subdev(icd); |
1076 | struct device *dev = icd->parent; | 1076 | struct device *dev = icd->parent; |
1077 | struct v4l2_mbus_framefmt mf; | 1077 | struct v4l2_mbus_framefmt mf; |
1078 | u32 vnmc; | 1078 | u32 vnmc; |
1079 | int ret, i; | 1079 | int ret, i; |
1080 | 1080 | ||
1081 | dev_dbg(dev, "S_CROP(%ux%u@%u:%u)\n", rect->width, rect->height, | 1081 | dev_dbg(dev, "S_CROP(%ux%u@%u:%u)\n", rect->width, rect->height, |
1082 | rect->left, rect->top); | 1082 | rect->left, rect->top); |
1083 | 1083 | ||
1084 | /* During camera cropping its output window can change too, stop VIN */ | 1084 | /* During camera cropping its output window can change too, stop VIN */ |
1085 | capture_stop_preserve(priv, &vnmc); | 1085 | capture_stop_preserve(priv, &vnmc); |
1086 | dev_dbg(dev, "VNMC_REG 0x%x\n", vnmc); | 1086 | dev_dbg(dev, "VNMC_REG 0x%x\n", vnmc); |
1087 | 1087 | ||
1088 | /* Apply iterative camera S_CROP for new input window. */ | 1088 | /* Apply iterative camera S_CROP for new input window. */ |
1089 | ret = soc_camera_client_s_crop(sd, &a_writable, &cam_crop, | 1089 | ret = soc_camera_client_s_crop(sd, &a_writable, &cam_crop, |
1090 | &cam->rect, &cam->subrect); | 1090 | &cam->rect, &cam->subrect); |
1091 | if (ret < 0) | 1091 | if (ret < 0) |
1092 | return ret; | 1092 | return ret; |
1093 | 1093 | ||
1094 | dev_dbg(dev, "camera cropped to %ux%u@%u:%u\n", | 1094 | dev_dbg(dev, "camera cropped to %ux%u@%u:%u\n", |
1095 | cam_rect->width, cam_rect->height, | 1095 | cam_rect->width, cam_rect->height, |
1096 | cam_rect->left, cam_rect->top); | 1096 | cam_rect->left, cam_rect->top); |
1097 | 1097 | ||
1098 | /* On success cam_crop contains current camera crop */ | 1098 | /* On success cam_crop contains current camera crop */ |
1099 | 1099 | ||
1100 | /* Retrieve camera output window */ | 1100 | /* Retrieve camera output window */ |
1101 | ret = v4l2_subdev_call(sd, video, g_mbus_fmt, &mf); | 1101 | ret = v4l2_subdev_call(sd, video, g_mbus_fmt, &mf); |
1102 | if (ret < 0) | 1102 | if (ret < 0) |
1103 | return ret; | 1103 | return ret; |
1104 | 1104 | ||
1105 | if (mf.width > VIN_MAX_WIDTH || mf.height > VIN_MAX_HEIGHT) | 1105 | if (mf.width > VIN_MAX_WIDTH || mf.height > VIN_MAX_HEIGHT) |
1106 | return -EINVAL; | 1106 | return -EINVAL; |
1107 | 1107 | ||
1108 | /* Cache camera output window */ | 1108 | /* Cache camera output window */ |
1109 | cam->width = mf.width; | 1109 | cam->width = mf.width; |
1110 | cam->height = mf.height; | 1110 | cam->height = mf.height; |
1111 | 1111 | ||
1112 | icd->user_width = cam->width; | 1112 | icd->user_width = cam->width; |
1113 | icd->user_height = cam->height; | 1113 | icd->user_height = cam->height; |
1114 | 1114 | ||
1115 | cam->vin_left = rect->left & ~1; | 1115 | cam->vin_left = rect->left & ~1; |
1116 | cam->vin_top = rect->top & ~1; | 1116 | cam->vin_top = rect->top & ~1; |
1117 | 1117 | ||
1118 | /* Use VIN cropping to crop to the new window. */ | 1118 | /* Use VIN cropping to crop to the new window. */ |
1119 | ret = rcar_vin_set_rect(icd); | 1119 | ret = rcar_vin_set_rect(icd); |
1120 | if (ret < 0) | 1120 | if (ret < 0) |
1121 | return ret; | 1121 | return ret; |
1122 | 1122 | ||
1123 | cam->subrect = *rect; | 1123 | cam->subrect = *rect; |
1124 | 1124 | ||
1125 | dev_dbg(dev, "VIN cropped to %ux%u@%u:%u\n", | 1125 | dev_dbg(dev, "VIN cropped to %ux%u@%u:%u\n", |
1126 | icd->user_width, icd->user_height, | 1126 | icd->user_width, icd->user_height, |
1127 | cam->vin_left, cam->vin_top); | 1127 | cam->vin_left, cam->vin_top); |
1128 | 1128 | ||
1129 | /* Restore capture */ | 1129 | /* Restore capture */ |
1130 | for (i = 0; i < MAX_BUFFER_NUM; i++) { | 1130 | for (i = 0; i < MAX_BUFFER_NUM; i++) { |
1131 | if (priv->queue_buf[i] && priv->state == STOPPED) { | 1131 | if (priv->queue_buf[i] && priv->state == STOPPED) { |
1132 | vnmc |= VNMC_ME; | 1132 | vnmc |= VNMC_ME; |
1133 | break; | 1133 | break; |
1134 | } | 1134 | } |
1135 | } | 1135 | } |
1136 | capture_restore(priv, vnmc); | 1136 | capture_restore(priv, vnmc); |
1137 | 1137 | ||
1138 | /* Even if only camera cropping succeeded */ | 1138 | /* Even if only camera cropping succeeded */ |
1139 | return ret; | 1139 | return ret; |
1140 | } | 1140 | } |
1141 | 1141 | ||
1142 | static int rcar_vin_get_crop(struct soc_camera_device *icd, | 1142 | static int rcar_vin_get_crop(struct soc_camera_device *icd, |
1143 | struct v4l2_crop *a) | 1143 | struct v4l2_crop *a) |
1144 | { | 1144 | { |
1145 | struct rcar_vin_cam *cam = icd->host_priv; | 1145 | struct rcar_vin_cam *cam = icd->host_priv; |
1146 | 1146 | ||
1147 | a->type = V4L2_BUF_TYPE_VIDEO_CAPTURE; | 1147 | a->type = V4L2_BUF_TYPE_VIDEO_CAPTURE; |
1148 | a->c = cam->subrect; | 1148 | a->c = cam->subrect; |
1149 | 1149 | ||
1150 | return 0; | 1150 | return 0; |
1151 | } | 1151 | } |
1152 | 1152 | ||
1153 | /* Similar to set_crop multistage iterative algorithm */ | 1153 | /* Similar to set_crop multistage iterative algorithm */ |
1154 | static int rcar_vin_set_fmt(struct soc_camera_device *icd, | 1154 | static int rcar_vin_set_fmt(struct soc_camera_device *icd, |
1155 | struct v4l2_format *f) | 1155 | struct v4l2_format *f) |
1156 | { | 1156 | { |
1157 | struct soc_camera_host *ici = to_soc_camera_host(icd->parent); | 1157 | struct soc_camera_host *ici = to_soc_camera_host(icd->parent); |
1158 | struct rcar_vin_priv *priv = ici->priv; | 1158 | struct rcar_vin_priv *priv = ici->priv; |
1159 | struct v4l2_subdev *sd = soc_camera_to_subdev(icd); | 1159 | struct v4l2_subdev *sd = soc_camera_to_subdev(icd); |
1160 | struct rcar_vin_cam *cam = icd->host_priv; | 1160 | struct rcar_vin_cam *cam = icd->host_priv; |
1161 | struct v4l2_pix_format *pix = &f->fmt.pix; | 1161 | struct v4l2_pix_format *pix = &f->fmt.pix; |
1162 | struct v4l2_mbus_framefmt mf; | 1162 | struct v4l2_mbus_framefmt mf; |
1163 | struct device *dev = icd->parent; | 1163 | struct device *dev = icd->parent; |
1164 | __u32 pixfmt = pix->pixelformat; | 1164 | __u32 pixfmt = pix->pixelformat; |
1165 | const struct soc_camera_format_xlate *xlate; | 1165 | const struct soc_camera_format_xlate *xlate; |
1166 | unsigned int vin_sub_width = 0, vin_sub_height = 0; | 1166 | unsigned int vin_sub_width = 0, vin_sub_height = 0; |
1167 | int ret; | 1167 | int ret; |
1168 | bool can_scale; | 1168 | bool can_scale; |
1169 | enum v4l2_field field; | 1169 | enum v4l2_field field; |
1170 | v4l2_std_id std; | 1170 | v4l2_std_id std; |
1171 | 1171 | ||
1172 | dev_dbg(dev, "S_FMT(pix=0x%x, %ux%u)\n", | 1172 | dev_dbg(dev, "S_FMT(pix=0x%x, %ux%u)\n", |
1173 | pixfmt, pix->width, pix->height); | 1173 | pixfmt, pix->width, pix->height); |
1174 | 1174 | ||
1175 | switch (pix->field) { | 1175 | switch (pix->field) { |
1176 | default: | 1176 | default: |
1177 | pix->field = V4L2_FIELD_NONE; | 1177 | pix->field = V4L2_FIELD_NONE; |
1178 | /* fall-through */ | 1178 | /* fall-through */ |
1179 | case V4L2_FIELD_NONE: | 1179 | case V4L2_FIELD_NONE: |
1180 | case V4L2_FIELD_TOP: | 1180 | case V4L2_FIELD_TOP: |
1181 | case V4L2_FIELD_BOTTOM: | 1181 | case V4L2_FIELD_BOTTOM: |
1182 | case V4L2_FIELD_INTERLACED_TB: | 1182 | case V4L2_FIELD_INTERLACED_TB: |
1183 | case V4L2_FIELD_INTERLACED_BT: | 1183 | case V4L2_FIELD_INTERLACED_BT: |
1184 | field = pix->field; | 1184 | field = pix->field; |
1185 | break; | 1185 | break; |
1186 | case V4L2_FIELD_INTERLACED: | 1186 | case V4L2_FIELD_INTERLACED: |
1187 | /* Query for standard if not explicitly mentioned _TB/_BT */ | 1187 | /* Query for standard if not explicitly mentioned _TB/_BT */ |
1188 | ret = v4l2_subdev_call(sd, video, querystd, &std); | 1188 | ret = v4l2_subdev_call(sd, video, querystd, &std); |
1189 | if (ret < 0) | 1189 | if (ret < 0) |
1190 | std = V4L2_STD_625_50; | 1190 | std = V4L2_STD_625_50; |
1191 | 1191 | ||
1192 | field = std & V4L2_STD_625_50 ? V4L2_FIELD_INTERLACED_TB : | 1192 | field = std & V4L2_STD_625_50 ? V4L2_FIELD_INTERLACED_TB : |
1193 | V4L2_FIELD_INTERLACED_BT; | 1193 | V4L2_FIELD_INTERLACED_BT; |
1194 | break; | 1194 | break; |
1195 | } | 1195 | } |
1196 | 1196 | ||
1197 | xlate = soc_camera_xlate_by_fourcc(icd, pixfmt); | 1197 | xlate = soc_camera_xlate_by_fourcc(icd, pixfmt); |
1198 | if (!xlate) { | 1198 | if (!xlate) { |
1199 | dev_warn(dev, "Format %x not found\n", pixfmt); | 1199 | dev_warn(dev, "Format %x not found\n", pixfmt); |
1200 | return -EINVAL; | 1200 | return -EINVAL; |
1201 | } | 1201 | } |
1202 | /* Calculate client output geometry */ | 1202 | /* Calculate client output geometry */ |
1203 | soc_camera_calc_client_output(icd, &cam->rect, &cam->subrect, pix, &mf, | 1203 | soc_camera_calc_client_output(icd, &cam->rect, &cam->subrect, pix, &mf, |
1204 | 12); | 1204 | 12); |
1205 | mf.field = pix->field; | 1205 | mf.field = pix->field; |
1206 | mf.colorspace = pix->colorspace; | 1206 | mf.colorspace = pix->colorspace; |
1207 | mf.code = xlate->code; | 1207 | mf.code = xlate->code; |
1208 | 1208 | ||
1209 | switch (pixfmt) { | 1209 | switch (pixfmt) { |
1210 | case V4L2_PIX_FMT_RGB32: | 1210 | case V4L2_PIX_FMT_RGB32: |
1211 | can_scale = priv->chip != RCAR_E1; | 1211 | can_scale = priv->chip != RCAR_E1; |
1212 | break; | 1212 | break; |
1213 | case V4L2_PIX_FMT_UYVY: | 1213 | case V4L2_PIX_FMT_UYVY: |
1214 | case V4L2_PIX_FMT_YUYV: | 1214 | case V4L2_PIX_FMT_YUYV: |
1215 | case V4L2_PIX_FMT_RGB565: | 1215 | case V4L2_PIX_FMT_RGB565: |
1216 | case V4L2_PIX_FMT_RGB555X: | 1216 | case V4L2_PIX_FMT_RGB555X: |
1217 | can_scale = true; | 1217 | can_scale = true; |
1218 | break; | 1218 | break; |
1219 | default: | 1219 | default: |
1220 | can_scale = false; | 1220 | can_scale = false; |
1221 | break; | 1221 | break; |
1222 | } | 1222 | } |
1223 | 1223 | ||
1224 | dev_dbg(dev, "request camera output %ux%u\n", mf.width, mf.height); | 1224 | dev_dbg(dev, "request camera output %ux%u\n", mf.width, mf.height); |
1225 | 1225 | ||
1226 | ret = soc_camera_client_scale(icd, &cam->rect, &cam->subrect, | 1226 | ret = soc_camera_client_scale(icd, &cam->rect, &cam->subrect, |
1227 | &mf, &vin_sub_width, &vin_sub_height, | 1227 | &mf, &vin_sub_width, &vin_sub_height, |
1228 | can_scale, 12); | 1228 | can_scale, 12); |
1229 | 1229 | ||
1230 | /* Done with the camera. Now see if we can improve the result */ | 1230 | /* Done with the camera. Now see if we can improve the result */ |
1231 | dev_dbg(dev, "Camera %d fmt %ux%u, requested %ux%u\n", | 1231 | dev_dbg(dev, "Camera %d fmt %ux%u, requested %ux%u\n", |
1232 | ret, mf.width, mf.height, pix->width, pix->height); | 1232 | ret, mf.width, mf.height, pix->width, pix->height); |
1233 | 1233 | ||
1234 | if (ret == -ENOIOCTLCMD) | 1234 | if (ret == -ENOIOCTLCMD) |
1235 | dev_dbg(dev, "Sensor doesn't support scaling\n"); | 1235 | dev_dbg(dev, "Sensor doesn't support scaling\n"); |
1236 | else if (ret < 0) | 1236 | else if (ret < 0) |
1237 | return ret; | 1237 | return ret; |
1238 | 1238 | ||
1239 | if (mf.code != xlate->code) | 1239 | if (mf.code != xlate->code) |
1240 | return -EINVAL; | 1240 | return -EINVAL; |
1241 | 1241 | ||
1242 | /* Prepare VIN crop */ | 1242 | /* Prepare VIN crop */ |
1243 | cam->width = mf.width; | 1243 | cam->width = mf.width; |
1244 | cam->height = mf.height; | 1244 | cam->height = mf.height; |
1245 | 1245 | ||
1246 | /* Use VIN scaling to scale to the requested user window. */ | 1246 | /* Use VIN scaling to scale to the requested user window. */ |
1247 | 1247 | ||
1248 | /* We cannot scale up */ | 1248 | /* We cannot scale up */ |
1249 | if (pix->width > vin_sub_width) | 1249 | if (pix->width > vin_sub_width) |
1250 | vin_sub_width = pix->width; | 1250 | vin_sub_width = pix->width; |
1251 | 1251 | ||
1252 | if (pix->height > vin_sub_height) | 1252 | if (pix->height > vin_sub_height) |
1253 | vin_sub_height = pix->height; | 1253 | vin_sub_height = pix->height; |
1254 | 1254 | ||
1255 | pix->colorspace = mf.colorspace; | 1255 | pix->colorspace = mf.colorspace; |
1256 | 1256 | ||
1257 | if (!can_scale) { | 1257 | if (!can_scale) { |
1258 | pix->width = vin_sub_width; | 1258 | pix->width = vin_sub_width; |
1259 | pix->height = vin_sub_height; | 1259 | pix->height = vin_sub_height; |
1260 | } | 1260 | } |
1261 | 1261 | ||
1262 | /* | 1262 | /* |
1263 | * We have calculated CFLCR, the actual configuration will be performed | 1263 | * We have calculated CFLCR, the actual configuration will be performed |
1264 | * in rcar_vin_set_bus_param() | 1264 | * in rcar_vin_set_bus_param() |
1265 | */ | 1265 | */ |
1266 | 1266 | ||
1267 | dev_dbg(dev, "W: %u : %u, H: %u : %u\n", | 1267 | dev_dbg(dev, "W: %u : %u, H: %u : %u\n", |
1268 | vin_sub_width, pix->width, vin_sub_height, pix->height); | 1268 | vin_sub_width, pix->width, vin_sub_height, pix->height); |
1269 | 1269 | ||
1270 | icd->current_fmt = xlate; | 1270 | icd->current_fmt = xlate; |
1271 | 1271 | ||
1272 | priv->field = field; | 1272 | priv->field = field; |
1273 | 1273 | ||
1274 | return 0; | 1274 | return 0; |
1275 | } | 1275 | } |
1276 | 1276 | ||
1277 | static int rcar_vin_try_fmt(struct soc_camera_device *icd, | 1277 | static int rcar_vin_try_fmt(struct soc_camera_device *icd, |
1278 | struct v4l2_format *f) | 1278 | struct v4l2_format *f) |
1279 | { | 1279 | { |
1280 | const struct soc_camera_format_xlate *xlate; | 1280 | const struct soc_camera_format_xlate *xlate; |
1281 | struct v4l2_pix_format *pix = &f->fmt.pix; | 1281 | struct v4l2_pix_format *pix = &f->fmt.pix; |
1282 | struct v4l2_subdev *sd = soc_camera_to_subdev(icd); | 1282 | struct v4l2_subdev *sd = soc_camera_to_subdev(icd); |
1283 | struct v4l2_mbus_framefmt mf; | 1283 | struct v4l2_mbus_framefmt mf; |
1284 | __u32 pixfmt = pix->pixelformat; | 1284 | __u32 pixfmt = pix->pixelformat; |
1285 | int width, height; | 1285 | int width, height; |
1286 | int ret; | 1286 | int ret; |
1287 | 1287 | ||
1288 | xlate = soc_camera_xlate_by_fourcc(icd, pixfmt); | 1288 | xlate = soc_camera_xlate_by_fourcc(icd, pixfmt); |
1289 | if (!xlate) { | 1289 | if (!xlate) { |
1290 | xlate = icd->current_fmt; | 1290 | xlate = icd->current_fmt; |
1291 | dev_dbg(icd->parent, "Format %x not found, keeping %x\n", | 1291 | dev_dbg(icd->parent, "Format %x not found, keeping %x\n", |
1292 | pixfmt, xlate->host_fmt->fourcc); | 1292 | pixfmt, xlate->host_fmt->fourcc); |
1293 | pixfmt = xlate->host_fmt->fourcc; | 1293 | pixfmt = xlate->host_fmt->fourcc; |
1294 | pix->pixelformat = pixfmt; | 1294 | pix->pixelformat = pixfmt; |
1295 | pix->colorspace = icd->colorspace; | 1295 | pix->colorspace = icd->colorspace; |
1296 | } | 1296 | } |
1297 | 1297 | ||
1298 | /* FIXME: calculate using depth and bus width */ | 1298 | /* FIXME: calculate using depth and bus width */ |
1299 | v4l_bound_align_image(&pix->width, 2, VIN_MAX_WIDTH, 1, | 1299 | v4l_bound_align_image(&pix->width, 2, VIN_MAX_WIDTH, 1, |
1300 | &pix->height, 4, VIN_MAX_HEIGHT, 2, 0); | 1300 | &pix->height, 4, VIN_MAX_HEIGHT, 2, 0); |
1301 | 1301 | ||
1302 | width = pix->width; | 1302 | width = pix->width; |
1303 | height = pix->height; | 1303 | height = pix->height; |
1304 | 1304 | ||
1305 | /* let soc-camera calculate these values */ | 1305 | /* let soc-camera calculate these values */ |
1306 | pix->bytesperline = 0; | 1306 | pix->bytesperline = 0; |
1307 | pix->sizeimage = 0; | 1307 | pix->sizeimage = 0; |
1308 | 1308 | ||
1309 | /* limit to sensor capabilities */ | 1309 | /* limit to sensor capabilities */ |
1310 | mf.width = pix->width; | 1310 | mf.width = pix->width; |
1311 | mf.height = pix->height; | 1311 | mf.height = pix->height; |
1312 | mf.field = pix->field; | 1312 | mf.field = pix->field; |
1313 | mf.code = xlate->code; | 1313 | mf.code = xlate->code; |
1314 | mf.colorspace = pix->colorspace; | 1314 | mf.colorspace = pix->colorspace; |
1315 | 1315 | ||
1316 | ret = v4l2_device_call_until_err(sd->v4l2_dev, soc_camera_grp_id(icd), | 1316 | ret = v4l2_device_call_until_err(sd->v4l2_dev, soc_camera_grp_id(icd), |
1317 | video, try_mbus_fmt, &mf); | 1317 | video, try_mbus_fmt, &mf); |
1318 | if (ret < 0) | 1318 | if (ret < 0) |
1319 | return ret; | 1319 | return ret; |
1320 | 1320 | ||
1321 | pix->width = mf.width; | 1321 | pix->width = mf.width; |
1322 | pix->height = mf.height; | 1322 | pix->height = mf.height; |
1323 | pix->field = mf.field; | 1323 | pix->field = mf.field; |
1324 | pix->colorspace = mf.colorspace; | 1324 | pix->colorspace = mf.colorspace; |
1325 | 1325 | ||
1326 | if (pixfmt == V4L2_PIX_FMT_NV16) { | 1326 | if (pixfmt == V4L2_PIX_FMT_NV16) { |
1327 | /* FIXME: check against rect_max after converting soc-camera */ | 1327 | /* FIXME: check against rect_max after converting soc-camera */ |
1328 | /* We can scale precisely, need a bigger image from camera */ | 1328 | /* We can scale precisely, need a bigger image from camera */ |
1329 | if (pix->width < width || pix->height < height) { | 1329 | if (pix->width < width || pix->height < height) { |
1330 | /* | 1330 | /* |
1331 | * We presume, the sensor behaves sanely, i.e. if | 1331 | * We presume, the sensor behaves sanely, i.e. if |
1332 | * requested a bigger rectangle, it will not return a | 1332 | * requested a bigger rectangle, it will not return a |
1333 | * smaller one. | 1333 | * smaller one. |
1334 | */ | 1334 | */ |
1335 | mf.width = VIN_MAX_WIDTH; | 1335 | mf.width = VIN_MAX_WIDTH; |
1336 | mf.height = VIN_MAX_HEIGHT; | 1336 | mf.height = VIN_MAX_HEIGHT; |
1337 | ret = v4l2_device_call_until_err(sd->v4l2_dev, | 1337 | ret = v4l2_device_call_until_err(sd->v4l2_dev, |
1338 | soc_camera_grp_id(icd), | 1338 | soc_camera_grp_id(icd), |
1339 | video, try_mbus_fmt, | 1339 | video, try_mbus_fmt, |
1340 | &mf); | 1340 | &mf); |
1341 | if (ret < 0) { | 1341 | if (ret < 0) { |
1342 | dev_err(icd->parent, | 1342 | dev_err(icd->parent, |
1343 | "client try_fmt() = %d\n", ret); | 1343 | "client try_fmt() = %d\n", ret); |
1344 | return ret; | 1344 | return ret; |
1345 | } | 1345 | } |
1346 | } | 1346 | } |
1347 | /* We will scale exactly */ | 1347 | /* We will scale exactly */ |
1348 | if (mf.width > width) | 1348 | if (mf.width > width) |
1349 | pix->width = width; | 1349 | pix->width = width; |
1350 | if (mf.height > height) | 1350 | if (mf.height > height) |
1351 | pix->height = height; | 1351 | pix->height = height; |
1352 | } | 1352 | } |
1353 | 1353 | ||
1354 | return ret; | 1354 | return ret; |
1355 | } | 1355 | } |
1356 | 1356 | ||
1357 | static unsigned int rcar_vin_poll(struct file *file, poll_table *pt) | 1357 | static unsigned int rcar_vin_poll(struct file *file, poll_table *pt) |
1358 | { | 1358 | { |
1359 | struct soc_camera_device *icd = file->private_data; | 1359 | struct soc_camera_device *icd = file->private_data; |
1360 | 1360 | ||
1361 | return vb2_poll(&icd->vb2_vidq, file, pt); | 1361 | return vb2_poll(&icd->vb2_vidq, file, pt); |
1362 | } | 1362 | } |
1363 | 1363 | ||
1364 | static int rcar_vin_querycap(struct soc_camera_host *ici, | 1364 | static int rcar_vin_querycap(struct soc_camera_host *ici, |
1365 | struct v4l2_capability *cap) | 1365 | struct v4l2_capability *cap) |
1366 | { | 1366 | { |
1367 | strlcpy(cap->card, "R_Car_VIN", sizeof(cap->card)); | 1367 | strlcpy(cap->card, "R_Car_VIN", sizeof(cap->card)); |
1368 | cap->capabilities = V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_STREAMING; | 1368 | cap->capabilities = V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_STREAMING; |
1369 | return 0; | 1369 | return 0; |
1370 | } | 1370 | } |
1371 | 1371 | ||
1372 | static int rcar_vin_init_videobuf2(struct vb2_queue *vq, | 1372 | static int rcar_vin_init_videobuf2(struct vb2_queue *vq, |
1373 | struct soc_camera_device *icd) | 1373 | struct soc_camera_device *icd) |
1374 | { | 1374 | { |
1375 | vq->type = V4L2_BUF_TYPE_VIDEO_CAPTURE; | 1375 | vq->type = V4L2_BUF_TYPE_VIDEO_CAPTURE; |
1376 | vq->io_modes = VB2_MMAP | VB2_USERPTR; | 1376 | vq->io_modes = VB2_MMAP | VB2_USERPTR; |
1377 | vq->drv_priv = icd; | 1377 | vq->drv_priv = icd; |
1378 | vq->ops = &rcar_vin_vb2_ops; | 1378 | vq->ops = &rcar_vin_vb2_ops; |
1379 | vq->mem_ops = &vb2_dma_contig_memops; | 1379 | vq->mem_ops = &vb2_dma_contig_memops; |
1380 | vq->buf_struct_size = sizeof(struct rcar_vin_buffer); | 1380 | vq->buf_struct_size = sizeof(struct rcar_vin_buffer); |
1381 | vq->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC; | 1381 | vq->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC; |
1382 | 1382 | ||
1383 | return vb2_queue_init(vq); | 1383 | return vb2_queue_init(vq); |
1384 | } | 1384 | } |
1385 | 1385 | ||
1386 | static struct soc_camera_host_ops rcar_vin_host_ops = { | 1386 | static struct soc_camera_host_ops rcar_vin_host_ops = { |
1387 | .owner = THIS_MODULE, | 1387 | .owner = THIS_MODULE, |
1388 | .add = rcar_vin_add_device, | 1388 | .add = rcar_vin_add_device, |
1389 | .remove = rcar_vin_remove_device, | 1389 | .remove = rcar_vin_remove_device, |
1390 | .clock_start = rcar_vin_clock_start, | 1390 | .clock_start = rcar_vin_clock_start, |
1391 | .clock_stop = rcar_vin_clock_stop, | 1391 | .clock_stop = rcar_vin_clock_stop, |
1392 | .get_formats = rcar_vin_get_formats, | 1392 | .get_formats = rcar_vin_get_formats, |
1393 | .put_formats = rcar_vin_put_formats, | 1393 | .put_formats = rcar_vin_put_formats, |
1394 | .get_crop = rcar_vin_get_crop, | 1394 | .get_crop = rcar_vin_get_crop, |
1395 | .set_crop = rcar_vin_set_crop, | 1395 | .set_crop = rcar_vin_set_crop, |
1396 | .try_fmt = rcar_vin_try_fmt, | 1396 | .try_fmt = rcar_vin_try_fmt, |
1397 | .set_fmt = rcar_vin_set_fmt, | 1397 | .set_fmt = rcar_vin_set_fmt, |
1398 | .poll = rcar_vin_poll, | 1398 | .poll = rcar_vin_poll, |
1399 | .querycap = rcar_vin_querycap, | 1399 | .querycap = rcar_vin_querycap, |
1400 | .set_bus_param = rcar_vin_set_bus_param, | 1400 | .set_bus_param = rcar_vin_set_bus_param, |
1401 | .init_videobuf2 = rcar_vin_init_videobuf2, | 1401 | .init_videobuf2 = rcar_vin_init_videobuf2, |
1402 | }; | 1402 | }; |
1403 | 1403 | ||
1404 | #ifdef CONFIG_OF | 1404 | #ifdef CONFIG_OF |
1405 | static struct of_device_id rcar_vin_of_table[] = { | 1405 | static struct of_device_id rcar_vin_of_table[] = { |
1406 | { .compatible = "renesas,vin-r8a7794", .data = (void *)RCAR_GEN2 }, | ||
1407 | { .compatible = "renesas,vin-r8a7793", .data = (void *)RCAR_GEN2 }, | ||
1406 | { .compatible = "renesas,vin-r8a7791", .data = (void *)RCAR_GEN2 }, | 1408 | { .compatible = "renesas,vin-r8a7791", .data = (void *)RCAR_GEN2 }, |
1407 | { .compatible = "renesas,vin-r8a7790", .data = (void *)RCAR_GEN2 }, | 1409 | { .compatible = "renesas,vin-r8a7790", .data = (void *)RCAR_GEN2 }, |
1408 | { .compatible = "renesas,vin-r8a7779", .data = (void *)RCAR_H1 }, | 1410 | { .compatible = "renesas,vin-r8a7779", .data = (void *)RCAR_H1 }, |
1409 | { .compatible = "renesas,vin-r8a7778", .data = (void *)RCAR_M1 }, | 1411 | { .compatible = "renesas,vin-r8a7778", .data = (void *)RCAR_M1 }, |
1410 | { }, | 1412 | { }, |
1411 | }; | 1413 | }; |
1412 | MODULE_DEVICE_TABLE(of, rcar_vin_of_table); | 1414 | MODULE_DEVICE_TABLE(of, rcar_vin_of_table); |
1413 | #endif | 1415 | #endif |
1414 | 1416 | ||
1415 | static struct platform_device_id rcar_vin_id_table[] = { | 1417 | static struct platform_device_id rcar_vin_id_table[] = { |
1416 | { "r8a7791-vin", RCAR_GEN2 }, | 1418 | { "r8a7791-vin", RCAR_GEN2 }, |
1417 | { "r8a7790-vin", RCAR_GEN2 }, | 1419 | { "r8a7790-vin", RCAR_GEN2 }, |
1418 | { "r8a7779-vin", RCAR_H1 }, | 1420 | { "r8a7779-vin", RCAR_H1 }, |
1419 | { "r8a7778-vin", RCAR_M1 }, | 1421 | { "r8a7778-vin", RCAR_M1 }, |
1420 | { "uPD35004-vin", RCAR_E1 }, | 1422 | { "uPD35004-vin", RCAR_E1 }, |
1421 | {}, | 1423 | {}, |
1422 | }; | 1424 | }; |
1423 | MODULE_DEVICE_TABLE(platform, rcar_vin_id_table); | 1425 | MODULE_DEVICE_TABLE(platform, rcar_vin_id_table); |
1424 | 1426 | ||
1425 | static int rcar_vin_probe(struct platform_device *pdev) | 1427 | static int rcar_vin_probe(struct platform_device *pdev) |
1426 | { | 1428 | { |
1427 | const struct of_device_id *match = NULL; | 1429 | const struct of_device_id *match = NULL; |
1428 | struct rcar_vin_priv *priv; | 1430 | struct rcar_vin_priv *priv; |
1429 | struct resource *mem; | 1431 | struct resource *mem; |
1430 | struct rcar_vin_platform_data *pdata; | 1432 | struct rcar_vin_platform_data *pdata; |
1431 | unsigned int pdata_flags; | 1433 | unsigned int pdata_flags; |
1432 | int irq, ret; | 1434 | int irq, ret; |
1433 | 1435 | ||
1434 | if (pdev->dev.of_node) { | 1436 | if (pdev->dev.of_node) { |
1435 | struct v4l2_of_endpoint ep; | 1437 | struct v4l2_of_endpoint ep; |
1436 | struct device_node *np; | 1438 | struct device_node *np; |
1437 | 1439 | ||
1438 | match = of_match_device(of_match_ptr(rcar_vin_of_table), | 1440 | match = of_match_device(of_match_ptr(rcar_vin_of_table), |
1439 | &pdev->dev); | 1441 | &pdev->dev); |
1440 | 1442 | ||
1441 | np = of_graph_get_next_endpoint(pdev->dev.of_node, NULL); | 1443 | np = of_graph_get_next_endpoint(pdev->dev.of_node, NULL); |
1442 | if (!np) { | 1444 | if (!np) { |
1443 | dev_err(&pdev->dev, "could not find endpoint\n"); | 1445 | dev_err(&pdev->dev, "could not find endpoint\n"); |
1444 | return -EINVAL; | 1446 | return -EINVAL; |
1445 | } | 1447 | } |
1446 | 1448 | ||
1447 | ret = v4l2_of_parse_endpoint(np, &ep); | 1449 | ret = v4l2_of_parse_endpoint(np, &ep); |
1448 | if (ret) { | 1450 | if (ret) { |
1449 | dev_err(&pdev->dev, "could not parse endpoint\n"); | 1451 | dev_err(&pdev->dev, "could not parse endpoint\n"); |
1450 | return ret; | 1452 | return ret; |
1451 | } | 1453 | } |
1452 | 1454 | ||
1453 | if (ep.bus_type == V4L2_MBUS_BT656) | 1455 | if (ep.bus_type == V4L2_MBUS_BT656) |
1454 | pdata_flags = RCAR_VIN_BT656; | 1456 | pdata_flags = RCAR_VIN_BT656; |
1455 | else { | 1457 | else { |
1456 | pdata_flags = 0; | 1458 | pdata_flags = 0; |
1457 | if (ep.bus.parallel.flags & V4L2_MBUS_HSYNC_ACTIVE_LOW) | 1459 | if (ep.bus.parallel.flags & V4L2_MBUS_HSYNC_ACTIVE_LOW) |
1458 | pdata_flags |= RCAR_VIN_HSYNC_ACTIVE_LOW; | 1460 | pdata_flags |= RCAR_VIN_HSYNC_ACTIVE_LOW; |
1459 | if (ep.bus.parallel.flags & V4L2_MBUS_VSYNC_ACTIVE_LOW) | 1461 | if (ep.bus.parallel.flags & V4L2_MBUS_VSYNC_ACTIVE_LOW) |
1460 | pdata_flags |= RCAR_VIN_VSYNC_ACTIVE_LOW; | 1462 | pdata_flags |= RCAR_VIN_VSYNC_ACTIVE_LOW; |
1461 | } | 1463 | } |
1462 | 1464 | ||
1463 | of_node_put(np); | 1465 | of_node_put(np); |
1464 | 1466 | ||
1465 | dev_dbg(&pdev->dev, "pdata_flags = %08x\n", pdata_flags); | 1467 | dev_dbg(&pdev->dev, "pdata_flags = %08x\n", pdata_flags); |
1466 | } else { | 1468 | } else { |
1467 | pdata = pdev->dev.platform_data; | 1469 | pdata = pdev->dev.platform_data; |
1468 | if (!pdata || !pdata->flags) { | 1470 | if (!pdata || !pdata->flags) { |
1469 | dev_err(&pdev->dev, "platform data not set\n"); | 1471 | dev_err(&pdev->dev, "platform data not set\n"); |
1470 | return -EINVAL; | 1472 | return -EINVAL; |
1471 | } | 1473 | } |
1472 | pdata_flags = pdata->flags; | 1474 | pdata_flags = pdata->flags; |
1473 | } | 1475 | } |
1474 | 1476 | ||
1475 | mem = platform_get_resource(pdev, IORESOURCE_MEM, 0); | 1477 | mem = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
1476 | if (mem == NULL) | 1478 | if (mem == NULL) |
1477 | return -EINVAL; | 1479 | return -EINVAL; |
1478 | 1480 | ||
1479 | irq = platform_get_irq(pdev, 0); | 1481 | irq = platform_get_irq(pdev, 0); |
1480 | if (irq <= 0) | 1482 | if (irq <= 0) |
1481 | return -EINVAL; | 1483 | return -EINVAL; |
1482 | 1484 | ||
1483 | priv = devm_kzalloc(&pdev->dev, sizeof(struct rcar_vin_priv), | 1485 | priv = devm_kzalloc(&pdev->dev, sizeof(struct rcar_vin_priv), |
1484 | GFP_KERNEL); | 1486 | GFP_KERNEL); |
1485 | if (!priv) | 1487 | if (!priv) |
1486 | return -ENOMEM; | 1488 | return -ENOMEM; |
1487 | 1489 | ||
1488 | priv->base = devm_ioremap_resource(&pdev->dev, mem); | 1490 | priv->base = devm_ioremap_resource(&pdev->dev, mem); |
1489 | if (IS_ERR(priv->base)) | 1491 | if (IS_ERR(priv->base)) |
1490 | return PTR_ERR(priv->base); | 1492 | return PTR_ERR(priv->base); |
1491 | 1493 | ||
1492 | ret = devm_request_irq(&pdev->dev, irq, rcar_vin_irq, IRQF_SHARED, | 1494 | ret = devm_request_irq(&pdev->dev, irq, rcar_vin_irq, IRQF_SHARED, |
1493 | dev_name(&pdev->dev), priv); | 1495 | dev_name(&pdev->dev), priv); |
1494 | if (ret) | 1496 | if (ret) |
1495 | return ret; | 1497 | return ret; |
1496 | 1498 | ||
1497 | priv->alloc_ctx = vb2_dma_contig_init_ctx(&pdev->dev); | 1499 | priv->alloc_ctx = vb2_dma_contig_init_ctx(&pdev->dev); |
1498 | if (IS_ERR(priv->alloc_ctx)) | 1500 | if (IS_ERR(priv->alloc_ctx)) |
1499 | return PTR_ERR(priv->alloc_ctx); | 1501 | return PTR_ERR(priv->alloc_ctx); |
1500 | 1502 | ||
1501 | priv->ici.priv = priv; | 1503 | priv->ici.priv = priv; |
1502 | priv->ici.v4l2_dev.dev = &pdev->dev; | 1504 | priv->ici.v4l2_dev.dev = &pdev->dev; |
1503 | priv->ici.drv_name = dev_name(&pdev->dev); | 1505 | priv->ici.drv_name = dev_name(&pdev->dev); |
1504 | priv->ici.ops = &rcar_vin_host_ops; | 1506 | priv->ici.ops = &rcar_vin_host_ops; |
1505 | 1507 | ||
1506 | priv->pdata_flags = pdata_flags; | 1508 | priv->pdata_flags = pdata_flags; |
1507 | if (!match) { | 1509 | if (!match) { |
1508 | priv->ici.nr = pdev->id; | 1510 | priv->ici.nr = pdev->id; |
1509 | priv->chip = pdev->id_entry->driver_data; | 1511 | priv->chip = pdev->id_entry->driver_data; |
1510 | } else { | 1512 | } else { |
1511 | priv->ici.nr = of_alias_get_id(pdev->dev.of_node, "vin"); | 1513 | priv->ici.nr = of_alias_get_id(pdev->dev.of_node, "vin"); |
1512 | priv->chip = (enum chip_id)match->data; | 1514 | priv->chip = (enum chip_id)match->data; |
1513 | } | 1515 | } |
1514 | 1516 | ||
1515 | spin_lock_init(&priv->lock); | 1517 | spin_lock_init(&priv->lock); |
1516 | INIT_LIST_HEAD(&priv->capture); | 1518 | INIT_LIST_HEAD(&priv->capture); |
1517 | 1519 | ||
1518 | priv->state = STOPPED; | 1520 | priv->state = STOPPED; |
1519 | 1521 | ||
1520 | pm_suspend_ignore_children(&pdev->dev, true); | 1522 | pm_suspend_ignore_children(&pdev->dev, true); |
1521 | pm_runtime_enable(&pdev->dev); | 1523 | pm_runtime_enable(&pdev->dev); |
1522 | 1524 | ||
1523 | ret = soc_camera_host_register(&priv->ici); | 1525 | ret = soc_camera_host_register(&priv->ici); |
1524 | if (ret) | 1526 | if (ret) |
1525 | goto cleanup; | 1527 | goto cleanup; |
1526 | 1528 | ||
1527 | return 0; | 1529 | return 0; |
1528 | 1530 | ||
1529 | cleanup: | 1531 | cleanup: |
1530 | pm_runtime_disable(&pdev->dev); | 1532 | pm_runtime_disable(&pdev->dev); |
1531 | vb2_dma_contig_cleanup_ctx(priv->alloc_ctx); | 1533 | vb2_dma_contig_cleanup_ctx(priv->alloc_ctx); |
1532 | 1534 | ||
1533 | return ret; | 1535 | return ret; |
1534 | } | 1536 | } |
1535 | 1537 | ||
1536 | static int rcar_vin_remove(struct platform_device *pdev) | 1538 | static int rcar_vin_remove(struct platform_device *pdev) |
1537 | { | 1539 | { |
1538 | struct soc_camera_host *soc_host = to_soc_camera_host(&pdev->dev); | 1540 | struct soc_camera_host *soc_host = to_soc_camera_host(&pdev->dev); |
1539 | struct rcar_vin_priv *priv = container_of(soc_host, | 1541 | struct rcar_vin_priv *priv = container_of(soc_host, |
1540 | struct rcar_vin_priv, ici); | 1542 | struct rcar_vin_priv, ici); |
1541 | 1543 | ||
1542 | soc_camera_host_unregister(soc_host); | 1544 | soc_camera_host_unregister(soc_host); |
1543 | pm_runtime_disable(&pdev->dev); | 1545 | pm_runtime_disable(&pdev->dev); |
1544 | vb2_dma_contig_cleanup_ctx(priv->alloc_ctx); | 1546 | vb2_dma_contig_cleanup_ctx(priv->alloc_ctx); |
1545 | 1547 | ||
1546 | return 0; | 1548 | return 0; |
1547 | } | 1549 | } |
1548 | 1550 | ||
1549 | static struct platform_driver rcar_vin_driver = { | 1551 | static struct platform_driver rcar_vin_driver = { |
1550 | .probe = rcar_vin_probe, | 1552 | .probe = rcar_vin_probe, |
1551 | .remove = rcar_vin_remove, | 1553 | .remove = rcar_vin_remove, |
1552 | .driver = { | 1554 | .driver = { |
1553 | .name = DRV_NAME, | 1555 | .name = DRV_NAME, |
1554 | .owner = THIS_MODULE, | 1556 | .owner = THIS_MODULE, |
1555 | .of_match_table = of_match_ptr(rcar_vin_of_table), | 1557 | .of_match_table = of_match_ptr(rcar_vin_of_table), |
1556 | }, | 1558 | }, |
1557 | .id_table = rcar_vin_id_table, | 1559 | .id_table = rcar_vin_id_table, |
1558 | }; | 1560 | }; |
1559 | 1561 | ||
1560 | module_platform_driver(rcar_vin_driver); | 1562 | module_platform_driver(rcar_vin_driver); |
1561 | 1563 | ||
1562 | MODULE_LICENSE("GPL"); | 1564 | MODULE_LICENSE("GPL"); |
1563 | MODULE_ALIAS("platform:rcar_vin"); | 1565 | MODULE_ALIAS("platform:rcar_vin"); |
1564 | MODULE_DESCRIPTION("Renesas R-Car VIN camera host driver"); | 1566 | MODULE_DESCRIPTION("Renesas R-Car VIN camera host driver"); |
1565 | 1567 |