Driver for Apple ISP and cameras.
Subsystems (5)
cover Driver for Apple ISP and cameras.
Hi.
This series adds support for the camera and ISP system present on Apple devices using M-series chips. This is a "simple" camera and does not need any special userspace handling, everything is handled by the firmware running on an ASC coprocessor.
Patches 1 and 2 add support for special handling neccesary for the ISP power domains. The rest add the driver itself.
---
Asahi Lina (1):
pmdomain: apple: Add force-disable/force-reset
Eileen Yoon (2):
media: apple: Add Apple ISP driver
arm64: dts: apple: Add ISP nodes
Sasha Finkelstein (2):
dt-bindings: power: apple,pmgr-pwrstate: Add force-{disable,reset} properties
media: dt-bindings: Add Apple ISP
.../devicetree/bindings/media/apple,isp.yaml | 151 ++++ .../bindings/power/apple,pmgr-pwrstate.yaml | 10 + MAINTAINERS | 2 + arch/arm64/boot/dts/apple/isp-common.dtsi | 45 ++ arch/arm64/boot/dts/apple/isp-imx248.dtsi | 62 ++ arch/arm64/boot/dts/apple/isp-imx364.dtsi | 78 ++ arch/arm64/boot/dts/apple/isp-imx558-cfg0.dtsi | 101 +++ arch/arm64/boot/dts/apple/isp-imx558.dtsi | 102 +++ arch/arm64/boot/dts/apple/t600x-die0.dtsi | 48 ++ arch/arm64/boot/dts/apple/t600x-j314-j316.dtsi | 6 + arch/arm64/boot/dts/apple/t600x-pmgr.dtsi | 81 ++ arch/arm64/boot/dts/apple/t8103-j293.dts | 6 + arch/arm64/boot/dts/apple/t8103-j313.dts | 6 + arch/arm64/boot/dts/apple/t8103-j456.dts | 6 + arch/arm64/boot/dts/apple/t8103-j457.dts | 6 + arch/arm64/boot/dts/apple/t8103-pmgr.dtsi | 118 +++ arch/arm64/boot/dts/apple/t8103.dtsi | 50 ++ arch/arm64/boot/dts/apple/t8112-j413.dts | 7 + arch/arm64/boot/dts/apple/t8112-j493.dts | 6 + arch/arm64/boot/dts/apple/t8112-pmgr.dtsi | 118 +++ arch/arm64/boot/dts/apple/t8112.dtsi | 50 ++ drivers/media/platform/Kconfig | 1 + drivers/media/platform/Makefile | 1 + drivers/media/platform/apple/Kconfig | 5 + drivers/media/platform/apple/Makefile | 3 + drivers/media/platform/apple/isp/Kconfig | 16 + drivers/media/platform/apple/isp/Makefile | 3 + drivers/media/platform/apple/isp/isp-cam.c | 414 ++++++++++ drivers/media/platform/apple/isp/isp-cam.h | 21 + drivers/media/platform/apple/isp/isp-cmd.c | 635 +++++++++++++++ drivers/media/platform/apple/isp/isp-cmd.h | 692 ++++++++++++++++ drivers/media/platform/apple/isp/isp-drv.c | 586 ++++++++++++++ drivers/media/platform/apple/isp/isp-drv.h | 284 +++++++ drivers/media/platform/apple/isp/isp-fw.c | 770 ++++++++++++++++++ drivers/media/platform/apple/isp/isp-fw.h | 24 + drivers/media/platform/apple/isp/isp-iommu.c | 251 ++++++ drivers/media/platform/apple/isp/isp-iommu.h | 20 + drivers/media/platform/apple/isp/isp-ipc.c | 258 ++++++ drivers/media/platform/apple/isp/isp-ipc.h | 25 + drivers/media/platform/apple/isp/isp-regs.h | 56 ++ drivers/media/platform/apple/isp/isp-v4l2.c | 900 +++++++++++++++++++++ drivers/media/platform/apple/isp/isp-v4l2.h | 16 + drivers/pmdomain/apple/pmgr-pwrstate.c | 43 +- 43 files changed, 6077 insertions(+), 6 deletions(-)
---
base-commit: 2408a807bfc3f738850ef5ad5e3fd59d66168996
change-id: 20250218-isp-5da1dbc7d472
PATCH 1/5 dt-bindings: power: apple,pmgr-pwrstate: Add force-{disable,reset} properties
From: Sasha Finkelstein <[email protected]>
Add properties to set disable/reset bits when powering down certain domains
--- .../devicetree/bindings/power/apple,pmgr-pwrstate.yaml | 10 ++++++++++ 1 file changed, 10 insertions(+)
Documentation/devicetree/bindings/power/apple,pmgr-pwrstate.yaml +10 -0
@@ -62,6 +62,16 @@ properties: Forces this power domain to always be powered up. type: boolean + apple,force-disable: + description: + Use the disable bit when turning the power off + type: boolean + + apple,force-reset: + description: + Use the reset bit when turning the power off + type: boolean + apple,min-state: description: Specifies the minimum power state for auto-PM.
Signature · 1 line
2.48.1
Re: [PATCH 1/5] dt-bindings: power: apple,pmgr-pwrstate: Add force-{disable,reset} properties
Quoted 4 lines · On 19/02/2025 10:26, Sasha Finkelstein via B4 Relay wrote:
From: Sasha Finkelstein <[email protected]>
Add properties to set disable/reset bits when powering down certain domains
Please explain why and what problem are you solving. This looks too close to SW policy or really arbitrary choice. Background would be useful.
Best regards,
Krzysztof
Re: [PATCH 1/5] dt-bindings: power: apple,pmgr-pwrstate: Add force-{disable,reset} properties
Quoted 9 lines · Krzysztof Kozlowski
Quoted 4 lines · On 19/02/2025 10:26, Sasha Finkelstein via B4 Relay wrote:
From: Sasha Finkelstein <[email protected]>
Add properties to set disable/reset bits when powering down certain domains
Please explain why and what problem are you solving. This looks too close to SW policy or really arbitrary choice. Background would be useful.
The ISP block has some weird requirements where some of it's power domains will not power down correctly without using the "force disable" or "force reset" pmgr feature. Basically a hardware quirk.
Rob Herring
maintainerRe: [PATCH 1/5] dt-bindings: power: apple,pmgr-pwrstate: Add force-{disable,reset} properties
Quoted 8 lines · Sasha Finkelstein
Quoted 7 lines · Krzysztof Kozlowski
Quoted 4 lines · On 19/02/2025 10:26, Sasha Finkelstein via B4 Relay wrote:
From: Sasha Finkelstein <[email protected]>
Add properties to set disable/reset bits when powering down certain domains
Quoted 6 lines
Quoted 2 lines
Please explain why and what problem are you solving. This looks too close to SW policy or really arbitrary choice. Background would be useful.
The ISP block has some weird requirements where some of it's power domains will not power down correctly without using the "force disable" or "force reset" pmgr feature. Basically a hardware quirk.
Add that to the commit message.
Rob
PATCH 2/5 pmdomain: apple: Add force-disable/force-reset
In reply to Sasha FinkelsteinFrom: Asahi Lina <[email protected]>
It seems some ISP power states should have their force disable device access flag set when powered down (which may avoid this problem, but we're still figuring that out), and on some bit 12 is also explicitly set before shutdown. Add two properties to handle this case.
--- drivers/pmdomain/apple/pmgr-pwrstate.c | 43 +++++++++++++++++++++++++++++----- 1 file changed, 37 insertions(+), 6 deletions(-)
drivers/pmdomain/apple/pmgr-pwrstate.c +37 -6
@@ -21,7 +21,8 @@#define APPLE_PMGR_AUTO_ENABLE BIT(28)#define APPLE_PMGR_PS_AUTO GENMASK(27, 24)#define APPLE_PMGR_PS_MIN GENMASK(19, 16) -#define APPLE_PMGR_PARENT_OFF BIT(11) +#define APPLE_PMGR_PS_RESET BIT(12) +#define APPLE_PMGR_BUSY BIT(11)#define APPLE_PMGR_DEV_DISABLE BIT(10)#define APPLE_PMGR_WAS_CLKGATED BIT(9)#define APPLE_PMGR_WAS_PWRGATED BIT(8)
@@ -44,6 +45,8 @@ struct apple_pmgr_ps {struct regmap *regmap;u32 offset;u32 min_state; +bool force_disable; +bool force_reset; };#define genpd_to_apple_pmgr_ps (_genpd) container_of(_genpd, struct apple_pmgr_ps, genpd)
@@ -53,7 +56,7 @@ static int apple_pmgr_ps_set(struct generic_pm_domain *genpd, u32 pstate, bool a {int ret;struct apple_pmgr_ps *ps =genpd_to_apple_pmgr_ps (genpd); -u32 reg; +u32 reg, cur; ret =regmap_read (ps->regmap, ps->offset, ®);if (ret <0 )
@@ -64,7 +67,29 @@ static int apple_pmgr_ps_set(struct generic_pm_domain *genpd, u32 pstate, bool adev_err (ps->dev,"PS %s: powering off with RESET active\n" , genpd->name); - reg &= ~(APPLE_PMGR_AUTO_ENABLE |APPLE_PMGR_FLAGS |APPLE_PMGR_PS_TARGET ); +if (pstate !=APPLE_PMGR_PS_ACTIVE && (ps->force_disable || ps->force_reset)) { +u32 reg_pre = reg & ~(APPLE_PMGR_AUTO_ENABLE |APPLE_PMGR_FLAGS ); + +if (ps->force_disable) + reg_pre |=APPLE_PMGR_DEV_DISABLE ; +if (ps->force_reset) + reg_pre |=APPLE_PMGR_PS_RESET ; + +regmap_write (ps->regmap, ps->offset, reg_pre); + + ret =regmap_read_poll_timeout_atomic ( + ps->regmap, ps->offset, cur, + (cur & (APPLE_PMGR_DEV_DISABLE |APPLE_PMGR_PS_RESET )) == + (reg_pre & (APPLE_PMGR_DEV_DISABLE |APPLE_PMGR_PS_RESET )),1 , +APPLE_PMGR_PS_SET_TIMEOUT ); + +if (ret <0 ) +dev_err (ps->dev,"PS %s: Failed to set reset/disable bits (now: 0x%x)\n" , + genpd->name, reg); + } + + reg &= ~(APPLE_PMGR_DEV_DISABLE |APPLE_PMGR_PS_RESET | +APPLE_PMGR_AUTO_ENABLE |APPLE_PMGR_FLAGS |APPLE_PMGR_PS_TARGET ); reg |=FIELD_PREP (APPLE_PMGR_PS_TARGET , pstate);dev_dbg (ps->dev,"PS %s: pwrstate = 0x%x: 0x%x\n" , genpd->name, pstate, reg);
@@ -72,16 +97,16 @@ static int apple_pmgr_ps_set(struct generic_pm_domain *genpd, u32 pstate, bool aregmap_write (ps->regmap, ps->offset, reg); ret =regmap_read_poll_timeout_atomic ( - ps->regmap, ps->offset, reg, - (FIELD_GET (APPLE_PMGR_PS_ACTUAL , reg) == pstate),1 , + ps->regmap, ps->offset, cur, +FIELD_GET (APPLE_PMGR_PS_ACTUAL , cur) == pstate,1 ,APPLE_PMGR_PS_SET_TIMEOUT ); +if (ret <0 )dev_err (ps->dev,"PS %s: Failed to reach power state 0x%x (now: 0x%x)\n" , genpd->name, pstate, reg);if (auto_enable) {/* Not all devices implement this; this is a no-op where not implemented. */ - reg &= ~APPLE_PMGR_FLAGS ; reg |=APPLE_PMGR_AUTO_ENABLE ;regmap_write (ps->regmap, ps->offset, reg); }
@@ -244,6 +269,12 @@ static int apple_pmgr_ps_probe(struct platform_device *pdev) } } +if (of_property_read_bool (node,"apple,force-disable" )) + ps->force_disable = true; + +if (of_property_read_bool (node,"apple,force-reset" )) + ps->force_reset = true; +/* Turn on auto-PM if the domain is already on */ if (active) regmap_update_bits(regmap, ps->offset, APPLE_PMGR_FLAGS | APPLE_PMGR_AUTO_ENABLE,
Signature · 1 line
2.48.1
PATCH 3/5 media: dt-bindings: Add Apple ISP
In reply to Sasha FinkelsteinFrom: Sasha Finkelstein <[email protected]>
Add bindings for the ISP used with the webcam in Apple ARM laptops.
--- .../devicetree/bindings/media/apple,isp.yaml | 151 +++++++++++++++++++++ MAINTAINERS | 1 + 2 files changed, 152 insertions(+)
Documentation/devicetree/bindings/media/apple,isp.yaml new file +151 -0
@@ -0,0 +1,151 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/media/apple,isp.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: An ISP block used in Apple products + +maintainers: + - Sasha Finkelstein <[email protected]> + +description: + The ISP in charge of webcams on ARM Apple laptops + +properties: + compatible: + items: + - enum: + - apple,t8103-isp + - apple,t8112-isp + - apple,t6000-isp + - apple,t6020-isp + - const: apple,isp + + reg: + items: + - description: ASC coprocessor control + - description: Peripheral to host mailbox + - description: General-purpose ASC IO registers + - description: Host to peripheral mailbox + + reg-names: + items: + - const: coproc + - const: mbox + - const: gpio + - const: mbox2 + + iommus: + description: All 3 must be kept in sync + minItems: 3 + maxItems: 3 + + interrupts: + maxItems: 1 + + power-domains: + minItems: 1 + maxItems: 20 + description: All necessary power domains. Driver will enable them in order + + memory-region: + maxItems: 1 + + apple,dart-vm-size: + description: Supported device memory range + $ref: /schemas/types.yaml#/definitions/uint64 + + apple,platform-id: + description: Platform id for firmware + $ref: /schemas/types.yaml#/definitions/uint32 + + apple,temporal-filter: + description: Whether temporal filter should be enabled in firmware + $ref: /schemas/types.yaml#/definitions/uint32 + + sensor-presets: + additionalProperties: false + + patternProperties: + '^preset[0-9]+$': + type: object + + additionalProperties: false + + properties: + apple,config-index: + description: Firmware config index + $ref: /schemas/types.yaml#/definitions/uint32 + + apple,input-size: + $ref: /schemas/types.yaml#/definitions/uint32-array + minItems: 2 + maxItems: 2 + description: Raw sensor size + + apple,output-size: + $ref: /schemas/types.yaml#/definitions/uint32-array + minItems: 2 + maxItems: 2 + description: Cropped and scaled image size + + apple,crop: + $ref: /schemas/types.yaml#/definitions/uint32-array + minItems: 4 + maxItems: 4 + description: Area to crop + + required: + - apple,config-index + - apple,input-size + - apple,output-size + - apple,crop + +required: + - compatible + - reg + - iommus + - interrupts + - power-domains + - memory-region + - apple,dart-vm-size + - apple,platform-id + - apple,temporal-filter + +additionalProperties: false + +examples: + - | + #include <dt-bindings/interrupt-controller/apple-aic.h> + isp: isp@2a000000 { + compatible = "apple,t8103-isp", "apple,isp"; + reg = <0x2a000000 0x2000000>, + <0x2c104000 0x100>, + <0x2c104170 0x100>, + <0x2c1043f0 0x100>; + reg-names = "coproc", "mbox", "gpio", "mbox2"; + iommus = <&isp_dart0 0>, <&isp_dart1 0>, <&isp_dart2 0>; + interrupt-parent = <&aic>; + interrupts = <AIC_IRQ 246 IRQ_TYPE_LEVEL_HIGH>; + power-domains = <&ps_isp_sys>, <&ps_isp_set0>, + <&ps_isp_set1>, <&ps_isp_set2>, <&ps_isp_fe>, + <&ps_isp_set4>, <&ps_isp_set5>, <&ps_isp_set6>, + <&ps_isp_set7>, <&ps_isp_set8>, <&ps_isp_set9>, + <&ps_isp_set10>, <&ps_isp_set11>, + <&ps_isp_set12>; + memory-region = <&isp_heap>; + apple,dart-vm-size = <0x0 0xa0000000>; + apple,platform-id = <1>; + apple,temporal-filter = <0>; + + sensor-presets { + preset0 { + apple,config-index = <0>; + apple,input-size = <1296 736>; + apple,output-size = <1280 720>; + apple,crop = <8 8 1280 720>; + }; + }; + }; +...
MAINTAINERS +1 -0
@@ -2228,6 +2228,7 @@ F: Documentation/devicetree/bindings/interrupt-controller/apple,* F: Documentation/devicetree/bindings/iommu/apple,dart.yaml F: Documentation/devicetree/bindings/iommu/apple,sart.yaml F: Documentation/devicetree/bindings/mailbox/apple,mailbox.yaml +F: Documentation/devicetree/bindings/media/apple,isp.yaml F: Documentation/devicetree/bindings/net/bluetooth/brcm,bcm4377-bluetooth.yaml F: Documentation/devicetree/bindings/nvme/apple,nvme-ans.yaml F: Documentation/devicetree/bindings/nvmem/apple,efuses.yaml
Signature · 1 line
2.48.1
Re: [PATCH 3/5] media: dt-bindings: Add Apple ISP
Documentation/devicetree/bindings/media/apple,isp.yaml line 41
Quoted 10 lines · On 19/02/2025 10:26, Sasha Finkelstein via B4 Relay wrote:
Documentation/devicetree/bindings/media/apple,isp.yaml new file +10
-0+ reg-names: + items: + - const: coproc + - const: mbox + - const: gpio + - const: mbox2 + + iommus: + description: All 3 must be kept in sync + minItems: 3
Drop minItems
Quoted 6 lines
Documentation/devicetree/bindings/media/apple,isp.yaml new file +6
-0+ maxItems: 3 + + interrupts: + maxItems: 1 + + power-domains:
Documentation/devicetree/bindings/media/apple,isp.yaml line 57
Quoted 10 lines
Documentation/devicetree/bindings/media/apple,isp.yaml new file +10
-0+ minItems: 1 + maxItems: 20 + description: All necessary power domains. Driver will enable them in order + + memory-region: + maxItems: 1 + + apple,dart-vm-size: + description: Supported device memory range + $ref: /schemas/types.yaml#/definitions/uint64
That's deducible from comaptible.
Documentation/devicetree/bindings/media/apple,isp.yaml line 61
Quoted 4 lines
Documentation/devicetree/bindings/media/apple,isp.yaml new file +4
-0+ + apple,platform-id: + description: Platform id for firmware + $ref: /schemas/types.yaml#/definitions/uint32
No, use firmware-name.
Documentation/devicetree/bindings/media/apple,isp.yaml line 65
Quoted 4 lines
Documentation/devicetree/bindings/media/apple,isp.yaml new file +4
-0+ + apple,temporal-filter: + description: Whether temporal filter should be enabled in firmware + $ref: /schemas/types.yaml#/definitions/uint32
And why is this not enabled always? Why this is board specific?
You miss here ports or port. ISP usually gets signal from some camera or other block.
Quoted 4 lines
Documentation/devicetree/bindings/media/apple,isp.yaml new file +4
-0+ + sensor-presets: + additionalProperties: false +
Documentation/devicetree/bindings/media/apple,isp.yaml line 79
Quoted 10 lines
Documentation/devicetree/bindings/media/apple,isp.yaml new file +10
-0+ patternProperties: + '^preset[0-9]+$': + type: object + + additionalProperties: false + + properties: + apple,config-index: + description: Firmware config index + $ref: /schemas/types.yaml#/definitions/uint32
No duplicated indices. You have reg for this, assuming this is index.
Quoted 8 lines
Documentation/devicetree/bindings/media/apple,isp.yaml new file +8
-0+ + apple,input-size: + $ref: /schemas/types.yaml#/definitions/uint32-array + minItems: 2 + maxItems: 2 + description: Raw sensor size + + apple,output-size:
Documentation/devicetree/bindings/media/apple,isp.yaml line 97
Quoted 10 lines
Documentation/devicetree/bindings/media/apple,isp.yaml new file +10
-0+ $ref: /schemas/types.yaml#/definitions/uint32-array + minItems: 2 + maxItems: 2 + description: Cropped and scaled image size + + apple,crop: + $ref: /schemas/types.yaml#/definitions/uint32-array + minItems: 4 + maxItems: 4 + description: Area to crop
All these do not look like hardware properties but rather configuration of sensor which should be done runtime by OS, not by DT.
Best regards,
Krzysztof
Re: [PATCH 3/5] media: dt-bindings: Add Apple ISP
Quoted 7 lines · Krzysztof Kozlowski
Documentation/devicetree/bindings/media/apple,isp.yaml line 61
Quoted 4 lines
Documentation/devicetree/bindings/media/apple,isp.yaml new file +4
-0+ + apple,platform-id: + description: Platform id for firmware + $ref: /schemas/types.yaml#/definitions/uint32No, use firmware-name.
Not sure how is firmware-name an appropriate field, fw-name is a string that references a firmware file, while this field is an id that is sent to the coprocessor firmware in order to identify the platform.
Quoted 5 lines
Documentation/devicetree/bindings/media/apple,isp.yaml line 65
Quoted 3 lines
Documentation/devicetree/bindings/media/apple,isp.yaml new file +3
-0+ apple,temporal-filter: + description: Whether temporal filter should be enabled in firmware + $ref: /schemas/types.yaml#/definitions/uint32And why is this not enabled always? Why this is board specific?
Not every board has support for this feature.
Quoted 2 lines
You miss here ports or port. ISP usually gets signal from some camera or other block.
For complex cameras - yes, but this is closer to a UVC camera connected via a bespoke protocol. We do not need to deal with the sensor access, all of it is managed by the coprocessor firmware.
Quoted 7 lines
Documentation/devicetree/bindings/media/apple,isp.yaml line 79
Quoted 4 lines
Documentation/devicetree/bindings/media/apple,isp.yaml new file +4
-0+ properties: + apple,config-index: + description: Firmware config index + $ref: /schemas/types.yaml#/definitions/uint32No duplicated indices. You have reg for this, assuming this is index.
There are duplicated indices, see isp-imx248.dtsi in patch 5 for an example.
Quoted 2 lines
All these do not look like hardware properties but rather configuration of sensor which should be done runtime by OS, not by DT.
Those are board-specific and not discoverable via the ISP protocol.
Re: [PATCH 3/5] media: dt-bindings: Add Apple ISP
Quoted 34 lines · Sasha Finkelstein
Quoted 7 lines · Krzysztof Kozlowski
Documentation/devicetree/bindings/media/apple,isp.yaml line 61
Quoted 4 lines
Documentation/devicetree/bindings/media/apple,isp.yaml new file +4
-0+ + apple,platform-id: + description: Platform id for firmware + $ref: /schemas/types.yaml#/definitions/uint32No, use firmware-name.
Not sure how is firmware-name an appropriate field, fw-name is a string that references a firmware file, while this field is an id that is sent to the coprocessor firmware in order to identify the platform.
Quoted 5 lines
Documentation/devicetree/bindings/media/apple,isp.yaml line 65
Quoted 3 lines
Documentation/devicetree/bindings/media/apple,isp.yaml new file +3
-0+ apple,temporal-filter: + description: Whether temporal filter should be enabled in firmware + $ref: /schemas/types.yaml#/definitions/uint32And why is this not enabled always? Why this is board specific?
Not every board has support for this feature.
Quoted 2 lines
You miss here ports or port. ISP usually gets signal from some camera or other block.
For complex cameras - yes, but this is closer to a UVC camera connected via a bespoke protocol. We do not need to deal with the sensor access, all of it is managed by the coprocessor firmware.
Quoted 6 lines
Quoted 4 lines
Documentation/devicetree/bindings/media/apple,isp.yaml new file +4
-0+ properties: + apple,config-index: + description: Firmware config index + $ref: /schemas/types.yaml#/definitions/uint32
Quoted 8 lines
Quoted 1 line
No duplicated indices. You have reg for this, assuming this is index.
There are duplicated indices, see
isp-imx248.dtsiin patch 5 for an example.Quoted 2 lines
All these do not look like hardware properties but rather configuration of sensor which should be done runtime by OS, not by DT.
Those are board-specific and not discoverable via the ISP protocol.
But they are settable through the ISP protocol, aren't they ? For instance, looking at isp-imx248.dtsi, the first four entries are
/* 1280x720 */
preset0 {
apple,config-index = <0>;
apple,input-size = <1296 736>;
apple,output-size = <1280 720>;
apple,crop = <8 8 1280 720>;
};
/* 960x720 (4:3) */
preset1 {
apple,config-index = <0>;
apple,input-size = <1296 736>;
apple,output-size = <960 720>;
apple,crop = <168 8 960 720>;
};
/* 960x540 (16:9) */
preset2 {
apple,config-index = <0>;
apple,input-size = <1296 736>;
apple,output-size = <960 540>;
apple,crop = <8 8 1280 720>;
};
/* 640x480 (4:3) */
preset3 {
apple,config-index = <0>;
apple,input-size = <1296 736>;
apple,output-size = <640 480>;
apple,crop = <168 8 960 720>;
};But I may be interested in capturing a 640x480 frame with cropping only and without scaling, with
input-size = 1296x736
output-size = 640x480
crop = (328,128)/640x480
Or I may want my cropped frame to be located in the upper-left corner:
input-size = 1296x736
output-size = 640x480
crop = (8,8)/640x480
If I set those parameters through the ISP protocol, won't it work ?
Signature · 3 lines
Regards, Laurent Pinchart
Re: [PATCH 3/5] media: dt-bindings: Add Apple ISP
Quoted 51 lines · Laurent Pinchart
Quoted 2 lines
Those are board-specific and not discoverable via the ISP protocol.
But they are settable through the ISP protocol, aren't they ? For instance, looking at
isp-imx248.dtsi, the first four entries are/* 1280x720 */ preset0 { apple,config-index = <0>; apple,input-size = <1296 736>; apple,output-size = <1280 720>; apple,crop = <8 8 1280 720>; }; /* 960x720 (4:3) */ preset1 { apple,config-index = <0>; apple,input-size = <1296 736>; apple,output-size = <960 720>; apple,crop = <168 8 960 720>; }; /* 960x540 (16:9) */ preset2 { apple,config-index = <0>; apple,input-size = <1296 736>; apple,output-size = <960 540>; apple,crop = <8 8 1280 720>; }; /* 640x480 (4:3) */ preset3 { apple,config-index = <0>; apple,input-size = <1296 736>; apple,output-size = <640 480>; apple,crop = <168 8 960 720>; };But I may be interested in capturing a 640x480 frame with cropping only and without scaling, with
input-size = 1296x736
output-size = 640x480
crop = (328,128)/640x480Or I may want my cropped frame to be located in the upper-left corner:
input-size = 1296x736
output-size = 640x480
crop = (8,8)/640x480
Quoted 6 lines
If I set those parameters through the ISP protocol, won't it work ?
--
Regards,Laurent Pinchart
For cropping - you do not want to change those parameters, the sensor is partially occluded, and the crop area is specified in such a way to not expose those pixels. As for scaling - we can expose only the 1:1 scale and let userspace deal with it, but it appears that it expects the other common output sizes to exist.
Re: [PATCH 3/5] media: dt-bindings: Add Apple ISP
Quoted 52 lines · Sasha Finkelstein
Quoted 51 lines · Laurent Pinchart
Quoted 2 lines
Those are board-specific and not discoverable via the ISP protocol.
But they are settable through the ISP protocol, aren't they ? For instance, looking at
isp-imx248.dtsi, the first four entries are/* 1280x720 */ preset0 { apple,config-index = <0>; apple,input-size = <1296 736>; apple,output-size = <1280 720>; apple,crop = <8 8 1280 720>; }; /* 960x720 (4:3) */ preset1 { apple,config-index = <0>; apple,input-size = <1296 736>; apple,output-size = <960 720>; apple,crop = <168 8 960 720>; }; /* 960x540 (16:9) */ preset2 { apple,config-index = <0>; apple,input-size = <1296 736>; apple,output-size = <960 540>; apple,crop = <8 8 1280 720>; }; /* 640x480 (4:3) */ preset3 { apple,config-index = <0>; apple,input-size = <1296 736>; apple,output-size = <640 480>; apple,crop = <168 8 960 720>; };But I may be interested in capturing a 640x480 frame with cropping only and without scaling, with
input-size = 1296x736
output-size = 640x480
crop = (328,128)/640x480Or I may want my cropped frame to be located in the upper-left corner:
input-size = 1296x736
output-size = 640x480
crop = (8,8)/640x480
Quoted 5 lines
Quoted 1 line
If I set those parameters through the ISP protocol, won't it work ?
For cropping - you do not want to change those parameters, the sensor is partially occluded, and the crop area is specified in such a way to not expose those pixels.
Surely cropping *more* wouldn't be an issue from that point of view ? The visible area is a device-specific property, so that could be specified in DT, instead of presets. The problem isn't limited to this device, so ideally the DT binding for this feature should be standardized.
In general, I'd say that even occluded pixels should be exposed to userspace, should an application want to capture them. If you think of fisheye lenses, for instance, it's common to have a round image captured from a rectangular sensor, and use a dewarping engine (it could just be GPU shaders) to un-distord it. Restricting capture to rectangles of fully visible pixels would result in loss of information. For this particular device I don't think that would really be a use case, so I'm not opposed to the driver setting restrictions on crop rectangles.
Quoted 3 lines
As for scaling - we can expose only the 1:1
scale and let userspace deal with it, but it appears that it expects the other common output sizes to exist.
Can the driver synthesize the list of scaled-down resolutions, instead of specifying them in DT ?
Signature · 3 lines
Regards, Laurent Pinchart
Re: [PATCH 3/5] media: dt-bindings: Add Apple ISP
In reply to Sasha FinkelsteinQuoted 58 lines · Sasha Finkelstein
Quoted 56 lines · Laurent Pinchart
Quoted 2 lines
Those are board-specific and not discoverable via the ISP protocol.
But they are settable through the ISP protocol, aren't they ? For instance, looking at
isp-imx248.dtsi, the first four entries are/* 1280x720 */ preset0 { apple,config-index = <0>; apple,input-size = <1296 736>; apple,output-size = <1280 720>; apple,crop = <8 8 1280 720>; }; /* 960x720 (4:3) */ preset1 { apple,config-index = <0>; apple,input-size = <1296 736>; apple,output-size = <960 720>; apple,crop = <168 8 960 720>; }; /* 960x540 (16:9) */ preset2 { apple,config-index = <0>; apple,input-size = <1296 736>; apple,output-size = <960 540>; apple,crop = <8 8 1280 720>; }; /* 640x480 (4:3) */ preset3 { apple,config-index = <0>; apple,input-size = <1296 736>; apple,output-size = <640 480>; apple,crop = <168 8 960 720>; };But I may be interested in capturing a 640x480 frame with cropping only and without scaling, with
input-size = 1296x736
output-size = 640x480
crop = (328,128)/640x480Or I may want my cropped frame to be located in the upper-left corner:
input-size = 1296x736
output-size = 640x480
crop = (8,8)/640x480If I set those parameters through the ISP protocol, won't it work ?
--
Regards,
Quoted 9 lines
Quoted 1 line
Laurent Pinchart
For cropping - you do not want to change those parameters, the sensor is partially occluded, and the crop area is specified in such a way to not expose those pixels. As for scaling - we can expose only the 1:1 scale and let userspace deal with it, but it appears that it expects the other common output sizes to exist.
The square sensor with the hack is the IMX558. The configs there are actually a workaround for missing ANE support.
What the driver is supposed to be doing is using the higher numbered presets, which crop internally and exclude the occluded area. But those on machines with that sensor end up requiring ANE integration for denoising and ISP crashes without it.
Config #0 doesn't use ANE, so the crops are re-creations of the other configs so it behaves the same minus the denoising.
Janne Grunau
maintainerRe: [PATCH 3/5] media: dt-bindings: Add Apple ISP
In reply to Laurent PinchartQuoted 86 lines · Laurent Pinchart
Quoted 34 lines · Sasha Finkelstein
Quoted 7 lines · Krzysztof Kozlowski
Documentation/devicetree/bindings/media/apple,isp.yaml line 61
Quoted 4 lines
Documentation/devicetree/bindings/media/apple,isp.yaml new file +4
-0+ + apple,platform-id: + description: Platform id for firmware + $ref: /schemas/types.yaml#/definitions/uint32No, use firmware-name.
Not sure how is firmware-name an appropriate field, fw-name is a string that references a firmware file, while this field is an id that is sent to the coprocessor firmware in order to identify the platform.
Quoted 5 lines
Documentation/devicetree/bindings/media/apple,isp.yaml line 65
Quoted 3 lines
Documentation/devicetree/bindings/media/apple,isp.yaml new file +3
-0+ apple,temporal-filter: + description: Whether temporal filter should be enabled in firmware + $ref: /schemas/types.yaml#/definitions/uint32And why is this not enabled always? Why this is board specific?
Not every board has support for this feature.
Quoted 2 lines
You miss here ports or port. ISP usually gets signal from some camera or other block.
For complex cameras - yes, but this is closer to a UVC camera connected via a bespoke protocol. We do not need to deal with the sensor access, all of it is managed by the coprocessor firmware.
Quoted 6 lines
Quoted 4 lines
Documentation/devicetree/bindings/media/apple,isp.yaml new file +4
-0+ properties: + apple,config-index: + description: Firmware config index + $ref: /schemas/types.yaml#/definitions/uint32Quoted 8 lines
Quoted 1 line
No duplicated indices. You have reg for this, assuming this is index.
There are duplicated indices, see
isp-imx248.dtsiin patch 5 for an example.Quoted 2 lines
All these do not look like hardware properties but rather configuration of sensor which should be done runtime by OS, not by DT.
Those are board-specific and not discoverable via the ISP protocol.
But they are settable through the ISP protocol, aren't they ? For instance, looking at
isp-imx248.dtsi, the first four entries are/* 1280x720 */ preset0 { apple,config-index = <0>; apple,input-size = <1296 736>; apple,output-size = <1280 720>; apple,crop = <8 8 1280 720>; }; /* 960x720 (4:3) */ preset1 { apple,config-index = <0>; apple,input-size = <1296 736>; apple,output-size = <960 720>; apple,crop = <168 8 960 720>; }; /* 960x540 (16:9) */ preset2 { apple,config-index = <0>; apple,input-size = <1296 736>; apple,output-size = <960 540>; apple,crop = <8 8 1280 720>; }; /* 640x480 (4:3) */ preset3 { apple,config-index = <0>; apple,input-size = <1296 736>; apple,output-size = <640 480>; apple,crop = <168 8 960 720>; };But I may be interested in capturing a 640x480 frame with cropping only and without scaling, with
input-size = 1296x736
output-size = 640x480
crop = (328,128)/640x480
Quoted 7 lines
Or I may want my cropped frame to be located in the upper-left corner:
input-size = 1296x736
output-size = 640x480
crop = (8,8)/640x480If I set those parameters through the ISP protocol, won't it work ?
If my memory serves me right the presets wre added as workaround for userspace not handling V4L2_FRMSIZE_TYPE_STEPWISE well (or at all) and the added complexity of handling the qadratic sensor with partially occluded or outside of the usable lens diameter corners.
It is a simplified description of the hardware to make it useable for most software which is expected simple uvc cameras.
There are still two common issues in user space software related to this driver:
- software expects width == linesize
- resolution selection is based frame height, i.e. it prefers 1080x1920 over 1920x1080 on devices with quadratic sensor.
ciao Janne
Re: [PATCH 3/5] media: dt-bindings: Add Apple ISP
Quoted 95 lines · Janne Grunau
Quoted 86 lines · Laurent Pinchart
Quoted 34 lines · Sasha Finkelstein
Quoted 7 lines · Krzysztof Kozlowski
Documentation/devicetree/bindings/media/apple,isp.yaml line 61
Quoted 4 lines
Documentation/devicetree/bindings/media/apple,isp.yaml new file +4
-0+ + apple,platform-id: + description: Platform id for firmware + $ref: /schemas/types.yaml#/definitions/uint32No, use firmware-name.
Not sure how is firmware-name an appropriate field, fw-name is a string that references a firmware file, while this field is an id that is sent to the coprocessor firmware in order to identify the platform.
Quoted 5 lines
Documentation/devicetree/bindings/media/apple,isp.yaml line 65
Quoted 3 lines
Documentation/devicetree/bindings/media/apple,isp.yaml new file +3
-0+ apple,temporal-filter: + description: Whether temporal filter should be enabled in firmware + $ref: /schemas/types.yaml#/definitions/uint32And why is this not enabled always? Why this is board specific?
Not every board has support for this feature.
Quoted 2 lines
You miss here ports or port. ISP usually gets signal from some camera or other block.
For complex cameras - yes, but this is closer to a UVC camera connected via a bespoke protocol. We do not need to deal with the sensor access, all of it is managed by the coprocessor firmware.
Quoted 6 lines
Quoted 4 lines
Documentation/devicetree/bindings/media/apple,isp.yaml new file +4
-0+ properties: + apple,config-index: + description: Firmware config index + $ref: /schemas/types.yaml#/definitions/uint32Quoted 8 lines
Quoted 1 line
No duplicated indices. You have reg for this, assuming this is index.
There are duplicated indices, see
isp-imx248.dtsiin patch 5 for an example.Quoted 2 lines
All these do not look like hardware properties but rather configuration of sensor which should be done runtime by OS, not by DT.
Those are board-specific and not discoverable via the ISP protocol.
But they are settable through the ISP protocol, aren't they ? For instance, looking at
isp-imx248.dtsi, the first four entries are/* 1280x720 */ preset0 { apple,config-index = <0>; apple,input-size = <1296 736>; apple,output-size = <1280 720>; apple,crop = <8 8 1280 720>; }; /* 960x720 (4:3) */ preset1 { apple,config-index = <0>; apple,input-size = <1296 736>; apple,output-size = <960 720>; apple,crop = <168 8 960 720>; }; /* 960x540 (16:9) */ preset2 { apple,config-index = <0>; apple,input-size = <1296 736>; apple,output-size = <960 540>; apple,crop = <8 8 1280 720>; }; /* 640x480 (4:3) */ preset3 { apple,config-index = <0>; apple,input-size = <1296 736>; apple,output-size = <640 480>; apple,crop = <168 8 960 720>; };But I may be interested in capturing a 640x480 frame with cropping only and without scaling, with
input-size = 1296x736
output-size = 640x480
crop = (328,128)/640x480Quoted 7 lines
Or I may want my cropped frame to be located in the upper-left corner:
input-size = 1296x736
output-size = 640x480
crop = (8,8)/640x480If I set those parameters through the ISP protocol, won't it work ?
Quoted 7 lines
If my memory serves me right the presets wre added as workaround for userspace not handling
V4L2_FRMSIZE_TYPE_STEPWISEwell (or at all) and the added complexity of handling the qadratic sensor with partially occluded or outside of the usable lens diameter corners.It is a simplified description of the hardware to make it useable for most software which is expected simple uvc cameras.
I understand that. Ideally userspace should be fixed, but in the meantime, I'm fine with the driver exposing a set of presets. They should however not be listed in DT, but computed by the driver based on properties that describe the device (such as, for instance, the full sensor resolution, or the visible area). Those properties could come from DT, or be hardcoded in the driver on a per-compatible basis.
Quoted 5 lines
There are still two common issues in user space software related to this driver:
- software expects width == linesize
- resolution selection is based frame height, i.e. it prefers 1080x1920 over 1920x1080 on devices with quadratic sensor.
I share your pain, having to fix userspace when doing kernel work isn't always fun :-)
Signature · 3 lines
Regards, Laurent Pinchart
Re: [PATCH 3/5] media: dt-bindings: Add Apple ISP
In reply to Sasha FinkelsteinQuoted 7 lines · Sasha Finkelstein
Quoted 6 lines · Krzysztof Kozlowski
Quoted 4 lines
Documentation/devicetree/bindings/media/apple,isp.yaml new file +4
-0+ + apple,platform-id: + description: Platform id for firmware + $ref: /schemas/types.yaml#/definitions/uint32
Quoted 5 lines
Quoted 1 line
No, use firmware-name.
Not sure how is firmware-name an appropriate field, fw-name is a string that references a firmware file, while this field is an id that is sent to the coprocessor firmware in order to identify the platform.
You get advice how you explain the hardware. Why do you need to identify the platform? Compatible already tells that. Who identifies the platform? For what purpose?
Quoted 8 lines
Quoted 6 lines
Documentation/devicetree/bindings/media/apple,isp.yaml line 65
Quoted 4 lines
Documentation/devicetree/bindings/media/apple,isp.yaml new file +3
-0+ apple,temporal-filter: + description: Whether temporal filter should be enabled in firmware + $ref: /schemas/types.yaml#/definitions/uint32And why is this not enabled always? Why this is board specific?
Not every board has support for this feature.
Board for the same SoC, right? It's fine then, but you should explain all this in binding description.
Quoted 7 lines
Quoted 3 lines
You miss here ports or port. ISP usually gets signal from some camera or other block.
For complex cameras - yes, but this is closer to a UVC camera connected via a bespoke protocol. We do not need to deal with the sensor access, all of it is managed by the coprocessor firmware.
And there is nothing more in this pipeline, like some other processing units? It's fine then, but you should explain all this in binding description.
Quoted 10 lines
Quoted 8 lines
Documentation/devicetree/bindings/media/apple,isp.yaml line 79
Quoted 5 lines
Documentation/devicetree/bindings/media/apple,isp.yaml new file +4
-0+ properties: + apple,config-index: + description: Firmware config index + $ref: /schemas/types.yaml#/definitions/uint32No duplicated indices. You have reg for this, assuming this is index.
There are duplicated indices, see
isp-imx248.dtsiin patch 5 for an example.
I still do no understand their point and description does not help me much.
Quoted 5 lines
Quoted 3 lines
All these do not look like hardware properties but rather configuration of sensor which should be done runtime by OS, not by DT.
Those are board-specific and not discoverable via the ISP protocol.
No, I rather suggest these should be runtime or deduced from the compatible of the sensor. You know embed the sensor characteristics into DT... or if not sensor then some user choice?
Best regards,
Krzysztof
PATCH 4/5 media: apple: Add Apple ISP driver
In reply to Sasha FinkelsteinFrom: Eileen Yoon <[email protected]>
This is the ISP and camera module present on certain Apple laptops
--- MAINTAINERS | 1 + drivers/media/platform/Kconfig | 1 + drivers/media/platform/Makefile | 1 + drivers/media/platform/apple/Kconfig | 5 + drivers/media/platform/apple/Makefile | 3 + drivers/media/platform/apple/isp/Kconfig | 16 + drivers/media/platform/apple/isp/Makefile | 3 + drivers/media/platform/apple/isp/isp-cam.c | 414 ++++++++++++ drivers/media/platform/apple/isp/isp-cam.h | 21 + drivers/media/platform/apple/isp/isp-cmd.c | 635 +++++++++++++++++++ drivers/media/platform/apple/isp/isp-cmd.h | 692 ++++++++++++++++++++ drivers/media/platform/apple/isp/isp-drv.c | 586 +++++++++++++++++ drivers/media/platform/apple/isp/isp-drv.h | 284 +++++++++ drivers/media/platform/apple/isp/isp-fw.c | 770 +++++++++++++++++++++++ drivers/media/platform/apple/isp/isp-fw.h | 24 + drivers/media/platform/apple/isp/isp-iommu.c | 251 ++++++++ drivers/media/platform/apple/isp/isp-iommu.h | 20 + drivers/media/platform/apple/isp/isp-ipc.c | 258 ++++++++ drivers/media/platform/apple/isp/isp-ipc.h | 25 + drivers/media/platform/apple/isp/isp-regs.h | 56 ++ drivers/media/platform/apple/isp/isp-v4l2.c | 900 +++++++++++++++++++++++++++ drivers/media/platform/apple/isp/isp-v4l2.h | 16 + 22 files changed, 4982 insertions(+)
MAINTAINERS +1 -0
@@ -2248,6 +2248,7 @@ F: drivers/i2c/busses/i2c-pasemi-platform.c F: drivers/iommu/apple-dart.c F: drivers/iommu/io-pgtable-dart.c F: drivers/irqchip/irq-apple-aic.c +F: drivers/media/platform/apple/* F: drivers/nvme/host/apple.c F: drivers/nvmem/apple-efuses.c F: drivers/pinctrl/pinctrl-apple-gpio.c
drivers/media/platform/Kconfig +1 -0
@@ -65,6 +65,7 @@ config VIDEO_MUX source "drivers/media/platform/allegro-dvt/Kconfig" source "drivers/media/platform/amlogic/Kconfig" source "drivers/media/platform/amphion/Kconfig" +source "drivers/media/platform/apple/Kconfig" source "drivers/media/platform/aspeed/Kconfig" source "drivers/media/platform/atmel/Kconfig" source "drivers/media/platform/broadcom/Kconfig"
drivers/media/platform/Makefile +1 -0
@@ -8,6 +8,7 @@ obj-y += allegro-dvt/ obj-y += amlogic/ obj-y += amphion/ +obj-y += apple/ obj-y += aspeed/ obj-y += atmel/ obj-y += broadcom/
drivers/media/platform/apple/Kconfig new file +5 -0
@@ -0,0 +1,5 @@ +# SPDX-License-Identifier: GPL-2.0-only + +comment "Apple media platform drivers" + +source "drivers/media/platform/apple/isp/Kconfig"
drivers/media/platform/apple/Makefile new file +3 -0
@@ -0,0 +1,3 @@ +# SPDX-License-Identifier: GPL-2.0-only + +obj-y += isp/
drivers/media/platform/apple/isp/Kconfig new file +16 -0
@@ -0,0 +1,16 @@ +# SPDX-License-Identifier: GPL-2.0-only + +config VIDEO_APPLE_ISP + tristate "Apple Silicon Image Signal Processor driver" + select VIDEOBUF2_CORE + select VIDEOBUF2_V4L2 + select VIDEOBUF2_DMA_SG + depends on ARCH_APPLE || COMPILE_TEST + depends on V4L_PLATFORM_DRIVERS + depends on VIDEO_DEV + help + Say Y here to enable support for the ISP and cameras persent + in Apple ARM laptops. + + To compile this driver as a module, choose M here. The module will be + called apple_isp
drivers/media/platform/apple/isp/Makefile new file +3 -0
@@ -0,0 +1,3 @@ +# SPDX-License-Identifier: GPL-2.0-only +apple-isp-y := isp-cam.o isp-cmd.o isp-drv.o isp-fw.o isp-iommu.o isp-ipc.o isp-v4l2.o +obj-$(CONFIG_VIDEO_APPLE_ISP) += apple-isp.o
drivers/media/platform/apple/isp/isp-cam.c new file +414 -0
414 lines not on this page · raw message
drivers/media/platform/apple/isp/isp-cam.h new file +21 -0
@@ -0,0 +1,21 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* Copyright 2023 Eileen Yoon <[email protected]> */ + +#ifndef __ISP_CAM_H__ +#define __ISP_CAM_H__ + +#include "isp-drv.h" + +#define ISP_FRAME_RATE_NUM 256 +#define ISP_FRAME_RATE_DEN 7680 +#define ISP_FRAME_RATE_DEN2 3840 + +int apple_isp_detect_camera (struct apple_isp *isp); + +int apple_isp_start_camera (struct apple_isp *isp); +void apple_isp_stop_camera (struct apple_isp *isp); + +int apple_isp_start_capture (struct apple_isp *isp); +void apple_isp_stop_capture (struct apple_isp *isp); + +#endif /* __ISP_CAM_H__ */
drivers/media/platform/apple/isp/isp-cmd.c new file +635 -0
635 lines not on this page · raw message
drivers/media/platform/apple/isp/isp-cmd.h new file +692 -0
692 lines not on this page · raw message
drivers/media/platform/apple/isp/isp-drv.c new file +586 -0
586 lines not on this page · raw message
drivers/media/platform/apple/isp/isp-drv.h new file +284 -0
284 lines not on this page · raw message
drivers/media/platform/apple/isp/isp-fw.c new file +770 -0
320 lines not on this page · raw message
drivers/media/platform/apple/isp/isp-fw.h new file +24 -0
Lines of this file are not shown. View the raw message.
drivers/media/platform/apple/isp/isp-iommu.c new file +251 -0
251 lines not on this page · raw message
drivers/media/platform/apple/isp/isp-iommu.h new file +20 -0
Lines of this file are not shown. View the raw message.
drivers/media/platform/apple/isp/isp-ipc.c new file +258 -0
258 lines not on this page · raw message
drivers/media/platform/apple/isp/isp-ipc.h new file +25 -0
Lines of this file are not shown. View the raw message.
drivers/media/platform/apple/isp/isp-regs.h new file +56 -0
56 lines not on this page · raw message
drivers/media/platform/apple/isp/isp-v4l2.c new file +900 -0
900 lines not on this page · raw message
drivers/media/platform/apple/isp/isp-v4l2.h new file +16 -0
Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
Signature · 1 line
2.48.1
Part of the diff is not shown here. View the raw message.
Janne Grunau
maintainerRe: [PATCH 4/5] media: apple: Add Apple ISP driver
Hej,
Quoted 29 lines · On Wed, Feb 19, 2025 at 10:27:00AM +0100, Sasha Finkelstein via B4 Relay wrote:
From: Eileen Yoon <[email protected]>
This is the ISP and camera module present on certain Apple laptops
Signed-off-by Eileen Yoon <[email protected]>Co-developed-by Hector Martin <[email protected]>Signed-off-by Hector Martin <[email protected]>Co-developed-by Asahi Lina <[email protected]>Signed-off-by Asahi Lina <[email protected]>Co-developed-by Janne Grunau <[email protected]>Signed-off-by Janne Grunau <[email protected]>Co-developed-by Sasha Finkelstein <[email protected]>Signed-off-by Sasha Finkelstein <[email protected]>--- MAINTAINERS | 1 + drivers/media/platform/Kconfig | 1 + drivers/media/platform/Makefile | 1 + drivers/media/platform/apple/Kconfig | 5 + drivers/media/platform/apple/Makefile | 3 + drivers/media/platform/apple/isp/Kconfig | 16 + drivers/media/platform/apple/isp/Makefile | 3 + drivers/media/platform/apple/isp/isp-cam.c | 414 ++++++++++++ drivers/media/platform/apple/isp/isp-cam.h | 21 + drivers/media/platform/apple/isp/isp-cmd.c | 635 +++++++++++++++++++ drivers/media/platform/apple/isp/isp-cmd.h | 692 ++++++++++++++++++++ drivers/media/platform/apple/isp/isp-drv.c | 586 +++++++++++++++++ drivers/media/platform/apple/isp/isp-drv.h | 284 +++++++++ drivers/media/platform/apple/isp/isp-fw.c | 770 +++++++++++++++++++++++ drivers/media/platform/apple/isp/isp-fw.h | 24 +
Quoted 8 lines
drivers/media/platform/apple/isp/isp-iommu.c | 251 ++++++++ drivers/media/platform/apple/isp/isp-iommu.h | 20 + drivers/media/platform/apple/isp/isp-ipc.c | 258 ++++++++ drivers/media/platform/apple/isp/isp-ipc.h | 25 + drivers/media/platform/apple/isp/isp-regs.h | 56 ++ drivers/media/platform/apple/isp/isp-v4l2.c | 900 +++++++++++++++++++++++++++ drivers/media/platform/apple/isp/isp-v4l2.h | 16 + 22 files changed, 4982 insertions(+)
quick partial review
Quoted 62 lines
MAINTAINERS +1
-0@@ -2248,6 +2248,7 @@ F: drivers/i2c/busses/i2c-pasemi-platform.c F: drivers/iommu/apple-dart.c F: drivers/iommu/io-pgtable-dart.c F: drivers/irqchip/irq-apple-aic.c +F: drivers/media/platform/apple/* F: drivers/nvme/host/apple.c F: drivers/nvmem/apple-efuses.c F: drivers/pinctrl/pinctrl-apple-gpio.cdrivers/media/platform/Kconfig +1
-0@@ -65,6 +65,7 @@ config VIDEO_MUX source "drivers/media/platform/allegro-dvt/Kconfig" source "drivers/media/platform/amlogic/Kconfig" source "drivers/media/platform/amphion/Kconfig" +source "drivers/media/platform/apple/Kconfig" source "drivers/media/platform/aspeed/Kconfig" source "drivers/media/platform/atmel/Kconfig" source "drivers/media/platform/broadcom/Kconfig"drivers/media/platform/Makefile +1
-0@@ -8,6 +8,7 @@ obj-y += allegro-dvt/ obj-y += amlogic/ obj-y += amphion/ +obj-y += apple/ obj-y += aspeed/ obj-y += atmel/ obj-y += broadcom/drivers/media/platform/apple/Kconfig new file +5
-0@@ -0,0 +1,5 @@ +# SPDX-License-Identifier: GPL-2.0-only + +comment "Apple media platform drivers" + +source "drivers/media/platform/apple/isp/Kconfig"drivers/media/platform/apple/Makefile new file +3
-0@@ -0,0 +1,3 @@ +# SPDX-License-Identifier: GPL-2.0-only + +obj-y += isp/drivers/media/platform/apple/isp/Kconfig new file +0
-0
drivers/media/platform/apple/isp/Kconfig line 10
Quoted 10 lines
drivers/media/platform/apple/isp/Kconfig new file +10
-0@@ -0,0 +1,16 @@ +# SPDX-License-Identifier: GPL-2.0-only + +config VIDEO_APPLE_ISP + tristate "Apple Silicon Image Signal Processor driver" + select VIDEOBUF2_CORE + select VIDEOBUF2_V4L2 + select VIDEOBUF2_DMA_SG + depends on ARCH_APPLE || COMPILE_TEST + depends on V4L_PLATFORM_DRIVERS + depends on VIDEO_DEV
missing dependency on DRM for drm_mm. I don't remember why iova's top down allocation was a problem but if we can avoid drm_mm that would be an option as well.
Quoted 15 lines
drivers/media/platform/apple/isp/Kconfig new file +6
-0+ help + Say Y here to enable support for the ISP and cameras persent + in Apple ARM laptops. + + To compile this driver as a module, choose M here. The module will be + called apple_ispdrivers/media/platform/apple/isp/Makefile new file +3
-0@@ -0,0 +1,3 @@ +# SPDX-License-Identifier: GPL-2.0-only +apple-isp-y := isp-cam.o isp-cmd.o isp-drv.o isp-fw.o isp-iommu.o isp-ipc.o isp-v4l2.o +obj-$(CONFIG_VIDEO_APPLE_ISP) += apple-isp.o
...
Quoted 27 lines
drivers/media/platform/apple/isp/isp-drv.c new file +21
-0@@ -0,0 +1,586 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* +* Apple Image Signal Processor driver +* +* Copyright (C) 2023 The Asahi Linux Contributors +*/ + +#include <linux/iommu.h> +#include <linux/module.h> +#include <linux/of_address.h> +#include <linux/of_device.h> +#include <linux/platform_device.h> +#include <linux/pm_domain.h> +#include <linux/pm_runtime.h> +#include <linux/workqueue.h> + +#include "isp-cam.h" +#include "isp-fw.h" +#include "isp-iommu.h" +#include "isp-v4l2.h" +
...
Quoted 25 lines
drivers/media/platform/apple/isp/isp-drv.c new file +25
-0+static int apple_isp_init_iommu (struct apple_isp *isp) +{ +struct device *dev = isp->dev; +phys_addr_t heap_base; +size_t heap_size; +u64 vm_size; +int err; +int size; +struct device_node *mem_node; +const __be32 *maps, *end; + + isp->domain =iommu_get_domain_for_dev (isp->dev); +if (!isp->domain) +return -ENODEV ; + isp->shift =__ffs (isp->domain->pgsize_bitmap); + + mem_node =of_parse_phandle (dev->of_node,"memory-region" ,0 ); +if (!mem_node) { +dev_err (dev,"No memory-region found for heap\n" ); +return -ENODEV ; + } + + maps =of_get_property (mem_node,"iommu-addresses" , &size); +if (!maps || !size) { +dev_err (dev,"No valid iommu-addresses found for heap\n" );
drivers/media/platform/apple/isp/isp-drv.c line 113
Quoted 10 lines
drivers/media/platform/apple/isp/isp-drv.c new file +10
-0+return -ENODEV ; + } + + end = maps + size /sizeof (__be32); + +while (maps < end) { + maps++; + maps =of_translate_dma_region (dev->of_node, maps, &heap_base, + &heap_size); + }
The hand-rolled reserved memory parsing looks like it can be replaced with of_iommu_get_resv_region();
drivers/media/platform/apple/isp/isp-drv.c line 118
Quoted 6 lines
drivers/media/platform/apple/isp/isp-drv.c new file +5
-0+ + isp->fw.heap_top = heap_base + heap_size; + + err =of_property_read_u64 (dev->of_node,"apple,dart-vm-size" , + &vm_size);
This is not necessary and can be inferred from
isp->domain->geometry.aperture_{start,end}.
drivers/media/platform/apple/isp/isp-drv.c line 125
Quoted 7 lines
drivers/media/platform/apple/isp/isp-drv.c new file +7
-0+if (err) { +dev_err (dev,"failed to read 'apple,dart-vm-size': %d\n" , err); +return err; + } + +drm_mm_init (&isp->iovad, isp->fw.heap_top, + vm_size - (heap_base &0xffffffff ));
drm_mm probably should be replaced with something else. As I wrote above I don't understand / remember what the problem was with relying on the DMA api and iova. I can't imagine that the firmware cares about top-down vs. bottom-up allocation. I could image it was related to "apple,dart-vm-size" and iova's top down allocation only allocated outside of the device's aperture. That should be solved by our current downstream handling of the "vm-base" and "vm-size" properties from Apple's devicetree.
ciao Janne
Re: [PATCH 4/5] media: apple: Add Apple ISP driver
Quoted 8 lines · Janne Grunau
drivers/media/platform/apple/isp/isp-drv.c line 113
Quoted 5 lines
drivers/media/platform/apple/isp/isp-drv.c new file +5
-0+while (maps < end) { + maps++; + maps =of_translate_dma_region (dev->of_node, maps, &heap_base, + &heap_size); + }The hand-rolled reserved memory parsing looks like it can be replaced with
of_iommu_get_resv_region();
I have looked into it, and of_iommu_get_resv_region does the wrong thing. We fill out reg, and it grabs that instead of iommu-addresses.
Janne Grunau
maintainerRe: [PATCH 4/5] media: apple: Add Apple ISP driver
Quoted 7 lines · Sasha Finkelstein
Quoted 6 lines · Janne Grunau
Quoted 5 lines
drivers/media/platform/apple/isp/isp-drv.c new file +5
-0+while (maps < end) { + maps++; + maps =of_translate_dma_region (dev->of_node, maps, &heap_base, + &heap_size); + }
Quoted 5 lines
Quoted 2 lines
The hand-rolled reserved memory parsing looks like it can be replaced with
of_iommu_get_resv_region();I have looked into it, and
of_iommu_get_resv_regiondoes the wrong thing. We fill outreg, and it grabs that instead ofiommu-addresses.
Downstream commit 704ace01cd3c4 [0] ("iommu: Add IOMMU_RESV_TRANSLATED for non 1:1 mapped reserved regions") adds device virtual addresses to struct iommu_resv_region. Sorry for the added dependency but it is required anyway for the isp to work.
ciao Janne
[0] https://github.com/AsahiLinux/linux/commit/704ace01cd3c423b1e2492f0777d9c4c0f3404d8
PATCH 5/5 arm64: dts: apple: Add ISP nodes
In reply to Sasha FinkelsteinFrom: Eileen Yoon <[email protected]>
Adds device tree entries for the ISP and camera sensors
--- arch/arm64/boot/dts/apple/isp-common.dtsi | 45 ++++++++++ arch/arm64/boot/dts/apple/isp-imx248.dtsi | 62 +++++++++++++ arch/arm64/boot/dts/apple/isp-imx364.dtsi | 78 ++++++++++++++++ arch/arm64/boot/dts/apple/isp-imx558-cfg0.dtsi | 101 +++++++++++++++++++++ arch/arm64/boot/dts/apple/isp-imx558.dtsi | 102 +++++++++++++++++++++ arch/arm64/boot/dts/apple/t600x-die0.dtsi | 48 ++++++++++ arch/arm64/boot/dts/apple/t600x-j314-j316.dtsi | 6 ++ arch/arm64/boot/dts/apple/t600x-pmgr.dtsi | 81 +++++++++++++++++ arch/arm64/boot/dts/apple/t8103-j293.dts | 6 ++ arch/arm64/boot/dts/apple/t8103-j313.dts | 6 ++ arch/arm64/boot/dts/apple/t8103-j456.dts | 6 ++ arch/arm64/boot/dts/apple/t8103-j457.dts | 6 ++ arch/arm64/boot/dts/apple/t8103-pmgr.dtsi | 118 +++++++++++++++++++++++++ arch/arm64/boot/dts/apple/t8103.dtsi | 50 +++++++++++ arch/arm64/boot/dts/apple/t8112-j413.dts | 7 ++ arch/arm64/boot/dts/apple/t8112-j493.dts | 6 ++ arch/arm64/boot/dts/apple/t8112-pmgr.dtsi | 118 +++++++++++++++++++++++++ arch/arm64/boot/dts/apple/t8112.dtsi | 50 +++++++++++ 18 files changed, 896 insertions(+)
arch/arm64/boot/dts/apple/isp-common.dtsi new file +45 -0
@@ -0,0 +1,45 @@ +// SPDX-License-Identifier: GPL-2.0+ OR MIT +/* + * Common ISP configuration for Apple silicon platforms. + * + * Copyright The Asahi Linux Contributors + */ + +/ { + aliases { + isp = &isp; + }; + + reserved-memory { + #address-cells = <2>; + #size-cells = <2>; + ranges; + + isp_heap: isp-heap { + /* Filled in by bootloder */ + reg = <0 0 0 0>; + no-map; + }; + }; +}; + +&isp { + memory-region = <&isp_heap>; + status = "okay"; +}; + +&isp_dart0 { + status = "okay"; +}; + +&isp_dart1 { + status = "okay"; +}; + +&isp_dart2 { + status = "okay"; +}; + +&ps_isp_sys { + status = "okay"; +};
arch/arm64/boot/dts/apple/isp-imx248.dtsi new file +62 -0
62 lines not on this page · raw message
arch/arm64/boot/dts/apple/isp-imx364.dtsi new file +78 -0
78 lines not on this page · raw message
arch/arm64/boot/dts/apple/isp-imx558-cfg0.dtsi new file +101 -0
101 lines not on this page · raw message
arch/arm64/boot/dts/apple/isp-imx558.dtsi new file +102 -0
102 lines not on this page · raw message
arch/arm64/boot/dts/apple/t600x-die0.dtsi +48 -0
54 lines not on this page · raw message
arch/arm64/boot/dts/apple/t600x-j314-j316.dtsi +6 -0
@@ -119,3 +119,9 @@ sdhci0: mmc@0,0 { &fpwm0 { status = "okay"; }; + +#include "isp-imx558.dtsi" + +&isp { + apple,platform-id = <3>; +};
arch/arm64/boot/dts/apple/t600x-pmgr.dtsi +81 -0
93 lines not on this page · raw message
arch/arm64/boot/dts/apple/t8103-j293.dts +6 -0
@@ -49,3 +49,9 @@ &i2c4 { &fpwm1 { status = "okay"; }; + +#include "isp-imx248.dtsi" + +&isp { + apple,platform-id = <1>; +};
arch/arm64/boot/dts/apple/t8103-j313.dts +6 -0
@@ -41,3 +41,9 @@ &wifi0 { &fpwm1 { status = "okay"; }; + +#include "isp-imx248.dtsi" + +&isp { + apple,platform-id = <1>; +};
arch/arm64/boot/dts/apple/t8103-j456.dts +6 -0
@@ -75,3 +75,9 @@ &pcie0_dart_1 { &pcie0_dart_2 { status = "okay"; }; + +#include "isp-imx364.dtsi" + +&isp { + apple,platform-id = <2>; +};
arch/arm64/boot/dts/apple/t8103-j457.dts +6 -0
@@ -48,3 +48,9 @@ ethernet0: ethernet@0,0 { &pcie0_dart_2 { status = "okay"; }; + +#include "isp-imx364.dtsi" + +&isp { + apple,platform-id = <2>; +};
arch/arm64/boot/dts/apple/t8103-pmgr.dtsi +118 -0
130 lines not on this page · raw message
arch/arm64/boot/dts/apple/t8103.dtsi +50 -0
56 lines not on this page · raw message
arch/arm64/boot/dts/apple/t8112-j413.dts +7 -0
@@ -78,3 +78,10 @@ &i2c4 { &fpwm1 { status = "okay"; }; + +#include "isp-imx558-cfg0.dtsi" + +&isp { + apple,platform-id = <14>; + apple,temporal-filter = <1>; +};
arch/arm64/boot/dts/apple/t8112-j493.dts +6 -0
@@ -67,3 +67,9 @@ &i2c4 { &fpwm1 { status = "okay"; }; + +#include "isp-imx248.dtsi" + +&isp { + apple,platform-id = <6>; +};
arch/arm64/boot/dts/apple/t8112-pmgr.dtsi +118 -0
130 lines not on this page · raw message
arch/arm64/boot/dts/apple/t8112.dtsi +50 -0
56 lines not on this page · raw message
Signature · 1 line
2.48.1