0012-cameras.patch 42 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394
  1. From 6d04b8ab365775a6b1ab7b7c560b5d50e78bb783 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 87e385542576..1183d09c13a6 100644
  51. --- a/drivers/acpi/scan.c
  52. +++ b/drivers/acpi/scan.c
  53. @@ -2105,6 +2105,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.42.0
  64. From df1aa869818d56d8153223c60d74fb307cf3ff81 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 6387f3a6eccf..d75107c47de0 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. @@ -290,12 +296,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. @@ -2553,6 +2561,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. @@ -2862,6 +2873,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. @@ -4765,6 +4779,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. @@ -4776,6 +4802,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. @@ -4811,6 +4838,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.42.0
  168. From 58f403707b4b56371254100412f325a30ef1707d 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 1e107fd49f82..e3e1696e7f0e 100644
  183. --- a/drivers/platform/x86/intel/int3472/tps68470.c
  184. +++ b/drivers/platform/x86/intel/int3472/tps68470.c
  185. @@ -46,6 +46,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.42.0
  199. From 60a2d404d65225351612a7d3d3d5a1d1a382ca82 Mon Sep 17 00:00:00 2001
  200. From: Daniel Scally <djrscally@gmail.com>
  201. Date: Wed, 4 May 2022 23:21:45 +0100
  202. Subject: [PATCH] media: ipu3-cio2: Move functionality from .complete() to
  203. .bound()
  204. Creating links and registering subdev nodes during the .complete()
  205. callback has the unfortunate effect of preventing all cameras that
  206. connect to a notifier from working if any one of their drivers fails
  207. to probe. Moving the functionality from .complete() to .bound() allows
  208. those camera sensor drivers that did probe correctly to work regardless.
  209. Signed-off-by: Daniel Scally <djrscally@gmail.com>
  210. Patchset: cameras
  211. ---
  212. drivers/media/pci/intel/ipu3/ipu3-cio2-main.c | 59 +++++++------------
  213. 1 file changed, 21 insertions(+), 38 deletions(-)
  214. diff --git a/drivers/media/pci/intel/ipu3/ipu3-cio2-main.c b/drivers/media/pci/intel/ipu3/ipu3-cio2-main.c
  215. index ca51776a961f..c027b2bfd851 100644
  216. --- a/drivers/media/pci/intel/ipu3/ipu3-cio2-main.c
  217. +++ b/drivers/media/pci/intel/ipu3/ipu3-cio2-main.c
  218. @@ -1386,7 +1386,10 @@ static int cio2_notifier_bound(struct v4l2_async_notifier *notifier,
  219. {
  220. struct cio2_device *cio2 = to_cio2_device(notifier);
  221. struct sensor_async_subdev *s_asd = to_sensor_asd(asd);
  222. + struct device *dev = &cio2->pci_dev->dev;
  223. struct cio2_queue *q;
  224. + unsigned int pad;
  225. + int ret;
  226. if (cio2->queue[s_asd->csi2.port].sensor)
  227. return -EBUSY;
  228. @@ -1397,7 +1400,24 @@ static int cio2_notifier_bound(struct v4l2_async_notifier *notifier,
  229. q->sensor = sd;
  230. q->csi_rx_base = cio2->base + CIO2_REG_PIPE_BASE(q->csi2.port);
  231. - return 0;
  232. + ret = media_entity_get_fwnode_pad(&q->sensor->entity,
  233. + s_asd->asd.match.fwnode,
  234. + MEDIA_PAD_FL_SOURCE);
  235. + if (ret < 0) {
  236. + dev_err(dev, "no pad for endpoint %pfw (%d)\n",
  237. + s_asd->asd.match.fwnode, ret);
  238. + return ret;
  239. + }
  240. +
  241. + ret = media_create_pad_link(&q->sensor->entity, ret, &q->subdev.entity,
  242. + CIO2_PAD_SINK, 0);
  243. + if (ret) {
  244. + dev_err(dev, "failed to create link for %s\n",
  245. + q->sensor->name);
  246. + return ret;
  247. + }
  248. +
  249. + return v4l2_device_register_subdev_nodes(&cio2->v4l2_dev);
  250. }
  251. /* The .unbind callback */
  252. @@ -1411,46 +1431,9 @@ static void cio2_notifier_unbind(struct v4l2_async_notifier *notifier,
  253. cio2->queue[s_asd->csi2.port].sensor = NULL;
  254. }
  255. -/* .complete() is called after all subdevices have been located */
  256. -static int cio2_notifier_complete(struct v4l2_async_notifier *notifier)
  257. -{
  258. - struct cio2_device *cio2 = to_cio2_device(notifier);
  259. - struct device *dev = &cio2->pci_dev->dev;
  260. - struct sensor_async_subdev *s_asd;
  261. - struct v4l2_async_subdev *asd;
  262. - struct cio2_queue *q;
  263. - int ret;
  264. -
  265. - list_for_each_entry(asd, &cio2->notifier.asd_list, asd_list) {
  266. - s_asd = to_sensor_asd(asd);
  267. - q = &cio2->queue[s_asd->csi2.port];
  268. -
  269. - ret = media_entity_get_fwnode_pad(&q->sensor->entity,
  270. - s_asd->asd.match.fwnode,
  271. - MEDIA_PAD_FL_SOURCE);
  272. - if (ret < 0) {
  273. - dev_err(dev, "no pad for endpoint %pfw (%d)\n",
  274. - s_asd->asd.match.fwnode, ret);
  275. - return ret;
  276. - }
  277. -
  278. - ret = media_create_pad_link(&q->sensor->entity, ret,
  279. - &q->subdev.entity, CIO2_PAD_SINK,
  280. - 0);
  281. - if (ret) {
  282. - dev_err(dev, "failed to create link for %s (endpoint %pfw, error %d)\n",
  283. - q->sensor->name, s_asd->asd.match.fwnode, ret);
  284. - return ret;
  285. - }
  286. - }
  287. -
  288. - return v4l2_device_register_subdev_nodes(&cio2->v4l2_dev);
  289. -}
  290. -
  291. static const struct v4l2_async_notifier_operations cio2_async_ops = {
  292. .bound = cio2_notifier_bound,
  293. .unbind = cio2_notifier_unbind,
  294. - .complete = cio2_notifier_complete,
  295. };
  296. static int cio2_parse_firmware(struct cio2_device *cio2)
  297. --
  298. 2.42.0
  299. From e9b59c24855f146141b665efed05b7455aeb5fd4 Mon Sep 17 00:00:00 2001
  300. From: Daniel Scally <djrscally@gmail.com>
  301. Date: Thu, 2 Jun 2022 22:15:56 +0100
  302. Subject: [PATCH] media: ipu3-cio2: Re-add .complete() to ipu3-cio2
  303. Removing the .complete() callback had some unintended consequences.
  304. Because the VCM driver is not directly linked to the ipu3-cio2
  305. driver .bound() never gets called for it, which means its devnode
  306. is never created if it probes late. Because .complete() waits for
  307. any sub-notifiers to also be complete it is captured in that call.
  308. Signed-off-by: Daniel Scally <djrscally@gmail.com>
  309. Patchset: cameras
  310. ---
  311. drivers/media/pci/intel/ipu3/ipu3-cio2-main.c | 9 +++++++++
  312. 1 file changed, 9 insertions(+)
  313. diff --git a/drivers/media/pci/intel/ipu3/ipu3-cio2-main.c b/drivers/media/pci/intel/ipu3/ipu3-cio2-main.c
  314. index c027b2bfd851..031acee26553 100644
  315. --- a/drivers/media/pci/intel/ipu3/ipu3-cio2-main.c
  316. +++ b/drivers/media/pci/intel/ipu3/ipu3-cio2-main.c
  317. @@ -1431,9 +1431,18 @@ static void cio2_notifier_unbind(struct v4l2_async_notifier *notifier,
  318. cio2->queue[s_asd->csi2.port].sensor = NULL;
  319. }
  320. +/* .complete() is called after all subdevices have been located */
  321. +static int cio2_notifier_complete(struct v4l2_async_notifier *notifier)
  322. +{
  323. + struct cio2_device *cio2 = to_cio2_device(notifier);
  324. +
  325. + return v4l2_device_register_subdev_nodes(&cio2->v4l2_dev);
  326. +}
  327. +
  328. static const struct v4l2_async_notifier_operations cio2_async_ops = {
  329. .bound = cio2_notifier_bound,
  330. .unbind = cio2_notifier_unbind,
  331. + .complete = cio2_notifier_complete,
  332. };
  333. static int cio2_parse_firmware(struct cio2_device *cio2)
  334. --
  335. 2.42.0
  336. From 0926490302f353661c1a454f27611f5c94d928f0 Mon Sep 17 00:00:00 2001
  337. From: Daniel Scally <djrscally@gmail.com>
  338. Date: Thu, 28 Oct 2021 21:55:16 +0100
  339. Subject: [PATCH] media: i2c: Add driver for DW9719 VCM
  340. Add a driver for the DW9719 VCM. The driver creates a v4l2 subdevice
  341. and registers a control to set the desired focus.
  342. Signed-off-by: Daniel Scally <djrscally@gmail.com>
  343. Patchset: cameras
  344. ---
  345. MAINTAINERS | 7 +
  346. drivers/media/i2c/Kconfig | 11 +
  347. drivers/media/i2c/Makefile | 1 +
  348. drivers/media/i2c/dw9719.c | 425 +++++++++++++++++++++++++++++++++++++
  349. 4 files changed, 444 insertions(+)
  350. create mode 100644 drivers/media/i2c/dw9719.c
  351. diff --git a/MAINTAINERS b/MAINTAINERS
  352. index 4cc6bf79fdd8..439cf523b80e 100644
  353. --- a/MAINTAINERS
  354. +++ b/MAINTAINERS
  355. @@ -6251,6 +6251,13 @@ T: git git://linuxtv.org/media_tree.git
  356. F: Documentation/devicetree/bindings/media/i2c/dongwoon,dw9714.yaml
  357. F: drivers/media/i2c/dw9714.c
  358. +DONGWOON DW9719 LENS VOICE COIL DRIVER
  359. +M: Daniel Scally <djrscally@gmail.com>
  360. +L: linux-media@vger.kernel.org
  361. +S: Maintained
  362. +T: git git://linuxtv.org/media_tree.git
  363. +F: drivers/media/i2c/dw9719.c
  364. +
  365. DONGWOON DW9768 LENS VOICE COIL DRIVER
  366. M: Dongchun Zhu <dongchun.zhu@mediatek.com>
  367. L: linux-media@vger.kernel.org
  368. diff --git a/drivers/media/i2c/Kconfig b/drivers/media/i2c/Kconfig
  369. index 0669aea3eba3..6959ee1a89fb 100644
  370. --- a/drivers/media/i2c/Kconfig
  371. +++ b/drivers/media/i2c/Kconfig
  372. @@ -855,6 +855,17 @@ config VIDEO_DW9714
  373. capability. This is designed for linear control of
  374. voice coil motors, controlled via I2C serial interface.
  375. +config VIDEO_DW9719
  376. + tristate "DW9719 lens voice coil support"
  377. + depends on I2C && VIDEO_V4L2
  378. + select MEDIA_CONTROLLER
  379. + select VIDEO_V4L2_SUBDEV_API
  380. + select V4L2_ASYNC
  381. + help
  382. + This is a driver for the DW9719 camera lens voice coil.
  383. + This is designed for linear control of voice coil motors,
  384. + controlled via I2C serial interface.
  385. +
  386. config VIDEO_DW9768
  387. tristate "DW9768 lens voice coil support"
  388. depends on I2C && VIDEO_DEV
  389. diff --git a/drivers/media/i2c/Makefile b/drivers/media/i2c/Makefile
  390. index c743aeb5d1ad..db1ebf5cadfe 100644
  391. --- a/drivers/media/i2c/Makefile
  392. +++ b/drivers/media/i2c/Makefile
  393. @@ -29,6 +29,7 @@ obj-$(CONFIG_VIDEO_CS5345) += cs5345.o
  394. obj-$(CONFIG_VIDEO_CS53L32A) += cs53l32a.o
  395. obj-$(CONFIG_VIDEO_CX25840) += cx25840/
  396. obj-$(CONFIG_VIDEO_DW9714) += dw9714.o
  397. +obj-$(CONFIG_VIDEO_DW9719) += dw9719.o
  398. obj-$(CONFIG_VIDEO_DW9768) += dw9768.o
  399. obj-$(CONFIG_VIDEO_DW9807_VCM) += dw9807-vcm.o
  400. obj-$(CONFIG_VIDEO_ET8EK8) += et8ek8/
  401. diff --git a/drivers/media/i2c/dw9719.c b/drivers/media/i2c/dw9719.c
  402. new file mode 100644
  403. index 000000000000..180b04d2a6b3
  404. --- /dev/null
  405. +++ b/drivers/media/i2c/dw9719.c
  406. @@ -0,0 +1,425 @@
  407. +// SPDX-License-Identifier: GPL-2.0
  408. +// Copyright (c) 2012 Intel Corporation
  409. +
  410. +/*
  411. + * Based on linux/modules/camera/drivers/media/i2c/imx/dw9719.c in this repo:
  412. + * https://github.com/ZenfoneArea/android_kernel_asus_zenfone5
  413. + */
  414. +
  415. +#include <asm/unaligned.h>
  416. +
  417. +#include <linux/delay.h>
  418. +#include <linux/i2c.h>
  419. +#include <linux/pm_runtime.h>
  420. +#include <linux/regulator/consumer.h>
  421. +#include <linux/types.h>
  422. +
  423. +#include <media/v4l2-common.h>
  424. +#include <media/v4l2-ctrls.h>
  425. +#include <media/v4l2-subdev.h>
  426. +
  427. +#define DW9719_MAX_FOCUS_POS 1023
  428. +#define DW9719_CTRL_STEPS 16
  429. +#define DW9719_CTRL_DELAY_US 1000
  430. +#define DELAY_MAX_PER_STEP_NS (1000000 * 1023)
  431. +
  432. +#define DW9719_INFO 0
  433. +#define DW9719_ID 0xF1
  434. +#define DW9719_CONTROL 2
  435. +#define DW9719_VCM_CURRENT 3
  436. +
  437. +#define DW9719_MODE 6
  438. +#define DW9719_VCM_FREQ 7
  439. +
  440. +#define DW9719_MODE_SAC3 0x40
  441. +#define DW9719_DEFAULT_VCM_FREQ 0x60
  442. +#define DW9719_ENABLE_RINGING 0x02
  443. +
  444. +#define NUM_REGULATORS 2
  445. +
  446. +#define to_dw9719_device(x) container_of(x, struct dw9719_device, sd)
  447. +
  448. +struct dw9719_device {
  449. + struct device *dev;
  450. + struct i2c_client *client;
  451. + struct regulator_bulk_data regulators[NUM_REGULATORS];
  452. + struct v4l2_subdev sd;
  453. +
  454. + struct dw9719_v4l2_ctrls {
  455. + struct v4l2_ctrl_handler handler;
  456. + struct v4l2_ctrl *focus;
  457. + } ctrls;
  458. +};
  459. +
  460. +static int dw9719_i2c_rd8(struct i2c_client *client, u8 reg, u8 *val)
  461. +{
  462. + struct i2c_msg msg[2];
  463. + u8 buf[2] = { reg };
  464. + int ret;
  465. +
  466. + msg[0].addr = client->addr;
  467. + msg[0].flags = 0;
  468. + msg[0].len = 1;
  469. + msg[0].buf = buf;
  470. +
  471. + msg[1].addr = client->addr;
  472. + msg[1].flags = I2C_M_RD;
  473. + msg[1].len = 1;
  474. + msg[1].buf = &buf[1];
  475. + *val = 0;
  476. +
  477. + ret = i2c_transfer(client->adapter, msg, 2);
  478. + if (ret < 0)
  479. + return ret;
  480. +
  481. + *val = buf[1];
  482. +
  483. + return 0;
  484. +}
  485. +
  486. +static int dw9719_i2c_wr8(struct i2c_client *client, u8 reg, u8 val)
  487. +{
  488. + struct i2c_msg msg;
  489. + int ret;
  490. +
  491. + u8 buf[2] = { reg, val };
  492. +
  493. + msg.addr = client->addr;
  494. + msg.flags = 0;
  495. + msg.len = sizeof(buf);
  496. + msg.buf = buf;
  497. +
  498. + ret = i2c_transfer(client->adapter, &msg, 1);
  499. +
  500. + return ret < 0 ? ret : 0;
  501. +}
  502. +
  503. +static int dw9719_i2c_wr16(struct i2c_client *client, u8 reg, u16 val)
  504. +{
  505. + struct i2c_msg msg;
  506. + u8 buf[3] = { reg };
  507. + int ret;
  508. +
  509. + put_unaligned_be16(val, buf + 1);
  510. +
  511. + msg.addr = client->addr;
  512. + msg.flags = 0;
  513. + msg.len = sizeof(buf);
  514. + msg.buf = buf;
  515. +
  516. + ret = i2c_transfer(client->adapter, &msg, 1);
  517. +
  518. + return ret < 0 ? ret : 0;
  519. +}
  520. +
  521. +static int dw9719_detect(struct dw9719_device *dw9719)
  522. +{
  523. + int ret;
  524. + u8 val;
  525. +
  526. + ret = dw9719_i2c_rd8(dw9719->client, DW9719_INFO, &val);
  527. + if (ret < 0)
  528. + return ret;
  529. +
  530. + if (val != DW9719_ID) {
  531. + dev_err(dw9719->dev, "Failed to detect correct id\n");
  532. + ret = -ENXIO;
  533. + }
  534. +
  535. + return 0;
  536. +}
  537. +
  538. +static int dw9719_power_down(struct dw9719_device *dw9719)
  539. +{
  540. + return regulator_bulk_disable(NUM_REGULATORS, dw9719->regulators);
  541. +}
  542. +
  543. +static int dw9719_power_up(struct dw9719_device *dw9719)
  544. +{
  545. + int ret;
  546. +
  547. + ret = regulator_bulk_enable(NUM_REGULATORS, dw9719->regulators);
  548. + if (ret)
  549. + return ret;
  550. +
  551. + /* Jiggle SCL pin to wake up device */
  552. + ret = dw9719_i2c_wr8(dw9719->client, DW9719_CONTROL, 1);
  553. +
  554. + /* Need 100us to transit from SHUTDOWN to STANDBY*/
  555. + usleep_range(100, 1000);
  556. +
  557. + ret = dw9719_i2c_wr8(dw9719->client, DW9719_CONTROL,
  558. + DW9719_ENABLE_RINGING);
  559. + if (ret < 0)
  560. + goto fail_powerdown;
  561. +
  562. + ret = dw9719_i2c_wr8(dw9719->client, DW9719_MODE, DW9719_MODE_SAC3);
  563. + if (ret < 0)
  564. + goto fail_powerdown;
  565. +
  566. + ret = dw9719_i2c_wr8(dw9719->client, DW9719_VCM_FREQ,
  567. + DW9719_DEFAULT_VCM_FREQ);
  568. + if (ret < 0)
  569. + goto fail_powerdown;
  570. +
  571. + return 0;
  572. +
  573. +fail_powerdown:
  574. + dw9719_power_down(dw9719);
  575. + return ret;
  576. +}
  577. +
  578. +static int dw9719_t_focus_abs(struct dw9719_device *dw9719, s32 value)
  579. +{
  580. + int ret;
  581. +
  582. + value = clamp(value, 0, DW9719_MAX_FOCUS_POS);
  583. + ret = dw9719_i2c_wr16(dw9719->client, DW9719_VCM_CURRENT, value);
  584. + if (ret < 0)
  585. + return ret;
  586. +
  587. + return 0;
  588. +}
  589. +
  590. +static int dw9719_set_ctrl(struct v4l2_ctrl *ctrl)
  591. +{
  592. + struct dw9719_device *dw9719 = container_of(ctrl->handler,
  593. + struct dw9719_device,
  594. + ctrls.handler);
  595. + int ret;
  596. +
  597. + /* Only apply changes to the controls if the device is powered up */
  598. + if (!pm_runtime_get_if_in_use(dw9719->dev))
  599. + return 0;
  600. +
  601. + switch (ctrl->id) {
  602. + case V4L2_CID_FOCUS_ABSOLUTE:
  603. + ret = dw9719_t_focus_abs(dw9719, ctrl->val);
  604. + break;
  605. + default:
  606. + ret = -EINVAL;
  607. + }
  608. +
  609. + pm_runtime_put(dw9719->dev);
  610. +
  611. + return ret;
  612. +}
  613. +
  614. +static const struct v4l2_ctrl_ops dw9719_ctrl_ops = {
  615. + .s_ctrl = dw9719_set_ctrl,
  616. +};
  617. +
  618. +static int __maybe_unused dw9719_suspend(struct device *dev)
  619. +{
  620. + struct v4l2_subdev *sd = dev_get_drvdata(dev);
  621. + struct dw9719_device *dw9719 = to_dw9719_device(sd);
  622. + int ret;
  623. + int val;
  624. +
  625. + for (val = dw9719->ctrls.focus->val; val >= 0;
  626. + val -= DW9719_CTRL_STEPS) {
  627. + ret = dw9719_t_focus_abs(dw9719, val);
  628. + if (ret)
  629. + return ret;
  630. +
  631. + usleep_range(DW9719_CTRL_DELAY_US, DW9719_CTRL_DELAY_US + 10);
  632. + }
  633. +
  634. + return dw9719_power_down(dw9719);
  635. +}
  636. +
  637. +static int __maybe_unused dw9719_resume(struct device *dev)
  638. +{
  639. + struct v4l2_subdev *sd = dev_get_drvdata(dev);
  640. + struct dw9719_device *dw9719 = to_dw9719_device(sd);
  641. + int current_focus = dw9719->ctrls.focus->val;
  642. + int ret;
  643. + int val;
  644. +
  645. + ret = dw9719_power_up(dw9719);
  646. + if (ret)
  647. + return ret;
  648. +
  649. + for (val = current_focus % DW9719_CTRL_STEPS; val < current_focus;
  650. + val += DW9719_CTRL_STEPS) {
  651. + ret = dw9719_t_focus_abs(dw9719, val);
  652. + if (ret)
  653. + goto err_power_down;
  654. +
  655. + usleep_range(DW9719_CTRL_DELAY_US, DW9719_CTRL_DELAY_US + 10);
  656. + }
  657. +
  658. + return 0;
  659. +
  660. +err_power_down:
  661. + dw9719_power_down(dw9719);
  662. + return ret;
  663. +}
  664. +
  665. +static int dw9719_open(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh)
  666. +{
  667. + return pm_runtime_resume_and_get(sd->dev);
  668. +}
  669. +
  670. +static int dw9719_close(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh)
  671. +{
  672. + pm_runtime_put(sd->dev);
  673. +
  674. + return 0;
  675. +}
  676. +
  677. +static const struct v4l2_subdev_internal_ops dw9719_internal_ops = {
  678. + .open = dw9719_open,
  679. + .close = dw9719_close,
  680. +};
  681. +
  682. +static int dw9719_init_controls(struct dw9719_device *dw9719)
  683. +{
  684. + const struct v4l2_ctrl_ops *ops = &dw9719_ctrl_ops;
  685. + int ret;
  686. +
  687. + ret = v4l2_ctrl_handler_init(&dw9719->ctrls.handler, 1);
  688. + if (ret)
  689. + return ret;
  690. +
  691. + dw9719->ctrls.focus = v4l2_ctrl_new_std(&dw9719->ctrls.handler, ops,
  692. + V4L2_CID_FOCUS_ABSOLUTE, 0,
  693. + DW9719_MAX_FOCUS_POS, 1, 0);
  694. +
  695. + if (dw9719->ctrls.handler.error) {
  696. + dev_err(dw9719->dev, "Error initialising v4l2 ctrls\n");
  697. + ret = dw9719->ctrls.handler.error;
  698. + goto err_free_handler;
  699. + }
  700. +
  701. + dw9719->sd.ctrl_handler = &dw9719->ctrls.handler;
  702. +
  703. + return ret;
  704. +
  705. +err_free_handler:
  706. + v4l2_ctrl_handler_free(&dw9719->ctrls.handler);
  707. + return ret;
  708. +}
  709. +
  710. +static const struct v4l2_subdev_ops dw9719_ops = { };
  711. +
  712. +static int dw9719_probe(struct i2c_client *client)
  713. +{
  714. + struct dw9719_device *dw9719;
  715. + int ret;
  716. +
  717. + dw9719 = devm_kzalloc(&client->dev, sizeof(*dw9719), GFP_KERNEL);
  718. + if (!dw9719)
  719. + return -ENOMEM;
  720. +
  721. + dw9719->client = client;
  722. + dw9719->dev = &client->dev;
  723. +
  724. + dw9719->regulators[0].supply = "vdd";
  725. + /*
  726. + * The DW9719 has only the 1 VDD voltage input, but some PMICs such as
  727. + * the TPS68470 PMIC have I2C passthrough capability, to disconnect the
  728. + * sensor's I2C pins from the I2C bus when the sensors VSIO (Sensor-IO)
  729. + * is off, because some sensors then short these pins to ground;
  730. + * and the DW9719 might sit behind this passthrough, this it needs to
  731. + * enable VSIO as that will also enable the I2C passthrough.
  732. + */
  733. + dw9719->regulators[1].supply = "vsio";
  734. +
  735. + ret = devm_regulator_bulk_get(&client->dev, NUM_REGULATORS,
  736. + dw9719->regulators);
  737. + if (ret)
  738. + return dev_err_probe(&client->dev, ret, "getting regulators\n");
  739. +
  740. + v4l2_i2c_subdev_init(&dw9719->sd, client, &dw9719_ops);
  741. + dw9719->sd.flags |= V4L2_SUBDEV_FL_HAS_DEVNODE;
  742. + dw9719->sd.internal_ops = &dw9719_internal_ops;
  743. +
  744. + ret = dw9719_init_controls(dw9719);
  745. + if (ret)
  746. + return ret;
  747. +
  748. + ret = media_entity_pads_init(&dw9719->sd.entity, 0, NULL);
  749. + if (ret < 0)
  750. + goto err_free_ctrl_handler;
  751. +
  752. + dw9719->sd.entity.function = MEDIA_ENT_F_LENS;
  753. +
  754. + /*
  755. + * We need the driver to work in the event that pm runtime is disable in
  756. + * the kernel, so power up and verify the chip now. In the event that
  757. + * runtime pm is disabled this will leave the chip on, so that the lens
  758. + * will work.
  759. + */
  760. +
  761. + ret = dw9719_power_up(dw9719);
  762. + if (ret)
  763. + goto err_cleanup_media;
  764. +
  765. + ret = dw9719_detect(dw9719);
  766. + if (ret)
  767. + goto err_powerdown;
  768. +
  769. + pm_runtime_set_active(&client->dev);
  770. + pm_runtime_get_noresume(&client->dev);
  771. + pm_runtime_enable(&client->dev);
  772. +
  773. + ret = v4l2_async_register_subdev(&dw9719->sd);
  774. + if (ret < 0)
  775. + goto err_pm_runtime;
  776. +
  777. + pm_runtime_set_autosuspend_delay(&client->dev, 1000);
  778. + pm_runtime_use_autosuspend(&client->dev);
  779. + pm_runtime_put_autosuspend(&client->dev);
  780. +
  781. + return ret;
  782. +
  783. +err_pm_runtime:
  784. + pm_runtime_disable(&client->dev);
  785. + pm_runtime_put_noidle(&client->dev);
  786. +err_powerdown:
  787. + dw9719_power_down(dw9719);
  788. +err_cleanup_media:
  789. + media_entity_cleanup(&dw9719->sd.entity);
  790. +err_free_ctrl_handler:
  791. + v4l2_ctrl_handler_free(&dw9719->ctrls.handler);
  792. +
  793. + return ret;
  794. +}
  795. +
  796. +static void dw9719_remove(struct i2c_client *client)
  797. +{
  798. + struct v4l2_subdev *sd = i2c_get_clientdata(client);
  799. + struct dw9719_device *dw9719 = container_of(sd, struct dw9719_device,
  800. + sd);
  801. +
  802. + pm_runtime_disable(&client->dev);
  803. + v4l2_async_unregister_subdev(sd);
  804. + v4l2_ctrl_handler_free(&dw9719->ctrls.handler);
  805. + media_entity_cleanup(&dw9719->sd.entity);
  806. +}
  807. +
  808. +static const struct i2c_device_id dw9719_id_table[] = {
  809. + { "dw9719" },
  810. + { }
  811. +};
  812. +MODULE_DEVICE_TABLE(i2c, dw9719_id_table);
  813. +
  814. +static const struct dev_pm_ops dw9719_pm_ops = {
  815. + SET_RUNTIME_PM_OPS(dw9719_suspend, dw9719_resume, NULL)
  816. +};
  817. +
  818. +static struct i2c_driver dw9719_i2c_driver = {
  819. + .driver = {
  820. + .name = "dw9719",
  821. + .pm = &dw9719_pm_ops,
  822. + },
  823. + .probe_new = dw9719_probe,
  824. + .remove = dw9719_remove,
  825. + .id_table = dw9719_id_table,
  826. +};
  827. +module_i2c_driver(dw9719_i2c_driver);
  828. +
  829. +MODULE_AUTHOR("Daniel Scally <djrscally@gmail.com>");
  830. +MODULE_DESCRIPTION("DW9719 VCM Driver");
  831. +MODULE_LICENSE("GPL");
  832. --
  833. 2.42.0
  834. From 3a35f5894c7e979357c64bbf198bd35dc3489a0a Mon Sep 17 00:00:00 2001
  835. From: Maximilian Luz <luzmaximilian@gmail.com>
  836. Date: Fri, 15 Jul 2022 23:48:00 +0200
  837. Subject: [PATCH] drivers/media/i2c: Fix DW9719 dependencies
  838. It should depend on VIDEO_DEV instead of VIDEO_V4L2.
  839. Signed-off-by: Maximilian Luz <luzmaximilian@gmail.com>
  840. Patchset: cameras
  841. ---
  842. drivers/media/i2c/Kconfig | 2 +-
  843. 1 file changed, 1 insertion(+), 1 deletion(-)
  844. diff --git a/drivers/media/i2c/Kconfig b/drivers/media/i2c/Kconfig
  845. index 6959ee1a89fb..1d5082fe9ce3 100644
  846. --- a/drivers/media/i2c/Kconfig
  847. +++ b/drivers/media/i2c/Kconfig
  848. @@ -857,7 +857,7 @@ config VIDEO_DW9714
  849. config VIDEO_DW9719
  850. tristate "DW9719 lens voice coil support"
  851. - depends on I2C && VIDEO_V4L2
  852. + depends on I2C && VIDEO_DEV
  853. select MEDIA_CONTROLLER
  854. select VIDEO_V4L2_SUBDEV_API
  855. select V4L2_ASYNC
  856. --
  857. 2.42.0
  858. From acbd8c1b38ffee270862e8efcf68ae3580b1b82d Mon Sep 17 00:00:00 2001
  859. From: Daniel Scally <dan.scally@ideasonboard.com>
  860. Date: Thu, 2 Mar 2023 12:59:39 +0000
  861. Subject: [PATCH] platform/x86: int3472: Remap reset GPIO for INT347E
  862. ACPI _HID INT347E represents the OmniVision 7251 camera sensor. The
  863. driver for this sensor expects a single pin named "enable", but on
  864. some Microsoft Surface platforms the sensor is assigned a single
  865. GPIO who's type flag is INT3472_GPIO_TYPE_RESET.
  866. Remap the GPIO pin's function from "reset" to "enable". This is done
  867. outside of the existing remap table since it is a more widespread
  868. discrepancy than that method is designed for. Additionally swap the
  869. polarity of the pin to match the driver's expectation.
  870. Signed-off-by: Daniel Scally <dan.scally@ideasonboard.com>
  871. Patchset: cameras
  872. ---
  873. drivers/platform/x86/intel/int3472/discrete.c | 14 ++++++++++++++
  874. 1 file changed, 14 insertions(+)
  875. diff --git a/drivers/platform/x86/intel/int3472/discrete.c b/drivers/platform/x86/intel/int3472/discrete.c
  876. index e33c2d75975c..c0c90ae66b70 100644
  877. --- a/drivers/platform/x86/intel/int3472/discrete.c
  878. +++ b/drivers/platform/x86/intel/int3472/discrete.c
  879. @@ -57,6 +57,9 @@ static int skl_int3472_map_gpio_to_sensor(struct int3472_discrete_device *int347
  880. const char *func, u32 polarity)
  881. {
  882. char *path = agpio->resource_source.string_ptr;
  883. + const struct acpi_device_id ov7251_ids[] = {
  884. + { "INT347E" },
  885. + };
  886. struct gpiod_lookup *table_entry;
  887. struct acpi_device *adev;
  888. acpi_handle handle;
  889. @@ -67,6 +70,17 @@ static int skl_int3472_map_gpio_to_sensor(struct int3472_discrete_device *int347
  890. return -EINVAL;
  891. }
  892. + /*
  893. + * In addition to the function remap table we need to bulk remap the
  894. + * "reset" GPIO for the OmniVision 7251 sensor, as the driver for that
  895. + * expects its only GPIO pin to be called "enable" (and to have the
  896. + * opposite polarity).
  897. + */
  898. + if (!strcmp(func, "reset") && !acpi_match_device_ids(int3472->sensor, ov7251_ids)) {
  899. + func = "enable";
  900. + polarity = GPIO_ACTIVE_HIGH;
  901. + }
  902. +
  903. status = acpi_get_handle(NULL, path, &handle);
  904. if (ACPI_FAILURE(status))
  905. return -EINVAL;
  906. --
  907. 2.42.0
  908. From b2ae8fc0aecde894bf6e8f52e515de645f1b4739 Mon Sep 17 00:00:00 2001
  909. From: Daniel Scally <dan.scally@ideasonboard.com>
  910. Date: Tue, 21 Mar 2023 13:45:26 +0000
  911. Subject: [PATCH] media: i2c: Clarify that gain is Analogue gain in OV7251
  912. Update the control ID for the gain control in the ov7251 driver to
  913. V4L2_CID_ANALOGUE_GAIN.
  914. Signed-off-by: Daniel Scally <dan.scally@ideasonboard.com>
  915. Patchset: cameras
  916. ---
  917. drivers/media/i2c/ov7251.c | 4 ++--
  918. 1 file changed, 2 insertions(+), 2 deletions(-)
  919. diff --git a/drivers/media/i2c/ov7251.c b/drivers/media/i2c/ov7251.c
  920. index 675fb37a6fea..43b30db08c9e 100644
  921. --- a/drivers/media/i2c/ov7251.c
  922. +++ b/drivers/media/i2c/ov7251.c
  923. @@ -1051,7 +1051,7 @@ static int ov7251_s_ctrl(struct v4l2_ctrl *ctrl)
  924. case V4L2_CID_EXPOSURE:
  925. ret = ov7251_set_exposure(ov7251, ctrl->val);
  926. break;
  927. - case V4L2_CID_GAIN:
  928. + case V4L2_CID_ANALOGUE_GAIN:
  929. ret = ov7251_set_gain(ov7251, ctrl->val);
  930. break;
  931. case V4L2_CID_TEST_PATTERN:
  932. @@ -1551,7 +1551,7 @@ static int ov7251_init_ctrls(struct ov7251 *ov7251)
  933. ov7251->exposure = v4l2_ctrl_new_std(&ov7251->ctrls, &ov7251_ctrl_ops,
  934. V4L2_CID_EXPOSURE, 1, 32, 1, 32);
  935. ov7251->gain = v4l2_ctrl_new_std(&ov7251->ctrls, &ov7251_ctrl_ops,
  936. - V4L2_CID_GAIN, 16, 1023, 1, 16);
  937. + V4L2_CID_ANALOGUE_GAIN, 16, 1023, 1, 16);
  938. v4l2_ctrl_new_std_menu_items(&ov7251->ctrls, &ov7251_ctrl_ops,
  939. V4L2_CID_TEST_PATTERN,
  940. ARRAY_SIZE(ov7251_test_pattern_menu) - 1,
  941. --
  942. 2.42.0
  943. From 590fe333492348f48411fd9c2fc14d4302223266 Mon Sep 17 00:00:00 2001
  944. From: Daniel Scally <dan.scally@ideasonboard.com>
  945. Date: Wed, 22 Mar 2023 11:01:42 +0000
  946. Subject: [PATCH] media: v4l2-core: Acquire privacy led in
  947. v4l2_async_register_subdev()
  948. The current call to v4l2_subdev_get_privacy_led() is contained in
  949. v4l2_async_register_subdev_sensor(), but that function isn't used by
  950. all the sensor drivers. Move the acquisition of the privacy led to
  951. v4l2_async_register_subdev() instead.
  952. Signed-off-by: Daniel Scally <dan.scally@ideasonboard.com>
  953. Patchset: cameras
  954. ---
  955. drivers/media/v4l2-core/v4l2-async.c | 4 ++++
  956. drivers/media/v4l2-core/v4l2-fwnode.c | 4 ----
  957. 2 files changed, 4 insertions(+), 4 deletions(-)
  958. diff --git a/drivers/media/v4l2-core/v4l2-async.c b/drivers/media/v4l2-core/v4l2-async.c
  959. index b16b5f4cb91e..33739a979cbc 100644
  960. --- a/drivers/media/v4l2-core/v4l2-async.c
  961. +++ b/drivers/media/v4l2-core/v4l2-async.c
  962. @@ -760,6 +760,10 @@ int v4l2_async_register_subdev(struct v4l2_subdev *sd)
  963. struct v4l2_async_notifier *notifier;
  964. int ret;
  965. + ret = v4l2_subdev_get_privacy_led(sd);
  966. + if (ret < 0)
  967. + return ret;
  968. +
  969. /*
  970. * No reference taken. The reference is held by the device
  971. * (struct v4l2_subdev.dev), and async sub-device does not
  972. diff --git a/drivers/media/v4l2-core/v4l2-fwnode.c b/drivers/media/v4l2-core/v4l2-fwnode.c
  973. index 4fa9225aa3d9..ed4c75253cbc 100644
  974. --- a/drivers/media/v4l2-core/v4l2-fwnode.c
  975. +++ b/drivers/media/v4l2-core/v4l2-fwnode.c
  976. @@ -1314,10 +1314,6 @@ int v4l2_async_register_subdev_sensor(struct v4l2_subdev *sd)
  977. v4l2_async_nf_init(notifier);
  978. - ret = v4l2_subdev_get_privacy_led(sd);
  979. - if (ret < 0)
  980. - goto out_cleanup;
  981. -
  982. ret = v4l2_async_nf_parse_fwnode_sensor(sd->dev, notifier);
  983. if (ret < 0)
  984. goto out_cleanup;
  985. --
  986. 2.42.0
  987. From cf42b6660ce6a705292e0cd0df8e7d39dcae8f04 Mon Sep 17 00:00:00 2001
  988. From: Kate Hsuan <hpa@redhat.com>
  989. Date: Tue, 21 Mar 2023 23:37:16 +0800
  990. Subject: [PATCH] platform: x86: int3472: Add MFD cell for tps68470 LED
  991. Add MFD cell for tps68470-led.
  992. Reviewed-by: Daniel Scally <dan.scally@ideasonboard.com>
  993. Signed-off-by: Kate Hsuan <hpa@redhat.com>
  994. Reviewed-by: Hans de Goede <hdegoede@redhat.com>
  995. Patchset: cameras
  996. ---
  997. drivers/platform/x86/intel/int3472/tps68470.c | 5 +++--
  998. 1 file changed, 3 insertions(+), 2 deletions(-)
  999. diff --git a/drivers/platform/x86/intel/int3472/tps68470.c b/drivers/platform/x86/intel/int3472/tps68470.c
  1000. index e3e1696e7f0e..423dc555093f 100644
  1001. --- a/drivers/platform/x86/intel/int3472/tps68470.c
  1002. +++ b/drivers/platform/x86/intel/int3472/tps68470.c
  1003. @@ -17,7 +17,7 @@
  1004. #define DESIGNED_FOR_CHROMEOS 1
  1005. #define DESIGNED_FOR_WINDOWS 2
  1006. -#define TPS68470_WIN_MFD_CELL_COUNT 3
  1007. +#define TPS68470_WIN_MFD_CELL_COUNT 4
  1008. static const struct mfd_cell tps68470_cros[] = {
  1009. { .name = "tps68470-gpio" },
  1010. @@ -200,7 +200,8 @@ static int skl_int3472_tps68470_probe(struct i2c_client *client)
  1011. cells[1].name = "tps68470-regulator";
  1012. cells[1].platform_data = (void *)board_data->tps68470_regulator_pdata;
  1013. cells[1].pdata_size = sizeof(struct tps68470_regulator_platform_data);
  1014. - cells[2].name = "tps68470-gpio";
  1015. + cells[2].name = "tps68470-led";
  1016. + cells[3].name = "tps68470-gpio";
  1017. for (i = 0; i < board_data->n_gpiod_lookups; i++)
  1018. gpiod_add_lookup_table(board_data->tps68470_gpio_lookup_tables[i]);
  1019. --
  1020. 2.42.0
  1021. From 5ef4b0088658da64a7f39c37e33aad3469b3fb39 Mon Sep 17 00:00:00 2001
  1022. From: Kate Hsuan <hpa@redhat.com>
  1023. Date: Tue, 21 Mar 2023 23:37:17 +0800
  1024. Subject: [PATCH] include: mfd: tps68470: Add masks for LEDA and LEDB
  1025. Add flags for both LEDA(TPS68470_ILEDCTL_ENA), LEDB
  1026. (TPS68470_ILEDCTL_ENB), and current control mask for LEDB
  1027. (TPS68470_ILEDCTL_CTRLB)
  1028. Reviewed-by: Daniel Scally <dan.scally@ideasonboard.com>
  1029. Reviewed-by: Hans de Goede <hdegoede@redhat.com>
  1030. Signed-off-by: Kate Hsuan <hpa@redhat.com>
  1031. Patchset: cameras
  1032. ---
  1033. include/linux/mfd/tps68470.h | 5 +++++
  1034. 1 file changed, 5 insertions(+)
  1035. diff --git a/include/linux/mfd/tps68470.h b/include/linux/mfd/tps68470.h
  1036. index 7807fa329db0..2d2abb25b944 100644
  1037. --- a/include/linux/mfd/tps68470.h
  1038. +++ b/include/linux/mfd/tps68470.h
  1039. @@ -34,6 +34,7 @@
  1040. #define TPS68470_REG_SGPO 0x22
  1041. #define TPS68470_REG_GPDI 0x26
  1042. #define TPS68470_REG_GPDO 0x27
  1043. +#define TPS68470_REG_ILEDCTL 0x28
  1044. #define TPS68470_REG_VCMVAL 0x3C
  1045. #define TPS68470_REG_VAUX1VAL 0x3D
  1046. #define TPS68470_REG_VAUX2VAL 0x3E
  1047. @@ -94,4 +95,8 @@
  1048. #define TPS68470_GPIO_MODE_OUT_CMOS 2
  1049. #define TPS68470_GPIO_MODE_OUT_ODRAIN 3
  1050. +#define TPS68470_ILEDCTL_ENA BIT(2)
  1051. +#define TPS68470_ILEDCTL_ENB BIT(6)
  1052. +#define TPS68470_ILEDCTL_CTRLB GENMASK(5, 4)
  1053. +
  1054. #endif /* __LINUX_MFD_TPS68470_H */
  1055. --
  1056. 2.42.0
  1057. From 3296fb49f2be7439c31fb45250c403a484107463 Mon Sep 17 00:00:00 2001
  1058. From: Kate Hsuan <hpa@redhat.com>
  1059. Date: Tue, 21 Mar 2023 23:37:18 +0800
  1060. Subject: [PATCH] leds: tps68470: Add LED control for tps68470
  1061. There are two LED controllers, LEDA indicator LED and LEDB flash LED for
  1062. tps68470. LEDA can be enabled by setting TPS68470_ILEDCTL_ENA. Moreover,
  1063. tps68470 provides four levels of power status for LEDB. If the
  1064. properties called "ti,ledb-current" can be found, the current will be
  1065. set according to the property values. These two LEDs can be controlled
  1066. through the LED class of sysfs (tps68470-leda and tps68470-ledb).
  1067. Signed-off-by: Kate Hsuan <hpa@redhat.com>
  1068. Reviewed-by: Hans de Goede <hdegoede@redhat.com>
  1069. Patchset: cameras
  1070. ---
  1071. drivers/leds/Kconfig | 12 +++
  1072. drivers/leds/Makefile | 1 +
  1073. drivers/leds/leds-tps68470.c | 185 +++++++++++++++++++++++++++++++++++
  1074. 3 files changed, 198 insertions(+)
  1075. create mode 100644 drivers/leds/leds-tps68470.c
  1076. diff --git a/drivers/leds/Kconfig b/drivers/leds/Kconfig
  1077. index 6046dfeca16f..385c06e4f1d3 100644
  1078. --- a/drivers/leds/Kconfig
  1079. +++ b/drivers/leds/Kconfig
  1080. @@ -864,6 +864,18 @@ config LEDS_TPS6105X
  1081. It is a single boost converter primarily for white LEDs and
  1082. audio amplifiers.
  1083. +config LEDS_TPS68470
  1084. + tristate "LED support for TI TPS68470"
  1085. + depends on LEDS_CLASS
  1086. + depends on INTEL_SKL_INT3472
  1087. + help
  1088. + This driver supports TPS68470 PMIC with LED chip.
  1089. + It provides two LED controllers, with the ability to drive 2
  1090. + indicator LEDs and 2 flash LEDs.
  1091. +
  1092. + To compile this driver as a module, choose M and it will be
  1093. + called leds-tps68470
  1094. +
  1095. config LEDS_IP30
  1096. tristate "LED support for SGI Octane machines"
  1097. depends on LEDS_CLASS
  1098. diff --git a/drivers/leds/Makefile b/drivers/leds/Makefile
  1099. index d71f1226540c..e2002b535967 100644
  1100. --- a/drivers/leds/Makefile
  1101. +++ b/drivers/leds/Makefile
  1102. @@ -83,6 +83,7 @@ obj-$(CONFIG_LEDS_TCA6507) += leds-tca6507.o
  1103. obj-$(CONFIG_LEDS_TI_LMU_COMMON) += leds-ti-lmu-common.o
  1104. obj-$(CONFIG_LEDS_TLC591XX) += leds-tlc591xx.o
  1105. obj-$(CONFIG_LEDS_TPS6105X) += leds-tps6105x.o
  1106. +obj-$(CONFIG_LEDS_TPS68470) += leds-tps68470.o
  1107. obj-$(CONFIG_LEDS_TURRIS_OMNIA) += leds-turris-omnia.o
  1108. obj-$(CONFIG_LEDS_WM831X_STATUS) += leds-wm831x-status.o
  1109. obj-$(CONFIG_LEDS_WM8350) += leds-wm8350.o
  1110. diff --git a/drivers/leds/leds-tps68470.c b/drivers/leds/leds-tps68470.c
  1111. new file mode 100644
  1112. index 000000000000..35aeb5db89c8
  1113. --- /dev/null
  1114. +++ b/drivers/leds/leds-tps68470.c
  1115. @@ -0,0 +1,185 @@
  1116. +// SPDX-License-Identifier: GPL-2.0
  1117. +/*
  1118. + * LED driver for TPS68470 PMIC
  1119. + *
  1120. + * Copyright (C) 2023 Red Hat
  1121. + *
  1122. + * Authors:
  1123. + * Kate Hsuan <hpa@redhat.com>
  1124. + */
  1125. +
  1126. +#include <linux/leds.h>
  1127. +#include <linux/mfd/tps68470.h>
  1128. +#include <linux/module.h>
  1129. +#include <linux/platform_device.h>
  1130. +#include <linux/property.h>
  1131. +#include <linux/regmap.h>
  1132. +
  1133. +
  1134. +#define lcdev_to_led(led_cdev) \
  1135. + container_of(led_cdev, struct tps68470_led, lcdev)
  1136. +
  1137. +#define led_to_tps68470(led, index) \
  1138. + container_of(led, struct tps68470_device, leds[index])
  1139. +
  1140. +enum tps68470_led_ids {
  1141. + TPS68470_ILED_A,
  1142. + TPS68470_ILED_B,
  1143. + TPS68470_NUM_LEDS
  1144. +};
  1145. +
  1146. +static const char *tps68470_led_names[] = {
  1147. + [TPS68470_ILED_A] = "tps68470-iled_a",
  1148. + [TPS68470_ILED_B] = "tps68470-iled_b",
  1149. +};
  1150. +
  1151. +struct tps68470_led {
  1152. + unsigned int led_id;
  1153. + struct led_classdev lcdev;
  1154. +};
  1155. +
  1156. +struct tps68470_device {
  1157. + struct device *dev;
  1158. + struct regmap *regmap;
  1159. + struct tps68470_led leds[TPS68470_NUM_LEDS];
  1160. +};
  1161. +
  1162. +enum ctrlb_current {
  1163. + CTRLB_2MA = 0,
  1164. + CTRLB_4MA = 1,
  1165. + CTRLB_8MA = 2,
  1166. + CTRLB_16MA = 3,
  1167. +};
  1168. +
  1169. +static int tps68470_brightness_set(struct led_classdev *led_cdev, enum led_brightness brightness)
  1170. +{
  1171. + struct tps68470_led *led = lcdev_to_led(led_cdev);
  1172. + struct tps68470_device *tps68470 = led_to_tps68470(led, led->led_id);
  1173. + struct regmap *regmap = tps68470->regmap;
  1174. +
  1175. + switch (led->led_id) {
  1176. + case TPS68470_ILED_A:
  1177. + return regmap_update_bits(regmap, TPS68470_REG_ILEDCTL, TPS68470_ILEDCTL_ENA,
  1178. + brightness ? TPS68470_ILEDCTL_ENA : 0);
  1179. + case TPS68470_ILED_B:
  1180. + return regmap_update_bits(regmap, TPS68470_REG_ILEDCTL, TPS68470_ILEDCTL_ENB,
  1181. + brightness ? TPS68470_ILEDCTL_ENB : 0);
  1182. + }
  1183. + return -EINVAL;
  1184. +}
  1185. +
  1186. +static enum led_brightness tps68470_brightness_get(struct led_classdev *led_cdev)
  1187. +{
  1188. + struct tps68470_led *led = lcdev_to_led(led_cdev);
  1189. + struct tps68470_device *tps68470 = led_to_tps68470(led, led->led_id);
  1190. + struct regmap *regmap = tps68470->regmap;
  1191. + int ret = 0;
  1192. + int value = 0;
  1193. +
  1194. + ret = regmap_read(regmap, TPS68470_REG_ILEDCTL, &value);
  1195. + if (ret)
  1196. + return dev_err_probe(led_cdev->dev, -EINVAL, "failed on reading register\n");
  1197. +
  1198. + switch (led->led_id) {
  1199. + case TPS68470_ILED_A:
  1200. + value = value & TPS68470_ILEDCTL_ENA;
  1201. + break;
  1202. + case TPS68470_ILED_B:
  1203. + value = value & TPS68470_ILEDCTL_ENB;
  1204. + break;
  1205. + }
  1206. +
  1207. + return value ? LED_ON : LED_OFF;
  1208. +}
  1209. +
  1210. +
  1211. +static int tps68470_ledb_current_init(struct platform_device *pdev,
  1212. + struct tps68470_device *tps68470)
  1213. +{
  1214. + int ret = 0;
  1215. + unsigned int curr;
  1216. +
  1217. + /* configure LEDB current if the properties can be got */
  1218. + if (!device_property_read_u32(&pdev->dev, "ti,ledb-current", &curr)) {
  1219. + if (curr > CTRLB_16MA) {
  1220. + dev_err(&pdev->dev,
  1221. + "Invalid LEDB current value: %d\n",
  1222. + curr);
  1223. + return -EINVAL;
  1224. + }
  1225. + ret = regmap_update_bits(tps68470->regmap, TPS68470_REG_ILEDCTL,
  1226. + TPS68470_ILEDCTL_CTRLB, curr);
  1227. + }
  1228. + return ret;
  1229. +}
  1230. +
  1231. +static int tps68470_leds_probe(struct platform_device *pdev)
  1232. +{
  1233. + int i = 0;
  1234. + int ret = 0;
  1235. + struct tps68470_device *tps68470;
  1236. + struct tps68470_led *led;
  1237. + struct led_classdev *lcdev;
  1238. +
  1239. + tps68470 = devm_kzalloc(&pdev->dev, sizeof(struct tps68470_device),
  1240. + GFP_KERNEL);
  1241. + if (!tps68470)
  1242. + return -ENOMEM;
  1243. +
  1244. + tps68470->dev = &pdev->dev;
  1245. + tps68470->regmap = dev_get_drvdata(pdev->dev.parent);
  1246. +
  1247. + for (i = 0; i < TPS68470_NUM_LEDS; i++) {
  1248. + led = &tps68470->leds[i];
  1249. + lcdev = &led->lcdev;
  1250. +
  1251. + led->led_id = i;
  1252. +
  1253. + lcdev->name = devm_kasprintf(tps68470->dev, GFP_KERNEL, "%s::%s",
  1254. + tps68470_led_names[i], LED_FUNCTION_INDICATOR);
  1255. + if (!lcdev->name)
  1256. + return -ENOMEM;
  1257. +
  1258. + lcdev->max_brightness = 1;
  1259. + lcdev->brightness = 0;
  1260. + lcdev->brightness_set_blocking = tps68470_brightness_set;
  1261. + lcdev->brightness_get = tps68470_brightness_get;
  1262. + lcdev->dev = &pdev->dev;
  1263. +
  1264. + ret = devm_led_classdev_register(tps68470->dev, lcdev);
  1265. + if (ret) {
  1266. + dev_err_probe(tps68470->dev, ret,
  1267. + "error registering led\n");
  1268. + goto err_exit;
  1269. + }
  1270. +
  1271. + if (i == TPS68470_ILED_B) {
  1272. + ret = tps68470_ledb_current_init(pdev, tps68470);
  1273. + if (ret)
  1274. + goto err_exit;
  1275. + }
  1276. + }
  1277. +
  1278. +err_exit:
  1279. + if (ret) {
  1280. + for (i = 0; i < TPS68470_NUM_LEDS; i++) {
  1281. + if (tps68470->leds[i].lcdev.name)
  1282. + devm_led_classdev_unregister(&pdev->dev,
  1283. + &tps68470->leds[i].lcdev);
  1284. + }
  1285. + }
  1286. +
  1287. + return ret;
  1288. +}
  1289. +static struct platform_driver tps68470_led_driver = {
  1290. + .driver = {
  1291. + .name = "tps68470-led",
  1292. + },
  1293. + .probe = tps68470_leds_probe,
  1294. +};
  1295. +
  1296. +module_platform_driver(tps68470_led_driver);
  1297. +
  1298. +MODULE_ALIAS("platform:tps68470-led");
  1299. +MODULE_DESCRIPTION("LED driver for TPS68470 PMIC");
  1300. +MODULE_LICENSE("GPL v2");
  1301. --
  1302. 2.42.0