0009-cameras.patch 32 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054
  1. From 4395d280ebe5b72648640ef63588fdadbcf3404b Mon Sep 17 00:00:00 2001
  2. From: Hans de Goede <hdegoede@redhat.com>
  3. Date: Sun, 10 Oct 2021 20:56:57 +0200
  4. Subject: [PATCH] ACPI: delay enumeration of devices with a _DEP pointing to an
  5. INT3472 device
  6. The clk and regulator frameworks expect clk/regulator consumer-devices
  7. to have info about the consumed clks/regulators described in the device's
  8. fw_node.
  9. To work around cases where this info is not present in the firmware tables,
  10. which is often the case on x86/ACPI devices, both frameworks allow the
  11. provider-driver to attach info about consumers to the clks/regulators
  12. when registering these.
  13. This causes problems with the probe ordering wrt drivers for consumers
  14. of these clks/regulators. Since the lookups are only registered when the
  15. provider-driver binds, trying to get these clks/regulators before then
  16. results in a -ENOENT error for clks and a dummy regulator for regulators.
  17. One case where we hit this issue is camera sensors such as e.g. the OV8865
  18. sensor found on the Microsoft Surface Go. The sensor uses clks, regulators
  19. and GPIOs provided by a TPS68470 PMIC which is described in an INT3472
  20. ACPI device. There is special platform code handling this and setting
  21. platform_data with the necessary consumer info on the MFD cells
  22. instantiated for the PMIC under: drivers/platform/x86/intel/int3472.
  23. For this to work properly the ov8865 driver must not bind to the I2C-client
  24. for the OV8865 sensor until after the TPS68470 PMIC gpio, regulator and
  25. clk MFD cells have all been fully setup.
  26. The OV8865 on the Microsoft Surface Go is just one example, all X86
  27. devices using the Intel IPU3 camera block found on recent Intel SoCs
  28. have similar issues where there is an INT3472 HID ACPI-device, which
  29. describes the clks and regulators, and the driver for this INT3472 device
  30. must be fully initialized before the sensor driver (any sensor driver)
  31. binds for things to work properly.
  32. On these devices the ACPI nodes describing the sensors all have a _DEP
  33. dependency on the matching INT3472 ACPI device (there is one per sensor).
  34. This allows solving the probe-ordering problem by delaying the enumeration
  35. (instantiation of the I2C-client in the ov8865 example) of ACPI-devices
  36. which have a _DEP dependency on an INT3472 device.
  37. The new acpi_dev_ready_for_enumeration() helper used for this is also
  38. exported because for devices, which have the enumeration_by_parent flag
  39. set, the parent-driver will do its own scan of child ACPI devices and
  40. it will try to enumerate those during its probe(). Code doing this such
  41. as e.g. the i2c-core-acpi.c code must call this new helper to ensure
  42. that it too delays the enumeration until all the _DEP dependencies are
  43. met on devices which have the new honor_deps flag set.
  44. Signed-off-by: Hans de Goede <hdegoede@redhat.com>
  45. Patchset: cameras
  46. ---
  47. drivers/acpi/scan.c | 3 +++
  48. 1 file changed, 3 insertions(+)
  49. diff --git a/drivers/acpi/scan.c b/drivers/acpi/scan.c
  50. index 42cec8120f18..72d0e599120f 100644
  51. --- a/drivers/acpi/scan.c
  52. +++ b/drivers/acpi/scan.c
  53. @@ -2108,6 +2108,9 @@ static acpi_status acpi_bus_check_add_2(acpi_handle handle, u32 lvl_not_used,
  54. static void acpi_default_enumeration(struct acpi_device *device)
  55. {
  56. + if (!acpi_dev_ready_for_enumeration(device))
  57. + return;
  58. +
  59. /*
  60. * Do not enumerate devices with enumeration_by_parent flag set as
  61. * they will be enumerated by their respective parents.
  62. --
  63. 2.38.1
  64. From 14a5925250e1eaf440925c88c6a055f2cf0490f1 Mon Sep 17 00:00:00 2001
  65. From: zouxiaoh <xiaohong.zou@intel.com>
  66. Date: Fri, 25 Jun 2021 08:52:59 +0800
  67. Subject: [PATCH] iommu: intel-ipu: use IOMMU passthrough mode for Intel IPUs
  68. Intel IPU(Image Processing Unit) has its own (IO)MMU hardware,
  69. The IPU driver allocates its own page table that is not mapped
  70. via the DMA, and thus the Intel IOMMU driver blocks access giving
  71. this error: DMAR: DRHD: handling fault status reg 3 DMAR:
  72. [DMA Read] Request device [00:05.0] PASID ffffffff
  73. fault addr 76406000 [fault reason 06] PTE Read access is not set
  74. As IPU is not an external facing device which is not risky, so use
  75. IOMMU passthrough mode for Intel IPUs.
  76. Change-Id: I6dcccdadac308cf42e20a18e1b593381391e3e6b
  77. Depends-On: Iacd67578e8c6a9b9ac73285f52b4081b72fb68a6
  78. Tracked-On: #JIITL8-411
  79. Signed-off-by: Bingbu Cao <bingbu.cao@intel.com>
  80. Signed-off-by: zouxiaoh <xiaohong.zou@intel.com>
  81. Signed-off-by: Xu Chongyang <chongyang.xu@intel.com>
  82. Patchset: cameras
  83. ---
  84. drivers/iommu/intel/iommu.c | 30 ++++++++++++++++++++++++++++++
  85. 1 file changed, 30 insertions(+)
  86. diff --git a/drivers/iommu/intel/iommu.c b/drivers/iommu/intel/iommu.c
  87. index 4c895b5f7e2d..f68f031dee46 100644
  88. --- a/drivers/iommu/intel/iommu.c
  89. +++ b/drivers/iommu/intel/iommu.c
  90. @@ -37,6 +37,12 @@
  91. #define IS_GFX_DEVICE(pdev) ((pdev->class >> 16) == PCI_BASE_CLASS_DISPLAY)
  92. #define IS_USB_DEVICE(pdev) ((pdev->class >> 8) == PCI_CLASS_SERIAL_USB)
  93. #define IS_ISA_DEVICE(pdev) ((pdev->class >> 8) == PCI_CLASS_BRIDGE_ISA)
  94. +#define IS_INTEL_IPU(pdev) ((pdev)->vendor == PCI_VENDOR_ID_INTEL && \
  95. + ((pdev)->device == 0x9a19 || \
  96. + (pdev)->device == 0x9a39 || \
  97. + (pdev)->device == 0x4e19 || \
  98. + (pdev)->device == 0x465d || \
  99. + (pdev)->device == 0x1919))
  100. #define IS_IPTS(pdev) ((pdev)->vendor == PCI_VENDOR_ID_INTEL && \
  101. ((pdev)->device == 0x9d3e))
  102. #define IS_AZALIA(pdev) ((pdev)->vendor == 0x8086 && (pdev)->device == 0x3a3e)
  103. @@ -284,12 +290,14 @@ EXPORT_SYMBOL_GPL(intel_iommu_enabled);
  104. static int dmar_map_gfx = 1;
  105. static int dmar_map_ipts = 1;
  106. +static int dmar_map_ipu = 1;
  107. static int intel_iommu_superpage = 1;
  108. static int iommu_identity_mapping;
  109. static int iommu_skip_te_disable;
  110. #define IDENTMAP_GFX 2
  111. #define IDENTMAP_AZALIA 4
  112. +#define IDENTMAP_IPU 8
  113. #define IDENTMAP_IPTS 16
  114. const struct iommu_ops intel_iommu_ops;
  115. @@ -2608,6 +2616,9 @@ static int device_def_domain_type(struct device *dev)
  116. if ((iommu_identity_mapping & IDENTMAP_GFX) && IS_GFX_DEVICE(pdev))
  117. return IOMMU_DOMAIN_IDENTITY;
  118. + if ((iommu_identity_mapping & IDENTMAP_IPU) && IS_INTEL_IPU(pdev))
  119. + return IOMMU_DOMAIN_IDENTITY;
  120. +
  121. if ((iommu_identity_mapping & IDENTMAP_IPTS) && IS_IPTS(pdev))
  122. return IOMMU_DOMAIN_IDENTITY;
  123. }
  124. @@ -2999,6 +3010,9 @@ static int __init init_dmars(void)
  125. if (!dmar_map_gfx)
  126. iommu_identity_mapping |= IDENTMAP_GFX;
  127. + if (!dmar_map_ipu)
  128. + iommu_identity_mapping |= IDENTMAP_IPU;
  129. +
  130. if (!dmar_map_ipts)
  131. iommu_identity_mapping |= IDENTMAP_IPTS;
  132. @@ -4803,6 +4817,18 @@ static void quirk_iommu_igfx(struct pci_dev *dev)
  133. dmar_map_gfx = 0;
  134. }
  135. +static void quirk_iommu_ipu(struct pci_dev *dev)
  136. +{
  137. + if (!IS_INTEL_IPU(dev))
  138. + return;
  139. +
  140. + if (risky_device(dev))
  141. + return;
  142. +
  143. + pci_info(dev, "Passthrough IOMMU for integrated Intel IPU\n");
  144. + dmar_map_ipu = 0;
  145. +}
  146. +
  147. static void quirk_iommu_ipts(struct pci_dev *dev)
  148. {
  149. if (!IS_IPTS(dev))
  150. @@ -4814,6 +4840,7 @@ static void quirk_iommu_ipts(struct pci_dev *dev)
  151. pci_info(dev, "Passthrough IOMMU for IPTS\n");
  152. dmar_map_ipts = 0;
  153. }
  154. +
  155. /* G4x/GM45 integrated gfx dmar support is totally busted. */
  156. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, 0x2a40, quirk_iommu_igfx);
  157. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, 0x2e00, quirk_iommu_igfx);
  158. @@ -4849,6 +4876,9 @@ DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, 0x1632, quirk_iommu_igfx);
  159. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, 0x163A, quirk_iommu_igfx);
  160. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, 0x163D, quirk_iommu_igfx);
  161. +/* disable IPU dmar support */
  162. +DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_ANY_ID, quirk_iommu_ipu);
  163. +
  164. /* disable IPTS dmar support */
  165. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, 0x9D3E, quirk_iommu_ipts);
  166. --
  167. 2.38.1
  168. From 6fe580b0bb6383a45e0b319007a06aae9ac2ce90 Mon Sep 17 00:00:00 2001
  169. From: Daniel Scally <djrscally@gmail.com>
  170. Date: Sun, 10 Oct 2021 20:57:02 +0200
  171. Subject: [PATCH] platform/x86: int3472: Enable I2c daisy chain
  172. The TPS68470 PMIC has an I2C passthrough mode through which I2C traffic
  173. can be forwarded to a device connected to the PMIC as though it were
  174. connected directly to the system bus. Enable this mode when the chip
  175. is initialised.
  176. Signed-off-by: Daniel Scally <djrscally@gmail.com>
  177. Patchset: cameras
  178. ---
  179. drivers/platform/x86/intel/int3472/tps68470.c | 7 +++++++
  180. 1 file changed, 7 insertions(+)
  181. diff --git a/drivers/platform/x86/intel/int3472/tps68470.c b/drivers/platform/x86/intel/int3472/tps68470.c
  182. index 22f61b47f9e5..e1de1ff40bba 100644
  183. --- a/drivers/platform/x86/intel/int3472/tps68470.c
  184. +++ b/drivers/platform/x86/intel/int3472/tps68470.c
  185. @@ -45,6 +45,13 @@ static int tps68470_chip_init(struct device *dev, struct regmap *regmap)
  186. return ret;
  187. }
  188. + /* Enable I2C daisy chain */
  189. + ret = regmap_write(regmap, TPS68470_REG_S_I2C_CTL, 0x03);
  190. + if (ret) {
  191. + dev_err(dev, "Failed to enable i2c daisy chain\n");
  192. + return ret;
  193. + }
  194. +
  195. dev_info(dev, "TPS68470 REVID: 0x%02x\n", version);
  196. return 0;
  197. --
  198. 2.38.1
  199. From afb496b7714c8e94697c4b5fdecae6573883c6f8 Mon Sep 17 00:00:00 2001
  200. From: Daniel Scally <djrscally@gmail.com>
  201. Date: Thu, 28 Oct 2021 21:55:16 +0100
  202. Subject: [PATCH] media: i2c: Add driver for DW9719 VCM
  203. Add a driver for the DW9719 VCM. The driver creates a v4l2 subdevice
  204. and registers a control to set the desired focus.
  205. Signed-off-by: Daniel Scally <djrscally@gmail.com>
  206. Patchset: cameras
  207. ---
  208. MAINTAINERS | 7 +
  209. drivers/media/i2c/Kconfig | 11 +
  210. drivers/media/i2c/Makefile | 1 +
  211. drivers/media/i2c/dw9719.c | 427 +++++++++++++++++++++++++++++++++++++
  212. 4 files changed, 446 insertions(+)
  213. create mode 100644 drivers/media/i2c/dw9719.c
  214. diff --git a/MAINTAINERS b/MAINTAINERS
  215. index 72b9654f764c..cecb621a6581 100644
  216. --- a/MAINTAINERS
  217. +++ b/MAINTAINERS
  218. @@ -6250,6 +6250,13 @@ T: git git://linuxtv.org/media_tree.git
  219. F: Documentation/devicetree/bindings/media/i2c/dongwoon,dw9714.txt
  220. F: drivers/media/i2c/dw9714.c
  221. +DONGWOON DW9719 LENS VOICE COIL DRIVER
  222. +M: Daniel Scally <djrscally@gmail.com>
  223. +L: linux-media@vger.kernel.org
  224. +S: Maintained
  225. +T: git git://linuxtv.org/media_tree.git
  226. +F: drivers/media/i2c/dw9719.c
  227. +
  228. DONGWOON DW9768 LENS VOICE COIL DRIVER
  229. M: Dongchun Zhu <dongchun.zhu@mediatek.com>
  230. L: linux-media@vger.kernel.org
  231. diff --git a/drivers/media/i2c/Kconfig b/drivers/media/i2c/Kconfig
  232. index 7806d4b81716..98d081efeef7 100644
  233. --- a/drivers/media/i2c/Kconfig
  234. +++ b/drivers/media/i2c/Kconfig
  235. @@ -821,6 +821,17 @@ config VIDEO_DW9714
  236. capability. This is designed for linear control of
  237. voice coil motors, controlled via I2C serial interface.
  238. +config VIDEO_DW9719
  239. + tristate "DW9719 lens voice coil support"
  240. + depends on I2C && VIDEO_V4L2
  241. + select MEDIA_CONTROLLER
  242. + select VIDEO_V4L2_SUBDEV_API
  243. + select V4L2_ASYNC
  244. + help
  245. + This is a driver for the DW9719 camera lens voice coil.
  246. + This is designed for linear control of voice coil motors,
  247. + controlled via I2C serial interface.
  248. +
  249. config VIDEO_DW9768
  250. tristate "DW9768 lens voice coil support"
  251. depends on I2C && VIDEO_DEV
  252. diff --git a/drivers/media/i2c/Makefile b/drivers/media/i2c/Makefile
  253. index 0a2933103dd9..b82a07c76388 100644
  254. --- a/drivers/media/i2c/Makefile
  255. +++ b/drivers/media/i2c/Makefile
  256. @@ -30,6 +30,7 @@ obj-$(CONFIG_VIDEO_CS5345) += cs5345.o
  257. obj-$(CONFIG_VIDEO_CS53L32A) += cs53l32a.o
  258. obj-$(CONFIG_VIDEO_CX25840) += cx25840/
  259. obj-$(CONFIG_VIDEO_DW9714) += dw9714.o
  260. +obj-$(CONFIG_VIDEO_DW9719) += dw9719.o
  261. obj-$(CONFIG_VIDEO_DW9768) += dw9768.o
  262. obj-$(CONFIG_VIDEO_DW9807_VCM) += dw9807-vcm.o
  263. obj-$(CONFIG_VIDEO_ET8EK8) += et8ek8/
  264. diff --git a/drivers/media/i2c/dw9719.c b/drivers/media/i2c/dw9719.c
  265. new file mode 100644
  266. index 000000000000..8451c75b696b
  267. --- /dev/null
  268. +++ b/drivers/media/i2c/dw9719.c
  269. @@ -0,0 +1,427 @@
  270. +// SPDX-License-Identifier: GPL-2.0
  271. +// Copyright (c) 2012 Intel Corporation
  272. +
  273. +/*
  274. + * Based on linux/modules/camera/drivers/media/i2c/imx/dw9719.c in this repo:
  275. + * https://github.com/ZenfoneArea/android_kernel_asus_zenfone5
  276. + */
  277. +
  278. +#include <asm/unaligned.h>
  279. +
  280. +#include <linux/delay.h>
  281. +#include <linux/i2c.h>
  282. +#include <linux/pm_runtime.h>
  283. +#include <linux/regulator/consumer.h>
  284. +#include <linux/types.h>
  285. +
  286. +#include <media/v4l2-common.h>
  287. +#include <media/v4l2-ctrls.h>
  288. +#include <media/v4l2-subdev.h>
  289. +
  290. +#define DW9719_MAX_FOCUS_POS 1023
  291. +#define DW9719_CTRL_STEPS 16
  292. +#define DW9719_CTRL_DELAY_US 1000
  293. +#define DELAY_MAX_PER_STEP_NS (1000000 * 1023)
  294. +
  295. +#define DW9719_INFO 0
  296. +#define DW9719_ID 0xF1
  297. +#define DW9719_CONTROL 2
  298. +#define DW9719_VCM_CURRENT 3
  299. +
  300. +#define DW9719_MODE 6
  301. +#define DW9719_VCM_FREQ 7
  302. +
  303. +#define DW9719_MODE_SAC3 0x40
  304. +#define DW9719_DEFAULT_VCM_FREQ 0x60
  305. +#define DW9719_ENABLE_RINGING 0x02
  306. +
  307. +#define NUM_REGULATORS 2
  308. +
  309. +#define to_dw9719_device(x) container_of(x, struct dw9719_device, sd)
  310. +
  311. +struct dw9719_device {
  312. + struct device *dev;
  313. + struct i2c_client *client;
  314. + struct regulator_bulk_data regulators[NUM_REGULATORS];
  315. + struct v4l2_subdev sd;
  316. +
  317. + struct dw9719_v4l2_ctrls {
  318. + struct v4l2_ctrl_handler handler;
  319. + struct v4l2_ctrl *focus;
  320. + } ctrls;
  321. +};
  322. +
  323. +static int dw9719_i2c_rd8(struct i2c_client *client, u8 reg, u8 *val)
  324. +{
  325. + struct i2c_msg msg[2];
  326. + u8 buf[2] = { reg };
  327. + int ret;
  328. +
  329. + msg[0].addr = client->addr;
  330. + msg[0].flags = 0;
  331. + msg[0].len = 1;
  332. + msg[0].buf = buf;
  333. +
  334. + msg[1].addr = client->addr;
  335. + msg[1].flags = I2C_M_RD;
  336. + msg[1].len = 1;
  337. + msg[1].buf = &buf[1];
  338. + *val = 0;
  339. +
  340. + ret = i2c_transfer(client->adapter, msg, 2);
  341. + if (ret < 0)
  342. + return ret;
  343. +
  344. + *val = buf[1];
  345. +
  346. + return 0;
  347. +}
  348. +
  349. +static int dw9719_i2c_wr8(struct i2c_client *client, u8 reg, u8 val)
  350. +{
  351. + struct i2c_msg msg;
  352. + int ret;
  353. +
  354. + u8 buf[2] = { reg, val };
  355. +
  356. + msg.addr = client->addr;
  357. + msg.flags = 0;
  358. + msg.len = sizeof(buf);
  359. + msg.buf = buf;
  360. +
  361. + ret = i2c_transfer(client->adapter, &msg, 1);
  362. +
  363. + return ret < 0 ? ret : 0;
  364. +}
  365. +
  366. +static int dw9719_i2c_wr16(struct i2c_client *client, u8 reg, u16 val)
  367. +{
  368. + struct i2c_msg msg;
  369. + u8 buf[3] = { reg };
  370. + int ret;
  371. +
  372. + put_unaligned_be16(val, buf + 1);
  373. +
  374. + msg.addr = client->addr;
  375. + msg.flags = 0;
  376. + msg.len = sizeof(buf);
  377. + msg.buf = buf;
  378. +
  379. + ret = i2c_transfer(client->adapter, &msg, 1);
  380. +
  381. + return ret < 0 ? ret : 0;
  382. +}
  383. +
  384. +static int dw9719_detect(struct dw9719_device *dw9719)
  385. +{
  386. + int ret;
  387. + u8 val;
  388. +
  389. + ret = dw9719_i2c_rd8(dw9719->client, DW9719_INFO, &val);
  390. + if (ret < 0)
  391. + return ret;
  392. +
  393. + if (val != DW9719_ID) {
  394. + dev_err(dw9719->dev, "Failed to detect correct id\n");
  395. + ret = -ENXIO;
  396. + }
  397. +
  398. + return 0;
  399. +}
  400. +
  401. +static int dw9719_power_down(struct dw9719_device *dw9719)
  402. +{
  403. + return regulator_bulk_disable(NUM_REGULATORS, dw9719->regulators);
  404. +}
  405. +
  406. +static int dw9719_power_up(struct dw9719_device *dw9719)
  407. +{
  408. + int ret;
  409. +
  410. + ret = regulator_bulk_enable(NUM_REGULATORS, dw9719->regulators);
  411. + if (ret)
  412. + return ret;
  413. +
  414. + /* Jiggle SCL pin to wake up device */
  415. + ret = dw9719_i2c_wr8(dw9719->client, DW9719_CONTROL, 1);
  416. +
  417. + /* Need 100us to transit from SHUTDOWN to STANDBY*/
  418. + usleep_range(100, 1000);
  419. +
  420. + ret = dw9719_i2c_wr8(dw9719->client, DW9719_CONTROL,
  421. + DW9719_ENABLE_RINGING);
  422. + if (ret < 0)
  423. + goto fail_powerdown;
  424. +
  425. + ret = dw9719_i2c_wr8(dw9719->client, DW9719_MODE, DW9719_MODE_SAC3);
  426. + if (ret < 0)
  427. + goto fail_powerdown;
  428. +
  429. + ret = dw9719_i2c_wr8(dw9719->client, DW9719_VCM_FREQ,
  430. + DW9719_DEFAULT_VCM_FREQ);
  431. + if (ret < 0)
  432. + goto fail_powerdown;
  433. +
  434. + return 0;
  435. +
  436. +fail_powerdown:
  437. + dw9719_power_down(dw9719);
  438. + return ret;
  439. +}
  440. +
  441. +static int dw9719_t_focus_abs(struct dw9719_device *dw9719, s32 value)
  442. +{
  443. + int ret;
  444. +
  445. + value = clamp(value, 0, DW9719_MAX_FOCUS_POS);
  446. + ret = dw9719_i2c_wr16(dw9719->client, DW9719_VCM_CURRENT, value);
  447. + if (ret < 0)
  448. + return ret;
  449. +
  450. + return 0;
  451. +}
  452. +
  453. +static int dw9719_set_ctrl(struct v4l2_ctrl *ctrl)
  454. +{
  455. + struct dw9719_device *dw9719 = container_of(ctrl->handler,
  456. + struct dw9719_device,
  457. + ctrls.handler);
  458. + int ret;
  459. +
  460. + /* Only apply changes to the controls if the device is powered up */
  461. + if (!pm_runtime_get_if_in_use(dw9719->dev))
  462. + return 0;
  463. +
  464. + switch (ctrl->id) {
  465. + case V4L2_CID_FOCUS_ABSOLUTE:
  466. + ret = dw9719_t_focus_abs(dw9719, ctrl->val);
  467. + break;
  468. + default:
  469. + ret = -EINVAL;
  470. + }
  471. +
  472. + pm_runtime_put(dw9719->dev);
  473. +
  474. + return ret;
  475. +}
  476. +
  477. +static const struct v4l2_ctrl_ops dw9719_ctrl_ops = {
  478. + .s_ctrl = dw9719_set_ctrl,
  479. +};
  480. +
  481. +static int __maybe_unused dw9719_suspend(struct device *dev)
  482. +{
  483. + struct v4l2_subdev *sd = dev_get_drvdata(dev);
  484. + struct dw9719_device *dw9719 = to_dw9719_device(sd);
  485. + int ret;
  486. + int val;
  487. +
  488. + for (val = dw9719->ctrls.focus->val; val >= 0;
  489. + val -= DW9719_CTRL_STEPS) {
  490. + ret = dw9719_t_focus_abs(dw9719, val);
  491. + if (ret)
  492. + return ret;
  493. +
  494. + usleep_range(DW9719_CTRL_DELAY_US, DW9719_CTRL_DELAY_US + 10);
  495. + }
  496. +
  497. + return dw9719_power_down(dw9719);
  498. +}
  499. +
  500. +static int __maybe_unused dw9719_resume(struct device *dev)
  501. +{
  502. + struct v4l2_subdev *sd = dev_get_drvdata(dev);
  503. + struct dw9719_device *dw9719 = to_dw9719_device(sd);
  504. + int current_focus = dw9719->ctrls.focus->val;
  505. + int ret;
  506. + int val;
  507. +
  508. + ret = dw9719_power_up(dw9719);
  509. + if (ret)
  510. + return ret;
  511. +
  512. + for (val = current_focus % DW9719_CTRL_STEPS; val < current_focus;
  513. + val += DW9719_CTRL_STEPS) {
  514. + ret = dw9719_t_focus_abs(dw9719, val);
  515. + if (ret)
  516. + goto err_power_down;
  517. +
  518. + usleep_range(DW9719_CTRL_DELAY_US, DW9719_CTRL_DELAY_US + 10);
  519. + }
  520. +
  521. + return 0;
  522. +
  523. +err_power_down:
  524. + dw9719_power_down(dw9719);
  525. + return ret;
  526. +}
  527. +
  528. +static int dw9719_open(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh)
  529. +{
  530. + return pm_runtime_resume_and_get(sd->dev);
  531. +}
  532. +
  533. +static int dw9719_close(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh)
  534. +{
  535. + pm_runtime_put(sd->dev);
  536. +
  537. + return 0;
  538. +}
  539. +
  540. +static const struct v4l2_subdev_internal_ops dw9719_internal_ops = {
  541. + .open = dw9719_open,
  542. + .close = dw9719_close,
  543. +};
  544. +
  545. +static int dw9719_init_controls(struct dw9719_device *dw9719)
  546. +{
  547. + const struct v4l2_ctrl_ops *ops = &dw9719_ctrl_ops;
  548. + int ret;
  549. +
  550. + ret = v4l2_ctrl_handler_init(&dw9719->ctrls.handler, 1);
  551. + if (ret)
  552. + return ret;
  553. +
  554. + dw9719->ctrls.focus = v4l2_ctrl_new_std(&dw9719->ctrls.handler, ops,
  555. + V4L2_CID_FOCUS_ABSOLUTE, 0,
  556. + DW9719_MAX_FOCUS_POS, 1, 0);
  557. +
  558. + if (dw9719->ctrls.handler.error) {
  559. + dev_err(dw9719->dev, "Error initialising v4l2 ctrls\n");
  560. + ret = dw9719->ctrls.handler.error;
  561. + goto err_free_handler;
  562. + }
  563. +
  564. + dw9719->sd.ctrl_handler = &dw9719->ctrls.handler;
  565. +
  566. + return ret;
  567. +
  568. +err_free_handler:
  569. + v4l2_ctrl_handler_free(&dw9719->ctrls.handler);
  570. + return ret;
  571. +}
  572. +
  573. +static const struct v4l2_subdev_ops dw9719_ops = { };
  574. +
  575. +static int dw9719_probe(struct i2c_client *client)
  576. +{
  577. + struct dw9719_device *dw9719;
  578. + int ret;
  579. +
  580. + dw9719 = devm_kzalloc(&client->dev, sizeof(*dw9719), GFP_KERNEL);
  581. + if (!dw9719)
  582. + return -ENOMEM;
  583. +
  584. + dw9719->client = client;
  585. + dw9719->dev = &client->dev;
  586. +
  587. + dw9719->regulators[0].supply = "vdd";
  588. + /*
  589. + * The DW9719 has only the 1 VDD voltage input, but some PMICs such as
  590. + * the TPS68470 PMIC have I2C passthrough capability, to disconnect the
  591. + * sensor's I2C pins from the I2C bus when the sensors VSIO (Sensor-IO)
  592. + * is off, because some sensors then short these pins to ground;
  593. + * and the DW9719 might sit behind this passthrough, this it needs to
  594. + * enable VSIO as that will also enable the I2C passthrough.
  595. + */
  596. + dw9719->regulators[1].supply = "vsio";
  597. +
  598. + ret = devm_regulator_bulk_get(&client->dev, NUM_REGULATORS,
  599. + dw9719->regulators);
  600. + if (ret)
  601. + return dev_err_probe(&client->dev, ret, "getting regulators\n");
  602. +
  603. + v4l2_i2c_subdev_init(&dw9719->sd, client, &dw9719_ops);
  604. + dw9719->sd.flags |= V4L2_SUBDEV_FL_HAS_DEVNODE;
  605. + dw9719->sd.internal_ops = &dw9719_internal_ops;
  606. +
  607. + ret = dw9719_init_controls(dw9719);
  608. + if (ret)
  609. + return ret;
  610. +
  611. + ret = media_entity_pads_init(&dw9719->sd.entity, 0, NULL);
  612. + if (ret < 0)
  613. + goto err_free_ctrl_handler;
  614. +
  615. + dw9719->sd.entity.function = MEDIA_ENT_F_LENS;
  616. +
  617. + /*
  618. + * We need the driver to work in the event that pm runtime is disable in
  619. + * the kernel, so power up and verify the chip now. In the event that
  620. + * runtime pm is disabled this will leave the chip on, so that the lens
  621. + * will work.
  622. + */
  623. +
  624. + ret = dw9719_power_up(dw9719);
  625. + if (ret)
  626. + goto err_cleanup_media;
  627. +
  628. + ret = dw9719_detect(dw9719);
  629. + if (ret)
  630. + goto err_powerdown;
  631. +
  632. + pm_runtime_set_active(&client->dev);
  633. + pm_runtime_get_noresume(&client->dev);
  634. + pm_runtime_enable(&client->dev);
  635. +
  636. + ret = v4l2_async_register_subdev(&dw9719->sd);
  637. + if (ret < 0)
  638. + goto err_pm_runtime;
  639. +
  640. + pm_runtime_set_autosuspend_delay(&client->dev, 1000);
  641. + pm_runtime_use_autosuspend(&client->dev);
  642. + pm_runtime_put_autosuspend(&client->dev);
  643. +
  644. + return ret;
  645. +
  646. +err_pm_runtime:
  647. + pm_runtime_disable(&client->dev);
  648. + pm_runtime_put_noidle(&client->dev);
  649. +err_powerdown:
  650. + dw9719_power_down(dw9719);
  651. +err_cleanup_media:
  652. + media_entity_cleanup(&dw9719->sd.entity);
  653. +err_free_ctrl_handler:
  654. + v4l2_ctrl_handler_free(&dw9719->ctrls.handler);
  655. +
  656. + return ret;
  657. +}
  658. +
  659. +static int dw9719_remove(struct i2c_client *client)
  660. +{
  661. + struct v4l2_subdev *sd = i2c_get_clientdata(client);
  662. + struct dw9719_device *dw9719 = container_of(sd, struct dw9719_device,
  663. + sd);
  664. +
  665. + pm_runtime_disable(&client->dev);
  666. + v4l2_async_unregister_subdev(sd);
  667. + v4l2_ctrl_handler_free(&dw9719->ctrls.handler);
  668. + media_entity_cleanup(&dw9719->sd.entity);
  669. +
  670. + return 0;
  671. +}
  672. +
  673. +static const struct i2c_device_id dw9719_id_table[] = {
  674. + { "dw9719" },
  675. + { }
  676. +};
  677. +MODULE_DEVICE_TABLE(i2c, dw9719_id_table);
  678. +
  679. +static const struct dev_pm_ops dw9719_pm_ops = {
  680. + SET_RUNTIME_PM_OPS(dw9719_suspend, dw9719_resume, NULL)
  681. +};
  682. +
  683. +static struct i2c_driver dw9719_i2c_driver = {
  684. + .driver = {
  685. + .name = "dw9719",
  686. + .pm = &dw9719_pm_ops,
  687. + },
  688. + .probe_new = dw9719_probe,
  689. + .remove = dw9719_remove,
  690. + .id_table = dw9719_id_table,
  691. +};
  692. +module_i2c_driver(dw9719_i2c_driver);
  693. +
  694. +MODULE_AUTHOR("Daniel Scally <djrscally@gmail.com>");
  695. +MODULE_DESCRIPTION("DW9719 VCM Driver");
  696. +MODULE_LICENSE("GPL");
  697. --
  698. 2.38.1
  699. From 83877415f586ae1d54c3958e1c6307ee9984b5cf Mon Sep 17 00:00:00 2001
  700. From: Daniel Scally <djrscally@gmail.com>
  701. Date: Wed, 4 May 2022 23:21:45 +0100
  702. Subject: [PATCH] media: ipu3-cio2: Move functionality from .complete() to
  703. .bound()
  704. Creating links and registering subdev nodes during the .complete()
  705. callback has the unfortunate effect of preventing all cameras that
  706. connect to a notifier from working if any one of their drivers fails
  707. to probe. Moving the functionality from .complete() to .bound() allows
  708. those camera sensor drivers that did probe correctly to work regardless.
  709. Signed-off-by: Daniel Scally <djrscally@gmail.com>
  710. Patchset: cameras
  711. ---
  712. drivers/media/pci/intel/ipu3/ipu3-cio2-main.c | 65 +++++++------------
  713. 1 file changed, 23 insertions(+), 42 deletions(-)
  714. diff --git a/drivers/media/pci/intel/ipu3/ipu3-cio2-main.c b/drivers/media/pci/intel/ipu3/ipu3-cio2-main.c
  715. index a3fe547b7fce..5648f29ced7b 100644
  716. --- a/drivers/media/pci/intel/ipu3/ipu3-cio2-main.c
  717. +++ b/drivers/media/pci/intel/ipu3/ipu3-cio2-main.c
  718. @@ -1383,7 +1383,10 @@ static int cio2_notifier_bound(struct v4l2_async_notifier *notifier,
  719. {
  720. struct cio2_device *cio2 = to_cio2_device(notifier);
  721. struct sensor_async_subdev *s_asd = to_sensor_asd(asd);
  722. + struct device *dev = &cio2->pci_dev->dev;
  723. struct cio2_queue *q;
  724. + unsigned int pad;
  725. + int ret;
  726. if (cio2->queue[s_asd->csi2.port].sensor)
  727. return -EBUSY;
  728. @@ -1394,7 +1397,26 @@ static int cio2_notifier_bound(struct v4l2_async_notifier *notifier,
  729. q->sensor = sd;
  730. q->csi_rx_base = cio2->base + CIO2_REG_PIPE_BASE(q->csi2.port);
  731. - return 0;
  732. + for (pad = 0; pad < q->sensor->entity.num_pads; pad++)
  733. + if (q->sensor->entity.pads[pad].flags &
  734. + MEDIA_PAD_FL_SOURCE)
  735. + break;
  736. +
  737. + if (pad == q->sensor->entity.num_pads) {
  738. + dev_err(dev, "failed to find src pad for %s\n",
  739. + q->sensor->name);
  740. + return -ENXIO;
  741. + }
  742. +
  743. + ret = media_create_pad_link(&q->sensor->entity, pad, &q->subdev.entity,
  744. + CIO2_PAD_SINK, 0);
  745. + if (ret) {
  746. + dev_err(dev, "failed to create link for %s\n",
  747. + q->sensor->name);
  748. + return ret;
  749. + }
  750. +
  751. + return v4l2_device_register_subdev_nodes(&cio2->v4l2_dev);
  752. }
  753. /* The .unbind callback */
  754. @@ -1408,50 +1430,9 @@ static void cio2_notifier_unbind(struct v4l2_async_notifier *notifier,
  755. cio2->queue[s_asd->csi2.port].sensor = NULL;
  756. }
  757. -/* .complete() is called after all subdevices have been located */
  758. -static int cio2_notifier_complete(struct v4l2_async_notifier *notifier)
  759. -{
  760. - struct cio2_device *cio2 = to_cio2_device(notifier);
  761. - struct device *dev = &cio2->pci_dev->dev;
  762. - struct sensor_async_subdev *s_asd;
  763. - struct v4l2_async_subdev *asd;
  764. - struct cio2_queue *q;
  765. - unsigned int pad;
  766. - int ret;
  767. -
  768. - list_for_each_entry(asd, &cio2->notifier.asd_list, asd_list) {
  769. - s_asd = to_sensor_asd(asd);
  770. - q = &cio2->queue[s_asd->csi2.port];
  771. -
  772. - for (pad = 0; pad < q->sensor->entity.num_pads; pad++)
  773. - if (q->sensor->entity.pads[pad].flags &
  774. - MEDIA_PAD_FL_SOURCE)
  775. - break;
  776. -
  777. - if (pad == q->sensor->entity.num_pads) {
  778. - dev_err(dev, "failed to find src pad for %s\n",
  779. - q->sensor->name);
  780. - return -ENXIO;
  781. - }
  782. -
  783. - ret = media_create_pad_link(
  784. - &q->sensor->entity, pad,
  785. - &q->subdev.entity, CIO2_PAD_SINK,
  786. - 0);
  787. - if (ret) {
  788. - dev_err(dev, "failed to create link for %s\n",
  789. - q->sensor->name);
  790. - return ret;
  791. - }
  792. - }
  793. -
  794. - return v4l2_device_register_subdev_nodes(&cio2->v4l2_dev);
  795. -}
  796. -
  797. static const struct v4l2_async_notifier_operations cio2_async_ops = {
  798. .bound = cio2_notifier_bound,
  799. .unbind = cio2_notifier_unbind,
  800. - .complete = cio2_notifier_complete,
  801. };
  802. static int cio2_parse_firmware(struct cio2_device *cio2)
  803. --
  804. 2.38.1
  805. From 6148516d49304e7fc633695762fd4ba12b4057a4 Mon Sep 17 00:00:00 2001
  806. From: Daniel Scally <djrscally@gmail.com>
  807. Date: Thu, 2 Jun 2022 22:15:56 +0100
  808. Subject: [PATCH] media: ipu3-cio2: Re-add .complete() to ipu3-cio2
  809. Removing the .complete() callback had some unintended consequences.
  810. Because the VCM driver is not directly linked to the ipu3-cio2
  811. driver .bound() never gets called for it, which means its devnode
  812. is never created if it probes late. Because .complete() waits for
  813. any sub-notifiers to also be complete it is captured in that call.
  814. Signed-off-by: Daniel Scally <djrscally@gmail.com>
  815. Patchset: cameras
  816. ---
  817. drivers/media/pci/intel/ipu3/ipu3-cio2-main.c | 9 +++++++++
  818. 1 file changed, 9 insertions(+)
  819. diff --git a/drivers/media/pci/intel/ipu3/ipu3-cio2-main.c b/drivers/media/pci/intel/ipu3/ipu3-cio2-main.c
  820. index 5648f29ced7b..957a30cd369d 100644
  821. --- a/drivers/media/pci/intel/ipu3/ipu3-cio2-main.c
  822. +++ b/drivers/media/pci/intel/ipu3/ipu3-cio2-main.c
  823. @@ -1430,9 +1430,18 @@ static void cio2_notifier_unbind(struct v4l2_async_notifier *notifier,
  824. cio2->queue[s_asd->csi2.port].sensor = NULL;
  825. }
  826. +/* .complete() is called after all subdevices have been located */
  827. +static int cio2_notifier_complete(struct v4l2_async_notifier *notifier)
  828. +{
  829. + struct cio2_device *cio2 = to_cio2_device(notifier);
  830. +
  831. + return v4l2_device_register_subdev_nodes(&cio2->v4l2_dev);
  832. +}
  833. +
  834. static const struct v4l2_async_notifier_operations cio2_async_ops = {
  835. .bound = cio2_notifier_bound,
  836. .unbind = cio2_notifier_unbind,
  837. + .complete = cio2_notifier_complete,
  838. };
  839. static int cio2_parse_firmware(struct cio2_device *cio2)
  840. --
  841. 2.38.1
  842. From 812f17227ae50a74cd75c43a9f6fa58dfa8ccac6 Mon Sep 17 00:00:00 2001
  843. From: Maximilian Luz <luzmaximilian@gmail.com>
  844. Date: Fri, 15 Jul 2022 23:48:00 +0200
  845. Subject: [PATCH] drivers/media/i2c: Fix DW9719 dependencies
  846. It should depend on VIDEO_DEV instead of VIDEO_V4L2.
  847. Signed-off-by: Maximilian Luz <luzmaximilian@gmail.com>
  848. Patchset: cameras
  849. ---
  850. drivers/media/i2c/Kconfig | 2 +-
  851. 1 file changed, 1 insertion(+), 1 deletion(-)
  852. diff --git a/drivers/media/i2c/Kconfig b/drivers/media/i2c/Kconfig
  853. index 98d081efeef7..c67966cafe10 100644
  854. --- a/drivers/media/i2c/Kconfig
  855. +++ b/drivers/media/i2c/Kconfig
  856. @@ -823,7 +823,7 @@ config VIDEO_DW9714
  857. config VIDEO_DW9719
  858. tristate "DW9719 lens voice coil support"
  859. - depends on I2C && VIDEO_V4L2
  860. + depends on I2C && VIDEO_DEV
  861. select MEDIA_CONTROLLER
  862. select VIDEO_V4L2_SUBDEV_API
  863. select V4L2_ASYNC
  864. --
  865. 2.38.1
  866. From 79d2968e29d7c65b44cb341d4f8a20cd4e1b277d Mon Sep 17 00:00:00 2001
  867. From: Maximilian Luz <luzmaximilian@gmail.com>
  868. Date: Wed, 7 Sep 2022 15:38:08 +0200
  869. Subject: [PATCH] ipu3-imgu: Fix NULL pointer dereference in
  870. imgu_subdev_set_selection()
  871. Calling v4l2_subdev_get_try_crop() and v4l2_subdev_get_try_compose()
  872. with a subdev state of NULL leads to a NULL pointer dereference. This
  873. can currently happen in imgu_subdev_set_selection() when the state
  874. passed in is NULL, as this method first gets pointers to both the "try"
  875. and "active" states and only then decides which to use.
  876. The same issue has been addressed for imgu_subdev_get_selection() with
  877. commit 30d03a0de650 ("ipu3-imgu: Fix NULL pointer dereference in active
  878. selection access"). However the issue still persists in
  879. imgu_subdev_set_selection().
  880. Therefore, apply a similar fix as done in the aforementioned commit to
  881. imgu_subdev_set_selection(). To keep things a bit cleaner, introduce
  882. helper functions for "crop" and "compose" access and use them in both
  883. imgu_subdev_set_selection() and imgu_subdev_get_selection().
  884. Fixes: 0d346d2a6f54 ("media: v4l2-subdev: add subdev-wide state struct")
  885. Cc: stable@vger.kernel.org # for v5.14 and later
  886. Signed-off-by: Maximilian Luz <luzmaximilian@gmail.com>
  887. Patchset: cameras
  888. ---
  889. drivers/staging/media/ipu3/ipu3-v4l2.c | 57 +++++++++++++++-----------
  890. 1 file changed, 34 insertions(+), 23 deletions(-)
  891. diff --git a/drivers/staging/media/ipu3/ipu3-v4l2.c b/drivers/staging/media/ipu3/ipu3-v4l2.c
  892. index 2234bb8d48b3..490ba0eb249b 100644
  893. --- a/drivers/staging/media/ipu3/ipu3-v4l2.c
  894. +++ b/drivers/staging/media/ipu3/ipu3-v4l2.c
  895. @@ -188,6 +188,28 @@ static int imgu_subdev_set_fmt(struct v4l2_subdev *sd,
  896. return 0;
  897. }
  898. +static struct v4l2_rect *
  899. +imgu_subdev_get_crop(struct imgu_v4l2_subdev *sd,
  900. + struct v4l2_subdev_state *sd_state, unsigned int pad,
  901. + enum v4l2_subdev_format_whence which)
  902. +{
  903. + if (which == V4L2_SUBDEV_FORMAT_TRY)
  904. + return v4l2_subdev_get_try_crop(&sd->subdev, sd_state, pad);
  905. + else
  906. + return &sd->rect.eff;
  907. +}
  908. +
  909. +static struct v4l2_rect *
  910. +imgu_subdev_get_compose(struct imgu_v4l2_subdev *sd,
  911. + struct v4l2_subdev_state *sd_state, unsigned int pad,
  912. + enum v4l2_subdev_format_whence which)
  913. +{
  914. + if (which == V4L2_SUBDEV_FORMAT_TRY)
  915. + return v4l2_subdev_get_try_compose(&sd->subdev, sd_state, pad);
  916. + else
  917. + return &sd->rect.bds;
  918. +}
  919. +
  920. static int imgu_subdev_get_selection(struct v4l2_subdev *sd,
  921. struct v4l2_subdev_state *sd_state,
  922. struct v4l2_subdev_selection *sel)
  923. @@ -200,18 +222,12 @@ static int imgu_subdev_get_selection(struct v4l2_subdev *sd,
  924. switch (sel->target) {
  925. case V4L2_SEL_TGT_CROP:
  926. - if (sel->which == V4L2_SUBDEV_FORMAT_TRY)
  927. - sel->r = *v4l2_subdev_get_try_crop(sd, sd_state,
  928. - sel->pad);
  929. - else
  930. - sel->r = imgu_sd->rect.eff;
  931. + sel->r = *imgu_subdev_get_crop(imgu_sd, sd_state, sel->pad,
  932. + sel->which);
  933. return 0;
  934. case V4L2_SEL_TGT_COMPOSE:
  935. - if (sel->which == V4L2_SUBDEV_FORMAT_TRY)
  936. - sel->r = *v4l2_subdev_get_try_compose(sd, sd_state,
  937. - sel->pad);
  938. - else
  939. - sel->r = imgu_sd->rect.bds;
  940. + sel->r = *imgu_subdev_get_compose(imgu_sd, sd_state, sel->pad,
  941. + sel->which);
  942. return 0;
  943. default:
  944. return -EINVAL;
  945. @@ -223,10 +239,9 @@ static int imgu_subdev_set_selection(struct v4l2_subdev *sd,
  946. struct v4l2_subdev_selection *sel)
  947. {
  948. struct imgu_device *imgu = v4l2_get_subdevdata(sd);
  949. - struct imgu_v4l2_subdev *imgu_sd = container_of(sd,
  950. - struct imgu_v4l2_subdev,
  951. - subdev);
  952. - struct v4l2_rect *rect, *try_sel;
  953. + struct imgu_v4l2_subdev *imgu_sd =
  954. + container_of(sd, struct imgu_v4l2_subdev, subdev);
  955. + struct v4l2_rect *rect;
  956. dev_dbg(&imgu->pci_dev->dev,
  957. "set subdev %u sel which %u target 0x%4x rect [%ux%u]",
  958. @@ -238,22 +253,18 @@ static int imgu_subdev_set_selection(struct v4l2_subdev *sd,
  959. switch (sel->target) {
  960. case V4L2_SEL_TGT_CROP:
  961. - try_sel = v4l2_subdev_get_try_crop(sd, sd_state, sel->pad);
  962. - rect = &imgu_sd->rect.eff;
  963. + rect = imgu_subdev_get_crop(imgu_sd, sd_state, sel->pad,
  964. + sel->which);
  965. break;
  966. case V4L2_SEL_TGT_COMPOSE:
  967. - try_sel = v4l2_subdev_get_try_compose(sd, sd_state, sel->pad);
  968. - rect = &imgu_sd->rect.bds;
  969. + rect = imgu_subdev_get_compose(imgu_sd, sd_state, sel->pad,
  970. + sel->which);
  971. break;
  972. default:
  973. return -EINVAL;
  974. }
  975. - if (sel->which == V4L2_SUBDEV_FORMAT_TRY)
  976. - *try_sel = sel->r;
  977. - else
  978. - *rect = sel->r;
  979. -
  980. + *rect = sel->r;
  981. return 0;
  982. }
  983. --
  984. 2.38.1