0010-cameras.patch 38 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218
  1. From 6d050a12fd922f54962a9a049e2351630dcdaca1 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 c82b1bfa1c3d..2227625202aa 100644
  51. --- a/drivers/acpi/scan.c
  52. +++ b/drivers/acpi/scan.c
  53. @@ -2130,6 +2130,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.36.1
  64. From 9a7cd1c24bd5a09c61c4bc2ed790d4f0dc0932fa 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 0bb308eaae4e..44411b057607 100644
  88. --- a/drivers/iommu/intel/iommu.c
  89. +++ b/drivers/iommu/intel/iommu.c
  90. @@ -57,6 +57,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. @@ -335,12 +341,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. int intel_iommu_gfx_mapped;
  115. @@ -2992,6 +3000,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. @@ -3430,6 +3441,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. @@ -5674,6 +5688,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. @@ -5685,6 +5711,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. @@ -5720,6 +5747,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.36.1
  168. From 00b5fffd14cdb2e2174756cd63fb534c1649ca51 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.36.1
  199. From 14be9ae22b20fc3df91b8f70015c09908cf4f820 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 4d83cd26e299..0e0e1e53e49c 100644
  216. --- a/MAINTAINERS
  217. +++ b/MAINTAINERS
  218. @@ -5865,6 +5865,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 69c56e24a612..d9fac304f451 100644
  233. --- a/drivers/media/i2c/Kconfig
  234. +++ b/drivers/media/i2c/Kconfig
  235. @@ -1466,6 +1466,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_V4L2
  252. diff --git a/drivers/media/i2c/Makefile b/drivers/media/i2c/Makefile
  253. index b01f6cd05ee8..ba8b31d79222 100644
  254. --- a/drivers/media/i2c/Makefile
  255. +++ b/drivers/media/i2c/Makefile
  256. @@ -24,6 +24,7 @@ obj-$(CONFIG_VIDEO_SAA6752HS) += saa6752hs.o
  257. obj-$(CONFIG_VIDEO_AD5820) += ad5820.o
  258. obj-$(CONFIG_VIDEO_AK7375) += ak7375.o
  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_ADV7170) += adv7170.o
  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.36.1
  699. From 6b10e5301810c1c63ce84430d8ea9f0be7e1ad39 Mon Sep 17 00:00:00 2001
  700. From: Daniel Scally <djrscally@gmail.com>
  701. Date: Mon, 13 Dec 2021 22:38:17 +0000
  702. Subject: [PATCH] media: entity: Skip non-data links in graph iteration
  703. When iterating over the media graph, don't follow links that are not
  704. data links.
  705. Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
  706. Signed-off-by: Daniel Scally <djrscally@gmail.com>
  707. Patchset: cameras
  708. ---
  709. drivers/media/mc/mc-entity.c | 6 ++++++
  710. 1 file changed, 6 insertions(+)
  711. diff --git a/drivers/media/mc/mc-entity.c b/drivers/media/mc/mc-entity.c
  712. index b411f9796191..d0563ee4b28b 100644
  713. --- a/drivers/media/mc/mc-entity.c
  714. +++ b/drivers/media/mc/mc-entity.c
  715. @@ -295,6 +295,12 @@ static void media_graph_walk_iter(struct media_graph *graph)
  716. link = list_entry(link_top(graph), typeof(*link), list);
  717. + /* If the link is not a data link, don't follow it */
  718. + if ((link->flags & MEDIA_LNK_FL_LINK_TYPE) != MEDIA_LNK_FL_DATA_LINK) {
  719. + link_top(graph) = link_top(graph)->next;
  720. + return;
  721. + }
  722. +
  723. /* The link is not enabled so we do not follow. */
  724. if (!(link->flags & MEDIA_LNK_FL_ENABLED)) {
  725. link_top(graph) = link_top(graph)->next;
  726. --
  727. 2.36.1
  728. From 6c7eadb12e4795830fae1b4d929adbe2aec7be9b Mon Sep 17 00:00:00 2001
  729. From: Daniel Scally <djrscally@gmail.com>
  730. Date: Mon, 13 Dec 2021 22:53:09 +0000
  731. Subject: [PATCH] media: media.h: Add new media link type
  732. To describe in the kernel the connection between devices and their
  733. supporting peripherals (for example, a camera sensor and the vcm
  734. driving the focusing lens for it), add a new type of media link
  735. to introduce the concept of these ancillary links.
  736. Add some elements to the uAPI documentation to explain the new link
  737. type, their purpose and some aspects of their current implementation.
  738. Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
  739. Signed-off-by: Daniel Scally <djrscally@gmail.com>
  740. Patchset: cameras
  741. ---
  742. .../media/mediactl/media-controller-model.rst | 6 ++++++
  743. .../media/mediactl/media-types.rst | 17 ++++++++++++-----
  744. include/uapi/linux/media.h | 1 +
  745. 3 files changed, 19 insertions(+), 5 deletions(-)
  746. diff --git a/Documentation/userspace-api/media/mediactl/media-controller-model.rst b/Documentation/userspace-api/media/mediactl/media-controller-model.rst
  747. index 222cb99debb5..78bfdfb2a322 100644
  748. --- a/Documentation/userspace-api/media/mediactl/media-controller-model.rst
  749. +++ b/Documentation/userspace-api/media/mediactl/media-controller-model.rst
  750. @@ -33,3 +33,9 @@ are:
  751. - An **interface link** is a point-to-point bidirectional control
  752. connection between a Linux Kernel interface and an entity.
  753. +
  754. +- An **ancillary link** is a point-to-point connection denoting that two
  755. + entities form a single logical unit. For example this could represent the
  756. + fact that a particular camera sensor and lens controller form a single
  757. + physical module, meaning this lens controller drives the lens for this
  758. + camera sensor.
  759. \ No newline at end of file
  760. diff --git a/Documentation/userspace-api/media/mediactl/media-types.rst b/Documentation/userspace-api/media/mediactl/media-types.rst
  761. index 0a26397bd01d..60747251d409 100644
  762. --- a/Documentation/userspace-api/media/mediactl/media-types.rst
  763. +++ b/Documentation/userspace-api/media/mediactl/media-types.rst
  764. @@ -412,14 +412,21 @@ must be set for every pad.
  765. is set by drivers and is read-only for applications.
  766. * - ``MEDIA_LNK_FL_LINK_TYPE``
  767. - - This is a bitmask that defines the type of the link. Currently,
  768. - two types of links are supported:
  769. + - This is a bitmask that defines the type of the link. The following
  770. + link types are currently supported:
  771. .. _MEDIA-LNK-FL-DATA-LINK:
  772. - ``MEDIA_LNK_FL_DATA_LINK`` if the link is between two pads
  773. + ``MEDIA_LNK_FL_DATA_LINK`` for links that represent a data connection
  774. + between two pads.
  775. .. _MEDIA-LNK-FL-INTERFACE-LINK:
  776. - ``MEDIA_LNK_FL_INTERFACE_LINK`` if the link is between an
  777. - interface and an entity
  778. + ``MEDIA_LNK_FL_INTERFACE_LINK`` for links that associate an entity to its
  779. + interface.
  780. +
  781. + .. _MEDIA-LNK-FL-ANCILLARY-LINK:
  782. +
  783. + ``MEDIA_LNK_FL_ANCILLARY_LINK`` for links that represent a physical
  784. + relationship between two entities. The link may or may not be ummutable, so
  785. + applications must not assume either case.
  786. \ No newline at end of file
  787. diff --git a/include/uapi/linux/media.h b/include/uapi/linux/media.h
  788. index 200fa8462b90..afbae7213d35 100644
  789. --- a/include/uapi/linux/media.h
  790. +++ b/include/uapi/linux/media.h
  791. @@ -226,6 +226,7 @@ struct media_pad_desc {
  792. #define MEDIA_LNK_FL_LINK_TYPE (0xf << 28)
  793. # define MEDIA_LNK_FL_DATA_LINK (0 << 28)
  794. # define MEDIA_LNK_FL_INTERFACE_LINK (1 << 28)
  795. +# define MEDIA_LNK_FL_ANCILLARY_LINK (2 << 28)
  796. struct media_link_desc {
  797. struct media_pad_desc source;
  798. --
  799. 2.36.1
  800. From 5aa28f39276b39d989ab6329eabd3388818b1951 Mon Sep 17 00:00:00 2001
  801. From: Daniel Scally <djrscally@gmail.com>
  802. Date: Mon, 13 Dec 2021 22:36:31 +0000
  803. Subject: [PATCH] media: entity: Add link_type_name() helper
  804. Now we have three types of media link, printing the right name during
  805. debug output is slightly more complicated. Add a helper function to
  806. make it easier.
  807. Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
  808. Signed-off-by: Daniel Scally <djrscally@gmail.com>
  809. Patchset: cameras
  810. ---
  811. drivers/media/mc/mc-entity.c | 18 +++++++++++++++---
  812. 1 file changed, 15 insertions(+), 3 deletions(-)
  813. diff --git a/drivers/media/mc/mc-entity.c b/drivers/media/mc/mc-entity.c
  814. index d0563ee4b28b..1a7d0a4fb9e8 100644
  815. --- a/drivers/media/mc/mc-entity.c
  816. +++ b/drivers/media/mc/mc-entity.c
  817. @@ -44,6 +44,20 @@ static inline const char *intf_type(struct media_interface *intf)
  818. }
  819. };
  820. +static inline const char *link_type_name(struct media_link *link)
  821. +{
  822. + switch (link->flags & MEDIA_LNK_FL_LINK_TYPE) {
  823. + case MEDIA_LNK_FL_DATA_LINK:
  824. + return "data";
  825. + case MEDIA_LNK_FL_INTERFACE_LINK:
  826. + return "interface";
  827. + case MEDIA_LNK_FL_ANCILLARY_LINK:
  828. + return "ancillary";
  829. + default:
  830. + return "unknown";
  831. + }
  832. +}
  833. +
  834. __must_check int __media_entity_enum_init(struct media_entity_enum *ent_enum,
  835. int idx_max)
  836. {
  837. @@ -89,9 +103,7 @@ static void dev_dbg_obj(const char *event_name, struct media_gobj *gobj)
  838. dev_dbg(gobj->mdev->dev,
  839. "%s id %u: %s link id %u ==> id %u\n",
  840. - event_name, media_id(gobj),
  841. - media_type(link->gobj0) == MEDIA_GRAPH_PAD ?
  842. - "data" : "interface",
  843. + event_name, media_id(gobj), link_type_name(link),
  844. media_id(link->gobj0),
  845. media_id(link->gobj1));
  846. break;
  847. --
  848. 2.36.1
  849. From 08908b9fe6ed00d0cb224cf3b30d08c749e141e5 Mon Sep 17 00:00:00 2001
  850. From: Daniel Scally <djrscally@gmail.com>
  851. Date: Mon, 13 Dec 2021 22:54:10 +0000
  852. Subject: [PATCH] media: entity: Add support for ancillary links
  853. Add functions to create ancillary links, so that they don't need to
  854. be manually created by users.
  855. Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
  856. Signed-off-by: Daniel Scally <djrscally@gmail.com>
  857. Patchset: cameras
  858. ---
  859. drivers/media/mc/mc-entity.c | 22 ++++++++++++++++++++++
  860. include/media/media-entity.h | 19 +++++++++++++++++++
  861. 2 files changed, 41 insertions(+)
  862. diff --git a/drivers/media/mc/mc-entity.c b/drivers/media/mc/mc-entity.c
  863. index 1a7d0a4fb9e8..d7e2f78a83cc 100644
  864. --- a/drivers/media/mc/mc-entity.c
  865. +++ b/drivers/media/mc/mc-entity.c
  866. @@ -1032,3 +1032,25 @@ void media_remove_intf_links(struct media_interface *intf)
  867. mutex_unlock(&mdev->graph_mutex);
  868. }
  869. EXPORT_SYMBOL_GPL(media_remove_intf_links);
  870. +
  871. +struct media_link *media_create_ancillary_link(struct media_entity *primary,
  872. + struct media_entity *ancillary)
  873. +{
  874. + struct media_link *link;
  875. +
  876. + link = media_add_link(&primary->links);
  877. + if (!link)
  878. + return ERR_PTR(-ENOMEM);
  879. +
  880. + link->gobj0 = &primary->graph_obj;
  881. + link->gobj1 = &ancillary->graph_obj;
  882. + link->flags = MEDIA_LNK_FL_IMMUTABLE | MEDIA_LNK_FL_ENABLED |
  883. + MEDIA_LNK_FL_ANCILLARY_LINK;
  884. +
  885. + /* Initialize graph object embedded in the new link */
  886. + media_gobj_create(primary->graph_obj.mdev, MEDIA_GRAPH_LINK,
  887. + &link->graph_obj);
  888. +
  889. + return link;
  890. +}
  891. +EXPORT_SYMBOL_GPL(media_create_ancillary_link);
  892. diff --git a/include/media/media-entity.h b/include/media/media-entity.h
  893. index fea489f03d57..2a58defc4886 100644
  894. --- a/include/media/media-entity.h
  895. +++ b/include/media/media-entity.h
  896. @@ -1108,4 +1108,23 @@ void media_remove_intf_links(struct media_interface *intf);
  897. (((entity)->ops && (entity)->ops->operation) ? \
  898. (entity)->ops->operation((entity) , ##args) : -ENOIOCTLCMD)
  899. +/**
  900. + * media_create_ancillary_link() - create an ancillary link between two
  901. + * instances of &media_entity
  902. + *
  903. + * @primary: pointer to the primary &media_entity
  904. + * @ancillary: pointer to the ancillary &media_entity
  905. + *
  906. + * Create an ancillary link between two entities, indicating that they
  907. + * represent two connected pieces of hardware that form a single logical unit.
  908. + * A typical example is a camera lens controller being linked to the sensor that
  909. + * it is supporting.
  910. + *
  911. + * The function sets both MEDIA_LNK_FL_ENABLED and MEDIA_LNK_FL_IMMUTABLE for
  912. + * the new link.
  913. + */
  914. +struct media_link *
  915. +media_create_ancillary_link(struct media_entity *primary,
  916. + struct media_entity *ancillary);
  917. +
  918. #endif
  919. --
  920. 2.36.1
  921. From e840422acb56ca345058c0a8cbf87b33252135ec Mon Sep 17 00:00:00 2001
  922. From: Daniel Scally <djrscally@gmail.com>
  923. Date: Fri, 26 Nov 2021 22:55:50 +0000
  924. Subject: [PATCH] media: v4l2-async: Create links during
  925. v4l2_async_match_notify()
  926. Upon an async fwnode match, there's some typical behaviour that the
  927. notifier and matching subdev will want to do. For example, a notifier
  928. representing a sensor matching to an async subdev representing its
  929. VCM will want to create an ancillary link to expose that relationship
  930. to userspace.
  931. To avoid lots of code in individual drivers, try to build these links
  932. within v4l2 core.
  933. Signed-off-by: Daniel Scally <djrscally@gmail.com>
  934. Patchset: cameras
  935. ---
  936. drivers/media/v4l2-core/v4l2-async.c | 31 ++++++++++++++++++++++++++++
  937. 1 file changed, 31 insertions(+)
  938. diff --git a/drivers/media/v4l2-core/v4l2-async.c b/drivers/media/v4l2-core/v4l2-async.c
  939. index 0404267f1ae4..436bd6900fd8 100644
  940. --- a/drivers/media/v4l2-core/v4l2-async.c
  941. +++ b/drivers/media/v4l2-core/v4l2-async.c
  942. @@ -275,6 +275,24 @@ v4l2_async_nf_try_complete(struct v4l2_async_notifier *notifier)
  943. static int
  944. v4l2_async_nf_try_all_subdevs(struct v4l2_async_notifier *notifier);
  945. +static int v4l2_async_create_ancillary_links(struct v4l2_async_notifier *n,
  946. + struct v4l2_subdev *sd)
  947. +{
  948. + struct media_link *link = NULL;
  949. +
  950. +#if IS_ENABLED(CONFIG_MEDIA_CONTROLLER)
  951. +
  952. + if (sd->entity.function != MEDIA_ENT_F_LENS &&
  953. + sd->entity.function != MEDIA_ENT_F_FLASH)
  954. + return 0;
  955. +
  956. + link = media_create_ancillary_link(&n->sd->entity, &sd->entity);
  957. +
  958. +#endif
  959. +
  960. + return IS_ERR(link) ? PTR_ERR(link) : 0;
  961. +}
  962. +
  963. static int v4l2_async_match_notify(struct v4l2_async_notifier *notifier,
  964. struct v4l2_device *v4l2_dev,
  965. struct v4l2_subdev *sd,
  966. @@ -293,6 +311,19 @@ static int v4l2_async_match_notify(struct v4l2_async_notifier *notifier,
  967. return ret;
  968. }
  969. + /*
  970. + * Depending of the function of the entities involved, we may want to
  971. + * create links between them (for example between a sensor and its lens
  972. + * or between a sensor's source pad and the connected device's sink
  973. + * pad).
  974. + */
  975. + ret = v4l2_async_create_ancillary_links(notifier, sd);
  976. + if (ret) {
  977. + v4l2_async_nf_call_unbind(notifier, sd, asd);
  978. + v4l2_device_unregister_subdev(sd);
  979. + return ret;
  980. + }
  981. +
  982. /* Remove from the waiting list */
  983. list_del(&asd->list);
  984. sd->asd = asd;
  985. --
  986. 2.36.1
  987. From 8dc582d9c02942a7aa2bedaeca6a6874980ae209 Mon Sep 17 00:00:00 2001
  988. From: Daniel Scally <djrscally@gmail.com>
  989. Date: Wed, 4 May 2022 23:21:45 +0100
  990. Subject: [PATCH] media: ipu3-cio2: Move functionality from .complete() to
  991. .bound()
  992. Creating links and registering subdev nodes during the .complete()
  993. callback has the unfortunate effect of preventing all cameras that
  994. connect to a notifier from working if any one of their drivers fails
  995. to probe. Moving the functionality from .complete() to .bound() allows
  996. those camera sensor drivers that did probe correctly to work regardless.
  997. Signed-off-by: Daniel Scally <djrscally@gmail.com>
  998. Patchset: cameras
  999. ---
  1000. drivers/media/pci/intel/ipu3/ipu3-cio2-main.c | 65 +++++++------------
  1001. 1 file changed, 23 insertions(+), 42 deletions(-)
  1002. diff --git a/drivers/media/pci/intel/ipu3/ipu3-cio2-main.c b/drivers/media/pci/intel/ipu3/ipu3-cio2-main.c
  1003. index 0e9b0503b62a..50682a7b2a07 100644
  1004. --- a/drivers/media/pci/intel/ipu3/ipu3-cio2-main.c
  1005. +++ b/drivers/media/pci/intel/ipu3/ipu3-cio2-main.c
  1006. @@ -1382,7 +1382,10 @@ static int cio2_notifier_bound(struct v4l2_async_notifier *notifier,
  1007. {
  1008. struct cio2_device *cio2 = to_cio2_device(notifier);
  1009. struct sensor_async_subdev *s_asd = to_sensor_asd(asd);
  1010. + struct device *dev = &cio2->pci_dev->dev;
  1011. struct cio2_queue *q;
  1012. + unsigned int pad;
  1013. + int ret;
  1014. if (cio2->queue[s_asd->csi2.port].sensor)
  1015. return -EBUSY;
  1016. @@ -1393,7 +1396,26 @@ static int cio2_notifier_bound(struct v4l2_async_notifier *notifier,
  1017. q->sensor = sd;
  1018. q->csi_rx_base = cio2->base + CIO2_REG_PIPE_BASE(q->csi2.port);
  1019. - return 0;
  1020. + for (pad = 0; pad < q->sensor->entity.num_pads; pad++)
  1021. + if (q->sensor->entity.pads[pad].flags &
  1022. + MEDIA_PAD_FL_SOURCE)
  1023. + break;
  1024. +
  1025. + if (pad == q->sensor->entity.num_pads) {
  1026. + dev_err(dev, "failed to find src pad for %s\n",
  1027. + q->sensor->name);
  1028. + return -ENXIO;
  1029. + }
  1030. +
  1031. + ret = media_create_pad_link(&q->sensor->entity, pad, &q->subdev.entity,
  1032. + CIO2_PAD_SINK, 0);
  1033. + if (ret) {
  1034. + dev_err(dev, "failed to create link for %s\n",
  1035. + q->sensor->name);
  1036. + return ret;
  1037. + }
  1038. +
  1039. + return v4l2_device_register_subdev_nodes(&cio2->v4l2_dev);
  1040. }
  1041. /* The .unbind callback */
  1042. @@ -1407,50 +1429,9 @@ static void cio2_notifier_unbind(struct v4l2_async_notifier *notifier,
  1043. cio2->queue[s_asd->csi2.port].sensor = NULL;
  1044. }
  1045. -/* .complete() is called after all subdevices have been located */
  1046. -static int cio2_notifier_complete(struct v4l2_async_notifier *notifier)
  1047. -{
  1048. - struct cio2_device *cio2 = to_cio2_device(notifier);
  1049. - struct device *dev = &cio2->pci_dev->dev;
  1050. - struct sensor_async_subdev *s_asd;
  1051. - struct v4l2_async_subdev *asd;
  1052. - struct cio2_queue *q;
  1053. - unsigned int pad;
  1054. - int ret;
  1055. -
  1056. - list_for_each_entry(asd, &cio2->notifier.asd_list, asd_list) {
  1057. - s_asd = to_sensor_asd(asd);
  1058. - q = &cio2->queue[s_asd->csi2.port];
  1059. -
  1060. - for (pad = 0; pad < q->sensor->entity.num_pads; pad++)
  1061. - if (q->sensor->entity.pads[pad].flags &
  1062. - MEDIA_PAD_FL_SOURCE)
  1063. - break;
  1064. -
  1065. - if (pad == q->sensor->entity.num_pads) {
  1066. - dev_err(dev, "failed to find src pad for %s\n",
  1067. - q->sensor->name);
  1068. - return -ENXIO;
  1069. - }
  1070. -
  1071. - ret = media_create_pad_link(
  1072. - &q->sensor->entity, pad,
  1073. - &q->subdev.entity, CIO2_PAD_SINK,
  1074. - 0);
  1075. - if (ret) {
  1076. - dev_err(dev, "failed to create link for %s\n",
  1077. - q->sensor->name);
  1078. - return ret;
  1079. - }
  1080. - }
  1081. -
  1082. - return v4l2_device_register_subdev_nodes(&cio2->v4l2_dev);
  1083. -}
  1084. -
  1085. static const struct v4l2_async_notifier_operations cio2_async_ops = {
  1086. .bound = cio2_notifier_bound,
  1087. .unbind = cio2_notifier_unbind,
  1088. - .complete = cio2_notifier_complete,
  1089. };
  1090. static int cio2_parse_firmware(struct cio2_device *cio2)
  1091. --
  1092. 2.36.1
  1093. From d6c1da8bbd5c3bf70b4d392f0cc4cd69d484b720 Mon Sep 17 00:00:00 2001
  1094. From: Daniel Scally <djrscally@gmail.com>
  1095. Date: Thu, 2 Jun 2022 22:15:56 +0100
  1096. Subject: [PATCH] media: ipu3-cio2: Re-add .complete() to ipu3-cio2
  1097. Removing the .complete() callback had some unintended consequences.
  1098. Because the VCM driver is not directly linked to the ipu3-cio2
  1099. driver .bound() never gets called for it, which means its devnode
  1100. is never created if it probes late. Because .complete() waits for
  1101. any sub-notifiers to also be complete it is captured in that call.
  1102. Signed-off-by: Daniel Scally <djrscally@gmail.com>
  1103. Patchset: cameras
  1104. ---
  1105. drivers/media/pci/intel/ipu3/ipu3-cio2-main.c | 9 +++++++++
  1106. 1 file changed, 9 insertions(+)
  1107. diff --git a/drivers/media/pci/intel/ipu3/ipu3-cio2-main.c b/drivers/media/pci/intel/ipu3/ipu3-cio2-main.c
  1108. index 50682a7b2a07..ff79582a583d 100644
  1109. --- a/drivers/media/pci/intel/ipu3/ipu3-cio2-main.c
  1110. +++ b/drivers/media/pci/intel/ipu3/ipu3-cio2-main.c
  1111. @@ -1429,9 +1429,18 @@ static void cio2_notifier_unbind(struct v4l2_async_notifier *notifier,
  1112. cio2->queue[s_asd->csi2.port].sensor = NULL;
  1113. }
  1114. +/* .complete() is called after all subdevices have been located */
  1115. +static int cio2_notifier_complete(struct v4l2_async_notifier *notifier)
  1116. +{
  1117. + struct cio2_device *cio2 = to_cio2_device(notifier);
  1118. +
  1119. + return v4l2_device_register_subdev_nodes(&cio2->v4l2_dev);
  1120. +}
  1121. +
  1122. static const struct v4l2_async_notifier_operations cio2_async_ops = {
  1123. .bound = cio2_notifier_bound,
  1124. .unbind = cio2_notifier_unbind,
  1125. + .complete = cio2_notifier_complete,
  1126. };
  1127. static int cio2_parse_firmware(struct cio2_device *cio2)
  1128. --
  1129. 2.36.1