History

Merge branch 'v4l_for_linus' of git://git.kernel.org/pub/scm/linux/kernel/git/mchehab/linux-media

* 'v4l_for_linus' of git://git.kernel.org/pub/scm/linux/kernel/git/mchehab/linux-media: (144 commits) [media] saa7134.h: Suppress compiler warnings when CONFIG_VIDEO_SAA7134_RC is not set [media] it913x [VER 1.07] Support for single ITE 9135 devices [media] Support for Terratec G1 [media] cx25821: off by one in cx25821_vidioc_s_input() [media] media: tea5764: reconcile Kconfig symbol and macro [media] omap_vout: Add poll() support [media] omap3isp: preview: Add crop support on the sink pad [media] omap3isp: preview: Rename min/max input/output sizes defines [media] omap3isp: preview: Remove horizontal averager support [media] omap3isp: Report the ISP revision through the media controller API [media] omap3isp: ccdc: remove redundant operation [media] omap3isp: Fix memory leaks in initialization error paths [media] omap3isp: Add missing mutex_destroy() calls [media] omap3isp: Move *_init_entities() functions to the init/cleanup section [media] omap3isp: Move media_entity_cleanup() from unregister() to cleanup() [media] MFC: Change MFC firmware binary name [media] vb2: add vb2_get_unmapped_area in vb2 core [media] v4l: Add v4l2 subdev driver for S5K6AAFX sensor [media] v4l: Add AUTO option for the V4L2_CID_POWER_LINE_FREQUENCY control [media] media: ov6650: stylistic improvements ...

Linus Torvalds committed 15 years ago

Commit 1046a2c2 parents 46e85f5 b3f4e1e216 files · +10316 −3785Browse files

Unified · Split

216 files
  1. Documentation/DocBook/media/v4l/compat.xml +3 −0
  2. Documentation/DocBook/media/v4l/controls.xml +3 −2
  3. Documentation/DocBook/media/v4l/io.xml +27 −0
  4. Documentation/DocBook/media/v4l/v4l2.xml +2 −0
  5. Documentation/DocBook/media/v4l/vidioc-create-bufs.xml +139 −0
  6. Documentation/DocBook/media/v4l/vidioc-prepare-buf.xml +88 −0
  7. arch/arm/mach-pxa/pcm990-baseboard.c +2 −2
  8. arch/arm/mach-shmobile/board-ap4evb.c +1 −1
  9. arch/arm/mach-shmobile/board-mackerel.c +4 −3
  10. arch/sh/boards/mach-ap325rxa/setup.c +5 −5
  11. arch/sh/boards/mach-migor/setup.c +1 −3
  12. drivers/dma/ipu/ipu_idmac.c +42 −23
  13. drivers/media/dvb/ddbridge/Makefile +1 −1
  14. drivers/media/dvb/dvb-usb/Makefile +1 −0
  15. drivers/media/dvb/dvb-usb/dvb-usb-ids.h +2 −0
  16. drivers/media/dvb/dvb-usb/it913x.c +78 −27
  17. drivers/media/dvb/dvb-usb/mxl111sf-demod.c +614 −0
  18. drivers/media/dvb/dvb-usb/mxl111sf-demod.h +55 −0
  19. drivers/media/dvb/dvb-usb/mxl111sf.c +225 −3
  20. drivers/media/dvb/dvb-usb/mxl111sf.h +1 −1
  21. drivers/media/dvb/ngene/Makefile +1 −1
  22. drivers/media/radio/radio-tea5764.c +3 −1
  23. drivers/media/video/Kconfig +9 −0
  24. drivers/media/video/Makefile +2 −0
  25. drivers/media/video/atmel-isi.c +76 −66
  26. drivers/media/video/cx18/cx18-driver.c +2 −0
  27. drivers/media/video/cx25821/Kconfig +0 −0
  28. drivers/media/video/cx25821/Makefile +0 −0
  29. drivers/media/video/cx25821/cx25821-alsa.c +0 −0
  30. drivers/media/video/cx25821/cx25821-audio-upstream.c +0 −0
  31. drivers/media/video/cx25821/cx25821-audio-upstream.h +0 −0
  32. drivers/media/video/cx25821/cx25821-audio.h +0 −0
  33. drivers/media/video/cx25821/cx25821-biffuncs.h +0 −0
  34. drivers/media/video/cx25821/cx25821-cards.c +0 −0
  35. drivers/media/video/cx25821/cx25821-core.c +0 −0
  36. drivers/media/video/cx25821/cx25821-gpio.c +0 −0
  37. drivers/media/video/cx25821/cx25821-i2c.c +0 −0
  38. drivers/media/video/cx25821/cx25821-medusa-defines.h +0 −0
  39. drivers/media/video/cx25821/cx25821-medusa-reg.h +0 −0
  40. drivers/media/video/cx25821/cx25821-medusa-video.c +0 −0
  41. drivers/media/video/cx25821/cx25821-medusa-video.h +0 −0
  42. drivers/media/video/cx25821/cx25821-reg.h +0 −0
  43. drivers/media/video/cx25821/cx25821-sram.h +0 −0
  44. drivers/media/video/cx25821/cx25821-video-upstream-ch2.c +0 −0
  45. drivers/media/video/cx25821/cx25821-video-upstream-ch2.h +0 −0
  46. drivers/media/video/cx25821/cx25821-video-upstream.c +0 −0
  47. drivers/media/video/cx25821/cx25821-video-upstream.h +0 −0
  48. drivers/media/video/cx25821/cx25821-video.c +1 −1
  49. drivers/media/video/cx25821/cx25821-video.h +0 −0
  50. drivers/media/video/cx25821/cx25821.h +2 −1
  51. drivers/media/video/em28xx/em28xx-cards.c +2 −0
  52. drivers/media/video/imx074.c +17 −37
  53. drivers/media/video/ivtv/ivtv-driver.c +2 −0
  54. drivers/media/video/marvell-ccic/mcam-core.c +2 −1
  55. drivers/media/video/mem2mem_testdev.c +4 −3
  56. drivers/media/video/mt9m001.c +122 −206
  57. drivers/media/video/mt9m111.c +70 −190
  58. drivers/media/video/mt9t031.c +141 −206
  59. drivers/media/video/mt9t112.c +117 −152
  60. drivers/media/video/mt9v022.c +185 −262
  61. drivers/media/video/mx1_camera.c +42 −29
  62. drivers/media/video/mx2_camera.c +45 −33
  63. drivers/media/video/mx3_camera.c +175 −184
  64. drivers/media/video/omap/omap_vout.c +10 −0
  65. drivers/media/video/omap1_camera.c +38 −24
  66. drivers/media/video/omap3isp/isp.c +3 −0
  67. drivers/media/video/omap3isp/ispccdc.c +51 −35
  68. drivers/media/video/omap3isp/ispccp2.c +65 −60
  69. drivers/media/video/omap3isp/ispcsi2.c +48 −43
  70. drivers/media/video/omap3isp/isph3a_aewb.c +1 −1
  71. drivers/media/video/omap3isp/isph3a_af.c +1 −1
  72. drivers/media/video/omap3isp/isphist.c +1 −1
  73. drivers/media/video/omap3isp/isppreview.c +269 −150
  74. drivers/media/video/omap3isp/isppreview.h +2 −7
  75. drivers/media/video/omap3isp/ispreg.h +0 −3
  76. drivers/media/video/omap3isp/ispresizer.c +53 −51
  77. drivers/media/video/omap3isp/ispstat.c +31 −21
  78. drivers/media/video/omap3isp/ispstat.h +1 −1
  79. drivers/media/video/omap3isp/ispvideo.c +8 −3
  80. drivers/media/video/omap3isp/ispvideo.h +1 −0
  81. drivers/media/video/ov2640.c +52 −126
  82. drivers/media/video/ov5642.c +181 −107
  83. drivers/media/video/ov6650.c +173 −331
  84. drivers/media/video/ov772x.c +69 −129
  85. drivers/media/video/ov9640.c +60 −126
  86. drivers/media/video/ov9640.h +1 −3
  87. drivers/media/video/ov9740.c +55 −96
  88. drivers/media/video/pwc/pwc-if.c +3 −3
  89. drivers/media/video/pxa_camera.c +80 −60
  90. drivers/media/video/rj54n1cb0c.c +75 −148
  91. drivers/media/video/s5k6aa.c +1680 −0
  92. drivers/media/video/s5p-fimc/fimc-capture.c +3 −3
  93. drivers/media/video/s5p-fimc/fimc-core.c +3 −3
  94. drivers/media/video/s5p-mfc/s5p_mfc_ctrl.c +2 −2
  95. drivers/media/video/s5p-mfc/s5p_mfc_dec.c +4 −3
  96. drivers/media/video/s5p-mfc/s5p_mfc_enc.c +3 −2
  97. drivers/media/video/s5p-tv/mixer_video.c +2 −2
  98. drivers/media/video/saa7134/saa7134.h +6 −6
  99. drivers/media/video/sh_mobile_ceu_camera.c +285 −206
  100. drivers/media/video/sh_mobile_csi2.c +84 −48
  101. drivers/media/video/soc_camera.c +141 −132
  102. drivers/media/video/soc_camera_platform.c +14 −31
  103. drivers/media/video/soc_mediabus.c +33 −0
  104. drivers/media/video/tw9910.c +113 −155
  105. drivers/media/video/v4l2-compat-ioctl32.c +68 −8
  106. drivers/media/video/v4l2-ctrls.c +1 −0
  107. drivers/media/video/v4l2-device.c +31 −5
  108. drivers/media/video/v4l2-ioctl.c +36 −0
  109. drivers/media/video/videobuf2-core.c +321 −70
  110. drivers/media/video/vivi.c +3 −3
  111. drivers/staging/Kconfig +2 −14
  112. drivers/staging/Makefile +1 −7
  113. drivers/staging/cx25821/README +0 −6
  114. drivers/staging/media/Kconfig +37 −0
  115. drivers/staging/media/Makefile +7 −0
  116. drivers/staging/media/as102/Kconfig +7 −0
  117. drivers/staging/media/as102/Makefile +6 −0
  118. drivers/staging/media/as102/as102_drv.c +351 −0
  119. drivers/staging/media/as102/as102_drv.h +141 −0
  120. drivers/staging/media/as102/as102_fe.c +603 −0
  121. drivers/staging/media/as102/as102_fw.c +251 −0
  122. drivers/staging/media/as102/as102_fw.h +42 −0
  123. drivers/staging/media/as102/as102_usb_drv.c +478 −0
  124. drivers/staging/media/as102/as102_usb_drv.h +59 −0
  125. drivers/staging/media/as102/as10x_cmd.c +452 −0
  126. drivers/staging/media/as102/as10x_cmd.h +540 −0
  127. drivers/staging/media/as102/as10x_cmd_cfg.c +215 −0
  128. drivers/staging/media/as102/as10x_cmd_stream.c +223 −0
  129. drivers/staging/media/as102/as10x_handle.h +58 −0
  130. drivers/staging/media/as102/as10x_types.h +198 −0
  131. drivers/staging/media/cxd2099/Kconfig +0 −0
  132. drivers/staging/media/cxd2099/Makefile +0 −0
  133. drivers/staging/media/cxd2099/TODO +0 −0
  134. drivers/staging/media/cxd2099/cxd2099.c +0 −0
  135. drivers/staging/media/cxd2099/cxd2099.h +0 −0
  136. drivers/staging/media/dt3155v4l/Kconfig +0 −0
  137. drivers/staging/media/dt3155v4l/Makefile +0 −0
  138. drivers/staging/media/dt3155v4l/dt3155v4l.c +0 −0
  139. drivers/staging/media/dt3155v4l/dt3155v4l.h +0 −0
  140. drivers/staging/media/easycap/Kconfig +0 −0
  141. drivers/staging/media/easycap/Makefile +0 −0
  142. drivers/staging/media/easycap/README +0 −0
  143. drivers/staging/media/easycap/easycap.h +0 −0
  144. drivers/staging/media/easycap/easycap_ioctl.c +0 −0
  145. drivers/staging/media/easycap/easycap_low.c +0 −0
  146. drivers/staging/media/easycap/easycap_main.c +0 −0
  147. drivers/staging/media/easycap/easycap_settings.c +0 −0
  148. drivers/staging/media/easycap/easycap_sound.c +0 −0
  149. drivers/staging/media/easycap/easycap_testcard.c +0 −0
  150. drivers/staging/media/go7007/Kconfig +0 −0
  151. drivers/staging/media/go7007/Makefile +0 −0
  152. drivers/staging/media/go7007/README +0 −0
  153. drivers/staging/media/go7007/go7007-driver.c +0 −0
  154. drivers/staging/media/go7007/go7007-fw.c +0 −0
  155. drivers/staging/media/go7007/go7007-i2c.c +0 −0
  156. drivers/staging/media/go7007/go7007-priv.h +0 −0
  157. drivers/staging/media/go7007/go7007-usb.c +0 −0
  158. drivers/staging/media/go7007/go7007-v4l2.c +0 −0
  159. drivers/staging/media/go7007/go7007.h +0 −0
  160. drivers/staging/media/go7007/go7007.txt +0 −0
  161. drivers/staging/media/go7007/s2250-board.c +0 −0
  162. drivers/staging/media/go7007/s2250-loader.c +0 −0
  163. drivers/staging/media/go7007/s2250-loader.h +0 −0
  164. drivers/staging/media/go7007/saa7134-go7007.c +0 −0
  165. drivers/staging/media/go7007/snd-go7007.c +0 −0
  166. drivers/staging/media/go7007/wis-i2c.h +0 −0
  167. drivers/staging/media/go7007/wis-ov7640.c +0 −0
  168. drivers/staging/media/go7007/wis-saa7113.c +0 −0
  169. drivers/staging/media/go7007/wis-saa7115.c +0 −0
  170. drivers/staging/media/go7007/wis-sony-tuner.c +0 −0
  171. drivers/staging/media/go7007/wis-tw2804.c +0 −0
  172. drivers/staging/media/go7007/wis-tw9903.c +0 −0
  173. drivers/staging/media/go7007/wis-uda1342.c +0 −0
  174. drivers/staging/media/lirc/Kconfig +0 −0
  175. drivers/staging/media/lirc/Makefile +0 −0
  176. drivers/staging/media/lirc/TODO +0 −0
  177. drivers/staging/media/lirc/TODO.lirc_zilog +0 −0
  178. drivers/staging/media/lirc/lirc_bt829.c +0 −0
  179. drivers/staging/media/lirc/lirc_ene0100.h +0 −0
  180. drivers/staging/media/lirc/lirc_igorplugusb.c +0 −0
  181. drivers/staging/media/lirc/lirc_imon.c +0 −0
  182. drivers/staging/media/lirc/lirc_parallel.c +0 −0
  183. drivers/staging/media/lirc/lirc_parallel.h +0 −0
  184. drivers/staging/media/lirc/lirc_sasem.c +0 −0
  185. drivers/staging/media/lirc/lirc_serial.c +0 −0
  186. drivers/staging/media/lirc/lirc_sir.c +0 −0
  187. drivers/staging/media/lirc/lirc_ttusbir.c +0 −0
  188. drivers/staging/media/lirc/lirc_zilog.c +0 −0
  189. drivers/staging/media/solo6x10/Kconfig +0 −0
  190. drivers/staging/media/solo6x10/Makefile +0 −0
  191. drivers/staging/media/solo6x10/TODO +0 −0
  192. drivers/staging/media/solo6x10/core.c +0 −0
  193. drivers/staging/media/solo6x10/disp.c +0 −0
  194. drivers/staging/media/solo6x10/enc.c +0 −0
  195. drivers/staging/media/solo6x10/g723.c +0 −0
  196. drivers/staging/media/solo6x10/gpio.c +0 −0
  197. drivers/staging/media/solo6x10/i2c.c +0 −0
  198. drivers/staging/media/solo6x10/jpeg.h +0 −0
  199. drivers/staging/media/solo6x10/offsets.h +0 −0
  200. drivers/staging/media/solo6x10/osd-font.h +0 −0
  201. drivers/staging/media/solo6x10/p2m.c +0 −0
  202. drivers/staging/media/solo6x10/registers.h +0 −0
  203. drivers/staging/media/solo6x10/solo6x10.h +0 −0
  204. drivers/staging/media/solo6x10/tw28.c +0 −0
  205. drivers/staging/media/solo6x10/tw28.h +0 −0
  206. drivers/staging/media/solo6x10/v4l2-enc.c +0 −0
  207. drivers/staging/media/solo6x10/v4l2.c +0 −0
  208. include/linux/videodev2.h +27 −0
  209. include/media/ov772x.h +12 −14
  210. include/media/s5k6aa.h +51 −0
  211. include/media/soc_camera.h +31 −73
  212. include/media/soc_camera_platform.h +3 −1
  213. include/media/soc_mediabus.h +2 −0
  214. include/media/v4l2-ioctl.h +2 −0
  215. include/media/v4l2-subdev.h +3 −2
  216. include/media/videobuf2-core.h +35 −15
Documentation/DocBook/media/v4l/compat.xml+3−0
@@ -2486,6 +2486,9 @@ ioctls.</para> · 2485 unmodified lines
24862486 <listitem>
24872487 <para>Flash API. <xref linkend="flash-controls" /></para>
24882488 </listitem>
2489+ <listitem>
2490+ <para>&VIDIOC-CREATE-BUFS; and &VIDIOC-PREPARE-BUF; ioctls.</para>
2491+ </listitem>
24892492 </itemizedlist>
24902493 </section>
24912494
Documentation/DocBook/media/v4l/controls.xml+3−2
@@ -232,8 +232,9 @@ control is deprecated. New drivers and applications should use the · 231 unmodified lines
232232 <entry>Enables a power line frequency filter to avoid
233233 flicker. Possible values for <constant>enum v4l2_power_line_frequency</constant> are:
234234 <constant>V4L2_CID_POWER_LINE_FREQUENCY_DISABLED</constant> (0),
235−<constant>V4L2_CID_POWER_LINE_FREQUENCY_50HZ</constant> (1) and
236−<constant>V4L2_CID_POWER_LINE_FREQUENCY_60HZ</constant> (2).</entry>
235+<constant>V4L2_CID_POWER_LINE_FREQUENCY_50HZ</constant> (1),
236+<constant>V4L2_CID_POWER_LINE_FREQUENCY_60HZ</constant> (2) and
237+<constant>V4L2_CID_POWER_LINE_FREQUENCY_AUTO</constant> (3).</entry>
237238 </row>
238239 <row>
239240 <entry><constant>V4L2_CID_HUE_AUTO</constant></entry>
Documentation/DocBook/media/v4l/io.xml+27−0
@@ -927,6 +927,33 @@ ioctl is called.</entry> · 926 unmodified lines
927927 Applications set or clear this flag before calling the
928928 <constant>VIDIOC_QBUF</constant> ioctl.</entry>
929929 </row>
930+ <row>
931+ <entry><constant>V4L2_BUF_FLAG_PREPARED</constant></entry>
932+ <entry>0x0400</entry>
933+ <entry>The buffer has been prepared for I/O and can be queued by the
934+application. Drivers set or clear this flag when the
935+<link linkend="vidioc-querybuf">VIDIOC_QUERYBUF</link>, <link
936+ linkend="vidioc-qbuf">VIDIOC_PREPARE_BUF</link>, <link
937+ linkend="vidioc-qbuf">VIDIOC_QBUF</link> or <link
938+ linkend="vidioc-qbuf">VIDIOC_DQBUF</link> ioctl is called.</entry>
939+ </row>
940+ <row>
941+ <entry><constant>V4L2_BUF_FLAG_NO_CACHE_INVALIDATE</constant></entry>
942+ <entry>0x0400</entry>
943+ <entry>Caches do not have to be invalidated for this buffer.
944+Typically applications shall use this flag if the data captured in the buffer
945+is not going to be touched by the CPU, instead the buffer will, probably, be
946+passed on to a DMA-capable hardware unit for further processing or output.
947+</entry>
948+ </row>
949+ <row>
950+ <entry><constant>V4L2_BUF_FLAG_NO_CACHE_CLEAN</constant></entry>
951+ <entry>0x0800</entry>
952+ <entry>Caches do not have to be cleaned for this buffer.
953+Typically applications shall use this flag for output buffers if the data
954+in this buffer has not been created by the CPU but by some DMA-capable unit,
955+in which case caches have not been used.</entry>
956+ </row>
930957 </tbody>
931958 </tgroup>
932959 </table>
Documentation/DocBook/media/v4l/v4l2.xml+2−0
@@ -469,6 +469,7 @@ and discussions on the V4L mailing list.</revremark> · 468 unmodified lines
469469 &sub-close;
470470 &sub-ioctl;
471471 <!-- All ioctls go here. -->
472+ &sub-create-bufs;
472473 &sub-cropcap;
473474 &sub-dbg-g-chip-ident;
474475 &sub-dbg-g-register;
@@ -511,6 +512,7 @@ and discussions on the V4L mailing list.</revremark> · 36 unmodified lines
511512 &sub-queryctrl;
512513 &sub-query-dv-preset;
513514 &sub-querystd;
515+ &sub-prepare-buf;
514516 &sub-reqbufs;
515517 &sub-s-hw-freq-seek;
516518 &sub-streamon;
Documentation/DocBook/media/v4l/vidioc-create-bufs.xml+139−0
@@ -0,0 +1,139 @@
1+<refentry id="vidioc-create-bufs">
2+ <refmeta>
3+ <refentrytitle>ioctl VIDIOC_CREATE_BUFS</refentrytitle>
4+ &manvol;
5+ </refmeta>
6+
7+ <refnamediv>
8+ <refname>VIDIOC_CREATE_BUFS</refname>
9+ <refpurpose>Create buffers for Memory Mapped or User Pointer I/O</refpurpose>
10+ </refnamediv>
11+
12+ <refsynopsisdiv>
13+ <funcsynopsis>
14+ <funcprototype>
15+ <funcdef>int <function>ioctl</function></funcdef>
16+ <paramdef>int <parameter>fd</parameter></paramdef>
17+ <paramdef>int <parameter>request</parameter></paramdef>
18+ <paramdef>struct v4l2_create_buffers *<parameter>argp</parameter></paramdef>
19+ </funcprototype>
20+ </funcsynopsis>
21+ </refsynopsisdiv>
22+
23+ <refsect1>
24+ <title>Arguments</title>
25+
26+ <variablelist>
27+ <varlistentry>
28+ <term><parameter>fd</parameter></term>
29+ <listitem>
30+ <para>&fd;</para>
31+ </listitem>
32+ </varlistentry>
33+ <varlistentry>
34+ <term><parameter>request</parameter></term>
35+ <listitem>
36+ <para>VIDIOC_CREATE_BUFS</para>
37+ </listitem>
38+ </varlistentry>
39+ <varlistentry>
40+ <term><parameter>argp</parameter></term>
41+ <listitem>
42+ <para></para>
43+ </listitem>
44+ </varlistentry>
45+ </variablelist>
46+ </refsect1>
47+
48+ <refsect1>
49+ <title>Description</title>
50+
51+ <para>This ioctl is used to create buffers for <link linkend="mmap">memory
52+mapped</link> or <link linkend="userp">user pointer</link>
53+I/O. It can be used as an alternative or in addition to the
54+<constant>VIDIOC_REQBUFS</constant> ioctl, when a tighter control over buffers
55+is required. This ioctl can be called multiple times to create buffers of
56+different sizes.</para>
57+
58+ <para>To allocate device buffers applications initialize relevant fields of
59+the <structname>v4l2_create_buffers</structname> structure. They set the
60+<structfield>type</structfield> field in the
61+<structname>v4l2_format</structname> structure, embedded in this
62+structure, to the respective stream or buffer type.
63+<structfield>count</structfield> must be set to the number of required buffers.
64+<structfield>memory</structfield> specifies the required I/O method. The
65+<structfield>format</structfield> field shall typically be filled in using
66+either the <constant>VIDIOC_TRY_FMT</constant> or
67+<constant>VIDIOC_G_FMT</constant> ioctl(). Additionally, applications can adjust
68+<structfield>sizeimage</structfield> fields to fit their specific needs. The
69+<structfield>reserved</structfield> array must be zeroed.</para>
70+
71+ <para>When the ioctl is called with a pointer to this structure the driver
72+will attempt to allocate up to the requested number of buffers and store the
73+actual number allocated and the starting index in the
74+<structfield>count</structfield> and the <structfield>index</structfield> fields
75+respectively. On return <structfield>count</structfield> can be smaller than
76+the number requested. The driver may also increase buffer sizes if required,
77+however, it will not update <structfield>sizeimage</structfield> field values.
78+The user has to use <constant>VIDIOC_QUERYBUF</constant> to retrieve that
79+information.</para>
80+
81+ <table pgwide="1" frame="none" id="v4l2-create-buffers">
82+ <title>struct <structname>v4l2_create_buffers</structname></title>
83+ <tgroup cols="3">
84+ &cs-str;
85+ <tbody valign="top">
86+ <row>
87+ <entry>__u32</entry>
88+ <entry><structfield>index</structfield></entry>
89+ <entry>The starting buffer index, returned by the driver.</entry>
90+ </row>
91+ <row>
92+ <entry>__u32</entry>
93+ <entry><structfield>count</structfield></entry>
94+ <entry>The number of buffers requested or granted.</entry>
95+ </row>
96+ <row>
97+ <entry>&v4l2-memory;</entry>
98+ <entry><structfield>memory</structfield></entry>
99+ <entry>Applications set this field to
100+<constant>V4L2_MEMORY_MMAP</constant> or
101+<constant>V4L2_MEMORY_USERPTR</constant>.</entry>
102+ </row>
103+ <row>
104+ <entry>&v4l2-format;</entry>
105+ <entry><structfield>format</structfield></entry>
106+ <entry>Filled in by the application, preserved by the driver.</entry>
107+ </row>
108+ <row>
109+ <entry>__u32</entry>
110+ <entry><structfield>reserved</structfield>[8]</entry>
111+ <entry>A place holder for future extensions.</entry>
112+ </row>
113+ </tbody>
114+ </tgroup>
115+ </table>
116+ </refsect1>
117+
118+ <refsect1>
119+ &return-value;
120+
121+ <variablelist>
122+ <varlistentry>
123+ <term><errorcode>ENOMEM</errorcode></term>
124+ <listitem>
125+ <para>No memory to allocate buffers for <link linkend="mmap">memory
126+mapped</link> I/O.</para>
127+ </listitem>
128+ </varlistentry>
129+ <varlistentry>
130+ <term><errorcode>EINVAL</errorcode></term>
131+ <listitem>
132+ <para>The buffer type (<structfield>type</structfield> field) or the
133+requested I/O method (<structfield>memory</structfield>) is not
134+supported.</para>
135+ </listitem>
136+ </varlistentry>
137+ </variablelist>
138+ </refsect1>
139+</refentry>
Documentation/DocBook/media/v4l/vidioc-prepare-buf.xml+88−0
@@ -0,0 +1,88 @@
1+<refentry id="vidioc-prepare-buf">
2+ <refmeta>
3+ <refentrytitle>ioctl VIDIOC_PREPARE_BUF</refentrytitle>
4+ &manvol;
5+ </refmeta>
6+
7+ <refnamediv>
8+ <refname>VIDIOC_PREPARE_BUF</refname>
9+ <refpurpose>Prepare a buffer for I/O</refpurpose>
10+ </refnamediv>
11+
12+ <refsynopsisdiv>
13+ <funcsynopsis>
14+ <funcprototype>
15+ <funcdef>int <function>ioctl</function></funcdef>
16+ <paramdef>int <parameter>fd</parameter></paramdef>
17+ <paramdef>int <parameter>request</parameter></paramdef>
18+ <paramdef>struct v4l2_buffer *<parameter>argp</parameter></paramdef>
19+ </funcprototype>
20+ </funcsynopsis>
21+ </refsynopsisdiv>
22+
23+ <refsect1>
24+ <title>Arguments</title>
25+
26+ <variablelist>
27+ <varlistentry>
28+ <term><parameter>fd</parameter></term>
29+ <listitem>
30+ <para>&fd;</para>
31+ </listitem>
32+ </varlistentry>
33+ <varlistentry>
34+ <term><parameter>request</parameter></term>
35+ <listitem>
36+ <para>VIDIOC_PREPARE_BUF</para>
37+ </listitem>
38+ </varlistentry>
39+ <varlistentry>
40+ <term><parameter>argp</parameter></term>
41+ <listitem>
42+ <para></para>
43+ </listitem>
44+ </varlistentry>
45+ </variablelist>
46+ </refsect1>
47+
48+ <refsect1>
49+ <title>Description</title>
50+
51+ <para>Applications can optionally call the
52+<constant>VIDIOC_PREPARE_BUF</constant> ioctl to pass ownership of the buffer
53+to the driver before actually enqueuing it, using the
54+<constant>VIDIOC_QBUF</constant> ioctl, and to prepare it for future I/O.
55+Such preparations may include cache invalidation or cleaning. Performing them
56+in advance saves time during the actual I/O. In case such cache operations are
57+not required, the application can use one of
58+<constant>V4L2_BUF_FLAG_NO_CACHE_INVALIDATE</constant> and
59+<constant>V4L2_BUF_FLAG_NO_CACHE_CLEAN</constant> flags to skip the respective
60+step.</para>
61+
62+ <para>The <structname>v4l2_buffer</structname> structure is
63+specified in <xref linkend="buffer" />.</para>
64+ </refsect1>
65+
66+ <refsect1>
67+ &return-value;
68+
69+ <variablelist>
70+ <varlistentry>
71+ <term><errorcode>EBUSY</errorcode></term>
72+ <listitem>
73+ <para>File I/O is in progress.</para>
74+ </listitem>
75+ </varlistentry>
76+ <varlistentry>
77+ <term><errorcode>EINVAL</errorcode></term>
78+ <listitem>
79+ <para>The buffer <structfield>type</structfield> is not
80+supported, or the <structfield>index</structfield> is out of bounds,
81+or no buffers have been allocated yet, or the
82+<structfield>userptr</structfield> or
83+<structfield>length</structfield> are invalid.</para>
84+ </listitem>
85+ </varlistentry>
86+ </variablelist>
87+ </refsect1>
88+</refentry>
arch/arm/mach-pxa/pcm990-baseboard.c+2−2
@@ -394,9 +394,9 @@ static int pcm990_camera_set_bus_param(struct soc_camera_link *link, · 393 unmodified lines
394394 }
395395
396396 if (flags & SOCAM_DATAWIDTH_8)
397− gpio_set_value(gpio_bus_switch, 1);
397+ gpio_set_value_cansleep(gpio_bus_switch, 1);
398398 else
399− gpio_set_value(gpio_bus_switch, 0);
399+ gpio_set_value_cansleep(gpio_bus_switch, 0);
400400
401401 return 0;
402402 }
arch/arm/mach-shmobile/board-ap4evb.c+1−1
@@ -933,7 +933,7 @@ static struct platform_device ap4evb_camera = { · 932 unmodified lines
933933 static struct sh_csi2_client_config csi2_clients[] = {
934934 {
935935 .phy = SH_CSI2_PHY_MAIN,
936− .lanes = 3,
936+ .lanes = 0, /* default: 2 lanes */
937937 .channel = 0,
938938 .pdev = &ap4evb_camera,
939939 },
arch/arm/mach-shmobile/board-mackerel.c+4−3
@@ -1223,9 +1223,10 @@ static struct soc_camera_platform_info camera_info = { · 1222 unmodified lines
12231223 .width = 640,
12241224 .height = 480,
12251225 },
1226− .bus_param = SOCAM_PCLK_SAMPLE_RISING | SOCAM_HSYNC_ACTIVE_HIGH |
1227− SOCAM_VSYNC_ACTIVE_HIGH | SOCAM_MASTER | SOCAM_DATAWIDTH_8 |
1228− SOCAM_DATA_ACTIVE_HIGH,
1226+ .mbus_param = V4L2_MBUS_PCLK_SAMPLE_RISING | V4L2_MBUS_MASTER |
1227+ V4L2_MBUS_VSYNC_ACTIVE_HIGH | V4L2_MBUS_HSYNC_ACTIVE_HIGH |
1228+ V4L2_MBUS_DATA_ACTIVE_HIGH,
1229+ .mbus_type = V4L2_MBUS_PARALLEL,
12291230 .set_capture = camera_set_capture,
12301231 };
12311232
arch/sh/boards/mach-ap325rxa/setup.c+5−5
@@ -345,9 +345,10 @@ static struct soc_camera_platform_info camera_info = { · 344 unmodified lines
345345 .width = 640,
346346 .height = 480,
347347 },
348− .bus_param = SOCAM_PCLK_SAMPLE_RISING | SOCAM_HSYNC_ACTIVE_HIGH |
349− SOCAM_VSYNC_ACTIVE_HIGH | SOCAM_MASTER | SOCAM_DATAWIDTH_8 |
350− SOCAM_DATA_ACTIVE_HIGH,
348+ .mbus_param = V4L2_MBUS_PCLK_SAMPLE_RISING | V4L2_MBUS_MASTER |
349+ V4L2_MBUS_VSYNC_ACTIVE_HIGH | V4L2_MBUS_HSYNC_ACTIVE_HIGH |
350+ V4L2_MBUS_DATA_ACTIVE_HIGH,
351+ .mbus_type = V4L2_MBUS_PARALLEL,
351352 .set_capture = camera_set_capture,
352353 };
353354
@@ -501,8 +502,7 @@ static struct i2c_board_info ap325rxa_i2c_camera[] = { · 147 unmodified lines
501502 };
502503
503504 static struct ov772x_camera_info ov7725_info = {
504− .flags = OV772X_FLAG_VFLIP | OV772X_FLAG_HFLIP | \
505− OV772X_FLAG_8BIT,
505+ .flags = OV772X_FLAG_VFLIP | OV772X_FLAG_HFLIP,
506506 .edgectrl = OV772X_AUTO_EDGECTRL(0xf, 0),
507507 };
508508
arch/sh/boards/mach-migor/setup.c+1−3
@@ -448,9 +448,7 @@ static struct i2c_board_info migor_i2c_camera[] = { · 447 unmodified lines
448448 },
449449 };
450450
451−static struct ov772x_camera_info ov7725_info = {
452− .flags = OV772X_FLAG_8BIT,
453−};
451+static struct ov772x_camera_info ov7725_info;
454452
455453 static struct soc_camera_link ov7725_link = {
456454 .power = ov7725_power,
drivers/dma/ipu/ipu_idmac.c+42−23
@@ -1307,6 +1307,7 @@ static irqreturn_t idmac_interrupt(int irq, void *dev_id) · 1306 unmodified lines
13071307 ipu_submit_buffer(ichan, descnew, sgnew, ichan->active_buffer) < 0) {
13081308 callback = descnew->txd.callback;
13091309 callback_param = descnew->txd.callback_param;
1310+ list_del_init(&descnew->list);
13101311 spin_unlock(&ichan->lock);
13111312 if (callback)
13121313 callback(callback_param);
@@ -1428,39 +1429,58 @@ static int __idmac_control(struct dma_chan *chan, enum dma_ctrl_cmd cmd, · 115 unmodified lines
14281429 {
14291430 struct idmac_channel *ichan = to_idmac_chan(chan);
14301431 struct idmac *idmac = to_idmac(chan->device);
1432+ struct ipu *ipu = to_ipu(idmac);
1433+ struct list_head *list, *tmp;
14311434 unsigned long flags;
14321435 int i;
14331436
1434− /* Only supports DMA_TERMINATE_ALL */
1435− if (cmd != DMA_TERMINATE_ALL)
1436− return -ENXIO;
1437+ switch (cmd) {
1438+ case DMA_PAUSE:
1439+ spin_lock_irqsave(&ipu->lock, flags);
1440+ ipu_ic_disable_task(ipu, chan->chan_id);
14371441
1438− ipu_disable_channel(idmac, ichan,
1439− ichan->status >= IPU_CHANNEL_ENABLED);
1442+ /* Return all descriptors into "prepared" state */
1443+ list_for_each_safe(list, tmp, &ichan->queue)
1444+ list_del_init(list);
14401445
1441− tasklet_disable(&to_ipu(idmac)->tasklet);
1446+ ichan->sg[0] = NULL;
1447+ ichan->sg[1] = NULL;
14421448
1443− /* ichan->queue is modified in ISR, have to spinlock */
1444− spin_lock_irqsave(&ichan->lock, flags);
1445− list_splice_init(&ichan->queue, &ichan->free_list);
1449+ spin_unlock_irqrestore(&ipu->lock, flags);
14461450
1447− if (ichan->desc)
1448− for (i = 0; i < ichan->n_tx_desc; i++) {
1449− struct idmac_tx_desc *desc = ichan->desc + i;
1450− if (list_empty(&desc->list))
1451− /* Descriptor was prepared, but not submitted */
1452− list_add(&desc->list, &ichan->free_list);
1451+ ichan->status = IPU_CHANNEL_INITIALIZED;
1452+ break;
1453+ case DMA_TERMINATE_ALL:
1454+ ipu_disable_channel(idmac, ichan,
1455+ ichan->status >= IPU_CHANNEL_ENABLED);
14531456
1454− async_tx_clear_ack(&desc->txd);
1455− }
1457+ tasklet_disable(&ipu->tasklet);
14561458
1457− ichan->sg[0] = NULL;
1458− ichan->sg[1] = NULL;
1459− spin_unlock_irqrestore(&ichan->lock, flags);
1459+ /* ichan->queue is modified in ISR, have to spinlock */
1460+ spin_lock_irqsave(&ichan->lock, flags);
1461+ list_splice_init(&ichan->queue, &ichan->free_list);
14601462
1461− tasklet_enable(&to_ipu(idmac)->tasklet);
1463+ if (ichan->desc)
1464+ for (i = 0; i < ichan->n_tx_desc; i++) {
1465+ struct idmac_tx_desc *desc = ichan->desc + i;
1466+ if (list_empty(&desc->list))
1467+ /* Descriptor was prepared, but not submitted */
1468+ list_add(&desc->list, &ichan->free_list);
14621469
1463− ichan->status = IPU_CHANNEL_INITIALIZED;
1470+ async_tx_clear_ack(&desc->txd);
1471+ }
1472+
1473+ ichan->sg[0] = NULL;
1474+ ichan->sg[1] = NULL;
1475+ spin_unlock_irqrestore(&ichan->lock, flags);
1476+
1477+ tasklet_enable(&ipu->tasklet);
1478+
1479+ ichan->status = IPU_CHANNEL_INITIALIZED;
1480+ break;
1481+ default:
1482+ return -ENOSYS;
1483+ }
14641484
14651485 return 0;
14661486 }
@@ -1663,7 +1683,6 @@ static void __exit ipu_idmac_exit(struct ipu *ipu) · 196 unmodified lines
16631683 struct idmac_channel *ichan = ipu->channel + i;
16641684
16651685 idmac_control(&ichan->dma_chan, DMA_TERMINATE_ALL, 0);
1666− idmac_prep_slave_sg(&ichan->dma_chan, NULL, 0, DMA_NONE, 0);
16671686 }
16681687
16691688 dma_async_device_unregister(&idmac->dma);
drivers/media/dvb/ddbridge/Makefile+1−1
@@ -11,4 +11,4 @@ ccflags-y += -Idrivers/media/dvb/frontends/ · 10 unmodified lines
1111 ccflags-y += -Idrivers/media/common/tuners/
1212
1313 # For the staging CI driver cxd2099
14−ccflags-y += -Idrivers/staging/cxd2099/
14+ccflags-y += -Idrivers/staging/media/cxd2099/
drivers/media/dvb/dvb-usb/Makefile+1−0
@@ -102,6 +102,7 @@ obj-$(CONFIG_DVB_USB_IT913X) += dvb-usb-it913x.o · 101 unmodified lines
102102
103103 dvb-usb-mxl111sf-objs = mxl111sf.o mxl111sf-phy.o mxl111sf-i2c.o mxl111sf-gpio.o
104104 obj-$(CONFIG_DVB_USB_MXL111SF) += dvb-usb-mxl111sf.o
105+obj-$(CONFIG_DVB_USB_MXL111SF) += mxl111sf-demod.o
105106 obj-$(CONFIG_DVB_USB_MXL111SF) += mxl111sf-tuner.o
106107
107108 ccflags-y += -Idrivers/media/dvb/dvb-core/ -Idrivers/media/dvb/frontends/
drivers/media/dvb/dvb-usb/dvb-usb-ids.h+2−0
@@ -37,6 +37,7 @@ · 36 unmodified lines
3737 #define USB_VID_HAUPPAUGE 0x2040
3838 #define USB_VID_HYPER_PALTEK 0x1025
3939 #define USB_VID_INTEL 0x8086
40+#define USB_VID_ITETECH 0x048d
4041 #define USB_VID_KWORLD 0xeb2a
4142 #define USB_VID_KWORLD_2 0x1b80
4243 #define USB_VID_KYE 0x0458
@@ -126,6 +127,7 @@ · 83 unmodified lines
126127 #define USB_PID_GRANDTEC_DVBT_USB_COLD 0x0fa0
127128 #define USB_PID_GRANDTEC_DVBT_USB_WARM 0x0fa1
128129 #define USB_PID_INTEL_CE9500 0x9500
130+#define USB_PID_ITETECH_IT9135 0x9135
129131 #define USB_PID_KWORLD_399U 0xe399
130132 #define USB_PID_KWORLD_399U_2 0xe400
131133 #define USB_PID_KWORLD_395U 0xe396
drivers/media/dvb/dvb-usb/it913x.c+78−27
@@ -60,6 +60,17 @@ struct it913x_state { · 59 unmodified lines
6060 u8 id;
6161 };
6262
63+struct ite_config {
64+ u8 chip_ver;
65+ u16 chip_type;
66+ u32 firmware;
67+ u8 tuner_id_0;
68+ u8 tuner_id_1;
69+ u8 dual_mode;
70+};
71+
72+struct ite_config it913x_config;
73+
6374 static int it913x_bulk_write(struct usb_device *dev,
6475 u8 *snd, int len, u8 pipe)
6576 {
@@ -191,18 +202,23 @@ static int it913x_read_reg(struct usb_device *udev, u32 reg) · 125 unmodified lines
191202 static u32 it913x_query(struct usb_device *udev, u8 pro)
192203 {
193204 int ret;
194− u32 res = 0;
195205 u8 data[4];
196206 ret = it913x_io(udev, READ_LONG, pro, CMD_DEMOD_READ,
197− 0x1222, 0, &data[0], 1);
198− if (data[0] == 0x1) {
199− ret = it913x_io(udev, READ_SHORT, pro,
207+ 0x1222, 0, &data[0], 3);
208+
209+ it913x_config.chip_ver = data[0];
210+ it913x_config.chip_type = (u16)(data[2] << 8) + data[1];
211+
212+ info("Chip Version=%02x Chip Type=%04x", it913x_config.chip_ver,
213+ it913x_config.chip_type);
214+
215+ ret |= it913x_io(udev, READ_SHORT, pro,
200216 CMD_QUERYINFO, 0, 0x1, &data[0], 4);
201− res = (data[0] << 24) + (data[1] << 16) +
217+
218+ it913x_config.firmware = (data[0] << 24) + (data[1] << 16) +
202219 (data[2] << 8) + data[3];
203− }
204220
205− return (ret < 0) ? 0 : res;
221+ return (ret < 0) ? 0 : it913x_config.firmware;
206222 }
207223
208224 static int it913x_pid_filter_ctrl(struct dvb_usb_adapter *adap, int onoff)
@@ -336,26 +352,35 @@ static int it913x_identify_state(struct usb_device *udev, · 127 unmodified lines
336352 int *cold)
337353 {
338354 int ret = 0, firm_no;
339− u8 reg, adap, ep, tun0, tun1;
355+ u8 reg, remote;
340356
341357 firm_no = it913x_return_status(udev);
342358
343− ep = it913x_read_reg(udev, 0x49ac);
344− adap = it913x_read_reg(udev, 0x49c5);
345− tun0 = it913x_read_reg(udev, 0x49d0);
346− info("No. Adapters=%x Endpoints=%x Tuner Type=%x", adap, ep, tun0);
359+ /* checnk for dual mode */
360+ it913x_config.dual_mode = it913x_read_reg(udev, 0x49c5);
361+
362+ /* TODO different remotes */
363+ remote = it913x_read_reg(udev, 0x49ac); /* Remote */
364+ if (remote == 0)
365+ props->rc.core.rc_codes = NULL;
366+
367+ /* TODO at the moment tuner_id is always assigned to 0x38 */
368+ it913x_config.tuner_id_0 = it913x_read_reg(udev, 0x49d0);
369+
370+ info("Dual mode=%x Remote=%x Tuner Type=%x", it913x_config.dual_mode
371+ , remote, it913x_config.tuner_id_0);
347372
348373 if (firm_no > 0) {
349374 *cold = 0;
350375 return 0;
351376 }
352377
353− if (adap > 2) {
354− tun1 = it913x_read_reg(udev, 0x49e0);
378+ if (it913x_config.dual_mode) {
379+ it913x_config.tuner_id_1 = it913x_read_reg(udev, 0x49e0);
355380 ret = it913x_wr_reg(udev, DEV_0, GPIOH1_EN, 0x1);
356381 ret |= it913x_wr_reg(udev, DEV_0, GPIOH1_ON, 0x1);
357382 ret |= it913x_wr_reg(udev, DEV_0, GPIOH1_O, 0x1);
358− msleep(50); /* Delay noticed reset cycle ? */
383+ msleep(50);
359384 ret |= it913x_wr_reg(udev, DEV_0, GPIOH1_O, 0x0);
360385 msleep(50);
361386 reg = it913x_read_reg(udev, GPIOH1_O);
@@ -366,14 +391,19 @@ static int it913x_identify_state(struct usb_device *udev, · 4 unmodified lines
366391 ret = it913x_wr_reg(udev, DEV_0,
367392 GPIOH1_O, 0x0);
368393 }
394+ props->num_adapters = 2;
369395 } else
370396 props->num_adapters = 1;
371397
372398 reg = it913x_read_reg(udev, IO_MUX_POWER_CLK);
373399
374− ret |= it913x_wr_reg(udev, DEV_0, 0x4bfb, CHIP2_I2C_ADDR);
375−
376− ret |= it913x_wr_reg(udev, DEV_0, CLK_O_EN, 0x1);
400+ if (it913x_config.dual_mode) {
401+ ret |= it913x_wr_reg(udev, DEV_0, 0x4bfb, CHIP2_I2C_ADDR);
402+ ret |= it913x_wr_reg(udev, DEV_0, CLK_O_EN, 0x1);
403+ } else {
404+ ret |= it913x_wr_reg(udev, DEV_0, 0x4bfb, 0x0);
405+ ret |= it913x_wr_reg(udev, DEV_0, CLK_O_EN, 0x0);
406+ }
377407
378408 *cold = 1;
379409
@@ -403,13 +433,11 @@ static int it913x_download_firmware(struct usb_device *udev, · 23 unmodified lines
403433 const struct firmware *fw)
404434 {
405435 int ret = 0, i;
406− u8 packet_size, dlen, tun1;
436+ u8 packet_size, dlen;
407437 u8 *fw_data;
408438
409439 packet_size = 0x29;
410440
411− tun1 = it913x_read_reg(udev, 0x49e0);
412−
413441 ret = it913x_wr_reg(udev, DEV_0, I2C_CLK, I2C_CLK_100);
414442
415443 info("FRM Starting Firmware Download");
@@ -444,11 +472,12 @@ static int it913x_download_firmware(struct usb_device *udev, · 28 unmodified lines
444472 ret |= it913x_wr_reg(udev, DEV_0, I2C_CLK, I2C_CLK_400);
445473
446474 /* Tuner function */
447− ret |= it913x_wr_reg(udev, DEV_0_DMOD , 0xec4c, 0xa0);
475+ if (it913x_config.dual_mode)
476+ ret |= it913x_wr_reg(udev, DEV_0_DMOD , 0xec4c, 0xa0);
448477
449478 ret |= it913x_wr_reg(udev, DEV_0, PADODPU, 0x0);
450479 ret |= it913x_wr_reg(udev, DEV_0, AGC_O_D, 0x0);
451− if (tun1 > 0) {
480+ if (it913x_config.dual_mode) {
452481 ret |= it913x_wr_reg(udev, DEV_1, PADODPU, 0x0);
453482 ret |= it913x_wr_reg(udev, DEV_1, AGC_O_D, 0x0);
454483 }
@@ -475,9 +504,28 @@ static int it913x_frontend_attach(struct dvb_usb_adapter *adap) · 20 unmodified lines
475504 u8 adf = it913x_read_reg(udev, IO_MUX_POWER_CLK);
476505 u8 adap_addr = I2C_BASE_ADDR + (adap->id << 5);
477506 u16 ep_size = adap->props.fe[0].stream.u.bulk.buffersize;
507+ u8 tuner_id, tuner_type;
508+
509+ if (adap->id == 0)
510+ tuner_id = it913x_config.tuner_id_0;
511+ else
512+ tuner_id = it913x_config.tuner_id_1;
513+
514+ /* TODO we always use IT9137 possible references here*/
515+ /* Documentation suggests don't care */
516+ switch (tuner_id) {
517+ case 0x51:
518+ case 0x52:
519+ case 0x60:
520+ case 0x61:
521+ case 0x62:
522+ default:
523+ case 0x38:
524+ tuner_type = IT9137;
525+ }
478526
479527 adap->fe_adap[0].fe = dvb_attach(it913x_fe_attach,
480− &adap->dev->i2c_adap, adap_addr, adf, IT9137);
528+ &adap->dev->i2c_adap, adap_addr, adf, tuner_type);
481529
482530 if (adap->id == 0 && adap->fe_adap[0].fe) {
483531 ret = it913x_wr_reg(udev, DEV_0_DMOD, MP2_SW_RST, 0x1);
@@ -533,6 +581,7 @@ static int it913x_probe(struct usb_interface *intf, · 49 unmodified lines
533581
534582 static struct usb_device_id it913x_table[] = {
535583 { USB_DEVICE(USB_VID_KWORLD_2, USB_PID_KWORLD_UB499_2T_T09) },
584+ { USB_DEVICE(USB_VID_ITETECH, USB_PID_ITETECH_IT9135) },
536585 {} /* Terminating entry */
537586 };
538587
@@ -608,12 +657,14 @@ static struct dvb_usb_device_properties it913x_properties = { · 69 unmodified lines
608657 .rc_codes = RC_MAP_KWORLD_315U,
609658 },
610659 .i2c_algo = &it913x_i2c_algo,
611− .num_device_descs = 1,
660+ .num_device_descs = 2,
612661 .devices = {
613662 { "Kworld UB499-2T T09(IT9137)",
614663 { &it913x_table[0], NULL },
615664 },
616−
665+ { "ITE 9135 Generic",
666+ { &it913x_table[1], NULL },
667+ },
617668 }
618669 };
619670
@@ -647,5 +698,5 @@ module_exit(it913x_module_exit); · 27 unmodified lines
647698
648699 MODULE_AUTHOR("Malcolm Priestley <tvboxspy@gmail.com>");
649700 MODULE_DESCRIPTION("it913x USB 2 Driver");
650−MODULE_VERSION("1.06");
701+MODULE_VERSION("1.07");
651702 MODULE_LICENSE("GPL");
drivers/media/dvb/dvb-usb/mxl111sf-demod.c+614−0
@@ -0,0 +1,614 @@
1+/*
2+ * mxl111sf-demod.c - driver for the MaxLinear MXL111SF DVB-T demodulator
3+ *
4+ * Copyright (C) 2010 Michael Krufky <mkrufky@kernellabs.com>
5+ *
6+ * This program is free software; you can redistribute it and/or modify
7+ * it under the terms of the GNU General Public License as published by
8+ * the Free Software Foundation; either version 2 of the License, or
9+ * (at your option) any later version.
10+ *
11+ * This program is distributed in the hope that it will be useful,
12+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
13+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+ * GNU General Public License for more details.
15+ *
16+ * You should have received a copy of the GNU General Public License
17+ * along with this program; if not, write to the Free Software
18+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19+ */
20+
21+#include "mxl111sf-demod.h"
22+#include "mxl111sf-reg.h"
23+
24+/* debug */
25+static int mxl111sf_demod_debug;
26+module_param_named(debug, mxl111sf_demod_debug, int, 0644);
27+MODULE_PARM_DESC(debug, "set debugging level (1=info (or-able)).");
28+
29+#define mxl_dbg(fmt, arg...) \
30+ if (mxl111sf_demod_debug) \
31+ mxl_printk(KERN_DEBUG, fmt, ##arg)
32+
33+/* ------------------------------------------------------------------------ */
34+
35+struct mxl111sf_demod_state {
36+ struct mxl111sf_state *mxl_state;
37+
38+ struct mxl111sf_demod_config *cfg;
39+
40+ struct dvb_frontend fe;
41+};
42+
43+/* ------------------------------------------------------------------------ */
44+
45+static int mxl111sf_demod_read_reg(struct mxl111sf_demod_state *state,
46+ u8 addr, u8 *data)
47+{
48+ return (state->cfg->read_reg) ?
49+ state->cfg->read_reg(state->mxl_state, addr, data) :
50+ -EINVAL;
51+}
52+
53+static int mxl111sf_demod_write_reg(struct mxl111sf_demod_state *state,
54+ u8 addr, u8 data)
55+{
56+ return (state->cfg->write_reg) ?
57+ state->cfg->write_reg(state->mxl_state, addr, data) :
58+ -EINVAL;
59+}
60+
61+static
62+int mxl111sf_demod_program_regs(struct mxl111sf_demod_state *state,
63+ struct mxl111sf_reg_ctrl_info *ctrl_reg_info)
64+{
65+ return (state->cfg->program_regs) ?
66+ state->cfg->program_regs(state->mxl_state, ctrl_reg_info) :
67+ -EINVAL;
68+}
69+
70+/* ------------------------------------------------------------------------ */
71+/* TPS */
72+
73+static
74+int mxl1x1sf_demod_get_tps_code_rate(struct mxl111sf_demod_state *state,
75+ fe_code_rate_t *code_rate)
76+{
77+ u8 val;
78+ int ret = mxl111sf_demod_read_reg(state, V6_CODE_RATE_TPS_REG, &val);
79+ /* bit<2:0> - 000:1/2, 001:2/3, 010:3/4, 011:5/6, 100:7/8 */
80+ if (mxl_fail(ret))
81+ goto fail;
82+
83+ switch (val & V6_CODE_RATE_TPS_MASK) {
84+ case 0:
85+ *code_rate = FEC_1_2;
86+ break;
87+ case 1:
88+ *code_rate = FEC_2_3;
89+ break;
90+ case 2:
91+ *code_rate = FEC_3_4;
92+ break;
93+ case 3:
94+ *code_rate = FEC_5_6;
95+ break;
96+ case 4:
97+ *code_rate = FEC_7_8;
98+ break;
99+ }
100+fail:
101+ return ret;
102+}
103+
104+static
105+int mxl1x1sf_demod_get_tps_constellation(struct mxl111sf_demod_state *state,
106+ fe_modulation_t *constellation)
107+{
108+ u8 val;
109+ int ret = mxl111sf_demod_read_reg(state, V6_MODORDER_TPS_REG, &val);
110+ /* Constellation, 00 : QPSK, 01 : 16QAM, 10:64QAM */
111+ if (mxl_fail(ret))
112+ goto fail;
113+
114+ switch ((val & V6_PARAM_CONSTELLATION_MASK) >> 4) {
115+ case 0:
116+ *constellation = QPSK;
117+ break;
118+ case 1:
119+ *constellation = QAM_16;
120+ break;
121+ case 2:
122+ *constellation = QAM_64;
123+ break;
124+ }
125+fail:
126+ return ret;
127+}
128+
129+static
130+int mxl1x1sf_demod_get_tps_guard_fft_mode(struct mxl111sf_demod_state *state,
131+ fe_transmit_mode_t *fft_mode)
132+{
133+ u8 val;
134+ int ret = mxl111sf_demod_read_reg(state, V6_MODE_TPS_REG, &val);
135+ /* FFT Mode, 00:2K, 01:8K, 10:4K */
136+ if (mxl_fail(ret))
137+ goto fail;
138+
139+ switch ((val & V6_PARAM_FFT_MODE_MASK) >> 2) {
140+ case 0:
141+ *fft_mode = TRANSMISSION_MODE_2K;
142+ break;
143+ case 1:
144+ *fft_mode = TRANSMISSION_MODE_8K;
145+ break;
146+ case 2:
147+ *fft_mode = TRANSMISSION_MODE_4K;
148+ break;
149+ }
150+fail:
151+ return ret;
152+}
153+
154+static
155+int mxl1x1sf_demod_get_tps_guard_interval(struct mxl111sf_demod_state *state,
156+ fe_guard_interval_t *guard)
157+{
158+ u8 val;
159+ int ret = mxl111sf_demod_read_reg(state, V6_CP_TPS_REG, &val);
160+ /* 00:1/32, 01:1/16, 10:1/8, 11:1/4 */
161+ if (mxl_fail(ret))
162+ goto fail;
163+
164+ switch ((val & V6_PARAM_GI_MASK) >> 4) {
165+ case 0:
166+ *guard = GUARD_INTERVAL_1_32;
167+ break;
168+ case 1:
169+ *guard = GUARD_INTERVAL_1_16;
170+ break;
171+ case 2:
172+ *guard = GUARD_INTERVAL_1_8;
173+ break;
174+ case 3:
175+ *guard = GUARD_INTERVAL_1_4;
176+ break;
177+ }
178+fail:
179+ return ret;
180+}
181+
182+static
183+int mxl1x1sf_demod_get_tps_hierarchy(struct mxl111sf_demod_state *state,
184+ fe_hierarchy_t *hierarchy)
185+{
186+ u8 val;
187+ int ret = mxl111sf_demod_read_reg(state, V6_TPS_HIERACHY_REG, &val);
188+ /* bit<6:4> - 000:Non hierarchy, 001:1, 010:2, 011:4 */
189+ if (mxl_fail(ret))
190+ goto fail;
191+
192+ switch ((val & V6_TPS_HIERARCHY_INFO_MASK) >> 6) {
193+ case 0:
194+ *hierarchy = HIERARCHY_NONE;
195+ break;
196+ case 1:
197+ *hierarchy = HIERARCHY_1;
198+ break;
199+ case 2:
200+ *hierarchy = HIERARCHY_2;
201+ break;
202+ case 3:
203+ *hierarchy = HIERARCHY_4;
204+ break;
205+ }
206+fail:
207+ return ret;
208+}
209+
210+/* ------------------------------------------------------------------------ */
211+/* LOCKS */
212+
213+static
214+int mxl1x1sf_demod_get_sync_lock_status(struct mxl111sf_demod_state *state,
215+ int *sync_lock)
216+{
217+ u8 val = 0;
218+ int ret = mxl111sf_demod_read_reg(state, V6_SYNC_LOCK_REG, &val);
219+ if (mxl_fail(ret))
220+ goto fail;
221+ *sync_lock = (val & SYNC_LOCK_MASK) >> 4;
222+fail:
223+ return ret;
224+}
225+
226+static
227+int mxl1x1sf_demod_get_rs_lock_status(struct mxl111sf_demod_state *state,
228+ int *rs_lock)
229+{
230+ u8 val = 0;
231+ int ret = mxl111sf_demod_read_reg(state, V6_RS_LOCK_DET_REG, &val);
232+ if (mxl_fail(ret))
233+ goto fail;
234+ *rs_lock = (val & RS_LOCK_DET_MASK) >> 3;
235+fail:
236+ return ret;
237+}
238+
239+static
240+int mxl1x1sf_demod_get_tps_lock_status(struct mxl111sf_demod_state *state,
241+ int *tps_lock)
242+{
243+ u8 val = 0;
244+ int ret = mxl111sf_demod_read_reg(state, V6_TPS_LOCK_REG, &val);
245+ if (mxl_fail(ret))
246+ goto fail;
247+ *tps_lock = (val & V6_PARAM_TPS_LOCK_MASK) >> 6;
248+fail:
249+ return ret;
250+}
251+
252+static
253+int mxl1x1sf_demod_get_fec_lock_status(struct mxl111sf_demod_state *state,
254+ int *fec_lock)
255+{
256+ u8 val = 0;
257+ int ret = mxl111sf_demod_read_reg(state, V6_IRQ_STATUS_REG, &val);
258+ if (mxl_fail(ret))
259+ goto fail;
260+ *fec_lock = (val & IRQ_MASK_FEC_LOCK) >> 4;
261+fail:
262+ return ret;
263+}
264+
265+#if 0
266+static
267+int mxl1x1sf_demod_get_cp_lock_status(struct mxl111sf_demod_state *state,
268+ int *cp_lock)
269+{
270+ u8 val = 0;
271+ int ret = mxl111sf_demod_read_reg(state, V6_CP_LOCK_DET_REG, &val);
272+ if (mxl_fail(ret))
273+ goto fail;
274+ *cp_lock = (val & V6_CP_LOCK_DET_MASK) >> 2;
275+fail:
276+ return ret;
277+}
278+#endif
279+
280+static int mxl1x1sf_demod_reset_irq_status(struct mxl111sf_demod_state *state)
281+{
282+ return mxl111sf_demod_write_reg(state, 0x0e, 0xff);
283+}
284+
285+/* ------------------------------------------------------------------------ */
286+
287+static int mxl111sf_demod_set_frontend(struct dvb_frontend *fe,
288+ struct dvb_frontend_parameters *param)
289+{
290+ struct mxl111sf_demod_state *state = fe->demodulator_priv;
291+ int ret = 0;
292+
293+ struct mxl111sf_reg_ctrl_info phy_pll_patch[] = {
294+ {0x00, 0xff, 0x01}, /* change page to 1 */
295+ {0x40, 0xff, 0x05},
296+ {0x40, 0xff, 0x01},
297+ {0x41, 0xff, 0xca},
298+ {0x41, 0xff, 0xc0},
299+ {0x00, 0xff, 0x00}, /* change page to 0 */
300+ {0, 0, 0}
301+ };
302+
303+ mxl_dbg("()");
304+
305+ if (fe->ops.tuner_ops.set_params) {
306+ ret = fe->ops.tuner_ops.set_params(fe, param);
307+ if (mxl_fail(ret))
308+ goto fail;
309+ msleep(50);
310+ }
311+ ret = mxl111sf_demod_program_regs(state, phy_pll_patch);
312+ mxl_fail(ret);
313+ msleep(50);
314+ ret = mxl1x1sf_demod_reset_irq_status(state);
315+ mxl_fail(ret);
316+ msleep(100);
317+fail:
318+ return ret;
319+}
320+
321+/* ------------------------------------------------------------------------ */
322+
323+#if 0
324+/* resets TS Packet error count */
325+/* After setting 7th bit of V5_PER_COUNT_RESET_REG, it should be reset to 0. */
326+static
327+int mxl1x1sf_demod_reset_packet_error_count(struct mxl111sf_demod_state *state)
328+{
329+ struct mxl111sf_reg_ctrl_info reset_per_count[] = {
330+ {0x20, 0x01, 0x01},
331+ {0x20, 0x01, 0x00},
332+ {0, 0, 0}
333+ };
334+ return mxl111sf_demod_program_regs(state, reset_per_count);
335+}
336+#endif
337+
338+/* returns TS Packet error count */
339+/* PER Count = FEC_PER_COUNT * (2 ** (FEC_PER_SCALE * 4)) */
340+static int mxl111sf_demod_read_ucblocks(struct dvb_frontend *fe, u32 *ucblocks)
341+{
342+ struct mxl111sf_demod_state *state = fe->demodulator_priv;
343+ u32 fec_per_count, fec_per_scale;
344+ u8 val;
345+ int ret;
346+
347+ *ucblocks = 0;
348+
349+ /* FEC_PER_COUNT Register */
350+ ret = mxl111sf_demod_read_reg(state, V6_FEC_PER_COUNT_REG, &val);
351+ if (mxl_fail(ret))
352+ goto fail;
353+
354+ fec_per_count = val;
355+
356+ /* FEC_PER_SCALE Register */
357+ ret = mxl111sf_demod_read_reg(state, V6_FEC_PER_SCALE_REG, &val);
358+ if (mxl_fail(ret))
359+ goto fail;
360+
361+ val &= V6_FEC_PER_SCALE_MASK;
362+ val *= 4;
363+
364+ fec_per_scale = 1 << val;
365+
366+ fec_per_count *= fec_per_scale;
367+
368+ *ucblocks = fec_per_count;
369+fail:
370+ return ret;
371+}
372+
373+#ifdef MXL111SF_DEMOD_ENABLE_CALCULATIONS
374+/* FIXME: leaving this enabled breaks the build on some architectures,
375+ * and we shouldn't have any floating point math in the kernel, anyway.
376+ *
377+ * These macros need to be re-written, but it's harmless to simply
378+ * return zero for now. */
379+#define CALCULATE_BER(avg_errors, count) \
380+ ((u32)(avg_errors * 4)/(count*64*188*8))
381+#define CALCULATE_SNR(data) \
382+ ((u32)((10 * (u32)data / 64) - 2.5))
383+#else
384+#define CALCULATE_BER(avg_errors, count) 0
385+#define CALCULATE_SNR(data) 0
386+#endif
387+
388+static int mxl111sf_demod_read_ber(struct dvb_frontend *fe, u32 *ber)
389+{
390+ struct mxl111sf_demod_state *state = fe->demodulator_priv;
391+ u8 val1, val2, val3;
392+ int ret;
393+
394+ *ber = 0;
395+
396+ ret = mxl111sf_demod_read_reg(state, V6_RS_AVG_ERRORS_LSB_REG, &val1);
397+ if (mxl_fail(ret))
398+ goto fail;
399+ ret = mxl111sf_demod_read_reg(state, V6_RS_AVG_ERRORS_MSB_REG, &val2);
400+ if (mxl_fail(ret))
401+ goto fail;
402+ ret = mxl111sf_demod_read_reg(state, V6_N_ACCUMULATE_REG, &val3);
403+ if (mxl_fail(ret))
404+ goto fail;
405+
406+ *ber = CALCULATE_BER((val1 | (val2 << 8)), val3);
407+fail:
408+ return ret;
409+}
410+
411+static int mxl111sf_demod_calc_snr(struct mxl111sf_demod_state *state,
412+ u16 *snr)
413+{
414+ u8 val1, val2;
415+ int ret;
416+
417+ *snr = 0;
418+
419+ ret = mxl111sf_demod_read_reg(state, V6_SNR_RB_LSB_REG, &val1);
420+ if (mxl_fail(ret))
421+ goto fail;
422+ ret = mxl111sf_demod_read_reg(state, V6_SNR_RB_MSB_REG, &val2);
423+ if (mxl_fail(ret))
424+ goto fail;
425+
426+ *snr = CALCULATE_SNR(val1 | ((val2 & 0x03) << 8));
427+fail:
428+ return ret;
429+}
430+
431+static int mxl111sf_demod_read_snr(struct dvb_frontend *fe, u16 *snr)
432+{
433+ struct mxl111sf_demod_state *state = fe->demodulator_priv;
434+
435+ int ret = mxl111sf_demod_calc_snr(state, snr);
436+ if (mxl_fail(ret))
437+ goto fail;
438+
439+ *snr /= 10; /* 0.1 dB */
440+fail:
441+ return ret;
442+}
443+
444+static int mxl111sf_demod_read_status(struct dvb_frontend *fe,
445+ fe_status_t *status)
446+{
447+ struct mxl111sf_demod_state *state = fe->demodulator_priv;
448+ int ret, locked, cr_lock, sync_lock, fec_lock;
449+
450+ *status = 0;
451+
452+ ret = mxl1x1sf_demod_get_rs_lock_status(state, &locked);
453+ if (mxl_fail(ret))
454+ goto fail;
455+ ret = mxl1x1sf_demod_get_tps_lock_status(state, &cr_lock);
456+ if (mxl_fail(ret))
457+ goto fail;
458+ ret = mxl1x1sf_demod_get_sync_lock_status(state, &sync_lock);
459+ if (mxl_fail(ret))
460+ goto fail;
461+ ret = mxl1x1sf_demod_get_fec_lock_status(state, &fec_lock);
462+ if (mxl_fail(ret))
463+ goto fail;
464+
465+ if (locked)
466+ *status |= FE_HAS_SIGNAL;
467+ if (cr_lock)
468+ *status |= FE_HAS_CARRIER;
469+ if (sync_lock)
470+ *status |= FE_HAS_SYNC;
471+ if (fec_lock) /* false positives? */
472+ *status |= FE_HAS_VITERBI;
473+
474+ if ((locked) && (cr_lock) && (sync_lock))
475+ *status |= FE_HAS_LOCK;
476+fail:
477+ return ret;
478+}
479+
480+static int mxl111sf_demod_read_signal_strength(struct dvb_frontend *fe,
481+ u16 *signal_strength)
482+{
483+ struct mxl111sf_demod_state *state = fe->demodulator_priv;
484+ fe_modulation_t constellation;
485+ u16 snr;
486+
487+ mxl111sf_demod_calc_snr(state, &snr);
488+ mxl1x1sf_demod_get_tps_constellation(state, &constellation);
489+
490+ switch (constellation) {
491+ case QPSK:
492+ *signal_strength = (snr >= 1300) ?
493+ min(65535, snr * 44) : snr * 38;
494+ break;
495+ case QAM_16:
496+ *signal_strength = (snr >= 1500) ?
497+ min(65535, snr * 38) : snr * 33;
498+ break;
499+ case QAM_64:
500+ *signal_strength = (snr >= 2000) ?
501+ min(65535, snr * 29) : snr * 25;
502+ break;
503+ default:
504+ *signal_strength = 0;
505+ return -EINVAL;
506+ }
507+
508+ return 0;
509+}
510+
511+static int mxl111sf_demod_get_frontend(struct dvb_frontend *fe,
512+ struct dvb_frontend_parameters *p)
513+{
514+ struct mxl111sf_demod_state *state = fe->demodulator_priv;
515+
516+ mxl_dbg("()");
517+#if 0
518+ p->inversion = /* FIXME */ ? INVERSION_ON : INVERSION_OFF;
519+#endif
520+ if (fe->ops.tuner_ops.get_bandwidth)
521+ fe->ops.tuner_ops.get_bandwidth(fe, &p->u.ofdm.bandwidth);
522+ if (fe->ops.tuner_ops.get_frequency)
523+ fe->ops.tuner_ops.get_frequency(fe, &p->frequency);
524+ mxl1x1sf_demod_get_tps_code_rate(state, &p->u.ofdm.code_rate_HP);
525+ mxl1x1sf_demod_get_tps_code_rate(state, &p->u.ofdm.code_rate_LP);
526+ mxl1x1sf_demod_get_tps_constellation(state, &p->u.ofdm.constellation);
527+ mxl1x1sf_demod_get_tps_guard_fft_mode(state,
528+ &p->u.ofdm.transmission_mode);
529+ mxl1x1sf_demod_get_tps_guard_interval(state,
530+ &p->u.ofdm.guard_interval);
531+ mxl1x1sf_demod_get_tps_hierarchy(state,
532+ &p->u.ofdm.hierarchy_information);
533+
534+ return 0;
535+}
536+
537+static
538+int mxl111sf_demod_get_tune_settings(struct dvb_frontend *fe,
539+ struct dvb_frontend_tune_settings *tune)
540+{
541+ tune->min_delay_ms = 1000;
542+ return 0;
543+}
544+
545+static void mxl111sf_demod_release(struct dvb_frontend *fe)
546+{
547+ struct mxl111sf_demod_state *state = fe->demodulator_priv;
548+ mxl_dbg("()");
549+ kfree(state);
550+ fe->demodulator_priv = NULL;
551+}
552+
553+static struct dvb_frontend_ops mxl111sf_demod_ops = {
554+
555+ .info = {
556+ .name = "MaxLinear MxL111SF DVB-T demodulator",
557+ .type = FE_OFDM,
558+ .frequency_min = 177000000,
559+ .frequency_max = 858000000,
560+ .frequency_stepsize = 166666,
561+ .caps = FE_CAN_FEC_1_2 | FE_CAN_FEC_2_3 | FE_CAN_FEC_3_4 |
562+ FE_CAN_FEC_5_6 | FE_CAN_FEC_7_8 | FE_CAN_FEC_AUTO |
563+ FE_CAN_QPSK | FE_CAN_QAM_16 | FE_CAN_QAM_64 |
564+ FE_CAN_QAM_AUTO |
565+ FE_CAN_HIERARCHY_AUTO | FE_CAN_GUARD_INTERVAL_AUTO |
566+ FE_CAN_TRANSMISSION_MODE_AUTO | FE_CAN_RECOVER
567+ },
568+ .release = mxl111sf_demod_release,
569+#if 0
570+ .init = mxl111sf_init,
571+ .i2c_gate_ctrl = mxl111sf_i2c_gate_ctrl,
572+#endif
573+ .set_frontend = mxl111sf_demod_set_frontend,
574+ .get_frontend = mxl111sf_demod_get_frontend,
575+ .get_tune_settings = mxl111sf_demod_get_tune_settings,
576+ .read_status = mxl111sf_demod_read_status,
577+ .read_signal_strength = mxl111sf_demod_read_signal_strength,
578+ .read_ber = mxl111sf_demod_read_ber,
579+ .read_snr = mxl111sf_demod_read_snr,
580+ .read_ucblocks = mxl111sf_demod_read_ucblocks,
581+};
582+
583+struct dvb_frontend *mxl111sf_demod_attach(struct mxl111sf_state *mxl_state,
584+ struct mxl111sf_demod_config *cfg)
585+{
586+ struct mxl111sf_demod_state *state = NULL;
587+
588+ mxl_dbg("()");
589+
590+ state = kzalloc(sizeof(struct mxl111sf_demod_state), GFP_KERNEL);
591+ if (state == NULL)
592+ return NULL;
593+
594+ state->mxl_state = mxl_state;
595+ state->cfg = cfg;
596+
597+ memcpy(&state->fe.ops, &mxl111sf_demod_ops,
598+ sizeof(struct dvb_frontend_ops));
599+
600+ state->fe.demodulator_priv = state;
601+ return &state->fe;
602+}
603+EXPORT_SYMBOL_GPL(mxl111sf_demod_attach);
604+
605+MODULE_DESCRIPTION("MaxLinear MxL111SF DVB-T demodulator driver");
606+MODULE_AUTHOR("Michael Krufky <mkrufky@kernellabs.com>");
607+MODULE_LICENSE("GPL");
608+MODULE_VERSION("0.1");
609+
610+/*
611+ * Local variables:
612+ * c-basic-offset: 8
613+ * End:
614+ */
drivers/media/dvb/dvb-usb/mxl111sf-demod.h+55−0
@@ -0,0 +1,55 @@
1+/*
2+ * mxl111sf-demod.h - driver for the MaxLinear MXL111SF DVB-T demodulator
3+ *
4+ * Copyright (C) 2010 Michael Krufky <mkrufky@kernellabs.com>
5+ *
6+ * This program is free software; you can redistribute it and/or modify
7+ * it under the terms of the GNU General Public License as published by
8+ * the Free Software Foundation; either version 2 of the License, or
9+ * (at your option) any later version.
10+ *
11+ * This program is distributed in the hope that it will be useful,
12+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
13+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+ * GNU General Public License for more details.
15+ *
16+ * You should have received a copy of the GNU General Public License
17+ * along with this program; if not, write to the Free Software
18+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19+ */
20+
21+#ifndef __MXL111SF_DEMOD_H__
22+#define __MXL111SF_DEMOD_H__
23+
24+#include "dvb_frontend.h"
25+#include "mxl111sf.h"
26+
27+struct mxl111sf_demod_config {
28+ int (*read_reg)(struct mxl111sf_state *state, u8 addr, u8 *data);
29+ int (*write_reg)(struct mxl111sf_state *state, u8 addr, u8 data);
30+ int (*program_regs)(struct mxl111sf_state *state,
31+ struct mxl111sf_reg_ctrl_info *ctrl_reg_info);
32+};
33+
34+#if defined(CONFIG_DVB_USB_MXL111SF) || \
35+ (defined(CONFIG_DVB_USB_MXL111SF_MODULE) && defined(MODULE))
36+extern
37+struct dvb_frontend *mxl111sf_demod_attach(struct mxl111sf_state *mxl_state,
38+ struct mxl111sf_demod_config *cfg);
39+#else
40+static inline
41+struct dvb_frontend *mxl111sf_demod_attach(struct mxl111sf_state *mxl_state,
42+ struct mxl111sf_demod_config *cfg)
43+{
44+ printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __func__);
45+ return NULL;
46+}
47+#endif /* CONFIG_DVB_USB_MXL111SF */
48+
49+#endif /* __MXL111SF_DEMOD_H__ */
50+
51+/*
52+ * Local variables:
53+ * c-basic-offset: 8
54+ * End:
55+ */
drivers/media/dvb/dvb-usb/mxl111sf.c+225−3
@@ -17,6 +17,7 @@ · 16 unmodified lines
1717 #include "mxl111sf-i2c.h"
1818 #include "mxl111sf-gpio.h"
1919
20+#include "mxl111sf-demod.h"
2021 #include "mxl111sf-tuner.h"
2122
2223 #include "lgdt3305.h"
@@ -362,6 +363,22 @@ static int mxl111sf_ep6_streaming_ctrl(struct dvb_usb_adapter *adap, int onoff) · 339 unmodified lines
362363 return ret;
363364 }
364365
366+static int mxl111sf_ep4_streaming_ctrl(struct dvb_usb_adapter *adap, int onoff)
367+{
368+ struct dvb_usb_device *d = adap->dev;
369+ struct mxl111sf_state *state = d->priv;
370+ int ret = 0;
371+
372+ deb_info("%s(%d)\n", __func__, onoff);
373+
374+ if (onoff) {
375+ ret = mxl111sf_enable_usb_output(state);
376+ mxl_fail(ret);
377+ }
378+
379+ return ret;
380+}
381+
365382 /* ------------------------------------------------------------------------ */
366383
367384 static struct lgdt3305_config hauppauge_lgdt3305_config = {
@@ -438,6 +455,70 @@ fail: · 70 unmodified lines
438455 return ret;
439456 }
440457
458+static struct mxl111sf_demod_config mxl_demod_config = {
459+ .read_reg = mxl111sf_read_reg,
460+ .write_reg = mxl111sf_write_reg,
461+ .program_regs = mxl111sf_ctrl_program_regs,
462+};
463+
464+static int mxl111sf_attach_demod(struct dvb_usb_adapter *adap)
465+{
466+ struct dvb_usb_device *d = adap->dev;
467+ struct mxl111sf_state *state = d->priv;
468+ int fe_id = adap->num_frontends_initialized;
469+ struct mxl111sf_adap_state *adap_state = adap->fe_adap[fe_id].priv;
470+ int ret;
471+
472+ deb_adv("%s()\n", __func__);
473+
474+ /* save a pointer to the dvb_usb_device in device state */
475+ state->d = d;
476+ adap_state->alt_mode = (dvb_usb_mxl111sf_isoc) ? 1 : 2;
477+ state->alt_mode = adap_state->alt_mode;
478+
479+ if (usb_set_interface(adap->dev->udev, 0, state->alt_mode) < 0)
480+ err("set interface failed");
481+
482+ state->gpio_mode = MXL111SF_GPIO_MOD_DVBT;
483+ adap_state->gpio_mode = state->gpio_mode;
484+ adap_state->device_mode = MXL_SOC_MODE;
485+ adap_state->ep6_clockphase = 1;
486+
487+ ret = mxl1x1sf_soft_reset(state);
488+ if (mxl_fail(ret))
489+ goto fail;
490+ ret = mxl111sf_init_tuner_demod(state);
491+ if (mxl_fail(ret))
492+ goto fail;
493+
494+ ret = mxl1x1sf_set_device_mode(state, adap_state->device_mode);
495+ if (mxl_fail(ret))
496+ goto fail;
497+
498+ ret = mxl111sf_enable_usb_output(state);
499+ if (mxl_fail(ret))
500+ goto fail;
501+ ret = mxl1x1sf_top_master_ctrl(state, 1);
502+ if (mxl_fail(ret))
503+ goto fail;
504+
505+ /* dont care if this fails */
506+ mxl111sf_init_port_expander(state);
507+
508+ adap->fe_adap[fe_id].fe = dvb_attach(mxl111sf_demod_attach, state,
509+ &mxl_demod_config);
510+ if (adap->fe_adap[fe_id].fe) {
511+ adap_state->fe_init = adap->fe_adap[fe_id].fe->ops.init;
512+ adap->fe_adap[fe_id].fe->ops.init = mxl111sf_adap_fe_init;
513+ adap_state->fe_sleep = adap->fe_adap[fe_id].fe->ops.sleep;
514+ adap->fe_adap[fe_id].fe->ops.sleep = mxl111sf_adap_fe_sleep;
515+ return 0;
516+ }
517+ ret = -EIO;
518+fail:
519+ return ret;
520+}
521+
441522 static inline int mxl111sf_set_ant_path(struct mxl111sf_state *state,
442523 int antpath)
443524 {
@@ -567,7 +648,8 @@ struct i2c_algorithm mxl111sf_i2c_algo = { · 123 unmodified lines
567648 #endif
568649 };
569650
570−/* DVB USB Driver stuff */
651+static struct dvb_usb_device_properties mxl111sf_dvbt_bulk_properties;
652+static struct dvb_usb_device_properties mxl111sf_dvbt_isoc_properties;
571653 static struct dvb_usb_device_properties mxl111sf_atsc_bulk_properties;
572654 static struct dvb_usb_device_properties mxl111sf_atsc_isoc_properties;
573655
@@ -580,8 +662,14 @@ static int mxl111sf_probe(struct usb_interface *intf, · 6 unmodified lines
580662
581663 if (((dvb_usb_mxl111sf_isoc) &&
582664 (0 == dvb_usb_device_init(intf,
665+ &mxl111sf_dvbt_isoc_properties,
666+ THIS_MODULE, &d, adapter_nr) ||
667+ 0 == dvb_usb_device_init(intf,
583668 &mxl111sf_atsc_isoc_properties,
584669 THIS_MODULE, &d, adapter_nr))) ||
670+ 0 == dvb_usb_device_init(intf,
671+ &mxl111sf_dvbt_bulk_properties,
672+ THIS_MODULE, &d, adapter_nr) ||
585673 0 == dvb_usb_device_init(intf,
586674 &mxl111sf_atsc_bulk_properties,
587675 THIS_MODULE, &d, adapter_nr) || 0) {
@@ -669,6 +757,36 @@ static struct usb_device_id mxl111sf_table[] = { · 81 unmodified lines
669757 MODULE_DEVICE_TABLE(usb, mxl111sf_table);
670758
671759
760+#define MXL111SF_EP4_BULK_STREAMING_CONFIG \
761+ .streaming_ctrl = mxl111sf_ep4_streaming_ctrl, \
762+ .stream = { \
763+ .type = USB_BULK, \
764+ .count = 5, \
765+ .endpoint = 0x04, \
766+ .u = { \
767+ .bulk = { \
768+ .buffersize = 8192, \
769+ } \
770+ } \
771+ }
772+
773+/* FIXME: works for v6 but not v8 silicon */
774+#define MXL111SF_EP4_ISOC_STREAMING_CONFIG \
775+ .streaming_ctrl = mxl111sf_ep4_streaming_ctrl, \
776+ .stream = { \
777+ .type = USB_ISOC, \
778+ .count = 5, \
779+ .endpoint = 0x04, \
780+ .u = { \
781+ .isoc = { \
782+ .framesperurb = 96, \
783+ /* FIXME: v6 SILICON: */ \
784+ .framesize = 564, \
785+ .interval = 1, \
786+ } \
787+ } \
788+ }
789+
672790 #define MXL111SF_EP6_BULK_STREAMING_CONFIG \
673791 .streaming_ctrl = mxl111sf_ep6_streaming_ctrl, \
674792 .stream = { \
@@ -712,7 +830,7 @@ MODULE_DEVICE_TABLE(usb, mxl111sf_table); · 37 unmodified lines
712830 .generic_bulk_ctrl_endpoint_response = MXL_EP1_REG_READ, \
713831 .size_of_priv = sizeof(struct mxl111sf_state)
714832
715−static struct dvb_usb_device_properties mxl111sf_atsc_bulk_properties = {
833+static struct dvb_usb_device_properties mxl111sf_dvbt_bulk_properties = {
716834 MXL111SF_DEFAULT_DEVICE_PROPERTIES,
717835
718836 .num_adapters = 1,
@@ -723,10 +841,106 @@ static struct dvb_usb_device_properties mxl111sf_atsc_bulk_properties = { · 4 unmodified lines
723841 .fe = {{
724842 .size_of_priv = sizeof(struct mxl111sf_adap_state),
725843
844+ .frontend_attach = mxl111sf_attach_demod,
845+ .tuner_attach = mxl111sf_attach_tuner,
846+
847+ MXL111SF_EP4_BULK_STREAMING_CONFIG,
848+ } },
849+ },
850+ },
851+ .num_device_descs = 4,
852+ .devices = {
853+ { "Hauppauge 126xxx DVBT (bulk)",
854+ { NULL },
855+ { &mxl111sf_table[4], &mxl111sf_table[8],
856+ NULL },
857+ },
858+ { "Hauppauge 117xxx DVBT (bulk)",
859+ { NULL },
860+ { &mxl111sf_table[15], &mxl111sf_table[18],
861+ NULL },
862+ },
863+ { "Hauppauge 138xxx DVBT (bulk)",
864+ { NULL },
865+ { &mxl111sf_table[20], &mxl111sf_table[22],
866+ &mxl111sf_table[24], &mxl111sf_table[26],
867+ NULL },
868+ },
869+ { "Hauppauge 126xxx (tp-bulk)",
870+ { NULL },
871+ { &mxl111sf_table[28], &mxl111sf_table[30],
872+ NULL },
873+ },
874+ }
875+};
876+
877+static struct dvb_usb_device_properties mxl111sf_dvbt_isoc_properties = {
878+ MXL111SF_DEFAULT_DEVICE_PROPERTIES,
879+
880+ .num_adapters = 1,
881+ .adapter = {
882+ {
883+ .fe_ioctl_override = mxl111sf_fe_ioctl_override,
884+ .num_frontends = 1,
885+ .fe = {{
886+ .size_of_priv = sizeof(struct mxl111sf_adap_state),
887+
888+ .frontend_attach = mxl111sf_attach_demod,
889+ .tuner_attach = mxl111sf_attach_tuner,
890+
891+ MXL111SF_EP4_ISOC_STREAMING_CONFIG,
892+ } },
893+ },
894+ },
895+ .num_device_descs = 4,
896+ .devices = {
897+ { "Hauppauge 126xxx DVBT (isoc)",
898+ { NULL },
899+ { &mxl111sf_table[4], &mxl111sf_table[8],
900+ NULL },
901+ },
902+ { "Hauppauge 117xxx DVBT (isoc)",
903+ { NULL },
904+ { &mxl111sf_table[15], &mxl111sf_table[18],
905+ NULL },
906+ },
907+ { "Hauppauge 138xxx DVBT (isoc)",
908+ { NULL },
909+ { &mxl111sf_table[20], &mxl111sf_table[22],
910+ &mxl111sf_table[24], &mxl111sf_table[26],
911+ NULL },
912+ },
913+ { "Hauppauge 126xxx (tp-isoc)",
914+ { NULL },
915+ { &mxl111sf_table[28], &mxl111sf_table[30],
916+ NULL },
917+ },
918+ }
919+};
920+
921+static struct dvb_usb_device_properties mxl111sf_atsc_bulk_properties = {
922+ MXL111SF_DEFAULT_DEVICE_PROPERTIES,
923+
924+ .num_adapters = 1,
925+ .adapter = {
926+ {
927+ .fe_ioctl_override = mxl111sf_fe_ioctl_override,
928+ .num_frontends = 2,
929+ .fe = {{
930+ .size_of_priv = sizeof(struct mxl111sf_adap_state),
931+
726932 .frontend_attach = mxl111sf_lgdt3305_frontend_attach,
727933 .tuner_attach = mxl111sf_attach_tuner,
728934
729935 MXL111SF_EP6_BULK_STREAMING_CONFIG,
936+ },
937+ {
938+ .size_of_priv = sizeof(struct mxl111sf_adap_state),
939+
940+ .frontend_attach = mxl111sf_attach_demod,
941+ .tuner_attach = mxl111sf_attach_tuner,
942+
943+ MXL111SF_EP4_BULK_STREAMING_CONFIG,
730944 }},
731945 },
732946 },
@@ -776,7 +990,7 @@ static struct dvb_usb_device_properties mxl111sf_atsc_isoc_properties = { · 43 unmodified lines
776990 .adapter = {
777991 {
778992 .fe_ioctl_override = mxl111sf_fe_ioctl_override,
779− .num_frontends = 1,
993+ .num_frontends = 2,
780994 .fe = {{
781995 .size_of_priv = sizeof(struct mxl111sf_adap_state),
782996
@@ -784,6 +998,14 @@ static struct dvb_usb_device_properties mxl111sf_atsc_isoc_properties = { · 1 unmodified line
784998 .tuner_attach = mxl111sf_attach_tuner,
785999
7861000 MXL111SF_EP6_ISOC_STREAMING_CONFIG,
1001+ },
1002+ {
1003+ .size_of_priv = sizeof(struct mxl111sf_adap_state),
1004+
1005+ .frontend_attach = mxl111sf_attach_demod,
1006+ .tuner_attach = mxl111sf_attach_tuner,
1007+
1008+ MXL111SF_EP4_ISOC_STREAMING_CONFIG,
7871009 }},
7881010 },
7891011 },
drivers/media/dvb/dvb-usb/mxl111sf.h+1−1
@@ -133,7 +133,7 @@ extern int dvb_usb_mxl111sf_debug; · 132 unmodified lines
133133 /* The following allows the mxl_fail() macro defined below to work
134134 * in externel modules, such as mxl111sf-tuner.ko, even though
135135 * dvb_usb_mxl111sf_debug is not defined within those modules */
136−#ifdef __MXL111SF_TUNER_H__
136+#if (defined(__MXL111SF_TUNER_H__)) || (defined(__MXL111SF_DEMOD_H__))
137137 #define MXL_ADV_DEBUG_ENABLED MXL_ADV_DBG
138138 #else
139139 #define MXL_ADV_DEBUG_ENABLED dvb_usb_mxl111sf_debug
drivers/media/dvb/ngene/Makefile+1−1
@@ -11,4 +11,4 @@ ccflags-y += -Idrivers/media/dvb/frontends/ · 10 unmodified lines
1111 ccflags-y += -Idrivers/media/common/tuners/
1212
1313 # For the staging CI driver cxd2099
14−ccflags-y += -Idrivers/staging/cxd2099/
14+ccflags-y += -Idrivers/staging/media/cxd2099/
drivers/media/radio/radio-tea5764.c+3−1
@@ -128,8 +128,10 @@ struct tea5764_write_regs { · 127 unmodified lines
128128 u16 rdsbbl; /* PAUSEDET & RDSBBL */
129129 } __attribute__ ((packed));
130130
131−#ifndef RADIO_TEA5764_XTAL
131+#ifdef CONFIG_RADIO_TEA5764_XTAL
132132 #define RADIO_TEA5764_XTAL 1
133+#else
134+#define RADIO_TEA5764_XTAL 0
133135 #endif
134136
135137 static int radio_nr = -1;
drivers/media/video/Kconfig+9−0
@@ -517,6 +517,13 @@ config VIDEO_NOON010PC30 · 516 unmodified lines
517517
518518 source "drivers/media/video/m5mols/Kconfig"
519519
520+config VIDEO_S5K6AA
521+ tristate "Samsung S5K6AAFX sensor support"
522+ depends on I2C && VIDEO_V4L2 && VIDEO_V4L2_SUBDEV_API
523+ ---help---
524+ This is a V4L2 sensor-level driver for Samsung S5K6AA(FX) 1.3M
525+ camera sensor with an embedded SoC image signal processor.
526+
520527 comment "Flash devices"
521528
522529 config VIDEO_ADP1653
@@ -736,6 +743,8 @@ source "drivers/media/video/cx88/Kconfig" · 213 unmodified lines
736743
737744 source "drivers/media/video/cx23885/Kconfig"
738745
746+source "drivers/media/video/cx25821/Kconfig"
747+
739748 source "drivers/media/video/au0828/Kconfig"
740749
741750 source "drivers/media/video/ivtv/Kconfig"
drivers/media/video/Makefile+2−0
@@ -72,6 +72,7 @@ obj-$(CONFIG_VIDEO_MT9V032) += mt9v032.o · 71 unmodified lines
7272 obj-$(CONFIG_VIDEO_SR030PC30) += sr030pc30.o
7373 obj-$(CONFIG_VIDEO_NOON010PC30) += noon010pc30.o
7474 obj-$(CONFIG_VIDEO_M5MOLS) += m5mols/
75+obj-$(CONFIG_VIDEO_S5K6AA) += s5k6aa.o
7576 obj-$(CONFIG_VIDEO_ADP1653) += adp1653.o
7677
7778 obj-$(CONFIG_SOC_CAMERA_IMX074) += imx074.o
@@ -104,6 +105,7 @@ obj-$(CONFIG_VIDEO_CX88) += cx88/ · 26 unmodified lines
104105 obj-$(CONFIG_VIDEO_EM28XX) += em28xx/
105106 obj-$(CONFIG_VIDEO_TLG2300) += tlg2300/
106107 obj-$(CONFIG_VIDEO_CX231XX) += cx231xx/
108+obj-$(CONFIG_VIDEO_CX25821) += cx25821/
107109 obj-$(CONFIG_VIDEO_USBVISION) += usbvision/
108110 obj-$(CONFIG_VIDEO_PVRUSB2) += pvrusb2/
109111 obj-$(CONFIG_VIDEO_CPIA2) += cpia2/
drivers/media/video/atmel-isi.c+76−66
@@ -94,6 +94,7 @@ struct atmel_isi { · 93 unmodified lines
9494 unsigned int irq;
9595
9696 struct isi_platform_data *pdata;
97+ u16 width_flags; /* max 12 bits */
9798
9899 struct list_head video_buffer_list;
99100 struct frame_buffer *active;
@@ -248,9 +249,9 @@ static int atmel_isi_wait_status(struct atmel_isi *isi, int wait_reset) · 148 unmodified lines
248249 /* ------------------------------------------------------------------
249250 Videobuf operations
250251 ------------------------------------------------------------------*/
251−static int queue_setup(struct vb2_queue *vq, unsigned int *nbuffers,
252− unsigned int *nplanes, unsigned int sizes[],
253− void *alloc_ctxs[])
252+static int queue_setup(struct vb2_queue *vq, const struct v4l2_format *fmt,
253+ unsigned int *nbuffers, unsigned int *nplanes,
254+ unsigned int sizes[], void *alloc_ctxs[])
254255 {
255256 struct soc_camera_device *icd = soc_camera_from_vb2q(vq);
256257 struct soc_camera_host *ici = to_soc_camera_host(icd->parent);
@@ -647,50 +648,42 @@ static bool isi_camera_packing_supported(const struct soc_mbus_pixelfmt *fmt) · 390 unmodified lines
647648 fmt->packing == SOC_MBUS_PACKING_EXTEND16);
648649 }
649650
650−static unsigned long make_bus_param(struct atmel_isi *isi)
651−{
652− unsigned long flags;
653− /*
654− * Platform specified synchronization and pixel clock polarities are
655− * only a recommendation and are only used during probing. Atmel ISI
656− * camera interface only works in master mode, i.e., uses HSYNC and
657− * VSYNC signals from the sensor
658− */
659− flags = SOCAM_MASTER |
660− SOCAM_HSYNC_ACTIVE_HIGH |
661− SOCAM_HSYNC_ACTIVE_LOW |
662− SOCAM_VSYNC_ACTIVE_HIGH |
663− SOCAM_VSYNC_ACTIVE_LOW |
664− SOCAM_PCLK_SAMPLE_RISING |
665− SOCAM_PCLK_SAMPLE_FALLING |
666− SOCAM_DATA_ACTIVE_HIGH;
667−
668− if (isi->pdata->data_width_flags & ISI_DATAWIDTH_10)
669− flags |= SOCAM_DATAWIDTH_10;
670−
671− if (isi->pdata->data_width_flags & ISI_DATAWIDTH_8)
672− flags |= SOCAM_DATAWIDTH_8;
673−
674− if (flags & SOCAM_DATAWIDTH_MASK)
675− return flags;
676−
677− return 0;
678−}
651+#define ISI_BUS_PARAM (V4L2_MBUS_MASTER | \
652+ V4L2_MBUS_HSYNC_ACTIVE_HIGH | \
653+ V4L2_MBUS_HSYNC_ACTIVE_LOW | \
654+ V4L2_MBUS_VSYNC_ACTIVE_HIGH | \
655+ V4L2_MBUS_VSYNC_ACTIVE_LOW | \
656+ V4L2_MBUS_PCLK_SAMPLE_RISING | \
657+ V4L2_MBUS_PCLK_SAMPLE_FALLING | \
658+ V4L2_MBUS_DATA_ACTIVE_HIGH)
679659
680660 static int isi_camera_try_bus_param(struct soc_camera_device *icd,
681661 unsigned char buswidth)
682662 {
663+ struct v4l2_subdev *sd = soc_camera_to_subdev(icd);
683664 struct soc_camera_host *ici = to_soc_camera_host(icd->parent);
684665 struct atmel_isi *isi = ici->priv;
685− unsigned long camera_flags;
666+ struct v4l2_mbus_config cfg = {.type = V4L2_MBUS_PARALLEL,};
667+ unsigned long common_flags;
686668 int ret;
687669
688− camera_flags = icd->ops->query_bus_param(icd);
689− ret = soc_camera_bus_param_compatible(camera_flags,
690− make_bus_param(isi));
691− if (!ret)
692− return -EINVAL;
693− return 0;
670+ ret = v4l2_subdev_call(sd, video, g_mbus_config, &cfg);
671+ if (!ret) {
672+ common_flags = soc_mbus_config_compatible(&cfg,
673+ ISI_BUS_PARAM);
674+ if (!common_flags) {
675+ dev_warn(icd->parent,
676+ "Flags incompatible: camera 0x%x, host 0x%x\n",
677+ cfg.flags, ISI_BUS_PARAM);
678+ return -EINVAL;
679+ }
680+ } else if (ret != -ENOIOCTLCMD) {
681+ return ret;
682+ }
683+
684+ if ((1 << (buswidth - 1)) & isi->width_flags)
685+ return 0;
686+ return -EINVAL;
694687 }
695688
696689
@@ -812,59 +805,71 @@ static int isi_camera_querycap(struct soc_camera_host *ici, · 115 unmodified lines
812805
813806 static int isi_camera_set_bus_param(struct soc_camera_device *icd, u32 pixfmt)
814807 {
808+ struct v4l2_subdev *sd = soc_camera_to_subdev(icd);
815809 struct soc_camera_host *ici = to_soc_camera_host(icd->parent);
816810 struct atmel_isi *isi = ici->priv;
817− unsigned long bus_flags, camera_flags, common_flags;
811+ struct v4l2_mbus_config cfg = {.type = V4L2_MBUS_PARALLEL,};
812+ unsigned long common_flags;
818813 int ret;
819814 u32 cfg1 = 0;
820815
821− camera_flags = icd->ops->query_bus_param(icd);
822−
823− bus_flags = make_bus_param(isi);
824− common_flags = soc_camera_bus_param_compatible(camera_flags, bus_flags);
825− dev_dbg(icd->parent, "Flags cam: 0x%lx host: 0x%lx common: 0x%lx\n",
826− camera_flags, bus_flags, common_flags);
827− if (!common_flags)
828− return -EINVAL;
816+ ret = v4l2_subdev_call(sd, video, g_mbus_config, &cfg);
817+ if (!ret) {
818+ common_flags = soc_mbus_config_compatible(&cfg,
819+ ISI_BUS_PARAM);
820+ if (!common_flags) {
821+ dev_warn(icd->parent,
822+ "Flags incompatible: camera 0x%x, host 0x%x\n",
823+ cfg.flags, ISI_BUS_PARAM);
824+ return -EINVAL;
825+ }
826+ } else if (ret != -ENOIOCTLCMD) {
827+ return ret;
828+ } else {
829+ common_flags = ISI_BUS_PARAM;
830+ }
831+ dev_dbg(icd->parent, "Flags cam: 0x%x host: 0x%x common: 0x%lx\n",
832+ cfg.flags, ISI_BUS_PARAM, common_flags);
829833
830834 /* Make choises, based on platform preferences */
831− if ((common_flags & SOCAM_HSYNC_ACTIVE_HIGH) &&
832− (common_flags & SOCAM_HSYNC_ACTIVE_LOW)) {
835+ if ((common_flags & V4L2_MBUS_HSYNC_ACTIVE_HIGH) &&
836+ (common_flags & V4L2_MBUS_HSYNC_ACTIVE_LOW)) {
833837 if (isi->pdata->hsync_act_low)
834− common_flags &= ~SOCAM_HSYNC_ACTIVE_HIGH;
838+ common_flags &= ~V4L2_MBUS_HSYNC_ACTIVE_HIGH;
835839 else
836− common_flags &= ~SOCAM_HSYNC_ACTIVE_LOW;
840+ common_flags &= ~V4L2_MBUS_HSYNC_ACTIVE_LOW;
837841 }
838842
839− if ((common_flags & SOCAM_VSYNC_ACTIVE_HIGH) &&
840− (common_flags & SOCAM_VSYNC_ACTIVE_LOW)) {
843+ if ((common_flags & V4L2_MBUS_VSYNC_ACTIVE_HIGH) &&
844+ (common_flags & V4L2_MBUS_VSYNC_ACTIVE_LOW)) {
841845 if (isi->pdata->vsync_act_low)
842− common_flags &= ~SOCAM_VSYNC_ACTIVE_HIGH;
846+ common_flags &= ~V4L2_MBUS_VSYNC_ACTIVE_HIGH;
843847 else
844− common_flags &= ~SOCAM_VSYNC_ACTIVE_LOW;
848+ common_flags &= ~V4L2_MBUS_VSYNC_ACTIVE_LOW;
845849 }
846850
847− if ((common_flags & SOCAM_PCLK_SAMPLE_RISING) &&
848− (common_flags & SOCAM_PCLK_SAMPLE_FALLING)) {
851+ if ((common_flags & V4L2_MBUS_PCLK_SAMPLE_RISING) &&
852+ (common_flags & V4L2_MBUS_PCLK_SAMPLE_FALLING)) {
849853 if (isi->pdata->pclk_act_falling)
850− common_flags &= ~SOCAM_PCLK_SAMPLE_RISING;
854+ common_flags &= ~V4L2_MBUS_PCLK_SAMPLE_RISING;
851855 else
852− common_flags &= ~SOCAM_PCLK_SAMPLE_FALLING;
856+ common_flags &= ~V4L2_MBUS_PCLK_SAMPLE_FALLING;
853857 }
854858
855− ret = icd->ops->set_bus_param(icd, common_flags);
856− if (ret < 0) {
857− dev_dbg(icd->parent, "Camera set_bus_param(%lx) returned %d\n",
859+ cfg.flags = common_flags;
860+ ret = v4l2_subdev_call(sd, video, s_mbus_config, &cfg);
861+ if (ret < 0 && ret != -ENOIOCTLCMD) {
862+ dev_dbg(icd->parent, "camera s_mbus_config(0x%lx) returned %d\n",
858863 common_flags, ret);
859864 return ret;
860865 }
861866
862867 /* set bus param for ISI */
863− if (common_flags & SOCAM_HSYNC_ACTIVE_LOW)
868+ if (common_flags & V4L2_MBUS_HSYNC_ACTIVE_LOW)
864869 cfg1 |= ISI_CFG1_HSYNC_POL_ACTIVE_LOW;
865− if (common_flags & SOCAM_VSYNC_ACTIVE_LOW)
870+ if (common_flags & V4L2_MBUS_VSYNC_ACTIVE_LOW)
866871 cfg1 |= ISI_CFG1_VSYNC_POL_ACTIVE_LOW;
867− if (common_flags & SOCAM_PCLK_SAMPLE_FALLING)
872+ if (common_flags & V4L2_MBUS_PCLK_SAMPLE_FALLING)
868873 cfg1 |= ISI_CFG1_PIXCLK_POL_ACTIVE_FALLING;
869874
870875 if (isi->pdata->has_emb_sync)
@@ -983,6 +988,11 @@ static int __devinit atmel_isi_probe(struct platform_device *pdev) · 112 unmodified lines
983988 goto err_ioremap;
984989 }
985990
991+ if (pdata->data_width_flags & ISI_DATAWIDTH_8)
992+ isi->width_flags = 1 << 7;
993+ if (pdata->data_width_flags & ISI_DATAWIDTH_10)
994+ isi->width_flags |= 1 << 9;
995+
986996 isi_writel(isi, ISI_CTRL, ISI_CTRL_DIS);
987997
988998 irq = platform_get_irq(pdev, 0);
drivers/media/video/cx18/cx18-driver.c+2−0
@@ -1085,6 +1085,8 @@ static int __devinit cx18_probe(struct pci_dev *pci_dev, · 1084 unmodified lines
10851085 setup.addr = ADDR_UNSET;
10861086 setup.type = cx->options.tuner;
10871087 setup.mode_mask = T_ANALOG_TV; /* matches TV tuners */
1088+ if (cx->options.radio > 0)
1089+ setup.mode_mask |= T_RADIO;
10881090 setup.tuner_callback = (setup.type == TUNER_XC2028) ?
10891091 cx18_reset_tuner_gpio : NULL;
10901092 cx18_call_all(cx, tuner, s_type_addr, &setup);
drivers/media/video/cx25821/Kconfigrenamed from drivers/staging/cx25821/Kconfig+0−0

File renamed without changes.

drivers/media/video/cx25821/Makefilerenamed from drivers/staging/cx25821/Makefile+0−0

File renamed without changes.

drivers/media/video/cx25821/cx25821-alsa.crenamed from drivers/staging/cx25821/cx25821-alsa.c+0−0

File renamed without changes.

drivers/media/video/cx25821/cx25821-audio-upstream.crenamed from drivers/staging/cx25821/cx25821-audio-upstream.c+0−0

File renamed without changes.

drivers/media/video/cx25821/cx25821-audio-upstream.hrenamed from drivers/staging/cx25821/cx25821-audio-upstream.h+0−0

File renamed without changes.

drivers/media/video/cx25821/cx25821-audio.hrenamed from drivers/staging/cx25821/cx25821-audio.h+0−0

File renamed without changes.

drivers/media/video/cx25821/cx25821-biffuncs.hrenamed from drivers/staging/cx25821/cx25821-biffuncs.h+0−0

File renamed without changes.

drivers/media/video/cx25821/cx25821-cards.crenamed from drivers/staging/cx25821/cx25821-cards.c+0−0

File renamed without changes.

drivers/media/video/cx25821/cx25821-core.crenamed from drivers/staging/cx25821/cx25821-core.c+0−0

File renamed without changes.

drivers/media/video/cx25821/cx25821-gpio.crenamed from drivers/staging/cx25821/cx25821-gpio.c+0−0

File renamed without changes.

drivers/media/video/cx25821/cx25821-i2c.crenamed from drivers/staging/cx25821/cx25821-i2c.c+0−0

File renamed without changes.

drivers/media/video/cx25821/cx25821-medusa-defines.hrenamed from drivers/staging/cx25821/cx25821-medusa-defines.h+0−0

File renamed without changes.

drivers/media/video/cx25821/cx25821-medusa-reg.hrenamed from drivers/staging/cx25821/cx25821-medusa-reg.h+0−0

File renamed without changes.

drivers/media/video/cx25821/cx25821-medusa-video.crenamed from drivers/staging/cx25821/cx25821-medusa-video.c+0−0

File renamed without changes.

drivers/media/video/cx25821/cx25821-medusa-video.hrenamed from drivers/staging/cx25821/cx25821-medusa-video.h+0−0

File renamed without changes.

drivers/media/video/cx25821/cx25821-reg.hrenamed from drivers/staging/cx25821/cx25821-reg.h+0−0

File renamed without changes.

drivers/media/video/cx25821/cx25821-sram.hrenamed from drivers/staging/cx25821/cx25821-sram.h+0−0

File renamed without changes.

drivers/media/video/cx25821/cx25821-video-upstream-ch2.crenamed from drivers/staging/cx25821/cx25821-video-upstream-ch2.c+0−0

File renamed without changes.

drivers/media/video/cx25821/cx25821-video-upstream-ch2.hrenamed from drivers/staging/cx25821/cx25821-video-upstream-ch2.h+0−0

File renamed without changes.

drivers/media/video/cx25821/cx25821-video-upstream.crenamed from drivers/staging/cx25821/cx25821-video-upstream.c+0−0

File renamed without changes.

drivers/media/video/cx25821/cx25821-video-upstream.hrenamed from drivers/staging/cx25821/cx25821-video-upstream.h+0−0

File renamed without changes.

drivers/media/video/cx25821/cx25821-video.crenamed from drivers/staging/cx25821/cx25821-video.c+1−1
@@ -1312,7 +1312,7 @@ int cx25821_vidioc_s_input(struct file *file, void *priv, unsigned int i) · 1311 unmodified lines
13121312 return err;
13131313 }
13141314
1315− if (i > 2) {
1315+ if (i >= CX25821_NR_INPUT) {
13161316 dprintk(1, "%s(): -EINVAL\n", __func__);
13171317 return -EINVAL;
13181318 }
drivers/media/video/cx25821/cx25821-video.hrenamed from drivers/staging/cx25821/cx25821-video.h+0−0

File renamed without changes.

drivers/media/video/cx25821/cx25821.hrenamed from drivers/staging/cx25821/cx25821.h+2−1
@@ -98,6 +98,7 @@ · 97 unmodified lines
9898 #define CX25821_BOARD_CONEXANT_ATHENA10 1
9999 #define MAX_VID_CHANNEL_NUM 12
100100 #define VID_CHANNEL_NUM 8
101+#define CX25821_NR_INPUT 2
101102
102103 struct cx25821_fmt {
103104 char *name;
@@ -196,7 +197,7 @@ struct cx25821_board { · 92 unmodified lines
196197 unsigned char radio_addr;
197198
198199 u32 clk_freq;
199− struct cx25821_input input[2];
200+ struct cx25821_input input[CX25821_NR_INPUT];
200201 };
201202
202203 struct cx25821_subid {
drivers/media/video/em28xx/em28xx-cards.c+2−0
@@ -1923,6 +1923,8 @@ struct usb_device_id em28xx_id_table[] = { · 1922 unmodified lines
19231923 .driver_info = EM2860_BOARD_TERRATEC_AV350 },
19241924 { USB_DEVICE(0x0ccd, 0x0096),
19251925 .driver_info = EM2860_BOARD_TERRATEC_GRABBY },
1926+ { USB_DEVICE(0x0ccd, 0x10AF),
1927+ .driver_info = EM2860_BOARD_TERRATEC_GRABBY },
19261928 { USB_DEVICE(0x0fd9, 0x0033),
19271929 .driver_info = EM2860_BOARD_ELGATO_VIDEO_CAPTURE},
19281930 { USB_DEVICE(0x185b, 0x2870),
drivers/media/video/imx074.c+17−37
@@ -12,11 +12,11 @@ · 11 unmodified lines
1212
1313 #include <linux/delay.h>
1414 #include <linux/i2c.h>
15+#include <linux/v4l2-mediabus.h>
1516 #include <linux/slab.h>
1617 #include <linux/videodev2.h>
1718
1819 #include <media/soc_camera.h>
19−#include <media/soc_mediabus.h>
2020 #include <media/v4l2-subdev.h>
2121 #include <media/v4l2-chip-ident.h>
2222
@@ -267,6 +267,17 @@ static int imx074_g_chip_ident(struct v4l2_subdev *sd, · 244 unmodified lines
267267 return 0;
268268 }
269269
270+static int imx074_g_mbus_config(struct v4l2_subdev *sd,
271+ struct v4l2_mbus_config *cfg)
272+{
273+ cfg->type = V4L2_MBUS_CSI2;
274+ cfg->flags = V4L2_MBUS_CSI2_2_LANE |
275+ V4L2_MBUS_CSI2_CHANNEL_0 |
276+ V4L2_MBUS_CSI2_CONTINUOUS_CLOCK;
277+
278+ return 0;
279+}
280+
270281 static struct v4l2_subdev_video_ops imx074_subdev_video_ops = {
271282 .s_stream = imx074_s_stream,
272283 .s_mbus_fmt = imx074_s_fmt,
@@ -275,6 +286,7 @@ static struct v4l2_subdev_video_ops imx074_subdev_video_ops = { · 2 unmodified lines
275286 .enum_mbus_fmt = imx074_enum_fmt,
276287 .g_crop = imx074_g_crop,
277288 .cropcap = imx074_cropcap,
289+ .g_mbus_config = imx074_g_mbus_config,
278290 };
279291
280292 static struct v4l2_subdev_core_ops imx074_subdev_core_ops = {
@@ -286,28 +298,7 @@ static struct v4l2_subdev_ops imx074_subdev_ops = { · 5 unmodified lines
286298 .video = &imx074_subdev_video_ops,
287299 };
288300
289−/*
290− * We have to provide soc-camera operations, but we don't have anything to say
291− * there. The MIPI CSI2 driver will provide .query_bus_param and .set_bus_param
292− */
293−static unsigned long imx074_query_bus_param(struct soc_camera_device *icd)
294−{
295− return 0;
296−}
297−
298−static int imx074_set_bus_param(struct soc_camera_device *icd,
299− unsigned long flags)
300−{
301− return -EINVAL;
302−}
303−
304−static struct soc_camera_ops imx074_ops = {
305− .query_bus_param = imx074_query_bus_param,
306− .set_bus_param = imx074_set_bus_param,
307−};
308−
309−static int imx074_video_probe(struct soc_camera_device *icd,
310− struct i2c_client *client)
301+static int imx074_video_probe(struct i2c_client *client)
311302 {
312303 int ret;
313304 u16 id;
@@ -417,17 +408,10 @@ static int imx074_probe(struct i2c_client *client, · 103 unmodified lines
417408 const struct i2c_device_id *did)
418409 {
419410 struct imx074 *priv;
420− struct soc_camera_device *icd = client->dev.platform_data;
421411 struct i2c_adapter *adapter = to_i2c_adapter(client->dev.parent);
422− struct soc_camera_link *icl;
412+ struct soc_camera_link *icl = soc_camera_i2c_to_link(client);
423413 int ret;
424414
425− if (!icd) {
426− dev_err(&client->dev, "IMX074: missing soc-camera data!\n");
427− return -EINVAL;
428− }
429−
430− icl = to_soc_camera_link(icd);
431415 if (!icl) {
432416 dev_err(&client->dev, "IMX074: missing platform data!\n");
433417 return -EINVAL;
@@ -445,12 +429,10 @@ static int imx074_probe(struct i2c_client *client, · 11 unmodified lines
445429
446430 v4l2_i2c_subdev_init(&priv->subdev, client, &imx074_subdev_ops);
447431
448− icd->ops = &imx074_ops;
449432 priv->fmt = &imx074_colour_fmts[0];
450433
451− ret = imx074_video_probe(icd, client);
434+ ret = imx074_video_probe(client);
452435 if (ret < 0) {
453− icd->ops = NULL;
454436 kfree(priv);
455437 return ret;
456438 }
@@ -461,10 +443,8 @@ static int imx074_probe(struct i2c_client *client, · 4 unmodified lines
461443 static int imx074_remove(struct i2c_client *client)
462444 {
463445 struct imx074 *priv = to_imx074(client);
464− struct soc_camera_device *icd = client->dev.platform_data;
465− struct soc_camera_link *icl = to_soc_camera_link(icd);
446+ struct soc_camera_link *icl = soc_camera_i2c_to_link(client);
466447
467− icd->ops = NULL;
468448 if (icl->free_bus)
469449 icl->free_bus(icl);
470450 kfree(priv);
drivers/media/video/ivtv/ivtv-driver.c+2−0
@@ -1180,6 +1180,8 @@ static int __devinit ivtv_probe(struct pci_dev *pdev, · 1179 unmodified lines
11801180 setup.addr = ADDR_UNSET;
11811181 setup.type = itv->options.tuner;
11821182 setup.mode_mask = T_ANALOG_TV; /* matches TV tuners */
1183+ if (itv->options.radio > 0)
1184+ setup.mode_mask |= T_RADIO;
11831185 setup.tuner_callback = (setup.type == TUNER_XC2028) ?
11841186 ivtv_reset_tuner_gpio : NULL;
11851187 ivtv_call_all(itv, tuner, s_type_addr, &setup);
drivers/media/video/marvell-ccic/mcam-core.c+2−1
@@ -883,7 +883,8 @@ static int mcam_read_setup(struct mcam_camera *cam) · 882 unmodified lines
883883 * Videobuf2 interface code.
884884 */
885885
886−static int mcam_vb_queue_setup(struct vb2_queue *vq, unsigned int *nbufs,
886+static int mcam_vb_queue_setup(struct vb2_queue *vq,
887+ const struct v4l2_format *fmt, unsigned int *nbufs,
887888 unsigned int *num_planes, unsigned int sizes[],
888889 void *alloc_ctxs[])
889890 {
drivers/media/video/mem2mem_testdev.c+4−3
@@ -738,9 +738,10 @@ static const struct v4l2_ioctl_ops m2mtest_ioctl_ops = { · 737 unmodified lines
738738 * Queue operations
739739 */
740740
741−static int m2mtest_queue_setup(struct vb2_queue *vq, unsigned int *nbuffers,
742− unsigned int *nplanes, unsigned int sizes[],
743− void *alloc_ctxs[])
741+static int m2mtest_queue_setup(struct vb2_queue *vq,
742+ const struct v4l2_format *fmt,
743+ unsigned int *nbuffers, unsigned int *nplanes,
744+ unsigned int sizes[], void *alloc_ctxs[])
744745 {
745746 struct m2mtest_ctx *ctx = vb2_get_drv_priv(vq);
746747 struct m2mtest_q_data *q_data;
drivers/media/video/mt9m001.c+122−206
@@ -13,9 +13,11 @@ · 12 unmodified lines
1313 #include <linux/i2c.h>
1414 #include <linux/log2.h>
1515
16+#include <media/soc_camera.h>
17+#include <media/soc_mediabus.h>
1618 #include <media/v4l2-subdev.h>
1719 #include <media/v4l2-chip-ident.h>
18−#include <media/soc_camera.h>
20+#include <media/v4l2-ctrls.h>
1921
2022 /*
2123 * mt9m001 i2c address 0x5d
@@ -84,15 +86,19 @@ static const struct mt9m001_datafmt mt9m001_monochrome_fmts[] = { · 62 unmodified lines
8486
8587 struct mt9m001 {
8688 struct v4l2_subdev subdev;
89+ struct v4l2_ctrl_handler hdl;
90+ struct {
91+ /* exposure/auto-exposure cluster */
92+ struct v4l2_ctrl *autoexposure;
93+ struct v4l2_ctrl *exposure;
94+ };
8795 struct v4l2_rect rect; /* Sensor window */
8896 const struct mt9m001_datafmt *fmt;
8997 const struct mt9m001_datafmt *fmts;
9098 int num_fmts;
9199 int model; /* V4L2_IDENT_MT9M001* codes from v4l2-chip-ident.h */
92− unsigned int gain;
93− unsigned int exposure;
100+ unsigned int total_h;
94101 unsigned short y_skip_top; /* Lines to skip at the top */
95− unsigned char autoexposure;
96102 };
97103
98104 static struct mt9m001 *to_mt9m001(const struct i2c_client *client)
@@ -165,54 +171,13 @@ static int mt9m001_s_stream(struct v4l2_subdev *sd, int enable) · 66 unmodified lines
165171 return 0;
166172 }
167173
168−static int mt9m001_set_bus_param(struct soc_camera_device *icd,
169− unsigned long flags)
170−{
171− struct soc_camera_link *icl = to_soc_camera_link(icd);
172− unsigned long width_flag = flags & SOCAM_DATAWIDTH_MASK;
173−
174− /* Only one width bit may be set */
175− if (!is_power_of_2(width_flag))
176− return -EINVAL;
177−
178− if (icl->set_bus_param)
179− return icl->set_bus_param(icl, width_flag);
180−
181− /*
182− * Without board specific bus width settings we only support the
183− * sensors native bus width
184− */
185− if (width_flag == SOCAM_DATAWIDTH_10)
186− return 0;
187−
188− return -EINVAL;
189−}
190−
191−static unsigned long mt9m001_query_bus_param(struct soc_camera_device *icd)
192−{
193− struct soc_camera_link *icl = to_soc_camera_link(icd);
194− /* MT9M001 has all capture_format parameters fixed */
195− unsigned long flags = SOCAM_PCLK_SAMPLE_FALLING |
196− SOCAM_HSYNC_ACTIVE_HIGH | SOCAM_VSYNC_ACTIVE_HIGH |
197− SOCAM_DATA_ACTIVE_HIGH | SOCAM_MASTER;
198−
199− if (icl->query_bus_param)
200− flags |= icl->query_bus_param(icl) & SOCAM_DATAWIDTH_MASK;
201− else
202− flags |= SOCAM_DATAWIDTH_10;
203−
204− return soc_camera_apply_sensor_flags(icl, flags);
205−}
206−
207174 static int mt9m001_s_crop(struct v4l2_subdev *sd, struct v4l2_crop *a)
208175 {
209176 struct i2c_client *client = v4l2_get_subdevdata(sd);
210177 struct mt9m001 *mt9m001 = to_mt9m001(client);
211178 struct v4l2_rect rect = a->c;
212− struct soc_camera_device *icd = client->dev.platform_data;
213179 int ret;
214180 const u16 hblank = 9, vblank = 25;
215− unsigned int total_h;
216181
217182 if (mt9m001->fmts == mt9m001_colour_fmts)
218183 /*
@@ -231,7 +196,7 @@ static int mt9m001_s_crop(struct v4l2_subdev *sd, struct v4l2_crop *a) · 12 unmodified lines
231196 soc_camera_limit_side(&rect.top, &rect.height,
232197 MT9M001_ROW_SKIP, MT9M001_MIN_HEIGHT, MT9M001_MAX_HEIGHT);
233198
234− total_h = rect.height + mt9m001->y_skip_top + vblank;
199+ mt9m001->total_h = rect.height + mt9m001->y_skip_top + vblank;
235200
236201 /* Blanking and start values - default... */
237202 ret = reg_write(client, MT9M001_HORIZONTAL_BLANKING, hblank);
@@ -240,7 +205,7 @@ static int mt9m001_s_crop(struct v4l2_subdev *sd, struct v4l2_crop *a) · 2 unmodified lines
240205
241206 /*
242207 * The caller provides a supported format, as verified per
243− * call to icd->try_fmt()
208+ * call to .try_mbus_fmt()
244209 */
245210 if (!ret)
246211 ret = reg_write(client, MT9M001_COLUMN_START, rect.left);
@@ -251,17 +216,8 @@ static int mt9m001_s_crop(struct v4l2_subdev *sd, struct v4l2_crop *a) · 4 unmodified lines
251216 if (!ret)
252217 ret = reg_write(client, MT9M001_WINDOW_HEIGHT,
253218 rect.height + mt9m001->y_skip_top - 1);
254− if (!ret && mt9m001->autoexposure) {
255− ret = reg_write(client, MT9M001_SHUTTER_WIDTH, total_h);
256− if (!ret) {
257− const struct v4l2_queryctrl *qctrl =
258− soc_camera_find_qctrl(icd->ops,
259− V4L2_CID_EXPOSURE);
260− mt9m001->exposure = (524 + (total_h - 1) *
261− (qctrl->maximum - qctrl->minimum)) /
262− 1048 + qctrl->minimum;
263− }
264− }
219+ if (!ret && v4l2_ctrl_g_ctrl(mt9m001->autoexposure) == V4L2_EXPOSURE_AUTO)
220+ ret = reg_write(client, MT9M001_SHUTTER_WIDTH, mt9m001->total_h);
265221
266222 if (!ret)
267223 mt9m001->rect = rect;
@@ -421,107 +377,48 @@ static int mt9m001_s_register(struct v4l2_subdev *sd, · 153 unmodified lines
421377 }
422378 #endif
423379
424−static const struct v4l2_queryctrl mt9m001_controls[] = {
425− {
426− .id = V4L2_CID_VFLIP,
427− .type = V4L2_CTRL_TYPE_BOOLEAN,
428− .name = "Flip Vertically",
429− .minimum = 0,
430− .maximum = 1,
431− .step = 1,
432− .default_value = 0,
433− }, {
434− .id = V4L2_CID_GAIN,
435− .type = V4L2_CTRL_TYPE_INTEGER,
436− .name = "Gain",
437− .minimum = 0,
438− .maximum = 127,
439− .step = 1,
440− .default_value = 64,
441− .flags = V4L2_CTRL_FLAG_SLIDER,
442− }, {
443− .id = V4L2_CID_EXPOSURE,
444− .type = V4L2_CTRL_TYPE_INTEGER,
445− .name = "Exposure",
446− .minimum = 1,
447− .maximum = 255,
448− .step = 1,
449− .default_value = 255,
450− .flags = V4L2_CTRL_FLAG_SLIDER,
451− }, {
452− .id = V4L2_CID_EXPOSURE_AUTO,
453− .type = V4L2_CTRL_TYPE_BOOLEAN,
454− .name = "Automatic Exposure",
455− .minimum = 0,
456− .maximum = 1,
457− .step = 1,
458− .default_value = 1,
459− }
460−};
461−
462−static struct soc_camera_ops mt9m001_ops = {
463− .set_bus_param = mt9m001_set_bus_param,
464− .query_bus_param = mt9m001_query_bus_param,
465− .controls = mt9m001_controls,
466− .num_controls = ARRAY_SIZE(mt9m001_controls),
467−};
468−
469−static int mt9m001_g_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
380+static int mt9m001_g_volatile_ctrl(struct v4l2_ctrl *ctrl)
470381 {
471− struct i2c_client *client = v4l2_get_subdevdata(sd);
472− struct mt9m001 *mt9m001 = to_mt9m001(client);
473− int data;
382+ struct mt9m001 *mt9m001 = container_of(ctrl->handler,
383+ struct mt9m001, hdl);
384+ s32 min, max;
474385
475386 switch (ctrl->id) {
476− case V4L2_CID_VFLIP:
477− data = reg_read(client, MT9M001_READ_OPTIONS2);
478− if (data < 0)
479− return -EIO;
480− ctrl->value = !!(data & 0x8000);
481− break;
482387 case V4L2_CID_EXPOSURE_AUTO:
483− ctrl->value = mt9m001->autoexposure;
484− break;
485− case V4L2_CID_GAIN:
486− ctrl->value = mt9m001->gain;
487− break;
488− case V4L2_CID_EXPOSURE:
489− ctrl->value = mt9m001->exposure;
388+ min = mt9m001->exposure->minimum;
389+ max = mt9m001->exposure->maximum;
390+ mt9m001->exposure->val =
391+ (524 + (mt9m001->total_h - 1) * (max - min)) / 1048 + min;
490392 break;
491393 }
492394 return 0;
493395 }
494396
495−static int mt9m001_s_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
397+static int mt9m001_s_ctrl(struct v4l2_ctrl *ctrl)
496398 {
399+ struct mt9m001 *mt9m001 = container_of(ctrl->handler,
400+ struct mt9m001, hdl);
401+ struct v4l2_subdev *sd = &mt9m001->subdev;
497402 struct i2c_client *client = v4l2_get_subdevdata(sd);
498− struct mt9m001 *mt9m001 = to_mt9m001(client);
499− struct soc_camera_device *icd = client->dev.platform_data;
500− const struct v4l2_queryctrl *qctrl;
403+ struct v4l2_ctrl *exp = mt9m001->exposure;
501404 int data;
502405
503− qctrl = soc_camera_find_qctrl(&mt9m001_ops, ctrl->id);
504−
505− if (!qctrl)
506− return -EINVAL;
507−
508406 switch (ctrl->id) {
509407 case V4L2_CID_VFLIP:
510− if (ctrl->value)
408+ if (ctrl->val)
511409 data = reg_set(client, MT9M001_READ_OPTIONS2, 0x8000);
512410 else
513411 data = reg_clear(client, MT9M001_READ_OPTIONS2, 0x8000);
514412 if (data < 0)
515413 return -EIO;
516− break;
414+ return 0;
415+
517416 case V4L2_CID_GAIN:
518− if (ctrl->value > qctrl->maximum || ctrl->value < qctrl->minimum)
519− return -EINVAL;
520417 /* See Datasheet Table 7, Gain settings. */
521− if (ctrl->value <= qctrl->default_value) {
418+ if (ctrl->val <= ctrl->default_value) {
522419 /* Pack it into 0..1 step 0.125, register values 0..8 */
523− unsigned long range = qctrl->default_value - qctrl->minimum;
524− data = ((ctrl->value - qctrl->minimum) * 8 + range / 2) / range;
420+ unsigned long range = ctrl->default_value - ctrl->minimum;
421+ data = ((ctrl->val - ctrl->minimum) * 8 + range / 2) / range;
525422
526423 dev_dbg(&client->dev, "Setting gain %d\n", data);
527424 data = reg_write(client, MT9M001_GLOBAL_GAIN, data);
@@ -530,8 +427,8 @@ static int mt9m001_s_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl) · 2 unmodified lines
530427 } else {
531428 /* Pack it into 1.125..15 variable step, register values 9..67 */
532429 /* We assume qctrl->maximum - qctrl->default_value - 1 > 0 */
533− unsigned long range = qctrl->maximum - qctrl->default_value - 1;
534− unsigned long gain = ((ctrl->value - qctrl->default_value - 1) *
430+ unsigned long range = ctrl->maximum - ctrl->default_value - 1;
431+ unsigned long gain = ((ctrl->val - ctrl->default_value - 1) *
535432 111 + range / 2) / range + 9;
536433
537434 if (gain <= 32)
@@ -547,66 +444,44 @@ static int mt9m001_s_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl) · 9 unmodified lines
547444 if (data < 0)
548445 return -EIO;
549446 }
447+ return 0;
550448
551− /* Success */
552− mt9m001->gain = ctrl->value;
553− break;
554− case V4L2_CID_EXPOSURE:
555− /* mt9m001 has maximum == default */
556− if (ctrl->value > qctrl->maximum || ctrl->value < qctrl->minimum)
557− return -EINVAL;
558− else {
559− unsigned long range = qctrl->maximum - qctrl->minimum;
560− unsigned long shutter = ((ctrl->value - qctrl->minimum) * 1048 +
449+ case V4L2_CID_EXPOSURE_AUTO:
450+ if (ctrl->val == V4L2_EXPOSURE_MANUAL) {
451+ unsigned long range = exp->maximum - exp->minimum;
452+ unsigned long shutter = ((exp->val - exp->minimum) * 1048 +
561453 range / 2) / range + 1;
562454
563455 dev_dbg(&client->dev,
564456 "Setting shutter width from %d to %lu\n",
565− reg_read(client, MT9M001_SHUTTER_WIDTH),
566− shutter);
457+ reg_read(client, MT9M001_SHUTTER_WIDTH), shutter);
567458 if (reg_write(client, MT9M001_SHUTTER_WIDTH, shutter) < 0)
568459 return -EIO;
569− mt9m001->exposure = ctrl->value;
570− mt9m001->autoexposure = 0;
571− }
572− break;
573− case V4L2_CID_EXPOSURE_AUTO:
574− if (ctrl->value) {
460+ } else {
575461 const u16 vblank = 25;
576− unsigned int total_h = mt9m001->rect.height +
462+
463+ mt9m001->total_h = mt9m001->rect.height +
577464 mt9m001->y_skip_top + vblank;
578− if (reg_write(client, MT9M001_SHUTTER_WIDTH,
579− total_h) < 0)
465+ if (reg_write(client, MT9M001_SHUTTER_WIDTH, mt9m001->total_h) < 0)
580466 return -EIO;
581− qctrl = soc_camera_find_qctrl(icd->ops, V4L2_CID_EXPOSURE);
582− mt9m001->exposure = (524 + (total_h - 1) *
583− (qctrl->maximum - qctrl->minimum)) /
584− 1048 + qctrl->minimum;
585− mt9m001->autoexposure = 1;
586− } else
587− mt9m001->autoexposure = 0;
588− break;
467+ }
468+ return 0;
589469 }
590− return 0;
470+ return -EINVAL;
591471 }
592472
593473 /*
594474 * Interface active, can use i2c. If it fails, it can indeed mean, that
595475 * this wasn't our capture interface, so, we wait for the right one
596476 */
597−static int mt9m001_video_probe(struct soc_camera_device *icd,
477+static int mt9m001_video_probe(struct soc_camera_link *icl,
598478 struct i2c_client *client)
599479 {
600480 struct mt9m001 *mt9m001 = to_mt9m001(client);
601− struct soc_camera_link *icl = to_soc_camera_link(icd);
602481 s32 data;
603482 unsigned long flags;
604483 int ret;
605484
606− /* We must have a parent by now. And it cannot be a wrong one. */
607− BUG_ON(!icd->parent ||
608− to_soc_camera_host(icd->parent)->nr != icd->iface);
609−
610485 /* Enable the chip */
611486 data = reg_write(client, MT9M001_CHIP_ENABLE, 1);
612487 dev_dbg(&client->dev, "write: %d\n", data);
@@ -661,18 +536,11 @@ static int mt9m001_video_probe(struct soc_camera_device *icd, · 48 unmodified lines
661536 dev_err(&client->dev, "Failed to initialise the camera\n");
662537
663538 /* mt9m001_init() has reset the chip, returning registers to defaults */
664− mt9m001->gain = 64;
665− mt9m001->exposure = 255;
666−
667− return ret;
539+ return v4l2_ctrl_handler_setup(&mt9m001->hdl);
668540 }
669541
670−static void mt9m001_video_remove(struct soc_camera_device *icd)
542+static void mt9m001_video_remove(struct soc_camera_link *icl)
671543 {
672− struct soc_camera_link *icl = to_soc_camera_link(icd);
673−
674− dev_dbg(icd->pdev, "Video removed: %p, %p\n",
675− icd->parent, icd->vdev);
676544 if (icl->free_bus)
677545 icl->free_bus(icl);
678546 }
@@ -687,9 +555,12 @@ static int mt9m001_g_skip_top_lines(struct v4l2_subdev *sd, u32 *lines) · 8 unmodified lines
687555 return 0;
688556 }
689557
558+static const struct v4l2_ctrl_ops mt9m001_ctrl_ops = {
559+ .g_volatile_ctrl = mt9m001_g_volatile_ctrl,
560+ .s_ctrl = mt9m001_s_ctrl,
561+};
562+
690563 static struct v4l2_subdev_core_ops mt9m001_subdev_core_ops = {
691− .g_ctrl = mt9m001_g_ctrl,
692− .s_ctrl = mt9m001_s_ctrl,
693564 .g_chip_ident = mt9m001_g_chip_ident,
694565 #ifdef CONFIG_VIDEO_ADV_DEBUG
695566 .g_register = mt9m001_g_register,
@@ -710,6 +581,40 @@ static int mt9m001_enum_fmt(struct v4l2_subdev *sd, unsigned int index, · 14 unmodified lines
710581 return 0;
711582 }
712583
584+static int mt9m001_g_mbus_config(struct v4l2_subdev *sd,
585+ struct v4l2_mbus_config *cfg)
586+{
587+ struct i2c_client *client = v4l2_get_subdevdata(sd);
588+ struct soc_camera_link *icl = soc_camera_i2c_to_link(client);
589+
590+ /* MT9M001 has all capture_format parameters fixed */
591+ cfg->flags = V4L2_MBUS_PCLK_SAMPLE_FALLING |
592+ V4L2_MBUS_HSYNC_ACTIVE_HIGH | V4L2_MBUS_VSYNC_ACTIVE_HIGH |
593+ V4L2_MBUS_DATA_ACTIVE_HIGH | V4L2_MBUS_MASTER;
594+ cfg->type = V4L2_MBUS_PARALLEL;
595+ cfg->flags = soc_camera_apply_board_flags(icl, cfg);
596+
597+ return 0;
598+}
599+
600+static int mt9m001_s_mbus_config(struct v4l2_subdev *sd,
601+ const struct v4l2_mbus_config *cfg)
602+{
603+ const struct i2c_client *client = v4l2_get_subdevdata(sd);
604+ struct soc_camera_link *icl = soc_camera_i2c_to_link(client);
605+ struct mt9m001 *mt9m001 = to_mt9m001(client);
606+ unsigned int bps = soc_mbus_get_fmtdesc(mt9m001->fmt->code)->bits_per_sample;
607+
608+ if (icl->set_bus_param)
609+ return icl->set_bus_param(icl, 1 << (bps - 1));
610+
611+ /*
612+ * Without board specific bus width settings we only support the
613+ * sensors native bus width
614+ */
615+ return bps == 10 ? 0 : -EINVAL;
616+}
617+
713618 static struct v4l2_subdev_video_ops mt9m001_subdev_video_ops = {
714619 .s_stream = mt9m001_s_stream,
715620 .s_mbus_fmt = mt9m001_s_fmt,
@@ -719,6 +624,8 @@ static struct v4l2_subdev_video_ops mt9m001_subdev_video_ops = { · 3 unmodified lines
719624 .g_crop = mt9m001_g_crop,
720625 .cropcap = mt9m001_cropcap,
721626 .enum_mbus_fmt = mt9m001_enum_fmt,
627+ .g_mbus_config = mt9m001_g_mbus_config,
628+ .s_mbus_config = mt9m001_s_mbus_config,
722629 };
723630
724631 static struct v4l2_subdev_sensor_ops mt9m001_subdev_sensor_ops = {
@@ -735,17 +642,10 @@ static int mt9m001_probe(struct i2c_client *client, · 10 unmodified lines
735642 const struct i2c_device_id *did)
736643 {
737644 struct mt9m001 *mt9m001;
738− struct soc_camera_device *icd = client->dev.platform_data;
739645 struct i2c_adapter *adapter = to_i2c_adapter(client->dev.parent);
740− struct soc_camera_link *icl;
646+ struct soc_camera_link *icl = soc_camera_i2c_to_link(client);
741647 int ret;
742648
743− if (!icd) {
744− dev_err(&client->dev, "MT9M001: missing soc-camera data!\n");
745− return -EINVAL;
746− }
747−
748− icl = to_soc_camera_link(icd);
749649 if (!icl) {
750650 dev_err(&client->dev, "MT9M001 driver needs platform data\n");
751651 return -EINVAL;
@@ -762,25 +662,40 @@ static int mt9m001_probe(struct i2c_client *client, · 10 unmodified lines
762662 return -ENOMEM;
763663
764664 v4l2_i2c_subdev_init(&mt9m001->subdev, client, &mt9m001_subdev_ops);
665+ v4l2_ctrl_handler_init(&mt9m001->hdl, 4);
666+ v4l2_ctrl_new_std(&mt9m001->hdl, &mt9m001_ctrl_ops,
667+ V4L2_CID_VFLIP, 0, 1, 1, 0);
668+ v4l2_ctrl_new_std(&mt9m001->hdl, &mt9m001_ctrl_ops,
669+ V4L2_CID_GAIN, 0, 127, 1, 64);
670+ mt9m001->exposure = v4l2_ctrl_new_std(&mt9m001->hdl, &mt9m001_ctrl_ops,
671+ V4L2_CID_EXPOSURE, 1, 255, 1, 255);
672+ /*
673+ * Simulated autoexposure. If enabled, we calculate shutter width
674+ * ourselves in the driver based on vertical blanking and frame width
675+ */
676+ mt9m001->autoexposure = v4l2_ctrl_new_std_menu(&mt9m001->hdl,
677+ &mt9m001_ctrl_ops, V4L2_CID_EXPOSURE_AUTO, 1, 0,
678+ V4L2_EXPOSURE_AUTO);
679+ mt9m001->subdev.ctrl_handler = &mt9m001->hdl;
680+ if (mt9m001->hdl.error) {
681+ int err = mt9m001->hdl.error;
765682
766− /* Second stage probe - when a capture adapter is there */
767− icd->ops = &mt9m001_ops;
683+ kfree(mt9m001);
684+ return err;
685+ }
686+ v4l2_ctrl_auto_cluster(2, &mt9m001->autoexposure,
687+ V4L2_EXPOSURE_MANUAL, true);
768688
689+ /* Second stage probe - when a capture adapter is there */
769690 mt9m001->y_skip_top = 0;
770691 mt9m001->rect.left = MT9M001_COLUMN_SKIP;
771692 mt9m001->rect.top = MT9M001_ROW_SKIP;
772693 mt9m001->rect.width = MT9M001_MAX_WIDTH;
773694 mt9m001->rect.height = MT9M001_MAX_HEIGHT;
774695
775− /*
776− * Simulated autoexposure. If enabled, we calculate shutter width
777− * ourselves in the driver based on vertical blanking and frame width
778− */
779− mt9m001->autoexposure = 1;
780−
781− ret = mt9m001_video_probe(icd, client);
696+ ret = mt9m001_video_probe(icl, client);
782697 if (ret) {
783− icd->ops = NULL;
698+ v4l2_ctrl_handler_free(&mt9m001->hdl);
784699 kfree(mt9m001);
785700 }
786701
@@ -790,10 +705,11 @@ static int mt9m001_probe(struct i2c_client *client, · 3 unmodified lines
790705 static int mt9m001_remove(struct i2c_client *client)
791706 {
792707 struct mt9m001 *mt9m001 = to_mt9m001(client);
793− struct soc_camera_device *icd = client->dev.platform_data;
708+ struct soc_camera_link *icl = soc_camera_i2c_to_link(client);
794709
795− icd->ops = NULL;
796− mt9m001_video_remove(icd);
710+ v4l2_device_unregister_subdev(&mt9m001->subdev);
711+ v4l2_ctrl_handler_free(&mt9m001->hdl);
712+ mt9m001_video_remove(icl);
797713 kfree(mt9m001);
798714
799715 return 0;
drivers/media/video/mt9m111.c+70−190
@@ -13,10 +13,12 @@ · 12 unmodified lines
1313 #include <linux/log2.h>
1414 #include <linux/gpio.h>
1515 #include <linux/delay.h>
16+#include <linux/v4l2-mediabus.h>
1617
18+#include <media/soc_camera.h>
1719 #include <media/v4l2-common.h>
20+#include <media/v4l2-ctrls.h>
1821 #include <media/v4l2-chip-ident.h>
19−#include <media/soc_camera.h>
2022
2123 /*
2224 * MT9M111, MT9M112 and MT9M131:
@@ -177,6 +179,8 @@ enum mt9m111_context { · 154 unmodified lines
177179
178180 struct mt9m111 {
179181 struct v4l2_subdev subdev;
182+ struct v4l2_ctrl_handler hdl;
183+ struct v4l2_ctrl *gain;
180184 int model; /* V4L2_IDENT_MT9M111 or V4L2_IDENT_MT9M112 code
181185 * from v4l2-chip-ident.h */
182186 enum mt9m111_context context;
@@ -185,13 +189,8 @@ struct mt9m111 { · 2 unmodified lines
185189 int power_count;
186190 const struct mt9m111_datafmt *fmt;
187191 int lastpage; /* PageMap cache value */
188− unsigned int gain;
189− unsigned char autoexposure;
190192 unsigned char datawidth;
191193 unsigned int powered:1;
192− unsigned int hflip:1;
193− unsigned int vflip:1;
194− unsigned int autowhitebalance:1;
195194 };
196195
197196 static struct mt9m111 *to_mt9m111(const struct i2c_client *client)
@@ -363,21 +362,6 @@ static int mt9m111_reset(struct mt9m111 *mt9m111) · 165 unmodified lines
363362 return ret;
364363 }
365364
366−static unsigned long mt9m111_query_bus_param(struct soc_camera_device *icd)
367−{
368− struct soc_camera_link *icl = to_soc_camera_link(icd);
369− unsigned long flags = SOCAM_MASTER | SOCAM_PCLK_SAMPLE_RISING |
370− SOCAM_HSYNC_ACTIVE_HIGH | SOCAM_VSYNC_ACTIVE_HIGH |
371− SOCAM_DATA_ACTIVE_HIGH | SOCAM_DATAWIDTH_8;
372−
373− return soc_camera_apply_sensor_flags(icl, flags);
374−}
375−
376−static int mt9m111_set_bus_param(struct soc_camera_device *icd, unsigned long f)
377−{
378− return 0;
379−}
380−
381365 static int mt9m111_make_rect(struct mt9m111 *mt9m111,
382366 struct v4l2_rect *rect)
383367 {
@@ -660,50 +644,6 @@ static int mt9m111_s_register(struct v4l2_subdev *sd, · 276 unmodified lines
660644 }
661645 #endif
662646
663−static const struct v4l2_queryctrl mt9m111_controls[] = {
664− {
665− .id = V4L2_CID_VFLIP,
666− .type = V4L2_CTRL_TYPE_BOOLEAN,
667− .name = "Flip Verticaly",
668− .minimum = 0,
669− .maximum = 1,
670− .step = 1,
671− .default_value = 0,
672− }, {
673− .id = V4L2_CID_HFLIP,
674− .type = V4L2_CTRL_TYPE_BOOLEAN,
675− .name = "Flip Horizontaly",
676− .minimum = 0,
677− .maximum = 1,
678− .step = 1,
679− .default_value = 0,
680− }, { /* gain = 1/32*val (=>gain=1 if val==32) */
681− .id = V4L2_CID_GAIN,
682− .type = V4L2_CTRL_TYPE_INTEGER,
683− .name = "Gain",
684− .minimum = 0,
685− .maximum = 63 * 2 * 2,
686− .step = 1,
687− .default_value = 32,
688− .flags = V4L2_CTRL_FLAG_SLIDER,
689− }, {
690− .id = V4L2_CID_EXPOSURE_AUTO,
691− .type = V4L2_CTRL_TYPE_BOOLEAN,
692− .name = "Auto Exposure",
693− .minimum = 0,
694− .maximum = 1,
695− .step = 1,
696− .default_value = 1,
697− }
698−};
699−
700−static struct soc_camera_ops mt9m111_ops = {
701− .query_bus_param = mt9m111_query_bus_param,
702− .set_bus_param = mt9m111_set_bus_param,
703− .controls = mt9m111_controls,
704− .num_controls = ARRAY_SIZE(mt9m111_controls),
705−};
706−
707647 static int mt9m111_set_flip(struct mt9m111 *mt9m111, int flip, int mask)
708648 {
709649 struct i2c_client *client = v4l2_get_subdevdata(&mt9m111->subdev);
@@ -744,7 +684,6 @@ static int mt9m111_set_global_gain(struct mt9m111 *mt9m111, int gain) · 34 unmodified lines
744684 if (gain > 63 * 2 * 2)
745685 return -EINVAL;
746686
747− mt9m111->gain = gain;
748687 if ((gain >= 64 * 2) && (gain < 63 * 2 * 2))
749688 val = (1 << 10) | (1 << 9) | (gain / 4);
750689 else if ((gain >= 64) && (gain < 64 * 2))
@@ -758,118 +697,47 @@ static int mt9m111_set_global_gain(struct mt9m111 *mt9m111, int gain) · 7 unmodified lines
758697 static int mt9m111_set_autoexposure(struct mt9m111 *mt9m111, int on)
759698 {
760699 struct i2c_client *client = v4l2_get_subdevdata(&mt9m111->subdev);
761− int ret;
762700
763701 if (on)
764− ret = reg_set(OPER_MODE_CTRL, MT9M111_OPMODE_AUTOEXPO_EN);
765− else
766− ret = reg_clear(OPER_MODE_CTRL, MT9M111_OPMODE_AUTOEXPO_EN);
767−
768− if (!ret)
769− mt9m111->autoexposure = on;
770−
771− return ret;
702+ return reg_set(OPER_MODE_CTRL, MT9M111_OPMODE_AUTOEXPO_EN);
703+ return reg_clear(OPER_MODE_CTRL, MT9M111_OPMODE_AUTOEXPO_EN);
772704 }
773705
774706 static int mt9m111_set_autowhitebalance(struct mt9m111 *mt9m111, int on)
775707 {
776708 struct i2c_client *client = v4l2_get_subdevdata(&mt9m111->subdev);
777− int ret;
778709
779710 if (on)
780− ret = reg_set(OPER_MODE_CTRL, MT9M111_OPMODE_AUTOWHITEBAL_EN);
781− else
782− ret = reg_clear(OPER_MODE_CTRL, MT9M111_OPMODE_AUTOWHITEBAL_EN);
783−
784− if (!ret)
785− mt9m111->autowhitebalance = on;
786−
787− return ret;
788−}
789−
790−static int mt9m111_g_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
791−{
792− struct i2c_client *client = v4l2_get_subdevdata(sd);
793− struct mt9m111 *mt9m111 = container_of(sd, struct mt9m111, subdev);
794− int data;
795−
796− switch (ctrl->id) {
797− case V4L2_CID_VFLIP:
798− if (mt9m111->context == HIGHPOWER)
799− data = reg_read(READ_MODE_B);
800− else
801− data = reg_read(READ_MODE_A);
802−
803− if (data < 0)
804− return -EIO;
805− ctrl->value = !!(data & MT9M111_RMB_MIRROR_ROWS);
806− break;
807− case V4L2_CID_HFLIP:
808− if (mt9m111->context == HIGHPOWER)
809− data = reg_read(READ_MODE_B);
810− else
811− data = reg_read(READ_MODE_A);
812−
813− if (data < 0)
814− return -EIO;
815− ctrl->value = !!(data & MT9M111_RMB_MIRROR_COLS);
816− break;
817− case V4L2_CID_GAIN:
818− data = mt9m111_get_global_gain(mt9m111);
819− if (data < 0)
820− return data;
821− ctrl->value = data;
822− break;
823− case V4L2_CID_EXPOSURE_AUTO:
824− ctrl->value = mt9m111->autoexposure;
825− break;
826− case V4L2_CID_AUTO_WHITE_BALANCE:
827− ctrl->value = mt9m111->autowhitebalance;
828− break;
829− }
830− return 0;
711+ return reg_set(OPER_MODE_CTRL, MT9M111_OPMODE_AUTOWHITEBAL_EN);
712+ return reg_clear(OPER_MODE_CTRL, MT9M111_OPMODE_AUTOWHITEBAL_EN);
831713 }
832714
833−static int mt9m111_s_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
715+static int mt9m111_s_ctrl(struct v4l2_ctrl *ctrl)
834716 {
835− struct mt9m111 *mt9m111 = container_of(sd, struct mt9m111, subdev);
836− const struct v4l2_queryctrl *qctrl;
837− int ret;
838−
839− qctrl = soc_camera_find_qctrl(&mt9m111_ops, ctrl->id);
840− if (!qctrl)
841− return -EINVAL;
717+ struct mt9m111 *mt9m111 = container_of(ctrl->handler,
718+ struct mt9m111, hdl);
842719
843720 switch (ctrl->id) {
844721 case V4L2_CID_VFLIP:
845− mt9m111->vflip = ctrl->value;
846− ret = mt9m111_set_flip(mt9m111, ctrl->value,
722+ return mt9m111_set_flip(mt9m111, ctrl->val,
847723 MT9M111_RMB_MIRROR_ROWS);
848− break;
849724 case V4L2_CID_HFLIP:
850− mt9m111->hflip = ctrl->value;
851− ret = mt9m111_set_flip(mt9m111, ctrl->value,
725+ return mt9m111_set_flip(mt9m111, ctrl->val,
852726 MT9M111_RMB_MIRROR_COLS);
853− break;
854727 case V4L2_CID_GAIN:
855− ret = mt9m111_set_global_gain(mt9m111, ctrl->value);
856− break;
728+ return mt9m111_set_global_gain(mt9m111, ctrl->val);
857729 case V4L2_CID_EXPOSURE_AUTO:
858− ret = mt9m111_set_autoexposure(mt9m111, ctrl->value);
859− break;
730+ return mt9m111_set_autoexposure(mt9m111, ctrl->val);
860731 case V4L2_CID_AUTO_WHITE_BALANCE:
861− ret = mt9m111_set_autowhitebalance(mt9m111, ctrl->value);
862− break;
863− default:
864− ret = -EINVAL;
732+ return mt9m111_set_autowhitebalance(mt9m111, ctrl->val);
865733 }
866734
867− return ret;
735+ return -EINVAL;
868736 }
869737
870738 static int mt9m111_suspend(struct mt9m111 *mt9m111)
871739 {
872− mt9m111->gain = mt9m111_get_global_gain(mt9m111);
740+ v4l2_ctrl_s_ctrl(mt9m111->gain, mt9m111_get_global_gain(mt9m111));
873741
874742 return 0;
875743 }
@@ -879,11 +747,7 @@ static void mt9m111_restore_state(struct mt9m111 *mt9m111) · 3 unmodified lines
879747 mt9m111_set_context(mt9m111, mt9m111->context);
880748 mt9m111_set_pixfmt(mt9m111, mt9m111->fmt->code);
881749 mt9m111_setup_rect(mt9m111, &mt9m111->rect);
882− mt9m111_set_flip(mt9m111, mt9m111->hflip, MT9M111_RMB_MIRROR_COLS);
883− mt9m111_set_flip(mt9m111, mt9m111->vflip, MT9M111_RMB_MIRROR_ROWS);
884− mt9m111_set_global_gain(mt9m111, mt9m111->gain);
885− mt9m111_set_autoexposure(mt9m111, mt9m111->autoexposure);
886− mt9m111_set_autowhitebalance(mt9m111, mt9m111->autowhitebalance);
750+ v4l2_ctrl_handler_setup(&mt9m111->hdl);
887751 }
888752
889753 static int mt9m111_resume(struct mt9m111 *mt9m111)
@@ -911,8 +775,6 @@ static int mt9m111_init(struct mt9m111 *mt9m111) · 21 unmodified lines
911775 ret = mt9m111_reset(mt9m111);
912776 if (!ret)
913777 ret = mt9m111_set_context(mt9m111, mt9m111->context);
914− if (!ret)
915− ret = mt9m111_set_autoexposure(mt9m111, mt9m111->autoexposure);
916778 if (ret)
917779 dev_err(&client->dev, "mt9m111 init failed: %d\n", ret);
918780 return ret;
@@ -922,22 +784,12 @@ static int mt9m111_init(struct mt9m111 *mt9m111) · 3 unmodified lines
922784 * Interface active, can use i2c. If it fails, it can indeed mean, that
923785 * this wasn't our capture interface, so, we wait for the right one
924786 */
925−static int mt9m111_video_probe(struct soc_camera_device *icd,
926− struct i2c_client *client)
787+static int mt9m111_video_probe(struct i2c_client *client)
927788 {
928789 struct mt9m111 *mt9m111 = to_mt9m111(client);
929790 s32 data;
930791 int ret;
931792
932− /* We must have a parent by now. And it cannot be a wrong one. */
933− BUG_ON(!icd->parent ||
934− to_soc_camera_host(icd->parent)->nr != icd->iface);
935−
936− mt9m111->lastpage = -1;
937−
938− mt9m111->autoexposure = 1;
939− mt9m111->autowhitebalance = 1;
940−
941793 data = reg_read(CHIP_VERSION);
942794
943795 switch (data) {
@@ -951,17 +803,16 @@ static int mt9m111_video_probe(struct soc_camera_device *icd, · 7 unmodified lines
951803 dev_info(&client->dev, "Detected a MT9M112 chip ID %x\n", data);
952804 break;
953805 default:
954− ret = -ENODEV;
955806 dev_err(&client->dev,
956807 "No MT9M111/MT9M112/MT9M131 chip detected register read %x\n",
957808 data);
958− goto ei2c;
809+ return -ENODEV;
959810 }
960811
961812 ret = mt9m111_init(mt9m111);
962−
963−ei2c:
964− return ret;
813+ if (ret)
814+ return ret;
815+ return v4l2_ctrl_handler_setup(&mt9m111->hdl);
965816 }
966817
967818 static int mt9m111_s_power(struct v4l2_subdev *sd, int on)
@@ -998,9 +849,11 @@ out: · 30 unmodified lines
998849 return ret;
999850 }
1000851
852+static const struct v4l2_ctrl_ops mt9m111_ctrl_ops = {
853+ .s_ctrl = mt9m111_s_ctrl,
854+};
855+
1001856 static struct v4l2_subdev_core_ops mt9m111_subdev_core_ops = {
1002− .g_ctrl = mt9m111_g_ctrl,
1003− .s_ctrl = mt9m111_s_ctrl,
1004857 .g_chip_ident = mt9m111_g_chip_ident,
1005858 .s_power = mt9m111_s_power,
1006859 #ifdef CONFIG_VIDEO_ADV_DEBUG
@@ -1019,6 +872,21 @@ static int mt9m111_enum_fmt(struct v4l2_subdev *sd, unsigned int index, · 12 unmodified lines
1019872 return 0;
1020873 }
1021874
875+static int mt9m111_g_mbus_config(struct v4l2_subdev *sd,
876+ struct v4l2_mbus_config *cfg)
877+{
878+ struct i2c_client *client = v4l2_get_subdevdata(sd);
879+ struct soc_camera_link *icl = soc_camera_i2c_to_link(client);
880+
881+ cfg->flags = V4L2_MBUS_MASTER | V4L2_MBUS_PCLK_SAMPLE_RISING |
882+ V4L2_MBUS_HSYNC_ACTIVE_HIGH | V4L2_MBUS_VSYNC_ACTIVE_HIGH |
883+ V4L2_MBUS_DATA_ACTIVE_HIGH;
884+ cfg->type = V4L2_MBUS_PARALLEL;
885+ cfg->flags = soc_camera_apply_board_flags(icl, cfg);
886+
887+ return 0;
888+}
889+
1022890 static struct v4l2_subdev_video_ops mt9m111_subdev_video_ops = {
1023891 .s_mbus_fmt = mt9m111_s_fmt,
1024892 .g_mbus_fmt = mt9m111_g_fmt,
@@ -1027,6 +895,7 @@ static struct v4l2_subdev_video_ops mt9m111_subdev_video_ops = { · 2 unmodified lines
1027895 .g_crop = mt9m111_g_crop,
1028896 .cropcap = mt9m111_cropcap,
1029897 .enum_mbus_fmt = mt9m111_enum_fmt,
898+ .g_mbus_config = mt9m111_g_mbus_config,
1030899 };
1031900
1032901 static struct v4l2_subdev_ops mt9m111_subdev_ops = {
@@ -1038,17 +907,10 @@ static int mt9m111_probe(struct i2c_client *client, · 5 unmodified lines
1038907 const struct i2c_device_id *did)
1039908 {
1040909 struct mt9m111 *mt9m111;
1041− struct soc_camera_device *icd = client->dev.platform_data;
1042910 struct i2c_adapter *adapter = to_i2c_adapter(client->dev.parent);
1043− struct soc_camera_link *icl;
911+ struct soc_camera_link *icl = soc_camera_i2c_to_link(client);
1044912 int ret;
1045913
1046− if (!icd) {
1047− dev_err(&client->dev, "mt9m111: soc-camera data missing!\n");
1048− return -EINVAL;
1049− }
1050−
1051− icl = to_soc_camera_link(icd);
1052914 if (!icl) {
1053915 dev_err(&client->dev, "mt9m111: driver needs platform data\n");
1054916 return -EINVAL;
@@ -1065,19 +927,37 @@ static int mt9m111_probe(struct i2c_client *client, · 10 unmodified lines
1065927 return -ENOMEM;
1066928
1067929 v4l2_i2c_subdev_init(&mt9m111->subdev, client, &mt9m111_subdev_ops);
930+ v4l2_ctrl_handler_init(&mt9m111->hdl, 5);
931+ v4l2_ctrl_new_std(&mt9m111->hdl, &mt9m111_ctrl_ops,
932+ V4L2_CID_VFLIP, 0, 1, 1, 0);
933+ v4l2_ctrl_new_std(&mt9m111->hdl, &mt9m111_ctrl_ops,
934+ V4L2_CID_HFLIP, 0, 1, 1, 0);
935+ v4l2_ctrl_new_std(&mt9m111->hdl, &mt9m111_ctrl_ops,
936+ V4L2_CID_AUTO_WHITE_BALANCE, 0, 1, 1, 1);
937+ mt9m111->gain = v4l2_ctrl_new_std(&mt9m111->hdl, &mt9m111_ctrl_ops,
938+ V4L2_CID_GAIN, 0, 63 * 2 * 2, 1, 32);
939+ v4l2_ctrl_new_std_menu(&mt9m111->hdl,
940+ &mt9m111_ctrl_ops, V4L2_CID_EXPOSURE_AUTO, 1, 0,
941+ V4L2_EXPOSURE_AUTO);
942+ mt9m111->subdev.ctrl_handler = &mt9m111->hdl;
943+ if (mt9m111->hdl.error) {
944+ int err = mt9m111->hdl.error;
1068945
1069− /* Second stage probe - when a capture adapter is there */
1070− icd->ops = &mt9m111_ops;
946+ kfree(mt9m111);
947+ return err;
948+ }
1071949
950+ /* Second stage probe - when a capture adapter is there */
1072951 mt9m111->rect.left = MT9M111_MIN_DARK_COLS;
1073952 mt9m111->rect.top = MT9M111_MIN_DARK_ROWS;
1074953 mt9m111->rect.width = MT9M111_MAX_WIDTH;
1075954 mt9m111->rect.height = MT9M111_MAX_HEIGHT;
1076955 mt9m111->fmt = &mt9m111_colour_fmts[0];
956+ mt9m111->lastpage = -1;
1077957
1078− ret = mt9m111_video_probe(icd, client);
958+ ret = mt9m111_video_probe(client);
1079959 if (ret) {
1080− icd->ops = NULL;
960+ v4l2_ctrl_handler_free(&mt9m111->hdl);
1081961 kfree(mt9m111);
1082962 }
1083963
@@ -1087,9 +967,9 @@ static int mt9m111_probe(struct i2c_client *client, · 3 unmodified lines
1087967 static int mt9m111_remove(struct i2c_client *client)
1088968 {
1089969 struct mt9m111 *mt9m111 = to_mt9m111(client);
1090− struct soc_camera_device *icd = client->dev.platform_data;
1091970
1092− icd->ops = NULL;
971+ v4l2_device_unregister_subdev(&mt9m111->subdev);
972+ v4l2_ctrl_handler_free(&mt9m111->hdl);
1093973 kfree(mt9m111);
1094974
1095975 return 0;
drivers/media/video/mt9t031.c+141−206
@@ -13,11 +13,20 @@ · 12 unmodified lines
1313 #include <linux/log2.h>
1414 #include <linux/pm.h>
1515 #include <linux/slab.h>
16+#include <linux/v4l2-mediabus.h>
1617 #include <linux/videodev2.h>
1718
1819 #include <media/soc_camera.h>
1920 #include <media/v4l2-chip-ident.h>
2021 #include <media/v4l2-subdev.h>
22+#include <media/v4l2-ctrls.h>
23+
24+/*
25+ * ATTENTION: this driver still cannot be used outside of the soc-camera
26+ * framework because of its PM implementation, using the video_device node.
27+ * If hardware becomes available for testing, alternative PM approaches shall
28+ * be considered and tested.
29+ */
2130
2231 /*
2332 * mt9t031 i2c address 0x5d
@@ -57,21 +66,20 @@ · 33 unmodified lines
5766 #define MT9T031_COLUMN_SKIP 32
5867 #define MT9T031_ROW_SKIP 20
5968
60−#define MT9T031_BUS_PARAM (SOCAM_PCLK_SAMPLE_RISING | \
61− SOCAM_PCLK_SAMPLE_FALLING | SOCAM_HSYNC_ACTIVE_HIGH | \
62− SOCAM_VSYNC_ACTIVE_HIGH | SOCAM_DATA_ACTIVE_HIGH | \
63− SOCAM_MASTER | SOCAM_DATAWIDTH_10)
64−
6569 struct mt9t031 {
6670 struct v4l2_subdev subdev;
71+ struct v4l2_ctrl_handler hdl;
72+ struct {
73+ /* exposure/auto-exposure cluster */
74+ struct v4l2_ctrl *autoexposure;
75+ struct v4l2_ctrl *exposure;
76+ };
6777 struct v4l2_rect rect; /* Sensor window */
6878 int model; /* V4L2_IDENT_MT9T031* codes from v4l2-chip-ident.h */
6979 u16 xskip;
7080 u16 yskip;
71− unsigned int gain;
81+ unsigned int total_h;
7282 unsigned short y_skip_top; /* Lines to skip at the top */
73− unsigned int exposure;
74− unsigned char autoexposure;
7583 };
7684
7785 static struct mt9t031 *to_mt9t031(const struct i2c_client *client)
@@ -179,95 +187,6 @@ static int mt9t031_s_stream(struct v4l2_subdev *sd, int enable) · 101 unmodified lines
179187 return 0;
180188 }
181189
182−static int mt9t031_set_bus_param(struct soc_camera_device *icd,
183− unsigned long flags)
184−{
185− struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
186−
187− /* The caller should have queried our parameters, check anyway */
188− if (flags & ~MT9T031_BUS_PARAM)
189− return -EINVAL;
190−
191− if (flags & SOCAM_PCLK_SAMPLE_FALLING)
192− reg_clear(client, MT9T031_PIXEL_CLOCK_CONTROL, 0x8000);
193− else
194− reg_set(client, MT9T031_PIXEL_CLOCK_CONTROL, 0x8000);
195−
196− return 0;
197−}
198−
199−static unsigned long mt9t031_query_bus_param(struct soc_camera_device *icd)
200−{
201− struct soc_camera_link *icl = to_soc_camera_link(icd);
202−
203− return soc_camera_apply_sensor_flags(icl, MT9T031_BUS_PARAM);
204−}
205−
206−enum {
207− MT9T031_CTRL_VFLIP,
208− MT9T031_CTRL_HFLIP,
209− MT9T031_CTRL_GAIN,
210− MT9T031_CTRL_EXPOSURE,
211− MT9T031_CTRL_EXPOSURE_AUTO,
212−};
213−
214−static const struct v4l2_queryctrl mt9t031_controls[] = {
215− [MT9T031_CTRL_VFLIP] = {
216− .id = V4L2_CID_VFLIP,
217− .type = V4L2_CTRL_TYPE_BOOLEAN,
218− .name = "Flip Vertically",
219− .minimum = 0,
220− .maximum = 1,
221− .step = 1,
222− .default_value = 0,
223− },
224− [MT9T031_CTRL_HFLIP] = {
225− .id = V4L2_CID_HFLIP,
226− .type = V4L2_CTRL_TYPE_BOOLEAN,
227− .name = "Flip Horizontally",
228− .minimum = 0,
229− .maximum = 1,
230− .step = 1,
231− .default_value = 0,
232− },
233− [MT9T031_CTRL_GAIN] = {
234− .id = V4L2_CID_GAIN,
235− .type = V4L2_CTRL_TYPE_INTEGER,
236− .name = "Gain",
237− .minimum = 0,
238− .maximum = 127,
239− .step = 1,
240− .default_value = 64,
241− .flags = V4L2_CTRL_FLAG_SLIDER,
242− },
243− [MT9T031_CTRL_EXPOSURE] = {
244− .id = V4L2_CID_EXPOSURE,
245− .type = V4L2_CTRL_TYPE_INTEGER,
246− .name = "Exposure",
247− .minimum = 1,
248− .maximum = 255,
249− .step = 1,
250− .default_value = 255,
251− .flags = V4L2_CTRL_FLAG_SLIDER,
252− },
253− [MT9T031_CTRL_EXPOSURE_AUTO] = {
254− .id = V4L2_CID_EXPOSURE_AUTO,
255− .type = V4L2_CTRL_TYPE_BOOLEAN,
256− .name = "Automatic Exposure",
257− .minimum = 0,
258− .maximum = 1,
259− .step = 1,
260− .default_value = 1,
261− }
262−};
263−
264−static struct soc_camera_ops mt9t031_ops = {
265− .set_bus_param = mt9t031_set_bus_param,
266− .query_bus_param = mt9t031_query_bus_param,
267− .controls = mt9t031_controls,
268− .num_controls = ARRAY_SIZE(mt9t031_controls),
269−};
270−
271190 /* target must be _even_ */
272191 static u16 mt9t031_skip(s32 *source, s32 target, s32 max)
273192 {
@@ -353,7 +272,7 @@ static int mt9t031_set_params(struct i2c_client *client, · 79 unmodified lines
353272
354273 /*
355274 * The caller provides a supported format, as guaranteed by
356− * icd->try_fmt_cap(), soc_camera_s_crop() and soc_camera_cropcap()
275+ * .try_mbus_fmt(), soc_camera_s_crop() and soc_camera_cropcap()
357276 */
358277 if (ret >= 0)
359278 ret = reg_write(client, MT9T031_COLUMN_START, rect->left);
@@ -364,17 +283,10 @@ static int mt9t031_set_params(struct i2c_client *client, · 4 unmodified lines
364283 if (ret >= 0)
365284 ret = reg_write(client, MT9T031_WINDOW_HEIGHT,
366285 rect->height + mt9t031->y_skip_top - 1);
367− if (ret >= 0 && mt9t031->autoexposure) {
368− unsigned int total_h = rect->height + mt9t031->y_skip_top + vblank;
369− ret = set_shutter(client, total_h);
370− if (ret >= 0) {
371− const u32 shutter_max = MT9T031_MAX_HEIGHT + vblank;
372− const struct v4l2_queryctrl *qctrl =
373− &mt9t031_controls[MT9T031_CTRL_EXPOSURE];
374− mt9t031->exposure = (shutter_max / 2 + (total_h - 1) *
375− (qctrl->maximum - qctrl->minimum)) /
376− shutter_max + qctrl->minimum;
377− }
286+ if (ret >= 0 && v4l2_ctrl_g_ctrl(mt9t031->autoexposure) == V4L2_EXPOSURE_AUTO) {
287+ mt9t031->total_h = rect->height + mt9t031->y_skip_top + vblank;
288+
289+ ret = set_shutter(client, mt9t031->total_h);
378290 }
379291
380292 /* Re-enable register update, commit all changes */
@@ -543,71 +455,57 @@ static int mt9t031_s_register(struct v4l2_subdev *sd, · 162 unmodified lines
543455 }
544456 #endif
545457
546−static int mt9t031_g_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
458+static int mt9t031_g_volatile_ctrl(struct v4l2_ctrl *ctrl)
547459 {
548− struct i2c_client *client = v4l2_get_subdevdata(sd);
549− struct mt9t031 *mt9t031 = to_mt9t031(client);
550− int data;
460+ struct mt9t031 *mt9t031 = container_of(ctrl->handler,
461+ struct mt9t031, hdl);
462+ const u32 shutter_max = MT9T031_MAX_HEIGHT + MT9T031_VERTICAL_BLANK;
463+ s32 min, max;
551464
552465 switch (ctrl->id) {
553− case V4L2_CID_VFLIP:
554− data = reg_read(client, MT9T031_READ_MODE_2);
555− if (data < 0)
556− return -EIO;
557− ctrl->value = !!(data & 0x8000);
558− break;
559− case V4L2_CID_HFLIP:
560− data = reg_read(client, MT9T031_READ_MODE_2);
561− if (data < 0)
562− return -EIO;
563− ctrl->value = !!(data & 0x4000);
564− break;
565466 case V4L2_CID_EXPOSURE_AUTO:
566− ctrl->value = mt9t031->autoexposure;
567− break;
568− case V4L2_CID_GAIN:
569− ctrl->value = mt9t031->gain;
570− break;
571− case V4L2_CID_EXPOSURE:
572− ctrl->value = mt9t031->exposure;
467+ min = mt9t031->exposure->minimum;
468+ max = mt9t031->exposure->maximum;
469+ mt9t031->exposure->val =
470+ (shutter_max / 2 + (mt9t031->total_h - 1) * (max - min))
471+ / shutter_max + min;
573472 break;
574473 }
575474 return 0;
576475 }
577476
578−static int mt9t031_s_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
477+static int mt9t031_s_ctrl(struct v4l2_ctrl *ctrl)
579478 {
479+ struct mt9t031 *mt9t031 = container_of(ctrl->handler,
480+ struct mt9t031, hdl);
481+ struct v4l2_subdev *sd = &mt9t031->subdev;
580482 struct i2c_client *client = v4l2_get_subdevdata(sd);
581− struct mt9t031 *mt9t031 = to_mt9t031(client);
582− const struct v4l2_queryctrl *qctrl;
483+ struct v4l2_ctrl *exp = mt9t031->exposure;
583484 int data;
584485
585486 switch (ctrl->id) {
586487 case V4L2_CID_VFLIP:
587− if (ctrl->value)
488+ if (ctrl->val)
588489 data = reg_set(client, MT9T031_READ_MODE_2, 0x8000);
589490 else
590491 data = reg_clear(client, MT9T031_READ_MODE_2, 0x8000);
591492 if (data < 0)
592493 return -EIO;
593− break;
494+ return 0;
594495 case V4L2_CID_HFLIP:
595− if (ctrl->value)
496+ if (ctrl->val)
596497 data = reg_set(client, MT9T031_READ_MODE_2, 0x4000);
597498 else
598499 data = reg_clear(client, MT9T031_READ_MODE_2, 0x4000);
599500 if (data < 0)
600501 return -EIO;
601− break;
502+ return 0;
602503 case V4L2_CID_GAIN:
603− qctrl = &mt9t031_controls[MT9T031_CTRL_GAIN];
604− if (ctrl->value > qctrl->maximum || ctrl->value < qctrl->minimum)
605− return -EINVAL;
606504 /* See Datasheet Table 7, Gain settings. */
607− if (ctrl->value <= qctrl->default_value) {
505+ if (ctrl->val <= ctrl->default_value) {
608506 /* Pack it into 0..1 step 0.125, register values 0..8 */
609− unsigned long range = qctrl->default_value - qctrl->minimum;
610− data = ((ctrl->value - qctrl->minimum) * 8 + range / 2) / range;
507+ unsigned long range = ctrl->default_value - ctrl->minimum;
508+ data = ((ctrl->val - ctrl->minimum) * 8 + range / 2) / range;
611509
612510 dev_dbg(&client->dev, "Setting gain %d\n", data);
613511 data = reg_write(client, MT9T031_GLOBAL_GAIN, data);
@@ -616,9 +514,9 @@ static int mt9t031_s_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl) · 2 unmodified lines
616514 } else {
617515 /* Pack it into 1.125..128 variable step, register values 9..0x7860 */
618516 /* We assume qctrl->maximum - qctrl->default_value - 1 > 0 */
619− unsigned long range = qctrl->maximum - qctrl->default_value - 1;
517+ unsigned long range = ctrl->maximum - ctrl->default_value - 1;
620518 /* calculated gain: map 65..127 to 9..1024 step 0.125 */
621− unsigned long gain = ((ctrl->value - qctrl->default_value - 1) *
519+ unsigned long gain = ((ctrl->val - ctrl->default_value - 1) *
622520 1015 + range / 2) / range + 9;
623521
624522 if (gain <= 32) /* calculated gain 9..32 -> 9..32 */
@@ -635,19 +533,13 @@ static int mt9t031_s_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl) · 10 unmodified lines
635533 if (data < 0)
636534 return -EIO;
637535 }
536+ return 0;
638537
639− /* Success */
640− mt9t031->gain = ctrl->value;
641− break;
642− case V4L2_CID_EXPOSURE:
643− qctrl = &mt9t031_controls[MT9T031_CTRL_EXPOSURE];
644− /* mt9t031 has maximum == default */
645− if (ctrl->value > qctrl->maximum || ctrl->value < qctrl->minimum)
646− return -EINVAL;
647− else {
648− const unsigned long range = qctrl->maximum - qctrl->minimum;
649− const u32 shutter = ((ctrl->value - qctrl->minimum) * 1048 +
650− range / 2) / range + 1;
538+ case V4L2_CID_EXPOSURE_AUTO:
539+ if (ctrl->val == V4L2_EXPOSURE_MANUAL) {
540+ unsigned int range = exp->maximum - exp->minimum;
541+ unsigned int shutter = ((exp->val - exp->minimum) * 1048 +
542+ range / 2) / range + 1;
651543 u32 old;
652544
653545 get_shutter(client, &old);
@@ -655,27 +547,15 @@ static int mt9t031_s_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl) · 1 unmodified line
655547 old, shutter);
656548 if (set_shutter(client, shutter) < 0)
657549 return -EIO;
658− mt9t031->exposure = ctrl->value;
659− mt9t031->autoexposure = 0;
660− }
661− break;
662− case V4L2_CID_EXPOSURE_AUTO:
663− if (ctrl->value) {
550+ } else {
664551 const u16 vblank = MT9T031_VERTICAL_BLANK;
665− const u32 shutter_max = MT9T031_MAX_HEIGHT + vblank;
666− unsigned int total_h = mt9t031->rect.height +
552+ mt9t031->total_h = mt9t031->rect.height +
667553 mt9t031->y_skip_top + vblank;
668554
669− if (set_shutter(client, total_h) < 0)
555+ if (set_shutter(client, mt9t031->total_h) < 0)
670556 return -EIO;
671− qctrl = &mt9t031_controls[MT9T031_CTRL_EXPOSURE];
672− mt9t031->exposure = (shutter_max / 2 + (total_h - 1) *
673− (qctrl->maximum - qctrl->minimum)) /
674− shutter_max + qctrl->minimum;
675− mt9t031->autoexposure = 1;
676− } else
677− mt9t031->autoexposure = 0;
678− break;
557+ }
558+ return 0;
679559 default:
680560 return -EINVAL;
681561 }
@@ -700,8 +580,7 @@ static int mt9t031_runtime_suspend(struct device *dev) · 18 unmodified lines
700580 static int mt9t031_runtime_resume(struct device *dev)
701581 {
702582 struct video_device *vdev = to_video_device(dev);
703− struct soc_camera_device *icd = dev_get_drvdata(vdev->parent);
704− struct v4l2_subdev *sd = soc_camera_to_subdev(icd);
583+ struct v4l2_subdev *sd = soc_camera_vdev_to_subdev(vdev);
705584 struct i2c_client *client = v4l2_get_subdevdata(sd);
706585 struct mt9t031 *mt9t031 = to_mt9t031(client);
707586
@@ -734,6 +613,19 @@ static struct device_type mt9t031_dev_type = { · 26 unmodified lines
734613 .pm = &mt9t031_dev_pm_ops,
735614 };
736615
616+static int mt9t031_s_power(struct v4l2_subdev *sd, int on)
617+{
618+ struct i2c_client *client = v4l2_get_subdevdata(sd);
619+ struct video_device *vdev = soc_camera_i2c_to_vdev(client);
620+
621+ if (on)
622+ vdev->dev.type = &mt9t031_dev_type;
623+ else
624+ vdev->dev.type = NULL;
625+
626+ return 0;
627+}
628+
737629 /*
738630 * Interface active, can use i2c. If it fails, it can indeed mean, that
739631 * this wasn't our capture interface, so, we wait for the right one
@@ -741,7 +633,6 @@ static struct device_type mt9t031_dev_type = { · 1 unmodified line
741633 static int mt9t031_video_probe(struct i2c_client *client)
742634 {
743635 struct mt9t031 *mt9t031 = to_mt9t031(client);
744− struct video_device *vdev = soc_camera_i2c_to_vdev(client);
745636 s32 data;
746637 int ret;
747638
@@ -768,11 +659,7 @@ static int mt9t031_video_probe(struct i2c_client *client) · 20 unmodified lines
768659 if (ret < 0)
769660 dev_err(&client->dev, "Failed to initialise the camera\n");
770661 else
771− vdev->dev.type = &mt9t031_dev_type;
772−
773− /* mt9t031_idle() has reset the chip to default. */
774− mt9t031->exposure = 255;
775− mt9t031->gain = 64;
662+ v4l2_ctrl_handler_setup(&mt9t031->hdl);
776663
777664 return ret;
778665 }
@@ -787,10 +674,14 @@ static int mt9t031_g_skip_top_lines(struct v4l2_subdev *sd, u32 *lines) · 8 unmodified lines
787674 return 0;
788675 }
789676
677+static const struct v4l2_ctrl_ops mt9t031_ctrl_ops = {
678+ .g_volatile_ctrl = mt9t031_g_volatile_ctrl,
679+ .s_ctrl = mt9t031_s_ctrl,
680+};
681+
790682 static struct v4l2_subdev_core_ops mt9t031_subdev_core_ops = {
791− .g_ctrl = mt9t031_g_ctrl,
792− .s_ctrl = mt9t031_s_ctrl,
793683 .g_chip_ident = mt9t031_g_chip_ident,
684+ .s_power = mt9t031_s_power,
794685 #ifdef CONFIG_VIDEO_ADV_DEBUG
795686 .g_register = mt9t031_g_register,
796687 .s_register = mt9t031_s_register,
@@ -807,6 +698,34 @@ static int mt9t031_enum_fmt(struct v4l2_subdev *sd, unsigned int index, · 10 unmodified lines
807698 return 0;
808699 }
809700
701+static int mt9t031_g_mbus_config(struct v4l2_subdev *sd,
702+ struct v4l2_mbus_config *cfg)
703+{
704+ struct i2c_client *client = v4l2_get_subdevdata(sd);
705+ struct soc_camera_link *icl = soc_camera_i2c_to_link(client);
706+
707+ cfg->flags = V4L2_MBUS_MASTER | V4L2_MBUS_PCLK_SAMPLE_RISING |
708+ V4L2_MBUS_PCLK_SAMPLE_FALLING | V4L2_MBUS_HSYNC_ACTIVE_HIGH |
709+ V4L2_MBUS_VSYNC_ACTIVE_HIGH | V4L2_MBUS_DATA_ACTIVE_HIGH;
710+ cfg->type = V4L2_MBUS_PARALLEL;
711+ cfg->flags = soc_camera_apply_board_flags(icl, cfg);
712+
713+ return 0;
714+}
715+
716+static int mt9t031_s_mbus_config(struct v4l2_subdev *sd,
717+ const struct v4l2_mbus_config *cfg)
718+{
719+ struct i2c_client *client = v4l2_get_subdevdata(sd);
720+ struct soc_camera_link *icl = soc_camera_i2c_to_link(client);
721+
722+ if (soc_camera_apply_board_flags(icl, cfg) &
723+ V4L2_MBUS_PCLK_SAMPLE_FALLING)
724+ return reg_clear(client, MT9T031_PIXEL_CLOCK_CONTROL, 0x8000);
725+ else
726+ return reg_set(client, MT9T031_PIXEL_CLOCK_CONTROL, 0x8000);
727+}
728+
810729 static struct v4l2_subdev_video_ops mt9t031_subdev_video_ops = {
811730 .s_stream = mt9t031_s_stream,
812731 .s_mbus_fmt = mt9t031_s_fmt,
@@ -816,6 +735,8 @@ static struct v4l2_subdev_video_ops mt9t031_subdev_video_ops = { · 3 unmodified lines
816735 .g_crop = mt9t031_g_crop,
817736 .cropcap = mt9t031_cropcap,
818737 .enum_mbus_fmt = mt9t031_enum_fmt,
738+ .g_mbus_config = mt9t031_g_mbus_config,
739+ .s_mbus_config = mt9t031_s_mbus_config,
819740 };
820741
821742 static struct v4l2_subdev_sensor_ops mt9t031_subdev_sensor_ops = {
@@ -832,18 +753,13 @@ static int mt9t031_probe(struct i2c_client *client, · 10 unmodified lines
832753 const struct i2c_device_id *did)
833754 {
834755 struct mt9t031 *mt9t031;
835− struct soc_camera_device *icd = client->dev.platform_data;
756+ struct soc_camera_link *icl = soc_camera_i2c_to_link(client);
836757 struct i2c_adapter *adapter = to_i2c_adapter(client->dev.parent);
837758 int ret;
838759
839− if (icd) {
840− struct soc_camera_link *icl = to_soc_camera_link(icd);
841− if (!icl) {
842− dev_err(&client->dev, "MT9T031 driver needs platform data\n");
843− return -EINVAL;
844− }
845−
846− icd->ops = &mt9t031_ops;
760+ if (!icl) {
761+ dev_err(&client->dev, "MT9T031 driver needs platform data\n");
762+ return -EINVAL;
847763 }
848764
849765 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_WORD_DATA)) {
@@ -857,6 +773,33 @@ static int mt9t031_probe(struct i2c_client *client, · 7 unmodified lines
857773 return -ENOMEM;
858774
859775 v4l2_i2c_subdev_init(&mt9t031->subdev, client, &mt9t031_subdev_ops);
776+ v4l2_ctrl_handler_init(&mt9t031->hdl, 5);
777+ v4l2_ctrl_new_std(&mt9t031->hdl, &mt9t031_ctrl_ops,
778+ V4L2_CID_VFLIP, 0, 1, 1, 0);
779+ v4l2_ctrl_new_std(&mt9t031->hdl, &mt9t031_ctrl_ops,
780+ V4L2_CID_HFLIP, 0, 1, 1, 0);
781+ v4l2_ctrl_new_std(&mt9t031->hdl, &mt9t031_ctrl_ops,
782+ V4L2_CID_GAIN, 0, 127, 1, 64);
783+
784+ /*
785+ * Simulated autoexposure. If enabled, we calculate shutter width
786+ * ourselves in the driver based on vertical blanking and frame width
787+ */
788+ mt9t031->autoexposure = v4l2_ctrl_new_std_menu(&mt9t031->hdl,
789+ &mt9t031_ctrl_ops, V4L2_CID_EXPOSURE_AUTO, 1, 0,
790+ V4L2_EXPOSURE_AUTO);
791+ mt9t031->exposure = v4l2_ctrl_new_std(&mt9t031->hdl, &mt9t031_ctrl_ops,
792+ V4L2_CID_EXPOSURE, 1, 255, 1, 255);
793+
794+ mt9t031->subdev.ctrl_handler = &mt9t031->hdl;
795+ if (mt9t031->hdl.error) {
796+ int err = mt9t031->hdl.error;
797+
798+ kfree(mt9t031);
799+ return err;
800+ }
801+ v4l2_ctrl_auto_cluster(2, &mt9t031->autoexposure,
802+ V4L2_EXPOSURE_MANUAL, true);
860803
861804 mt9t031->y_skip_top = 0;
862805 mt9t031->rect.left = MT9T031_COLUMN_SKIP;
@@ -864,12 +807,6 @@ static int mt9t031_probe(struct i2c_client *client, · 1 unmodified line
864807 mt9t031->rect.width = MT9T031_MAX_WIDTH;
865808 mt9t031->rect.height = MT9T031_MAX_HEIGHT;
866809
867− /*
868− * Simulated autoexposure. If enabled, we calculate shutter width
869− * ourselves in the driver based on vertical blanking and frame width
870− */
871− mt9t031->autoexposure = 1;
872−
873810 mt9t031->xskip = 1;
874811 mt9t031->yskip = 1;
875812
@@ -880,8 +817,7 @@ static int mt9t031_probe(struct i2c_client *client, · 4 unmodified lines
880817 mt9t031_disable(client);
881818
882819 if (ret) {
883− if (icd)
884− icd->ops = NULL;
820+ v4l2_ctrl_handler_free(&mt9t031->hdl);
885821 kfree(mt9t031);
886822 }
887823
@@ -891,10 +827,9 @@ static int mt9t031_probe(struct i2c_client *client, · 3 unmodified lines
891827 static int mt9t031_remove(struct i2c_client *client)
892828 {
893829 struct mt9t031 *mt9t031 = to_mt9t031(client);
894− struct soc_camera_device *icd = client->dev.platform_data;
895830
896− if (icd)
897− icd->ops = NULL;
831+ v4l2_device_unregister_subdev(&mt9t031->subdev);
832+ v4l2_ctrl_handler_free(&mt9t031->hdl);
898833 kfree(mt9t031);
899834
900835 return 0;
drivers/media/video/mt9t112.c+117−152
@@ -22,11 +22,11 @@ · 21 unmodified lines
2222 #include <linux/init.h>
2323 #include <linux/module.h>
2424 #include <linux/slab.h>
25+#include <linux/v4l2-mediabus.h>
2526 #include <linux/videodev2.h>
2627
2728 #include <media/mt9t112.h>
2829 #include <media/soc_camera.h>
29−#include <media/soc_mediabus.h>
3030 #include <media/v4l2-chip-ident.h>
3131 #include <media/v4l2-common.h>
3232
@@ -34,11 +34,7 @@ · 1 unmodified line
3434 /* #define EXT_CLOCK 24000000 */
3535
3636 /************************************************************************
37−
38−
3937 macro
40−
41−
4238 ************************************************************************/
4339 /*
4440 * frame size
@@ -80,17 +76,8 @@ · 35 unmodified lines
8076 #define VAR8(id, offset) _VAR(id, offset, 0x8000)
8177
8278 /************************************************************************
83−
84−
8579 struct
86−
87−
8880 ************************************************************************/
89−struct mt9t112_frame_size {
90− u16 width;
91− u16 height;
92−};
93−
9481 struct mt9t112_format {
9582 enum v4l2_mbus_pixelcode code;
9683 enum v4l2_colorspace colorspace;
@@ -102,21 +89,17 @@ struct mt9t112_priv { · 5 unmodified lines
10289 struct v4l2_subdev subdev;
10390 struct mt9t112_camera_info *info;
10491 struct i2c_client *client;
105− struct soc_camera_device icd;
106− struct mt9t112_frame_size frame;
92+ struct v4l2_rect frame;
10793 const struct mt9t112_format *format;
10894 int model;
10995 u32 flags;
11096 /* for flags */
111−#define INIT_DONE (1<<0)
97+#define INIT_DONE (1 << 0)
98+#define PCLK_RISING (1 << 1)
11299 };
113100
114101 /************************************************************************
115−
116−
117102 supported format
118−
119−
120103 ************************************************************************/
121104
122105 static const struct mt9t112_format mt9t112_cfmts[] = {
@@ -154,11 +137,7 @@ static const struct mt9t112_format mt9t112_cfmts[] = { · 31 unmodified lines
154137 };
155138
156139 /************************************************************************
157−
158−
159140 general function
160−
161−
162141 ************************************************************************/
163142 static struct mt9t112_priv *to_mt9t112(const struct i2c_client *client)
164143 {
@@ -326,50 +305,47 @@ static int mt9t112_clock_info(const struct i2c_client *client, u32 ext) · 161 unmodified lines
326305 n = (n >> 8) & 0x003f;
327306
328307 enable = ((6000 > ext) || (54000 < ext)) ? "X" : "";
329− dev_info(&client->dev, "EXTCLK : %10u K %s\n", ext, enable);
308+ dev_dbg(&client->dev, "EXTCLK : %10u K %s\n", ext, enable);
330309
331310 vco = 2 * m * ext / (n+1);
332311 enable = ((384000 > vco) || (768000 < vco)) ? "X" : "";
333− dev_info(&client->dev, "VCO : %10u K %s\n", vco, enable);
312+ dev_dbg(&client->dev, "VCO : %10u K %s\n", vco, enable);
334313
335314 clk = vco / (p1+1) / (p2+1);
336315 enable = (96000 < clk) ? "X" : "";
337− dev_info(&client->dev, "PIXCLK : %10u K %s\n", clk, enable);
316+ dev_dbg(&client->dev, "PIXCLK : %10u K %s\n", clk, enable);
338317
339318 clk = vco / (p3+1);
340319 enable = (768000 < clk) ? "X" : "";
341− dev_info(&client->dev, "MIPICLK : %10u K %s\n", clk, enable);
320+ dev_dbg(&client->dev, "MIPICLK : %10u K %s\n", clk, enable);
342321
343322 clk = vco / (p6+1);
344323 enable = (96000 < clk) ? "X" : "";
345− dev_info(&client->dev, "MCU CLK : %10u K %s\n", clk, enable);
324+ dev_dbg(&client->dev, "MCU CLK : %10u K %s\n", clk, enable);
346325
347326 clk = vco / (p5+1);
348327 enable = (54000 < clk) ? "X" : "";
349− dev_info(&client->dev, "SOC CLK : %10u K %s\n", clk, enable);
328+ dev_dbg(&client->dev, "SOC CLK : %10u K %s\n", clk, enable);
350329
351330 clk = vco / (p4+1);
352331 enable = (70000 < clk) ? "X" : "";
353− dev_info(&client->dev, "Sensor CLK : %10u K %s\n", clk, enable);
332+ dev_dbg(&client->dev, "Sensor CLK : %10u K %s\n", clk, enable);
354333
355334 clk = vco / (p7+1);
356− dev_info(&client->dev, "External sensor : %10u K\n", clk);
335+ dev_dbg(&client->dev, "External sensor : %10u K\n", clk);
357336
358337 clk = ext / (n+1);
359338 enable = ((2000 > clk) || (24000 < clk)) ? "X" : "";
360− dev_info(&client->dev, "PFD : %10u K %s\n", clk, enable);
339+ dev_dbg(&client->dev, "PFD : %10u K %s\n", clk, enable);
361340
362341 return 0;
363342 }
364343 #endif
365344
366−static void mt9t112_frame_check(u32 *width, u32 *height)
345+static void mt9t112_frame_check(u32 *width, u32 *height, u32 *left, u32 *top)
367346 {
368− if (*width > MAX_WIDTH)
369− *width = MAX_WIDTH;
370−
371− if (*height > MAX_HEIGHT)
372− *height = MAX_HEIGHT;
347+ soc_camera_limit_side(left, width, 0, 0, MAX_WIDTH);
348+ soc_camera_limit_side(top, height, 0, 0, MAX_HEIGHT);
373349 }
374350
375351 static int mt9t112_set_a_frame_size(const struct i2c_client *client,
@@ -758,48 +734,7 @@ static int mt9t112_init_camera(const struct i2c_client *client) · 382 unmodified lines
758734 }
759735
760736 /************************************************************************
761−
762−
763− soc_camera_ops
764−
765−
766−************************************************************************/
767−static int mt9t112_set_bus_param(struct soc_camera_device *icd,
768− unsigned long flags)
769−{
770− return 0;
771−}
772−
773−static unsigned long mt9t112_query_bus_param(struct soc_camera_device *icd)
774−{
775− struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
776− struct mt9t112_priv *priv = to_mt9t112(client);
777− struct soc_camera_link *icl = to_soc_camera_link(icd);
778− unsigned long flags = SOCAM_MASTER | SOCAM_VSYNC_ACTIVE_HIGH |
779− SOCAM_HSYNC_ACTIVE_HIGH | SOCAM_DATA_ACTIVE_HIGH;
780−
781− flags |= (priv->info->flags & MT9T112_FLAG_PCLK_RISING_EDGE) ?
782− SOCAM_PCLK_SAMPLE_RISING : SOCAM_PCLK_SAMPLE_FALLING;
783−
784− if (priv->info->flags & MT9T112_FLAG_DATAWIDTH_8)
785− flags |= SOCAM_DATAWIDTH_8;
786− else
787− flags |= SOCAM_DATAWIDTH_10;
788−
789− return soc_camera_apply_sensor_flags(icl, flags);
790−}
791−
792−static struct soc_camera_ops mt9t112_ops = {
793− .set_bus_param = mt9t112_set_bus_param,
794− .query_bus_param = mt9t112_query_bus_param,
795−};
796−
797−/************************************************************************
798−
799−
800737 v4l2_subdev_core_ops
801−
802−
803738 ************************************************************************/
804739 static int mt9t112_g_chip_ident(struct v4l2_subdev *sd,
805740 struct v4l2_dbg_chip_ident *id)
@@ -850,11 +785,7 @@ static struct v4l2_subdev_core_ops mt9t112_subdev_core_ops = { · 44 unmodified lines
850785
851786
852787 /************************************************************************
853−
854−
855788 v4l2_subdev_video_ops
856−
857−
858789 ************************************************************************/
859790 static int mt9t112_s_stream(struct v4l2_subdev *sd, int enable)
860791 {
@@ -877,8 +808,7 @@ static int mt9t112_s_stream(struct v4l2_subdev *sd, int enable) · 16 unmodified lines
877808 }
878809
879810 if (!(priv->flags & INIT_DONE)) {
880− u16 param = (MT9T112_FLAG_PCLK_RISING_EDGE &
881− priv->info->flags) ? 0x0001 : 0x0000;
811+ u16 param = PCLK_RISING & priv->flags ? 0x0001 : 0x0000;
882812
883813 ECHECKER(ret, mt9t112_init_camera(client));
884814
@@ -910,19 +840,12 @@ static int mt9t112_s_stream(struct v4l2_subdev *sd, int enable) · 25 unmodified lines
910840 return ret;
911841 }
912842
913−static int mt9t112_set_params(struct i2c_client *client, u32 width, u32 height,
843+static int mt9t112_set_params(struct mt9t112_priv *priv,
844+ const struct v4l2_rect *rect,
914845 enum v4l2_mbus_pixelcode code)
915846 {
916− struct mt9t112_priv *priv = to_mt9t112(client);
917847 int i;
918848
919− priv->format = NULL;
920−
921− /*
922− * frame size check
923− */
924− mt9t112_frame_check(&width, &height);
925−
926849 /*
927850 * get color format
928851 */
@@ -933,8 +856,13 @@ static int mt9t112_set_params(struct i2c_client *client, u32 width, u32 height, · 4 unmodified lines
933856 if (i == ARRAY_SIZE(mt9t112_cfmts))
934857 return -EINVAL;
935858
936− priv->frame.width = (u16)width;
937− priv->frame.height = (u16)height;
859+ priv->frame = *rect;
860+
861+ /*
862+ * frame size check
863+ */
864+ mt9t112_frame_check(&priv->frame.width, &priv->frame.height,
865+ &priv->frame.left, &priv->frame.top);
938866
939867 priv->format = mt9t112_cfmts + i;
940868
@@ -945,9 +873,12 @@ static int mt9t112_cropcap(struct v4l2_subdev *sd, struct v4l2_cropcap *a) · 4 unmodified lines
945873 {
946874 a->bounds.left = 0;
947875 a->bounds.top = 0;
948− a->bounds.width = VGA_WIDTH;
949− a->bounds.height = VGA_HEIGHT;
950− a->defrect = a->bounds;
876+ a->bounds.width = MAX_WIDTH;
877+ a->bounds.height = MAX_HEIGHT;
878+ a->defrect.left = 0;
879+ a->defrect.top = 0;
880+ a->defrect.width = VGA_WIDTH;
881+ a->defrect.height = VGA_HEIGHT;
951882 a->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
952883 a->pixelaspect.numerator = 1;
953884 a->pixelaspect.denominator = 1;
@@ -957,11 +888,11 @@ static int mt9t112_cropcap(struct v4l2_subdev *sd, struct v4l2_cropcap *a) · 3 unmodified lines
957888
958889 static int mt9t112_g_crop(struct v4l2_subdev *sd, struct v4l2_crop *a)
959890 {
960− a->c.left = 0;
961− a->c.top = 0;
962− a->c.width = VGA_WIDTH;
963− a->c.height = VGA_HEIGHT;
964− a->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
891+ struct i2c_client *client = v4l2_get_subdevdata(sd);
892+ struct mt9t112_priv *priv = to_mt9t112(client);
893+
894+ a->c = priv->frame;
895+ a->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
965896
966897 return 0;
967898 }
@@ -969,10 +900,10 @@ static int mt9t112_g_crop(struct v4l2_subdev *sd, struct v4l2_crop *a) · 1 unmodified line
969900 static int mt9t112_s_crop(struct v4l2_subdev *sd, struct v4l2_crop *a)
970901 {
971902 struct i2c_client *client = v4l2_get_subdevdata(sd);
903+ struct mt9t112_priv *priv = to_mt9t112(client);
972904 struct v4l2_rect *rect = &a->c;
973905
974− return mt9t112_set_params(client, rect->width, rect->height,
975− V4L2_MBUS_FMT_UYVY8_2X8);
906+ return mt9t112_set_params(priv, rect, priv->format->code);
976907 }
977908
978909 static int mt9t112_g_fmt(struct v4l2_subdev *sd,
@@ -981,16 +912,9 @@ static int mt9t112_g_fmt(struct v4l2_subdev *sd, · 2 unmodified lines
981912 struct i2c_client *client = v4l2_get_subdevdata(sd);
982913 struct mt9t112_priv *priv = to_mt9t112(client);
983914
984− if (!priv->format) {
985− int ret = mt9t112_set_params(client, VGA_WIDTH, VGA_HEIGHT,
986− V4L2_MBUS_FMT_UYVY8_2X8);
987− if (ret < 0)
988− return ret;
989− }
990−
991915 mf->width = priv->frame.width;
992916 mf->height = priv->frame.height;
993− /* TODO: set colorspace */
917+ mf->colorspace = priv->format->colorspace;
994918 mf->code = priv->format->code;
995919 mf->field = V4L2_FIELD_NONE;
996920
@@ -1001,17 +925,42 @@ static int mt9t112_s_fmt(struct v4l2_subdev *sd, · 4 unmodified lines
1001925 struct v4l2_mbus_framefmt *mf)
1002926 {
1003927 struct i2c_client *client = v4l2_get_subdevdata(sd);
928+ struct mt9t112_priv *priv = to_mt9t112(client);
929+ struct v4l2_rect rect = {
930+ .width = mf->width,
931+ .height = mf->height,
932+ .left = priv->frame.left,
933+ .top = priv->frame.top,
934+ };
935+ int ret;
936+
937+ ret = mt9t112_set_params(priv, &rect, mf->code);
938+
939+ if (!ret)
940+ mf->colorspace = priv->format->colorspace;
1004941
1005− /* TODO: set colorspace */
1006− return mt9t112_set_params(client, mf->width, mf->height, mf->code);
942+ return ret;
1007943 }
1008944
1009945 static int mt9t112_try_fmt(struct v4l2_subdev *sd,
1010946 struct v4l2_mbus_framefmt *mf)
1011947 {
1012− mt9t112_frame_check(&mf->width, &mf->height);
948+ unsigned int top, left;
949+ int i;
950+
951+ for (i = 0; i < ARRAY_SIZE(mt9t112_cfmts); i++)
952+ if (mt9t112_cfmts[i].code == mf->code)
953+ break;
954+
955+ if (i == ARRAY_SIZE(mt9t112_cfmts)) {
956+ mf->code = V4L2_MBUS_FMT_UYVY8_2X8;
957+ mf->colorspace = V4L2_COLORSPACE_JPEG;
958+ } else {
959+ mf->colorspace = mt9t112_cfmts[i].colorspace;
960+ }
961+
962+ mt9t112_frame_check(&mf->width, &mf->height, &left, &top);
1013963
1014− /* TODO: set colorspace */
1015964 mf->field = V4L2_FIELD_NONE;
1016965
1017966 return 0;
@@ -1024,6 +973,35 @@ static int mt9t112_enum_fmt(struct v4l2_subdev *sd, unsigned int index, · 6 unmodified lines
1024973 return -EINVAL;
1025974
1026975 *code = mt9t112_cfmts[index].code;
976+
977+ return 0;
978+}
979+
980+static int mt9t112_g_mbus_config(struct v4l2_subdev *sd,
981+ struct v4l2_mbus_config *cfg)
982+{
983+ struct i2c_client *client = v4l2_get_subdevdata(sd);
984+ struct soc_camera_link *icl = soc_camera_i2c_to_link(client);
985+
986+ cfg->flags = V4L2_MBUS_MASTER | V4L2_MBUS_VSYNC_ACTIVE_HIGH |
987+ V4L2_MBUS_HSYNC_ACTIVE_HIGH | V4L2_MBUS_DATA_ACTIVE_HIGH |
988+ V4L2_MBUS_PCLK_SAMPLE_RISING | V4L2_MBUS_PCLK_SAMPLE_FALLING;
989+ cfg->type = V4L2_MBUS_PARALLEL;
990+ cfg->flags = soc_camera_apply_board_flags(icl, cfg);
991+
992+ return 0;
993+}
994+
995+static int mt9t112_s_mbus_config(struct v4l2_subdev *sd,
996+ const struct v4l2_mbus_config *cfg)
997+{
998+ struct i2c_client *client = v4l2_get_subdevdata(sd);
999+ struct soc_camera_link *icl = soc_camera_i2c_to_link(client);
1000+ struct mt9t112_priv *priv = to_mt9t112(client);
1001+
1002+ if (soc_camera_apply_board_flags(icl, cfg) & V4L2_MBUS_PCLK_SAMPLE_RISING)
1003+ priv->flags |= PCLK_RISING;
1004+
10271005 return 0;
10281006 }
10291007
@@ -1036,31 +1014,24 @@ static struct v4l2_subdev_video_ops mt9t112_subdev_video_ops = { · 6 unmodified lines
10361014 .g_crop = mt9t112_g_crop,
10371015 .s_crop = mt9t112_s_crop,
10381016 .enum_mbus_fmt = mt9t112_enum_fmt,
1017+ .g_mbus_config = mt9t112_g_mbus_config,
1018+ .s_mbus_config = mt9t112_s_mbus_config,
10391019 };
10401020
10411021 /************************************************************************
1042−
1043−
10441022 i2c driver
1045−
1046−
10471023 ************************************************************************/
10481024 static struct v4l2_subdev_ops mt9t112_subdev_ops = {
10491025 .core = &mt9t112_subdev_core_ops,
10501026 .video = &mt9t112_subdev_video_ops,
10511027 };
10521028
1053−static int mt9t112_camera_probe(struct soc_camera_device *icd,
1054− struct i2c_client *client)
1029+static int mt9t112_camera_probe(struct i2c_client *client)
10551030 {
10561031 struct mt9t112_priv *priv = to_mt9t112(client);
10571032 const char *devname;
10581033 int chipid;
10591034
1060− /* We must have a parent by now. And it cannot be a wrong one. */
1061− BUG_ON(!icd->parent ||
1062− to_soc_camera_host(icd->parent)->nr != icd->iface);
1063−
10641035 /*
10651036 * check and show chip ID
10661037 */
@@ -1088,20 +1059,21 @@ static int mt9t112_camera_probe(struct soc_camera_device *icd, · 21 unmodified lines
10881059 static int mt9t112_probe(struct i2c_client *client,
10891060 const struct i2c_device_id *did)
10901061 {
1091− struct mt9t112_priv *priv;
1092− struct soc_camera_device *icd = client->dev.platform_data;
1093− struct soc_camera_link *icl;
1094− int ret;
1062+ struct mt9t112_priv *priv;
1063+ struct soc_camera_link *icl = soc_camera_i2c_to_link(client);
1064+ struct v4l2_rect rect = {
1065+ .width = VGA_WIDTH,
1066+ .height = VGA_HEIGHT,
1067+ .left = (MAX_WIDTH - VGA_WIDTH) / 2,
1068+ .top = (MAX_HEIGHT - VGA_HEIGHT) / 2,
1069+ };
1070+ int ret;
10951071
1096− if (!icd) {
1097− dev_err(&client->dev, "mt9t112: missing soc-camera data!\n");
1072+ if (!icl || !icl->priv) {
1073+ dev_err(&client->dev, "mt9t112: missing platform data!\n");
10981074 return -EINVAL;
10991075 }
11001076
1101− icl = to_soc_camera_link(icd);
1102− if (!icl || !icl->priv)
1103− return -EINVAL;
1104−
11051077 priv = kzalloc(sizeof(*priv), GFP_KERNEL);
11061078 if (!priv)
11071079 return -ENOMEM;
@@ -1110,13 +1082,12 @@ static int mt9t112_probe(struct i2c_client *client, · 2 unmodified lines
11101082
11111083 v4l2_i2c_subdev_init(&priv->subdev, client, &mt9t112_subdev_ops);
11121084
1113− icd->ops = &mt9t112_ops;
1114−
1115− ret = mt9t112_camera_probe(icd, client);
1116− if (ret) {
1117− icd->ops = NULL;
1085+ ret = mt9t112_camera_probe(client);
1086+ if (ret)
11181087 kfree(priv);
1119− }
1088+
1089+ /* Cannot fail: using the default supported pixel code */
1090+ mt9t112_set_params(priv, &rect, V4L2_MBUS_FMT_UYVY8_2X8);
11201091
11211092 return ret;
11221093 }
@@ -1124,9 +1095,7 @@ static int mt9t112_probe(struct i2c_client *client, · 1 unmodified line
11241095 static int mt9t112_remove(struct i2c_client *client)
11251096 {
11261097 struct mt9t112_priv *priv = to_mt9t112(client);
1127− struct soc_camera_device *icd = client->dev.platform_data;
11281098
1129− icd->ops = NULL;
11301099 kfree(priv);
11311100 return 0;
11321101 }
@@ -1147,11 +1116,7 @@ static struct i2c_driver mt9t112_i2c_driver = { · 14 unmodified lines
11471116 };
11481117
11491118 /************************************************************************
1150−
1151−
11521119 module function
1153−
1154−
11551120 ************************************************************************/
11561121 static int __init mt9t112_module_init(void)
11571122 {
drivers/media/video/mt9v022.c+185−262
@@ -14,9 +14,11 @@ · 13 unmodified lines
1414 #include <linux/delay.h>
1515 #include <linux/log2.h>
1616
17+#include <media/soc_camera.h>
18+#include <media/soc_mediabus.h>
1719 #include <media/v4l2-subdev.h>
1820 #include <media/v4l2-chip-ident.h>
19−#include <media/soc_camera.h>
21+#include <media/v4l2-ctrls.h>
2022
2123 /*
2224 * mt9v022 i2c address 0x48, 0x4c, 0x58, 0x5c
@@ -100,6 +102,17 @@ static const struct mt9v022_datafmt mt9v022_monochrome_fmts[] = { · 77 unmodified lines
100102
101103 struct mt9v022 {
102104 struct v4l2_subdev subdev;
105+ struct v4l2_ctrl_handler hdl;
106+ struct {
107+ /* exposure/auto-exposure cluster */
108+ struct v4l2_ctrl *autoexposure;
109+ struct v4l2_ctrl *exposure;
110+ };
111+ struct {
112+ /* gain/auto-gain cluster */
113+ struct v4l2_ctrl *autogain;
114+ struct v4l2_ctrl *gain;
115+ };
103116 struct v4l2_rect rect; /* Sensor window */
104117 const struct mt9v022_datafmt *fmt;
105118 const struct mt9v022_datafmt *fmts;
@@ -178,6 +191,8 @@ static int mt9v022_init(struct i2c_client *client) · 72 unmodified lines
178191 ret = reg_clear(client, MT9V022_BLACK_LEVEL_CALIB_CTRL, 1);
179192 if (!ret)
180193 ret = reg_write(client, MT9V022_DIGITAL_TEST_PATTERN, 0);
194+ if (!ret)
195+ return v4l2_ctrl_handler_setup(&mt9v022->hdl);
181196
182197 return ret;
183198 }
@@ -199,78 +214,6 @@ static int mt9v022_s_stream(struct v4l2_subdev *sd, int enable) · 15 unmodified lines
199214 return 0;
200215 }
201216
202−static int mt9v022_set_bus_param(struct soc_camera_device *icd,
203− unsigned long flags)
204−{
205− struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
206− struct mt9v022 *mt9v022 = to_mt9v022(client);
207− struct soc_camera_link *icl = to_soc_camera_link(icd);
208− unsigned int width_flag = flags & SOCAM_DATAWIDTH_MASK;
209− int ret;
210− u16 pixclk = 0;
211−
212− /* Only one width bit may be set */
213− if (!is_power_of_2(width_flag))
214− return -EINVAL;
215−
216− if (icl->set_bus_param) {
217− ret = icl->set_bus_param(icl, width_flag);
218− if (ret)
219− return ret;
220− } else {
221− /*
222− * Without board specific bus width settings we only support the
223− * sensors native bus width
224− */
225− if (width_flag != SOCAM_DATAWIDTH_10)
226− return -EINVAL;
227− }
228−
229− flags = soc_camera_apply_sensor_flags(icl, flags);
230−
231− if (flags & SOCAM_PCLK_SAMPLE_FALLING)
232− pixclk |= 0x10;
233−
234− if (!(flags & SOCAM_HSYNC_ACTIVE_HIGH))
235− pixclk |= 0x1;
236−
237− if (!(flags & SOCAM_VSYNC_ACTIVE_HIGH))
238− pixclk |= 0x2;
239−
240− ret = reg_write(client, MT9V022_PIXCLK_FV_LV, pixclk);
241− if (ret < 0)
242− return ret;
243−
244− if (!(flags & SOCAM_MASTER))
245− mt9v022->chip_control &= ~0x8;
246−
247− ret = reg_write(client, MT9V022_CHIP_CONTROL, mt9v022->chip_control);
248− if (ret < 0)
249− return ret;
250−
251− dev_dbg(&client->dev, "Calculated pixclk 0x%x, chip control 0x%x\n",
252− pixclk, mt9v022->chip_control);
253−
254− return 0;
255−}
256−
257−static unsigned long mt9v022_query_bus_param(struct soc_camera_device *icd)
258−{
259− struct soc_camera_link *icl = to_soc_camera_link(icd);
260− unsigned int flags = SOCAM_MASTER | SOCAM_SLAVE |
261− SOCAM_PCLK_SAMPLE_RISING | SOCAM_PCLK_SAMPLE_FALLING |
262− SOCAM_HSYNC_ACTIVE_HIGH | SOCAM_HSYNC_ACTIVE_LOW |
263− SOCAM_VSYNC_ACTIVE_HIGH | SOCAM_VSYNC_ACTIVE_LOW |
264− SOCAM_DATA_ACTIVE_HIGH;
265−
266− if (icl->query_bus_param)
267− flags |= icl->query_bus_param(icl) & SOCAM_DATAWIDTH_MASK;
268− else
269− flags |= SOCAM_DATAWIDTH_10;
270−
271− return soc_camera_apply_sensor_flags(icl, flags);
272−}
273−
274217 static int mt9v022_s_crop(struct v4l2_subdev *sd, struct v4l2_crop *a)
275218 {
276219 struct i2c_client *client = v4l2_get_subdevdata(sd);
@@ -389,7 +332,7 @@ static int mt9v022_s_fmt(struct v4l2_subdev *sd, · 112 unmodified lines
389332
390333 /*
391334 * The caller provides a supported format, as verified per call to
392− * icd->try_fmt(), datawidth is from our supported format list
335+ * .try_mbus_fmt(), datawidth is from our supported format list
393336 */
394337 switch (mf->code) {
395338 case V4L2_MBUS_FMT_Y8_1X8:
@@ -502,236 +445,131 @@ static int mt9v022_s_register(struct v4l2_subdev *sd, · 106 unmodified lines
502445 }
503446 #endif
504447
505−static const struct v4l2_queryctrl mt9v022_controls[] = {
506− {
507− .id = V4L2_CID_VFLIP,
508− .type = V4L2_CTRL_TYPE_BOOLEAN,
509− .name = "Flip Vertically",
510− .minimum = 0,
511− .maximum = 1,
512− .step = 1,
513− .default_value = 0,
514− }, {
515− .id = V4L2_CID_HFLIP,
516− .type = V4L2_CTRL_TYPE_BOOLEAN,
517− .name = "Flip Horizontally",
518− .minimum = 0,
519− .maximum = 1,
520− .step = 1,
521− .default_value = 0,
522− }, {
523− .id = V4L2_CID_GAIN,
524− .type = V4L2_CTRL_TYPE_INTEGER,
525− .name = "Analog Gain",
526− .minimum = 64,
527− .maximum = 127,
528− .step = 1,
529− .default_value = 64,
530− .flags = V4L2_CTRL_FLAG_SLIDER,
531− }, {
532− .id = V4L2_CID_EXPOSURE,
533− .type = V4L2_CTRL_TYPE_INTEGER,
534− .name = "Exposure",
535− .minimum = 1,
536− .maximum = 255,
537− .step = 1,
538− .default_value = 255,
539− .flags = V4L2_CTRL_FLAG_SLIDER,
540− }, {
541− .id = V4L2_CID_AUTOGAIN,
542− .type = V4L2_CTRL_TYPE_BOOLEAN,
543− .name = "Automatic Gain",
544− .minimum = 0,
545− .maximum = 1,
546− .step = 1,
547− .default_value = 1,
548− }, {
549− .id = V4L2_CID_EXPOSURE_AUTO,
550− .type = V4L2_CTRL_TYPE_BOOLEAN,
551− .name = "Automatic Exposure",
552− .minimum = 0,
553− .maximum = 1,
554− .step = 1,
555− .default_value = 1,
556− }
557−};
558−
559−static struct soc_camera_ops mt9v022_ops = {
560− .set_bus_param = mt9v022_set_bus_param,
561− .query_bus_param = mt9v022_query_bus_param,
562− .controls = mt9v022_controls,
563− .num_controls = ARRAY_SIZE(mt9v022_controls),
564−};
565−
566−static int mt9v022_g_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
448+static int mt9v022_g_volatile_ctrl(struct v4l2_ctrl *ctrl)
567449 {
450+ struct mt9v022 *mt9v022 = container_of(ctrl->handler,
451+ struct mt9v022, hdl);
452+ struct v4l2_subdev *sd = &mt9v022->subdev;
568453 struct i2c_client *client = v4l2_get_subdevdata(sd);
569− const struct v4l2_queryctrl *qctrl;
454+ struct v4l2_ctrl *gain = mt9v022->gain;
455+ struct v4l2_ctrl *exp = mt9v022->exposure;
570456 unsigned long range;
571457 int data;
572458
573− qctrl = soc_camera_find_qctrl(&mt9v022_ops, ctrl->id);
574−
575459 switch (ctrl->id) {
576− case V4L2_CID_VFLIP:
577− data = reg_read(client, MT9V022_READ_MODE);
578− if (data < 0)
579− return -EIO;
580− ctrl->value = !!(data & 0x10);
581− break;
582− case V4L2_CID_HFLIP:
583− data = reg_read(client, MT9V022_READ_MODE);
584− if (data < 0)
585− return -EIO;
586− ctrl->value = !!(data & 0x20);
587− break;
588− case V4L2_CID_EXPOSURE_AUTO:
589− data = reg_read(client, MT9V022_AEC_AGC_ENABLE);
590− if (data < 0)
591− return -EIO;
592− ctrl->value = !!(data & 0x1);
593− break;
594460 case V4L2_CID_AUTOGAIN:
595− data = reg_read(client, MT9V022_AEC_AGC_ENABLE);
596− if (data < 0)
597− return -EIO;
598− ctrl->value = !!(data & 0x2);
599− break;
600− case V4L2_CID_GAIN:
601461 data = reg_read(client, MT9V022_ANALOG_GAIN);
602462 if (data < 0)
603463 return -EIO;
604464
605− range = qctrl->maximum - qctrl->minimum;
606− ctrl->value = ((data - 16) * range + 24) / 48 + qctrl->minimum;
607−
608− break;
609− case V4L2_CID_EXPOSURE:
465+ range = gain->maximum - gain->minimum;
466+ gain->val = ((data - 16) * range + 24) / 48 + gain->minimum;
467+ return 0;
468+ case V4L2_CID_EXPOSURE_AUTO:
610469 data = reg_read(client, MT9V022_TOTAL_SHUTTER_WIDTH);
611470 if (data < 0)
612471 return -EIO;
613472
614− range = qctrl->maximum - qctrl->minimum;
615− ctrl->value = ((data - 1) * range + 239) / 479 + qctrl->minimum;
616−
617− break;
473+ range = exp->maximum - exp->minimum;
474+ exp->val = ((data - 1) * range + 239) / 479 + exp->minimum;
475+ return 0;
618476 }
619− return 0;
477+ return -EINVAL;
620478 }
621479
622−static int mt9v022_s_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
480+static int mt9v022_s_ctrl(struct v4l2_ctrl *ctrl)
623481 {
624− int data;
482+ struct mt9v022 *mt9v022 = container_of(ctrl->handler,
483+ struct mt9v022, hdl);
484+ struct v4l2_subdev *sd = &mt9v022->subdev;
625485 struct i2c_client *client = v4l2_get_subdevdata(sd);
626− const struct v4l2_queryctrl *qctrl;
627−
628− qctrl = soc_camera_find_qctrl(&mt9v022_ops, ctrl->id);
629− if (!qctrl)
630− return -EINVAL;
486+ int data;
631487
632488 switch (ctrl->id) {
633489 case V4L2_CID_VFLIP:
634− if (ctrl->value)
490+ if (ctrl->val)
635491 data = reg_set(client, MT9V022_READ_MODE, 0x10);
636492 else
637493 data = reg_clear(client, MT9V022_READ_MODE, 0x10);
638494 if (data < 0)
639495 return -EIO;
640− break;
496+ return 0;
641497 case V4L2_CID_HFLIP:
642− if (ctrl->value)
498+ if (ctrl->val)
643499 data = reg_set(client, MT9V022_READ_MODE, 0x20);
644500 else
645501 data = reg_clear(client, MT9V022_READ_MODE, 0x20);
646502 if (data < 0)
647503 return -EIO;
648− break;
649− case V4L2_CID_GAIN:
650− /* mt9v022 has minimum == default */
651− if (ctrl->value > qctrl->maximum || ctrl->value < qctrl->minimum)
652− return -EINVAL;
653− else {
654− unsigned long range = qctrl->maximum - qctrl->minimum;
504+ return 0;
505+ case V4L2_CID_AUTOGAIN:
506+ if (ctrl->val) {
507+ if (reg_set(client, MT9V022_AEC_AGC_ENABLE, 0x2) < 0)
508+ return -EIO;
509+ } else {
510+ struct v4l2_ctrl *gain = mt9v022->gain;
511+ /* mt9v022 has minimum == default */
512+ unsigned long range = gain->maximum - gain->minimum;
655513 /* Valid values 16 to 64, 32 to 64 must be even. */
656− unsigned long gain = ((ctrl->value - qctrl->minimum) *
514+ unsigned long gain_val = ((gain->val - gain->minimum) *
657515 48 + range / 2) / range + 16;
658− if (gain >= 32)
659− gain &= ~1;
516+
517+ if (gain_val >= 32)
518+ gain_val &= ~1;
519+
660520 /*
661521 * The user wants to set gain manually, hope, she
662522 * knows, what she's doing... Switch AGC off.
663523 */
664−
665524 if (reg_clear(client, MT9V022_AEC_AGC_ENABLE, 0x2) < 0)
666525 return -EIO;
667526
668527 dev_dbg(&client->dev, "Setting gain from %d to %lu\n",
669− reg_read(client, MT9V022_ANALOG_GAIN), gain);
670− if (reg_write(client, MT9V022_ANALOG_GAIN, gain) < 0)
528+ reg_read(client, MT9V022_ANALOG_GAIN), gain_val);
529+ if (reg_write(client, MT9V022_ANALOG_GAIN, gain_val) < 0)
671530 return -EIO;
672531 }
673− break;
674− case V4L2_CID_EXPOSURE:
675− /* mt9v022 has maximum == default */
676− if (ctrl->value > qctrl->maximum || ctrl->value < qctrl->minimum)
677− return -EINVAL;
678− else {
679− unsigned long range = qctrl->maximum - qctrl->minimum;
680− unsigned long shutter = ((ctrl->value - qctrl->minimum) *
681− 479 + range / 2) / range + 1;
532+ return 0;
533+ case V4L2_CID_EXPOSURE_AUTO:
534+ if (ctrl->val == V4L2_EXPOSURE_AUTO) {
535+ data = reg_set(client, MT9V022_AEC_AGC_ENABLE, 0x1);
536+ } else {
537+ struct v4l2_ctrl *exp = mt9v022->exposure;
538+ unsigned long range = exp->maximum - exp->minimum;
539+ unsigned long shutter = ((exp->val - exp->minimum) *
540+ 479 + range / 2) / range + 1;
541+
682542 /*
683543 * The user wants to set shutter width manually, hope,
684544 * she knows, what she's doing... Switch AEC off.
685545 */
686−
687− if (reg_clear(client, MT9V022_AEC_AGC_ENABLE, 0x1) < 0)
546+ data = reg_clear(client, MT9V022_AEC_AGC_ENABLE, 0x1);
547+ if (data < 0)
688548 return -EIO;
689−
690549 dev_dbg(&client->dev, "Shutter width from %d to %lu\n",
691− reg_read(client, MT9V022_TOTAL_SHUTTER_WIDTH),
692− shutter);
550+ reg_read(client, MT9V022_TOTAL_SHUTTER_WIDTH),
551+ shutter);
693552 if (reg_write(client, MT9V022_TOTAL_SHUTTER_WIDTH,
694− shutter) < 0)
553+ shutter) < 0)
695554 return -EIO;
696555 }
697− break;
698− case V4L2_CID_AUTOGAIN:
699− if (ctrl->value)
700− data = reg_set(client, MT9V022_AEC_AGC_ENABLE, 0x2);
701− else
702− data = reg_clear(client, MT9V022_AEC_AGC_ENABLE, 0x2);
703− if (data < 0)
704− return -EIO;
705− break;
706− case V4L2_CID_EXPOSURE_AUTO:
707− if (ctrl->value)
708− data = reg_set(client, MT9V022_AEC_AGC_ENABLE, 0x1);
709− else
710− data = reg_clear(client, MT9V022_AEC_AGC_ENABLE, 0x1);
711− if (data < 0)
712− return -EIO;
713− break;
556+ return 0;
714557 }
715− return 0;
558+ return -EINVAL;
716559 }
717560
718561 /*
719562 * Interface active, can use i2c. If it fails, it can indeed mean, that
720563 * this wasn't our capture interface, so, we wait for the right one
721564 */
722−static int mt9v022_video_probe(struct soc_camera_device *icd,
723− struct i2c_client *client)
565+static int mt9v022_video_probe(struct i2c_client *client)
724566 {
725567 struct mt9v022 *mt9v022 = to_mt9v022(client);
726− struct soc_camera_link *icl = to_soc_camera_link(icd);
568+ struct soc_camera_link *icl = soc_camera_i2c_to_link(client);
727569 s32 data;
728570 int ret;
729571 unsigned long flags;
730572
731− /* We must have a parent by now. And it cannot be a wrong one. */
732− BUG_ON(!icd->parent ||
733− to_soc_camera_host(icd->parent)->nr != icd->iface);
734−
735573 /* Read out the chip version register */
736574 data = reg_read(client, MT9V022_CHIP_VERSION);
737575
@@ -805,16 +643,6 @@ ei2c: · 67 unmodified lines
805643 return ret;
806644 }
807645
808−static void mt9v022_video_remove(struct soc_camera_device *icd)
809−{
810− struct soc_camera_link *icl = to_soc_camera_link(icd);
811−
812− dev_dbg(icd->pdev, "Video removed: %p, %p\n",
813− icd->parent, icd->vdev);
814− if (icl->free_bus)
815− icl->free_bus(icl);
816−}
817−
818646 static int mt9v022_g_skip_top_lines(struct v4l2_subdev *sd, u32 *lines)
819647 {
820648 struct i2c_client *client = v4l2_get_subdevdata(sd);
@@ -825,9 +653,12 @@ static int mt9v022_g_skip_top_lines(struct v4l2_subdev *sd, u32 *lines) · 4 unmodified lines
825653 return 0;
826654 }
827655
656+static const struct v4l2_ctrl_ops mt9v022_ctrl_ops = {
657+ .g_volatile_ctrl = mt9v022_g_volatile_ctrl,
658+ .s_ctrl = mt9v022_s_ctrl,
659+};
660+
828661 static struct v4l2_subdev_core_ops mt9v022_subdev_core_ops = {
829− .g_ctrl = mt9v022_g_ctrl,
830− .s_ctrl = mt9v022_s_ctrl,
831662 .g_chip_ident = mt9v022_g_chip_ident,
832663 #ifdef CONFIG_VIDEO_ADV_DEBUG
833664 .g_register = mt9v022_g_register,
@@ -848,6 +679,72 @@ static int mt9v022_enum_fmt(struct v4l2_subdev *sd, unsigned int index, · 14 unmodified lines
848679 return 0;
849680 }
850681
682+static int mt9v022_g_mbus_config(struct v4l2_subdev *sd,
683+ struct v4l2_mbus_config *cfg)
684+{
685+ struct i2c_client *client = v4l2_get_subdevdata(sd);
686+ struct soc_camera_link *icl = soc_camera_i2c_to_link(client);
687+
688+ cfg->flags = V4L2_MBUS_MASTER | V4L2_MBUS_SLAVE |
689+ V4L2_MBUS_PCLK_SAMPLE_RISING | V4L2_MBUS_PCLK_SAMPLE_FALLING |
690+ V4L2_MBUS_HSYNC_ACTIVE_HIGH | V4L2_MBUS_HSYNC_ACTIVE_LOW |
691+ V4L2_MBUS_VSYNC_ACTIVE_HIGH | V4L2_MBUS_VSYNC_ACTIVE_LOW |
692+ V4L2_MBUS_DATA_ACTIVE_HIGH;
693+ cfg->type = V4L2_MBUS_PARALLEL;
694+ cfg->flags = soc_camera_apply_board_flags(icl, cfg);
695+
696+ return 0;
697+}
698+
699+static int mt9v022_s_mbus_config(struct v4l2_subdev *sd,
700+ const struct v4l2_mbus_config *cfg)
701+{
702+ struct i2c_client *client = v4l2_get_subdevdata(sd);
703+ struct soc_camera_link *icl = soc_camera_i2c_to_link(client);
704+ struct mt9v022 *mt9v022 = to_mt9v022(client);
705+ unsigned long flags = soc_camera_apply_board_flags(icl, cfg);
706+ unsigned int bps = soc_mbus_get_fmtdesc(mt9v022->fmt->code)->bits_per_sample;
707+ int ret;
708+ u16 pixclk = 0;
709+
710+ if (icl->set_bus_param) {
711+ ret = icl->set_bus_param(icl, 1 << (bps - 1));
712+ if (ret)
713+ return ret;
714+ } else if (bps != 10) {
715+ /*
716+ * Without board specific bus width settings we only support the
717+ * sensors native bus width
718+ */
719+ return -EINVAL;
720+ }
721+
722+ if (flags & V4L2_MBUS_PCLK_SAMPLE_FALLING)
723+ pixclk |= 0x10;
724+
725+ if (!(flags & V4L2_MBUS_HSYNC_ACTIVE_HIGH))
726+ pixclk |= 0x1;
727+
728+ if (!(flags & V4L2_MBUS_VSYNC_ACTIVE_HIGH))
729+ pixclk |= 0x2;
730+
731+ ret = reg_write(client, MT9V022_PIXCLK_FV_LV, pixclk);
732+ if (ret < 0)
733+ return ret;
734+
735+ if (!(flags & V4L2_MBUS_MASTER))
736+ mt9v022->chip_control &= ~0x8;
737+
738+ ret = reg_write(client, MT9V022_CHIP_CONTROL, mt9v022->chip_control);
739+ if (ret < 0)
740+ return ret;
741+
742+ dev_dbg(&client->dev, "Calculated pixclk 0x%x, chip control 0x%x\n",
743+ pixclk, mt9v022->chip_control);
744+
745+ return 0;
746+}
747+
851748 static struct v4l2_subdev_video_ops mt9v022_subdev_video_ops = {
852749 .s_stream = mt9v022_s_stream,
853750 .s_mbus_fmt = mt9v022_s_fmt,
@@ -857,6 +754,8 @@ static struct v4l2_subdev_video_ops mt9v022_subdev_video_ops = { · 3 unmodified lines
857754 .g_crop = mt9v022_g_crop,
858755 .cropcap = mt9v022_cropcap,
859756 .enum_mbus_fmt = mt9v022_enum_fmt,
757+ .g_mbus_config = mt9v022_g_mbus_config,
758+ .s_mbus_config = mt9v022_s_mbus_config,
860759 };
861760
862761 static struct v4l2_subdev_sensor_ops mt9v022_subdev_sensor_ops = {
@@ -873,17 +772,10 @@ static int mt9v022_probe(struct i2c_client *client, · 10 unmodified lines
873772 const struct i2c_device_id *did)
874773 {
875774 struct mt9v022 *mt9v022;
876− struct soc_camera_device *icd = client->dev.platform_data;
775+ struct soc_camera_link *icl = soc_camera_i2c_to_link(client);
877776 struct i2c_adapter *adapter = to_i2c_adapter(client->dev.parent);
878− struct soc_camera_link *icl;
879777 int ret;
880778
881− if (!icd) {
882− dev_err(&client->dev, "MT9V022: missing soc-camera data!\n");
883− return -EINVAL;
884− }
885−
886− icl = to_soc_camera_link(icd);
887779 if (!icl) {
888780 dev_err(&client->dev, "MT9V022 driver needs platform data\n");
889781 return -EINVAL;
@@ -900,10 +792,39 @@ static int mt9v022_probe(struct i2c_client *client, · 10 unmodified lines
900792 return -ENOMEM;
901793
902794 v4l2_i2c_subdev_init(&mt9v022->subdev, client, &mt9v022_subdev_ops);
795+ v4l2_ctrl_handler_init(&mt9v022->hdl, 6);
796+ v4l2_ctrl_new_std(&mt9v022->hdl, &mt9v022_ctrl_ops,
797+ V4L2_CID_VFLIP, 0, 1, 1, 0);
798+ v4l2_ctrl_new_std(&mt9v022->hdl, &mt9v022_ctrl_ops,
799+ V4L2_CID_HFLIP, 0, 1, 1, 0);
800+ mt9v022->autogain = v4l2_ctrl_new_std(&mt9v022->hdl, &mt9v022_ctrl_ops,
801+ V4L2_CID_AUTOGAIN, 0, 1, 1, 1);
802+ mt9v022->gain = v4l2_ctrl_new_std(&mt9v022->hdl, &mt9v022_ctrl_ops,
803+ V4L2_CID_GAIN, 0, 127, 1, 64);
804+
805+ /*
806+ * Simulated autoexposure. If enabled, we calculate shutter width
807+ * ourselves in the driver based on vertical blanking and frame width
808+ */
809+ mt9v022->autoexposure = v4l2_ctrl_new_std_menu(&mt9v022->hdl,
810+ &mt9v022_ctrl_ops, V4L2_CID_EXPOSURE_AUTO, 1, 0,
811+ V4L2_EXPOSURE_AUTO);
812+ mt9v022->exposure = v4l2_ctrl_new_std(&mt9v022->hdl, &mt9v022_ctrl_ops,
813+ V4L2_CID_EXPOSURE, 1, 255, 1, 255);
814+
815+ mt9v022->subdev.ctrl_handler = &mt9v022->hdl;
816+ if (mt9v022->hdl.error) {
817+ int err = mt9v022->hdl.error;
818+
819+ kfree(mt9v022);
820+ return err;
821+ }
822+ v4l2_ctrl_auto_cluster(2, &mt9v022->autoexposure,
823+ V4L2_EXPOSURE_MANUAL, true);
824+ v4l2_ctrl_auto_cluster(2, &mt9v022->autogain, 0, true);
903825
904826 mt9v022->chip_control = MT9V022_CHIP_CONTROL_DEFAULT;
905827
906− icd->ops = &mt9v022_ops;
907828 /*
908829 * MT9V022 _really_ corrupts the first read out line.
909830 * TODO: verify on i.MX31
@@ -914,9 +835,9 @@ static int mt9v022_probe(struct i2c_client *client, · 4 unmodified lines
914835 mt9v022->rect.width = MT9V022_MAX_WIDTH;
915836 mt9v022->rect.height = MT9V022_MAX_HEIGHT;
916837
917− ret = mt9v022_video_probe(icd, client);
838+ ret = mt9v022_video_probe(client);
918839 if (ret) {
919− icd->ops = NULL;
840+ v4l2_ctrl_handler_free(&mt9v022->hdl);
920841 kfree(mt9v022);
921842 }
922843
@@ -926,10 +847,12 @@ static int mt9v022_probe(struct i2c_client *client, · 3 unmodified lines
926847 static int mt9v022_remove(struct i2c_client *client)
927848 {
928849 struct mt9v022 *mt9v022 = to_mt9v022(client);
929− struct soc_camera_device *icd = client->dev.platform_data;
850+ struct soc_camera_link *icl = soc_camera_i2c_to_link(client);
930851
931− icd->ops = NULL;
932− mt9v022_video_remove(icd);
852+ v4l2_device_unregister_subdev(&mt9v022->subdev);
853+ if (icl->free_bus)
854+ icl->free_bus(icl);
855+ v4l2_ctrl_handler_free(&mt9v022->hdl);
933856 kfree(mt9v022);
934857
935858 return 0;
drivers/media/video/mx1_camera.c+42−29
@@ -78,11 +78,10 @@ · 77 unmodified lines
7878 #define CSI_IRQ_MASK (CSISR_SFF_OR_INT | CSISR_RFF_OR_INT | \
7979 CSISR_STATFF_INT | CSISR_RXFF_INT | CSISR_SOF_INT)
8080
81−#define CSI_BUS_FLAGS (SOCAM_MASTER | SOCAM_HSYNC_ACTIVE_HIGH | \
82− SOCAM_VSYNC_ACTIVE_HIGH | SOCAM_VSYNC_ACTIVE_LOW | \
83− SOCAM_PCLK_SAMPLE_RISING | SOCAM_PCLK_SAMPLE_FALLING | \
84− SOCAM_DATA_ACTIVE_HIGH | SOCAM_DATA_ACTIVE_LOW | \
85− SOCAM_DATAWIDTH_8)
81+#define CSI_BUS_FLAGS (V4L2_MBUS_MASTER | V4L2_MBUS_HSYNC_ACTIVE_HIGH | \
82+ V4L2_MBUS_VSYNC_ACTIVE_HIGH | V4L2_MBUS_VSYNC_ACTIVE_LOW | \
83+ V4L2_MBUS_PCLK_SAMPLE_RISING | V4L2_MBUS_PCLK_SAMPLE_FALLING | \
84+ V4L2_MBUS_DATA_ACTIVE_HIGH | V4L2_MBUS_DATA_ACTIVE_LOW)
8685
8786 #define MAX_VIDEO_MEM 16 /* Video memory limit in megabytes */
8887
@@ -490,59 +489,73 @@ static int mx1_camera_set_crop(struct soc_camera_device *icd, · 401 unmodified lines
490489
491490 static int mx1_camera_set_bus_param(struct soc_camera_device *icd, __u32 pixfmt)
492491 {
492+ struct v4l2_subdev *sd = soc_camera_to_subdev(icd);
493493 struct soc_camera_host *ici = to_soc_camera_host(icd->parent);
494494 struct mx1_camera_dev *pcdev = ici->priv;
495− unsigned long camera_flags, common_flags;
495+ struct v4l2_mbus_config cfg = {.type = V4L2_MBUS_PARALLEL,};
496+ unsigned long common_flags;
496497 unsigned int csicr1;
497498 int ret;
498499
499− camera_flags = icd->ops->query_bus_param(icd);
500−
501500 /* MX1 supports only 8bit buswidth */
502− common_flags = soc_camera_bus_param_compatible(camera_flags,
503− CSI_BUS_FLAGS);
504− if (!common_flags)
505− return -EINVAL;
501+ ret = v4l2_subdev_call(sd, video, g_mbus_config, &cfg);
502+ if (!ret) {
503+ common_flags = soc_mbus_config_compatible(&cfg, CSI_BUS_FLAGS);
504+ if (!common_flags) {
505+ dev_warn(icd->parent,
506+ "Flags incompatible: camera 0x%x, host 0x%x\n",
507+ cfg.flags, CSI_BUS_FLAGS);
508+ return -EINVAL;
509+ }
510+ } else if (ret != -ENOIOCTLCMD) {
511+ return ret;
512+ } else {
513+ common_flags = CSI_BUS_FLAGS;
514+ }
506515
507516 /* Make choises, based on platform choice */
508− if ((common_flags & SOCAM_VSYNC_ACTIVE_HIGH) &&
509− (common_flags & SOCAM_VSYNC_ACTIVE_LOW)) {
517+ if ((common_flags & V4L2_MBUS_VSYNC_ACTIVE_HIGH) &&
518+ (common_flags & V4L2_MBUS_VSYNC_ACTIVE_LOW)) {
510519 if (!pcdev->pdata ||
511520 pcdev->pdata->flags & MX1_CAMERA_VSYNC_HIGH)
512− common_flags &= ~SOCAM_VSYNC_ACTIVE_LOW;
521+ common_flags &= ~V4L2_MBUS_VSYNC_ACTIVE_LOW;
513522 else
514− common_flags &= ~SOCAM_VSYNC_ACTIVE_HIGH;
523+ common_flags &= ~V4L2_MBUS_VSYNC_ACTIVE_HIGH;
515524 }
516525
517− if ((common_flags & SOCAM_PCLK_SAMPLE_RISING) &&
518− (common_flags & SOCAM_PCLK_SAMPLE_FALLING)) {
526+ if ((common_flags & V4L2_MBUS_PCLK_SAMPLE_RISING) &&
527+ (common_flags & V4L2_MBUS_PCLK_SAMPLE_FALLING)) {
519528 if (!pcdev->pdata ||
520529 pcdev->pdata->flags & MX1_CAMERA_PCLK_RISING)
521− common_flags &= ~SOCAM_PCLK_SAMPLE_FALLING;
530+ common_flags &= ~V4L2_MBUS_PCLK_SAMPLE_FALLING;
522531 else
523− common_flags &= ~SOCAM_PCLK_SAMPLE_RISING;
532+ common_flags &= ~V4L2_MBUS_PCLK_SAMPLE_RISING;
524533 }
525534
526− if ((common_flags & SOCAM_DATA_ACTIVE_HIGH) &&
527− (common_flags & SOCAM_DATA_ACTIVE_LOW)) {
535+ if ((common_flags & V4L2_MBUS_DATA_ACTIVE_HIGH) &&
536+ (common_flags & V4L2_MBUS_DATA_ACTIVE_LOW)) {
528537 if (!pcdev->pdata ||
529538 pcdev->pdata->flags & MX1_CAMERA_DATA_HIGH)
530− common_flags &= ~SOCAM_DATA_ACTIVE_LOW;
539+ common_flags &= ~V4L2_MBUS_DATA_ACTIVE_LOW;
531540 else
532− common_flags &= ~SOCAM_DATA_ACTIVE_HIGH;
541+ common_flags &= ~V4L2_MBUS_DATA_ACTIVE_HIGH;
533542 }
534543
535− ret = icd->ops->set_bus_param(icd, common_flags);
536− if (ret < 0)
544+ cfg.flags = common_flags;
545+ ret = v4l2_subdev_call(sd, video, s_mbus_config, &cfg);
546+ if (ret < 0 && ret != -ENOIOCTLCMD) {
547+ dev_dbg(icd->parent, "camera s_mbus_config(0x%lx) returned %d\n",
548+ common_flags, ret);
537549 return ret;
550+ }
538551
539552 csicr1 = __raw_readl(pcdev->base + CSICR1);
540553
541− if (common_flags & SOCAM_PCLK_SAMPLE_RISING)
554+ if (common_flags & V4L2_MBUS_PCLK_SAMPLE_RISING)
542555 csicr1 |= CSICR1_REDGE;
543− if (common_flags & SOCAM_VSYNC_ACTIVE_HIGH)
556+ if (common_flags & V4L2_MBUS_VSYNC_ACTIVE_HIGH)
544557 csicr1 |= CSICR1_SOF_POL;
545− if (common_flags & SOCAM_DATA_ACTIVE_LOW)
558+ if (common_flags & V4L2_MBUS_DATA_ACTIVE_LOW)
546559 csicr1 |= CSICR1_DATA_POL;
547560
548561 __raw_writel(csicr1, pcdev->base + CSICR1);
drivers/media/video/mx2_camera.c+45−33
@@ -686,16 +686,15 @@ static void mx2_camera_init_videobuf(struct videobuf_queue *q, · 685 unmodified lines
686686 icd, &icd->video_lock);
687687 }
688688
689−#define MX2_BUS_FLAGS (SOCAM_DATAWIDTH_8 | \
690− SOCAM_MASTER | \
691− SOCAM_VSYNC_ACTIVE_HIGH | \
692− SOCAM_VSYNC_ACTIVE_LOW | \
693− SOCAM_HSYNC_ACTIVE_HIGH | \
694− SOCAM_HSYNC_ACTIVE_LOW | \
695− SOCAM_PCLK_SAMPLE_RISING | \
696− SOCAM_PCLK_SAMPLE_FALLING | \
697− SOCAM_DATA_ACTIVE_HIGH | \
698− SOCAM_DATA_ACTIVE_LOW)
689+#define MX2_BUS_FLAGS (V4L2_MBUS_MASTER | \
690+ V4L2_MBUS_VSYNC_ACTIVE_HIGH | \
691+ V4L2_MBUS_VSYNC_ACTIVE_LOW | \
692+ V4L2_MBUS_HSYNC_ACTIVE_HIGH | \
693+ V4L2_MBUS_HSYNC_ACTIVE_LOW | \
694+ V4L2_MBUS_PCLK_SAMPLE_RISING | \
695+ V4L2_MBUS_PCLK_SAMPLE_FALLING | \
696+ V4L2_MBUS_DATA_ACTIVE_HIGH | \
697+ V4L2_MBUS_DATA_ACTIVE_LOW)
699698
700699 static int mx27_camera_emma_prp_reset(struct mx2_camera_dev *pcdev)
701700 {
@@ -770,46 +769,59 @@ static void mx27_camera_emma_buf_init(struct soc_camera_device *icd, · 68 unmodified lines
770769 static int mx2_camera_set_bus_param(struct soc_camera_device *icd,
771770 __u32 pixfmt)
772771 {
773− struct soc_camera_host *ici =
774− to_soc_camera_host(icd->parent);
772+ struct v4l2_subdev *sd = soc_camera_to_subdev(icd);
773+ struct soc_camera_host *ici = to_soc_camera_host(icd->parent);
775774 struct mx2_camera_dev *pcdev = ici->priv;
776− unsigned long camera_flags, common_flags;
777− int ret = 0;
775+ struct v4l2_mbus_config cfg = {.type = V4L2_MBUS_PARALLEL,};
776+ unsigned long common_flags;
777+ int ret;
778778 int bytesperline;
779779 u32 csicr1 = pcdev->csicr1;
780780
781− camera_flags = icd->ops->query_bus_param(icd);
782−
783− common_flags = soc_camera_bus_param_compatible(camera_flags,
784− MX2_BUS_FLAGS);
785− if (!common_flags)
786− return -EINVAL;
781+ ret = v4l2_subdev_call(sd, video, g_mbus_config, &cfg);
782+ if (!ret) {
783+ common_flags = soc_mbus_config_compatible(&cfg, MX2_BUS_FLAGS);
784+ if (!common_flags) {
785+ dev_warn(icd->parent,
786+ "Flags incompatible: camera 0x%x, host 0x%x\n",
787+ cfg.flags, MX2_BUS_FLAGS);
788+ return -EINVAL;
789+ }
790+ } else if (ret != -ENOIOCTLCMD) {
791+ return ret;
792+ } else {
793+ common_flags = MX2_BUS_FLAGS;
794+ }
787795
788− if ((common_flags & SOCAM_HSYNC_ACTIVE_HIGH) &&
789− (common_flags & SOCAM_HSYNC_ACTIVE_LOW)) {
796+ if ((common_flags & V4L2_MBUS_HSYNC_ACTIVE_HIGH) &&
797+ (common_flags & V4L2_MBUS_HSYNC_ACTIVE_LOW)) {
790798 if (pcdev->platform_flags & MX2_CAMERA_HSYNC_HIGH)
791− common_flags &= ~SOCAM_HSYNC_ACTIVE_LOW;
799+ common_flags &= ~V4L2_MBUS_HSYNC_ACTIVE_LOW;
792800 else
793− common_flags &= ~SOCAM_HSYNC_ACTIVE_HIGH;
801+ common_flags &= ~V4L2_MBUS_HSYNC_ACTIVE_HIGH;
794802 }
795803
796− if ((common_flags & SOCAM_PCLK_SAMPLE_RISING) &&
797− (common_flags & SOCAM_PCLK_SAMPLE_FALLING)) {
804+ if ((common_flags & V4L2_MBUS_PCLK_SAMPLE_RISING) &&
805+ (common_flags & V4L2_MBUS_PCLK_SAMPLE_FALLING)) {
798806 if (pcdev->platform_flags & MX2_CAMERA_PCLK_SAMPLE_RISING)
799− common_flags &= ~SOCAM_PCLK_SAMPLE_FALLING;
807+ common_flags &= ~V4L2_MBUS_PCLK_SAMPLE_FALLING;
800808 else
801− common_flags &= ~SOCAM_PCLK_SAMPLE_RISING;
809+ common_flags &= ~V4L2_MBUS_PCLK_SAMPLE_RISING;
802810 }
803811
804− ret = icd->ops->set_bus_param(icd, common_flags);
805− if (ret < 0)
812+ cfg.flags = common_flags;
813+ ret = v4l2_subdev_call(sd, video, s_mbus_config, &cfg);
814+ if (ret < 0 && ret != -ENOIOCTLCMD) {
815+ dev_dbg(icd->parent, "camera s_mbus_config(0x%lx) returned %d\n",
816+ common_flags, ret);
806817 return ret;
818+ }
807819
808− if (common_flags & SOCAM_PCLK_SAMPLE_RISING)
820+ if (common_flags & V4L2_MBUS_PCLK_SAMPLE_RISING)
809821 csicr1 |= CSICR1_REDGE;
810− if (common_flags & SOCAM_VSYNC_ACTIVE_HIGH)
822+ if (common_flags & V4L2_MBUS_VSYNC_ACTIVE_HIGH)
811823 csicr1 |= CSICR1_SOF_POL;
812− if (common_flags & SOCAM_HSYNC_ACTIVE_HIGH)
824+ if (common_flags & V4L2_MBUS_HSYNC_ACTIVE_HIGH)
813825 csicr1 |= CSICR1_HSYNC_POL;
814826 if (pcdev->platform_flags & MX2_CAMERA_SWAP16)
815827 csicr1 |= CSICR1_SWAP16_EN;
drivers/media/video/mx3_camera.c+175−184
@@ -109,10 +109,12 @@ struct mx3_camera_dev { · 108 unmodified lines
109109
110110 unsigned long platform_flags;
111111 unsigned long mclk;
112+ u16 width_flags; /* max 15 bits */
112113
113114 struct list_head capture;
114115 spinlock_t lock; /* Protects video buffer lists */
115116 struct mx3_camera_buffer *active;
117+ size_t buf_total;
116118 struct vb2_alloc_ctx *alloc_ctx;
117119 enum v4l2_field field;
118120 int sequence;
@@ -190,79 +192,53 @@ static void mx3_cam_dma_done(void *arg) · 71 unmodified lines
190192 * Calculate the __buffer__ (not data) size and number of buffers.
191193 */
192194 static int mx3_videobuf_setup(struct vb2_queue *vq,
195+ const struct v4l2_format *fmt,
193196 unsigned int *count, unsigned int *num_planes,
194197 unsigned int sizes[], void *alloc_ctxs[])
195198 {
196199 struct soc_camera_device *icd = soc_camera_from_vb2q(vq);
197200 struct soc_camera_host *ici = to_soc_camera_host(icd->parent);
198201 struct mx3_camera_dev *mx3_cam = ici->priv;
199− int bytes_per_line = soc_mbus_bytes_per_line(icd->user_width,
200− icd->current_fmt->host_fmt);
201−
202− if (bytes_per_line < 0)
203− return bytes_per_line;
202+ int bytes_per_line;
203+ unsigned int height;
204204
205205 if (!mx3_cam->idmac_channel[0])
206206 return -EINVAL;
207207
208− *num_planes = 1;
209−
210− mx3_cam->sequence = 0;
211− sizes[0] = bytes_per_line * icd->user_height;
212− alloc_ctxs[0] = mx3_cam->alloc_ctx;
213−
214− if (!*count)
215− *count = 32;
216−
217− if (sizes[0] * *count > MAX_VIDEO_MEM * 1024 * 1024)
218− *count = MAX_VIDEO_MEM * 1024 * 1024 / sizes[0];
219−
220− return 0;
221−}
222−
223−static int mx3_videobuf_prepare(struct vb2_buffer *vb)
224−{
225− struct soc_camera_device *icd = soc_camera_from_vb2q(vb->vb2_queue);
226− struct soc_camera_host *ici = to_soc_camera_host(icd->parent);
227− struct mx3_camera_dev *mx3_cam = ici->priv;
228− struct idmac_channel *ichan = mx3_cam->idmac_channel[0];
229− struct scatterlist *sg;
230− struct mx3_camera_buffer *buf;
231− size_t new_size;
232− int bytes_per_line = soc_mbus_bytes_per_line(icd->user_width,
208+ if (fmt) {
209+ const struct soc_camera_format_xlate *xlate = soc_camera_xlate_by_fourcc(icd,
210+ fmt->fmt.pix.pixelformat);
211+ if (!xlate)
212+ return -EINVAL;
213+ bytes_per_line = soc_mbus_bytes_per_line(fmt->fmt.pix.width,
214+ xlate->host_fmt);
215+ height = fmt->fmt.pix.height;
216+ } else {
217+ /* Called from VIDIOC_REQBUFS or in compatibility mode */
218+ bytes_per_line = soc_mbus_bytes_per_line(icd->user_width,
233219 icd->current_fmt->host_fmt);
234−
220+ height = icd->user_height;
221+ }
235222 if (bytes_per_line < 0)
236223 return bytes_per_line;
237224
238− buf = to_mx3_vb(vb);
239− sg = &buf->sg;
240−
241− new_size = bytes_per_line * icd->user_height;
225+ sizes[0] = bytes_per_line * height;
242226
243− if (vb2_plane_size(vb, 0) < new_size) {
244− dev_err(icd->parent, "Buffer too small (%lu < %zu)\n",
245− vb2_plane_size(vb, 0), new_size);
246− return -ENOBUFS;
247− }
227+ alloc_ctxs[0] = mx3_cam->alloc_ctx;
248228
249− if (buf->state == CSI_BUF_NEEDS_INIT) {
250− sg_dma_address(sg) = vb2_dma_contig_plane_dma_addr(vb, 0);
251− sg_dma_len(sg) = new_size;
229+ if (!vq->num_buffers)
230+ mx3_cam->sequence = 0;
252231
253− buf->txd = ichan->dma_chan.device->device_prep_slave_sg(
254− &ichan->dma_chan, sg, 1, DMA_FROM_DEVICE,
255− DMA_PREP_INTERRUPT);
256− if (!buf->txd)
257− return -EIO;
258−
259− buf->txd->callback_param = buf->txd;
260− buf->txd->callback = mx3_cam_dma_done;
232+ if (!*count)
233+ *count = 2;
261234
262− buf->state = CSI_BUF_PREPARED;
263− }
235+ /* If *num_planes != 0, we have already verified *count. */
236+ if (!*num_planes &&
237+ sizes[0] * *count + mx3_cam->buf_total > MAX_VIDEO_MEM * 1024 * 1024)
238+ *count = (MAX_VIDEO_MEM * 1024 * 1024 - mx3_cam->buf_total) /
239+ sizes[0];
264240
265− vb2_set_plane_payload(vb, 0, new_size);
241+ *num_planes = 1;
266242
267243 return 0;
268244 }
@@ -286,28 +262,58 @@ static void mx3_videobuf_queue(struct vb2_buffer *vb) · 17 unmodified lines
286262 struct soc_camera_host *ici = to_soc_camera_host(icd->parent);
287263 struct mx3_camera_dev *mx3_cam = ici->priv;
288264 struct mx3_camera_buffer *buf = to_mx3_vb(vb);
289− struct dma_async_tx_descriptor *txd = buf->txd;
290− struct idmac_channel *ichan = to_idmac_chan(txd->chan);
265+ struct scatterlist *sg = &buf->sg;
266+ struct dma_async_tx_descriptor *txd;
267+ struct idmac_channel *ichan = mx3_cam->idmac_channel[0];
291268 struct idmac_video_param *video = &ichan->params.video;
292− dma_cookie_t cookie;
293− u32 fourcc = icd->current_fmt->host_fmt->fourcc;
269+ const struct soc_mbus_pixelfmt *host_fmt = icd->current_fmt->host_fmt;
270+ int bytes_per_line = soc_mbus_bytes_per_line(icd->user_width, host_fmt);
294271 unsigned long flags;
272+ dma_cookie_t cookie;
273+ size_t new_size;
274+
275+ BUG_ON(bytes_per_line <= 0);
276+
277+ new_size = bytes_per_line * icd->user_height;
278+
279+ if (vb2_plane_size(vb, 0) < new_size) {
280+ dev_err(icd->parent, "Buffer #%d too small (%lu < %zu)\n",
281+ vb->v4l2_buf.index, vb2_plane_size(vb, 0), new_size);
282+ goto error;
283+ }
284+
285+ if (buf->state == CSI_BUF_NEEDS_INIT) {
286+ sg_dma_address(sg) = vb2_dma_contig_plane_dma_addr(vb, 0);
287+ sg_dma_len(sg) = new_size;
288+
289+ txd = ichan->dma_chan.device->device_prep_slave_sg(
290+ &ichan->dma_chan, sg, 1, DMA_FROM_DEVICE,
291+ DMA_PREP_INTERRUPT);
292+ if (!txd)
293+ goto error;
294+
295+ txd->callback_param = txd;
296+ txd->callback = mx3_cam_dma_done;
297+
298+ buf->state = CSI_BUF_PREPARED;
299+ buf->txd = txd;
300+ } else {
301+ txd = buf->txd;
302+ }
303+
304+ vb2_set_plane_payload(vb, 0, new_size);
295305
296306 /* This is the configuration of one sg-element */
297− video->out_pixel_fmt = fourcc_to_ipu_pix(fourcc);
307+ video->out_pixel_fmt = fourcc_to_ipu_pix(host_fmt->fourcc);
298308
299309 if (video->out_pixel_fmt == IPU_PIX_FMT_GENERIC) {
300310 /*
301− * If the IPU DMA channel is configured to transport
302− * generic 8-bit data, we have to set up correctly the
303− * geometry parameters upon the current pixel format.
304− * So, since the DMA horizontal parameters are expressed
305− * in bytes not pixels, convert these in the right unit.
311+ * If the IPU DMA channel is configured to transfer generic
312+ * 8-bit data, we have to set up the geometry parameters
313+ * correctly, according to the current pixel format. The DMA
314+ * horizontal parameters in this case are expressed in bytes,
315+ * not in pixels.
306316 */
307− int bytes_per_line = soc_mbus_bytes_per_line(icd->user_width,
308− icd->current_fmt->host_fmt);
309− BUG_ON(bytes_per_line <= 0);
310−
311317 video->out_width = bytes_per_line;
312318 video->out_height = icd->user_height;
313319 video->out_stride = bytes_per_line;
@@ -351,6 +357,7 @@ static void mx3_videobuf_queue(struct vb2_buffer *vb) · 37 unmodified lines
351357 mx3_cam->active = NULL;
352358
353359 spin_unlock_irqrestore(&mx3_cam->lock, flags);
360+error:
354361 vb2_buffer_done(vb, VB2_BUF_STATE_ERROR);
355362 }
356363
@@ -384,17 +391,24 @@ static void mx3_videobuf_release(struct vb2_buffer *vb) · 27 unmodified lines
384391 }
385392
386393 spin_unlock_irqrestore(&mx3_cam->lock, flags);
394+
395+ mx3_cam->buf_total -= vb2_plane_size(vb, 0);
387396 }
388397
389398 static int mx3_videobuf_init(struct vb2_buffer *vb)
390399 {
400+ struct soc_camera_device *icd = soc_camera_from_vb2q(vb->vb2_queue);
401+ struct soc_camera_host *ici = to_soc_camera_host(icd->parent);
402+ struct mx3_camera_dev *mx3_cam = ici->priv;
391403 struct mx3_camera_buffer *buf = to_mx3_vb(vb);
404+
392405 /* This is for locking debugging only */
393406 INIT_LIST_HEAD(&buf->queue);
394407 sg_init_table(&buf->sg, 1);
395408
396409 buf->state = CSI_BUF_NEEDS_INIT;
397− buf->txd = NULL;
410+
411+ mx3_cam->buf_total += vb2_plane_size(vb, 0);
398412
399413 return 0;
400414 }
@@ -405,13 +419,12 @@ static int mx3_stop_streaming(struct vb2_queue *q) · 4 unmodified lines
405419 struct soc_camera_host *ici = to_soc_camera_host(icd->parent);
406420 struct mx3_camera_dev *mx3_cam = ici->priv;
407421 struct idmac_channel *ichan = mx3_cam->idmac_channel[0];
408− struct dma_chan *chan;
409422 struct mx3_camera_buffer *buf, *tmp;
410423 unsigned long flags;
411424
412425 if (ichan) {
413− chan = &ichan->dma_chan;
414− chan->device->device_control(chan, DMA_TERMINATE_ALL, 0);
426+ struct dma_chan *chan = &ichan->dma_chan;
427+ chan->device->device_control(chan, DMA_PAUSE, 0);
415428 }
416429
417430 spin_lock_irqsave(&mx3_cam->lock, flags);
@@ -419,8 +432,8 @@ static int mx3_stop_streaming(struct vb2_queue *q) · 1 unmodified line
419432 mx3_cam->active = NULL;
420433
421434 list_for_each_entry_safe(buf, tmp, &mx3_cam->capture, queue) {
422− buf->state = CSI_BUF_NEEDS_INIT;
423435 list_del_init(&buf->queue);
436+ vb2_buffer_done(&buf->vb, VB2_BUF_STATE_ERROR);
424437 }
425438
426439 spin_unlock_irqrestore(&mx3_cam->lock, flags);
@@ -430,7 +443,6 @@ static int mx3_stop_streaming(struct vb2_queue *q) · 3 unmodified lines
430443
431444 static struct vb2_ops mx3_videobuf_ops = {
432445 .queue_setup = mx3_videobuf_setup,
433− .buf_prepare = mx3_videobuf_prepare,
434446 .buf_queue = mx3_videobuf_queue,
435447 .buf_cleanup = mx3_videobuf_release,
436448 .buf_init = mx3_videobuf_init,
@@ -514,6 +526,7 @@ static int mx3_camera_add_device(struct soc_camera_device *icd) · 77 unmodified lines
514526
515527 mx3_camera_activate(mx3_cam, icd);
516528
529+ mx3_cam->buf_total = 0;
517530 mx3_cam->icd = icd;
518531
519532 dev_info(icd->parent, "MX3 Camera driver attached to camera %d\n",
@@ -547,59 +560,28 @@ static void mx3_camera_remove_device(struct soc_camera_device *icd) · 27 unmodified lines
547560 static int test_platform_param(struct mx3_camera_dev *mx3_cam,
548561 unsigned char buswidth, unsigned long *flags)
549562 {
563+ /*
564+ * If requested data width is supported by the platform, use it or any
565+ * possible lower value - i.MX31 is smart enough to shift bits
566+ */
567+ if (buswidth > fls(mx3_cam->width_flags))
568+ return -EINVAL;
569+
550570 /*
551571 * Platform specified synchronization and pixel clock polarities are
552572 * only a recommendation and are only used during probing. MX3x
553573 * camera interface only works in master mode, i.e., uses HSYNC and
554574 * VSYNC signals from the sensor
555575 */
556− *flags = SOCAM_MASTER |
557− SOCAM_HSYNC_ACTIVE_HIGH |
558− SOCAM_HSYNC_ACTIVE_LOW |
559− SOCAM_VSYNC_ACTIVE_HIGH |
560− SOCAM_VSYNC_ACTIVE_LOW |
561− SOCAM_PCLK_SAMPLE_RISING |
562− SOCAM_PCLK_SAMPLE_FALLING |
563− SOCAM_DATA_ACTIVE_HIGH |
564− SOCAM_DATA_ACTIVE_LOW;
565−
566− /*
567− * If requested data width is supported by the platform, use it or any
568− * possible lower value - i.MX31 is smart enough to schift bits
569− */
570− if (mx3_cam->platform_flags & MX3_CAMERA_DATAWIDTH_15)
571− *flags |= SOCAM_DATAWIDTH_15 | SOCAM_DATAWIDTH_10 |
572− SOCAM_DATAWIDTH_8 | SOCAM_DATAWIDTH_4;
573− else if (mx3_cam->platform_flags & MX3_CAMERA_DATAWIDTH_10)
574− *flags |= SOCAM_DATAWIDTH_10 | SOCAM_DATAWIDTH_8 |
575− SOCAM_DATAWIDTH_4;
576− else if (mx3_cam->platform_flags & MX3_CAMERA_DATAWIDTH_8)
577− *flags |= SOCAM_DATAWIDTH_8 | SOCAM_DATAWIDTH_4;
578− else if (mx3_cam->platform_flags & MX3_CAMERA_DATAWIDTH_4)
579− *flags |= SOCAM_DATAWIDTH_4;
580−
581− switch (buswidth) {
582− case 15:
583− if (!(*flags & SOCAM_DATAWIDTH_15))
584− return -EINVAL;
585− break;
586− case 10:
587− if (!(*flags & SOCAM_DATAWIDTH_10))
588− return -EINVAL;
589− break;
590− case 8:
591− if (!(*flags & SOCAM_DATAWIDTH_8))
592− return -EINVAL;
593− break;
594− case 4:
595− if (!(*flags & SOCAM_DATAWIDTH_4))
596− return -EINVAL;
597− break;
598− default:
599− dev_warn(mx3_cam->soc_host.v4l2_dev.dev,
600− "Unsupported bus width %d\n", buswidth);
601− return -EINVAL;
602− }
576+ *flags = V4L2_MBUS_MASTER |
577+ V4L2_MBUS_HSYNC_ACTIVE_HIGH |
578+ V4L2_MBUS_HSYNC_ACTIVE_LOW |
579+ V4L2_MBUS_VSYNC_ACTIVE_HIGH |
580+ V4L2_MBUS_VSYNC_ACTIVE_LOW |
581+ V4L2_MBUS_PCLK_SAMPLE_RISING |
582+ V4L2_MBUS_PCLK_SAMPLE_FALLING |
583+ V4L2_MBUS_DATA_ACTIVE_HIGH |
584+ V4L2_MBUS_DATA_ACTIVE_LOW;
603585
604586 return 0;
605587 }
@@ -607,9 +589,11 @@ static int test_platform_param(struct mx3_camera_dev *mx3_cam, · 1 unmodified line
607589 static int mx3_camera_try_bus_param(struct soc_camera_device *icd,
608590 const unsigned int depth)
609591 {
592+ struct v4l2_subdev *sd = soc_camera_to_subdev(icd);
610593 struct soc_camera_host *ici = to_soc_camera_host(icd->parent);
611594 struct mx3_camera_dev *mx3_cam = ici->priv;
612− unsigned long bus_flags, camera_flags;
595+ struct v4l2_mbus_config cfg = {.type = V4L2_MBUS_PARALLEL,};
596+ unsigned long bus_flags, common_flags;
613597 int ret = test_platform_param(mx3_cam, depth, &bus_flags);
614598
615599 dev_dbg(icd->parent, "request bus width %d bit: %d\n", depth, ret);
@@ -617,15 +601,21 @@ static int mx3_camera_try_bus_param(struct soc_camera_device *icd, · 1 unmodified line
617601 if (ret < 0)
618602 return ret;
619603
620− camera_flags = icd->ops->query_bus_param(icd);
621−
622− ret = soc_camera_bus_param_compatible(camera_flags, bus_flags);
623− if (ret < 0)
624− dev_warn(icd->parent,
625− "Flags incompatible: camera %lx, host %lx\n",
626− camera_flags, bus_flags);
604+ ret = v4l2_subdev_call(sd, video, g_mbus_config, &cfg);
605+ if (!ret) {
606+ common_flags = soc_mbus_config_compatible(&cfg,
607+ bus_flags);
608+ if (!common_flags) {
609+ dev_warn(icd->parent,
610+ "Flags incompatible: camera 0x%x, host 0x%lx\n",
611+ cfg.flags, bus_flags);
612+ return -EINVAL;
613+ }
614+ } else if (ret != -ENOIOCTLCMD) {
615+ return ret;
616+ }
627617
628− return ret;
618+ return 0;
629619 }
630620
631621 static bool chan_filter(struct dma_chan *chan, void *arg)
@@ -994,9 +984,11 @@ static int mx3_camera_querycap(struct soc_camera_host *ici, · 362 unmodified lines
994984
995985 static int mx3_camera_set_bus_param(struct soc_camera_device *icd, __u32 pixfmt)
996986 {
987+ struct v4l2_subdev *sd = soc_camera_to_subdev(icd);
997988 struct soc_camera_host *ici = to_soc_camera_host(icd->parent);
998989 struct mx3_camera_dev *mx3_cam = ici->priv;
999− unsigned long bus_flags, camera_flags, common_flags;
990+ struct v4l2_mbus_config cfg = {.type = V4L2_MBUS_PARALLEL,};
991+ unsigned long bus_flags, common_flags;
1000992 u32 dw, sens_conf;
1001993 const struct soc_mbus_pixelfmt *fmt;
1002994 int buswidth;
@@ -1008,83 +1000,76 @@ static int mx3_camera_set_bus_param(struct soc_camera_device *icd, __u32 pixfmt) · 5 unmodified lines
10081000 if (!fmt)
10091001 return -EINVAL;
10101002
1011− buswidth = fmt->bits_per_sample;
1012− ret = test_platform_param(mx3_cam, buswidth, &bus_flags);
1013−
10141003 xlate = soc_camera_xlate_by_fourcc(icd, pixfmt);
10151004 if (!xlate) {
10161005 dev_warn(dev, "Format %x not found\n", pixfmt);
10171006 return -EINVAL;
10181007 }
10191008
1009+ buswidth = fmt->bits_per_sample;
1010+ ret = test_platform_param(mx3_cam, buswidth, &bus_flags);
1011+
10201012 dev_dbg(dev, "requested bus width %d bit: %d\n", buswidth, ret);
10211013
10221014 if (ret < 0)
10231015 return ret;
10241016
1025− camera_flags = icd->ops->query_bus_param(icd);
1026−
1027− common_flags = soc_camera_bus_param_compatible(camera_flags, bus_flags);
1028− dev_dbg(dev, "Flags cam: 0x%lx host: 0x%lx common: 0x%lx\n",
1029− camera_flags, bus_flags, common_flags);
1030− if (!common_flags) {
1031− dev_dbg(dev, "no common flags");
1032− return -EINVAL;
1017+ ret = v4l2_subdev_call(sd, video, g_mbus_config, &cfg);
1018+ if (!ret) {
1019+ common_flags = soc_mbus_config_compatible(&cfg,
1020+ bus_flags);
1021+ if (!common_flags) {
1022+ dev_warn(icd->parent,
1023+ "Flags incompatible: camera 0x%x, host 0x%lx\n",
1024+ cfg.flags, bus_flags);
1025+ return -EINVAL;
1026+ }
1027+ } else if (ret != -ENOIOCTLCMD) {
1028+ return ret;
1029+ } else {
1030+ common_flags = bus_flags;
10331031 }
10341032
1033+ dev_dbg(dev, "Flags cam: 0x%x host: 0x%lx common: 0x%lx\n",
1034+ cfg.flags, bus_flags, common_flags);
1035+
10351036 /* Make choices, based on platform preferences */
1036− if ((common_flags & SOCAM_HSYNC_ACTIVE_HIGH) &&
1037− (common_flags & SOCAM_HSYNC_ACTIVE_LOW)) {
1037+ if ((common_flags & V4L2_MBUS_HSYNC_ACTIVE_HIGH) &&
1038+ (common_flags & V4L2_MBUS_HSYNC_ACTIVE_LOW)) {
10381039 if (mx3_cam->platform_flags & MX3_CAMERA_HSP)
1039− common_flags &= ~SOCAM_HSYNC_ACTIVE_HIGH;
1040+ common_flags &= ~V4L2_MBUS_HSYNC_ACTIVE_HIGH;
10401041 else
1041− common_flags &= ~SOCAM_HSYNC_ACTIVE_LOW;
1042+ common_flags &= ~V4L2_MBUS_HSYNC_ACTIVE_LOW;
10421043 }
10431044
1044− if ((common_flags & SOCAM_VSYNC_ACTIVE_HIGH) &&
1045− (common_flags & SOCAM_VSYNC_ACTIVE_LOW)) {
1045+ if ((common_flags & V4L2_MBUS_VSYNC_ACTIVE_HIGH) &&
1046+ (common_flags & V4L2_MBUS_VSYNC_ACTIVE_LOW)) {
10461047 if (mx3_cam->platform_flags & MX3_CAMERA_VSP)
1047− common_flags &= ~SOCAM_VSYNC_ACTIVE_HIGH;
1048+ common_flags &= ~V4L2_MBUS_VSYNC_ACTIVE_HIGH;
10481049 else
1049− common_flags &= ~SOCAM_VSYNC_ACTIVE_LOW;
1050+ common_flags &= ~V4L2_MBUS_VSYNC_ACTIVE_LOW;
10501051 }
10511052
1052− if ((common_flags & SOCAM_DATA_ACTIVE_HIGH) &&
1053− (common_flags & SOCAM_DATA_ACTIVE_LOW)) {
1053+ if ((common_flags & V4L2_MBUS_DATA_ACTIVE_HIGH) &&
1054+ (common_flags & V4L2_MBUS_DATA_ACTIVE_LOW)) {
10541055 if (mx3_cam->platform_flags & MX3_CAMERA_DP)
1055− common_flags &= ~SOCAM_DATA_ACTIVE_HIGH;
1056+ common_flags &= ~V4L2_MBUS_DATA_ACTIVE_HIGH;
10561057 else
1057− common_flags &= ~SOCAM_DATA_ACTIVE_LOW;
1058+ common_flags &= ~V4L2_MBUS_DATA_ACTIVE_LOW;
10581059 }
10591060
1060− if ((common_flags & SOCAM_PCLK_SAMPLE_RISING) &&
1061− (common_flags & SOCAM_PCLK_SAMPLE_FALLING)) {
1061+ if ((common_flags & V4L2_MBUS_PCLK_SAMPLE_RISING) &&
1062+ (common_flags & V4L2_MBUS_PCLK_SAMPLE_FALLING)) {
10621063 if (mx3_cam->platform_flags & MX3_CAMERA_PCP)
1063− common_flags &= ~SOCAM_PCLK_SAMPLE_RISING;
1064+ common_flags &= ~V4L2_MBUS_PCLK_SAMPLE_RISING;
10641065 else
1065− common_flags &= ~SOCAM_PCLK_SAMPLE_FALLING;
1066+ common_flags &= ~V4L2_MBUS_PCLK_SAMPLE_FALLING;
10661067 }
10671068
1068− /*
1069− * Make the camera work in widest common mode, we'll take care of
1070− * the rest
1071− */
1072− if (common_flags & SOCAM_DATAWIDTH_15)
1073− common_flags = (common_flags & ~SOCAM_DATAWIDTH_MASK) |
1074− SOCAM_DATAWIDTH_15;
1075− else if (common_flags & SOCAM_DATAWIDTH_10)
1076− common_flags = (common_flags & ~SOCAM_DATAWIDTH_MASK) |
1077− SOCAM_DATAWIDTH_10;
1078− else if (common_flags & SOCAM_DATAWIDTH_8)
1079− common_flags = (common_flags & ~SOCAM_DATAWIDTH_MASK) |
1080− SOCAM_DATAWIDTH_8;
1081− else
1082− common_flags = (common_flags & ~SOCAM_DATAWIDTH_MASK) |
1083− SOCAM_DATAWIDTH_4;
1084−
1085− ret = icd->ops->set_bus_param(icd, common_flags);
1086− if (ret < 0) {
1087− dev_dbg(dev, "camera set_bus_param(%lx) returned %d\n",
1069+ cfg.flags = common_flags;
1070+ ret = v4l2_subdev_call(sd, video, s_mbus_config, &cfg);
1071+ if (ret < 0 && ret != -ENOIOCTLCMD) {
1072+ dev_dbg(dev, "camera s_mbus_config(0x%lx) returned %d\n",
10881073 common_flags, ret);
10891074 return ret;
10901075 }
@@ -1108,13 +1093,13 @@ static int mx3_camera_set_bus_param(struct soc_camera_device *icd, __u32 pixfmt) · 17 unmodified lines
11081093 /* This has been set in mx3_camera_activate(), but we clear it above */
11091094 sens_conf |= CSI_SENS_CONF_DATA_FMT_BAYER;
11101095
1111− if (common_flags & SOCAM_PCLK_SAMPLE_FALLING)
1096+ if (common_flags & V4L2_MBUS_PCLK_SAMPLE_FALLING)
11121097 sens_conf |= 1 << CSI_SENS_CONF_PIX_CLK_POL_SHIFT;
1113− if (common_flags & SOCAM_HSYNC_ACTIVE_LOW)
1098+ if (common_flags & V4L2_MBUS_HSYNC_ACTIVE_LOW)
11141099 sens_conf |= 1 << CSI_SENS_CONF_HSYNC_POL_SHIFT;
1115− if (common_flags & SOCAM_VSYNC_ACTIVE_LOW)
1100+ if (common_flags & V4L2_MBUS_VSYNC_ACTIVE_LOW)
11161101 sens_conf |= 1 << CSI_SENS_CONF_VSYNC_POL_SHIFT;
1117− if (common_flags & SOCAM_DATA_ACTIVE_LOW)
1102+ if (common_flags & V4L2_MBUS_DATA_ACTIVE_LOW)
11181103 sens_conf |= 1 << CSI_SENS_CONF_DATA_POL_SHIFT;
11191104
11201105 /* Just do what we're asked to do */
@@ -1199,6 +1184,14 @@ static int __devinit mx3_camera_probe(struct platform_device *pdev) · 78 unmodified lines
11991184 "data widths, using default 8 bit\n");
12001185 mx3_cam->platform_flags |= MX3_CAMERA_DATAWIDTH_8;
12011186 }
1187+ if (mx3_cam->platform_flags & MX3_CAMERA_DATAWIDTH_4)
1188+ mx3_cam->width_flags = 1 << 3;
1189+ if (mx3_cam->platform_flags & MX3_CAMERA_DATAWIDTH_8)
1190+ mx3_cam->width_flags |= 1 << 7;
1191+ if (mx3_cam->platform_flags & MX3_CAMERA_DATAWIDTH_10)
1192+ mx3_cam->width_flags |= 1 << 9;
1193+ if (mx3_cam->platform_flags & MX3_CAMERA_DATAWIDTH_15)
1194+ mx3_cam->width_flags |= 1 << 14;
12021195
12031196 mx3_cam->mclk = mx3_cam->pdata->mclk_10khz * 10000;
12041197 if (!mx3_cam->mclk) {
@@ -1281,8 +1274,6 @@ static int __devexit mx3_camera_remove(struct platform_device *pdev) · 76 unmodified lines
12811274
12821275 dmaengine_put();
12831276
1284− dev_info(&pdev->dev, "i.MX3x Camera driver unloaded\n");
1285−
12861277 return 0;
12871278 }
12881279
drivers/media/video/omap/omap_vout.c+10−0
@@ -833,6 +833,15 @@ static void omap_vout_buffer_release(struct videobuf_queue *q, · 832 unmodified lines
833833 /*
834834 * File operations
835835 */
836+static unsigned int omap_vout_poll(struct file *file,
837+ struct poll_table_struct *wait)
838+{
839+ struct omap_vout_device *vout = file->private_data;
840+ struct videobuf_queue *q = &vout->vbq;
841+
842+ return videobuf_poll_stream(file, q, wait);
843+}
844+
836845 static void omap_vout_vm_open(struct vm_area_struct *vma)
837846 {
838847 struct omap_vout_device *vout = vma->vm_private_data;
@@ -1861,6 +1870,7 @@ static const struct v4l2_ioctl_ops vout_ioctl_ops = { · 1022 unmodified lines
18611870
18621871 static const struct v4l2_file_operations omap_vout_fops = {
18631872 .owner = THIS_MODULE,
1873+ .poll = omap_vout_poll,
18641874 .unlocked_ioctl = video_ioctl2,
18651875 .mmap = omap_vout_mmap,
18661876 .open = omap_vout_open,
drivers/media/video/omap1_camera.c+38−24
@@ -102,10 +102,10 @@ · 101 unmodified lines
102102 /* end of OMAP1 Camera Interface registers */
103103
104104
105−#define SOCAM_BUS_FLAGS (SOCAM_MASTER | \
106− SOCAM_HSYNC_ACTIVE_HIGH | SOCAM_VSYNC_ACTIVE_HIGH | \
107− SOCAM_PCLK_SAMPLE_RISING | SOCAM_PCLK_SAMPLE_FALLING | \
108− SOCAM_DATA_ACTIVE_HIGH | SOCAM_DATAWIDTH_8)
105+#define SOCAM_BUS_FLAGS (V4L2_MBUS_MASTER | \
106+ V4L2_MBUS_HSYNC_ACTIVE_HIGH | V4L2_MBUS_VSYNC_ACTIVE_HIGH | \
107+ V4L2_MBUS_PCLK_SAMPLE_RISING | V4L2_MBUS_PCLK_SAMPLE_FALLING | \
108+ V4L2_MBUS_DATA_ACTIVE_HIGH)
109109
110110
111111 #define FIFO_SIZE ((THRESHOLD_MASK >> THRESHOLD_SHIFT) + 1)
@@ -1438,41 +1438,55 @@ static int omap1_cam_querycap(struct soc_camera_host *ici, · 1326 unmodified lines
14381438 static int omap1_cam_set_bus_param(struct soc_camera_device *icd,
14391439 __u32 pixfmt)
14401440 {
1441+ struct v4l2_subdev *sd = soc_camera_to_subdev(icd);
14411442 struct device *dev = icd->parent;
14421443 struct soc_camera_host *ici = to_soc_camera_host(dev);
14431444 struct omap1_cam_dev *pcdev = ici->priv;
14441445 const struct soc_camera_format_xlate *xlate;
14451446 const struct soc_mbus_pixelfmt *fmt;
1446− unsigned long camera_flags, common_flags;
1447+ struct v4l2_mbus_config cfg = {.type = V4L2_MBUS_PARALLEL,};
1448+ unsigned long common_flags;
14471449 u32 ctrlclock, mode;
14481450 int ret;
14491451
1450− camera_flags = icd->ops->query_bus_param(icd);
1451−
1452− common_flags = soc_camera_bus_param_compatible(camera_flags,
1453− SOCAM_BUS_FLAGS);
1454− if (!common_flags)
1455− return -EINVAL;
1452+ ret = v4l2_subdev_call(sd, video, g_mbus_config, &cfg);
1453+ if (!ret) {
1454+ common_flags = soc_mbus_config_compatible(&cfg, SOCAM_BUS_FLAGS);
1455+ if (!common_flags) {
1456+ dev_warn(dev,
1457+ "Flags incompatible: camera 0x%x, host 0x%x\n",
1458+ cfg.flags, SOCAM_BUS_FLAGS);
1459+ return -EINVAL;
1460+ }
1461+ } else if (ret != -ENOIOCTLCMD) {
1462+ return ret;
1463+ } else {
1464+ common_flags = SOCAM_BUS_FLAGS;
1465+ }
14561466
14571467 /* Make choices, possibly based on platform configuration */
1458− if ((common_flags & SOCAM_PCLK_SAMPLE_RISING) &&
1459− (common_flags & SOCAM_PCLK_SAMPLE_FALLING)) {
1468+ if ((common_flags & V4L2_MBUS_PCLK_SAMPLE_RISING) &&
1469+ (common_flags & V4L2_MBUS_PCLK_SAMPLE_FALLING)) {
14601470 if (!pcdev->pdata ||
14611471 pcdev->pdata->flags & OMAP1_CAMERA_LCLK_RISING)
1462− common_flags &= ~SOCAM_PCLK_SAMPLE_FALLING;
1472+ common_flags &= ~V4L2_MBUS_PCLK_SAMPLE_FALLING;
14631473 else
1464− common_flags &= ~SOCAM_PCLK_SAMPLE_RISING;
1474+ common_flags &= ~V4L2_MBUS_PCLK_SAMPLE_RISING;
14651475 }
14661476
1467− ret = icd->ops->set_bus_param(icd, common_flags);
1468− if (ret < 0)
1477+ cfg.flags = common_flags;
1478+ ret = v4l2_subdev_call(sd, video, s_mbus_config, &cfg);
1479+ if (ret < 0 && ret != -ENOIOCTLCMD) {
1480+ dev_dbg(dev, "camera s_mbus_config(0x%lx) returned %d\n",
1481+ common_flags, ret);
14691482 return ret;
1483+ }
14701484
14711485 ctrlclock = CAM_READ_CACHE(pcdev, CTRLCLOCK);
14721486 if (ctrlclock & LCLK_EN)
14731487 CAM_WRITE(pcdev, CTRLCLOCK, ctrlclock & ~LCLK_EN);
14741488
1475− if (common_flags & SOCAM_PCLK_SAMPLE_RISING) {
1489+ if (common_flags & V4L2_MBUS_PCLK_SAMPLE_RISING) {
14761490 dev_dbg(dev, "CTRLCLOCK_REG |= POLCLK\n");
14771491 ctrlclock |= POLCLK;
14781492 } else {
@@ -1565,10 +1579,10 @@ static int __init omap1_cam_probe(struct platform_device *pdev) · 86 unmodified lines
15651579 pcdev->clk = clk;
15661580
15671581 pcdev->pdata = pdev->dev.platform_data;
1568− pcdev->pflags = pcdev->pdata->flags;
1569−
1570− if (pcdev->pdata)
1582+ if (pcdev->pdata) {
1583+ pcdev->pflags = pcdev->pdata->flags;
15711584 pcdev->camexclk = pcdev->pdata->camexclk_khz * 1000;
1585+ }
15721586
15731587 switch (pcdev->camexclk) {
15741588 case 6000000:
@@ -1578,6 +1592,7 @@ static int __init omap1_cam_probe(struct platform_device *pdev) · 3 unmodified lines
15781592 case 24000000:
15791593 break;
15801594 default:
1595+ /* pcdev->camexclk != 0 => pcdev->pdata != NULL */
15811596 dev_warn(&pdev->dev,
15821597 "Incorrect sensor clock frequency %ld kHz, "
15831598 "should be one of 0, 6, 8, 9.6, 12 or 24 MHz, "
@@ -1585,8 +1600,7 @@ static int __init omap1_cam_probe(struct platform_device *pdev) · 1 unmodified line
15851600 pcdev->pdata->camexclk_khz);
15861601 pcdev->camexclk = 0;
15871602 case 0:
1588− dev_info(&pdev->dev,
1589− "Not providing sensor clock\n");
1603+ dev_info(&pdev->dev, "Not providing sensor clock\n");
15901604 }
15911605
15921606 INIT_LIST_HEAD(&pcdev->capture);
@@ -1716,5 +1730,5 @@ MODULE_PARM_DESC(sg_mode, "videobuf mode, 0: dma-contig (default), 1: dma-sg"); · 123 unmodified lines
17161730 MODULE_DESCRIPTION("OMAP1 Camera Interface driver");
17171731 MODULE_AUTHOR("Janusz Krzysztofik <jkrzyszt@tis.icnet.pl>");
17181732 MODULE_LICENSE("GPL v2");
1719−MODULE_LICENSE(DRIVER_VERSION);
1733+MODULE_VERSION(DRIVER_VERSION);
17201734 MODULE_ALIAS("platform:" DRIVER_NAME);
drivers/media/video/omap3isp/isp.c+3−0
@@ -1704,6 +1704,7 @@ static int isp_register_entities(struct isp_device *isp) · 1703 unmodified lines
17041704 isp->media_dev.dev = isp->dev;
17051705 strlcpy(isp->media_dev.model, "TI OMAP3 ISP",
17061706 sizeof(isp->media_dev.model));
1707+ isp->media_dev.hw_revision = isp->revision;
17071708 isp->media_dev.link_notify = isp_pipeline_link_notify;
17081709 ret = media_device_register(&isp->media_dev);
17091710 if (ret < 0) {
@@ -2210,6 +2211,8 @@ error: · 500 unmodified lines
22102211 regulator_put(isp->isp_csiphy2.vdd);
22112212 regulator_put(isp->isp_csiphy1.vdd);
22122213 platform_set_drvdata(pdev, NULL);
2214+
2215+ mutex_destroy(&isp->isp_mutex);
22132216 kfree(isp);
22142217
22152218 return ret;
drivers/media/video/omap3isp/ispccdc.c+51−35
@@ -1836,7 +1836,7 @@ ccdc_try_format(struct isp_ccdc_device *ccdc, struct v4l2_subdev_fh *fh, · 1835 unmodified lines
18361836 * callers to request an output size bigger than the input size
18371837 * up to the nearest multiple of 16.
18381838 */
1839− fmt->width = clamp_t(u32, width, 32, (fmt->width + 15) & ~15);
1839+ fmt->width = clamp_t(u32, width, 32, fmt->width + 15);
18401840 fmt->width &= ~15;
18411841 fmt->height = clamp_t(u32, height, 32, fmt->height);
18421842 break;
@@ -2152,6 +2152,37 @@ static const struct media_entity_operations ccdc_media_ops = { · 309 unmodified lines
21522152 .link_setup = ccdc_link_setup,
21532153 };
21542154
2155+void omap3isp_ccdc_unregister_entities(struct isp_ccdc_device *ccdc)
2156+{
2157+ v4l2_device_unregister_subdev(&ccdc->subdev);
2158+ omap3isp_video_unregister(&ccdc->video_out);
2159+}
2160+
2161+int omap3isp_ccdc_register_entities(struct isp_ccdc_device *ccdc,
2162+ struct v4l2_device *vdev)
2163+{
2164+ int ret;
2165+
2166+ /* Register the subdev and video node. */
2167+ ret = v4l2_device_register_subdev(vdev, &ccdc->subdev);
2168+ if (ret < 0)
2169+ goto error;
2170+
2171+ ret = omap3isp_video_register(&ccdc->video_out, vdev);
2172+ if (ret < 0)
2173+ goto error;
2174+
2175+ return 0;
2176+
2177+error:
2178+ omap3isp_ccdc_unregister_entities(ccdc);
2179+ return ret;
2180+}
2181+
2182+/* -----------------------------------------------------------------------------
2183+ * ISP CCDC initialisation and cleanup
2184+ */
2185+
21552186 /*
21562187 * ccdc_init_entities - Initialize V4L2 subdev and media entity
21572188 * @ccdc: ISP CCDC module
@@ -2193,50 +2224,23 @@ static int ccdc_init_entities(struct isp_ccdc_device *ccdc) · 35 unmodified lines
21932224
21942225 ret = omap3isp_video_init(&ccdc->video_out, "CCDC");
21952226 if (ret < 0)
2196− return ret;
2227+ goto error_video;
21972228
21982229 /* Connect the CCDC subdev to the video node. */
21992230 ret = media_entity_create_link(&ccdc->subdev.entity, CCDC_PAD_SOURCE_OF,
22002231 &ccdc->video_out.video.entity, 0, 0);
22012232 if (ret < 0)
2202− return ret;
2203−
2204− return 0;
2205−}
2206−
2207−void omap3isp_ccdc_unregister_entities(struct isp_ccdc_device *ccdc)
2208−{
2209− media_entity_cleanup(&ccdc->subdev.entity);
2210−
2211− v4l2_device_unregister_subdev(&ccdc->subdev);
2212− omap3isp_video_unregister(&ccdc->video_out);
2213−}
2214−
2215−int omap3isp_ccdc_register_entities(struct isp_ccdc_device *ccdc,
2216− struct v4l2_device *vdev)
2217−{
2218− int ret;
2219−
2220− /* Register the subdev and video node. */
2221− ret = v4l2_device_register_subdev(vdev, &ccdc->subdev);
2222− if (ret < 0)
2223− goto error;
2224−
2225− ret = omap3isp_video_register(&ccdc->video_out, vdev);
2226− if (ret < 0)
2227− goto error;
2233+ goto error_link;
22282234
22292235 return 0;
22302236
2231−error:
2232− omap3isp_ccdc_unregister_entities(ccdc);
2237+error_link:
2238+ omap3isp_video_cleanup(&ccdc->video_out);
2239+error_video:
2240+ media_entity_cleanup(me);
22332241 return ret;
22342242 }
22352243
2236−/* -----------------------------------------------------------------------------
2237− * ISP CCDC initialisation and cleanup
2238− */
2239−
22402244 /*
22412245 * omap3isp_ccdc_init - CCDC module initialization.
22422246 * @dev: Device pointer specific to the OMAP3 ISP.
@@ -2248,6 +2252,7 @@ error: · 5 unmodified lines
22482252 int omap3isp_ccdc_init(struct isp_device *isp)
22492253 {
22502254 struct isp_ccdc_device *ccdc = &isp->isp_ccdc;
2255+ int ret;
22512256
22522257 spin_lock_init(&ccdc->lock);
22532258 init_waitqueue_head(&ccdc->wait);
@@ -2276,7 +2281,13 @@ int omap3isp_ccdc_init(struct isp_device *isp) · 22 unmodified lines
22762281 ccdc->update = OMAP3ISP_CCDC_BLCLAMP;
22772282 ccdc_apply_controls(ccdc);
22782283
2279− return ccdc_init_entities(ccdc);
2284+ ret = ccdc_init_entities(ccdc);
2285+ if (ret < 0) {
2286+ mutex_destroy(&ccdc->ioctl_lock);
2287+ return ret;
2288+ }
2289+
2290+ return 0;
22802291 }
22812292
22822293 /*
@@ -2287,6 +2298,9 @@ void omap3isp_ccdc_cleanup(struct isp_device *isp) · 4 unmodified lines
22872298 {
22882299 struct isp_ccdc_device *ccdc = &isp->isp_ccdc;
22892300
2301+ omap3isp_video_cleanup(&ccdc->video_out);
2302+ media_entity_cleanup(&ccdc->subdev.entity);
2303+
22902304 /* Free LSC requests. As the CCDC is stopped there's no active request,
22912305 * so only the pending request and the free queue need to be handled.
22922306 */
@@ -2296,4 +2310,6 @@ void omap3isp_ccdc_cleanup(struct isp_device *isp) · 3 unmodified lines
22962310
22972311 if (ccdc->fpc.fpcaddr != 0)
22982312 omap_iommu_vfree(isp->domain, isp->iommu, ccdc->fpc.fpcaddr);
2313+
2314+ mutex_destroy(&ccdc->ioctl_lock);
22992315 }
drivers/media/video/omap3isp/ispccp2.c+65−60
@@ -1031,6 +1031,48 @@ static const struct media_entity_operations ccp2_media_ops = { · 1030 unmodified lines
10311031 .link_setup = ccp2_link_setup,
10321032 };
10331033
1034+/*
1035+ * omap3isp_ccp2_unregister_entities - Unregister media entities: subdev
1036+ * @ccp2: Pointer to ISP CCP2 device
1037+ */
1038+void omap3isp_ccp2_unregister_entities(struct isp_ccp2_device *ccp2)
1039+{
1040+ v4l2_device_unregister_subdev(&ccp2->subdev);
1041+ omap3isp_video_unregister(&ccp2->video_in);
1042+}
1043+
1044+/*
1045+ * omap3isp_ccp2_register_entities - Register the subdev media entity
1046+ * @ccp2: Pointer to ISP CCP2 device
1047+ * @vdev: Pointer to v4l device
1048+ * return negative error code or zero on success
1049+ */
1050+
1051+int omap3isp_ccp2_register_entities(struct isp_ccp2_device *ccp2,
1052+ struct v4l2_device *vdev)
1053+{
1054+ int ret;
1055+
1056+ /* Register the subdev and video nodes. */
1057+ ret = v4l2_device_register_subdev(vdev, &ccp2->subdev);
1058+ if (ret < 0)
1059+ goto error;
1060+
1061+ ret = omap3isp_video_register(&ccp2->video_in, vdev);
1062+ if (ret < 0)
1063+ goto error;
1064+
1065+ return 0;
1066+
1067+error:
1068+ omap3isp_ccp2_unregister_entities(ccp2);
1069+ return ret;
1070+}
1071+
1072+/* -----------------------------------------------------------------------------
1073+ * ISP ccp2 initialisation and cleanup
1074+ */
1075+
10341076 /*
10351077 * ccp2_init_entities - Initialize ccp2 subdev and media entity.
10361078 * @ccp2: Pointer to ISP CCP2 device
@@ -1083,72 +1125,23 @@ static int ccp2_init_entities(struct isp_ccp2_device *ccp2) · 46 unmodified lines
10831125
10841126 ret = omap3isp_video_init(&ccp2->video_in, "CCP2");
10851127 if (ret < 0)
1086− return ret;
1128+ goto error_video;
10871129
10881130 /* Connect the video node to the ccp2 subdev. */
10891131 ret = media_entity_create_link(&ccp2->video_in.video.entity, 0,
10901132 &ccp2->subdev.entity, CCP2_PAD_SINK, 0);
10911133 if (ret < 0)
1092− return ret;
1134+ goto error_link;
10931135
10941136 return 0;
1095−}
10961137
1097−/*
1098− * omap3isp_ccp2_unregister_entities - Unregister media entities: subdev
1099− * @ccp2: Pointer to ISP CCP2 device
1100− */
1101−void omap3isp_ccp2_unregister_entities(struct isp_ccp2_device *ccp2)
1102−{
1138+error_link:
1139+ omap3isp_video_cleanup(&ccp2->video_in);
1140+error_video:
11031141 media_entity_cleanup(&ccp2->subdev.entity);
1104−
1105− v4l2_device_unregister_subdev(&ccp2->subdev);
1106− omap3isp_video_unregister(&ccp2->video_in);
1107−}
1108−
1109−/*
1110− * omap3isp_ccp2_register_entities - Register the subdev media entity
1111− * @ccp2: Pointer to ISP CCP2 device
1112− * @vdev: Pointer to v4l device
1113− * return negative error code or zero on success
1114− */
1115−
1116−int omap3isp_ccp2_register_entities(struct isp_ccp2_device *ccp2,
1117− struct v4l2_device *vdev)
1118−{
1119− int ret;
1120−
1121− /* Register the subdev and video nodes. */
1122− ret = v4l2_device_register_subdev(vdev, &ccp2->subdev);
1123− if (ret < 0)
1124− goto error;
1125−
1126− ret = omap3isp_video_register(&ccp2->video_in, vdev);
1127− if (ret < 0)
1128− goto error;
1129−
1130− return 0;
1131−
1132−error:
1133− omap3isp_ccp2_unregister_entities(ccp2);
11341142 return ret;
11351143 }
11361144
1137−/* -----------------------------------------------------------------------------
1138− * ISP ccp2 initialisation and cleanup
1139− */
1140−
1141−/*
1142− * omap3isp_ccp2_cleanup - CCP2 un-initialization
1143− * @isp : Pointer to ISP device
1144− */
1145−void omap3isp_ccp2_cleanup(struct isp_device *isp)
1146−{
1147− struct isp_ccp2_device *ccp2 = &isp->isp_ccp2;
1148−
1149− regulator_put(ccp2->vdds_csib);
1150−}
1151−
11521145 /*
11531146 * omap3isp_ccp2_init - CCP2 initialization.
11541147 * @isp : Pointer to ISP device
@@ -1184,13 +1177,25 @@ int omap3isp_ccp2_init(struct isp_device *isp) · 29 unmodified lines
11841177 }
11851178
11861179 ret = ccp2_init_entities(ccp2);
1187− if (ret < 0)
1188− goto out;
1180+ if (ret < 0) {
1181+ regulator_put(ccp2->vdds_csib);
1182+ return ret;
1183+ }
11891184
11901185 ccp2_reset(ccp2);
1191−out:
1192− if (ret)
1193− omap3isp_ccp2_cleanup(isp);
1186+ return 0;
1187+}
11941188
1195− return ret;
1189+/*
1190+ * omap3isp_ccp2_cleanup - CCP2 un-initialization
1191+ * @isp : Pointer to ISP device
1192+ */
1193+void omap3isp_ccp2_cleanup(struct isp_device *isp)
1194+{
1195+ struct isp_ccp2_device *ccp2 = &isp->isp_ccp2;
1196+
1197+ omap3isp_video_cleanup(&ccp2->video_in);
1198+ media_entity_cleanup(&ccp2->subdev.entity);
1199+
1200+ regulator_put(ccp2->vdds_csib);
11961201 }
drivers/media/video/omap3isp/ispcsi2.c+48−43
@@ -1187,6 +1187,37 @@ static const struct media_entity_operations csi2_media_ops = { · 1186 unmodified lines
11871187 .link_setup = csi2_link_setup,
11881188 };
11891189
1190+void omap3isp_csi2_unregister_entities(struct isp_csi2_device *csi2)
1191+{
1192+ v4l2_device_unregister_subdev(&csi2->subdev);
1193+ omap3isp_video_unregister(&csi2->video_out);
1194+}
1195+
1196+int omap3isp_csi2_register_entities(struct isp_csi2_device *csi2,
1197+ struct v4l2_device *vdev)
1198+{
1199+ int ret;
1200+
1201+ /* Register the subdev and video nodes. */
1202+ ret = v4l2_device_register_subdev(vdev, &csi2->subdev);
1203+ if (ret < 0)
1204+ goto error;
1205+
1206+ ret = omap3isp_video_register(&csi2->video_out, vdev);
1207+ if (ret < 0)
1208+ goto error;
1209+
1210+ return 0;
1211+
1212+error:
1213+ omap3isp_csi2_unregister_entities(csi2);
1214+ return ret;
1215+}
1216+
1217+/* -----------------------------------------------------------------------------
1218+ * ISP CSI2 initialisation and cleanup
1219+ */
1220+
11901221 /*
11911222 * csi2_init_entities - Initialize subdev and media entity.
11921223 * @csi2: Pointer to csi2 structure.
@@ -1228,57 +1259,23 @@ static int csi2_init_entities(struct isp_csi2_device *csi2) · 35 unmodified lines
12281259
12291260 ret = omap3isp_video_init(&csi2->video_out, "CSI2a");
12301261 if (ret < 0)
1231− return ret;
1262+ goto error_video;
12321263
12331264 /* Connect the CSI2 subdev to the video node. */
12341265 ret = media_entity_create_link(&csi2->subdev.entity, CSI2_PAD_SOURCE,
12351266 &csi2->video_out.video.entity, 0, 0);
12361267 if (ret < 0)
1237− return ret;
1268+ goto error_link;
12381269
12391270 return 0;
1240−}
12411271
1242−void omap3isp_csi2_unregister_entities(struct isp_csi2_device *csi2)
1243−{
1272+error_link:
1273+ omap3isp_video_cleanup(&csi2->video_out);
1274+error_video:
12441275 media_entity_cleanup(&csi2->subdev.entity);
1245−
1246− v4l2_device_unregister_subdev(&csi2->subdev);
1247− omap3isp_video_unregister(&csi2->video_out);
1248−}
1249−
1250−int omap3isp_csi2_register_entities(struct isp_csi2_device *csi2,
1251− struct v4l2_device *vdev)
1252−{
1253− int ret;
1254−
1255− /* Register the subdev and video nodes. */
1256− ret = v4l2_device_register_subdev(vdev, &csi2->subdev);
1257− if (ret < 0)
1258− goto error;
1259−
1260− ret = omap3isp_video_register(&csi2->video_out, vdev);
1261− if (ret < 0)
1262− goto error;
1263−
1264− return 0;
1265−
1266−error:
1267− omap3isp_csi2_unregister_entities(csi2);
12681276 return ret;
12691277 }
12701278
1271−/* -----------------------------------------------------------------------------
1272− * ISP CSI2 initialisation and cleanup
1273− */
1274−
1275−/*
1276− * omap3isp_csi2_cleanup - Routine for module driver cleanup
1277− */
1278−void omap3isp_csi2_cleanup(struct isp_device *isp)
1279−{
1280−}
1281−
12821279 /*
12831280 * omap3isp_csi2_init - Routine for module driver init
12841281 */
@@ -1298,7 +1295,7 @@ int omap3isp_csi2_init(struct isp_device *isp) · 13 unmodified lines
12981295
12991296 ret = csi2_init_entities(csi2a);
13001297 if (ret < 0)
1301− goto fail;
1298+ return ret;
13021299
13031300 if (isp->revision == ISP_REVISION_15_0) {
13041301 csi2c->isp = isp;
@@ -1311,7 +1308,15 @@ int omap3isp_csi2_init(struct isp_device *isp) · 6 unmodified lines
13111308 }
13121309
13131310 return 0;
1314−fail:
1315− omap3isp_csi2_cleanup(isp);
1316− return ret;
1311+}
1312+
1313+/*
1314+ * omap3isp_csi2_cleanup - Routine for module driver cleanup
1315+ */
1316+void omap3isp_csi2_cleanup(struct isp_device *isp)
1317+{
1318+ struct isp_csi2_device *csi2a = &isp->isp_csi2a;
1319+
1320+ omap3isp_video_cleanup(&csi2a->video_out);
1321+ media_entity_cleanup(&csi2a->subdev.entity);
13171322 }
drivers/media/video/omap3isp/isph3a_aewb.c+1−1
@@ -370,5 +370,5 @@ void omap3isp_h3a_aewb_cleanup(struct isp_device *isp) · 369 unmodified lines
370370 {
371371 kfree(isp->isp_aewb.priv);
372372 kfree(isp->isp_aewb.recover_priv);
373− omap3isp_stat_free(&isp->isp_aewb);
373+ omap3isp_stat_cleanup(&isp->isp_aewb);
374374 }
drivers/media/video/omap3isp/isph3a_af.c+1−1
@@ -425,5 +425,5 @@ void omap3isp_h3a_af_cleanup(struct isp_device *isp) · 424 unmodified lines
425425 {
426426 kfree(isp->isp_af.priv);
427427 kfree(isp->isp_af.recover_priv);
428− omap3isp_stat_free(&isp->isp_af);
428+ omap3isp_stat_cleanup(&isp->isp_af);
429429 }
drivers/media/video/omap3isp/isphist.c+1−1
@@ -516,5 +516,5 @@ void omap3isp_hist_cleanup(struct isp_device *isp) · 515 unmodified lines
516516 if (HIST_USING_DMA(&isp->isp_hist))
517517 omap_free_dma(isp->isp_hist.dma_ch);
518518 kfree(isp->isp_hist.priv);
519− omap3isp_stat_free(&isp->isp_hist);
519+ omap3isp_stat_cleanup(&isp->isp_hist);
520520 }
drivers/media/video/omap3isp/isppreview.c+269−150
@@ -76,9 +76,51 @@ static struct omap3isp_prev_csc flr_prev_csc = { · 75 unmodified lines
7676
7777 #define DEF_DETECT_CORRECT_VAL 0xe
7878
79−#define PREV_MIN_WIDTH 64
80−#define PREV_MIN_HEIGHT 8
81−#define PREV_MAX_HEIGHT 16384
79+/*
80+ * Margins and image size limits.
81+ *
82+ * The preview engine crops several rows and columns internally depending on
83+ * which filters are enabled. To avoid format changes when the filters are
84+ * enabled or disabled (which would prevent them from being turned on or off
85+ * during streaming), the driver assumes all the filters are enabled when
86+ * computing sink crop and source format limits.
87+ *
88+ * If a filter is disabled, additional cropping is automatically added at the
89+ * preview engine input by the driver to avoid overflow at line and frame end.
90+ * This is completely transparent for applications.
91+ *
92+ * Median filter 4 pixels
93+ * Noise filter,
94+ * Faulty pixels correction 4 pixels, 4 lines
95+ * CFA filter 4 pixels, 4 lines in Bayer mode
96+ * 2 lines in other modes
97+ * Color suppression 2 pixels
98+ * or luma enhancement
99+ * -------------------------------------------------------------
100+ * Maximum total 14 pixels, 8 lines
101+ *
102+ * The color suppression and luma enhancement filters are applied after bayer to
103+ * YUV conversion. They thus can crop one pixel on the left and one pixel on the
104+ * right side of the image without changing the color pattern. When both those
105+ * filters are disabled, the driver must crop the two pixels on the same side of
106+ * the image to avoid changing the bayer pattern. The left margin is thus set to
107+ * 8 pixels and the right margin to 6 pixels.
108+ */
109+
110+#define PREV_MARGIN_LEFT 8
111+#define PREV_MARGIN_RIGHT 6
112+#define PREV_MARGIN_TOP 4
113+#define PREV_MARGIN_BOTTOM 4
114+
115+#define PREV_MIN_IN_WIDTH 64
116+#define PREV_MIN_IN_HEIGHT 8
117+#define PREV_MAX_IN_HEIGHT 16384
118+
119+#define PREV_MIN_OUT_WIDTH 0
120+#define PREV_MIN_OUT_HEIGHT 0
121+#define PREV_MAX_OUT_WIDTH 1280
122+#define PREV_MAX_OUT_WIDTH_ES2 3300
123+#define PREV_MAX_OUT_WIDTH_3630 4096
82124
83125 /*
84126 * Coeficient Tables for the submodules in Preview.
@@ -979,52 +1021,36 @@ static void preview_config_averager(struct isp_prev_device *prev, u8 average) · 894 unmodified lines
9791021 * enabled when reporting source pad formats to userspace. If this assumption is
9801022 * not true, rows and columns must be manually cropped at the preview engine
9811023 * input to avoid overflows at the end of lines and frames.
1024+ *
1025+ * See the explanation at the PREV_MARGIN_* definitions for more details.
9821026 */
9831027 static void preview_config_input_size(struct isp_prev_device *prev)
9841028 {
9851029 struct isp_device *isp = to_isp_device(prev);
9861030 struct prev_params *params = &prev->params;
987− struct v4l2_mbus_framefmt *format = &prev->formats[PREV_PAD_SINK];
988− unsigned int sph = 0;
989− unsigned int eph = format->width - 1;
990− unsigned int slv = 0;
991− unsigned int elv = format->height - 1;
992−
993− if (prev->input == PREVIEW_INPUT_CCDC) {
994− sph += 2;
995− eph -= 2;
1031+ unsigned int sph = prev->crop.left;
1032+ unsigned int eph = prev->crop.left + prev->crop.width - 1;
1033+ unsigned int slv = prev->crop.top;
1034+ unsigned int elv = prev->crop.top + prev->crop.height - 1;
1035+
1036+ if (params->features & PREV_CFA) {
1037+ sph -= 2;
1038+ eph += 2;
1039+ slv -= 2;
1040+ elv += 2;
9961041 }
997−
998− /*
999− * Median filter 4 pixels
1000− * Noise filter 4 pixels, 4 lines
1001− * or faulty pixels correction
1002− * CFA filter 4 pixels, 4 lines in Bayer mode
1003− * 2 lines in other modes
1004− * Color suppression 2 pixels
1005− * or luma enhancement
1006− * -------------------------------------------------------------
1007− * Maximum total 14 pixels, 8 lines
1008− */
1009−
1010− if (!(params->features & PREV_CFA)) {
1011− sph += 2;
1012− eph -= 2;
1013− slv += 2;
1014− elv -= 2;
1042+ if (params->features & (PREV_DEFECT_COR | PREV_NOISE_FILTER)) {
1043+ sph -= 2;
1044+ eph += 2;
1045+ slv -= 2;
1046+ elv += 2;
10151047 }
1016− if (!(params->features & (PREV_DEFECT_COR | PREV_NOISE_FILTER))) {
1017− sph += 2;
1018− eph -= 2;
1019− slv += 2;
1020− elv -= 2;
1048+ if (params->features & PREV_HORZ_MEDIAN_FILTER) {
1049+ sph -= 2;
1050+ eph += 2;
10211051 }
1022− if (!(params->features & PREV_HORZ_MEDIAN_FILTER)) {
1023− sph += 2;
1024− eph -= 2;
1025− }
1026− if (!(params->features & (PREV_CHROMA_SUPPRESS | PREV_LUMA_ENHANCE)))
1027− sph += 2;
1052+ if (params->features & (PREV_CHROMA_SUPPRESS | PREV_LUMA_ENHANCE))
1053+ sph -= 2;
10281054
10291055 isp_reg_writel(isp, (sph << ISPPRV_HORZ_INFO_SPH_SHIFT) | eph,
10301056 OMAP3_ISP_IOMEM_PREV, ISPPRV_HORZ_INFO);
@@ -1228,7 +1254,6 @@ static void preview_init_params(struct isp_prev_device *prev) · 197 unmodified lines
12281254 /* Init values */
12291255 params->contrast = ISPPRV_CONTRAST_DEF * ISPPRV_CONTRAST_UNITS;
12301256 params->brightness = ISPPRV_BRIGHT_DEF * ISPPRV_BRIGHT_UNITS;
1231− params->average = NO_AVE;
12321257 params->cfa.format = OMAP3ISP_CFAFMT_BAYER;
12331258 memcpy(params->cfa.table, cfa_coef_table,
12341259 sizeof(params->cfa.table));
@@ -1281,14 +1306,14 @@ static unsigned int preview_max_out_width(struct isp_prev_device *prev) · 46 unmodified lines
12811306
12821307 switch (isp->revision) {
12831308 case ISP_REVISION_1_0:
1284− return ISPPRV_MAXOUTPUT_WIDTH;
1309+ return PREV_MAX_OUT_WIDTH;
12851310
12861311 case ISP_REVISION_2_0:
12871312 default:
1288− return ISPPRV_MAXOUTPUT_WIDTH_ES2;
1313+ return PREV_MAX_OUT_WIDTH_ES2;
12891314
12901315 case ISP_REVISION_15_0:
1291− return ISPPRV_MAXOUTPUT_WIDTH_3630;
1316+ return PREV_MAX_OUT_WIDTH_3630;
12921317 }
12931318 }
12941319
@@ -1296,8 +1321,6 @@ static void preview_configure(struct isp_prev_device *prev) · 1 unmodified line
12961321 {
12971322 struct isp_device *isp = to_isp_device(prev);
12981323 struct v4l2_mbus_framefmt *format;
1299− unsigned int max_out_width;
1300− unsigned int format_avg;
13011324
13021325 preview_setup_hw(prev);
13031326
@@ -1335,10 +1358,7 @@ static void preview_configure(struct isp_prev_device *prev) · 31 unmodified lines
13351358 preview_config_outlineoffset(prev,
13361359 ALIGN(format->width, 0x10) * 2);
13371360
1338− max_out_width = preview_max_out_width(prev);
1339−
1340− format_avg = fls(DIV_ROUND_UP(format->width, max_out_width) - 1);
1341− preview_config_averager(prev, format_avg);
1361+ preview_config_averager(prev, 0);
13421362 preview_config_ycpos(prev, format->code);
13431363 }
13441364
@@ -1597,6 +1617,16 @@ __preview_get_format(struct isp_prev_device *prev, struct v4l2_subdev_fh *fh, · 252 unmodified lines
15971617 return &prev->formats[pad];
15981618 }
15991619
1620+static struct v4l2_rect *
1621+__preview_get_crop(struct isp_prev_device *prev, struct v4l2_subdev_fh *fh,
1622+ enum v4l2_subdev_format_whence which)
1623+{
1624+ if (which == V4L2_SUBDEV_FORMAT_TRY)
1625+ return v4l2_subdev_get_try_crop(fh, PREV_PAD_SINK);
1626+ else
1627+ return &prev->crop;
1628+}
1629+
16001630 /* previewer format descriptions */
16011631 static const unsigned int preview_input_fmts[] = {
16021632 V4L2_MBUS_FMT_SGRBG10_1X10,
@@ -1611,24 +1641,25 @@ static const unsigned int preview_output_fmts[] = { · 8 unmodified lines
16111641 };
16121642
16131643 /*
1614− * preview_try_format - Handle try format by pad subdev method
1615− * @prev: ISP preview device
1616− * @fh : V4L2 subdev file handle
1617− * @pad: pad num
1618− * @fmt: pointer to v4l2 format structure
1644+ * preview_try_format - Validate a format
1645+ * @prev: ISP preview engine
1646+ * @fh: V4L2 subdev file handle
1647+ * @pad: pad number
1648+ * @fmt: format to be validated
1649+ * @which: try/active format selector
1650+ *
1651+ * Validate and adjust the given format for the given pad based on the preview
1652+ * engine limits and the format and crop rectangles on other pads.
16191653 */
16201654 static void preview_try_format(struct isp_prev_device *prev,
16211655 struct v4l2_subdev_fh *fh, unsigned int pad,
16221656 struct v4l2_mbus_framefmt *fmt,
16231657 enum v4l2_subdev_format_whence which)
16241658 {
1625− struct v4l2_mbus_framefmt *format;
1626− unsigned int max_out_width;
16271659 enum v4l2_mbus_pixelcode pixelcode;
1660+ struct v4l2_rect *crop;
16281661 unsigned int i;
16291662
1630− max_out_width = preview_max_out_width(prev);
1631−
16321663 switch (pad) {
16331664 case PREV_PAD_SINK:
16341665 /* When reading data from the CCDC, the input size has already
@@ -1641,10 +1672,11 @@ static void preview_try_format(struct isp_prev_device *prev, · 6 unmodified lines
16411672 * filter array interpolation.
16421673 */
16431674 if (prev->input == PREVIEW_INPUT_MEMORY) {
1644− fmt->width = clamp_t(u32, fmt->width, PREV_MIN_WIDTH,
1645− max_out_width * 8);
1646− fmt->height = clamp_t(u32, fmt->height, PREV_MIN_HEIGHT,
1647− PREV_MAX_HEIGHT);
1675+ fmt->width = clamp_t(u32, fmt->width, PREV_MIN_IN_WIDTH,
1676+ preview_max_out_width(prev));
1677+ fmt->height = clamp_t(u32, fmt->height,
1678+ PREV_MIN_IN_HEIGHT,
1679+ PREV_MAX_IN_HEIGHT);
16481680 }
16491681
16501682 fmt->colorspace = V4L2_COLORSPACE_SRGB;
@@ -1661,15 +1693,8 @@ static void preview_try_format(struct isp_prev_device *prev, · 10 unmodified lines
16611693
16621694 case PREV_PAD_SOURCE:
16631695 pixelcode = fmt->code;
1664− format = __preview_get_format(prev, fh, PREV_PAD_SINK, which);
1665− memcpy(fmt, format, sizeof(*fmt));
1696+ *fmt = *__preview_get_format(prev, fh, PREV_PAD_SINK, which);
16661697
1667− /* The preview module output size is configurable through the
1668− * input interface (horizontal and vertical cropping) and the
1669− * averager (horizontal scaling by 1/1, 1/2, 1/4 or 1/8). In
1670− * spite of this, hardcode the output size to the biggest
1671− * possible value for simplicity reasons.
1672− */
16731698 switch (pixelcode) {
16741699 case V4L2_MBUS_FMT_YUYV8_1X16:
16751700 case V4L2_MBUS_FMT_UYVY8_1X16:
@@ -1681,31 +1706,14 @@ static void preview_try_format(struct isp_prev_device *prev, · 5 unmodified lines
16811706 break;
16821707 }
16831708
1684− /* The TRM states (12.1.4.7.1.2) that 2 pixels must be cropped
1685− * from the left and right sides when the input source is the
1686− * CCDC. This seems not to be needed in practice, investigation
1687− * is required.
1688− */
1689− if (prev->input == PREVIEW_INPUT_CCDC)
1690− fmt->width -= 4;
1691−
1692− /* The preview module can output a maximum of 3312 pixels
1693− * horizontally due to fixed memory-line sizes. Compute the
1694− * horizontal averaging factor accordingly. Note that the limit
1695− * applies to the noise filter and CFA interpolation blocks, so
1696− * it doesn't take cropping by further blocks into account.
1697− *
1698− * ES 1.0 hardware revision is limited to 1280 pixels
1699− * horizontally.
1700− */
1701− fmt->width >>= fls(DIV_ROUND_UP(fmt->width, max_out_width) - 1);
1702−
1703− /* Assume that all blocks are enabled and crop pixels and lines
1704− * accordingly. See preview_config_input_size() for more
1705− * information.
1709+ /* The preview module output size is configurable through the
1710+ * averager (horizontal scaling by 1/1, 1/2, 1/4 or 1/8). This
1711+ * is not supported yet, hardcode the output size to the crop
1712+ * rectangle size.
17061713 */
1707− fmt->width -= 14;
1708− fmt->height -= 8;
1714+ crop = __preview_get_crop(prev, fh, which);
1715+ fmt->width = crop->width;
1716+ fmt->height = crop->height;
17091717
17101718 fmt->colorspace = V4L2_COLORSPACE_JPEG;
17111719 break;
@@ -1714,6 +1722,49 @@ static void preview_try_format(struct isp_prev_device *prev, · 2 unmodified lines
17141722 fmt->field = V4L2_FIELD_NONE;
17151723 }
17161724
1725+/*
1726+ * preview_try_crop - Validate a crop rectangle
1727+ * @prev: ISP preview engine
1728+ * @sink: format on the sink pad
1729+ * @crop: crop rectangle to be validated
1730+ *
1731+ * The preview engine crops lines and columns for its internal operation,
1732+ * depending on which filters are enabled. Enforce minimum crop margins to
1733+ * handle that transparently for userspace.
1734+ *
1735+ * See the explanation at the PREV_MARGIN_* definitions for more details.
1736+ */
1737+static void preview_try_crop(struct isp_prev_device *prev,
1738+ const struct v4l2_mbus_framefmt *sink,
1739+ struct v4l2_rect *crop)
1740+{
1741+ unsigned int left = PREV_MARGIN_LEFT;
1742+ unsigned int right = sink->width - PREV_MARGIN_RIGHT;
1743+ unsigned int top = PREV_MARGIN_TOP;
1744+ unsigned int bottom = sink->height - PREV_MARGIN_BOTTOM;
1745+
1746+ /* When processing data on-the-fly from the CCDC, at least 2 pixels must
1747+ * be cropped from the left and right sides of the image. As we don't
1748+ * know which filters will be enabled, increase the left and right
1749+ * margins by two.
1750+ */
1751+ if (prev->input == PREVIEW_INPUT_CCDC) {
1752+ left += 2;
1753+ right -= 2;
1754+ }
1755+
1756+ /* Restrict left/top to even values to keep the Bayer pattern. */
1757+ crop->left &= ~1;
1758+ crop->top &= ~1;
1759+
1760+ crop->left = clamp_t(u32, crop->left, left, right - PREV_MIN_OUT_WIDTH);
1761+ crop->top = clamp_t(u32, crop->top, top, bottom - PREV_MIN_OUT_HEIGHT);
1762+ crop->width = clamp_t(u32, crop->width, PREV_MIN_OUT_WIDTH,
1763+ right - crop->left);
1764+ crop->height = clamp_t(u32, crop->height, PREV_MIN_OUT_HEIGHT,
1765+ bottom - crop->top);
1766+}
1767+
17171768 /*
17181769 * preview_enum_mbus_code - Handle pixel format enumeration
17191770 * @sd : pointer to v4l2 subdev structure
@@ -1775,6 +1826,60 @@ static int preview_enum_frame_size(struct v4l2_subdev *sd, · 55 unmodified lines
17751826 return 0;
17761827 }
17771828
1829+/*
1830+ * preview_get_crop - Retrieve the crop rectangle on a pad
1831+ * @sd: ISP preview V4L2 subdevice
1832+ * @fh: V4L2 subdev file handle
1833+ * @crop: crop rectangle
1834+ *
1835+ * Return 0 on success or a negative error code otherwise.
1836+ */
1837+static int preview_get_crop(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh,
1838+ struct v4l2_subdev_crop *crop)
1839+{
1840+ struct isp_prev_device *prev = v4l2_get_subdevdata(sd);
1841+
1842+ /* Cropping is only supported on the sink pad. */
1843+ if (crop->pad != PREV_PAD_SINK)
1844+ return -EINVAL;
1845+
1846+ crop->rect = *__preview_get_crop(prev, fh, crop->which);
1847+ return 0;
1848+}
1849+
1850+/*
1851+ * preview_set_crop - Retrieve the crop rectangle on a pad
1852+ * @sd: ISP preview V4L2 subdevice
1853+ * @fh: V4L2 subdev file handle
1854+ * @crop: crop rectangle
1855+ *
1856+ * Return 0 on success or a negative error code otherwise.
1857+ */
1858+static int preview_set_crop(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh,
1859+ struct v4l2_subdev_crop *crop)
1860+{
1861+ struct isp_prev_device *prev = v4l2_get_subdevdata(sd);
1862+ struct v4l2_mbus_framefmt *format;
1863+
1864+ /* Cropping is only supported on the sink pad. */
1865+ if (crop->pad != PREV_PAD_SINK)
1866+ return -EINVAL;
1867+
1868+ /* The crop rectangle can't be changed while streaming. */
1869+ if (prev->state != ISP_PIPELINE_STREAM_STOPPED)
1870+ return -EBUSY;
1871+
1872+ format = __preview_get_format(prev, fh, PREV_PAD_SINK, crop->which);
1873+ preview_try_crop(prev, format, &crop->rect);
1874+ *__preview_get_crop(prev, fh, crop->which) = crop->rect;
1875+
1876+ /* Update the source format. */
1877+ format = __preview_get_format(prev, fh, PREV_PAD_SOURCE, crop->which);
1878+ preview_try_format(prev, fh, PREV_PAD_SOURCE, format, crop->which);
1879+
1880+ return 0;
1881+}
1882+
17781883 /*
17791884 * preview_get_format - Handle get format by pads subdev method
17801885 * @sd : pointer to v4l2 subdev structure
@@ -1808,6 +1913,7 @@ static int preview_set_format(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh, · 27 unmodified lines
18081913 {
18091914 struct isp_prev_device *prev = v4l2_get_subdevdata(sd);
18101915 struct v4l2_mbus_framefmt *format;
1916+ struct v4l2_rect *crop;
18111917
18121918 format = __preview_get_format(prev, fh, fmt->pad, fmt->which);
18131919 if (format == NULL)
@@ -1818,9 +1924,18 @@ static int preview_set_format(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh, · 4 unmodified lines
18181924
18191925 /* Propagate the format from sink to source */
18201926 if (fmt->pad == PREV_PAD_SINK) {
1927+ /* Reset the crop rectangle. */
1928+ crop = __preview_get_crop(prev, fh, fmt->which);
1929+ crop->left = 0;
1930+ crop->top = 0;
1931+ crop->width = fmt->format.width;
1932+ crop->height = fmt->format.height;
1933+
1934+ preview_try_crop(prev, &fmt->format, crop);
1935+
1936+ /* Update the source format. */
18211937 format = __preview_get_format(prev, fh, PREV_PAD_SOURCE,
18221938 fmt->which);
1823− *format = fmt->format;
18241939 preview_try_format(prev, fh, PREV_PAD_SOURCE, format,
18251940 fmt->which);
18261941 }
@@ -1869,6 +1984,8 @@ static const struct v4l2_subdev_pad_ops preview_v4l2_pad_ops = { · 42 unmodified lines
18691984 .enum_frame_size = preview_enum_frame_size,
18701985 .get_fmt = preview_get_format,
18711986 .set_fmt = preview_set_format,
1987+ .get_crop = preview_get_crop,
1988+ .set_crop = preview_set_crop,
18721989 };
18731990
18741991 /* subdev operations */
@@ -1966,8 +2083,44 @@ static const struct media_entity_operations preview_media_ops = { · 91 unmodified lines
19662083 .link_setup = preview_link_setup,
19672084 };
19682085
2086+void omap3isp_preview_unregister_entities(struct isp_prev_device *prev)
2087+{
2088+ v4l2_device_unregister_subdev(&prev->subdev);
2089+ omap3isp_video_unregister(&prev->video_in);
2090+ omap3isp_video_unregister(&prev->video_out);
2091+}
2092+
2093+int omap3isp_preview_register_entities(struct isp_prev_device *prev,
2094+ struct v4l2_device *vdev)
2095+{
2096+ int ret;
2097+
2098+ /* Register the subdev and video nodes. */
2099+ ret = v4l2_device_register_subdev(vdev, &prev->subdev);
2100+ if (ret < 0)
2101+ goto error;
2102+
2103+ ret = omap3isp_video_register(&prev->video_in, vdev);
2104+ if (ret < 0)
2105+ goto error;
2106+
2107+ ret = omap3isp_video_register(&prev->video_out, vdev);
2108+ if (ret < 0)
2109+ goto error;
2110+
2111+ return 0;
2112+
2113+error:
2114+ omap3isp_preview_unregister_entities(prev);
2115+ return ret;
2116+}
2117+
2118+/* -----------------------------------------------------------------------------
2119+ * ISP previewer initialisation and cleanup
2120+ */
2121+
19692122 /*
1970− * review_init_entities - Initialize subdev and media entity.
2123+ * preview_init_entities - Initialize subdev and media entity.
19712124 * @prev : Pointer to preview structure
19722125 * return -ENOMEM or zero on success
19732126 */
@@ -2024,69 +2177,34 @@ static int preview_init_entities(struct isp_prev_device *prev) · 50 unmodified lines
20242177
20252178 ret = omap3isp_video_init(&prev->video_in, "preview");
20262179 if (ret < 0)
2027− return ret;
2180+ goto error_video_in;
20282181
20292182 ret = omap3isp_video_init(&prev->video_out, "preview");
20302183 if (ret < 0)
2031− return ret;
2184+ goto error_video_out;
20322185
20332186 /* Connect the video nodes to the previewer subdev. */
20342187 ret = media_entity_create_link(&prev->video_in.video.entity, 0,
20352188 &prev->subdev.entity, PREV_PAD_SINK, 0);
20362189 if (ret < 0)
2037− return ret;
2190+ goto error_link;
20382191
20392192 ret = media_entity_create_link(&prev->subdev.entity, PREV_PAD_SOURCE,
20402193 &prev->video_out.video.entity, 0, 0);
20412194 if (ret < 0)
2042− return ret;
2195+ goto error_link;
20432196
20442197 return 0;
2045−}
20462198
2047−void omap3isp_preview_unregister_entities(struct isp_prev_device *prev)
2048−{
2199+error_link:
2200+ omap3isp_video_cleanup(&prev->video_out);
2201+error_video_out:
2202+ omap3isp_video_cleanup(&prev->video_in);
2203+error_video_in:
20492204 media_entity_cleanup(&prev->subdev.entity);
2050−
2051− v4l2_device_unregister_subdev(&prev->subdev);
2052− v4l2_ctrl_handler_free(&prev->ctrls);
2053− omap3isp_video_unregister(&prev->video_in);
2054− omap3isp_video_unregister(&prev->video_out);
2055−}
2056−
2057−int omap3isp_preview_register_entities(struct isp_prev_device *prev,
2058− struct v4l2_device *vdev)
2059−{
2060− int ret;
2061−
2062− /* Register the subdev and video nodes. */
2063− ret = v4l2_device_register_subdev(vdev, &prev->subdev);
2064− if (ret < 0)
2065− goto error;
2066−
2067− ret = omap3isp_video_register(&prev->video_in, vdev);
2068− if (ret < 0)
2069− goto error;
2070−
2071− ret = omap3isp_video_register(&prev->video_out, vdev);
2072− if (ret < 0)
2073− goto error;
2074−
2075− return 0;
2076−
2077−error:
2078− omap3isp_preview_unregister_entities(prev);
20792205 return ret;
20802206 }
20812207
2082−/* -----------------------------------------------------------------------------
2083− * ISP previewer initialisation and cleanup
2084− */
2085−
2086−void omap3isp_preview_cleanup(struct isp_device *isp)
2087−{
2088−}
2089−
20902208 /*
20912209 * isp_preview_init - Previewer initialization.
20922210 * @dev : Pointer to ISP device
@@ -2095,19 +2213,20 @@ void omap3isp_preview_cleanup(struct isp_device *isp) · 2 unmodified lines
20952213 int omap3isp_preview_init(struct isp_device *isp)
20962214 {
20972215 struct isp_prev_device *prev = &isp->isp_prev;
2098− int ret;
20992216
21002217 spin_lock_init(&prev->lock);
21012218 init_waitqueue_head(&prev->wait);
21022219 preview_init_params(prev);
21032220
2104− ret = preview_init_entities(prev);
2105− if (ret < 0)
2106− goto out;
2221+ return preview_init_entities(prev);
2222+}
21072223
2108−out:
2109− if (ret)
2110− omap3isp_preview_cleanup(isp);
2224+void omap3isp_preview_cleanup(struct isp_device *isp)
2225+{
2226+ struct isp_prev_device *prev = &isp->isp_prev;
21112227
2112− return ret;
2228+ v4l2_ctrl_handler_free(&prev->ctrls);
2229+ omap3isp_video_cleanup(&prev->video_in);
2230+ omap3isp_video_cleanup(&prev->video_out);
2231+ media_entity_cleanup(&prev->subdev.entity);
21132232 }
drivers/media/video/omap3isp/isppreview.h+2−7
@@ -45,11 +45,6 @@ · 44 unmodified lines
4545 #define ISPPRV_CONTRAST_HIGH 0xFF
4646 #define ISPPRV_CONTRAST_UNITS 0x1
4747
48−#define NO_AVE 0x0
49−#define AVE_2_PIX 0x1
50−#define AVE_4_PIX 0x2
51−#define AVE_8_PIX 0x3
52−
5348 /* Features list */
5449 #define PREV_LUMA_ENHANCE OMAP3ISP_PREV_LUMAENH
5550 #define PREV_INVERSE_ALAW OMAP3ISP_PREV_INVALAW
@@ -106,7 +101,6 @@ enum preview_ycpos_mode { · 50 unmodified lines
106101 * @rgb2ycbcr: RGB to ycbcr parameters.
107102 * @hmed: Horizontal median filter.
108103 * @yclimit: YC limits parameters.
109− * @average: Downsampling rate for averager.
110104 * @contrast: Contrast.
111105 * @brightness: Brightness.
112106 */
@@ -124,7 +118,6 @@ struct prev_params { · 11 unmodified lines
124118 struct omap3isp_prev_csc rgb2ycbcr;
125119 struct omap3isp_prev_hmed hmed;
126120 struct omap3isp_prev_yclimit yclimit;
127− u8 average;
128121 u8 contrast;
129122 u8 brightness;
130123 };
@@ -159,6 +152,7 @@ struct isptables_update { · 28 unmodified lines
159152 * @subdev: V4L2 subdevice
160153 * @pads: Media entity pads
161154 * @formats: Active formats at the subdev pad
155+ * @crop: Active crop rectangle
162156 * @input: Module currently connected to the input pad
163157 * @output: Bitmask of the active output
164158 * @video_in: Input video entity
@@ -177,6 +171,7 @@ struct isp_prev_device { · 12 unmodified lines
177171 struct v4l2_subdev subdev;
178172 struct media_pad pads[PREV_PADS_NUM];
179173 struct v4l2_mbus_framefmt formats[PREV_PADS_NUM];
174+ struct v4l2_rect crop;
180175
181176 struct v4l2_ctrl_handler ctrls;
182177
drivers/media/video/omap3isp/ispreg.h+0−3
@@ -402,9 +402,6 @@ · 401 unmodified lines
402402 #define ISPPRV_YENH_TABLE_ADDR 0x1000
403403 #define ISPPRV_CFA_TABLE_ADDR 0x1400
404404
405−#define ISPPRV_MAXOUTPUT_WIDTH 1280
406−#define ISPPRV_MAXOUTPUT_WIDTH_ES2 3300
407−#define ISPPRV_MAXOUTPUT_WIDTH_3630 4096
408405 #define ISPRSZ_MIN_OUTPUT 64
409406 #define ISPRSZ_MAX_OUTPUT 3312
410407
drivers/media/video/omap3isp/ispresizer.c+53−51
@@ -1608,6 +1608,42 @@ static const struct media_entity_operations resizer_media_ops = { · 1607 unmodified lines
16081608 .link_setup = resizer_link_setup,
16091609 };
16101610
1611+void omap3isp_resizer_unregister_entities(struct isp_res_device *res)
1612+{
1613+ v4l2_device_unregister_subdev(&res->subdev);
1614+ omap3isp_video_unregister(&res->video_in);
1615+ omap3isp_video_unregister(&res->video_out);
1616+}
1617+
1618+int omap3isp_resizer_register_entities(struct isp_res_device *res,
1619+ struct v4l2_device *vdev)
1620+{
1621+ int ret;
1622+
1623+ /* Register the subdev and video nodes. */
1624+ ret = v4l2_device_register_subdev(vdev, &res->subdev);
1625+ if (ret < 0)
1626+ goto error;
1627+
1628+ ret = omap3isp_video_register(&res->video_in, vdev);
1629+ if (ret < 0)
1630+ goto error;
1631+
1632+ ret = omap3isp_video_register(&res->video_out, vdev);
1633+ if (ret < 0)
1634+ goto error;
1635+
1636+ return 0;
1637+
1638+error:
1639+ omap3isp_resizer_unregister_entities(res);
1640+ return ret;
1641+}
1642+
1643+/* -----------------------------------------------------------------------------
1644+ * ISP resizer initialization and cleanup
1645+ */
1646+
16111647 /*
16121648 * resizer_init_entities - Initialize resizer subdev and media entity.
16131649 * @res : Pointer to resizer device structure
@@ -1652,68 +1688,34 @@ static int resizer_init_entities(struct isp_res_device *res) · 38 unmodified lines
16521688
16531689 ret = omap3isp_video_init(&res->video_in, "resizer");
16541690 if (ret < 0)
1655− return ret;
1691+ goto error_video_in;
16561692
16571693 ret = omap3isp_video_init(&res->video_out, "resizer");
16581694 if (ret < 0)
1659− return ret;
1695+ goto error_video_out;
16601696
16611697 /* Connect the video nodes to the resizer subdev. */
16621698 ret = media_entity_create_link(&res->video_in.video.entity, 0,
16631699 &res->subdev.entity, RESZ_PAD_SINK, 0);
16641700 if (ret < 0)
1665− return ret;
1701+ goto error_link;
16661702
16671703 ret = media_entity_create_link(&res->subdev.entity, RESZ_PAD_SOURCE,
16681704 &res->video_out.video.entity, 0, 0);
16691705 if (ret < 0)
1670− return ret;
1706+ goto error_link;
16711707
16721708 return 0;
1673−}
16741709
1675−void omap3isp_resizer_unregister_entities(struct isp_res_device *res)
1676−{
1710+error_link:
1711+ omap3isp_video_cleanup(&res->video_out);
1712+error_video_out:
1713+ omap3isp_video_cleanup(&res->video_in);
1714+error_video_in:
16771715 media_entity_cleanup(&res->subdev.entity);
1678−
1679− v4l2_device_unregister_subdev(&res->subdev);
1680− omap3isp_video_unregister(&res->video_in);
1681− omap3isp_video_unregister(&res->video_out);
1682−}
1683−
1684−int omap3isp_resizer_register_entities(struct isp_res_device *res,
1685− struct v4l2_device *vdev)
1686−{
1687− int ret;
1688−
1689− /* Register the subdev and video nodes. */
1690− ret = v4l2_device_register_subdev(vdev, &res->subdev);
1691− if (ret < 0)
1692− goto error;
1693−
1694− ret = omap3isp_video_register(&res->video_in, vdev);
1695− if (ret < 0)
1696− goto error;
1697−
1698− ret = omap3isp_video_register(&res->video_out, vdev);
1699− if (ret < 0)
1700− goto error;
1701−
1702− return 0;
1703−
1704−error:
1705− omap3isp_resizer_unregister_entities(res);
17061716 return ret;
17071717 }
17081718
1709−/* -----------------------------------------------------------------------------
1710− * ISP resizer initialization and cleanup
1711− */
1712−
1713−void omap3isp_resizer_cleanup(struct isp_device *isp)
1714−{
1715−}
1716−
17171719 /*
17181720 * isp_resizer_init - Resizer initialization.
17191721 * @isp : Pointer to ISP device
@@ -1722,17 +1724,17 @@ void omap3isp_resizer_cleanup(struct isp_device *isp) · 2 unmodified lines
17221724 int omap3isp_resizer_init(struct isp_device *isp)
17231725 {
17241726 struct isp_res_device *res = &isp->isp_res;
1725− int ret;
17261727
17271728 init_waitqueue_head(&res->wait);
17281729 atomic_set(&res->stopping, 0);
1729− ret = resizer_init_entities(res);
1730− if (ret < 0)
1731− goto out;
1730+ return resizer_init_entities(res);
1731+}
17321732
1733−out:
1734− if (ret)
1735− omap3isp_resizer_cleanup(isp);
1733+void omap3isp_resizer_cleanup(struct isp_device *isp)
1734+{
1735+ struct isp_res_device *res = &isp->isp_res;
17361736
1737− return ret;
1737+ omap3isp_video_cleanup(&res->video_in);
1738+ omap3isp_video_cleanup(&res->video_out);
1739+ media_entity_cleanup(&res->subdev.entity);
17381740 }
drivers/media/video/omap3isp/ispstat.c+31−21
@@ -1023,24 +1023,6 @@ void omap3isp_stat_dma_isr(struct ispstat *stat) · 1022 unmodified lines
10231023 __stat_isr(stat, 1);
10241024 }
10251025
1026−static int isp_stat_init_entities(struct ispstat *stat, const char *name,
1027− const struct v4l2_subdev_ops *sd_ops)
1028−{
1029− struct v4l2_subdev *subdev = &stat->subdev;
1030− struct media_entity *me = &subdev->entity;
1031−
1032− v4l2_subdev_init(subdev, sd_ops);
1033− snprintf(subdev->name, V4L2_SUBDEV_NAME_SIZE, "OMAP3 ISP %s", name);
1034− subdev->grp_id = 1 << 16; /* group ID for isp subdevs */
1035− subdev->flags |= V4L2_SUBDEV_FL_HAS_EVENTS | V4L2_SUBDEV_FL_HAS_DEVNODE;
1036− v4l2_set_subdevdata(subdev, stat);
1037−
1038− stat->pad.flags = MEDIA_PAD_FL_SINK;
1039− me->ops = NULL;
1040−
1041− return media_entity_init(me, 1, &stat->pad, 0);
1042−}
1043−
10441026 int omap3isp_stat_subscribe_event(struct v4l2_subdev *subdev,
10451027 struct v4l2_fh *fh,
10461028 struct v4l2_event_subscription *sub)
@@ -1062,7 +1044,6 @@ int omap3isp_stat_unsubscribe_event(struct v4l2_subdev *subdev, · 15 unmodified lines
10621044
10631045 void omap3isp_stat_unregister_entities(struct ispstat *stat)
10641046 {
1065− media_entity_cleanup(&stat->subdev.entity);
10661047 v4l2_device_unregister_subdev(&stat->subdev);
10671048 }
10681049
@@ -1072,21 +1053,50 @@ int omap3isp_stat_register_entities(struct ispstat *stat, · 3 unmodified lines
10721053 return v4l2_device_register_subdev(vdev, &stat->subdev);
10731054 }
10741055
1056+static int isp_stat_init_entities(struct ispstat *stat, const char *name,
1057+ const struct v4l2_subdev_ops *sd_ops)
1058+{
1059+ struct v4l2_subdev *subdev = &stat->subdev;
1060+ struct media_entity *me = &subdev->entity;
1061+
1062+ v4l2_subdev_init(subdev, sd_ops);
1063+ snprintf(subdev->name, V4L2_SUBDEV_NAME_SIZE, "OMAP3 ISP %s", name);
1064+ subdev->grp_id = 1 << 16; /* group ID for isp subdevs */
1065+ subdev->flags |= V4L2_SUBDEV_FL_HAS_EVENTS | V4L2_SUBDEV_FL_HAS_DEVNODE;
1066+ v4l2_set_subdevdata(subdev, stat);
1067+
1068+ stat->pad.flags = MEDIA_PAD_FL_SINK;
1069+ me->ops = NULL;
1070+
1071+ return media_entity_init(me, 1, &stat->pad, 0);
1072+}
1073+
10751074 int omap3isp_stat_init(struct ispstat *stat, const char *name,
10761075 const struct v4l2_subdev_ops *sd_ops)
10771076 {
1077+ int ret;
1078+
10781079 stat->buf = kcalloc(STAT_MAX_BUFS, sizeof(*stat->buf), GFP_KERNEL);
10791080 if (!stat->buf)
10801081 return -ENOMEM;
1082+
10811083 isp_stat_buf_clear(stat);
10821084 mutex_init(&stat->ioctl_lock);
10831085 atomic_set(&stat->buf_err, 0);
10841086
1085− return isp_stat_init_entities(stat, name, sd_ops);
1087+ ret = isp_stat_init_entities(stat, name, sd_ops);
1088+ if (ret < 0) {
1089+ mutex_destroy(&stat->ioctl_lock);
1090+ kfree(stat->buf);
1091+ }
1092+
1093+ return ret;
10861094 }
10871095
1088−void omap3isp_stat_free(struct ispstat *stat)
1096+void omap3isp_stat_cleanup(struct ispstat *stat)
10891097 {
1098+ media_entity_cleanup(&stat->subdev.entity);
1099+ mutex_destroy(&stat->ioctl_lock);
10901100 isp_stat_bufs_free(stat);
10911101 kfree(stat->buf);
10921102 }
drivers/media/video/omap3isp/ispstat.h+1−1
@@ -144,7 +144,7 @@ int omap3isp_stat_request_statistics(struct ispstat *stat, · 143 unmodified lines
144144 struct omap3isp_stat_data *data);
145145 int omap3isp_stat_init(struct ispstat *stat, const char *name,
146146 const struct v4l2_subdev_ops *sd_ops);
147−void omap3isp_stat_free(struct ispstat *stat);
147+void omap3isp_stat_cleanup(struct ispstat *stat);
148148 int omap3isp_stat_subscribe_event(struct v4l2_subdev *subdev,
149149 struct v4l2_fh *fh,
150150 struct v4l2_event_subscription *sub);
drivers/media/video/omap3isp/ispvideo.c+8−3
@@ -1325,6 +1325,13 @@ int omap3isp_video_init(struct isp_video *video, const char *name) · 1324 unmodified lines
13251325 return 0;
13261326 }
13271327
1328+void omap3isp_video_cleanup(struct isp_video *video)
1329+{
1330+ media_entity_cleanup(&video->video.entity);
1331+ mutex_destroy(&video->stream_lock);
1332+ mutex_destroy(&video->mutex);
1333+}
1334+
13281335 int omap3isp_video_register(struct isp_video *video, struct v4l2_device *vdev)
13291336 {
13301337 int ret;
@@ -1341,8 +1348,6 @@ int omap3isp_video_register(struct isp_video *video, struct v4l2_device *vdev) · 10 unmodified lines
13411348
13421349 void omap3isp_video_unregister(struct isp_video *video)
13431350 {
1344− if (video_is_registered(&video->video)) {
1345− media_entity_cleanup(&video->video.entity);
1351+ if (video_is_registered(&video->video))
13461352 video_unregister_device(&video->video);
1347− }
13481353 }
drivers/media/video/omap3isp/ispvideo.h+1−0
@@ -190,6 +190,7 @@ struct isp_video_fh { · 189 unmodified lines
190190 container_of(q, struct isp_video_fh, queue)
191191
192192 int omap3isp_video_init(struct isp_video *video, const char *name);
193+void omap3isp_video_cleanup(struct isp_video *video);
193194 int omap3isp_video_register(struct isp_video *video,
194195 struct v4l2_device *vdev);
195196 void omap3isp_video_unregister(struct isp_video *video);
drivers/media/video/ov2640.c+52−126
@@ -18,11 +18,13 @@ · 17 unmodified lines
1818 #include <linux/i2c.h>
1919 #include <linux/slab.h>
2020 #include <linux/delay.h>
21+#include <linux/v4l2-mediabus.h>
2122 #include <linux/videodev2.h>
23+
24+#include <media/soc_camera.h>
2225 #include <media/v4l2-chip-ident.h>
2326 #include <media/v4l2-subdev.h>
24−#include <media/soc_camera.h>
25−#include <media/soc_mediabus.h>
27+#include <media/v4l2-ctrls.h>
2628
2729 #define VAL_SET(x, mask, rshift, lshift) \
2830 ((((x) >> rshift) & mask) << lshift)
@@ -299,12 +301,10 @@ struct ov2640_win_size { · 270 unmodified lines
299301
300302 struct ov2640_priv {
301303 struct v4l2_subdev subdev;
302− struct ov2640_camera_info *info;
304+ struct v4l2_ctrl_handler hdl;
303305 enum v4l2_mbus_pixelcode cfmt_code;
304306 const struct ov2640_win_size *win;
305307 int model;
306− u16 flag_vflip:1;
307− u16 flag_hflip:1;
308308 };
309309
310310 /*
@@ -609,29 +609,6 @@ static enum v4l2_mbus_pixelcode ov2640_codes[] = { · 298 unmodified lines
609609 V4L2_MBUS_FMT_RGB565_2X8_LE,
610610 };
611611
612−/*
613− * Supported controls
614− */
615−static const struct v4l2_queryctrl ov2640_controls[] = {
616− {
617− .id = V4L2_CID_VFLIP,
618− .type = V4L2_CTRL_TYPE_BOOLEAN,
619− .name = "Flip Vertically",
620− .minimum = 0,
621− .maximum = 1,
622− .step = 1,
623− .default_value = 0,
624− }, {
625− .id = V4L2_CID_HFLIP,
626− .type = V4L2_CTRL_TYPE_BOOLEAN,
627− .name = "Flip Horizontally",
628− .minimum = 0,
629− .maximum = 1,
630− .step = 1,
631− .default_value = 0,
632− },
633−};
634−
635612 /*
636613 * General functions
637614 */
@@ -701,81 +678,23 @@ static int ov2640_s_stream(struct v4l2_subdev *sd, int enable) · 63 unmodified lines
701678 return 0;
702679 }
703680
704−static int ov2640_set_bus_param(struct soc_camera_device *icd,
705− unsigned long flags)
706−{
707− struct soc_camera_link *icl = to_soc_camera_link(icd);
708− unsigned long width_flag = flags & SOCAM_DATAWIDTH_MASK;
709−
710− /* Only one width bit may be set */
711− if (!is_power_of_2(width_flag))
712− return -EINVAL;
713−
714− if (icl->set_bus_param)
715− return icl->set_bus_param(icl, width_flag);
716−
717− /*
718− * Without board specific bus width settings we support only the
719− * sensors native bus width witch are tested working
720− */
721− if (width_flag & (SOCAM_DATAWIDTH_10 | SOCAM_DATAWIDTH_8))
722− return 0;
723−
724− return 0;
725−}
726−
727−static unsigned long ov2640_query_bus_param(struct soc_camera_device *icd)
728−{
729− struct soc_camera_link *icl = to_soc_camera_link(icd);
730− unsigned long flags = SOCAM_PCLK_SAMPLE_RISING | SOCAM_MASTER |
731− SOCAM_VSYNC_ACTIVE_HIGH | SOCAM_HSYNC_ACTIVE_HIGH |
732− SOCAM_DATA_ACTIVE_HIGH;
733−
734− if (icl->query_bus_param)
735− flags |= icl->query_bus_param(icl) & SOCAM_DATAWIDTH_MASK;
736− else
737− flags |= SOCAM_DATAWIDTH_10;
738−
739− return soc_camera_apply_sensor_flags(icl, flags);
740−}
741−
742−static int ov2640_g_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
681+static int ov2640_s_ctrl(struct v4l2_ctrl *ctrl)
743682 {
683+ struct v4l2_subdev *sd =
684+ &container_of(ctrl->handler, struct ov2640_priv, hdl)->subdev;
744685 struct i2c_client *client = v4l2_get_subdevdata(sd);
745− struct ov2640_priv *priv = to_ov2640(client);
746−
747− switch (ctrl->id) {
748− case V4L2_CID_VFLIP:
749− ctrl->value = priv->flag_vflip;
750− break;
751− case V4L2_CID_HFLIP:
752− ctrl->value = priv->flag_hflip;
753− break;
754− }
755− return 0;
756−}
757−
758−static int ov2640_s_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
759−{
760− struct i2c_client *client = v4l2_get_subdevdata(sd);
761− struct ov2640_priv *priv = to_ov2640(client);
762− int ret = 0;
763686 u8 val;
764687
765688 switch (ctrl->id) {
766689 case V4L2_CID_VFLIP:
767− val = ctrl->value ? REG04_VFLIP_IMG : 0x00;
768− priv->flag_vflip = ctrl->value ? 1 : 0;
769− ret = ov2640_mask_set(client, REG04, REG04_VFLIP_IMG, val);
770− break;
690+ val = ctrl->val ? REG04_VFLIP_IMG : 0x00;
691+ return ov2640_mask_set(client, REG04, REG04_VFLIP_IMG, val);
771692 case V4L2_CID_HFLIP:
772− val = ctrl->value ? REG04_HFLIP_IMG : 0x00;
773− priv->flag_hflip = ctrl->value ? 1 : 0;
774− ret = ov2640_mask_set(client, REG04, REG04_HFLIP_IMG, val);
775− break;
693+ val = ctrl->val ? REG04_HFLIP_IMG : 0x00;
694+ return ov2640_mask_set(client, REG04, REG04_HFLIP_IMG, val);
776695 }
777696
778− return ret;
697+ return -EINVAL;
779698 }
780699
781700 static int ov2640_g_chip_ident(struct v4l2_subdev *sd,
@@ -1023,18 +942,13 @@ static int ov2640_cropcap(struct v4l2_subdev *sd, struct v4l2_cropcap *a) · 241 unmodified lines
1023942 return 0;
1024943 }
1025944
1026−static int ov2640_video_probe(struct soc_camera_device *icd,
1027− struct i2c_client *client)
945+static int ov2640_video_probe(struct i2c_client *client)
1028946 {
1029947 struct ov2640_priv *priv = to_ov2640(client);
1030948 u8 pid, ver, midh, midl;
1031949 const char *devname;
1032950 int ret;
1033951
1034− /* We must have a parent by now. And it cannot be a wrong one. */
1035− BUG_ON(!icd->parent ||
1036− to_soc_camera_host(icd->parent)->nr != icd->iface);
1037−
1038952 /*
1039953 * check and show product ID and manufacturer ID
1040954 */
@@ -1060,22 +974,17 @@ static int ov2640_video_probe(struct soc_camera_device *icd, · 19 unmodified lines
1060974 "%s Product ID %0x:%0x Manufacturer ID %x:%x\n",
1061975 devname, pid, ver, midh, midl);
1062976
1063− return 0;
977+ return v4l2_ctrl_handler_setup(&priv->hdl);
1064978
1065979 err:
1066980 return ret;
1067981 }
1068982
1069−static struct soc_camera_ops ov2640_ops = {
1070− .set_bus_param = ov2640_set_bus_param,
1071− .query_bus_param = ov2640_query_bus_param,
1072− .controls = ov2640_controls,
1073− .num_controls = ARRAY_SIZE(ov2640_controls),
983+static const struct v4l2_ctrl_ops ov2640_ctrl_ops = {
984+ .s_ctrl = ov2640_s_ctrl,
1074985 };
1075986
1076987 static struct v4l2_subdev_core_ops ov2640_subdev_core_ops = {
1077− .g_ctrl = ov2640_g_ctrl,
1078− .s_ctrl = ov2640_s_ctrl,
1079988 .g_chip_ident = ov2640_g_chip_ident,
1080989 #ifdef CONFIG_VIDEO_ADV_DEBUG
1081990 .g_register = ov2640_g_register,
@@ -1083,6 +992,21 @@ static struct v4l2_subdev_core_ops ov2640_subdev_core_ops = { · 1 unmodified line
1083992 #endif
1084993 };
1085994
995+static int ov2640_g_mbus_config(struct v4l2_subdev *sd,
996+ struct v4l2_mbus_config *cfg)
997+{
998+ struct i2c_client *client = v4l2_get_subdevdata(sd);
999+ struct soc_camera_link *icl = soc_camera_i2c_to_link(client);
1000+
1001+ cfg->flags = V4L2_MBUS_PCLK_SAMPLE_RISING | V4L2_MBUS_MASTER |
1002+ V4L2_MBUS_VSYNC_ACTIVE_HIGH | V4L2_MBUS_HSYNC_ACTIVE_HIGH |
1003+ V4L2_MBUS_DATA_ACTIVE_HIGH;
1004+ cfg->type = V4L2_MBUS_PARALLEL;
1005+ cfg->flags = soc_camera_apply_board_flags(icl, cfg);
1006+
1007+ return 0;
1008+}
1009+
10861010 static struct v4l2_subdev_video_ops ov2640_subdev_video_ops = {
10871011 .s_stream = ov2640_s_stream,
10881012 .g_mbus_fmt = ov2640_g_fmt,
@@ -1091,6 +1015,7 @@ static struct v4l2_subdev_video_ops ov2640_subdev_video_ops = { · 2 unmodified lines
10911015 .cropcap = ov2640_cropcap,
10921016 .g_crop = ov2640_g_crop,
10931017 .enum_mbus_fmt = ov2640_enum_fmt,
1018+ .g_mbus_config = ov2640_g_mbus_config,
10941019 };
10951020
10961021 static struct v4l2_subdev_ops ov2640_subdev_ops = {
@@ -1104,18 +1029,11 @@ static struct v4l2_subdev_ops ov2640_subdev_ops = { · 7 unmodified lines
11041029 static int ov2640_probe(struct i2c_client *client,
11051030 const struct i2c_device_id *did)
11061031 {
1107− struct ov2640_priv *priv;
1108− struct soc_camera_device *icd = client->dev.platform_data;
1109− struct i2c_adapter *adapter = to_i2c_adapter(client->dev.parent);
1110− struct soc_camera_link *icl;
1111− int ret;
1112−
1113− if (!icd) {
1114− dev_err(&adapter->dev, "OV2640: missing soc-camera data!\n");
1115− return -EINVAL;
1116− }
1032+ struct ov2640_priv *priv;
1033+ struct soc_camera_link *icl = soc_camera_i2c_to_link(client);
1034+ struct i2c_adapter *adapter = to_i2c_adapter(client->dev.parent);
1035+ int ret;
11171036
1118− icl = to_soc_camera_link(icd);
11191037 if (!icl) {
11201038 dev_err(&adapter->dev,
11211039 "OV2640: Missing platform_data for driver\n");
@@ -1135,15 +1053,23 @@ static int ov2640_probe(struct i2c_client *client, · 13 unmodified lines
11351053 return -ENOMEM;
11361054 }
11371055
1138− priv->info = icl->priv;
1139−
11401056 v4l2_i2c_subdev_init(&priv->subdev, client, &ov2640_subdev_ops);
1057+ v4l2_ctrl_handler_init(&priv->hdl, 2);
1058+ v4l2_ctrl_new_std(&priv->hdl, &ov2640_ctrl_ops,
1059+ V4L2_CID_VFLIP, 0, 1, 1, 0);
1060+ v4l2_ctrl_new_std(&priv->hdl, &ov2640_ctrl_ops,
1061+ V4L2_CID_HFLIP, 0, 1, 1, 0);
1062+ priv->subdev.ctrl_handler = &priv->hdl;
1063+ if (priv->hdl.error) {
1064+ int err = priv->hdl.error;
11411065
1142− icd->ops = &ov2640_ops;
1066+ kfree(priv);
1067+ return err;
1068+ }
11431069
1144− ret = ov2640_video_probe(icd, client);
1070+ ret = ov2640_video_probe(client);
11451071 if (ret) {
1146− icd->ops = NULL;
1072+ v4l2_ctrl_handler_free(&priv->hdl);
11471073 kfree(priv);
11481074 } else {
11491075 dev_info(&adapter->dev, "OV2640 Probed\n");
@@ -1155,9 +1081,9 @@ static int ov2640_probe(struct i2c_client *client, · 5 unmodified lines
11551081 static int ov2640_remove(struct i2c_client *client)
11561082 {
11571083 struct ov2640_priv *priv = to_ov2640(client);
1158− struct soc_camera_device *icd = client->dev.platform_data;
11591084
1160− icd->ops = NULL;
1085+ v4l2_device_unregister_subdev(&priv->subdev);
1086+ v4l2_ctrl_handler_free(&priv->hdl);
11611087 kfree(priv);
11621088 return 0;
11631089 }
drivers/media/video/ov5642.c+181−107
@@ -14,14 +14,16 @@ · 13 unmodified lines
1414 * published by the Free Software Foundation.
1515 */
1616
17+#include <linux/bitops.h>
1718 #include <linux/delay.h>
1819 #include <linux/i2c.h>
20+#include <linux/kernel.h>
1921 #include <linux/slab.h>
2022 #include <linux/videodev2.h>
2123 #include <linux/module.h>
24+#include <linux/v4l2-mediabus.h>
2225
2326 #include <media/soc_camera.h>
24−#include <media/soc_mediabus.h>
2527 #include <media/v4l2-chip-ident.h>
2628 #include <media/v4l2-subdev.h>
2729
@@ -35,7 +37,7 @@ · 7 unmodified lines
3537 #define REG_WINDOW_START_Y_LOW 0x3803
3638 #define REG_WINDOW_WIDTH_HIGH 0x3804
3739 #define REG_WINDOW_WIDTH_LOW 0x3805
38−#define REG_WINDOW_HEIGHT_HIGH 0x3806
40+#define REG_WINDOW_HEIGHT_HIGH 0x3806
3941 #define REG_WINDOW_HEIGHT_LOW 0x3807
4042 #define REG_OUT_WIDTH_HIGH 0x3808
4143 #define REG_OUT_WIDTH_LOW 0x3809
@@ -45,19 +47,44 @@ · 3 unmodified lines
4547 #define REG_OUT_TOTAL_WIDTH_LOW 0x380d
4648 #define REG_OUT_TOTAL_HEIGHT_HIGH 0x380e
4749 #define REG_OUT_TOTAL_HEIGHT_LOW 0x380f
50+#define REG_OUTPUT_FORMAT 0x4300
51+#define REG_ISP_CTRL_01 0x5001
52+#define REG_AVG_WINDOW_END_X_HIGH 0x5682
53+#define REG_AVG_WINDOW_END_X_LOW 0x5683
54+#define REG_AVG_WINDOW_END_Y_HIGH 0x5686
55+#define REG_AVG_WINDOW_END_Y_LOW 0x5687
56+
57+/* active pixel array size */
58+#define OV5642_SENSOR_SIZE_X 2592
59+#define OV5642_SENSOR_SIZE_Y 1944
4860
4961 /*
50− * define standard resolution.
51− * Works currently only for up to 720 lines
52− * eg. 320x240, 640x480, 800x600, 1280x720, 2048x720
62+ * About OV5642 resolution, cropping and binning:
63+ * This sensor supports it all, at least in the feature description.
64+ * Unfortunately, no combination of appropriate registers settings could make
65+ * the chip work the intended way. As it works with predefined register lists,
66+ * some undocumented registers are presumably changed there to achieve their
67+ * goals.
68+ * This driver currently only works for resolutions up to 720 lines with a
69+ * 1:1 scale. Hopefully these restrictions will be removed in the future.
5370 */
71+#define OV5642_MAX_WIDTH OV5642_SENSOR_SIZE_X
72+#define OV5642_MAX_HEIGHT 720
5473
55−#define OV5642_WIDTH 1280
56−#define OV5642_HEIGHT 720
57−#define OV5642_TOTAL_WIDTH 3200
58−#define OV5642_TOTAL_HEIGHT 2000
59−#define OV5642_SENSOR_SIZE_X 2592
60−#define OV5642_SENSOR_SIZE_Y 1944
74+/* default sizes */
75+#define OV5642_DEFAULT_WIDTH 1280
76+#define OV5642_DEFAULT_HEIGHT OV5642_MAX_HEIGHT
77+
78+/* minimum extra blanking */
79+#define BLANKING_EXTRA_WIDTH 500
80+#define BLANKING_EXTRA_HEIGHT 20
81+
82+/*
83+ * the sensor's autoexposure is buggy when setting total_height low.
84+ * It tries to expose longer than 1 frame period without taking care of it
85+ * and this leads to weird output. So we set 1000 lines as minimum.
86+ */
87+#define BLANKING_MIN_HEIGHT 1000
6188
6289 struct regval_list {
6390 u16 reg_num;
@@ -582,6 +609,11 @@ struct ov5642_datafmt { · 518 unmodified lines
582609 struct ov5642 {
583610 struct v4l2_subdev subdev;
584611 const struct ov5642_datafmt *fmt;
612+ struct v4l2_rect crop_rect;
613+
614+ /* blanking information */
615+ int total_width;
616+ int total_height;
585617 };
586618
587619 static const struct ov5642_datafmt ov5642_colour_fmts[] = {
@@ -642,6 +674,21 @@ static int reg_write(struct i2c_client *client, u16 reg, u8 val) · 54 unmodified lines
642674
643675 return 0;
644676 }
677+
678+/*
679+ * convenience function to write 16 bit register values that are split up
680+ * into two consecutive high and low parts
681+ */
682+static int reg_write16(struct i2c_client *client, u16 reg, u16 val16)
683+{
684+ int ret;
685+
686+ ret = reg_write(client, reg, val16 >> 8);
687+ if (ret)
688+ return ret;
689+ return reg_write(client, reg + 1, val16 & 0x00ff);
690+}
691+
645692 #ifdef CONFIG_VIDEO_ADV_DEBUG
646693 static int ov5642_get_register(struct v4l2_subdev *sd, struct v4l2_dbg_register *reg)
647694 {
@@ -685,58 +732,55 @@ static int ov5642_write_array(struct i2c_client *client, · 37 unmodified lines
685732 return 0;
686733 }
687734
688−static int ov5642_set_resolution(struct i2c_client *client)
735+static int ov5642_set_resolution(struct v4l2_subdev *sd)
689736 {
737+ struct i2c_client *client = v4l2_get_subdevdata(sd);
738+ struct ov5642 *priv = to_ov5642(client);
739+ int width = priv->crop_rect.width;
740+ int height = priv->crop_rect.height;
741+ int total_width = priv->total_width;
742+ int total_height = priv->total_height;
743+ int start_x = (OV5642_SENSOR_SIZE_X - width) / 2;
744+ int start_y = (OV5642_SENSOR_SIZE_Y - height) / 2;
690745 int ret;
691− u8 start_x_high = ((OV5642_SENSOR_SIZE_X - OV5642_WIDTH) / 2) >> 8;
692− u8 start_x_low = ((OV5642_SENSOR_SIZE_X - OV5642_WIDTH) / 2) & 0xff;
693− u8 start_y_high = ((OV5642_SENSOR_SIZE_Y - OV5642_HEIGHT) / 2) >> 8;
694− u8 start_y_low = ((OV5642_SENSOR_SIZE_Y - OV5642_HEIGHT) / 2) & 0xff;
695−
696− u8 width_high = OV5642_WIDTH >> 8;
697− u8 width_low = OV5642_WIDTH & 0xff;
698− u8 height_high = OV5642_HEIGHT >> 8;
699− u8 height_low = OV5642_HEIGHT & 0xff;
700−
701− u8 total_width_high = OV5642_TOTAL_WIDTH >> 8;
702− u8 total_width_low = OV5642_TOTAL_WIDTH & 0xff;
703− u8 total_height_high = OV5642_TOTAL_HEIGHT >> 8;
704− u8 total_height_low = OV5642_TOTAL_HEIGHT & 0xff;
705−
706− ret = reg_write(client, REG_WINDOW_START_X_HIGH, start_x_high);
707− if (!ret)
708− ret = reg_write(client, REG_WINDOW_START_X_LOW, start_x_low);
709− if (!ret)
710− ret = reg_write(client, REG_WINDOW_START_Y_HIGH, start_y_high);
711− if (!ret)
712− ret = reg_write(client, REG_WINDOW_START_Y_LOW, start_y_low);
713746
747+ /*
748+ * This should set the starting point for cropping.
749+ * Doesn't work so far.
750+ */
751+ ret = reg_write16(client, REG_WINDOW_START_X_HIGH, start_x);
714752 if (!ret)
715− ret = reg_write(client, REG_WINDOW_WIDTH_HIGH, width_high);
716− if (!ret)
717− ret = reg_write(client, REG_WINDOW_WIDTH_LOW , width_low);
718− if (!ret)
719− ret = reg_write(client, REG_WINDOW_HEIGHT_HIGH, height_high);
720− if (!ret)
721− ret = reg_write(client, REG_WINDOW_HEIGHT_LOW, height_low);
753+ ret = reg_write16(client, REG_WINDOW_START_Y_HIGH, start_y);
754+ if (!ret) {
755+ priv->crop_rect.left = start_x;
756+ priv->crop_rect.top = start_y;
757+ }
722758
723759 if (!ret)
724− ret = reg_write(client, REG_OUT_WIDTH_HIGH, width_high);
760+ ret = reg_write16(client, REG_WINDOW_WIDTH_HIGH, width);
725761 if (!ret)
726− ret = reg_write(client, REG_OUT_WIDTH_LOW , width_low);
727− if (!ret)
728− ret = reg_write(client, REG_OUT_HEIGHT_HIGH, height_high);
762+ ret = reg_write16(client, REG_WINDOW_HEIGHT_HIGH, height);
763+ if (ret)
764+ return ret;
765+ priv->crop_rect.width = width;
766+ priv->crop_rect.height = height;
767+
768+ /* Set the output window size. Only 1:1 scale is supported so far. */
769+ ret = reg_write16(client, REG_OUT_WIDTH_HIGH, width);
729770 if (!ret)
730− ret = reg_write(client, REG_OUT_HEIGHT_LOW, height_low);
771+ ret = reg_write16(client, REG_OUT_HEIGHT_HIGH, height);
731772
773+ /* Total width = output size + blanking */
732774 if (!ret)
733− ret = reg_write(client, REG_OUT_TOTAL_WIDTH_HIGH, total_width_high);
775+ ret = reg_write16(client, REG_OUT_TOTAL_WIDTH_HIGH, total_width);
734776 if (!ret)
735− ret = reg_write(client, REG_OUT_TOTAL_WIDTH_LOW, total_width_low);
777+ ret = reg_write16(client, REG_OUT_TOTAL_HEIGHT_HIGH, total_height);
778+
779+ /* Sets the window for AWB calculations */
736780 if (!ret)
737− ret = reg_write(client, REG_OUT_TOTAL_HEIGHT_HIGH, total_height_high);
781+ ret = reg_write16(client, REG_AVG_WINDOW_END_X_HIGH, width);
738782 if (!ret)
739− ret = reg_write(client, REG_OUT_TOTAL_HEIGHT_LOW, total_height_low);
783+ ret = reg_write16(client, REG_AVG_WINDOW_END_Y_HIGH, height);
740784
741785 return ret;
742786 }
@@ -744,18 +788,18 @@ static int ov5642_set_resolution(struct i2c_client *client) · 1 unmodified line
744788 static int ov5642_try_fmt(struct v4l2_subdev *sd,
745789 struct v4l2_mbus_framefmt *mf)
746790 {
791+ struct i2c_client *client = v4l2_get_subdevdata(sd);
792+ struct ov5642 *priv = to_ov5642(client);
747793 const struct ov5642_datafmt *fmt = ov5642_find_datafmt(mf->code);
748794
749− dev_dbg(sd->v4l2_dev->dev, "%s(%u) width: %u heigth: %u\n",
750− __func__, mf->code, mf->width, mf->height);
795+ mf->width = priv->crop_rect.width;
796+ mf->height = priv->crop_rect.height;
751797
752798 if (!fmt) {
753799 mf->code = ov5642_colour_fmts[0].code;
754800 mf->colorspace = ov5642_colour_fmts[0].colorspace;
755801 }
756802
757− mf->width = OV5642_WIDTH;
758− mf->height = OV5642_HEIGHT;
759803 mf->field = V4L2_FIELD_NONE;
760804
761805 return 0;
@@ -767,20 +811,13 @@ static int ov5642_s_fmt(struct v4l2_subdev *sd, · 5 unmodified lines
767811 struct i2c_client *client = v4l2_get_subdevdata(sd);
768812 struct ov5642 *priv = to_ov5642(client);
769813
770− dev_dbg(sd->v4l2_dev->dev, "%s(%u)\n", __func__, mf->code);
771−
772814 /* MIPI CSI could have changed the format, double-check */
773815 if (!ov5642_find_datafmt(mf->code))
774816 return -EINVAL;
775817
776818 ov5642_try_fmt(sd, mf);
777−
778819 priv->fmt = ov5642_find_datafmt(mf->code);
779820
780− ov5642_write_array(client, ov5642_default_regs_init);
781− ov5642_set_resolution(client);
782− ov5642_write_array(client, ov5642_default_regs_finalise);
783−
784821 return 0;
785822 }
786823
@@ -794,8 +831,8 @@ static int ov5642_g_fmt(struct v4l2_subdev *sd, · 7 unmodified lines
794831
795832 mf->code = fmt->code;
796833 mf->colorspace = fmt->colorspace;
797− mf->width = OV5642_WIDTH;
798− mf->height = OV5642_HEIGHT;
834+ mf->width = priv->crop_rect.width;
835+ mf->height = priv->crop_rect.height;
799836 mf->field = V4L2_FIELD_NONE;
800837
801838 return 0;
@@ -828,15 +865,44 @@ static int ov5642_g_chip_ident(struct v4l2_subdev *sd, · 26 unmodified lines
828865 return 0;
829866 }
830867
868+static int ov5642_s_crop(struct v4l2_subdev *sd, struct v4l2_crop *a)
869+{
870+ struct i2c_client *client = v4l2_get_subdevdata(sd);
871+ struct ov5642 *priv = to_ov5642(client);
872+ struct v4l2_rect *rect = &a->c;
873+ int ret;
874+
875+ v4l_bound_align_image(&rect->width, 48, OV5642_MAX_WIDTH, 1,
876+ &rect->height, 32, OV5642_MAX_HEIGHT, 1, 0);
877+
878+ priv->crop_rect.width = rect->width;
879+ priv->crop_rect.height = rect->height;
880+ priv->total_width = rect->width + BLANKING_EXTRA_WIDTH;
881+ priv->total_height = max_t(int, rect->height +
882+ BLANKING_EXTRA_HEIGHT,
883+ BLANKING_MIN_HEIGHT);
884+ priv->crop_rect.width = rect->width;
885+ priv->crop_rect.height = rect->height;
886+
887+ ret = ov5642_write_array(client, ov5642_default_regs_init);
888+ if (!ret)
889+ ret = ov5642_set_resolution(sd);
890+ if (!ret)
891+ ret = ov5642_write_array(client, ov5642_default_regs_finalise);
892+
893+ return ret;
894+}
895+
831896 static int ov5642_g_crop(struct v4l2_subdev *sd, struct v4l2_crop *a)
832897 {
898+ struct i2c_client *client = v4l2_get_subdevdata(sd);
899+ struct ov5642 *priv = to_ov5642(client);
833900 struct v4l2_rect *rect = &a->c;
834901
835− a->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
836− rect->top = 0;
837− rect->left = 0;
838− rect->width = OV5642_WIDTH;
839− rect->height = OV5642_HEIGHT;
902+ if (a->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
903+ return -EINVAL;
904+
905+ *rect = priv->crop_rect;
840906
841907 return 0;
842908 }
@@ -845,8 +911,8 @@ static int ov5642_cropcap(struct v4l2_subdev *sd, struct v4l2_cropcap *a) · 2 unmodified lines
845911 {
846912 a->bounds.left = 0;
847913 a->bounds.top = 0;
848− a->bounds.width = OV5642_WIDTH;
849− a->bounds.height = OV5642_HEIGHT;
914+ a->bounds.width = OV5642_MAX_WIDTH;
915+ a->bounds.height = OV5642_MAX_HEIGHT;
850916 a->defrect = a->bounds;
851917 a->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
852918 a->pixelaspect.numerator = 1;
@@ -855,16 +921,47 @@ static int ov5642_cropcap(struct v4l2_subdev *sd, struct v4l2_cropcap *a) · 2 unmodified lines
855921 return 0;
856922 }
857923
924+static int ov5642_g_mbus_config(struct v4l2_subdev *sd,
925+ struct v4l2_mbus_config *cfg)
926+{
927+ cfg->type = V4L2_MBUS_CSI2;
928+ cfg->flags = V4L2_MBUS_CSI2_2_LANE | V4L2_MBUS_CSI2_CHANNEL_0 |
929+ V4L2_MBUS_CSI2_CONTINUOUS_CLOCK;
930+
931+ return 0;
932+}
933+
934+static int ov5642_s_power(struct v4l2_subdev *sd, int on)
935+{
936+ struct i2c_client *client;
937+ int ret;
938+
939+ if (!on)
940+ return 0;
941+
942+ client = v4l2_get_subdevdata(sd);
943+ ret = ov5642_write_array(client, ov5642_default_regs_init);
944+ if (!ret)
945+ ret = ov5642_set_resolution(sd);
946+ if (!ret)
947+ ret = ov5642_write_array(client, ov5642_default_regs_finalise);
948+
949+ return ret;
950+}
951+
858952 static struct v4l2_subdev_video_ops ov5642_subdev_video_ops = {
859953 .s_mbus_fmt = ov5642_s_fmt,
860954 .g_mbus_fmt = ov5642_g_fmt,
861955 .try_mbus_fmt = ov5642_try_fmt,
862956 .enum_mbus_fmt = ov5642_enum_fmt,
957+ .s_crop = ov5642_s_crop,
863958 .g_crop = ov5642_g_crop,
864959 .cropcap = ov5642_cropcap,
960+ .g_mbus_config = ov5642_g_mbus_config,
865961 };
866962
867963 static struct v4l2_subdev_core_ops ov5642_subdev_core_ops = {
964+ .s_power = ov5642_s_power,
868965 .g_chip_ident = ov5642_g_chip_ident,
869966 #ifdef CONFIG_VIDEO_ADV_DEBUG
870967 .g_register = ov5642_get_register,
@@ -877,28 +974,7 @@ static struct v4l2_subdev_ops ov5642_subdev_ops = { · 6 unmodified lines
877974 .video = &ov5642_subdev_video_ops,
878975 };
879976
880−/*
881− * We have to provide soc-camera operations, but we don't have anything to say
882− * there. The MIPI CSI2 driver will provide .query_bus_param and .set_bus_param
883− */
884−static unsigned long soc_ov5642_query_bus_param(struct soc_camera_device *icd)
885−{
886− return 0;
887−}
888−
889−static int soc_ov5642_set_bus_param(struct soc_camera_device *icd,
890− unsigned long flags)
891−{
892− return -EINVAL;
893−}
894−
895−static struct soc_camera_ops soc_ov5642_ops = {
896− .query_bus_param = soc_ov5642_query_bus_param,
897− .set_bus_param = soc_ov5642_set_bus_param,
898−};
899−
900−static int ov5642_video_probe(struct soc_camera_device *icd,
901− struct i2c_client *client)
977+static int ov5642_video_probe(struct i2c_client *client)
902978 {
903979 int ret;
904980 u8 id_high, id_low;
@@ -929,16 +1005,9 @@ static int ov5642_probe(struct i2c_client *client, · 24 unmodified lines
9291005 const struct i2c_device_id *did)
9301006 {
9311007 struct ov5642 *priv;
932− struct soc_camera_device *icd = client->dev.platform_data;
933− struct soc_camera_link *icl;
1008+ struct soc_camera_link *icl = soc_camera_i2c_to_link(client);
9341009 int ret;
9351010
936− if (!icd) {
937− dev_err(&client->dev, "OV5642: missing soc-camera data!\n");
938− return -EINVAL;
939− }
940−
941− icl = to_soc_camera_link(icd);
9421011 if (!icl) {
9431012 dev_err(&client->dev, "OV5642: missing platform data!\n");
9441013 return -EINVAL;
@@ -950,17 +1019,24 @@ static int ov5642_probe(struct i2c_client *client, · 5 unmodified lines
9501019
9511020 v4l2_i2c_subdev_init(&priv->subdev, client, &ov5642_subdev_ops);
9521021
953− icd->ops = &soc_ov5642_ops;
954− priv->fmt = &ov5642_colour_fmts[0];
1022+ priv->fmt = &ov5642_colour_fmts[0];
1023+
1024+ priv->crop_rect.width = OV5642_DEFAULT_WIDTH;
1025+ priv->crop_rect.height = OV5642_DEFAULT_HEIGHT;
1026+ priv->crop_rect.left = (OV5642_MAX_WIDTH - OV5642_DEFAULT_WIDTH) / 2;
1027+ priv->crop_rect.top = (OV5642_MAX_HEIGHT - OV5642_DEFAULT_HEIGHT) / 2;
1028+ priv->crop_rect.width = OV5642_DEFAULT_WIDTH;
1029+ priv->crop_rect.height = OV5642_DEFAULT_HEIGHT;
1030+ priv->total_width = OV5642_DEFAULT_WIDTH + BLANKING_EXTRA_WIDTH;
1031+ priv->total_height = BLANKING_MIN_HEIGHT;
9551032
956− ret = ov5642_video_probe(icd, client);
1033+ ret = ov5642_video_probe(client);
9571034 if (ret < 0)
9581035 goto error;
9591036
9601037 return 0;
9611038
9621039 error:
963− icd->ops = NULL;
9641040 kfree(priv);
9651041 return ret;
9661042 }
@@ -968,10 +1044,8 @@ error: · 1 unmodified line
9681044 static int ov5642_remove(struct i2c_client *client)
9691045 {
9701046 struct ov5642 *priv = to_ov5642(client);
971− struct soc_camera_device *icd = client->dev.platform_data;
972− struct soc_camera_link *icl = to_soc_camera_link(icd);
1047+ struct soc_camera_link *icl = soc_camera_i2c_to_link(client);
9731048
974− icd->ops = NULL;
9751049 if (icl->free_bus)
9761050 icl->free_bus(icl);
9771051 kfree(priv);
drivers/media/video/ov6650.c+173−331
@@ -28,10 +28,11 @@ · 27 unmodified lines
2828 #include <linux/delay.h>
2929 #include <linux/i2c.h>
3030 #include <linux/slab.h>
31+#include <linux/v4l2-mediabus.h>
3132
3233 #include <media/soc_camera.h>
3334 #include <media/v4l2-chip-ident.h>
34−
35+#include <media/v4l2-ctrls.h>
3536
3637 /* Register definitions */
3738 #define REG_GAIN 0x00 /* range 00 - 3F */
@@ -177,20 +178,23 @@ struct ov6650_reg { · 139 unmodified lines
177178
178179 struct ov6650 {
179180 struct v4l2_subdev subdev;
180−
181− int gain;
182− int blue;
183− int red;
184− int saturation;
185− int hue;
186− int brightness;
187− int exposure;
188− int gamma;
189− int aec;
190− bool vflip;
191− bool hflip;
192− bool awb;
193− bool agc;
181+ struct v4l2_ctrl_handler hdl;
182+ struct {
183+ /* exposure/autoexposure cluster */
184+ struct v4l2_ctrl *autoexposure;
185+ struct v4l2_ctrl *exposure;
186+ };
187+ struct {
188+ /* gain/autogain cluster */
189+ struct v4l2_ctrl *autogain;
190+ struct v4l2_ctrl *gain;
191+ };
192+ struct {
193+ /* blue/red/autowhitebalance cluster */
194+ struct v4l2_ctrl *autowb;
195+ struct v4l2_ctrl *blue;
196+ struct v4l2_ctrl *red;
197+ };
194198 bool half_scale; /* scale down output by 2 */
195199 struct v4l2_rect rect; /* sensor cropping window */
196200 unsigned long pclk_limit; /* from host */
@@ -210,126 +214,6 @@ static enum v4l2_mbus_pixelcode ov6650_codes[] = { · 13 unmodified lines
210214 V4L2_MBUS_FMT_Y8_1X8,
211215 };
212216
213−static const struct v4l2_queryctrl ov6650_controls[] = {
214− {
215− .id = V4L2_CID_AUTOGAIN,
216− .type = V4L2_CTRL_TYPE_BOOLEAN,
217− .name = "AGC",
218− .minimum = 0,
219− .maximum = 1,
220− .step = 1,
221− .default_value = 1,
222− },
223− {
224− .id = V4L2_CID_GAIN,
225− .type = V4L2_CTRL_TYPE_INTEGER,
226− .name = "Gain",
227− .minimum = 0,
228− .maximum = 0x3f,
229− .step = 1,
230− .default_value = DEF_GAIN,
231− },
232− {
233− .id = V4L2_CID_AUTO_WHITE_BALANCE,
234− .type = V4L2_CTRL_TYPE_BOOLEAN,
235− .name = "AWB",
236− .minimum = 0,
237− .maximum = 1,
238− .step = 1,
239− .default_value = 1,
240− },
241− {
242− .id = V4L2_CID_BLUE_BALANCE,
243− .type = V4L2_CTRL_TYPE_INTEGER,
244− .name = "Blue",
245− .minimum = 0,
246− .maximum = 0xff,
247− .step = 1,
248− .default_value = DEF_BLUE,
249− },
250− {
251− .id = V4L2_CID_RED_BALANCE,
252− .type = V4L2_CTRL_TYPE_INTEGER,
253− .name = "Red",
254− .minimum = 0,
255− .maximum = 0xff,
256− .step = 1,
257− .default_value = DEF_RED,
258− },
259− {
260− .id = V4L2_CID_SATURATION,
261− .type = V4L2_CTRL_TYPE_INTEGER,
262− .name = "Saturation",
263− .minimum = 0,
264− .maximum = 0xf,
265− .step = 1,
266− .default_value = 0x8,
267− },
268− {
269− .id = V4L2_CID_HUE,
270− .type = V4L2_CTRL_TYPE_INTEGER,
271− .name = "Hue",
272− .minimum = 0,
273− .maximum = HUE_MASK,
274− .step = 1,
275− .default_value = DEF_HUE,
276− },
277− {
278− .id = V4L2_CID_BRIGHTNESS,
279− .type = V4L2_CTRL_TYPE_INTEGER,
280− .name = "Brightness",
281− .minimum = 0,
282− .maximum = 0xff,
283− .step = 1,
284− .default_value = 0x80,
285− },
286− {
287− .id = V4L2_CID_EXPOSURE_AUTO,
288− .type = V4L2_CTRL_TYPE_INTEGER,
289− .name = "AEC",
290− .minimum = 0,
291− .maximum = 3,
292− .step = 1,
293− .default_value = 0,
294− },
295− {
296− .id = V4L2_CID_EXPOSURE,
297− .type = V4L2_CTRL_TYPE_INTEGER,
298− .name = "Exposure",
299− .minimum = 0,
300− .maximum = 0xff,
301− .step = 1,
302− .default_value = DEF_AECH,
303− },
304− {
305− .id = V4L2_CID_GAMMA,
306− .type = V4L2_CTRL_TYPE_INTEGER,
307− .name = "Gamma",
308− .minimum = 0,
309− .maximum = 0xff,
310− .step = 1,
311− .default_value = 0x12,
312− },
313− {
314− .id = V4L2_CID_VFLIP,
315− .type = V4L2_CTRL_TYPE_BOOLEAN,
316− .name = "Flip Vertically",
317− .minimum = 0,
318− .maximum = 1,
319− .step = 1,
320− .default_value = 0,
321− },
322− {
323− .id = V4L2_CID_HFLIP,
324− .type = V4L2_CTRL_TYPE_BOOLEAN,
325− .name = "Flip Horizontally",
326− .minimum = 0,
327− .maximum = 1,
328− .step = 1,
329− .default_value = 0,
330− },
331−};
332−
333217 /* read a register */
334218 static int ov6650_reg_read(struct i2c_client *client, u8 reg, u8 *val)
335219 {
@@ -419,213 +303,90 @@ static int ov6650_s_stream(struct v4l2_subdev *sd, int enable) · 83 unmodified lines
419303 return 0;
420304 }
421305
422−/* Alter bus settings on camera side */
423−static int ov6650_set_bus_param(struct soc_camera_device *icd,
424− unsigned long flags)
425−{
426− struct soc_camera_link *icl = to_soc_camera_link(icd);
427− struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
428− int ret;
429−
430− flags = soc_camera_apply_sensor_flags(icl, flags);
431−
432− if (flags & SOCAM_PCLK_SAMPLE_RISING)
433− ret = ov6650_reg_rmw(client, REG_COMJ, COMJ_PCLK_RISING, 0);
434− else
435− ret = ov6650_reg_rmw(client, REG_COMJ, 0, COMJ_PCLK_RISING);
436− if (ret)
437− return ret;
438−
439− if (flags & SOCAM_HSYNC_ACTIVE_LOW)
440− ret = ov6650_reg_rmw(client, REG_COMF, COMF_HREF_LOW, 0);
441− else
442− ret = ov6650_reg_rmw(client, REG_COMF, 0, COMF_HREF_LOW);
443− if (ret)
444− return ret;
445−
446− if (flags & SOCAM_VSYNC_ACTIVE_HIGH)
447− ret = ov6650_reg_rmw(client, REG_COMJ, COMJ_VSYNC_HIGH, 0);
448− else
449− ret = ov6650_reg_rmw(client, REG_COMJ, 0, COMJ_VSYNC_HIGH);
450−
451− return ret;
452−}
453−
454−/* Request bus settings on camera side */
455−static unsigned long ov6650_query_bus_param(struct soc_camera_device *icd)
456−{
457− struct soc_camera_link *icl = to_soc_camera_link(icd);
458−
459− unsigned long flags = SOCAM_MASTER |
460− SOCAM_PCLK_SAMPLE_RISING | SOCAM_PCLK_SAMPLE_FALLING |
461− SOCAM_HSYNC_ACTIVE_HIGH | SOCAM_HSYNC_ACTIVE_LOW |
462− SOCAM_VSYNC_ACTIVE_HIGH | SOCAM_VSYNC_ACTIVE_LOW |
463− SOCAM_DATA_ACTIVE_HIGH | SOCAM_DATAWIDTH_8;
464−
465− return soc_camera_apply_sensor_flags(icl, flags);
466−}
467−
468306 /* Get status of additional camera capabilities */
469−static int ov6650_g_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
307+static int ov6550_g_volatile_ctrl(struct v4l2_ctrl *ctrl)
470308 {
309+ struct ov6650 *priv = container_of(ctrl->handler, struct ov6650, hdl);
310+ struct v4l2_subdev *sd = &priv->subdev;
471311 struct i2c_client *client = v4l2_get_subdevdata(sd);
472− struct ov6650 *priv = to_ov6650(client);
473− uint8_t reg;
474− int ret = 0;
312+ uint8_t reg, reg2;
313+ int ret;
475314
476315 switch (ctrl->id) {
477316 case V4L2_CID_AUTOGAIN:
478− ctrl->value = priv->agc;
479− break;
480− case V4L2_CID_GAIN:
481− if (priv->agc) {
482− ret = ov6650_reg_read(client, REG_GAIN, &reg);
483− ctrl->value = reg;
484− } else {
485− ctrl->value = priv->gain;
486− }
487− break;
317+ ret = ov6650_reg_read(client, REG_GAIN, &reg);
318+ if (!ret)
319+ priv->gain->val = reg;
320+ return ret;
488321 case V4L2_CID_AUTO_WHITE_BALANCE:
489− ctrl->value = priv->awb;
490− break;
491− case V4L2_CID_BLUE_BALANCE:
492− if (priv->awb) {
493− ret = ov6650_reg_read(client, REG_BLUE, &reg);
494− ctrl->value = reg;
495− } else {
496− ctrl->value = priv->blue;
497− }
498− break;
499− case V4L2_CID_RED_BALANCE:
500− if (priv->awb) {
501− ret = ov6650_reg_read(client, REG_RED, &reg);
502− ctrl->value = reg;
503− } else {
504− ctrl->value = priv->red;
322+ ret = ov6650_reg_read(client, REG_BLUE, &reg);
323+ if (!ret)
324+ ret = ov6650_reg_read(client, REG_RED, &reg2);
325+ if (!ret) {
326+ priv->blue->val = reg;
327+ priv->red->val = reg2;
505328 }
506− break;
507− case V4L2_CID_SATURATION:
508− ctrl->value = priv->saturation;
509− break;
510− case V4L2_CID_HUE:
511− ctrl->value = priv->hue;
512− break;
513− case V4L2_CID_BRIGHTNESS:
514− ctrl->value = priv->brightness;
515− break;
329+ return ret;
516330 case V4L2_CID_EXPOSURE_AUTO:
517− ctrl->value = priv->aec;
518− break;
519− case V4L2_CID_EXPOSURE:
520− if (priv->aec) {
521− ret = ov6650_reg_read(client, REG_AECH, &reg);
522− ctrl->value = reg;
523− } else {
524− ctrl->value = priv->exposure;
525− }
526− break;
527− case V4L2_CID_GAMMA:
528− ctrl->value = priv->gamma;
529− break;
530− case V4L2_CID_VFLIP:
531− ctrl->value = priv->vflip;
532− break;
533− case V4L2_CID_HFLIP:
534− ctrl->value = priv->hflip;
535− break;
331+ ret = ov6650_reg_read(client, REG_AECH, &reg);
332+ if (!ret)
333+ priv->exposure->val = reg;
334+ return ret;
536335 }
537− return ret;
336+ return -EINVAL;
538337 }
539338
540339 /* Set status of additional camera capabilities */
541−static int ov6650_s_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
340+static int ov6550_s_ctrl(struct v4l2_ctrl *ctrl)
542341 {
342+ struct ov6650 *priv = container_of(ctrl->handler, struct ov6650, hdl);
343+ struct v4l2_subdev *sd = &priv->subdev;
543344 struct i2c_client *client = v4l2_get_subdevdata(sd);
544− struct ov6650 *priv = to_ov6650(client);
545− int ret = 0;
345+ int ret;
546346
547347 switch (ctrl->id) {
548348 case V4L2_CID_AUTOGAIN:
549349 ret = ov6650_reg_rmw(client, REG_COMB,
550− ctrl->value ? COMB_AGC : 0, COMB_AGC);
551− if (!ret)
552− priv->agc = ctrl->value;
553− break;
554− case V4L2_CID_GAIN:
555− ret = ov6650_reg_write(client, REG_GAIN, ctrl->value);
556− if (!ret)
557− priv->gain = ctrl->value;
558− break;
350+ ctrl->val ? COMB_AGC : 0, COMB_AGC);
351+ if (!ret && !ctrl->val)
352+ ret = ov6650_reg_write(client, REG_GAIN, priv->gain->val);
353+ return ret;
559354 case V4L2_CID_AUTO_WHITE_BALANCE:
560355 ret = ov6650_reg_rmw(client, REG_COMB,
561− ctrl->value ? COMB_AWB : 0, COMB_AWB);
562− if (!ret)
563− priv->awb = ctrl->value;
564− break;
565− case V4L2_CID_BLUE_BALANCE:
566− ret = ov6650_reg_write(client, REG_BLUE, ctrl->value);
567− if (!ret)
568− priv->blue = ctrl->value;
569− break;
570− case V4L2_CID_RED_BALANCE:
571− ret = ov6650_reg_write(client, REG_RED, ctrl->value);
572− if (!ret)
573− priv->red = ctrl->value;
574− break;
356+ ctrl->val ? COMB_AWB : 0, COMB_AWB);
357+ if (!ret && !ctrl->val) {
358+ ret = ov6650_reg_write(client, REG_BLUE, priv->blue->val);
359+ if (!ret)
360+ ret = ov6650_reg_write(client, REG_RED,
361+ priv->red->val);
362+ }
363+ return ret;
575364 case V4L2_CID_SATURATION:
576− ret = ov6650_reg_rmw(client, REG_SAT, SET_SAT(ctrl->value),
365+ return ov6650_reg_rmw(client, REG_SAT, SET_SAT(ctrl->val),
577366 SAT_MASK);
578− if (!ret)
579− priv->saturation = ctrl->value;
580− break;
581367 case V4L2_CID_HUE:
582− ret = ov6650_reg_rmw(client, REG_HUE, SET_HUE(ctrl->value),
368+ return ov6650_reg_rmw(client, REG_HUE, SET_HUE(ctrl->val),
583369 HUE_MASK);
584− if (!ret)
585− priv->hue = ctrl->value;
586− break;
587370 case V4L2_CID_BRIGHTNESS:
588− ret = ov6650_reg_write(client, REG_BRT, ctrl->value);
589− if (!ret)
590− priv->brightness = ctrl->value;
591− break;
371+ return ov6650_reg_write(client, REG_BRT, ctrl->val);
592372 case V4L2_CID_EXPOSURE_AUTO:
593− switch (ctrl->value) {
594− case V4L2_EXPOSURE_AUTO:
595− ret = ov6650_reg_rmw(client, REG_COMB, COMB_AEC, 0);
596− break;
597− default:
598− ret = ov6650_reg_rmw(client, REG_COMB, 0, COMB_AEC);
599− break;
600− }
601− if (!ret)
602− priv->aec = ctrl->value;
603− break;
604− case V4L2_CID_EXPOSURE:
605− ret = ov6650_reg_write(client, REG_AECH, ctrl->value);
606− if (!ret)
607− priv->exposure = ctrl->value;
608− break;
373+ ret = ov6650_reg_rmw(client, REG_COMB, ctrl->val ==
374+ V4L2_EXPOSURE_AUTO ? COMB_AEC : 0, COMB_AEC);
375+ if (!ret && ctrl->val == V4L2_EXPOSURE_MANUAL)
376+ ret = ov6650_reg_write(client, REG_AECH,
377+ priv->exposure->val);
378+ return ret;
609379 case V4L2_CID_GAMMA:
610− ret = ov6650_reg_write(client, REG_GAM1, ctrl->value);
611− if (!ret)
612− priv->gamma = ctrl->value;
613− break;
380+ return ov6650_reg_write(client, REG_GAM1, ctrl->val);
614381 case V4L2_CID_VFLIP:
615− ret = ov6650_reg_rmw(client, REG_COMB,
616− ctrl->value ? COMB_FLIP_V : 0, COMB_FLIP_V);
617− if (!ret)
618− priv->vflip = ctrl->value;
619− break;
382+ return ov6650_reg_rmw(client, REG_COMB,
383+ ctrl->val ? COMB_FLIP_V : 0, COMB_FLIP_V);
620384 case V4L2_CID_HFLIP:
621− ret = ov6650_reg_rmw(client, REG_COMB,
622− ctrl->value ? COMB_FLIP_H : 0, COMB_FLIP_H);
623− if (!ret)
624− priv->hflip = ctrl->value;
625− break;
385+ return ov6650_reg_rmw(client, REG_COMB,
386+ ctrl->val ? COMB_FLIP_H : 0, COMB_FLIP_H);
626387 }
627388
628− return ret;
389+ return -EINVAL;
629390 }
630391
631392 /* Get chip identification */
@@ -778,7 +539,7 @@ static u8 to_clkrc(struct v4l2_fract *timeperframe, · 146 unmodified lines
778539 static int ov6650_s_fmt(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf)
779540 {
780541 struct i2c_client *client = v4l2_get_subdevdata(sd);
781− struct soc_camera_device *icd = client->dev.platform_data;
542+ struct soc_camera_device *icd = (struct soc_camera_device *)sd->grp_id;
782543 struct soc_camera_sense *sense = icd->sense;
783544 struct ov6650 *priv = to_ov6650(client);
784545 bool half_scale = !is_unscaled_ok(mf->width, mf->height, &priv->rect);
@@ -1057,8 +818,7 @@ static int ov6650_prog_dflt(struct i2c_client *client) · 272 unmodified lines
1057818 return ret;
1058819 }
1059820
1060−static int ov6650_video_probe(struct soc_camera_device *icd,
1061− struct i2c_client *client)
821+static int ov6650_video_probe(struct i2c_client *client)
1062822 {
1063823 u8 pidh, pidl, midh, midl;
1064824 int ret = 0;
@@ -1094,16 +854,12 @@ static int ov6650_video_probe(struct soc_camera_device *icd, · 29 unmodified lines
1094854 return ret;
1095855 }
1096856
1097−static struct soc_camera_ops ov6650_ops = {
1098− .set_bus_param = ov6650_set_bus_param,
1099− .query_bus_param = ov6650_query_bus_param,
1100− .controls = ov6650_controls,
1101− .num_controls = ARRAY_SIZE(ov6650_controls),
857+static const struct v4l2_ctrl_ops ov6550_ctrl_ops = {
858+ .g_volatile_ctrl = ov6550_g_volatile_ctrl,
859+ .s_ctrl = ov6550_s_ctrl,
1102860 };
1103861
1104862 static struct v4l2_subdev_core_ops ov6650_core_ops = {
1105− .g_ctrl = ov6650_g_ctrl,
1106− .s_ctrl = ov6650_s_ctrl,
1107863 .g_chip_ident = ov6650_g_chip_ident,
1108864 #ifdef CONFIG_VIDEO_ADV_DEBUG
1109865 .g_register = ov6650_get_register,
@@ -1111,6 +867,55 @@ static struct v4l2_subdev_core_ops ov6650_core_ops = { · 1 unmodified line
1111867 #endif
1112868 };
1113869
870+/* Request bus settings on camera side */
871+static int ov6650_g_mbus_config(struct v4l2_subdev *sd,
872+ struct v4l2_mbus_config *cfg)
873+{
874+ struct i2c_client *client = v4l2_get_subdevdata(sd);
875+ struct soc_camera_link *icl = soc_camera_i2c_to_link(client);
876+
877+ cfg->flags = V4L2_MBUS_MASTER |
878+ V4L2_MBUS_PCLK_SAMPLE_RISING | V4L2_MBUS_PCLK_SAMPLE_FALLING |
879+ V4L2_MBUS_HSYNC_ACTIVE_HIGH | V4L2_MBUS_HSYNC_ACTIVE_LOW |
880+ V4L2_MBUS_VSYNC_ACTIVE_HIGH | V4L2_MBUS_VSYNC_ACTIVE_LOW |
881+ V4L2_MBUS_DATA_ACTIVE_HIGH;
882+ cfg->type = V4L2_MBUS_PARALLEL;
883+ cfg->flags = soc_camera_apply_board_flags(icl, cfg);
884+
885+ return 0;
886+}
887+
888+/* Alter bus settings on camera side */
889+static int ov6650_s_mbus_config(struct v4l2_subdev *sd,
890+ const struct v4l2_mbus_config *cfg)
891+{
892+ struct i2c_client *client = v4l2_get_subdevdata(sd);
893+ struct soc_camera_link *icl = soc_camera_i2c_to_link(client);
894+ unsigned long flags = soc_camera_apply_board_flags(icl, cfg);
895+ int ret;
896+
897+ if (flags & V4L2_MBUS_PCLK_SAMPLE_RISING)
898+ ret = ov6650_reg_rmw(client, REG_COMJ, COMJ_PCLK_RISING, 0);
899+ else
900+ ret = ov6650_reg_rmw(client, REG_COMJ, 0, COMJ_PCLK_RISING);
901+ if (ret)
902+ return ret;
903+
904+ if (flags & V4L2_MBUS_HSYNC_ACTIVE_LOW)
905+ ret = ov6650_reg_rmw(client, REG_COMF, COMF_HREF_LOW, 0);
906+ else
907+ ret = ov6650_reg_rmw(client, REG_COMF, 0, COMF_HREF_LOW);
908+ if (ret)
909+ return ret;
910+
911+ if (flags & V4L2_MBUS_VSYNC_ACTIVE_HIGH)
912+ ret = ov6650_reg_rmw(client, REG_COMJ, COMJ_VSYNC_HIGH, 0);
913+ else
914+ ret = ov6650_reg_rmw(client, REG_COMJ, 0, COMJ_VSYNC_HIGH);
915+
916+ return ret;
917+}
918+
1114919 static struct v4l2_subdev_video_ops ov6650_video_ops = {
1115920 .s_stream = ov6650_s_stream,
1116921 .g_mbus_fmt = ov6650_g_fmt,
@@ -1122,6 +927,8 @@ static struct v4l2_subdev_video_ops ov6650_video_ops = { · 5 unmodified lines
1122927 .s_crop = ov6650_s_crop,
1123928 .g_parm = ov6650_g_parm,
1124929 .s_parm = ov6650_s_parm,
930+ .g_mbus_config = ov6650_g_mbus_config,
931+ .s_mbus_config = ov6650_s_mbus_config,
1125932 };
1126933
1127934 static struct v4l2_subdev_ops ov6650_subdev_ops = {
@@ -1136,16 +943,9 @@ static int ov6650_probe(struct i2c_client *client, · 8 unmodified lines
1136943 const struct i2c_device_id *did)
1137944 {
1138945 struct ov6650 *priv;
1139− struct soc_camera_device *icd = client->dev.platform_data;
1140− struct soc_camera_link *icl;
946+ struct soc_camera_link *icl = soc_camera_i2c_to_link(client);
1141947 int ret;
1142948
1143− if (!icd) {
1144− dev_err(&client->dev, "Missing soc-camera data!\n");
1145− return -EINVAL;
1146− }
1147−
1148− icl = to_soc_camera_link(icd);
1149949 if (!icl) {
1150950 dev_err(&client->dev, "Missing platform_data for driver\n");
1151951 return -EINVAL;
@@ -1159,8 +959,46 @@ static int ov6650_probe(struct i2c_client *client, · 7 unmodified lines
1159959 }
1160960
1161961 v4l2_i2c_subdev_init(&priv->subdev, client, &ov6650_subdev_ops);
962+ v4l2_ctrl_handler_init(&priv->hdl, 13);
963+ v4l2_ctrl_new_std(&priv->hdl, &ov6550_ctrl_ops,
964+ V4L2_CID_VFLIP, 0, 1, 1, 0);
965+ v4l2_ctrl_new_std(&priv->hdl, &ov6550_ctrl_ops,
966+ V4L2_CID_HFLIP, 0, 1, 1, 0);
967+ priv->autogain = v4l2_ctrl_new_std(&priv->hdl, &ov6550_ctrl_ops,
968+ V4L2_CID_AUTOGAIN, 0, 1, 1, 1);
969+ priv->gain = v4l2_ctrl_new_std(&priv->hdl, &ov6550_ctrl_ops,
970+ V4L2_CID_GAIN, 0, 0x3f, 1, DEF_GAIN);
971+ priv->autowb = v4l2_ctrl_new_std(&priv->hdl, &ov6550_ctrl_ops,
972+ V4L2_CID_AUTO_WHITE_BALANCE, 0, 1, 1, 1);
973+ priv->blue = v4l2_ctrl_new_std(&priv->hdl, &ov6550_ctrl_ops,
974+ V4L2_CID_BLUE_BALANCE, 0, 0xff, 1, DEF_BLUE);
975+ priv->red = v4l2_ctrl_new_std(&priv->hdl, &ov6550_ctrl_ops,
976+ V4L2_CID_RED_BALANCE, 0, 0xff, 1, DEF_RED);
977+ v4l2_ctrl_new_std(&priv->hdl, &ov6550_ctrl_ops,
978+ V4L2_CID_SATURATION, 0, 0xf, 1, 0x8);
979+ v4l2_ctrl_new_std(&priv->hdl, &ov6550_ctrl_ops,
980+ V4L2_CID_HUE, 0, HUE_MASK, 1, DEF_HUE);
981+ v4l2_ctrl_new_std(&priv->hdl, &ov6550_ctrl_ops,
982+ V4L2_CID_BRIGHTNESS, 0, 0xff, 1, 0x80);
983+ priv->autoexposure = v4l2_ctrl_new_std_menu(&priv->hdl,
984+ &ov6550_ctrl_ops, V4L2_CID_EXPOSURE_AUTO,
985+ V4L2_EXPOSURE_MANUAL, 0, V4L2_EXPOSURE_AUTO);
986+ priv->exposure = v4l2_ctrl_new_std(&priv->hdl, &ov6550_ctrl_ops,
987+ V4L2_CID_EXPOSURE, 0, 0xff, 1, DEF_AECH);
988+ v4l2_ctrl_new_std(&priv->hdl, &ov6550_ctrl_ops,
989+ V4L2_CID_GAMMA, 0, 0xff, 1, 0x12);
990+
991+ priv->subdev.ctrl_handler = &priv->hdl;
992+ if (priv->hdl.error) {
993+ int err = priv->hdl.error;
1162994
1163− icd->ops = &ov6650_ops;
995+ kfree(priv);
996+ return err;
997+ }
998+ v4l2_ctrl_auto_cluster(2, &priv->autogain, 0, true);
999+ v4l2_ctrl_auto_cluster(3, &priv->autowb, 0, true);
1000+ v4l2_ctrl_auto_cluster(2, &priv->autoexposure,
1001+ V4L2_EXPOSURE_MANUAL, true);
11641002
11651003 priv->rect.left = DEF_HSTRT << 1;
11661004 priv->rect.top = DEF_VSTRT << 1;
@@ -1170,10 +1008,12 @@ static int ov6650_probe(struct i2c_client *client, · 3 unmodified lines
11701008 priv->code = V4L2_MBUS_FMT_YUYV8_2X8;
11711009 priv->colorspace = V4L2_COLORSPACE_JPEG;
11721010
1173− ret = ov6650_video_probe(icd, client);
1011+ ret = ov6650_video_probe(client);
1012+ if (!ret)
1013+ ret = v4l2_ctrl_handler_setup(&priv->hdl);
11741014
11751015 if (ret) {
1176− icd->ops = NULL;
1016+ v4l2_ctrl_handler_free(&priv->hdl);
11771017 kfree(priv);
11781018 }
11791019
@@ -1184,6 +1024,8 @@ static int ov6650_remove(struct i2c_client *client) · 4 unmodified lines
11841024 {
11851025 struct ov6650 *priv = to_ov6650(client);
11861026
1027+ v4l2_device_unregister_subdev(&priv->subdev);
1028+ v4l2_ctrl_handler_free(&priv->hdl);
11871029 kfree(priv);
11881030 return 0;
11891031 }
drivers/media/video/ov772x.c+69−129
@@ -20,12 +20,14 @@ · 19 unmodified lines
2020 #include <linux/i2c.h>
2121 #include <linux/slab.h>
2222 #include <linux/delay.h>
23+#include <linux/v4l2-mediabus.h>
2324 #include <linux/videodev2.h>
25+
26+#include <media/ov772x.h>
27+#include <media/soc_camera.h>
28+#include <media/v4l2-ctrls.h>
2429 #include <media/v4l2-chip-ident.h>
2530 #include <media/v4l2-subdev.h>
26−#include <media/soc_camera.h>
27−#include <media/soc_mediabus.h>
28−#include <media/ov772x.h>
2931
3032 /*
3133 * register offset
@@ -400,6 +402,7 @@ struct ov772x_win_size { · 368 unmodified lines
400402
401403 struct ov772x_priv {
402404 struct v4l2_subdev subdev;
405+ struct v4l2_ctrl_handler hdl;
403406 struct ov772x_camera_info *info;
404407 const struct ov772x_color_format *cfmt;
405408 const struct ov772x_win_size *win;
@@ -517,36 +520,6 @@ static const struct ov772x_win_size ov772x_win_qvga = { · 111 unmodified lines
517520 .regs = ov772x_qvga_regs,
518521 };
519522
520−static const struct v4l2_queryctrl ov772x_controls[] = {
521− {
522− .id = V4L2_CID_VFLIP,
523− .type = V4L2_CTRL_TYPE_BOOLEAN,
524− .name = "Flip Vertically",
525− .minimum = 0,
526− .maximum = 1,
527− .step = 1,
528− .default_value = 0,
529− },
530− {
531− .id = V4L2_CID_HFLIP,
532− .type = V4L2_CTRL_TYPE_BOOLEAN,
533− .name = "Flip Horizontally",
534− .minimum = 0,
535− .maximum = 1,
536− .step = 1,
537− .default_value = 0,
538− },
539− {
540− .id = V4L2_CID_BAND_STOP_FILTER,
541− .type = V4L2_CTRL_TYPE_INTEGER,
542− .name = "Band-stop filter",
543− .minimum = 0,
544− .maximum = 256,
545− .step = 1,
546− .default_value = 0,
547− },
548−};
549−
550523 /*
551524 * general function
552525 */
@@ -620,75 +593,30 @@ static int ov772x_s_stream(struct v4l2_subdev *sd, int enable) · 67 unmodified lines
620593 return 0;
621594 }
622595
623−static int ov772x_set_bus_param(struct soc_camera_device *icd,
624− unsigned long flags)
625−{
626− return 0;
627−}
628−
629−static unsigned long ov772x_query_bus_param(struct soc_camera_device *icd)
630−{
631− struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
632− struct ov772x_priv *priv = i2c_get_clientdata(client);
633− struct soc_camera_link *icl = to_soc_camera_link(icd);
634− unsigned long flags = SOCAM_PCLK_SAMPLE_RISING | SOCAM_MASTER |
635− SOCAM_VSYNC_ACTIVE_HIGH | SOCAM_HSYNC_ACTIVE_HIGH |
636− SOCAM_DATA_ACTIVE_HIGH;
637−
638− if (priv->info->flags & OV772X_FLAG_8BIT)
639− flags |= SOCAM_DATAWIDTH_8;
640− else
641− flags |= SOCAM_DATAWIDTH_10;
642−
643− return soc_camera_apply_sensor_flags(icl, flags);
644−}
645−
646−static int ov772x_g_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
647−{
648− struct ov772x_priv *priv = container_of(sd, struct ov772x_priv, subdev);
649−
650− switch (ctrl->id) {
651− case V4L2_CID_VFLIP:
652− ctrl->value = priv->flag_vflip;
653− break;
654− case V4L2_CID_HFLIP:
655− ctrl->value = priv->flag_hflip;
656− break;
657− case V4L2_CID_BAND_STOP_FILTER:
658− ctrl->value = priv->band_filter;
659− break;
660− }
661− return 0;
662−}
663−
664−static int ov772x_s_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
596+static int ov772x_s_ctrl(struct v4l2_ctrl *ctrl)
665597 {
598+ struct ov772x_priv *priv = container_of(ctrl->handler,
599+ struct ov772x_priv, hdl);
600+ struct v4l2_subdev *sd = &priv->subdev;
666601 struct i2c_client *client = v4l2_get_subdevdata(sd);
667− struct ov772x_priv *priv = container_of(sd, struct ov772x_priv, subdev);
668602 int ret = 0;
669603 u8 val;
670604
671605 switch (ctrl->id) {
672606 case V4L2_CID_VFLIP:
673− val = ctrl->value ? VFLIP_IMG : 0x00;
674− priv->flag_vflip = ctrl->value;
607+ val = ctrl->val ? VFLIP_IMG : 0x00;
608+ priv->flag_vflip = ctrl->val;
675609 if (priv->info->flags & OV772X_FLAG_VFLIP)
676610 val ^= VFLIP_IMG;
677− ret = ov772x_mask_set(client, COM3, VFLIP_IMG, val);
678− break;
611+ return ov772x_mask_set(client, COM3, VFLIP_IMG, val);
679612 case V4L2_CID_HFLIP:
680− val = ctrl->value ? HFLIP_IMG : 0x00;
681− priv->flag_hflip = ctrl->value;
613+ val = ctrl->val ? HFLIP_IMG : 0x00;
614+ priv->flag_hflip = ctrl->val;
682615 if (priv->info->flags & OV772X_FLAG_HFLIP)
683616 val ^= HFLIP_IMG;
684− ret = ov772x_mask_set(client, COM3, HFLIP_IMG, val);
685− break;
617+ return ov772x_mask_set(client, COM3, HFLIP_IMG, val);
686618 case V4L2_CID_BAND_STOP_FILTER:
687− if ((unsigned)ctrl->value > 256)
688− ctrl->value = 256;
689− if (ctrl->value == priv->band_filter)
690− break;
691− if (!ctrl->value) {
619+ if (!ctrl->val) {
692620 /* Switch the filter off, it is on now */
693621 ret = ov772x_mask_set(client, BDBASE, 0xff, 0xff);
694622 if (!ret)
@@ -696,7 +624,7 @@ static int ov772x_s_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl) · 1 unmodified line
696624 BNDF_ON_OFF, 0);
697625 } else {
698626 /* Switch the filter on, set AEC low limit */
699− val = 256 - ctrl->value;
627+ val = 256 - ctrl->val;
700628 ret = ov772x_mask_set(client, COM8,
701629 BNDF_ON_OFF, BNDF_ON_OFF);
702630 if (!ret)
@@ -704,11 +632,11 @@ static int ov772x_s_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl) · 1 unmodified line
704632 0xff, val);
705633 }
706634 if (!ret)
707− priv->band_filter = ctrl->value;
708− break;
635+ priv->band_filter = ctrl->val;
636+ return ret;
709637 }
710638
711− return ret;
639+ return -EINVAL;
712640 }
713641
714642 static int ov772x_g_chip_ident(struct v4l2_subdev *sd,
@@ -822,13 +750,13 @@ static int ov772x_set_params(struct i2c_client *client, u32 *width, u32 *height, · 107 unmodified lines
822750 goto ov772x_set_fmt_error;
823751
824752 ret = ov772x_mask_set(client,
825− EDGE_TRSHLD, EDGE_THRESHOLD_MASK,
753+ EDGE_TRSHLD, OV772X_EDGE_THRESHOLD_MASK,
826754 priv->info->edgectrl.threshold);
827755 if (ret < 0)
828756 goto ov772x_set_fmt_error;
829757
830758 ret = ov772x_mask_set(client,
831− EDGE_STRNGT, EDGE_STRENGTH_MASK,
759+ EDGE_STRNGT, OV772X_EDGE_STRENGTH_MASK,
832760 priv->info->edgectrl.strength);
833761 if (ret < 0)
834762 goto ov772x_set_fmt_error;
@@ -840,13 +768,13 @@ static int ov772x_set_params(struct i2c_client *client, u32 *width, u32 *height, · 5 unmodified lines
840768 * set upper and lower limit
841769 */
842770 ret = ov772x_mask_set(client,
843− EDGE_UPPER, EDGE_UPPER_MASK,
771+ EDGE_UPPER, OV772X_EDGE_UPPER_MASK,
844772 priv->info->edgectrl.upper);
845773 if (ret < 0)
846774 goto ov772x_set_fmt_error;
847775
848776 ret = ov772x_mask_set(client,
849− EDGE_LOWER, EDGE_LOWER_MASK,
777+ EDGE_LOWER, OV772X_EDGE_LOWER_MASK,
850778 priv->info->edgectrl.lower);
851779 if (ret < 0)
852780 goto ov772x_set_fmt_error;
@@ -1025,17 +953,12 @@ static int ov772x_try_fmt(struct v4l2_subdev *sd, · 172 unmodified lines
1025953 return 0;
1026954 }
1027955
1028−static int ov772x_video_probe(struct soc_camera_device *icd,
1029− struct i2c_client *client)
956+static int ov772x_video_probe(struct i2c_client *client)
1030957 {
1031958 struct ov772x_priv *priv = to_ov772x(client);
1032959 u8 pid, ver;
1033960 const char *devname;
1034961
1035− /* We must have a parent by now. And it cannot be a wrong one. */
1036− BUG_ON(!icd->parent ||
1037− to_soc_camera_host(icd->parent)->nr != icd->iface);
1038−
1039962 /*
1040963 * check and show product ID and manufacturer ID
1041964 */
@@ -1064,20 +987,14 @@ static int ov772x_video_probe(struct soc_camera_device *icd, · 22 unmodified lines
1064987 ver,
1065988 i2c_smbus_read_byte_data(client, MIDH),
1066989 i2c_smbus_read_byte_data(client, MIDL));
1067−
1068− return 0;
990+ return v4l2_ctrl_handler_setup(&priv->hdl);
1069991 }
1070992
1071−static struct soc_camera_ops ov772x_ops = {
1072− .set_bus_param = ov772x_set_bus_param,
1073− .query_bus_param = ov772x_query_bus_param,
1074− .controls = ov772x_controls,
1075− .num_controls = ARRAY_SIZE(ov772x_controls),
993+static const struct v4l2_ctrl_ops ov772x_ctrl_ops = {
994+ .s_ctrl = ov772x_s_ctrl,
1076995 };
1077996
1078997 static struct v4l2_subdev_core_ops ov772x_subdev_core_ops = {
1079− .g_ctrl = ov772x_g_ctrl,
1080− .s_ctrl = ov772x_s_ctrl,
1081998 .g_chip_ident = ov772x_g_chip_ident,
1082999 #ifdef CONFIG_VIDEO_ADV_DEBUG
10831000 .g_register = ov772x_g_register,
@@ -1095,6 +1012,21 @@ static int ov772x_enum_fmt(struct v4l2_subdev *sd, unsigned int index, · 11 unmodified lines
10951012 return 0;
10961013 }
10971014
1015+static int ov772x_g_mbus_config(struct v4l2_subdev *sd,
1016+ struct v4l2_mbus_config *cfg)
1017+{
1018+ struct i2c_client *client = v4l2_get_subdevdata(sd);
1019+ struct soc_camera_link *icl = soc_camera_i2c_to_link(client);
1020+
1021+ cfg->flags = V4L2_MBUS_PCLK_SAMPLE_RISING | V4L2_MBUS_MASTER |
1022+ V4L2_MBUS_VSYNC_ACTIVE_HIGH | V4L2_MBUS_HSYNC_ACTIVE_HIGH |
1023+ V4L2_MBUS_DATA_ACTIVE_HIGH;
1024+ cfg->type = V4L2_MBUS_PARALLEL;
1025+ cfg->flags = soc_camera_apply_board_flags(icl, cfg);
1026+
1027+ return 0;
1028+}
1029+
10981030 static struct v4l2_subdev_video_ops ov772x_subdev_video_ops = {
10991031 .s_stream = ov772x_s_stream,
11001032 .g_mbus_fmt = ov772x_g_fmt,
@@ -1103,6 +1035,7 @@ static struct v4l2_subdev_video_ops ov772x_subdev_video_ops = { · 2 unmodified lines
11031035 .cropcap = ov772x_cropcap,
11041036 .g_crop = ov772x_g_crop,
11051037 .enum_mbus_fmt = ov772x_enum_fmt,
1038+ .g_mbus_config = ov772x_g_mbus_config,
11061039 };
11071040
11081041 static struct v4l2_subdev_ops ov772x_subdev_ops = {
@@ -1117,20 +1050,15 @@ static struct v4l2_subdev_ops ov772x_subdev_ops = { · 8 unmodified lines
11171050 static int ov772x_probe(struct i2c_client *client,
11181051 const struct i2c_device_id *did)
11191052 {
1120− struct ov772x_priv *priv;
1121− struct soc_camera_device *icd = client->dev.platform_data;
1122− struct i2c_adapter *adapter = to_i2c_adapter(client->dev.parent);
1123− struct soc_camera_link *icl;
1124− int ret;
1125−
1126− if (!icd) {
1127− dev_err(&client->dev, "OV772X: missing soc-camera data!\n");
1128− return -EINVAL;
1129− }
1053+ struct ov772x_priv *priv;
1054+ struct soc_camera_link *icl = soc_camera_i2c_to_link(client);
1055+ struct i2c_adapter *adapter = to_i2c_adapter(client->dev.parent);
1056+ int ret;
11301057
1131− icl = to_soc_camera_link(icd);
1132− if (!icl || !icl->priv)
1058+ if (!icl || !icl->priv) {
1059+ dev_err(&client->dev, "OV772X: missing platform data!\n");
11331060 return -EINVAL;
1061+ }
11341062
11351063 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) {
11361064 dev_err(&adapter->dev,
@@ -1146,12 +1074,24 @@ static int ov772x_probe(struct i2c_client *client, · 9 unmodified lines
11461074 priv->info = icl->priv;
11471075
11481076 v4l2_i2c_subdev_init(&priv->subdev, client, &ov772x_subdev_ops);
1077+ v4l2_ctrl_handler_init(&priv->hdl, 3);
1078+ v4l2_ctrl_new_std(&priv->hdl, &ov772x_ctrl_ops,
1079+ V4L2_CID_VFLIP, 0, 1, 1, 0);
1080+ v4l2_ctrl_new_std(&priv->hdl, &ov772x_ctrl_ops,
1081+ V4L2_CID_HFLIP, 0, 1, 1, 0);
1082+ v4l2_ctrl_new_std(&priv->hdl, &ov772x_ctrl_ops,
1083+ V4L2_CID_BAND_STOP_FILTER, 0, 256, 1, 0);
1084+ priv->subdev.ctrl_handler = &priv->hdl;
1085+ if (priv->hdl.error) {
1086+ int err = priv->hdl.error;
11491087
1150− icd->ops = &ov772x_ops;
1088+ kfree(priv);
1089+ return err;
1090+ }
11511091
1152− ret = ov772x_video_probe(icd, client);
1092+ ret = ov772x_video_probe(client);
11531093 if (ret) {
1154− icd->ops = NULL;
1094+ v4l2_ctrl_handler_free(&priv->hdl);
11551095 kfree(priv);
11561096 }
11571097
@@ -1161,9 +1101,9 @@ static int ov772x_probe(struct i2c_client *client, · 3 unmodified lines
11611101 static int ov772x_remove(struct i2c_client *client)
11621102 {
11631103 struct ov772x_priv *priv = to_ov772x(client);
1164− struct soc_camera_device *icd = client->dev.platform_data;
11651104
1166− icd->ops = NULL;
1105+ v4l2_device_unregister_subdev(&priv->subdev);
1106+ v4l2_ctrl_handler_free(&priv->hdl);
11671107 kfree(priv);
11681108 return 0;
11691109 }
drivers/media/video/ov9640.c+60−126
@@ -24,10 +24,13 @@ · 23 unmodified lines
2424 #include <linux/i2c.h>
2525 #include <linux/slab.h>
2626 #include <linux/delay.h>
27+#include <linux/v4l2-mediabus.h>
2728 #include <linux/videodev2.h>
29+
30+#include <media/soc_camera.h>
2831 #include <media/v4l2-chip-ident.h>
2932 #include <media/v4l2-common.h>
30−#include <media/soc_camera.h>
33+#include <media/v4l2-ctrls.h>
3134
3235 #include "ov9640.h"
3336
@@ -162,27 +165,6 @@ static enum v4l2_mbus_pixelcode ov9640_codes[] = { · 128 unmodified lines
162165 V4L2_MBUS_FMT_RGB565_2X8_LE,
163166 };
164167
165−static const struct v4l2_queryctrl ov9640_controls[] = {
166− {
167− .id = V4L2_CID_VFLIP,
168− .type = V4L2_CTRL_TYPE_BOOLEAN,
169− .name = "Flip Vertically",
170− .minimum = 0,
171− .maximum = 1,
172− .step = 1,
173− .default_value = 0,
174− },
175− {
176− .id = V4L2_CID_HFLIP,
177− .type = V4L2_CTRL_TYPE_BOOLEAN,
178− .name = "Flip Horizontally",
179− .minimum = 0,
180− .maximum = 1,
181− .step = 1,
182− .default_value = 0,
183− },
184−};
185−
186168 /* read a register */
187169 static int ov9640_reg_read(struct i2c_client *client, u8 reg, u8 *val)
188170 {
@@ -284,75 +266,25 @@ static int ov9640_s_stream(struct v4l2_subdev *sd, int enable) · 95 unmodified lines
284266 return 0;
285267 }
286268
287−/* Alter bus settings on camera side */
288−static int ov9640_set_bus_param(struct soc_camera_device *icd,
289− unsigned long flags)
290−{
291− return 0;
292−}
293−
294−/* Request bus settings on camera side */
295−static unsigned long ov9640_query_bus_param(struct soc_camera_device *icd)
296−{
297− struct soc_camera_link *icl = to_soc_camera_link(icd);
298−
299− /*
300− * REVISIT: the camera probably can do 10 bit transfers, but I don't
301− * have those pins connected on my hardware.
302− */
303− unsigned long flags = SOCAM_PCLK_SAMPLE_RISING | SOCAM_MASTER |
304− SOCAM_VSYNC_ACTIVE_HIGH | SOCAM_HSYNC_ACTIVE_HIGH |
305− SOCAM_DATA_ACTIVE_HIGH | SOCAM_DATAWIDTH_8;
306−
307− return soc_camera_apply_sensor_flags(icl, flags);
308−}
309−
310−/* Get status of additional camera capabilities */
311−static int ov9640_g_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
312−{
313− struct ov9640_priv *priv = to_ov9640_sensor(sd);
314−
315− switch (ctrl->id) {
316− case V4L2_CID_VFLIP:
317− ctrl->value = priv->flag_vflip;
318− break;
319− case V4L2_CID_HFLIP:
320− ctrl->value = priv->flag_hflip;
321− break;
322− }
323− return 0;
324−}
325−
326269 /* Set status of additional camera capabilities */
327−static int ov9640_s_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
270+static int ov9640_s_ctrl(struct v4l2_ctrl *ctrl)
328271 {
329− struct i2c_client *client = v4l2_get_subdevdata(sd);
330− struct ov9640_priv *priv = to_ov9640_sensor(sd);
331−
332− int ret = 0;
272+ struct ov9640_priv *priv = container_of(ctrl->handler, struct ov9640_priv, hdl);
273+ struct i2c_client *client = v4l2_get_subdevdata(&priv->subdev);
333274
334275 switch (ctrl->id) {
335276 case V4L2_CID_VFLIP:
336− priv->flag_vflip = ctrl->value;
337− if (ctrl->value)
338− ret = ov9640_reg_rmw(client, OV9640_MVFP,
277+ if (ctrl->val)
278+ return ov9640_reg_rmw(client, OV9640_MVFP,
339279 OV9640_MVFP_V, 0);
340− else
341− ret = ov9640_reg_rmw(client, OV9640_MVFP,
342− 0, OV9640_MVFP_V);
343− break;
280+ return ov9640_reg_rmw(client, OV9640_MVFP, 0, OV9640_MVFP_V);
344281 case V4L2_CID_HFLIP:
345− priv->flag_hflip = ctrl->value;
346− if (ctrl->value)
347− ret = ov9640_reg_rmw(client, OV9640_MVFP,
282+ if (ctrl->val)
283+ return ov9640_reg_rmw(client, OV9640_MVFP,
348284 OV9640_MVFP_H, 0);
349− else
350− ret = ov9640_reg_rmw(client, OV9640_MVFP,
351− 0, OV9640_MVFP_H);
352− break;
285+ return ov9640_reg_rmw(client, OV9640_MVFP, 0, OV9640_MVFP_H);
353286 }
354−
355− return ret;
287+ return -EINVAL;
356288 }
357289
358290 /* Get chip identification */
@@ -646,10 +578,7 @@ static int ov9640_cropcap(struct v4l2_subdev *sd, struct v4l2_cropcap *a) · 287 unmodified lines
646578 return 0;
647579 }
648580
649−
650−
651−static int ov9640_video_probe(struct soc_camera_device *icd,
652− struct i2c_client *client)
581+static int ov9640_video_probe(struct i2c_client *client)
653582 {
654583 struct v4l2_subdev *sd = i2c_get_clientdata(client);
655584 struct ov9640_priv *priv = to_ov9640_sensor(sd);
@@ -657,29 +586,19 @@ static int ov9640_video_probe(struct soc_camera_device *icd, · 1 unmodified line
657586 const char *devname;
658587 int ret = 0;
659588
660− /* We must have a parent by now. And it cannot be a wrong one. */
661− BUG_ON(!icd->parent ||
662− to_soc_camera_host(icd->parent)->nr != icd->iface);
663−
664589 /*
665590 * check and show product ID and manufacturer ID
666591 */
667592
668593 ret = ov9640_reg_read(client, OV9640_PID, &pid);
594+ if (!ret)
595+ ret = ov9640_reg_read(client, OV9640_VER, &ver);
596+ if (!ret)
597+ ret = ov9640_reg_read(client, OV9640_MIDH, &midh);
598+ if (!ret)
599+ ret = ov9640_reg_read(client, OV9640_MIDL, &midl);
669600 if (ret)
670− goto err;
671−
672− ret = ov9640_reg_read(client, OV9640_VER, &ver);
673− if (ret)
674− goto err;
675−
676− ret = ov9640_reg_read(client, OV9640_MIDH, &midh);
677− if (ret)
678− goto err;
679−
680− ret = ov9640_reg_read(client, OV9640_MIDL, &midl);
681− if (ret)
682− goto err;
601+ return ret;
683602
684603 switch (VERSION(pid, ver)) {
685604 case OV9640_V2:
@@ -693,27 +612,20 @@ static int ov9640_video_probe(struct soc_camera_device *icd, · 7 unmodified lines
693612 break;
694613 default:
695614 dev_err(&client->dev, "Product ID error %x:%x\n", pid, ver);
696− ret = -ENODEV;
697− goto err;
615+ return -ENODEV;
698616 }
699617
700618 dev_info(&client->dev, "%s Product ID %0x:%0x Manufacturer ID %x:%x\n",
701619 devname, pid, ver, midh, midl);
702620
703−err:
704− return ret;
621+ return v4l2_ctrl_handler_setup(&priv->hdl);
705622 }
706623
707−static struct soc_camera_ops ov9640_ops = {
708− .set_bus_param = ov9640_set_bus_param,
709− .query_bus_param = ov9640_query_bus_param,
710− .controls = ov9640_controls,
711− .num_controls = ARRAY_SIZE(ov9640_controls),
624+static const struct v4l2_ctrl_ops ov9640_ctrl_ops = {
625+ .s_ctrl = ov9640_s_ctrl,
712626 };
713627
714628 static struct v4l2_subdev_core_ops ov9640_core_ops = {
715− .g_ctrl = ov9640_g_ctrl,
716− .s_ctrl = ov9640_s_ctrl,
717629 .g_chip_ident = ov9640_g_chip_ident,
718630 #ifdef CONFIG_VIDEO_ADV_DEBUG
719631 .g_register = ov9640_get_register,
@@ -722,6 +634,22 @@ static struct v4l2_subdev_core_ops ov9640_core_ops = { · 2 unmodified lines
722634
723635 };
724636
637+/* Request bus settings on camera side */
638+static int ov9640_g_mbus_config(struct v4l2_subdev *sd,
639+ struct v4l2_mbus_config *cfg)
640+{
641+ struct i2c_client *client = v4l2_get_subdevdata(sd);
642+ struct soc_camera_link *icl = soc_camera_i2c_to_link(client);
643+
644+ cfg->flags = V4L2_MBUS_PCLK_SAMPLE_RISING | V4L2_MBUS_MASTER |
645+ V4L2_MBUS_VSYNC_ACTIVE_HIGH | V4L2_MBUS_HSYNC_ACTIVE_HIGH |
646+ V4L2_MBUS_DATA_ACTIVE_HIGH;
647+ cfg->type = V4L2_MBUS_PARALLEL;
648+ cfg->flags = soc_camera_apply_board_flags(icl, cfg);
649+
650+ return 0;
651+}
652+
725653 static struct v4l2_subdev_video_ops ov9640_video_ops = {
726654 .s_stream = ov9640_s_stream,
727655 .s_mbus_fmt = ov9640_s_fmt,
@@ -729,7 +657,7 @@ static struct v4l2_subdev_video_ops ov9640_video_ops = { · 1 unmodified line
729657 .enum_mbus_fmt = ov9640_enum_fmt,
730658 .cropcap = ov9640_cropcap,
731659 .g_crop = ov9640_g_crop,
732−
660+ .g_mbus_config = ov9640_g_mbus_config,
733661 };
734662
735663 static struct v4l2_subdev_ops ov9640_subdev_ops = {
@@ -744,16 +672,9 @@ static int ov9640_probe(struct i2c_client *client, · 8 unmodified lines
744672 const struct i2c_device_id *did)
745673 {
746674 struct ov9640_priv *priv;
747− struct soc_camera_device *icd = client->dev.platform_data;
748− struct soc_camera_link *icl;
675+ struct soc_camera_link *icl = soc_camera_i2c_to_link(client);
749676 int ret;
750677
751− if (!icd) {
752− dev_err(&client->dev, "Missing soc-camera data!\n");
753− return -EINVAL;
754− }
755−
756− icl = to_soc_camera_link(icd);
757678 if (!icl) {
758679 dev_err(&client->dev, "Missing platform_data for driver\n");
759680 return -EINVAL;
@@ -768,12 +689,23 @@ static int ov9640_probe(struct i2c_client *client, · 8 unmodified lines
768689
769690 v4l2_i2c_subdev_init(&priv->subdev, client, &ov9640_subdev_ops);
770691
771− icd->ops = &ov9640_ops;
692+ v4l2_ctrl_handler_init(&priv->hdl, 2);
693+ v4l2_ctrl_new_std(&priv->hdl, &ov9640_ctrl_ops,
694+ V4L2_CID_VFLIP, 0, 1, 1, 0);
695+ v4l2_ctrl_new_std(&priv->hdl, &ov9640_ctrl_ops,
696+ V4L2_CID_HFLIP, 0, 1, 1, 0);
697+ priv->subdev.ctrl_handler = &priv->hdl;
698+ if (priv->hdl.error) {
699+ int err = priv->hdl.error;
700+
701+ kfree(priv);
702+ return err;
703+ }
772704
773− ret = ov9640_video_probe(icd, client);
705+ ret = ov9640_video_probe(client);
774706
775707 if (ret) {
776− icd->ops = NULL;
708+ v4l2_ctrl_handler_free(&priv->hdl);
777709 kfree(priv);
778710 }
779711
@@ -785,6 +717,8 @@ static int ov9640_remove(struct i2c_client *client) · 5 unmodified lines
785717 struct v4l2_subdev *sd = i2c_get_clientdata(client);
786718 struct ov9640_priv *priv = to_ov9640_sensor(sd);
787719
720+ v4l2_device_unregister_subdev(&priv->subdev);
721+ v4l2_ctrl_handler_free(&priv->hdl);
788722 kfree(priv);
789723 return 0;
790724 }
drivers/media/video/ov9640.h+1−3
@@ -198,12 +198,10 @@ struct ov9640_reg { · 197 unmodified lines
198198
199199 struct ov9640_priv {
200200 struct v4l2_subdev subdev;
201+ struct v4l2_ctrl_handler hdl;
201202
202203 int model;
203204 int revision;
204−
205− bool flag_vflip;
206− bool flag_hflip;
207205 };
208206
209207 #endif /* __DRIVERS_MEDIA_VIDEO_OV9640_H__ */
drivers/media/video/ov9740.c+55−96
@@ -14,8 +14,11 @@ · 13 unmodified lines
1414 #include <linux/module.h>
1515 #include <linux/i2c.h>
1616 #include <linux/slab.h>
17−#include <media/v4l2-chip-ident.h>
17+#include <linux/v4l2-mediabus.h>
18+
1819 #include <media/soc_camera.h>
20+#include <media/v4l2-chip-ident.h>
21+#include <media/v4l2-ctrls.h>
1922
2023 #define to_ov9740(sd) container_of(sd, struct ov9740_priv, subdev)
2124
@@ -192,6 +195,7 @@ struct ov9740_reg { · 170 unmodified lines
192195
193196 struct ov9740_priv {
194197 struct v4l2_subdev subdev;
198+ struct v4l2_ctrl_handler hdl;
195199
196200 int ident;
197201 u16 model;
@@ -392,27 +396,6 @@ static enum v4l2_mbus_pixelcode ov9740_codes[] = { · 194 unmodified lines
392396 V4L2_MBUS_FMT_YUYV8_2X8,
393397 };
394398
395−static const struct v4l2_queryctrl ov9740_controls[] = {
396− {
397− .id = V4L2_CID_VFLIP,
398− .type = V4L2_CTRL_TYPE_BOOLEAN,
399− .name = "Flip Vertically",
400− .minimum = 0,
401− .maximum = 1,
402− .step = 1,
403− .default_value = 0,
404− },
405− {
406− .id = V4L2_CID_HFLIP,
407− .type = V4L2_CTRL_TYPE_BOOLEAN,
408− .name = "Flip Horizontally",
409− .minimum = 0,
410− .maximum = 1,
411− .step = 1,
412− .default_value = 0,
413− },
414−};
415−
416399 /* read a register */
417400 static int ov9740_reg_read(struct i2c_client *client, u16 reg, u8 *val)
418401 {
@@ -560,25 +543,6 @@ static int ov9740_s_stream(struct v4l2_subdev *sd, int enable) · 141 unmodified lines
560543 return ret;
561544 }
562545
563−/* Alter bus settings on camera side */
564−static int ov9740_set_bus_param(struct soc_camera_device *icd,
565− unsigned long flags)
566−{
567− return 0;
568−}
569−
570−/* Request bus settings on camera side */
571−static unsigned long ov9740_query_bus_param(struct soc_camera_device *icd)
572−{
573− struct soc_camera_link *icl = to_soc_camera_link(icd);
574−
575− unsigned long flags = SOCAM_PCLK_SAMPLE_RISING | SOCAM_MASTER |
576− SOCAM_VSYNC_ACTIVE_HIGH | SOCAM_HSYNC_ACTIVE_HIGH |
577− SOCAM_DATA_ACTIVE_HIGH | SOCAM_DATAWIDTH_8;
578−
579− return soc_camera_apply_sensor_flags(icl, flags);
580−}
581−
582546 /* select nearest higher resolution for capture */
583547 static void ov9740_res_roundup(u32 *width, u32 *height)
584548 {
@@ -788,36 +752,18 @@ static int ov9740_g_crop(struct v4l2_subdev *sd, struct v4l2_crop *a) · 203 unmodified lines
788752 return 0;
789753 }
790754
791−/* Get status of additional camera capabilities */
792−static int ov9740_g_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
793−{
794− struct ov9740_priv *priv = to_ov9740(sd);
795−
796− switch (ctrl->id) {
797− case V4L2_CID_VFLIP:
798− ctrl->value = priv->flag_vflip;
799− break;
800− case V4L2_CID_HFLIP:
801− ctrl->value = priv->flag_hflip;
802− break;
803− default:
804− return -EINVAL;
805− }
806−
807− return 0;
808−}
809−
810755 /* Set status of additional camera capabilities */
811−static int ov9740_s_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
756+static int ov9740_s_ctrl(struct v4l2_ctrl *ctrl)
812757 {
813− struct ov9740_priv *priv = to_ov9740(sd);
758+ struct ov9740_priv *priv =
759+ container_of(ctrl->handler, struct ov9740_priv, hdl);
814760
815761 switch (ctrl->id) {
816762 case V4L2_CID_VFLIP:
817− priv->flag_vflip = ctrl->value;
763+ priv->flag_vflip = ctrl->val;
818764 break;
819765 case V4L2_CID_HFLIP:
820− priv->flag_hflip = ctrl->value;
766+ priv->flag_hflip = ctrl->val;
821767 break;
822768 default:
823769 return -EINVAL;
@@ -890,18 +836,13 @@ static int ov9740_set_register(struct v4l2_subdev *sd, · 66 unmodified lines
890836 }
891837 #endif
892838
893−static int ov9740_video_probe(struct soc_camera_device *icd,
894− struct i2c_client *client)
839+static int ov9740_video_probe(struct i2c_client *client)
895840 {
896841 struct v4l2_subdev *sd = i2c_get_clientdata(client);
897842 struct ov9740_priv *priv = to_ov9740(sd);
898843 u8 modelhi, modello;
899844 int ret;
900845
901− /* We must have a parent by now. And it cannot be a wrong one. */
902− BUG_ON(!icd->parent ||
903− to_soc_camera_host(icd->parent)->nr != icd->iface);
904−
905846 /*
906847 * check and show product ID and manufacturer ID
907848 */
@@ -942,25 +883,33 @@ err: · 34 unmodified lines
942883 return ret;
943884 }
944885
945−static struct soc_camera_ops ov9740_ops = {
946− .set_bus_param = ov9740_set_bus_param,
947− .query_bus_param = ov9740_query_bus_param,
948− .controls = ov9740_controls,
949− .num_controls = ARRAY_SIZE(ov9740_controls),
950−};
886+/* Request bus settings on camera side */
887+static int ov9740_g_mbus_config(struct v4l2_subdev *sd,
888+ struct v4l2_mbus_config *cfg)
889+{
890+ struct i2c_client *client = v4l2_get_subdevdata(sd);
891+ struct soc_camera_link *icl = soc_camera_i2c_to_link(client);
892+
893+ cfg->flags = V4L2_MBUS_PCLK_SAMPLE_RISING | V4L2_MBUS_MASTER |
894+ V4L2_MBUS_VSYNC_ACTIVE_HIGH | V4L2_MBUS_HSYNC_ACTIVE_HIGH |
895+ V4L2_MBUS_DATA_ACTIVE_HIGH;
896+ cfg->type = V4L2_MBUS_PARALLEL;
897+ cfg->flags = soc_camera_apply_board_flags(icl, cfg);
898+
899+ return 0;
900+}
951901
952902 static struct v4l2_subdev_video_ops ov9740_video_ops = {
953− .s_stream = ov9740_s_stream,
954− .s_mbus_fmt = ov9740_s_fmt,
955− .try_mbus_fmt = ov9740_try_fmt,
956− .enum_mbus_fmt = ov9740_enum_fmt,
957− .cropcap = ov9740_cropcap,
958− .g_crop = ov9740_g_crop,
903+ .s_stream = ov9740_s_stream,
904+ .s_mbus_fmt = ov9740_s_fmt,
905+ .try_mbus_fmt = ov9740_try_fmt,
906+ .enum_mbus_fmt = ov9740_enum_fmt,
907+ .cropcap = ov9740_cropcap,
908+ .g_crop = ov9740_g_crop,
909+ .g_mbus_config = ov9740_g_mbus_config,
959910 };
960911
961912 static struct v4l2_subdev_core_ops ov9740_core_ops = {
962− .g_ctrl = ov9740_g_ctrl,
963− .s_ctrl = ov9740_s_ctrl,
964913 .g_chip_ident = ov9740_g_chip_ident,
965914 .s_power = ov9740_s_power,
966915 #ifdef CONFIG_VIDEO_ADV_DEBUG
@@ -974,6 +923,10 @@ static struct v4l2_subdev_ops ov9740_subdev_ops = { · 7 unmodified lines
974923 .video = &ov9740_video_ops,
975924 };
976925
926+static const struct v4l2_ctrl_ops ov9740_ctrl_ops = {
927+ .s_ctrl = ov9740_s_ctrl,
928+};
929+
977930 /*
978931 * i2c_driver function
979932 */
@@ -981,16 +934,9 @@ static int ov9740_probe(struct i2c_client *client, · 1 unmodified line
981934 const struct i2c_device_id *did)
982935 {
983936 struct ov9740_priv *priv;
984− struct soc_camera_device *icd = client->dev.platform_data;
985− struct soc_camera_link *icl;
937+ struct soc_camera_link *icl = soc_camera_i2c_to_link(client);
986938 int ret;
987939
988− if (!icd) {
989− dev_err(&client->dev, "Missing soc-camera data!\n");
990− return -EINVAL;
991− }
992−
993− icl = to_soc_camera_link(icd);
994940 if (!icl) {
995941 dev_err(&client->dev, "Missing platform_data for driver\n");
996942 return -EINVAL;
@@ -1003,12 +949,24 @@ static int ov9740_probe(struct i2c_client *client, · 6 unmodified lines
1003949 }
1004950
1005951 v4l2_i2c_subdev_init(&priv->subdev, client, &ov9740_subdev_ops);
952+ v4l2_ctrl_handler_init(&priv->hdl, 13);
953+ v4l2_ctrl_new_std(&priv->hdl, &ov9740_ctrl_ops,
954+ V4L2_CID_VFLIP, 0, 1, 1, 0);
955+ v4l2_ctrl_new_std(&priv->hdl, &ov9740_ctrl_ops,
956+ V4L2_CID_HFLIP, 0, 1, 1, 0);
957+ priv->subdev.ctrl_handler = &priv->hdl;
958+ if (priv->hdl.error) {
959+ int err = priv->hdl.error;
1006960
1007− icd->ops = &ov9740_ops;
961+ kfree(priv);
962+ return err;
963+ }
1008964
1009− ret = ov9740_video_probe(icd, client);
965+ ret = ov9740_video_probe(client);
966+ if (!ret)
967+ ret = v4l2_ctrl_handler_setup(&priv->hdl);
1010968 if (ret < 0) {
1011− icd->ops = NULL;
969+ v4l2_ctrl_handler_free(&priv->hdl);
1012970 kfree(priv);
1013971 }
1014972
@@ -1019,8 +977,9 @@ static int ov9740_remove(struct i2c_client *client) · 4 unmodified lines
1019977 {
1020978 struct ov9740_priv *priv = i2c_get_clientdata(client);
1021979
980+ v4l2_device_unregister_subdev(&priv->subdev);
981+ v4l2_ctrl_handler_free(&priv->hdl);
1022982 kfree(priv);
1023−
1024983 return 0;
1025984 }
1026985
drivers/media/video/pwc/pwc-if.c+3−3
@@ -744,9 +744,9 @@ static int pwc_video_mmap(struct file *file, struct vm_area_struct *vma) · 743 unmodified lines
744744 /***************************************************************************/
745745 /* Videobuf2 operations */
746746
747−static int queue_setup(struct vb2_queue *vq, unsigned int *nbuffers,
748− unsigned int *nplanes, unsigned int sizes[],
749− void *alloc_ctxs[])
747+static int queue_setup(struct vb2_queue *vq, const struct v4l2_format *fmt,
748+ unsigned int *nbuffers, unsigned int *nplanes,
749+ unsigned int sizes[], void *alloc_ctxs[])
750750 {
751751 struct pwc_device *pdev = vb2_get_drv_priv(vq);
752752
drivers/media/video/pxa_camera.c+80−60
@@ -214,6 +214,7 @@ struct pxa_camera_dev { · 213 unmodified lines
214214 unsigned long ciclk;
215215 unsigned long mclk;
216216 u32 mclk_divisor;
217+ u16 width_flags; /* max 10 bits */
217218
218219 struct list_head capture;
219220
@@ -1020,37 +1021,20 @@ static int test_platform_param(struct pxa_camera_dev *pcdev, · 800 unmodified lines
10201021 * quick capture interface supports both.
10211022 */
10221023 *flags = (pcdev->platform_flags & PXA_CAMERA_MASTER ?
1023− SOCAM_MASTER : SOCAM_SLAVE) |
1024− SOCAM_HSYNC_ACTIVE_HIGH |
1025− SOCAM_HSYNC_ACTIVE_LOW |
1026− SOCAM_VSYNC_ACTIVE_HIGH |
1027− SOCAM_VSYNC_ACTIVE_LOW |
1028− SOCAM_DATA_ACTIVE_HIGH |
1029− SOCAM_PCLK_SAMPLE_RISING |
1030− SOCAM_PCLK_SAMPLE_FALLING;
1024+ V4L2_MBUS_MASTER : V4L2_MBUS_SLAVE) |
1025+ V4L2_MBUS_HSYNC_ACTIVE_HIGH |
1026+ V4L2_MBUS_HSYNC_ACTIVE_LOW |
1027+ V4L2_MBUS_VSYNC_ACTIVE_HIGH |
1028+ V4L2_MBUS_VSYNC_ACTIVE_LOW |
1029+ V4L2_MBUS_DATA_ACTIVE_HIGH |
1030+ V4L2_MBUS_PCLK_SAMPLE_RISING |
1031+ V4L2_MBUS_PCLK_SAMPLE_FALLING;
10311032
10321033 /* If requested data width is supported by the platform, use it */
1033− switch (buswidth) {
1034− case 10:
1035− if (!(pcdev->platform_flags & PXA_CAMERA_DATAWIDTH_10))
1036− return -EINVAL;
1037− *flags |= SOCAM_DATAWIDTH_10;
1038− break;
1039− case 9:
1040− if (!(pcdev->platform_flags & PXA_CAMERA_DATAWIDTH_9))
1041− return -EINVAL;
1042− *flags |= SOCAM_DATAWIDTH_9;
1043− break;
1044− case 8:
1045− if (!(pcdev->platform_flags & PXA_CAMERA_DATAWIDTH_8))
1046− return -EINVAL;
1047− *flags |= SOCAM_DATAWIDTH_8;
1048− break;
1049− default:
1050− return -EINVAL;
1051− }
1034+ if ((1 << (buswidth - 1)) & pcdev->width_flags)
1035+ return 0;
10521036
1053− return 0;
1037+ return -EINVAL;
10541038 }
10551039
10561040 static void pxa_camera_setup_cicr(struct soc_camera_device *icd,
@@ -1070,12 +1054,12 @@ static void pxa_camera_setup_cicr(struct soc_camera_device *icd, · 13 unmodified lines
10701054 * Datawidth is now guaranteed to be equal to one of the three values.
10711055 * We fix bit-per-pixel equal to data-width...
10721056 */
1073− switch (flags & SOCAM_DATAWIDTH_MASK) {
1074− case SOCAM_DATAWIDTH_10:
1057+ switch (icd->current_fmt->host_fmt->bits_per_sample) {
1058+ case 10:
10751059 dw = 4;
10761060 bpp = 0x40;
10771061 break;
1078− case SOCAM_DATAWIDTH_9:
1062+ case 9:
10791063 dw = 3;
10801064 bpp = 0x20;
10811065 break;
@@ -1084,7 +1068,7 @@ static void pxa_camera_setup_cicr(struct soc_camera_device *icd, · 2 unmodified lines
10841068 * Actually it can only be 8 now,
10851069 * default is just to silence compiler warnings
10861070 */
1087− case SOCAM_DATAWIDTH_8:
1071+ case 8:
10881072 dw = 2;
10891073 bpp = 0;
10901074 }
@@ -1093,11 +1077,11 @@ static void pxa_camera_setup_cicr(struct soc_camera_device *icd, · 2 unmodified lines
10931077 cicr4 |= CICR4_PCLK_EN;
10941078 if (pcdev->platform_flags & PXA_CAMERA_MCLK_EN)
10951079 cicr4 |= CICR4_MCLK_EN;
1096− if (flags & SOCAM_PCLK_SAMPLE_FALLING)
1080+ if (flags & V4L2_MBUS_PCLK_SAMPLE_FALLING)
10971081 cicr4 |= CICR4_PCP;
1098− if (flags & SOCAM_HSYNC_ACTIVE_LOW)
1082+ if (flags & V4L2_MBUS_HSYNC_ACTIVE_LOW)
10991083 cicr4 |= CICR4_HSP;
1100− if (flags & SOCAM_VSYNC_ACTIVE_LOW)
1084+ if (flags & V4L2_MBUS_VSYNC_ACTIVE_LOW)
11011085 cicr4 |= CICR4_VSP;
11021086
11031087 cicr0 = __raw_readl(pcdev->base + CICR0);
@@ -1151,9 +1135,11 @@ static void pxa_camera_setup_cicr(struct soc_camera_device *icd, · 47 unmodified lines
11511135
11521136 static int pxa_camera_set_bus_param(struct soc_camera_device *icd, __u32 pixfmt)
11531137 {
1138+ struct v4l2_subdev *sd = soc_camera_to_subdev(icd);
11541139 struct soc_camera_host *ici = to_soc_camera_host(icd->parent);
11551140 struct pxa_camera_dev *pcdev = ici->priv;
1156− unsigned long bus_flags, camera_flags, common_flags;
1141+ struct v4l2_mbus_config cfg = {.type = V4L2_MBUS_PARALLEL,};
1142+ unsigned long bus_flags, common_flags;
11571143 int ret;
11581144 struct pxa_cam *cam = icd->host_priv;
11591145
@@ -1162,44 +1148,58 @@ static int pxa_camera_set_bus_param(struct soc_camera_device *icd, __u32 pixfmt) · 2 unmodified lines
11621148 if (ret < 0)
11631149 return ret;
11641150
1165− camera_flags = icd->ops->query_bus_param(icd);
1166−
1167− common_flags = soc_camera_bus_param_compatible(camera_flags, bus_flags);
1168− if (!common_flags)
1169− return -EINVAL;
1151+ ret = v4l2_subdev_call(sd, video, g_mbus_config, &cfg);
1152+ if (!ret) {
1153+ common_flags = soc_mbus_config_compatible(&cfg,
1154+ bus_flags);
1155+ if (!common_flags) {
1156+ dev_warn(icd->parent,
1157+ "Flags incompatible: camera 0x%x, host 0x%lx\n",
1158+ cfg.flags, bus_flags);
1159+ return -EINVAL;
1160+ }
1161+ } else if (ret != -ENOIOCTLCMD) {
1162+ return ret;
1163+ } else {
1164+ common_flags = bus_flags;
1165+ }
11701166
11711167 pcdev->channels = 1;
11721168
11731169 /* Make choises, based on platform preferences */
1174− if ((common_flags & SOCAM_HSYNC_ACTIVE_HIGH) &&
1175− (common_flags & SOCAM_HSYNC_ACTIVE_LOW)) {
1170+ if ((common_flags & V4L2_MBUS_HSYNC_ACTIVE_HIGH) &&
1171+ (common_flags & V4L2_MBUS_HSYNC_ACTIVE_LOW)) {
11761172 if (pcdev->platform_flags & PXA_CAMERA_HSP)
1177− common_flags &= ~SOCAM_HSYNC_ACTIVE_HIGH;
1173+ common_flags &= ~V4L2_MBUS_HSYNC_ACTIVE_HIGH;
11781174 else
1179− common_flags &= ~SOCAM_HSYNC_ACTIVE_LOW;
1175+ common_flags &= ~V4L2_MBUS_HSYNC_ACTIVE_LOW;
11801176 }
11811177
1182− if ((common_flags & SOCAM_VSYNC_ACTIVE_HIGH) &&
1183− (common_flags & SOCAM_VSYNC_ACTIVE_LOW)) {
1178+ if ((common_flags & V4L2_MBUS_VSYNC_ACTIVE_HIGH) &&
1179+ (common_flags & V4L2_MBUS_VSYNC_ACTIVE_LOW)) {
11841180 if (pcdev->platform_flags & PXA_CAMERA_VSP)
1185− common_flags &= ~SOCAM_VSYNC_ACTIVE_HIGH;
1181+ common_flags &= ~V4L2_MBUS_VSYNC_ACTIVE_HIGH;
11861182 else
1187− common_flags &= ~SOCAM_VSYNC_ACTIVE_LOW;
1183+ common_flags &= ~V4L2_MBUS_VSYNC_ACTIVE_LOW;
11881184 }
11891185
1190− if ((common_flags & SOCAM_PCLK_SAMPLE_RISING) &&
1191− (common_flags & SOCAM_PCLK_SAMPLE_FALLING)) {
1186+ if ((common_flags & V4L2_MBUS_PCLK_SAMPLE_RISING) &&
1187+ (common_flags & V4L2_MBUS_PCLK_SAMPLE_FALLING)) {
11921188 if (pcdev->platform_flags & PXA_CAMERA_PCP)
1193− common_flags &= ~SOCAM_PCLK_SAMPLE_RISING;
1189+ common_flags &= ~V4L2_MBUS_PCLK_SAMPLE_RISING;
11941190 else
1195− common_flags &= ~SOCAM_PCLK_SAMPLE_FALLING;
1191+ common_flags &= ~V4L2_MBUS_PCLK_SAMPLE_FALLING;
11961192 }
11971193
1198− cam->flags = common_flags;
1199−
1200− ret = icd->ops->set_bus_param(icd, common_flags);
1201− if (ret < 0)
1194+ cfg.flags = common_flags;
1195+ ret = v4l2_subdev_call(sd, video, s_mbus_config, &cfg);
1196+ if (ret < 0 && ret != -ENOIOCTLCMD) {
1197+ dev_dbg(icd->parent, "camera s_mbus_config(0x%lx) returned %d\n",
1198+ common_flags, ret);
12021199 return ret;
1200+ }
1201+
1202+ cam->flags = common_flags;
12031203
12041204 pxa_camera_setup_cicr(icd, common_flags, pixfmt);
12051205
@@ -1209,17 +1209,31 @@ static int pxa_camera_set_bus_param(struct soc_camera_device *icd, __u32 pixfmt) · 3 unmodified lines
12091209 static int pxa_camera_try_bus_param(struct soc_camera_device *icd,
12101210 unsigned char buswidth)
12111211 {
1212+ struct v4l2_subdev *sd = soc_camera_to_subdev(icd);
12121213 struct soc_camera_host *ici = to_soc_camera_host(icd->parent);
12131214 struct pxa_camera_dev *pcdev = ici->priv;
1214− unsigned long bus_flags, camera_flags;
1215+ struct v4l2_mbus_config cfg = {.type = V4L2_MBUS_PARALLEL,};
1216+ unsigned long bus_flags, common_flags;
12151217 int ret = test_platform_param(pcdev, buswidth, &bus_flags);
12161218
12171219 if (ret < 0)
12181220 return ret;
12191221
1220− camera_flags = icd->ops->query_bus_param(icd);
1222+ ret = v4l2_subdev_call(sd, video, g_mbus_config, &cfg);
1223+ if (!ret) {
1224+ common_flags = soc_mbus_config_compatible(&cfg,
1225+ bus_flags);
1226+ if (!common_flags) {
1227+ dev_warn(icd->parent,
1228+ "Flags incompatible: camera 0x%x, host 0x%lx\n",
1229+ cfg.flags, bus_flags);
1230+ return -EINVAL;
1231+ }
1232+ } else if (ret == -ENOIOCTLCMD) {
1233+ ret = 0;
1234+ }
12211235
1222− return soc_camera_bus_param_compatible(camera_flags, bus_flags) ? 0 : -EINVAL;
1236+ return ret;
12231237 }
12241238
12251239 static const struct soc_mbus_pixelfmt pxa_camera_formats[] = {
@@ -1687,6 +1701,12 @@ static int __devinit pxa_camera_probe(struct platform_device *pdev) · 461 unmodified lines
16871701 "data widths, using default 10 bit\n");
16881702 pcdev->platform_flags |= PXA_CAMERA_DATAWIDTH_10;
16891703 }
1704+ if (pcdev->platform_flags & PXA_CAMERA_DATAWIDTH_8)
1705+ pcdev->width_flags = 1 << 7;
1706+ if (pcdev->platform_flags & PXA_CAMERA_DATAWIDTH_9)
1707+ pcdev->width_flags |= 1 << 8;
1708+ if (pcdev->platform_flags & PXA_CAMERA_DATAWIDTH_10)
1709+ pcdev->width_flags |= 1 << 9;
16901710 pcdev->mclk = pcdev->pdata->mclk_10khz * 10000;
16911711 if (!pcdev->mclk) {
16921712 dev_warn(&pdev->dev,
drivers/media/video/rj54n1cb0c.c+75−148
@@ -11,13 +11,14 @@ · 10 unmodified lines
1111 #include <linux/delay.h>
1212 #include <linux/i2c.h>
1313 #include <linux/slab.h>
14+#include <linux/v4l2-mediabus.h>
1415 #include <linux/videodev2.h>
1516
1617 #include <media/rj54n1cb0c.h>
1718 #include <media/soc_camera.h>
18−#include <media/soc_mediabus.h>
1919 #include <media/v4l2-subdev.h>
2020 #include <media/v4l2-chip-ident.h>
21+#include <media/v4l2-ctrls.h>
2122
2223 #define RJ54N1_DEV_CODE 0x0400
2324 #define RJ54N1_DEV_CODE2 0x0401
@@ -148,6 +149,7 @@ struct rj54n1_clock_div { · 124 unmodified lines
148149
149150 struct rj54n1 {
150151 struct v4l2_subdev subdev;
152+ struct v4l2_ctrl_handler hdl;
151153 struct rj54n1_clock_div clk_div;
152154 const struct rj54n1_datafmt *fmt;
153155 struct v4l2_rect rect; /* Sensor window */
@@ -499,31 +501,6 @@ static int rj54n1_s_stream(struct v4l2_subdev *sd, int enable) · 345 unmodified lines
499501 return reg_set(client, RJ54N1_STILL_CONTROL, (!enable) << 7, 0x80);
500502 }
501503
502−static int rj54n1_set_bus_param(struct soc_camera_device *icd,
503− unsigned long flags)
504−{
505− struct v4l2_subdev *sd = soc_camera_to_subdev(icd);
506− struct i2c_client *client = v4l2_get_subdevdata(sd);
507− /* Figures 2.5-1 to 2.5-3 - default falling pixclk edge */
508−
509− if (flags & SOCAM_PCLK_SAMPLE_RISING)
510− return reg_write(client, RJ54N1_OUT_SIGPO, 1 << 4);
511− else
512− return reg_write(client, RJ54N1_OUT_SIGPO, 0);
513−}
514−
515−static unsigned long rj54n1_query_bus_param(struct soc_camera_device *icd)
516−{
517− struct soc_camera_link *icl = to_soc_camera_link(icd);
518− const unsigned long flags =
519− SOCAM_PCLK_SAMPLE_RISING | SOCAM_PCLK_SAMPLE_FALLING |
520− SOCAM_MASTER | SOCAM_DATAWIDTH_8 |
521− SOCAM_HSYNC_ACTIVE_HIGH | SOCAM_VSYNC_ACTIVE_HIGH |
522− SOCAM_DATA_ACTIVE_HIGH;
523−
524− return soc_camera_apply_sensor_flags(icl, flags);
525−}
526−
527504 static int rj54n1_set_rect(struct i2c_client *client,
528505 u16 reg_x, u16 reg_y, u16 reg_xy,
529506 u32 width, u32 height)
@@ -1202,134 +1179,51 @@ static int rj54n1_s_register(struct v4l2_subdev *sd, · 672 unmodified lines
12021179 }
12031180 #endif
12041181
1205−static const struct v4l2_queryctrl rj54n1_controls[] = {
1206− {
1207− .id = V4L2_CID_VFLIP,
1208− .type = V4L2_CTRL_TYPE_BOOLEAN,
1209− .name = "Flip Vertically",
1210− .minimum = 0,
1211− .maximum = 1,
1212− .step = 1,
1213− .default_value = 0,
1214− }, {
1215− .id = V4L2_CID_HFLIP,
1216− .type = V4L2_CTRL_TYPE_BOOLEAN,
1217− .name = "Flip Horizontally",
1218− .minimum = 0,
1219− .maximum = 1,
1220− .step = 1,
1221− .default_value = 0,
1222− }, {
1223− .id = V4L2_CID_GAIN,
1224− .type = V4L2_CTRL_TYPE_INTEGER,
1225− .name = "Gain",
1226− .minimum = 0,
1227− .maximum = 127,
1228− .step = 1,
1229− .default_value = 66,
1230− .flags = V4L2_CTRL_FLAG_SLIDER,
1231− }, {
1232− .id = V4L2_CID_AUTO_WHITE_BALANCE,
1233− .type = V4L2_CTRL_TYPE_BOOLEAN,
1234− .name = "Auto white balance",
1235− .minimum = 0,
1236− .maximum = 1,
1237− .step = 1,
1238− .default_value = 1,
1239− },
1240−};
1241−
1242−static struct soc_camera_ops rj54n1_ops = {
1243− .set_bus_param = rj54n1_set_bus_param,
1244− .query_bus_param = rj54n1_query_bus_param,
1245− .controls = rj54n1_controls,
1246− .num_controls = ARRAY_SIZE(rj54n1_controls),
1247−};
1248−
1249−static int rj54n1_g_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
1182+static int rj54n1_s_ctrl(struct v4l2_ctrl *ctrl)
12501183 {
1184+ struct rj54n1 *rj54n1 = container_of(ctrl->handler, struct rj54n1, hdl);
1185+ struct v4l2_subdev *sd = &rj54n1->subdev;
12511186 struct i2c_client *client = v4l2_get_subdevdata(sd);
1252− struct rj54n1 *rj54n1 = to_rj54n1(client);
12531187 int data;
12541188
12551189 switch (ctrl->id) {
12561190 case V4L2_CID_VFLIP:
1257− data = reg_read(client, RJ54N1_MIRROR_STILL_MODE);
1258− if (data < 0)
1259− return -EIO;
1260− ctrl->value = !(data & 1);
1261− break;
1262− case V4L2_CID_HFLIP:
1263− data = reg_read(client, RJ54N1_MIRROR_STILL_MODE);
1264− if (data < 0)
1265− return -EIO;
1266− ctrl->value = !(data & 2);
1267− break;
1268− case V4L2_CID_GAIN:
1269− data = reg_read(client, RJ54N1_Y_GAIN);
1270− if (data < 0)
1271− return -EIO;
1272−
1273− ctrl->value = data / 2;
1274− break;
1275− case V4L2_CID_AUTO_WHITE_BALANCE:
1276− ctrl->value = rj54n1->auto_wb;
1277− break;
1278− }
1279−
1280− return 0;
1281−}
1282−
1283−static int rj54n1_s_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
1284−{
1285− int data;
1286− struct i2c_client *client = v4l2_get_subdevdata(sd);
1287− struct rj54n1 *rj54n1 = to_rj54n1(client);
1288− const struct v4l2_queryctrl *qctrl;
1289−
1290− qctrl = soc_camera_find_qctrl(&rj54n1_ops, ctrl->id);
1291− if (!qctrl)
1292− return -EINVAL;
1293−
1294− switch (ctrl->id) {
1295− case V4L2_CID_VFLIP:
1296− if (ctrl->value)
1191+ if (ctrl->val)
12971192 data = reg_set(client, RJ54N1_MIRROR_STILL_MODE, 0, 1);
12981193 else
12991194 data = reg_set(client, RJ54N1_MIRROR_STILL_MODE, 1, 1);
13001195 if (data < 0)
13011196 return -EIO;
1302− break;
1197+ return 0;
13031198 case V4L2_CID_HFLIP:
1304− if (ctrl->value)
1199+ if (ctrl->val)
13051200 data = reg_set(client, RJ54N1_MIRROR_STILL_MODE, 0, 2);
13061201 else
13071202 data = reg_set(client, RJ54N1_MIRROR_STILL_MODE, 2, 2);
13081203 if (data < 0)
13091204 return -EIO;
1310− break;
1205+ return 0;
13111206 case V4L2_CID_GAIN:
1312− if (ctrl->value > qctrl->maximum ||
1313− ctrl->value < qctrl->minimum)
1314− return -EINVAL;
1315− else if (reg_write(client, RJ54N1_Y_GAIN, ctrl->value * 2) < 0)
1207+ if (reg_write(client, RJ54N1_Y_GAIN, ctrl->val * 2) < 0)
13161208 return -EIO;
1317− break;
1209+ return 0;
13181210 case V4L2_CID_AUTO_WHITE_BALANCE:
13191211 /* Auto WB area - whole image */
1320− if (reg_set(client, RJ54N1_WB_SEL_WEIGHT_I, ctrl->value << 7,
1212+ if (reg_set(client, RJ54N1_WB_SEL_WEIGHT_I, ctrl->val << 7,
13211213 0x80) < 0)
13221214 return -EIO;
1323− rj54n1->auto_wb = ctrl->value;
1324− break;
1215+ rj54n1->auto_wb = ctrl->val;
1216+ return 0;
13251217 }
13261218
1327− return 0;
1219+ return -EINVAL;
13281220 }
13291221
1222+static const struct v4l2_ctrl_ops rj54n1_ctrl_ops = {
1223+ .s_ctrl = rj54n1_s_ctrl,
1224+};
1225+
13301226 static struct v4l2_subdev_core_ops rj54n1_subdev_core_ops = {
1331− .g_ctrl = rj54n1_g_ctrl,
1332− .s_ctrl = rj54n1_s_ctrl,
13331227 .g_chip_ident = rj54n1_g_chip_ident,
13341228 #ifdef CONFIG_VIDEO_ADV_DEBUG
13351229 .g_register = rj54n1_g_register,
@@ -1337,6 +1231,36 @@ static struct v4l2_subdev_core_ops rj54n1_subdev_core_ops = { · 1 unmodified line
13371231 #endif
13381232 };
13391233
1234+static int rj54n1_g_mbus_config(struct v4l2_subdev *sd,
1235+ struct v4l2_mbus_config *cfg)
1236+{
1237+ struct i2c_client *client = v4l2_get_subdevdata(sd);
1238+ struct soc_camera_link *icl = soc_camera_i2c_to_link(client);
1239+
1240+ cfg->flags =
1241+ V4L2_MBUS_PCLK_SAMPLE_RISING | V4L2_MBUS_PCLK_SAMPLE_FALLING |
1242+ V4L2_MBUS_MASTER | V4L2_MBUS_DATA_ACTIVE_HIGH |
1243+ V4L2_MBUS_HSYNC_ACTIVE_HIGH | V4L2_MBUS_VSYNC_ACTIVE_HIGH;
1244+ cfg->type = V4L2_MBUS_PARALLEL;
1245+ cfg->flags = soc_camera_apply_board_flags(icl, cfg);
1246+
1247+ return 0;
1248+}
1249+
1250+static int rj54n1_s_mbus_config(struct v4l2_subdev *sd,
1251+ const struct v4l2_mbus_config *cfg)
1252+{
1253+ struct i2c_client *client = v4l2_get_subdevdata(sd);
1254+ struct soc_camera_link *icl = soc_camera_i2c_to_link(client);
1255+
1256+ /* Figures 2.5-1 to 2.5-3 - default falling pixclk edge */
1257+ if (soc_camera_apply_board_flags(icl, cfg) &
1258+ V4L2_MBUS_PCLK_SAMPLE_RISING)
1259+ return reg_write(client, RJ54N1_OUT_SIGPO, 1 << 4);
1260+ else
1261+ return reg_write(client, RJ54N1_OUT_SIGPO, 0);
1262+}
1263+
13401264 static struct v4l2_subdev_video_ops rj54n1_subdev_video_ops = {
13411265 .s_stream = rj54n1_s_stream,
13421266 .s_mbus_fmt = rj54n1_s_fmt,
@@ -1346,6 +1270,8 @@ static struct v4l2_subdev_video_ops rj54n1_subdev_video_ops = { · 3 unmodified lines
13461270 .g_crop = rj54n1_g_crop,
13471271 .s_crop = rj54n1_s_crop,
13481272 .cropcap = rj54n1_cropcap,
1273+ .g_mbus_config = rj54n1_g_mbus_config,
1274+ .s_mbus_config = rj54n1_s_mbus_config,
13491275 };
13501276
13511277 static struct v4l2_subdev_ops rj54n1_subdev_ops = {
@@ -1357,17 +1283,12 @@ static struct v4l2_subdev_ops rj54n1_subdev_ops = { · 5 unmodified lines
13571283 * Interface active, can use i2c. If it fails, it can indeed mean, that
13581284 * this wasn't our capture interface, so, we wait for the right one
13591285 */
1360−static int rj54n1_video_probe(struct soc_camera_device *icd,
1361− struct i2c_client *client,
1286+static int rj54n1_video_probe(struct i2c_client *client,
13621287 struct rj54n1_pdata *priv)
13631288 {
13641289 int data1, data2;
13651290 int ret;
13661291
1367− /* We must have a parent by now. And it cannot be a wrong one. */
1368− BUG_ON(!icd->parent ||
1369− to_soc_camera_host(icd->parent)->nr != icd->iface);
1370−
13711292 /* Read out the chip version register */
13721293 data1 = reg_read(client, RJ54N1_DEV_CODE);
13731294 data2 = reg_read(client, RJ54N1_DEV_CODE2);
@@ -1395,18 +1316,11 @@ static int rj54n1_probe(struct i2c_client *client, · 21 unmodified lines
13951316 const struct i2c_device_id *did)
13961317 {
13971318 struct rj54n1 *rj54n1;
1398− struct soc_camera_device *icd = client->dev.platform_data;
1319+ struct soc_camera_link *icl = soc_camera_i2c_to_link(client);
13991320 struct i2c_adapter *adapter = to_i2c_adapter(client->dev.parent);
1400− struct soc_camera_link *icl;
14011321 struct rj54n1_pdata *rj54n1_priv;
14021322 int ret;
14031323
1404− if (!icd) {
1405− dev_err(&client->dev, "RJ54N1CB0C: missing soc-camera data!\n");
1406− return -EINVAL;
1407− }
1408−
1409− icl = to_soc_camera_link(icd);
14101324 if (!icl || !icl->priv) {
14111325 dev_err(&client->dev, "RJ54N1CB0C: missing platform data!\n");
14121326 return -EINVAL;
@@ -1425,8 +1339,22 @@ static int rj54n1_probe(struct i2c_client *client, · 12 unmodified lines
14251339 return -ENOMEM;
14261340
14271341 v4l2_i2c_subdev_init(&rj54n1->subdev, client, &rj54n1_subdev_ops);
1342+ v4l2_ctrl_handler_init(&rj54n1->hdl, 4);
1343+ v4l2_ctrl_new_std(&rj54n1->hdl, &rj54n1_ctrl_ops,
1344+ V4L2_CID_VFLIP, 0, 1, 1, 0);
1345+ v4l2_ctrl_new_std(&rj54n1->hdl, &rj54n1_ctrl_ops,
1346+ V4L2_CID_HFLIP, 0, 1, 1, 0);
1347+ v4l2_ctrl_new_std(&rj54n1->hdl, &rj54n1_ctrl_ops,
1348+ V4L2_CID_GAIN, 0, 127, 1, 66);
1349+ v4l2_ctrl_new_std(&rj54n1->hdl, &rj54n1_ctrl_ops,
1350+ V4L2_CID_AUTO_WHITE_BALANCE, 0, 1, 1, 1);
1351+ rj54n1->subdev.ctrl_handler = &rj54n1->hdl;
1352+ if (rj54n1->hdl.error) {
1353+ int err = rj54n1->hdl.error;
14281354
1429− icd->ops = &rj54n1_ops;
1355+ kfree(rj54n1);
1356+ return err;
1357+ }
14301358
14311359 rj54n1->clk_div = clk_div;
14321360 rj54n1->rect.left = RJ54N1_COLUMN_SKIP;
@@ -1440,25 +1368,24 @@ static int rj54n1_probe(struct i2c_client *client, · 7 unmodified lines
14401368 rj54n1->tgclk_mhz = (rj54n1_priv->mclk_freq / PLL_L * PLL_N) /
14411369 (clk_div.ratio_tg + 1) / (clk_div.ratio_t + 1);
14421370
1443− ret = rj54n1_video_probe(icd, client, rj54n1_priv);
1371+ ret = rj54n1_video_probe(client, rj54n1_priv);
14441372 if (ret < 0) {
1445− icd->ops = NULL;
1373+ v4l2_ctrl_handler_free(&rj54n1->hdl);
14461374 kfree(rj54n1);
14471375 return ret;
14481376 }
1449−
1450− return ret;
1377+ return v4l2_ctrl_handler_setup(&rj54n1->hdl);
14511378 }
14521379
14531380 static int rj54n1_remove(struct i2c_client *client)
14541381 {
14551382 struct rj54n1 *rj54n1 = to_rj54n1(client);
1456− struct soc_camera_device *icd = client->dev.platform_data;
1457− struct soc_camera_link *icl = to_soc_camera_link(icd);
1383+ struct soc_camera_link *icl = soc_camera_i2c_to_link(client);
14581384
1459− icd->ops = NULL;
1385+ v4l2_device_unregister_subdev(&rj54n1->subdev);
14601386 if (icl->free_bus)
14611387 icl->free_bus(icl);
1388+ v4l2_ctrl_handler_free(&rj54n1->hdl);
14621389 kfree(rj54n1);
14631390
14641391 return 0;
drivers/media/video/s5k6aa.c+1680−0
@@ -0,0 +1,1680 @@
1+/*
2+ * Driver for Samsung S5K6AAFX SXGA 1/6" 1.3M CMOS Image Sensor
3+ * with embedded SoC ISP.
4+ *
5+ * Copyright (C) 2011, Samsung Electronics Co., Ltd.
6+ * Sylwester Nawrocki <s.nawrocki@samsung.com>
7+ *
8+ * Based on a driver authored by Dongsoo Nathaniel Kim.
9+ * Copyright (C) 2009, Dongsoo Nathaniel Kim <dongsoo45.kim@samsung.com>
10+ *
11+ * This program is free software; you can redistribute it and/or modify
12+ * it under the terms of the GNU General Public License as published by
13+ * the Free Software Foundation; either version 2 of the License, or
14+ * (at your option) any later version.
15+ */
16+
17+#include <linux/clk.h>
18+#include <linux/delay.h>
19+#include <linux/gpio.h>
20+#include <linux/i2c.h>
21+#include <linux/media.h>
22+#include <linux/regulator/consumer.h>
23+#include <linux/slab.h>
24+
25+#include <media/media-entity.h>
26+#include <media/v4l2-ctrls.h>
27+#include <media/v4l2-device.h>
28+#include <media/v4l2-subdev.h>
29+#include <media/v4l2-mediabus.h>
30+#include <media/s5k6aa.h>
31+
32+static int debug;
33+module_param(debug, int, 0644);
34+
35+#define DRIVER_NAME "S5K6AA"
36+
37+/* The token to indicate array termination */
38+#define S5K6AA_TERM 0xffff
39+#define S5K6AA_OUT_WIDTH_DEF 640
40+#define S5K6AA_OUT_HEIGHT_DEF 480
41+#define S5K6AA_WIN_WIDTH_MAX 1280
42+#define S5K6AA_WIN_HEIGHT_MAX 1024
43+#define S5K6AA_WIN_WIDTH_MIN 8
44+#define S5K6AA_WIN_HEIGHT_MIN 8
45+
46+/*
47+ * H/W register Interface (0xD0000000 - 0xD0000FFF)
48+ */
49+#define AHB_MSB_ADDR_PTR 0xfcfc
50+#define GEN_REG_OFFSH 0xd000
51+#define REG_CMDWR_ADDRH 0x0028
52+#define REG_CMDWR_ADDRL 0x002a
53+#define REG_CMDRD_ADDRH 0x002c
54+#define REG_CMDRD_ADDRL 0x002e
55+#define REG_CMDBUF0_ADDR 0x0f12
56+#define REG_CMDBUF1_ADDR 0x0f10
57+
58+/*
59+ * Host S/W Register interface (0x70000000 - 0x70002000)
60+ * The value of the two most significant address bytes is 0x7000,
61+ * (HOST_SWIF_OFFS_H). The register addresses below specify 2 LSBs.
62+ */
63+#define HOST_SWIF_OFFSH 0x7000
64+
65+/* Initialization parameters */
66+/* Master clock frequency in KHz */
67+#define REG_I_INCLK_FREQ_L 0x01b8
68+#define REG_I_INCLK_FREQ_H 0x01ba
69+#define MIN_MCLK_FREQ_KHZ 6000U
70+#define MAX_MCLK_FREQ_KHZ 27000U
71+#define REG_I_USE_NPVI_CLOCKS 0x01c6
72+#define REG_I_USE_NMIPI_CLOCKS 0x01c8
73+
74+/* Clock configurations, n = 0..2. REG_I_* frequency unit is 4 kHz. */
75+#define REG_I_OPCLK_4KHZ(n) ((n) * 6 + 0x01cc)
76+#define REG_I_MIN_OUTRATE_4KHZ(n) ((n) * 6 + 0x01ce)
77+#define REG_I_MAX_OUTRATE_4KHZ(n) ((n) * 6 + 0x01d0)
78+#define SYS_PLL_OUT_FREQ (48000000 / 4000)
79+#define PCLK_FREQ_MIN (24000000 / 4000)
80+#define PCLK_FREQ_MAX (48000000 / 4000)
81+#define REG_I_INIT_PARAMS_UPDATED 0x01e0
82+#define REG_I_ERROR_INFO 0x01e2
83+
84+/* General purpose parameters */
85+#define REG_USER_BRIGHTNESS 0x01e4
86+#define REG_USER_CONTRAST 0x01e6
87+#define REG_USER_SATURATION 0x01e8
88+#define REG_USER_SHARPBLUR 0x01ea
89+
90+#define REG_G_SPEC_EFFECTS 0x01ee
91+#define REG_G_ENABLE_PREV 0x01f0
92+#define REG_G_ENABLE_PREV_CHG 0x01f2
93+#define REG_G_NEW_CFG_SYNC 0x01f8
94+#define REG_G_PREVZOOM_IN_WIDTH 0x020a
95+#define REG_G_PREVZOOM_IN_HEIGHT 0x020c
96+#define REG_G_PREVZOOM_IN_XOFFS 0x020e
97+#define REG_G_PREVZOOM_IN_YOFFS 0x0210
98+#define REG_G_INPUTS_CHANGE_REQ 0x021a
99+#define REG_G_ACTIVE_PREV_CFG 0x021c
100+#define REG_G_PREV_CFG_CHG 0x021e
101+#define REG_G_PREV_OPEN_AFTER_CH 0x0220
102+#define REG_G_PREV_CFG_ERROR 0x0222
103+
104+/* Preview control section. n = 0...4. */
105+#define PREG(n, x) ((n) * 0x26 + x)
106+#define REG_P_OUT_WIDTH(n) PREG(n, 0x0242)
107+#define REG_P_OUT_HEIGHT(n) PREG(n, 0x0244)
108+#define REG_P_FMT(n) PREG(n, 0x0246)
109+#define REG_P_MAX_OUT_RATE(n) PREG(n, 0x0248)
110+#define REG_P_MIN_OUT_RATE(n) PREG(n, 0x024a)
111+#define REG_P_PVI_MASK(n) PREG(n, 0x024c)
112+#define REG_P_CLK_INDEX(n) PREG(n, 0x024e)
113+#define REG_P_FR_RATE_TYPE(n) PREG(n, 0x0250)
114+#define FR_RATE_DYNAMIC 0
115+#define FR_RATE_FIXED 1
116+#define FR_RATE_FIXED_ACCURATE 2
117+#define REG_P_FR_RATE_Q_TYPE(n) PREG(n, 0x0252)
118+#define FR_RATE_Q_BEST_FRRATE 1 /* Binning enabled */
119+#define FR_RATE_Q_BEST_QUALITY 2 /* Binning disabled */
120+/* Frame period in 0.1 ms units */
121+#define REG_P_MAX_FR_TIME(n) PREG(n, 0x0254)
122+#define REG_P_MIN_FR_TIME(n) PREG(n, 0x0256)
123+/* Conversion to REG_P_[MAX/MIN]_FR_TIME value; __t: time in us */
124+#define US_TO_FR_TIME(__t) ((__t) / 100)
125+#define S5K6AA_MIN_FR_TIME 33300 /* us */
126+#define S5K6AA_MAX_FR_TIME 650000 /* us */
127+#define S5K6AA_MAX_HIGHRES_FR_TIME 666 /* x100 us */
128+/* The below 5 registers are for "device correction" values */
129+#define REG_P_COLORTEMP(n) PREG(n, 0x025e)
130+#define REG_P_PREV_MIRROR(n) PREG(n, 0x0262)
131+
132+/* Extended image property controls */
133+/* Exposure time in 10 us units */
134+#define REG_SF_USR_EXPOSURE_L 0x03c6
135+#define REG_SF_USR_EXPOSURE_H 0x03c8
136+#define REG_SF_USR_EXPOSURE_CHG 0x03ca
137+#define REG_SF_USR_TOT_GAIN 0x03cc
138+#define REG_SF_USR_TOT_GAIN_CHG 0x03ce
139+#define REG_SF_RGAIN 0x03d0
140+#define REG_SF_RGAIN_CHG 0x03d2
141+#define REG_SF_GGAIN 0x03d4
142+#define REG_SF_GGAIN_CHG 0x03d6
143+#define REG_SF_BGAIN 0x03d8
144+#define REG_SF_BGAIN_CHG 0x03da
145+#define REG_SF_FLICKER_QUANT 0x03dc
146+#define REG_SF_FLICKER_QUANT_CHG 0x03de
147+
148+/* Output interface (parallel/MIPI) setup */
149+#define REG_OIF_EN_MIPI_LANES 0x03fa
150+#define REG_OIF_EN_PACKETS 0x03fc
151+#define REG_OIF_CFG_CHG 0x03fe
152+
153+/* Auto-algorithms enable mask */
154+#define REG_DBG_AUTOALG_EN 0x0400
155+#define AALG_ALL_EN_MASK (1 << 0)
156+#define AALG_AE_EN_MASK (1 << 1)
157+#define AALG_DIVLEI_EN_MASK (1 << 2)
158+#define AALG_WB_EN_MASK (1 << 3)
159+#define AALG_FLICKER_EN_MASK (1 << 5)
160+#define AALG_FIT_EN_MASK (1 << 6)
161+#define AALG_WRHW_EN_MASK (1 << 7)
162+
163+/* Firmware revision information */
164+#define REG_FW_APIVER 0x012e
165+#define S5K6AAFX_FW_APIVER 0x0001
166+#define REG_FW_REVISION 0x0130
167+
168+/* For now we use only one user configuration register set */
169+#define S5K6AA_MAX_PRESETS 1
170+
171+static const char * const s5k6aa_supply_names[] = {
172+ "vdd_core", /* Digital core supply 1.5V (1.4V to 1.6V) */
173+ "vdda", /* Analog power supply 2.8V (2.6V to 3.0V) */
174+ "vdd_reg", /* Regulator input power 1.8V (1.7V to 1.9V)
175+ or 2.8V (2.6V to 3.0) */
176+ "vddio", /* I/O supply 1.8V (1.65V to 1.95V)
177+ or 2.8V (2.5V to 3.1V) */
178+};
179+#define S5K6AA_NUM_SUPPLIES ARRAY_SIZE(s5k6aa_supply_names)
180+
181+enum s5k6aa_gpio_id {
182+ STBY,
183+ RST,
184+ GPIO_NUM,
185+};
186+
187+struct s5k6aa_regval {
188+ u16 addr;
189+ u16 val;
190+};
191+
192+struct s5k6aa_pixfmt {
193+ enum v4l2_mbus_pixelcode code;
194+ u32 colorspace;
195+ /* REG_P_FMT(x) register value */
196+ u16 reg_p_fmt;
197+};
198+
199+struct s5k6aa_preset {
200+ /* output pixel format and resolution */
201+ struct v4l2_mbus_framefmt mbus_fmt;
202+ u8 clk_id;
203+ u8 index;
204+};
205+
206+struct s5k6aa_ctrls {
207+ struct v4l2_ctrl_handler handler;
208+ /* Auto / manual white balance cluster */
209+ struct v4l2_ctrl *awb;
210+ struct v4l2_ctrl *gain_red;
211+ struct v4l2_ctrl *gain_blue;
212+ struct v4l2_ctrl *gain_green;
213+ /* Mirror cluster */
214+ struct v4l2_ctrl *hflip;
215+ struct v4l2_ctrl *vflip;
216+ /* Auto exposure / manual exposure and gain cluster */
217+ struct v4l2_ctrl *auto_exp;
218+ struct v4l2_ctrl *exposure;
219+ struct v4l2_ctrl *gain;
220+};
221+
222+struct s5k6aa_interval {
223+ u16 reg_fr_time;
224+ struct v4l2_fract interval;
225+ /* Maximum rectangle for the interval */
226+ struct v4l2_frmsize_discrete size;
227+};
228+
229+struct s5k6aa {
230+ struct v4l2_subdev sd;
231+ struct media_pad pad;
232+
233+ enum v4l2_mbus_type bus_type;
234+ u8 mipi_lanes;
235+
236+ int (*s_power)(int enable);
237+ struct regulator_bulk_data supplies[S5K6AA_NUM_SUPPLIES];
238+ struct s5k6aa_gpio gpio[GPIO_NUM];
239+
240+ /* external master clock frequency */
241+ unsigned long mclk_frequency;
242+ /* ISP internal master clock frequency */
243+ u16 clk_fop;
244+ /* output pixel clock frequency range */
245+ u16 pclk_fmin;
246+ u16 pclk_fmax;
247+
248+ unsigned int inv_hflip:1;
249+ unsigned int inv_vflip:1;
250+
251+ /* protects the struct members below */
252+ struct mutex lock;
253+
254+ /* sensor matrix scan window */
255+ struct v4l2_rect ccd_rect;
256+
257+ struct s5k6aa_ctrls ctrls;
258+ struct s5k6aa_preset presets[S5K6AA_MAX_PRESETS];
259+ struct s5k6aa_preset *preset;
260+ const struct s5k6aa_interval *fiv;
261+
262+ unsigned int streaming:1;
263+ unsigned int apply_cfg:1;
264+ unsigned int apply_crop:1;
265+ unsigned int power;
266+};
267+
268+static struct s5k6aa_regval s5k6aa_analog_config[] = {
269+ /* Analog settings */
270+ { 0x112a, 0x0000 }, { 0x1132, 0x0000 },
271+ { 0x113e, 0x0000 }, { 0x115c, 0x0000 },
272+ { 0x1164, 0x0000 }, { 0x1174, 0x0000 },
273+ { 0x1178, 0x0000 }, { 0x077a, 0x0000 },
274+ { 0x077c, 0x0000 }, { 0x077e, 0x0000 },
275+ { 0x0780, 0x0000 }, { 0x0782, 0x0000 },
276+ { 0x0784, 0x0000 }, { 0x0786, 0x0000 },
277+ { 0x0788, 0x0000 }, { 0x07a2, 0x0000 },
278+ { 0x07a4, 0x0000 }, { 0x07a6, 0x0000 },
279+ { 0x07a8, 0x0000 }, { 0x07b6, 0x0000 },
280+ { 0x07b8, 0x0002 }, { 0x07ba, 0x0004 },
281+ { 0x07bc, 0x0004 }, { 0x07be, 0x0005 },
282+ { 0x07c0, 0x0005 }, { S5K6AA_TERM, 0 },
283+};
284+
285+/* TODO: Add RGB888 and Bayer format */
286+static const struct s5k6aa_pixfmt s5k6aa_formats[] = {
287+ { V4L2_MBUS_FMT_YUYV8_2X8, V4L2_COLORSPACE_JPEG, 5 },
288+ /* range 16-240 */
289+ { V4L2_MBUS_FMT_YUYV8_2X8, V4L2_COLORSPACE_REC709, 6 },
290+ { V4L2_MBUS_FMT_RGB565_2X8_BE, V4L2_COLORSPACE_JPEG, 0 },
291+};
292+
293+static const struct s5k6aa_interval s5k6aa_intervals[] = {
294+ { 1000, {10000, 1000000}, {1280, 1024} }, /* 10 fps */
295+ { 666, {15000, 1000000}, {1280, 1024} }, /* 15 fps */
296+ { 500, {20000, 1000000}, {1280, 720} }, /* 20 fps */
297+ { 400, {25000, 1000000}, {640, 480} }, /* 25 fps */
298+ { 333, {33300, 1000000}, {640, 480} }, /* 30 fps */
299+};
300+
301+#define S5K6AA_INTERVAL_DEF_INDEX 1 /* 15 fps */
302+
303+static inline struct v4l2_subdev *ctrl_to_sd(struct v4l2_ctrl *ctrl)
304+{
305+ return &container_of(ctrl->handler, struct s5k6aa, ctrls.handler)->sd;
306+}
307+
308+static inline struct s5k6aa *to_s5k6aa(struct v4l2_subdev *sd)
309+{
310+ return container_of(sd, struct s5k6aa, sd);
311+}
312+
313+/* Set initial values for all preview presets */
314+static void s5k6aa_presets_data_init(struct s5k6aa *s5k6aa)
315+{
316+ struct s5k6aa_preset *preset = &s5k6aa->presets[0];
317+ int i;
318+
319+ for (i = 0; i < S5K6AA_MAX_PRESETS; i++) {
320+ preset->mbus_fmt.width = S5K6AA_OUT_WIDTH_DEF;
321+ preset->mbus_fmt.height = S5K6AA_OUT_HEIGHT_DEF;
322+ preset->mbus_fmt.code = s5k6aa_formats[0].code;
323+ preset->index = i;
324+ preset->clk_id = 0;
325+ preset++;
326+ }
327+
328+ s5k6aa->fiv = &s5k6aa_intervals[S5K6AA_INTERVAL_DEF_INDEX];
329+ s5k6aa->preset = &s5k6aa->presets[0];
330+}
331+
332+static int s5k6aa_i2c_read(struct i2c_client *client, u16 addr, u16 *val)
333+{
334+ u8 wbuf[2] = {addr >> 8, addr & 0xFF};
335+ struct i2c_msg msg[2];
336+ u8 rbuf[2];
337+ int ret;
338+
339+ msg[0].addr = client->addr;
340+ msg[0].flags = 0;
341+ msg[0].len = 2;
342+ msg[0].buf = wbuf;
343+
344+ msg[1].addr = client->addr;
345+ msg[1].flags = I2C_M_RD;
346+ msg[1].len = 2;
347+ msg[1].buf = rbuf;
348+
349+ ret = i2c_transfer(client->adapter, msg, 2);
350+ *val = be16_to_cpu(*((u16 *)rbuf));
351+
352+ v4l2_dbg(3, debug, client, "i2c_read: 0x%04X : 0x%04x\n", addr, *val);
353+
354+ return ret == 2 ? 0 : ret;
355+}
356+
357+static int s5k6aa_i2c_write(struct i2c_client *client, u16 addr, u16 val)
358+{
359+ u8 buf[4] = {addr >> 8, addr & 0xFF, val >> 8, val & 0xFF};
360+
361+ int ret = i2c_master_send(client, buf, 4);
362+ v4l2_dbg(3, debug, client, "i2c_write: 0x%04X : 0x%04x\n", addr, val);
363+
364+ return ret == 4 ? 0 : ret;
365+}
366+
367+/* The command register write, assumes Command_Wr_addH = 0x7000. */
368+static int s5k6aa_write(struct i2c_client *c, u16 addr, u16 val)
369+{
370+ int ret = s5k6aa_i2c_write(c, REG_CMDWR_ADDRL, addr);
371+ if (ret)
372+ return ret;
373+ return s5k6aa_i2c_write(c, REG_CMDBUF0_ADDR, val);
374+}
375+
376+/* The command register read, assumes Command_Rd_addH = 0x7000. */
377+static int s5k6aa_read(struct i2c_client *client, u16 addr, u16 *val)
378+{
379+ int ret = s5k6aa_i2c_write(client, REG_CMDRD_ADDRL, addr);
380+ if (ret)
381+ return ret;
382+ return s5k6aa_i2c_read(client, REG_CMDBUF0_ADDR, val);
383+}
384+
385+static int s5k6aa_write_array(struct v4l2_subdev *sd,
386+ const struct s5k6aa_regval *msg)
387+{
388+ struct i2c_client *client = v4l2_get_subdevdata(sd);
389+ u16 addr_incr = 0;
390+ int ret = 0;
391+
392+ while (msg->addr != S5K6AA_TERM) {
393+ if (addr_incr != 2)
394+ ret = s5k6aa_i2c_write(client, REG_CMDWR_ADDRL,
395+ msg->addr);
396+ if (ret)
397+ break;
398+ ret = s5k6aa_i2c_write(client, REG_CMDBUF0_ADDR, msg->val);
399+ if (ret)
400+ break;
401+ /* Assume that msg->addr is always less than 0xfffc */
402+ addr_incr = (msg + 1)->addr - msg->addr;
403+ msg++;
404+ }
405+
406+ return ret;
407+}
408+
409+/* Configure the AHB high address bytes for GTG registers access */
410+static int s5k6aa_set_ahb_address(struct i2c_client *client)
411+{
412+ int ret = s5k6aa_i2c_write(client, AHB_MSB_ADDR_PTR, GEN_REG_OFFSH);
413+ if (ret)
414+ return ret;
415+ ret = s5k6aa_i2c_write(client, REG_CMDRD_ADDRH, HOST_SWIF_OFFSH);
416+ if (ret)
417+ return ret;
418+ return s5k6aa_i2c_write(client, REG_CMDWR_ADDRH, HOST_SWIF_OFFSH);
419+}
420+
421+/**
422+ * s5k6aa_configure_pixel_clock - apply ISP main clock/PLL configuration
423+ *
424+ * Configure the internal ISP PLL for the required output frequency.
425+ * Locking: called with s5k6aa.lock mutex held.
426+ */
427+static int s5k6aa_configure_pixel_clocks(struct s5k6aa *s5k6aa)
428+{
429+ struct i2c_client *c = v4l2_get_subdevdata(&s5k6aa->sd);
430+ unsigned long fmclk = s5k6aa->mclk_frequency / 1000;
431+ u16 status;
432+ int ret;
433+
434+ if (WARN(fmclk < MIN_MCLK_FREQ_KHZ || fmclk > MAX_MCLK_FREQ_KHZ,
435+ "Invalid clock frequency: %ld\n", fmclk))
436+ return -EINVAL;
437+
438+ s5k6aa->pclk_fmin = PCLK_FREQ_MIN;
439+ s5k6aa->pclk_fmax = PCLK_FREQ_MAX;
440+ s5k6aa->clk_fop = SYS_PLL_OUT_FREQ;
441+
442+ /* External input clock frequency in kHz */
443+ ret = s5k6aa_write(c, REG_I_INCLK_FREQ_H, fmclk >> 16);
444+ if (!ret)
445+ ret = s5k6aa_write(c, REG_I_INCLK_FREQ_L, fmclk & 0xFFFF);
446+ if (!ret)
447+ ret = s5k6aa_write(c, REG_I_USE_NPVI_CLOCKS, 1);
448+ /* Internal PLL frequency */
449+ if (!ret)
450+ ret = s5k6aa_write(c, REG_I_OPCLK_4KHZ(0), s5k6aa->clk_fop);
451+ if (!ret)
452+ ret = s5k6aa_write(c, REG_I_MIN_OUTRATE_4KHZ(0),
453+ s5k6aa->pclk_fmin);
454+ if (!ret)
455+ ret = s5k6aa_write(c, REG_I_MAX_OUTRATE_4KHZ(0),
456+ s5k6aa->pclk_fmax);
457+ if (!ret)
458+ ret = s5k6aa_write(c, REG_I_INIT_PARAMS_UPDATED, 1);
459+ if (!ret)
460+ ret = s5k6aa_read(c, REG_I_ERROR_INFO, &status);
461+
462+ return ret ? ret : (status ? -EINVAL : 0);
463+}
464+
465+/* Set horizontal and vertical image flipping */
466+static int s5k6aa_set_mirror(struct s5k6aa *s5k6aa, int horiz_flip)
467+{
468+ struct i2c_client *client = v4l2_get_subdevdata(&s5k6aa->sd);
469+ int index = s5k6aa->preset->index;
470+
471+ unsigned int vflip = s5k6aa->ctrls.vflip->val ^ s5k6aa->inv_vflip;
472+ unsigned int flip = (horiz_flip ^ s5k6aa->inv_hflip) | (vflip << 1);
473+
474+ return s5k6aa_write(client, REG_P_PREV_MIRROR(index), flip);
475+}
476+
477+/* Configure auto/manual white balance and R/G/B gains */
478+static int s5k6aa_set_awb(struct s5k6aa *s5k6aa, int awb)
479+{
480+ struct i2c_client *c = v4l2_get_subdevdata(&s5k6aa->sd);
481+ struct s5k6aa_ctrls *ctrls = &s5k6aa->ctrls;
482+ u16 reg;
483+
484+ int ret = s5k6aa_read(c, REG_DBG_AUTOALG_EN, &reg);
485+
486+ if (!ret && !awb) {
487+ ret = s5k6aa_write(c, REG_SF_RGAIN, ctrls->gain_red->val);
488+ if (!ret)
489+ ret = s5k6aa_write(c, REG_SF_RGAIN_CHG, 1);
490+ if (ret)
491+ return ret;
492+
493+ ret = s5k6aa_write(c, REG_SF_GGAIN, ctrls->gain_green->val);
494+ if (!ret)
495+ ret = s5k6aa_write(c, REG_SF_GGAIN_CHG, 1);
496+ if (ret)
497+ return ret;
498+
499+ ret = s5k6aa_write(c, REG_SF_BGAIN, ctrls->gain_blue->val);
500+ if (!ret)
501+ ret = s5k6aa_write(c, REG_SF_BGAIN_CHG, 1);
502+ }
503+ if (!ret) {
504+ reg = awb ? reg | AALG_WB_EN_MASK : reg & ~AALG_WB_EN_MASK;
505+ ret = s5k6aa_write(c, REG_DBG_AUTOALG_EN, reg);
506+ }
507+
508+ return ret;
509+}
510+
511+/* Program FW with exposure time, 'exposure' in us units */
512+static int s5k6aa_set_user_exposure(struct i2c_client *client, int exposure)
513+{
514+ unsigned int time = exposure / 10;
515+
516+ int ret = s5k6aa_write(client, REG_SF_USR_EXPOSURE_L, time & 0xffff);
517+ if (!ret)
518+ ret = s5k6aa_write(client, REG_SF_USR_EXPOSURE_H, time >> 16);
519+ if (ret)
520+ return ret;
521+ return s5k6aa_write(client, REG_SF_USR_EXPOSURE_CHG, 1);
522+}
523+
524+static int s5k6aa_set_user_gain(struct i2c_client *client, int gain)
525+{
526+ int ret = s5k6aa_write(client, REG_SF_USR_TOT_GAIN, gain);
527+ if (ret)
528+ return ret;
529+ return s5k6aa_write(client, REG_SF_USR_TOT_GAIN_CHG, 1);
530+}
531+
532+/* Set auto/manual exposure and total gain */
533+static int s5k6aa_set_auto_exposure(struct s5k6aa *s5k6aa, int value)
534+{
535+ struct i2c_client *c = v4l2_get_subdevdata(&s5k6aa->sd);
536+ unsigned int exp_time = s5k6aa->ctrls.exposure->val;
537+ u16 auto_alg;
538+
539+ int ret = s5k6aa_read(c, REG_DBG_AUTOALG_EN, &auto_alg);
540+ if (ret)
541+ return ret;
542+
543+ v4l2_dbg(1, debug, c, "man_exp: %d, auto_exp: %d, a_alg: 0x%x\n",
544+ exp_time, value, auto_alg);
545+
546+ if (value == V4L2_EXPOSURE_AUTO) {
547+ auto_alg |= AALG_AE_EN_MASK | AALG_DIVLEI_EN_MASK;
548+ } else {
549+ ret = s5k6aa_set_user_exposure(c, exp_time);
550+ if (ret)
551+ return ret;
552+ ret = s5k6aa_set_user_gain(c, s5k6aa->ctrls.gain->val);
553+ if (ret)
554+ return ret;
555+ auto_alg &= ~(AALG_AE_EN_MASK | AALG_DIVLEI_EN_MASK);
556+ }
557+
558+ return s5k6aa_write(c, REG_DBG_AUTOALG_EN, auto_alg);
559+}
560+
561+static int s5k6aa_set_anti_flicker(struct s5k6aa *s5k6aa, int value)
562+{
563+ struct i2c_client *client = v4l2_get_subdevdata(&s5k6aa->sd);
564+ u16 auto_alg;
565+ int ret;
566+
567+ ret = s5k6aa_read(client, REG_DBG_AUTOALG_EN, &auto_alg);
568+ if (ret)
569+ return ret;
570+
571+ if (value == V4L2_CID_POWER_LINE_FREQUENCY_AUTO) {
572+ auto_alg |= AALG_FLICKER_EN_MASK;
573+ } else {
574+ auto_alg &= ~AALG_FLICKER_EN_MASK;
575+ /* The V4L2_CID_LINE_FREQUENCY control values match
576+ * the register values */
577+ ret = s5k6aa_write(client, REG_SF_FLICKER_QUANT, value);
578+ if (ret)
579+ return ret;
580+ ret = s5k6aa_write(client, REG_SF_FLICKER_QUANT_CHG, 1);
581+ if (ret)
582+ return ret;
583+ }
584+
585+ return s5k6aa_write(client, REG_DBG_AUTOALG_EN, auto_alg);
586+}
587+
588+static int s5k6aa_set_colorfx(struct s5k6aa *s5k6aa, int val)
589+{
590+ struct i2c_client *client = v4l2_get_subdevdata(&s5k6aa->sd);
591+ static const struct v4l2_control colorfx[] = {
592+ { V4L2_COLORFX_NONE, 0 },
593+ { V4L2_COLORFX_BW, 1 },
594+ { V4L2_COLORFX_NEGATIVE, 2 },
595+ { V4L2_COLORFX_SEPIA, 3 },
596+ { V4L2_COLORFX_SKY_BLUE, 4 },
597+ { V4L2_COLORFX_SKETCH, 5 },
598+ };
599+ int i;
600+
601+ for (i = 0; i < ARRAY_SIZE(colorfx); i++) {
602+ if (colorfx[i].id == val)
603+ return s5k6aa_write(client, REG_G_SPEC_EFFECTS,
604+ colorfx[i].value);
605+ }
606+ return -EINVAL;
607+}
608+
609+static int s5k6aa_preview_config_status(struct i2c_client *client)
610+{
611+ u16 error = 0;
612+ int ret = s5k6aa_read(client, REG_G_PREV_CFG_ERROR, &error);
613+
614+ v4l2_dbg(1, debug, client, "error: 0x%x (%d)\n", error, ret);
615+ return ret ? ret : (error ? -EINVAL : 0);
616+}
617+
618+static int s5k6aa_get_pixfmt_index(struct s5k6aa *s5k6aa,
619+ struct v4l2_mbus_framefmt *mf)
620+{
621+ unsigned int i;
622+
623+ for (i = 0; i < ARRAY_SIZE(s5k6aa_formats); i++)
624+ if (mf->colorspace == s5k6aa_formats[i].colorspace &&
625+ mf->code == s5k6aa_formats[i].code)
626+ return i;
627+ return 0;
628+}
629+
630+static int s5k6aa_set_output_framefmt(struct s5k6aa *s5k6aa,
631+ struct s5k6aa_preset *preset)
632+{
633+ struct i2c_client *client = v4l2_get_subdevdata(&s5k6aa->sd);
634+ int fmt_index = s5k6aa_get_pixfmt_index(s5k6aa, &preset->mbus_fmt);
635+ int ret;
636+
637+ ret = s5k6aa_write(client, REG_P_OUT_WIDTH(preset->index),
638+ preset->mbus_fmt.width);
639+ if (!ret)
640+ ret = s5k6aa_write(client, REG_P_OUT_HEIGHT(preset->index),
641+ preset->mbus_fmt.height);
642+ if (!ret)
643+ ret = s5k6aa_write(client, REG_P_FMT(preset->index),
644+ s5k6aa_formats[fmt_index].reg_p_fmt);
645+ return ret;
646+}
647+
648+static int s5k6aa_set_input_params(struct s5k6aa *s5k6aa)
649+{
650+ struct i2c_client *c = v4l2_get_subdevdata(&s5k6aa->sd);
651+ struct v4l2_rect *r = &s5k6aa->ccd_rect;
652+ int ret;
653+
654+ ret = s5k6aa_write(c, REG_G_PREVZOOM_IN_WIDTH, r->width);
655+ if (!ret)
656+ ret = s5k6aa_write(c, REG_G_PREVZOOM_IN_HEIGHT, r->height);
657+ if (!ret)
658+ ret = s5k6aa_write(c, REG_G_PREVZOOM_IN_XOFFS, r->left);
659+ if (!ret)
660+ ret = s5k6aa_write(c, REG_G_PREVZOOM_IN_YOFFS, r->top);
661+ if (!ret)
662+ ret = s5k6aa_write(c, REG_G_INPUTS_CHANGE_REQ, 1);
663+ if (!ret)
664+ s5k6aa->apply_crop = 0;
665+
666+ return ret;
667+}
668+
669+/**
670+ * s5k6aa_configure_video_bus - configure the video output interface
671+ * @bus_type: video bus type: parallel or MIPI-CSI
672+ * @nlanes: number of MIPI lanes to be used (MIPI-CSI only)
673+ *
674+ * Note: Only parallel bus operation has been tested.
675+ */
676+static int s5k6aa_configure_video_bus(struct s5k6aa *s5k6aa,
677+ enum v4l2_mbus_type bus_type, int nlanes)
678+{
679+ struct i2c_client *client = v4l2_get_subdevdata(&s5k6aa->sd);
680+ u16 cfg = 0;
681+ int ret;
682+
683+ /*
684+ * TODO: The sensor is supposed to support BT.601 and BT.656
685+ * but there is nothing indicating how to switch between both
686+ * in the datasheet. For now default BT.601 interface is assumed.
687+ */
688+ if (bus_type == V4L2_MBUS_CSI2)
689+ cfg = nlanes;
690+ else if (bus_type != V4L2_MBUS_PARALLEL)
691+ return -EINVAL;
692+
693+ ret = s5k6aa_write(client, REG_OIF_EN_MIPI_LANES, cfg);
694+ if (ret)
695+ return ret;
696+ return s5k6aa_write(client, REG_OIF_CFG_CHG, 1);
697+}
698+
699+/* This function should be called when switching to new user configuration set*/
700+static int s5k6aa_new_config_sync(struct i2c_client *client, int timeout,
701+ int cid)
702+{
703+ unsigned long end = jiffies + msecs_to_jiffies(timeout);
704+ u16 reg = 1;
705+ int ret;
706+
707+ ret = s5k6aa_write(client, REG_G_ACTIVE_PREV_CFG, cid);
708+ if (!ret)
709+ ret = s5k6aa_write(client, REG_G_PREV_CFG_CHG, 1);
710+ if (!ret)
711+ ret = s5k6aa_write(client, REG_G_NEW_CFG_SYNC, 1);
712+ if (timeout == 0)
713+ return ret;
714+
715+ while (ret >= 0 && time_is_after_jiffies(end)) {
716+ ret = s5k6aa_read(client, REG_G_NEW_CFG_SYNC, &reg);
717+ if (!reg)
718+ return 0;
719+ usleep_range(1000, 5000);
720+ }
721+ return ret ? ret : -ETIMEDOUT;
722+}
723+
724+/**
725+ * s5k6aa_set_prev_config - write user preview register set
726+ *
727+ * Configure output resolution and color fromat, pixel clock
728+ * frequency range, device frame rate type and frame period range.
729+ */
730+static int s5k6aa_set_prev_config(struct s5k6aa *s5k6aa,
731+ struct s5k6aa_preset *preset)
732+{
733+ struct i2c_client *client = v4l2_get_subdevdata(&s5k6aa->sd);
734+ int idx = preset->index;
735+ u16 frame_rate_q;
736+ int ret;
737+
738+ if (s5k6aa->fiv->reg_fr_time >= S5K6AA_MAX_HIGHRES_FR_TIME)
739+ frame_rate_q = FR_RATE_Q_BEST_FRRATE;
740+ else
741+ frame_rate_q = FR_RATE_Q_BEST_QUALITY;
742+
743+ ret = s5k6aa_set_output_framefmt(s5k6aa, preset);
744+ if (!ret)
745+ ret = s5k6aa_write(client, REG_P_MAX_OUT_RATE(idx),
746+ s5k6aa->pclk_fmax);
747+ if (!ret)
748+ ret = s5k6aa_write(client, REG_P_MIN_OUT_RATE(idx),
749+ s5k6aa->pclk_fmin);
750+ if (!ret)
751+ ret = s5k6aa_write(client, REG_P_CLK_INDEX(idx),
752+ preset->clk_id);
753+ if (!ret)
754+ ret = s5k6aa_write(client, REG_P_FR_RATE_TYPE(idx),
755+ FR_RATE_DYNAMIC);
756+ if (!ret)
757+ ret = s5k6aa_write(client, REG_P_FR_RATE_Q_TYPE(idx),
758+ frame_rate_q);
759+ if (!ret)
760+ ret = s5k6aa_write(client, REG_P_MAX_FR_TIME(idx),
761+ s5k6aa->fiv->reg_fr_time + 33);
762+ if (!ret)
763+ ret = s5k6aa_write(client, REG_P_MIN_FR_TIME(idx),
764+ s5k6aa->fiv->reg_fr_time - 33);
765+ if (!ret)
766+ ret = s5k6aa_new_config_sync(client, 250, idx);
767+ if (!ret)
768+ ret = s5k6aa_preview_config_status(client);
769+ if (!ret)
770+ s5k6aa->apply_cfg = 0;
771+
772+ v4l2_dbg(1, debug, client, "Frame interval: %d +/- 3.3ms. (%d)\n",
773+ s5k6aa->fiv->reg_fr_time, ret);
774+ return ret;
775+}
776+
777+/**
778+ * s5k6aa_initialize_isp - basic ISP MCU initialization
779+ *
780+ * Configure AHB addresses for registers read/write; configure PLLs for
781+ * required output pixel clock. The ISP power supply needs to be already
782+ * enabled, with an optional H/W reset.
783+ * Locking: called with s5k6aa.lock mutex held.
784+ */
785+static int s5k6aa_initialize_isp(struct v4l2_subdev *sd)
786+{
787+ struct i2c_client *client = v4l2_get_subdevdata(sd);
788+ struct s5k6aa *s5k6aa = to_s5k6aa(sd);
789+ int ret;
790+
791+ s5k6aa->apply_crop = 1;
792+ s5k6aa->apply_cfg = 1;
793+ msleep(100);
794+
795+ ret = s5k6aa_set_ahb_address(client);
796+ if (ret)
797+ return ret;
798+ ret = s5k6aa_configure_video_bus(s5k6aa, s5k6aa->bus_type,
799+ s5k6aa->mipi_lanes);
800+ if (ret)
801+ return ret;
802+ ret = s5k6aa_write_array(sd, s5k6aa_analog_config);
803+ if (ret)
804+ return ret;
805+ msleep(20);
806+
807+ return s5k6aa_configure_pixel_clocks(s5k6aa);
808+}
809+
810+static int s5k6aa_gpio_set_value(struct s5k6aa *priv, int id, u32 val)
811+{
812+ if (!gpio_is_valid(priv->gpio[id].gpio))
813+ return 0;
814+ gpio_set_value(priv->gpio[id].gpio, !!val);
815+ return 1;
816+}
817+
818+static int s5k6aa_gpio_assert(struct s5k6aa *priv, int id)
819+{
820+ return s5k6aa_gpio_set_value(priv, id, priv->gpio[id].level);
821+}
822+
823+static int s5k6aa_gpio_deassert(struct s5k6aa *priv, int id)
824+{
825+ return s5k6aa_gpio_set_value(priv, id, !priv->gpio[id].level);
826+}
827+
828+static int __s5k6aa_power_on(struct s5k6aa *s5k6aa)
829+{
830+ int ret;
831+
832+ ret = regulator_bulk_enable(S5K6AA_NUM_SUPPLIES, s5k6aa->supplies);
833+ if (ret)
834+ return ret;
835+ if (s5k6aa_gpio_deassert(s5k6aa, STBY))
836+ usleep_range(150, 200);
837+
838+ if (s5k6aa->s_power)
839+ ret = s5k6aa->s_power(1);
840+ usleep_range(4000, 4000);
841+
842+ if (s5k6aa_gpio_deassert(s5k6aa, RST))
843+ msleep(20);
844+
845+ return ret;
846+}
847+
848+static int __s5k6aa_power_off(struct s5k6aa *s5k6aa)
849+{
850+ int ret;
851+
852+ if (s5k6aa_gpio_assert(s5k6aa, RST))
853+ usleep_range(100, 150);
854+
855+ if (s5k6aa->s_power) {
856+ ret = s5k6aa->s_power(0);
857+ if (ret)
858+ return ret;
859+ }
860+ if (s5k6aa_gpio_assert(s5k6aa, STBY))
861+ usleep_range(50, 100);
862+ s5k6aa->streaming = 0;
863+
864+ return regulator_bulk_disable(S5K6AA_NUM_SUPPLIES, s5k6aa->supplies);
865+}
866+
867+/*
868+ * V4L2 subdev core and video operations
869+ */
870+static int s5k6aa_set_power(struct v4l2_subdev *sd, int on)
871+{
872+ struct s5k6aa *s5k6aa = to_s5k6aa(sd);
873+ int ret = 0;
874+
875+ mutex_lock(&s5k6aa->lock);
876+
877+ if (!on == s5k6aa->power) {
878+ if (on) {
879+ ret = __s5k6aa_power_on(s5k6aa);
880+ if (!ret)
881+ ret = s5k6aa_initialize_isp(sd);
882+ } else {
883+ ret = __s5k6aa_power_off(s5k6aa);
884+ }
885+
886+ if (!ret)
887+ s5k6aa->power += on ? 1 : -1;
888+ }
889+
890+ mutex_unlock(&s5k6aa->lock);
891+
892+ if (!on || ret || s5k6aa->power != 1)
893+ return ret;
894+
895+ return v4l2_ctrl_handler_setup(sd->ctrl_handler);
896+}
897+
898+static int __s5k6aa_stream(struct s5k6aa *s5k6aa, int enable)
899+{
900+ struct i2c_client *client = v4l2_get_subdevdata(&s5k6aa->sd);
901+ int ret = 0;
902+
903+ ret = s5k6aa_write(client, REG_G_ENABLE_PREV, enable);
904+ if (!ret)
905+ ret = s5k6aa_write(client, REG_G_ENABLE_PREV_CHG, 1);
906+ if (!ret)
907+ s5k6aa->streaming = enable;
908+
909+ return ret;
910+}
911+
912+static int s5k6aa_s_stream(struct v4l2_subdev *sd, int on)
913+{
914+ struct s5k6aa *s5k6aa = to_s5k6aa(sd);
915+ int ret = 0;
916+
917+ mutex_lock(&s5k6aa->lock);
918+
919+ if (s5k6aa->streaming == !on) {
920+ if (!ret && s5k6aa->apply_cfg)
921+ ret = s5k6aa_set_prev_config(s5k6aa, s5k6aa->preset);
922+ if (s5k6aa->apply_crop)
923+ ret = s5k6aa_set_input_params(s5k6aa);
924+ if (!ret)
925+ ret = __s5k6aa_stream(s5k6aa, !!on);
926+ }
927+ mutex_unlock(&s5k6aa->lock);
928+
929+ return ret;
930+}
931+
932+static int s5k6aa_g_frame_interval(struct v4l2_subdev *sd,
933+ struct v4l2_subdev_frame_interval *fi)
934+{
935+ struct s5k6aa *s5k6aa = to_s5k6aa(sd);
936+
937+ mutex_lock(&s5k6aa->lock);
938+ fi->interval = s5k6aa->fiv->interval;
939+ mutex_unlock(&s5k6aa->lock);
940+
941+ return 0;
942+}
943+
944+static int __s5k6aa_set_frame_interval(struct s5k6aa *s5k6aa,
945+ struct v4l2_subdev_frame_interval *fi)
946+{
947+ struct v4l2_mbus_framefmt *mbus_fmt = &s5k6aa->preset->mbus_fmt;
948+ const struct s5k6aa_interval *fiv = &s5k6aa_intervals[0];
949+ unsigned int err, min_err = UINT_MAX;
950+ unsigned int i, fr_time;
951+
952+ if (fi->interval.denominator == 0)
953+ return -EINVAL;
954+
955+ fr_time = fi->interval.numerator * 10000 / fi->interval.denominator;
956+
957+ for (i = 0; i < ARRAY_SIZE(s5k6aa_intervals); i++) {
958+ const struct s5k6aa_interval *iv = &s5k6aa_intervals[i];
959+
960+ if (mbus_fmt->width > iv->size.width ||
961+ mbus_fmt->height > iv->size.height)
962+ continue;
963+
964+ err = abs(iv->reg_fr_time - fr_time);
965+ if (err < min_err) {
966+ fiv = iv;
967+ min_err = err;
968+ }
969+ }
970+ s5k6aa->fiv = fiv;
971+
972+ v4l2_dbg(1, debug, &s5k6aa->sd, "Changed frame interval to %d us\n",
973+ fiv->reg_fr_time * 100);
974+ return 0;
975+}
976+
977+static int s5k6aa_s_frame_interval(struct v4l2_subdev *sd,
978+ struct v4l2_subdev_frame_interval *fi)
979+{
980+ struct s5k6aa *s5k6aa = to_s5k6aa(sd);
981+ int ret;
982+
983+ v4l2_dbg(1, debug, sd, "Setting %d/%d frame interval\n",
984+ fi->interval.numerator, fi->interval.denominator);
985+
986+ mutex_lock(&s5k6aa->lock);
987+ ret = __s5k6aa_set_frame_interval(s5k6aa, fi);
988+ s5k6aa->apply_cfg = 1;
989+
990+ mutex_unlock(&s5k6aa->lock);
991+ return ret;
992+}
993+
994+/*
995+ * V4L2 subdev pad level and video operations
996+ */
997+static int s5k6aa_enum_frame_interval(struct v4l2_subdev *sd,
998+ struct v4l2_subdev_fh *fh,
999+ struct v4l2_subdev_frame_interval_enum *fie)
1000+{
1001+ struct s5k6aa *s5k6aa = to_s5k6aa(sd);
1002+ const struct s5k6aa_interval *fi;
1003+ int ret = 0;
1004+
1005+ if (fie->index > ARRAY_SIZE(s5k6aa_intervals))
1006+ return -EINVAL;
1007+
1008+ v4l_bound_align_image(&fie->width, S5K6AA_WIN_WIDTH_MIN,
1009+ S5K6AA_WIN_WIDTH_MAX, 1,
1010+ &fie->height, S5K6AA_WIN_HEIGHT_MIN,
1011+ S5K6AA_WIN_HEIGHT_MAX, 1, 0);
1012+
1013+ mutex_lock(&s5k6aa->lock);
1014+ fi = &s5k6aa_intervals[fie->index];
1015+ if (fie->width > fi->size.width || fie->height > fi->size.height)
1016+ ret = -EINVAL;
1017+ else
1018+ fie->interval = fi->interval;
1019+ mutex_unlock(&s5k6aa->lock);
1020+
1021+ return ret;
1022+}
1023+
1024+static int s5k6aa_enum_mbus_code(struct v4l2_subdev *sd,
1025+ struct v4l2_subdev_fh *fh,
1026+ struct v4l2_subdev_mbus_code_enum *code)
1027+{
1028+ if (code->index >= ARRAY_SIZE(s5k6aa_formats))
1029+ return -EINVAL;
1030+
1031+ code->code = s5k6aa_formats[code->index].code;
1032+ return 0;
1033+}
1034+
1035+static int s5k6aa_enum_frame_size(struct v4l2_subdev *sd,
1036+ struct v4l2_subdev_fh *fh,
1037+ struct v4l2_subdev_frame_size_enum *fse)
1038+{
1039+ int i = ARRAY_SIZE(s5k6aa_formats);
1040+
1041+ if (fse->index > 0)
1042+ return -EINVAL;
1043+
1044+ while (--i)
1045+ if (fse->code == s5k6aa_formats[i].code)
1046+ break;
1047+
1048+ fse->code = s5k6aa_formats[i].code;
1049+ fse->min_width = S5K6AA_WIN_WIDTH_MIN;
1050+ fse->max_width = S5K6AA_WIN_WIDTH_MAX;
1051+ fse->max_height = S5K6AA_WIN_HEIGHT_MIN;
1052+ fse->min_height = S5K6AA_WIN_HEIGHT_MAX;
1053+
1054+ return 0;
1055+}
1056+
1057+static struct v4l2_rect *
1058+__s5k6aa_get_crop_rect(struct s5k6aa *s5k6aa, struct v4l2_subdev_fh *fh,
1059+ enum v4l2_subdev_format_whence which)
1060+{
1061+ if (which == V4L2_SUBDEV_FORMAT_ACTIVE)
1062+ return &s5k6aa->ccd_rect;
1063+ if (which == V4L2_SUBDEV_FORMAT_TRY)
1064+ return v4l2_subdev_get_try_crop(fh, 0);
1065+
1066+ return NULL;
1067+}
1068+
1069+static void s5k6aa_try_format(struct s5k6aa *s5k6aa,
1070+ struct v4l2_mbus_framefmt *mf)
1071+{
1072+ unsigned int index;
1073+
1074+ v4l_bound_align_image(&mf->width, S5K6AA_WIN_WIDTH_MIN,
1075+ S5K6AA_WIN_WIDTH_MAX, 1,
1076+ &mf->height, S5K6AA_WIN_HEIGHT_MIN,
1077+ S5K6AA_WIN_HEIGHT_MAX, 1, 0);
1078+
1079+ if (mf->colorspace != V4L2_COLORSPACE_JPEG &&
1080+ mf->colorspace != V4L2_COLORSPACE_REC709)
1081+ mf->colorspace = V4L2_COLORSPACE_JPEG;
1082+
1083+ index = s5k6aa_get_pixfmt_index(s5k6aa, mf);
1084+
1085+ mf->colorspace = s5k6aa_formats[index].colorspace;
1086+ mf->code = s5k6aa_formats[index].code;
1087+ mf->field = V4L2_FIELD_NONE;
1088+}
1089+
1090+static int s5k6aa_get_fmt(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh,
1091+ struct v4l2_subdev_format *fmt)
1092+{
1093+ struct s5k6aa *s5k6aa = to_s5k6aa(sd);
1094+ struct v4l2_mbus_framefmt *mf;
1095+
1096+ memset(fmt->reserved, 0, sizeof(fmt->reserved));
1097+
1098+ if (fmt->which == V4L2_SUBDEV_FORMAT_TRY) {
1099+ mf = v4l2_subdev_get_try_format(fh, 0);
1100+ fmt->format = *mf;
1101+ return 0;
1102+ }
1103+
1104+ mutex_lock(&s5k6aa->lock);
1105+ fmt->format = s5k6aa->preset->mbus_fmt;
1106+ mutex_unlock(&s5k6aa->lock);
1107+
1108+ return 0;
1109+}
1110+
1111+static int s5k6aa_set_fmt(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh,
1112+ struct v4l2_subdev_format *fmt)
1113+{
1114+ struct s5k6aa *s5k6aa = to_s5k6aa(sd);
1115+ struct s5k6aa_preset *preset = s5k6aa->preset;
1116+ struct v4l2_mbus_framefmt *mf;
1117+ struct v4l2_rect *crop;
1118+ int ret = 0;
1119+
1120+ mutex_lock(&s5k6aa->lock);
1121+ s5k6aa_try_format(s5k6aa, &fmt->format);
1122+
1123+ if (fmt->which == V4L2_SUBDEV_FORMAT_TRY) {
1124+ mf = v4l2_subdev_get_try_format(fh, fmt->pad);
1125+ crop = v4l2_subdev_get_try_crop(fh, 0);
1126+ } else {
1127+ if (s5k6aa->streaming) {
1128+ ret = -EBUSY;
1129+ } else {
1130+ mf = &preset->mbus_fmt;
1131+ crop = &s5k6aa->ccd_rect;
1132+ s5k6aa->apply_cfg = 1;
1133+ }
1134+ }
1135+
1136+ if (ret == 0) {
1137+ struct v4l2_subdev_frame_interval fiv = {
1138+ .interval = {0, 1}
1139+ };
1140+
1141+ *mf = fmt->format;
1142+ /*
1143+ * Make sure the crop window is valid, i.e. its size is
1144+ * greater than the output window, as the ISP supports
1145+ * only down-scaling.
1146+ */
1147+ crop->width = clamp_t(unsigned int, crop->width, mf->width,
1148+ S5K6AA_WIN_WIDTH_MAX);
1149+ crop->height = clamp_t(unsigned int, crop->height, mf->height,
1150+ S5K6AA_WIN_HEIGHT_MAX);
1151+ crop->left = clamp_t(unsigned int, crop->left, 0,
1152+ S5K6AA_WIN_WIDTH_MAX - crop->width);
1153+ crop->top = clamp_t(unsigned int, crop->top, 0,
1154+ S5K6AA_WIN_HEIGHT_MAX - crop->height);
1155+
1156+ /* Reset to minimum possible frame interval */
1157+ ret = __s5k6aa_set_frame_interval(s5k6aa, &fiv);
1158+ }
1159+ mutex_unlock(&s5k6aa->lock);
1160+
1161+ return ret;
1162+}
1163+
1164+static int s5k6aa_get_crop(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh,
1165+ struct v4l2_subdev_crop *crop)
1166+{
1167+ struct s5k6aa *s5k6aa = to_s5k6aa(sd);
1168+ struct v4l2_rect *rect;
1169+
1170+ memset(crop->reserved, 0, sizeof(crop->reserved));
1171+ mutex_lock(&s5k6aa->lock);
1172+
1173+ rect = __s5k6aa_get_crop_rect(s5k6aa, fh, crop->which);
1174+ if (rect)
1175+ crop->rect = *rect;
1176+
1177+ mutex_unlock(&s5k6aa->lock);
1178+
1179+ v4l2_dbg(1, debug, sd, "Current crop rectangle: (%d,%d)/%dx%d\n",
1180+ rect->left, rect->top, rect->width, rect->height);
1181+
1182+ return 0;
1183+}
1184+
1185+static int s5k6aa_set_crop(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh,
1186+ struct v4l2_subdev_crop *crop)
1187+{
1188+ struct s5k6aa *s5k6aa = to_s5k6aa(sd);
1189+ struct v4l2_mbus_framefmt *mf;
1190+ unsigned int max_x, max_y;
1191+ struct v4l2_rect *crop_r;
1192+
1193+ mutex_lock(&s5k6aa->lock);
1194+ crop_r = __s5k6aa_get_crop_rect(s5k6aa, fh, crop->which);
1195+
1196+ if (crop->which == V4L2_SUBDEV_FORMAT_ACTIVE) {
1197+ mf = &s5k6aa->preset->mbus_fmt;
1198+ s5k6aa->apply_crop = 1;
1199+ } else {
1200+ mf = v4l2_subdev_get_try_format(fh, 0);
1201+ }
1202+ v4l_bound_align_image(&crop->rect.width, mf->width,
1203+ S5K6AA_WIN_WIDTH_MAX, 1,
1204+ &crop->rect.height, mf->height,
1205+ S5K6AA_WIN_HEIGHT_MAX, 1, 0);
1206+
1207+ max_x = (S5K6AA_WIN_WIDTH_MAX - crop->rect.width) & ~1;
1208+ max_y = (S5K6AA_WIN_HEIGHT_MAX - crop->rect.height) & ~1;
1209+
1210+ crop->rect.left = clamp_t(unsigned int, crop->rect.left, 0, max_x);
1211+ crop->rect.top = clamp_t(unsigned int, crop->rect.top, 0, max_y);
1212+
1213+ *crop_r = crop->rect;
1214+
1215+ mutex_unlock(&s5k6aa->lock);
1216+
1217+ v4l2_dbg(1, debug, sd, "Set crop rectangle: (%d,%d)/%dx%d\n",
1218+ crop_r->left, crop_r->top, crop_r->width, crop_r->height);
1219+
1220+ return 0;
1221+}
1222+
1223+static const struct v4l2_subdev_pad_ops s5k6aa_pad_ops = {
1224+ .enum_mbus_code = s5k6aa_enum_mbus_code,
1225+ .enum_frame_size = s5k6aa_enum_frame_size,
1226+ .enum_frame_interval = s5k6aa_enum_frame_interval,
1227+ .get_fmt = s5k6aa_get_fmt,
1228+ .set_fmt = s5k6aa_set_fmt,
1229+ .get_crop = s5k6aa_get_crop,
1230+ .set_crop = s5k6aa_set_crop,
1231+};
1232+
1233+static const struct v4l2_subdev_video_ops s5k6aa_video_ops = {
1234+ .g_frame_interval = s5k6aa_g_frame_interval,
1235+ .s_frame_interval = s5k6aa_s_frame_interval,
1236+ .s_stream = s5k6aa_s_stream,
1237+};
1238+
1239+/*
1240+ * V4L2 subdev controls
1241+ */
1242+
1243+static int s5k6aa_s_ctrl(struct v4l2_ctrl *ctrl)
1244+{
1245+ struct v4l2_subdev *sd = ctrl_to_sd(ctrl);
1246+ struct i2c_client *client = v4l2_get_subdevdata(sd);
1247+ struct s5k6aa *s5k6aa = to_s5k6aa(sd);
1248+ int idx, err = 0;
1249+
1250+ v4l2_dbg(1, debug, sd, "ctrl: 0x%x, value: %d\n", ctrl->id, ctrl->val);
1251+
1252+ mutex_lock(&s5k6aa->lock);
1253+ /*
1254+ * If the device is not powered up by the host driver do
1255+ * not apply any controls to H/W at this time. Instead
1256+ * the controls will be restored right after power-up.
1257+ */
1258+ if (s5k6aa->power == 0)
1259+ goto unlock;
1260+ idx = s5k6aa->preset->index;
1261+
1262+ switch (ctrl->id) {
1263+ case V4L2_CID_AUTO_WHITE_BALANCE:
1264+ err = s5k6aa_set_awb(s5k6aa, ctrl->val);
1265+ break;
1266+
1267+ case V4L2_CID_BRIGHTNESS:
1268+ err = s5k6aa_write(client, REG_USER_BRIGHTNESS, ctrl->val);
1269+ break;
1270+
1271+ case V4L2_CID_COLORFX:
1272+ err = s5k6aa_set_colorfx(s5k6aa, ctrl->val);
1273+ break;
1274+
1275+ case V4L2_CID_CONTRAST:
1276+ err = s5k6aa_write(client, REG_USER_CONTRAST, ctrl->val);
1277+ break;
1278+
1279+ case V4L2_CID_EXPOSURE_AUTO:
1280+ err = s5k6aa_set_auto_exposure(s5k6aa, ctrl->val);
1281+ break;
1282+
1283+ case V4L2_CID_HFLIP:
1284+ err = s5k6aa_set_mirror(s5k6aa, ctrl->val);
1285+ if (err)
1286+ break;
1287+ err = s5k6aa_write(client, REG_G_PREV_CFG_CHG, 1);
1288+ break;
1289+
1290+ case V4L2_CID_POWER_LINE_FREQUENCY:
1291+ err = s5k6aa_set_anti_flicker(s5k6aa, ctrl->val);
1292+ break;
1293+
1294+ case V4L2_CID_SATURATION:
1295+ err = s5k6aa_write(client, REG_USER_SATURATION, ctrl->val);
1296+ break;
1297+
1298+ case V4L2_CID_SHARPNESS:
1299+ err = s5k6aa_write(client, REG_USER_SHARPBLUR, ctrl->val);
1300+ break;
1301+
1302+ case V4L2_CID_WHITE_BALANCE_TEMPERATURE:
1303+ err = s5k6aa_write(client, REG_P_COLORTEMP(idx), ctrl->val);
1304+ if (err)
1305+ break;
1306+ err = s5k6aa_write(client, REG_G_PREV_CFG_CHG, 1);
1307+ break;
1308+ }
1309+unlock:
1310+ mutex_unlock(&s5k6aa->lock);
1311+ return err;
1312+}
1313+
1314+static const struct v4l2_ctrl_ops s5k6aa_ctrl_ops = {
1315+ .s_ctrl = s5k6aa_s_ctrl,
1316+};
1317+
1318+static int s5k6aa_log_status(struct v4l2_subdev *sd)
1319+{
1320+ v4l2_ctrl_handler_log_status(sd->ctrl_handler, sd->name);
1321+ return 0;
1322+}
1323+
1324+#define V4L2_CID_RED_GAIN (V4L2_CTRL_CLASS_CAMERA | 0x1001)
1325+#define V4L2_CID_GREEN_GAIN (V4L2_CTRL_CLASS_CAMERA | 0x1002)
1326+#define V4L2_CID_BLUE_GAIN (V4L2_CTRL_CLASS_CAMERA | 0x1003)
1327+
1328+static const struct v4l2_ctrl_config s5k6aa_ctrls[] = {
1329+ {
1330+ .ops = &s5k6aa_ctrl_ops,
1331+ .id = V4L2_CID_RED_GAIN,
1332+ .type = V4L2_CTRL_TYPE_INTEGER,
1333+ .name = "Gain, Red",
1334+ .min = 0,
1335+ .max = 256,
1336+ .def = 127,
1337+ .step = 1,
1338+ }, {
1339+ .ops = &s5k6aa_ctrl_ops,
1340+ .id = V4L2_CID_GREEN_GAIN,
1341+ .type = V4L2_CTRL_TYPE_INTEGER,
1342+ .name = "Gain, Green",
1343+ .min = 0,
1344+ .max = 256,
1345+ .def = 127,
1346+ .step = 1,
1347+ }, {
1348+ .ops = &s5k6aa_ctrl_ops,
1349+ .id = V4L2_CID_BLUE_GAIN,
1350+ .type = V4L2_CTRL_TYPE_INTEGER,
1351+ .name = "Gain, Blue",
1352+ .min = 0,
1353+ .max = 256,
1354+ .def = 127,
1355+ .step = 1,
1356+ },
1357+};
1358+
1359+static int s5k6aa_initialize_ctrls(struct s5k6aa *s5k6aa)
1360+{
1361+ const struct v4l2_ctrl_ops *ops = &s5k6aa_ctrl_ops;
1362+ struct s5k6aa_ctrls *ctrls = &s5k6aa->ctrls;
1363+ struct v4l2_ctrl_handler *hdl = &ctrls->handler;
1364+
1365+ int ret = v4l2_ctrl_handler_init(hdl, 16);
1366+ if (ret)
1367+ return ret;
1368+ /* Auto white balance cluster */
1369+ ctrls->awb = v4l2_ctrl_new_std(hdl, ops, V4L2_CID_AUTO_WHITE_BALANCE,
1370+ 0, 1, 1, 1);
1371+ ctrls->gain_red = v4l2_ctrl_new_custom(hdl, &s5k6aa_ctrls[0], NULL);
1372+ ctrls->gain_green = v4l2_ctrl_new_custom(hdl, &s5k6aa_ctrls[1], NULL);
1373+ ctrls->gain_blue = v4l2_ctrl_new_custom(hdl, &s5k6aa_ctrls[2], NULL);
1374+ v4l2_ctrl_auto_cluster(4, &ctrls->awb, 0, false);
1375+
1376+ ctrls->hflip = v4l2_ctrl_new_std(hdl, ops, V4L2_CID_HFLIP, 0, 1, 1, 0);
1377+ ctrls->vflip = v4l2_ctrl_new_std(hdl, ops, V4L2_CID_VFLIP, 0, 1, 1, 0);
1378+ v4l2_ctrl_cluster(2, &ctrls->hflip);
1379+
1380+ ctrls->auto_exp = v4l2_ctrl_new_std_menu(hdl, ops,
1381+ V4L2_CID_EXPOSURE_AUTO,
1382+ V4L2_EXPOSURE_MANUAL, 0, V4L2_EXPOSURE_AUTO);
1383+ /* Exposure time: x 1 us */
1384+ ctrls->exposure = v4l2_ctrl_new_std(hdl, ops, V4L2_CID_EXPOSURE,
1385+ 0, 6000000U, 1, 100000U);
1386+ /* Total gain: 256 <=> 1x */
1387+ ctrls->gain = v4l2_ctrl_new_std(hdl, ops, V4L2_CID_GAIN,
1388+ 0, 256, 1, 256);
1389+ v4l2_ctrl_auto_cluster(3, &ctrls->auto_exp, 0, false);
1390+
1391+ v4l2_ctrl_new_std_menu(hdl, ops, V4L2_CID_POWER_LINE_FREQUENCY,
1392+ V4L2_CID_POWER_LINE_FREQUENCY_AUTO, 0,
1393+ V4L2_CID_POWER_LINE_FREQUENCY_AUTO);
1394+
1395+ v4l2_ctrl_new_std_menu(hdl, ops, V4L2_CID_COLORFX,
1396+ V4L2_COLORFX_SKY_BLUE, ~0x6f, V4L2_COLORFX_NONE);
1397+
1398+ v4l2_ctrl_new_std(hdl, ops, V4L2_CID_WHITE_BALANCE_TEMPERATURE,
1399+ 0, 256, 1, 0);
1400+
1401+ v4l2_ctrl_new_std(hdl, ops, V4L2_CID_SATURATION, -127, 127, 1, 0);
1402+ v4l2_ctrl_new_std(hdl, ops, V4L2_CID_BRIGHTNESS, -127, 127, 1, 0);
1403+ v4l2_ctrl_new_std(hdl, ops, V4L2_CID_CONTRAST, -127, 127, 1, 0);
1404+ v4l2_ctrl_new_std(hdl, ops, V4L2_CID_SHARPNESS, -127, 127, 1, 0);
1405+
1406+ if (hdl->error) {
1407+ ret = hdl->error;
1408+ v4l2_ctrl_handler_free(hdl);
1409+ return ret;
1410+ }
1411+
1412+ s5k6aa->sd.ctrl_handler = hdl;
1413+ return 0;
1414+}
1415+
1416+/*
1417+ * V4L2 subdev internal operations
1418+ */
1419+static int s5k6aa_open(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh)
1420+{
1421+ struct v4l2_mbus_framefmt *format = v4l2_subdev_get_try_format(fh, 0);
1422+ struct v4l2_rect *crop = v4l2_subdev_get_try_crop(fh, 0);
1423+
1424+ format->colorspace = s5k6aa_formats[0].colorspace;
1425+ format->code = s5k6aa_formats[0].code;
1426+ format->width = S5K6AA_OUT_WIDTH_DEF;
1427+ format->height = S5K6AA_OUT_HEIGHT_DEF;
1428+ format->field = V4L2_FIELD_NONE;
1429+
1430+ crop->width = S5K6AA_WIN_WIDTH_MAX;
1431+ crop->height = S5K6AA_WIN_HEIGHT_MAX;
1432+ crop->left = 0;
1433+ crop->top = 0;
1434+
1435+ return 0;
1436+}
1437+
1438+int s5k6aa_check_fw_revision(struct s5k6aa *s5k6aa)
1439+{
1440+ struct i2c_client *client = v4l2_get_subdevdata(&s5k6aa->sd);
1441+ u16 api_ver = 0, fw_rev = 0;
1442+
1443+ int ret = s5k6aa_set_ahb_address(client);
1444+
1445+ if (!ret)
1446+ ret = s5k6aa_read(client, REG_FW_APIVER, &api_ver);
1447+ if (!ret)
1448+ ret = s5k6aa_read(client, REG_FW_REVISION, &fw_rev);
1449+ if (ret) {
1450+ v4l2_err(&s5k6aa->sd, "FW revision check failed!\n");
1451+ return ret;
1452+ }
1453+
1454+ v4l2_info(&s5k6aa->sd, "FW API ver.: 0x%X, FW rev.: 0x%X\n",
1455+ api_ver, fw_rev);
1456+
1457+ return api_ver == S5K6AAFX_FW_APIVER ? 0 : -ENODEV;
1458+}
1459+
1460+static int s5k6aa_registered(struct v4l2_subdev *sd)
1461+{
1462+ struct s5k6aa *s5k6aa = to_s5k6aa(sd);
1463+ int ret;
1464+
1465+ mutex_lock(&s5k6aa->lock);
1466+ ret = __s5k6aa_power_on(s5k6aa);
1467+ if (!ret) {
1468+ msleep(100);
1469+ ret = s5k6aa_check_fw_revision(s5k6aa);
1470+ __s5k6aa_power_off(s5k6aa);
1471+ }
1472+ mutex_unlock(&s5k6aa->lock);
1473+
1474+ return ret;
1475+}
1476+
1477+static const struct v4l2_subdev_internal_ops s5k6aa_subdev_internal_ops = {
1478+ .registered = s5k6aa_registered,
1479+ .open = s5k6aa_open,
1480+};
1481+
1482+static const struct v4l2_subdev_core_ops s5k6aa_core_ops = {
1483+ .s_power = s5k6aa_set_power,
1484+ .log_status = s5k6aa_log_status,
1485+};
1486+
1487+static const struct v4l2_subdev_ops s5k6aa_subdev_ops = {
1488+ .core = &s5k6aa_core_ops,
1489+ .pad = &s5k6aa_pad_ops,
1490+ .video = &s5k6aa_video_ops,
1491+};
1492+
1493+/*
1494+ * GPIO setup
1495+ */
1496+static int s5k6aa_configure_gpio(int nr, int val, const char *name)
1497+{
1498+ unsigned long flags = val ? GPIOF_OUT_INIT_HIGH : GPIOF_OUT_INIT_LOW;
1499+ int ret;
1500+
1501+ if (!gpio_is_valid(nr))
1502+ return 0;
1503+ ret = gpio_request_one(nr, flags, name);
1504+ if (!ret)
1505+ gpio_export(nr, 0);
1506+ return ret;
1507+}
1508+
1509+static void s5k6aa_free_gpios(struct s5k6aa *s5k6aa)
1510+{
1511+ int i;
1512+
1513+ for (i = 0; i < ARRAY_SIZE(s5k6aa->gpio); i++) {
1514+ if (!gpio_is_valid(s5k6aa->gpio[i].gpio))
1515+ continue;
1516+ gpio_free(s5k6aa->gpio[i].gpio);
1517+ s5k6aa->gpio[i].gpio = -EINVAL;
1518+ }
1519+}
1520+
1521+static int s5k6aa_configure_gpios(struct s5k6aa *s5k6aa,
1522+ const struct s5k6aa_platform_data *pdata)
1523+{
1524+ const struct s5k6aa_gpio *gpio = &pdata->gpio_stby;
1525+ int ret;
1526+
1527+ s5k6aa->gpio[STBY].gpio = -EINVAL;
1528+ s5k6aa->gpio[RST].gpio = -EINVAL;
1529+
1530+ ret = s5k6aa_configure_gpio(gpio->gpio, gpio->level, "S5K6AA_STBY");
1531+ if (ret) {
1532+ s5k6aa_free_gpios(s5k6aa);
1533+ return ret;
1534+ }
1535+ s5k6aa->gpio[STBY] = *gpio;
1536+ if (gpio_is_valid(gpio->gpio))
1537+ gpio_set_value(gpio->gpio, 0);
1538+
1539+ gpio = &pdata->gpio_reset;
1540+ ret = s5k6aa_configure_gpio(gpio->gpio, gpio->level, "S5K6AA_RST");
1541+ if (ret) {
1542+ s5k6aa_free_gpios(s5k6aa);
1543+ return ret;
1544+ }
1545+ s5k6aa->gpio[RST] = *gpio;
1546+ if (gpio_is_valid(gpio->gpio))
1547+ gpio_set_value(gpio->gpio, 0);
1548+
1549+ return 0;
1550+}
1551+
1552+static int s5k6aa_probe(struct i2c_client *client,
1553+ const struct i2c_device_id *id)
1554+{
1555+ const struct s5k6aa_platform_data *pdata = client->dev.platform_data;
1556+ struct v4l2_subdev *sd;
1557+ struct s5k6aa *s5k6aa;
1558+ int i, ret;
1559+
1560+ if (pdata == NULL) {
1561+ dev_err(&client->dev, "Platform data not specified\n");
1562+ return -EINVAL;
1563+ }
1564+
1565+ if (pdata->mclk_frequency == 0) {
1566+ dev_err(&client->dev, "MCLK frequency not specified\n");
1567+ return -EINVAL;
1568+ }
1569+
1570+ s5k6aa = kzalloc(sizeof(*s5k6aa), GFP_KERNEL);
1571+ if (!s5k6aa)
1572+ return -ENOMEM;
1573+
1574+ mutex_init(&s5k6aa->lock);
1575+
1576+ s5k6aa->mclk_frequency = pdata->mclk_frequency;
1577+ s5k6aa->bus_type = pdata->bus_type;
1578+ s5k6aa->mipi_lanes = pdata->nlanes;
1579+ s5k6aa->s_power = pdata->set_power;
1580+ s5k6aa->inv_hflip = pdata->horiz_flip;
1581+ s5k6aa->inv_vflip = pdata->vert_flip;
1582+
1583+ sd = &s5k6aa->sd;
1584+ strlcpy(sd->name, DRIVER_NAME, sizeof(sd->name));
1585+ v4l2_i2c_subdev_init(sd, client, &s5k6aa_subdev_ops);
1586+
1587+ sd->internal_ops = &s5k6aa_subdev_internal_ops;
1588+ sd->flags |= V4L2_SUBDEV_FL_HAS_DEVNODE;
1589+
1590+ s5k6aa->pad.flags = MEDIA_PAD_FL_SOURCE;
1591+ sd->entity.type = MEDIA_ENT_T_V4L2_SUBDEV_SENSOR;
1592+ ret = media_entity_init(&sd->entity, 1, &s5k6aa->pad, 0);
1593+ if (ret)
1594+ goto out_err1;
1595+
1596+ ret = s5k6aa_configure_gpios(s5k6aa, pdata);
1597+ if (ret)
1598+ goto out_err2;
1599+
1600+ for (i = 0; i < S5K6AA_NUM_SUPPLIES; i++)
1601+ s5k6aa->supplies[i].supply = s5k6aa_supply_names[i];
1602+
1603+ ret = regulator_bulk_get(&client->dev, S5K6AA_NUM_SUPPLIES,
1604+ s5k6aa->supplies);
1605+ if (ret) {
1606+ dev_err(&client->dev, "Failed to get regulators\n");
1607+ goto out_err3;
1608+ }
1609+
1610+ ret = s5k6aa_initialize_ctrls(s5k6aa);
1611+ if (ret)
1612+ goto out_err4;
1613+
1614+ s5k6aa_presets_data_init(s5k6aa);
1615+
1616+ s5k6aa->ccd_rect.width = S5K6AA_WIN_WIDTH_MAX;
1617+ s5k6aa->ccd_rect.height = S5K6AA_WIN_HEIGHT_MAX;
1618+ s5k6aa->ccd_rect.left = 0;
1619+ s5k6aa->ccd_rect.top = 0;
1620+
1621+ return 0;
1622+
1623+out_err4:
1624+ regulator_bulk_free(S5K6AA_NUM_SUPPLIES, s5k6aa->supplies);
1625+out_err3:
1626+ s5k6aa_free_gpios(s5k6aa);
1627+out_err2:
1628+ media_entity_cleanup(&s5k6aa->sd.entity);
1629+out_err1:
1630+ kfree(s5k6aa);
1631+ return ret;
1632+}
1633+
1634+static int s5k6aa_remove(struct i2c_client *client)
1635+{
1636+ struct v4l2_subdev *sd = i2c_get_clientdata(client);
1637+ struct s5k6aa *s5k6aa = to_s5k6aa(sd);
1638+
1639+ v4l2_device_unregister_subdev(sd);
1640+ v4l2_ctrl_handler_free(sd->ctrl_handler);
1641+ media_entity_cleanup(&sd->entity);
1642+ regulator_bulk_free(S5K6AA_NUM_SUPPLIES, s5k6aa->supplies);
1643+ s5k6aa_free_gpios(s5k6aa);
1644+ kfree(s5k6aa);
1645+
1646+ return 0;
1647+}
1648+
1649+static const struct i2c_device_id s5k6aa_id[] = {
1650+ { DRIVER_NAME, 0 },
1651+ { },
1652+};
1653+MODULE_DEVICE_TABLE(i2c, s5k6aa_id);
1654+
1655+
1656+static struct i2c_driver s5k6aa_i2c_driver = {
1657+ .driver = {
1658+ .name = DRIVER_NAME
1659+ },
1660+ .probe = s5k6aa_probe,
1661+ .remove = s5k6aa_remove,
1662+ .id_table = s5k6aa_id,
1663+};
1664+
1665+static int __init s5k6aa_init(void)
1666+{
1667+ return i2c_add_driver(&s5k6aa_i2c_driver);
1668+}
1669+
1670+static void __exit s5k6aa_exit(void)
1671+{
1672+ i2c_del_driver(&s5k6aa_i2c_driver);
1673+}
1674+
1675+module_init(s5k6aa_init);
1676+module_exit(s5k6aa_exit);
1677+
1678+MODULE_DESCRIPTION("Samsung S5K6AA(FX) SXGA camera driver");
1679+MODULE_AUTHOR("Sylwester Nawrocki <s.nawrocki@samsung.com>");
1680+MODULE_LICENSE("GPL");
drivers/media/video/s5p-fimc/fimc-capture.c+3−3
@@ -246,9 +246,9 @@ static unsigned int get_plane_size(struct fimc_frame *fr, unsigned int plane) · 245 unmodified lines
246246 return fr->f_width * fr->f_height * fr->fmt->depth[plane] / 8;
247247 }
248248
249−static int queue_setup(struct vb2_queue *vq, unsigned int *num_buffers,
250− unsigned int *num_planes, unsigned int sizes[],
251− void *allocators[])
249+static int queue_setup(struct vb2_queue *vq, const struct v4l2_format *pfmt,
250+ unsigned int *num_buffers, unsigned int *num_planes,
251+ unsigned int sizes[], void *allocators[])
252252 {
253253 struct fimc_ctx *ctx = vq->drv_priv;
254254 struct fimc_fmt *fmt = ctx->d_frame.fmt;
drivers/media/video/s5p-fimc/fimc-core.c+3−3
@@ -670,9 +670,9 @@ static void fimc_job_abort(void *priv) · 669 unmodified lines
670670 fimc_m2m_shutdown(priv);
671671 }
672672
673−static int fimc_queue_setup(struct vb2_queue *vq, unsigned int *num_buffers,
674− unsigned int *num_planes, unsigned int sizes[],
675− void *allocators[])
673+static int fimc_queue_setup(struct vb2_queue *vq, const struct v4l2_format *fmt,
674+ unsigned int *num_buffers, unsigned int *num_planes,
675+ unsigned int sizes[], void *allocators[])
676676 {
677677 struct fimc_ctx *ctx = vb2_get_drv_priv(vq);
678678 struct fimc_frame *f;
drivers/media/video/s5p-mfc/s5p_mfc_ctrl.c+2−2
@@ -38,7 +38,7 @@ int s5p_mfc_alloc_and_load_firmware(struct s5p_mfc_dev *dev) · 37 unmodified lines
3838 * into kernel. */
3939 mfc_debug_enter();
4040 err = request_firmware((const struct firmware **)&fw_blob,
41− "s5pc110-mfc.fw", dev->v4l2_dev.dev);
41+ "s5p-mfc.fw", dev->v4l2_dev.dev);
4242 if (err != 0) {
4343 mfc_err("Firmware is not present in the /lib/firmware directory nor compiled in kernel\n");
4444 return -EINVAL;
@@ -116,7 +116,7 @@ int s5p_mfc_reload_firmware(struct s5p_mfc_dev *dev) · 71 unmodified lines
116116 * into kernel. */
117117 mfc_debug_enter();
118118 err = request_firmware((const struct firmware **)&fw_blob,
119− "s5pc110-mfc.fw", dev->v4l2_dev.dev);
119+ "s5p-mfc.fw", dev->v4l2_dev.dev);
120120 if (err != 0) {
121121 mfc_err("Firmware is not present in the /lib/firmware directory nor compiled in kernel\n");
122122 return -EINVAL;
drivers/media/video/s5p-mfc/s5p_mfc_dec.c+4−3
@@ -744,9 +744,10 @@ static const struct v4l2_ioctl_ops s5p_mfc_dec_ioctl_ops = { · 743 unmodified lines
744744 .vidioc_g_crop = vidioc_g_crop,
745745 };
746746
747−static int s5p_mfc_queue_setup(struct vb2_queue *vq, unsigned int *buf_count,
748− unsigned int *plane_count, unsigned int psize[],
749− void *allocators[])
747+static int s5p_mfc_queue_setup(struct vb2_queue *vq,
748+ const struct v4l2_format *fmt, unsigned int *buf_count,
749+ unsigned int *plane_count, unsigned int psize[],
750+ void *allocators[])
750751 {
751752 struct s5p_mfc_ctx *ctx = fh_to_ctx(vq->drv_priv);
752753
drivers/media/video/s5p-mfc/s5p_mfc_enc.c+3−2
@@ -1513,8 +1513,9 @@ static int check_vb_with_fmt(struct s5p_mfc_fmt *fmt, struct vb2_buffer *vb) · 1512 unmodified lines
15131513 }
15141514
15151515 static int s5p_mfc_queue_setup(struct vb2_queue *vq,
1516− unsigned int *buf_count, unsigned int *plane_count,
1517− unsigned int psize[], void *allocators[])
1516+ const struct v4l2_format *fmt,
1517+ unsigned int *buf_count, unsigned int *plane_count,
1518+ unsigned int psize[], void *allocators[])
15181519 {
15191520 struct s5p_mfc_ctx *ctx = fh_to_ctx(vq->drv_priv);
15201521
drivers/media/video/s5p-tv/mixer_video.c+2−2
@@ -727,8 +727,8 @@ static const struct v4l2_file_operations mxr_fops = { · 726 unmodified lines
727727 .unlocked_ioctl = video_ioctl2,
728728 };
729729
730−static int queue_setup(struct vb2_queue *vq, unsigned int *nbuffers,
731− unsigned int *nplanes, unsigned int sizes[],
730+static int queue_setup(struct vb2_queue *vq, const struct v4l2_format *pfmt,
731+ unsigned int *nbuffers, unsigned int *nplanes, unsigned int sizes[],
732732 void *alloc_ctxs[])
733733 {
734734 struct mxr_layer *layer = vb2_get_drv_priv(vq);
drivers/media/video/saa7134/saa7134.h+6−6
@@ -843,10 +843,10 @@ void saa7134_probe_i2c_ir(struct saa7134_dev *dev); · 842 unmodified lines
843843 int saa7134_ir_start(struct saa7134_dev *dev);
844844 void saa7134_ir_stop(struct saa7134_dev *dev);
845845 #else
846−#define saa7134_input_init1(dev) (0)
847−#define saa7134_input_fini(dev) (0)
848−#define saa7134_input_irq(dev) (0)
849−#define saa7134_probe_i2c_ir(dev) (0)
850−#define saa7134_ir_start(dev) (0)
851−#define saa7134_ir_stop(dev) (0)
846+#define saa7134_input_init1(dev) ((void)0)
847+#define saa7134_input_fini(dev) ((void)0)
848+#define saa7134_input_irq(dev) ((void)0)
849+#define saa7134_probe_i2c_ir(dev) ((void)0)
850+#define saa7134_ir_start(dev) ((void)0)
851+#define saa7134_ir_stop(dev) ((void)0)
852852 #endif
drivers/media/video/sh_mobile_ceu_camera.c+285−206
@@ -90,7 +90,6 @@ · 89 unmodified lines
9090 struct sh_mobile_ceu_buffer {
9191 struct vb2_buffer vb; /* v4l buffer must be first */
9292 struct list_head queue;
93− enum v4l2_mbus_pixelcode code;
9493 };
9594
9695 struct sh_mobile_ceu_dev {
@@ -100,7 +99,8 @@ struct sh_mobile_ceu_dev { · 3 unmodified lines
10099
101100 unsigned int irq;
102101 void __iomem *base;
103− unsigned long video_limit;
102+ size_t video_limit;
103+ size_t buf_total;
104104
105105 spinlock_t lock; /* Protects video buffer lists */
106106 struct list_head capture;
@@ -121,7 +121,7 @@ struct sh_mobile_ceu_dev { · 14 unmodified lines
121121 };
122122
123123 struct sh_mobile_ceu_cam {
124− /* CEU offsets within scaled by the CEU camera output */
124+ /* CEU offsets within the camera output, before the CEU scaler */
125125 unsigned int ceu_left;
126126 unsigned int ceu_top;
127127 /* Client output, as seen by the CEU */
@@ -144,30 +144,6 @@ static struct sh_mobile_ceu_buffer *to_ceu_vb(struct vb2_buffer *vb) · 16 unmodified lines
144144 return container_of(vb, struct sh_mobile_ceu_buffer, vb);
145145 }
146146
147−static unsigned long make_bus_param(struct sh_mobile_ceu_dev *pcdev)
148−{
149− unsigned long flags;
150−
151− flags = SOCAM_MASTER |
152− SOCAM_PCLK_SAMPLE_RISING |
153− SOCAM_HSYNC_ACTIVE_HIGH |
154− SOCAM_HSYNC_ACTIVE_LOW |
155− SOCAM_VSYNC_ACTIVE_HIGH |
156− SOCAM_VSYNC_ACTIVE_LOW |
157− SOCAM_DATA_ACTIVE_HIGH;
158−
159− if (pcdev->pdata->flags & SH_CEU_FLAG_USE_8BIT_BUS)
160− flags |= SOCAM_DATAWIDTH_8;
161−
162− if (pcdev->pdata->flags & SH_CEU_FLAG_USE_16BIT_BUS)
163− flags |= SOCAM_DATAWIDTH_16;
164−
165− if (flags & SOCAM_DATAWIDTH_MASK)
166− return flags;
167−
168− return 0;
169−}
170−
171147 static void ceu_write(struct sh_mobile_ceu_dev *priv,
172148 unsigned long reg_offs, u32 data)
173149 {
@@ -216,33 +192,61 @@ static int sh_mobile_ceu_soft_reset(struct sh_mobile_ceu_dev *pcdev) · 42 unmodified lines
216192 /*
217193 * Videobuf operations
218194 */
195+
196+/*
197+ * .queue_setup() is called to check, whether the driver can accept the
198+ * requested number of buffers and to fill in plane sizes
199+ * for the current frame format if required
200+ */
219201 static int sh_mobile_ceu_videobuf_setup(struct vb2_queue *vq,
202+ const struct v4l2_format *fmt,
220203 unsigned int *count, unsigned int *num_planes,
221204 unsigned int sizes[], void *alloc_ctxs[])
222205 {
223206 struct soc_camera_device *icd = container_of(vq, struct soc_camera_device, vb2_vidq);
224207 struct soc_camera_host *ici = to_soc_camera_host(icd->parent);
225208 struct sh_mobile_ceu_dev *pcdev = ici->priv;
226− int bytes_per_line = soc_mbus_bytes_per_line(icd->user_width,
227− icd->current_fmt->host_fmt);
209+ int bytes_per_line;
210+ unsigned int height;
228211
212+ if (fmt) {
213+ const struct soc_camera_format_xlate *xlate = soc_camera_xlate_by_fourcc(icd,
214+ fmt->fmt.pix.pixelformat);
215+ if (!xlate)
216+ return -EINVAL;
217+ bytes_per_line = soc_mbus_bytes_per_line(fmt->fmt.pix.width,
218+ xlate->host_fmt);
219+ height = fmt->fmt.pix.height;
220+ } else {
221+ /* Called from VIDIOC_REQBUFS or in compatibility mode */
222+ bytes_per_line = soc_mbus_bytes_per_line(icd->user_width,
223+ icd->current_fmt->host_fmt);
224+ height = icd->user_height;
225+ }
229226 if (bytes_per_line < 0)
230227 return bytes_per_line;
231228
232− *num_planes = 1;
229+ sizes[0] = bytes_per_line * height;
233230
234− pcdev->sequence = 0;
235− sizes[0] = bytes_per_line * icd->user_height;
236231 alloc_ctxs[0] = pcdev->alloc_ctx;
237232
233+ if (!vq->num_buffers)
234+ pcdev->sequence = 0;
235+
238236 if (!*count)
239237 *count = 2;
240238
241− if (pcdev->video_limit) {
242− if (PAGE_ALIGN(sizes[0]) * *count > pcdev->video_limit)
243− *count = pcdev->video_limit / PAGE_ALIGN(sizes[0]);
239+ /* If *num_planes != 0, we have already verified *count. */
240+ if (pcdev->video_limit && !*num_planes) {
241+ size_t size = PAGE_ALIGN(sizes[0]) * *count;
242+
243+ if (size + pcdev->buf_total > pcdev->video_limit)
244+ *count = (pcdev->video_limit - pcdev->buf_total) /
245+ PAGE_ALIGN(sizes[0]);
244246 }
245247
248+ *num_planes = 1;
249+
246250 dev_dbg(icd->parent, "count=%d, size=%u\n", *count, sizes[0]);
247251
248252 return 0;
@@ -267,6 +271,7 @@ static int sh_mobile_ceu_capture(struct sh_mobile_ceu_dev *pcdev) · 18 unmodified lines
267271 unsigned long top1, top2;
268272 unsigned long bottom1, bottom2;
269273 u32 status;
274+ bool planar;
270275 int ret = 0;
271276
272277 /*
@@ -314,17 +319,29 @@ static int sh_mobile_ceu_capture(struct sh_mobile_ceu_dev *pcdev) · 41 unmodified lines
314319
315320 phys_addr_top = vb2_dma_contig_plane_dma_addr(pcdev->active, 0);
316321
317− ceu_write(pcdev, top1, phys_addr_top);
318− if (V4L2_FIELD_NONE != pcdev->field) {
319− phys_addr_bottom = phys_addr_top + icd->user_width;
320− ceu_write(pcdev, bottom1, phys_addr_bottom);
321− }
322−
323322 switch (icd->current_fmt->host_fmt->fourcc) {
324323 case V4L2_PIX_FMT_NV12:
325324 case V4L2_PIX_FMT_NV21:
326325 case V4L2_PIX_FMT_NV16:
327326 case V4L2_PIX_FMT_NV61:
327+ planar = true;
328+ break;
329+ default:
330+ planar = false;
331+ }
332+
333+ ceu_write(pcdev, top1, phys_addr_top);
334+ if (V4L2_FIELD_NONE != pcdev->field) {
335+ if (planar)
336+ phys_addr_bottom = phys_addr_top + icd->user_width;
337+ else
338+ phys_addr_bottom = phys_addr_top +
339+ soc_mbus_bytes_per_line(icd->user_width,
340+ icd->current_fmt->host_fmt);
341+ ceu_write(pcdev, bottom1, phys_addr_bottom);
342+ }
343+
344+ if (planar) {
328345 phys_addr_top += icd->user_width *
329346 icd->user_height;
330347 ceu_write(pcdev, top2, phys_addr_top);
@@ -340,24 +357,41 @@ static int sh_mobile_ceu_capture(struct sh_mobile_ceu_dev *pcdev) · 9 unmodified lines
340357 }
341358
342359 static int sh_mobile_ceu_videobuf_prepare(struct vb2_buffer *vb)
360+{
361+ struct sh_mobile_ceu_buffer *buf = to_ceu_vb(vb);
362+
363+ /* Added list head initialization on alloc */
364+ WARN(!list_empty(&buf->queue), "Buffer %p on queue!\n", vb);
365+
366+ return 0;
367+}
368+
369+static void sh_mobile_ceu_videobuf_queue(struct vb2_buffer *vb)
343370 {
344371 struct soc_camera_device *icd = container_of(vb->vb2_queue, struct soc_camera_device, vb2_vidq);
345− struct sh_mobile_ceu_buffer *buf;
372+ struct soc_camera_host *ici = to_soc_camera_host(icd->parent);
373+ struct sh_mobile_ceu_dev *pcdev = ici->priv;
374+ struct sh_mobile_ceu_buffer *buf = to_ceu_vb(vb);
375+ unsigned long size;
346376 int bytes_per_line = soc_mbus_bytes_per_line(icd->user_width,
347377 icd->current_fmt->host_fmt);
348− unsigned long size;
349378
350379 if (bytes_per_line < 0)
351− return bytes_per_line;
380+ goto error;
352381
353− buf = to_ceu_vb(vb);
382+ size = icd->user_height * bytes_per_line;
383+
384+ if (vb2_plane_size(vb, 0) < size) {
385+ dev_err(icd->parent, "Buffer #%d too small (%lu < %lu)\n",
386+ vb->v4l2_buf.index, vb2_plane_size(vb, 0), size);
387+ goto error;
388+ }
389+
390+ vb2_set_plane_payload(vb, 0, size);
354391
355392 dev_dbg(icd->parent, "%s (vb=0x%p) 0x%p %lu\n", __func__,
356393 vb, vb2_plane_vaddr(vb, 0), vb2_get_plane_payload(vb, 0));
357394
358− /* Added list head initialization on alloc */
359− WARN(!list_empty(&buf->queue), "Buffer %p on queue!\n", vb);
360−
361395 #ifdef DEBUG
362396 /*
363397 * This can be useful if you want to see if we actually fill
@@ -367,31 +401,6 @@ static int sh_mobile_ceu_videobuf_prepare(struct vb2_buffer *vb) · 3 unmodified lines
367401 memset(vb2_plane_vaddr(vb, 0), 0xaa, vb2_get_plane_payload(vb, 0));
368402 #endif
369403
370− BUG_ON(NULL == icd->current_fmt);
371−
372− size = icd->user_height * bytes_per_line;
373−
374− if (vb2_plane_size(vb, 0) < size) {
375− dev_err(icd->parent, "Buffer too small (%lu < %lu)\n",
376− vb2_plane_size(vb, 0), size);
377− return -ENOBUFS;
378− }
379−
380− vb2_set_plane_payload(vb, 0, size);
381−
382− return 0;
383−}
384−
385−static void sh_mobile_ceu_videobuf_queue(struct vb2_buffer *vb)
386−{
387− struct soc_camera_device *icd = container_of(vb->vb2_queue, struct soc_camera_device, vb2_vidq);
388− struct soc_camera_host *ici = to_soc_camera_host(icd->parent);
389− struct sh_mobile_ceu_dev *pcdev = ici->priv;
390− struct sh_mobile_ceu_buffer *buf = to_ceu_vb(vb);
391−
392− dev_dbg(icd->parent, "%s (vb=0x%p) 0x%p %lu\n", __func__,
393− vb, vb2_plane_vaddr(vb, 0), vb2_get_plane_payload(vb, 0));
394−
395404 spin_lock_irq(&pcdev->lock);
396405 list_add_tail(&buf->queue, &pcdev->capture);
397406
@@ -405,6 +414,11 @@ static void sh_mobile_ceu_videobuf_queue(struct vb2_buffer *vb) · 7 unmodified lines
405414 sh_mobile_ceu_capture(pcdev);
406415 }
407416 spin_unlock_irq(&pcdev->lock);
417+
418+ return;
419+
420+error:
421+ vb2_buffer_done(vb, VB2_BUF_STATE_ERROR);
408422 }
409423
410424 static void sh_mobile_ceu_videobuf_release(struct vb2_buffer *vb)
@@ -429,11 +443,23 @@ static void sh_mobile_ceu_videobuf_release(struct vb2_buffer *vb) · 18 unmodified lines
429443 if (buf->queue.next)
430444 list_del_init(&buf->queue);
431445
446+ pcdev->buf_total -= PAGE_ALIGN(vb2_plane_size(vb, 0));
447+ dev_dbg(icd->parent, "%s() %zu bytes buffers\n", __func__,
448+ pcdev->buf_total);
449+
432450 spin_unlock_irq(&pcdev->lock);
433451 }
434452
435453 static int sh_mobile_ceu_videobuf_init(struct vb2_buffer *vb)
436454 {
455+ struct soc_camera_device *icd = container_of(vb->vb2_queue, struct soc_camera_device, vb2_vidq);
456+ struct soc_camera_host *ici = to_soc_camera_host(icd->parent);
457+ struct sh_mobile_ceu_dev *pcdev = ici->priv;
458+
459+ pcdev->buf_total += PAGE_ALIGN(vb2_plane_size(vb, 0));
460+ dev_dbg(icd->parent, "%s() %zu bytes buffers\n", __func__,
461+ pcdev->buf_total);
462+
437463 /* This is for locking debugging only */
438464 INIT_LIST_HEAD(&to_ceu_vb(vb)->queue);
439465 return 0;
@@ -535,19 +561,29 @@ static int sh_mobile_ceu_add_device(struct soc_camera_device *icd) · 95 unmodified lines
535561
536562 pm_runtime_get_sync(ici->v4l2_dev.dev);
537563
564+ pcdev->buf_total = 0;
565+
538566 ret = sh_mobile_ceu_soft_reset(pcdev);
539567
540568 csi2_sd = find_csi2(pcdev);
569+ if (csi2_sd)
570+ csi2_sd->grp_id = (long)icd;
541571
542572 ret = v4l2_subdev_call(csi2_sd, core, s_power, 1);
543− if (ret != -ENODEV && ret != -ENOIOCTLCMD && ret < 0) {
573+ if (ret < 0 && ret != -ENOIOCTLCMD && ret != -ENODEV) {
544574 pm_runtime_put_sync(ici->v4l2_dev.dev);
545− } else {
546− pcdev->icd = icd;
547− ret = 0;
575+ return ret;
548576 }
549577
550− return ret;
578+ /*
579+ * -ENODEV is special: either csi2_sd == NULL or the CSI-2 driver
580+ * has not found this soc-camera device among its clients
581+ */
582+ if (ret == -ENODEV && csi2_sd)
583+ csi2_sd->grp_id = 0;
584+ pcdev->icd = icd;
585+
586+ return 0;
551587 }
552588
553589 /* Called with .video_lock held */
@@ -560,6 +596,8 @@ static void sh_mobile_ceu_remove_device(struct soc_camera_device *icd) · 6 unmodified lines
560596 BUG_ON(icd != pcdev->icd);
561597
562598 v4l2_subdev_call(csi2_sd, core, s_power, 0);
599+ if (csi2_sd)
600+ csi2_sd->grp_id = 0;
563601 /* disable capture, disable interrupts */
564602 ceu_write(pcdev, CEIER, 0);
565603 sh_mobile_ceu_soft_reset(pcdev);
@@ -628,22 +666,22 @@ static void sh_mobile_ceu_set_rect(struct soc_camera_device *icd) · 62 unmodified lines
628666 left_offset = cam->ceu_left;
629667 top_offset = cam->ceu_top;
630668
631− /* CEU cropping (CFSZR) is applied _after_ the scaling filter (CFLCR) */
669+ WARN_ON(icd->user_width & 3 || icd->user_height & 3);
670+
671+ width = icd->user_width;
672+
632673 if (pcdev->image_mode) {
633674 in_width = cam->width;
634675 if (!pcdev->is_16bit) {
635676 in_width *= 2;
636677 left_offset *= 2;
637678 }
638− width = icd->user_width;
639− cdwdr_width = icd->user_width;
679+ cdwdr_width = width;
640680 } else {
641− int bytes_per_line = soc_mbus_bytes_per_line(icd->user_width,
681+ int bytes_per_line = soc_mbus_bytes_per_line(width,
642682 icd->current_fmt->host_fmt);
643683 unsigned int w_factor;
644684
645− width = icd->user_width;
646−
647685 switch (icd->current_fmt->host_fmt->packing) {
648686 case SOC_MBUS_PACKING_2X8_PADHI:
649687 w_factor = 2;
@@ -653,10 +691,10 @@ static void sh_mobile_ceu_set_rect(struct soc_camera_device *icd) · 3 unmodified lines
653691 }
654692
655693 in_width = cam->width * w_factor;
656− left_offset = left_offset * w_factor;
694+ left_offset *= w_factor;
657695
658696 if (bytes_per_line < 0)
659− cdwdr_width = icd->user_width;
697+ cdwdr_width = width;
660698 else
661699 cdwdr_width = bytes_per_line;
662700 }
@@ -664,7 +702,7 @@ static void sh_mobile_ceu_set_rect(struct soc_camera_device *icd) · 1 unmodified line
664702 height = icd->user_height;
665703 in_height = cam->height;
666704 if (V4L2_FIELD_NONE != pcdev->field) {
667− height /= 2;
705+ height = (height / 2) & ~3;
668706 in_height /= 2;
669707 top_offset /= 2;
670708 cdwdr_width *= 2;
@@ -686,6 +724,7 @@ static void sh_mobile_ceu_set_rect(struct soc_camera_device *icd) · 15 unmodified lines
686724
687725 ceu_write(pcdev, CAMOR, camor);
688726 ceu_write(pcdev, CAPWR, (in_height << 16) | in_width);
727+ /* CFSZR clipping is applied _after_ the scaling filter (CFLCR) */
689728 ceu_write(pcdev, CFSZR, (height << 16) | width);
690729 ceu_write(pcdev, CDWDR, cdwdr_width);
691730 }
@@ -723,66 +762,93 @@ static void capture_restore(struct sh_mobile_ceu_dev *pcdev, u32 capsr) · 31 unmodified lines
723762 ceu_write(pcdev, CAPSR, capsr);
724763 }
725764
765+/* Find the bus subdevice driver, e.g., CSI2 */
766+static struct v4l2_subdev *find_bus_subdev(struct sh_mobile_ceu_dev *pcdev,
767+ struct soc_camera_device *icd)
768+{
769+ if (pcdev->csi2_pdev) {
770+ struct v4l2_subdev *csi2_sd = find_csi2(pcdev);
771+ if (csi2_sd && csi2_sd->grp_id == (u32)icd)
772+ return csi2_sd;
773+ }
774+
775+ return soc_camera_to_subdev(icd);
776+}
777+
778+#define CEU_BUS_FLAGS (V4L2_MBUS_MASTER | \
779+ V4L2_MBUS_PCLK_SAMPLE_RISING | \
780+ V4L2_MBUS_HSYNC_ACTIVE_HIGH | \
781+ V4L2_MBUS_HSYNC_ACTIVE_LOW | \
782+ V4L2_MBUS_VSYNC_ACTIVE_HIGH | \
783+ V4L2_MBUS_VSYNC_ACTIVE_LOW | \
784+ V4L2_MBUS_DATA_ACTIVE_HIGH)
785+
726786 /* Capture is not running, no interrupts, no locking needed */
727787 static int sh_mobile_ceu_set_bus_param(struct soc_camera_device *icd,
728788 __u32 pixfmt)
729789 {
730790 struct soc_camera_host *ici = to_soc_camera_host(icd->parent);
731791 struct sh_mobile_ceu_dev *pcdev = ici->priv;
732− int ret;
733− unsigned long camera_flags, common_flags, value;
734− int yuv_lineskip;
792+ struct v4l2_subdev *sd = find_bus_subdev(pcdev, icd);
735793 struct sh_mobile_ceu_cam *cam = icd->host_priv;
794+ struct v4l2_mbus_config cfg = {.type = V4L2_MBUS_PARALLEL,};
795+ unsigned long value, common_flags = CEU_BUS_FLAGS;
736796 u32 capsr = capture_save_reset(pcdev);
797+ unsigned int yuv_lineskip;
798+ int ret;
737799
738− camera_flags = icd->ops->query_bus_param(icd);
739− common_flags = soc_camera_bus_param_compatible(camera_flags,
740− make_bus_param(pcdev));
741− if (!common_flags)
742− return -EINVAL;
800+ /*
801+ * If the client doesn't implement g_mbus_config, we just use our
802+ * platform data
803+ */
804+ ret = v4l2_subdev_call(sd, video, g_mbus_config, &cfg);
805+ if (!ret) {
806+ common_flags = soc_mbus_config_compatible(&cfg,
807+ common_flags);
808+ if (!common_flags)
809+ return -EINVAL;
810+ } else if (ret != -ENOIOCTLCMD) {
811+ return ret;
812+ }
743813
744814 /* Make choises, based on platform preferences */
745− if ((common_flags & SOCAM_HSYNC_ACTIVE_HIGH) &&
746− (common_flags & SOCAM_HSYNC_ACTIVE_LOW)) {
815+ if ((common_flags & V4L2_MBUS_HSYNC_ACTIVE_HIGH) &&
816+ (common_flags & V4L2_MBUS_HSYNC_ACTIVE_LOW)) {
747817 if (pcdev->pdata->flags & SH_CEU_FLAG_HSYNC_LOW)
748− common_flags &= ~SOCAM_HSYNC_ACTIVE_HIGH;
818+ common_flags &= ~V4L2_MBUS_HSYNC_ACTIVE_HIGH;
749819 else
750− common_flags &= ~SOCAM_HSYNC_ACTIVE_LOW;
820+ common_flags &= ~V4L2_MBUS_HSYNC_ACTIVE_LOW;
751821 }
752822
753− if ((common_flags & SOCAM_VSYNC_ACTIVE_HIGH) &&
754− (common_flags & SOCAM_VSYNC_ACTIVE_LOW)) {
823+ if ((common_flags & V4L2_MBUS_VSYNC_ACTIVE_HIGH) &&
824+ (common_flags & V4L2_MBUS_VSYNC_ACTIVE_LOW)) {
755825 if (pcdev->pdata->flags & SH_CEU_FLAG_VSYNC_LOW)
756− common_flags &= ~SOCAM_VSYNC_ACTIVE_HIGH;
826+ common_flags &= ~V4L2_MBUS_VSYNC_ACTIVE_HIGH;
757827 else
758− common_flags &= ~SOCAM_VSYNC_ACTIVE_LOW;
828+ common_flags &= ~V4L2_MBUS_VSYNC_ACTIVE_LOW;
759829 }
760830
761− ret = icd->ops->set_bus_param(icd, common_flags);
762− if (ret < 0)
831+ cfg.flags = common_flags;
832+ ret = v4l2_subdev_call(sd, video, s_mbus_config, &cfg);
833+ if (ret < 0 && ret != -ENOIOCTLCMD)
763834 return ret;
764835
765− switch (common_flags & SOCAM_DATAWIDTH_MASK) {
766− case SOCAM_DATAWIDTH_8:
767− pcdev->is_16bit = 0;
768− break;
769− case SOCAM_DATAWIDTH_16:
836+ if (icd->current_fmt->host_fmt->bits_per_sample > 8)
770837 pcdev->is_16bit = 1;
771− break;
772− default:
773− return -EINVAL;
774− }
838+ else
839+ pcdev->is_16bit = 0;
775840
776841 ceu_write(pcdev, CRCNTR, 0);
777842 ceu_write(pcdev, CRCMPR, 0);
778843
779844 value = 0x00000010; /* data fetch by default */
780− yuv_lineskip = 0;
845+ yuv_lineskip = 0x10;
781846
782847 switch (icd->current_fmt->host_fmt->fourcc) {
783848 case V4L2_PIX_FMT_NV12:
784849 case V4L2_PIX_FMT_NV21:
785− yuv_lineskip = 1; /* skip for NV12/21, no skip for NV16/61 */
850+ /* convert 4:2:2 -> 4:2:0 */
851+ yuv_lineskip = 0; /* skip for NV12/21, no skip for NV16/61 */
786852 /* fall-through */
787853 case V4L2_PIX_FMT_NV16:
788854 case V4L2_PIX_FMT_NV61:
@@ -808,8 +874,8 @@ static int sh_mobile_ceu_set_bus_param(struct soc_camera_device *icd, · 19 unmodified lines
808874 icd->current_fmt->host_fmt->fourcc == V4L2_PIX_FMT_NV61)
809875 value ^= 0x00000100; /* swap U, V to change from NV1x->NVx1 */
810876
811− value |= common_flags & SOCAM_VSYNC_ACTIVE_LOW ? 1 << 1 : 0;
812− value |= common_flags & SOCAM_HSYNC_ACTIVE_LOW ? 1 << 0 : 0;
877+ value |= common_flags & V4L2_MBUS_VSYNC_ACTIVE_LOW ? 1 << 1 : 0;
878+ value |= common_flags & V4L2_MBUS_HSYNC_ACTIVE_LOW ? 1 << 0 : 0;
813879 value |= pcdev->is_16bit ? 1 << 12 : 0;
814880
815881 /* CSI2 mode */
@@ -852,9 +918,7 @@ static int sh_mobile_ceu_set_bus_param(struct soc_camera_device *icd, · 36 unmodified lines
852918 * using 7 we swap the data bytes to match the incoming order:
853919 * D0, D1, D2, D3, D4, D5, D6, D7
854920 */
855− value = 0x00000017;
856− if (yuv_lineskip)
857− value &= ~0x00000010; /* convert 4:2:2 -> 4:2:0 */
921+ value = 0x00000007 | yuv_lineskip;
858922
859923 ceu_write(pcdev, CDOCR, value);
860924 ceu_write(pcdev, CFWCR, 0); /* keep "datafetch firewall" disabled */
@@ -875,13 +939,19 @@ static int sh_mobile_ceu_try_bus_param(struct soc_camera_device *icd, · 14 unmodified lines
875939 {
876940 struct soc_camera_host *ici = to_soc_camera_host(icd->parent);
877941 struct sh_mobile_ceu_dev *pcdev = ici->priv;
878− unsigned long camera_flags, common_flags;
942+ struct v4l2_subdev *sd = find_bus_subdev(pcdev, icd);
943+ unsigned long common_flags = CEU_BUS_FLAGS;
944+ struct v4l2_mbus_config cfg = {.type = V4L2_MBUS_PARALLEL,};
945+ int ret;
879946
880− camera_flags = icd->ops->query_bus_param(icd);
881− common_flags = soc_camera_bus_param_compatible(camera_flags,
882− make_bus_param(pcdev));
883− if (!common_flags || buswidth > 16 ||
884− (buswidth > 8 && !(common_flags & SOCAM_DATAWIDTH_16)))
947+ ret = v4l2_subdev_call(sd, video, g_mbus_config, &cfg);
948+ if (!ret)
949+ common_flags = soc_mbus_config_compatible(&cfg,
950+ common_flags);
951+ else if (ret != -ENOIOCTLCMD)
952+ return ret;
953+
954+ if (!common_flags || buswidth > 16)
885955 return -EINVAL;
886956
887957 return 0;
@@ -891,26 +961,26 @@ static const struct soc_mbus_pixelfmt sh_mobile_ceu_formats[] = { · 3 unmodified lines
891961 {
892962 .fourcc = V4L2_PIX_FMT_NV12,
893963 .name = "NV12",
894− .bits_per_sample = 12,
895− .packing = SOC_MBUS_PACKING_NONE,
964+ .bits_per_sample = 8,
965+ .packing = SOC_MBUS_PACKING_1_5X8,
896966 .order = SOC_MBUS_ORDER_LE,
897967 }, {
898968 .fourcc = V4L2_PIX_FMT_NV21,
899969 .name = "NV21",
900− .bits_per_sample = 12,
901− .packing = SOC_MBUS_PACKING_NONE,
970+ .bits_per_sample = 8,
971+ .packing = SOC_MBUS_PACKING_1_5X8,
902972 .order = SOC_MBUS_ORDER_LE,
903973 }, {
904974 .fourcc = V4L2_PIX_FMT_NV16,
905975 .name = "NV16",
906− .bits_per_sample = 16,
907− .packing = SOC_MBUS_PACKING_NONE,
976+ .bits_per_sample = 8,
977+ .packing = SOC_MBUS_PACKING_2X8_PADHI,
908978 .order = SOC_MBUS_ORDER_LE,
909979 }, {
910980 .fourcc = V4L2_PIX_FMT_NV61,
911981 .name = "NV61",
912− .bits_per_sample = 16,
913− .packing = SOC_MBUS_PACKING_NONE,
982+ .bits_per_sample = 8,
983+ .packing = SOC_MBUS_PACKING_2X8_PADHI,
914984 .order = SOC_MBUS_ORDER_LE,
915985 },
916986 };
@@ -919,6 +989,8 @@ static const struct soc_mbus_pixelfmt sh_mobile_ceu_formats[] = { · 2 unmodified lines
919989 static bool sh_mobile_ceu_packing_supported(const struct soc_mbus_pixelfmt *fmt)
920990 {
921991 return fmt->packing == SOC_MBUS_PACKING_NONE ||
992+ (fmt->bits_per_sample == 8 &&
993+ fmt->packing == SOC_MBUS_PACKING_1_5X8) ||
922994 (fmt->bits_per_sample == 8 &&
923995 fmt->packing == SOC_MBUS_PACKING_2X8_PADHI) ||
924996 (fmt->bits_per_sample > 8 &&
@@ -927,6 +999,38 @@ static bool sh_mobile_ceu_packing_supported(const struct soc_mbus_pixelfmt *fmt) · 2 unmodified lines
927999
9281000 static int client_g_rect(struct v4l2_subdev *sd, struct v4l2_rect *rect);
9291001
1002+static struct soc_camera_device *ctrl_to_icd(struct v4l2_ctrl *ctrl)
1003+{
1004+ return container_of(ctrl->handler, struct soc_camera_device,
1005+ ctrl_handler);
1006+}
1007+
1008+static int sh_mobile_ceu_s_ctrl(struct v4l2_ctrl *ctrl)
1009+{
1010+ struct soc_camera_device *icd = ctrl_to_icd(ctrl);
1011+ struct soc_camera_host *ici = to_soc_camera_host(icd->parent);
1012+ struct sh_mobile_ceu_dev *pcdev = ici->priv;
1013+
1014+ switch (ctrl->id) {
1015+ case V4L2_CID_SHARPNESS:
1016+ switch (icd->current_fmt->host_fmt->fourcc) {
1017+ case V4L2_PIX_FMT_NV12:
1018+ case V4L2_PIX_FMT_NV21:
1019+ case V4L2_PIX_FMT_NV16:
1020+ case V4L2_PIX_FMT_NV61:
1021+ ceu_write(pcdev, CLFCR, !ctrl->val);
1022+ return 0;
1023+ }
1024+ break;
1025+ }
1026+
1027+ return -EINVAL;
1028+}
1029+
1030+static const struct v4l2_ctrl_ops sh_mobile_ceu_ctrl_ops = {
1031+ .s_ctrl = sh_mobile_ceu_s_ctrl,
1032+};
1033+
9301034 static int sh_mobile_ceu_get_formats(struct soc_camera_device *icd, unsigned int idx,
9311035 struct soc_camera_format_xlate *xlate)
9321036 {
@@ -952,6 +1056,7 @@ static int sh_mobile_ceu_get_formats(struct soc_camera_device *icd, unsigned int · 19 unmodified lines
9521056 }
9531057
9541058 if (!pcdev->pdata->csi2) {
1059+ /* Are there any restrictions in the CSI-2 case? */
9551060 ret = sh_mobile_ceu_try_bus_param(icd, fmt->bits_per_sample);
9561061 if (ret < 0)
9571062 return 0;
@@ -962,6 +1067,12 @@ static int sh_mobile_ceu_get_formats(struct soc_camera_device *icd, unsigned int · 4 unmodified lines
9621067 struct v4l2_rect rect;
9631068 int shift = 0;
9641069
1070+ /* Add our control */
1071+ v4l2_ctrl_new_std(&icd->ctrl_handler, &sh_mobile_ceu_ctrl_ops,
1072+ V4L2_CID_SHARPNESS, 0, 1, 1, 0);
1073+ if (icd->ctrl_handler.error)
1074+ return icd->ctrl_handler.error;
1075+
9651076 /* FIXME: subwindow is lost between close / open */
9661077
9671078 /* Cache current client geometry */
@@ -1004,9 +1115,6 @@ static int sh_mobile_ceu_get_formats(struct soc_camera_device *icd, unsigned int · 36 unmodified lines
10041115 cam->width = mf.width;
10051116 cam->height = mf.height;
10061117
1007− cam->width = mf.width;
1008− cam->height = mf.height;
1009−
10101118 icd->host_priv = cam;
10111119 } else {
10121120 cam = icd->host_priv;
@@ -1278,6 +1386,7 @@ static int client_s_fmt(struct soc_camera_device *icd, · 265 unmodified lines
12781386 unsigned int width = mf->width, height = mf->height, tmp_w, tmp_h;
12791387 unsigned int max_width, max_height;
12801388 struct v4l2_cropcap cap;
1389+ bool ceu_1to1;
12811390 int ret;
12821391
12831392 ret = v4l2_device_call_until_err(sd->v4l2_dev, (long)icd, video,
@@ -1287,7 +1396,14 @@ static int client_s_fmt(struct soc_camera_device *icd, · 3 unmodified lines
12871396
12881397 dev_geo(dev, "camera scaled to %ux%u\n", mf->width, mf->height);
12891398
1290− if ((width == mf->width && height == mf->height) || !ceu_can_scale)
1399+ if (width == mf->width && height == mf->height) {
1400+ /* Perfect! The client has done it all. */
1401+ ceu_1to1 = true;
1402+ goto update_cache;
1403+ }
1404+
1405+ ceu_1to1 = false;
1406+ if (!ceu_can_scale)
12911407 goto update_cache;
12921408
12931409 cap.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
@@ -1327,7 +1443,10 @@ update_cache: · 33 unmodified lines
13271443 if (ret < 0)
13281444 return ret;
13291445
1330− update_subrect(cam);
1446+ if (ceu_1to1)
1447+ cam->subrect = cam->rect;
1448+ else
1449+ update_subrect(cam);
13311450
13321451 return 0;
13331452 }
@@ -1414,7 +1533,10 @@ static int sh_mobile_ceu_set_crop(struct soc_camera_device *icd, · 80 unmodified lines
14141533 capsr = capture_save_reset(pcdev);
14151534 dev_dbg(dev, "CAPSR 0x%x, CFLCR 0x%x\n", capsr, pcdev->cflcr);
14161535
1417− /* 1. - 2. Apply iterative camera S_CROP for new input window. */
1536+ /*
1537+ * 1. - 2. Apply iterative camera S_CROP for new input window, read back
1538+ * actual camera rectangle.
1539+ */
14181540 ret = client_s_crop(icd, a, &cam_crop);
14191541 if (ret < 0)
14201542 return ret;
@@ -1498,8 +1620,9 @@ static int sh_mobile_ceu_set_crop(struct soc_camera_device *icd, · 77 unmodified lines
14981620 ceu_write(pcdev, CFLCR, cflcr);
14991621 }
15001622
1501− icd->user_width = out_width;
1502− icd->user_height = out_height;
1623+ icd->user_width = out_width & ~3;
1624+ icd->user_height = out_height & ~3;
1625+ /* Offsets are applied at the CEU scaling filter input */
15031626 cam->ceu_left = scale_down(rect->left - cam_rect->left, scale_cam_h) & ~1;
15041627 cam->ceu_top = scale_down(rect->top - cam_rect->top, scale_cam_v) & ~1;
15051628
@@ -1538,7 +1661,7 @@ static int sh_mobile_ceu_get_crop(struct soc_camera_device *icd, · 32 unmodified lines
15381661 * CEU crop, mapped backed onto the client input (subrect).
15391662 */
15401663 static void calculate_client_output(struct soc_camera_device *icd,
1541− struct v4l2_pix_format *pix, struct v4l2_mbus_framefmt *mf)
1664+ const struct v4l2_pix_format *pix, struct v4l2_mbus_framefmt *mf)
15421665 {
15431666 struct sh_mobile_ceu_cam *cam = icd->host_priv;
15441667 struct device *dev = icd->parent;
@@ -1574,8 +1697,8 @@ static void calculate_client_output(struct soc_camera_device *icd, · 29 unmodified lines
15741697 dev_geo(dev, "3: scales %u:%u\n", scale_h, scale_v);
15751698
15761699 /*
1577− * 4. Calculate client output window by applying combined scales to real
1578− * input window.
1700+ * 4. Calculate desired client output window by applying combined scales
1701+ * to client (real) input window.
15791702 */
15801703 mf->width = scale_down(cam->rect.width, scale_h);
15811704 mf->height = scale_down(cam->rect.height, scale_v);
@@ -1600,8 +1723,6 @@ static int sh_mobile_ceu_set_fmt(struct soc_camera_device *icd, · 18 unmodified lines
16001723 bool image_mode;
16011724 enum v4l2_field field;
16021725
1603− dev_geo(dev, "S_FMT(pix=0x%x, %ux%u)\n", pixfmt, pix->width, pix->height);
1604−
16051726 switch (pix->field) {
16061727 default:
16071728 pix->field = V4L2_FIELD_NONE;
@@ -1622,8 +1743,8 @@ static int sh_mobile_ceu_set_fmt(struct soc_camera_device *icd, · 14 unmodified lines
16221743 return -EINVAL;
16231744 }
16241745
1625− /* 1.-4. Calculate client output geometry */
1626− calculate_client_output(icd, &f->fmt.pix, &mf);
1746+ /* 1.-4. Calculate desired client output geometry */
1747+ calculate_client_output(icd, pix, &mf);
16271748 mf.field = pix->field;
16281749 mf.colorspace = pix->colorspace;
16291750 mf.code = xlate->code;
@@ -1639,6 +1760,9 @@ static int sh_mobile_ceu_set_fmt(struct soc_camera_device *icd, · 9 unmodified lines
16391760 image_mode = false;
16401761 }
16411762
1763+ dev_geo(dev, "S_FMT(pix=0x%x, fld 0x%x, code 0x%x, %ux%u)\n", pixfmt, mf.field, mf.code,
1764+ pix->width, pix->height);
1765+
16421766 dev_geo(dev, "4: request camera output %ux%u\n", mf.width, mf.height);
16431767
16441768 /* 5. - 9. */
@@ -1700,6 +1824,10 @@ static int sh_mobile_ceu_set_fmt(struct soc_camera_device *icd, · 55 unmodified lines
17001824 pcdev->field = field;
17011825 pcdev->image_mode = image_mode;
17021826
1827+ /* CFSZR requirement */
1828+ pix->width &= ~3;
1829+ pix->height &= ~3;
1830+
17031831 return 0;
17041832 }
17051833
@@ -1725,7 +1853,8 @@ static int sh_mobile_ceu_try_fmt(struct soc_camera_device *icd, · 19 unmodified lines
17251853
17261854 /* FIXME: calculate using depth and bus width */
17271855
1728− v4l_bound_align_image(&pix->width, 2, 2560, 1,
1856+ /* CFSZR requires height and width to be 4-pixel aligned */
1857+ v4l_bound_align_image(&pix->width, 2, 2560, 2,
17291858 &pix->height, 4, 1920, 2, 0);
17301859
17311860 width = pix->width;
@@ -1778,6 +1907,9 @@ static int sh_mobile_ceu_try_fmt(struct soc_camera_device *icd, · 46 unmodified lines
17781907 pix->height = height;
17791908 }
17801909
1910+ pix->width &= ~3;
1911+ pix->height &= ~3;
1912+
17811913 dev_geo(icd->parent, "%s(): return %d, fmt 0x%x, %ux%u\n",
17821914 __func__, ret, pix->pixelformat, pix->width, pix->height);
17831915
@@ -1824,8 +1956,8 @@ static int sh_mobile_ceu_set_livecrop(struct soc_camera_device *icd, · 40 unmodified lines
18241956 out_height != f.fmt.pix.height))
18251957 ret = -EINVAL;
18261958 if (!ret) {
1827− icd->user_width = out_width;
1828− icd->user_height = out_height;
1959+ icd->user_width = out_width & ~3;
1960+ icd->user_height = out_height & ~3;
18291961 ret = sh_mobile_ceu_set_bus_param(icd,
18301962 icd->current_fmt->host_fmt->fourcc);
18311963 }
@@ -1869,55 +2001,6 @@ static int sh_mobile_ceu_init_videobuf(struct vb2_queue *q, · 37 unmodified lines
18692001 return vb2_queue_init(q);
18702002 }
18712003
1872−static int sh_mobile_ceu_get_ctrl(struct soc_camera_device *icd,
1873− struct v4l2_control *ctrl)
1874−{
1875− struct soc_camera_host *ici = to_soc_camera_host(icd->parent);
1876− struct sh_mobile_ceu_dev *pcdev = ici->priv;
1877− u32 val;
1878−
1879− switch (ctrl->id) {
1880− case V4L2_CID_SHARPNESS:
1881− val = ceu_read(pcdev, CLFCR);
1882− ctrl->value = val ^ 1;
1883− return 0;
1884− }
1885− return -ENOIOCTLCMD;
1886−}
1887−
1888−static int sh_mobile_ceu_set_ctrl(struct soc_camera_device *icd,
1889− struct v4l2_control *ctrl)
1890−{
1891− struct soc_camera_host *ici = to_soc_camera_host(icd->parent);
1892− struct sh_mobile_ceu_dev *pcdev = ici->priv;
1893−
1894− switch (ctrl->id) {
1895− case V4L2_CID_SHARPNESS:
1896− switch (icd->current_fmt->host_fmt->fourcc) {
1897− case V4L2_PIX_FMT_NV12:
1898− case V4L2_PIX_FMT_NV21:
1899− case V4L2_PIX_FMT_NV16:
1900− case V4L2_PIX_FMT_NV61:
1901− ceu_write(pcdev, CLFCR, !ctrl->value);
1902− return 0;
1903− }
1904− return -EINVAL;
1905− }
1906− return -ENOIOCTLCMD;
1907−}
1908−
1909−static const struct v4l2_queryctrl sh_mobile_ceu_controls[] = {
1910− {
1911− .id = V4L2_CID_SHARPNESS,
1912− .type = V4L2_CTRL_TYPE_BOOLEAN,
1913− .name = "Low-pass filter",
1914− .minimum = 0,
1915− .maximum = 1,
1916− .step = 1,
1917− .default_value = 0,
1918− },
1919−};
1920−
19212004 static struct soc_camera_host_ops sh_mobile_ceu_host_ops = {
19222005 .owner = THIS_MODULE,
19232006 .add = sh_mobile_ceu_add_device,
@@ -1929,14 +2012,10 @@ static struct soc_camera_host_ops sh_mobile_ceu_host_ops = { · 5 unmodified lines
19292012 .set_livecrop = sh_mobile_ceu_set_livecrop,
19302013 .set_fmt = sh_mobile_ceu_set_fmt,
19312014 .try_fmt = sh_mobile_ceu_try_fmt,
1932− .set_ctrl = sh_mobile_ceu_set_ctrl,
1933− .get_ctrl = sh_mobile_ceu_get_ctrl,
19342015 .poll = sh_mobile_ceu_poll,
19352016 .querycap = sh_mobile_ceu_querycap,
19362017 .set_bus_param = sh_mobile_ceu_set_bus_param,
19372018 .init_videobuf2 = sh_mobile_ceu_init_videobuf,
1938− .controls = sh_mobile_ceu_controls,
1939− .num_controls = ARRAY_SIZE(sh_mobile_ceu_controls),
19402019 };
19412020
19422021 struct bus_wait {
drivers/media/video/sh_mobile_csi2.c+84−48
@@ -19,6 +19,7 @@ · 18 unmodified lines
1919 #include <media/sh_mobile_ceu.h>
2020 #include <media/sh_mobile_csi2.h>
2121 #include <media/soc_camera.h>
22+#include <media/soc_mediabus.h>
2223 #include <media/v4l2-common.h>
2324 #include <media/v4l2-dev.h>
2425 #include <media/v4l2-device.h>
@@ -35,11 +36,10 @@ struct sh_csi2 { · 10 unmodified lines
3536 struct v4l2_subdev subdev;
3637 struct list_head list;
3738 unsigned int irq;
39+ unsigned long mipi_flags;
3840 void __iomem *base;
3941 struct platform_device *pdev;
4042 struct sh_csi2_client_config *client;
41− unsigned long (*query_bus_param)(struct soc_camera_device *);
42− int (*set_bus_param)(struct soc_camera_device *, unsigned long);
4343 };
4444
4545 static int sh_csi2_try_fmt(struct v4l2_subdev *sd,
@@ -127,9 +127,34 @@ static int sh_csi2_s_fmt(struct v4l2_subdev *sd, · 81 unmodified lines
127127 return 0;
128128 }
129129
130+static int sh_csi2_g_mbus_config(struct v4l2_subdev *sd,
131+ struct v4l2_mbus_config *cfg)
132+{
133+ cfg->flags = V4L2_MBUS_PCLK_SAMPLE_RISING |
134+ V4L2_MBUS_HSYNC_ACTIVE_HIGH | V4L2_MBUS_VSYNC_ACTIVE_HIGH |
135+ V4L2_MBUS_MASTER | V4L2_MBUS_DATA_ACTIVE_HIGH;
136+ cfg->type = V4L2_MBUS_PARALLEL;
137+
138+ return 0;
139+}
140+
141+static int sh_csi2_s_mbus_config(struct v4l2_subdev *sd,
142+ const struct v4l2_mbus_config *cfg)
143+{
144+ struct sh_csi2 *priv = container_of(sd, struct sh_csi2, subdev);
145+ struct soc_camera_device *icd = (struct soc_camera_device *)sd->grp_id;
146+ struct v4l2_subdev *client_sd = soc_camera_to_subdev(icd);
147+ struct v4l2_mbus_config client_cfg = {.type = V4L2_MBUS_CSI2,
148+ .flags = priv->mipi_flags};
149+
150+ return v4l2_subdev_call(client_sd, video, s_mbus_config, &client_cfg);
151+}
152+
130153 static struct v4l2_subdev_video_ops sh_csi2_subdev_video_ops = {
131154 .s_mbus_fmt = sh_csi2_s_fmt,
132155 .try_mbus_fmt = sh_csi2_try_fmt,
156+ .g_mbus_config = sh_csi2_g_mbus_config,
157+ .s_mbus_config = sh_csi2_s_mbus_config,
133158 };
134159
135160 static void sh_csi2_hwinit(struct sh_csi2 *priv)
@@ -144,11 +169,21 @@ static void sh_csi2_hwinit(struct sh_csi2 *priv) · 8 unmodified lines
144169 udelay(5);
145170 iowrite32(0x00000000, priv->base + SH_CSI2_SRST);
146171
147− if (priv->client->lanes & 3)
148− tmp |= priv->client->lanes & 3;
149− else
150− /* Default - both lanes */
151− tmp |= 3;
172+ switch (pdata->type) {
173+ case SH_CSI2C:
174+ if (priv->client->lanes == 1)
175+ tmp |= 1;
176+ else
177+ /* Default - both lanes */
178+ tmp |= 3;
179+ break;
180+ case SH_CSI2I:
181+ if (!priv->client->lanes || priv->client->lanes > 4)
182+ /* Default - all 4 lanes */
183+ tmp |= 0xf;
184+ else
185+ tmp |= (1 << priv->client->lanes) - 1;
186+ }
152187
153188 if (priv->client->phy == SH_CSI2_PHY_MAIN)
154189 tmp |= 0x8000;
@@ -163,38 +198,18 @@ static void sh_csi2_hwinit(struct sh_csi2 *priv) · 8 unmodified lines
163198 iowrite32(tmp, priv->base + SH_CSI2_CHKSUM);
164199 }
165200
166−static int sh_csi2_set_bus_param(struct soc_camera_device *icd,
167− unsigned long flags)
168−{
169− return 0;
170−}
171−
172−static unsigned long sh_csi2_query_bus_param(struct soc_camera_device *icd)
173−{
174− struct soc_camera_link *icl = to_soc_camera_link(icd);
175− const unsigned long flags = SOCAM_PCLK_SAMPLE_RISING |
176− SOCAM_HSYNC_ACTIVE_HIGH | SOCAM_VSYNC_ACTIVE_HIGH |
177− SOCAM_MASTER | SOCAM_DATAWIDTH_8 | SOCAM_DATA_ACTIVE_HIGH;
178−
179− return soc_camera_apply_sensor_flags(icl, flags);
180−}
181−
182201 static int sh_csi2_client_connect(struct sh_csi2 *priv)
183202 {
184203 struct sh_csi2_pdata *pdata = priv->pdev->dev.platform_data;
185− struct v4l2_subdev *sd, *csi2_sd = &priv->subdev;
186− struct soc_camera_device *icd = NULL;
204+ struct soc_camera_device *icd = (struct soc_camera_device *)priv->subdev.grp_id;
205+ struct v4l2_subdev *client_sd = soc_camera_to_subdev(icd);
187206 struct device *dev = v4l2_get_subdevdata(&priv->subdev);
188− int i;
207+ struct v4l2_mbus_config cfg;
208+ unsigned long common_flags, csi2_flags;
209+ int i, ret;
189210
190− v4l2_device_for_each_subdev(sd, csi2_sd->v4l2_dev)
191− if (sd->grp_id) {
192− icd = (struct soc_camera_device *)sd->grp_id;
193− break;
194− }
195−
196− if (!icd)
197− return -EINVAL;
211+ if (priv->client)
212+ return -EBUSY;
198213
199214 for (i = 0; i < pdata->num_clients; i++)
200215 if (&pdata->clients[i].pdev->dev == icd->pdev)
@@ -205,14 +220,41 @@ static int sh_csi2_client_connect(struct sh_csi2 *priv) · 4 unmodified lines
205220 if (i == pdata->num_clients)
206221 return -ENODEV;
207222
208− priv->client = pdata->clients + i;
223+ /* Check if we can support this camera */
224+ csi2_flags = V4L2_MBUS_CSI2_CONTINUOUS_CLOCK | V4L2_MBUS_CSI2_1_LANE;
225+
226+ switch (pdata->type) {
227+ case SH_CSI2C:
228+ if (pdata->clients[i].lanes != 1)
229+ csi2_flags |= V4L2_MBUS_CSI2_2_LANE;
230+ break;
231+ case SH_CSI2I:
232+ switch (pdata->clients[i].lanes) {
233+ default:
234+ csi2_flags |= V4L2_MBUS_CSI2_4_LANE;
235+ case 3:
236+ csi2_flags |= V4L2_MBUS_CSI2_3_LANE;
237+ case 2:
238+ csi2_flags |= V4L2_MBUS_CSI2_2_LANE;
239+ }
240+ }
209241
210− priv->set_bus_param = icd->ops->set_bus_param;
211− priv->query_bus_param = icd->ops->query_bus_param;
212− icd->ops->set_bus_param = sh_csi2_set_bus_param;
213− icd->ops->query_bus_param = sh_csi2_query_bus_param;
242+ cfg.type = V4L2_MBUS_CSI2;
243+ ret = v4l2_subdev_call(client_sd, video, g_mbus_config, &cfg);
244+ if (ret == -ENOIOCTLCMD)
245+ common_flags = csi2_flags;
246+ else if (!ret)
247+ common_flags = soc_mbus_config_compatible(&cfg,
248+ csi2_flags);
249+ else
250+ common_flags = 0;
214251
215− csi2_sd->grp_id = (long)icd;
252+ if (!common_flags)
253+ return -EINVAL;
254+
255+ /* All good: camera MIPI configuration supported */
256+ priv->mipi_flags = common_flags;
257+ priv->client = pdata->clients + i;
216258
217259 pm_runtime_get_sync(dev);
218260
@@ -223,16 +265,10 @@ static int sh_csi2_client_connect(struct sh_csi2 *priv) · 4 unmodified lines
223265
224266 static void sh_csi2_client_disconnect(struct sh_csi2 *priv)
225267 {
226− struct soc_camera_device *icd = (struct soc_camera_device *)priv->subdev.grp_id;
268+ if (!priv->client)
269+ return;
227270
228271 priv->client = NULL;
229− priv->subdev.grp_id = 0;
230−
231− /* Driver is about to be unbound */
232− icd->ops->set_bus_param = priv->set_bus_param;
233− icd->ops->query_bus_param = priv->query_bus_param;
234− priv->set_bus_param = NULL;
235− priv->query_bus_param = NULL;
236272
237273 pm_runtime_put(v4l2_get_subdevdata(&priv->subdev));
238274 }
drivers/media/video/soc_camera.c+141−132
@@ -50,49 +50,65 @@ static LIST_HEAD(hosts); · 49 unmodified lines
5050 static LIST_HEAD(devices);
5151 static DEFINE_MUTEX(list_lock); /* Protects the list of hosts */
5252
53−static int soc_camera_power_set(struct soc_camera_device *icd,
54− struct soc_camera_link *icl,
55− int power_on)
53+static int soc_camera_power_on(struct soc_camera_device *icd,
54+ struct soc_camera_link *icl)
5655 {
57− int ret;
58−
59− if (power_on) {
60− ret = regulator_bulk_enable(icl->num_regulators,
61− icl->regulators);
62− if (ret < 0) {
63− dev_err(icd->pdev, "Cannot enable regulators\n");
64− return ret;
65− }
56+ struct v4l2_subdev *sd = soc_camera_to_subdev(icd);
57+ int ret = regulator_bulk_enable(icl->num_regulators,
58+ icl->regulators);
59+ if (ret < 0) {
60+ dev_err(icd->pdev, "Cannot enable regulators\n");
61+ return ret;
62+ }
6663
67− if (icl->power)
68− ret = icl->power(icd->pdev, power_on);
64+ if (icl->power) {
65+ ret = icl->power(icd->pdev, 1);
6966 if (ret < 0) {
7067 dev_err(icd->pdev,
7168 "Platform failed to power-on the camera.\n");
72−
73− regulator_bulk_disable(icl->num_regulators,
74− icl->regulators);
75− return ret;
69+ goto elinkpwr;
7670 }
77− } else {
78− ret = 0;
79− if (icl->power)
80− ret = icl->power(icd->pdev, 0);
71+ }
72+
73+ ret = v4l2_subdev_call(sd, core, s_power, 1);
74+ if (ret < 0 && ret != -ENOIOCTLCMD && ret != -ENODEV)
75+ goto esdpwr;
76+
77+ return 0;
78+
79+esdpwr:
80+ if (icl->power)
81+ icl->power(icd->pdev, 0);
82+elinkpwr:
83+ regulator_bulk_disable(icl->num_regulators,
84+ icl->regulators);
85+ return ret;
86+}
87+
88+static int soc_camera_power_off(struct soc_camera_device *icd,
89+ struct soc_camera_link *icl)
90+{
91+ struct v4l2_subdev *sd = soc_camera_to_subdev(icd);
92+ int ret = v4l2_subdev_call(sd, core, s_power, 0);
93+
94+ if (ret < 0 && ret != -ENOIOCTLCMD && ret != -ENODEV)
95+ return ret;
96+
97+ if (icl->power) {
98+ ret = icl->power(icd->pdev, 0);
8199 if (ret < 0) {
82100 dev_err(icd->pdev,
83101 "Platform failed to power-off the camera.\n");
84102 return ret;
85103 }
86−
87− ret = regulator_bulk_disable(icl->num_regulators,
88− icl->regulators);
89− if (ret < 0) {
90− dev_err(icd->pdev, "Cannot disable regulators\n");
91− return ret;
92− }
93104 }
94105
95− return 0;
106+ ret = regulator_bulk_disable(icl->num_regulators,
107+ icl->regulators);
108+ if (ret < 0)
109+ dev_err(icd->pdev, "Cannot disable regulators\n");
110+
111+ return ret;
96112 }
97113
98114 const struct soc_camera_format_xlate *soc_camera_xlate_by_fourcc(
@@ -108,38 +124,38 @@ const struct soc_camera_format_xlate *soc_camera_xlate_by_fourcc( · 9 unmodified lines
108124 EXPORT_SYMBOL(soc_camera_xlate_by_fourcc);
109125
110126 /**
111− * soc_camera_apply_sensor_flags() - apply platform SOCAM_SENSOR_INVERT_* flags
127+ * soc_camera_apply_board_flags() - apply platform SOCAM_SENSOR_INVERT_* flags
112128 * @icl: camera platform parameters
113− * @flags: flags to be inverted according to platform configuration
129+ * @cfg: media bus configuration
114130 * @return: resulting flags
115131 */
116−unsigned long soc_camera_apply_sensor_flags(struct soc_camera_link *icl,
117− unsigned long flags)
132+unsigned long soc_camera_apply_board_flags(struct soc_camera_link *icl,
133+ const struct v4l2_mbus_config *cfg)
118134 {
119− unsigned long f;
135+ unsigned long f, flags = cfg->flags;
120136
121137 /* If only one of the two polarities is supported, switch to the opposite */
122138 if (icl->flags & SOCAM_SENSOR_INVERT_HSYNC) {
123− f = flags & (SOCAM_HSYNC_ACTIVE_HIGH | SOCAM_HSYNC_ACTIVE_LOW);
124− if (f == SOCAM_HSYNC_ACTIVE_HIGH || f == SOCAM_HSYNC_ACTIVE_LOW)
125− flags ^= SOCAM_HSYNC_ACTIVE_HIGH | SOCAM_HSYNC_ACTIVE_LOW;
139+ f = flags & (V4L2_MBUS_HSYNC_ACTIVE_HIGH | V4L2_MBUS_HSYNC_ACTIVE_LOW);
140+ if (f == V4L2_MBUS_HSYNC_ACTIVE_HIGH || f == V4L2_MBUS_HSYNC_ACTIVE_LOW)
141+ flags ^= V4L2_MBUS_HSYNC_ACTIVE_HIGH | V4L2_MBUS_HSYNC_ACTIVE_LOW;
126142 }
127143
128144 if (icl->flags & SOCAM_SENSOR_INVERT_VSYNC) {
129− f = flags & (SOCAM_VSYNC_ACTIVE_HIGH | SOCAM_VSYNC_ACTIVE_LOW);
130− if (f == SOCAM_VSYNC_ACTIVE_HIGH || f == SOCAM_VSYNC_ACTIVE_LOW)
131− flags ^= SOCAM_VSYNC_ACTIVE_HIGH | SOCAM_VSYNC_ACTIVE_LOW;
145+ f = flags & (V4L2_MBUS_VSYNC_ACTIVE_HIGH | V4L2_MBUS_VSYNC_ACTIVE_LOW);
146+ if (f == V4L2_MBUS_VSYNC_ACTIVE_HIGH || f == V4L2_MBUS_VSYNC_ACTIVE_LOW)
147+ flags ^= V4L2_MBUS_VSYNC_ACTIVE_HIGH | V4L2_MBUS_VSYNC_ACTIVE_LOW;
132148 }
133149
134150 if (icl->flags & SOCAM_SENSOR_INVERT_PCLK) {
135− f = flags & (SOCAM_PCLK_SAMPLE_RISING | SOCAM_PCLK_SAMPLE_FALLING);
136− if (f == SOCAM_PCLK_SAMPLE_RISING || f == SOCAM_PCLK_SAMPLE_FALLING)
137− flags ^= SOCAM_PCLK_SAMPLE_RISING | SOCAM_PCLK_SAMPLE_FALLING;
151+ f = flags & (V4L2_MBUS_PCLK_SAMPLE_RISING | V4L2_MBUS_PCLK_SAMPLE_FALLING);
152+ if (f == V4L2_MBUS_PCLK_SAMPLE_RISING || f == V4L2_MBUS_PCLK_SAMPLE_FALLING)
153+ flags ^= V4L2_MBUS_PCLK_SAMPLE_RISING | V4L2_MBUS_PCLK_SAMPLE_FALLING;
138154 }
139155
140156 return flags;
141157 }
142−EXPORT_SYMBOL(soc_camera_apply_sensor_flags);
158+EXPORT_SYMBOL(soc_camera_apply_board_flags);
143159
144160 #define pixfmtstr(x) (x) & 0xff, ((x) >> 8) & 0xff, ((x) >> 16) & 0xff, \
145161 ((x) >> 24) & 0xff
@@ -233,6 +249,14 @@ static int soc_camera_s_std(struct file *file, void *priv, v4l2_std_id *a) · 87 unmodified lines
233249 return v4l2_subdev_call(sd, core, s_std, *a);
234250 }
235251
252+static int soc_camera_g_std(struct file *file, void *priv, v4l2_std_id *a)
253+{
254+ struct soc_camera_device *icd = file->private_data;
255+ struct v4l2_subdev *sd = soc_camera_to_subdev(icd);
256+
257+ return v4l2_subdev_call(sd, core, g_std, a);
258+}
259+
236260 static int soc_camera_enum_fsizes(struct file *file, void *fh,
237261 struct v4l2_frmsizeenum *fsize)
238262 {
@@ -318,6 +342,32 @@ static int soc_camera_dqbuf(struct file *file, void *priv, · 79 unmodified lines
318342 return vb2_dqbuf(&icd->vb2_vidq, p, file->f_flags & O_NONBLOCK);
319343 }
320344
345+static int soc_camera_create_bufs(struct file *file, void *priv,
346+ struct v4l2_create_buffers *create)
347+{
348+ struct soc_camera_device *icd = file->private_data;
349+ struct soc_camera_host *ici = to_soc_camera_host(icd->parent);
350+
351+ /* videobuf2 only */
352+ if (ici->ops->init_videobuf)
353+ return -EINVAL;
354+ else
355+ return vb2_create_bufs(&icd->vb2_vidq, create);
356+}
357+
358+static int soc_camera_prepare_buf(struct file *file, void *priv,
359+ struct v4l2_buffer *b)
360+{
361+ struct soc_camera_device *icd = file->private_data;
362+ struct soc_camera_host *ici = to_soc_camera_host(icd->parent);
363+
364+ /* videobuf2 only */
365+ if (ici->ops->init_videobuf)
366+ return -EINVAL;
367+ else
368+ return vb2_prepare_buf(&icd->vb2_vidq, b);
369+}
370+
321371 /* Always entered with .video_lock held */
322372 static int soc_camera_init_user_formats(struct soc_camera_device *icd)
323373 {
@@ -448,7 +498,7 @@ static int soc_camera_open(struct file *file) · 124 unmodified lines
448498 struct soc_camera_host *ici;
449499 int ret;
450500
451− if (!icd->ops)
501+ if (!to_soc_camera_control(icd))
452502 /* No device driver attached */
453503 return -ENODEV;
454504
@@ -476,7 +526,7 @@ static int soc_camera_open(struct file *file) · 21 unmodified lines
476526 },
477527 };
478528
479− ret = soc_camera_power_set(icd, icl, 1);
529+ ret = soc_camera_power_on(icd, icl);
480530 if (ret < 0)
481531 goto epower;
482532
@@ -512,6 +562,7 @@ static int soc_camera_open(struct file *file) · 29 unmodified lines
512562 if (ret < 0)
513563 goto einitvb;
514564 }
565+ v4l2_ctrl_handler_setup(&icd->ctrl_handler);
515566 }
516567
517568 file->private_data = icd;
@@ -529,7 +580,7 @@ esfmt: · 11 unmodified lines
529580 eresume:
530581 ici->ops->remove(icd);
531582 eiciadd:
532− soc_camera_power_set(icd, icl, 0);
583+ soc_camera_power_off(icd, icl);
533584 epower:
534585 icd->use_count--;
535586 module_put(ici->ops->owner);
@@ -553,7 +604,7 @@ static int soc_camera_close(struct file *file) · 17 unmodified lines
553604 if (ici->ops->init_videobuf2)
554605 vb2_queue_release(&icd->vb2_vidq);
555606
556− soc_camera_power_set(icd, icl, 0);
607+ soc_camera_power_off(icd, icl);
557608 }
558609
559610 if (icd->streamer == file)
@@ -781,75 +832,6 @@ static int soc_camera_streamoff(struct file *file, void *priv, · 221 unmodified lines
781832 return 0;
782833 }
783834
784−static int soc_camera_queryctrl(struct file *file, void *priv,
785− struct v4l2_queryctrl *qc)
786−{
787− struct soc_camera_device *icd = file->private_data;
788− struct soc_camera_host *ici = to_soc_camera_host(icd->parent);
789− int i;
790−
791− WARN_ON(priv != file->private_data);
792−
793− if (!qc->id)
794− return -EINVAL;
795−
796− /* First check host controls */
797− for (i = 0; i < ici->ops->num_controls; i++)
798− if (qc->id == ici->ops->controls[i].id) {
799− memcpy(qc, &(ici->ops->controls[i]),
800− sizeof(*qc));
801− return 0;
802− }
803−
804− /* Then device controls */
805− for (i = 0; i < icd->ops->num_controls; i++)
806− if (qc->id == icd->ops->controls[i].id) {
807− memcpy(qc, &(icd->ops->controls[i]),
808− sizeof(*qc));
809− return 0;
810− }
811−
812− return -EINVAL;
813−}
814−
815−static int soc_camera_g_ctrl(struct file *file, void *priv,
816− struct v4l2_control *ctrl)
817−{
818− struct soc_camera_device *icd = file->private_data;
819− struct soc_camera_host *ici = to_soc_camera_host(icd->parent);
820− struct v4l2_subdev *sd = soc_camera_to_subdev(icd);
821− int ret;
822−
823− WARN_ON(priv != file->private_data);
824−
825− if (ici->ops->get_ctrl) {
826− ret = ici->ops->get_ctrl(icd, ctrl);
827− if (ret != -ENOIOCTLCMD)
828− return ret;
829− }
830−
831− return v4l2_subdev_call(sd, core, g_ctrl, ctrl);
832−}
833−
834−static int soc_camera_s_ctrl(struct file *file, void *priv,
835− struct v4l2_control *ctrl)
836−{
837− struct soc_camera_device *icd = file->private_data;
838− struct soc_camera_host *ici = to_soc_camera_host(icd->parent);
839− struct v4l2_subdev *sd = soc_camera_to_subdev(icd);
840− int ret;
841−
842− WARN_ON(priv != file->private_data);
843−
844− if (ici->ops->set_ctrl) {
845− ret = ici->ops->set_ctrl(icd, ctrl);
846− if (ret != -ENOIOCTLCMD)
847− return ret;
848− }
849−
850− return v4l2_subdev_call(sd, core, s_ctrl, ctrl);
851−}
852−
853835 static int soc_camera_cropcap(struct file *file, void *fh,
854836 struct v4l2_cropcap *a)
855837 {
@@ -1003,7 +985,7 @@ static int soc_camera_init_i2c(struct soc_camera_device *icd, · 147 unmodified lines
1003985 goto ei2cga;
1004986 }
1005987
1006− icl->board_info->platform_data = icd;
988+ icl->board_info->platform_data = icl;
1007989
1008990 subdev = v4l2_i2c_new_subdev_board(&ici->v4l2_dev, adap,
1009991 icl->board_info, NULL);
@@ -1052,12 +1034,29 @@ static int soc_camera_probe(struct soc_camera_device *icd) · 42 unmodified lines
10521034
10531035 dev_info(icd->pdev, "Probing %s\n", dev_name(icd->pdev));
10541036
1037+ /*
1038+ * Currently the subdev with the largest number of controls (13) is
1039+ * ov6550. So let's pick 16 as a hint for the control handler. Note
1040+ * that this is a hint only: too large and you waste some memory, too
1041+ * small and there is a (very) small performance hit when looking up
1042+ * controls in the internal hash.
1043+ */
1044+ ret = v4l2_ctrl_handler_init(&icd->ctrl_handler, 16);
1045+ if (ret < 0)
1046+ return ret;
1047+
10551048 ret = regulator_bulk_get(icd->pdev, icl->num_regulators,
10561049 icl->regulators);
10571050 if (ret < 0)
10581051 goto ereg;
10591052
1060− ret = soc_camera_power_set(icd, icl, 1);
1053+ /*
1054+ * This will not yet call v4l2_subdev_core_ops::s_power(1), because the
1055+ * subdevice has not been initialised yet. We'll have to call it once
1056+ * again after initialisation, even though it shouldn't be needed, we
1057+ * don't do any IO here.
1058+ */
1059+ ret = soc_camera_power_on(icd, icl);
10611060 if (ret < 0)
10621061 goto epower;
10631062
@@ -1098,6 +1097,7 @@ static int soc_camera_probe(struct soc_camera_device *icd) · 34 unmodified lines
10981097 if (!control || !control->driver || !dev_get_drvdata(control) ||
10991098 !try_module_get(control->driver->owner)) {
11001099 icl->del_device(icd);
1100+ ret = -ENODEV;
11011101 goto enodrv;
11021102 }
11031103 }
@@ -1105,6 +1105,9 @@ static int soc_camera_probe(struct soc_camera_device *icd) · 1 unmodified line
11051105 sd = soc_camera_to_subdev(icd);
11061106 sd->grp_id = (long)icd;
11071107
1108+ if (v4l2_ctrl_add_handler(&icd->ctrl_handler, sd->ctrl_handler))
1109+ goto ectrl;
1110+
11081111 /* At this point client .probe() should have run already */
11091112 ret = soc_camera_init_user_formats(icd);
11101113 if (ret < 0)
@@ -1123,6 +1126,10 @@ static int soc_camera_probe(struct soc_camera_device *icd) · 12 unmodified lines
11231126 if (ret < 0)
11241127 goto evidstart;
11251128
1129+ ret = v4l2_subdev_call(sd, core, s_power, 1);
1130+ if (ret < 0 && ret != -ENOIOCTLCMD)
1131+ goto esdpwr;
1132+
11261133 /* Try to improve our guess of a reasonable window format */
11271134 if (!v4l2_subdev_call(sd, video, g_mbus_fmt, &mf)) {
11281135 icd->user_width = mf.width;
@@ -1133,16 +1140,19 @@ static int soc_camera_probe(struct soc_camera_device *icd) · 4 unmodified lines
11331140
11341141 ici->ops->remove(icd);
11351142
1136− soc_camera_power_set(icd, icl, 0);
1143+ soc_camera_power_off(icd, icl);
11371144
11381145 mutex_unlock(&icd->video_lock);
11391146
11401147 return 0;
11411148
1149+esdpwr:
1150+ video_unregister_device(icd->vdev);
11421151 evidstart:
11431152 mutex_unlock(&icd->video_lock);
11441153 soc_camera_free_user_formats(icd);
11451154 eiufmt:
1155+ectrl:
11461156 if (icl->board_info) {
11471157 soc_camera_free_i2c(icd);
11481158 } else {
@@ -1152,13 +1162,15 @@ eiufmt: · 3 unmodified lines
11521162 enodrv:
11531163 eadddev:
11541164 video_device_release(icd->vdev);
1165+ icd->vdev = NULL;
11551166 evdc:
11561167 ici->ops->remove(icd);
11571168 eadd:
1158− soc_camera_power_set(icd, icl, 0);
1169+ soc_camera_power_off(icd, icl);
11591170 epower:
11601171 regulator_bulk_free(icl->num_regulators, icl->regulators);
11611172 ereg:
1173+ v4l2_ctrl_handler_free(&icd->ctrl_handler);
11621174 return ret;
11631175 }
11641176
@@ -1173,6 +1185,7 @@ static int soc_camera_remove(struct soc_camera_device *icd) · 8 unmodified lines
11731185
11741186 BUG_ON(!icd->parent);
11751187
1188+ v4l2_ctrl_handler_free(&icd->ctrl_handler);
11761189 if (vdev) {
11771190 video_unregister_device(vdev);
11781191 icd->vdev = NULL;
@@ -1363,24 +1376,24 @@ static int soc_camera_device_register(struct soc_camera_device *icd) · 184 unmodified lines
13631376
13641377 static const struct v4l2_ioctl_ops soc_camera_ioctl_ops = {
13651378 .vidioc_querycap = soc_camera_querycap,
1379+ .vidioc_try_fmt_vid_cap = soc_camera_try_fmt_vid_cap,
13661380 .vidioc_g_fmt_vid_cap = soc_camera_g_fmt_vid_cap,
1367− .vidioc_enum_fmt_vid_cap = soc_camera_enum_fmt_vid_cap,
13681381 .vidioc_s_fmt_vid_cap = soc_camera_s_fmt_vid_cap,
1382+ .vidioc_enum_fmt_vid_cap = soc_camera_enum_fmt_vid_cap,
13691383 .vidioc_enum_input = soc_camera_enum_input,
13701384 .vidioc_g_input = soc_camera_g_input,
13711385 .vidioc_s_input = soc_camera_s_input,
13721386 .vidioc_s_std = soc_camera_s_std,
1387+ .vidioc_g_std = soc_camera_g_std,
13731388 .vidioc_enum_framesizes = soc_camera_enum_fsizes,
13741389 .vidioc_reqbufs = soc_camera_reqbufs,
1375− .vidioc_try_fmt_vid_cap = soc_camera_try_fmt_vid_cap,
13761390 .vidioc_querybuf = soc_camera_querybuf,
13771391 .vidioc_qbuf = soc_camera_qbuf,
13781392 .vidioc_dqbuf = soc_camera_dqbuf,
1393+ .vidioc_create_bufs = soc_camera_create_bufs,
1394+ .vidioc_prepare_buf = soc_camera_prepare_buf,
13791395 .vidioc_streamon = soc_camera_streamon,
13801396 .vidioc_streamoff = soc_camera_streamoff,
1381− .vidioc_queryctrl = soc_camera_queryctrl,
1382− .vidioc_g_ctrl = soc_camera_g_ctrl,
1383− .vidioc_s_ctrl = soc_camera_s_ctrl,
13841397 .vidioc_cropcap = soc_camera_cropcap,
13851398 .vidioc_g_crop = soc_camera_g_crop,
13861399 .vidioc_s_crop = soc_camera_s_crop,
@@ -1409,6 +1422,7 @@ static int video_dev_create(struct soc_camera_device *icd) · 22 unmodified lines
14091422 vdev->ioctl_ops = &soc_camera_ioctl_ops;
14101423 vdev->release = video_device_release;
14111424 vdev->tvnorms = V4L2_STD_UNKNOWN;
1425+ vdev->ctrl_handler = &icd->ctrl_handler;
14121426 vdev->lock = &icd->video_lock;
14131427
14141428 icd->vdev = vdev;
@@ -1427,11 +1441,6 @@ static int soc_camera_video_start(struct soc_camera_device *icd) · 12 unmodified lines
14271441 if (!icd->parent)
14281442 return -ENODEV;
14291443
1430− if (!icd->ops ||
1431− !icd->ops->query_bus_param ||
1432− !icd->ops->set_bus_param)
1433− return -EINVAL;
1434−
14351444 ret = video_register_device(icd->vdev, VFL_TYPE_GRABBER, -1);
14361445 if (ret < 0) {
14371446 dev_err(icd->pdev, "video_register_device failed: %d\n", ret);
drivers/media/video/soc_camera_platform.c+14−31
@@ -30,32 +30,12 @@ static struct soc_camera_platform_priv *get_priv(struct platform_device *pdev) · 29 unmodified lines
3030 return container_of(subdev, struct soc_camera_platform_priv, subdev);
3131 }
3232
33−static struct soc_camera_platform_info *get_info(struct soc_camera_device *icd)
34−{
35− struct platform_device *pdev =
36− to_platform_device(to_soc_camera_control(icd));
37− return pdev->dev.platform_data;
38−}
39−
4033 static int soc_camera_platform_s_stream(struct v4l2_subdev *sd, int enable)
4134 {
4235 struct soc_camera_platform_info *p = v4l2_get_subdevdata(sd);
4336 return p->set_capture(p, enable);
4437 }
4538
46−static int soc_camera_platform_set_bus_param(struct soc_camera_device *icd,
47− unsigned long flags)
48−{
49− return 0;
50−}
51−
52−static unsigned long
53−soc_camera_platform_query_bus_param(struct soc_camera_device *icd)
54−{
55− struct soc_camera_platform_info *p = get_info(icd);
56− return p->bus_param;
57−}
58−
5939 static int soc_camera_platform_fill_fmt(struct v4l2_subdev *sd,
6040 struct v4l2_mbus_framefmt *mf)
6141 {
@@ -115,6 +95,17 @@ static int soc_camera_platform_cropcap(struct v4l2_subdev *sd, · 53 unmodified lines
11595 return 0;
11696 }
11797
98+static int soc_camera_platform_g_mbus_config(struct v4l2_subdev *sd,
99+ struct v4l2_mbus_config *cfg)
100+{
101+ struct soc_camera_platform_info *p = v4l2_get_subdevdata(sd);
102+
103+ cfg->flags = p->mbus_param;
104+ cfg->type = p->mbus_type;
105+
106+ return 0;
107+}
108+
118109 static struct v4l2_subdev_video_ops platform_subdev_video_ops = {
119110 .s_stream = soc_camera_platform_s_stream,
120111 .enum_mbus_fmt = soc_camera_platform_enum_fmt,
@@ -123,6 +114,7 @@ static struct v4l2_subdev_video_ops platform_subdev_video_ops = { · 2 unmodified lines
123114 .try_mbus_fmt = soc_camera_platform_fill_fmt,
124115 .g_mbus_fmt = soc_camera_platform_fill_fmt,
125116 .s_mbus_fmt = soc_camera_platform_fill_fmt,
117+ .g_mbus_config = soc_camera_platform_g_mbus_config,
126118 };
127119
128120 static struct v4l2_subdev_ops platform_subdev_ops = {
@@ -130,11 +122,6 @@ static struct v4l2_subdev_ops platform_subdev_ops = { · 1 unmodified line
130122 .video = &platform_subdev_video_ops,
131123 };
132124
133−static struct soc_camera_ops soc_camera_platform_ops = {
134− .set_bus_param = soc_camera_platform_set_bus_param,
135− .query_bus_param = soc_camera_platform_query_bus_param,
136−};
137−
138125 static int soc_camera_platform_probe(struct platform_device *pdev)
139126 {
140127 struct soc_camera_host *ici;
@@ -163,8 +150,6 @@ static int soc_camera_platform_probe(struct platform_device *pdev) · 22 unmodified lines
163150 /* Set the control device reference */
164151 icd->control = &pdev->dev;
165152
166− icd->ops = &soc_camera_platform_ops;
167−
168153 ici = to_soc_camera_host(icd->parent);
169154
170155 v4l2_subdev_init(&priv->subdev, &platform_subdev_ops);
@@ -178,7 +163,6 @@ static int soc_camera_platform_probe(struct platform_device *pdev) · 7 unmodified lines
178163 return ret;
179164
180165 evdrs:
181− icd->ops = NULL;
182166 platform_set_drvdata(pdev, NULL);
183167 kfree(priv);
184168 return ret;
@@ -187,11 +171,10 @@ evdrs: · 2 unmodified lines
187171 static int soc_camera_platform_remove(struct platform_device *pdev)
188172 {
189173 struct soc_camera_platform_priv *priv = get_priv(pdev);
190− struct soc_camera_platform_info *p = pdev->dev.platform_data;
191− struct soc_camera_device *icd = p->icd;
174+ struct soc_camera_platform_info *p = v4l2_get_subdevdata(&priv->subdev);
192175
176+ p->icd->control = NULL;
193177 v4l2_device_unregister_subdev(&priv->subdev);
194− icd->ops = NULL;
195178 platform_set_drvdata(pdev, NULL);
196179 kfree(priv);
197180 return 0;
drivers/media/video/soc_mediabus.c+33−0
@@ -383,6 +383,39 @@ const struct soc_mbus_pixelfmt *soc_mbus_get_fmtdesc( · 382 unmodified lines
383383 }
384384 EXPORT_SYMBOL(soc_mbus_get_fmtdesc);
385385
386+unsigned int soc_mbus_config_compatible(const struct v4l2_mbus_config *cfg,
387+ unsigned int flags)
388+{
389+ unsigned long common_flags;
390+ bool hsync = true, vsync = true, pclk, data, mode;
391+ bool mipi_lanes, mipi_clock;
392+
393+ common_flags = cfg->flags & flags;
394+
395+ switch (cfg->type) {
396+ case V4L2_MBUS_PARALLEL:
397+ hsync = common_flags & (V4L2_MBUS_HSYNC_ACTIVE_HIGH |
398+ V4L2_MBUS_HSYNC_ACTIVE_LOW);
399+ vsync = common_flags & (V4L2_MBUS_VSYNC_ACTIVE_HIGH |
400+ V4L2_MBUS_VSYNC_ACTIVE_LOW);
401+ case V4L2_MBUS_BT656:
402+ pclk = common_flags & (V4L2_MBUS_PCLK_SAMPLE_RISING |
403+ V4L2_MBUS_PCLK_SAMPLE_FALLING);
404+ data = common_flags & (V4L2_MBUS_DATA_ACTIVE_HIGH |
405+ V4L2_MBUS_DATA_ACTIVE_LOW);
406+ mode = common_flags & (V4L2_MBUS_MASTER | V4L2_MBUS_SLAVE);
407+ return (!hsync || !vsync || !pclk || !data || !mode) ?
408+ 0 : common_flags;
409+ case V4L2_MBUS_CSI2:
410+ mipi_lanes = common_flags & V4L2_MBUS_CSI2_LANES;
411+ mipi_clock = common_flags & (V4L2_MBUS_CSI2_NONCONTINUOUS_CLOCK |
412+ V4L2_MBUS_CSI2_CONTINUOUS_CLOCK);
413+ return (!mipi_lanes || !mipi_clock) ? 0 : common_flags;
414+ }
415+ return 0;
416+}
417+EXPORT_SYMBOL(soc_mbus_config_compatible);
418+
386419 static int __init soc_mbus_init(void)
387420 {
388421 return 0;
drivers/media/video/tw9910.c+113−155
@@ -22,11 +22,13 @@ · 21 unmodified lines
2222 #include <linux/slab.h>
2323 #include <linux/kernel.h>
2424 #include <linux/delay.h>
25+#include <linux/v4l2-mediabus.h>
2526 #include <linux/videodev2.h>
26−#include <media/v4l2-chip-ident.h>
27−#include <media/v4l2-subdev.h>
27+
2828 #include <media/soc_camera.h>
2929 #include <media/tw9910.h>
30+#include <media/v4l2-chip-ident.h>
31+#include <media/v4l2-subdev.h>
3032
3133 #define GET_ID(val) ((val & 0xF8) >> 3)
3234 #define GET_REV(val) (val & 0x07)
@@ -203,6 +205,10 @@ · 170 unmodified lines
203205 #define RTSEL_FIELD 0x06 /* 0110 = FIELD */
204206 #define RTSEL_RTCO 0x07 /* 0111 = RTCO ( Real Time Control ) */
205207
208+/* HSYNC start and end are constant for now */
209+#define HSYNC_START 0x0260
210+#define HSYNC_END 0x0300
211+
206212 /*
207213 * structure
208214 */
@@ -220,22 +226,11 @@ struct tw9910_scale_ctrl { · 11 unmodified lines
220226 u16 vscale;
221227 };
222228
223−struct tw9910_cropping_ctrl {
224− u16 vdelay;
225− u16 vactive;
226− u16 hdelay;
227− u16 hactive;
228−};
229−
230−struct tw9910_hsync_ctrl {
231− u16 start;
232− u16 end;
233−};
234−
235229 struct tw9910_priv {
236230 struct v4l2_subdev subdev;
237231 struct tw9910_video_info *info;
238232 const struct tw9910_scale_ctrl *scale;
233+ v4l2_std_id norm;
239234 u32 revision;
240235 };
241236
@@ -329,11 +324,6 @@ static const struct tw9910_scale_ctrl tw9910_pal_scales[] = { · 87 unmodified lines
329324 },
330325 };
331326
332−static const struct tw9910_hsync_ctrl tw9910_hsync_ctrl = {
333− .start = 0x0260,
334− .end = 0x0300,
335−};
336−
337327 /*
338328 * general function
339329 */
@@ -378,21 +368,20 @@ static int tw9910_set_scale(struct i2c_client *client, · 38 unmodified lines
378368 return ret;
379369 }
380370
381−static int tw9910_set_hsync(struct i2c_client *client,
382− const struct tw9910_hsync_ctrl *hsync)
371+static int tw9910_set_hsync(struct i2c_client *client)
383372 {
384373 struct tw9910_priv *priv = to_tw9910(client);
385374 int ret;
386375
387376 /* bit 10 - 3 */
388377 ret = i2c_smbus_write_byte_data(client, HSBEGIN,
389− (hsync->start & 0x07F8) >> 3);
378+ (HSYNC_START & 0x07F8) >> 3);
390379 if (ret < 0)
391380 return ret;
392381
393382 /* bit 10 - 3 */
394383 ret = i2c_smbus_write_byte_data(client, HSEND,
395− (hsync->end & 0x07F8) >> 3);
384+ (HSYNC_END & 0x07F8) >> 3);
396385 if (ret < 0)
397386 return ret;
398387
@@ -400,8 +389,8 @@ static int tw9910_set_hsync(struct i2c_client *client, · 1 unmodified line
400389 /* bit 2 - 0 */
401390 if (1 == priv->revision)
402391 ret = tw9910_mask_set(client, HSLOWCTL, 0x77,
403− (hsync->start & 0x0007) << 4 |
404− (hsync->end & 0x0007));
392+ (HSYNC_START & 0x0007) << 4 |
393+ (HSYNC_END & 0x0007));
405394
406395 return ret;
407396 }
@@ -433,12 +422,11 @@ static int tw9910_power(struct i2c_client *client, int enable) · 25 unmodified lines
433422 return tw9910_mask_set(client, ACNTL2, ACNTL2_PDN_MASK, acntl2);
434423 }
435424
436−static const struct tw9910_scale_ctrl*
437−tw9910_select_norm(struct soc_camera_device *icd, u32 width, u32 height)
425+static const struct tw9910_scale_ctrl *tw9910_select_norm(v4l2_std_id norm,
426+ u32 width, u32 height)
438427 {
439428 const struct tw9910_scale_ctrl *scale;
440429 const struct tw9910_scale_ctrl *ret = NULL;
441− v4l2_std_id norm = icd->vdev->current_norm;
442430 __u32 diff = 0xffffffff, tmp;
443431 int size, i;
444432
@@ -465,7 +453,7 @@ tw9910_select_norm(struct soc_camera_device *icd, u32 width, u32 height) · 20 unmodified lines
465453 }
466454
467455 /*
468− * soc_camera_ops function
456+ * subdevice operations
469457 */
470458 static int tw9910_s_stream(struct v4l2_subdev *sd, int enable)
471459 {
@@ -507,49 +495,27 @@ static int tw9910_s_stream(struct v4l2_subdev *sd, int enable) · 35 unmodified lines
507495 return tw9910_power(client, enable);
508496 }
509497
510−static int tw9910_set_bus_param(struct soc_camera_device *icd,
511− unsigned long flags)
498+static int tw9910_g_std(struct v4l2_subdev *sd, v4l2_std_id *norm)
512499 {
513− struct v4l2_subdev *sd = soc_camera_to_subdev(icd);
514500 struct i2c_client *client = v4l2_get_subdevdata(sd);
515− u8 val = VSSL_VVALID | HSSL_DVALID;
501+ struct tw9910_priv *priv = to_tw9910(client);
516502
517− /*
518− * set OUTCTR1
519− *
520− * We use VVALID and DVALID signals to control VSYNC and HSYNC
521− * outputs, in this mode their polarity is inverted.
522− */
523− if (flags & SOCAM_HSYNC_ACTIVE_LOW)
524− val |= HSP_HI;
503+ *norm = priv->norm;
525504
526− if (flags & SOCAM_VSYNC_ACTIVE_LOW)
527− val |= VSP_HI;
528−
529− return i2c_smbus_write_byte_data(client, OUTCTR1, val);
505+ return 0;
530506 }
531507
532−static unsigned long tw9910_query_bus_param(struct soc_camera_device *icd)
508+static int tw9910_s_std(struct v4l2_subdev *sd, v4l2_std_id norm)
533509 {
534− struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
510+ struct i2c_client *client = v4l2_get_subdevdata(sd);
535511 struct tw9910_priv *priv = to_tw9910(client);
536− struct soc_camera_link *icl = to_soc_camera_link(icd);
537− unsigned long flags = SOCAM_PCLK_SAMPLE_RISING | SOCAM_MASTER |
538− SOCAM_VSYNC_ACTIVE_HIGH | SOCAM_HSYNC_ACTIVE_HIGH |
539− SOCAM_VSYNC_ACTIVE_LOW | SOCAM_HSYNC_ACTIVE_LOW |
540− SOCAM_DATA_ACTIVE_HIGH | priv->info->buswidth;
541512
542− return soc_camera_apply_sensor_flags(icl, flags);
543−}
544−
545−static int tw9910_s_std(struct v4l2_subdev *sd, v4l2_std_id norm)
546−{
547− int ret = -EINVAL;
513+ if (!(norm & (V4L2_STD_NTSC | V4L2_STD_PAL)))
514+ return -EINVAL;
548515
549− if (norm & (V4L2_STD_NTSC | V4L2_STD_PAL))
550− ret = 0;
516+ priv->norm = norm;
551517
552− return ret;
518+ return 0;
553519 }
554520
555521 static int tw9910_g_chip_ident(struct v4l2_subdev *sd,
@@ -600,19 +566,17 @@ static int tw9910_s_register(struct v4l2_subdev *sd, · 44 unmodified lines
600566 }
601567 #endif
602568
603−static int tw9910_s_crop(struct v4l2_subdev *sd, struct v4l2_crop *a)
569+static int tw9910_set_frame(struct v4l2_subdev *sd, u32 *width, u32 *height)
604570 {
605− struct v4l2_rect *rect = &a->c;
606571 struct i2c_client *client = v4l2_get_subdevdata(sd);
607572 struct tw9910_priv *priv = to_tw9910(client);
608− struct soc_camera_device *icd = client->dev.platform_data;
609− int ret = -EINVAL;
610− u8 val;
573+ int ret = -EINVAL;
574+ u8 val;
611575
612576 /*
613577 * select suitable norm
614578 */
615− priv->scale = tw9910_select_norm(icd, rect->width, rect->height);
579+ priv->scale = tw9910_select_norm(priv->norm, *width, *height);
616580 if (!priv->scale)
617581 goto tw9910_set_fmt_error;
618582
@@ -670,14 +634,12 @@ static int tw9910_s_crop(struct v4l2_subdev *sd, struct v4l2_crop *a) · 51 unmodified lines
670634 /*
671635 * set hsync
672636 */
673− ret = tw9910_set_hsync(client, &tw9910_hsync_ctrl);
637+ ret = tw9910_set_hsync(client);
674638 if (ret < 0)
675639 goto tw9910_set_fmt_error;
676640
677− rect->width = priv->scale->width;
678− rect->height = priv->scale->height;
679− rect->left = 0;
680− rect->top = 0;
641+ *width = priv->scale->width;
642+ *height = priv->scale->height;
681643
682644 return ret;
683645
@@ -694,25 +656,15 @@ static int tw9910_g_crop(struct v4l2_subdev *sd, struct v4l2_crop *a) · 10 unmodified lines
694656 struct i2c_client *client = v4l2_get_subdevdata(sd);
695657 struct tw9910_priv *priv = to_tw9910(client);
696658
697− if (!priv->scale) {
698− int ret;
699− struct v4l2_crop crop = {
700− .c = {
701− .left = 0,
702− .top = 0,
703− .width = 640,
704− .height = 480,
705− },
706− };
707− ret = tw9910_s_crop(sd, &crop);
708− if (ret < 0)
709− return ret;
710− }
711−
712659 a->c.left = 0;
713660 a->c.top = 0;
714− a->c.width = priv->scale->width;
715− a->c.height = priv->scale->height;
661+ if (priv->norm & V4L2_STD_NTSC) {
662+ a->c.width = 640;
663+ a->c.height = 480;
664+ } else {
665+ a->c.width = 768;
666+ a->c.height = 576;
667+ }
716668 a->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
717669
718670 return 0;
@@ -720,14 +672,19 @@ static int tw9910_g_crop(struct v4l2_subdev *sd, struct v4l2_crop *a) · 1 unmodified line
720672
721673 static int tw9910_cropcap(struct v4l2_subdev *sd, struct v4l2_cropcap *a)
722674 {
675+ struct i2c_client *client = v4l2_get_subdevdata(sd);
676+ struct tw9910_priv *priv = to_tw9910(client);
677+
723678 a->bounds.left = 0;
724679 a->bounds.top = 0;
725− a->bounds.width = 768;
726− a->bounds.height = 576;
727− a->defrect.left = 0;
728− a->defrect.top = 0;
729− a->defrect.width = 640;
730− a->defrect.height = 480;
680+ if (priv->norm & V4L2_STD_NTSC) {
681+ a->bounds.width = 640;
682+ a->bounds.height = 480;
683+ } else {
684+ a->bounds.width = 768;
685+ a->bounds.height = 576;
686+ }
687+ a->defrect = a->bounds;
731688 a->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
732689 a->pixelaspect.numerator = 1;
733690 a->pixelaspect.denominator = 1;
@@ -743,15 +700,8 @@ static int tw9910_g_fmt(struct v4l2_subdev *sd, · 9 unmodified lines
743700
744701 if (!priv->scale) {
745702 int ret;
746− struct v4l2_crop crop = {
747− .c = {
748− .left = 0,
749− .top = 0,
750− .width = 640,
751− .height = 480,
752− },
753− };
754− ret = tw9910_s_crop(sd, &crop);
703+ u32 width = 640, height = 480;
704+ ret = tw9910_set_frame(sd, &width, &height);
755705 if (ret < 0)
756706 return ret;
757707 }
@@ -768,17 +718,7 @@ static int tw9910_g_fmt(struct v4l2_subdev *sd, · 10 unmodified lines
768718 static int tw9910_s_fmt(struct v4l2_subdev *sd,
769719 struct v4l2_mbus_framefmt *mf)
770720 {
771− struct i2c_client *client = v4l2_get_subdevdata(sd);
772− struct tw9910_priv *priv = to_tw9910(client);
773− /* See tw9910_s_crop() - no proper cropping support */
774− struct v4l2_crop a = {
775− .c = {
776− .left = 0,
777− .top = 0,
778− .width = mf->width,
779− .height = mf->height,
780− },
781− };
721+ u32 width = mf->width, height = mf->height;
782722 int ret;
783723
784724 WARN_ON(mf->field != V4L2_FIELD_ANY &&
@@ -792,10 +732,10 @@ static int tw9910_s_fmt(struct v4l2_subdev *sd, · 7 unmodified lines
792732
793733 mf->colorspace = V4L2_COLORSPACE_JPEG;
794734
795− ret = tw9910_s_crop(sd, &a);
735+ ret = tw9910_set_frame(sd, &width, &height);
796736 if (!ret) {
797− mf->width = priv->scale->width;
798− mf->height = priv->scale->height;
737+ mf->width = width;
738+ mf->height = height;
799739 }
800740 return ret;
801741 }
@@ -804,7 +744,7 @@ static int tw9910_try_fmt(struct v4l2_subdev *sd, · 2 unmodified lines
804744 struct v4l2_mbus_framefmt *mf)
805745 {
806746 struct i2c_client *client = v4l2_get_subdevdata(sd);
807− struct soc_camera_device *icd = client->dev.platform_data;
747+ struct tw9910_priv *priv = to_tw9910(client);
808748 const struct tw9910_scale_ctrl *scale;
809749
810750 if (V4L2_FIELD_ANY == mf->field) {
@@ -820,7 +760,7 @@ static int tw9910_try_fmt(struct v4l2_subdev *sd, · 9 unmodified lines
820760 /*
821761 * select suitable norm
822762 */
823− scale = tw9910_select_norm(icd, mf->width, mf->height);
763+ scale = tw9910_select_norm(priv->norm, mf->width, mf->height);
824764 if (!scale)
825765 return -EINVAL;
826766
@@ -830,16 +770,11 @@ static int tw9910_try_fmt(struct v4l2_subdev *sd, · 3 unmodified lines
830770 return 0;
831771 }
832772
833−static int tw9910_video_probe(struct soc_camera_device *icd,
834− struct i2c_client *client)
773+static int tw9910_video_probe(struct i2c_client *client)
835774 {
836775 struct tw9910_priv *priv = to_tw9910(client);
837776 s32 id;
838777
839− /* We must have a parent by now. And it cannot be a wrong one. */
840− BUG_ON(!icd->parent ||
841− to_soc_camera_host(icd->parent)->nr != icd->iface);
842−
843778 /*
844779 * tw9910 only use 8 or 16 bit bus width
845780 */
@@ -868,20 +803,15 @@ static int tw9910_video_probe(struct soc_camera_device *icd, · 22 unmodified lines
868803 dev_info(&client->dev,
869804 "tw9910 Product ID %0x:%0x\n", id, priv->revision);
870805
871− icd->vdev->tvnorms = V4L2_STD_NTSC | V4L2_STD_PAL;
872− icd->vdev->current_norm = V4L2_STD_NTSC;
806+ priv->norm = V4L2_STD_NTSC;
873807
874808 return 0;
875809 }
876810
877−static struct soc_camera_ops tw9910_ops = {
878− .set_bus_param = tw9910_set_bus_param,
879− .query_bus_param = tw9910_query_bus_param,
880−};
881−
882811 static struct v4l2_subdev_core_ops tw9910_subdev_core_ops = {
883812 .g_chip_ident = tw9910_g_chip_ident,
884813 .s_std = tw9910_s_std,
814+ .g_std = tw9910_g_std,
885815 #ifdef CONFIG_VIDEO_ADV_DEBUG
886816 .g_register = tw9910_g_register,
887817 .s_register = tw9910_s_register,
@@ -898,6 +828,45 @@ static int tw9910_enum_fmt(struct v4l2_subdev *sd, unsigned int index, · 10 unmodified lines
898828 return 0;
899829 }
900830
831+static int tw9910_g_mbus_config(struct v4l2_subdev *sd,
832+ struct v4l2_mbus_config *cfg)
833+{
834+ struct i2c_client *client = v4l2_get_subdevdata(sd);
835+ struct soc_camera_link *icl = soc_camera_i2c_to_link(client);
836+
837+ cfg->flags = V4L2_MBUS_PCLK_SAMPLE_RISING | V4L2_MBUS_MASTER |
838+ V4L2_MBUS_VSYNC_ACTIVE_HIGH | V4L2_MBUS_VSYNC_ACTIVE_LOW |
839+ V4L2_MBUS_HSYNC_ACTIVE_HIGH | V4L2_MBUS_HSYNC_ACTIVE_LOW |
840+ V4L2_MBUS_DATA_ACTIVE_HIGH;
841+ cfg->type = V4L2_MBUS_PARALLEL;
842+ cfg->flags = soc_camera_apply_board_flags(icl, cfg);
843+
844+ return 0;
845+}
846+
847+static int tw9910_s_mbus_config(struct v4l2_subdev *sd,
848+ const struct v4l2_mbus_config *cfg)
849+{
850+ struct i2c_client *client = v4l2_get_subdevdata(sd);
851+ struct soc_camera_link *icl = soc_camera_i2c_to_link(client);
852+ u8 val = VSSL_VVALID | HSSL_DVALID;
853+ unsigned long flags = soc_camera_apply_board_flags(icl, cfg);
854+
855+ /*
856+ * set OUTCTR1
857+ *
858+ * We use VVALID and DVALID signals to control VSYNC and HSYNC
859+ * outputs, in this mode their polarity is inverted.
860+ */
861+ if (flags & V4L2_MBUS_HSYNC_ACTIVE_LOW)
862+ val |= HSP_HI;
863+
864+ if (flags & V4L2_MBUS_VSYNC_ACTIVE_LOW)
865+ val |= VSP_HI;
866+
867+ return i2c_smbus_write_byte_data(client, OUTCTR1, val);
868+}
869+
901870 static struct v4l2_subdev_video_ops tw9910_subdev_video_ops = {
902871 .s_stream = tw9910_s_stream,
903872 .g_mbus_fmt = tw9910_g_fmt,
@@ -905,8 +874,9 @@ static struct v4l2_subdev_video_ops tw9910_subdev_video_ops = { · 1 unmodified line
905874 .try_mbus_fmt = tw9910_try_fmt,
906875 .cropcap = tw9910_cropcap,
907876 .g_crop = tw9910_g_crop,
908− .s_crop = tw9910_s_crop,
909877 .enum_mbus_fmt = tw9910_enum_fmt,
878+ .g_mbus_config = tw9910_g_mbus_config,
879+ .s_mbus_config = tw9910_s_mbus_config,
910880 };
911881
912882 static struct v4l2_subdev_ops tw9910_subdev_ops = {
@@ -922,23 +892,18 @@ static int tw9910_probe(struct i2c_client *client, · 9 unmodified lines
922892 const struct i2c_device_id *did)
923893
924894 {
925− struct tw9910_priv *priv;
926− struct tw9910_video_info *info;
927− struct soc_camera_device *icd = client->dev.platform_data;
928− struct i2c_adapter *adapter =
895+ struct tw9910_priv *priv;
896+ struct tw9910_video_info *info;
897+ struct i2c_adapter *adapter =
929898 to_i2c_adapter(client->dev.parent);
930− struct soc_camera_link *icl;
931− int ret;
899+ struct soc_camera_link *icl = soc_camera_i2c_to_link(client);
900+ int ret;
932901
933− if (!icd) {
934− dev_err(&client->dev, "TW9910: missing soc-camera data!\n");
902+ if (!icl || !icl->priv) {
903+ dev_err(&client->dev, "TW9910: missing platform data!\n");
935904 return -EINVAL;
936905 }
937906
938− icl = to_soc_camera_link(icd);
939− if (!icl || !icl->priv)
940− return -EINVAL;
941−
942907 info = icl->priv;
943908
944909 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) {
@@ -956,14 +921,9 @@ static int tw9910_probe(struct i2c_client *client, · 11 unmodified lines
956921
957922 v4l2_i2c_subdev_init(&priv->subdev, client, &tw9910_subdev_ops);
958923
959− icd->ops = &tw9910_ops;
960− icd->iface = icl->bus_id;
961−
962− ret = tw9910_video_probe(icd, client);
963− if (ret) {
964− icd->ops = NULL;
924+ ret = tw9910_video_probe(client);
925+ if (ret)
965926 kfree(priv);
966− }
967927
968928 return ret;
969929 }
@@ -971,9 +931,7 @@ static int tw9910_probe(struct i2c_client *client, · 1 unmodified line
971931 static int tw9910_remove(struct i2c_client *client)
972932 {
973933 struct tw9910_priv *priv = to_tw9910(client);
974− struct soc_camera_device *icd = client->dev.platform_data;
975934
976− icd->ops = NULL;
977935 kfree(priv);
978936 return 0;
979937 }
drivers/media/video/v4l2-compat-ioctl32.c+68−8
@@ -159,11 +159,25 @@ struct v4l2_format32 { · 158 unmodified lines
159159 } fmt;
160160 };
161161
162−static int get_v4l2_format32(struct v4l2_format *kp, struct v4l2_format32 __user *up)
162+/**
163+ * struct v4l2_create_buffers32 - VIDIOC_CREATE_BUFS32 argument
164+ * @index: on return, index of the first created buffer
165+ * @count: entry: number of requested buffers,
166+ * return: number of created buffers
167+ * @memory: buffer memory type
168+ * @format: frame format, for which buffers are requested
169+ * @reserved: future extensions
170+ */
171+struct v4l2_create_buffers32 {
172+ __u32 index;
173+ __u32 count;
174+ enum v4l2_memory memory;
175+ struct v4l2_format32 format;
176+ __u32 reserved[8];
177+};
178+
179+static int __get_v4l2_format32(struct v4l2_format *kp, struct v4l2_format32 __user *up)
163180 {
164− if (!access_ok(VERIFY_READ, up, sizeof(struct v4l2_format32)) ||
165− get_user(kp->type, &up->type))
166− return -EFAULT;
167181 switch (kp->type) {
168182 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
169183 case V4L2_BUF_TYPE_VIDEO_OUTPUT:
@@ -192,11 +206,24 @@ static int get_v4l2_format32(struct v4l2_format *kp, struct v4l2_format32 __user · 22 unmodified lines
192206 }
193207 }
194208
195−static int put_v4l2_format32(struct v4l2_format *kp, struct v4l2_format32 __user *up)
209+static int get_v4l2_format32(struct v4l2_format *kp, struct v4l2_format32 __user *up)
210+{
211+ if (!access_ok(VERIFY_READ, up, sizeof(struct v4l2_format32)) ||
212+ get_user(kp->type, &up->type))
213+ return -EFAULT;
214+ return __get_v4l2_format32(kp, up);
215+}
216+
217+static int get_v4l2_create32(struct v4l2_create_buffers *kp, struct v4l2_create_buffers32 __user *up)
218+{
219+ if (!access_ok(VERIFY_READ, up, sizeof(struct v4l2_create_buffers32)) ||
220+ copy_from_user(kp, up, offsetof(struct v4l2_create_buffers32, format.fmt)))
221+ return -EFAULT;
222+ return __get_v4l2_format32(&kp->format, &up->format);
223+}
224+
225+static int __put_v4l2_format32(struct v4l2_format *kp, struct v4l2_format32 __user *up)
196226 {
197− if (!access_ok(VERIFY_WRITE, up, sizeof(struct v4l2_format32)) ||
198− put_user(kp->type, &up->type))
199− return -EFAULT;
200227 switch (kp->type) {
201228 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
202229 case V4L2_BUF_TYPE_VIDEO_OUTPUT:
@@ -225,6 +252,22 @@ static int put_v4l2_format32(struct v4l2_format *kp, struct v4l2_format32 __user · 22 unmodified lines
225252 }
226253 }
227254
255+static int put_v4l2_format32(struct v4l2_format *kp, struct v4l2_format32 __user *up)
256+{
257+ if (!access_ok(VERIFY_WRITE, up, sizeof(struct v4l2_format32)) ||
258+ put_user(kp->type, &up->type))
259+ return -EFAULT;
260+ return __put_v4l2_format32(kp, up);
261+}
262+
263+static int put_v4l2_create32(struct v4l2_create_buffers *kp, struct v4l2_create_buffers32 __user *up)
264+{
265+ if (!access_ok(VERIFY_WRITE, up, sizeof(struct v4l2_create_buffers32)) ||
266+ copy_to_user(up, kp, offsetof(struct v4l2_create_buffers32, format.fmt)))
267+ return -EFAULT;
268+ return __put_v4l2_format32(&kp->format, &up->format);
269+}
270+
228271 struct v4l2_standard32 {
229272 __u32 index;
230273 __u32 id[2]; /* __u64 would get the alignment wrong */
@@ -702,6 +745,8 @@ static int put_v4l2_event32(struct v4l2_event *kp, struct v4l2_event32 __user *u · 471 unmodified lines
702745 #define VIDIOC_S_EXT_CTRLS32 _IOWR('V', 72, struct v4l2_ext_controls32)
703746 #define VIDIOC_TRY_EXT_CTRLS32 _IOWR('V', 73, struct v4l2_ext_controls32)
704747 #define VIDIOC_DQEVENT32 _IOR ('V', 89, struct v4l2_event32)
748+#define VIDIOC_CREATE_BUFS32 _IOWR('V', 92, struct v4l2_create_buffers32)
749+#define VIDIOC_PREPARE_BUF32 _IOWR('V', 93, struct v4l2_buffer32)
705750
706751 #define VIDIOC_OVERLAY32 _IOW ('V', 14, s32)
707752 #define VIDIOC_STREAMON32 _IOW ('V', 18, s32)
@@ -721,6 +766,7 @@ static long do_video_ioctl(struct file *file, unsigned int cmd, unsigned long ar · 13 unmodified lines
721766 struct v4l2_standard v2s;
722767 struct v4l2_ext_controls v2ecs;
723768 struct v4l2_event v2ev;
769+ struct v4l2_create_buffers v2crt;
724770 unsigned long vx;
725771 int vi;
726772 } karg;
@@ -751,6 +797,8 @@ static long do_video_ioctl(struct file *file, unsigned int cmd, unsigned long ar · 24 unmodified lines
751797 case VIDIOC_S_INPUT32: cmd = VIDIOC_S_INPUT; break;
752798 case VIDIOC_G_OUTPUT32: cmd = VIDIOC_G_OUTPUT; break;
753799 case VIDIOC_S_OUTPUT32: cmd = VIDIOC_S_OUTPUT; break;
800+ case VIDIOC_CREATE_BUFS32: cmd = VIDIOC_CREATE_BUFS; break;
801+ case VIDIOC_PREPARE_BUF32: cmd = VIDIOC_PREPARE_BUF; break;
754802 }
755803
756804 switch (cmd) {
@@ -775,6 +823,12 @@ static long do_video_ioctl(struct file *file, unsigned int cmd, unsigned long ar · 18 unmodified lines
775823 compatible_arg = 0;
776824 break;
777825
826+ case VIDIOC_CREATE_BUFS:
827+ err = get_v4l2_create32(&karg.v2crt, up);
828+ compatible_arg = 0;
829+ break;
830+
831+ case VIDIOC_PREPARE_BUF:
778832 case VIDIOC_QUERYBUF:
779833 case VIDIOC_QBUF:
780834 case VIDIOC_DQBUF:
@@ -860,6 +914,10 @@ static long do_video_ioctl(struct file *file, unsigned int cmd, unsigned long ar · 79 unmodified lines
860914 err = put_v4l2_format32(&karg.v2f, up);
861915 break;
862916
917+ case VIDIOC_CREATE_BUFS:
918+ err = put_v4l2_create32(&karg.v2crt, up);
919+ break;
920+
863921 case VIDIOC_QUERYBUF:
864922 case VIDIOC_QBUF:
865923 case VIDIOC_DQBUF:
@@ -959,6 +1017,8 @@ long v4l2_compat_ioctl32(struct file *file, unsigned int cmd, unsigned long arg) · 93 unmodified lines
9591017 case VIDIOC_DQEVENT32:
9601018 case VIDIOC_SUBSCRIBE_EVENT:
9611019 case VIDIOC_UNSUBSCRIBE_EVENT:
1020+ case VIDIOC_CREATE_BUFS32:
1021+ case VIDIOC_PREPARE_BUF32:
9621022 ret = do_video_ioctl(file, cmd, arg);
9631023 break;
9641024
drivers/media/video/v4l2-ctrls.c+1−0
@@ -210,6 +210,7 @@ const char * const *v4l2_ctrl_get_menu(u32 id) · 209 unmodified lines
210210 "Disabled",
211211 "50 Hz",
212212 "60 Hz",
213+ "Auto",
213214 NULL
214215 };
215216 static const char * const camera_exposure_auto[] = {
drivers/media/video/v4l2-device.c+31−5
@@ -21,6 +21,7 @@ · 20 unmodified lines
2121 #include <linux/types.h>
2222 #include <linux/ioctl.h>
2323 #include <linux/i2c.h>
24+#include <linux/slab.h>
2425 #if defined(CONFIG_SPI)
2526 #include <linux/spi/spi.h>
2627 #endif
@@ -193,6 +194,13 @@ int v4l2_device_register_subdev(struct v4l2_device *v4l2_dev, · 166 unmodified lines
193194 }
194195 EXPORT_SYMBOL_GPL(v4l2_device_register_subdev);
195196
197+static void v4l2_device_release_subdev_node(struct video_device *vdev)
198+{
199+ struct v4l2_subdev *sd = video_get_drvdata(vdev);
200+ sd->devnode = NULL;
201+ kfree(vdev);
202+}
203+
196204 int v4l2_device_register_subdev_nodes(struct v4l2_device *v4l2_dev)
197205 {
198206 struct video_device *vdev;
@@ -206,22 +214,40 @@ int v4l2_device_register_subdev_nodes(struct v4l2_device *v4l2_dev) · 7 unmodified lines
206214 if (!(sd->flags & V4L2_SUBDEV_FL_HAS_DEVNODE))
207215 continue;
208216
209− vdev = &sd->devnode;
217+ vdev = kzalloc(sizeof(*vdev), GFP_KERNEL);
218+ if (!vdev) {
219+ err = -ENOMEM;
220+ goto clean_up;
221+ }
222+
223+ video_set_drvdata(vdev, sd);
210224 strlcpy(vdev->name, sd->name, sizeof(vdev->name));
211225 vdev->v4l2_dev = v4l2_dev;
212226 vdev->fops = &v4l2_subdev_fops;
213− vdev->release = video_device_release_empty;
227+ vdev->release = v4l2_device_release_subdev_node;
214228 vdev->ctrl_handler = sd->ctrl_handler;
215229 err = __video_register_device(vdev, VFL_TYPE_SUBDEV, -1, 1,
216230 sd->owner);
217− if (err < 0)
218− return err;
231+ if (err < 0) {
232+ kfree(vdev);
233+ goto clean_up;
234+ }
219235 #if defined(CONFIG_MEDIA_CONTROLLER)
220236 sd->entity.v4l.major = VIDEO_MAJOR;
221237 sd->entity.v4l.minor = vdev->minor;
222238 #endif
239+ sd->devnode = vdev;
223240 }
224241 return 0;
242+
243+clean_up:
244+ list_for_each_entry(sd, &v4l2_dev->subdevs, list) {
245+ if (!sd->devnode)
246+ break;
247+ video_unregister_device(sd->devnode);
248+ }
249+
250+ return err;
225251 }
226252 EXPORT_SYMBOL_GPL(v4l2_device_register_subdev_nodes);
227253
@@ -247,7 +273,7 @@ void v4l2_device_unregister_subdev(struct v4l2_subdev *sd) · 19 unmodified lines
247273 if (v4l2_dev->mdev)
248274 media_device_unregister_entity(&sd->entity);
249275 #endif
250− video_unregister_device(&sd->devnode);
276+ video_unregister_device(sd->devnode);
251277 module_put(sd->owner);
252278 }
253279 EXPORT_SYMBOL_GPL(v4l2_device_unregister_subdev);
drivers/media/video/v4l2-ioctl.c+36−0
@@ -273,6 +273,8 @@ static const char *v4l2_ioctls[] = { · 272 unmodified lines
273273 [_IOC_NR(VIDIOC_DQEVENT)] = "VIDIOC_DQEVENT",
274274 [_IOC_NR(VIDIOC_SUBSCRIBE_EVENT)] = "VIDIOC_SUBSCRIBE_EVENT",
275275 [_IOC_NR(VIDIOC_UNSUBSCRIBE_EVENT)] = "VIDIOC_UNSUBSCRIBE_EVENT",
276+ [_IOC_NR(VIDIOC_CREATE_BUFS)] = "VIDIOC_CREATE_BUFS",
277+ [_IOC_NR(VIDIOC_PREPARE_BUF)] = "VIDIOC_PREPARE_BUF",
276278 };
277279 #define V4L2_IOCTLS ARRAY_SIZE(v4l2_ioctls)
278280
@@ -2104,6 +2106,40 @@ static long __video_do_ioctl(struct file *file, · 1825 unmodified lines
21042106 dbgarg(cmd, "type=0x%8.8x", sub->type);
21052107 break;
21062108 }
2109+ case VIDIOC_CREATE_BUFS:
2110+ {
2111+ struct v4l2_create_buffers *create = arg;
2112+
2113+ if (!ops->vidioc_create_bufs)
2114+ break;
2115+ if (ret_prio) {
2116+ ret = ret_prio;
2117+ break;
2118+ }
2119+ ret = check_fmt(ops, create->format.type);
2120+ if (ret)
2121+ break;
2122+
2123+ ret = ops->vidioc_create_bufs(file, fh, create);
2124+
2125+ dbgarg(cmd, "count=%d @ %d\n", create->count, create->index);
2126+ break;
2127+ }
2128+ case VIDIOC_PREPARE_BUF:
2129+ {
2130+ struct v4l2_buffer *b = arg;
2131+
2132+ if (!ops->vidioc_prepare_buf)
2133+ break;
2134+ ret = check_fmt(ops, b->type);
2135+ if (ret)
2136+ break;
2137+
2138+ ret = ops->vidioc_prepare_buf(file, fh, b);
2139+
2140+ dbgarg(cmd, "index=%d", b->index);
2141+ break;
2142+ }
21072143 default:
21082144 if (!ops->vidioc_default)
21092145 break;
drivers/media/video/videobuf2-core.c+321−70
@@ -38,7 +38,8 @@ module_param(debug, int, 0644); · 37 unmodified lines
3838 (((q)->ops->op) ? ((q)->ops->op(args)) : 0)
3939
4040 #define V4L2_BUFFER_STATE_FLAGS (V4L2_BUF_FLAG_MAPPED | V4L2_BUF_FLAG_QUEUED | \
41− V4L2_BUF_FLAG_DONE | V4L2_BUF_FLAG_ERROR)
41+ V4L2_BUF_FLAG_DONE | V4L2_BUF_FLAG_ERROR | \
42+ V4L2_BUF_FLAG_PREPARED)
4243
4344 /**
4445 * __vb2_buf_mem_alloc() - allocate video memory for the given buffer
@@ -109,13 +110,22 @@ static void __vb2_buf_userptr_put(struct vb2_buffer *vb) · 64 unmodified lines
109110 * __setup_offsets() - setup unique offsets ("cookies") for every plane in
110111 * every buffer on the queue
111112 */
112−static void __setup_offsets(struct vb2_queue *q)
113+static void __setup_offsets(struct vb2_queue *q, unsigned int n)
113114 {
114115 unsigned int buffer, plane;
115116 struct vb2_buffer *vb;
116− unsigned long off = 0;
117+ unsigned long off;
117118
118− for (buffer = 0; buffer < q->num_buffers; ++buffer) {
119+ if (q->num_buffers) {
120+ struct v4l2_plane *p;
121+ vb = q->bufs[q->num_buffers - 1];
122+ p = &vb->v4l2_planes[vb->num_planes - 1];
123+ off = PAGE_ALIGN(p->m.mem_offset + p->length);
124+ } else {
125+ off = 0;
126+ }
127+
128+ for (buffer = q->num_buffers; buffer < q->num_buffers + n; ++buffer) {
119129 vb = q->bufs[buffer];
120130 if (!vb)
121131 continue;
@@ -161,7 +171,7 @@ static int __vb2_queue_alloc(struct vb2_queue *q, enum v4l2_memory memory, · 39 unmodified lines
161171 vb->state = VB2_BUF_STATE_DEQUEUED;
162172 vb->vb2_queue = q;
163173 vb->num_planes = num_planes;
164− vb->v4l2_buf.index = buffer;
174+ vb->v4l2_buf.index = q->num_buffers + buffer;
165175 vb->v4l2_buf.type = q->type;
166176 vb->v4l2_buf.memory = memory;
167177
@@ -189,15 +199,13 @@ static int __vb2_queue_alloc(struct vb2_queue *q, enum v4l2_memory memory, · 21 unmodified lines
189199 }
190200 }
191201
192− q->bufs[buffer] = vb;
202+ q->bufs[q->num_buffers + buffer] = vb;
193203 }
194204
195− q->num_buffers = buffer;
196−
197− __setup_offsets(q);
205+ __setup_offsets(q, buffer);
198206
199207 dprintk(1, "Allocated %d buffers, %d plane(s) each\n",
200− q->num_buffers, num_planes);
208+ buffer, num_planes);
201209
202210 return buffer;
203211 }
@@ -205,12 +213,13 @@ static int __vb2_queue_alloc(struct vb2_queue *q, enum v4l2_memory memory, · 1 unmodified line
205213 /**
206214 * __vb2_free_mem() - release all video buffer memory for a given queue
207215 */
208−static void __vb2_free_mem(struct vb2_queue *q)
216+static void __vb2_free_mem(struct vb2_queue *q, unsigned int buffers)
209217 {
210218 unsigned int buffer;
211219 struct vb2_buffer *vb;
212220
213− for (buffer = 0; buffer < q->num_buffers; ++buffer) {
221+ for (buffer = q->num_buffers - buffers; buffer < q->num_buffers;
222+ ++buffer) {
214223 vb = q->bufs[buffer];
215224 if (!vb)
216225 continue;
@@ -224,17 +233,18 @@ static void __vb2_free_mem(struct vb2_queue *q) · 7 unmodified lines
224233 }
225234
226235 /**
227− * __vb2_queue_free() - free the queue - video memory and related information
228− * and return the queue to an uninitialized state. Might be called even if the
229− * queue has already been freed.
236+ * __vb2_queue_free() - free buffers at the end of the queue - video memory and
237+ * related information, if no buffers are left return the queue to an
238+ * uninitialized state. Might be called even if the queue has already been freed.
230239 */
231−static void __vb2_queue_free(struct vb2_queue *q)
240+static void __vb2_queue_free(struct vb2_queue *q, unsigned int buffers)
232241 {
233242 unsigned int buffer;
234243
235244 /* Call driver-provided cleanup function for each buffer, if provided */
236245 if (q->ops->buf_cleanup) {
237− for (buffer = 0; buffer < q->num_buffers; ++buffer) {
246+ for (buffer = q->num_buffers - buffers; buffer < q->num_buffers;
247+ ++buffer) {
238248 if (NULL == q->bufs[buffer])
239249 continue;
240250 q->ops->buf_cleanup(q->bufs[buffer]);
@@ -242,23 +252,25 @@ static void __vb2_queue_free(struct vb2_queue *q) · 1 unmodified line
242252 }
243253
244254 /* Release video buffer memory */
245− __vb2_free_mem(q);
255+ __vb2_free_mem(q, buffers);
246256
247257 /* Free videobuf buffers */
248− for (buffer = 0; buffer < q->num_buffers; ++buffer) {
258+ for (buffer = q->num_buffers - buffers; buffer < q->num_buffers;
259+ ++buffer) {
249260 kfree(q->bufs[buffer]);
250261 q->bufs[buffer] = NULL;
251262 }
252263
253− q->num_buffers = 0;
254− q->memory = 0;
264+ q->num_buffers -= buffers;
265+ if (!q->num_buffers)
266+ q->memory = 0;
255267 }
256268
257269 /**
258270 * __verify_planes_array() - verify that the planes array passed in struct
259271 * v4l2_buffer from userspace can be safely used
260272 */
261−static int __verify_planes_array(struct vb2_buffer *vb, struct v4l2_buffer *b)
273+static int __verify_planes_array(struct vb2_buffer *vb, const struct v4l2_buffer *b)
262274 {
263275 /* Is memory for copying plane information present? */
264276 if (NULL == b->m.planes) {
@@ -318,7 +330,7 @@ static bool __buffers_in_use(struct vb2_queue *q) · 53 unmodified lines
318330 static int __fill_v4l2_buffer(struct vb2_buffer *vb, struct v4l2_buffer *b)
319331 {
320332 struct vb2_queue *q = vb->vb2_queue;
321− int ret = 0;
333+ int ret;
322334
323335 /* Copy back data such as timestamp, flags, input, etc. */
324336 memcpy(b, &vb->v4l2_buf, offsetof(struct v4l2_buffer, m));
@@ -365,6 +377,9 @@ static int __fill_v4l2_buffer(struct vb2_buffer *vb, struct v4l2_buffer *b) · 40 unmodified lines
365377 case VB2_BUF_STATE_DONE:
366378 b->flags |= V4L2_BUF_FLAG_DONE;
367379 break;
380+ case VB2_BUF_STATE_PREPARED:
381+ b->flags |= V4L2_BUF_FLAG_PREPARED;
382+ break;
368383 case VB2_BUF_STATE_DEQUEUED:
369384 /* nothing */
370385 break;
@@ -373,7 +388,7 @@ static int __fill_v4l2_buffer(struct vb2_buffer *vb, struct v4l2_buffer *b) · 2 unmodified lines
373388 if (__buffer_in_use(q, vb))
374389 b->flags |= V4L2_BUF_FLAG_MAPPED;
375390
376− return ret;
391+ return 0;
377392 }
378393
379394 /**
@@ -459,7 +474,7 @@ static int __verify_mmap_ops(struct vb2_queue *q) · 79 unmodified lines
459474 */
460475 int vb2_reqbufs(struct vb2_queue *q, struct v4l2_requestbuffers *req)
461476 {
462− unsigned int num_buffers, num_planes;
477+ unsigned int num_buffers, allocated_buffers, num_planes = 0;
463478 int ret = 0;
464479
465480 if (q->fileio) {
@@ -507,7 +522,7 @@ int vb2_reqbufs(struct vb2_queue *q, struct v4l2_requestbuffers *req) · 41 unmodified lines
507522 return -EBUSY;
508523 }
509524
510− __vb2_queue_free(q);
525+ __vb2_queue_free(q, q->num_buffers);
511526
512527 /*
513528 * In case of REQBUFS(0) return immediately without calling
@@ -529,7 +544,7 @@ int vb2_reqbufs(struct vb2_queue *q, struct v4l2_requestbuffers *req) · 15 unmodified lines
529544 * Ask the driver how many buffers and planes per buffer it requires.
530545 * Driver also sets the size and allocator context for each plane.
531546 */
532− ret = call_qop(q, queue_setup, q, &num_buffers, &num_planes,
547+ ret = call_qop(q, queue_setup, q, NULL, &num_buffers, &num_planes,
533548 q->plane_sizes, q->alloc_ctx);
534549 if (ret)
535550 return ret;
@@ -541,43 +556,167 @@ int vb2_reqbufs(struct vb2_queue *q, struct v4l2_requestbuffers *req) · 5 unmodified lines
541556 return -ENOMEM;
542557 }
543558
559+ allocated_buffers = ret;
560+
544561 /*
545562 * Check if driver can handle the allocated number of buffers.
546563 */
547− if (ret < num_buffers) {
548− unsigned int orig_num_buffers;
564+ if (allocated_buffers < num_buffers) {
565+ num_buffers = allocated_buffers;
549566
550− orig_num_buffers = num_buffers = ret;
551− ret = call_qop(q, queue_setup, q, &num_buffers, &num_planes,
552− q->plane_sizes, q->alloc_ctx);
553− if (ret)
554− goto free_mem;
567+ ret = call_qop(q, queue_setup, q, NULL, &num_buffers,
568+ &num_planes, q->plane_sizes, q->alloc_ctx);
555569
556− if (orig_num_buffers < num_buffers) {
570+ if (!ret && allocated_buffers < num_buffers)
557571 ret = -ENOMEM;
558− goto free_mem;
559− }
560572
561573 /*
562− * Ok, driver accepted smaller number of buffers.
574+ * Either the driver has accepted a smaller number of buffers,
575+ * or .queue_setup() returned an error
563576 */
564− ret = num_buffers;
577+ }
578+
579+ q->num_buffers = allocated_buffers;
580+
581+ if (ret < 0) {
582+ __vb2_queue_free(q, allocated_buffers);
583+ return ret;
565584 }
566585
567586 /*
568587 * Return the number of successfully allocated buffers
569588 * to the userspace.
570589 */
571− req->count = ret;
590+ req->count = allocated_buffers;
572591
573592 return 0;
574−
575−free_mem:
576− __vb2_queue_free(q);
577− return ret;
578593 }
579594 EXPORT_SYMBOL_GPL(vb2_reqbufs);
580595
596+/**
597+ * vb2_create_bufs() - Allocate buffers and any required auxiliary structs
598+ * @q: videobuf2 queue
599+ * @create: creation parameters, passed from userspace to vidioc_create_bufs
600+ * handler in driver
601+ *
602+ * Should be called from vidioc_create_bufs ioctl handler of a driver.
603+ * This function:
604+ * 1) verifies parameter sanity
605+ * 2) calls the .queue_setup() queue operation
606+ * 3) performs any necessary memory allocations
607+ *
608+ * The return values from this function are intended to be directly returned
609+ * from vidioc_create_bufs handler in driver.
610+ */
611+int vb2_create_bufs(struct vb2_queue *q, struct v4l2_create_buffers *create)
612+{
613+ unsigned int num_planes = 0, num_buffers, allocated_buffers;
614+ int ret = 0;
615+
616+ if (q->fileio) {
617+ dprintk(1, "%s(): file io in progress\n", __func__);
618+ return -EBUSY;
619+ }
620+
621+ if (create->memory != V4L2_MEMORY_MMAP
622+ && create->memory != V4L2_MEMORY_USERPTR) {
623+ dprintk(1, "%s(): unsupported memory type\n", __func__);
624+ return -EINVAL;
625+ }
626+
627+ if (create->format.type != q->type) {
628+ dprintk(1, "%s(): requested type is incorrect\n", __func__);
629+ return -EINVAL;
630+ }
631+
632+ /*
633+ * Make sure all the required memory ops for given memory type
634+ * are available.
635+ */
636+ if (create->memory == V4L2_MEMORY_MMAP && __verify_mmap_ops(q)) {
637+ dprintk(1, "%s(): MMAP for current setup unsupported\n", __func__);
638+ return -EINVAL;
639+ }
640+
641+ if (create->memory == V4L2_MEMORY_USERPTR && __verify_userptr_ops(q)) {
642+ dprintk(1, "%s(): USERPTR for current setup unsupported\n", __func__);
643+ return -EINVAL;
644+ }
645+
646+ if (q->num_buffers == VIDEO_MAX_FRAME) {
647+ dprintk(1, "%s(): maximum number of buffers already allocated\n",
648+ __func__);
649+ return -ENOBUFS;
650+ }
651+
652+ create->index = q->num_buffers;
653+
654+ if (!q->num_buffers) {
655+ memset(q->plane_sizes, 0, sizeof(q->plane_sizes));
656+ memset(q->alloc_ctx, 0, sizeof(q->alloc_ctx));
657+ q->memory = create->memory;
658+ }
659+
660+ num_buffers = min(create->count, VIDEO_MAX_FRAME - q->num_buffers);
661+
662+ /*
663+ * Ask the driver, whether the requested number of buffers, planes per
664+ * buffer and their sizes are acceptable
665+ */
666+ ret = call_qop(q, queue_setup, q, &create->format, &num_buffers,
667+ &num_planes, q->plane_sizes, q->alloc_ctx);
668+ if (ret)
669+ return ret;
670+
671+ /* Finally, allocate buffers and video memory */
672+ ret = __vb2_queue_alloc(q, create->memory, num_buffers,
673+ num_planes);
674+ if (ret < 0) {
675+ dprintk(1, "Memory allocation failed with error: %d\n", ret);
676+ return ret;
677+ }
678+
679+ allocated_buffers = ret;
680+
681+ /*
682+ * Check if driver can handle the so far allocated number of buffers.
683+ */
684+ if (ret < num_buffers) {
685+ num_buffers = ret;
686+
687+ /*
688+ * q->num_buffers contains the total number of buffers, that the
689+ * queue driver has set up
690+ */
691+ ret = call_qop(q, queue_setup, q, &create->format, &num_buffers,
692+ &num_planes, q->plane_sizes, q->alloc_ctx);
693+
694+ if (!ret && allocated_buffers < num_buffers)
695+ ret = -ENOMEM;
696+
697+ /*
698+ * Either the driver has accepted a smaller number of buffers,
699+ * or .queue_setup() returned an error
700+ */
701+ }
702+
703+ q->num_buffers += allocated_buffers;
704+
705+ if (ret < 0) {
706+ __vb2_queue_free(q, allocated_buffers);
707+ return ret;
708+ }
709+
710+ /*
711+ * Return the number of successfully allocated buffers
712+ * to the userspace.
713+ */
714+ create->count = allocated_buffers;
715+
716+ return 0;
717+}
718+EXPORT_SYMBOL_GPL(vb2_create_bufs);
719+
581720 /**
582721 * vb2_plane_vaddr() - Return a kernel virtual address of a given plane
583722 * @vb: vb2_buffer to which the plane in question belongs to
@@ -662,7 +801,7 @@ EXPORT_SYMBOL_GPL(vb2_buffer_done); · 78 unmodified lines
662801 * __fill_vb2_buffer() - fill a vb2_buffer with information provided in
663802 * a v4l2_buffer by the userspace
664803 */
665−static int __fill_vb2_buffer(struct vb2_buffer *vb, struct v4l2_buffer *b,
804+static int __fill_vb2_buffer(struct vb2_buffer *vb, const struct v4l2_buffer *b,
666805 struct v4l2_plane *v4l2_planes)
667806 {
668807 unsigned int plane;
@@ -726,7 +865,7 @@ static int __fill_vb2_buffer(struct vb2_buffer *vb, struct v4l2_buffer *b, · 57 unmodified lines
726865 /**
727866 * __qbuf_userptr() - handle qbuf of a USERPTR buffer
728867 */
729−static int __qbuf_userptr(struct vb2_buffer *vb, struct v4l2_buffer *b)
868+static int __qbuf_userptr(struct vb2_buffer *vb, const struct v4l2_buffer *b)
730869 {
731870 struct v4l2_plane planes[VIDEO_MAX_PLANES];
732871 struct vb2_queue *q = vb->vb2_queue;
@@ -815,7 +954,7 @@ err: · 82 unmodified lines
815954 /**
816955 * __qbuf_mmap() - handle qbuf of an MMAP buffer
817956 */
818−static int __qbuf_mmap(struct vb2_buffer *vb, struct v4l2_buffer *b)
957+static int __qbuf_mmap(struct vb2_buffer *vb, const struct v4l2_buffer *b)
819958 {
820959 return __fill_vb2_buffer(vb, b, vb->v4l2_planes);
821960 }
@@ -832,6 +971,95 @@ static void __enqueue_in_driver(struct vb2_buffer *vb) · 10 unmodified lines
832971 q->ops->buf_queue(vb);
833972 }
834973
974+static int __buf_prepare(struct vb2_buffer *vb, const struct v4l2_buffer *b)
975+{
976+ struct vb2_queue *q = vb->vb2_queue;
977+ int ret;
978+
979+ switch (q->memory) {
980+ case V4L2_MEMORY_MMAP:
981+ ret = __qbuf_mmap(vb, b);
982+ break;
983+ case V4L2_MEMORY_USERPTR:
984+ ret = __qbuf_userptr(vb, b);
985+ break;
986+ default:
987+ WARN(1, "Invalid queue type\n");
988+ ret = -EINVAL;
989+ }
990+
991+ if (!ret)
992+ ret = call_qop(q, buf_prepare, vb);
993+ if (ret)
994+ dprintk(1, "qbuf: buffer preparation failed: %d\n", ret);
995+ else
996+ vb->state = VB2_BUF_STATE_PREPARED;
997+
998+ return ret;
999+}
1000+
1001+/**
1002+ * vb2_prepare_buf() - Pass ownership of a buffer from userspace to the kernel
1003+ * @q: videobuf2 queue
1004+ * @b: buffer structure passed from userspace to vidioc_prepare_buf
1005+ * handler in driver
1006+ *
1007+ * Should be called from vidioc_prepare_buf ioctl handler of a driver.
1008+ * This function:
1009+ * 1) verifies the passed buffer,
1010+ * 2) calls buf_prepare callback in the driver (if provided), in which
1011+ * driver-specific buffer initialization can be performed,
1012+ *
1013+ * The return values from this function are intended to be directly returned
1014+ * from vidioc_prepare_buf handler in driver.
1015+ */
1016+int vb2_prepare_buf(struct vb2_queue *q, struct v4l2_buffer *b)
1017+{
1018+ struct vb2_buffer *vb;
1019+ int ret;
1020+
1021+ if (q->fileio) {
1022+ dprintk(1, "%s(): file io in progress\n", __func__);
1023+ return -EBUSY;
1024+ }
1025+
1026+ if (b->type != q->type) {
1027+ dprintk(1, "%s(): invalid buffer type\n", __func__);
1028+ return -EINVAL;
1029+ }
1030+
1031+ if (b->index >= q->num_buffers) {
1032+ dprintk(1, "%s(): buffer index out of range\n", __func__);
1033+ return -EINVAL;
1034+ }
1035+
1036+ vb = q->bufs[b->index];
1037+ if (NULL == vb) {
1038+ /* Should never happen */
1039+ dprintk(1, "%s(): buffer is NULL\n", __func__);
1040+ return -EINVAL;
1041+ }
1042+
1043+ if (b->memory != q->memory) {
1044+ dprintk(1, "%s(): invalid memory type\n", __func__);
1045+ return -EINVAL;
1046+ }
1047+
1048+ if (vb->state != VB2_BUF_STATE_DEQUEUED) {
1049+ dprintk(1, "%s(): invalid buffer state %d\n", __func__, vb->state);
1050+ return -EINVAL;
1051+ }
1052+
1053+ ret = __buf_prepare(vb, b);
1054+ if (ret < 0)
1055+ return ret;
1056+
1057+ __fill_v4l2_buffer(vb, b);
1058+
1059+ return 0;
1060+}
1061+EXPORT_SYMBOL_GPL(vb2_prepare_buf);
1062+
8351063 /**
8361064 * vb2_qbuf() - Queue a buffer from userspace
8371065 * @q: videobuf2 queue
@@ -841,8 +1069,8 @@ static void __enqueue_in_driver(struct vb2_buffer *vb) · 3 unmodified lines
8411069 * Should be called from vidioc_qbuf ioctl handler of a driver.
8421070 * This function:
8431071 * 1) verifies the passed buffer,
844− * 2) calls buf_prepare callback in the driver (if provided), in which
845− * driver-specific buffer initialization can be performed,
1072+ * 2) if necessary, calls buf_prepare callback in the driver (if provided), in
1073+ * which driver-specific buffer initialization can be performed,
8461074 * 3) if streaming is on, queues the buffer in driver by the means of buf_queue
8471075 * callback for processing.
8481076 *
@@ -852,7 +1080,7 @@ static void __enqueue_in_driver(struct vb2_buffer *vb) · 3 unmodified lines
8521080 int vb2_qbuf(struct vb2_queue *q, struct v4l2_buffer *b)
8531081 {
8541082 struct vb2_buffer *vb;
855− int ret = 0;
1083+ int ret;
8561084
8571085 if (q->fileio) {
8581086 dprintk(1, "qbuf: file io in progress\n");
@@ -881,29 +1109,18 @@ int vb2_qbuf(struct vb2_queue *q, struct v4l2_buffer *b) · 22 unmodified lines
8811109 return -EINVAL;
8821110 }
8831111
884− if (vb->state != VB2_BUF_STATE_DEQUEUED) {
1112+ switch (vb->state) {
1113+ case VB2_BUF_STATE_DEQUEUED:
1114+ ret = __buf_prepare(vb, b);
1115+ if (ret)
1116+ return ret;
1117+ case VB2_BUF_STATE_PREPARED:
1118+ break;
1119+ default:
8851120 dprintk(1, "qbuf: buffer already in use\n");
8861121 return -EINVAL;
8871122 }
8881123
889− if (q->memory == V4L2_MEMORY_MMAP)
890− ret = __qbuf_mmap(vb, b);
891− else if (q->memory == V4L2_MEMORY_USERPTR)
892− ret = __qbuf_userptr(vb, b);
893− else {
894− WARN(1, "Invalid queue type\n");
895− return -EINVAL;
896− }
897−
898− if (ret)
899− return ret;
900−
901− ret = call_qop(q, buf_prepare, vb);
902− if (ret) {
903− dprintk(1, "qbuf: buffer preparation failed\n");
904− return ret;
905− }
906−
9071124 /*
9081125 * Add to the queued buffers list, a buffer will stay on it until
9091126 * dequeued in dqbuf.
@@ -918,6 +1135,9 @@ int vb2_qbuf(struct vb2_queue *q, struct v4l2_buffer *b) · 8 unmodified lines
9181135 if (q->streaming)
9191136 __enqueue_in_driver(vb);
9201137
1138+ /* Fill buffer information for the userspace */
1139+ __fill_v4l2_buffer(vb, b);
1140+
9211141 dprintk(1, "qbuf of buffer %d succeeded\n", vb->v4l2_buf.index);
9221142 return 0;
9231143 }
@@ -1347,6 +1567,37 @@ int vb2_mmap(struct vb2_queue *q, struct vm_area_struct *vma) · 423 unmodified lines
13471567 }
13481568 EXPORT_SYMBOL_GPL(vb2_mmap);
13491569
1570+#ifndef CONFIG_MMU
1571+unsigned long vb2_get_unmapped_area(struct vb2_queue *q,
1572+ unsigned long addr,
1573+ unsigned long len,
1574+ unsigned long pgoff,
1575+ unsigned long flags)
1576+{
1577+ unsigned long off = pgoff << PAGE_SHIFT;
1578+ struct vb2_buffer *vb;
1579+ unsigned int buffer, plane;
1580+ int ret;
1581+
1582+ if (q->memory != V4L2_MEMORY_MMAP) {
1583+ dprintk(1, "Queue is not currently set up for mmap\n");
1584+ return -EINVAL;
1585+ }
1586+
1587+ /*
1588+ * Find the plane corresponding to the offset passed by userspace.
1589+ */
1590+ ret = __find_plane_by_offset(q, off, &buffer, &plane);
1591+ if (ret)
1592+ return ret;
1593+
1594+ vb = q->bufs[buffer];
1595+
1596+ return (unsigned long)vb2_plane_vaddr(vb, plane);
1597+}
1598+EXPORT_SYMBOL_GPL(vb2_get_unmapped_area);
1599+#endif
1600+
13501601 static int __vb2_init_fileio(struct vb2_queue *q, int read);
13511602 static int __vb2_cleanup_fileio(struct vb2_queue *q);
13521603
@@ -1464,7 +1715,7 @@ void vb2_queue_release(struct vb2_queue *q) · 111 unmodified lines
14641715 {
14651716 __vb2_cleanup_fileio(q);
14661717 __vb2_queue_cancel(q);
1467− __vb2_queue_free(q);
1718+ __vb2_queue_free(q, q->num_buffers);
14681719 }
14691720 EXPORT_SYMBOL_GPL(vb2_queue_release);
14701721
drivers/media/video/vivi.c+3−3
@@ -650,9 +650,9 @@ static void vivi_stop_generating(struct vivi_dev *dev) · 649 unmodified lines
650650 /* ------------------------------------------------------------------
651651 Videobuf operations
652652 ------------------------------------------------------------------*/
653−static int queue_setup(struct vb2_queue *vq, unsigned int *nbuffers,
654− unsigned int *nplanes, unsigned int sizes[],
655− void *alloc_ctxs[])
653+static int queue_setup(struct vb2_queue *vq, const struct v4l2_format *fmt,
654+ unsigned int *nbuffers, unsigned int *nplanes,
655+ unsigned int sizes[], void *alloc_ctxs[])
656656 {
657657 struct vivi_dev *dev = vb2_get_drv_priv(vq);
658658 unsigned long size;
drivers/staging/Kconfig+2−14
@@ -30,12 +30,6 @@ source "drivers/staging/et131x/Kconfig" · 29 unmodified lines
3030
3131 source "drivers/staging/slicoss/Kconfig"
3232
33−source "drivers/staging/go7007/Kconfig"
34−
35−source "drivers/staging/cx25821/Kconfig"
36−
37−source "drivers/staging/cxd2099/Kconfig"
38−
3933 source "drivers/staging/usbip/Kconfig"
4034
4135 source "drivers/staging/winbond/Kconfig"
@@ -104,20 +98,12 @@ source "drivers/staging/wlags49_h25/Kconfig" · 62 unmodified lines
10498
10599 source "drivers/staging/sm7xx/Kconfig"
106100
107−source "drivers/staging/dt3155v4l/Kconfig"
108−
109101 source "drivers/staging/crystalhd/Kconfig"
110102
111103 source "drivers/staging/cxt1e1/Kconfig"
112104
113105 source "drivers/staging/xgifb/Kconfig"
114106
115−source "drivers/staging/lirc/Kconfig"
116−
117−source "drivers/staging/easycap/Kconfig"
118−
119−source "drivers/staging/solo6x10/Kconfig"
120−
121107 source "drivers/staging/tidspbridge/Kconfig"
122108
123109 source "drivers/staging/quickstart/Kconfig"
@@ -144,4 +130,6 @@ source "drivers/staging/mei/Kconfig" · 20 unmodified lines
144130
145131 source "drivers/staging/nvec/Kconfig"
146132
133+source "drivers/staging/media/Kconfig"
134+
147135 endif # STAGING
drivers/staging/Makefile+1−7
@@ -4,12 +4,9 @@ · 3 unmodified lines
44 obj-$(CONFIG_STAGING) += staging.o
55
66 obj-y += serial/
7+obj-y += media/
78 obj-$(CONFIG_ET131X) += et131x/
89 obj-$(CONFIG_SLICOSS) += slicoss/
9−obj-$(CONFIG_VIDEO_GO7007) += go7007/
10−obj-$(CONFIG_VIDEO_CX25821) += cx25821/
11−obj-$(CONFIG_DVB_CXD2099) += cxd2099/
12−obj-$(CONFIG_LIRC_STAGING) += lirc/
1310 obj-$(CONFIG_USBIP_CORE) += usbip/
1411 obj-$(CONFIG_W35UND) += winbond/
1512 obj-$(CONFIG_PRISM2_USB) += wlan-ng/
@@ -44,12 +41,9 @@ obj-$(CONFIG_ZCACHE) += zcache/ · 28 unmodified lines
4441 obj-$(CONFIG_WLAGS49_H2) += wlags49_h2/
4542 obj-$(CONFIG_WLAGS49_H25) += wlags49_h25/
4643 obj-$(CONFIG_FB_SM7XX) += sm7xx/
47−obj-$(CONFIG_VIDEO_DT3155) += dt3155v4l/
4844 obj-$(CONFIG_CRYSTALHD) += crystalhd/
4945 obj-$(CONFIG_CXT1E1) += cxt1e1/
5046 obj-$(CONFIG_FB_XGI) += xgifb/
51−obj-$(CONFIG_EASYCAP) += easycap/
52−obj-$(CONFIG_SOLO6X10) += solo6x10/
5347 obj-$(CONFIG_TIDSPBRIDGE) += tidspbridge/
5448 obj-$(CONFIG_ACPI_QUICKSTART) += quickstart/
5549 obj-$(CONFIG_SBE_2T3E3) += sbe-2t3e3/
drivers/staging/cx25821/README+0−6
@@ -1,6 +0,0 @@
1−Todo:
2− - checkpatch.pl cleanups
3− - sparse cleanups
4−
5−Please send patches to linux-media@vger.kernel.org
6−
drivers/staging/media/Kconfig+37−0
@@ -0,0 +1,37 @@
1+menuconfig STAGING_MEDIA
2+ bool "Media staging drivers"
3+ default n
4+ ---help---
5+ This option allows you to select a number of media drivers that
6+ don't have the "normal" Linux kernel quality level.
7+ Most of them don't follow properly the V4L, DVB and/or RC API's,
8+ so, they won't likely work fine with the existing applications.
9+ That also means that, one fixed, their API's will change to match
10+ the existing ones.
11+
12+ If you wish to work on these drivers, to help improve them, or
13+ to report problems you have with them, please use the
14+ linux-media@vger.kernel.org mailing list.
15+
16+ If in doubt, say N here.
17+
18+
19+if STAGING_MEDIA
20+
21+# Please keep them in alphabetic order
22+source "drivers/staging/media/as102/Kconfig"
23+
24+source "drivers/staging/media/cxd2099/Kconfig"
25+
26+source "drivers/staging/media/dt3155v4l/Kconfig"
27+
28+source "drivers/staging/media/easycap/Kconfig"
29+
30+source "drivers/staging/media/go7007/Kconfig"
31+
32+source "drivers/staging/media/solo6x10/Kconfig"
33+
34+# Keep LIRC at the end, as it has sub-menus
35+source "drivers/staging/media/lirc/Kconfig"
36+
37+endif
drivers/staging/media/Makefile+7−0
@@ -0,0 +1,7 @@
1+obj-$(CONFIG_DVB_AS102) += as102/
2+obj-$(CONFIG_DVB_CXD2099) += cxd2099/
3+obj-$(CONFIG_EASYCAP) += easycap/
4+obj-$(CONFIG_LIRC_STAGING) += lirc/
5+obj-$(CONFIG_SOLO6X10) += solo6x10/
6+obj-$(CONFIG_VIDEO_DT3155) += dt3155v4l/
7+obj-$(CONFIG_VIDEO_GO7007) += go7007/
drivers/staging/media/as102/Kconfig+7−0
@@ -0,0 +1,7 @@
1+config DVB_AS102
2+ tristate "Abilis AS102 DVB receiver"
3+ depends on DVB_CORE && USB && I2C && INPUT
4+ help
5+ Choose Y or M here if you have a device containing an AS102
6+
7+ To compile this driver as a module, choose M here
drivers/staging/media/as102/Makefile+6−0
@@ -0,0 +1,6 @@
1+dvb-as102-objs := as102_drv.o as102_fw.o as10x_cmd.o as10x_cmd_stream.o \
2+ as102_fe.o as102_usb_drv.o as10x_cmd_cfg.o
3+
4+obj-$(CONFIG_DVB_AS102) += dvb-as102.o
5+
6+EXTRA_CFLAGS += -DCONFIG_AS102_USB -Idrivers/media/dvb/dvb-core
drivers/staging/media/as102/as102_drv.c+351−0
@@ -0,0 +1,351 @@
1+/*
2+ * Abilis Systems Single DVB-T Receiver
3+ * Copyright (C) 2008 Pierrick Hascoet <pierrick.hascoet@abilis.com>
4+ * Copyright (C) 2010 Devin Heitmueller <dheitmueller@kernellabs.com>
5+ *
6+ * This program is free software; you can redistribute it and/or modify
7+ * it under the terms of the GNU General Public License as published by
8+ * the Free Software Foundation; either version 2, or (at your option)
9+ * any later version.
10+ *
11+ * This program is distributed in the hope that it will be useful,
12+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
13+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+ * GNU General Public License for more details.
15+ *
16+ * You should have received a copy of the GNU General Public License
17+ * along with this program; if not, write to the Free Software
18+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19+ */
20+#include <linux/kernel.h>
21+#include <linux/errno.h>
22+#include <linux/init.h>
23+#include <linux/slab.h>
24+#include <linux/module.h>
25+#include <linux/mm.h>
26+#include <linux/kref.h>
27+#include <asm/uaccess.h>
28+#include <linux/usb.h>
29+
30+/* header file for Usb device driver*/
31+#include "as102_drv.h"
32+#include "as102_fw.h"
33+#include "dvbdev.h"
34+
35+int debug;
36+module_param_named(debug, debug, int, 0644);
37+MODULE_PARM_DESC(debug, "Turn on/off debugging (default: off)");
38+
39+int dual_tuner;
40+module_param_named(dual_tuner, dual_tuner, int, 0644);
41+MODULE_PARM_DESC(dual_tuner, "Activate Dual-Tuner config (default: off)");
42+
43+static int fw_upload = 1;
44+module_param_named(fw_upload, fw_upload, int, 0644);
45+MODULE_PARM_DESC(fw_upload, "Turn on/off default FW upload (default: on)");
46+
47+static int pid_filtering;
48+module_param_named(pid_filtering, pid_filtering, int, 0644);
49+MODULE_PARM_DESC(pid_filtering, "Activate HW PID filtering (default: off)");
50+
51+static int ts_auto_disable;
52+module_param_named(ts_auto_disable, ts_auto_disable, int, 0644);
53+MODULE_PARM_DESC(ts_auto_disable, "Stream Auto Enable on FW (default: off)");
54+
55+int elna_enable = 1;
56+module_param_named(elna_enable, elna_enable, int, 0644);
57+MODULE_PARM_DESC(elna_enable, "Activate eLNA (default: on)");
58+
59+#ifdef DVB_DEFINE_MOD_OPT_ADAPTER_NR
60+DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
61+#endif
62+
63+static void as102_stop_stream(struct as102_dev_t *dev)
64+{
65+ struct as102_bus_adapter_t *bus_adap;
66+
67+ if (dev != NULL)
68+ bus_adap = &dev->bus_adap;
69+ else
70+ return;
71+
72+ if (bus_adap->ops->stop_stream != NULL)
73+ bus_adap->ops->stop_stream(dev);
74+
75+ if (ts_auto_disable) {
76+ if (mutex_lock_interruptible(&dev->bus_adap.lock))
77+ return;
78+
79+ if (as10x_cmd_stop_streaming(bus_adap) < 0)
80+ dprintk(debug, "as10x_cmd_stop_streaming failed\n");
81+
82+ mutex_unlock(&dev->bus_adap.lock);
83+ }
84+}
85+
86+static int as102_start_stream(struct as102_dev_t *dev)
87+{
88+ struct as102_bus_adapter_t *bus_adap;
89+ int ret = -EFAULT;
90+
91+ if (dev != NULL)
92+ bus_adap = &dev->bus_adap;
93+ else
94+ return ret;
95+
96+ if (bus_adap->ops->start_stream != NULL)
97+ ret = bus_adap->ops->start_stream(dev);
98+
99+ if (ts_auto_disable) {
100+ if (mutex_lock_interruptible(&dev->bus_adap.lock))
101+ return -EFAULT;
102+
103+ ret = as10x_cmd_start_streaming(bus_adap);
104+
105+ mutex_unlock(&dev->bus_adap.lock);
106+ }
107+
108+ return ret;
109+}
110+
111+static int as10x_pid_filter(struct as102_dev_t *dev,
112+ int index, u16 pid, int onoff) {
113+
114+ struct as102_bus_adapter_t *bus_adap = &dev->bus_adap;
115+ int ret = -EFAULT;
116+
117+ ENTER();
118+
119+ if (mutex_lock_interruptible(&dev->bus_adap.lock)) {
120+ dprintk(debug, "mutex_lock_interruptible(lock) failed !\n");
121+ return -EBUSY;
122+ }
123+
124+ switch (onoff) {
125+ case 0:
126+ ret = as10x_cmd_del_PID_filter(bus_adap, (uint16_t) pid);
127+ dprintk(debug, "DEL_PID_FILTER([%02d] 0x%04x) ret = %d\n",
128+ index, pid, ret);
129+ break;
130+ case 1:
131+ {
132+ struct as10x_ts_filter filter;
133+
134+ filter.type = TS_PID_TYPE_TS;
135+ filter.idx = 0xFF;
136+ filter.pid = pid;
137+
138+ ret = as10x_cmd_add_PID_filter(bus_adap, &filter);
139+ dprintk(debug, "ADD_PID_FILTER([%02d -> %02d], 0x%04x) ret = %d\n",
140+ index, filter.idx, filter.pid, ret);
141+ break;
142+ }
143+ }
144+
145+ mutex_unlock(&dev->bus_adap.lock);
146+
147+ LEAVE();
148+ return ret;
149+}
150+
151+static int as102_dvb_dmx_start_feed(struct dvb_demux_feed *dvbdmxfeed)
152+{
153+ int ret = 0;
154+ struct dvb_demux *demux = dvbdmxfeed->demux;
155+ struct as102_dev_t *as102_dev = demux->priv;
156+
157+ ENTER();
158+
159+ if (mutex_lock_interruptible(&as102_dev->sem))
160+ return -ERESTARTSYS;
161+
162+ if (pid_filtering) {
163+ as10x_pid_filter(as102_dev,
164+ dvbdmxfeed->index, dvbdmxfeed->pid, 1);
165+ }
166+
167+ if (as102_dev->streaming++ == 0)
168+ ret = as102_start_stream(as102_dev);
169+
170+ mutex_unlock(&as102_dev->sem);
171+ LEAVE();
172+ return ret;
173+}
174+
175+static int as102_dvb_dmx_stop_feed(struct dvb_demux_feed *dvbdmxfeed)
176+{
177+ struct dvb_demux *demux = dvbdmxfeed->demux;
178+ struct as102_dev_t *as102_dev = demux->priv;
179+
180+ ENTER();
181+
182+ if (mutex_lock_interruptible(&as102_dev->sem))
183+ return -ERESTARTSYS;
184+
185+ if (--as102_dev->streaming == 0)
186+ as102_stop_stream(as102_dev);
187+
188+ if (pid_filtering) {
189+ as10x_pid_filter(as102_dev,
190+ dvbdmxfeed->index, dvbdmxfeed->pid, 0);
191+ }
192+
193+ mutex_unlock(&as102_dev->sem);
194+ LEAVE();
195+ return 0;
196+}
197+
198+int as102_dvb_register(struct as102_dev_t *as102_dev)
199+{
200+ int ret = 0;
201+ ENTER();
202+
203+ ret = dvb_register_adapter(&as102_dev->dvb_adap,
204+ as102_dev->name,
205+ THIS_MODULE,
206+#if defined(CONFIG_AS102_USB)
207+ &as102_dev->bus_adap.usb_dev->dev
208+#elif defined(CONFIG_AS102_SPI)
209+ &as102_dev->bus_adap.spi_dev->dev
210+#else
211+#error >>> dvb_register_adapter <<<
212+#endif
213+#ifdef DVB_DEFINE_MOD_OPT_ADAPTER_NR
214+ , adapter_nr
215+#endif
216+ );
217+ if (ret < 0) {
218+ err("%s: dvb_register_adapter() failed (errno = %d)",
219+ __func__, ret);
220+ goto failed;
221+ }
222+
223+ as102_dev->dvb_dmx.priv = as102_dev;
224+ as102_dev->dvb_dmx.filternum = pid_filtering ? 16 : 256;
225+ as102_dev->dvb_dmx.feednum = 256;
226+ as102_dev->dvb_dmx.start_feed = as102_dvb_dmx_start_feed;
227+ as102_dev->dvb_dmx.stop_feed = as102_dvb_dmx_stop_feed;
228+
229+ as102_dev->dvb_dmx.dmx.capabilities = DMX_TS_FILTERING |
230+ DMX_SECTION_FILTERING;
231+
232+ as102_dev->dvb_dmxdev.filternum = as102_dev->dvb_dmx.filternum;
233+ as102_dev->dvb_dmxdev.demux = &as102_dev->dvb_dmx.dmx;
234+ as102_dev->dvb_dmxdev.capabilities = 0;
235+
236+ ret = dvb_dmx_init(&as102_dev->dvb_dmx);
237+ if (ret < 0) {
238+ err("%s: dvb_dmx_init() failed (errno = %d)", __func__, ret);
239+ goto failed;
240+ }
241+
242+ ret = dvb_dmxdev_init(&as102_dev->dvb_dmxdev, &as102_dev->dvb_adap);
243+ if (ret < 0) {
244+ err("%s: dvb_dmxdev_init() failed (errno = %d)", __func__,
245+ ret);
246+ goto failed;
247+ }
248+
249+ ret = as102_dvb_register_fe(as102_dev, &as102_dev->dvb_fe);
250+ if (ret < 0) {
251+ err("%s: as102_dvb_register_frontend() failed (errno = %d)",
252+ __func__, ret);
253+ goto failed;
254+ }
255+
256+ /* init bus mutex for token locking */
257+ mutex_init(&as102_dev->bus_adap.lock);
258+
259+ /* init start / stop stream mutex */
260+ mutex_init(&as102_dev->sem);
261+
262+#if defined(CONFIG_FW_LOADER) || defined(CONFIG_FW_LOADER_MODULE)
263+ /*
264+ * try to load as102 firmware. If firmware upload failed, we'll be
265+ * able to upload it later.
266+ */
267+ if (fw_upload)
268+ try_then_request_module(as102_fw_upload(&as102_dev->bus_adap),
269+ "firmware_class");
270+#endif
271+
272+failed:
273+ LEAVE();
274+ /* FIXME: free dvb_XXX */
275+ return ret;
276+}
277+
278+void as102_dvb_unregister(struct as102_dev_t *as102_dev)
279+{
280+ ENTER();
281+
282+ /* unregister as102 frontend */
283+ as102_dvb_unregister_fe(&as102_dev->dvb_fe);
284+
285+ /* unregister demux device */
286+ dvb_dmxdev_release(&as102_dev->dvb_dmxdev);
287+ dvb_dmx_release(&as102_dev->dvb_dmx);
288+
289+ /* unregister dvb adapter */
290+ dvb_unregister_adapter(&as102_dev->dvb_adap);
291+
292+ LEAVE();
293+}
294+
295+static int __init as102_driver_init(void)
296+{
297+ int ret = 0;
298+
299+ ENTER();
300+
301+ /* register this driver with the low level subsystem */
302+#if defined(CONFIG_AS102_USB)
303+ ret = usb_register(&as102_usb_driver);
304+ if (ret)
305+ err("usb_register failed (ret = %d)", ret);
306+#endif
307+#if defined(CONFIG_AS102_SPI)
308+ ret = spi_register_driver(&as102_spi_driver);
309+ if (ret)
310+ printk(KERN_ERR "spi_register failed (ret = %d)", ret);
311+#endif
312+
313+ LEAVE();
314+ return ret;
315+}
316+
317+/*
318+ * Mandatory function : Adds a special section to the module indicating
319+ * where initialisation function is defined
320+ */
321+module_init(as102_driver_init);
322+
323+/**
324+ * as102_driver_exit - as102 driver exit point
325+ *
326+ * This function is called when device has to be removed.
327+ */
328+static void __exit as102_driver_exit(void)
329+{
330+ ENTER();
331+ /* deregister this driver with the low level bus subsystem */
332+#if defined(CONFIG_AS102_USB)
333+ usb_deregister(&as102_usb_driver);
334+#endif
335+#if defined(CONFIG_AS102_SPI)
336+ spi_unregister_driver(&as102_spi_driver);
337+#endif
338+ LEAVE();
339+}
340+
341+/*
342+ * required function for unload: Adds a special section to the module
343+ * indicating where unload function is defined
344+ */
345+module_exit(as102_driver_exit);
346+/* modinfo details */
347+MODULE_DESCRIPTION(DRIVER_FULL_NAME);
348+MODULE_LICENSE("GPL");
349+MODULE_AUTHOR("Pierrick Hascoet <pierrick.hascoet@abilis.com>");
350+
351+/* EOF - vim: set textwidth=80 ts=8 sw=8 sts=8 noet: */
drivers/staging/media/as102/as102_drv.h+141−0
@@ -0,0 +1,141 @@
1+/*
2+ * Abilis Systems Single DVB-T Receiver
3+ * Copyright (C) 2008 Pierrick Hascoet <pierrick.hascoet@abilis.com>
4+ *
5+ * This program is free software; you can redistribute it and/or modify
6+ * it under the terms of the GNU General Public License as published by
7+ * the Free Software Foundation; either version 2, or (at your option)
8+ * any later version.
9+ *
10+ * This program is distributed in the hope that it will be useful,
11+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
12+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+ * GNU General Public License for more details.
14+ *
15+ * You should have received a copy of the GNU General Public License
16+ * along with this program; if not, write to the Free Software
17+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18+ */
19+
20+#if defined(CONFIG_AS102_USB)
21+#include <linux/usb.h>
22+extern struct usb_driver as102_usb_driver;
23+#endif
24+
25+#if defined(CONFIG_AS102_SPI)
26+#include <linux/platform_device.h>
27+#include <linux/spi/spi.h>
28+#include <linux/cdev.h>
29+
30+extern struct spi_driver as102_spi_driver;
31+#endif
32+
33+#include "dvb_demux.h"
34+#include "dvb_frontend.h"
35+#include "dmxdev.h"
36+
37+#define DRIVER_FULL_NAME "Abilis Systems as10x usb driver"
38+#define DRIVER_NAME "as10x_usb"
39+
40+extern int debug;
41+
42+#define dprintk(debug, args...) \
43+ do { if (debug) { \
44+ printk(KERN_DEBUG "%s: ",__FUNCTION__); \
45+ printk(args); \
46+ } } while (0)
47+
48+#ifdef TRACE
49+#define ENTER() printk(">> enter %s\n", __FUNCTION__)
50+#define LEAVE() printk("<< leave %s\n", __FUNCTION__)
51+#else
52+#define ENTER()
53+#define LEAVE()
54+#endif
55+
56+#define AS102_DEVICE_MAJOR 192
57+
58+#define AS102_USB_BUF_SIZE 512
59+#define MAX_STREAM_URB 32
60+
61+#include "as10x_cmd.h"
62+
63+#if defined(CONFIG_AS102_USB)
64+#include "as102_usb_drv.h"
65+#endif
66+
67+#if defined(CONFIG_AS102_SPI)
68+#include "as10x_spi_drv.h"
69+#endif
70+
71+
72+struct as102_bus_adapter_t {
73+#if defined(CONFIG_AS102_USB)
74+ struct usb_device *usb_dev;
75+#elif defined(CONFIG_AS102_SPI)
76+ struct spi_device *spi_dev;
77+ struct cdev cdev; /* spidev raw device */
78+
79+ struct timer_list timer;
80+ struct completion xfer_done;
81+#endif
82+ /* bus token lock */
83+ struct mutex lock;
84+ /* low level interface for bus adapter */
85+ union as10x_bus_token_t {
86+#if defined(CONFIG_AS102_USB)
87+ /* usb token */
88+ struct as10x_usb_token_cmd_t usb;
89+#endif
90+#if defined(CONFIG_AS102_SPI)
91+ /* spi token */
92+ struct as10x_spi_token_cmd_t spi;
93+#endif
94+ } token;
95+
96+ /* token cmd xfer id */
97+ uint16_t cmd_xid;
98+
99+ /* as10x command and response for dvb interface*/
100+ struct as10x_cmd_t *cmd, *rsp;
101+
102+ /* bus adapter private ops callback */
103+ struct as102_priv_ops_t *ops;
104+};
105+
106+struct as102_dev_t {
107+ const char *name;
108+ struct as102_bus_adapter_t bus_adap;
109+ struct list_head device_entry;
110+ struct kref kref;
111+ unsigned long minor;
112+
113+ struct dvb_adapter dvb_adap;
114+ struct dvb_frontend dvb_fe;
115+ struct dvb_demux dvb_dmx;
116+ struct dmxdev dvb_dmxdev;
117+
118+ /* demodulator stats */
119+ struct as10x_demod_stats demod_stats;
120+ /* signal strength */
121+ uint16_t signal_strength;
122+ /* bit error rate */
123+ uint32_t ber;
124+
125+ /* timer handle to trig ts stream download */
126+ struct timer_list timer_handle;
127+
128+ struct mutex sem;
129+ dma_addr_t dma_addr;
130+ void *stream;
131+ int streaming;
132+ struct urb *stream_urb[MAX_STREAM_URB];
133+};
134+
135+int as102_dvb_register(struct as102_dev_t *dev);
136+void as102_dvb_unregister(struct as102_dev_t *dev);
137+
138+int as102_dvb_register_fe(struct as102_dev_t *dev, struct dvb_frontend *fe);
139+int as102_dvb_unregister_fe(struct dvb_frontend *dev);
140+
141+/* EOF - vim: set textwidth=80 ts=8 sw=8 sts=8 noet: */
drivers/staging/media/as102/as102_fe.c+603−0
@@ -0,0 +1,603 @@
1+/*
2+ * Abilis Systems Single DVB-T Receiver
3+ * Copyright (C) 2008 Pierrick Hascoet <pierrick.hascoet@abilis.com>
4+ * Copyright (C) 2010 Devin Heitmueller <dheitmueller@kernellabs.com>
5+ *
6+ * This program is free software; you can redistribute it and/or modify
7+ * it under the terms of the GNU General Public License as published by
8+ * the Free Software Foundation; either version 2, or (at your option)
9+ * any later version.
10+ *
11+ * This program is distributed in the hope that it will be useful,
12+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
13+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+ * GNU General Public License for more details.
15+ *
16+ * You should have received a copy of the GNU General Public License
17+ * along with this program; if not, write to the Free Software
18+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19+ */
20+#include <linux/version.h>
21+
22+#include "as102_drv.h"
23+#include "as10x_types.h"
24+#include "as10x_cmd.h"
25+
26+extern int elna_enable;
27+
28+static void as10x_fe_copy_tps_parameters(struct dvb_frontend_parameters *dst,
29+ struct as10x_tps *src);
30+
31+static void as102_fe_copy_tune_parameters(struct as10x_tune_args *dst,
32+ struct dvb_frontend_parameters *src);
33+
34+static int as102_fe_set_frontend(struct dvb_frontend *fe,
35+ struct dvb_frontend_parameters *params)
36+{
37+ int ret = 0;
38+ struct as102_dev_t *dev;
39+ struct as10x_tune_args tune_args = { 0 };
40+
41+ ENTER();
42+
43+ dev = (struct as102_dev_t *) fe->tuner_priv;
44+ if (dev == NULL)
45+ return -ENODEV;
46+
47+ if (mutex_lock_interruptible(&dev->bus_adap.lock))
48+ return -EBUSY;
49+
50+ as102_fe_copy_tune_parameters(&tune_args, params);
51+
52+ /* send abilis command: SET_TUNE */
53+ ret = as10x_cmd_set_tune(&dev->bus_adap, &tune_args);
54+ if (ret != 0)
55+ dprintk(debug, "as10x_cmd_set_tune failed. (err = %d)\n", ret);
56+
57+ mutex_unlock(&dev->bus_adap.lock);
58+
59+ LEAVE();
60+ return (ret < 0) ? -EINVAL : 0;
61+}
62+
63+static int as102_fe_get_frontend(struct dvb_frontend *fe,
64+ struct dvb_frontend_parameters *p) {
65+ int ret = 0;
66+ struct as102_dev_t *dev;
67+ struct as10x_tps tps = { 0 };
68+
69+ ENTER();
70+
71+ dev = (struct as102_dev_t *) fe->tuner_priv;
72+ if (dev == NULL)
73+ return -EINVAL;
74+
75+ if (mutex_lock_interruptible(&dev->bus_adap.lock))
76+ return -EBUSY;
77+
78+ /* send abilis command: GET_TPS */
79+ ret = as10x_cmd_get_tps(&dev->bus_adap, &tps);
80+
81+ if (ret == 0)
82+ as10x_fe_copy_tps_parameters(p, &tps);
83+
84+ mutex_unlock(&dev->bus_adap.lock);
85+
86+ LEAVE();
87+ return (ret < 0) ? -EINVAL : 0;
88+}
89+
90+static int as102_fe_get_tune_settings(struct dvb_frontend *fe,
91+ struct dvb_frontend_tune_settings *settings) {
92+ ENTER();
93+
94+#if 0
95+ dprintk(debug, "step_size = %d\n", settings->step_size);
96+ dprintk(debug, "max_drift = %d\n", settings->max_drift);
97+ dprintk(debug, "min_delay_ms = %d -> %d\n", settings->min_delay_ms,
98+ 1000);
99+#endif
100+
101+ settings->min_delay_ms = 1000;
102+
103+ LEAVE();
104+ return 0;
105+}
106+
107+
108+static int as102_fe_read_status(struct dvb_frontend *fe, fe_status_t *status)
109+{
110+ int ret = 0;
111+ struct as102_dev_t *dev;
112+ struct as10x_tune_status tstate = { 0 };
113+
114+ ENTER();
115+
116+ dev = (struct as102_dev_t *) fe->tuner_priv;
117+ if (dev == NULL)
118+ return -ENODEV;
119+
120+ if (mutex_lock_interruptible(&dev->bus_adap.lock))
121+ return -EBUSY;
122+
123+ /* send abilis command: GET_TUNE_STATUS */
124+ ret = as10x_cmd_get_tune_status(&dev->bus_adap, &tstate);
125+ if (ret < 0) {
126+ dprintk(debug, "as10x_cmd_get_tune_status failed (err = %d)\n",
127+ ret);
128+ goto out;
129+ }
130+
131+ dev->signal_strength = tstate.signal_strength;
132+ dev->ber = tstate.BER;
133+
134+ switch (tstate.tune_state) {
135+ case TUNE_STATUS_SIGNAL_DVB_OK:
136+ *status = FE_HAS_SIGNAL | FE_HAS_CARRIER;
137+ break;
138+ case TUNE_STATUS_STREAM_DETECTED:
139+ *status = FE_HAS_SIGNAL | FE_HAS_CARRIER | FE_HAS_SYNC;
140+ break;
141+ case TUNE_STATUS_STREAM_TUNED:
142+ *status = FE_HAS_SIGNAL | FE_HAS_CARRIER | FE_HAS_SYNC |
143+ FE_HAS_LOCK;
144+ break;
145+ default:
146+ *status = TUNE_STATUS_NOT_TUNED;
147+ }
148+
149+ dprintk(debug, "tuner status: 0x%02x, strength %d, per: %d, ber: %d\n",
150+ tstate.tune_state, tstate.signal_strength,
151+ tstate.PER, tstate.BER);
152+
153+ if (*status & FE_HAS_LOCK) {
154+ if (as10x_cmd_get_demod_stats(&dev->bus_adap,
155+ (struct as10x_demod_stats *) &dev->demod_stats) < 0) {
156+ memset(&dev->demod_stats, 0, sizeof(dev->demod_stats));
157+ dprintk(debug, "as10x_cmd_get_demod_stats failed "
158+ "(probably not tuned)\n");
159+ } else {
160+ dprintk(debug,
161+ "demod status: fc: 0x%08x, bad fc: 0x%08x, "
162+ "bytes corrected: 0x%08x , MER: 0x%04x\n",
163+ dev->demod_stats.frame_count,
164+ dev->demod_stats.bad_frame_count,
165+ dev->demod_stats.bytes_fixed_by_rs,
166+ dev->demod_stats.mer);
167+ }
168+ } else {
169+ memset(&dev->demod_stats, 0, sizeof(dev->demod_stats));
170+ }
171+
172+out:
173+ mutex_unlock(&dev->bus_adap.lock);
174+ LEAVE();
175+ return ret;
176+}
177+
178+/*
179+ * Note:
180+ * - in AS102 SNR=MER
181+ * - the SNR will be returned in linear terms, i.e. not in dB
182+ * - the accuracy equals ±2dB for a SNR range from 4dB to 30dB
183+ * - the accuracy is >2dB for SNR values outside this range
184+ */
185+static int as102_fe_read_snr(struct dvb_frontend *fe, u16 *snr)
186+{
187+ struct as102_dev_t *dev;
188+
189+ ENTER();
190+
191+ dev = (struct as102_dev_t *) fe->tuner_priv;
192+ if (dev == NULL)
193+ return -ENODEV;
194+
195+ *snr = dev->demod_stats.mer;
196+
197+ LEAVE();
198+ return 0;
199+}
200+
201+static int as102_fe_read_ber(struct dvb_frontend *fe, u32 *ber)
202+{
203+ struct as102_dev_t *dev;
204+
205+ ENTER();
206+
207+ dev = (struct as102_dev_t *) fe->tuner_priv;
208+ if (dev == NULL)
209+ return -ENODEV;
210+
211+ *ber = dev->ber;
212+
213+ LEAVE();
214+ return 0;
215+}
216+
217+static int as102_fe_read_signal_strength(struct dvb_frontend *fe,
218+ u16 *strength)
219+{
220+ struct as102_dev_t *dev;
221+
222+ ENTER();
223+
224+ dev = (struct as102_dev_t *) fe->tuner_priv;
225+ if (dev == NULL)
226+ return -ENODEV;
227+
228+ *strength = (((0xffff * 400) * dev->signal_strength + 41000) * 2);
229+
230+ LEAVE();
231+ return 0;
232+}
233+
234+static int as102_fe_read_ucblocks(struct dvb_frontend *fe, u32 *ucblocks)
235+{
236+ struct as102_dev_t *dev;
237+
238+ ENTER();
239+
240+ dev = (struct as102_dev_t *) fe->tuner_priv;
241+ if (dev == NULL)
242+ return -ENODEV;
243+
244+ if (dev->demod_stats.has_started)
245+ *ucblocks = dev->demod_stats.bad_frame_count;
246+ else
247+ *ucblocks = 0;
248+
249+ LEAVE();
250+ return 0;
251+}
252+
253+static int as102_fe_ts_bus_ctrl(struct dvb_frontend *fe, int acquire)
254+{
255+ struct as102_dev_t *dev;
256+ int ret;
257+
258+ ENTER();
259+
260+ dev = (struct as102_dev_t *) fe->tuner_priv;
261+ if (dev == NULL)
262+ return -ENODEV;
263+
264+ if (mutex_lock_interruptible(&dev->bus_adap.lock))
265+ return -EBUSY;
266+
267+ if (acquire) {
268+ if (elna_enable)
269+ as10x_cmd_set_context(&dev->bus_adap, 1010, 0xC0);
270+
271+ ret = as10x_cmd_turn_on(&dev->bus_adap);
272+ } else {
273+ ret = as10x_cmd_turn_off(&dev->bus_adap);
274+ }
275+
276+ mutex_unlock(&dev->bus_adap.lock);
277+
278+ LEAVE();
279+ return ret;
280+}
281+
282+static struct dvb_frontend_ops as102_fe_ops = {
283+ .info = {
284+ .name = "Unknown AS102 device",
285+ .type = FE_OFDM,
286+ .frequency_min = 174000000,
287+ .frequency_max = 862000000,
288+ .frequency_stepsize = 166667,
289+ .caps = FE_CAN_INVERSION_AUTO
290+ | FE_CAN_FEC_1_2 | FE_CAN_FEC_2_3 | FE_CAN_FEC_3_4
291+ | FE_CAN_FEC_5_6 | FE_CAN_FEC_7_8 | FE_CAN_FEC_AUTO
292+ | FE_CAN_QAM_16 | FE_CAN_QAM_64 | FE_CAN_QPSK
293+ | FE_CAN_QAM_AUTO
294+ | FE_CAN_TRANSMISSION_MODE_AUTO
295+ | FE_CAN_GUARD_INTERVAL_AUTO
296+ | FE_CAN_HIERARCHY_AUTO
297+ | FE_CAN_RECOVER
298+ | FE_CAN_MUTE_TS
299+ },
300+
301+ .set_frontend = as102_fe_set_frontend,
302+ .get_frontend = as102_fe_get_frontend,
303+ .get_tune_settings = as102_fe_get_tune_settings,
304+
305+ .read_status = as102_fe_read_status,
306+ .read_snr = as102_fe_read_snr,
307+ .read_ber = as102_fe_read_ber,
308+ .read_signal_strength = as102_fe_read_signal_strength,
309+ .read_ucblocks = as102_fe_read_ucblocks,
310+ .ts_bus_ctrl = as102_fe_ts_bus_ctrl,
311+};
312+
313+int as102_dvb_unregister_fe(struct dvb_frontend *fe)
314+{
315+ /* unregister frontend */
316+ dvb_unregister_frontend(fe);
317+
318+ /* detach frontend */
319+ dvb_frontend_detach(fe);
320+
321+ return 0;
322+}
323+
324+int as102_dvb_register_fe(struct as102_dev_t *as102_dev,
325+ struct dvb_frontend *dvb_fe)
326+{
327+ int errno;
328+ struct dvb_adapter *dvb_adap;
329+
330+ if (as102_dev == NULL)
331+ return -EINVAL;
332+
333+ /* extract dvb_adapter */
334+ dvb_adap = &as102_dev->dvb_adap;
335+
336+ /* init frontend callback ops */
337+ memcpy(&dvb_fe->ops, &as102_fe_ops, sizeof(struct dvb_frontend_ops));
338+ strncpy(dvb_fe->ops.info.name, as102_dev->name,
339+ sizeof(dvb_fe->ops.info.name));
340+
341+ /* register dbvb frontend */
342+ errno = dvb_register_frontend(dvb_adap, dvb_fe);
343+ if (errno == 0)
344+ dvb_fe->tuner_priv = as102_dev;
345+
346+ return errno;
347+}
348+
349+static void as10x_fe_copy_tps_parameters(struct dvb_frontend_parameters *dst,
350+ struct as10x_tps *as10x_tps)
351+{
352+
353+ struct dvb_ofdm_parameters *fe_tps = &dst->u.ofdm;
354+
355+ /* extract consteallation */
356+ switch (as10x_tps->constellation) {
357+ case CONST_QPSK:
358+ fe_tps->constellation = QPSK;
359+ break;
360+ case CONST_QAM16:
361+ fe_tps->constellation = QAM_16;
362+ break;
363+ case CONST_QAM64:
364+ fe_tps->constellation = QAM_64;
365+ break;
366+ }
367+
368+ /* extract hierarchy */
369+ switch (as10x_tps->hierarchy) {
370+ case HIER_NONE:
371+ fe_tps->hierarchy_information = HIERARCHY_NONE;
372+ break;
373+ case HIER_ALPHA_1:
374+ fe_tps->hierarchy_information = HIERARCHY_1;
375+ break;
376+ case HIER_ALPHA_2:
377+ fe_tps->hierarchy_information = HIERARCHY_2;
378+ break;
379+ case HIER_ALPHA_4:
380+ fe_tps->hierarchy_information = HIERARCHY_4;
381+ break;
382+ }
383+
384+ /* extract code rate HP */
385+ switch (as10x_tps->code_rate_HP) {
386+ case CODE_RATE_1_2:
387+ fe_tps->code_rate_HP = FEC_1_2;
388+ break;
389+ case CODE_RATE_2_3:
390+ fe_tps->code_rate_HP = FEC_2_3;
391+ break;
392+ case CODE_RATE_3_4:
393+ fe_tps->code_rate_HP = FEC_3_4;
394+ break;
395+ case CODE_RATE_5_6:
396+ fe_tps->code_rate_HP = FEC_5_6;
397+ break;
398+ case CODE_RATE_7_8:
399+ fe_tps->code_rate_HP = FEC_7_8;
400+ break;
401+ }
402+
403+ /* extract code rate LP */
404+ switch (as10x_tps->code_rate_LP) {
405+ case CODE_RATE_1_2:
406+ fe_tps->code_rate_LP = FEC_1_2;
407+ break;
408+ case CODE_RATE_2_3:
409+ fe_tps->code_rate_LP = FEC_2_3;
410+ break;
411+ case CODE_RATE_3_4:
412+ fe_tps->code_rate_LP = FEC_3_4;
413+ break;
414+ case CODE_RATE_5_6:
415+ fe_tps->code_rate_LP = FEC_5_6;
416+ break;
417+ case CODE_RATE_7_8:
418+ fe_tps->code_rate_LP = FEC_7_8;
419+ break;
420+ }
421+
422+ /* extract guard interval */
423+ switch (as10x_tps->guard_interval) {
424+ case GUARD_INT_1_32:
425+ fe_tps->guard_interval = GUARD_INTERVAL_1_32;
426+ break;
427+ case GUARD_INT_1_16:
428+ fe_tps->guard_interval = GUARD_INTERVAL_1_16;
429+ break;
430+ case GUARD_INT_1_8:
431+ fe_tps->guard_interval = GUARD_INTERVAL_1_8;
432+ break;
433+ case GUARD_INT_1_4:
434+ fe_tps->guard_interval = GUARD_INTERVAL_1_4;
435+ break;
436+ }
437+
438+ /* extract transmission mode */
439+ switch (as10x_tps->transmission_mode) {
440+ case TRANS_MODE_2K:
441+ fe_tps->transmission_mode = TRANSMISSION_MODE_2K;
442+ break;
443+ case TRANS_MODE_8K:
444+ fe_tps->transmission_mode = TRANSMISSION_MODE_8K;
445+ break;
446+ }
447+}
448+
449+static uint8_t as102_fe_get_code_rate(fe_code_rate_t arg)
450+{
451+ uint8_t c;
452+
453+ switch (arg) {
454+ case FEC_1_2:
455+ c = CODE_RATE_1_2;
456+ break;
457+ case FEC_2_3:
458+ c = CODE_RATE_2_3;
459+ break;
460+ case FEC_3_4:
461+ c = CODE_RATE_3_4;
462+ break;
463+ case FEC_5_6:
464+ c = CODE_RATE_5_6;
465+ break;
466+ case FEC_7_8:
467+ c = CODE_RATE_7_8;
468+ break;
469+ default:
470+ c = CODE_RATE_UNKNOWN;
471+ break;
472+ }
473+
474+ return c;
475+}
476+
477+static void as102_fe_copy_tune_parameters(struct as10x_tune_args *tune_args,
478+ struct dvb_frontend_parameters *params)
479+{
480+
481+ /* set frequency */
482+ tune_args->freq = params->frequency / 1000;
483+
484+ /* fix interleaving_mode */
485+ tune_args->interleaving_mode = INTLV_NATIVE;
486+
487+ switch (params->u.ofdm.bandwidth) {
488+ case BANDWIDTH_8_MHZ:
489+ tune_args->bandwidth = BW_8_MHZ;
490+ break;
491+ case BANDWIDTH_7_MHZ:
492+ tune_args->bandwidth = BW_7_MHZ;
493+ break;
494+ case BANDWIDTH_6_MHZ:
495+ tune_args->bandwidth = BW_6_MHZ;
496+ break;
497+ default:
498+ tune_args->bandwidth = BW_8_MHZ;
499+ }
500+
501+ switch (params->u.ofdm.guard_interval) {
502+ case GUARD_INTERVAL_1_32:
503+ tune_args->guard_interval = GUARD_INT_1_32;
504+ break;
505+ case GUARD_INTERVAL_1_16:
506+ tune_args->guard_interval = GUARD_INT_1_16;
507+ break;
508+ case GUARD_INTERVAL_1_8:
509+ tune_args->guard_interval = GUARD_INT_1_8;
510+ break;
511+ case GUARD_INTERVAL_1_4:
512+ tune_args->guard_interval = GUARD_INT_1_4;
513+ break;
514+ case GUARD_INTERVAL_AUTO:
515+ default:
516+ tune_args->guard_interval = GUARD_UNKNOWN;
517+ break;
518+ }
519+
520+ switch (params->u.ofdm.constellation) {
521+ case QPSK:
522+ tune_args->constellation = CONST_QPSK;
523+ break;
524+ case QAM_16:
525+ tune_args->constellation = CONST_QAM16;
526+ break;
527+ case QAM_64:
528+ tune_args->constellation = CONST_QAM64;
529+ break;
530+ default:
531+ tune_args->constellation = CONST_UNKNOWN;
532+ break;
533+ }
534+
535+ switch (params->u.ofdm.transmission_mode) {
536+ case TRANSMISSION_MODE_2K:
537+ tune_args->transmission_mode = TRANS_MODE_2K;
538+ break;
539+ case TRANSMISSION_MODE_8K:
540+ tune_args->transmission_mode = TRANS_MODE_8K;
541+ break;
542+ default:
543+ tune_args->transmission_mode = TRANS_MODE_UNKNOWN;
544+ }
545+
546+ switch (params->u.ofdm.hierarchy_information) {
547+ case HIERARCHY_NONE:
548+ tune_args->hierarchy = HIER_NONE;
549+ break;
550+ case HIERARCHY_1:
551+ tune_args->hierarchy = HIER_ALPHA_1;
552+ break;
553+ case HIERARCHY_2:
554+ tune_args->hierarchy = HIER_ALPHA_2;
555+ break;
556+ case HIERARCHY_4:
557+ tune_args->hierarchy = HIER_ALPHA_4;
558+ break;
559+ case HIERARCHY_AUTO:
560+ tune_args->hierarchy = HIER_UNKNOWN;
561+ break;
562+ }
563+
564+ dprintk(debug, "tuner parameters: freq: %d bw: 0x%02x gi: 0x%02x\n",
565+ params->frequency,
566+ tune_args->bandwidth,
567+ tune_args->guard_interval);
568+
569+ /*
570+ * Detect a hierarchy selection
571+ * if HP/LP are both set to FEC_NONE, HP will be selected.
572+ */
573+ if ((tune_args->hierarchy != HIER_NONE) &&
574+ ((params->u.ofdm.code_rate_LP == FEC_NONE) ||
575+ (params->u.ofdm.code_rate_HP == FEC_NONE))) {
576+
577+ if (params->u.ofdm.code_rate_LP == FEC_NONE) {
578+ tune_args->hier_select = HIER_HIGH_PRIORITY;
579+ tune_args->code_rate =
580+ as102_fe_get_code_rate(params->u.ofdm.code_rate_HP);
581+ }
582+
583+ if (params->u.ofdm.code_rate_HP == FEC_NONE) {
584+ tune_args->hier_select = HIER_LOW_PRIORITY;
585+ tune_args->code_rate =
586+ as102_fe_get_code_rate(params->u.ofdm.code_rate_LP);
587+ }
588+
589+ dprintk(debug, "\thierarchy: 0x%02x "
590+ "selected: %s code_rate_%s: 0x%02x\n",
591+ tune_args->hierarchy,
592+ tune_args->hier_select == HIER_HIGH_PRIORITY ?
593+ "HP" : "LP",
594+ tune_args->hier_select == HIER_HIGH_PRIORITY ?
595+ "HP" : "LP",
596+ tune_args->code_rate);
597+ } else {
598+ tune_args->code_rate =
599+ as102_fe_get_code_rate(params->u.ofdm.code_rate_HP);
600+ }
601+}
602+
603+/* EOF - vim: set textwidth=80 ts=8 sw=8 sts=8 noet: */
drivers/staging/media/as102/as102_fw.c+251−0
@@ -0,0 +1,251 @@
1+/*
2+ * Abilis Systems Single DVB-T Receiver
3+ * Copyright (C) 2008 Pierrick Hascoet <pierrick.hascoet@abilis.com>
4+ * Copyright (C) 2010 Devin Heitmueller <dheitmueller@kernellabs.com>
5+ *
6+ * This program is free software; you can redistribute it and/or modify
7+ * it under the terms of the GNU General Public License as published by
8+ * the Free Software Foundation; either version 2, or (at your option)
9+ * any later version.
10+ *
11+ * This program is distributed in the hope that it will be useful,
12+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
13+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+ * GNU General Public License for more details.
15+ *
16+ * You should have received a copy of the GNU General Public License
17+ * along with this program; if not, write to the Free Software
18+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19+ */
20+#include <linux/kernel.h>
21+#include <linux/errno.h>
22+#include <linux/ctype.h>
23+#include <linux/delay.h>
24+#include <linux/firmware.h>
25+
26+#include "as102_drv.h"
27+#include "as102_fw.h"
28+
29+#if defined(CONFIG_FW_LOADER) || defined(CONFIG_FW_LOADER_MODULE)
30+char as102_st_fw1[] = "as102_data1_st.hex";
31+char as102_st_fw2[] = "as102_data2_st.hex";
32+char as102_dt_fw1[] = "as102_data1_dt.hex";
33+char as102_dt_fw2[] = "as102_data2_dt.hex";
34+
35+static unsigned char atohx(unsigned char *dst, char *src)
36+{
37+ unsigned char value = 0;
38+
39+ char msb = tolower(*src) - '0';
40+ char lsb = tolower(*(src + 1)) - '0';
41+
42+ if (msb > 9)
43+ msb -= 7;
44+ if (lsb > 9)
45+ lsb -= 7;
46+
47+ *dst = value = ((msb & 0xF) << 4) | (lsb & 0xF);
48+ return value;
49+}
50+
51+/*
52+ * Parse INTEL HEX firmware file to extract address and data.
53+ */
54+static int parse_hex_line(unsigned char *fw_data, unsigned char *addr,
55+ unsigned char *data, int *dataLength,
56+ unsigned char *addr_has_changed) {
57+
58+ int count = 0;
59+ unsigned char *src, dst;
60+
61+ if (*fw_data++ != ':') {
62+ printk(KERN_ERR "invalid firmware file\n");
63+ return -EFAULT;
64+ }
65+
66+ /* locate end of line */
67+ for (src = fw_data; *src != '\n'; src += 2) {
68+ atohx(&dst, src);
69+ /* parse line to split addr / data */
70+ switch (count) {
71+ case 0:
72+ *dataLength = dst;
73+ break;
74+ case 1:
75+ addr[2] = dst;
76+ break;
77+ case 2:
78+ addr[3] = dst;
79+ break;
80+ case 3:
81+ /* check if data is an address */
82+ if (dst == 0x04)
83+ *addr_has_changed = 1;
84+ else
85+ *addr_has_changed = 0;
86+ break;
87+ case 4:
88+ case 5:
89+ if (*addr_has_changed)
90+ addr[(count - 4)] = dst;
91+ else
92+ data[(count - 4)] = dst;
93+ break;
94+ default:
95+ data[(count - 4)] = dst;
96+ break;
97+ }
98+ count++;
99+ }
100+
101+ /* return read value + ':' + '\n' */
102+ return (count * 2) + 2;
103+}
104+
105+static int as102_firmware_upload(struct as102_bus_adapter_t *bus_adap,
106+ unsigned char *cmd,
107+ const struct firmware *firmware) {
108+
109+ struct as10x_fw_pkt_t fw_pkt;
110+ int total_read_bytes = 0, errno = 0;
111+ unsigned char addr_has_changed = 0;
112+
113+ ENTER();
114+
115+ for (total_read_bytes = 0; total_read_bytes < firmware->size; ) {
116+ int read_bytes = 0, data_len = 0;
117+
118+ /* parse intel hex line */
119+ read_bytes = parse_hex_line(
120+ (u8 *) (firmware->data + total_read_bytes),
121+ fw_pkt.raw.address,
122+ fw_pkt.raw.data,
123+ &data_len,
124+ &addr_has_changed);
125+
126+ if (read_bytes <= 0)
127+ goto error;
128+
129+ /* detect the end of file */
130+ total_read_bytes += read_bytes;
131+ if (total_read_bytes == firmware->size) {
132+ fw_pkt.u.request[0] = 0x00;
133+ fw_pkt.u.request[1] = 0x03;
134+
135+ /* send EOF command */
136+ errno = bus_adap->ops->upload_fw_pkt(bus_adap,
137+ (uint8_t *)
138+ &fw_pkt, 2, 0);
139+ if (errno < 0)
140+ goto error;
141+ } else {
142+ if (!addr_has_changed) {
143+ /* prepare command to send */
144+ fw_pkt.u.request[0] = 0x00;
145+ fw_pkt.u.request[1] = 0x01;
146+
147+ data_len += sizeof(fw_pkt.u.request);
148+ data_len += sizeof(fw_pkt.raw.address);
149+
150+ /* send cmd to device */
151+ errno = bus_adap->ops->upload_fw_pkt(bus_adap,
152+ (uint8_t *)
153+ &fw_pkt,
154+ data_len,
155+ 0);
156+ if (errno < 0)
157+ goto error;
158+ }
159+ }
160+ }
161+error:
162+ LEAVE();
163+ return (errno == 0) ? total_read_bytes : errno;
164+}
165+
166+int as102_fw_upload(struct as102_bus_adapter_t *bus_adap)
167+{
168+ int errno = -EFAULT;
169+ const struct firmware *firmware;
170+ unsigned char *cmd_buf = NULL;
171+ char *fw1, *fw2;
172+
173+#if defined(CONFIG_AS102_USB)
174+ struct usb_device *dev = bus_adap->usb_dev;
175+#endif
176+#if defined(CONFIG_AS102_SPI)
177+ struct spi_device *dev = bus_adap->spi_dev;
178+#endif
179+ ENTER();
180+
181+ /* select fw file to upload */
182+ if (dual_tuner) {
183+ fw1 = as102_dt_fw1;
184+ fw2 = as102_dt_fw2;
185+ } else {
186+ fw1 = as102_st_fw1;
187+ fw2 = as102_st_fw2;
188+ }
189+
190+#if defined(CONFIG_FW_LOADER) || defined(CONFIG_FW_LOADER_MODULE)
191+ /* allocate buffer to store firmware upload command and data */
192+ cmd_buf = kzalloc(MAX_FW_PKT_SIZE, GFP_KERNEL);
193+ if (cmd_buf == NULL) {
194+ errno = -ENOMEM;
195+ goto error;
196+ }
197+
198+ /* request kernel to locate firmware file: part1 */
199+ errno = request_firmware(&firmware, fw1, &dev->dev);
200+ if (errno < 0) {
201+ printk(KERN_ERR "%s: unable to locate firmware file: %s\n",
202+ DRIVER_NAME, fw1);
203+ goto error;
204+ }
205+
206+ /* initiate firmware upload */
207+ errno = as102_firmware_upload(bus_adap, cmd_buf, firmware);
208+ if (errno < 0) {
209+ printk(KERN_ERR "%s: error during firmware upload part1\n",
210+ DRIVER_NAME);
211+ goto error;
212+ }
213+
214+ printk(KERN_INFO "%s: fimrware: %s loaded with success\n",
215+ DRIVER_NAME, fw1);
216+ release_firmware(firmware);
217+
218+ /* wait for boot to complete */
219+ mdelay(100);
220+
221+ /* request kernel to locate firmware file: part2 */
222+ errno = request_firmware(&firmware, fw2, &dev->dev);
223+ if (errno < 0) {
224+ printk(KERN_ERR "%s: unable to locate firmware file: %s\n",
225+ DRIVER_NAME, fw2);
226+ goto error;
227+ }
228+
229+ /* initiate firmware upload */
230+ errno = as102_firmware_upload(bus_adap, cmd_buf, firmware);
231+ if (errno < 0) {
232+ printk(KERN_ERR "%s: error during firmware upload part2\n",
233+ DRIVER_NAME);
234+ goto error;
235+ }
236+
237+ printk(KERN_INFO "%s: fimrware: %s loaded with success\n",
238+ DRIVER_NAME, fw2);
239+error:
240+ /* free data buffer */
241+ kfree(cmd_buf);
242+ /* release firmware if needed */
243+ if (firmware != NULL)
244+ release_firmware(firmware);
245+#endif
246+ LEAVE();
247+ return errno;
248+}
249+#endif
250+
251+/* EOF - vim: set textwidth=80 ts=8 sw=8 sts=8 noet: */
drivers/staging/media/as102/as102_fw.h+42−0
@@ -0,0 +1,42 @@
1+/*
2+ * Abilis Systems Single DVB-T Receiver
3+ * Copyright (C) 2008 Pierrick Hascoet <pierrick.hascoet@abilis.com>
4+ *
5+ * This program is free software; you can redistribute it and/or modify
6+ * it under the terms of the GNU General Public License as published by
7+ * the Free Software Foundation; either version 2, or (at your option)
8+ * any later version.
9+ *
10+ * This program is distributed in the hope that it will be useful,
11+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
12+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+ * GNU General Public License for more details.
14+ *
15+ * You should have received a copy of the GNU General Public License
16+ * along with this program; if not, write to the Free Software
17+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18+ */
19+#define MAX_FW_PKT_SIZE 64
20+
21+extern int dual_tuner;
22+
23+#pragma pack(1)
24+struct as10x_raw_fw_pkt {
25+ unsigned char address[4];
26+ unsigned char data[MAX_FW_PKT_SIZE - 6];
27+};
28+
29+struct as10x_fw_pkt_t {
30+ union {
31+ unsigned char request[2];
32+ unsigned char length[2];
33+ } u;
34+ struct as10x_raw_fw_pkt raw;
35+};
36+#pragma pack()
37+
38+#ifdef __KERNEL__
39+int as102_fw_upload(struct as102_bus_adapter_t *bus_adap);
40+#endif
41+
42+/* EOF - vim: set textwidth=80 ts=8 sw=8 sts=8 noet: */
drivers/staging/media/as102/as102_usb_drv.c+478−0
@@ -0,0 +1,478 @@
1+/*
2+ * Abilis Systems Single DVB-T Receiver
3+ * Copyright (C) 2008 Pierrick Hascoet <pierrick.hascoet@abilis.com>
4+ * Copyright (C) 2010 Devin Heitmueller <dheitmueller@kernellabs.com>
5+ *
6+ * This program is free software; you can redistribute it and/or modify
7+ * it under the terms of the GNU General Public License as published by
8+ * the Free Software Foundation; either version 2, or (at your option)
9+ * any later version.
10+ *
11+ * This program is distributed in the hope that it will be useful,
12+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
13+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+ * GNU General Public License for more details.
15+ *
16+ * You should have received a copy of the GNU General Public License
17+ * along with this program; if not, write to the Free Software
18+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19+ */
20+#include <linux/kernel.h>
21+#include <linux/errno.h>
22+#include <linux/slab.h>
23+#include <linux/mm.h>
24+#include <linux/usb.h>
25+
26+#include "as102_drv.h"
27+#include "as102_usb_drv.h"
28+#include "as102_fw.h"
29+
30+static void as102_usb_disconnect(struct usb_interface *interface);
31+static int as102_usb_probe(struct usb_interface *interface,
32+ const struct usb_device_id *id);
33+
34+static int as102_usb_start_stream(struct as102_dev_t *dev);
35+static void as102_usb_stop_stream(struct as102_dev_t *dev);
36+
37+static int as102_open(struct inode *inode, struct file *file);
38+static int as102_release(struct inode *inode, struct file *file);
39+
40+static struct usb_device_id as102_usb_id_table[] = {
41+ { USB_DEVICE(AS102_USB_DEVICE_VENDOR_ID, AS102_USB_DEVICE_PID_0001) },
42+ { USB_DEVICE(PCTV_74E_USB_VID, PCTV_74E_USB_PID) },
43+ { USB_DEVICE(ELGATO_EYETV_DTT_USB_VID, ELGATO_EYETV_DTT_USB_PID) },
44+ { USB_DEVICE(NBOX_DVBT_DONGLE_USB_VID, NBOX_DVBT_DONGLE_USB_PID) },
45+ { } /* Terminating entry */
46+};
47+
48+/* Note that this table must always have the same number of entries as the
49+ as102_usb_id_table struct */
50+static const char *as102_device_names[] = {
51+ AS102_REFERENCE_DESIGN,
52+ AS102_PCTV_74E,
53+ AS102_ELGATO_EYETV_DTT_NAME,
54+ AS102_NBOX_DVBT_DONGLE_NAME,
55+ NULL /* Terminating entry */
56+};
57+
58+struct usb_driver as102_usb_driver = {
59+ .name = DRIVER_FULL_NAME,
60+ .probe = as102_usb_probe,
61+ .disconnect = as102_usb_disconnect,
62+ .id_table = as102_usb_id_table
63+};
64+
65+static const struct file_operations as102_dev_fops = {
66+ .owner = THIS_MODULE,
67+ .open = as102_open,
68+ .release = as102_release,
69+};
70+
71+static struct usb_class_driver as102_usb_class_driver = {
72+ .name = "aton2-%d",
73+ .fops = &as102_dev_fops,
74+ .minor_base = AS102_DEVICE_MAJOR,
75+};
76+
77+static int as102_usb_xfer_cmd(struct as102_bus_adapter_t *bus_adap,
78+ unsigned char *send_buf, int send_buf_len,
79+ unsigned char *recv_buf, int recv_buf_len)
80+{
81+ int ret = 0;
82+ ENTER();
83+
84+ if (send_buf != NULL) {
85+ ret = usb_control_msg(bus_adap->usb_dev,
86+ usb_sndctrlpipe(bus_adap->usb_dev, 0),
87+ AS102_USB_DEVICE_TX_CTRL_CMD,
88+ USB_DIR_OUT | USB_TYPE_VENDOR |
89+ USB_RECIP_DEVICE,
90+ bus_adap->cmd_xid, /* value */
91+ 0, /* index */
92+ send_buf, send_buf_len,
93+ USB_CTRL_SET_TIMEOUT /* 200 */);
94+ if (ret < 0) {
95+ dprintk(debug, "usb_control_msg(send) failed, err %i\n",
96+ ret);
97+ return ret;
98+ }
99+
100+ if (ret != send_buf_len) {
101+ dprintk(debug, "only wrote %d of %d bytes\n",
102+ ret, send_buf_len);
103+ return -1;
104+ }
105+ }
106+
107+ if (recv_buf != NULL) {
108+#ifdef TRACE
109+ dprintk(debug, "want to read: %d bytes\n", recv_buf_len);
110+#endif
111+ ret = usb_control_msg(bus_adap->usb_dev,
112+ usb_rcvctrlpipe(bus_adap->usb_dev, 0),
113+ AS102_USB_DEVICE_RX_CTRL_CMD,
114+ USB_DIR_IN | USB_TYPE_VENDOR |
115+ USB_RECIP_DEVICE,
116+ bus_adap->cmd_xid, /* value */
117+ 0, /* index */
118+ recv_buf, recv_buf_len,
119+ USB_CTRL_GET_TIMEOUT /* 200 */);
120+ if (ret < 0) {
121+ dprintk(debug, "usb_control_msg(recv) failed, err %i\n",
122+ ret);
123+ return ret;
124+ }
125+#ifdef TRACE
126+ dprintk(debug, "read %d bytes\n", recv_buf_len);
127+#endif
128+ }
129+
130+ LEAVE();
131+ return ret;
132+}
133+
134+static int as102_send_ep1(struct as102_bus_adapter_t *bus_adap,
135+ unsigned char *send_buf,
136+ int send_buf_len,
137+ int swap32)
138+{
139+ int ret = 0, actual_len;
140+
141+ ret = usb_bulk_msg(bus_adap->usb_dev,
142+ usb_sndbulkpipe(bus_adap->usb_dev, 1),
143+ send_buf, send_buf_len, &actual_len, 200);
144+ if (ret) {
145+ dprintk(debug, "usb_bulk_msg(send) failed, err %i\n", ret);
146+ return ret;
147+ }
148+
149+ if (actual_len != send_buf_len) {
150+ dprintk(debug, "only wrote %d of %d bytes\n",
151+ actual_len, send_buf_len);
152+ return -1;
153+ }
154+ return ret ? ret : actual_len;
155+}
156+
157+static int as102_read_ep2(struct as102_bus_adapter_t *bus_adap,
158+ unsigned char *recv_buf, int recv_buf_len)
159+{
160+ int ret = 0, actual_len;
161+
162+ if (recv_buf == NULL)
163+ return -EINVAL;
164+
165+ ret = usb_bulk_msg(bus_adap->usb_dev,
166+ usb_rcvbulkpipe(bus_adap->usb_dev, 2),
167+ recv_buf, recv_buf_len, &actual_len, 200);
168+ if (ret) {
169+ dprintk(debug, "usb_bulk_msg(recv) failed, err %i\n", ret);
170+ return ret;
171+ }
172+
173+ if (actual_len != recv_buf_len) {
174+ dprintk(debug, "only read %d of %d bytes\n",
175+ actual_len, recv_buf_len);
176+ return -1;
177+ }
178+ return ret ? ret : actual_len;
179+}
180+
181+struct as102_priv_ops_t as102_priv_ops = {
182+ .upload_fw_pkt = as102_send_ep1,
183+ .xfer_cmd = as102_usb_xfer_cmd,
184+ .as102_read_ep2 = as102_read_ep2,
185+ .start_stream = as102_usb_start_stream,
186+ .stop_stream = as102_usb_stop_stream,
187+};
188+
189+static int as102_submit_urb_stream(struct as102_dev_t *dev, struct urb *urb)
190+{
191+ int err;
192+
193+ usb_fill_bulk_urb(urb,
194+ dev->bus_adap.usb_dev,
195+ usb_rcvbulkpipe(dev->bus_adap.usb_dev, 0x2),
196+ urb->transfer_buffer,
197+ AS102_USB_BUF_SIZE,
198+ as102_urb_stream_irq,
199+ dev);
200+
201+ err = usb_submit_urb(urb, GFP_ATOMIC);
202+ if (err)
203+ dprintk(debug, "%s: usb_submit_urb failed\n", __func__);
204+
205+ return err;
206+}
207+
208+void as102_urb_stream_irq(struct urb *urb)
209+{
210+ struct as102_dev_t *as102_dev = urb->context;
211+
212+ if (urb->actual_length > 0) {
213+ dvb_dmx_swfilter(&as102_dev->dvb_dmx,
214+ urb->transfer_buffer,
215+ urb->actual_length);
216+ } else {
217+ if (urb->actual_length == 0)
218+ memset(urb->transfer_buffer, 0, AS102_USB_BUF_SIZE);
219+ }
220+
221+ /* is not stopped, re-submit urb */
222+ if (as102_dev->streaming)
223+ as102_submit_urb_stream(as102_dev, urb);
224+}
225+
226+static void as102_free_usb_stream_buffer(struct as102_dev_t *dev)
227+{
228+ int i;
229+
230+ ENTER();
231+
232+ for (i = 0; i < MAX_STREAM_URB; i++)
233+ usb_free_urb(dev->stream_urb[i]);
234+
235+ usb_free_coherent(dev->bus_adap.usb_dev,
236+ MAX_STREAM_URB * AS102_USB_BUF_SIZE,
237+ dev->stream,
238+ dev->dma_addr);
239+ LEAVE();
240+}
241+
242+static int as102_alloc_usb_stream_buffer(struct as102_dev_t *dev)
243+{
244+ int i, ret = 0;
245+
246+ ENTER();
247+
248+ dev->stream = usb_alloc_coherent(dev->bus_adap.usb_dev,
249+ MAX_STREAM_URB * AS102_USB_BUF_SIZE,
250+ GFP_KERNEL,
251+ &dev->dma_addr);
252+ if (!dev->stream) {
253+ dprintk(debug, "%s: usb_buffer_alloc failed\n", __func__);
254+ return -ENOMEM;
255+ }
256+
257+ memset(dev->stream, 0, MAX_STREAM_URB * AS102_USB_BUF_SIZE);
258+
259+ /* init urb buffers */
260+ for (i = 0; i < MAX_STREAM_URB; i++) {
261+ struct urb *urb;
262+
263+ urb = usb_alloc_urb(0, GFP_ATOMIC);
264+ if (urb == NULL) {
265+ dprintk(debug, "%s: usb_alloc_urb failed\n", __func__);
266+ as102_free_usb_stream_buffer(dev);
267+ return -ENOMEM;
268+ }
269+
270+ urb->transfer_buffer = dev->stream + (i * AS102_USB_BUF_SIZE);
271+ urb->transfer_buffer_length = AS102_USB_BUF_SIZE;
272+
273+ dev->stream_urb[i] = urb;
274+ }
275+ LEAVE();
276+ return ret;
277+}
278+
279+static void as102_usb_stop_stream(struct as102_dev_t *dev)
280+{
281+ int i;
282+
283+ for (i = 0; i < MAX_STREAM_URB; i++)
284+ usb_kill_urb(dev->stream_urb[i]);
285+}
286+
287+static int as102_usb_start_stream(struct as102_dev_t *dev)
288+{
289+ int i, ret = 0;
290+
291+ for (i = 0; i < MAX_STREAM_URB; i++) {
292+ ret = as102_submit_urb_stream(dev, dev->stream_urb[i]);
293+ if (ret) {
294+ as102_usb_stop_stream(dev);
295+ return ret;
296+ }
297+ }
298+
299+ return 0;
300+}
301+
302+static void as102_usb_release(struct kref *kref)
303+{
304+ struct as102_dev_t *as102_dev;
305+
306+ ENTER();
307+
308+ as102_dev = container_of(kref, struct as102_dev_t, kref);
309+ if (as102_dev != NULL) {
310+ usb_put_dev(as102_dev->bus_adap.usb_dev);
311+ kfree(as102_dev);
312+ }
313+
314+ LEAVE();
315+}
316+
317+static void as102_usb_disconnect(struct usb_interface *intf)
318+{
319+ struct as102_dev_t *as102_dev;
320+
321+ ENTER();
322+
323+ /* extract as102_dev_t from usb_device private data */
324+ as102_dev = usb_get_intfdata(intf);
325+
326+ /* unregister dvb layer */
327+ as102_dvb_unregister(as102_dev);
328+
329+ /* free usb buffers */
330+ as102_free_usb_stream_buffer(as102_dev);
331+
332+ usb_set_intfdata(intf, NULL);
333+
334+ /* usb unregister device */
335+ usb_deregister_dev(intf, &as102_usb_class_driver);
336+
337+ /* decrement usage counter */
338+ kref_put(&as102_dev->kref, as102_usb_release);
339+
340+ printk(KERN_INFO "%s: device has been disconnected\n", DRIVER_NAME);
341+
342+ LEAVE();
343+}
344+
345+static int as102_usb_probe(struct usb_interface *intf,
346+ const struct usb_device_id *id)
347+{
348+ int ret;
349+ struct as102_dev_t *as102_dev;
350+ int i;
351+
352+ ENTER();
353+
354+ as102_dev = kzalloc(sizeof(struct as102_dev_t), GFP_KERNEL);
355+ if (as102_dev == NULL) {
356+ err("%s: kzalloc failed", __func__);
357+ return -ENOMEM;
358+ }
359+
360+ /* This should never actually happen */
361+ if ((sizeof(as102_usb_id_table) / sizeof(struct usb_device_id)) !=
362+ (sizeof(as102_device_names) / sizeof(const char *))) {
363+ printk(KERN_ERR "Device names table invalid size");
364+ return -EINVAL;
365+ }
366+
367+ /* Assign the user-friendly device name */
368+ for (i = 0; i < (sizeof(as102_usb_id_table) /
369+ sizeof(struct usb_device_id)); i++) {
370+ if (id == &as102_usb_id_table[i])
371+ as102_dev->name = as102_device_names[i];
372+ }
373+
374+ if (as102_dev->name == NULL)
375+ as102_dev->name = "Unknown AS102 device";
376+
377+ /* set private callback functions */
378+ as102_dev->bus_adap.ops = &as102_priv_ops;
379+
380+ /* init cmd token for usb bus */
381+ as102_dev->bus_adap.cmd = &as102_dev->bus_adap.token.usb.c;
382+ as102_dev->bus_adap.rsp = &as102_dev->bus_adap.token.usb.r;
383+
384+ /* init kernel device reference */
385+ kref_init(&as102_dev->kref);
386+
387+ /* store as102 device to usb_device private data */
388+ usb_set_intfdata(intf, (void *) as102_dev);
389+
390+ /* store in as102 device the usb_device pointer */
391+ as102_dev->bus_adap.usb_dev = usb_get_dev(interface_to_usbdev(intf));
392+
393+ /* we can register the device now, as it is ready */
394+ ret = usb_register_dev(intf, &as102_usb_class_driver);
395+ if (ret < 0) {
396+ /* something prevented us from registering this driver */
397+ err("%s: usb_register_dev() failed (errno = %d)",
398+ __func__, ret);
399+ goto failed;
400+ }
401+
402+ printk(KERN_INFO "%s: device has been detected\n", DRIVER_NAME);
403+
404+ /* request buffer allocation for streaming */
405+ ret = as102_alloc_usb_stream_buffer(as102_dev);
406+ if (ret != 0)
407+ goto failed;
408+
409+ /* register dvb layer */
410+ ret = as102_dvb_register(as102_dev);
411+
412+ LEAVE();
413+ return ret;
414+
415+failed:
416+ usb_set_intfdata(intf, NULL);
417+ kfree(as102_dev);
418+ return ret;
419+}
420+
421+static int as102_open(struct inode *inode, struct file *file)
422+{
423+ int ret = 0, minor = 0;
424+ struct usb_interface *intf = NULL;
425+ struct as102_dev_t *dev = NULL;
426+
427+ ENTER();
428+
429+ /* read minor from inode */
430+ minor = iminor(inode);
431+
432+ /* fetch device from usb interface */
433+ intf = usb_find_interface(&as102_usb_driver, minor);
434+ if (intf == NULL) {
435+ printk(KERN_ERR "%s: can't find device for minor %d\n",
436+ __func__, minor);
437+ ret = -ENODEV;
438+ goto exit;
439+ }
440+
441+ /* get our device */
442+ dev = usb_get_intfdata(intf);
443+ if (dev == NULL) {
444+ ret = -EFAULT;
445+ goto exit;
446+ }
447+
448+ /* save our device object in the file's private structure */
449+ file->private_data = dev;
450+
451+ /* increment our usage count for the device */
452+ kref_get(&dev->kref);
453+
454+exit:
455+ LEAVE();
456+ return ret;
457+}
458+
459+static int as102_release(struct inode *inode, struct file *file)
460+{
461+ int ret = 0;
462+ struct as102_dev_t *dev = NULL;
463+
464+ ENTER();
465+
466+ dev = file->private_data;
467+ if (dev != NULL) {
468+ /* decrement the count on our device */
469+ kref_put(&dev->kref, as102_usb_release);
470+ }
471+
472+ LEAVE();
473+ return ret;
474+}
475+
476+MODULE_DEVICE_TABLE(usb, as102_usb_id_table);
477+
478+/* EOF - vim: set textwidth=80 ts=8 sw=8 sts=8 noet: */
drivers/staging/media/as102/as102_usb_drv.h+59−0
@@ -0,0 +1,59 @@
1+/*
2+ * Abilis Systems Single DVB-T Receiver
3+ * Copyright (C) 2008 Pierrick Hascoet <pierrick.hascoet@abilis.com>
4+ * Copyright (C) 2010 Devin Heitmueller <dheitmueller@kernellabs.com>
5+ *
6+ * This program is free software; you can redistribute it and/or modify
7+ * it under the terms of the GNU General Public License as published by
8+ * the Free Software Foundation; either version 2, or (at your option)
9+ * any later version.
10+ *
11+ * This program is distributed in the hope that it will be useful,
12+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
13+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+ * GNU General Public License for more details.
15+ *
16+ * You should have received a copy of the GNU General Public License
17+ * along with this program; if not, write to the Free Software
18+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19+ */
20+#include <linux/version.h>
21+
22+#ifndef _AS102_USB_DRV_H_
23+#define _AS102_USB_DRV_H_
24+
25+#define AS102_USB_DEVICE_TX_CTRL_CMD 0xF1
26+#define AS102_USB_DEVICE_RX_CTRL_CMD 0xF2
27+
28+/* define these values to match the supported devices */
29+
30+/* Abilis system: "TITAN" */
31+#define AS102_REFERENCE_DESIGN "Abilis Systems DVB-Titan"
32+#define AS102_USB_DEVICE_VENDOR_ID 0x1BA6
33+#define AS102_USB_DEVICE_PID_0001 0x0001
34+
35+/* PCTV Systems: PCTV picoStick (74e) */
36+#define AS102_PCTV_74E "PCTV Systems picoStick (74e)"
37+#define PCTV_74E_USB_VID 0x2013
38+#define PCTV_74E_USB_PID 0x0246
39+
40+/* Elgato: EyeTV DTT Deluxe */
41+#define AS102_ELGATO_EYETV_DTT_NAME "Elgato EyeTV DTT Deluxe"
42+#define ELGATO_EYETV_DTT_USB_VID 0x0fd9
43+#define ELGATO_EYETV_DTT_USB_PID 0x002c
44+
45+/* nBox: nBox DVB-T Dongle */
46+#define AS102_NBOX_DVBT_DONGLE_NAME "nBox DVB-T Dongle"
47+#define NBOX_DVBT_DONGLE_USB_VID 0x0b89
48+#define NBOX_DVBT_DONGLE_USB_PID 0x0007
49+
50+void as102_urb_stream_irq(struct urb *urb);
51+
52+struct as10x_usb_token_cmd_t {
53+ /* token cmd */
54+ struct as10x_cmd_t c;
55+ /* token response */
56+ struct as10x_cmd_t r;
57+};
58+#endif
59+/* EOF - vim: set textwidth=80 ts=8 sw=8 sts=8 noet: */
drivers/staging/media/as102/as10x_cmd.c+452−0
@@ -0,0 +1,452 @@
1+/*
2+ * Abilis Systems Single DVB-T Receiver
3+ * Copyright (C) 2008 Pierrick Hascoet <pierrick.hascoet@abilis.com>
4+ * Copyright (C) 2010 Devin Heitmueller <dheitmueller@kernellabs.com>
5+ *
6+ * This program is free software; you can redistribute it and/or modify
7+ * it under the terms of the GNU General Public License as published by
8+ * the Free Software Foundation; either version 2, or (at your option)
9+ * any later version.
10+ *
11+ * This program is distributed in the hope that it will be useful,
12+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
13+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+ * GNU General Public License for more details.
15+ *
16+ * You should have received a copy of the GNU General Public License
17+ * along with this program; if not, write to the Free Software
18+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19+ */
20+
21+#include <linux/kernel.h>
22+#include "as102_drv.h"
23+#include "as10x_types.h"
24+#include "as10x_cmd.h"
25+
26+/**
27+ * as10x_cmd_turn_on - send turn on command to AS10x
28+ * @phandle: pointer to AS10x handle
29+ *
30+ * Return 0 when no error, < 0 in case of error.
31+ */
32+int as10x_cmd_turn_on(as10x_handle_t *phandle)
33+{
34+ int error;
35+ struct as10x_cmd_t *pcmd, *prsp;
36+
37+ ENTER();
38+
39+ pcmd = phandle->cmd;
40+ prsp = phandle->rsp;
41+
42+ /* prepare command */
43+ as10x_cmd_build(pcmd, (++phandle->cmd_xid),
44+ sizeof(pcmd->body.turn_on.req));
45+
46+ /* fill command */
47+ pcmd->body.turn_on.req.proc_id = cpu_to_le16(CONTROL_PROC_TURNON);
48+
49+ /* send command */
50+ if (phandle->ops->xfer_cmd) {
51+ error = phandle->ops->xfer_cmd(phandle, (uint8_t *) pcmd,
52+ sizeof(pcmd->body.turn_on.req) +
53+ HEADER_SIZE,
54+ (uint8_t *) prsp,
55+ sizeof(prsp->body.turn_on.rsp) +
56+ HEADER_SIZE);
57+ } else {
58+ error = AS10X_CMD_ERROR;
59+ }
60+
61+ if (error < 0)
62+ goto out;
63+
64+ /* parse response */
65+ error = as10x_rsp_parse(prsp, CONTROL_PROC_TURNON_RSP);
66+
67+out:
68+ LEAVE();
69+ return error;
70+}
71+
72+/**
73+ * as10x_cmd_turn_off - send turn off command to AS10x
74+ * @phandle: pointer to AS10x handle
75+ *
76+ * Return 0 on success or negative value in case of error.
77+ */
78+int as10x_cmd_turn_off(as10x_handle_t *phandle)
79+{
80+ int error;
81+ struct as10x_cmd_t *pcmd, *prsp;
82+
83+ ENTER();
84+
85+ pcmd = phandle->cmd;
86+ prsp = phandle->rsp;
87+
88+ /* prepare command */
89+ as10x_cmd_build(pcmd, (++phandle->cmd_xid),
90+ sizeof(pcmd->body.turn_off.req));
91+
92+ /* fill command */
93+ pcmd->body.turn_off.req.proc_id = cpu_to_le16(CONTROL_PROC_TURNOFF);
94+
95+ /* send command */
96+ if (phandle->ops->xfer_cmd) {
97+ error = phandle->ops->xfer_cmd(
98+ phandle, (uint8_t *) pcmd,
99+ sizeof(pcmd->body.turn_off.req) + HEADER_SIZE,
100+ (uint8_t *) prsp,
101+ sizeof(prsp->body.turn_off.rsp) + HEADER_SIZE);
102+ } else {
103+ error = AS10X_CMD_ERROR;
104+ }
105+
106+ if (error < 0)
107+ goto out;
108+
109+ /* parse response */
110+ error = as10x_rsp_parse(prsp, CONTROL_PROC_TURNOFF_RSP);
111+
112+out:
113+ LEAVE();
114+ return error;
115+}
116+
117+/**
118+ * as10x_cmd_set_tune - send set tune command to AS10x
119+ * @phandle: pointer to AS10x handle
120+ * @ptune: tune parameters
121+ *
122+ * Return 0 on success or negative value in case of error.
123+ */
124+int as10x_cmd_set_tune(as10x_handle_t *phandle, struct as10x_tune_args *ptune)
125+{
126+ int error;
127+ struct as10x_cmd_t *preq, *prsp;
128+
129+ ENTER();
130+
131+ preq = phandle->cmd;
132+ prsp = phandle->rsp;
133+
134+ /* prepare command */
135+ as10x_cmd_build(preq, (++phandle->cmd_xid),
136+ sizeof(preq->body.set_tune.req));
137+
138+ /* fill command */
139+ preq->body.set_tune.req.proc_id = cpu_to_le16(CONTROL_PROC_SETTUNE);
140+ preq->body.set_tune.req.args.freq = cpu_to_le32(ptune->freq);
141+ preq->body.set_tune.req.args.bandwidth = ptune->bandwidth;
142+ preq->body.set_tune.req.args.hier_select = ptune->hier_select;
143+ preq->body.set_tune.req.args.constellation = ptune->constellation;
144+ preq->body.set_tune.req.args.hierarchy = ptune->hierarchy;
145+ preq->body.set_tune.req.args.interleaving_mode =
146+ ptune->interleaving_mode;
147+ preq->body.set_tune.req.args.code_rate = ptune->code_rate;
148+ preq->body.set_tune.req.args.guard_interval = ptune->guard_interval;
149+ preq->body.set_tune.req.args.transmission_mode =
150+ ptune->transmission_mode;
151+
152+ /* send command */
153+ if (phandle->ops->xfer_cmd) {
154+ error = phandle->ops->xfer_cmd(phandle,
155+ (uint8_t *) preq,
156+ sizeof(preq->body.set_tune.req)
157+ + HEADER_SIZE,
158+ (uint8_t *) prsp,
159+ sizeof(prsp->body.set_tune.rsp)
160+ + HEADER_SIZE);
161+ } else {
162+ error = AS10X_CMD_ERROR;
163+ }
164+
165+ if (error < 0)
166+ goto out;
167+
168+ /* parse response */
169+ error = as10x_rsp_parse(prsp, CONTROL_PROC_SETTUNE_RSP);
170+
171+out:
172+ LEAVE();
173+ return error;
174+}
175+
176+/**
177+ * as10x_cmd_get_tune_status - send get tune status command to AS10x
178+ * @phandle: pointer to AS10x handle
179+ * @pstatus: pointer to updated status structure of the current tune
180+ *
181+ * Return 0 on success or negative value in case of error.
182+ */
183+int as10x_cmd_get_tune_status(as10x_handle_t *phandle,
184+ struct as10x_tune_status *pstatus)
185+{
186+ int error;
187+ struct as10x_cmd_t *preq, *prsp;
188+
189+ ENTER();
190+
191+ preq = phandle->cmd;
192+ prsp = phandle->rsp;
193+
194+ /* prepare command */
195+ as10x_cmd_build(preq, (++phandle->cmd_xid),
196+ sizeof(preq->body.get_tune_status.req));
197+
198+ /* fill command */
199+ preq->body.get_tune_status.req.proc_id =
200+ cpu_to_le16(CONTROL_PROC_GETTUNESTAT);
201+
202+ /* send command */
203+ if (phandle->ops->xfer_cmd) {
204+ error = phandle->ops->xfer_cmd(
205+ phandle,
206+ (uint8_t *) preq,
207+ sizeof(preq->body.get_tune_status.req) + HEADER_SIZE,
208+ (uint8_t *) prsp,
209+ sizeof(prsp->body.get_tune_status.rsp) + HEADER_SIZE);
210+ } else {
211+ error = AS10X_CMD_ERROR;
212+ }
213+
214+ if (error < 0)
215+ goto out;
216+
217+ /* parse response */
218+ error = as10x_rsp_parse(prsp, CONTROL_PROC_GETTUNESTAT_RSP);
219+ if (error < 0)
220+ goto out;
221+
222+ /* Response OK -> get response data */
223+ pstatus->tune_state = prsp->body.get_tune_status.rsp.sts.tune_state;
224+ pstatus->signal_strength =
225+ le16_to_cpu(prsp->body.get_tune_status.rsp.sts.signal_strength);
226+ pstatus->PER = le16_to_cpu(prsp->body.get_tune_status.rsp.sts.PER);
227+ pstatus->BER = le16_to_cpu(prsp->body.get_tune_status.rsp.sts.BER);
228+
229+out:
230+ LEAVE();
231+ return error;
232+}
233+
234+/**
235+ * send get TPS command to AS10x
236+ * @phandle: pointer to AS10x handle
237+ * @ptps: pointer to TPS parameters structure
238+ *
239+ * Return 0 on success or negative value in case of error.
240+ */
241+int as10x_cmd_get_tps(as10x_handle_t *phandle, struct as10x_tps *ptps)
242+{
243+ int error;
244+ struct as10x_cmd_t *pcmd, *prsp;
245+
246+ ENTER();
247+
248+ pcmd = phandle->cmd;
249+ prsp = phandle->rsp;
250+
251+ /* prepare command */
252+ as10x_cmd_build(pcmd, (++phandle->cmd_xid),
253+ sizeof(pcmd->body.get_tps.req));
254+
255+ /* fill command */
256+ pcmd->body.get_tune_status.req.proc_id =
257+ cpu_to_le16(CONTROL_PROC_GETTPS);
258+
259+ /* send command */
260+ if (phandle->ops->xfer_cmd) {
261+ error = phandle->ops->xfer_cmd(phandle,
262+ (uint8_t *) pcmd,
263+ sizeof(pcmd->body.get_tps.req) +
264+ HEADER_SIZE,
265+ (uint8_t *) prsp,
266+ sizeof(prsp->body.get_tps.rsp) +
267+ HEADER_SIZE);
268+ } else {
269+ error = AS10X_CMD_ERROR;
270+ }
271+
272+ if (error < 0)
273+ goto out;
274+
275+ /* parse response */
276+ error = as10x_rsp_parse(prsp, CONTROL_PROC_GETTPS_RSP);
277+ if (error < 0)
278+ goto out;
279+
280+ /* Response OK -> get response data */
281+ ptps->constellation = prsp->body.get_tps.rsp.tps.constellation;
282+ ptps->hierarchy = prsp->body.get_tps.rsp.tps.hierarchy;
283+ ptps->interleaving_mode = prsp->body.get_tps.rsp.tps.interleaving_mode;
284+ ptps->code_rate_HP = prsp->body.get_tps.rsp.tps.code_rate_HP;
285+ ptps->code_rate_LP = prsp->body.get_tps.rsp.tps.code_rate_LP;
286+ ptps->guard_interval = prsp->body.get_tps.rsp.tps.guard_interval;
287+ ptps->transmission_mode = prsp->body.get_tps.rsp.tps.transmission_mode;
288+ ptps->DVBH_mask_HP = prsp->body.get_tps.rsp.tps.DVBH_mask_HP;
289+ ptps->DVBH_mask_LP = prsp->body.get_tps.rsp.tps.DVBH_mask_LP;
290+ ptps->cell_ID = le16_to_cpu(prsp->body.get_tps.rsp.tps.cell_ID);
291+
292+out:
293+ LEAVE();
294+ return error;
295+}
296+
297+/**
298+ * as10x_cmd_get_demod_stats - send get demod stats command to AS10x
299+ * @phandle: pointer to AS10x handle
300+ * @pdemod_stats: pointer to demod stats parameters structure
301+ *
302+ * Return 0 on success or negative value in case of error.
303+ */
304+int as10x_cmd_get_demod_stats(as10x_handle_t *phandle,
305+ struct as10x_demod_stats *pdemod_stats)
306+{
307+ int error;
308+ struct as10x_cmd_t *pcmd, *prsp;
309+
310+ ENTER();
311+
312+ pcmd = phandle->cmd;
313+ prsp = phandle->rsp;
314+
315+ /* prepare command */
316+ as10x_cmd_build(pcmd, (++phandle->cmd_xid),
317+ sizeof(pcmd->body.get_demod_stats.req));
318+
319+ /* fill command */
320+ pcmd->body.get_demod_stats.req.proc_id =
321+ cpu_to_le16(CONTROL_PROC_GET_DEMOD_STATS);
322+
323+ /* send command */
324+ if (phandle->ops->xfer_cmd) {
325+ error = phandle->ops->xfer_cmd(phandle,
326+ (uint8_t *) pcmd,
327+ sizeof(pcmd->body.get_demod_stats.req)
328+ + HEADER_SIZE,
329+ (uint8_t *) prsp,
330+ sizeof(prsp->body.get_demod_stats.rsp)
331+ + HEADER_SIZE);
332+ } else {
333+ error = AS10X_CMD_ERROR;
334+ }
335+
336+ if (error < 0)
337+ goto out;
338+
339+ /* parse response */
340+ error = as10x_rsp_parse(prsp, CONTROL_PROC_GET_DEMOD_STATS_RSP);
341+ if (error < 0)
342+ goto out;
343+
344+ /* Response OK -> get response data */
345+ pdemod_stats->frame_count =
346+ le32_to_cpu(prsp->body.get_demod_stats.rsp.stats.frame_count);
347+ pdemod_stats->bad_frame_count =
348+ le32_to_cpu(prsp->body.get_demod_stats.rsp.stats.bad_frame_count);
349+ pdemod_stats->bytes_fixed_by_rs =
350+ le32_to_cpu(prsp->body.get_demod_stats.rsp.stats.bytes_fixed_by_rs);
351+ pdemod_stats->mer =
352+ le16_to_cpu(prsp->body.get_demod_stats.rsp.stats.mer);
353+ pdemod_stats->has_started =
354+ prsp->body.get_demod_stats.rsp.stats.has_started;
355+
356+out:
357+ LEAVE();
358+ return error;
359+}
360+
361+/**
362+ * as10x_cmd_get_impulse_resp - send get impulse response command to AS10x
363+ * @phandle: pointer to AS10x handle
364+ * @is_ready: pointer to value indicating when impulse
365+ * response data is ready
366+ *
367+ * Return 0 on success or negative value in case of error.
368+ */
369+int as10x_cmd_get_impulse_resp(as10x_handle_t *phandle,
370+ uint8_t *is_ready)
371+{
372+ int error;
373+ struct as10x_cmd_t *pcmd, *prsp;
374+
375+ ENTER();
376+
377+ pcmd = phandle->cmd;
378+ prsp = phandle->rsp;
379+
380+ /* prepare command */
381+ as10x_cmd_build(pcmd, (++phandle->cmd_xid),
382+ sizeof(pcmd->body.get_impulse_rsp.req));
383+
384+ /* fill command */
385+ pcmd->body.get_impulse_rsp.req.proc_id =
386+ cpu_to_le16(CONTROL_PROC_GET_IMPULSE_RESP);
387+
388+ /* send command */
389+ if (phandle->ops->xfer_cmd) {
390+ error = phandle->ops->xfer_cmd(phandle,
391+ (uint8_t *) pcmd,
392+ sizeof(pcmd->body.get_impulse_rsp.req)
393+ + HEADER_SIZE,
394+ (uint8_t *) prsp,
395+ sizeof(prsp->body.get_impulse_rsp.rsp)
396+ + HEADER_SIZE);
397+ } else {
398+ error = AS10X_CMD_ERROR;
399+ }
400+
401+ if (error < 0)
402+ goto out;
403+
404+ /* parse response */
405+ error = as10x_rsp_parse(prsp, CONTROL_PROC_GET_IMPULSE_RESP_RSP);
406+ if (error < 0)
407+ goto out;
408+
409+ /* Response OK -> get response data */
410+ *is_ready = prsp->body.get_impulse_rsp.rsp.is_ready;
411+
412+out:
413+ LEAVE();
414+ return error;
415+}
416+
417+/**
418+ * as10x_cmd_build - build AS10x command header
419+ * @pcmd: pointer to AS10x command buffer
420+ * @xid: sequence id of the command
421+ * @cmd_len: length of the command
422+ */
423+void as10x_cmd_build(struct as10x_cmd_t *pcmd,
424+ uint16_t xid, uint16_t cmd_len)
425+{
426+ pcmd->header.req_id = cpu_to_le16(xid);
427+ pcmd->header.prog = cpu_to_le16(SERVICE_PROG_ID);
428+ pcmd->header.version = cpu_to_le16(SERVICE_PROG_VERSION);
429+ pcmd->header.data_len = cpu_to_le16(cmd_len);
430+}
431+
432+/**
433+ * as10x_rsp_parse - Parse command response
434+ * @prsp: pointer to AS10x command buffer
435+ * @proc_id: id of the command
436+ *
437+ * Return 0 on success or negative value in case of error.
438+ */
439+int as10x_rsp_parse(struct as10x_cmd_t *prsp, uint16_t proc_id)
440+{
441+ int error;
442+
443+ /* extract command error code */
444+ error = prsp->body.common.rsp.error;
445+
446+ if ((error == 0) &&
447+ (le16_to_cpu(prsp->body.common.rsp.proc_id) == proc_id)) {
448+ return 0;
449+ }
450+
451+ return AS10X_CMD_ERROR;
452+}
drivers/staging/media/as102/as10x_cmd.h+540−0
@@ -0,0 +1,540 @@
1+/*
2+ * Abilis Systems Single DVB-T Receiver
3+ * Copyright (C) 2008 Pierrick Hascoet <pierrick.hascoet@abilis.com>
4+ *
5+ * This program is free software; you can redistribute it and/or modify
6+ * it under the terms of the GNU General Public License as published by
7+ * the Free Software Foundation; either version 2, or (at your option)
8+ * any later version.
9+ *
10+ * This program is distributed in the hope that it will be useful,
11+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
12+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+ * GNU General Public License for more details.
14+ *
15+ * You should have received a copy of the GNU General Public License
16+ * along with this program; if not, write to the Free Software
17+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18+ */
19+#ifndef _AS10X_CMD_H_
20+#define _AS10X_CMD_H_
21+
22+#ifdef __KERNEL__
23+#include <linux/kernel.h>
24+#endif
25+
26+#include "as10x_types.h"
27+
28+/*********************************/
29+/* MACRO DEFINITIONS */
30+/*********************************/
31+#define AS10X_CMD_ERROR -1
32+
33+#define SERVICE_PROG_ID 0x0002
34+#define SERVICE_PROG_VERSION 0x0001
35+
36+#define HIER_NONE 0x00
37+#define HIER_LOW_PRIORITY 0x01
38+
39+#define HEADER_SIZE (sizeof(struct as10x_cmd_header_t))
40+
41+/* context request types */
42+#define GET_CONTEXT_DATA 1
43+#define SET_CONTEXT_DATA 2
44+
45+/* ODSP suspend modes */
46+#define CFG_MODE_ODSP_RESUME 0
47+#define CFG_MODE_ODSP_SUSPEND 1
48+
49+/* Dump memory size */
50+#define DUMP_BLOCK_SIZE_MAX 0x20
51+
52+/*********************************/
53+/* TYPE DEFINITION */
54+/*********************************/
55+typedef enum {
56+ CONTROL_PROC_TURNON = 0x0001,
57+ CONTROL_PROC_TURNON_RSP = 0x0100,
58+ CONTROL_PROC_SET_REGISTER = 0x0002,
59+ CONTROL_PROC_SET_REGISTER_RSP = 0x0200,
60+ CONTROL_PROC_GET_REGISTER = 0x0003,
61+ CONTROL_PROC_GET_REGISTER_RSP = 0x0300,
62+ CONTROL_PROC_SETTUNE = 0x000A,
63+ CONTROL_PROC_SETTUNE_RSP = 0x0A00,
64+ CONTROL_PROC_GETTUNESTAT = 0x000B,
65+ CONTROL_PROC_GETTUNESTAT_RSP = 0x0B00,
66+ CONTROL_PROC_GETTPS = 0x000D,
67+ CONTROL_PROC_GETTPS_RSP = 0x0D00,
68+ CONTROL_PROC_SETFILTER = 0x000E,
69+ CONTROL_PROC_SETFILTER_RSP = 0x0E00,
70+ CONTROL_PROC_REMOVEFILTER = 0x000F,
71+ CONTROL_PROC_REMOVEFILTER_RSP = 0x0F00,
72+ CONTROL_PROC_GET_IMPULSE_RESP = 0x0012,
73+ CONTROL_PROC_GET_IMPULSE_RESP_RSP = 0x1200,
74+ CONTROL_PROC_START_STREAMING = 0x0013,
75+ CONTROL_PROC_START_STREAMING_RSP = 0x1300,
76+ CONTROL_PROC_STOP_STREAMING = 0x0014,
77+ CONTROL_PROC_STOP_STREAMING_RSP = 0x1400,
78+ CONTROL_PROC_GET_DEMOD_STATS = 0x0015,
79+ CONTROL_PROC_GET_DEMOD_STATS_RSP = 0x1500,
80+ CONTROL_PROC_ELNA_CHANGE_MODE = 0x0016,
81+ CONTROL_PROC_ELNA_CHANGE_MODE_RSP = 0x1600,
82+ CONTROL_PROC_ODSP_CHANGE_MODE = 0x0017,
83+ CONTROL_PROC_ODSP_CHANGE_MODE_RSP = 0x1700,
84+ CONTROL_PROC_AGC_CHANGE_MODE = 0x0018,
85+ CONTROL_PROC_AGC_CHANGE_MODE_RSP = 0x1800,
86+
87+ CONTROL_PROC_CONTEXT = 0x00FC,
88+ CONTROL_PROC_CONTEXT_RSP = 0xFC00,
89+ CONTROL_PROC_DUMP_MEMORY = 0x00FD,
90+ CONTROL_PROC_DUMP_MEMORY_RSP = 0xFD00,
91+ CONTROL_PROC_DUMPLOG_MEMORY = 0x00FE,
92+ CONTROL_PROC_DUMPLOG_MEMORY_RSP = 0xFE00,
93+ CONTROL_PROC_TURNOFF = 0x00FF,
94+ CONTROL_PROC_TURNOFF_RSP = 0xFF00
95+} control_proc;
96+
97+
98+#pragma pack(1)
99+typedef union {
100+ /* request */
101+ struct {
102+ /* request identifier */
103+ uint16_t proc_id;
104+ } req;
105+ /* response */
106+ struct {
107+ /* response identifier */
108+ uint16_t proc_id;
109+ /* error */
110+ uint8_t error;
111+ } rsp;
112+} TURN_ON;
113+
114+typedef union {
115+ /* request */
116+ struct {
117+ /* request identifier */
118+ uint16_t proc_id;
119+ } req;
120+ /* response */
121+ struct {
122+ /* response identifier */
123+ uint16_t proc_id;
124+ /* error */
125+ uint8_t err;
126+ } rsp;
127+} TURN_OFF;
128+
129+typedef union {
130+ /* request */
131+ struct {
132+ /* request identifier */
133+ uint16_t proc_id;
134+ /* tune params */
135+ struct as10x_tune_args args;
136+ } req;
137+ /* response */
138+ struct {
139+ /* response identifier */
140+ uint16_t proc_id;
141+ /* response error */
142+ uint8_t error;
143+ } rsp;
144+} SET_TUNE;
145+
146+typedef union {
147+ /* request */
148+ struct {
149+ /* request identifier */
150+ uint16_t proc_id;
151+ } req;
152+ /* response */
153+ struct {
154+ /* response identifier */
155+ uint16_t proc_id;
156+ /* response error */
157+ uint8_t error;
158+ /* tune status */
159+ struct as10x_tune_status sts;
160+ } rsp;
161+} GET_TUNE_STATUS;
162+
163+typedef union {
164+ /* request */
165+ struct {
166+ /* request identifier */
167+ uint16_t proc_id;
168+ } req;
169+ /* response */
170+ struct {
171+ /* response identifier */
172+ uint16_t proc_id;
173+ /* response error */
174+ uint8_t error;
175+ /* tps details */
176+ struct as10x_tps tps;
177+ } rsp;
178+} GET_TPS;
179+
180+typedef union {
181+ /* request */
182+ struct {
183+ /* request identifier */
184+ uint16_t proc_id;
185+ } req;
186+ /* response */
187+ struct {
188+ /* response identifier */
189+ uint16_t proc_id;
190+ /* response error */
191+ uint8_t error;
192+ } rsp;
193+} COMMON;
194+
195+typedef union {
196+ /* request */
197+ struct {
198+ /* request identifier */
199+ uint16_t proc_id;
200+ /* PID to filter */
201+ uint16_t pid;
202+ /* stream type (MPE, PSI/SI or PES )*/
203+ uint8_t stream_type;
204+ /* PID index in filter table */
205+ uint8_t idx;
206+ } req;
207+ /* response */
208+ struct {
209+ /* response identifier */
210+ uint16_t proc_id;
211+ /* response error */
212+ uint8_t error;
213+ /* Filter id */
214+ uint8_t filter_id;
215+ } rsp;
216+} ADD_PID_FILTER;
217+
218+typedef union {
219+ /* request */
220+ struct {
221+ /* request identifier */
222+ uint16_t proc_id;
223+ /* PID to remove */
224+ uint16_t pid;
225+ } req;
226+ /* response */
227+ struct {
228+ /* response identifier */
229+ uint16_t proc_id;
230+ /* response error */
231+ uint8_t error;
232+ } rsp;
233+} DEL_PID_FILTER;
234+
235+typedef union {
236+ /* request */
237+ struct {
238+ /* request identifier */
239+ uint16_t proc_id;
240+ } req;
241+ /* response */
242+ struct {
243+ /* response identifier */
244+ uint16_t proc_id;
245+ /* error */
246+ uint8_t error;
247+ } rsp;
248+} START_STREAMING;
249+
250+typedef union {
251+ /* request */
252+ struct {
253+ /* request identifier */
254+ uint16_t proc_id;
255+ } req;
256+ /* response */
257+ struct {
258+ /* response identifier */
259+ uint16_t proc_id;
260+ /* error */
261+ uint8_t error;
262+ } rsp;
263+} STOP_STREAMING;
264+
265+typedef union {
266+ /* request */
267+ struct {
268+ /* request identifier */
269+ uint16_t proc_id;
270+ } req;
271+ /* response */
272+ struct {
273+ /* response identifier */
274+ uint16_t proc_id;
275+ /* error */
276+ uint8_t error;
277+ /* demod stats */
278+ struct as10x_demod_stats stats;
279+ } rsp;
280+} GET_DEMOD_STATS;
281+
282+typedef union {
283+ /* request */
284+ struct {
285+ /* request identifier */
286+ uint16_t proc_id;
287+ } req;
288+ /* response */
289+ struct {
290+ /* response identifier */
291+ uint16_t proc_id;
292+ /* error */
293+ uint8_t error;
294+ /* impulse response ready */
295+ uint8_t is_ready;
296+ } rsp;
297+} GET_IMPULSE_RESP;
298+
299+typedef union {
300+ /* request */
301+ struct {
302+ /* request identifier */
303+ uint16_t proc_id;
304+ /* value to write (for set context)*/
305+ struct as10x_register_value reg_val;
306+ /* context tag */
307+ uint16_t tag;
308+ /* context request type */
309+ uint16_t type;
310+ } req;
311+ /* response */
312+ struct {
313+ /* response identifier */
314+ uint16_t proc_id;
315+ /* value read (for get context) */
316+ struct as10x_register_value reg_val;
317+ /* context request type */
318+ uint16_t type;
319+ /* error */
320+ uint8_t error;
321+ } rsp;
322+} FW_CONTEXT;
323+
324+typedef union {
325+ /* request */
326+ struct {
327+ /* response identifier */
328+ uint16_t proc_id;
329+ /* register description */
330+ struct as10x_register_addr reg_addr;
331+ /* register content */
332+ struct as10x_register_value reg_val;
333+ } req;
334+ /* response */
335+ struct {
336+ /* response identifier */
337+ uint16_t proc_id;
338+ /* error */
339+ uint8_t error;
340+ } rsp;
341+} SET_REGISTER;
342+
343+typedef union {
344+ /* request */
345+ struct {
346+ /* response identifier */
347+ uint16_t proc_id;
348+ /* register description */
349+ struct as10x_register_addr reg_addr;
350+ } req;
351+ /* response */
352+ struct {
353+ /* response identifier */
354+ uint16_t proc_id;
355+ /* error */
356+ uint8_t error;
357+ /* register content */
358+ struct as10x_register_value reg_val;
359+ } rsp;
360+} GET_REGISTER;
361+
362+typedef union {
363+ /* request */
364+ struct {
365+ /* request identifier */
366+ uint16_t proc_id;
367+ /* mode */
368+ uint8_t mode;
369+ } req;
370+ /* response */
371+ struct {
372+ /* response identifier */
373+ uint16_t proc_id;
374+ /* error */
375+ uint8_t error;
376+ } rsp;
377+} CFG_CHANGE_MODE;
378+
379+struct as10x_cmd_header_t {
380+ uint16_t req_id;
381+ uint16_t prog;
382+ uint16_t version;
383+ uint16_t data_len;
384+};
385+
386+#define DUMP_BLOCK_SIZE 16
387+typedef union {
388+ /* request */
389+ struct {
390+ /* request identifier */
391+ uint16_t proc_id;
392+ /* dump memory type request */
393+ uint8_t dump_req;
394+ /* register description */
395+ struct as10x_register_addr reg_addr;
396+ /* nb blocks to read */
397+ uint16_t num_blocks;
398+ } req;
399+ /* response */
400+ struct {
401+ /* response identifier */
402+ uint16_t proc_id;
403+ /* error */
404+ uint8_t error;
405+ /* dump response */
406+ uint8_t dump_rsp;
407+ /* data */
408+ union {
409+ uint8_t data8[DUMP_BLOCK_SIZE];
410+ uint16_t data16[DUMP_BLOCK_SIZE / sizeof(uint16_t)];
411+ uint32_t data32[DUMP_BLOCK_SIZE / sizeof(uint32_t)];
412+ } u;
413+ } rsp;
414+} DUMP_MEMORY;
415+
416+typedef union {
417+ struct {
418+ /* request identifier */
419+ uint16_t proc_id;
420+ /* dump memory type request */
421+ uint8_t dump_req;
422+ } req;
423+ struct {
424+ /* request identifier */
425+ uint16_t proc_id;
426+ /* error */
427+ uint8_t error;
428+ /* dump response */
429+ uint8_t dump_rsp;
430+ /* dump data */
431+ uint8_t data[DUMP_BLOCK_SIZE];
432+ } rsp;
433+} DUMPLOG_MEMORY;
434+
435+typedef union {
436+ /* request */
437+ struct {
438+ uint16_t proc_id;
439+ uint8_t data[64 - sizeof(struct as10x_cmd_header_t) -2 /* proc_id */];
440+ } req;
441+ /* response */
442+ struct {
443+ uint16_t proc_id;
444+ uint8_t error;
445+ uint8_t data[64 - sizeof(struct as10x_cmd_header_t) /* header */
446+ - 2 /* proc_id */ - 1 /* rc */];
447+ } rsp;
448+} RAW_DATA;
449+
450+struct as10x_cmd_t {
451+ /* header */
452+ struct as10x_cmd_header_t header;
453+ /* body */
454+ union {
455+ TURN_ON turn_on;
456+ TURN_OFF turn_off;
457+ SET_TUNE set_tune;
458+ GET_TUNE_STATUS get_tune_status;
459+ GET_TPS get_tps;
460+ COMMON common;
461+ ADD_PID_FILTER add_pid_filter;
462+ DEL_PID_FILTER del_pid_filter;
463+ START_STREAMING start_streaming;
464+ STOP_STREAMING stop_streaming;
465+ GET_DEMOD_STATS get_demod_stats;
466+ GET_IMPULSE_RESP get_impulse_rsp;
467+ FW_CONTEXT context;
468+ SET_REGISTER set_register;
469+ GET_REGISTER get_register;
470+ CFG_CHANGE_MODE cfg_change_mode;
471+ DUMP_MEMORY dump_memory;
472+ DUMPLOG_MEMORY dumplog_memory;
473+ RAW_DATA raw_data;
474+ } body;
475+};
476+
477+struct as10x_token_cmd_t {
478+ /* token cmd */
479+ struct as10x_cmd_t c;
480+ /* token response */
481+ struct as10x_cmd_t r;
482+};
483+#pragma pack()
484+
485+
486+/**************************/
487+/* FUNCTION DECLARATION */
488+/**************************/
489+
490+void as10x_cmd_build(struct as10x_cmd_t *pcmd, uint16_t proc_id,
491+ uint16_t cmd_len);
492+int as10x_rsp_parse(struct as10x_cmd_t *r, uint16_t proc_id);
493+
494+#ifdef __cplusplus
495+extern "C" {
496+#endif
497+
498+/* as10x cmd */
499+int as10x_cmd_turn_on(as10x_handle_t *phandle);
500+int as10x_cmd_turn_off(as10x_handle_t *phandle);
501+
502+int as10x_cmd_set_tune(as10x_handle_t *phandle,
503+ struct as10x_tune_args *ptune);
504+
505+int as10x_cmd_get_tune_status(as10x_handle_t *phandle,
506+ struct as10x_tune_status *pstatus);
507+
508+int as10x_cmd_get_tps(as10x_handle_t *phandle,
509+ struct as10x_tps *ptps);
510+
511+int as10x_cmd_get_demod_stats(as10x_handle_t *phandle,
512+ struct as10x_demod_stats *pdemod_stats);
513+
514+int as10x_cmd_get_impulse_resp(as10x_handle_t *phandle,
515+ uint8_t *is_ready);
516+
517+/* as10x cmd stream */
518+int as10x_cmd_add_PID_filter(as10x_handle_t *phandle,
519+ struct as10x_ts_filter *filter);
520+int as10x_cmd_del_PID_filter(as10x_handle_t *phandle,
521+ uint16_t pid_value);
522+
523+int as10x_cmd_start_streaming(as10x_handle_t *phandle);
524+int as10x_cmd_stop_streaming(as10x_handle_t *phandle);
525+
526+/* as10x cmd cfg */
527+int as10x_cmd_set_context(as10x_handle_t *phandle,
528+ uint16_t tag,
529+ uint32_t value);
530+int as10x_cmd_get_context(as10x_handle_t *phandle,
531+ uint16_t tag,
532+ uint32_t *pvalue);
533+
534+int as10x_cmd_eLNA_change_mode(as10x_handle_t *phandle, uint8_t mode);
535+int as10x_context_rsp_parse(struct as10x_cmd_t *prsp, uint16_t proc_id);
536+#ifdef __cplusplus
537+}
538+#endif
539+#endif
540+/* EOF - vim: set textwidth=80 ts=3 sw=3 sts=3 et: */
drivers/staging/media/as102/as10x_cmd_cfg.c+215−0
@@ -0,0 +1,215 @@
1+/*
2+ * Abilis Systems Single DVB-T Receiver
3+ * Copyright (C) 2008 Pierrick Hascoet <pierrick.hascoet@abilis.com>
4+ *
5+ * This program is free software; you can redistribute it and/or modify
6+ * it under the terms of the GNU General Public License as published by
7+ * the Free Software Foundation; either version 2, or (at your option)
8+ * any later version.
9+ *
10+ * This program is distributed in the hope that it will be useful,
11+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
12+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+ * GNU General Public License for more details.
14+ *
15+ * You should have received a copy of the GNU General Public License
16+ * along with this program; if not, write to the Free Software
17+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18+ */
19+
20+#include <linux/kernel.h>
21+#include "as102_drv.h"
22+#include "as10x_types.h"
23+#include "as10x_cmd.h"
24+
25+/***************************/
26+/* FUNCTION DEFINITION */
27+/***************************/
28+
29+/**
30+ * as10x_cmd_get_context - Send get context command to AS10x
31+ * @phandle: pointer to AS10x handle
32+ * @tag: context tag
33+ * @pvalue: pointer where to store context value read
34+ *
35+ * Return 0 on success or negative value in case of error.
36+ */
37+int as10x_cmd_get_context(as10x_handle_t *phandle, uint16_t tag,
38+ uint32_t *pvalue)
39+{
40+ int error;
41+ struct as10x_cmd_t *pcmd, *prsp;
42+
43+ ENTER();
44+
45+ pcmd = phandle->cmd;
46+ prsp = phandle->rsp;
47+
48+ /* prepare command */
49+ as10x_cmd_build(pcmd, (++phandle->cmd_xid),
50+ sizeof(pcmd->body.context.req));
51+
52+ /* fill command */
53+ pcmd->body.context.req.proc_id = cpu_to_le16(CONTROL_PROC_CONTEXT);
54+ pcmd->body.context.req.tag = cpu_to_le16(tag);
55+ pcmd->body.context.req.type = cpu_to_le16(GET_CONTEXT_DATA);
56+
57+ /* send command */
58+ if (phandle->ops->xfer_cmd) {
59+ error = phandle->ops->xfer_cmd(phandle,
60+ (uint8_t *) pcmd,
61+ sizeof(pcmd->body.context.req)
62+ + HEADER_SIZE,
63+ (uint8_t *) prsp,
64+ sizeof(prsp->body.context.rsp)
65+ + HEADER_SIZE);
66+ } else {
67+ error = AS10X_CMD_ERROR;
68+ }
69+
70+ if (error < 0)
71+ goto out;
72+
73+ /* parse response: context command do not follow the common response */
74+ /* structure -> specific handling response parse required */
75+ error = as10x_context_rsp_parse(prsp, CONTROL_PROC_CONTEXT_RSP);
76+
77+ if (error == 0) {
78+ /* Response OK -> get response data */
79+ *pvalue = le32_to_cpu(prsp->body.context.rsp.reg_val.u.value32);
80+ /* value returned is always a 32-bit value */
81+ }
82+
83+out:
84+ LEAVE();
85+ return error;
86+}
87+
88+/**
89+ * as10x_cmd_set_context - send set context command to AS10x
90+ * @phandle: pointer to AS10x handle
91+ * @tag: context tag
92+ * @value: value to set in context
93+ *
94+ * Return 0 on success or negative value in case of error.
95+ */
96+int as10x_cmd_set_context(as10x_handle_t *phandle, uint16_t tag,
97+ uint32_t value)
98+{
99+ int error;
100+ struct as10x_cmd_t *pcmd, *prsp;
101+
102+ ENTER();
103+
104+ pcmd = phandle->cmd;
105+ prsp = phandle->rsp;
106+
107+ /* prepare command */
108+ as10x_cmd_build(pcmd, (++phandle->cmd_xid),
109+ sizeof(pcmd->body.context.req));
110+
111+ /* fill command */
112+ pcmd->body.context.req.proc_id = cpu_to_le16(CONTROL_PROC_CONTEXT);
113+ /* pcmd->body.context.req.reg_val.mode initialization is not required */
114+ pcmd->body.context.req.reg_val.u.value32 = cpu_to_le32(value);
115+ pcmd->body.context.req.tag = cpu_to_le16(tag);
116+ pcmd->body.context.req.type = cpu_to_le16(SET_CONTEXT_DATA);
117+
118+ /* send command */
119+ if (phandle->ops->xfer_cmd) {
120+ error = phandle->ops->xfer_cmd(phandle,
121+ (uint8_t *) pcmd,
122+ sizeof(pcmd->body.context.req)
123+ + HEADER_SIZE,
124+ (uint8_t *) prsp,
125+ sizeof(prsp->body.context.rsp)
126+ + HEADER_SIZE);
127+ } else {
128+ error = AS10X_CMD_ERROR;
129+ }
130+
131+ if (error < 0)
132+ goto out;
133+
134+ /* parse response: context command do not follow the common response */
135+ /* structure -> specific handling response parse required */
136+ error = as10x_context_rsp_parse(prsp, CONTROL_PROC_CONTEXT_RSP);
137+
138+out:
139+ LEAVE();
140+ return error;
141+}
142+
143+/**
144+ * as10x_cmd_eLNA_change_mode - send eLNA change mode command to AS10x
145+ * @phandle: pointer to AS10x handle
146+ * @mode: mode selected:
147+ * - ON : 0x0 => eLNA always ON
148+ * - OFF : 0x1 => eLNA always OFF
149+ * - AUTO : 0x2 => eLNA follow hysteresis parameters
150+ * to be ON or OFF
151+ *
152+ * Return 0 on success or negative value in case of error.
153+ */
154+int as10x_cmd_eLNA_change_mode(as10x_handle_t *phandle, uint8_t mode)
155+{
156+ int error;
157+ struct as10x_cmd_t *pcmd, *prsp;
158+
159+ ENTER();
160+
161+ pcmd = phandle->cmd;
162+ prsp = phandle->rsp;
163+
164+ /* prepare command */
165+ as10x_cmd_build(pcmd, (++phandle->cmd_xid),
166+ sizeof(pcmd->body.cfg_change_mode.req));
167+
168+ /* fill command */
169+ pcmd->body.cfg_change_mode.req.proc_id =
170+ cpu_to_le16(CONTROL_PROC_ELNA_CHANGE_MODE);
171+ pcmd->body.cfg_change_mode.req.mode = mode;
172+
173+ /* send command */
174+ if (phandle->ops->xfer_cmd) {
175+ error = phandle->ops->xfer_cmd(phandle, (uint8_t *) pcmd,
176+ sizeof(pcmd->body.cfg_change_mode.req)
177+ + HEADER_SIZE, (uint8_t *) prsp,
178+ sizeof(prsp->body.cfg_change_mode.rsp)
179+ + HEADER_SIZE);
180+ } else {
181+ error = AS10X_CMD_ERROR;
182+ }
183+
184+ if (error < 0)
185+ goto out;
186+
187+ /* parse response */
188+ error = as10x_rsp_parse(prsp, CONTROL_PROC_ELNA_CHANGE_MODE_RSP);
189+
190+out:
191+ LEAVE();
192+ return error;
193+}
194+
195+/**
196+ * as10x_context_rsp_parse - Parse context command response
197+ * @prsp: pointer to AS10x command response buffer
198+ * @proc_id: id of the command
199+ *
200+ * Since the contex command reponse does not follow the common
201+ * response, a specific parse function is required.
202+ * Return 0 on success or negative value in case of error.
203+ */
204+int as10x_context_rsp_parse(struct as10x_cmd_t *prsp, uint16_t proc_id)
205+{
206+ int err;
207+
208+ err = prsp->body.context.rsp.error;
209+
210+ if ((err == 0) &&
211+ (le16_to_cpu(prsp->body.context.rsp.proc_id) == proc_id)) {
212+ return 0;
213+ }
214+ return AS10X_CMD_ERROR;
215+}
drivers/staging/media/as102/as10x_cmd_stream.c+223−0
@@ -0,0 +1,223 @@
1+/*
2+ * Abilis Systems Single DVB-T Receiver
3+ * Copyright (C) 2008 Pierrick Hascoet <pierrick.hascoet@abilis.com>
4+ *
5+ * This program is free software; you can redistribute it and/or modify
6+ * it under the terms of the GNU General Public License as published by
7+ * the Free Software Foundation; either version 2, or (at your option)
8+ * any later version.
9+ *
10+ * This program is distributed in the hope that it will be useful,
11+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
12+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+ * GNU General Public License for more details.
14+ *
15+ * You should have received a copy of the GNU General Public License
16+ * along with this program; if not, write to the Free Software
17+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18+ */
19+
20+#include <linux/kernel.h>
21+#include "as102_drv.h"
22+#include "as10x_cmd.h"
23+
24+/**
25+ * as10x_cmd_add_PID_filter - send add filter command to AS10x
26+ * @phandle: pointer to AS10x handle
27+ * @filter: TSFilter filter for DVB-T
28+ *
29+ * Return 0 on success or negative value in case of error.
30+ */
31+int as10x_cmd_add_PID_filter(as10x_handle_t *phandle,
32+ struct as10x_ts_filter *filter)
33+{
34+ int error;
35+ struct as10x_cmd_t *pcmd, *prsp;
36+
37+ ENTER();
38+
39+ pcmd = phandle->cmd;
40+ prsp = phandle->rsp;
41+
42+ /* prepare command */
43+ as10x_cmd_build(pcmd, (++phandle->cmd_xid),
44+ sizeof(pcmd->body.add_pid_filter.req));
45+
46+ /* fill command */
47+ pcmd->body.add_pid_filter.req.proc_id =
48+ cpu_to_le16(CONTROL_PROC_SETFILTER);
49+ pcmd->body.add_pid_filter.req.pid = cpu_to_le16(filter->pid);
50+ pcmd->body.add_pid_filter.req.stream_type = filter->type;
51+
52+ if (filter->idx < 16)
53+ pcmd->body.add_pid_filter.req.idx = filter->idx;
54+ else
55+ pcmd->body.add_pid_filter.req.idx = 0xFF;
56+
57+ /* send command */
58+ if (phandle->ops->xfer_cmd) {
59+ error = phandle->ops->xfer_cmd(phandle, (uint8_t *) pcmd,
60+ sizeof(pcmd->body.add_pid_filter.req)
61+ + HEADER_SIZE, (uint8_t *) prsp,
62+ sizeof(prsp->body.add_pid_filter.rsp)
63+ + HEADER_SIZE);
64+ } else {
65+ error = AS10X_CMD_ERROR;
66+ }
67+
68+ if (error < 0)
69+ goto out;
70+
71+ /* parse response */
72+ error = as10x_rsp_parse(prsp, CONTROL_PROC_SETFILTER_RSP);
73+
74+ if (error == 0) {
75+ /* Response OK -> get response data */
76+ filter->idx = prsp->body.add_pid_filter.rsp.filter_id;
77+ }
78+
79+out:
80+ LEAVE();
81+ return error;
82+}
83+
84+/**
85+ * as10x_cmd_del_PID_filter - Send delete filter command to AS10x
86+ * @phandle: pointer to AS10x handle
87+ * @pid_value: PID to delete
88+ *
89+ * Return 0 on success or negative value in case of error.
90+ */
91+int as10x_cmd_del_PID_filter(as10x_handle_t *phandle,
92+ uint16_t pid_value)
93+{
94+ int error;
95+ struct as10x_cmd_t *pcmd, *prsp;
96+
97+ ENTER();
98+
99+ pcmd = phandle->cmd;
100+ prsp = phandle->rsp;
101+
102+ /* prepare command */
103+ as10x_cmd_build(pcmd, (++phandle->cmd_xid),
104+ sizeof(pcmd->body.del_pid_filter.req));
105+
106+ /* fill command */
107+ pcmd->body.del_pid_filter.req.proc_id =
108+ cpu_to_le16(CONTROL_PROC_REMOVEFILTER);
109+ pcmd->body.del_pid_filter.req.pid = cpu_to_le16(pid_value);
110+
111+ /* send command */
112+ if (phandle->ops->xfer_cmd) {
113+ error = phandle->ops->xfer_cmd(phandle, (uint8_t *) pcmd,
114+ sizeof(pcmd->body.del_pid_filter.req)
115+ + HEADER_SIZE, (uint8_t *) prsp,
116+ sizeof(prsp->body.del_pid_filter.rsp)
117+ + HEADER_SIZE);
118+ } else {
119+ error = AS10X_CMD_ERROR;
120+ }
121+
122+ if (error < 0)
123+ goto out;
124+
125+ /* parse response */
126+ error = as10x_rsp_parse(prsp, CONTROL_PROC_REMOVEFILTER_RSP);
127+
128+out:
129+ LEAVE();
130+ return error;
131+}
132+
133+/**
134+ * as10x_cmd_start_streaming - Send start streaming command to AS10x
135+ * @phandle: pointer to AS10x handle
136+ *
137+ * Return 0 on success or negative value in case of error.
138+ */
139+int as10x_cmd_start_streaming(as10x_handle_t *phandle)
140+{
141+ int error;
142+ struct as10x_cmd_t *pcmd, *prsp;
143+
144+ ENTER();
145+
146+ pcmd = phandle->cmd;
147+ prsp = phandle->rsp;
148+
149+ /* prepare command */
150+ as10x_cmd_build(pcmd, (++phandle->cmd_xid),
151+ sizeof(pcmd->body.start_streaming.req));
152+
153+ /* fill command */
154+ pcmd->body.start_streaming.req.proc_id =
155+ cpu_to_le16(CONTROL_PROC_START_STREAMING);
156+
157+ /* send command */
158+ if (phandle->ops->xfer_cmd) {
159+ error = phandle->ops->xfer_cmd(phandle, (uint8_t *) pcmd,
160+ sizeof(pcmd->body.start_streaming.req)
161+ + HEADER_SIZE, (uint8_t *) prsp,
162+ sizeof(prsp->body.start_streaming.rsp)
163+ + HEADER_SIZE);
164+ } else {
165+ error = AS10X_CMD_ERROR;
166+ }
167+
168+ if (error < 0)
169+ goto out;
170+
171+ /* parse response */
172+ error = as10x_rsp_parse(prsp, CONTROL_PROC_START_STREAMING_RSP);
173+
174+out:
175+ LEAVE();
176+ return error;
177+}
178+
179+/**
180+ * as10x_cmd_stop_streaming - Send stop streaming command to AS10x
181+ * @phandle: pointer to AS10x handle
182+ *
183+ * Return 0 on success or negative value in case of error.
184+ */
185+int as10x_cmd_stop_streaming(as10x_handle_t *phandle)
186+{
187+ int8_t error;
188+ struct as10x_cmd_t *pcmd, *prsp;
189+
190+ ENTER();
191+
192+ pcmd = phandle->cmd;
193+ prsp = phandle->rsp;
194+
195+ /* prepare command */
196+ as10x_cmd_build(pcmd, (++phandle->cmd_xid),
197+ sizeof(pcmd->body.stop_streaming.req));
198+
199+ /* fill command */
200+ pcmd->body.stop_streaming.req.proc_id =
201+ cpu_to_le16(CONTROL_PROC_STOP_STREAMING);
202+
203+ /* send command */
204+ if (phandle->ops->xfer_cmd) {
205+ error = phandle->ops->xfer_cmd(phandle, (uint8_t *) pcmd,
206+ sizeof(pcmd->body.stop_streaming.req)
207+ + HEADER_SIZE, (uint8_t *) prsp,
208+ sizeof(prsp->body.stop_streaming.rsp)
209+ + HEADER_SIZE);
210+ } else {
211+ error = AS10X_CMD_ERROR;
212+ }
213+
214+ if (error < 0)
215+ goto out;
216+
217+ /* parse response */
218+ error = as10x_rsp_parse(prsp, CONTROL_PROC_STOP_STREAMING_RSP);
219+
220+out:
221+ LEAVE();
222+ return error;
223+}
drivers/staging/media/as102/as10x_handle.h+58−0
@@ -0,0 +1,58 @@
1+/*
2+ * Abilis Systems Single DVB-T Receiver
3+ * Copyright (C) 2008 Pierrick Hascoet <pierrick.hascoet@abilis.com>
4+ *
5+ * This program is free software; you can redistribute it and/or modify
6+ * it under the terms of the GNU General Public License as published by
7+ * the Free Software Foundation; either version 2, or (at your option)
8+ * any later version.
9+ *
10+ * This program is distributed in the hope that it will be useful,
11+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
12+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+ * GNU General Public License for more details.
14+ *
15+ * You should have received a copy of the GNU General Public License
16+ * along with this program; if not, write to the Free Software
17+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18+ */
19+#ifdef __KERNEL__
20+struct as102_bus_adapter_t;
21+struct as102_dev_t;
22+
23+#define as10x_handle_t struct as102_bus_adapter_t
24+#include "as10x_cmd.h"
25+
26+/* values for "mode" field */
27+#define REGMODE8 8
28+#define REGMODE16 16
29+#define REGMODE32 32
30+
31+struct as102_priv_ops_t {
32+ int (*upload_fw_pkt) (struct as102_bus_adapter_t *bus_adap,
33+ unsigned char *buf, int buflen, int swap32);
34+
35+ int (*send_cmd) (struct as102_bus_adapter_t *bus_adap,
36+ unsigned char *buf, int buflen);
37+
38+ int (*xfer_cmd) (struct as102_bus_adapter_t *bus_adap,
39+ unsigned char *send_buf, int send_buf_len,
40+ unsigned char *recv_buf, int recv_buf_len);
41+/*
42+ int (*pid_filter) (struct as102_bus_adapter_t *bus_adap,
43+ int index, u16 pid, int onoff);
44+*/
45+ int (*start_stream) (struct as102_dev_t *dev);
46+ void (*stop_stream) (struct as102_dev_t *dev);
47+
48+ int (*reset_target) (struct as102_bus_adapter_t *bus_adap);
49+
50+ int (*read_write)(struct as102_bus_adapter_t *bus_adap, uint8_t mode,
51+ uint32_t rd_addr, uint16_t rd_len,
52+ uint32_t wr_addr, uint16_t wr_len);
53+
54+ int (*as102_read_ep2) (struct as102_bus_adapter_t *bus_adap,
55+ unsigned char *recv_buf,
56+ int recv_buf_len);
57+};
58+#endif
drivers/staging/media/as102/as10x_types.h+198−0
@@ -0,0 +1,198 @@
1+/*
2+ * Abilis Systems Single DVB-T Receiver
3+ * Copyright (C) 2008 Pierrick Hascoet <pierrick.hascoet@abilis.com>
4+ *
5+ * This program is free software; you can redistribute it and/or modify
6+ * it under the terms of the GNU General Public License as published by
7+ * the Free Software Foundation; either version 2, or (at your option)
8+ * any later version.
9+ *
10+ * This program is distributed in the hope that it will be useful,
11+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
12+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+ * GNU General Public License for more details.
14+ *
15+ * You should have received a copy of the GNU General Public License
16+ * along with this program; if not, write to the Free Software
17+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18+ */
19+#ifndef _AS10X_TYPES_H_
20+#define _AS10X_TYPES_H_
21+
22+#include "as10x_handle.h"
23+
24+/*********************************/
25+/* MACRO DEFINITIONS */
26+/*********************************/
27+
28+/* bandwidth constant values */
29+#define BW_5_MHZ 0x00
30+#define BW_6_MHZ 0x01
31+#define BW_7_MHZ 0x02
32+#define BW_8_MHZ 0x03
33+
34+/* hierarchy priority selection values */
35+#define HIER_NO_PRIORITY 0x00
36+#define HIER_LOW_PRIORITY 0x01
37+#define HIER_HIGH_PRIORITY 0x02
38+
39+/* constellation available values */
40+#define CONST_QPSK 0x00
41+#define CONST_QAM16 0x01
42+#define CONST_QAM64 0x02
43+#define CONST_UNKNOWN 0xFF
44+
45+/* hierarchy available values */
46+#define HIER_NONE 0x00
47+#define HIER_ALPHA_1 0x01
48+#define HIER_ALPHA_2 0x02
49+#define HIER_ALPHA_4 0x03
50+#define HIER_UNKNOWN 0xFF
51+
52+/* interleaving available values */
53+#define INTLV_NATIVE 0x00
54+#define INTLV_IN_DEPTH 0x01
55+#define INTLV_UNKNOWN 0xFF
56+
57+/* code rate available values */
58+#define CODE_RATE_1_2 0x00
59+#define CODE_RATE_2_3 0x01
60+#define CODE_RATE_3_4 0x02
61+#define CODE_RATE_5_6 0x03
62+#define CODE_RATE_7_8 0x04
63+#define CODE_RATE_UNKNOWN 0xFF
64+
65+/* guard interval available values */
66+#define GUARD_INT_1_32 0x00
67+#define GUARD_INT_1_16 0x01
68+#define GUARD_INT_1_8 0x02
69+#define GUARD_INT_1_4 0x03
70+#define GUARD_UNKNOWN 0xFF
71+
72+/* transmission mode available values */
73+#define TRANS_MODE_2K 0x00
74+#define TRANS_MODE_8K 0x01
75+#define TRANS_MODE_4K 0x02
76+#define TRANS_MODE_UNKNOWN 0xFF
77+
78+/* DVBH signalling available values */
79+#define TIMESLICING_PRESENT 0x01
80+#define MPE_FEC_PRESENT 0x02
81+
82+/* tune state available */
83+#define TUNE_STATUS_NOT_TUNED 0x00
84+#define TUNE_STATUS_IDLE 0x01
85+#define TUNE_STATUS_LOCKING 0x02
86+#define TUNE_STATUS_SIGNAL_DVB_OK 0x03
87+#define TUNE_STATUS_STREAM_DETECTED 0x04
88+#define TUNE_STATUS_STREAM_TUNED 0x05
89+#define TUNE_STATUS_ERROR 0xFF
90+
91+/* available TS FID filter types */
92+#define TS_PID_TYPE_TS 0
93+#define TS_PID_TYPE_PSI_SI 1
94+#define TS_PID_TYPE_MPE 2
95+
96+/* number of echos available */
97+#define MAX_ECHOS 15
98+
99+/* Context types */
100+#define CONTEXT_LNA 1010
101+#define CONTEXT_ELNA_HYSTERESIS 4003
102+#define CONTEXT_ELNA_GAIN 4004
103+#define CONTEXT_MER_THRESHOLD 5005
104+#define CONTEXT_MER_OFFSET 5006
105+#define CONTEXT_IR_STATE 7000
106+#define CONTEXT_TSOUT_MSB_FIRST 7004
107+#define CONTEXT_TSOUT_FALLING_EDGE 7005
108+
109+/* Configuration modes */
110+#define CFG_MODE_ON 0
111+#define CFG_MODE_OFF 1
112+#define CFG_MODE_AUTO 2
113+
114+#pragma pack(1)
115+struct as10x_tps {
116+ uint8_t constellation;
117+ uint8_t hierarchy;
118+ uint8_t interleaving_mode;
119+ uint8_t code_rate_HP;
120+ uint8_t code_rate_LP;
121+ uint8_t guard_interval;
122+ uint8_t transmission_mode;
123+ uint8_t DVBH_mask_HP;
124+ uint8_t DVBH_mask_LP;
125+ uint16_t cell_ID;
126+};
127+
128+struct as10x_tune_args {
129+ /* frequency */
130+ uint32_t freq;
131+ /* bandwidth */
132+ uint8_t bandwidth;
133+ /* hierarchy selection */
134+ uint8_t hier_select;
135+ /* constellation */
136+ uint8_t constellation;
137+ /* hierarchy */
138+ uint8_t hierarchy;
139+ /* interleaving mode */
140+ uint8_t interleaving_mode;
141+ /* code rate */
142+ uint8_t code_rate;
143+ /* guard interval */
144+ uint8_t guard_interval;
145+ /* transmission mode */
146+ uint8_t transmission_mode;
147+};
148+
149+struct as10x_tune_status {
150+ /* tune status */
151+ uint8_t tune_state;
152+ /* signal strength */
153+ int16_t signal_strength;
154+ /* packet error rate 10^-4 */
155+ uint16_t PER;
156+ /* bit error rate 10^-4 */
157+ uint16_t BER;
158+};
159+
160+struct as10x_demod_stats {
161+ /* frame counter */
162+ uint32_t frame_count;
163+ /* Bad frame counter */
164+ uint32_t bad_frame_count;
165+ /* Number of wrong bytes fixed by Reed-Solomon */
166+ uint32_t bytes_fixed_by_rs;
167+ /* Averaged MER */
168+ uint16_t mer;
169+ /* statistics calculation state indicator (started or not) */
170+ uint8_t has_started;
171+};
172+
173+struct as10x_ts_filter {
174+ uint16_t pid; /** valid PID value 0x00 : 0x2000 */
175+ uint8_t type; /** Red TS_PID_TYPE_<N> values */
176+ uint8_t idx; /** index in filtering table */
177+};
178+
179+struct as10x_register_value {
180+ uint8_t mode;
181+ union {
182+ uint8_t value8; /* 8 bit value */
183+ uint16_t value16; /* 16 bit value */
184+ uint32_t value32; /* 32 bit value */
185+ }u;
186+};
187+
188+#pragma pack()
189+
190+struct as10x_register_addr {
191+ /* register addr */
192+ uint32_t addr;
193+ /* register mode access */
194+ uint8_t mode;
195+};
196+
197+
198+#endif
drivers/staging/media/cxd2099/Kconfigrenamed from drivers/staging/cxd2099/Kconfig+0−0

File renamed without changes.

drivers/staging/media/cxd2099/Makefilerenamed from drivers/staging/cxd2099/Makefile+0−0

File renamed without changes.

drivers/staging/media/cxd2099/TODOrenamed from drivers/staging/cxd2099/TODO+0−0

File renamed without changes.

drivers/staging/media/cxd2099/cxd2099.crenamed from drivers/staging/cxd2099/cxd2099.c+0−0

File renamed without changes.

drivers/staging/media/cxd2099/cxd2099.hrenamed from drivers/staging/cxd2099/cxd2099.h+0−0

File renamed without changes.

drivers/staging/media/dt3155v4l/Kconfigrenamed from drivers/staging/dt3155v4l/Kconfig+0−0

File renamed without changes.

drivers/staging/media/dt3155v4l/Makefilerenamed from drivers/staging/dt3155v4l/Makefile+0−0

File renamed without changes.

drivers/staging/media/dt3155v4l/dt3155v4l.crenamed from drivers/staging/dt3155v4l/dt3155v4l.c+0−0

File renamed without changes.

drivers/staging/media/dt3155v4l/dt3155v4l.hrenamed from drivers/staging/dt3155v4l/dt3155v4l.h+0−0

File renamed without changes.

drivers/staging/media/easycap/Kconfigrenamed from drivers/staging/easycap/Kconfig+0−0

File renamed without changes.

drivers/staging/media/easycap/Makefilerenamed from drivers/staging/easycap/Makefile+0−0

File renamed without changes.

drivers/staging/media/easycap/READMErenamed from drivers/staging/easycap/README+0−0

File renamed without changes.

drivers/staging/media/easycap/easycap.hrenamed from drivers/staging/easycap/easycap.h+0−0

File renamed without changes.

drivers/staging/media/easycap/easycap_ioctl.crenamed from drivers/staging/easycap/easycap_ioctl.c+0−0

File renamed without changes.

drivers/staging/media/easycap/easycap_low.crenamed from drivers/staging/easycap/easycap_low.c+0−0

File renamed without changes.

drivers/staging/media/easycap/easycap_main.crenamed from drivers/staging/easycap/easycap_main.c+0−0

File renamed without changes.

drivers/staging/media/easycap/easycap_settings.crenamed from drivers/staging/easycap/easycap_settings.c+0−0

File renamed without changes.

drivers/staging/media/easycap/easycap_sound.crenamed from drivers/staging/easycap/easycap_sound.c+0−0

File renamed without changes.

drivers/staging/media/easycap/easycap_testcard.crenamed from drivers/staging/easycap/easycap_testcard.c+0−0

File renamed without changes.

drivers/staging/media/go7007/Kconfigrenamed from drivers/staging/go7007/Kconfig+0−0

File renamed without changes.

drivers/staging/media/go7007/Makefilerenamed from drivers/staging/go7007/Makefile+0−0

File renamed without changes.

drivers/staging/media/go7007/READMErenamed from drivers/staging/go7007/README+0−0

File renamed without changes.

drivers/staging/media/go7007/go7007-driver.crenamed from drivers/staging/go7007/go7007-driver.c+0−0

File renamed without changes.

drivers/staging/media/go7007/go7007-fw.crenamed from drivers/staging/go7007/go7007-fw.c+0−0

File renamed without changes.

drivers/staging/media/go7007/go7007-i2c.crenamed from drivers/staging/go7007/go7007-i2c.c+0−0

File renamed without changes.

drivers/staging/media/go7007/go7007-priv.hrenamed from drivers/staging/go7007/go7007-priv.h+0−0

File renamed without changes.

drivers/staging/media/go7007/go7007-usb.crenamed from drivers/staging/go7007/go7007-usb.c+0−0

File renamed without changes.

drivers/staging/media/go7007/go7007-v4l2.crenamed from drivers/staging/go7007/go7007-v4l2.c+0−0

File renamed without changes.

drivers/staging/media/go7007/go7007.hrenamed from drivers/staging/go7007/go7007.h+0−0

File renamed without changes.

drivers/staging/media/go7007/go7007.txtrenamed from drivers/staging/go7007/go7007.txt+0−0

File renamed without changes.

drivers/staging/media/go7007/s2250-board.crenamed from drivers/staging/go7007/s2250-board.c+0−0

File renamed without changes.

drivers/staging/media/go7007/s2250-loader.crenamed from drivers/staging/go7007/s2250-loader.c+0−0

File renamed without changes.

drivers/staging/media/go7007/s2250-loader.hrenamed from drivers/staging/go7007/s2250-loader.h+0−0

File renamed without changes.

drivers/staging/media/go7007/saa7134-go7007.crenamed from drivers/staging/go7007/saa7134-go7007.c+0−0

File renamed without changes.

drivers/staging/media/go7007/snd-go7007.crenamed from drivers/staging/go7007/snd-go7007.c+0−0

File renamed without changes.

drivers/staging/media/go7007/wis-i2c.hrenamed from drivers/staging/go7007/wis-i2c.h+0−0

File renamed without changes.

drivers/staging/media/go7007/wis-ov7640.crenamed from drivers/staging/go7007/wis-ov7640.c+0−0

File renamed without changes.

drivers/staging/media/go7007/wis-saa7113.crenamed from drivers/staging/go7007/wis-saa7113.c+0−0

File renamed without changes.

drivers/staging/media/go7007/wis-saa7115.crenamed from drivers/staging/go7007/wis-saa7115.c+0−0

File renamed without changes.

drivers/staging/media/go7007/wis-sony-tuner.crenamed from drivers/staging/go7007/wis-sony-tuner.c+0−0

File renamed without changes.

drivers/staging/media/go7007/wis-tw2804.crenamed from drivers/staging/go7007/wis-tw2804.c+0−0

File renamed without changes.

drivers/staging/media/go7007/wis-tw9903.crenamed from drivers/staging/go7007/wis-tw9903.c+0−0

File renamed without changes.

drivers/staging/media/go7007/wis-uda1342.crenamed from drivers/staging/go7007/wis-uda1342.c+0−0

File renamed without changes.

drivers/staging/media/lirc/Kconfigrenamed from drivers/staging/lirc/Kconfig+0−0

File renamed without changes.

drivers/staging/media/lirc/Makefilerenamed from drivers/staging/lirc/Makefile+0−0

File renamed without changes.

drivers/staging/media/lirc/TODOrenamed from drivers/staging/lirc/TODO+0−0

File renamed without changes.

drivers/staging/media/lirc/TODO.lirc_zilogrenamed from drivers/staging/lirc/TODO.lirc_zilog+0−0

File renamed without changes.

drivers/staging/media/lirc/lirc_bt829.crenamed from drivers/staging/lirc/lirc_bt829.c+0−0

File renamed without changes.

drivers/staging/media/lirc/lirc_ene0100.hrenamed from drivers/staging/lirc/lirc_ene0100.h+0−0

File renamed without changes.

drivers/staging/media/lirc/lirc_igorplugusb.crenamed from drivers/staging/lirc/lirc_igorplugusb.c+0−0

File renamed without changes.

drivers/staging/media/lirc/lirc_imon.crenamed from drivers/staging/lirc/lirc_imon.c+0−0

File renamed without changes.

drivers/staging/media/lirc/lirc_parallel.crenamed from drivers/staging/lirc/lirc_parallel.c+0−0

File renamed without changes.

drivers/staging/media/lirc/lirc_parallel.hrenamed from drivers/staging/lirc/lirc_parallel.h+0−0

File renamed without changes.

drivers/staging/media/lirc/lirc_sasem.crenamed from drivers/staging/lirc/lirc_sasem.c+0−0

File renamed without changes.

drivers/staging/media/lirc/lirc_serial.crenamed from drivers/staging/lirc/lirc_serial.c+0−0

File renamed without changes.

drivers/staging/media/lirc/lirc_sir.crenamed from drivers/staging/lirc/lirc_sir.c+0−0

File renamed without changes.

drivers/staging/media/lirc/lirc_ttusbir.crenamed from drivers/staging/lirc/lirc_ttusbir.c+0−0

File renamed without changes.

drivers/staging/media/lirc/lirc_zilog.crenamed from drivers/staging/lirc/lirc_zilog.c+0−0

File renamed without changes.

drivers/staging/media/solo6x10/Kconfigrenamed from drivers/staging/solo6x10/Kconfig+0−0

File renamed without changes.

drivers/staging/media/solo6x10/Makefilerenamed from drivers/staging/solo6x10/Makefile+0−0

File renamed without changes.

drivers/staging/media/solo6x10/TODOrenamed from drivers/staging/solo6x10/TODO+0−0

File renamed without changes.

drivers/staging/media/solo6x10/core.crenamed from drivers/staging/solo6x10/core.c+0−0

File renamed without changes.

drivers/staging/media/solo6x10/disp.crenamed from drivers/staging/solo6x10/disp.c+0−0

File renamed without changes.

drivers/staging/media/solo6x10/enc.crenamed from drivers/staging/solo6x10/enc.c+0−0

File renamed without changes.

drivers/staging/media/solo6x10/g723.crenamed from drivers/staging/solo6x10/g723.c+0−0

File renamed without changes.

drivers/staging/media/solo6x10/gpio.crenamed from drivers/staging/solo6x10/gpio.c+0−0

File renamed without changes.

drivers/staging/media/solo6x10/i2c.crenamed from drivers/staging/solo6x10/i2c.c+0−0

File renamed without changes.

drivers/staging/media/solo6x10/jpeg.hrenamed from drivers/staging/solo6x10/jpeg.h+0−0

File renamed without changes.

drivers/staging/media/solo6x10/offsets.hrenamed from drivers/staging/solo6x10/offsets.h+0−0

File renamed without changes.

drivers/staging/media/solo6x10/osd-font.hrenamed from drivers/staging/solo6x10/osd-font.h+0−0

File renamed without changes.

drivers/staging/media/solo6x10/p2m.crenamed from drivers/staging/solo6x10/p2m.c+0−0

File renamed without changes.

drivers/staging/media/solo6x10/registers.hrenamed from drivers/staging/solo6x10/registers.h+0−0

File renamed without changes.

drivers/staging/media/solo6x10/solo6x10.hrenamed from drivers/staging/solo6x10/solo6x10.h+0−0

File renamed without changes.

drivers/staging/media/solo6x10/tw28.crenamed from drivers/staging/solo6x10/tw28.c+0−0

File renamed without changes.

drivers/staging/media/solo6x10/tw28.hrenamed from drivers/staging/solo6x10/tw28.h+0−0

File renamed without changes.

drivers/staging/media/solo6x10/v4l2-enc.crenamed from drivers/staging/solo6x10/v4l2-enc.c+0−0

File renamed without changes.

drivers/staging/media/solo6x10/v4l2.crenamed from drivers/staging/solo6x10/v4l2.c+0−0

File renamed without changes.

include/linux/videodev2.h+27−0
@@ -653,6 +653,10 @@ struct v4l2_buffer { · 652 unmodified lines
653653 #define V4L2_BUF_FLAG_ERROR 0x0040
654654 #define V4L2_BUF_FLAG_TIMECODE 0x0100 /* timecode field is valid */
655655 #define V4L2_BUF_FLAG_INPUT 0x0200 /* input field is valid */
656+#define V4L2_BUF_FLAG_PREPARED 0x0400 /* Buffer is prepared for queuing */
657+/* Cache handling flags */
658+#define V4L2_BUF_FLAG_NO_CACHE_INVALIDATE 0x0800
659+#define V4L2_BUF_FLAG_NO_CACHE_CLEAN 0x1000
656660
657661 /*
658662 * O V E R L A Y P R E V I E W
@@ -1165,6 +1169,7 @@ enum v4l2_power_line_frequency { · 506 unmodified lines
11651169 V4L2_CID_POWER_LINE_FREQUENCY_DISABLED = 0,
11661170 V4L2_CID_POWER_LINE_FREQUENCY_50HZ = 1,
11671171 V4L2_CID_POWER_LINE_FREQUENCY_60HZ = 2,
1172+ V4L2_CID_POWER_LINE_FREQUENCY_AUTO = 3,
11681173 };
11691174 #define V4L2_CID_HUE_AUTO (V4L2_CID_BASE+25)
11701175 #define V4L2_CID_WHITE_BALANCE_TEMPERATURE (V4L2_CID_BASE+26)
@@ -2138,6 +2143,23 @@ struct v4l2_dbg_chip_ident { · 967 unmodified lines
21382143 __u32 revision; /* chip revision, chip specific */
21392144 } __attribute__ ((packed));
21402145
2146+/**
2147+ * struct v4l2_create_buffers - VIDIOC_CREATE_BUFS argument
2148+ * @index: on return, index of the first created buffer
2149+ * @count: entry: number of requested buffers,
2150+ * return: number of created buffers
2151+ * @memory: buffer memory type
2152+ * @format: frame format, for which buffers are requested
2153+ * @reserved: future extensions
2154+ */
2155+struct v4l2_create_buffers {
2156+ __u32 index;
2157+ __u32 count;
2158+ enum v4l2_memory memory;
2159+ struct v4l2_format format;
2160+ __u32 reserved[8];
2161+};
2162+
21412163 /*
21422164 * I O C T L C O D E S F O R V I D E O D E V I C E S
21432165 *
@@ -2228,6 +2250,11 @@ struct v4l2_dbg_chip_ident { · 84 unmodified lines
22282250 #define VIDIOC_SUBSCRIBE_EVENT _IOW('V', 90, struct v4l2_event_subscription)
22292251 #define VIDIOC_UNSUBSCRIBE_EVENT _IOW('V', 91, struct v4l2_event_subscription)
22302252
2253+/* Experimental, the below two ioctls may change over the next couple of kernel
2254+ versions */
2255+#define VIDIOC_CREATE_BUFS _IOWR('V', 92, struct v4l2_create_buffers)
2256+#define VIDIOC_PREPARE_BUF _IOWR('V', 93, struct v4l2_buffer)
2257+
22312258 /* Reminder: when adding new ioctls please add support for them to
22322259 drivers/media/video/v4l2-compat-ioctl32.c as well! */
22332260
include/media/ov772x.h+12−14
@@ -12,12 +12,9 @@ · 11 unmodified lines
1212 #ifndef __OV772X_H__
1313 #define __OV772X_H__
1414
15−#include <media/soc_camera.h>
16−
1715 /* for flags */
1816 #define OV772X_FLAG_VFLIP (1 << 0) /* Vertical flip image */
1917 #define OV772X_FLAG_HFLIP (1 << 1) /* Horizontal flip image */
20−#define OV772X_FLAG_8BIT (1 << 2) /* default 10 bit */
2118
2219 /*
2320 * for Edge ctrl
@@ -32,22 +29,23 @@ struct ov772x_edge_ctrl { · 8 unmodified lines
3229 unsigned char lower;
3330 };
3431
35−#define OV772X_MANUAL_EDGE_CTRL 0x80 /* un-used bit of strength */
36−#define EDGE_STRENGTH_MASK 0x1F
37−#define EDGE_THRESHOLD_MASK 0x0F
38−#define EDGE_UPPER_MASK 0xFF
39−#define EDGE_LOWER_MASK 0xFF
32+#define OV772X_MANUAL_EDGE_CTRL 0x80 /* un-used bit of strength */
33+#define OV772X_EDGE_STRENGTH_MASK 0x1F
34+#define OV772X_EDGE_THRESHOLD_MASK 0x0F
35+#define OV772X_EDGE_UPPER_MASK 0xFF
36+#define OV772X_EDGE_LOWER_MASK 0xFF
4037
4138 #define OV772X_AUTO_EDGECTRL(u, l) \
4239 { \
43− .upper = (u & EDGE_UPPER_MASK), \
44− .lower = (l & EDGE_LOWER_MASK), \
40+ .upper = (u & OV772X_EDGE_UPPER_MASK), \
41+ .lower = (l & OV772X_EDGE_LOWER_MASK), \
4542 }
4643
47−#define OV772X_MANUAL_EDGECTRL(s, t) \
48−{ \
49− .strength = (s & EDGE_STRENGTH_MASK) | OV772X_MANUAL_EDGE_CTRL,\
50− .threshold = (t & EDGE_THRESHOLD_MASK), \
44+#define OV772X_MANUAL_EDGECTRL(s, t) \
45+{ \
46+ .strength = (s & OV772X_EDGE_STRENGTH_MASK) | \
47+ OV772X_MANUAL_EDGE_CTRL, \
48+ .threshold = (t & OV772X_EDGE_THRESHOLD_MASK), \
5149 }
5250
5351 /*
include/media/s5k6aa.h+51−0
@@ -0,0 +1,51 @@
1+/*
2+ * S5K6AAFX camera sensor driver header
3+ *
4+ * Copyright (C) 2011 Samsung Electronics Co., Ltd.
5+ *
6+ * This program is free software; you can redistribute it and/or modify
7+ * it under the terms of the GNU General Public License as published by
8+ * the Free Software Foundation; either version 2 of the License, or
9+ * (at your option) any later version.
10+ */
11+
12+#ifndef S5K6AA_H
13+#define S5K6AA_H
14+
15+#include <media/v4l2-mediabus.h>
16+
17+/**
18+ * struct s5k6aa_gpio - data structure describing a GPIO
19+ * @gpio: GPIO number
20+ * @level: indicates active state of the @gpio
21+ */
22+struct s5k6aa_gpio {
23+ int gpio;
24+ int level;
25+};
26+
27+/**
28+ * struct s5k6aa_platform_data - s5k6aa driver platform data
29+ * @set_power: an additional callback to the board code, called
30+ * after enabling the regulators and before switching
31+ * the sensor off
32+ * @mclk_frequency: sensor's master clock frequency in Hz
33+ * @gpio_reset: GPIO driving RESET pin
34+ * @gpio_stby: GPIO driving STBY pin
35+ * @nlanes: maximum number of MIPI-CSI lanes used
36+ * @horiz_flip: default horizontal image flip value, non zero to enable
37+ * @vert_flip: default vertical image flip value, non zero to enable
38+ */
39+
40+struct s5k6aa_platform_data {
41+ int (*set_power)(int enable);
42+ unsigned long mclk_frequency;
43+ struct s5k6aa_gpio gpio_reset;
44+ struct s5k6aa_gpio gpio_stby;
45+ enum v4l2_mbus_type bus_type;
46+ u8 nlanes;
47+ u8 horiz_flip;
48+ u8 vert_flip;
49+};
50+
51+#endif /* S5K6AA_H */
include/media/soc_camera.h+31−73
@@ -12,12 +12,14 @@ · 11 unmodified lines
1212 #ifndef SOC_CAMERA_H
1313 #define SOC_CAMERA_H
1414
15+#include <linux/bitops.h>
1516 #include <linux/device.h>
1617 #include <linux/mutex.h>
1718 #include <linux/pm.h>
1819 #include <linux/videodev2.h>
1920 #include <media/videobuf-core.h>
2021 #include <media/videobuf2-core.h>
22+#include <media/v4l2-ctrls.h>
2123 #include <media/v4l2-device.h>
2224
2325 struct file;
@@ -37,8 +39,8 @@ struct soc_camera_device { · 13 unmodified lines
3739 unsigned char iface; /* Host number */
3840 unsigned char devnum; /* Device number per host */
3941 struct soc_camera_sense *sense; /* See comment in struct definition */
40− struct soc_camera_ops *ops;
4142 struct video_device *vdev;
43+ struct v4l2_ctrl_handler ctrl_handler;
4244 const struct soc_camera_format_xlate *current_fmt;
4345 struct soc_camera_format_xlate *user_formats;
4446 int num_user_formats;
@@ -93,14 +95,10 @@ struct soc_camera_host_ops { · 48 unmodified lines
9395 int (*reqbufs)(struct soc_camera_device *, struct v4l2_requestbuffers *);
9496 int (*querycap)(struct soc_camera_host *, struct v4l2_capability *);
9597 int (*set_bus_param)(struct soc_camera_device *, __u32);
96− int (*get_ctrl)(struct soc_camera_device *, struct v4l2_control *);
97− int (*set_ctrl)(struct soc_camera_device *, struct v4l2_control *);
9898 int (*get_parm)(struct soc_camera_device *, struct v4l2_streamparm *);
9999 int (*set_parm)(struct soc_camera_device *, struct v4l2_streamparm *);
100100 int (*enum_fsizes)(struct soc_camera_device *, struct v4l2_frmsizeenum *);
101101 unsigned int (*poll)(struct file *, poll_table *);
102− const struct v4l2_queryctrl *controls;
103− int num_controls;
104102 };
105103
106104 #define SOCAM_SENSOR_INVERT_PCLK (1 << 0)
@@ -193,13 +191,6 @@ struct soc_camera_format_xlate { · 86 unmodified lines
193191 const struct soc_mbus_pixelfmt *host_fmt;
194192 };
195193
196−struct soc_camera_ops {
197− unsigned long (*query_bus_param)(struct soc_camera_device *);
198− int (*set_bus_param)(struct soc_camera_device *, unsigned long);
199− const struct v4l2_queryctrl *controls;
200− int num_controls;
201−};
202−
203194 #define SOCAM_SENSE_PCLK_CHANGED (1 << 0)
204195
205196 /**
@@ -226,65 +217,18 @@ struct soc_camera_sense { · 20 unmodified lines
226217 unsigned long pixel_clock;
227218 };
228219
229−static inline struct v4l2_queryctrl const *soc_camera_find_qctrl(
230− struct soc_camera_ops *ops, int id)
231−{
232− int i;
233−
234− for (i = 0; i < ops->num_controls; i++)
235− if (ops->controls[i].id == id)
236− return &ops->controls[i];
237−
238− return NULL;
239−}
240−
241−#define SOCAM_MASTER (1 << 0)
242−#define SOCAM_SLAVE (1 << 1)
243−#define SOCAM_HSYNC_ACTIVE_HIGH (1 << 2)
244−#define SOCAM_HSYNC_ACTIVE_LOW (1 << 3)
245−#define SOCAM_VSYNC_ACTIVE_HIGH (1 << 4)
246−#define SOCAM_VSYNC_ACTIVE_LOW (1 << 5)
247−#define SOCAM_DATAWIDTH_4 (1 << 6)
248−#define SOCAM_DATAWIDTH_8 (1 << 7)
249−#define SOCAM_DATAWIDTH_9 (1 << 8)
250−#define SOCAM_DATAWIDTH_10 (1 << 9)
251−#define SOCAM_DATAWIDTH_15 (1 << 10)
252−#define SOCAM_DATAWIDTH_16 (1 << 11)
253−#define SOCAM_PCLK_SAMPLE_RISING (1 << 12)
254−#define SOCAM_PCLK_SAMPLE_FALLING (1 << 13)
255−#define SOCAM_DATA_ACTIVE_HIGH (1 << 14)
256−#define SOCAM_DATA_ACTIVE_LOW (1 << 15)
257−#define SOCAM_MIPI_1LANE (1 << 16)
258−#define SOCAM_MIPI_2LANE (1 << 17)
259−#define SOCAM_MIPI_3LANE (1 << 18)
260−#define SOCAM_MIPI_4LANE (1 << 19)
261−#define SOCAM_MIPI (SOCAM_MIPI_1LANE | SOCAM_MIPI_2LANE | \
262− SOCAM_MIPI_3LANE | SOCAM_MIPI_4LANE)
220+#define SOCAM_DATAWIDTH(x) BIT((x) - 1)
221+#define SOCAM_DATAWIDTH_4 SOCAM_DATAWIDTH(4)
222+#define SOCAM_DATAWIDTH_8 SOCAM_DATAWIDTH(8)
223+#define SOCAM_DATAWIDTH_9 SOCAM_DATAWIDTH(9)
224+#define SOCAM_DATAWIDTH_10 SOCAM_DATAWIDTH(10)
225+#define SOCAM_DATAWIDTH_15 SOCAM_DATAWIDTH(15)
226+#define SOCAM_DATAWIDTH_16 SOCAM_DATAWIDTH(16)
263227
264228 #define SOCAM_DATAWIDTH_MASK (SOCAM_DATAWIDTH_4 | SOCAM_DATAWIDTH_8 | \
265229 SOCAM_DATAWIDTH_9 | SOCAM_DATAWIDTH_10 | \
266230 SOCAM_DATAWIDTH_15 | SOCAM_DATAWIDTH_16)
267231
268−static inline unsigned long soc_camera_bus_param_compatible(
269− unsigned long camera_flags, unsigned long bus_flags)
270−{
271− unsigned long common_flags, hsync, vsync, pclk, data, buswidth, mode;
272− unsigned long mipi;
273−
274− common_flags = camera_flags & bus_flags;
275−
276− hsync = common_flags & (SOCAM_HSYNC_ACTIVE_HIGH | SOCAM_HSYNC_ACTIVE_LOW);
277− vsync = common_flags & (SOCAM_VSYNC_ACTIVE_HIGH | SOCAM_VSYNC_ACTIVE_LOW);
278− pclk = common_flags & (SOCAM_PCLK_SAMPLE_RISING | SOCAM_PCLK_SAMPLE_FALLING);
279− data = common_flags & (SOCAM_DATA_ACTIVE_HIGH | SOCAM_DATA_ACTIVE_LOW);
280− mode = common_flags & (SOCAM_MASTER | SOCAM_SLAVE);
281− buswidth = common_flags & SOCAM_DATAWIDTH_MASK;
282− mipi = common_flags & SOCAM_MIPI;
283−
284− return ((!hsync || !vsync || !pclk || !data || !mode || !buswidth) && !mipi) ? 0 :
285− common_flags;
286−}
287−
288232 static inline void soc_camera_limit_side(int *start, int *length,
289233 unsigned int start_min,
290234 unsigned int length_min, unsigned int length_max)
@@ -300,23 +244,37 @@ static inline void soc_camera_limit_side(int *start, int *length, · 9 unmodified lines
300244 *start = start_min + length_max - *length;
301245 }
302246
303−extern unsigned long soc_camera_apply_sensor_flags(struct soc_camera_link *icl,
304− unsigned long flags);
247+unsigned long soc_camera_apply_sensor_flags(struct soc_camera_link *icl,
248+ unsigned long flags);
249+unsigned long soc_camera_apply_board_flags(struct soc_camera_link *icl,
250+ const struct v4l2_mbus_config *cfg);
305251
306252 /* This is only temporary here - until v4l2-subdev begins to link to video_device */
307253 #include <linux/i2c.h>
308−static inline struct video_device *soc_camera_i2c_to_vdev(struct i2c_client *client)
254+static inline struct video_device *soc_camera_i2c_to_vdev(const struct i2c_client *client)
255+{
256+ struct v4l2_subdev *sd = i2c_get_clientdata(client);
257+ struct soc_camera_device *icd = (struct soc_camera_device *)sd->grp_id;
258+ return icd ? icd->vdev : NULL;
259+}
260+
261+static inline struct soc_camera_link *soc_camera_i2c_to_link(const struct i2c_client *client)
262+{
263+ return client->dev.platform_data;
264+}
265+
266+static inline struct v4l2_subdev *soc_camera_vdev_to_subdev(const struct video_device *vdev)
309267 {
310− struct soc_camera_device *icd = client->dev.platform_data;
311− return icd->vdev;
268+ struct soc_camera_device *icd = dev_get_drvdata(vdev->parent);
269+ return soc_camera_to_subdev(icd);
312270 }
313271
314−static inline struct soc_camera_device *soc_camera_from_vb2q(struct vb2_queue *vq)
272+static inline struct soc_camera_device *soc_camera_from_vb2q(const struct vb2_queue *vq)
315273 {
316274 return container_of(vq, struct soc_camera_device, vb2_vidq);
317275 }
318276
319−static inline struct soc_camera_device *soc_camera_from_vbq(struct videobuf_queue *vq)
277+static inline struct soc_camera_device *soc_camera_from_vbq(const struct videobuf_queue *vq)
320278 {
321279 return container_of(vq, struct soc_camera_device, vb_vidq);
322280 }
include/media/soc_camera_platform.h+3−1
@@ -13,6 +13,7 @@ · 12 unmodified lines
1313
1414 #include <linux/videodev2.h>
1515 #include <media/soc_camera.h>
16+#include <media/v4l2-mediabus.h>
1617
1718 struct device;
1819
@@ -20,7 +21,8 @@ struct soc_camera_platform_info { · 1 unmodified line
2021 const char *format_name;
2122 unsigned long format_depth;
2223 struct v4l2_mbus_framefmt format;
23− unsigned long bus_param;
24+ unsigned long mbus_param;
25+ enum v4l2_mbus_type mbus_type;
2426 struct soc_camera_device *icd;
2527 int (*set_capture)(struct soc_camera_platform_info *info, int enable);
2628 };
include/media/soc_mediabus.h+2−0
@@ -82,5 +82,7 @@ const struct soc_mbus_pixelfmt *soc_mbus_get_fmtdesc( · 81 unmodified lines
8282 s32 soc_mbus_bytes_per_line(u32 width, const struct soc_mbus_pixelfmt *mf);
8383 int soc_mbus_samples_per_pixel(const struct soc_mbus_pixelfmt *mf,
8484 unsigned int *numerator, unsigned int *denominator);
85+unsigned int soc_mbus_config_compatible(const struct v4l2_mbus_config *cfg,
86+ unsigned int flags);
8587
8688 #endif
include/media/v4l2-ioctl.h+2−0
@@ -122,6 +122,8 @@ struct v4l2_ioctl_ops { · 121 unmodified lines
122122 int (*vidioc_qbuf) (struct file *file, void *fh, struct v4l2_buffer *b);
123123 int (*vidioc_dqbuf) (struct file *file, void *fh, struct v4l2_buffer *b);
124124
125+ int (*vidioc_create_bufs)(struct file *file, void *fh, struct v4l2_create_buffers *b);
126+ int (*vidioc_prepare_buf)(struct file *file, void *fh, struct v4l2_buffer *b);
125127
126128 int (*vidioc_overlay) (struct file *file, void *fh, unsigned int i);
127129 int (*vidioc_g_fbuf) (struct file *file, void *fh,
include/media/v4l2-subdev.h+3−2
@@ -158,6 +158,7 @@ struct v4l2_subdev_core_ops { · 157 unmodified lines
158158 int (*s_ext_ctrls)(struct v4l2_subdev *sd, struct v4l2_ext_controls *ctrls);
159159 int (*try_ext_ctrls)(struct v4l2_subdev *sd, struct v4l2_ext_controls *ctrls);
160160 int (*querymenu)(struct v4l2_subdev *sd, struct v4l2_querymenu *qm);
161+ int (*g_std)(struct v4l2_subdev *sd, v4l2_std_id *norm);
161162 int (*s_std)(struct v4l2_subdev *sd, v4l2_std_id norm);
162163 long (*ioctl)(struct v4l2_subdev *sd, unsigned int cmd, void *arg);
163164 #ifdef CONFIG_VIDEO_ADV_DEBUG
@@ -534,13 +535,13 @@ struct v4l2_subdev { · 370 unmodified lines
534535 void *dev_priv;
535536 void *host_priv;
536537 /* subdev device node */
537− struct video_device devnode;
538+ struct video_device *devnode;
538539 };
539540
540541 #define media_entity_to_v4l2_subdev(ent) \
541542 container_of(ent, struct v4l2_subdev, entity)
542543 #define vdev_to_v4l2_subdev(vdev) \
543− container_of(vdev, struct v4l2_subdev, devnode)
544+ video_get_drvdata(vdev)
544545
545546 /*
546547 * Used for storing subdev information per file handle
include/media/videobuf2-core.h+35−15
@@ -105,6 +105,7 @@ enum vb2_fileio_flags { · 104 unmodified lines
105105 /**
106106 * enum vb2_buffer_state - current video buffer state
107107 * @VB2_BUF_STATE_DEQUEUED: buffer under userspace control
108+ * @VB2_BUF_STATE_PREPARED: buffer prepared in videobuf and by the driver
108109 * @VB2_BUF_STATE_QUEUED: buffer queued in videobuf, but not in driver
109110 * @VB2_BUF_STATE_ACTIVE: buffer queued in driver and possibly used
110111 * in a hardware operation
@@ -116,6 +117,7 @@ enum vb2_fileio_flags { · 5 unmodified lines
116117 */
117118 enum vb2_buffer_state {
118119 VB2_BUF_STATE_DEQUEUED,
120+ VB2_BUF_STATE_PREPARED,
119121 VB2_BUF_STATE_QUEUED,
120122 VB2_BUF_STATE_ACTIVE,
121123 VB2_BUF_STATE_DONE,
@@ -167,13 +169,21 @@ struct vb2_buffer { · 45 unmodified lines
167169 /**
168170 * struct vb2_ops - driver-specific callbacks
169171 *
170− * @queue_setup: called from a VIDIOC_REQBUFS handler, before
171− * memory allocation; driver should return the required
172− * number of buffers in num_buffers, the required number
173− * of planes per buffer in num_planes; the size of each
174− * plane should be set in the sizes[] array and optional
175− * per-plane allocator specific context in alloc_ctxs[]
176− * array
172+ * @queue_setup: called from VIDIOC_REQBUFS and VIDIOC_CREATE_BUFS
173+ * handlers before memory allocation, or, if
174+ * *num_planes != 0, after the allocation to verify a
175+ * smaller number of buffers. Driver should return
176+ * the required number of buffers in *num_buffers, the
177+ * required number of planes per buffer in *num_planes; the
178+ * size of each plane should be set in the sizes[] array
179+ * and optional per-plane allocator specific context in the
180+ * alloc_ctxs[] array. When called from VIDIOC_REQBUFS,
181+ * fmt == NULL, the driver has to use the currently
182+ * configured format and *num_buffers is the total number
183+ * of buffers, that are being allocated. When called from
184+ * VIDIOC_CREATE_BUFS, fmt != NULL and it describes the
185+ * target frame format. In this case *num_buffers are being
186+ * allocated additionally to q->num_buffers.
177187 * @wait_prepare: release any locks taken while calling vb2 functions;
178188 * it is called before an ioctl needs to wait for a new
179189 * buffer to arrive; required to avoid a deadlock in
@@ -186,11 +196,11 @@ struct vb2_buffer { · 6 unmodified lines
186196 * perform additional buffer-related initialization;
187197 * initialization failure (return != 0) will prevent
188198 * queue setup from completing successfully; optional
189− * @buf_prepare: called every time the buffer is queued from userspace;
190− * drivers may perform any initialization required before
191− * each hardware operation in this callback;
192− * if an error is returned, the buffer will not be queued
193− * in driver; optional
199+ * @buf_prepare: called every time the buffer is queued from userspace
200+ * and from the VIDIOC_PREPARE_BUF ioctl; drivers may
201+ * perform any initialization required before each hardware
202+ * operation in this callback; if an error is returned, the
203+ * buffer will not be queued in driver; optional
194204 * @buf_finish: called before every dequeue of the buffer back to
195205 * userspace; drivers may perform any operations required
196206 * before userspace accesses the buffer; optional
@@ -216,9 +226,9 @@ struct vb2_buffer { · 19 unmodified lines
216226 * pre-queued buffers before calling STREAMON
217227 */
218228 struct vb2_ops {
219− int (*queue_setup)(struct vb2_queue *q, unsigned int *num_buffers,
220− unsigned int *num_planes, unsigned int sizes[],
221− void *alloc_ctxs[]);
229+ int (*queue_setup)(struct vb2_queue *q, const struct v4l2_format *fmt,
230+ unsigned int *num_buffers, unsigned int *num_planes,
231+ unsigned int sizes[], void *alloc_ctxs[]);
222232
223233 void (*wait_prepare)(struct vb2_queue *q);
224234 void (*wait_finish)(struct vb2_queue *q);
@@ -298,6 +308,9 @@ int vb2_wait_for_all_buffers(struct vb2_queue *q); · 73 unmodified lines
298308 int vb2_querybuf(struct vb2_queue *q, struct v4l2_buffer *b);
299309 int vb2_reqbufs(struct vb2_queue *q, struct v4l2_requestbuffers *req);
300310
311+int vb2_create_bufs(struct vb2_queue *q, struct v4l2_create_buffers *create);
312+int vb2_prepare_buf(struct vb2_queue *q, struct v4l2_buffer *b);
313+
301314 int vb2_queue_init(struct vb2_queue *q);
302315
303316 void vb2_queue_release(struct vb2_queue *q);
@@ -309,6 +322,13 @@ int vb2_streamon(struct vb2_queue *q, enum v4l2_buf_type type); · 5 unmodified lines
309322 int vb2_streamoff(struct vb2_queue *q, enum v4l2_buf_type type);
310323
311324 int vb2_mmap(struct vb2_queue *q, struct vm_area_struct *vma);
325+#ifndef CONFIG_MMU
326+unsigned long vb2_get_unmapped_area(struct vb2_queue *q,
327+ unsigned long addr,
328+ unsigned long len,
329+ unsigned long pgoff,
330+ unsigned long flags);
331+#endif
312332 unsigned int vb2_poll(struct vb2_queue *q, struct file *file, poll_table *wait);
313333 size_t vb2_read(struct vb2_queue *q, char __user *data, size_t count,
314334 loff_t *ppos, int nonblock);

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t